diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-04-06 11:17:08 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:11:27 -0500 |
commit | 7c6c366150022d6a745dcf18ed67bd264bc9c55d (patch) | |
tree | c43db606012e52a129179bef0b489c34a65a8036 /source4/libcli/dgram | |
parent | 567a74690c9536f464844d647b9fe21ca56b53f3 (diff) | |
download | samba-7c6c366150022d6a745dcf18ed67bd264bc9c55d.tar.gz samba-7c6c366150022d6a745dcf18ed67bd264bc9c55d.tar.bz2 samba-7c6c366150022d6a745dcf18ed67bd264bc9c55d.zip |
r6223: added a bit more datagram infrastructure and the beginnings of a test
suite. The NBT-DGRAM test does a UDP/138 netlogon request, to which a
windows server sends a reply, but the windows server sends the reply
to the wrong port (it always sends to 138), so the test suite doesn't
see it.
(This used to be commit a7634625dbc944dd8256a822be290010f341a571)
Diffstat (limited to 'source4/libcli/dgram')
-rw-r--r-- | source4/libcli/dgram/libdgram.h | 16 | ||||
-rw-r--r-- | source4/libcli/dgram/mailslot.c | 61 | ||||
-rw-r--r-- | source4/libcli/dgram/netlogon.c | 58 |
3 files changed, 130 insertions, 5 deletions
diff --git a/source4/libcli/dgram/libdgram.h b/source4/libcli/dgram/libdgram.h index 866877e341..482fd86980 100644 --- a/source4/libcli/dgram/libdgram.h +++ b/source4/libcli/dgram/libdgram.h @@ -111,8 +111,18 @@ struct dgram_mailslot_handler *dgram_mailslot_temp(struct nbt_dgram_socket *dgms void *private); - - - +NTSTATUS dgram_mailslot_send(struct nbt_dgram_socket *dgmsock, + enum dgram_msg_type msg_type, + const char *mailslot_name, + struct nbt_name *dest_name, + const char *dest_address, + struct nbt_name *src_name, + DATA_BLOB *request); + +NTSTATUS dgram_mailslot_netlogon_send(struct nbt_dgram_socket *dgmsock, + struct nbt_name *dest_name, + const char *dest_address, + struct nbt_name *src_name, + struct nbt_netlogon_packet *request); diff --git a/source4/libcli/dgram/mailslot.c b/source4/libcli/dgram/mailslot.c index da9b6cdd20..89aab9c874 100644 --- a/source4/libcli/dgram/mailslot.c +++ b/source4/libcli/dgram/mailslot.c @@ -115,9 +115,9 @@ struct dgram_mailslot_handler *dgram_mailslot_temp(struct nbt_dgram_socket *dgms /* try a 100 times at most */ for (i=0;i<100;i++) { - name = talloc_asprintf(dgmsock, "%s%u", + name = talloc_asprintf(dgmsock, "%s%03u", mailslot_name, - generate_random() % UINT16_MAX); + generate_random() % 1000); if (name == NULL) return NULL; if (dgram_mailslot_find(dgmsock, name)) { talloc_free(name); @@ -130,3 +130,60 @@ struct dgram_mailslot_handler *dgram_mailslot_temp(struct nbt_dgram_socket *dgms DEBUG(2,("Unable to create temporary mailslot from %s\n", mailslot_name)); return NULL; } + + +/* + send a mailslot request +*/ +NTSTATUS dgram_mailslot_send(struct nbt_dgram_socket *dgmsock, + enum dgram_msg_type msg_type, + const char *mailslot_name, + struct nbt_name *dest_name, + const char *dest_address, + struct nbt_name *src_name, + DATA_BLOB *request) +{ + TALLOC_CTX *tmp_ctx = talloc_new(dgmsock); + struct nbt_dgram_packet packet; + struct dgram_message *msg; + struct dgram_smb_packet *smb; + struct smb_trans_body *trans; + NTSTATUS status; + + ZERO_STRUCT(packet); + packet.msg_type = msg_type; + packet.flags = DGRAM_FLAG_FIRST; + packet.dgram_id = generate_random() % UINT16_MAX; + packet.source = socket_get_my_addr(dgmsock->sock, tmp_ctx); + packet.src_port = socket_get_my_port(dgmsock->sock); + + msg = &packet.data.msg; + /* this length calculation is very crude - it should be based on gensize + calls */ + msg->length = 138 + strlen(mailslot_name) + request->length; + msg->offset = 0; + + msg->source_name = *src_name; + msg->dest_name = *dest_name; + msg->dgram_body_type = DGRAM_SMB; + + smb = &msg->body.smb; + smb->smb_command = SMB_TRANSACTION; + + trans = &smb->body.trans; + trans->total_data_count = request->length; + trans->timeout = (uint32_t)-1; + trans->data_count = request->length; + trans->data_offset = 70 + strlen(mailslot_name); + trans->opcode = 1; /* write mail slot */ + trans->priority = 1; + trans->class = 2; + trans->mailslot_name = mailslot_name; + trans->data = *request; + + status = nbt_dgram_send(dgmsock, &packet, dest_address, lp_dgram_port()); + + talloc_free(tmp_ctx); + + return status; +} diff --git a/source4/libcli/dgram/netlogon.c b/source4/libcli/dgram/netlogon.c new file mode 100644 index 0000000000..1f3a3d6c62 --- /dev/null +++ b/source4/libcli/dgram/netlogon.c @@ -0,0 +1,58 @@ +/* + Unix SMB/CIFS implementation. + + handling for netlogon dgram requests + + Copyright (C) Andrew Tridgell 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "dlinklist.h" +#include "libcli/nbt/libnbt.h" +#include "libcli/dgram/libdgram.h" +#include "lib/socket/socket.h" +#include "librpc/gen_ndr/ndr_nbt.h" + +/* + send a netlogon mailslot request +*/ +NTSTATUS dgram_mailslot_netlogon_send(struct nbt_dgram_socket *dgmsock, + struct nbt_name *dest_name, + const char *dest_address, + struct nbt_name *src_name, + struct nbt_netlogon_packet *request) +{ + NTSTATUS status; + DATA_BLOB blob; + TALLOC_CTX *tmp_ctx = talloc_new(dgmsock); + + status = ndr_push_struct_blob(&blob, tmp_ctx, request, + (ndr_push_flags_fn_t)ndr_push_nbt_netlogon_packet); + if (!NT_STATUS_IS_OK(status)) { + talloc_free(tmp_ctx); + return status; + } + + + status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE, + "\\MAILSLOT\\NET\\NETLOGON", + dest_name, dest_address, src_name, &blob); + talloc_free(tmp_ctx); + return status; +} + |