1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-26 21:57:41 +03:00

dsdb: Fix incorrect sorting of replPropertyMetaData with RDN last

Per tests against Windows 2012R2 the RDN is not sorted last and is
instead sorted normally with all the other elements.

The RDN attribute, unlike name, is not replicated over DRS, so this
has no interopability impact.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz
This commit is contained in:
Andrew Bartlett 2016-05-13 23:12:47 +12:00
parent 225cef9851
commit a8430d15a5
6 changed files with 40 additions and 101 deletions

View File

@ -1161,7 +1161,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
# Sort the array, except for the last element. This strange
# construction, creating a new list, due to bugs in samba's
# array handling in IDL generated objects.
ctr.array = sorted(ctr.array[:-1], key=lambda o: o.attid) + [ctr.array[-1]]
ctr.array = sorted(ctr.array[:], key=lambda o: o.attid)
# Now walk it in reverse, so we see the low (and so incorrect,
# the correct values are above 0x80000000) values first and
# remove the 'second' value we see.
@ -1215,9 +1215,8 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
fix = True
o.attid = correct_attid
if fix:
# Sort the array, except for the last element (we changed
# the value so must re-sort)
new_list[:-1] = sorted(new_list[:-1], key=lambda o: o.attid)
# Sort the array, (we changed the value so must re-sort)
new_list[:] = sorted(new_list[:], key=lambda o: o.attid)
# If we did not already need to fix it, then ask about sorting
if not fix:
@ -1461,7 +1460,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
if len(set_attrs_from_md) < len(list_attid_from_md) \
or len(wrong_attids) > 0 \
or sorted(list_attid_from_md[:-1]) != list_attid_from_md[:-1]:
or sorted(list_attid_from_md) != list_attid_from_md:
error_count +=1
self.err_replmetadata_incorrect_attid(dn, attrname, obj[attrname], wrong_attids)
@ -1469,12 +1468,6 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
# Here we check that the first attid is 0
# (objectClass) and that the last on is the RDN
# from the DN.
rdn_attid = self.samdb_schema.get_attid_from_lDAPDisplayName(dn.get_rdn_name())
if list_attid_from_md[-1] != rdn_attid:
error_count += 1
self.report("ERROR: Not fixing incorrect final attributeID in '%s' on '%s', it should match the RDN %s" %
(attrname, str(dn), dn.get_rdn_name()))
if list_attid_from_md[0] != 0:
error_count += 1
self.report("ERROR: Not fixing incorrect inital attributeID in '%s' on '%s', it should be objectClass" %

View File

@ -689,24 +689,6 @@ static int replmd_replPropertyMetaData1_attid_sort(const struct replPropertyMeta
return 0;
}
/*
* the rdn attribute should be at the end!
* so we need to return a value greater than zero
* which means m1 is greater than m2
*/
if (attid_1 == *rdn_attid) {
return 1;
}
/*
* the rdn attribute should be at the end!
* so we need to return a value less than zero
* which means m2 is greater than m1
*/
if (attid_2 == *rdn_attid) {
return -1;
}
/*
* See above regarding this being an unsigned comparison.
* Otherwise when the high bit is set on non-standard
@ -718,7 +700,6 @@ static int replmd_replPropertyMetaData1_attid_sort(const struct replPropertyMeta
static int replmd_replPropertyMetaDataCtr1_verify(struct ldb_context *ldb,
struct replPropertyMetaDataCtr1 *ctr1,
const struct dsdb_attribute *rdn_sa,
struct ldb_dn *dn)
{
if (ctr1->count == 0) {
@ -741,34 +722,12 @@ static int replmd_replPropertyMetaDataCtr1_verify(struct ldb_context *ldb,
static int replmd_replPropertyMetaDataCtr1_sort_and_verify(struct ldb_context *ldb,
struct replPropertyMetaDataCtr1 *ctr1,
const struct dsdb_schema *schema,
struct ldb_dn *dn)
{
const char *rdn_name;
const struct dsdb_attribute *rdn_sa;
rdn_name = ldb_dn_get_rdn_name(dn);
if (!rdn_name) {
ldb_debug_set(ldb, LDB_DEBUG_FATAL,
__location__ ": No rDN for %s?\n",
ldb_dn_get_linearized(dn));
return LDB_ERR_INVALID_DN_SYNTAX;
}
rdn_sa = dsdb_attribute_by_lDAPDisplayName(schema, rdn_name);
if (rdn_sa == NULL) {
ldb_debug_set(ldb, LDB_DEBUG_FATAL,
__location__ ": No sa found for rDN %s for %s\n",
rdn_name, ldb_dn_get_linearized(dn));
return LDB_ERR_UNDEFINED_ATTRIBUTE_TYPE;
}
DEBUG(6,("Sorting rpmd with attid exception %u rDN=%s DN=%s\n",
rdn_sa->attributeID_id, rdn_name, ldb_dn_get_linearized(dn)));
LDB_TYPESAFE_QSORT(ctr1->array, ctr1->count, &rdn_sa->attributeID_id,
/* Note this is O(n^2) for the almost-sorted case, which this is */
LDB_TYPESAFE_QSORT(ctr1->array, ctr1->count, NULL,
replmd_replPropertyMetaData1_attid_sort);
return replmd_replPropertyMetaDataCtr1_verify(ldb, ctr1, rdn_sa, dn);
return replmd_replPropertyMetaDataCtr1_verify(ldb, ctr1, dn);
}
static int replmd_ldb_message_element_attid_sort(const struct ldb_message_element *e1,
@ -1085,7 +1044,7 @@ static int replmd_add(struct ldb_module *module, struct ldb_request *req)
/*
* sort meta data array, and move the rdn attribute entry to the end
*/
ret = replmd_replPropertyMetaDataCtr1_sort_and_verify(ldb, &nmd.ctr.ctr1, ac->schema, msg->dn);
ret = replmd_replPropertyMetaDataCtr1_sort_and_verify(ldb, &nmd.ctr.ctr1, msg->dn);
if (ret != LDB_SUCCESS) {
ldb_asprintf_errstring(ldb, "%s: error during direct ADD: %s", __func__, ldb_errstring(ldb));
talloc_free(ac);
@ -1618,7 +1577,7 @@ static int replmd_update_rpmd(struct ldb_module *module,
return LDB_ERR_OPERATIONS_ERROR;
}
ret = replmd_replPropertyMetaDataCtr1_sort_and_verify(ldb, &omd.ctr.ctr1, schema, msg->dn);
ret = replmd_replPropertyMetaDataCtr1_sort_and_verify(ldb, &omd.ctr.ctr1, msg->dn);
if (ret != LDB_SUCCESS) {
ldb_asprintf_errstring(ldb, "%s: %s", __func__, ldb_errstring(ldb));
return ret;
@ -4072,8 +4031,6 @@ static int replmd_replicated_apply_add(struct replmd_replicated_request *ar)
unsigned int i;
int ret;
bool remote_isDeleted = false;
const struct dsdb_attribute *rdn_sa;
const char *rdn_name;
ldb = ldb_module_get_ctx(ar->module);
msg = ar->objs->objects[ar->index_current].msg;
@ -4141,23 +4098,12 @@ static int replmd_replicated_apply_add(struct replmd_replicated_request *ar)
"isDeleted", false);
/*
* the meta data array is already sorted by the caller
* the meta data array is already sorted by the caller, except
* for the RDN, which needs to be put in the right spot.
*/
rdn_name = ldb_dn_get_rdn_name(msg->dn);
if (rdn_name == NULL) {
ldb_asprintf_errstring(ldb, __location__ ": No rDN for %s?\n", ldb_dn_get_linearized(msg->dn));
return replmd_replicated_request_error(ar, LDB_ERR_INVALID_DN_SYNTAX);
}
rdn_sa = dsdb_attribute_by_lDAPDisplayName(ar->schema, rdn_name);
if (rdn_sa == NULL) {
ldb_asprintf_errstring(ldb, ": No schema attribute found for rDN %s for %s\n",
rdn_name, ldb_dn_get_linearized(msg->dn));
return replmd_replicated_request_error(ar, LDB_ERR_UNDEFINED_ATTRIBUTE_TYPE);
}
ret = replmd_replPropertyMetaDataCtr1_verify(ldb, &md->ctr.ctr1, rdn_sa, msg->dn);
ret = replmd_replPropertyMetaDataCtr1_sort_and_verify(ldb, &md->ctr.ctr1, msg->dn);
if (ret != LDB_SUCCESS) {
ldb_asprintf_errstring(ldb, "%s: error during DRS repl ADD: %s", __func__, ldb_errstring(ldb));
return replmd_replicated_request_error(ar, ret);
@ -4867,9 +4813,9 @@ static int replmd_replicated_apply_merge(struct replmd_replicated_request *ar)
* 'cn' for most objects is the last entry in the meta data array
* we have stored
*
* sort the new meta data array
* sort the new meta data array so it is slotted into the right place
*/
ret = replmd_replPropertyMetaDataCtr1_sort_and_verify(ldb, &nmd.ctr.ctr1, ar->schema, msg->dn);
ret = replmd_replPropertyMetaDataCtr1_sort_and_verify(ldb, &nmd.ctr.ctr1, msg->dn);
if (ret != LDB_SUCCESS) {
ldb_asprintf_errstring(ldb, "%s: error during DRS repl merge: %s", __func__, ldb_errstring(ldb));
return ret;

View File

@ -23,6 +23,13 @@ replPropertyMetaData: NDR: struct replPropertyMetaDataBlob
originating_invocation_id: 7b2e1a86-f4d6-4e7f-a49f-d40f3596aa63
originating_usn : 0x0000000000000eb1 (3761)
local_usn : 0x0000000000000dba (3514)
array: struct replPropertyMetaData1
attid : DRSUAPI_ATTID_cn (0x3)
version : 0x00000001 (1)
originating_change_time : Sun Aug 2 22:51:30 2015 UTC
originating_invocation_id: 7b2e1a86-f4d6-4e7f-a49f-d40f3596aa63
originating_usn : 0x0000000000000eb1 (3761)
local_usn : 0x0000000000000dba (3514)
array: struct replPropertyMetaData1
attid : DRSUAPI_ATTID_instanceType (0x20001)
version : 0x00000001 (1)
@ -93,13 +100,6 @@ replPropertyMetaData: NDR: struct replPropertyMetaDataBlob
originating_invocation_id: 7b2e1a86-f4d6-4e7f-a49f-d40f3596aa63
originating_usn : 0x0000000000000eb1 (3761)
local_usn : 0x0000000000000dba (3514)
array: struct replPropertyMetaData1
attid : DRSUAPI_ATTID_cn (0x3)
version : 0x00000001 (1)
originating_change_time : Sun Aug 2 22:51:30 2015 UTC
originating_invocation_id: 7b2e1a86-f4d6-4e7f-a49f-d40f3596aa63
originating_usn : 0x0000000000000eb1 (3761)
local_usn : 0x0000000000000dba (3514)
sudoCommand: ALL
sudoHost: ALL

View File

@ -22,6 +22,12 @@ replPropertyMetaData: NDR: struct replPropertyMetaDataBlob
originating_invocation_id: b249ef44-b215-4d3b-b5d6-7cec08154b7a
originating_usn : 0x0000000000000dbc (3516)
local_usn : 0x0000000000000dbc (3516)
array: struct replPropertyMetaData1
attid : DRSUAPI_ATTID_cn (0x3)
version : 0x00000001 (1)
originating_invocation_id: b249ef44-b215-4d3b-b5d6-7cec08154b7a
originating_usn : 0x0000000000000dbc (3516)
local_usn : 0x0000000000000dbc (3516)
array: struct replPropertyMetaData1
attid : DRSUAPI_ATTID_instanceType (0x20001)
version : 0x00000001 (1)
@ -82,12 +88,6 @@ replPropertyMetaData: NDR: struct replPropertyMetaDataBlob
originating_invocation_id: b249ef44-b215-4d3b-b5d6-7cec08154b7a
originating_usn : 0x0000000000000dbc (3516)
local_usn : 0x0000000000000dbc (3516)
array: struct replPropertyMetaData1
attid : DRSUAPI_ATTID_cn (0x3)
version : 0x00000001 (1)
originating_invocation_id: b249ef44-b215-4d3b-b5d6-7cec08154b7a
originating_usn : 0x0000000000000dbc (3516)
local_usn : 0x0000000000000dbc (3516)
sudoCommand: ALL
sudoHost: ALL

View File

@ -23,6 +23,13 @@ replPropertyMetaData: NDR: struct replPropertyMetaDataBlob
originating_invocation_id: b249ef44-b215-4d3b-b5d6-7cec08154b7a
originating_usn : 0x0000000000000dbd (3517)
local_usn : 0x0000000000000dbd (3517)
array: struct replPropertyMetaData1
attid : DRSUAPI_ATTID_cn (0x3)
version : 0x00000001 (1)
originating_change_time : Wed Dec 23 00:16:03 2015 UTC
originating_invocation_id: b249ef44-b215-4d3b-b5d6-7cec08154b7a
originating_usn : 0x0000000000000dbd (3517)
local_usn : 0x0000000000000dbd (3517)
array: struct replPropertyMetaData1
attid : DRSUAPI_ATTID_instanceType (0x20001)
version : 0x00000001 (1)
@ -93,13 +100,6 @@ replPropertyMetaData: NDR: struct replPropertyMetaDataBlob
originating_invocation_id: b249ef44-b215-4d3b-b5d6-7cec08154b7a
originating_usn : 0x0000000000000dbd (3517)
local_usn : 0x0000000000000dbd (3517)
array: struct replPropertyMetaData1
attid : DRSUAPI_ATTID_cn (0x3)
version : 0x00000001 (1)
originating_change_time : Wed Dec 23 00:16:03 2015 UTC
originating_invocation_id: b249ef44-b215-4d3b-b5d6-7cec08154b7a
originating_usn : 0x0000000000000dbd (3517)
local_usn : 0x0000000000000dbd (3517)
sudoCommand: ALL
sudoHost: ALL

View File

@ -22,6 +22,12 @@ replPropertyMetaData: NDR: struct replPropertyMetaDataBlob
originating_invocation_id: b249ef44-b215-4d3b-b5d6-7cec08154b7a
originating_usn : 0x0000000000000dbc (3516)
local_usn : 0x0000000000000dbc (3516)
array: struct replPropertyMetaData1
attid : DRSUAPI_ATTID_cn (0x3)
version : 0x00000001 (1)
originating_invocation_id: b249ef44-b215-4d3b-b5d6-7cec08154b7a
originating_usn : 0x0000000000000dbc (3516)
local_usn : 0x0000000000000dbc (3516)
array: struct replPropertyMetaData1
attid : DRSUAPI_ATTID_instanceType (0x20001)
version : 0x00000001 (1)
@ -82,12 +88,6 @@ replPropertyMetaData: NDR: struct replPropertyMetaDataBlob
originating_invocation_id: b249ef44-b215-4d3b-b5d6-7cec08154b7a
originating_usn : 0x0000000000000dbe (3518)
local_usn : 0x0000000000000dbe (3518)
array: struct replPropertyMetaData1
attid : DRSUAPI_ATTID_cn (0x3)
version : 0x00000001 (1)
originating_invocation_id: b249ef44-b215-4d3b-b5d6-7cec08154b7a
originating_usn : 0x0000000000000dbc (3516)
local_usn : 0x0000000000000dbc (3516)
sudoCommand: ALL
sudoHost: ALL