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/automount.c | |
parent | 6442185ab674cc202d63c18605057b9a51ca2722 (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/core/automount.c')
-rw-r--r-- | src/core/automount.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/core/automount.c b/src/core/automount.c index 73b75f163e..1806fa39d3 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -167,8 +167,9 @@ static int automount_add_default_dependencies(Automount *a) { } static int automount_verify(Automount *a) { - bool b; _cleanup_free_ char *e = NULL; + int r; + assert(a); if (UNIT(a)->load_state != UNIT_LOADED) @@ -179,13 +180,11 @@ static int automount_verify(Automount *a) { return -EINVAL; } - e = unit_name_from_path(a->where, ".automount"); - if (!e) - return -ENOMEM; - - b = unit_has_name(UNIT(a), e); + r = unit_name_from_path(a->where, ".automount", &e); + if (r < 0) + return log_unit_error(UNIT(a)->id, "Failed to generate unit name from path: %m"); - if (!b) { + if (!unit_has_name(UNIT(a), e)) { log_unit_error(UNIT(a)->id, "%s's Where setting doesn't match unit name. Refusing.", UNIT(a)->id); return -EINVAL; } @@ -209,9 +208,9 @@ static int automount_load(Unit *u) { Unit *x; if (!a->where) { - a->where = unit_name_to_path(u->id); - if (!a->where) - return -ENOMEM; + r = unit_name_to_path(u->id, &a->where); + if (r < 0) + return r; } path_kill_slashes(a->where); |