summaryrefslogtreecommitdiff
path: root/src/shared/dropin.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-30 20:21:00 +0200
committerLennart Poettering <lennart@poettering.net>2015-05-05 15:06:42 -0700
commit7410616cd9dbbec97cf98d75324da5cda2b2f7a2 (patch)
tree6d968995b3bdf961603ab4853bf078c0dbdce27c /src/shared/dropin.c
parent6442185ab674cc202d63c18605057b9a51ca2722 (diff)
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/shared/dropin.c')
-rw-r--r--src/shared/dropin.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/shared/dropin.c b/src/shared/dropin.c
index d1baad6192..963d05d32e 100644
--- a/src/shared/dropin.c
+++ b/src/shared/dropin.c
@@ -164,7 +164,7 @@ static int iterate_dir(
}
int unit_file_process_dir(
- Set * unit_path_cache,
+ Set *unit_path_cache,
const char *unit_path,
const char *name,
const char *suffix,
@@ -174,6 +174,7 @@ int unit_file_process_dir(
char ***strv) {
_cleanup_free_ char *path = NULL;
+ int r;
assert(unit_path);
assert(name);
@@ -184,22 +185,22 @@ int unit_file_process_dir(
return log_oom();
if (!unit_path_cache || set_get(unit_path_cache, path))
- iterate_dir(path, dependency, consumer, arg, strv);
+ (void) iterate_dir(path, dependency, consumer, arg, strv);
- if (unit_name_is_instance(name)) {
+ if (unit_name_is_valid(name, UNIT_NAME_INSTANCE)) {
_cleanup_free_ char *template = NULL, *p = NULL;
/* Also try the template dir */
- template = unit_name_template(name);
- if (!template)
- return log_oom();
+ r = unit_name_template(name, &template);
+ if (r < 0)
+ return log_error_errno(r, "Failed to generate template from unit name: %m");
p = strjoin(unit_path, "/", template, suffix, NULL);
if (!p)
return log_oom();
if (!unit_path_cache || set_get(unit_path_cache, p))
- iterate_dir(p, dependency, consumer, arg, strv);
+ (void) iterate_dir(p, dependency, consumer, arg, strv);
}
return 0;