diff options
author | Florian Dold <florian@dold.me> | 2021-03-01 23:25:21 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-03-01 23:25:21 +0100 |
commit | e29a6603fd830338742d295b426728cfd7c9c4af (patch) | |
tree | ca60f138b4a7a9e2765571c197b165ce41e0e009 /src/backenddb/plugin_merchantdb_postgres.c | |
parent | c18d676333c148a3c9fb5eea75089c1cff599c21 (diff) | |
download | merchant-e29a6603fd830338742d295b426728cfd7c9c4af.tar.gz merchant-e29a6603fd830338742d295b426728cfd7c9c4af.tar.bz2 merchant-e29a6603fd830338742d295b426728cfd7c9c4af.zip |
towards updated auth API (tests still missing)
Diffstat (limited to 'src/backenddb/plugin_merchantdb_postgres.c')
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 616172f1..a1b659db 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -343,6 +343,11 @@ struct LookupInstancesContext struct TALER_MERCHANTDB_InstanceSettings is; /** + * Instance authentication settings, valid only during find_instances_cb(). + */ + struct TALER_MERCHANTDB_InstanceAuthSettings ias; + + /** * Instance serial number, valid only during find_instances_cb(). */ uint64_t instance_serial; @@ -407,6 +412,7 @@ call_with_accounts (struct LookupInstancesContext *lic, &lic->merchant_pub, (0 == qs) ? NULL : &merchant_priv, &lic->is, + &lic->ias, num_accounts, accounts); } @@ -493,11 +499,11 @@ lookup_instances_cb (void *cls, &lic->merchant_pub), GNUNET_PQ_result_spec_allow_null ( GNUNET_PQ_result_spec_auto_from_type ("auth_hash", - &lic->is.auth_hash), + &lic->ias.auth_hash), &no_auth), GNUNET_PQ_result_spec_allow_null ( GNUNET_PQ_result_spec_auto_from_type ("auth_salt", - &lic->is.auth_salt), + &lic->ias.auth_salt), &no_salt), GNUNET_PQ_result_spec_string ("merchant_id", &lic->is.id), @@ -524,12 +530,12 @@ lookup_instances_cb (void *cls, GNUNET_PQ_query_param_end }; - memset (&lic->is.auth_salt, + memset (&lic->ias.auth_salt, 0, - sizeof (lic->is.auth_salt)); - memset (&lic->is.auth_hash, + sizeof (lic->ias.auth_salt)); + memset (&lic->ias.auth_hash, 0, - sizeof (lic->is.auth_hash)); + sizeof (lic->ias.auth_hash)); if (GNUNET_OK != GNUNET_PQ_extract_result (result, rs, @@ -610,13 +616,14 @@ static enum GNUNET_DB_QueryStatus postgres_insert_instance (void *cls, const struct TALER_MerchantPublicKeyP *merchant_pub, const struct TALER_MerchantPrivateKeyP *merchant_priv, - const struct TALER_MERCHANTDB_InstanceSettings *is) + const struct TALER_MERCHANTDB_InstanceSettings *is, + const struct TALER_MERCHANTDB_InstanceAuthSettings *ias) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (merchant_pub), - GNUNET_PQ_query_param_auto_from_type (&is->auth_hash), - GNUNET_PQ_query_param_auto_from_type (&is->auth_salt), + GNUNET_PQ_query_param_auto_from_type (&ias->auth_hash), + GNUNET_PQ_query_param_auto_from_type (&ias->auth_salt), GNUNET_PQ_query_param_string (is->id), GNUNET_PQ_query_param_string (is->name), TALER_PQ_query_param_json (is->address), @@ -753,6 +760,31 @@ postgres_update_instance (void *cls, GNUNET_PQ_query_param_relative_time ( &is->default_wire_transfer_delay), GNUNET_PQ_query_param_relative_time (&is->default_pay_delay), + GNUNET_PQ_query_param_end + }; + + check_connection (pg); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "update_instance", + params); +} + +/** + * Update information about an instance's authentication settings + * into our database. + * + * @param cls closure + * @param ias details about the instance + * @return database result code + */ +static enum GNUNET_DB_QueryStatus +postgres_update_instance_auth (void *cls, + const char *merchant_id, + const struct TALER_MERCHANTDB_InstanceAuthSettings *is) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (merchant_id), GNUNET_PQ_query_param_auto_from_type (&is->auth_hash), GNUNET_PQ_query_param_auto_from_type (&is->auth_salt), GNUNET_PQ_query_param_end @@ -760,7 +792,7 @@ postgres_update_instance (void *cls, check_connection (pg); return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "update_instance", + "update_instance_auth", params); } @@ -6149,10 +6181,15 @@ postgres_connect (void *cls) ",default_wire_fee_amortization=$9" ",default_wire_transfer_delay=$10" ",default_pay_delay=$11" - ",auth_hash=$12" - ",auth_salt=$13" " WHERE merchant_id = $1", - 13), + 11), + /* for postgres_update_instance_auth() */ + GNUNET_PQ_make_prepare ("update_instance_auth", + "UPDATE merchant_instances SET" + " auth_hash=$2" + ",auth_salt=$3" + " WHERE merchant_id = $1", + 3), /* for postgres_inactivate_account() */ GNUNET_PQ_make_prepare ("inactivate_account", "UPDATE merchant_accounts SET" @@ -8487,6 +8524,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) plugin->delete_instance_private_key = &postgres_delete_instance_private_key; plugin->purge_instance = &postgres_purge_instance; plugin->update_instance = &postgres_update_instance; + plugin->update_instance_auth = &postgres_update_instance_auth; plugin->activate_account = &postgres_activate_account; plugin->inactivate_account = &postgres_inactivate_account; plugin->lookup_products = &postgres_lookup_products; |