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