static struct in_addr *lookup_byname_backend(const char *name, int *count)
{
- struct ip_service *address = NULL;
+ TALLOC_CTX *frame = talloc_stackframe();
+ struct sockaddr_storage *address = NULL;
struct in_addr *ret = NULL;
+ NTSTATUS status;
int j;
if (!initialised) {
*count = 0;
/* always try with wins first */
- if (NT_STATUS_IS_OK(resolve_wins(name,0x00,&address,count))) {
+ status = resolve_wins(name, 0x00, talloc_tos(),
+ &address, count);
+ if (NT_STATUS_IS_OK(status)) {
if ( (ret = SMB_MALLOC_P(struct in_addr)) == NULL ) {
- free( address );
+ TALLOC_FREE(frame);
return NULL;
}
- if (address[0].ss.ss_family != AF_INET) {
- free(address);
+ if (address[0].ss_family != AF_INET) {
free(ret);
+ TALLOC_FREE(frame);
return NULL;
}
- *ret = ((struct sockaddr_in *)(void *)&address[0].ss)
+ *ret = ((struct sockaddr_in *)(void *)address)
->sin_addr;
- free( address );
+ TALLOC_FREE(frame);
return ret;
}
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);
status = name_query(name, 0x00, True, True, &ss,
- NULL, &pss, count, NULL);
- if (pss) {
+ talloc_tos(), &pss, count, NULL);
+ if (NT_STATUS_IS_OK(status) && (*count > 0)) {
if ((ret = SMB_MALLOC_P(struct in_addr)) == NULL) {
+ TALLOC_FREE(frame);
return NULL;
}
*ret = ((struct sockaddr_in *)pss)->sin_addr;
- TALLOC_FREE(pss);
break;
}
}
-
+ TALLOC_FREE(frame);
return ret;
}
#ifdef HAVE_NS_API_H
-/* Use our own create socket code so we don't recurse.... */
-
-static int wins_lookup_open_socket_in(void)
-{
- struct sockaddr_in sock;
- int val=1;
- int res;
-
- memset((char *)&sock,'\0',sizeof(sock));
-
-#ifdef HAVE_SOCK_SIN_LEN
- sock.sin_len = sizeof(sock);
-#endif
- sock.sin_port = 0;
- sock.sin_family = AF_INET;
- sock.sin_addr.s_addr = interpret_addr("0.0.0.0");
- res = socket(AF_INET, SOCK_DGRAM, 0);
- if (res == -1)
- return -1;
-
- if (setsockopt(res,SOL_SOCKET,SO_REUSEADDR,(char *)&val,sizeof(val)) != 0) {
- close(res);
- return -1;
- }
-#ifdef SO_REUSEPORT
- if (setsockopt(res,SOL_SOCKET,SO_REUSEPORT,(char *)&val,sizeof(val)) != 0) {
- close(res);
- return -1;
- }
-#endif /* SO_REUSEPORT */
-
- /* now we've got a socket - we need to bind it */
-
- if (bind(res, (struct sockaddr * ) &sock,sizeof(sock)) < 0) {
- close(res);
- return(-1);
- }
-
- set_socket_options(res,"SO_BROADCAST");
-
- return res;
-}
-
static struct node_status *lookup_byaddr_backend(char *addr, int *count)
{
- int fd;
struct sockaddr_storage ss;
struct nmb_name nname;
- struct node_status *status;
+ struct node_status *result;
+ NTSTATUS status;
if (!initialised) {
nss_wins_init();
}
- fd = wins_lookup_open_socket_in();
- if (fd == -1)
- return NULL;
-
make_nmb_name(&nname, "*", 0);
if (!interpret_string_addr(&ss, addr, AI_NUMERICHOST)) {
return NULL;
}
- status = node_status_query(fd, &nname, &ss, count, NULL);
+ status = node_status_query(NULL, &nname, &ss, &result, count, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ return NULL;
+ }
- close(fd);
- return status;
+ return result;
}
/* IRIX version */
* response needs to be a string of the following format
* ip_address[ ip_address]*\tname[ alias]*
*/
- if (StrCaseCmp(map,"hosts.byaddr") == 0) {
+ if (strcasecmp_m(map,"hosts.byaddr") == 0) {
if ( status = lookup_byaddr_backend(key, &count)) {
size = strlen(key) + 1;
if (size > len) {
- free(status);
+ talloc_free(status);
return NSD_ERROR;
}
len -= size;
if (status[i].type == 0x20) {
size = sizeof(status[i].name) + 1;
if (size > len) {
- free(status);
+ talloc_free(status);
return NSD_ERROR;
}
len -= size;
}
}
response[strlen(response)-1] = '\n';
- free(status);
+ talloc_free(status);
}
- } else if (StrCaseCmp(map,"hosts.byname") == 0) {
+ } else if (strcasecmp_m(map,"hosts.byname") == 0) {
if (ip_list = lookup_byname_backend(key, &count)) {
for (i = count; i ; i--) {
addr = inet_ntoa(ip_list[i-1]);