Part 3 of bugfix for #8211 - "inherit owner = yes" doesn't interact correctly with...
authorJeremy Allison <jra@samba.org>
Wed, 8 Jun 2011 17:25:33 +0000 (10:25 -0700)
committerKarolin Seeger <kseeger@samba.org>
Fri, 10 Jun 2011 19:09:12 +0000 (21:09 +0200)
When changing ownership on a new file make sure we
must have a valid stat struct before making the inheritance
calls (as they may look at it), and if we make changes we
must have a valid stat struct after them.

source3/smbd/open.c

index aaae9673d1a48e5d8e9cfd0ad8edec985755f35f..e77284b9f9379c5fd94d66229eb9dcae39e00883 100644 (file)
@@ -370,6 +370,7 @@ 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;
@@ -469,23 +470,7 @@ static NTSTATUS open_file(files_struct *fsp,
                }
 
                if ((local_flags & O_CREAT) && !file_existed) {
-
-                       /* Inherit the ACL if required */
-                       if (lp_inherit_perms(SNUM(conn))) {
-                               inherit_access_posix_acl(conn, parent_dir,
-                                                        smb_fname->base_name,
-                                                        unx_mode);
-                       }
-
-                       /* Change the owner if required. */
-                       if (lp_inherit_owner(SNUM(conn))) {
-                               change_file_owner_to_parent(conn, parent_dir,
-                                                           fsp);
-                       }
-
-                       notify_fname(conn, NOTIFY_ACTION_ADDED,
-                                    FILE_NOTIFY_CHANGE_FILE_NAME,
-                                    smb_fname->base_name);
+                       file_created = true;
                }
 
        } else {
@@ -595,6 +580,29 @@ static NTSTATUS open_file(files_struct *fsp,
                        fd_close(fsp);
                        return status;
                }
+
+               if (file_created) {
+                       /* 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);
+                       }
+
+                       /* Change the owner if required. */
+                       if (lp_inherit_owner(SNUM(conn))) {
+                               change_file_owner_to_parent(conn, parent_dir,
+                                                           fsp);
+                       }
+
+                       notify_fname(conn, NOTIFY_ACTION_ADDED,
+                                    FILE_NOTIFY_CHANGE_FILE_NAME,
+                                    smb_fname->base_name);
+               }
        }
 
        /*