#include "smbd/service.h"
#include "lib/events/events.h"
#include "dsdb/repl/drepl_service.h"
-#include "lib/ldb/include/ldb_errors.h"
+#include <ldb_errors.h>
#include "../lib/util/dlinklist.h"
#include "librpc/gen_ndr/ndr_misc.h"
#include "librpc/gen_ndr/ndr_drsuapi.h"
#include "librpc/gen_ndr/ndr_drsblobs.h"
#include "librpc/gen_ndr/ndr_irpc.h"
#include "param/param.h"
+#include "libds/common/roles.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_DRS_REPL
/**
* Call-back data for _drepl_replica_sync_done_cb()
{
service->system_session_info = system_session(service->task->lp_ctx);
if (service->system_session_info == NULL) {
- return WERR_NOMEM;
+ return WERR_NOT_ENOUGH_MEMORY;
}
return WERR_OK;
struct drsuapi_DsReplicaSync *r = data->r;
/* store last bad result */
- if (W_ERROR_IS_OK(werr)) {
+ if (!W_ERROR_IS_OK(werr)) {
data->werr_last_failure = werr;
}
static WERROR _drepl_schedule_replication(struct dreplsrv_service *service,
struct dreplsrv_partition_source_dsa *dsa,
struct drsuapi_DsReplicaObjectIdentifier *nc,
+ uint32_t rep_options,
struct drepl_replica_sync_cb_data *data,
TALLOC_CTX *mem_ctx)
{
}
/* schedule replication item */
- werr = dreplsrv_schedule_partition_pull_source(service, dsa,
+ werr = dreplsrv_schedule_partition_pull_source(service, dsa, rep_options,
DRSUAPI_EXOP_NONE, 0,
fn_callback, data);
if (!W_ERROR_IS_OK(werr)) {
} else {
cb_data = talloc_zero(msg, struct drepl_replica_sync_cb_data);
if (!cb_data) {
- REPLICA_SYNC_FAIL("Not enought memory",
+ REPLICA_SYNC_FAIL("Not enough memory",
WERR_DS_DRA_INTERNAL_ERROR);
}
if (req1->options & DRSUAPI_DRS_SYNC_ALL) {
for (dsa = p->sources; dsa; dsa = dsa->next) {
/* schedule replication item */
- werr = _drepl_schedule_replication(service, dsa, nc, cb_data, msg);
+ werr = _drepl_schedule_replication(service, dsa, nc,
+ req1->options, cb_data, msg);
if (!W_ERROR_IS_OK(werr)) {
REPLICA_SYNC_FAIL("_drepl_schedule_replication() failed",
werr);
werr = dreplsrv_partition_source_dsa_by_guid(p,
&req1->source_dsa_guid,
&dsa);
+ if (W_ERROR_EQUAL(werr, WERR_DS_DRA_NO_REPLICA)) {
+ /* we don't have this source setup as
+ a replication partner. Create a
+ temporary dsa structure for this
+ replication */
+ werr = dreplsrv_partition_source_dsa_temporary(p,
+ msg,
+ &req1->source_dsa_guid,
+ &dsa);
+ }
}
if (!W_ERROR_IS_OK(werr)) {
REPLICA_SYNC_FAIL("Failed to locate source DSA for given NC",
}
/* schedule replication item */
- werr = _drepl_schedule_replication(service, dsa, nc, cb_data, msg);
+ werr = _drepl_schedule_replication(service, dsa, nc,
+ req1->options, cb_data, msg);
if (!W_ERROR_IS_OK(werr)) {
REPLICA_SYNC_FAIL("_drepl_schedule_replication() failed",
werr);
/* if we got here, everything is OK */
r->out.result = WERR_OK;
- /* force execution of scheduled replications */
- dreplsrv_run_pending_ops(service);
+ /*
+ * schedule replication event to force
+ * replication as soon as possible
+ */
+ dreplsrv_pendingops_schedule_pull_now(service);
done:
return NT_STATUS_OK;
return NT_STATUS_OK;
}
-static NTSTATUS drepl_take_FSMO_role(struct irpc_message *msg,
- struct drepl_takeFSMORole *r)
-{
- struct dreplsrv_service *service = talloc_get_type(msg->private_data,
- struct dreplsrv_service);
- r->out.result = dreplsrv_fsmo_role_check(service, r->in.role);
- return NT_STATUS_OK;
-}
-
/**
* Called when the auth code wants us to try and replicate
* a users secrets
task_server_terminate(task, "dreplsrv: no DSDB replication required in domain member configuration",
false);
return;
- case ROLE_DOMAIN_CONTROLLER:
+ case ROLE_ACTIVE_DIRECTORY_DC:
/* Yes, we want DSDB replication */
break;
}
return;
}
+ service->pending.im = tevent_create_immediate(service);
+ if (service->pending.im == NULL) {
+ task_server_terminate(task,
+ "dreplsrv: Failed to create immediate "
+ "task for future DsReplicaSync\n",
+ true);
+ return;
+ }
+
/* if we are a RODC then we do not send DSReplicaSync*/
if (!service->am_rodc) {
service->notify.interval = lpcfg_parm_int(task->lp_ctx, NULL, "dreplsrv",
IRPC_REGISTER(task->msg_ctx, drsuapi, DRSUAPI_DSREPLICAMOD, dreplsrv_replica_mod, service);
IRPC_REGISTER(task->msg_ctx, irpc, DREPL_TAKEFSMOROLE, drepl_take_FSMO_role, service);
IRPC_REGISTER(task->msg_ctx, irpc, DREPL_TRIGGER_REPL_SECRET, drepl_trigger_repl_secret, service);
- messaging_register(task->msg_ctx, service, MSG_DREPL_ALLOCATE_RID, dreplsrv_allocate_rid);
+ imessaging_register(task->msg_ctx, service, MSG_DREPL_ALLOCATE_RID, dreplsrv_allocate_rid);
}
/*
register ourselves as a available server
*/
-NTSTATUS server_service_drepl_init(void)
+NTSTATUS server_service_drepl_init(TALLOC_CTX *ctx)
{
- return register_server_service("drepl", dreplsrv_task_init);
+ return register_server_service(ctx, "drepl", dreplsrv_task_init);
}