2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1992-1998
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.
24 extern int DEBUGLEVEL
;
27 extern fstring global_myworkgroup
;
28 extern fstring remote_machine
;
30 /****************************************************************************
31 reply for the core protocol
32 ****************************************************************************/
33 static int reply_corep(char *outbuf
)
35 int outsize
= set_message(outbuf
,1,0,True
);
37 Protocol
= PROTOCOL_CORE
;
43 /****************************************************************************
44 reply for the coreplus protocol
45 ****************************************************************************/
46 static int reply_coreplus(char *outbuf
)
48 int raw
= (lp_readraw()?1:0) | (lp_writeraw()?2:0);
49 int outsize
= set_message(outbuf
,13,0,True
);
50 SSVAL(outbuf
,smb_vwv5
,raw
); /* tell redirector we support
51 readbraw and writebraw (possibly) */
52 /* Reply, SMBlockread, SMBwritelock supported. */
53 SCVAL(outbuf
,smb_flg
,FLAG_REPLY
|FLAG_SUPPORT_LOCKREAD
);
54 SSVAL(outbuf
,smb_vwv1
,0x1); /* user level security, don't encrypt */
56 Protocol
= PROTOCOL_COREPLUS
;
62 /****************************************************************************
63 reply for the lanman 1.0 protocol
64 ****************************************************************************/
65 static int reply_lanman1(char *outbuf
)
67 int raw
= (lp_readraw()?1:0) | (lp_writeraw()?2:0);
69 BOOL doencrypt
= SMBENCRYPT();
70 time_t t
= time(NULL
);
72 if (lp_security()>=SEC_USER
) secword
|= 1;
73 if (doencrypt
) secword
|= 2;
75 set_message(outbuf
,13,doencrypt
?8:0,True
);
76 SSVAL(outbuf
,smb_vwv1
,secword
);
77 /* Create a token value and add it to the outgoing packet. */
79 generate_next_challenge(smb_buf(outbuf
));
81 Protocol
= PROTOCOL_LANMAN1
;
83 /* Reply, SMBlockread, SMBwritelock supported. */
84 SCVAL(outbuf
,smb_flg
,FLAG_REPLY
|FLAG_SUPPORT_LOCKREAD
);
85 SSVAL(outbuf
,smb_vwv2
,max_recv
);
86 SSVAL(outbuf
,smb_vwv3
,lp_maxmux()); /* maxmux */
87 SSVAL(outbuf
,smb_vwv4
,1);
88 SSVAL(outbuf
,smb_vwv5
,raw
); /* tell redirector we support
89 readbraw writebraw (possibly) */
90 SIVAL(outbuf
,smb_vwv6
,sys_getpid());
91 SSVAL(outbuf
,smb_vwv10
, TimeDiff(t
)/60);
93 put_dos_date(outbuf
,smb_vwv8
,t
);
95 return (smb_len(outbuf
)+4);
99 /****************************************************************************
100 reply for the lanman 2.0 protocol
101 ****************************************************************************/
102 static int reply_lanman2(char *outbuf
)
104 int raw
= (lp_readraw()?1:0) | (lp_writeraw()?2:0);
106 BOOL doencrypt
= SMBENCRYPT();
107 time_t t
= time(NULL
);
108 struct cli_state
*cli
= NULL
;
112 if (lp_security() == SEC_SERVER
) {
113 cli
= server_cryptkey();
117 DEBUG(3,("using password server validation\n"));
118 doencrypt
= ((cli
->sec_mode
& 2) != 0);
121 if (lp_security()>=SEC_USER
) secword
|= 1;
122 if (doencrypt
) secword
|= 2;
127 generate_next_challenge(cryptkey
);
129 memcpy(cryptkey
, cli
->cryptkey
, 8);
130 set_challenge(cli
->cryptkey
);
134 set_message(outbuf
,13,crypt_len
,True
);
135 SSVAL(outbuf
,smb_vwv1
,secword
);
136 SIVAL(outbuf
,smb_vwv6
,sys_getpid());
138 memcpy(smb_buf(outbuf
), cryptkey
, 8);
140 Protocol
= PROTOCOL_LANMAN2
;
142 /* Reply, SMBlockread, SMBwritelock supported. */
143 SCVAL(outbuf
,smb_flg
,FLAG_REPLY
|FLAG_SUPPORT_LOCKREAD
);
144 SSVAL(outbuf
,smb_vwv2
,max_recv
);
145 SSVAL(outbuf
,smb_vwv3
,lp_maxmux());
146 SSVAL(outbuf
,smb_vwv4
,1);
147 SSVAL(outbuf
,smb_vwv5
,raw
); /* readbraw and/or writebraw */
148 SSVAL(outbuf
,smb_vwv10
, TimeDiff(t
)/60);
149 put_dos_date(outbuf
,smb_vwv8
,t
);
151 return (smb_len(outbuf
)+4);
155 /****************************************************************************
156 reply for the nt protocol
157 ****************************************************************************/
158 static int reply_nt1(char *outbuf
)
160 /* dual names + lock_and_read + nt SMBs + remote API calls */
161 int capabilities
= CAP_NT_FIND
|CAP_LOCK_AND_READ
|CAP_LEVEL_II_OPLOCKS
|
162 (lp_nt_smb_support() ? CAP_NT_SMBS
| CAP_RPC_REMOTE_APIS
: 0) |
163 ((lp_large_readwrite() && (SMB_OFF_T_BITS
== 64)) ?
164 CAP_LARGE_READX
| CAP_LARGE_WRITEX
| CAP_W2K_SMBS
: 0) |
165 (SMB_OFF_T_BITS
== 64 ? CAP_LARGE_FILES
: 0);
169 other valid capabilities which we may support at some time...
170 CAP_LARGE_READX|CAP_STATUS32|CAP_LEVEL_II_OPLOCKS;
174 BOOL doencrypt
= SMBENCRYPT();
175 time_t t
= time(NULL
);
177 struct cli_state
*cli
= NULL
;
181 if (lp_security() == SEC_SERVER
) {
182 cli
= server_cryptkey();
186 DEBUG(3,("using password server validation\n"));
187 doencrypt
= ((cli
->sec_mode
& 2) != 0);
193 generate_next_challenge(cryptkey
);
195 memcpy(cryptkey
, cli
->cryptkey
, 8);
196 set_challenge(cli
->cryptkey
);
200 if (lp_readraw() && lp_writeraw()) {
201 capabilities
|= CAP_RAW_MODE
;
205 /* allow for disabling unicode */
207 capabilities
|= CAP_UNICODE
;
212 capabilities
|= CAP_DFS
;
215 if (lp_security() >= SEC_USER
) secword
|= 1;
216 if (doencrypt
) secword
|= 2;
218 /* decide where (if) to put the encryption challenge, and
219 follow it with the OEM'd domain name
221 data_len
= crypt_len
+ strlen(global_myworkgroup
) + 1;
223 set_message(outbuf
,17,data_len
,True
);
224 pstrcpy(smb_buf(outbuf
)+crypt_len
, global_myworkgroup
);
226 CVAL(outbuf
,smb_vwv1
) = secword
;
227 SSVALS(outbuf
,smb_vwv16
+1,crypt_len
);
229 memcpy(smb_buf(outbuf
), cryptkey
, 8);
231 Protocol
= PROTOCOL_NT1
;
233 SSVAL(outbuf
,smb_vwv1
+1,lp_maxmux()); /* maxmpx */
234 SSVAL(outbuf
,smb_vwv2
+1,1); /* num vcs */
235 SIVAL(outbuf
,smb_vwv3
+1,0xffff); /* max buffer. LOTS! */
236 SIVAL(outbuf
,smb_vwv5
+1,0x10000); /* raw size. full 64k */
237 SIVAL(outbuf
,smb_vwv7
+1,sys_getpid()); /* session key */
238 SIVAL(outbuf
,smb_vwv9
+1,capabilities
); /* capabilities */
239 put_long_date(outbuf
+smb_vwv11
+1,t
);
240 SSVALS(outbuf
,smb_vwv15
+1,TimeDiff(t
)/60);
241 SSVAL(outbuf
,smb_vwv17
,data_len
); /* length of challenge+domain strings */
243 return (smb_len(outbuf
)+4);
246 /* these are the protocol lists used for auto architecture detection:
249 protocol [PC NETWORK PROGRAM 1.0]
250 protocol [XENIX CORE]
251 protocol [MICROSOFT NETWORKS 1.03]
253 protocol [Windows for Workgroups 3.1a]
256 protocol [NT LM 0.12]
259 protocol [PC NETWORK PROGRAM 1.0]
260 protocol [XENIX CORE]
261 protocol [MICROSOFT NETWORKS 1.03]
263 protocol [Windows for Workgroups 3.1a]
266 protocol [NT LM 0.12]
269 protocol [PC NETWORK PROGRAM 1.0]
271 protocol [Windows for Workgroups 3.1a]
274 protocol [NT LM 0.12]
277 protocol [PC NETWORK PROGRAM 1.0]
278 protocol [XENIX CORE]
285 * Modified to recognize the architecture of the remote machine better.
287 * This appears to be the matrix of which protocol is used by which
289 Protocol WfWg Win95 WinNT Win2K OS/2
290 PC NETWORK PROGRAM 1.0 1 1 1 1 1
292 MICROSOFT NETWORKS 3.0 2 2
294 MICROSOFT NETWORKS 1.03 3
297 Windows for Workgroups 3.1a 5 5 5 3
302 * tim@fsg.com 09/29/95
303 * Win2K added by matty 17/7/99
306 #define ARCH_WFWG 0x3 /* This is a fudge because WfWg is like Win95 */
307 #define ARCH_WIN95 0x2
308 #define ARCH_WINNT 0x4
309 #define ARCH_WIN2K 0xC /* Win2K is like NT */
310 #define ARCH_OS2 0x14 /* Again OS/2 is like NT */
311 #define ARCH_SAMBA 0x20
313 #define ARCH_ALL 0x3F
315 /* List of supported protocols, most desired first */
319 int (*proto_reply_fn
)(char *);
321 } supported_protocols
[] = {
322 {"NT LANMAN 1.0", "NT1", reply_nt1
, PROTOCOL_NT1
},
323 {"NT LM 0.12", "NT1", reply_nt1
, PROTOCOL_NT1
},
324 {"LM1.2X002", "LANMAN2", reply_lanman2
, PROTOCOL_LANMAN2
},
325 {"Samba", "LANMAN2", reply_lanman2
, PROTOCOL_LANMAN2
},
326 {"DOS LM1.2X002", "LANMAN2", reply_lanman2
, PROTOCOL_LANMAN2
},
327 {"LANMAN1.0", "LANMAN1", reply_lanman1
, PROTOCOL_LANMAN1
},
328 {"MICROSOFT NETWORKS 3.0", "LANMAN1", reply_lanman1
, PROTOCOL_LANMAN1
},
329 {"MICROSOFT NETWORKS 1.03", "COREPLUS", reply_coreplus
, PROTOCOL_COREPLUS
},
330 {"PC NETWORK PROGRAM 1.0", "CORE", reply_corep
, PROTOCOL_CORE
},
335 /****************************************************************************
337 ****************************************************************************/
338 int reply_negprot(connection_struct
*conn
,
339 char *inbuf
,char *outbuf
, int dum_size
,
342 int outsize
= set_message(outbuf
,1,0,True
);
347 int bcc
= SVAL(smb_buf(inbuf
),-2);
349 START_PROFILE(SMBnegprot
);
351 p
= smb_buf(inbuf
)+1;
352 while (p
< (smb_buf(inbuf
) + bcc
))
355 DEBUG(3,("Requested protocol [%s]\n",p
));
356 if (strcsequal(p
,"Windows for Workgroups 3.1a"))
357 arch
&= ( ARCH_WFWG
| ARCH_WIN95
| ARCH_WINNT
| ARCH_WIN2K
);
358 else if (strcsequal(p
,"DOS LM1.2X002"))
359 arch
&= ( ARCH_WFWG
| ARCH_WIN95
);
360 else if (strcsequal(p
,"DOS LANMAN2.1"))
361 arch
&= ( ARCH_WFWG
| ARCH_WIN95
);
362 else if (strcsequal(p
,"NT LM 0.12"))
363 arch
&= ( ARCH_WIN95
| ARCH_WINNT
| ARCH_WIN2K
);
364 else if (strcsequal(p
,"LANMAN2.1"))
365 arch
&= ( ARCH_WINNT
| ARCH_WIN2K
| ARCH_OS2
);
366 else if (strcsequal(p
,"LM1.2X002"))
367 arch
&= ( ARCH_WINNT
| ARCH_WIN2K
| ARCH_OS2
);
368 else if (strcsequal(p
,"MICROSOFT NETWORKS 1.03"))
370 else if (strcsequal(p
,"XENIX CORE"))
371 arch
&= ( ARCH_WINNT
| ARCH_OS2
);
372 else if (strcsequal(p
,"Samba")) {
382 set_remote_arch(RA_SAMBA
);
385 set_remote_arch(RA_WFWG
);
388 set_remote_arch(RA_WIN95
);
391 if(SVAL(inbuf
,smb_flg2
)==FLAGS2_WIN2K_SIGNATURE
)
392 set_remote_arch(RA_WIN2K
);
394 set_remote_arch(RA_WINNT
);
397 set_remote_arch(RA_WIN2K
);
400 set_remote_arch(RA_OS2
);
403 set_remote_arch(RA_UNKNOWN
);
407 /* possibly reload - change of architecture */
408 reload_services(True
);
410 /* a special case to stop password server loops */
411 if (Index
== 1 && strequal(remote_machine
,myhostname()) &&
412 (lp_security()==SEC_SERVER
|| lp_security()==SEC_DOMAIN
))
413 exit_server("Password server loop!");
415 /* Check for protocols, most desirable first */
416 for (protocol
= 0; supported_protocols
[protocol
].proto_name
; protocol
++)
418 p
= smb_buf(inbuf
)+1;
420 if ((supported_protocols
[protocol
].protocol_level
<= lp_maxprotocol()) &&
421 (supported_protocols
[protocol
].protocol_level
>= lp_minprotocol()))
422 while (p
< (smb_buf(inbuf
) + bcc
))
424 if (strequal(p
,supported_protocols
[protocol
].proto_name
))
433 SSVAL(outbuf
,smb_vwv0
,choice
);
435 extern fstring remote_proto
;
436 fstrcpy(remote_proto
,supported_protocols
[protocol
].short_name
);
437 reload_services(True
);
438 outsize
= supported_protocols
[protocol
].proto_reply_fn(outbuf
);
439 DEBUG(3,("Selected protocol %s\n",supported_protocols
[protocol
].proto_name
));
442 DEBUG(0,("No protocol supported !\n"));
444 SSVAL(outbuf
,smb_vwv0
,choice
);
446 DEBUG( 5, ( "negprot index=%d\n", choice
) );
448 END_PROFILE(SMBnegprot
);