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/gpt-auto-generator/gpt-auto-generator.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/gpt-auto-generator/gpt-auto-generator.c')
-rw-r--r-- | src/gpt-auto-generator/gpt-auto-generator.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index 96a8447efd..b192526186 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -49,14 +49,15 @@ static bool arg_root_rw = false; static int add_swap(const char *path) { _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL; _cleanup_fclose_ FILE *f = NULL; + int r; assert(path); log_debug("Adding swap: %s", path); - name = unit_name_from_path(path, ".swap"); - if (!name) - return log_oom(); + r = unit_name_from_path(path, ".swap", &name); + if (r < 0) + return log_error_errno(r, "Failed to generate unit name: %m"); unit = strjoin(arg_dest, "/", name, NULL); if (!unit) @@ -100,17 +101,17 @@ static int add_cryptsetup(const char *id, const char *what, bool rw, char **devi assert(what); assert(device); - d = unit_name_from_path(what, ".device"); - if (!d) - return log_oom(); + r = unit_name_from_path(what, ".device", &d); + if (r < 0) + return log_error_errno(r, "Failed to generate unit name: %m"); e = unit_name_escape(id); if (!e) return log_oom(); - n = unit_name_build("systemd-cryptsetup", e, ".service"); - if (!n) - return log_oom(); + r = unit_name_build("systemd-cryptsetup", e, ".service", &n); + if (r < 0) + return log_error_errno(r, "Failed to generate unit name: %m"); p = strjoin(arg_dest, "/", n, NULL); if (!p) @@ -224,9 +225,9 @@ static int add_mount( fstype = NULL; } - unit = unit_name_from_path(where, ".mount"); - if (!unit) - return log_oom(); + r = unit_name_from_path(where, ".mount", &unit); + if (r < 0) + return log_error_errno(r, "Failed to generate unit name: %m"); p = strjoin(arg_dest, "/", unit, NULL); if (!p) |