X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fhostname%2Fhostnamed.c;h=979dcfdc7f42442a2f9c485a3e1123eedd8e5794;hb=5052495bbaf318d132024e75295da2f5d721420c;hp=92b150bfc9d5e785770b853bb8efaa3b3885a7c9;hpb=7871c8e9327e4e5b18de9d8081b0f32fa38c2c1f;p=elogind.git diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 92b150bfc..979dcfdc7 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" \ @@ -156,6 +159,19 @@ static bool valid_chassis(const char *chassis) { chassis); } +static bool pretty_string_is_safe(const char *p) { + const char *t; + + assert(p); + + for (t = p; *t; t++) { + if (*t >= '\0' && *t < ' ') + return false; + } + + return true; +} + static const char* fallback_chassis(void) { int r; char *type; @@ -286,8 +302,7 @@ static int write_data_static_hostname(void) { return 0; } - - return write_one_line_file_atomic("/etc/hostname", data[PROP_STATIC_HOSTNAME]); + return write_one_line_file_atomic_label("/etc/hostname", data[PROP_STATIC_HOSTNAME]); } static int write_data_other(void) { @@ -337,7 +352,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; @@ -551,7 +566,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 && !pretty_string_is_safe(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); @@ -682,6 +697,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