<xi:include href="xml/kit-list.xml"/>
<xi:include href="xml/kit-hash.xml"/>
<xi:include href="xml/kit-file.xml"/>
+ <xi:include href="xml/kit-spawn.xml"/>
</reference>
<reference id="ref-core">
kit-list.h kit-list.c \
kit-hash.h kit-hash.c \
kit-file.h kit-file.c \
+ kit-spawn.h kit-spawn.c \
kit-message.h kit-message.c \
$(NULL)
return n;
}
+/**
+ * kit_str_append:
+ * @s: either %NULL or a string previously allocated on the heap
+ * @s2: string to append
+ *
+ * Append a string to an existing string.
+ *
+ * Returns: %NULL on OOM or the new string; possibly at the same
+ * location as @s.
+ */
+char *
+kit_str_append (char *s, const char *s2)
+{
+ char *p;
+ size_t s_len;
+ size_t s2_len;
+
+ kit_return_val_if_fail (s2 != NULL, NULL);
+
+ if (s != NULL)
+ s_len = strlen (s);
+ else
+ s_len = 0;
+ s2_len = strlen (s2);
+ p = (char *) kit_realloc ((void *) s, s_len + s2_len + 1);
+ if (p == NULL)
+ goto oom;
+ s = p;
+ memcpy ((void *) (s + s_len), s2, s2_len);
+ s[s_len + s2_len] = '\0';
+
+ return s;
+oom:
+ return NULL;
+}
+
#ifdef KIT_BUILD_TESTS
{
char str[] = "Hello world";
char *p;
+ char *p2;
char **tokens;
size_t num_tokens;
kit_strfreev (tokens);
}
+ if ((p = kit_strdup ("foobar")) != NULL) {
+ if ((p2 = kit_str_append (p, "_cool")) != NULL) {
+ p = p2;
+
+ kit_assert (strcmp (p, "foobar_cool") == 0);
+ }
+
+ kit_free (p);
+ }
+
+ if ((p = kit_str_append (NULL, "baz")) != NULL) {
+ kit_assert (strcmp (p, "baz") == 0);
+ kit_free (p);
+ }
+
+
return TRUE;
}
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);
+char *kit_str_append (char *s, const char *s2);
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);
*/
static KitTest *tests[] = {
+ &_test_message,
&_test_memory,
&_test_string,
&_test_list,
&_test_hash,
&_test_file,
- &_test_message,
+ &_test_spawn,
};
int
extern KitTest _test_hash;
extern KitTest _test_list;
extern KitTest _test_file;
+extern KitTest _test_spawn;
extern KitTest _test_message;
KIT_END_DECLS
#include <kit/kit-list.h>
#include <kit/kit-hash.h>
#include <kit/kit-file.h>
+#include <kit/kit-spawn.h>
#include <kit/kit-message.h>
#undef _KIT_INSIDE_KIT_H
/* PolKitAuthorizationDB structure is defined in polkit/polkit-private.h */
static void
-_free_authlist (GSList *authlist)
+_free_authlist (KitList *authlist)
{
if (authlist != NULL) {
- g_slist_foreach (authlist, (GFunc) polkit_authorization_unref, NULL);
- g_slist_free (authlist);
+ kit_list_foreach (authlist, (KitListForeachFunc) polkit_authorization_unref, NULL);
+ kit_list_free (authlist);
}
}
{
PolKitAuthorizationDB *authdb;
- authdb = g_new0 (PolKitAuthorizationDB, 1);
+ authdb = kit_new0 (PolKitAuthorizationDB, 1);
+ if (authdb == NULL)
+ goto oom;
authdb->refcount = 1;
/* set up the hashtable */
_polkit_authorization_db_invalidate_cache (authdb);
+oom:
return authdb;
}
if (authdb->refcount > 0)
return;
kit_hash_unref (authdb->uid_to_authlist);
- g_free (authdb);
+ kit_free (authdb);
}
/**
if (ret != NULL)
goto out;
- helper_argv[1] = g_strdup_printf ("%d", uid);
+ helper_argv[1] = kit_strdup_printf ("%d", uid);
/* we need to do this through a setgid polkituser helper
* because the auth file is readable only for uid 0 and gid
kit_hash_insert (authdb->uid_to_authlist, (void *) uid, ret);
out:
- g_free (helper_argv[1]);
- g_free (standard_output);
+ kit_free (helper_argv[1]);
+ kit_free (standard_output);
return ret;
}
helper_argv[1] = (char *) auth_file_entry;
helper_argv[2] = "uid";
- helper_argv[3] = g_strdup_printf ("%d", polkit_authorization_get_uid (auth));
+ helper_argv[3] = kit_strdup_printf ("%d", polkit_authorization_get_uid (auth));
g_error = NULL;
if (!g_spawn_sync (NULL, /* const gchar *working_directory */
}
out:
- g_free (helper_argv[3]);
+ kit_free (helper_argv[3]);
return ret;
}
#include <unistd.h>
#include <errno.h>
-#include <glib.h>
-
#include "polkit-debug.h"
#include "polkit-authorization.h"
#include "polkit-utils.h"
_polkit_authorization_new_for_uid (const char *entry_in_auth_file, uid_t uid)
{
char **t;
- guint num_t;
+ size_t num_t;
char *ep;
PolKitAuthorization *auth;
int n;
auth->uid = uid;
- t = g_strsplit (entry_in_auth_file, ":", 0);
- num_t = g_strv_length (t);
+ t = kit_strsplit (entry_in_auth_file, ':', &num_t);
+ if (t == NULL)
+ goto oom;
/*
* pid:
goto error;
}
- g_strfreev (t);
+ kit_strfreev (t);
return auth;
error:
if (auth != NULL)
polkit_authorization_unref (auth);
if (t != NULL)
- g_strfreev (t);
+ kit_strfreev (t);
return NULL;
}
#include <expat.h>
-#include <glib.h>
#include "polkit-config.h"
#include "polkit-debug.h"
#include "polkit-error.h"
} data;
- GSList *children;
+ KitList *children;
};
config_node_new (void)
{
ConfigNode *node;
- node = g_new0 (ConfigNode, 1);
+ node = kit_new0 (ConfigNode, 1);
return node;
}
static void
config_node_dump_real (ConfigNode *node, unsigned int indent)
{
- GSList *i;
+ KitList *i;
unsigned int n;
char buf[128];
break;
}
- for (i = node->children; i != NULL; i = g_slist_next (i)) {
+ for (i = node->children; i != NULL; i = i->next) {
ConfigNode *child = i->data;
config_node_dump_real (child, indent + 2);
}
static void
config_node_unref (ConfigNode *node)
{
- GSList *i;
+ KitList *i;
switch (node->node_type) {
case NODE_TYPE_NOP:
case NODE_TYPE_TOP:
break;
case NODE_TYPE_MATCH:
- g_free (node->data.node_match.data);
+ kit_free (node->data.node_match.data);
regfree (&(node->data.node_match.preq));
break;
case NODE_TYPE_RETURN:
break;
case NODE_TYPE_DEFINE_ADMIN_AUTH:
- g_free (node->data.node_define_admin_auth.data);
+ kit_free (node->data.node_define_admin_auth.data);
break;
}
- for (i = node->children; i != NULL; i = g_slist_next (i)) {
+ for (i = node->children; i != NULL; i = i->next) {
ConfigNode *child = i->data;
config_node_unref (child);
}
- g_slist_free (node->children);
- g_free (node);
+ kit_list_free (node->children);
+ kit_free (node);
}
static void
goto error;
}
- node->data.node_match.data = g_strdup (attr[1]);
+ node->data.node_match.data = kit_strdup (attr[1]);
if (regcomp (&(node->data.node_match.preq), node->data.node_match.data, REG_NOSUB|REG_EXTENDED) != 0) {
_pk_debug ("Invalid expression '%s'", node->data.node_match.data);
goto error;
goto error;
}
- node->data.node_define_admin_auth.data = g_strdup (attr[1]);
+ node->data.node_define_admin_auth.data = kit_strdup (attr[1]);
state = STATE_IN_DEFINE_ADMIN_AUTH;
_pk_debug ("parsed define_admin_auth node ('%s' (%d) -> '%s')",
}
if (state == STATE_NONE || node == NULL) {
- g_warning ("skipping unknown tag <%s> at line %d of %s",
- el, (int) XML_GetCurrentLineNumber (pd->parser), pd->path);
+ kit_warning ("skipping unknown tag <%s> at line %d of %s",
+ el, (int) XML_GetCurrentLineNumber (pd->parser), pd->path);
syslog (LOG_ALERT, "libpolkit: skipping unknown tag <%s> at line %d of %s",
el, (int) XML_GetCurrentLineNumber (pd->parser), pd->path);
state = STATE_UNKNOWN_TAG;
if (pd->stack_depth > 0) {
pd->node_stack[pd->stack_depth - 1]->children =
- g_slist_append (pd->node_stack[pd->stack_depth - 1]->children, node);
+ kit_list_append (pd->node_stack[pd->stack_depth - 1]->children, node);
}
pd->stack_depth++;
int xml_res;
PolKitConfig *pk_config;
char *buf;
- gsize buflen;
- GError *g_error;
+ size_t buflen;
/* load and parse the configuration file */
pk_config = NULL;
- g_error = NULL;
- if (!g_file_get_contents (path, &buf, &buflen, &g_error)) {
+ if (!kit_file_get_contents (path, &buf, &buflen)) {
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);
+ "Cannot load PolicyKit policy file at '%s': %m",
+ path);
goto error;
}
XML_SetElementHandler (pd.parser, _start, _end);
XML_SetCharacterDataHandler (pd.parser, _cdata);
- pk_config = g_new0 (PolKitConfig, 1);
+ pk_config = kit_new0 (PolKitConfig, 1);
pk_config->refcount = 1;
pd.state = STATE_NONE;
XML_ErrorString (XML_GetErrorCode (pd.parser)));
XML_ParserFree (pd.parser);
- g_free (buf);
+ kit_free (buf);
goto error;
}
XML_ParserFree (pd.parser);
- g_free (buf);
+ kit_free (buf);
_pk_debug ("Loaded configuration file %s", path);
if (pk_config->top_config_node != NULL)
config_node_unref (pk_config->top_config_node);
- g_free (pk_config);
+ kit_free (pk_config);
}
-static gboolean
+static polkit_bool_t
config_node_match (ConfigNode *node,
PolKitAction *action,
PolKitCaller *caller,
char *str1;
char *str2;
uid_t uid;
- gboolean match;
+ polkit_bool_t match;
match = FALSE;
str1 = NULL;
case MATCH_TYPE_ACTION:
if (!polkit_action_get_action_id (action, &str))
goto out;
- str1 = g_strdup (str);
+ str1 = kit_strdup (str);
break;
case MATCH_TYPE_USER:
} else
goto out;
- str1 = g_strdup_printf ("%d", uid);
+ str1 = kit_strdup_printf ("%d", uid);
{
struct passwd pd;
struct passwd* pwdptr=&pd;
if ((getpwuid_r (uid, pwdptr, pwdbuffer, pwdlinelen, &tempPwdPtr)) !=0 )
goto out;
- str2 = g_strdup (pd.pw_name);
+ str2 = kit_strdup (pd.pw_name);
}
break;
}
}
out:
- g_free (str1);
- g_free (str2);
+ kit_free (str1);
+ kit_free (str2);
return match;
}
PolKitCaller *caller,
PolKitSession *session)
{
- gboolean recurse;
+ polkit_bool_t recurse;
PolKitResult result;
recurse = FALSE;
}
if (recurse) {
- GSList *i;
- for (i = node->children; i != NULL; i = g_slist_next (i)) {
+ KitList *i;
+ for (i = node->children; i != NULL; i = i->next) {
ConfigNode *child_node = i->data;
result = config_node_test (child_node, action, caller, session);
if (result != POLKIT_RESULT_UNKNOWN) {
PolKitConfigAdminAuthType *out_admin_auth_type,
const char **out_data)
{
- gboolean recurse;
- gboolean result_set;
+ polkit_bool_t recurse;
+ polkit_bool_t result_set;
recurse = FALSE;
result_set = FALSE;
}
if (recurse) {
- GSList *i;
- for (i = node->children; i != NULL; i = g_slist_next (i)) {
+ KitList *i;
+ for (i = node->children; i != NULL; i = i->next) {
ConfigNode *child_node = i->data;
result_set = config_node_determine_admin_auth (child_node,
#include <sys/inotify.h>
#include <syslog.h>
-#include <glib.h>
#include "polkit-config.h"
#include "polkit-debug.h"
#include "polkit-context.h"
polkit_context_new (void)
{
PolKitContext *pk_context;
- pk_context = g_new0 (PolKitContext, 1);
+ pk_context = kit_new0 (PolKitContext, 1);
pk_context->refcount = 1;
/* TODO: May want to rethink instantiating this on demand.. */
pk_context->authdb = _polkit_authorization_db_new ();
{
kit_return_val_if_fail (pk_context != NULL, FALSE);
- pk_context->policy_dir = g_strdup (PACKAGE_DATA_DIR "/PolicyKit/policy");
+ pk_context->policy_dir = kit_strdup (PACKAGE_DATA_DIR "/PolicyKit/policy");
_pk_debug ("Using policy files from directory %s", pk_context->policy_dir);
/* NOTE: we don't populate the cache until it's needed.. */
if (pk_context->refcount > 0)
return;
- g_free (pk_context);
+ kit_free (pk_context);
}
/**
void
polkit_context_io_func (PolKitContext *pk_context, int fd)
{
- gboolean config_changed;
+ polkit_bool_t config_changed;
kit_return_if_fail (pk_context != NULL);
pk_context->load_descriptions,
&error);
if (pk_context->priv_cache == NULL) {
- g_warning ("Error loading policy files from %s: %s",
+ kit_warning ("Error loading policy files from %s: %s",
pk_context->policy_dir, polkit_error_get_error_message (error));
polkit_error_free (error);
} else {
if (pfe == NULL) {
char *action_name;
if (!polkit_action_get_action_id (action, &action_name)) {
- g_warning ("given action has no name");
+ kit_warning ("given action has no name");
} else {
- g_warning ("no action with name '%s'", action_name);
+ kit_warning ("no action with name '%s'", action_name);
}
result = POLKIT_RESULT_UNKNOWN;
goto out;
/* Otherwise, fall back to defaults as specified in the .policy file */
policy_default = polkit_policy_file_entry_get_default (pfe);
if (policy_default == NULL) {
- g_warning ("no default policy for action!");
+ kit_warning ("no default policy for action!");
goto out;
}
result = polkit_policy_default_can_session_do_action (policy_default, action, session);
if (pfe == NULL) {
char *action_name;
if (!polkit_action_get_action_id (action, &action_name)) {
- g_warning ("given action has no name");
+ kit_warning ("given action has no name");
} else {
- g_warning ("no action with name '%s'", action_name);
+ kit_warning ("no action with name '%s'", action_name);
}
result = POLKIT_RESULT_UNKNOWN;
goto out;
/* Otherwise, fall back to defaults as specified in the .policy file */
policy_default = polkit_policy_file_entry_get_default (pfe);
if (policy_default == NULL) {
- g_warning ("no default policy for action!");
+ kit_warning ("no default policy for action!");
goto out;
}
result = polkit_policy_default_can_caller_do_action (policy_default, action, caller);