173
PolkitAuthorizationResult *polres = NULL;
174
gboolean ret = FALSE;
174
175
if (pk_can_do_action(pk_action, &polres)) {
175
if (polres == POLKIT_RESULT_YES) {
176
if (polkit_authorization_result_get_is_challenge (polres)) {
179
g_debug ("pk_require_auth(%s): authorized, is_challenge: %i", pk_action, ret);
181
g_debug ("pk_require_auth(%s): not authorized", pk_action);
184
g_object_unref (polres);
184
pk_can_do_action (const gchar *action_id, PolKitResult * pol_result)
190
pk_can_do_action (const gchar *action_id, PolkitAuthorizationResult ** pol_result)
186
PolKitGnomeContext *gnome_context;
187
PolKitAction *action;
188
PolKitCaller *caller;
189
DBusError dbus_error;
193
gnome_context = polkit_gnome_context_get (NULL);
195
if (gnome_context == NULL) {
199
if (gnome_context->pk_tracker == NULL) {
203
dbus_error_init (&dbus_error);
204
caller = polkit_tracker_get_caller_from_pid (gnome_context->pk_tracker,
207
dbus_error_free (&dbus_error);
209
if (caller == NULL) {
213
action = polkit_action_new ();
214
if (!polkit_action_set_action_id (action, action_id)) {
215
polkit_action_unref (action);
216
polkit_caller_unref (caller);
220
result = POLKIT_RESULT_UNKNOWN;
222
result = polkit_context_is_caller_authorized (gnome_context->pk_context,
223
action, caller, FALSE,
225
if (polkit_error_is_set (error)) {
226
polkit_error_free (error);
228
polkit_action_unref (action);
229
polkit_caller_unref (caller);
231
if (pol_result != NULL) {
232
*pol_result = result;
235
return result != POLKIT_RESULT_NO && result != POLKIT_RESULT_UNKNOWN;
192
PolkitAuthority *authority;
193
PolkitSubject *subject;
194
PolkitAuthorizationResult *result;
197
authority = polkit_authority_get();
199
g_warning ("Could not get PolicyKit authority instance");
202
subject = polkit_unix_process_new (getpid());
204
result = polkit_authority_check_authorization_sync (authority, subject, action_id, NULL, 0, NULL, NULL);
205
g_object_unref (authority);
209
ret = polkit_authorization_result_get_is_authorized (result) ||
210
polkit_authorization_result_get_is_challenge (result);
211
g_debug ("pk_can_do_action(%s): %i", action_id, ret);
213
g_warning ("pk_can_do_action(%s): check_authorization returned NULL", action_id);
216
*pol_result = result;
218
g_object_unref (result);