overlayfs: Implement splice-read
[linux-block.git] / fs / cifs / ntlmssp.h
CommitLineData
929be906 1/* SPDX-License-Identifier: LGPL-2.1 */
1da177e4 2/*
1da177e4 3 *
d38d8c74 4 * Copyright (c) International Business Machines Corp., 2002,2007
1da177e4
LT
5 * Author(s): Steve French (sfrench@us.ibm.com)
6 *
1da177e4
LT
7 */
8
1da177e4
LT
9#define NTLMSSP_SIGNATURE "NTLMSSP"
10/* Message Types */
11#define NtLmNegotiate cpu_to_le32(1)
12#define NtLmChallenge cpu_to_le32(2)
13#define NtLmAuthenticate cpu_to_le32(3)
14#define UnknownMessage cpu_to_le32(8)
15
16/* Negotiate Flags */
e14b2fe1
SF
17#define NTLMSSP_NEGOTIATE_UNICODE 0x01 /* Text strings are unicode */
18#define NTLMSSP_NEGOTIATE_OEM 0x02 /* Text strings are in OEM */
19#define NTLMSSP_REQUEST_TARGET 0x04 /* Srv returns its auth realm */
20/* define reserved9 0x08 */
21#define NTLMSSP_NEGOTIATE_SIGN 0x0010 /* Request signing capability */
22#define NTLMSSP_NEGOTIATE_SEAL 0x0020 /* Request confidentiality */
23#define NTLMSSP_NEGOTIATE_DGRAM 0x0040
24#define NTLMSSP_NEGOTIATE_LM_KEY 0x0080 /* Use LM session key */
25/* defined reserved 8 0x0100 */
26#define NTLMSSP_NEGOTIATE_NTLM 0x0200 /* NTLM authentication */
27#define NTLMSSP_NEGOTIATE_NT_ONLY 0x0400 /* Lanman not allowed */
28#define NTLMSSP_ANONYMOUS 0x0800
29#define NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED 0x1000 /* reserved6 */
1da177e4 30#define NTLMSSP_NEGOTIATE_WORKSTATION_SUPPLIED 0x2000
e14b2fe1
SF
31#define NTLMSSP_NEGOTIATE_LOCAL_CALL 0x4000 /* client/server same machine */
32#define NTLMSSP_NEGOTIATE_ALWAYS_SIGN 0x8000 /* Sign. All security levels */
33#define NTLMSSP_TARGET_TYPE_DOMAIN 0x10000
34#define NTLMSSP_TARGET_TYPE_SERVER 0x20000
35#define NTLMSSP_TARGET_TYPE_SHARE 0x40000
36#define NTLMSSP_NEGOTIATE_EXTENDED_SEC 0x80000 /* NB:not related to NTLMv2 pwd*/
37/* #define NTLMSSP_REQUEST_INIT_RESP 0x100000 */
38#define NTLMSSP_NEGOTIATE_IDENTIFY 0x100000
39#define NTLMSSP_REQUEST_ACCEPT_RESP 0x200000 /* reserved5 */
40#define NTLMSSP_REQUEST_NON_NT_KEY 0x400000
1da177e4 41#define NTLMSSP_NEGOTIATE_TARGET_INFO 0x800000
e14b2fe1 42/* #define reserved4 0x1000000 */
52d00533 43#define NTLMSSP_NEGOTIATE_VERSION 0x2000000 /* we only set for SMB2+ */
e14b2fe1
SF
44/* #define reserved3 0x4000000 */
45/* #define reserved2 0x8000000 */
46/* #define reserved1 0x10000000 */
47#define NTLMSSP_NEGOTIATE_128 0x20000000
48#define NTLMSSP_NEGOTIATE_KEY_XCH 0x40000000
49#define NTLMSSP_NEGOTIATE_56 0x80000000
1da177e4 50
2b149f11
SP
51/* Define AV Pair Field IDs */
52enum av_field_type {
53 NTLMSSP_AV_EOL = 0,
54 NTLMSSP_AV_NB_COMPUTER_NAME,
55 NTLMSSP_AV_NB_DOMAIN_NAME,
56 NTLMSSP_AV_DNS_COMPUTER_NAME,
57 NTLMSSP_AV_DNS_DOMAIN_NAME,
58 NTLMSSP_AV_DNS_TREE_NAME,
59 NTLMSSP_AV_FLAGS,
60 NTLMSSP_AV_TIMESTAMP,
61 NTLMSSP_AV_RESTRICTION,
62 NTLMSSP_AV_TARGET_NAME,
63 NTLMSSP_AV_CHANNEL_BINDINGS
64};
65
1da177e4
LT
66/* Although typedefs are not commonly used for structure definitions */
67/* in the Linux kernel, in this particular case they are useful */
68/* to more closely match the standards document for NTLMSSP from */
69/* OpenGroup and to make the code more closely match the standard in */
70/* appearance */
71
72typedef struct _SECURITY_BUFFER {
73 __le16 Length;
74 __le16 MaximumLength;
e14b2fe1 75 __le32 BufferOffset; /* offset to buffer */
0753ca7b 76} __attribute__((packed)) SECURITY_BUFFER;
1da177e4
LT
77
78typedef struct _NEGOTIATE_MESSAGE {
582d21e5 79 __u8 Signature[sizeof(NTLMSSP_SIGNATURE)];
e14b2fe1 80 __le32 MessageType; /* NtLmNegotiate = 1 */
1da177e4
LT
81 __le32 NegotiateFlags;
82 SECURITY_BUFFER DomainName; /* RFC 1001 style and ASCII */
83 SECURITY_BUFFER WorkstationName; /* RFC 1001 and ASCII */
e14b2fe1
SF
84 /* SECURITY_BUFFER for version info not present since we
85 do not set the version is present flag */
4e551dbd 86 char DomainString[];
1da177e4 87 /* followed by WorkstationString */
0753ca7b 88} __attribute__((packed)) NEGOTIATE_MESSAGE, *PNEGOTIATE_MESSAGE;
1da177e4 89
52d00533
SF
90#define NTLMSSP_REVISION_W2K3 0x0F
91
92/* See MS-NLMP section 2.2.2.10 */
93struct ntlmssp_version {
94 __u8 ProductMajorVersion;
95 __u8 ProductMinorVersion;
96 __le16 ProductBuild; /* we send the cifs.ko module version here */
97 __u8 Reserved[3];
98 __u8 NTLMRevisionCurrent; /* currently 0x0F */
99} __packed;
100
101/* see MS-NLMP section 2.2.1.1 */
102struct negotiate_message {
103 __u8 Signature[sizeof(NTLMSSP_SIGNATURE)];
104 __le32 MessageType; /* NtLmNegotiate = 1 */
105 __le32 NegotiateFlags;
106 SECURITY_BUFFER DomainName; /* RFC 1001 style and ASCII */
107 SECURITY_BUFFER WorkstationName; /* RFC 1001 and ASCII */
108 struct ntlmssp_version Version;
109 /* SECURITY_BUFFER */
5224f790 110 char DomainString[];
52d00533
SF
111 /* followed by WorkstationString */
112} __packed;
113
1da177e4 114typedef struct _CHALLENGE_MESSAGE {
582d21e5 115 __u8 Signature[sizeof(NTLMSSP_SIGNATURE)];
e14b2fe1 116 __le32 MessageType; /* NtLmChallenge = 2 */
1da177e4
LT
117 SECURITY_BUFFER TargetName;
118 __le32 NegotiateFlags;
119 __u8 Challenge[CIFS_CRYPTO_KEY_SIZE];
120 __u8 Reserved[8];
121 SECURITY_BUFFER TargetInfoArray;
e14b2fe1
SF
122 /* SECURITY_BUFFER for version info not present since we
123 do not set the version is present flag */
0753ca7b 124} __attribute__((packed)) CHALLENGE_MESSAGE, *PCHALLENGE_MESSAGE;
1da177e4
LT
125
126typedef struct _AUTHENTICATE_MESSAGE {
e14b2fe1
SF
127 __u8 Signature[sizeof(NTLMSSP_SIGNATURE)];
128 __le32 MessageType; /* NtLmsAuthenticate = 3 */
1da177e4
LT
129 SECURITY_BUFFER LmChallengeResponse;
130 SECURITY_BUFFER NtChallengeResponse;
131 SECURITY_BUFFER DomainName;
132 SECURITY_BUFFER UserName;
133 SECURITY_BUFFER WorkstationName;
134 SECURITY_BUFFER SessionKey;
135 __le32 NegotiateFlags;
e14b2fe1
SF
136 /* SECURITY_BUFFER for version info not present since we
137 do not set the version is present flag */
4e551dbd 138 char UserString[];
0753ca7b 139} __attribute__((packed)) AUTHENTICATE_MESSAGE, *PAUTHENTICATE_MESSAGE;
5478f9ba
PS
140
141/*
142 * Size of the session key (crypto key encrypted with the password
143 */
144
145int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, struct cifs_ses *ses);
49bd49f9
SP
146int build_ntlmssp_negotiate_blob(unsigned char **pbuffer, u16 *buflen,
147 struct cifs_ses *ses,
f486ef8e 148 struct TCP_Server_Info *server,
49bd49f9 149 const struct nls_table *nls_cp);
52d00533
SF
150int build_ntlmssp_smb3_negotiate_blob(unsigned char **pbuffer, u16 *buflen,
151 struct cifs_ses *ses,
152 struct TCP_Server_Info *server,
153 const struct nls_table *nls_cp);
b8da344b 154int build_ntlmssp_auth_blob(unsigned char **pbuffer, u16 *buflen,
5478f9ba 155 struct cifs_ses *ses,
f486ef8e 156 struct TCP_Server_Info *server,
5478f9ba 157 const struct nls_table *nls_cp);