The branch, master has been updated
       via  4622812 s3: Make name_query return NTSTATUS
       via  28d997a s3: AllowDebugChange is gone
       via  5f79588 Fix a memleak in nss_wins
       via  181cd32 Fix a crash in libnss_wins
      from  5717114 s3: Make node_status_query return NTSTATUS

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 4622812a41eb5ce07dd8f74534217e858743883f
Author: Volker Lendecke <[email protected]>
Date:   Tue Dec 28 13:47:35 2010 +0100

    s3: Make name_query return NTSTATUS
    
    Also use talloc for the result
    
    Autobuild-User: Volker Lendecke <[email protected]>
    Autobuild-Date: Tue Dec 28 18:21:05 CET 2010 on sn-devel-104

commit 28d997a89056f144de6a7b95af0e54a044c5e5b3
Author: Volker Lendecke <[email protected]>
Date:   Tue Dec 28 17:17:04 2010 +0100

    s3: AllowDebugChange is gone

commit 5f79588de07754ef112abac33535a34624b3b078
Author: Volker Lendecke <[email protected]>
Date:   Tue Dec 28 17:08:57 2010 +0100

    Fix a memleak in nss_wins

commit 181cd3281c4f2c53dc507f59d281a2517579cfe1
Author: Volker Lendecke <[email protected]>
Date:   Tue Dec 28 17:05:18 2010 +0100

    Fix a crash in libnss_wins
    
    lp_set_parm accesses the case tables

-----------------------------------------------------------------------

Summary of changes:
 nsswitch/wins.c                  |   10 +++++---
 source3/client/client.c          |    1 -
 source3/include/proto.h          |    4 ++-
 source3/libsmb/namequery.c       |   46 +++++++++++++++++++++----------------
 source3/utils/nmblookup.c        |   23 ++++++++++--------
 source3/web/diagnose.c           |   10 +++++---
 source3/winbindd/winbindd_wins.c |   25 +++++++++++++-------
 7 files changed, 70 insertions(+), 49 deletions(-)


Changeset truncated at 500 lines:

diff --git a/nsswitch/wins.c b/nsswitch/wins.c
index 731efcb..ac062fe 100644
--- a/nsswitch/wins.c
+++ b/nsswitch/wins.c
@@ -40,8 +40,6 @@ static pthread_mutex_t wins_nss_mutex = 
PTHREAD_MUTEX_INITIALIZER;
 
 static int initialised;
 
-extern bool AllowDebugChange;
-
 NSS_STATUS _nss_wins_gethostbyname_r(const char *hostname, struct hostent *he,
                          char *buffer, size_t buflen, int *h_errnop);
 NSS_STATUS _nss_wins_gethostbyname2_r(const char *name, int af, struct hostent 
*he,
@@ -94,11 +92,11 @@ static int wins_lookup_open_socket_in(void)
 static void nss_wins_init(void)
 {
        initialised = 1;
+       load_case_tables();
        lp_set_cmdline("log level", "0");
 
        TimeInit();
        setup_logging("nss_wins",False);
-       load_case_tables();
        lp_load(get_dyn_CONFIGFILE(),True,False,False,True);
        load_interfaces();
 }
@@ -142,16 +140,20 @@ static struct in_addr *lookup_byname_backend(const char 
*name, int *count)
                const struct in_addr *bcast = iface_n_bcast_v4(j);
                struct sockaddr_storage ss;
                struct sockaddr_storage *pss;
+               NTSTATUS status;
+
                if (!bcast) {
                        continue;
                }
                in_addr_to_sockaddr_storage(&ss, *bcast);
-               pss = name_query(fd,name,0x00,True,True,&ss,count, &flags, 
NULL);
+               status = name_query(fd, name, 0x00, True, True, &ss,
+                                   NULL, &pss, count, &flags, NULL);
                if (pss) {
                        if ((ret = SMB_MALLOC_P(struct in_addr)) == NULL) {
                                return NULL;
                        }
                        *ret = ((struct sockaddr_in *)pss)->sin_addr;
+                       TALLOC_FREE(pss);
                        break;
                }
        }
diff --git a/source3/client/client.c b/source3/client/client.c
index b3bbcf5..8486bb2 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -36,7 +36,6 @@
 
 extern int do_smb_browse(void); /* mDNS browsing */
 
-extern bool AllowDebugChange;
 extern bool override_logfile;
 extern char tar_type;
 
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 8278ffb..9b391ae 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -2712,12 +2712,14 @@ bool name_status_find(const char *q_name,
                        const struct sockaddr_storage *to_ss,
                        fstring name);
 int ip_service_compare(struct ip_service *ss1, struct ip_service *ss2);
-struct sockaddr_storage *name_query(int fd,
+NTSTATUS name_query(int fd,
                        const char *name,
                        int name_type,
                        bool bcast,
                        bool recurse,
                        const struct sockaddr_storage *to_ss,
+                       TALLOC_CTX *mem_ctx,
+                       struct sockaddr_storage **addrs,
                        int *count,
                        int *flags,
                        bool *timed_out);
diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index a283038..7016f6b 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -679,12 +679,14 @@ static bool prioritize_ipv4_list(struct ip_service 
*iplist, int count)
  *timed_out is set if we failed by timing out
 ****************************************************************************/
 
-struct sockaddr_storage *name_query(int fd,
+NTSTATUS name_query(int fd,
                        const char *name,
                        int name_type,
                        bool bcast,
                        bool recurse,
                        const struct sockaddr_storage *to_ss,
+                       TALLOC_CTX *mem_ctx,
+                       struct sockaddr_storage **addrs,
                        int *count,
                        int *flags,
                        bool *timed_out)
@@ -701,11 +703,11 @@ struct sockaddr_storage *name_query(int fd,
        if (lp_disable_netbios()) {
                DEBUG(5,("name_query(%s#%02x): netbios is disabled\n",
                                        name, name_type));
-               return NULL;
+               return NT_STATUS_NOT_FOUND;
        }
 
        if (to_ss->ss_family != AF_INET) {
-               return NULL;
+               return NT_STATUS_INVALID_ADDRESS;
        }
 
        if (timed_out) {
@@ -745,7 +747,7 @@ struct sockaddr_storage *name_query(int fd,
        clock_gettime_mono(&tp);
 
        if (!send_packet_request(&p))
-               return NULL;
+               return NT_STATUS_NOT_FOUND;
 
        retries--;
 
@@ -757,7 +759,7 @@ struct sockaddr_storage *name_query(int fd,
                        if (!retries)
                                break;
                        if (!found && !send_packet_request(&p))
-                               return NULL;
+                               return NT_STATUS_NOT_FOUND;
                        clock_gettime_mono(&tp);
                        retries--;
                }
@@ -806,7 +808,7 @@ struct sockaddr_storage *name_query(int fd,
                                        }
                                }
                                free_packet(p2);
-                               return( NULL );
+                               return NT_STATUS_NOT_FOUND;
                        }
 
                        if (nmb2->header.opcode != 0 ||
@@ -822,7 +824,7 @@ struct sockaddr_storage *name_query(int fd,
                                continue;
                        }
 
-                       ss_list = SMB_REALLOC_ARRAY(ss_list,
+                       ss_list = TALLOC_REALLOC_ARRAY(mem_ctx, ss_list,
                                                struct sockaddr_storage,
                                                (*count) +
                                                nmb2->answers->rdlength/6);
@@ -830,7 +832,7 @@ struct sockaddr_storage *name_query(int fd,
                        if (!ss_list) {
                                DEBUG(0,("name_query: Realloc failed.\n"));
                                free_packet(p2);
-                               return NULL;
+                               return NT_STATUS_NO_MEMORY;
                        }
 
                        DEBUG(2,("Got a positive name query response "
@@ -882,7 +884,8 @@ struct sockaddr_storage *name_query(int fd,
        /* sort the ip list so we choose close servers first if possible */
        sort_addr_list(ss_list, *count);
 
-       return ss_list;
+       *addrs = ss_list;
+       return NT_STATUS_OK;
 }
 
 /********************************************************
@@ -953,7 +956,7 @@ NTSTATUS name_resolve_bcast(const char *name,
 
        sock = open_socket_in( SOCK_DGRAM, 0, 3, &ss, true );
        if (sock == -1) {
-               return NT_STATUS_UNSUCCESSFUL;
+               return map_nt_error_from_unix(errno);
        }
 
        set_socket_options(sock,"SO_BROADCAST");
@@ -969,9 +972,10 @@ NTSTATUS name_resolve_bcast(const char *name,
                if (!pss) {
                        continue;
                }
-               ss_list = name_query(sock, name, name_type, true,
-                                   true, pss, return_count, &flags, NULL);
-               if (ss_list) {
+               status = name_query(sock, name, name_type, true, true, pss,
+                                   talloc_tos(), &ss_list, return_count,
+                                   &flags, NULL);
+               if (NT_STATUS_IS_OK(status)) {
                        goto success;
                }
        }
@@ -979,15 +983,14 @@ NTSTATUS name_resolve_bcast(const char *name,
        /* failed - no response */
 
        close(sock);
-       return NT_STATUS_UNSUCCESSFUL;
+       return status;
 
 success:
 
-       status = NT_STATUS_OK;
        if (!convert_ss2service(return_iplist, ss_list, *return_count) )
-               status = NT_STATUS_INVALID_PARAMETER;
+               status = NT_STATUS_NO_MEMORY;
 
-       SAFE_FREE(ss_list);
+       TALLOC_FREE(ss_list);
        close(sock);
        return status;
 }
@@ -1083,20 +1086,23 @@ NTSTATUS resolve_wins(const char *name,
                        }
 
                        in_addr_to_sockaddr_storage(&wins_ss, wins_ip);
-                       ss_list = name_query(sock,
+                       status = name_query(sock,
                                                name,
                                                name_type,
                                                false,
                                                true,
                                                &wins_ss,
+                                               talloc_tos(),
+                                               &ss_list,
                                                return_count,
                                                &flags,
                                                &timed_out);
 
                        /* exit loop if we got a list of addresses */
 
-                       if (ss_list)
+                       if (NT_STATUS_IS_OK(status)) {
                                goto success;
+                       }
 
                        close(sock);
 
@@ -1123,7 +1129,7 @@ success:
        if (!convert_ss2service(return_iplist, ss_list, *return_count))
                status = NT_STATUS_INVALID_PARAMETER;
 
-       SAFE_FREE(ss_list);
+       TALLOC_FREE(ss_list);
        wins_srv_tags_free(wins_tags);
        close(sock);
 
diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c
index 5bbd06c..4a55647 100644
--- a/source3/utils/nmblookup.c
+++ b/source3/utils/nmblookup.c
@@ -156,14 +156,16 @@ static bool query_one(const char *lookup, unsigned int 
lookup_type)
 {
        int j, count, flags = 0;
        struct sockaddr_storage *ip_list=NULL;
+       NTSTATUS status;
 
        if (got_bcast) {
                char addr[INET6_ADDRSTRLEN];
                print_sockaddr(addr, sizeof(addr), &bcast_addr);
                d_printf("querying %s on %s\n", lookup, addr);
-               ip_list = name_query(ServerFD,lookup,lookup_type,use_bcast,
-                                    use_bcast?true:recursion_desired,
-                                    &bcast_addr, &count, &flags, NULL);
+               status = name_query(ServerFD,lookup,lookup_type,use_bcast,
+                                   use_bcast?true:recursion_desired,
+                                   &bcast_addr, talloc_tos(),
+                                   &ip_list, &count, &flags, NULL);
        } else {
                const struct in_addr *bcast;
                for (j=iface_count() - 1;
@@ -180,14 +182,15 @@ static bool query_one(const char *lookup, unsigned int 
lookup_type)
                        print_sockaddr(addr, sizeof(addr), &bcast_ss);
                        d_printf("querying %s on %s\n",
                               lookup, addr);
-                       ip_list = name_query(ServerFD,lookup,lookup_type,
-                                            use_bcast,
-                                            use_bcast?True:recursion_desired,
-                                            &bcast_ss,&count, &flags, NULL);
+                       status = name_query(ServerFD,lookup,lookup_type,
+                                           use_bcast,
+                                           use_bcast?True:recursion_desired,
+                                           &bcast_ss, talloc_tos(),
+                                           &ip_list, &count, &flags, NULL);
                }
        }
 
-       if (!ip_list) {
+       if (!NT_STATUS_IS_OK(status)) {
                return false;
        }
 
@@ -220,9 +223,9 @@ static bool query_one(const char *lookup, unsigned int 
lookup_type)
                }
        }
 
-       free(ip_list);
+       TALLOC_FREE(ip_list);
 
-       return (ip_list != NULL);
+       return NT_STATUS_IS_OK(status);
 }
 
 
diff --git a/source3/web/diagnose.c b/source3/web/diagnose.c
index 221ce83..df61658 100644
--- a/source3/web/diagnose.c
+++ b/source3/web/diagnose.c
@@ -44,10 +44,12 @@ bool nmbd_running(void)
 
        if ((fd = open_socket_in(SOCK_DGRAM, 0, 3,
                                 &ss, True)) != -1) {
-               if ((ss_list = name_query(fd, "__SAMBA__", 0, 
-                                         True, True, &ss,
-                                         &count, &flags, NULL)) != NULL) {
-                       SAFE_FREE(ss_list);
+               NTSTATUS status = name_query(fd, "__SAMBA__", 0,
+                                            True, True, &ss,
+                                            talloc_tos(), &ss_list, &count,
+                                            &flags, NULL);
+               if (NT_STATUS_IS_OK(status)) {
+                       TALLOC_FREE(ss_list);
                        close(fd);
                        return True;
                }
diff --git a/source3/winbindd/winbindd_wins.c b/source3/winbindd/winbindd_wins.c
index 484b393..720feaf 100644
--- a/source3/winbindd/winbindd_wins.c
+++ b/source3/winbindd/winbindd_wins.c
@@ -96,13 +96,15 @@ static struct node_status *lookup_byaddr_backend(TALLOC_CTX 
*mem_ctx,
        return result;
 }
 
-static struct sockaddr_storage *lookup_byname_backend(const char *name,
-                                       int *count)
+static struct sockaddr_storage *lookup_byname_backend(TALLOC_CTX *mem_ctx,
+                                                     const char *name,
+                                                     int *count)
 {
        int fd;
        struct ip_service *ret = NULL;
        struct sockaddr_storage *return_ss = NULL;
        int j, i, flags = 0;
+       NTSTATUS status;
 
        *count = 0;
 
@@ -110,7 +112,9 @@ static struct sockaddr_storage *lookup_byname_backend(const 
char *name,
        if (NT_STATUS_IS_OK(resolve_wins(name,0x20,&ret,count))) {
                if ( *count == 0 )
                        return NULL;
-               if ( (return_ss = SMB_MALLOC_ARRAY(struct sockaddr_storage, 
*count)) == NULL ) {
+               return_ss = TALLOC_ARRAY(mem_ctx, struct sockaddr_storage,
+                                        *count);
+               if (return_ss == NULL ) {
                        free( ret );
                        return NULL;
                }
@@ -136,8 +140,9 @@ static struct sockaddr_storage *lookup_byname_backend(const 
char *name,
                if (!bcast_ss) {
                        continue;
                }
-               return_ss = name_query(fd,name,0x20,True,True,bcast_ss,count, 
&flags, NULL);
-               if (return_ss) {
+               status = name_query(fd, name, 0x20, True, True,bcast_ss,
+                                   mem_ctx, &return_ss, count, &flags, NULL);
+               if (NT_STATUS_IS_OK(status)) {
                        break;
                }
        }
@@ -213,12 +218,14 @@ void winbindd_wins_byname(struct winbindd_cli_state 
*state)
        *response = '\0';
        maxlen = sizeof(response) - 1;
 
-       if ((ip_list = 
lookup_byname_backend(state->request->data.winsreq,&count))){
+       ip_list = lookup_byname_backend(
+               state->mem_ctx, state->request->data.winsreq, &count);
+       if (ip_list != NULL){
                for (i = count; i ; i--) {
                        print_sockaddr(addr, sizeof(addr), &ip_list[i-1]);
                        size = strlen(addr);
                        if (size > maxlen) {
-                               SAFE_FREE(ip_list);
+                               TALLOC_FREE(ip_list);
                                request_error(state);
                                return;
                        }
@@ -235,13 +242,13 @@ void winbindd_wins_byname(struct winbindd_cli_state 
*state)
                }
                size = strlen(state->request->data.winsreq) + strlen(response);
                if (size > maxlen) {
-                   SAFE_FREE(ip_list);
+                   TALLOC_FREE(ip_list);
                    request_error(state);
                    return;
                }
                fstrcat(response,state->request->data.winsreq);
                fstrcat(response,"\n");
-               SAFE_FREE(ip_list);
+               TALLOC_FREE(ip_list);
        } else {
                request_error(state);
                return;


-- 
Samba Shared Repository

Reply via email to