]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: libsmb: Add namecache_store_sa(). Doesn't store ports and takes a samba_sockaddr...
authorJeremy Allison <jra@samba.org>
Thu, 27 Aug 2020 18:45:17 +0000 (11:45 -0700)
committerNoel Power <npower@samba.org>
Mon, 7 Sep 2020 13:23:44 +0000 (13:23 +0000)
Now uses ipstr_list_make_sa(). Now convert
the callers, remove namecache_store() and
then rename namecache_store_sa() back to namecache_store().

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
source3/include/proto.h
source3/libsmb/namecache.c

index dacd9e7fa44a4d726034f93b2fcb59040b9825a8..cc151eb7f5ead1ce70cb7711f1d6193fc9620dd4 100644 (file)
@@ -680,6 +680,10 @@ bool namecache_store(const char *name,
                        int name_type,
                        size_t num_names,
                        struct ip_service *ip_list);
+bool namecache_store_sa(const char *name,
+                       int name_type,
+                       size_t num_names,
+                       struct samba_sockaddr *sa_list);
 bool namecache_fetch(TALLOC_CTX *ctx,
                        const char *name,
                        int name_type,
index 0b853ed7e4a5f9617338b3119d7702a786d1cf34..69299aee38015e51e2751368016db8687f447ab1 100644 (file)
@@ -108,7 +108,6 @@ static char *ipstr_list_make(TALLOC_CTX *ctx,
        return ipstr_list;
 }
 
-#if 0
 /**
  * Allocate and initialise an ipstr list using samba_sockaddr ip adresses
  * passed as arguments.
@@ -188,7 +187,6 @@ static char *ipstr_list_make_sa(TALLOC_CTX *ctx,
 
        return ipstr_list;
 }
-#endif
 
 /**
  * Parse given ip string list into array of ip addresses
@@ -364,6 +362,78 @@ bool namecache_store(const char *name,
        return ret;
 }
 
+/**
+ * Store a name(s) in the name cache - samba_sockaddr version.
+ *
+ * @param name netbios names array
+ * @param name_type integer netbios name type
+ * @param num_names number of names being stored
+ * @param ip_list array of in_addr structures containing
+ *        ip addresses being stored
+ **/
+
+bool namecache_store_sa(const char *name,
+                       int name_type,
+                       size_t num_names,
+                       struct samba_sockaddr *sa_list)
+{
+       time_t expiry;
+       char *key = NULL;
+       char *value_string = NULL;
+       size_t i;
+       bool ret = false;
+       TALLOC_CTX *frame = talloc_stackframe();
+
+       if (name_type > 255) {
+               /* Don't store non-real name types. */
+               goto out;
+       }
+
+       if ( DEBUGLEVEL >= 5 ) {
+               char *addr = NULL;
+
+               DBG_INFO("storing %zu address%s for %s#%02x: ",
+                       num_names, num_names == 1 ? "": "es", name, name_type);
+
+               for (i = 0; i < num_names; i++) {
+                       addr = print_canonical_sockaddr(frame,
+                                       &sa_list[i].u.ss);
+                       if (!addr) {
+                               continue;
+                       }
+                       DEBUGADD(5, ("%s%s", addr,
+                               (i == (num_names - 1) ? "" : ",")));
+
+               }
+               DEBUGADD(5, ("\n"));
+       }
+
+       key = namecache_key(frame, name, name_type);
+       if (!key) {
+               goto out;
+       }
+
+       expiry = time(NULL) + lp_name_cache_timeout();
+
+       /*
+        * Generate string representation of ip addresses list
+        */
+       value_string = ipstr_list_make_sa(frame, sa_list, num_names);
+       if (value_string == NULL) {
+               goto out;
+       }
+
+       /* set the entry */
+       ret = gencache_set(key, value_string, expiry);
+
+  out:
+
+       TALLOC_FREE(key);
+       TALLOC_FREE(value_string);
+       TALLOC_FREE(frame);
+       return ret;
+}
+
 /**
  * Look up a name in the cache.
  *