3 * This generates a list of users and their MIT ID numbers and the
4 * signatures which guarentee this mapping.
6 * (c) Copyright 1992 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
11 #include <mit-copyright.h>
14 #include <moira_site.h>
18 #include <sys/types.h>
24 EXEC SQL INCLUDE sqlca;
27 char *whoami = "sis.gen";
34 int out = 1 /* stdout */;
35 char *outf = NULL, outft[64];
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];
47 EXEC SQL END DECLARE SECTION;
49 initialize_sms_error_table ();
52 EXEC SQL CONNECT moira;
53 EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED;
56 EXEC SQL DATABASE moira;
60 if (stat(argv[1], &sb) == 0) {
61 if (ModDiff (&flag1, "users", sb.st_mtime) == 0 &&
63 fprintf(stderr, "File %s does not need to be rebuilt.\n",
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);
74 } else if (argc != 1) {
75 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
81 /* the cutoff time is 14 days before now */
82 gettimeofday(&now, NULL);
83 cutoff = now.tv_sec - 14 * 24 * 60 * 60;
85 /* The following is declarative, not executed,
86 * and so is dependent on where it is in the file,
87 * not in the order of execution of statements.
89 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
91 /* lock user table first */
93 EXEC SQL SELECT modtime INTO :id FROM users WHERE users_id = 0;
95 EXEC SQL DECLARE x CURSOR FOR
96 SELECT u.login, u.clearid, u.signature, u.sigdate, s.string
97 FROM users u, strings s
98 WHERE u.status = 1 and u.sigwho = s.string_id and u.sigwho != 0
99 and u.secure <= :cutoff and u.secure != 0;
102 EXEC SQL FETCH x INTO :login, :id, :sig, :timestamp, :kname;
103 if (sqlca.sqlcode != 0) break;
104 if (id == 0) continue;
105 if (!isdigit(id[1])) continue;
109 strcpy(outrec.login, login);
110 strcpy(outrec.id, id);
111 si.timestamp = timestamp;
112 si.SigInfoVersion = 0; /* XXXXXX this isn't used */
113 kname_parse(si.pname, si.pinst, si.prealm, kname);
114 si.rawsig = (unsigned char *)sig;
115 GDSS_Recompose(&si, outrec.sig);
116 write(out, &outrec, sizeof(outrec));
124 EXEC SQL CLOSE DATABASE;
128 perror("close failed");
136 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
138 if (sqlca.sqlcode == 17700 || sqlca.sqlcode == -37000)
141 critical_alert("DCM", "SIS build encountered INGRES ERROR %d",