Line data Source code
1 : /* 2 : Unix SMB/CIFS implementation. 3 : 4 : defend our names against name registration requests 5 : 6 : Copyright (C) Andrew Tridgell 2005 7 : 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 3 of the License, or 11 : (at your option) any later version. 12 : 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. 17 : 18 : You should have received a copy of the GNU General Public License 19 : along with this program. If not, see <http://www.gnu.org/licenses/>. 20 : */ 21 : 22 : #include "includes.h" 23 : #include "../lib/util/dlinklist.h" 24 : #include "system/network.h" 25 : #include "nbt_server/nbt_server.h" 26 : #include "nbt_server/wins/winsserver.h" 27 : #include "librpc/gen_ndr/ndr_nbt.h" 28 : #include "lib/socket/socket.h" 29 : 30 : 31 : /* 32 : defend our registered names against registration or name refresh 33 : requests 34 : */ 35 5489 : void nbtd_request_defense(struct nbt_name_socket *nbtsock, 36 : struct nbt_name_packet *packet, 37 : struct socket_address *src) 38 : { 39 66 : struct nbtd_iface_name *iname; 40 66 : struct nbt_name *name; 41 5489 : struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private_data, 42 : struct nbtd_interface); 43 : 44 : /* 45 : * if the packet comes from one of our interfaces 46 : * it must be our winsclient trying to reach the winsserver 47 : */ 48 5489 : if (nbtd_self_packet(nbtsock, packet, src)) { 49 1501 : nbtd_winsserver_request(nbtsock, packet, src); 50 1501 : return; 51 : } 52 : 53 3988 : NBTD_ASSERT_PACKET(packet, src, packet->qdcount == 1); 54 3988 : NBTD_ASSERT_PACKET(packet, src, packet->arcount == 1); 55 3988 : NBTD_ASSERT_PACKET(packet, src, 56 : packet->questions[0].question_type == NBT_QTYPE_NETBIOS); 57 3988 : NBTD_ASSERT_PACKET(packet, src, 58 : packet->questions[0].question_class == NBT_QCLASS_IP); 59 3988 : NBTD_ASSERT_PACKET(packet, src, 60 : packet->additional[0].rr_type == NBT_QTYPE_NETBIOS); 61 3988 : NBTD_ASSERT_PACKET(packet, src, 62 : packet->additional[0].rr_class == NBT_QCLASS_IP); 63 3988 : NBTD_ASSERT_PACKET(packet, src, 64 : packet->additional[0].rdata.netbios.length == 6); 65 : 66 : /* see if we have the requested name on this interface */ 67 3988 : name = &packet->questions[0].name; 68 : 69 3988 : iname = nbtd_find_iname(iface, name, NBT_NM_ACTIVE); 70 3988 : if (iname != NULL && 71 251 : !(name->type == NBT_NAME_LOGON || iname->nb_flags & NBT_NM_GROUP)) { 72 9 : DEBUG(2,("Defending name %s on %s against %s\n", 73 : nbt_name_string(packet, name), 74 : iface->bcast_address, src->addr)); 75 9 : nbtd_name_registration_reply(nbtsock, packet, src, NBT_RCODE_ACT); 76 : } else { 77 3979 : nbtd_winsserver_request(nbtsock, packet, src); 78 : } 79 : }