[PATCH] Some small cleanups in winbind

Volker Lendecke vl at samba.org
Tue Apr 11 17:01:14 UTC 2017


Hi!

Review appreciated!

Thanks, Volker
-------------- next part --------------
From dcf0dda8c530e16b9bb616b97b410ba33cb6bf20 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 9 Mar 2017 18:49:39 +0100
Subject: [PATCH 1/5] winbind: Simplify a logic expression

This isn't 100% the same flow, but before this patch we initialized
domain->primary to "false" via "talloc_zero". This means that the
end-result should be the same before and after this patch that IMHO
simplifies the logic a bit.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/winbindd/winbindd_util.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/source3/winbindd/winbindd_util.c b/source3/winbindd/winbindd_util.c
index 8f16da7..ee6ca60 100644
--- a/source3/winbindd/winbindd_util.c
+++ b/source3/winbindd/winbindd_util.c
@@ -252,12 +252,10 @@ add_trusted_domain_from_tdc(const struct winbindd_tdc_domain *tdc)
 	domain->domain_trust_attribs = tdc->trust_attribs;
 
 	/* Is this our primary domain ? */
-	if (strequal(domain_name, get_global_sam_name()) &&
-			(role != ROLE_DOMAIN_MEMBER)) {
-		domain->primary = true;
-	} else if (strequal(domain_name, lp_workgroup()) &&
-			(role == ROLE_DOMAIN_MEMBER)) {
-		domain->primary = true;
+	if (role == ROLE_DOMAIN_MEMBER) {
+		domain->primary = strequal(domain_name, lp_workgroup());
+	} else {
+		domain->primary = strequal(domain_name, get_global_sam_name());
 	}
 
 	if (domain->primary) {
-- 
2.7.4


From 3e56d35195fbd280bd89472de9b26826305edc59 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 9 Mar 2017 18:27:55 +0100
Subject: [PATCH 2/5] winbind: Avoid a "ok==false"

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

diff --git a/source3/winbindd/winbindd_util.c b/source3/winbindd/winbindd_util.c
index ee6ca60..d2a091a 100644
--- a/source3/winbindd/winbindd_util.c
+++ b/source3/winbindd/winbindd_util.c
@@ -854,7 +854,7 @@ bool init_domain_list(void)
 			 */
 			ok = migrate_secrets_tdb_to_ldb(domain);
 
-			if (ok == false) {
+			if (!ok) {
 				DEBUG(0, ("Failed to migrate our own, "
 					  "local AD domain join password for "
 					  "winbindd's internal use into "
@@ -865,7 +865,7 @@ bool init_domain_list(void)
 					       current_nt_hash.hash,
 					       &account_name,
 					       &sec_chan_type);
-			if (ok == false) {
+			if (!ok) {
 				DEBUG(0, ("Failed to find our our own, just "
 					  "written local AD domain join "
 					  "password for winbindd's internal "
-- 
2.7.4


From b9f16e8ac2b54ec18153d9bd2bad806c25625fa8 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 9 Mar 2017 17:50:01 +0100
Subject: [PATCH 3/5] winbind: Slightly simplify remove_timed_out_clients

Best reviewed with "git show -b"

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

diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c
index 3c16366..58e4d89 100644
--- a/source3/winbindd/winbindd.c
+++ b/source3/winbindd/winbindd.c
@@ -1125,24 +1125,25 @@ static void remove_timed_out_clients(void)
 		prev = winbindd_client_list_prev(state);
 		expiry_time = state->last_access + timeout_val;
 
-		if (curr_time > expiry_time) {
-			if (client_is_idle(state)) {
-				DEBUG(5,("Idle client timed out, "
-					"shutting down sock %d, pid %u\n",
-					state->sock,
-					(unsigned int)state->pid));
-			} else {
-				DEBUG(5,("Client request timed out, "
-					"shutting down sock %d, pid %u\n",
-					state->sock,
-					(unsigned int)state->pid));
-			}
-			remove_client(state);
-		} else {
+		if (curr_time <= expiry_time) {
 			/* list is sorted, previous clients in
 			   list are newer */
 			break;
 		}
+
+		if (client_is_idle(state)) {
+			DEBUG(5,("Idle client timed out, "
+				 "shutting down sock %d, pid %u\n",
+				 state->sock,
+				 (unsigned int)state->pid));
+		} else {
+			DEBUG(5,("Client request timed out, "
+				 "shutting down sock %d, pid %u\n",
+				 state->sock,
+				 (unsigned int)state->pid));
+		}
+
+		remove_client(state);
 	}
 }
 
-- 
2.7.4


From 92d9e05e172cb65b49813683ac517acfe91c5c7d Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 6 Mar 2017 20:36:25 +0000
Subject: [PATCH 4/5] winbind_pam: Use any_nt_status_not_ok in
 map_auth_samlogon

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

diff --git a/source3/winbindd/winbindd_pam.c b/source3/winbindd/winbindd_pam.c
index 292f556..718acd7 100644
--- a/source3/winbindd/winbindd_pam.c
+++ b/source3/winbindd/winbindd_pam.c
@@ -1695,18 +1695,13 @@ static NTSTATUS winbindd_dual_pam_auth_samlogon(TALLOC_CTX *mem_ctx,
 						       &info,
 						       &result_tmp);
 
-		if (!NT_STATUS_IS_OK(status_tmp)) {
+		if (any_nt_status_not_ok(status_tmp, result_tmp,
+					 &status_tmp)) {
 			DEBUG(3, ("could not query user info on SAMR pipe: %s\n",
 				nt_errstr(status_tmp)));
 			dcerpc_samr_Close(b, mem_ctx, &user_pol, &result_tmp);
 			goto done;
 		}
-		if (!NT_STATUS_IS_OK(result_tmp)) {
-			DEBUG(3, ("could not query user info on SAMR pipe: %s\n",
-				nt_errstr(result_tmp)));
-			dcerpc_samr_Close(b, mem_ctx, &user_pol, &result_tmp);
-			goto done;
-		}
 
 		acct_flags = info->info16.acct_flags;
 
-- 
2.7.4


From 0484ca8a15e5a1d77713d9d61129e7e7b9a8a036 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 9 Mar 2017 18:57:14 +0100
Subject: [PATCH 5/5] winbind_msrpc: Use any_nt_status_not_ok

Less lines, less bytes .text

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/winbindd/winbindd_msrpc.c | 31 ++++++-------------------------
 1 file changed, 6 insertions(+), 25 deletions(-)

diff --git a/source3/winbindd/winbindd_msrpc.c b/source3/winbindd/winbindd_msrpc.c
index cd7dfbc..c565376 100644
--- a/source3/winbindd/winbindd_msrpc.c
+++ b/source3/winbindd/winbindd_msrpc.c
@@ -576,12 +576,9 @@ static NTSTATUS msrpc_lookup_groupmem(struct winbindd_domain *domain,
 				       group_rid,
 				       &group_pol,
 				       &result);
-	if (!NT_STATUS_IS_OK(status)) {
+	if (any_nt_status_not_ok(status, result, &status)) {
 		return status;
 	}
-	if (!NT_STATUS_IS_OK(result)) {
-		return result;
-	}
 
         /* Step #1: Get a list of user rids that are the members of the
            group. */
@@ -604,14 +601,10 @@ static NTSTATUS msrpc_lookup_groupmem(struct winbindd_domain *domain,
 		dcerpc_samr_Close(b, mem_ctx, &group_pol, &_result);
 	}
 
-	if (!NT_STATUS_IS_OK(status)) {
+	if (any_nt_status_not_ok(status, result, &status)) {
 		return status;
 	}
 
-	if (!NT_STATUS_IS_OK(result)) {
-		return result;
-	}
-
 	if (!rids || !rids->count) {
 		names = NULL;
 		name_types = NULL;
@@ -927,12 +920,8 @@ static NTSTATUS msrpc_lockout_policy(struct winbindd_domain *domain,
 					     DomainLockoutInformation,
 					     &info,
 					     &result);
-	if (!NT_STATUS_IS_OK(status)) {
-		goto done;
-	}
-	if (!NT_STATUS_IS_OK(result)) {
-		status = result;
-		goto done;
+	if (any_nt_status_not_ok(status, result, &status)) {
+		return status;
 	}
 
 	*lockout_policy = info->info12;
@@ -1062,14 +1051,10 @@ NTSTATUS winbindd_lookup_sids(TALLOC_CTX *mem_ctx,
 		status = NT_STATUS_ACCESS_DENIED;
 	}
 
-	if (!NT_STATUS_IS_OK(status)) {
+	if (any_nt_status_not_ok(status, result, &status)) {
 		return status;
 	}
 
-	if (!NT_STATUS_IS_OK(result)) {
-		return result;
-	}
-
 	return NT_STATUS_OK;
 }
 
@@ -1141,14 +1126,10 @@ static NTSTATUS winbindd_lookup_names(TALLOC_CTX *mem_ctx,
 		status = NT_STATUS_ACCESS_DENIED;
 	}
 
-	if (!NT_STATUS_IS_OK(status)) {
+	if (any_nt_status_not_ok(status, result, &status)) {
 		return status;
 	}
 
-	if (!NT_STATUS_IS_OK(result)) {
-		return result;
-	}
-
 	return NT_STATUS_OK;
 }
 
-- 
2.7.4



More information about the samba-technical mailing list