summaryrefslogtreecommitdiff
path: root/src/providers
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2013-04-09 14:20:28 +0200
committerJakub Hrozek <jhrozek@redhat.com>2013-05-03 20:22:37 +0200
commit04868f1573f4b26ef34610b6d7069172f93bd8ab (patch)
tree25585171d9bfde286ffbd0add7a2fad64240e6ed /src/providers
parent9cb46bc62f22e0104f1b41a423b014c281ef5fc2 (diff)
downloadsssd-04868f1573f4b26ef34610b6d7069172f93bd8ab.tar.gz
sssd-04868f1573f4b26ef34610b6d7069172f93bd8ab.tar.bz2
sssd-04868f1573f4b26ef34610b6d7069172f93bd8ab.zip
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.
Diffstat (limited to 'src/providers')
-rw-r--r--src/providers/dp_dyndns.c57
-rw-r--r--src/providers/dp_dyndns.h24
-rw-r--r--src/providers/ipa/ipa_common.c96
-rw-r--r--src/providers/ipa/ipa_common.h7
-rw-r--r--src/providers/ipa/ipa_dyndns.c9
-rw-r--r--src/providers/ipa/ipa_init.c29
-rw-r--r--src/providers/ipa/ipa_opts.h10
7 files changed, 204 insertions, 28 deletions
diff --git a/src/providers/dp_dyndns.c b/src/providers/dp_dyndns.c
index 7e5cc690..81228d5c 100644
--- a/src/providers/dp_dyndns.c
+++ b/src/providers/dp_dyndns.c
@@ -878,3 +878,60 @@ be_nsupdate_recv(struct tevent_req *req, int *child_status)
return EOK;
}
+
+errno_t
+be_nsupdate_check(void)
+{
+ errno_t ret;
+ struct stat stat_buf;
+
+ /* Ensure that nsupdate exists */
+ errno = 0;
+ ret = stat(NSUPDATE_PATH, &stat_buf);
+ if (ret == -1) {
+ ret = errno;
+ if (ret == ENOENT) {
+ DEBUG(SSSDBG_MINOR_FAILURE,
+ ("%s does not exist. Dynamic DNS updates disabled\n",
+ NSUPDATE_PATH));
+ } else {
+ DEBUG(SSSDBG_OP_FAILURE,
+ ("Could not set up dynamic DNS updates: [%d][%s]\n",
+ ret, strerror(ret)));
+ }
+ }
+
+ return ret;
+}
+
+static struct dp_option default_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
+};
+
+errno_t
+be_nsupdate_init(TALLOC_CTX *mem_ctx, struct be_ctx *be_ctx,
+ struct dp_option *defopts, struct be_nsupdate_ctx **_ctx)
+{
+ errno_t ret;
+ struct dp_option *src_opts;
+ struct be_nsupdate_ctx *ctx;
+
+ ctx = talloc(mem_ctx, struct be_nsupdate_ctx);
+ if (ctx == NULL) return ENOMEM;
+
+ src_opts = defopts ? defopts : default_dyndns_opts;
+
+ ret = dp_get_options(ctx, be_ctx->cdb, be_ctx->conf_path,
+ src_opts, DP_OPT_DYNDNS, &ctx->opts);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Cannot retrieve dynamic DNS options\n"));
+ return ret;
+ }
+
+ *_ctx = ctx;
+ return EOK;
+}
diff --git a/src/providers/dp_dyndns.h b/src/providers/dp_dyndns.h
index b0020560..95403a3a 100644
--- a/src/providers/dp_dyndns.h
+++ b/src/providers/dp_dyndns.h
@@ -22,12 +22,34 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
+#ifndef DP_DYNDNS_H_
+#define DP_DYNDNS_H_
+
/* dynamic dns helpers */
struct sss_iface_addr;
+struct be_nsupdate_ctx {
+ struct dp_option *opts;
+};
+
+enum dp_dyndns_opts {
+ DP_OPT_DYNDNS_UPDATE,
+ DP_OPT_DYNDNS_IFACE,
+ DP_OPT_DYNDNS_TTL,
+
+ DP_OPT_DYNDNS /* attrs counter */
+};
+
#define DYNDNS_REMOVE_A 0x1
#define DYNDNS_REMOVE_AAAA 0x2
+errno_t be_nsupdate_check(void);
+
+errno_t
+be_nsupdate_init(TALLOC_CTX *mem_ctx, struct be_ctx *be_ctx,
+ struct dp_option *defopts, struct be_nsupdate_ctx **ctx);
+
errno_t
sss_iface_addr_list_get(TALLOC_CTX *mem_ctx, const char *ifname,
struct sss_iface_addr **_addrlist);
@@ -66,3 +88,5 @@ struct tevent_req * nsupdate_get_addrs_send(TALLOC_CTX *mem_ctx,
errno_t nsupdate_get_addrs_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx,
char ***_addrlist);
+
+#endif /* DP_DYNDNS_H_ */
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 },