diff options
author | Andrew Tridgell <tridge@samba.org> | 2010-12-08 09:58:52 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2010-12-08 05:26:06 +0100 |
commit | 18177f1e52e2767e1266f44ea32a8f8d82a17b74 (patch) | |
tree | 44aabebc7f0fe78402834091bdee9bd86bfef6e0 /source4 | |
parent | cba73975c2868bb657962229c0c5e77009c0197d (diff) | |
download | samba-18177f1e52e2767e1266f44ea32a8f8d82a17b74.tar.gz samba-18177f1e52e2767e1266f44ea32a8f8d82a17b74.tar.bz2 samba-18177f1e52e2767e1266f44ea32a8f8d82a17b74.zip |
s4-dns: use ldb hooks for samba extensions in dlz_bind9
this avoids linking dlz_bind9 directly to heimdal, which allows a
RTLD_DEEPBIND in ldb module loading to find the right kerberos version
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4')
-rw-r--r-- | source4/dns_server/dlz_bind9.c | 84 |
1 files changed, 35 insertions, 49 deletions
diff --git a/source4/dns_server/dlz_bind9.c b/source4/dns_server/dlz_bind9.c index a3eaf333c3..573a0e8fab 100644 --- a/source4/dns_server/dlz_bind9.c +++ b/source4/dns_server/dlz_bind9.c @@ -30,6 +30,7 @@ #include "gen_ndr/ndr_dnsp.h" #include "lib/cmdline/popt_common.h" #include "lib/cmdline/popt_credentials.h" +#include "ldb_module.h" #include "dlz_bind9.h" struct dlz_bind9_data { @@ -234,54 +235,36 @@ static isc_result_t parse_options(struct dlz_bind9_data *state, int opt; poptContext pc; struct poptOption long_options[] = { - POPT_COMMON_SAMBA - POPT_COMMON_CREDENTIALS { "url", 'H', POPT_ARG_STRING, &options->url, 0, "database URL", "URL" }, { NULL } }; + struct poptOption **popt_options; + int ret; + + popt_options = ldb_module_popt_options(state->samdb); + (*popt_options) = long_options; - pc = poptGetContext("dlz_bind9", argc, (const char **)argv, long_options, + ret = ldb_modules_hook(state->samdb, LDB_MODULE_HOOK_CMDLINE_OPTIONS); + if (ret != LDB_SUCCESS) { + state->log(ISC_LOG_ERROR, "dlz samba: failed cmdline hook"); + return ISC_R_FAILURE; + } + + pc = poptGetContext("dlz_bind9", argc, (const char **)argv, *popt_options, POPT_CONTEXT_KEEP_FIRST); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { default: - state->log(ISC_LOG_ERROR, "Invalid option %s: %s", + state->log(ISC_LOG_ERROR, "dlz samba: Invalid option %s: %s", poptBadOption(pc, 0), poptStrerror(opt)); return ISC_R_FAILURE; } } - return ISC_R_SUCCESS; -} - - -/* - setup credentials and handlers for full ldb SAMDB support - */ -static isc_result_t b9_setup_samba_context(struct dlz_bind9_data *state) - -{ - int ret; - - ret = ldb_register_samba_handlers(state->samdb); + ret = ldb_modules_hook(state->samdb, LDB_MODULE_HOOK_CMDLINE_PRECONNECT); if (ret != LDB_SUCCESS) { - state->log(ISC_LOG_ERROR, "samba dlz_bind9: Failed to load Samba handlers"); - return ISC_R_FAILURE; - } - - gensec_init(state->lp); - - if (ldb_set_opaque(state->samdb, "sessionInfo", system_session(state->lp))) { - state->log(ISC_LOG_ERROR, "samba dlz_bind9: Failed to setup system session"); - return ISC_R_FAILURE; - } - if (ldb_set_opaque(state->samdb, "credentials", cmdline_credentials)) { - state->log(ISC_LOG_ERROR, "samba dlz_bind9: Failed to setup cmdline credentials"); - return ISC_R_FAILURE; - } - if (ldb_set_opaque(state->samdb, "loadparm", state->lp)) { - state->log(ISC_LOG_ERROR, "samba dlz_bind9: Failed to setup lp ctx"); + state->log(ISC_LOG_ERROR, "dlz samba: failed cmdline preconnect"); return ISC_R_FAILURE; } @@ -321,17 +304,6 @@ _PUBLIC_ isc_result_t dlz_create(const char *dlzname, } va_end(ap); - result = parse_options(state, argc, argv, &options); - if (result != ISC_R_SUCCESS) { - goto failed; - } - - state->lp = loadparm_init_global(true); - if (state->lp == NULL) { - result = ISC_R_NOMEMORY; - goto failed; - } - state->ev_ctx = s4_event_context_init(state); if (state->ev_ctx == NULL) { result = ISC_R_NOMEMORY; @@ -345,6 +317,17 @@ _PUBLIC_ isc_result_t dlz_create(const char *dlzname, goto failed; } + result = parse_options(state, argc, argv, &options); + if (result != ISC_R_SUCCESS) { + goto failed; + } + + state->lp = loadparm_init_global(true); + if (state->lp == NULL) { + result = ISC_R_NOMEMORY; + goto failed; + } + if (options.url == NULL) { options.url = talloc_asprintf(tmp_ctx, "ldapi://%s", private_path(tmp_ctx, state->lp, "ldap_priv/ldapi")); @@ -354,11 +337,6 @@ _PUBLIC_ isc_result_t dlz_create(const char *dlzname, } } - result = b9_setup_samba_context(state); - if (result != ISC_R_SUCCESS) { - goto failed; - } - ret = ldb_connect(state->samdb, options.url, 0, NULL); if (ret == -1) { state->log(ISC_LOG_ERROR, "samba dlz_bind9: Failed to connect to %s - %s", @@ -367,6 +345,14 @@ _PUBLIC_ isc_result_t dlz_create(const char *dlzname, goto failed; } + ret = ldb_modules_hook(state->samdb, LDB_MODULE_HOOK_CMDLINE_POSTCONNECT); + if (ret != LDB_SUCCESS) { + state->log(ISC_LOG_ERROR, "samba dlz_bind9: Failed postconnect for %s - %s", + options.url, ldb_errstring(state->samdb)); + result = ISC_R_FAILURE; + goto failed; + } + dn = ldb_get_default_basedn(state->samdb); if (dn == NULL) { state->log(ISC_LOG_ERROR, "samba dlz_bind9: Unable to get basedn for %s - %s", |