static int send_rodc_referral(struct ldb_request *req,
			      struct ldb_context *ldb,
			      struct ldb_dn *dn)
{
	char *referral = NULL;
	struct loadparm_context *lp_ctx = NULL;
	struct ldb_dn *fsmo_role_dn = NULL;
	struct ldb_dn *role_owner_dn = NULL;
	const char *domain = NULL;
	WERROR werr;

	lp_ctx = talloc_get_type(ldb_get_opaque(ldb, "loadparm"),
				 struct loadparm_context);

	werr = dsdb_get_fsmo_role_info(req, ldb, DREPL_PDC_MASTER,
				       &fsmo_role_dn, &role_owner_dn);

	if (W_ERROR_IS_OK(werr)) {
		struct ldb_dn *server_dn = ldb_dn_copy(req, role_owner_dn);
		if (server_dn != NULL) {
			ldb_dn_remove_child_components(server_dn, 1);
			domain = samdb_dn_to_dnshostname(ldb, req,
							 server_dn);
		}
	}

	if (domain == NULL) {
		domain = lpcfg_dnsdomain(lp_ctx);
	}

	referral = talloc_asprintf(req, "ldap://%s/%s",
				   domain,
				   ldb_dn_get_linearized(dn));
	if (referral == NULL) {
		ldb_oom(ldb);
		return LDB_ERR_OPERATIONS_ERROR;
	}

	return ldb_module_send_referral(req, referral);
}
static int send_rodc_referral(struct ldb_request *req,
			      struct ldb_context *ldb,
			      struct ldb_dn *dn)
{
	char *referral = NULL;
	struct loadparm_context *lp_ctx = NULL;
	struct ldb_dn *fsmo_role_dn = NULL;
	struct ldb_dn *role_owner_dn = NULL;
	const char *domain = NULL;
	WERROR werr;

	lp_ctx = talloc_get_type(ldb_get_opaque(ldb, "loadparm"),
				 struct loadparm_context);

	werr = dsdb_get_fsmo_role_info(req, ldb, DREPL_PDC_MASTER,
				       &fsmo_role_dn, &role_owner_dn);

	if (W_ERROR_IS_OK(werr)) {
		struct ldb_dn *server_dn = ldb_dn_copy(req, role_owner_dn);
		if (server_dn != NULL) {
			ldb_dn_remove_child_components(server_dn, 1);
			domain = samdb_dn_to_dnshostname(ldb, req,
							 server_dn);
		}
	}

	if (domain == NULL) {
		domain = lpcfg_dnsdomain(lp_ctx);
	}

	referral = talloc_asprintf(req, "ldap://%s/%s",
				   domain,
				   ldb_dn_get_linearized(dn));
	if (referral == NULL) {
		ldb_oom(ldb);
		return LDB_ERR_OPERATIONS_ERROR;
	}

	return ldb_module_send_referral(req, referral);
}