X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fhostname%2Fhostnamed.c;h=0437e33a664c18016ab0319552ebe088c15719a5;hb=fda2c5d28bdf5c6ac1ff1ba504fa884c48ed1439;hp=92b150bfc9d5e785770b853bb8efaa3b3885a7c9;hpb=f274ece0f76b5709408821e317e87aef76123db6;p=elogind.git diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 92b150bfc..0437e33a6 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,7 @@ 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)) 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 +574,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 +592,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 +684,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