From f06e39e30866207162656801210d2f574166d4df Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Apr 2005 05:07:04 +0000 Subject: r6321: added IDL and test suite for NBT dgram 'sam logon' request (sent by clients when a user tries to login) (This used to be commit 08ded62156b387457bc56b5910e1ddc813b375bd) --- source4/torture/nbt/dgram.c | 112 ++++++++++++++++++++++++++++++++++++++++- source4/torture/rpc/testjoin.c | 11 ++++ 2 files changed, 121 insertions(+), 2 deletions(-) (limited to 'source4/torture') diff --git a/source4/torture/nbt/dgram.c b/source4/torture/nbt/dgram.c index b62c41b17d..14d98fc0c0 100644 --- a/source4/torture/nbt/dgram.c +++ b/source4/torture/nbt/dgram.c @@ -24,6 +24,7 @@ #include "libcli/nbt/libnbt.h" #include "libcli/dgram/libdgram.h" #include "librpc/gen_ndr/ndr_nbt.h" +#include "librpc/gen_ndr/ndr_samr.h" #include "lib/socket/socket.h" #include "lib/events/events.h" @@ -61,7 +62,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); - const char *myaddress = talloc_strdup(mem_ctx, iface_best_ip(address)); + const char *myaddress = talloc_strdup(dgmsock, iface_best_ip(address)); struct nbt_netlogon_packet logon; struct nbt_name myname; NTSTATUS status; @@ -116,6 +117,112 @@ failed: } +/* + reply handler for ntlogon request +*/ +static void ntlogon_handler(struct dgram_mailslot_handler *dgmslot, + struct nbt_dgram_packet *packet, + const char *src_address, int src_port) +{ + NTSTATUS status; + struct nbt_ntlogon_packet ntlogon; + int *replies = dgmslot->private; + + printf("ntlogon reply from %s:%d\n", src_address, src_port); + + status = dgram_mailslot_ntlogon_parse(dgmslot, dgmslot, packet, &ntlogon); + if (!NT_STATUS_IS_OK(status)) { + printf("Failed to parse ntlogon packet from %s:%d\n", + src_address, src_port); + return; + } + + NDR_PRINT_DEBUG(nbt_ntlogon_packet, &ntlogon); + + (*replies)++; +} + + +/* test UDP/138 ntlogon requests */ +static BOOL nbt_test_ntlogon(TALLOC_CTX *mem_ctx, + struct nbt_name name, const char *address) +{ + struct dgram_mailslot_handler *dgmslot; + struct nbt_dgram_socket *dgmsock = nbt_dgram_socket_init(mem_ctx, NULL); + 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; + const char *password; + const char *dom_sid; + + join_ctx = torture_join_domain(TEST_NAME, lp_workgroup(), + ACB_WSTRUST, &password); + 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); + + /* 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); + if (!NT_STATUS_IS_OK(status)) { + socket_listen(dgmsock->sock, myaddress, 0, 0, 0); + } + + /* setup a temporary mailslot listener for replies */ + dgmslot = dgram_mailslot_temp(dgmsock, NBT_MAILSLOT_GETDC, + ntlogon_handler, &replies); + + + ZERO_STRUCT(logon); + logon.command = NTLOGON_SAM_LOGON; + logon.req.logon.request_count = 0; + logon.req.logon.computer_name = TEST_NAME; + logon.req.logon.user_name = TEST_NAME"$"; + logon.req.logon.mailslot_name = dgmslot->mailslot_name; + logon.req.logon.acct_control = ACB_WSTRUST; + logon.req.logon.sid = *dom_sid_parse_talloc(dgmslot, dom_sid); + logon.req.logon.nt_version = 1; + logon.req.logon.lmnt_token = 0xFFFF; + logon.req.logon.lm20_token = 0xFFFF; + + + myname.name = TEST_NAME; + myname.type = NBT_NAME_CLIENT; + myname.scope = NULL; + + status = dgram_mailslot_ntlogon_send(dgmsock, &name, address, + 0, &myname, &logon); + if (!NT_STATUS_IS_OK(status)) { + printf("Failed to send ntlogon request - %s\n", nt_errstr(status)); + goto failed; + } + + + while (timeval_elapsed(&tv) < 5 && replies == 0) { + event_loop_once(dgmsock->event_ctx); + } + + torture_leave_domain(join_ctx); + talloc_free(dgmsock); + return True; + +failed: + torture_leave_domain(join_ctx); + talloc_free(dgmsock); + return False; +} + + /* test nbt dgram operations */ @@ -127,7 +234,7 @@ BOOL torture_nbt_dgram(void) NTSTATUS status; BOOL ret = True; - name.name = lp_parm_string(-1, "torture", "host"); + name.name = lp_workgroup(); name.type = NBT_NAME_PDC; name.scope = NULL; @@ -141,6 +248,7 @@ BOOL torture_nbt_dgram(void) } ret &= nbt_test_netlogon(mem_ctx, name, address); + ret &= nbt_test_ntlogon(mem_ctx, name, address); talloc_free(mem_ctx); diff --git a/source4/torture/rpc/testjoin.c b/source4/torture/rpc/testjoin.c index 5e4c5a32f3..270d8ff7b7 100644 --- a/source4/torture/rpc/testjoin.c +++ b/source4/torture/rpc/testjoin.c @@ -32,6 +32,7 @@ struct test_join { struct dcerpc_pipe *p; struct policy_handle user_handle; + const char *dom_sid; }; @@ -156,6 +157,8 @@ struct test_join *torture_create_testuser(const char *username, goto failed; } + join->dom_sid = dom_sid_string(join, l.out.sid); + o.in.connect_handle = &handle; o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; o.in.sid = l.out.sid; @@ -309,6 +312,14 @@ void torture_leave_domain(struct test_join *join) talloc_free(join); } +/* + return the dom sid for a test join +*/ +const char *torture_join_sid(struct test_join *join) +{ + return join->dom_sid; +} + struct test_join_ads_dc { struct test_join *join; -- cgit