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.
26 extern fstring global_myworkgroup
;
27 extern fstring remote_machine
;
29 /****************************************************************************
30 reply for the core protocol
31 ****************************************************************************/
32 static int reply_corep(char *outbuf
)
34 int outsize
= set_message(outbuf
,1,0,True
);
36 Protocol
= PROTOCOL_CORE
;
42 /****************************************************************************
43 reply for the coreplus protocol
44 ****************************************************************************/
45 static int reply_coreplus(char *outbuf
)
47 int raw
= (lp_readraw()?1:0) | (lp_writeraw()?2:0);
48 int outsize
= set_message(outbuf
,13,0,True
);
49 SSVAL(outbuf
,smb_vwv5
,raw
); /* tell redirector we support
50 readbraw and writebraw (possibly) */
51 /* Reply, SMBlockread, SMBwritelock supported. */
52 SCVAL(outbuf
,smb_flg
,FLAG_REPLY
|FLAG_SUPPORT_LOCKREAD
);
53 SSVAL(outbuf
,smb_vwv1
,0x1); /* user level security, don't encrypt */
55 Protocol
= PROTOCOL_COREPLUS
;
61 /****************************************************************************
62 reply for the lanman 1.0 protocol
63 ****************************************************************************/
64 static int reply_lanman1(char *outbuf
)
66 int raw
= (lp_readraw()?1:0) | (lp_writeraw()?2:0);
68 BOOL doencrypt
= SMBENCRYPT();
69 time_t t
= time(NULL
);
71 if (lp_security()>=SEC_USER
) secword
|= 1;
72 if (doencrypt
) secword
|= 2;
74 set_message(outbuf
,13,doencrypt
?8:0,True
);
75 SSVAL(outbuf
,smb_vwv1
,secword
);
76 /* Create a token value and add it to the outgoing packet. */
78 generate_next_challenge(smb_buf(outbuf
));
80 Protocol
= PROTOCOL_LANMAN1
;
82 /* Reply, SMBlockread, SMBwritelock supported. */
83 SCVAL(outbuf
,smb_flg
,FLAG_REPLY
|FLAG_SUPPORT_LOCKREAD
);
84 SSVAL(outbuf
,smb_vwv2
,max_recv
);
85 SSVAL(outbuf
,smb_vwv3
,lp_maxmux()); /* maxmux */
86 SSVAL(outbuf
,smb_vwv4
,1);
87 SSVAL(outbuf
,smb_vwv5
,raw
); /* tell redirector we support
88 readbraw writebraw (possibly) */
89 SIVAL(outbuf
,smb_vwv6
,sys_getpid());
90 SSVAL(outbuf
,smb_vwv10
, TimeDiff(t
)/60);
92 put_dos_date(outbuf
,smb_vwv8
,t
);
94 return (smb_len(outbuf
)+4);
98 /****************************************************************************
99 reply for the lanman 2.0 protocol
100 ****************************************************************************/
101 static int reply_lanman2(char *outbuf
)
103 int raw
= (lp_readraw()?1:0) | (lp_writeraw()?2:0);
105 BOOL doencrypt
= SMBENCRYPT();
106 time_t t
= time(NULL
);
107 struct cli_state
*cli
= NULL
;
111 if (lp_security() == SEC_SERVER
) {
112 cli
= server_cryptkey();
116 DEBUG(3,("using password server validation\n"));
117 doencrypt
= ((cli
->sec_mode
& 2) != 0);
120 if (lp_security()>=SEC_USER
) secword
|= 1;
121 if (doencrypt
) secword
|= 2;
126 generate_next_challenge(cryptkey
);
128 memcpy(cryptkey
, cli
->cryptkey
, 8);
129 set_challenge(cli
->cryptkey
);
133 set_message(outbuf
,13,crypt_len
,True
);
134 SSVAL(outbuf
,smb_vwv1
,secword
);
135 SIVAL(outbuf
,smb_vwv6
,sys_getpid());
137 memcpy(smb_buf(outbuf
), cryptkey
, 8);
139 Protocol
= PROTOCOL_LANMAN2
;
141 /* Reply, SMBlockread, SMBwritelock supported. */
142 SCVAL(outbuf
,smb_flg
,FLAG_REPLY
|FLAG_SUPPORT_LOCKREAD
);
143 SSVAL(outbuf
,smb_vwv2
,max_recv
);
144 SSVAL(outbuf
,smb_vwv3
,lp_maxmux());
145 SSVAL(outbuf
,smb_vwv4
,1);
146 SSVAL(outbuf
,smb_vwv5
,raw
); /* readbraw and/or writebraw */
147 SSVAL(outbuf
,smb_vwv10
, TimeDiff(t
)/60);
148 put_dos_date(outbuf
,smb_vwv8
,t
);
150 return (smb_len(outbuf
)+4);
154 /****************************************************************************
155 reply for the nt protocol
156 ****************************************************************************/
157 static int reply_nt1(char *outbuf
)
159 /* dual names + lock_and_read + nt SMBs + remote API calls */
160 int capabilities
= CAP_NT_FIND
|CAP_LOCK_AND_READ
|CAP_LEVEL_II_OPLOCKS
|
161 (lp_nt_status_support() ? CAP_STATUS32
: 0)|
162 (lp_unix_extensions() ? CAP_UNIX
: 0) |
163 (lp_nt_smb_support() ? CAP_NT_SMBS
| CAP_RPC_REMOTE_APIS
: 0) |
164 ((lp_large_readwrite() && (SMB_OFF_T_BITS
== 64)) ? CAP_LARGE_READX
| CAP_LARGE_WRITEX
| CAP_W2K_SMBS
: 0) |
165 (SMB_OFF_T_BITS
== 64 ? CAP_LARGE_FILES
: 0);
167 BOOL doencrypt
= SMBENCRYPT();
168 time_t t
= time(NULL
);
170 struct cli_state
*cli
= NULL
;
174 if (lp_security() == SEC_SERVER
) {
175 cli
= server_cryptkey();
179 DEBUG(3,("using password server validation\n"));
180 doencrypt
= ((cli
->sec_mode
& 2) != 0);
186 generate_next_challenge(cryptkey
);
188 memcpy(cryptkey
, cli
->cryptkey
, 8);
189 set_challenge(cli
->cryptkey
);
193 if (lp_readraw() && lp_writeraw()) {
194 capabilities
|= CAP_RAW_MODE
;
199 capabilities
|= CAP_DFS
;
202 if (lp_security() >= SEC_USER
) secword
|= 1;
203 if (doencrypt
) secword
|= 2;
205 /* decide where (if) to put the encryption challenge, and
206 follow it with the OEM'd domain name
208 data_len
= crypt_len
+ strlen(global_myworkgroup
) + 1;
210 set_message(outbuf
,17,data_len
,True
);
211 pstrcpy(smb_buf(outbuf
)+crypt_len
, global_myworkgroup
);
213 SCVAL(outbuf
,smb_vwv1
,secword
);
214 SSVALS(outbuf
,smb_vwv16
+1,crypt_len
);
216 memcpy(smb_buf(outbuf
), cryptkey
, 8);
218 Protocol
= PROTOCOL_NT1
;
220 SSVAL(outbuf
,smb_vwv1
+1,lp_maxmux()); /* maxmpx */
221 SSVAL(outbuf
,smb_vwv2
+1,1); /* num vcs */
222 SIVAL(outbuf
,smb_vwv3
+1,max_recv
); /* max buffer. LOTS! */
223 SIVAL(outbuf
,smb_vwv5
+1,0x10000); /* raw size. full 64k */
224 SIVAL(outbuf
,smb_vwv7
+1,sys_getpid()); /* session key */
225 SIVAL(outbuf
,smb_vwv9
+1,capabilities
); /* capabilities */
226 put_long_date(outbuf
+smb_vwv11
+1,t
);
227 SSVALS(outbuf
,smb_vwv15
+1,TimeDiff(t
)/60);
228 SSVAL(outbuf
,smb_vwv17
,data_len
); /* length of challenge+domain strings */
230 return (smb_len(outbuf
)+4);
233 /* these are the protocol lists used for auto architecture detection:
236 protocol [PC NETWORK PROGRAM 1.0]
237 protocol [XENIX CORE]
238 protocol [MICROSOFT NETWORKS 1.03]
240 protocol [Windows for Workgroups 3.1a]
243 protocol [NT LM 0.12]
246 protocol [PC NETWORK PROGRAM 1.0]
247 protocol [XENIX CORE]
248 protocol [MICROSOFT NETWORKS 1.03]
250 protocol [Windows for Workgroups 3.1a]
253 protocol [NT LM 0.12]
256 protocol [PC NETWORK PROGRAM 1.0]
258 protocol [Windows for Workgroups 3.1a]
261 protocol [NT LM 0.12]
264 protocol [PC NETWORK PROGRAM 1.0]
265 protocol [XENIX CORE]
272 * Modified to recognize the architecture of the remote machine better.
274 * This appears to be the matrix of which protocol is used by which
276 Protocol WfWg Win95 WinNT Win2K OS/2
277 PC NETWORK PROGRAM 1.0 1 1 1 1 1
279 MICROSOFT NETWORKS 3.0 2 2
281 MICROSOFT NETWORKS 1.03 3
284 Windows for Workgroups 3.1a 5 5 5 3
289 * tim@fsg.com 09/29/95
290 * Win2K added by matty 17/7/99
293 #define ARCH_WFWG 0x3 /* This is a fudge because WfWg is like Win95 */
294 #define ARCH_WIN95 0x2
295 #define ARCH_WINNT 0x4
296 #define ARCH_WIN2K 0xC /* Win2K is like NT */
297 #define ARCH_OS2 0x14 /* Again OS/2 is like NT */
298 #define ARCH_SAMBA 0x20
300 #define ARCH_ALL 0x3F
302 /* List of supported protocols, most desired first */
306 int (*proto_reply_fn
)(char *);
308 } supported_protocols
[] = {
309 {"NT LANMAN 1.0", "NT1", reply_nt1
, PROTOCOL_NT1
},
310 {"NT LM 0.12", "NT1", reply_nt1
, PROTOCOL_NT1
},
311 {"LM1.2X002", "LANMAN2", reply_lanman2
, PROTOCOL_LANMAN2
},
312 {"Samba", "LANMAN2", reply_lanman2
, PROTOCOL_LANMAN2
},
313 {"DOS LM1.2X002", "LANMAN2", reply_lanman2
, PROTOCOL_LANMAN2
},
314 {"LANMAN1.0", "LANMAN1", reply_lanman1
, PROTOCOL_LANMAN1
},
315 {"MICROSOFT NETWORKS 3.0", "LANMAN1", reply_lanman1
, PROTOCOL_LANMAN1
},
316 {"MICROSOFT NETWORKS 1.03", "COREPLUS", reply_coreplus
, PROTOCOL_COREPLUS
},
317 {"PC NETWORK PROGRAM 1.0", "CORE", reply_corep
, PROTOCOL_CORE
},
322 /****************************************************************************
324 ****************************************************************************/
325 int reply_negprot(connection_struct
*conn
,
326 char *inbuf
,char *outbuf
, int dum_size
,
329 int outsize
= set_message(outbuf
,1,0,True
);
334 int bcc
= SVAL(smb_buf(inbuf
),-2);
336 START_PROFILE(SMBnegprot
);
338 p
= smb_buf(inbuf
)+1;
339 while (p
< (smb_buf(inbuf
) + bcc
))
342 DEBUG(3,("Requested protocol [%s]\n",p
));
343 if (strcsequal(p
,"Windows for Workgroups 3.1a"))
344 arch
&= ( ARCH_WFWG
| ARCH_WIN95
| ARCH_WINNT
| ARCH_WIN2K
);
345 else if (strcsequal(p
,"DOS LM1.2X002"))
346 arch
&= ( ARCH_WFWG
| ARCH_WIN95
);
347 else if (strcsequal(p
,"DOS LANMAN2.1"))
348 arch
&= ( ARCH_WFWG
| ARCH_WIN95
);
349 else if (strcsequal(p
,"NT LM 0.12"))
350 arch
&= ( ARCH_WIN95
| ARCH_WINNT
| ARCH_WIN2K
);
351 else if (strcsequal(p
,"LANMAN2.1"))
352 arch
&= ( ARCH_WINNT
| ARCH_WIN2K
| ARCH_OS2
);
353 else if (strcsequal(p
,"LM1.2X002"))
354 arch
&= ( ARCH_WINNT
| ARCH_WIN2K
| ARCH_OS2
);
355 else if (strcsequal(p
,"MICROSOFT NETWORKS 1.03"))
357 else if (strcsequal(p
,"XENIX CORE"))
358 arch
&= ( ARCH_WINNT
| ARCH_OS2
);
359 else if (strcsequal(p
,"Samba")) {
369 set_remote_arch(RA_SAMBA
);
372 set_remote_arch(RA_WFWG
);
375 set_remote_arch(RA_WIN95
);
378 if(SVAL(inbuf
,smb_flg2
)==FLAGS2_WIN2K_SIGNATURE
)
379 set_remote_arch(RA_WIN2K
);
381 set_remote_arch(RA_WINNT
);
384 set_remote_arch(RA_WIN2K
);
387 set_remote_arch(RA_OS2
);
390 set_remote_arch(RA_UNKNOWN
);
394 /* possibly reload - change of architecture */
395 reload_services(True
);
397 /* a special case to stop password server loops */
398 if (Index
== 1 && strequal(remote_machine
,myhostname()) &&
399 (lp_security()==SEC_SERVER
|| lp_security()==SEC_DOMAIN
))
400 exit_server("Password server loop!");
402 /* Check for protocols, most desirable first */
403 for (protocol
= 0; supported_protocols
[protocol
].proto_name
; protocol
++)
405 p
= smb_buf(inbuf
)+1;
407 if ((supported_protocols
[protocol
].protocol_level
<= lp_maxprotocol()) &&
408 (supported_protocols
[protocol
].protocol_level
>= lp_minprotocol()))
409 while (p
< (smb_buf(inbuf
) + bcc
))
411 if (strequal(p
,supported_protocols
[protocol
].proto_name
))
420 SSVAL(outbuf
,smb_vwv0
,choice
);
422 extern fstring remote_proto
;
423 fstrcpy(remote_proto
,supported_protocols
[protocol
].short_name
);
424 reload_services(True
);
425 outsize
= supported_protocols
[protocol
].proto_reply_fn(outbuf
);
426 DEBUG(3,("Selected protocol %s\n",supported_protocols
[protocol
].proto_name
));
429 DEBUG(0,("No protocol supported !\n"));
431 SSVAL(outbuf
,smb_vwv0
,choice
);
433 DEBUG( 5, ( "negprot index=%d\n", choice
) );
435 END_PROFILE(SMBnegprot
);