X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/blobdiff_plain/b7a5a70eb8d8f312325af828b47726977f4fbb79..b46987cfe602a9a7e2c98bae1528b4a6cdf3e56e:/keydb_fs.c?ds=sidebyside diff --git a/keydb_fs.c b/keydb_fs.c index 7e739d8..7de5bac 100644 --- a/keydb_fs.c +++ b/keydb_fs.c @@ -5,7 +5,7 @@ * * Copyright 2004 Daniel Silverstone and Project Purple * - * $Id: keydb_fs.c,v 1.1 2004/05/27 03:37:58 noodles Exp $ + * $Id: keydb_fs.c,v 1.3 2004/05/28 03:23:04 noodles Exp $ */ #include @@ -45,7 +45,7 @@ static uint32_t calchash(uint8_t * ptr) { register uint32_t h = FNV_offset_basis; register uint32_t p = FNV_mixing_prime; - register uint32_t n = strlen(ptr); + register uint32_t n = strlen((char *) ptr); register uint8_t *c = ptr; while (n--) { h *= p; @@ -58,7 +58,7 @@ static uint32_t calchash(uint8_t * ptr) void keypath(char *buffer, uint64_t _keyid) { uint64_t keyid = _keyid << 32; - snprintf(buffer, PATH_MAX, "%s/key/%02X/%02X/%08lX/%016llX", + snprintf(buffer, PATH_MAX, "%s/key/%02X/%02X/%08X/%016llX", config.db_dir, (uint8_t) ((keyid >> 56) & 0xFF), (uint8_t) ((keyid >> 48) & 0xFF), (uint32_t) (keyid >> 32), _keyid); @@ -67,7 +67,7 @@ void keypath(char *buffer, uint64_t _keyid) void keydir(char *buffer, uint64_t _keyid) { uint64_t keyid = _keyid << 32; - snprintf(buffer, PATH_MAX, "%s/key/%02X/%02X/%08lX", config.db_dir, + snprintf(buffer, PATH_MAX, "%s/key/%02X/%02X/%08X", config.db_dir, (uint8_t) ((keyid >> 56) & 0xFF), (uint8_t) ((keyid >> 48) & 0xFF), (uint32_t) (keyid >> 32)); @@ -88,7 +88,7 @@ void prove_path_to(uint64_t keyid, char *what) (uint8_t) ((keyid >> 16) & 0xFF)); mkdir(buffer, 0777); - snprintf(buffer, PATH_MAX, "%s/%s/%02X/%02X/%08lX", config.db_dir, what, + snprintf(buffer, PATH_MAX, "%s/%s/%02X/%02X/%08X", config.db_dir, what, (uint8_t) ((keyid >> 24) & 0xFF), (uint8_t) ((keyid >> 16) & 0xFF), (uint32_t) (keyid)); mkdir(buffer, 0777); @@ -96,14 +96,14 @@ void prove_path_to(uint64_t keyid, char *what) void wordpath(char *buffer, char *word, uint32_t hash, uint64_t keyid) { - snprintf(buffer, PATH_MAX, "%s/words/%02X/%02X/%08lX/%s/%016llX", + snprintf(buffer, PATH_MAX, "%s/words/%02X/%02X/%08X/%s/%016llX", config.db_dir, (uint8_t) ((hash >> 24) & 0xFF), (uint8_t) ((hash >> 16) & 0xFF), hash, word, keyid); } void worddir(char *buffer, char *word, uint32_t hash) { - snprintf(buffer, PATH_MAX, "%s/words/%02X/%02X/%08lX/%s", config.db_dir, + snprintf(buffer, PATH_MAX, "%s/words/%02X/%02X/%08X/%s", config.db_dir, (uint8_t) ((hash >> 24) & 0xFF), (uint8_t) ((hash >> 16) & 0xFF), hash, word); } @@ -279,9 +279,7 @@ int store_key(struct openpgp_publickey *publickey, bool intrans, wl = wl->next; } - - - llfree(wordlist, NULL); + llfree(wordlist, free); } if (!intrans) @@ -377,16 +375,20 @@ int fetch_key_text(const char *search, { struct ll *wordlist = NULL, *wl = NULL; struct ll *keylist = NULL; + char *searchtext = NULL; int addedkeys = 0; logthing(LOGTHING_CRITICAL, "Search was '%s'", search); - wl = wordlist = makewordlist(wordlist, search); + searchtext = strdup(search); + wl = wordlist = makewordlist(wordlist, searchtext); keylist = internal_get_key_by_word(wordlist->object, NULL); if (!keylist) { llfree(wordlist, NULL); + free(searchtext); + searchtext = NULL; return 0; } @@ -397,6 +399,8 @@ int fetch_key_text(const char *search, if (!nkl) { llfree(wordlist, NULL); llfree(keylist, free); + free(searchtext); + searchtext = NULL; return 0; } llfree(keylist, free); @@ -419,6 +423,8 @@ int fetch_key_text(const char *search, } llfree(keylist, free); + free(searchtext); + searchtext = NULL; return addedkeys; }