challenger

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

commit 69fd977733bc07909553f6710a06b515f1e65674
parent fff07476270a0c82e7247783483f7d59a8d407f5
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 10 Nov 2024 17:22:00 +0100

ensure we do not start if the database version is outdated (#9203)

Diffstat:
Msrc/challenger/challenger-admin.c | 3++-
Msrc/challenger/challenger-httpd.c | 3++-
Msrc/challengerdb/challenger-dbinit.c | 3++-
Msrc/challengerdb/challenger_db_plugin.c | 12+++++++++++-
Msrc/challengerdb/plugin_challengerdb_postgres.c | 18++++++------------
Msrc/challengerdb/test_challenger_db.c | 16+++++++++-------
Msrc/include/challenger_database_lib.h | 10++++++++--
7 files changed, 40 insertions(+), 25 deletions(-)

diff --git a/src/challenger/challenger-admin.c b/src/challenger/challenger-admin.c @@ -95,7 +95,8 @@ run (void *cls, return; } if (NULL == - (plugin = CHALLENGER_DB_plugin_load (cfg))) + (plugin = CHALLENGER_DB_plugin_load (cfg, + false))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize database plugin.\n"); diff --git a/src/challenger/challenger-httpd.c b/src/challenger/challenger-httpd.c @@ -662,7 +662,8 @@ run (void *cls, &rc); rc = GNUNET_CURL_gnunet_rc_create (CH_ctx); if (NULL == - (CH_db = CHALLENGER_DB_plugin_load (config))) + (CH_db = CHALLENGER_DB_plugin_load (config, + false))) { global_ret = EXIT_NOTINSTALLED; GNUNET_SCHEDULER_shutdown (); diff --git a/src/challengerdb/challenger-dbinit.c b/src/challengerdb/challenger-dbinit.c @@ -60,7 +60,8 @@ run (void *cls, (void) args; (void) cfgfile; if (NULL == - (plugin = CHALLENGER_DB_plugin_load (cfg))) + (plugin = CHALLENGER_DB_plugin_load (cfg, + true))) { fprintf (stderr, "Failed to initialize database plugin.\n"); diff --git a/src/challengerdb/challenger_db_plugin.c b/src/challengerdb/challenger_db_plugin.c @@ -25,7 +25,8 @@ struct CHALLENGER_DatabasePlugin * -CHALLENGER_DB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg) +CHALLENGER_DB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg, + bool skip_preflight) { char *plugin_name; char *lib_name; @@ -52,6 +53,15 @@ CHALLENGER_DB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg) plugin->library_name = lib_name; else GNUNET_free (lib_name); + if ( (! skip_preflight) && + (GNUNET_OK != + plugin->preflight (plugin->cls)) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Database not ready. Try running challenger-dbinit!\n"); + CHALLENGER_DB_plugin_unload (plugin); + return NULL; + } return plugin; } diff --git a/src/challengerdb/plugin_challengerdb_postgres.c b/src/challengerdb/plugin_challengerdb_postgres.c @@ -130,11 +130,12 @@ internal_setup (struct PostgresClosure *pg) #endif struct GNUNET_PQ_Context *db_conn; - db_conn = GNUNET_PQ_connect_with_cfg (pg->cfg, - "challengerdb-postgres", - NULL, - es, - NULL); + db_conn = GNUNET_PQ_connect_with_cfg2 (pg->cfg, + "challengerdb-postgres", + "challenger-", + es, + NULL, + GNUNET_PQ_FLAG_CHECK_CURRENT); if (NULL == db_conn) return GNUNET_SYSERR; pg->conn = db_conn; @@ -371,13 +372,6 @@ libchallenger_plugin_db_postgres_init (void *cls) GNUNET_free (pg); return NULL; } - if (GNUNET_OK != - internal_setup (pg)) - { - GNUNET_free (pg->sql_dir); - GNUNET_free (pg); - return NULL; - } plugin = GNUNET_new (struct CHALLENGER_DatabasePlugin); plugin->cls = pg; plugin->create_tables diff --git a/src/challengerdb/test_challenger_db.c b/src/challengerdb/test_challenger_db.c @@ -27,14 +27,15 @@ #define FAILIF(cond) \ - do { \ - if (! (cond)) { break;} \ - GNUNET_break (0); \ - goto drop; \ - } while (0) + do { \ + if (! (cond)) { break;} \ + GNUNET_break (0); \ + goto drop; \ + } while (0) #define RND_BLK(ptr) \ - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (*ptr)) + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (* \ + ptr)) /** * Global return value for the test. Initially -1, set to 0 upon @@ -58,7 +59,8 @@ run (void *cls) { struct GNUNET_CONFIGURATION_Handle *cfg = cls; - if (NULL == (plugin = CHALLENGER_DB_plugin_load (cfg))) + if (NULL == (plugin = CHALLENGER_DB_plugin_load (cfg, + true))) { result = 77; return; diff --git a/src/include/challenger_database_lib.h b/src/include/challenger_database_lib.h @@ -14,7 +14,9 @@ Challenger; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * + * @file include/challenger_database_lib.h + * @brief database helper functions for postgres used by challenger + * @author Christian Grothoff */ #ifndef CHALLENGER_DB_LIB_H #define CHALLENGER_DB_LIB_H @@ -26,10 +28,14 @@ * Initialize the plugin. * * @param cfg configuration to use + * @param skip_preflight true if we should skip the usual + * preflight check which assures us that the DB is actually + * operational; only challenger-dbinit should use true here. * @return NULL on failure */ struct CHALLENGER_DatabasePlugin * -CHALLENGER_DB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg); +CHALLENGER_DB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg, + bool skip_preflight); /**