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;
53 char *uniuser; /* Unicode user name. */
55 char *unicomp; /* Unicode computer name. */
56 struct smb_passwd *smb_pass; /* To check if machine account exists */
58 if (!lp_domain_logons())
60 DEBUG(3,("process_logon_packet: Logon packet received from IP %s and domain \
61 logons are not enabled.\n", inet_ntoa(p->ip) ));
65 pstrcpy(my_name, global_myname);
69 DEBUG(1,("process_logon_packet: Logon from %s: code = %x\n", inet_ntoa(p->ip), code));
77 char *user = skip_string(machine,1);
79 getdc = skip_string(user,1);
80 q = skip_string(getdc,1);
83 fstrcpy(reply_name,my_name);
85 DEBUG(3,("process_logon_packet: Domain login request from %s at IP %s user=%s token=%x\n",
86 machine,inet_ntoa(p->ip),user,token));
89 SSVAL(q, 0, 6); q += 2;
91 fstrcpy(reply_name, "\\\\");
92 fstrcat(reply_name, my_name);
93 fstrcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */
95 SSVAL(q, 0, token); q += 2;
97 dump_data(4, outbuf, PTR_DIFF(q, outbuf));
99 send_mailslot(True, getdc,
100 outbuf,PTR_DIFF(q,outbuf),
101 dgram->dest_name.name,
102 dgram->dest_name.name_type,
103 dgram->source_name.name,
104 dgram->source_name.name_type,
105 p->ip, *iface_ip(p->ip), p->port);
114 getdc = skip_string(machine,1);
115 unicomp = skip_string(getdc,1);
117 q = align2(unicomp, buf);
119 q = skip_unicode_string(q, 1);
121 ntversion = IVAL(q, 0); q += 4;
122 lmnttoken = SVAL(q, 0); q += 2;
123 lm20token = SVAL(q, 0); q += 2;
125 /* Construct reply. */
128 SSVAL(q, 0, QUERYFORPDC_R); q += 2;
130 fstrcpy(reply_name,my_name);
131 fstrcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */
133 if (strcmp(mailslot, NT_LOGON_MAILSLOT)==0) {
136 PutUniCode(q, my_name); /* PDC name */
137 q = skip_unicode_string(q, 1);
138 PutUniCode(q, global_myworkgroup); /* Domain name*/
139 q = skip_unicode_string(q, 1);
141 SIVAL(q, 0, ntversion); q += 4;
142 SSVAL(q, 0, lmnttoken); q += 2;
143 SSVAL(q, 0, lm20token); q += 2;
146 DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \
147 reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
148 machine,inet_ntoa(p->ip), reply_name, lp_workgroup(),
149 QUERYFORPDC_R, (uint32)ntversion, (uint32)lmnttoken,
150 (uint32)lm20token ));
152 dump_data(4, outbuf, PTR_DIFF(q, outbuf));
154 send_mailslot(True, getdc,
155 outbuf,PTR_DIFF(q,outbuf),
156 dgram->dest_name.name,
157 dgram->dest_name.name_type,
158 dgram->source_name.name,
159 dgram->source_name.name_type,
160 p->ip, *iface_ip(p->ip), p->port);
169 uniuser = skip_unicode_string(unicomp,1);
170 getdc = skip_unicode_string(uniuser,1);
171 q = skip_string(getdc,1);
172 domainsidsize = IVAL(q, 0); q += 4;
173 q += domainsidsize + 3;
174 ntversion = IVAL(q, 0); q += 4;
175 lmnttoken = SVAL(q, 0); q += 2;
176 lm20token = SVAL(q, 0); q += 2;
178 DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d ntv %d\n", domainsidsize, ntversion));
181 * If MACHINE$ is in our password database then respond, else ignore.
182 * Let's ignore the SID.
185 pstrcpy(ascuser, unistr(uniuser));
186 DEBUG(3,("process_logon_packet: SAMLOGON user %s\n", ascuser));
188 fstrcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */
189 fstrcpy(reply_name+2,my_name);
191 smb_pass = getsmbpwnam(ascuser);
195 DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, not in password file\n",
196 unistr(unicomp),inet_ntoa(p->ip), ascuser));
199 else if(smb_pass->acct_ctrl & ACB_DISABLED)
201 DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, accound disabled.\n",
202 unistr(unicomp),inet_ntoa(p->ip), ascuser));
207 DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n",
208 unistr(unicomp),inet_ntoa(p->ip), ascuser, reply_name, global_myworkgroup,
209 SAMLOGON_R ,lmnttoken));
212 /* Construct reply. */
215 SSVAL(q, 0, SAMLOGON_R); q += 2;
217 PutUniCode(q, reply_name); q = skip_unicode_string(q, 1);
218 unistrcpy(q, uniuser); q = skip_unicode_string(q, 1); /* User name (workstation trust account) */
219 PutUniCode(q, lp_workgroup()); q = skip_unicode_string(q, 1); /* Domain name. */
221 SIVAL(q, 0, ntversion); q += 4;
222 SSVAL(q, 0, lmnttoken); q += 2;
223 SSVAL(q, 0, lm20token); q += 2;
225 dump_data(4, outbuf, PTR_DIFF(q, outbuf));
227 send_mailslot(True, getdc,
228 outbuf,PTR_DIFF(q,outbuf),
229 dgram->dest_name.name,
230 dgram->dest_name.name_type,
231 dgram->source_name.name,
232 dgram->source_name.name_type,
233 p->ip, *iface_ip(p->ip), p->port);
239 DEBUG(3,("process_logon_packet: Unknown domain request %d\n",code));