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:
@@ -83,9 +83,9 @@ static int add_swap(
|
||||
opts = filtered;
|
||||
}
|
||||
|
||||
name = unit_name_from_path(what, ".swap");
|
||||
if (!name)
|
||||
return log_oom();
|
||||
r = unit_name_from_path(what, ".swap", &name);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to generate unit name: %m");
|
||||
|
||||
unit = strjoin(arg_dest, "/", name, NULL);
|
||||
if (!unit)
|
||||
@@ -224,9 +224,9 @@ static int add_mount(
|
||||
noauto = nofail = automount = false;
|
||||
}
|
||||
|
||||
name = unit_name_from_path(where, ".mount");
|
||||
if (!name)
|
||||
return log_oom();
|
||||
r = unit_name_from_path(where, ".mount", &name);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to generate unit name: %m");
|
||||
|
||||
unit = strjoin(arg_dest, "/", name, NULL);
|
||||
if (!unit)
|
||||
@@ -290,9 +290,9 @@ static int add_mount(
|
||||
}
|
||||
|
||||
if (automount) {
|
||||
automount_name = unit_name_from_path(where, ".automount");
|
||||
if (!automount_name)
|
||||
return log_oom();
|
||||
r = unit_name_from_path(where, ".automount", &automount_name);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to generate unit name: %m");
|
||||
|
||||
automount_unit = strjoin(arg_dest, "/", automount_name, NULL);
|
||||
if (!automount_unit)
|
||||
|
||||
Reference in New Issue
Block a user