#include "libcli/wrepl/winsrepl.h"
#include "lib/events/events.h"
#include "lib/socket/socket.h"
-#include "libcli/resolve/resolve.h"
#include "system/network.h"
#include "lib/socket/netif.h"
#include "librpc/gen_ndr/ndr_nbt.h"
torture_comment(tctx, "Test if assoc_ctx is only valid on the conection it was created on\n");
- wrepl_socket1 = wrepl_socket_init(tctx, NULL, lp_iconv_convenience(tctx->lp_ctx));
- wrepl_socket2 = wrepl_socket_init(tctx, NULL, lp_iconv_convenience(tctx->lp_ctx));
+ wrepl_socket1 = wrepl_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
+ wrepl_socket2 = wrepl_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
torture_comment(tctx, "Setup 2 wrepl connections\n");
- status = wrepl_connect(wrepl_socket1, lp_resolve_context(tctx->lp_ctx), wrepl_best_ip(tctx->lp_ctx, address), address);
+ status = wrepl_connect(wrepl_socket1, wrepl_best_ip(tctx->lp_ctx, address), address);
CHECK_STATUS(tctx, status, NT_STATUS_OK);
- status = wrepl_connect(wrepl_socket2, lp_resolve_context(tctx->lp_ctx), wrepl_best_ip(tctx->lp_ctx, address), address);
+ status = wrepl_connect(wrepl_socket2, wrepl_best_ip(tctx->lp_ctx, address), address);
CHECK_STATUS(tctx, status, NT_STATUS_OK);
torture_comment(tctx, "Send a start association request (conn1)\n");
torture_comment(tctx, "Test if we always get back the same assoc_ctx\n");
- wrepl_socket = wrepl_socket_init(tctx, NULL, lp_iconv_convenience(tctx->lp_ctx));
+ wrepl_socket = wrepl_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
torture_comment(tctx, "Setup wrepl connections\n");
- status = wrepl_connect(wrepl_socket, lp_resolve_context(tctx->lp_ctx), wrepl_best_ip(tctx->lp_ctx, address), address);
+ status = wrepl_connect(wrepl_socket, wrepl_best_ip(tctx->lp_ctx, address), address);
CHECK_STATUS(tctx, status, NT_STATUS_OK);
torture_comment(tctx, "Send 1st start association request\n");
torture_comment(tctx, "Test one pull replication cycle\n");
- wrepl_socket = wrepl_socket_init(tctx, NULL, lp_iconv_convenience(tctx->lp_ctx));
+ wrepl_socket = wrepl_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
torture_comment(tctx, "Setup wrepl connections\n");
- status = wrepl_connect(wrepl_socket, lp_resolve_context(tctx->lp_ctx), wrepl_best_ip(tctx->lp_ctx, address), address);
+ status = wrepl_connect(wrepl_socket, wrepl_best_ip(tctx->lp_ctx, address), address);
CHECK_STATUS(tctx, status, NT_STATUS_OK);
torture_comment(tctx, "Send a start association request\n");
if (!ctx) return NULL;
ctx->address = address;
- ctx->pull = wrepl_socket_init(ctx, NULL, lp_iconv_convenience(tctx->lp_ctx));
+ ctx->pull = wrepl_socket_init(ctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
if (!ctx->pull) return NULL;
torture_comment(tctx, "Setup wrepl conflict pull connection\n");
- status = wrepl_connect(ctx->pull, lp_resolve_context(tctx->lp_ctx), wrepl_best_ip(tctx->lp_ctx, ctx->address), ctx->address);
+ status = wrepl_connect(ctx->pull, wrepl_best_ip(tctx->lp_ctx, ctx->address), ctx->address);
if (!NT_STATUS_IS_OK(status)) return NULL;
status = wrepl_associate(ctx->pull, &associate);
talloc_free(pull_table.out.partners);
- ctx->nbtsock = nbt_name_socket_init(ctx, NULL, lp_iconv_convenience(tctx->lp_ctx));
+ ctx->nbtsock = nbt_name_socket_init(ctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
if (!ctx->nbtsock) return NULL;
load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces);
status = socket_listen(ctx->nbtsock->sock, ctx->myaddr, 0, 0);
if (!NT_STATUS_IS_OK(status)) return NULL;
- ctx->nbtsock_srv = nbt_name_socket_init(ctx, NULL, lp_iconv_convenience(tctx->lp_ctx));
+ ctx->nbtsock_srv = nbt_name_socket_init(ctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
if (!ctx->nbtsock_srv) return NULL;
/* Make a port 137 version of ctx->myaddr */
}
if (ctx->myaddr2 && ctx->nbtsock_srv) {
- ctx->nbtsock2 = nbt_name_socket_init(ctx, NULL, lp_iconv_convenience(tctx->lp_ctx));
+ ctx->nbtsock2 = nbt_name_socket_init(ctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
if (!ctx->nbtsock2) return NULL;
status = socket_listen(ctx->nbtsock2->sock, ctx->myaddr2, 0, 0);
uint32_t assoc_ctx;
NTSTATUS status;
- wrepl_socket = wrepl_socket_init(ctx, NULL, lp_iconv_convenience(tctx->lp_ctx));
+ wrepl_socket = wrepl_socket_init(ctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
- status = wrepl_connect(wrepl_socket, lp_resolve_context(tctx->lp_ctx), wrepl_best_ip(tctx->lp_ctx, ctx->address), ctx->address);
+ status = wrepl_connect(wrepl_socket, wrepl_best_ip(tctx->lp_ctx, ctx->address), ctx->address);
CHECK_STATUS(tctx, status, NT_STATUS_OK);
status = wrepl_associate(wrepl_socket, &associate);
names[0].state,
names[0].node,
names[0].is_static);
+ char *expected_scope = NULL;
CHECK_VALUE(tctx, names[0].name.type, name->name->type);
CHECK_VALUE_STRING(tctx, names[0].name.name, name->name->name);
- CHECK_VALUE_STRING(tctx, names[0].name.scope, name->name->scope);
+
+ if (names[0].name.scope) {
+ expected_scope = talloc_strndup(tctx,
+ name->name->scope,
+ 237);
+ }
+ CHECK_VALUE_STRING(tctx, names[0].name.scope, expected_scope);
CHECK_VALUE(tctx, flags, name->flags);
CHECK_VALUE_UINT64(tctx, names[0].version_id, name->id);
return true;
}
+static char *test_nbt_winsrepl_scope_string(TALLOC_CTX *mem_ctx, uint8_t count)
+{
+ char *res;
+ uint8_t i;
+
+ res = talloc_array(mem_ctx, char, count+1);
+ if (res == NULL) {
+ return NULL;
+ }
+
+ for (i=0; i < count; i++) {
+ res[i] = '0' + (i%10);
+ }
+
+ res[count] = '\0';
+
+ talloc_set_name_const(res, res);
+
+ return res;
+}
+
static bool test_conflict_same_owner(struct torture_context *tctx,
struct test_wrepl_conflict_conn *ctx)
{
static bool ret = true;
- struct nbt_name name;
struct wrepl_wins_name wins_name1;
struct wrepl_wins_name wins_name2;
struct wrepl_wins_name *wins_name_tmp;
struct wrepl_wins_name *wins_name_last;
struct wrepl_wins_name *wins_name_cur;
uint32_t i,j;
- uint8_t types[] = { 0x00, 0x1C };
+ struct nbt_name names[] = {
+ _NBT_NAME("_SAME_OWNER_A", 0x00, NULL),
+ _NBT_NAME("_SAME_OWNER_A", 0x00,
+ test_nbt_winsrepl_scope_string(tctx, 1)),
+ _NBT_NAME("_SAME_OWNER_A", 0x00,
+ test_nbt_winsrepl_scope_string(tctx, 2)),
+ _NBT_NAME("_SAME_OWNER_A", 0x00,
+ test_nbt_winsrepl_scope_string(tctx, 3)),
+ _NBT_NAME("_SAME_OWNER_A", 0x00,
+ test_nbt_winsrepl_scope_string(tctx, 4)),
+ _NBT_NAME("_SAME_OWNER_A", 0x00,
+ test_nbt_winsrepl_scope_string(tctx, 5)),
+ _NBT_NAME("_SAME_OWNER_A", 0x00,
+ test_nbt_winsrepl_scope_string(tctx, 6)),
+ _NBT_NAME("_SAME_OWNER_A", 0x00,
+ test_nbt_winsrepl_scope_string(tctx, 7)),
+ _NBT_NAME("_SAME_OWNER_A", 0x00,
+ test_nbt_winsrepl_scope_string(tctx, 8)),
+ _NBT_NAME("_SAME_OWNER_A", 0x00,
+ test_nbt_winsrepl_scope_string(tctx, 9)),
+ _NBT_NAME("_SAME_OWNER_A", 0x00,
+ test_nbt_winsrepl_scope_string(tctx, 237)),
+ _NBT_NAME("_SAME_OWNER_A", 0x00,
+ test_nbt_winsrepl_scope_string(tctx, 238)),
+ _NBT_NAME("_SAME_OWNER_A", 0x1C, NULL),
+ };
struct {
enum wrepl_name_type type;
enum wrepl_name_state state;
}
};
- name.name = "_SAME_OWNER_A";
- name.type = 0;
- name.scope = NULL;
-
wins_name_tmp = NULL;
wins_name_last = &wins_name2;
wins_name_cur = &wins_name1;
- for (j=0; ret && j < ARRAY_SIZE(types); j++) {
- name.type = types[j];
+ for (j=0; ret && j < ARRAY_SIZE(names); j++) {
torture_comment(tctx, "Test Replica Conflicts with same owner[%s] for %s\n",
- nbt_name_string(ctx, &name), ctx->a.address);
+ nbt_name_string(ctx, &names[j]), ctx->a.address);
for(i=0; ret && i < ARRAY_SIZE(records); i++) {
wins_name_tmp = wins_name_last;
"REPLACE");
}
- wins_name_cur->name = &name;
+ wins_name_cur->name = &names[j];
wins_name_cur->flags = WREPL_NAME_FLAGS(records[i].type,
records[i].state,
records[i].node,
wins_name_cur->id = ++ctx->a.max_version;
if (wins_name_cur->flags & 2) {
wins_name_cur->addresses.addresses.num_ips = records[i].num_ips;
- wins_name_cur->addresses.addresses.ips = discard_const(records[i].ips);
+ wins_name_cur->addresses.addresses.ips = discard_const_p(struct wrepl_ip,
+ records[i].ips);
} else {
wins_name_cur->addresses.ip = records[i].ips[0].ip;
}
wins_name_r1->id = ++records[i].r1.owner->max_version;
if (wins_name_r1->flags & 2) {
wins_name_r1->addresses.addresses.num_ips = records[i].r1.num_ips;
- wins_name_r1->addresses.addresses.ips = discard_const(records[i].r1.ips);
+ wins_name_r1->addresses.addresses.ips = discard_const_p(struct wrepl_ip,
+ records[i].r1.ips);
} else {
wins_name_r1->addresses.ip = records[i].r1.ips[0].ip;
}
wins_name_r2->id = ++records[i].r2.owner->max_version;
if (wins_name_r2->flags & 2) {
wins_name_r2->addresses.addresses.num_ips = records[i].r2.num_ips;
- wins_name_r2->addresses.addresses.ips = discard_const(records[i].r2.ips);
+ wins_name_r2->addresses.addresses.ips = discard_const_p(struct wrepl_ip,
+ records[i].r2.ips);
} else {
wins_name_r2->addresses.ip = records[i].r2.ips[0].ip;
}
WREPL_NODE_B, false);
wins_name_r2->id = ++records[i].r2.owner->max_version;
wins_name_r2->addresses.addresses.num_ips = ARRAY_SIZE(addresses_B_1);
- wins_name_r2->addresses.addresses.ips = discard_const(addresses_B_1);
+ wins_name_r2->addresses.addresses.ips = discard_const_p(struct wrepl_ip,
+ addresses_B_1);
wins_name_r2->unknown = "255.255.255.255";
ret &= test_wrepl_update_one(tctx, ctx, records[i].r2.owner, wins_name_r2);
ret &= test_wrepl_is_applied(tctx, ctx, records[i].r2.owner, wins_name_r2, true);
WREPL_NODE_B, false);
wins_name_r2->id = ++records[i].r2.owner->max_version;
wins_name_r2->addresses.addresses.num_ips = ARRAY_SIZE(addresses_B_1);
- wins_name_r2->addresses.addresses.ips = discard_const(addresses_B_1);
+ wins_name_r2->addresses.addresses.ips = discard_const_p(struct wrepl_ip,
+ addresses_B_1);
wins_name_r2->unknown = "255.255.255.255";
ret &= test_wrepl_update_one(tctx, ctx, records[i].r2.owner, wins_name_r2);
ret &= test_wrepl_is_applied(tctx, ctx, records[i].r2.owner, wins_name_r2, true);
wins_name->id = ++ctx->b.max_version;
if (wins_name->flags & 2) {
wins_name->addresses.addresses.num_ips = records[i].replica.num_ips;
- wins_name->addresses.addresses.ips = discard_const(records[i].replica.ips);
+ wins_name->addresses.addresses.ips = discard_const_p(struct wrepl_ip,
+ records[i].replica.ips);
} else {
wins_name->addresses.ip = records[i].replica.ips[0].ip;
}
/*
* unique vs. unique section
*/
-#if METZE_NEEDS_TO_LOOK_AT_THIS_ONE
/*
* unique,active vs. unique,active with same ip(s), unchecked
*/
.apply_expected = true
},
},
-#endif
/*
* unique,active vs. unique,active with different ip(s), positive response
*/
.sgroup_merge = true
},
},
-#if 0
/*
* sgroup,active vs. sgroup,active with same ip(s)
*/
.apply_expected = false
},
},
-#endif
};
if (!ctx->nbtsock_srv) {
wins_name->id = ++ctx->b.max_version;
if (wins_name->flags & 2) {
wins_name->addresses.addresses.num_ips = records[i].replica.num_ips;
- wins_name->addresses.addresses.ips = discard_const(records[i].replica.ips);
+ wins_name->addresses.addresses.ips = discard_const_p(struct wrepl_ip,
+ records[i].replica.ips);
} else {
wins_name->addresses.ip = records[i].replica.ips[0].ip;
}
WREPL_NODE_B, false);
wins_name->id = ++ctx->b.max_version;
wins_name->addresses.addresses.num_ips = ARRAY_SIZE(addresses_B_1);
- wins_name->addresses.addresses.ips = discard_const(addresses_B_1);
+ wins_name->addresses.addresses.ips = discard_const_p(struct wrepl_ip,
+ addresses_B_1);
wins_name->unknown = "255.255.255.255";
ret &= test_wrepl_update_one(tctx, ctx, &ctx->b, wins_name);
ret &= test_wrepl_is_applied(tctx, ctx, &ctx->b, wins_name, true);
struct nbt_name *name;
struct nbt_name_packet *rep_packet;
struct test_conflict_owned_active_vs_replica_struct *rec =
- (struct test_conflict_owned_active_vs_replica_struct *)nbtsock->incoming.private;
+ (struct test_conflict_owned_active_vs_replica_struct *)nbtsock->incoming.private_data;
_NBT_ASSERT(req_packet->qdcount, 1);
_NBT_ASSERT(req_packet->questions[0].question_type, NBT_QTYPE_NETBIOS);
talloc_free(rep_packet);
/* make sure we push the reply to the wire */
- event_loop_once(nbtsock->event_ctx);
+ while (nbtsock->send_queue) {
+ event_loop_once(nbtsock->event_ctx);
+ }
msleep(1000);
rec->defend.timeout = 0;
struct nbt_name *name;
struct nbt_name_packet *rep_packet;
struct test_conflict_owned_active_vs_replica_struct *rec =
- (struct test_conflict_owned_active_vs_replica_struct *)nbtsock->incoming.private;
+ (struct test_conflict_owned_active_vs_replica_struct *)nbtsock->incoming.private_data;
_NBT_ASSERT(req_packet->qdcount, 1);
_NBT_ASSERT(req_packet->questions[0].question_type, NBT_QTYPE_NETBIOS);
talloc_free(rep_packet);
/* make sure we push the reply to the wire */
- event_loop_once(nbtsock->event_ctx);
+ while (nbtsock->send_queue) {
+ event_loop_once(nbtsock->event_ctx);
+ }
msleep(1000);
rec->defend.timeout = 0;
struct socket_address *src)
{
struct test_conflict_owned_active_vs_replica_struct *rec =
- (struct test_conflict_owned_active_vs_replica_struct *)nbtsock->incoming.private;
+ (struct test_conflict_owned_active_vs_replica_struct *)nbtsock->incoming.private_data;
rec->defend.ret = false;