cscvs to tla changeset 29
[onak.git] / add.c
1 /*
2  * add.c - CGI to add keys.
3  *
4  * Jonathan McDowell <noodles@earth.li>
5  *
6  * Copyright 2002 Project Purple
7  */
8
9 #include <errno.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13
14 #include "armor.h"
15 #include "charfuncs.h"
16 #include "getcgi.h"
17 #include "keydb.h"
18 #include "keystructs.h"
19 #include "onak-conf.h"
20 #include "parsekey.h"
21 #include "merge.h"
22
23 int main(int argc, char *argv[])
24 {
25         struct openpgp_packet_list *packets = NULL;
26         struct openpgp_publickey *keys = NULL;
27         char **params = NULL;
28         struct buffer_ctx ctx;
29         int i;
30
31         memset(&ctx, 0, sizeof(ctx));
32
33         params = getcgivars(argc, argv);
34         for (i = 0; params != NULL && params[i] != NULL; i += 2) {
35                 if (!strcmp(params[i], "keytext")) {
36                         ctx.buffer = params[i+1];
37                         ctx.size = strlen(ctx.buffer);
38                 } else {
39                         free(params[i+1]);
40                 }
41                 params[i+1] = NULL;
42                 free(params[i]);
43                 params[i] = NULL;
44         }
45         if (params != NULL) {
46                 free(params);
47                 params = NULL;
48         }
49
50         start_html("onak : Add");
51         if (ctx.buffer == NULL) {
52                 puts("Error: No keytext to add supplied.");
53         } else {
54                 dearmor_openpgp_stream(buffer_fetchchar,
55                                         &ctx,
56                                         &packets);
57                 if (packets != NULL) {
58                         parse_keys(packets, &keys);
59                         readconfig();
60                         initdb();
61                         printf("Got %d new keys.\n",
62                                         update_keys(&keys, false));
63                         cleanupdb();
64                 } else {
65                         puts("No OpenPGP packets found in input.");
66                 }
67         }
68         end_html();
69         return (EXIT_SUCCESS);
70 }