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;
44 BOOL add_slashes = False;
47 char unknown_byte = 0;
48 uint16 request_count = 0;
54 uint32 allowableaccount; /* Control bits, i.e. 0x80 == workstation trust a/c. */
59 char *uniuser; /* Unicode user name. */
61 char *unicomp; /* Unicode computer name. */
62 struct smb_passwd *smb_pass; /* To check if machine account exists */
64 if (!lp_domain_logons())
66 DEBUG(3,("process_logon_packet: Logon packet received from IP %s and domain \
67 logons are not enabled.\n", inet_ntoa(p->ip) ));
71 pstrcpy(my_name, global_myname);
75 DEBUG(1,("process_logon_packet: Logon from %s: code = %x\n", inet_ntoa(p->ip), code));
83 char *user = skip_string(machine,1);
85 getdc = skip_string(user,1);
86 q = skip_string(getdc,1);
87 unknown_byte = CVAL(q,0);
88 request_count = SVAL(q,1);
92 fstrcpy(reply_name,my_name);
95 DEBUG(3,("process_logon_packet: Domain login request from %s at IP %s user=%s token=%x\n",
96 machine,inet_ntoa(p->ip),user,token));
99 SSVAL(q, 0, 6); q += 2;
101 fstrcpy(reply_name, "\\\\");
102 fstrcat(reply_name, my_name);
103 fstrcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */
105 SSVAL(q, 0, token); q += 2;
107 dump_data(4, outbuf, PTR_DIFF(q, outbuf));
109 send_mailslot(True, getdc,
110 outbuf,PTR_DIFF(q,outbuf),
111 dgram->dest_name.name,
112 dgram->dest_name.name_type,
113 dgram->source_name.name,
114 dgram->source_name.name_type,
115 p->ip, *iface_ip(p->ip));
124 getdc = skip_string(machine,1);
125 unicomp = skip_string(getdc,1);
127 q = align2(unicomp, buf);
129 q = skip_unicode_string(q, 1);
131 ntversion = IVAL(q, 0); q += 4;
132 lmnttoken = SVAL(q, 0); q += 2;
133 lm20token = SVAL(q, 0); q += 2;
135 /* Construct reply. */
138 SSVAL(q, 0, QUERYFORPDC_R); q += 2;
140 fstrcpy(reply_name,my_name);
141 fstrcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */
143 if (strcmp(mailslot, NT_LOGON_MAILSLOT)==0) {
146 PutUniCode(q, my_name); /* PDC name */
147 q = skip_unicode_string(q, 1);
148 PutUniCode(q, global_myworkgroup); /* Domain name*/
149 q = skip_unicode_string(q, 1);
151 SIVAL(q, 0, ntversion); q += 4;
152 SSVAL(q, 0, lmnttoken); q += 2;
153 SSVAL(q, 0, lm20token); q += 2;
156 DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \
157 reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
158 machine,inet_ntoa(p->ip), reply_name, lp_workgroup(),
159 QUERYFORPDC_R, (uint32)ntversion, (uint32)lmnttoken,
160 (uint32)lm20token ));
162 dump_data(4, outbuf, PTR_DIFF(q, outbuf));
164 send_mailslot(True, getdc,
165 outbuf,PTR_DIFF(q,outbuf),
166 dgram->dest_name.name,
167 dgram->dest_name.name_type,
168 dgram->source_name.name,
169 dgram->source_name.name_type,
170 p->ip, *iface_ip(p->ip));
178 requestcount = SVAL(q, 0); q += 2;
180 uniuser = skip_unicode_string(unicomp,1);
181 getdc = skip_unicode_string(uniuser,1);
182 q = skip_string(getdc,1);
183 allowableaccount = IVAL(q, 0); q += 4;
184 domainsidsize = IVAL(q, 0); q += 4;
186 q += domainsidsize + 3;
187 ntversion = IVAL(q, 0); q += 4;
188 lmnttoken = SVAL(q, 0); q += 2;
189 lm20token = SVAL(q, 0); q += 2;
191 DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d ntv %d\n", domainsidsize, ntversion));
194 * If MACHINE$ is in our password database then respond, else ignore.
195 * Let's ignore the SID.
198 pstrcpy(ascuser, unistr(uniuser));
199 DEBUG(3,("process_logon_packet: SAMLOGON user %s\n", ascuser));
201 fstrcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */
202 fstrcpy(reply_name+2,my_name);
204 smb_pass = getsampwnam(ascuser);
208 DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, not in password file\n",
209 unistr(unicomp),inet_ntoa(p->ip), ascuser));
212 else if(smb_pass->acct_ctrl & ACB_DISABLED)
214 DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, accound disabled.\n",
215 unistr(unicomp),inet_ntoa(p->ip), ascuser));
220 DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n",
221 unistr(unicomp),inet_ntoa(p->ip), ascuser, reply_name, global_myworkgroup,
222 SAMLOGON_R ,lmnttoken));
225 /* Construct reply. */
228 SSVAL(q, 0, SAMLOGON_R); q += 2;
230 PutUniCode(q, reply_name); q = skip_unicode_string(q, 1);
231 unistrcpy(q, uniuser); q = skip_unicode_string(q, 1); /* User name (workstation trust account) */
232 PutUniCode(q, lp_workgroup()); q = skip_unicode_string(q, 1); /* Domain name. */
234 SIVAL(q, 0, ntversion); q += 4;
235 SSVAL(q, 0, lmnttoken); q += 2;
236 SSVAL(q, 0, lm20token); q += 2;
238 dump_data(4, outbuf, PTR_DIFF(q, outbuf));
240 send_mailslot(True, getdc,
241 outbuf,PTR_DIFF(q,outbuf),
242 dgram->dest_name.name,
243 dgram->dest_name.name_type,
244 dgram->source_name.name,
245 dgram->source_name.name_type,
246 p->ip, *iface_ip(p->ip));
252 DEBUG(3,("process_logon_packet: Unknown domain request %d\n",code));