diff options
Diffstat (limited to 'source4/libcli/dgram')
-rw-r--r-- | source4/libcli/dgram/browse.c | 16 | ||||
-rw-r--r-- | source4/libcli/dgram/dgramsocket.c | 24 | ||||
-rw-r--r-- | source4/libcli/dgram/libdgram.h | 24 | ||||
-rw-r--r-- | source4/libcli/dgram/mailslot.c | 25 | ||||
-rw-r--r-- | source4/libcli/dgram/netlogon.c | 16 | ||||
-rw-r--r-- | source4/libcli/dgram/ntlogon.c | 17 |
6 files changed, 75 insertions, 47 deletions
diff --git a/source4/libcli/dgram/browse.c b/source4/libcli/dgram/browse.c index 821bf9d815..433d1c1971 100644 --- a/source4/libcli/dgram/browse.c +++ b/source4/libcli/dgram/browse.c @@ -23,9 +23,10 @@ #include "includes.h" #include "libcli/dgram/libdgram.h" +#include "lib/socket/socket.h" NTSTATUS dgram_mailslot_browse_send(struct nbt_dgram_socket *dgmsock, - struct nbt_name *dest_name, const struct nbt_peer_socket *dest, + struct nbt_name *dest_name, struct socket_address *dest, struct nbt_name *src_name, struct nbt_browse_packet *request) { NTSTATUS status; @@ -55,7 +56,7 @@ NTSTATUS dgram_mailslot_browse_reply(struct nbt_dgram_socket *dgmsock, DATA_BLOB blob; TALLOC_CTX *tmp_ctx = talloc_new(dgmsock); struct nbt_name myname; - struct nbt_peer_socket dest; + struct socket_address *dest; status = ndr_push_struct_blob(&blob, tmp_ctx, reply, (ndr_push_flags_fn_t)ndr_push_nbt_browse_packet); @@ -66,12 +67,17 @@ NTSTATUS dgram_mailslot_browse_reply(struct nbt_dgram_socket *dgmsock, make_nbt_name_client(&myname, lp_netbios_name()); - dest.port = request->src_port; - dest.addr = request->src_addr; + 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, + dest, &myname, &blob); talloc_free(tmp_ctx); return status; diff --git a/source4/libcli/dgram/dgramsocket.c b/source4/libcli/dgram/dgramsocket.c index 143b9c309b..326ec7e908 100644 --- a/source4/libcli/dgram/dgramsocket.c +++ b/source4/libcli/dgram/dgramsocket.c @@ -34,7 +34,7 @@ static void dgm_socket_recv(struct nbt_dgram_socket *dgmsock) { TALLOC_CTX *tmp_ctx = talloc_new(dgmsock); NTSTATUS status; - struct nbt_peer_socket src; + struct socket_address *src; DATA_BLOB blob; size_t nread, dsize; struct nbt_dgram_packet *packet; @@ -53,16 +53,15 @@ static void dgm_socket_recv(struct nbt_dgram_socket *dgmsock) } status = socket_recvfrom(dgmsock->sock, blob.data, blob.length, &nread, 0, - &src.addr, &src.port); + tmp_ctx, &src); if (!NT_STATUS_IS_OK(status)) { talloc_free(tmp_ctx); return; } - talloc_steal(tmp_ctx, src.addr); blob.length = nread; DEBUG(2,("Received dgram packet of length %d from %s:%d\n", - (int)blob.length, src.addr, src.port)); + (int)blob.length, src->addr, src->port)); packet = talloc(tmp_ctx, struct nbt_dgram_packet); if (packet == NULL) { @@ -86,14 +85,14 @@ static void dgm_socket_recv(struct nbt_dgram_socket *dgmsock) struct dgram_mailslot_handler *dgmslot; dgmslot = dgram_mailslot_find(dgmsock, mailslot_name); if (dgmslot) { - dgmslot->handler(dgmslot, packet, &src); + 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); + dgmsock->incoming.handler(dgmsock, packet, src); } } @@ -114,10 +113,10 @@ static void dgm_socket_send(struct nbt_dgram_socket *dgmsock) len = req->encoded.length; status = socket_sendto(dgmsock->sock, &req->encoded, &len, 0, - req->dest.addr, req->dest.port); + 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, + (unsigned)req->encoded.length, req->dest->addr, req->dest->port, nt_errstr(status))); DLIST_REMOVE(dgmsock->send_queue, req); talloc_free(req); @@ -200,7 +199,7 @@ failed: NTSTATUS dgram_set_incoming_handler(struct nbt_dgram_socket *dgmsock, void (*handler)(struct nbt_dgram_socket *, struct nbt_dgram_packet *, - const struct nbt_peer_socket *), + struct socket_address *), void *private) { dgmsock->incoming.handler = handler; @@ -215,7 +214,7 @@ NTSTATUS dgram_set_incoming_handler(struct nbt_dgram_socket *dgmsock, */ NTSTATUS nbt_dgram_send(struct nbt_dgram_socket *dgmsock, struct nbt_dgram_packet *packet, - const struct nbt_peer_socket *dest) + struct socket_address *dest) { struct nbt_dgram_request *req; NTSTATUS status = NT_STATUS_NO_MEMORY; @@ -223,9 +222,8 @@ NTSTATUS nbt_dgram_send(struct nbt_dgram_socket *dgmsock, req = talloc(dgmsock, struct nbt_dgram_request); if (req == NULL) goto failed; - req->dest.port = dest->port; - req->dest.addr = talloc_strdup(req, dest->addr); - if (req->dest.addr == 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); diff --git a/source4/libcli/dgram/libdgram.h b/source4/libcli/dgram/libdgram.h index f913e90d88..d5e28ed03d 100644 --- a/source4/libcli/dgram/libdgram.h +++ b/source4/libcli/dgram/libdgram.h @@ -29,7 +29,7 @@ struct nbt_dgram_request { struct nbt_dgram_request *next, *prev; /* where to send the request */ - struct nbt_peer_socket dest; + struct socket_address *dest; /* the encoded request */ DATA_BLOB encoded; @@ -54,7 +54,7 @@ struct nbt_dgram_socket { /* what to do with incoming request packets */ struct { void (*handler)(struct nbt_dgram_socket *, struct nbt_dgram_packet *, - const struct nbt_peer_socket *src); + struct socket_address *src); void *private; } incoming; }; @@ -70,7 +70,7 @@ struct nbt_dgram_socket { typedef void (*dgram_mailslot_handler_t)(struct dgram_mailslot_handler *, struct nbt_dgram_packet *, - const struct nbt_peer_socket *src); + struct socket_address *src); struct dgram_mailslot_handler { struct dgram_mailslot_handler *next, *prev; @@ -86,11 +86,11 @@ struct dgram_mailslot_handler { /* prototypes */ NTSTATUS nbt_dgram_send(struct nbt_dgram_socket *dgmsock, struct nbt_dgram_packet *packet, - const struct nbt_peer_socket *dest); + struct socket_address *dest); NTSTATUS dgram_set_incoming_handler(struct nbt_dgram_socket *dgmsock, void (*handler)(struct nbt_dgram_socket *, struct nbt_dgram_packet *, - const struct nbt_peer_socket *), + struct socket_address *), void *private); struct nbt_dgram_socket *nbt_dgram_socket_init(TALLOC_CTX *mem_ctx, struct event_context *event_ctx); @@ -113,13 +113,13 @@ 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 struct nbt_peer_socket *dest, + 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, - const struct nbt_peer_socket *dest, + struct socket_address *dest, struct nbt_name *src_name, struct nbt_netlogon_packet *request); NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock, @@ -132,11 +132,11 @@ NTSTATUS dgram_mailslot_netlogon_parse(struct dgram_mailslot_handler *dgmslot, 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, - const struct nbt_peer_socket *dest, - struct nbt_name *src_name, - struct nbt_ntlogon_packet *request); + 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, diff --git a/source4/libcli/dgram/mailslot.c b/source4/libcli/dgram/mailslot.c index 0e6b99c3e3..33bca166ce 100644 --- a/source4/libcli/dgram/mailslot.c +++ b/source4/libcli/dgram/mailslot.c @@ -151,28 +151,39 @@ 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 struct nbt_peer_socket *_dest, + 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 nbt_peer_socket dest = *_dest; + 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.port = lp_dgram_port(); + 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; - packet.src_addr = socket_get_my_addr(dgmsock->sock, tmp_ctx); - packet.src_port = socket_get_my_port(dgmsock->sock); + 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 @@ -198,7 +209,7 @@ NTSTATUS dgram_mailslot_send(struct nbt_dgram_socket *dgmsock, trans->mailslot_name = mailslot_name; trans->data = *request; - status = nbt_dgram_send(dgmsock, &packet, &dest); + status = nbt_dgram_send(dgmsock, &packet, dest); talloc_free(tmp_ctx); diff --git a/source4/libcli/dgram/netlogon.c b/source4/libcli/dgram/netlogon.c index dffeae2007..6ad4c28811 100644 --- a/source4/libcli/dgram/netlogon.c +++ b/source4/libcli/dgram/netlogon.c @@ -22,13 +22,14 @@ #include "includes.h" #include "libcli/dgram/libdgram.h" +#include "lib/socket/socket.h" /* send a netlogon mailslot request */ NTSTATUS dgram_mailslot_netlogon_send(struct nbt_dgram_socket *dgmsock, struct nbt_name *dest_name, - const struct nbt_peer_socket *dest, + struct socket_address *dest, struct nbt_name *src_name, struct nbt_netlogon_packet *request) { @@ -65,7 +66,7 @@ NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock, DATA_BLOB blob; TALLOC_CTX *tmp_ctx = talloc_new(dgmsock); struct nbt_name myname; - struct nbt_peer_socket dest; + struct socket_address *dest; status = ndr_push_struct_blob(&blob, tmp_ctx, reply, (ndr_push_flags_fn_t)ndr_push_nbt_netlogon_packet); @@ -76,12 +77,17 @@ NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock, make_nbt_name_client(&myname, lp_netbios_name()); - dest.port = request->src_port; - dest.addr = request->src_addr; + 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, + dest, &myname, &blob); talloc_free(tmp_ctx); return status; diff --git a/source4/libcli/dgram/ntlogon.c b/source4/libcli/dgram/ntlogon.c index 3205416cea..ecd6bd4587 100644 --- a/source4/libcli/dgram/ntlogon.c +++ b/source4/libcli/dgram/ntlogon.c @@ -22,6 +22,7 @@ #include "includes.h" #include "libcli/dgram/libdgram.h" +#include "lib/socket/socket.h" /* send a ntlogon mailslot request @@ -29,7 +30,7 @@ NTSTATUS dgram_mailslot_ntlogon_send(struct nbt_dgram_socket *dgmsock, enum dgram_msg_type msg_type, struct nbt_name *dest_name, - const struct nbt_peer_socket *dest, + struct socket_address *dest, struct nbt_name *src_name, struct nbt_ntlogon_packet *request) { @@ -66,7 +67,7 @@ NTSTATUS dgram_mailslot_ntlogon_reply(struct nbt_dgram_socket *dgmsock, DATA_BLOB blob; TALLOC_CTX *tmp_ctx = talloc_new(dgmsock); struct nbt_name myname; - struct nbt_peer_socket dest; + struct socket_address *dest; status = ndr_push_struct_blob(&blob, tmp_ctx, reply, (ndr_push_flags_fn_t)ndr_push_nbt_ntlogon_packet); @@ -77,12 +78,18 @@ NTSTATUS dgram_mailslot_ntlogon_reply(struct nbt_dgram_socket *dgmsock, make_nbt_name_client(&myname, lp_netbios_name()); - dest.port = request->src_port; - dest.addr = request->src_addr; + 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, + dest, &myname, &blob); talloc_free(tmp_ctx); return status; |