]> git.sommitrealweird.co.uk Git - onak.git/blob - add.c
cscvs to tla changeset 28
[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 "parsekey.h"
20 #include "merge.h"
21
22 int main(int argc, char *argv[])
23 {
24         struct openpgp_packet_list *packets = NULL;
25         struct openpgp_publickey *keys = NULL;
26         char **params = NULL;
27         struct buffer_ctx ctx;
28         int i;
29
30         memset(&ctx, 0, sizeof(ctx));
31
32         params = getcgivars(argc, argv);
33         for (i = 0; params != NULL && params[i] != NULL; i += 2) {
34                 if (!strcmp(params[i], "keytext")) {
35                         ctx.buffer = params[i+1];
36                         ctx.size = strlen(ctx.buffer);
37                 } else {
38                         free(params[i+1]);
39                 }
40                 params[i+1] = NULL;
41                 free(params[i]);
42                 params[i] = NULL;
43         }
44         if (params != NULL) {
45                 free(params);
46                 params = NULL;
47         }
48
49         start_html("onak : Add");
50         if (ctx.buffer == NULL) {
51                 puts("Error: No keytext to add supplied.");
52         } else {
53                 dearmor_openpgp_stream(buffer_fetchchar,
54                                         &ctx,
55                                         &packets);
56                 if (packets != NULL) {
57                         parse_keys(packets, &keys);
58                         initdb();
59                         printf("Got %d new keys.\n",
60                                         update_keys(&keys, false));
61                         cleanupdb();
62                 } else {
63                         puts("No OpenPGP packets found in input.");
64                 }
65         }
66         end_html();
67         return (EXIT_SUCCESS);
68 }