2 Unix SMB/Netbios implementation.
4 NBT netbios routines and daemon - version 2
5 Copyright (C) Andrew Tridgell 1994-1998
6 Copyright (C) Luke Kenneth Casson Leighton 1994-1998
7 Copyright (C) Jeremy Allison 1994-1998
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 extern int DEBUGLEVEL;
31 extern pstring global_myname;
32 extern fstring global_myworkgroup;
34 /****************************************************************************
35 Process a domain logon packet
36 **************************************************************************/
38 void process_logon_packet(struct packet_struct *p,char *buf,int len,
41 struct dgram_packet *dgram = &p->packet.dgram;
52 char *uniuser; /* Unicode user name. */
53 char *unicomp; /* Unicode computer name. */
55 memset(outbuf, 0, sizeof(outbuf));
57 if (!lp_domain_logons())
59 DEBUG(3,("process_logon_packet: Logon packet received from IP %s and domain \
60 logons are not enabled.\n", inet_ntoa(p->ip) ));
64 pstrcpy(my_name, global_myname);
68 DEBUG(1,("process_logon_packet: Logon from %s: code = %x\n", inet_ntoa(p->ip), code));
76 char *user = skip_string(machine,1);
78 getdc = skip_string(user,1);
79 q = skip_string(getdc,1);
82 fstrcpy(reply_name,my_name);
84 DEBUG(3,("process_logon_packet: Domain login request from %s at IP %s user=%s token=%x\n",
85 machine,inet_ntoa(p->ip),user,token));
91 fstrcpy(reply_name, "\\\\");
92 fstrcat(reply_name, my_name);
93 fstrcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */
98 dump_data(4, outbuf, PTR_DIFF(q, outbuf));
100 send_mailslot(True, getdc,
101 outbuf,PTR_DIFF(q,outbuf),
102 dgram->dest_name.name,
103 dgram->dest_name.name_type,
104 dgram->source_name.name,
105 dgram->source_name.name_type,
106 p->ip, *iface_ip(p->ip), p->port);
115 getdc = skip_string(machine,1);
116 unicomp = skip_string(getdc,1);
118 q = align2(unicomp, buf);
120 q = skip_unibuf(q, buf+len-q);
122 ntversion = IVAL(q, 0);
124 lmnttoken = SVAL(q, 0);
126 lm20token = SVAL(q, 0);
129 /* Construct reply. */
132 SSVAL(q, 0, QUERYFORPDC_R);
135 fstrcpy(reply_name,my_name);
136 fstrcpy(q, reply_name);
137 q = skip_string(q, 1); /* PDC name */
139 if (strcmp(mailslot, NT_LOGON_MAILSLOT)==0) {
142 /* PDC and domain name */
143 q = ascii_to_unibuf(q, my_name, outbuf+sizeof(outbuf)-q-2);
144 q = ascii_to_unibuf(q, global_myworkgroup, outbuf+sizeof(outbuf)-q-2);
146 SIVAL(q, 0, ntversion);
148 SSVAL(q, 0, lmnttoken);
150 SSVAL(q, 0, lm20token);
154 DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \
155 reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
156 machine,inet_ntoa(p->ip), reply_name, lp_workgroup(),
157 QUERYFORPDC_R, (uint32)ntversion, (uint32)lmnttoken,
158 (uint32)lm20token ));
160 dump_data(4, outbuf, PTR_DIFF(q, outbuf));
162 send_mailslot(True, getdc,
163 outbuf,PTR_DIFF(q,outbuf),
164 dgram->dest_name.name,
165 dgram->dest_name.name_type,
166 dgram->source_name.name,
167 dgram->source_name.name_type,
168 p->ip, *iface_ip(p->ip), p->port);
178 uniuser = skip_unibuf(unicomp, buf+len-q);
179 getdc = skip_unibuf(uniuser, buf+len-q);
180 q = skip_string(getdc,1);
182 domainsidsize = IVAL(q, 0);
184 q += domainsidsize + 3;
185 ntversion = IVAL(q, 0);
187 lmnttoken = SVAL(q, 0);
189 lm20token = SVAL(q, 0);
192 DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d ntv %d\n", domainsidsize, ntversion));
195 * we respond regadless of whether the machine is in our password
196 * database. If it isn't then we let smbd send an appropriate error.
197 * Let's ignore the SID.
200 fstrcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */
201 fstrcpy(reply_name+2,my_name);
207 unibuf_to_ascii(ascuser, uniuser, sizeof(ascuser)-1);
208 unibuf_to_ascii(asccomp, unicomp, sizeof(asccomp)-1);
210 DEBUGADD(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n",
211 asccomp,inet_ntoa(p->ip), ascuser, reply_name,
212 global_myworkgroup, SAMLOGON_R, lmnttoken));
215 /* Construct reply. */
218 SSVAL(q, 0, SAMLOGON_R);
221 /* Logon server, trust account, domain */
222 q = ascii_to_unibuf(q, reply_name, outbuf+sizeof(outbuf)-q-2);
223 q = uni_strncpy(q, uniuser, outbuf+sizeof(outbuf)-q-2);
224 q = ascii_to_unibuf(q, lp_workgroup(), outbuf+sizeof(outbuf)-q-2);
226 SIVAL(q, 0, ntversion);
228 SSVAL(q, 0, lmnttoken);
230 SSVAL(q, 0, lm20token);
233 dump_data(4, outbuf, PTR_DIFF(q, outbuf));
235 send_mailslot(True, getdc,
236 outbuf,PTR_DIFF(q,outbuf),
237 dgram->dest_name.name,
238 dgram->dest_name.name_type,
239 dgram->source_name.name,
240 dgram->source_name.name_type,
241 p->ip, *iface_ip(p->ip), p->port);
247 DEBUG(3,("process_logon_packet: Unknown domain request %d\n",code));