PolicyKit: Branch 'master'

David Zeuthen david at kemper.freedesktop.org
Sat Nov 10 15:21:09 PST 2007


 configure.in                                 |   14 
 doc/Makefile.am                              |    4 
 doc/polkit-docs.xml                          |   21 -
 src/Makefile.am                              |    2 
 src/kit/Makefile.am                          |   74 +++
 src/kit/kit-file.c                           |  314 +++++++++++++++
 src/kit/kit-file.h                           |   44 ++
 src/kit/kit-hash.c                           |  533 +++++++++++++++++++++++++
 src/kit/kit-hash.h                           |  148 +++++++
 src/kit/kit-list.c                           |  314 +++++++++++++++
 src/kit/kit-list.h                           |   85 ++++
 src/kit/kit-memory.c                         |  281 +++++++++++++
 src/kit/kit-memory.h                         |   75 +++
 src/kit/kit-message.c                        |  109 +++++
 src/kit/kit-message.h                        |   44 ++
 src/kit/kit-string.c                         |  279 +++++++++++++
 src/kit/kit-string.h                         |   49 ++
 src/kit/kit-test.c                           |  113 +++++
 src/kit/kit-test.h                           |   61 ++
 src/kit/kit.h                                |  141 ++++++
 src/polkit-dbus/polkit-read-auth-helper.c    |    6 
 src/polkit/Makefile.am                       |    8 
 src/polkit/polkit-action.c                   |   58 +-
 src/polkit/polkit-authorization-constraint.c |  123 ++---
 src/polkit/polkit-authorization-db-dummy.c   |    8 
 src/polkit/polkit-authorization-db.c         |  135 +++++-
 src/polkit/polkit-authorization.c            |   95 ++--
 src/polkit/polkit-caller.c                   |  109 ++---
 src/polkit/polkit-config.c                   |    5 
 src/polkit/polkit-context.c                  |   20 
 src/polkit/polkit-error.c                    |   44 +-
 src/polkit/polkit-hash.c                     |  560 ---------------------------
 src/polkit/polkit-hash.h                     |  147 -------
 src/polkit/polkit-list.c                     |  330 ---------------
 src/polkit/polkit-list.h                     |   85 ----
 src/polkit/polkit-memory.c                   |  373 -----------------
 src/polkit/polkit-memory.h                   |   75 ---
 src/polkit/polkit-policy-cache.c             |   91 ++--
 src/polkit/polkit-policy-default.c           |   77 +--
 src/polkit/polkit-policy-file-entry.c        |  105 ++---
 src/polkit/polkit-policy-file.c              |  149 +++----
 src/polkit/polkit-private.h                  |    9 
 src/polkit/polkit-result.c                   |   15 
 src/polkit/polkit-seat.c                     |   41 -
 src/polkit/polkit-session.c                  |  125 ++----
 src/polkit/polkit-sysdeps.c                  |   18 
 src/polkit/polkit-test.c                     |   17 
 src/polkit/polkit-test.h                     |    3 
 src/polkit/polkit-utils.c                    |   10 
 src/polkit/polkit.h                          |    2 
 50 files changed, 3360 insertions(+), 2188 deletions(-)

New commits:
commit cd68aa0a7562332c23a1008d4359fe4c8647af67
Author: David Zeuthen <davidz at redhat.com>
Date:   Sat Nov 10 18:17:38 2007 -0500

    split utility bits into a private statically linked library
    
    getting closer...
    
    $ grep glib *.c
    polkit-authorization.c:#include <glib.h>
    polkit-authorization-db.c:#include <glib.h>
    polkit-authorization-db-dummy.c:#include <glib.h>
    polkit-config.c:#include <glib.h>
    polkit-context.c:#include <glib.h>
    polkit-sysdeps.c:#include <glib.h>

diff --git a/configure.in b/configure.in
index 22004f2..59ab7e5 100644
--- a/configure.in
+++ b/configure.in
@@ -34,24 +34,19 @@ AC_ARG_ENABLE(tests, AS_HELP_STRING([--enable-tests],[enable unit test code]),en
 AC_ARG_ENABLE(gcov, AS_HELP_STRING([--enable-gcov],[compile with coverage profiling instrumentation (gcc only)]),enable_gcov=$enableval,enable_gcov=no)
 AC_ARG_ENABLE(man-pages,        [  --enable-man-pages      build manual pages],enable_man_pages=$enableval,enable_man_pages=yes)
 
+AM_CONDITIONAL(KIT_BUILD_TESTS, test x$enable_tests = xyes)
 AM_CONDITIONAL(POLKIT_BUILD_TESTS, test x$enable_tests = xyes)
 if test x$enable_tests = xyes; then
+    AC_DEFINE(KIT_BUILD_TESTS,1,[Build test code])
     AC_DEFINE(POLKIT_BUILD_TESTS,1,[Build test code])
 fi
 
 if test x$enable_gcov = xyes; then
      ## so that config.h changes when you toggle gcov support
+     AC_DEFINE_UNQUOTED(KIT_GCOV_ENABLED, 1, [Defined if gcov is enabled to force a rebuild due to config.h changing])
      AC_DEFINE_UNQUOTED(POLKIT_GCOV_ENABLED, 1, [Defined if gcov is enabled to force a rebuild due to config.h changing])
-
-     AC_MSG_CHECKING([for gcc 3.3 version of gcov file format])
-     have_gcc33_gcov=no
-     AC_RUN_IFELSE( [AC_LANG_PROGRAM( , [[ if (__GNUC__ >=3 && __GNUC_MINOR__ >= 3) exit (0); else exit (1); ]])],  
-                   have_gcc33_gcov=yes)
-     if test x$have_gcc33_gcov = xyes ; then
-         AC_DEFINE_UNQUOTED(POLKIT_HAVE_GCC33_GCOV, 1, [Defined if we have gcc 3.3 and thus the new gcov format])
-     fi
-     AC_MSG_RESULT($have_gcc33_gcov)
 fi
+AM_CONDITIONAL(KIT_GCOV_ENABLED, test x$enable_gcov = xyes)
 AM_CONDITIONAL(POLKIT_GCOV_ENABLED, test x$enable_gcov = xyes)
 
 
@@ -454,6 +449,7 @@ data/polkit.pc
 data/polkit-dbus.pc
 data/polkit-grant.pc
 src/Makefile
+src/kit/Makefile
 src/polkit/Makefile
 src/polkit-dbus/Makefile
 src/polkit-grant/Makefile
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 02b4b24..07372e4 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -19,8 +19,8 @@ SCAN_OPTIONS=--ignore-headers=config.h
 DOC_SOURCE_DIR=../src
 
 # Used for dependencies
-HFILE_GLOB=$(top_srcdir)/src/polkit*/*.h
-CFILE_GLOB=$(top_srcdir)/src/polkit*/*.c
+HFILE_GLOB=$(top_srcdir)/src/*/*.h
+CFILE_GLOB=$(top_srcdir)/src/*/*.c
 
 # Headers to ignore
 IGNORE_HFILES= \
diff --git a/doc/polkit-docs.xml b/doc/polkit-docs.xml
index dc308a3..bdd04e2 100644
--- a/doc/polkit-docs.xml
+++ b/doc/polkit-docs.xml
@@ -68,6 +68,24 @@
     <xi:include href="spec/polkit-spec-configuration.xml" />    
   </reference>
 
+  <reference id="ref-internal">
+    <title>Internal API Reference</title>
+    <partintro>
+      <para>
+	This part presents the class and function reference for the
+	internal support classes, data structures and functions. These
+	symbols are not exported.
+      </para>
+    </partintro>
+    <xi:include href="xml/kit.xml"/>
+    <xi:include href="xml/kit-memory.xml"/>
+    <xi:include href="xml/kit-string.xml"/>
+    <xi:include href="xml/kit-message.xml"/>
+    <xi:include href="xml/kit-list.xml"/>
+    <xi:include href="xml/kit-hash.xml"/>
+    <xi:include href="xml/kit-file.xml"/>
+  </reference>
+
   <reference id="ref-core">
     <title>Core API Reference</title>
     <partintro>
@@ -84,9 +102,6 @@
     </partintro>
     <xi:include href="xml/polkit-types.xml"/>
     <xi:include href="xml/polkit-sysdeps.xml"/>
-    <xi:include href="xml/polkit-memory.xml"/>
-    <xi:include href="xml/polkit-list.xml"/>
-    <xi:include href="xml/polkit-hash.xml"/>
     <xi:include href="xml/polkit-error.xml"/>
     <xi:include href="xml/polkit-result.xml"/>
     <xi:include href="xml/polkit-action.xml"/>
diff --git a/src/Makefile.am b/src/Makefile.am
index 3760276..02554f1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,5 @@
 
-SUBDIRS = polkit polkit-dbus polkit-grant
+SUBDIRS = kit polkit polkit-dbus polkit-grant
 
 clean-local :
 	rm -f *~
diff --git a/src/kit/Makefile.am b/src/kit/Makefile.am
new file mode 100644
index 0000000..e0aa5e2
--- /dev/null
+++ b/src/kit/Makefile.am
@@ -0,0 +1,74 @@
+## Process this file with automake to produce Makefile.in
+
+NULL =
+
+INCLUDES = \
+	-I$(top_builddir)/src -I$(top_srcdir)/src \
+	-DPACKAGE_LIBEXEC_DIR=\""$(libexecdir)"\" \
+	-DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\" \
+	-DPACKAGE_DATA_DIR=\""$(datadir)"\" \
+	-DPACKAGE_BIN_DIR=\""$(bindir)"\" \
+	-DPACKAGE_LOCALSTATE_DIR=\""$(localstatedir)"\" \
+	-DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \
+	-DPACKAGE_LIB_DIR=\""$(libdir)"\" \
+	-D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT	\
+	-DKIT_COMPILATION \
+	@GLIB_CFLAGS@
+
+noinst_LTLIBRARIES=libkit.la
+
+
+libkit_la_SOURCES =					\
+	kit.h						\
+	kit-memory.h		kit-memory.c		\
+	kit-string.h		kit-string.c		\
+	kit-list.h		kit-list.c		\
+	kit-hash.h		kit-hash.c		\
+	kit-file.h		kit-file.c		\
+	kit-message.h		kit-message.c		\
+	$(NULL)
+
+
+## note that TESTS has special meaning (stuff to use in make check)
+## so if adding tests not to be run in make check, don't add them to 
+## TESTS
+if KIT_BUILD_TESTS
+TESTS_ENVIRONMENT=
+TESTS=kit-test
+
+if KIT_GCOV_ENABLED
+clean-gcov:
+	rm -f *.gcov .libs/*.gcda
+
+.PHONY: coverage-report.txt
+coverage-report.txt :
+	$(top_srcdir)/test/create-coverage-report.sh kit $(filter %.c,$(libkit_la_SOURCES)) > coverage-report.txt
+
+check-coverage : clean-gcov all check coverage-report.txt
+	cat coverage-report.txt
+else
+coverage-report.txt:
+	@echo "Need to reconfigure with --enable-gcov"
+
+check-coverage:
+	@echo "Need to reconfigure with --enable-gcov"
+endif
+
+else
+TESTS=
+endif
+
+## we use noinst_PROGRAMS not check_PROGRAMS so that we build 
+## even when not doing "make check"
+noinst_PROGRAMS=$(TESTS)
+
+kit_test_SOURCES=				\
+	kit-test.h		kit-test.c
+
+kit_test_LDADD=$(top_builddir)/src/kit/libkit.la
+kit_test_LDFLAGS=
+#@R_DYNAMIC_LDFLAG@
+
+
+clean-local :
+	rm -f *~ *.bb *.bbg *.da *.gcov .libs/*.da .libs/*.bbg 
diff --git a/src/kit/kit-file.c b/src/kit/kit-file.c
new file mode 100644
index 0000000..cc8ddd0
--- /dev/null
+++ b/src/kit/kit-file.c
@@ -0,0 +1,314 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-file.c : File utilities
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at 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
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+
+#include <kit/kit.h>
+#include "kit-test.h"
+
+
+/**
+ * SECTION:kit-file
+ * @title: File utilities
+ * @short_description: File utilities
+ *
+ * Various file utilities.
+ **/
+
+#define BUF_SIZE 4096
+
+/**
+ * kit_file_get_contents:
+ * @path: path to file
+ * @out_contents: Return location for allocated memory. Free with kit_free().
+ * @out_contents_size: Return location for size of the file.
+ * 
+ * Reads an entire file into allocated memory.
+ *
+ * Returns: #TRUE if the file was read into memory; #FALSE if an error
+ * occured and errno will be set.
+ */
+kit_bool_t
+kit_file_get_contents (const char *path, char **out_contents, size_t *out_contents_size)
+{
+        int fd;
+        kit_bool_t ret;
+        ssize_t num_read;
+        char *p;
+        char *q;
+        size_t total_allocated;
+        size_t total_size;
+        char buf[BUF_SIZE];
+
+        kit_return_val_if_fail (path != NULL, FALSE);
+        kit_return_val_if_fail (out_contents != NULL, FALSE);
+        kit_return_val_if_fail (out_contents_size != NULL, FALSE);
+
+        fd = -1;
+        ret = FALSE;
+        *out_contents = NULL;
+
+        fd = open (path, O_RDONLY);
+        if (fd == 0)
+                goto out;
+
+        p = kit_malloc (BUF_SIZE);
+        if (p == NULL) {
+                errno = ENOMEM;
+                goto out;
+        }
+        total_allocated = BUF_SIZE;
+        total_size = 0;
+
+        do {
+        again:
+                num_read = read (fd, buf, BUF_SIZE);
+                if (num_read == -1) {
+                        if (errno == EINTR)
+                                goto again;
+                        else
+                                goto out;
+                }
+
+
+                if (total_size + num_read > total_allocated) {
+                        total_allocated += BUF_SIZE;
+                        q = kit_realloc (p, total_allocated);
+                        if (q == NULL) {
+                                errno = ENOMEM;
+                                goto out;
+                        }
+                        p = q;
+                }
+
+                memcpy (p + total_size, buf, num_read);
+                total_size += num_read;
+                
+        } while (num_read > 0);
+
+        /* add terminating zero */
+        if (total_size + 1 > total_allocated) {
+                total_allocated += BUF_SIZE;
+                q = kit_realloc (p, total_allocated);
+                if (q == NULL) {
+                        errno = ENOMEM;
+                        goto out;
+                }
+                p = q;
+        }
+        p[total_size] = '\0';
+
+        *out_contents = p;
+        *out_contents_size = total_size;
+        ret = TRUE;
+
+out:
+        if (fd >= 0) {
+        again2:
+                if (close (fd) != 0) {
+                        if (errno == EINTR)
+                                goto again2;
+                        else
+                                ret = FALSE;
+                }
+        }
+
+        if (!ret) {
+                kit_free (p);
+                *out_contents = NULL;
+        }
+
+        return ret;
+}
+
+static kit_bool_t
+_write_to_fd (int fd, const char *str, ssize_t str_len)
+{
+        kit_bool_t ret;
+        ssize_t written;
+
+        ret = FALSE;
+
+        written = 0;
+        while (written < str_len) {
+                ssize_t ret;
+                ret = write (fd, str + written, str_len - written);
+                if (ret < 0) {
+                        if (errno == EAGAIN || errno == EINTR) {
+                                continue;
+                        } else {
+                                goto out;
+                        }
+                }
+                written += ret;
+        }
+
+        ret = TRUE;
+
+out:
+        return ret;
+}
+
+/**
+ * kit_file_set_contents:
+ * @path: path to file
+ * @mode: mode for file
+ * @contents: contents to set
+ * @contents_size: size of contents
+ *
+ * Writes all of contents to a file named @path, with good error
+ * checking. If a file called @path already exists it will be
+ * overwritten. This write is atomic in the sense that it is first
+ * written to a temporary file which is then renamed to the final
+ * name.
+ *
+ * If the file already exists hard links to @path will break. Also
+ * since the file is recreated, existing permissions, access control
+ * lists, metadata etc. may be lost. If @path is a symbolic link, the
+ * link itself will be replaced, not the linked file.
+ *
+ * Returns: #TRUE if contents were set; #FALSE if an error occured and
+ * errno will be set
+ */
+kit_bool_t
+kit_file_set_contents (const char *path, mode_t mode, const char *contents, size_t contents_size)
+{
+        int fd;
+        char *path_tmp;
+        kit_bool_t ret;
+
+        path_tmp = NULL;
+        ret = FALSE;
+
+        kit_return_val_if_fail ((contents == NULL && contents_size == 0) || (contents != NULL), FALSE);
+        kit_return_val_if_fail (path != NULL, FALSE);
+
+        path_tmp = kit_strdup_printf ("%s.XXXXXX", path);
+        if (path_tmp == NULL) {
+                errno = ENOMEM;
+                goto out;
+        }
+
+        fd = mkstemp (path_tmp);
+        if (fd < 0) {
+                kit_warning ("Cannot create file '%s': %m", path_tmp);
+                goto out;
+        }
+        if (fchmod (fd, mode) != 0) {
+                kit_warning ("Cannot change mode for '%s' to 0%o: %m", path_tmp, mode);
+                close (fd);
+                unlink (path_tmp);
+                goto out;
+        }
+
+        if (contents_size > 0) {
+                if (!_write_to_fd (fd, contents, contents_size)) {
+                        kit_warning ("Cannot write to file %s: %m", path_tmp);
+                        close (fd);
+                        if (unlink (path_tmp) != 0) {
+                                kit_warning ("Cannot unlink %s: %m", path_tmp);
+                        }
+                        goto out;
+                }
+        }
+        close (fd);
+
+        if (rename (path_tmp, path) != 0) {
+                kit_warning ("Cannot rename %s to %s: %m", path_tmp, path);
+                if (unlink (path_tmp) != 0) {
+                        kit_warning ("Cannot unlink %s: %m", path_tmp);
+                }
+                goto out;
+        }
+
+        ret = TRUE;
+
+out:
+        if (path_tmp != NULL)
+                kit_free (path_tmp);
+
+        return ret;
+}
+
+
+#ifdef KIT_BUILD_TESTS
+
+static kit_bool_t
+_run_test (void)
+{
+        char path[] = "/tmp/kit-test";
+        char *buf;
+        size_t buf_size;
+        char *p;
+        size_t s;
+        unsigned int n;
+
+        buf_size = 3 * BUF_SIZE;
+        if ((buf = kit_malloc (buf_size)) == NULL)
+                goto out;
+
+        for (n = 0; n < buf_size; n++)
+                buf[n] = n;
+
+        if (!kit_file_set_contents (path, 0400, buf, buf_size)) {
+                kit_assert (errno == ENOMEM);
+        } else {
+                if (!kit_file_get_contents (path, &p, &s)) {
+                        kit_assert (errno == ENOMEM);
+                } else {
+                        kit_assert (s == buf_size && memcmp (p, buf, buf_size) == 0);
+                        kit_free (p);
+                }
+
+                kit_assert (unlink (path) == 0);
+
+                kit_assert (!kit_file_get_contents (path, &p, &s));
+        }
+
+        kit_free (buf);
+
+out:
+        return TRUE;
+}
+
+KitTest _test_file = {
+        "kit_file",
+        NULL,
+        NULL,
+        _run_test
+};
+
+#endif /* KIT_BUILD_TESTS */
diff --git a/src/kit/kit-file.h b/src/kit/kit-file.h
new file mode 100644
index 0000000..2b31d53
--- /dev/null
+++ b/src/kit/kit-file.h
@@ -0,0 +1,44 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-file.h : File utilities
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at 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
+ *
+ **************************************************************************/
+
+#if !defined (KIT_COMPILATION) && !defined(_KIT_INSIDE_KIT_H)
+#error "Only <kit/kit.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef KIT_FILE_H
+#define KIT_FILE_H
+
+#include <kit/kit.h>
+
+KIT_BEGIN_DECLS
+
+kit_bool_t kit_file_get_contents (const char *path, char **out_contents, size_t *out_contents_size);
+kit_bool_t kit_file_set_contents (const char *path, mode_t mode, const char *contents, size_t contents_size);
+
+KIT_END_DECLS
+
+#endif /* KIT_FILE_H */
+
+
diff --git a/src/kit/kit-hash.c b/src/kit/kit-hash.c
new file mode 100644
index 0000000..c79f7dd
--- /dev/null
+++ b/src/kit/kit-hash.c
@@ -0,0 +1,533 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-hash.c : Hash tables
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at 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
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <kit/kit-memory.h>
+#include <kit/kit-hash.h>
+#include <kit/kit-test.h>
+
+/**
+ * SECTION:kit-hash
+ * @title: Hash tables
+ * @short_description: Hash tables
+ *
+ * This class provides support for hash tables.
+ **/
+
+struct _KitHashNode;
+
+typedef struct _KitHashNode {
+        void *key;
+        void *value;
+        struct _KitHashNode *next;
+} KitHashNode;
+
+
+/**
+ * KitHash:
+ *
+ * The #KitHash structure not be accessed directly.
+ */
+struct _KitHash
+{
+        int refcount;
+
+        int num_top_nodes;
+        KitHashNode **top_nodes;
+
+        KitHashFunc  hash_func;
+        KitEqualFunc key_equal_func;
+        KitCopyFunc  key_copy_func;
+        KitCopyFunc  value_copy_func;
+        KitFreeFunc  key_destroy_func;
+        KitFreeFunc  value_destroy_func;
+};
+
+/**
+ * kit_hash_new:
+ * @hash_func: The hash function to use
+ * @key_equal_func: The function used to determine key equality
+ * @key_copy_func: Function for copying keys or #NULL
+ * @value_copy_func: Function for copying values or #NULL
+ * @key_destroy_func: Function for freeing keys or #NULL
+ * @value_destroy_func: Function for freeing values or #NULL
+ *
+ * Creates a new Hash Table.
+ *
+ * Returns: The new hash table. Returns #NULL on OOM.
+ */
+KitHash *
+kit_hash_new (KitHashFunc  hash_func,
+              KitEqualFunc key_equal_func,
+              KitCopyFunc  key_copy_func,
+              KitCopyFunc  value_copy_func,
+              KitFreeFunc  key_destroy_func,
+              KitFreeFunc  value_destroy_func)
+{
+        KitHash *h;
+
+        kit_return_val_if_fail (hash_func != NULL, NULL);
+        kit_return_val_if_fail (key_equal_func != NULL, NULL);
+
+        h = kit_new0 (KitHash, 1);
+        if (h == NULL)
+                goto error;
+
+        h->refcount = 1;
+        h->hash_func = hash_func;
+        h->key_copy_func = key_copy_func;
+        h->value_copy_func = value_copy_func;
+        h->key_equal_func = key_equal_func;
+        h->key_destroy_func = key_destroy_func;
+        h->value_destroy_func = value_destroy_func;
+
+        h->num_top_nodes = 11; /* TODO: configurable? */
+        h->top_nodes = kit_new0 (KitHashNode*, h->num_top_nodes);
+        if (h->top_nodes == NULL)
+                goto error;
+
+        return h;
+error:
+        if (h != NULL)
+                kit_hash_unref (h);
+        return NULL;
+}
+
+/**
+ * kit_hash_ref:
+ * @hash: the hash table
+ *
+ * Increase reference count.
+ *
+ * Returns: the hash table
+ */
+KitHash *
+kit_hash_ref (KitHash *hash)
+{
+        kit_return_val_if_fail (hash != NULL, hash);
+        hash->refcount++;
+        return hash;
+}
+
+/**
+ * kit_hash_unref:
+ * @hash: the hash table
+ *
+ * Decrease reference count. If reference count drop to zero the hash
+ * table is freed.
+ */
+void
+kit_hash_unref (KitHash *hash)
+{
+        kit_return_if_fail (hash != NULL);
+
+        hash->refcount--;
+        if (hash->refcount > 0) 
+                return;
+
+        if (hash->top_nodes != NULL) {
+                int n;
+
+                for (n = 0; n < hash->num_top_nodes; n++) {
+                        KitHashNode *node;
+                        KitHashNode *next;
+                        
+                        for (node = hash->top_nodes[n]; node != NULL; node = next) {
+                                if (hash->key_destroy_func != NULL)
+                                        hash->key_destroy_func (node->key);
+                                if (hash->value_destroy_func != NULL)
+                                        hash->value_destroy_func (node->value);
+                                next = node->next;
+                                kit_free (node);
+                        }
+                }
+        }
+
+        kit_free (hash->top_nodes);
+        kit_free (hash);
+}
+
+/**
+ * kit_hash_insert:
+ * @hash: the hash table
+ * @key: key to insert
+ * @value: value to insert
+ *
+ * Inserts a new key and value into a hash table. If the key already
+ * exists in the hash table it's current value is replaced with the
+ * new value.
+ *
+ * Returns: #TRUE unless OOM
+ */
+kit_bool_t 
+kit_hash_insert (KitHash *hash,
+                    void *key,
+                    void *value)
+{
+        int bucket;
+        KitHashNode **nodep;
+        KitHashNode *node;
+        void *key_copy;
+        void *value_copy;
+
+        kit_return_val_if_fail (hash != NULL, FALSE);
+        kit_return_val_if_fail (key != NULL, FALSE);
+
+        key_copy = NULL;
+        value_copy = NULL;
+        if (hash->key_copy_func != NULL) {
+                key_copy = hash->key_copy_func (key);
+                if (key_copy == NULL) {
+                        goto oom;
+                }
+        } else {
+                key_copy = key;
+        }
+        if (hash->value_copy_func != NULL) {
+                value_copy = hash->value_copy_func (value);
+                if (value_copy == NULL) {
+                        goto oom;
+                }
+        } else {
+                value_copy = value;
+        }
+
+        bucket = hash->hash_func (key) % hash->num_top_nodes;
+
+        nodep = & (hash->top_nodes [bucket]);
+        node = hash->top_nodes [bucket];
+        while (node != NULL) {
+                nodep = &(node->next);
+
+                if (hash->key_equal_func (key, node->key)) {
+                        /* replace the value */
+
+                        if (hash->key_destroy_func != NULL)
+                                hash->key_destroy_func (node->key);
+                        if (hash->value_destroy_func != NULL)
+                                hash->value_destroy_func (node->value);
+
+                        node->key = key_copy;
+                        node->value = value_copy;
+
+                        goto out;
+                } else {
+                        node = node->next;
+                }
+        }
+
+        node = kit_new0 (KitHashNode, 1);
+        if (node == NULL)
+                goto oom;
+
+        node->key = key_copy;
+        node->value = value_copy;
+        *nodep = node;
+
+out:
+        return TRUE;
+
+oom:
+        if (key_copy != NULL && hash->key_copy_func != NULL && hash->key_destroy_func != NULL)
+                hash->key_destroy_func (key_copy);
+
+        if (value_copy != NULL && hash->value_copy_func != NULL && hash->value_destroy_func != NULL)
+                hash->value_destroy_func (value_copy);
+
+        return FALSE;
+}
+
+/**
+ * kit_hash_lookup:
+ * @hash: the hash table
+ * @key: key to look up
+ * @found: if not #NULL, will return #TRUE only if the key was found in the hash table
+ *
+ * Look up a value in the hash table.
+ *
+ * Returns: the value; caller shall not free/unref this value
+ */
+void *
+kit_hash_lookup (KitHash *hash, void *key, kit_bool_t *found)
+{
+        int bucket;
+        void *value;
+        KitHashNode *node;
+
+        value = NULL;
+        if (found != NULL)
+                *found = FALSE;
+
+        kit_return_val_if_fail (hash != NULL, NULL);
+        kit_return_val_if_fail (key != NULL, NULL);
+
+        bucket = hash->hash_func (key) % hash->num_top_nodes;
+
+        node = hash->top_nodes [bucket];
+        while (node != NULL) {
+                if (hash->key_equal_func (key, node->key)) {
+                        /* got it */
+
+                        value = node->value;
+                        if (found != NULL)
+                                *found = TRUE;
+                        goto out;
+                } else {
+                        node = node->next;
+                }
+        }
+
+out:
+        return value;
+}
+
+
+/**
+ * kit_hash_foreach:
+ * @hash: the hash table
+ * @cb: callback function
+ * @user_data: user data
+ *
+ * Iterate over all elements in a hash table
+ *
+ * Returns: #TRUE only if the callback short-circuited the iteration
+ */
+kit_bool_t
+kit_hash_foreach (KitHash *hash, KitHashForeachFunc cb, void *user_data)
+{
+        int n;
+
+        kit_return_val_if_fail (hash != NULL, FALSE);
+        kit_return_val_if_fail (cb != NULL, FALSE);
+
+        for (n = 0; n < hash->num_top_nodes; n++) {
+                KitHashNode *node;
+
+                for (node = hash->top_nodes[n]; node != NULL; node = node->next) {
+                        if (cb (hash, node->key, node->value, user_data))
+                                return TRUE;
+                }
+        }
+
+        return FALSE;
+}
+
+
+/**
+ * kit_hash_direct_hash_func:
+ * @key: the key
+ *
+ * Converts a pointer to a hash value.
+ *
+ * Returns: a hash value corresponding to the key
+ */
+uint32_t 
+kit_hash_direct_hash_func (const void *key)
+{
+        return (uint32_t) key;
+}
+
+/**
+ * kit_hash_direct_equal_func:
+ * @v1: first value
+ * @v2: second value
+ *
+ * Compares two pointers and return #TRUE if they are equal (same address).
+ *
+ * Returns: #TRUE only if the values are equal
+ */
+kit_bool_t
+kit_hash_direct_equal_func (const void *v1, const void *v2)
+{
+        return v1 == v2;
+}
+
+/**
+ * kit_hash_str_hash_func:
+ * @key: the key
+ *
+ * Converts a string to a hash value.
+ *
+ * Returns: a hash value corresponding to the key
+ */
+uint32_t
+kit_hash_str_hash_func (const void *key)
+{
+        const char *p;
+        uint32_t hash;
+
+        hash = 0;
+        for (p = key; *p != '\0'; p++)
+                hash = hash * 617 ^ *p;
+
+        return hash;
+}
+
+/**
+ * kit_hash_str_equal_func:
+ * @v1: first value
+ * @v2: second value
+ *
+ * Compares two strings and return #TRUE if they are equal.
+ *
+ * Returns: #TRUE only if the values are equal
+ */
+kit_bool_t
+kit_hash_str_equal_func (const void *v1, const void *v2)
+{
+        return strcmp (v1, v2) == 0;
+}
+
+/**
+ * kit_hash_str_copy:
+ * @p: void pointer to string
+ *
+ * Similar to kit_strdup() except for types.
+ *
+ * Returns: a void pointer to a copy or #NULL on OOM
+ */
+void *
+kit_hash_str_copy (const void *p)
+{
+        return (void *) kit_strdup ((const char *) p);
+}
+
+#ifdef KIT_BUILD_TESTS
+
+static kit_bool_t
+_it1 (KitHash *hash, void *key, void *value, void *user_data)
+{
+        int *count = (int *) user_data;
+        *count += 1;
+        return FALSE;
+}
+
+static kit_bool_t
+_it2 (KitHash *hash, void *key, void *value, void *user_data)
+{
+        int *count = (int *) user_data;
+        *count += 1;
+        return TRUE;
+}
+
+static kit_bool_t
+_run_test (void)
+{
+        int count;
+        KitHash *h;
+        kit_bool_t found;
+
+        /* string hash tables */
+        if ((h = kit_hash_new (kit_hash_str_hash_func, kit_hash_str_equal_func, 
+                                  kit_hash_str_copy, kit_hash_str_copy,
+                                  kit_free, kit_free)) != NULL) {
+                int n;
+                char *key;
+                char *value;
+                char *test_data[] = {"key1", "val1",
+                                     "key2", "val2",
+                                     "key3", "val3",
+                                     "key4", "val4",
+                                     "key5", "val5",
+                                     "key6", "val6",
+                                     "key7", "val7",
+                                     "key8", "val8",
+                                     "key9", "val9",
+                                     "key10", "val10",
+                                     "key11", "val11",
+                                     "key12", "val12",
+                                     NULL};
+
+                /* first insert the values */
+                for (n = 0; test_data [n*2] != NULL; n++) {
+                        if (!kit_hash_insert (h, test_data [n*2], test_data [n*2 + 1])) {
+                                goto oom;
+                        }
+                }
+
+                /* then check that we can look them up */
+                for (n = 0; test_data [n*2] != NULL; n++) {
+                        key = test_data [n*2];
+                        value = kit_hash_lookup (h, test_data[n*2], &found);
+
+                        kit_assert (found && strcmp (value, test_data[n*2 + 1]) == 0);
+                }
+
+                /* lookup unknown key */
+                kit_assert (kit_hash_lookup (h, "unknown", &found) == NULL && !found);
+
+                /* replace key */
+                if (key != NULL) {
+                        if (kit_hash_insert (h, "key1", "val1-replaced")) {
+                                /* check for replaced value */
+                                value = kit_hash_lookup (h, "key1", &found);
+                                kit_assert (found && value != NULL && strcmp (value, "val1-replaced") == 0);
+                        }
+                }
+
+                count = 0;
+                kit_assert (kit_hash_foreach (h, _it1, &count) == FALSE);
+                kit_assert (count == ((sizeof (test_data) / sizeof (char *) - 1) / 2));
+                count = 0;
+                kit_assert (kit_hash_foreach (h, _it2, &count) == TRUE);
+                kit_assert (count == 1);
+                
+                kit_hash_ref (h);
+                kit_hash_unref (h);
+        oom:
+
+                kit_hash_unref (h);
+        }
+
+        /* direct hash tables */
+        if ((h = kit_hash_new (kit_hash_direct_hash_func, kit_hash_direct_equal_func, 
+                                  NULL, NULL, 
+                                  NULL, NULL)) != NULL) {
+                if (kit_hash_insert (h, h, h)) {
+                        kit_assert ((kit_hash_lookup (h, h, &found) == h) && found);
+                        if (kit_hash_insert (h, h, NULL)) {
+                                kit_assert (kit_hash_lookup (h, h, &found) == NULL && found);
+                        }
+                }
+                kit_hash_unref (h);
+        }
+
+        return TRUE;
+}
+
+KitTest _test_hash = {
+        "kit_hash",
+        NULL,
+        NULL,
+        _run_test
+};
+
+#endif /* KIT_BUILD_TESTS */
diff --git a/src/kit/kit-hash.h b/src/kit/kit-hash.h
new file mode 100644
index 0000000..cc581b4
--- /dev/null
+++ b/src/kit/kit-hash.h
@@ -0,0 +1,148 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-hash.h : Hash tables
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at 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
+ *
+ **************************************************************************/
+
+#if !defined (KIT_COMPILATION) && !defined(_KIT_INSIDE_KIT_H)
+#error "Only <kit/kit.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef KIT_HASH_H
+#define KIT_HASH_H
+
+#include <stdint.h>
+#include <kit/kit.h>
+
+KIT_BEGIN_DECLS
+
+struct _KitHash;
+typedef struct _KitHash KitHash;
+
+/**
+ * KitHashFunc:
+ * @key: a key
+ *
+ * The function is passed a key and should return a hash value. The
+ * functions kit_hash_direct_hash_func() and
+ * kit_hash_str_hash_func() provide hash functions which can be
+ * used when the key is a pointer and an char* respectively.
+ *
+ * Returns: the hash value corresponding to the key
+ *
+ * Since: 0.7
+ */
+typedef uint32_t (*KitHashFunc) (const void *key);
+
+/**
+ * KitEqualFunc:
+ * @key1: first key
+ * @key2: second key
+ *
+ * Determines if two keys are equal. The functions
+ * kit_hash_direct_equal_func() and kit_hash_str_equal_func()
+ * provide equality functions which can be used when the key is a
+ * pointer and an char* respectively.
+ *
+ * Returns: #TRUE iff the keys are equal
+ *
+ * Since: 0.7
+ */
+typedef kit_bool_t (*KitEqualFunc) (const void *key1, const void *key2);
+
+/**
+ * KitFreeFunc:
+ * @p: pointer
+ *
+ * Specifies the type of function which is called when a data element
+ * is destroyed. It is passed the pointer to the data element and
+ * should free any memory and resources allocated for it. The function
+ * p_free() or any of the object unref functions can be passed here.
+ *
+ * Since: 0.7
+ */
+typedef void (*KitFreeFunc) (void *p);
+
+/**
+ * KitCopyFunc:
+ * @p: pointer
+ *
+ * Specifies the type of function which is called when a data element
+ * is to be cloned or reffed. It is passed the pointer to the data
+ * element and should return a new pointer to a reffed or cloned
+ * object. The function kit_hash_str_copy() or any of the object
+ * ref functions can be passed here.
+ *
+ * Returns: A copy or ref of the object in question
+ *
+ * Since: 0.7
+ */
+typedef void *(*KitCopyFunc) (const void *p);
+
+/**
+ * KitHashForeachFunc:
+ * @hash: the hash table
+ * @key: key
+ * @value: value
+ * @user_data: user data passed to kit_hash_foreach()
+ *
+ * Type signature for callback function used in kit_hash_foreach().
+ *
+ * Returns: Return #TRUE to short-circuit, e.g. stop the iteration.
+ *
+ * Since: 0.7
+ */
+typedef kit_bool_t (*KitHashForeachFunc) (KitHash *hash,
+                                          void *key,
+                                          void *value,
+                                          void *user_data);
+
+
+KitHash *kit_hash_new (KitHashFunc  hash_func,
+                       KitEqualFunc key_equal_func,
+                       KitCopyFunc  key_copy_func,
+                       KitCopyFunc  value_copy_func,
+                       KitFreeFunc  key_destroy_func,
+                       KitFreeFunc  value_destroy_func);
+
+KitHash    *kit_hash_ref   (KitHash *hash);
+void       kit_hash_unref (KitHash *hash);
+
+kit_bool_t  kit_hash_insert (KitHash *hash, void *key, void *value);
+
+void       *kit_hash_lookup (KitHash *hash, void *key, kit_bool_t *found);
+
+kit_bool_t  kit_hash_foreach (KitHash *hash, KitHashForeachFunc cb, void *user_data);
+
+
+uint32_t     kit_hash_direct_hash_func  (const void *key);
+kit_bool_t   kit_hash_direct_equal_func (const void *v1, const void *v2);
+
+uint32_t     kit_hash_str_hash_func     (const void *key);
+kit_bool_t   kit_hash_str_equal_func    (const void *v1, const void *v2);
+void        *kit_hash_str_copy          (const void *p);
+
+KIT_END_DECLS
+
+#endif /* KIT_HASH_H */
+
+
diff --git a/src/kit/kit-list.c b/src/kit/kit-list.c
new file mode 100644
index 0000000..a1b3f52
--- /dev/null
+++ b/src/kit/kit-list.c
@@ -0,0 +1,314 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-list.c : Doubly-linked lists
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at 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
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <kit/kit.h>
+#include "kit-test.h"
+
+/**
+ * SECTION:kit-list
+ * @title: Doubly-linked lists
+ * @short_description: Doubly-linked lists
+ *
+ * This class provides support for doubly-linked lists.
+ **/
+
+/**
+ * kit_list_append:
+ * @list: existing list or #NULL to create a new list
+ * @data: data to append to the list
+ *
+ * Append an entry to a list.
+ *
+ * Returns: the head of the new list or #NULL on OOM
+ */
+KitList *
+kit_list_append (KitList *list, void *data)
+{
+        KitList *l;
+        KitList *j;
+        
+        for (j = list; j != NULL && j->next != NULL; j = j->next)
+                ;
+        
+        l = kit_new0 (KitList, 1);
+        if (l == NULL)
+                goto oom;
+
+        l->data = data;
+        l->prev = j;
+        
+        if (j != NULL) {
+                j->next = l;
+        } else {
+                list = l;
+        }
+
+        return list;
+oom:
+        return NULL;
+}
+
+/**
+ * kit_list_prepend:
+ * @list: existing list or #NULL to create a new list
+ * @data: data to prepend to the list
+ *
+ * Prepend an entry to a list.
+ *
+ * Returns: the head of the new list or #NULL on OOM
+ */
+KitList *
+kit_list_prepend (KitList *list, void *data)
+{
+        KitList *l;
+
+        l = kit_new0 (KitList, 1);
+        if (l == NULL)
+                goto oom;
+
+        l->next = list;
+        l->data = data;
+        if (list != NULL) {
+                list->prev = l;
+        }
+
+oom:
+        return l;
+}
+
+/**
+ * kit_list_delete_link:
+ * @list: existing list, cannot be #NULL
+ * @link: link to delete, cannot be #NULL
+ *
+ * Delete a link from a list.
+ *
+ * Returns: the new head of the list or #NULL if the list is empty after deletion.
+ */
+KitList *
+kit_list_delete_link (KitList *list, KitList *link)
+{
+        KitList *ret;
+
+        kit_return_val_if_fail (list != NULL, NULL);
+        kit_return_val_if_fail (link != NULL, NULL);
+
+        if (list == link)
+                ret = link->next;
+        else
+                ret = list;
+
+        if (link->prev != NULL) {
+                link->prev->next = link->next;
+        }
+
+        if (link->next != NULL) {
+                link->next->prev = link->prev;
+        }
+
+        kit_free (link);
+
+        return ret;
+}
+
+/**
+ * kit_list_free:
+ * @list: the list
+ *
+ * Frees all links in a list
+ */
+void
+kit_list_free (KitList *list)
+{
+        KitList *l;
+        KitList *j;
+
+        for (l = list; l != NULL; l = j) {
+                j = l->next;
+                kit_free (l);
+        }
+}
+
+/**
+ * kit_list_length:
+ * @list: the list
+ *
+ * Compute the length of a list.
+ *
+ * Returns: Number of entries in list
+ */
+size_t
+kit_list_length (KitList *list)
+{
+        ssize_t n;
+        KitList *l;
+
+        n = 0;
+        for (l = list; l != NULL; l = l->next)
+                n++;
+
+        return n;
+}
+
+/**
+ * kit_list_foreach:
+ * @list: the list
+ * @func: callback function
+ * @user_data: user data to pass to callback
+ *
+ * Iterate over all entries in a list.
+ *
+ * Returns: #TRUE only if the callback short-circuited the iteration
+ */
+kit_bool_t 
+kit_list_foreach (KitList *list, KitListForeachFunc func, void *user_data)
+{
+        KitList *l;
+
+        kit_return_val_if_fail (list != NULL, FALSE);
+        kit_return_val_if_fail (func != NULL, FALSE);
+
+        for (l = list; l != NULL; l = l->next) {
+                if (func (list, l->data, user_data))
+                        return TRUE;
+        }
+        
+        return FALSE;
+}
+
+
+#ifdef KIT_BUILD_TESTS
+
+typedef struct {
+        int num;
+        int result;
+} _Closure;
+
+static kit_bool_t 
+_sum (KitList *list, void *data, void *user_data)
+{
+        _Closure *c = (_Closure*) user_data;
+
+        c->result += ((int) data) * (c->num + 1);
+        c->num += 1;
+
+        return FALSE;
+}
+
+static kit_bool_t 
+_sum2 (KitList *list, void *data, void *user_data)
+{
+        _Closure *c = (_Closure*) user_data;
+
+        if (c->num == 2)
+                return TRUE;
+
+        c->result += ((int) data) * (c->num + 1);
+        c->num += 1;
+
+        return FALSE;
+}
+
+static kit_bool_t
+_run_test (void)
+{
+        _Closure c;
+        int items[] = {1, 2, 3, 4, 5};
+        unsigned int num_items = sizeof (items) / sizeof (int);
+        unsigned int n;
+        KitList *l;
+        KitList *j;
+
+        l = NULL;
+        for (n = 0; n < num_items; n++) {
+                j = l;
+                l = kit_list_prepend (l, (void *) items[n]);
+                if (l == NULL)
+                        goto oom;
+        }
+
+        kit_assert (kit_list_length (l) == num_items);
+        c.num = 0;
+        c.result = 0;
+        kit_list_foreach (l, _sum, &c);
+        kit_assert (c.result == 1*5 + 2*4 + 3*3 + 4*2 + 5*1);
+
+        c.num = 0;
+        c.result = 0;
+        kit_list_foreach (l, _sum2, &c);
+        kit_assert (c.result == 1*5 + 2*4);
+
+        l = kit_list_delete_link (l, l);
+        kit_assert (kit_list_length (l) == num_items - 1);
+        c.num = 0;
+        c.result = 0;
+        kit_list_foreach (l, _sum, &c);
+        kit_assert (c.result == 1*4 + 2*3 + 3*2 + 4*1);
+
+        l = kit_list_delete_link (l, l->next);
+        kit_assert (kit_list_length (l) == num_items - 2);
+        c.num = 0;
+        c.result = 0;
+        kit_list_foreach (l, _sum, &c);
+        kit_assert (c.result == 1*4 + 2*2 + 3*1);
+
+        kit_list_free (l);
+
+        l = NULL;
+        for (n = 0; n < num_items; n++) {
+                j = l;
+                l = kit_list_append (l, (void *) items[n]);
+                if (l == NULL)
+                        goto oom;
+        }
+
+        c.num = 0;
+        c.result = 0;
+        kit_list_foreach (l, _sum, &c);
+        kit_assert (c.result == 1*1 + 2*2 + 3*3 + 4*4 + 5*5);
+
+        kit_list_free (l);
+
+        return TRUE;
+oom:
+        kit_list_free (j);
+        return TRUE;
+}
+
+KitTest _test_list = {
+        "kit_list",
+        NULL,
+        NULL,
+        _run_test
+};
+
+#endif /* KIT_BUILD_TESTS */
diff --git a/src/kit/kit-list.h b/src/kit/kit-list.h
new file mode 100644
index 0000000..1984fac
--- /dev/null
+++ b/src/kit/kit-list.h
@@ -0,0 +1,85 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-list.h : Doubly-linked list
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at 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
+ *
+ **************************************************************************/
+
+#if !defined (KIT_COMPILATION) && !defined(_KIT_INSIDE_KIT_H)
+#error "Only <kit/kit.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef KIT_LIST_H
+#define KIT_LIST_H
+
+#include <kit/kit.h>
+
+KIT_BEGIN_DECLS
+
+struct _KitList;
+typedef struct _KitList KitList;
+
+/**
+ * KitList:
+ * @data: the value passed in kit_list_append() and kit_list_prepend()
+ * @next: the next element in the list or #NULL if this is the last element
+ * @prev: the previous element in the list or #NULL if this is the last element
+ *
+ * Public members of the #KitList data structure
+ *
+ * Since: 0.7
+ */
+struct _KitList {
+        void *data;
+        KitList *next;
+        KitList *prev;
+};
+
+/**
+ * KitListForeachFunc:
+ * @list: the list
+ * @data: data of link entry
+ * @user_data: user data passed to kit_list_foreach()
+ *
+ * Type signature for callback function used in kit_list_foreach().
+ *
+ * Returns: Return #TRUE to short-circuit, e.g. stop the iteration.
+ *
+ * Since: 0.7
+ */
+typedef kit_bool_t (*KitListForeachFunc) (KitList *list,
+                                          void *data,
+                                          void *user_data);
+
+KitList    *kit_list_append      (KitList *list, void *data);
+KitList    *kit_list_prepend     (KitList *list, void *data);
+void        kit_list_free        (KitList *list);
+KitList    *kit_list_delete_link (KitList *list, KitList *link);
+
+size_t      kit_list_length      (KitList *list);
+kit_bool_t  kit_list_foreach     (KitList *list, KitListForeachFunc func, void *user_data);
+
+
+KIT_END_DECLS
+
+#endif /* KIT_LIST_H */
+
+
diff --git a/src/kit/kit-memory.c b/src/kit/kit-memory.c
new file mode 100644
index 0000000..397245c
--- /dev/null
+++ b/src/kit/kit-memory.c
@@ -0,0 +1,281 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-memory.c : Memory management
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at 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
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <kit/kit-memory.h>
+#include <kit/kit-test.h>
+
+/**
+ * SECTION:kit-memory
+ * @title: Memory management
+ * @short_description: Memory management
+ *
+ * Functions used for memory management.
+ **/
+
+
+#ifdef KIT_BUILD_TESTS
+
+static int _cur_allocs = 0;
+static int _total_allocs = 0;
+static int _fail_nth = -1;
+
+void 
+_kit_memory_reset (void)
+{
+        _cur_allocs = 0;
+        _total_allocs = 0;
+        _fail_nth = -1;
+}
+
+int 
+_kit_memory_get_current_allocations (void)
+{
+        return _cur_allocs;
+}
+
+int 
+_kit_memory_get_total_allocations (void)
+{
+        return _total_allocs;
+}
+
+void 
+_kit_memory_fail_nth_alloc (int number)
+{
+        _fail_nth = number;
+}
+
+/**
+ * kit_malloc:
+ * @bytes: number of 8-bit bytes to allocate
+ *
+ * Allocate memory
+ *
+ * Returns: memory location or #NULL on OOM. Free with kit_free().
+ */
+void *
+kit_malloc (size_t bytes)
+{
+        void *p;
+
+        if (_fail_nth != -1 && _total_allocs == _fail_nth) {
+                return NULL;
+        }
+
+        p = malloc (bytes);
+
+        if (p != NULL)  {
+                _cur_allocs++;
+                _total_allocs++;
+        }
+
+        return p;
+}
+
+/**
+ * kit_malloc0:
+ * @bytes: number of 8-bit bytes to allocate
+ *
+ * Allocate memory and zero it.
+ *
+ * Returns: memory location or #NULL on OOM. Free with kit_free().
+ */
+void *
+kit_malloc0 (size_t bytes)
+{
+        void *p;
+
+        if (_fail_nth != -1 && _total_allocs == _fail_nth) {
+                return NULL;
+        }
+
+        p = calloc (1, bytes);
+
+        if (p != NULL)  {
+                _cur_allocs++;
+                _total_allocs++;
+        }
+
+        return p;
+}
+
+/**
+ * kit_realloc:
+ * @memory: memory previously allocated
+ * @bytes: new size
+ *
+ * Reallocate memory; like realloc(3).
+ *
+ * Returns: memory location or #NULL on OOM. Free with kit_free().
+ */
+void *
+kit_realloc (void *memory, size_t bytes)
+{
+        void *p;
+
+        if (memory == NULL)
+                return kit_malloc (bytes);
+
+        if (bytes == 0) {
+                kit_free (memory);
+                return memory;
+        }
+
+        if (_fail_nth != -1 && _total_allocs == _fail_nth) {
+                return NULL;
+        }
+
+        p = realloc (memory, bytes);
+
+        return p;
+}
+
+/**
+ * kit_free:
+ * @memory: pointer to memory allocated with kit_malloc() + friends
+ *
+ * Free memory allocated by kit_malloc() + friends.
+ */
+void
+kit_free (void *memory)
+{
+        free (memory);
+        if (memory != NULL) {
+                _cur_allocs--;
+        }
+}
+
+/*--------------------------------------------------------------------------------------------------------------*/
+#else
+/*--------------------------------------------------------------------------------------------------------------*/
+
+void *
+kit_malloc (size_t bytes)
+{
+        return malloc (bytes);
+}
+
+void *
+kit_malloc0 (size_t bytes)
+{
+        return calloc (1, bytes);
+}
+
+void *
+kit_realloc (void *memory, size_t bytes)
+{
+        return realloc (memory, bytes);
+}
+
+void
+kit_free (void *memory)
+{
+        free (memory);
+}
+
+void 
+_kit_memory_reset (void)
+{
+}
+
+int 
+_kit_memory_get_current_allocations (void)
+{
+        return -1;
+}
+
+int 
+_kit_memory_get_total_allocations (void)
+{
+        return -1;
+}
+
+void 
+_kit_memory_fail_nth_alloc (int number)
+{
+}
+
+#endif /* KIT_BUILD_TESTS */
+
+
+
+#ifdef KIT_BUILD_TESTS
+
+static kit_bool_t
+_run_test (void)
+{
+        int n;
+        char *p;
+        char *p2;
+
+        if ((p = kit_malloc (1000)) != NULL) {
+                for (n = 0; n < 1000; n++)
+                        p[n] = n;
+
+                p2 = kit_realloc (p, 2000);
+                if (p2 != NULL) {
+                        p = p2;
+
+                        for (n = 0; n < 2000; n++)
+                                p[n] = n;
+                }
+
+                kit_free (p);
+        }
+
+        if ((p = kit_realloc (NULL, 1000)) != NULL) {
+                for (n = 0; n < 1000; n++)
+                        p[n] = n;
+
+                kit_realloc (p, 0);
+        }
+
+        if ((p = kit_malloc0 (1000)) != NULL) {
+                for (n = 0; n < 1000; n++)
+                        kit_assert (p[n] == '\0');
+                kit_free (p);
+        }
+        
+        return TRUE;
+}
+
+KitTest _test_memory = {
+        "kit_memory",
+        NULL,
+        NULL,
+        _run_test
+};
+
+#endif /* KIT_BUILD_TESTS */
diff --git a/src/kit/kit-memory.h b/src/kit/kit-memory.h
new file mode 100644
index 0000000..c8c68d9
--- /dev/null
+++ b/src/kit/kit-memory.h
@@ -0,0 +1,75 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-memory.h : Memory management
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at 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
+ *
+ **************************************************************************/
+
+#if !defined (KIT_COMPILATION) && !defined(_KIT_INSIDE_KIT_H)
+#error "Only <kit/kit.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef KIT_MEMORY_H
+#define KIT_MEMORY_H
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <kit/kit.h>
+
+KIT_BEGIN_DECLS
+
+void *kit_malloc  (size_t bytes);
+void *kit_malloc0 (size_t bytes);
+void *kit_realloc (void *memory, size_t bytes);
+void  kit_free    (void *memory);
+
+/**
+ * kit_new:
+ * @type: the type of object to allocate
+ * @count: number of objects to allocate
+ *
+ * Allocate memory for @count structures of type @type.
+ *
+ * Returns: Allocated memory, cast to a pointer of #type or #NULL on OOM.
+ */
+#define kit_new(type, count)  ((type*)kit_malloc (sizeof (type) * (count)));
+
+/**
+ * kit_new0:
+ * @type: the type of object to allocate
+ * @count: number of objects to allocate
+ *
+ * Allocate zeroed memory for @count structures of type @type.
+ *
+ * Returns: Allocated memory, cast to a pointer of #type or #NULL on OOM.
+ */
+#define kit_new0(type, count) ((type*)kit_malloc0 (sizeof (type) * (count)));
+
+void  _kit_memory_reset (void);
+int   _kit_memory_get_current_allocations (void);
+int   _kit_memory_get_total_allocations (void);
+void  _kit_memory_fail_nth_alloc (int number);
+
+KIT_END_DECLS
+
+#endif /* KIT_MEMORY_H */
+
+
diff --git a/src/kit/kit-message.c b/src/kit/kit-message.c
new file mode 100644
index 0000000..0fe6f82
--- /dev/null
+++ b/src/kit/kit-message.c
@@ -0,0 +1,109 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-message.c : Message utilities
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at 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
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <kit/kit.h>
+#include "kit-test.h"
+
+/**
+ * SECTION:kit-message
+ * @title: Message utilities
+ * @short_description: Message utilities
+ *
+ * Various message and logging utilities.
+ **/
+
+/**
+ * kit_debug:
+ * @format: printf(3) style format string
+ * @...: the parameters to insert into @format
+ *
+ * Outputs a debug message on stdout.
+ */
+void 
+kit_debug (const char *format, ...)
+{
+        va_list args;
+        char buf[1024];
+
+        kit_return_if_fail (format != NULL);
+
+        va_start (args, format);
+        vsnprintf (buf, sizeof (buf), format, args);
+        va_end (args);
+
+        printf ("[INFO %5d] %s\n", getpid (), buf);
+}
+
+/**
+ * kit_warning:
+ * @format: printf(3) style format string
+ * @...: the parameters to insert into @format
+ *
+ * Outputs a warning message on stderr.
+ */
+void 
+kit_warning (const char *format, ...)
+{
+        va_list args;
+        char buf[1024];
+
+        kit_return_if_fail (format != NULL);
+
+        va_start (args, format);
+        vsnprintf (buf, sizeof (buf), format, args);
+        va_end (args);
+
+        fprintf (stderr, "[WARN %5d] %s\n", getpid (), buf);
+}
+
+#ifdef KIT_BUILD_TESTS
+
+static kit_bool_t
+_run_test (void)
+{
+        kit_debug ("Debug %d", 42);
+        kit_warning ("Warning %d %s", 42, "foo");
+        return TRUE;
+}
+
+KitTest _test_message = {
+        "kit_message",
+        NULL,
+        NULL,
+        _run_test
+};
+
+#endif /* KIT_BUILD_TESTS */
diff --git a/src/kit/kit-message.h b/src/kit/kit-message.h
new file mode 100644
index 0000000..31472fa
--- /dev/null
+++ b/src/kit/kit-message.h
@@ -0,0 +1,44 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-message.h : Message utilities
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at 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
+ *
+ **************************************************************************/
+
+#if !defined (KIT_COMPILATION) && !defined(_KIT_INSIDE_KIT_H)
+#error "Only <kit/kit.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef KIT_MESSAGE_H
+#define KIT_MESSAGE_H
+
+#include <kit/kit.h>
+
+KIT_BEGIN_DECLS
+
+void kit_debug   (const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
+void kit_warning (const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
+
+KIT_END_DECLS
+
+#endif /* KIT_MESSAGE_H */
+
+
diff --git a/src/kit/kit-string.c b/src/kit/kit-string.c
new file mode 100644
index 0000000..e130ef4
--- /dev/null
+++ b/src/kit/kit-string.c
@@ -0,0 +1,279 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-string.c : String utilities
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at 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
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <kit/kit.h>
+#include "kit-test.h"
+
+
+/**
+ * SECTION:kit-string
+ * @title: String utilities
+ * @short_description: String utilities
+ *
+ * Various string utilities.
+ **/
+
+#ifdef KIT_BUILD_TESTS
+
+/**
+ * kit_strdup:
+ * @s: string
+ *
+ * Duplicate a string. Similar to strdup(3).
+ *
+ * Returns: Allocated memory or #NULL on OOM. Free with kit_free().
+ */
+char *
+kit_strdup (const char *s)
+{
+        char *p;
+        size_t len;
+
+        len = strlen (s);
+
+        p = kit_malloc (len + 1);
+        if (p == NULL)
+                goto out;
+
+        memcpy (p, s, len);
+        p[len] = '\0';
+
+out:
+        return p;
+}
+
+/**
+ * kit_strndup:
+ * @s: string
+ * @n: size
+ *
+ * Duplicate a string but copy at most @n characters. If @s is longer
+ * than @n, only @n characters are copied, and a terminating null byte
+ * is added. Similar to strndup(3).
+ *
+ * Returns: Allocated memory or #NULL on OOM. Free with kit_free().
+ */
+char *
+kit_strndup (const char *s, size_t n)
+{
+        char *p;
+        size_t len;
+
+        for (len = 0; len < n; len++) {
+                if (s[len] == '\0')
+                        break;
+        }
+
+
+        p = kit_malloc (len + 1);
+        if (p == NULL)
+                goto out;
+
+        memcpy (p, s, len);
+        p[len] = '\0';
+out:
+        return p;
+}
+
+#else
+
+char *
+kit_strdup (const char *s)
+{
+        return strdup (s);
+}
+
+char *
+kit_strndup (const char *s, size_t n)
+{
+        return strndup (s, n);
+}
+
+#endif /* KIT_BUILD_TESTS */
+
+/**
+ * kit_strdup_printf:
+ * @format: sprintf(3) format string
+ * @...:  the parameters to insert into the format string.
+ * 
+ * Similar to the standard C sprintf(3) function but safer, since it
+ * calculates the maximum space required and allocates memory to hold
+ * the result. The returned string should be freed when no longer
+ * needed.
+ *
+ * Returns: A newly allocated string or #NULL on OOM. Free with kit_free().
+ */
+char* 
+kit_strdup_printf (const char *format, ...)
+{
+        char *s;
+        va_list args;
+
+        va_start (args, format);
+        s = kit_strdup_vprintf (format, args);
+        va_end (args);
+
+        return s;
+}
+
+/**
+ * kit_strdup_vprintf:
+ * @format: printf(3) format string
+ * @args: list of parameters to insert
+ * 
+ * Similar to the standard C vsprintf(3) function but safer, since it
+ * calculates the maximum space required and allocates memory to hold
+ * the result. The returned string should be freed when no longer
+ * needed.
+ *
+ * Returns: A newly allocated string or #NULL on OOM. Free with kit_free().
+ */
+char* 
+kit_strdup_vprintf (const char *format, va_list args)
+{
+        char *s;
+
+#ifdef KIT_BUILD_TESTS
+        char *p;
+        vasprintf (&p, format, args);
+        s = kit_strdup (p);
+        free (p);
+#else
+        if (vasprintf (&s, format, args) == -1) {
+                s = NULL;
+        }
+#endif
+        return s;
+}
+
+
+/**
+ * kit_str_has_prefix:
+ * @s: string to check
+ * @prefix: prefix to check for
+ *
+ * Determines if a string has a given prefix.
+ *
+ * Returns: #TRUE only if @s starts with @prefix
+ */
+kit_bool_t
+kit_str_has_prefix (const char *s, const char *prefix)
+{
+        size_t s_len;
+        size_t prefix_len;
+
+        kit_return_val_if_fail (s != NULL, FALSE);
+        kit_return_val_if_fail (prefix != NULL, FALSE);
+
+        s_len = strlen (s);
+        prefix_len = strlen (prefix);
+        if (prefix_len > s_len)
+                return FALSE;
+
+        return strncmp (s, prefix, prefix_len) == 0;
+}
+
+/**
+ * kit_str_has_suffix:
+ * @s: string to check
+ * @suffix: suffix to check for
+ *
+ * Determines if a string has a given suffix.
+ *
+ * Returns: #TRUE only if @s ends with @suffix
+ */
+kit_bool_t
+kit_str_has_suffix (const char *s, const char *suffix)
+{
+        size_t s_len;
+        size_t suffix_len;
+
+        kit_return_val_if_fail (s != NULL, FALSE);
+        kit_return_val_if_fail (suffix != NULL, FALSE);
+
+        s_len = strlen (s);
+        suffix_len = strlen (suffix);
+        if (suffix_len > s_len)
+                return FALSE;
+
+        return strncmp (s + s_len - suffix_len, suffix, suffix_len) == 0;
+}
+
+
+#ifdef KIT_BUILD_TESTS
+
+static kit_bool_t
+_run_test (void)
+{
+        char str[] = "Hello world";
+        char *p;
+
+        if ((p = kit_strdup (str)) != NULL) {
+                kit_assert (strcmp (p, "Hello world") == 0);
+                kit_free (p);
+        }
+
+        if ((p = kit_strndup (str, 5)) != NULL) {
+                kit_assert (strcmp (p, "Hello") == 0);
+                kit_free (p);
+        }
+
+        if ((p = kit_strndup (str, 100)) != NULL) {
+                kit_assert (strcmp (p, "Hello world") == 0);
+                kit_free (p);
+        }
+
+        if ((p = kit_strdup_printf ("Hello %d", 5)) != NULL) {
+                kit_assert (strcmp (p, "Hello 5") == 0);
+                kit_free (p);
+        }
+
+        kit_assert ( kit_str_has_suffix ("12345", "45"));
+        kit_assert ( kit_str_has_suffix ("12345", "12345"));
+        kit_assert (!kit_str_has_suffix ("12345", "123456"));
+
+        kit_assert ( kit_str_has_prefix ("12345", "12"));
+        kit_assert ( kit_str_has_prefix ("12345", "12345"));
+        kit_assert (!kit_str_has_prefix ("12345", "123456"));
+
+        return TRUE;
+}
+
+KitTest _test_string = {
+        "kit_string",
+        NULL,
+        NULL,
+        _run_test
+};
+
+#endif /* KIT_BUILD_TESTS */
diff --git a/src/kit/kit-string.h b/src/kit/kit-string.h
new file mode 100644
index 0000000..f40c97e
--- /dev/null
+++ b/src/kit/kit-string.h
@@ -0,0 +1,49 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-string.h : String utilities
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at 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
+ *
+ **************************************************************************/
+
+#if !defined (KIT_COMPILATION) && !defined(_KIT_INSIDE_KIT_H)
+#error "Only <kit/kit.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef KIT_STRING_H
+#define KIT_STRING_H
+
+#include <kit/kit.h>
+
+KIT_BEGIN_DECLS
+
+char *kit_strdup         (const char *s);
+char *kit_strndup        (const char *s, size_t n);
+char *kit_strdup_printf  (const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
+char *kit_strdup_vprintf (const char *format, va_list args);
+
+kit_bool_t kit_str_has_prefix (const char *s, const char *prefix);
+kit_bool_t kit_str_has_suffix (const char *s, const char *suffix);
+
+KIT_END_DECLS
+
+#endif /* KIT_STRING_H */
+
+
diff --git a/src/kit/kit-test.c b/src/kit/kit-test.c
new file mode 100644
index 0000000..b2c9771
--- /dev/null
+++ b/src/kit/kit-test.c
@@ -0,0 +1,113 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-test.c : PolicyKit test
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at 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
+ *
+ **************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <kit/kit-test.h>
+#include <kit/kit-memory.h>
+
+#define MAX_TESTS 64
+
+/**
+ * SECTION:kit-test
+ * @short_description: Testing code for libkit
+ *
+ * Testing code for libkit.
+ */
+
+static KitTest *tests[] = {
+        &_test_memory,
+        &_test_string,
+        &_test_list,
+        &_test_hash,
+        &_test_file,
+        &_test_message,
+};
+
+int 
+main (int argc, char *argv[])
+{
+        int ret;
+        int n;
+        int num_tests;
+
+        ret = 0;
+
+        num_tests = sizeof (tests) / sizeof (KitTest*);
+
+        printf ("Running %d unit tests\n", num_tests);
+        for (n = 0; n < num_tests; n++) {
+                int m;
+                int total_allocs;
+                int delta;
+                KitTest *test = tests[n];
+
+                _kit_memory_reset ();
+
+                if (test->setup != NULL)
+                        test->setup ();
+
+                printf ("Running: %s\n", test->name);
+                if (!test->run ()) {
+                        printf ("Failed\n");
+                        ret = 1;
+                        goto test_done;
+                }
+
+                total_allocs = _kit_memory_get_total_allocations ();
+                printf ("  Unit test made %d allocations in total\n", total_allocs);
+                
+                delta = _kit_memory_get_current_allocations ();
+                if (delta != 0) {
+                        printf ("  Unit test leaked %d allocations\n", delta);
+                        ret = 1;
+                }
+                
+                for (m = 0; m < total_allocs; m++) {
+                        printf ("  Failing allocation %d of %d\n", m + 1, total_allocs);
+                        
+                        _kit_memory_reset ();
+                        _kit_memory_fail_nth_alloc (m);
+                        
+                        if (!test->run ()) {
+                                printf ("  Failed\n");
+                                ret = 1;
+                                continue;
+                        }
+                        
+                        delta = _kit_memory_get_current_allocations ();
+                        if (delta != 0) {
+                                printf ("  Unit test leaked %d allocations\n", delta);
+                                ret = 1;
+                        }
+                }
+
+        test_done:
+                if (test->teardown != NULL)
+                        test->teardown ();
+        }
+
+        return ret;
+}
diff --git a/src/kit/kit-test.h b/src/kit/kit-test.h
new file mode 100644
index 0000000..937db9c
--- /dev/null
+++ b/src/kit/kit-test.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit-test.h : PolicyKit test
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at 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
+ *
+ **************************************************************************/
+
+#if !defined (KIT_COMPILATION)
+#error "kit-test.h is a private file."
+#endif
+
+#ifndef KIT_TEST_H
+#define KIT_TEST_H
+
+#include <kit/kit.h>
+
+KIT_BEGIN_DECLS
+
+/**
+ * KitTest:
+ *
+ * Test suite abstraction.
+ */
+typedef struct {
+        /*< private >*/
+        const char *name;
+        void (*setup) (void);
+        void (*teardown) (void);
+        kit_bool_t (*run) (void);
+} KitTest;
+
+extern KitTest _test_memory;
+extern KitTest _test_string;
+extern KitTest _test_hash;
+extern KitTest _test_list;
+extern KitTest _test_file;
+extern KitTest _test_message;
+
+KIT_END_DECLS
+
+#endif /* KIT_TEST_H */
+
+
diff --git a/src/kit/kit.h b/src/kit/kit.h
new file mode 100644
index 0000000..b08c6ae
--- /dev/null
+++ b/src/kit/kit.h
@@ -0,0 +1,141 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/***************************************************************************
+ *
+ * kit.h : OOM-safe utility library
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at 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 KIT_H
+#define KIT_H
+
+/**
+ * SECTION:kit
+ * @title: Macros
+ * @short_description: Macros
+ *
+ * Various low-level macros.
+ **/
+
+#ifdef __cplusplus
+#  define KIT_BEGIN_DECLS extern "C" {
+#  define KIT_END_DECLS }
+#else
+/**
+ * KIT_BEGIN_DECLS:
+ *
+ * C++ include header guard.
+ */
+#  define KIT_BEGIN_DECLS
+/**
+ * KIT_END_DECLS:
+ *
+ * C++ include header guard.
+ */
+#  define KIT_END_DECLS
+#endif
+
+/**
+ * kit_bool_t:
+ *
+ * A boolean, valid values are #TRUE and #FALSE.
+ */
+typedef int kit_bool_t;
+
+#ifndef TRUE
+#  define TRUE 1
+#endif
+#ifndef FALSE
+#  define FALSE 0
+#endif
+
+/**
+ * kit_assert:
+ * @expr: expression
+ *
+ * Debugging macro to terminate the application if the assertion
+ * fails. If the assertion fails (i.e. the expression is not true), an
+ * error message is logged and the application is terminated.
+ */
+#define kit_assert(expr)                                                                        \
+do {                                                                                            \
+        if (expr) {                                                                             \
+                ;                                                                               \
+        } else {                                                                                \
+                kit_warning ("%s:%d:%s(): %s", __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
+                exit (1);                                                                       \
+        }                                                                                       \
+} while (0)
+
+/**
+ * kit_return_if_fail:
+ * @expr: expression
+ *
+ * Returns from the current function if the expression is not true. If
+ * the expression evaluates to #FALSE, an error message is logged and
+ * the function returns. This can only be used in functions which do
+ * not return a value.
+ */
+#define kit_return_if_fail(expr)                                                                \
+do {                                                                                            \
+        if (expr) {                                                                             \
+                ;                                                                               \
+        } else {                                                                                \
+                kit_warning ("%s:%d:%s(): %s", __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
+                return;                                                                         \
+        }                                                                                       \
+} while (0)
+
+/**
+ * kit_return_val_if_fail:
+ * @expr: expression
+ * @val: the value to return if the expression evaluates does not
+ * evaluate to #TRUE
+ *
+ * Returns from the current function, returning the value @val, if the
+ * expression is not true. If the expression evaluates to #FALSE, an
+ * error message is logged and val is returned.
+ */
+#define kit_return_val_if_fail(expr,val)                                                        \
+do {                                                                                            \
+        if (expr) {                                                                             \
+                ;                                                                               \
+        } else {                                                                                \
+                kit_warning ("%s:%d:%s(): %s", __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
+                return val;                                                                     \
+        }                                                                                       \
+} while (0)
+
+
+
+#define _KIT_INSIDE_KIT_H 1
+
+#include <kit/kit-memory.h>
+#include <kit/kit-string.h>
+#include <kit/kit-list.h>
+#include <kit/kit-hash.h>
+#include <kit/kit-file.h>
+#include <kit/kit-message.h>
+
+#undef _KIT_INSIDE_KIT_H
+
+#endif /* KIT_H */
+
+
diff --git a/src/polkit-dbus/polkit-read-auth-helper.c b/src/polkit-dbus/polkit-read-auth-helper.c
index 3a067d9..79be560 100644
--- a/src/polkit-dbus/polkit-read-auth-helper.c
+++ b/src/polkit-dbus/polkit-read-auth-helper.c
@@ -379,10 +379,10 @@ main (int argc, char *argv[])
 
         ret = 1;
         /* clear the entire environment to avoid attacks using with libraries honoring environment variables */
-        //if (clearenv () != 0)
-        //        goto out;
+        if (clearenv () != 0)
+                goto out;
         /* set a minimal environment */
-        //setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
+        setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
 
         openlog ("polkit-read-auth-helper", LOG_CONS | LOG_PID, LOG_AUTHPRIV);
 
diff --git a/src/polkit/Makefile.am b/src/polkit/Makefile.am
index 17f0b61..2703da8 100644
--- a/src/polkit/Makefile.am
+++ b/src/polkit/Makefile.am
@@ -21,9 +21,6 @@ libpolkitincludedir=$(includedir)/PolicyKit/polkit
 libpolkitinclude_HEADERS =              		\
 	polkit.h					\
 	polkit-sysdeps.h				\
-	polkit-memory.h					\
-	polkit-hash.h					\
-	polkit-list.h					\
 	polkit-types.h					\
 	polkit-error.h					\
 	polkit-result.h					\
@@ -45,9 +42,6 @@ libpolkit_la_SOURCES =                                					\
 	polkit.h									\
 	polkit-private.h								\
 	polkit-types.h									\
-	polkit-memory.h				polkit-memory.c				\
-	polkit-hash.h				polkit-hash.c				\
-	polkit-list.h				polkit-list.c				\
 	polkit-sysdeps.h			polkit-sysdeps.c			\
 	polkit-error.h				polkit-error.c				\
 	polkit-result.h				polkit-result.c				\
@@ -77,7 +71,7 @@ libpolkit_la_SOURCES +=                                					\
 						polkit-authorization-db.c
 endif
 
-libpolkit_la_LIBADD = @GLIB_LIBS@ @EXPAT_LIBS@
+libpolkit_la_LIBADD = @GLIB_LIBS@ @EXPAT_LIBS@ $(top_builddir)/src/kit/libkit.la
 
 libpolkit_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
 
diff --git a/src/polkit/polkit-action.c b/src/polkit/polkit-action.c
index ac7fea6..bc2c333 100644
--- a/src/polkit/polkit-action.c
+++ b/src/polkit/polkit-action.c
@@ -35,13 +35,13 @@
 #include <grp.h>
 #include <unistd.h>
 #include <errno.h>
+#include <ctype.h>
 
-#include <glib.h>
 #include "polkit-debug.h"
 #include "polkit-action.h"
 #include "polkit-utils.h"
 #include "polkit-utils.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
 #include "polkit-test.h"
 
 /**
@@ -74,7 +74,7 @@ PolKitAction *
 polkit_action_new (void)
 {
         PolKitAction *action;
-        action = p_new0 (PolKitAction, 1);
+        action = kit_new0 (PolKitAction, 1);
         if (action == NULL)
                 goto out;
         action->refcount = 1;
@@ -93,7 +93,7 @@ out:
 PolKitAction *
 polkit_action_ref (PolKitAction *action)
 {
-        g_return_val_if_fail (action != NULL, action);
+        kit_return_val_if_fail (action != NULL, action);
         action->refcount++;
         return action;
 }
@@ -109,12 +109,12 @@ polkit_action_ref (PolKitAction *action)
 void
 polkit_action_unref (PolKitAction *action)
 {
-        g_return_if_fail (action != NULL);
+        kit_return_if_fail (action != NULL);
         action->refcount--;
         if (action->refcount > 0) 
                 return;
-        p_free (action->id);
-        p_free (action);
+        kit_free (action->id);
+        kit_free (action);
 }
 
 /**
@@ -129,11 +129,11 @@ polkit_action_unref (PolKitAction *action)
 polkit_bool_t
 polkit_action_set_action_id (PolKitAction *action, const char  *action_id)
 {
-        g_return_val_if_fail (action != NULL, FALSE);
-        g_return_val_if_fail (polkit_action_validate_id (action_id), FALSE);
+        kit_return_val_if_fail (action != NULL, FALSE);
+        kit_return_val_if_fail (polkit_action_validate_id (action_id), FALSE);
         if (action->id != NULL)
-                p_free (action->id);
-        action->id = p_strdup (action_id);
+                kit_free (action->id);
+        action->id = kit_strdup (action_id);
         if (action->id == NULL)
                 return FALSE;
 
@@ -152,8 +152,8 @@ polkit_action_set_action_id (PolKitAction *action, const char  *action_id)
 polkit_bool_t
 polkit_action_get_action_id (PolKitAction *action, char **out_action_id)
 {
-        g_return_val_if_fail (action != NULL, FALSE);
-        g_return_val_if_fail (out_action_id != NULL, FALSE);
+        kit_return_val_if_fail (action != NULL, FALSE);
+        kit_return_val_if_fail (out_action_id != NULL, FALSE);
         if (action->id == NULL)
                 return FALSE;
         *out_action_id = action->id;
@@ -169,7 +169,7 @@ polkit_action_get_action_id (PolKitAction *action, char **out_action_id)
 void
 polkit_action_debug (PolKitAction *action)
 {
-        g_return_if_fail (action != NULL);
+        kit_return_if_fail (action != NULL);
         _pk_debug ("PolKitAction: refcount=%d id=%s", action->refcount, action->id);
 }
 
@@ -190,18 +190,18 @@ polkit_action_validate_id (const char *action_id)
 {
         int n;
 
-        g_return_val_if_fail (action_id != NULL, FALSE);
+        kit_return_val_if_fail (action_id != NULL, FALSE);
 
         /* validate that the form of the action identifier is correct */
-        if (!g_ascii_islower (action_id[0]))
+        if (!islower (action_id[0]))
                 goto malformed;
 
         for (n = 1; action_id[n] != '\0'; n++) {
                 if (n >= 255)
                         goto malformed;
 
-                if (! (g_ascii_islower (action_id[n]) ||
-                       g_ascii_isdigit (action_id[n]) ||
+                if (! (islower (action_id[n]) ||
+                       isdigit (action_id[n]) ||
                        action_id[n] == '.' ||
                        action_id[n] == '-'))
                         goto malformed;
@@ -224,8 +224,8 @@ malformed:
 polkit_bool_t
 polkit_action_validate (PolKitAction *action)
 {
-        g_return_val_if_fail (action != NULL, FALSE);
-        g_return_val_if_fail (action->id != NULL, FALSE);
+        kit_return_val_if_fail (action != NULL, FALSE);
+        kit_return_val_if_fail (action->id != NULL, FALSE);
 
         return polkit_action_validate_id (action->id);
 }
@@ -252,11 +252,11 @@ _run_test (void)
                                       NULL};
 
         for (n = 0; valid_action_ids[n] != NULL; n++) {
-                g_assert (polkit_action_validate_id (valid_action_ids[n]));
+                kit_assert (polkit_action_validate_id (valid_action_ids[n]));
         }
 
         for (n = 0; invalid_action_ids[n] != NULL; n++) {
-                g_assert (! polkit_action_validate_id (invalid_action_ids[n]));
+                kit_assert (! polkit_action_validate_id (invalid_action_ids[n]));
         }
 
         PolKitAction *a;
@@ -266,23 +266,23 @@ _run_test (void)
                 /* OOM */
         } else {
 
-                g_assert (! polkit_action_get_action_id (a, &s));
+                kit_assert (! polkit_action_get_action_id (a, &s));
 
                 if (!polkit_action_set_action_id (a, "org.example.action")) {
                         /* OOM */
                 } else {
-                        g_assert (polkit_action_validate (a));
+                        kit_assert (polkit_action_validate (a));
                         polkit_action_ref (a);
-                        g_assert (polkit_action_validate (a));
+                        kit_assert (polkit_action_validate (a));
                         polkit_action_unref (a);
-                        g_assert (polkit_action_validate (a));
+                        kit_assert (polkit_action_validate (a));
 
                         if (!polkit_action_set_action_id (a, "org.example.action2")) {
                                 /* OOM */
                         } else {
-                                g_assert (polkit_action_validate (a));
-                                g_assert (polkit_action_get_action_id (a, &s));
-                                g_assert (strcmp (s, "org.example.action2") == 0);
+                                kit_assert (polkit_action_validate (a));
+                                kit_assert (polkit_action_get_action_id (a, &s));
+                                kit_assert (strcmp (s, "org.example.action2") == 0);
                                 polkit_action_debug (a);
                         }
                 }
diff --git a/src/polkit/polkit-authorization-constraint.c b/src/polkit/polkit-authorization-constraint.c
index 9bb24f3..5e0c98d 100644
--- a/src/polkit/polkit-authorization-constraint.c
+++ b/src/polkit/polkit-authorization-constraint.c
@@ -37,13 +37,12 @@
 #include <unistd.h>
 #include <errno.h>
 
-#include <glib.h>
 #include "polkit-debug.h"
 #include "polkit-authorization-constraint.h"
 #include "polkit-utils.h"
 #include "polkit-private.h"
 #include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
  
 /**
  * SECTION:polkit-authorization-constraint
@@ -87,7 +86,7 @@ PolKitAuthorizationConstraint *
 _polkit_authorization_constraint_new (const char *entry_in_auth_file)
 {
         PolKitAuthorizationConstraint *authc;
-        authc = p_new0 (PolKitAuthorizationConstraint, 1);
+        authc = kit_new0 (PolKitAuthorizationConstraint, 1);
         if (authc == NULL)
                 goto oom;
         authc->refcount = 1;
@@ -108,7 +107,7 @@ oom:
 PolKitAuthorizationConstraint *
 polkit_authorization_constraint_ref (PolKitAuthorizationConstraint *authc)
 {
-        g_return_val_if_fail (authc != NULL, authc);
+        kit_return_val_if_fail (authc != NULL, authc);
         if (authc->refcount == -1)
                 return authc;
         authc->refcount++;
@@ -128,14 +127,14 @@ polkit_authorization_constraint_ref (PolKitAuthorizationConstraint *authc)
 void
 polkit_authorization_constraint_unref (PolKitAuthorizationConstraint *authc)
 {
-        g_return_if_fail (authc != NULL);
+        kit_return_if_fail (authc != NULL);
         if (authc->refcount == -1)
                 return;
         authc->refcount--;
         if (authc->refcount > 0) 
                 return;
 
-        p_free (authc);
+        kit_free (authc);
 }
 
 /**
@@ -149,7 +148,7 @@ polkit_authorization_constraint_unref (PolKitAuthorizationConstraint *authc)
 void
 polkit_authorization_constraint_debug (PolKitAuthorizationConstraint *authc)
 {
-        g_return_if_fail (authc != NULL);
+        kit_return_if_fail (authc != NULL);
         _pk_debug ("PolKitAuthorizationConstraint: refcount=%d", authc->refcount);
 }
 
@@ -166,7 +165,7 @@ polkit_authorization_constraint_debug (PolKitAuthorizationConstraint *authc)
 polkit_bool_t
 polkit_authorization_constraint_validate (PolKitAuthorizationConstraint *authc)
 {
-        g_return_val_if_fail (authc != NULL, FALSE);
+        kit_return_val_if_fail (authc != NULL, FALSE);
 
         return TRUE;
 }
@@ -192,8 +191,8 @@ polkit_authorization_constraint_check_session (PolKitAuthorizationConstraint *au
         polkit_bool_t is_active;
         polkit_bool_t is_local;
 
-        g_return_val_if_fail (authc != NULL, FALSE);
-        g_return_val_if_fail (session != NULL, FALSE);
+        kit_return_val_if_fail (authc != NULL, FALSE);
+        kit_return_val_if_fail (session != NULL, FALSE);
 
         ret = FALSE;
 
@@ -235,8 +234,8 @@ polkit_authorization_constraint_check_caller (PolKitAuthorizationConstraint *aut
         polkit_bool_t ret;
         PolKitSession *session;
 
-        g_return_val_if_fail (authc != NULL, FALSE);
-        g_return_val_if_fail (caller != NULL, FALSE);
+        kit_return_val_if_fail (authc != NULL, FALSE);
+        kit_return_val_if_fail (caller != NULL, FALSE);
 
         ret = FALSE;
 
@@ -274,7 +273,7 @@ polkit_authorization_constraint_check_caller (PolKitAuthorizationConstraint *aut
 PolKitAuthorizationConstraintFlags
 polkit_authorization_constraint_get_flags (PolKitAuthorizationConstraint *authc)
 {
-        g_return_val_if_fail (authc != NULL, FALSE);
+        kit_return_val_if_fail (authc != NULL, FALSE);
         return authc->flags;
 }
 
@@ -362,7 +361,7 @@ polkit_authorization_constraint_get_require_local_active (void)
 size_t
 polkit_authorization_constraint_to_string (PolKitAuthorizationConstraint *authc, char *out_buf, size_t buf_size)
 {
-        g_return_val_if_fail (authc != NULL, buf_size);
+        kit_return_val_if_fail (authc != NULL, buf_size);
 
         switch (authc->flags) {
         default:
@@ -394,7 +393,7 @@ polkit_authorization_constraint_from_string (const char *str)
 {
         PolKitAuthorizationConstraint *ret;
 
-        g_return_val_if_fail (str != NULL, NULL);
+        kit_return_val_if_fail (str != NULL, NULL);
 
         ret = NULL;
 
@@ -481,8 +480,8 @@ out:
 polkit_bool_t
 polkit_authorization_constraint_equal (PolKitAuthorizationConstraint *a, PolKitAuthorizationConstraint *b)
 {
-        g_return_val_if_fail (a != NULL, FALSE);
-        g_return_val_if_fail (b != NULL, FALSE);
+        kit_return_val_if_fail (a != NULL, FALSE);
+        kit_return_val_if_fail (b != NULL, FALSE);
 
         return a->flags == b->flags;
 }
@@ -504,13 +503,13 @@ _tst1 (PolKitSession *s, PolKitAuthorizationConstraint *ac, polkit_bool_t *out_r
 
         if ((c = polkit_caller_new ()) != NULL) {
                 if (ac->flags == 0)  {
-                        g_assert (polkit_authorization_constraint_check_caller (ac, c) == TRUE);
+                        kit_assert (polkit_authorization_constraint_check_caller (ac, c) == TRUE);
                 } else {
-                        g_assert (polkit_authorization_constraint_check_caller (ac, c) == FALSE);
+                        kit_assert (polkit_authorization_constraint_check_caller (ac, c) == FALSE);
                 }
 
-                g_assert (polkit_caller_set_ck_session (c, s));
-                g_assert (*out_result == polkit_authorization_constraint_check_caller (ac, c));
+                kit_assert (polkit_caller_set_ck_session (c, s));
+                kit_assert (*out_result == polkit_authorization_constraint_check_caller (ac, c));
                 polkit_caller_unref (c);
         }
 
@@ -527,11 +526,11 @@ _tst2 (PolKitAuthorizationConstraint *ac)
         PolKitAuthorizationConstraint *ac2;
 
         /* not enough space */
-        g_assert (polkit_authorization_constraint_to_string (ac, buf, 2) >= 2);
+        kit_assert (polkit_authorization_constraint_to_string (ac, buf, 2) >= 2);
 
-        g_assert (polkit_authorization_constraint_to_string (ac, buf, sizeof (buf)) < sizeof (buf));
+        kit_assert (polkit_authorization_constraint_to_string (ac, buf, sizeof (buf)) < sizeof (buf));
         if ((ac2 = polkit_authorization_constraint_from_string (buf)) != NULL) {
-                g_assert (polkit_authorization_constraint_equal (ac, ac2) == TRUE);
+                kit_assert (polkit_authorization_constraint_equal (ac, ac2) == TRUE);
                 polkit_authorization_constraint_unref (ac2);
         }
 }
@@ -550,10 +549,10 @@ _tst3 (PolKitSession *s, PolKitAuthorizationConstraint *compare_to, polkit_bool_
 
         if ((c = polkit_caller_new ()) != NULL) {
                 ac = polkit_authorization_constraint_get_from_caller (c);
-                g_assert (polkit_authorization_constraint_equal (ac, polkit_authorization_constraint_get_null ()));
+                kit_assert (polkit_authorization_constraint_equal (ac, polkit_authorization_constraint_get_null ()));
 
 
-                g_assert (polkit_caller_set_ck_session (c, s));
+                kit_assert (polkit_caller_set_ck_session (c, s));
 
                 ac = polkit_authorization_constraint_get_from_caller (c);
 
@@ -587,8 +586,8 @@ _run_test (void)
                         polkit_session_unref (s_active);
                         s_active = NULL;
                 } else {
-                        g_assert (polkit_session_set_ck_is_local (s_active, TRUE));
-                        g_assert (polkit_session_set_ck_is_active (s_active, TRUE));
+                        kit_assert (polkit_session_set_ck_is_local (s_active, TRUE));
+                        kit_assert (polkit_session_set_ck_is_active (s_active, TRUE));
                 }
         }
 
@@ -597,8 +596,8 @@ _run_test (void)
                         polkit_session_unref (s_inactive);
                         s_inactive = NULL;
                 } else {
-                        g_assert (polkit_session_set_ck_is_local (s_inactive, TRUE));
-                        g_assert (polkit_session_set_ck_is_active (s_inactive, FALSE));
+                        kit_assert (polkit_session_set_ck_is_local (s_inactive, TRUE));
+                        kit_assert (polkit_session_set_ck_is_active (s_inactive, FALSE));
                 }
         }
 
@@ -608,8 +607,8 @@ _run_test (void)
                         polkit_session_unref (s_active_remote);
                         s_active_remote = NULL;
                 } else {
-                        g_assert (polkit_session_set_ck_is_local (s_active_remote, FALSE));
-                        g_assert (polkit_session_set_ck_is_active (s_active_remote, TRUE));
+                        kit_assert (polkit_session_set_ck_is_local (s_active_remote, FALSE));
+                        kit_assert (polkit_session_set_ck_is_active (s_active_remote, TRUE));
                 }
         }
 
@@ -619,52 +618,52 @@ _run_test (void)
                         polkit_session_unref (s_inactive_remote);
                         s_inactive_remote = NULL;
                 } else {
-                        g_assert (polkit_session_set_ck_is_local (s_inactive_remote, FALSE));
-                        g_assert (polkit_session_set_ck_is_active (s_inactive_remote, FALSE));
+                        kit_assert (polkit_session_set_ck_is_local (s_inactive_remote, FALSE));
+                        kit_assert (polkit_session_set_ck_is_active (s_inactive_remote, FALSE));
                 }
         }
 
         /* null constraint */
-        g_assert ((ac = polkit_authorization_constraint_get_null ()) != NULL);
+        kit_assert ((ac = polkit_authorization_constraint_get_null ()) != NULL);
         polkit_authorization_constraint_ref (ac);
         polkit_authorization_constraint_unref (ac);
         flags = polkit_authorization_constraint_get_flags (ac);
-        g_assert (flags == 0);
-        g_assert (_tst1 (s_active, ac, &ret) || ret == TRUE);
-        g_assert (_tst1 (s_inactive, ac, &ret) || ret == TRUE);
-        g_assert (_tst1 (s_active_remote, ac, &ret) || ret == TRUE);
-        g_assert (_tst1 (s_inactive_remote, ac, &ret) || ret == TRUE);
+        kit_assert (flags == 0);
+        kit_assert (_tst1 (s_active, ac, &ret) || ret == TRUE);
+        kit_assert (_tst1 (s_inactive, ac, &ret) || ret == TRUE);
+        kit_assert (_tst1 (s_active_remote, ac, &ret) || ret == TRUE);
+        kit_assert (_tst1 (s_inactive_remote, ac, &ret) || ret == TRUE);
         _tst2 (ac);
 
         /* local constraint */
-        g_assert ((ac = polkit_authorization_constraint_get_require_local ()) != NULL);
+        kit_assert ((ac = polkit_authorization_constraint_get_require_local ()) != NULL);
         flags = polkit_authorization_constraint_get_flags (ac);
-        g_assert (flags == POLKIT_AUTHORIZATION_CONSTRAINT_REQUIRE_LOCAL);
-        g_assert (_tst1 (s_active, ac, &ret) || ret == TRUE);
-        g_assert (_tst1 (s_inactive, ac, &ret) || ret == TRUE);
-        g_assert (_tst1 (s_active_remote, ac, &ret) || ret == FALSE);
-        g_assert (_tst1 (s_inactive_remote, ac, &ret) || ret == FALSE);
+        kit_assert (flags == POLKIT_AUTHORIZATION_CONSTRAINT_REQUIRE_LOCAL);
+        kit_assert (_tst1 (s_active, ac, &ret) || ret == TRUE);
+        kit_assert (_tst1 (s_inactive, ac, &ret) || ret == TRUE);
+        kit_assert (_tst1 (s_active_remote, ac, &ret) || ret == FALSE);
+        kit_assert (_tst1 (s_inactive_remote, ac, &ret) || ret == FALSE);
         _tst2 (ac);
 
         /* active constraint */
-        g_assert ((ac = polkit_authorization_constraint_get_require_active ()) != NULL);
+        kit_assert ((ac = polkit_authorization_constraint_get_require_active ()) != NULL);
         flags = polkit_authorization_constraint_get_flags (ac);
-        g_assert (flags == POLKIT_AUTHORIZATION_CONSTRAINT_REQUIRE_ACTIVE);
-        g_assert (_tst1 (s_active, ac, &ret) || ret == TRUE);
-        g_assert (_tst1 (s_inactive, ac, &ret) || ret == FALSE);
-        g_assert (_tst1 (s_active_remote, ac, &ret) || ret == TRUE);
-        g_assert (_tst1 (s_inactive_remote, ac, &ret) || ret == FALSE);
+        kit_assert (flags == POLKIT_AUTHORIZATION_CONSTRAINT_REQUIRE_ACTIVE);
+        kit_assert (_tst1 (s_active, ac, &ret) || ret == TRUE);
+        kit_assert (_tst1 (s_inactive, ac, &ret) || ret == FALSE);
+        kit_assert (_tst1 (s_active_remote, ac, &ret) || ret == TRUE);
+        kit_assert (_tst1 (s_inactive_remote, ac, &ret) || ret == FALSE);
         _tst2 (ac);
 
         /* local+active constraint */
-        g_assert ((ac = polkit_authorization_constraint_get_require_local_active ()) != NULL);
+        kit_assert ((ac = polkit_authorization_constraint_get_require_local_active ()) != NULL);
         flags = polkit_authorization_constraint_get_flags (ac);
-        g_assert (flags == (POLKIT_AUTHORIZATION_CONSTRAINT_REQUIRE_LOCAL|
+        kit_assert (flags == (POLKIT_AUTHORIZATION_CONSTRAINT_REQUIRE_LOCAL|
                             POLKIT_AUTHORIZATION_CONSTRAINT_REQUIRE_ACTIVE));
-        g_assert (_tst1 (s_active, ac, &ret) || ret == TRUE);
-        g_assert (_tst1 (s_inactive, ac, &ret) || ret == FALSE);
-        g_assert (_tst1 (s_active_remote, ac, &ret) || ret == FALSE);
-        g_assert (_tst1 (s_inactive_remote, ac, &ret) || ret == FALSE);
+        kit_assert (_tst1 (s_active, ac, &ret) || ret == TRUE);
+        kit_assert (_tst1 (s_inactive, ac, &ret) || ret == FALSE);
+        kit_assert (_tst1 (s_active_remote, ac, &ret) || ret == FALSE);
+        kit_assert (_tst1 (s_inactive_remote, ac, &ret) || ret == FALSE);
         _tst2 (ac);
 
         for (n = 0; n < 4; n++) {
@@ -702,10 +701,10 @@ _run_test (void)
                         break;
                 }
 
-                g_assert (_tst3 (s, polkit_authorization_constraint_get_require_local_active (), &ret) || ret == expected[0]);
-                g_assert (_tst3 (s, polkit_authorization_constraint_get_require_local (), &ret) || ret == expected[1]);
-                g_assert (_tst3 (s, polkit_authorization_constraint_get_require_active (), &ret) || ret == expected[2]);
-                g_assert (_tst3 (s, polkit_authorization_constraint_get_null (), &ret) || ret == expected[3]);
+                kit_assert (_tst3 (s, polkit_authorization_constraint_get_require_local_active (), &ret) || ret == expected[0]);
+                kit_assert (_tst3 (s, polkit_authorization_constraint_get_require_local (), &ret) || ret == expected[1]);
+                kit_assert (_tst3 (s, polkit_authorization_constraint_get_require_active (), &ret) || ret == expected[2]);
+                kit_assert (_tst3 (s, polkit_authorization_constraint_get_null (), &ret) || ret == expected[3]);
         }
 
         if ((ac = _polkit_authorization_constraint_new ("local+active")) != NULL) {
diff --git a/src/polkit/polkit-authorization-db-dummy.c b/src/polkit/polkit-authorization-db-dummy.c
index 30a086b..023d764 100644
--- a/src/polkit/polkit-authorization-db-dummy.c
+++ b/src/polkit/polkit-authorization-db-dummy.c
@@ -83,7 +83,7 @@ _polkit_authorization_db_pfe_get_by_id (PolKitPolicyCache *policy_cache,
 PolKitAuthorizationDB *
 polkit_authorization_db_ref (PolKitAuthorizationDB *authdb)
 {
-        g_return_val_if_fail (authdb != NULL, authdb);
+        kit_return_val_if_fail (authdb != NULL, authdb);
         authdb->refcount++;
         return authdb;
 }
@@ -91,7 +91,7 @@ polkit_authorization_db_ref (PolKitAuthorizationDB *authdb)
 void 
 polkit_authorization_db_unref (PolKitAuthorizationDB *authdb)
 {
-        g_return_if_fail (authdb != NULL);
+        kit_return_if_fail (authdb != NULL);
         authdb->refcount--;
         if (authdb->refcount > 0) 
                 return;
@@ -101,14 +101,14 @@ polkit_authorization_db_unref (PolKitAuthorizationDB *authdb)
 void 
 polkit_authorization_db_debug (PolKitAuthorizationDB *authdb)
 {
-        g_return_if_fail (authdb != NULL);
+        kit_return_if_fail (authdb != NULL);
         _pk_debug ("PolKitAuthorizationDB: refcount=%d", authdb->refcount);
 }
 
 polkit_bool_t
 polkit_authorization_db_validate (PolKitAuthorizationDB *authdb)
 {
-        g_return_val_if_fail (authdb != NULL, FALSE);
+        kit_return_val_if_fail (authdb != NULL, FALSE);
 
         return TRUE;
 }
diff --git a/src/polkit/polkit-authorization-db.c b/src/polkit/polkit-authorization-db.c
index 3f2edee..d7810eb 100644
--- a/src/polkit/polkit-authorization-db.c
+++ b/src/polkit/polkit-authorization-db.c
@@ -45,6 +45,8 @@
 #include "polkit-authorization-db.h"
 #include "polkit-utils.h"
 #include "polkit-private.h"
+#include "polkit-test.h"
+#include "polkit-private.h"
 
 /**
  * SECTION:polkit-authorization-db
@@ -148,7 +150,7 @@ _polkit_authorization_db_pfe_get_by_id (PolKitPolicyCache *policy_cache,
 PolKitAuthorizationDB *
 polkit_authorization_db_ref (PolKitAuthorizationDB *authdb)
 {
-        g_return_val_if_fail (authdb != NULL, authdb);
+        kit_return_val_if_fail (authdb != NULL, authdb);
         authdb->refcount++;
         return authdb;
 }
@@ -166,11 +168,11 @@ polkit_authorization_db_ref (PolKitAuthorizationDB *authdb)
 void
 polkit_authorization_db_unref (PolKitAuthorizationDB *authdb)
 {
-        g_return_if_fail (authdb != NULL);
+        kit_return_if_fail (authdb != NULL);
         authdb->refcount--;
         if (authdb->refcount > 0) 
                 return;
-        g_hash_table_destroy (authdb->uid_to_authlist);
+        kit_hash_unref (authdb->uid_to_authlist);
         g_free (authdb);
 }
 
@@ -185,7 +187,7 @@ polkit_authorization_db_unref (PolKitAuthorizationDB *authdb)
 void
 polkit_authorization_db_debug (PolKitAuthorizationDB *authdb)
 {
-        g_return_if_fail (authdb != NULL);
+        kit_return_if_fail (authdb != NULL);
         _pk_debug ("PolKitAuthorizationDB: refcount=%d", authdb->refcount);
 }
 
@@ -202,7 +204,7 @@ polkit_authorization_db_debug (PolKitAuthorizationDB *authdb)
 polkit_bool_t
 polkit_authorization_db_validate (PolKitAuthorizationDB *authdb)
 {
-        g_return_val_if_fail (authdb != NULL, FALSE);
+        kit_return_val_if_fail (authdb != NULL, FALSE);
 
         return TRUE;
 }
@@ -222,12 +224,14 @@ _polkit_authorization_db_invalidate_cache (PolKitAuthorizationDB *authdb)
 {
         /* out with the old, in the with new */
         if (authdb->uid_to_authlist != NULL) {
-                g_hash_table_destroy (authdb->uid_to_authlist);
+                kit_hash_unref (authdb->uid_to_authlist);
         }
-        authdb->uid_to_authlist = g_hash_table_new_full (g_direct_hash,
-                                                         g_direct_equal,
-                                                         NULL,
-                                                         (GDestroyNotify) _free_authlist);
+        authdb->uid_to_authlist = kit_hash_new (kit_hash_direct_hash_func,
+                                                kit_hash_direct_equal_func,
+                                                NULL,
+                                                NULL,
+                                                NULL,
+                                                (KitFreeFunc) _free_authlist);
 }
 
 /**
@@ -263,7 +267,7 @@ _authdb_get_auths_for_uid (PolKitAuthorizationDB *authdb,
         standard_output = NULL;
 
         /* first, see if this is in the cache */
-        ret = g_hash_table_lookup (authdb->uid_to_authlist, (gpointer) uid);
+        ret = kit_hash_lookup (authdb->uid_to_authlist, (void *) uid, NULL);
         if (ret != NULL)
                 goto out;
 
@@ -345,7 +349,7 @@ _authdb_get_auths_for_uid (PolKitAuthorizationDB *authdb,
                 n = m + 1;
         }
 
-        g_hash_table_insert (authdb->uid_to_authlist, (gpointer) uid, ret);
+        kit_hash_insert (authdb->uid_to_authlist, (void *) uid, ret);
 
 out:
         g_free (helper_argv[1]);
@@ -367,8 +371,8 @@ _internal_foreach (PolKitAuthorizationDB       *authdb,
         polkit_bool_t ret;
         char *action_id;
 
-        g_return_val_if_fail (authdb != NULL, FALSE);
-        g_return_val_if_fail (cb != NULL, FALSE);
+        kit_return_val_if_fail (authdb != NULL, FALSE);
+        kit_return_val_if_fail (cb != NULL, FALSE);
 
         ret = FALSE;
 
@@ -488,7 +492,7 @@ polkit_authorization_db_foreach_for_action (PolKitAuthorizationDB       *authdb,
                                             void                        *user_data,
                                             PolKitError                **error)
 {
-        g_return_val_if_fail (action != NULL, FALSE);
+        kit_return_val_if_fail (action != NULL, FALSE);
         return _internal_foreach (authdb, action, -1, cb, user_data, error);
 }
 
@@ -522,7 +526,7 @@ polkit_authorization_db_foreach_for_action_for_uid (PolKitAuthorizationDB
                                                     void                        *user_data,
                                                     PolKitError                **error)
 {
-        g_return_val_if_fail (action != NULL, FALSE);
+        kit_return_val_if_fail (action != NULL, FALSE);
         return _internal_foreach (authdb, action, uid, cb, user_data, error);
 }
 
@@ -598,10 +602,10 @@ polkit_authorization_db_is_session_authorized (PolKitAuthorizationDB *authdb,
 
         ret = FALSE;
 
-        g_return_val_if_fail (authdb != NULL, FALSE);
-        g_return_val_if_fail (action != NULL, FALSE);
-        g_return_val_if_fail (session != NULL, FALSE);
-        g_return_val_if_fail (out_is_authorized != NULL, FALSE);
+        kit_return_val_if_fail (authdb != NULL, FALSE);
+        kit_return_val_if_fail (action != NULL, FALSE);
+        kit_return_val_if_fail (session != NULL, FALSE);
+        kit_return_val_if_fail (out_is_authorized != NULL, FALSE);
 
         if (!polkit_action_get_action_id (action, &cd.action_id))
                 return FALSE;
@@ -731,10 +735,10 @@ polkit_authorization_db_is_caller_authorized (PolKitAuthorizationDB *authdb,
 
         ret = FALSE;
 
-        g_return_val_if_fail (authdb != NULL, FALSE);
-        g_return_val_if_fail (action != NULL, FALSE);
-        g_return_val_if_fail (caller != NULL, FALSE);
-        g_return_val_if_fail (out_is_authorized != NULL, FALSE);
+        kit_return_val_if_fail (authdb != NULL, FALSE);
+        kit_return_val_if_fail (action != NULL, FALSE);
+        kit_return_val_if_fail (caller != NULL, FALSE);
+        kit_return_val_if_fail (out_is_authorized != NULL, FALSE);
 
         if (!polkit_action_get_action_id (action, &cd.action_id))
                 return FALSE;
@@ -799,8 +803,8 @@ polkit_authorization_db_revoke_entry (PolKitAuthorizationDB *authdb,
 
         ret = FALSE;
 
-        g_return_val_if_fail (authdb != NULL, FALSE);
-        g_return_val_if_fail (auth != NULL, FALSE);
+        kit_return_val_if_fail (authdb != NULL, FALSE);
+        kit_return_val_if_fail (auth != NULL, FALSE);
 
         auth_file_entry = _polkit_authorization_get_authfile_entry (auth);
         //g_debug ("should delete line '%s'", auth_file_entry);
@@ -847,3 +851,82 @@ out:
         g_free (helper_argv[3]);
         return ret;
 }
+
+#ifdef POLKIT_BUILD_TESTS
+
+static polkit_bool_t
+_run_test (void)
+{
+        PolKitAuthorizationDB *adb;
+        const char test_passwd[] = 
+                "pu1:x:50400:50400:PolKit Test user 1:/home/polkittest1:/bin/bash\n"
+                "pu2:x:50401:50401:PolKit Test user 2:/home/polkittest2:/bin/bash\n";
+        const char test_pu1_run[] =
+                "";
+        const char test_pu1_lib[] =
+                "grant:org.freedesktop.policykit.read:1194634242:0:none\n";
+        const char test_pu2_run[] =
+                "";
+        const char test_pu2_lib[] =
+                "";
+        
+        if (setenv ("POLKIT_TEST_LOCALSTATE_DIR", TEST_DATA_DIR "authdb-test", 1) != 0)
+                goto fail;
+
+        if (setenv ("POLKIT_TEST_PASSWD_FILE", TEST_DATA_DIR "authdb-test/passwd", 1) != 0)
+                goto fail;
+
+        /* create test users */
+        if (!kit_file_set_contents (TEST_DATA_DIR "authdb-test/passwd", 0644, 
+                                    test_passwd, sizeof (test_passwd) - 1))
+                goto out;
+
+        /* seed the authdb with known defaults */
+        if (!kit_file_set_contents (TEST_DATA_DIR "authdb-test/run/PolicyKit/user-pu1.auths", 0644, 
+                                    test_pu1_run, sizeof (test_pu1_run) - 1))
+                goto out;
+        if (!kit_file_set_contents (TEST_DATA_DIR "authdb-test/lib/PolicyKit/user-pu1.auths", 0644, 
+                                    test_pu1_lib, sizeof (test_pu1_lib) - 1))
+                goto out;
+        if (!kit_file_set_contents (TEST_DATA_DIR "authdb-test/run/PolicyKit/user-pu2.auths", 0644, 
+                                    test_pu2_run, sizeof (test_pu2_run) - 1))
+                goto out;
+        if (!kit_file_set_contents (TEST_DATA_DIR "authdb-test/lib/PolicyKit/user-pu2.auths", 0644, 
+                                    test_pu2_lib, sizeof (test_pu2_lib) - 1))
+                goto out;
+
+        if ((adb = _polkit_authorization_db_new ()) == NULL)
+                goto out;
+
+        if (setenv ("POLKIT_TEST_PRETEND_TO_BE_UID", "50400", 1) != 0)
+                goto fail;
+
+        /* TODO: FIXME: this code is not finished */
+
+
+        polkit_authorization_db_unref (adb);
+
+out:
+        if (unsetenv ("POLKIT_TEST_PRETEND_TO_BE_UID") != 0)
+                goto fail;
+
+        if (unsetenv ("POLKIT_TEST_LOCALSTATE_DIR") != 0)
+                goto fail;
+
+        if (unsetenv ("POLKIT_TEST_PASSWD_FILE") != 0)
+                goto fail;
+
+        return TRUE;
+fail:
+        return FALSE;
+}
+
+
+PolKitTest _test_authorization_db = {
+        "polkit_authorization_db",
+        NULL,
+        NULL,
+        _run_test
+};
+
+#endif /* POLKIT_BUILD_TESTS */
diff --git a/src/polkit/polkit-authorization.c b/src/polkit/polkit-authorization.c
index 76a3e5d..d1374f5 100644
--- a/src/polkit/polkit-authorization.c
+++ b/src/polkit/polkit-authorization.c
@@ -38,12 +38,13 @@
 #include <errno.h>
 
 #include <glib.h>
+
 #include "polkit-debug.h"
 #include "polkit-authorization.h"
 #include "polkit-utils.h"
 #include "polkit-private.h"
 #include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
 
 /**
  * SECTION:polkit-authorization
@@ -90,7 +91,7 @@ struct _PolKitAuthorization
 const char *
 _polkit_authorization_get_authfile_entry (PolKitAuthorization *auth)
 {
-        g_return_val_if_fail (auth != NULL, NULL);
+        kit_return_val_if_fail (auth != NULL, NULL);
         return auth->entry_in_auth_file;
 }
 
@@ -105,16 +106,16 @@ _polkit_authorization_new_for_uid (const char *entry_in_auth_file, uid_t uid)
         PolKitAuthorization *auth;
         int n;
 
-        g_return_val_if_fail (entry_in_auth_file != NULL, NULL);
+        kit_return_val_if_fail (entry_in_auth_file != NULL, NULL);
 
         t = NULL;
 
-        auth = p_new0 (PolKitAuthorization, 1);
+        auth = kit_new0 (PolKitAuthorization, 1);
         if (auth == NULL)
                 goto oom;
 
         auth->refcount = 1;
-        auth->entry_in_auth_file = p_strdup (entry_in_auth_file);
+        auth->entry_in_auth_file = kit_strdup (entry_in_auth_file);
         if (auth->entry_in_auth_file == NULL)
                 goto oom;
 
@@ -155,7 +156,7 @@ _polkit_authorization_new_for_uid (const char *entry_in_auth_file, uid_t uid)
 
                 if (!polkit_action_validate_id (t[n]))
                         goto error;
-                auth->action_id = p_strdup (t[n++]);
+                auth->action_id = kit_strdup (t[n++]);
                 if (auth->action_id == NULL)
                         goto oom;
 
@@ -185,13 +186,13 @@ _polkit_authorization_new_for_uid (const char *entry_in_auth_file, uid_t uid)
 
                 auth->scope = POLKIT_AUTHORIZATION_SCOPE_SESSION;
 
-                auth->session_id = p_strdup (t[n++]);
+                auth->session_id = kit_strdup (t[n++]);
                 if (auth->session_id == NULL)
                         goto oom;
 
                 if (!polkit_action_validate_id (t[n]))
                         goto error;
-                auth->action_id = p_strdup (t[n++]);
+                auth->action_id = kit_strdup (t[n++]);
                 if (auth->action_id == NULL)
                         goto oom;
 
@@ -225,7 +226,7 @@ _polkit_authorization_new_for_uid (const char *entry_in_auth_file, uid_t uid)
 
                 if (!polkit_action_validate_id (t[n]))
                         goto error;
-                auth->action_id = p_strdup (t[n++]);
+                auth->action_id = kit_strdup (t[n++]);
                 if (auth->action_id == NULL)
                         goto oom;
 
@@ -260,7 +261,7 @@ _polkit_authorization_new_for_uid (const char *entry_in_auth_file, uid_t uid)
 
                 if (!polkit_action_validate_id (t[n]))
                         goto error;
-                auth->action_id = p_strdup (t[n++]);
+                auth->action_id = kit_strdup (t[n++]);
                 if (auth->action_id == NULL)
                         goto oom;
 
@@ -308,7 +309,7 @@ oom:
 PolKitAuthorization *
 polkit_authorization_ref (PolKitAuthorization *auth)
 {
-        g_return_val_if_fail (auth != NULL, auth);
+        kit_return_val_if_fail (auth != NULL, auth);
         auth->refcount++;
         return auth;
 }
@@ -326,17 +327,17 @@ polkit_authorization_ref (PolKitAuthorization *auth)
 void
 polkit_authorization_unref (PolKitAuthorization *auth)
 {
-        g_return_if_fail (auth != NULL);
+        kit_return_if_fail (auth != NULL);
         auth->refcount--;
         if (auth->refcount > 0) 
                 return;
 
-        p_free (auth->entry_in_auth_file);
-        p_free (auth->action_id);
-        p_free (auth->session_id);
+        kit_free (auth->entry_in_auth_file);
+        kit_free (auth->action_id);
+        kit_free (auth->session_id);
         if (auth->constraint != NULL)
                 polkit_authorization_constraint_unref (auth->constraint);
-        p_free (auth);
+        kit_free (auth);
 }
 
 /**
@@ -350,7 +351,7 @@ polkit_authorization_unref (PolKitAuthorization *auth)
 void
 polkit_authorization_debug (PolKitAuthorization *auth)
 {
-        g_return_if_fail (auth != NULL);
+        kit_return_if_fail (auth != NULL);
         _pk_debug ("PolKitAuthorization: refcount=%d", auth->refcount);
         _pk_debug (" scope          = %d",  auth->scope);
         _pk_debug (" pid            = %d",  auth->pid);
@@ -373,7 +374,7 @@ polkit_authorization_debug (PolKitAuthorization *auth)
 polkit_bool_t
 polkit_authorization_validate (PolKitAuthorization *auth)
 {
-        g_return_val_if_fail (auth != NULL, FALSE);
+        kit_return_val_if_fail (auth != NULL, FALSE);
 
         return TRUE;
 }
@@ -391,7 +392,7 @@ polkit_authorization_validate (PolKitAuthorization *auth)
 const char *
 polkit_authorization_get_action_id (PolKitAuthorization *auth)
 {
-        g_return_val_if_fail (auth != NULL, NULL);
+        kit_return_val_if_fail (auth != NULL, NULL);
 
         return auth->action_id;
 }
@@ -412,7 +413,7 @@ polkit_authorization_get_action_id (PolKitAuthorization *auth)
 PolKitAuthorizationScope
 polkit_authorization_get_scope (PolKitAuthorization *auth)
 {
-        g_return_val_if_fail (auth != NULL, 0);
+        kit_return_val_if_fail (auth != NULL, 0);
 
         return auth->scope;
 }
@@ -440,10 +441,10 @@ polkit_authorization_scope_process_get_pid (PolKitAuthorization *auth,
                                             pid_t *out_pid, 
                                             polkit_uint64_t *out_pid_start_time)
 {
-        g_return_val_if_fail (auth != NULL, FALSE);
-        g_return_val_if_fail (out_pid != NULL, FALSE);
-        g_return_val_if_fail (out_pid_start_time != NULL, FALSE);
-        g_return_val_if_fail (auth->scope == POLKIT_AUTHORIZATION_SCOPE_PROCESS || 
+        kit_return_val_if_fail (auth != NULL, FALSE);
+        kit_return_val_if_fail (out_pid != NULL, FALSE);
+        kit_return_val_if_fail (out_pid_start_time != NULL, FALSE);
+        kit_return_val_if_fail (auth->scope == POLKIT_AUTHORIZATION_SCOPE_PROCESS || 
                               auth->scope == POLKIT_AUTHORIZATION_SCOPE_PROCESS_ONE_SHOT, FALSE);
 
         *out_pid = auth->pid;
@@ -466,8 +467,8 @@ polkit_authorization_scope_process_get_pid (PolKitAuthorization *auth,
 const char *
 polkit_authorization_scope_session_get_ck_objref (PolKitAuthorization *auth)
 {
-        g_return_val_if_fail (auth != NULL, FALSE);
-        g_return_val_if_fail (auth->scope == POLKIT_AUTHORIZATION_SCOPE_SESSION, FALSE);
+        kit_return_val_if_fail (auth != NULL, FALSE);
+        kit_return_val_if_fail (auth->scope == POLKIT_AUTHORIZATION_SCOPE_SESSION, FALSE);
 
         return auth->session_id;
 }
@@ -486,7 +487,7 @@ polkit_authorization_scope_session_get_ck_objref (PolKitAuthorization *auth)
 uid_t
 polkit_authorization_get_uid (PolKitAuthorization *auth)
 {
-        g_return_val_if_fail (auth != NULL, 0);
+        kit_return_val_if_fail (auth != NULL, 0);
         return auth->uid;
 }
 
@@ -505,7 +506,7 @@ polkit_authorization_get_uid (PolKitAuthorization *auth)
 time_t
 polkit_authorization_get_time_of_grant (PolKitAuthorization *auth)
 {
-        g_return_val_if_fail (auth != NULL, 0);
+        kit_return_val_if_fail (auth != NULL, 0);
         return auth->when;
 }
 
@@ -531,8 +532,8 @@ polkit_bool_t
 polkit_authorization_was_granted_via_defaults (PolKitAuthorization *auth,
                                                uid_t *out_user_authenticated_as)
 {
-        g_return_val_if_fail (auth != NULL, FALSE);
-        g_return_val_if_fail (out_user_authenticated_as != NULL, FALSE);
+        kit_return_val_if_fail (auth != NULL, FALSE);
+        kit_return_val_if_fail (out_user_authenticated_as != NULL, FALSE);
 
         if (auth->explicitly_granted)
                 return FALSE;
@@ -561,8 +562,8 @@ polkit_bool_t
 polkit_authorization_was_granted_explicitly (PolKitAuthorization *auth,
                                              uid_t *out_by_whom)
 {
-        g_return_val_if_fail (auth != NULL, FALSE);
-        g_return_val_if_fail (out_by_whom != NULL, FALSE);
+        kit_return_val_if_fail (auth != NULL, FALSE);
+        kit_return_val_if_fail (out_by_whom != NULL, FALSE);
 
         if (!auth->explicitly_granted)
                 return FALSE;
@@ -585,7 +586,7 @@ polkit_authorization_was_granted_explicitly (PolKitAuthorization *auth,
 PolKitAuthorizationConstraint *
 polkit_authorization_get_constraint (PolKitAuthorization *auth)
 {
-        g_return_val_if_fail (auth != NULL, FALSE);
+        kit_return_val_if_fail (auth != NULL, FALSE);
         return auth->constraint;
 }
 
@@ -722,39 +723,39 @@ _run_test (void)
                         polkit_authorization_debug (a);
                         polkit_authorization_validate (a);
 
-                        g_assert (t->scope == polkit_authorization_get_scope (a));
-                        g_assert (t->time_of_grant == polkit_authorization_get_time_of_grant (a));
-                        g_assert (500 == polkit_authorization_get_uid (a));
+                        kit_assert (t->scope == polkit_authorization_get_scope (a));
+                        kit_assert (t->time_of_grant == polkit_authorization_get_time_of_grant (a));
+                        kit_assert (500 == polkit_authorization_get_uid (a));
 
                         switch (t->scope) {
                         case POLKIT_AUTHORIZATION_SCOPE_PROCESS_ONE_SHOT: /* explicit fallthrough */
                         case POLKIT_AUTHORIZATION_SCOPE_PROCESS:
-                                g_assert (polkit_authorization_scope_process_get_pid (a, &pid, &pid_start_time) && 
+                                kit_assert (polkit_authorization_scope_process_get_pid (a, &pid, &pid_start_time) && 
                                           t->pid == pid && t->pid_start_time == pid_start_time);
                                 break;
                         case POLKIT_AUTHORIZATION_SCOPE_SESSION:
-                                g_assert ((s = polkit_authorization_scope_session_get_ck_objref (a)) != NULL &&
+                                kit_assert ((s = polkit_authorization_scope_session_get_ck_objref (a)) != NULL &&
                                           strcmp (s, t->session) == 0);
                                 break;
                         case POLKIT_AUTHORIZATION_SCOPE_ALWAYS:
                                 break;
                         }
 
-                        g_assert ((s = _polkit_authorization_get_authfile_entry (a)) != NULL && strcmp (t->entry, s) == 0);
+                        kit_assert ((s = _polkit_authorization_get_authfile_entry (a)) != NULL && strcmp (t->entry, s) == 0);
 
-                        g_assert ((s = polkit_authorization_get_action_id (a)) != NULL && strcmp (t->action_id, s) == 0);
+                        kit_assert ((s = polkit_authorization_get_action_id (a)) != NULL && strcmp (t->action_id, s) == 0);
 
-                        g_assert (t->time_of_grant == polkit_authorization_get_time_of_grant (a));
+                        kit_assert (t->time_of_grant == polkit_authorization_get_time_of_grant (a));
 
-                        g_assert ((ac = polkit_authorization_get_constraint (a)) != NULL &&
+                        kit_assert ((ac = polkit_authorization_get_constraint (a)) != NULL &&
                                   polkit_authorization_constraint_equal (ac, t->constraint));
 
                         if (t->explicit) {
-                                g_assert (!polkit_authorization_was_granted_via_defaults (a, &uid));
-                                g_assert (polkit_authorization_was_granted_explicitly (a, &uid) && uid == t->from);
+                                kit_assert (!polkit_authorization_was_granted_via_defaults (a, &uid));
+                                kit_assert (polkit_authorization_was_granted_explicitly (a, &uid) && uid == t->from);
                         } else {
-                                g_assert (polkit_authorization_was_granted_via_defaults (a, &uid) && uid == t->from);
-                                g_assert (!polkit_authorization_was_granted_explicitly (a, &uid));
+                                kit_assert (polkit_authorization_was_granted_via_defaults (a, &uid) && uid == t->from);
+                                kit_assert (!polkit_authorization_was_granted_explicitly (a, &uid));
                         }
 
                         polkit_authorization_ref (a);
@@ -764,7 +765,7 @@ _run_test (void)
         }
 
         for (n = 0; n < num_invalid_auths; n++) {
-                g_assert (_polkit_authorization_new_for_uid (invalid_auths[n], 500) == NULL);
+                kit_assert (_polkit_authorization_new_for_uid (invalid_auths[n], 500) == NULL);
         }
 
         return TRUE;
diff --git a/src/polkit/polkit-caller.c b/src/polkit/polkit-caller.c
index d3432b2..faf0a54 100644
--- a/src/polkit/polkit-caller.c
+++ b/src/polkit/polkit-caller.c
@@ -45,12 +45,11 @@
 #include <unistd.h>
 #include <errno.h>
 
-#include <glib.h>
 #include "polkit-debug.h"
 #include "polkit-caller.h"
 #include "polkit-utils.h"
 #include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
 
 /**
  * PolKitCaller:
@@ -79,7 +78,7 @@ PolKitCaller *
 polkit_caller_new (void)
 {
         PolKitCaller *caller;
-        caller = p_new0 (PolKitCaller, 1);
+        caller = kit_new0 (PolKitCaller, 1);
         if (caller == NULL)
                 goto out;
         caller->refcount = 1;
@@ -98,7 +97,7 @@ out:
 PolKitCaller *
 polkit_caller_ref (PolKitCaller *caller)
 {
-        g_return_val_if_fail (caller != NULL, caller);
+        kit_return_val_if_fail (caller != NULL, caller);
         caller->refcount++;
         return caller;
 }
@@ -115,15 +114,15 @@ polkit_caller_ref (PolKitCaller *caller)
 void
 polkit_caller_unref (PolKitCaller *caller)
 {
-        g_return_if_fail (caller != NULL);
+        kit_return_if_fail (caller != NULL);
         caller->refcount--;
         if (caller->refcount > 0) 
                 return;
-        p_free (caller->dbus_name);
-        p_free (caller->selinux_context);
+        kit_free (caller->dbus_name);
+        kit_free (caller->selinux_context);
         if (caller->session != NULL)
                 polkit_session_unref (caller->session);
-        p_free (caller);
+        kit_free (caller);
 }
 
 /**
@@ -138,15 +137,15 @@ polkit_caller_unref (PolKitCaller *caller)
 polkit_bool_t
 polkit_caller_set_dbus_name (PolKitCaller *caller, const char *dbus_name)
 {
-        g_return_val_if_fail (caller != NULL, FALSE);
-        g_return_val_if_fail (dbus_name == NULL || _pk_validate_unique_bus_name (dbus_name), FALSE);
+        kit_return_val_if_fail (caller != NULL, FALSE);
+        kit_return_val_if_fail (dbus_name == NULL || _pk_validate_unique_bus_name (dbus_name), FALSE);
         if (caller->dbus_name != NULL)
-                p_free (caller->dbus_name);
+                kit_free (caller->dbus_name);
         if (dbus_name == NULL) {
                 caller->dbus_name = NULL;
                 return TRUE;
         } else {
-                caller->dbus_name = p_strdup (dbus_name);
+                caller->dbus_name = kit_strdup (dbus_name);
                 if (caller->dbus_name == NULL)
                         return FALSE;
                 else
@@ -166,7 +165,7 @@ polkit_caller_set_dbus_name (PolKitCaller *caller, const char *dbus_name)
 polkit_bool_t
 polkit_caller_set_uid (PolKitCaller *caller, uid_t uid)
 {
-        g_return_val_if_fail (caller != NULL, FALSE);
+        kit_return_val_if_fail (caller != NULL, FALSE);
         caller->uid = uid;
         return TRUE;
 }
@@ -183,7 +182,7 @@ polkit_caller_set_uid (PolKitCaller *caller, uid_t uid)
 polkit_bool_t
 polkit_caller_set_pid (PolKitCaller *caller, pid_t pid)
 {
-        g_return_val_if_fail (caller != NULL, FALSE);
+        kit_return_val_if_fail (caller != NULL, FALSE);
         caller->pid = pid;
         return TRUE;
 }
@@ -200,17 +199,17 @@ polkit_caller_set_pid (PolKitCaller *caller, pid_t pid)
 polkit_bool_t
 polkit_caller_set_selinux_context (PolKitCaller *caller, const char *selinux_context)
 {
-        g_return_val_if_fail (caller != NULL, FALSE);
+        kit_return_val_if_fail (caller != NULL, FALSE);
         /* TODO: probably should have a separate validation function for SELinux contexts */
-        g_return_val_if_fail (selinux_context == NULL || _pk_validate_identifier (selinux_context), FALSE);
+        kit_return_val_if_fail (selinux_context == NULL || _pk_validate_identifier (selinux_context), FALSE);
 
         if (caller->selinux_context != NULL)
-                p_free (caller->selinux_context);
+                kit_free (caller->selinux_context);
         if (selinux_context == NULL) {
                 caller->selinux_context = NULL;
                 return TRUE;
         } else {
-                caller->selinux_context = p_strdup (selinux_context);
+                caller->selinux_context = kit_strdup (selinux_context);
                 if (caller->selinux_context == NULL)
                         return FALSE;
                 else
@@ -232,8 +231,8 @@ polkit_caller_set_selinux_context (PolKitCaller *caller, const char *selinux_con
 polkit_bool_t
 polkit_caller_set_ck_session (PolKitCaller *caller, PolKitSession *session)
 {
-        g_return_val_if_fail (caller != NULL, FALSE);
-        g_return_val_if_fail (session == NULL || polkit_session_validate (session), FALSE);
+        kit_return_val_if_fail (caller != NULL, FALSE);
+        kit_return_val_if_fail (session == NULL || polkit_session_validate (session), FALSE);
         if (caller->session != NULL)
                 polkit_session_unref (caller->session);
         caller->session = session != NULL ? polkit_session_ref (session) : NULL;
@@ -252,8 +251,8 @@ polkit_caller_set_ck_session (PolKitCaller *caller, PolKitSession *session)
 polkit_bool_t
 polkit_caller_get_dbus_name (PolKitCaller *caller, char **out_dbus_name)
 {
-        g_return_val_if_fail (caller != NULL, FALSE);
-        g_return_val_if_fail (out_dbus_name != NULL, FALSE);
+        kit_return_val_if_fail (caller != NULL, FALSE);
+        kit_return_val_if_fail (out_dbus_name != NULL, FALSE);
         *out_dbus_name = caller->dbus_name;
         return TRUE;
 }
@@ -270,8 +269,8 @@ polkit_caller_get_dbus_name (PolKitCaller *caller, char **out_dbus_name)
 polkit_bool_t
 polkit_caller_get_uid (PolKitCaller *caller, uid_t *out_uid)
 {
-        g_return_val_if_fail (caller != NULL, FALSE);
-        g_return_val_if_fail (out_uid != NULL, FALSE);
+        kit_return_val_if_fail (caller != NULL, FALSE);
+        kit_return_val_if_fail (out_uid != NULL, FALSE);
         *out_uid = caller->uid;
         return TRUE;
 }
@@ -288,8 +287,8 @@ polkit_caller_get_uid (PolKitCaller *caller, uid_t *out_uid)
 polkit_bool_t
 polkit_caller_get_pid (PolKitCaller *caller, pid_t *out_pid)
 {
-        g_return_val_if_fail (caller != NULL, FALSE);
-        g_return_val_if_fail (out_pid != NULL, FALSE);
+        kit_return_val_if_fail (caller != NULL, FALSE);
+        kit_return_val_if_fail (out_pid != NULL, FALSE);
         *out_pid = caller->pid;
         return TRUE;
 }
@@ -307,8 +306,8 @@ polkit_caller_get_pid (PolKitCaller *caller, pid_t *out_pid)
 polkit_bool_t
 polkit_caller_get_selinux_context (PolKitCaller *caller, char **out_selinux_context)
 {
-        g_return_val_if_fail (caller != NULL, FALSE);
-        g_return_val_if_fail (out_selinux_context != NULL, FALSE);
+        kit_return_val_if_fail (caller != NULL, FALSE);
+        kit_return_val_if_fail (out_selinux_context != NULL, FALSE);
         *out_selinux_context = caller->selinux_context;
         return TRUE;
 }
@@ -326,8 +325,8 @@ polkit_caller_get_selinux_context (PolKitCaller *caller, char **out_selinux_cont
 polkit_bool_t
 polkit_caller_get_ck_session (PolKitCaller *caller, PolKitSession **out_session)
 {
-        g_return_val_if_fail (caller != NULL, FALSE);
-        g_return_val_if_fail (out_session != NULL, FALSE);
+        kit_return_val_if_fail (caller != NULL, FALSE);
+        kit_return_val_if_fail (out_session != NULL, FALSE);
         *out_session = caller->session;
         return TRUE;
 }
@@ -341,7 +340,7 @@ polkit_caller_get_ck_session (PolKitCaller *caller, PolKitSession **out_session)
 void
 polkit_caller_debug (PolKitCaller *caller)
 {
-        g_return_if_fail (caller != NULL);
+        kit_return_if_fail (caller != NULL);
         _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)
@@ -360,8 +359,8 @@ polkit_caller_debug (PolKitCaller *caller)
 polkit_bool_t
 polkit_caller_validate (PolKitCaller *caller)
 {
-        g_return_val_if_fail (caller != NULL, FALSE);
-        g_return_val_if_fail (caller->pid > 0, FALSE);
+        kit_return_val_if_fail (caller != NULL, FALSE);
+        kit_return_val_if_fail (caller->pid > 0, FALSE);
         return TRUE;
 }
 
@@ -380,52 +379,52 @@ _run_test (void)
 
         if ((c = polkit_caller_new ()) != NULL) {
                 
-                g_assert (! polkit_caller_set_dbus_name (c, "org.invalid.name"));
-                g_assert (polkit_caller_set_dbus_name (c, NULL));
+                kit_assert (! polkit_caller_set_dbus_name (c, "org.invalid.name"));
+                kit_assert (polkit_caller_set_dbus_name (c, NULL));
                 if (polkit_caller_set_dbus_name (c, ":1.43")) {
-                        g_assert (polkit_caller_get_dbus_name (c, &s) && strcmp (s, ":1.43") == 0);
+                        kit_assert (polkit_caller_get_dbus_name (c, &s) && strcmp (s, ":1.43") == 0);
 
                         if (polkit_caller_set_dbus_name (c, ":1.44")) {
-                                g_assert (polkit_caller_get_dbus_name (c, &s) && strcmp (s, ":1.44") == 0);
+                                kit_assert (polkit_caller_get_dbus_name (c, &s) && strcmp (s, ":1.44") == 0);
                         }
                 }
 
-                g_assert (polkit_caller_set_selinux_context (c, NULL));
+                kit_assert (polkit_caller_set_selinux_context (c, NULL));
                 if (polkit_caller_set_selinux_context (c, "system_u:object_r:bin_t")) {
-                        g_assert (polkit_caller_get_selinux_context (c, &s) && strcmp (s, "system_u:object_r:bin_t") == 0);
+                        kit_assert (polkit_caller_get_selinux_context (c, &s) && strcmp (s, "system_u:object_r:bin_t") == 0);
 
                         if (polkit_caller_set_selinux_context (c, "system_u:object_r:httpd_exec_t")) {
-                                g_assert (polkit_caller_get_selinux_context (c, &s) && strcmp (s, "system_u:object_r:httpd_exec_t") == 0);
+                                kit_assert (polkit_caller_get_selinux_context (c, &s) && strcmp (s, "system_u:object_r:httpd_exec_t") == 0);
                         }
                 }
 
-                g_assert (polkit_caller_set_uid (c, 0));
-                g_assert (polkit_caller_get_uid (c, &uid) && uid == 0);
-                g_assert (polkit_caller_set_pid (c, 1));
-                g_assert (polkit_caller_get_pid (c, &pid) && pid == 1);
+                kit_assert (polkit_caller_set_uid (c, 0));
+                kit_assert (polkit_caller_get_uid (c, &uid) && uid == 0);
+                kit_assert (polkit_caller_set_pid (c, 1));
+                kit_assert (polkit_caller_get_pid (c, &pid) && pid == 1);
 
                 /* validate where caller is not in a session */
-                g_assert (polkit_caller_validate (c));
+                kit_assert (polkit_caller_validate (c));
                 polkit_caller_ref (c);
-                g_assert (polkit_caller_validate (c));
+                kit_assert (polkit_caller_validate (c));
                 polkit_caller_unref (c);
-                g_assert (polkit_caller_validate (c));
+                kit_assert (polkit_caller_validate (c));
 
                 if ((session = polkit_session_new ()) != NULL) {
                         if (polkit_session_set_ck_objref (session, "/somesession")) {
                                 if ((seat = polkit_seat_new ()) != NULL) {
                                         if (polkit_seat_set_ck_objref (seat, "/someseat")) {
-                                                g_assert (polkit_session_set_seat (session, seat));
-                                                g_assert (polkit_session_set_ck_is_local (session, TRUE));
+                                                kit_assert (polkit_session_set_seat (session, seat));
+                                                kit_assert (polkit_session_set_ck_is_local (session, TRUE));
 
-                                                g_assert (polkit_caller_set_ck_session (c, NULL));
-                                                g_assert (polkit_caller_get_ck_session (c, &session2) && session2 == NULL);
+                                                kit_assert (polkit_caller_set_ck_session (c, NULL));
+                                                kit_assert (polkit_caller_get_ck_session (c, &session2) && session2 == NULL);
 
-                                                g_assert (polkit_caller_set_ck_session (c, session));
-                                                g_assert (polkit_caller_set_ck_session (c, session));
-                                                g_assert (polkit_caller_get_ck_session (c, &session2) && session2 == session);
+                                                kit_assert (polkit_caller_set_ck_session (c, session));
+                                                kit_assert (polkit_caller_set_ck_session (c, session));
+                                                kit_assert (polkit_caller_get_ck_session (c, &session2) && session2 == session);
                                                 /* validate where caller is in a session */
-                                                g_assert (polkit_caller_validate (c));
+                                                kit_assert (polkit_caller_validate (c));
 
                                                 polkit_caller_debug (c);
 
diff --git a/src/polkit/polkit-config.c b/src/polkit/polkit-config.c
index ff3c15e..eaff178 100644
--- a/src/polkit/polkit-config.c
+++ b/src/polkit/polkit-config.c
@@ -46,6 +46,7 @@
 #include "polkit-config.h"
 #include "polkit-debug.h"
 #include "polkit-error.h"
+#include "polkit-private.h"
 
 /**
  * SECTION:polkit-config
@@ -496,7 +497,7 @@ error:
 PolKitConfig *
 polkit_config_ref (PolKitConfig *pk_config)
 {
-        g_return_val_if_fail (pk_config != NULL, pk_config);
+        kit_return_val_if_fail (pk_config != NULL, pk_config);
         pk_config->refcount++;
         return pk_config;
 }
@@ -512,7 +513,7 @@ polkit_config_ref (PolKitConfig *pk_config)
 void
 polkit_config_unref (PolKitConfig *pk_config)
 {
-        g_return_if_fail (pk_config != NULL);
+        kit_return_if_fail (pk_config != NULL);
         pk_config->refcount--;
         if (pk_config->refcount > 0) 
                 return;
diff --git a/src/polkit/polkit-context.c b/src/polkit/polkit-context.c
index 1f25d58..e2559ff 100644
--- a/src/polkit/polkit-context.c
+++ b/src/polkit/polkit-context.c
@@ -140,7 +140,7 @@ polkit_context_new (void)
 polkit_bool_t
 polkit_context_init (PolKitContext *pk_context, PolKitError **error)
 {
-        g_return_val_if_fail (pk_context != NULL, FALSE);
+        kit_return_val_if_fail (pk_context != NULL, FALSE);
 
         pk_context->policy_dir = g_strdup (PACKAGE_DATA_DIR "/PolicyKit/policy");
         _pk_debug ("Using policy files from directory %s", pk_context->policy_dir);
@@ -216,7 +216,7 @@ error:
 PolKitContext *
 polkit_context_ref (PolKitContext *pk_context)
 {
-        g_return_val_if_fail (pk_context != NULL, pk_context);
+        kit_return_val_if_fail (pk_context != NULL, pk_context);
         pk_context->refcount++;
         return pk_context;
 }
@@ -233,7 +233,7 @@ void
 polkit_context_unref (PolKitContext *pk_context)
 {
 
-        g_return_if_fail (pk_context != NULL);
+        kit_return_if_fail (pk_context != NULL);
         pk_context->refcount--;
         if (pk_context->refcount > 0) 
                 return;
@@ -267,7 +267,7 @@ polkit_context_set_config_changed (PolKitContext                *pk_context,
                                    PolKitContextConfigChangedCB  cb, 
                                    void                         *user_data)
 {
-        g_return_if_fail (pk_context != NULL);
+        kit_return_if_fail (pk_context != NULL);
         pk_context->config_changed_cb = cb;
         pk_context->config_changed_user_data = user_data;
 }
@@ -286,7 +286,7 @@ polkit_context_io_func (PolKitContext *pk_context, int fd)
 {
         gboolean config_changed;
 
-        g_return_if_fail (pk_context != NULL);
+        kit_return_if_fail (pk_context != NULL);
 
         _pk_debug ("polkit_context_io_func: data on fd %d", fd);
 
@@ -364,7 +364,7 @@ polkit_context_set_io_watch_functions (PolKitContext                        *pk_
                                        PolKitContextAddIOWatch               io_add_watch_func,
                                        PolKitContextRemoveIOWatch            io_remove_watch_func)
 {
-        g_return_if_fail (pk_context != NULL);
+        kit_return_if_fail (pk_context != NULL);
         pk_context->io_add_watch_func = io_add_watch_func;
         pk_context->io_remove_watch_func = io_remove_watch_func;
 }
@@ -382,7 +382,7 @@ polkit_context_set_io_watch_functions (PolKitContext                        *pk_
 void
 polkit_context_set_load_descriptions  (PolKitContext *pk_context)
 {
-        g_return_if_fail (pk_context != NULL);
+        kit_return_if_fail (pk_context != NULL);
         pk_context->load_descriptions = TRUE;
 }
 
@@ -397,7 +397,7 @@ polkit_context_set_load_descriptions  (PolKitContext *pk_context)
 PolKitPolicyCache *
 polkit_context_get_policy_cache (PolKitContext *pk_context)
 {
-        g_return_val_if_fail (pk_context != NULL, NULL);
+        kit_return_val_if_fail (pk_context != NULL, NULL);
 
         if (pk_context->priv_cache == NULL) {
                 PolKitError *error;
@@ -452,7 +452,7 @@ polkit_context_is_session_authorized (PolKitContext         *pk_context,
         PolKitConfig *config;
 
         result = POLKIT_RESULT_NO;
-        g_return_val_if_fail (pk_context != NULL, result);
+        kit_return_val_if_fail (pk_context != NULL, result);
 
         config = polkit_context_get_config (pk_context, NULL);
         /* if the configuration file is malformed, always say no */
@@ -602,7 +602,7 @@ polkit_context_is_caller_authorized (PolKitContext         *pk_context,
         polkit_bool_t from_authdb;
 
         result = POLKIT_RESULT_NO;
-        g_return_val_if_fail (pk_context != NULL, result);
+        kit_return_val_if_fail (pk_context != NULL, result);
 
         /* if the configuration file is malformed, always say no */
         config = polkit_context_get_config (pk_context, NULL);
diff --git a/src/polkit/polkit-error.c b/src/polkit/polkit-error.c
index af016ad..aa886cb 100644
--- a/src/polkit/polkit-error.c
+++ b/src/polkit/polkit-error.c
@@ -44,13 +44,11 @@
 #include <unistd.h>
 #include <errno.h>
 
-#include <glib.h>
-
 #include "polkit-types.h"
 #include "polkit-error.h"
 #include "polkit-debug.h"
 #include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
 
 /**
  * PolKitError:
@@ -105,8 +103,8 @@ static const char *error_names[POLKIT_ERROR_NUM_ERROR_CODES] = {
 const char *
 polkit_error_get_error_name (PolKitError *error)
 {
-        g_return_val_if_fail (error != NULL, NULL);
-        g_return_val_if_fail (error->error_code >= 0 && error->error_code < POLKIT_ERROR_NUM_ERROR_CODES, NULL);
+        kit_return_val_if_fail (error != NULL, NULL);
+        kit_return_val_if_fail (error->error_code >= 0 && error->error_code < POLKIT_ERROR_NUM_ERROR_CODES, NULL);
 
         return error_names[error->error_code];
 }
@@ -122,7 +120,7 @@ polkit_error_get_error_name (PolKitError *error)
 PolKitErrorCode 
 polkit_error_get_error_code (PolKitError *error)
 {
-        g_return_val_if_fail (error != NULL, -1);
+        kit_return_val_if_fail (error != NULL, -1);
         return error->error_code;
 }
 
@@ -137,7 +135,7 @@ polkit_error_get_error_code (PolKitError *error)
 const char *
 polkit_error_get_error_message (PolKitError *error)
 {
-        g_return_val_if_fail (error != NULL, NULL);
+        kit_return_val_if_fail (error != NULL, NULL);
         return error->error_message;
 }
 
@@ -150,10 +148,10 @@ polkit_error_get_error_message (PolKitError *error)
 void
 polkit_error_free (PolKitError *error)
 {
-        g_return_if_fail (error != NULL);
+        kit_return_if_fail (error != NULL);
         if (!error->is_static) {
-                p_free (error->error_message);
-                p_free (error);
+                kit_free (error->error_message);
+                kit_free (error);
         }
 }
 
@@ -177,23 +175,23 @@ polkit_error_set_error (PolKitError **error, PolKitErrorCode error_code, const c
         va_list args;
         PolKitError *e;
 
-        g_return_val_if_fail (format != NULL, FALSE);
-        g_return_val_if_fail (error_code >= 0 && error_code < POLKIT_ERROR_NUM_ERROR_CODES, FALSE);
+        kit_return_val_if_fail (format != NULL, FALSE);
+        kit_return_val_if_fail (error_code >= 0 && error_code < POLKIT_ERROR_NUM_ERROR_CODES, FALSE);
 
         if (error == NULL)
                 goto out;
 
-        e = p_new0 (PolKitError, 1);
+        e = kit_new0 (PolKitError, 1);
         if (e == NULL) {
                 *error = &_oom_error;
         } else {
                 e->is_static = FALSE;
                 e->error_code = error_code;
                 va_start (args, format);
-                e->error_message = p_strdup_vprintf (format, args);
+                e->error_message = kit_strdup_vprintf (format, args);
                 va_end (args);
                 if (e->error_message == NULL) {
-                        p_free (e);
+                        kit_free (e);
                         *error = &_oom_error;
                 } else {                
                         *error = e;
@@ -214,25 +212,25 @@ _run_test (void)
         char s[256];
 
         e = NULL;
-        g_assert (! polkit_error_is_set (e));
-        g_assert (! polkit_error_set_error (&e, -1, "Testing"));
-        g_assert (! polkit_error_set_error (&e, POLKIT_ERROR_NUM_ERROR_CODES, "Testing"));
+        kit_assert (! polkit_error_is_set (e));
+        kit_assert (! polkit_error_set_error (&e, -1, "Testing"));
+        kit_assert (! polkit_error_set_error (&e, POLKIT_ERROR_NUM_ERROR_CODES, "Testing"));
 
         for (n = 0; n < POLKIT_ERROR_NUM_ERROR_CODES; n++) {
                 polkit_error_set_error (&e, n, "Testing error code %d", n);
-                g_assert (polkit_error_is_set (e));
-                g_assert (polkit_error_get_error_code (e) == n || polkit_error_get_error_code (e) == POLKIT_ERROR_OUT_OF_MEMORY);
-                g_assert (strcmp (polkit_error_get_error_name (e), error_names[polkit_error_get_error_code (e)]) == 0);
+                kit_assert (polkit_error_is_set (e));
+                kit_assert (polkit_error_get_error_code (e) == n || polkit_error_get_error_code (e) == POLKIT_ERROR_OUT_OF_MEMORY);
+                kit_assert (strcmp (polkit_error_get_error_name (e), error_names[polkit_error_get_error_code (e)]) == 0);
 
                 if (polkit_error_get_error_code (e) != POLKIT_ERROR_OUT_OF_MEMORY) {
                         snprintf (s, sizeof (s), "Testing error code %d", n);
-                        g_assert (strcmp (polkit_error_get_error_message (e), s) == 0);
+                        kit_assert (strcmp (polkit_error_get_error_message (e), s) == 0);
                 }
 
                 polkit_error_free (e);
         }
 
-        g_assert (polkit_error_set_error (NULL, POLKIT_ERROR_OUT_OF_MEMORY, "This error will never get set"));
+        kit_assert (polkit_error_set_error (NULL, POLKIT_ERROR_OUT_OF_MEMORY, "This error will never get set"));
 
         return TRUE;
 }
diff --git a/src/polkit/polkit-hash.c b/src/polkit/polkit-hash.c
deleted file mode 100644
index ef2797d..0000000
--- a/src/polkit/polkit-hash.c
+++ /dev/null
@@ -1,560 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-/***************************************************************************
- *
- * polkit-hash.c : Hash tables
- *
- * Copyright (C) 2007 David Zeuthen, <david at 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
- *
- **************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <glib.h>
-#include <polkit/polkit-hash.h>
-#include <polkit/polkit-memory.h>
-#include <polkit/polkit-test.h>
-
-/**
- * SECTION:polkit-hash
- * @title: Hash Tables
- * @short_description: Hash Tables
- *
- * This class provides support for hash tables.
- *
- * Since: 0.7
- **/
-
-struct _PolKitHashNode;
-
-typedef struct _PolKitHashNode {
-        void *key;
-        void *value;
-        struct _PolKitHashNode *next;
-} PolKitHashNode;
-
-
-/**
- * PolKitHash:
- *
- * The #PolKitHash structure not be accessed directly.
- *
- * Since: 0.7
- */
-struct _PolKitHash
-{
-        int refcount;
-
-        int num_top_nodes;
-        PolKitHashNode **top_nodes;
-
-        PolKitHashFunc  hash_func;
-        PolKitEqualFunc key_equal_func;
-        PolKitCopyFunc  key_copy_func;
-        PolKitCopyFunc  value_copy_func;
-        PolKitFreeFunc  key_destroy_func;
-        PolKitFreeFunc  value_destroy_func;
-};
-
-/**
- * polkit_hash_new:
- * @hash_func: The hash function to use
- * @key_equal_func: The function used to determine key equality
- * @key_copy_func: Function for copying keys or #NULL
- * @value_copy_func: Function for copying values or #NULL
- * @key_destroy_func: Function for freeing keys or #NULL
- * @value_destroy_func: Function for freeing values or #NULL
- *
- * Creates a new Hash Table.
- *
- * Returns: The new hash table. Returns #NULL on OOM.
- *
- * Since: 0.7
- */
-PolKitHash *
-polkit_hash_new (PolKitHashFunc  hash_func,
-                 PolKitEqualFunc key_equal_func,
-                 PolKitCopyFunc  key_copy_func,
-                 PolKitCopyFunc  value_copy_func,
-                 PolKitFreeFunc  key_destroy_func,
-                 PolKitFreeFunc  value_destroy_func)
-{
-        PolKitHash *h;
-
-        g_return_val_if_fail (hash_func != NULL, NULL);
-        g_return_val_if_fail (key_equal_func != NULL, NULL);
-
-        h = p_new0 (PolKitHash, 1);
-        if (h == NULL)
-                goto error;
-
-        h->refcount = 1;
-        h->hash_func = hash_func;
-        h->key_copy_func = key_copy_func;
-        h->value_copy_func = value_copy_func;
-        h->key_equal_func = key_equal_func;
-        h->key_destroy_func = key_destroy_func;
-        h->value_destroy_func = value_destroy_func;
-
-        h->num_top_nodes = 11; /* TODO: configurable? */
-        h->top_nodes = p_new0 (PolKitHashNode*, h->num_top_nodes);
-        if (h->top_nodes == NULL)
-                goto error;
-
-        return h;
-error:
-        if (h != NULL)
-                polkit_hash_unref (h);
-        return NULL;
-}
-
-/**
- * polkit_hash_ref:
- * @hash: the hash table
- *
- * Increase reference count.
- *
- * Returns: the hash table
- *
- * Since: 0.7
- */
-PolKitHash *
-polkit_hash_ref (PolKitHash *hash)
-{
-        g_return_val_if_fail (hash != NULL, hash);
-        hash->refcount++;
-        return hash;
-}
-
-/**
- * polkit_hash_unref:
- * @hash: the hash table
- *
- * Decrease reference count. If reference count drop to zero the hash
- * table is freed.
- *
- * Since: 0.7
- */
-void
-polkit_hash_unref (PolKitHash *hash)
-{
-        g_return_if_fail (hash != NULL);
-
-        hash->refcount--;
-        if (hash->refcount > 0) 
-                return;
-
-        if (hash->top_nodes != NULL) {
-                int n;
-
-                for (n = 0; n < hash->num_top_nodes; n++) {
-                        PolKitHashNode *node;
-                        PolKitHashNode *next;
-                        
-                        for (node = hash->top_nodes[n]; node != NULL; node = next) {
-                                if (hash->key_destroy_func != NULL)
-                                        hash->key_destroy_func (node->key);
-                                if (hash->value_destroy_func != NULL)
-                                        hash->value_destroy_func (node->value);
-                                next = node->next;
-                                p_free (node);
-                        }
-                }
-        }
-
-        p_free (hash->top_nodes);
-        p_free (hash);
-}
-
-/**
- * polkit_hash_insert:
- * @hash: the hash table
- * @key: key to insert
- * @value: value to insert
- *
- * Inserts a new key and value into a hash table. If the key already
- * exists in the hash table it's current value is replaced with the
- * new value.
- *
- * Returns: #TRUE unless OOM
- *
- * Since: 0.7
- */
-polkit_bool_t 
-polkit_hash_insert (PolKitHash *hash,
-                    void *key,
-                    void *value)
-{
-        int bucket;
-        PolKitHashNode **nodep;
-        PolKitHashNode *node;
-        void *key_copy;
-        void *value_copy;
-
-        g_return_val_if_fail (hash != NULL, FALSE);
-        g_return_val_if_fail (key != NULL, FALSE);
-
-        key_copy = NULL;
-        value_copy = NULL;
-        if (hash->key_copy_func != NULL) {
-                key_copy = hash->key_copy_func (key);
-                if (key_copy == NULL) {
-                        goto oom;
-                }
-        } else {
-                key_copy = key;
-        }
-        if (hash->value_copy_func != NULL) {
-                value_copy = hash->value_copy_func (value);
-                if (value_copy == NULL) {
-                        goto oom;
-                }
-        } else {
-                value_copy = value;
-        }
-
-        bucket = hash->hash_func (key) % hash->num_top_nodes;
-
-        nodep = & (hash->top_nodes [bucket]);
-        node = hash->top_nodes [bucket];
-        while (node != NULL) {
-                nodep = &(node->next);
-
-                if (hash->key_equal_func (key, node->key)) {
-                        /* replace the value */
-
-                        if (hash->key_destroy_func != NULL)
-                                hash->key_destroy_func (node->key);
-                        if (hash->value_destroy_func != NULL)
-                                hash->value_destroy_func (node->value);
-
-                        node->key = key_copy;
-                        node->value = value_copy;
-
-                        goto out;
-                } else {
-                        node = node->next;
-                }
-        }
-
-        node = p_new0 (PolKitHashNode, 1);
-        if (node == NULL)
-                goto oom;
-
-        node->key = key_copy;
-        node->value = value_copy;
-        *nodep = node;
-
-out:
-        return TRUE;
-
-oom:
-        if (key_copy != NULL && hash->key_copy_func != NULL && hash->key_destroy_func != NULL)
-                hash->key_destroy_func (key_copy);
-
-        if (value_copy != NULL && hash->value_copy_func != NULL && hash->value_destroy_func != NULL)
-                hash->value_destroy_func (value_copy);
-
-        return FALSE;
-}
-
-/**
- * polkit_hash_lookup:
- * @hash: the hash table
- * @key: key to look up
- * @found: if not #NULL, will return #TRUE only if the key was found in the hash table
- *
- * Look up a value in the hash table.
- *
- * Returns: the value; caller shall not free/unref this value
- *
- * Since: 0.7
- */
-void *
-polkit_hash_lookup (PolKitHash *hash, void *key, polkit_bool_t *found)
-{
-        int bucket;
-        void *value;
-        PolKitHashNode *node;
-
-        value = NULL;
-        if (found != NULL)
-                *found = FALSE;
-
-        g_return_val_if_fail (hash != NULL, NULL);
-        g_return_val_if_fail (key != NULL, NULL);
-
-        bucket = hash->hash_func (key) % hash->num_top_nodes;
-
-        node = hash->top_nodes [bucket];
-        while (node != NULL) {
-                if (hash->key_equal_func (key, node->key)) {
-                        /* got it */
-
-                        value = node->value;
-                        if (found != NULL)
-                                *found = TRUE;
-                        goto out;
-                } else {
-                        node = node->next;
-                }
-        }
-
-out:
-        return value;
-}
-
-
-/**
- * polkit_hash_foreach:
- * @hash: the hash table
- * @cb: callback function
- * @user_data: user data
- *
- * Iterate over all elements in a hash table
- *
- * Returns: #TRUE only if the callback short-circuited the iteration
- *
- * Since: 0.7
- */
-polkit_bool_t
-polkit_hash_foreach (PolKitHash *hash, PolKitHashForeachFunc cb, void *user_data)
-{
-        int n;
-
-        g_return_val_if_fail (hash != NULL, FALSE);
-        g_return_val_if_fail (cb != NULL, FALSE);
-
-        for (n = 0; n < hash->num_top_nodes; n++) {
-                PolKitHashNode *node;
-
-                for (node = hash->top_nodes[n]; node != NULL; node = node->next) {
-                        if (cb (hash, node->key, node->value, user_data))
-                                return TRUE;
-                }
-        }
-
-        return FALSE;
-}
-
-
-/**
- * polkit_hash_direct_hash_func:
- * @key: the key
- *
- * Converts a pointer to a hash value.
- *
- * Returns: a hash value corresponding to the key
- *
- * Since: 0.7
- */
-polkit_uint32_t 
-polkit_hash_direct_hash_func (const void *key)
-{
-        /* TODO: reimplement */
-        return g_direct_hash (key);
-}
-
-/**
- * polkit_hash_direct_equal_func:
- * @v1: first value
- * @v2: second value
- *
- * Compares two pointers and return #TRUE if they are equal (same address).
- *
- * Returns: #TRUE only if the values are equal
- *
- * Since: 0.7
- */
-polkit_bool_t
-polkit_hash_direct_equal_func (const void *v1, const void *v2)
-{
-        /* TODO: reimplement */
-        return g_direct_equal (v1, v2);
-}
-
-/**
- * polkit_hash_str_hash_func:
- * @key: the key
- *
- * Converts a string to a hash value.
- *
- * Returns: a hash value corresponding to the key
- *
- * Since: 0.7
- */
-polkit_uint32_t
-polkit_hash_str_hash_func (const void *key)
-{
-        const char *p;
-        polkit_uint32_t hash;
-
-        hash = 0;
-        for (p = key; *p != '\0'; p++)
-                hash = hash * 617 ^ *p;
-
-        return hash;
-}
-
-/**
- * polkit_hash_str_equal_func:
- * @v1: first value
- * @v2: second value
- *
- * Compares two strings and return #TRUE if they are equal.
- *
- * Returns: #TRUE only if the values are equal
- *
- * Since: 0.7
- */
-polkit_bool_t
-polkit_hash_str_equal_func (const void *v1, const void *v2)
-{
-        return strcmp (v1, v2) == 0;
-}
-
-/**
- * polkit_hash_str_copy:
- * @p: void pointer to string
- *
- * Similar to p_strdup() except for types.
- *
- * Returns: a void pointer to a copy or #NULL on OOM
- */
-void *
-polkit_hash_str_copy (const void *p)
-{
-        return (void *) p_strdup ((const char *) p);
-}
-
-#ifdef POLKIT_BUILD_TESTS
-
-static polkit_bool_t
-_it1 (PolKitHash *hash, void *key, void *value, void *user_data)
-{
-        int *count = (int *) user_data;
-        *count += 1;
-        return FALSE;
-}
-
-static polkit_bool_t
-_it2 (PolKitHash *hash, void *key, void *value, void *user_data)
-{
-        int *count = (int *) user_data;
-        *count += 1;
-        return TRUE;
-}
-
-static polkit_bool_t
-_run_test (void)
-{
-        int count;
-        PolKitHash *h;
-        polkit_bool_t found;
-
-        /* string hash tables */
-        if ((h = polkit_hash_new (polkit_hash_str_hash_func, polkit_hash_str_equal_func, 
-                                  polkit_hash_str_copy, polkit_hash_str_copy,
-                                  p_free, p_free)) != NULL) {
-                int n;
-                char *key;
-                char *value;
-                char *test_data[] = {"key1", "val1",
-                                     "key2", "val2",
-                                     "key3", "val3",
-                                     "key4", "val4",
-                                     "key5", "val5",
-                                     "key6", "val6",
-                                     "key7", "val7",
-                                     "key8", "val8",
-                                     "key9", "val9",
-                                     "key10", "val10",
-                                     "key11", "val11",
-                                     "key12", "val12",
-                                     NULL};
-
-                /* first insert the values */
-                for (n = 0; test_data [n*2] != NULL; n++) {
-                        if (!polkit_hash_insert (h, test_data [n*2], test_data [n*2 + 1])) {
-                                goto oom;
-                        }
-                }
-
-                /* then check that we can look them up */
-                for (n = 0; test_data [n*2] != NULL; n++) {
-                        key = test_data [n*2];
-                        value = polkit_hash_lookup (h, test_data[n*2], &found);
-
-                        g_assert (found && strcmp (value, test_data[n*2 + 1]) == 0);
-                }
-
-                /* lookup unknown key */
-                g_assert (polkit_hash_lookup (h, "unknown", &found) == NULL && !found);
-
-                /* replace key */
-                if (key != NULL) {
-                        if (polkit_hash_insert (h, "key1", "val1-replaced")) {
-                                /* check for replaced value */
-                                value = polkit_hash_lookup (h, "key1", &found);
-                                g_assert (found && value != NULL && strcmp (value, "val1-replaced") == 0);
-                        }
-                }
-
-                count = 0;
-                g_assert (polkit_hash_foreach (h, _it1, &count) == FALSE);
-                g_assert (count == ((sizeof (test_data) / sizeof (char *) - 1) / 2));
-                count = 0;
-                g_assert (polkit_hash_foreach (h, _it2, &count) == TRUE);
-                g_assert (count == 1);
-                
-                polkit_hash_ref (h);
-                polkit_hash_unref (h);
-        oom:
-
-                polkit_hash_unref (h);
-        }
-
-        /* direct hash tables */
-        if ((h = polkit_hash_new (polkit_hash_direct_hash_func, polkit_hash_direct_equal_func, 
-                                  NULL, NULL, 
-                                  NULL, NULL)) != NULL) {
-                if (polkit_hash_insert (h, h, h)) {
-                        g_assert ((polkit_hash_lookup (h, h, &found) == h) && found);
-                        if (polkit_hash_insert (h, h, NULL)) {
-                                g_assert (polkit_hash_lookup (h, h, &found) == NULL && found);
-                        }
-                }
-                polkit_hash_unref (h);
-        }
-
-        return TRUE;
-}
-
-PolKitTest _test_hash = {
-        "polkit_hash",
-        NULL,
-        NULL,
-        _run_test
-};
-
-#endif /* POLKIT_BUILD_TESTS */
diff --git a/src/polkit/polkit-hash.h b/src/polkit/polkit-hash.h
deleted file mode 100644
index 0c3428f..0000000
--- a/src/polkit/polkit-hash.h
+++ /dev/null
@@ -1,147 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-/***************************************************************************
- *
- * polkit-hash.h : Hash tables
- *
- * Copyright (C) 2007 David Zeuthen, <david at 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
- *
- **************************************************************************/
-
-#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_HASH_H
-#define POLKIT_HASH_H
-
-#include <polkit/polkit-types.h>
-
-POLKIT_BEGIN_DECLS
-
-struct _PolKitHash;
-typedef struct _PolKitHash PolKitHash;
-
-/**
- * PolKitHashFunc:
- * @key: a key
- *
- * The function is passed a key and should return a hash value. The
- * functions polkit_hash_direct_hash_func() and
- * polkit_hash_str_hash_func() provide hash functions which can be
- * used when the key is a pointer and an char* respectively.
- *
- * Returns: the hash value corresponding to the key
- *
- * Since: 0.7
- */
-typedef polkit_uint32_t (*PolKitHashFunc) (const void *key);
-
-/**
- * PolKitEqualFunc:
- * @key1: first key
- * @key2: second key
- *
- * Determines if two keys are equal. The functions
- * polkit_hash_direct_equal_func() and polkit_hash_str_equal_func()
- * provide equality functions which can be used when the key is a
- * pointer and an char* respectively.
- *
- * Returns: #TRUE iff the keys are equal
- *
- * Since: 0.7
- */
-typedef polkit_bool_t (*PolKitEqualFunc) (const void *key1, const void *key2);
-
-/**
- * PolKitFreeFunc:
- * @p: pointer
- *
- * Specifies the type of function which is called when a data element
- * is destroyed. It is passed the pointer to the data element and
- * should free any memory and resources allocated for it. The function
- * p_free() or any of the object unref functions can be passed here.
- *
- * Since: 0.7
- */
-typedef void (*PolKitFreeFunc) (void *p);
-
-/**
- * PolKitCopyFunc:
- * @p: pointer
- *
- * Specifies the type of function which is called when a data element
- * is to be cloned or reffed. It is passed the pointer to the data
- * element and should return a new pointer to a reffed or cloned
- * object. The function polkit_hash_str_copy() or any of the object
- * ref functions can be passed here.
- *
- * Returns: A copy or ref of the object in question
- *
- * Since: 0.7
- */
-typedef void *(*PolKitCopyFunc) (const void *p);
-
-/**
- * PolKitHashForeachFunc:
- * @hash: the hash table
- * @key: key
- * @value: value
- * @user_data: user data passed to polkit_hash_foreach()
- *
- * Type signature for callback function used in polkit_hash_foreach().
- *
- * Returns: Return #TRUE to short-circuit, e.g. stop the iteration.
- *
- * Since: 0.7
- */
-typedef polkit_bool_t (*PolKitHashForeachFunc) (PolKitHash *hash,
-                                                void *key,
-                                                void *value,
-                                                void *user_data);
-
-
-PolKitHash *polkit_hash_new (PolKitHashFunc  hash_func,
-                             PolKitEqualFunc key_equal_func,
-                             PolKitCopyFunc  key_copy_func,
-                             PolKitCopyFunc  value_copy_func,
-                             PolKitFreeFunc  key_destroy_func,
-                             PolKitFreeFunc  value_destroy_func);
-
-PolKitHash    *polkit_hash_ref   (PolKitHash *hash);
-void           polkit_hash_unref (PolKitHash *hash);
-
-polkit_bool_t  polkit_hash_insert (PolKitHash *hash, void *key, void *value);
-
-void          *polkit_hash_lookup (PolKitHash *hash, void *key, polkit_bool_t *found);
-
-polkit_bool_t  polkit_hash_foreach (PolKitHash *hash, PolKitHashForeachFunc cb, void *user_data);
-
-
-polkit_uint32_t polkit_hash_direct_hash_func  (const void *key);
-polkit_bool_t   polkit_hash_direct_equal_func (const void *v1, const void *v2);
-
-polkit_uint32_t polkit_hash_str_hash_func     (const void *key);
-polkit_bool_t   polkit_hash_str_equal_func    (const void *v1, const void *v2);
-void           *polkit_hash_str_copy          (const void *p);
-
-POLKIT_END_DECLS
-
-#endif /* POLKIT_HASH_H */
-
-
diff --git a/src/polkit/polkit-list.c b/src/polkit/polkit-list.c
deleted file mode 100644
index 72f6642..0000000
--- a/src/polkit/polkit-list.c
+++ /dev/null
@@ -1,330 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-/***************************************************************************
- *
- * polkit-list.c : Doubly-linked lists
- *
- * Copyright (C) 2007 David Zeuthen, <david at 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
- *
- **************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <glib.h>
-#include <polkit/polkit-list.h>
-#include <polkit/polkit-memory.h>
-#include <polkit/polkit-test.h>
-
-/**
- * SECTION:polkit-list
- * @title: Doubly-linked lists
- * @short_description: Doubly-linked lists
- *
- * This class provides support for doubly-linked lists.
- *
- * Since: 0.7
- **/
-
-/**
- * polkit_list_append:
- * @list: existing list or #NULL to create a new list
- * @data: data to append to the list
- *
- * Append an entry to a list.
- *
- * Returns: the head of the new list or #NULL on OOM
- *
- * Since: 0.7
- */
-PolKitList *
-polkit_list_append (PolKitList *list, void *data)
-{
-        PolKitList *l;
-        PolKitList *j;
-        
-        for (j = list; j != NULL && j->next != NULL; j = j->next)
-                ;
-        
-        l = p_new0 (PolKitList, 1);
-        if (l == NULL)
-                goto oom;
-
-        l->data = data;
-        l->prev = j;
-        
-        if (j != NULL) {
-                j->next = l;
-        } else {
-                list = l;
-        }
-
-        return list;
-oom:
-        return NULL;
-}
-
-/**
- * polkit_list_prepend:
- * @list: existing list or #NULL to create a new list
- * @data: data to prepend to the list
- *
- * Prepend an entry to a list.
- *
- * Returns: the head of the new list or #NULL on OOM
- *
- * Since: 0.7
- */
-PolKitList *
-polkit_list_prepend (PolKitList *list, void *data)
-{
-        PolKitList *l;
-
-        l = p_new0 (PolKitList, 1);
-        if (l == NULL)
-                goto oom;
-
-        l->next = list;
-        l->data = data;
-        if (list != NULL) {
-                list->prev = l;
-        }
-
-oom:
-        return l;
-}
-
-/**
- * polkit_list_delete_link:
- * @list: existing list, cannot be #NULL
- * @link: link to delete, cannot be #NULL
- *
- * Delete a link from a list.
- *
- * Returns: the new head of the list or #NULL if the list is empty after deletion.
- *
- * Since: 0.7
- */
-PolKitList *
-polkit_list_delete_link (PolKitList *list, PolKitList *link)
-{
-        PolKitList *ret;
-
-        g_return_val_if_fail (list != NULL, NULL);
-        g_return_val_if_fail (link != NULL, NULL);
-
-        if (list == link)
-                ret = link->next;
-        else
-                ret = list;
-
-        if (link->prev != NULL) {
-                link->prev->next = link->next;
-        }
-
-        if (link->next != NULL) {
-                link->next->prev = link->prev;
-        }
-
-        p_free (link);
-
-        return ret;
-}
-
-/**
- * polkit_list_free:
- * @list: the list
- *
- * Frees all links in a list
- *
- * Since: 0.7
- */
-void
-polkit_list_free (PolKitList *list)
-{
-        PolKitList *l;
-        PolKitList *j;
-
-        for (l = list; l != NULL; l = j) {
-                j = l->next;
-                p_free (l);
-        }
-}
-
-/**
- * polkit_list_length:
- * @list: the list
- *
- * Compute the length of a list.
- *
- * Returns: Number of entries in list
- *
- * Since: 0.7
- */
-size_t
-polkit_list_length (PolKitList *list)
-{
-        ssize_t n;
-        PolKitList *l;
-
-        n = 0;
-        for (l = list; l != NULL; l = l->next)
-                n++;
-
-        return n;
-}
-
-/**
- * polkit_list_foreach:
- * @list: the list
- * @func: callback function
- * @user_data: user data to pass to callback
- *
- * Iterate over all entries in a list.
- *
- * Returns: #TRUE only if the callback short-circuited the iteration
- *
- * Since: 0.7
- */
-polkit_bool_t 
-polkit_list_foreach (PolKitList *list, PolKitListForeachFunc func, void *user_data)
-{
-        PolKitList *l;
-
-        g_return_val_if_fail (list != NULL, FALSE);
-        g_return_val_if_fail (func != NULL, FALSE);
-
-        for (l = list; l != NULL; l = l->next) {
-                if (func (list, l->data, user_data))
-                        return TRUE;
-        }
-        
-        return FALSE;
-}
-
-
-#ifdef POLKIT_BUILD_TESTS
-
-typedef struct {
-        int num;
-        int result;
-} _Closure;
-
-static polkit_bool_t 
-_sum (PolKitList *list, void *data, void *user_data)
-{
-        _Closure *c = (_Closure*) user_data;
-
-        c->result += ((int) data) * (c->num + 1);
-        c->num += 1;
-
-        return FALSE;
-}
-
-static polkit_bool_t 
-_sum2 (PolKitList *list, void *data, void *user_data)
-{
-        _Closure *c = (_Closure*) user_data;
-
-        if (c->num == 2)
-                return TRUE;
-
-        c->result += ((int) data) * (c->num + 1);
-        c->num += 1;
-
-        return FALSE;
-}
-
-static polkit_bool_t
-_run_test (void)
-{
-        _Closure c;
-        int items[] = {1, 2, 3, 4, 5};
-        unsigned int num_items = sizeof (items) / sizeof (int);
-        unsigned int n;
-        PolKitList *l;
-        PolKitList *j;
-
-        l = NULL;
-        for (n = 0; n < num_items; n++) {
-                j = l;
-                l = polkit_list_prepend (l, (void *) items[n]);
-                if (l == NULL)
-                        goto oom;
-        }
-
-        g_assert (polkit_list_length (l) == num_items);
-        c.num = 0;
-        c.result = 0;
-        polkit_list_foreach (l, _sum, &c);
-        g_assert (c.result == 1*5 + 2*4 + 3*3 + 4*2 + 5*1);
-
-        c.num = 0;
-        c.result = 0;
-        polkit_list_foreach (l, _sum2, &c);
-        g_assert (c.result == 1*5 + 2*4);
-
-        l = polkit_list_delete_link (l, l);
-        g_assert (polkit_list_length (l) == num_items - 1);
-        c.num = 0;
-        c.result = 0;
-        polkit_list_foreach (l, _sum, &c);
-        g_assert (c.result == 1*4 + 2*3 + 3*2 + 4*1);
-
-        l = polkit_list_delete_link (l, l->next);
-        g_assert (polkit_list_length (l) == num_items - 2);
-        c.num = 0;
-        c.result = 0;
-        polkit_list_foreach (l, _sum, &c);
-        g_assert (c.result == 1*4 + 2*2 + 3*1);
-
-        polkit_list_free (l);
-
-        l = NULL;
-        for (n = 0; n < num_items; n++) {
-                j = l;
-                l = polkit_list_append (l, (void *) items[n]);
-                if (l == NULL)
-                        goto oom;
-        }
-
-        c.num = 0;
-        c.result = 0;
-        polkit_list_foreach (l, _sum, &c);
-        g_assert (c.result == 1*1 + 2*2 + 3*3 + 4*4 + 5*5);
-
-        polkit_list_free (l);
-
-        return TRUE;
-oom:
-        polkit_list_free (j);
-        return TRUE;
-}
-
-PolKitTest _test_list = {
-        "polkit_list",
-        NULL,
-        NULL,
-        _run_test
-};
-
-#endif /* POLKIT_BUILD_TESTS */
diff --git a/src/polkit/polkit-list.h b/src/polkit/polkit-list.h
deleted file mode 100644
index e8de811..0000000
--- a/src/polkit/polkit-list.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-/***************************************************************************
- *
- * polkit-list.h : Doubly-linked list
- *
- * Copyright (C) 2007 David Zeuthen, <david at 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
- *
- **************************************************************************/
-
-#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_LIST_H
-#define POLKIT_LIST_H
-
-#include <polkit/polkit-types.h>
-
-POLKIT_BEGIN_DECLS
-
-struct _PolKitList;
-typedef struct _PolKitList PolKitList;
-
-/**
- * PolKitList:
- * @data: the value passed in polkit_list_append() and polkit_list_prepend()
- * @next: the next element in the list or #NULL if this is the last element
- * @prev: the previous element in the list or #NULL if this is the last element
- *
- * Public members of the #PolKitList data structure
- *
- * Since: 0.7
- */
-struct _PolKitList {
-        void *data;
-        PolKitList *next;
-        PolKitList *prev;
-};
-
-/**
- * PolKitListForeachFunc:
- * @list: the list
- * @data: data of link entry
- * @user_data: user data passed to polkit_list_foreach()
- *
- * Type signature for callback function used in polkit_list_foreach().
- *
- * Returns: Return #TRUE to short-circuit, e.g. stop the iteration.
- *
- * Since: 0.7
- */
-typedef polkit_bool_t (*PolKitListForeachFunc) (PolKitList *list,
-                                                void *data,
-                                                void *user_data);
-
-PolKitList    *polkit_list_append      (PolKitList *list, void *data);
-PolKitList    *polkit_list_prepend     (PolKitList *list, void *data);
-void           polkit_list_free        (PolKitList *list);
-PolKitList    *polkit_list_delete_link (PolKitList *list, PolKitList *link);
-
-size_t         polkit_list_length      (PolKitList *list);
-polkit_bool_t  polkit_list_foreach     (PolKitList *list, PolKitListForeachFunc func, void *user_data);
-
-
-POLKIT_END_DECLS
-
-#endif /* POLKIT_LIST_H */
-
-
diff --git a/src/polkit/polkit-memory.c b/src/polkit/polkit-memory.c
deleted file mode 100644
index 10c208d..0000000
--- a/src/polkit/polkit-memory.c
+++ /dev/null
@@ -1,373 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-/***************************************************************************
- *
- * polkit-memory.c : Memory management
- *
- * Copyright (C) 2007 David Zeuthen, <david at 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
- *
- **************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <glib.h>
-
-#include <polkit/polkit-memory.h>
-#include <polkit/polkit-private.h>
-
-/**
- * SECTION:polkit-memory
- * @title: Memory management
- * @short_description: Memory management
- *
- * Functions used for memory management.
- *
- * Since: 0.7
- **/
-
-
-#ifdef POLKIT_BUILD_TESTS
-
-static int _cur_allocs = 0;
-static int _total_allocs = 0;
-static int _fail_nth = -1;
-
-void 
-_polkit_memory_reset (void)
-{
-        _cur_allocs = 0;
-        _total_allocs = 0;
-        _fail_nth = -1;
-}
-
-int 
-_polkit_memory_get_current_allocations (void)
-{
-        return _cur_allocs;
-}
-
-int 
-_polkit_memory_get_total_allocations (void)
-{
-        return _total_allocs;
-}
-
-void 
-_polkit_memory_fail_nth_alloc (int number)
-{
-        _fail_nth = number;
-}
-
-/**
- * p_malloc:
- * @bytes: number of 8-bit bytes to allocate
- *
- * Allocate memory
- *
- * Returns: memory location or #NULL on OOM. Free with p_free().
- *
- * Since: 0.7
- */
-void *
-p_malloc (size_t bytes)
-{
-        void *p;
-
-        if (_fail_nth != -1 && _total_allocs == _fail_nth) {
-                return NULL;
-        }
-
-        p = malloc (bytes);
-
-        if (p != NULL)  {
-                _cur_allocs++;
-                _total_allocs++;
-        }
-
-        return p;
-}
-
-/**
- * p_malloc0:
- * @bytes: number of 8-bit bytes to allocate
- *
- * Allocate memory and zero it.
- *
- * Returns: memory location or #NULL on OOM. Free with p_free().
- *
- * Since: 0.7
- */
-void *
-p_malloc0 (size_t bytes)
-{
-        void *p;
-
-        if (_fail_nth != -1 && _total_allocs == _fail_nth) {
-                return NULL;
-        }
-
-        p = calloc (1, bytes);
-
-        if (p != NULL)  {
-                _cur_allocs++;
-                _total_allocs++;
-        }
-
-        return p;
-}
-
-/**
- * p_realloc:
- * @memory: memory previously allocated
- * @bytes: new size
- *
- * Reallocate memory; like realloc(3).
- *
- * Returns: memory location or #NULL on OOM. Free with p_free().
- *
- * Since: 0.7
- */
-void *
-p_realloc (void *memory, size_t bytes)
-{
-        void *p;
-
-        g_debug ("realloc %p %d", memory, bytes);
-
-        if (memory == NULL)
-                return p_malloc (bytes);
-
-        if (bytes == 0) {
-                p_free (memory);
-                return memory;
-        }
-
-        if (_fail_nth != -1 && _total_allocs == _fail_nth) {
-                return NULL;
-        }
-
-        p = realloc (memory, bytes);
-
-        return p;
-}
-
-/**
- * p_free:
- * @memory: pointer to memory allocated with p_malloc() + friends
- *
- * Free memory allocated by p_malloc() + friends.
- *
- * Since: 0.7
- */
-void
-p_free (void *memory)
-{
-        free (memory);
-        if (memory != NULL) {
-                _cur_allocs--;
-        }
-}
-
-/**
- * p_strdup:
- * @s: string
- *
- * Duplicate a string. Similar to strdup(3).
- *
- * Returns: Allocated memory or #NULL on OOM. Free with p_free().
- *
- * Since: 0.7
- */
-char *
-p_strdup (const char *s)
-{
-        char *p;
-        size_t len;
-
-        len = strlen (s);
-
-        p = p_malloc (len + 1);
-        if (p == NULL)
-                goto out;
-
-        memcpy (p, s, len);
-        p[len] = '\0';
-
-out:
-        return p;
-}
-
-/**
- * p_strndup:
- * @s: string
- * @n: size
- *
- * Duplicate a string but copy at most @n characters. If @s is longer
- * than @n, only @n characters are copied, and a terminating null byte
- * is added. Similar to strndup(3).
- *
- * Returns: Allocated memory or #NULL on OOM. Free with p_free().
- *
- * Since: 0.7
- */
-char *
-p_strndup (const char *s, size_t n)
-{
-        char *p;
-        size_t len;
-
-        for (len = 0; len < n; len++) {
-                if (s[len] == '\0')
-                        break;
-                if (len == n)
-                        break;
-        }
-
-
-        p = p_malloc (len + 1);
-        if (p == NULL)
-                goto out;
-
-        memcpy (p, s, len);
-        p[len] = '\0';
-out:
-        return p;
-}
-
-/*--------------------------------------------------------------------------------------------------------------*/
-#else
-/*--------------------------------------------------------------------------------------------------------------*/
-
-void *
-p_malloc (size_t bytes)
-{
-        return malloc (bytes);
-}
-
-void *
-p_malloc0 (size_t bytes)
-{
-        return calloc (1, bytes);
-}
-
-void *
-p_realloc (void *memory, size_t bytes)
-{
-        return realloc (memory, bytes);
-}
-
-void
-p_free (void *memory)
-{
-        free (memory);
-}
-
-void 
-_polkit_memory_reset (void)
-{
-}
-
-int 
-_polkit_memory_get_current_allocations (void)
-{
-        return -1;
-}
-
-int 
-_polkit_memory_get_total_allocations (void)
-{
-        return -1;
-}
-
-void 
-_polkit_memory_fail_nth_alloc (int number)
-{
-}
-
-char *
-p_strdup (const char *s)
-{
-        return strdup (s);
-}
-
-char *
-p_strndup (const char *s, size_t n)
-{
-        return strndup (s, n);
-}
-
-#endif /* POLKIT_BUILD_TESTS */
-
-/**
- * p_strdup_printf:
- * @format: sprintf(3) format string
- * @...:  the parameters to insert into the format string.
- * 
- * Similar to the standard C sprintf(3) function but safer, since it
- * calculates the maximum space required and allocates memory to hold
- * the result. The returned string should be freed when no longer
- * needed.
- *
- * Returns: A newly allocated string or #NULL on OOM. Free with p_free().
- *
- * Since: 0.7
- */
-char* 
-p_strdup_printf (const char *format, ...)
-{
-        char *s;
-        va_list args;
-
-        va_start (args, format);
-        s = p_strdup_vprintf (format, args);
-        va_end (args);
-
-        return s;
-}
-
-/**
- * p_strdup_vprintf:
- * @format: printf(3) format string
- * @args: list of parameters to insert
- * 
- * Similar to the standard C vsprintf(3) function but safer, since it
- * calculates the maximum space required and allocates memory to hold
- * the result. The returned string should be freed when no longer
- * needed.
- *
- * Returns: A newly allocated string or #NULL on OOM. Free with p_free().
- *
- * Since: 0.7
- */
-char* 
-p_strdup_vprintf (const char *format, va_list args)
-{
-        char *s;
-        char *gs;
-        /* TODO: reimplement */
-        gs = g_strdup_vprintf (format, args);
-        s = p_strdup (gs);
-        g_free (gs);
-
-        return s;
-}
diff --git a/src/polkit/polkit-memory.h b/src/polkit/polkit-memory.h
deleted file mode 100644
index 78d3d83..0000000
--- a/src/polkit/polkit-memory.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-/***************************************************************************
- *
- * polkit-memory.h : Memory management
- *
- * Copyright (C) 2007 David Zeuthen, <david at 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
- *
- **************************************************************************/
-
-#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_MEMORY_H
-#define POLKIT_MEMORY_H
-
-#include <stdarg.h>
-#include <polkit/polkit-types.h>
-
-POLKIT_BEGIN_DECLS
-
-void *p_malloc  (size_t bytes);
-void *p_malloc0 (size_t bytes);
-void *p_realloc (void *memory, size_t bytes);
-void  p_free    (void *memory);
-
-/**
- * p_new:
- * @type: the type of object to allocate
- * @count: number of objects to allocate
- *
- * Allocate memory for @count structures of type @type.
- *
- * Returns: Allocated memory, cast to a pointer of #type or #NULL on OOM.
- */
-#define p_new(type, count)  ((type*)p_malloc (sizeof (type) * (count)));
-
-/**
- * p_new0:
- * @type: the type of object to allocate
- * @count: number of objects to allocate
- *
- * Allocate zeroed memory for @count structures of type @type.
- *
- * Returns: Allocated memory, cast to a pointer of #type or #NULL on OOM.
- */
-#define p_new0(type, count) ((type*)p_malloc0 (sizeof (type) * (count)));
-
-char *p_strdup         (const char *s);
-char *p_strndup        (const char *s, size_t n);
-char* p_strdup_printf  (const char *format, ...);
-char* p_strdup_vprintf (const char *format, va_list args);
-
-
-POLKIT_END_DECLS
-
-#endif /* POLKIT_MEMORY_H */
-
-
diff --git a/src/polkit/polkit-policy-cache.c b/src/polkit/polkit-policy-cache.c
index 6775238..dc49d28 100644
--- a/src/polkit/polkit-policy-cache.c
+++ b/src/polkit/polkit-policy-cache.c
@@ -41,13 +41,10 @@
 #include <fcntl.h>
 #include <dirent.h>
 
-#include <glib.h>
 #include "polkit-debug.h"
 #include "polkit-policy-file.h"
 #include "polkit-policy-cache.h"
 #include "polkit-private.h"
-#include "polkit-memory.h"
-#include "polkit-list.h"
 #include "polkit-test.h"
 
 /**
@@ -69,7 +66,7 @@ struct _PolKitPolicyCache
 {
         int refcount;
 
-        PolKitList *priv_entries;
+        KitList *priv_entries;
 };
 
 
@@ -78,11 +75,11 @@ _prepend_entry (PolKitPolicyFile       *policy_file,
                PolKitPolicyFileEntry  *policy_file_entry,
                void                   *user_data)
 {
-        PolKitList *l;
+        KitList *l;
         PolKitPolicyCache *policy_cache = user_data;
 
         polkit_policy_file_entry_ref (policy_file_entry);
-        l = polkit_list_prepend (policy_cache->priv_entries, policy_file_entry);
+        l = kit_list_prepend (policy_cache->priv_entries, policy_file_entry);
         if (l == NULL) {
                 polkit_policy_file_entry_unref (policy_file_entry);
                 goto oom;
@@ -103,7 +100,7 @@ _polkit_policy_cache_new (const char *dirname, polkit_bool_t load_descriptions,
 
         dir = NULL;
 
-        pc = p_new0 (PolKitPolicyCache, 1);
+        pc = kit_new0 (PolKitPolicyCache, 1);
         if (pc == NULL) {
                 polkit_error_set_error (error, POLKIT_ERROR_OUT_OF_MEMORY, "Out of memory");
                 goto out;
@@ -136,12 +133,16 @@ _polkit_policy_cache_new (const char *dirname, polkit_bool_t load_descriptions,
                 if (name_len < sizeof (suffix) || strcmp ((filename + name_len - sizeof (suffix) + 1), suffix) != 0)
                         continue;
 
-                path = g_strdup_printf ("%s/%s", dirname, filename);
+                path = kit_strdup_printf ("%s/%s", dirname, filename);
+                if (path == NULL) {
+                        polkit_error_set_error (error, POLKIT_ERROR_OUT_OF_MEMORY, "Out of memory");
+                        goto out;
+                }
 
                 _pk_debug ("Loading %s", path);
                 pk_error = NULL;
                 pf = polkit_policy_file_new (path, load_descriptions, &pk_error);
-                g_free (path);
+                kit_free (path);
 
                 if (pf == NULL) {
                         if (polkit_error_get_error_code (pk_error) == POLKIT_ERROR_OUT_OF_MEMORY) {
@@ -189,7 +190,7 @@ out:
 PolKitPolicyCache *
 polkit_policy_cache_ref (PolKitPolicyCache *policy_cache)
 {
-        g_return_val_if_fail (policy_cache != NULL, policy_cache);
+        kit_return_val_if_fail (policy_cache != NULL, policy_cache);
         policy_cache->refcount++;
         return policy_cache;
 }
@@ -205,9 +206,9 @@ polkit_policy_cache_ref (PolKitPolicyCache *policy_cache)
 void
 polkit_policy_cache_unref (PolKitPolicyCache *policy_cache)
 {
-        PolKitList *i;
+        KitList *i;
 
-        g_return_if_fail (policy_cache != NULL);
+        kit_return_if_fail (policy_cache != NULL);
         policy_cache->refcount--;
         if (policy_cache->refcount > 0) 
                 return;
@@ -217,9 +218,9 @@ polkit_policy_cache_unref (PolKitPolicyCache *policy_cache)
                 polkit_policy_file_entry_unref (pfe);
         }
         if (policy_cache->priv_entries != NULL)
-                polkit_list_free (policy_cache->priv_entries);
+                kit_list_free (policy_cache->priv_entries);
 
-        p_free (policy_cache);
+        kit_free (policy_cache);
 }
 
 /**
@@ -231,12 +232,12 @@ polkit_policy_cache_unref (PolKitPolicyCache *policy_cache)
 void
 polkit_policy_cache_debug (PolKitPolicyCache *policy_cache)
 {
-        PolKitList *i;
-        g_return_if_fail (policy_cache != NULL);
+        KitList *i;
+        kit_return_if_fail (policy_cache != NULL);
 
         _pk_debug ("PolKitPolicyCache: refcount=%d num_entries=%d ...", 
                    policy_cache->refcount,
-                   policy_cache->priv_entries == NULL ? 0 : polkit_list_length (policy_cache->priv_entries));
+                   policy_cache->priv_entries == NULL ? 0 : kit_list_length (policy_cache->priv_entries));
 
         for (i = policy_cache->priv_entries; i != NULL; i = i->next) {
                 PolKitPolicyFileEntry *pfe = i->data;
@@ -260,11 +261,11 @@ polkit_policy_cache_debug (PolKitPolicyCache *policy_cache)
 PolKitPolicyFileEntry* 
 polkit_policy_cache_get_entry_by_id (PolKitPolicyCache *policy_cache, const char *action_id)
 {
-        PolKitList *i;
+        KitList *i;
         PolKitPolicyFileEntry *pfe;
 
-        g_return_val_if_fail (policy_cache != NULL, NULL);
-        g_return_val_if_fail (action_id != NULL, NULL);
+        kit_return_val_if_fail (policy_cache != NULL, NULL);
+        kit_return_val_if_fail (action_id != NULL, NULL);
 
         pfe = NULL;
 
@@ -307,8 +308,8 @@ polkit_policy_cache_get_entry (PolKitPolicyCache *policy_cache,
 
         /* I'm sure it would be easy to make this O(1)... */
 
-        g_return_val_if_fail (policy_cache != NULL, NULL);
-        g_return_val_if_fail (action != NULL, NULL);
+        kit_return_val_if_fail (policy_cache != NULL, NULL);
+        kit_return_val_if_fail (action != NULL, NULL);
 
         pfe = NULL;
 
@@ -336,11 +337,11 @@ polkit_policy_cache_foreach (PolKitPolicyCache *policy_cache,
                              PolKitPolicyCacheForeachFunc callback,
                              void *user_data)
 {
-        PolKitList *i;
+        KitList *i;
         PolKitPolicyFileEntry *pfe;
 
-        g_return_val_if_fail (policy_cache != NULL, FALSE);
-        g_return_val_if_fail (callback != NULL, FALSE);
+        kit_return_val_if_fail (policy_cache != NULL, FALSE);
+        kit_return_val_if_fail (callback != NULL, FALSE);
 
         for (i = policy_cache->priv_entries; i != NULL; i = i->next) {
                 pfe = i->data;
@@ -376,11 +377,11 @@ polkit_policy_cache_get_entry_by_annotation (PolKitPolicyCache *policy_cache,
                                              const char *annotation_key,
                                              const char *annotation_value)
 {
-        PolKitList *i;
+        KitList *i;
 
-        g_return_val_if_fail (policy_cache != NULL, NULL);
-        g_return_val_if_fail (annotation_key != NULL, NULL);
-        g_return_val_if_fail (annotation_value != NULL, NULL);
+        kit_return_val_if_fail (policy_cache != NULL, NULL);
+        kit_return_val_if_fail (annotation_key != NULL, NULL);
+        kit_return_val_if_fail (annotation_value != NULL, NULL);
 
         for (i = policy_cache->priv_entries; i != NULL; i = i->next) {
                 const char *value;
@@ -437,15 +438,15 @@ _run_test (void)
         int counter;
 
         error = NULL;
-        g_assert (_polkit_policy_cache_new (TEST_DATA_DIR "/non-existant", TRUE, &error) == NULL);
-        g_assert (polkit_error_is_set (error) && 
+        kit_assert (_polkit_policy_cache_new (TEST_DATA_DIR "/non-existant", TRUE, &error) == NULL);
+        kit_assert (polkit_error_is_set (error) && 
                   (polkit_error_get_error_code (error) == POLKIT_ERROR_POLICY_FILE_INVALID ||
                    polkit_error_get_error_code (error) == POLKIT_ERROR_OUT_OF_MEMORY));
         polkit_error_free (error);
 
         error = NULL;
         if ((pc = _polkit_policy_cache_new (TEST_DATA_DIR "/invalid", TRUE, &error)) == NULL) {
-                g_assert (polkit_error_is_set (error) && 
+                kit_assert (polkit_error_is_set (error) && 
                           polkit_error_get_error_code (error) == POLKIT_ERROR_OUT_OF_MEMORY);
                 polkit_error_free (error);
         } else {
@@ -454,36 +455,36 @@ _run_test (void)
 
         error = NULL;
         if ((pc = _polkit_policy_cache_new (TEST_DATA_DIR "/valid", TRUE, &error)) == NULL) {
-                g_assert (polkit_error_is_set (error) && 
+                kit_assert (polkit_error_is_set (error) && 
                           polkit_error_get_error_code (error) == POLKIT_ERROR_OUT_OF_MEMORY);
                 polkit_error_free (error);
                 goto out;
         }
 
-        g_assert (polkit_policy_cache_get_entry_by_id (pc, "org.example.valid1") != NULL);
-        g_assert (polkit_policy_cache_get_entry_by_id (pc, "org.example.non-existant") == NULL);
+        kit_assert (polkit_policy_cache_get_entry_by_id (pc, "org.example.valid1") != NULL);
+        kit_assert (polkit_policy_cache_get_entry_by_id (pc, "org.example.non-existant") == NULL);
 
         pfe = polkit_policy_cache_get_entry_by_annotation (pc, "the.key1", "Some Value 1");
-        g_assert (pfe != NULL && strcmp (polkit_policy_file_entry_get_id (pfe), "org.example.valid2") == 0);
+        kit_assert (pfe != NULL && strcmp (polkit_policy_file_entry_get_id (pfe), "org.example.valid2") == 0);
         pfe = polkit_policy_cache_get_entry_by_annotation (pc, "the.key2", "Some Value 2");
-        g_assert (pfe != NULL && strcmp (polkit_policy_file_entry_get_id (pfe), "org.example.valid2") == 0);
+        kit_assert (pfe != NULL && strcmp (polkit_policy_file_entry_get_id (pfe), "org.example.valid2") == 0);
         pfe = polkit_policy_cache_get_entry_by_annotation (pc, "the.key1", "Some Value 1b");
-        g_assert (pfe != NULL && strcmp (polkit_policy_file_entry_get_id (pfe), "org.example.valid2b") == 0);
+        kit_assert (pfe != NULL && strcmp (polkit_policy_file_entry_get_id (pfe), "org.example.valid2b") == 0);
         pfe = polkit_policy_cache_get_entry_by_annotation (pc, "the.key1", "NON-EXISTANT VALUE");
-        g_assert (pfe == NULL);
+        kit_assert (pfe == NULL);
         pfe = polkit_policy_cache_get_entry_by_annotation (pc, "NON_EXISTANT KEY", "NON-EXISTANT VALUE");
-        g_assert (pfe == NULL);
+        kit_assert (pfe == NULL);
 
         if ((a = polkit_action_new ()) != NULL) {
                 pfe = polkit_policy_cache_get_entry (pc, a);
-                g_assert (pfe == NULL);
+                kit_assert (pfe == NULL);
                 if (polkit_action_set_action_id (a, "org.example.valid1")) {
                         pfe = polkit_policy_cache_get_entry (pc, a);
-                        g_assert (pfe != NULL && strcmp (polkit_policy_file_entry_get_id (pfe), "org.example.valid1") == 0);
+                        kit_assert (pfe != NULL && strcmp (polkit_policy_file_entry_get_id (pfe), "org.example.valid1") == 0);
                 }
                 if (polkit_action_set_action_id (a, "org.example.non-existant")) {
                         pfe = polkit_policy_cache_get_entry (pc, a);
-                        g_assert (pfe == NULL);
+                        kit_assert (pfe == NULL);
                 }
 
                 polkit_action_unref (a);
@@ -491,11 +492,11 @@ _run_test (void)
 
         counter = 0;
         polkit_policy_cache_foreach (pc, _test_count, &counter);
-        g_assert (counter == 6);
+        kit_assert (counter == 6);
 
         counter = 0;
         polkit_policy_cache_foreach (pc, _test_short_circuit, &counter);
-        g_assert (counter == 1);
+        kit_assert (counter == 1);
 
         polkit_policy_cache_debug (pc);
         polkit_policy_cache_ref (pc);
diff --git a/src/polkit/polkit-policy-default.c b/src/polkit/polkit-policy-default.c
index ed689e5..e0b6009 100644
--- a/src/polkit/polkit-policy-default.c
+++ b/src/polkit/polkit-policy-default.c
@@ -36,13 +36,12 @@
 #include <unistd.h>
 #include <errno.h>
 
-#include <glib.h>
 #include "polkit-debug.h"
 #include "polkit-error.h"
 #include "polkit-policy-default.h"
 #include "polkit-private.h"
 #include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
 
 /**
  * SECTION:polkit-policy-default
@@ -73,7 +72,7 @@ _polkit_policy_default_new (PolKitResult defaults_allow_any,
 {
         PolKitPolicyDefault *pd;
 
-        pd = p_new0 (PolKitPolicyDefault, 1);
+        pd = kit_new0 (PolKitPolicyDefault, 1);
         if (pd == NULL)
                 goto out;
         pd->refcount = 1;
@@ -95,7 +94,7 @@ out:
 PolKitPolicyDefault *
 polkit_policy_default_ref (PolKitPolicyDefault *policy_default)
 {
-        g_return_val_if_fail (policy_default != NULL, policy_default);
+        kit_return_val_if_fail (policy_default != NULL, policy_default);
         policy_default->refcount++;
         return policy_default;
 }
@@ -111,11 +110,11 @@ polkit_policy_default_ref (PolKitPolicyDefault *policy_default)
 void
 polkit_policy_default_unref (PolKitPolicyDefault *policy_default)
 {
-        g_return_if_fail (policy_default != NULL);
+        kit_return_if_fail (policy_default != NULL);
         policy_default->refcount--;
         if (policy_default->refcount > 0) 
                 return;
-        p_free (policy_default);
+        kit_free (policy_default);
 }
 
 /**
@@ -127,7 +126,7 @@ polkit_policy_default_unref (PolKitPolicyDefault *policy_default)
 void
 polkit_policy_default_debug (PolKitPolicyDefault *policy_default)
 {
-        g_return_if_fail (policy_default != NULL);
+        kit_return_if_fail (policy_default != NULL);
         _pk_debug ("PolKitPolicyDefault: refcount=%d\n"
                    "        default_any=%s\n"
                    "   default_inactive=%s\n"
@@ -162,9 +161,9 @@ polkit_policy_default_can_session_do_action (PolKitPolicyDefault *policy_default
 
         ret = POLKIT_RESULT_NO;
 
-        g_return_val_if_fail (policy_default != NULL, ret);
-        g_return_val_if_fail (action != NULL, ret);
-        g_return_val_if_fail (session != NULL, ret);
+        kit_return_val_if_fail (policy_default != NULL, ret);
+        kit_return_val_if_fail (action != NULL, ret);
+        kit_return_val_if_fail (session != NULL, ret);
 
         ret = policy_default->default_any;
 
@@ -207,9 +206,9 @@ polkit_policy_default_can_caller_do_action (PolKitPolicyDefault *policy_default,
 
         ret = POLKIT_RESULT_NO;
 
-        g_return_val_if_fail (policy_default != NULL, ret);
-        g_return_val_if_fail (action != NULL, ret);
-        g_return_val_if_fail (caller != NULL, ret);
+        kit_return_val_if_fail (policy_default != NULL, ret);
+        kit_return_val_if_fail (action != NULL, ret);
+        kit_return_val_if_fail (caller != NULL, ret);
 
         ret = policy_default->default_any;
 
@@ -244,7 +243,7 @@ out:
 PolKitResult
 polkit_policy_default_get_allow_any (PolKitPolicyDefault *policy_default)
 {
-        g_return_val_if_fail (policy_default != NULL, POLKIT_RESULT_NO);
+        kit_return_val_if_fail (policy_default != NULL, POLKIT_RESULT_NO);
         return policy_default->default_any;
 }
 
@@ -259,7 +258,7 @@ polkit_policy_default_get_allow_any (PolKitPolicyDefault *policy_default)
 PolKitResult
 polkit_policy_default_get_allow_inactive (PolKitPolicyDefault *policy_default)
 {
-        g_return_val_if_fail (policy_default != NULL, POLKIT_RESULT_NO);
+        kit_return_val_if_fail (policy_default != NULL, POLKIT_RESULT_NO);
         return policy_default->default_inactive;
 }
 
@@ -274,7 +273,7 @@ polkit_policy_default_get_allow_inactive (PolKitPolicyDefault *policy_default)
 PolKitResult
 polkit_policy_default_get_allow_active (PolKitPolicyDefault *policy_default)
 {
-        g_return_val_if_fail (policy_default != NULL, POLKIT_RESULT_NO);
+        kit_return_val_if_fail (policy_default != NULL, POLKIT_RESULT_NO);
         return policy_default->default_active;
 }
 
@@ -304,10 +303,10 @@ _ts (PolKitSession *s, PolKitResult any, PolKitResult inactive, PolKitResult act
                                 oom = FALSE;
 
                                 if ((c = polkit_caller_new ()) != NULL) {
-                                        g_assert (polkit_policy_default_can_caller_do_action (d, a, c) == any);
+                                        kit_assert (polkit_policy_default_can_caller_do_action (d, a, c) == any);
 
-                                        g_assert (polkit_caller_set_ck_session (c, s));
-                                        g_assert (polkit_policy_default_can_caller_do_action (d, a, c) == *ret);
+                                        kit_assert (polkit_caller_set_ck_session (c, s));
+                                        kit_assert (polkit_policy_default_can_caller_do_action (d, a, c) == *ret);
                                         polkit_caller_unref (c);
                                 }
 
@@ -341,8 +340,8 @@ _run_test (void)
                         polkit_session_unref (s_active);
                         s_active = NULL;
                 } else {
-                        g_assert (polkit_session_set_ck_is_local (s_active, TRUE));
-                        g_assert (polkit_session_set_ck_is_active (s_active, TRUE));
+                        kit_assert (polkit_session_set_ck_is_local (s_active, TRUE));
+                        kit_assert (polkit_session_set_ck_is_active (s_active, TRUE));
                 }
         }
 
@@ -351,8 +350,8 @@ _run_test (void)
                         polkit_session_unref (s_inactive);
                         s_inactive = NULL;
                 } else {
-                        g_assert (polkit_session_set_ck_is_local (s_inactive, TRUE));
-                        g_assert (polkit_session_set_ck_is_active (s_inactive, FALSE));
+                        kit_assert (polkit_session_set_ck_is_local (s_inactive, TRUE));
+                        kit_assert (polkit_session_set_ck_is_active (s_inactive, FALSE));
                 }
         }
 
@@ -362,8 +361,8 @@ _run_test (void)
                         polkit_session_unref (s_active_remote);
                         s_active_remote = NULL;
                 } else {
-                        g_assert (polkit_session_set_ck_is_local (s_active_remote, FALSE));
-                        g_assert (polkit_session_set_ck_is_active (s_active_remote, TRUE));
+                        kit_assert (polkit_session_set_ck_is_local (s_active_remote, FALSE));
+                        kit_assert (polkit_session_set_ck_is_active (s_active_remote, TRUE));
                 }
         }
 
@@ -373,47 +372,47 @@ _run_test (void)
                         polkit_session_unref (s_inactive_remote);
                         s_inactive_remote = NULL;
                 } else {
-                        g_assert (polkit_session_set_ck_is_local (s_inactive_remote, FALSE));
-                        g_assert (polkit_session_set_ck_is_active (s_inactive_remote, FALSE));
+                        kit_assert (polkit_session_set_ck_is_local (s_inactive_remote, FALSE));
+                        kit_assert (polkit_session_set_ck_is_active (s_inactive_remote, FALSE));
                 }
         }
 
-        g_assert (_ts (s_active, 
+        kit_assert (_ts (s_active, 
                        POLKIT_RESULT_NO, POLKIT_RESULT_NO, POLKIT_RESULT_YES, &ret) || 
                   ret == POLKIT_RESULT_YES);
-        g_assert (_ts (s_inactive, 
+        kit_assert (_ts (s_inactive, 
                        POLKIT_RESULT_NO, POLKIT_RESULT_NO, POLKIT_RESULT_YES, &ret) || 
                   ret == POLKIT_RESULT_NO);
-        g_assert (_ts (s_active_remote, 
+        kit_assert (_ts (s_active_remote, 
                        POLKIT_RESULT_NO, POLKIT_RESULT_NO, POLKIT_RESULT_YES, &ret) || 
                   ret == POLKIT_RESULT_NO);
-        g_assert (_ts (s_inactive_remote, 
+        kit_assert (_ts (s_inactive_remote, 
                        POLKIT_RESULT_NO, POLKIT_RESULT_NO, POLKIT_RESULT_YES, &ret) || 
                   ret == POLKIT_RESULT_NO);
 
-        g_assert (_ts (s_active, 
+        kit_assert (_ts (s_active, 
                        POLKIT_RESULT_NO, POLKIT_RESULT_YES, POLKIT_RESULT_YES, &ret) || 
                   ret == POLKIT_RESULT_YES);
-        g_assert (_ts (s_inactive, 
+        kit_assert (_ts (s_inactive, 
                        POLKIT_RESULT_NO, POLKIT_RESULT_YES, POLKIT_RESULT_YES, &ret) || 
                   ret == POLKIT_RESULT_YES);
-        g_assert (_ts (s_active_remote, 
+        kit_assert (_ts (s_active_remote, 
                        POLKIT_RESULT_NO, POLKIT_RESULT_YES, POLKIT_RESULT_YES, &ret) || 
                   ret == POLKIT_RESULT_NO);
-        g_assert (_ts (s_inactive_remote, 
+        kit_assert (_ts (s_inactive_remote, 
                        POLKIT_RESULT_NO, POLKIT_RESULT_YES, POLKIT_RESULT_YES, &ret) || 
                   ret == POLKIT_RESULT_NO);
 
-        g_assert (_ts (s_active, 
+        kit_assert (_ts (s_active, 
                        POLKIT_RESULT_YES, POLKIT_RESULT_YES, POLKIT_RESULT_YES, &ret) || 
                   ret == POLKIT_RESULT_YES);
-        g_assert (_ts (s_inactive, 
+        kit_assert (_ts (s_inactive, 
                        POLKIT_RESULT_YES, POLKIT_RESULT_YES, POLKIT_RESULT_YES, &ret) || 
                   ret == POLKIT_RESULT_YES);
-        g_assert (_ts (s_active_remote, 
+        kit_assert (_ts (s_active_remote, 
                        POLKIT_RESULT_YES, POLKIT_RESULT_YES, POLKIT_RESULT_YES, &ret) || 
                   ret == POLKIT_RESULT_YES);
-        g_assert (_ts (s_inactive_remote, 
+        kit_assert (_ts (s_inactive_remote, 
                        POLKIT_RESULT_YES, POLKIT_RESULT_YES, POLKIT_RESULT_YES, &ret) || 
                   ret == POLKIT_RESULT_YES);
 
diff --git a/src/polkit/polkit-policy-file-entry.c b/src/polkit/polkit-policy-file-entry.c
index de37dba..a6abe42 100644
--- a/src/polkit/polkit-policy-file-entry.c
+++ b/src/polkit/polkit-policy-file-entry.c
@@ -36,7 +36,6 @@
 #include <unistd.h>
 #include <errno.h>
 
-#include <glib.h>
 #include "polkit-debug.h"
 #include "polkit-error.h"
 #include "polkit-result.h"
@@ -44,7 +43,7 @@
 #include "polkit-authorization-db.h"
 #include "polkit-private.h"
 #include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
 
 /**
  * SECTION:polkit-policy-file-entry
@@ -68,7 +67,7 @@ struct _PolKitPolicyFileEntry
 
         char *policy_description;
         char *policy_message;
-        PolKitHash *annotations;
+        KitHash *annotations;
 };
 
 
@@ -78,17 +77,17 @@ _polkit_policy_file_entry_new   (const char *action_id,
                                  PolKitResult defaults_allow_any,
                                  PolKitResult defaults_allow_inactive,
                                  PolKitResult defaults_allow_active,
-                                 PolKitHash *annotations)
+                                 KitHash *annotations)
 {
         PolKitPolicyFileEntry *pfe;
 
-        g_return_val_if_fail (action_id != NULL, NULL);
+        kit_return_val_if_fail (action_id != NULL, NULL);
 
-        pfe = p_new0 (PolKitPolicyFileEntry, 1);
+        pfe = kit_new0 (PolKitPolicyFileEntry, 1);
         if (pfe == NULL)
                 goto error;
         pfe->refcount = 1;
-        pfe->action = p_strdup (action_id);
+        pfe->action = kit_strdup (action_id);
         if (pfe->action == NULL)
                 goto error;
 
@@ -121,15 +120,15 @@ _polkit_policy_file_entry_set_descriptions (PolKitPolicyFileEntry *pfe,
                                             const char *policy_description,
                                             const char *policy_message)
 {
-        g_return_val_if_fail (pfe != NULL, FALSE);
+        kit_return_val_if_fail (pfe != NULL, FALSE);
 
         if (pfe->policy_description != NULL)
-                p_free (pfe->policy_description);
+                kit_free (pfe->policy_description);
         if (pfe->policy_message != NULL)
-                p_free (pfe->policy_message);
+                kit_free (pfe->policy_message);
 
-        pfe->policy_description = p_strdup (policy_description);
-        pfe->policy_message = p_strdup (policy_message);
+        pfe->policy_description = kit_strdup (policy_description);
+        pfe->policy_message = kit_strdup (policy_message);
 
         if (policy_description != NULL && pfe->policy_description == NULL)
                 return FALSE;
@@ -158,7 +157,7 @@ _polkit_policy_file_entry_set_descriptions (PolKitPolicyFileEntry *pfe,
 const char *
 polkit_policy_file_entry_get_action_description (PolKitPolicyFileEntry *policy_file_entry)
 {
-        g_return_val_if_fail (policy_file_entry != NULL, NULL);
+        kit_return_val_if_fail (policy_file_entry != NULL, NULL);
         return policy_file_entry->policy_description;
 }
 
@@ -181,7 +180,7 @@ polkit_policy_file_entry_get_action_description (PolKitPolicyFileEntry *policy_f
 const char *
 polkit_policy_file_entry_get_action_message (PolKitPolicyFileEntry *policy_file_entry)
 {
-        g_return_val_if_fail (policy_file_entry != NULL, NULL);
+        kit_return_val_if_fail (policy_file_entry != NULL, NULL);
         return policy_file_entry->policy_message;
 }
 
@@ -196,7 +195,7 @@ polkit_policy_file_entry_get_action_message (PolKitPolicyFileEntry *policy_file_
 PolKitPolicyFileEntry *
 polkit_policy_file_entry_ref (PolKitPolicyFileEntry *policy_file_entry)
 {
-        g_return_val_if_fail (policy_file_entry != NULL, policy_file_entry);
+        kit_return_val_if_fail (policy_file_entry != NULL, policy_file_entry);
         policy_file_entry->refcount++;
         return policy_file_entry;
 }
@@ -212,23 +211,23 @@ polkit_policy_file_entry_ref (PolKitPolicyFileEntry *policy_file_entry)
 void
 polkit_policy_file_entry_unref (PolKitPolicyFileEntry *policy_file_entry)
 {
-        g_return_if_fail (policy_file_entry != NULL);
+        kit_return_if_fail (policy_file_entry != NULL);
         policy_file_entry->refcount--;
         if (policy_file_entry->refcount > 0) 
                 return;
 
-        p_free (policy_file_entry->action);
+        kit_free (policy_file_entry->action);
 
         if (policy_file_entry->defaults != NULL)
                 polkit_policy_default_unref (policy_file_entry->defaults);
 
         if (policy_file_entry->annotations != NULL)
-                polkit_hash_unref (policy_file_entry->annotations);
+                kit_hash_unref (policy_file_entry->annotations);
 
-        p_free (policy_file_entry->policy_description);
-        p_free (policy_file_entry->policy_message);
+        kit_free (policy_file_entry->policy_description);
+        kit_free (policy_file_entry->policy_message);
 
-        p_free (policy_file_entry);
+        kit_free (policy_file_entry);
 }
 
 /**
@@ -240,7 +239,7 @@ polkit_policy_file_entry_unref (PolKitPolicyFileEntry *policy_file_entry)
 void
 polkit_policy_file_entry_debug (PolKitPolicyFileEntry *policy_file_entry)
 {
-        g_return_if_fail (policy_file_entry != NULL);
+        kit_return_if_fail (policy_file_entry != NULL);
         _pk_debug ("PolKitPolicyFileEntry: refcount=%d action=%s",
                    policy_file_entry->refcount,
                    policy_file_entry->action);
@@ -258,7 +257,7 @@ polkit_policy_file_entry_debug (PolKitPolicyFileEntry *policy_file_entry)
 const char *
 polkit_policy_file_entry_get_id (PolKitPolicyFileEntry *policy_file_entry)
 {
-        g_return_val_if_fail (policy_file_entry != NULL, NULL);
+        kit_return_val_if_fail (policy_file_entry != NULL, NULL);
         return policy_file_entry->action;
 }
 
@@ -273,7 +272,7 @@ polkit_policy_file_entry_get_id (PolKitPolicyFileEntry *policy_file_entry)
 PolKitPolicyDefault *
 polkit_policy_file_entry_get_default (PolKitPolicyFileEntry *policy_file_entry)
 {
-        g_return_val_if_fail (policy_file_entry != NULL, NULL);
+        kit_return_val_if_fail (policy_file_entry != NULL, NULL);
         return policy_file_entry->defaults;
 }
 
@@ -284,7 +283,7 @@ typedef struct  {
 } _AnnotationsClosure;
 
 static polkit_bool_t
-_annotations_cb (PolKitHash *hash,
+_annotations_cb (KitHash *hash,
                  void *key,
                  void *value,
                  void *user_data)
@@ -310,7 +309,7 @@ polkit_policy_file_entry_annotations_foreach (PolKitPolicyFileEntry *policy_file
 {
         _AnnotationsClosure closure;
 
-        g_return_val_if_fail (policy_file_entry != NULL, FALSE);
+        kit_return_val_if_fail (policy_file_entry != NULL, FALSE);
         if (policy_file_entry->annotations == NULL)
                 return FALSE;
 
@@ -318,7 +317,7 @@ polkit_policy_file_entry_annotations_foreach (PolKitPolicyFileEntry *policy_file
         closure.cb = cb;
         closure.user_data = user_data;
 
-        return polkit_hash_foreach (policy_file_entry->annotations,
+        return kit_hash_foreach (policy_file_entry->annotations,
                                     _annotations_cb,
                                     &closure);
 }
@@ -337,12 +336,12 @@ polkit_policy_file_entry_get_annotation (PolKitPolicyFileEntry *policy_file_entr
                                          const char *key)
 {
         const char *value;
-        g_return_val_if_fail (policy_file_entry != NULL, NULL);
-        g_return_val_if_fail (key != NULL, NULL);
+        kit_return_val_if_fail (policy_file_entry != NULL, NULL);
+        kit_return_val_if_fail (key != NULL, NULL);
 
         value = NULL;
         if (policy_file_entry->annotations != NULL) {
-                value = polkit_hash_lookup (policy_file_entry->annotations, (void *) key, NULL);
+                value = kit_hash_lookup (policy_file_entry->annotations, (void *) key, NULL);
         }
         return value;
 }
@@ -383,22 +382,22 @@ _run_test (void)
 {
         PolKitPolicyFileEntry *pfe;
         PolKitPolicyDefault *d;
-        PolKitHash *a;
+        KitHash *a;
         int count;
 
         a = NULL;
         pfe = NULL;
 
-        if ((a = polkit_hash_new (polkit_hash_str_hash_func,
-                                  polkit_hash_str_equal_func,
-                                  NULL, NULL,
-                                  NULL, NULL)) == NULL)
+        if ((a = kit_hash_new (kit_hash_str_hash_func,
+                               kit_hash_str_equal_func,
+                               NULL, NULL,
+                               NULL, NULL)) == NULL)
                 goto oom;
 
-        if (!polkit_hash_insert (a, "a1", "v1"))
+        if (!kit_hash_insert (a, "a1", "v1"))
                 goto oom;
 
-        if (!polkit_hash_insert (a, "a2", "v2"))
+        if (!kit_hash_insert (a, "a2", "v2"))
                 goto oom;
 
         if ((pfe = _polkit_policy_file_entry_new ("org.example-action",
@@ -410,38 +409,38 @@ _run_test (void)
         /* _file_entry_new assumes ownership of the passed a variable */
         a = NULL;
 
-        g_assert (strcmp (polkit_policy_file_entry_get_id (pfe), "org.example-action") == 0);
+        kit_assert (strcmp (polkit_policy_file_entry_get_id (pfe), "org.example-action") == 0);
         
         if (_polkit_policy_file_entry_set_descriptions (pfe,
                                                         "the desc",
                                                         "the msg")) {
-                g_assert (strcmp (polkit_policy_file_entry_get_action_description (pfe), "the desc") == 0);
-                g_assert (strcmp (polkit_policy_file_entry_get_action_message (pfe), "the msg") == 0);
+                kit_assert (strcmp (polkit_policy_file_entry_get_action_description (pfe), "the desc") == 0);
+                kit_assert (strcmp (polkit_policy_file_entry_get_action_message (pfe), "the msg") == 0);
         }
         
         if (_polkit_policy_file_entry_set_descriptions (pfe,
                                                         "the desc2",
                                                         "the msg2")) {
-                g_assert (strcmp (polkit_policy_file_entry_get_action_description (pfe), "the desc2") == 0);
-                g_assert (strcmp (polkit_policy_file_entry_get_action_message (pfe), "the msg2") == 0);
+                kit_assert (strcmp (polkit_policy_file_entry_get_action_description (pfe), "the desc2") == 0);
+                kit_assert (strcmp (polkit_policy_file_entry_get_action_message (pfe), "the msg2") == 0);
         }
         
-        g_assert ((d = polkit_policy_file_entry_get_default (pfe)) != NULL);
-        g_assert (polkit_policy_default_get_allow_any (d) == POLKIT_RESULT_NO);
-        g_assert (polkit_policy_default_get_allow_inactive (d) == POLKIT_RESULT_ONLY_VIA_SELF_AUTH);
-        g_assert (polkit_policy_default_get_allow_active (d) == POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH);
+        kit_assert ((d = polkit_policy_file_entry_get_default (pfe)) != NULL);
+        kit_assert (polkit_policy_default_get_allow_any (d) == POLKIT_RESULT_NO);
+        kit_assert (polkit_policy_default_get_allow_inactive (d) == POLKIT_RESULT_ONLY_VIA_SELF_AUTH);
+        kit_assert (polkit_policy_default_get_allow_active (d) == POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH);
         
         polkit_policy_file_entry_ref (pfe);
         polkit_policy_file_entry_unref (pfe);
         polkit_policy_file_entry_debug (pfe);
 
-        g_assert (strcmp (polkit_policy_file_entry_get_annotation (pfe, "a1"), "v1") == 0);
-        g_assert (strcmp (polkit_policy_file_entry_get_annotation (pfe, "a2"), "v2") == 0);
-        g_assert (polkit_policy_file_entry_get_annotation (pfe, "a3") == NULL);
+        kit_assert (strcmp (polkit_policy_file_entry_get_annotation (pfe, "a1"), "v1") == 0);
+        kit_assert (strcmp (polkit_policy_file_entry_get_annotation (pfe, "a2"), "v2") == 0);
+        kit_assert (polkit_policy_file_entry_get_annotation (pfe, "a3") == NULL);
 
         count = 0;
         polkit_policy_file_entry_annotations_foreach (pfe, _pfe_cb, &count);
-        g_assert (count == 2);
+        kit_assert (count == 2);
 
         polkit_policy_file_entry_unref (pfe);
         if ((pfe = _polkit_policy_file_entry_new ("org.example-action-2",
@@ -452,16 +451,16 @@ _run_test (void)
                 goto oom;
         count = 0;
         polkit_policy_file_entry_annotations_foreach (pfe, _pfe_cb2, &count);
-        g_assert (count == 0);
+        kit_assert (count == 0);
         _pfe_cb2 (pfe, NULL, NULL, &count); /* want to get coverage of _pfe_cb2 */
-        g_assert (count == 1);
+        kit_assert (count == 1);
 
 oom:
         if (pfe != NULL)
                 polkit_policy_file_entry_unref (pfe);
 
         if (a != NULL)
-                polkit_hash_unref (a);
+                kit_hash_unref (a);
 
         return TRUE;
 }
diff --git a/src/polkit/polkit-policy-file.c b/src/polkit/polkit-policy-file.c
index 1b7d238..595b168 100644
--- a/src/polkit/polkit-policy-file.c
+++ b/src/polkit/polkit-policy-file.c
@@ -36,10 +36,10 @@
 #include <unistd.h>
 #include <errno.h>
 #include <syslog.h>
+#include <sys/stat.h>
 
 #include <expat.h>
 
-#include <glib.h>
 #include "polkit-error.h"
 #include "polkit-result.h"
 #include "polkit-policy-file.h"
@@ -47,7 +47,6 @@
 #include "polkit-debug.h"
 #include "polkit-private.h"
 #include "polkit-test.h"
-#include "polkit-list.h"
 
 /**
  * SECTION:polkit-policy-file
@@ -66,7 +65,7 @@
 struct _PolKitPolicyFile
 {
         int refcount;
-        PolKitList *entries;
+        KitList *entries;
 };
 
 enum {
@@ -103,8 +102,8 @@ typedef struct {
 
         polkit_bool_t load_descriptions;
 
-        PolKitHash *policy_descriptions;
-        PolKitHash *policy_messages;
+        KitHash *policy_descriptions;
+        KitHash *policy_messages;
 
         char *policy_description_nolang;
         char *policy_message_nolang;
@@ -116,7 +115,7 @@ typedef struct {
         char *elem_lang;
 
         char *annotate_key;
-        PolKitHash *annotations;
+        KitHash *annotations;
 
         polkit_bool_t is_oom;
 } ParserData;
@@ -124,27 +123,27 @@ typedef struct {
 static void
 pd_unref_action_data (ParserData *pd)
 {
-        p_free (pd->action_id);
+        kit_free (pd->action_id);
         pd->action_id = NULL;
-        p_free (pd->policy_description_nolang);
+        kit_free (pd->policy_description_nolang);
         pd->policy_description_nolang = NULL;
-        p_free (pd->policy_message_nolang);
+        kit_free (pd->policy_message_nolang);
         pd->policy_message_nolang = NULL;
         if (pd->policy_descriptions != NULL) {
-                polkit_hash_unref (pd->policy_descriptions);
+                kit_hash_unref (pd->policy_descriptions);
                 pd->policy_descriptions = NULL;
         }
         if (pd->policy_messages != NULL) {
-                polkit_hash_unref (pd->policy_messages);
+                kit_hash_unref (pd->policy_messages);
                 pd->policy_messages = NULL;
         }
-        p_free (pd->annotate_key);
+        kit_free (pd->annotate_key);
         pd->annotate_key = NULL;
         if (pd->annotations != NULL) {
-                polkit_hash_unref (pd->annotations);
+                kit_hash_unref (pd->annotations);
                 pd->annotations = NULL;
         }
-        p_free (pd->elem_lang);
+        kit_free (pd->elem_lang);
         pd->elem_lang = NULL;
 }
 
@@ -152,7 +151,7 @@ static void
 pd_unref_data (ParserData *pd)
 {
         pd_unref_action_data (pd);
-        p_free (pd->lang);
+        kit_free (pd->lang);
         pd->lang = NULL;
 }
 
@@ -184,17 +183,17 @@ _start (void *data, const char *el, const char **attr)
                                 goto error;
 
                         pd_unref_action_data (pd);
-                        pd->action_id = p_strdup (attr[1]);
+                        pd->action_id = kit_strdup (attr[1]);
                         if (pd->action_id == NULL)
                                 goto oom;
-                        pd->policy_descriptions = polkit_hash_new (polkit_hash_str_hash_func, 
-                                                                   polkit_hash_str_equal_func, 
-                                                                   polkit_hash_str_copy, polkit_hash_str_copy,
-                                                                   p_free, p_free);
-                        pd->policy_messages = polkit_hash_new (polkit_hash_str_hash_func, 
-                                                               polkit_hash_str_equal_func, 
-                                                               polkit_hash_str_copy, polkit_hash_str_copy,
-                                                               p_free, p_free);
+                        pd->policy_descriptions = kit_hash_new (kit_hash_str_hash_func, 
+                                                                kit_hash_str_equal_func, 
+                                                                kit_hash_str_copy, kit_hash_str_copy,
+                                                                kit_free, kit_free);
+                        pd->policy_messages = kit_hash_new (kit_hash_str_hash_func, 
+                                                            kit_hash_str_equal_func, 
+                                                            kit_hash_str_copy, kit_hash_str_copy,
+                                                            kit_free, kit_free);
 
                         /* initialize defaults */
                         pd->defaults_allow_any = POLKIT_RESULT_NO;
@@ -207,14 +206,14 @@ _start (void *data, const char *el, const char **attr)
                         state = STATE_IN_DEFAULTS;
                 } else if (strcmp (el, "description") == 0) {
                         if (num_attr == 2 && strcmp (attr[0], "xml:lang") == 0) {
-                                pd->elem_lang = p_strdup (attr[1]);
+                                pd->elem_lang = kit_strdup (attr[1]);
                                 if (pd->elem_lang == NULL)
                                         goto oom;
                         }
                         state = STATE_IN_ACTION_DESCRIPTION;
                 } else if (strcmp (el, "message") == 0) {
                         if (num_attr == 2 && strcmp (attr[0], "xml:lang") == 0) {
-                                pd->elem_lang = p_strdup (attr[1]);
+                                pd->elem_lang = kit_strdup (attr[1]);
                                 if (pd->elem_lang == NULL)
                                         goto oom;
                         }
@@ -224,8 +223,8 @@ _start (void *data, const char *el, const char **attr)
                                 goto error;
                         state = STATE_IN_ANNOTATE;
 
-                        p_free (pd->annotate_key);
-                        pd->annotate_key = p_strdup (attr[1]);
+                        kit_free (pd->annotate_key);
+                        pd->annotate_key = kit_strdup (attr[1]);
                         if (pd->annotate_key == NULL)
                                 goto oom;
                 }
@@ -266,7 +265,7 @@ _cdata (void *data, const char *s, int len)
         char *str;
         ParserData *pd = data;
 
-        str = p_strndup (s, len);
+        str = kit_strndup (s, len);
         if (str == NULL)
                 goto oom;
 
@@ -275,11 +274,11 @@ _cdata (void *data, const char *s, int len)
         case STATE_IN_ACTION_DESCRIPTION:
                 if (pd->load_descriptions) {
                         if (pd->elem_lang == NULL) {
-                                p_free (pd->policy_description_nolang);
+                                kit_free (pd->policy_description_nolang);
                                 pd->policy_description_nolang = str;
                                 str = NULL;
                         } else {
-                                if (!polkit_hash_insert (pd->policy_descriptions, pd->elem_lang, str))
+                                if (!kit_hash_insert (pd->policy_descriptions, pd->elem_lang, str))
                                         goto oom;
                         }
                 }
@@ -288,11 +287,11 @@ _cdata (void *data, const char *s, int len)
         case STATE_IN_ACTION_MESSAGE:
                 if (pd->load_descriptions) {
                         if (pd->elem_lang == NULL) {
-                                p_free (pd->policy_message_nolang);
+                                kit_free (pd->policy_message_nolang);
                                 pd->policy_message_nolang = str;
                                 str = NULL;
                         } else {
-                                if (!polkit_hash_insert (pd->policy_messages, pd->elem_lang, str))
+                                if (!kit_hash_insert (pd->policy_messages, pd->elem_lang, str))
                                         goto oom;
                         }
                 }
@@ -313,26 +312,26 @@ _cdata (void *data, const char *s, int len)
 
         case STATE_IN_ANNOTATE:
                 if (pd->annotations == NULL) {
-                        pd->annotations = polkit_hash_new (polkit_hash_str_hash_func, 
-                                                           polkit_hash_str_equal_func, 
-                                                           polkit_hash_str_copy, polkit_hash_str_copy,
-                                                           p_free, p_free);
+                        pd->annotations = kit_hash_new (kit_hash_str_hash_func, 
+                                                        kit_hash_str_equal_func, 
+                                                        kit_hash_str_copy, kit_hash_str_copy,
+                                                        kit_free, kit_free);
                         if (pd->annotations == NULL)
                                 goto oom;
                 }
-                if (!polkit_hash_insert (pd->annotations, pd->annotate_key, str))
+                if (!kit_hash_insert (pd->annotations, pd->annotate_key, str))
                         goto oom;
                 break;
 
         default:
                 break;
         }
-        p_free (str);
+        kit_free (str);
         return;
 oom:
         pd->is_oom = TRUE;
 error:
-        p_free (str);
+        kit_free (str);
         XML_StopParser (pd->parser, FALSE);
 }
 
@@ -348,7 +347,7 @@ error:
  * Returns: the localized string to use
  */
 static const char *
-_localize (PolKitHash *translations, const char *untranslated, const char *lang)
+_localize (KitHash *translations, const char *untranslated, const char *lang)
 {
         const char *result;
         char lang2[256];
@@ -360,7 +359,7 @@ _localize (PolKitHash *translations, const char *untranslated, const char *lang)
         }
 
         /* first see if we have the translation */
-        result = (const char *) polkit_hash_lookup (translations, (void *) lang, NULL);
+        result = (const char *) kit_hash_lookup (translations, (void *) lang, NULL);
         if (result != NULL)
                 goto out;
 
@@ -372,7 +371,7 @@ _localize (PolKitHash *translations, const char *untranslated, const char *lang)
                         break;
                 }
         }
-        result = (const char *) polkit_hash_lookup (translations, (void *) lang2, NULL);
+        result = (const char *) kit_hash_lookup (translations, (void *) lang2, NULL);
         if (result != NULL)
                 goto out;
 
@@ -386,9 +385,9 @@ static void
 _end (void *data, const char *el)
 {
         ParserData *pd = data;
-        PolKitList *l;
+        KitList *l;
 
-        p_free (pd->elem_lang);
+        kit_free (pd->elem_lang);
         pd->elem_lang = NULL;
 
         switch (pd->state) {
@@ -425,7 +424,7 @@ _end (void *data, const char *el)
                         }
                 }
 
-                l = polkit_list_prepend (pd->pf->entries, pfe);
+                l = kit_list_prepend (pd->pf->entries, pfe);
                 if (l == NULL) {
                         polkit_policy_file_entry_unref (pfe);
                         goto oom;
@@ -454,7 +453,6 @@ error:
         XML_StopParser (pd->parser, FALSE);
 }
 
-
 /**
  * polkit_policy_file_new:
  * @path: path to file
@@ -473,8 +471,7 @@ polkit_policy_file_new (const char *path, polkit_bool_t load_descriptions, PolKi
         int xml_res;
         char *lang;
 	char *buf;
-	gsize buflen;
-        GError *g_error;
+	size_t buflen;
 
         pf = NULL;
         buf = NULL;
@@ -482,20 +479,24 @@ polkit_policy_file_new (const char *path, polkit_bool_t load_descriptions, PolKi
         /* clear parser data */
         memset (&pd, 0, sizeof (ParserData));
 
-        if (!g_str_has_suffix (path, ".policy")) {
+        if (!kit_str_has_suffix (path, ".policy")) {
                 polkit_error_set_error (error, 
                                         POLKIT_ERROR_POLICY_FILE_INVALID,
                                         "Policy files must have extension .policy; file '%s' doesn't", path);
                 goto error;
         }
 
-        g_error = NULL;
-	if (!g_file_get_contents (path, &buf, &buflen, &g_error)) {
-                polkit_error_set_error (error, POLKIT_ERROR_POLICY_FILE_INVALID,
-                                        "Cannot load PolicyKit policy file at '%s': %s",
-                                        path,
-                                        g_error->message);
-                g_error_free (g_error);
+	if (!kit_file_get_contents (path, &buf, &buflen)) {
+                if (errno == ENOMEM) {
+                        polkit_error_set_error (error, POLKIT_ERROR_OUT_OF_MEMORY,
+                                                "Cannot load PolicyKit policy file at '%s': %s",
+                                                path,
+                                                "No memory for parser");
+                } else {
+                        polkit_error_set_error (error, POLKIT_ERROR_POLICY_FILE_INVALID,
+                                                "Cannot load PolicyKit policy file at '%s': %m",
+                                                path);
+                }
 		goto error;
         }
 
@@ -504,7 +505,7 @@ polkit_policy_file_new (const char *path, polkit_bool_t load_descriptions, PolKi
    TODO: expat appears to leak on certain OOM paths
 */
 #if 0
-        XML_Memory_Handling_Suite memsuite = {p_malloc, p_realloc, p_free};
+        XML_Memory_Handling_Suite memsuite = {p_malloc, p_realloc, kit_free};
         pd.parser = XML_ParserCreate_MM (NULL, &memsuite, NULL);
 #else
         pd.parser = XML_ParserCreate (NULL);
@@ -521,7 +522,7 @@ polkit_policy_file_new (const char *path, polkit_bool_t load_descriptions, PolKi
 	XML_SetElementHandler (pd.parser, _start, _end);
 	XML_SetCharacterDataHandler (pd.parser, _cdata);
 
-        pf = p_new0 (PolKitPolicyFile, 1);
+        pf = kit_new0 (PolKitPolicyFile, 1);
         if (pf == NULL) {
                 polkit_error_set_error (error, POLKIT_ERROR_OUT_OF_MEMORY,
                                         "Cannot load PolicyKit policy file at '%s': No memory for object",
@@ -538,7 +539,7 @@ polkit_policy_file_new (const char *path, polkit_bool_t load_descriptions, PolKi
         lang = getenv ("LANG");
         if (lang != NULL) {
                 int n;
-                pd.lang = p_strdup (lang);
+                pd.lang = kit_strdup (lang);
                 if (pd.lang == NULL) {
                         polkit_error_set_error (error, POLKIT_ERROR_OUT_OF_MEMORY,
                                                 "Cannot load PolicyKit policy file at '%s': No memory for lang",
@@ -576,14 +577,14 @@ polkit_policy_file_new (const char *path, polkit_bool_t load_descriptions, PolKi
 	}
 
 	XML_ParserFree (pd.parser);
-	g_free (buf);
+	kit_free (buf);
         pd_unref_data (&pd);
         return pf;
 error:
         if (pf != NULL)
                 polkit_policy_file_unref (pf);
         pd_unref_data (&pd);
-        g_free (buf);
+        kit_free (buf);
         return NULL;
 }
 
@@ -598,7 +599,7 @@ error:
 PolKitPolicyFile *
 polkit_policy_file_ref (PolKitPolicyFile *policy_file)
 {
-        g_return_val_if_fail (policy_file != NULL, policy_file);
+        kit_return_val_if_fail (policy_file != NULL, policy_file);
         policy_file->refcount++;
         return policy_file;
 }
@@ -614,8 +615,8 @@ polkit_policy_file_ref (PolKitPolicyFile *policy_file)
 void
 polkit_policy_file_unref (PolKitPolicyFile *policy_file)
 {
-        PolKitList *i;
-        g_return_if_fail (policy_file != NULL);
+        KitList *i;
+        kit_return_if_fail (policy_file != NULL);
         policy_file->refcount--;
         if (policy_file->refcount > 0) 
                 return;
@@ -623,8 +624,8 @@ polkit_policy_file_unref (PolKitPolicyFile *policy_file)
                 polkit_policy_file_entry_unref (i->data);
         }
         if (policy_file->entries != NULL)
-                polkit_list_free (policy_file->entries);
-        p_free (policy_file);
+                kit_list_free (policy_file->entries);
+        kit_free (policy_file);
 }
 
 /**
@@ -642,10 +643,10 @@ polkit_policy_file_entry_foreach (PolKitPolicyFile                 *policy_file,
                                   PolKitPolicyFileEntryForeachFunc  cb,
                                   void                              *user_data)
 {
-        PolKitList *i;
+        KitList *i;
 
-        g_return_val_if_fail (policy_file != NULL, FALSE);
-        g_return_val_if_fail (cb != NULL, FALSE);
+        kit_return_val_if_fail (policy_file != NULL, FALSE);
+        kit_return_val_if_fail (cb != NULL, FALSE);
 
         for (i = policy_file->entries; i != NULL; i = i->next) {
                 PolKitPolicyFileEntry *pfe = i->data;
@@ -739,8 +740,8 @@ _run_test (void)
 
         for (n = 0; n < sizeof (invalid_files) / sizeof (char*); n++) {
                 error = NULL;
-                g_assert (polkit_policy_file_new (invalid_files[n], TRUE, &error) == NULL);
-                g_assert (polkit_error_get_error_code (error) == POLKIT_ERROR_OUT_OF_MEMORY ||
+                kit_assert (polkit_policy_file_new (invalid_files[n], TRUE, &error) == NULL);
+                kit_assert (polkit_error_get_error_code (error) == POLKIT_ERROR_OUT_OF_MEMORY ||
                           polkit_error_get_error_code (error) == POLKIT_ERROR_POLICY_FILE_INVALID);
                 polkit_error_free (error);
         }
@@ -782,7 +783,7 @@ _run_test (void)
 
                         error = NULL;
                         if ((pf = polkit_policy_file_new (valid_files[n], load_descriptions, &error)) == NULL) {
-                                g_assert (polkit_error_get_error_code (error) == POLKIT_ERROR_OUT_OF_MEMORY);
+                                kit_assert (polkit_error_get_error_code (error) == POLKIT_ERROR_OUT_OF_MEMORY);
                                 polkit_error_free (error);
                         } else {
 
@@ -793,7 +794,7 @@ _run_test (void)
                                         polkit_policy_file_entry_foreach (pf,
                                                                           _check_pf,
                                                                           &num_passed);
-                                        g_assert (num_passed == 2);
+                                        kit_assert (num_passed == 2);
                                 }
 
                                 polkit_policy_file_ref (pf);
diff --git a/src/polkit/polkit-private.h b/src/polkit/polkit-private.h
index 614e409..35b1f82 100644
--- a/src/polkit/polkit-private.h
+++ b/src/polkit/polkit-private.h
@@ -30,10 +30,9 @@
 #ifndef POLKIT_PRIVATE_H
 #define POLKIT_PRIVATE_H
 
-#include <glib.h>
+#include <kit/kit.h>
 #include <polkit/polkit.h>
-#include <polkit/polkit-memory.h>
-#include <polkit/polkit-hash.h>
+#include <polkit/polkit-debug.h>
 
 /**
  * SECTION:polkit-private
@@ -89,7 +88,7 @@ PolKitPolicyFileEntry *_polkit_policy_file_entry_new   (const char *action_id,
                                                         PolKitResult defaults_allow_any,
                                                         PolKitResult defaults_allow_inactive,
                                                         PolKitResult defaults_allow_active,
-                                                        PolKitHash *annotations);
+                                                        KitHash *annotations);
 
 
 #ifdef POLKIT_AUTHDB_DUMMY
@@ -103,7 +102,7 @@ struct _PolKitAuthorizationDB
 {
         /*< private >*/
         int refcount;
-        GHashTable *uid_to_authlist;
+        KitHash *uid_to_authlist;
 };
 
 #endif
diff --git a/src/polkit/polkit-result.c b/src/polkit/polkit-result.c
index eee04c0..6bd05c7 100644
--- a/src/polkit/polkit-result.c
+++ b/src/polkit/polkit-result.c
@@ -44,10 +44,9 @@
 #include <unistd.h>
 #include <errno.h>
 
-#include <glib.h>
 #include "polkit-result.h"
 #include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
 
 
 static const struct {
@@ -85,7 +84,7 @@ const char *
 polkit_result_to_string_representation (PolKitResult result)
 {
         if (result < 0 || result >= POLKIT_RESULT_N_RESULTS) {
-                g_warning ("The passed result code, %d, is not valid", result);
+                kit_warning ("The passed result code, %d, is not valid", result);
                 return NULL;
         }
 
@@ -107,7 +106,7 @@ polkit_result_from_string_representation (const char *string, PolKitResult *out_
 {
         int n;
 
-        g_return_val_if_fail (out_result != NULL, FALSE);
+        kit_return_val_if_fail (out_result != NULL, FALSE);
 
         for (n = 0; n < POLKIT_RESULT_N_RESULTS; n++) {
                 if (strcmp (mapping[n].str, string) == 0) {
@@ -130,13 +129,13 @@ _run_test (void)
         PolKitResult m;
 
         for (n = 0; n < POLKIT_RESULT_N_RESULTS; n++) {
-                g_assert (polkit_result_from_string_representation (polkit_result_to_string_representation (n), &m) && n== m);
+                kit_assert (polkit_result_from_string_representation (polkit_result_to_string_representation (n), &m) && n== m);
         }
 
-        g_assert (polkit_result_to_string_representation ((PolKitResult) -1) == NULL);
-        g_assert (polkit_result_to_string_representation (POLKIT_RESULT_N_RESULTS) == NULL);
+        kit_assert (polkit_result_to_string_representation ((PolKitResult) -1) == NULL);
+        kit_assert (polkit_result_to_string_representation (POLKIT_RESULT_N_RESULTS) == NULL);
 
-        g_assert (! polkit_result_from_string_representation ("non-exiting-result-id", &m));
+        kit_assert (! polkit_result_from_string_representation ("non-exiting-result-id", &m));
 
 
         return TRUE;
diff --git a/src/polkit/polkit-seat.c b/src/polkit/polkit-seat.c
index 0056da9..69d8325 100644
--- a/src/polkit/polkit-seat.c
+++ b/src/polkit/polkit-seat.c
@@ -36,12 +36,11 @@
 #include <unistd.h>
 #include <errno.h>
 
-#include <glib.h>
 #include "polkit-debug.h"
 #include "polkit-seat.h"
 #include "polkit-utils.h"
 #include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
 
 /**
  * SECTION:polkit-seat
@@ -74,7 +73,7 @@ PolKitSeat *
 polkit_seat_new (void)
 {
         PolKitSeat *seat;
-        seat = p_new0 (PolKitSeat, 1);
+        seat = kit_new0 (PolKitSeat, 1);
         if (seat == NULL)
                 goto out;
         seat->refcount = 1;
@@ -93,7 +92,7 @@ out:
 PolKitSeat *
 polkit_seat_ref (PolKitSeat *seat)
 {
-        g_return_val_if_fail (seat != NULL, seat);
+        kit_return_val_if_fail (seat != NULL, seat);
         seat->refcount++;
         return seat;
 }
@@ -109,12 +108,12 @@ polkit_seat_ref (PolKitSeat *seat)
 void
 polkit_seat_unref (PolKitSeat *seat)
 {
-        g_return_if_fail (seat != NULL);
+        kit_return_if_fail (seat != NULL);
         seat->refcount--;
         if (seat->refcount > 0) 
                 return;
-        p_free (seat->ck_objref);
-        p_free (seat);
+        kit_free (seat->ck_objref);
+        kit_free (seat);
 }
 
 /**
@@ -129,11 +128,11 @@ polkit_seat_unref (PolKitSeat *seat)
 polkit_bool_t
 polkit_seat_set_ck_objref (PolKitSeat *seat, const char *ck_objref)
 {
-        g_return_val_if_fail (seat != NULL, FALSE);
-        g_return_val_if_fail (_pk_validate_identifier (ck_objref), FALSE);
+        kit_return_val_if_fail (seat != NULL, FALSE);
+        kit_return_val_if_fail (_pk_validate_identifier (ck_objref), FALSE);
         if (seat->ck_objref != NULL)
-                p_free (seat->ck_objref);
-        seat->ck_objref = p_strdup (ck_objref);
+                kit_free (seat->ck_objref);
+        seat->ck_objref = kit_strdup (ck_objref);
         if (seat->ck_objref == NULL)
                 return FALSE;
         else
@@ -152,8 +151,8 @@ polkit_seat_set_ck_objref (PolKitSeat *seat, const char *ck_objref)
 polkit_bool_t
 polkit_seat_get_ck_objref (PolKitSeat *seat, char **out_ck_objref)
 {
-        g_return_val_if_fail (seat != NULL, FALSE);
-        g_return_val_if_fail (out_ck_objref != NULL, FALSE);
+        kit_return_val_if_fail (seat != NULL, FALSE);
+        kit_return_val_if_fail (out_ck_objref != NULL, FALSE);
         *out_ck_objref = seat->ck_objref;
         return TRUE;
 }
@@ -167,7 +166,7 @@ polkit_seat_get_ck_objref (PolKitSeat *seat, char **out_ck_objref)
 void
 polkit_seat_debug (PolKitSeat *seat)
 {
-        g_return_if_fail (seat != NULL);
+        kit_return_if_fail (seat != NULL);
         _pk_debug ("PolKitSeat: refcount=%d objpath=%s", seat->refcount, seat->ck_objref);
 }
 
@@ -182,8 +181,8 @@ polkit_seat_debug (PolKitSeat *seat)
 polkit_bool_t
 polkit_seat_validate (PolKitSeat *seat)
 {
-        g_return_val_if_fail (seat != NULL, FALSE);
-        g_return_val_if_fail (seat->ck_objref != NULL, FALSE);
+        kit_return_val_if_fail (seat != NULL, FALSE);
+        kit_return_val_if_fail (seat->ck_objref != NULL, FALSE);
         return TRUE;
 }
 
@@ -202,17 +201,17 @@ _run_test (void)
                 if (! polkit_seat_set_ck_objref (s, "/someseat")) {
                         /* OOM */
                 } else {
-                        g_assert (polkit_seat_get_ck_objref (s, &str) && strcmp (str, "/someseat") == 0);
-                        g_assert (polkit_seat_validate (s));
+                        kit_assert (polkit_seat_get_ck_objref (s, &str) && strcmp (str, "/someseat") == 0);
+                        kit_assert (polkit_seat_validate (s));
                         polkit_seat_ref (s);
-                        g_assert (polkit_seat_validate (s));
+                        kit_assert (polkit_seat_validate (s));
                         polkit_seat_unref (s);
-                        g_assert (polkit_seat_validate (s));
+                        kit_assert (polkit_seat_validate (s));
                         polkit_seat_debug (s);
                         if (! polkit_seat_set_ck_objref (s, "/someseat2")) {
                                 /* OOM */
                         } else {
-                                g_assert (polkit_seat_get_ck_objref (s, &str) && strcmp (str, "/someseat2") == 0);
+                                kit_assert (polkit_seat_get_ck_objref (s, &str) && strcmp (str, "/someseat2") == 0);
                         }
                 }
                 polkit_seat_unref (s);
diff --git a/src/polkit/polkit-session.c b/src/polkit/polkit-session.c
index 3c0ebd2..189e11f 100644
--- a/src/polkit/polkit-session.c
+++ b/src/polkit/polkit-session.c
@@ -36,12 +36,11 @@
 #include <unistd.h>
 #include <errno.h>
 
-#include <glib.h>
 #include "polkit-debug.h"
 #include "polkit-session.h"
 #include "polkit-utils.h"
 #include "polkit-test.h"
-#include "polkit-memory.h"
+#include "polkit-private.h"
 
 /**
  * SECTION:polkit-session
@@ -79,7 +78,7 @@ PolKitSession *
 polkit_session_new (void)
 {
         PolKitSession *session;
-        session = p_new0 (PolKitSession, 1);
+        session = kit_new0 (PolKitSession, 1);
         if (session == NULL)
                 goto out;
         session->refcount = 1;
@@ -98,7 +97,7 @@ out:
 PolKitSession *
 polkit_session_ref (PolKitSession *session)
 {
-        g_return_val_if_fail (session != NULL, session);
+        kit_return_val_if_fail (session != NULL, session);
         session->refcount++;
         return session;
 }
@@ -115,15 +114,15 @@ polkit_session_ref (PolKitSession *session)
 void 
 polkit_session_unref (PolKitSession *session)
 {
-        g_return_if_fail (session != NULL);
+        kit_return_if_fail (session != NULL);
         session->refcount--;
         if (session->refcount > 0) 
                 return;
-        p_free (session->ck_objref);
-        p_free (session->remote_host);
+        kit_free (session->ck_objref);
+        kit_free (session->remote_host);
         if (session->seat != NULL)
                 polkit_seat_unref (session->seat);
-        p_free (session);
+        kit_free (session);
 }
 
 /**
@@ -138,7 +137,7 @@ polkit_session_unref (PolKitSession *session)
 polkit_bool_t
 polkit_session_set_uid (PolKitSession *session, uid_t uid)
 {
-        g_return_val_if_fail (session != NULL, FALSE);
+        kit_return_val_if_fail (session != NULL, FALSE);
         session->uid = uid;
         return TRUE;
 }
@@ -155,11 +154,11 @@ polkit_session_set_uid (PolKitSession *session, uid_t uid)
 polkit_bool_t
 polkit_session_set_ck_objref (PolKitSession *session, const char *ck_objref)
 {
-        g_return_val_if_fail (session != NULL, FALSE);
-        g_return_val_if_fail (_pk_validate_identifier (ck_objref), FALSE);
+        kit_return_val_if_fail (session != NULL, FALSE);
+        kit_return_val_if_fail (_pk_validate_identifier (ck_objref), FALSE);
         if (session->ck_objref != NULL)
-                p_free (session->ck_objref);
-        session->ck_objref = p_strdup (ck_objref);
+                kit_free (session->ck_objref);
+        session->ck_objref = kit_strdup (ck_objref);
         if (session->ck_objref == NULL)
                 return FALSE;
         else
@@ -178,7 +177,7 @@ polkit_session_set_ck_objref (PolKitSession *session, const char *ck_objref)
 polkit_bool_t
 polkit_session_set_ck_is_active (PolKitSession *session, polkit_bool_t is_active)
 {
-        g_return_val_if_fail (session != NULL, FALSE);
+        kit_return_val_if_fail (session != NULL, FALSE);
         session->is_active = is_active;
         return TRUE;
 }
@@ -195,7 +194,7 @@ polkit_session_set_ck_is_active (PolKitSession *session, polkit_bool_t is_active
 polkit_bool_t
 polkit_session_set_ck_is_local (PolKitSession *session, polkit_bool_t is_local)
 {
-        g_return_val_if_fail (session != NULL, FALSE);
+        kit_return_val_if_fail (session != NULL, FALSE);
         session->is_local = is_local;
         return TRUE;
 }
@@ -214,12 +213,12 @@ polkit_session_set_ck_is_local (PolKitSession *session, polkit_bool_t is_local)
 polkit_bool_t
 polkit_session_set_ck_remote_host (PolKitSession *session, const char *remote_host)
 {
-        g_return_val_if_fail (session != NULL, FALSE);
+        kit_return_val_if_fail (session != NULL, FALSE);
         /* TODO: FIXME: probably need to allow a lot more here */
-        g_return_val_if_fail (_pk_validate_identifier (remote_host), FALSE);
+        kit_return_val_if_fail (_pk_validate_identifier (remote_host), FALSE);
         if (session->remote_host != NULL)
-                p_free (session->remote_host);
-        session->remote_host = p_strdup (remote_host);
+                kit_free (session->remote_host);
+        session->remote_host = kit_strdup (remote_host);
         if (session->remote_host == NULL)
                 return FALSE;
         else
@@ -241,8 +240,8 @@ polkit_session_set_ck_remote_host (PolKitSession *session, const char *remote_ho
 polkit_bool_t
 polkit_session_set_seat (PolKitSession *session, PolKitSeat *seat)
 {
-        g_return_val_if_fail (session != NULL, FALSE);
-        g_return_val_if_fail (polkit_seat_validate (seat), FALSE);
+        kit_return_val_if_fail (session != NULL, FALSE);
+        kit_return_val_if_fail (polkit_seat_validate (seat), FALSE);
         if (session->seat != NULL)
                 polkit_seat_unref (session->seat);
         session->seat = seat != NULL ? polkit_seat_ref (seat) : NULL;
@@ -261,8 +260,8 @@ polkit_session_set_seat (PolKitSession *session, PolKitSeat *seat)
 polkit_bool_t
 polkit_session_get_uid (PolKitSession *session, uid_t *out_uid)
 {
-        g_return_val_if_fail (session != NULL, FALSE);
-        g_return_val_if_fail (out_uid != NULL, FALSE);
+        kit_return_val_if_fail (session != NULL, FALSE);
+        kit_return_val_if_fail (out_uid != NULL, FALSE);
         *out_uid = session->uid;
         return TRUE;
 }
@@ -279,8 +278,8 @@ polkit_session_get_uid (PolKitSession *session, uid_t *out_uid)
 polkit_bool_t
 polkit_session_get_ck_objref (PolKitSession *session, char **out_ck_objref)
 {
-        g_return_val_if_fail (session != NULL, FALSE);
-        g_return_val_if_fail (out_ck_objref != NULL, FALSE);
+        kit_return_val_if_fail (session != NULL, FALSE);
+        kit_return_val_if_fail (out_ck_objref != NULL, FALSE);
         *out_ck_objref = session->ck_objref;
         return TRUE;
 }
@@ -297,8 +296,8 @@ polkit_session_get_ck_objref (PolKitSession *session, char **out_ck_objref)
 polkit_bool_t
 polkit_session_get_ck_is_active (PolKitSession *session, polkit_bool_t *out_is_active)
 {
-        g_return_val_if_fail (session != NULL, FALSE);
-        g_return_val_if_fail (out_is_active != NULL, FALSE);
+        kit_return_val_if_fail (session != NULL, FALSE);
+        kit_return_val_if_fail (out_is_active != NULL, FALSE);
         *out_is_active = session->is_active;
         return TRUE;
 }
@@ -315,8 +314,8 @@ polkit_session_get_ck_is_active (PolKitSession *session, polkit_bool_t *out_is_a
 polkit_bool_t
 polkit_session_get_ck_is_local (PolKitSession *session, polkit_bool_t *out_is_local)
 {
-        g_return_val_if_fail (session != NULL, FALSE);
-        g_return_val_if_fail (out_is_local != NULL, FALSE);
+        kit_return_val_if_fail (session != NULL, FALSE);
+        kit_return_val_if_fail (out_is_local != NULL, FALSE);
         *out_is_local = session->is_local;
         return TRUE;
 }
@@ -335,8 +334,8 @@ polkit_session_get_ck_is_local (PolKitSession *session, polkit_bool_t *out_is_lo
 polkit_bool_t
 polkit_session_get_ck_remote_host (PolKitSession *session, char **out_remote_host)
 {
-        g_return_val_if_fail (session != NULL, FALSE);
-        g_return_val_if_fail (out_remote_host != NULL, FALSE);
+        kit_return_val_if_fail (session != NULL, FALSE);
+        kit_return_val_if_fail (out_remote_host != NULL, FALSE);
         *out_remote_host = session->remote_host;
         return TRUE;
 }
@@ -354,8 +353,8 @@ polkit_session_get_ck_remote_host (PolKitSession *session, char **out_remote_hos
 polkit_bool_t
 polkit_session_get_seat (PolKitSession *session, PolKitSeat **out_seat)
 {
-        g_return_val_if_fail (session != NULL, FALSE);
-        g_return_val_if_fail (out_seat != NULL, FALSE);
+        kit_return_val_if_fail (session != NULL, FALSE);
+        kit_return_val_if_fail (out_seat != NULL, FALSE);
         *out_seat = session->seat;
         return TRUE;
 }
@@ -369,7 +368,7 @@ polkit_session_get_seat (PolKitSession *session, PolKitSeat **out_seat)
 void
 polkit_session_debug (PolKitSession *session)
 {
-        g_return_if_fail (session != NULL);
+        kit_return_if_fail (session != NULL);
         _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);
@@ -390,7 +389,7 @@ polkit_bool_t
 polkit_session_validate (PolKitSession *session)
 {
         polkit_bool_t ret;
-        g_return_val_if_fail (session != NULL, FALSE);
+        kit_return_val_if_fail (session != NULL, FALSE);
 
         ret = FALSE;
         if (session->is_local) {
@@ -424,62 +423,62 @@ _run_test (void)
                 if (! polkit_session_set_ck_objref (s, "/somesession")) {
                         /* OOM */
                 } else {
-                        g_assert (polkit_session_get_ck_objref (s, &str) && strcmp (str, "/somesession") == 0);
+                        kit_assert (polkit_session_get_ck_objref (s, &str) && strcmp (str, "/somesession") == 0);
                         polkit_session_ref (s);
                         polkit_session_unref (s);
                         polkit_session_debug (s);
                         if (! polkit_session_set_ck_objref (s, "/somesession2")) {
                                 /* OOM */
                         } else {
-                                g_assert (polkit_session_get_ck_objref (s, &str) && strcmp (str, "/somesession2") == 0);
+                                kit_assert (polkit_session_get_ck_objref (s, &str) && strcmp (str, "/somesession2") == 0);
                         }
 
                         if ((seat = polkit_seat_new ()) != NULL) {
                                 if (polkit_seat_set_ck_objref (seat, "/someseat")) {
-                                        g_assert (polkit_session_set_seat (s, seat));
-                                        g_assert (polkit_session_get_seat (s, &seat2) && seat == seat2);
+                                        kit_assert (polkit_session_set_seat (s, seat));
+                                        kit_assert (polkit_session_get_seat (s, &seat2) && seat == seat2);
                                 }
                                 polkit_seat_unref (seat);
                                 if ((seat = polkit_seat_new ()) != NULL) {
                                         if (polkit_seat_set_ck_objref (seat, "/someseat2")) {
-                                                g_assert (polkit_session_set_seat (s, seat));
-                                                g_assert (polkit_session_get_seat (s, &seat2) && seat == seat2);
+                                                kit_assert (polkit_session_set_seat (s, seat));
+                                                kit_assert (polkit_session_get_seat (s, &seat2) && seat == seat2);
                                         }
                                         polkit_seat_unref (seat);
                                 }
                         }
 
-                        g_assert (polkit_session_set_uid (s, 0));
-                        g_assert (polkit_session_get_uid (s, &uid) && uid == 0);
-                        g_assert (polkit_session_set_ck_is_active (s, TRUE));
-                        g_assert (polkit_session_get_ck_is_active (s, &b) && b == TRUE);
-                        g_assert (polkit_session_set_ck_is_local (s, TRUE));
-                        g_assert (polkit_session_get_ck_is_local (s, &b) && b == TRUE);
-                        g_assert (polkit_session_validate (s));
-
-                        g_assert (polkit_session_set_uid (s, 500));
-                        g_assert (polkit_session_get_uid (s, &uid) && uid == 500);
-                        g_assert (polkit_session_set_ck_is_active (s, FALSE));
-                        g_assert (polkit_session_get_ck_is_active (s, &b) && b == FALSE);
-                        g_assert (polkit_session_set_ck_is_local (s, FALSE));
-                        g_assert (polkit_session_get_ck_is_local (s, &b) && b == FALSE);
+                        kit_assert (polkit_session_set_uid (s, 0));
+                        kit_assert (polkit_session_get_uid (s, &uid) && uid == 0);
+                        kit_assert (polkit_session_set_ck_is_active (s, TRUE));
+                        kit_assert (polkit_session_get_ck_is_active (s, &b) && b == TRUE);
+                        kit_assert (polkit_session_set_ck_is_local (s, TRUE));
+                        kit_assert (polkit_session_get_ck_is_local (s, &b) && b == TRUE);
+                        kit_assert (polkit_session_validate (s));
+
+                        kit_assert (polkit_session_set_uid (s, 500));
+                        kit_assert (polkit_session_get_uid (s, &uid) && uid == 500);
+                        kit_assert (polkit_session_set_ck_is_active (s, FALSE));
+                        kit_assert (polkit_session_get_ck_is_active (s, &b) && b == FALSE);
+                        kit_assert (polkit_session_set_ck_is_local (s, FALSE));
+                        kit_assert (polkit_session_get_ck_is_local (s, &b) && b == FALSE);
 
                         /* not valid because remote host is not set.. */
-                        g_assert (!polkit_session_validate (s));
+                        kit_assert (!polkit_session_validate (s));
 
 
                         if (polkit_session_set_ck_remote_host (s, "somehost.com")) {
-                                g_assert (polkit_session_get_ck_remote_host (s, &str) && strcmp (str, "somehost.com") == 0);
-                                g_assert (polkit_session_validate (s));
+                                kit_assert (polkit_session_get_ck_remote_host (s, &str) && strcmp (str, "somehost.com") == 0);
+                                kit_assert (polkit_session_validate (s));
 
                                 /* not valid because remote host is set and local==TRUE */
-                                g_assert (polkit_session_set_ck_is_local (s, TRUE));
-                                g_assert (!polkit_session_validate (s));
-                                g_assert (polkit_session_set_ck_is_local (s, FALSE));
+                                kit_assert (polkit_session_set_ck_is_local (s, TRUE));
+                                kit_assert (!polkit_session_validate (s));
+                                kit_assert (polkit_session_set_ck_is_local (s, FALSE));
 
                                 if (polkit_session_set_ck_remote_host (s, "somehost2.com")) {
-                                        g_assert (polkit_session_get_ck_remote_host (s, &str) && strcmp (str, "somehost2.com") == 0);
-                                        g_assert (polkit_session_validate (s));
+                                        kit_assert (polkit_session_get_ck_remote_host (s, &str) && strcmp (str, "somehost2.com") == 0);
+                                        kit_assert (polkit_session_validate (s));
                                 }
                                 polkit_session_debug (s);
                         }
diff --git a/src/polkit/polkit-sysdeps.c b/src/polkit/polkit-sysdeps.c
index 1a8f15d..cebbc92 100644
--- a/src/polkit/polkit-sysdeps.c
+++ b/src/polkit/polkit-sysdeps.c
@@ -39,7 +39,9 @@
 #include <syslog.h>
 
 #include <glib.h>
+
 #include "polkit-sysdeps.h"
+#include "polkit-private.h"
 
 
 /**
@@ -68,9 +70,8 @@ polkit_sysdeps_get_start_time_for_pid (pid_t pid)
 {
         char *filename;
         char *contents;
-        gsize length;
+        size_t length;
         polkit_uint64_t start_time;
-        GError *error = NULL;
         char **tokens;
         char *p;
         char *endp;
@@ -78,15 +79,14 @@ polkit_sysdeps_get_start_time_for_pid (pid_t pid)
         start_time = 0;
         contents = NULL;
 
-        filename = g_strdup_printf ("/proc/%d/stat", pid);
+        filename = kit_strdup_printf ("/proc/%d/stat", pid);
         if (filename == NULL) {
-                fprintf (stderr, "Out of memory\n");
+                kit_warning ("Out of memory");
                 goto out;
         }
 
-        if (!g_file_get_contents (filename, &contents, &length, &error)) {
+        if (!kit_file_get_contents (filename, &contents, &length)) {
                 //fprintf (stderr, "Cannot get contents of '%s': %s\n", filename, error->message);
-                g_error_free (error);
                 goto out;
         }
 
@@ -114,8 +114,8 @@ polkit_sysdeps_get_start_time_for_pid (pid_t pid)
         g_strfreev (tokens);
 
 out:
-        g_free (filename);
-        g_free (contents);
+        kit_free (filename);
+        kit_free (contents);
         return start_time;
 }
 
@@ -151,7 +151,7 @@ polkit_sysdeps_get_exe_for_pid (pid_t pid, char *out_buf, size_t buf_size)
         if (ret == -1) {
                 goto out;
         }
-        g_assert (ret >= 0 && ret < (int) buf_size - 1);
+        kit_assert (ret >= 0 && ret < (int) buf_size - 1);
         out_buf[ret] = '\0';
 
 out:
diff --git a/src/polkit/polkit-test.c b/src/polkit/polkit-test.c
index 997a9bd..5760d66 100644
--- a/src/polkit/polkit-test.c
+++ b/src/polkit/polkit-test.c
@@ -26,7 +26,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <polkit/polkit-test.h>
-#include <polkit/polkit-memory.h>
+#include <polkit/polkit-private.h>
 #include <polkit/polkit-private.h>
 
 #define MAX_TESTS 64
@@ -39,8 +39,6 @@
  */
 
 static PolKitTest *tests[] = {
-        &_test_list,
-        &_test_hash,
         &_test_action,
         &_test_error,
         &_test_result,
@@ -53,6 +51,7 @@ static PolKitTest *tests[] = {
         &_test_policy_cache,
         &_test_authorization_constraint,
         &_test_authorization,
+        &_test_authorization_db,
 };
 
 int 
@@ -73,7 +72,7 @@ main (int argc, char *argv[])
                 int delta;
                 PolKitTest *test = tests[n];
 
-                _polkit_memory_reset ();
+                _kit_memory_reset ();
 
                 if (test->setup != NULL)
                         test->setup ();
@@ -85,10 +84,10 @@ main (int argc, char *argv[])
                         goto test_done;
                 }
 
-                total_allocs = _polkit_memory_get_total_allocations ();
+                total_allocs = _kit_memory_get_total_allocations ();
                 printf ("  Unit test made %d allocations in total\n", total_allocs);
                 
-                delta = _polkit_memory_get_current_allocations ();
+                delta = _kit_memory_get_current_allocations ();
                 if (delta != 0) {
                         printf ("  Unit test leaked %d allocations\n", delta);
                         ret = 1;
@@ -97,8 +96,8 @@ main (int argc, char *argv[])
                 for (m = 0; m < total_allocs; m++) {
                         printf ("  Failing allocation %d of %d\n", m + 1, total_allocs);
                         
-                        _polkit_memory_reset ();
-                        _polkit_memory_fail_nth_alloc (m);
+                        _kit_memory_reset ();
+                        _kit_memory_fail_nth_alloc (m);
                         
                         if (!test->run ()) {
                                 printf ("  Failed\n");
@@ -106,7 +105,7 @@ main (int argc, char *argv[])
                                 continue;
                         }
                         
-                        delta = _polkit_memory_get_current_allocations ();
+                        delta = _kit_memory_get_current_allocations ();
                         if (delta != 0) {
                                 printf ("  Unit test leaked %d allocations\n", delta);
                                 ret = 1;
diff --git a/src/polkit/polkit-test.h b/src/polkit/polkit-test.h
index 0e3844f..4c1d3a2 100644
--- a/src/polkit/polkit-test.h
+++ b/src/polkit/polkit-test.h
@@ -58,12 +58,11 @@ extern PolKitTest _test_session;
 extern PolKitTest _test_caller;
 extern PolKitTest _test_policy_default;
 extern PolKitTest _test_policy_file_entry;
-extern PolKitTest _test_hash;
 extern PolKitTest _test_policy_file;
-extern PolKitTest _test_list;
 extern PolKitTest _test_policy_cache;
 extern PolKitTest _test_authorization_constraint;
 extern PolKitTest _test_authorization;
+extern PolKitTest _test_authorization_db;
 
 POLKIT_END_DECLS
 
diff --git a/src/polkit/polkit-utils.c b/src/polkit/polkit-utils.c
index 9b51a53..199ca7b 100644
--- a/src/polkit/polkit-utils.c
+++ b/src/polkit/polkit-utils.c
@@ -32,11 +32,11 @@
 #include <stdlib.h>
 #include <sys/time.h>
 #include <time.h>
-#include <glib.h>
 #include <string.h>
 
 #include "polkit-utils.h"
 #include "polkit-debug.h"
+#include "polkit-private.h"
 
 /**
  * SECTION:polkit-utils
@@ -61,7 +61,7 @@ _pk_validate_identifier (const char *identifier)
         unsigned int n;
         polkit_bool_t ret;
 
-        g_return_val_if_fail (identifier != NULL, FALSE);
+        kit_return_val_if_fail (identifier != NULL, FALSE);
 
         ret = FALSE;
         for (n = 0; identifier[n] != '\0'; n++) {
@@ -130,12 +130,12 @@ _pk_validate_unique_bus_name (const char *unique_bus_name)
                 ++s;
                 while (s != end) {
                         if (*s == '.') {
-                                if (G_UNLIKELY ((s + 1) == end))
+                                if ((s + 1) == end)
                                         goto error;
-                                if (G_UNLIKELY (!VALID_BUS_NAME_CHARACTER (*(s + 1))))
+                                if (!VALID_BUS_NAME_CHARACTER (*(s + 1)))
                                         goto error;
                                 ++s; /* we just validated the next char, so skip two */
-                        } else if (G_UNLIKELY (!VALID_BUS_NAME_CHARACTER (*s))) {
+                        } else if (!VALID_BUS_NAME_CHARACTER (*s)) {
                                 goto error;
                         }
                         ++s;
diff --git a/src/polkit/polkit.h b/src/polkit/polkit.h
index 0836d4c..0a929a5 100644
--- a/src/polkit/polkit.h
+++ b/src/polkit/polkit.h
@@ -28,8 +28,6 @@
 
 #define _POLKIT_INSIDE_POLKIT_H 1
 #include <polkit/polkit-types.h>
-#include <polkit/polkit-memory.h>
-#include <polkit/polkit-hash.h>
 #include <polkit/polkit-sysdeps.h>
 #include <polkit/polkit-error.h>
 #include <polkit/polkit-result.h>


More information about the hal-commit mailing list