[PATCH] streamline idmap config code
Volker Lendecke
vl at samba.org
Sun Mar 19 10:58:52 UTC 2017
Hi!
A few less lines, less tallocs, less memory fragmentation.
Review appreciated!
Thanks, Volker
-------------- next part --------------
>From 10ad5398b22676c7b2d2755704d80475601634a6 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 7 Jan 2017 14:53:09 +0000
Subject: [PATCH 01/19] winbind: Add idmap_config_const_string
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap.c | 16 ++++++++++++++++
source3/winbindd/winbindd_proto.h | 2 ++
2 files changed, 18 insertions(+)
diff --git a/source3/winbindd/idmap.c b/source3/winbindd/idmap.c
index 6a52633..a8a7136 100644
--- a/source3/winbindd/idmap.c
+++ b/source3/winbindd/idmap.c
@@ -177,6 +177,22 @@ static bool idmap_init(void)
return true;
}
+const char *idmap_config_const_string(const char *domname, const char *option,
+ const char *def)
+{
+ int len = snprintf(NULL, 0, "idmap config %s", domname);
+
+ if (len == -1) {
+ return NULL;
+ }
+ {
+ char config_option[len+1];
+ snprintf(config_option, sizeof(config_option),
+ "idmap config %s", domname);
+ return lp_parm_const_string(-1, config_option, option, def);
+ }
+}
+
bool domain_has_idmap_config(const char *domname)
{
int i;
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index ede2c3e..b33c24f 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -378,6 +378,8 @@ void init_idmap_child(void);
struct winbindd_child *idmap_child(void);
struct idmap_domain *idmap_find_domain_with_sid(const char *domname,
const struct dom_sid *sid);
+const char *idmap_config_const_string(const char *domname, const char *option,
+ const char *def);
bool domain_has_idmap_config(const char *domname);
bool lp_scan_idmap_domains(bool (*fn)(const char *domname,
void *private_data),
--
1.9.1
>From 25fd5a2eee1055e57a39d6fe033e8735a7ee8306 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 7 Jan 2017 14:55:41 +0000
Subject: [PATCH 02/19] winbind: Use idmap_config_const_string in
domain_has_idmap_config
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap.c | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/source3/winbindd/idmap.c b/source3/winbindd/idmap.c
index a8a7136..9978e10 100644
--- a/source3/winbindd/idmap.c
+++ b/source3/winbindd/idmap.c
@@ -196,7 +196,6 @@ const char *idmap_config_const_string(const char *domname, const char *option,
bool domain_has_idmap_config(const char *domname)
{
int i;
- char *config_option;
const char *range = NULL;
const char *backend = NULL;
bool ok;
@@ -214,23 +213,14 @@ bool domain_has_idmap_config(const char *domname)
/* fallback: also check loadparm */
- config_option = talloc_asprintf(talloc_tos(), "idmap config %s",
- domname);
- if (config_option == NULL) {
- DEBUG(0, ("out of memory\n"));
- return false;
- }
-
- range = lp_parm_const_string(-1, config_option, "range", NULL);
- backend = lp_parm_const_string(-1, config_option, "backend", NULL);
+ range = idmap_config_const_string(domname, "range", NULL);
+ backend = idmap_config_const_string(domname, "backend", NULL);
if (range != NULL && backend != NULL) {
DEBUG(5, ("idmap configuration specified for domain '%s'\n",
domname));
- TALLOC_FREE(config_option);
return true;
}
- TALLOC_FREE(config_option);
return false;
}
--
1.9.1
>From beb243ee70e273b2662179905c842dcac7225c31 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 7 Jan 2017 14:55:41 +0000
Subject: [PATCH 03/19] winbind: Use idmap_config_const_string in
idmap_init_named_domain
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/source3/winbindd/idmap.c b/source3/winbindd/idmap.c
index 9978e10..8971e7f 100644
--- a/source3/winbindd/idmap.c
+++ b/source3/winbindd/idmap.c
@@ -454,7 +454,6 @@ static struct idmap_domain *idmap_init_named_domain(TALLOC_CTX *mem_ctx,
const char *domname)
{
struct idmap_domain *result = NULL;
- char *config_option;
const char *backend;
bool ok;
@@ -463,14 +462,7 @@ static struct idmap_domain *idmap_init_named_domain(TALLOC_CTX *mem_ctx,
return NULL;
}
- config_option = talloc_asprintf(talloc_tos(), "idmap config %s",
- domname);
- if (config_option == NULL) {
- DEBUG(0, ("talloc failed\n"));
- goto fail;
- }
-
- backend = lp_parm_const_string(-1, config_option, "backend", NULL);
+ backend = idmap_config_const_string(domname, "backend", NULL);
if (backend == NULL) {
DEBUG(10, ("no idmap backend configured for domain '%s'\n",
domname));
@@ -482,11 +474,9 @@ static struct idmap_domain *idmap_init_named_domain(TALLOC_CTX *mem_ctx,
goto fail;
}
- TALLOC_FREE(config_option);
return result;
fail:
- TALLOC_FREE(config_option);
TALLOC_FREE(result);
return NULL;
}
--
1.9.1
>From da4d8e777e8b3121fd35f92f76fa579b797f38ce Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 7 Jan 2017 14:55:41 +0000
Subject: [PATCH 04/19] winbind: Use idmap_config_const_string in
wb_xids2sids_add_dom
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/wb_xids2sids.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/source3/winbindd/wb_xids2sids.c b/source3/winbindd/wb_xids2sids.c
index 7ac1998..15e94c4 100644
--- a/source3/winbindd/wb_xids2sids.c
+++ b/source3/winbindd/wb_xids2sids.c
@@ -43,19 +43,11 @@ static bool wb_xids2sids_add_dom(const char *domname,
struct wb_xids2sids_dom_map *map = NULL;
size_t num_maps = talloc_array_length(dom_maps);
size_t i;
- char *config_option;
const char *range;
unsigned low_id, high_id;
int ret;
- config_option = talloc_asprintf(
- talloc_tos(), "idmap config %s", domname);
- if (config_option == NULL) {
- return false;
- }
- range = lp_parm_const_string(-1, config_option, "range", NULL);
- TALLOC_FREE(config_option);
-
+ range = idmap_config_const_string(domname, "range", NULL);
if (range == NULL) {
DBG_DEBUG("No range for domain %s found\n", domname);
return false;
--
1.9.1
>From 9ce2780ca19d698ee61e580f4a0592fd7e98b6f1 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 7 Jan 2017 14:55:41 +0000
Subject: [PATCH 05/19] winbind: Use idmap_config_const_string in
idmap_tdb2_db_init
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap_tdb2.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/source3/winbindd/idmap_tdb2.c b/source3/winbindd/idmap_tdb2.c
index fdcd44e..72c5b9e 100644
--- a/source3/winbindd/idmap_tdb2.c
+++ b/source3/winbindd/idmap_tdb2.c
@@ -533,7 +533,6 @@ static NTSTATUS idmap_tdb2_db_init(struct idmap_domain *dom)
NTSTATUS ret;
struct idmap_tdb_common_context *commonctx;
struct idmap_tdb2_context *ctx;
- char *config_option = NULL;
const char * idmap_script = NULL;
commonctx = talloc_zero(dom, struct idmap_tdb_common_context);
@@ -556,14 +555,7 @@ static NTSTATUS idmap_tdb2_db_init(struct idmap_domain *dom)
goto failed;
}
- config_option = talloc_asprintf(ctx, "idmap config %s", dom->name);
- if (config_option == NULL) {
- DEBUG(0, ("Out of memory!\n"));
- ret = NT_STATUS_NO_MEMORY;
- goto failed;
- }
- ctx->script = lp_parm_const_string(-1, config_option, "script", NULL);
- talloc_free(config_option);
+ ctx->script = idmap_config_const_string(dom->name, "script", NULL);
idmap_script = lp_parm_const_string(-1, "idmap", "script", NULL);
if (idmap_script != NULL) {
--
1.9.1
>From cef2904e9fc5ef11168a128357a2669f0691dfec Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 7 Jan 2017 14:55:41 +0000
Subject: [PATCH 06/19] winbind: Use idmap_config_const_string in
idmap_script_db_init
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap_script.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/source3/winbindd/idmap_script.c b/source3/winbindd/idmap_script.c
index 75eabdf..4faf2d5 100644
--- a/source3/winbindd/idmap_script.c
+++ b/source3/winbindd/idmap_script.c
@@ -582,7 +582,6 @@ static NTSTATUS idmap_script_db_init(struct idmap_domain *dom)
{
NTSTATUS ret;
struct idmap_script_context *ctx;
- char *config_option = NULL;
const char * idmap_script = NULL;
DEBUG(10, ("%s called ...\n", __func__));
@@ -594,14 +593,7 @@ static NTSTATUS idmap_script_db_init(struct idmap_domain *dom)
goto failed;
}
- config_option = talloc_asprintf(ctx, "idmap config %s", dom->name);
- if (config_option == NULL) {
- DEBUG(0, ("Out of memory!\n"));
- ret = NT_STATUS_NO_MEMORY;
- goto failed;
- }
- ctx->script = lp_parm_const_string(-1, config_option, "script", NULL);
- talloc_free(config_option);
+ ctx->script = idmap_config_const_string(dom->name, "script", NULL);
/* Do we even need to handle this? */
idmap_script = lp_parm_const_string(-1, "idmap", "script", NULL);
--
1.9.1
>From b4802a096ce221b67d630b1479b32742c7e312d3 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 18 Mar 2017 18:34:07 +0100
Subject: [PATCH 07/19] winbind: Use idmap_config_const_string in
idmap_init_domain
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source3/winbindd/idmap.c b/source3/winbindd/idmap.c
index 8971e7f..d5471e9 100644
--- a/source3/winbindd/idmap.c
+++ b/source3/winbindd/idmap.c
@@ -398,7 +398,7 @@ static struct idmap_domain *idmap_init_domain(TALLOC_CTX *mem_ctx,
}
result->read_only = lp_parm_bool(-1, config_option, "read only", false);
- range = lp_parm_const_string(-1, config_option, "range", NULL);
+ range = idmap_config_const_string(result->name, "range", NULL);
talloc_free(config_option);
--
1.9.1
>From ad414f4e529bed34dd6a4aacf544be41924672b1 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 18 Mar 2017 18:38:10 +0100
Subject: [PATCH 08/19] idmap_ldap: Use idmap_config_const_string
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap_ldap.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/source3/winbindd/idmap_ldap.c b/source3/winbindd/idmap_ldap.c
index 0520f21..a7fe17e 100644
--- a/source3/winbindd/idmap_ldap.c
+++ b/source3/winbindd/idmap_ldap.c
@@ -64,7 +64,6 @@ struct idmap_ldap_context {
static NTSTATUS get_credentials( TALLOC_CTX *mem_ctx,
struct smbldap_state *ldap_state,
- const char *config_option,
struct idmap_domain *dom,
char **dn )
{
@@ -76,7 +75,7 @@ static NTSTATUS get_credentials( TALLOC_CTX *mem_ctx,
/* assume anonymous if we don't have a specified user */
- tmp = lp_parm_const_string(-1, config_option, "ldap_user_dn", NULL);
+ tmp = idmap_config_const_string(dom->name, "ldap_user_dn", NULL);
if ( tmp ) {
if (!dom) {
@@ -478,7 +477,7 @@ static NTSTATUS idmap_ldap_db_init(struct idmap_domain *dom)
goto done;
}
- ret = get_credentials( ctx, ctx->smbldap_state, config_option,
+ ret = get_credentials( ctx, ctx->smbldap_state,
dom, &ctx->user_dn );
if ( !NT_STATUS_IS_OK(ret) ) {
DEBUG(1,("idmap_ldap_db_init: Failed to get connection "
--
1.9.1
>From 7cd68651cb82f86fcab0f4f9d96af8a751d63ad1 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 18 Mar 2017 18:40:28 +0100
Subject: [PATCH 09/19] idmap_ldap: Use idmap_config_const_string
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap_ldap.c | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/source3/winbindd/idmap_ldap.c b/source3/winbindd/idmap_ldap.c
index a7fe17e..041152c 100644
--- a/source3/winbindd/idmap_ldap.c
+++ b/source3/winbindd/idmap_ldap.c
@@ -416,7 +416,6 @@ static NTSTATUS idmap_ldap_db_init(struct idmap_domain *dom)
{
NTSTATUS ret;
struct idmap_ldap_context *ctx = NULL;
- char *config_option = NULL;
const char *tmp = NULL;
/* Only do init if we are online */
@@ -430,14 +429,7 @@ static NTSTATUS idmap_ldap_db_init(struct idmap_domain *dom)
return NT_STATUS_NO_MEMORY;
}
- config_option = talloc_asprintf(ctx, "idmap config %s", dom->name);
- if (!config_option) {
- DEBUG(0, ("Out of memory!\n"));
- ret = NT_STATUS_NO_MEMORY;
- goto done;
- }
-
- tmp = lp_parm_const_string(-1, config_option, "ldap_url", NULL);
+ tmp = idmap_config_const_string(dom->name, "ldap_url", NULL);
if ( ! tmp) {
DEBUG(1, ("ERROR: missing idmap ldap url\n"));
@@ -449,7 +441,7 @@ static NTSTATUS idmap_ldap_db_init(struct idmap_domain *dom)
trim_char(ctx->url, '\"', '\"');
- tmp = lp_parm_const_string(-1, config_option, "ldap_base_dn", NULL);
+ tmp = idmap_config_const_string(dom->name, "ldap_base_dn", NULL);
if ( ! tmp || ! *tmp) {
tmp = lp_ldap_idmap_suffix(talloc_tos());
if ( ! tmp) {
@@ -500,7 +492,6 @@ static NTSTATUS idmap_ldap_db_init(struct idmap_domain *dom)
goto done;
}
- talloc_free(config_option);
return NT_STATUS_OK;
/*failed */
--
1.9.1
>From 9f13b3b87157f6b5a600b76d5bddfb47140f2372 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 18 Mar 2017 18:48:46 +0100
Subject: [PATCH 10/19] idmap_rfc2307: Use idmap_config_const_string
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap_rfc2307.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/source3/winbindd/idmap_rfc2307.c b/source3/winbindd/idmap_rfc2307.c
index 34cc5cd..d59690e 100644
--- a/source3/winbindd/idmap_rfc2307.c
+++ b/source3/winbindd/idmap_rfc2307.c
@@ -109,15 +109,15 @@ static NTSTATUS idmap_rfc2307_ads_search(struct idmap_rfc2307_context *ctx,
}
static NTSTATUS idmap_rfc2307_init_ads(struct idmap_rfc2307_context *ctx,
- const char *cfg_opt)
+ const char *domain_name)
{
const char *ldap_domain;
ctx->search = idmap_rfc2307_ads_search;
ctx->check_connection = idmap_rfc2307_ads_check_connection;
- ldap_domain = lp_parm_const_string(-1, cfg_opt, "ldap_domain",
- NULL);
+ ldap_domain = idmap_config_const_string(domain_name, "ldap_domain",
+ NULL);
if (ldap_domain) {
ctx->ldap_domain = talloc_strdup(ctx, ldap_domain);
if (ctx->ldap_domain == NULL) {
@@ -167,8 +167,7 @@ static bool idmap_rfc2307_get_uint32(LDAP *ldap, LDAPMessage *entry,
}
static NTSTATUS idmap_rfc2307_init_ldap(struct idmap_rfc2307_context *ctx,
- struct idmap_domain *dom,
- const char *config_option)
+ const char *domain_name)
{
NTSTATUS ret;
char *url;
@@ -176,7 +175,7 @@ static NTSTATUS idmap_rfc2307_init_ldap(struct idmap_rfc2307_context *ctx,
const char *ldap_url, *user_dn;
TALLOC_CTX *mem_ctx = ctx;
- ldap_url = lp_parm_const_string(-1, config_option, "ldap_url", NULL);
+ ldap_url = idmap_config_const_string(domain_name, "ldap_url", NULL);
if (!ldap_url) {
DEBUG(1, ("ERROR: missing idmap ldap url\n"));
return NT_STATUS_UNSUCCESSFUL;
@@ -184,9 +183,9 @@ static NTSTATUS idmap_rfc2307_init_ldap(struct idmap_rfc2307_context *ctx,
url = talloc_strdup(talloc_tos(), ldap_url);
- user_dn = lp_parm_const_string(-1, config_option, "ldap_user_dn", NULL);
+ user_dn = idmap_config_const_string(domain_name, "ldap_user_dn", NULL);
if (user_dn) {
- secret = idmap_fetch_secret("ldap", dom->name, user_dn);
+ secret = idmap_fetch_secret("ldap", domain_name, user_dn);
if (!secret) {
ret = NT_STATUS_ACCESS_DENIED;
goto done;
@@ -780,8 +779,8 @@ static NTSTATUS idmap_rfc2307_initialize(struct idmap_domain *domain)
goto err;
}
- bind_path_user = lp_parm_const_string(-1, cfg_opt, "bind_path_user",
- NULL);
+ bind_path_user = idmap_config_const_string(
+ domain->name, "bind_path_user", NULL);
if (bind_path_user) {
ctx->bind_path_user = talloc_strdup(ctx, bind_path_user);
if (ctx->bind_path_user == NULL) {
@@ -793,8 +792,8 @@ static NTSTATUS idmap_rfc2307_initialize(struct idmap_domain *domain)
goto err;
}
- bind_path_group = lp_parm_const_string(-1, cfg_opt, "bind_path_group",
- NULL);
+ bind_path_group = idmap_config_const_string(
+ domain->name, "bind_path_group", NULL);
if (bind_path_group) {
ctx->bind_path_group = talloc_strdup(ctx, bind_path_group);
if (ctx->bind_path_group == NULL) {
@@ -806,17 +805,18 @@ static NTSTATUS idmap_rfc2307_initialize(struct idmap_domain *domain)
goto err;
}
- ldap_server = lp_parm_const_string(-1, cfg_opt, "ldap_server", NULL);
+ ldap_server = idmap_config_const_string(
+ domain->name, "ldap_server", NULL);
if (!ldap_server) {
status = NT_STATUS_INVALID_PARAMETER;
goto err;
}
if (strcmp(ldap_server, "stand-alone") == 0) {
- status = idmap_rfc2307_init_ldap(ctx, domain, cfg_opt);
+ status = idmap_rfc2307_init_ldap(ctx, domain->name);
} else if (strcmp(ldap_server, "ad") == 0) {
- status = idmap_rfc2307_init_ads(ctx, cfg_opt);
+ status = idmap_rfc2307_init_ads(ctx, domain->name);
} else {
status = NT_STATUS_INVALID_PARAMETER;
@@ -826,7 +826,7 @@ static NTSTATUS idmap_rfc2307_initialize(struct idmap_domain *domain)
goto err;
}
- realm = lp_parm_const_string(-1, cfg_opt, "realm", NULL);
+ realm = idmap_config_const_string(domain->name, "realm", NULL);
if (realm) {
ctx->realm = talloc_strdup(ctx, realm);
if (ctx->realm == NULL) {
--
1.9.1
>From a3723c2f46013f156e74c7208ce4f8ed5b45362e Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 18 Mar 2017 18:50:38 +0100
Subject: [PATCH 11/19] idmap_ad: Use idmap_config_const_string
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap_ad.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/source3/winbindd/idmap_ad.c b/source3/winbindd/idmap_ad.c
index 5039e9b..f1dfeff 100644
--- a/source3/winbindd/idmap_ad.c
+++ b/source3/winbindd/idmap_ad.c
@@ -397,10 +397,11 @@ static NTSTATUS idmap_ad_context_create(TALLOC_CTX *mem_ctx,
ctx->unix_nss_info = lp_parm_bool(
-1, schema_config_option, "unix_nss_info", false);
- schema_mode = lp_parm_const_string(
- -1, schema_config_option, "schema_mode", "rfc2307");
TALLOC_FREE(schema_config_option);
+ schema_mode = idmap_config_const_string(
+ domname, "schema_mode", "rfc2307");
+
rc = get_posix_schema_names(ctx->ld, schema_mode, ctx, &ctx->schema);
if (!TLDAP_RC_IS_SUCCESS(rc)) {
DBG_DEBUG("get_posix_schema_names failed: %s\n",
--
1.9.1
>From b516bc0e967979b1abb340a0dc937ce057e0279f Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 7 Jan 2017 15:10:05 +0000
Subject: [PATCH 12/19] winbind: Add idmap_config_bool()
---
source3/winbindd/idmap.c | 15 +++++++++++++++
source3/winbindd/winbindd_proto.h | 1 +
2 files changed, 16 insertions(+)
diff --git a/source3/winbindd/idmap.c b/source3/winbindd/idmap.c
index d5471e9..be4ee64 100644
--- a/source3/winbindd/idmap.c
+++ b/source3/winbindd/idmap.c
@@ -193,6 +193,21 @@ const char *idmap_config_const_string(const char *domname, const char *option,
}
}
+bool idmap_config_bool(const char *domname, const char *option, bool def)
+{
+ int len = snprintf(NULL, 0, "idmap config %s", domname);
+
+ if (len == -1) {
+ return def;
+ }
+ {
+ char config_option[len+1];
+ snprintf(config_option, sizeof(config_option),
+ "idmap config %s", domname);
+ return lp_parm_bool(-1, config_option, option, def);
+ }
+}
+
bool domain_has_idmap_config(const char *domname)
{
int i;
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index b33c24f..9afa780 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -380,6 +380,7 @@ struct idmap_domain *idmap_find_domain_with_sid(const char *domname,
const struct dom_sid *sid);
const char *idmap_config_const_string(const char *domname, const char *option,
const char *def);
+bool idmap_config_bool(const char *domname, const char *option, bool def);
bool domain_has_idmap_config(const char *domname);
bool lp_scan_idmap_domains(bool (*fn)(const char *domname,
void *private_data),
--
1.9.1
>From 551646f374d81325bf50f54abd82eb369a4048b3 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 18 Mar 2017 18:53:58 +0100
Subject: [PATCH 13/19] idmap: Use idmap_config_bool in idmap_init_domain
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/source3/winbindd/idmap.c b/source3/winbindd/idmap.c
index be4ee64..602d3cd 100644
--- a/source3/winbindd/idmap.c
+++ b/source3/winbindd/idmap.c
@@ -361,7 +361,6 @@ static struct idmap_domain *idmap_init_domain(TALLOC_CTX *mem_ctx,
{
struct idmap_domain *result;
NTSTATUS status;
- char *config_option = NULL;
const char *range;
unsigned low_id = 0;
unsigned high_id = 0;
@@ -405,18 +404,9 @@ static struct idmap_domain *idmap_init_domain(TALLOC_CTX *mem_ctx,
* load ranges and read only information from the config
*/
- config_option = talloc_asprintf(result, "idmap config %s",
- result->name);
- if (config_option == NULL) {
- DEBUG(0, ("Out of memory!\n"));
- goto fail;
- }
-
- result->read_only = lp_parm_bool(-1, config_option, "read only", false);
+ result->read_only = idmap_config_bool(result->name, "read only", false);
range = idmap_config_const_string(result->name, "range", NULL);
- talloc_free(config_option);
-
if (range == NULL) {
if (check_range) {
DEBUG(1, ("idmap range not specified for domain %s\n",
--
1.9.1
>From 7ab48e45bac5e8dbaba424e4c8929b0e2f32c1bb Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 18 Mar 2017 18:57:03 +0100
Subject: [PATCH 14/19] idmap_rfc2307: Use idmap_config_bool
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap_rfc2307.c | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
diff --git a/source3/winbindd/idmap_rfc2307.c b/source3/winbindd/idmap_rfc2307.c
index d59690e..340757a 100644
--- a/source3/winbindd/idmap_rfc2307.c
+++ b/source3/winbindd/idmap_rfc2307.c
@@ -763,7 +763,6 @@ static int idmap_rfc2307_context_destructor(struct idmap_rfc2307_context *ctx)
static NTSTATUS idmap_rfc2307_initialize(struct idmap_domain *domain)
{
struct idmap_rfc2307_context *ctx;
- char *cfg_opt;
const char *bind_path_user, *bind_path_group, *ldap_server, *realm;
NTSTATUS status;
@@ -773,12 +772,6 @@ static NTSTATUS idmap_rfc2307_initialize(struct idmap_domain *domain)
}
talloc_set_destructor(ctx, idmap_rfc2307_context_destructor);
- cfg_opt = talloc_asprintf(ctx, "idmap config %s", domain->name);
- if (cfg_opt == NULL) {
- status = NT_STATUS_NO_MEMORY;
- goto err;
- }
-
bind_path_user = idmap_config_const_string(
domain->name, "bind_path_user", NULL);
if (bind_path_user) {
@@ -835,14 +828,12 @@ static NTSTATUS idmap_rfc2307_initialize(struct idmap_domain *domain)
}
}
- ctx->user_cn = lp_parm_bool(-1, cfg_opt, "user_cn", false);
+ ctx->user_cn = idmap_config_bool(domain->name, "user_cn", false);
domain->private_data = ctx;
- talloc_free(cfg_opt);
return NT_STATUS_OK;
err:
- talloc_free(cfg_opt);
talloc_free(ctx);
return status;
}
--
1.9.1
>From fedba388360b546f97ae9eb5c408cd24843147e2 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 18 Mar 2017 18:59:06 +0100
Subject: [PATCH 15/19] idmap_ad: Use idmap_config_bool
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap_ad.c | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/source3/winbindd/idmap_ad.c b/source3/winbindd/idmap_ad.c
index f1dfeff..1dbc3e4 100644
--- a/source3/winbindd/idmap_ad.c
+++ b/source3/winbindd/idmap_ad.c
@@ -357,7 +357,6 @@ static NTSTATUS idmap_ad_context_create(TALLOC_CTX *mem_ctx,
struct idmap_ad_context **pctx)
{
struct idmap_ad_context *ctx;
- char *schema_config_option;
const char *schema_mode;
NTSTATUS status;
TLDAPRC rc;
@@ -385,19 +384,10 @@ static NTSTATUS idmap_ad_context_create(TALLOC_CTX *mem_ctx,
return status;
}
- schema_config_option = talloc_asprintf(
- ctx, "idmap config %s", domname);
- if (schema_config_option == NULL) {
- TALLOC_FREE(ctx);
- return NT_STATUS_NO_MEMORY;
- }
-
- ctx->unix_primary_group = lp_parm_bool(
- -1, schema_config_option, "unix_primary_group", false);
- ctx->unix_nss_info = lp_parm_bool(
- -1, schema_config_option, "unix_nss_info", false);
-
- TALLOC_FREE(schema_config_option);
+ ctx->unix_primary_group = idmap_config_bool(
+ domname, "unix_primary_group", false);
+ ctx->unix_nss_info = idmap_config_bool(
+ domname, "unix_nss_info", false);
schema_mode = idmap_config_const_string(
domname, "schema_mode", "rfc2307");
--
1.9.1
>From 71c8fbb8e1bbb982ddc0ae5fd7b625c9e9968f05 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 18 Mar 2017 19:01:01 +0100
Subject: [PATCH 16/19] idmap_autorid: Use idmap_config_bool
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap_autorid.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/source3/winbindd/idmap_autorid.c b/source3/winbindd/idmap_autorid.c
index ab89d35..f53ef54 100644
--- a/source3/winbindd/idmap_autorid.c
+++ b/source3/winbindd/idmap_autorid.c
@@ -869,8 +869,7 @@ static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
DEBUG(5, ("%d domain ranges with a size of %d are available\n",
config->maxranges, config->rangesize));
- ignore_builtin = lp_parm_bool(-1, "idmap config *",
- "ignore builtin", false);
+ ignore_builtin = idmap_config_bool("*", "ignore builtin", false);
/* fill the TDB common configuration */
--
1.9.1
>From a9d42d115109e2628af551567fdca95f5cc403cf Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 8 Jan 2017 11:52:56 +0000
Subject: [PATCH 17/19] winbind: Add idmap_config_int
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap.c | 15 +++++++++++++++
source3/winbindd/winbindd_proto.h | 1 +
2 files changed, 16 insertions(+)
diff --git a/source3/winbindd/idmap.c b/source3/winbindd/idmap.c
index 602d3cd..dda8d0a 100644
--- a/source3/winbindd/idmap.c
+++ b/source3/winbindd/idmap.c
@@ -208,6 +208,21 @@ bool idmap_config_bool(const char *domname, const char *option, bool def)
}
}
+int idmap_config_int(const char *domname, const char *option, int def)
+{
+ int len = snprintf(NULL, 0, "idmap config %s", domname);
+
+ if (len == -1) {
+ return def;
+ }
+ {
+ char config_option[len+1];
+ snprintf(config_option, sizeof(config_option),
+ "idmap config %s", domname);
+ return lp_parm_int(-1, config_option, option, def);
+ }
+}
+
bool domain_has_idmap_config(const char *domname)
{
int i;
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index 9afa780..b8d8baa 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -381,6 +381,7 @@ struct idmap_domain *idmap_find_domain_with_sid(const char *domname,
const char *idmap_config_const_string(const char *domname, const char *option,
const char *def);
bool idmap_config_bool(const char *domname, const char *option, bool def);
+int idmap_config_int(const char *domname, const char *option, int def);
bool domain_has_idmap_config(const char *domname);
bool lp_scan_idmap_domains(bool (*fn)(const char *domname,
void *private_data),
--
1.9.1
>From e7dd001292fe093e2772bd7474bb3266a7944c47 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 18 Mar 2017 19:05:10 +0100
Subject: [PATCH 18/19] idmap_rid: Use idmap_config_int
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap_rid.c | 16 +---------------
1 file changed, 1 insertion(+), 15 deletions(-)
diff --git a/source3/winbindd/idmap_rid.c b/source3/winbindd/idmap_rid.c
index ac53705..8cf1f03 100644
--- a/source3/winbindd/idmap_rid.c
+++ b/source3/winbindd/idmap_rid.c
@@ -37,9 +37,7 @@ struct idmap_rid_context {
static NTSTATUS idmap_rid_initialize(struct idmap_domain *dom)
{
- NTSTATUS ret;
struct idmap_rid_context *ctx;
- char *config_option = NULL;
ctx = talloc_zero(dom, struct idmap_rid_context);
if (ctx == NULL) {
@@ -47,23 +45,11 @@ static NTSTATUS idmap_rid_initialize(struct idmap_domain *dom)
return NT_STATUS_NO_MEMORY;
}
- config_option = talloc_asprintf(ctx, "idmap config %s", dom->name);
- if ( ! config_option) {
- DEBUG(0, ("Out of memory!\n"));
- ret = NT_STATUS_NO_MEMORY;
- goto failed;
- }
-
- ctx->base_rid = lp_parm_int(-1, config_option, "base_rid", 0);
+ ctx->base_rid = idmap_config_int(dom->name, "base_rid", 0);
dom->private_data = ctx;
- talloc_free(config_option);
return NT_STATUS_OK;
-
-failed:
- talloc_free(ctx);
- return ret;
}
static NTSTATUS idmap_rid_id_to_sid(struct idmap_domain *dom, struct id_map *map)
--
1.9.1
>From 50dbae111f1afddda78d947cdbef13c7e95427cb Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 18 Mar 2017 19:06:49 +0100
Subject: [PATCH 19/19] idmap_autorid: Use idmap_config_int
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/winbindd/idmap_autorid.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/source3/winbindd/idmap_autorid.c b/source3/winbindd/idmap_autorid.c
index f53ef54..9793bfe 100644
--- a/source3/winbindd/idmap_autorid.c
+++ b/source3/winbindd/idmap_autorid.c
@@ -844,8 +844,7 @@ static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
commonconfig->private_data = config;
config->minvalue = dom->low_id;
- config->rangesize = lp_parm_int(-1, "idmap config *",
- "rangesize", 100000);
+ config->rangesize = idmap_config_int("*", "rangesize", 100000);
config->maxranges = (dom->high_id - dom->low_id + 1) /
config->rangesize;
--
1.9.1
More information about the samba-technical
mailing list