2 * add.c - CGI to add keys.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
17 #include "charfuncs.h"
20 #include "keystructs.h"
24 #include "onak-conf.h"
27 int main(int argc, char *argv[])
29 struct openpgp_packet_list *packets = NULL;
30 struct openpgp_publickey *keys = NULL;
32 struct buffer_ctx ctx;
36 memset(&ctx, 0, sizeof(ctx));
38 params = getcgivars(argc, argv);
39 for (i = 0; params != NULL && params[i] != NULL; i += 2) {
40 if (!strcmp(params[i], "keytext")) {
41 ctx.buffer = params[i+1];
42 ctx.size = strlen(ctx.buffer);
55 start_html("onak : Add");
56 if (ctx.buffer == NULL) {
57 puts("Error: No keytext to add supplied.");
61 initlogthing("add", config.logfile);
62 dearmor_openpgp_stream(buffer_fetchchar,
65 if (packets != NULL) {
66 count = parse_keys(packets, &keys);
67 logthing(LOGTHING_NOTICE, "Received %d keys.",
69 printf("Key block added to key server database.\n");
70 printf(" New public keys added: %d\n", count);
72 if (stdout != NULL && fileno(stdout) != -1) {
75 if (stderr != NULL && stderr != stdout &&
76 fileno(stderr) != -1) {
80 config.dbbackend->initdb(false);
82 count = cleankeys(keys);
83 logthing(LOGTHING_INFO, "%d keys cleaned.",
86 count = config.dbbackend->update_keys(&keys, true);
87 logthing(LOGTHING_NOTICE, "Got %d new keys.",
95 config.dbbackend->cleanupdb();
97 puts("No OpenPGP packets found in input.");
103 return (EXIT_SUCCESS);