]> andersk Git - moira.git/blob - gen/sis.dc
Initial revision
[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, cutoff;
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 sms;
53 #endsql
54 #ifsql INFORMIX
55     EXEC SQL DATABASE sms;
56 #endsql
57
58     if (argc == 2) {
59         if (stat(argv[1], &sb) == 0) {
60             if (ModDiff (&flag1, "users", sb.st_mtime) == 0 &&
61                 flag1 < 0) {
62                 fprintf(stderr, "File %s does not need to be rebuilt.\n",
63                         argv[1]);
64                 exit(MR_NO_CHANGE);
65             }
66         }
67         outf = argv[1];
68         sprintf(outft, "%s~", outf);
69         if ((out = open(outft, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, 0666)) < 0) {
70             fprintf(stderr, "unable to open %s for output\n", outf);
71             exit(MR_OCONFIG);
72         }
73     } else if (argc != 1) {
74         fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
75         exit(MR_ARGS);
76     } else {
77         outf = NULL;
78     }
79
80     /* the cutoff time is 14 days before now */
81     gettimeofday(&now, NULL);
82     cutoff = now.tv_sec - 14 * 24 * 60 * 60;
83
84     EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
85
86     EXEC SQL DECLARE x CURSOR FOR
87       SELECT u.login, u.mit_id, u.signature, u.sigdate, s.string
88       FROM users u, strings s
89         WHERE u.status = 1 and u.sigwho = s.string_id and u.sigwho != 0
90           and u.secure <= :cutoff and u.secure != 0;
91     EXEC SQL OPEN x;
92     while (1) {
93         EXEC SQL FETCH x INTO :login, :id, :sig, :timestamp, :kname;
94         if (sqlca.sqlcode != 0) break;
95         if (id == 0) continue;
96         if (!isdigit(id[1])) continue;
97         strtrim(login);
98         strtrim(id);
99         strtrim(kname);
100         strcpy(outrec.login, login);
101         strcpy(outrec.id, id);
102         si.timestamp = timestamp;
103         si.SigInfoVersion = 0; /* XXXXXX this isn't used */
104         kname_parse(si.pname, si.pinst, si.prealm, kname);
105         si.rawsig = sig;
106         GDSS_Recompose(&si, outrec.sig);
107         write(out, &outrec, sizeof(outrec));
108     }
109     EXEC SQL CLOSE x;
110
111 #ifsql INGRES
112     EXEC SQL DISCONNECT;
113 #endsql
114 #ifsql INFORMIX
115     EXEC SQL CLOSE DATABASE;
116 #endsql
117
118     if (close(out)) {
119         perror("close failed");
120         exit(MR_CCONFIG);
121     }
122     if (outf)
123       fix_file(outf);
124     exit(MR_SUCCESS);
125
126  sqlerr:
127     com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
128 #ifsql INGRES
129     if (sqlca.sqlcode == 17700)
130       exit(MR_DEADLOCK);
131 #endsql
132     critical_alert("DCM", "SIS build encountered INGRES ERROR %d",
133                    sqlca.sqlcode);
134     exit(MR_INGRES_ERR);
135 }
This page took 0.095091 seconds and 5 git commands to generate.