s3-auth: smbd needs auth.h
[Samba.git] / source3 / smbd / negprot.c
blobad058657dd089fbf67a8d781c53644f9eec4970c
1 /*
2 Unix SMB/CIFS implementation.
3 negprot reply code
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) Volker Lendecke 2007
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 3 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, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "smbd/smbd.h"
23 #include "smbd/globals.h"
24 #include "../libcli/auth/spnego.h"
25 #include "serverid.h"
26 #include "auth.h"
28 extern fstring remote_proto;
30 static void get_challenge(struct smbd_server_connection *sconn, uint8 buff[8])
32 NTSTATUS nt_status;
34 /* We might be called more than once, multiple negprots are
35 * permitted */
36 if (sconn->smb1.negprot.auth_context) {
37 DEBUG(3, ("get challenge: is this a secondary negprot? "
38 "sconn->negprot.auth_context is non-NULL!\n"));
39 TALLOC_FREE(sconn->smb1.negprot.auth_context);
42 DEBUG(10, ("get challenge: creating negprot_global_auth_context\n"));
43 nt_status = make_auth_context_subsystem(
44 sconn, &sconn->smb1.negprot.auth_context);
45 if (!NT_STATUS_IS_OK(nt_status)) {
46 DEBUG(0, ("make_auth_context_subsystem returned %s",
47 nt_errstr(nt_status)));
48 smb_panic("cannot make_negprot_global_auth_context!");
50 DEBUG(10, ("get challenge: getting challenge\n"));
51 sconn->smb1.negprot.auth_context->get_ntlm_challenge(
52 sconn->smb1.negprot.auth_context, buff);
55 /****************************************************************************
56 Reply for the core protocol.
57 ****************************************************************************/
59 static void reply_corep(struct smb_request *req, uint16 choice)
61 reply_outbuf(req, 1, 0);
62 SSVAL(req->outbuf, smb_vwv0, choice);
64 set_Protocol(PROTOCOL_CORE);
67 /****************************************************************************
68 Reply for the coreplus protocol.
69 ****************************************************************************/
71 static void reply_coreplus(struct smb_request *req, uint16 choice)
73 int raw = (lp_readraw()?1:0) | (lp_writeraw()?2:0);
75 reply_outbuf(req, 13, 0);
77 SSVAL(req->outbuf,smb_vwv0,choice);
78 SSVAL(req->outbuf,smb_vwv5,raw); /* tell redirector we support
79 readbraw and writebraw (possibly) */
80 /* Reply, SMBlockread, SMBwritelock supported. */
81 SCVAL(req->outbuf,smb_flg,FLAG_REPLY|FLAG_SUPPORT_LOCKREAD);
82 SSVAL(req->outbuf,smb_vwv1,0x1); /* user level security, don't
83 * encrypt */
84 set_Protocol(PROTOCOL_COREPLUS);
87 /****************************************************************************
88 Reply for the lanman 1.0 protocol.
89 ****************************************************************************/
91 static void reply_lanman1(struct smb_request *req, uint16 choice)
93 int raw = (lp_readraw()?1:0) | (lp_writeraw()?2:0);
94 int secword=0;
95 time_t t = time(NULL);
96 struct smbd_server_connection *sconn = req->sconn;
98 sconn->smb1.negprot.encrypted_passwords = lp_encrypted_passwords();
100 if (lp_security()>=SEC_USER) {
101 secword |= NEGOTIATE_SECURITY_USER_LEVEL;
103 if (sconn->smb1.negprot.encrypted_passwords) {
104 secword |= NEGOTIATE_SECURITY_CHALLENGE_RESPONSE;
107 reply_outbuf(req, 13, sconn->smb1.negprot.encrypted_passwords?8:0);
109 SSVAL(req->outbuf,smb_vwv0,choice);
110 SSVAL(req->outbuf,smb_vwv1,secword);
111 /* Create a token value and add it to the outgoing packet. */
112 if (sconn->smb1.negprot.encrypted_passwords) {
113 get_challenge(sconn, (uint8 *)smb_buf(req->outbuf));
114 SSVAL(req->outbuf,smb_vwv11, 8);
117 set_Protocol(PROTOCOL_LANMAN1);
119 /* Reply, SMBlockread, SMBwritelock supported. */
120 SCVAL(req->outbuf,smb_flg,FLAG_REPLY|FLAG_SUPPORT_LOCKREAD);
121 SSVAL(req->outbuf,smb_vwv2,sconn->smb1.negprot.max_recv);
122 SSVAL(req->outbuf,smb_vwv3,lp_maxmux()); /* maxmux */
123 SSVAL(req->outbuf,smb_vwv4,1);
124 SSVAL(req->outbuf,smb_vwv5,raw); /* tell redirector we support
125 readbraw writebraw (possibly) */
126 SIVAL(req->outbuf,smb_vwv6,sys_getpid());
127 SSVAL(req->outbuf,smb_vwv10, set_server_zone_offset(t)/60);
129 srv_put_dos_date((char *)req->outbuf,smb_vwv8,t);
131 return;
134 /****************************************************************************
135 Reply for the lanman 2.0 protocol.
136 ****************************************************************************/
138 static void reply_lanman2(struct smb_request *req, uint16 choice)
140 int raw = (lp_readraw()?1:0) | (lp_writeraw()?2:0);
141 int secword=0;
142 time_t t = time(NULL);
143 struct smbd_server_connection *sconn = req->sconn;
145 sconn->smb1.negprot.encrypted_passwords = lp_encrypted_passwords();
147 if (lp_security()>=SEC_USER) {
148 secword |= NEGOTIATE_SECURITY_USER_LEVEL;
150 if (sconn->smb1.negprot.encrypted_passwords) {
151 secword |= NEGOTIATE_SECURITY_CHALLENGE_RESPONSE;
154 reply_outbuf(req, 13, sconn->smb1.negprot.encrypted_passwords?8:0);
156 SSVAL(req->outbuf,smb_vwv0,choice);
157 SSVAL(req->outbuf,smb_vwv1,secword);
158 SIVAL(req->outbuf,smb_vwv6,sys_getpid());
160 /* Create a token value and add it to the outgoing packet. */
161 if (sconn->smb1.negprot.encrypted_passwords) {
162 get_challenge(sconn, (uint8 *)smb_buf(req->outbuf));
163 SSVAL(req->outbuf,smb_vwv11, 8);
166 set_Protocol(PROTOCOL_LANMAN2);
168 /* Reply, SMBlockread, SMBwritelock supported. */
169 SCVAL(req->outbuf,smb_flg,FLAG_REPLY|FLAG_SUPPORT_LOCKREAD);
170 SSVAL(req->outbuf,smb_vwv2,sconn->smb1.negprot.max_recv);
171 SSVAL(req->outbuf,smb_vwv3,lp_maxmux());
172 SSVAL(req->outbuf,smb_vwv4,1);
173 SSVAL(req->outbuf,smb_vwv5,raw); /* readbraw and/or writebraw */
174 SSVAL(req->outbuf,smb_vwv10, set_server_zone_offset(t)/60);
175 srv_put_dos_date((char *)req->outbuf,smb_vwv8,t);
178 /****************************************************************************
179 Generate the spnego negprot reply blob. Return the number of bytes used.
180 ****************************************************************************/
182 DATA_BLOB negprot_spnego(TALLOC_CTX *ctx, struct smbd_server_connection *sconn)
184 DATA_BLOB blob = data_blob_null;
185 DATA_BLOB blob_out = data_blob_null;
186 nstring dos_name;
187 fstring unix_name;
188 #ifdef DEVELOPER
189 size_t slen;
190 #endif
191 const char *OIDs_krb5[] = {OID_KERBEROS5,
192 OID_KERBEROS5_OLD,
193 OID_NTLMSSP,
194 NULL};
195 const char *OIDs_ntlm[] = {OID_NTLMSSP, NULL};
197 sconn->smb1.negprot.spnego = true;
198 /* strangely enough, NT does not sent the single OID NTLMSSP when
199 not a ADS member, it sends no OIDs at all
201 OLD COMMENT : "we can't do this until we teach our sesssion setup parser to know
202 about raw NTLMSSP (clients send no ASN.1 wrapping if we do this)"
204 Our sessionsetup code now handles raw NTLMSSP connects, so we can go
205 back to doing what W2K3 does here. This is needed to make PocketPC 2003
206 CIFS connections work with SPNEGO. See bugzilla bugs #1828 and #3133
207 for details. JRA.
211 if (lp_security() != SEC_ADS && !USE_KERBEROS_KEYTAB) {
212 #if 0
213 /* Code for PocketPC client */
214 blob = data_blob(guid, 16);
215 #else
216 /* Code for standalone WXP client */
217 blob = spnego_gen_negTokenInit(ctx, OIDs_ntlm, NULL, "NONE");
218 #endif
219 } else if (!lp_send_spnego_principal()) {
220 /* By default, Windows 2008 and later sends not_defined_in_RFC4178@please_ignore */
221 blob = spnego_gen_negTokenInit(ctx, OIDs_krb5, NULL, ADS_IGNORE_PRINCIPAL);
222 } else {
223 fstring myname;
224 char *host_princ_s = NULL;
225 name_to_fqdn(myname, global_myname());
226 strlower_m(myname);
227 if (asprintf(&host_princ_s, "cifs/%s@%s", myname, lp_realm())
228 == -1) {
229 return data_blob_null;
231 blob = spnego_gen_negTokenInit(ctx, OIDs_krb5, NULL, host_princ_s);
232 SAFE_FREE(host_princ_s);
235 blob_out = data_blob_talloc(ctx, NULL, 16 + blob.length);
236 if (blob_out.data == NULL) {
237 data_blob_free(&blob);
238 return data_blob_null;
241 memset(blob_out.data, '\0', 16);
243 safe_strcpy(unix_name, global_myname(), sizeof(unix_name)-1);
244 strlower_m(unix_name);
245 push_ascii_nstring(dos_name, unix_name);
246 safe_strcpy((char *)blob_out.data, dos_name, 16);
248 #ifdef DEVELOPER
249 /* Fix valgrind 'uninitialized bytes' issue. */
250 slen = strlen(dos_name);
251 if (slen < 16) {
252 memset(blob_out.data+slen, '\0', 16 - slen);
254 #endif
256 memcpy(&blob_out.data[16], blob.data, blob.length);
258 data_blob_free(&blob);
260 return blob_out;
263 /****************************************************************************
264 Reply for the nt protocol.
265 ****************************************************************************/
267 static void reply_nt1(struct smb_request *req, uint16 choice)
269 /* dual names + lock_and_read + nt SMBs + remote API calls */
270 int capabilities = CAP_NT_FIND|CAP_LOCK_AND_READ|
271 CAP_LEVEL_II_OPLOCKS;
273 int secword=0;
274 bool negotiate_spnego = False;
275 struct timespec ts;
276 ssize_t ret;
277 struct smbd_server_connection *sconn = req->sconn;
279 sconn->smb1.negprot.encrypted_passwords = lp_encrypted_passwords();
281 /* Check the flags field to see if this is Vista.
282 WinXP sets it and Vista does not. But we have to
283 distinguish from NT which doesn't set it either. */
285 if ( (req->flags2 & FLAGS2_EXTENDED_SECURITY) &&
286 ((req->flags2 & FLAGS2_UNKNOWN_BIT4) == 0) )
288 if (get_remote_arch() != RA_SAMBA) {
289 set_remote_arch( RA_VISTA );
293 reply_outbuf(req,17,0);
295 /* do spnego in user level security if the client
296 supports it and we can do encrypted passwords */
298 if (sconn->smb1.negprot.encrypted_passwords &&
299 (lp_security() != SEC_SHARE) &&
300 lp_use_spnego() &&
301 (req->flags2 & FLAGS2_EXTENDED_SECURITY)) {
302 negotiate_spnego = True;
303 capabilities |= CAP_EXTENDED_SECURITY;
304 add_to_common_flags2(FLAGS2_EXTENDED_SECURITY);
305 /* Ensure FLAGS2_EXTENDED_SECURITY gets set in this reply
306 (already partially constructed. */
307 SSVAL(req->outbuf, smb_flg2,
308 req->flags2 | FLAGS2_EXTENDED_SECURITY);
311 capabilities |= CAP_NT_SMBS|CAP_RPC_REMOTE_APIS|CAP_UNICODE;
313 if (lp_unix_extensions()) {
314 capabilities |= CAP_UNIX;
317 if (lp_large_readwrite() && (SMB_OFF_T_BITS == 64))
318 capabilities |= CAP_LARGE_READX|CAP_LARGE_WRITEX|CAP_W2K_SMBS;
320 if (SMB_OFF_T_BITS == 64)
321 capabilities |= CAP_LARGE_FILES;
323 if (lp_readraw() && lp_writeraw())
324 capabilities |= CAP_RAW_MODE;
326 if (lp_nt_status_support())
327 capabilities |= CAP_STATUS32;
329 if (lp_host_msdfs())
330 capabilities |= CAP_DFS;
332 if (lp_security() >= SEC_USER) {
333 secword |= NEGOTIATE_SECURITY_USER_LEVEL;
335 if (sconn->smb1.negprot.encrypted_passwords) {
336 secword |= NEGOTIATE_SECURITY_CHALLENGE_RESPONSE;
339 if (lp_server_signing()) {
340 if (lp_security() >= SEC_USER) {
341 secword |= NEGOTIATE_SECURITY_SIGNATURES_ENABLED;
342 /* No raw mode with smb signing. */
343 capabilities &= ~CAP_RAW_MODE;
344 if (lp_server_signing() == Required)
345 secword |=NEGOTIATE_SECURITY_SIGNATURES_REQUIRED;
346 srv_set_signing_negotiated(sconn);
347 } else {
348 DEBUG(0,("reply_nt1: smb signing is incompatible with share level security !\n"));
349 if (lp_server_signing() == Required) {
350 exit_server_cleanly("reply_nt1: smb signing required and share level security selected.");
355 SSVAL(req->outbuf,smb_vwv0,choice);
356 SCVAL(req->outbuf,smb_vwv1,secword);
358 set_Protocol(PROTOCOL_NT1);
360 SSVAL(req->outbuf,smb_vwv1+1,lp_maxmux()); /* maxmpx */
361 SSVAL(req->outbuf,smb_vwv2+1,1); /* num vcs */
362 SIVAL(req->outbuf,smb_vwv3+1,
363 sconn->smb1.negprot.max_recv); /* max buffer. LOTS! */
364 SIVAL(req->outbuf,smb_vwv5+1,0x10000); /* raw size. full 64k */
365 SIVAL(req->outbuf,smb_vwv7+1,sys_getpid()); /* session key */
366 SIVAL(req->outbuf,smb_vwv9+1,capabilities); /* capabilities */
367 clock_gettime(CLOCK_REALTIME,&ts);
368 put_long_date_timespec(TIMESTAMP_SET_NT_OR_BETTER,(char *)req->outbuf+smb_vwv11+1,ts);
369 SSVALS(req->outbuf,smb_vwv15+1,set_server_zone_offset(ts.tv_sec)/60);
371 if (!negotiate_spnego) {
372 /* Create a token value and add it to the outgoing packet. */
373 if (sconn->smb1.negprot.encrypted_passwords) {
374 uint8 chal[8];
375 /* note that we do not send a challenge at all if
376 we are using plaintext */
377 get_challenge(sconn, chal);
378 ret = message_push_blob(
379 &req->outbuf, data_blob_const(chal, sizeof(chal)));
380 if (ret == -1) {
381 DEBUG(0, ("Could not push challenge\n"));
382 reply_nterror(req, NT_STATUS_NO_MEMORY);
383 return;
385 SCVAL(req->outbuf, smb_vwv16+1, ret);
387 ret = message_push_string(&req->outbuf, lp_workgroup(),
388 STR_UNICODE|STR_TERMINATE
389 |STR_NOALIGN);
390 if (ret == -1) {
391 DEBUG(0, ("Could not push workgroup string\n"));
392 reply_nterror(req, NT_STATUS_NO_MEMORY);
393 return;
395 DEBUG(3,("not using SPNEGO\n"));
396 } else {
397 DATA_BLOB spnego_blob = negprot_spnego(req, req->sconn);
399 if (spnego_blob.data == NULL) {
400 reply_nterror(req, NT_STATUS_NO_MEMORY);
401 return;
404 ret = message_push_blob(&req->outbuf, spnego_blob);
405 if (ret == -1) {
406 DEBUG(0, ("Could not push spnego blob\n"));
407 reply_nterror(req, NT_STATUS_NO_MEMORY);
408 return;
410 data_blob_free(&spnego_blob);
412 SCVAL(req->outbuf,smb_vwv16+1, 0);
413 DEBUG(3,("using SPNEGO\n"));
416 return;
419 /* these are the protocol lists used for auto architecture detection:
421 WinNT 3.51:
422 protocol [PC NETWORK PROGRAM 1.0]
423 protocol [XENIX CORE]
424 protocol [MICROSOFT NETWORKS 1.03]
425 protocol [LANMAN1.0]
426 protocol [Windows for Workgroups 3.1a]
427 protocol [LM1.2X002]
428 protocol [LANMAN2.1]
429 protocol [NT LM 0.12]
431 Win95:
432 protocol [PC NETWORK PROGRAM 1.0]
433 protocol [XENIX CORE]
434 protocol [MICROSOFT NETWORKS 1.03]
435 protocol [LANMAN1.0]
436 protocol [Windows for Workgroups 3.1a]
437 protocol [LM1.2X002]
438 protocol [LANMAN2.1]
439 protocol [NT LM 0.12]
441 Win2K:
442 protocol [PC NETWORK PROGRAM 1.0]
443 protocol [LANMAN1.0]
444 protocol [Windows for Workgroups 3.1a]
445 protocol [LM1.2X002]
446 protocol [LANMAN2.1]
447 protocol [NT LM 0.12]
449 Vista:
450 protocol [PC NETWORK PROGRAM 1.0]
451 protocol [LANMAN1.0]
452 protocol [Windows for Workgroups 3.1a]
453 protocol [LM1.2X002]
454 protocol [LANMAN2.1]
455 protocol [NT LM 0.12]
456 protocol [SMB 2.001]
458 OS/2:
459 protocol [PC NETWORK PROGRAM 1.0]
460 protocol [XENIX CORE]
461 protocol [LANMAN1.0]
462 protocol [LM1.2X002]
463 protocol [LANMAN2.1]
467 * Modified to recognize the architecture of the remote machine better.
469 * This appears to be the matrix of which protocol is used by which
470 * MS product.
471 Protocol WfWg Win95 WinNT Win2K OS/2 Vista
472 PC NETWORK PROGRAM 1.0 1 1 1 1 1 1
473 XENIX CORE 2 2
474 MICROSOFT NETWORKS 3.0 2 2
475 DOS LM1.2X002 3 3
476 MICROSOFT NETWORKS 1.03 3
477 DOS LANMAN2.1 4 4
478 LANMAN1.0 4 2 3 2
479 Windows for Workgroups 3.1a 5 5 5 3 3
480 LM1.2X002 6 4 4 4
481 LANMAN2.1 7 5 5 5
482 NT LM 0.12 6 8 6 6
483 SMB 2.001 7
485 * tim@fsg.com 09/29/95
486 * Win2K added by matty 17/7/99
489 #define ARCH_WFWG 0x3 /* This is a fudge because WfWg is like Win95 */
490 #define ARCH_WIN95 0x2
491 #define ARCH_WINNT 0x4
492 #define ARCH_WIN2K 0xC /* Win2K is like NT */
493 #define ARCH_OS2 0x14 /* Again OS/2 is like NT */
494 #define ARCH_SAMBA 0x20
495 #define ARCH_CIFSFS 0x40
496 #define ARCH_VISTA 0x8C /* Vista is like XP/2K */
498 #define ARCH_ALL 0x7F
500 /* List of supported protocols, most desired first */
501 static const struct {
502 const char *proto_name;
503 const char *short_name;
504 void (*proto_reply_fn)(struct smb_request *req, uint16 choice);
505 int protocol_level;
506 } supported_protocols[] = {
507 {"SMB 2.002", "SMB2", reply_smb2002, PROTOCOL_SMB2},
508 {"NT LANMAN 1.0", "NT1", reply_nt1, PROTOCOL_NT1},
509 {"NT LM 0.12", "NT1", reply_nt1, PROTOCOL_NT1},
510 {"POSIX 2", "NT1", reply_nt1, PROTOCOL_NT1},
511 {"LANMAN2.1", "LANMAN2", reply_lanman2, PROTOCOL_LANMAN2},
512 {"LM1.2X002", "LANMAN2", reply_lanman2, PROTOCOL_LANMAN2},
513 {"Samba", "LANMAN2", reply_lanman2, PROTOCOL_LANMAN2},
514 {"DOS LM1.2X002", "LANMAN2", reply_lanman2, PROTOCOL_LANMAN2},
515 {"LANMAN1.0", "LANMAN1", reply_lanman1, PROTOCOL_LANMAN1},
516 {"MICROSOFT NETWORKS 3.0", "LANMAN1", reply_lanman1, PROTOCOL_LANMAN1},
517 {"MICROSOFT NETWORKS 1.03", "COREPLUS", reply_coreplus, PROTOCOL_COREPLUS},
518 {"PC NETWORK PROGRAM 1.0", "CORE", reply_corep, PROTOCOL_CORE},
519 {NULL,NULL,NULL,0},
522 /****************************************************************************
523 Reply to a negprot.
524 conn POINTER CAN BE NULL HERE !
525 ****************************************************************************/
527 void reply_negprot(struct smb_request *req)
529 int choice= -1;
530 int protocol;
531 const char *p;
532 int arch = ARCH_ALL;
533 int num_cliprotos;
534 char **cliprotos;
535 int i;
536 size_t converted_size;
537 struct smbd_server_connection *sconn = req->sconn;
539 START_PROFILE(SMBnegprot);
541 if (sconn->smb1.negprot.done) {
542 END_PROFILE(SMBnegprot);
543 exit_server_cleanly("multiple negprot's are not permitted");
545 sconn->smb1.negprot.done = true;
547 if (req->buflen == 0) {
548 DEBUG(0, ("negprot got no protocols\n"));
549 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
550 END_PROFILE(SMBnegprot);
551 return;
554 if (req->buf[req->buflen-1] != '\0') {
555 DEBUG(0, ("negprot protocols not 0-terminated\n"));
556 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
557 END_PROFILE(SMBnegprot);
558 return;
561 p = (const char *)req->buf + 1;
563 num_cliprotos = 0;
564 cliprotos = NULL;
566 while (smbreq_bufrem(req, p) > 0) {
568 char **tmp;
570 tmp = TALLOC_REALLOC_ARRAY(talloc_tos(), cliprotos, char *,
571 num_cliprotos+1);
572 if (tmp == NULL) {
573 DEBUG(0, ("talloc failed\n"));
574 TALLOC_FREE(cliprotos);
575 reply_nterror(req, NT_STATUS_NO_MEMORY);
576 END_PROFILE(SMBnegprot);
577 return;
580 cliprotos = tmp;
582 if (!pull_ascii_talloc(cliprotos, &cliprotos[num_cliprotos], p,
583 &converted_size)) {
584 DEBUG(0, ("pull_ascii_talloc failed\n"));
585 TALLOC_FREE(cliprotos);
586 reply_nterror(req, NT_STATUS_NO_MEMORY);
587 END_PROFILE(SMBnegprot);
588 return;
591 DEBUG(3, ("Requested protocol [%s]\n",
592 cliprotos[num_cliprotos]));
594 num_cliprotos += 1;
595 p += strlen(p) + 2;
598 for (i=0; i<num_cliprotos; i++) {
599 if (strcsequal(cliprotos[i], "Windows for Workgroups 3.1a"))
600 arch &= ( ARCH_WFWG | ARCH_WIN95 | ARCH_WINNT
601 | ARCH_WIN2K );
602 else if (strcsequal(cliprotos[i], "DOS LM1.2X002"))
603 arch &= ( ARCH_WFWG | ARCH_WIN95 );
604 else if (strcsequal(cliprotos[i], "DOS LANMAN2.1"))
605 arch &= ( ARCH_WFWG | ARCH_WIN95 );
606 else if (strcsequal(cliprotos[i], "NT LM 0.12"))
607 arch &= ( ARCH_WIN95 | ARCH_WINNT | ARCH_WIN2K
608 | ARCH_CIFSFS);
609 else if (strcsequal(cliprotos[i], "SMB 2.001"))
610 arch = ARCH_VISTA;
611 else if (strcsequal(cliprotos[i], "LANMAN2.1"))
612 arch &= ( ARCH_WINNT | ARCH_WIN2K | ARCH_OS2 );
613 else if (strcsequal(cliprotos[i], "LM1.2X002"))
614 arch &= ( ARCH_WINNT | ARCH_WIN2K | ARCH_OS2 );
615 else if (strcsequal(cliprotos[i], "MICROSOFT NETWORKS 1.03"))
616 arch &= ARCH_WINNT;
617 else if (strcsequal(cliprotos[i], "XENIX CORE"))
618 arch &= ( ARCH_WINNT | ARCH_OS2 );
619 else if (strcsequal(cliprotos[i], "Samba")) {
620 arch = ARCH_SAMBA;
621 break;
622 } else if (strcsequal(cliprotos[i], "POSIX 2")) {
623 arch = ARCH_CIFSFS;
624 break;
628 /* CIFSFS can send one arch only, NT LM 0.12. */
629 if (i == 1 && (arch & ARCH_CIFSFS)) {
630 arch = ARCH_CIFSFS;
633 switch ( arch ) {
634 case ARCH_CIFSFS:
635 set_remote_arch(RA_CIFSFS);
636 break;
637 case ARCH_SAMBA:
638 set_remote_arch(RA_SAMBA);
639 break;
640 case ARCH_WFWG:
641 set_remote_arch(RA_WFWG);
642 break;
643 case ARCH_WIN95:
644 set_remote_arch(RA_WIN95);
645 break;
646 case ARCH_WINNT:
647 if(req->flags2 == FLAGS2_WIN2K_SIGNATURE)
648 set_remote_arch(RA_WIN2K);
649 else
650 set_remote_arch(RA_WINNT);
651 break;
652 case ARCH_WIN2K:
653 /* Vista may have been set in the negprot so don't
654 override it here */
655 if ( get_remote_arch() != RA_VISTA )
656 set_remote_arch(RA_WIN2K);
657 break;
658 case ARCH_VISTA:
659 set_remote_arch(RA_VISTA);
660 break;
661 case ARCH_OS2:
662 set_remote_arch(RA_OS2);
663 break;
664 default:
665 set_remote_arch(RA_UNKNOWN);
666 break;
669 /* possibly reload - change of architecture */
670 reload_services(sconn->msg_ctx, sconn->sock, True);
672 /* moved from the netbios session setup code since we don't have that
673 when the client connects to port 445. Of course there is a small
674 window where we are listening to messages -- jerry */
676 serverid_register(sconn_server_id(sconn),
677 FLAG_MSG_GENERAL|FLAG_MSG_SMBD
678 |FLAG_MSG_PRINT_GENERAL);
680 /* Check for protocols, most desirable first */
681 for (protocol = 0; supported_protocols[protocol].proto_name; protocol++) {
682 i = 0;
683 if ((supported_protocols[protocol].protocol_level <= lp_maxprotocol()) &&
684 (supported_protocols[protocol].protocol_level >= lp_minprotocol()))
685 while (i < num_cliprotos) {
686 if (strequal(cliprotos[i],supported_protocols[protocol].proto_name))
687 choice = i;
688 i++;
690 if(choice != -1)
691 break;
694 if(choice != -1) {
695 fstrcpy(remote_proto,supported_protocols[protocol].short_name);
696 reload_services(sconn->msg_ctx, sconn->sock, True);
697 supported_protocols[protocol].proto_reply_fn(req, choice);
698 DEBUG(3,("Selected protocol %s\n",supported_protocols[protocol].proto_name));
699 } else {
700 DEBUG(0,("No protocol supported !\n"));
701 reply_outbuf(req, 1, 0);
702 SSVAL(req->outbuf, smb_vwv0, choice);
705 DEBUG( 5, ( "negprot index=%d\n", choice ) );
707 if ((lp_server_signing() == Required) && (get_Protocol() < PROTOCOL_NT1)) {
708 exit_server_cleanly("SMB signing is required and "
709 "client negotiated a downlevel protocol");
712 TALLOC_FREE(cliprotos);
713 END_PROFILE(SMBnegprot);
714 return;