| 1 |
diff -up GConf-2.26.2/configure.in.polkit1 GConf-2.26.2/configure.in
|
| 2 |
--- GConf-2.26.2/configure.in.polkit1 2009-05-14 11:18:34.000000000 -0400
|
| 3 |
+++ GConf-2.26.2/configure.in 2009-06-12 13:00:27.978836073 -0400
|
| 4 |
@@ -181,7 +181,7 @@ AC_ARG_ENABLE(defaults_service,
|
| 5 |
, enable_defaults_service=auto)
|
| 6 |
|
| 7 |
if test "x$enable_defaults_service" != "xno" ; then
|
| 8 |
- PKG_CHECK_MODULES(DEFAULTS, glib-2.0 gobject-2.0 dbus-1 dbus-glib-1 polkit-dbus, HAVE_POLKIT=yes)
|
| 9 |
+ PKG_CHECK_MODULES(DEFAULTS, glib-2.0 gobject-2.0 dbus-1 dbus-glib-1 polkit-gobject-1, HAVE_POLKIT=yes)
|
| 10 |
if test "x$HAVE_POLKIT" = "xno"; then
|
| 11 |
if test "x$enable_defaults_service" = "xyes" ; then
|
| 12 |
AC_MSG_ERROR([[
|
| 13 |
@@ -194,13 +194,6 @@ fi
|
| 14 |
|
| 15 |
if test "x$enable_defaults_service" != "xno" ; then
|
| 16 |
AC_DEFINE(ENABLE_DEFAULTS_SERVICE, 1, [enable defaults DBus service])
|
| 17 |
-
|
| 18 |
- AC_CHECK_PROG([POLKIT_POLICY_FILE_VALIDATE],
|
| 19 |
- [polkit-policy-file-validate], [polkit-policy-file-validate])
|
| 20 |
-
|
| 21 |
- if test -z "$POLKIT_POLICY_FILE_VALIDATE"; then
|
| 22 |
- AC_MSG_ERROR([polkit-policy-file-validate not found])
|
| 23 |
- fi
|
| 24 |
fi
|
| 25 |
|
| 26 |
AM_CONDITIONAL(ENABLE_DEFAULTS_SERVICE, [test "x$enable_defaults_service" != "xno"])
|
| 27 |
diff -up GConf-2.26.2/defaults/gconf-defaults.c.polkit1 GConf-2.26.2/defaults/gconf-defaults.c
|
| 28 |
--- GConf-2.26.2/defaults/gconf-defaults.c.polkit1 2009-05-14 11:13:40.000000000 -0400
|
| 29 |
+++ GConf-2.26.2/defaults/gconf-defaults.c 2009-06-12 14:21:50.117398713 -0400
|
| 30 |
@@ -1,6 +1,6 @@
|
| 31 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
| 32 |
*
|
| 33 |
- * Copyright (C) 2008 Matthias Clasen <mclasen@redhat.com>
|
| 34 |
+ * Copyright (C) 2008, 2009 Matthias Clasen <mclasen@redhat.com>
|
| 35 |
*
|
| 36 |
* This program is free software; you can redistribute it and/or modify
|
| 37 |
* it under the terms of the GNU General Public License as published by
|
| 38 |
@@ -37,7 +37,6 @@
|
| 39 |
#include <dbus/dbus-glib.h>
|
| 40 |
#include <dbus/dbus-glib-lowlevel.h>
|
| 41 |
|
| 42 |
-#include <polkit-dbus/polkit-dbus.h>
|
| 43 |
#include <polkit/polkit.h>
|
| 44 |
|
| 45 |
#define GCONF_ENABLE_INTERNALS
|
| 46 |
@@ -56,10 +55,14 @@ do_exit (gpointer user_data)
|
| 47 |
}
|
| 48 |
|
| 49 |
static guint timer_id = 0;
|
| 50 |
+gboolean disable_killtimer = FALSE;
|
| 51 |
|
| 52 |
static void
|
| 53 |
stop_killtimer (void)
|
| 54 |
{
|
| 55 |
+ if (disable_killtimer)
|
| 56 |
+ return;
|
| 57 |
+
|
| 58 |
if (timer_id > 0) {
|
| 59 |
g_source_remove (timer_id);
|
| 60 |
timer_id = 0;
|
| 61 |
@@ -69,15 +72,38 @@ stop_killtimer (void)
|
| 62 |
static void
|
| 63 |
start_killtimer (void)
|
| 64 |
{
|
| 65 |
- g_debug ("Setting killtimer to 30 seconds...");
|
| 66 |
- timer_id = g_timeout_add_seconds (30, do_exit, NULL);
|
| 67 |
+ if (disable_killtimer)
|
| 68 |
+ return;
|
| 69 |
+
|
| 70 |
+ if (timer_id == 0) {
|
| 71 |
+ g_debug ("Setting killtimer to 30 seconds...");
|
| 72 |
+ timer_id = g_timeout_add_seconds (30, do_exit, NULL);
|
| 73 |
+ }
|
| 74 |
+}
|
| 75 |
+
|
| 76 |
+static gint operations = 0;
|
| 77 |
+
|
| 78 |
+static void
|
| 79 |
+start_operation (void)
|
| 80 |
+{
|
| 81 |
+ if (operations == 0)
|
| 82 |
+ stop_killtimer ();
|
| 83 |
+ operations++;
|
| 84 |
+}
|
| 85 |
+
|
| 86 |
+static void
|
| 87 |
+stop_operation (void)
|
| 88 |
+{
|
| 89 |
+ if (operations == 1)
|
| 90 |
+ start_killtimer ();
|
| 91 |
+ operations --;
|
| 92 |
}
|
| 93 |
|
| 94 |
struct GConfDefaultsPrivate
|
| 95 |
{
|
| 96 |
DBusGConnection *system_bus_connection;
|
| 97 |
DBusGProxy *system_bus_proxy;
|
| 98 |
- PolKitContext *pol_ctx;
|
| 99 |
+ PolkitAuthority *auth;
|
| 100 |
};
|
| 101 |
|
| 102 |
static void gconf_defaults_finalize (GObject *object);
|
| 103 |
@@ -105,7 +131,7 @@ GType
|
| 104 |
gconf_defaults_error_get_type (void)
|
| 105 |
{
|
| 106 |
static GType etype = 0;
|
| 107 |
-
|
| 108 |
+
|
| 109 |
if (etype == 0)
|
| 110 |
{
|
| 111 |
static const GEnumValue values[] =
|
| 112 |
@@ -114,12 +140,12 @@ gconf_defaults_error_get_type (void)
|
| 113 |
ENUM_ENTRY (GCONF_DEFAULTS_ERROR_NOT_PRIVILEGED, "NotPrivileged"),
|
| 114 |
{ 0, 0, 0 }
|
| 115 |
};
|
| 116 |
-
|
| 117 |
+
|
| 118 |
g_assert (GCONF_DEFAULTS_NUM_ERRORS == G_N_ELEMENTS (values) - 1);
|
| 119 |
-
|
| 120 |
+
|
| 121 |
etype = g_enum_register_static ("GConfDefaultsError", values);
|
| 122 |
}
|
| 123 |
-
|
| 124 |
+
|
| 125 |
return etype;
|
| 126 |
}
|
| 127 |
|
| 128 |
@@ -191,56 +217,18 @@ gconf_defaults_finalize (GObject *object
|
| 129 |
|
| 130 |
g_return_if_fail (mechanism->priv != NULL);
|
| 131 |
|
| 132 |
+ g_object_unref (mechanism->priv->auth);
|
| 133 |
g_object_unref (mechanism->priv->system_bus_proxy);
|
| 134 |
|
| 135 |
G_OBJECT_CLASS (gconf_defaults_parent_class)->finalize (object);
|
| 136 |
}
|
| 137 |
|
| 138 |
static gboolean
|
| 139 |
-pk_io_watch_have_data (GIOChannel *channel, GIOCondition condition, gpointer user_data)
|
| 140 |
-{
|
| 141 |
- int fd;
|
| 142 |
- PolKitContext *pk_context = user_data;
|
| 143 |
- fd = g_io_channel_unix_get_fd (channel);
|
| 144 |
- polkit_context_io_func (pk_context, fd);
|
| 145 |
- return TRUE;
|
| 146 |
-}
|
| 147 |
-
|
| 148 |
-static int
|
| 149 |
-pk_io_add_watch (PolKitContext *pk_context, int fd)
|
| 150 |
-{
|
| 151 |
- guint id = 0;
|
| 152 |
- GIOChannel *channel;
|
| 153 |
- channel = g_io_channel_unix_new (fd);
|
| 154 |
- if (channel == NULL)
|
| 155 |
- goto out;
|
| 156 |
- id = g_io_add_watch (channel, G_IO_IN, pk_io_watch_have_data, pk_context);
|
| 157 |
- if (id == 0) {
|
| 158 |
- g_io_channel_unref (channel);
|
| 159 |
- goto out;
|
| 160 |
- }
|
| 161 |
- g_io_channel_unref (channel);
|
| 162 |
-out:
|
| 163 |
- return id;
|
| 164 |
-}
|
| 165 |
-
|
| 166 |
-static void
|
| 167 |
-pk_io_remove_watch (PolKitContext *pk_context, int watch_id)
|
| 168 |
-{
|
| 169 |
- g_source_remove (watch_id);
|
| 170 |
-}
|
| 171 |
-
|
| 172 |
-static gboolean
|
| 173 |
register_mechanism (GConfDefaults *mechanism)
|
| 174 |
{
|
| 175 |
GError *error = NULL;
|
| 176 |
|
| 177 |
- mechanism->priv->pol_ctx = polkit_context_new ();
|
| 178 |
- polkit_context_set_io_watch_functions (mechanism->priv->pol_ctx, pk_io_add_watch, pk_io_remove_watch);
|
| 179 |
- if (!polkit_context_init (mechanism->priv->pol_ctx, NULL)) {
|
| 180 |
- g_critical ("cannot initialize libpolkit");
|
| 181 |
- goto error;
|
| 182 |
- }
|
| 183 |
+ mechanism->priv->auth = polkit_authority_get ();
|
| 184 |
|
| 185 |
error = NULL;
|
| 186 |
mechanism->priv->system_bus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
|
| 187 |
@@ -252,7 +240,7 @@ register_mechanism (GConfDefaults *mecha
|
| 188 |
goto error;
|
| 189 |
}
|
| 190 |
|
| 191 |
- dbus_g_connection_register_g_object (mechanism->priv->system_bus_connection, "/",
|
| 192 |
+ dbus_g_connection_register_g_object (mechanism->priv->system_bus_connection, "/",
|
| 193 |
G_OBJECT (mechanism));
|
| 194 |
|
| 195 |
mechanism->priv->system_bus_proxy = dbus_g_proxy_new_for_name (mechanism->priv->system_bus_connection,
|
| 196 |
@@ -288,33 +276,37 @@ gconf_defaults_new (void)
|
| 197 |
|
| 198 |
static const char *
|
| 199 |
polkit_action_for_gconf_path (GConfDefaults *mechanism,
|
| 200 |
+ GList *action_descriptions,
|
| 201 |
const char *annotation_key,
|
| 202 |
const char *path)
|
| 203 |
{
|
| 204 |
- PolKitPolicyCache *cache;
|
| 205 |
- PolKitPolicyFileEntry *entry;
|
| 206 |
char *prefix, *p;
|
| 207 |
const char *action;
|
| 208 |
+ GList *l;
|
| 209 |
+ PolkitActionDescription *action_description;
|
| 210 |
+ const gchar *annotation;
|
| 211 |
|
| 212 |
- cache = polkit_context_get_policy_cache (mechanism->priv->pol_ctx);
|
| 213 |
prefix = g_strdup (path);
|
| 214 |
|
| 215 |
while (1) {
|
| 216 |
- entry = polkit_policy_cache_get_entry_by_annotation (cache,
|
| 217 |
- annotation_key,
|
| 218 |
- prefix);
|
| 219 |
- if (entry) {
|
| 220 |
- action = polkit_policy_file_entry_get_id (entry);
|
| 221 |
- break;
|
| 222 |
+ for (l = action_descriptions; l; l = l->next) {
|
| 223 |
+ action_description = l->data;
|
| 224 |
+
|
| 225 |
+ annotation = polkit_action_description_get_annotation (action_description, annotation_key);
|
| 226 |
+ if (g_strcmp0 (prefix, annotation) == 0) {
|
| 227 |
+ action = polkit_action_description_get_action_id (action_description);
|
| 228 |
+ g_debug ("action for path '%s': '%s'\n", action, path);
|
| 229 |
+ break;
|
| 230 |
+ }
|
| 231 |
}
|
| 232 |
-
|
| 233 |
+
|
| 234 |
p = strrchr (prefix, '/');
|
| 235 |
|
| 236 |
if (p == NULL || p == prefix) {
|
| 237 |
action = NULL;
|
| 238 |
break;
|
| 239 |
}
|
| 240 |
-
|
| 241 |
+
|
| 242 |
*p = 0;
|
| 243 |
}
|
| 244 |
|
| 245 |
@@ -323,56 +315,160 @@ polkit_action_for_gconf_path (GConfDefau
|
| 246 |
return action;
|
| 247 |
}
|
| 248 |
|
| 249 |
-static gboolean
|
| 250 |
-check_polkit_for_action (GConfDefaults *mechanism,
|
| 251 |
- DBusGMethodInvocation *context,
|
| 252 |
- const char *action)
|
| 253 |
-{
|
| 254 |
- const char *sender;
|
| 255 |
- GError *error;
|
| 256 |
- DBusError dbus_error;
|
| 257 |
- PolKitCaller *pk_caller;
|
| 258 |
- PolKitAction *pk_action;
|
| 259 |
- PolKitResult pk_result;
|
| 260 |
+static void
|
| 261 |
+throw_error (DBusGMethodInvocation *context,
|
| 262 |
+ gint error_code,
|
| 263 |
+ const gchar *format,
|
| 264 |
+ ...)
|
| 265 |
+{
|
| 266 |
+ GError *error;
|
| 267 |
+ va_list args;
|
| 268 |
+ gchar *message;
|
| 269 |
|
| 270 |
- error = NULL;
|
| 271 |
+ va_start (args, format);
|
| 272 |
+ message = g_strdup_vprintf (format, args);
|
| 273 |
+ va_end (args);
|
| 274 |
+
|
| 275 |
+ error = g_error_new (GCONF_DEFAULTS_ERROR,
|
| 276 |
+ error_code,
|
| 277 |
+ "%s", message);
|
| 278 |
+ dbus_g_method_return_error (context, error);
|
| 279 |
+ g_error_free (error);
|
| 280 |
+ g_free (message);
|
| 281 |
+}
|
| 282 |
+
|
| 283 |
+typedef void (*AuthObtainedCallback) (GConfDefaults *mechanism,
|
| 284 |
+ DBusGMethodInvocation *context,
|
| 285 |
+ gpointer user_data);
|
| 286 |
+
|
| 287 |
+typedef struct
|
| 288 |
+{
|
| 289 |
+ GConfDefaults *mechanism;
|
| 290 |
+ DBusGMethodInvocation *context;
|
| 291 |
+ gchar **actions;
|
| 292 |
+ gint id;
|
| 293 |
+ gint flags;
|
| 294 |
+ AuthObtainedCallback auth_obtained_callback;
|
| 295 |
+ GAsyncReadyCallback check_auth_callback;
|
| 296 |
+ gpointer user_data;
|
| 297 |
+ GDestroyNotify destroy;
|
| 298 |
+ PolkitSubject *subject;
|
| 299 |
+ gboolean challenge;
|
| 300 |
+} CheckAuthData;
|
| 301 |
|
| 302 |
- /* Check that caller is privileged */
|
| 303 |
- sender = dbus_g_method_get_sender (context);
|
| 304 |
- dbus_error_init (&dbus_error);
|
| 305 |
- pk_caller = polkit_caller_new_from_dbus_name (
|
| 306 |
- dbus_g_connection_get_connection (mechanism->priv->system_bus_connection),
|
| 307 |
- sender,
|
| 308 |
- &dbus_error);
|
| 309 |
- if (pk_caller == NULL) {
|
| 310 |
- error = g_error_new (GCONF_DEFAULTS_ERROR,
|
| 311 |
- GCONF_DEFAULTS_ERROR_GENERAL,
|
| 312 |
- "Error getting information about caller: %s: %s",
|
| 313 |
- dbus_error.name, dbus_error.message);
|
| 314 |
- dbus_error_free (&dbus_error);
|
| 315 |
- dbus_g_method_return_error (context, error);
|
| 316 |
- g_error_free (error);
|
| 317 |
- return FALSE;
|
| 318 |
- }
|
| 319 |
+static void
|
| 320 |
+check_auth_data_free (CheckAuthData *data)
|
| 321 |
+{
|
| 322 |
+ g_object_unref (data->mechanism);
|
| 323 |
+ g_strfreev (data->actions);
|
| 324 |
+ if (data->destroy)
|
| 325 |
+ data->destroy (data->user_data);
|
| 326 |
+ g_object_unref (data->subject);
|
| 327 |
+ g_free (data);
|
| 328 |
+}
|
| 329 |
|
| 330 |
- pk_action = polkit_action_new ();
|
| 331 |
- polkit_action_set_action_id (pk_action, action);
|
| 332 |
- pk_result = polkit_context_is_caller_authorized (mechanism->priv->pol_ctx, pk_action, pk_caller, TRUE, NULL);
|
| 333 |
- polkit_caller_unref (pk_caller);
|
| 334 |
-
|
| 335 |
- if (pk_result != POLKIT_RESULT_YES) {
|
| 336 |
- dbus_error_init (&dbus_error);
|
| 337 |
- polkit_dbus_error_generate (pk_action, pk_result, &dbus_error);
|
| 338 |
- dbus_set_g_error (&error, &dbus_error);
|
| 339 |
- dbus_g_method_return_error (context, error);
|
| 340 |
- dbus_error_free (&dbus_error);
|
| 341 |
- g_error_free (error);
|
| 342 |
- polkit_action_unref (pk_action);
|
| 343 |
- return FALSE;
|
| 344 |
- }
|
| 345 |
+static void check_next_action (CheckAuthData *data);
|
| 346 |
|
| 347 |
- polkit_action_unref (pk_action);
|
| 348 |
- return TRUE;
|
| 349 |
+static void
|
| 350 |
+check_authorization_callback (PolkitAuthority *authority,
|
| 351 |
+ GAsyncResult *res,
|
| 352 |
+ gpointer user_data)
|
| 353 |
+{
|
| 354 |
+ CheckAuthData *data = user_data;
|
| 355 |
+ PolkitAuthorizationResult *result;
|
| 356 |
+ GError *error;
|
| 357 |
+ gboolean is_authorized;
|
| 358 |
+
|
| 359 |
+ is_authorized = FALSE;
|
| 360 |
+
|
| 361 |
+ error = NULL;
|
| 362 |
+ result = polkit_authority_check_authorization_finish (authority,
|
| 363 |
+ res,
|
| 364 |
+ &error);
|
| 365 |
+ if (error != NULL) {
|
| 366 |
+ g_debug ("error checking action '%s'\n", error->message);
|
| 367 |
+ throw_error (data->context,
|
| 368 |
+ GCONF_DEFAULTS_ERROR_NOT_PRIVILEGED,
|
| 369 |
+ "Not Authorized: %s", error->message);
|
| 370 |
+ g_error_free (error);
|
| 371 |
+ }
|
| 372 |
+ else {
|
| 373 |
+ if (polkit_authorization_result_get_is_authorized (result)) {
|
| 374 |
+ g_debug ("result for '%s': authorized\n",
|
| 375 |
+ data->actions[data->id]);
|
| 376 |
+ is_authorized = TRUE;
|
| 377 |
+ }
|
| 378 |
+ else if (polkit_authorization_result_get_is_challenge (result)) {
|
| 379 |
+ g_debug ("result for '%s': challenge\n",
|
| 380 |
+ data->actions[data->id]);
|
| 381 |
+ throw_error (data->context,
|
| 382 |
+ GCONF_DEFAULTS_ERROR_NOT_PRIVILEGED,
|
| 383 |
+ "Authorization is required");
|
| 384 |
+ }
|
| 385 |
+ else {
|
| 386 |
+ g_debug ("result for '%s': not authorized\n",
|
| 387 |
+ data->actions[data->id]);
|
| 388 |
+ throw_error (data->context,
|
| 389 |
+ GCONF_DEFAULTS_ERROR_NOT_PRIVILEGED,
|
| 390 |
+ "Not Authorized");
|
| 391 |
+ }
|
| 392 |
+ }
|
| 393 |
+
|
| 394 |
+ if (is_authorized) {
|
| 395 |
+ data->id++;
|
| 396 |
+ if (data->actions[data->id] == NULL)
|
| 397 |
+ data->auth_obtained_callback (data->mechanism,
|
| 398 |
+ data->context,
|
| 399 |
+ data->user_data);
|
| 400 |
+ else {
|
| 401 |
+ check_next_action (data);
|
| 402 |
+ return; /* continue operation */
|
| 403 |
+ }
|
| 404 |
+ }
|
| 405 |
+
|
| 406 |
+ check_auth_data_free (data);
|
| 407 |
+ g_object_unref (result);
|
| 408 |
+ stop_operation ();
|
| 409 |
+}
|
| 410 |
+
|
| 411 |
+static void
|
| 412 |
+check_next_action (CheckAuthData *data)
|
| 413 |
+{
|
| 414 |
+ g_debug ("checking action '%s'\n", data->actions[data->id]);
|
| 415 |
+ polkit_authority_check_authorization (data->mechanism->priv->auth,
|
| 416 |
+ data->subject,
|
| 417 |
+ data->actions[data->id],
|
| 418 |
+ NULL,
|
| 419 |
+ data->flags,
|
| 420 |
+ NULL,
|
| 421 |
+ data->check_auth_callback,
|
| 422 |
+ data);
|
| 423 |
+}
|
| 424 |
+
|
| 425 |
+static void
|
| 426 |
+check_polkit_for_actions (GConfDefaults *mechanism,
|
| 427 |
+ DBusGMethodInvocation *context,
|
| 428 |
+ gchar **actions,
|
| 429 |
+ AuthObtainedCallback auth_obtained_callback,
|
| 430 |
+ gpointer user_data,
|
| 431 |
+ GDestroyNotify destroy)
|
| 432 |
+{
|
| 433 |
+ CheckAuthData *data;
|
| 434 |
+
|
| 435 |
+ data = g_new0 (CheckAuthData, 1);
|
| 436 |
+ data->mechanism = g_object_ref (mechanism);
|
| 437 |
+ data->context = context;
|
| 438 |
+ data->actions = actions;
|
| 439 |
+ data->flags = POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION;
|
| 440 |
+ data->id = 0;
|
| 441 |
+ data->auth_obtained_callback = auth_obtained_callback;
|
| 442 |
+ data->check_auth_callback = (GAsyncReadyCallback)check_authorization_callback;
|
| 443 |
+ data->user_data = user_data;
|
| 444 |
+ data->destroy = destroy;
|
| 445 |
+ data->subject = polkit_system_bus_name_new (dbus_g_method_get_sender (context));
|
| 446 |
+ data->challenge = FALSE;
|
| 447 |
+
|
| 448 |
+ check_next_action (data);
|
| 449 |
}
|
| 450 |
|
| 451 |
static char *
|
| 452 |
@@ -398,11 +494,11 @@ gconf_address_for_caller (GConfDefaults
|
| 453 |
dbus_error_free (&error);
|
| 454 |
return NULL;
|
| 455 |
}
|
| 456 |
-
|
| 457 |
+
|
| 458 |
pwd = getpwuid (uid);
|
| 459 |
if (pwd == NULL) {
|
| 460 |
- g_set_error (gerror,
|
| 461 |
- 0, 0,
|
| 462 |
+ g_set_error (gerror,
|
| 463 |
+ 0, 0,
|
| 464 |
"Failed to get passwd information for uid %d", uid);
|
| 465 |
return NULL;
|
| 466 |
}
|
| 467 |
@@ -434,13 +530,13 @@ copy_tree (GConfClient *src,
|
| 468 |
GSList *list, *l;
|
| 469 |
GConfEntry *entry;
|
| 470 |
|
| 471 |
- if (path_is_excluded (path, excludes))
|
| 472 |
+ if (path_is_excluded (path, excludes))
|
| 473 |
return;
|
| 474 |
|
| 475 |
list = gconf_client_all_entries (src, path, NULL);
|
| 476 |
for (l = list; l; l = l->next) {
|
| 477 |
entry = l->data;
|
| 478 |
- if (!path_is_excluded (entry->key, excludes))
|
| 479 |
+ if (!path_is_excluded (entry->key, excludes))
|
| 480 |
gconf_change_set_set (changes, entry->key, entry->value);
|
| 481 |
}
|
| 482 |
g_slist_foreach (list, (GFunc)gconf_entry_free, NULL);
|
| 483 |
@@ -461,7 +557,7 @@ copy_entry (GConfClient *src,
|
| 484 |
{
|
| 485 |
GConfValue *value;
|
| 486 |
|
| 487 |
- if (path_is_excluded (path, excludes))
|
| 488 |
+ if (path_is_excluded (path, excludes))
|
| 489 |
return;
|
| 490 |
|
| 491 |
value = gconf_client_get (src, path, NULL);
|
| 492 |
@@ -471,69 +567,66 @@ copy_entry (GConfClient *src,
|
| 493 |
}
|
| 494 |
}
|
| 495 |
|
| 496 |
+typedef void (*ChangeSetCallback) (GConfDefaults *mechanism,
|
| 497 |
+ GConfChangeSet *changes,
|
| 498 |
+ gpointer data);
|
| 499 |
+
|
| 500 |
+typedef struct
|
| 501 |
+{
|
| 502 |
+ GConfDefaults *mechanism;
|
| 503 |
+ DBusGMethodInvocation *context;
|
| 504 |
+ const char *dest_address;
|
| 505 |
+ char **actions;
|
| 506 |
+ char **includes;
|
| 507 |
+ char **excludes;
|
| 508 |
+ ChangeSetCallback changeset_callback;
|
| 509 |
+ gpointer user_data;
|
| 510 |
+ GDestroyNotify destroy;
|
| 511 |
+} CopyData;
|
| 512 |
|
| 513 |
static void
|
| 514 |
-do_copy (GConfDefaults *mechanism,
|
| 515 |
- gboolean mandatory,
|
| 516 |
- const char **includes,
|
| 517 |
- const char **excludes,
|
| 518 |
- DBusGMethodInvocation *context,
|
| 519 |
- GConfChangeSet **changeset_out)
|
| 520 |
+copy_data_free (gpointer user_data)
|
| 521 |
{
|
| 522 |
- char *address = NULL;
|
| 523 |
- GConfClient *source = NULL;
|
| 524 |
+ CopyData *data = user_data;
|
| 525 |
+
|
| 526 |
+ g_object_unref (data->mechanism);
|
| 527 |
+ g_strfreev (data->includes);
|
| 528 |
+ g_strfreev (data->excludes);
|
| 529 |
+ g_strfreev (data->actions);
|
| 530 |
+ if (data->destroy)
|
| 531 |
+ data->destroy (data->user_data);
|
| 532 |
+ g_free (data);
|
| 533 |
+}
|
| 534 |
+
|
| 535 |
+static void
|
| 536 |
+do_copy_authorized (GConfDefaults *mechanism,
|
| 537 |
+ DBusGMethodInvocation *context,
|
| 538 |
+ gpointer user_data)
|
| 539 |
+{
|
| 540 |
+ CopyData *data = user_data;
|
| 541 |
+ GConfClient *source = NULL;
|
| 542 |
GConfClient *dest = NULL;
|
| 543 |
GConfChangeSet *changes = NULL;
|
| 544 |
GConfEngine *engine;
|
| 545 |
+ char *address = NULL;
|
| 546 |
+ gint i;
|
| 547 |
GError *error;
|
| 548 |
- GError *error2;
|
| 549 |
- const char *action;
|
| 550 |
- const char *annotation_key;
|
| 551 |
- const char *default_action;
|
| 552 |
- const char *dest_address;
|
| 553 |
- int i;
|
| 554 |
-
|
| 555 |
- if (changeset_out)
|
| 556 |
- *changeset_out = NULL;
|
| 557 |
-
|
| 558 |
- stop_killtimer ();
|
| 559 |
-
|
| 560 |
- /* check privileges for each include */
|
| 561 |
- if (mandatory) {
|
| 562 |
- annotation_key = "org.gnome.gconf.defaults.set-mandatory.prefix";
|
| 563 |
- default_action = "org.gnome.gconf.defaults.set-mandatory";
|
| 564 |
- dest_address = "xml:merged:" SYSGCONFDIR "/gconf.xml.mandatory";
|
| 565 |
- }
|
| 566 |
- else {
|
| 567 |
- annotation_key = "org.gnome.gconf.defaults.set-system.prefix";
|
| 568 |
- default_action = "org.gnome.gconf.defaults.set-system";
|
| 569 |
- dest_address = "xml:merged:" SYSGCONFDIR "/gconf.xml.system";
|
| 570 |
- }
|
| 571 |
-
|
| 572 |
- for (i = 0; includes[i]; i++) {
|
| 573 |
- action = polkit_action_for_gconf_path (mechanism, annotation_key, includes[i]);
|
| 574 |
- if (action == NULL)
|
| 575 |
- action = default_action;
|
| 576 |
-
|
| 577 |
- if (!check_polkit_for_action (mechanism, context, action))
|
| 578 |
- goto out;
|
| 579 |
- }
|
| 580 |
|
| 581 |
error = NULL;
|
| 582 |
- engine = gconf_engine_get_local (dest_address, &error);
|
| 583 |
- if (error)
|
| 584 |
- goto cleanup;
|
| 585 |
+ engine = gconf_engine_get_local (data->dest_address, &error);
|
| 586 |
+ if (error)
|
| 587 |
+ goto cleanup;
|
| 588 |
|
| 589 |
dest = gconf_client_get_for_engine (engine);
|
| 590 |
gconf_engine_unref (engine);
|
| 591 |
|
| 592 |
/* find the address to from the caller id */
|
| 593 |
- address = gconf_address_for_caller (mechanism, context, &error);
|
| 594 |
+ address = gconf_address_for_caller (data->mechanism, data->context, &error);
|
| 595 |
if (error)
|
| 596 |
goto cleanup;
|
| 597 |
|
| 598 |
engine = gconf_engine_get_local (address, &error);
|
| 599 |
- if (error)
|
| 600 |
+ if (error)
|
| 601 |
goto cleanup;
|
| 602 |
|
| 603 |
source = gconf_client_get_for_engine (engine);
|
| 604 |
@@ -542,45 +635,175 @@ do_copy (GConfDefaults *mechani
|
| 605 |
changes = gconf_change_set_new ();
|
| 606 |
|
| 607 |
/* recursively copy each include, leaving out the excludes */
|
| 608 |
- for (i = 0; includes[i]; i++) {
|
| 609 |
- if (gconf_client_dir_exists (source, includes[i], NULL))
|
| 610 |
- copy_tree (source, includes[i], changes, excludes);
|
| 611 |
+ for (i = 0; data->includes[i]; i++) {
|
| 612 |
+ if (gconf_client_dir_exists (source, data->includes[i], NULL))
|
| 613 |
+ copy_tree (source, data->includes[i], changes, (const char **)data->excludes);
|
| 614 |
else
|
| 615 |
- copy_entry (source, includes[i], changes, excludes);
|
| 616 |
+ copy_entry (source, data->includes[i], changes, (const char **)data->excludes);
|
| 617 |
}
|
| 618 |
|
| 619 |
gconf_client_commit_change_set (dest, changes, FALSE, &error);
|
| 620 |
gconf_client_suggest_sync (dest, NULL);
|
| 621 |
|
| 622 |
- if (changeset_out) {
|
| 623 |
- *changeset_out = changes;
|
| 624 |
- changes = NULL;
|
| 625 |
+ if (data->changeset_callback) {
|
| 626 |
+ data->changeset_callback (data->mechanism, changes, data->user_data);
|
| 627 |
}
|
| 628 |
|
| 629 |
cleanup:
|
| 630 |
g_free (address);
|
| 631 |
if (changes)
|
| 632 |
gconf_change_set_unref (changes);
|
| 633 |
- if (dest)
|
| 634 |
+ if (dest)
|
| 635 |
g_object_unref (dest);
|
| 636 |
if (source)
|
| 637 |
g_object_unref (source);
|
| 638 |
|
| 639 |
if (error) {
|
| 640 |
- g_print ("failed to set GConf values: %s\n", error->message);
|
| 641 |
- error2 = g_error_new_literal (GCONF_DEFAULTS_ERROR,
|
| 642 |
- GCONF_DEFAULTS_ERROR_GENERAL,
|
| 643 |
- error->message);
|
| 644 |
+ throw_error (data->context,
|
| 645 |
+ GCONF_DEFAULTS_ERROR_GENERAL,
|
| 646 |
+ "%s", error->message);
|
| 647 |
g_error_free (error);
|
| 648 |
-
|
| 649 |
- dbus_g_method_return_error (context, error2);
|
| 650 |
- g_error_free (error2);
|
| 651 |
}
|
| 652 |
else
|
| 653 |
- dbus_g_method_return (context);
|
| 654 |
+ dbus_g_method_return (data->context);
|
| 655 |
+}
|
| 656 |
|
| 657 |
-out:
|
| 658 |
- start_killtimer ();
|
| 659 |
+typedef void (*ActionsReadyCallback) (GConfDefaults *mechanism,
|
| 660 |
+ DBusGMethodInvocation *context,
|
| 661 |
+ gchar **actions,
|
| 662 |
+ AuthObtainedCallback auth_obtained_callback,
|
| 663 |
+ gpointer data,
|
| 664 |
+ GDestroyNotify destroy);
|
| 665 |
+
|
| 666 |
+typedef struct
|
| 667 |
+{
|
| 668 |
+ GConfDefaults *mechanism;
|
| 669 |
+ DBusGMethodInvocation *context;
|
| 670 |
+ char **includes;
|
| 671 |
+ const char *default_action;
|
| 672 |
+ const char *annotation_key;
|
| 673 |
+ ActionsReadyCallback actions_ready_callback;
|
| 674 |
+ AuthObtainedCallback auth_obtained_callback;
|
| 675 |
+ gpointer data;
|
| 676 |
+ GDestroyNotify destroy;
|
| 677 |
+} ActionData;
|
| 678 |
+
|
| 679 |
+static void
|
| 680 |
+action_data_free (ActionData *data)
|
| 681 |
+{
|
| 682 |
+ g_object_unref (data->mechanism);
|
| 683 |
+ g_strfreev (data->includes);
|
| 684 |
+ if (data->destroy)
|
| 685 |
+ data->destroy (data->data);
|
| 686 |
+ g_free (data);
|
| 687 |
+}
|
| 688 |
+
|
| 689 |
+static void
|
| 690 |
+actions_ready_cb (GObject *source,
|
| 691 |
+ GAsyncResult *res,
|
| 692 |
+ gpointer user_data)
|
| 693 |
+{
|
| 694 |
+ ActionData *data = user_data;
|
| 695 |
+ GList *action_descriptions;
|
| 696 |
+ GError *error = NULL;
|
| 697 |
+ int i;
|
| 698 |
+ GHashTable *obtained;
|
| 699 |
+ GHashTableIter iter;
|
| 700 |
+ const gchar *action;
|
| 701 |
+ gchar **actions;
|
| 702 |
+ gpointer key, value;
|
| 703 |
+
|
| 704 |
+ action_descriptions = polkit_authority_enumerate_actions_finish (data->mechanism->priv->auth, res, &error);
|
| 705 |
+
|
| 706 |
+ if (error) {
|
| 707 |
+ throw_error (data->context,
|
| 708 |
+ GCONF_DEFAULTS_ERROR_GENERAL,
|
| 709 |
+ "Failed to get action descriptions: %s", error->message);
|
| 710 |
+ g_error_free (error);
|
| 711 |
+ action_data_free (data);
|
| 712 |
+ stop_operation ();
|
| 713 |
+ return;
|
| 714 |
+ }
|
| 715 |
+
|
| 716 |
+ obtained = g_hash_table_new (g_str_hash, g_str_equal);
|
| 717 |
+
|
| 718 |
+ for (i = 0; data->includes[i]; i++) {
|
| 719 |
+ action = polkit_action_for_gconf_path (data->mechanism, action_descriptions, data->annotation_key, data->includes[i]);
|
| 720 |
+ if (action == NULL) {
|
| 721 |
+ g_debug ("using default action '%s' for path '%s'",
|
| 722 |
+ data->default_action, data->includes[i]);
|
| 723 |
+ action = data->default_action;
|
| 724 |
+ }
|
| 725 |
+
|
| 726 |
+ g_hash_table_insert (obtained, (gpointer)action, (gpointer)action);
|
| 727 |
+ }
|
| 728 |
+ actions = g_new0 (char *, g_hash_table_size (obtained) + 1);
|
| 729 |
+ g_hash_table_iter_init (&iter, obtained);
|
| 730 |
+ i = 0;
|
| 731 |
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
|
| 732 |
+ actions[i] = g_strdup ((char *)key);
|
| 733 |
+ i++;
|
| 734 |
+ }
|
| 735 |
+ g_hash_table_destroy (obtained);
|
| 736 |
+ g_list_foreach (action_descriptions, (GFunc)g_object_unref, NULL);
|
| 737 |
+ g_list_free (action_descriptions);
|
| 738 |
+
|
| 739 |
+ data->actions_ready_callback (data->mechanism, data->context, actions, data->auth_obtained_callback, data->data, data->destroy);
|
| 740 |
+
|
| 741 |
+ data->destroy = NULL;
|
| 742 |
+ action_data_free (data);
|
| 743 |
+}
|
| 744 |
+
|
| 745 |
+static void
|
| 746 |
+do_copy (GConfDefaults *mechanism,
|
| 747 |
+ gboolean mandatory,
|
| 748 |
+ const gchar **includes,
|
| 749 |
+ const gchar **excludes,
|
| 750 |
+ DBusGMethodInvocation *context,
|
| 751 |
+ ChangeSetCallback changeset_callback,
|
| 752 |
+ gpointer user_data,
|
| 753 |
+ GDestroyNotify destroy)
|
| 754 |
+{
|
| 755 |
+ CopyData *cdata;
|
| 756 |
+ ActionData *adata;
|
| 757 |
+
|
| 758 |
+ start_operation ();
|
| 759 |
+
|
| 760 |
+ cdata = g_new0 (CopyData, 1);
|
| 761 |
+ cdata->mechanism = g_object_ref (mechanism);
|
| 762 |
+ cdata->context = context;
|
| 763 |
+ cdata->includes = g_strdupv ((gchar **)includes);
|
| 764 |
+ cdata->excludes = g_strdupv ((gchar **)excludes);
|
| 765 |
+ cdata->actions = NULL;
|
| 766 |
+ cdata->changeset_callback = changeset_callback;
|
| 767 |
+ cdata->user_data = user_data;
|
| 768 |
+ cdata->destroy = destroy;
|
| 769 |
+
|
| 770 |
+ adata = g_new0 (ActionData, 1);
|
| 771 |
+ adata->mechanism = g_object_ref (mechanism);
|
| 772 |
+ adata->context = context;
|
| 773 |
+ adata->includes = g_strdupv ((gchar **)includes);
|
| 774 |
+ adata->actions_ready_callback = check_polkit_for_actions;
|
| 775 |
+ adata->auth_obtained_callback = do_copy_authorized;
|
| 776 |
+ adata->data = cdata;
|
| 777 |
+ adata->destroy = copy_data_free;
|
| 778 |
+
|
| 779 |
+ /* check privileges for each include */
|
| 780 |
+ if (mandatory) {
|
| 781 |
+ adata->annotation_key = "org.gnome.gconf.defaults.set-mandatory.prefix";
|
| 782 |
+ adata->default_action = "org.gnome.gconf.defaults.set-mandatory";
|
| 783 |
+ cdata->dest_address = "xml:merged:" SYSGCONFDIR "/gconf.xml.mandatory";
|
| 784 |
+ }
|
| 785 |
+ else {
|
| 786 |
+ adata->annotation_key = "org.gnome.gconf.defaults.set-system.prefix";
|
| 787 |
+ adata->default_action = "org.gnome.gconf.defaults.set-system";
|
| 788 |
+ cdata->dest_address = "xml:merged:" SYSGCONFDIR "/gconf.xml.system";
|
| 789 |
+ }
|
| 790 |
+
|
| 791 |
+ polkit_authority_enumerate_actions (mechanism->priv->auth,
|
| 792 |
+ NULL,
|
| 793 |
+ actions_ready_cb,
|
| 794 |
+ adata);
|
| 795 |
}
|
| 796 |
|
| 797 |
static void
|
| 798 |
@@ -594,20 +817,13 @@ append_key (GConfChangeSet *cs,
|
| 799 |
g_ptr_array_add (keys, (gpointer) key);
|
| 800 |
}
|
| 801 |
|
| 802 |
-void
|
| 803 |
-gconf_defaults_set_system (GConfDefaults *mechanism,
|
| 804 |
- const char **includes,
|
| 805 |
- const char **excludes,
|
| 806 |
- DBusGMethodInvocation *context)
|
| 807 |
+static void
|
| 808 |
+set_system_changes (GConfDefaults *mechanism,
|
| 809 |
+ GConfChangeSet *changes,
|
| 810 |
+ gpointer data)
|
| 811 |
{
|
| 812 |
- GConfChangeSet *changes = NULL;
|
| 813 |
GPtrArray *keys;
|
| 814 |
|
| 815 |
- do_copy (mechanism, FALSE, includes, excludes, context, &changes);
|
| 816 |
-
|
| 817 |
- if (!changes)
|
| 818 |
- return;
|
| 819 |
-
|
| 820 |
keys = g_ptr_array_new ();
|
| 821 |
gconf_change_set_foreach (changes, append_key, keys);
|
| 822 |
g_ptr_array_add (keys, NULL);
|
| 823 |
@@ -615,7 +831,15 @@ gconf_defaults_set_system (GConfDefaults
|
| 824 |
g_signal_emit (mechanism, signals[SYSTEM_SET], 0, keys->pdata);
|
| 825 |
|
| 826 |
g_ptr_array_free (keys, TRUE);
|
| 827 |
- gconf_change_set_unref (changes);
|
| 828 |
+}
|
| 829 |
+
|
| 830 |
+void
|
| 831 |
+gconf_defaults_set_system (GConfDefaults *mechanism,
|
| 832 |
+ const char **includes,
|
| 833 |
+ const char **excludes,
|
| 834 |
+ DBusGMethodInvocation *context)
|
| 835 |
+{
|
| 836 |
+ do_copy (mechanism, FALSE, includes, excludes, context, set_system_changes, NULL, NULL);
|
| 837 |
}
|
| 838 |
|
| 839 |
void
|
| 840 |
@@ -624,7 +848,7 @@ gconf_defaults_set_mandatory (GConfDefau
|
| 841 |
const char **excludes,
|
| 842 |
DBusGMethodInvocation *context)
|
| 843 |
{
|
| 844 |
- do_copy (mechanism, TRUE, includes, excludes, context, NULL);
|
| 845 |
+ do_copy (mechanism, TRUE, includes, excludes, context, NULL, NULL, NULL);
|
| 846 |
}
|
| 847 |
|
| 848 |
static void
|
| 849 |
@@ -636,13 +860,13 @@ unset_tree (GConfClient *dest,
|
| 850 |
GSList *list, *l;
|
| 851 |
GConfEntry *entry;
|
| 852 |
|
| 853 |
- if (path_is_excluded (path, excludes))
|
| 854 |
+ if (path_is_excluded (path, excludes))
|
| 855 |
return;
|
| 856 |
|
| 857 |
list = gconf_client_all_entries (dest, path, NULL);
|
| 858 |
for (l = list; l; l = l->next) {
|
| 859 |
entry = l->data;
|
| 860 |
- if (!path_is_excluded (entry->key, excludes))
|
| 861 |
+ if (!path_is_excluded (entry->key, excludes))
|
| 862 |
gconf_change_set_unset (changes, entry->key);
|
| 863 |
}
|
| 864 |
g_slist_foreach (list, (GFunc)gconf_entry_free, NULL);
|
| 865 |
@@ -654,25 +878,25 @@ unset_tree (GConfClient *dest,
|
| 866 |
g_slist_foreach (list, (GFunc)g_free, NULL);
|
| 867 |
g_slist_free (list);
|
| 868 |
}
|
| 869 |
-
|
| 870 |
+
|
| 871 |
static void
|
| 872 |
unset_entry (GConfClient *dest,
|
| 873 |
const char *path,
|
| 874 |
GConfChangeSet *changes,
|
| 875 |
const char **excludes)
|
| 876 |
{
|
| 877 |
- if (path_is_excluded (path, excludes))
|
| 878 |
+ if (path_is_excluded (path, excludes))
|
| 879 |
return;
|
| 880 |
|
| 881 |
gconf_change_set_unset (changes, path);
|
| 882 |
}
|
| 883 |
-
|
| 884 |
+
|
| 885 |
static void
|
| 886 |
-unset_in_db (GConfDefaults *mechanism,
|
| 887 |
- const char *address,
|
| 888 |
- const char **includes,
|
| 889 |
- const char **excludes,
|
| 890 |
- GError **error)
|
| 891 |
+unset_in_db (GConfDefaults *mechanism,
|
| 892 |
+ const gchar *address,
|
| 893 |
+ const gchar **includes,
|
| 894 |
+ const gchar **excludes,
|
| 895 |
+ GError **error)
|
| 896 |
{
|
| 897 |
GConfEngine *engine;
|
| 898 |
GConfClient *dest = NULL;
|
| 899 |
@@ -680,7 +904,7 @@ unset_in_db (GConfDefaults *mechanism,
|
| 900 |
int i;
|
| 901 |
|
| 902 |
engine = gconf_engine_get_local (address, error);
|
| 903 |
- if (*error)
|
| 904 |
+ if (*error)
|
| 905 |
goto out;
|
| 906 |
|
| 907 |
dest = gconf_client_get_for_engine (engine);
|
| 908 |
@@ -706,48 +930,224 @@ out:
|
| 909 |
gconf_change_set_unref (changes);
|
| 910 |
}
|
| 911 |
|
| 912 |
+typedef struct
|
| 913 |
+{
|
| 914 |
+ GConfDefaults *mechanism;
|
| 915 |
+ DBusGMethodInvocation *context;
|
| 916 |
+ char **includes;
|
| 917 |
+ char **excludes;
|
| 918 |
+} UnsetData;
|
| 919 |
+
|
| 920 |
+static void
|
| 921 |
+unset_data_free (gpointer user_data)
|
| 922 |
+{
|
| 923 |
+ UnsetData *data = user_data;
|
| 924 |
+
|
| 925 |
+ g_object_unref (data->mechanism);
|
| 926 |
+ g_strfreev (data->includes);
|
| 927 |
+ g_strfreev (data->excludes);
|
| 928 |
+ g_free (data);
|
| 929 |
+}
|
| 930 |
+
|
| 931 |
+static void
|
| 932 |
+do_unset_authorized (GConfDefaults *mechanism,
|
| 933 |
+ DBusGMethodInvocation *context,
|
| 934 |
+ gpointer user_data)
|
| 935 |
+{
|
| 936 |
+ UnsetData *data = user_data;
|
| 937 |
+ GError *error;
|
| 938 |
+
|
| 939 |
+ error = NULL;
|
| 940 |
+ unset_in_db (mechanism, "xml:merged:" SYSGCONFDIR "/gconf.xml.mandatory",
|
| 941 |
+ (const gchar **)data->includes,
|
| 942 |
+ (const gchar **)data->excludes, &error);
|
| 943 |
+
|
| 944 |
+ if (error) {
|
| 945 |
+ throw_error (data->context,
|
| 946 |
+ GCONF_DEFAULTS_ERROR,
|
| 947 |
+ GCONF_DEFAULTS_ERROR_GENERAL,
|
| 948 |
+ "%s", error->message);
|
| 949 |
+ g_error_free (error);
|
| 950 |
+ }
|
| 951 |
+ else
|
| 952 |
+ dbus_g_method_return (data->context);
|
| 953 |
+}
|
| 954 |
+
|
| 955 |
void
|
| 956 |
gconf_defaults_unset_mandatory (GConfDefaults *mechanism,
|
| 957 |
const char **includes,
|
| 958 |
const char **excludes,
|
| 959 |
DBusGMethodInvocation *context)
|
| 960 |
{
|
| 961 |
- const char *annotation_key;
|
| 962 |
- const char *default_action;
|
| 963 |
- int i;
|
| 964 |
- const char *action;
|
| 965 |
- GError *error;
|
| 966 |
- GError *error2;
|
| 967 |
+ UnsetData *udata;
|
| 968 |
+ ActionData *adata;
|
| 969 |
|
| 970 |
- stop_killtimer ();
|
| 971 |
+ start_operation ();
|
| 972 |
|
| 973 |
- annotation_key = "org.gnome.gconf.defaults.set-mandatory.prefix";
|
| 974 |
- default_action = "org.gnome.gconf.defaults.set-mandatory";
|
| 975 |
+ udata = g_new0 (UnsetData, 1);
|
| 976 |
+ udata->mechanism = g_object_ref (mechanism);
|
| 977 |
+ udata->context = context;
|
| 978 |
+ udata->includes = g_strdupv ((gchar **)includes);
|
| 979 |
+ udata->excludes = g_strdupv ((gchar **)excludes);
|
| 980 |
+
|
| 981 |
+ adata = g_new0 (ActionData, 1);
|
| 982 |
+ adata->mechanism = g_object_ref (mechanism);
|
| 983 |
+ adata->context = context;
|
| 984 |
+ adata->includes = g_strdupv ((gchar **)includes);
|
| 985 |
+ adata->auth_obtained_callback = do_unset_authorized;
|
| 986 |
+ adata->data = udata;
|
| 987 |
+ adata->destroy = unset_data_free;
|
| 988 |
+
|
| 989 |
+ adata->annotation_key = "org.gnome.gconf.defaults.set-mandatory.prefix";
|
| 990 |
+ adata->default_action = "org.gnome.gconf.defaults.set-mandatory";
|
| 991 |
+
|
| 992 |
+ polkit_authority_enumerate_actions (mechanism->priv->auth,
|
| 993 |
+ NULL,
|
| 994 |
+ actions_ready_cb,
|
| 995 |
+ adata);
|
| 996 |
+}
|
| 997 |
|
| 998 |
- for (i = 0; includes[i]; i++) {
|
| 999 |
- action = polkit_action_for_gconf_path (mechanism, annotation_key, includes[i]);
|
| 1000 |
- if (action == NULL)
|
| 1001 |
- action = default_action;
|
| 1002 |
+static void
|
| 1003 |
+check_authorization_only_callback (PolkitAuthority *authority,
|
| 1004 |
+ GAsyncResult *res,
|
| 1005 |
+ gpointer user_data)
|
| 1006 |
+{
|
| 1007 |
+ CheckAuthData *data = user_data;
|
| 1008 |
+ PolkitAuthorizationResult *result;
|
| 1009 |
+ GError *error;
|
| 1010 |
+ gboolean is_authorized;
|
| 1011 |
|
| 1012 |
- if (!check_polkit_for_action (mechanism, context, action))
|
| 1013 |
- goto out;
|
| 1014 |
- }
|
| 1015 |
+ is_authorized = FALSE;
|
| 1016 |
|
| 1017 |
error = NULL;
|
| 1018 |
- unset_in_db (mechanism, "xml:merged:" SYSGCONFDIR "/gconf.xml.mandatory",
|
| 1019 |
- includes, excludes, &error);
|
| 1020 |
-
|
| 1021 |
- if (error) {
|
| 1022 |
- error2 = g_error_new_literal (GCONF_DEFAULTS_ERROR,
|
| 1023 |
- GCONF_DEFAULTS_ERROR_GENERAL,
|
| 1024 |
- error->message);
|
| 1025 |
+ result = polkit_authority_check_authorization_finish (authority,
|
| 1026 |
+ res,
|
| 1027 |
+ &error);
|
| 1028 |
+ if (error != NULL) {
|
| 1029 |
+ g_debug ("error checking action '%s'\n", error->message);
|
| 1030 |
+ throw_error (data->context,
|
| 1031 |
+ GCONF_DEFAULTS_ERROR_NOT_PRIVILEGED,
|
| 1032 |
+ "Not Authorized: %s", error->message);
|
| 1033 |
g_error_free (error);
|
| 1034 |
+ goto out;
|
| 1035 |
+ }
|
| 1036 |
+ else {
|
| 1037 |
+ if (polkit_authorization_result_get_is_authorized (result)) {
|
| 1038 |
+ g_debug ("result for '%s': authorized\n",
|
| 1039 |
+ data->actions[data->id]);
|
| 1040 |
+ is_authorized = TRUE;
|
| 1041 |
+ }
|
| 1042 |
+ else if (polkit_authorization_result_get_is_challenge (result)) {
|
| 1043 |
+ g_debug ("result for '%s': challenge\n",
|
| 1044 |
+ data->actions[data->id]);
|
| 1045 |
+ is_authorized = TRUE;
|
| 1046 |
+ data->challenge = TRUE;
|
| 1047 |
+ }
|
| 1048 |
+ else {
|
| 1049 |
+ g_debug ("result for '%s': not authorized\n",
|
| 1050 |
+ data->actions[data->id]);
|
| 1051 |
+ is_authorized = FALSE;
|
| 1052 |
+ }
|
| 1053 |
+ }
|
| 1054 |
|
| 1055 |
- dbus_g_method_return_error (context, error2);
|
| 1056 |
- g_error_free (error2);
|
| 1057 |
+ if (is_authorized) {
|
| 1058 |
+ data->id++;
|
| 1059 |
+ if (data->actions[data->id] == NULL) {
|
| 1060 |
+ gint result;
|
| 1061 |
+
|
| 1062 |
+ result = data->challenge ? 1 : 2;
|
| 1063 |
+ g_debug ("return %d\n", result);
|
| 1064 |
+ dbus_g_method_return (data->context, result);
|
| 1065 |
+ }
|
| 1066 |
+ else {
|
| 1067 |
+ check_next_action (data);
|
| 1068 |
+ return; /* continue operation */
|
| 1069 |
+ }
|
| 1070 |
}
|
| 1071 |
- else
|
| 1072 |
- dbus_g_method_return (context);
|
| 1073 |
+ else {
|
| 1074 |
+ g_debug ("return 0\n");
|
| 1075 |
+ dbus_g_method_return (data->context, 0);
|
| 1076 |
+ }
|
| 1077 |
+
|
| 1078 |
out:
|
| 1079 |
- start_killtimer();
|
| 1080 |
+ check_auth_data_free (data);
|
| 1081 |
+ g_object_unref (result);
|
| 1082 |
+ stop_operation ();
|
| 1083 |
+}
|
| 1084 |
+
|
| 1085 |
+static void
|
| 1086 |
+check_permissions_only (GConfDefaults *mechanism,
|
| 1087 |
+ DBusGMethodInvocation *context,
|
| 1088 |
+ gchar **actions,
|
| 1089 |
+ AuthObtainedCallback auth_obtained_callback,
|
| 1090 |
+ gpointer user_data,
|
| 1091 |
+ GDestroyNotify destroy)
|
| 1092 |
+{
|
| 1093 |
+ CheckAuthData *data;
|
| 1094 |
+
|
| 1095 |
+ data = g_new0 (CheckAuthData, 1);
|
| 1096 |
+ data->mechanism = g_object_ref (mechanism);
|
| 1097 |
+ data->context = context;
|
| 1098 |
+ data->actions = actions;
|
| 1099 |
+ data->flags = 0;
|
| 1100 |
+ data->id = 0;
|
| 1101 |
+ data->check_auth_callback = (GAsyncReadyCallback)check_authorization_only_callback;
|
| 1102 |
+ data->auth_obtained_callback = NULL;
|
| 1103 |
+ data->user_data = NULL;
|
| 1104 |
+ data->destroy = NULL;
|
| 1105 |
+ data->subject = polkit_system_bus_name_new (dbus_g_method_get_sender (context));
|
| 1106 |
+ data->challenge = FALSE;
|
| 1107 |
+
|
| 1108 |
+ check_next_action (data);
|
| 1109 |
+}
|
| 1110 |
+
|
| 1111 |
+static void
|
| 1112 |
+do_check (GConfDefaults *mechanism,
|
| 1113 |
+ gboolean mandatory,
|
| 1114 |
+ const gchar **includes,
|
| 1115 |
+ DBusGMethodInvocation *context)
|
| 1116 |
+{
|
| 1117 |
+ ActionData *adata;
|
| 1118 |
+
|
| 1119 |
+ start_operation ();
|
| 1120 |
+
|
| 1121 |
+ adata = g_new0 (ActionData, 1);
|
| 1122 |
+ adata->mechanism = g_object_ref (mechanism);
|
| 1123 |
+ adata->context = context;
|
| 1124 |
+ adata->includes = g_strdupv ((gchar **)includes);
|
| 1125 |
+ adata->actions_ready_callback = check_permissions_only;
|
| 1126 |
+ adata->auth_obtained_callback = NULL;
|
| 1127 |
+ adata->data = NULL;
|
| 1128 |
+ adata->destroy = NULL;
|
| 1129 |
+
|
| 1130 |
+ if (mandatory) {
|
| 1131 |
+ adata->annotation_key = "org.gnome.gconf.defaults.set-mandatory.prefix";
|
| 1132 |
+ adata->default_action = "org.gnome.gconf.defaults.set-mandatory";
|
| 1133 |
+ }
|
| 1134 |
+ else {
|
| 1135 |
+ adata->annotation_key = "org.gnome.gconf.defaults.set-system.prefix";
|
| 1136 |
+ adata->default_action = "org.gnome.gconf.defaults.set-system";
|
| 1137 |
+ }
|
| 1138 |
+
|
| 1139 |
+ polkit_authority_enumerate_actions (mechanism->priv->auth,
|
| 1140 |
+ NULL,
|
| 1141 |
+ actions_ready_cb,
|
| 1142 |
+ adata);
|
| 1143 |
+}
|
| 1144 |
+
|
| 1145 |
+void
|
| 1146 |
+gconf_defaults_can_set_system (GConfDefaults *mechanism,
|
| 1147 |
+ const char **includes,
|
| 1148 |
+ DBusGMethodInvocation *context)
|
| 1149 |
+{
|
| 1150 |
+ do_check (mechanism, FALSE, includes, context);
|
| 1151 |
}
|
| 1152 |
+
|
| 1153 |
+void
|
| 1154 |
+gconf_defaults_can_set_mandatory (GConfDefaults *mechanism,
|
| 1155 |
+ const char **includes,
|
| 1156 |
+ DBusGMethodInvocation *context)
|
| 1157 |
+{
|
| 1158 |
+ do_check (mechanism, TRUE, includes, context);
|
| 1159 |
+}
|
| 1160 |
+
|
| 1161 |
diff -up GConf-2.26.2/defaults/gconf-defaults.h.polkit1 GConf-2.26.2/defaults/gconf-defaults.h
|
| 1162 |
--- GConf-2.26.2/defaults/gconf-defaults.h.polkit1 2009-05-14 11:13:40.000000000 -0400
|
| 1163 |
+++ GConf-2.26.2/defaults/gconf-defaults.h 2009-06-12 13:00:27.984836059 -0400
|
| 1164 |
@@ -83,6 +83,14 @@ void gconf_defaults_unset_mand
|
| 1165 |
const char **excludes,
|
| 1166 |
DBusGMethodInvocation *context);
|
| 1167 |
|
| 1168 |
+void gconf_defaults_can_set_system (GConfDefaults *mechanism,
|
| 1169 |
+ const char **includes,
|
| 1170 |
+ DBusGMethodInvocation *context);
|
| 1171 |
+
|
| 1172 |
+void gconf_defaults_can_set_mandatory (GConfDefaults *mechanism,
|
| 1173 |
+ const char **includes,
|
| 1174 |
+ DBusGMethodInvocation *context);
|
| 1175 |
+
|
| 1176 |
G_END_DECLS
|
| 1177 |
|
| 1178 |
#endif /* GCONF_DEFAULTS_H */
|
| 1179 |
diff -up GConf-2.26.2/defaults/gconf-defaults-main.c.polkit1 GConf-2.26.2/defaults/gconf-defaults-main.c
|
| 1180 |
--- GConf-2.26.2/defaults/gconf-defaults-main.c.polkit1 2009-05-05 20:37:32.000000000 -0400
|
| 1181 |
+++ GConf-2.26.2/defaults/gconf-defaults-main.c 2009-06-12 13:00:27.987836052 -0400
|
| 1182 |
@@ -122,6 +122,29 @@ get_system_bus (void)
|
| 1183 |
return bus;
|
| 1184 |
}
|
| 1185 |
|
| 1186 |
+extern gboolean disable_killtimer;
|
| 1187 |
+gboolean debug = FALSE;
|
| 1188 |
+
|
| 1189 |
+GOptionEntry entries [] = {
|
| 1190 |
+ { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, "Emit debug output", NULL },
|
| 1191 |
+ { "no-kill", 0, 0, G_OPTION_ARG_NONE, &disable_killtimer, "Don't exit when idle", NULL },
|
| 1192 |
+ { NULL, }
|
| 1193 |
+};
|
| 1194 |
+
|
| 1195 |
+static gint log_levels = (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
|
| 1196 |
+
|
| 1197 |
+void
|
| 1198 |
+log_default_handler (const gchar *log_domain,
|
| 1199 |
+ GLogLevelFlags log_level,
|
| 1200 |
+ const gchar *message,
|
| 1201 |
+ gpointer unused_data)
|
| 1202 |
+{
|
| 1203 |
+ if ((log_level & log_levels) != 0) {
|
| 1204 |
+ g_log_default_handler (log_domain, log_level, message, unused_data);
|
| 1205 |
+ }
|
| 1206 |
+}
|
| 1207 |
+
|
| 1208 |
+
|
| 1209 |
int
|
| 1210 |
main (int argc, char **argv)
|
| 1211 |
{
|
| 1212 |
@@ -130,6 +153,8 @@ main (int argc, char **argv)
|
| 1213 |
DBusGProxy *bus_proxy;
|
| 1214 |
DBusGConnection *connection;
|
| 1215 |
int ret;
|
| 1216 |
+ GOptionContext *options;
|
| 1217 |
+ GError *error = NULL;
|
| 1218 |
|
| 1219 |
ret = 1;
|
| 1220 |
|
| 1221 |
@@ -139,8 +164,22 @@ main (int argc, char **argv)
|
| 1222 |
dbus_g_thread_init ();
|
| 1223 |
g_type_init ();
|
| 1224 |
|
| 1225 |
+ options = g_option_context_new (NULL);
|
| 1226 |
+ g_option_context_add_main_entries (options, entries, NULL);
|
| 1227 |
+ if (!g_option_context_parse (options, &argc, &argv, &error)) {
|
| 1228 |
+ g_warning ("Failed to parse options: %s\n", error->message);
|
| 1229 |
+ g_error_free (error);
|
| 1230 |
+ }
|
| 1231 |
+ g_option_context_free (options);
|
| 1232 |
+
|
| 1233 |
+ g_log_set_default_handler (log_default_handler, NULL);
|
| 1234 |
+ if (debug) {
|
| 1235 |
+ log_levels = log_levels | G_LOG_LEVEL_DEBUG;
|
| 1236 |
+ }
|
| 1237 |
+
|
| 1238 |
connection = get_system_bus ();
|
| 1239 |
if (connection == NULL) {
|
| 1240 |
+ g_warning ("Could not get system bus connection; bailing out");
|
| 1241 |
goto out;
|
| 1242 |
}
|
| 1243 |
|
| 1244 |
diff -up GConf-2.26.2/defaults/gconf-defaults.xml.polkit1 GConf-2.26.2/defaults/gconf-defaults.xml
|
| 1245 |
--- GConf-2.26.2/defaults/gconf-defaults.xml.polkit1 2009-05-14 11:13:40.000000000 -0400
|
| 1246 |
+++ GConf-2.26.2/defaults/gconf-defaults.xml 2009-06-12 14:21:43.646401662 -0400
|
| 1247 |
@@ -2,12 +2,12 @@
|
| 1248 |
<node name="/">
|
| 1249 |
<interface name="org.gnome.GConf.Defaults">
|
| 1250 |
<!--
|
| 1251 |
- includes: an array of GConf paths to copy from the
|
| 1252 |
+ includes: an array of GConf paths to copy from the
|
| 1253 |
callers GConf database to the system database
|
| 1254 |
excludes: an array of GConf paths to omit
|
| 1255 |
|
| 1256 |
- Copies values from the callers GConf database to the system-wide
|
| 1257 |
- database. The subtree below each included path is copied recursively,
|
| 1258 |
+ Copies values from the callers GConf database to the system-wide
|
| 1259 |
+ database. The subtree below each included path is copied recursively,
|
| 1260 |
skipping the excluded subtrees.
|
| 1261 |
To decide which PolicyKit privilege to require for the copying of
|
| 1262 |
each path in includes, the mechanism looks for a privilege with an
|
| 1263 |
@@ -21,16 +21,22 @@
|
| 1264 |
<arg name="excludes" direction="in" type="as"/>
|
| 1265 |
</method>
|
| 1266 |
|
| 1267 |
+ <method name="CanSetSystem">
|
| 1268 |
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
|
| 1269 |
+ <arg name="includes" direction="in" type="as"/>
|
| 1270 |
+ <arg name="result" direction="out" type="u"/>
|
| 1271 |
+ </method>
|
| 1272 |
+
|
| 1273 |
<signal name="SystemSet">
|
| 1274 |
<arg name="keys" type="as"/>
|
| 1275 |
</signal>
|
| 1276 |
<!--
|
| 1277 |
- includes: an array of GConf paths to copy from the
|
| 1278 |
+ includes: an array of GConf paths to copy from the
|
| 1279 |
callers GConf database to the mandatory database
|
| 1280 |
excludes: an array of GConf paths to omit
|
| 1281 |
|
| 1282 |
- Copies values from the callers GConf database to the system-wide
|
| 1283 |
- mandatory database. The subtree below each included path is copied
|
| 1284 |
+ Copies values from the callers GConf database to the system-wide
|
| 1285 |
+ mandatory database. The subtree below each included path is copied
|
| 1286 |
recursively, skipping the excluded subtrees.
|
| 1287 |
To decide which PolicyKit privilege to require for the copying of
|
| 1288 |
each path in includes, the mechanism looks for a privilege with an
|
| 1289 |
@@ -46,7 +52,7 @@
|
| 1290 |
|
| 1291 |
<!--
|
| 1292 |
Unsets keys in the system-wide mandatory GConf database, making the
|
| 1293 |
- keys writable again. The subtree below each included path is copied
|
| 1294 |
+ keys writable again. The subtree below each included path is copied
|
| 1295 |
recursively, skipping the excluded subtrees.
|
| 1296 |
To decide which PolicyKit privilege to require for the copying of
|
| 1297 |
each path in includes, the mechanism looks for a privilege with an
|
| 1298 |
@@ -59,6 +65,12 @@
|
| 1299 |
<arg name="includes" direction="in" type="as"/>
|
| 1300 |
<arg name="excludes" direction="in" type="as"/>
|
| 1301 |
</method>
|
| 1302 |
-
|
| 1303 |
+
|
| 1304 |
+ <method name="CanSetMandatory">
|
| 1305 |
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
|
| 1306 |
+ <arg name="includes" direction="in" type="as"/>
|
| 1307 |
+ <arg name="result" direction="out" type="u"/>
|
| 1308 |
+ </method>
|
| 1309 |
+
|
| 1310 |
</interface>
|
| 1311 |
</node>
|
| 1312 |
diff -up GConf-2.26.2/defaults/Makefile.am.polkit1 GConf-2.26.2/defaults/Makefile.am
|
| 1313 |
--- GConf-2.26.2/defaults/Makefile.am.polkit1 2009-04-25 02:44:06.000000000 -0400
|
| 1314 |
+++ GConf-2.26.2/defaults/Makefile.am 2009-06-12 13:00:27.990835416 -0400
|
| 1315 |
@@ -20,13 +20,13 @@ INCLUDES = \
|
| 1316 |
|
| 1317 |
gconf_defaults_mechanism_LDADD = \
|
| 1318 |
$(top_builddir)/gconf/libgconf-2.la \
|
| 1319 |
- $(DEFAULTS_LIBS)
|
| 1320 |
+ $(DEFAULTS_LIBS)
|
| 1321 |
|
| 1322 |
BUILT_SOURCES = gconf-defaults-glue.h
|
| 1323 |
|
| 1324 |
dbus_servicesdir = $(datadir)/dbus-1/system-services
|
| 1325 |
dbus_confdir = $(sysconfdir)/dbus-1/system.d
|
| 1326 |
-polkitdir = $(datadir)/PolicyKit/policy
|
| 1327 |
+polkitdir = $(datadir)/polkit-1/actions
|
| 1328 |
|
| 1329 |
dbus_services_in_files = org.gnome.GConf.Defaults.service.in
|
| 1330 |
polkit_in_files = org.gnome.gconf.defaults.policy.in
|
| 1331 |
@@ -41,9 +41,6 @@ dbus_conf_DATA = org.gnome.GConf.Default
|
| 1332 |
@INTLTOOL_POLICY_RULE@
|
| 1333 |
polkit_DATA = $(polkit_in_files:.policy.in=.policy)
|
| 1334 |
|
| 1335 |
-check:
|
| 1336 |
- $(POLKIT_POLICY_FILE_VALIDATE) $(polkit_DATA)
|
| 1337 |
-
|
| 1338 |
EXTRA_DIST = \
|
| 1339 |
$(dbus_services_in_files) \
|
| 1340 |
org.gnome.GConf.Defaults.conf \
|