[PATCH] Small cleanups
Volker Lendecke
vl at samba.org
Mon Mar 13 18:05:40 UTC 2017
Hi!
We will have to live with enumerating trusts for the foreseeable future,
so lets better make the code a bit nicer.
Review appreciated!
Thanks, Volker
-------------- next part --------------
>From 6b4d0cb3706147ad2791efc2159622b02ae185c7 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 20 Jan 2017 13:40:23 +0100
Subject: [PATCH 1/5] libsmb: Remove some stale code
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/proto.h | 2 --
source3/libsmb/trustdom_cache.c | 28 ----------------------------
source3/winbindd/winbindd.c | 2 --
3 files changed, 32 deletions(-)
diff --git a/source3/include/proto.h b/source3/include/proto.h
index e6d4284..acd0127 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -847,8 +847,6 @@ WERROR map_werror_from_unix(int error);
/* The following definitions come from libsmb/trustdom_cache.c */
-bool trustdom_cache_enable(void);
-bool trustdom_cache_shutdown(void);
bool trustdom_cache_store(const char *name, const char *alt_name,
const struct dom_sid *sid, time_t timeout);
bool trustdom_cache_fetch(const char* name, struct dom_sid* sid);
diff --git a/source3/libsmb/trustdom_cache.c b/source3/libsmb/trustdom_cache.c
index d78a28c..587e1d2 100644
--- a/source3/libsmb/trustdom_cache.c
+++ b/source3/libsmb/trustdom_cache.c
@@ -44,34 +44,6 @@
**/
/**
- * Initialise trustdom name caching system. Call gencache
- * initialisation routine to perform necessary activities.
- *
- * @return true upon successful cache initialisation or
- * false if cache init failed
- **/
-
-bool trustdom_cache_enable(void)
-{
- return True;
-}
-
-
-/**
- * Shutdown trustdom name caching system. Calls gencache
- * shutdown function.
- *
- * @return true upon successful cache close or
- * false if it failed
- **/
-
-bool trustdom_cache_shutdown(void)
-{
- return True;
-}
-
-
-/**
* Form up trustdom name key. It is based only
* on domain name now.
*
diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c
index 2cd2001..3c16366 100644
--- a/source3/winbindd/winbindd.c
+++ b/source3/winbindd/winbindd.c
@@ -243,8 +243,6 @@ static void terminate(bool is_parent)
idmap_close();
- trustdom_cache_shutdown();
-
gencache_stabilize();
#if 0
--
2.1.4
>From 6fae87c856368c0f43e5e0be8c382e8f4ad7c43a Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 24 Jan 2017 21:30:40 +0100
Subject: [PATCH 2/5] libsmb: Make a few functions static
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/proto.h | 2 --
source3/libsmb/trustdom_cache.c | 4 ++--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/source3/include/proto.h b/source3/include/proto.h
index acd0127..d095126 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -850,8 +850,6 @@ WERROR map_werror_from_unix(int error);
bool trustdom_cache_store(const char *name, const char *alt_name,
const struct dom_sid *sid, time_t timeout);
bool trustdom_cache_fetch(const char* name, struct dom_sid* sid);
-uint32_t trustdom_cache_fetch_timestamp( void );
-bool trustdom_cache_store_timestamp( uint32_t t, time_t timeout );
void trustdom_cache_flush(void);
void update_trustdom_cache( void );
diff --git a/source3/libsmb/trustdom_cache.c b/source3/libsmb/trustdom_cache.c
index 587e1d2..692ac02 100644
--- a/source3/libsmb/trustdom_cache.c
+++ b/source3/libsmb/trustdom_cache.c
@@ -157,7 +157,7 @@ bool trustdom_cache_fetch(const char* name, struct dom_sid* sid)
fetch the timestamp from the last update
*******************************************************************/
-uint32_t trustdom_cache_fetch_timestamp( void )
+static uint32_t trustdom_cache_fetch_timestamp( void )
{
char *value = NULL;
time_t timeout;
@@ -179,7 +179,7 @@ uint32_t trustdom_cache_fetch_timestamp( void )
store the timestamp from the last update
*******************************************************************/
-bool trustdom_cache_store_timestamp( uint32_t t, time_t timeout )
+static bool trustdom_cache_store_timestamp( uint32_t t, time_t timeout )
{
fstring value;
--
2.1.4
>From 4b3c9f8c21fce3318eff804d1332b70e3b5173ac Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 24 Jan 2017 21:35:16 +0100
Subject: [PATCH 3/5] libsmb: Simplify trustdom_cache_store
The additional arguments were never used
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/proto.h | 3 +--
source3/libsmb/trustdom_cache.c | 27 ++++++---------------------
2 files changed, 7 insertions(+), 23 deletions(-)
diff --git a/source3/include/proto.h b/source3/include/proto.h
index d095126..bb40056 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -847,8 +847,7 @@ WERROR map_werror_from_unix(int error);
/* The following definitions come from libsmb/trustdom_cache.c */
-bool trustdom_cache_store(const char *name, const char *alt_name,
- const struct dom_sid *sid, time_t timeout);
+bool trustdom_cache_store(const char *name, const struct dom_sid *sid);
bool trustdom_cache_fetch(const char* name, struct dom_sid* sid);
void trustdom_cache_flush(void);
void update_trustdom_cache( void );
diff --git a/source3/libsmb/trustdom_cache.c b/source3/libsmb/trustdom_cache.c
index 692ac02..ad2f647 100644
--- a/source3/libsmb/trustdom_cache.c
+++ b/source3/libsmb/trustdom_cache.c
@@ -31,6 +31,7 @@
#define TDOMKEY_FMT "TDOM/%s"
#define TDOMTSKEY "TDOMCACHE/TIMESTAMP"
+#define TRUSTDOM_UPDATE_INTERVAL 600
/**
@@ -72,10 +73,9 @@ static char* trustdom_cache_key(const char* name)
* false if store attempt failed
**/
-bool trustdom_cache_store(const char *name, const char *alt_name,
- const struct dom_sid *sid, time_t timeout)
+bool trustdom_cache_store(const char *name, const struct dom_sid *sid)
{
- char *key, *alt_key;
+ char *key;
fstring sid_string;
bool ret;
@@ -83,25 +83,12 @@ bool trustdom_cache_store(const char *name, const char *alt_name,
sid_string_dbg(sid), name));
key = trustdom_cache_key(name);
- alt_key = alt_name ? trustdom_cache_key(alt_name) : NULL;
/* Generate string representation domain SID */
sid_to_fstring(sid_string, sid);
- /*
- * try to put the names in the cache
- */
- if (alt_key) {
- ret = gencache_set(alt_key, sid_string, timeout);
- if ( ret ) {
- ret = gencache_set(key, sid_string, timeout);
- }
- SAFE_FREE(alt_key);
- SAFE_FREE(key);
- return ret;
- }
-
- ret = gencache_set(key, sid_string, timeout);
+ ret = gencache_set(key, sid_string,
+ time(NULL) + TRUSTDOM_UPDATE_INTERVAL);
SAFE_FREE(key);
return ret;
}
@@ -323,7 +310,6 @@ done:
/********************************************************************
update the trustdom_cache if needed
********************************************************************/
-#define TRUSTDOM_UPDATE_INTERVAL 600
void update_trustdom_cache( void )
{
@@ -362,8 +348,7 @@ void update_trustdom_cache( void )
if ( enumerate_domain_trusts(mem_ctx, lp_workgroup(), &domain_names,
&num_domains, &dom_sids)) {
for ( i=0; i<num_domains; i++ ) {
- trustdom_cache_store( domain_names[i], NULL, &dom_sids[i],
- now+TRUSTDOM_UPDATE_INTERVAL);
+ trustdom_cache_store(domain_names[i], &dom_sids[i]);
}
} else {
/* we failed to fetch the list of trusted domains - restore the old
--
2.1.4
>From ec184646e70141a130f07503ffc4688f956dc38f Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 24 Jan 2017 21:40:42 +0100
Subject: [PATCH 4/5] libsmb: Use talloc in trustdom_cache_key
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/libsmb/trustdom_cache.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/source3/libsmb/trustdom_cache.c b/source3/libsmb/trustdom_cache.c
index ad2f647..6b8e252 100644
--- a/source3/libsmb/trustdom_cache.c
+++ b/source3/libsmb/trustdom_cache.c
@@ -52,12 +52,9 @@
* @return cache key for use in gencache mechanism
**/
-static char* trustdom_cache_key(const char* name)
+static char *trustdom_cache_key(TALLOC_CTX *mem_ctx, const char *name)
{
- char* keystr = NULL;
- asprintf_strupper_m(&keystr, TDOMKEY_FMT, name);
-
- return keystr;
+ return talloc_asprintf_strupper_m(mem_ctx, TDOMKEY_FMT, name);
}
@@ -82,14 +79,14 @@ bool trustdom_cache_store(const char *name, const struct dom_sid *sid)
DEBUG(5, ("trustdom_store: storing SID %s of domain %s\n",
sid_string_dbg(sid), name));
- key = trustdom_cache_key(name);
+ key = trustdom_cache_key(talloc_tos(), name);
/* Generate string representation domain SID */
sid_to_fstring(sid_string, sid);
ret = gencache_set(key, sid_string,
time(NULL) + TRUSTDOM_UPDATE_INTERVAL);
- SAFE_FREE(key);
+ TALLOC_FREE(key);
return ret;
}
@@ -115,16 +112,16 @@ bool trustdom_cache_fetch(const char* name, struct dom_sid* sid)
return False;
/* prepare a key and get the value */
- key = trustdom_cache_key(name);
+ key = trustdom_cache_key(talloc_tos(), name);
if (!key)
return False;
if (!gencache_get(key, talloc_tos(), &value, &timeout)) {
DEBUG(5, ("no entry for trusted domain %s found.\n", name));
- SAFE_FREE(key);
+ TALLOC_FREE(key);
return False;
} else {
- SAFE_FREE(key);
+ TALLOC_FREE(key);
DEBUG(5, ("trusted domain %s found (%s)\n", name, value));
}
@@ -200,11 +197,13 @@ static void flush_trustdom_name(const char* key, const char *value, time_t timeo
void trustdom_cache_flush(void)
{
+ char *key = trustdom_cache_key(talloc_tos(), "*");
/*
* iterate through each TDOM cache's entry and flush it
* by flush_trustdom_name function
*/
- gencache_iterate(flush_trustdom_name, NULL, trustdom_cache_key("*"));
+ gencache_iterate(flush_trustdom_name, NULL, key);
+ TALLOC_FREE(key);
DEBUG(5, ("Trusted domains cache flushed\n"));
}
--
2.1.4
>From bc46572575a8cefb89cbd067bb3d30501ce8c3d0 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 24 Jan 2017 21:42:51 +0100
Subject: [PATCH 5/5] libsmb: Slightly simplify trustdom_cache_fetch
Also adapt to modern coding standards
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/libsmb/trustdom_cache.c | 33 +++++++++++++++------------------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/source3/libsmb/trustdom_cache.c b/source3/libsmb/trustdom_cache.c
index 6b8e252..f7c9e2e 100644
--- a/source3/libsmb/trustdom_cache.c
+++ b/source3/libsmb/trustdom_cache.c
@@ -106,37 +106,34 @@ bool trustdom_cache_fetch(const char* name, struct dom_sid* sid)
{
char *key = NULL, *value = NULL;
time_t timeout;
+ bool ok;
/* exit now if null pointers were passed as they're required further */
- if (!sid)
- return False;
+ if (sid == NULL) {
+ return false;
+ }
/* prepare a key and get the value */
key = trustdom_cache_key(talloc_tos(), name);
- if (!key)
- return False;
+ if (key == NULL) {
+ return false;
+ }
- if (!gencache_get(key, talloc_tos(), &value, &timeout)) {
+ ok = gencache_get(key, talloc_tos(), &value, &timeout);
+ TALLOC_FREE(key);
+ if (!ok) {
DEBUG(5, ("no entry for trusted domain %s found.\n", name));
- TALLOC_FREE(key);
- return False;
- } else {
- TALLOC_FREE(key);
- DEBUG(5, ("trusted domain %s found (%s)\n", name, value));
+ return false;
}
- /* convert sid string representation into struct dom_sid structure */
- if(! string_to_sid(sid, value)) {
- sid = NULL;
- TALLOC_FREE(value);
- return False;
- }
+ DEBUG(5, ("trusted domain %s found (%s)\n", name, value));
+ /* convert sid string representation into struct dom_sid structure */
+ ok = string_to_sid(sid, value);
TALLOC_FREE(value);
- return True;
+ return ok;
}
-
/*******************************************************************
fetch the timestamp from the last update
*******************************************************************/
--
2.1.4
More information about the samba-technical
mailing list