identity: fix owner and acl handling
authorJussi Laako <jussi.laako@linux.intel.com>
Mon, 25 Nov 2013 15:54:02 +0000 (17:54 +0200)
committerJussi Laako <jussi.laako@linux.intel.com>
Thu, 28 Nov 2013 14:49:38 +0000 (16:49 +0200)
src/common/gsignond-identity-info-internal.h
src/common/gsignond-identity-info.c
src/daemon/gsignond-identity.c

index 1348a1d..92af966 100644 (file)
@@ -96,6 +96,9 @@ gsignond_identity_info_selective_copy (GSignondIdentityInfo *dest,
                                        const GSignondIdentityInfo *src,
                                        GSignondIdentityInfoPropFlags flags);
 
+void
+gsignond_identity_info_remove_owner (GSignondIdentityInfo *info);
+
 G_END_DECLS
 
 #endif /* __GSIGNOND_IDENTITY_INFO_INTERNAL_H__ */
index ff2ce29..c2a7334 100644 (file)
@@ -314,7 +314,7 @@ gsignond_identity_info_selective_copy (GSignondIdentityInfo *dest,
     for (i= 0, tmp_flag = IDENTITY_INFO_PROP_ID; 
          tmp_flag < IDENTITY_INFO_PROP_MAX;
          tmp_flag <<= 1, i++) {
-        if (flags & tmp_flag && 
+        if ((flags & tmp_flag) && 
             gsignond_dictionary_contains (src->map, keys[i])) {
             gsignond_dictionary_set (dest->map, keys[i],
                g_variant_ref (gsignond_dictionary_get (src->map, keys[i])));
@@ -339,6 +339,14 @@ gsignond_identity_info_selective_copy (GSignondIdentityInfo *dest,
     return flags;
 }
 
+void
+gsignond_identity_info_remove_owner (GSignondIdentityInfo *info)
+{
+    g_return_if_fail (info && GSIGNOND_IS_IDENTITY_INFO(info));
+
+    gsignond_dictionary_remove (info->map, GSIGNOND_IDENTITY_INFO_OWNER);
+}
+
 /**
  * gsignond_identity_info_new:
  *
@@ -1117,7 +1125,7 @@ gsignond_identity_info_get_owner (GSignondIdentityInfo *info)
     g_return_val_if_fail (info && GSIGNOND_IS_IDENTITY_INFO (info), NULL);
 
     GVariant *var = gsignond_dictionary_get (info->map,
-                         GSIGNOND_IDENTITY_INFO_OWNER);
+                                             GSIGNOND_IDENTITY_INFO_OWNER);
     return var ? gsignond_security_context_from_variant (var) : NULL;
 }
 
@@ -1146,11 +1154,11 @@ gsignond_identity_info_set_owner (
         gsignond_security_context_compare (current_owner, owner) == 0)
         return TRUE;
 
-    return gsignond_dictionary_set (info->map,
-                GSIGNOND_IDENTITY_INFO_OWNER,
-                gsignond_security_context_to_variant (owner)) &&
-           gsignond_identity_info_set_edit_flags (info,
-                IDENTITY_INFO_PROP_OWNER);
+    return (gsignond_dictionary_set (info->map,
+                                     GSIGNOND_IDENTITY_INFO_OWNER,
+                                     gsignond_security_context_to_variant (owner)) &&
+            gsignond_identity_info_set_edit_flags (info,
+                                                   IDENTITY_INFO_PROP_OWNER));
 }
 
 /**
index f8b5bd0..3cdcab6 100644 (file)
@@ -820,6 +820,7 @@ typedef struct _{
     GSignondDaemon *daemon;
     guint32 identity_id;
 }_StoreCachedTokenCbInfo;
+
 static void
 _store_cached_token_data (const gchar *method, GSignondAuthSession *session, _StoreCachedTokenCbInfo *data)
 {
@@ -831,6 +832,14 @@ _store_cached_token_data (const gchar *method, GSignondAuthSession *session, _St
         gsignond_daemon_store_identity_data (data->daemon, data->identity_id, method, token_data);
 }
 
+static long
+_ncstrlen (const gchar *strptr)
+{
+    if (strptr == NULL)
+        return -1;
+    return (long) strlen (strptr);
+}
+
 guint32
 gsignond_identity_store (GSignondIdentity *identity, 
                          const GVariant *info,
@@ -840,8 +849,10 @@ gsignond_identity_store (GSignondIdentity *identity,
     GSignondIdentityPrivate *priv = NULL;
     GSignondIdentityInfo *identity_info = NULL;
     gboolean was_new_identity = FALSE;
+    GSignondSecurityContext *owner_ctx = NULL;
     GSignondSecurityContextList *contexts = NULL;
     GSignondIdentityInfoPropFlags flags;
+    GSignondIdentityInfoPropFlags flag_mask;
     guint32 id;
 
     if (!(identity && GSIGNOND_IS_IDENTITY (identity))) {
@@ -858,6 +869,19 @@ gsignond_identity_store (GSignondIdentity *identity,
 
     identity_info = gsignond_identity_info_new_from_variant ((GVariant *)info);
 
+    /* if owner context is non-NULL but empty, remove the dictionary item,
+     * it will get filled up later when actual store happens */
+    owner_ctx = gsignond_identity_info_get_owner (identity_info);
+    if (owner_ctx) {
+        const gchar *sys_ctx =
+            gsignond_security_context_get_system_context (owner_ctx);
+        if (_ncstrlen (sys_ctx) <= 0) {
+            gsignond_identity_info_remove_owner (identity_info);
+        }
+        gsignond_security_context_free (owner_ctx);
+        owner_ctx = NULL;
+    }
+
     contexts = gsignond_identity_info_get_access_control_list (identity_info);
     if (contexts) {
         VALIDATE_IDENTITY_WRITE_ACL (identity, ctx, 0);
@@ -867,14 +891,18 @@ gsignond_identity_store (GSignondIdentity *identity,
     flags = gsignond_identity_info_get_edit_flags (identity_info);
 
     /* select only interested field */
-    flags &= (IDENTITY_INFO_PROP_USERNAME |
-              IDENTITY_INFO_PROP_USERNAME_IS_SECRET |
-              IDENTITY_INFO_PROP_SECRET |
-              IDENTITY_INFO_PROP_STORE_SECRET |
-              IDENTITY_INFO_PROP_CAPTION |
-              IDENTITY_INFO_PROP_TYPE |
-              IDENTITY_INFO_PROP_METHODS |
-              IDENTITY_INFO_PROP_REALMS);
+    flag_mask = (IDENTITY_INFO_PROP_USERNAME |
+                 IDENTITY_INFO_PROP_USERNAME_IS_SECRET |
+                 IDENTITY_INFO_PROP_SECRET |
+                 IDENTITY_INFO_PROP_STORE_SECRET |
+                 IDENTITY_INFO_PROP_CAPTION |
+                 IDENTITY_INFO_PROP_TYPE |
+                 IDENTITY_INFO_PROP_METHODS |
+                 IDENTITY_INFO_PROP_REALMS |
+                 IDENTITY_INFO_PROP_ACL);
+    if (was_new_identity)
+        flag_mask |= IDENTITY_INFO_PROP_OWNER;
+    flags &= flag_mask;
     gsignond_identity_info_selective_copy (priv->info, identity_info, flags);
 
     /* FIXME : either username/secret changed reset the identity