cifs: cifsacl cleanups
Subsystems (2)
cover cifs: cifsacl cleanups
Just some nits I noticed while trying to understand how this code works. Nothing in here that can't wait until 3.8...
Jeff Layton (4):
cifs: clean up id_mode_to_cifs_acl
cifs: move num_subauth check inside of CONFIG_CIFS_DEBUG2 check in
parse_sid()
cifs: use the NUM_AUTHS and NUM_SUBAUTHS constants in cifsacl code
cifs: make compare_sids static
fs/cifs/cifsacl.c | 159 +++++++++++++++++++++++++++--------------------------- fs/cifs/cifsacl.h | 6 +-- 2 files changed, 81 insertions(+), 84 deletions(-)
Signature · 1 line
1.7.11.7
PATCH 1/4 cifs: clean up id_mode_to_cifs_acl
In reply to a message not in the archiveAdd a label we can goto on error, and get rid of some excess indentation. Also move to kernel-style comments.
--- fs/cifs/cifsacl.c | 53 +++++++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 28 deletions(-)
fs/cifs/cifsacl.c +25 -28
@@ -1307,42 +1307,39 @@ id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 nmode,/* Get the security descriptor */ pntsd =get_cifs_acl (CIFS_SB (inode->i_sb), inode, path, &secdesclen); - -/* Add three ACEs for owner, group, everyone getting rid of -other ACEs as chmod disables ACEs and set the security descriptor */ -if (IS_ERR (pntsd)) { rc =PTR_ERR (pntsd);cERROR (1 ,"%s: error %d getting sec desc" , __func__, rc); - }else { -/* allocate memory for the smb header, -set security descriptor request security descriptor -parameters, and secuirty descriptor itself */ - - secdesclen = secdesclen <DEFSECDESCLEN ? -DEFSECDESCLEN : secdesclen; - pnntsd =kmalloc (secdesclen,GFP_KERNEL ); -if (!pnntsd) { -cERROR (1 ,"Unable to allocate security descriptor" ); -kfree (pntsd); -return -ENOMEM ; - } + goto out; + } - rc =build_sec_desc (pntsd, pnntsd, secdesclen, nmode, uid, gid, - &aclflag); +/* +* Add three ACEs for owner, group, everyone getting rid of other ACEs +* as chmod disables ACEs and set the security descriptor allocate +* memory for the smb header, set security descriptor request security +* descriptor parameters, and secuirty descriptor itself +*/ + secdesclen =max_t (u32, secdesclen,DEFSECDESCLEN ); + pnntsd =kmalloc (secdesclen,GFP_KERNEL ); +if (!pnntsd) { +cERROR (1 ,"Unable to allocate security descriptor" ); +kfree (pntsd); +return -ENOMEM ; + } -cFYI (DBG2 ,"build_sec_desc rc: %d" , rc); + rc =build_sec_desc (pntsd, pnntsd, secdesclen, nmode, uid, gid, + &aclflag); -if (!rc) { -/* Set the security descriptor */ - rc =set_cifs_acl (pnntsd, secdesclen, inode, - path, aclflag); -cFYI (DBG2 ,"set_cifs_acl rc: %d" , rc); - } +cFYI (DBG2 ,"build_sec_desc rc: %d" , rc); -kfree (pnntsd); -kfree (pntsd); +if (!rc) { +/* Set the security descriptor */ + rc =set_cifs_acl (pnntsd, secdesclen, inode, path, aclflag); +cFYI (DBG2 ,"set_cifs_acl rc: %d" , rc); } +kfree (pnntsd); +kfree (pntsd); +out:return rc; }
Signature · 1 line
1.7.11.7
PATCH 2/4 cifs: move num_subauth check inside of CONFIG_CIFS_DEBUG2 check in parse_sid()
In reply to a message not in the archive--- fs/cifs/cifsacl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/cifs/cifsacl.c +2 -2
@@ -987,8 +987,8 @@ static int parse_sid(struct cifs_sid *psid, char *end_of_acl)return -EINVAL ; } -if (psid->num_subauth) {#ifdef CONFIG_CIFS_DEBUG2 +if (psid->num_subauth) {int i;cFYI (1 ,"SID revision %d num_auth %d" , psid->revision, psid->num_subauth);
@@ -1002,8 +1002,8 @@ static int parse_sid(struct cifs_sid *psid, char *end_of_acl)num auths and therefore go off the end */ cFYI (1 ,"RID 0x%x" , le32_to_cpu(psid->sub_auth[psid->num_subauth-1])); -#endif } +#endif return 0 ; }
Signature · 1 line
1.7.11.7
PATCH 3/4 cifs: use the NUM_AUTHS and NUM_SUBAUTHS constants in cifsacl code
In reply to a message not in the archive...instead of hardcoding in '5' and '6' all over the place.
--- fs/cifs/cifsacl.c | 6 +++--- fs/cifs/cifsacl.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)
fs/cifs/cifsacl.c +3 -3
@@ -210,7 +210,7 @@ sid_to_str(struct cifs_sid *sidptr, char *sidstr)sprintf (strptr,"-%d" , sidptr->revision); strptr = sidstr +strlen (sidstr); -for (i =0 ; i <6 ; ++i) { +for (i =0 ; i <NUM_AUTHS ; ++i) {if (sidptr->authority[i]) {sprintf (strptr,"-%d" , sidptr->authority[i]); strptr = sidstr +strlen (sidstr);
@@ -649,7 +649,7 @@ int compare_sids(const struct cifs_sid *ctsid, const struct cifs_sid *cwsid) }/* compare all of the six auth values */ -for (i =0 ; i <6 ; ++i) { +for (i =0 ; i <NUM_AUTHS ; ++i) {if (ctsid->authority[i] != cwsid->authority[i]) {if (ctsid->authority[i] > cwsid->authority[i])return 1 ;
@@ -811,7 +811,7 @@ static __u16 fill_ace_for_sid(struct cifs_ace *pntace, pntace->sid.revision = psid->revision; pntace->sid.num_subauth = psid->num_subauth; -for (i =0 ; i <6 ; i++) +for (i =0 ; i <NUM_AUTHS ; i++) pntace->sid.authority[i] = psid->authority[i];for (i =0 ; i < psid->num_subauth; i++) pntace->sid.sub_auth[i] = psid->sub_auth[i];
fs/cifs/cifsacl.h +2 -2
@@ -60,8 +60,8 @@ struct cifs_ntsd {struct cifs_sid {__u8 revision;/* revision level */ __u8 num_subauth; -__u8 authority[6 ]; -__le32 sub_auth[5 ];/* sub_auth[num_subauth] */ +__u8 authority[NUM_AUTHS ]; +__le32 sub_auth[NUM_SUBAUTHS ];/* sub_auth[num_subauth] */ } __attribute__((packed));struct cifs_acl {
Signature · 1 line
1.7.11.7
PATCH 4/4 cifs: make compare_sids static
In reply to a message not in the archive..nothing outside of cifsacl.c calls it. Also fix the incorrect comment on the function. It returns 0 when they match.
--- fs/cifs/cifsacl.c | 98 ++++++++++++++++++++++++++++--------------------------- fs/cifs/cifsacl.h | 2 -- 2 files changed, 50 insertions(+), 50 deletions(-)
fs/cifs/cifsacl.c +50 -48
@@ -224,6 +224,56 @@ sid_to_str(struct cifs_sid *sidptr, char *sidstr) } } +/* +* if the two SIDs (roughly equivalent to a UUID for a user or group) are +* the same returns zero, if they do not match returns non-zero. +*/ +static int +compare_sids (const struct cifs_sid *ctsid,const struct cifs_sid *cwsid) +{ +int i; +int num_subauth, num_sat, num_saw; + +if ((!ctsid) || (!cwsid)) +return 1 ; + +/* compare the revision */ +if (ctsid->revision != cwsid->revision) { +if (ctsid->revision > cwsid->revision) +return 1 ; +else +return -1 ; + } + +/* compare all of the six auth values */ +for (i =0 ; i <NUM_AUTHS ; ++i) { +if (ctsid->authority[i] != cwsid->authority[i]) { +if (ctsid->authority[i] > cwsid->authority[i]) +return 1 ; +else +return -1 ; + } + } + +/* compare all of the subauth values if any */ + num_sat = ctsid->num_subauth; + num_saw = cwsid->num_subauth; + num_subauth = num_sat < num_saw ? num_sat : num_saw; +if (num_subauth) { +for (i =0 ; i < num_subauth; ++i) { +if (ctsid->sub_auth[i] != cwsid->sub_auth[i]) { +if (le32_to_cpu (ctsid->sub_auth[i]) > +le32_to_cpu (cwsid->sub_auth[i])) +return 1 ; +else +return -1 ; + } + } + } + +return 0 ;/* sids compare/match */ +} +static void cifs_copy_sid (struct cifs_sid *dst,const struct cifs_sid *src) {
@@ -630,54 +680,6 @@ cifs_destroy_idmaptrees(void)spin_unlock (&gidsidlock); } -/* if the two SIDs (roughly equivalent to a UUID for a user or group) are -the same returns 1, if they do not match returns 0 */ -int compare_sids (const struct cifs_sid *ctsid,const struct cifs_sid *cwsid) -{ -int i; -int num_subauth, num_sat, num_saw; - -if ((!ctsid) || (!cwsid)) -return 1 ; - -/* compare the revision */ -if (ctsid->revision != cwsid->revision) { -if (ctsid->revision > cwsid->revision) -return 1 ; -else -return -1 ; - } - -/* compare all of the six auth values */ -for (i =0 ; i <NUM_AUTHS ; ++i) { -if (ctsid->authority[i] != cwsid->authority[i]) { -if (ctsid->authority[i] > cwsid->authority[i]) -return 1 ; -else -return -1 ; - } - } - -/* compare all of the subauth values if any */ - num_sat = ctsid->num_subauth; - num_saw = cwsid->num_subauth; - num_subauth = num_sat < num_saw ? num_sat : num_saw; -if (num_subauth) { -for (i =0 ; i < num_subauth; ++i) { -if (ctsid->sub_auth[i] != cwsid->sub_auth[i]) { -if (le32_to_cpu (ctsid->sub_auth[i]) > -le32_to_cpu (cwsid->sub_auth[i])) -return 1 ; -else -return -1 ; - } - } - } - -return 0 ;/* sids compare/match */ -} - -/* copy ntsd, owner sid, and group sid from a security descriptor to another */ static void copy_sec_desc (const struct cifs_ntsd *pntsd,struct cifs_ntsd *pnntsd,__u32 sidsoffset)
fs/cifs/cifsacl.h +0 -2
@@ -98,6 +98,4 @@ extern struct key_type cifs_idmap_key_type;extern const struct cred *root_cred;#endif /* KERNEL */ -extern int compare_sids (const struct cifs_sid *,const struct cifs_sid *); -#endif /* _CIFSACL_H */
Signature · 1 line
1.7.11.7
Shirish Pargaonkar
Reviewed-byRe: [PATCH 1/4] cifs: clean up id_mode_to_cifs_acl
In reply to a message not in the archiveQuoted 83 lines · Jeff Layton
Add a label we can goto on error, and get rid of some excess indentation. Also move to kernel-style comments.
Signed-off-by Jeff Layton <[email protected]>--- fs/cifs/cifsacl.c | 53 +++++++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 28 deletions(-)fs/cifs/cifsacl.c +25
-29@@ -1307,42 +1307,39 @@ id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 nmode,/* Get the security descriptor */ pntsd =get_cifs_acl (CIFS_SB (inode->i_sb), inode, path, &secdesclen); - -/* Add three ACEs for owner, group, everyone getting rid of -other ACEs as chmod disables ACEs and set the security descriptor */ -if (IS_ERR (pntsd)) { rc =PTR_ERR (pntsd);cERROR (1 ,"%s: error %d getting sec desc" , __func__, rc); - }else { -/* allocate memory for the smb header, -set security descriptor request security descriptor -parameters, and secuirty descriptor itself */ - - secdesclen = secdesclen <DEFSECDESCLEN ? -DEFSECDESCLEN : secdesclen; - pnntsd =kmalloc (secdesclen,GFP_KERNEL ); -if (!pnntsd) { -cERROR (1 ,"Unable to allocate security descriptor" ); -kfree (pntsd); -return -ENOMEM ; - } + goto out; + } - rc =build_sec_desc (pntsd, pnntsd, secdesclen, nmode, uid, gid, - &aclflag); +/* +* Add three ACEs for owner, group, everyone getting rid of other ACEs +* as chmod disables ACEs and set the security descriptor allocate +* memory for the smb header, set security descriptor request security +* descriptor parameters, and secuirty descriptor itself +*/ + secdesclen =max_t (u32, secdesclen,DEFSECDESCLEN ); + pnntsd =kmalloc (secdesclen,GFP_KERNEL ); +if (!pnntsd) { +cERROR (1 ,"Unable to allocate security descriptor" ); +kfree (pntsd); +return -ENOMEM ; + } -cFYI (DBG2 ,"build_sec_desc rc: %d" , rc); + rc =build_sec_desc (pntsd, pnntsd, secdesclen, nmode, uid, gid, + &aclflag); -if (!rc) { -/* Set the security descriptor */ - rc =set_cifs_acl (pnntsd, secdesclen, inode, - path, aclflag); -cFYI (DBG2 ,"set_cifs_acl rc: %d" , rc); - } +cFYI (DBG2 ,"build_sec_desc rc: %d" , rc); -kfree (pnntsd); -kfree (pntsd); +if (!rc) { +/* Set the security descriptor */ + rc =set_cifs_acl (pnntsd, secdesclen, inode, path, aclflag); +cFYI (DBG2 ,"set_cifs_acl rc: %d" , rc); } +kfree (pnntsd); +kfree (pntsd); +out:return rc; } --1.7.11.7
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
This looks correct.
Shirish Pargaonkar
Reviewed-byRe: [PATCH 2/4] cifs: move num_subauth check inside of CONFIG_CIFS_DEBUG2 check in parse_sid()
In reply to a message not in the archiveQuoted 33 lines · Jeff Layton
Cc Shirish Pargaonkar <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/cifs/cifsacl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/cifs/cifsacl.c +2
-3@@ -987,8 +987,8 @@ static int parse_sid(struct cifs_sid *psid, char *end_of_acl)return -EINVAL ; } -if (psid->num_subauth) {#ifdef CONFIG_CIFS_DEBUG2 +if (psid->num_subauth) {int i;cFYI (1 ,"SID revision %d num_auth %d" , psid->revision, psid->num_subauth);@@ -1002,8 +1002,8 @@ static int parse_sid(struct cifs_sid *psid, char *end_of_acl)num auths and therefore go off the end */ cFYI (1 ,"RID 0x%x" , le32_to_cpu(psid->sub_auth[psid->num_subauth-1])); -#endif } +#endif return 0 ; } --1.7.11.7
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Looks correct.
Shirish Pargaonkar
Reviewed-byRe: [PATCH 3/4] cifs: use the NUM_AUTHS and NUM_SUBAUTHS constants in cifsacl code
In reply to a message not in the archiveQuoted 58 lines · Jeff Layton
...instead of hardcoding in '5' and '6' all over the place.
Cc Shirish Pargaonkar <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/cifs/cifsacl.c | 6 +++--- fs/cifs/cifsacl.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)fs/cifs/cifsacl.c +3
-3@@ -210,7 +210,7 @@ sid_to_str(struct cifs_sid *sidptr, char *sidstr)sprintf (strptr,"-%d" , sidptr->revision); strptr = sidstr +strlen (sidstr); -for (i =0 ; i <6 ; ++i) { +for (i =0 ; i <NUM_AUTHS ; ++i) {if (sidptr->authority[i]) {sprintf (strptr,"-%d" , sidptr->authority[i]); strptr = sidstr +strlen (sidstr);@@ -649,7 +649,7 @@ int compare_sids(const struct cifs_sid *ctsid, const struct cifs_sid *cwsid) }/* compare all of the six auth values */ -for (i =0 ; i <6 ; ++i) { +for (i =0 ; i <NUM_AUTHS ; ++i) {if (ctsid->authority[i] != cwsid->authority[i]) {if (ctsid->authority[i] > cwsid->authority[i])return 1 ;@@ -811,7 +811,7 @@ static __u16 fill_ace_for_sid(struct cifs_ace *pntace, pntace->sid.revision = psid->revision; pntace->sid.num_subauth = psid->num_subauth; -for (i =0 ; i <6 ; i++) +for (i =0 ; i <NUM_AUTHS ; i++) pntace->sid.authority[i] = psid->authority[i];for (i =0 ; i < psid->num_subauth; i++) pntace->sid.sub_auth[i] = psid->sub_auth[i];fs/cifs/cifsacl.h +2
-3@@ -60,8 +60,8 @@ struct cifs_ntsd {struct cifs_sid {__u8 revision;/* revision level */ __u8 num_subauth; -__u8 authority[6 ]; -__le32 sub_auth[5 ];/* sub_auth[num_subauth] */ +__u8 authority[NUM_AUTHS ]; +__le32 sub_auth[NUM_SUBAUTHS ];/* sub_auth[num_subauth] */ } __attribute__((packed));struct cifs_acl { --1.7.11.7
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Looks correct.
Shirish Pargaonkar
Reviewed-byRe: [PATCH 4/4] cifs: make compare_sids static
In reply to a message not in the archiveQuoted 140 lines · Jeff Layton
..nothing outside of
cifsacl.ccalls it. Also fix the incorrect comment on the function. It returns 0 when they match.Cc Shirish Pargaonkar <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/cifs/cifsacl.c | 98 ++++++++++++++++++++++++++++--------------------------- fs/cifs/cifsacl.h | 2 -- 2 files changed, 50 insertions(+), 50 deletions(-)fs/cifs/cifsacl.c +50
-48@@ -224,6 +224,56 @@ sid_to_str(struct cifs_sid *sidptr, char *sidstr) } } +/* +* if the two SIDs (roughly equivalent to a UUID for a user or group) are +* the same returns zero, if they do not match returns non-zero. +*/ +static int +compare_sids (const struct cifs_sid *ctsid,const struct cifs_sid *cwsid) +{ +int i; +int num_subauth, num_sat, num_saw; + +if ((!ctsid) || (!cwsid)) +return 1 ; + +/* compare the revision */ +if (ctsid->revision != cwsid->revision) { +if (ctsid->revision > cwsid->revision) +return 1 ; +else +return -1 ; + } + +/* compare all of the six auth values */ +for (i =0 ; i <NUM_AUTHS ; ++i) { +if (ctsid->authority[i] != cwsid->authority[i]) { +if (ctsid->authority[i] > cwsid->authority[i]) +return 1 ; +else +return -1 ; + } + } + +/* compare all of the subauth values if any */ + num_sat = ctsid->num_subauth; + num_saw = cwsid->num_subauth; + num_subauth = num_sat < num_saw ? num_sat : num_saw; +if (num_subauth) { +for (i =0 ; i < num_subauth; ++i) { +if (ctsid->sub_auth[i] != cwsid->sub_auth[i]) { +if (le32_to_cpu (ctsid->sub_auth[i]) > +le32_to_cpu (cwsid->sub_auth[i])) +return 1 ; +else +return -1 ; + } + } + } + +return 0 ;/* sids compare/match */ +} +static void cifs_copy_sid (struct cifs_sid *dst,const struct cifs_sid *src) {@@ -630,54 +680,6 @@ cifs_destroy_idmaptrees(void)spin_unlock (&gidsidlock); } -/* if the two SIDs (roughly equivalent to a UUID for a user or group) are -the same returns 1, if they do not match returns 0 */ -int compare_sids (const struct cifs_sid *ctsid,const struct cifs_sid *cwsid) -{ -int i; -int num_subauth, num_sat, num_saw; - -if ((!ctsid) || (!cwsid)) -return 1 ; - -/* compare the revision */ -if (ctsid->revision != cwsid->revision) { -if (ctsid->revision > cwsid->revision) -return 1 ; -else -return -1 ; - } - -/* compare all of the six auth values */ -for (i =0 ; i <NUM_AUTHS ; ++i) { -if (ctsid->authority[i] != cwsid->authority[i]) { -if (ctsid->authority[i] > cwsid->authority[i]) -return 1 ; -else -return -1 ; - } - } - -/* compare all of the subauth values if any */ - num_sat = ctsid->num_subauth; - num_saw = cwsid->num_subauth; - num_subauth = num_sat < num_saw ? num_sat : num_saw; -if (num_subauth) { -for (i =0 ; i < num_subauth; ++i) { -if (ctsid->sub_auth[i] != cwsid->sub_auth[i]) { -if (le32_to_cpu (ctsid->sub_auth[i]) > -le32_to_cpu (cwsid->sub_auth[i])) -return 1 ; -else -return -1 ; - } - } - } - -return 0 ;/* sids compare/match */ -} - -/* copy ntsd, owner sid, and group sid from a security descriptor to another */ static void copy_sec_desc (const struct cifs_ntsd *pntsd,struct cifs_ntsd *pnntsd,__u32 sidsoffset)fs/cifs/cifsacl.h +0
-3@@ -98,6 +98,4 @@ extern struct key_type cifs_idmap_key_type;extern const struct cred *root_cred;#endif /* KERNEL */ -extern int compare_sids (const struct cifs_sid *,const struct cifs_sid *); -#endif /* _CIFSACL_H */ --1.7.11.7
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Looks correct.