diff options
author | Luke Shumaker <lukeshu@parabola.nu> | 2017-07-07 18:30:03 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@parabola.nu> | 2018-07-20 12:12:02 -0400 |
commit | 9c0fad5fb5f47da125bb768dbb4cd0e824cccc7c (patch) | |
tree | 474be34ee5d1e5215b1551f32d9273f5e840aecf /src/nspawn/nspawn-mount.c | |
parent | f07b548940ed46722c54b15069a7f08739714659 (diff) | |
download | systemd-9c0fad5fb5f47da125bb768dbb4cd0e824cccc7c.tar.gz |
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.
Diffstat (limited to 'src/nspawn/nspawn-mount.c')
-rw-r--r-- | src/nspawn/nspawn-mount.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/nspawn/nspawn-mount.c b/src/nspawn/nspawn-mount.c index b5df65e2a4..3613a179fe 100644 --- a/src/nspawn/nspawn-mount.c +++ b/src/nspawn/nspawn-mount.c @@ -442,7 +442,7 @@ int mount_sysfs(const char *dest, MountSettingsMask mount_settings) { MS_BIND|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_REMOUNT|extra_flags, NULL); } -static int mkdir_userns(const char *path, mode_t mode, MountSettingsMask mask, uid_t uid_shift) { +static int mkdir_userns(const char *path, mode_t mode, uid_t uid_shift) { int r; assert(path); @@ -451,10 +451,7 @@ static int mkdir_userns(const char *path, mode_t mode, MountSettingsMask mask, u if (r < 0 && r != -EEXIST) return r; - if ((mask & MOUNT_USE_USERNS) == 0) - return 0; - - if (mask & MOUNT_IN_USERNS) + if (uid_shift == UID_INVALID) return 0; 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 return 0; } -static int mkdir_userns_p(const char *prefix, const char *path, mode_t mode, MountSettingsMask mask, uid_t uid_shift) { +static int mkdir_userns_p(const char *prefix, const char *path, mode_t mode, uid_t uid_shift) { const char *p, *e; int r; @@ -490,12 +487,12 @@ static int mkdir_userns_p(const char *prefix, const char *path, mode_t mode, Mou if (prefix && path_startswith(prefix, t)) continue; - r = mkdir_userns(t, mode, mask, uid_shift); + r = mkdir_userns(t, mode, uid_shift); if (r < 0) return r; } - return mkdir_userns(path, mode, mask, uid_shift); + return mkdir_userns(path, mode, uid_shift); } int mount_all(const char *dest, @@ -634,7 +631,7 @@ int mount_all(const char *dest, if (what && r > 0) continue; - r = mkdir_userns_p(dest, where, 0755, mount_settings, uid_shift); + r = mkdir_userns_p(dest, where, 0755, (use_userns && !in_userns) ? uid_shift : UID_INVALID); if (r < 0 && r != -EEXIST) { if (fatal && r != -EROFS) return log_error_errno(r, "Failed to create directory %s: %m", where); |