|
|
a77461 |
From 63e1ceac74cdfda7cf432537a18670e9562b58df Mon Sep 17 00:00:00 2001
|
|
|
a77461 |
From: progier389 <progier@redhat.com>
|
|
|
a77461 |
Date: Mon, 2 May 2022 18:43:25 +0200
|
|
|
a77461 |
Subject: [PATCH] Issue 5126 - Memory leak in slapi_ldap_get_lderrno (#5153)
|
|
|
a77461 |
MIME-Version: 1.0
|
|
|
a77461 |
Content-Type: text/plain; charset=UTF-8
|
|
|
a77461 |
Content-Transfer-Encoding: 8bit
|
|
|
a77461 |
|
|
|
a77461 |
* Issue 5126 - Memory leak in slapi_ldap_get_lderrno
|
|
|
a77461 |
|
|
|
a77461 |
The problem is that some time ago libldap API replaced ​LDAP_OPT_ERROR_STRING whose data should not be freed by
|
|
|
a77461 |
LDAP_OPT_DIAGNOSTIC_MESSAGE whose data must be freed.
|
|
|
a77461 |
slapi_ldap_get_lderrno was adapted to use the new option but the callers were not modified to free the value.
|
|
|
a77461 |
|
|
|
a77461 |
The Solution:
|
|
|
a77461 |
Insure that we also need to free slapi_ldap_get_lderrno value if legacy LDAP_OPT_ERROR_STRING is used (by duping the value)
|
|
|
a77461 |
Insure that the callers free the value.
|
|
|
a77461 |
|
|
|
a77461 |
Added test case about replication using SASL/Digest-md5 authentication
|
|
|
a77461 |
Added test case to check this leak
|
|
|
a77461 |
Also updated test case about SASL/GSSAPI to be comapatible with current lib389 framework but marked as skipped because it requires a specific configuration (This path should be tested by IPA tests)
|
|
|
a77461 |
Fixed valgrind lib389 function to run on prefixed installation without needing to be root.
|
|
|
a77461 |
At last I also improved lib389 mapped object to have a better diagnostic when LDAP operation fails (by adding the request within the exception)
|
|
|
a77461 |
|
|
|
a77461 |
issue: 5126 https://github.com/389ds/389-ds-base/issues/5126
|
|
|
a77461 |
|
|
|
a77461 |
Reviewd by: @droideck
|
|
|
a77461 |
|
|
|
a77461 |
(cherry picked from commit 4d89e11494233d8297896540bc752cfdbab2cc69)
|
|
|
a77461 |
---
|
|
|
a77461 |
.../suites/gssapi_repl/gssapi_repl_test.py | 31 ++-
|
|
|
a77461 |
.../tests/suites/replication/sasl_m2_test.py | 185 ++++++++++++++++++
|
|
|
a77461 |
ldap/servers/plugins/chainingdb/cb_search.c | 6 +-
|
|
|
a77461 |
ldap/servers/plugins/passthru/ptbind.c | 2 +
|
|
|
a77461 |
.../plugins/replication/repl5_connection.c | 4 +
|
|
|
a77461 |
.../plugins/replication/windows_connection.c | 3 +
|
|
|
a77461 |
ldap/servers/slapd/ldaputil.c | 6 +
|
|
|
a77461 |
src/lib389/lib389/_mapped_object.py | 76 ++++---
|
|
|
a77461 |
src/lib389/lib389/utils.py | 40 +++-
|
|
|
a77461 |
9 files changed, 311 insertions(+), 42 deletions(-)
|
|
|
a77461 |
create mode 100644 dirsrvtests/tests/suites/replication/sasl_m2_test.py
|
|
|
a77461 |
|
|
|
a77461 |
diff --git a/dirsrvtests/tests/suites/gssapi_repl/gssapi_repl_test.py b/dirsrvtests/tests/suites/gssapi_repl/gssapi_repl_test.py
|
|
|
a77461 |
index 41f323c06..402684aab 100644
|
|
|
a77461 |
--- a/dirsrvtests/tests/suites/gssapi_repl/gssapi_repl_test.py
|
|
|
a77461 |
+++ b/dirsrvtests/tests/suites/gssapi_repl/gssapi_repl_test.py
|
|
|
a77461 |
@@ -9,6 +9,7 @@
|
|
|
a77461 |
import pytest
|
|
|
a77461 |
from lib389.tasks import *
|
|
|
a77461 |
from lib389.utils import *
|
|
|
a77461 |
+from lib389.agreement import *
|
|
|
a77461 |
from lib389.topologies import topology_m2
|
|
|
a77461 |
|
|
|
a77461 |
pytestmark = pytest.mark.tier2
|
|
|
a77461 |
@@ -65,10 +66,27 @@ def _allow_machine_account(inst, name):
|
|
|
a77461 |
# First we need to get the mapping tree dn
|
|
|
a77461 |
mt = inst.mappingtree.list(suffix=DEFAULT_SUFFIX)[0]
|
|
|
a77461 |
inst.modify_s('cn=replica,%s' % mt.dn, [
|
|
|
a77461 |
- (ldap.MOD_REPLACE, 'nsDS5ReplicaBindDN', "uid=%s,ou=Machines,%s" % (name, DEFAULT_SUFFIX))
|
|
|
a77461 |
+ (ldap.MOD_REPLACE, 'nsDS5ReplicaBindDN', f"uid={name},ou=Machines,{DEFAULT_SUFFIX}".encode('utf-8'))
|
|
|
a77461 |
])
|
|
|
a77461 |
|
|
|
a77461 |
-
|
|
|
a77461 |
+def _verify_etc_hosts():
|
|
|
a77461 |
+ #Check if /etc/hosts is compatible with the test
|
|
|
a77461 |
+ NEEDED_HOSTS = ( ('ldapkdc.example.com', '127.0.0.1'),
|
|
|
a77461 |
+ ('ldapkdc1.example.com', '127.0.1.1'),
|
|
|
a77461 |
+ ('ldapkdc2.example.com', '127.0.2.1'))
|
|
|
a77461 |
+ found_hosts = {}
|
|
|
a77461 |
+ with open('/etc/hosts','r') as f:
|
|
|
a77461 |
+ for l in f:
|
|
|
a77461 |
+ s = l.split()
|
|
|
a77461 |
+ if len(s) < 2:
|
|
|
a77461 |
+ continue
|
|
|
a77461 |
+ for nh in NEEDED_HOSTS:
|
|
|
a77461 |
+ if (s[0] == nh[1] and s[1] == nh[0]):
|
|
|
a77461 |
+ found_hosts[s[1]] = True
|
|
|
a77461 |
+ return len(found_hosts) == len(NEEDED_HOSTS)
|
|
|
a77461 |
+
|
|
|
a77461 |
+@pytest.mark.skipif(not _verify_etc_hosts(), reason="/etc/hosts does not contains the needed hosts.")
|
|
|
a77461 |
+@pytest.mark.skipif(True, reason="Test disabled because it requires specific kerberos requirement (server principal, keytab, etc ...")
|
|
|
a77461 |
def test_gssapi_repl(topology_m2):
|
|
|
a77461 |
"""Test gssapi authenticated replication agreement of two suppliers using KDC
|
|
|
a77461 |
|
|
|
a77461 |
@@ -94,8 +112,6 @@ def test_gssapi_repl(topology_m2):
|
|
|
a77461 |
6. Test User should be created on M1 and M2 both
|
|
|
a77461 |
7. Test User should be created on M1 and M2 both
|
|
|
a77461 |
"""
|
|
|
a77461 |
-
|
|
|
a77461 |
- return
|
|
|
a77461 |
supplier1 = topology_m2.ms["supplier1"]
|
|
|
a77461 |
supplier2 = topology_m2.ms["supplier2"]
|
|
|
a77461 |
|
|
|
a77461 |
@@ -121,6 +137,7 @@ def test_gssapi_repl(topology_m2):
|
|
|
a77461 |
properties = {RA_NAME: r'meTo_$host:$port',
|
|
|
a77461 |
RA_METHOD: 'SASL/GSSAPI',
|
|
|
a77461 |
RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}
|
|
|
a77461 |
+ supplier1.agreement.delete(suffix=SUFFIX, consumer_host=supplier2.host, consumer_port=supplier2.port)
|
|
|
a77461 |
m1_m2_agmt = supplier1.agreement.create(suffix=SUFFIX, host=supplier2.host, port=supplier2.port, properties=properties)
|
|
|
a77461 |
if not m1_m2_agmt:
|
|
|
a77461 |
log.fatal("Fail to create a supplier -> supplier replica agreement")
|
|
|
a77461 |
@@ -133,6 +150,7 @@ def test_gssapi_repl(topology_m2):
|
|
|
a77461 |
properties = {RA_NAME: r'meTo_$host:$port',
|
|
|
a77461 |
RA_METHOD: 'SASL/GSSAPI',
|
|
|
a77461 |
RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}
|
|
|
a77461 |
+ supplier2.agreement.delete(suffix=SUFFIX, consumer_host=supplier1.host, consumer_port=supplier1.port)
|
|
|
a77461 |
m2_m1_agmt = supplier2.agreement.create(suffix=SUFFIX, host=supplier1.host, port=supplier1.port, properties=properties)
|
|
|
a77461 |
if not m2_m1_agmt:
|
|
|
a77461 |
log.fatal("Fail to create a supplier -> supplier replica agreement")
|
|
|
a77461 |
@@ -145,8 +163,9 @@ def test_gssapi_repl(topology_m2):
|
|
|
a77461 |
#
|
|
|
a77461 |
# Initialize all the agreements
|
|
|
a77461 |
#
|
|
|
a77461 |
- supplier1.agreement.init(SUFFIX, HOST_SUPPLIER_2, PORT_SUPPLIER_2)
|
|
|
a77461 |
- supplier1.waitForReplInit(m1_m2_agmt)
|
|
|
a77461 |
+ agmt = Agreement(supplier1, m1_m2_agmt)
|
|
|
a77461 |
+ agmt.begin_reinit()
|
|
|
a77461 |
+ agmt.wait_reinit()
|
|
|
a77461 |
|
|
|
a77461 |
# Check replication is working...
|
|
|
a77461 |
if supplier1.testReplication(DEFAULT_SUFFIX, supplier2):
|
|
|
a77461 |
diff --git a/dirsrvtests/tests/suites/replication/sasl_m2_test.py b/dirsrvtests/tests/suites/replication/sasl_m2_test.py
|
|
|
a77461 |
new file mode 100644
|
|
|
a77461 |
index 000000000..d7406ac7e
|
|
|
a77461 |
--- /dev/null
|
|
|
a77461 |
+++ b/dirsrvtests/tests/suites/replication/sasl_m2_test.py
|
|
|
a77461 |
@@ -0,0 +1,185 @@
|
|
|
a77461 |
+# --- BEGIN COPYRIGHT BLOCK ---
|
|
|
a77461 |
+# Copyright (C) 2022 Red Hat, Inc.
|
|
|
a77461 |
+# All rights reserved.
|
|
|
a77461 |
+#
|
|
|
a77461 |
+# License: GPL (version 3 or any later version).
|
|
|
a77461 |
+# See LICENSE for details.
|
|
|
a77461 |
+# --- END COPYRIGHT BLOCK ---
|
|
|
a77461 |
+#
|
|
|
a77461 |
+import logging
|
|
|
a77461 |
+import os
|
|
|
a77461 |
+import pytest
|
|
|
a77461 |
+import ldap
|
|
|
a77461 |
+import uuid
|
|
|
a77461 |
+from lib389.utils import ds_is_older, valgrind_enable, valgrind_disable, valgrind_get_results_file, valgrind_check_file
|
|
|
a77461 |
+
|
|
|
a77461 |
+from lib389.idm.services import ServiceAccounts
|
|
|
a77461 |
+from lib389.idm.group import Groups
|
|
|
a77461 |
+from lib389.config import CertmapLegacy, Config
|
|
|
a77461 |
+from lib389._constants import DEFAULT_SUFFIX
|
|
|
a77461 |
+from lib389.agreement import Agreements
|
|
|
a77461 |
+from lib389._mapped_object import DSLdapObject
|
|
|
a77461 |
+from lib389.replica import ReplicationManager, Replicas, BootstrapReplicationManager
|
|
|
a77461 |
+from lib389.topologies import topology_m2 as topo_m2
|
|
|
a77461 |
+
|
|
|
a77461 |
+pytestmark = pytest.mark.tier1
|
|
|
a77461 |
+
|
|
|
a77461 |
+DEBUGGING = os.getenv("DEBUGGING", default=False)
|
|
|
a77461 |
+if DEBUGGING:
|
|
|
a77461 |
+ logging.getLogger(__name__).setLevel(logging.DEBUG)
|
|
|
a77461 |
+else:
|
|
|
a77461 |
+ logging.getLogger(__name__).setLevel(logging.INFO)
|
|
|
a77461 |
+log = logging.getLogger(__name__)
|
|
|
a77461 |
+
|
|
|
a77461 |
+def set_sasl_md5_client_auth(inst, to):
|
|
|
a77461 |
+ # Create the certmap before we restart
|
|
|
a77461 |
+ cm = CertmapLegacy(to)
|
|
|
a77461 |
+ certmaps = cm.list()
|
|
|
a77461 |
+ certmaps['default']['nsSaslMapRegexString'] = '^dn:\\(.*\\)'
|
|
|
a77461 |
+ certmaps['default']['nsSaslMapBaseDNTemplate'] = 'cn=config'
|
|
|
a77461 |
+ certmaps['default']['nsSaslMapFilterTemplate'] = '(objectclass=*)'
|
|
|
a77461 |
+ cm.set(certmaps)
|
|
|
a77461 |
+
|
|
|
a77461 |
+ Config(to).replace("passwordStorageScheme", 'CLEAR')
|
|
|
a77461 |
+
|
|
|
a77461 |
+ # Create a repl manager on the replica
|
|
|
a77461 |
+ replication_manager_pwd = 'secret12'
|
|
|
a77461 |
+ brm = BootstrapReplicationManager(to)
|
|
|
a77461 |
+ try:
|
|
|
a77461 |
+ brm.delete()
|
|
|
a77461 |
+ except ldap.NO_SUCH_OBJECT:
|
|
|
a77461 |
+ pass
|
|
|
a77461 |
+ brm.create(properties={
|
|
|
a77461 |
+ 'cn': brm.common_name,
|
|
|
a77461 |
+ 'userPassword': replication_manager_pwd
|
|
|
a77461 |
+ })
|
|
|
a77461 |
+ replication_manager_dn = brm.dn
|
|
|
a77461 |
+
|
|
|
a77461 |
+ replica = Replicas(inst).get(DEFAULT_SUFFIX)
|
|
|
a77461 |
+ replica.set('nsDS5ReplicaBindDN', brm.dn)
|
|
|
a77461 |
+ replica.remove_all('nsDS5ReplicaBindDNgroup')
|
|
|
a77461 |
+ agmt = replica.get_agreements().list()[0]
|
|
|
a77461 |
+ agmt.replace_many(
|
|
|
a77461 |
+ ('nsDS5ReplicaBindMethod', 'SASL/DIGEST-MD5'),
|
|
|
a77461 |
+ ('nsDS5ReplicaTransportInfo', 'LDAP'),
|
|
|
a77461 |
+ ('nsDS5ReplicaPort', str(to.port)),
|
|
|
a77461 |
+ ('nsDS5ReplicaBindDN', replication_manager_dn),
|
|
|
a77461 |
+ ('nsDS5ReplicaCredentials', replication_manager_pwd),
|
|
|
a77461 |
+ )
|
|
|
a77461 |
+
|
|
|
a77461 |
+
|
|
|
a77461 |
+def gen_valgrind_wrapper(dir):
|
|
|
a77461 |
+ name=f"{dir}/VALGRIND"
|
|
|
a77461 |
+ with open(name, 'w') as f:
|
|
|
a77461 |
+ f.write('#!/bin/sh\n')
|
|
|
a77461 |
+ f.write('export SASL_PATH=foo\n')
|
|
|
a77461 |
+ f.write(f'valgrind -q --tool=memcheck --leak-check=yes --leak-resolution=high --num-callers=50 --log-file=/var/tmp/slapd.vg.$$ {dir}/ns-slapd.original "$@"\n')
|
|
|
a77461 |
+ os.chmod(name, 0o755)
|
|
|
a77461 |
+ return name
|
|
|
a77461 |
+
|
|
|
a77461 |
+@pytest.fixture
|
|
|
a77461 |
+def use_valgrind(topo_m2, request):
|
|
|
a77461 |
+ """Adds entries to the supplier1"""
|
|
|
a77461 |
+
|
|
|
a77461 |
+ log.info("Enable valgrind")
|
|
|
a77461 |
+ m1 = topo_m2.ms['supplier1']
|
|
|
a77461 |
+ m2 = topo_m2.ms['supplier2']
|
|
|
a77461 |
+ if m1.has_asan():
|
|
|
a77461 |
+ pytest.skip('Tescase using valgring cannot run on asan enabled build')
|
|
|
a77461 |
+ return
|
|
|
a77461 |
+ set_sasl_md5_client_auth(m1, m2)
|
|
|
a77461 |
+ set_sasl_md5_client_auth(m2, m1)
|
|
|
a77461 |
+ m1.stop()
|
|
|
a77461 |
+ m2.stop()
|
|
|
a77461 |
+ m1.systemd_override = False
|
|
|
a77461 |
+ m2.systemd_override = False
|
|
|
a77461 |
+ valgrind_enable(m1.ds_paths.sbin_dir, gen_valgrind_wrapper(m1.ds_paths.sbin_dir))
|
|
|
a77461 |
+
|
|
|
a77461 |
+ def fin():
|
|
|
a77461 |
+ log.info("Disable valgrind")
|
|
|
a77461 |
+ valgrind_disable(m1.ds_paths.sbin_dir)
|
|
|
a77461 |
+
|
|
|
a77461 |
+ request.addfinalizer(fin)
|
|
|
a77461 |
+
|
|
|
a77461 |
+
|
|
|
a77461 |
+def test_repl_sasl_md5_auth(topo_m2):
|
|
|
a77461 |
+ """Test replication with SASL digest-md5 authentication
|
|
|
a77461 |
+
|
|
|
a77461 |
+ :id: 922d16f8-662a-4915-a39e-0aecd7c8e6e2
|
|
|
a77461 |
+ :setup: Two supplier replication
|
|
|
a77461 |
+ :steps:
|
|
|
a77461 |
+ 1. Set sasl digest/md4 on both suppliers
|
|
|
a77461 |
+ 2. Restart the instance
|
|
|
a77461 |
+ 3. Check that replication works
|
|
|
a77461 |
+ :expectedresults:
|
|
|
a77461 |
+ 1. Success
|
|
|
a77461 |
+ 2. Success
|
|
|
a77461 |
+ 3. Replication works
|
|
|
a77461 |
+ """
|
|
|
a77461 |
+
|
|
|
a77461 |
+ m1 = topo_m2.ms['supplier1']
|
|
|
a77461 |
+ m2 = topo_m2.ms['supplier2']
|
|
|
a77461 |
+
|
|
|
a77461 |
+ set_sasl_md5_client_auth(m1, m2)
|
|
|
a77461 |
+ set_sasl_md5_client_auth(m2, m1)
|
|
|
a77461 |
+
|
|
|
a77461 |
+ m1.restart()
|
|
|
a77461 |
+ m2.restart()
|
|
|
a77461 |
+
|
|
|
a77461 |
+ repl = ReplicationManager(DEFAULT_SUFFIX)
|
|
|
a77461 |
+ repl.test_replication_topology(topo_m2)
|
|
|
a77461 |
+
|
|
|
a77461 |
+
|
|
|
a77461 |
+@pytest.mark.skipif(not os.path.exists('/usr/bin/valgrind'), reason="valgrind is not installed.")
|
|
|
a77461 |
+def test_repl_sasl_leak(topo_m2, use_valgrind):
|
|
|
a77461 |
+ """Test replication with SASL digest-md5 authentication
|
|
|
a77461 |
+
|
|
|
a77461 |
+ :id: 180e088e-841c-11ec-af4f-482ae39447e5
|
|
|
a77461 |
+ :setup: Two supplier replication, valgrind
|
|
|
a77461 |
+ :steps:
|
|
|
a77461 |
+ 1. Set sasl digest/md4 on both suppliers
|
|
|
a77461 |
+ 2. Break sasl by setting invalid PATH
|
|
|
a77461 |
+ 3. Restart the instances
|
|
|
a77461 |
+ 4. Perform a change
|
|
|
a77461 |
+ 5. Poke replication 100 times
|
|
|
a77461 |
+ 6. Stop server
|
|
|
a77461 |
+ 7. Check presence of "SASL(-4): no mechanism available: No worthy mechs found" message in error log
|
|
|
a77461 |
+ 8 Check that there is no leak about slapi_ldap_get_lderrno
|
|
|
a77461 |
+ :expectedresults:
|
|
|
a77461 |
+ 1. Success
|
|
|
a77461 |
+ 2. Success
|
|
|
a77461 |
+ 2. Success
|
|
|
a77461 |
+ 4. Success
|
|
|
a77461 |
+ 5. Success
|
|
|
a77461 |
+ 6. Success
|
|
|
a77461 |
+ 7. Success
|
|
|
a77461 |
+ 8. Success
|
|
|
a77461 |
+ """
|
|
|
a77461 |
+
|
|
|
a77461 |
+ m1 = topo_m2.ms['supplier1']
|
|
|
a77461 |
+ m2 = topo_m2.ms['supplier2']
|
|
|
a77461 |
+
|
|
|
a77461 |
+ os.environ["SASL_PATH"] = 'foo'
|
|
|
a77461 |
+
|
|
|
a77461 |
+ m1.start()
|
|
|
a77461 |
+ m2.start()
|
|
|
a77461 |
+
|
|
|
a77461 |
+ resfile=valgrind_get_results_file(m1)
|
|
|
a77461 |
+
|
|
|
a77461 |
+ # Perform a change
|
|
|
a77461 |
+ from_groups = Groups(m1, basedn=DEFAULT_SUFFIX, rdn=None)
|
|
|
a77461 |
+ from_group = from_groups.get('replication_managers')
|
|
|
a77461 |
+ change = str(uuid.uuid4())
|
|
|
a77461 |
+ from_group.replace('description', change)
|
|
|
a77461 |
+
|
|
|
a77461 |
+ # Poke replication to trigger thev leak
|
|
|
a77461 |
+ replica = Replicas(m1).get(DEFAULT_SUFFIX)
|
|
|
a77461 |
+ agmt = Agreements(m1, replica.dn).list()[0]
|
|
|
a77461 |
+ for i in range(0, 100):
|
|
|
a77461 |
+ agmt.pause()
|
|
|
a77461 |
+ agmt.resume()
|
|
|
a77461 |
+
|
|
|
a77461 |
+ m1.stop()
|
|
|
a77461 |
+ assert m1.searchErrorsLog("worthy")
|
|
|
a77461 |
+ assert not valgrind_check_file(resfile, 'slapi_ldap_get_lderrno');
|
|
|
a77461 |
+
|
|
|
a77461 |
diff --git a/ldap/servers/plugins/chainingdb/cb_search.c b/ldap/servers/plugins/chainingdb/cb_search.c
|
|
|
a77461 |
index ffc8f56f8..d6f30b357 100644
|
|
|
a77461 |
--- a/ldap/servers/plugins/chainingdb/cb_search.c
|
|
|
a77461 |
+++ b/ldap/servers/plugins/chainingdb/cb_search.c
|
|
|
a77461 |
@@ -348,10 +348,9 @@ chainingdb_build_candidate_list(Slapi_PBlock *pb)
|
|
|
a77461 |
warned_rc = 1;
|
|
|
a77461 |
}
|
|
|
a77461 |
cb_send_ldap_result(pb, rc, NULL, ENDUSERMSG, 0, NULL);
|
|
|
a77461 |
- /* BEWARE: matched_msg and error_msg points */
|
|
|
a77461 |
+ /* BEWARE: matched_msg points */
|
|
|
a77461 |
/* to ld fields. */
|
|
|
a77461 |
matched_msg = NULL;
|
|
|
a77461 |
- error_msg = NULL;
|
|
|
a77461 |
rc = -1;
|
|
|
a77461 |
}
|
|
|
a77461 |
|
|
|
a77461 |
@@ -695,10 +694,9 @@ chainingdb_next_search_entry(Slapi_PBlock *pb)
|
|
|
a77461 |
}
|
|
|
a77461 |
cb_send_ldap_result(pb, rc, matched_msg, ENDUSERMSG, 0, NULL);
|
|
|
a77461 |
|
|
|
a77461 |
- /* BEWARE: Don't free matched_msg && error_msg */
|
|
|
a77461 |
+ /* BEWARE: Don't free matched_msg */
|
|
|
a77461 |
/* Points to the ld fields */
|
|
|
a77461 |
matched_msg = NULL;
|
|
|
a77461 |
- error_msg = NULL;
|
|
|
a77461 |
retcode = -1;
|
|
|
a77461 |
} else {
|
|
|
a77461 |
/* Add control response sent by the farm server */
|
|
|
a77461 |
diff --git a/ldap/servers/plugins/passthru/ptbind.c b/ldap/servers/plugins/passthru/ptbind.c
|
|
|
a77461 |
index 705ab2c3a..3e79b47f6 100644
|
|
|
a77461 |
--- a/ldap/servers/plugins/passthru/ptbind.c
|
|
|
a77461 |
+++ b/ldap/servers/plugins/passthru/ptbind.c
|
|
|
a77461 |
@@ -33,6 +33,8 @@ passthru_simple_bind_once_s(PassThruServer *srvr, const char *dn, struct berval
|
|
|
a77461 |
* are only interested in recovering silently when the remote server is up
|
|
|
a77461 |
* but decided to close our connection, we retry without pausing between
|
|
|
a77461 |
* attempts.
|
|
|
a77461 |
+ *
|
|
|
a77461 |
+ * Note that errmsgp must be freed by the caller.
|
|
|
a77461 |
*/
|
|
|
a77461 |
int
|
|
|
a77461 |
passthru_simple_bind_s(Slapi_PBlock *pb, PassThruServer *srvr, int tries, const char *dn, struct berval *creds, LDAPControl **reqctrls, int *lderrnop, char **matcheddnp, char **errmsgp, struct berval ***refurlsp, LDAPControl ***resctrlsp)
|
|
|
a77461 |
diff --git a/ldap/servers/plugins/replication/repl5_connection.c b/ldap/servers/plugins/replication/repl5_connection.c
|
|
|
a77461 |
index 2dd74f9e7..b6bc21c46 100644
|
|
|
a77461 |
--- a/ldap/servers/plugins/replication/repl5_connection.c
|
|
|
a77461 |
+++ b/ldap/servers/plugins/replication/repl5_connection.c
|
|
|
a77461 |
@@ -244,6 +244,7 @@ conn_delete_internal(Repl_Connection *conn)
|
|
|
a77461 |
PR_ASSERT(NULL != conn);
|
|
|
a77461 |
close_connection_internal(conn);
|
|
|
a77461 |
/* slapi_ch_free accepts NULL pointer */
|
|
|
a77461 |
+ slapi_ch_free_string(&conn->last_ldap_errmsg);
|
|
|
a77461 |
slapi_ch_free((void **)&conn->hostname);
|
|
|
a77461 |
slapi_ch_free((void **)&conn->binddn);
|
|
|
a77461 |
slapi_ch_free((void **)&conn->plain);
|
|
|
a77461 |
@@ -450,6 +451,7 @@ conn_read_result_ex(Repl_Connection *conn, char **retoidp, struct berval **retda
|
|
|
a77461 |
char *s = NULL;
|
|
|
a77461 |
|
|
|
a77461 |
rc = slapi_ldap_get_lderrno(conn->ld, NULL, &s);
|
|
|
a77461 |
+ slapi_ch_free_string(&conn->last_ldap_errmsg);
|
|
|
a77461 |
conn->last_ldap_errmsg = s;
|
|
|
a77461 |
conn->last_ldap_error = rc;
|
|
|
a77461 |
/* some errors will require a disconnect and retry the connection
|
|
|
a77461 |
@@ -1937,6 +1939,7 @@ bind_and_check_pwp(Repl_Connection *conn, char *binddn, char *password)
|
|
|
a77461 |
agmt_get_long_name(conn->agmt),
|
|
|
a77461 |
mech ? mech : "SIMPLE", rc,
|
|
|
a77461 |
ldap_err2string(rc), errmsg ? errmsg : "");
|
|
|
a77461 |
+ slapi_ch_free_string(&errmsg);
|
|
|
a77461 |
} else {
|
|
|
a77461 |
char *errmsg = NULL;
|
|
|
a77461 |
/* errmsg is a pointer directly into the ld structure - do not free */
|
|
|
a77461 |
@@ -1946,6 +1949,7 @@ bind_and_check_pwp(Repl_Connection *conn, char *binddn, char *password)
|
|
|
a77461 |
agmt_get_long_name(conn->agmt),
|
|
|
a77461 |
mech ? mech : "SIMPLE", rc,
|
|
|
a77461 |
ldap_err2string(rc), errmsg ? errmsg : "");
|
|
|
a77461 |
+ slapi_ch_free_string(&errmsg);
|
|
|
a77461 |
}
|
|
|
a77461 |
|
|
|
a77461 |
return (CONN_OPERATION_FAILED);
|
|
|
a77461 |
diff --git a/ldap/servers/plugins/replication/windows_connection.c b/ldap/servers/plugins/replication/windows_connection.c
|
|
|
a77461 |
index 5eca5fad1..d3f6a4e93 100644
|
|
|
a77461 |
--- a/ldap/servers/plugins/replication/windows_connection.c
|
|
|
a77461 |
+++ b/ldap/servers/plugins/replication/windows_connection.c
|
|
|
a77461 |
@@ -331,6 +331,7 @@ windows_perform_operation(Repl_Connection *conn, int optype, const char *dn, LDA
|
|
|
a77461 |
"windows_perform_operation - %s: Received error %d: %s for %s operation\n",
|
|
|
a77461 |
agmt_get_long_name(conn->agmt),
|
|
|
a77461 |
rc, s ? s : "NULL", op_string);
|
|
|
a77461 |
+ slapi_ch_free_string(&s);
|
|
|
a77461 |
conn->last_ldap_error = rc;
|
|
|
a77461 |
/* some errors will require a disconnect and retry the connection
|
|
|
a77461 |
later */
|
|
|
a77461 |
@@ -1709,6 +1710,7 @@ bind_and_check_pwp(Repl_Connection *conn, char *binddn, char *password)
|
|
|
a77461 |
agmt_get_long_name(conn->agmt),
|
|
|
a77461 |
mech ? mech : "SIMPLE", rc,
|
|
|
a77461 |
ldap_err2string(rc), errmsg);
|
|
|
a77461 |
+ slapi_ch_free_string(&errmsg);
|
|
|
a77461 |
} else {
|
|
|
a77461 |
char *errmsg = NULL;
|
|
|
a77461 |
/* errmsg is a pointer directly into the ld structure - do not free */
|
|
|
a77461 |
@@ -1718,6 +1720,7 @@ bind_and_check_pwp(Repl_Connection *conn, char *binddn, char *password)
|
|
|
a77461 |
agmt_get_long_name(conn->agmt),
|
|
|
a77461 |
mech ? mech : "SIMPLE", rc,
|
|
|
a77461 |
ldap_err2string(rc), errmsg);
|
|
|
a77461 |
+ slapi_ch_free_string(&errmsg);
|
|
|
a77461 |
}
|
|
|
a77461 |
|
|
|
a77461 |
slapi_log_err(SLAPI_LOG_TRACE, windows_repl_plugin_name, "<= bind_and_check_pwp - CONN_OPERATION_FAILED\n");
|
|
|
a77461 |
diff --git a/ldap/servers/slapd/ldaputil.c b/ldap/servers/slapd/ldaputil.c
|
|
|
a77461 |
index 336ca3912..db3300e30 100644
|
|
|
a77461 |
--- a/ldap/servers/slapd/ldaputil.c
|
|
|
a77461 |
+++ b/ldap/servers/slapd/ldaputil.c
|
|
|
a77461 |
@@ -375,6 +375,8 @@ slapi_ldap_url_parse(const char *url, LDAPURLDesc **ludpp, int require_dn, int *
|
|
|
a77461 |
|
|
|
a77461 |
#include <sasl/sasl.h>
|
|
|
a77461 |
|
|
|
a77461 |
+
|
|
|
a77461 |
+/* Warning: caller must free s (if not NULL) */
|
|
|
a77461 |
int
|
|
|
a77461 |
slapi_ldap_get_lderrno(LDAP *ld, char **m, char **s)
|
|
|
a77461 |
{
|
|
|
a77461 |
@@ -389,6 +391,9 @@ slapi_ldap_get_lderrno(LDAP *ld, char **m, char **s)
|
|
|
a77461 |
ldap_get_option(ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, s);
|
|
|
a77461 |
#else
|
|
|
a77461 |
ldap_get_option(ld, LDAP_OPT_ERROR_STRING, s);
|
|
|
a77461 |
+ if (*s) {
|
|
|
a77461 |
+ *s = slapi_ch_strdup(*s);
|
|
|
a77461 |
+ }
|
|
|
a77461 |
#endif
|
|
|
a77461 |
}
|
|
|
a77461 |
return rc;
|
|
|
a77461 |
@@ -1517,6 +1522,7 @@ slapd_ldap_sasl_interactive_bind(
|
|
|
a77461 |
mech ? mech : "SIMPLE",
|
|
|
a77461 |
rc, ldap_err2string(rc), errmsg,
|
|
|
a77461 |
errno, slapd_system_strerror(errno));
|
|
|
a77461 |
+ slapi_ch_free_string(&errmsg);
|
|
|
a77461 |
if (can_retry_bind(ld, mech, bindid, creds, rc, errmsg)) {
|
|
|
a77461 |
; /* pass through to retry one time */
|
|
|
a77461 |
} else {
|
|
|
a77461 |
diff --git a/src/lib389/lib389/_mapped_object.py b/src/lib389/lib389/_mapped_object.py
|
|
|
a77461 |
index 48d3879a3..1c314322b 100644
|
|
|
a77461 |
--- a/src/lib389/lib389/_mapped_object.py
|
|
|
a77461 |
+++ b/src/lib389/lib389/_mapped_object.py
|
|
|
a77461 |
@@ -67,6 +67,34 @@ def _gen_filter(attrtypes, values, extra=None):
|
|
|
a77461 |
return filt
|
|
|
a77461 |
|
|
|
a77461 |
|
|
|
a77461 |
+# Define wrappers around the ldap operation to have a clear diagnostic
|
|
|
a77461 |
+def _ldap_op_s(inst, f, fname, *args, **kwargs):
|
|
|
a77461 |
+ # f.__name__ says 'inner' so the wanted name is provided as argument
|
|
|
a77461 |
+ try:
|
|
|
a77461 |
+ return f(*args, **kwargs)
|
|
|
a77461 |
+ except ldap.LDAPError as e:
|
|
|
a77461 |
+ new_desc = f"{fname}({args},{kwargs}) on instance {inst.serverid}";
|
|
|
a77461 |
+ if len(e.args) >= 1:
|
|
|
a77461 |
+ e.args[0]['ldap_request'] = new_desc
|
|
|
a77461 |
+ logging.getLogger().error(f"args={e.args}")
|
|
|
a77461 |
+ raise
|
|
|
a77461 |
+
|
|
|
a77461 |
+def _add_ext_s(inst, *args, **kwargs):
|
|
|
a77461 |
+ return _ldap_op_s(inst, inst.add_ext_s, 'add_ext_s', *args, **kwargs)
|
|
|
a77461 |
+
|
|
|
a77461 |
+def _modify_ext_s(inst, *args, **kwargs):
|
|
|
a77461 |
+ return _ldap_op_s(inst, inst.modify_ext_s, 'modify_ext_s', *args, **kwargs)
|
|
|
a77461 |
+
|
|
|
a77461 |
+def _delete_ext_s(inst, *args, **kwargs):
|
|
|
a77461 |
+ return _ldap_op_s(inst, inst.delete_ext_s, 'delete_ext_s', *args, **kwargs)
|
|
|
a77461 |
+
|
|
|
a77461 |
+def _search_ext_s(inst, *args, **kwargs):
|
|
|
a77461 |
+ return _ldap_op_s(inst, inst.search_ext_s, 'search_ext_s', *args, **kwargs)
|
|
|
a77461 |
+
|
|
|
a77461 |
+def _search_s(inst, *args, **kwargs):
|
|
|
a77461 |
+ return _ldap_op_s(inst, inst.search_s, 'search_s', *args, **kwargs)
|
|
|
a77461 |
+
|
|
|
a77461 |
+
|
|
|
a77461 |
class DSLogging(object):
|
|
|
a77461 |
"""The benefit of this is automatic name detection, and correct application
|
|
|
a77461 |
of level and verbosity to the object.
|
|
|
a77461 |
@@ -129,7 +157,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
:returns: Entry object
|
|
|
a77461 |
"""
|
|
|
a77461 |
|
|
|
a77461 |
- return self._instance.search_ext_s(self._dn, ldap.SCOPE_BASE, self._object_filter, attrlist=["*"],
|
|
|
a77461 |
+ return _search_ext_s(self._instance,self._dn, ldap.SCOPE_BASE, self._object_filter, attrlist=["*"],
|
|
|
a77461 |
serverctrls=self._server_controls, clientctrls=self._client_controls,
|
|
|
a77461 |
escapehatch='i am sure')[0]
|
|
|
a77461 |
|
|
|
a77461 |
@@ -140,7 +168,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
"""
|
|
|
a77461 |
|
|
|
a77461 |
try:
|
|
|
a77461 |
- self._instance.search_ext_s(self._dn, ldap.SCOPE_BASE, self._object_filter, attrsonly=1,
|
|
|
a77461 |
+ _search_ext_s(self._instance,self._dn, ldap.SCOPE_BASE, self._object_filter, attrsonly=1,
|
|
|
a77461 |
serverctrls=self._server_controls, clientctrls=self._client_controls,
|
|
|
a77461 |
escapehatch='i am sure')
|
|
|
a77461 |
except ldap.NO_SUCH_OBJECT:
|
|
|
a77461 |
@@ -156,7 +184,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
search_scope = ldap.SCOPE_ONE
|
|
|
a77461 |
elif scope == 'subtree':
|
|
|
a77461 |
search_scope = ldap.SCOPE_SUBTREE
|
|
|
a77461 |
- return self._instance.search_ext_s(self._dn, search_scope, filter,
|
|
|
a77461 |
+ return _search_ext_s(self._instance,self._dn, search_scope, filter,
|
|
|
a77461 |
serverctrls=self._server_controls,
|
|
|
a77461 |
clientctrls=self._client_controls,
|
|
|
a77461 |
escapehatch='i am sure')
|
|
|
a77461 |
@@ -166,7 +194,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
|
|
|
a77461 |
:returns: LDIF formatted string
|
|
|
a77461 |
"""
|
|
|
a77461 |
- e = self._instance.search_ext_s(self._dn, ldap.SCOPE_BASE, self._object_filter, attrlist=attrlist,
|
|
|
a77461 |
+ e = _search_ext_s(self._instance,self._dn, ldap.SCOPE_BASE, self._object_filter, attrlist=attrlist,
|
|
|
a77461 |
serverctrls=self._server_controls, clientctrls=self._client_controls,
|
|
|
a77461 |
escapehatch='i am sure')[0]
|
|
|
a77461 |
return e.__repr__()
|
|
|
a77461 |
@@ -258,7 +286,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
raise ValueError("Invalid state. Cannot get presence on instance that is not ONLINE")
|
|
|
a77461 |
self._log.debug("%s present(%r) %s" % (self._dn, attr, value))
|
|
|
a77461 |
|
|
|
a77461 |
- self._instance.search_ext_s(self._dn, ldap.SCOPE_BASE, self._object_filter, attrlist=[attr, ],
|
|
|
a77461 |
+ _search_ext_s(self._instance,self._dn, ldap.SCOPE_BASE, self._object_filter, attrlist=[attr, ],
|
|
|
a77461 |
serverctrls=self._server_controls, clientctrls=self._client_controls,
|
|
|
a77461 |
escapehatch='i am sure')[0]
|
|
|
a77461 |
values = self.get_attr_vals_bytes(attr)
|
|
|
a77461 |
@@ -313,7 +341,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
else:
|
|
|
a77461 |
value = [ensure_bytes(arg[1])]
|
|
|
a77461 |
mods.append((ldap.MOD_REPLACE, ensure_str(arg[0]), value))
|
|
|
a77461 |
- return self._instance.modify_ext_s(self._dn, mods, serverctrls=self._server_controls,
|
|
|
a77461 |
+ return _modify_ext_s(self._instance,self._dn, mods, serverctrls=self._server_controls,
|
|
|
a77461 |
clientctrls=self._client_controls, escapehatch='i am sure')
|
|
|
a77461 |
|
|
|
a77461 |
# This needs to work on key + val, and key
|
|
|
a77461 |
@@ -457,7 +485,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
elif value is not None:
|
|
|
a77461 |
value = [ensure_bytes(value)]
|
|
|
a77461 |
|
|
|
a77461 |
- return self._instance.modify_ext_s(self._dn, [(action, key, value)],
|
|
|
a77461 |
+ return _modify_ext_s(self._instance,self._dn, [(action, key, value)],
|
|
|
a77461 |
serverctrls=self._server_controls, clientctrls=self._client_controls,
|
|
|
a77461 |
escapehatch='i am sure')
|
|
|
a77461 |
|
|
|
a77461 |
@@ -497,7 +525,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
else:
|
|
|
a77461 |
# Error too many items
|
|
|
a77461 |
raise ValueError('Too many arguments in the mod op')
|
|
|
a77461 |
- return self._instance.modify_ext_s(self._dn, mod_list, serverctrls=self._server_controls, clientctrls=self._client_controls, escapehatch='i am sure')
|
|
|
a77461 |
+ return _modify_ext_s(self._instance,self._dn, mod_list, serverctrls=self._server_controls, clientctrls=self._client_controls, escapehatch='i am sure')
|
|
|
a77461 |
|
|
|
a77461 |
def _unsafe_compare_attribute(self, other):
|
|
|
a77461 |
"""Compare two attributes from two objects. This is currently marked unsafe as it's
|
|
|
a77461 |
@@ -593,7 +621,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
raise ValueError("Invalid state. Cannot get properties on instance that is not ONLINE")
|
|
|
a77461 |
else:
|
|
|
a77461 |
# retrieving real(*) and operational attributes(+)
|
|
|
a77461 |
- attrs_entry = self._instance.search_ext_s(self._dn, ldap.SCOPE_BASE, self._object_filter,
|
|
|
a77461 |
+ attrs_entry = _search_ext_s(self._instance,self._dn, ldap.SCOPE_BASE, self._object_filter,
|
|
|
a77461 |
attrlist=["*", "+"], serverctrls=self._server_controls,
|
|
|
a77461 |
clientctrls=self._client_controls, escapehatch='i am sure')[0]
|
|
|
a77461 |
# getting dict from 'entry' object
|
|
|
a77461 |
@@ -613,7 +641,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
raise ValueError("Invalid state. Cannot get properties on instance that is not ONLINE")
|
|
|
a77461 |
else:
|
|
|
a77461 |
# retrieving real(*) and operational attributes(+)
|
|
|
a77461 |
- attrs_entry = self._instance.search_ext_s(self._dn, ldap.SCOPE_BASE, self._object_filter,
|
|
|
a77461 |
+ attrs_entry = _search_ext_s(self._instance,self._dn, ldap.SCOPE_BASE, self._object_filter,
|
|
|
a77461 |
attrlist=["*", "+"], serverctrls=self._server_controls,
|
|
|
a77461 |
clientctrls=self._client_controls, escapehatch='i am sure')[0]
|
|
|
a77461 |
# getting dict from 'entry' object
|
|
|
a77461 |
@@ -627,7 +655,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
if self._instance.state != DIRSRV_STATE_ONLINE:
|
|
|
a77461 |
raise ValueError("Invalid state. Cannot get properties on instance that is not ONLINE")
|
|
|
a77461 |
else:
|
|
|
a77461 |
- entry = self._instance.search_ext_s(self._dn, ldap.SCOPE_BASE, self._object_filter,
|
|
|
a77461 |
+ entry = _search_ext_s(self._instance,self._dn, ldap.SCOPE_BASE, self._object_filter,
|
|
|
a77461 |
attrlist=keys, serverctrls=self._server_controls,
|
|
|
a77461 |
clientctrls=self._client_controls, escapehatch='i am sure')[0]
|
|
|
a77461 |
return entry.getValuesSet(keys)
|
|
|
a77461 |
@@ -636,7 +664,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
self._log.debug("%s get_attrs_vals_utf8(%r)" % (self._dn, keys))
|
|
|
a77461 |
if self._instance.state != DIRSRV_STATE_ONLINE:
|
|
|
a77461 |
raise ValueError("Invalid state. Cannot get properties on instance that is not ONLINE")
|
|
|
a77461 |
- entry = self._instance.search_ext_s(self._dn, ldap.SCOPE_BASE, self._object_filter, attrlist=keys,
|
|
|
a77461 |
+ entry = _search_ext_s(self._instance,self._dn, ldap.SCOPE_BASE, self._object_filter, attrlist=keys,
|
|
|
a77461 |
serverctrls=self._server_controls, clientctrls=self._client_controls,
|
|
|
a77461 |
escapehatch='i am sure')[0]
|
|
|
a77461 |
vset = entry.getValuesSet(keys)
|
|
|
a77461 |
@@ -655,7 +683,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
else:
|
|
|
a77461 |
# It would be good to prevent the entry code intercepting this ....
|
|
|
a77461 |
# We have to do this in this method, because else we ignore the scope base.
|
|
|
a77461 |
- entry = self._instance.search_ext_s(self._dn, ldap.SCOPE_BASE, self._object_filter,
|
|
|
a77461 |
+ entry = _search_ext_s(self._instance,self._dn, ldap.SCOPE_BASE, self._object_filter,
|
|
|
a77461 |
attrlist=[key], serverctrls=self._server_controls,
|
|
|
a77461 |
clientctrls=self._client_controls, escapehatch='i am sure')[0]
|
|
|
a77461 |
vals = entry.getValues(key)
|
|
|
a77461 |
@@ -675,7 +703,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
# In the future, I plan to add a mode where if local == true, we
|
|
|
a77461 |
# can use get on dse.ldif to get values offline.
|
|
|
a77461 |
else:
|
|
|
a77461 |
- entry = self._instance.search_ext_s(self._dn, ldap.SCOPE_BASE, self._object_filter,
|
|
|
a77461 |
+ entry = _search_ext_s(self._instance,self._dn, ldap.SCOPE_BASE, self._object_filter,
|
|
|
a77461 |
attrlist=[key], serverctrls=self._server_controls,
|
|
|
a77461 |
clientctrls=self._client_controls, escapehatch='i am sure')[0]
|
|
|
a77461 |
return entry.getValue(key)
|
|
|
a77461 |
@@ -831,11 +859,11 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
# Is there a way to mark this as offline and kill it
|
|
|
a77461 |
if recursive:
|
|
|
a77461 |
filterstr = "(|(objectclass=*)(objectclass=ldapsubentry))"
|
|
|
a77461 |
- ents = self._instance.search_s(self._dn, ldap.SCOPE_SUBTREE, filterstr, escapehatch='i am sure')
|
|
|
a77461 |
+ ents = _search_s(self._instance, self._dn, ldap.SCOPE_SUBTREE, filterstr, escapehatch='i am sure')
|
|
|
a77461 |
for ent in sorted(ents, key=lambda e: len(e.dn), reverse=True):
|
|
|
a77461 |
- self._instance.delete_ext_s(ent.dn, serverctrls=self._server_controls, clientctrls=self._client_controls, escapehatch='i am sure')
|
|
|
a77461 |
+ _delete_ext_s(self._instance, ent.dn, serverctrls=self._server_controls, clientctrls=self._client_controls, escapehatch='i am sure')
|
|
|
a77461 |
else:
|
|
|
a77461 |
- self._instance.delete_ext_s(self._dn, serverctrls=self._server_controls, clientctrls=self._client_controls, escapehatch='i am sure')
|
|
|
a77461 |
+ _delete_ext_s(self._instance, self._dn, serverctrls=self._server_controls, clientctrls=self._client_controls, escapehatch='i am sure')
|
|
|
a77461 |
|
|
|
a77461 |
def _validate(self, rdn, properties, basedn):
|
|
|
a77461 |
"""Used to validate a create request.
|
|
|
a77461 |
@@ -933,7 +961,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
# If we are running in stateful ensure mode, we need to check if the object exists, and
|
|
|
a77461 |
# we can see the state that it is in.
|
|
|
a77461 |
try:
|
|
|
a77461 |
- self._instance.search_ext_s(dn, ldap.SCOPE_BASE, self._object_filter, attrsonly=1, serverctrls=self._server_controls, clientctrls=self._client_controls, escapehatch='i am sure')
|
|
|
a77461 |
+ _search_ext_s(self._instance,dn, ldap.SCOPE_BASE, self._object_filter, attrsonly=1, serverctrls=self._server_controls, clientctrls=self._client_controls, escapehatch='i am sure')
|
|
|
a77461 |
exists = True
|
|
|
a77461 |
except ldap.NO_SUCH_OBJECT:
|
|
|
a77461 |
pass
|
|
|
a77461 |
@@ -946,7 +974,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
mods = []
|
|
|
a77461 |
for k, v in list(valid_props.items()):
|
|
|
a77461 |
mods.append((ldap.MOD_REPLACE, k, v))
|
|
|
a77461 |
- self._instance.modify_ext_s(self._dn, mods, serverctrls=self._server_controls, clientctrls=self._client_controls, escapehatch='i am sure')
|
|
|
a77461 |
+ _modify_ext_s(self._instance,self._dn, mods, serverctrls=self._server_controls, clientctrls=self._client_controls, escapehatch='i am sure')
|
|
|
a77461 |
elif not exists:
|
|
|
a77461 |
# This case is reached in two cases. One is we are in ensure mode, and we KNOW the entry
|
|
|
a77461 |
# doesn't exist.
|
|
|
a77461 |
@@ -957,7 +985,7 @@ class DSLdapObject(DSLogging, DSLint):
|
|
|
a77461 |
e.update({'objectclass': ensure_list_bytes(self._create_objectclasses)})
|
|
|
a77461 |
e.update(valid_props)
|
|
|
a77461 |
# We rely on exceptions here to indicate failure to the parent.
|
|
|
a77461 |
- self._instance.add_ext_s(e, serverctrls=self._server_controls, clientctrls=self._client_controls, escapehatch='i am sure')
|
|
|
a77461 |
+ _add_ext_s(self._instance, e, serverctrls=self._server_controls, clientctrls=self._client_controls, escapehatch='i am sure')
|
|
|
a77461 |
self._log.debug('Created entry %s : %s' % (dn, display_log_data(e.data)))
|
|
|
a77461 |
# If it worked, we need to fix our instance dn for the object's self reference. Because
|
|
|
a77461 |
# we may not have a self reference yet (just created), it may have changed (someone
|
|
|
a77461 |
@@ -1104,7 +1132,7 @@ class DSLdapObjects(DSLogging, DSLints):
|
|
|
a77461 |
else:
|
|
|
a77461 |
# If not paged
|
|
|
a77461 |
try:
|
|
|
a77461 |
- results = self._instance.search_ext_s(
|
|
|
a77461 |
+ results = _search_ext_s(self._instance,
|
|
|
a77461 |
base=self._basedn,
|
|
|
a77461 |
scope=self._scope,
|
|
|
a77461 |
filterstr=filterstr,
|
|
|
a77461 |
@@ -1172,7 +1200,7 @@ class DSLdapObjects(DSLogging, DSLints):
|
|
|
a77461 |
filterstr = self._get_objectclass_filter()
|
|
|
a77461 |
self._log.debug('_gen_dn filter = %s' % filterstr)
|
|
|
a77461 |
self._log.debug('_gen_dn dn = %s' % dn)
|
|
|
a77461 |
- return self._instance.search_ext_s(
|
|
|
a77461 |
+ return _search_ext_s(self._instance,
|
|
|
a77461 |
base=dn,
|
|
|
a77461 |
scope=ldap.SCOPE_BASE,
|
|
|
a77461 |
filterstr=filterstr,
|
|
|
a77461 |
@@ -1187,7 +1215,7 @@ class DSLdapObjects(DSLogging, DSLints):
|
|
|
a77461 |
# This will yield and & filter for objectClass with as many terms as needed.
|
|
|
a77461 |
filterstr = self._get_selector_filter(selector)
|
|
|
a77461 |
self._log.debug('_gen_selector filter = %s' % filterstr)
|
|
|
a77461 |
- return self._instance.search_ext_s(
|
|
|
a77461 |
+ return _search_ext_s(self._instance,
|
|
|
a77461 |
base=self._basedn,
|
|
|
a77461 |
scope=self._scope,
|
|
|
a77461 |
filterstr=filterstr,
|
|
|
a77461 |
@@ -1261,7 +1289,7 @@ class DSLdapObjects(DSLogging, DSLints):
|
|
|
a77461 |
self._list_attrlist = attrlist
|
|
|
a77461 |
self._log.debug(f'list filter = {search_filter} with scope {scope} and attribute list {attrlist}')
|
|
|
a77461 |
try:
|
|
|
a77461 |
- results = self._instance.search_ext_s(
|
|
|
a77461 |
+ results = _search_ext_s(self._instance,
|
|
|
a77461 |
base=self._basedn,
|
|
|
a77461 |
scope=scope,
|
|
|
a77461 |
filterstr=search_filter,
|
|
|
a77461 |
diff --git a/src/lib389/lib389/utils.py b/src/lib389/lib389/utils.py
|
|
|
a77461 |
index 6eba2d7b9..da966ed97 100644
|
|
|
a77461 |
--- a/src/lib389/lib389/utils.py
|
|
|
a77461 |
+++ b/src/lib389/lib389/utils.py
|
|
|
a77461 |
@@ -52,7 +52,7 @@ from ldapurl import LDAPUrl
|
|
|
a77461 |
from contextlib import closing
|
|
|
a77461 |
|
|
|
a77461 |
import lib389
|
|
|
a77461 |
-from lib389.paths import Paths
|
|
|
a77461 |
+from lib389.paths import ( Paths, DEFAULTS_PATH )
|
|
|
a77461 |
from lib389.dseldif import DSEldif
|
|
|
a77461 |
from lib389._constants import (
|
|
|
a77461 |
DEFAULT_USER, VALGRIND_WRAPPER, DN_CONFIG, CFGSUFFIX, LOCALHOST,
|
|
|
a77461 |
@@ -495,8 +495,10 @@ def valgrind_enable(sbin_dir, wrapper=None):
|
|
|
a77461 |
:raise EnvironmentError: If script is not run as 'root'
|
|
|
a77461 |
'''
|
|
|
a77461 |
|
|
|
a77461 |
- if os.geteuid() != 0:
|
|
|
a77461 |
- log.error('This script must be run as root to use valgrind')
|
|
|
a77461 |
+ if not os.access(sbin_dir, os.W_OK):
|
|
|
a77461 |
+ # Note: valgrind has no limitation but ns-slapd must be replaced
|
|
|
a77461 |
+ # This check allows non root user to use custom install prefix
|
|
|
a77461 |
+ log.error('This script must be run as root to use valgrind (Should at least be able to write in {sbin_dir})')
|
|
|
a77461 |
raise EnvironmentError
|
|
|
a77461 |
|
|
|
a77461 |
if not wrapper:
|
|
|
a77461 |
@@ -542,7 +544,20 @@ def valgrind_enable(sbin_dir, wrapper=None):
|
|
|
a77461 |
e.strerror)
|
|
|
a77461 |
|
|
|
a77461 |
# Disable selinux
|
|
|
a77461 |
- os.system('setenforce 0')
|
|
|
a77461 |
+ if os.geteuid() == 0:
|
|
|
a77461 |
+ os.system('setenforce 0')
|
|
|
a77461 |
+
|
|
|
a77461 |
+ # Disable systemd by turning off with_system in .inf file
|
|
|
a77461 |
+ old_path = Paths()._get_defaults_loc(DEFAULTS_PATH)
|
|
|
a77461 |
+ new_path = f'{old_path}.orig'
|
|
|
a77461 |
+ os.rename(old_path, new_path)
|
|
|
a77461 |
+ with open(new_path, 'rt') as fin:
|
|
|
a77461 |
+ with open(old_path, 'wt') as fout:
|
|
|
a77461 |
+ for line in fin:
|
|
|
a77461 |
+ if line.startswith('with_systemd'):
|
|
|
a77461 |
+ fout.write('with_systemd = 0\n')
|
|
|
a77461 |
+ else:
|
|
|
a77461 |
+ fout.write(line)
|
|
|
a77461 |
|
|
|
a77461 |
log.info('Valgrind is now enabled.')
|
|
|
a77461 |
|
|
|
a77461 |
@@ -559,8 +574,10 @@ def valgrind_disable(sbin_dir):
|
|
|
a77461 |
:raise EnvironmentError: If script is not run as 'root'
|
|
|
a77461 |
'''
|
|
|
a77461 |
|
|
|
a77461 |
- if os.geteuid() != 0:
|
|
|
a77461 |
- log.error('This script must be run as root to use valgrind')
|
|
|
a77461 |
+ if not os.access(sbin_dir, os.W_OK):
|
|
|
a77461 |
+ # Note: valgrind has no limitation but ns-slapd must be replaced
|
|
|
a77461 |
+ # This check allows non root user to use custom install prefix
|
|
|
a77461 |
+ log.error('This script must be run as root to use valgrind (Should at least be able to write in {sbin_dir})')
|
|
|
a77461 |
raise EnvironmentError
|
|
|
a77461 |
|
|
|
a77461 |
nsslapd_orig = '%s/ns-slapd' % sbin_dir
|
|
|
a77461 |
@@ -584,7 +601,14 @@ def valgrind_disable(sbin_dir):
|
|
|
a77461 |
e.strerror)
|
|
|
a77461 |
|
|
|
a77461 |
# Enable selinux
|
|
|
a77461 |
- os.system('setenforce 1')
|
|
|
a77461 |
+ if os.geteuid() == 0:
|
|
|
a77461 |
+ os.system('setenforce 1')
|
|
|
a77461 |
+
|
|
|
a77461 |
+ # Restore .inf file (for systemd)
|
|
|
a77461 |
+ new_path = Paths()._get_defaults_loc(DEFAULTS_PATH)
|
|
|
a77461 |
+ old_path = f'{new_path}.orig'
|
|
|
a77461 |
+ if os.path.exists(old_path):
|
|
|
a77461 |
+ os.replace(old_path, new_path)
|
|
|
a77461 |
|
|
|
a77461 |
log.info('Valgrind is now disabled.')
|
|
|
a77461 |
|
|
|
a77461 |
@@ -610,7 +634,7 @@ def valgrind_get_results_file(dirsrv_inst):
|
|
|
a77461 |
|
|
|
a77461 |
# Run the command and grab the output
|
|
|
a77461 |
p = os.popen(cmd)
|
|
|
a77461 |
- results_file = p.readline()
|
|
|
a77461 |
+ results_file = p.readline().strip()
|
|
|
a77461 |
p.close()
|
|
|
a77461 |
|
|
|
a77461 |
return results_file
|
|
|
a77461 |
--
|
|
|
a77461 |
2.31.1
|
|
|
a77461 |
|