debug: Add new debug class "drs_repl" for DRS replication processing
[samba.git] / source4 / dsdb / repl / drepl_service.c
index ec803f6fdb05c1345371e363cfdbdd6d6e59bb60..0951a0f0cc0f1c52d62824c0a7753d2be859ba1f 100644 (file)
 #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()
@@ -53,7 +57,7 @@ static WERROR dreplsrv_init_creds(struct dreplsrv_service *service)
 {
        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;
@@ -265,7 +269,7 @@ static NTSTATUS drepl_replica_sync(struct irpc_message *msg,
        } 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);
                }
 
@@ -306,6 +310,16 @@ static NTSTATUS drepl_replica_sync(struct irpc_message *msg,
                        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",
@@ -328,7 +342,7 @@ static NTSTATUS drepl_replica_sync(struct irpc_message *msg,
         * schedule replication event to force
         * replication as soon as possible
         */
-       dreplsrv_periodic_schedule(service, 0);
+       dreplsrv_pendingops_schedule_pull_now(service);
 
 done:
        return NT_STATUS_OK;
@@ -424,7 +438,7 @@ static void dreplsrv_task_init(struct task_server *task)
                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;
        }
@@ -475,6 +489,15 @@ static void dreplsrv_task_init(struct task_server *task)
                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",
@@ -503,7 +526,7 @@ static void dreplsrv_task_init(struct task_server *task)
 /*
   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);
 }