static void check_auth_cb (PolkitAuthority *authority, GAsyncResult *res, gpointer data) { CheckAuthData *cad = data; PolkitAuthorizationResult *result; GError *error; gboolean is_authorized; is_authorized = FALSE; error = NULL; result = polkit_authority_check_authorization_finish (authority, res, &error); if (error) { throw_error (cad->context, ERROR_PERMISSION_DENIED, "Not authorized: %s", error->message); g_error_free (error); } else { if (polkit_authorization_result_get_is_authorized (result)) { is_authorized = TRUE; } else if (polkit_authorization_result_get_is_challenge (result)) { throw_error (cad->context, ERROR_PERMISSION_DENIED, "Authentication is required"); } else { throw_error (cad->context, ERROR_PERMISSION_DENIED, "Not authorized"); } g_object_unref (result); } if (is_authorized) { (* cad->authorized_cb) (cad->daemon, cad->user, cad->context, cad->data); } check_auth_data_free (data); }
static void check_authorization_callback (PolkitAuthority *authority, GAsyncResult *res, gpointer user_data) { CheckAuthData *data = user_data; PolkitAuthorizationResult *result; GError *error; gboolean is_authorized; is_authorized = FALSE; error = NULL; result = polkit_authority_check_authorization_finish (authority, res, &error); if (error != NULL) { g_debug ("error checking action '%s'\n", error->message); throw_error (data->context, GCONF_DEFAULTS_ERROR_NOT_PRIVILEGED, "Not Authorized: %s", error->message); g_error_free (error); } else { if (polkit_authorization_result_get_is_authorized (result)) { g_debug ("result for '%s': authorized\n", data->actions[data->id]); is_authorized = TRUE; } else if (polkit_authorization_result_get_is_challenge (result)) { g_debug ("result for '%s': challenge\n", data->actions[data->id]); throw_error (data->context, GCONF_DEFAULTS_ERROR_NOT_PRIVILEGED, "Authorization is required"); } else { g_debug ("result for '%s': not authorized\n", data->actions[data->id]); throw_error (data->context, GCONF_DEFAULTS_ERROR_NOT_PRIVILEGED, "Not Authorized"); } } if (is_authorized) { data->id++; if (data->actions[data->id] == NULL) data->auth_obtained_callback (data->mechanism, data->context, data->user_data); else { check_next_action (data); return; /* continue operation */ } } check_auth_data_free (data); g_object_unref (result); stop_operation (); }