summaryrefslogtreecommitdiff
path: root/src/core/mount.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/core/mount.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/core/mount.c')
-rw-r--r--src/core/mount.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/core/mount.c b/src/core/mount.c
index d0c41a73a9..65a66b468f 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -435,7 +435,7 @@ static int mount_add_default_dependencies(Mount *m) {
static int mount_verify(Mount *m) {
_cleanup_free_ char *e = NULL;
- bool b;
+ int r;
assert(m);
@@ -445,12 +445,11 @@ static int mount_verify(Mount *m) {
if (!m->from_fragment && !m->from_proc_self_mountinfo)
return -ENOENT;
- e = unit_name_from_path(m->where, ".mount");
- if (!e)
- return -ENOMEM;
+ r = unit_name_from_path(m->where, ".mount", &e);
+ if (r < 0)
+ return log_unit_error_errno(UNIT(m)->id, r, "Failed to generate unit name from mount path: %m");
- b = unit_has_name(UNIT(m), e);
- if (!b) {
+ if (!unit_has_name(UNIT(m), e)) {
log_unit_error(UNIT(m)->id, "%s's Where= setting doesn't match unit name. Refusing.", UNIT(m)->id);
return -EINVAL;
}
@@ -483,9 +482,9 @@ static int mount_add_extras(Mount *m) {
m->from_fragment = true;
if (!m->where) {
- m->where = unit_name_to_path(u->id);
- if (!m->where)
- return -ENOMEM;
+ r = unit_name_to_path(u->id, &m->where);
+ if (r < 0)
+ return r;
}
path_kill_slashes(m->where);
@@ -1419,9 +1418,9 @@ static int mount_setup_unit(
if (!is_path(where))
return 0;
- e = unit_name_from_path(where, ".mount");
- if (!e)
- return -ENOMEM;
+ r = unit_name_from_path(where, ".mount", &e);
+ if (r < 0)
+ return r;
u = manager_get_unit(m, e);
if (!u) {