Skip to content

Commit 4355a8f

Browse files
Ronnie Sahlbergsmfrench
authored andcommitted
ksmbd: switch to use shared definitions where available
Acked-by: Namjae Jeon <[email protected]> Signed-off-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 2734b69 commit 4355a8f

File tree

5 files changed

+2
-180
lines changed

5 files changed

+2
-180
lines changed

fs/ksmbd/smb2misc.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "glob.h"
88
#include "nterr.h"
9-
#include "smb2pdu.h"
109
#include "smb_common.h"
1110
#include "smbstatus.h"
1211
#include "mgmt/user_session.h"

fs/ksmbd/smb2ops.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include <linux/slab.h>
88
#include "glob.h"
9-
#include "smb2pdu.h"
109

1110
#include "auth.h"
1211
#include "connection.h"

fs/ksmbd/smb2pdu.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <linux/falloc.h>
1414

1515
#include "glob.h"
16-
#include "smb2pdu.h"
1716
#include "smbfsctl.h"
1817
#include "oplock.h"
1918
#include "smbacl.h"
@@ -8433,7 +8432,7 @@ static void fill_transform_hdr(void *tr_buf, char *old_buf, __le16 cipher_type)
84338432
memset(tr_buf, 0, sizeof(struct smb2_transform_hdr) + 4);
84348433
tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
84358434
tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
8436-
tr_hdr->Flags = cpu_to_le16(0x01);
8435+
tr_hdr->Flags = cpu_to_le16(TRANSFORM_FLAG_ENCRYPTED);
84378436
if (cipher_type == SMB2_ENCRYPTION_AES128_GCM ||
84388437
cipher_type == SMB2_ENCRYPTION_AES256_GCM)
84398438
get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);

fs/ksmbd/smb2pdu.h

Lines changed: 0 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -10,60 +10,6 @@
1010
#include "ntlmssp.h"
1111
#include "smbacl.h"
1212

13-
/*
14-
* Note that, due to trying to use names similar to the protocol specifications,
15-
* there are many mixed case field names in the structures below. Although
16-
* this does not match typical Linux kernel style, it is necessary to be
17-
* able to match against the protocol specfication.
18-
*
19-
* SMB2 commands
20-
* Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
21-
* (ie no useful data other than the SMB error code itself) and are marked such.
22-
* Knowing this helps avoid response buffer allocations and copy in some cases.
23-
*/
24-
25-
/* List of commands in host endian */
26-
#define SMB2_NEGOTIATE_HE 0x0000
27-
#define SMB2_SESSION_SETUP_HE 0x0001
28-
#define SMB2_LOGOFF_HE 0x0002 /* trivial request/resp */
29-
#define SMB2_TREE_CONNECT_HE 0x0003
30-
#define SMB2_TREE_DISCONNECT_HE 0x0004 /* trivial req/resp */
31-
#define SMB2_CREATE_HE 0x0005
32-
#define SMB2_CLOSE_HE 0x0006
33-
#define SMB2_FLUSH_HE 0x0007 /* trivial resp */
34-
#define SMB2_READ_HE 0x0008
35-
#define SMB2_WRITE_HE 0x0009
36-
#define SMB2_LOCK_HE 0x000A
37-
#define SMB2_IOCTL_HE 0x000B
38-
#define SMB2_CANCEL_HE 0x000C
39-
#define SMB2_ECHO_HE 0x000D
40-
#define SMB2_QUERY_DIRECTORY_HE 0x000E
41-
#define SMB2_CHANGE_NOTIFY_HE 0x000F
42-
#define SMB2_QUERY_INFO_HE 0x0010
43-
#define SMB2_SET_INFO_HE 0x0011
44-
#define SMB2_OPLOCK_BREAK_HE 0x0012
45-
46-
/* The same list in little endian */
47-
#define SMB2_NEGOTIATE cpu_to_le16(SMB2_NEGOTIATE_HE)
48-
#define SMB2_SESSION_SETUP cpu_to_le16(SMB2_SESSION_SETUP_HE)
49-
#define SMB2_LOGOFF cpu_to_le16(SMB2_LOGOFF_HE)
50-
#define SMB2_TREE_CONNECT cpu_to_le16(SMB2_TREE_CONNECT_HE)
51-
#define SMB2_TREE_DISCONNECT cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
52-
#define SMB2_CREATE cpu_to_le16(SMB2_CREATE_HE)
53-
#define SMB2_CLOSE cpu_to_le16(SMB2_CLOSE_HE)
54-
#define SMB2_FLUSH cpu_to_le16(SMB2_FLUSH_HE)
55-
#define SMB2_READ cpu_to_le16(SMB2_READ_HE)
56-
#define SMB2_WRITE cpu_to_le16(SMB2_WRITE_HE)
57-
#define SMB2_LOCK cpu_to_le16(SMB2_LOCK_HE)
58-
#define SMB2_IOCTL cpu_to_le16(SMB2_IOCTL_HE)
59-
#define SMB2_CANCEL cpu_to_le16(SMB2_CANCEL_HE)
60-
#define SMB2_ECHO cpu_to_le16(SMB2_ECHO_HE)
61-
#define SMB2_QUERY_DIRECTORY cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
62-
#define SMB2_CHANGE_NOTIFY cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
63-
#define SMB2_QUERY_INFO cpu_to_le16(SMB2_QUERY_INFO_HE)
64-
#define SMB2_SET_INFO cpu_to_le16(SMB2_SET_INFO_HE)
65-
#define SMB2_OPLOCK_BREAK cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
66-
6713
/*Create Action Flags*/
6814
#define FILE_SUPERSEDED 0x00000000
6915
#define FILE_OPENED 0x00000001
@@ -107,77 +53,12 @@
10753
/* BB FIXME - analyze following length BB */
10854
#define MAX_SMB2_HDR_SIZE 0x78 /* 4 len + 64 hdr + (2*24 wct) + 2 bct + 2 pad */
10955

110-
#define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe) /* 'B''M''S' */
111-
#define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
112-
11356
#define SMB21_DEFAULT_IOSIZE (1024 * 1024)
11457
#define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
11558
#define SMB3_DEFAULT_TRANS_SIZE (1024 * 1024)
11659
#define SMB3_MIN_IOSIZE (64 * 1024)
11760
#define SMB3_MAX_IOSIZE (8 * 1024 * 1024)
11861

119-
/*
120-
* SMB2 Header Definition
121-
*
122-
* "MBZ" : Must be Zero
123-
* "BB" : BugBug, Something to check/review/analyze later
124-
* "PDU" : "Protocol Data Unit" (ie a network "frame")
125-
*
126-
*/
127-
128-
#define __SMB2_HEADER_STRUCTURE_SIZE 64
129-
#define SMB2_HEADER_STRUCTURE_SIZE \
130-
cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE)
131-
132-
struct smb2_hdr {
133-
__le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
134-
__le16 StructureSize; /* 64 */
135-
__le16 CreditCharge; /* MBZ */
136-
__le32 Status; /* Error from server */
137-
__le16 Command;
138-
__le16 CreditRequest; /* CreditResponse */
139-
__le32 Flags;
140-
__le32 NextCommand;
141-
__le64 MessageId;
142-
union {
143-
struct {
144-
__le32 ProcessId;
145-
__le32 TreeId;
146-
} __packed SyncId;
147-
__le64 AsyncId;
148-
} __packed Id;
149-
__le64 SessionId;
150-
__u8 Signature[16];
151-
} __packed;
152-
153-
struct smb2_pdu {
154-
struct smb2_hdr hdr;
155-
__le16 StructureSize2; /* size of wct area (varies, request specific) */
156-
} __packed;
157-
158-
#define SMB3_AES_CCM_NONCE 11
159-
#define SMB3_AES_GCM_NONCE 12
160-
161-
struct smb2_transform_hdr {
162-
__le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */
163-
__u8 Signature[16];
164-
__u8 Nonce[16];
165-
__le32 OriginalMessageSize;
166-
__u16 Reserved1;
167-
__le16 Flags; /* EncryptionAlgorithm */
168-
__le64 SessionId;
169-
} __packed;
170-
171-
/*
172-
* SMB2 flag definitions
173-
*/
174-
#define SMB2_FLAGS_SERVER_TO_REDIR cpu_to_le32(0x00000001)
175-
#define SMB2_FLAGS_ASYNC_COMMAND cpu_to_le32(0x00000002)
176-
#define SMB2_FLAGS_RELATED_OPERATIONS cpu_to_le32(0x00000004)
177-
#define SMB2_FLAGS_SIGNED cpu_to_le32(0x00000008)
178-
#define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000)
179-
#define SMB2_FLAGS_REPLAY_OPERATIONS cpu_to_le32(0x20000000)
180-
18162
/*
18263
* Definitions for SMB2 Protocol Data Units (network frames)
18364
*
@@ -410,63 +291,6 @@ struct smb2_logoff_rsp {
410291
__le16 Reserved;
411292
} __packed;
412293

413-
struct smb2_tree_connect_req {
414-
struct smb2_hdr hdr;
415-
__le16 StructureSize; /* Must be 9 */
416-
__le16 Reserved; /* Flags in SMB3.1.1 */
417-
__le16 PathOffset;
418-
__le16 PathLength;
419-
__u8 Buffer[1]; /* variable length */
420-
} __packed;
421-
422-
struct smb2_tree_connect_rsp {
423-
struct smb2_hdr hdr;
424-
__le16 StructureSize; /* Must be 16 */
425-
__u8 ShareType; /* see below */
426-
__u8 Reserved;
427-
__le32 ShareFlags; /* see below */
428-
__le32 Capabilities; /* see below */
429-
__le32 MaximalAccess;
430-
} __packed;
431-
432-
/* Possible ShareType values */
433-
#define SMB2_SHARE_TYPE_DISK 0x01
434-
#define SMB2_SHARE_TYPE_PIPE 0x02
435-
#define SMB2_SHARE_TYPE_PRINT 0x03
436-
437-
/*
438-
* Possible ShareFlags - exactly one and only one of the first 4 caching flags
439-
* must be set (any of the remaining, SHI1005, flags may be set individually
440-
* or in combination.
441-
*/
442-
#define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
443-
#define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
444-
#define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
445-
#define SMB2_SHAREFLAG_NO_CACHING 0x00000030
446-
#define SHI1005_FLAGS_DFS 0x00000001
447-
#define SHI1005_FLAGS_DFS_ROOT 0x00000002
448-
#define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
449-
#define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
450-
#define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
451-
#define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
452-
#define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
453-
#define SHI1005_FLAGS_ENABLE_HASH 0x00002000
454-
455-
/* Possible share capabilities */
456-
#define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008)
457-
458-
struct smb2_tree_disconnect_req {
459-
struct smb2_hdr hdr;
460-
__le16 StructureSize; /* Must be 4 */
461-
__le16 Reserved;
462-
} __packed;
463-
464-
struct smb2_tree_disconnect_rsp {
465-
struct smb2_hdr hdr;
466-
__le16 StructureSize; /* Must be 4 */
467-
__le16 Reserved;
468-
} __packed;
469-
470294
#define ATTR_READONLY_LE cpu_to_le32(ATTR_READONLY)
471295
#define ATTR_HIDDEN_LE cpu_to_le32(ATTR_HIDDEN)
472296
#define ATTR_SYSTEM_LE cpu_to_le32(ATTR_SYSTEM)

fs/ksmbd/smb_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "glob.h"
1212
#include "nterr.h"
13+
#include "../smbfs_common/smb2pdu.h"
1314
#include "smb2pdu.h"
1415

1516
/* ksmbd's Specific ERRNO */

0 commit comments

Comments
 (0)