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

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