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