From 04868f1573f4b26ef34610b6d7069172f93bd8ab Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Tue, 9 Apr 2013 14:20:28 +0200 Subject: Convert IPA-specific options to be back-end agnostic This patch introduces new options for dynamic DNS updates that are not specific to any back end. The current ipa dyndns options are still usable, just with a deprecation warning. --- src/providers/ipa/ipa_common.c | 96 ++++++++++++++++++++++++++++++++++++++++++ src/providers/ipa/ipa_common.h | 7 +-- src/providers/ipa/ipa_dyndns.c | 9 ++-- src/providers/ipa/ipa_init.c | 29 +++++-------- src/providers/ipa/ipa_opts.h | 10 +++-- 5 files changed, 123 insertions(+), 28 deletions(-) (limited to 'src/providers/ipa') diff --git a/src/providers/ipa/ipa_common.c b/src/providers/ipa/ipa_common.c index be1bd1d2..51750b2a 100644 --- a/src/providers/ipa/ipa_common.c +++ b/src/providers/ipa/ipa_common.c @@ -29,6 +29,7 @@ #include "db/sysdb_selinux.h" #include "providers/ipa/ipa_common.h" #include "providers/ldap/sdap_async_private.h" +#include "providers/dp_dyndns.h" #include "util/sss_krb5.h" #include "db/sysdb_services.h" #include "db/sysdb_autofs.h" @@ -1008,3 +1009,98 @@ done: talloc_free(tmp_ctx); return ret; } + +errno_t ipa_get_dyndns_options(struct be_ctx *be_ctx, + struct ipa_options *ctx) +{ + errno_t ret; + char *val; + bool update; + int ttl; + + ret = be_nsupdate_init(ctx, be_ctx, ipa_dyndns_opts, &ctx->dyndns_ctx); + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, + ("Cannot initialize IPA dyndns opts [%d]: %s\n", + ret, sss_strerror(ret))); + return ret; + } + + if (ctx->basic == NULL) { + DEBUG(SSSDBG_MINOR_FAILURE, ("IPA basic options not (yet) " + "initialized, cannot copy legacy options\n")); + return EOK; + } + + /* Reuse legacy option values */ + ret = confdb_get_string(be_ctx->cdb, ctx, be_ctx->conf_path, + "ipa_dyndns_update", NULL, &val); + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, ("Cannot get the value of %s\n", + "ipa_dyndns_update")); + /* Not fatal */ + } else if (ret == EOK && val) { + if (strcasecmp(val, "FALSE") == 0) { + update = false; + } else if (strcasecmp(val, "TRUE") == 0) { + update = true; + } else { + DEBUG(SSSDBG_MINOR_FAILURE, + ("ipa_dyndns_update value is not a boolean!\n")); + talloc_free(val); + return EINVAL; + } + + DEBUG(SSSDBG_MINOR_FAILURE, ("Deprecation warning: The option %s is " + "deprecated and should not be used in favor of %s\n", + "ipa_dyndns_update", "dyndns_update")); + + ret = dp_opt_set_bool(ctx->dyndns_ctx->opts, + DP_OPT_DYNDNS_UPDATE, update); + talloc_free(val); + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, ("Cannot set option value\n")); + return ret; + } + } + + ret = confdb_get_int(be_ctx->cdb, be_ctx->conf_path, + "ipa_dyndns_ttl", -1, &ttl); + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, ("Cannot get the value of %s\n", + "ipa_dyndns_ttl")); + /* Not fatal */ + } else if (ret == EOK && ttl != -1) { + DEBUG(SSSDBG_MINOR_FAILURE, ("Deprecation warning: The option %s is " + "deprecated and should not be used in favor of %s\n", + "ipa_dyndns_ttl", "dyndns_ttl")); + + ret = dp_opt_set_int(ctx->dyndns_ctx->opts, DP_OPT_DYNDNS_TTL, ttl); + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, ("Cannot set option value\n")); + return ret; + } + } + + /* Reuse legacy option values */ + ret = confdb_get_string(be_ctx->cdb, ctx, be_ctx->conf_path, + "ipa_dyndns_iface", NULL, &val); + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, ("Cannot get the value of %s\n", + "ipa_dyndns_iface")); + /* Not fatal */ + } else if (ret == EOK && val) { + DEBUG(SSSDBG_MINOR_FAILURE, ("Deprecation warning: The option %s is " + "deprecated and should not be used in favor of %s\n", + "ipa_dyndns_iface", "dyndns_iface")); + + ret = dp_opt_set_string(ctx->dyndns_ctx->opts, + DP_OPT_DYNDNS_IFACE, val); + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, ("Cannot set option value\n")); + return ret; + } + } + + return EOK; +} diff --git a/src/providers/ipa/ipa_common.h b/src/providers/ipa/ipa_common.h index 6e77c997..a32867dd 100644 --- a/src/providers/ipa/ipa_common.h +++ b/src/providers/ipa/ipa_common.h @@ -37,9 +37,6 @@ enum ipa_basic_opt { IPA_SERVER, IPA_BACKUP_SERVER, IPA_HOSTNAME, - IPA_DYNDNS_UPDATE, - IPA_DYNDNS_TTL, - IPA_DYNDNS_IFACE, IPA_HBAC_SEARCH_BASE, IPA_HOST_SEARCH_BASE, IPA_SELINUX_SEARCH_BASE, @@ -139,6 +136,7 @@ struct ipa_options { struct sdap_options *id; struct ipa_id_ctx *id_ctx; struct be_resolv_ctx *be_res; + struct be_nsupdate_ctx *dyndns_ctx; /* auth and chpass provider */ struct dp_option *auth; @@ -169,6 +167,9 @@ int ipa_get_autofs_options(struct ipa_options *ipa_opts, const char *conf_path, struct sdap_options **_opts); +errno_t ipa_get_dyndns_options(struct be_ctx *be_ctx, + struct ipa_options *ctx); + int ipa_autofs_init(struct be_ctx *be_ctx, struct ipa_id_ctx *id_ctx, struct bet_ops **ops, diff --git a/src/providers/ipa/ipa_dyndns.c b/src/providers/ipa/ipa_dyndns.c index 79918a26..8023b533 100644 --- a/src/providers/ipa/ipa_dyndns.c +++ b/src/providers/ipa/ipa_dyndns.c @@ -28,6 +28,7 @@ #include "providers/ipa/ipa_common.h" #include "providers/ipa/ipa_dyndns.h" #include "providers/data_provider.h" +#include "providers/dp_dyndns.h" void ipa_dyndns_update(void *pvt); @@ -135,16 +136,16 @@ ipa_dyndns_update_send(struct ipa_options *ctx) subreq = sdap_dyndns_update_send(state, sdap_ctx->be->ev, sdap_ctx->be, sdap_ctx, - dp_opt_get_string(ctx->basic, - IPA_DYNDNS_IFACE), + dp_opt_get_string(ctx->dyndns_ctx->opts, + DP_OPT_DYNDNS_IFACE), dp_opt_get_string(ctx->basic, IPA_HOSTNAME), dns_zone, dp_opt_get_string(ctx->basic, IPA_KRB5_REALM), servername, - dp_opt_get_int(ctx->basic, - IPA_DYNDNS_TTL), + dp_opt_get_int(ctx->dyndns_ctx->opts, + DP_OPT_DYNDNS_TTL), true); if (!subreq) { ret = EIO; diff --git a/src/providers/ipa/ipa_init.c b/src/providers/ipa/ipa_init.c index 0e9fe0dd..5192bc81 100644 --- a/src/providers/ipa/ipa_init.c +++ b/src/providers/ipa/ipa_init.c @@ -40,6 +40,7 @@ #include "providers/ldap/sdap_access.h" #include "providers/ipa/ipa_subdomains.h" #include "providers/ipa/ipa_srv.h" +#include "providers/dp_dyndns.h" struct ipa_options *ipa_options = NULL; @@ -110,11 +111,9 @@ int sssm_ipa_id_init(struct be_ctx *bectx, { struct ipa_id_ctx *ipa_ctx; struct sdap_id_ctx *sdap_ctx; - struct stat stat_buf; const char *hostname; const char *ipa_domain; struct ipa_srv_plugin_ctx *srv_ctx; - errno_t err; int ret; if (!ipa_options) { @@ -153,7 +152,12 @@ int sssm_ipa_id_init(struct be_ctx *bectx, goto done; } - if(dp_opt_get_bool(ipa_options->basic, IPA_DYNDNS_UPDATE)) { + ret = ipa_get_dyndns_options(bectx, ipa_options); + if (ret != EOK) { + goto done; + } + + if (dp_opt_get_bool(ipa_options->dyndns_ctx->opts, DP_OPT_DYNDNS_UPDATE)) { /* Perform automatic DNS updates when the * IP address changes. * Register a callback for successful LDAP @@ -161,21 +165,10 @@ int sssm_ipa_id_init(struct be_ctx *bectx, * identify that we have gone online. */ - /* Ensure that nsupdate exists */ - errno = 0; - ret = stat(NSUPDATE_PATH, &stat_buf); - if (ret == -1) { - err = errno; - if (err == ENOENT) { - DEBUG(0, ("%s does not exist. Dynamic DNS updates disabled\n", - NSUPDATE_PATH)); - } - else { - DEBUG(0, ("Could not set up dynamic DNS updates: [%d][%s]\n", - err, strerror(err))); - } - } - else { + DEBUG(SSSDBG_CONF_SETTINGS, + ("Dynamic DNS updates are on. Checking for nsupdate..\n")); + ret = be_nsupdate_check(); + if (ret == EOK) { /* nsupdate is available. Dynamic updates * are supported */ diff --git a/src/providers/ipa/ipa_opts.h b/src/providers/ipa/ipa_opts.h index 6adbdd96..392fcd86 100644 --- a/src/providers/ipa/ipa_opts.h +++ b/src/providers/ipa/ipa_opts.h @@ -35,9 +35,6 @@ struct dp_option ipa_basic_opts[] = { { "ipa_server", DP_OPT_STRING, NULL_STRING, NULL_STRING }, { "ipa_backup_server", DP_OPT_STRING, NULL_STRING, NULL_STRING }, { "ipa_hostname", DP_OPT_STRING, NULL_STRING, NULL_STRING }, - { "ipa_dyndns_update", DP_OPT_BOOL, BOOL_FALSE, BOOL_FALSE }, - { "ipa_dyndns_ttl", DP_OPT_NUMBER, { .number = 1200}, NULL_NUMBER}, - { "ipa_dyndns_iface", DP_OPT_STRING, NULL_STRING, NULL_STRING}, { "ipa_hbac_search_base", DP_OPT_STRING, NULL_STRING, NULL_STRING}, { "ipa_host_search_base", DP_OPT_STRING, NULL_STRING, NULL_STRING }, { "ipa_selinux_search_base", DP_OPT_STRING, NULL_STRING, NULL_STRING }, @@ -54,6 +51,13 @@ struct dp_option ipa_basic_opts[] = { DP_OPTION_TERMINATOR }; +struct dp_option ipa_dyndns_opts[] = { + { "dyndns_update", DP_OPT_BOOL, BOOL_FALSE, BOOL_FALSE }, + { "dyndns_iface", DP_OPT_STRING, NULL_STRING, NULL_STRING }, + { "dyndns_ttl", DP_OPT_NUMBER, { .number = 1200 }, NULL_NUMBER }, + DP_OPTION_TERMINATOR +}; + struct dp_option ipa_def_ldap_opts[] = { { "ldap_uri", DP_OPT_STRING, NULL_STRING, NULL_STRING }, { "ldap_backup_uri", DP_OPT_STRING, NULL_STRING, NULL_STRING }, -- cgit