]> git.sommitrealweird.co.uk Git - onak.git/blob - add.c
cscvs to tla changeset 134
[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  * $Id: add.c,v 1.14 2004/05/26 21:20:05 noodles Exp $
9  */
10
11 #include <errno.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15
16 #include "armor.h"
17 #include "charfuncs.h"
18 #include "getcgi.h"
19 #include "keydb.h"
20 #include "keystructs.h"
21 #include "log.h"
22 #include "mem.h"
23 #include "merge.h"
24 #include "onak-conf.h"
25 #include "parsekey.h"
26 #include "sendsync.h"
27
28 int main(int argc, char *argv[])
29 {
30         struct openpgp_packet_list  *packets = NULL;
31         struct openpgp_publickey    *keys = NULL;
32         char                       **params = NULL;
33         struct buffer_ctx            ctx;
34         int                          count = 0;
35         int                          i;
36
37         memset(&ctx, 0, sizeof(ctx));
38
39         params = getcgivars(argc, argv);
40         for (i = 0; params != NULL && params[i] != NULL; i += 2) {
41                 if (!strcmp(params[i], "keytext")) {
42                         ctx.buffer = params[i+1];
43                         ctx.size = strlen(ctx.buffer);
44                 } else {
45                         free(params[i+1]);
46                 }
47                 params[i+1] = NULL;
48                 free(params[i]);
49                 params[i] = NULL;
50         }
51         if (params != NULL) {
52                 free(params);
53                 params = NULL;
54         }
55
56         start_html("onak : Add");
57         if (ctx.buffer == NULL) {
58                 puts("Error: No keytext to add supplied.");
59                 end_html();
60         } else {
61                 readconfig(NULL);
62                 initlogthing("add", config.logfile);
63                 dearmor_openpgp_stream(buffer_fetchchar,
64                                         &ctx,
65                                         &packets);
66                 if (packets != NULL) {
67                         printf("Storing %d keys.\n",
68                                 parse_keys(packets, &keys));
69                         end_html();
70                         fclose(stdout);
71                         fclose(stderr);
72                         initdb(false);
73                         count = update_keys(&keys);
74                         printf("Got %d new keys.\n", count);
75                         logthing(LOGTHING_NOTICE, "Got %d new keys.",
76                                 count);
77                         if (keys != NULL) {
78                                 sendkeysync(keys);
79                                 free_publickey(keys);
80                                 keys = NULL;
81                         }
82                         cleanupdb();
83                 } else {
84                         puts("No OpenPGP packets found in input.");
85                         end_html();
86                 }
87                 cleanuplogthing();
88                 cleanupconfig();
89         }
90         return (EXIT_SUCCESS);
91 }