summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2010-12-28 13:47:35 +0100
committerVolker Lendecke <vlendec@samba.org>2010-12-28 18:21:05 +0100
commit4622812a41eb5ce07dd8f74534217e858743883f (patch)
tree3a07c7d4971c9e11fe3a623311098baaa7a925e4 /source3
parent28d997a89056f144de6a7b95af0e54a044c5e5b3 (diff)
downloadsamba-4622812a41eb5ce07dd8f74534217e858743883f.tar.gz
samba-4622812a41eb5ce07dd8f74534217e858743883f.tar.bz2
samba-4622812a41eb5ce07dd8f74534217e858743883f.zip
s3: Make name_query return NTSTATUS
Also use talloc for the result Autobuild-User: Volker Lendecke <vlendec@samba.org> Autobuild-Date: Tue Dec 28 18:21:05 CET 2010 on sn-devel-104
Diffstat (limited to 'source3')
-rw-r--r--source3/include/proto.h4
-rw-r--r--source3/libsmb/namequery.c46
-rw-r--r--source3/utils/nmblookup.c23
-rw-r--r--source3/web/diagnose.c10
-rw-r--r--source3/winbindd/winbindd_wins.c25
5 files changed, 64 insertions, 44 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 8278ffbcd5..9b391ae767 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 a283038c32..7016f6b091 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 5bbd06c994..4a55647361 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 221ce83f82..df61658f8d 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 484b39342a..720feaf83a 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;