mirror of
https://github.com/adulau/aha.git
synced 2024-12-29 04:06:22 +00:00
cifs: reorganize get_cifs_acl
Thus spake Christoph: "But this whole set_cifs_acl function is a real mess anyway and needs some splitting up." With this change too, it's possible to call acl_to_uid_mode() with a NULL inode pointer. That (or something close to it) will eventually be necessary when cifs_get_inode_info is reorganized. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Shirish Pargaonkar <shirishp@us.ibm.com> Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve French <sfrench@us.ibm.com>
This commit is contained in:
parent
c5077ec423
commit
1bf4072da6
3 changed files with 56 additions and 52 deletions
|
@ -552,67 +552,66 @@ static int build_sec_desc(struct cifs_ntsd *pntsd, struct cifs_ntsd *pnntsd,
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb,
|
||||||
/* Retrieve an ACL from the server */
|
__u16 fid, u32 *pacllen)
|
||||||
static struct cifs_ntsd *get_cifs_acl(u32 *pacllen, struct inode *inode,
|
|
||||||
const char *path, const __u16 *pfid)
|
|
||||||
{
|
{
|
||||||
struct cifsFileInfo *open_file = NULL;
|
|
||||||
bool unlock_file = false;
|
|
||||||
int xid;
|
|
||||||
int rc = -EIO;
|
|
||||||
__u16 fid;
|
|
||||||
struct super_block *sb;
|
|
||||||
struct cifs_sb_info *cifs_sb;
|
|
||||||
struct cifs_ntsd *pntsd = NULL;
|
struct cifs_ntsd *pntsd = NULL;
|
||||||
|
int xid, rc;
|
||||||
cFYI(1, ("get mode from ACL for %s", path));
|
|
||||||
|
|
||||||
if (inode == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
xid = GetXid();
|
xid = GetXid();
|
||||||
if (pfid == NULL)
|
rc = CIFSSMBGetCIFSACL(xid, cifs_sb->tcon, fid, &pntsd, pacllen);
|
||||||
open_file = find_readable_file(CIFS_I(inode));
|
FreeXid(xid);
|
||||||
else
|
|
||||||
fid = *pfid;
|
|
||||||
|
|
||||||
sb = inode->i_sb;
|
|
||||||
if (sb == NULL) {
|
|
||||||
FreeXid(xid);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
cifs_sb = CIFS_SB(sb);
|
|
||||||
|
|
||||||
if (open_file) {
|
cFYI(1, ("GetCIFSACL rc = %d ACL len %d", rc, *pacllen));
|
||||||
unlock_file = true;
|
return pntsd;
|
||||||
fid = open_file->netfid;
|
}
|
||||||
} else if (pfid == NULL) {
|
|
||||||
int oplock = 0;
|
static struct cifs_ntsd *get_cifs_acl_by_path(struct cifs_sb_info *cifs_sb,
|
||||||
/* open file */
|
const char *path, u32 *pacllen)
|
||||||
rc = CIFSSMBOpen(xid, cifs_sb->tcon, path, FILE_OPEN,
|
{
|
||||||
READ_CONTROL, 0, &fid, &oplock, NULL,
|
struct cifs_ntsd *pntsd = NULL;
|
||||||
cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
|
int oplock = 0;
|
||||||
CIFS_MOUNT_MAP_SPECIAL_CHR);
|
int xid, rc;
|
||||||
if (rc != 0) {
|
__u16 fid;
|
||||||
cERROR(1, ("Unable to open file to get ACL"));
|
|
||||||
FreeXid(xid);
|
xid = GetXid();
|
||||||
return NULL;
|
|
||||||
}
|
rc = CIFSSMBOpen(xid, cifs_sb->tcon, path, FILE_OPEN, READ_CONTROL, 0,
|
||||||
|
&fid, &oplock, NULL, cifs_sb->local_nls,
|
||||||
|
cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
|
||||||
|
if (rc) {
|
||||||
|
cERROR(1, ("Unable to open file to get ACL"));
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = CIFSSMBGetCIFSACL(xid, cifs_sb->tcon, fid, &pntsd, pacllen);
|
rc = CIFSSMBGetCIFSACL(xid, cifs_sb->tcon, fid, &pntsd, pacllen);
|
||||||
cFYI(1, ("GetCIFSACL rc = %d ACL len %d", rc, *pacllen));
|
cFYI(1, ("GetCIFSACL rc = %d ACL len %d", rc, *pacllen));
|
||||||
if (unlock_file == true) /* find_readable_file increments ref count */
|
|
||||||
atomic_dec(&open_file->wrtPending);
|
|
||||||
else if (pfid == NULL) /* if opened above we have to close the handle */
|
|
||||||
CIFSSMBClose(xid, cifs_sb->tcon, fid);
|
|
||||||
/* else handle was passed in by caller */
|
|
||||||
|
|
||||||
|
CIFSSMBClose(xid, cifs_sb->tcon, fid);
|
||||||
|
out:
|
||||||
FreeXid(xid);
|
FreeXid(xid);
|
||||||
return pntsd;
|
return pntsd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Retrieve an ACL from the server */
|
||||||
|
static struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *cifs_sb,
|
||||||
|
struct inode *inode, const char *path,
|
||||||
|
u32 *pacllen)
|
||||||
|
{
|
||||||
|
struct cifs_ntsd *pntsd = NULL;
|
||||||
|
struct cifsFileInfo *open_file = NULL;
|
||||||
|
|
||||||
|
if (inode)
|
||||||
|
open_file = find_readable_file(CIFS_I(inode));
|
||||||
|
if (!open_file)
|
||||||
|
return get_cifs_acl_by_path(cifs_sb, path, pacllen);
|
||||||
|
|
||||||
|
pntsd = get_cifs_acl_by_fid(cifs_sb, open_file->netfid, pacllen);
|
||||||
|
atomic_dec(&open_file->wrtPending);
|
||||||
|
return pntsd;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set an ACL on the server */
|
/* Set an ACL on the server */
|
||||||
static int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
|
static int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
|
||||||
struct inode *inode, const char *path)
|
struct inode *inode, const char *path)
|
||||||
|
@ -668,14 +667,19 @@ static int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Translate the CIFS ACL (simlar to NTFS ACL) for a file into mode bits */
|
/* Translate the CIFS ACL (simlar to NTFS ACL) for a file into mode bits */
|
||||||
void acl_to_uid_mode(struct inode *inode, const char *path, const __u16 *pfid)
|
void acl_to_uid_mode(struct cifs_sb_info *cifs_sb, struct inode *inode,
|
||||||
|
const char *path, const __u16 *pfid)
|
||||||
{
|
{
|
||||||
struct cifs_ntsd *pntsd = NULL;
|
struct cifs_ntsd *pntsd = NULL;
|
||||||
u32 acllen = 0;
|
u32 acllen = 0;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
cFYI(DBG2, ("converting ACL to mode for %s", path));
|
cFYI(DBG2, ("converting ACL to mode for %s", path));
|
||||||
pntsd = get_cifs_acl(&acllen, inode, path, pfid);
|
|
||||||
|
if (pfid)
|
||||||
|
pntsd = get_cifs_acl_by_fid(cifs_sb, *pfid, &acllen);
|
||||||
|
else
|
||||||
|
pntsd = get_cifs_acl(cifs_sb, inode, path, &acllen);
|
||||||
|
|
||||||
/* if we can retrieve the ACL, now parse Access Control Entries, ACEs */
|
/* if we can retrieve the ACL, now parse Access Control Entries, ACEs */
|
||||||
if (pntsd)
|
if (pntsd)
|
||||||
|
@ -698,7 +702,7 @@ int mode_to_acl(struct inode *inode, const char *path, __u64 nmode)
|
||||||
cFYI(DBG2, ("set ACL from mode for %s", path));
|
cFYI(DBG2, ("set ACL from mode for %s", path));
|
||||||
|
|
||||||
/* Get the security descriptor */
|
/* Get the security descriptor */
|
||||||
pntsd = get_cifs_acl(&secdesclen, inode, path, NULL);
|
pntsd = get_cifs_acl(CIFS_SB(inode->i_sb), inode, path, &secdesclen);
|
||||||
|
|
||||||
/* Add three ACEs for owner, group, everyone getting rid of
|
/* Add three ACEs for owner, group, everyone getting rid of
|
||||||
other ACEs as chmod disables ACEs and set the security descriptor */
|
other ACEs as chmod disables ACEs and set the security descriptor */
|
||||||
|
|
|
@ -108,8 +108,8 @@ extern int cifs_get_inode_info(struct inode **pinode,
|
||||||
extern int cifs_get_inode_info_unix(struct inode **pinode,
|
extern int cifs_get_inode_info_unix(struct inode **pinode,
|
||||||
const unsigned char *search_path,
|
const unsigned char *search_path,
|
||||||
struct super_block *sb, int xid);
|
struct super_block *sb, int xid);
|
||||||
extern void acl_to_uid_mode(struct inode *inode, const char *path,
|
extern void acl_to_uid_mode(struct cifs_sb_info *cifs_sb, struct inode *inode,
|
||||||
const __u16 *pfid);
|
const char *path, const __u16 *pfid);
|
||||||
extern int mode_to_acl(struct inode *inode, const char *path, __u64);
|
extern int mode_to_acl(struct inode *inode, const char *path, __u64);
|
||||||
|
|
||||||
extern int cifs_mount(struct super_block *, struct cifs_sb_info *, char *,
|
extern int cifs_mount(struct super_block *, struct cifs_sb_info *, char *,
|
||||||
|
|
|
@ -626,7 +626,7 @@ int cifs_get_inode_info(struct inode **pinode,
|
||||||
/* fill in 0777 bits from ACL */
|
/* fill in 0777 bits from ACL */
|
||||||
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
|
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
|
||||||
cFYI(1, ("Getting mode bits from ACL"));
|
cFYI(1, ("Getting mode bits from ACL"));
|
||||||
acl_to_uid_mode(inode, full_path, pfid);
|
acl_to_uid_mode(cifs_sb, inode, full_path, pfid);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
|
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
|
||||||
|
|
Loading…
Reference in a new issue