1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
Unix SMB/CIFS implementation.
wins server dns proxy
Copyright (C) Stefan Metzmacher 2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "nbt_server/nbt_server.h"
#include "nbt_server/wins/winsdb.h"
#include "nbt_server/wins/winsserver.h"
#include "system/time.h"
#include "libcli/composite/composite.h"
#include "smbd/service_task.h"
#include "libcli/resolve/resolve.h"
struct wins_dns_proxy_state {
struct nbt_name_socket *nbtsock;
struct nbt_name_packet *packet;
struct socket_address *src;
};
static void nbtd_wins_dns_proxy_handler(struct composite_context *creq)
{
NTSTATUS status;
struct wins_dns_proxy_state *s = talloc_get_type(creq->async.private_data,
struct wins_dns_proxy_state);
struct nbt_name *name = &s->packet->questions[0].name;
const char *address;
const char **addresses;
uint16_t nb_flags = 0; /* TODO: ... */
status = resolve_name_recv(creq, s->packet, &address);
if (!NT_STATUS_IS_OK(status)) {
goto notfound;
}
addresses = str_list_add(NULL, address);
talloc_steal(s->packet, addresses);
if (!addresses) goto notfound;
nbtd_name_query_reply(s->nbtsock, s->packet, s->src, name,
0, nb_flags, addresses);
return;
notfound:
nbtd_negative_name_query_reply(s->nbtsock, s->packet, s->src);
}
/*
dns proxy query a name
*/
void nbtd_wins_dns_proxy_query(struct nbt_name_socket *nbtsock,
struct nbt_name_packet *packet,
struct socket_address *src)
{
struct nbt_name *name = &packet->questions[0].name;
struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private,
struct nbtd_interface);
struct wins_dns_proxy_state *s;
struct composite_context *creq;
const char *methods[] = {
"host",
NULL
};
s = talloc(nbtsock, struct wins_dns_proxy_state);
if (!s) goto failed;
s->nbtsock = nbtsock;
s->packet = talloc_steal(s, packet);
s->src = src;
if (!talloc_reference(s, src)) {
goto failed;
}
creq = resolve_name_send(name, iface->nbtsrv->task->event_ctx, methods);
if (!creq) goto failed;
creq->async.fn = nbtd_wins_dns_proxy_handler;
creq->async.private_data= s;
return;
failed:
nbtd_negative_name_query_reply(nbtsock, packet, src);
}
|