main: create dir in two steps with xattrs permissions

if xattrs permissions are used, create the directory in two steps and
set the correct ownership before moving it into the target.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2023-11-02 11:49:14 +01:00
parent d65ce2a8bb
commit d9e78eadb7
No known key found for this signature in database
GPG Key ID: 67E38F7A8BA21772

3
main.c
View File

@ -2866,7 +2866,7 @@ create_directory (struct ovl_data *lo, int dirfd, const char *name, const struct
bool need_rename; bool need_rename;
mode_t backing_file_mode = mode | (lo->xattr_permissions ? 0755 : 0); mode_t backing_file_mode = mode | (lo->xattr_permissions ? 0755 : 0);
need_rename = set_opaque || times || xattr_sfd >= 0 || uid != lo->uid || gid != lo->gid; need_rename = set_opaque || times || xattr_sfd >= 0 || uid != lo->uid || gid != lo->gid || get_upper_layer (lo)->stat_override_mode != STAT_OVERRIDE_NONE;
if (! need_rename) if (! need_rename)
{ {
/* mkdir can be used directly without a temporary directory in the working directory. */ /* mkdir can be used directly without a temporary directory in the working directory. */
@ -2937,6 +2937,7 @@ create_directory (struct ovl_data *lo, int dirfd, const char *name, const struct
ret = fstat (dfd, st_out); ret = fstat (dfd, st_out);
if (ret < 0) if (ret < 0)
goto out; goto out;
st_out->st_mode = (st_out->st_mode & S_IFMT) | (mode & ~S_IFMT);
} }
ret = inherit_acl (lo, parent, dfd, NULL); ret = inherit_acl (lo, parent, dfd, NULL);