>From 8fba4d0959c67b10bcfec9bc437e05ef563426ea Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Wed, 19 Jun 2013 19:06:14 +0300 Subject: [PATCH 2/8] LDAP: Add utility function sdap_copy_map The AD subdomains will only use default options values. This patch introduces a new utility function sdap_copy_map() that copies the default options map. Subtask of: https://fedorahosted.org/sssd/ticket/1962 --- src/providers/ldap/sdap.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/providers/ldap/sdap.h | 5 +++++ 2 files changed, 45 insertions(+) diff --git a/src/providers/ldap/sdap.c b/src/providers/ldap/sdap.c index 0492be05d78b78967989ecd783d92ce94315c551..5497d94340b67bd30af69454512976bd3fe1b883 100644 --- a/src/providers/ldap/sdap.c +++ b/src/providers/ldap/sdap.c @@ -28,6 +28,46 @@ /* =Retrieve-Options====================================================== */ +int sdap_copy_map(TALLOC_CTX *memctx, + struct sdap_attr_map *src_map, + int num_entries, + struct sdap_attr_map **_map) +{ + struct sdap_attr_map *map; + int i; + + map = talloc_array(memctx, struct sdap_attr_map, num_entries); + if (!map) { + return ENOMEM; + } + + for (i = 0; i < num_entries; i++) { + map[i].opt_name = talloc_strdup(map, src_map[i].opt_name); + map[i].sys_name = talloc_strdup(map, src_map[i].sys_name); + if (map[i].opt_name == NULL || map[i].sys_name == NULL) { + return ENOMEM; + } + + if (src_map[i].def_name != NULL) { + map[i].def_name = talloc_strdup(map, src_map[i].def_name); + map[i].name = talloc_strdup(map, src_map[i].def_name); + if (map[i].def_name == NULL || map[i].name == NULL) { + return ENOMEM; + } + } else { + map[i].def_name = NULL; + map[i].name = NULL; + } + + DEBUG(SSSDBG_TRACE_FUNC, ("Option %s has%s value %s\n", + map[i].opt_name, map[i].name ? "" : " no", + map[i].name ? map[i].name : "")); + } + + *_map = map; + return EOK; +} + int sdap_get_map(TALLOC_CTX *memctx, struct confdb_ctx *cdb, const char *conf_path, diff --git a/src/providers/ldap/sdap.h b/src/providers/ldap/sdap.h index 9fbe04b6a7071b82cc0170e7d8b371898b20a8a7..24d208a2e62dc088821d866e5b1411c94397e232 100644 --- a/src/providers/ldap/sdap.h +++ b/src/providers/ldap/sdap.h @@ -438,6 +438,11 @@ struct sdap_deref_attrs { struct sysdb_attrs *attrs; }; +int sdap_copy_map(TALLOC_CTX *memctx, + struct sdap_attr_map *src_map, + int num_entries, + struct sdap_attr_map **_map); + int sdap_get_map(TALLOC_CTX *memctx, struct confdb_ctx *cdb, const char *conf_path, -- 1.8.3.1