2 Unix SMB/CIFS implementation.
4 NBT datagram netlogon server
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 "dlinklist.h"
25 #include "nbt_server/nbt_server.h"
26 #include "smbd/service_task.h"
27 #include "lib/socket/socket.h"
30 reply to a GETDC request
32 static void nbtd_netlogon_getdc(struct dgram_mailslot_handler *dgmslot,
33 struct nbt_dgram_packet *packet,
34 const char *src_address, int src_port,
35 struct nbt_netlogon_packet *netlogon)
37 struct nbt_name *name = &packet->data.msg.dest_name;
38 struct nbt_netlogon_packet reply;
39 struct nbt_netlogon_response_from_pdc *pdc;
41 /* only answer getdc requests on the PDC or LOGON names */
42 if (name->type != NBT_NAME_PDC && name->type != NBT_NAME_LOGON) {
46 /* setup a GETDC reply */
47 reply.command = NETLOGON_RESPONSE_FROM_PDC;
48 pdc = &reply.req.response;
50 pdc->pdc_name = lp_netbios_name();
51 pdc->unicode_pdc_name = pdc->pdc_name;
52 pdc->domain_name = lp_workgroup();
54 pdc->lmnt_token = 0xFFFF;
55 pdc->lm20_token = 0xFFFF;
58 packet->data.msg.dest_name.type = 0;
60 dgram_mailslot_netlogon_reply(dgmslot->dgmsock,
62 netlogon->req.pdc.mailslot_name,
68 handle incoming netlogon mailslot requests
70 void nbtd_mailslot_netlogon_handler(struct dgram_mailslot_handler *dgmslot,
71 struct nbt_dgram_packet *packet,
72 const char *src_address, int src_port)
74 NTSTATUS status = NT_STATUS_NO_MEMORY;
75 struct nbtd_interface *iface =
76 talloc_get_type(dgmslot->private, struct nbtd_interface);
77 struct nbt_netlogon_packet *netlogon =
78 talloc(dgmslot, struct nbt_netlogon_packet);
79 struct nbtd_iface_name *iname;
80 struct nbt_name *name = &packet->data.msg.dest_name;
82 if (netlogon == NULL) goto failed;
85 see if the we are listening on the destination netbios name
87 iname = nbtd_find_iname(iface, name, 0);
89 status = NT_STATUS_BAD_NETWORK_NAME;
93 DEBUG(2,("netlogon request to %s from %s:%d\n",
94 nbt_name_string(netlogon, name), src_address, src_port));
95 status = dgram_mailslot_netlogon_parse(dgmslot, netlogon, packet, netlogon);
96 if (!NT_STATUS_IS_OK(status)) goto failed;
98 NDR_PRINT_DEBUG(nbt_netlogon_packet, netlogon);
100 switch (netlogon->command) {
101 case NETLOGON_QUERY_FOR_PDC:
102 nbtd_netlogon_getdc(dgmslot, packet, src_address, src_port, netlogon);
105 DEBUG(2,("unknown netlogon op %d from %s:%d\n",
106 netlogon->command, src_address, src_port));
110 talloc_free(netlogon);
114 DEBUG(2,("nbtd netlogon handler failed from %s:%d - %s\n",
115 src_address, src_port, nt_errstr(status)));
116 talloc_free(netlogon);