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-05-05 15:06:42 -07:00
parent 6442185ab6
commit 7410616cd9
34 changed files with 1066 additions and 867 deletions
+5 -3
View File
@@ -310,11 +310,13 @@ static int sysv_translate_facility(const char *name, const char *filename, char
* out whether something is a target or a service alias. */
if (*name == '$') {
if (!unit_prefix_is_valid(n))
return -EINVAL;
int k;
/* Facilities starting with $ are most likely targets */
r = unit_name_build(n, NULL, ".target");
k = unit_name_build(n, NULL, ".target", &r);
if (k < 0)
return k;
} else if (streq_ptr(n, filename))
/* Names equaling the file name of the services are redundant */
return 0;