summaryrefslogtreecommitdiff
path: root/src/machine
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-30 20:21:00 +0200
committerLennart Poettering <lennart@poettering.net>2015-05-05 15:06:42 -0700
commit7410616cd9dbbec97cf98d75324da5cda2b2f7a2 (patch)
tree6d968995b3bdf961603ab4853bf078c0dbdce27c /src/machine
parent6442185ab674cc202d63c18605057b9a51ca2722 (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/machine')
-rw-r--r--src/machine/machinectl.c55
1 files changed, 30 insertions, 25 deletions
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index ed7221800f..9931e4f1fd 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -1340,6 +1340,29 @@ static int read_only_image(int argc, char *argv[], void *userdata) {
return 0;
}
+static int make_service_name(const char *name, char **ret) {
+ _cleanup_free_ char *e = NULL;
+ int r;
+
+ assert(name);
+ assert(ret);
+
+ if (!machine_name_is_valid(name)) {
+ log_error("Invalid machine name %s.", name);
+ return -EINVAL;
+ }
+
+ e = unit_name_escape(name);
+ if (!e)
+ return log_oom();
+
+ r = unit_name_build("systemd-nspawn", e, ".service", ret);
+ if (r < 0)
+ return log_error_errno(r, "Failed to build unit name: %m");
+
+ return 0;
+}
+
static int start_machine(int argc, char *argv[], void *userdata) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(bus_wait_for_jobs_freep) BusWaitForJobs *w = NULL;
@@ -1356,21 +1379,12 @@ static int start_machine(int argc, char *argv[], void *userdata) {
for (i = 1; i < argc; i++) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
- _cleanup_free_ char *e = NULL, *unit = NULL;
+ _cleanup_free_ char *unit = NULL;
const char *object;
- if (!machine_name_is_valid(argv[i])) {
- log_error("Invalid machine name %s.", argv[i]);
- return -EINVAL;
- }
-
- e = unit_name_escape(argv[i]);
- if (!e)
- return log_oom();
-
- unit = unit_name_build("systemd-nspawn", e, ".service");
- if (!unit)
- return log_oom();
+ r = make_service_name(argv[i], &unit);
+ if (r < 0)
+ return r;
r = sd_bus_call_method(
bus,
@@ -1433,18 +1447,9 @@ static int enable_machine(int argc, char *argv[], void *userdata) {
for (i = 1; i < argc; i++) {
_cleanup_free_ char *e = NULL, *unit = NULL;
- if (!machine_name_is_valid(argv[i])) {
- log_error("Invalid machine name %s.", argv[i]);
- return -EINVAL;
- }
-
- e = unit_name_escape(argv[i]);
- if (!e)
- return log_oom();
-
- unit = unit_name_build("systemd-nspawn", e, ".service");
- if (!unit)
- return log_oom();
+ r = make_service_name(argv[i], &unit);
+ if (r < 0)
+ return r;
r = sd_bus_message_append(m, "s", unit);
if (r < 0)