]>
Commit | Line | Data |
---|---|---|
0138e073 | 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> | |
02cd9ede | 16 | EXEC SQL INCLUDE sqlca; |
0138e073 | 17 | |
18 | ||
19 | char *program; | |
20 | ||
21 | main(argc, argv) | |
22 | int argc; | |
23 | char **argv; | |
02cd9ede | 24 | { |
0138e073 | 25 | char buf[BUFSIZ], *data, *p; |
26 | struct save_queue *sq; | |
27 | SigInfo si; | |
28 | int found, status, i, wait; | |
02cd9ede | 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; | |
0138e073 | 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 | ||
02cd9ede | 59 | EXEC SQL CONNECT moira; |
0138e073 | 60 | |
61 | sms = 0; | |
02cd9ede | 62 | EXEC SQL SELECT string_id INTO :sms FROM strings |
63 | WHERE string='moira.extra@ATHENA.MIT.EDU'; | |
0138e073 | 64 | if (sms == 0) { |
65 | com_err(program, 0, " failed to find string moira.extra@ATHENA.MIT.EDU in database"); | |
66 | dest_tkt(); | |
67 | exit(1); | |
68 | } | |
69 | ||
70 | found = 0; | |
71 | sq = sq_create(); | |
72 | ||
02cd9ede | 73 | EXEC SQL DECLARE c CURSOR FOR |
74 | SELECT users_id, login, clearid | |
75 | FROM users WHERE signature = ''; | |
76 | EXEC SQL OPEN c; | |
77 | while (1) { | |
78 | EXEC SQL FETCH c INTO :id, :login, :mid; | |
79 | if (sqlca.sqlcode != 0) break; | |
80 | if (login[0] == '#' || !isdigit(mid[0])) | |
81 | continue; | |
82 | sprintf(buf, "%d:%s:%s", id, strtrim(login), strtrim(mid)); | |
83 | sq_save_data(sq, strsave(buf)); | |
84 | found++; | |
85 | } | |
0138e073 | 86 | |
87 | printf("Found %d users to sign.\n", found); | |
88 | ||
89 | si.rawsig = (unsigned char *) &rawsig[0]; | |
90 | ||
91 | while (sq_get_data(sq, &data)) { | |
92 | p = index(data, ':'); | |
93 | if (!p) { | |
94 | com_err(program, 0, " malformatted data"); | |
95 | continue; | |
96 | } | |
97 | *p++ = 0; | |
98 | id = atoi(data); | |
99 | data = p; | |
02cd9ede | 100 | again: |
0138e073 | 101 | status = GDSS_Sign(data, strlen(data), buf); |
102 | if (status) { | |
103 | com_err(program, gdss2et(status), "signing data"); | |
104 | continue; | |
105 | } | |
106 | status = GDSS_Verify(data, strlen(data), buf, &si); | |
107 | if (status) { | |
108 | com_err(program, gdss2et(status), "verifying data"); | |
109 | continue; | |
110 | } | |
02cd9ede | 111 | if (strlen(rawsig) > 68) { |
112 | sleep(1); | |
113 | goto again; | |
114 | } | |
0138e073 | 115 | |
116 | timestamp = si.timestamp; | |
02cd9ede | 117 | EXEC SQL REPEATED UPDATE users |
118 | SET signature = :rawsig, sigwho = :sms, sigdate = :timestamp | |
119 | WHERE users_id = :id; | |
0138e073 | 120 | if (wait) { |
121 | printf("Next"); | |
122 | fflush(stdout); | |
123 | gets(buf); | |
124 | } | |
125 | } | |
126 | dest_tkt(); | |
0138e073 | 127 | exit(0); |
02cd9ede | 128 | } |