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

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