2 Unix SMB/Netbios implementation.
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.
23 14 jan 96: lkcl@pires.co.uk
24 added multiple workgroup domain master support
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
;
46 BOOL add_slashes
= False
;
49 char unknown_byte
= 0;
50 uint16 request_count
= 0;
56 uint32 allowableaccount
; /* Control bits, i.e. 0x80 == workstation trust a/c */
60 char *uniuser
; /* Unicode user name */
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"));
72 strcpy(my_name
, myname
);
76 DEBUG(1,("namelogon from %s: %x\n", inet_ntoa(p
->ip
), code
));
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);
93 strcpy(reply_name
,my_name
);
96 DEBUG(3,("Domain login request from %s(%s) user=%s token=%x\n",
97 machine
,inet_ntoa(p
->ip
),user
,token
));
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
));
121 mailslot
= skip_string(machine
,1);
122 unicomp
= skip_string(mailslot
,1);
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 */
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 */
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
,
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
));
167 requestcount
= SVAL(q
, 0); q
+= 2;
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;
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
);
193 DEBUG(3,("SAMLOGON request from %s(%s) for %s, not in password file\n",
194 unistr(unicomp
),inet_ntoa(p
->ip
), ascuser
));
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 */
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
));
228 DEBUG(3,("Unknown domain request %d\n",code
));