diff options
author | Daniel Wagner <daniel.wagner@bmw-carit.de> | 2013-05-31 09:13:29 +0200 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2013-05-31 14:36:32 +0300 |
commit | 99249a49b7d5e9c763ff21214b08aac3b5fbfd99 (patch) | |
tree | 13c42026ea65717be6861b8b1402044efc23909f | |
parent | 3fb5619a5771591cb425e7383880fa9a71840b95 (diff) | |
download | connman-99249a49b7d5e9c763ff21214b08aac3b5fbfd99.tar.gz connman-99249a49b7d5e9c763ff21214b08aac3b5fbfd99.tar.bz2 connman-99249a49b7d5e9c763ff21214b08aac3b5fbfd99.zip |
session_policy_local: Refactor SELinux context parser
g_strplit() will eventually strdup the tokens so no need to
strdup() 'context'. But we an ugly cast (from 'const unsigned char *'
to 'const char *') is needed for g_strsplit() to make the compiler happy.
-rw-r--r-- | plugins/session_policy_local.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/plugins/session_policy_local.c b/plugins/session_policy_local.c index 0b5f5eed..21b794dd 100644 --- a/plugins/session_policy_local.c +++ b/plugins/session_policy_local.c @@ -73,9 +73,9 @@ static void cleanup_policy(gpointer user_data) g_free(policy); } -static char *parse_ident(const unsigned char *context) +static char *parse_selinux_type(const char *context) { - char *str, *ident, **tokens; + char *ident, **tokens; /* * SELinux combines Role-Based Access Control (RBAC), Type @@ -95,15 +95,9 @@ static char *parse_ident(const unsigned char *context) * as haifux_t. */ - str = g_strdup((const gchar*)context); - if (str == NULL) - return NULL; - - DBG("SELinux context %s", str); - - tokens = g_strsplit(str, ":", 0); - if (tokens == NULL) { - g_free(str); + tokens = g_strsplit(context, ":", 0); + if (g_strv_length(tokens) < 2) { + g_strfreev(tokens); return NULL; } @@ -111,7 +105,6 @@ static char *parse_ident(const unsigned char *context) ident = g_strdup(tokens[2]); g_strfreev(tokens); - g_free(str); return ident; } @@ -167,7 +160,9 @@ static void selinux_context_reply(const unsigned char *context, void *user_data, if (err < 0) goto done; - ident = parse_ident(context); + DBG("SELinux context %s", context); + + ident = parse_selinux_type((const char*)context); if (ident == NULL) { err = -EINVAL; goto done; |