From: Daniel Wagner <daniel.wag...@bmw-carit.de>

selinux_context_reply() should handle the 'type' conversion of
data it gets from D-Bus.
---
 plugins/session_policy_local.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/plugins/session_policy_local.c b/plugins/session_policy_local.c
index 5a8f6b8..d3e51a2 100644
--- a/plugins/session_policy_local.c
+++ b/plugins/session_policy_local.c
@@ -75,9 +75,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
@@ -97,23 +97,14 @@ static char *parse_ident(const unsigned char *context)
         * as haifux_t.
         */
 
-       str = g_strdup((const gchar*)context);
-       if (str == NULL)
+       tokens = g_strsplit(context, ":", 0);
+       if (tokens == NULL)
                return NULL;
 
-       DBG("SELinux context %s", str);
-
-       tokens = g_strsplit(str, ":", 0);
-       if (tokens == NULL) {
-               g_free(str);
-               return NULL;
-       }
-
        /* Use the SELinux type as identification token. */
        ident = g_strdup(tokens[2]);
 
        g_strfreev(tokens);
-       g_free(str);
 
        return ident;
 }
@@ -167,14 +158,22 @@ static void selinux_context_reply(const unsigned char 
*context, void *user_data,
        struct create_data *data = user_data;
        struct policy_data *policy;
        struct connman_session_config *config = NULL;
-       char *ident = NULL;
+       char *ident = NULL, *ctx = NULL;
 
        DBG("session %p", data->session);
 
        if (err < 0)
                goto done;
 
-       ident = parse_ident(context);
+       ctx = g_strdup((const gchar*)context);
+       if (ctx == NULL) {
+               err = -ENOMEM;
+               goto done;
+       }
+
+       DBG("SELinux context %s", ctx);
+
+       ident = parse_selinux_type(ctx);
        if (ident == NULL) {
                err = -EINVAL;
                goto done;
@@ -200,6 +199,7 @@ done:
 
        g_free(data);
        g_free(ident);
+       g_free(ctx);
 }
 
 static int policy_local_create(struct connman_session *session,
-- 
1.8.1.3.566.gaa39828

_______________________________________________
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman

Reply via email to