]> andersk Git - moira.git/blob - gen/sis.dc
Oracle and Solaris/POSIX changes
[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 #include <fcntl.h>
25 EXEC SQL INCLUDE sqlca;
26
27 extern int errno;
28 char *whoami = "sis.gen";
29 char *db = "moira/moira";
30
31 main(argc, argv)
32 int argc;
33 char **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];
43     EXEC SQL VAR sig IS STRING(257);
44     int timestamp;
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
53     EXEC SQL CONNECT :db;
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
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      */
81     EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
82
83     EXEC SQL DECLARE x CURSOR FOR
84       SELECT u.login, u.clearid, u.signature, u.sigdate, s.string
85       FROM users u, strings s
86         WHERE u.status = 1 and u.sigwho = s.string_id and u.sigwho != 0
87           and u.secure != 0;
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);
97         memset(&outrec, 0, sizeof(outrec));
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);
103         si.rawsig = (unsigned char *)sig;
104         GDSS_Recompose(&si, outrec.sig);
105         write(out, &outrec, sizeof(outrec));
106     }
107     EXEC SQL CLOSE x;
108
109     EXEC SQL COMMIT;
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:
120     db_error(sqlca.sqlcode);
121     exit(MR_DBMS_ERR);
122 }
This page took 0.047407 seconds and 5 git commands to generate.