2 * add.c - CGI to add keys.
4 * Copyright 2002-2004,2007-2008 Jonathan McDowell <noodles@earth.li>
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #include "charfuncs.h"
31 #include "keystructs.h"
35 #include "onak-conf.h"
38 int main(int argc, char *argv[])
40 struct openpgp_packet_list *packets = NULL;
41 struct openpgp_publickey *keys = NULL;
43 struct buffer_ctx ctx;
47 memset(&ctx, 0, sizeof(ctx));
49 params = getcgivars(argc, argv);
50 for (i = 0; params != NULL && params[i] != NULL; i += 2) {
51 if (!strcmp(params[i], "keytext")) {
52 ctx.buffer = params[i+1];
53 ctx.size = strlen(ctx.buffer);
66 start_html("onak : Add");
67 if (ctx.buffer == NULL) {
68 puts("Error: No keytext to add supplied.");
72 initlogthing("add", config.logfile);
73 dearmor_openpgp_stream(buffer_fetchchar,
76 if (packets != NULL) {
77 count = parse_keys(packets, &keys);
78 logthing(LOGTHING_NOTICE, "Received %d keys.",
80 printf("Key block added to key server database.\n");
81 printf(" New public keys added: %d\n", count);
83 if (stdout != NULL && fileno(stdout) != -1) {
86 if (stderr != NULL && stderr != stdout &&
87 fileno(stderr) != -1) {
91 config.dbbackend->initdb(false);
93 count = cleankeys(keys);
94 logthing(LOGTHING_INFO, "%d keys cleaned.",
97 count = config.dbbackend->update_keys(&keys, true);
98 logthing(LOGTHING_NOTICE, "Got %d new keys.",
102 free_publickey(keys);
106 config.dbbackend->cleanupdb();
108 puts("No OpenPGP packets found in input.");
114 return (EXIT_SUCCESS);