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

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