]> andersk Git - moira.git/blame - gen/pobox.pc
fix RCS IDs
[moira.git] / gen / pobox.pc
CommitLineData
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 22EXEC SQL INCLUDE sqlca;
23
7ac48069 24RCSID("$Header$");
25
c7fb2d10 26char *whoami = "pobox.gen";
9c04b191 27char *db = "moira/moira";
c7fb2d10 28
5eaef520 29int main(int argc, char **argv)
c7fb2d10 30{
5eaef520 31 FILE *out = stdout;
dfaf9b68 32 char *outf = NULL, outft[MAXPATHLEN];
5eaef520 33 struct stat sb;
34 int flag, i;
35 EXEC SQL BEGIN DECLARE SECTION;
dfaf9b68 36 char login[USERS_LOGIN_SIZE], id[USERS_CLEARID_SIZE];
37 char string[STRINGS_STRING_SIZE];
5eaef520 38 EXEC SQL END DECLARE SECTION;
c7fb2d10 39
5eaef520 40 EXEC SQL CONNECT :db;
c7fb2d10 41
5eaef520 42 if (argc == 2)
43 {
44 if (stat(argv[1], &sb) == 0)
45 {
46 if (ModDiff(&flag, "users", sb.st_mtime))
47 exit(MR_DATE);
48 if (flag < 0)
49 {
50 fprintf(stderr, "File %s does not need to be rebuilt.\n",
51 argv[1]);
52 exit(MR_NO_CHANGE);
c7fb2d10 53 }
54 }
5eaef520 55 outf = argv[1];
56 sprintf(outft, "%s~", outf);
57 if (!(out = fopen(outft, "w")))
58 {
59 fprintf(stderr, "unable to open %s for output\n", outf);
60 exit(MR_OCONFIG);
c7fb2d10 61 }
c7fb2d10 62 }
5eaef520 63 else if (argc != 1)
64 {
65 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
66 exit(MR_ARGS);
67 }
68 else
69 outf = NULL;
c7fb2d10 70
5eaef520 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.
74 */
75 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
c7fb2d10 76
5eaef520 77 EXEC SQL DECLARE x CURSOR FOR SELECT
78 clearid, login
79 FROM users WHERE status != 3 and potype = 'POP';
80 EXEC SQL OPEN x;
81 while (1)
82 {
83 EXEC SQL FETCH x INTO :id, :login;
84 if (sqlca.sqlcode)
85 break;
86 strtrim(login);
87 strtrim(id);
88 if (isdigit(id[0]))
89 fprintf(out, "%s %s@MIT.EDU\n", id, login);
c7fb2d10 90 }
91
5eaef520 92 EXEC SQL CLOSE x;
c7fb2d10 93
5eaef520 94 EXEC SQL DECLARE y CURSOR FOR SELECT
95 u.clearid, s.string
96 FROM users u, strings s
97 WHERE u.status != 3 and u.potype = 'SMTP' and u.box_id = s.string_id;
98 EXEC SQL OPEN y;
99 while (1)
100 {
101 EXEC SQL FETCH y INTO :id, :string;
102 if (sqlca.sqlcode)
103 break;
104 strtrim(string);
105 strtrim(id);
106 if (isdigit(id[0]))
107 {
108 if ((i = strlen(string)) > 7 &&
109 !strcasecmp(".local", string + i - 6))
110 {
111 string[i - 6] = '\0';
112 fprintf(out, "%s %s.mit.edu\n", id, string);
113 }
114 else if (!strchr(string, '@'))
115 fprintf(out, "%s %s@mit.edu\n", id, string);
116 else
117 fprintf(out, "%s %s\n", id, string);
c7fb2d10 118 }
119 }
120
5eaef520 121 EXEC SQL CLOSE y;
c7fb2d10 122
5eaef520 123 EXEC SQL COMMIT;
c7fb2d10 124
5eaef520 125 if (fclose(out))
126 {
127 perror("close failed");
128 exit(MR_CCONFIG);
c7fb2d10 129 }
5eaef520 130 if (outf)
131 fix_file(outf);
132 exit(MR_SUCCESS);
c7fb2d10 133
5eaef520 134sqlerr:
135 db_error(sqlca.sqlcode);
136 exit(MR_DBMS_ERR);
c7fb2d10 137}
This page took 0.085732 seconds and 5 git commands to generate.