X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fhostname%2Fhostnamed.c;h=6a43aeb840c36ab8d2903ce86418b62c8cd1c10f;hb=ac4c8d6da8b5ebc35f02c9c6cb7595be7b134a05;hp=92b150bfc9d5e785770b853bb8efaa3b3885a7c9;hpb=7871c8e9327e4e5b18de9d8081b0f32fa38c2c1f;p=elogind.git diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 92b150bfc..6a43aeb84 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -32,6 +32,9 @@ #include "polkit.h" #include "def.h" #include "virt.h" +#include "env-util.h" +#include "fileio-label.h" +#include "label.h" #define INTERFACE \ " \n" \ @@ -286,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) { @@ -301,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; @@ -337,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; @@ -442,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", @@ -496,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", @@ -551,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); @@ -572,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", @@ -590,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); @@ -682,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