libpolkit-privilege-file-entry.h libpolkit-privilege-file-entry.c \
libpolkit-privilege-file.h libpolkit-privilege-file.c \
libpolkit-privilege-cache.h libpolkit-privilege-cache.c \
- libpolkit-privilege-default.h libpolkit-privilege-default.c
+ libpolkit-privilege-default.h libpolkit-privilege-default.c \
+ libpolkit-debug.h libpolkit-debug.c
libpolkit_la_LIBADD = @GLIB_LIBS@ @DBUS_LIBS@
#include <errno.h>
#include <glib.h>
+#include "libpolkit-debug.h"
#include "libpolkit-caller.h"
/**
}
not_in_session:
- g_debug ("uid %d", uid);
- g_debug ("pid %d", pid);
- g_debug ("selinux context '%s'", selinux_context != NULL ? selinux_context : "(not set)");
- g_debug ("ck session '%s'", ck_session_objpath != NULL ? ck_session_objpath : "(not in a session)");
+ _pk_debug ("uid %d", uid);
+ _pk_debug ("pid %d", pid);
+ _pk_debug ("selinux context '%s'", selinux_context != NULL ? selinux_context : "(not set)");
+ _pk_debug ("ck session '%s'", ck_session_objpath != NULL ? ck_session_objpath : "(not in a session)");
caller = libpolkit_caller_new ();
libpolkit_caller_set_dbus_name (caller, dbus_name);
libpolkit_caller_debug (PolKitCaller *caller)
{
g_return_if_fail (caller != NULL);
- g_debug ("PolKitCaller: refcount=%d dbus_name=%s uid=%d pid=%d selinux_context=%s",
- caller->refcount, caller->dbus_name, caller->uid, caller->pid, caller->selinux_context);
+ _pk_debug ("PolKitCaller: refcount=%d dbus_name=%s uid=%d pid=%d selinux_context=%s",
+ caller->refcount, caller->dbus_name, caller->uid, caller->pid, caller->selinux_context);
if (caller->session != NULL)
libpolkit_session_debug (caller->session);
}
#include <errno.h>
#include <glib.h>
+#include "libpolkit-debug.h"
#include "libpolkit-context.h"
#include "libpolkit-privilege-cache.h"
* libpolkit_context_new:
* @error: return location for error
*
- * Create a new context.
+ * Create a new context; loads PolicyKit files from
+ * /etc/PolicyKit/privileges unless the environment variable
+ * $POLKIT_PRIVILEGE_DIR points to a location.
+ *
+ * If the environment $POLKIT_DEBUG is set, libpolkit will spew lots
+ * of debug.
*
* Returns: #NULL if @error was set, otherwise the #PolKitPrivilegeCache object
**/
pk_context = g_new0 (PolKitContext, 1);
pk_context->refcount = 1;
- dirname = getenv ("POLKIT_PRIV_DIR");
+ dirname = getenv ("POLKIT_PRIVILEGE_DIR");
if (dirname != NULL) {
- g_debug ("Using directory %s", dirname);
+ _pk_debug ("Using directory %s", dirname);
} else {
dirname = PACKAGE_SYSCONF_DIR "/PolicyKit/privileges";
}
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * libpolkit.c : library for querying system-wide policy
+ *
+ * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ **************************************************************************/
+
+/**
+ * SECTION:libpolkit-debug
+ * @short_description: Debug functions.
+ *
+ * These functions are used for debug purposes
+ **/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include "libpolkit-debug.h"
+
+/**
+ * pk_debug:
+ * @format: format
+ *
+ * Print debug message
+ **/
+void
+_pk_debug (const char *format, ...)
+{
+ va_list args;
+ static gboolean show_debug = FALSE;
+ static gboolean init = FALSE;
+
+ if (!init) {
+ init = TRUE;
+ if (getenv ("POLKIT_DEBUG") != NULL) {
+ show_debug = TRUE;
+ }
+ }
+
+ if (show_debug) {
+ va_start (args, format);
+ vfprintf (stdout, format, args);
+ va_end (args);
+ fprintf (stdout, "\n");
+ }
+}
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * libpolkit-debug.h : debug infrastructure for libpolkit
+ *
+ * Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+#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 */
+
+
#include <errno.h>
#include <glib.h>
+#include "libpolkit-debug.h"
#include "libpolkit-privilege-file.h"
#include "libpolkit-privilege-cache.h"
path = g_strdup_printf ("%s/%s", dirname, file);
- g_debug ("Loading %s", path);
+ _pk_debug ("Loading %s", path);
pf = libpolkit_privilege_file_new (path, error);
g_free (path);
GSList *i;
g_return_if_fail (privilege_cache != NULL);
- g_debug ("PolKitPrivilegeCache: refcount=%d num_entries=%d ...",
- privilege_cache->refcount,
- privilege_cache->priv_entries == NULL ? 0 : g_slist_length (privilege_cache->priv_entries));
+ _pk_debug ("PolKitPrivilegeCache: refcount=%d num_entries=%d ...",
+ privilege_cache->refcount,
+ privilege_cache->priv_entries == NULL ? 0 : g_slist_length (privilege_cache->priv_entries));
for (i = privilege_cache->priv_entries; i != NULL; i = g_slist_next (i)) {
PolKitPrivilegeFileEntry *pfe = i->data;
pfe = NULL;
+ /* I'm sure it would be easy to make this O(1)... */
+
g_return_val_if_fail (privilege_cache != NULL, NULL);
g_return_val_if_fail (privilege != NULL, NULL);
#include <errno.h>
#include <glib.h>
+#include "libpolkit-debug.h"
#include "libpolkit-error.h"
#include "libpolkit-privilege-default.h"
libpolkit_privilege_default_debug (PolKitPrivilegeDefault *privilege_default)
{
g_return_if_fail (privilege_default != NULL);
- g_debug ("PolKitPrivilegeDefault: refcount=%d\n"
- " default_remote_inactive=%s\n"
- " default_remote_active=%s\n"
- " default_local_inactive=%s\n"
- " default_local_active=%s",
- privilege_default->refcount,
- libpolkit_result_to_string_representation (privilege_default->default_remote_inactive),
- libpolkit_result_to_string_representation (privilege_default->default_remote_active),
- libpolkit_result_to_string_representation (privilege_default->default_local_inactive),
- libpolkit_result_to_string_representation (privilege_default->default_local_active));
+ _pk_debug ("PolKitPrivilegeDefault: refcount=%d\n"
+ " default_remote_inactive=%s\n"
+ " default_remote_active=%s\n"
+ " default_local_inactive=%s\n"
+ " default_local_active=%s",
+ privilege_default->refcount,
+ libpolkit_result_to_string_representation (privilege_default->default_remote_inactive),
+ libpolkit_result_to_string_representation (privilege_default->default_remote_active),
+ libpolkit_result_to_string_representation (privilege_default->default_local_inactive),
+ libpolkit_result_to_string_representation (privilege_default->default_local_active));
}
#include <errno.h>
#include <glib.h>
+#include "libpolkit-debug.h"
#include "libpolkit-error.h"
#include "libpolkit-result.h"
#include "libpolkit-privilege-file-entry.h"
libpolkit_privilege_file_entry_debug (PolKitPrivilegeFileEntry *privilege_file_entry)
{
g_return_if_fail (privilege_file_entry != NULL);
- g_debug ("PolKitPrivilegeFileEntry: refcount=%d privilege=%s",
- privilege_file_entry->refcount,
- privilege_file_entry->privilege);
+ _pk_debug ("PolKitPrivilegeFileEntry: refcount=%d privilege=%s",
+ privilege_file_entry->refcount,
+ privilege_file_entry->privilege);
libpolkit_privilege_default_debug (privilege_file_entry->defaults);
}
#include <errno.h>
#include <glib.h>
+#include "libpolkit-debug.h"
#include "libpolkit-privilege.h"
/**
libpolkit_privilege_debug (PolKitPrivilege *privilege)
{
g_return_if_fail (privilege != NULL);
- g_debug ("PolKitPrivilege: refcount=%d id=%s", privilege->refcount, privilege->id);
+ _pk_debug ("PolKitPrivilege: refcount=%d id=%s", privilege->refcount, privilege->id);
}
#include <errno.h>
#include <glib.h>
+#include "libpolkit-debug.h"
#include "libpolkit-resource.h"
/**
libpolkit_resource_debug (PolKitResource *resource)
{
g_return_if_fail (resource != NULL);
- g_debug ("PolKitResource: refcount=%d type=%s id=%s", resource->refcount, resource->type, resource->id);
+ _pk_debug ("PolKitResource: refcount=%d type=%s id=%s", resource->refcount, resource->type, resource->id);
}
#include <errno.h>
#include <glib.h>
+#include "libpolkit-debug.h"
#include "libpolkit-seat.h"
/**
libpolkit_seat_debug (PolKitSeat *seat)
{
g_return_if_fail (seat != NULL);
- g_debug ("PolKitSeat: refcount=%d objpath=%s", seat->refcount, seat->ck_objref);
+ _pk_debug ("PolKitSeat: refcount=%d objpath=%s", seat->refcount, seat->ck_objref);
}
#include <errno.h>
#include <glib.h>
+#include "libpolkit-debug.h"
#include "libpolkit-session.h"
dbus_message_unref (reply);
}
- g_debug ("is_active %d", is_active);
- g_debug ("is_local %d", is_local);
- g_debug ("uid %d", uid);
+ _pk_debug ("is_active %d", is_active);
+ _pk_debug ("is_local %d", is_local);
+ _pk_debug ("uid %d", uid);
if (!is_local) {
- g_debug ("remote host '%s'", remote_host);
+ _pk_debug ("remote host '%s'", remote_host);
}
- g_debug ("ck seat '%s'", seat_path);
+ _pk_debug ("ck seat '%s'", seat_path);
session = libpolkit_session_new ();
libpolkit_session_set_ck_is_active (session, is_active);
libpolkit_session_debug (PolKitSession *session)
{
g_return_if_fail (session != NULL);
- g_debug ("PolKitSession: refcount=%d objpath=%s is_active=%d is_local=%d remote_host=%s",
- session->refcount, session->ck_objref, session->is_active, session->is_local, session->remote_host);
+ _pk_debug ("PolKitSession: refcount=%d uid=%d objpath=%s is_active=%d is_local=%d remote_host=%s",
+ session->refcount, session->uid,
+ session->ck_objref, session->is_active, session->is_local, session->remote_host);
if (session->seat != NULL)
libpolkit_seat_debug (session->seat);
}
#include <glib.h>
#include "libpolkit.h"
+#include "libpolkit-debug.h"
/**
* libpolkit_get_seat_resource_association:
if (cache == NULL)
goto out;
- g_debug ("entering libpolkit_can_session_access_resource()");
+ _pk_debug ("entering libpolkit_can_session_access_resource()");
libpolkit_privilege_debug (privilege);
libpolkit_resource_debug (resource);
libpolkit_session_debug (session);
resource,
session);
out:
- g_debug ("... result was %s", libpolkit_result_to_string_representation (result));
+ _pk_debug ("... result was %s", libpolkit_result_to_string_representation (result));
return result;
}
if (cache == NULL)
goto out;
- g_debug ("entering libpolkit_can_caller_access_resource()");
+ _pk_debug ("entering libpolkit_can_caller_access_resource()");
libpolkit_privilege_debug (privilege);
libpolkit_resource_debug (resource);
libpolkit_caller_debug (caller);
caller);
out:
- g_debug ("... result was %s", libpolkit_result_to_string_representation (result));
+ _pk_debug ("... result was %s", libpolkit_result_to_string_representation (result));
return result;
}