summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/providers/data_provider_fo.c26
-rw-r--r--src/resolv/async_resolv.c41
-rw-r--r--src/resolv/async_resolv.h8
3 files changed, 52 insertions, 23 deletions
diff --git a/src/providers/data_provider_fo.c b/src/providers/data_provider_fo.c
index 8427d297e..3d726da19 100644
--- a/src/providers/data_provider_fo.c
+++ b/src/providers/data_provider_fo.c
@@ -65,38 +65,18 @@ int be_fo_is_srv_identifier(const char *server)
static int be_fo_get_options(TALLOC_CTX *mem_ctx, struct be_ctx *ctx,
struct fo_options *opts)
{
- char *str_opt;
- int ret;
+ errno_t ret;
/* todo get timeout from configuration */
opts->retry_timeout = 30;
opts->srv_retry_timeout = 14400;
- ret = confdb_get_string(ctx->cdb, mem_ctx, ctx->conf_path,
- CONFDB_DOMAIN_FAMILY_ORDER,
- "ipv4_first", &str_opt);
+ ret = resolv_get_family_order(ctx->cdb, ctx->conf_path,
+ &opts->family_order);
if (ret != EOK) {
return ret;
}
- DEBUG(7, ("Lookup order: %s\n", str_opt));
-
- if (strcasecmp(str_opt, "ipv4_first") == 0) {
- opts->family_order = IPV4_FIRST;
- } else if (strcasecmp(str_opt, "ipv4_only") == 0) {
- opts->family_order = IPV4_ONLY;
- } else if (strcasecmp(str_opt, "ipv6_first") == 0) {
- opts->family_order = IPV6_FIRST;
- } else if (strcasecmp(str_opt, "ipv6_only") == 0) {
- opts->family_order = IPV6_ONLY;
- } else {
- DEBUG(1, ("Unknown value for option %s: %s\n",
- CONFDB_DOMAIN_FAMILY_ORDER, str_opt));
- talloc_free(str_opt);
- return EINVAL;
- }
-
- talloc_free(str_opt);
return EOK;
}
diff --git a/src/resolv/async_resolv.c b/src/resolv/async_resolv.c
index 9b9b0538e..4cbb56d82 100644
--- a/src/resolv/async_resolv.c
+++ b/src/resolv/async_resolv.c
@@ -98,6 +98,47 @@ struct resolv_ctx {
struct resolv_ctx *context_list;
+errno_t
+resolv_get_family_order(struct confdb_ctx *cdb, const char *conf_path,
+ enum restrict_family *family_order)
+{
+ errno_t ret;
+ TALLOC_CTX *tmp_ctx;
+ char *str_opt;
+
+ tmp_ctx = talloc_new(NULL);
+ if (!tmp_ctx) return ENOMEM;
+
+ ret = confdb_get_string(cdb, tmp_ctx, conf_path,
+ CONFDB_DOMAIN_FAMILY_ORDER,
+ "ipv4_first", &str_opt);
+ if (ret != EOK) {
+ goto done;
+ }
+
+ DEBUG(7, ("Lookup order: %s\n", str_opt));
+
+ if (strcasecmp(str_opt, "ipv4_first") == 0) {
+ *family_order = IPV4_FIRST;
+ } else if (strcasecmp(str_opt, "ipv4_only") == 0) {
+ *family_order = IPV4_ONLY;
+ } else if (strcasecmp(str_opt, "ipv6_first") == 0) {
+ *family_order = IPV6_FIRST;
+ } else if (strcasecmp(str_opt, "ipv6_only") == 0) {
+ *family_order = IPV6_ONLY;
+ } else {
+ DEBUG(1, ("Unknown value for option %s: %s\n",
+ CONFDB_DOMAIN_FAMILY_ORDER, str_opt));
+ ret = EINVAL;
+ goto done;
+ }
+
+ ret = EOK;
+done:
+ talloc_free(tmp_ctx);
+ return ret;
+}
+
static int
return_code(int ares_code)
{
diff --git a/src/resolv/async_resolv.h b/src/resolv/async_resolv.h
index 70694795e..0e2030324 100644
--- a/src/resolv/async_resolv.h
+++ b/src/resolv/async_resolv.h
@@ -30,6 +30,7 @@
#include <ares.h>
#include "config.h"
+#include "confdb/confdb.h"
#ifndef HAVE_ARES_DATA
#include "resolv/ares/ares_parse_srv_reply.h"
@@ -43,6 +44,8 @@
#define RESOLV_DEFAULT_TIMEOUT 5
+#include "util/util.h"
+
/*
* An opaque structure which holds context for a module using the async
* resolver. Is should be used as a "local-global" variable - in sssd,
@@ -82,6 +85,11 @@ enum restrict_family {
IPV6_FIRST
};
+/* Read and validate the family order from conf_path in confdb */
+errno_t
+resolv_get_family_order(struct confdb_ctx *cdb, const char *conf_path,
+ enum restrict_family *family_order);
+
/* If resolv_hostent->family is AF_INET, then ipaddr points to
* struct in_addr, else if family is AF_INET6, ipaddr points to
* struct in6_addr