mirror of
https://github.com/systemd/systemd.git
synced 2025-01-07 17:14:09 +08:00
conf-parser: config_parse_path_strv() is not generic, so let's move it into load-fragment.c
The parse code actually checked for specific lvalue names, which is really wrong for supposedly generic parsers...
This commit is contained in:
parent
3af00fb85a
commit
94828d2ddc
@ -74,9 +74,9 @@ $1.LimitMSGQUEUE, config_parse_limit, RLIMIT_MSGQ
|
|||||||
$1.LimitNICE, config_parse_limit, RLIMIT_NICE, offsetof($1, exec_context.rlimit)
|
$1.LimitNICE, config_parse_limit, RLIMIT_NICE, offsetof($1, exec_context.rlimit)
|
||||||
$1.LimitRTPRIO, config_parse_limit, RLIMIT_RTPRIO, offsetof($1, exec_context.rlimit)
|
$1.LimitRTPRIO, config_parse_limit, RLIMIT_RTPRIO, offsetof($1, exec_context.rlimit)
|
||||||
$1.LimitRTTIME, config_parse_limit, RLIMIT_RTTIME, offsetof($1, exec_context.rlimit)
|
$1.LimitRTTIME, config_parse_limit, RLIMIT_RTTIME, offsetof($1, exec_context.rlimit)
|
||||||
$1.ReadWriteDirectories, config_parse_path_strv, 0, offsetof($1, exec_context.read_write_dirs)
|
$1.ReadWriteDirectories, config_parse_namespace_path_strv, 0, offsetof($1, exec_context.read_write_dirs)
|
||||||
$1.ReadOnlyDirectories, config_parse_path_strv, 0, offsetof($1, exec_context.read_only_dirs)
|
$1.ReadOnlyDirectories, config_parse_namespace_path_strv, 0, offsetof($1, exec_context.read_only_dirs)
|
||||||
$1.InaccessibleDirectories, config_parse_path_strv, 0, offsetof($1, exec_context.inaccessible_dirs)
|
$1.InaccessibleDirectories, config_parse_namespace_path_strv, 0, offsetof($1, exec_context.inaccessible_dirs)
|
||||||
$1.PrivateTmp, config_parse_bool, 0, offsetof($1, exec_context.private_tmp)
|
$1.PrivateTmp, config_parse_bool, 0, offsetof($1, exec_context.private_tmp)
|
||||||
$1.PrivateNetwork, config_parse_bool, 0, offsetof($1, exec_context.private_network)
|
$1.PrivateNetwork, config_parse_bool, 0, offsetof($1, exec_context.private_network)
|
||||||
$1.PrivateDevices, config_parse_bool, 0, offsetof($1, exec_context.private_devices)
|
$1.PrivateDevices, config_parse_bool, 0, offsetof($1, exec_context.private_devices)
|
||||||
|
@ -2848,6 +2848,65 @@ int config_parse_set_status(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int config_parse_namespace_path_strv(
|
||||||
|
const char *unit,
|
||||||
|
const char *filename,
|
||||||
|
unsigned line,
|
||||||
|
const char *section,
|
||||||
|
unsigned section_line,
|
||||||
|
const char *lvalue,
|
||||||
|
int ltype,
|
||||||
|
const char *rvalue,
|
||||||
|
void *data,
|
||||||
|
void *userdata) {
|
||||||
|
|
||||||
|
char*** sv = data, *w, *state;
|
||||||
|
size_t l;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(filename);
|
||||||
|
assert(lvalue);
|
||||||
|
assert(rvalue);
|
||||||
|
assert(data);
|
||||||
|
|
||||||
|
if (isempty(rvalue)) {
|
||||||
|
/* Empty assignment resets the list */
|
||||||
|
strv_free(*sv);
|
||||||
|
*sv = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
||||||
|
_cleanup_free_ char *n;
|
||||||
|
int offset;
|
||||||
|
|
||||||
|
n = strndup(w, l);
|
||||||
|
if (!n)
|
||||||
|
return log_oom();
|
||||||
|
|
||||||
|
if (!utf8_is_valid(n)) {
|
||||||
|
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Path is not UTF-8 clean, ignoring assignment: %s", rvalue);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
offset = n[0] == '-';
|
||||||
|
if (!path_is_absolute(n + offset)) {
|
||||||
|
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Not an absolute path, ignoring: %s", rvalue);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
path_kill_slashes(n);
|
||||||
|
|
||||||
|
r = strv_push(sv, n);
|
||||||
|
if (r < 0)
|
||||||
|
return log_oom();
|
||||||
|
|
||||||
|
n = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#define FOLLOW_MAX 8
|
#define FOLLOW_MAX 8
|
||||||
|
|
||||||
static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
|
static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
|
||||||
@ -3206,7 +3265,7 @@ void unit_dump_config_items(FILE *f) {
|
|||||||
{ config_parse_socket_bindtodevice, "NETWORKINTERFACE" },
|
{ config_parse_socket_bindtodevice, "NETWORKINTERFACE" },
|
||||||
{ config_parse_sec, "SECONDS" },
|
{ config_parse_sec, "SECONDS" },
|
||||||
{ config_parse_nsec, "NANOSECONDS" },
|
{ config_parse_nsec, "NANOSECONDS" },
|
||||||
{ config_parse_path_strv, "PATH [...]" },
|
{ config_parse_namespace_path_strv, "PATH [...]" },
|
||||||
{ config_parse_unit_requires_mounts_for, "PATH [...]" },
|
{ config_parse_unit_requires_mounts_for, "PATH [...]" },
|
||||||
{ config_parse_exec_mount_flags, "MOUNTFLAG [...]" },
|
{ config_parse_exec_mount_flags, "MOUNTFLAG [...]" },
|
||||||
{ config_parse_unit_string_printf, "STRING" },
|
{ config_parse_unit_string_printf, "STRING" },
|
||||||
|
@ -93,6 +93,7 @@ int config_parse_exec_apparmor_profile(const char *unit, const char *filename, u
|
|||||||
int config_parse_address_families(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
int config_parse_address_families(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
||||||
int config_parse_runtime_directory(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
int config_parse_runtime_directory(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
||||||
int config_parse_set_status(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
int config_parse_set_status(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
||||||
|
int config_parse_namespace_path_strv(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
||||||
|
|
||||||
/* gperf prototypes */
|
/* gperf prototypes */
|
||||||
const struct ConfigPerfItem* load_fragment_gperf_lookup(const char *key, unsigned length);
|
const struct ConfigPerfItem* load_fragment_gperf_lookup(const char *key, unsigned length);
|
||||||
|
@ -69,7 +69,7 @@ static int append_mounts(BindMount **p, char **strv, MountMode mode) {
|
|||||||
|
|
||||||
(*p)->ignore = false;
|
(*p)->ignore = false;
|
||||||
|
|
||||||
if ((mode == INACCESSIBLE || mode == READONLY) && (*i)[0] == '-') {
|
if ((mode == INACCESSIBLE || mode == READONLY || mode == READWRITE) && (*i)[0] == '-') {
|
||||||
(*p)->ignore = true;
|
(*p)->ignore = true;
|
||||||
(*i)++;
|
(*i)++;
|
||||||
}
|
}
|
||||||
|
@ -709,64 +709,6 @@ int config_parse_strv(const char *unit,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int config_parse_path_strv(const char *unit,
|
|
||||||
const char *filename,
|
|
||||||
unsigned line,
|
|
||||||
const char *section,
|
|
||||||
unsigned section_line,
|
|
||||||
const char *lvalue,
|
|
||||||
int ltype,
|
|
||||||
const char *rvalue,
|
|
||||||
void *data,
|
|
||||||
void *userdata) {
|
|
||||||
|
|
||||||
char*** sv = data, *w, *state;
|
|
||||||
size_t l;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(filename);
|
|
||||||
assert(lvalue);
|
|
||||||
assert(rvalue);
|
|
||||||
assert(data);
|
|
||||||
|
|
||||||
if (isempty(rvalue)) {
|
|
||||||
/* Empty assignment resets the list */
|
|
||||||
strv_free(*sv);
|
|
||||||
*sv = NULL;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
|
||||||
_cleanup_free_ char *n;
|
|
||||||
int offset;
|
|
||||||
|
|
||||||
n = strndup(w, l);
|
|
||||||
if (!n)
|
|
||||||
return log_oom();
|
|
||||||
|
|
||||||
if (!utf8_is_valid(n)) {
|
|
||||||
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
|
|
||||||
"Path is not UTF-8 clean, ignoring assignment: %s", rvalue);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = n[0] == '-' && (streq(lvalue, "InaccessibleDirectories") ||
|
|
||||||
streq(lvalue, "ReadOnlyDirectories"));
|
|
||||||
if (!path_is_absolute(n + offset)) {
|
|
||||||
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
|
|
||||||
"Not an absolute path, ignoring: %s", rvalue);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
path_kill_slashes(n);
|
|
||||||
r = strv_extend(sv, n);
|
|
||||||
if (r < 0)
|
|
||||||
return log_oom();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int config_parse_mode(const char *unit,
|
int config_parse_mode(const char *unit,
|
||||||
const char *filename,
|
const char *filename,
|
||||||
unsigned line,
|
unsigned line,
|
||||||
|
@ -104,7 +104,6 @@ int config_parse_bool(const char *unit, const char *filename, unsigned line, con
|
|||||||
int config_parse_string(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
int config_parse_string(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
||||||
int config_parse_path(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
int config_parse_path(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
||||||
int config_parse_strv(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
int config_parse_strv(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
||||||
int config_parse_path_strv(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
|
||||||
int config_parse_sec(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
int config_parse_sec(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
||||||
int config_parse_nsec(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
int config_parse_nsec(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
||||||
int config_parse_mode(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
int config_parse_mode(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
||||||
|
Loading…
Reference in New Issue
Block a user