diff options
author | David Zeuthen <davidz@redhat.com> | 2009-02-08 16:23:45 -0500 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2009-02-08 16:23:45 -0500 |
commit | 21e21e97cd2b663ae96efe62c8f6cc69edbd1d3c (patch) | |
tree | 6efcdce824c817bdc381da8bc8250a8b2668cba1 /src/polkitbackend | |
parent | bc150368d95ef70b04af3bc9250c1bdfe950a048 (diff) |
load and choose what backend to use; also write a simple null backend
The thinking is that if someone wants to turn off PolicyKit, they
simply drop a file /etc/polkit-1/nullbackend.conf.d/99-i-hate-polkit.conf
with the contents
[Configuration]
priority=1000
This also provides a good cut-n-paste template / example etc. of how
to implement a PolicyKit backend.
Diffstat (limited to 'src/polkitbackend')
-rw-r--r-- | src/polkitbackend/Makefile.am | 1 | ||||
-rw-r--r-- | src/polkitbackend/polkitbackend.h | 2 | ||||
-rw-r--r-- | src/polkitbackend/polkitbackendauthority.c | 56 | ||||
-rw-r--r-- | src/polkitbackend/polkitbackendauthority.h | 9 | ||||
-rw-r--r-- | src/polkitbackend/polkitbackendlocalauthority.c | 6 |
5 files changed, 72 insertions, 2 deletions
diff --git a/src/polkitbackend/Makefile.am b/src/polkitbackend/Makefile.am index 5f10f9e..a505fa7 100644 --- a/src/polkitbackend/Makefile.am +++ b/src/polkitbackend/Makefile.am @@ -84,3 +84,4 @@ clean-local : install-exec-hook: mkdir -p $(DESTDIR)$(localstatedir)/lib/polkit-1 -chmod 600 $(DESTDIR)$(localstatedir)/lib/polkit-1 + mkdir -p $(DESTDIR)$(libdir)/polkit-1/backends diff --git a/src/polkitbackend/polkitbackend.h b/src/polkitbackend/polkitbackend.h index 3da728d..6ff0439 100644 --- a/src/polkitbackend/polkitbackend.h +++ b/src/polkitbackend/polkitbackend.h @@ -22,6 +22,8 @@ #ifndef __POLKIT_BACKEND_H #define __POLKIT_BACKEND_H +#include <polkit/polkit.h> + #define _POLKIT_BACKEND_INSIDE_POLKIT_BACKEND_H 1 #include <polkitbackend/polkitbackendtypes.h> #include <polkitbackend/polkitbackendauthority.h> diff --git a/src/polkitbackend/polkitbackendauthority.c b/src/polkitbackend/polkitbackendauthority.c index f81fba8..bf40283 100644 --- a/src/polkitbackend/polkitbackendauthority.c +++ b/src/polkitbackend/polkitbackendauthority.c @@ -26,6 +26,7 @@ #include <polkit/polkit.h> #include <polkit/polkitprivate.h> #include "polkitbackendauthority.h" +#include "polkitbackendlocalauthority.h" #include "polkitbackendprivate.h" @@ -85,7 +86,8 @@ polkit_backend_authority_system_bus_name_owner_changed (PolkitBackendAuthority klass = POLKIT_BACKEND_AUTHORITY_GET_CLASS (authority); - klass->system_bus_name_owner_changed (authority, name, old_owner, new_owner); + if (klass->system_bus_name_owner_changed != NULL) + klass->system_bus_name_owner_changed (authority, name, old_owner, new_owner); } /** @@ -1261,3 +1263,55 @@ polkit_backend_register_authority (PolkitBackendAuthority *authority, g_object_unref (server); return FALSE; } + + +/** + * polkit_backend_authority_get: + * + * Loads all #GIOModule<!-- -->s from <literal>$(libdir)/polkit-1/backends</literal> to determine + * what implementation of #PolkitBackendAuthority to use. Then instantiates an object of the + * implementation with the highest priority and unloads all other modules. + * + * Returns: A #PolkitBackendAuthority. Free with g_object_unref(). + **/ +PolkitBackendAuthority * +polkit_backend_authority_get (void) +{ + static GIOExtensionPoint *ep = NULL; + static volatile GType local_authority_type = G_TYPE_INVALID; + GList *modules; + GList *authority_implementations; + GType authority_type; + PolkitBackendAuthority *authority; + + /* define the extension point */ + if (ep == NULL) + { + ep = g_io_extension_point_register (POLKIT_BACKEND_AUTHORITY_EXTENSION_POINT_NAME); + g_io_extension_point_set_required_type (ep, POLKIT_BACKEND_TYPE_AUTHORITY); + } + + /* make sure local types are registered */ + if (local_authority_type == G_TYPE_INVALID) + { + local_authority_type = POLKIT_BACKEND_TYPE_LOCAL_AUTHORITY; + } + + /* load all modules */ + modules = g_io_modules_load_all_in_directory (PACKAGE_LIB_DIR "/polkit-1/backends"); + + /* find all extensions; we have at least one here since we've registered the local backend */ + authority_implementations = g_io_extension_point_get_extensions (ep); + + /* the returned list is sorted according to priority so just take the highest one */ + authority_type = g_io_extension_get_type ((GIOExtension*) authority_implementations->data); + authority = POLKIT_BACKEND_AUTHORITY (g_object_new (authority_type, NULL)); + + /* unload all modules; the module our instantiated authority is in won't be unloaded because + * we've instantiated a reference to a type in this module + */ + g_list_foreach (modules, (GFunc) g_type_module_unuse, NULL); + g_list_free (modules); + + return authority; +} diff --git a/src/polkitbackend/polkitbackendauthority.h b/src/polkitbackend/polkitbackendauthority.h index 25c0ce0..e08360b 100644 --- a/src/polkitbackend/polkitbackendauthority.h +++ b/src/polkitbackend/polkitbackendauthority.h @@ -41,6 +41,13 @@ G_BEGIN_DECLS typedef struct _PolkitBackendAuthorityClass PolkitBackendAuthorityClass; /** + * POLKIT_BACKEND_AUTHORITY_EXTENSION_POINT_NAME: + * + * Extension point name for authority backend implementations. + */ +#define POLKIT_BACKEND_AUTHORITY_EXTENSION_POINT_NAME "polkit-backend-authority-1" + +/** * PolkitBackendAuthority: * * The #PolkitBackendAuthority struct should not be accessed directly. @@ -258,6 +265,8 @@ gboolean polkit_backend_authority_authentication_agent_response (PolkitBackendAu /* --- */ +PolkitBackendAuthority *polkit_backend_authority_get (void); + gboolean polkit_backend_register_authority (PolkitBackendAuthority *authority, const gchar *well_known_name, const gchar *object_path, diff --git a/src/polkitbackend/polkitbackendlocalauthority.c b/src/polkitbackend/polkitbackendlocalauthority.c index 15a7f8f..c735c8c 100644 --- a/src/polkitbackend/polkitbackendlocalauthority.c +++ b/src/polkitbackend/polkitbackendlocalauthority.c @@ -220,7 +220,11 @@ action_pool_changed (PolkitBackendActionPool *action_pool, /* ---------------------------------------------------------------------------------------------------- */ -G_DEFINE_TYPE (PolkitBackendLocalAuthority, polkit_backend_local_authority, POLKIT_BACKEND_TYPE_AUTHORITY); +G_DEFINE_TYPE_WITH_CODE (PolkitBackendLocalAuthority, polkit_backend_local_authority,POLKIT_BACKEND_TYPE_AUTHORITY, + g_io_extension_point_implement (POLKIT_BACKEND_AUTHORITY_EXTENSION_POINT_NAME, + g_define_type_id, + "local-files " PACKAGE_VERSION, + 0)); #define POLKIT_BACKEND_LOCAL_AUTHORITY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), POLKIT_BACKEND_TYPE_LOCAL_AUTHORITY, PolkitBackendLocalAuthorityPrivate)) |