ret = ldb_msg_add_empty(msg, "objectClass", LDB_FLAG_MOD_REPLACE, NULL);
- if (ret != 0) goto failed;
+ if (ret != LDB_SUCCESS) goto failed;
ret = ldb_msg_add_string(msg, "objectClass", "winsMaxVersion");
- if (ret != 0) goto failed;
+ if (ret != LDB_SUCCESS) goto failed;
ret = ldb_msg_add_empty(msg, "maxVersion", LDB_FLAG_MOD_REPLACE, NULL);
- if (ret != 0) goto failed;
+ if (ret != LDB_SUCCESS) goto failed;
ret = ldb_msg_add_fmt(msg, "maxVersion", "%llu", (long long)newMaxVersion);
- if (ret != 0) goto failed;
+ if (ret != LDB_SUCCESS) goto failed;
ret = ldb_modify(wins_db, msg);
- if (ret != 0) ret = ldb_add(wins_db, msg);
- if (ret != 0) goto failed;
+ if (ret != LDB_SUCCESS) ret = ldb_add(wins_db, msg);
+ if (ret != LDB_SUCCESS) goto failed;
trans = ldb_transaction_commit(wins_db);
if (trans != LDB_SUCCESS) goto failed;
/*
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;
return NT_STATUS_OK;
}
- *p = '\0';p++;
+ *p = '\0'; p++;
addr->address = talloc_strdup(addr, address);
if (!addr->address) {
status = NT_STATUS_NO_MEMORY;
static int ldb_msg_add_winsdb_addr(struct ldb_message *msg, struct winsdb_record *rec,
const char *attr_name, struct winsdb_addr *addr)
{
- struct ldb_val val;
const char *str;
if (rec->is_static) {
str = talloc_strdup(msg, addr->address);
- if (!str) return -1;
+ if (!str) return LDB_ERR_OPERATIONS_ERROR;
} else {
char *expire_time;
expire_time = ldb_timestring(msg, addr->expire_time);
- if (!expire_time) return -1;
+ if (!expire_time) return LDB_ERR_OPERATIONS_ERROR;
str = talloc_asprintf(msg, "%s;winsOwner:%s;expireTime:%s;",
addr->address, addr->wins_owner,
expire_time);
talloc_free(expire_time);
- if (!str) return -1;
+ if (!str) return LDB_ERR_OPERATIONS_ERROR;
}
- val.data = discard_const_p(uint8_t, str);
- val.length = strlen(str);
-
- return ldb_msg_add_value(msg, attr_name, &val, NULL);
+ return ldb_msg_add_string(msg, attr_name, str);
}
struct winsdb_addr **winsdb_addr_list_make(TALLOC_CTX *mem_ctx)
addresses[len+1] = NULL;
- ldb_qsort(addresses, len+1 , sizeof(addresses[0]), h, (ldb_qsort_cmp_fn_t)winsdb_addr_sort_list);
+ LDB_TYPESAFE_QSORT(addresses, len+1, h, winsdb_addr_sort_list);
return addresses;
}
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)
{
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;
+ int i, ret;
size_t addr_count;
const char *expire_time;
struct ldb_message *msg = ldb_msg_new(mem_ctx);
msg->dn = winsdb_dn(msg, ldb, rec->name);
if (msg->dn == NULL) goto failed;
- ret |= ldb_msg_add_fmt(msg, "type", "0x%02X", rec->name->type);
+ ret = ldb_msg_add_fmt(msg, "type", "0x%02X", rec->name->type);
if (rec->name->name && *rec->name->name) {
ret |= ldb_msg_add_string(msg, "name", rec->name->name);
}
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 != LDB_SUCCESS) goto failed;
return msg;
failed:
struct ldb_context *wins_db = h->ldb;
TALLOC_CTX *tmp_ctx = talloc_new(wins_db);
int trans = -1;
- int ret = 0;
+ int ret;
trans = ldb_transaction_start(wins_db);
if (trans != LDB_SUCCESS) goto failed;
msg = winsdb_message(wins_db, rec, tmp_ctx);
if (msg == NULL) goto failed;
ret = ldb_add(wins_db, msg);
- if (ret != 0) goto failed;
+ if (ret != LDB_SUCCESS) goto failed;
trans = ldb_transaction_commit(wins_db);
if (trans != LDB_SUCCESS) goto failed;
}
ret = ldb_modify(wins_db, msg);
- if (ret != 0) goto failed;
+ if (ret != LDB_SUCCESS) goto failed;
trans = ldb_transaction_commit(wins_db);
if (trans != LDB_SUCCESS) goto failed;
if (dn == NULL) goto failed;
ret = ldb_delete(wins_db, dn);
- if (ret != 0) goto failed;
+ if (ret != LDB_SUCCESS) goto failed;
trans = ldb_transaction_commit(wins_db);
if (trans != LDB_SUCCESS) goto failed;
return NBT_RCODE_SVR;
}
-static bool winsdb_check_or_add_module_list(struct event_context *ev_ctx,
+static bool winsdb_check_or_add_module_list(struct tevent_context *ev_ctx,
struct loadparm_context *lp_ctx, struct winsdb_handle *h)
{
int trans;
msg->dn = dn;
ret = ldb_msg_add_string(msg, "@LIST", "wins_ldb");
- if (ret != 0) goto failed;
+ if (ret != LDB_SUCCESS) goto failed;
ret = ldb_add(h->ldb, msg);
- if (ret != 0) goto failed;
+ if (ret != LDB_SUCCESS) goto failed;
trans = ldb_transaction_commit(h->ldb);
if (trans != LDB_SUCCESS) goto failed;
talloc_free(h->ldb);
h->ldb = NULL;
- if (lp_parm_bool(lp_ctx, NULL,"winsdb", "nosync", false)) {
+ if (lpcfg_parm_bool(lp_ctx, NULL,"winsdb", "nosync", false)) {
flags |= LDB_FLG_NOSYNC;
}
- h->ldb = ldb_wrap_connect(h, ev_ctx, lp_ctx, lock_path(h, lp_ctx, lp_wins_url(lp_ctx)),
- NULL, NULL, flags, NULL);
+ h->ldb = ldb_wrap_connect(h, ev_ctx, lp_ctx, lock_path(h, lp_ctx, lpcfg_wins_url(lp_ctx)),
+ NULL, NULL, flags);
if (!h->ldb) goto failed;
talloc_free(tmp_ctx);
}
struct winsdb_handle *winsdb_connect(TALLOC_CTX *mem_ctx,
- struct event_context *ev_ctx,
+ struct tevent_context *ev_ctx,
struct loadparm_context *lp_ctx,
const char *owner,
enum winsdb_handle_caller caller)
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)) {
+ if (lpcfg_parm_bool(lp_ctx, NULL,"winsdb", "nosync", false)) {
flags |= LDB_FLG_NOSYNC;
}
- h->ldb = ldb_wrap_connect(h, ev_ctx, lp_ctx, lock_path(h, lp_ctx, lp_wins_url(lp_ctx)),
- NULL, NULL, flags, NULL);
+ h->ldb = ldb_wrap_connect(h, ev_ctx, lp_ctx, lock_path(h, lp_ctx, lpcfg_wins_url(lp_ctx)),
+ NULL, NULL, flags);
if (!h->ldb) goto failed;
h->caller = caller;
- h->hook_script = lp_wins_hook(lp_ctx);
+ h->hook_script = lpcfg_wins_hook(lp_ctx);
h->local_owner = talloc_strdup(h, owner);
if (!h->local_owner) goto failed;
talloc_free(h);
return NULL;
}
+