wmi-1.3.16 from opsview.com
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
handling for browsing dgram requests
|
||||
|
||||
Copyright (C) Jelmer Vernooij 2005
|
||||
Heavily based on ntlogon.c
|
||||
|
||||
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 "libcli/dgram/libdgram.h"
|
||||
#include "lib/socket/socket.h"
|
||||
#include "libcli/resolve/resolve.h"
|
||||
#include "librpc/gen_ndr/ndr_nbt.h"
|
||||
|
||||
NTSTATUS dgram_mailslot_browse_send(struct nbt_dgram_socket *dgmsock,
|
||||
struct nbt_name *dest_name,
|
||||
struct socket_address *dest,
|
||||
struct nbt_name *src_name,
|
||||
struct nbt_browse_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_browse_packet);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
talloc_free(tmp_ctx);
|
||||
return status;
|
||||
}
|
||||
|
||||
status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE,
|
||||
NBT_MAILSLOT_BROWSE,
|
||||
dest_name, dest,
|
||||
src_name, &blob);
|
||||
talloc_free(tmp_ctx);
|
||||
return status;
|
||||
}
|
||||
|
||||
NTSTATUS dgram_mailslot_browse_reply(struct nbt_dgram_socket *dgmsock,
|
||||
struct nbt_dgram_packet *request,
|
||||
const char *mailslot_name,
|
||||
struct nbt_browse_packet *reply)
|
||||
{
|
||||
NTSTATUS status;
|
||||
DATA_BLOB blob;
|
||||
TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
|
||||
struct nbt_name myname;
|
||||
struct socket_address *dest;
|
||||
|
||||
status = ndr_push_struct_blob(&blob, tmp_ctx, reply,
|
||||
(ndr_push_flags_fn_t)ndr_push_nbt_browse_packet);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
talloc_free(tmp_ctx);
|
||||
return status;
|
||||
}
|
||||
|
||||
make_nbt_name_client(&myname, lp_netbios_name());
|
||||
|
||||
dest = socket_address_from_strings(tmp_ctx, dgmsock->sock->backend_name,
|
||||
request->src_addr, request->src_port);
|
||||
if (!dest) {
|
||||
talloc_free(tmp_ctx);
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE,
|
||||
mailslot_name,
|
||||
&request->data.msg.source_name,
|
||||
dest,
|
||||
&myname, &blob);
|
||||
talloc_free(tmp_ctx);
|
||||
return status;
|
||||
}
|
||||
|
||||
NTSTATUS dgram_mailslot_browse_parse(struct dgram_mailslot_handler *dgmslot,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
struct nbt_dgram_packet *dgram,
|
||||
struct nbt_browse_packet *pkt)
|
||||
{
|
||||
DATA_BLOB data = dgram_mailslot_data(dgram);
|
||||
NTSTATUS status;
|
||||
|
||||
status = ndr_pull_struct_blob(&data, mem_ctx, pkt,
|
||||
(ndr_pull_flags_fn_t)ndr_pull_nbt_browse_packet);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(0,("Failed to parse browse packet of length %d\n",
|
||||
(int)data.length));
|
||||
if (DEBUGLVL(10)) {
|
||||
file_save("browse.dat", data.data, data.length);
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
low level socket handling for nbt dgram requests (UDP138)
|
||||
|
||||
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 "lib/util/dlinklist.h"
|
||||
#include "libcli/dgram/libdgram.h"
|
||||
#include "lib/socket/socket.h"
|
||||
#include "librpc/gen_ndr/ndr_nbt.h"
|
||||
|
||||
|
||||
/*
|
||||
handle recv events on a nbt dgram socket
|
||||
*/
|
||||
static void dgm_socket_recv(struct nbt_dgram_socket *dgmsock)
|
||||
{
|
||||
TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
|
||||
NTSTATUS status;
|
||||
struct socket_address *src;
|
||||
DATA_BLOB blob;
|
||||
size_t nread, dsize;
|
||||
struct nbt_dgram_packet *packet;
|
||||
const char *mailslot_name;
|
||||
|
||||
status = socket_pending(dgmsock->sock, &dsize);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
talloc_free(tmp_ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
blob = data_blob_talloc(tmp_ctx, NULL, dsize);
|
||||
if (blob.data == NULL) {
|
||||
talloc_free(tmp_ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
status = socket_recvfrom(dgmsock->sock, blob.data, blob.length, &nread,
|
||||
tmp_ctx, &src);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
talloc_free(tmp_ctx);
|
||||
return;
|
||||
}
|
||||
blob.length = nread;
|
||||
|
||||
DEBUG(2,("Received dgram packet of length %d from %s:%d\n",
|
||||
(int)blob.length, src->addr, src->port));
|
||||
|
||||
packet = talloc(tmp_ctx, struct nbt_dgram_packet);
|
||||
if (packet == NULL) {
|
||||
talloc_free(tmp_ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
/* parse the request */
|
||||
status = ndr_pull_struct_blob(&blob, packet, packet,
|
||||
(ndr_pull_flags_fn_t)ndr_pull_nbt_dgram_packet);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(2,("Failed to parse incoming NBT DGRAM packet - %s\n",
|
||||
nt_errstr(status)));
|
||||
talloc_free(tmp_ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
/* if this is a mailslot message, then see if we can dispatch it to a handler */
|
||||
mailslot_name = dgram_mailslot_name(packet);
|
||||
if (mailslot_name) {
|
||||
struct dgram_mailslot_handler *dgmslot;
|
||||
dgmslot = dgram_mailslot_find(dgmsock, mailslot_name);
|
||||
if (dgmslot) {
|
||||
dgmslot->handler(dgmslot, packet, src);
|
||||
} else {
|
||||
DEBUG(2,("No mailslot handler for '%s'\n", mailslot_name));
|
||||
}
|
||||
} else {
|
||||
/* dispatch if there is a general handler */
|
||||
if (dgmsock->incoming.handler) {
|
||||
dgmsock->incoming.handler(dgmsock, packet, src);
|
||||
}
|
||||
}
|
||||
|
||||
talloc_free(tmp_ctx);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
handle send events on a nbt dgram socket
|
||||
*/
|
||||
static void dgm_socket_send(struct nbt_dgram_socket *dgmsock)
|
||||
{
|
||||
struct nbt_dgram_request *req;
|
||||
NTSTATUS status;
|
||||
|
||||
while ((req = dgmsock->send_queue)) {
|
||||
size_t len;
|
||||
|
||||
len = req->encoded.length;
|
||||
status = socket_sendto(dgmsock->sock, &req->encoded, &len,
|
||||
req->dest);
|
||||
if (NT_STATUS_IS_ERR(status)) {
|
||||
DEBUG(3,("Failed to send datagram of length %u to %s:%d: %s\n",
|
||||
(unsigned)req->encoded.length, req->dest->addr, req->dest->port,
|
||||
nt_errstr(status)));
|
||||
DLIST_REMOVE(dgmsock->send_queue, req);
|
||||
talloc_free(req);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!NT_STATUS_IS_OK(status)) return;
|
||||
|
||||
DLIST_REMOVE(dgmsock->send_queue, req);
|
||||
talloc_free(req);
|
||||
}
|
||||
|
||||
EVENT_FD_NOT_WRITEABLE(dgmsock->fde);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
handle fd events on a nbt_dgram_socket
|
||||
*/
|
||||
static void dgm_socket_handler(struct event_context *ev, struct fd_event *fde,
|
||||
uint16_t flags, void *private)
|
||||
{
|
||||
struct nbt_dgram_socket *dgmsock = talloc_get_type(private,
|
||||
struct nbt_dgram_socket);
|
||||
if (flags & EVENT_FD_WRITE) {
|
||||
dgm_socket_send(dgmsock);
|
||||
}
|
||||
if (flags & EVENT_FD_READ) {
|
||||
dgm_socket_recv(dgmsock);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
initialise a nbt_dgram_socket. The event_ctx is optional, if provided
|
||||
then operations will use that event context
|
||||
*/
|
||||
struct nbt_dgram_socket *nbt_dgram_socket_init(TALLOC_CTX *mem_ctx,
|
||||
struct event_context *event_ctx)
|
||||
{
|
||||
struct nbt_dgram_socket *dgmsock;
|
||||
NTSTATUS status;
|
||||
|
||||
dgmsock = talloc(mem_ctx, struct nbt_dgram_socket);
|
||||
if (dgmsock == NULL) goto failed;
|
||||
|
||||
if (event_ctx == NULL) {
|
||||
dgmsock->event_ctx = event_context_init(dgmsock);
|
||||
} else {
|
||||
dgmsock->event_ctx = talloc_reference(dgmsock, event_ctx);
|
||||
}
|
||||
if (dgmsock->event_ctx == NULL) goto failed;
|
||||
|
||||
status = socket_create("ip", SOCKET_TYPE_DGRAM, &dgmsock->sock, 0);
|
||||
if (!NT_STATUS_IS_OK(status)) goto failed;
|
||||
|
||||
socket_set_option(dgmsock->sock, "SO_BROADCAST", "1");
|
||||
|
||||
talloc_steal(dgmsock, dgmsock->sock);
|
||||
|
||||
dgmsock->fde = event_add_fd(dgmsock->event_ctx, dgmsock,
|
||||
socket_get_fd(dgmsock->sock), 0,
|
||||
dgm_socket_handler, dgmsock);
|
||||
|
||||
dgmsock->send_queue = NULL;
|
||||
dgmsock->incoming.handler = NULL;
|
||||
dgmsock->mailslot_handlers = NULL;
|
||||
|
||||
return dgmsock;
|
||||
|
||||
failed:
|
||||
talloc_free(dgmsock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
setup a handler for generic incoming requests
|
||||
*/
|
||||
NTSTATUS dgram_set_incoming_handler(struct nbt_dgram_socket *dgmsock,
|
||||
void (*handler)(struct nbt_dgram_socket *,
|
||||
struct nbt_dgram_packet *,
|
||||
struct socket_address *),
|
||||
void *private)
|
||||
{
|
||||
dgmsock->incoming.handler = handler;
|
||||
dgmsock->incoming.private = private;
|
||||
EVENT_FD_READABLE(dgmsock->fde);
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
queue a datagram for send
|
||||
*/
|
||||
NTSTATUS nbt_dgram_send(struct nbt_dgram_socket *dgmsock,
|
||||
struct nbt_dgram_packet *packet,
|
||||
struct socket_address *dest)
|
||||
{
|
||||
struct nbt_dgram_request *req;
|
||||
NTSTATUS status = NT_STATUS_NO_MEMORY;
|
||||
|
||||
req = talloc(dgmsock, struct nbt_dgram_request);
|
||||
if (req == NULL) goto failed;
|
||||
|
||||
req->dest = dest;
|
||||
if (talloc_reference(req, dest) == NULL) goto failed;
|
||||
|
||||
status = ndr_push_struct_blob(&req->encoded, req, packet,
|
||||
(ndr_push_flags_fn_t)ndr_push_nbt_dgram_packet);
|
||||
if (!NT_STATUS_IS_OK(status)) goto failed;
|
||||
|
||||
DLIST_ADD_END(dgmsock->send_queue, req, struct nbt_dgram_request *);
|
||||
|
||||
EVENT_FD_WRITEABLE(dgmsock->fde);
|
||||
|
||||
return NT_STATUS_OK;
|
||||
|
||||
failed:
|
||||
talloc_free(req);
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
a raw async NBT DGRAM library
|
||||
|
||||
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 "librpc/gen_ndr/nbt.h"
|
||||
|
||||
/*
|
||||
a datagram name request
|
||||
*/
|
||||
struct nbt_dgram_request {
|
||||
struct nbt_dgram_request *next, *prev;
|
||||
|
||||
/* where to send the request */
|
||||
struct socket_address *dest;
|
||||
|
||||
/* the encoded request */
|
||||
DATA_BLOB encoded;
|
||||
};
|
||||
|
||||
/*
|
||||
context structure for operations on dgram packets
|
||||
*/
|
||||
struct nbt_dgram_socket {
|
||||
struct socket_context *sock;
|
||||
struct event_context *event_ctx;
|
||||
|
||||
/* the fd event */
|
||||
struct fd_event *fde;
|
||||
|
||||
/* a queue of outgoing requests */
|
||||
struct nbt_dgram_request *send_queue;
|
||||
|
||||
/* a list of mailslot handlers */
|
||||
struct dgram_mailslot_handler *mailslot_handlers;
|
||||
|
||||
/* what to do with incoming request packets */
|
||||
struct {
|
||||
void (*handler)(struct nbt_dgram_socket *, struct nbt_dgram_packet *,
|
||||
struct socket_address *src);
|
||||
void *private;
|
||||
} incoming;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
the mailslot code keeps a list of mailslot handlers. A mailslot
|
||||
handler is a function that receives incoming packets for a specific
|
||||
mailslot name. When a caller needs to send a mailslot and wants to
|
||||
get a reply then it needs to register itself as listening for
|
||||
incoming packets on the reply mailslot
|
||||
*/
|
||||
|
||||
typedef void (*dgram_mailslot_handler_t)(struct dgram_mailslot_handler *,
|
||||
struct nbt_dgram_packet *,
|
||||
struct socket_address *src);
|
||||
|
||||
struct dgram_mailslot_handler {
|
||||
struct dgram_mailslot_handler *next, *prev;
|
||||
|
||||
struct nbt_dgram_socket *dgmsock;
|
||||
const char *mailslot_name;
|
||||
|
||||
dgram_mailslot_handler_t handler;
|
||||
void *private;
|
||||
};
|
||||
|
||||
|
||||
/* prototypes */
|
||||
NTSTATUS nbt_dgram_send(struct nbt_dgram_socket *dgmsock,
|
||||
struct nbt_dgram_packet *packet,
|
||||
struct socket_address *dest);
|
||||
NTSTATUS dgram_set_incoming_handler(struct nbt_dgram_socket *dgmsock,
|
||||
void (*handler)(struct nbt_dgram_socket *,
|
||||
struct nbt_dgram_packet *,
|
||||
struct socket_address *),
|
||||
void *private);
|
||||
struct nbt_dgram_socket *nbt_dgram_socket_init(TALLOC_CTX *mem_ctx,
|
||||
struct event_context *event_ctx);
|
||||
|
||||
const char *dgram_mailslot_name(struct nbt_dgram_packet *packet);
|
||||
struct dgram_mailslot_handler *dgram_mailslot_find(struct nbt_dgram_socket *dgmsock,
|
||||
const char *mailslot_name);
|
||||
struct dgram_mailslot_handler *dgram_mailslot_listen(struct nbt_dgram_socket *dgmsock,
|
||||
const char *mailslot_name,
|
||||
dgram_mailslot_handler_t handler,
|
||||
void *private);
|
||||
struct dgram_mailslot_handler *dgram_mailslot_temp(struct nbt_dgram_socket *dgmsock,
|
||||
const char *mailslot_name,
|
||||
dgram_mailslot_handler_t handler,
|
||||
void *private);
|
||||
DATA_BLOB dgram_mailslot_data(struct nbt_dgram_packet *dgram);
|
||||
|
||||
|
||||
NTSTATUS dgram_mailslot_send(struct nbt_dgram_socket *dgmsock,
|
||||
enum dgram_msg_type msg_type,
|
||||
const char *mailslot_name,
|
||||
struct nbt_name *dest_name,
|
||||
struct socket_address *dest,
|
||||
struct nbt_name *src_name,
|
||||
DATA_BLOB *request);
|
||||
|
||||
NTSTATUS dgram_mailslot_netlogon_send(struct nbt_dgram_socket *dgmsock,
|
||||
struct nbt_name *dest_name,
|
||||
struct socket_address *dest,
|
||||
struct nbt_name *src_name,
|
||||
struct nbt_netlogon_packet *request);
|
||||
NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock,
|
||||
struct nbt_dgram_packet *request,
|
||||
const char *mailslot_name,
|
||||
struct nbt_netlogon_packet *reply);
|
||||
NTSTATUS dgram_mailslot_netlogon_parse(struct dgram_mailslot_handler *dgmslot,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
struct nbt_dgram_packet *dgram,
|
||||
struct nbt_netlogon_packet *netlogon);
|
||||
|
||||
NTSTATUS dgram_mailslot_ntlogon_send(struct nbt_dgram_socket *dgmsock,
|
||||
enum dgram_msg_type msg_type,
|
||||
struct nbt_name *dest_name,
|
||||
struct socket_address *dest,
|
||||
struct nbt_name *src_name,
|
||||
struct nbt_ntlogon_packet *request);
|
||||
NTSTATUS dgram_mailslot_ntlogon_reply(struct nbt_dgram_socket *dgmsock,
|
||||
struct nbt_dgram_packet *request,
|
||||
const char *mailslot_name,
|
||||
struct nbt_ntlogon_packet *reply);
|
||||
NTSTATUS dgram_mailslot_ntlogon_parse(struct dgram_mailslot_handler *dgmslot,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
struct nbt_dgram_packet *dgram,
|
||||
struct nbt_ntlogon_packet *ntlogon);
|
||||
|
||||
NTSTATUS dgram_mailslot_browse_send(struct nbt_dgram_socket *dgmsock,
|
||||
struct nbt_name *dest_name,
|
||||
struct socket_address *dest,
|
||||
struct nbt_name *src_name,
|
||||
struct nbt_browse_packet *request);
|
||||
|
||||
NTSTATUS dgram_mailslot_browse_reply(struct nbt_dgram_socket *dgmsock,
|
||||
struct nbt_dgram_packet *request,
|
||||
const char *mailslot_name,
|
||||
struct nbt_browse_packet *reply);
|
||||
|
||||
NTSTATUS dgram_mailslot_browse_parse(struct dgram_mailslot_handler *dgmslot,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
struct nbt_dgram_packet *dgram,
|
||||
struct nbt_browse_packet *pkt);
|
||||
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
packet handling for mailslot 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
This implements "Class 2 mailslots", i.e. the communication mechanism
|
||||
used for all mailslot packets smaller than 425 bytes.
|
||||
|
||||
"Class 1 mailslots" (which use SMB) are used for messages larger
|
||||
than 426 bytes and are supported on some systems. These are not implemented
|
||||
in Samba4 yet, as there don't appear to be any core services that use
|
||||
them.
|
||||
|
||||
425 and 426-byte sized messages are not supported at all.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "lib/events/events.h"
|
||||
#include "lib/util/dlinklist.h"
|
||||
#include "libcli/dgram/libdgram.h"
|
||||
#include "lib/socket/socket.h"
|
||||
|
||||
/*
|
||||
destroy a mailslot handler
|
||||
*/
|
||||
static int dgram_mailslot_destructor(struct dgram_mailslot_handler *dgmslot)
|
||||
{
|
||||
DLIST_REMOVE(dgmslot->dgmsock->mailslot_handlers, dgmslot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
start listening on a mailslot. talloc_free() the handle to stop listening
|
||||
*/
|
||||
struct dgram_mailslot_handler *dgram_mailslot_listen(struct nbt_dgram_socket *dgmsock,
|
||||
const char *mailslot_name,
|
||||
dgram_mailslot_handler_t handler,
|
||||
void *private)
|
||||
{
|
||||
struct dgram_mailslot_handler *dgmslot;
|
||||
|
||||
dgmslot = talloc(dgmsock, struct dgram_mailslot_handler);
|
||||
if (dgmslot == NULL) return NULL;
|
||||
|
||||
dgmslot->dgmsock = dgmsock;
|
||||
dgmslot->mailslot_name = talloc_strdup(dgmslot, mailslot_name);
|
||||
if (dgmslot->mailslot_name == NULL) {
|
||||
talloc_free(dgmslot);
|
||||
return NULL;
|
||||
}
|
||||
dgmslot->handler = handler;
|
||||
dgmslot->private = private;
|
||||
|
||||
DLIST_ADD(dgmsock->mailslot_handlers, dgmslot);
|
||||
talloc_set_destructor(dgmslot, dgram_mailslot_destructor);
|
||||
|
||||
EVENT_FD_READABLE(dgmsock->fde);
|
||||
|
||||
return dgmslot;
|
||||
}
|
||||
|
||||
/*
|
||||
find the handler for a specific mailslot name
|
||||
*/
|
||||
struct dgram_mailslot_handler *dgram_mailslot_find(struct nbt_dgram_socket *dgmsock,
|
||||
const char *mailslot_name)
|
||||
{
|
||||
struct dgram_mailslot_handler *h;
|
||||
for (h=dgmsock->mailslot_handlers;h;h=h->next) {
|
||||
if (strcasecmp(h->mailslot_name, mailslot_name) == 0) {
|
||||
return h;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
check that a datagram packet is a valid mailslot request, and return the
|
||||
mailslot name if it is, otherwise return NULL
|
||||
*/
|
||||
const char *dgram_mailslot_name(struct nbt_dgram_packet *packet)
|
||||
{
|
||||
if (packet->msg_type != DGRAM_DIRECT_UNIQUE &&
|
||||
packet->msg_type != DGRAM_DIRECT_GROUP &&
|
||||
packet->msg_type != DGRAM_BCAST) {
|
||||
return NULL;
|
||||
}
|
||||
if (packet->data.msg.dgram_body_type != DGRAM_SMB) return NULL;
|
||||
if (packet->data.msg.body.smb.smb_command != SMB_TRANSACTION) return NULL;
|
||||
return packet->data.msg.body.smb.body.trans.mailslot_name;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
create a temporary mailslot handler for a reply mailslot, allocating
|
||||
a new mailslot name using the given base name and a random integer extension
|
||||
*/
|
||||
struct dgram_mailslot_handler *dgram_mailslot_temp(struct nbt_dgram_socket *dgmsock,
|
||||
const char *mailslot_name,
|
||||
dgram_mailslot_handler_t handler,
|
||||
void *private)
|
||||
{
|
||||
char *name;
|
||||
int i;
|
||||
struct dgram_mailslot_handler *dgmslot;
|
||||
|
||||
/* try a 100 times at most */
|
||||
for (i=0;i<100;i++) {
|
||||
name = talloc_asprintf(dgmsock, "%s%03u",
|
||||
mailslot_name,
|
||||
generate_random() % 1000);
|
||||
if (name == NULL) return NULL;
|
||||
if (dgram_mailslot_find(dgmsock, name)) {
|
||||
talloc_free(name);
|
||||
return NULL;
|
||||
}
|
||||
dgmslot = dgram_mailslot_listen(dgmsock, name, handler, private);
|
||||
talloc_free(name);
|
||||
if (dgmslot != NULL) {
|
||||
return dgmslot;
|
||||
}
|
||||
}
|
||||
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,
|
||||
struct socket_address *_dest,
|
||||
struct nbt_name *src_name,
|
||||
DATA_BLOB *request)
|
||||
{
|
||||
TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
|
||||
struct nbt_dgram_packet packet;
|
||||
struct socket_address *dest;
|
||||
struct dgram_message *msg;
|
||||
struct dgram_smb_packet *smb;
|
||||
struct smb_trans_body *trans;
|
||||
struct socket_address *src;
|
||||
NTSTATUS status;
|
||||
|
||||
if (_dest->port == 0) {
|
||||
dest = socket_address_from_strings(tmp_ctx, _dest->family,
|
||||
_dest->addr, lp_dgram_port());
|
||||
} else {
|
||||
dest = _dest;
|
||||
}
|
||||
if (!dest) {
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
ZERO_STRUCT(packet);
|
||||
packet.msg_type = msg_type;
|
||||
packet.flags = DGRAM_FLAG_FIRST | DGRAM_NODE_NBDD;
|
||||
packet.dgram_id = generate_random() % UINT16_MAX;
|
||||
src = socket_get_my_addr(dgmsock->sock, tmp_ctx);
|
||||
if (!src) {
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
packet.src_addr = src->addr;
|
||||
packet.src_port = src->port;
|
||||
|
||||
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 = 1000;
|
||||
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);
|
||||
|
||||
talloc_free(tmp_ctx);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
return the mailslot data portion from a mailslot packet
|
||||
*/
|
||||
DATA_BLOB dgram_mailslot_data(struct nbt_dgram_packet *dgram)
|
||||
{
|
||||
struct smb_trans_body *trans = &dgram->data.msg.body.smb.body.trans;
|
||||
DATA_BLOB ret = trans->data;
|
||||
int pad = trans->data_offset - (70 + strlen(trans->mailslot_name));
|
||||
|
||||
if (pad < 0 || pad > ret.length) {
|
||||
DEBUG(2,("Badly formatted data in mailslot - pad = %d\n", pad));
|
||||
return data_blob(NULL, 0);
|
||||
}
|
||||
ret.data += pad;
|
||||
ret.length -= pad;
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
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 "libcli/dgram/libdgram.h"
|
||||
#include "lib/socket/socket.h"
|
||||
#include "libcli/resolve/resolve.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,
|
||||
struct socket_address *dest,
|
||||
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,
|
||||
NBT_MAILSLOT_NETLOGON,
|
||||
dest_name, dest,
|
||||
src_name, &blob);
|
||||
talloc_free(tmp_ctx);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
send a netlogon mailslot reply
|
||||
*/
|
||||
NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock,
|
||||
struct nbt_dgram_packet *request,
|
||||
const char *mailslot_name,
|
||||
struct nbt_netlogon_packet *reply)
|
||||
{
|
||||
NTSTATUS status;
|
||||
DATA_BLOB blob;
|
||||
TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
|
||||
struct nbt_name myname;
|
||||
struct socket_address *dest;
|
||||
|
||||
status = ndr_push_struct_blob(&blob, tmp_ctx, reply,
|
||||
(ndr_push_flags_fn_t)ndr_push_nbt_netlogon_packet);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
talloc_free(tmp_ctx);
|
||||
return status;
|
||||
}
|
||||
|
||||
make_nbt_name_client(&myname, lp_netbios_name());
|
||||
|
||||
dest = socket_address_from_strings(tmp_ctx, dgmsock->sock->backend_name,
|
||||
request->src_addr, request->src_port);
|
||||
if (!dest) {
|
||||
talloc_free(tmp_ctx);
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE,
|
||||
mailslot_name,
|
||||
&request->data.msg.source_name,
|
||||
dest,
|
||||
&myname, &blob);
|
||||
talloc_free(tmp_ctx);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
parse a netlogon response. The packet must be a valid mailslot packet
|
||||
*/
|
||||
NTSTATUS dgram_mailslot_netlogon_parse(struct dgram_mailslot_handler *dgmslot,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
struct nbt_dgram_packet *dgram,
|
||||
struct nbt_netlogon_packet *netlogon)
|
||||
{
|
||||
DATA_BLOB data = dgram_mailslot_data(dgram);
|
||||
NTSTATUS status;
|
||||
|
||||
status = ndr_pull_struct_blob(&data, mem_ctx, netlogon,
|
||||
(ndr_pull_flags_fn_t)ndr_pull_nbt_netlogon_packet);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(0,("Failed to parse netlogon packet of length %d\n",
|
||||
(int)data.length));
|
||||
if (DEBUGLVL(10)) {
|
||||
file_save("netlogon.dat", data.data, data.length);
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
handling for ntlogon 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 "libcli/dgram/libdgram.h"
|
||||
#include "lib/socket/socket.h"
|
||||
#include "libcli/resolve/resolve.h"
|
||||
#include "librpc/gen_ndr/ndr_nbt.h"
|
||||
|
||||
/*
|
||||
send a ntlogon mailslot request
|
||||
*/
|
||||
NTSTATUS dgram_mailslot_ntlogon_send(struct nbt_dgram_socket *dgmsock,
|
||||
enum dgram_msg_type msg_type,
|
||||
struct nbt_name *dest_name,
|
||||
struct socket_address *dest,
|
||||
struct nbt_name *src_name,
|
||||
struct nbt_ntlogon_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_ntlogon_packet);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
talloc_free(tmp_ctx);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
status = dgram_mailslot_send(dgmsock, msg_type,
|
||||
NBT_MAILSLOT_NTLOGON,
|
||||
dest_name, dest,
|
||||
src_name, &blob);
|
||||
talloc_free(tmp_ctx);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
send a ntlogon mailslot reply
|
||||
*/
|
||||
NTSTATUS dgram_mailslot_ntlogon_reply(struct nbt_dgram_socket *dgmsock,
|
||||
struct nbt_dgram_packet *request,
|
||||
const char *mailslot_name,
|
||||
struct nbt_ntlogon_packet *reply)
|
||||
{
|
||||
NTSTATUS status;
|
||||
DATA_BLOB blob;
|
||||
TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
|
||||
struct nbt_name myname;
|
||||
struct socket_address *dest;
|
||||
|
||||
status = ndr_push_struct_blob(&blob, tmp_ctx, reply,
|
||||
(ndr_push_flags_fn_t)ndr_push_nbt_ntlogon_packet);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
talloc_free(tmp_ctx);
|
||||
return status;
|
||||
}
|
||||
|
||||
make_nbt_name_client(&myname, lp_netbios_name());
|
||||
|
||||
dest = socket_address_from_strings(tmp_ctx,
|
||||
dgmsock->sock->backend_name,
|
||||
request->src_addr, request->src_port);
|
||||
if (!dest) {
|
||||
talloc_free(tmp_ctx);
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE,
|
||||
mailslot_name,
|
||||
&request->data.msg.source_name,
|
||||
dest,
|
||||
&myname, &blob);
|
||||
talloc_free(tmp_ctx);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
parse a ntlogon response. The packet must be a valid mailslot packet
|
||||
*/
|
||||
NTSTATUS dgram_mailslot_ntlogon_parse(struct dgram_mailslot_handler *dgmslot,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
struct nbt_dgram_packet *dgram,
|
||||
struct nbt_ntlogon_packet *ntlogon)
|
||||
{
|
||||
DATA_BLOB data = dgram_mailslot_data(dgram);
|
||||
NTSTATUS status;
|
||||
|
||||
status = ndr_pull_struct_blob(&data, mem_ctx, ntlogon,
|
||||
(ndr_pull_flags_fn_t)ndr_pull_nbt_ntlogon_packet);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(0,("Failed to parse ntlogon packet of length %d\n",
|
||||
(int)data.length));
|
||||
if (DEBUGLVL(10)) {
|
||||
file_save("ntlogon.dat", data.data, data.length);
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
Reference in New Issue
Block a user