]>
Commit | Line | Data |
---|---|---|
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> | |
17 | EXEC SQL INCLUDE sqlca; | |
18 | ||
19 | extern int errno; | |
20 | char *whoami = "pobox.gen"; | |
21 | ||
22 | ||
23 | main(argc, argv) | |
24 | int argc; | |
25 | char **argv; | |
26 | { | |
27 | FILE *out = stdout; | |
28 | char *outf = NULL, outft[64]; | |
29 | struct stat sb; | |
30 | int flag, i; | |
31 | EXEC SQL BEGIN DECLARE SECTION; | |
32 | char login[9], id[18], string[257]; | |
33 | EXEC SQL END DECLARE SECTION; | |
34 | ||
35 | #ifsql INGRES | |
36 | EXEC SQL CONNECT sms; | |
37 | #endsql | |
38 | #ifsql INFORMIX | |
39 | EXEC SQL DATABASE sms; | |
40 | #endsql | |
41 | ||
42 | if (argc == 2) { | |
43 | if (stat(argv[1], &sb) == 0) { | |
44 | if (ModDiff (&flag, "users", sb.st_mtime)) | |
45 | exit(MR_DATE); | |
46 | if (flag < 0) { | |
47 | fprintf(stderr, "File %s does not need to be rebuilt.\n", | |
48 | argv[1]); | |
49 | exit(MR_NO_CHANGE); | |
50 | } | |
51 | } | |
52 | outf = argv[1]; | |
53 | sprintf(outft, "%s~", outf); | |
54 | if ((out = fopen(outft, "w")) == NULL) { | |
55 | fprintf(stderr, "unable to open %s for output\n", outf); | |
56 | exit(MR_OCONFIG); | |
57 | } | |
58 | } else if (argc != 1) { | |
59 | fprintf(stderr, "usage: %s [outfile]\n", argv[0]); | |
60 | exit(MR_ARGS); | |
61 | } else { | |
62 | outf = NULL; | |
63 | } | |
64 | ||
65 | EXEC SQL WHENEVER SQLERROR GOTO sqlerr; | |
66 | ||
67 | EXEC SQL DECLARE x CURSOR FOR SELECT | |
68 | mit_id, login | |
69 | FROM users WHERE status != 3 and potype="POP"; | |
70 | EXEC SQL OPEN x; | |
71 | while (1) { | |
72 | EXEC SQL FETCH x INTO :id, :login; | |
73 | if (sqlca.sqlcode != 0) break; | |
74 | strtrim(login); | |
75 | strtrim(id); | |
76 | if (isdigit(id[0])) | |
77 | fprintf(out, "%s %s@ATHENA.MIT.EDU\n", id, login); | |
78 | } | |
79 | ||
80 | EXEC SQL CLOSE x; | |
81 | ||
82 | EXEC SQL DECLARE y CURSOR FOR SELECT | |
83 | u.mit_id, s.string | |
84 | FROM users u, strings s | |
85 | WHERE u.status != 3 and u.potype="SMTP" and u.box_id = s.string_id; | |
86 | EXEC SQL OPEN y; | |
87 | while (1) { | |
88 | EXEC SQL FETCH y INTO :id, :string; | |
89 | if (sqlca.sqlcode != 0) break; | |
90 | strtrim(string); | |
91 | strtrim(id); | |
92 | if (isdigit(id[0])) { | |
93 | if ((i = strlen(string)) > 7 && | |
94 | !strcasecmp(".local", string + i - 6)) { | |
95 | string[i-6] = 0; | |
96 | fprintf(out, "%s %s.mit.edu\n", id, string); | |
97 | } else | |
98 | fprintf(out, "%s %s\n", id, string); | |
99 | } | |
100 | } | |
101 | ||
102 | EXEC SQL CLOSE y; | |
103 | ||
104 | #ifsql INGRES | |
105 | EXEC SQL DISCONNECT; | |
106 | #endsql | |
107 | #ifsql INFORMIX | |
108 | EXEC SQL CLOSE DATABASE; | |
109 | #endsql | |
110 | ||
111 | if (fclose(out)) { | |
112 | perror("close failed"); | |
113 | exit(MR_CCONFIG); | |
114 | } | |
115 | if (outf) | |
116 | fix_file(outf); | |
117 | exit(MR_SUCCESS); | |
118 | ||
119 | sqlerr: | |
120 | com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); | |
121 | critical_alert("DCM", "Pobox build encountered INGRES ERROR %d", | |
122 | sqlca.sqlcode); | |
123 | exit(MR_INGRES_ERR); | |
124 | } |