[PATCH] Some small cleanups

Volker Lendecke vl at samba.org
Tue Mar 21 20:08:08 UTC 2017


Hi!

Review appreciated!

Thanks, Volker
-------------- next part --------------
>From 8541f62a1c524b3201a61fcf6c6ed35bac84ea23 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 8 Jan 2017 13:00:39 +0000
Subject: [PATCH 1/3] idmap_tdb: Avoid a few casts

The times of attempting to be C++ compatible are gone since C compilers
can do very good warnings too.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/winbindd/idmap_tdb_common.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/source3/winbindd/idmap_tdb_common.c b/source3/winbindd/idmap_tdb_common.c
index 0d7e734..e873b60 100644
--- a/source3/winbindd/idmap_tdb_common.c
+++ b/source3/winbindd/idmap_tdb_common.c
@@ -51,11 +51,9 @@ static NTSTATUS idmap_tdb_common_allocate_id_action(struct db_context *db,
 						    void *private_data)
 {
 	NTSTATUS ret;
-	struct idmap_tdb_common_allocate_id_context *state;
+	struct idmap_tdb_common_allocate_id_context *state = private_data;
 	uint32_t hwm;
 
-	state = (struct idmap_tdb_common_allocate_id_context *)private_data;
-
 	ret = dbwrap_fetch_uint32_bystring(db, state->hwmkey, &hwm);
 	if (!NT_STATUS_IS_OK(ret)) {
 		ret = NT_STATUS_INTERNAL_DB_ERROR;
@@ -180,11 +178,9 @@ static NTSTATUS idmap_tdb_common_set_mapping_action(struct db_context *db,
 {
 	TDB_DATA data;
 	NTSTATUS ret;
-	struct idmap_tdb_common_set_mapping_context *state;
+	struct idmap_tdb_common_set_mapping_context *state = private_data;
 	TALLOC_CTX *tmp_ctx = talloc_stackframe();
 
-	state = (struct idmap_tdb_common_set_mapping_context *)private_data;
-
 	DEBUG(10, ("Storing %s <-> %s map\n", state->ksidstr, state->kidstr));
 
 	/* check whether sid mapping is already present in db */
@@ -546,12 +542,10 @@ struct idmap_tdb_common_sids_to_unixids_context {
 static NTSTATUS idmap_tdb_common_sids_to_unixids_action(struct db_context *db,
 							void *private_data)
 {
-	struct idmap_tdb_common_sids_to_unixids_context *state;
+	struct idmap_tdb_common_sids_to_unixids_context *state = private_data;
 	int i, num_mapped = 0;
 	NTSTATUS ret = NT_STATUS_OK;
 
-	state = (struct idmap_tdb_common_sids_to_unixids_context *)private_data;
-
 	DEBUG(10, ("idmap_tdb_common_sids_to_unixids: "
 		   " domain: [%s], allocate: %s\n",
 		   state->dom->name, state->allocate_unmapped ? "yes" : "no"));
-- 
2.1.4


>From 1354785ab98d193ee134acb50594445fc9a61e58 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 21 Mar 2017 15:52:37 +0100
Subject: [PATCH 2/3] idmap_rfc2307: Slightly simplify
 idmap_rfc2307_initialize()

Replace an "else" branch with an early "goto err"

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/winbindd/idmap_rfc2307.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/source3/winbindd/idmap_rfc2307.c b/source3/winbindd/idmap_rfc2307.c
index 340757a..8ee84f7 100644
--- a/source3/winbindd/idmap_rfc2307.c
+++ b/source3/winbindd/idmap_rfc2307.c
@@ -774,29 +774,27 @@ static NTSTATUS idmap_rfc2307_initialize(struct idmap_domain *domain)
 
 	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) {
-			status = NT_STATUS_NO_MEMORY;
-			goto err;
-		}
-	} else {
+	if (bind_path_user == NULL) {
 		status = NT_STATUS_INVALID_PARAMETER;
 		goto err;
 	}
+	ctx->bind_path_user = talloc_strdup(ctx, bind_path_user);
+	if (ctx->bind_path_user == NULL) {
+		status = NT_STATUS_NO_MEMORY;
+		goto err;
+	}
 
 	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) {
-			status = NT_STATUS_NO_MEMORY;
-			goto err;
-		}
-	} else {
+	if (bind_path_group == NULL) {
 		status = NT_STATUS_INVALID_PARAMETER;
 		goto err;
 	}
+	ctx->bind_path_group = talloc_strdup(ctx, bind_path_group);
+	if (ctx->bind_path_group == NULL) {
+		status = NT_STATUS_NO_MEMORY;
+		goto err;
+	}
 
 	ldap_server = idmap_config_const_string(
 		domain->name, "ldap_server", NULL);
-- 
2.1.4


>From 559a05e3b8520ebec31eaed32c8307f85d12df06 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 21 Mar 2017 16:00:27 +0100
Subject: [PATCH 3/3] idmap_rfc2307: Clarify the documentation a bit

"bind_path" is a variable name internally used inside Samba. If you
look at "man ldapsearch" from OpenLDAP for example, the more common
term for this parameter is "search base". Adapt the documentation
accordingly.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 docs-xml/manpages/idmap_rfc2307.8.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/docs-xml/manpages/idmap_rfc2307.8.xml b/docs-xml/manpages/idmap_rfc2307.8.xml
index 024415a..5785662 100644
--- a/docs-xml/manpages/idmap_rfc2307.8.xml
+++ b/docs-xml/manpages/idmap_rfc2307.8.xml
@@ -70,13 +70,13 @@
 		</varlistentry>
 		<varlistentry>
 			<term>bind_path_user</term>
-			<listitem><para>Specifies the bind path where
+			<listitem><para>Specifies the search base where
 			user objects can be found in the LDAP
 			server.</para></listitem>
 		</varlistentry>
 		<varlistentry>
 			<term>bind_path_group</term>
-			<listitem><para>Specifies the bind path where
+			<listitem><para>Specifies the search base where
 			group objects can be found in the LDAP
 			server.</para></listitem>
 		</varlistentry>
-- 
2.1.4



More information about the samba-technical mailing list