X-Git-Url: http://the.earth.li/gitweb/?a=blobdiff_plain;f=onak.c;h=f67c969e513e47382cff59e1e5be867de36ed0bc;hb=cab77e4ffc25ba4fb2e5289beaa47c7d915de942;hp=4ba3a7abda38e76852f0150e1989a903a89fb7aa;hpb=d9432fa0982c0f7a736bf00c04969dedca347ea3;p=onak.git diff --git a/onak.c b/onak.c index 4ba3a7a..f67c969 100644 --- a/onak.c +++ b/onak.c @@ -3,9 +3,20 @@ * * This is the main swiss army knife binary. * - * Jonathan McDowell - * - * Copyright 2002 Project Purple + * Copyright 2002 Jonathan McDowell + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include @@ -33,14 +44,19 @@ #include "photoid.h" #include "version.h" -void find_keys(char *search, uint64_t keyid, bool ishex, - bool fingerprint, bool skshash, bool exact, bool verbose) +void find_keys(char *search, uint64_t keyid, uint8_t *fp, bool ishex, + bool isfp, bool fingerprint, bool skshash, bool exact, + bool verbose) { struct openpgp_publickey *publickey = NULL; int count = 0; if (ishex) { - count = config.dbbackend->fetch_key(keyid, &publickey, false); + count = config.dbbackend->fetch_key_id(keyid, &publickey, + false); + } else if (isfp) { + count = config.dbbackend->fetch_key_fp(fp, MAX_FINGERPRINT_LEN, + &publickey, false); } else { count = config.dbbackend->fetch_key_text(search, &publickey); } @@ -57,11 +73,19 @@ void find_keys(char *search, uint64_t keyid, bool ishex, } } +/** + * @brief Context for the keyserver dumping function + */ struct dump_ctx { + /** Keys we've dumped so far to this file */ int count; + /** Maximum keys to dump per file */ int maxcount; + /** File descriptor for the current dump file */ int fd; + /** Number of the current dump file */ int filenum; + /** Base filename to use for dump files */ char *filebase; }; @@ -92,6 +116,19 @@ void dump_func(void *ctx, struct openpgp_publickey *key) return; } +static uint8_t hex2bin(char c) +{ + if (c >= '0' && c <= '9') { + return (c - '0'); + } else if (c >= 'a' && c <= 'f') { + return (c - 'a' + 10); + } else if (c >= 'A' && c <= 'F') { + return (c - 'A' + 10); + } + + return 255; +} + void usage(void) { puts("onak " ONAK_VERSION " - an OpenPGP keyserver.\n"); puts("Usage:\n"); @@ -123,7 +160,10 @@ int main(int argc, char *argv[]) char *search = NULL; char *end = NULL; uint64_t keyid = 0; + uint8_t fp[MAX_FINGERPRINT_LEN]; + int i; bool ishex = false; + bool isfp = false; bool verbose = false; bool update = false; bool binary = false; @@ -277,7 +317,14 @@ int main(int argc, char *argv[]) } } else if ((argc - optind) == 2) { search = argv[optind+1]; - if (search != NULL) { + if (search != NULL && strlen(search) == 42 && + search[0] == '0' && search[1] == 'x') { + for (i = 0; i < MAX_FINGERPRINT_LEN; i++) { + fp[i] = (hex2bin(search[2 + i * 2]) << 4) + + hex2bin(search[3 + i * 2]); + } + isfp = true; + } else if (search != NULL) { keyid = strtoul(search, &end, 16); if (*search != 0 && end != NULL && @@ -287,21 +334,24 @@ int main(int argc, char *argv[]) } config.dbbackend->initdb(false); if (!strcmp("index", argv[optind])) { - find_keys(search, keyid, ishex, fingerprint, skshash, + find_keys(search, keyid, fp, ishex, isfp, + fingerprint, skshash, false, false); } else if (!strcmp("vindex", argv[optind])) { - find_keys(search, keyid, ishex, fingerprint, skshash, + find_keys(search, keyid, fp, ishex, isfp, + fingerprint, skshash, false, true); } else if (!strcmp("getphoto", argv[optind])) { if (!ishex) { puts("Can't get a key on uid text." " You must supply a keyid."); - } else if (config.dbbackend->fetch_key(keyid, &keys, + } else if (config.dbbackend->fetch_key_id(keyid, &keys, false)) { unsigned char *photo = NULL; size_t length = 0; - if (getphoto(keys, 0, &photo, &length)) { + if (getphoto(keys, 0, &photo, + &length) == ONAK_E_OK) { fwrite(photo, 1, length, @@ -317,11 +367,17 @@ int main(int argc, char *argv[]) config.dbbackend->getfullkeyid(keyid), false); } else if (!strcmp("get", argv[optind])) { - if (!ishex) { + if (!(ishex || isfp)) { puts("Can't get a key on uid text." - " You must supply a keyid."); - } else if (config.dbbackend->fetch_key(keyid, &keys, - false)) { + " You must supply a keyid / " + "fingerprint."); + } else if ((isfp && + config.dbbackend->fetch_key_fp(fp, + MAX_FINGERPRINT_LEN, + &keys, false)) || + (ishex && + config.dbbackend->fetch_key_id(keyid, + &keys, false))) { logthing(LOGTHING_INFO, "Got key."); flatten_publickey(keys, &packets,