From: Jeremy Allison Date: Thu, 27 Aug 2020 19:14:13 +0000 (-0700) Subject: s3: libsmb: Remove use of struct ip_service from the namecache code. X-Git-Tag: talloc-2.3.2~575 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2989d736c4a95c73ccb6d828362425b30d580337;p=thirdparty%2Fsamba.git s3: libsmb: Remove use of struct ip_service from the namecache code. Signed-off-by: Jeremy Allison Reviewed-by: Noel Power --- diff --git a/source3/include/proto.h b/source3/include/proto.h index cc151eb7f5e..194b7ffa8f9 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -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, diff --git a/source3/libsmb/namecache.c b/source3/libsmb/namecache.c index 69299aee380..0cba52233ba 100644 --- a/source3/libsmb/namecache.c +++ b/source3/libsmb/namecache.c @@ -28,86 +28,6 @@ #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. *