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;
46 struct onak_dbctx *dbctx;
48 memset(&ctx, 0, sizeof(ctx));
50 params = getcgivars(argc, argv);
51 for (i = 0; params != NULL && params[i] != NULL; i += 2) {
52 if (!strcmp(params[i], "keytext")) {
53 ctx.buffer = params[i+1];
54 ctx.size = strlen(ctx.buffer);
67 start_html("onak : Add");
68 if (ctx.buffer == NULL) {
69 puts("Error: No keytext to add supplied.");
73 initlogthing("add", config.logfile);
74 dearmor_openpgp_stream(buffer_fetchchar,
77 if (packets != NULL) {
78 count = parse_keys(packets, &keys);
79 logthing(LOGTHING_NOTICE, "Received %d keys.",
81 printf("Key block added to key server database.\n");
82 printf(" New public keys added: %d\n", count);
84 if (stdout != NULL && fileno(stdout) != -1) {
87 if (stderr != NULL && stderr != stdout &&
88 fileno(stderr) != -1) {
92 dbctx = config.dbinit(config.backend, false);
94 count = cleankeys(keys);
95 logthing(LOGTHING_INFO, "%d keys cleaned.",
98 count = dbctx->update_keys(dbctx, &keys, true);
99 logthing(LOGTHING_NOTICE, "Got %d new keys.",
103 free_publickey(keys);
107 dbctx->cleanupdb(dbctx);
109 puts("No OpenPGP packets found in input.");
115 return (EXIT_SUCCESS);