namemap_cache: Absorb the expired calculation into namemap_cache.c
authorVolker Lendecke <vl@samba.org>
Sat, 13 Oct 2018 10:01:41 +0000 (12:01 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 16 Oct 2018 16:00:10 +0000 (18:00 +0200)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/namemap_cache.c
source3/lib/namemap_cache.h
source3/torture/test_namemap_cache.c
source3/winbindd/winbindd_cache.c

index 38f7a2ddc88044989626c8d9094c2334a16b68be..f6e71cd6d169a0a413e07e61d1c383bdfcd65de0 100644 (file)
@@ -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)
 {
index a70de34b885868cb7ea92956fe88dc2e6272b1ec..5de8ce4c0f2e3223e10c76c4ff65d9848b3022af 100644 (file)
@@ -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);
 
index 07c6bf4744ee2d8b9fdbb8312865620275decd5b..01dd1b7c8dccd1230c8aee1e422f7d9046050f7a 100644 (file)
@@ -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;
index be3e5ffc2ade180545a6fc944190e1081e12b858..7d98d613ac447194b4a9ac32ea861c3d30ac3da1 100644 (file)
@@ -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,