[evolution-kolab] CamelImapxAcl: implemented basic ACL validation



commit 62947398698f37f797eb7dffb6ad3638311a121e
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Mon Oct 15 16:02:48 2012 +0200

    CamelImapxAcl: implemented basic ACL validation
    
    * implemented validator function for access_id
      (require valid UTF-8, disallow non-printables)
    * implemented validator function for rights
      (require alphanumeric)
    * more checks could be added here

 src/libekolab/camel-imapx-acl.c |   71 ++++++++++++++++++++++++++++++++++----
 1 files changed, 63 insertions(+), 8 deletions(-)
---
diff --git a/src/libekolab/camel-imapx-acl.c b/src/libekolab/camel-imapx-acl.c
index 31205ab..40fe98a 100644
--- a/src/libekolab/camel-imapx-acl.c
+++ b/src/libekolab/camel-imapx-acl.c
@@ -63,29 +63,84 @@ static gboolean
 imapx_acl_entry_validate_access_id (const gchar *access_id,
                                     GError **err)
 {
+	const gchar *id_ptr = NULL;
+	gunichar uc;
+	gboolean ok = TRUE;
+
 	g_return_val_if_fail (access_id != NULL, FALSE);
 	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
 
-	/* FIXME implement me */
-	g_warning ("%s[%u] FIXME implement me", __func__, __LINE__);
+	/* access_id is required to be valid UTF-8 */
+	ok = g_utf8_validate (access_id, -1, NULL);
+	if (! ok)
+		goto exit;
 
-	return TRUE;
+	/* access_id may not contain whitespace
+	 * and non-printables
+	 */
+	id_ptr = access_id;
+	while (id_ptr != NULL) {
+		uc = g_utf8_get_char (id_ptr);
+		if (! g_unichar_isgraph (uc)) {
+			ok = FALSE;
+			goto exit;
+		}
+		id_ptr = g_utf8_next_char (id_ptr);
+		if (g_strcmp0 (id_ptr, "") == 0)
+			break;
+	}
+
+	/* add more checks here */
+
+ exit:
+
+	if (! ok) {
+		g_set_error (err,
+		             CAMEL_ERROR,
+		             CAMEL_ERROR_GENERIC,
+		             _("Invalid IMAP ACL AccessID"));
+	}
+
+	return ok;
 }
 
 static gboolean
 imapx_acl_entry_validate_rights (const gchar *rights,
                                  GError **err)
 {
+	const gchar *rights_ptr = NULL;
+	gboolean ok = TRUE;
+
 	/* rights may be NULL */
 	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
 
 	if (rights == NULL)
 		return TRUE;
 
-	/* FIXME implement me */
-	g_warning ("%s[%u] FIXME implement me", __func__, __LINE__);
+	/* if non-NULL, rights is required to be alphanumeric */
+	rights_ptr = rights;
+	while (rights_ptr != NULL) {
+		if (! g_ascii_isalnum (rights_ptr[0])) {
+			ok = FALSE;
+			goto exit;
+		}
+		rights_ptr++;
+		if (g_strcmp0 (rights_ptr, "") == 0)
+			break;
+	}
+
+	/* add more checks here */
 
-	return TRUE;
+ exit:
+
+	if (! ok) {
+		g_set_error (err,
+		             CAMEL_ERROR,
+		             CAMEL_ERROR_GENERIC,
+		             _("Invalid IMAP ACL Rights"));
+	}
+
+	return ok;
 }
 
 static gboolean



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