]>
Commit | Line | Data |
---|---|---|
c441a31a | 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 | 22 | EXEC SQL INCLUDE sqlca; |
23 | ||
7ac48069 | 24 | RCSID("$Header$"); |
25 | ||
c7fb2d10 | 26 | char *whoami = "pobox.gen"; |
9c04b191 | 27 | char *db = "moira/moira"; |
c7fb2d10 | 28 | |
5eaef520 | 29 | int main(int argc, char **argv) |
c7fb2d10 | 30 | { |
5eaef520 | 31 | FILE *out = stdout; |
dfaf9b68 | 32 | char *outf = NULL, outft[MAXPATHLEN]; |
a589d269 | 33 | int i; |
5eaef520 | 34 | EXEC SQL BEGIN DECLARE SECTION; |
dfaf9b68 | 35 | char login[USERS_LOGIN_SIZE], id[USERS_CLEARID_SIZE]; |
36 | char string[STRINGS_STRING_SIZE]; | |
5eaef520 | 37 | EXEC SQL END DECLARE SECTION; |
c7fb2d10 | 38 | |
5eaef520 | 39 | EXEC SQL CONNECT :db; |
c7fb2d10 | 40 | |
5eaef520 | 41 | if (argc == 2) |
42 | { | |
5eaef520 | 43 | outf = argv[1]; |
44 | sprintf(outft, "%s~", outf); | |
45 | if (!(out = fopen(outft, "w"))) | |
46 | { | |
47 | fprintf(stderr, "unable to open %s for output\n", outf); | |
48 | exit(MR_OCONFIG); | |
c7fb2d10 | 49 | } |
c7fb2d10 | 50 | } |
5eaef520 | 51 | else if (argc != 1) |
52 | { | |
53 | fprintf(stderr, "usage: %s [outfile]\n", argv[0]); | |
54 | exit(MR_ARGS); | |
55 | } | |
56 | else | |
57 | outf = NULL; | |
c7fb2d10 | 58 | |
5eaef520 | 59 | /* The following is declarative, not executed, |
60 | * and so is dependent on where it is in the file, | |
61 | * not in the order of execution of statements. | |
62 | */ | |
63 | EXEC SQL WHENEVER SQLERROR GOTO sqlerr; | |
c7fb2d10 | 64 | |
5eaef520 | 65 | EXEC SQL DECLARE x CURSOR FOR SELECT |
66 | clearid, login | |
9786b8ee | 67 | FROM users WHERE status != 3 AND potype != 'NONE' AND potype != 'SMTP'; |
5eaef520 | 68 | EXEC SQL OPEN x; |
69 | while (1) | |
70 | { | |
71 | EXEC SQL FETCH x INTO :id, :login; | |
72 | if (sqlca.sqlcode) | |
73 | break; | |
74 | strtrim(login); | |
75 | strtrim(id); | |
76 | if (isdigit(id[0])) | |
77 | fprintf(out, "%s %s@MIT.EDU\n", id, login); | |
c7fb2d10 | 78 | } |
79 | ||
5eaef520 | 80 | EXEC SQL CLOSE x; |
c7fb2d10 | 81 | |
5eaef520 | 82 | EXEC SQL DECLARE y CURSOR FOR SELECT |
83 | u.clearid, 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 | { | |
89 | EXEC SQL FETCH y INTO :id, :string; | |
90 | if (sqlca.sqlcode) | |
91 | break; | |
92 | strtrim(string); | |
93 | strtrim(id); | |
94 | if (isdigit(id[0])) | |
95 | { | |
96 | if ((i = strlen(string)) > 7 && | |
97 | !strcasecmp(".local", string + i - 6)) | |
98 | { | |
99 | string[i - 6] = '\0'; | |
100 | fprintf(out, "%s %s.mit.edu\n", id, string); | |
101 | } | |
102 | else if (!strchr(string, '@')) | |
103 | fprintf(out, "%s %s@mit.edu\n", id, string); | |
104 | else | |
105 | fprintf(out, "%s %s\n", id, string); | |
c7fb2d10 | 106 | } |
107 | } | |
108 | ||
5eaef520 | 109 | EXEC SQL CLOSE y; |
c7fb2d10 | 110 | |
5eaef520 | 111 | EXEC SQL COMMIT; |
c7fb2d10 | 112 | |
5eaef520 | 113 | if (fclose(out)) |
114 | { | |
115 | perror("close failed"); | |
116 | exit(MR_CCONFIG); | |
c7fb2d10 | 117 | } |
5eaef520 | 118 | if (outf) |
119 | fix_file(outf); | |
120 | exit(MR_SUCCESS); | |
c7fb2d10 | 121 | |
5eaef520 | 122 | sqlerr: |
123 | db_error(sqlca.sqlcode); | |
124 | exit(MR_DBMS_ERR); | |
c7fb2d10 | 125 | } |