Commit 192f04ce authored by David Zeuthen's avatar David Zeuthen
Browse files

remove all usage of glib from the header files

This paves the way for getting rid of a glib dependency; when and if
that happens is to be determined; right now it just doesn't make a lot
of sense to reimplement GKeyFile, GSList, GHashTable, g_spawn_sync and
other useful routines. But it might make sense if we want to get the
message bus daemon to link with libpolkit so you e.g. can say

 <policy polkit="acme-frobnicate">
   <allow send_interface="com.acme.Frobnicator"
 </policy>

to allow a caller on the system message bus to access that interface
if, and only if, he can do the "acme-frobnicate" action according to
PolicyKit.
parent 02a4c510
......@@ -140,7 +140,7 @@ libpolkit_action_set_action_id (PolKitAction *action, const char *action_id)
*
* Returns: TRUE iff the value was returned.
**/
gboolean
bool
libpolkit_action_get_action_id (PolKitAction *action, char **out_action_id)
{
g_return_val_if_fail (action != NULL, FALSE);
......@@ -205,7 +205,7 @@ libpolkit_action_get_param (PolKitAction *action, const char *key)
typedef struct {
PolKitAction *action;
PolKitActionParamForeachFunc cb;
gpointer user_data;
void *user_data;
} HashClosure;
static void
......@@ -224,7 +224,7 @@ _hash_cb (gpointer key, gpointer value, gpointer user_data)
* Calls the given function for each parameter on the object.
**/
void
libpolkit_action_param_foreach (PolKitAction *action, PolKitActionParamForeachFunc cb, gpointer user_data)
libpolkit_action_param_foreach (PolKitAction *action, PolKitActionParamForeachFunc cb, void *user_data)
{
HashClosure data;
......
......@@ -26,10 +26,7 @@
#ifndef LIBPOLKIT_ACTION_H
#define LIBPOLKIT_ACTION_H
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <glib.h>
#include <stdbool.h>
struct PolKitAction;
typedef struct PolKitAction PolKitAction;
......@@ -46,19 +43,19 @@ typedef struct PolKitAction PolKitAction;
typedef void (*PolKitActionParamForeachFunc) (PolKitAction *action,
const char *key,
const char *value,
gpointer user_data);
void *user_data);
PolKitAction *libpolkit_action_new (void);
PolKitAction *libpolkit_action_ref (PolKitAction *action);
PolKitAction *libpolkit_action_new (void);
PolKitAction *libpolkit_action_ref (PolKitAction *action);
void libpolkit_action_unref (PolKitAction *action);
void libpolkit_action_set_action_id (PolKitAction *action, const char *action_id);
gboolean libpolkit_action_get_action_id (PolKitAction *action, char **out_action_id);
bool libpolkit_action_get_action_id (PolKitAction *action, char **out_action_id);
void libpolkit_action_set_param (PolKitAction *action, const char *key, const char *value);
const char *libpolkit_action_get_param (PolKitAction *action, const char *key);
void libpolkit_action_param_foreach (PolKitAction *action, PolKitActionParamForeachFunc cb, gpointer user_data);
void libpolkit_action_param_foreach (PolKitAction *action, PolKitActionParamForeachFunc cb, void *user_data);
void libpolkit_action_debug (PolKitAction *action);
void libpolkit_action_debug (PolKitAction *action);
#endif /* LIBPOLKIT_ACTION_H */
......
......@@ -205,7 +205,7 @@ libpolkit_caller_set_ck_session (PolKitCaller *caller, PolKitSession *session)
*
* Returns: TRUE iff the value is returned
**/
gboolean
bool
libpolkit_caller_get_dbus_name (PolKitCaller *caller, char **out_dbus_name)
{
g_return_val_if_fail (caller != NULL, FALSE);
......@@ -223,7 +223,7 @@ libpolkit_caller_get_dbus_name (PolKitCaller *caller, char **out_dbus_name)
*
* Returns: TRUE iff the value is returned
**/
gboolean
bool
libpolkit_caller_get_uid (PolKitCaller *caller, uid_t *out_uid)
{
g_return_val_if_fail (caller != NULL, FALSE);
......@@ -241,7 +241,7 @@ libpolkit_caller_get_uid (PolKitCaller *caller, uid_t *out_uid)
*
* Returns: TRUE iff the value is returned
**/
gboolean
bool
libpolkit_caller_get_pid (PolKitCaller *caller, pid_t *out_pid)
{
g_return_val_if_fail (caller != NULL, FALSE);
......@@ -260,7 +260,7 @@ libpolkit_caller_get_pid (PolKitCaller *caller, pid_t *out_pid)
*
* Returns: TRUE iff the value is returned
**/
gboolean
bool
libpolkit_caller_get_selinux_context (PolKitCaller *caller, char **out_selinux_context)
{
g_return_val_if_fail (caller != NULL, FALSE);
......@@ -279,7 +279,7 @@ libpolkit_caller_get_selinux_context (PolKitCaller *caller, char **out_selinux_c
*
* Returns: TRUE iff the value is returned
**/
gboolean
bool
libpolkit_caller_get_ck_session (PolKitCaller *caller, PolKitSession **out_session)
{
g_return_val_if_fail (caller != NULL, FALSE);
......
......@@ -26,10 +26,8 @@
#ifndef LIBPOLKIT_CALLER_H
#define LIBPOLKIT_CALLER_H
#include <stdio.h>
#include <unistd.h>
#include <stdbool.h>
#include <sys/types.h>
#include <glib.h>
#include <dbus/dbus.h>
#include <libpolkit/libpolkit-session.h>
......@@ -46,11 +44,11 @@ void libpolkit_caller_set_uid (PolKitCaller *caller,
void libpolkit_caller_set_pid (PolKitCaller *caller, pid_t pid);
void libpolkit_caller_set_selinux_context (PolKitCaller *caller, const char *selinux_context);
void libpolkit_caller_set_ck_session (PolKitCaller *caller, PolKitSession *session);
gboolean libpolkit_caller_get_dbus_name (PolKitCaller *caller, char **out_dbus_name);
gboolean libpolkit_caller_get_uid (PolKitCaller *caller, uid_t *out_uid);
gboolean libpolkit_caller_get_pid (PolKitCaller *caller, pid_t *out_pid);
gboolean libpolkit_caller_get_selinux_context (PolKitCaller *caller, char **out_selinux_context);
gboolean libpolkit_caller_get_ck_session (PolKitCaller *caller, PolKitSession **out_session);
bool libpolkit_caller_get_dbus_name (PolKitCaller *caller, char **out_dbus_name);
bool libpolkit_caller_get_uid (PolKitCaller *caller, uid_t *out_uid);
bool libpolkit_caller_get_pid (PolKitCaller *caller, pid_t *out_pid);
bool libpolkit_caller_get_selinux_context (PolKitCaller *caller, char **out_selinux_context);
bool libpolkit_caller_get_ck_session (PolKitCaller *caller, PolKitSession **out_session);
void libpolkit_caller_debug (PolKitCaller *caller);
......
......@@ -66,7 +66,7 @@ struct PolKitContext
int refcount;
PolKitContextConfigChangedCB config_changed_cb;
gpointer config_changed_user_data;
void *config_changed_user_data;
PolKitContextFileMonitorAddWatch file_monitor_add_watch_func;
PolKitContextFileMonitorRemoveWatch file_monitor_remove_watch_func;
......@@ -94,7 +94,7 @@ libpolkit_context_new (void)
return pk_context;
}
static gboolean
static bool
unload_modules (PolKitContext *pk_context)
{
GSList *i;
......@@ -109,11 +109,11 @@ unload_modules (PolKitContext *pk_context)
return TRUE;
}
static gboolean
load_modules (PolKitContext *pk_context, GError **error)
static bool
load_modules (PolKitContext *pk_context, PolKitError **error)
{
const char *config_file;
gboolean ret;
bool ret;
char *buf;
char *end;
char line[256];
......@@ -122,17 +122,24 @@ load_modules (PolKitContext *pk_context, GError **error)
gsize len;
int line_number;
int mod_number;
GError *g_error;
ret = FALSE;
buf = NULL;
mod_number = 0;
config_file = PACKAGE_SYSCONF_DIR "/PolicyKit/PolicyKit.conf";
g_error = NULL;
if (!g_file_get_contents (config_file,
&buf,
&len,
error)) {
&g_error)) {
_pk_debug ("Cannot load PolicyKit configuration file at '%s'", config_file);
polkit_error_set_error (error, POLKIT_ERROR_POLICY_FILE_INVALID,
"Cannot load PolicyKit configuration file at '%s': %s",
config_file,
g_error->message);
g_error_free (g_error);
goto out;
}
......@@ -223,7 +230,7 @@ static void
_config_file_events (PolKitContext *pk_context,
PolKitContextFileMonitorEvent event_mask,
const char *path,
gpointer user_data)
void *user_data)
{
_pk_debug ("Config file changed");
unload_modules (pk_context);
......@@ -239,7 +246,7 @@ static void
_policy_dir_events (PolKitContext *pk_context,
PolKitContextFileMonitorEvent event_mask,
const char *path,
gpointer user_data)
void *user_data)
{
/* mark cache of policy files as stale.. (will be populated on-demand, see _get_cache()) */
if (pk_context->priv_cache != NULL) {
......@@ -265,8 +272,8 @@ _policy_dir_events (PolKitContext *pk_context,
*
* Returns: #FALSE if @error was set, otherwise #TRUE
**/
gboolean
libpolkit_context_init (PolKitContext *pk_context, GError **error)
bool
libpolkit_context_init (PolKitContext *pk_context, PolKitError **error)
{
const char *dirname;
......@@ -373,8 +380,8 @@ libpolkit_context_unref (PolKitContext *pk_context)
**/
void
libpolkit_context_set_config_changed (PolKitContext *pk_context,
PolKitContextConfigChangedCB cb,
gpointer user_data)
PolKitContextConfigChangedCB cb,
void *user_data)
{
g_return_if_fail (pk_context != NULL);
pk_context->config_changed_cb = cb;
......@@ -414,7 +421,7 @@ libpolkit_context_get_policy_cache (PolKitContext *pk_context)
g_return_val_if_fail (pk_context != NULL, NULL);
if (pk_context->priv_cache == NULL) {
GError *error;
PolKitError *error;
_pk_debug ("Populating cache from directory %s", pk_context->policy_dir);
......@@ -422,8 +429,8 @@ libpolkit_context_get_policy_cache (PolKitContext *pk_context)
pk_context->priv_cache = libpolkit_policy_cache_new (pk_context->policy_dir, &error);
if (pk_context->priv_cache == NULL) {
g_warning ("Error loading policy files from %s: %s",
pk_context->policy_dir, error->message);
g_error_free (error);
pk_context->policy_dir, polkit_error_get_error_message (error));
polkit_error_free (error);
} else {
libpolkit_policy_cache_debug (pk_context->priv_cache);
}
......@@ -459,7 +466,7 @@ libpolkit_context_get_policy_cache (PolKitContext *pk_context)
PolKitResult
libpolkit_context_get_seat_resource_association (PolKitContext *pk_context,
PolKitSeatVisitorCB visitor,
gpointer *user_data)
void *user_data)
{
return LIBPOLKIT_RESULT_YES;
}
......
......@@ -26,11 +26,7 @@
#ifndef LIBPOLKIT_CONTEXT_H
#define LIBPOLKIT_CONTEXT_H
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <glib.h>
#include <stdbool.h>
#include <libpolkit/libpolkit-error.h>
#include <libpolkit/libpolkit-result.h>
#include <libpolkit/libpolkit-context.h>
......@@ -63,7 +59,7 @@ typedef struct PolKitContext PolKitContext;
* timeframe.
*/
typedef void (*PolKitContextConfigChangedCB) (PolKitContext *pk_context,
gpointer user_data);
void *user_data);
/**
* PolKitContextFileMonitorEvent:
......@@ -96,7 +92,7 @@ typedef enum
typedef void (*PolKitContextFileMonitorNotifyFunc) (PolKitContext *pk_context,
PolKitContextFileMonitorEvent event_mask,
const char *path,
gpointer user_data);
void *user_data);
/**
* PolKitContextFileMonitorAddWatch:
......@@ -114,11 +110,11 @@ typedef void (*PolKitContextFileMonitorNotifyFunc) (PolKitContext
* be watched. Caller can remove the watch using the supplied function
* of type #PolKitContextFileMonitorRemoveWatch and the handle.
*/
typedef guint (*PolKitContextFileMonitorAddWatch) (PolKitContext *pk_context,
const char *path,
PolKitContextFileMonitorEvent event_mask,
PolKitContextFileMonitorNotifyFunc notify_cb,
gpointer user_data);
typedef int (*PolKitContextFileMonitorAddWatch) (PolKitContext *pk_context,
const char *path,
PolKitContextFileMonitorEvent event_mask,
PolKitContextFileMonitorNotifyFunc notify_cb,
void *user_data);
/**
* PolKitContextFileMonitorRemoveWatch:
......@@ -130,18 +126,18 @@ typedef guint (*PolKitContextFileMonitorAddWatch) (PolKitContext
* type #PolKitContextFileMonitorAddWatch.
*/
typedef void (*PolKitContextFileMonitorRemoveWatch) (PolKitContext *pk_context,
guint watch_id);
int watch_id);
PolKitContext *libpolkit_context_new (void);
void libpolkit_context_set_config_changed (PolKitContext *pk_context,
PolKitContextConfigChangedCB cb,
gpointer user_data);
void *user_data);
void libpolkit_context_set_file_monitor (PolKitContext *pk_context,
PolKitContextFileMonitorAddWatch add_watch_func,
PolKitContextFileMonitorRemoveWatch remove_watch_func);
gboolean libpolkit_context_init (PolKitContext *pk_context,
GError **error);
bool libpolkit_context_init (PolKitContext *pk_context,
PolKitError **error);
PolKitContext *libpolkit_context_ref (PolKitContext *pk_context);
void libpolkit_context_unref (PolKitContext *pk_context);
......@@ -157,12 +153,12 @@ PolKitPolicyCache *libpolkit_context_get_policy_cache (PolKitContext *pk_context
*/
typedef void (*PolKitSeatVisitorCB) (PolKitSeat *seat,
PolKitResource **resources_associated_with_seat,
gpointer user_data);
void *user_data);
PolKitResult
libpolkit_context_get_seat_resource_association (PolKitContext *pk_context,
PolKitSeatVisitorCB visitor,
gpointer *user_data);
void *user_data);
PolKitResult
libpolkit_context_is_resource_associated_with_seat (PolKitContext *pk_context,
......
......@@ -34,10 +34,12 @@
# include <config.h>
#endif
#include <stdbool.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include "libpolkit-debug.h"
......@@ -51,13 +53,13 @@ void
_pk_debug (const char *format, ...)
{
va_list args;
static gboolean show_debug = FALSE;
static gboolean init = FALSE;
static bool show_debug = false;
static bool init = false;
if (!init) {
init = TRUE;
init = true;
if (getenv ("POLKIT_DEBUG") != NULL) {
show_debug = TRUE;
show_debug = true;
}
}
......
......@@ -26,11 +26,6 @@
#ifndef LIBPOLKIT_DEBUG_H
#define LIBPOLKIT_DEBUG_H
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <glib.h>
void _pk_debug (const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
#endif /* LIBPOLKIT_DEBUG_H */
......
......@@ -34,6 +34,7 @@
# include <config.h>
#endif
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -44,18 +45,96 @@
#include <errno.h>
#include <glib.h>
#include "libpolkit-error.h"
/**
* PolKitError:
*
* Objects of this class are used for error reporting.
**/
struct PolKitError
{
bool is_static;
PolKitErrorCode error_code;
char *error_message;
};
//static PolKitError _oom_error = {true, POLKIT_ERROR_OUT_OF_MEMORY, "Out of memory"};
/**
* polkit_error_get_error_code:
* @error: the error object
*
* Returns the error code.
*
* Returns: A value from the #PolKitErrorCode enumeration.
**/
PolKitErrorCode
polkit_error_get_error_code (PolKitError *error)
{
g_return_val_if_fail (error != NULL, -1);
return error->error_code;
}
/**
* libpolkit_error_quark:
* polkit_error_get_error_message:
* @error: the error object
*
* Returns error domain for PolicyKit library.
* Get the error message.
*
* Returns: The error domain
* Returns: A string describing the error. Caller shall not free this string.
**/
GQuark
libpolkit_error_quark (void)
const char *
polkit_error_get_error_message (PolKitError *error)
{
return g_quark_from_static_string ("libpolkit-error-quark");
g_return_val_if_fail (error != NULL, NULL);
return error->error_message;
}
/**
* polkit_error_free:
* @error: the error
*
* Free an error.
**/
void
polkit_error_free (PolKitError *error)
{
g_return_if_fail (error != NULL);
if (!error->is_static) {
g_free (error->error_message);
g_free (error);
}
}
/**
* polkit_error_set_error:
* @error: the error object
* @error_code: A value from the #PolKitErrorCode enumeration.
* @format: printf style formatting string
* @Varargs: printf style arguments
*
* Sets an error. If OOM, the error will be set to a pre-allocated OOM error.
**/
void
polkit_error_set_error (PolKitError **error, PolKitErrorCode error_code, const char *format, ...)
{
va_list args;
PolKitError *e;
if (*error == NULL)
return;
e = g_new0 (PolKitError, 1);
e->is_static = false;
e->error_code = error_code;
va_start (args, format);
e->error_message = g_strdup_vprintf (format, args);
va_end (args);
*error = e;
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/***************************************************************************
*
* libpolkit-error.h : GError error codes from PolicyKit
* libpolkit-error.h : error reporting from PolicyKit
*
* Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
*
......@@ -26,28 +26,25 @@
#ifndef LIBPOLKIT_ERROR_H
#define LIBPOLKIT_ERROR_H
#include <glib.h>
/**
* PolKitError:
* PolKitErrorCode:
* @POLKIT_ERROR_OUT_OF_MEMORY: Out of memory
* @POLKIT_ERROR_POLICY_FILE_INVALID: There was an error parsing the given policy file
*
* Error codes returned by PolicyKit
*/
typedef enum
{
POLKIT_ERROR_OUT_OF_MEMORY,
POLKIT_ERROR_POLICY_FILE_INVALID
} PolKitError;
/**
* POLKIT_ERROR:
*
* Error domain for PolicyKit library. Errors in this domain will be
* from the #PolKitError enumeration. See GError for details.
**/
#define POLKIT_ERROR libpolkit_error_quark()
} PolKitErrorCode;
GQuark libpolkit_error_quark (void);
struct PolKitError;
typedef struct PolKitError PolKitError;
PolKitErrorCode polkit_error_get_error_code (PolKitError *error);
const char *polkit_error_get_error_message (PolKitError *error);
void polkit_error_free (PolKitError *error);
void polkit_error_set_error (PolKitError **error, PolKitErrorCode error_code, const char *format, ...) __attribute__((__format__ (__printf__, 3, 4)));
#endif /* LIBPOLKIT_RESULT_H */
#endif /* LIBPOLKIT_ERROR_H */
......@@ -37,6 +37,8 @@
#include <regex.h>
#include <pwd.h>
#include <grp.h>
#include <glib.h>
#include <unistd.h>
#include "libpolkit-debug.h"
#include "libpolkit-module.h"
......@@ -52,7 +54,7 @@ struct PolKitModuleInterface
void *dlopen_handle;
char *name;
gpointer module_user_data;
void *module_user_data;
PolKitModuleControl module_control;
PolKitModuleInitialize func_initialize;
......@@ -62,7 +64,7 @@ struct PolKitModuleInterface
PolKitModuleCanSessionAccessResource func_can_session_access_resource;
PolKitModuleCanCallerAccessResource func_can_caller_access_resource;
gboolean builtin_have_action_regex;
bool builtin_have_action_regex;
regex_t builtin_action_regex_compiled;
GSList *builtin_users;
......@@ -107,13 +109,13 @@ _parse_builtin_remove_option (int *argc, char *argv[], int position)
(*argc)--;
}
static gboolean
static bool
_parse_builtin (PolKitModuleInterface *mi, int *argc, char *argv[])
{
int n;
gboolean ret;
bool ret;
ret = FALSE;
ret = false;
for (n = 1; n < *argc; ) {
if (g_str_has_prefix (argv[n], "action=")) {
......@@ -129,7 +131,7 @@ _parse_builtin (PolKitModuleInterface *mi, int *argc, char *argv[])
_pk_debug ("Regex '%s' didn't compile", regex);
goto error;
}
mi->builtin_have_action_regex = TRUE;
mi->builtin_have_action_regex = true;
_pk_debug ("Compiled regex '%s' for option 'action=' OK", regex);
......@@ -163,7 +165,7 @@ _parse_builtin (PolKitModuleInterface *mi, int *argc, char *argv[])
}
}
ret = TRUE;
ret = true;
error:
return ret;
......@@ -185,7 +187,7 @@ libpolkit_module_interface_load_module (const char *name, PolKitModuleControl mo
{
void *handle;
PolKitModuleInterface *mi;
gboolean (*func) (PolKitModuleInterface *);
bool (*func) (PolKitModuleInterface *);
mi = NULL;
......@@ -554,12 +556,12 @@ libpolkit_module_control_to_string_representation (PolKitModuleControl module_co
*
* Returns: TRUE if the textual representation was valid, otherwise FALSE
**/
gboolean
bool
libpolkit_module_control_from_string_representation (const char *string, PolKitModuleControl *out_module_control)
{
int n;
g_return_val_if_fail (out_module_control != NULL, FALSE);
g_return_val_if_fail (out_module_control != NULL, false);