+ } */
+ }
+ }
+ }
+
+ g_key_file_save_to_file(config, "/etc/machine-info", NULL);
+ g_key_file_unref(config);
+
+ return ret;
+}
+
+static gboolean
+on_handle_set_chassis(Hostname1 *hn1_passed_interf,
+ GDBusMethodInvocation *invoc,
+ const gchar *greet,
+ gpointer data) {
+
+ GVariant *params;
+ gchar *proposed_chassis_name, *valid_chassis_name_buf;
+ const gchar *bus_name;
+ gboolean policykit_auth, ret, try_to_set;
+ check_auth_result is_authed;
+ GKeyFile *config;
+
+ config = g_key_file_new();
+ proposed_chassis_name = NULL;
+ ret = try_to_set = FALSE;
+ valid_chassis_name_buf = (gchar *)g_malloc0(8192);
+
+ params = g_dbus_method_invocation_get_parameters(invoc);
+ g_variant_get(params, "(sb)", &proposed_chassis_name, &policykit_auth);
+ bus_name = g_dbus_method_invocation_get_sender(invoc);
+
+ g_strlcpy(valid_chassis_name_buf, proposed_chassis_name, (gsize)64);
+
+ /* verify caller has correct permissions via polkit */
+ is_authed = polkit_try_auth(bus_name, "org.freedesktop.hostname1.set-chassis", policykit_auth);
+
+ switch(is_authed) {
+
+ case AUTHORIZED_NATIVELY:
+ case AUTHORIZED_BY_PROMPT:
+ try_to_set = TRUE;
+ break;
+
+ case UNAUTHORIZED_NATIVELY:
+ case UNAUTHORIZED_FAILED_PROMPT:
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.EACCES", "Insufficient permissions to set chassis type.");
+ break;
+
+ case ERROR_BADBUS:
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.EFAULT", "Provided bus name is invalid.");
+ break;
+
+ case ERROR_BADACTION:
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.EFAULT", "Provided action ID is invalid.");
+ break;
+
+ case ERROR_GENERIC:
+ default:
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.ECANCELED", "Failed to set chassis type for unknown reason.");
+ break;
+ }
+
+ /* verify passed chassis type's validity */
+ if(try_to_set && proposed_chassis_name) {
+
+ if(!is_valid_chassis_type(proposed_chassis_name)) {
+
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.ECANCELED", "Chassis type must be 'desktop', 'laptop', 'server', 'tablet', 'handset', 'vm', or 'container'.");
+ g_free(valid_chassis_name_buf);
+
+ } else if(!(CHASSIS = valid_chassis_name_buf)) {
+
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.ECANCELED", "Failed to set chassis type for unknown reason.");
+ g_free(valid_chassis_name_buf);
+
+ } else {
+
+ hostname1_set_chassis(hn1_passed_interf, CHASSIS);
+ g_ptr_array_add(hostnamed_freeable, valid_chassis_name_buf);
+ hostname1_complete_set_chassis(hn1_passed_interf, invoc);
+
+ if(g_key_file_load_from_file(config, "/etc/machine-info", G_KEY_FILE_NONE, NULL)) {
+
+ ret = TRUE;
+ g_key_file_set_string(config, "hostnamed", "ChassisType", valid_chassis_name_buf);
+
+ }
+ }
+ }
+
+ g_key_file_save_to_file(config, "/etc/machine-info", NULL);
+ g_key_file_unref(config);
+
+ return ret;
+}
+
+static gboolean
+on_handle_set_icon_name(Hostname1 *hn1_passed_interf,
+ GDBusMethodInvocation *invoc,
+ const gchar *greet,
+ gpointer data) {
+
+ GVariant *params;
+ gchar *proposed_icon_name, *valid_icon_name_buf;
+ const gchar *bus_name;
+ gboolean policykit_auth, ret, try_to_set;
+ check_auth_result is_authed;
+ GKeyFile *config;
+
+ config = g_key_file_new();
+ proposed_icon_name = NULL;
+ ret = try_to_set = FALSE;
+
+ params = g_dbus_method_invocation_get_parameters(invoc);
+ g_variant_get(params, "(sb)", &proposed_icon_name, &policykit_auth);
+ bus_name = g_dbus_method_invocation_get_sender(invoc);
+
+ /* verify caller has correct permissions via polkit */
+ is_authed = polkit_try_auth(bus_name, "org.freedesktop.hostname1.set-icon-name", policykit_auth);
+
+ switch(is_authed) {
+
+ case AUTHORIZED_NATIVELY:
+ case AUTHORIZED_BY_PROMPT:
+ try_to_set = TRUE;
+ break;
+
+ case UNAUTHORIZED_NATIVELY:
+ case UNAUTHORIZED_FAILED_PROMPT:
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.EACCES", "Insufficient permissions to set icon name.");
+ break;
+
+ case ERROR_BADBUS:
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.EFAULT", "Provided bus name is invalid.");
+ break;
+
+ case ERROR_BADACTION:
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.EFAULT", "Provided action ID is invalid.");
+ break;
+
+ case ERROR_GENERIC:
+ default:
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.ECANCELED", "Failed to set icon name for unknown reason.");
+ break;
+ }
+
+ /* verify passed chassis type's validity */
+ if(try_to_set && proposed_icon_name) {
+
+ g_strlcpy(valid_icon_name_buf, proposed_icon_name, (gsize)64);
+
+ if(!(ICON = valid_icon_name_buf)) {
+
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.ECANCELED", "Failed to set icon name for unknown reason.");
+ g_free(valid_icon_name_buf);
+
+ } else {
+
+ hostname1_set_icon_name(hn1_passed_interf, ICON);
+ g_ptr_array_add(hostnamed_freeable, valid_icon_name_buf);
+ hostname1_complete_set_icon_name(hn1_passed_interf, invoc);
+
+ if(g_key_file_load_from_file(config, "/etc/machine-info", G_KEY_FILE_NONE, NULL)) {
+
+ ret = TRUE;
+ g_key_file_set_string(config, "hostnamed", "IconName", valid_icon_name_buf);
+
+ }
+ }
+ }
+
+ g_key_file_save_to_file(config, "/etc/machine-info", NULL);
+ g_key_file_unref(config);
+
+ return ret;