Commit 20d7b8fe authored by David Zeuthen's avatar David Zeuthen

api cleanup (part 1)

parent 08df7620
......@@ -36,7 +36,9 @@ polkit_backendd_CPPFLAGS = \
$(AM_CPPFLAGS)
polkit_backendd_LDADD = \
$(DBUS_GLIB_LIBS) $(top_builddir)/src/polkit/libpolkit-1.la
$(DBUS_GLIB_LIBS) \
$(top_builddir)/src/kit/libkit.la \
$(top_builddir)/src/polkit/libpolkit-1.la
servicedir = $(datadir)/dbus-1/system-services
......
......@@ -9,5 +9,10 @@
<arg name="result" direction="out" type="s"/>
</method>
<method name="GetPolicyEntries">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="result" direction="out" type="as"/>
</method>
</interface>
</node>
......@@ -49,6 +49,9 @@
#include "polkit-daemon-backend.h"
#include <polkit/polkit.h>
#include <polkit/polkit-private.h>
static gboolean no_exit = FALSE;
/*--------------------------------------------------------------------------------------------------------------*/
......@@ -253,6 +256,37 @@ polkit_daemon_backend_hello (PolKitDaemonBackend *daemon,
s = g_strdup_printf ("You said '%s'", message);
dbus_g_method_return (context, s);
g_free (s);
return TRUE;
}
/*--------------------------------------------------------------------------------------------------------------*/
gboolean
polkit_daemon_backend_get_policy_entries (PolKitDaemonBackend *daemon,
DBusGMethodInvocation *context)
{
GPtrArray *a;
PolKitPolicyCache *c;
c = _polkit_policy_cache_new (PACKAGE_DATA_DIR "polkit-1/actions", TRUE, NULL);
polkit_policy_cache_unref (c);
a = g_ptr_array_new ();
g_ptr_array_add (a, g_strdup ("foo"));
g_ptr_array_add (a, g_strdup ("bar"));
g_ptr_array_add (a, g_strdup ("baz"));
g_ptr_array_add (a, NULL);
dbus_g_method_return (context, a->pdata);
g_ptr_array_foreach (a, (GFunc) g_free, NULL);
g_ptr_array_free (a, TRUE);
return TRUE;
}
/*--------------------------------------------------------------------------------------------------------------*/
......@@ -73,6 +73,9 @@ gboolean polkit_daemon_backend_hello (PolKitDaemonBackend *daemon,
const char *message,
DBusGMethodInvocation *context);
gboolean polkit_daemon_backend_get_policy_entries (PolKitDaemonBackend *daemon,
DBusGMethodInvocation *context);
G_END_DECLS
#endif /* __POLKIT_DAEMON_BACKEND_H__ */
......@@ -31,17 +31,15 @@ libpolkit_1include_HEADERS = \
polkit-seat.h \
polkit-session.h \
polkit-caller.h \
polkit-policy-file-entry.h \
polkit-policy-file.h \
polkit-policy-cache.h \
polkit-policy-default.h \
polkit-action-description.h \
polkit-implicit-authorization.h \
polkit-authorization.h \
polkit-authorization-constraint.h \
polkit-authorization-db.h \
polkit-tracker.h \
polkit-simple.h
libpolkit_1_la_SOURCES = \
libpolkit_1_la_SOURCES = \
polkit.h \
polkit-private.h \
polkit-types.h \
......@@ -53,10 +51,8 @@ libpolkit_1_la_SOURCES = \
polkit-seat.h polkit-seat.c \
polkit-session.h polkit-session.c \
polkit-caller.h polkit-caller.c \
polkit-policy-file-entry.h polkit-policy-file-entry.c \
polkit-policy-file.h polkit-policy-file.c \
polkit-policy-cache.h polkit-policy-cache.c \
polkit-policy-default.h polkit-policy-default.c \
polkit-action-description.h polkit-action-description.c \
polkit-implicit-authorization.h polkit-implicit-authorization.c \
polkit-debug.h polkit-debug.c \
polkit-utils.h polkit-utils.c \
polkit-authorization.h polkit-authorization.c \
......
......@@ -31,62 +31,62 @@
#error "Only <polkit/polkit.h> can be included directly, this file may disappear or change contents."
#endif
#ifndef POLKIT_POLICY_FILE_ENTRY_H
#define POLKIT_POLICY_FILE_ENTRY_H
#ifndef POLKIT_ACTION_DESCRIPTION_H
#define POLKIT_ACTION_DESCRIPTION_H
#include <polkit/polkit-types.h>
#include <polkit/polkit-result.h>
#include <polkit/polkit-policy-default.h>
#include <polkit/polkit-implicit-authorization.h>
#include <polkit/polkit-error.h>
POLKIT_BEGIN_DECLS
struct _PolKitPolicyFileEntry;
typedef struct _PolKitPolicyFileEntry PolKitPolicyFileEntry;
struct _PolKitActionDescription;
typedef struct _PolKitActionDescription PolKitActionDescription;
/**
* PolKitPolicyFileEntryAnnotationsForeachFunc:
* @policy_file_entry: the policy file entry
* PolKitActionDescriptionAnnotationsForeachFunc:
* @action_description: the policy file entry
* @key: key of the annotation
* @value: corrosponding value of the annotation
* @user_data: user data passed to polkit_policy_file_entry_annotations_foreach()
* @user_data: user data passed to polkit_action_description_annotations_foreach()
*
* Callback function for polkit_policy_file_entry_annotations_foreach().
* Callback function for polkit_action_description_annotations_foreach().
*
* Returns: Pass #TRUE to short-circuit, e.g. stop the iteration
**/
typedef polkit_bool_t (*PolKitPolicyFileEntryAnnotationsForeachFunc) (PolKitPolicyFileEntry *policy_file_entry,
typedef polkit_bool_t (*PolKitActionDescriptionAnnotationsForeachFunc) (PolKitActionDescription *action_description,
const char *key,
const char *value,
void *user_data);
PolKitPolicyFileEntry *polkit_policy_file_entry_ref (PolKitPolicyFileEntry *policy_file_entry);
void polkit_policy_file_entry_unref (PolKitPolicyFileEntry *policy_file_entry);
void polkit_policy_file_entry_debug (PolKitPolicyFileEntry *policy_file_entry);
PolKitActionDescription *polkit_action_description_ref (PolKitActionDescription *action_description);
void polkit_action_description_unref (PolKitActionDescription *action_description);
void polkit_action_description_debug (PolKitActionDescription *action_description);
const char *polkit_policy_file_entry_get_id (PolKitPolicyFileEntry *policy_file_entry);
PolKitPolicyDefault *polkit_policy_file_entry_get_default (PolKitPolicyFileEntry *policy_file_entry);
const char *polkit_action_description_get_id (PolKitActionDescription *action_description);
PolKitImplicitAuthorization *polkit_action_description_get_implicit_authorization (PolKitActionDescription *action_description);
const char *polkit_policy_file_entry_get_action_description (PolKitPolicyFileEntry *policy_file_entry);
const char *polkit_policy_file_entry_get_action_message (PolKitPolicyFileEntry *policy_file_entry);
const char *polkit_action_description_get_action_description (PolKitActionDescription *action_description);
const char *polkit_action_description_get_action_message (PolKitActionDescription *action_description);
const char *polkit_policy_file_entry_get_action_vendor (PolKitPolicyFileEntry *policy_file_entry);
const char *polkit_policy_file_entry_get_action_vendor_url (PolKitPolicyFileEntry *policy_file_entry);
const char *polkit_policy_file_entry_get_action_icon_name (PolKitPolicyFileEntry *policy_file_entry);
const char *polkit_action_description_get_action_vendor (PolKitActionDescription *action_description);
const char *polkit_action_description_get_action_vendor_url (PolKitActionDescription *action_description);
const char *polkit_action_description_get_action_icon_name (PolKitActionDescription *action_description);
polkit_bool_t polkit_policy_file_entry_annotations_foreach (PolKitPolicyFileEntry *policy_file_entry,
PolKitPolicyFileEntryAnnotationsForeachFunc cb,
polkit_bool_t polkit_action_description_annotations_foreach (PolKitActionDescription *action_description,
PolKitActionDescriptionAnnotationsForeachFunc cb,
void *user_data);
const char *polkit_policy_file_entry_get_annotation (PolKitPolicyFileEntry *policy_file_entry,
const char *polkit_action_description_get_annotation (PolKitActionDescription *action_description,
const char *key);
PolKitPolicyDefault *polkit_policy_file_entry_get_default_factory (PolKitPolicyFileEntry *policy_file_entry);
polkit_bool_t polkit_policy_file_entry_set_default (PolKitPolicyFileEntry *policy_file_entry,
PolKitPolicyDefault *defaults,
PolKitImplicitAuthorization *polkit_action_description_get_implicit_authorization_factory (PolKitActionDescription *action_description);
polkit_bool_t polkit_action_description_set_implicit_authorization (PolKitActionDescription *action_description,
PolKitImplicitAuthorization *implicit_authorzation,
PolKitError **error);
POLKIT_END_DECLS
#endif /* POLKIT_POLICY_FILE_ENTRY_H */
#endif /* POLKIT_ACTION_DESCRIPTION_H */
......@@ -134,22 +134,6 @@ oom:
return authdb;
}
polkit_bool_t
_polkit_authorization_db_pfe_foreach (PolKitPolicyCache *policy_cache,
PolKitPolicyCacheForeachFunc callback,
void *user_data)
{
return FALSE;
}
PolKitPolicyFileEntry*
_polkit_authorization_db_pfe_get_by_id (PolKitPolicyCache *policy_cache,
const char *action_id)
{
return NULL;
}
/**
* polkit_authorization_db_ref:
* @authdb: the object
......
This diff is collapsed.
......@@ -39,10 +39,10 @@
#include <polkit/polkit-result.h>
#include <polkit/polkit-context.h>
#include <polkit/polkit-action.h>
#include <polkit/polkit-action-description.h>
#include <polkit/polkit-seat.h>
#include <polkit/polkit-session.h>
#include <polkit/polkit-caller.h>
#include <polkit/polkit-policy-cache.h>
#include <polkit/polkit-authorization-db.h>
POLKIT_BEGIN_DECLS
......@@ -75,104 +75,26 @@ typedef void (*PolKitContextConfigChangedCB) (PolKitContext *pk_context,
void *user_data);
/**
* PolKitContextAddIOWatch:
* @pk_context: the polkit context
* @fd: the file descriptor to watch
*
* Type for function supplied by the application to integrate a watch
* on a file descriptor into the applications main loop. The
* application must call polkit_context_io_func() when there is data
* to read from the file descriptor.
*
* For glib mainloop, the function will typically look like this:
*
* <programlisting>
* static gboolean
* io_watch_have_data (GIOChannel *channel, GIOCondition condition, gpointer user_data)
* {
* int fd;
* PolKitContext *pk_context = user_data;
* fd = g_io_channel_unix_get_fd (channel);
* polkit_context_io_func (pk_context, fd);
* return TRUE;
* }
*
* static int
* io_add_watch (PolKitContext *pk_context, int fd)
* {
* guint id = 0;
* GIOChannel *channel;
* channel = g_io_channel_unix_new (fd);
* if (channel == NULL)
* goto out;
* id = g_io_add_watch (channel, G_IO_IN, io_watch_have_data, pk_context);
* if (id == 0) {
* g_io_channel_unref (channel);
* goto out;
* }
* g_io_channel_unref (channel);
* out:
* return id;
* }
* </programlisting>
*
* Returns: 0 if the watch couldn't be set up; otherwise an unique
* identifier for the watch.
**/
typedef int (*PolKitContextAddIOWatch) (PolKitContext *pk_context, int fd);
/**
* PolKitContextRemoveIOWatch:
* @pk_context: the context object
* @watch_id: the id obtained from using the supplied function
* of type #PolKitContextAddIOWatch
*
* Type for function supplied by the application to remove a watch set
* up via the supplied function of type #PolKitContextAddIOWatch
*
* For the glib mainloop, the function will typically look like this:
* PolKitActionDescriptionForeachFunc:
* @action_description: the entry
* @user_data: user data
*
* <programlisting>
* static void
* io_remove_watch (PolKitContext *pk_context, int watch_id)
* {
* g_source_remove (watch_id);
* }
* </programlisting>
* Type for function used in to iterate over action descriptions.
*
* Returns: #TRUE to short-circuit, e.g. stop the iteration
**/
typedef void (*PolKitContextRemoveIOWatch) (PolKitContext *pk_context, int watch_id);
typedef polkit_bool_t (*PolKitActionDescriptionForeachFunc) (PolKitActionDescription *action_description,
void *user_data);
PolKitContext *polkit_context_new (void);
void polkit_context_set_config_changed (PolKitContext *pk_context,
PolKitContextConfigChangedCB cb,
void *user_data);
void polkit_context_set_io_watch_functions (PolKitContext *pk_context,
PolKitContextAddIOWatch io_add_watch_func,
PolKitContextRemoveIOWatch io_remove_watch_func);
void polkit_context_set_load_descriptions (PolKitContext *pk_context);
polkit_bool_t polkit_context_init (PolKitContext *pk_context,
PolKitError **error);
PolKitContext *polkit_context_ref (PolKitContext *pk_context);
void polkit_context_unref (PolKitContext *pk_context);
void polkit_context_force_reload (PolKitContext *pk_context);
void polkit_context_io_func (PolKitContext *pk_context, int fd);
PolKitPolicyCache *polkit_context_get_policy_cache (PolKitContext *pk_context);
POLKIT_GNUC_DEPRECATED
PolKitResult polkit_context_can_session_do_action (PolKitContext *pk_context,
PolKitAction *action,
PolKitSession *session);
POLKIT_GNUC_DEPRECATED
PolKitResult polkit_context_can_caller_do_action (PolKitContext *pk_context,
PolKitAction *action,
PolKitCaller *caller);
PolKitResult polkit_context_is_caller_authorized (PolKitContext *pk_context,
PolKitAction *action,
PolKitCaller *caller,
......@@ -184,6 +106,20 @@ PolKitResult polkit_context_is_session_authorized (PolKitContext *pk_con
PolKitSession *session,
PolKitError **error);
polkit_bool_t polkit_context_action_description_foreach (PolKitContext *pk_context,
PolKitActionDescriptionForeachFunc cb,
void *user_data);
PolKitActionDescription *polkit_context_get_action_description (PolKitContext *pk_context,
const char *action_id);
/* TODO: move to private static lib */
polkit_bool_t polkit_action_description_get_from_file (const char *path,
PolKitActionDescriptionForeachFunc cb,
void *user_data,
PolKitError **error);
PolKitAuthorizationDB *polkit_context_get_authorization_db (PolKitContext *pk_context);
POLKIT_END_DECLS
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/***************************************************************************
*
* polkit-policy-default.c : policy definition for the defaults
* polkit-implicit-authorization.c : policy definition for the defaults
*
* Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
*
......@@ -42,13 +42,13 @@
#include "polkit-debug.h"
#include "polkit-error.h"
#include "polkit-policy-default.h"
#include "polkit-implicit-authorization.h"
#include "polkit-private.h"
#include "polkit-test.h"
#include "polkit-private.h"
/**
* SECTION:polkit-policy-default
* SECTION:polkit-implicit-authorization
* @title: Defaults
* @short_description: Models the default policy for an action.
*
......@@ -56,12 +56,12 @@
**/
/**
* PolKitPolicyDefault:
* PolKitImplicitAuthorization:
*
* Objects of this class are used to record information about a
* default policy for an action.
**/
struct _PolKitPolicyDefault
struct _PolKitImplicitAuthorization
{
int refcount;
PolKitResult default_any;
......@@ -70,7 +70,7 @@ struct _PolKitPolicyDefault
};
/**
* polkit_policy_default_new:
* polkit_implicit_authorization_new:
*
* Construct a new object with all defaults set as restrictive as possible.
*
......@@ -78,12 +78,12 @@ struct _PolKitPolicyDefault
*
* Since: 0.7
*/
PolKitPolicyDefault *
polkit_policy_default_new (void)
PolKitImplicitAuthorization *
polkit_implicit_authorization_new (void)
{
PolKitPolicyDefault *pd;
PolKitImplicitAuthorization *pd;
pd = kit_new0 (PolKitPolicyDefault, 1);
pd = kit_new0 (PolKitImplicitAuthorization, 1);
if (pd == NULL)
goto out;
pd->refcount = 1;
......@@ -95,8 +95,8 @@ out:
}
/**
* polkit_policy_default_clone:
* @policy_default: object to clone
* polkit_implicit_authorization_clone:
* @implicit_authorization: object to clone
*
* Create a new object with the same value as the given object
*
......@@ -104,36 +104,36 @@ out:
*
* Since: 0.7
*/
PolKitPolicyDefault *
polkit_policy_default_clone (PolKitPolicyDefault *policy_default)
PolKitImplicitAuthorization *
polkit_implicit_authorization_clone (PolKitImplicitAuthorization *implicit_authorization)
{
PolKitPolicyDefault *pd;
PolKitImplicitAuthorization *pd;
kit_return_val_if_fail (policy_default != NULL, NULL);
kit_return_val_if_fail (implicit_authorization != NULL, NULL);
pd = polkit_policy_default_new ();
pd = polkit_implicit_authorization_new ();
if (pd == NULL)
goto out;
pd->refcount = 1;
pd->default_any = policy_default->default_any;
pd->default_inactive = policy_default->default_inactive;
pd->default_active = policy_default->default_active;
pd->default_any = implicit_authorization->default_any;
pd->default_inactive = implicit_authorization->default_inactive;
pd->default_active = implicit_authorization->default_active;
out:
return pd;
}
/**
* polkit_policy_default_equals:
* @a: a #PolKitPolicyDefault object
* @b: a #PolKitPolicyDefault object
* polkit_implicit_authorization_equals:
* @a: a #PolKitImplicitAuthorization object
* @b: a #PolKitImplicitAuthorization object
*
* Compare if two objects are equal.
*
* Returns: %TRUE only if the objects are equal
*/
polkit_bool_t
polkit_policy_default_equals (PolKitPolicyDefault *a, PolKitPolicyDefault *b)
polkit_implicit_authorization_equals (PolKitImplicitAuthorization *a, PolKitImplicitAuthorization *b)
{
polkit_bool_t ret;
......@@ -151,14 +151,14 @@ polkit_policy_default_equals (PolKitPolicyDefault *a, PolKitPolicyDefault *b)
return ret;
}
PolKitPolicyDefault *
_polkit_policy_default_new (PolKitResult defaults_allow_any,
PolKitImplicitAuthorization *
_polkit_implicit_authorization_new (PolKitResult defaults_allow_any,
PolKitResult defaults_allow_inactive,
PolKitResult defaults_allow_active)
{
PolKitPolicyDefault *pd;
PolKitImplicitAuthorization *pd;
pd = kit_new0 (PolKitPolicyDefault, 1);
pd = kit_new0 (PolKitImplicitAuthorization, 1);
if (pd == NULL)
goto out;
pd->refcount = 1;
......@@ -170,63 +170,63 @@ out:
}
/**
* polkit_policy_default_ref:
* @policy_default: the policy object
* polkit_implicit_authorization_ref:
* @implicit_authorization: the policy object
*
* Increase reference count.
*
* Returns: the object
**/
PolKitPolicyDefault *
polkit_policy_default_ref (PolKitPolicyDefault *policy_default)
PolKitImplicitAuthorization *
polkit_implicit_authorization_ref (PolKitImplicitAuthorization *implicit_authorization)
{
kit_return_val_if_fail (policy_default != NULL, policy_default);
policy_default->refcount++;
return policy_default;
kit_return_val_if_fail (implicit_authorization != NULL, implicit_authorization);
implicit_authorization->refcount++;
return implicit_authorization;
}
/**
* polkit_policy_default_unref:
* @policy_default: the object
* polkit_implicit_authorization_unref:
* @implicit_authorization: the object
*
* Decreases the reference count of the object. If it becomes zero,
* the object is freed. Before freeing, reference counts on embedded
* objects are decresed by one.
**/
void
polkit_policy_default_unref (PolKitPolicyDefault *policy_default)
polkit_implicit_authorization_unref (PolKitImplicitAuthorization *implicit_authorization)
{
kit_return_if_fail (policy_default != NULL);
policy_default->refcount--;
if (policy_default->refcount > 0)
kit_return_if_fail (implicit_authorization != NULL);
implicit_authorization->refcount--;
if (implicit_authorization->refcount > 0)
return;
kit_free (policy_default);
kit_free (implicit_authorization);
}
/**
* polkit_policy_default_debug:
* @policy_default: the object
* polkit_implicit_authorization_debug:
* @implicit_authorization: the object
*
* Print debug details
**/
void
polkit_policy_default_debug (PolKitPolicyDefault *policy_default)
polkit_implicit_authorization_debug (PolKitImplicitAuthorization *implicit_authorization)
{
kit_return_if_fail (policy_default != NULL);
polkit_debug ("PolKitPolicyDefault: refcount=%d\n"
kit_return_if_fail (implicit_authorization != NULL);
polkit_debug ("PolKitImplicitAuthorization: refcount=%d\n"
" default_any=%s\n"
" default_inactive=%s\n"
" default_active=%s",
policy_default->refcount,
polkit_result_to_string_representation (policy_default->default_any),
polkit_result_to_string_representation (policy_default->default_inactive),
polkit_result_to_string_representation (policy_default->default_active));
implicit_authorization->refcount,
polkit_result_to_string_representation (implicit_authorization->default_any),
polkit_result_to_string_representation (implicit_authorization->default_inactive),
polkit_result_to_string_representation (implicit_authorization->default_active));
}
/**
* polkit_policy_default_can_session_do_action:
* @policy_default: the object
* polkit_implicit_authorization_can_session_do_action:
* @implicit_authorization: the object
* @action: the type of access to check for
* @session: the session in question
*
......@@ -237,7 +237,7 @@ polkit_policy_default_debug (PolKitPolicyDefault *policy_default)
* #POLKIT_RESULT_YES, #POLKIT_RESULT_NO.
**/
PolKitResult
polkit_policy_default_can_session_do_action (PolKitPolicyDefault *policy_default,
polkit_implicit_authorization_can_session_do_action (PolKitImplicitAuthorization *implicit_authorization,
PolKitAction *action,
PolKitSession *session)
{
......@@ -247,11 +247,11 @@ polkit_policy_default_can_session_do_action (PolKitPolicyDefault *policy_default
ret = POLKIT_RESULT_NO;
kit_return_val_if_fail (policy_default != NULL, ret);
kit_return_val_if_fail (implicit_authorization != NULL, ret);
kit_return_val_if_fail (action != NULL, ret);
kit_return_val_if_fail (session != NULL, ret);
ret = policy_default->default_any;
ret = implicit_authorization->default_any;
polkit_session_get_ck_is_local (session, &is_local);
polkit_session_get_ck_is_active (session, &is_active);
......@@ -260,17 +260,17 @@ polkit_policy_default_can_session_do_action (PolKitPolicyDefault *policy_default
goto out;
if (is_active) {
ret = policy_default->default_active;