[PATCH] A few cleanups in winbindd

Volker Lendecke Volker.Lendecke at SerNet.DE
Fri Jul 28 11:42:55 UTC 2017


Hi!

Review appreciated!

Thanks, Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 09de365cbc61d77d9935c670767fb36fb7044b33 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 12 Jul 2017 13:30:02 +0200
Subject: [PATCH 01/10] winbindd: Fix a few signed/unsigned hickups

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

diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c
index 98c69f8b231..d4e4471e448 100644
--- a/source3/winbindd/winbindd_cache.c
+++ b/source3/winbindd/winbindd_cache.c
@@ -2477,11 +2477,10 @@ NTSTATUS wcache_lookup_useraliases(struct winbindd_domain *domain,
 {
 	struct winbind_cache *cache = get_cache(domain);
 	struct cache_entry *centry = NULL;
-	uint32_t num_aliases;
+	uint32_t i, num_aliases;
 	uint32_t *aliases;
 	NTSTATUS status;
 	char *sidlist;
-	int i;
 
 	if (cache->tdb == NULL) {
 		return NT_STATUS_NOT_FOUND;
@@ -2541,7 +2540,7 @@ NTSTATUS wb_cache_lookup_useraliases(struct winbindd_domain *domain,
 	struct cache_entry *centry = NULL;
 	NTSTATUS status;
 	char *sidlist;
-	int i;
+	uint32_t i;
 	bool old_status;
 
 	old_status = domain->online;
@@ -2764,7 +2763,7 @@ NTSTATUS wb_cache_trusted_domains(struct winbindd_domain *domain,
 	struct winbindd_tdc_domain *dom_list = NULL;
 	size_t num_domains = 0;
 	bool retval = false;
-	int i;
+	size_t i;
 	bool old_status;
 
 	old_status = domain->online;
@@ -4321,8 +4320,7 @@ static bool add_wbdomain_to_tdc_array( struct winbindd_domain *new_dom,
 				       size_t *num_domains )
 {
 	struct winbindd_tdc_domain *list = NULL;
-	size_t idx;
-	int i;
+	size_t i, idx;
 	bool set_only = false;
 
 	/* don't allow duplicates */
@@ -4423,7 +4421,7 @@ static int pack_tdc_domains( struct winbindd_tdc_domain *domains,
         unsigned char *buffer = NULL;
 	int len = 0;
 	int buflen = 0;
-	int i = 0;
+	size_t i = 0;
 
 	DEBUG(10,("pack_tdc_domains: Packing %d trusted domains\n",
 		  (int)num_domains));
@@ -4693,7 +4691,7 @@ struct winbindd_tdc_domain * wcache_tdc_fetch_domain( TALLOC_CTX *ctx, const cha
 {
 	struct winbindd_tdc_domain *dom_list = NULL;
 	size_t num_domains = 0;
-	int i;
+	size_t i;
 	struct winbindd_tdc_domain *d = NULL;	
 
 	DEBUG(10,("wcache_tdc_fetch_domain: Searching for domain %s\n", name));
-- 
2.11.0


From 2180ffde0fbc78bf7d882d6258e551d0c200f027 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 12 Jul 2017 12:40:29 +0200
Subject: [PATCH 02/10] winbindd: Make wcache_flush_cache static

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

diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c
index d4e4471e448..9c56938bcba 100644
--- a/source3/winbindd/winbindd_cache.c
+++ b/source3/winbindd/winbindd_cache.c
@@ -52,6 +52,8 @@ extern struct winbindd_methods reconnect_ads_methods;
 extern struct winbindd_methods builtin_passdb_methods;
 extern struct winbindd_methods sam_passdb_methods;
 
+static void wcache_flush_cache(void);
+
 /*
  * JRA. KEEP THIS LIST UP TO DATE IF YOU ADD CACHE ENTRIES.
  * Here are the list of entry types that are *not* stored
@@ -3319,7 +3321,7 @@ static int traverse_fn_cleanup(TDB_CONTEXT *the_tdb, TDB_DATA kbuf,
 }
 
 /* flush the cache */
-void wcache_flush_cache(void)
+static void wcache_flush_cache(void)
 {
 	char *db_path;
 
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index 6d6fafcb72f..aa2693b7ecf 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -178,7 +178,6 @@ NTSTATUS wcache_lookup_usergroups(struct winbindd_domain *domain,
 				  uint32_t *pnum_sids,
 				  struct dom_sid **psids);
 
-void wcache_flush_cache(void);
 NTSTATUS wcache_count_cached_creds(struct winbindd_domain *domain, int *count);
 NTSTATUS wcache_remove_oldest_cached_creds(struct winbindd_domain *domain, const struct dom_sid *sid) ;
 bool set_global_winbindd_state_offline(void);
-- 
2.11.0


From 3228d1875370efcc7c6294b4bdb236e01bdd5d0c Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 12 Jul 2017 12:40:29 +0200
Subject: [PATCH 03/10] winbindd: Make wcache_lookup_groupmem static

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/winbindd/winbindd_cache.c | 12 ++++++------
 source3/winbindd/winbindd_proto.h |  6 ------
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c
index 9c56938bcba..aa72b49c63a 100644
--- a/source3/winbindd/winbindd_cache.c
+++ b/source3/winbindd/winbindd_cache.c
@@ -2602,12 +2602,12 @@ NTSTATUS wb_cache_lookup_useraliases(struct winbindd_domain *domain,
 	return status;
 }
 
-NTSTATUS wcache_lookup_groupmem(struct winbindd_domain *domain,
-				TALLOC_CTX *mem_ctx,
-				const struct dom_sid *group_sid,
-				uint32_t *num_names,
-				struct dom_sid **sid_mem, char ***names,
-				uint32_t **name_types)
+static NTSTATUS wcache_lookup_groupmem(struct winbindd_domain *domain,
+				       TALLOC_CTX *mem_ctx,
+				       const struct dom_sid *group_sid,
+				       uint32_t *num_names,
+				       struct dom_sid **sid_mem, char ***names,
+				       uint32_t **name_types)
 {
 	struct winbind_cache *cache = get_cache(domain);
 	struct cache_entry *centry = NULL;
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index aa2693b7ecf..e35f1997b7a 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -134,12 +134,6 @@ bool wcache_invalidate_cache_noinit(void);
 bool init_wcache(void);
 bool initialize_winbindd_cache(void);
 void close_winbindd_cache(void);
-NTSTATUS wcache_lookup_groupmem(struct winbindd_domain *domain,
-				TALLOC_CTX *mem_ctx,
-				const struct dom_sid *group_sid,
-				uint32_t *num_names,
-				struct dom_sid **sid_mem, char ***names,
-				uint32_t **name_types);
 bool lookup_cached_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
 		       char **domain_name, char **name,
 		       enum lsa_SidType *type);
-- 
2.11.0


From 84a164a0eabfd58a67fae7632c41d235196e5938 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 12 Jul 2017 13:12:45 +0200
Subject: [PATCH 04/10] winbindd: Make wcache_name_to_sid static

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/winbindd/winbindd_cache.c | 10 +++++-----
 source3/winbindd/winbindd_proto.h |  5 -----
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c
index aa72b49c63a..2fb41cead8c 100644
--- a/source3/winbindd/winbindd_cache.c
+++ b/source3/winbindd/winbindd_cache.c
@@ -1764,11 +1764,11 @@ skip_save:
 	return status;
 }
 
-NTSTATUS wcache_name_to_sid(struct winbindd_domain *domain,
-			    const char *domain_name,
-			    const char *name,
-			    struct dom_sid *sid,
-			    enum lsa_SidType *type)
+static NTSTATUS wcache_name_to_sid(struct winbindd_domain *domain,
+				   const char *domain_name,
+				   const char *name,
+				   struct dom_sid *sid,
+				   enum lsa_SidType *type)
 {
 	struct winbind_cache *cache = get_cache(domain);
 	struct cache_entry *centry;
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index e35f1997b7a..9aa80631d1b 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -149,11 +149,6 @@ void cache_name2sid_trusted(struct winbindd_domain *domain,
 void cache_name2sid(struct winbindd_domain *domain, 
 		    const char *domain_name, const char *name,
 		    enum lsa_SidType type, const struct dom_sid *sid);
-NTSTATUS wcache_name_to_sid(struct winbindd_domain *domain,
-			    const char *domain_name,
-			    const char *name,
-			    struct dom_sid *sid,
-			    enum lsa_SidType *type);
 NTSTATUS wcache_query_user(struct winbindd_domain *domain,
 			   TALLOC_CTX *mem_ctx,
 			   const struct dom_sid *user_sid,
-- 
2.11.0


From 440cfee384c537061f88e74df87c1528f500b1f7 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 12 Jul 2017 13:14:44 +0200
Subject: [PATCH 05/10] winbindd: Make wcache_lookup_useraliases static

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/winbindd/winbindd_cache.c | 10 ++++++----
 source3/winbindd/winbindd_proto.h |  4 ----
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c
index 2fb41cead8c..e19ffbc2443 100644
--- a/source3/winbindd/winbindd_cache.c
+++ b/source3/winbindd/winbindd_cache.c
@@ -2472,10 +2472,12 @@ static char *wcache_make_sidlist(TALLOC_CTX *mem_ctx, uint32_t num_sids,
 	return sidlist;
 }
 
-NTSTATUS wcache_lookup_useraliases(struct winbindd_domain *domain,
-				   TALLOC_CTX *mem_ctx, uint32_t num_sids,
-				   const struct dom_sid *sids,
-				   uint32_t *pnum_aliases, uint32_t **paliases)
+static NTSTATUS wcache_lookup_useraliases(struct winbindd_domain *domain,
+					  TALLOC_CTX *mem_ctx,
+					  uint32_t num_sids,
+					  const struct dom_sid *sids,
+					  uint32_t *pnum_aliases,
+					  uint32_t **paliases)
 {
 	struct winbind_cache *cache = get_cache(domain);
 	struct cache_entry *centry = NULL;
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index 9aa80631d1b..cbfb903c99d 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -157,10 +157,6 @@ NTSTATUS wcache_query_user_fullname(struct winbindd_domain *domain,
 				    TALLOC_CTX *mem_ctx,
 				    const struct dom_sid *user_sid,
 				    const char **full_name);
-NTSTATUS wcache_lookup_useraliases(struct winbindd_domain *domain,
-				   TALLOC_CTX *mem_ctx,
-				   uint32_t num_sids, const struct dom_sid *sids,
-				   uint32_t *pnum_aliases, uint32_t **paliases);
 NTSTATUS wcache_lookup_usergroups(struct winbindd_domain *domain,
 				  TALLOC_CTX *mem_ctx,
 				  const struct dom_sid *user_sid,
-- 
2.11.0


From f85a0404618dbc97fc83ede987571d89328f4568 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 12 Jul 2017 13:32:33 +0200
Subject: [PATCH 06/10] winbindd: Make init_wcache static

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/winbindd/winbindd_cache.c | 2 +-
 source3/winbindd/winbindd_proto.h | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c
index e19ffbc2443..7f363e953d8 100644
--- a/source3/winbindd/winbindd_cache.c
+++ b/source3/winbindd/winbindd_cache.c
@@ -3111,7 +3111,7 @@ bool wcache_invalidate_cache_noinit(void)
 	return true;
 }
 
-bool init_wcache(void)
+static bool init_wcache(void)
 {
 	char *db_path;
 
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index cbfb903c99d..e8051b28c55 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -131,7 +131,6 @@ void wcache_invalidate_samlogon(struct winbindd_domain *domain,
 				const struct dom_sid *user_sid);
 bool wcache_invalidate_cache(void);
 bool wcache_invalidate_cache_noinit(void);
-bool init_wcache(void);
 bool initialize_winbindd_cache(void);
 void close_winbindd_cache(void);
 bool lookup_cached_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
-- 
2.11.0


From c906d2d75a2d25c2b0baa2b285365537d8ed5b70 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 12 Jul 2017 14:32:02 +0200
Subject: [PATCH 07/10] winbindd: Fix indentation

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

diff --git a/source3/winbindd/winbindd_pam.c b/source3/winbindd/winbindd_pam.c
index 37b0c098d89..11672f737bc 100644
--- a/source3/winbindd/winbindd_pam.c
+++ b/source3/winbindd/winbindd_pam.c
@@ -1863,10 +1863,10 @@ sam_logon:
 			goto cached_logon;
 		}
 
-			if (domain->online) {
-				/* We're still online - fail. */
-				goto done;
-			}
+		if (domain->online) {
+			/* We're still online - fail. */
+			goto done;
+		}
 	}
 
 cached_logon:
-- 
2.11.0


From a1039007ab25a99317f8c79aa19109adf6793d8a Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 12 Jul 2017 14:56:32 +0200
Subject: [PATCH 08/10] winbindd: Make wcache_lookup_usergroups static

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/winbindd/winbindd_cache.c | 10 +++++-----
 source3/winbindd/winbindd_proto.h |  5 -----
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c
index 7f363e953d8..adc68eb0d11 100644
--- a/source3/winbindd/winbindd_cache.c
+++ b/source3/winbindd/winbindd_cache.c
@@ -2321,11 +2321,11 @@ NTSTATUS wcache_query_user_fullname(struct winbindd_domain *domain,
 	return NT_STATUS_OK;
 }
 
-NTSTATUS wcache_lookup_usergroups(struct winbindd_domain *domain,
-				  TALLOC_CTX *mem_ctx,
-				  const struct dom_sid *user_sid,
-				  uint32_t *pnum_sids,
-				  struct dom_sid **psids)
+static NTSTATUS wcache_lookup_usergroups(struct winbindd_domain *domain,
+					 TALLOC_CTX *mem_ctx,
+					 const struct dom_sid *user_sid,
+					 uint32_t *pnum_sids,
+					 struct dom_sid **psids)
 {
 	struct winbind_cache *cache = get_cache(domain);
 	struct cache_entry *centry = NULL;
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index e8051b28c55..6aa0ed99b6b 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -156,11 +156,6 @@ NTSTATUS wcache_query_user_fullname(struct winbindd_domain *domain,
 				    TALLOC_CTX *mem_ctx,
 				    const struct dom_sid *user_sid,
 				    const char **full_name);
-NTSTATUS wcache_lookup_usergroups(struct winbindd_domain *domain,
-				  TALLOC_CTX *mem_ctx,
-				  const struct dom_sid *user_sid,
-				  uint32_t *pnum_sids,
-				  struct dom_sid **psids);
 
 NTSTATUS wcache_count_cached_creds(struct winbindd_domain *domain, int *count);
 NTSTATUS wcache_remove_oldest_cached_creds(struct winbindd_domain *domain, const struct dom_sid *sid) ;
-- 
2.11.0


From 716d7fd853eb433b63abc7de5248823b79cdf3cb Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 13 Jul 2017 15:52:35 +0200
Subject: [PATCH 09/10] winbindd: Simplify wcache_cached_creds_exist

No need to fetch, use tdb_exists

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

diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c
index adc68eb0d11..ce5e5cdfa30 100644
--- a/source3/winbindd/winbindd_cache.c
+++ b/source3/winbindd/winbindd_cache.c
@@ -1269,7 +1269,7 @@ do_query:
 NTSTATUS wcache_cached_creds_exist(struct winbindd_domain *domain, const struct dom_sid *sid)
 {
 	struct winbind_cache *cache = get_cache(domain);
-	TDB_DATA data;
+	int ret;
 	fstring key_str, tmp;
 	uint32_t rid;
 
@@ -1287,12 +1287,11 @@ NTSTATUS wcache_cached_creds_exist(struct winbindd_domain *domain, const struct
 
 	fstr_sprintf(key_str, "CRED/%s", sid_to_fstring(tmp, sid));
 
-	data = tdb_fetch(cache->tdb, string_tdb_data(key_str));
-	if (!data.dptr) {
+	ret = tdb_exists(cache->tdb, string_tdb_data(key_str));
+	if (ret != 0) {
 		return NT_STATUS_OBJECT_NAME_NOT_FOUND;
 	}
 
-	SAFE_FREE(data.dptr);
 	return NT_STATUS_OK;
 }
 
-- 
2.11.0


From c4bdbb16fe49142cbafb16184b9ee72deeb3a778 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 14 Jul 2017 13:18:59 +0200
Subject: [PATCH 10/10] winbindd: Simplify two debug msgs

With DBG_DEBUG we get the function name automatically, DEBUGADD is also
not necessary here

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

diff --git a/source3/winbindd/winbindd_cred_cache.c b/source3/winbindd/winbindd_cred_cache.c
index 20b4d55fb80..ed2dd10c91d 100644
--- a/source3/winbindd/winbindd_cred_cache.c
+++ b/source3/winbindd/winbindd_cred_cache.c
@@ -118,9 +118,8 @@ static void krb5_ticket_refresh_handler(struct tevent_context *event_ctx,
 	struct WINBINDD_MEMORY_CREDS *cred_ptr = entry->cred_ptr;
 #endif
 
-	DEBUG(10,("krb5_ticket_refresh_handler called\n"));
-	DEBUGADD(10,("event called for: %s, %s\n",
-		entry->ccname, entry->username));
+	DBG_DEBUG("event called for: %s, %s\n",
+		  entry->ccname, entry->username);
 
 	TALLOC_FREE(entry->event);
 
@@ -311,9 +310,8 @@ static void krb5_ticket_gain_handler(struct tevent_context *event_ctx,
 	struct winbindd_domain *domain = NULL;
 #endif
 
-	DEBUG(10,("krb5_ticket_gain_handler called\n"));
-	DEBUGADD(10,("event called for: %s, %s\n",
-		entry->ccname, entry->username));
+	DBG_DEBUG("event called for: %s, %s\n",
+		  entry->ccname, entry->username);
 
 	TALLOC_FREE(entry->event);
 
-- 
2.11.0



More information about the samba-technical mailing list