static int anr_search(struct ldb_module *module, struct ldb_request *req)
{
	struct ldb_context *ldb;
	struct ldb_parse_tree *anr_tree;
	struct ldb_request *down_req;
	struct anr_context *ac;
	struct anr_present_ctx ctx;
	const char *attr = "anr";
	int ret;

	ctx.found_anr = false;
	ctx.attr = attr;

	ldb_parse_tree_walk(req->op.search.tree,
			    parse_tree_anr_present,
			    &ctx);

	if (!ctx.found_anr) {
		return ldb_next_request(module, req);
	}

	ldb = ldb_module_get_ctx(module);

	ac = talloc(req, struct anr_context);
	if (!ac) {
		return ldb_oom(ldb);
	}

	ac->module = module;
	ac->req = req;

#if 0
	printf("oldanr : %s\n", ldb_filter_from_tree (0, req->op.search.tree));
#endif

	/* First make a copy, so we don't overwrite caller memory */

	anr_tree = ldb_parse_tree_copy_shallow(ac, req->op.search.tree);

	if (anr_tree == NULL) {
		return ldb_operr(ldb);
	}

	/* Now expand 'anr' out */
	ret = anr_replace_subtrees(ac, anr_tree, attr, &anr_tree);
	if (ret != LDB_SUCCESS) {
		return ldb_operr(ldb);
	}

	ret = ldb_build_search_req_ex(&down_req,
					ldb, ac,
					req->op.search.base,
					req->op.search.scope,
					anr_tree,
					req->op.search.attrs,
					req->controls,
					ac, anr_search_callback,
					req);
	LDB_REQ_SET_LOCATION(down_req);
	if (ret != LDB_SUCCESS) {
		return ldb_operr(ldb);
	}
	talloc_steal(down_req, anr_tree);

	return ldb_next_request(module, down_req);
}
static int anr_search(struct ldb_module *module, struct ldb_request *req)
{
	struct ldb_context *ldb;
	struct ldb_parse_tree *anr_tree;
	struct ldb_request *down_req;
	struct anr_context *ac;
	struct anr_present_ctx ctx;
	const char *attr = "anr";
	int ret;

	ctx.found_anr = false;
	ctx.attr = attr;

	ldb_parse_tree_walk(req->op.search.tree,
			    parse_tree_anr_present,
			    &ctx);

	if (!ctx.found_anr) {
		return ldb_next_request(module, req);
	}

	ldb = ldb_module_get_ctx(module);

	ac = talloc(req, struct anr_context);
	if (!ac) {
		return ldb_oom(ldb);
	}

	ac->module = module;
	ac->req = req;

#if 0
	printf("oldanr : %s\n", ldb_filter_from_tree (0, req->op.search.tree));
#endif

	 

	anr_tree = ldb_parse_tree_copy_shallow(ac, req->op.search.tree);

	if (anr_tree == NULL) {
		return ldb_operr(ldb);
	}

	 
	ret = anr_replace_subtrees(ac, anr_tree, attr, &anr_tree);
	if (ret != LDB_SUCCESS) {
		return ldb_operr(ldb);
	}

	ret = ldb_build_search_req_ex(&down_req,
					ldb, ac,
					req->op.search.base,
					req->op.search.scope,
					anr_tree,
					req->op.search.attrs,
					req->controls,
					ac, anr_search_callback,
					req);
	LDB_REQ_SET_LOCATION(down_req);
	if (ret != LDB_SUCCESS) {
		return ldb_operr(ldb);
	}
	talloc_steal(down_req, anr_tree);

	return ldb_next_request(module, down_req);
}