]> andersk Git - moira.git/blame_incremental - gen/pobox.pc
Add an alternate possible location of postacldcm (in /usr/local/sbin)
[moira.git] / gen / pobox.pc
... / ...
CommitLineData
1/* $Id$
2 *
3 * This generates a list of everyone's poboxes for the mitdir.
4 *
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>.
8 */
9
10#include <mit-copyright.h>
11#include <moira.h>
12
13#include <sys/stat.h>
14#include <sys/types.h>
15
16#include <ctype.h>
17#include <stdio.h>
18#include <string.h>
19
20#include "util.h"
21
22EXEC SQL INCLUDE sqlca;
23
24RCSID("$Header$");
25
26char *whoami = "pobox.gen";
27char *db = "moira/moira";
28
29int main(int argc, char **argv)
30{
31 FILE *out = stdout;
32 char *outf = NULL, outft[MAXPATHLEN];
33 int i;
34 EXEC SQL BEGIN DECLARE SECTION;
35 char login[USERS_LOGIN_SIZE], id[USERS_CLEARID_SIZE];
36 char string[STRINGS_STRING_SIZE];
37 EXEC SQL END DECLARE SECTION;
38
39 EXEC SQL CONNECT :db;
40
41 if (argc == 2)
42 {
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);
49 }
50 }
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;
58
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;
64
65 EXEC SQL DECLARE x CURSOR FOR SELECT
66 clearid, login
67 FROM users WHERE status != 3 AND potype != 'NONE';
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);
78 }
79
80 EXEC SQL CLOSE x;
81
82 EXEC SQL COMMIT;
83
84 if (fclose(out))
85 {
86 perror("close failed");
87 exit(MR_CCONFIG);
88 }
89 if (outf)
90 fix_file(outf);
91 exit(MR_SUCCESS);
92
93sqlerr:
94 db_error(sqlca.sqlcode);
95 exit(MR_DBMS_ERR);
96}
This page took 0.031229 seconds and 5 git commands to generate.