Skip to content

Commit b51174d

Browse files
ChenXiaoSongsmfrench
authored andcommitted
smb: move some duplicate definitions to common/smbacl.h
In order to maintain the code more easily, move duplicate definitions to new common header file. Signed-off-by: ChenXiaoSong <[email protected]> Acked-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 09bedaf commit b51174d

File tree

3 files changed

+123
-200
lines changed

3 files changed

+123
-200
lines changed

fs/smb/client/cifsacl.h

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#ifndef _CIFSACL_H
1010
#define _CIFSACL_H
1111

12-
#define NUM_AUTHS (6) /* number of authority fields */
13-
#define SID_MAX_SUB_AUTHORITIES (15) /* max number of sub authority fields */
12+
#include "../common/smbacl.h"
1413

1514
#define READ_BIT 0x4
1615
#define WRITE_BIT 0x2
@@ -23,12 +22,6 @@
2322
#define UBITSHIFT 6
2423
#define GBITSHIFT 3
2524

26-
#define ACCESS_ALLOWED 0
27-
#define ACCESS_DENIED 1
28-
29-
#define SIDOWNER 1
30-
#define SIDGROUP 2
31-
3225
/*
3326
* Security Descriptor length containing DACL with 3 ACEs (one each for
3427
* owner, group and world).
@@ -37,88 +30,6 @@
3730
sizeof(struct smb_acl) + \
3831
(sizeof(struct smb_ace) * 4))
3932

40-
/*
41-
* Maximum size of a string representation of a SID:
42-
*
43-
* The fields are unsigned values in decimal. So:
44-
*
45-
* u8: max 3 bytes in decimal
46-
* u32: max 10 bytes in decimal
47-
*
48-
* "S-" + 3 bytes for version field + 15 for authority field + NULL terminator
49-
*
50-
* For authority field, max is when all 6 values are non-zero and it must be
51-
* represented in hex. So "-0x" + 12 hex digits.
52-
*
53-
* Add 11 bytes for each subauthority field (10 bytes each + 1 for '-')
54-
*/
55-
#define SID_STRING_BASE_SIZE (2 + 3 + 15 + 1)
56-
#define SID_STRING_SUBAUTH_SIZE (11) /* size of a single subauth string */
57-
58-
struct smb_ntsd {
59-
__le16 revision; /* revision level */
60-
__le16 type;
61-
__le32 osidoffset;
62-
__le32 gsidoffset;
63-
__le32 sacloffset;
64-
__le32 dacloffset;
65-
} __attribute__((packed));
66-
67-
struct smb_sid {
68-
__u8 revision; /* revision level */
69-
__u8 num_subauth;
70-
__u8 authority[NUM_AUTHS];
71-
__le32 sub_auth[SID_MAX_SUB_AUTHORITIES]; /* sub_auth[num_subauth] */
72-
} __attribute__((packed));
73-
74-
/* size of a struct smb_sid, sans sub_auth array */
75-
#define CIFS_SID_BASE_SIZE (1 + 1 + NUM_AUTHS)
76-
77-
struct smb_acl {
78-
__le16 revision; /* revision level */
79-
__le16 size;
80-
__le32 num_aces;
81-
} __attribute__((packed));
82-
83-
/* ACE types - see MS-DTYP 2.4.4.1 */
84-
#define ACCESS_ALLOWED_ACE_TYPE 0x00
85-
#define ACCESS_DENIED_ACE_TYPE 0x01
86-
#define SYSTEM_AUDIT_ACE_TYPE 0x02
87-
#define SYSTEM_ALARM_ACE_TYPE 0x03
88-
#define ACCESS_ALLOWED_COMPOUND_ACE_TYPE 0x04
89-
#define ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05
90-
#define ACCESS_DENIED_OBJECT_ACE_TYPE 0x06
91-
#define SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07
92-
#define SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08
93-
#define ACCESS_ALLOWED_CALLBACK_ACE_TYPE 0x09
94-
#define ACCESS_DENIED_CALLBACK_ACE_TYPE 0x0A
95-
#define ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE 0x0B
96-
#define ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE 0x0C
97-
#define SYSTEM_AUDIT_CALLBACK_ACE_TYPE 0x0D
98-
#define SYSTEM_ALARM_CALLBACK_ACE_TYPE 0x0E /* Reserved */
99-
#define SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE 0x0F
100-
#define SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE 0x10 /* reserved */
101-
#define SYSTEM_MANDATORY_LABEL_ACE_TYPE 0x11
102-
#define SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE 0x12
103-
#define SYSTEM_SCOPED_POLICY_ID_ACE_TYPE 0x13
104-
105-
/* ACE flags */
106-
#define OBJECT_INHERIT_ACE 0x01
107-
#define CONTAINER_INHERIT_ACE 0x02
108-
#define NO_PROPAGATE_INHERIT_ACE 0x04
109-
#define INHERIT_ONLY_ACE 0x08
110-
#define INHERITED_ACE 0x10
111-
#define SUCCESSFUL_ACCESS_ACE_FLAG 0x40
112-
#define FAILED_ACCESS_ACE_FLAG 0x80
113-
114-
struct smb_ace {
115-
__u8 type; /* see above and MS-DTYP 2.4.4.1 */
116-
__u8 flags;
117-
__le16 size;
118-
__le32 access_req;
119-
struct smb_sid sid; /* ie UUID of user or group who gets these perms */
120-
} __attribute__((packed));
121-
12233
/*
12334
* The current SMB3 form of security descriptor is similar to what was used for
12435
* cifs (see above) but some fields are split, and fields in the struct below

fs/smb/common/smbacl.h

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/* SPDX-License-Identifier: LGPL-2.1+ */
2+
/*
3+
* Copyright (c) International Business Machines Corp., 2007
4+
* Author(s): Steve French ([email protected])
5+
* Modified by Namjae Jeon ([email protected])
6+
*/
7+
8+
#ifndef _COMMON_SMBACL_H
9+
#define _COMMON_SMBACL_H
10+
11+
#define NUM_AUTHS (6) /* number of authority fields */
12+
#define SID_MAX_SUB_AUTHORITIES (15) /* max number of sub authority fields */
13+
14+
/* ACE types - see MS-DTYP 2.4.4.1 */
15+
#define ACCESS_ALLOWED_ACE_TYPE 0x00
16+
#define ACCESS_DENIED_ACE_TYPE 0x01
17+
#define SYSTEM_AUDIT_ACE_TYPE 0x02
18+
#define SYSTEM_ALARM_ACE_TYPE 0x03
19+
#define ACCESS_ALLOWED_COMPOUND_ACE_TYPE 0x04
20+
#define ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05
21+
#define ACCESS_DENIED_OBJECT_ACE_TYPE 0x06
22+
#define SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07
23+
#define SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08
24+
#define ACCESS_ALLOWED_CALLBACK_ACE_TYPE 0x09
25+
#define ACCESS_DENIED_CALLBACK_ACE_TYPE 0x0A
26+
#define ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE 0x0B
27+
#define ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE 0x0C
28+
#define SYSTEM_AUDIT_CALLBACK_ACE_TYPE 0x0D
29+
#define SYSTEM_ALARM_CALLBACK_ACE_TYPE 0x0E /* Reserved */
30+
#define SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE 0x0F
31+
#define SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE 0x10 /* reserved */
32+
#define SYSTEM_MANDATORY_LABEL_ACE_TYPE 0x11
33+
#define SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE 0x12
34+
#define SYSTEM_SCOPED_POLICY_ID_ACE_TYPE 0x13
35+
36+
/* ACE flags */
37+
#define OBJECT_INHERIT_ACE 0x01
38+
#define CONTAINER_INHERIT_ACE 0x02
39+
#define NO_PROPAGATE_INHERIT_ACE 0x04
40+
#define INHERIT_ONLY_ACE 0x08
41+
#define INHERITED_ACE 0x10
42+
#define SUCCESSFUL_ACCESS_ACE_FLAG 0x40
43+
#define FAILED_ACCESS_ACE_FLAG 0x80
44+
45+
/*
46+
* Maximum size of a string representation of a SID:
47+
*
48+
* The fields are unsigned values in decimal. So:
49+
*
50+
* u8: max 3 bytes in decimal
51+
* u32: max 10 bytes in decimal
52+
*
53+
* "S-" + 3 bytes for version field + 15 for authority field + NULL terminator
54+
*
55+
* For authority field, max is when all 6 values are non-zero and it must be
56+
* represented in hex. So "-0x" + 12 hex digits.
57+
*
58+
* Add 11 bytes for each subauthority field (10 bytes each + 1 for '-')
59+
*/
60+
#define SID_STRING_BASE_SIZE (2 + 3 + 15 + 1)
61+
#define SID_STRING_SUBAUTH_SIZE (11) /* size of a single subauth string */
62+
63+
#define DOMAIN_USER_RID_LE cpu_to_le32(513)
64+
65+
/*
66+
* ACE types - see MS-DTYP 2.4.4.1
67+
*/
68+
enum {
69+
ACCESS_ALLOWED,
70+
ACCESS_DENIED,
71+
};
72+
73+
/*
74+
* Security ID types
75+
*/
76+
enum {
77+
SIDOWNER = 1,
78+
SIDGROUP,
79+
SIDCREATOR_OWNER,
80+
SIDCREATOR_GROUP,
81+
SIDUNIX_USER,
82+
SIDUNIX_GROUP,
83+
SIDNFS_USER,
84+
SIDNFS_GROUP,
85+
SIDNFS_MODE,
86+
};
87+
88+
struct smb_ntsd {
89+
__le16 revision; /* revision level */
90+
__le16 type;
91+
__le32 osidoffset;
92+
__le32 gsidoffset;
93+
__le32 sacloffset;
94+
__le32 dacloffset;
95+
} __attribute__((packed));
96+
97+
struct smb_sid {
98+
__u8 revision; /* revision level */
99+
__u8 num_subauth;
100+
__u8 authority[NUM_AUTHS];
101+
__le32 sub_auth[SID_MAX_SUB_AUTHORITIES]; /* sub_auth[num_subauth] */
102+
} __attribute__((packed));
103+
104+
/* size of a struct smb_sid, sans sub_auth array */
105+
#define CIFS_SID_BASE_SIZE (1 + 1 + NUM_AUTHS)
106+
107+
struct smb_acl {
108+
__le16 revision; /* revision level */
109+
__le16 size;
110+
__le32 num_aces;
111+
} __attribute__((packed));
112+
113+
struct smb_ace {
114+
__u8 type; /* see above and MS-DTYP 2.4.4.1 */
115+
__u8 flags;
116+
__le16 size;
117+
__le32 access_req;
118+
struct smb_sid sid; /* ie UUID of user or group who gets these perms */
119+
} __attribute__((packed));
120+
121+
#endif /* _COMMON_SMBACL_H */

fs/smb/server/smbacl.h

Lines changed: 1 addition & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,14 @@
88
#ifndef _SMBACL_H
99
#define _SMBACL_H
1010

11+
#include "../common/smbacl.h"
1112
#include <linux/fs.h>
1213
#include <linux/namei.h>
1314
#include <linux/posix_acl.h>
1415
#include <linux/mnt_idmapping.h>
1516

1617
#include "mgmt/tree_connect.h"
1718

18-
#define NUM_AUTHS (6) /* number of authority fields */
19-
#define SID_MAX_SUB_AUTHORITIES (15) /* max number of sub authority fields */
20-
21-
/*
22-
* ACE types - see MS-DTYP 2.4.4.1
23-
*/
24-
enum {
25-
ACCESS_ALLOWED,
26-
ACCESS_DENIED,
27-
};
28-
29-
/*
30-
* Security ID types
31-
*/
32-
enum {
33-
SIDOWNER = 1,
34-
SIDGROUP,
35-
SIDCREATOR_OWNER,
36-
SIDCREATOR_GROUP,
37-
SIDUNIX_USER,
38-
SIDUNIX_GROUP,
39-
SIDNFS_USER,
40-
SIDNFS_GROUP,
41-
SIDNFS_MODE,
42-
};
43-
4419
/* Revision for ACLs */
4520
#define SD_REVISION 1
4621

@@ -62,92 +37,8 @@ enum {
6237
#define RM_CONTROL_VALID 0x4000
6338
#define SELF_RELATIVE 0x8000
6439

65-
/* ACE types - see MS-DTYP 2.4.4.1 */
66-
#define ACCESS_ALLOWED_ACE_TYPE 0x00
67-
#define ACCESS_DENIED_ACE_TYPE 0x01
68-
#define SYSTEM_AUDIT_ACE_TYPE 0x02
69-
#define SYSTEM_ALARM_ACE_TYPE 0x03
70-
#define ACCESS_ALLOWED_COMPOUND_ACE_TYPE 0x04
71-
#define ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05
72-
#define ACCESS_DENIED_OBJECT_ACE_TYPE 0x06
73-
#define SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07
74-
#define SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08
75-
#define ACCESS_ALLOWED_CALLBACK_ACE_TYPE 0x09
76-
#define ACCESS_DENIED_CALLBACK_ACE_TYPE 0x0A
77-
#define ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE 0x0B
78-
#define ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE 0x0C
79-
#define SYSTEM_AUDIT_CALLBACK_ACE_TYPE 0x0D
80-
#define SYSTEM_ALARM_CALLBACK_ACE_TYPE 0x0E /* Reserved */
81-
#define SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE 0x0F
82-
#define SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE 0x10 /* reserved */
83-
#define SYSTEM_MANDATORY_LABEL_ACE_TYPE 0x11
84-
#define SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE 0x12
85-
#define SYSTEM_SCOPED_POLICY_ID_ACE_TYPE 0x13
86-
87-
/* ACE flags */
88-
#define OBJECT_INHERIT_ACE 0x01
89-
#define CONTAINER_INHERIT_ACE 0x02
90-
#define NO_PROPAGATE_INHERIT_ACE 0x04
91-
#define INHERIT_ONLY_ACE 0x08
92-
#define INHERITED_ACE 0x10
93-
#define SUCCESSFUL_ACCESS_ACE_FLAG 0x40
94-
#define FAILED_ACCESS_ACE_FLAG 0x80
95-
96-
/*
97-
* Maximum size of a string representation of a SID:
98-
*
99-
* The fields are unsigned values in decimal. So:
100-
*
101-
* u8: max 3 bytes in decimal
102-
* u32: max 10 bytes in decimal
103-
*
104-
* "S-" + 3 bytes for version field + 15 for authority field + NULL terminator
105-
*
106-
* For authority field, max is when all 6 values are non-zero and it must be
107-
* represented in hex. So "-0x" + 12 hex digits.
108-
*
109-
* Add 11 bytes for each subauthority field (10 bytes each + 1 for '-')
110-
*/
111-
#define SID_STRING_BASE_SIZE (2 + 3 + 15 + 1)
112-
#define SID_STRING_SUBAUTH_SIZE (11) /* size of a single subauth string */
113-
114-
#define DOMAIN_USER_RID_LE cpu_to_le32(513)
115-
11640
struct ksmbd_conn;
11741

118-
struct smb_ntsd {
119-
__le16 revision; /* revision level */
120-
__le16 type;
121-
__le32 osidoffset;
122-
__le32 gsidoffset;
123-
__le32 sacloffset;
124-
__le32 dacloffset;
125-
} __packed;
126-
127-
struct smb_sid {
128-
__u8 revision; /* revision level */
129-
__u8 num_subauth;
130-
__u8 authority[NUM_AUTHS];
131-
__le32 sub_auth[SID_MAX_SUB_AUTHORITIES]; /* sub_auth[num_subauth] */
132-
} __packed;
133-
134-
/* size of a struct cifs_sid, sans sub_auth array */
135-
#define CIFS_SID_BASE_SIZE (1 + 1 + NUM_AUTHS)
136-
137-
struct smb_acl {
138-
__le16 revision; /* revision level */
139-
__le16 size;
140-
__le32 num_aces;
141-
} __packed;
142-
143-
struct smb_ace {
144-
__u8 type;
145-
__u8 flags;
146-
__le16 size;
147-
__le32 access_req;
148-
struct smb_sid sid; /* ie UUID of user or group who gets these perms */
149-
} __packed;
150-
15142
struct smb_fattr {
15243
kuid_t cf_uid;
15344
kgid_t cf_gid;

0 commit comments

Comments
 (0)