summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2012-07-09 16:13:06 -0700
committerJeremy Allison <jra@samba.org>2012-07-10 03:30:22 +0200
commit3aa186f1d4d9ca723fb9c876d0b3fc1f58d556fb (patch)
treeec9caffd15a9e0918d2026f46b301004bb9a81c9 /source3/smbd
parent3a705e5f3d0843e3765852e26661aeee5ebdfd79 (diff)
downloadsamba-3aa186f1d4d9ca723fb9c876d0b3fc1f58d556fb.tar.gz
samba-3aa186f1d4d9ca723fb9c876d0b3fc1f58d556fb.tar.bz2
samba-3aa186f1d4d9ca723fb9c876d0b3fc1f58d556fb.zip
Simplify the logic in open_file() some more.
Move the inheritance work into the if block where we created the file. We can never have created the file (and thus need no inheritance) for a stat-open. Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Tue Jul 10 03:30:22 CEST 2012 on sn-devel-104
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/open.c84
1 files changed, 36 insertions, 48 deletions
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 26b48c1cf1..473fd9769c 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -551,7 +551,6 @@ static NTSTATUS open_file(files_struct *fsp,
int accmode = (flags & O_ACCMODE);
int local_flags = flags;
bool file_existed = VALID_STAT(fsp->fsp_name->st);
- bool file_created = false;
fsp->fh->fd = -1;
errno = EPERM;
@@ -692,9 +691,43 @@ static NTSTATUS open_file(files_struct *fsp,
}
if ((local_flags & O_CREAT) && !file_existed) {
- file_created = true;
- }
+ /* We created this file. */
+
+ bool need_re_stat = false;
+ /* Do all inheritance work after we've
+ done a successful fstat call and filled
+ in the stat struct in fsp->fsp_name. */
+
+ /* Inherit the ACL if required */
+ if (lp_inherit_perms(SNUM(conn))) {
+ inherit_access_posix_acl(conn, parent_dir,
+ smb_fname->base_name,
+ unx_mode);
+ need_re_stat = true;
+ }
+ /* Change the owner if required. */
+ if (lp_inherit_owner(SNUM(conn))) {
+ change_file_owner_to_parent(conn, parent_dir,
+ fsp);
+ need_re_stat = true;
+ }
+
+ if (need_re_stat) {
+ ret = SMB_VFS_FSTAT(fsp, &smb_fname->st);
+ /* If we have an fd, this stat should succeed. */
+ if (ret == -1) {
+ DEBUG(0,("Error doing fstat on open file %s "
+ "(%s)\n",
+ smb_fname_str_dbg(smb_fname),
+ strerror(errno) ));
+ }
+ }
+
+ notify_fname(conn, NOTIFY_ACTION_ADDED,
+ FILE_NOTIFY_CHANGE_FILE_NAME,
+ smb_fname->base_name);
+ }
} else {
fsp->fh->fd = -1; /* What we used to call a stat open. */
if (!file_existed) {
@@ -728,51 +761,6 @@ static NTSTATUS open_file(files_struct *fsp,
}
}
- if (!file_existed) {
- if (file_created) {
- bool need_re_stat = false;
- /* Do all inheritance work after we've
- done a successful stat call and filled
- in the stat struct in fsp->fsp_name. */
-
- /* Inherit the ACL if required */
- if (lp_inherit_perms(SNUM(conn))) {
- inherit_access_posix_acl(conn, parent_dir,
- smb_fname->base_name,
- unx_mode);
- need_re_stat = true;
- }
-
- /* Change the owner if required. */
- if (lp_inherit_owner(SNUM(conn))) {
- change_file_owner_to_parent(conn, parent_dir,
- fsp);
- need_re_stat = true;
- }
-
- if (need_re_stat) {
- int ret;
-
- if (fsp->fh->fd == -1) {
- ret = SMB_VFS_STAT(conn, smb_fname);
- } else {
- ret = SMB_VFS_FSTAT(fsp, &smb_fname->st);
- /* If we have an fd, this stat should succeed. */
- if (ret == -1) {
- DEBUG(0,("Error doing fstat on open file %s "
- "(%s)\n",
- smb_fname_str_dbg(smb_fname),
- strerror(errno) ));
- }
- }
- }
-
- notify_fname(conn, NOTIFY_ACTION_ADDED,
- FILE_NOTIFY_CHANGE_FILE_NAME,
- smb_fname->base_name);
- }
- }
-
/*
* POSIX allows read-only opens of directories. We don't
* want to do this (we use a different code path for this)