]> andersk Git - moira.git/blame - regtape/verify.dc
translate to SQL
[moira.git] / regtape / verify.dc
CommitLineData
02cd9ede 1/* $Header$
2 *
3 * This program will verify signatures on 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 <gdss.h>
15EXEC SQL INCLUDE sqlca;
16
17
18char *program;
19
20main(argc, argv)
21int argc;
22char **argv;
23{
24 char buf[BUFSIZ], *usercheck[100], sigbuf[256];
25 SigInfo si;
26 int status, i, wait, check, debug;
27 EXEC SQL BEGIN DECLARE SECTION;
28 char login[10], mid[32], rawsig[256], who[257];
29 int id, timestamp;
30 EXEC SQL END DECLARE SECTION;
31
32 initialize_sms_error_table();
33 initialize_krb_error_table();
34 initialize_gdss_error_table();
35
36 program = "sign";
37 check = debug = 0;
38
39 for (i = 1; i < argc; i++) {
40 if (!strcmp(argv[i], "-w"))
41 wait++;
42 else if (!strcmp(argv[i], "-d"))
43 debug++;
44 else if (!strcmp(argv[i], "-D"))
45 setenv("ING_SET", "set printqry");
46 else if (argv[i][0] == '-')
47 fprintf(stderr, "Usage: %s [-w] [-D]\n", argv[0]);
48 else usercheck[check++] = argv[i];
49 }
50
51 EXEC SQL CONNECT moira;
52
53 if (check == 0) {
54 EXEC SQL DECLARE c CURSOR FOR
55 SELECT login, clearid, signature, string, sigdate
56 FROM users, strings
57 WHERE signature != '' and sigwho = string_id;
58 EXEC SQL OPEN c;
59 while (1) {
60 EXEC SQL FETCH c INTO :login, :mid, :rawsig, :who, :timestamp;
61 if (sqlca.sqlcode != 0) break;
62 sprintf(buf, "%s:%s", strtrim(login), strtrim(mid));
63 si.timestamp = timestamp;
64 si.SigInfoVersion = 0;
65 kname_parse(si.pname, si.pinst, si.prealm, strtrim(who));
66 si.rawsig = (unsigned char *) &rawsig[0];
67 status = GDSS_Recompose(&si, sigbuf);
68 if (status) {
69 com_err(program, gdss2et(status), "recomposing for user %s",
70 login);
71 continue;
72 }
73 si.rawsig = NULL;
74 status = GDSS_Verify(buf, strlen(buf), sigbuf, &si);
75 if (status) {
76 com_err(program, gdss2et(status), "verifying user %s", login);
77 }
78 if (wait) {
79 printf("Next");
80 fflush(stdout);
81 gets(buf);
82 }
83 }
84 } else {
85 for (i = check - 1; i >= 0; i--) {
86 strcpy(login, usercheck[i]);
87 EXEC SQL DECLARE s CURSOR FOR
88 SELECT clearid, signature, string, sigdate
89 FROM users, strings
90 WHERE signature != '' and sigwho = string_id and login = :login;
91 EXEC SQL OPEN s;
92 while (1) {
93 EXEC SQL FETCH s INTO :mid, :rawsig, :who, :timestamp;
94 if (sqlca.sqlcode != 0) break;
95 sprintf(buf, "%s:%s", strtrim(login), strtrim(mid));
96 if (debug) {
97 printf("Verifying \"%s\"\n", buf);
98 }
99 si.timestamp = timestamp;
100 si.SigInfoVersion = 0;
101 kname_parse(si.pname, si.pinst, si.prealm, strtrim(who));
102 si.rawsig = (unsigned char *) &rawsig[0];
103 status = GDSS_Recompose(&si, sigbuf);
104 if (status) {
105 com_err(program, gdss2et(status), "recomposing for user %s", login);
106 continue;
107 }
108 si.rawsig = NULL;
109 status = GDSS_Verify(buf, strlen(buf), sigbuf, &si);
110 if (status)
111 com_err(program, gdss2et(status), "verifying user %s", login);
112 else {
113 com_err(program, 0, "signature verified %s", buf);
114 if (debug == 2) {
115 hex_dump(sigbuf);
116 }
117 }
118 if (wait) {
119 printf("Next");
120 fflush(stdout);
121 gets(buf);
122 }
123 }
124 }
125 }
126
127 exit(0);
128}
129
130
131hex_dump(p)
132unsigned char *p;
133{
134 printf("Size: %d\n", strlen(p));
135 while (strlen(p) >= 8) {
136 printf("%02x %02x %02x %02x %02x %02x %02x %02x\n",
137 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
138 p += 8;
139 }
140 switch (strlen(p)) {
141 case 7:
142 printf("%02x %02x %02x %02x %02x %02x %02x\n",
143 p[0], p[1], p[2], p[3], p[4], p[5], p[6]);
144 break;
145 case 6:
146 printf("%02x %02x %02x %02x %02x %02x\n",
147 p[0], p[1], p[2], p[3], p[4], p[5]);
148 break;
149 case 5:
150 printf("%02x %02x %02x %02x %02x\n",
151 p[0], p[1], p[2], p[3], p[4]);
152 break;
153 case 4:
154 printf("%02x %02x %02x %02x\n",
155 p[0], p[1], p[2], p[3]);
156 break;
157 case 3:
158 printf("%02x %02x %02x\n",
159 p[0], p[1], p[2]);
160 break;
161 case 2:
162 printf("%02x %02x\n",
163 p[0], p[1]);
164 break;
165 case 1:
166 printf("%02x\n",
167 p[0]);
168 break;
169 default:
170 return;
171 }
172}
This page took 0.074263 seconds and 5 git commands to generate.