X-Git-Url: https://the.earth.li/gitweb/?a=blobdiff_plain;f=keydb_pg.c;h=7d59640b0fd2a82189f0411fe2f0d5018c7fdf97;hb=dfab9e96ee1fa4a10acf9c1cf644d7a4366a5af6;hp=ca7e35bac0545796f4fe32c768a4b47af2ec78d0;hpb=8e0907be1d73011075a99a0c029c56664e12843e;p=onak.git diff --git a/keydb_pg.c b/keydb_pg.c index ca7e35b..7d59640 100644 --- a/keydb_pg.c +++ b/keydb_pg.c @@ -13,8 +13,7 @@ * 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. + * this program. If not, see . */ #include @@ -248,13 +247,14 @@ static int pg_fetch_key_text(struct onak_dbctx *dbctx, /** * delete_key - Given a keyid delete the key from storage. - * @keyid: The keyid to delete. + * @fp: The fingerprint of the key to delete. * @intrans: If we're already in a transaction. * * This function deletes a public key from whatever storage mechanism we * are using. Returns 0 if the key existed. */ -static int pg_delete_key(struct onak_dbctx *dbctx, uint64_t keyid, bool intrans) +static int pg_delete_key(struct onak_dbctx *dbctx, + struct openpgp_fingerprint *fp, bool intrans) { PGconn *dbconn = (PGconn *) dbctx->priv; PGresult *result = NULL; @@ -263,11 +263,14 @@ static int pg_delete_key(struct onak_dbctx *dbctx, uint64_t keyid, bool intrans) int found = 1; int i; Oid key_oid; + uint64_t keyid; if (!intrans) { result = PQexec(dbconn, "BEGIN"); PQclear(result); } + + keyid = fingerprint2keyid(fp); snprintf(statement, 1023, "SELECT keydata FROM onak_keys WHERE keyid = '%" @@ -348,6 +351,7 @@ static int pg_store_key(struct onak_dbctx *dbctx, int i; uint64_t keyid; struct pg_fc_ctx fcctx; + struct openpgp_fingerprint fp; if (!intrans) { result = PQexec(dbconn, "BEGIN"); @@ -368,7 +372,8 @@ static int pg_store_key(struct onak_dbctx *dbctx, * it definitely needs updated. */ if (update) { - pg_delete_key(dbctx, keyid, true); + get_fingerprint(publickey->publickey, &fp); + pg_delete_key(dbctx, &fp, true); } next = publickey->next; @@ -638,7 +643,6 @@ static int pg_iterate_keys(struct onak_dbctx *dbctx, /* * Include the basic keydb routines. */ -#define NEED_GETFULLKEYID 1 #define NEED_UPDATEKEYS 1 #define NEED_GET_FP 1 #include "keydb.c" @@ -666,7 +670,7 @@ static void pg_cleanupdb(struct onak_dbctx *dbctx) * this file are called in order to allow the DB to be initialized ready * for access. */ -struct onak_dbctx *keydb_pg_init(bool readonly) +struct onak_dbctx *keydb_pg_init(struct onak_db_config *dbcfg, bool readonly) { struct onak_dbctx *dbctx; PGconn *dbconn; @@ -675,14 +679,15 @@ struct onak_dbctx *keydb_pg_init(bool readonly) if (dbctx == NULL) { return NULL; } + dbctx->config = dbcfg; - dbconn = PQsetdbLogin(config.pg_dbhost, // host + dbconn = PQsetdbLogin(dbcfg->hostname, // host NULL, // port NULL, // options NULL, // tty - config.pg_dbname, // database - config.pg_dbuser, //login - config.pg_dbpass); // password + dbcfg->location, // database + dbcfg->username, //login + dbcfg->password); // password if (PQstatus(dbconn) == CONNECTION_BAD) { logthing(LOGTHING_CRITICAL, "Connection to database failed."); @@ -706,7 +711,6 @@ struct onak_dbctx *keydb_pg_init(bool readonly) dbctx->getkeysigs = pg_getkeysigs; dbctx->cached_getkeysigs = generic_cached_getkeysigs; dbctx->keyid2uid = pg_keyid2uid; - dbctx->getfullkeyid = generic_getfullkeyid; dbctx->iterate_keys = pg_iterate_keys; return dbctx;