2 Unix SMB/CIFS implementation.
4 defend our names against name registration requests
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 "nbt_server/wins/winsserver.h"
28 #include "librpc/gen_ndr/ndr_nbt.h"
29 #include "lib/socket/socket.h"
33 defend our registered names against registration or name refresh
36 void nbtd_request_defense(struct nbt_name_socket *nbtsock,
37 struct nbt_name_packet *packet,
38 struct socket_address *src)
40 struct nbtd_iface_name *iname;
41 struct nbt_name *name;
42 struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private,
43 struct nbtd_interface);
46 * if the packet comes from one of our interfaces
47 * it must be our winsclient trying to reach the winsserver
49 if (nbtd_self_packet(nbtsock, packet, src)) {
50 nbtd_winsserver_request(nbtsock, packet, src);
54 NBTD_ASSERT_PACKET(packet, src, packet->qdcount == 1);
55 NBTD_ASSERT_PACKET(packet, src, packet->arcount == 1);
56 NBTD_ASSERT_PACKET(packet, src,
57 packet->questions[0].question_type == NBT_QTYPE_NETBIOS);
58 NBTD_ASSERT_PACKET(packet, src,
59 packet->questions[0].question_class == NBT_QCLASS_IP);
60 NBTD_ASSERT_PACKET(packet, src,
61 packet->additional[0].rr_type == NBT_QTYPE_NETBIOS);
62 NBTD_ASSERT_PACKET(packet, src,
63 packet->additional[0].rr_class == NBT_QCLASS_IP);
64 NBTD_ASSERT_PACKET(packet, src,
65 packet->additional[0].rdata.netbios.length == 6);
67 /* see if we have the requested name on this interface */
68 name = &packet->questions[0].name;
70 iname = nbtd_find_iname(iface, name, NBT_NM_ACTIVE);
72 !(name->type == NBT_NAME_LOGON || iname->nb_flags & NBT_NM_GROUP)) {
73 DEBUG(2,("Defending name %s on %s against %s\n",
74 nbt_name_string(packet, name),
75 iface->bcast_address, src->addr));
76 nbtd_name_registration_reply(nbtsock, packet, src, NBT_RCODE_ACT);
78 nbtd_winsserver_request(nbtsock, packet, src);