challenger

OAuth 2.0-based authentication service that validates user can receive messages at a certain address
Log | Files | Refs | Submodules | README | LICENSE

commit 3186e3c49e456f0389101904a4cdcc6861c604cd
parent 7ad0be8ea7e217ef1a713f471661d8c8dee1df75
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 22 Nov 2024 19:58:58 +0100

make challenger-admin idempotent

Diffstat:
Msrc/challenger/challenger-admin.c | 24++++++++++++++++++++++++
Msrc/challengerdb/pg_client_check.c | 31+++++++++++++++++++++++++++++++
Msrc/challengerdb/pg_client_check.h | 16++++++++++++++++
Msrc/challengerdb/plugin_challengerdb_postgres.c | 2++
Msrc/include/challenger_database_plugin.h | 16++++++++++++++++
5 files changed, 89 insertions(+), 0 deletions(-)

diff --git a/src/challenger/challenger-admin.c b/src/challenger/challenger-admin.c @@ -183,6 +183,30 @@ run (void *cls, enum GNUNET_DB_QueryStatus qs; uint64_t row_id; + qs = plugin->client_check2 (plugin->cls, + redirect_uri, + client_secret, + &row_id); + switch (qs) + { + case GNUNET_DB_STATUS_SOFT_ERROR: + case GNUNET_DB_STATUS_HARD_ERROR: + GNUNET_break (0); + global_ret = EXIT_FAILURE; + goto cleanup; + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + break; + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + if (be_quiet) + fprintf (stdout, + "%llu\n", + (unsigned long long) row_id); + else + fprintf (stdout, + "Client added. Client ID is: %llu\n", + (unsigned long long) row_id); + goto cleanup; + } qs = plugin->client_add (plugin->cls, redirect_uri, client_secret, diff --git a/src/challengerdb/pg_client_check.c b/src/challengerdb/pg_client_check.c @@ -61,3 +61,34 @@ CH_PG_client_check (void *cls, params, rs); } + + +enum GNUNET_DB_QueryStatus +CH_PG_client_check2 (void *cls, + const char *client_uri, + const char *client_secret, + uint64_t *client_id) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (client_uri), + GNUNET_PQ_query_param_string (client_secret), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("client_serial_id", + client_id), + GNUNET_PQ_result_spec_end + }; + + PREPARE (pg, + "client_check2", + "SELECT client_serial_id" + " FROM clients" + " WHERE uri=$1" + " AND client_secret=$2;"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "client_check2", + params, + rs); +} diff --git a/src/challengerdb/pg_client_check.h b/src/challengerdb/pg_client_check.h @@ -45,4 +45,20 @@ CH_PG_client_check (void *cls, uint32_t counter_increment, char **client_url); + +/** + * Check if a client is in the list of authorized clients. + * + * @param cls + * @param client_url client redirect URL (if known) + * @param client_secret secret of the client + * @param[out] set to client_id ID of the client if found + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +CH_PG_client_check2 (void *cls, + const char *client_url, + const char *client_secret, + uint64_t *client_id); + #endif diff --git a/src/challengerdb/plugin_challengerdb_postgres.c b/src/challengerdb/plugin_challengerdb_postgres.c @@ -396,6 +396,8 @@ libchallenger_plugin_db_postgres_init (void *cls) = &CH_PG_client_delete; plugin->client_check = &CH_PG_client_check; + plugin->client_check2 + = &CH_PG_client_check2; plugin->setup_nonce = &CH_PG_setup_nonce; plugin->authorize_start diff --git a/src/include/challenger_database_plugin.h b/src/include/challenger_database_plugin.h @@ -216,6 +216,22 @@ struct CHALLENGER_DatabasePlugin /** + * Check if a client is in the list of authorized clients. + * + * @param cls + * @param client_url client redirect URL (if known) + * @param client_secret secret of the client + * @param[out] set to client_id ID of the client if found + * @return transaction status + */ + enum GNUNET_DB_QueryStatus + (*client_check2)(void *cls, + const char *client_url, + const char *client_secret, + uint64_t *client_id); + + + /** * Start validation process by setting up a validation entry. Allows * the respective user who learns the @a nonce to later begin the * process.