]> andersk Git - moira.git/blob - gen/sis.dc
e2c4b98acde70ec92c5178aa54d3f8db7bc679e9
[moira.git] / gen / sis.dc
1 /* $Header$
2  *
3  * This generates a list of users and their MIT ID numbers and the
4  * signatures which guarentee this mapping.
5  *
6  *  (c) Copyright 1992 by the Massachusetts Institute of Technology.
7  *  For copying and distribution information, please see the file
8  *  <mit-copyright.h>.
9  */
10
11 #include <mit-copyright.h>
12 #include <stdio.h>
13 #include <moira.h>
14 #include <moira_site.h>
15 #include <des.h>
16 #include <krb.h>
17 #include <gdss.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 #include <sys/time.h>
21 #include <sys/file.h>
22 #include <strings.h>
23 #include <ctype.h>
24 EXEC SQL INCLUDE sqlca;
25
26 extern int errno;
27 char *whoami = "sis.gen";
28
29
30 main(argc, argv)
31 int argc;
32 char **argv;
33 {
34     int out = 1 /* stdout */;
35     char *outf = NULL, outft[64];
36     struct stat sb;
37     int flag1;
38     SigInfo si;
39     struct timeval now;
40     EXEC SQL BEGIN DECLARE SECTION;
41     char login[9], sig[257], id[17], kname[257];
42     int timestamp;
43     struct { char login[12];
44              char id[12];
45              char sig[256];
46          } outrec;
47     EXEC SQL END DECLARE SECTION;
48
49     initialize_sms_error_table ();
50
51 #ifsql INGRES
52     EXEC SQL CONNECT moira;
53     EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED;
54 #endsql
55 #ifsql INFORMIX
56     EXEC SQL DATABASE moira;
57 #endsql
58
59     if (argc == 2) {
60         if (stat(argv[1], &sb) == 0) {
61             if (ModDiff (&flag1, "users", sb.st_mtime) == 0 &&
62                 flag1 < 0) {
63                 fprintf(stderr, "File %s does not need to be rebuilt.\n",
64                         argv[1]);
65                 exit(MR_NO_CHANGE);
66             }
67         }
68         outf = argv[1];
69         sprintf(outft, "%s~", outf);
70         if ((out = open(outft, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, 0666)) < 0) {
71             fprintf(stderr, "unable to open %s for output\n", outf);
72             exit(MR_OCONFIG);
73         }
74     } else if (argc != 1) {
75         fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
76         exit(MR_ARGS);
77     } else {
78         outf = NULL;
79     }
80
81     /* The following is declarative, not executed,
82      * and so is dependent on where it is in the file,
83      * not in the order of execution of statements.
84      */
85     EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
86
87     EXEC SQL DECLARE x CURSOR FOR
88       SELECT u.login, u.clearid, u.signature, u.sigdate, s.string
89       FROM users u, strings s
90         WHERE u.status = 1 and u.sigwho = s.string_id and u.sigwho != 0
91           and u.secure != 0;
92     EXEC SQL OPEN x;
93     while (1) {
94         EXEC SQL FETCH x INTO :login, :id, :sig, :timestamp, :kname;
95         if (sqlca.sqlcode != 0) break;
96         if (id == 0) continue;
97         if (!isdigit(id[1])) continue;
98         strtrim(login);
99         strtrim(id);
100         strtrim(kname);
101         strcpy(outrec.login, login);
102         strcpy(outrec.id, id);
103         si.timestamp = timestamp;
104         si.SigInfoVersion = 0; /* XXXXXX this isn't used */
105         kname_parse(si.pname, si.pinst, si.prealm, kname);
106         si.rawsig = (unsigned char *)sig;
107         GDSS_Recompose(&si, outrec.sig);
108         write(out, &outrec, sizeof(outrec));
109     }
110     EXEC SQL CLOSE x;
111
112 #ifsql INGRES
113     EXEC SQL DISCONNECT;
114 #endsql
115 #ifsql INFORMIX
116     EXEC SQL CLOSE DATABASE;
117 #endsql
118
119     if (close(out)) {
120         perror("close failed");
121         exit(MR_CCONFIG);
122     }
123     if (outf)
124       fix_file(outf);
125     exit(MR_SUCCESS);
126
127  sqlerr:
128     com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
129 #ifsql INGRES
130     if (sqlca.sqlcode == 17700 || sqlca.sqlcode == -37000)
131       exit(MR_DEADLOCK);
132 #endsql
133     critical_alert("DCM", "SIS build encountered INGRES ERROR %d",
134                    sqlca.sqlcode);
135     exit(MR_INGRES_ERR);
136 }
This page took 0.113531 seconds and 3 git commands to generate.