diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-04-30 20:21:00 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-05-05 15:06:42 -0700 |
commit | 7410616cd9dbbec97cf98d75324da5cda2b2f7a2 (patch) | |
tree | 6d968995b3bdf961603ab4853bf078c0dbdce27c /src/core/unit-printf.c | |
parent | 6442185ab674cc202d63c18605057b9a51ca2722 (diff) | |
download | systemd-7410616cd9dbbec97cf98d75324da5cda2b2f7a2.tar.gz |
core: rework unit name validation and manipulation logic
A variety of changes:
- Make sure all our calls distuingish OOM from other errors if OOM is
not the only error possible.
- Be much stricter when parsing escaped paths, do not accept trailing or
leading escaped slashes.
- Change unit validation to take a bit mask for allowing plain names,
instance names or template names or an combination thereof.
- Refuse manipulating invalid unit name
Diffstat (limited to 'src/core/unit-printf.c')
-rw-r--r-- | src/core/unit-printf.c | 55 |
1 files changed, 13 insertions, 42 deletions
diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c index 5513fe7d9c..8050e2fd66 100644 --- a/src/core/unit-printf.c +++ b/src/core/unit-printf.c @@ -30,83 +30,54 @@ static int specifier_prefix_and_instance(char specifier, void *data, void *userdata, char **ret) { Unit *u = userdata; - char *n; assert(u); - n = unit_name_to_prefix_and_instance(u->id); - if (!n) - return -ENOMEM; - - *ret = n; - return 0; + return unit_name_to_prefix_and_instance(u->id, ret); } static int specifier_prefix(char specifier, void *data, void *userdata, char **ret) { Unit *u = userdata; - char *n; assert(u); - n = unit_name_to_prefix(u->id); - if (!n) - return -ENOMEM; - - *ret = n; - return 0; + return unit_name_to_prefix(u->id, ret); } static int specifier_prefix_unescaped(char specifier, void *data, void *userdata, char **ret) { - Unit *u = userdata; _cleanup_free_ char *p = NULL; - char *n; + Unit *u = userdata; + int r; assert(u); - p = unit_name_to_prefix(u->id); - if (!p) - return -ENOMEM; - - n = unit_name_unescape(p); - if (!n) - return -ENOMEM; + r = unit_name_to_prefix(u->id, &p); + if (r < 0) + return r; - *ret = n; - return 0; + return unit_name_unescape(p, ret); } static int specifier_instance_unescaped(char specifier, void *data, void *userdata, char **ret) { Unit *u = userdata; - char *n; assert(u); if (!u->instance) - return -EOPNOTSUPP; - - n = unit_name_unescape(u->instance); - if (!n) - return -ENOMEM; + return -EINVAL; - *ret = n; - return 0; + return unit_name_unescape(u->instance, ret); } static int specifier_filename(char specifier, void *data, void *userdata, char **ret) { Unit *u = userdata; - char *n; assert(u); if (u->instance) - n = unit_name_path_unescape(u->instance); + return unit_name_path_unescape(u->instance, ret); else - n = unit_name_to_path(u->id); - if (!n) - return -ENOMEM; - - *ret = n; - return 0; + return unit_name_to_path(u->id, ret); } static int specifier_cgroup(char specifier, void *data, void *userdata, char **ret) { @@ -195,7 +166,7 @@ static int specifier_user_name(char specifier, void *data, void *userdata, char c = unit_get_exec_context(u); if (!c) - return -EOPNOTSUPP; + return -EINVAL; if (u->manager->running_as == SYSTEMD_SYSTEM) { |