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