This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
-#include "dlinklist.h"
+#include "lib/util/dlinklist.h"
#include "smbd/service_task.h"
+#include "smbd/service.h"
#include "lib/messaging/irpc.h"
-#include "librpc/gen_ndr/ndr_winsrepl.h"
+#include "librpc/gen_ndr/winsrepl.h"
#include "wrepl_server/wrepl_server.h"
#include "nbt_server/wins/winsdb.h"
#include "ldb/include/ldb.h"
#include "ldb/include/ldb_errors.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 loadparm_context *lp_ctx)
{
- return ldb_wrap_connect(mem_ctx, private_path(mem_ctx, lp_wins_config_url()),
- system_session(mem_ctx), NULL, 0, NULL);
+ return ldb_wrap_connect(mem_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)
TALLOC_CTX *tmp_ctx = talloc_new(ldb);
uint64_t seqnumber = 0;
- dn = ldb_dn_explode(tmp_ctx, "@BASEINFO");
+ dn = ldb_dn_new(tmp_ctx, ldb, "@BASEINFO");
if (!dn) goto failed;
/* find the record in the WINS database */
if (res->count > 1) goto failed;
if (res->count == 1) {
- seqnumber = ldb_msg_find_uint64(res->msgs[0], "sequenceNumber", 0);
+ seqnumber = ldb_msg_find_attr_as_uint64(res->msgs[0], "sequenceNumber", 0);
}
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, 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, 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(-1,"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(-1,"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(-1,"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(-1,"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(-1,"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(-1,"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(-1,"wreplsrv","periodic_interval", 15);
+ service->config.periodic_interval = lp_parm_int(lp_ctx, NULL,"wreplsrv","periodic_interval", 15);
return NT_STATUS_OK;
}
struct wreplsrv_partner *partner;
struct ldb_result *res = NULL;
int ret;
- TALLOC_CTX *tmp_ctx = talloc_new(service);
+ TALLOC_CTX *tmp_ctx;
int i;
uint64_t new_seqnumber;
return NT_STATUS_OK;
}
+ tmp_ctx = talloc_new(service);
+ NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
+
service->config.seqnumber = new_seqnumber;
/* find the record in the WINS database */
- ret = ldb_search(service->config.ldb, ldb_dn_explode(tmp_ctx, "CN=PARTNERS"), LDB_SCOPE_SUBTREE,
+ ret = ldb_search(service->config.ldb, ldb_dn_new(tmp_ctx, service->config.ldb, "CN=PARTNERS"), LDB_SCOPE_SUBTREE,
"(objectClass=wreplPartner)", NULL, &res);
if (ret != LDB_SUCCESS) goto failed;
talloc_steal(tmp_ctx, res);
for (i=0; i < res->count; i++) {
const char *address;
- address = ldb_msg_find_string(res->msgs[i], "address", NULL);
+ address = ldb_msg_find_attr_as_string(res->msgs[i], "address", NULL);
if (!address) {
goto failed;
}
DLIST_ADD_END(service->partners, partner, struct wreplsrv_partner *);
}
- partner->name = ldb_msg_find_string(res->msgs[i], "name", partner->address);
+ partner->name = ldb_msg_find_attr_as_string(res->msgs[i], "name", partner->address);
talloc_steal(partner, partner->name);
- partner->our_address = ldb_msg_find_string(res->msgs[i], "ourAddress", NULL);
+ partner->our_address = ldb_msg_find_attr_as_string(res->msgs[i], "ourAddress", NULL);
talloc_steal(partner, partner->our_address);
- partner->type = ldb_msg_find_uint(res->msgs[i], "type", WINSREPL_PARTNER_BOTH);
- partner->pull.interval = ldb_msg_find_uint(res->msgs[i], "pullInterval",
+ partner->type = ldb_msg_find_attr_as_uint(res->msgs[i], "type", WINSREPL_PARTNER_BOTH);
+ partner->pull.interval = ldb_msg_find_attr_as_uint(res->msgs[i], "pullInterval",
WINSREPL_DEFAULT_PULL_INTERVAL);
- partner->pull.retry_interval = ldb_msg_find_uint(res->msgs[i], "pullRetryInterval",
+ partner->pull.retry_interval = ldb_msg_find_attr_as_uint(res->msgs[i], "pullRetryInterval",
WINSREPL_DEFAULT_PULL_RETRY_INTERVAL);
- partner->push.change_count = ldb_msg_find_uint(res->msgs[i], "pushChangeCount",
+ partner->push.change_count = ldb_msg_find_attr_as_uint(res->msgs[i], "pushChangeCount",
WINSREPL_DEFAULT_PUSH_CHANGE_COUNT);
- partner->push.use_inform = ldb_msg_find_uint(res->msgs[i], "pushUseInform", False);
+ partner->push.use_inform = ldb_msg_find_attr_as_uint(res->msgs[i], "pushUseInform", false);
DEBUG(3,("wreplsrv_load_partners: found partner: %s type: 0x%X\n",
partner->address, partner->type));
}
DEBUG(2,("wreplsrv_load_partners: %u partners found: wins_config_db seqnumber %llu\n",
- res->count, service->config.seqnumber));
+ res->count, (unsigned long long)service->config.seqnumber));
talloc_free(tmp_ctx);
return NT_STATUS_OK;
TALLOC_CTX *mem_ctx,
struct wrepl_table *table_out,
const char *initiator,
- BOOL full_table)
+ bool full_table)
{
struct wreplsrv_owner *cur;
uint32_t i = 0;
NT_STATUS_HAVE_NO_MEMORY(table_out->partners);
for (cur = service->table; cur && i < table_out->partner_count; cur = cur->next) {
+ /*
+ * if it's our local entry
+ * update the max version
+ */
+ if (cur == service->owner) {
+ cur->owner.max_version = winsdb_get_maxVersion(service->wins_db);
+ }
+
if (full_table) {
table_out->partners[i] = cur->owner;
i++;
/* the min_version is always 0 here, and won't be updated */
- /* if the given version is higher the then current nax_version, update */
+ /* if the given version is higher than the current max_version, update */
if (cur->owner.max_version < version) {
cur->owner.max_version = version;
/* if it's for our local db, we need to update the wins.ldb too */
ret = winsdb_set_maxVersion(service->wins_db, cur->owner.max_version);
if (ret != cur->owner.max_version) {
DEBUG(0,("winsdb_set_maxVersion(%llu) failed: %llu\n",
- cur->owner.max_version, ret));
+ (unsigned long long)cur->owner.max_version,
+ (unsigned long long)ret));
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
}
talloc_steal(tmp_ctx, res);
for (i=0; i < res->count; i++) {
- wins_owner = ldb_msg_find_string(res->msgs[i], "winsOwner", NULL);
- version = ldb_msg_find_uint64(res->msgs[i], "versionID", 0);
+ wins_owner = ldb_msg_find_attr_as_string(res->msgs[i], "winsOwner", NULL);
+ version = ldb_msg_find_attr_as_uint64(res->msgs[i], "versionID", 0);
status = wreplsrv_add_table(service,
service, &service->table,
NTSTATUS status;
struct wreplsrv_service *service;
+ task_server_set_title(task, "task[wreplsrv]");
+
service = talloc_zero(task, struct wreplsrv_service);
if (!service) {
task_server_terminate(task, "wreplsrv_task_init: out of memory");
/*
* 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;
* 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;
/*
initialise the WREPL server
*/
-static NTSTATUS wreplsrv_init(struct event_context *event_ctx, const struct model_ops *model_ops)
+static NTSTATUS wreplsrv_init(struct event_context *event_ctx, struct loadparm_context *lp_ctx, const struct model_ops *model_ops)
{
- if (!lp_wins_support()) {
+ if (!lp_wins_support(lp_ctx)) {
return NT_STATUS_OK;
}
- return task_server_startup(event_ctx, model_ops, wreplsrv_task_init);
+ return task_server_startup(event_ctx, lp_ctx, "wrepl",
+ model_ops, wreplsrv_task_init);
}
/*