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) {
if (!dn) goto failed;
/* find the record in the WINS database */
- ret = ldb_search(wins_db, dn, LDB_SCOPE_BASE, NULL, NULL, &res);
-
+ ret = ldb_search(wins_db, 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;
- talloc_steal(tmp_ctx, res);
-
if (res->count == 1) {
oldMaxVersion = ldb_msg_find_attr_as_uint64(res->msgs[0], "maxVersion", 0);
}
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) {
/*
return a DN for a nbt_name
*/
-static struct ldb_dn *winsdb_dn(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, struct nbt_name *name)
+static struct ldb_dn *winsdb_dn(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
+ const struct nbt_name *name)
{
struct ldb_dn *dn;
load a WINS entry from the database
*/
NTSTATUS winsdb_lookup(struct winsdb_handle *h,
- struct nbt_name *name,
+ const struct nbt_name *name,
TALLOC_CTX *mem_ctx,
struct winsdb_record **_rec)
{
time_t now = time(NULL);
/* find the record in the WINS database */
- ret = ldb_search(wins_db, winsdb_dn(tmp_ctx, wins_db, name), LDB_SCOPE_BASE,
- NULL, NULL, &res);
+ ret = ldb_search(wins_db, tmp_ctx, &res,
+ winsdb_dn(tmp_ctx, wins_db, name),
+ LDB_SCOPE_BASE, NULL, NULL);
- talloc_steal(tmp_ctx, res);
if (ret != LDB_SUCCESS || res->count > 1) {
status = NT_STATUS_INTERNAL_DB_CORRUPTION;
goto failed;
struct ldb_message_element *el;
struct nbt_name *name;
uint32_t i, j, num_values;
- bool we_are_owner = false;
rec = talloc(mem_ctx, struct winsdb_record);
if (rec == NULL) {
goto failed;
}
- if (strcmp(rec->wins_owner, h->local_owner) == 0) {
- we_are_owner = true;
- }
-
- /*
- * see if it has already expired
- *
- * NOTE: only expire owned records this way!
- * w2k3 resolves expired replicas
- * which are in active state
- */
- if (!rec->is_static &&
- rec->expire_time <= now &&
- rec->state == WREPL_STATE_ACTIVE &&
- we_are_owner) {
- DEBUG(5,("WINS: expiring name %s (expired at %s)\n",
- nbt_name_string(mem_ctx, rec->name), timestring(mem_ctx, rec->expire_time)));
- rec->state = WREPL_STATE_RELEASED;
- }
-
rec->addresses = talloc_array(rec, struct winsdb_addr *, num_values+1);
if (rec->addresses == NULL) {
status = NT_STATUS_NO_MEMORY;
}
for (i=0,j=0;i<num_values;i++) {
+ bool we_are_owner = false;
+
status = winsdb_addr_decode(h, rec, &el->values[i], rec->addresses, &rec->addresses[j]);
if (!NT_STATUS_IS_OK(status)) goto failed;
+ if (strcmp(rec->addresses[j]->wins_owner, h->local_owner) == 0) {
+ we_are_owner = true;
+ }
+
/*
* the record isn't static and is active
- * then don't add the address if it's expired
+ * then don't add the address if it's expired,
+ * but only if we're the owner of the address
+ *
+ * This is important for SGROUP records,
+ * because each server thinks he's the owner of the
+ * record and the record isn't replicated on a
+ * name_refresh. So addresses owned by another owner
+ * could expire, but we still need to return them
+ * (as windows does).
*/
if (!rec->is_static &&
rec->addresses[j]->expire_time <= now &&
/*
form a ldb_message from a winsdb_record
*/
-struct ldb_message *winsdb_message(struct ldb_context *ldb,
- struct winsdb_record *rec, TALLOC_CTX *mem_ctx)
+static struct ldb_message *winsdb_message(struct ldb_context *ldb,
+ struct winsdb_record *rec,
+ TALLOC_CTX *mem_ctx)
{
int i, ret=0;
size_t addr_count;
for (i=0;rec->addresses[i];i++) {
ret |= ldb_msg_add_winsdb_addr(msg, rec, "address", rec->addresses[i]);
}
- ret |= ldb_msg_add_empty(msg, "registeredBy", 0, NULL);
if (rec->registered_by) {
+ ret |= ldb_msg_add_empty(msg, "registeredBy", 0, NULL);
ret |= ldb_msg_add_string(msg, "registeredBy", rec->registered_by);
- if (ret != 0) goto failed;
}
+ if (ret != 0) goto failed;
return msg;
failed:
return NBT_RCODE_SVR;
}
-static bool winsdb_check_or_add_module_list(struct loadparm_context *lp_ctx, struct winsdb_handle *h)
+static bool winsdb_check_or_add_module_list(struct tevent_context *ev_ctx,
+ struct loadparm_context *lp_ctx, struct winsdb_handle *h)
{
int trans;
int ret;
if (!dn) goto failed;
/* find the record in the WINS database */
- ret = ldb_search(h->ldb, dn, LDB_SCOPE_BASE, NULL, NULL, &res);
+ ret = ldb_search(h->ldb, tmp_ctx, &res, dn, LDB_SCOPE_BASE, NULL, NULL);
if (ret != LDB_SUCCESS) goto failed;
- talloc_steal(tmp_ctx, res);
if (res->count > 0) goto skip;
flags |= LDB_FLG_NOSYNC;
}
- h->ldb = ldb_wrap_connect(h, lp_ctx, lock_path(h, lp_ctx, lp_wins_url(lp_ctx)),
+ h->ldb = ldb_wrap_connect(h, ev_ctx, lp_ctx, lock_path(h, lp_ctx, lp_wins_url(lp_ctx)),
NULL, NULL, flags, NULL);
if (!h->ldb) goto failed;
return false;
}
-struct winsdb_handle *winsdb_connect(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
+struct winsdb_handle *winsdb_connect(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev_ctx,
+ struct loadparm_context *lp_ctx,
+ const char *owner,
enum winsdb_handle_caller caller)
{
struct winsdb_handle *h = NULL;
- const char *owner;
unsigned int flags = 0;
bool ret;
int ldb_err;
- h = talloc(mem_ctx, struct winsdb_handle);
+ h = talloc_zero(mem_ctx, struct winsdb_handle);
if (!h) return NULL;
if (lp_parm_bool(lp_ctx, NULL,"winsdb", "nosync", false)) {
flags |= LDB_FLG_NOSYNC;
}
- h->ldb = ldb_wrap_connect(h, lp_ctx, lock_path(h, lp_ctx, lp_wins_url(lp_ctx)),
+ h->ldb = ldb_wrap_connect(h, ev_ctx, lp_ctx, lock_path(h, lp_ctx, lp_wins_url(lp_ctx)),
NULL, NULL, flags, NULL);
if (!h->ldb) goto failed;
h->caller = caller;
h->hook_script = lp_wins_hook(lp_ctx);
- owner = lp_parm_string(lp_ctx, NULL, "winsdb", "local_owner");
- if (!owner) {
- owner = iface_n_ip(0);
- }
-
h->local_owner = talloc_strdup(h, owner);
if (!h->local_owner) goto failed;
/* make sure the module list is available and used */
- ret = winsdb_check_or_add_module_list(lp_ctx, h);
+ ret = winsdb_check_or_add_module_list(ev_ctx, lp_ctx, h);
if (!ret) goto failed;
ldb_err = ldb_set_opaque(h->ldb, "winsdb_handle", h);