Skip to content

Commit

Permalink
vfs: Simplify fake_acls_stat() with an early return
Browse files Browse the repository at this point in the history
Review with "git di -b"

Signed-off-by: Volker Lendecke <[email protected]>
Reviewed-by: Jeremy Allison <[email protected]>

Autobuild-User(master): Jeremy Allison <[email protected]>
Autobuild-Date(master): Tue Feb  1 20:04:44 UTC 2022 on sn-devel-184
  • Loading branch information
vlendec authored and jrasamba committed Feb 1, 2022
1 parent e93f463 commit 95c7d23
Showing 1 changed file with 82 additions and 82 deletions.
164 changes: 82 additions & 82 deletions source3/modules/vfs_fake_acls.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,106 +80,106 @@ static int fake_acls_stat(vfs_handle_struct *handle,
{
int ret = -1;
struct in_pathref_data *prd = NULL;
struct smb_filename *smb_fname_cp = NULL;
struct files_struct *fsp = NULL;

SMB_VFS_HANDLE_GET_DATA(handle,
prd,
struct in_pathref_data,
return -1);

ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
if (ret == 0) {
struct smb_filename *smb_fname_cp = NULL;
struct files_struct *fsp = NULL;

if (smb_fname->fsp != NULL) {
fsp = smb_fname->fsp;
if (fsp->base_fsp != NULL) {
/*
* This is a stream pathname. Use
* the base_fsp to get the xattr.
*/
fsp = fsp->base_fsp;
}
} else {
NTSTATUS status;
if (ret != 0) {
return ret;
}

if (smb_fname->fsp != NULL) {
fsp = smb_fname->fsp;
if (fsp->base_fsp != NULL) {
/*
* Ensure openat_pathref_fsp()
* can't recurse into fake_acls_stat().
* openat_pathref_fsp() doesn't care
* about the uid/gid values, it only
* wants a valid/invalid stat answer
* and we know smb_fname exists as
* the SMB_VFS_NEXT_STAT() returned
* zero above.
* This is a stream pathname. Use
* the base_fsp to get the xattr.
*/
if (prd->calling_pathref_fsp) {
return 0;
}
fsp = fsp->base_fsp;
}
} else {
NTSTATUS status;

/*
* openat_pathref_fsp() expects a talloc'ed
* smb_filename. stat can be passed a struct
* from the stack. Make a talloc'ed copy
* so openat_pathref_fsp() can add its
* destructor.
*/
smb_fname_cp = cp_smb_filename(talloc_tos(),
smb_fname);
if (smb_fname_cp == NULL) {
errno = ENOMEM;
return -1;
}

/* Recursion guard. */
prd->calling_pathref_fsp = true;
status = openat_pathref_fsp(handle->conn->cwd_fsp,
smb_fname_cp);
/* End recursion guard. */
prd->calling_pathref_fsp = false;

if (!NT_STATUS_IS_OK(status)) {
/*
* Ignore errors here. We know
* the path exists (the SMB_VFS_NEXT_STAT()
* above succeeded. So being unable to
* open a pathref fsp can be due to a
* range of errors (startup path beginning
* with '/' for example, path = ".." when
* enumerating a directory. Just treat this
* the same way as the path not having the
* FAKE_UID or FAKE_GID EA's present. For the
* test purposes of this module (fake NT ACLs
* from windows clients) this is close enough.
* Just report for debugging purposes.
*/
DBG_DEBUG("Unable to get pathref fsp on %s. "
"Error %s\n",
smb_fname_str_dbg(smb_fname_cp),
nt_errstr(status));
TALLOC_FREE(smb_fname_cp);
return 0;
}
fsp = smb_fname_cp->fsp;
/*
* Ensure openat_pathref_fsp()
* can't recurse into fake_acls_stat().
* openat_pathref_fsp() doesn't care
* about the uid/gid values, it only
* wants a valid/invalid stat answer
* and we know smb_fname exists as
* the SMB_VFS_NEXT_STAT() returned
* zero above.
*/
if (prd->calling_pathref_fsp) {
return 0;
}

ret = fake_acls_fuid(handle,
fsp,
&smb_fname->st.st_ex_uid);
if (ret != 0) {
TALLOC_FREE(smb_fname_cp);
return ret;
/*
* openat_pathref_fsp() expects a talloc'ed
* smb_filename. stat can be passed a struct
* from the stack. Make a talloc'ed copy
* so openat_pathref_fsp() can add its
* destructor.
*/
smb_fname_cp = cp_smb_filename(talloc_tos(),
smb_fname);
if (smb_fname_cp == NULL) {
errno = ENOMEM;
return -1;
}
ret = fake_acls_fgid(handle,
fsp,
&smb_fname->st.st_ex_gid);
if (ret != 0) {

/* Recursion guard. */
prd->calling_pathref_fsp = true;
status = openat_pathref_fsp(handle->conn->cwd_fsp,
smb_fname_cp);
/* End recursion guard. */
prd->calling_pathref_fsp = false;

if (!NT_STATUS_IS_OK(status)) {
/*
* Ignore errors here. We know
* the path exists (the SMB_VFS_NEXT_STAT()
* above succeeded. So being unable to
* open a pathref fsp can be due to a
* range of errors (startup path beginning
* with '/' for example, path = ".." when
* enumerating a directory. Just treat this
* the same way as the path not having the
* FAKE_UID or FAKE_GID EA's present. For the
* test purposes of this module (fake NT ACLs
* from windows clients) this is close enough.
* Just report for debugging purposes.
*/
DBG_DEBUG("Unable to get pathref fsp on %s. "
"Error %s\n",
smb_fname_str_dbg(smb_fname_cp),
nt_errstr(status));
TALLOC_FREE(smb_fname_cp);
return ret;
return 0;
}
TALLOC_FREE(smb_fname_cp);
fsp = smb_fname_cp->fsp;
}

ret = fake_acls_fuid(handle,
fsp,
&smb_fname->st.st_ex_uid);
if (ret != 0) {
TALLOC_FREE(smb_fname_cp);
return ret;
}
ret = fake_acls_fgid(handle,
fsp,
&smb_fname->st.st_ex_gid);
if (ret != 0) {
TALLOC_FREE(smb_fname_cp);
return ret;
}
TALLOC_FREE(smb_fname_cp);
return ret;
}

Expand Down

0 comments on commit 95c7d23

Please sign in to comment.