]>
Commit | Line | Data |
---|---|---|
1 | /* $Header$ | |
2 | * | |
3 | * This program will bulk sign user records in the database. | |
4 | */ | |
5 | ||
6 | #include <stdio.h> | |
7 | #include <strings.h> | |
8 | #include <ctype.h> | |
9 | #include <sys/time.h> | |
10 | #include <moira.h> | |
11 | #include <moira_site.h> | |
12 | #include <des.h> | |
13 | #include <krb.h> | |
14 | #include <krb_err.h> | |
15 | #include <gdss.h> | |
16 | EXEC SQL INCLUDE sqlca; | |
17 | ||
18 | ||
19 | char *program; | |
20 | ||
21 | main(argc, argv) | |
22 | int argc; | |
23 | char **argv; | |
24 | { | |
25 | char buf[BUFSIZ], *data, *p; | |
26 | struct save_queue *sq; | |
27 | SigInfo si; | |
28 | int found, status, i, wait; | |
29 | EXEC SQL BEGIN DECLARE SECTION; | |
30 | char login[10], mid[32], rawsig[256]; | |
31 | int id, timestamp, sms; | |
32 | EXEC SQL END DECLARE SECTION; | |
33 | ||
34 | program = "sign"; | |
35 | init_krb_err_tbl(); | |
36 | init_sms_err_tbl(); | |
37 | ||
38 | for (i = 1; i < argc; i++) { | |
39 | if (!strcmp(argv[i], "-w")) | |
40 | wait++; | |
41 | else if (!strcmp(argv[i], "-D")) | |
42 | setenv("ING_SET", "set printqry"); | |
43 | else | |
44 | fprintf(stderr, "Usage: %s [-w] [-D]\n", argv[0]); | |
45 | } | |
46 | ||
47 | /* Set the name of our kerberos ticket file */ | |
48 | krb_set_tkt_string("/tmp/tkt_sign"); | |
49 | status = 1; | |
50 | while (status) { | |
51 | printf("Authenticating as moira.extra:\n"); | |
52 | status = krb_get_pw_in_tkt("moira", "extra", "ATHENA.MIT.EDU", | |
53 | "krbtgt", "ATHENA.MIT.EDU", | |
54 | DEFAULT_TKT_LIFE, 0); | |
55 | if (status != 0) | |
56 | com_err(program, status + krb_err_base, " in krb_get_pw_in_tkt"); | |
57 | } | |
58 | ||
59 | EXEC SQL CONNECT moira; | |
60 | if (sqlca.sqlcode != 0) { | |
61 | com_err(program, 0, "ingres error %d", sqlca.sqlcode); | |
62 | exit(1); | |
63 | } | |
64 | ||
65 | sms = 0; | |
66 | EXEC SQL SELECT string_id INTO :sms FROM strings | |
67 | WHERE string='moira.extra@ATHENA.MIT.EDU'; | |
68 | if (sms == 0) { | |
69 | com_err(program, 0, " failed to find string moira.extra@ATHENA.MIT.EDU in database"); | |
70 | dest_tkt(); | |
71 | exit(1); | |
72 | } | |
73 | ||
74 | found = 0; | |
75 | sq = sq_create(); | |
76 | ||
77 | EXEC SQL DECLARE c CURSOR FOR | |
78 | SELECT users_id, login, clearid | |
79 | FROM users WHERE signature = ''; | |
80 | if (sqlca.sqlcode != 0) { | |
81 | com_err(program, 0, "ingres error %d", sqlca.sqlcode); | |
82 | exit(1); | |
83 | } | |
84 | EXEC SQL OPEN c; | |
85 | if (sqlca.sqlcode != 0) { | |
86 | com_err(program, 0, "ingres error %d", sqlca.sqlcode); | |
87 | exit(1); | |
88 | } | |
89 | while (1) { | |
90 | EXEC SQL FETCH c INTO :id, :login, :mid; | |
91 | if (sqlca.sqlcode != 0) break; | |
92 | if (login[0] == '#' || !isdigit(mid[0])) | |
93 | continue; | |
94 | sprintf(buf, "%d:%s:%s", id, strtrim(login), strtrim(mid)); | |
95 | sq_save_data(sq, strsave(buf)); | |
96 | found++; | |
97 | } | |
98 | EXEC SQL CLOSE c; | |
99 | EXEC SQL COMMIT WORK; | |
100 | printf("Found %d users to sign.\n", found); | |
101 | ||
102 | si.rawsig = (unsigned char *) &rawsig[0]; | |
103 | ||
104 | while (sq_get_data(sq, &data)) { | |
105 | p = index(data, ':'); | |
106 | if (!p) { | |
107 | com_err(program, 0, " malformatted data"); | |
108 | continue; | |
109 | } | |
110 | *p++ = 0; | |
111 | id = atoi(data); | |
112 | data = p; | |
113 | again: | |
114 | status = GDSS_Sign(data, strlen(data), buf); | |
115 | if (status) { | |
116 | com_err(program, gdss2et(status), "signing data"); | |
117 | continue; | |
118 | } | |
119 | status = GDSS_Verify(data, strlen(data), buf, &si); | |
120 | if (status) { | |
121 | com_err(program, gdss2et(status), "verifying data"); | |
122 | continue; | |
123 | } | |
124 | if (strlen(rawsig) > 68) { | |
125 | sleep(1); | |
126 | goto again; | |
127 | } | |
128 | ||
129 | timestamp = si.timestamp; | |
130 | EXEC SQL REPEATED UPDATE users | |
131 | SET signature = :rawsig, sigwho = :sms, sigdate = :timestamp | |
132 | WHERE users_id = :id; | |
133 | if (sqlca.sqlcode != 0) { | |
134 | com_err(program, 0, "ingres error %d", sqlca.sqlcode); | |
135 | exit(1); | |
136 | } | |
137 | EXEC SQL COMMIT WORK; | |
138 | if (wait) { | |
139 | printf("Next"); | |
140 | fflush(stdout); | |
141 | gets(buf); | |
142 | } | |
143 | } | |
144 | dest_tkt(); | |
145 | exit(0); | |
146 | } |