Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: LGPL-2.1 */
0002 /*
0003  *
0004  *   Copyright (c) International Business Machines  Corp., 2002,2007
0005  *   Author(s): Steve French (sfrench@us.ibm.com)
0006  *
0007  */
0008 
0009 #define NTLMSSP_SIGNATURE "NTLMSSP"
0010 /* Message Types */
0011 #define NtLmNegotiate     cpu_to_le32(1)
0012 #define NtLmChallenge     cpu_to_le32(2)
0013 #define NtLmAuthenticate  cpu_to_le32(3)
0014 #define UnknownMessage    cpu_to_le32(8)
0015 
0016 /* Negotiate Flags */
0017 #define NTLMSSP_NEGOTIATE_UNICODE         0x01 /* Text strings are unicode */
0018 #define NTLMSSP_NEGOTIATE_OEM             0x02 /* Text strings are in OEM */
0019 #define NTLMSSP_REQUEST_TARGET            0x04 /* Srv returns its auth realm */
0020 /* define reserved9                       0x08 */
0021 #define NTLMSSP_NEGOTIATE_SIGN          0x0010 /* Request signing capability */
0022 #define NTLMSSP_NEGOTIATE_SEAL          0x0020 /* Request confidentiality */
0023 #define NTLMSSP_NEGOTIATE_DGRAM         0x0040
0024 #define NTLMSSP_NEGOTIATE_LM_KEY        0x0080 /* Use LM session key */
0025 /* defined reserved 8                   0x0100 */
0026 #define NTLMSSP_NEGOTIATE_NTLM          0x0200 /* NTLM authentication */
0027 #define NTLMSSP_NEGOTIATE_NT_ONLY       0x0400 /* Lanman not allowed */
0028 #define NTLMSSP_ANONYMOUS               0x0800
0029 #define NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED 0x1000 /* reserved6 */
0030 #define NTLMSSP_NEGOTIATE_WORKSTATION_SUPPLIED 0x2000
0031 #define NTLMSSP_NEGOTIATE_LOCAL_CALL    0x4000 /* client/server same machine */
0032 #define NTLMSSP_NEGOTIATE_ALWAYS_SIGN   0x8000 /* Sign. All security levels  */
0033 #define NTLMSSP_TARGET_TYPE_DOMAIN     0x10000
0034 #define NTLMSSP_TARGET_TYPE_SERVER     0x20000
0035 #define NTLMSSP_TARGET_TYPE_SHARE      0x40000
0036 #define NTLMSSP_NEGOTIATE_EXTENDED_SEC 0x80000 /* NB:not related to NTLMv2 pwd*/
0037 /* #define NTLMSSP_REQUEST_INIT_RESP     0x100000 */
0038 #define NTLMSSP_NEGOTIATE_IDENTIFY    0x100000
0039 #define NTLMSSP_REQUEST_ACCEPT_RESP   0x200000 /* reserved5 */
0040 #define NTLMSSP_REQUEST_NON_NT_KEY    0x400000
0041 #define NTLMSSP_NEGOTIATE_TARGET_INFO 0x800000
0042 /* #define reserved4                 0x1000000 */
0043 #define NTLMSSP_NEGOTIATE_VERSION    0x2000000 /* we only set for SMB2+ */
0044 /* #define reserved3                 0x4000000 */
0045 /* #define reserved2                 0x8000000 */
0046 /* #define reserved1                0x10000000 */
0047 #define NTLMSSP_NEGOTIATE_128       0x20000000
0048 #define NTLMSSP_NEGOTIATE_KEY_XCH   0x40000000
0049 #define NTLMSSP_NEGOTIATE_56        0x80000000
0050 
0051 /* Define AV Pair Field IDs */
0052 enum av_field_type {
0053     NTLMSSP_AV_EOL = 0,
0054     NTLMSSP_AV_NB_COMPUTER_NAME,
0055     NTLMSSP_AV_NB_DOMAIN_NAME,
0056     NTLMSSP_AV_DNS_COMPUTER_NAME,
0057     NTLMSSP_AV_DNS_DOMAIN_NAME,
0058     NTLMSSP_AV_DNS_TREE_NAME,
0059     NTLMSSP_AV_FLAGS,
0060     NTLMSSP_AV_TIMESTAMP,
0061     NTLMSSP_AV_RESTRICTION,
0062     NTLMSSP_AV_TARGET_NAME,
0063     NTLMSSP_AV_CHANNEL_BINDINGS
0064 };
0065 
0066 /* Although typedefs are not commonly used for structure definitions */
0067 /* in the Linux kernel, in this particular case they are useful      */
0068 /* to more closely match the standards document for NTLMSSP from     */
0069 /* OpenGroup and to make the code more closely match the standard in */
0070 /* appearance */
0071 
0072 typedef struct _SECURITY_BUFFER {
0073     __le16 Length;
0074     __le16 MaximumLength;
0075     __le32 BufferOffset;    /* offset to buffer */
0076 } __attribute__((packed)) SECURITY_BUFFER;
0077 
0078 typedef struct _NEGOTIATE_MESSAGE {
0079     __u8 Signature[sizeof(NTLMSSP_SIGNATURE)];
0080     __le32 MessageType;     /* NtLmNegotiate = 1 */
0081     __le32 NegotiateFlags;
0082     SECURITY_BUFFER DomainName; /* RFC 1001 style and ASCII */
0083     SECURITY_BUFFER WorkstationName;    /* RFC 1001 and ASCII */
0084     /* SECURITY_BUFFER for version info not present since we
0085        do not set the version is present flag */
0086     char DomainString[0];
0087     /* followed by WorkstationString */
0088 } __attribute__((packed)) NEGOTIATE_MESSAGE, *PNEGOTIATE_MESSAGE;
0089 
0090 #define NTLMSSP_REVISION_W2K3 0x0F
0091 
0092 /* See MS-NLMP section 2.2.2.10 */
0093 struct ntlmssp_version {
0094     __u8    ProductMajorVersion;
0095     __u8    ProductMinorVersion;
0096     __le16  ProductBuild; /* we send the cifs.ko module version here */
0097     __u8    Reserved[3];
0098     __u8    NTLMRevisionCurrent; /* currently 0x0F */
0099 } __packed;
0100 
0101 /* see MS-NLMP section 2.2.1.1 */
0102 struct negotiate_message {
0103     __u8 Signature[sizeof(NTLMSSP_SIGNATURE)];
0104     __le32 MessageType;     /* NtLmNegotiate = 1 */
0105     __le32 NegotiateFlags;
0106     SECURITY_BUFFER DomainName; /* RFC 1001 style and ASCII */
0107     SECURITY_BUFFER WorkstationName;    /* RFC 1001 and ASCII */
0108     struct  ntlmssp_version Version;
0109     /* SECURITY_BUFFER */
0110     char DomainString[];
0111     /* followed by WorkstationString */
0112 } __packed;
0113 
0114 typedef struct _CHALLENGE_MESSAGE {
0115     __u8 Signature[sizeof(NTLMSSP_SIGNATURE)];
0116     __le32 MessageType;   /* NtLmChallenge = 2 */
0117     SECURITY_BUFFER TargetName;
0118     __le32 NegotiateFlags;
0119     __u8 Challenge[CIFS_CRYPTO_KEY_SIZE];
0120     __u8 Reserved[8];
0121     SECURITY_BUFFER TargetInfoArray;
0122     /* SECURITY_BUFFER for version info not present since we
0123        do not set the version is present flag */
0124 } __attribute__((packed)) CHALLENGE_MESSAGE, *PCHALLENGE_MESSAGE;
0125 
0126 typedef struct _AUTHENTICATE_MESSAGE {
0127     __u8 Signature[sizeof(NTLMSSP_SIGNATURE)];
0128     __le32 MessageType;  /* NtLmsAuthenticate = 3 */
0129     SECURITY_BUFFER LmChallengeResponse;
0130     SECURITY_BUFFER NtChallengeResponse;
0131     SECURITY_BUFFER DomainName;
0132     SECURITY_BUFFER UserName;
0133     SECURITY_BUFFER WorkstationName;
0134     SECURITY_BUFFER SessionKey;
0135     __le32 NegotiateFlags;
0136     /* SECURITY_BUFFER for version info not present since we
0137        do not set the version is present flag */
0138     char UserString[0];
0139 } __attribute__((packed)) AUTHENTICATE_MESSAGE, *PAUTHENTICATE_MESSAGE;
0140 
0141 /*
0142  * Size of the session key (crypto key encrypted with the password
0143  */
0144 
0145 int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, struct cifs_ses *ses);
0146 int build_ntlmssp_negotiate_blob(unsigned char **pbuffer, u16 *buflen,
0147                  struct cifs_ses *ses,
0148                  struct TCP_Server_Info *server,
0149                  const struct nls_table *nls_cp);
0150 int build_ntlmssp_smb3_negotiate_blob(unsigned char **pbuffer, u16 *buflen,
0151                  struct cifs_ses *ses,
0152                  struct TCP_Server_Info *server,
0153                  const struct nls_table *nls_cp);
0154 int build_ntlmssp_auth_blob(unsigned char **pbuffer, u16 *buflen,
0155             struct cifs_ses *ses,
0156             struct TCP_Server_Info *server,
0157             const struct nls_table *nls_cp);