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, see <https://www.gnu.org/licenses/>.
27 #include "charfuncs.h"
32 #include "onak-conf.h"
35 int main(int argc, char *argv[])
37 struct openpgp_packet_list *packets = NULL;
38 struct openpgp_publickey *keys = NULL;
40 struct buffer_ctx ctx;
43 struct onak_dbctx *dbctx;
45 memset(&ctx, 0, sizeof(ctx));
47 params = getcgivars(argc, argv);
48 for (i = 0; params != NULL && params[i] != NULL; i += 2) {
49 if (!strcmp(params[i], "keytext")) {
50 ctx.buffer = params[i+1];
51 ctx.size = strlen(ctx.buffer);
64 start_html("onak : Add");
65 if (ctx.buffer == NULL) {
66 puts("Error: No keytext to add supplied.");
70 initlogthing("add", config.logfile);
71 dearmor_openpgp_stream(buffer_fetchchar,
74 if (packets != NULL) {
75 count = parse_keys(packets, &keys);
76 logthing(LOGTHING_NOTICE, "Received %d keys.",
78 printf("Key block added to key server database.\n");
79 printf(" New public keys added: %d\n", count);
81 if (stdout != NULL && fileno(stdout) != -1) {
84 if (stderr != NULL && stderr != stdout &&
85 fileno(stderr) != -1) {
89 dbctx = config.dbinit(config.backend, false);
91 count = cleankeys(dbctx, &keys, config.clean_policies);
92 logthing(LOGTHING_INFO, "%d keys cleaned.",
95 count = dbctx->update_keys(dbctx, &keys,
97 config.clean_policies & ONAK_CLEAN_UPDATE_ONLY,
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);