]> andersk Git - moira.git/blame - gen/sis.pc
Remove `delete_user_by_uid' since it's never been used in any logs we have,
[moira.git] / gen / sis.pc
CommitLineData
279f3753 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>
4b50f071 22#include <string.h>
279f3753 23#include <ctype.h>
9c04b191 24#include <fcntl.h>
279f3753 25EXEC SQL INCLUDE sqlca;
26
27extern int errno;
28char *whoami = "sis.gen";
9c04b191 29char *db = "moira/moira";
279f3753 30
31main(argc, argv)
32int argc;
33char **argv;
34{
35 int out = 1 /* stdout */;
36 char *outf = NULL, outft[64];
37 struct stat sb;
38 int flag1;
39 SigInfo si;
40 struct timeval now;
41 EXEC SQL BEGIN DECLARE SECTION;
42 char login[9], sig[257], id[17], kname[257];
9c04b191 43 EXEC SQL VAR sig IS STRING(257);
b6c73ed5 44 int timestamp;
279f3753 45 struct { char login[12];
46 char id[12];
47 char sig[256];
48 } outrec;
49 EXEC SQL END DECLARE SECTION;
50
51 initialize_sms_error_table ();
52
9c04b191 53 EXEC SQL CONNECT :db;
279f3753 54
55 if (argc == 2) {
56 if (stat(argv[1], &sb) == 0) {
57 if (ModDiff (&flag1, "users", sb.st_mtime) == 0 &&
58 flag1 < 0) {
59 fprintf(stderr, "File %s does not need to be rebuilt.\n",
60 argv[1]);
61 exit(MR_NO_CHANGE);
62 }
63 }
64 outf = argv[1];
65 sprintf(outft, "%s~", outf);
66 if ((out = open(outft, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, 0666)) < 0) {
67 fprintf(stderr, "unable to open %s for output\n", outf);
68 exit(MR_OCONFIG);
69 }
70 } else if (argc != 1) {
71 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
72 exit(MR_ARGS);
73 } else {
74 outf = NULL;
75 }
76
5036bc6d 77 /* The following is declarative, not executed,
78 * and so is dependent on where it is in the file,
79 * not in the order of execution of statements.
80 */
279f3753 81 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
82
83 EXEC SQL DECLARE x CURSOR FOR
5036bc6d 84 SELECT u.login, u.clearid, u.signature, u.sigdate, s.string
279f3753 85 FROM users u, strings s
86 WHERE u.status = 1 and u.sigwho = s.string_id and u.sigwho != 0
b6c73ed5 87 and u.secure != 0;
279f3753 88 EXEC SQL OPEN x;
89 while (1) {
90 EXEC SQL FETCH x INTO :login, :id, :sig, :timestamp, :kname;
91 if (sqlca.sqlcode != 0) break;
92 if (id == 0) continue;
93 if (!isdigit(id[1])) continue;
94 strtrim(login);
95 strtrim(id);
96 strtrim(kname);
9c04b191 97 memset(&outrec, 0, sizeof(outrec));
279f3753 98 strcpy(outrec.login, login);
99 strcpy(outrec.id, id);
100 si.timestamp = timestamp;
101 si.SigInfoVersion = 0; /* XXXXXX this isn't used */
102 kname_parse(si.pname, si.pinst, si.prealm, kname);
5036bc6d 103 si.rawsig = (unsigned char *)sig;
279f3753 104 GDSS_Recompose(&si, outrec.sig);
105 write(out, &outrec, sizeof(outrec));
106 }
107 EXEC SQL CLOSE x;
108
9c04b191 109 EXEC SQL COMMIT;
279f3753 110
111 if (close(out)) {
112 perror("close failed");
113 exit(MR_CCONFIG);
114 }
115 if (outf)
116 fix_file(outf);
117 exit(MR_SUCCESS);
118
119 sqlerr:
9c04b191 120 db_error(sqlca.sqlcode);
121 exit(MR_DBMS_ERR);
279f3753 122}
This page took 0.081865 seconds and 5 git commands to generate.