Commit ccacb4e8 authored by David Zeuthen's avatar David Zeuthen

add infrastructure for registering/unregistering authentication agents

parent 83bf3b05
## Process this file with automake to produce Makefile.in
NULL =
servicedir = $(datadir)/dbus-1/system-services
service_in_files = org.freedesktop.PolicyKit1.service.in
service_DATA = $(service_in_files:.service.in=.service)
......@@ -24,13 +26,16 @@ pkgconfig_DATA = polkit-gobject-1.pc polkit-backend-1.pc polkit-agent-1.pc
CLEANFILES = $(BUILT_SOURCES)
EXTRA_DIST = \
org.freedesktop.PolicyKit1.Authority.xml \
$(service_in_files) \
$(dbusconf_in_files) \
polkit-gobject-1.in \
polkit-backend-1.in \
polkit-agent-1.in
EXTRA_DIST = \
org.freedesktop.PolicyKit1.Authority.xml \
org.freedesktop.PolicyKit1.AuthenticationAgent.xml \
$(service_in_files) \
$(dbusconf_in_files) \
polkit-gobject-1.in \
polkit-backend-1.in \
polkit-agent-1.in \
$(NULL)
clean-local :
rm -f *~ $(service_DATA) $(dbusconf_DATA)
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/">
<interface name="org.freedesktop.PolicyKit1.AuthenticationAgent">
<method name="BeginAuthentication">
<!-- The action id for the action that the user is authentication for -->
<arg name="action_id" direction="in" type="s"/>
<!-- A cookie identifying the authentication request -->
<arg name="cookie" direction="in" type="s"/>
<!-- A list of identities of that the user can use for authentication -->
<arg name="identities" direction="in" type="a(sa{sv})"/>
</method>
<method name="EndAuthentication">
<arg name="cookie" direction="in" type="s"/>
</method>
</interface>
</node>
......@@ -178,5 +178,17 @@
</arg>
</method>
<method name="RegisterAuthenticationAgent">
<arg name="object_path" direction="in" type="s">
<annotation name="org.gtk.EggDBus.DocString" value="Path of authentication agent object on the unique name of the caller"/>
</arg>
</method>
<method name="UnregisterAuthenticationAgent">
<arg name="object_path" direction="in" type="s">
<annotation name="org.gtk.EggDBus.DocString" value="Path of authentication agent object on the unique name of the caller"/>
</arg>
</method>
</interface>
</node>
......@@ -860,3 +860,189 @@ polkit_authority_remove_authorization_sync (PolkitAuthority *authority,
}
/* ---------------------------------------------------------------------------------------------------- */
static guint
polkit_authority_register_authentication_agent_async (PolkitAuthority *authority,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
guint call_id;
GSimpleAsyncResult *simple;
simple = g_simple_async_result_new (G_OBJECT (authority),
callback,
user_data,
polkit_authority_register_authentication_agent_async);
call_id = _polkit_authority_register_authentication_agent (authority->real,
EGG_DBUS_CALL_FLAGS_NONE,
object_path,
cancellable,
generic_async_cb,
simple);
return call_id;
}
void
polkit_authority_register_authentication_agent (PolkitAuthority *authority,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
polkit_authority_register_authentication_agent_async (authority,
object_path,
cancellable,
callback,
user_data);
}
gboolean
polkit_authority_register_authentication_agent_finish (PolkitAuthority *authority,
GAsyncResult *res,
GError **error)
{
GSimpleAsyncResult *simple;
GAsyncResult *real_res;
gboolean ret;
simple = G_SIMPLE_ASYNC_RESULT (res);
real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_register_authentication_agent_async);
ret = _polkit_authority_register_authentication_agent_finish (authority->real,
real_res,
error);
if (!ret)
goto out;
out:
g_object_unref (real_res);
return ret;
}
gboolean
polkit_authority_register_authentication_agent_sync (PolkitAuthority *authority,
const gchar *object_path,
GCancellable *cancellable,
GError **error)
{
guint call_id;
GAsyncResult *res;
gboolean ret;
call_id = polkit_authority_register_authentication_agent_async (authority,
object_path,
cancellable,
generic_cb,
&res);
egg_dbus_connection_pending_call_block (authority->system_bus, call_id);
ret = polkit_authority_register_authentication_agent_finish (authority, res, error);
g_object_unref (res);
return ret;
}
/* ---------------------------------------------------------------------------------------------------- */
static guint
polkit_authority_unregister_authentication_agent_async (PolkitAuthority *authority,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
guint call_id;
GSimpleAsyncResult *simple;
simple = g_simple_async_result_new (G_OBJECT (authority),
callback,
user_data,
polkit_authority_unregister_authentication_agent_async);
call_id = _polkit_authority_unregister_authentication_agent (authority->real,
EGG_DBUS_CALL_FLAGS_NONE,
object_path,
cancellable,
generic_async_cb,
simple);
return call_id;
}
void
polkit_authority_unregister_authentication_agent (PolkitAuthority *authority,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
polkit_authority_unregister_authentication_agent_async (authority,
object_path,
cancellable,
callback,
user_data);
}
gboolean
polkit_authority_unregister_authentication_agent_finish (PolkitAuthority *authority,
GAsyncResult *res,
GError **error)
{
GSimpleAsyncResult *simple;
GAsyncResult *real_res;
gboolean ret;
simple = G_SIMPLE_ASYNC_RESULT (res);
real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_unregister_authentication_agent_async);
ret = _polkit_authority_unregister_authentication_agent_finish (authority->real,
real_res,
error);
if (!ret)
goto out;
out:
g_object_unref (real_res);
return ret;
}
gboolean
polkit_authority_unregister_authentication_agent_sync (PolkitAuthority *authority,
const gchar *object_path,
GCancellable *cancellable,
GError **error)
{
guint call_id;
GAsyncResult *res;
gboolean ret;
call_id = polkit_authority_unregister_authentication_agent_async (authority,
object_path,
cancellable,
generic_cb,
&res);
egg_dbus_connection_pending_call_block (authority->system_bus, call_id);
ret = polkit_authority_unregister_authentication_agent_finish (authority, res, error);
g_object_unref (res);
return ret;
}
/* ---------------------------------------------------------------------------------------------------- */
......@@ -83,6 +83,16 @@ gboolean polkit_authority_remove_authorization_sync (PolkitAut
GCancellable *cancellable,
GError **error);
gboolean polkit_authority_register_authentication_agent_sync (PolkitAuthority *authority,
const gchar *object_path,
GCancellable *cancellable,
GError **error);
gboolean polkit_authority_unregister_authentication_agent_sync (PolkitAuthority *authority,
const gchar *object_path,
GCancellable *cancellable,
GError **error);
/* ---------------------------------------------------------------------------------------------------- */
void polkit_authority_enumerate_actions (PolkitAuthority *authority,
......@@ -158,6 +168,26 @@ gboolean polkit_authority_remove_authorization_finish (PolkitA
GError **error);
void polkit_authority_register_authentication_agent (PolkitAuthority *authority,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean polkit_authority_register_authentication_agent_finish (PolkitAuthority *authority,
GAsyncResult *res,
GError **error);
void polkit_authority_unregister_authentication_agent (PolkitAuthority *authority,
const gchar *object_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean polkit_authority_unregister_authentication_agent_finish (PolkitAuthority *authority,
GAsyncResult *res,
GError **error);
/* ---------------------------------------------------------------------------------------------------- */
G_END_DECLS
......
......@@ -12,23 +12,41 @@ INCLUDES = \
-DPACKAGE_LIB_DIR=\""$(libdir)"\" \
-D_POSIX_PTHREAD_SEMANTICS \
-D_REENTRANT \
-DEGG_DBUS_I_KNOW_API_IS_SUBJECT_TO_CHANGE \
$(NULL)
BUILT_SOURCES = \
_polkitagentauthenticationagent.c _polkitagentauthenticationagent.h \
_polkitagentbindings.c _polkitagentbindings.h \
_polkitagentbindingsmarshal.list \
_polkitagentbindingsmarshal.c _polkitagentbindingsmarshal.h \
_polkitagentbindingstypes.h \
$(NULL)
$(BUILT_SOURCES) : Makefile.am $(top_srcdir)/data/org.freedesktop.PolicyKit1.AuthenticationAgent.xml
eggdbus-binding-tool \
--namespace "_PolkitAgent" \
--dbus-namespace "org.freedesktop.PolicyKit1" \
--introspection-xml $(top_srcdir)/data/org.freedesktop.PolicyKit1.AuthenticationAgent.xml \
$(NULL)
lib_LTLIBRARIES=libpolkit-agent-1.la
libpolkit_agent_1includedir=$(includedir)/polkit-1/polkitagent
libpolkit_agent_1include_HEADERS = \
polkitagent.h \
polkitagenttypes.h \
polkitauthenticationsession.h \
libpolkit_agent_1include_HEADERS = \
polkitagent.h \
polkitagenttypes.h \
polkitagentauthenticationsession.h \
polkitagentauthenticationagent.h \
$(NULL)
libpolkit_agent_1_la_SOURCES = \
polkitagent.h \
polkitagenttypes.h \
polkitauthenticationsession.h polkitauthenticationsession.c \
libpolkit_agent_1_la_SOURCES = \
polkitagent.h \
polkitagenttypes.h \
polkitagentauthenticationsession.h polkitagentauthenticationsession.c \
polkitagentauthenticationagent.h polkitagentauthenticationagent.c \
$(BUILT_SOURCES) \
$(NULL)
libpolkit_agent_1_la_CFLAGS = \
......
......@@ -23,7 +23,8 @@
#define __POLKIT_AGENT_H
#define _POLKIT_AGENT_INSIDE_POLKIT_AGENT_H 1
#include <polkitagent/polkitauthenticationsession.h>
#include <polkitagent/polkitagentauthenticationagent.h>
#include <polkitagent/polkitagentauthenticationsession.h>
#undef _POLKIT_AGENT_INSIDE_POLKIT_AGENT_H
#endif /* __POLKIT_AGENT_H */
/*
* Copyright (C) 2008 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: David Zeuthen <davidz@redhat.com>
*/
#include "config.h"
#include <polkit/polkitprivate.h>
#include "_polkitagentbindings.h"
#include "polkitagentauthenticationagent.h"
struct _PolkitAgentAuthenticationAgent
{
GObject parent_instance;
EggDBusConnection *system_bus;
PolkitAuthority *authority;
PolkitAgentAuthenticationAgentBeginFunc begin_func;
PolkitAgentAuthenticationAgentEndFunc end_func;
gpointer user_data;
};
struct _PolkitAgentAuthenticationAgentClass
{
GObjectClass parent_class;
};
static void authentication_agent_iface_init (_PolkitAgentAuthenticationAgentIface *agent_iface);
G_DEFINE_TYPE_WITH_CODE (PolkitAgentAuthenticationAgent, polkit_agent_authentication_agent, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (_POLKIT_AGENT_TYPE_AUTHENTICATION_AGENT,
authentication_agent_iface_init)
);
static void
polkit_agent_authentication_agent_init (PolkitAgentAuthenticationAgent *agent)
{
agent->system_bus = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM);
egg_dbus_connection_register_interface (agent->system_bus,
"/org/freedesktop/PolicyKit1/AuthenticationAgent",
_POLKIT_AGENT_TYPE_AUTHENTICATION_AGENT,
G_OBJECT (agent),
G_TYPE_INVALID);
agent->authority = polkit_authority_get ();
}
static void
polkit_agent_authentication_agent_finalize (GObject *object)
{
PolkitAgentAuthenticationAgent *agent = POLKIT_AGENT_AUTHENTICATION_AGENT (object);
GError *error;
error = NULL;
if (!polkit_authority_unregister_authentication_agent_sync (agent->authority,
"/org/freedesktop/PolicyKit1/AuthenticationAgent",
NULL,
&error))
{
g_warning ("Error unregistering authentication agent: %s", error->message);
g_error_free (error);
}
g_object_unref (agent->authority);
g_object_unref (agent->system_bus);
if (G_OBJECT_CLASS (polkit_agent_authentication_agent_parent_class)->finalize != NULL)
G_OBJECT_CLASS (polkit_agent_authentication_agent_parent_class)->finalize (object);
}
static void
polkit_agent_authentication_agent_class_init (PolkitAgentAuthenticationAgentClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = polkit_agent_authentication_agent_finalize;
}
PolkitAgentAuthenticationAgent *
polkit_agent_authentication_agent_new (PolkitAgentAuthenticationAgentBeginFunc begin_func,
PolkitAgentAuthenticationAgentEndFunc end_func,
gpointer user_data,
GError **error)
{
PolkitAgentAuthenticationAgent *agent;
agent = POLKIT_AGENT_AUTHENTICATION_AGENT (g_object_new (POLKIT_AGENT_TYPE_AUTHENTICATION_AGENT, NULL));
agent->begin_func = begin_func;
agent->end_func = end_func;
agent->user_data = user_data;
if (!polkit_authority_register_authentication_agent_sync (agent->authority,
"/org/freedesktop/PolicyKit1/AuthenticationAgent",
NULL,
error))
{
g_object_unref (agent);
agent = NULL;
}
return agent;
}
static void
handle_begin_authentication (_PolkitAgentAuthenticationAgent *instance,
const gchar *action_id,
const gchar *cookie,
EggDBusArraySeq *identities,
EggDBusMethodInvocation *method_invocation)
{
PolkitAgentAuthenticationAgent *agent = POLKIT_AGENT_AUTHENTICATION_AGENT (instance);
GList *list;
guint n;
GError *error;
list = NULL;
for (n = 0; n < identities->size; n++)
{
_PolkitIdentity *real_identity = _POLKIT_IDENTITY (identities->data.v_ptr[n]);
list = g_list_prepend (list, polkit_identity_new_for_real (real_identity));
}
list = g_list_reverse (list);
error = NULL;
if (!agent->begin_func (agent,
action_id,
cookie,
list,
&error,
agent->user_data))
{
egg_dbus_method_invocation_return_gerror (method_invocation, error);
g_error_free (error);
}
else
{
_polkit_agent_authentication_agent_handle_begin_authentication_finish (method_invocation);
}
g_list_free (list);
}
static void
handle_end_authentication (_PolkitAgentAuthenticationAgent *instance,
const gchar *cookie,
EggDBusMethodInvocation *method_invocation)
{
PolkitAgentAuthenticationAgent *agent = POLKIT_AGENT_AUTHENTICATION_AGENT (instance);
agent->end_func (agent,
cookie,
agent->user_data);
_polkit_agent_authentication_agent_handle_end_authentication_finish (method_invocation);
}
static void
authentication_agent_iface_init (_PolkitAgentAuthenticationAgentIface *agent_iface)
{
agent_iface->handle_begin_authentication = handle_begin_authentication;
agent_iface->handle_end_authentication = handle_end_authentication;
}
/*
* Copyright (C) 2008 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: David Zeuthen <davidz@redhat.com>
*/
#ifndef __POLKIT_AGENT_AUTHENTICATION_SESSION_H
#define __POLKIT_AGENT_AUTHENTICATION_SESSION_H
#include <polkit/polkit.h>
#include <polkitagent/polkitagenttypes.h>
G_BEGIN_DECLS
#define POLKIT_AGENT_TYPE_AUTHENTICATION_AGENT (polkit_agent_authentication_agent_get_type ())
#define POLKIT_AGENT_AUTHENTICATION_AGENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_AGENT_TYPE_AUTHENTICATION_AGENT, PolkitAgentAuthenticationAgent))
#define POLKIT_AGENT_AUTHENTICATION_AGENT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), POLKIT_AGENT_TYPE_AUTHENTICATION_AGENT, PolkitAgentAuthenticationAgentClass))
#define POLKIT_AGENT_AUTHENTICATION_AGENT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_AGENT_TYPE_AUTHENTICATION_AGENT,PolkitAgentAuthenticationAgentClass))
#define POLKIT_AGENT_IS_AUTHENTICATION_AGENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_AGENT_TYPE_AUTHENTICATION_AGENT))
#define POLKIT_AGENT_IS_AUTHENTICATION_AGENT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_AGENT_TYPE_AUTHENTICATION_AGENT))
#if 0
typedef struct _PolkitAgentAuthenticationAgent PolkitAgentAuthenticationAgent;
#endif
typedef struct _PolkitAgentAuthenticationAgentClass PolkitAgentAuthenticationAgentClass;
/* TODO: we probably want to express this interface in another way but this is good enough for now */
typedef gboolean (*PolkitAgentAuthenticationAgentBeginFunc) (PolkitAgentAuthenticationAgent *agent,
const gchar *action_id,
const gchar *cookie,
GList *identities,
GError **error,
gpointer user_data);
typedef void (*PolkitAgentAuthenticationAgentEndFunc) (PolkitAgentAuthenticationAgent *agent,
const gchar *cookie,
gpointer user_data);
GType polkit_agent_authentication_agent_get_type (void) G_GNUC_CONST;
PolkitAgentAuthenticationAgent *polkit_agent_authentication_agent_new (PolkitAgentAuthenticationAgentBeginFunc begin_func,
PolkitAgentAuthenticationAgentEndFunc end_func,
gpointer user_data,
GError **error);
/* --- */
G_END_DECLS
#endif /* __POLKIT_AGENT_AUTHENTICATION_SESSION_H */
......@@ -36,9 +36,9 @@
#include <sys/wait.h>
#include <pwd.h>
#include "polkitauthenticationsession.h"
#include "polkitagentauthenticationsession.h"
struct _PolkitAuthenticationSession
struct _PolkitAgentAuthenticationSession
{