static int map_init_dns(struct ldb_module *module, struct ldb_map_context *data, const char *name)
{
	static const char * const attrs[] = { MAP_DN_FROM, MAP_DN_TO, NULL };
	struct ldb_context *ldb;
	struct ldb_dn *dn;
	struct ldb_message *msg;
	struct ldb_result *res;
	int ret;

	if (!name) {
		data->local_base_dn = NULL;
		data->remote_base_dn = NULL;
		return LDB_SUCCESS;
	}

	ldb = ldb_module_get_ctx(module);

	dn = ldb_dn_new_fmt(data, ldb, "%s=%s", MAP_DN_NAME, name);
	if ( ! ldb_dn_validate(dn)) {
		ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: "
			  "Failed to construct '%s' DN!", MAP_DN_NAME);
		return LDB_ERR_OPERATIONS_ERROR;
	}

	ret = ldb_search(ldb, data, &res, dn, LDB_SCOPE_BASE, attrs, NULL);
	talloc_free(dn);
	if (ret != LDB_SUCCESS) {
		return ret;
	}
	if (res->count == 0) {
		ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: "
			  "No results for '%s=%s'!", MAP_DN_NAME, name);
		talloc_free(res);
		return LDB_ERR_CONSTRAINT_VIOLATION;
	}
	if (res->count > 1) {
		ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: "
			  "Too many results for '%s=%s'!", MAP_DN_NAME, name);
		talloc_free(res);
		return LDB_ERR_CONSTRAINT_VIOLATION;
	}

	msg = res->msgs[0];
	data->local_base_dn = ldb_msg_find_attr_as_dn(ldb, data, msg, MAP_DN_FROM);
	data->remote_base_dn = ldb_msg_find_attr_as_dn(ldb, data, msg, MAP_DN_TO);
	talloc_free(res);

	return LDB_SUCCESS;
}
static int map_init_dns(struct ldb_module *module, struct ldb_map_context *data, const char *name)
{
	static const char * const attrs[] = { MAP_DN_FROM, MAP_DN_TO, NULL };
	struct ldb_context *ldb;
	struct ldb_dn *dn;
	struct ldb_message *msg;
	struct ldb_result *res;
	int ret;

	if (!name) {
		data->local_base_dn = NULL;
		data->remote_base_dn = NULL;
		return LDB_SUCCESS;
	}

	ldb = ldb_module_get_ctx(module);

	dn = ldb_dn_new_fmt(data, ldb, "%s=%s", MAP_DN_NAME, name);
	if ( ! ldb_dn_validate(dn)) {
		ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: "
			  "Failed to construct '%s' DN!", MAP_DN_NAME);
		return LDB_ERR_OPERATIONS_ERROR;
	}

	ret = ldb_search(ldb, data, &res, dn, LDB_SCOPE_BASE, attrs, NULL);
	talloc_free(dn);
	if (ret != LDB_SUCCESS) {
		return ret;
	}
	if (res->count == 0) {
		ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: "
			  "No results for '%s=%s'!", MAP_DN_NAME, name);
		talloc_free(res);
		return LDB_ERR_CONSTRAINT_VIOLATION;
	}
	if (res->count > 1) {
		ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: "
			  "Too many results for '%s=%s'!", MAP_DN_NAME, name);
		talloc_free(res);
		return LDB_ERR_CONSTRAINT_VIOLATION;
	}

	msg = res->msgs[0];
	data->local_base_dn = ldb_msg_find_attr_as_dn(ldb, data, msg, MAP_DN_FROM);
	data->remote_base_dn = ldb_msg_find_attr_as_dn(ldb, data, msg, MAP_DN_TO);
	talloc_free(res);

	return LDB_SUCCESS;
}