]> andersk Git - moira.git/blame - gen/pobox.dc
New database and column names for Moira2.
[moira.git] / gen / pobox.dc
CommitLineData
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>
17EXEC SQL INCLUDE sqlca;
18
19extern int errno;
20char *whoami = "pobox.gen";
21
22
23main(argc, argv)
24int argc;
25char **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
9fd1c2b8 36 EXEC SQL CONNECT moira;
c7fb2d10 37#endsql
38#ifsql INFORMIX
9fd1c2b8 39 EXEC SQL DATABASE moira;
c7fb2d10 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
9fd1c2b8 65 /* The following is declarative, not executed,
66 * and so is dependent on where it is in the file,
67 * not in the order of execution of statements.
68 */
c7fb2d10 69 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
70
71 EXEC SQL DECLARE x CURSOR FOR SELECT
9fd1c2b8 72 clearid, login
73 FROM users WHERE status != 3 and potype='POP';
c7fb2d10 74 EXEC SQL OPEN x;
75 while (1) {
76 EXEC SQL FETCH x INTO :id, :login;
77 if (sqlca.sqlcode != 0) break;
78 strtrim(login);
79 strtrim(id);
80 if (isdigit(id[0]))
81 fprintf(out, "%s %s@ATHENA.MIT.EDU\n", id, login);
82 }
83
84 EXEC SQL CLOSE x;
85
86 EXEC SQL DECLARE y CURSOR FOR SELECT
9fd1c2b8 87 u.clearid, s.string
c7fb2d10 88 FROM users u, strings s
9fd1c2b8 89 WHERE u.status != 3 and u.potype='SMTP' and u.box_id = s.string_id;
c7fb2d10 90 EXEC SQL OPEN y;
91 while (1) {
92 EXEC SQL FETCH y INTO :id, :string;
93 if (sqlca.sqlcode != 0) break;
94 strtrim(string);
95 strtrim(id);
96 if (isdigit(id[0])) {
97 if ((i = strlen(string)) > 7 &&
98 !strcasecmp(".local", string + i - 6)) {
99 string[i-6] = 0;
100 fprintf(out, "%s %s.mit.edu\n", id, string);
101 } else
102 fprintf(out, "%s %s\n", id, string);
103 }
104 }
105
106 EXEC SQL CLOSE y;
107
108#ifsql INGRES
109 EXEC SQL DISCONNECT;
110#endsql
111#ifsql INFORMIX
112 EXEC SQL CLOSE DATABASE;
113#endsql
114
115 if (fclose(out)) {
116 perror("close failed");
117 exit(MR_CCONFIG);
118 }
119 if (outf)
120 fix_file(outf);
121 exit(MR_SUCCESS);
122
123 sqlerr:
124 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
125 critical_alert("DCM", "Pobox build encountered INGRES ERROR %d",
126 sqlca.sqlcode);
127 exit(MR_INGRES_ERR);
128}
This page took 0.063621 seconds and 5 git commands to generate.