3 * This generates a list of everyone's poboxes for the mitdir.
5 * Copyright (C) 1992-1998 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
14 #include <sys/types.h>
22 EXEC SQL INCLUDE sqlca;
26 char *whoami = "pobox.gen";
27 char *db = "moira/moira";
29 int main(int argc, char **argv)
32 char *outf = NULL, outft[MAXPATHLEN];
35 EXEC SQL BEGIN DECLARE SECTION;
36 char login[USERS_LOGIN_SIZE], id[USERS_CLEARID_SIZE];
37 char string[STRINGS_STRING_SIZE];
38 EXEC SQL END DECLARE SECTION;
44 if (stat(argv[1], &sb) == 0)
46 if (ModDiff(&flag, "users", sb.st_mtime))
50 fprintf(stderr, "File %s does not need to be rebuilt.\n",
56 sprintf(outft, "%s~", outf);
57 if (!(out = fopen(outft, "w")))
59 fprintf(stderr, "unable to open %s for output\n", outf);
65 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
71 /* The following is declarative, not executed,
72 * and so is dependent on where it is in the file,
73 * not in the order of execution of statements.
75 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
77 EXEC SQL DECLARE x CURSOR FOR SELECT
79 FROM users WHERE status != 3 AND potype != 'NONE' AND potype != 'SMTP';
83 EXEC SQL FETCH x INTO :id, :login;
89 fprintf(out, "%s %s@MIT.EDU\n", id, login);
94 EXEC SQL DECLARE y CURSOR FOR SELECT
96 FROM users u, strings s
97 WHERE u.status != 3 and u.potype = 'SMTP' and u.box_id = s.string_id;
101 EXEC SQL FETCH y INTO :id, :string;
108 if ((i = strlen(string)) > 7 &&
109 !strcasecmp(".local", string + i - 6))
111 string[i - 6] = '\0';
112 fprintf(out, "%s %s.mit.edu\n", id, string);
114 else if (!strchr(string, '@'))
115 fprintf(out, "%s %s@mit.edu\n", id, string);
117 fprintf(out, "%s %s\n", id, string);
127 perror("close failed");
135 db_error(sqlca.sqlcode);