summaryrefslogtreecommitdiff
path: root/source4/libcli
diff options
context:
space:
mode:
Diffstat (limited to 'source4/libcli')
-rw-r--r--source4/libcli/cldap/cldap.c47
-rw-r--r--source4/libcli/cldap/cldap.h14
-rw-r--r--source4/libcli/dgram/browse.c16
-rw-r--r--source4/libcli/dgram/dgramsocket.c24
-rw-r--r--source4/libcli/dgram/libdgram.h24
-rw-r--r--source4/libcli/dgram/mailslot.c25
-rw-r--r--source4/libcli/dgram/netlogon.c16
-rw-r--r--source4/libcli/dgram/ntlogon.c17
-rw-r--r--source4/libcli/nbt/libnbt.h14
-rw-r--r--source4/libcli/nbt/namequery.c24
-rw-r--r--source4/libcli/nbt/namerefresh.c12
-rw-r--r--source4/libcli/nbt/nameregister.c12
-rw-r--r--source4/libcli/nbt/namerelease.c12
-rw-r--r--source4/libcli/nbt/nbtsocket.c39
-rw-r--r--source4/libcli/wrepl/winsrepl.c12
15 files changed, 168 insertions, 140 deletions
diff --git a/source4/libcli/cldap/cldap.c b/source4/libcli/cldap/cldap.c
index a6710cf32c..490a03d50e 100644
--- a/source4/libcli/cldap/cldap.c
+++ b/source4/libcli/cldap/cldap.c
@@ -62,8 +62,7 @@ static void cldap_socket_recv(struct cldap_socket *cldap)
{
TALLOC_CTX *tmp_ctx = talloc_new(cldap);
NTSTATUS status;
- const char *src_addr;
- int src_port;
+ struct socket_address *src;
DATA_BLOB blob;
size_t nread, dsize;
struct asn1_data asn1;
@@ -83,16 +82,15 @@ static void cldap_socket_recv(struct cldap_socket *cldap)
}
status = socket_recvfrom(cldap->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 cldap packet of length %d from %s:%d\n",
- (int)blob.length, src_addr, src_port));
+ (int)blob.length, src->addr, src->port));
if (!asn1_load(&asn1, blob)) {
DEBUG(2,("Failed to setup for asn.1 decode\n"));
@@ -118,10 +116,10 @@ static void cldap_socket_recv(struct cldap_socket *cldap)
req = idr_find(cldap->idr, ldap_msg->messageid);
if (req == NULL) {
if (cldap->incoming.handler) {
- cldap->incoming.handler(cldap, ldap_msg, src_addr, src_port);
+ cldap->incoming.handler(cldap, ldap_msg, src);
} else {
DEBUG(2,("Mismatched cldap reply %u from %s:%d\n",
- ldap_msg->messageid, src_addr, src_port));
+ ldap_msg->messageid, src->addr, src->port));
}
talloc_free(tmp_ctx);
return;
@@ -157,7 +155,7 @@ static void cldap_request_timeout(struct event_context *event_ctx,
req->num_retries--;
socket_sendto(req->cldap->sock, &req->encoded, &len, 0,
- req->dest_addr, req->dest_port);
+ req->dest);
req->te = event_add_timed(req->cldap->event_ctx, req,
timeval_current_ofs(req->timeout, 0),
@@ -184,10 +182,10 @@ static void cldap_socket_send(struct cldap_socket *cldap)
len = req->encoded.length;
status = socket_sendto(cldap->sock, &req->encoded, &len, 0,
- req->dest_addr, req->dest_port);
+ req->dest);
if (NT_STATUS_IS_ERR(status)) {
DEBUG(3,("Failed to send cldap request of length %u to %s:%d\n",
- (unsigned)req->encoded.length, req->dest_addr, req->dest_port));
+ (unsigned)req->encoded.length, req->dest->addr, req->dest->port));
DLIST_REMOVE(cldap->send_queue, req);
talloc_free(req);
continue;
@@ -278,7 +276,7 @@ failed:
*/
NTSTATUS cldap_set_incoming_handler(struct cldap_socket *cldap,
void (*handler)(struct cldap_socket *, struct ldap_message *,
- const char *, int ),
+ struct socket_address *),
void *private)
{
cldap->incoming.handler = handler;
@@ -306,9 +304,9 @@ struct cldap_request *cldap_search_send(struct cldap_socket *cldap,
req->num_retries = io->in.retries;
req->is_reply = False;
- req->dest_addr = talloc_strdup(req, io->in.dest_address);
- if (req->dest_addr == NULL) goto failed;
- req->dest_port = lp_cldap_port();
+ req->dest = socket_address_from_strings(req, cldap->sock->backend_name,
+ io->in.dest_address, lp_cldap_port());
+ if (!req->dest) goto failed;
req->message_id = idr_get_new_random(cldap->idr, req, UINT16_MAX);
if (req->message_id == -1) goto failed;
@@ -337,7 +335,7 @@ struct cldap_request *cldap_search_send(struct cldap_socket *cldap,
if (!ldap_encode(msg, &req->encoded, req)) {
DEBUG(0,("Failed to encode cldap message to %s:%d\n",
- req->dest_addr, req->dest_port));
+ req->dest->addr, req->dest->port));
goto failed;
}
@@ -370,9 +368,8 @@ NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io)
req->state = CLDAP_REQUEST_SEND;
req->is_reply = True;
- req->dest_addr = talloc_strdup(req, io->dest_address);
- if (req->dest_addr == NULL) goto failed;
- req->dest_port = io->dest_port;
+ req->dest = io->dest;
+ if (talloc_reference(req, io->dest) == NULL) goto failed;
talloc_set_destructor(req, cldap_request_destructor);
@@ -387,7 +384,7 @@ NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io)
if (!ldap_encode(msg, &blob1, req)) {
DEBUG(0,("Failed to encode cldap message to %s:%d\n",
- req->dest_addr, req->dest_port));
+ req->dest->addr, req->dest->port));
status = NT_STATUS_INVALID_PARAMETER;
goto failed;
}
@@ -400,7 +397,7 @@ NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io)
if (!ldap_encode(msg, &blob2, req)) {
DEBUG(0,("Failed to encode cldap message to %s:%d\n",
- req->dest_addr, req->dest_port));
+ req->dest->addr, req->dest->port));
status = NT_STATUS_INVALID_PARAMETER;
goto failed;
}
@@ -620,15 +617,14 @@ NTSTATUS cldap_netlogon(struct cldap_socket *cldap,
*/
NTSTATUS cldap_empty_reply(struct cldap_socket *cldap,
uint32_t message_id,
- const char *src_address, int src_port)
+ struct socket_address *src)
{
NTSTATUS status;
struct cldap_reply reply;
struct ldap_Result result;
reply.messageid = message_id;
- reply.dest_address = src_address;
- reply.dest_port = src_port;
+ reply.dest = src;
reply.response = NULL;
reply.result = &result;
@@ -645,7 +641,7 @@ NTSTATUS cldap_empty_reply(struct cldap_socket *cldap,
*/
NTSTATUS cldap_netlogon_reply(struct cldap_socket *cldap,
uint32_t message_id,
- const char *src_address, int src_port,
+ struct socket_address *src,
uint32_t version,
union nbt_cldap_netlogon *netlogon)
{
@@ -664,8 +660,7 @@ NTSTATUS cldap_netlogon_reply(struct cldap_socket *cldap,
}
reply.messageid = message_id;
- reply.dest_address = src_address;
- reply.dest_port = src_port;
+ reply.dest = src;
reply.response = &response;
reply.result = &result;
diff --git a/source4/libcli/cldap/cldap.h b/source4/libcli/cldap/cldap.h
index 0baaec02df..944510077b 100644
--- a/source4/libcli/cldap/cldap.h
+++ b/source4/libcli/cldap/cldap.h
@@ -41,8 +41,7 @@ struct cldap_request {
enum cldap_request_state state;
/* where to send the request */
- const char *dest_addr;
- int dest_port;
+ struct socket_address *dest;
/* timeout between retries (seconds) */
int timeout;
@@ -87,7 +86,7 @@ struct cldap_socket {
/* what to do with incoming request packets */
struct {
void (*handler)(struct cldap_socket *, struct ldap_message *,
- const char *, int );
+ struct socket_address *);
void *private;
} incoming;
};
@@ -114,7 +113,7 @@ struct cldap_socket *cldap_socket_init(TALLOC_CTX *mem_ctx,
struct event_context *event_ctx);
NTSTATUS cldap_set_incoming_handler(struct cldap_socket *cldap,
void (*handler)(struct cldap_socket *, struct ldap_message *,
- const char *, int ),
+ struct socket_address *),
void *private);
struct cldap_request *cldap_search_send(struct cldap_socket *cldap,
struct cldap_search *io);
@@ -129,8 +128,7 @@ NTSTATUS cldap_search(struct cldap_socket *cldap, TALLOC_CTX *mem_ctx,
*/
struct cldap_reply {
uint32_t messageid;
- const char *dest_address;
- int dest_port;
+ struct socket_address *dest;
struct ldap_SearchResEntry *response;
struct ldap_Result *result;
};
@@ -167,9 +165,9 @@ NTSTATUS cldap_netlogon(struct cldap_socket *cldap,
NTSTATUS cldap_empty_reply(struct cldap_socket *cldap,
uint32_t message_id,
- const char *src_address, int src_port);
+ struct socket_address *src);
NTSTATUS cldap_netlogon_reply(struct cldap_socket *cldap,
uint32_t message_id,
- const char *src_address, int src_port,
+ struct socket_address *src,
uint32_t version,
union nbt_cldap_netlogon *netlogon);
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;
diff --git a/source4/libcli/nbt/libnbt.h b/source4/libcli/nbt/libnbt.h
index 7c9e3e9651..b4411d6fe6 100644
--- a/source4/libcli/nbt/libnbt.h
+++ b/source4/libcli/nbt/libnbt.h
@@ -34,12 +34,6 @@ enum nbt_request_state {NBT_REQUEST_SEND,
NBT_REQUEST_TIMEOUT,
NBT_REQUEST_ERROR};
-/* where to send the request/replies */
-struct nbt_peer_socket {
- const char *addr;
- int port;
-};
-
/*
a nbt name request
*/
@@ -54,7 +48,7 @@ struct nbt_name_request {
struct nbt_name_socket *nbtsock;
/* where to send the request */
- struct nbt_peer_socket dest;
+ struct socket_address *dest;
/* timeout between retries */
int timeout;
@@ -83,7 +77,7 @@ struct nbt_name_request {
uint_t num_replies;
struct nbt_name_reply {
struct nbt_name_packet *packet;
- struct nbt_peer_socket dest;
+ struct socket_address *dest;
} *replies;
/* information on what to do on completion */
@@ -117,14 +111,14 @@ struct nbt_name_socket {
/* what to do with incoming request packets */
struct {
void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
- const struct nbt_peer_socket *);
+ struct socket_address *);
void *private;
} incoming;
/* what to do with unexpected replies */
struct {
void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
- const struct nbt_peer_socket *);
+ struct socket_address *);
void *private;
} unexpected;
};
diff --git a/source4/libcli/nbt/namequery.c b/source4/libcli/nbt/namequery.c
index 38fb2f966d..6566e48a5a 100644
--- a/source4/libcli/nbt/namequery.c
+++ b/source4/libcli/nbt/namequery.c
@@ -22,7 +22,7 @@
#include "includes.h"
#include "libcli/nbt/libnbt.h"
-
+#include "lib/socket/socket.h"
/*
send a nbt name query
*/
@@ -31,7 +31,7 @@ struct nbt_name_request *nbt_name_query_send(struct nbt_name_socket *nbtsock,
{
struct nbt_name_request *req;
struct nbt_name_packet *packet;
- struct nbt_peer_socket dest;
+ struct socket_address *dest;
packet = talloc_zero(nbtsock, struct nbt_name_packet);
if (packet == NULL) return NULL;
@@ -52,9 +52,10 @@ struct nbt_name_request *nbt_name_query_send(struct nbt_name_socket *nbtsock,
packet->questions[0].question_type = NBT_QTYPE_NETBIOS;
packet->questions[0].question_class = NBT_QCLASS_IP;
- dest.port = lp_nbt_port();
- dest.addr = io->in.dest_addr;
- req = nbt_name_request_send(nbtsock, &dest, packet,
+ dest = socket_address_from_strings(packet, nbtsock->sock->backend_name,
+ io->in.dest_addr, lp_nbt_port());
+ if (dest == NULL) goto failed;
+ req = nbt_name_request_send(nbtsock, dest, packet,
io->in.timeout, io->in.retries, False);
if (req == NULL) goto failed;
@@ -84,7 +85,7 @@ NTSTATUS nbt_name_query_recv(struct nbt_name_request *req,
}
packet = req->replies[0].packet;
- io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest.addr);
+ io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest->addr);
if ((packet->operation & NBT_RCODE) != 0) {
status = nbt_rcode_to_ntstatus(packet->operation & NBT_RCODE);
@@ -140,7 +141,7 @@ struct nbt_name_request *nbt_name_status_send(struct nbt_name_socket *nbtsock,
{
struct nbt_name_request *req;
struct nbt_name_packet *packet;
- struct nbt_peer_socket dest;
+ struct socket_address *dest;
packet = talloc_zero(nbtsock, struct nbt_name_packet);
if (packet == NULL) return NULL;
@@ -155,9 +156,10 @@ struct nbt_name_request *nbt_name_status_send(struct nbt_name_socket *nbtsock,
packet->questions[0].question_type = NBT_QTYPE_STATUS;
packet->questions[0].question_class = NBT_QCLASS_IP;
- dest.port = lp_nbt_port();
- dest.addr = io->in.dest_addr;
- req = nbt_name_request_send(nbtsock, &dest, packet,
+ dest = socket_address_from_strings(packet, nbtsock->sock->backend_name,
+ io->in.dest_addr, lp_nbt_port());
+ if (dest == NULL) goto failed;
+ req = nbt_name_request_send(nbtsock, dest, packet,
io->in.timeout, io->in.retries, False);
if (req == NULL) goto failed;
@@ -187,7 +189,7 @@ NTSTATUS nbt_name_status_recv(struct nbt_name_request *req,
}
packet = req->replies[0].packet;
- io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest.addr);
+ io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest->addr);
if ((packet->operation & NBT_RCODE) != 0) {
status = nbt_rcode_to_ntstatus(packet->operation & NBT_RCODE);
diff --git a/source4/libcli/nbt/namerefresh.c b/source4/libcli/nbt/namerefresh.c
index e6464885f7..8940fbb95e 100644
--- a/source4/libcli/nbt/namerefresh.c
+++ b/source4/libcli/nbt/namerefresh.c
@@ -23,6 +23,7 @@
#include "includes.h"
#include "libcli/nbt/libnbt.h"
#include "libcli/composite/composite.h"
+#include "lib/socket/socket.h"
/*
send a nbt name refresh request
@@ -32,7 +33,7 @@ struct nbt_name_request *nbt_name_refresh_send(struct nbt_name_socket *nbtsock,
{
struct nbt_name_request *req;
struct nbt_name_packet *packet;
- struct nbt_peer_socket dest;
+ struct socket_address *dest;
packet = talloc_zero(nbtsock, struct nbt_name_packet);
if (packet == NULL) return NULL;
@@ -66,9 +67,10 @@ struct nbt_name_request *nbt_name_refresh_send(struct nbt_name_socket *nbtsock,
packet->additional[0].rdata.netbios.addresses[0].ipaddr =
talloc_strdup(packet->additional, io->in.address);
- dest.port = lp_nbt_port();
- dest.addr = io->in.dest_addr;
- req = nbt_name_request_send(nbtsock, &dest, packet,
+ dest = socket_address_from_strings(nbtsock, nbtsock->sock->backend_name,
+ io->in.dest_addr, lp_nbt_port());
+ if (dest == NULL) goto failed;
+ req = nbt_name_request_send(nbtsock, dest, packet,
io->in.timeout, io->in.retries, False);
if (req == NULL) goto failed;
@@ -97,7 +99,7 @@ NTSTATUS nbt_name_refresh_recv(struct nbt_name_request *req,
}
packet = req->replies[0].packet;
- io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest.addr);
+ io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest->addr);
if (packet->ancount != 1 ||
packet->answers[0].rr_type != NBT_QTYPE_NETBIOS ||
diff --git a/source4/libcli/nbt/nameregister.c b/source4/libcli/nbt/nameregister.c
index 4f3e046274..5c7e86367f 100644
--- a/source4/libcli/nbt/nameregister.c
+++ b/source4/libcli/nbt/nameregister.c
@@ -23,6 +23,7 @@
#include "includes.h"
#include "libcli/nbt/libnbt.h"
#include "libcli/composite/composite.h"
+#include "lib/socket/socket.h"
/*
send a nbt name registration request
@@ -32,7 +33,7 @@ struct nbt_name_request *nbt_name_register_send(struct nbt_name_socket *nbtsock,
{
struct nbt_name_request *req;
struct nbt_name_packet *packet;
- struct nbt_peer_socket dest;
+ struct socket_address *dest;
packet = talloc_zero(nbtsock, struct nbt_name_packet);
if (packet == NULL) return NULL;
@@ -74,9 +75,10 @@ struct nbt_name_request *nbt_name_register_send(struct nbt_name_socket *nbtsock,
talloc_strdup(packet->additional, io->in.address);
if (packet->additional[0].rdata.netbios.addresses[0].ipaddr == NULL) goto failed;
- dest.port = lp_nbt_port();
- dest.addr = io->in.dest_addr;
- req = nbt_name_request_send(nbtsock, &dest, packet,
+ dest = socket_address_from_strings(packet, nbtsock->sock->backend_name,
+ io->in.dest_addr, lp_nbt_port());
+ if (dest == NULL) goto failed;
+ req = nbt_name_request_send(nbtsock, dest, packet,
io->in.timeout, io->in.retries, False);
if (req == NULL) goto failed;
@@ -105,7 +107,7 @@ NTSTATUS nbt_name_register_recv(struct nbt_name_request *req,
}
packet = req->replies[0].packet;
- io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest.addr);
+ io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest->addr);
if (packet->ancount != 1 ||
packet->answers[0].rr_type != NBT_QTYPE_NETBIOS ||
diff --git a/source4/libcli/nbt/namerelease.c b/source4/libcli/nbt/namerelease.c
index 0a0cd45276..e8dc175b36 100644
--- a/source4/libcli/nbt/namerelease.c
+++ b/source4/libcli/nbt/namerelease.c
@@ -22,6 +22,7 @@
#include "includes.h"
#include "libcli/nbt/libnbt.h"
+#include "lib/socket/socket.h"
/*
send a nbt name release request
@@ -31,7 +32,7 @@ struct nbt_name_request *nbt_name_release_send(struct nbt_name_socket *nbtsock,
{
struct nbt_name_request *req;
struct nbt_name_packet *packet;
- struct nbt_peer_socket dest;
+ struct socket_address *dest;
packet = talloc_zero(nbtsock, struct nbt_name_packet);
if (packet == NULL) return NULL;
@@ -65,9 +66,10 @@ struct nbt_name_request *nbt_name_release_send(struct nbt_name_socket *nbtsock,
packet->additional[0].rdata.netbios.addresses[0].ipaddr =
talloc_strdup(packet->additional, io->in.address);
- dest.port = lp_nbt_port();
- dest.addr = io->in.dest_addr;
- req = nbt_name_request_send(nbtsock, &dest, packet,
+ dest = socket_address_from_strings(packet, nbtsock->sock->backend_name,
+ io->in.dest_addr, lp_nbt_port());
+ if (dest == NULL) goto failed;
+ req = nbt_name_request_send(nbtsock, dest, packet,
io->in.timeout, io->in.retries, False);
if (req == NULL) goto failed;
@@ -96,7 +98,7 @@ NTSTATUS nbt_name_release_recv(struct nbt_name_request *req,
}
packet = req->replies[0].packet;
- io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest.addr);
+ io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest->addr);
if (packet->ancount != 1 ||
packet->answers[0].rr_type != NBT_QTYPE_NETBIOS ||
diff --git a/source4/libcli/nbt/nbtsocket.c b/source4/libcli/nbt/nbtsocket.c
index 1c41b80fdb..42b92b14cc 100644
--- a/source4/libcli/nbt/nbtsocket.c
+++ b/source4/libcli/nbt/nbtsocket.c
@@ -73,7 +73,7 @@ static void nbt_name_socket_send(struct nbt_name_socket *nbtsock)
len = req->encoded.length;
status = socket_sendto(nbtsock->sock, &req->encoded, &len, 0,
- req->dest.addr, req->dest.port);
+ req->dest);
if (NT_STATUS_IS_ERR(status)) goto failed;
if (!NT_STATUS_IS_OK(status)) {
@@ -153,7 +153,7 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
{
TALLOC_CTX *tmp_ctx = talloc_new(nbtsock);
NTSTATUS status;
- struct nbt_peer_socket src;
+ struct socket_address *src;
DATA_BLOB blob;
size_t nread, dsize;
struct nbt_name_packet *packet;
@@ -172,13 +172,11 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
}
status = socket_recvfrom(nbtsock->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;
packet = talloc(tmp_ctx, struct nbt_name_packet);
if (packet == NULL) {
@@ -198,7 +196,7 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
if (DEBUGLVL(10)) {
DEBUG(10,("Received nbt packet of length %d from %s:%d\n",
- (int)blob.length, src.addr, src.port));
+ (int)blob.length, src->addr, src->port));
NDR_PRINT_DEBUG(nbt_name_packet, packet);
}
@@ -206,7 +204,7 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
handler, if any */
if (!(packet->operation & NBT_FLAG_REPLY)) {
if (nbtsock->incoming.handler) {
- nbtsock->incoming.handler(nbtsock, packet, &src);
+ nbtsock->incoming.handler(nbtsock, packet, src);
}
talloc_free(tmp_ctx);
return;
@@ -216,7 +214,7 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
req = idr_find(nbtsock->idr, packet->name_trn_id);
if (req == NULL) {
if (nbtsock->unexpected.handler) {
- nbtsock->unexpected.handler(nbtsock, packet, &src);
+ nbtsock->unexpected.handler(nbtsock, packet, src);
} else {
DEBUG(2,("Failed to match request for incoming name packet id 0x%04x on %p\n",
packet->name_trn_id, nbtsock));
@@ -258,9 +256,10 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
goto done;
}
- req->replies[req->num_replies].dest.addr = talloc_steal(req, src.addr);
- req->replies[req->num_replies].dest.port = src.port;
- req->replies[req->num_replies].packet = talloc_steal(req, packet);
+ talloc_steal(req, src);
+ req->replies[req->num_replies].dest = src;
+ talloc_steal(req, packet);
+ req->replies[req->num_replies].packet = packet;
req->num_replies++;
/* if we don't want multiple replies then we are done */
@@ -348,7 +347,7 @@ failed:
send off a nbt name request
*/
struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock,
- const struct nbt_peer_socket *dest,
+ struct socket_address *dest,
struct nbt_name_packet *request,
int timeout, int retries,
BOOL allow_multiple_replies)
@@ -366,9 +365,8 @@ struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock,
req->is_reply = False;
req->timeout = timeout;
req->num_retries = retries;
- 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;
/* we select a random transaction id unless the user supplied one */
if (request->name_trn_id == 0) {
@@ -397,7 +395,7 @@ struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock,
if (DEBUGLVL(10)) {
DEBUG(10,("Queueing nbt packet to %s:%d\n",
- req->dest.addr, req->dest.port));
+ req->dest->addr, req->dest->port));
NDR_PRINT_DEBUG(nbt_name_packet, request);
}
@@ -415,7 +413,7 @@ failed:
send off a nbt name reply
*/
NTSTATUS nbt_name_reply_send(struct nbt_name_socket *nbtsock,
- const struct nbt_peer_socket *dest,
+ struct socket_address *dest,
struct nbt_name_packet *request)
{
struct nbt_name_request *req;
@@ -425,9 +423,8 @@ NTSTATUS nbt_name_reply_send(struct nbt_name_socket *nbtsock,
NT_STATUS_HAVE_NO_MEMORY(req);
req->nbtsock = nbtsock;
- 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;
req->state = NBT_REQUEST_SEND;
req->is_reply = True;
@@ -480,7 +477,7 @@ NTSTATUS nbt_name_request_recv(struct nbt_name_request *req)
*/
NTSTATUS nbt_set_incoming_handler(struct nbt_name_socket *nbtsock,
void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
- const struct nbt_peer_socket *),
+ struct socket_address *),
void *private)
{
nbtsock->incoming.handler = handler;
diff --git a/source4/libcli/wrepl/winsrepl.c b/source4/libcli/wrepl/winsrepl.c
index 0409607aa9..909bedf530 100644
--- a/source4/libcli/wrepl/winsrepl.c
+++ b/source4/libcli/wrepl/winsrepl.c
@@ -311,6 +311,7 @@ struct composite_context *wrepl_connect_send(struct wrepl_socket *wrepl_socket,
{
struct composite_context *result;
struct wrepl_connect_state *state;
+ struct socket_address *peer, *us;
result = talloc_zero(wrepl_socket, struct composite_context);
if (!result) return NULL;
@@ -328,8 +329,15 @@ struct composite_context *wrepl_connect_send(struct wrepl_socket *wrepl_socket,
our_ip = iface_best_ip(peer_ip);
}
- state->creq = socket_connect_send(wrepl_socket->sock, our_ip, 0,
- peer_ip, WINS_REPLICATION_PORT,
+ us = socket_address_from_strings(state, wrepl_socket->sock->backend_name,
+ our_ip, 0);
+ if (composite_nomem(us, result)) return result;
+
+ peer = socket_address_from_strings(state, wrepl_socket->sock->backend_name,
+ peer_ip, WINS_REPLICATION_PORT);
+ if (composite_nomem(peer, result)) return result;
+
+ state->creq = socket_connect_send(wrepl_socket->sock, us, peer,
0, wrepl_socket->event.ctx);
composite_continue(result, state->creq, wrepl_connect_handler, state);
return result;