static int replmd_get_la_entry_source(struct ldb_module *module,
				      struct la_entry *la_entry,
				      TALLOC_CTX *mem_ctx,
				      const struct dsdb_attribute **ret_attr,
				      struct ldb_message **source_msg)
{
	struct drsuapi_DsReplicaLinkedAttribute *la = la_entry->la;
	struct ldb_context *ldb = ldb_module_get_ctx(module);
	const struct dsdb_schema *schema = dsdb_get_schema(ldb, mem_ctx);
	int ret;
	const struct dsdb_attribute *attr;
	struct ldb_result *res;
	const char *attrs[4];

/*
linked_attributes[0]:
     &objs->linked_attributes[i]: struct drsuapi_DsReplicaLinkedAttribute
        identifier               : *
            identifier: struct drsuapi_DsReplicaObjectIdentifier
                __ndr_size               : 0x0000003a (58)
                __ndr_size_sid           : 0x00000000 (0)
                guid                     : 8e95b6a9-13dd-4158-89db-3220a5be5cc7
                sid                      : S-0-0
                __ndr_size_dn            : 0x00000000 (0)
                dn                       : ''
        attid                    : DRSUAPI_ATTID_member (0x1F)
        value: struct drsuapi_DsAttributeValue
            __ndr_size               : 0x0000007e (126)
            blob                     : *
                blob                     : DATA_BLOB length=126
        flags                    : 0x00000001 (1)
               1: DRSUAPI_DS_LINKED_ATTRIBUTE_FLAG_ACTIVE
        originating_add_time     : Wed Sep  2 22:20:01 2009 EST
        meta_data: struct drsuapi_DsReplicaMetaData
            version                  : 0x00000015 (21)
            originating_change_time  : Wed Sep  2 23:39:07 2009 EST
            originating_invocation_id: 794640f3-18cf-40ee-a211-a93992b67a64
            originating_usn          : 0x000000000001e19c (123292)

(for cases where the link is to a normal DN)
     &target: struct drsuapi_DsReplicaObjectIdentifier3
        __ndr_size               : 0x0000007e (126)
        __ndr_size_sid           : 0x0000001c (28)
        guid                     : 7639e594-db75-4086-b0d4-67890ae46031
        sid                      : S-1-5-21-2848215498-2472035911-1947525656-19924
        __ndr_size_dn            : 0x00000022 (34)
        dn                       : 'CN=UOne,OU=TestOU,DC=vsofs8,DC=com'
 */

	/* find the attribute being modified */
	attr = dsdb_attribute_by_attributeID_id(schema, la->attid);
	if (attr == NULL) {
		struct GUID_txt_buf guid_str;
		ldb_asprintf_errstring(ldb, "Unable to find attributeID 0x%x for link on <GUID=%s>",
				       la->attid,
				       GUID_buf_string(&la->identifier->guid,
						       &guid_str));
		return LDB_ERR_OPERATIONS_ERROR;
	}

	/*
	 * All attributes listed here must be dealt with in some way
	 * by replmd_process_linked_attribute() otherwise in the case
	 * of isDeleted: FALSE the modify will fail with:
	 *
	 * Failed to apply linked attribute change 'attribute 'isDeleted':
	 * invalid modify flags on
	 * 'CN=g1_1527570609273,CN=Users,DC=samba,DC=example,DC=com':
	 * 0x0'
	 *
	 * This is becaue isDeleted is a Boolean, so FALSE is a
	 * legitimate value (set by Samba's deletetest.py)
	 */
	attrs[0] = attr->lDAPDisplayName;
	attrs[1] = "isDeleted";
	attrs[2] = "isRecycled";
	attrs[3] = NULL;

	/*
	 * get the existing message from the db for the object with
	 * this GUID, returning attribute being modified. We will then
	 * use this msg as the basis for a modify call
	 */
	ret = dsdb_module_search(module, mem_ctx, &res, NULL, LDB_SCOPE_SUBTREE, attrs,
	                         DSDB_FLAG_NEXT_MODULE |
				 DSDB_SEARCH_SEARCH_ALL_PARTITIONS |
				 DSDB_SEARCH_SHOW_RECYCLED |
				 DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT |
				 DSDB_SEARCH_REVEAL_INTERNALS,
				 NULL,
				 "objectGUID=%s", GUID_string(mem_ctx, &la->identifier->guid));
	if (ret != LDB_SUCCESS) {
		return ret;
	}
	if (res->count != 1) {
		ldb_asprintf_errstring(ldb, "DRS linked attribute for GUID %s - DN not found",
				       GUID_string(mem_ctx, &la->identifier->guid));
		return LDB_ERR_NO_SUCH_OBJECT;
	}

	*source_msg = res->msgs[0];
	*ret_attr = attr;

	return LDB_SUCCESS;
}