static int replmd_check_upgrade_links(struct ldb_context *ldb,
				      struct parsed_dn *dns, uint32_t count,
				      struct ldb_message_element *el,
				      const char *ldap_oid)
{
	uint32_t i;
	const struct GUID *invocation_id = NULL;
	for (i=0; i<count; i++) {
		NTSTATUS status;
		uint32_t version;
		int ret;
		if (dns[i].dsdb_dn == NULL) {
			ret = really_parse_trusted_dn(dns, ldb, &dns[i],
						      ldap_oid);
			if (ret != LDB_SUCCESS) {
				return LDB_ERR_INVALID_DN_SYNTAX;
			}
		}

		status = dsdb_get_extended_dn_uint32(dns[i].dsdb_dn->dn,
						     &version, "RMD_VERSION");
		if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
			/*
			 *  We optimistically assume they are all the same; if
			 *  the first one is fixed, they are all fixed.
			 *
			 *  If the first one was *not* fixed and we find a
			 *  later one that is, that is an occasion to shout
			 *  with DEBUG(0).
			 */
			if (i == 0) {
				return LDB_SUCCESS;
			}
			DEBUG(0, ("Mixed w2k and fixed format "
				  "linked attributes\n"));
			continue;
		}

		if (invocation_id == NULL) {
			invocation_id = samdb_ntds_invocation_id(ldb);
			if (invocation_id == NULL) {
				return LDB_ERR_OPERATIONS_ERROR;
			}
		}


		/* it's an old one that needs upgrading */
		ret = replmd_update_la_val(el->values, dns[i].v,
					   dns[i].dsdb_dn, dns[i].dsdb_dn,
					   invocation_id, 1, 1, 0, false);
		if (ret != LDB_SUCCESS) {
			return ret;
		}
	}

	/*
	 * This sort() is critical for the operation of
	 * get_parsed_dns_trusted_fallback() because callers of this function
	 * expect a sorted list, and FL2000 style links are not
	 * sorted.  In particular, as well as the upgrade case,
	 * get_parsed_dns_trusted_fallback() is called from
	 * replmd_delete_remove_link() even in FL2000 mode
	 *
	 * We do not normally pay the cost of the qsort() due to the
	 * early return in the RMD_VERSION found case.
	 */
	TYPESAFE_QSORT(dns, count, parsed_dn_compare);
	return LDB_SUCCESS;
}
static int replmd_check_upgrade_links(struct ldb_context *ldb,
				      struct parsed_dn *dns, uint32_t count,
				      struct ldb_message_element *el,
				      const char *ldap_oid)
{
	uint32_t i;
	const struct GUID *invocation_id = NULL;
	for (i=0; i<count; i++) {
		NTSTATUS status;
		uint32_t version;
		int ret;
		if (dns[i].dsdb_dn == NULL) {
			ret = really_parse_trusted_dn(dns, ldb, &dns[i],
						      ldap_oid);
			if (ret != LDB_SUCCESS) {
				return LDB_ERR_INVALID_DN_SYNTAX;
			}
		}

		status = dsdb_get_extended_dn_uint32(dns[i].dsdb_dn->dn,
						     &version, "RMD_VERSION");
		if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
			 
			if (i == 0) {
				return LDB_SUCCESS;
			}
			DEBUG(0, ("Mixed w2k and fixed format "
				  "linked attributes\n"));
			continue;
		}

		if (invocation_id == NULL) {
			invocation_id = samdb_ntds_invocation_id(ldb);
			if (invocation_id == NULL) {
				return LDB_ERR_OPERATIONS_ERROR;
			}
		}


		 
		ret = replmd_update_la_val(el->values, dns[i].v,
					   dns[i].dsdb_dn, dns[i].dsdb_dn,
					   invocation_id, 1, 1, 0, false);
		if (ret != LDB_SUCCESS) {
			return ret;
		}
	}

	 
	TYPESAFE_QSORT(dns, count, parsed_dn_compare);
	return LDB_SUCCESS;
}