don't use SEM_UNDO because of ridiculously small undo limits on some
[Samba.git] / source / namelogon.c
blobd8e0fcfc7681e9bdac212d8617940b1c1c8f49b9
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;
121 mailslot = skip_string(machine,1);
122 unicomp = skip_string(mailslot,1);
124 q = align2(q, buf);
126 q = skip_unicode_string(unicomp,1);
128 ntversion = IVAL(q, 0); q += 4;
129 lmnttoken = SVAL(q, 0); q += 2;
130 lm20token = SVAL(q, 0); q += 2;
132 /* construct reply */
134 q = outbuf;
135 SSVAL(q, 0, QUERYFORPDC_R); q += 2;
137 strcpy(reply_name,my_name);
138 strcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */
140 q = align2(q, buf);
142 PutUniCode(q, my_name); q = skip_unicode_string(q, 1); /* PDC name */
143 PutUniCode(q, lp_workgroup()); q = skip_unicode_string(q, 1); /* Domain name. */
145 SIVAL(q, 0, ntversion); q += 4;
146 SSVAL(q, 0, lmnttoken); q += 2;
147 SSVAL(q, 0, lm20token); q += 2;
149 DEBUG(3,("GETDC request from %s(%s), reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
150 machine,inet_ntoa(p->ip), reply_name, lp_workgroup(),
151 QUERYFORPDC_R, (uint32)ntversion, (uint32)lmnttoken,
152 (uint32)lm20token));
154 dump_data(4, outbuf, PTR_DIFF(q, outbuf));
156 send_mailslot_reply(True, mailslot,ClientDGRAM,
157 outbuf,PTR_DIFF(q,outbuf),
158 my_name,&dgram->source_name.name[0],0x20,0,
159 p->ip, *iface_ip(p->ip));
160 return;
163 case SAMLOGON:
165 char *q = buf + 2;
167 requestcount = SVAL(q, 0); q += 2;
168 unicomp = q;
169 uniuser = skip_unicode_string(unicomp,1);
170 mailslot = skip_unicode_string(uniuser,1);
171 q = skip_string(mailslot,1);
172 allowableaccount = IVAL(q, 0); q += 4;
173 domainsidsize = IVAL(q, 0); q += 4;
174 domainsid = q;
175 q += domainsidsize + 3;
176 ntversion = IVAL(q, 0); q += 4;
177 lmnttoken = SVAL(q, 0); q += 2;
178 lm20token = SVAL(q, 0); q += 2;
179 DEBUG(3,("SAMLOGON sidsize %d ntv %d\n", domainsidsize, ntversion));
182 If MACHINE$ is in our password database then respond, else ignore.
183 Let's ignore the SID.
185 strcpy(ascuser,unistr(uniuser));
186 DEBUG(3,("SAMLOGON user %s\n", ascuser));
187 strcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER */
188 strcpy(reply_name+2,my_name); /* PAXX: Assuming we are logon svr */
189 smb_pass = get_smbpwnam(ascuser);
191 if(!smb_pass)
193 DEBUG(3,("SAMLOGON request from %s(%s) for %s, not in password file\n",
194 unistr(unicomp),inet_ntoa(p->ip), ascuser));
195 return;
197 else
199 DEBUG(3,("SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n",
200 unistr(unicomp),inet_ntoa(p->ip), ascuser, reply_name, lp_workgroup(),
201 SAMLOGON_R ,lmnttoken));
204 /* construct reply */
206 q = outbuf;
207 SSVAL(q, 0, SAMLOGON_R); q += 2;
209 PutUniCode(q, reply_name); q = skip_unicode_string(q, 1);
210 unistrcpy(q, uniuser); q = skip_unicode_string(q, 1); /* User name (workstation trust account) */
211 PutUniCode(q, lp_workgroup()); q = skip_unicode_string(q, 1); /* Domain name. */
213 SIVAL(q, 0, ntversion); q += 4;
214 SSVAL(q, 0, lmnttoken); q += 2;
215 SSVAL(q, 0, lm20token); q += 2;
217 dump_data(4, outbuf, PTR_DIFF(q, outbuf));
219 send_mailslot_reply(True, mailslot,ClientDGRAM,
220 outbuf,PTR_DIFF(q,outbuf),
221 my_name,&dgram->source_name.name[0],0x20,0,
222 p->ip, *iface_ip(p->ip));
223 break;
226 default:
228 DEBUG(3,("Unknown domain request %d\n",code));
229 return;