added some debug lines to the rename code
[Samba.git] / source / namelogon.c
blob697a11a16a4494f279ec6d75cf2827be01ec0138
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 NBT netbios routines and daemon - version 2
5 Copyright (C) Andrew Tridgell 1994-1997
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 Revision History:
23 14 jan 96: lkcl@pires.co.uk
24 added multiple workgroup domain master support
28 #include "includes.h"
30 extern int ClientDGRAM;
32 extern int DEBUGLEVEL;
34 extern pstring myname;
37 /****************************************************************************
38 process a domain logon packet
40 **************************************************************************/
41 void process_logon_packet(struct packet_struct *p,char *buf,int len)
43 struct dgram_packet *dgram = &p->packet.dgram;
44 pstring my_name;
45 fstring reply_name;
46 BOOL add_slashes = False;
47 pstring outbuf;
48 int code,reply_code;
49 char unknown_byte = 0;
50 uint16 request_count = 0;
51 uint16 token = 0;
53 uint32 ntversion;
54 uint16 lmnttoken;
55 uint16 lm20token;
56 uint32 allowableaccount; /* Control bits, i.e. 0x80 == workstation trust a/c */
57 uint32 domainsidsize;
58 uint16 requestcount;
59 char *domainsid;
60 char *uniuser; /* Unicode user name */
61 pstring ascuser;
62 char *mailslot;
63 char *unicomp; /* Unicode computer name */
64 struct smb_passwd *smb_pass; /* To check if machine account exists */
66 if (!lp_domain_logons())
68 DEBUG(3,("No domain logons\n"));
69 return;
72 strcpy(my_name, myname);
73 strupper(my_name);
75 code = SVAL(buf,0);
76 DEBUG(1,("namelogon from %s: %x\n", inet_ntoa(p->ip), code));
78 switch (code)
80 case 0:
82 char *q = buf + 2;
83 char *machine = q;
84 char *user = skip_string(machine,1);
86 mailslot = skip_string(user,1);
87 q = skip_string(mailslot,1);
88 unknown_byte = CVAL(q,0);
89 request_count = SVAL(q,1);
90 token = SVAL(q,3);
92 reply_code = 0x6;
93 strcpy(reply_name,my_name);
94 add_slashes = True;
96 DEBUG(3,("Domain login request from %s(%s) user=%s token=%x\n",
97 machine,inet_ntoa(p->ip),user,token));
99 q = outbuf;
100 SSVAL(q, 0, 6); q += 2;
102 strcpy(reply_name, "\\\\");
103 strcat(reply_name, my_name);
104 strcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */
106 SSVAL(q, 0, token); q += 2;
108 dump_data(4, outbuf, PTR_DIFF(q, outbuf));
110 send_mailslot_reply(True, mailslot, ClientDGRAM,
111 outbuf,PTR_DIFF(q,outbuf),
112 my_name,&dgram->source_name.name[0],0x20,0,
113 p->ip, *iface_ip(p->ip));
114 break;
117 case QUERYFORPDC:
119 char *q = buf + 2;
120 char *machine = q;
122 mailslot = skip_string(machine,1);
123 unicomp = skip_string(mailslot,1);
125 q = align2(unicomp, buf);
127 q = skip_unicode_string(q, 1);
129 ntversion = IVAL(q, 0); q += 4;
130 lmnttoken = SVAL(q, 0); q += 2;
131 lm20token = SVAL(q, 0); q += 2;
133 /* construct reply */
135 q = outbuf;
136 SSVAL(q, 0, QUERYFORPDC_R); q += 2;
138 strcpy(reply_name,my_name);
139 strcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */
141 q = align2(q, buf);
143 PutUniCode(q, my_name); q = skip_unicode_string(q, 1); /* PDC name */
144 PutUniCode(q, lp_workgroup()); q = skip_unicode_string(q, 1); /* Domain name. */
146 SIVAL(q, 0, ntversion); q += 4;
147 SSVAL(q, 0, lmnttoken); q += 2;
148 SSVAL(q, 0, lm20token); q += 2;
150 DEBUG(3,("GETDC request from %s(%s), reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
151 machine,inet_ntoa(p->ip), reply_name, lp_workgroup(),
152 QUERYFORPDC_R, (uint32)ntversion, (uint32)lmnttoken,
153 (uint32)lm20token));
155 dump_data(4, outbuf, PTR_DIFF(q, outbuf));
157 send_mailslot_reply(True, mailslot,ClientDGRAM,
158 outbuf,PTR_DIFF(q,outbuf),
159 my_name,&dgram->source_name.name[0],0x20,0,
160 p->ip, *iface_ip(p->ip));
161 return;
164 case SAMLOGON:
166 char *q = buf + 2;
168 requestcount = SVAL(q, 0); q += 2;
169 unicomp = q;
170 uniuser = skip_unicode_string(unicomp,1);
171 mailslot = skip_unicode_string(uniuser,1);
172 q = skip_string(mailslot,1);
173 allowableaccount = IVAL(q, 0); q += 4;
174 domainsidsize = IVAL(q, 0); q += 4;
175 domainsid = q;
176 q += domainsidsize + 3;
177 ntversion = IVAL(q, 0); q += 4;
178 lmnttoken = SVAL(q, 0); q += 2;
179 lm20token = SVAL(q, 0); q += 2;
181 DEBUG(3,("SAMLOGON sidsize %d ntv %d\n", domainsidsize, ntversion));
184 If MACHINE$ is in our password database then respond, else ignore.
185 Let's ignore the SID.
188 strcpy(ascuser, unistr(uniuser));
189 DEBUG(3,("SAMLOGON user %s\n", ascuser));
191 strcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER */
192 strcpy(reply_name+2,my_name);
194 smb_pass = get_smbpwd_entry(ascuser, 0);
196 if(!smb_pass)
198 DEBUG(3,("SAMLOGON request from %s(%s) for %s, not in password file\n",
199 unistr(unicomp),inet_ntoa(p->ip), ascuser));
200 return;
202 else
204 DEBUG(3,("SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n",
205 unistr(unicomp),inet_ntoa(p->ip), ascuser, reply_name, lp_workgroup(),
206 SAMLOGON_R ,lmnttoken));
209 /* construct reply */
211 q = outbuf;
212 SSVAL(q, 0, SAMLOGON_R); q += 2;
214 PutUniCode(q, reply_name); q = skip_unicode_string(q, 1);
215 unistrcpy(q, uniuser); q = skip_unicode_string(q, 1); /* User name (workstation trust account) */
216 PutUniCode(q, lp_workgroup()); q = skip_unicode_string(q, 1); /* Domain name. */
218 SIVAL(q, 0, ntversion); q += 4;
219 SSVAL(q, 0, lmnttoken); q += 2;
220 SSVAL(q, 0, lm20token); q += 2;
222 dump_data(4, outbuf, PTR_DIFF(q, outbuf));
224 send_mailslot_reply(True, mailslot,ClientDGRAM,
225 outbuf,PTR_DIFF(q,outbuf),
226 my_name,&dgram->source_name.name[0],0x20,0,
227 p->ip, *iface_ip(p->ip));
228 break;
231 default:
233 DEBUG(3,("Unknown domain request %d\n",code));
234 return;