chiark / gitweb /
Allow tabs in environment files
[elogind.git] / src / hostname / hostnamed.c
index c5a8b6faafc1b45bd2a8ba283573066f306d8a93..6a43aeb840c36ab8d2903ce86418b62c8cd1c10f 100644 (file)
@@ -33,6 +33,8 @@
 #include "def.h"
 #include "virt.h"
 #include "env-util.h"
+#include "fileio-label.h"
+#include "label.h"
 
 #define INTERFACE \
         " <interface name=\"org.freedesktop.hostname1\">\n"             \
@@ -287,8 +289,7 @@ static int write_data_static_hostname(void) {
 
                 return 0;
         }
-
-        return write_one_line_file_atomic("/etc/hostname", data[PROP_STATIC_HOSTNAME]);
+        return write_string_file_atomic_label("/etc/hostname", data[PROP_STATIC_HOSTNAME]);
 }
 
 static int write_data_other(void) {
@@ -302,7 +303,7 @@ static int write_data_other(void) {
         char **l = NULL;
         int r, p;
 
-        r = load_env_file("/etc/machine-info", &l);
+        r = load_env_file("/etc/machine-info", NULL, &l);
         if (r < 0 && r != -ENOENT)
                 return r;
 
@@ -338,7 +339,7 @@ static int write_data_other(void) {
                 return 0;
         }
 
-        r = write_env_file("/etc/machine-info", l);
+        r = write_env_file_label("/etc/machine-info", l);
         strv_free(l);
 
         return r;
@@ -443,7 +444,7 @@ static DBusHandlerResult hostname_message_handler(
                                 return bus_send_error_reply(connection, message, NULL, r);
                         }
 
-                        log_info("Changed host name to '%s'", strempty(data[PROP_HOSTNAME]));
+                        log_info("Changed host name to '%s'", strna(data[PROP_HOSTNAME]));
 
                         changed = bus_properties_changed_new(
                                         "/org/freedesktop/hostname1",
@@ -497,7 +498,7 @@ static DBusHandlerResult hostname_message_handler(
                                 return bus_send_error_reply(connection, message, NULL, r);
                         }
 
-                        log_info("Changed static host name to '%s'", strempty(data[PROP_STATIC_HOSTNAME]));
+                        log_info("Changed static host name to '%s'", strna(data[PROP_STATIC_HOSTNAME]));
 
                         changed = bus_properties_changed_new(
                                         "/org/freedesktop/hostname1",
@@ -552,7 +553,8 @@ static DBusHandlerResult hostname_message_handler(
                                  * safe than sorry */
                                 if (k == PROP_ICON_NAME && !filename_is_safe(name))
                                         return bus_send_error_reply(connection, message, NULL, -EINVAL);
-                                if (k == PROP_PRETTY_HOSTNAME && !string_is_safe(name))
+                                if (k == PROP_PRETTY_HOSTNAME &&
+                                    (string_has_cc(name) || chars_intersect(name, "\t")))
                                         return bus_send_error_reply(connection, message, NULL, -EINVAL);
                                 if (k == PROP_CHASSIS && !valid_chassis(name))
                                         return bus_send_error_reply(connection, message, NULL, -EINVAL);
@@ -573,7 +575,7 @@ static DBusHandlerResult hostname_message_handler(
 
                         log_info("Changed %s to '%s'",
                                  k == PROP_PRETTY_HOSTNAME ? "pretty host name" :
-                                 k == PROP_CHASSIS ? "chassis" : "icon name", strempty(data[k]));
+                                 k == PROP_CHASSIS ? "chassis" : "icon name", strna(data[k]));
 
                         changed = bus_properties_changed_new(
                                         "/org/freedesktop/hostname1",
@@ -591,7 +593,7 @@ static DBusHandlerResult hostname_message_handler(
         if (!reply)
                 goto oom;
 
-        if (!dbus_connection_send(connection, reply, NULL))
+        if (!bus_maybe_send_reply(connection, message, reply))
                 goto oom;
 
         dbus_message_unref(reply);
@@ -683,6 +685,7 @@ int main(int argc, char *argv[]) {
         log_open();
 
         umask(0022);
+        label_init("/etc");
 
         if (argc == 2 && streq(argv[1], "--introspect")) {
                 fputs(DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE