This is a high-level function, and it belongs in libsystemd-shared. This way we don't end up linking a separate copy into various binaries. It would even end up in libsystemd, where it is not needed. (Maybe it'd be removed in some optimization phase, but it's better to not rely on that.) $ grep -l -r -a 'path is not absolute%s' build/ build/libnss_systemd.so.2 build/pam_systemd_home.so build/test-dlopen build/src/basic/libbasic.a.p/path-util.c.o build/src/basic/libbasic.a build/src/shared/libsystemd-shared-249.so build/test-bus-error build/libnss_mymachines.so.2 build/pam_systemd.so build/libnss_resolve.so.2 build/libnss_myhostname.so.2 build/libsystemd.so.0.32.0 build/libudev.so.1.7.2 $ grep -l -r -a 'path is not absolute%s' build/ build/src/shared/libsystemd-shared-251.a.p/parse-helpers.c.o build/src/shared/libsystemd-shared-251.a build/src/shared/libsystemd-shared-251.so No functional change.
53 lines
2.0 KiB
C
53 lines
2.0 KiB
C
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
|
|
#include "log.h"
|
|
#include "parse-helpers.h"
|
|
#include "path-util.h"
|
|
#include "utf8.h"
|
|
|
|
int path_simplify_and_warn(
|
|
char *path,
|
|
unsigned flag,
|
|
const char *unit,
|
|
const char *filename,
|
|
unsigned line,
|
|
const char *lvalue) {
|
|
|
|
bool fatal = flag & PATH_CHECK_FATAL;
|
|
|
|
assert(!FLAGS_SET(flag, PATH_CHECK_ABSOLUTE | PATH_CHECK_RELATIVE));
|
|
|
|
if (!utf8_is_valid(path))
|
|
return log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, path);
|
|
|
|
if (flag & (PATH_CHECK_ABSOLUTE | PATH_CHECK_RELATIVE)) {
|
|
bool absolute;
|
|
|
|
absolute = path_is_absolute(path);
|
|
|
|
if (!absolute && (flag & PATH_CHECK_ABSOLUTE))
|
|
return log_syntax(unit, LOG_ERR, filename, line, SYNTHETIC_ERRNO(EINVAL),
|
|
"%s= path is not absolute%s: %s",
|
|
lvalue, fatal ? "" : ", ignoring", path);
|
|
|
|
if (absolute && (flag & PATH_CHECK_RELATIVE))
|
|
return log_syntax(unit, LOG_ERR, filename, line, SYNTHETIC_ERRNO(EINVAL),
|
|
"%s= path is absolute%s: %s",
|
|
lvalue, fatal ? "" : ", ignoring", path);
|
|
}
|
|
|
|
path_simplify(path);
|
|
|
|
if (!path_is_valid(path))
|
|
return log_syntax(unit, LOG_ERR, filename, line, SYNTHETIC_ERRNO(EINVAL),
|
|
"%s= path has invalid length (%zu bytes)%s.",
|
|
lvalue, strlen(path), fatal ? "" : ", ignoring");
|
|
|
|
if (!path_is_normalized(path))
|
|
return log_syntax(unit, LOG_ERR, filename, line, SYNTHETIC_ERRNO(EINVAL),
|
|
"%s= path is not normalized%s: %s",
|
|
lvalue, fatal ? "" : ", ignoring", path);
|
|
|
|
return 0;
|
|
}
|