1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-24 06:04:05 +03:00

load-fragment: allow MountImages= with paths starting with /dev

For MountImages=, if the source is a block device, it will most likely reside
in /dev. It should be also possible to mount a static device file system in
place of (or part of) /dev. So let's allow paths starting with /dev as an
exception for MountImages=.

(cherry picked from commit e81025970fed5673c631976711d45c67b0443bb4)
This commit is contained in:
Topi Miettinen 2024-06-26 22:06:41 +03:00 committed by Luca Boccassi
parent cc4472c31e
commit 0ff6d2cf47
3 changed files with 26 additions and 8 deletions

View File

@ -5397,7 +5397,7 @@ int config_parse_mount_images(
continue;
}
r = path_simplify_and_warn(sresolved, PATH_CHECK_ABSOLUTE|PATH_CHECK_NON_API_VFS, unit, filename, line, lvalue);
r = path_simplify_and_warn(sresolved, PATH_CHECK_ABSOLUTE|PATH_CHECK_NON_API_VFS_DEV_OK, unit, filename, line, lvalue);
if (r < 0)
continue;
@ -5413,7 +5413,7 @@ int config_parse_mount_images(
continue;
}
r = path_simplify_and_warn(dresolved, PATH_CHECK_ABSOLUTE|PATH_CHECK_NON_API_VFS, unit, filename, line, lvalue);
r = path_simplify_and_warn(dresolved, PATH_CHECK_ABSOLUTE|PATH_CHECK_NON_API_VFS_DEV_OK, unit, filename, line, lvalue);
if (r < 0)
continue;

View File

@ -10,6 +10,22 @@
#include "path-util.h"
#include "utf8.h"
static bool validate_api_vfs(const char *path, PathSimplifyWarnFlags flags) {
assert(path);
if ((flags & (PATH_CHECK_NON_API_VFS|PATH_CHECK_NON_API_VFS_DEV_OK)) == 0)
return true;
if (!path_below_api_vfs(path))
return true;
if (FLAGS_SET(flags, PATH_CHECK_NON_API_VFS_DEV_OK) && path_startswith(path, "/dev"))
return true;
return false;
}
int path_simplify_and_warn(
char *path,
PathSimplifyWarnFlags flags,
@ -23,6 +39,7 @@ int path_simplify_and_warn(
assert(path);
assert(!FLAGS_SET(flags, PATH_CHECK_ABSOLUTE | PATH_CHECK_RELATIVE));
assert(!FLAGS_SET(flags, PATH_CHECK_NON_API_VFS | PATH_CHECK_NON_API_VFS_DEV_OK));
assert(lvalue);
if (!utf8_is_valid(path))
@ -56,7 +73,7 @@ int path_simplify_and_warn(
"%s= path is not normalized%s: %s",
lvalue, fatal ? "" : ", ignoring", path);
if (FLAGS_SET(flags, PATH_CHECK_NON_API_VFS) && path_below_api_vfs(path))
if (!validate_api_vfs(path, flags))
return log_syntax(unit, level, filename, line, SYNTHETIC_ERRNO(EINVAL),
"%s= path is below API VFS%s: %s",
lvalue, fatal ? ", refusing" : ", ignoring",

View File

@ -4,11 +4,12 @@
#include <stdint.h>
typedef enum PathSimplifyWarnFlags {
PATH_CHECK_FATAL = 1 << 0, /* If not set, then error message is appended with 'ignoring'. */
PATH_CHECK_ABSOLUTE = 1 << 1,
PATH_CHECK_RELATIVE = 1 << 2,
PATH_KEEP_TRAILING_SLASH = 1 << 3,
PATH_CHECK_NON_API_VFS = 1 << 4,
PATH_CHECK_FATAL = 1 << 0, /* If not set, then error message is appended with 'ignoring'. */
PATH_CHECK_ABSOLUTE = 1 << 1,
PATH_CHECK_RELATIVE = 1 << 2,
PATH_KEEP_TRAILING_SLASH = 1 << 3,
PATH_CHECK_NON_API_VFS = 1 << 4,
PATH_CHECK_NON_API_VFS_DEV_OK = 1 << 5,
} PathSimplifyWarnFlags;
int path_simplify_and_warn(