Blame SOURCES/0025-Ticket-48393-Improve-replication-config-validation.patch

058656
From c1ac23d7f5f6f14d75bd02cfd55818e2558f7cb9 Mon Sep 17 00:00:00 2001
058656
From: Mark Reynolds <mreynolds@redhat.com>
058656
Date: Fri, 3 Nov 2017 09:30:01 -0400
058656
Subject: [PATCH] Ticket 48393 - Improve replication config validation
058656
058656
Bug Description:  There was inconsistent behavior when modifying and adding replication
058656
                  configurations and agreements.  There were also a few places where
058656
                  unsigned ints were used for values which made checking for negative
058656
                  values impossible.
058656
058656
Fix Description:  Added a new function to properly check "number" attribute values.
058656
                  Also forced failure on the actual update if an invalid value was used
058656
                  (previously we would log an error and use some default value).  Also
058656
                  made all the int types consistent.
058656
058656
https://pagure.io/389-ds-base/issue/48393
058656
058656
Reviewed by: firstyear(Thanks!)
058656
058656
(cherry picked from commit f6b0e1841059460d6d0071cc771e3fbe834af393)
058656
---
058656
 .../suites/replication/replica_config_test.py      | 397 +++++++++++++++++++++
058656
 ldap/schema/01core389.ldif                         |   3 +-
058656
 ldap/servers/plugins/replication/repl5.h           |  54 +--
058656
 ldap/servers/plugins/replication/repl5_agmt.c      | 173 +++++----
058656
 ldap/servers/plugins/replication/repl5_replica.c   | 280 +++++++++------
058656
 .../plugins/replication/repl5_replica_config.c     | 158 ++++----
058656
 ldap/servers/plugins/replication/replutil.c        |  26 ++
058656
 7 files changed, 792 insertions(+), 299 deletions(-)
058656
 create mode 100644 dirsrvtests/tests/suites/replication/replica_config_test.py
058656
058656
diff --git a/dirsrvtests/tests/suites/replication/replica_config_test.py b/dirsrvtests/tests/suites/replication/replica_config_test.py
058656
new file mode 100644
058656
index 000000000..50ea2ece9
058656
--- /dev/null
058656
+++ b/dirsrvtests/tests/suites/replication/replica_config_test.py
058656
@@ -0,0 +1,397 @@
058656
+import logging
058656
+import pytest
058656
+import copy
058656
+import os
058656
+import ldap
058656
+from lib389._constants import *
058656
+from lib389 import Entry
058656
+from lib389.topologies import topology_st as topo
058656
+
058656
+DEBUGGING = os.getenv("DEBUGGING", default=False)
058656
+if DEBUGGING:
058656
+    logging.getLogger(__name__).setLevel(logging.DEBUG)
058656
+else:
058656
+    logging.getLogger(__name__).setLevel(logging.INFO)
058656
+log = logging.getLogger(__name__)
058656
+
058656
+REPLICA_DN = 'cn=replica,cn="dc=example,dc=com",cn=mapping tree,cn=config'
058656
+AGMT_DN = 'cn=test_agreement,cn=replica,cn="dc=example,dc=com",cn=mapping tree,cn=config'
058656
+notnum = 'invalid'
058656
+too_big = '9223372036854775807'
058656
+overflow = '9999999999999999999999999999999999999999999999999999999999999999999'
058656
+
058656
+replica_dict = {'objectclass': 'top nsDS5Replica'.split(),
058656
+                'nsDS5ReplicaRoot': 'dc=example,dc=com',
058656
+                'nsDS5ReplicaType': '3',
058656
+                'nsDS5Flags': '1',
058656
+                'nsDS5ReplicaId': '65535',
058656
+                'nsds5ReplicaPurgeDelay': '604800',
058656
+                'nsDS5ReplicaBindDN': 'cn=u',
058656
+                'cn': 'replica'}
058656
+
058656
+agmt_dict = {'objectClass': 'top nsDS5ReplicationAgreement'.split(),
058656
+             'cn': 'test_agreement',
058656
+             'nsDS5ReplicaRoot': 'dc=example,dc=com',
058656
+             'nsDS5ReplicaHost': 'localhost.localdomain',
058656
+             'nsDS5ReplicaPort': '5555',
058656
+             'nsDS5ReplicaBindDN': 'uid=tester',
058656
+             'nsds5ReplicaCredentials': 'password',
058656
+             'nsDS5ReplicaTransportInfo': 'LDAP',
058656
+             'nsDS5ReplicaBindMethod': 'SIMPLE'}
058656
+
058656
+
058656
+repl_add_attrs = [('nsDS5ReplicaType', '-1', '4', overflow, notnum, '1'),
058656
+                  ('nsDS5Flags', '-1', '2', overflow, notnum, '1'),
058656
+                  ('nsDS5ReplicaId', '0', '65536', overflow, notnum, '1'),
058656
+                  ('nsds5ReplicaPurgeDelay', '-2', too_big, overflow, notnum, '1'),
058656
+                  ('nsDS5ReplicaBindDnGroupCheckInterval', '-2', too_big, overflow, notnum, '1'),
058656
+                  ('nsds5ReplicaTombstonePurgeInterval', '-2', too_big, overflow, notnum, '1'),
058656
+                  ('nsds5ReplicaProtocolTimeout', '-1', too_big, overflow, notnum, '1'),
058656
+                  ('nsds5ReplicaReleaseTimeout', '-1', too_big, overflow, notnum, '1'),
058656
+                  ('nsds5ReplicaBackoffMin', '0', too_big, overflow, notnum, '3'),
058656
+                  ('nsds5ReplicaBackoffMax', '0', too_big, overflow, notnum, '6')]
058656
+
058656
+repl_mod_attrs = [('nsDS5Flags', '-1', '2', overflow, notnum, '1'),
058656
+                  ('nsds5ReplicaPurgeDelay', '-2', too_big, overflow, notnum, '1'),
058656
+                  ('nsDS5ReplicaBindDnGroupCheckInterval', '-2', too_big, overflow, notnum, '1'),
058656
+                  ('nsds5ReplicaTombstonePurgeInterval', '-2', too_big, overflow, notnum, '1'),
058656
+                  ('nsds5ReplicaProtocolTimeout', '-1', too_big, overflow, notnum, '1'),
058656
+                  ('nsds5ReplicaReleaseTimeout', '-1', too_big, overflow, notnum, '1'),
058656
+                  ('nsds5ReplicaBackoffMin', '0', too_big, overflow, notnum, '3'),
058656
+                  ('nsds5ReplicaBackoffMax', '0', too_big, overflow, notnum, '6')]
058656
+
058656
+agmt_attrs = [('nsds5ReplicaPort', '0', '65536', overflow, notnum, '389'),
058656
+              ('nsds5ReplicaTimeout', '-1', too_big, overflow, notnum, '6'),
058656
+              ('nsds5ReplicaBusyWaitTime', '-1', too_big, overflow, notnum, '6'),
058656
+              ('nsds5ReplicaSessionPauseTime', '-1', too_big, overflow, notnum, '6'),
058656
+              ('nsds5ReplicaFlowControlWindow', '-1', too_big, overflow, notnum, '6'),
058656
+              ('nsds5ReplicaFlowControlPause', '-1', too_big, overflow, notnum, '6'),
058656
+              ('nsds5ReplicaProtocolTimeout', '-1', too_big, overflow, notnum, '6')]
058656
+
058656
+
058656
+def replica_setup(topo):
058656
+    """Add a valid replica config entry to modify
058656
+    """
058656
+    try:
058656
+        topo.standalone.delete_s(REPLICA_DN)
058656
+    except:
058656
+        pass
058656
+
058656
+    try:
058656
+        topo.standalone.add_s(Entry((REPLICA_DN, replica_dict)))
058656
+    except ldap.LDAPError as e:
058656
+        log.fatal("Failed to add replica entry: " + str(e))
058656
+        assert False
058656
+
058656
+
058656
+def replica_reset(topo):
058656
+    try:
058656
+        topo.standalone.delete_s(REPLICA_DN)
058656
+    except:
058656
+        pass
058656
+
058656
+
058656
+def agmt_setup(topo):
058656
+    """Add a valid replica config entry to modify
058656
+    """
058656
+    try:
058656
+        topo.standalone.delete_s(AGMT_DN)
058656
+    except:
058656
+        pass
058656
+
058656
+    try:
058656
+        topo.standalone.add_s(Entry((AGMT_DN, agmt_dict)))
058656
+    except ldap.LDAPError as e:
058656
+        log.fatal("Failed to add agreement entry: " + str(e))
058656
+        assert False
058656
+
058656
+
058656
+def agmt_reset(topo):
058656
+    try:
058656
+        topo.standalone.delete_s(AGMT_DN)
058656
+    except:
058656
+        pass
058656
+
058656
+
058656
+@pytest.mark.parametrize("attr, too_small, too_big, overflow, notnum, valid", repl_add_attrs)
058656
+def test_replica_num_add(topo, attr, too_small, too_big, overflow, notnum, valid):
058656
+    """Test all the number values you can set for a replica config entry
058656
+
058656
+    :id: a8b47d4a-a089-4d70-8070-e6181209bf92
058656
+    :setup: standalone instance
058656
+    :steps:
058656
+        1. Use a value that is too small
058656
+        2. Use a value that is too big
058656
+        3. Use a value that overflows the int
058656
+        4. Use a value with character value (not a number)
058656
+        5. Use a valid value
058656
+    :expectedresults:
058656
+        1. Add is rejected
058656
+        2. Add is rejected
058656
+        3. Add is rejected
058656
+        4. Add is rejected
058656
+        5. Add is allowed
058656
+    """
058656
+
058656
+    replica_reset(topo)
058656
+
058656
+    # Test too small
058656
+    my_replica = copy.deepcopy(replica_dict)
058656
+    my_replica[attr] = too_small
058656
+    try:
058656
+        topo.standalone.add_s(Entry((REPLICA_DN, my_replica)))
058656
+        log.fatal("Incorrectly allowed to add replica entry with {}:{}".format(attr, too_small))
058656
+        assert False
058656
+    except ldap.LDAPError as e:
058656
+        log.info("Correctly failed to add replica entry with {}:{}  error: {}".format(attr, too_small, str(e)))
058656
+
058656
+    # Test too big
058656
+    my_replica = copy.deepcopy(replica_dict)
058656
+    my_replica[attr] = too_big
058656
+    try:
058656
+        topo.standalone.add_s(Entry((REPLICA_DN, my_replica)))
058656
+        log.fatal("Incorrectly allowed to add replica entry with {}:{}".format(attr, too_big))
058656
+        assert False
058656
+    except ldap.LDAPError as e:
058656
+        log.info("Correctly failed to add replica entry with {}:{}  error: {}".format(attr, too_big, str(e)))
058656
+
058656
+    # Test overflow
058656
+    my_replica = copy.deepcopy(replica_dict)
058656
+    my_replica[attr] = overflow
058656
+    try:
058656
+        topo.standalone.add_s(Entry((REPLICA_DN, my_replica)))
058656
+        log.fatal("Incorrectly allowed to add replica entry with {}:{}".format(attr, overflow))
058656
+        assert False
058656
+    except ldap.LDAPError as e:
058656
+        log.info("Correctly failed to add replica entry with {}:{}  error: {}".format(attr, overflow, str(e)))
058656
+
058656
+    # test not a number
058656
+    my_replica = copy.deepcopy(replica_dict)
058656
+    my_replica[attr] = notnum
058656
+    try:
058656
+        topo.standalone.add_s(Entry((REPLICA_DN, my_replica)))
058656
+        log.fatal("Incorrectly allowed to add replica entry with {}:{}".format(attr, notnum))
058656
+        assert False
058656
+    except ldap.LDAPError as e:
058656
+        log.info("Correctly failed to add replica entry with {}:{}  error: {}".format(attr, notnum, str(e)))
058656
+
058656
+    # Test valid value
058656
+    my_replica = copy.deepcopy(replica_dict)
058656
+    my_replica[attr] = valid
058656
+    try:
058656
+        topo.standalone.add_s(Entry((REPLICA_DN, my_replica)))
058656
+        log.info("Correctly allowed to add replica entry with {}: {}".format(attr, valid))
058656
+    except ldap.LDAPError as e:
058656
+        log.fatal("Incorrectly failed to add replica entry with {}: {}  error: {}".format(attr, valid, str(e)))
058656
+        assert False
058656
+
058656
+
058656
+@pytest.mark.parametrize("attr, too_small, too_big, overflow, notnum, valid", repl_mod_attrs)
058656
+def test_replica_num_modify(topo, attr, too_small, too_big, overflow, notnum, valid):
058656
+    """Test all the number values you can set for a replica config entry
058656
+
058656
+    :id: a8b47d4a-a089-4d70-8070-e6181209bf93
058656
+    :setup: standalone instance
058656
+    :steps:
058656
+        1. Replace a value that is too small
058656
+        2. Repalce a value that is too big
058656
+        3. Replace a value that overflows the int
058656
+        4. Replace a value with character value (not a number)
058656
+        5. Replace a vlue with a valid value
058656
+    :expectedresults:
058656
+        1. Value is rejected
058656
+        2. Value is rejected
058656
+        3. Value is rejected
058656
+        4. Value is rejected
058656
+        5. Value is allowed
058656
+    """
058656
+
058656
+    # Value too small
058656
+    replica_setup(topo)
058656
+    try:
058656
+        topo.standalone.modify_s(REPLICA_DN, [(ldap.MOD_REPLACE, attr, too_small)])
058656
+        log.fatal('Invalid value for {}:{} was incorrectly allowed'.format(attr, too_small))
058656
+        assert False
058656
+    except:
058656
+        log.info('Invalid value for {}:{} was correctly rejected'.format(attr, too_small))
058656
+
058656
+    # Value too big
058656
+    replica_setup(topo)
058656
+    try:
058656
+        topo.standalone.modify_s(REPLICA_DN, [(ldap.MOD_REPLACE, attr, too_big)])
058656
+        log.fatal('Invalid value for {}:{} was incorrectly allowed'.format(attr, too_big))
058656
+        assert False
058656
+    except:
058656
+        log.info('Invalid value for {}:{} was correctly rejected'.format(attr, too_big))
058656
+
058656
+    # Value overflow
058656
+    replica_setup(topo)
058656
+    try:
058656
+        topo.standalone.modify_s(REPLICA_DN, [(ldap.MOD_REPLACE, attr, overflow)])
058656
+        log.fatal('Invalid value for {}:{} was incorrectly allowed'.format(attr, overflow))
058656
+        assert False
058656
+    except:
058656
+        log.info('Invalid value for {}:{} was correctly rejected'.format(attr, overflow))
058656
+
058656
+    # Value not a number
058656
+    replica_setup(topo)
058656
+    try:
058656
+        topo.standalone.modify_s(REPLICA_DN, [(ldap.MOD_REPLACE, attr, notnum)])
058656
+        log.fatal('Invalid value for {}:{} was incorrectly allowed'.format(attr, notnum))
058656
+        assert False
058656
+    except:
058656
+        log.info('Invalid value for {}:{} was correctly rejected'.format(attr, notnum))
058656
+
058656
+    # Value is valid
058656
+    replica_setup(topo)
058656
+    try:
058656
+        topo.standalone.modify_s(REPLICA_DN, [(ldap.MOD_REPLACE, attr, valid)])
058656
+        log.info('Correctly added valid agreement attribute value: {}:{}'.format(attr, valid))
058656
+    except ldap.LDAPError as e:
058656
+        log.fatal('Valid value for {}:{} was incorrectly rejected.  Error {}'.format(attr, valid, str(e)))
058656
+        assert False
058656
+
058656
+
058656
+@pytest.mark.parametrize("attr, too_small, too_big, overflow, notnum, valid", agmt_attrs)
058656
+def test_agmt_num_add(topo, attr, too_small, too_big, overflow, notnum, valid):
058656
+    """Test all the number values you can set for a replica config entry
058656
+
058656
+    :id: a8b47d4a-a089-4d70-8070-e6181209bf94
058656
+    :setup: standalone instance
058656
+    :steps:
058656
+        1. Use a value that is too small
058656
+        2. Use a value that is too big
058656
+        3. Use a value that overflows the int
058656
+        4. Use a value with character value (not a number)
058656
+        5. Use a valid value
058656
+    :expectedresults:
058656
+        1. Add is rejected
058656
+        2. Add is rejected
058656
+        3. Add is rejected
058656
+        4. Add is rejected
058656
+        5. Add is allowed
058656
+    """
058656
+    agmt_reset(topo)
058656
+
058656
+    # Test too small
058656
+    my_agmt = copy.deepcopy(agmt_dict)
058656
+    my_agmt[attr] = too_small
058656
+    try:
058656
+        topo.standalone.add_s(Entry((AGMT_DN, my_agmt)))
058656
+        log.fatal("Incorrectly allowed to add agreement entry with {}:{}".format(attr, too_small))
058656
+        assert False
058656
+    except ldap.LDAPError as e:
058656
+        log.info("Correctly failed to add agreement entry with {}:{}  error: {}".format(attr, too_small, str(e)))
058656
+
058656
+    # Test too big
058656
+    my_agmt = copy.deepcopy(agmt_dict)
058656
+    my_agmt[attr] = too_big
058656
+    try:
058656
+        topo.standalone.add_s(Entry((AGMT_DN, my_agmt)))
058656
+        log.fatal("Incorrectly allowed to add agreement entry with {}:{}".format(attr, too_big))
058656
+        assert False
058656
+    except ldap.LDAPError as e:
058656
+        log.info("Correctly failed to add agreement entry with {}:{}  error: {}".format(attr, too_big, str(e)))
058656
+
058656
+    # Test overflow
058656
+    my_agmt = copy.deepcopy(agmt_dict)
058656
+    my_agmt[attr] = overflow
058656
+    try:
058656
+        topo.standalone.add_s(Entry((AGMT_DN, my_agmt)))
058656
+        log.fatal("Incorrectly allowed to add agreement entry with {}:{}".format(attr, overflow))
058656
+        assert False
058656
+    except ldap.LDAPError as e:
058656
+        log.info("Correctly failed to add agreement entry with {}:{}  error: {}".format(attr, overflow, str(e)))
058656
+
058656
+    # test not a number
058656
+    my_agmt = copy.deepcopy(agmt_dict)
058656
+    my_agmt[attr] = notnum
058656
+    try:
058656
+        topo.standalone.add_s(Entry((AGMT_DN, my_agmt)))
058656
+        log.fatal("Incorrectly allowed to add agreement entry with {}:{}".format(attr, notnum))
058656
+        assert False
058656
+    except ldap.LDAPError as e:
058656
+        log.info("Correctly failed to add agreement entry with {}:{}  error: {}".format(attr, notnum, str(e)))
058656
+
058656
+    # Test valid value
058656
+    my_agmt = copy.deepcopy(agmt_dict)
058656
+    my_agmt[attr] = valid
058656
+    try:
058656
+        topo.standalone.add_s(Entry((AGMT_DN, my_agmt)))
058656
+        log.info("Correctly allowed to add agreement entry with {}: {}".format(attr, valid))
058656
+    except ldap.LDAPError as e:
058656
+        log.fatal("Incorrectly failed to add agreement entry with {}: {}  error: {}".format(attr, valid, str(e)))
058656
+        assert False
058656
+
058656
+
058656
+@pytest.mark.parametrize("attr, too_small, too_big, overflow, notnum, valid", agmt_attrs)
058656
+def test_agmt_num_modify(topo, attr, too_small, too_big, overflow, notnum, valid):
058656
+    """Test all the number values you can set for a replica config entry
058656
+
058656
+    :id: a8b47d4a-a089-4d70-8070-e6181209bf95
058656
+    :setup: standalone instance
058656
+    :steps:
058656
+        1. Replace a value that is too small
058656
+        2. Replace a value that is too big
058656
+        3. Replace a value that overflows the int
058656
+        4. Replace a value with character value (not a number)
058656
+        5. Replace a vlue with a valid value
058656
+    :expectedresults:
058656
+        1. Value is rejected
058656
+        2. Value is rejected
058656
+        3. Value is rejected
058656
+        4. Value is rejected
058656
+        5. Value is allowed
058656
+    """
058656
+
058656
+    # Value too small
058656
+    agmt_setup(topo)
058656
+    try:
058656
+        topo.standalone.modify_s(AGMT_DN, [(ldap.MOD_REPLACE, attr, too_small)])
058656
+        log.fatal('Invalid value for {}:{} was incorrectly allowed'.format(attr, too_small))
058656
+        assert False
058656
+    except:
058656
+        log.info('Invalid value for {}:{} was correctly rejected'.format(attr, too_small))
058656
+
058656
+    # Value too big
058656
+    agmt_setup(topo)
058656
+    try:
058656
+        topo.standalone.modify_s(AGMT_DN, [(ldap.MOD_REPLACE, attr, too_big)])
058656
+        log.fatal('Invalid value for {}:{} was incorrectly allowed'.format(attr, too_big))
058656
+        assert False
058656
+    except:
058656
+        log.info('Invalid value for {}:{} was correctly rejected'.format(attr, too_big))
058656
+
058656
+    # Value overflow
058656
+    agmt_setup(topo)
058656
+    try:
058656
+        topo.standalone.modify_s(AGMT_DN, [(ldap.MOD_REPLACE, attr, overflow)])
058656
+        log.fatal('Invalid value for {}:{} was incorrectly allowed'.format(attr, overflow))
058656
+        assert False
058656
+    except:
058656
+        log.info('Invalid value for {}:{} was correctly rejected'.format(attr, overflow))
058656
+
058656
+    # Value not a number
058656
+    agmt_setup(topo)
058656
+    try:
058656
+        topo.standalone.modify_s(AGMT_DN, [(ldap.MOD_REPLACE, attr, notnum)])
058656
+        log.fatal('Invalid value for {}:{} was incorrectly allowed'.format(attr, notnum))
058656
+        assert False
058656
+    except:
058656
+        log.info('Invalid value for {}:{} was correctly rejected'.format(attr, notnum))
058656
+
058656
+    # Value is valid
058656
+    agmt_setup(topo)
058656
+    try:
058656
+        topo.standalone.modify_s(AGMT_DN, [(ldap.MOD_REPLACE, attr, valid)])
058656
+    except ldap.LDAPError as e:
058656
+        log.fatal('Valid value for {}:{} was incorrectly rejected.  Error {}'.format(attr, valid, str(e)))
058656
+        assert False
058656
+
058656
+
058656
+if __name__ == '__main__':
058656
+    # Run isolated
058656
+    # -s for DEBUG mode
058656
+    CURRENT_FILE = os.path.realpath(__file__)
058656
+    pytest.main("-s %s" % CURRENT_FILE)
058656
+
058656
diff --git a/ldap/schema/01core389.ldif b/ldap/schema/01core389.ldif
058656
index 246495214..ab124c86c 100644
058656
--- a/ldap/schema/01core389.ldif
058656
+++ b/ldap/schema/01core389.ldif
058656
@@ -303,6 +303,7 @@ attributeTypes: ( 2.16.840.1.113730.3.1.2331 NAME 'nsslapd-logging-hr-timestamps
058656
 attributeTypes: ( 2.16.840.1.113730.3.1.2332 NAME 'allowWeakDHParam' DESC 'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-ORIGIN 'Netscape Directory Server' )
058656
 attributeTypes: ( 2.16.840.1.113730.3.1.2333 NAME 'nsds5ReplicaReleaseTimeout' DESC 'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
058656
 attributeTypes: ( 2.16.840.1.113730.3.1.2335 NAME 'nsds5ReplicaIgnoreMissingChange' DESC 'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
058656
+attributeTypes: ( 2.16.840.1.113730.3.1.2336 NAME 'nsDS5ReplicaBindDnGroupCheckInterval' DESC 'Replication configuration setting for controlling the bind dn group check interval' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
058656
 #
058656
 # objectclasses
058656
 #
058656
@@ -312,7 +313,7 @@ objectClasses: ( 2.16.840.1.113730.3.2.44 NAME 'nsIndex' DESC 'Netscape defined
058656
 objectClasses: ( 2.16.840.1.113730.3.2.109 NAME 'nsBackendInstance' DESC 'Netscape defined objectclass' SUP top  MUST ( CN ) X-ORIGIN 'Netscape Directory Server' )
058656
 objectClasses: ( 2.16.840.1.113730.3.2.110 NAME 'nsMappingTree' DESC 'Netscape defined objectclass' SUP top  MUST ( CN ) X-ORIGIN 'Netscape Directory Server' )
058656
 objectClasses: ( 2.16.840.1.113730.3.2.104 NAME 'nsContainer' DESC 'Netscape defined objectclass' SUP top  MUST ( CN ) X-ORIGIN 'Netscape Directory Server' )
058656
-objectClasses: ( 2.16.840.1.113730.3.2.108 NAME 'nsDS5Replica' DESC 'Netscape defined objectclass' SUP top  MUST ( nsDS5ReplicaRoot $  nsDS5ReplicaId ) MAY (cn $ nsds5ReplicaPreciseTombstonePurging $ nsds5ReplicaCleanRUV $ nsds5ReplicaAbortCleanRUV $ nsDS5ReplicaType $ nsDS5ReplicaBindDN $ nsState $ nsDS5ReplicaName $ nsDS5Flags $ nsDS5Task $ nsDS5ReplicaReferral $ nsDS5ReplicaAutoReferral $ nsds5ReplicaPurgeDelay $ nsds5ReplicaTombstonePurgeInterval $ nsds5ReplicaChangeCount $ nsds5ReplicaLegacyConsumer $ nsds5ReplicaProtocolTimeout $ nsds5ReplicaBackoffMin $ nsds5ReplicaBackoffMax $ nsds5ReplicaReleaseTimeout ) X-ORIGIN 'Netscape Directory Server' )
058656
+objectClasses: ( 2.16.840.1.113730.3.2.108 NAME 'nsDS5Replica' DESC 'Replication configuration objectclass' SUP top  MUST ( nsDS5ReplicaRoot $  nsDS5ReplicaId ) MAY (cn $ nsds5ReplicaPreciseTombstonePurging $ nsds5ReplicaCleanRUV $ nsds5ReplicaAbortCleanRUV $ nsDS5ReplicaType $ nsDS5ReplicaBindDN $ nsState $ nsDS5ReplicaName $ nsDS5Flags $ nsDS5Task $ nsDS5ReplicaReferral $ nsDS5ReplicaAutoReferral $ nsds5ReplicaPurgeDelay $ nsds5ReplicaTombstonePurgeInterval $ nsds5ReplicaChangeCount $ nsds5ReplicaLegacyConsumer $ nsds5ReplicaProtocolTimeout $ nsds5ReplicaBackoffMin $ nsds5ReplicaBackoffMax $ nsds5ReplicaReleaseTimeout $ nsDS5ReplicaBindDnGroupCheckInterval ) X-ORIGIN 'Netscape Directory Server' )
058656
 objectClasses: ( 2.16.840.1.113730.3.2.113 NAME 'nsTombstone' DESC 'Netscape defined objectclass' SUP top MAY ( nstombstonecsn $ nsParentUniqueId $ nscpEntryDN ) X-ORIGIN 'Netscape Directory Server' )
058656
 objectClasses: ( 2.16.840.1.113730.3.2.103 NAME 'nsDS5ReplicationAgreement' DESC 'Netscape defined objectclass' SUP top MUST ( cn ) MAY ( nsds5ReplicaCleanRUVNotified $ nsDS5ReplicaHost $ nsDS5ReplicaPort $ nsDS5ReplicaTransportInfo $ nsDS5ReplicaBindDN $ nsDS5ReplicaCredentials $ nsDS5ReplicaBindMethod $ nsDS5ReplicaRoot $ nsDS5ReplicatedAttributeList $ nsDS5ReplicatedAttributeListTotal $ nsDS5ReplicaUpdateSchedule $ nsds5BeginReplicaRefresh $ description $ nsds50ruv $ nsruvReplicaLastModified $ nsds5ReplicaTimeout $ nsds5replicaChangesSentSinceStartup $ nsds5replicaLastUpdateEnd $ nsds5replicaLastUpdateStart $ nsds5replicaLastUpdateStatus $ nsds5replicaUpdateInProgress $ nsds5replicaLastInitEnd $ nsds5ReplicaEnabled $ nsds5replicaLastInitStart $ nsds5replicaLastInitStatus $ nsds5debugreplicatimeout $ nsds5replicaBusyWaitTime $ nsds5ReplicaStripAttrs $ nsds5replicaSessionPauseTime $ nsds5ReplicaProtocolTimeout $ nsds5ReplicaFlowControlWindow $ nsds5ReplicaFlowControlPause $ nsDS5ReplicaWaitForAsyncResults $ nsds5ReplicaIgnoreMissingChange) X-ORIGIN 'Netscape Directory Server' )
058656
 objectClasses: ( 2.16.840.1.113730.3.2.39 NAME 'nsslapdConfig' DESC 'Netscape defined objectclass' SUP top MAY ( cn ) X-ORIGIN 'Netscape Directory Server' )
058656
diff --git a/ldap/servers/plugins/replication/repl5.h b/ldap/servers/plugins/replication/repl5.h
058656
index 3bd878d4d..c6e79b7e2 100644
058656
--- a/ldap/servers/plugins/replication/repl5.h
058656
+++ b/ldap/servers/plugins/replication/repl5.h
058656
@@ -330,8 +330,8 @@ void replsupplier_configure(Repl_Supplier *rs, Slapi_PBlock *pb);
058656
 void replsupplier_start(Repl_Supplier *rs);
058656
 void replsupplier_stop(Repl_Supplier *rs);
058656
 void replsupplier_destroy(Repl_Supplier **rs);
058656
-void replsupplier_notify(Repl_Supplier *rs, PRUint32 eventmask);
058656
-PRUint32 replsupplier_get_status(Repl_Supplier *rs);
058656
+void replsupplier_notify(Repl_Supplier *rs, uint32_t eventmask);
058656
+uint32_t replsupplier_get_status(Repl_Supplier *rs);
058656
 
058656
 /* In repl5_plugins.c */
058656
 int multimaster_set_local_purl(void);
058656
@@ -383,7 +383,7 @@ int agmt_stop(Repl_Agmt *ra);
058656
 int agmt_replicate_now(Repl_Agmt *ra);
058656
 char *agmt_get_hostname(const Repl_Agmt *ra);
058656
 int agmt_get_port(const Repl_Agmt *ra);
058656
-PRUint32 agmt_get_transport_flags(const Repl_Agmt *ra);
058656
+uint32_t agmt_get_transport_flags(const Repl_Agmt *ra);
058656
 char *agmt_get_binddn(const Repl_Agmt *ra);
058656
 struct berval *agmt_get_credentials(const Repl_Agmt *ra);
058656
 int agmt_get_bindmethod(const Repl_Agmt *ra);
058656
@@ -448,8 +448,8 @@ int agmt_set_attrs_to_strip(Repl_Agmt *ra, Slapi_Entry *e);
058656
 int agmt_set_timeout(Repl_Agmt *ra, long timeout);
058656
 int agmt_set_ignoremissing(Repl_Agmt *ra, long ignoremissing);
058656
 void agmt_update_done(Repl_Agmt *ra, int is_total);
058656
-PRUint64 agmt_get_protocol_timeout(Repl_Agmt *agmt);
058656
-void agmt_set_protocol_timeout(Repl_Agmt *agmt, PRUint64 timeout);
058656
+uint64_t agmt_get_protocol_timeout(Repl_Agmt *agmt);
058656
+void agmt_set_protocol_timeout(Repl_Agmt *agmt, uint64_t timeout);
058656
 void agmt_update_maxcsn(Replica *r, Slapi_DN *sdn, int op, LDAPMod **mods, CSN *csn);
058656
 void add_agmt_maxcsns(Slapi_Entry *e, Replica *r);
058656
 void agmt_remove_maxcsn(Repl_Agmt *ra);
058656
@@ -532,8 +532,8 @@ void *consumer_connection_extension_constructor(void *object, void *parent);
058656
 void consumer_connection_extension_destructor(void *ext, void *object, void *parent);
058656
 
058656
 /* extension helpers for managing exclusive access */
058656
-consumer_connection_extension *consumer_connection_extension_acquire_exclusive_access(void *conn, PRUint64 connid, int opid);
058656
-int consumer_connection_extension_relinquish_exclusive_access(void *conn, PRUint64 connid, int opid, PRBool force);
058656
+consumer_connection_extension *consumer_connection_extension_acquire_exclusive_access(void *conn, uint64_t connid, int opid);
058656
+int consumer_connection_extension_relinquish_exclusive_access(void *conn, uint64_t connid, int opid, PRBool force);
058656
 
058656
 /* mapping tree extension - stores replica object */
058656
 typedef struct multimaster_mtnode_extension
058656
@@ -666,8 +666,8 @@ Replica *replica_new_from_entry(Slapi_Entry *e, char *errortext, PRBool is_add_o
058656
 void replica_destroy(void **arg);
058656
 int replica_subentry_update(Slapi_DN *repl_root, ReplicaId rid);
058656
 int replica_subentry_check(Slapi_DN *repl_root, ReplicaId rid);
058656
-PRBool replica_get_exclusive_access(Replica *r, PRBool *isInc, PRUint64 connid, int opid, const char *locking_purl, char **current_purl);
058656
-void replica_relinquish_exclusive_access(Replica *r, PRUint64 connid, int opid);
058656
+PRBool replica_get_exclusive_access(Replica *r, PRBool *isInc, uint64_t connid, int opid, const char *locking_purl, char **current_purl);
058656
+void replica_relinquish_exclusive_access(Replica *r, uint64_t connid, int opid);
058656
 PRBool replica_get_tombstone_reap_active(const Replica *r);
058656
 const Slapi_DN *replica_get_root(const Replica *r);
058656
 const char *replica_get_name(const Replica *r);
058656
@@ -685,11 +685,13 @@ PRBool replica_is_updatedn(Replica *r, const Slapi_DN *sdn);
058656
 void replica_set_updatedn(Replica *r, const Slapi_ValueSet *vs, int mod_op);
058656
 void replica_set_groupdn(Replica *r, const Slapi_ValueSet *vs, int mod_op);
058656
 char *replica_get_generation(const Replica *r);
058656
+
058656
 /* currently supported flags */
058656
 #define REPLICA_LOG_CHANGES 0x1 /* enable change logging */
058656
-PRBool replica_is_flag_set(const Replica *r, PRUint32 flag);
058656
-void replica_set_flag(Replica *r, PRUint32 flag, PRBool clear);
058656
-void replica_replace_flags(Replica *r, PRUint32 flags);
058656
+
058656
+PRBool replica_is_flag_set(const Replica *r, uint32_t flag);
058656
+void replica_set_flag(Replica *r, uint32_t flag, PRBool clear);
058656
+void replica_replace_flags(Replica *r, uint32_t flags);
058656
 void replica_dump(Replica *r);
058656
 void replica_set_enabled(Replica *r, PRBool enable);
058656
 Object *replica_get_replica_from_dn(const Slapi_DN *dn);
058656
@@ -720,7 +722,7 @@ int replica_delete_by_dn(const char *dn);
058656
 int replica_is_being_configured(const char *dn);
058656
 void consumer5_set_mapping_tree_state_for_replica(const Replica *r, RUV *supplierRuv);
058656
 Object *replica_get_for_backend(const char *be_name);
058656
-void replica_set_purge_delay(Replica *r, PRUint32 purge_delay);
058656
+void replica_set_purge_delay(Replica *r, uint32_t purge_delay);
058656
 void replica_set_tombstone_reap_interval(Replica *r, long interval);
058656
 void replica_update_ruv_consumer(Replica *r, RUV *supplier_ruv);
058656
 void replica_set_ruv_dirty(Replica *r);
058656
@@ -730,20 +732,20 @@ char *replica_get_dn(Replica *r);
058656
 void replica_check_for_tasks(Replica *r, Slapi_Entry *e);
058656
 void replica_update_state(time_t when, void *arg);
058656
 void replica_reset_csn_pl(Replica *r);
058656
-PRUint64 replica_get_protocol_timeout(Replica *r);
058656
-void replica_set_protocol_timeout(Replica *r, PRUint64 timeout);
058656
-PRUint64 replica_get_release_timeout(Replica *r);
058656
-void replica_set_release_timeout(Replica *r, PRUint64 timeout);
058656
+uint64_t replica_get_protocol_timeout(Replica *r);
058656
+void replica_set_protocol_timeout(Replica *r, uint64_t timeout);
058656
+uint64_t replica_get_release_timeout(Replica *r);
058656
+void replica_set_release_timeout(Replica *r, uint64_t timeout);
058656
 void replica_set_groupdn_checkinterval(Replica *r, int timeout);
058656
-PRUint64 replica_get_backoff_min(Replica *r);
058656
-PRUint64 replica_get_backoff_max(Replica *r);
058656
-void replica_set_backoff_min(Replica *r, PRUint64 min);
058656
-void replica_set_backoff_max(Replica *r, PRUint64 max);
058656
+uint64_t replica_get_backoff_min(Replica *r);
058656
+uint64_t replica_get_backoff_max(Replica *r);
058656
+void replica_set_backoff_min(Replica *r, uint64_t min);
058656
+void replica_set_backoff_max(Replica *r, uint64_t max);
058656
 int replica_get_agmt_count(Replica *r);
058656
 void replica_incr_agmt_count(Replica *r);
058656
 void replica_decr_agmt_count(Replica *r);
058656
-PRUint64 replica_get_precise_purging(Replica *r);
058656
-void replica_set_precise_purging(Replica *r, PRUint64 on_off);
058656
+uint64_t replica_get_precise_purging(Replica *r);
058656
+void replica_set_precise_purging(Replica *r, uint64_t on_off);
058656
 PRBool ignore_error_and_keep_going(int error);
058656
 void replica_check_release_timeout(Replica *r, Slapi_PBlock *pb);
058656
 void replica_lock_replica(Replica *r);
058656
@@ -764,8 +766,8 @@ void replica_unlock_replica(Replica *r);
058656
                                               is active, RECV should back off. And vice versa.  But SEND can coexist. */
058656
 #define REPLICA_TOTAL_EXCL_RECV         32 /* ditto */
058656
 
058656
-PRBool replica_is_state_flag_set(Replica *r, PRInt32 flag);
058656
-void replica_set_state_flag(Replica *r, PRUint32 flag, PRBool clear);
058656
+PRBool replica_is_state_flag_set(Replica *r, int32_t flag);
058656
+void replica_set_state_flag(Replica *r, uint32_t flag, PRBool clear);
058656
 void replica_set_tombstone_reap_stop(Replica *r, PRBool val);
058656
 void replica_enable_replication(Replica *r);
058656
 void replica_disable_replication(Replica *r, Object *r_obj);
058656
@@ -836,6 +838,8 @@ LDAPControl *create_managedsait_control(void);
058656
 LDAPControl *create_backend_control(Slapi_DN *sdn);
058656
 void repl_set_mtn_state_and_referrals(const Slapi_DN *sdn, const char *mtn_state, const RUV *ruv, char **ruv_referrals, char **other_referrals);
058656
 void repl_set_repl_plugin_path(const char *path);
058656
+int repl_config_valid_num(const char *config_attr, char *config_attr_value, int64_t min, int64_t max,
058656
+                          int *returncode, char *errortext, int64_t *retval);
058656
 
058656
 /* repl5_updatedn_list.c */
058656
 typedef void *ReplicaUpdateDNList;
058656
diff --git a/ldap/servers/plugins/replication/repl5_agmt.c b/ldap/servers/plugins/replication/repl5_agmt.c
058656
index e2ab320e4..78fb91ae6 100644
058656
--- a/ldap/servers/plugins/replication/repl5_agmt.c
058656
+++ b/ldap/servers/plugins/replication/repl5_agmt.c
058656
@@ -65,31 +65,31 @@
058656
 struct changecounter
058656
 {
058656
     ReplicaId rid;
058656
-    PRUint32 num_replayed;
058656
-    PRUint32 num_skipped;
058656
+    uint32_t num_replayed;
058656
+    uint32_t num_skipped;
058656
 };
058656
 
058656
 typedef struct repl5agmt
058656
 {
058656
     char *hostname;                        /* remote hostname */
058656
-    int port;                              /* port of remote server */
058656
-    PRUint32 transport_flags;              /* SSL, TLS, etc. */
058656
+    int64_t port;                          /* port of remote server */
058656
+    uint32_t transport_flags;              /* SSL, TLS, etc. */
058656
     char *binddn;                          /* DN to bind as */
058656
     struct berval *creds;                  /* Password, or certificate */
058656
-    int bindmethod;                        /* Bind method - simple, SSL */
058656
+    int64_t bindmethod;                    /* Bind method - simple, SSL */
058656
     Slapi_DN *replarea;                    /* DN of replicated area */
058656
     char **frac_attrs;                     /* list of fractional attributes to be replicated */
058656
     char **frac_attrs_total;               /* list of fractional attributes to be replicated for total update protocol */
058656
     PRBool frac_attr_total_defined;        /* TRUE if frac_attrs_total is defined */
058656
     Schedule *schedule;                    /* Scheduling information */
058656
-    int auto_initialize;                   /* 1 = automatically re-initialize replica */
058656
+    int64_t auto_initialize;               /* 1 = automatically re-initialize replica */
058656
     const Slapi_DN *dn;                    /* DN of replication agreement entry */
058656
     const Slapi_RDN *rdn;                  /* RDN of replication agreement entry */
058656
     char *long_name;                       /* Long name (rdn + host, port) of entry, for logging */
058656
     Repl_Protocol *protocol;               /* Protocol object - manages protocol */
058656
     struct changecounter **changecounters; /* changes sent/skipped since server start up */
058656
-    int num_changecounters;
058656
-    int max_changecounters;
058656
+    int64_t num_changecounters;
058656
+    int64_t max_changecounters;
058656
     time_t last_update_start_time;       /* Local start time of last update session */
058656
     time_t last_update_end_time;         /* Local end time of last update session */
058656
     char last_update_status[STATUS_LEN]; /* Status of last update. Format = numeric code <space> textual description */
058656
@@ -102,35 +102,35 @@ typedef struct repl5agmt
058656
     Object *consumerRUV;     /* last RUV received from the consumer - used for changelog purging */
058656
     CSN *consumerSchemaCSN;  /* last schema CSN received from the consumer */
058656
     ReplicaId consumerRID;   /* indicates if the consumer is the originator of a CSN */
058656
-    int tmpConsumerRID;      /* Indicates the consumer rid was set from the agmt maxcsn - it should be refreshed */
058656
-    long timeout;            /* timeout (in seconds) for outbound LDAP connections to remote server */
058656
+    int64_t tmpConsumerRID;  /* Indicates the consumer rid was set from the agmt maxcsn - it should be refreshed */
058656
+    int64_t timeout;         /* timeout (in seconds) for outbound LDAP connections to remote server */
058656
     PRBool stop_in_progress; /* set by agmt_stop when shutting down */
058656
-    long busywaittime;       /* time in seconds to wait after getting a REPLICA BUSY from the consumer -
058656
-                          to allow another supplier to finish sending its updates -
058656
-                          if set to 0, this means to use the default value if we get a busy
058656
-                          signal from the consumer */
058656
-    long pausetime;          /* time in seconds to pause after sending updates -
058656
-                       to allow another supplier to send its updates -
058656
-                       should be greater than busywaittime -
058656
-                       if set to 0, this means do not pause */
058656
+    int64_t busywaittime;    /* time in seconds to wait after getting a REPLICA BUSY from the consumer -
058656
+                              * to allow another supplier to finish sending its updates -
058656
+                              * if set to 0, this means to use the default value if we get a busy
058656
+                              * signal from the consumer
058656
+                              */
058656
+    int64_t pausetime;       /* time in seconds to pause after sending updates -
058656
+                              * to allow another supplier to send its updates -
058656
+                              * should be greater than busywaittime -
058656
+                              * if set to 0, this means do not pause
058656
+                              */
058656
     void *priv;              /* private data, used for windows-specific agreement data
058656
-                   for sync agreements or for replication session plug-in
058656
-                   private data for normal replication agreements */
058656
+                              * for sync agreements or for replication session plug-in
058656
+                              * private data for normal replication agreements
058656
+                              */
058656
     char **attrs_to_strip;   /* for fractional replication, if a "mod" is empty, strip out these attributes:
058656
-                            * modifiersname, modifytimestamp, internalModifiersname, internalModifyTimestamp, etc */
058656
-    int agreement_type;
058656
+                              * modifiersname, modifytimestamp, internalModifiersname, internalModifyTimestamp, etc */
058656
+    int64_t agreement_type;
058656
     Slapi_Counter *protocol_timeout;
058656
-    char *maxcsn;             /* agmt max csn */
058656
-    long flowControlWindow;   /* This is the maximum number of entries
058656
-                             * sent without acknowledgment
058656
-                             */
058656
-    long flowControlPause;    /* When nb of not acknowledged entries overpass totalUpdateWindow
058656
-                            * This is the duration (in msec) that the RA will pause before sending the next entry
058656
-                            */
058656
-    long ignoreMissingChange; /* if set replication will try to continue even if change cannot be found in changelog */
058656
-    Slapi_RWLock *attr_lock;  /* RW lock for all the stripped attrs */
058656
-    int WaitForAsyncResults;  /* Pass to DS_Sleep(PR_MillisecondsToInterval(WaitForAsyncResults))
058656
-                              * in repl5_inc_waitfor_async_results */
058656
+    char *maxcsn;                /* agmt max csn */
058656
+    int64_t flowControlWindow;   /* This is the maximum number of entries sent without acknowledgment */
058656
+    int64_t flowControlPause;    /* When nb of not acknowledged entries overpass totalUpdateWindow
058656
+                                  * This is the duration (in msec) that the RA will pause before sending the next entry */
058656
+    int64_t ignoreMissingChange; /* if set replication will try to continue even if change cannot be found in changelog */
058656
+    Slapi_RWLock *attr_lock;     /* RW lock for all the stripped attrs */
058656
+    int64_t WaitForAsyncResults; /* Pass to DS_Sleep(PR_MillisecondsToInterval(WaitForAsyncResults))
058656
+                                  * in repl5_inc_waitfor_async_results */
058656
 } repl5agmt;
058656
 
058656
 /* Forward declarations */
058656
@@ -182,7 +182,7 @@ agmt_is_valid(Repl_Agmt *ra)
058656
     }
058656
     if (ra->port <= 0) {
058656
         slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "agmt_is_valid - Replication agreement \"%s\" "
058656
-                                                       "is malformed: invalid port number %d.\n",
058656
+                                                       "is malformed: invalid port number %ld.\n",
058656
                       slapi_sdn_get_dn(ra->dn), ra->port);
058656
         return_value = 0;
058656
     }
058656
@@ -241,10 +241,14 @@ agmt_new_from_entry(Slapi_Entry *e)
058656
 {
058656
     Repl_Agmt *ra;
058656
     Slapi_Attr *sattr;
058656
+    char errormsg[SLAPI_DSE_RETURNTEXT_SIZE];
058656
     char *tmpstr;
058656
     char **denied_attrs = NULL;
058656
     char *auto_initialize = NULL;
058656
     char *val_nsds5BeginReplicaRefresh = "start";
058656
+    char *val = NULL;
058656
+    int64_t ptimeout = 0;
058656
+    int rc = 0;
058656
 
058656
     ra = (Repl_Agmt *)slapi_ch_calloc(1, sizeof(repl5agmt));
058656
     if ((ra->lock = PR_NewLock()) == NULL) {
058656
@@ -283,8 +287,17 @@ agmt_new_from_entry(Slapi_Entry *e)
058656
 
058656
     /* Host name of remote replica */
058656
     ra->hostname = slapi_entry_attr_get_charptr(e, type_nsds5ReplicaHost);
058656
+
058656
     /* Port number for remote replica instance */
058656
-    ra->port = slapi_entry_attr_get_int(e, type_nsds5ReplicaPort);
058656
+    if ((val = slapi_entry_attr_get_charptr(e, type_nsds5ReplicaPort))){
058656
+        int64_t port;
058656
+        if (repl_config_valid_num(type_nsds5ReplicaPort, val, 1, 65535, &rc, errormsg, &port) != 0) {
058656
+            goto loser;
058656
+        }
058656
+        slapi_ch_free_string(&val;;
058656
+        ra->port = port;
058656
+    }
058656
+
058656
     /* SSL, TLS, or other transport stuff */
058656
     ra->transport_flags = 0;
058656
     (void)agmt_set_transportinfo_no_lock(ra, e);
058656
@@ -313,29 +326,35 @@ agmt_new_from_entry(Slapi_Entry *e)
058656
 
058656
     /* timeout. */
058656
     ra->timeout = DEFAULT_TIMEOUT;
058656
-    if (slapi_entry_attr_find(e, type_nsds5ReplicaTimeout, &sattr) == 0) {
058656
-        Slapi_Value *sval;
058656
-        if (slapi_attr_first_value(sattr, &sval) == 0) {
058656
-            ra->timeout = slapi_value_get_long(sval);
058656
+    if ((val = slapi_entry_attr_get_charptr(e, type_nsds5ReplicaTimeout))){
058656
+        int64_t timeout;
058656
+        if (repl_config_valid_num(type_nsds5ReplicaTimeout, val, 0, INT_MAX, &rc, errormsg, &timeout) != 0) {
058656
+            goto loser;
058656
         }
058656
+        slapi_ch_free_string(&val;;
058656
+        ra->timeout = timeout;
058656
     }
058656
 
058656
     /* flow control update window. */
058656
     ra->flowControlWindow = DEFAULT_FLOWCONTROL_WINDOW;
058656
-    if (slapi_entry_attr_find(e, type_nsds5ReplicaFlowControlWindow, &sattr) == 0) {
058656
-        Slapi_Value *sval;
058656
-        if (slapi_attr_first_value(sattr, &sval) == 0) {
058656
-            ra->flowControlWindow = slapi_value_get_long(sval);
058656
+    if ((val = slapi_entry_attr_get_charptr(e, type_nsds5ReplicaFlowControlWindow))){
058656
+        int64_t flow;
058656
+        if (repl_config_valid_num(type_nsds5ReplicaTimeout, val, 0, INT_MAX, &rc, errormsg, &flow) != 0) {
058656
+            goto loser;
058656
         }
058656
+        slapi_ch_free_string(&val;;
058656
+        ra->flowControlWindow = flow;
058656
     }
058656
 
058656
     /* flow control update pause. */
058656
     ra->flowControlPause = DEFAULT_FLOWCONTROL_PAUSE;
058656
-    if (slapi_entry_attr_find(e, type_nsds5ReplicaFlowControlPause, &sattr) == 0) {
058656
-        Slapi_Value *sval;
058656
-        if (slapi_attr_first_value(sattr, &sval) == 0) {
058656
-            ra->flowControlPause = slapi_value_get_long(sval);
058656
+    if ((val = slapi_entry_attr_get_charptr(e, type_nsds5ReplicaFlowControlPause))){
058656
+        int64_t pause;
058656
+        if (repl_config_valid_num(type_nsds5ReplicaFlowControlPause, val, 0, INT_MAX, &rc, errormsg, &pause) != 0) {
058656
+            goto loser;
058656
         }
058656
+        slapi_ch_free_string(&val;;
058656
+        ra->flowControlPause = pause;
058656
     }
058656
 
058656
     /* continue on missing change ? */
058656
@@ -357,7 +376,6 @@ agmt_new_from_entry(Slapi_Entry *e)
058656
     if (NULL != tmpstr) {
058656
         Object *repl_obj;
058656
         Replica *replica;
058656
-        PRUint64 ptimeout = 0;
058656
 
058656
         ra->replarea = slapi_sdn_new_dn_passin(tmpstr);
058656
 
058656
@@ -367,14 +385,18 @@ agmt_new_from_entry(Slapi_Entry *e)
058656
                 replica_incr_agmt_count(replica);
058656
             }
058656
         }
058656
+    }
058656
 
058656
-        /* If this agmt has its own timeout, grab it, otherwise use the replica's protocol timeout */
058656
-        ptimeout = slapi_entry_attr_get_int(e, type_replicaProtocolTimeout);
058656
-        if (ptimeout) {
058656
-            slapi_counter_set_value(ra->protocol_timeout, ptimeout);
058656
+    /* If this agmt has its own timeout, grab it, otherwise use the replica's protocol timeout */
058656
+    if ((val = slapi_entry_attr_get_charptr(e, type_replicaProtocolTimeout))){
058656
+        if (repl_config_valid_num(type_replicaProtocolTimeout, val, 0, INT_MAX, &rc, errormsg, &ptimeout) != 0) {
058656
+            goto loser;
058656
         }
058656
+        slapi_ch_free_string(&val;;
058656
+        slapi_counter_set_value(ra->protocol_timeout, ptimeout);
058656
     }
058656
 
058656
+
058656
     /* Replica enabled */
058656
     tmpstr = slapi_entry_attr_get_charptr(e, type_nsds5ReplicaEnabled);
058656
     if (NULL != tmpstr) {
058656
@@ -384,9 +406,8 @@ agmt_new_from_entry(Slapi_Entry *e)
058656
             ra->is_enabled = PR_TRUE;
058656
         } else {
058656
             slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "agmt_new_from_entry - "
058656
-                                                           "Warning invalid value for nsds5ReplicaEnabled (%s), value must be \"on\" or \"off\".  "
058656
-                                                           "Ignoring this repl agreement.\n",
058656
-                          tmpstr);
058656
+                    "Warning invalid value for nsds5ReplicaEnabled (%s), value must be \"on\" or \"off\".  "
058656
+                    "Ignoring this repl agreement.\n", tmpstr);
058656
             slapi_ch_free_string(&tmpstr);
058656
             goto loser;
058656
         }
058656
@@ -402,11 +423,24 @@ agmt_new_from_entry(Slapi_Entry *e)
058656
     }
058656
 
058656
     /* busy wait time - time to wait after getting REPLICA BUSY from consumer */
058656
-    ra->busywaittime = slapi_entry_attr_get_long(e, type_nsds5ReplicaBusyWaitTime);
058656
+    if ((val = slapi_entry_attr_get_charptr(e, type_nsds5ReplicaBusyWaitTime))){
058656
+        int64_t busytime = 0;
058656
+        if (repl_config_valid_num(type_nsds5ReplicaBusyWaitTime, val, 0, INT_MAX, &rc, errormsg, &busytime) != 0) {
058656
+            goto loser;
058656
+        }
058656
+        slapi_ch_free_string(&val;;
058656
+        ra->busywaittime = busytime;
058656
+    }
058656
 
058656
     /* pause time - time to pause after a session has ended */
058656
-    ra->pausetime = slapi_entry_attr_get_long(e, type_nsds5ReplicaSessionPauseTime);
058656
-
058656
+    if ((val = slapi_entry_attr_get_charptr(e, type_nsds5ReplicaSessionPauseTime))){
058656
+        int64_t pausetime = 0;
058656
+        if (repl_config_valid_num(type_nsds5ReplicaSessionPauseTime, val, 0, INT_MAX, &rc, errormsg, &pausetime) != 0) {
058656
+            goto loser;
058656
+        }
058656
+        slapi_ch_free_string(&val;;
058656
+        ra->pausetime = pausetime;
058656
+    }
058656
     /* consumer's RUV */
058656
     if (slapi_entry_attr_find(e, type_ruvElement, &sattr) == 0) {
058656
         RUV *ruv;
058656
@@ -434,7 +468,7 @@ agmt_new_from_entry(Slapi_Entry *e)
058656
         if (dot) {
058656
             *dot = '\0';
058656
         }
058656
-        ra->long_name = slapi_ch_smprintf("agmt=\"%s\" (%s:%d)", agmtname, hostname, ra->port);
058656
+        ra->long_name = slapi_ch_smprintf("agmt=\"%s\" (%s:%ld)", agmtname, hostname, ra->port);
058656
     }
058656
 
058656
     /* DBDB: review this code */
058656
@@ -534,6 +568,9 @@ agmt_new_from_entry(Slapi_Entry *e)
058656
 
058656
     return ra;
058656
 loser:
058656
+    slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
058656
+                  "agmt_new_from_entry - Failed to parse agreement, skipping.\n");
058656
+    slapi_ch_free_string(&val;;
058656
     agmt_delete((void **)&ra);
058656
     return NULL;
058656
 }
058656
@@ -754,10 +791,10 @@ agmt_start(Repl_Agmt *ra)
058656
                     char buf[BUFSIZ];
058656
                     char unavail_buf[BUFSIZ];
058656
 
058656
-                    PR_snprintf(buf, BUFSIZ, "%s;%s;%s;%d;", slapi_sdn_get_dn(repl_sdn),
058656
+                    PR_snprintf(buf, BUFSIZ, "%s;%s;%s;%ld;", slapi_sdn_get_dn(repl_sdn),
058656
                                 slapi_rdn_get_value_by_ref(slapi_rdn_get_rdn(ra->rdn)),
058656
                                 ra->hostname, ra->port);
058656
-                    PR_snprintf(unavail_buf, BUFSIZ, "%s;%s;%s;%d;unavailable", slapi_sdn_get_dn(repl_sdn),
058656
+                    PR_snprintf(unavail_buf, BUFSIZ, "%s;%s;%s;%ld;unavailable", slapi_sdn_get_dn(repl_sdn),
058656
                                 slapi_rdn_get_value_by_ref(slapi_rdn_get_rdn(ra->rdn)),
058656
                                 ra->hostname, ra->port);
058656
                     if (strstr(maxcsns[i], buf) || strstr(maxcsns[i], unavail_buf)) {
058656
@@ -901,7 +938,7 @@ agmt_get_port(const Repl_Agmt *ra)
058656
 /*
058656
  * Return the transport flags for this agreement.
058656
  */
058656
-PRUint32
058656
+uint32_t
058656
 agmt_get_transport_flags(const Repl_Agmt *ra)
058656
 {
058656
     unsigned int return_value;
058656
@@ -2919,7 +2956,7 @@ agmt_update_done(Repl_Agmt *agmt, int is_total)
058656
     }
058656
 }
058656
 
058656
-PRUint64
058656
+uint64_t
058656
 agmt_get_protocol_timeout(Repl_Agmt *agmt)
058656
 {
058656
     if (agmt) {
058656
@@ -2930,7 +2967,7 @@ agmt_get_protocol_timeout(Repl_Agmt *agmt)
058656
 }
058656
 
058656
 void
058656
-agmt_set_protocol_timeout(Repl_Agmt *agmt, PRUint64 timeout)
058656
+agmt_set_protocol_timeout(Repl_Agmt *agmt, uint64_t timeout)
058656
 {
058656
     if (agmt) {
058656
         slapi_counter_set_value(agmt->protocol_timeout, timeout);
058656
@@ -2992,11 +3029,11 @@ agmt_update_maxcsn(Replica *r, Slapi_DN *sdn, int op, LDAPMod **mods, CSN *csn)
058656
                  * temporarily mark it as "unavailable".
058656
                  */
058656
                 slapi_ch_free_string(&agmt->maxcsn);
058656
-                agmt->maxcsn = slapi_ch_smprintf("%s;%s;%s;%d;unavailable", slapi_sdn_get_dn(agmt->replarea),
058656
+                agmt->maxcsn = slapi_ch_smprintf("%s;%s;%s;%ld;unavailable", slapi_sdn_get_dn(agmt->replarea),
058656
                                                  slapi_rdn_get_value_by_ref(slapi_rdn_get_rdn(agmt->rdn)), agmt->hostname, agmt->port);
058656
             } else if (rid == oprid) {
058656
                 slapi_ch_free_string(&agmt->maxcsn);
058656
-                agmt->maxcsn = slapi_ch_smprintf("%s;%s;%s;%d;%d;%s", slapi_sdn_get_dn(agmt->replarea),
058656
+                agmt->maxcsn = slapi_ch_smprintf("%s;%s;%s;%ld;%d;%s", slapi_sdn_get_dn(agmt->replarea),
058656
                                                  slapi_rdn_get_value_by_ref(slapi_rdn_get_rdn(agmt->rdn)), agmt->hostname,
058656
                                                  agmt->port, agmt->consumerRID, maxcsn);
058656
             }
058656
@@ -3190,10 +3227,10 @@ agmt_remove_maxcsn(Repl_Agmt *ra)
058656
                     char unavail_buf[BUFSIZ];
058656
                     struct berval val;
058656
 
058656
-                    PR_snprintf(buf, BUFSIZ, "%s;%s;%s;%d;", slapi_sdn_get_dn(ra->replarea),
058656
+                    PR_snprintf(buf, BUFSIZ, "%s;%s;%s;%ld;", slapi_sdn_get_dn(ra->replarea),
058656
                                 slapi_rdn_get_value_by_ref(slapi_rdn_get_rdn(ra->rdn)),
058656
                                 ra->hostname, ra->port);
058656
-                    PR_snprintf(unavail_buf, BUFSIZ, "%s;%s;%s;%d;unavailable",
058656
+                    PR_snprintf(unavail_buf, BUFSIZ, "%s;%s;%s;%ld;unavailable",
058656
                                 slapi_sdn_get_dn(ra->replarea),
058656
                                 slapi_rdn_get_value_by_ref(slapi_rdn_get_rdn(ra->rdn)),
058656
                                 ra->hostname, ra->port);
058656
diff --git a/ldap/servers/plugins/replication/repl5_replica.c b/ldap/servers/plugins/replication/repl5_replica.c
058656
index 92f847f24..e5296bf1c 100644
058656
--- a/ldap/servers/plugins/replication/repl5_replica.c
058656
+++ b/ldap/servers/plugins/replication/repl5_replica.c
058656
@@ -33,42 +33,40 @@ struct replica
058656
     Slapi_DN *repl_root;               /* top of the replicated are */
058656
     char *repl_name;                   /* unique replica name */
058656
     PRBool new_name;                   /* new name was generated - need to be saved */
058656
-    ReplicaUpdateDNList updatedn_list; /* list of dns with which a supplier should bind
058656
-                           to update this replica                */
058656
-    Slapi_ValueSet *updatedn_groups;   /* set of groups whose memebers are
058656
-                                * allowed to update replica */
058656
+    ReplicaUpdateDNList updatedn_list; /* list of dns with which a supplier should bind to update this replica */
058656
+    Slapi_ValueSet *updatedn_groups;   /* set of groups whose memebers are allowed to update replica */
058656
     ReplicaUpdateDNList groupdn_list;  /* exploded listof dns from update group */
058656
-    PRUint32 updatedn_group_last_check;
058656
-    int updatedn_group_check_interval;
058656
-    ReplicaType repl_type;           /* is this replica read-only ?            */
058656
-    ReplicaId repl_rid;              /* replicaID                            */
058656
-    Object *repl_ruv;                /* replica update vector                */
058656
-    PRBool repl_ruv_dirty;           /* Dirty flag for ruv                   */
058656
-    CSNPL *min_csn_pl;               /* Pending list for minimal CSN         */
058656
-    void *csn_pl_reg_id;             /* registration assignment for csn callbacks */
058656
-    unsigned long repl_state_flags;  /* state flags                            */
058656
-    PRUint32 repl_flags;             /* persistent, externally visible flags */
058656
-    PRMonitor *repl_lock;            /* protects entire structure            */
058656
-    Slapi_Eq_Context repl_eqcxt_rs;  /* context to cancel event that saves ruv */
058656
-    Slapi_Eq_Context repl_eqcxt_tr;  /* context to cancel event that reaps tombstones */
058656
-    Object *repl_csngen;             /* CSN generator for this replica */
058656
-    PRBool repl_csn_assigned;        /* Flag set when new csn is assigned. */
058656
-    PRUint32 repl_purge_delay;       /* When purgeable, CSNs are held on to for this many extra seconds */
058656
-    PRBool tombstone_reap_stop;      /* TRUE when the tombstone reaper should stop */
058656
-    PRBool tombstone_reap_active;    /* TRUE when the tombstone reaper is running */
058656
-    long tombstone_reap_interval;    /* Time in seconds between tombstone reaping */
058656
-    Slapi_ValueSet *repl_referral;   /* A list of administrator provided referral URLs */
058656
-    PRBool state_update_inprogress;  /* replica state is being updated */
058656
-    PRLock *agmt_lock;               /* protects agreement creation, start and stop */
058656
-    char *locking_purl;              /* supplier who has exclusive access */
058656
-    uint64_t locking_conn;           /* The supplier's connection id */
058656
-    Slapi_Counter *protocol_timeout; /* protocol shutdown timeout */
058656
-    Slapi_Counter *backoff_min;      /* backoff retry minimum */
058656
-    Slapi_Counter *backoff_max;      /* backoff retry maximum */
058656
-    Slapi_Counter *precise_purging;  /* Enable precise tombstone purging */
058656
-    PRUint64 agmt_count;             /* Number of agmts */
058656
-    Slapi_Counter *release_timeout;  /* The amount of time to wait before releasing active replica */
058656
-    PRUint64 abort_session;          /* Abort the current replica session */
058656
+    uint32_t updatedn_group_last_check;    /* the time of the last group check */
058656
+    int64_t updatedn_group_check_interval; /* the group check interval */
058656
+    ReplicaType repl_type;             /* is this replica read-only ? */
058656
+    ReplicaId repl_rid;                /* replicaID */
058656
+    Object *repl_ruv;                  /* replica update vector */
058656
+    PRBool repl_ruv_dirty;             /* Dirty flag for ruv */
058656
+    CSNPL *min_csn_pl;                 /* Pending list for minimal CSN */
058656
+    void *csn_pl_reg_id;               /* registration assignment for csn callbacks */
058656
+    unsigned long repl_state_flags;    /* state flags */
058656
+    uint32_t repl_flags;               /* persistent, externally visible flags */
058656
+    PRMonitor *repl_lock;              /* protects entire structure */
058656
+    Slapi_Eq_Context repl_eqcxt_rs;    /* context to cancel event that saves ruv */
058656
+    Slapi_Eq_Context repl_eqcxt_tr;    /* context to cancel event that reaps tombstones */
058656
+    Object *repl_csngen;               /* CSN generator for this replica */
058656
+    PRBool repl_csn_assigned;          /* Flag set when new csn is assigned. */
058656
+    int64_t repl_purge_delay;          /* When purgeable, CSNs are held on to for this many extra seconds */
058656
+    PRBool tombstone_reap_stop;        /* TRUE when the tombstone reaper should stop */
058656
+    PRBool tombstone_reap_active;      /* TRUE when the tombstone reaper is running */
058656
+    int64_t tombstone_reap_interval;   /* Time in seconds between tombstone reaping */
058656
+    Slapi_ValueSet *repl_referral;     /* A list of administrator provided referral URLs */
058656
+    PRBool state_update_inprogress;    /* replica state is being updated */
058656
+    PRLock *agmt_lock;                 /* protects agreement creation, start and stop */
058656
+    char *locking_purl;                /* supplier who has exclusive access */
058656
+    uint64_t locking_conn;             /* The supplier's connection id */
058656
+    Slapi_Counter *protocol_timeout;   /* protocol shutdown timeout */
058656
+    Slapi_Counter *backoff_min;        /* backoff retry minimum */
058656
+    Slapi_Counter *backoff_max;        /* backoff retry maximum */
058656
+    Slapi_Counter *precise_purging;    /* Enable precise tombstone purging */
058656
+    uint64_t agmt_count;               /* Number of agmts */
058656
+    Slapi_Counter *release_timeout;    /* The amount of time to wait before releasing active replica */
058656
+    uint64_t abort_session;            /* Abort the current replica session */
058656
 };
058656
 
058656
 
058656
@@ -532,7 +530,7 @@ replica_subentry_update(Slapi_DN *repl_root, ReplicaId rid)
058656
  * current_purl is the supplier who already has access, if any
058656
  */
058656
 PRBool
058656
-replica_get_exclusive_access(Replica *r, PRBool *isInc, PRUint64 connid, int opid, const char *locking_purl, char **current_purl)
058656
+replica_get_exclusive_access(Replica *r, PRBool *isInc, uint64_t connid, int opid, const char *locking_purl, char **current_purl)
058656
 {
058656
     PRBool rval = PR_TRUE;
058656
 
058656
@@ -608,7 +606,7 @@ done:
058656
  * Relinquish exclusive access to the replica
058656
  */
058656
 void
058656
-replica_relinquish_exclusive_access(Replica *r, PRUint64 connid, int opid)
058656
+replica_relinquish_exclusive_access(Replica *r, uint64_t connid, int opid)
058656
 {
058656
     PRBool isInc;
058656
 
058656
@@ -915,7 +913,7 @@ replica_get_type(const Replica *r)
058656
     return r->repl_type;
058656
 }
058656
 
058656
-PRUint64
058656
+uint64_t
058656
 replica_get_protocol_timeout(Replica *r)
058656
 {
058656
     if (r) {
058656
@@ -925,7 +923,7 @@ replica_get_protocol_timeout(Replica *r)
058656
     }
058656
 }
058656
 
058656
-PRUint64
058656
+uint64_t
058656
 replica_get_release_timeout(Replica *r)
058656
 {
058656
     if (r) {
058656
@@ -936,7 +934,7 @@ replica_get_release_timeout(Replica *r)
058656
 }
058656
 
058656
 void
058656
-replica_set_release_timeout(Replica *r, PRUint64 limit)
058656
+replica_set_release_timeout(Replica *r, uint64_t limit)
058656
 {
058656
     if (r) {
058656
         slapi_counter_set_value(r->release_timeout, limit);
058656
@@ -944,7 +942,7 @@ replica_set_release_timeout(Replica *r, PRUint64 limit)
058656
 }
058656
 
058656
 void
058656
-replica_set_protocol_timeout(Replica *r, PRUint64 timeout)
058656
+replica_set_protocol_timeout(Replica *r, uint64_t timeout)
058656
 {
058656
     if (r) {
058656
         slapi_counter_set_value(r->protocol_timeout, timeout);
058656
@@ -1182,7 +1180,7 @@ replica_get_generation(const Replica *r)
058656
 }
058656
 
058656
 PRBool
058656
-replica_is_flag_set(const Replica *r, PRUint32 flag)
058656
+replica_is_flag_set(const Replica *r, uint32_t flag)
058656
 {
058656
     if (r)
058656
         return (r->repl_flags & flag);
058656
@@ -1191,7 +1189,7 @@ replica_is_flag_set(const Replica *r, PRUint32 flag)
058656
 }
058656
 
058656
 void
058656
-replica_set_flag(Replica *r, PRUint32 flag, PRBool clear)
058656
+replica_set_flag(Replica *r, uint32_t flag, PRBool clear)
058656
 {
058656
     if (r == NULL)
058656
         return;
058656
@@ -1208,7 +1206,7 @@ replica_set_flag(Replica *r, PRUint32 flag, PRBool clear)
058656
 }
058656
 
058656
 void
058656
-replica_replace_flags(Replica *r, PRUint32 flags)
058656
+replica_replace_flags(Replica *r, uint32_t flags)
058656
 {
058656
     if (r) {
058656
         replica_lock(r->repl_lock);
058656
@@ -1829,17 +1827,18 @@ _replica_check_validity(const Replica *r)
058656
 static int
058656
 _replica_init_from_config(Replica *r, Slapi_Entry *e, char *errortext)
058656
 {
058656
-    Slapi_Attr *a = NULL;
058656
     Slapi_Attr *attr;
058656
     CSNGen *gen;
058656
     char *precise_purging = NULL;
058656
     char buf[SLAPI_DSE_RETURNTEXT_SIZE];
058656
     char *errormsg = errortext ? errortext : buf;
058656
     char *val;
058656
-    int backoff_min;
058656
-    int backoff_max;
058656
-    int ptimeout = 0;
058656
-    int release_timeout = 0;
058656
+    int64_t backoff_min;
058656
+    int64_t backoff_max;
058656
+    int64_t ptimeout = 0;
058656
+    int64_t release_timeout = 0;
058656
+    int64_t interval = 0;
058656
+    int64_t rtype = 0;
058656
     int rc;
058656
 
058656
     PR_ASSERT(r && e);
058656
@@ -1847,7 +1846,7 @@ _replica_init_from_config(Replica *r, Slapi_Entry *e, char *errortext)
058656
     /* get replica root */
058656
     val = slapi_entry_attr_get_charptr(e, attr_replicaRoot);
058656
     if (val == NULL) {
058656
-        PR_snprintf(errormsg, SLAPI_DSE_RETURNTEXT_SIZE, "Failed to retrieve %s attribute from (%s)\n",
058656
+        PR_snprintf(errormsg, SLAPI_DSE_RETURNTEXT_SIZE, "Failed to retrieve %s attribute from (%s)",
058656
                     attr_replicaRoot,
058656
                     (char *)slapi_entry_get_dn((Slapi_Entry *)e));
058656
         slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "_replica_init_from_config - %s\n",
058656
@@ -1858,66 +1857,94 @@ _replica_init_from_config(Replica *r, Slapi_Entry *e, char *errortext)
058656
     r->repl_root = slapi_sdn_new_dn_passin(val);
058656
 
058656
     /* get replica type */
058656
-    val = slapi_entry_attr_get_charptr(e, attr_replicaType);
058656
-    if (val) {
058656
-        r->repl_type = atoi(val);
058656
-        slapi_ch_free((void **)&val;;
058656
+    if (slapi_entry_attr_exists(e, attr_replicaType)) {
058656
+        if ((val = slapi_entry_attr_get_charptr(e, attr_replicaType))) {
058656
+            if (repl_config_valid_num(attr_replicaType, val, 0, REPLICA_TYPE_UPDATABLE, &rc, errormsg, &rtype) != 0) {
058656
+                slapi_ch_free_string(&val;;
058656
+                return -1;
058656
+            }
058656
+            r->repl_type = rtype;
058656
+            slapi_ch_free_string(&val;;
058656
+        } else {
058656
+            r->repl_type = REPLICA_TYPE_READONLY;
058656
+        }
058656
     } else {
058656
         r->repl_type = REPLICA_TYPE_READONLY;
058656
     }
058656
 
058656
-    /* grab and validate the backoff retry settings */
058656
+    /* grab and validate the backoff min retry settings */
058656
     if (slapi_entry_attr_exists(e, type_replicaBackoffMin)) {
058656
-        backoff_min = slapi_entry_attr_get_int(e, type_replicaBackoffMin);
058656
-        if (backoff_min <= 0) {
058656
-            slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name, "_replica_init_from_config - "
058656
-                                                               "Invalid value for %s: %d  Using default value (%d)\n",
058656
-                          type_replicaBackoffMin, backoff_min, PROTOCOL_BACKOFF_MINIMUM);
058656
+        if ((val = slapi_entry_attr_get_charptr(e, type_replicaBackoffMin))) {
058656
+            if (repl_config_valid_num(type_replicaBackoffMin, val, 1, INT_MAX, &rc, errormsg, &backoff_min) != 0) {
058656
+                slapi_ch_free_string(&val;;
058656
+                return -1;
058656
+            }
058656
+            slapi_ch_free_string(&val;;
058656
+        } else {
058656
             backoff_min = PROTOCOL_BACKOFF_MINIMUM;
058656
         }
058656
     } else {
058656
         backoff_min = PROTOCOL_BACKOFF_MINIMUM;
058656
     }
058656
 
058656
+    /* grab and validate the backoff max retry settings */
058656
     if (slapi_entry_attr_exists(e, type_replicaBackoffMax)) {
058656
-        backoff_max = slapi_entry_attr_get_int(e, type_replicaBackoffMax);
058656
-        if (backoff_max <= 0) {
058656
-            slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name, "_replica_init_from_config - "
058656
-                                                               "Invalid value for %s: %d  Using default value (%d)\n",
058656
-                          type_replicaBackoffMax, backoff_max, PROTOCOL_BACKOFF_MAXIMUM);
058656
+        if ((val = slapi_entry_attr_get_charptr(e, type_replicaBackoffMax))) {
058656
+            if (repl_config_valid_num(type_replicaBackoffMax, val, 1, INT_MAX, &rc, errormsg, &backoff_max) != 0) {
058656
+                slapi_ch_free_string(&val;;
058656
+                return -1;
058656
+            }
058656
+            slapi_ch_free_string(&val;;
058656
+        } else {
058656
             backoff_max = PROTOCOL_BACKOFF_MAXIMUM;
058656
         }
058656
     } else {
058656
         backoff_max = PROTOCOL_BACKOFF_MAXIMUM;
058656
     }
058656
 
058656
+    /* Verify backoff min and max work together */
058656
     if (backoff_min > backoff_max) {
058656
-        /* Ok these values are invalid, reset back the defaults */
058656
-        slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name, "_replica_init_from_config - "
058656
-                                                           "Backoff minimum (%d) can not be greater than "
058656
-                                                           "the backoff maximum (%d).  Using default values: min (%d) max (%d)\n",
058656
-                      backoff_min, backoff_max, PROTOCOL_BACKOFF_MINIMUM, PROTOCOL_BACKOFF_MAXIMUM);
058656
-        slapi_counter_set_value(r->backoff_min, PROTOCOL_BACKOFF_MINIMUM);
058656
-        slapi_counter_set_value(r->backoff_max, PROTOCOL_BACKOFF_MAXIMUM);
058656
+        PR_snprintf(errormsg, SLAPI_DSE_RETURNTEXT_SIZE,
058656
+                    "Backoff minimum (%ld) can not be greater than the backoff maximum (%ld).",
058656
+                    backoff_min, backoff_max);
058656
+        slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "_replica_init_from_config - "
058656
+                      "%s\n", errormsg);
058656
+        return -1;
058656
     } else {
058656
         slapi_counter_set_value(r->backoff_min, backoff_min);
058656
         slapi_counter_set_value(r->backoff_max, backoff_max);
058656
     }
058656
 
058656
     /* get the protocol timeout */
058656
-    ptimeout = slapi_entry_attr_get_int(e, type_replicaProtocolTimeout);
058656
-    if (ptimeout <= 0) {
058656
-        slapi_counter_set_value(r->protocol_timeout, DEFAULT_PROTOCOL_TIMEOUT);
058656
+    if (slapi_entry_attr_exists(e, type_replicaProtocolTimeout)) {
058656
+        if ((val = slapi_entry_attr_get_charptr(e, type_replicaProtocolTimeout))) {
058656
+            if (repl_config_valid_num(type_replicaProtocolTimeout, val, 0, INT_MAX, &rc, errormsg, &ptimeout) != 0) {
058656
+                slapi_ch_free_string(&val;;
058656
+                return -1;
058656
+            }
058656
+            slapi_ch_free_string(&val;;
058656
+            slapi_counter_set_value(r->protocol_timeout, ptimeout);
058656
+        } else {
058656
+            slapi_counter_set_value(r->protocol_timeout, DEFAULT_PROTOCOL_TIMEOUT);
058656
+        }
058656
     } else {
058656
-        slapi_counter_set_value(r->protocol_timeout, ptimeout);
058656
+        slapi_counter_set_value(r->protocol_timeout, DEFAULT_PROTOCOL_TIMEOUT);
058656
     }
058656
 
058656
     /* Get the release timeout */
058656
-    release_timeout = slapi_entry_attr_get_int(e, type_replicaReleaseTimeout);
058656
-    if (release_timeout <= 0) {
058656
-        slapi_counter_set_value(r->release_timeout, 0);
058656
+    if (slapi_entry_attr_exists(e, type_replicaReleaseTimeout)) {
058656
+        if ((val = slapi_entry_attr_get_charptr(e, type_replicaReleaseTimeout))) {
058656
+            if (repl_config_valid_num(type_replicaReleaseTimeout, val, 0, INT_MAX, &rc, errortext, &release_timeout) != 0) {
058656
+                slapi_ch_free_string(&val;;
058656
+                return -1;
058656
+            }
058656
+            slapi_counter_set_value(r->release_timeout, release_timeout);
058656
+            slapi_ch_free_string(&val;;
058656
+        } else {
058656
+            slapi_counter_set_value(r->release_timeout, 0);
058656
+        }
058656
     } else {
058656
-        slapi_counter_set_value(r->release_timeout, release_timeout);
058656
+        slapi_counter_set_value(r->release_timeout, 0);
058656
     }
058656
 
058656
     /* check for precise tombstone purging */
058656
@@ -1929,10 +1956,11 @@ _replica_init_from_config(Replica *r, Slapi_Entry *e, char *errortext)
058656
             slapi_counter_set_value(r->precise_purging, 0);
058656
         } else {
058656
             /* Invalid value */
058656
-            slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name, "_replica_init_from_config - "
058656
-                                                               "Invalid value for %s: %s  Using default value (off)\n",
058656
-                          type_replicaPrecisePurge, precise_purging);
058656
-            slapi_counter_set_value(r->precise_purging, 0);
058656
+            PR_snprintf(errormsg, SLAPI_DSE_RETURNTEXT_SIZE, "Invalid value for %s: %s",
058656
+                        type_replicaPrecisePurge, precise_purging);
058656
+            slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "_replica_init_from_config - "
058656
+                          "%s\n", errormsg);
058656
+            return -1;
058656
         }
058656
         slapi_ch_free_string(&precise_purging);
058656
     } else {
058656
@@ -1940,7 +1968,19 @@ _replica_init_from_config(Replica *r, Slapi_Entry *e, char *errortext)
058656
     }
058656
 
058656
     /* get replica flags */
058656
-    r->repl_flags = slapi_entry_attr_get_ulong(e, attr_flags);
058656
+    if (slapi_entry_attr_exists(e, attr_flags)) {
058656
+        int64_t rflags;
058656
+        if((val = slapi_entry_attr_get_charptr(e, attr_flags))) {
058656
+            if (repl_config_valid_num(attr_flags, val, 0, 1, &rc, errortext, &rflags) != 0) {
058656
+                return -1;
058656
+            }
058656
+            r->repl_flags = (uint32_t)rflags;
058656
+        } else {
058656
+            r->repl_flags = 0;
058656
+        }
058656
+    } else {
058656
+        r->repl_flags = 0;
058656
+    }
058656
 
058656
     /*
058656
      * Get replicaid
058656
@@ -1955,20 +1995,13 @@ _replica_init_from_config(Replica *r, Slapi_Entry *e, char *errortext)
058656
     else if (r->repl_type == REPLICA_TYPE_UPDATABLE ||
058656
              r->repl_type == REPLICA_TYPE_PRIMARY) {
058656
         if ((val = slapi_entry_attr_get_charptr(e, attr_replicaId))) {
058656
-            int temprid = atoi(val);
058656
-            slapi_ch_free((void **)&val;;
058656
-            if (temprid <= 0 || temprid >= READ_ONLY_REPLICA_ID) {
058656
-                PR_snprintf(errormsg, SLAPI_DSE_RETURNTEXT_SIZE,
058656
-                            "Attribute %s must have a value greater than 0 "
058656
-                            "and less than %d: entry %s",
058656
-                            attr_replicaId, READ_ONLY_REPLICA_ID,
058656
-                            (char *)slapi_entry_get_dn((Slapi_Entry *)e));
058656
-                slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
058656
-                              "_replica_init_from_config - %s\n", errormsg);
058656
+            int64_t rid;
058656
+            if (repl_config_valid_num(attr_replicaId, val, 1, 65535, &rc, errormsg, &rid) != 0) {
058656
+                slapi_ch_free_string(&val;;
058656
                 return -1;
058656
-            } else {
058656
-                r->repl_rid = (ReplicaId)temprid;
058656
             }
058656
+            r->repl_rid = (ReplicaId)rid;
058656
+            slapi_ch_free_string(&val;;
058656
         } else {
058656
             PR_snprintf(errormsg, SLAPI_DSE_RETURNTEXT_SIZE,
058656
                         "Failed to retrieve required %s attribute from %s",
058656
@@ -2003,10 +2036,13 @@ _replica_init_from_config(Replica *r, Slapi_Entry *e, char *errortext)
058656
     r->groupdn_list = replica_groupdn_list_new(r->updatedn_groups);
058656
     r->updatedn_group_last_check = time(NULL);
058656
     /* get groupdn check interval */
058656
-    val = slapi_entry_attr_get_charptr(e, attr_replicaBindDnGroupCheckInterval);
058656
-    if (val) {
058656
-        r->updatedn_group_check_interval = atoi(val);
058656
-        slapi_ch_free((void **)&val;;
058656
+    if ((val = slapi_entry_attr_get_charptr(e, attr_replicaBindDnGroupCheckInterval))) {
058656
+        if (repl_config_valid_num(attr_replicaBindDnGroupCheckInterval, val, -1, INT_MAX, &rc, errormsg, &interval) != 0) {
058656
+            slapi_ch_free_string(&val;;
058656
+            return -1;
058656
+        }
058656
+        r->updatedn_group_check_interval = interval;
058656
+        slapi_ch_free_string(&val;;
058656
     } else {
058656
         r->updatedn_group_check_interval = -1;
058656
     }
058656
@@ -2041,18 +2077,26 @@ _replica_init_from_config(Replica *r, Slapi_Entry *e, char *errortext)
058656
      * since we don't know about LCUP replicas, and they can just
058656
      * turn up whenever they want to.
058656
      */
058656
-    if (slapi_entry_attr_find(e, type_replicaPurgeDelay, &a) == -1) {
058656
-        /* No purge delay provided, so use default */
058656
-        r->repl_purge_delay = 60 * 60 * 24 * 7; /* One week, in seconds */
058656
+    if ((val = slapi_entry_attr_get_charptr(e, type_replicaPurgeDelay))) {
058656
+        if (repl_config_valid_num(type_replicaPurgeDelay, val, -1, INT_MAX, &rc, errormsg, &interval) != 0) {
058656
+            slapi_ch_free_string(&val;;
058656
+            return -1;
058656
+        }
058656
+        r->repl_purge_delay = interval;
058656
+        slapi_ch_free_string(&val;;
058656
     } else {
058656
-        r->repl_purge_delay = slapi_entry_attr_get_uint(e, type_replicaPurgeDelay);
058656
+        r->repl_purge_delay = 60 * 60 * 24 * 7; /* One week, in seconds */
058656
     }
058656
 
058656
-    if (slapi_entry_attr_find(e, type_replicaTombstonePurgeInterval, &a) == -1) {
058656
-        /* No reap interval provided, so use default */
058656
-        r->tombstone_reap_interval = 3600 * 24; /* One day */
058656
+    if ((val = slapi_entry_attr_get_charptr(e, type_replicaTombstonePurgeInterval))) {
058656
+        if (repl_config_valid_num(type_replicaTombstonePurgeInterval, val, -1, INT_MAX, &rc, errormsg, &interval) != 0) {
058656
+            slapi_ch_free_string(&val;;
058656
+            return -1;
058656
+        }
058656
+        r->tombstone_reap_interval = interval;
058656
+        slapi_ch_free_string(&val;;
058656
     } else {
058656
-        r->tombstone_reap_interval = slapi_entry_attr_get_int(e, type_replicaTombstonePurgeInterval);
058656
+        r->tombstone_reap_interval = 3600 * 24; /* One week, in seconds */
058656
     }
058656
 
058656
     r->tombstone_reap_stop = r->tombstone_reap_active = PR_FALSE;
058656
@@ -3534,7 +3578,7 @@ replica_log_ruv_elements_nolock(const Replica *r)
058656
 }
058656
 
058656
 void
058656
-replica_set_purge_delay(Replica *r, PRUint32 purge_delay)
058656
+replica_set_purge_delay(Replica *r, uint32_t purge_delay)
058656
 {
058656
     PR_ASSERT(r);
058656
     replica_lock(r->repl_lock);
058656
@@ -3710,7 +3754,7 @@ replica_set_ruv_dirty(Replica *r)
058656
 }
058656
 
058656
 PRBool
058656
-replica_is_state_flag_set(Replica *r, PRInt32 flag)
058656
+replica_is_state_flag_set(Replica *r, int32_t flag)
058656
 {
058656
     PR_ASSERT(r);
058656
     if (r)
058656
@@ -3720,7 +3764,7 @@ replica_is_state_flag_set(Replica *r, PRInt32 flag)
058656
 }
058656
 
058656
 void
058656
-replica_set_state_flag(Replica *r, PRUint32 flag, PRBool clear)
058656
+replica_set_state_flag(Replica *r, uint32_t flag, PRBool clear)
058656
 {
058656
     if (r == NULL)
058656
         return;
058656
@@ -3994,7 +4038,7 @@ replica_get_attr(Slapi_PBlock *pb, const char *type, void *value)
058656
     return rc;
058656
 }
058656
 
058656
-PRUint64
058656
+uint64_t
058656
 replica_get_backoff_min(Replica *r)
058656
 {
058656
     if (r) {
058656
@@ -4004,7 +4048,7 @@ replica_get_backoff_min(Replica *r)
058656
     }
058656
 }
058656
 
058656
-PRUint64
058656
+uint64_t
058656
 replica_get_backoff_max(Replica *r)
058656
 {
058656
     if (r) {
058656
@@ -4015,7 +4059,7 @@ replica_get_backoff_max(Replica *r)
058656
 }
058656
 
058656
 void
058656
-replica_set_backoff_min(Replica *r, PRUint64 min)
058656
+replica_set_backoff_min(Replica *r, uint64_t min)
058656
 {
058656
     if (r) {
058656
         slapi_counter_set_value(r->backoff_min, min);
058656
@@ -4023,7 +4067,7 @@ replica_set_backoff_min(Replica *r, PRUint64 min)
058656
 }
058656
 
058656
 void
058656
-replica_set_backoff_max(Replica *r, PRUint64 max)
058656
+replica_set_backoff_max(Replica *r, uint64_t max)
058656
 {
058656
     if (r) {
058656
         slapi_counter_set_value(r->backoff_max, max);
058656
@@ -4031,14 +4075,14 @@ replica_set_backoff_max(Replica *r, PRUint64 max)
058656
 }
058656
 
058656
 void
058656
-replica_set_precise_purging(Replica *r, PRUint64 on_off)
058656
+replica_set_precise_purging(Replica *r, uint64_t on_off)
058656
 {
058656
     if (r) {
058656
         slapi_counter_set_value(r->precise_purging, on_off);
058656
     }
058656
 }
058656
 
058656
-PRUint64
058656
+uint64_t
058656
 replica_get_precise_purging(Replica *r)
058656
 {
058656
     if (r) {
058656
diff --git a/ldap/servers/plugins/replication/repl5_replica_config.c b/ldap/servers/plugins/replication/repl5_replica_config.c
058656
index 7477a292c..9c3c75458 100644
058656
--- a/ldap/servers/plugins/replication/repl5_replica_config.c
058656
+++ b/ldap/servers/plugins/replication/repl5_replica_config.c
058656
@@ -405,28 +405,35 @@ replica_config_modify(Slapi_PBlock *pb,
058656
                 } else if (strcasecmp(config_attr, attr_replicaBindDnGroup) == 0) {
058656
                     *returncode = replica_config_change_updatedngroup(r, mods[i], errortext, apply_mods);
058656
                 } else if (strcasecmp(config_attr, attr_replicaBindDnGroupCheckInterval) == 0) {
058656
-                    int interval = atoi(config_attr_value);
058656
-                    replica_set_groupdn_checkinterval(r, interval);
058656
+                    int64_t interval = 0;
058656
+                    if (repl_config_valid_num(config_attr, config_attr_value, -1, INT_MAX, returncode, errortext, &interval) == 0) {
058656
+                        replica_set_groupdn_checkinterval(r, interval);
058656
+                    } else {
058656
+                        break;
058656
+                    }
058656
                 } else if (strcasecmp(config_attr, attr_replicaType) == 0) {
058656
+                    int64_t rtype;
058656
                     slapi_ch_free_string(&new_repl_type);
058656
-                    new_repl_type = slapi_ch_strdup(config_attr_value);
058656
+                    if (repl_config_valid_num(config_attr, config_attr_value, 1, 3, returncode, errortext, &rtype) == 0) {
058656
+                        new_repl_type = slapi_ch_strdup(config_attr_value);
058656
+                    } else {
058656
+                        break;
058656
+                    }
058656
                 } else if (strcasecmp(config_attr, attr_replicaId) == 0) {
058656
-                    char *endp = NULL;
058656
                     int64_t rid = 0;
058656
-                    errno = 0;
058656
-                    rid = strtoll(config_attr_value, &endp, 10);
058656
-                    if (*endp != '\0' || rid > 65535 || rid < 1 || errno == ERANGE) {
058656
-                        *returncode = LDAP_UNWILLING_TO_PERFORM;
058656
-                        PR_snprintf(errortext, SLAPI_DSE_RETURNTEXT_SIZE,
058656
-                            "Attribute %s value (%s) is invalid, must be a number between 1 and 65535.\n",
058656
-                            config_attr, config_attr_value);
058656
-                        slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "replica_config_modify - %s\n", errortext);
058656
+                    if (repl_config_valid_num(config_attr, config_attr_value, 1, 65535, returncode, errortext, &rid) == 0) {
058656
+                        slapi_ch_free_string(&new_repl_id);
058656
+                        new_repl_id = slapi_ch_strdup(config_attr_value);
058656
+                    } else {
058656
                         break;
058656
                     }
058656
-                    slapi_ch_free_string(&new_repl_id);
058656
-                    new_repl_id = slapi_ch_strdup(config_attr_value);
058656
                 } else if (strcasecmp(config_attr, attr_flags) == 0) {
058656
-                    *returncode = replica_config_change_flags(r, config_attr_value, errortext, apply_mods);
058656
+                    int64_t rflags = 0;
058656
+                    if (repl_config_valid_num(config_attr, config_attr_value, 0, 1, returncode, errortext, &rflags) == 0) {
058656
+                        *returncode = replica_config_change_flags(r, config_attr_value, errortext, apply_mods);
058656
+                    } else {
058656
+                        break;
058656
+                    }
058656
                 } else if (strcasecmp(config_attr, TASK_ATTR) == 0) {
058656
                     *returncode = replica_execute_task(mtnode_ext->replica, config_attr_value, errortext, apply_mods);
058656
                 } else if (strcasecmp(config_attr, attr_replicaReferral) == 0) {
058656
@@ -442,18 +449,21 @@ replica_config_modify(Slapi_PBlock *pb,
058656
                     }
058656
                 } else if (strcasecmp(config_attr, type_replicaPurgeDelay) == 0) {
058656
                     if (apply_mods && config_attr_value[0]) {
058656
-                        PRUint32 delay;
058656
-                        if (isdigit(config_attr_value[0])) {
058656
-                            delay = (unsigned int)atoi(config_attr_value);
058656
+                        int64_t delay = 0;
058656
+                        if (repl_config_valid_num(config_attr, config_attr_value, -1, INT_MAX, returncode, errortext, &delay) == 0) {
058656
                             replica_set_purge_delay(r, delay);
058656
-                        } else
058656
-                            *returncode = LDAP_OPERATIONS_ERROR;
058656
+                        } else {
058656
+                            break;
058656
+                        }
058656
                     }
058656
                 } else if (strcasecmp(config_attr, type_replicaTombstonePurgeInterval) == 0) {
058656
                     if (apply_mods && config_attr_value[0]) {
058656
-                        long interval;
058656
-                        interval = atol(config_attr_value);
058656
-                        replica_set_tombstone_reap_interval(r, interval);
058656
+                        int64_t interval;
058656
+                        if (repl_config_valid_num(config_attr, config_attr_value, -1, INT_MAX, returncode, errortext, &interval) == 0) {
058656
+                            replica_set_tombstone_reap_interval(r, interval);
058656
+                        } else {
058656
+                            break;
058656
+                        }
058656
                     }
058656
                 }
058656
                 /* ignore modifiers attributes added by the server */
058656
@@ -461,73 +471,55 @@ replica_config_modify(Slapi_PBlock *pb,
058656
                     *returncode = LDAP_SUCCESS;
058656
                 } else if (strcasecmp(config_attr, type_replicaProtocolTimeout) == 0) {
058656
                     if (apply_mods) {
058656
-                        PRUint64 ptimeout = 0;
058656
-
058656
-                        ptimeout = atoll(config_attr_value);
058656
-
058656
-                        if (ptimeout <= 0) {
058656
-                            *returncode = LDAP_UNWILLING_TO_PERFORM;
058656
-                            PR_snprintf(errortext, SLAPI_DSE_RETURNTEXT_SIZE,
058656
-                                        "Attribute %s value (%s) is invalid, must be a number greater than zero.\n",
058656
-                                        config_attr, config_attr_value);
058656
-                            slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "replica_config_modify - %s\n", errortext);
058656
+                        int64_t ptimeout = 0;
058656
+                        if (repl_config_valid_num(config_attr, config_attr_value, 1, INT_MAX, returncode, errortext, &ptimeout) == 0) {
058656
+                            replica_set_protocol_timeout(r, ptimeout);
058656
+                        } else {
058656
                             break;
058656
                         }
058656
-                        replica_set_protocol_timeout(r, ptimeout);
058656
                     }
058656
                 } else if (strcasecmp(config_attr, type_replicaBackoffMin) == 0) {
058656
                     if (apply_mods) {
058656
-                        uint64_t val = atoll(config_attr_value);
058656
-                        uint64_t max;
058656
-
058656
-                        if (val <= 0) {
058656
-                            *returncode = LDAP_UNWILLING_TO_PERFORM;
058656
-                            PR_snprintf(errortext, SLAPI_DSE_RETURNTEXT_SIZE,
058656
-                                        "Attribute %s value (%s) is invalid, must be a number greater than zero.\n",
058656
-                                        config_attr, config_attr_value);
058656
-                            slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "replica_config_modify - %s\n", errortext);
058656
-                            break;
058656
-                        }
058656
-                        max = replica_get_backoff_max(r);
058656
-                        if (val > max){
058656
-                            *returncode = LDAP_UNWILLING_TO_PERFORM;
058656
-                            PR_snprintf(errortext, SLAPI_DSE_RETURNTEXT_SIZE,
058656
-                                        "Attribute %s value (%s) is invalid, must be a number less than the max backoff time (%d).\n",
058656
-                                        config_attr, config_attr_value, (int)max);
058656
-                            slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "replica_config_modify - %s\n", errortext);
058656
+                        int64_t val = 0;
058656
+                        int64_t max;
058656
+                        if (repl_config_valid_num(config_attr, config_attr_value, 1, INT_MAX, returncode, errortext, &val) == 0) {
058656
+                            max = replica_get_backoff_max(r);
058656
+                            if (val > max){
058656
+                                *returncode = LDAP_UNWILLING_TO_PERFORM;
058656
+                                PR_snprintf(errortext, SLAPI_DSE_RETURNTEXT_SIZE,
058656
+                                            "Attribute %s value (%s) is invalid, must be a number less than the max backoff time (%d).\n",
058656
+                                            config_attr, config_attr_value, (int)max);
058656
+                                slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "replica_config_modify - %s\n", errortext);
058656
+                                break;
058656
+                            }
058656
+                            replica_set_backoff_min(r, val);
058656
+                        } else {
058656
                             break;
058656
                         }
058656
-                        replica_set_backoff_min(r, val);
058656
                     }
058656
                 } else if (strcasecmp(config_attr, type_replicaBackoffMax) == 0) {
058656
                     if (apply_mods) {
058656
-                        uint64_t val = atoll(config_attr_value);
058656
-                        uint64_t min;
058656
-
058656
-                        if (val <= 0) {
058656
-                            *returncode = LDAP_UNWILLING_TO_PERFORM;
058656
-                            PR_snprintf(errortext, SLAPI_DSE_RETURNTEXT_SIZE,
058656
-                                        "Attribute %s value (%s) is invalid, must be a number greater than zero.\n",
058656
-                                        config_attr, config_attr_value);
058656
-                            slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "replica_config_modify - %s\n",
058656
-                                          errortext);
058656
-                            break;
058656
-                        }
058656
-                        min = replica_get_backoff_min(r);
058656
-                        if (val < min) {
058656
-                            *returncode = LDAP_UNWILLING_TO_PERFORM;
058656
-                            PR_snprintf(errortext, SLAPI_DSE_RETURNTEXT_SIZE,
058656
-                                        "Attribute %s value (%s) is invalid, must be a number more than the min backoff time (%d).\n",
058656
-                                        config_attr, config_attr_value, (int)min);
058656
-                            slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "replica_config_modify - %s\n", errortext);
058656
+                        int64_t val = 0;
058656
+                        int64_t min;
058656
+                        if (repl_config_valid_num(config_attr, config_attr_value, 1, INT_MAX, returncode, errortext, &val) == 0) {
058656
+                            min = replica_get_backoff_min(r);
058656
+                            if (val < min) {
058656
+                                *returncode = LDAP_UNWILLING_TO_PERFORM;
058656
+                                PR_snprintf(errortext, SLAPI_DSE_RETURNTEXT_SIZE,
058656
+                                            "Attribute %s value (%s) is invalid, must be a number more than the min backoff time (%d).\n",
058656
+                                            config_attr, config_attr_value, (int)min);
058656
+                                slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "replica_config_modify - %s\n", errortext);
058656
+                                break;
058656
+                            }
058656
+                            replica_set_backoff_max(r, val);
058656
+                        } else {
058656
                             break;
058656
                         }
058656
-                        replica_set_backoff_max(r, val);
058656
                     }
058656
                 } else if (strcasecmp(config_attr, type_replicaPrecisePurge) == 0) {
058656
                     if (apply_mods) {
058656
                         if (config_attr_value[0]) {
058656
-                            PRUint64 on_off = 0;
058656
+                            uint64_t on_off = 0;
058656
 
058656
                             if (strcasecmp(config_attr_value, "on") == 0) {
058656
                                 on_off = 1;
058656
@@ -550,19 +542,11 @@ replica_config_modify(Slapi_PBlock *pb,
058656
                     }
058656
                 } else if (strcasecmp(config_attr, type_replicaReleaseTimeout) == 0) {
058656
                     if (apply_mods) {
058656
-                        long val = atol(config_attr_value);
058656
-
058656
-                        if (val < 0) {
058656
-                            *returncode = LDAP_UNWILLING_TO_PERFORM;
058656
-                            PR_snprintf(errortext, SLAPI_DSE_RETURNTEXT_SIZE,
058656
-                                        "Attribute %s value (%s) is invalid, must be a number zero or greater.\n",
058656
-                                        config_attr, config_attr_value);
058656
-                            slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
058656
-                                          "replica_config_modify - %s\n", errortext);
058656
-                            break;
058656
-                        } else {
058656
-                            /* Set the timeout */
058656
+                        int64_t val;
058656
+                        if (repl_config_valid_num(config_attr, config_attr_value, 1, INT_MAX, returncode, errortext, &val) == 0) {
058656
                             replica_set_release_timeout(r, val);
058656
+                        } else {
058656
+                            break;
058656
                         }
058656
                     }
058656
                 } else {
058656
@@ -1011,7 +995,7 @@ replica_config_change_flags(Replica *r, const char *new_flags, char *returntext
058656
     PR_ASSERT(r);
058656
 
058656
     if (apply_mods) {
058656
-        PRUint32 flags;
058656
+        uint32_t flags;
058656
 
058656
         flags = atol(new_flags);
058656
 
058656
diff --git a/ldap/servers/plugins/replication/replutil.c b/ldap/servers/plugins/replication/replutil.c
058656
index 1b0446788..7cc132362 100644
058656
--- a/ldap/servers/plugins/replication/replutil.c
058656
+++ b/ldap/servers/plugins/replication/replutil.c
058656
@@ -1061,3 +1061,29 @@ repl_set_repl_plugin_path(const char *path)
058656
 {
058656
     replpluginpath = slapi_ch_strdup(path);
058656
 }
058656
+
058656
+int
058656
+repl_config_valid_num(const char *config_attr, char *config_attr_value, int64_t min, int64_t max,
058656
+                      int *returncode, char *errortext, int64_t *retval)
058656
+{
058656
+    int rc = 0;
058656
+    char *endp = NULL;
058656
+    int64_t val;
058656
+    errno = 0;
058656
+
058656
+    val = strtol(config_attr_value, &endp, 10);
058656
+    if (*endp != '\0' || val < min || val > max || errno == ERANGE) {
058656
+        *returncode = LDAP_UNWILLING_TO_PERFORM;
058656
+        if (errortext){
058656
+            PR_snprintf(errortext, SLAPI_DSE_RETURNTEXT_SIZE,
058656
+                        "Attribute %s value (%s) is invalid, must be a number between %ld and %ld.",
058656
+                        config_attr, config_attr_value, min, max);
058656
+            slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "repl_config_valid_num - %s\n",
058656
+                          errortext);
058656
+        }
058656
+        rc = -1;
058656
+    } else {
058656
+        *retval = val;
058656
+    }
058656
+    return rc;
058656
+}
058656
-- 
058656
2.13.6
058656