9e566a4
--- cyrus-imapd-2.2.12/lib/acl_afs.c.orig	2005-07-14 17:12:53 +0300
9e566a4
+++ cyrus-imapd-2.2.12/lib/acl_afs.c	2005-07-14 17:17:44 +0300
9e566a4
@@ -119,12 +119,17 @@
9e566a4
     char *thisid, *nextid;
9e566a4
     int oldaccess = 0;
9e566a4
     char *rights;
9e566a4
+    int identifier_found = 0;
9e566a4
+    int identifier_overridden = 0;
9e566a4
 
9e566a4
     /* Convert 'identifier' into canonical form */
9e566a4
     if (*identifier == '-') {
9e566a4
 	char *canonid = auth_canonifyid(identifier+1, 0);
9e566a4
-	if (!canonid) {
9e566a4
+	if (!canonid && access != 0L) {
9e566a4
 	    return -1;
9e566a4
+	} else if (!canonid && access == 0L) {
9e566a4
+	    canonid = identifier+1;
9e566a4
+	    identifier_overridden = 1;
9e566a4
 	}
9e566a4
 	newidentifier = xmalloc(strlen(canonid)+2);
9e566a4
 	newidentifier[0] = '-';
9e566a4
@@ -135,9 +140,15 @@
9e566a4
 	}
9e566a4
     }
9e566a4
     else {
9e566a4
+	newidentifier = xmalloc(strlen(identifier)+1);
9e566a4
+	strlcpy(newidentifier, identifier, strlen(identifier)+1);
9e566a4
+	
9e566a4
 	identifier = auth_canonifyid(identifier, 0);
9e566a4
-	if (!identifier) {
9e566a4
+	if (!identifier && access != 0L) {
9e566a4
 	    return -1;
9e566a4
+	} else if(!identifier && access == 0L) {
9e566a4
+            identifier = newidentifier;
9e566a4
+            identifier_overridden = 1;
9e566a4
 	}
9e566a4
 	if (canonproc) {
9e566a4
 	    access = canonproc(canonrock, identifier, access);
9e566a4
@@ -165,6 +176,7 @@
9e566a4
 	*nextid++ = '\0';
9e566a4
 
9e566a4
 	if (strcmp(identifier, thisid) == 0) {
9e566a4
+            identifier_found = 1;
9e566a4
 	    oldaccess = cyrus_acl_strtomask(rights);
9e566a4
 	    break;
9e566a4
 	}
9e566a4
@@ -172,6 +184,15 @@
9e566a4
 	nextid[-1] = '\t';
9e566a4
     }
9e566a4
 
9e566a4
+    /* 
9e566a4
+     * In case we have overridden the canonification of the
9e566a4
+     * identifier, but still the identifier does not exist in
9e566a4
+     * the mailboxdb, then return error as normally expected.
9e566a4
+     */
9e566a4
+    if(identifier_overridden && !identifier_found) {
9e566a4
+        return -1;
9e566a4
+    }
9e566a4
+
9e566a4
     switch (mode) {
9e566a4
     case ACL_MODE_SET:
9e566a4
 	break;