andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame SOURCES/0009-Issue-51113-Allow-using-uid-for-replication-manager-.patch

d69b2b
From 52ce524f7672563b543e84401665765cfa72dea5 Mon Sep 17 00:00:00 2001
d69b2b
From: Mark Reynolds <mreynolds@redhat.com>
d69b2b
Date: Tue, 26 May 2020 17:03:11 -0400
d69b2b
Subject: [PATCH 09/12] Issue 51113 - Allow using uid for replication manager
d69b2b
 entry
d69b2b
d69b2b
Bug Description:  Currently it was hardcoded to only allow "cn" as
d69b2b
                  the rdn attribute for the replication manager entry.
d69b2b
d69b2b
Fix description:  Allow setting the rdn attribute of the replication
d69b2b
                  manager DS ldap object, and include the schema that
d69b2b
                  allows "uid".
d69b2b
d69b2b
relates:  https://pagure.io/389-ds-base/issue/51113
d69b2b
d69b2b
Reviewed by: spichugi & firstyear(Thanks!!)
d69b2b
---
d69b2b
 src/lib389/lib389/cli_conf/replication.py | 53 ++++++++++++-----------
d69b2b
 src/lib389/lib389/replica.py              | 11 +++--
d69b2b
 2 files changed, 35 insertions(+), 29 deletions(-)
d69b2b
d69b2b
diff --git a/src/lib389/lib389/cli_conf/replication.py b/src/lib389/lib389/cli_conf/replication.py
d69b2b
index 09cb9b435..b9bc3d291 100644
d69b2b
--- a/src/lib389/lib389/cli_conf/replication.py
d69b2b
+++ b/src/lib389/lib389/cli_conf/replication.py
d69b2b
@@ -199,19 +199,21 @@ def enable_replication(inst, basedn, log, args):
d69b2b
 
d69b2b
     # Create replication manager if password was provided
d69b2b
     if args.bind_dn and args.bind_passwd:
d69b2b
-        cn_rdn = args.bind_dn.split(",", 1)[0]
d69b2b
-        cn_val = cn_rdn.split("=", 1)[1]
d69b2b
-        manager = BootstrapReplicationManager(inst, dn=args.bind_dn)
d69b2b
+        rdn = args.bind_dn.split(",", 1)[0]
d69b2b
+        rdn_attr, rdn_val = rdn.split("=", 1)
d69b2b
+        manager = BootstrapReplicationManager(inst, dn=args.bind_dn, rdn_attr=rdn_attr)
d69b2b
         try:
d69b2b
             manager.create(properties={
d69b2b
-                'cn': cn_val,
d69b2b
+                'cn': rdn_val,
d69b2b
+                'uid': rdn_val,
d69b2b
                 'userPassword': args.bind_passwd
d69b2b
             })
d69b2b
         except ldap.ALREADY_EXISTS:
d69b2b
             # Already there, but could have different password.  Delete and recreate
d69b2b
             manager.delete()
d69b2b
             manager.create(properties={
d69b2b
-                'cn': cn_val,
d69b2b
+                'cn': rdn_val,
d69b2b
+                'uid': rdn_val,
d69b2b
                 'userPassword': args.bind_passwd
d69b2b
             })
d69b2b
         except ldap.NO_SUCH_OBJECT:
d69b2b
@@ -511,22 +513,23 @@ def get_cl(inst, basedn, log, args):
d69b2b
 
d69b2b
 
d69b2b
 def create_repl_manager(inst, basedn, log, args):
d69b2b
-    manager_cn = "replication manager"
d69b2b
+    manager_name = "replication manager"
d69b2b
     repl_manager_password = ""
d69b2b
     repl_manager_password_confirm = ""
d69b2b
 
d69b2b
     if args.name:
d69b2b
-        manager_cn = args.name
d69b2b
-
d69b2b
-    if is_a_dn(manager_cn):
d69b2b
-        # A full DN was provided, make sure it uses "cn" for the RDN
d69b2b
-        if manager_cn.split("=", 1)[0].lower() != "cn":
d69b2b
-            raise ValueError("Replication manager DN must use \"cn\" for the rdn attribute")
d69b2b
-        manager_dn = manager_cn
d69b2b
-        manager_rdn = manager_dn.split(",", 1)[0]
d69b2b
-        manager_cn = manager_rdn.split("=", 1)[1]
d69b2b
+        manager_name = args.name
d69b2b
+
d69b2b
+    if is_a_dn(manager_name):
d69b2b
+        # A full DN was provided
d69b2b
+        manager_dn = manager_name
d69b2b
+        manager_rdn = manager_name.split(",", 1)[0]
d69b2b
+        manager_attr, manager_name = manager_rdn.split("=", 1)
d69b2b
+        if manager_attr.lower() not in ['cn', 'uid']:
d69b2b
+            raise ValueError(f'The RDN attribute "{manager_attr}" is not allowed, you must use "cn" or "uid"')
d69b2b
     else:
d69b2b
-        manager_dn = "cn={},cn=config".format(manager_cn)
d69b2b
+        manager_dn = "cn={},cn=config".format(manager_name)
d69b2b
+        manager_attr = "cn"
d69b2b
 
d69b2b
     if args.passwd:
d69b2b
         repl_manager_password = args.passwd
d69b2b
@@ -544,10 +547,11 @@ def create_repl_manager(inst, basedn, log, args):
d69b2b
                 repl_manager_password = ""
d69b2b
                 repl_manager_password_confirm = ""
d69b2b
 
d69b2b
-    manager = BootstrapReplicationManager(inst, dn=manager_dn)
d69b2b
+    manager = BootstrapReplicationManager(inst, dn=manager_dn, rdn_attr=manager_attr)
d69b2b
     try:
d69b2b
         manager.create(properties={
d69b2b
-            'cn': manager_cn,
d69b2b
+            'cn': manager_name,
d69b2b
+            'uid': manager_name,
d69b2b
             'userPassword': repl_manager_password
d69b2b
         })
d69b2b
         if args.suffix:
d69b2b
@@ -564,7 +568,8 @@ def create_repl_manager(inst, basedn, log, args):
d69b2b
         # Already there, but could have different password.  Delete and recreate
d69b2b
         manager.delete()
d69b2b
         manager.create(properties={
d69b2b
-            'cn': manager_cn,
d69b2b
+            'cn': manager_name,
d69b2b
+            'uid': manager_name,
d69b2b
             'userPassword': repl_manager_password
d69b2b
         })
d69b2b
         if args.suffix:
d69b2b
@@ -954,6 +959,7 @@ def get_winsync_agmt_status(inst, basedn, log, args):
d69b2b
     status = agmt.status(winsync=True, use_json=args.json)
d69b2b
     log.info(status)
d69b2b
 
d69b2b
+
d69b2b
 #
d69b2b
 # Tasks
d69b2b
 #
d69b2b
@@ -1347,8 +1353,7 @@ def create_parser(subparsers):
d69b2b
     agmt_set_parser.add_argument('--wait-async-results', help="The amount of time in milliseconds the server waits if "
d69b2b
                                                               "the consumer is not ready before resending data")
d69b2b
     agmt_set_parser.add_argument('--busy-wait-time', help="The amount of time in seconds a supplier should wait after "
d69b2b
-                                                          "a consumer sends back a busy response before making another "
d69b2b
-                                                          "attempt to acquire access.")
d69b2b
+                                 "a consumer sends back a busy response before making another attempt to acquire access.")
d69b2b
     agmt_set_parser.add_argument('--session-pause-time', help="The amount of time in seconds a supplier should wait between update sessions.")
d69b2b
     agmt_set_parser.add_argument('--flow-control-window', help="Sets the maximum number of entries and updates sent by a supplier, which are not acknowledged by the consumer.")
d69b2b
     agmt_set_parser.add_argument('--flow-control-pause', help="The time in milliseconds to pause after reaching the number of entries and updates set in \"--flow-control-window\"")
d69b2b
@@ -1438,8 +1443,7 @@ def create_parser(subparsers):
d69b2b
     winsync_agmt_add_parser.add_argument('--subtree-pair', help="Set the subtree pair: <DS_SUBTREE>:<WINDOWS_SUBTREE>")
d69b2b
     winsync_agmt_add_parser.add_argument('--conn-timeout', help="The timeout used for replicaton connections")
d69b2b
     winsync_agmt_add_parser.add_argument('--busy-wait-time', help="The amount of time in seconds a supplier should wait after "
d69b2b
-                                                          "a consumer sends back a busy response before making another "
d69b2b
-                                                          "attempt to acquire access.")
d69b2b
+                                         "a consumer sends back a busy response before making another attempt to acquire access.")
d69b2b
     winsync_agmt_add_parser.add_argument('--session-pause-time', help="The amount of time in seconds a supplier should wait between update sessions.")
d69b2b
     winsync_agmt_add_parser.add_argument('--init', action='store_true', default=False, help="Initialize the agreement after creating it.")
d69b2b
 
d69b2b
@@ -1468,8 +1472,7 @@ def create_parser(subparsers):
d69b2b
     winsync_agmt_set_parser.add_argument('--subtree-pair', help="Set the subtree pair: <DS_SUBTREE>:<WINDOWS_SUBTREE>")
d69b2b
     winsync_agmt_set_parser.add_argument('--conn-timeout', help="The timeout used for replicaton connections")
d69b2b
     winsync_agmt_set_parser.add_argument('--busy-wait-time', help="The amount of time in seconds a supplier should wait after "
d69b2b
-                                                          "a consumer sends back a busy response before making another "
d69b2b
-                                                          "attempt to acquire access.")
d69b2b
+                                         "a consumer sends back a busy response before making another attempt to acquire access.")
d69b2b
     winsync_agmt_set_parser.add_argument('--session-pause-time', help="The amount of time in seconds a supplier should wait between update sessions.")
d69b2b
 
d69b2b
     # Get
d69b2b
diff --git a/src/lib389/lib389/replica.py b/src/lib389/lib389/replica.py
d69b2b
index e3fc7fe1f..f8adb3ce2 100644
d69b2b
--- a/src/lib389/lib389/replica.py
d69b2b
+++ b/src/lib389/lib389/replica.py
d69b2b
@@ -1779,15 +1779,18 @@ class BootstrapReplicationManager(DSLdapObject):
d69b2b
     :type instance: lib389.DirSrv
d69b2b
     :param dn: The dn to create
d69b2b
     :type dn: str
d69b2b
+    :param rdn_attr: The attribute to use for the RDN
d69b2b
+    :type rdn_attr: str
d69b2b
     """
d69b2b
-    def __init__(self, instance, dn='cn=replication manager,cn=config'):
d69b2b
+    def __init__(self, instance, dn='cn=replication manager,cn=config', rdn_attr='cn'):
d69b2b
         super(BootstrapReplicationManager, self).__init__(instance, dn)
d69b2b
-        self._rdn_attribute = 'cn'
d69b2b
+        self._rdn_attribute = rdn_attr
d69b2b
         self._must_attributes = ['cn', 'userPassword']
d69b2b
         self._create_objectclasses = [
d69b2b
             'top',
d69b2b
-            'netscapeServer',
d69b2b
-            'nsAccount'
d69b2b
+            'inetUser',  # for uid
d69b2b
+            'netscapeServer',  # for cn
d69b2b
+            'nsAccount',  # for authentication attributes
d69b2b
             ]
d69b2b
         if ds_is_older('1.4.0'):
d69b2b
             self._create_objectclasses.remove('nsAccount')
d69b2b
-- 
d69b2b
2.26.2
d69b2b