]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: libsmb: Add internal ipstr_list_make_sa().
authorJeremy Allison <jra@samba.org>
Thu, 27 Aug 2020 18:40:10 +0000 (11:40 -0700)
committerNoel Power <npower@samba.org>
Mon, 7 Sep 2020 13:23:44 +0000 (13:23 +0000)
Duplicates ipstr_list_make() with samba_sockaddr, but doesn't store
ports. The duplication is temporary as the ipstr_list_make() function
will go away once namecache_store is converted to samba_sockaddr.

Compiles but commented out as not yet used.

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

index 76fab4dfce595e82b4715efb3249625428cb6c69..0b853ed7e4a5f9617338b3119d7702a786d1cf34 100644 (file)
@@ -108,6 +108,88 @@ 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.
+ *
+ * @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_sa(TALLOC_CTX *ctx,
+                       const struct samba_sockaddr *sa_list,
+                       size_t ip_count)
+{
+       char *ipstr_list = NULL;
+       size_t i;
+
+       /* arguments checking */
+       if (sa_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),
+                               &sa_list[i].u.ss);
+
+               if (sa_list[i].u.ss.ss_family == AF_INET) {
+                       /* IPv4 - port no longer used, store 0 */
+                       new_str = talloc_asprintf(ctx,
+                                               "%s:%d",
+                                               addr_buf,
+                                               0);
+               } else {
+                       /* IPv6 - port no longer used, store 0 */
+                       new_str = talloc_asprintf(ctx,
+                                               "[%s]:%d",
+                                               addr_buf,
+                                               0);
+               }
+               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;
+}
+#endif
+
 /**
  * Parse given ip string list into array of ip addresses
  * (as ip_service structures)