X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/blobdiff_plain/316f1bb1d6915d509f9bee0508922858b103d243..HEAD:/keydb_pg.c diff --git a/keydb_pg.c b/keydb_pg.c index e71ddee..1ec0a1a 100644 --- a/keydb_pg.c +++ b/keydb_pg.c @@ -1,9 +1,20 @@ /* * keydb_pg.c - Routines to store and fetch keys in a PostGres database. * - * Jonathan McDowell + * Copyright 2002-2004 Jonathan McDowell * - * Copyright 2002-2004 Project Purple + * 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 @@ -36,7 +47,7 @@ static PGconn *dbconn = NULL; /** * keydb_fetchchar - Fetches a char from a file. */ -static int keydb_fetchchar(void *fd, size_t count, unsigned char *c) +static int keydb_fetchchar(void *fd, size_t count, void *c) { return (!lo_read(dbconn, *(int *) fd, (char *) c, count)); } @@ -44,7 +55,7 @@ static int keydb_fetchchar(void *fd, size_t count, unsigned char *c) /** * keydb_putchar - Puts a char to a file. */ -static int keydb_putchar(void *fd, size_t count, unsigned char *c) +static int keydb_putchar(void *fd, size_t count, void *c) { return !(lo_write(dbconn, *(int *) fd, (char *) c, count)); } @@ -358,12 +369,15 @@ static int pg_store_key(struct openpgp_publickey *publickey, bool intrans, char *primary = NULL; char *safeuid = NULL; int i; + uint64_t keyid; if (!intrans) { result = PQexec(dbconn, "BEGIN"); PQclear(result); } + get_keyid(publickey, &keyid); + /* * Delete the key if we already have it. * @@ -373,7 +387,7 @@ static int pg_store_key(struct openpgp_publickey *publickey, bool intrans, * it definitely needs updated. */ if (update) { - pg_delete_key(get_keyid(publickey), true); + pg_delete_key(keyid, true); } next = publickey->next; @@ -395,7 +409,7 @@ static int pg_store_key(struct openpgp_publickey *publickey, bool intrans, snprintf(statement, 1023, "INSERT INTO onak_keys (keyid, keydata) VALUES " "('%" PRIX64 "', '%d')", - get_keyid(publickey), + keyid, key_oid); result = PQexec(dbconn, statement); @@ -418,7 +432,7 @@ static int pg_store_key(struct openpgp_publickey *publickey, bool intrans, "INSERT INTO onak_uids " "(keyid, uid, pri) " "VALUES ('%" PRIX64 "', '%s', '%c')", - get_keyid(publickey), + keyid, safeuid, (uids[i] == primary) ? 't' : 'f'); result = PQexec(dbconn, statement); @@ -453,7 +467,7 @@ static int pg_store_key(struct openpgp_publickey *publickey, bool intrans, "INSERT INTO onak_sigs (signer, signee) " "VALUES ('%" PRIX64 "', '%" PRIX64 "')", sig_keyid(packets->packet), - get_keyid(publickey)); + keyid); result = PQexec(dbconn, statement); PQclear(result); }