Commit 49de132d authored by David Zeuthen's avatar David Zeuthen

Add properties with information about the currently used authority

Also bump requirement on EggDBus to 0.6 (to be released later) for a
bug-fix with flag properties.
parent 50385761
......@@ -124,7 +124,7 @@ PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.21.4 gio-2.0 >= 2.21.4])
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
PKG_CHECK_MODULES(EGG_DBUS, [eggdbus-1 >= 0.5])
PKG_CHECK_MODULES(EGG_DBUS, [eggdbus-1 >= 0.6])
AC_SUBST(EGG_DBUS_CFLAGS)
AC_SUBST(EGG_DBUS_LIBS)
......
......@@ -195,6 +195,37 @@
<!-- ---------------------------------------------------------------------------------------------------- -->
<!-- Flags describing what features the Authority implementation supports -->
<annotation name="org.gtk.EggDBus.DeclareFlags" value="AuthorityFeatures">
<annotation name="org.gtk.EggDBus.DocString.Summary" value="Authority Features"/>
<annotation name="org.gtk.EggDBus.DocString" value="Flags describing features supported by the Authority implementation."/>
<annotation name="org.gtk.EggDBus.Flags.Member" value="TemporaryAuthorization">
<annotation name="org.gtk.EggDBus.DocString" value="The authority supports temporary authorizations that can be obtained through authentication."/>
</annotation>
<annotation name="org.gtk.EggDBus.Flags.Member" value="Lockdown">
<annotation name="org.gtk.EggDBus.DocString" value="The authority supports the XXX method."/>
</annotation>
</annotation>
<!-- ---------------------------------------------------------------------------------------------------- -->
<property name="BackendName" type="s" access="read">
<annotation name="org.gtk.EggDBus.DocString" value="The name of the currently used Authority backend."/>
</property>
<property name="BackendVersion" type="s" access="read">
<annotation name="org.gtk.EggDBus.DocString" value="The version of the currently used Authority backend."/>
</property>
<property name="BackendFeatures" type="u" access="read">
<annotation name="org.gtk.EggDBus.Type" value="AuthorityFeatures"/>
<annotation name="org.gtk.EggDBus.DocString" value="The features supported by the currently used Authority backend."/>
</property>
<!-- ---------------------------------------------------------------------------------------------------- -->
<method name="EnumerateActions">
<annotation name="org.gtk.EggDBus.DocString" value="Enumerates all registered PolicyKit actions."/>
......
......@@ -19,8 +19,12 @@ POLKIT_UNIX_USER_GET_CLASS
<SECTION>
<FILE>polkitauthority</FILE>
PolkitAuthority
PolkitAuthorityFeatures
PolkitCheckAuthorizationFlags
polkit_authority_get
polkit_authority_get_backend_name
polkit_authority_get_backend_version
polkit_authority_get_backend_features
polkit_authority_check_authorization
polkit_authority_check_authorization_finish
polkit_authority_enumerate_actions
......@@ -265,6 +269,9 @@ POLKIT_DETAILS_GET_CLASS
POLKIT_BACKEND_AUTHORITY_EXTENSION_POINT_NAME
PolkitBackendAuthority
PolkitBackendAuthorityClass
polkit_backend_authority_get_name
polkit_backend_authority_get_version
polkit_backend_authority_get_features
polkit_backend_authority_check_authorization
polkit_backend_authority_check_authorization_finish
polkit_backend_authority_register_authentication_agent
......
......@@ -72,6 +72,24 @@ polkit_backend_null_authority_finalize (GObject *object)
G_OBJECT_CLASS (polkit_backend_null_authority_parent_class)->finalize (object);
}
static const gchar *
authority_get_name (PolkitBackendAuthority *authority)
{
return "null";
}
static const gchar *
authority_get_version (PolkitBackendAuthority *authority)
{
return PACKAGE_VERSION;
}
static PolkitAuthorityFeatures
authority_get_features (PolkitBackendAuthority *authority)
{
return POLKIT_AUTHORITY_FEATURES_NONE;
}
static void
polkit_backend_null_authority_class_init (PolkitBackendNullAuthorityClass *klass)
{
......@@ -83,6 +101,9 @@ polkit_backend_null_authority_class_init (PolkitBackendNullAuthorityClass *klass
gobject_class->finalize = polkit_backend_null_authority_finalize;
authority_class->get_name = authority_get_name;
authority_class->get_version = authority_get_version;
authority_class->get_features = authority_get_features;
authority_class->enumerate_actions = authority_enumerate_actions;
authority_class->check_authorization = authority_check_authorization;
authority_class->check_authorization_finish = authority_check_authorization_finish;
......
......@@ -20,7 +20,7 @@ BUILT_SOURCES = \
polkitenumtypes.c polkitenumtypes.h \
$(NULL)
enum_headers = polkitcheckauthorizationflags.h polkiterror.h polkitimplicitauthorization.h
enum_headers = polkitcheckauthorizationflags.h polkiterror.h polkitimplicitauthorization.h polkitauthorityfeatures.h
polkitenumtypes.h: $(enum_headers) polkitenumtypes.h.template
( top_builddir=`cd $(top_builddir) && pwd`; \
......@@ -46,7 +46,7 @@ polkit-built-sources.stamp : Makefile.am $(top_srcdir)/data/org.freedesktop.Poli
# keep in sync with contents of polkit-built-sources.stamp (Thanks autotools)
#
polkit_built_sources = _polkitactiondescription.c _polkitactiondescription.h _polkitauthenticationagent.c _polkitauthenticationagent.h _polkitauthority.c _polkitauthority.h _polkitauthorizationresult.c _polkitauthorizationresult.h _polkitbindings.c _polkitbindings.h _polkitbindingsmarshal.c _polkitbindingsmarshal.h _polkitbindingstypes.h _polkitcheckauthorizationflags.c _polkitcheckauthorizationflags.h _polkiterror.c _polkiterror.h _polkitidentity.c _polkitidentity.h _polkitimplicitauthorization.c _polkitimplicitauthorization.h _polkitsubject.c _polkitsubject.h _polkittemporaryauthorization.c _polkittemporaryauthorization.h docbook-interface-org.freedesktop.PolicyKit1.AuthenticationAgent.xml docbook-interface-org.freedesktop.PolicyKit1.Authority.xml _polkitbindingsmarshal.list
polkit_built_sources = _polkitactiondescription.c _polkitactiondescription.h _polkitauthenticationagent.c _polkitauthenticationagent.h _polkitauthority.c _polkitauthority.h _polkitauthorizationresult.c _polkitauthorizationresult.h _polkitbindings.c _polkitbindings.h _polkitbindingsmarshal.c _polkitbindingsmarshal.h _polkitbindingstypes.h _polkitcheckauthorizationflags.c _polkitcheckauthorizationflags.h _polkiterror.c _polkiterror.h _polkitidentity.c _polkitidentity.h _polkitimplicitauthorization.c _polkitimplicitauthorization.h _polkitsubject.c _polkitsubject.h _polkittemporaryauthorization.c _polkittemporaryauthorization.h docbook-interface-org.freedesktop.PolicyKit1.AuthenticationAgent.xml docbook-interface-org.freedesktop.PolicyKit1.Authority.xml _polkitbindingsmarshal.list _polkitauthorityfeatures.h _polkitauthorityfeatures.c
noinst_LTLIBRARIES = libpolkit-private.la
......@@ -73,6 +73,7 @@ libpolkit_gobject_1include_HEADERS = \
polkittypes.h \
polkitenumtypes.h \
polkitactiondescription.h \
polkitauthorityfeatures.h \
polkitdetails.h \
polkitauthority.h \
polkiterror.h \
......@@ -93,6 +94,7 @@ libpolkit_gobject_1_la_SOURCES = \
$(BUILT_SOURCES) \
polkit.h \
polkitactiondescription.c polkitactiondescription.h \
polkitauthorityfeatures.h polkitauthorityfeatures.c \
polkitdetails.c polkitdetails.h \
polkitauthority.c polkitauthority.h \
polkiterror.c polkiterror.h \
......
......@@ -28,6 +28,7 @@
#include <polkit/polkitenumtypes.h>
#include <polkit/polkitimplicitauthorization.h>
#include <polkit/polkitactiondescription.h>
#include <polkit/polkitauthorityfeatures.h>
#include <polkit/polkiterror.h>
#include <polkit/polkitidentity.h>
#include <polkit/polkitunixuser.h>
......
......@@ -27,6 +27,7 @@
#include "polkitcheckauthorizationflags.h"
#include "polkitauthority.h"
#include "polkiterror.h"
#include "polkitenumtypes.h"
#include "polkitprivate.h"
......@@ -62,6 +63,8 @@ struct _PolkitAuthority
EggDBusObjectProxy *authority_object_proxy;
_PolkitAuthority *real;
gchar *name;
gchar *version;
guint cancellation_id_counter;
};
......@@ -82,6 +85,14 @@ enum
LAST_SIGNAL,
};
enum
{
PROP_0,
PROP_BACKEND_NAME,
PROP_BACKEND_VERSION,
PROP_BACKEND_FEATURES
};
static guint signals[LAST_SIGNAL] = {0};
G_DEFINE_TYPE (PolkitAuthority, polkit_authority, G_TYPE_OBJECT);
......@@ -121,6 +132,8 @@ polkit_authority_finalize (GObject *object)
g_object_unref (authority->authority_object_proxy);
g_object_unref (authority->system_bus);
g_free (authority->name);
g_free (authority->version);
the_authority = NULL;
......@@ -128,12 +141,90 @@ polkit_authority_finalize (GObject *object)
G_OBJECT_CLASS (polkit_authority_parent_class)->finalize (object);
}
static void
polkit_authority_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
PolkitAuthority *authority = POLKIT_AUTHORITY (object);
switch (prop_id)
{
case PROP_BACKEND_NAME:
g_value_set_string (value, polkit_authority_get_backend_name (authority));
break;
case PROP_BACKEND_VERSION:
g_value_set_string (value, polkit_authority_get_backend_version (authority));
break;
case PROP_BACKEND_FEATURES:
g_value_set_flags (value, polkit_authority_get_backend_features (authority));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
polkit_authority_class_init (PolkitAuthorityClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = polkit_authority_finalize;
gobject_class->finalize = polkit_authority_finalize;
gobject_class->get_property = polkit_authority_get_property;
/**
* PolkitAuthority:backend-name:
*
* The name of the currently used Authority backend.
*/
g_object_class_install_property (gobject_class,
PROP_BACKEND_NAME,
g_param_spec_string ("backend-name",
"Backend name",
"The name of the currently used Authority backend.",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
/**
* PolkitAuthority:version:
*
* The version of the currently used Authority backend.
*/
g_object_class_install_property (gobject_class,
PROP_BACKEND_VERSION,
g_param_spec_string ("backend-version",
"Backend version",
"The version of the currently used Authority backend.",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
/**
* PolkitAuthority:backend-features:
*
* The features of the currently used Authority backend.
*/
g_object_class_install_property (gobject_class,
PROP_BACKEND_FEATURES,
g_param_spec_flags ("backend-features",
"Backend features",
"The features of the currently used Authority backend.",
POLKIT_TYPE_AUTHORITY_FEATURES,
POLKIT_AUTHORITY_FEATURES_NONE,
G_PARAM_READABLE |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
/**
* PolkitAuthority::changed:
......@@ -1391,3 +1482,49 @@ polkit_authority_revoke_temporary_authorization_by_id_sync (PolkitAuthority
}
/* ---------------------------------------------------------------------------------------------------- */
/**
* polkit_authority_get_backend_name:
* @authority: A #PolkitAuthority.
*
* Gets the name of the authority backend.
*
* Returns: The name of the backend.
*/
const gchar *
polkit_authority_get_backend_name (PolkitAuthority *authority)
{
if (authority->name == NULL)
authority->name = _polkit_authority_get_backend_name (authority->real);
return authority->name;
}
/**
* polkit_authority_get_backend_version:
* @authority: A #PolkitAuthority.
*
* Gets the version of the authority backend.
*
* Returns: The name of the backend.
*/
const gchar *
polkit_authority_get_backend_version (PolkitAuthority *authority)
{
if (authority->version == NULL)
authority->version = _polkit_authority_get_backend_version (authority->real);
return authority->version;
}
/**
* polkit_authority_get_backend_features:
* @authority: A #PolkitAuthority.
*
* Gets the features supported by the authority backend.
*
* Returns: Flags from #PolkitAuthorityFeatures.
*/
PolkitAuthorityFeatures
polkit_authority_get_backend_features (PolkitAuthority *authority)
{
return _polkit_authority_get_backend_features (authority->real);
}
......@@ -29,6 +29,7 @@
#include <glib-object.h>
#include <gio/gio.h>
#include <polkit/polkittypes.h>
#include <polkit/polkitauthorityfeatures.h>
G_BEGIN_DECLS
......@@ -48,6 +49,10 @@ GType polkit_authority_get_type (void) G_GNUC_CONST;
PolkitAuthority *polkit_authority_get (void);
const gchar *polkit_authority_get_backend_name (PolkitAuthority *authority);
const gchar *polkit_authority_get_backend_version (PolkitAuthority *authority);
PolkitAuthorityFeatures polkit_authority_get_backend_features (PolkitAuthority *authority);
/* ---------------------------------------------------------------------------------------------------- */
GList *polkit_authority_enumerate_actions_sync (PolkitAuthority *authority,
......
/*
* 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>
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "polkitcheckauthorizationflags.h"
#include "polkitprivate.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>
*/
#if !defined (_POLKIT_COMPILATION) && !defined(_POLKIT_INSIDE_POLKIT_H)
#error "Only <polkit/polkit.h> can be included directly, this file may disappear or change contents."
#endif
#ifndef __POLKIT_AUTHORITY_FEATURES_H
#define __POLKIT_AUTHORITY_FEATURES_H
#include <glib-object.h>
G_BEGIN_DECLS
/**
* PolkitAuthorityFeatures:
* @POLKIT_AUTHORITY_FEATURES_NONE: No flags set.
* @POLKIT_AUTHORITY_FEATURES_TEMPORARY_AUTHORIZATION: The authority supports temporary authorizations
* that can be obtained through authentication.
* @POLKIT_AUTHORITY_FEATURES_LOCKDOWN: The authority supports the XXX method.
*
* Flags describing features supported by the Authority implementation.
*/
typedef enum
{
POLKIT_AUTHORITY_FEATURES_NONE = 0,
POLKIT_AUTHORITY_FEATURES_TEMPORARY_AUTHORIZATION = (1<<0),
POLKIT_AUTHORITY_FEATURES_LOCKDOWN = (1<<1)
} PolkitAuthorityFeatures;
G_END_DECLS
#endif /* __POLKIT_AUTHORITY_FEATURES_H */
......@@ -45,8 +45,8 @@ GType polkit_check_authorization_flags_get_type (void) G_GNUC_CONST;
*/
typedef enum
{
POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE = 0x0000, /*< nick=none >*/
POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION = 0x0001,
POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE = 0,
POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION = (1<<0),
} PolkitCheckAuthorizationFlags;
G_END_DECLS
......
......@@ -93,6 +93,60 @@ polkit_backend_authority_system_bus_name_owner_changed (PolkitBackendAuthority
klass->system_bus_name_owner_changed (authority, name, old_owner, new_owner);
}
/**
* polkit_backend_authority_get_name:
* @authority: A #PolkitBackendAuthority.
*
* Gets the name of the authority backend.
*
* Returns: The name of the backend.
*/
const gchar *
polkit_backend_authority_get_name (PolkitBackendAuthority *authority)
{
PolkitBackendAuthorityClass *klass;
klass = POLKIT_BACKEND_AUTHORITY_GET_CLASS (authority);
if (klass->get_name == NULL)
return "(not set)";
return klass->get_name (authority);
}
/**
* polkit_backend_authority_get_version:
* @authority: A #PolkitBackendAuthority.
*
* Gets the version of the authority backend.
*
* Returns: The name of the backend.
*/
const gchar *
polkit_backend_authority_get_version (PolkitBackendAuthority *authority)
{
PolkitBackendAuthorityClass *klass;
klass = POLKIT_BACKEND_AUTHORITY_GET_CLASS (authority);
if (klass->get_version == NULL)
return "(not set)";
return klass->get_version (authority);
}
/**
* polkit_backend_authority_get_features:
* @authority: A #PolkitBackendAuthority.
*
* Gets the features supported by the authority backend.
*
* Returns: Flags from #PolkitAuthorityFeatures.
*/
PolkitAuthorityFeatures
polkit_backend_authority_get_features (PolkitBackendAuthority *authority)
{
PolkitBackendAuthorityClass *klass;
klass = POLKIT_BACKEND_AUTHORITY_GET_CLASS (authority);
if (klass->get_features == NULL)
return POLKIT_AUTHORITY_FEATURES_NONE;
return klass->get_features (authority);
}
/**
* polkit_backend_authority_enumerate_actions:
* @authority: A #PolkitBackendAuthority.
......@@ -483,6 +537,14 @@ struct _ServerClass
GObjectClass parent_class;
};
enum
{
PROP_0,
PROP_BACKEND_NAME,
PROP_BACKEND_VERSION,
PROP_BACKEND_FEATURES
};
static void authority_iface_init (_PolkitAuthorityIface *authority_iface);
G_DEFINE_TYPE_WITH_CODE (Server, server, G_TYPE_OBJECT,
......@@ -520,6 +582,35 @@ server_finalize (GObject *object)
g_hash_table_unref (server->cancellation_id_to_cancellable);
}
static void
server_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
Server *server = SERVER (object);
switch (prop_id)
{
case PROP_BACKEND_NAME:
g_value_set_string (value, polkit_backend_authority_get_name (server->authority));
break;
case PROP_BACKEND_VERSION:
g_value_set_string (value, polkit_backend_authority_get_version (server->authority));
break;
case PROP_BACKEND_FEATURES:
g_value_set_flags (value, polkit_backend_authority_get_features (server->authority));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
server_class_init (ServerClass *klass)
{
......@@ -528,6 +619,9 @@ server_class_init (ServerClass *klass)
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = server_finalize;
gobject_class->get_property = server_get_property;
g_assert (_polkit_authority_override_properties (gobject_class, PROP_BACKEND_NAME) == PROP_BACKEND_FEATURES);
}
static void
......
......@@ -112,6 +112,10 @@ struct _PolkitBackendAuthorityClass
/* VTable */
const gchar *(*get_name) (PolkitBackendAuthority *authority);
const gchar *(*get_version) (PolkitBackendAuthority *authority);
PolkitAuthorityFeatures (*get_features) (PolkitBackendAuthority *authority);
GList *(*enumerate_actions) (PolkitBackendAuthority *authority,
PolkitSubject *caller,
const gchar *locale,
......@@ -211,6 +215,10 @@ GType polkit_backend_authority_get_type (void) G_GNUC_CONST;
/* --- */
const gchar *polkit_backend_authority_get_name (PolkitBackendAuthority *authority);
const gchar *polkit_backend_authority_get_version (PolkitBackendAuthority *authority);
PolkitAuthorityFeatures polkit_backend_authority_get_features (PolkitBackendAuthority *authority);
void polkit_backend_authority_system_bus_name_owner_changed (PolkitBackendAuthority *authority,
const gchar *name,
const gchar *old_owner,
......
......@@ -276,6 +276,24 @@ polkit_backend_interactive_authority_finalize (GObject *object)
G_OBJECT_CLASS (polkit_backend_interactive_authority_parent_class)->finalize (object);
}
static const gchar *
polkit_backend_interactive_authority_get_name (PolkitBackendAuthority *authority)
{
return "interactive";
}
static const gchar *
polkit_backend_interactive_authority_get_version (PolkitBackendAuthority *authority)
{
return PACKAGE_VERSION;
}
static PolkitAuthorityFeatures
polkit_backend_interactive_authority_get_features (PolkitBackendAuthority *authority)
{
return POLKIT_AUTHORITY_FEATURES_TEMPORARY_AUTHORIZATION;
}
static void
polkit_backend_interactive_authority_class_init (PolkitBackendInteractiveAuthorityClass *klass)
{
......@@ -287,6 +305,9 @@ polkit_backend_interactive_authority_class_init (PolkitBackendInteractiveAuthori
gobject_class->finalize = polkit_backend_interactive_authority_finalize;
authority_class->get_name = polkit_backend_interactive_authority_get_name;
authority_class->get_version = polkit_backend_interactive_authority_get_version;
authority_class->get_features = polkit_backend_interactive_authority_get_features;
authority_class->system_bus_name_owner_changed = polkit_backend_interactive_authority_system_bus_name_owner_changed;
authority_class->enumerate_actions = polkit_backend_interactive_authority_enumerate_actions;
authority_class->check_authorization = polkit_backend_interactive_authority_check_authorization;
......
......@@ -161,16 +161,39 @@ polkit_backend_local_authority_finalize (GObject *object)
G_OBJECT_CLASS (polkit_backend_local_authority_parent_class)->finalize (object);
}
static const gchar *
polkit_backend_local_authority_get_name (PolkitBackendAuthority *authority)
{
return "local";
}
static const gchar *
polkit_backend_local_authority_get_version (PolkitBackendAuthority *authority)
{
return PACKAGE_VERSION;
}
static PolkitAuthorityFeatures
polkit_backend_local_authority_get_features (PolkitBackendAuthority *authority)
{
return POLKIT_AUTHORITY_FEATURES_TEMPORARY_AUTHORIZATION | POLKIT_AUTHORITY_FEATURES_LOCKDOWN;
}
static void
polkit_backend_local_authority_class_init (PolkitBackendLocalAuthorityClass *klass)
{
GObjectClass *gobject_class;
PolkitBackendAuthorityClass *authority_class;
PolkitBackendInteractiveAuthorityClass *interactive_authority_class;