Fix include paths to new location of libutil.
[bbaumbach/samba-autobuild/.git] / source4 / wrepl_server / wrepl_server.c
index 834d9a70e8119d694a419951bf6b1e5c9caf7846..d0b02d0abe3616bfab4285adfaa6fd809464c386 100644 (file)
@@ -20,7 +20,7 @@
 */
 
 #include "includes.h"
-#include "lib/util/dlinklist.h"
+#include "../lib/util/dlinklist.h"
 #include "smbd/service_task.h"
 #include "smbd/service.h"
 #include "lib/messaging/irpc.h"
 #include "auth/auth.h"
 #include "ldb_wrap.h"
 #include "param/param.h"
+#include "lib/socket/netif.h"
 
-static struct ldb_context *wins_config_db_connect(TALLOC_CTX *mem_ctx)
+static struct ldb_context *wins_config_db_connect(TALLOC_CTX *mem_ctx, 
+                                                 struct event_context *ev_ctx,
+                                                 struct loadparm_context *lp_ctx)
 {
-       return ldb_wrap_connect(mem_ctx, global_loadparm, private_path(mem_ctx, 
-                               global_loadparm, 
-                               lp_wins_config_url(global_loadparm)),
-                               system_session(mem_ctx), NULL, 0, NULL);
+       return ldb_wrap_connect(mem_ctx, ev_ctx, lp_ctx, private_path(mem_ctx, 
+                               lp_ctx, lp_wins_config_url(lp_ctx)),
+                               system_session(mem_ctx, lp_ctx), NULL, 0, NULL);
 }
 
 static uint64_t wins_config_db_get_seqnumber(struct ldb_context *ldb)
@@ -53,10 +55,8 @@ static uint64_t wins_config_db_get_seqnumber(struct ldb_context *ldb)
        if (!dn) goto failed;
 
        /* find the record in the WINS database */
-       ret = ldb_search(ldb, dn, LDB_SCOPE_BASE, 
-                        NULL, NULL, &res);
+       ret = ldb_search(ldb, tmp_ctx, &res, dn, LDB_SCOPE_BASE, NULL, NULL);
        if (ret != LDB_SUCCESS) goto failed;
-       talloc_steal(tmp_ctx, res);
        if (res->count > 1) goto failed;
 
        if (res->count == 1) {
@@ -71,39 +71,48 @@ failed:
 /*
   open winsdb
 */
-static NTSTATUS wreplsrv_open_winsdb(struct wreplsrv_service *service)
+static NTSTATUS wreplsrv_open_winsdb(struct wreplsrv_service *service, 
+                                    struct loadparm_context *lp_ctx)
 {
-       service->wins_db     = winsdb_connect(service, WINSDB_HANDLE_CALLER_WREPL);
+       const char *owner = lp_parm_string(lp_ctx, NULL, "winsdb", "local_owner");
+
+       if (owner == NULL) {
+               struct interface *ifaces;
+               load_interfaces(service, lp_interfaces(lp_ctx), &ifaces);
+               owner = iface_n_ip(ifaces, 0);
+       }
+
+       service->wins_db     = winsdb_connect(service, service->task->event_ctx, lp_ctx, owner, WINSDB_HANDLE_CALLER_WREPL);
        if (!service->wins_db) {
                return NT_STATUS_INTERNAL_DB_ERROR;
        }
 
-       service->config.ldb = wins_config_db_connect(service);
+       service->config.ldb = wins_config_db_connect(service, service->task->event_ctx, lp_ctx);
        if (!service->config.ldb) {
                return NT_STATUS_INTERNAL_DB_ERROR;
        }
 
        /* the default renew interval is 6 days */
-       service->config.renew_interval    = lp_parm_int(global_loadparm, NULL,"wreplsrv","renew_interval", 6*24*60*60);
+       service->config.renew_interval    = lp_parm_int(lp_ctx, NULL,"wreplsrv","renew_interval", 6*24*60*60);
 
        /* the default tombstone (extinction) interval is 6 days */
-       service->config.tombstone_interval= lp_parm_int(global_loadparm, NULL,"wreplsrv","tombstone_interval", 6*24*60*60);
+       service->config.tombstone_interval= lp_parm_int(lp_ctx, NULL,"wreplsrv","tombstone_interval", 6*24*60*60);
 
        /* the default tombstone (extinction) timeout is 1 day */
-       service->config.tombstone_timeout = lp_parm_int(global_loadparm, NULL,"wreplsrv","tombstone_timeout", 1*24*60*60);
+       service->config.tombstone_timeout = lp_parm_int(lp_ctx, NULL,"wreplsrv","tombstone_timeout", 1*24*60*60);
 
        /* the default tombstone extra timeout is 3 days */
-       service->config.tombstone_extra_timeout = lp_parm_int(global_loadparm, NULL,"wreplsrv","tombstone_extra_timeout", 3*24*60*60);
+       service->config.tombstone_extra_timeout = lp_parm_int(lp_ctx, NULL,"wreplsrv","tombstone_extra_timeout", 3*24*60*60);
 
        /* the default verify interval is 24 days */
-       service->config.verify_interval   = lp_parm_int(global_loadparm, NULL,"wreplsrv","verify_interval", 24*24*60*60);
+       service->config.verify_interval   = lp_parm_int(lp_ctx, NULL,"wreplsrv","verify_interval", 24*24*60*60);
 
        /* the default scavenging interval is 'renew_interval/2' */
-       service->config.scavenging_interval=lp_parm_int(global_loadparm, NULL,"wreplsrv","scavenging_interval",
+       service->config.scavenging_interval=lp_parm_int(lp_ctx, NULL,"wreplsrv","scavenging_interval",
                                                        service->config.renew_interval/2);
 
        /* the maximun interval to the next periodic processing event */
-       service->config.periodic_interval = lp_parm_int(global_loadparm, NULL,"wreplsrv","periodic_interval", 15);
+       service->config.periodic_interval = lp_parm_int(lp_ctx, NULL,"wreplsrv","periodic_interval", 15);
 
        return NT_STATUS_OK;
 }
@@ -146,10 +155,10 @@ NTSTATUS wreplsrv_load_partners(struct wreplsrv_service *service)
        service->config.seqnumber = new_seqnumber;
 
        /* find the record in the WINS database */
-       ret = ldb_search(service->config.ldb, ldb_dn_new(tmp_ctx, service->config.ldb, "CN=PARTNERS"), LDB_SCOPE_SUBTREE,
-                        "(objectClass=wreplPartner)", NULL, &res);
+       ret = ldb_search(service->config.ldb, tmp_ctx, &res,
+                        ldb_dn_new(tmp_ctx, service->config.ldb, "CN=PARTNERS"),
+                        LDB_SCOPE_SUBTREE, NULL, "(objectClass=wreplPartner)");
        if (ret != LDB_SUCCESS) goto failed;
-       talloc_steal(tmp_ctx, res);
 
        /* first disable all existing partners */
        for (partner=service->partners; partner; partner = partner->next) {
@@ -380,11 +389,10 @@ static NTSTATUS wreplsrv_load_table(struct wreplsrv_service *service)
        }
 
        /* find the record in the WINS database */
-       ret = ldb_search(ldb, NULL, LDB_SCOPE_SUBTREE,
-                        "(objectClass=winsRecord)", attrs, &res);
+       ret = ldb_search(ldb, tmp_ctx, &res, NULL, LDB_SCOPE_SUBTREE,
+                        attrs, "(objectClass=winsRecord)");
        status = NT_STATUS_INTERNAL_DB_CORRUPTION;
        if (ret != LDB_SUCCESS) goto failed;
-       talloc_steal(tmp_ctx, res);
 
        for (i=0; i < res->count; i++) {
                wins_owner     = ldb_msg_find_attr_as_string(res->msgs[i], "winsOwner", NULL);
@@ -443,6 +451,10 @@ static void wreplsrv_task_init(struct task_server *task)
        NTSTATUS status;
        struct wreplsrv_service *service;
 
+       if (!lp_wins_support(task->lp_ctx)) {
+               return;
+       }
+
        task_server_set_title(task, "task[wreplsrv]");
 
        service = talloc_zero(task, struct wreplsrv_service);
@@ -457,7 +469,7 @@ static void wreplsrv_task_init(struct task_server *task)
        /*
         * setup up all partners, and open the winsdb
         */
-       status = wreplsrv_open_winsdb(service);
+       status = wreplsrv_open_winsdb(service, task->lp_ctx);
        if (!NT_STATUS_IS_OK(status)) {
                task_server_terminate(task, "wreplsrv_task_init: wreplsrv_open_winsdb() failed");
                return;
@@ -476,7 +488,7 @@ static void wreplsrv_task_init(struct task_server *task)
         * setup listen sockets, so we can anwser requests from our partners,
         * which pull from us
         */
-       status = wreplsrv_setup_sockets(service);
+       status = wreplsrv_setup_sockets(service, task->lp_ctx);
        if (!NT_STATUS_IS_OK(status)) {
                task_server_terminate(task, "wreplsrv_task_init: wreplsrv_setup_sockets() failed");
                return;
@@ -491,22 +503,10 @@ static void wreplsrv_task_init(struct task_server *task)
        irpc_add_name(task->msg_ctx, "wrepl_server");
 }
 
-/*
-  initialise the WREPL server
- */
-static NTSTATUS wreplsrv_init(struct event_context *event_ctx, const struct model_ops *model_ops)
-{
-       if (!lp_wins_support(global_loadparm)) {
-               return NT_STATUS_OK;
-       }
-
-       return task_server_startup(event_ctx, model_ops, wreplsrv_task_init);
-}
-
 /*
   register ourselves as a available server
 */
 NTSTATUS server_service_wrepl_init(void)
 {
-       return register_server_service("wrepl", wreplsrv_init);
+       return register_server_service("wrepl", wreplsrv_task_init);
 }