s4-repl: added a preiodic notification check to the repl task
[ira/wip.git] / source4 / dsdb / repl / drepl_service.c
index 3611258ca586b995fdd3e2d1e74ababe74f2b9a1..cb415b65e684a3ba19dbefd996361acd61cb04cb 100644 (file)
@@ -27,7 +27,7 @@
 #include "lib/messaging/irpc.h"
 #include "dsdb/repl/drepl_service.h"
 #include "lib/ldb/include/ldb_errors.h"
-#include "lib/util/dlinklist.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"
@@ -53,12 +53,12 @@ static WERROR dreplsrv_connect_samdb(struct dreplsrv_service *service, struct lo
 
        service->samdb = samdb_connect(service, service->task->event_ctx, lp_ctx, service->system_session_info);
        if (!service->samdb) {
-               return WERR_DS_SERVICE_UNAVAILABLE;
+               return WERR_DS_UNAVAILABLE;
        }
 
        ntds_guid = samdb_ntds_objectGUID(service->samdb);
        if (!ntds_guid) {
-               return WERR_DS_SERVICE_UNAVAILABLE;
+               return WERR_DS_UNAVAILABLE;
        }
 
        service->ntds_guid = *ntds_guid;
@@ -73,12 +73,7 @@ static WERROR dreplsrv_connect_samdb(struct dreplsrv_service *service, struct lo
        bind_info28->supported_extensions       |= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION;
        bind_info28->supported_extensions       |= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE;
        bind_info28->supported_extensions       |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2;
-#if 0
-       if (s->domain_behavior_version == 2) {
-               /* TODO: find out how this is really triggered! */
-               bind_info28->supported_extensions       |= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION;
-       }
-#endif
+       bind_info28->supported_extensions       |= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION;
        bind_info28->supported_extensions       |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2;
        bind_info28->supported_extensions       |= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD;
        bind_info28->supported_extensions       |= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND;
@@ -110,6 +105,30 @@ static WERROR dreplsrv_connect_samdb(struct dreplsrv_service *service, struct lo
        return WERR_OK;
 }
 
+/*
+  DsReplicaSync messages from the DRSUAPI server are forwarded here
+ */
+static NTSTATUS drepl_replica_sync(struct irpc_message *msg, 
+                                  struct drsuapi_DsReplicaSync *r)
+{
+       struct dreplsrv_service *service = talloc_get_type(msg->private_data,
+                                                          struct dreplsrv_service);
+       WERROR werr;
+       struct GUID *guid = &r->in.req.req1.naming_context->guid;
+
+       werr = dreplsrv_schedule_partition_pull_by_guid(service, msg, guid);
+       if (W_ERROR_IS_OK(werr)) {
+               DEBUG(3,("drepl_replica_sync: forcing sync of partition %s\n",
+                        GUID_string(msg, guid)));
+               dreplsrv_run_pending_ops(service);
+       } else {
+               DEBUG(3,("drepl_replica_sync: failed setup of sync of partition %s - %s\n",
+                        GUID_string(msg, guid), win_errstr(werr)));
+               return NT_STATUS_INTERNAL_ERROR;
+       }
+       return NT_STATUS_OK;
+}
+
 /*
   startup the dsdb replicator service task
 */
@@ -140,7 +159,7 @@ static void dreplsrv_task_init(struct task_server *task)
        }
        service->task           = task;
        service->startup_time   = timeval_current();
-       task->private           = service;
+       task->private_data      = service;
 
        status = dreplsrv_init_creds(service);
        if (!W_ERROR_IS_OK(status)) {
@@ -177,7 +196,19 @@ static void dreplsrv_task_init(struct task_server *task)
                return;
        }
 
+       service->notify.interval = lp_parm_int(task->lp_ctx, NULL, "dreplsrv", 
+                                              "notify_interval", 5); /* in seconds */
+       status = dreplsrv_notify_schedule(service, service->notify.interval);
+       if (!W_ERROR_IS_OK(status)) {
+               task_server_terminate(task, talloc_asprintf(task,
+                                     "dreplsrv: Failed to setup notify schedule: %s\n",
+                                     win_errstr(status)));
+               return;
+       }
+
        irpc_add_name(task->msg_ctx, "dreplsrv");
+
+       IRPC_REGISTER(task->msg_ctx, drsuapi, DRSUAPI_DSREPLICASYNC, drepl_replica_sync, service);
 }
 
 /*