]> saetta.ns0.it Git - zakautho/libzakautho/commitdiff
Managed role's parents.
authorAndrea Zagli <azagli@libero.it>
Thu, 24 Jun 2010 20:34:40 +0000 (22:34 +0200)
committerAndrea Zagli <azagli@libero.it>
Thu, 24 Jun 2010 20:34:40 +0000 (22:34 +0200)
src/autoz.c
tests/test.c

index f4070bb9def949cdb26dbf59430a1b044a38fa4a..c52fa995c655d1145426e6217ffcedfbf934cc22 100644 (file)
@@ -28,14 +28,14 @@ typedef struct _Role Role;
 struct _Role
        {
                AutozIRole *irole;
-               GList *parents;
+               GList *parents; /* struct Role */
        };
 
 typedef struct _Resource Resource;
 struct _Resource
        {
                AutozIResource *iresource;
-               GList *parents;
+               GList *parents; /* struct Resource */
        };
 
 typedef struct _Rule Rule;
@@ -62,10 +62,10 @@ static void autoz_get_property (GObject *object,
 typedef struct _AutozPrivate AutozPrivate;
 struct _AutozPrivate
        {
-               GHashTable *roles;
-               GHashTable *resources;
+               GHashTable *roles; /* struct Role */
+               GHashTable *resources; /* struct Resource */
 
-               GHashTable *rules;
+               GHashTable *rules; /* struct Rule */
        };
 
 G_DEFINE_TYPE (Autoz, autoz, G_TYPE_OBJECT)
@@ -207,7 +207,48 @@ autoz_allow (Autoz *autoz, AutozIRole *irole, AutozIResource *iresource)
                        g_hash_table_insert (priv->rules, str_id, r);
                }
 }
-       
+
+static gboolean
+_autoz_is_allowed (Autoz *autoz, Role *role, Resource *resource)
+{
+       gboolean ret;
+
+       gchar *str_id;
+
+       AutozPrivate *priv = AUTOZ_GET_PRIVATE (autoz);
+
+       ret = FALSE;
+
+       str_id = g_strconcat (autoz_irole_get_role_id (role->irole),
+                             "|",
+                             autoz_iresource_get_resource_id (resource->iresource),
+                             NULL);
+
+       if (g_hash_table_lookup (priv->rules, str_id) != NULL)
+               {
+                       ret = TRUE;
+               }
+       else if (role->parents != NULL)
+               {
+                       /* trying parents */
+                       GList *parents;
+
+                       parents = g_list_first (role->parents);
+                       while (parents != NULL)
+                               {
+                                       if (_autoz_is_allowed (autoz, (Role *)parents->data, resource))
+                                               {
+                                                       ret = TRUE;
+                                                       break;          
+                                               }
+
+                                       parents = g_list_next (parents);
+                               }
+               }
+
+       return ret;
+}
+
 gboolean
 autoz_is_allowed (Autoz *autoz, AutozIRole *irole, AutozIResource *iresource)
 {
@@ -242,6 +283,23 @@ autoz_is_allowed (Autoz *autoz, AutozIRole *irole, AutozIResource *iresource)
                {
                        ret = TRUE;
                }
+       else if (role->parents != NULL)
+               {
+                       /* trying parents */
+                       GList *parents;
+
+                       parents = g_list_first (role->parents);
+                       while (parents != NULL)
+                               {
+                                       if (_autoz_is_allowed (autoz, (Role *)parents->data, resource))
+                                               {
+                                                       ret = TRUE;
+                                                       break;          
+                                               }
+
+                                       parents = g_list_next (parents);
+                               }
+               }
 
        return ret;
 }
index e8597e25abb4fb848ea6140e4770e5740fd483ff..85596382f777b1b02c1e5db2cc0d4be0802641d2 100644 (file)
@@ -37,7 +37,9 @@ main (int argc, char **argv)
        autoz_add_role (autoz, AUTOZ_IROLE (role_writer));
 
        role_writer_child = autoz_role_new ("writer-child");
-       autoz_add_role_with_parents (autoz, AUTOZ_IROLE (role_writer_child), AUTOZ_IROLE (role_writer), NULL);
+       autoz_add_role_with_parents (autoz, AUTOZ_IROLE (role_writer_child),
+                                    AUTOZ_IROLE (role_writer),
+                                    NULL);
 
        role_read_only = autoz_role_new ("read-only");
        autoz_add_role (autoz, AUTOZ_IROLE (role_read_only));