]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/bus-unit-util.c
core: use strv_split_colon_pairs when parsing RootImageOptions
[thirdparty/systemd.git] / src / shared / bus-unit-util.c
index 30a872342ff732847d1310690eedbda887c3c633..d307e746f157c3b72d1364c444a175b714847c2d 100644 (file)
@@ -18,6 +18,7 @@
 #include "hostname-util.h"
 #include "in-addr-util.h"
 #include "ip-protocol-list.h"
+#include "libmount-util.h"
 #include "locale-util.h"
 #include "log.h"
 #include "missing_fs.h"
@@ -1455,6 +1456,8 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
         }
 
         if (streq(field, "RootImageOptions")) {
+                _cleanup_strv_free_ char **l = NULL;
+                char **first = NULL, **second = NULL;
                 const char *p = eq;
 
                 r = sd_bus_message_open_container(m, SD_BUS_TYPE_STRUCT, "sv");
@@ -1473,34 +1476,24 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
                 if (r < 0)
                         return bus_log_create_error(r);
 
-                for (;;) {
-                        _cleanup_free_ char *first = NULL, *tuple = NULL;
-                        const char *mount_options = NULL, *second = NULL;
-                        unsigned partition_number = 0;
-
-                        r = extract_first_word(&p, &tuple, WHITESPACE, EXTRACT_UNQUOTE);
-                        if (r == 0)
-                                break;
-                        if (r < 0)
-                                return log_error_errno(r, "Failed to parse argument: %m");
+                r = strv_split_colon_pairs(&l, p);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to parse argument: %m");
 
-                        second = tuple;
-                        r = extract_first_word(&second, &first, ":", EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS);
-                        if (r == 0)
-                                continue;
-                        if (r < 0)
-                                return log_error_errno(r, "Failed to parse argument: %m");
+                STRV_FOREACH_PAIR(first, second, l) {
+                        const char *mount_options;
+                        unsigned partition_number = 0;
 
                         /* Format is either '0:foo' or 'foo' (0 is implied) */
-                        if (!isempty(second) && second[-1] == ':') {
-                                mount_options = second;
-                                r = safe_atou(first, &partition_number);
+                        if (!isempty(*second)) {
+                                mount_options = *second;
+                                r = safe_atou(*first, &partition_number);
                                 if (r < 0) {
-                                        log_error_errno(r, "Failed to parse partition number from %s: %m", first);
+                                        log_error_errno(r, "Failed to parse partition number from %s: %m", *first);
                                         continue;
                                 }
                         } else
-                                mount_options = first;
+                                mount_options = *first;
 
                         r = sd_bus_message_append(m, "(us)", partition_number, mount_options);
                         if (r < 0)
@@ -1522,6 +1515,65 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
                 return 1;
         }
 
+        if (streq(field, "MountImages")) {
+                _cleanup_strv_free_ char **l = NULL;
+                char **source = NULL, **destination = NULL;
+                const char *p = eq;
+
+                r = sd_bus_message_open_container(m, SD_BUS_TYPE_STRUCT, "sv");
+                if (r < 0)
+                        return bus_log_create_error(r);
+
+                r = sd_bus_message_append_basic(m, SD_BUS_TYPE_STRING, field);
+                if (r < 0)
+                        return bus_log_create_error(r);
+
+                r = sd_bus_message_open_container(m, 'v', "a(ssb)");
+                if (r < 0)
+                        return bus_log_create_error(r);
+
+                r = sd_bus_message_open_container(m, 'a', "(ssb)");
+                if (r < 0)
+                        return bus_log_create_error(r);
+
+                r = strv_split_colon_pairs(&l, p);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to parse argument: %m");
+
+                STRV_FOREACH_PAIR(source, destination, l) {
+                        char *s = *source;
+                        bool permissive = false;
+
+                        if (s[0] == '-') {
+                                permissive = true;
+                                s++;
+                        }
+
+                        if (isempty(*destination))
+                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                                        "Missing argument after ':': %s",
+                                                        eq);
+
+                        r = sd_bus_message_append(m, "(ssb)", s, *destination, permissive);
+                        if (r < 0)
+                                return bus_log_create_error(r);
+                }
+
+                r = sd_bus_message_close_container(m);
+                if (r < 0)
+                        return bus_log_create_error(r);
+
+                r = sd_bus_message_close_container(m);
+                if (r < 0)
+                        return bus_log_create_error(r);
+
+                r = sd_bus_message_close_container(m);
+                if (r < 0)
+                        return bus_log_create_error(r);
+
+                return 1;
+        }
+
         return 0;
 }