2 Unix SMB/CIFS implementation.
4 NBT datagram ntlogon 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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "nbt_server/nbt_server.h"
24 #include "smbd/service_task.h"
25 #include "lib/socket/socket.h"
26 #include "librpc/gen_ndr/ndr_nbt.h"
27 #include "param/param.h"
30 reply to a SAM LOGON request
32 static void nbtd_ntlogon_sam_logon(struct dgram_mailslot_handler
*dgmslot
,
33 struct nbtd_interface
*iface
,
34 struct nbt_dgram_packet
*packet
,
35 const struct socket_address
*src
,
36 struct nbt_ntlogon_packet
*ntlogon
)
38 struct nbt_name
*name
= &packet
->data
.msg
.dest_name
;
39 struct nbtd_interface
*reply_iface
= nbtd_find_reply_iface(iface
, src
->addr
, false);
40 struct nbt_ntlogon_packet reply
;
41 struct nbt_ntlogon_sam_logon_reply
*logon
;
43 /* only answer sam logon requests on the PDC or LOGON names */
44 if (name
->type
!= NBT_NAME_PDC
&& name
->type
!= NBT_NAME_LOGON
) {
48 /* setup a SAM LOGON reply */
50 reply
.command
= NTLOGON_SAM_LOGON_REPLY
;
51 logon
= &reply
.req
.reply
;
53 logon
->server
= talloc_asprintf(packet
, "\\\\%s",
54 lpcfg_netbios_name(iface
->nbtsrv
->task
->lp_ctx
));
55 logon
->user_name
= ntlogon
->req
.logon
.user_name
;
56 logon
->domain
= lpcfg_workgroup(iface
->nbtsrv
->task
->lp_ctx
);
57 logon
->nt_version
= 1;
58 logon
->lmnt_token
= 0xFFFF;
59 logon
->lm20_token
= 0xFFFF;
61 packet
->data
.msg
.dest_name
.type
= 0;
63 dgram_mailslot_ntlogon_reply(reply_iface
->dgmsock
,
65 lpcfg_netbios_name(iface
->nbtsrv
->task
->lp_ctx
),
66 ntlogon
->req
.logon
.mailslot_name
,
71 handle incoming ntlogon mailslot requests
73 void nbtd_mailslot_ntlogon_handler(struct dgram_mailslot_handler
*dgmslot
,
74 struct nbt_dgram_packet
*packet
,
75 struct socket_address
*src
)
77 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
78 struct nbtd_interface
*iface
=
79 talloc_get_type(dgmslot
->private_data
, struct nbtd_interface
);
80 struct nbt_ntlogon_packet
*ntlogon
=
81 talloc(dgmslot
, struct nbt_ntlogon_packet
);
82 struct nbtd_iface_name
*iname
;
83 struct nbt_name
*name
= &packet
->data
.msg
.dest_name
;
85 if (ntlogon
== NULL
) goto failed
;
88 see if the we are listening on the destination netbios name
90 iname
= nbtd_find_iname(iface
, name
, 0);
92 status
= NT_STATUS_BAD_NETWORK_NAME
;
96 DEBUG(2,("ntlogon request to %s from %s:%d\n",
97 nbt_name_string(ntlogon
, name
), src
->addr
, src
->port
));
98 status
= dgram_mailslot_ntlogon_parse(dgmslot
, ntlogon
, packet
, ntlogon
);
99 if (!NT_STATUS_IS_OK(status
)) goto failed
;
101 NDR_PRINT_DEBUG(nbt_ntlogon_packet
, ntlogon
);
103 switch (ntlogon
->command
) {
104 case NTLOGON_SAM_LOGON
:
105 nbtd_ntlogon_sam_logon(dgmslot
, iface
, packet
, src
, ntlogon
);
108 DEBUG(2,("unknown ntlogon op %d from %s:%d\n",
109 ntlogon
->command
, src
->addr
, src
->port
));
113 talloc_free(ntlogon
);
117 DEBUG(2,("nbtd ntlogon handler failed from %s:%d to %s - %s\n",
118 src
->addr
, src
->port
, nbt_name_string(ntlogon
, name
),
120 talloc_free(ntlogon
);