[evolution-kolab/ek-wip-acl: 21/21] CamelImapxAcl: implemented validator function



commit 80be93d87b38b7989b81889ee14967e30697d1e3
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Thu Oct 11 16:29:59 2012 +0200

    CamelImapxAcl: implemented validator function
    
    * implemented validator function for a full
      CamelImapxAcl instance
    * validates the contents of the MYRIGHTS table
      and the general ACL tables for the mailboxes

 src/libekolab/camel-imapx-acl.c |  117 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 110 insertions(+), 7 deletions(-)
---
diff --git a/src/libekolab/camel-imapx-acl.c b/src/libekolab/camel-imapx-acl.c
index d2fbd93..0d159c3 100644
--- a/src/libekolab/camel-imapx-acl.c
+++ b/src/libekolab/camel-imapx-acl.c
@@ -136,6 +136,94 @@ imapx_acl_mboxes_table_new (void)
 	return tbl;
 }
 
+static gboolean
+imapx_acl_validate (CamelImapxAcl *acl,
+                    GError **err)
+{
+	GHashTable *entries = NULL;
+	GList *keys = NULL;
+	GList *keys_ptr = NULL;
+	GList *entries_keys = NULL;
+	GList *entries_keys_ptr = NULL;
+	gpointer tmp = NULL;
+	GError *tmp_err = NULL;
+	gboolean ok = TRUE;
+
+	g_return_val_if_fail (acl != NULL, FALSE);
+	g_return_val_if_fail (acl->mboxes != NULL, FALSE);
+	g_return_val_if_fail (acl->myrights, FALSE);
+	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+	/* caller should hold acl->lock */
+
+	/* MYRIGHTS */
+	keys = g_hash_table_get_keys (acl->myrights);
+	keys_ptr = keys;
+	while (keys_ptr != NULL) {
+		tmp = g_hash_table_lookup (acl->myrights, keys_ptr);
+
+		ok = imapx_acl_entry_validate_rights ((const gchar *) tmp,
+		                                      &tmp_err);
+		if (! ok)
+			goto exit;
+
+		keys_ptr = g_list_next (keys_ptr);
+	}
+	g_list_free (keys);
+
+	/* ACL */
+	keys = g_hash_table_get_keys (acl->mboxes);
+	keys_ptr = keys;
+	while (keys_ptr != NULL) {
+		entries = g_hash_table_lookup (acl->mboxes,
+		                               keys_ptr);
+		if (entries == NULL) {
+			g_set_error (&tmp_err,
+			             CAMEL_IMAPX_ERROR,
+			             0, /* FIXME define sensible error number */
+			             _("Invalid internal IMAP ACL datastructure"));
+			goto exit;
+		}
+
+		/* mbox rights entries */
+		entries_keys = g_hash_table_get_keys (entries);
+		entries_keys_ptr = entries_keys;
+		while (entries_keys_ptr != NULL) {
+			ok = imapx_acl_entry_validate_access_id ((const gchar *) entries_keys_ptr->data,
+			                                         &tmp_err);
+			if (! ok) {
+				g_list_free (entries_keys);
+				goto exit;
+			}
+
+			tmp = g_hash_table_lookup (entries,
+			                           entries_keys_ptr);
+			ok = imapx_acl_entry_validate_rights ((const gchar *) tmp,
+			                                      &tmp_err);
+			if (! ok) {
+				g_list_free (entries_keys);
+				goto exit;
+			}
+
+			entries_keys_ptr = g_list_next (entries_keys_ptr);
+		}
+		g_list_free (entries_keys);
+
+		keys_ptr = g_list_next (keys_ptr);
+	}
+
+ exit:
+
+	if (tmp_err != NULL) {
+		g_propagate_error (err, tmp_err);
+		ok = FALSE;
+	}
+
+	g_list_free (keys);
+
+	return ok;
+}
+
 /*----------------------------------------------------------------------------*/
 
 CamelImapxAclSpec*
@@ -308,18 +396,20 @@ gboolean
 camel_imapx_acl_validate (CamelImapxAcl *acl,
                           GError **err)
 {
+	gboolean ok = FALSE;
+
 	g_return_val_if_fail (acl != NULL, FALSE);
 	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
 
 	/* (acquire acl lock) */
 	g_mutex_lock (&(acl->lock));
 
-	g_warning ("%s()[%u] FIXME implement me", __func__, __LINE__);
+	ok = imapx_acl_validate (acl, err);
 
 	/* (release acl lock) */
 	g_mutex_unlock (&(acl->lock));
 
-	return TRUE;
+	return ok;
 }
 
 GList*
@@ -472,6 +562,8 @@ camel_imapx_acl_update_from_acl (CamelImapxAcl *acl,
 	GHashTable *src_entries = NULL;
 	GHashTable *new_entries = NULL;
 	gchar *rights = NULL;
+	GError *tmp_err = NULL;
+	gboolean ok = FALSE;
 
 	g_return_val_if_fail (acl != NULL, FALSE);
 	g_return_val_if_fail (acl->mboxes != NULL, FALSE);
@@ -482,12 +574,16 @@ camel_imapx_acl_update_from_acl (CamelImapxAcl *acl,
 	if (src_acl == NULL)
 		return TRUE;
 
-	/* (acquire acl lock) */
-	g_mutex_lock (&(acl->lock));
-
 	/* (acquire src_acl lock) */
 	g_mutex_lock (&(src_acl->lock));
 
+	ok = imapx_acl_validate (src_acl, &tmp_err);
+	if (! ok)
+		goto src_acl_skip;
+
+	/* (acquire acl lock) */
+	g_mutex_lock (&(acl->lock));
+
 	if (src_acl->mboxes == NULL)
 		goto acl_skip;
 
@@ -550,11 +646,18 @@ camel_imapx_acl_update_from_acl (CamelImapxAcl *acl,
 
  myrights_skip:
 
+	/* (release acl lock) */
+	g_mutex_unlock (&(acl->lock));
+
+ src_acl_skip:
+
 	/* (release src_acl lock) */
 	g_mutex_unlock (&(src_acl->lock));
 
-	/* (release acl lock) */
-	g_mutex_unlock (&(acl->lock));
+	if (tmp_err != NULL) {
+		g_propagate_error (err, tmp_err);
+		return FALSE;
+	}
 
 	return TRUE;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]