polkitauthority.c 68.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * Copyright (C) 2008 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: David Zeuthen <davidz@redhat.com>
 */

#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

26
#include "polkitauthorizationresult.h"
27
#include "polkitcheckauthorizationflags.h"
28
#include "polkitauthority.h"
29
#include "polkiterror.h"
30
#include "polkitenumtypes.h"
31 32 33 34 35 36 37

#include "polkitprivate.h"

/**
 * SECTION:polkitauthority
 * @title: PolkitAuthority
 * @short_description: Authority
38
 * @stability: Stable
39
 *
40 41 42 43 44 45 46 47
 * #PolkitAuthority is used for checking whether a given subject is
 * authorized to perform a given action. Typically privileged system
 * daemons or suid helpers will use this when handling requests from
 * untrusted clients.
 *
 * User sessions can register an authentication agent with the
 * authority. This is used for requests from untrusted clients where
 * system policy requires that the user needs to acknowledge (through
David Zeuthen's avatar
David Zeuthen committed
48 49
 * proving he is the user or the administrator) a given action. See
 * #PolkitAgentListener and #PolkitAgentSession for details.
50 51
 */

52 53 54 55 56
/**
 * PolkitAuthority:
 *
 * The #PolkitAuthority struct should not be accessed directly.
 */
57 58
struct _PolkitAuthority
{
59
  /*< private >*/
60 61
  GObject parent_instance;

62
  EggDBusConnection *system_bus;
63 64 65
  EggDBusObjectProxy *authority_object_proxy;

  _PolkitAuthority *real;
66 67
  gchar *name;
  gchar *version;
68 69

  guint cancellation_id_counter;
70 71 72 73 74 75 76 77 78 79 80 81
};

struct _PolkitAuthorityClass
{
  GObjectClass parent_class;

};

/* TODO: locking */

static PolkitAuthority *the_authority = NULL;

82 83 84 85 86 87
enum
{
  CHANGED_SIGNAL,
  LAST_SIGNAL,
};

88 89 90 91 92 93 94 95
enum
{
  PROP_0,
  PROP_BACKEND_NAME,
  PROP_BACKEND_VERSION,
  PROP_BACKEND_FEATURES
};

96 97
static guint signals[LAST_SIGNAL] = {0};

98 99
G_DEFINE_TYPE (PolkitAuthority, polkit_authority, G_TYPE_OBJECT);

100 101 102 103 104 105 106 107 108
static void
real_authority_changed (_PolkitAuthority *real_authority,
                        gpointer user_data)
{
  PolkitAuthority *authority = POLKIT_AUTHORITY (user_data);

  g_signal_emit_by_name (authority, "changed");
}

109 110 111
static void
polkit_authority_init (PolkitAuthority *authority)
{
112
  authority->system_bus = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM);
113

114
  authority->authority_object_proxy = egg_dbus_connection_get_object_proxy (authority->system_bus,
115 116 117 118
                                                                            "org.freedesktop.PolicyKit1",
                                                                            "/org/freedesktop/PolicyKit1/Authority");

  authority->real = _POLKIT_QUERY_INTERFACE_AUTHORITY (authority->authority_object_proxy);
119 120 121 122 123

  g_signal_connect (authority->real,
                    "changed",
                    (GCallback) real_authority_changed,
                    authority);
124 125 126 127 128 129 130 131 132 133
}

static void
polkit_authority_finalize (GObject *object)
{
  PolkitAuthority *authority;

  authority = POLKIT_AUTHORITY (object);

  g_object_unref (authority->authority_object_proxy);
134
  g_object_unref (authority->system_bus);
135 136
  g_free (authority->name);
  g_free (authority->version);
137 138

  the_authority = NULL;
139 140 141

  if (G_OBJECT_CLASS (polkit_authority_parent_class)->finalize != NULL)
    G_OBJECT_CLASS (polkit_authority_parent_class)->finalize (object);
142 143
}

144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
static void
polkit_authority_get_property (GObject    *object,
                               guint       prop_id,
                               GValue     *value,
                               GParamSpec *pspec)
{
  PolkitAuthority *authority = POLKIT_AUTHORITY (object);

  switch (prop_id)
    {
    case PROP_BACKEND_NAME:
      g_value_set_string (value, polkit_authority_get_backend_name (authority));
      break;

    case PROP_BACKEND_VERSION:
      g_value_set_string (value, polkit_authority_get_backend_version (authority));
      break;

    case PROP_BACKEND_FEATURES:
      g_value_set_flags (value, polkit_authority_get_backend_features (authority));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

172 173 174 175 176
static void
polkit_authority_class_init (PolkitAuthorityClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
  gobject_class->finalize     = polkit_authority_finalize;
  gobject_class->get_property = polkit_authority_get_property;

  /**
   * PolkitAuthority:backend-name:
   *
   * The name of the currently used Authority backend.
   */
  g_object_class_install_property (gobject_class,
                                   PROP_BACKEND_NAME,
                                   g_param_spec_string ("backend-name",
                                                        "Backend name",
                                                        "The name of the currently used Authority backend.",
                                                        NULL,
                                                        G_PARAM_READABLE |
                                                        G_PARAM_STATIC_NAME |
                                                        G_PARAM_STATIC_NICK |
                                                        G_PARAM_STATIC_BLURB));

  /**
   * PolkitAuthority:version:
   *
   * The version of the currently used Authority backend.
   */
  g_object_class_install_property (gobject_class,
                                   PROP_BACKEND_VERSION,
                                   g_param_spec_string ("backend-version",
                                                        "Backend version",
                                                        "The version of the currently used Authority backend.",
                                                        NULL,
                                                        G_PARAM_READABLE |
                                                        G_PARAM_STATIC_NAME |
                                                        G_PARAM_STATIC_NICK |
                                                        G_PARAM_STATIC_BLURB));

  /**
   * PolkitAuthority:backend-features:
   *
   * The features of the currently used Authority backend.
   */
  g_object_class_install_property (gobject_class,
                                   PROP_BACKEND_FEATURES,
                                   g_param_spec_flags ("backend-features",
                                                       "Backend features",
                                                       "The features of the currently used Authority backend.",
                                                       POLKIT_TYPE_AUTHORITY_FEATURES,
                                                       POLKIT_AUTHORITY_FEATURES_NONE,
                                                       G_PARAM_READABLE |
                                                       G_PARAM_STATIC_NAME |
                                                       G_PARAM_STATIC_NICK |
                                                       G_PARAM_STATIC_BLURB));
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243

  /**
   * PolkitAuthority::changed:
   * @authority: A #PolkitAuthority.
   *
   * Emitted when actions and/or authorizations change
   */
  signals[CHANGED_SIGNAL] = g_signal_new ("changed",
                                          POLKIT_TYPE_AUTHORITY,
                                          G_SIGNAL_RUN_LAST,
                                          0,                      /* class offset     */
                                          NULL,                   /* accumulator      */
                                          NULL,                   /* accumulator data */
                                          g_cclosure_marshal_VOID__VOID,
                                          G_TYPE_NONE,
                                          0);
244 245
}

246 247 248 249 250 251 252
/**
 * polkit_authority_get:
 *
 * Gets a reference to the authority.
 *
 * Returns: A #PolkitAuthority. Free it with g_object_unref() when done with it.
 **/
253 254 255
PolkitAuthority *
polkit_authority_get (void)
{
256 257
  if (the_authority != NULL) {
    g_object_ref (the_authority);
258
    goto out;
259
  }
260 261 262 263 264 265 266

  the_authority = POLKIT_AUTHORITY (g_object_new (POLKIT_TYPE_AUTHORITY, NULL));

 out:
  return the_authority;
}

267 268 269 270 271 272 273 274 275 276
static void
generic_cb (GObject      *source_obj,
            GAsyncResult *res,
            gpointer      user_data)
{
  GAsyncResult **target_res = user_data;

  *target_res = g_object_ref (res);
}

277 278 279 280 281 282 283 284 285 286 287
static void
generic_async_cb (GObject      *source_obj,
                  GAsyncResult *res,
                  gpointer      user_data)
{
  GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);

  g_simple_async_result_set_op_res_gpointer (simple, g_object_ref (res), g_object_unref);
  g_simple_async_result_complete (simple);
}

288 289 290 291 292 293 294 295 296
/* ---------------------------------------------------------------------------------------------------- */

static guint
polkit_authority_enumerate_actions_async (PolkitAuthority     *authority,
                                          GCancellable        *cancellable,
                                          GAsyncReadyCallback  callback,
                                          gpointer             user_data)
{
  guint call_id;
297 298 299 300 301 302
  GSimpleAsyncResult *simple;

  simple = g_simple_async_result_new (G_OBJECT (authority),
                                      callback,
                                      user_data,
                                      polkit_authority_enumerate_actions_async);
303 304 305

  call_id = _polkit_authority_enumerate_actions (authority->real,
                                                 EGG_DBUS_CALL_FLAGS_NONE,
306
                                                 "", /* TODO: use current locale */
307
                                                 cancellable,
308 309
                                                 generic_async_cb,
                                                 simple);
310 311 312 313

  return call_id;
}

314 315 316 317 318 319 320 321 322 323 324 325 326
/**
 * polkit_authority_enumerate_actions:
 * @authority: A #PolkitAuthority.
 * @cancellable: A #GCancellable or %NULL.
 * @callback: A #GAsyncReadyCallback to call when the request is satisfied.
 * @user_data: The data to pass to @callback.
 *
 * Asynchronously retrieves all registered actions.
 *
 * When the operation is finished, @callback will be invoked. You can then
 * call polkit_authority_enumerate_actions_finish() to get the result of
 * the operation.
 **/
327 328 329 330 331 332
void
polkit_authority_enumerate_actions (PolkitAuthority     *authority,
                                    GCancellable        *cancellable,
                                    GAsyncReadyCallback  callback,
                                    gpointer             user_data)
{
333
  polkit_authority_enumerate_actions_async (authority, cancellable, callback, user_data);
334 335
}

336 337 338 339 340 341 342 343
/**
 * polkit_authority_enumerate_actions_finish:
 * @authority: A #PolkitAuthority.
 * @res: A #GAsyncResult obtained from the callback.
 * @error: Return location for error or %NULL.
 *
 * Finishes retrieving all registered actions.
 *
344
 * Returns: A list of #PolkitActionDescription objects or %NULL if @error is set. The returned list
345 346
 * should be freed with g_list_free() after each element have been freed with g_object_unref().
 **/
347
GList *
348 349 350
polkit_authority_enumerate_actions_finish (PolkitAuthority *authority,
                                           GAsyncResult    *res,
                                           GError         **error)
351 352 353 354
{
  EggDBusArraySeq *array_seq;
  GList *result;
  guint n;
355 356 357 358 359 360 361
  GSimpleAsyncResult *simple;
  GAsyncResult *real_res;

  simple = G_SIMPLE_ASYNC_RESULT (res);
  real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));

  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_enumerate_actions_async);
362 363 364

  result = NULL;

365 366
  if (!_polkit_authority_enumerate_actions_finish (authority->real,
                                                   &array_seq,
367
                                                   real_res,
368
                                                   error))
369 370 371 372 373 374 375 376 377 378 379 380 381
    goto out;

  for (n = 0; n < array_seq->size; n++)
    {
      _PolkitActionDescription *real_ad;

      real_ad = array_seq->data.v_ptr[n];

      result = g_list_prepend (result, polkit_action_description_new_for_real (real_ad));
    }

  result = g_list_reverse (result);

382 383 384
  g_object_unref (array_seq);

 out:
385
  g_object_unref (real_res);
386 387 388
  return result;
}

389

390 391 392 393 394 395 396 397 398 399 400
/**
 * polkit_authority_enumerate_actions_sync:
 * @authority: A #PolkitAuthority.
 * @cancellable: A #GCancellable or %NULL.
 * @error: Return location for error or %NULL.
 *
 * Synchronously retrieves all registered actions.
 *
 * Returns: A list of #PolkitActionDescription or %NULL if @error is set. The returned list
 * should be freed with g_list_free() after each element have been freed with g_object_unref().
 **/
401
GList *
402 403 404 405 406 407 408 409
polkit_authority_enumerate_actions_sync (PolkitAuthority *authority,
                                         GCancellable    *cancellable,
                                         GError         **error)
{
  guint call_id;
  GAsyncResult *res;
  GList *result;

410
  call_id = polkit_authority_enumerate_actions_async (authority, cancellable, generic_cb, &res);
411 412 413 414 415 416 417 418 419 420 421

  egg_dbus_connection_pending_call_block (authority->system_bus, call_id);

  result = polkit_authority_enumerate_actions_finish (authority, res, error);

  g_object_unref (res);

  return result;
}

/* ---------------------------------------------------------------------------------------------------- */
422

423
static guint
424 425 426
polkit_authority_check_authorization_async (PolkitAuthority               *authority,
                                            PolkitSubject                 *subject,
                                            const gchar                   *action_id,
427
                                            PolkitDetails                 *details,
428 429 430 431
                                            PolkitCheckAuthorizationFlags  flags,
                                            GCancellable                  *cancellable,
                                            GAsyncReadyCallback            callback,
                                            gpointer                       user_data)
432
{
433
  _PolkitSubject *real_subject;
434
  guint call_id;
435
  GSimpleAsyncResult *simple;
436
  gchar *cancellation_id;
437
  EggDBusHashMap *real_details;
438

439
  real_subject = polkit_subject_get_real (subject);
440

441 442 443
  simple = g_simple_async_result_new (G_OBJECT (authority),
                                      callback,
                                      user_data,
444
                                      polkit_authority_check_authorization_async);
445

446 447 448 449 450 451 452
  cancellation_id = NULL;
  if (cancellable != NULL)
    {
      cancellation_id = g_strdup_printf ("cancellation-id-%d", authority->cancellation_id_counter++);
      g_object_set_data_full (G_OBJECT (simple), "polkit-1-cancellation-id", cancellation_id, g_free);
    }

453 454 455 456
  real_details = egg_dbus_hash_map_new (G_TYPE_STRING, NULL,
                                        G_TYPE_STRING, NULL);
  if (details != NULL)
    {
457
      GHashTable *hash;
458 459 460 461
      GHashTableIter iter;
      const gchar *key;
      const gchar *value;

462 463 464 465 466 467 468
      hash = polkit_details_get_hash (details);
      if (hash != NULL)
        {
          g_hash_table_iter_init (&iter, hash);
          while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value))
            egg_dbus_hash_map_insert (real_details, key, value);
        }
469 470
    }

471
  call_id = _polkit_authority_check_authorization (authority->real,
472
                                                   EGG_DBUS_CALL_FLAGS_TIMEOUT_NONE,
473 474
                                                   real_subject,
                                                   action_id,
475
                                                   real_details,
476
                                                   flags,
477
                                                   cancellation_id,
478 479 480
                                                   cancellable,
                                                   generic_async_cb,
                                                   simple);
481

482
  g_object_unref (real_subject);
483 484 485 486

  return call_id;
}

487 488 489 490 491
/**
 * polkit_authority_check_authorization:
 * @authority: A #PolkitAuthority.
 * @subject: A #PolkitSubject.
 * @action_id: The action to check for.
492 493
 * @details: Details about the action or %NULL. Keys starting with <literal>polkit.</literal> are reserved
 * for internal use and cannot be used.
494 495 496 497 498 499 500 501
 * @flags: A set of #PolkitCheckAuthorizationFlags.
 * @cancellable: A #GCancellable or %NULL.
 * @callback: A #GAsyncReadyCallback to call when the request is satisfied.
 * @user_data: The data to pass to @callback.
 *
 * Asynchronously checks if @subject is authorized to perform the action represented
 * by @action_id.
 *
502 503 504 505 506
 * Note that #POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION
 * SHOULD be passed ONLY if the event that triggered the authorization
 * check is stemming from an user action, e.g. the user pressing a
 * button or attaching a device.
 *
507 508 509 510
 * When the operation is finished, @callback will be invoked. You can then
 * call polkit_authority_check_authorization_finish() to get the result of
 * the operation.
 **/
511
void
512 513 514
polkit_authority_check_authorization (PolkitAuthority               *authority,
                                      PolkitSubject                 *subject,
                                      const gchar                   *action_id,
515
                                      PolkitDetails                 *details,
516 517 518 519
                                      PolkitCheckAuthorizationFlags  flags,
                                      GCancellable                  *cancellable,
                                      GAsyncReadyCallback            callback,
                                      gpointer                       user_data)
520
{
521 522 523
  polkit_authority_check_authorization_async (authority,
                                              subject,
                                              action_id,
524
                                              details,
525 526 527 528
                                              flags,
                                              cancellable,
                                              callback,
                                              user_data);
529 530
}

531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
static void
authorization_check_cancelled_cb (GObject      *source_object,
                                  GAsyncResult *res,
                                  gpointer      user_data)
{
  GError *error;

  error = NULL;
  if (!_polkit_authority_cancel_check_authorization_finish (_POLKIT_AUTHORITY (source_object),
                                                            res,
                                                            &error))
    {
      g_warning ("Error cancelling authorization check: %s", error->message);
      g_error_free (error);
    }
}

548 549 550 551 552 553 554 555
/**
 * polkit_authority_check_authorization_finish:
 * @authority: A #PolkitAuthority.
 * @res: A #GAsyncResult obtained from the callback.
 * @error: Return location for error or %NULL.
 *
 * Finishes checking if a subject is authorized for an action.
 *
556
 * Returns: A #PolkitAuthorizationResult or %NULL if @error is set. Free with g_object_unref().
557
 **/
558
PolkitAuthorizationResult *
559 560 561
polkit_authority_check_authorization_finish (PolkitAuthority          *authority,
                                             GAsyncResult             *res,
                                             GError                  **error)
562
{
563 564
  PolkitAuthorizationResult *result;
  _PolkitAuthorizationResult *real_result;
565 566
  GSimpleAsyncResult *simple;
  GAsyncResult *real_res;
567
  GError *local_error;
568 569 570 571

  simple = G_SIMPLE_ASYNC_RESULT (res);
  real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));

572
  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_check_authorization_async);
573

574
  result = NULL;
David Zeuthen's avatar
David Zeuthen committed
575
  real_result = NULL;
576

577 578
  local_error = NULL;
  _polkit_authority_check_authorization_finish (authority->real,
579
                                                &real_result,
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
                                                real_res,
                                                &local_error);

  if (local_error != NULL)
    {
      if (local_error->domain == EGG_DBUS_ERROR && local_error->code == EGG_DBUS_ERROR_CANCELLED)
        {
          const gchar *cancellation_id;

          /* if the operation was cancelled locally, make sure to tell the daemon so the authentication
           * dialog etc. can be removed
           */
          cancellation_id = g_object_get_data (G_OBJECT (simple), "polkit-1-cancellation-id");
          if (cancellation_id != NULL)
            {
              _polkit_authority_cancel_check_authorization (authority->real,
                                                            EGG_DBUS_CALL_FLAGS_NONE,
                                                            cancellation_id,
                                                            NULL,
                                                            authorization_check_cancelled_cb,
                                                            NULL);
            }

          g_set_error (error,
                       POLKIT_ERROR,
                       POLKIT_ERROR_CANCELLED,
                       "The operation was cancelled");
          g_error_free (local_error);
        }
      else
        {
          g_propagate_error (error, local_error);
        }
    }
614
  g_object_unref (real_res);
615 616 617 618 619 620 621

  if (real_result != NULL)
    {
      result = polkit_authorization_result_new_for_real (real_result);
      g_object_unref (real_result);
    }

622 623 624
  return result;
}

625
/**
626
 * polkit_authority_check_authorization_sync:
627 628 629
 * @authority: A #PolkitAuthority.
 * @subject: A #PolkitSubject.
 * @action_id: The action to check for.
630 631
 * @details: Details about the action or %NULL. Keys starting with <literal>polkit.</literal> are reserved
 * for internal use and cannot be used.
632 633
 * @flags: A set of #PolkitCheckAuthorizationFlags.
 * @cancellable: A #GCancellable or %NULL.
634
 * @error: Return location for error or %NULL.
635 636 637
 *
 * Checks if @subject is authorized to perform the action represented by @action_id.
 *
638 639 640 641 642
 * Note that #POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION
 * SHOULD be passed ONLY if the event that triggered the authorization
 * check is stemming from an user action, e.g. the user pressing a
 * button or attaching a device.
 *
643
 * Returns: A #PolkitAuthorizationResult or %NULL if @error is set. Free with g_object_unref().
644
 */
645
PolkitAuthorizationResult *
646 647 648
polkit_authority_check_authorization_sync (PolkitAuthority               *authority,
                                           PolkitSubject                 *subject,
                                           const gchar                   *action_id,
649
                                           PolkitDetails                 *details,
650 651 652
                                           PolkitCheckAuthorizationFlags  flags,
                                           GCancellable                  *cancellable,
                                           GError                       **error)
653 654 655
{
  guint call_id;
  GAsyncResult *res;
656
  PolkitAuthorizationResult *result;
657

658 659 660
  call_id = polkit_authority_check_authorization_async (authority,
                                                        subject,
                                                        action_id,
661
                                                        details,
662 663 664 665
                                                        flags,
                                                        cancellable,
                                                        generic_cb,
                                                        &res);
666 667 668

  egg_dbus_connection_pending_call_block (authority->system_bus, call_id);

669
  result = polkit_authority_check_authorization_finish (authority, res, error);
670 671 672 673 674 675 676

  g_object_unref (res);

  return result;
}

/* ---------------------------------------------------------------------------------------------------- */
677

678 679
static guint
polkit_authority_register_authentication_agent_async (PolkitAuthority      *authority,
680
                                                      PolkitSubject        *subject,
681
                                                      const gchar          *locale,
682 683 684 685 686 687 688
                                                      const gchar          *object_path,
                                                      GCancellable         *cancellable,
                                                      GAsyncReadyCallback   callback,
                                                      gpointer              user_data)
{
  guint call_id;
  GSimpleAsyncResult *simple;
689
  _PolkitSubject *real_subject;
690 691 692 693 694 695

  simple = g_simple_async_result_new (G_OBJECT (authority),
                                      callback,
                                      user_data,
                                      polkit_authority_register_authentication_agent_async);

696 697
  real_subject = polkit_subject_get_real (subject);

698 699
  call_id = _polkit_authority_register_authentication_agent (authority->real,
                                                             EGG_DBUS_CALL_FLAGS_NONE,
700
                                                             real_subject,
701
                                                             locale,
702 703 704 705
                                                             object_path,
                                                             cancellable,
                                                             generic_async_cb,
                                                             simple);
706
  g_object_unref (real_subject);
707 708 709 710

  return call_id;
}

711 712 713
/**
 * polkit_authority_register_authentication_agent:
 * @authority: A #PolkitAuthority.
714
 * @subject: The subject the authentication agent is for, typically a #PolkitUnixSession object.
715
 * @locale: The locale of the authentication agent.
716 717 718 719 720 721 722 723 724 725 726
 * @object_path: The object path for the authentication agent.
 * @cancellable: A #GCancellable or %NULL.
 * @callback: A #GAsyncReadyCallback to call when the request is satisfied.
 * @user_data: The data to pass to @callback.
 *
 * Asynchronously registers an authentication agent.
 *
 * When the operation is finished, @callback will be invoked. You can then
 * call polkit_authority_register_authentication_agent_finish() to get the result of
 * the operation.
 **/
727 728
void
polkit_authority_register_authentication_agent (PolkitAuthority      *authority,
729
                                                PolkitSubject        *subject,
730
                                                const gchar          *locale,
731 732 733 734 735 736
                                                const gchar          *object_path,
                                                GCancellable         *cancellable,
                                                GAsyncReadyCallback   callback,
                                                gpointer              user_data)
{
  polkit_authority_register_authentication_agent_async (authority,
737
                                                        subject,
738
                                                        locale,
739 740 741 742 743 744
                                                        object_path,
                                                        cancellable,
                                                        callback,
                                                        user_data);
}

745 746 747 748 749 750 751 752 753 754
/**
 * polkit_authority_register_authentication_agent_finish:
 * @authority: A #PolkitAuthority.
 * @res: A #GAsyncResult obtained from the callback.
 * @error: Return location for error or %NULL.
 *
 * Finishes registering an authentication agent.
 *
 * Returns: %TRUE if the authentication agent was successfully registered, %FALSE if @error is set.
 **/
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781
gboolean
polkit_authority_register_authentication_agent_finish (PolkitAuthority *authority,
                                                       GAsyncResult    *res,
                                                       GError         **error)
{
  GSimpleAsyncResult *simple;
  GAsyncResult *real_res;
  gboolean ret;

  simple = G_SIMPLE_ASYNC_RESULT (res);
  real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));

  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_register_authentication_agent_async);

  ret = _polkit_authority_register_authentication_agent_finish (authority->real,
                                                                real_res,
                                                                error);

  if (!ret)
    goto out;

 out:
  g_object_unref (real_res);
  return ret;
}


782 783 784
/**
 * polkit_authority_register_authentication_agent_sync:
 * @authority: A #PolkitAuthority.
785
 * @subject: The subject the authentication agent is for, typically a #PolkitUnixSession object.
786
 * @locale: The locale of the authentication agent.
787 788 789 790 791 792 793 794
 * @object_path: The object path for the authentication agent.
 * @cancellable: A #GCancellable or %NULL.
 * @error: Return location for error or %NULL.
 *
 * Registers an authentication agent.
 *
 * Returns: %TRUE if the authentication agent was successfully registered, %FALSE if @error is set.
 **/
795 796
gboolean
polkit_authority_register_authentication_agent_sync (PolkitAuthority     *authority,
797
                                                     PolkitSubject       *subject,
798
                                                     const gchar         *locale,
799 800 801 802 803 804 805 806 807
                                                     const gchar         *object_path,
                                                     GCancellable        *cancellable,
                                                     GError             **error)
{
  guint call_id;
  GAsyncResult *res;
  gboolean ret;

  call_id = polkit_authority_register_authentication_agent_async (authority,
808
                                                                  subject,
809
                                                                  locale,
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827
                                                                  object_path,
                                                                  cancellable,
                                                                  generic_cb,
                                                                  &res);

  egg_dbus_connection_pending_call_block (authority->system_bus, call_id);

  ret = polkit_authority_register_authentication_agent_finish (authority, res, error);

  g_object_unref (res);

  return ret;
}

/* ---------------------------------------------------------------------------------------------------- */

static guint
polkit_authority_unregister_authentication_agent_async (PolkitAuthority      *authority,
828
                                                        PolkitSubject        *subject,
829 830 831 832 833 834 835
                                                        const gchar          *object_path,
                                                        GCancellable         *cancellable,
                                                        GAsyncReadyCallback   callback,
                                                        gpointer              user_data)
{
  guint call_id;
  GSimpleAsyncResult *simple;
836
  _PolkitSubject *real_subject;
837 838 839 840 841 842

  simple = g_simple_async_result_new (G_OBJECT (authority),
                                      callback,
                                      user_data,
                                      polkit_authority_unregister_authentication_agent_async);

843 844
  real_subject = polkit_subject_get_real (subject);

845
  call_id = _polkit_authority_unregister_authentication_agent (authority->real,
846
                                                               EGG_DBUS_CALL_FLAGS_NONE,
847
                                                               real_subject,
848 849 850 851
                                                               object_path,
                                                               cancellable,
                                                               generic_async_cb,
                                                               simple);
852

853 854
  g_object_unref (real_subject);

855 856 857
  return call_id;
}

858 859 860
/**
 * polkit_authority_unregister_authentication_agent:
 * @authority: A #PolkitAuthority.
861
 * @subject: The #PolkitSubject passed when registering the agent.
862 863 864 865 866 867 868 869 870 871 872
 * @object_path: The object path that the authentication agent is registered at.
 * @cancellable: A #GCancellable or %NULL.
 * @callback: A #GAsyncReadyCallback to call when the request is satisfied.
 * @user_data: The data to pass to @callback.
 *
 * Asynchronously unregisters an authentication agent.
 *
 * When the operation is finished, @callback will be invoked. You can then
 * call polkit_authority_unregister_authentication_agent_finish() to get the result of
 * the operation.
 **/
873 874
void
polkit_authority_unregister_authentication_agent (PolkitAuthority      *authority,
875
                                                  PolkitSubject        *subject,
876 877 878 879 880 881
                                                  const gchar          *object_path,
                                                  GCancellable         *cancellable,
                                                  GAsyncReadyCallback   callback,
                                                  gpointer              user_data)
{
  polkit_authority_unregister_authentication_agent_async (authority,
882
                                                          subject,
883 884 885 886
                                                          object_path,
                                                          cancellable,
                                                          callback,
                                                          user_data);
887 888
}

889 890 891 892 893 894 895 896 897 898
/**
 * polkit_authority_unregister_authentication_agent_finish:
 * @authority: A #PolkitAuthority.
 * @res: A #GAsyncResult obtained from the callback.
 * @error: Return location for error or %NULL.
 *
 * Finishes unregistering an authentication agent.
 *
 * Returns: %TRUE if the authentication agent was successfully unregistered, %FALSE if @error is set.
 **/
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
gboolean
polkit_authority_unregister_authentication_agent_finish (PolkitAuthority *authority,
                                                         GAsyncResult    *res,
                                                         GError         **error)
{
  GSimpleAsyncResult *simple;
  GAsyncResult *real_res;
  gboolean ret;

  simple = G_SIMPLE_ASYNC_RESULT (res);
  real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));

  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_unregister_authentication_agent_async);

  ret = _polkit_authority_unregister_authentication_agent_finish (authority->real,
                                                                real_res,
                                                                error);

  if (!ret)
    goto out;

 out:
  g_object_unref (real_res);
  return ret;
}

925 926 927
/**
 * polkit_authority_unregister_authentication_agent_sync:
 * @authority: A #PolkitAuthority.
928
 * @subject: The #PolkitSubject passed when registering the agent.
929 930 931 932 933 934 935 936
 * @object_path: The object path that the authentication agent is registered at.
 * @cancellable: A #GCancellable or %NULL.
 * @error: Return location for error or %NULL.
 *
 * Unregisters an authentication agent.
 *
 * Returns: %TRUE if the authentication agent was successfully unregistered, %FALSE if @error is set.
 **/
937 938
gboolean
polkit_authority_unregister_authentication_agent_sync (PolkitAuthority     *authority,
939
                                                       PolkitSubject       *subject,
940 941 942 943 944 945 946 947 948
                                                       const gchar         *object_path,
                                                       GCancellable        *cancellable,
                                                       GError             **error)
{
  guint call_id;
  GAsyncResult *res;
  gboolean ret;

  call_id = polkit_authority_unregister_authentication_agent_async (authority,
949
                                                                    subject,
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
                                                                    object_path,
                                                                    cancellable,
                                                                    generic_cb,
                                                                    &res);

  egg_dbus_connection_pending_call_block (authority->system_bus, call_id);

  ret = polkit_authority_unregister_authentication_agent_finish (authority, res, error);

  g_object_unref (res);

  return ret;
}

/* ---------------------------------------------------------------------------------------------------- */
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997

static guint
polkit_authority_authentication_agent_response_async (PolkitAuthority      *authority,
                                                      const gchar          *cookie,
                                                      PolkitIdentity       *identity,
                                                      GCancellable         *cancellable,
                                                      GAsyncReadyCallback   callback,
                                                      gpointer              user_data)
{
  guint call_id;
  GSimpleAsyncResult *simple;
  _PolkitIdentity *real_identity;

  simple = g_simple_async_result_new (G_OBJECT (authority),
                                      callback,
                                      user_data,
                                      polkit_authority_authentication_agent_response_async);

  real_identity = polkit_identity_get_real (identity);

  call_id = _polkit_authority_authentication_agent_response (authority->real,
                                                             EGG_DBUS_CALL_FLAGS_NONE,
                                                             cookie,
                                                             real_identity,
                                                             cancellable,
                                                             generic_async_cb,
                                                             simple);

  g_object_unref (real_identity);

  return call_id;
}

998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
/**
 * polkit_authority_authentication_agent_response:
 * @authority: A #PolkitAuthority.
 * @cookie: The cookie passed to the authentication agent from the authority.
 * @identity: The identity that was authenticated.
 * @cancellable: A #GCancellable or %NULL.
 * @callback: A #GAsyncReadyCallback to call when the request is satisfied.
 * @user_data: The data to pass to @callback.
 *
 * Asynchronously provide response that @identity successfully authenticated
 * for the authentication request identified by @cookie.
 *
 * This function is only used by the privileged bits of an authentication agent.
 * It will fail if the caller is not sufficiently privileged (typically uid 0).
 *
 * When the operation is finished, @callback will be invoked. You can then
 * call polkit_authority_authentication_agent_response_finish() to get the result of
 * the operation.
 **/
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
void
polkit_authority_authentication_agent_response (PolkitAuthority      *authority,
                                                const gchar          *cookie,
                                                PolkitIdentity       *identity,
                                                GCancellable         *cancellable,
                                                GAsyncReadyCallback   callback,
                                                gpointer              user_data)
{
  polkit_authority_authentication_agent_response_async (authority,
                                                        cookie,
                                                        identity,
                                                        cancellable,
                                                        callback,
                                                        user_data);
}

1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
/**
 * polkit_authority_authentication_agent_response_finish:
 * @authority: A #PolkitAuthority.
 * @res: A #GAsyncResult obtained from the callback.
 * @error: Return location for error or %NULL.
 *
 * Finishes providing response from an authentication agent.
 *
 * Returns: %TRUE if @authority acknowledged the call, %FALSE if @error is set.
 **/
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
gboolean
polkit_authority_authentication_agent_response_finish (PolkitAuthority *authority,
                                                       GAsyncResult    *res,
                                                       GError         **error)
{
  GSimpleAsyncResult *simple;
  GAsyncResult *real_res;
  gboolean ret;

  simple = G_SIMPLE_ASYNC_RESULT (res);
  real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));

  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_authentication_agent_response_async);

  ret = _polkit_authority_authentication_agent_response_finish (authority->real,
                                                                real_res,
                                                                error);

  if (!ret)
    goto out;

 out:
  g_object_unref (real_res);
  return ret;
}


1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
/**
 * polkit_authority_authentication_agent_response_sync:
 * @authority: A #PolkitAuthority.
 * @cookie: The cookie passed to the authentication agent from the authority.
 * @identity: The identity that was authenticated.
 * @cancellable: A #GCancellable or %NULL.
 * @error: Return location for error or %NULL.
 *
 * Provide response that @identity successfully authenticated for the
 * authentication request identified by @cookie. See polkit_authority_authentication_agent_response()
 * for limitations on who is allowed is to call this method.
 *
 * Returns: %TRUE if @authority acknowledged the call, %FALSE if @error is set.
 **/
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
gboolean
polkit_authority_authentication_agent_response_sync (PolkitAuthority     *authority,
                                                     const gchar         *cookie,
                                                     PolkitIdentity      *identity,
                                                     GCancellable        *cancellable,
                                                     GError             **error)
{
  guint call_id;
  GAsyncResult *res;
  gboolean ret;

  call_id = polkit_authority_authentication_agent_response_async (authority,
                                                                  cookie,
                                                                  identity,
                                                                  cancellable,
                                                                  generic_cb,
                                                                  &res);

  egg_dbus_connection_pending_call_block (authority->system_bus, call_id);

  ret = polkit_authority_authentication_agent_response_finish (authority, res, error);

  g_object_unref (res);

  return ret;
}

/* ---------------------------------------------------------------------------------------------------- */
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142

static guint
polkit_authority_enumerate_temporary_authorizations_async (PolkitAuthority     *authority,
                                                           PolkitSubject       *subject,
                                                           GCancellable        *cancellable,
                                                           GAsyncReadyCallback  callback,
                                                           gpointer             user_data)
{
  guint call_id;
  GSimpleAsyncResult *simple;
  _PolkitSubject *real_subject;

  simple = g_simple_async_result_new (G_OBJECT (authority),
                                      callback,
                                      user_data,
                                      polkit_authority_enumerate_temporary_authorizations_async);

  real_subject = polkit_subject_get_real (subject);

  call_id = _polkit_authority_enumerate_temporary_authorizations (authority->real,
                                                                  EGG_DBUS_CALL_FLAGS_NONE,
                                                                  real_subject,
                                                                  cancellable,
                                                                  generic_async_cb,
                                                                  simple);

  g_object_unref (real_subject);

  return call_id;
}

1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
/**
 * polkit_authority_enumerate_temporary_authorizations:
 * @authority: A #PolkitAuthority.
 * @subject: A #PolkitSubject, typically a #PolkitUnixSession.
 * @cancellable: A #GCancellable or %NULL.
 * @callback: A #GAsyncReadyCallback to call when the request is satisfied.
 * @user_data: The data to pass to @callback.
 *
 * Asynchronously gets all temporary authorizations for @subject.
 *
 * When the operation is finished, @callback will be invoked. You can then
 * call polkit_authority_enumerate_temporary_authorizations_finish() to get the result of
 * the operation.
 **/
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
void
polkit_authority_enumerate_temporary_authorizations (PolkitAuthority     *authority,
                                                     PolkitSubject       *subject,
                                                     GCancellable        *cancellable,
                                                     GAsyncReadyCallback  callback,
                                                     gpointer             user_data)
{
  polkit_authority_enumerate_temporary_authorizations_async (authority, subject, cancellable, callback, user_data);
}

1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177
/**
 * polkit_authority_enumerate_temporary_authorizations_finish:
 * @authority: A #PolkitAuthority.
 * @res: A #GAsyncResult obtained from the callback.
 * @error: Return location for error or %NULL.
 *
 * Finishes retrieving all registered actions.
 *
 * Returns: A list of #PolkitTemporaryAuthorization objects or %NULL if @error is set. The returned list
 * should be freed with g_list_free() after each element have been freed with g_object_unref().
 **/
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219
GList *
polkit_authority_enumerate_temporary_authorizations_finish (PolkitAuthority *authority,
                                                            GAsyncResult    *res,
                                                            GError         **error)
{
  EggDBusArraySeq *array_seq;
  GList *result;
  guint n;
  GSimpleAsyncResult *simple;
  GAsyncResult *real_res;

  simple = G_SIMPLE_ASYNC_RESULT (res);
  real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));

  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_enumerate_temporary_authorizations_async);

  result = NULL;

  if (!_polkit_authority_enumerate_temporary_authorizations_finish (authority->real,
                                                                    &array_seq,
                                                                    real_res,
                                                                    error))
    goto out;

  for (n = 0; n < array_seq->size; n++)
    {
      _PolkitTemporaryAuthorization *real_ta;

      real_ta = array_seq->data.v_ptr[n];

      result = g_list_prepend (result, polkit_temporary_authorization_new_for_real (real_ta));
    }

  result = g_list_reverse (result);

  g_object_unref (array_seq);

 out:
  g_object_unref (real_res);
  return result;
}

1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
/**
 * polkit_authority_enumerate_temporary_authorizations_sync:
 * @authority: A #PolkitAuthority.
 * @subject: A #PolkitSubject, typically a #PolkitUnixSession.
 * @cancellable: A #GCancellable or %NULL.
 * @error: Return location for error or %NULL.
 *
 * Synchronousky gets all temporary authorizations for @subject.
 *
 * Returns: A list of #PolkitTemporaryAuthorization objects or %NULL if @error is set. The returned list
 * should be freed with g_list_free() after each element have been freed with g_object_unref().
 **/
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284
GList *
polkit_authority_enumerate_temporary_authorizations_sync (PolkitAuthority     *authority,
                                                          PolkitSubject       *subject,
                                                          GCancellable        *cancellable,
                                                          GError             **error)
{
  guint call_id;
  GAsyncResult *res;
  GList *result;

  call_id = polkit_authority_enumerate_temporary_authorizations_async (authority, subject, cancellable, generic_cb, &res);

  egg_dbus_connection_pending_call_block (authority->system_bus, call_id);

  result = polkit_authority_enumerate_temporary_authorizations_finish (authority, res, error);

  g_object_unref (res);

  return result;
}

/* ---------------------------------------------------------------------------------------------------- */

static guint
polkit_authority_revoke_temporary_authorizations_async (PolkitAuthority     *authority,
                                                        PolkitSubject       *subject,
                                                        GCancellable        *cancellable,
                                                        GAsyncReadyCallback  callback,
                                                        gpointer             user_data)
{
  guint call_id;
  GSimpleAsyncResult *simple;
  _PolkitSubject *real_subject;

  simple = g_simple_async_result_new (G_OBJECT (authority),
                                      callback,
                                      user_data,
                                      polkit_authority_revoke_temporary_authorizations_async);

  real_subject = polkit_subject_get_real (subject);

  call_id = _polkit_authority_revoke_temporary_authorizations (authority->real,
                                                               EGG_DBUS_CALL_FLAGS_NONE,
                                                               real_subject,
                                                               cancellable,
                                                               generic_async_cb,
                                                               simple);

  g_object_unref (real_subject);

  return call_id;
}

1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298
/**
 * polkit_authority_revoke_temporary_authorizations:
 * @authority: A #PolkitAuthority.
 * @subject: The subject to revoke authorizations from, typically a #PolkitUnixSession.
 * @cancellable: A #GCancellable or %NULL.
 * @callback: A #GAsyncReadyCallback to call when the request is satisfied.
 * @user_data: The data to pass to @callback.
 *
 * Asynchronously revokes all temporary authorizations for @subject.
 *
 * When the operation is finished, @callback will be invoked. You can then
 * call polkit_authority_revoke_temporary_authorizations_finish() to get the result of
 * the operation.
 **/
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308
void
polkit_authority_revoke_temporary_authorizations (PolkitAuthority     *authority,
                                                  PolkitSubject       *subject,
                                                  GCancellable        *cancellable,
                                                  GAsyncReadyCallback  callback,
                                                  gpointer             user_data)
{
  polkit_authority_revoke_temporary_authorizations_async (authority, subject, cancellable, callback, user_data);
}

1309 1310 1311 1312 1313 1314
/**
 * polkit_authority_revoke_temporary_authorizations_finish:
 * @authority: A #PolkitAuthority.
 * @res: A #GAsyncResult obtained from the callback.
 * @error: Return location for error or %NULL.
 *
1315
 * Finishes revoking temporary authorizations.
1316 1317 1318
 *
 * Returns: %TRUE if all the temporary authorizations was revoked, %FALSE if error is set.
 **/
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344
gboolean
polkit_authority_revoke_temporary_authorizations_finish (PolkitAuthority *authority,
                                                         GAsyncResult    *res,
                                                         GError         **error)
{
  GSimpleAsyncResult *simple;
  GAsyncResult *real_res;
  gboolean ret;

  simple = G_SIMPLE_ASYNC_RESULT (res);
  real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));

  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_revoke_temporary_authorizations_async);

  ret = _polkit_authority_revoke_temporary_authorizations_finish (authority->real,
                                                                  real_res,
                                                                  error);

  if (!ret)
    goto out;

 out:
  g_object_unref (real_res);
  return ret;
}

1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355
/**
 * polkit_authority_revoke_temporary_authorizations_sync:
 * @authority: A #PolkitAuthority.
 * @subject: The subject to revoke authorizations from, typically a #PolkitUnixSession.
 * @cancellable: A #GCancellable or %NULL.
 * @error: Return location for error or %NULL.
 *
 * Synchronously revokes all temporary authorization from @subject.
 *
 * Returns: %TRUE if the temporary authorization was revoked, %FALSE if error is set.
 **/
1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377
gboolean
polkit_authority_revoke_temporary_authorizations_sync (PolkitAuthority     *authority,
                                                       PolkitSubject       *subject,
                                                       GCancellable        *cancellable,
                                                       GError             **error)
{
  guint call_id;
  GAsyncResult *res;
  gboolean result;

  call_id = polkit_authority_revoke_temporary_authorizations_async (authority, subject, cancellable, generic_cb, &res);

  egg_dbus_connection_pending_call_block (authority->system_bus, call_id);

  result = polkit_authority_revoke_temporary_authorizations_finish (authority, res, error);

  g_object_unref (res);

  return result;
}

/* ---------------------------------------------------------------------------------------------------- */
1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433

static guint
polkit_authority_revoke_temporary_authorization_by_id_async (PolkitAuthority     *authority,
                                                             const gchar         *id,
                                                             GCancellable        *cancellable,
                                                             GAsyncReadyCallback  callback,
                                                             gpointer             user_data)
{
  guint call_id;
  GSimpleAsyncResult *simple;

  simple = g_simple_async_result_new (G_OBJECT (authority),
                                      callback,
                                      user_data,
                                      polkit_authority_revoke_temporary_authorizations_async);

  call_id = _polkit_authority_revoke_temporary_authorization_by_id (authority->real,
                                                                    EGG_DBUS_CALL_FLAGS_NONE,
                                                                    id,
                                                                    cancellable,
                                                                    generic_async_cb,
                                                                    simple);

  return call_id;
}

/**
 * polkit_authority_revoke_temporary_authorization_by_id:
 * @authority: A #PolkitAuthority.
 * @id: The opaque identifier for the temporary authorization.
 * @cancellable: A #GCancellable or %NULL.
 * @callback: A #GAsyncReadyCallback to call when the request is satisfied.
 * @user_data: The data to pass to @callback.
 *
 * Asynchronously revoke a temporary authorization.
 *
 * When the operation is finished, @callback will be invoked. You can then
 * call polkit_authority_revoke_temporary_authorization_by_id_finish() to get the result of
 * the operation.
 */
void
polkit_authority_revoke_temporary_authorization_by_id (PolkitAuthority     *authority,
                                                       const gchar         *id,
                                                       GCancellable        *cancellable,
                                                       GAsyncReadyCallback  callback,
                                                       gpointer             user_data)
{
  polkit_authority_revoke_temporary_authorization_by_id_async (authority, id, cancellable, callback, user_data);
}

/**
 * polkit_authority_revoke_temporary_authorization_by_id_finish:
 * @authority: A #PolkitAuthority.
 * @res: A #GAsyncResult obtained from the callback.
 * @error: Return location for error or %NULL.
 *
1434
 * Finishes revoking a temporary authorization by id.
1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496
 *
 * Returns: %TRUE if the temporary authorization was revoked, %FALSE if error is set.
 **/
gboolean
polkit_authority_revoke_temporary_authorization_by_id_finish (PolkitAuthority *authority,
                                                              GAsyncResult    *res,
                                                              GError         **error)
{
  GSimpleAsyncResult *simple;
  GAsyncResult *real_res;
  gboolean ret;

  simple = G_SIMPLE_ASYNC_RESULT (res);
  real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));

  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_revoke_temporary_authorizations_async);

  ret = _polkit_authority_revoke_temporary_authorization_by_id_finish (authority->real,
                                                                       real_res,
                                                                       error);

  if (!ret)
    goto out;

 out:
  g_object_unref (real_res);
  return ret;
}

/**
 * polkit_authority_revoke_temporary_authorization_by_id_sync:
 * @authority: A #PolkitAuthority.
 * @id: The opaque identifier for the temporary authorization.
 * @cancellable: A #GCancellable or %NULL.
 * @error: Return location for error or %NULL.
 *
 * Synchronously revokes a temporary authorization.
 *
 * Returns: %TRUE if the temporary authorization was revoked, %FALSE if error is set.
 **/
gboolean
polkit_authority_revoke_temporary_authorization_by_id_sync (PolkitAuthority     *authority,
                                                            const gchar         *id,
                                                            GCancellable        *cancellable,
                                                            GError             **error)
{
  guint call_id;
  GAsyncResult *res;
  gboolean result;

  call_id = polkit_authority_revoke_temporary_authorization_by_id_async (authority, id, cancellable, generic_cb, &res);

  egg_dbus_connection_pending_call_block (authority->system_bus, call_id);

  result = polkit_authority_revoke_temporary_authorization_by_id_finish (authority, res, error);

  g_object_unref (res);

  return result;
}

/* ---------------------------------------------------------------------------------------------------- */
1497

1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552
static guint
polkit_authority_add_lockdown_for_action_async (PolkitAuthority     *authority,
                                                const gchar         *action_id,
                                                GCancellable        *cancellable,
                                                GAsyncReadyCallback  callback,
                                                gpointer             user_data)
{
  guint call_id;
  GSimpleAsyncResult *simple;

  simple = g_simple_async_result_new (G_OBJECT (authority),
                                      callback,
                                      user_data,
                                      polkit_authority_add_lockdown_for_action_async);

  call_id = _polkit_authority_add_lockdown_for_action (authority->real,
                                                       EGG_DBUS_CALL_FLAGS_NONE,
                                                       action_id,
                                                       cancellable,
                                                       generic_async_cb,
                                                       simple);

  return call_id;
}

/**
 * polkit_authority_add_lockdown_for_action:
 * @authority: A #PolkitAuthority.
 * @action_id: The identifier for the action.
 * @cancellable: A #GCancellable or %NULL.
 * @callback: A #GAsyncReadyCallback to call when the request is satisfied.
 * @user_data: The data to pass to @callback.
 *
 * Locks down the action identified by @action_id.
 *
 * When the operation is finished, @callback will be invoked. You can then
 * call polkit_authority_add_lockdown_for_action_finish() to get the result of
 * the operation.
 */
void
polkit_authority_add_lockdown_for_action (PolkitAuthority     *authority,
                                          const gchar         *action_id,
                                          GCancellable        *cancellable,
                                          GAsyncReadyCallback  callback,
                                          gpointer             user_data)
{
  polkit_authority_add_lockdown_for_action_async (authority, action_id, cancellable, callback, user_data);
}

/**
 * polkit_authority_add_lockdown_for_action_finish:
 * @authority: A #PolkitAuthority.
 * @res: A #GAsyncResult obtained from the callback.
 * @error: Return location for error or %NULL.
 *
1553
 * Finishes locking down an action.
1554 1555 1556 1557 1558 1559 1560 1561 1562