+static gboolean
+on_handle_set_location(Hostname1 *hn1_passed_interf,
+ GDBusMethodInvocation *invoc,
+ const gchar *greet,
+ gpointer data) {
+ GVariant *params;
+ const gchar *bus_name;
+ gchar *proposed_location, *valid_location_buf;
+ gboolean policykit_auth, ret, try_to_set;
+ check_auth_result is_authed;
+
+ ret = try_to_set = FALSE;
+
+ params = g_dbus_method_invocation_get_parameters(invoc);
+ g_variant_get(params, "(sb)", &proposed_location, &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-location", 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 location.");
+ return FALSE;
+ break;
+
+ case ERROR_BADBUS:
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.EFAULT", "Provided bus name is invalid.");
+ return FALSE;
+ break;
+
+ case ERROR_BADACTION:
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.EFAULT", "Provided action ID is invalid.");
+ return FALSE;
+ break;
+
+ case ERROR_GENERIC:
+ default:
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.ECANCELED", "Failed to set location for unknown reason.");
+ return FALSE;
+ break;
+ }
+ /* XXX follow systemd impl here */
+ LOCATION = (gchar *) g_malloc0(LOCATION_MAXSIZE);
+ g_strlcpy(LOCATION, proposed_location, LOCATION_MAXSIZE);
+ hostname1_set_location(hn1_passed_interf, LOCATION);
+ g_ptr_array_add(hostnamed_freeable, valid_location_buf);
+ hostname1_complete_set_location(hn1_passed_interf, invoc);
+ return TRUE;
+}
+
+static gboolean
+on_handle_set_deployment(Hostname1 *hn1_passed_interf,
+ GDBusMethodInvocation *invoc,
+ const gchar *greet,
+ gpointer data) {
+ GVariant *params;
+ const gchar *bus_name;
+ gchar *proposed_deployment, *valid_deployment_buf;
+ gboolean policykit_auth, ret, try_to_set;
+ check_auth_result is_authed;
+
+ ret = try_to_set = FALSE;
+
+ params = g_dbus_method_invocation_get_parameters(invoc);
+ g_variant_get(params, "(sb)", &proposed_deployment, &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-deployment", 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 deployment.");
+ return FALSE;
+ break;
+
+ case ERROR_BADBUS:
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.EFAULT", "Provided bus name is invalid.");
+ return FALSE;
+ break;
+
+ case ERROR_BADACTION:
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.EFAULT", "Provided action ID is invalid.");
+ return FALSE;
+ break;
+
+ case ERROR_GENERIC:
+ default:
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.ECANCELED", "Failed to set deployment for unknown reason.");
+ return FALSE;
+ break;
+ }
+ /* XXX follow systemd impl here */
+ DEPLOYMENT = (gchar *) g_malloc0(DEPLOYMENT_MAXSIZE);
+ g_strlcpy(DEPLOYMENT, proposed_deployment, DEPLOYMENT_MAXSIZE);
+ hostname1_set_deployment(hn1_passed_interf, DEPLOYMENT);
+ g_ptr_array_add(hostnamed_freeable, valid_deployment_buf);
+ hostname1_complete_set_deployment(hn1_passed_interf, invoc);
+ return TRUE;
+}