2 Unix SMB/CIFS implementation.
4 Winbind daemon - WINS related functions
6 Copyright (C) Andrew Tridgell 1999
7 Copyright (C) Herb Lewis 2002
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "libsmb/nmblib.h"
28 #define DBGC_CLASS DBGC_WINBIND
30 static struct sockaddr_storage *lookup_byname_backend(TALLOC_CTX *mem_ctx,
34 struct ip_service *ret = NULL;
35 struct sockaddr_storage *return_ss = NULL;
41 /* always try with wins first */
42 if (NT_STATUS_IS_OK(resolve_wins(name,0x20,&ret,count))) {
45 return_ss = talloc_array(mem_ctx, struct sockaddr_storage,
47 if (return_ss == NULL ) {
52 /* copy the IP addresses */
53 for ( i=0; i<(*count); i++ )
54 return_ss[i] = ret[i].ss;
60 /* uggh, we have to broadcast to each interface in turn */
61 for (j=iface_count() - 1;
64 const struct sockaddr_storage *bcast_ss = iface_n_bcast(j);
68 status = name_query(name, 0x20, True, True,bcast_ss,
69 mem_ctx, &return_ss, count, NULL);
70 if (NT_STATUS_IS_OK(status)) {
78 /* Get IP from hostname */
80 void winbindd_wins_byname(struct winbindd_cli_state *state)
82 struct sockaddr_storage *ip_list = NULL;
83 int i, count, maxlen, size;
85 char addr[INET6_ADDRSTRLEN];
87 /* Ensure null termination */
88 state->request->data.winsreq[sizeof(state->request->data.winsreq)-1]='\0';
90 DEBUG(3, ("[%5lu]: wins_byname %s\n", (unsigned long)state->pid,
91 state->request->data.winsreq));
94 maxlen = sizeof(response) - 1;
96 ip_list = lookup_byname_backend(
97 state->mem_ctx, state->request->data.winsreq, &count);
99 for (i = count; i ; i--) {
100 print_sockaddr(addr, sizeof(addr), &ip_list[i-1]);
103 TALLOC_FREE(ip_list);
104 request_error(state);
108 /* Clear out the newline character */
109 /* But only if there is something in there,
110 otherwise we clobber something in the stack */
111 if (strlen(response)) {
112 response[strlen(response)-1] = ' ';
115 strlcat(response,addr,sizeof(response));
116 strlcat(response,"\t",sizeof(response));
118 size = strlen(state->request->data.winsreq) + strlen(response);
120 TALLOC_FREE(ip_list);
121 request_error(state);
124 strlcat(response,state->request->data.winsreq,sizeof(response));
125 strlcat(response,"\n",sizeof(response));
126 TALLOC_FREE(ip_list);
128 request_error(state);
132 strlcpy(state->response->data.winsresp,
134 sizeof(state->response->data.winsresp));