2 Unix SMB/CIFS implementation.
3 async implementation of WINBINDD_WINS_BYIP
4 Copyright (C) Volker Lendecke 2011
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "libsmb/namequery.h"
23 #include "librpc/gen_ndr/ndr_winbind_c.h"
24 #include "libsmb/nmblib.h"
25 #include "lib/util/string_wrappers.h"
27 struct winbindd_wins_byip_state
{
29 struct sockaddr_storage addr
;
33 static void winbindd_wins_byip_done(struct tevent_req
*subreq
);
35 struct tevent_req
*winbindd_wins_byip_send(TALLOC_CTX
*mem_ctx
,
36 struct tevent_context
*ev
,
37 struct winbindd_cli_state
*cli
,
38 struct winbindd_request
*request
)
40 struct tevent_req
*req
, *subreq
;
41 struct winbindd_wins_byip_state
*state
;
43 req
= tevent_req_create(mem_ctx
, &state
,
44 struct winbindd_wins_byip_state
);
48 /* Ensure null termination */
49 request
->data
.winsreq
[sizeof(request
->data
.winsreq
)-1]='\0';
51 fstr_sprintf(state
->response
, "%s\t", request
->data
.winsreq
);
53 D_NOTICE("[%s (%u)] Winbind external command WINS_BYIP start.\n"
54 "Resolving wins byip for %s.\n",
56 (unsigned int)cli
->pid
,
57 request
->data
.winsreq
);
59 make_nmb_name(&state
->star
, "*", 0);
61 if (!interpret_string_addr(&state
->addr
, request
->data
.winsreq
,
63 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
64 return tevent_req_post(req
, ev
);
67 subreq
= node_status_query_send(state
, ev
, &state
->star
,
69 if (tevent_req_nomem(subreq
, req
)) {
70 return tevent_req_post(req
, ev
);
72 tevent_req_set_callback(subreq
, winbindd_wins_byip_done
, req
);
76 static void winbindd_wins_byip_done(struct tevent_req
*subreq
)
78 struct tevent_req
*req
= tevent_req_callback_data(
79 subreq
, struct tevent_req
);
80 struct winbindd_wins_byip_state
*state
= tevent_req_data(
81 req
, struct winbindd_wins_byip_state
);
82 struct node_status
*names
;
87 status
= node_status_query_recv(subreq
, talloc_tos(), &names
,
90 if (tevent_req_nterror(req
, status
)) {
94 for (i
=0; i
<num_names
; i
++) {
99 if (names
[i
].flags
& 0x80) {
105 if (names
[i
].type
!= 0x20) {
109 D_DEBUG("Got name '%s'.\n", names
[i
].name
);
111 /* len(name) + len(" ") + len(response) */
112 size
= strlen(names
[i
].name
) + 1 + strlen(state
->response
);
113 if (size
> sizeof(state
->response
) - 1) {
114 D_WARNING("Too much data!\n");
115 tevent_req_nterror(req
, STATUS_BUFFER_OVERFLOW
);
118 fstrcat(state
->response
, names
[i
].name
);
119 fstrcat(state
->response
, " ");
121 state
->response
[strlen(state
->response
)-1] = '\n';
125 tevent_req_done(req
);
128 NTSTATUS
winbindd_wins_byip_recv(struct tevent_req
*req
,
129 struct winbindd_response
*presp
)
131 struct winbindd_wins_byip_state
*state
= tevent_req_data(
132 req
, struct winbindd_wins_byip_state
);
135 if (tevent_req_is_nterror(req
, &status
)) {
138 D_NOTICE("Winbind external command WINS_BYIP end.\n"
141 fstrcpy(presp
->data
.winsresp
, state
->response
);