Blame SOURCES/0008-Issue-49095-targetattr-wildcard-evaluation-is-incorr.patch

61f723
From abc9ff876209819c8f0dd7e799f1ab6a1b084fe5 Mon Sep 17 00:00:00 2001
61f723
From: Mark Reynolds <mreynolds@redhat.com>
61f723
Date: Mon, 20 Mar 2017 15:08:45 -0400
61f723
Subject: [PATCH] Issue 49095 - targetattr wildcard evaluation is incorrectly
61f723
 case sensitive
61f723
61f723
Description:  When processing an aci that uses a wildcard targetattr, the
61f723
              comparision should be done using case insensitive functions.
61f723
61f723
https://pagure.io/389-ds-base/issue/49095
61f723
61f723
Reviewed by: firstyear(Thanks!)
61f723
---
61f723
 dirsrvtests/tests/tickets/ticket49095_test.py | 85 +++++++++++++++++++++++++++
61f723
 ldap/servers/plugins/acl/acl.c                | 10 ++--
61f723
 2 files changed, 90 insertions(+), 5 deletions(-)
61f723
 create mode 100644 dirsrvtests/tests/tickets/ticket49095_test.py
61f723
61f723
diff --git a/dirsrvtests/tests/tickets/ticket49095_test.py b/dirsrvtests/tests/tickets/ticket49095_test.py
61f723
new file mode 100644
61f723
index 0000000..04f92b2
61f723
--- /dev/null
61f723
+++ b/dirsrvtests/tests/tickets/ticket49095_test.py
61f723
@@ -0,0 +1,85 @@
61f723
+import time
61f723
+import ldap
61f723
+import logging
61f723
+import pytest
61f723
+from lib389 import DirSrv, Entry, tools, tasks
61f723
+from lib389.tools import DirSrvTools
61f723
+from lib389._constants import *
61f723
+from lib389.properties import *
61f723
+from lib389.tasks import *
61f723
+from lib389.utils import *
61f723
+from lib389.topologies import topology_st as topo
61f723
+
61f723
+DEBUGGING = os.getenv("DEBUGGING", default=False)
61f723
+if DEBUGGING:
61f723
+    logging.getLogger(__name__).setLevel(logging.DEBUG)
61f723
+else:
61f723
+    logging.getLogger(__name__).setLevel(logging.INFO)
61f723
+log = logging.getLogger(__name__)
61f723
+
61f723
+USER_DN = 'uid=testuser,dc=example,dc=com'
61f723
+acis = ['(targetattr != "tele*") (version 3.0;acl "test case";allow (read,compare,search)(userdn = "ldap:///anyone");)',
61f723
+        '(targetattr != "TELE*") (version 3.0;acl "test case";allow (read,compare,search)(userdn = "ldap:///anyone");)',
61f723
+        '(targetattr != "telephonenum*") (version 3.0;acl "test case";allow (read,compare,search)(userdn = "ldap:///anyone");)',
61f723
+        '(targetattr != "TELEPHONENUM*") (version 3.0;acl "test case";allow (read,compare,search)(userdn = "ldap:///anyone");)']
61f723
+
61f723
+
61f723
+def test_ticket49095(topo):
61f723
+    """Check that target attrbiutes with wildcards are case insensitive
61f723
+    """
61f723
+
61f723
+    # Add an entry
61f723
+    try:
61f723
+        topo.standalone.add_s(Entry((USER_DN, {
61f723
+            'objectclass': 'top extensibleObject'.split(),
61f723
+            'uid': 'testuser',
61f723
+            'telephonenumber': '555-555-5555'
61f723
+        })))
61f723
+    except ldap.LDAPError as e:
61f723
+            log.fatal('Failed to add test user: ' + e.message['desc'])
61f723
+            assert False
61f723
+
61f723
+    for aci in acis:
61f723
+        # Add ACI
61f723
+        try:
61f723
+            topo.standalone.modify_s(DEFAULT_SUFFIX,
61f723
+                          [(ldap.MOD_REPLACE, 'aci', aci)])
61f723
+
61f723
+        except ldap.LDAPError as e:
61f723
+            log.fatal('Failed to set aci: ' + aci + ': ' + e.message['desc'])
61f723
+            assert False
61f723
+
61f723
+        # Set Anonymous Bind to test aci
61f723
+        try:
61f723
+            topo.standalone.simple_bind_s("", "")
61f723
+        except ldap.LDAPError as e:
61f723
+            log.fatal('Failed to bind anonymously: ' + e.message['desc'])
61f723
+            assert False
61f723
+
61f723
+        # Search for entry - should not get any results
61f723
+        try:
61f723
+            entry = topo.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_BASE,
61f723
+                                             'telephonenumber=*')
61f723
+            if entry:
61f723
+                log.fatal('The entry was incorrectly returned')
61f723
+                assert False
61f723
+        except ldap.LDAPError as e:
61f723
+            log.fatal('Failed to search anonymously: ' + e.message['desc'])
61f723
+            assert False
61f723
+
61f723
+        # Set root DN Bind so we can update aci's
61f723
+        try:
61f723
+            topo.standalone.simple_bind_s(DN_DM, PASSWORD)
61f723
+        except ldap.LDAPError as e:
61f723
+            log.fatal('Failed to bind anonymously: ' + e.message['desc'])
61f723
+            assert False
61f723
+
61f723
+    log.info("Test Passed")
61f723
+
61f723
+
61f723
+if __name__ == '__main__':
61f723
+    # Run isolated
61f723
+    # -s for DEBUG mode
61f723
+    CURRENT_FILE = os.path.realpath(__file__)
61f723
+    pytest.main("-s %s" % CURRENT_FILE)
61f723
+
61f723
diff --git a/ldap/servers/plugins/acl/acl.c b/ldap/servers/plugins/acl/acl.c
61f723
index 0a93808..48b8efc 100644
61f723
--- a/ldap/servers/plugins/acl/acl.c
61f723
+++ b/ldap/servers/plugins/acl/acl.c
61f723
@@ -3407,19 +3407,19 @@ acl_match_substring ( Slapi_Filter *f, char *str, int exact_match)
61f723
 	}
61f723
 
61f723
 	/* this assumes that str and the filter components are already
61f723
-	 * normalized. If not, it shoul be done
61f723
+	 * normalized. If not, it should be done
61f723
 	 */
61f723
 	if ( initial != NULL) {
61f723
 		len = strlen(initial);
61f723
 		if (exact_match) {
61f723
-			int rc = strncmp(p, initial, len);
61f723
+			int rc = strncasecmp(p, initial, len);
61f723
 			if (rc) {
61f723
 				return ACL_FALSE;
61f723
 			} else {
61f723
 				p += len;
61f723
 			}  
61f723
 		} else {
61f723
-			p = strstr(p, initial);
61f723
+			p = strcasestr(p, initial);
61f723
 			if (p) {
61f723
 				p += len;
61f723
 			} else {
61f723
@@ -3430,7 +3430,7 @@ acl_match_substring ( Slapi_Filter *f, char *str, int exact_match)
61f723
 
61f723
 	if ( any != NULL) {
61f723
 		for (i = 0;  any && any[i] != NULL; i++) {
61f723
-			p = strstr(p, any[i]);
61f723
+			p = strcasestr(p, any[i]);
61f723
 			if (p) {
61f723
 				p += strlen(any[i]);
61f723
 			} else {
61f723
@@ -3444,7 +3444,7 @@ acl_match_substring ( Slapi_Filter *f, char *str, int exact_match)
61f723
 		len = strlen(final);
61f723
 		tlen = strlen(p);
61f723
 		if (len > tlen) return ACL_FALSE;
61f723
-		if (strcmp(p+tlen-len, final)) return ACL_FALSE;
61f723
+		if (strcasecmp(p+tlen-len, final)) return ACL_FALSE;
61f723
 	}
61f723
 
61f723
 	return ACL_TRUE;
61f723
-- 
61f723
2.9.3
61f723