From: Volker Lendecke Date: Sat, 13 Oct 2018 10:01:41 +0000 (+0200) Subject: namemap_cache: Absorb the expired calculation into namemap_cache.c X-Git-Tag: tdb-1.3.17~1313 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fdb50817cac2423adae3daf94759ecf1e6580760;p=thirdparty%2Fsamba.git namemap_cache: Absorb the expired calculation into namemap_cache.c Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/lib/namemap_cache.c b/source3/lib/namemap_cache.c index 38f7a2ddc88..f6e71cd6d16 100644 --- a/source3/lib/namemap_cache.c +++ b/source3/lib/namemap_cache.c @@ -85,8 +85,10 @@ fail: } struct namemap_cache_find_sid_state { - void (*fn)(const char *domain, const char *name, - enum lsa_SidType type, time_t timeout, + void (*fn)(const char *domain, + const char *name, + enum lsa_SidType type, + bool expired, void *private_data); void *private_data; bool ok; @@ -127,15 +129,20 @@ static void namemap_cache_find_sid_parser(time_t timeout, DATA_BLOB blob, return; } - state->fn(domain, name, (enum lsa_SidType)type, timeout, + state->fn(domain, + name, + (enum lsa_SidType)type, + timeout <= time(NULL), state->private_data); state->ok = true; } bool namemap_cache_find_sid(const struct dom_sid *sid, - void (*fn)(const char *domain, const char *name, - enum lsa_SidType type, time_t timeout, + void (*fn)(const char *domain, + const char *name, + enum lsa_SidType type, + bool expired, void *private_data), void *private_data) { @@ -227,7 +234,8 @@ fail: struct namemap_cache_find_name_state { void (*fn)(const struct dom_sid *sid, - enum lsa_SidType type, time_t timeout, + enum lsa_SidType type, + bool expired, void *private_data); void *private_data; bool ok; @@ -274,14 +282,19 @@ static void namemap_cache_find_name_parser(time_t timeout, DATA_BLOB blob, return; } - state->fn(&sid, (enum lsa_SidType)type, timeout, state->private_data); + state->fn(&sid, + (enum lsa_SidType)type, + timeout <= time(NULL), + state->private_data); state->ok = true; } -bool namemap_cache_find_name(const char *domain, const char *name, +bool namemap_cache_find_name(const char *domain, + const char *name, void (*fn)(const struct dom_sid *sid, - enum lsa_SidType type, time_t timeout, + enum lsa_SidType type, + bool expired, void *private_data), void *private_data) { diff --git a/source3/lib/namemap_cache.h b/source3/lib/namemap_cache.h index a70de34b885..5de8ce4c0f2 100644 --- a/source3/lib/namemap_cache.h +++ b/source3/lib/namemap_cache.h @@ -32,13 +32,17 @@ bool namemap_cache_set_name2sid(const char *domain, const char *name, enum lsa_SidType type, time_t timeout); bool namemap_cache_find_sid(const struct dom_sid *sid, - void (*fn)(const char *domain, const char *name, - enum lsa_SidType type, time_t timeout, + void (*fn)(const char *domain, + const char *name, + enum lsa_SidType type, + bool expired, void *private_data), void *private_data); -bool namemap_cache_find_name(const char *domain, const char *name, +bool namemap_cache_find_name(const char *domain, + const char *name, void (*fn)(const struct dom_sid *sid, - enum lsa_SidType type, time_t timeout, + enum lsa_SidType type, + bool expired, void *private_data), void *private_data); diff --git a/source3/torture/test_namemap_cache.c b/source3/torture/test_namemap_cache.c index 07c6bf4744e..01dd1b7c8dc 100644 --- a/source3/torture/test_namemap_cache.c +++ b/source3/torture/test_namemap_cache.c @@ -26,8 +26,10 @@ static const struct dom_sid domsid = { 1, 4, {0,0,0,0,0,5}, {21, 123, 456, 789} }; -static void namemap_cache1_fn1(const char *domain, const char *name, - enum lsa_SidType type, time_t timeout, +static void namemap_cache1_fn1(const char *domain, + const char *name, + enum lsa_SidType type, + bool expired, void *private_data) { bool *p_ok = private_data; @@ -41,7 +43,8 @@ static void namemap_cache1_fn1(const char *domain, const char *name, } static void namemap_cache1_fn2(const struct dom_sid *sid, - enum lsa_SidType type, time_t timeout, + enum lsa_SidType type, + bool expired, void *private_data) { bool *p_ok = private_data; @@ -53,8 +56,10 @@ static void namemap_cache1_fn2(const struct dom_sid *sid, *p_ok = ok; } -static void namemap_cache1_fn3(const char *domain, const char *name, - enum lsa_SidType type, time_t timeout, +static void namemap_cache1_fn3(const char *domain, + const char *name, + enum lsa_SidType type, + bool expired, void *private_data) { bool *p_ok = private_data; @@ -68,7 +73,8 @@ static void namemap_cache1_fn3(const char *domain, const char *name, } static void namemap_cache1_fn4(const struct dom_sid *sid, - enum lsa_SidType type, time_t timeout, + enum lsa_SidType type, + bool expired, void *private_data) { bool *p_ok = private_data; @@ -80,8 +86,10 @@ static void namemap_cache1_fn4(const struct dom_sid *sid, *p_ok = ok; } -static void namemap_cache1_fn5(const char *domain, const char *name, - enum lsa_SidType type, time_t timeout, +static void namemap_cache1_fn5(const char *domain, + const char *name, + enum lsa_SidType type, + bool expired, void *private_data) { bool *p_ok = private_data; @@ -95,7 +103,8 @@ static void namemap_cache1_fn5(const char *domain, const char *name, } static void namemap_cache1_fn6(const struct dom_sid *sid, - enum lsa_SidType type, time_t timeout, + enum lsa_SidType type, + bool expired, void *private_data) { bool *p_ok = private_data; diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c index be3e5ffc2ad..7d98d613ac4 100644 --- a/source3/winbindd/winbindd_cache.c +++ b/source3/winbindd/winbindd_cache.c @@ -1742,14 +1742,15 @@ struct wcache_name_to_sid_state { }; static void wcache_name_to_sid_fn(const struct dom_sid *sid, - enum lsa_SidType type, time_t timeout, + enum lsa_SidType type, + bool expired, void *private_data) { struct wcache_name_to_sid_state *state = private_data; *state->sid = *sid; *state->type = type; - state->found = (state->offline || (timeout > time(NULL))); + state->found = (!expired || state->offline); } static NTSTATUS wcache_name_to_sid(struct winbindd_domain *domain, @@ -1869,8 +1870,10 @@ struct wcache_sid_to_name_state { bool found; }; -static void wcache_sid_to_name_fn(const char *domain, const char *name, - enum lsa_SidType type, time_t timeout, +static void wcache_sid_to_name_fn(const char *domain, + const char *name, + enum lsa_SidType type, + bool expired, void *private_data) { struct wcache_sid_to_name_state *state = private_data; @@ -1884,7 +1887,7 @@ static void wcache_sid_to_name_fn(const char *domain, const char *name, return; } *state->type = type; - state->found = (state->offline || (timeout > time(NULL))); + state->found = (!expired || state->offline); } static NTSTATUS wcache_sid_to_name(struct winbindd_domain *domain,