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
This commit is contained in:
Lennart Poettering
2015-04-30 20:21:00 +02:00
parent 6442185ab6
commit 7410616cd9
34 changed files with 1066 additions and 867 deletions

View File

@@ -41,9 +41,9 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
else {
char *n;
n = unit_name_mangle(value, MANGLE_NOGLOB);
if (!n)
return log_oom();
r = unit_name_mangle(value, UNIT_NAME_NOGLOB, &n);
if (r < 0)
return log_error_errno(r, "Failed to glob unit name: %m");
r = strv_consume(&arg_mask, n);
if (r < 0)
@@ -57,9 +57,9 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
else {
char *n;
n = unit_name_mangle(value, MANGLE_NOGLOB);
if (!n)
return log_oom();
r = unit_name_mangle(value, UNIT_NAME_NOGLOB, &n);
if (r < 0)
return log_error_errno(r, "Failed to glob unit name: %m");
r = strv_consume(&arg_wants, n);
if (r < 0)