From 8c7900c40bc5e1607277a2573c5b29fb8d5bc5be Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Fri, 2 Oct 2020 19:49:19 -0500 Subject: [PATCH] hdb: Use db type preference from ./configure Use the HDB backend type from the --with-db-type-preference=... option to ./configure to make the default HDB backend more stable. --- lib/hdb/Makefile.am | 1 + lib/hdb/hdb.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/hdb/Makefile.am b/lib/hdb/Makefile.am index 692242323..7ebd4dd08 100644 --- a/lib/hdb/Makefile.am +++ b/lib/hdb/Makefile.am @@ -7,6 +7,7 @@ AM_CPPFLAGS += $(INCLUDE_openldap) -DHDB_DB_DIR=\"$(DIR_hdbdir)\" AM_CPPFLAGS += -I$(srcdir)/../krb5 AM_CPPFLAGS += $(INCLUDE_sqlite3) AM_CPPFLAGS += $(INCLUDE_libintl) +AM_CPPFLAGS += -DHDB_DEFAULT_DB_TYPE=\"$(db_type):\" if HAVE_DBHEADER AM_CPPFLAGS += -I$(DBHEADER) endif diff --git a/lib/hdb/hdb.c b/lib/hdb/hdb.c index 4934cb1c7..e89c64aa1 100644 --- a/lib/hdb/hdb.c +++ b/lib/hdb/hdb.c @@ -802,7 +802,19 @@ hdb_create(krb5_context context, HDB **db, const char *filename) *db = NULL; } } +#ifdef HDB_DEFAULT_DB_TYPE + if (cb_ctx.h == NULL || cb_ctx.h->prefix == NULL) { + /* + * If still we've not picked a backend, use a build configuration time + * default. + */ + for (cb_ctx.h = methods; cb_ctx.h->prefix != NULL; cb_ctx.h++) + if (strcmp(cb_ctx.h->prefix, HDB_DEFAULT_DB_TYPE) == 0) + break; + } +#endif if (cb_ctx.h == NULL || cb_ctx.h->prefix == NULL) + /* Last resort default */ cb_ctx.h = &default_dbmethod; if (cb_ctx.h == NULL || cb_ctx.h->prefix == NULL) { krb5_set_error_message(context, ENOTSUP,