| 1 |
/* |
| 2 |
* Copyright (C) 2008 Red Hat, Inc. |
| 3 |
* |
| 4 |
* This library is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU Lesser General Public |
| 6 |
* License as published by the Free Software Foundation; either |
| 7 |
* version 2 of the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This library is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
* Lesser General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU Lesser General |
| 15 |
* Public License along with this library; if not, write to the |
| 16 |
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
| 17 |
* Boston, MA 02111-1307, USA. |
| 18 |
* |
| 19 |
* Author: David Zeuthen <[email protected]> |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "polkitauthorizationresult.h" |
| 23 |
#include "polkitcheckauthorizationflags.h" |
| 24 |
#include "polkitauthority.h" |
| 25 |
#include "polkiterror.h" |
| 26 |
#include "polkitenumtypes.h" |
| 27 |
#include "polkitsubject.h" |
| 28 |
#include "polkitidentity.h" |
| 29 |
#include "polkitdetails.h" |
| 30 |
|
| 31 |
#include "polkitprivate.h" |
| 32 |
|
| 33 |
/** |
| 34 |
* SECTION:polkitauthority |
| 35 |
* @title: PolkitAuthority |
| 36 |
* @short_description: Authority |
| 37 |
* @stability: Stable |
| 38 |
* |
| 39 |
* #PolkitAuthority is used for checking whether a given subject is |
| 40 |
* authorized to perform a given action. Typically privileged system |
| 41 |
* daemons or suid helpers will use this when handling requests from |
| 42 |
* untrusted clients. |
| 43 |
* |
| 44 |
* User sessions can register an authentication agent with the |
| 45 |
* authority. This is used for requests from untrusted clients where |
| 46 |
* system policy requires that the user needs to acknowledge (through |
| 47 |
* proving he is the user or the administrator) a given action. See |
| 48 |
* #PolkitAgentListener and #PolkitAgentSession for details. |
| 49 |
*/ |
| 50 |
|
| 51 |
/** |
| 52 |
* PolkitAuthority: |
| 53 |
* |
| 54 |
* The #PolkitAuthority struct should not be accessed directly. |
| 55 |
*/ |
| 56 |
struct _PolkitAuthority |
| 57 |
{ |
| 58 |
/*< private >*/ |
| 59 |
GObject parent_instance; |
| 60 |
|
| 61 |
gchar *name; |
| 62 |
gchar *version; |
| 63 |
|
| 64 |
GDBusProxy *proxy; |
| 65 |
guint cancellation_id_counter; |
| 66 |
|
| 67 |
gboolean initialized; |
| 68 |
GError *initialization_error; |
| 69 |
}; |
| 70 |
|
| 71 |
struct _PolkitAuthorityClass |
| 72 |
{ |
| 73 |
GObjectClass parent_class; |
| 74 |
|
| 75 |
}; |
| 76 |
|
| 77 |
G_LOCK_DEFINE_STATIC (the_lock); |
| 78 |
static PolkitAuthority *the_authority = NULL; |
| 79 |
|
| 80 |
enum |
| 81 |
{ |
| 82 |
CHANGED_SIGNAL, |
| 83 |
SESSIONS_CHANGED_SIGNAL, |
| 84 |
LAST_SIGNAL, |
| 85 |
}; |
| 86 |
|
| 87 |
enum |
| 88 |
{ |
| 89 |
PROP_0, |
| 90 |
PROP_OWNER, |
| 91 |
PROP_BACKEND_NAME, |
| 92 |
PROP_BACKEND_VERSION, |
| 93 |
PROP_BACKEND_FEATURES |
| 94 |
}; |
| 95 |
|
| 96 |
static guint signals[LAST_SIGNAL] = {0}; |
| 97 |
|
| 98 |
static void initable_iface_init (GInitableIface *initable_iface); |
| 99 |
static void async_initable_iface_init (GAsyncInitableIface *async_initable_iface); |
| 100 |
|
| 101 |
G_DEFINE_TYPE_WITH_CODE (PolkitAuthority, polkit_authority, G_TYPE_OBJECT, |
| 102 |
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init) |
| 103 |
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init)) |
| 104 |
|
| 105 |
static void |
| 106 |
on_proxy_signal (GDBusProxy *proxy, |
| 107 |
const gchar *sender_name, |
| 108 |
const gchar *signal_name, |
| 109 |
GVariant *parameters, |
| 110 |
gpointer user_data) |
| 111 |
{ |
| 112 |
PolkitAuthority *authority = POLKIT_AUTHORITY (user_data); |
| 113 |
guint16 msg_mask; |
| 114 |
|
| 115 |
if (g_strcmp0 (signal_name, "Changed") == 0) |
| 116 |
{ |
| 117 |
if ((parameters != NULL) && g_variant_check_format_string(parameters, "(q)", FALSE)) |
| 118 |
{ |
| 119 |
g_variant_get(parameters, "(q)", &msg_mask); |
| 120 |
if (msg_mask >= LAST_SIGNAL) |
| 121 |
{ |
| 122 |
msg_mask = CHANGED_SIGNAL; /* If signal not valid, we send generic "changed". */ |
| 123 |
} |
| 124 |
g_signal_emit (authority, signals[msg_mask], 0); |
| 125 |
} |
| 126 |
else |
| 127 |
{ |
| 128 |
g_signal_emit_by_name (authority, "changed"); |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
static void |
| 134 |
on_notify_g_name_owner (GObject *object, |
| 135 |
GParamSpec *ppsec, |
| 136 |
gpointer user_data) |
| 137 |
{ |
| 138 |
PolkitAuthority *authority = POLKIT_AUTHORITY (user_data); |
| 139 |
g_object_notify (G_OBJECT (authority), "owner"); |
| 140 |
} |
| 141 |
|
| 142 |
static void |
| 143 |
polkit_authority_init (PolkitAuthority *authority) |
| 144 |
{ |
| 145 |
} |
| 146 |
|
| 147 |
static void |
| 148 |
polkit_authority_dispose (GObject *object) |
| 149 |
{ |
| 150 |
PolkitAuthority *authority = POLKIT_AUTHORITY (object); |
| 151 |
|
| 152 |
G_LOCK (the_lock); |
| 153 |
if (authority == the_authority) |
| 154 |
the_authority = NULL; |
| 155 |
G_UNLOCK (the_lock); |
| 156 |
|
| 157 |
if (G_OBJECT_CLASS (polkit_authority_parent_class)->dispose != NULL) |
| 158 |
G_OBJECT_CLASS (polkit_authority_parent_class)->dispose (object); |
| 159 |
} |
| 160 |
|
| 161 |
static void |
| 162 |
polkit_authority_finalize (GObject *object) |
| 163 |
{ |
| 164 |
PolkitAuthority *authority = POLKIT_AUTHORITY (object); |
| 165 |
|
| 166 |
if (authority->initialization_error != NULL) |
| 167 |
g_error_free (authority->initialization_error); |
| 168 |
|
| 169 |
g_free (authority->name); |
| 170 |
g_free (authority->version); |
| 171 |
if (authority->proxy != NULL) |
| 172 |
g_object_unref (authority->proxy); |
| 173 |
|
| 174 |
if (G_OBJECT_CLASS (polkit_authority_parent_class)->finalize != NULL) |
| 175 |
G_OBJECT_CLASS (polkit_authority_parent_class)->finalize (object); |
| 176 |
} |
| 177 |
|
| 178 |
static void |
| 179 |
polkit_authority_get_property (GObject *object, |
| 180 |
guint prop_id, |
| 181 |
GValue *value, |
| 182 |
GParamSpec *pspec) |
| 183 |
{ |
| 184 |
PolkitAuthority *authority = POLKIT_AUTHORITY (object); |
| 185 |
|
| 186 |
switch (prop_id) |
| 187 |
{ |
| 188 |
case PROP_OWNER: |
| 189 |
g_value_take_string (value, polkit_authority_get_owner (authority)); |
| 190 |
break; |
| 191 |
|
| 192 |
case PROP_BACKEND_NAME: |
| 193 |
g_value_set_string (value, polkit_authority_get_backend_name (authority)); |
| 194 |
break; |
| 195 |
|
| 196 |
case PROP_BACKEND_VERSION: |
| 197 |
g_value_set_string (value, polkit_authority_get_backend_version (authority)); |
| 198 |
break; |
| 199 |
|
| 200 |
case PROP_BACKEND_FEATURES: |
| 201 |
g_value_set_flags (value, polkit_authority_get_backend_features (authority)); |
| 202 |
break; |
| 203 |
|
| 204 |
default: |
| 205 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 206 |
break; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
static void |
| 211 |
polkit_authority_class_init (PolkitAuthorityClass *klass) |
| 212 |
{ |
| 213 |
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); |
| 214 |
|
| 215 |
gobject_class->dispose = polkit_authority_dispose; |
| 216 |
gobject_class->finalize = polkit_authority_finalize; |
| 217 |
gobject_class->get_property = polkit_authority_get_property; |
| 218 |
|
| 219 |
/** |
| 220 |
* PolkitAuthority:owner: |
| 221 |
* |
| 222 |
* The unique name of the owner of the org.freedesktop.PolicyKit1 |
| 223 |
* D-Bus service or %NULL if there is no owner. Connect to the |
| 224 |
* #GObject::notify signal to track changes to this property. |
| 225 |
*/ |
| 226 |
g_object_class_install_property (gobject_class, |
| 227 |
PROP_OWNER, |
| 228 |
g_param_spec_string ("owner", |
| 229 |
"Owner", |
| 230 |
"Owner.", |
| 231 |
NULL, |
| 232 |
G_PARAM_READABLE | |
| 233 |
G_PARAM_STATIC_NAME | |
| 234 |
G_PARAM_STATIC_NICK | |
| 235 |
G_PARAM_STATIC_BLURB)); |
| 236 |
|
| 237 |
/** |
| 238 |
* PolkitAuthority:backend-name: |
| 239 |
* |
| 240 |
* The name of the currently used Authority backend. |
| 241 |
*/ |
| 242 |
g_object_class_install_property (gobject_class, |
| 243 |
PROP_BACKEND_NAME, |
| 244 |
g_param_spec_string ("backend-name", |
| 245 |
"Backend name", |
| 246 |
"The name of the currently used Authority backend.", |
| 247 |
NULL, |
| 248 |
G_PARAM_READABLE | |
| 249 |
G_PARAM_STATIC_NAME | |
| 250 |
G_PARAM_STATIC_NICK | |
| 251 |
G_PARAM_STATIC_BLURB)); |
| 252 |
|
| 253 |
/** |
| 254 |
* PolkitAuthority:version: |
| 255 |
* |
| 256 |
* The version of the currently used Authority backend. |
| 257 |
*/ |
| 258 |
g_object_class_install_property (gobject_class, |
| 259 |
PROP_BACKEND_VERSION, |
| 260 |
g_param_spec_string ("backend-version", |
| 261 |
"Backend version", |
| 262 |
"The version of the currently used Authority backend.", |
| 263 |
NULL, |
| 264 |
G_PARAM_READABLE | |
| 265 |
G_PARAM_STATIC_NAME | |
| 266 |
G_PARAM_STATIC_NICK | |
| 267 |
G_PARAM_STATIC_BLURB)); |
| 268 |
|
| 269 |
/** |
| 270 |
* PolkitAuthority:backend-features: |
| 271 |
* |
| 272 |
* The features of the currently used Authority backend. |
| 273 |
*/ |
| 274 |
g_object_class_install_property (gobject_class, |
| 275 |
PROP_BACKEND_FEATURES, |
| 276 |
g_param_spec_flags ("backend-features", |
| 277 |
"Backend features", |
| 278 |
"The features of the currently used Authority backend.", |
| 279 |
POLKIT_TYPE_AUTHORITY_FEATURES, |
| 280 |
POLKIT_AUTHORITY_FEATURES_NONE, |
| 281 |
G_PARAM_READABLE | |
| 282 |
G_PARAM_STATIC_NAME | |
| 283 |
G_PARAM_STATIC_NICK | |
| 284 |
G_PARAM_STATIC_BLURB)); |
| 285 |
|
| 286 |
/** |
| 287 |
* PolkitAuthority::changed: |
| 288 |
* @authority: A #PolkitAuthority. |
| 289 |
* |
| 290 |
* Emitted when actions and/or authorizations change |
| 291 |
*/ |
| 292 |
signals[CHANGED_SIGNAL] = g_signal_new ("changed", |
| 293 |
POLKIT_TYPE_AUTHORITY, |
| 294 |
G_SIGNAL_RUN_LAST, |
| 295 |
0, /* class offset */ |
| 296 |
NULL, /* accumulator */ |
| 297 |
NULL, /* accumulator data */ |
| 298 |
g_cclosure_marshal_VOID__VOID, |
| 299 |
G_TYPE_NONE, |
| 300 |
0); |
| 301 |
/** |
| 302 |
* PolkitAuthority::sessions-changed: |
| 303 |
* @authority: A #PolkitAuthority. |
| 304 |
* |
| 305 |
* Emitted when sessions change |
| 306 |
*/ |
| 307 |
signals[SESSIONS_CHANGED_SIGNAL] = g_signal_new ("sessions-changed", |
| 308 |
POLKIT_TYPE_AUTHORITY, |
| 309 |
G_SIGNAL_RUN_LAST, |
| 310 |
0, /* class offset */ |
| 311 |
NULL, /* accumulator */ |
| 312 |
NULL, /* accumulator data */ |
| 313 |
g_cclosure_marshal_VOID__VOID, |
| 314 |
G_TYPE_NONE, |
| 315 |
0); |
| 316 |
} |
| 317 |
|
| 318 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 319 |
|
| 320 |
static gboolean |
| 321 |
polkit_authority_initable_init (GInitable *initable, |
| 322 |
GCancellable *cancellable, |
| 323 |
GError **error) |
| 324 |
{ |
| 325 |
PolkitAuthority *authority = POLKIT_AUTHORITY (initable); |
| 326 |
gboolean ret; |
| 327 |
|
| 328 |
/* This method needs to be idempotent to work with the singleton |
| 329 |
* pattern. See the docs for g_initable_init(). We implement this by |
| 330 |
* locking. |
| 331 |
*/ |
| 332 |
|
| 333 |
ret = FALSE; |
| 334 |
|
| 335 |
G_LOCK (the_lock); |
| 336 |
if (authority->initialized) |
| 337 |
{ |
| 338 |
if (authority->initialization_error == NULL) |
| 339 |
ret = TRUE; |
| 340 |
goto out; |
| 341 |
} |
| 342 |
|
| 343 |
authority->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, |
| 344 |
G_DBUS_PROXY_FLAGS_NONE, |
| 345 |
NULL, /* TODO: pass GDBusInterfaceInfo* */ |
| 346 |
"org.freedesktop.PolicyKit1", /* name */ |
| 347 |
"/org/freedesktop/PolicyKit1/Authority", /* path */ |
| 348 |
"org.freedesktop.PolicyKit1.Authority", /* interface */ |
| 349 |
cancellable, |
| 350 |
&authority->initialization_error); |
| 351 |
if (authority->proxy == NULL) |
| 352 |
{ |
| 353 |
g_prefix_error (&authority->initialization_error, "Error initializing authority: "); |
| 354 |
goto out; |
| 355 |
} |
| 356 |
g_signal_connect (authority->proxy, |
| 357 |
"g-signal", |
| 358 |
G_CALLBACK (on_proxy_signal), |
| 359 |
authority); |
| 360 |
g_signal_connect (authority->proxy, |
| 361 |
"notify::g-name-owner", |
| 362 |
G_CALLBACK (on_notify_g_name_owner), |
| 363 |
authority); |
| 364 |
|
| 365 |
ret = TRUE; |
| 366 |
|
| 367 |
out: |
| 368 |
authority->initialized = TRUE; |
| 369 |
|
| 370 |
if (!ret) |
| 371 |
{ |
| 372 |
g_assert (authority->initialization_error != NULL); |
| 373 |
g_propagate_error (error, g_error_copy (authority->initialization_error)); |
| 374 |
} |
| 375 |
G_UNLOCK (the_lock); |
| 376 |
return ret; |
| 377 |
} |
| 378 |
|
| 379 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 380 |
|
| 381 |
static void |
| 382 |
initable_iface_init (GInitableIface *initable_iface) |
| 383 |
{ |
| 384 |
initable_iface->init = polkit_authority_initable_init; |
| 385 |
} |
| 386 |
|
| 387 |
static void |
| 388 |
async_initable_iface_init (GAsyncInitableIface *async_initable_iface) |
| 389 |
{ |
| 390 |
/* for now, we use default implementation to run GInitable code in a |
| 391 |
* thread - would probably be nice to have real async version to |
| 392 |
* avoid the thread-overhead |
| 393 |
*/ |
| 394 |
} |
| 395 |
|
| 396 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 397 |
|
| 398 |
/* deprecated, see polkitauthority.h */ |
| 399 |
|
| 400 |
/** |
| 401 |
* polkit_authority_get: |
| 402 |
* |
| 403 |
* (deprecated) |
| 404 |
* |
| 405 |
* Returns: (transfer full): value |
| 406 |
*/ |
| 407 |
PolkitAuthority * |
| 408 |
polkit_authority_get (void) |
| 409 |
{ |
| 410 |
GError *error; |
| 411 |
PolkitAuthority *ret; |
| 412 |
|
| 413 |
error = NULL; |
| 414 |
ret = polkit_authority_get_sync (NULL, /* GCancellable* */ |
| 415 |
&error); |
| 416 |
if (ret == NULL) |
| 417 |
{ |
| 418 |
g_warning ("polkit_authority_get: Error getting authority: %s", |
| 419 |
error->message); |
| 420 |
g_error_free (error); |
| 421 |
} |
| 422 |
|
| 423 |
return ret; |
| 424 |
} |
| 425 |
|
| 426 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 427 |
|
| 428 |
static PolkitAuthority * |
| 429 |
get_uninitialized_authority (GCancellable *cancellable, |
| 430 |
GError **error) |
| 431 |
{ |
| 432 |
static volatile GQuark error_quark = 0; |
| 433 |
|
| 434 |
G_LOCK (the_lock); |
| 435 |
if (error_quark == 0) |
| 436 |
error_quark = POLKIT_ERROR; |
| 437 |
|
| 438 |
if (the_authority != NULL) |
| 439 |
{ |
| 440 |
g_object_ref (the_authority); |
| 441 |
goto out; |
| 442 |
} |
| 443 |
the_authority = POLKIT_AUTHORITY (g_object_new (POLKIT_TYPE_AUTHORITY, NULL)); |
| 444 |
out: |
| 445 |
G_UNLOCK (the_lock); |
| 446 |
return the_authority; |
| 447 |
} |
| 448 |
|
| 449 |
static void |
| 450 |
authority_get_async_cb (GObject *source_object, |
| 451 |
GAsyncResult *res, |
| 452 |
gpointer user_data) |
| 453 |
{ |
| 454 |
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); |
| 455 |
GError *error; |
| 456 |
|
| 457 |
error = NULL; |
| 458 |
if (!g_async_initable_init_finish (G_ASYNC_INITABLE (source_object), |
| 459 |
res, |
| 460 |
&error)) |
| 461 |
{ |
| 462 |
g_assert (error != NULL); |
| 463 |
g_simple_async_result_set_from_error (simple, error); |
| 464 |
g_error_free (error); |
| 465 |
g_object_unref (source_object); |
| 466 |
} |
| 467 |
else |
| 468 |
{ |
| 469 |
g_simple_async_result_set_op_res_gpointer (simple, |
| 470 |
source_object, |
| 471 |
g_object_unref); |
| 472 |
} |
| 473 |
g_simple_async_result_complete_in_idle (simple); |
| 474 |
g_object_unref (simple); |
| 475 |
} |
| 476 |
|
| 477 |
/** |
| 478 |
* polkit_authority_get_async: |
| 479 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 480 |
* @callback: A #GAsyncReadyCallback to call when the request is satisfied. |
| 481 |
* @user_data: The data to pass to @callback. |
| 482 |
* |
| 483 |
* Asynchronously gets a reference to the authority. |
| 484 |
* |
| 485 |
* This is an asynchronous failable function. When the result is |
| 486 |
* ready, @callback will be invoked in the <link |
| 487 |
* linkend="g-main-context-push-thread-default">thread-default main |
| 488 |
* loop</link> of the thread you are calling this method from and you |
| 489 |
* can use polkit_authority_get_finish() to get the result. See |
| 490 |
* polkit_authority_get_sync() for the synchronous version. |
| 491 |
*/ |
| 492 |
void |
| 493 |
polkit_authority_get_async (GCancellable *cancellable, |
| 494 |
GAsyncReadyCallback callback, |
| 495 |
gpointer user_data) |
| 496 |
{ |
| 497 |
PolkitAuthority *authority; |
| 498 |
GSimpleAsyncResult *simple; |
| 499 |
GError *error; |
| 500 |
|
| 501 |
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); |
| 502 |
|
| 503 |
simple = g_simple_async_result_new (NULL, |
| 504 |
callback, |
| 505 |
user_data, |
| 506 |
polkit_authority_get_async); |
| 507 |
|
| 508 |
error = NULL; |
| 509 |
authority = get_uninitialized_authority (cancellable, &error); |
| 510 |
if (authority == NULL) |
| 511 |
{ |
| 512 |
g_assert (error != NULL); |
| 513 |
g_simple_async_result_set_from_error (simple, error); |
| 514 |
g_error_free (error); |
| 515 |
g_simple_async_result_complete_in_idle (simple); |
| 516 |
g_object_unref (simple); |
| 517 |
} |
| 518 |
else |
| 519 |
{ |
| 520 |
g_async_initable_init_async (G_ASYNC_INITABLE (authority), |
| 521 |
G_PRIORITY_DEFAULT, |
| 522 |
cancellable, |
| 523 |
authority_get_async_cb, |
| 524 |
simple); |
| 525 |
} |
| 526 |
} |
| 527 |
|
| 528 |
/** |
| 529 |
* polkit_authority_get_finish: |
| 530 |
* @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to polkit_authority_get_async(). |
| 531 |
* @error: (allow-none): Return location for error or %NULL. |
| 532 |
* |
| 533 |
* Finishes an operation started with polkit_authority_get_async(). |
| 534 |
* |
| 535 |
* Returns: (transfer full): A #PolkitAuthority. Free it with |
| 536 |
* g_object_unref() when done with it. |
| 537 |
*/ |
| 538 |
PolkitAuthority * |
| 539 |
polkit_authority_get_finish (GAsyncResult *res, |
| 540 |
GError **error) |
| 541 |
{ |
| 542 |
GSimpleAsyncResult *simple; |
| 543 |
GObject *object; |
| 544 |
PolkitAuthority *ret; |
| 545 |
|
| 546 |
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), NULL); |
| 547 |
g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 548 |
|
| 549 |
simple = G_SIMPLE_ASYNC_RESULT (res); |
| 550 |
|
| 551 |
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_get_async); |
| 552 |
|
| 553 |
ret = NULL; |
| 554 |
|
| 555 |
if (g_simple_async_result_propagate_error (simple, error)) |
| 556 |
goto out; |
| 557 |
|
| 558 |
object = g_simple_async_result_get_op_res_gpointer (simple); |
| 559 |
g_assert (object != NULL); |
| 560 |
ret = g_object_ref (POLKIT_AUTHORITY (object)); |
| 561 |
|
| 562 |
out: |
| 563 |
return ret; |
| 564 |
} |
| 565 |
|
| 566 |
/** |
| 567 |
* polkit_authority_get_sync: |
| 568 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 569 |
* @error: (allow-none): Return location for error or %NULL. |
| 570 |
* |
| 571 |
* Synchronously gets a reference to the authority. |
| 572 |
* |
| 573 |
* This is a synchronous failable function - the calling thread is |
| 574 |
* blocked until a reply is received. See polkit_authority_get_async() |
| 575 |
* for the asynchronous version. |
| 576 |
* |
| 577 |
* Returns: (transfer full): A #PolkitAuthority. Free it with |
| 578 |
* g_object_unref() when done with it. |
| 579 |
*/ |
| 580 |
PolkitAuthority * |
| 581 |
polkit_authority_get_sync (GCancellable *cancellable, |
| 582 |
GError **error) |
| 583 |
{ |
| 584 |
PolkitAuthority *authority; |
| 585 |
|
| 586 |
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL); |
| 587 |
g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 588 |
|
| 589 |
authority = get_uninitialized_authority (cancellable, error); |
| 590 |
if (authority == NULL) |
| 591 |
goto out; |
| 592 |
|
| 593 |
if (!g_initable_init (G_INITABLE (authority), cancellable, error)) |
| 594 |
{ |
| 595 |
g_object_unref (authority); |
| 596 |
authority = NULL; |
| 597 |
} |
| 598 |
|
| 599 |
out: |
| 600 |
return authority; |
| 601 |
} |
| 602 |
|
| 603 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 604 |
|
| 605 |
typedef struct |
| 606 |
{ |
| 607 |
GAsyncResult *res; |
| 608 |
GMainContext *context; |
| 609 |
GMainLoop *loop; |
| 610 |
} CallSyncData; |
| 611 |
|
| 612 |
static CallSyncData * |
| 613 |
call_sync_new (void) |
| 614 |
{ |
| 615 |
CallSyncData *data; |
| 616 |
data = g_new0 (CallSyncData, 1); |
| 617 |
data->context = g_main_context_new (); |
| 618 |
data->loop = g_main_loop_new (data->context, FALSE); |
| 619 |
g_main_context_push_thread_default (data->context); |
| 620 |
return data; |
| 621 |
} |
| 622 |
|
| 623 |
static void |
| 624 |
call_sync_cb (GObject *source_object, |
| 625 |
GAsyncResult *res, |
| 626 |
gpointer user_data) |
| 627 |
{ |
| 628 |
CallSyncData *data = user_data; |
| 629 |
data->res = g_object_ref (res); |
| 630 |
g_main_loop_quit (data->loop); |
| 631 |
} |
| 632 |
|
| 633 |
static void |
| 634 |
call_sync_block (CallSyncData *data) |
| 635 |
{ |
| 636 |
g_main_loop_run (data->loop); |
| 637 |
} |
| 638 |
|
| 639 |
static void |
| 640 |
call_sync_free (CallSyncData *data) |
| 641 |
{ |
| 642 |
g_main_context_pop_thread_default (data->context); |
| 643 |
g_main_context_unref (data->context); |
| 644 |
g_main_loop_unref (data->loop); |
| 645 |
g_object_unref (data->res); |
| 646 |
g_free (data); |
| 647 |
} |
| 648 |
|
| 649 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 650 |
|
| 651 |
static void |
| 652 |
generic_async_cb (GObject *source_obj, |
| 653 |
GAsyncResult *res, |
| 654 |
gpointer user_data) |
| 655 |
{ |
| 656 |
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); |
| 657 |
g_simple_async_result_set_op_res_gpointer (simple, g_object_ref (res), g_object_unref); |
| 658 |
g_simple_async_result_complete (simple); |
| 659 |
g_object_unref (simple); |
| 660 |
} |
| 661 |
|
| 662 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 663 |
|
| 664 |
/** |
| 665 |
* polkit_authority_enumerate_actions: |
| 666 |
* @authority: A #PolkitAuthority. |
| 667 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 668 |
* @callback: A #GAsyncReadyCallback to call when the request is satisfied. |
| 669 |
* @user_data: The data to pass to @callback. |
| 670 |
* |
| 671 |
* Asynchronously retrieves all registered actions. |
| 672 |
* |
| 673 |
* When the operation is finished, @callback will be invoked in the |
| 674 |
* <link linkend="g-main-context-push-thread-default">thread-default |
| 675 |
* main loop</link> of the thread you are calling this method |
| 676 |
* from. You can then call polkit_authority_enumerate_actions_finish() |
| 677 |
* to get the result of the operation. |
| 678 |
**/ |
| 679 |
void |
| 680 |
polkit_authority_enumerate_actions (PolkitAuthority *authority, |
| 681 |
GCancellable *cancellable, |
| 682 |
GAsyncReadyCallback callback, |
| 683 |
gpointer user_data) |
| 684 |
{ |
| 685 |
g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); |
| 686 |
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); |
| 687 |
g_dbus_proxy_call (authority->proxy, |
| 688 |
"EnumerateActions", |
| 689 |
g_variant_new ("(s)", |
| 690 |
""), /* TODO: use system locale */ |
| 691 |
G_DBUS_CALL_FLAGS_NONE, |
| 692 |
-1, |
| 693 |
cancellable, |
| 694 |
generic_async_cb, |
| 695 |
g_simple_async_result_new (G_OBJECT (authority), |
| 696 |
callback, |
| 697 |
user_data, |
| 698 |
polkit_authority_enumerate_actions)); |
| 699 |
} |
| 700 |
|
| 701 |
/** |
| 702 |
* polkit_authority_enumerate_actions_finish: |
| 703 |
* @authority: A #PolkitAuthority. |
| 704 |
* @res: A #GAsyncResult obtained from the callback. |
| 705 |
* @error: (allow-none): Return location for error or %NULL. |
| 706 |
* |
| 707 |
* Finishes retrieving all registered actions. |
| 708 |
* |
| 709 |
* Returns: (element-type Polkit.ActionDescription) (transfer full): A list of |
| 710 |
* #PolkitActionDescription objects or %NULL if @error is set. The returned |
| 711 |
* list should be freed with g_list_free() after each element have been freed |
| 712 |
* with g_object_unref(). |
| 713 |
**/ |
| 714 |
GList * |
| 715 |
polkit_authority_enumerate_actions_finish (PolkitAuthority *authority, |
| 716 |
GAsyncResult *res, |
| 717 |
GError **error) |
| 718 |
{ |
| 719 |
GList *ret; |
| 720 |
GVariant *value; |
| 721 |
GVariantIter iter; |
| 722 |
GVariant *child; |
| 723 |
GVariant *array; |
| 724 |
GAsyncResult *_res; |
| 725 |
|
| 726 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), NULL); |
| 727 |
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), NULL); |
| 728 |
g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 729 |
|
| 730 |
ret = NULL; |
| 731 |
|
| 732 |
g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == polkit_authority_enumerate_actions); |
| 733 |
_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); |
| 734 |
|
| 735 |
value = g_dbus_proxy_call_finish (authority->proxy, _res, error); |
| 736 |
if (value == NULL) |
| 737 |
goto out; |
| 738 |
|
| 739 |
array = g_variant_get_child_value (value, 0); |
| 740 |
g_variant_iter_init (&iter, array); |
| 741 |
while ((child = g_variant_iter_next_value (&iter)) != NULL) |
| 742 |
{ |
| 743 |
ret = g_list_prepend (ret, polkit_action_description_new_for_gvariant (child)); |
| 744 |
g_variant_unref (child); |
| 745 |
} |
| 746 |
ret = g_list_reverse (ret); |
| 747 |
g_variant_unref (array); |
| 748 |
g_variant_unref (value); |
| 749 |
|
| 750 |
out: |
| 751 |
return ret; |
| 752 |
} |
| 753 |
|
| 754 |
/** |
| 755 |
* polkit_authority_enumerate_actions_sync: |
| 756 |
* @authority: A #PolkitAuthority. |
| 757 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 758 |
* @error: (allow-none): Return location for error or %NULL. |
| 759 |
* |
| 760 |
* Synchronously retrieves all registered actions - the calling thread |
| 761 |
* is blocked until a reply is received. See |
| 762 |
* polkit_authority_enumerate_actions() for the asynchronous version. |
| 763 |
* |
| 764 |
* Returns: (element-type Polkit.ActionDescription) (transfer full): A list of |
| 765 |
* #PolkitActionDescription or %NULL if @error is set. The returned list should |
| 766 |
* be freed with g_list_free() after each element have been freed with |
| 767 |
* g_object_unref(). |
| 768 |
**/ |
| 769 |
GList * |
| 770 |
polkit_authority_enumerate_actions_sync (PolkitAuthority *authority, |
| 771 |
GCancellable *cancellable, |
| 772 |
GError **error) |
| 773 |
{ |
| 774 |
GList *ret; |
| 775 |
CallSyncData *data; |
| 776 |
|
| 777 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), NULL); |
| 778 |
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL); |
| 779 |
g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 780 |
|
| 781 |
data = call_sync_new (); |
| 782 |
polkit_authority_enumerate_actions (authority, cancellable, call_sync_cb, data); |
| 783 |
call_sync_block (data); |
| 784 |
ret = polkit_authority_enumerate_actions_finish (authority, data->res, error); |
| 785 |
call_sync_free (data); |
| 786 |
|
| 787 |
return ret; |
| 788 |
} |
| 789 |
|
| 790 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 791 |
|
| 792 |
typedef struct |
| 793 |
{ |
| 794 |
PolkitAuthority *authority; |
| 795 |
GSimpleAsyncResult *simple; |
| 796 |
gchar *cancellation_id; |
| 797 |
} CheckAuthData; |
| 798 |
|
| 799 |
static void |
| 800 |
cancel_check_authorization_cb (GDBusProxy *proxy, |
| 801 |
GAsyncResult *res, |
| 802 |
gpointer user_data) |
| 803 |
{ |
| 804 |
GVariant *value; |
| 805 |
GError *error; |
| 806 |
|
| 807 |
error = NULL; |
| 808 |
value = g_dbus_proxy_call_finish (proxy, res, &error); |
| 809 |
if (value == NULL) |
| 810 |
{ |
| 811 |
g_warning ("Error cancelling authorization check: %s", error->message); |
| 812 |
g_error_free (error); |
| 813 |
} |
| 814 |
else |
| 815 |
{ |
| 816 |
g_variant_unref (value); |
| 817 |
} |
| 818 |
} |
| 819 |
|
| 820 |
static void |
| 821 |
check_authorization_cb (GDBusProxy *proxy, |
| 822 |
GAsyncResult *res, |
| 823 |
gpointer user_data) |
| 824 |
{ |
| 825 |
CheckAuthData *data = user_data; |
| 826 |
GVariant *value; |
| 827 |
GError *error; |
| 828 |
|
| 829 |
error = NULL; |
| 830 |
value = g_dbus_proxy_call_finish (proxy, res, &error); |
| 831 |
if (value == NULL) |
| 832 |
{ |
| 833 |
if (data->cancellation_id != NULL && |
| 834 |
(!g_dbus_error_is_remote_error (error) && |
| 835 |
error->domain == G_IO_ERROR && |
| 836 |
error->code == G_IO_ERROR_CANCELLED)) |
| 837 |
{ |
| 838 |
g_dbus_proxy_call (data->authority->proxy, |
| 839 |
"CancelCheckAuthorization", |
| 840 |
g_variant_new ("(s)", data->cancellation_id), |
| 841 |
G_DBUS_CALL_FLAGS_NONE, |
| 842 |
-1, |
| 843 |
NULL, /* GCancellable */ |
| 844 |
(GAsyncReadyCallback) cancel_check_authorization_cb, |
| 845 |
NULL); |
| 846 |
} |
| 847 |
g_simple_async_result_set_from_error (data->simple, error); |
| 848 |
g_error_free (error); |
| 849 |
} |
| 850 |
else |
| 851 |
{ |
| 852 |
GVariant *result_value; |
| 853 |
PolkitAuthorizationResult *result; |
| 854 |
result_value = g_variant_get_child_value (value, 0); |
| 855 |
result = polkit_authorization_result_new_for_gvariant (result_value); |
| 856 |
g_variant_unref (result_value); |
| 857 |
g_variant_unref (value); |
| 858 |
g_simple_async_result_set_op_res_gpointer (data->simple, result, g_object_unref); |
| 859 |
} |
| 860 |
|
| 861 |
g_simple_async_result_complete (data->simple); |
| 862 |
|
| 863 |
g_object_unref (data->authority); |
| 864 |
g_object_unref (data->simple); |
| 865 |
g_free (data->cancellation_id); |
| 866 |
g_free (data); |
| 867 |
} |
| 868 |
|
| 869 |
/** |
| 870 |
* polkit_authority_check_authorization: |
| 871 |
* @authority: A #PolkitAuthority. |
| 872 |
* @subject: A #PolkitSubject. |
| 873 |
* @action_id: The action to check for. |
| 874 |
* @details: (allow-none): Details about the action or %NULL. |
| 875 |
* @flags: A set of #PolkitCheckAuthorizationFlags. |
| 876 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 877 |
* @callback: A #GAsyncReadyCallback to call when the request is satisfied. |
| 878 |
* @user_data: The data to pass to @callback. |
| 879 |
* |
| 880 |
* Asynchronously checks if @subject is authorized to perform the action represented |
| 881 |
* by @action_id. |
| 882 |
* |
| 883 |
* Note that %POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION |
| 884 |
* <emphasis>SHOULD</emphasis> be passed <emphasis>ONLY</emphasis> if |
| 885 |
* the event that triggered the authorization check is stemming from |
| 886 |
* an user action, e.g. the user pressing a button or attaching a |
| 887 |
* device. |
| 888 |
* |
| 889 |
* When the operation is finished, @callback will be invoked in the |
| 890 |
* <link linkend="g-main-context-push-thread-default">thread-default |
| 891 |
* main loop</link> of the thread you are calling this method |
| 892 |
* from. You can then call |
| 893 |
* polkit_authority_check_authorization_finish() to get the result of |
| 894 |
* the operation. |
| 895 |
* |
| 896 |
* Known keys in @details include <literal>polkit.message</literal> |
| 897 |
* and <literal>polkit.gettext_domain</literal> that can be used to |
| 898 |
* override the message shown to the user. See the documentation for |
| 899 |
* the <link linkend="eggdbus-method-org.freedesktop.PolicyKit1.Authority.CheckAuthorization">D-Bus method</link> for more details. |
| 900 |
* |
| 901 |
* If @details is non-empty then the request will fail with |
| 902 |
* #POLKIT_ERROR_FAILED unless the process doing the check itself is |
| 903 |
* sufficiently authorized (e.g. running as uid 0). |
| 904 |
**/ |
| 905 |
void |
| 906 |
polkit_authority_check_authorization (PolkitAuthority *authority, |
| 907 |
PolkitSubject *subject, |
| 908 |
const gchar *action_id, |
| 909 |
PolkitDetails *details, |
| 910 |
PolkitCheckAuthorizationFlags flags, |
| 911 |
GCancellable *cancellable, |
| 912 |
GAsyncReadyCallback callback, |
| 913 |
gpointer user_data) |
| 914 |
{ |
| 915 |
CheckAuthData *data; |
| 916 |
|
| 917 |
g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); |
| 918 |
g_return_if_fail (POLKIT_IS_SUBJECT (subject)); |
| 919 |
g_return_if_fail (action_id != NULL); |
| 920 |
g_return_if_fail (details == NULL || POLKIT_IS_DETAILS (details)); |
| 921 |
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); |
| 922 |
|
| 923 |
data = g_new0 (CheckAuthData, 1); |
| 924 |
data->authority = g_object_ref (authority); |
| 925 |
data->simple = g_simple_async_result_new (G_OBJECT (authority), |
| 926 |
callback, |
| 927 |
user_data, |
| 928 |
polkit_authority_check_authorization); |
| 929 |
G_LOCK (the_lock); |
| 930 |
if (cancellable != NULL) |
| 931 |
data->cancellation_id = g_strdup_printf ("cancellation-id-%d", authority->cancellation_id_counter++); |
| 932 |
G_UNLOCK (the_lock); |
| 933 |
|
| 934 |
g_dbus_proxy_call (authority->proxy, |
| 935 |
"CheckAuthorization", |
| 936 |
g_variant_new ("(@(sa{sv})s@a{ss}us)", |
| 937 |
polkit_subject_to_gvariant (subject), /* A floating value */ |
| 938 |
action_id, |
| 939 |
polkit_details_to_gvariant (details), /* A floating value */ |
| 940 |
flags, |
| 941 |
data->cancellation_id != NULL ? data->cancellation_id : ""), |
| 942 |
G_DBUS_CALL_FLAGS_NONE, |
| 943 |
G_MAXINT, /* no timeout */ |
| 944 |
cancellable, |
| 945 |
(GAsyncReadyCallback) check_authorization_cb, |
| 946 |
data); |
| 947 |
} |
| 948 |
|
| 949 |
/** |
| 950 |
* polkit_authority_check_authorization_finish: |
| 951 |
* @authority: A #PolkitAuthority. |
| 952 |
* @res: A #GAsyncResult obtained from the callback. |
| 953 |
* @error: (allow-none): Return location for error or %NULL. |
| 954 |
* |
| 955 |
* Finishes checking if a subject is authorized for an action. |
| 956 |
* |
| 957 |
* Returns: (transfer full): A #PolkitAuthorizationResult or %NULL if |
| 958 |
* @error is set. Free with g_object_unref(). |
| 959 |
**/ |
| 960 |
PolkitAuthorizationResult * |
| 961 |
polkit_authority_check_authorization_finish (PolkitAuthority *authority, |
| 962 |
GAsyncResult *res, |
| 963 |
GError **error) |
| 964 |
{ |
| 965 |
PolkitAuthorizationResult *ret; |
| 966 |
|
| 967 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), NULL); |
| 968 |
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), NULL); |
| 969 |
g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 970 |
|
| 971 |
ret = NULL; |
| 972 |
|
| 973 |
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) |
| 974 |
goto out; |
| 975 |
|
| 976 |
ret = g_object_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); |
| 977 |
|
| 978 |
out: |
| 979 |
return ret; |
| 980 |
} |
| 981 |
|
| 982 |
/** |
| 983 |
* polkit_authority_check_authorization_sync: |
| 984 |
* @authority: A #PolkitAuthority. |
| 985 |
* @subject: A #PolkitSubject. |
| 986 |
* @action_id: The action to check for. |
| 987 |
* @details: (allow-none): Details about the action or %NULL. |
| 988 |
* @flags: A set of #PolkitCheckAuthorizationFlags. |
| 989 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 990 |
* @error: (allow-none): Return location for error or %NULL. |
| 991 |
* |
| 992 |
* Checks if @subject is authorized to perform the action represented |
| 993 |
* by @action_id. |
| 994 |
* |
| 995 |
* Note that %POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION |
| 996 |
* <emphasis>SHOULD</emphasis> be passed <emphasis>ONLY</emphasis> if |
| 997 |
* the event that triggered the authorization check is stemming from |
| 998 |
* an user action, e.g. the user pressing a button or attaching a |
| 999 |
* device. |
| 1000 |
* |
| 1001 |
* Note the calling thread is blocked until a reply is received. You |
| 1002 |
* should therefore <emphasis>NEVER</emphasis> do this from a GUI |
| 1003 |
* thread or a daemon service thread when using the |
| 1004 |
* %POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION flag. This |
| 1005 |
* is because it may potentially take minutes (or even hours) for the |
| 1006 |
* operation to complete because it involves waiting for the user to |
| 1007 |
* authenticate. |
| 1008 |
* |
| 1009 |
* Known keys in @details include <literal>polkit.message</literal> |
| 1010 |
* and <literal>polkit.gettext_domain</literal> that can be used to |
| 1011 |
* override the message shown to the user. See the documentation for |
| 1012 |
* the <link linkend="eggdbus-method-org.freedesktop.PolicyKit1.Authority.CheckAuthorization">D-Bus method</link> for more details. |
| 1013 |
* |
| 1014 |
* Returns: (transfer full): A #PolkitAuthorizationResult or %NULL if @error is set. Free with g_object_unref(). |
| 1015 |
*/ |
| 1016 |
PolkitAuthorizationResult * |
| 1017 |
polkit_authority_check_authorization_sync (PolkitAuthority *authority, |
| 1018 |
PolkitSubject *subject, |
| 1019 |
const gchar *action_id, |
| 1020 |
PolkitDetails *details, |
| 1021 |
PolkitCheckAuthorizationFlags flags, |
| 1022 |
GCancellable *cancellable, |
| 1023 |
GError **error) |
| 1024 |
{ |
| 1025 |
PolkitAuthorizationResult *ret; |
| 1026 |
CallSyncData *data; |
| 1027 |
|
| 1028 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), NULL); |
| 1029 |
g_return_val_if_fail (POLKIT_IS_SUBJECT (subject), NULL); |
| 1030 |
g_return_val_if_fail (action_id != NULL, NULL); |
| 1031 |
g_return_val_if_fail (details == NULL || POLKIT_IS_DETAILS (details), NULL); |
| 1032 |
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL); |
| 1033 |
g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 1034 |
|
| 1035 |
data = call_sync_new (); |
| 1036 |
polkit_authority_check_authorization (authority, subject, action_id, details, flags, cancellable, call_sync_cb, data); |
| 1037 |
call_sync_block (data); |
| 1038 |
ret = polkit_authority_check_authorization_finish (authority, data->res, error); |
| 1039 |
call_sync_free (data); |
| 1040 |
|
| 1041 |
return ret; |
| 1042 |
} |
| 1043 |
|
| 1044 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 1045 |
|
| 1046 |
/** |
| 1047 |
* polkit_authority_register_authentication_agent: |
| 1048 |
* @authority: A #PolkitAuthority. |
| 1049 |
* @subject: The subject the authentication agent is for, typically a #PolkitUnixSession object. |
| 1050 |
* @locale: The locale of the authentication agent. |
| 1051 |
* @object_path: The object path for the authentication agent. |
| 1052 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 1053 |
* @callback: A #GAsyncReadyCallback to call when the request is satisfied. |
| 1054 |
* @user_data: The data to pass to @callback. |
| 1055 |
* |
| 1056 |
* Asynchronously registers an authentication agent. |
| 1057 |
* |
| 1058 |
* Note that this should be called by the same effective UID which will be |
| 1059 |
* the real UID using the #PolkitAgentSession API or otherwise calling |
| 1060 |
* polkit_authority_authentication_agent_response(). |
| 1061 |
* |
| 1062 |
* When the operation is finished, @callback will be invoked in the |
| 1063 |
* <link linkend="g-main-context-push-thread-default">thread-default |
| 1064 |
* main loop</link> of the thread you are calling this method |
| 1065 |
* from. You can then call |
| 1066 |
* polkit_authority_register_authentication_agent_finish() to get the |
| 1067 |
* result of the operation. |
| 1068 |
**/ |
| 1069 |
void |
| 1070 |
polkit_authority_register_authentication_agent (PolkitAuthority *authority, |
| 1071 |
PolkitSubject *subject, |
| 1072 |
const gchar *locale, |
| 1073 |
const gchar *object_path, |
| 1074 |
GCancellable *cancellable, |
| 1075 |
GAsyncReadyCallback callback, |
| 1076 |
gpointer user_data) |
| 1077 |
{ |
| 1078 |
g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); |
| 1079 |
g_return_if_fail (POLKIT_IS_SUBJECT (subject)); |
| 1080 |
g_return_if_fail (locale != NULL); |
| 1081 |
g_return_if_fail (g_variant_is_object_path (object_path)); |
| 1082 |
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); |
| 1083 |
|
| 1084 |
g_dbus_proxy_call (authority->proxy, |
| 1085 |
"RegisterAuthenticationAgent", |
| 1086 |
g_variant_new ("(@(sa{sv})ss)", |
| 1087 |
polkit_subject_to_gvariant (subject), /* A floating value */ |
| 1088 |
locale, |
| 1089 |
object_path), |
| 1090 |
G_DBUS_CALL_FLAGS_NONE, |
| 1091 |
-1, |
| 1092 |
cancellable, |
| 1093 |
generic_async_cb, |
| 1094 |
g_simple_async_result_new (G_OBJECT (authority), |
| 1095 |
callback, |
| 1096 |
user_data, |
| 1097 |
polkit_authority_register_authentication_agent)); |
| 1098 |
} |
| 1099 |
|
| 1100 |
/** |
| 1101 |
* polkit_authority_register_authentication_agent_finish: |
| 1102 |
* @authority: A #PolkitAuthority. |
| 1103 |
* @res: A #GAsyncResult obtained from the callback. |
| 1104 |
* @error: (allow-none): Return location for error or %NULL. |
| 1105 |
* |
| 1106 |
* Finishes registering an authentication agent. |
| 1107 |
* |
| 1108 |
* Returns: %TRUE if the authentication agent was successfully registered, %FALSE if @error is set. |
| 1109 |
**/ |
| 1110 |
gboolean |
| 1111 |
polkit_authority_register_authentication_agent_finish (PolkitAuthority *authority, |
| 1112 |
GAsyncResult *res, |
| 1113 |
GError **error) |
| 1114 |
{ |
| 1115 |
gboolean ret; |
| 1116 |
GVariant *value; |
| 1117 |
GAsyncResult *_res; |
| 1118 |
|
| 1119 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), FALSE); |
| 1120 |
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE); |
| 1121 |
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1122 |
|
| 1123 |
ret = FALSE; |
| 1124 |
|
| 1125 |
g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == polkit_authority_register_authentication_agent); |
| 1126 |
_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); |
| 1127 |
|
| 1128 |
value = g_dbus_proxy_call_finish (authority->proxy, _res, error); |
| 1129 |
if (value == NULL) |
| 1130 |
goto out; |
| 1131 |
ret = TRUE; |
| 1132 |
g_variant_unref (value); |
| 1133 |
|
| 1134 |
out: |
| 1135 |
return ret; |
| 1136 |
} |
| 1137 |
|
| 1138 |
|
| 1139 |
/** |
| 1140 |
* polkit_authority_register_authentication_agent_sync: |
| 1141 |
* @authority: A #PolkitAuthority. |
| 1142 |
* @subject: The subject the authentication agent is for, typically a #PolkitUnixSession object. |
| 1143 |
* @locale: The locale of the authentication agent. |
| 1144 |
* @object_path: The object path for the authentication agent. |
| 1145 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 1146 |
* @error: (allow-none): Return location for error or %NULL. |
| 1147 |
* |
| 1148 |
* Registers an authentication agent. |
| 1149 |
* |
| 1150 |
* Note that this should be called by the same effective UID which will be |
| 1151 |
* the real UID using the #PolkitAgentSession API or otherwise calling |
| 1152 |
* polkit_authority_authentication_agent_response(). |
| 1153 |
* |
| 1154 |
* The calling thread is blocked |
| 1155 |
* until a reply is received. See |
| 1156 |
* polkit_authority_register_authentication_agent() for the |
| 1157 |
* asynchronous version. |
| 1158 |
* |
| 1159 |
* Returns: %TRUE if the authentication agent was successfully registered, %FALSE if @error is set. |
| 1160 |
**/ |
| 1161 |
gboolean |
| 1162 |
polkit_authority_register_authentication_agent_sync (PolkitAuthority *authority, |
| 1163 |
PolkitSubject *subject, |
| 1164 |
const gchar *locale, |
| 1165 |
const gchar *object_path, |
| 1166 |
GCancellable *cancellable, |
| 1167 |
GError **error) |
| 1168 |
{ |
| 1169 |
gboolean ret; |
| 1170 |
CallSyncData *data; |
| 1171 |
|
| 1172 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), FALSE); |
| 1173 |
g_return_val_if_fail (POLKIT_IS_SUBJECT (subject), FALSE); |
| 1174 |
g_return_val_if_fail (locale != NULL, FALSE); |
| 1175 |
g_return_val_if_fail (g_variant_is_object_path (object_path), FALSE); |
| 1176 |
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE); |
| 1177 |
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1178 |
|
| 1179 |
data = call_sync_new (); |
| 1180 |
polkit_authority_register_authentication_agent (authority, subject, locale, object_path, cancellable, call_sync_cb, data); |
| 1181 |
call_sync_block (data); |
| 1182 |
ret = polkit_authority_register_authentication_agent_finish (authority, data->res, error); |
| 1183 |
call_sync_free (data); |
| 1184 |
|
| 1185 |
return ret; |
| 1186 |
} |
| 1187 |
|
| 1188 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 1189 |
|
| 1190 |
/** |
| 1191 |
* polkit_authority_register_authentication_agent_with_options: |
| 1192 |
* @authority: A #PolkitAuthority. |
| 1193 |
* @subject: The subject the authentication agent is for, typically a #PolkitUnixSession object. |
| 1194 |
* @locale: The locale of the authentication agent. |
| 1195 |
* @object_path: The object path for the authentication agent. |
| 1196 |
* @options: (allow-none): A #GVariant with options or %NULL. |
| 1197 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 1198 |
* @callback: A #GAsyncReadyCallback to call when the request is satisfied. |
| 1199 |
* @user_data: The data to pass to @callback. |
| 1200 |
* |
| 1201 |
* Asynchronously registers an authentication agent. |
| 1202 |
* |
| 1203 |
* Note that this should be called by the same effective UID which will be |
| 1204 |
* the real UID using the #PolkitAgentSession API or otherwise calling |
| 1205 |
* polkit_authority_authentication_agent_response(). |
| 1206 |
* |
| 1207 |
* When the operation is finished, @callback will be invoked in the |
| 1208 |
* <link linkend="g-main-context-push-thread-default">thread-default |
| 1209 |
* main loop</link> of the thread you are calling this method |
| 1210 |
* from. You can then call |
| 1211 |
* polkit_authority_register_authentication_agent_with_options_finish() to get the |
| 1212 |
* result of the operation. |
| 1213 |
**/ |
| 1214 |
void |
| 1215 |
polkit_authority_register_authentication_agent_with_options (PolkitAuthority *authority, |
| 1216 |
PolkitSubject *subject, |
| 1217 |
const gchar *locale, |
| 1218 |
const gchar *object_path, |
| 1219 |
GVariant *options, |
| 1220 |
GCancellable *cancellable, |
| 1221 |
GAsyncReadyCallback callback, |
| 1222 |
gpointer user_data) |
| 1223 |
{ |
| 1224 |
GVariant *subject_value; |
| 1225 |
|
| 1226 |
g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); |
| 1227 |
g_return_if_fail (POLKIT_IS_SUBJECT (subject)); |
| 1228 |
g_return_if_fail (locale != NULL); |
| 1229 |
g_return_if_fail (g_variant_is_object_path (object_path)); |
| 1230 |
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); |
| 1231 |
|
| 1232 |
subject_value = polkit_subject_to_gvariant (subject); |
| 1233 |
g_variant_ref_sink (subject_value); |
| 1234 |
if (options != NULL) |
| 1235 |
{ |
| 1236 |
g_dbus_proxy_call (authority->proxy, |
| 1237 |
"RegisterAuthenticationAgentWithOptions", |
| 1238 |
g_variant_new ("(@(sa{sv})ss@a{sv})", |
| 1239 |
subject_value, |
| 1240 |
locale, |
| 1241 |
object_path, |
| 1242 |
options), |
| 1243 |
G_DBUS_CALL_FLAGS_NONE, |
| 1244 |
-1, |
| 1245 |
cancellable, |
| 1246 |
generic_async_cb, |
| 1247 |
g_simple_async_result_new (G_OBJECT (authority), |
| 1248 |
callback, |
| 1249 |
user_data, |
| 1250 |
polkit_authority_register_authentication_agent_with_options)); |
| 1251 |
} |
| 1252 |
else |
| 1253 |
{ |
| 1254 |
g_dbus_proxy_call (authority->proxy, |
| 1255 |
"RegisterAuthenticationAgent", |
| 1256 |
g_variant_new ("(@(sa{sv})ss)", |
| 1257 |
subject_value, |
| 1258 |
locale, |
| 1259 |
object_path), |
| 1260 |
G_DBUS_CALL_FLAGS_NONE, |
| 1261 |
-1, |
| 1262 |
cancellable, |
| 1263 |
generic_async_cb, |
| 1264 |
g_simple_async_result_new (G_OBJECT (authority), |
| 1265 |
callback, |
| 1266 |
user_data, |
| 1267 |
polkit_authority_register_authentication_agent_with_options)); |
| 1268 |
} |
| 1269 |
g_variant_unref (subject_value); |
| 1270 |
} |
| 1271 |
|
| 1272 |
/** |
| 1273 |
* polkit_authority_register_authentication_agent_with_options_finish: |
| 1274 |
* @authority: A #PolkitAuthority. |
| 1275 |
* @res: A #GAsyncResult obtained from the callback. |
| 1276 |
* @error: (allow-none): Return location for error or %NULL. |
| 1277 |
* |
| 1278 |
* Finishes registering an authentication agent. |
| 1279 |
* |
| 1280 |
* Returns: %TRUE if the authentication agent was successfully registered, %FALSE if @error is set. |
| 1281 |
**/ |
| 1282 |
gboolean |
| 1283 |
polkit_authority_register_authentication_agent_with_options_finish (PolkitAuthority *authority, |
| 1284 |
GAsyncResult *res, |
| 1285 |
GError **error) |
| 1286 |
{ |
| 1287 |
gboolean ret; |
| 1288 |
GVariant *value; |
| 1289 |
GAsyncResult *_res; |
| 1290 |
|
| 1291 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), FALSE); |
| 1292 |
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE); |
| 1293 |
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1294 |
|
| 1295 |
ret = FALSE; |
| 1296 |
|
| 1297 |
g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == polkit_authority_register_authentication_agent_with_options); |
| 1298 |
_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); |
| 1299 |
|
| 1300 |
value = g_dbus_proxy_call_finish (authority->proxy, _res, error); |
| 1301 |
if (value == NULL) |
| 1302 |
goto out; |
| 1303 |
ret = TRUE; |
| 1304 |
g_variant_unref (value); |
| 1305 |
|
| 1306 |
out: |
| 1307 |
return ret; |
| 1308 |
} |
| 1309 |
|
| 1310 |
|
| 1311 |
/** |
| 1312 |
* polkit_authority_register_authentication_agent_with_options_sync: |
| 1313 |
* @authority: A #PolkitAuthority. |
| 1314 |
* @subject: The subject the authentication agent is for, typically a #PolkitUnixSession object. |
| 1315 |
* @locale: The locale of the authentication agent. |
| 1316 |
* @object_path: The object path for the authentication agent. |
| 1317 |
* @options: (allow-none): A #GVariant with options or %NULL. |
| 1318 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 1319 |
* @error: (allow-none): Return location for error or %NULL. |
| 1320 |
* |
| 1321 |
* Registers an authentication agent. |
| 1322 |
* |
| 1323 |
* Note that this should be called by the same effective UID which will be |
| 1324 |
* the real UID using the #PolkitAgentSession API or otherwise calling |
| 1325 |
* polkit_authority_authentication_agent_response(). |
| 1326 |
* |
| 1327 |
* The calling thread is blocked |
| 1328 |
* until a reply is received. See |
| 1329 |
* polkit_authority_register_authentication_agent_with_options() for the |
| 1330 |
* asynchronous version. |
| 1331 |
* |
| 1332 |
* Returns: %TRUE if the authentication agent was successfully registered, %FALSE if @error is set. |
| 1333 |
**/ |
| 1334 |
gboolean |
| 1335 |
polkit_authority_register_authentication_agent_with_options_sync (PolkitAuthority *authority, |
| 1336 |
PolkitSubject *subject, |
| 1337 |
const gchar *locale, |
| 1338 |
const gchar *object_path, |
| 1339 |
GVariant *options, |
| 1340 |
GCancellable *cancellable, |
| 1341 |
GError **error) |
| 1342 |
{ |
| 1343 |
gboolean ret; |
| 1344 |
CallSyncData *data; |
| 1345 |
|
| 1346 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), FALSE); |
| 1347 |
g_return_val_if_fail (POLKIT_IS_SUBJECT (subject), FALSE); |
| 1348 |
g_return_val_if_fail (locale != NULL, FALSE); |
| 1349 |
g_return_val_if_fail (g_variant_is_object_path (object_path), FALSE); |
| 1350 |
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE); |
| 1351 |
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1352 |
|
| 1353 |
data = call_sync_new (); |
| 1354 |
polkit_authority_register_authentication_agent_with_options (authority, subject, locale, object_path, options, cancellable, call_sync_cb, data); |
| 1355 |
call_sync_block (data); |
| 1356 |
ret = polkit_authority_register_authentication_agent_with_options_finish (authority, data->res, error); |
| 1357 |
call_sync_free (data); |
| 1358 |
|
| 1359 |
return ret; |
| 1360 |
} |
| 1361 |
|
| 1362 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 1363 |
|
| 1364 |
/** |
| 1365 |
* polkit_authority_unregister_authentication_agent: |
| 1366 |
* @authority: A #PolkitAuthority. |
| 1367 |
* @subject: The subject the authentication agent is for, typically a #PolkitUnixSession object. |
| 1368 |
* @object_path: The object path for the authentication agent. |
| 1369 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 1370 |
* @callback: A #GAsyncReadyCallback to call when the request is satisfied. |
| 1371 |
* @user_data: The data to pass to @callback. |
| 1372 |
* |
| 1373 |
* Asynchronously unregisters an authentication agent. |
| 1374 |
* |
| 1375 |
* When the operation is finished, @callback will be invoked in the |
| 1376 |
* <link linkend="g-main-context-push-thread-default">thread-default |
| 1377 |
* main loop</link> of the thread you are calling this method |
| 1378 |
* from. You can then call |
| 1379 |
* polkit_authority_unregister_authentication_agent_finish() to get |
| 1380 |
* the result of the operation. |
| 1381 |
**/ |
| 1382 |
void |
| 1383 |
polkit_authority_unregister_authentication_agent (PolkitAuthority *authority, |
| 1384 |
PolkitSubject *subject, |
| 1385 |
const gchar *object_path, |
| 1386 |
GCancellable *cancellable, |
| 1387 |
GAsyncReadyCallback callback, |
| 1388 |
gpointer user_data) |
| 1389 |
{ |
| 1390 |
g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); |
| 1391 |
g_return_if_fail (POLKIT_IS_SUBJECT (subject)); |
| 1392 |
g_return_if_fail (g_variant_is_object_path (object_path)); |
| 1393 |
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); |
| 1394 |
|
| 1395 |
g_dbus_proxy_call (authority->proxy, |
| 1396 |
"UnregisterAuthenticationAgent", |
| 1397 |
g_variant_new ("(@(sa{sv})s)", |
| 1398 |
polkit_subject_to_gvariant (subject), /* A floating value */ |
| 1399 |
object_path), |
| 1400 |
G_DBUS_CALL_FLAGS_NONE, |
| 1401 |
-1, |
| 1402 |
cancellable, |
| 1403 |
generic_async_cb, |
| 1404 |
g_simple_async_result_new (G_OBJECT (authority), |
| 1405 |
callback, |
| 1406 |
user_data, |
| 1407 |
polkit_authority_unregister_authentication_agent)); |
| 1408 |
} |
| 1409 |
|
| 1410 |
/** |
| 1411 |
* polkit_authority_unregister_authentication_agent_finish: |
| 1412 |
* @authority: A #PolkitAuthority. |
| 1413 |
* @res: A #GAsyncResult obtained from the callback. |
| 1414 |
* @error: (allow-none): Return location for error or %NULL. |
| 1415 |
* |
| 1416 |
* Finishes unregistering an authentication agent. |
| 1417 |
* |
| 1418 |
* Returns: %TRUE if the authentication agent was successfully unregistered, %FALSE if @error is set. |
| 1419 |
**/ |
| 1420 |
gboolean |
| 1421 |
polkit_authority_unregister_authentication_agent_finish (PolkitAuthority *authority, |
| 1422 |
GAsyncResult *res, |
| 1423 |
GError **error) |
| 1424 |
{ |
| 1425 |
gboolean ret; |
| 1426 |
GVariant *value; |
| 1427 |
GAsyncResult *_res; |
| 1428 |
|
| 1429 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), FALSE); |
| 1430 |
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE); |
| 1431 |
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1432 |
|
| 1433 |
ret = FALSE; |
| 1434 |
|
| 1435 |
g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == polkit_authority_unregister_authentication_agent); |
| 1436 |
_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); |
| 1437 |
|
| 1438 |
value = g_dbus_proxy_call_finish (authority->proxy, _res, error); |
| 1439 |
if (value == NULL) |
| 1440 |
goto out; |
| 1441 |
ret = TRUE; |
| 1442 |
g_variant_unref (value); |
| 1443 |
|
| 1444 |
out: |
| 1445 |
return ret; |
| 1446 |
} |
| 1447 |
|
| 1448 |
|
| 1449 |
/** |
| 1450 |
* polkit_authority_unregister_authentication_agent_sync: |
| 1451 |
* @authority: A #PolkitAuthority. |
| 1452 |
* @subject: The subject the authentication agent is for, typically a #PolkitUnixSession object. |
| 1453 |
* @object_path: The object path for the authentication agent. |
| 1454 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 1455 |
* @error: (allow-none): Return location for error or %NULL. |
| 1456 |
* |
| 1457 |
* Unregisters an authentication agent. The calling thread is blocked |
| 1458 |
* until a reply is received. See |
| 1459 |
* polkit_authority_unregister_authentication_agent() for the |
| 1460 |
* asynchronous version. |
| 1461 |
* |
| 1462 |
* Returns: %TRUE if the authentication agent was successfully unregistered, %FALSE if @error is set. |
| 1463 |
**/ |
| 1464 |
gboolean |
| 1465 |
polkit_authority_unregister_authentication_agent_sync (PolkitAuthority *authority, |
| 1466 |
PolkitSubject *subject, |
| 1467 |
const gchar *object_path, |
| 1468 |
GCancellable *cancellable, |
| 1469 |
GError **error) |
| 1470 |
{ |
| 1471 |
gboolean ret; |
| 1472 |
CallSyncData *data; |
| 1473 |
|
| 1474 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), FALSE); |
| 1475 |
g_return_val_if_fail (POLKIT_IS_SUBJECT (subject), FALSE); |
| 1476 |
g_return_val_if_fail (g_variant_is_object_path (object_path), FALSE); |
| 1477 |
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE); |
| 1478 |
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1479 |
|
| 1480 |
data = call_sync_new (); |
| 1481 |
polkit_authority_unregister_authentication_agent (authority, subject, object_path, cancellable, call_sync_cb, data); |
| 1482 |
call_sync_block (data); |
| 1483 |
ret = polkit_authority_unregister_authentication_agent_finish (authority, data->res, error); |
| 1484 |
call_sync_free (data); |
| 1485 |
|
| 1486 |
return ret; |
| 1487 |
} |
| 1488 |
|
| 1489 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 1490 |
|
| 1491 |
/** |
| 1492 |
* polkit_authority_authentication_agent_response_with_subject: (finish-func polkit_authority_authentication_agent_response_finish) |
| 1493 |
* @authority: A #PolkitAuthority. |
| 1494 |
* @cookie: The cookie passed to the authentication agent from the authority. |
| 1495 |
* @identity: The identity that was authenticated. |
| 1496 |
* @subject: The subject that requested the authentication. |
| 1497 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 1498 |
* @callback: A #GAsyncReadyCallback to call when the request is satisfied. |
| 1499 |
* @user_data: The data to pass to @callback. |
| 1500 |
* |
| 1501 |
* Asynchronously provide response that @identity successfully authenticated |
| 1502 |
* for the authentication request identified by @cookie as requested by @subject. |
| 1503 |
* |
| 1504 |
* This function is only used by the socket-activated agent helper, running as uiid |
| 1505 |
* 0, and will fail otherwise. The requesting process is identified via @subject |
| 1506 |
* which will contain a PID FD identifying the process. |
| 1507 |
* |
| 1508 |
* When the operation is finished, @callback will be invoked in the |
| 1509 |
* <link linkend="g-main-context-push-thread-default">thread-default |
| 1510 |
* main loop</link> of the thread you are calling this method |
| 1511 |
* from. You can then call |
| 1512 |
* polkit_authority_authentication_agent_response_finish() to get the |
| 1513 |
* result of the operation. |
| 1514 |
**/ |
| 1515 |
void |
| 1516 |
polkit_authority_authentication_agent_response_with_subject (PolkitAuthority *authority, |
| 1517 |
const gchar *cookie, |
| 1518 |
PolkitIdentity *identity, |
| 1519 |
PolkitSubject *subject, |
| 1520 |
GCancellable *cancellable, |
| 1521 |
GAsyncReadyCallback callback, |
| 1522 |
gpointer user_data) |
| 1523 |
{ |
| 1524 |
/* Unlike the polkit_authority_authentication_agent_response variant, |
| 1525 |
* this one is called from a socket-activated service, rather than a |
| 1526 |
* setuid helper invoked directly by the authenticating process. |
| 1527 |
*/ |
| 1528 |
g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); |
| 1529 |
g_return_if_fail (cookie != NULL); |
| 1530 |
g_return_if_fail (POLKIT_IS_IDENTITY (identity)); |
| 1531 |
g_return_if_fail (POLKIT_IS_SUBJECT (subject)); |
| 1532 |
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); |
| 1533 |
|
| 1534 |
g_dbus_proxy_call (authority->proxy, |
| 1535 |
"AuthenticationAgentResponse3", |
| 1536 |
g_variant_new ("(s@(sa{sv})@(sa{sv}))", |
| 1537 |
cookie, |
| 1538 |
polkit_identity_to_gvariant (identity), /* Floating value */ |
| 1539 |
polkit_subject_to_gvariant (subject)), /* Floating value */ |
| 1540 |
G_DBUS_CALL_FLAGS_NONE, |
| 1541 |
-1, |
| 1542 |
cancellable, |
| 1543 |
generic_async_cb, |
| 1544 |
g_simple_async_result_new (G_OBJECT (authority), |
| 1545 |
callback, |
| 1546 |
user_data, |
| 1547 |
polkit_authority_authentication_agent_response)); |
| 1548 |
} |
| 1549 |
|
| 1550 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 1551 |
|
| 1552 |
/** |
| 1553 |
* polkit_authority_authentication_agent_response: |
| 1554 |
* @authority: A #PolkitAuthority. |
| 1555 |
* @cookie: The cookie passed to the authentication agent from the authority. |
| 1556 |
* @identity: The identity that was authenticated. |
| 1557 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 1558 |
* @callback: A #GAsyncReadyCallback to call when the request is satisfied. |
| 1559 |
* @user_data: The data to pass to @callback. |
| 1560 |
* |
| 1561 |
* Asynchronously provide response that @identity successfully authenticated |
| 1562 |
* for the authentication request identified by @cookie. |
| 1563 |
* |
| 1564 |
* This function is only used by the privileged bits of an authentication agent. |
| 1565 |
* It will fail if the caller is not sufficiently privileged (typically uid 0). |
| 1566 |
* |
| 1567 |
* When the operation is finished, @callback will be invoked in the |
| 1568 |
* <link linkend="g-main-context-push-thread-default">thread-default |
| 1569 |
* main loop</link> of the thread you are calling this method |
| 1570 |
* from. You can then call |
| 1571 |
* polkit_authority_authentication_agent_response_finish() to get the |
| 1572 |
* result of the operation. |
| 1573 |
**/ |
| 1574 |
void |
| 1575 |
polkit_authority_authentication_agent_response (PolkitAuthority *authority, |
| 1576 |
const gchar *cookie, |
| 1577 |
PolkitIdentity *identity, |
| 1578 |
GCancellable *cancellable, |
| 1579 |
GAsyncReadyCallback callback, |
| 1580 |
gpointer user_data) |
| 1581 |
{ |
| 1582 |
/* Note that in reality, this API is only accessible to root, and |
| 1583 |
* only called from the setuid helper `polkit-agent-helper-1`. |
| 1584 |
* |
| 1585 |
* However, because this is currently public API, we avoid |
| 1586 |
* triggering warnings from ABI diff type programs by just grabbing |
| 1587 |
* the real uid of the caller here. |
| 1588 |
*/ |
| 1589 |
uid_t uid = getuid (); |
| 1590 |
|
| 1591 |
g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); |
| 1592 |
g_return_if_fail (cookie != NULL); |
| 1593 |
g_return_if_fail (POLKIT_IS_IDENTITY (identity)); |
| 1594 |
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); |
| 1595 |
|
| 1596 |
g_dbus_proxy_call (authority->proxy, |
| 1597 |
"AuthenticationAgentResponse2", |
| 1598 |
g_variant_new ("(us@(sa{sv}))", |
| 1599 |
(guint32)uid, |
| 1600 |
cookie, |
| 1601 |
polkit_identity_to_gvariant (identity)), /* A floating value */ |
| 1602 |
G_DBUS_CALL_FLAGS_NONE, |
| 1603 |
-1, |
| 1604 |
cancellable, |
| 1605 |
generic_async_cb, |
| 1606 |
g_simple_async_result_new (G_OBJECT (authority), |
| 1607 |
callback, |
| 1608 |
user_data, |
| 1609 |
polkit_authority_authentication_agent_response)); |
| 1610 |
} |
| 1611 |
|
| 1612 |
/** |
| 1613 |
* polkit_authority_authentication_agent_response_finish: |
| 1614 |
* @authority: A #PolkitAuthority. |
| 1615 |
* @res: A #GAsyncResult obtained from the callback. |
| 1616 |
* @error: (allow-none): Return location for error or %NULL. |
| 1617 |
* |
| 1618 |
* Finishes providing response from an authentication agent. |
| 1619 |
* |
| 1620 |
* Returns: %TRUE if @authority acknowledged the call, %FALSE if @error is set. |
| 1621 |
**/ |
| 1622 |
gboolean |
| 1623 |
polkit_authority_authentication_agent_response_finish (PolkitAuthority *authority, |
| 1624 |
GAsyncResult *res, |
| 1625 |
GError **error) |
| 1626 |
{ |
| 1627 |
gboolean ret; |
| 1628 |
GVariant *value; |
| 1629 |
GAsyncResult *_res; |
| 1630 |
|
| 1631 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), FALSE); |
| 1632 |
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE); |
| 1633 |
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1634 |
|
| 1635 |
ret = FALSE; |
| 1636 |
|
| 1637 |
g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == polkit_authority_authentication_agent_response); |
| 1638 |
_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); |
| 1639 |
|
| 1640 |
value = g_dbus_proxy_call_finish (authority->proxy, _res, error); |
| 1641 |
if (value == NULL) |
| 1642 |
goto out; |
| 1643 |
ret = TRUE; |
| 1644 |
g_variant_unref (value); |
| 1645 |
|
| 1646 |
out: |
| 1647 |
return ret; |
| 1648 |
} |
| 1649 |
|
| 1650 |
|
| 1651 |
/** |
| 1652 |
* polkit_authority_authentication_agent_response_sync: |
| 1653 |
* @authority: A #PolkitAuthority. |
| 1654 |
* @cookie: The cookie passed to the authentication agent from the authority. |
| 1655 |
* @identity: The identity that was authenticated. |
| 1656 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 1657 |
* @error: (allow-none): Return location for error or %NULL. |
| 1658 |
* |
| 1659 |
* Provide response that @identity successfully authenticated for the |
| 1660 |
* authentication request identified by @cookie. See polkit_authority_authentication_agent_response() |
| 1661 |
* for limitations on who is allowed is to call this method. |
| 1662 |
* |
| 1663 |
* The calling thread is blocked until a reply is received. See |
| 1664 |
* polkit_authority_authentication_agent_response() for the |
| 1665 |
* asynchronous version. |
| 1666 |
* |
| 1667 |
* Returns: %TRUE if @authority acknowledged the call, %FALSE if @error is set. |
| 1668 |
**/ |
| 1669 |
gboolean |
| 1670 |
polkit_authority_authentication_agent_response_sync (PolkitAuthority *authority, |
| 1671 |
const gchar *cookie, |
| 1672 |
PolkitIdentity *identity, |
| 1673 |
GCancellable *cancellable, |
| 1674 |
GError **error) |
| 1675 |
{ |
| 1676 |
gboolean ret; |
| 1677 |
CallSyncData *data; |
| 1678 |
|
| 1679 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), FALSE); |
| 1680 |
g_return_val_if_fail (cookie != NULL, FALSE); |
| 1681 |
g_return_val_if_fail (POLKIT_IS_IDENTITY (identity), FALSE); |
| 1682 |
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE); |
| 1683 |
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1684 |
|
| 1685 |
data = call_sync_new (); |
| 1686 |
polkit_authority_authentication_agent_response (authority, cookie, identity, cancellable, call_sync_cb, data); |
| 1687 |
call_sync_block (data); |
| 1688 |
ret = polkit_authority_authentication_agent_response_finish (authority, data->res, error); |
| 1689 |
call_sync_free (data); |
| 1690 |
|
| 1691 |
return ret; |
| 1692 |
} |
| 1693 |
|
| 1694 |
|
| 1695 |
/** |
| 1696 |
* polkit_authority_authentication_agent_response_with_subject_sync: |
| 1697 |
* @authority: A #PolkitAuthority. |
| 1698 |
* @cookie: The cookie passed to the authentication agent from the authority. |
| 1699 |
* @identity: The identity that was authenticated. |
| 1700 |
* @subject: The subject that requested the authentication. |
| 1701 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 1702 |
* @error: (allow-none): Return location for error or %NULL. |
| 1703 |
* |
| 1704 |
* Provide response that @identity successfully authenticated for the |
| 1705 |
* authentication request identified by @cookie. See polkit_authority_authentication_agent_response_with_subject() |
| 1706 |
* for limitations on who is allowed is to call this method. |
| 1707 |
* |
| 1708 |
* The calling thread is blocked until a reply is received. See |
| 1709 |
* polkit_authority_authentication_agent_response_with_subject() for the |
| 1710 |
* asynchronous version. |
| 1711 |
* |
| 1712 |
* Returns: %TRUE if @authority acknowledged the call, %FALSE if @error is set. |
| 1713 |
**/ |
| 1714 |
gboolean |
| 1715 |
polkit_authority_authentication_agent_response_with_subject_sync (PolkitAuthority *authority, |
| 1716 |
const gchar *cookie, |
| 1717 |
PolkitIdentity *identity, |
| 1718 |
PolkitSubject *subject, |
| 1719 |
GCancellable *cancellable, |
| 1720 |
GError **error) |
| 1721 |
{ |
| 1722 |
gboolean ret; |
| 1723 |
CallSyncData *data; |
| 1724 |
|
| 1725 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), FALSE); |
| 1726 |
g_return_val_if_fail (cookie != NULL, FALSE); |
| 1727 |
g_return_val_if_fail (POLKIT_IS_IDENTITY (identity), FALSE); |
| 1728 |
g_return_val_if_fail (POLKIT_IS_SUBJECT (subject), FALSE); |
| 1729 |
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE); |
| 1730 |
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1731 |
|
| 1732 |
data = call_sync_new (); |
| 1733 |
polkit_authority_authentication_agent_response_with_subject (authority, cookie, identity, subject, cancellable, call_sync_cb, data); |
| 1734 |
call_sync_block (data); |
| 1735 |
ret = polkit_authority_authentication_agent_response_finish (authority, data->res, error); |
| 1736 |
call_sync_free (data); |
| 1737 |
|
| 1738 |
return ret; |
| 1739 |
} |
| 1740 |
|
| 1741 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 1742 |
|
| 1743 |
/** |
| 1744 |
* polkit_authority_enumerate_temporary_authorizations: |
| 1745 |
* @authority: A #PolkitAuthority. |
| 1746 |
* @subject: A #PolkitSubject, typically a #PolkitUnixSession. |
| 1747 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 1748 |
* @callback: A #GAsyncReadyCallback to call when the request is satisfied. |
| 1749 |
* @user_data: The data to pass to @callback. |
| 1750 |
* |
| 1751 |
* Asynchronously gets all temporary authorizations for @subject. |
| 1752 |
* |
| 1753 |
* When the operation is finished, @callback will be invoked in the |
| 1754 |
* <link linkend="g-main-context-push-thread-default">thread-default |
| 1755 |
* main loop</link> of the thread you are calling this method |
| 1756 |
* from. You can then call |
| 1757 |
* polkit_authority_enumerate_temporary_authorizations_finish() to get |
| 1758 |
* the result of the operation. |
| 1759 |
**/ |
| 1760 |
void |
| 1761 |
polkit_authority_enumerate_temporary_authorizations (PolkitAuthority *authority, |
| 1762 |
PolkitSubject *subject, |
| 1763 |
GCancellable *cancellable, |
| 1764 |
GAsyncReadyCallback callback, |
| 1765 |
gpointer user_data) |
| 1766 |
{ |
| 1767 |
g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); |
| 1768 |
g_return_if_fail (POLKIT_IS_SUBJECT (subject)); |
| 1769 |
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); |
| 1770 |
|
| 1771 |
g_dbus_proxy_call (authority->proxy, |
| 1772 |
"EnumerateTemporaryAuthorizations", |
| 1773 |
g_variant_new ("(@(sa{sv}))", |
| 1774 |
polkit_subject_to_gvariant (subject)), /* A floating value */ |
| 1775 |
G_DBUS_CALL_FLAGS_NONE, |
| 1776 |
-1, |
| 1777 |
cancellable, |
| 1778 |
generic_async_cb, |
| 1779 |
g_simple_async_result_new (G_OBJECT (authority), |
| 1780 |
callback, |
| 1781 |
user_data, |
| 1782 |
polkit_authority_enumerate_temporary_authorizations)); |
| 1783 |
} |
| 1784 |
|
| 1785 |
/** |
| 1786 |
* polkit_authority_enumerate_temporary_authorizations_finish: |
| 1787 |
* @authority: A #PolkitAuthority. |
| 1788 |
* @res: A #GAsyncResult obtained from the callback. |
| 1789 |
* @error: (allow-none): Return location for error or %NULL. |
| 1790 |
* |
| 1791 |
* Finishes retrieving all registered actions. |
| 1792 |
* |
| 1793 |
* Returns: (element-type Polkit.TemporaryAuthorization) (transfer full): A |
| 1794 |
* list of #PolkitTemporaryAuthorization objects or %NULL if @error is set. The |
| 1795 |
* returned list should be freed with g_list_free() after each element have |
| 1796 |
* been freed with g_object_unref(). |
| 1797 |
**/ |
| 1798 |
GList * |
| 1799 |
polkit_authority_enumerate_temporary_authorizations_finish (PolkitAuthority *authority, |
| 1800 |
GAsyncResult *res, |
| 1801 |
GError **error) |
| 1802 |
{ |
| 1803 |
GList *ret; |
| 1804 |
GVariant *value; |
| 1805 |
GVariantIter iter; |
| 1806 |
GVariant *child; |
| 1807 |
GVariant *array; |
| 1808 |
GAsyncResult *_res; |
| 1809 |
|
| 1810 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), NULL); |
| 1811 |
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), NULL); |
| 1812 |
g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 1813 |
|
| 1814 |
ret = NULL; |
| 1815 |
|
| 1816 |
g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == polkit_authority_enumerate_temporary_authorizations); |
| 1817 |
_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); |
| 1818 |
|
| 1819 |
value = g_dbus_proxy_call_finish (authority->proxy, _res, error); |
| 1820 |
if (value == NULL) |
| 1821 |
goto out; |
| 1822 |
|
| 1823 |
array = g_variant_get_child_value (value, 0); |
| 1824 |
g_variant_iter_init (&iter, array); |
| 1825 |
while ((child = g_variant_iter_next_value (&iter)) != NULL) |
| 1826 |
{ |
| 1827 |
PolkitTemporaryAuthorization *auth; |
| 1828 |
auth = polkit_temporary_authorization_new_for_gvariant (child, error); |
| 1829 |
g_variant_unref (child); |
| 1830 |
if (auth == NULL) |
| 1831 |
{ |
| 1832 |
g_prefix_error (error, "Error serializing return value of EnumerateTemporaryAuthorizations: "); |
| 1833 |
g_list_foreach (ret, (GFunc) g_object_unref, NULL); |
| 1834 |
g_list_free (ret); |
| 1835 |
ret = NULL; |
| 1836 |
goto out_array; |
| 1837 |
} |
| 1838 |
ret = g_list_prepend (ret, auth); |
| 1839 |
} |
| 1840 |
ret = g_list_reverse (ret); |
| 1841 |
out_array: |
| 1842 |
g_variant_unref (array); |
| 1843 |
g_variant_unref (value); |
| 1844 |
|
| 1845 |
out: |
| 1846 |
return ret; |
| 1847 |
} |
| 1848 |
|
| 1849 |
/** |
| 1850 |
* polkit_authority_enumerate_temporary_authorizations_sync: |
| 1851 |
* @authority: A #PolkitAuthority. |
| 1852 |
* @subject: A #PolkitSubject, typically a #PolkitUnixSession. |
| 1853 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 1854 |
* @error: (allow-none): Return location for error or %NULL. |
| 1855 |
* |
| 1856 |
* Synchronousky gets all temporary authorizations for @subject. |
| 1857 |
* |
| 1858 |
* The calling thread is blocked until a reply is received. See |
| 1859 |
* polkit_authority_enumerate_temporary_authorizations() for the |
| 1860 |
* asynchronous version. |
| 1861 |
* |
| 1862 |
* Returns: (element-type Polkit.TemporaryAuthorization) (transfer full): A |
| 1863 |
* list of #PolkitTemporaryAuthorization objects or %NULL if @error is set. The |
| 1864 |
* returned list should be freed with g_list_free() after each element have |
| 1865 |
* been freed with g_object_unref(). |
| 1866 |
**/ |
| 1867 |
GList * |
| 1868 |
polkit_authority_enumerate_temporary_authorizations_sync (PolkitAuthority *authority, |
| 1869 |
PolkitSubject *subject, |
| 1870 |
GCancellable *cancellable, |
| 1871 |
GError **error) |
| 1872 |
{ |
| 1873 |
GList *ret; |
| 1874 |
CallSyncData *data; |
| 1875 |
|
| 1876 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), NULL); |
| 1877 |
g_return_val_if_fail (POLKIT_IS_SUBJECT (subject), NULL); |
| 1878 |
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL); |
| 1879 |
g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
| 1880 |
|
| 1881 |
data = call_sync_new (); |
| 1882 |
polkit_authority_enumerate_temporary_authorizations (authority, subject, cancellable, call_sync_cb, data); |
| 1883 |
call_sync_block (data); |
| 1884 |
ret = polkit_authority_enumerate_temporary_authorizations_finish (authority, data->res, error); |
| 1885 |
call_sync_free (data); |
| 1886 |
|
| 1887 |
return ret; |
| 1888 |
} |
| 1889 |
|
| 1890 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 1891 |
|
| 1892 |
/** |
| 1893 |
* polkit_authority_revoke_temporary_authorizations: |
| 1894 |
* @authority: A #PolkitAuthority. |
| 1895 |
* @subject: The subject to revoke authorizations from, typically a #PolkitUnixSession. |
| 1896 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 1897 |
* @callback: A #GAsyncReadyCallback to call when the request is satisfied. |
| 1898 |
* @user_data: The data to pass to @callback. |
| 1899 |
* |
| 1900 |
* Asynchronously revokes all temporary authorizations for @subject. |
| 1901 |
* |
| 1902 |
* When the operation is finished, @callback will be invoked in the |
| 1903 |
* <link linkend="g-main-context-push-thread-default">thread-default |
| 1904 |
* main loop</link> of the thread you are calling this method |
| 1905 |
* from. You can then call |
| 1906 |
* polkit_authority_revoke_temporary_authorizations_finish() to get |
| 1907 |
* the result of the operation. |
| 1908 |
**/ |
| 1909 |
void |
| 1910 |
polkit_authority_revoke_temporary_authorizations (PolkitAuthority *authority, |
| 1911 |
PolkitSubject *subject, |
| 1912 |
GCancellable *cancellable, |
| 1913 |
GAsyncReadyCallback callback, |
| 1914 |
gpointer user_data) |
| 1915 |
{ |
| 1916 |
g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); |
| 1917 |
g_return_if_fail (POLKIT_IS_SUBJECT (subject)); |
| 1918 |
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); |
| 1919 |
|
| 1920 |
g_dbus_proxy_call (authority->proxy, |
| 1921 |
"RevokeTemporaryAuthorizations", |
| 1922 |
g_variant_new ("(@(sa{sv}))", |
| 1923 |
polkit_subject_to_gvariant (subject)), /* A floating value */ |
| 1924 |
G_DBUS_CALL_FLAGS_NONE, |
| 1925 |
-1, |
| 1926 |
cancellable, |
| 1927 |
generic_async_cb, |
| 1928 |
g_simple_async_result_new (G_OBJECT (authority), |
| 1929 |
callback, |
| 1930 |
user_data, |
| 1931 |
polkit_authority_revoke_temporary_authorizations)); |
| 1932 |
} |
| 1933 |
|
| 1934 |
/** |
| 1935 |
* polkit_authority_revoke_temporary_authorizations_finish: |
| 1936 |
* @authority: A #PolkitAuthority. |
| 1937 |
* @res: A #GAsyncResult obtained from the callback. |
| 1938 |
* @error: (allow-none): Return location for error or %NULL. |
| 1939 |
* |
| 1940 |
* Finishes revoking temporary authorizations. |
| 1941 |
* |
| 1942 |
* Returns: %TRUE if all the temporary authorizations was revoked, %FALSE if error is set. |
| 1943 |
**/ |
| 1944 |
gboolean |
| 1945 |
polkit_authority_revoke_temporary_authorizations_finish (PolkitAuthority *authority, |
| 1946 |
GAsyncResult *res, |
| 1947 |
GError **error) |
| 1948 |
{ |
| 1949 |
gboolean ret; |
| 1950 |
GVariant *value; |
| 1951 |
GAsyncResult *_res; |
| 1952 |
|
| 1953 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), FALSE); |
| 1954 |
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE); |
| 1955 |
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 1956 |
|
| 1957 |
ret = FALSE; |
| 1958 |
|
| 1959 |
g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == polkit_authority_revoke_temporary_authorizations); |
| 1960 |
_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); |
| 1961 |
|
| 1962 |
value = g_dbus_proxy_call_finish (authority->proxy, _res, error); |
| 1963 |
if (value == NULL) |
| 1964 |
goto out; |
| 1965 |
ret = TRUE; |
| 1966 |
g_variant_unref (value); |
| 1967 |
|
| 1968 |
out: |
| 1969 |
return ret; |
| 1970 |
} |
| 1971 |
|
| 1972 |
/** |
| 1973 |
* polkit_authority_revoke_temporary_authorizations_sync: |
| 1974 |
* @authority: A #PolkitAuthority. |
| 1975 |
* @subject: The subject to revoke authorizations from, typically a #PolkitUnixSession. |
| 1976 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 1977 |
* @error: (allow-none): Return location for error or %NULL. |
| 1978 |
* |
| 1979 |
* Synchronously revokes all temporary authorization from @subject. |
| 1980 |
* |
| 1981 |
* The calling thread is blocked until a reply is received. See |
| 1982 |
* polkit_authority_revoke_temporary_authorizations() for the |
| 1983 |
* asynchronous version. |
| 1984 |
* |
| 1985 |
* Returns: %TRUE if the temporary authorization was revoked, %FALSE if error is set. |
| 1986 |
**/ |
| 1987 |
gboolean |
| 1988 |
polkit_authority_revoke_temporary_authorizations_sync (PolkitAuthority *authority, |
| 1989 |
PolkitSubject *subject, |
| 1990 |
GCancellable *cancellable, |
| 1991 |
GError **error) |
| 1992 |
{ |
| 1993 |
gboolean ret; |
| 1994 |
CallSyncData *data; |
| 1995 |
|
| 1996 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), FALSE); |
| 1997 |
g_return_val_if_fail (POLKIT_IS_SUBJECT (subject), FALSE); |
| 1998 |
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE); |
| 1999 |
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 2000 |
|
| 2001 |
data = call_sync_new (); |
| 2002 |
polkit_authority_revoke_temporary_authorizations (authority, subject, cancellable, call_sync_cb, data); |
| 2003 |
call_sync_block (data); |
| 2004 |
ret = polkit_authority_revoke_temporary_authorizations_finish (authority, data->res, error); |
| 2005 |
call_sync_free (data); |
| 2006 |
|
| 2007 |
return ret; |
| 2008 |
} |
| 2009 |
|
| 2010 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 2011 |
|
| 2012 |
/** |
| 2013 |
* polkit_authority_revoke_temporary_authorization_by_id: |
| 2014 |
* @authority: A #PolkitAuthority. |
| 2015 |
* @id: The opaque identifier for the temporary authorization. |
| 2016 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 2017 |
* @callback: A #GAsyncReadyCallback to call when the request is satisfied. |
| 2018 |
* @user_data: The data to pass to @callback. |
| 2019 |
* |
| 2020 |
* Asynchronously revoke a temporary authorization. |
| 2021 |
* |
| 2022 |
* When the operation is finished, @callback will be invoked in the |
| 2023 |
* <link linkend="g-main-context-push-thread-default">thread-default |
| 2024 |
* main loop</link> of the thread you are calling this method |
| 2025 |
* from. You can then call |
| 2026 |
* polkit_authority_revoke_temporary_authorization_by_id_finish() to |
| 2027 |
* get the result of the operation. |
| 2028 |
*/ |
| 2029 |
void |
| 2030 |
polkit_authority_revoke_temporary_authorization_by_id (PolkitAuthority *authority, |
| 2031 |
const gchar *id, |
| 2032 |
GCancellable *cancellable, |
| 2033 |
GAsyncReadyCallback callback, |
| 2034 |
gpointer user_data) |
| 2035 |
{ |
| 2036 |
g_return_if_fail (POLKIT_IS_AUTHORITY (authority)); |
| 2037 |
g_return_if_fail (id != NULL); |
| 2038 |
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); |
| 2039 |
|
| 2040 |
g_dbus_proxy_call (authority->proxy, |
| 2041 |
"RevokeTemporaryAuthorizationById", |
| 2042 |
g_variant_new ("(s)", |
| 2043 |
id), |
| 2044 |
G_DBUS_CALL_FLAGS_NONE, |
| 2045 |
-1, |
| 2046 |
cancellable, |
| 2047 |
generic_async_cb, |
| 2048 |
g_simple_async_result_new (G_OBJECT (authority), |
| 2049 |
callback, |
| 2050 |
user_data, |
| 2051 |
polkit_authority_revoke_temporary_authorization_by_id)); |
| 2052 |
} |
| 2053 |
|
| 2054 |
/** |
| 2055 |
* polkit_authority_revoke_temporary_authorization_by_id_finish: |
| 2056 |
* @authority: A #PolkitAuthority. |
| 2057 |
* @res: A #GAsyncResult obtained from the callback. |
| 2058 |
* @error: (allow-none): Return location for error or %NULL. |
| 2059 |
* |
| 2060 |
* Finishes revoking a temporary authorization by id. |
| 2061 |
* |
| 2062 |
* Returns: %TRUE if the temporary authorization was revoked, %FALSE if error is set. |
| 2063 |
**/ |
| 2064 |
gboolean |
| 2065 |
polkit_authority_revoke_temporary_authorization_by_id_finish (PolkitAuthority *authority, |
| 2066 |
GAsyncResult *res, |
| 2067 |
GError **error) |
| 2068 |
{ |
| 2069 |
gboolean ret; |
| 2070 |
GVariant *value; |
| 2071 |
GAsyncResult *_res; |
| 2072 |
|
| 2073 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), FALSE); |
| 2074 |
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), FALSE); |
| 2075 |
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 2076 |
|
| 2077 |
ret = FALSE; |
| 2078 |
|
| 2079 |
g_warn_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) == polkit_authority_revoke_temporary_authorization_by_id); |
| 2080 |
_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))); |
| 2081 |
|
| 2082 |
value = g_dbus_proxy_call_finish (authority->proxy, _res, error); |
| 2083 |
if (value == NULL) |
| 2084 |
goto out; |
| 2085 |
ret = TRUE; |
| 2086 |
g_variant_unref (value); |
| 2087 |
|
| 2088 |
out: |
| 2089 |
return ret; |
| 2090 |
} |
| 2091 |
|
| 2092 |
/** |
| 2093 |
* polkit_authority_revoke_temporary_authorization_by_id_sync: |
| 2094 |
* @authority: A #PolkitAuthority. |
| 2095 |
* @id: The opaque identifier for the temporary authorization. |
| 2096 |
* @cancellable: (allow-none): A #GCancellable or %NULL. |
| 2097 |
* @error: (allow-none): Return location for error or %NULL. |
| 2098 |
* |
| 2099 |
* Synchronously revokes a temporary authorization. |
| 2100 |
* |
| 2101 |
* The calling thread is blocked until a reply is received. See |
| 2102 |
* polkit_authority_revoke_temporary_authorization_by_id() for the |
| 2103 |
* asynchronous version. |
| 2104 |
* |
| 2105 |
* Returns: %TRUE if the temporary authorization was revoked, %FALSE if error is set. |
| 2106 |
**/ |
| 2107 |
gboolean |
| 2108 |
polkit_authority_revoke_temporary_authorization_by_id_sync (PolkitAuthority *authority, |
| 2109 |
const gchar *id, |
| 2110 |
GCancellable *cancellable, |
| 2111 |
GError **error) |
| 2112 |
{ |
| 2113 |
gboolean ret; |
| 2114 |
CallSyncData *data; |
| 2115 |
|
| 2116 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), FALSE); |
| 2117 |
g_return_val_if_fail (id != NULL, FALSE); |
| 2118 |
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE); |
| 2119 |
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); |
| 2120 |
|
| 2121 |
data = call_sync_new (); |
| 2122 |
polkit_authority_revoke_temporary_authorization_by_id (authority, id, cancellable, call_sync_cb, data); |
| 2123 |
call_sync_block (data); |
| 2124 |
ret = polkit_authority_revoke_temporary_authorization_by_id_finish (authority, data->res, error); |
| 2125 |
call_sync_free (data); |
| 2126 |
|
| 2127 |
return ret; |
| 2128 |
} |
| 2129 |
|
| 2130 |
/* ---------------------------------------------------------------------------------------------------- */ |
| 2131 |
|
| 2132 |
/** |
| 2133 |
* polkit_authority_get_owner: |
| 2134 |
* @authority: A #PolkitAuthority. |
| 2135 |
* |
| 2136 |
* The unique name on the system message bus of the owner of the name |
| 2137 |
* <literal>org.freedesktop.PolicyKit1</literal> or %NULL if no-one |
| 2138 |
* currently owns the name. You may connect to the #GObject::notify |
| 2139 |
* signal to track changes to the #PolkitAuthority:owner property. |
| 2140 |
* |
| 2141 |
* Returns: (allow-none): %NULL or a string that should be freed with g_free(). |
| 2142 |
**/ |
| 2143 |
gchar * |
| 2144 |
polkit_authority_get_owner (PolkitAuthority *authority) |
| 2145 |
{ |
| 2146 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), NULL); |
| 2147 |
return g_dbus_proxy_get_name_owner (authority->proxy); |
| 2148 |
} |
| 2149 |
|
| 2150 |
/** |
| 2151 |
* polkit_authority_get_backend_name: |
| 2152 |
* @authority: A #PolkitAuthority. |
| 2153 |
* |
| 2154 |
* Gets the name of the authority backend. |
| 2155 |
* |
| 2156 |
* Returns: The name of the backend. |
| 2157 |
*/ |
| 2158 |
const gchar * |
| 2159 |
polkit_authority_get_backend_name (PolkitAuthority *authority) |
| 2160 |
{ |
| 2161 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), NULL); |
| 2162 |
if (authority->name == NULL) |
| 2163 |
{ |
| 2164 |
GVariant *value; |
| 2165 |
value = g_dbus_proxy_get_cached_property (authority->proxy, "BackendName"); |
| 2166 |
authority->name = g_variant_dup_string (value, NULL); |
| 2167 |
g_variant_unref (value); |
| 2168 |
} |
| 2169 |
return authority->name; |
| 2170 |
} |
| 2171 |
|
| 2172 |
/** |
| 2173 |
* polkit_authority_get_backend_version: |
| 2174 |
* @authority: A #PolkitAuthority. |
| 2175 |
* |
| 2176 |
* Gets the version of the authority backend. |
| 2177 |
* |
| 2178 |
* Returns: The version string for the backend. |
| 2179 |
*/ |
| 2180 |
const gchar * |
| 2181 |
polkit_authority_get_backend_version (PolkitAuthority *authority) |
| 2182 |
{ |
| 2183 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), NULL); |
| 2184 |
if (authority->version == NULL) |
| 2185 |
{ |
| 2186 |
GVariant *value; |
| 2187 |
value = g_dbus_proxy_get_cached_property (authority->proxy, "BackendVersion"); |
| 2188 |
authority->version = g_variant_dup_string (value, NULL); |
| 2189 |
g_variant_unref (value); |
| 2190 |
} |
| 2191 |
return authority->version; |
| 2192 |
} |
| 2193 |
|
| 2194 |
/** |
| 2195 |
* polkit_authority_get_backend_features: |
| 2196 |
* @authority: A #PolkitAuthority. |
| 2197 |
* |
| 2198 |
* Gets the features supported by the authority backend. |
| 2199 |
* |
| 2200 |
* Returns: Flags from #PolkitAuthorityFeatures. |
| 2201 |
*/ |
| 2202 |
PolkitAuthorityFeatures |
| 2203 |
polkit_authority_get_backend_features (PolkitAuthority *authority) |
| 2204 |
{ |
| 2205 |
PolkitAuthorityFeatures ret; |
| 2206 |
GVariant *value; |
| 2207 |
|
| 2208 |
g_return_val_if_fail (POLKIT_IS_AUTHORITY (authority), 0); |
| 2209 |
|
| 2210 |
value = g_dbus_proxy_get_cached_property (authority->proxy, "BackendFeatures"); |
| 2211 |
ret = (PolkitAuthorityFeatures) g_variant_get_uint32 (value); |
| 2212 |
g_variant_unref (value); |
| 2213 |
|
| 2214 |
return ret; |
| 2215 |
} |