From ea4fa549e6daeba648ce11c8c2ce4e7688ffab7b Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Feb 25 2020 19:05:03 +0000 Subject: Issue 50909 - nsDS5ReplicaId cant be set to the old value it had before Bug Description: We were not handling the process of changing the replica type and id correctly. For one, we were not correctly handling a change to a hub/consumer, but it just happened to work by accident in most cases. In other caes you could not change the rid more than once. Fix Description: Changed the value checking to allow ID changes to 65535 which allowed the type/id pointers to be set correctly. Then the checking of the type & ID change combination had to be revised. Also, removed the option to get just set the RID or type from dsconf. Only replication promotion/demotion should be touching these values. relates: https://pagure.io/389-ds-base/issue/50909 Reviewed by: firstyear & tbordaz(Thanks!!) --- diff --git a/dirsrvtests/tests/suites/replication/replica_config_test.py b/dirsrvtests/tests/suites/replication/replica_config_test.py index 1855143..c2140a2 100644 --- a/dirsrvtests/tests/suites/replication/replica_config_test.py +++ b/dirsrvtests/tests/suites/replication/replica_config_test.py @@ -43,7 +43,7 @@ agmt_dict = {'cn': 'test_agreement', repl_add_attrs = [('nsDS5ReplicaType', '-1', '4', overflow, notnum, '1'), ('nsDS5Flags', '-1', '2', overflow, notnum, '1'), - ('nsDS5ReplicaId', '0', '65535', overflow, notnum, '1'), + ('nsDS5ReplicaId', '0', '65536', overflow, notnum, '1'), ('nsds5ReplicaPurgeDelay', '-2', too_big, overflow, notnum, '1'), ('nsDS5ReplicaBindDnGroupCheckInterval', '-2', too_big, overflow, notnum, '1'), ('nsds5ReplicaTombstonePurgeInterval', '-2', too_big, overflow, notnum, '1'), diff --git a/ldap/servers/plugins/replication/repl5_replica_config.c b/ldap/servers/plugins/replication/repl5_replica_config.c index 02b36f6..d64d4bf 100644 --- a/ldap/servers/plugins/replication/repl5_replica_config.c +++ b/ldap/servers/plugins/replication/repl5_replica_config.c @@ -461,7 +461,7 @@ replica_config_modify(Slapi_PBlock *pb, } } else if (strcasecmp(config_attr, attr_replicaId) == 0) { int64_t rid = 0; - if (repl_config_valid_num(config_attr, config_attr_value, 1, 65534, returncode, errortext, &rid) == 0) { + if (repl_config_valid_num(config_attr, config_attr_value, 1, MAX_REPLICA_ID, returncode, errortext, &rid) == 0) { slapi_ch_free_string(&new_repl_id); new_repl_id = slapi_ch_strdup(config_attr_value); } else { @@ -890,7 +890,7 @@ replica_config_search(Slapi_PBlock *pb, static int replica_config_change_type_and_id(Replica *r, const char *new_type, const char *new_id, char *returntext, int apply_mods) { - int type; + int type = REPLICA_TYPE_READONLY; /* by default - replica is read-only */ ReplicaType oldtype; ReplicaId rid; ReplicaId oldrid; @@ -899,21 +899,21 @@ replica_config_change_type_and_id(Replica *r, const char *new_type, const char * oldtype = replica_get_type(r); oldrid = replica_get_rid(r); - if (new_type == NULL) /* by default - replica is read-only */ - { - type = REPLICA_TYPE_READONLY; + if (new_type == NULL) { + if (oldtype) { + type = oldtype; + } } else { type = atoi(new_type); if (type <= REPLICA_TYPE_UNKNOWN || type >= REPLICA_TYPE_END) { PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "invalid replica type %d", type); return LDAP_OPERATIONS_ERROR; } - } - - /* disallow changing type to itself just to permit a replica ID change */ - if (oldtype == type) { - PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "replica type is already %d - not changing", type); - return LDAP_OPERATIONS_ERROR; + /* disallow changing type to itself just to permit a replica ID change */ + if (oldtype == type) { + PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "replica type is already %d - not changing", type); + return LDAP_OPERATIONS_ERROR; + } } if (type == REPLICA_TYPE_READONLY) { diff --git a/src/lib389/lib389/cli_conf/replication.py b/src/lib389/lib389/cli_conf/replication.py index 7acbb33..1c0c925 100644 --- a/src/lib389/lib389/cli_conf/replication.py +++ b/src/lib389/lib389/cli_conf/replication.py @@ -1189,9 +1189,6 @@ def create_parser(subparsers): repl_set_parser = repl_subcommands.add_parser('set', help='Set an attribute in the replication configuration') repl_set_parser.set_defaults(func=set_repl_config) repl_set_parser.add_argument('--suffix', required=True, help='The DN of the replication suffix') - repl_set_parser.add_argument('--replica-id', help="The Replication Identifier number") - repl_set_parser.add_argument('--replica-role', help="The Replication role: master, hub, or consumer") - repl_set_parser.add_argument('--repl-add-bind-dn', help="Add a bind (supplier) DN") repl_set_parser.add_argument('--repl-del-bind-dn', help="Remove a bind (supplier) DN") repl_set_parser.add_argument('--repl-add-ref', help="Add a replication referral (for consumers only)")