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