Skip to content

Commit 1172d85

Browse files
ZhangGuoDongsmfrench
authored andcommitted
smb: move some duplicate definitions to common/smb2pdu.h
In order to maintain the code more easily, move duplicate definitions to common header file. There are only 4 different definitions, the client uses cpu_to_le16() but the server does not: - RSS_CAPABLE - RDMA_CAPABLE - INTERNETWORK - INTERNETWORKV6 The other definitions are exactly the same on both client and server. The struct smb_hdr is defined in MS-CIFS and MS-SMB, but it's also used by SMB2 and SMB3, so move it to the common smb2pdu.h. Co-developed-by: ChenXiaoSong <chenxiaosong@kylinos.cn> Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn> Signed-off-by: ZhangGuoDong <zhangguodong@kylinos.cn> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 96721fd commit 1172d85

6 files changed

Lines changed: 173 additions & 257 deletions

File tree

fs/smb/client/cifspdu.h

Lines changed: 2 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <net/sock.h>
1313
#include <linux/unaligned.h>
1414
#include "../common/smbfsctl.h"
15+
#include "../common/smb2pdu.h"
1516

1617
#define CIFS_PROT 0
1718
#define POSIX_PROT (CIFS_PROT+1)
@@ -179,98 +180,7 @@
179180
#define SMBFLG2_ERR_STATUS cpu_to_le16(0x4000)
180181
#define SMBFLG2_UNICODE cpu_to_le16(0x8000)
181182

182-
/*
183-
* These are the file access permission bits defined in CIFS for the
184-
* NTCreateAndX as well as the level 0x107
185-
* TRANS2_QUERY_PATH_INFORMATION API. The level 0x107, SMB_QUERY_FILE_ALL_INFO
186-
* responds with the AccessFlags.
187-
* The AccessFlags specifies the access permissions a caller has to the
188-
* file and can have any suitable combination of the following values:
189-
*/
190-
191-
#define FILE_READ_DATA 0x00000001 /* Data can be read from the file */
192-
/* or directory child entries can */
193-
/* be listed together with the */
194-
/* associated child attributes */
195-
/* (so the FILE_READ_ATTRIBUTES on */
196-
/* the child entry is not needed) */
197-
#define FILE_WRITE_DATA 0x00000002 /* Data can be written to the file */
198-
/* or new file can be created in */
199-
/* the directory */
200-
#define FILE_APPEND_DATA 0x00000004 /* Data can be appended to the file */
201-
/* (for non-local files over SMB it */
202-
/* is same as FILE_WRITE_DATA) */
203-
/* or new subdirectory can be */
204-
/* created in the directory */
205-
#define FILE_READ_EA 0x00000008 /* Extended attributes associated */
206-
/* with the file can be read */
207-
#define FILE_WRITE_EA 0x00000010 /* Extended attributes associated */
208-
/* with the file can be written */
209-
#define FILE_EXECUTE 0x00000020 /*Data can be read into memory from */
210-
/* the file using system paging I/O */
211-
/* for executing the file / script */
212-
/* or right to traverse directory */
213-
/* (but by default all users have */
214-
/* directory bypass traverse */
215-
/* privilege and do not need this */
216-
/* permission on directories at all)*/
217-
#define FILE_DELETE_CHILD 0x00000040 /* Child entry can be deleted from */
218-
/* the directory (so the DELETE on */
219-
/* the child entry is not needed) */
220-
#define FILE_READ_ATTRIBUTES 0x00000080 /* Attributes associated with the */
221-
/* file or directory can be read */
222-
#define FILE_WRITE_ATTRIBUTES 0x00000100 /* Attributes associated with the */
223-
/* file or directory can be written */
224-
#define DELETE 0x00010000 /* The file or dir can be deleted */
225-
#define READ_CONTROL 0x00020000 /* The discretionary access control */
226-
/* list and ownership associated */
227-
/* with the file or dir can be read */
228-
#define WRITE_DAC 0x00040000 /* The discretionary access control */
229-
/* list associated with the file or */
230-
/* directory can be written */
231-
#define WRITE_OWNER 0x00080000 /* Ownership information associated */
232-
/* with the file/dir can be written */
233-
#define SYNCHRONIZE 0x00100000 /* The file handle can waited on to */
234-
/* synchronize with the completion */
235-
/* of an input/output request */
236-
#define SYSTEM_SECURITY 0x01000000 /* The system access control list */
237-
/* associated with the file or */
238-
/* directory can be read or written */
239-
/* (cannot be in DACL, can in SACL) */
240-
#define MAXIMUM_ALLOWED 0x02000000 /* Maximal subset of GENERIC_ALL */
241-
/* permissions which can be granted */
242-
/* (cannot be in DACL nor SACL) */
243-
#define GENERIC_ALL 0x10000000 /* Same as: GENERIC_EXECUTE | */
244-
/* GENERIC_WRITE | */
245-
/* GENERIC_READ | */
246-
/* FILE_DELETE_CHILD | */
247-
/* DELETE | */
248-
/* WRITE_DAC | */
249-
/* WRITE_OWNER */
250-
/* So GENERIC_ALL contains all bits */
251-
/* mentioned above except these two */
252-
/* SYSTEM_SECURITY MAXIMUM_ALLOWED */
253-
#define GENERIC_EXECUTE 0x20000000 /* Same as: FILE_EXECUTE | */
254-
/* FILE_READ_ATTRIBUTES | */
255-
/* READ_CONTROL | */
256-
/* SYNCHRONIZE */
257-
#define GENERIC_WRITE 0x40000000 /* Same as: FILE_WRITE_DATA | */
258-
/* FILE_APPEND_DATA | */
259-
/* FILE_WRITE_EA | */
260-
/* FILE_WRITE_ATTRIBUTES | */
261-
/* READ_CONTROL | */
262-
/* SYNCHRONIZE */
263-
#define GENERIC_READ 0x80000000 /* Same as: FILE_READ_DATA | */
264-
/* FILE_READ_EA | */
265-
/* FILE_READ_ATTRIBUTES | */
266-
/* READ_CONTROL | */
267-
/* SYNCHRONIZE */
268-
269-
#define FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES)
270-
#define FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \
271-
| FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES)
272-
#define FILE_EXEC_RIGHTS (FILE_EXECUTE)
273-
183+
/* Combinations of file access permission bits */
274184
#define SET_FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA | FILE_WRITE_EA \
275185
| FILE_READ_ATTRIBUTES \
276186
| FILE_WRITE_ATTRIBUTES \
@@ -282,15 +192,6 @@
282192
| FILE_WRITE_ATTRIBUTES \
283193
| DELETE | READ_CONTROL | WRITE_DAC \
284194
| WRITE_OWNER | SYNCHRONIZE)
285-
#define SET_FILE_EXEC_RIGHTS (FILE_READ_EA | FILE_WRITE_EA | FILE_EXECUTE \
286-
| FILE_READ_ATTRIBUTES \
287-
| FILE_WRITE_ATTRIBUTES \
288-
| DELETE | READ_CONTROL | WRITE_DAC \
289-
| WRITE_OWNER | SYNCHRONIZE)
290-
291-
#define SET_MINIMUM_RIGHTS (FILE_READ_EA | FILE_READ_ATTRIBUTES \
292-
| READ_CONTROL | SYNCHRONIZE)
293-
294195

295196
/*
296197
* Invalid readdir handle
@@ -416,38 +317,6 @@
416317
#define GETU16(var) (*((__u16 *)var)) /* BB check for endian issues */
417318
#define GETU32(var) (*((__u32 *)var)) /* BB check for endian issues */
418319

419-
struct smb_hdr {
420-
__be32 smb_buf_length; /* BB length is only two (rarely three) bytes,
421-
with one or two byte "type" preceding it that will be
422-
zero - we could mask the type byte off */
423-
__u8 Protocol[4];
424-
__u8 Command;
425-
union {
426-
struct {
427-
__u8 ErrorClass;
428-
__u8 Reserved;
429-
__le16 Error;
430-
} __attribute__((packed)) DosError;
431-
__le32 CifsError;
432-
} __attribute__((packed)) Status;
433-
__u8 Flags;
434-
__le16 Flags2; /* note: le */
435-
__le16 PidHigh;
436-
union {
437-
struct {
438-
__le32 SequenceNumber; /* le */
439-
__u32 Reserved; /* zero */
440-
} __attribute__((packed)) Sequence;
441-
__u8 SecuritySignature[8]; /* le */
442-
} __attribute__((packed)) Signature;
443-
__u8 pad[2];
444-
__u16 Tid;
445-
__le16 Pid;
446-
__u16 Uid;
447-
__le16 Mid;
448-
__u8 WordCount;
449-
} __attribute__((packed));
450-
451320
/* given a pointer to an smb_hdr, retrieve a void pointer to the ByteCount */
452321
static inline void *
453322
BCC(struct smb_hdr *smb)

fs/smb/client/smb2pdu.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,6 @@ struct share_redirect_error_context_rsp {
133133
#define SMB2_LEASE_HANDLE_CACHING_HE 0x02
134134
#define SMB2_LEASE_WRITE_CACHING_HE 0x04
135135

136-
137-
/* See MS-SMB2 2.2.13.2.11 */
138-
/* Flags */
139-
#define SMB2_DHANDLE_FLAG_PERSISTENT 0x00000002
140-
141136
/* See MS-SMB2 2.2.13.2.5 */
142137
struct crt_twarp_ctxt {
143138
struct create_context_hdr ccontext;
@@ -198,22 +193,6 @@ struct network_resiliency_req {
198193
} __packed;
199194
/* There is no buffer for the response ie no struct network_resiliency_rsp */
200195

201-
#define RSS_CAPABLE cpu_to_le32(0x00000001)
202-
#define RDMA_CAPABLE cpu_to_le32(0x00000002)
203-
204-
#define INTERNETWORK cpu_to_le16(0x0002)
205-
#define INTERNETWORKV6 cpu_to_le16(0x0017)
206-
207-
struct network_interface_info_ioctl_rsp {
208-
__le32 Next; /* next interface. zero if this is last one */
209-
__le32 IfIndex;
210-
__le32 Capability; /* RSS or RDMA Capable */
211-
__le32 Reserved;
212-
__le64 LinkSpeed;
213-
__le16 Family;
214-
__u8 Buffer[126];
215-
} __packed;
216-
217196
#define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
218197

219198
struct compress_ioctl {

fs/smb/common/smb2pdu.h

Lines changed: 166 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,12 +1149,6 @@ struct smb2_server_client_notification {
11491149
#define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
11501150
#define FILE_CREATE_MASK_LE cpu_to_le32(0x00000007)
11511151

1152-
#define FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA \
1153-
| FILE_READ_ATTRIBUTES)
1154-
#define FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \
1155-
| FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES)
1156-
#define FILE_EXEC_RIGHTS (FILE_EXECUTE)
1157-
11581152
/* CreateOptions Flags */
11591153
#define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
11601154
/* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */
@@ -1290,6 +1284,14 @@ struct create_mxac_req {
12901284
__le64 Timestamp;
12911285
} __packed;
12921286

1287+
/*
1288+
* Flags
1289+
* See MS-SMB2 2.2.13.2.11
1290+
* MS-SMB2 2.2.13.2.12
1291+
* MS-SMB2 2.2.14.2.12
1292+
*/
1293+
#define SMB2_DHANDLE_FLAG_PERSISTENT 0x00000002
1294+
12931295
/* See MS-SMB2 2.2.13.2.11 */
12941296
struct durable_context_v2_req {
12951297
__le32 Timeout;
@@ -1500,6 +1502,26 @@ struct smb_sockaddr_in6 {
15001502
__be32 ScopeId;
15011503
} __packed;
15021504

1505+
/* See MS-SMB2 2.2.32.5 and MS-SMB2 2.2.32.5.1 */
1506+
#define RSS_CAPABLE cpu_to_le32(0x00000001)
1507+
#define RDMA_CAPABLE cpu_to_le32(0x00000002)
1508+
#define INTERNETWORK cpu_to_le16(0x0002)
1509+
#define INTERNETWORKV6 cpu_to_le16(0x0017)
1510+
struct network_interface_info_ioctl_rsp {
1511+
__le32 Next; /* next interface. zero if this is last one */
1512+
__le32 IfIndex;
1513+
__le32 Capability; /* RSS or RDMA Capable */
1514+
__le32 Reserved;
1515+
__le64 LinkSpeed;
1516+
union {
1517+
char SockAddr_Storage[128];
1518+
struct {
1519+
__le16 Family;
1520+
__u8 Buffer[126];
1521+
};
1522+
};
1523+
} __packed;
1524+
15031525
/* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
15041526
struct file_zero_data_information {
15051527
__le64 FileOffset;
@@ -1989,6 +2011,144 @@ struct smb2_lease_ack {
19892011
__le64 LeaseDuration;
19902012
} __packed;
19912013

2014+
/*
2015+
* See MS-CIFS 2.2.3.1
2016+
* MS-SMB 2.2.3.1
2017+
*/
2018+
struct smb_hdr {
2019+
__be32 smb_buf_length; /* BB length is only two (rarely three) bytes,
2020+
with one or two byte "type" preceding it that will be
2021+
zero - we could mask the type byte off */
2022+
__u8 Protocol[4];
2023+
__u8 Command;
2024+
union {
2025+
struct {
2026+
__u8 ErrorClass;
2027+
__u8 Reserved;
2028+
__le16 Error;
2029+
} __packed DosError;
2030+
__le32 CifsError;
2031+
} __packed Status;
2032+
__u8 Flags;
2033+
__le16 Flags2; /* note: le */
2034+
__le16 PidHigh;
2035+
union {
2036+
struct {
2037+
__le32 SequenceNumber; /* le */
2038+
__u32 Reserved; /* zero */
2039+
} __packed Sequence;
2040+
__u8 SecuritySignature[8]; /* le */
2041+
} __packed Signature;
2042+
__u8 pad[2];
2043+
__u16 Tid;
2044+
__le16 Pid;
2045+
__u16 Uid;
2046+
__le16 Mid;
2047+
__u8 WordCount;
2048+
} __packed;
2049+
19922050
#define OP_BREAK_STRUCT_SIZE_20 24
19932051
#define OP_BREAK_STRUCT_SIZE_21 36
2052+
2053+
/*
2054+
* See MS-SMB2 2.2.13.1.1
2055+
* MS-SMB 2.2.1.4.1
2056+
* These are the file access permission bits defined in CIFS for the
2057+
* NTCreateAndX as well as the level 0x107
2058+
* TRANS2_QUERY_PATH_INFORMATION API. The level 0x107, SMB_QUERY_FILE_ALL_INFO
2059+
* responds with the AccessFlags.
2060+
* The AccessFlags specifies the access permissions a caller has to the
2061+
* file and can have any suitable combination of the following values:
2062+
*/
2063+
#define FILE_READ_DATA 0x00000001 /* Data can be read from the file */
2064+
/* or directory child entries can */
2065+
/* be listed together with the */
2066+
/* associated child attributes */
2067+
/* (so the FILE_READ_ATTRIBUTES on */
2068+
/* the child entry is not needed) */
2069+
#define FILE_WRITE_DATA 0x00000002 /* Data can be written to the file */
2070+
/* or new file can be created in */
2071+
/* the directory */
2072+
#define FILE_APPEND_DATA 0x00000004 /* Data can be appended to the file */
2073+
/* (for non-local files over SMB it */
2074+
/* is same as FILE_WRITE_DATA) */
2075+
/* or new subdirectory can be */
2076+
/* created in the directory */
2077+
#define FILE_READ_EA 0x00000008 /* Extended attributes associated */
2078+
/* with the file can be read */
2079+
#define FILE_WRITE_EA 0x00000010 /* Extended attributes associated */
2080+
/* with the file can be written */
2081+
#define FILE_EXECUTE 0x00000020 /*Data can be read into memory from */
2082+
/* the file using system paging I/O */
2083+
/* for executing the file / script */
2084+
/* or right to traverse directory */
2085+
/* (but by default all users have */
2086+
/* directory bypass traverse */
2087+
/* privilege and do not need this */
2088+
/* permission on directories at all)*/
2089+
#define FILE_DELETE_CHILD 0x00000040 /* Child entry can be deleted from */
2090+
/* the directory (so the DELETE on */
2091+
/* the child entry is not needed) */
2092+
#define FILE_READ_ATTRIBUTES 0x00000080 /* Attributes associated with the */
2093+
/* file or directory can be read */
2094+
#define FILE_WRITE_ATTRIBUTES 0x00000100 /* Attributes associated with the */
2095+
/* file or directory can be written */
2096+
#define DELETE 0x00010000 /* The file or dir can be deleted */
2097+
#define READ_CONTROL 0x00020000 /* The discretionary access control */
2098+
/* list and ownership associated */
2099+
/* with the file or dir can be read */
2100+
#define WRITE_DAC 0x00040000 /* The discretionary access control */
2101+
/* list associated with the file or */
2102+
/* directory can be written */
2103+
#define WRITE_OWNER 0x00080000 /* Ownership information associated */
2104+
/* with the file/dir can be written */
2105+
#define SYNCHRONIZE 0x00100000 /* The file handle can waited on to */
2106+
/* synchronize with the completion */
2107+
/* of an input/output request */
2108+
#define SYSTEM_SECURITY 0x01000000 /* The system access control list */
2109+
/* associated with the file or */
2110+
/* directory can be read or written */
2111+
/* (cannot be in DACL, can in SACL) */
2112+
#define MAXIMUM_ALLOWED 0x02000000 /* Maximal subset of GENERIC_ALL */
2113+
/* permissions which can be granted */
2114+
/* (cannot be in DACL nor SACL) */
2115+
#define GENERIC_ALL 0x10000000 /* Same as: GENERIC_EXECUTE | */
2116+
/* GENERIC_WRITE | */
2117+
/* GENERIC_READ | */
2118+
/* FILE_DELETE_CHILD | */
2119+
/* DELETE | */
2120+
/* WRITE_DAC | */
2121+
/* WRITE_OWNER */
2122+
/* So GENERIC_ALL contains all bits */
2123+
/* mentioned above except these two */
2124+
/* SYSTEM_SECURITY MAXIMUM_ALLOWED */
2125+
#define GENERIC_EXECUTE 0x20000000 /* Same as: FILE_EXECUTE | */
2126+
/* FILE_READ_ATTRIBUTES | */
2127+
/* READ_CONTROL | */
2128+
/* SYNCHRONIZE */
2129+
#define GENERIC_WRITE 0x40000000 /* Same as: FILE_WRITE_DATA | */
2130+
/* FILE_APPEND_DATA | */
2131+
/* FILE_WRITE_EA | */
2132+
/* FILE_WRITE_ATTRIBUTES | */
2133+
/* READ_CONTROL | */
2134+
/* SYNCHRONIZE */
2135+
#define GENERIC_READ 0x80000000 /* Same as: FILE_READ_DATA | */
2136+
/* FILE_READ_EA | */
2137+
/* FILE_READ_ATTRIBUTES | */
2138+
/* READ_CONTROL | */
2139+
/* SYNCHRONIZE */
2140+
2141+
/* Combinations of file access permission bits */
2142+
#define FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES)
2143+
#define FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \
2144+
| FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES)
2145+
#define FILE_EXEC_RIGHTS (FILE_EXECUTE)
2146+
#define SET_FILE_EXEC_RIGHTS (FILE_READ_EA | FILE_WRITE_EA | FILE_EXECUTE \
2147+
| FILE_READ_ATTRIBUTES \
2148+
| FILE_WRITE_ATTRIBUTES \
2149+
| DELETE | READ_CONTROL | WRITE_DAC \
2150+
| WRITE_OWNER | SYNCHRONIZE)
2151+
#define SET_MINIMUM_RIGHTS (FILE_READ_EA | FILE_READ_ATTRIBUTES \
2152+
| READ_CONTROL | SYNCHRONIZE)
2153+
19942154
#endif /* _COMMON_SMB2PDU_H */

0 commit comments

Comments
 (0)