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