]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: libsmb: Remove use of struct ip_service from the namecache code.
authorJeremy Allison <jra@samba.org>
Thu, 27 Aug 2020 19:14:13 +0000 (12:14 -0700)
committerNoel Power <npower@samba.org>
Mon, 7 Sep 2020 13:23:44 +0000 (13:23 +0000)
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
source3/include/proto.h
source3/libsmb/namecache.c

index cc151eb7f5ead1ce70cb7711f1d6193fc9620dd4..194b7ffa8f9f4c0b662be210ce119489f767a5cd 100644 (file)
@@ -676,10 +676,6 @@ NTSTATUS dos_to_ntstatus(uint8_t eclass, uint32_t ecode);
 
 /* The following definitions come from libsmb/namecache.c  */
 
-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,
index 69299aee38015e51e2751368016db8687f447ab1..0cba52233baa5262dd26ff2bd4f4e333bfa02e53 100644 (file)
 #define IPSTR_LIST_SEP ","
 #define IPSTR_LIST_CHAR        ','
 
-/**
- * Allocate and initialise an ipstr list using ip adresses
- * passed as arguments.
- *
- * @param ctx TALLOC_CTX to use
- * @param ip_list array of ip addresses to place in the list
- * @param ip_count number of addresses stored in ip_list
- * @return pointer to allocated ip string
- **/
-
-static char *ipstr_list_make(TALLOC_CTX *ctx,
-                       const struct ip_service *ip_list,
-                       size_t ip_count)
-{
-       char *ipstr_list = NULL;
-       size_t i;
-
-       /* arguments checking */
-       if (ip_list == NULL) {
-               return NULL;
-       }
-
-       /* process ip addresses given as arguments */
-       for (i = 0; i < ip_count; i++) {
-               char addr_buf[INET6_ADDRSTRLEN];
-               char *new_str = NULL;
-
-               print_sockaddr(addr_buf,
-                              sizeof(addr_buf),
-                              &ip_list[i].ss);
-
-               if (ip_list[i].ss.ss_family == AF_INET) {
-                       /* IPv4 */
-                       new_str = talloc_asprintf(ctx,
-                                                 "%s:%d",
-                                                 addr_buf,
-                                                 ip_list[i].port);
-               } else {
-                       /* IPv6 */
-                       new_str = talloc_asprintf(ctx,
-                                                 "[%s]:%d",
-                                                 addr_buf,
-                                                 ip_list[i].port);
-               }
-               if (new_str == NULL) {
-                       TALLOC_FREE(ipstr_list);
-                       return NULL;
-               }
-
-               if (ipstr_list == NULL) {
-                       /* First ip address. */
-                       ipstr_list = new_str;
-               } else {
-                       /*
-                        * Append the separator "," and then the new
-                        * ip address to the existing list.
-                        *
-                        * The efficiency here is horrible, but
-                        * ip_count should be small enough we can
-                        * live with it.
-                        */
-                       char *tmp = talloc_asprintf(ctx,
-                                                   "%s%s%s",
-                                                   ipstr_list,
-                                                   IPSTR_LIST_SEP,
-                                                   new_str);
-                       if (tmp == NULL) {
-                               TALLOC_FREE(new_str);
-                               TALLOC_FREE(ipstr_list);
-                               return NULL;
-                       }
-                       TALLOC_FREE(new_str);
-                       TALLOC_FREE(ipstr_list);
-                       ipstr_list = tmp;
-               }
-       }
-
-       return ipstr_list;
-}
-
 /**
  * Allocate and initialise an ipstr list using samba_sockaddr ip adresses
  * passed as arguments.
@@ -290,78 +210,6 @@ static char *namecache_key(TALLOC_CTX *ctx,
                                          name_type);
 }
 
-/**
- * Store a name(s) in the name cache
- *
- * @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(const char *name,
-                       int name_type,
-                       size_t num_names,
-                       struct ip_service *ip_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,
-                                                       &ip_list[i].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(frame, ip_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;
-}
-
 /**
  * Store a name(s) in the name cache - samba_sockaddr version.
  *