]> andersk Git - moira.git/blame - gen/pobox.pc
Use moira_schema.h
[moira.git] / gen / pobox.pc
CommitLineData
7ac48069 1/* $Id $
c7fb2d10 2 *
3 * This generates a list of everyone's poboxes for the mitdir.
4 *
7ac48069 5 * Copyright (C) 1992-1998 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
c7fb2d10 8 */
9
10#include <mit-copyright.h>
c7fb2d10 11#include <moira.h>
7ac48069 12
c7fb2d10 13#include <sys/stat.h>
7ac48069 14#include <sys/types.h>
15
c7fb2d10 16#include <ctype.h>
7ac48069 17#include <stdio.h>
18#include <string.h>
19
20#include "util.h"
21
c7fb2d10 22EXEC SQL INCLUDE sqlca;
23
7ac48069 24RCSID("$Header$");
25
c7fb2d10 26char *whoami = "pobox.gen";
9c04b191 27char *db = "moira/moira";
c7fb2d10 28
5eaef520 29int main(int argc, char **argv)
c7fb2d10 30{
5eaef520 31 FILE *out = stdout;
32 char *outf = NULL, outft[64];
33 struct stat sb;
34 int flag, i;
35 EXEC SQL BEGIN DECLARE SECTION;
36 char login[9], id[18], string[257];
37 EXEC SQL END DECLARE SECTION;
c7fb2d10 38
5eaef520 39 EXEC SQL CONNECT :db;
c7fb2d10 40
5eaef520 41 if (argc == 2)
42 {
43 if (stat(argv[1], &sb) == 0)
44 {
45 if (ModDiff(&flag, "users", sb.st_mtime))
46 exit(MR_DATE);
47 if (flag < 0)
48 {
49 fprintf(stderr, "File %s does not need to be rebuilt.\n",
50 argv[1]);
51 exit(MR_NO_CHANGE);
c7fb2d10 52 }
53 }
5eaef520 54 outf = argv[1];
55 sprintf(outft, "%s~", outf);
56 if (!(out = fopen(outft, "w")))
57 {
58 fprintf(stderr, "unable to open %s for output\n", outf);
59 exit(MR_OCONFIG);
c7fb2d10 60 }
c7fb2d10 61 }
5eaef520 62 else if (argc != 1)
63 {
64 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
65 exit(MR_ARGS);
66 }
67 else
68 outf = NULL;
c7fb2d10 69
5eaef520 70 /* The following is declarative, not executed,
71 * and so is dependent on where it is in the file,
72 * not in the order of execution of statements.
73 */
74 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
c7fb2d10 75
5eaef520 76 EXEC SQL DECLARE x CURSOR FOR SELECT
77 clearid, login
78 FROM users WHERE status != 3 and potype = 'POP';
79 EXEC SQL OPEN x;
80 while (1)
81 {
82 EXEC SQL FETCH x INTO :id, :login;
83 if (sqlca.sqlcode)
84 break;
85 strtrim(login);
86 strtrim(id);
87 if (isdigit(id[0]))
88 fprintf(out, "%s %s@MIT.EDU\n", id, login);
c7fb2d10 89 }
90
5eaef520 91 EXEC SQL CLOSE x;
c7fb2d10 92
5eaef520 93 EXEC SQL DECLARE y CURSOR FOR SELECT
94 u.clearid, s.string
95 FROM users u, strings s
96 WHERE u.status != 3 and u.potype = 'SMTP' and u.box_id = s.string_id;
97 EXEC SQL OPEN y;
98 while (1)
99 {
100 EXEC SQL FETCH y INTO :id, :string;
101 if (sqlca.sqlcode)
102 break;
103 strtrim(string);
104 strtrim(id);
105 if (isdigit(id[0]))
106 {
107 if ((i = strlen(string)) > 7 &&
108 !strcasecmp(".local", string + i - 6))
109 {
110 string[i - 6] = '\0';
111 fprintf(out, "%s %s.mit.edu\n", id, string);
112 }
113 else if (!strchr(string, '@'))
114 fprintf(out, "%s %s@mit.edu\n", id, string);
115 else
116 fprintf(out, "%s %s\n", id, string);
c7fb2d10 117 }
118 }
119
5eaef520 120 EXEC SQL CLOSE y;
c7fb2d10 121
5eaef520 122 EXEC SQL COMMIT;
c7fb2d10 123
5eaef520 124 if (fclose(out))
125 {
126 perror("close failed");
127 exit(MR_CCONFIG);
c7fb2d10 128 }
5eaef520 129 if (outf)
130 fix_file(outf);
131 exit(MR_SUCCESS);
c7fb2d10 132
5eaef520 133sqlerr:
134 db_error(sqlca.sqlcode);
135 exit(MR_DBMS_ERR);
c7fb2d10 136}
This page took 0.076045 seconds and 5 git commands to generate.