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
+11 -12
View File
@@ -196,12 +196,15 @@ int socket_instantiate_service(Socket *s) {
* here. For Accept=no this is mostly a NOP since the service
* is figured out at load time anyway. */
if (UNIT_DEREF(s->service) || !s->accept)
if (UNIT_DEREF(s->service))
return 0;
prefix = unit_name_to_prefix(UNIT(s)->id);
if (!prefix)
return -ENOMEM;
if (!s->accept)
return 0;
r = unit_name_to_prefix(UNIT(s)->id, &prefix);
if (r < 0)
return r;
if (asprintf(&name, "%s@%u.service", prefix, s->n_accepted) < 0)
return -ENOMEM;
@@ -1836,17 +1839,13 @@ static void socket_enter_running(Socket *s, int cfd) {
return;
}
prefix = unit_name_to_prefix(UNIT(s)->id);
if (!prefix) {
r = -ENOMEM;
r = unit_name_to_prefix(UNIT(s)->id, &prefix);
if (r < 0)
goto fail;
}
name = unit_name_build(prefix, instance, ".service");
if (!name) {
r = -ENOMEM;
r = unit_name_build(prefix, instance, ".service", &name);
if (r < 0)
goto fail;
}
r = unit_add_name(UNIT_DEREF(s->service), name);
if (r < 0)