~gotwig/indicator-pantheon-session/indicator-pantheon-session

« back to all changes in this revision

Viewing changes to src/gtk-dialog/ck-pk-helper.c

  • Committer: Bazaar Package Importer
  • Author(s): Ted Gould
  • Date: 2009-09-24 17:07:51 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090924170751-l7afnthkpri6diwd
Tags: 0.1.5-0ubuntu1
* Upstream release 0.1.5 (LP: #436223)
  * PolicyKit-1 support (LP: #418643)
  * GDM User list support (LP: #422052)
  * MissionControl5 support (LP: #427643)
  * Better locking of the screensaver (LP: #428115)
* debian/control: Adding in a libempathy-dev build dependency
  as it's now required by upstream.
* Removing patches 01_polkit-1.patch and 99_autoreconf.patch
  as they were merged upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <unistd.h>
25
25
#include <glib.h>
26
26
#include <dbus/dbus-glib.h>
27
 
#include <polkit-gnome/polkit-gnome.h>
 
27
#include <polkit/polkit.h>
28
28
 
29
29
#include "logout-dialog.h"
30
30
#include "ck-pk-helper.h"
170
170
                }
171
171
        }
172
172
 
173
 
        PolKitResult polres;
 
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
 
                        return FALSE;
 
176
                if (polkit_authorization_result_get_is_challenge (polres)) {
 
177
                        ret = TRUE;
177
178
                }
178
 
                return TRUE;
179
 
        }
180
 
        return FALSE;
 
179
                g_debug ("pk_require_auth(%s): authorized, is_challenge: %i", pk_action, ret);
 
180
        } else {
 
181
                g_debug ("pk_require_auth(%s): not authorized", pk_action);
 
182
        }
 
183
        if (polres) {
 
184
                g_object_unref (polres);
 
185
        }
 
186
        return ret;
181
187
}
182
188
 
183
189
gboolean
184
 
pk_can_do_action (const gchar    *action_id, PolKitResult * pol_result)
 
190
pk_can_do_action (const gchar    *action_id, PolkitAuthorizationResult ** pol_result)
185
191
{
186
 
        PolKitGnomeContext *gnome_context;
187
 
        PolKitAction *action;
188
 
        PolKitCaller *caller;
189
 
        DBusError dbus_error;
190
 
        PolKitError *error;
191
 
        PolKitResult result;
192
 
 
193
 
        gnome_context = polkit_gnome_context_get (NULL);
194
 
 
195
 
        if (gnome_context == NULL) {
196
 
                return FALSE;
197
 
        }
198
 
 
199
 
        if (gnome_context->pk_tracker == NULL) {
200
 
                return FALSE;
201
 
        }
202
 
 
203
 
        dbus_error_init (&dbus_error);
204
 
        caller = polkit_tracker_get_caller_from_pid (gnome_context->pk_tracker,
205
 
                                                     getpid (),
206
 
                                                     &dbus_error);
207
 
        dbus_error_free (&dbus_error);
208
 
 
209
 
        if (caller == NULL) {
210
 
                return FALSE;
211
 
        }
212
 
 
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);
217
 
                return FALSE;
218
 
        }
219
 
 
220
 
        result = POLKIT_RESULT_UNKNOWN;
221
 
        error = NULL;
222
 
        result = polkit_context_is_caller_authorized (gnome_context->pk_context,
223
 
                                                      action, caller, FALSE,
224
 
                                                      &error);
225
 
        if (polkit_error_is_set (error)) {
226
 
                polkit_error_free (error);
227
 
        }
228
 
        polkit_action_unref (action);
229
 
                polkit_caller_unref (caller);
230
 
 
231
 
                if (pol_result != NULL) {
232
 
                        *pol_result = result;
233
 
                }
234
 
 
235
 
        return result != POLKIT_RESULT_NO && result != POLKIT_RESULT_UNKNOWN;
 
192
        PolkitAuthority *authority;
 
193
        PolkitSubject *subject;
 
194
        PolkitAuthorizationResult *result;
 
195
        gboolean ret;
 
196
 
 
197
        authority = polkit_authority_get();
 
198
        if (!authority) {
 
199
                g_warning ("Could not get PolicyKit authority instance");
 
200
                return FALSE;
 
201
        }
 
202
        subject = polkit_unix_process_new (getpid());
 
203
 
 
204
        result = polkit_authority_check_authorization_sync (authority, subject, action_id, NULL, 0, NULL, NULL);
 
205
        g_object_unref (authority);
 
206
 
 
207
        ret = FALSE;
 
208
        if (result) {
 
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);
 
212
        } else {
 
213
                g_warning ("pk_can_do_action(%s): check_authorization returned NULL", action_id);
 
214
        }
 
215
        if (pol_result) {
 
216
                *pol_result = result;
 
217
        } else {
 
218
                g_object_unref (result);
 
219
        }
 
220
        return ret;
 
221
        
236
222
}