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