From b3d110fbc424a03674a6e50e489a7cbab9702f0b Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Wed, 6 May 2015 08:06:53 +0200 Subject: DP: Add a function to inherit DP options, if set Related to: https://fedorahosted.org/sssd/ticket/2644 Adds a utility function that checks if a DP option is present in the subdomain_inherit list. If it is, then the option is set from source to destination dp_option array. Reviewed-by: Pavel Reichl --- src/providers/data_provider.h | 5 ++++ src/providers/data_provider_opts.c | 57 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) (limited to 'src/providers') diff --git a/src/providers/data_provider.h b/src/providers/data_provider.h index 5df493e9d..657d2b798 100644 --- a/src/providers/data_provider.h +++ b/src/providers/data_provider.h @@ -277,6 +277,11 @@ struct dp_option { #define DP_OPTION_TERMINATOR { NULL, 0, NULL_STRING, NULL_STRING } +void dp_option_inherit(char **inherit_opt_list, + int option, + struct dp_option *parent_opts, + struct dp_option *subdom_opts); + int dp_get_options(TALLOC_CTX *memctx, struct confdb_ctx *cdb, const char *conf_path, diff --git a/src/providers/data_provider_opts.c b/src/providers/data_provider_opts.c index 8ad84560b..9db43fc40 100644 --- a/src/providers/data_provider_opts.c +++ b/src/providers/data_provider_opts.c @@ -21,6 +21,63 @@ #include "data_provider.h" +/* =Copy-Option-From-Subdomain-If-Allowed================================= */ +void dp_option_inherit(char **inherit_opt_list, + int option, + struct dp_option *parent_opts, + struct dp_option *subdom_opts) +{ + errno_t ret; + bool inherit_option; + + inherit_option = string_in_list(parent_opts[option].opt_name, + inherit_opt_list, false); + if (inherit_option == false) { + DEBUG(SSSDBG_CONF_SETTINGS, + "Option %s is not set up to be inherited\n", + parent_opts[option].opt_name); + return; + } + + DEBUG(SSSDBG_CONF_SETTINGS, + "Will inherit option %s\n", parent_opts[option].opt_name); + switch (parent_opts[option].type) { + case DP_OPT_NUMBER: + ret = dp_opt_set_int(subdom_opts, + option, + dp_opt_get_int(parent_opts, + option)); + break; + case DP_OPT_STRING: + ret = dp_opt_set_string(subdom_opts, + option, + dp_opt_get_string(parent_opts, + option)); + break; + case DP_OPT_BLOB: + ret = dp_opt_set_blob(subdom_opts, + option, + dp_opt_get_blob(parent_opts, + option)); + break; + case DP_OPT_BOOL: + ret = dp_opt_set_bool(subdom_opts, + option, + dp_opt_get_bool(parent_opts, + option)); + break; + default: + ret = EINVAL; + break; + } + + if (ret != EOK) { + DEBUG(SSSDBG_MINOR_FAILURE, + "Failed to inherit option %s\n", parent_opts[option].opt_name); + /* Not fatal */ + } +} + /* =Retrieve-Options====================================================== */ int dp_get_options(TALLOC_CTX *memctx, -- cgit