zrhoffman / rpms / 389-ds-base

Forked from rpms/389-ds-base 3 years ago
Clone

Blame SOURCES/0019-Ticket-47920-Encoding-of-SearchResultEntry-is-missin.patch

f92ce9
From 5d034162124f8d92c4ad3ea205b0e60be81c5c4f Mon Sep 17 00:00:00 2001
f92ce9
From: "Thierry bordaz (tbordaz)" <tbordaz@redhat.com>
f92ce9
Date: Thu, 9 Oct 2014 14:31:11 +0200
f92ce9
Subject: [PATCH 19/21] Ticket 47920: Encoding of SearchResultEntry is missing
f92ce9
 tag
f92ce9
f92ce9
Bug Description:
f92ce9
	The encoding of the PreReadControl,PostReadControl does not
f92ce9
	contain the tag (LDAP_RES_SEARCH_ENTRY = constructed+application).
f92ce9
f92ce9
	The server should return SearchResultEntry (http://tools.ietf.org/html/rfc4527 3.1 & 3.2)
f92ce9
	That is
f92ce9
		SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
f92ce9
			     objectName      LDAPDN,
f92ce9
			     attributes      PartialAttributeList }
f92ce9
Fix Description:
f92ce9
	Add the tag to the ber encoding
f92ce9
f92ce9
https://fedorahosted.org/389/ticket/47920
f92ce9
f92ce9
Reviewed by: Noriko (thanks !)
f92ce9
f92ce9
Platforms tested: F17
f92ce9
f92ce9
Flag Day: no
f92ce9
f92ce9
Doc impact: no
f92ce9
f92ce9
(cherry picked from commit 90939dc9c965ea1cb88b88eec0cb735ab97ae551)
f92ce9
---
f92ce9
 dirsrvtests/tickets/ticket47920_test.py | 251 ++++++++++++++++++++++++++++++++
f92ce9
 ldap/servers/slapd/result.c             |   2 +-
f92ce9
 2 files changed, 252 insertions(+), 1 deletion(-)
f92ce9
 create mode 100644 dirsrvtests/tickets/ticket47920_test.py
f92ce9
f92ce9
diff --git a/dirsrvtests/tickets/ticket47920_test.py b/dirsrvtests/tickets/ticket47920_test.py
f92ce9
new file mode 100644
f92ce9
index 0000000..1e04626
f92ce9
--- /dev/null
f92ce9
+++ b/dirsrvtests/tickets/ticket47920_test.py
f92ce9
@@ -0,0 +1,251 @@
f92ce9
+import os
f92ce9
+import sys
f92ce9
+import time
f92ce9
+import ldap
f92ce9
+import logging
f92ce9
+import socket
f92ce9
+import time
f92ce9
+import logging
f92ce9
+import pytest
f92ce9
+import re
f92ce9
+from lib389 import DirSrv, Entry, tools
f92ce9
+from lib389.tools import DirSrvTools
f92ce9
+from lib389._constants import *
f92ce9
+from lib389.properties import *
f92ce9
+from constants import *
f92ce9
+from ldap.controls.readentry import PreReadControl,PostReadControl
f92ce9
+
f92ce9
+
f92ce9
+SCOPE_IN_CN  = 'in'
f92ce9
+SCOPE_OUT_CN = 'out'
f92ce9
+SCOPE_IN_DN  = 'cn=%s,%s' % (SCOPE_IN_CN, SUFFIX)
f92ce9
+SCOPE_OUT_DN = 'cn=%s,%s' % (SCOPE_OUT_CN, SUFFIX)
f92ce9
+
f92ce9
+PROVISIONING_CN = "provisioning"
f92ce9
+PROVISIONING_DN = "cn=%s,%s" % (PROVISIONING_CN, SCOPE_IN_DN)
f92ce9
+
f92ce9
+
f92ce9
+
f92ce9
+
f92ce9
+ACTIVE_CN = "accounts"
f92ce9
+STAGE_CN  = "staged users"
f92ce9
+DELETE_CN = "deleted users"
f92ce9
+ACTIVE_DN = "cn=%s,%s" % (ACTIVE_CN, SCOPE_IN_DN)
f92ce9
+STAGE_DN  = "cn=%s,%s" % (STAGE_CN, PROVISIONING_DN)
f92ce9
+DELETE_DN  = "cn=%s,%s" % (DELETE_CN, PROVISIONING_DN)
f92ce9
+
f92ce9
+STAGE_USER_CN = "stage guy"
f92ce9
+STAGE_USER_DN = "cn=%s,%s" % (STAGE_USER_CN, STAGE_DN)
f92ce9
+
f92ce9
+ACTIVE_USER_CN = "active guy"
f92ce9
+ACTIVE_USER_DN = "cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN)
f92ce9
+
f92ce9
+OUT_USER_CN = "out guy"
f92ce9
+OUT_USER_DN = "cn=%s,%s" % (OUT_USER_CN, SCOPE_OUT_DN)
f92ce9
+
f92ce9
+STAGE_GROUP_CN = "stage group"
f92ce9
+STAGE_GROUP_DN = "cn=%s,%s" % (STAGE_GROUP_CN, STAGE_DN)
f92ce9
+
f92ce9
+ACTIVE_GROUP_CN = "active group"
f92ce9
+ACTIVE_GROUP_DN = "cn=%s,%s" % (ACTIVE_GROUP_CN, ACTIVE_DN)
f92ce9
+
f92ce9
+OUT_GROUP_CN = "out group"
f92ce9
+OUT_GROUP_DN = "cn=%s,%s" % (OUT_GROUP_CN, SCOPE_OUT_DN)
f92ce9
+
f92ce9
+INDIRECT_ACTIVE_GROUP_CN = "indirect active group"
f92ce9
+INDIRECT_ACTIVE_GROUP_DN = "cn=%s,%s" % (INDIRECT_ACTIVE_GROUP_CN, ACTIVE_DN)
f92ce9
+
f92ce9
+INITIAL_DESC="inital description"
f92ce9
+FINAL_DESC  ="final description"
f92ce9
+
f92ce9
+
f92ce9
+
f92ce9
+log = logging.getLogger(__name__)
f92ce9
+
f92ce9
+installation_prefix = None
f92ce9
+
f92ce9
+
f92ce9
+class TopologyStandalone(object):
f92ce9
+    def __init__(self, standalone):
f92ce9
+        standalone.open()
f92ce9
+        self.standalone = standalone
f92ce9
+
f92ce9
+
f92ce9
+
f92ce9
+@pytest.fixture(scope="module")
f92ce9
+def topology(request):
f92ce9
+    '''
f92ce9
+        This fixture is used to standalone topology for the 'module'.
f92ce9
+        At the beginning, It may exists a standalone instance.
f92ce9
+        It may also exists a backup for the standalone instance.
f92ce9
+    
f92ce9
+        Principle:
f92ce9
+            If standalone instance exists:
f92ce9
+                restart it
f92ce9
+            If backup of standalone exists:
f92ce9
+                create/rebind to standalone
f92ce9
+
f92ce9
+                restore standalone instance from backup
f92ce9
+            else:
f92ce9
+                Cleanup everything
f92ce9
+                    remove instance
f92ce9
+                    remove backup
f92ce9
+                Create instance
f92ce9
+                Create backup
f92ce9
+    '''
f92ce9
+    global installation_prefix
f92ce9
+
f92ce9
+    if installation_prefix:
f92ce9
+        args_instance[SER_DEPLOYED_DIR] = installation_prefix
f92ce9
+    
f92ce9
+    standalone = DirSrv(verbose=False)
f92ce9
+    
f92ce9
+    # Args for the standalone instance
f92ce9
+    args_instance[SER_HOST] = HOST_STANDALONE
f92ce9
+    args_instance[SER_PORT] = PORT_STANDALONE
f92ce9
+    args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
f92ce9
+    args_standalone = args_instance.copy()
f92ce9
+    standalone.allocate(args_standalone)
f92ce9
+        
f92ce9
+    # Get the status of the backups
f92ce9
+    backup_standalone = standalone.checkBackupFS()
f92ce9
+    
f92ce9
+    # Get the status of the instance and restart it if it exists
f92ce9
+    instance_standalone   = standalone.exists()
f92ce9
+    if instance_standalone:
f92ce9
+        # assuming the instance is already stopped, just wait 5 sec max
f92ce9
+        standalone.stop(timeout=5)
f92ce9
+        standalone.start(timeout=10)
f92ce9
+    
f92ce9
+    if backup_standalone:
f92ce9
+        # The backup exist, assuming it is correct 
f92ce9
+        # we just re-init the instance with it
f92ce9
+        if not instance_standalone:
f92ce9
+            standalone.create()
f92ce9
+            # Used to retrieve configuration information (dbdir, confdir...)
f92ce9
+            standalone.open()
f92ce9
+        
f92ce9
+        # restore standalone instance from backup
f92ce9
+        standalone.stop(timeout=10)
f92ce9
+        standalone.restoreFS(backup_standalone)
f92ce9
+        standalone.start(timeout=10)
f92ce9
+        
f92ce9
+    else:
f92ce9
+        # We should be here only in two conditions
f92ce9
+        #      - This is the first time a test involve standalone instance
f92ce9
+        #      - Something weird happened (instance/backup destroyed)
f92ce9
+        #        so we discard everything and recreate all
f92ce9
+        
f92ce9
+        # Remove the backup. So even if we have a specific backup file
f92ce9
+        # (e.g backup_standalone) we clear backup that an instance may have created
f92ce9
+        if backup_standalone:
f92ce9
+            standalone.clearBackupFS()
f92ce9
+        
f92ce9
+        # Remove the instance
f92ce9
+        if instance_standalone:
f92ce9
+            standalone.delete()
f92ce9
+            
f92ce9
+        # Create the instance
f92ce9
+        standalone.create()
f92ce9
+        
f92ce9
+        # Used to retrieve configuration information (dbdir, confdir...)
f92ce9
+        standalone.open()
f92ce9
+                
f92ce9
+        # Time to create the backups
f92ce9
+        standalone.stop(timeout=10)
f92ce9
+        standalone.backupfile = standalone.backupFS()
f92ce9
+        standalone.start(timeout=10)
f92ce9
+
f92ce9
+    # clear the tmp directory
f92ce9
+    standalone.clearTmpDir(__file__)
f92ce9
+
f92ce9
+    # 
f92ce9
+    # Here we have standalone instance up and running
f92ce9
+    # Either coming from a backup recovery
f92ce9
+    # or from a fresh (re)init
f92ce9
+    # Time to return the topology
f92ce9
+    return TopologyStandalone(standalone)
f92ce9
+
f92ce9
+def _header(topology, label):
f92ce9
+    topology.standalone.log.info("\n\n###############################################")
f92ce9
+    topology.standalone.log.info("#######")
f92ce9
+    topology.standalone.log.info("####### %s" % label)
f92ce9
+    topology.standalone.log.info("#######")
f92ce9
+    topology.standalone.log.info("###############################################")
f92ce9
+    
f92ce9
+def _add_user(topology, type='active'):
f92ce9
+    if type == 'active':
f92ce9
+        topology.standalone.add_s(Entry((ACTIVE_USER_DN, {
f92ce9
+                                                'objectclass': "top person inetuser".split(),
f92ce9
+                                                'sn': ACTIVE_USER_CN,
f92ce9
+                                                'cn': ACTIVE_USER_CN,
f92ce9
+                                                'description': INITIAL_DESC})))
f92ce9
+    elif type == 'stage':
f92ce9
+        topology.standalone.add_s(Entry((STAGE_USER_DN, {
f92ce9
+                                                'objectclass': "top person inetuser".split(),
f92ce9
+                                                'sn': STAGE_USER_CN,
f92ce9
+                                                'cn': STAGE_USER_CN})))
f92ce9
+    else:
f92ce9
+        topology.standalone.add_s(Entry((OUT_USER_DN, {
f92ce9
+                                        'objectclass': "top person inetuser".split(),
f92ce9
+                                        'sn': OUT_USER_CN,
f92ce9
+                                        'cn': OUT_USER_CN})))
f92ce9
+
f92ce9
+def test_ticket47920_init(topology):
f92ce9
+    topology.standalone.add_s(Entry((SCOPE_IN_DN, {
f92ce9
+                                                        'objectclass': "top nscontainer".split(),
f92ce9
+                                                        'cn': SCOPE_IN_DN})))
f92ce9
+    topology.standalone.add_s(Entry((ACTIVE_DN, {
f92ce9
+                                                        'objectclass': "top nscontainer".split(),
f92ce9
+                                                        'cn': ACTIVE_CN})))
f92ce9
+
f92ce9
+    # add users
f92ce9
+    _add_user(topology, 'active')
f92ce9
+
f92ce9
+
f92ce9
+def test_ticket47920_mod_readentry_ctrl(topology):
f92ce9
+    _header(topology, 'MOD: with a readentry control')
f92ce9
+    
f92ce9
+    topology.standalone.log.info("Check the initial value of the entry")
f92ce9
+    ent = topology.standalone.getEntry(ACTIVE_USER_DN, ldap.SCOPE_BASE, "(objectclass=*)", ['description'])
f92ce9
+    assert ent.hasAttr('description')
f92ce9
+    assert ent.getValue('description') == INITIAL_DESC
f92ce9
+
f92ce9
+    pr = PostReadControl(criticality=True,attrList=['cn', 'description'])
f92ce9
+    _,_,_,resp_ctrls = topology.standalone.modify_ext_s(ACTIVE_USER_DN, [(ldap.MOD_REPLACE, 'description', [FINAL_DESC])], serverctrls= [pr])
f92ce9
+
f92ce9
+    assert resp_ctrls[0].dn == ACTIVE_USER_DN
f92ce9
+    assert resp_ctrls[0].entry.has_key('description')
f92ce9
+    assert resp_ctrls[0].entry.has_key('cn')
f92ce9
+    print resp_ctrls[0].entry['description']
f92ce9
+
f92ce9
+    ent = topology.standalone.getEntry(ACTIVE_USER_DN, ldap.SCOPE_BASE, "(objectclass=*)", ['description'])
f92ce9
+    assert ent.hasAttr('description')
f92ce9
+    assert ent.getValue('description') == FINAL_DESC
f92ce9
+    
f92ce9
+def test_ticket47920_final(topology):
f92ce9
+    topology.standalone.stop(timeout=10)
f92ce9
+    
f92ce9
+
f92ce9
+
f92ce9
+def run_isolated():
f92ce9
+    '''
f92ce9
+        run_isolated is used to run these test cases independently of a test scheduler (xunit, py.test..)
f92ce9
+        To run isolated without py.test, you need to 
f92ce9
+            - edit this file and comment '@pytest.fixture' line before 'topology' function.
f92ce9
+            - set the installation prefix
f92ce9
+            - run this program
f92ce9
+    '''
f92ce9
+    global installation_prefix
f92ce9
+    installation_prefix =  None
f92ce9
+        
f92ce9
+    topo = topology(True)
f92ce9
+    test_ticket47920_init(topo)
f92ce9
+
f92ce9
+    test_ticket47920_mod_readentry_ctrl(topo)
f92ce9
+    
f92ce9
+    test_ticket47920_final(topo)
f92ce9
+
f92ce9
+if __name__ == '__main__':
f92ce9
+    run_isolated()
f92ce9
+
f92ce9
diff --git a/ldap/servers/slapd/result.c b/ldap/servers/slapd/result.c
f92ce9
index fa1788c..92573d5 100644
f92ce9
--- a/ldap/servers/slapd/result.c
f92ce9
+++ b/ldap/servers/slapd/result.c
f92ce9
@@ -2176,7 +2176,7 @@ encode_read_entry (Slapi_PBlock *pb, Slapi_Entry *e, char **attrs, int alluserat
f92ce9
     }
f92ce9
 
f92ce9
     /* Start the ber encoding with the DN */
f92ce9
-    rc = ber_printf( ber, "{s{", slapi_entry_get_dn_const(e) );
f92ce9
+    rc = ber_printf( ber, "t{s{", LDAP_RES_SEARCH_ENTRY, slapi_entry_get_dn_const(e) );
f92ce9
     if ( rc == -1 ) {
f92ce9
         rc = -1;
f92ce9
         goto cleanup;
f92ce9
-- 
f92ce9
1.9.3
f92ce9