3 * This generates a list of everyone's poboxes for the mitdir.
5 * (c) Copyright 1992 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
13 #include <sys/types.h>
17 EXEC SQL INCLUDE sqlca;
20 char *whoami = "pobox.gen";
21 char *db = "moira/moira";
28 char *outf = NULL, outft[64];
31 EXEC SQL BEGIN DECLARE SECTION;
32 char login[9], id[18], string[257];
33 EXEC SQL END DECLARE SECTION;
38 if (stat(argv[1], &sb) == 0) {
39 if (ModDiff (&flag, "users", sb.st_mtime))
42 fprintf(stderr, "File %s does not need to be rebuilt.\n",
48 sprintf(outft, "%s~", outf);
49 if ((out = fopen(outft, "w")) == NULL) {
50 fprintf(stderr, "unable to open %s for output\n", outf);
53 } else if (argc != 1) {
54 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
60 /* The following is declarative, not executed,
61 * and so is dependent on where it is in the file,
62 * not in the order of execution of statements.
64 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
66 EXEC SQL DECLARE x CURSOR FOR SELECT
68 FROM users WHERE status != 3 and potype='POP';
71 EXEC SQL FETCH x INTO :id, :login;
72 if (sqlca.sqlcode != 0) break;
76 fprintf(out, "%s %s@MIT.EDU\n", id, login);
81 EXEC SQL DECLARE y CURSOR FOR SELECT
83 FROM users u, strings s
84 WHERE u.status != 3 and u.potype='SMTP' and u.box_id = s.string_id;
87 EXEC SQL FETCH y INTO :id, :string;
88 if (sqlca.sqlcode != 0) break;
92 if ((i = strlen(string)) > 7 &&
93 !strcasecmp(".local", string + i - 6)) {
95 fprintf(out, "%s %s.mit.edu\n", id, string);
96 } else if ( !strchr(string, '@') ) {
97 fprintf(out, "%s %s@mit.edu\n", id, string);
99 fprintf(out, "%s %s\n", id, string);
108 perror("close failed");
116 db_error(sqlca.sqlcode);