diff options
author | David Zeuthen <davidz@redhat.com> | 2012-04-12 13:54:27 -0400 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2012-04-12 14:00:26 -0400 |
commit | 2dd284eb425535445f0be6e9dd7d45e8ccd3ffa6 (patch) | |
tree | 2df3f5169bde212bb49890e3b145fef3f927f1bd /src/polkitagent | |
parent | bda0fc1de3361fc6f377d041ce2088118048fdf7 (diff) | |
download | polkit-2dd284eb425535445f0be6e9dd7d45e8ccd3ffa6.tar.gz |
Make it possible to influence agent registration with an a{sv} parameter
Additionally, add a "fallback" option. Also add support in this in the
pkttyagent(1) program.
This slightly breaks libpolkit-backend API by adding a GVariant* param
to one of the class vfuncs... but that API is already declared
unstable so that's fine.
Signed-off-by: David Zeuthen <davidz@redhat.com>
Diffstat (limited to 'src/polkitagent')
-rw-r--r-- | src/polkitagent/polkitagentlistener.c | 98 | ||||
-rw-r--r-- | src/polkitagent/polkitagentlistener.h | 8 |
2 files changed, 76 insertions, 30 deletions
diff --git a/src/polkitagent/polkitagentlistener.c b/src/polkitagent/polkitagentlistener.c index dbbfd63..0d97501 100644 --- a/src/polkitagent/polkitagentlistener.c +++ b/src/polkitagent/polkitagentlistener.c @@ -43,7 +43,8 @@ * evidence that the user is one of the requested identities. * * To register a #PolkitAgentListener with the PolicyKit daemon, use - * polkit_agent_listener_register(). + * polkit_agent_listener_register() or + * polkit_agent_listener_register_with_options(). */ typedef struct @@ -62,6 +63,8 @@ typedef struct PolkitAgentListener *listener; + GVariant *registration_options; + PolkitSubject *subject; gchar *object_path; @@ -104,6 +107,9 @@ server_free (Server *server) if (server->interface_info != NULL) g_dbus_interface_info_unref (server->interface_info); + if (server->registration_options != NULL) + g_variant_unref (server->registration_options); + if (server->listener != NULL) g_object_unref (server->listener); @@ -143,12 +149,13 @@ server_register (Server *server, locale = "en_US.UTF-8"; local_error = NULL; - if (!polkit_authority_register_authentication_agent_sync (server->authority, - server->subject, - locale, - server->object_path, - NULL, - &local_error)) + if (!polkit_authority_register_authentication_agent_with_options_sync (server->authority, + server->subject, + locale, + server->object_path, + server->registration_options, + NULL, + &local_error)) { g_warning ("Unable to register authentication agent: %s", local_error->message); g_propagate_error (error, local_error); @@ -360,42 +367,30 @@ server_thread_func (gpointer user_data) } /** - * polkit_agent_listener_register: + * polkit_agent_listener_register_with_options: * @listener: A #PolkitAgentListener. * @flags: A set of flags from the #PolkitAgentRegisterFlags enumeration. * @subject: The subject to become an authentication agent for, typically a #PolkitUnixSession object. * @object_path: The D-Bus object path to use for the authentication agent or %NULL for the default object path. + * @options: (allow-none): A #GVariant with options or %NULL. * @cancellable: A #GCancellable or %NULL. * @error: Return location for error. * - * Registers @listener with the PolicyKit daemon as an authentication - * agent for @subject. This is implemented by registering a D-Bus - * object at @object_path on the unique name assigned by the system - * message bus. - * - * Whenever the PolicyKit daemon needs to authenticate a processes - * that is related to @subject, the methods - * polkit_agent_listener_initiate_authentication() and - * polkit_agent_listener_initiate_authentication_finish() will be - * invoked on @listener. - * - * Note that registration of an authentication agent can fail; for - * example another authentication agent may already be registered for - * @subject. - * - * Note that the calling thread is blocked until a reply is received. + * Like polkit_agent_listener_register() but takes options to influence registration. See the + * <link linkend="eggdbus-method-org.freedesktop.PolicyKit1.Authority.RegisterAuthenticationAgentWithOptions">RegisterAuthenticationAgentWithOptions()</link> D-Bus method for details. * * Returns: (transfer full): %NULL if @error is set, otherwise a * registration handle that can be used with * polkit_agent_listener_unregister(). */ gpointer -polkit_agent_listener_register (PolkitAgentListener *listener, - PolkitAgentRegisterFlags flags, - PolkitSubject *subject, - const gchar *object_path, - GCancellable *cancellable, - GError **error) +polkit_agent_listener_register_with_options (PolkitAgentListener *listener, + PolkitAgentRegisterFlags flags, + PolkitSubject *subject, + const gchar *object_path, + GVariant *options, + GCancellable *cancellable, + GError **error) { Server *server; GDBusNodeInfo *node_info; @@ -425,6 +420,8 @@ polkit_agent_listener_register (PolkitAgentListener *listener, server->listener = g_object_ref (listener); + server->registration_options = options != NULL ? g_variant_ref_sink (options) : NULL; + if (flags & POLKIT_AGENT_REGISTER_FLAGS_RUN_IN_THREAD) { server->thread = g_thread_create (server_thread_func, @@ -472,6 +469,47 @@ polkit_agent_listener_register (PolkitAgentListener *listener, } /** + * polkit_agent_listener_register: + * @listener: A #PolkitAgentListener. + * @flags: A set of flags from the #PolkitAgentRegisterFlags enumeration. + * @subject: The subject to become an authentication agent for, typically a #PolkitUnixSession object. + * @object_path: The D-Bus object path to use for the authentication agent or %NULL for the default object path. + * @cancellable: A #GCancellable or %NULL. + * @error: Return location for error. + * + * Registers @listener with the PolicyKit daemon as an authentication + * agent for @subject. This is implemented by registering a D-Bus + * object at @object_path on the unique name assigned by the system + * message bus. + * + * Whenever the PolicyKit daemon needs to authenticate a processes + * that is related to @subject, the methods + * polkit_agent_listener_initiate_authentication() and + * polkit_agent_listener_initiate_authentication_finish() will be + * invoked on @listener. + * + * Note that registration of an authentication agent can fail; for + * example another authentication agent may already be registered for + * @subject. + * + * Note that the calling thread is blocked until a reply is received. + * + * Returns: (transfer full): %NULL if @error is set, otherwise a + * registration handle that can be used with + * polkit_agent_listener_unregister(). + */ +gpointer +polkit_agent_listener_register (PolkitAgentListener *listener, + PolkitAgentRegisterFlags flags, + PolkitSubject *subject, + const gchar *object_path, + GCancellable *cancellable, + GError **error) +{ + return polkit_agent_listener_register_with_options (listener, flags, subject, object_path, NULL, cancellable, error); +} + +/** * polkit_agent_listener_unregister: * @registration_handle: A handle obtained from polkit_agent_listener_register(). * diff --git a/src/polkitagent/polkitagentlistener.h b/src/polkitagent/polkitagentlistener.h index 191b265..c3cbcfb 100644 --- a/src/polkitagent/polkitagentlistener.h +++ b/src/polkitagent/polkitagentlistener.h @@ -134,6 +134,14 @@ gpointer polkit_agent_listener_register (PolkitAgentList GCancellable *cancellable, GError **error); +gpointer polkit_agent_listener_register_with_options (PolkitAgentListener *listener, + PolkitAgentRegisterFlags flags, + PolkitSubject *subject, + const gchar *object_path, + GVariant *options, + GCancellable *cancellable, + GError **error); + void polkit_agent_listener_unregister (gpointer registration_handle); G_END_DECLS |