X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/blobdiff_plain/d55ec9e986e5c0c7345ae0e6a1449c4292291b32..393d83b8760584006eaefd6fc370abead228e02a:/keydb_file.c?ds=inline diff --git a/keydb_file.c b/keydb_file.c index 243e59e..4a4322b 100644 --- a/keydb_file.c +++ b/keydb_file.c @@ -15,6 +15,7 @@ #include #include +#include "charfuncs.h" #include "keydb.h" #include "keyid.h" #include "keystructs.h" @@ -23,28 +24,12 @@ #include "onak-conf.h" #include "parsekey.h" -/** - * keydb_fetchchar - Fetches a char from a file. - */ -static int keydb_fetchchar(void *fd, size_t count, unsigned char *c) -{ - return !(read( *(int *) fd, c, count)); -} - -/** - * keydb_putchar - Puts a char to a file. - */ -static int keydb_putchar(void *fd, size_t count, unsigned char *c) -{ - return !(write( *(int *) fd, c, count)); -} - /** * initdb - Initialize the key database. * * This is just a no-op for flat file access. */ -void initdb(void) +void initdb(bool readonly) { } @@ -96,13 +81,15 @@ int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey, char keyfile[1024]; int fd = -1; - snprintf(keyfile, 1023, "%s/0x%llX", config.file_dbpath, + snprintf(keyfile, 1023, "%s/0x%llX", config.db_dir, keyid & 0xFFFFFFFF); fd = open(keyfile, O_RDONLY); // | O_SHLOCK); if (fd > -1) { - read_openpgp_stream(keydb_fetchchar, &fd, &packets); + read_openpgp_stream(file_fetchchar, &fd, &packets, 0); parse_keys(packets, publickey); + free_packet_list(packets); + packets = NULL; close(fd); } @@ -128,7 +115,7 @@ int store_key(struct openpgp_publickey *publickey, bool intrans, bool update) char keyfile[1024]; int fd = -1; - snprintf(keyfile, 1023, "%s/0x%llX", config.file_dbpath, + snprintf(keyfile, 1023, "%s/0x%llX", config.db_dir, get_keyid(publickey) & 0xFFFFFFFF); fd = open(keyfile, O_WRONLY | O_CREAT, 0664); // | O_EXLOCK); @@ -138,8 +125,10 @@ int store_key(struct openpgp_publickey *publickey, bool intrans, bool update) flatten_publickey(publickey, &packets, &list_end); publickey -> next = next; - write_openpgp_stream(keydb_putchar, &fd, packets); + write_openpgp_stream(file_putchar, &fd, packets); close(fd); + free_packet_list(packets); + packets = NULL; } return (fd > -1); @@ -157,7 +146,7 @@ int delete_key(uint64_t keyid, bool intrans) { char keyfile[1024]; - snprintf(keyfile, 1023, "%s/0x%llX", config.file_dbpath, + snprintf(keyfile, 1023, "%s/0x%llX", config.db_dir, keyid & 0xFFFFFFFF); return unlink(keyfile); @@ -178,6 +167,21 @@ int fetch_key_text(const char *search, struct openpgp_publickey **publickey) return 0; } +/** + * dumpdb - dump the key database + * @filenamebase: The base filename to use for the dump. + * + * Dumps the database into one or more files, which contain pure OpenPGP + * that can be reimported into onak or gpg. filenamebase provides a base + * file name for the dump; several files may be created, all of which will + * begin with this string and then have a unique number and a .pgp + * extension. + * */ +int dumpdb(char *filenamebase) +{ + return 0; +} + /* * Include the basic keydb routines. */