From: Justin Maggard Date: Wed, 2 Mar 2016 18:18:34 +0000 (-0800) Subject: s3:smbd: rework negprot remote arch detection X-Git-Tag: samba-4.2.12~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd11d39472116133bc2c943630c9eeca0746865f;p=thirdparty%2Fsamba.git s3:smbd: rework negprot remote arch detection Negprot remote arch detection is very cryptic. Rework it so it's easier to understand, and therefore more extensible, following the protocol table in inline comments. This also allows us to remove some hacks. Signed-off-by: Justin Maggard Reviewed-by: Ralph Boehme Reviewed-by: Jeremy Allison (cherry picked from commit b69b96fc14128f50a906b4f5b34934efbc94afbc) --- diff --git a/libcli/smb/smb_constants.h b/libcli/smb/smb_constants.h index 9b570782b64..60588769025 100644 --- a/libcli/smb/smb_constants.h +++ b/libcli/smb/smb_constants.h @@ -307,7 +307,6 @@ enum csc_policy { #define FLAGS2_READ_PERMIT_EXECUTE 0x2000 #define FLAGS2_32_BIT_ERROR_CODES 0x4000 #define FLAGS2_UNICODE_STRINGS 0x8000 -#define FLAGS2_WIN2K_SIGNATURE 0xC852 /* Hack alert ! For now... JRA. */ /* FileAttributes (search attributes) field */ #define FILE_ATTRIBUTE_READONLY 0x0001L diff --git a/source3/smbd/negprot.c b/source3/smbd/negprot.c index e6a9bde15e1..1cfdb59a0c6 100644 --- a/source3/smbd/negprot.c +++ b/source3/smbd/negprot.c @@ -468,16 +468,34 @@ protocol [LANMAN2.1] * Win2K added by matty 17/7/99 */ -#define ARCH_WFWG 0x3 /* This is a fudge because WfWg is like Win95 */ -#define ARCH_WIN95 0x2 -#define ARCH_WINNT 0x4 -#define ARCH_WIN2K 0xC /* Win2K is like NT */ -#define ARCH_OS2 0x14 /* Again OS/2 is like NT */ -#define ARCH_SAMBA 0x20 -#define ARCH_CIFSFS 0x40 -#define ARCH_VISTA 0x8C /* Vista is like XP/2K */ - -#define ARCH_ALL 0x7F +#define PROT_PC_NETWORK_PROGRAM_1_0 0x0001 +#define PROT_XENIX_CORE 0x0002 +#define PROT_MICROSOFT_NETWORKS_3_0 0x0004 +#define PROT_DOS_LM1_2X002 0x0008 +#define PROT_MICROSOFT_NETWORKS_1_03 0x0010 +#define PROT_DOS_LANMAN2_1 0x0020 +#define PROT_LANMAN1_0 0x0040 +#define PROT_WFWG 0x0080 +#define PROT_LM1_2X002 0x0100 +#define PROT_LANMAN2_1 0x0200 +#define PROT_NT_LM_0_12 0x0400 +#define PROT_SMB_2_001 0x0800 +#define PROT_SMB_2_002 0x1000 +#define PROT_SMB_2_FF 0x2000 +#define PROT_SAMBA 0x4000 +#define PROT_POSIX_2 0x8000 + +#define ARCH_WFWG ( PROT_PC_NETWORK_PROGRAM_1_0 | PROT_MICROSOFT_NETWORKS_3_0 | \ + PROT_DOS_LM1_2X002 | PROT_DOS_LANMAN2_1 | PROT_WFWG ) +#define ARCH_WIN95 ( ARCH_WFWG | PROT_NT_LM_0_12 ) +#define ARCH_WINNT ( PROT_PC_NETWORK_PROGRAM_1_0 | PROT_XENIX_CORE | \ + PROT_MICROSOFT_NETWORKS_1_03 | PROT_LANMAN1_0 | PROT_WFWG | \ + PROT_LM1_2X002 | PROT_LANMAN2_1 | PROT_NT_LM_0_12 ) +#define ARCH_WIN2K ( ARCH_WINNT & ~(PROT_XENIX_CORE | PROT_MICROSOFT_NETWORKS_1_03) ) +#define ARCH_OS2 ( ARCH_WINNT & ~(PROT_MICROSOFT_NETWORKS_1_03 | PROT_WFWG) ) +#define ARCH_VISTA ( ARCH_WIN2K | PROT_SMB_2_001 ) +#define ARCH_SAMBA ( PROT_SAMBA ) +#define ARCH_CIFSFS ( PROT_POSIX_2 ) /* List of supported protocols, most desired first */ static const struct { @@ -511,7 +529,7 @@ void reply_negprot(struct smb_request *req) int chosen_level = -1; int protocol; const char *p; - int arch = ARCH_ALL; + int protocols = 0; int num_cliprotos; char **cliprotos; int i; @@ -579,41 +597,46 @@ void reply_negprot(struct smb_request *req) } for (i=0; iflags2 == FLAGS2_WIN2K_SIGNATURE) - set_remote_arch(RA_WIN2K); - else - set_remote_arch(RA_WINNT); + set_remote_arch(RA_WINNT); break; case ARCH_WIN2K: - /* Vista may have been set in the negprot so don't - override it here */ - if ( get_remote_arch() != RA_VISTA ) - set_remote_arch(RA_WIN2K); + set_remote_arch(RA_WIN2K); break; case ARCH_VISTA: set_remote_arch(RA_VISTA); diff --git a/source3/smbd/smb2_negprot.c b/source3/smbd/smb2_negprot.c index 1f7f1a9a56b..eb238d38b08 100644 --- a/source3/smbd/smb2_negprot.c +++ b/source3/smbd/smb2_negprot.c @@ -200,8 +200,15 @@ NTSTATUS smbd_smb2_request_process_negprot(struct smbd_smb2_request *req) return smbd_smb2_request_error(req, NT_STATUS_NOT_SUPPORTED); } - if (get_remote_arch() != RA_SAMBA) { + switch (get_remote_arch()) { + case RA_VISTA: + case RA_SAMBA: + case RA_CIFSFS: + case RA_OSX: + break; + default: set_remote_arch(RA_VISTA); + break; } fstr_sprintf(remote_proto, "SMB%X_%02X",