diff options
author | Andrew Bartlett <abartlet@samba.org> | 2006-01-09 22:12:53 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:49:57 -0500 |
commit | f55ea8bb3dca868e21663cd90eaea7a35cd7886c (patch) | |
tree | 80aab2a3f10310e1946821603752cd407e435214 /source4/torture | |
parent | 806b3fdbc12b3284ab9872a4ecae3a7ee34ea171 (diff) | |
download | samba-f55ea8bb3dca868e21663cd90eaea7a35cd7886c.tar.gz samba-f55ea8bb3dca868e21663cd90eaea7a35cd7886c.tar.bz2 samba-f55ea8bb3dca868e21663cd90eaea7a35cd7886c.zip |
r12804: This patch reworks the Samba4 sockets layer to use a socket_address
structure that is more generic than just 'IP/port'.
It now passes make test, and has been reviewed and updated by
metze. (Thankyou *very* much).
This passes 'make test' as well as kerberos use (not currently in the
testsuite).
The original purpose of this patch was to have Samba able to pass a
socket address stucture from the BSD layer into the kerberos routines
and back again. It also removes nbt_peer_addr, which was being used
for a similar purpose.
It is a large change, but worthwhile I feel.
Andrew Bartlett
(This used to be commit 88198c4881d8620a37086f80e4da5a5b71c5bbb2)
Diffstat (limited to 'source4/torture')
-rw-r--r-- | source4/torture/local/messaging.c | 33 | ||||
-rw-r--r-- | source4/torture/local/socket.c | 85 | ||||
-rw-r--r-- | source4/torture/nbt/dgram.c | 116 | ||||
-rw-r--r-- | source4/torture/nbt/register.c | 30 | ||||
-rw-r--r-- | source4/torture/nbt/wins.c | 15 | ||||
-rw-r--r-- | source4/torture/nbt/winsbench.c | 6 | ||||
-rw-r--r-- | source4/torture/nbt/winsreplication.c | 59 |
7 files changed, 239 insertions, 105 deletions
diff --git a/source4/torture/local/messaging.c b/source4/torture/local/messaging.c index faba8304d7..0d4dfc49a8 100644 --- a/source4/torture/local/messaging.c +++ b/source4/torture/local/messaging.c @@ -56,8 +56,8 @@ static void exit_message(struct messaging_context *msg, void *private, static BOOL test_ping_speed(TALLOC_CTX *mem_ctx) { struct event_context *ev; - struct messaging_context *msg_ctx; - struct messaging_context *msg_ctx2; + struct messaging_context *msg_client_ctx; + struct messaging_context *msg_server_ctx; int ping_count = 0; int pong_count = 0; BOOL ret = True; @@ -68,23 +68,25 @@ static BOOL test_ping_speed(TALLOC_CTX *mem_ctx) ev = event_context_init(mem_ctx); - msg_ctx2 = messaging_init(mem_ctx, 1, ev); + msg_server_ctx = messaging_init(mem_ctx, 1, ev); - if (!msg_ctx2) { - exit(1); + if (!msg_server_ctx) { + printf("Failed to init ping messaging context\n"); + talloc_free(mem_ctx); + return False; } - messaging_register(msg_ctx2, NULL, MY_PING, ping_message); - messaging_register(msg_ctx2, mem_ctx, MY_EXIT, exit_message); + messaging_register(msg_server_ctx, NULL, MY_PING, ping_message); + messaging_register(msg_server_ctx, mem_ctx, MY_EXIT, exit_message); - msg_ctx = messaging_init(mem_ctx, 2, ev); + msg_client_ctx = messaging_init(mem_ctx, 2, ev); - if (!msg_ctx) { - printf("messaging_init() failed\n"); + if (!msg_client_ctx) { + printf("msg_client_ctx messaging_init() failed\n"); return False; } - messaging_register(msg_ctx, &pong_count, MY_PONG, pong_message); + messaging_register(msg_client_ctx, &pong_count, MY_PONG, pong_message); tv = timeval_current(); @@ -96,8 +98,8 @@ static BOOL test_ping_speed(TALLOC_CTX *mem_ctx) data.data = discard_const_p(uint8_t, "testing"); data.length = strlen((const char *)data.data); - status1 = messaging_send(msg_ctx, 1, MY_PING, &data); - status2 = messaging_send(msg_ctx, 1, MY_PING, NULL); + status1 = messaging_send(msg_client_ctx, 1, MY_PING, &data); + status2 = messaging_send(msg_client_ctx, 1, MY_PING, NULL); if (!NT_STATUS_IS_OK(status1)) { printf("msg1 failed - %s\n", nt_errstr(status1)); @@ -123,7 +125,7 @@ static BOOL test_ping_speed(TALLOC_CTX *mem_ctx) } printf("sending exit\n"); - messaging_send(msg_ctx, 1, MY_EXIT, NULL); + messaging_send(msg_client_ctx, 1, MY_EXIT, NULL); if (ping_count != pong_count) { printf("ping test failed! received %d, sent %d\n", @@ -134,7 +136,8 @@ static BOOL test_ping_speed(TALLOC_CTX *mem_ctx) printf("ping rate of %.0f messages/sec\n", (ping_count+pong_count)/timeval_elapsed(&tv)); - talloc_free(msg_ctx); + talloc_free(msg_client_ctx); + talloc_free(msg_server_ctx); talloc_free(ev); diff --git a/source4/torture/local/socket.c b/source4/torture/local/socket.c index 4a3a339333..195354611f 100644 --- a/source4/torture/local/socket.c +++ b/source4/torture/local/socket.c @@ -40,8 +40,7 @@ static BOOL test_udp(TALLOC_CTX *mem_ctx) { struct socket_context *sock1, *sock2; NTSTATUS status; - int srv_port, from_port; - const char *srv_addr, *from_addr; + struct socket_address *srv_addr, *from_addr, *localhost; size_t size = 100 + (random() % 100); DATA_BLOB blob, blob2; size_t sent, nread; @@ -57,33 +56,38 @@ static BOOL test_udp(TALLOC_CTX *mem_ctx) CHECK_STATUS(status, NT_STATUS_OK); talloc_steal(mem_ctx, sock2); - status = socket_listen(sock1, iface_best_ip("127.0.0.1"), 0, 0, 0); + localhost = socket_address_from_strings(sock1, sock1->backend_name, + iface_best_ip("127.0.0.1"), 0); + if (!localhost) { + return False; + } + + status = socket_listen(sock1, localhost, 0, 0); CHECK_STATUS(status, NT_STATUS_OK); srv_addr = socket_get_my_addr(sock1, mem_ctx); - if (srv_addr == NULL || strcmp(srv_addr, iface_best_ip("127.0.0.1")) != 0) { + if (srv_addr == NULL || strcmp(srv_addr->addr, iface_best_ip("127.0.0.1")) != 0) { printf("Expected server address of %s but got %s\n", - iface_best_ip("127.0.0.1"), srv_addr); + iface_best_ip("127.0.0.1"), srv_addr ? srv_addr->addr : NULL); return False; } - srv_port = socket_get_my_port(sock1); - printf("server port is %d\n", srv_port); + printf("server port is %d\n", srv_addr->port); blob = data_blob_talloc(mem_ctx, NULL, size); blob2 = data_blob_talloc(mem_ctx, NULL, size); generate_random_buffer(blob.data, blob.length); sent = size; - status = socket_sendto(sock2, &blob, &sent, 0, srv_addr, srv_port); + status = socket_sendto(sock2, &blob, &sent, 0, srv_addr); CHECK_STATUS(status, NT_STATUS_OK); status = socket_recvfrom(sock1, blob2.data, size, &nread, 0, - &from_addr, &from_port); + sock1, &from_addr); CHECK_STATUS(status, NT_STATUS_OK); - if (strcmp(from_addr, srv_addr) != 0) { - printf("Unexpected recvfrom addr %s\n", from_addr); + if (strcmp(from_addr->addr, srv_addr->addr) != 0) { + printf("Unexpected recvfrom addr %s\n", from_addr->addr); ret = False; } if (nread != size) { @@ -97,23 +101,23 @@ static BOOL test_udp(TALLOC_CTX *mem_ctx) } generate_random_buffer(blob.data, blob.length); - status = socket_sendto(sock1, &blob, &sent, 0, from_addr, from_port); + status = socket_sendto(sock1, &blob, &sent, 0, from_addr); CHECK_STATUS(status, NT_STATUS_OK); status = socket_recvfrom(sock2, blob2.data, size, &nread, 0, - &from_addr, &from_port); + sock2, &from_addr); CHECK_STATUS(status, NT_STATUS_OK); - if (strcmp(from_addr, srv_addr) != 0) { - printf("Unexpected recvfrom addr %s\n", from_addr); + if (strcmp(from_addr->addr, srv_addr->addr) != 0) { + printf("Unexpected recvfrom addr %s\n", from_addr->addr); ret = False; } if (nread != size) { printf("Unexpected recvfrom size %d should be %d\n", (int)nread, (int)size); ret = False; } - if (from_port != srv_port) { + if (from_addr->port != srv_addr->port) { printf("Unexpected recvfrom port %d should be %d\n", - from_port, srv_port); + from_addr->port, srv_addr->port); ret = False; } if (memcmp(blob2.data, blob.data, size) != 0) { @@ -135,8 +139,7 @@ static BOOL test_tcp(TALLOC_CTX *mem_ctx) { struct socket_context *sock1, *sock2, *sock3; NTSTATUS status; - int srv_port, from_port; - const char *srv_addr, *from_addr; + struct socket_address *srv_addr, *from_addr, *localhost; size_t size = 100 + (random() % 100); DATA_BLOB blob, blob2; size_t sent, nread; @@ -153,20 +156,30 @@ static BOOL test_tcp(TALLOC_CTX *mem_ctx) CHECK_STATUS(status, NT_STATUS_OK); talloc_steal(mem_ctx, sock2); - status = socket_listen(sock1, iface_best_ip("127.0.0.1"), 0, 0, 0); + localhost = socket_address_from_strings(sock1, sock1->backend_name, + iface_best_ip("127.0.0.1"), 0); + if (!localhost) { + return False; + } + + status = socket_listen(sock1, localhost, 0, 0); CHECK_STATUS(status, NT_STATUS_OK); srv_addr = socket_get_my_addr(sock1, mem_ctx); - if (srv_addr == NULL || strcmp(srv_addr, iface_best_ip("127.0.0.1")) != 0) { + if (srv_addr == NULL || !srv_addr->addr) { + printf("Unexpected socket_get_my_addr NULL\n"); + return False; + } + + if (strcmp(srv_addr->addr, iface_best_ip("127.0.0.1")) != 0) { printf("Expected server address of %s but got %s\n", - iface_best_ip("127.0.0.1"), srv_addr); + iface_best_ip("127.0.0.1"), srv_addr ? srv_addr->addr : NULL); return False; } - srv_port = socket_get_my_port(sock1); - printf("server port is %d\n", srv_port); + printf("server port is %d\n", srv_addr->port); - status = socket_connect_ev(sock2, NULL, 0, srv_addr, srv_port, 0, ev); + status = socket_connect_ev(sock2, NULL, srv_addr, 0, ev); CHECK_STATUS(status, NT_STATUS_OK); status = socket_accept(sock1, &sock3); @@ -186,10 +199,13 @@ static BOOL test_tcp(TALLOC_CTX *mem_ctx) CHECK_STATUS(status, NT_STATUS_OK); from_addr = socket_get_peer_addr(sock3, mem_ctx); - from_port = socket_get_peer_port(sock3); - if (strcmp(from_addr, srv_addr) != 0) { - printf("Unexpected recvfrom addr %s\n", from_addr); + if (!from_addr || !from_addr->addr) { + printf("Unexpected recvfrom addr NULL\n"); + return False; + } + if (strcmp(from_addr->addr, srv_addr->addr) != 0) { + printf("Unexpected recvfrom addr %s\n", from_addr ? from_addr->addr : NULL); ret = False; } if (nread != size) { @@ -210,19 +226,22 @@ static BOOL test_tcp(TALLOC_CTX *mem_ctx) CHECK_STATUS(status, NT_STATUS_OK); from_addr = socket_get_peer_addr(sock2, mem_ctx); - from_port = socket_get_peer_port(sock2); - if (strcmp(from_addr, srv_addr) != 0) { - printf("Unexpected recvfrom addr %s\n", from_addr); + if (!from_addr || !from_addr->addr) { + printf("Unexpected recvfrom addr NULL\n"); + return False; + } + if (strcmp(from_addr->addr, srv_addr->addr) != 0) { + printf("Unexpected recvfrom addr %s\n", from_addr ? from_addr->addr : NULL); ret = False; } if (nread != size) { printf("Unexpected recvfrom size %d should be %d\n", (int)nread, (int)size); ret = False; } - if (from_port != srv_port) { + if (from_addr->port != srv_addr->port) { printf("Unexpected recvfrom port %d should be %d\n", - from_port, srv_port); + from_addr->port, srv_addr->port); ret = False; } if (memcmp(blob2.data, blob.data, size) != 0) { diff --git a/source4/torture/nbt/dgram.c b/source4/torture/nbt/dgram.c index 64d4825edc..821a169314 100644 --- a/source4/torture/nbt/dgram.c +++ b/source4/torture/nbt/dgram.c @@ -33,7 +33,7 @@ */ static void netlogon_handler(struct dgram_mailslot_handler *dgmslot, struct nbt_dgram_packet *packet, - const struct nbt_peer_socket *src) + struct socket_address *src) { NTSTATUS status; struct nbt_netlogon_packet netlogon; @@ -60,7 +60,7 @@ static BOOL nbt_test_netlogon(TALLOC_CTX *mem_ctx, { struct dgram_mailslot_handler *dgmslot; struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(mem_ctx, NULL); - struct nbt_peer_socket dest; + struct socket_address *dest; const char *myaddress = talloc_strdup(dgmsock, iface_best_ip(address)); struct nbt_netlogon_packet logon; struct nbt_name myname; @@ -68,13 +68,28 @@ static BOOL nbt_test_netlogon(TALLOC_CTX *mem_ctx, struct timeval tv = timeval_current(); int replies = 0; + struct socket_address *socket_address; + + socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, + myaddress, lp_dgram_port()); + if (!socket_address) { + return False; + } + /* try receiving replies on port 138 first, which will only work if we are root and smbd/nmbd are not running - fall back to listening on any port, which means replies from some windows versions won't be seen */ - status = socket_listen(dgmsock->sock, myaddress, lp_dgram_port(), 0, 0); + status = socket_listen(dgmsock->sock, socket_address, 0, 0); if (!NT_STATUS_IS_OK(status)) { - socket_listen(dgmsock->sock, myaddress, 0, 0, 0); + talloc_free(socket_address); + socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, + myaddress, 0); + if (!socket_address) { + return False; + } + + socket_listen(dgmsock->sock, socket_address, 0, 0); } /* setup a temporary mailslot listener for replies */ @@ -92,9 +107,13 @@ static BOOL nbt_test_netlogon(TALLOC_CTX *mem_ctx, make_nbt_name_client(&myname, TEST_NAME); - dest.port = 0; - dest.addr = address; - status = dgram_mailslot_netlogon_send(dgmsock, &name, &dest, + dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, + address, 0); + if (!dest) { + return False; + } + + status = dgram_mailslot_netlogon_send(dgmsock, &name, dest, &myname, &logon); if (!NT_STATUS_IS_OK(status)) { printf("Failed to send netlogon request - %s\n", nt_errstr(status)); @@ -120,7 +139,7 @@ static BOOL nbt_test_netlogon2(TALLOC_CTX *mem_ctx, { struct dgram_mailslot_handler *dgmslot; struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(mem_ctx, NULL); - struct nbt_peer_socket dest; + struct socket_address *dest; const char *myaddress = talloc_strdup(dgmsock, iface_best_ip(address)); struct nbt_netlogon_packet logon; struct nbt_name myname; @@ -128,13 +147,28 @@ static BOOL nbt_test_netlogon2(TALLOC_CTX *mem_ctx, struct timeval tv = timeval_current(); int replies = 0; + struct socket_address *socket_address; + + socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, + myaddress, lp_dgram_port()); + if (!socket_address) { + return False; + } + /* try receiving replies on port 138 first, which will only work if we are root and smbd/nmbd are not running - fall back to listening on any port, which means replies from some windows versions won't be seen */ - status = socket_listen(dgmsock->sock, myaddress, lp_dgram_port(), 0, 0); + status = socket_listen(dgmsock->sock, socket_address, 0, 0); if (!NT_STATUS_IS_OK(status)) { - socket_listen(dgmsock->sock, myaddress, 0, 0, 0); + talloc_free(socket_address); + socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, + myaddress, 0); + if (!socket_address) { + return False; + } + + socket_listen(dgmsock->sock, socket_address, 0, 0); } /* setup a temporary mailslot listener for replies */ @@ -154,9 +188,12 @@ static BOOL nbt_test_netlogon2(TALLOC_CTX *mem_ctx, make_nbt_name_client(&myname, TEST_NAME); - dest.port = 0; - dest.addr = address; - status = dgram_mailslot_netlogon_send(dgmsock, &name, &dest, + dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, + address, 0); + if (!dest) { + goto failed; + } + status = dgram_mailslot_netlogon_send(dgmsock, &name, dest, &myname, &logon); if (!NT_STATUS_IS_OK(status)) { printf("Failed to send netlogon request - %s\n", nt_errstr(status)); @@ -182,7 +219,7 @@ failed: */ static void ntlogon_handler(struct dgram_mailslot_handler *dgmslot, struct nbt_dgram_packet *packet, - const struct nbt_peer_socket *src) + struct socket_address *src) { NTSTATUS status; struct nbt_ntlogon_packet ntlogon; @@ -209,36 +246,52 @@ static BOOL nbt_test_ntlogon(TALLOC_CTX *mem_ctx, { struct dgram_mailslot_handler *dgmslot; struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(mem_ctx, NULL); - struct nbt_peer_socket dest; + struct socket_address *dest; + struct test_join *join_ctx; + struct cli_credentials *machine_credentials; + const char *dom_sid; + const char *myaddress = talloc_strdup(dgmsock, iface_best_ip(address)); struct nbt_ntlogon_packet logon; struct nbt_name myname; NTSTATUS status; struct timeval tv = timeval_current(); int replies = 0; - struct test_join *join_ctx; - struct cli_credentials *machine_credentials; - const char *dom_sid; - join_ctx = torture_join_domain(TEST_NAME, - ACB_WSTRUST, &machine_credentials); - if (join_ctx == NULL) { - printf("Failed to join domain %s as %s\n", lp_workgroup(), TEST_NAME); - talloc_free(dgmsock); + struct socket_address *socket_address; + + socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, + myaddress, lp_dgram_port()); + if (!socket_address) { return False; } - dom_sid = torture_join_sid(join_ctx); - /* try receiving replies on port 138 first, which will only work if we are root and smbd/nmbd are not running - fall back to listening on any port, which means replies from some windows versions won't be seen */ - status = socket_listen(dgmsock->sock, myaddress, lp_dgram_port(), 0, 0); + status = socket_listen(dgmsock->sock, socket_address, 0, 0); if (!NT_STATUS_IS_OK(status)) { - socket_listen(dgmsock->sock, myaddress, 0, 0, 0); + talloc_free(socket_address); + socket_address = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, + myaddress, 0); + if (!socket_address) { + return False; + } + + socket_listen(dgmsock->sock, socket_address, 0, 0); + } + + join_ctx = torture_join_domain(TEST_NAME, + ACB_WSTRUST, &machine_credentials); + if (join_ctx == NULL) { + printf("Failed to join domain %s as %s\n", lp_workgroup(), TEST_NAME); + talloc_free(dgmsock); + return False; } + dom_sid = torture_join_sid(join_ctx); + /* setup a temporary mailslot listener for replies */ dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC, ntlogon_handler, &replies); @@ -258,10 +311,13 @@ static BOOL nbt_test_ntlogon(TALLOC_CTX *mem_ctx, make_nbt_name_client(&myname, TEST_NAME); - dest.port = 0; - dest.addr = address; + dest = socket_address_from_strings(dgmsock, dgmsock->sock->backend_name, + address, 0); + if (!dest) { + goto failed; + } status = dgram_mailslot_ntlogon_send(dgmsock, DGRAM_DIRECT_UNIQUE, - &name, &dest, &myname, &logon); + &name, dest, &myname, &logon); if (!NT_STATUS_IS_OK(status)) { printf("Failed to send ntlogon request - %s\n", nt_errstr(status)); goto failed; diff --git a/source4/torture/nbt/register.c b/source4/torture/nbt/register.c index 8cbceb8e30..cd7d3c7624 100644 --- a/source4/torture/nbt/register.c +++ b/source4/torture/nbt/register.c @@ -48,8 +48,19 @@ static BOOL nbt_register_own(TALLOC_CTX *mem_ctx, struct nbt_name *name, struct nbt_name_socket *nbtsock = nbt_name_socket_init(mem_ctx, NULL); BOOL ret = True; const char *myaddress = iface_best_ip(address); + struct socket_address *socket_address; - socket_listen(nbtsock->sock, myaddress, 0, 0, 0); + socket_address = socket_address_from_strings(mem_ctx, nbtsock->sock->backend_name, + myaddress, 0); + if (!socket_address) { + return False; + } + + status = socket_listen(nbtsock->sock, socket_address, 0, 0); + if (!NT_STATUS_IS_OK(status)) { + printf("socket_listen for nbt_register_own failed: %s\n", nt_errstr(status)); + return False; + } printf("Testing name defense to name registration\n"); @@ -85,11 +96,11 @@ static BOOL nbt_register_own(TALLOC_CTX *mem_ctx, struct nbt_name *name, status = nbt_name_register(nbtsock, mem_ctx, &io); if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { - printf("No response from %s for name register\n", address); + printf("No response from %s for name register demand\n", address); return False; } if (!NT_STATUS_IS_OK(status)) { - printf("Bad response from %s for name register - %s\n", + printf("Bad response from %s for name register demand - %s\n", address, nt_errstr(status)); return False; } @@ -113,8 +124,19 @@ static BOOL nbt_refresh_own(TALLOC_CTX *mem_ctx, struct nbt_name *name, struct nbt_name_socket *nbtsock = nbt_name_socket_init(mem_ctx, NULL); BOOL ret = True; const char *myaddress = iface_best_ip(address); + struct socket_address *socket_address; + + socket_address = socket_address_from_strings(mem_ctx, nbtsock->sock->backend_name, + myaddress, 0); + if (!socket_address) { + return False; + } - socket_listen(nbtsock->sock, myaddress, 0, 0, 0); + status = socket_listen(nbtsock->sock, socket_address, 0, 0); + if (!NT_STATUS_IS_OK(status)) { + printf("socket_listen for nbt_referesh_own failed: %s\n", nt_errstr(status)); + return False; + } printf("Testing name defense to name refresh\n"); diff --git a/source4/torture/nbt/wins.c b/source4/torture/nbt/wins.c index 37e9688a60..bcb52dc9b8 100644 --- a/source4/torture/nbt/wins.c +++ b/source4/torture/nbt/wins.c @@ -59,10 +59,23 @@ static BOOL nbt_test_wins_name(TALLOC_CTX *mem_ctx, const char *address, struct nbt_name_socket *nbtsock = nbt_name_socket_init(mem_ctx, NULL); BOOL ret = True; const char *myaddress = talloc_strdup(mem_ctx, iface_best_ip(address)); + struct socket_address *socket_address; + + socket_address = socket_address_from_strings(mem_ctx, + nbtsock->sock->backend_name, + myaddress, 0); + if (!socket_address) { + return False; + } /* we do the listen here to ensure the WINS server receives the packets from the right IP */ - socket_listen(nbtsock->sock, myaddress, 0, 0, 0); + status = socket_listen(nbtsock->sock, socket_address, 0, 0); + if (!NT_STATUS_IS_OK(status)) { + printf("socket_listen for WINS failed: %s\n", nt_errstr(status)); + return False; + } + talloc_free(socket_address); printf("Testing name registration to WINS with name %s at %s nb_flags=0x%x\n", nbt_name_string(mem_ctx, name), myaddress, nb_flags); diff --git a/source4/torture/nbt/winsbench.c b/source4/torture/nbt/winsbench.c index 65f494184f..5aa97f9ade 100644 --- a/source4/torture/nbt/winsbench.c +++ b/source4/torture/nbt/winsbench.c @@ -223,6 +223,7 @@ static BOOL bench_wins(TALLOC_CTX *mem_ctx, struct nbt_name *name, const char *a int timelimit = lp_parm_int(-1, "torture", "timelimit", 10); struct wins_state *state; extern int torture_entries; + struct socket_address *my_ip; state = talloc_zero(nbtsock, struct wins_state); @@ -232,7 +233,10 @@ static BOOL bench_wins(TALLOC_CTX *mem_ctx, struct nbt_name *name, const char *a state->my_ip = talloc_strdup(mem_ctx, iface_best_ip(address)); state->ttl = timelimit; - socket_listen(nbtsock->sock, state->my_ip, 0, 0, 0); + my_ip = socket_address_from_strings(nbtsock, nbtsock->sock->backend_name, + state->my_ip, 0); + + socket_listen(nbtsock->sock, my_ip, 0, 0); printf("Running for %d seconds\n", timelimit); while (timeval_elapsed(&tv) < timelimit) { diff --git a/source4/torture/nbt/winsreplication.c b/source4/torture/nbt/winsreplication.c index f7f9665a6d..a6089fc2db 100644 --- a/source4/torture/nbt/winsreplication.c +++ b/source4/torture/nbt/winsreplication.c @@ -338,8 +338,8 @@ struct test_wrepl_conflict_conn { struct wrepl_wins_owner a, b, c, x; - const char *myaddr; - const char *myaddr2; + struct socket_address *myaddr; + struct socket_address *myaddr2; struct nbt_name_socket *nbtsock; struct nbt_name_socket *nbtsock2; @@ -551,6 +551,7 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx(TALLOC_CTX *mem struct test_wrepl_conflict_conn *ctx; struct wrepl_associate associate; struct wrepl_pull_table pull_table; + struct socket_address *nbt_srv_addr; NTSTATUS status; uint32_t i; @@ -615,27 +616,34 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx(TALLOC_CTX *mem talloc_free(pull_table.out.partners); - ctx->myaddr = talloc_strdup(mem_ctx, iface_best_ip(address)); + ctx->nbtsock = nbt_name_socket_init(ctx, NULL); + if (!ctx->nbtsock) return NULL; + + ctx->myaddr = socket_address_from_strings(mem_ctx, ctx->nbtsock->sock->backend_name, iface_best_ip(address), 0); if (!ctx->myaddr) return NULL; for (i = 0; i < iface_count(); i++) { - if (strcmp(ctx->myaddr, iface_n_ip(i)) == 0) continue; - ctx->myaddr2 = talloc_strdup(mem_ctx, iface_n_ip(i)); + if (strcmp(ctx->myaddr->addr, iface_n_ip(i)) == 0) continue; + ctx->myaddr2 = socket_address_from_strings(mem_ctx, ctx->nbtsock->sock->backend_name, iface_n_ip(i), 0); if (!ctx->myaddr2) return NULL; break; } - ctx->nbtsock = nbt_name_socket_init(ctx, NULL); - if (!ctx->nbtsock) return NULL; - - status = socket_listen(ctx->nbtsock->sock, ctx->myaddr, 0, 0, 0); + 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); if (!ctx->nbtsock_srv) return NULL; - status = socket_listen(ctx->nbtsock_srv->sock, ctx->myaddr, lp_nbt_port(), 0, 0); + /* Make a port 137 version of ctx->myaddr */ + nbt_srv_addr = socket_address_from_strings(mem_ctx, ctx->nbtsock_srv->sock->backend_name, ctx->myaddr->addr, lp_nbt_port()); + if (!nbt_srv_addr) return NULL; + + /* And if possible, bind to it. This won't work unless we are root or in sockewrapper */ + status = socket_listen(ctx->nbtsock_srv->sock, nbt_srv_addr, 0, 0); + talloc_free(nbt_srv_addr); if (!NT_STATUS_IS_OK(status)) { + /* this isn't fatal */ talloc_free(ctx->nbtsock_srv); ctx->nbtsock_srv = NULL; } @@ -644,14 +652,23 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx(TALLOC_CTX *mem ctx->nbtsock2 = nbt_name_socket_init(ctx, NULL); if (!ctx->nbtsock2) return NULL; - status = socket_listen(ctx->nbtsock2->sock, ctx->myaddr2, 0, 0, 0); + status = socket_listen(ctx->nbtsock2->sock, ctx->myaddr2, 0, 0); if (!NT_STATUS_IS_OK(status)) return NULL; ctx->nbtsock_srv2 = nbt_name_socket_init(ctx, ctx->nbtsock_srv->event_ctx); if (!ctx->nbtsock_srv2) return NULL; - status = socket_listen(ctx->nbtsock_srv2->sock, ctx->myaddr2, lp_nbt_port(), 0, 0); + /* Make a port 137 version of ctx->myaddr2 */ + nbt_srv_addr = socket_address_from_strings(mem_ctx, + ctx->nbtsock_srv->sock->backend_name, + ctx->myaddr2->addr, lp_nbt_port()); + if (!nbt_srv_addr) return NULL; + + /* And if possible, bind to it. This won't work unless we are root or in sockewrapper */ + status = socket_listen(ctx->nbtsock_srv2->sock, ctx->myaddr2, 0, 0); + talloc_free(nbt_srv_addr); if (!NT_STATUS_IS_OK(status)) { + /* this isn't fatal */ talloc_free(ctx->nbtsock_srv2); ctx->nbtsock_srv2 = NULL; } @@ -661,7 +678,7 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx(TALLOC_CTX *mem ctx->addresses_best = talloc_array(ctx, struct wrepl_ip, ctx->addresses_best_num); if (!ctx->addresses_best) return NULL; ctx->addresses_best[0].owner = ctx->b.address; - ctx->addresses_best[0].ip = ctx->myaddr; + ctx->addresses_best[0].ip = ctx->myaddr->addr; ctx->addresses_all_num = iface_count(); ctx->addresses_all = talloc_array(ctx, struct wrepl_ip, ctx->addresses_all_num); @@ -677,15 +694,15 @@ static struct test_wrepl_conflict_conn *test_create_conflict_ctx(TALLOC_CTX *mem ctx->addresses_best2 = talloc_array(ctx, struct wrepl_ip, ctx->addresses_best2_num); if (!ctx->addresses_best2) return NULL; ctx->addresses_best2[0].owner = ctx->b.address; - ctx->addresses_best2[0].ip = ctx->myaddr2; + ctx->addresses_best2[0].ip = ctx->myaddr2->addr; ctx->addresses_mhomed_num = 2; ctx->addresses_mhomed = talloc_array(ctx, struct wrepl_ip, ctx->addresses_mhomed_num); if (!ctx->addresses_mhomed) return NULL; ctx->addresses_mhomed[0].owner = ctx->b.address; - ctx->addresses_mhomed[0].ip = ctx->myaddr; + ctx->addresses_mhomed[0].ip = ctx->myaddr->addr; ctx->addresses_mhomed[1].owner = ctx->b.address; - ctx->addresses_mhomed[1].ip = ctx->myaddr2; + ctx->addresses_mhomed[1].ip = ctx->myaddr2->addr; } return ctx; @@ -6545,7 +6562,7 @@ struct test_conflict_owned_active_vs_replica_struct { static void test_conflict_owned_active_vs_replica_handler(struct nbt_name_socket *nbtsock, struct nbt_name_packet *req_packet, - const struct nbt_peer_socket *src); + struct socket_address *src); static BOOL test_conflict_owned_active_vs_replica(struct test_wrepl_conflict_conn *ctx) { @@ -9220,7 +9237,7 @@ static BOOL test_conflict_owned_active_vs_replica(struct test_wrepl_conflict_con for (j=0; j < count; j++) { struct nbt_name_socket *nbtsock = ctx->nbtsock; - if (ctx->myaddr2 && strcmp(records[i].wins.ips[j].ip, ctx->myaddr2) == 0) { + if (ctx->myaddr2 && strcmp(records[i].wins.ips[j].ip, ctx->myaddr2->addr) == 0) { nbtsock = ctx->nbtsock2; } @@ -9312,7 +9329,7 @@ done: static void test_conflict_owned_active_vs_replica_handler_query(struct nbt_name_socket *nbtsock, struct nbt_name_packet *req_packet, - const struct nbt_peer_socket *src) + struct socket_address *src) { struct nbt_name *name; struct nbt_name_packet *rep_packet; @@ -9407,7 +9424,7 @@ static void test_conflict_owned_active_vs_replica_handler_query(struct nbt_name_ static void test_conflict_owned_active_vs_replica_handler_release(struct nbt_name_socket *nbtsock, struct nbt_name_packet *req_packet, - const struct nbt_peer_socket *src) + struct socket_address *src) { struct nbt_name *name; struct nbt_name_packet *rep_packet; @@ -9460,7 +9477,7 @@ static void test_conflict_owned_active_vs_replica_handler_release(struct nbt_nam static void test_conflict_owned_active_vs_replica_handler(struct nbt_name_socket *nbtsock, struct nbt_name_packet *req_packet, - const struct nbt_peer_socket *src) + struct socket_address *src) { struct test_conflict_owned_active_vs_replica_struct *rec = nbtsock->incoming.private; |