- } else if (dbus_message_is_method_call(message, "org.freedesktop.hostname1", "SetPrettyHostname") ||
- dbus_message_is_method_call(message, "org.freedesktop.hostname1", "SetIconName") ||
- dbus_message_is_method_call(message, "org.freedesktop.hostname1", "SetChassis")) {
-
- const char *name;
- dbus_bool_t interactive;
- int k;
-
- if (!dbus_message_get_args(
- message,
- &error,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_BOOLEAN, &interactive,
- DBUS_TYPE_INVALID))
- return bus_send_error_reply(connection, message, &error, -EINVAL);
-
- if (isempty(name))
- name = NULL;
-
- k = streq(dbus_message_get_member(message), "SetPrettyHostname") ? PROP_PRETTY_HOSTNAME :
- streq(dbus_message_get_member(message), "SetChassis") ? PROP_CHASSIS : PROP_ICON_NAME;
-
- if (!streq_ptr(name, data[k])) {
-
- /* Since the pretty hostname should always be
- * changed at the same time as the static one,
- * use the same policy action for both... */
-
- r = verify_polkit(connection, message, k == PROP_PRETTY_HOSTNAME ?
- "org.freedesktop.hostname1.set-static-hostname" :
- "org.freedesktop.hostname1.set-machine-info", interactive, NULL, &error);
- if (r < 0)
- return bus_send_error_reply(connection, message, &error, r);
-
- if (isempty(name)) {
- free(data[k]);
- data[k] = NULL;
- } else {
- char *h;
-
- /* The icon name might ultimately be
- * used as file name, so better be
- * 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_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);
-
- h = strdup(name);
- if (!h)
- goto oom;
-
- free(data[k]);
- data[k] = h;
- }
-
- r = write_data_other();
- if (r < 0) {
- log_error("Failed to write machine info: %s", strerror(-r));
- return bus_send_error_reply(connection, message, NULL, r);
- }
-
- log_info("Changed %s to '%s'",
- k == PROP_PRETTY_HOSTNAME ? "pretty host name" :
- k == PROP_CHASSIS ? "chassis" : "icon name", strempty(data[k]));
-
- changed = bus_properties_changed_new(
- "/org/freedesktop/hostname1",
- "org.freedesktop.hostname1",
- k == PROP_PRETTY_HOSTNAME ? "PrettyHostname\0" :
- k == PROP_CHASSIS ? "Chassis\0" : "IconName\0");
- if (!changed)
- goto oom;
- }
+ h = strdup(name);
+ if (!h)
+ return -ENOMEM;
+
+ free(c->data[PROP_STATIC_HOSTNAME]);
+ c->data[PROP_STATIC_HOSTNAME] = h;
+ }
+
+ r = context_write_data_static_hostname(c);
+ if (r < 0) {
+ log_error("Failed to write static host name: %s", strerror(-r));
+ return sd_bus_error_set_errnof(error, r, "Failed to set static hostname: %s", strerror(-r));
+ }
+
+ log_info("Changed static host name to '%s'", strna(c->data[PROP_STATIC_HOSTNAME]));
+
+ sd_bus_emit_properties_changed(bus, "/org/freedesktop/hostname1", "org.freedesktop.hostname1", "StaticHostname", NULL);
+
+ return sd_bus_reply_method_return(m, NULL);
+}
+
+static int set_machine_info(Context *c, sd_bus *bus, sd_bus_message *m, int prop, sd_bus_message_handler_t cb, sd_bus_error *error) {
+ int interactive;
+ const char *name;
+ int r;
+
+ assert(c);
+ assert(bus);
+ assert(m);