Skip to content

Commit 9c0fad5

Browse files
committed
nspawn: Simplify mkdir_userns() usage, and trickle that up
One of the things that mkdir_userns{,_p}() does is take an (optional) UID, and chown the directory to that. So we need a uid_t argument, and a way of telling if we should use that uid_t argument. Fortunately, that is built in to the uid_t type by having UID_INVALID as a possible value. However, currently mkdir_userns() also takes a MountSettingsMask and checks a couple of bits in it to decide if it should perform the chown. Drop the mask argument, and instead have the caller pass UID_INVALID if it shouldn't chown.
1 parent f07b548 commit 9c0fad5

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/nspawn/nspawn-mount.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ int mount_sysfs(const char *dest, MountSettingsMask mount_settings) {
442442
MS_BIND|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_REMOUNT|extra_flags, NULL);
443443
}
444444

445-
static int mkdir_userns(const char *path, mode_t mode, MountSettingsMask mask, uid_t uid_shift) {
445+
static int mkdir_userns(const char *path, mode_t mode, uid_t uid_shift) {
446446
int r;
447447

448448
assert(path);
@@ -451,10 +451,7 @@ static int mkdir_userns(const char *path, mode_t mode, MountSettingsMask mask, u
451451
if (r < 0 && r != -EEXIST)
452452
return r;
453453

454-
if ((mask & MOUNT_USE_USERNS) == 0)
455-
return 0;
456-
457-
if (mask & MOUNT_IN_USERNS)
454+
if (uid_shift == UID_INVALID)
458455
return 0;
459456

460457
if (lchown(path, uid_shift, uid_shift) < 0)
@@ -463,7 +460,7 @@ static int mkdir_userns(const char *path, mode_t mode, MountSettingsMask mask, u
463460
return 0;
464461
}
465462

466-
static int mkdir_userns_p(const char *prefix, const char *path, mode_t mode, MountSettingsMask mask, uid_t uid_shift) {
463+
static int mkdir_userns_p(const char *prefix, const char *path, mode_t mode, uid_t uid_shift) {
467464
const char *p, *e;
468465
int r;
469466

@@ -490,12 +487,12 @@ static int mkdir_userns_p(const char *prefix, const char *path, mode_t mode, Mou
490487
if (prefix && path_startswith(prefix, t))
491488
continue;
492489

493-
r = mkdir_userns(t, mode, mask, uid_shift);
490+
r = mkdir_userns(t, mode, uid_shift);
494491
if (r < 0)
495492
return r;
496493
}
497494

498-
return mkdir_userns(path, mode, mask, uid_shift);
495+
return mkdir_userns(path, mode, uid_shift);
499496
}
500497

501498
int mount_all(const char *dest,
@@ -634,7 +631,7 @@ int mount_all(const char *dest,
634631
if (what && r > 0)
635632
continue;
636633

637-
r = mkdir_userns_p(dest, where, 0755, mount_settings, uid_shift);
634+
r = mkdir_userns_p(dest, where, 0755, (use_userns && !in_userns) ? uid_shift : UID_INVALID);
638635
if (r < 0 && r != -EEXIST) {
639636
if (fatal && r != -EROFS)
640637
return log_error_errno(r, "Failed to create directory %s: %m", where);

0 commit comments

Comments
 (0)