2 Unix SMB/CIFS implementation.
4 answer node status queries
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "lib/util/dlinklist.h"
25 #include "system/network.h"
26 #include "nbt_server/nbt_server.h"
27 #include "lib/socket/socket.h"
28 #include "librpc/gen_ndr/ndr_nbt.h"
31 send a name status reply
33 static void nbtd_node_status_reply(struct nbt_name_socket
*nbtsock
,
34 struct nbt_name_packet
*request_packet
,
35 struct socket_address
*src
,
36 struct nbt_name
*name
,
37 struct nbtd_interface
*iface
)
39 struct nbt_name_packet
*packet
;
41 struct nbtd_iface_name
*iname
;
42 struct nbtd_server
*nbtsrv
= iface
->nbtsrv
;
44 /* work out how many names to send */
46 for (iname
=iface
->names
;iname
;iname
=iname
->next
) {
47 if ((iname
->nb_flags
& NBT_NM_ACTIVE
) &&
48 strcmp(iname
->name
.name
, "*") != 0) {
53 packet
= talloc_zero(nbtsock
, struct nbt_name_packet
);
54 if (packet
== NULL
) return;
56 packet
->name_trn_id
= request_packet
->name_trn_id
;
58 packet
->operation
= NBT_OPCODE_QUERY
| NBT_FLAG_REPLY
| NBT_FLAG_AUTHORITIVE
;
60 packet
->answers
= talloc_array(packet
, struct nbt_res_rec
, 1);
61 if (packet
->answers
== NULL
) goto failed
;
63 packet
->answers
[0].name
= *name
;
64 packet
->answers
[0].rr_type
= NBT_QTYPE_STATUS
;
65 packet
->answers
[0].rr_class
= NBT_QCLASS_IP
;
66 packet
->answers
[0].ttl
= 0;
67 packet
->answers
[0].rdata
.status
.num_names
= name_count
;
68 packet
->answers
[0].rdata
.status
.names
= talloc_array(packet
->answers
,
69 struct nbt_status_name
, name_count
);
70 if (packet
->answers
[0].rdata
.status
.names
== NULL
) goto failed
;
73 for (iname
=iface
->names
;iname
;iname
=iname
->next
) {
74 if ((iname
->nb_flags
& NBT_NM_ACTIVE
) &&
75 strcmp(iname
->name
.name
, "*") != 0) {
76 struct nbt_status_name
*n
= &packet
->answers
[0].rdata
.status
.names
[name_count
];
77 n
->name
= talloc_asprintf(packet
->answers
, "%-15s", iname
->name
.name
);
78 if (n
->name
== NULL
) goto failed
;
79 n
->type
= iname
->name
.type
;
80 n
->nb_flags
= iname
->nb_flags
;
84 /* we deliberately don't fill in the statistics structure as
85 it could lead to giving attackers too much information */
86 ZERO_STRUCT(packet
->answers
[0].rdata
.status
.statistics
);
88 DEBUG(7,("Sending node status reply for %s to %s:%d\n",
89 nbt_name_string(packet
, name
), src
->addr
, src
->port
));
91 nbtsrv
->stats
.total_sent
++;
92 nbt_name_reply_send(nbtsock
, src
, packet
);
100 answer a node status query
102 void nbtd_query_status(struct nbt_name_socket
*nbtsock
,
103 struct nbt_name_packet
*packet
,
104 struct socket_address
*src
)
106 struct nbt_name
*name
;
107 struct nbtd_iface_name
*iname
;
108 struct nbtd_interface
*iface
= talloc_get_type(nbtsock
->incoming
.private,
109 struct nbtd_interface
);
111 NBTD_ASSERT_PACKET(packet
, src
, packet
->qdcount
== 1);
112 NBTD_ASSERT_PACKET(packet
, src
, packet
->questions
[0].question_type
== NBT_QTYPE_STATUS
);
113 NBTD_ASSERT_PACKET(packet
, src
, packet
->questions
[0].question_class
== NBT_QCLASS_IP
);
115 /* see if we have the requested name on this interface */
116 name
= &packet
->questions
[0].name
;
118 iname
= nbtd_find_iname(iface
, name
, NBT_NM_ACTIVE
);
120 DEBUG(7,("Node status query for %s from %s - not found on %s\n",
121 nbt_name_string(packet
, name
), src
->addr
, iface
->ip_address
));
125 nbtd_node_status_reply(nbtsock
, packet
, src
,
126 &iname
->name
, iface
);