Complete fix for bug #8811 - sd_has_inheritable_components segfaults on an SD that...
[ddiss/samba.git] / source3 / modules / vfs_acl_common.c
index bc9f56b798f33f394d8b8b2d27a68426e540b830..a5370110986a171b8f452aaeca2712158b0e2542 100644 (file)
@@ -166,7 +166,7 @@ static NTSTATUS create_acl_blob(const struct security_descriptor *psd,
  CREATOR_OWNER/CREATOR_GROUP/WORLD.
 *******************************************************************/
 
-static void add_directory_inheritable_components(vfs_handle_struct *handle,
+static NTSTATUS add_directory_inheritable_components(vfs_handle_struct *handle,
                                 const char *name,
                                SMB_STRUCT_STAT *psbuf,
                                struct security_descriptor *psd)
@@ -184,7 +184,7 @@ static void add_directory_inheritable_components(vfs_handle_struct *handle,
                                                num_aces + 3);
 
        if (new_ace_list == NULL) {
-               return;
+               return NT_STATUS_NO_MEMORY;
        }
 
        /* Fake a quick smb_filename. */
@@ -236,8 +236,19 @@ static void add_directory_inheritable_components(vfs_handle_struct *handle,
                        SEC_ACE_FLAG_CONTAINER_INHERIT|
                                SEC_ACE_FLAG_OBJECT_INHERIT|
                                SEC_ACE_FLAG_INHERIT_ONLY);
-       psd->dacl->aces = new_ace_list;
-       psd->dacl->num_aces += 3;
+       if (psd->dacl) {
+               psd->dacl->aces = new_ace_list;
+               psd->dacl->num_aces += 3;
+       } else {
+               psd->dacl = make_sec_acl(talloc_tos(),
+                               NT4_ACL_REVISION,
+                               3,
+                               new_ace_list);
+               if (psd->dacl == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+       }
+       return NT_STATUS_OK;
 }
 
 /*******************************************************************
@@ -393,10 +404,14 @@ static NTSTATUS get_nt_acl_internal(vfs_handle_struct *handle,
                        if (is_directory &&
                                !sd_has_inheritable_components(psd,
                                                        true)) {
-                               add_directory_inheritable_components(handle,
+                               status = add_directory_inheritable_components(
+                                                       handle,
                                                        name,
                                                        psbuf,
                                                        psd);
+                               if (!NT_STATUS_IS_OK(status)) {
+                                       return status;
+                               }
                        }
                        /* The underlying POSIX module always sets
                           the ~SEC_DESC_DACL_PROTECTED bit, as ACLs
@@ -804,10 +819,12 @@ static NTSTATUS fset_nt_acl_common(vfs_handle_struct *handle, files_struct *fsp,
                NDR_PRINT_DEBUG(security_descriptor,
                        CONST_DISCARD(struct security_descriptor *,psd));
        }
-       /*
-        * Perhaps create_acl_blob should have a status return as well
-        */
-       create_acl_blob(psd, &blob, XATTR_SD_HASH_TYPE_SHA256, hash);
+       status = create_acl_blob(psd, &blob, XATTR_SD_HASH_TYPE_SHA256, hash);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(10, ("fset_nt_acl_xattr: create_acl_blob failed\n"));
+               return status;
+       }
+
        status = store_acl_blob_fsp(handle, fsp, &blob);
 
        return status;