static int replmd_make_prefix_child_dn(TALLOC_CTX *tmp_ctx,
				       struct ldb_context *ldb,
				       struct ldb_dn *dn,
				       const char *four_char_prefix,
				       const char *rdn_name,
				       const struct ldb_val *rdn_value,
				       struct GUID guid)
{
	struct ldb_val deleted_child_rdn_val;
	struct GUID_txt_buf guid_str;
	int ret;
	bool retb;

	GUID_buf_string(&guid, &guid_str);

	retb = ldb_dn_add_child_fmt(dn, "X=Y");
	if (!retb) {
		ldb_asprintf_errstring(ldb, __location__
				       ": Unable to add a formatted child to dn: %s",
				       ldb_dn_get_linearized(dn));
		return LDB_ERR_OPERATIONS_ERROR;
	}

	/*
	 * TODO: Per MS-ADTS 3.1.1.5.5 Delete Operation
	 * we should truncate this value to ensure the RDN is not more than 255 chars.
	 *
	 * However we MS-ADTS 3.1.1.5.1.2 Naming Constraints indicates that:
	 *
	 * "Naming constraints are not enforced for replicated
	 * updates." so this is safe and we don't have to work out not
	 * splitting a UTF8 char right now.
	 */
	deleted_child_rdn_val = ldb_val_dup(tmp_ctx, rdn_value);

	/*
	 * sizeof(guid_str.buf) will always be longer than
	 * strlen(guid_str.buf) but we allocate using this and
	 * waste the trailing bytes to avoid scaring folks
	 * with memcpy() using strlen() below
	 */

	deleted_child_rdn_val.data
		= talloc_realloc(tmp_ctx, deleted_child_rdn_val.data,
				 uint8_t,
				 rdn_value->length + 5
				 + sizeof(guid_str.buf));
	if (!deleted_child_rdn_val.data) {
		ldb_asprintf_errstring(ldb, __location__
				       ": Unable to add a formatted child to dn: %s",
				       ldb_dn_get_linearized(dn));
		return LDB_ERR_OPERATIONS_ERROR;
	}

	deleted_child_rdn_val.length =
		rdn_value->length + 5
		+ strlen(guid_str.buf);

	SMB_ASSERT(deleted_child_rdn_val.length <
		   talloc_get_size(deleted_child_rdn_val.data));

	/*
	 * talloc won't allocate more than 256MB so we can't
	 * overflow but just to be sure
	 */
	if (deleted_child_rdn_val.length < rdn_value->length) {
		return LDB_ERR_OPERATIONS_ERROR;
	}

	deleted_child_rdn_val.data[rdn_value->length] = 0x0a;
	memcpy(&deleted_child_rdn_val.data[rdn_value->length + 1],
	       four_char_prefix, 4);
	memcpy(&deleted_child_rdn_val.data[rdn_value->length + 5],
	       guid_str.buf,
	       sizeof(guid_str.buf));

	/* Now set the value into the RDN, without parsing it */
	ret = ldb_dn_set_component(
		dn,
		0,
		rdn_name,
		deleted_child_rdn_val);

	return ret;
}
static int replmd_make_prefix_child_dn(TALLOC_CTX *tmp_ctx,
				       struct ldb_context *ldb,
				       struct ldb_dn *dn,
				       const char *four_char_prefix,
				       const char *rdn_name,
				       const struct ldb_val *rdn_value,
				       struct GUID guid)
{
	struct ldb_val deleted_child_rdn_val;
	struct GUID_txt_buf guid_str;
	int ret;
	bool retb;

	GUID_buf_string(&guid, &guid_str);

	retb = ldb_dn_add_child_fmt(dn, "X=Y");
	if (!retb) {
		ldb_asprintf_errstring(ldb, __location__
				       ": Unable to add a formatted child to dn: %s",
				       ldb_dn_get_linearized(dn));
		return LDB_ERR_OPERATIONS_ERROR;
	}

	 
	deleted_child_rdn_val = ldb_val_dup(tmp_ctx, rdn_value);

	 

	deleted_child_rdn_val.data
		= talloc_realloc(tmp_ctx, deleted_child_rdn_val.data,
				 uint8_t,
				 rdn_value->length + 5
				 + sizeof(guid_str.buf));
	if (!deleted_child_rdn_val.data) {
		ldb_asprintf_errstring(ldb, __location__
				       ": Unable to add a formatted child to dn: %s",
				       ldb_dn_get_linearized(dn));
		return LDB_ERR_OPERATIONS_ERROR;
	}

	deleted_child_rdn_val.length =
		rdn_value->length + 5
		+ strlen(guid_str.buf);

	SMB_ASSERT(deleted_child_rdn_val.length <
		   talloc_get_size(deleted_child_rdn_val.data));

	 
	if (deleted_child_rdn_val.length < rdn_value->length) {
		return LDB_ERR_OPERATIONS_ERROR;
	}

	deleted_child_rdn_val.data[rdn_value->length] = 0x0a;
	memcpy(&deleted_child_rdn_val.data[rdn_value->length + 1],
	       four_char_prefix, 4);
	memcpy(&deleted_child_rdn_val.data[rdn_value->length + 5],
	       guid_str.buf,
	       sizeof(guid_str.buf));

	 
	ret = ldb_dn_set_component(
		dn,
		0,
		rdn_name,
		deleted_child_rdn_val);

	return ret;
}