diff options
Diffstat (limited to 'source4/libcli/nbt')
-rw-r--r-- | source4/libcli/nbt/libnbt.h | 16 | ||||
-rw-r--r-- | source4/libcli/nbt/namequery.c | 18 | ||||
-rw-r--r-- | source4/libcli/nbt/namerefresh.c | 9 | ||||
-rw-r--r-- | source4/libcli/nbt/nameregister.c | 9 | ||||
-rw-r--r-- | source4/libcli/nbt/namerelease.c | 9 | ||||
-rw-r--r-- | source4/libcli/nbt/nbtsocket.c | 39 |
6 files changed, 59 insertions, 41 deletions
diff --git a/source4/libcli/nbt/libnbt.h b/source4/libcli/nbt/libnbt.h index 5a53510ccf..218b5e5921 100644 --- a/source4/libcli/nbt/libnbt.h +++ b/source4/libcli/nbt/libnbt.h @@ -31,6 +31,12 @@ 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 */ @@ -45,8 +51,7 @@ struct nbt_name_request { struct nbt_name_socket *nbtsock; /* where to send the request */ - const char *dest_addr; - int dest_port; + struct nbt_peer_socket dest; /* timeout between retries */ int timeout; @@ -75,8 +80,7 @@ struct nbt_name_request { uint_t num_replies; struct nbt_name_reply { struct nbt_name_packet *packet; - const char *reply_addr; - int reply_port; + struct nbt_peer_socket dest; } *replies; /* information on what to do on completion */ @@ -110,14 +114,14 @@ struct nbt_name_socket { /* what to do with incoming request packets */ struct { void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *, - const char *, int ); + const struct nbt_peer_socket *); void *private; } incoming; /* what to do with unexpected replies */ struct { void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *, - const char *, int ); + const struct nbt_peer_socket *); void *private; } unexpected; }; diff --git a/source4/libcli/nbt/namequery.c b/source4/libcli/nbt/namequery.c index f222148f4d..c0a1e274e2 100644 --- a/source4/libcli/nbt/namequery.c +++ b/source4/libcli/nbt/namequery.c @@ -31,6 +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; packet = talloc_zero(nbtsock, struct nbt_name_packet); if (packet == NULL) return NULL; @@ -50,8 +51,10 @@ struct nbt_name_request *nbt_name_query_send(struct nbt_name_socket *nbtsock, packet->questions[0].name = io->in.name; packet->questions[0].question_type = NBT_QTYPE_NETBIOS; packet->questions[0].question_class = NBT_QCLASS_IP; - - req = nbt_name_request_send(nbtsock, io->in.dest_addr, lp_nbt_port(), packet, + + dest.port = lp_nbt_port(); + dest.addr = io->in.dest_addr; + req = nbt_name_request_send(nbtsock, &dest, packet, io->in.timeout, io->in.retries, False); if (req == NULL) goto failed; @@ -81,7 +84,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].reply_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); @@ -137,6 +140,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; packet = talloc_zero(nbtsock, struct nbt_name_packet); if (packet == NULL) return NULL; @@ -150,8 +154,10 @@ struct nbt_name_request *nbt_name_status_send(struct nbt_name_socket *nbtsock, packet->questions[0].name = io->in.name; packet->questions[0].question_type = NBT_QTYPE_STATUS; packet->questions[0].question_class = NBT_QCLASS_IP; - - req = nbt_name_request_send(nbtsock, io->in.dest_addr, lp_nbt_port(), packet, + + dest.port = lp_nbt_port(); + dest.addr = io->in.dest_addr; + req = nbt_name_request_send(nbtsock, &dest, packet, io->in.timeout, io->in.retries, False); if (req == NULL) goto failed; @@ -181,7 +187,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].reply_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 d9f2070d4c..e6464885f7 100644 --- a/source4/libcli/nbt/namerefresh.c +++ b/source4/libcli/nbt/namerefresh.c @@ -32,6 +32,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; packet = talloc_zero(nbtsock, struct nbt_name_packet); if (packet == NULL) return NULL; @@ -64,8 +65,10 @@ struct nbt_name_request *nbt_name_refresh_send(struct nbt_name_socket *nbtsock, packet->additional[0].rdata.netbios.addresses[0].nb_flags = io->in.nb_flags; packet->additional[0].rdata.netbios.addresses[0].ipaddr = talloc_strdup(packet->additional, io->in.address); - - req = nbt_name_request_send(nbtsock, io->in.dest_addr, lp_nbt_port(), packet, + + dest.port = lp_nbt_port(); + dest.addr = io->in.dest_addr; + req = nbt_name_request_send(nbtsock, &dest, packet, io->in.timeout, io->in.retries, False); if (req == NULL) goto failed; @@ -94,7 +97,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].reply_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 4dac500780..4f3e046274 100644 --- a/source4/libcli/nbt/nameregister.c +++ b/source4/libcli/nbt/nameregister.c @@ -32,6 +32,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; packet = talloc_zero(nbtsock, struct nbt_name_packet); if (packet == NULL) return NULL; @@ -72,8 +73,10 @@ struct nbt_name_request *nbt_name_register_send(struct nbt_name_socket *nbtsock, packet->additional[0].rdata.netbios.addresses[0].ipaddr = talloc_strdup(packet->additional, io->in.address); if (packet->additional[0].rdata.netbios.addresses[0].ipaddr == NULL) goto failed; - - req = nbt_name_request_send(nbtsock, io->in.dest_addr, lp_nbt_port(), packet, + + dest.port = lp_nbt_port(); + dest.addr = io->in.dest_addr; + req = nbt_name_request_send(nbtsock, &dest, packet, io->in.timeout, io->in.retries, False); if (req == NULL) goto failed; @@ -102,7 +105,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].reply_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 208c73d386..0a0cd45276 100644 --- a/source4/libcli/nbt/namerelease.c +++ b/source4/libcli/nbt/namerelease.c @@ -31,6 +31,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; packet = talloc_zero(nbtsock, struct nbt_name_packet); if (packet == NULL) return NULL; @@ -63,8 +64,10 @@ struct nbt_name_request *nbt_name_release_send(struct nbt_name_socket *nbtsock, packet->additional[0].rdata.netbios.addresses[0].nb_flags = io->in.nb_flags; packet->additional[0].rdata.netbios.addresses[0].ipaddr = talloc_strdup(packet->additional, io->in.address); - - req = nbt_name_request_send(nbtsock, io->in.dest_addr, lp_nbt_port(), packet, + + dest.port = lp_nbt_port(); + dest.addr = io->in.dest_addr; + req = nbt_name_request_send(nbtsock, &dest, packet, io->in.timeout, io->in.retries, False); if (req == NULL) goto failed; @@ -93,7 +96,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].reply_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 f40ec84e77..905541e74a 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.addr, req->dest.port); if (NT_STATUS_IS_ERR(status)) goto failed; if (!NT_STATUS_IS_OK(status)) { @@ -153,8 +153,7 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock) { TALLOC_CTX *tmp_ctx = talloc_new(nbtsock); NTSTATUS status; - const char *src_addr; - int src_port; + struct nbt_peer_socket src; DATA_BLOB blob; size_t nread, dsize; struct nbt_name_packet *packet; @@ -173,12 +172,12 @@ 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); + &src.addr, &src.port); if (!NT_STATUS_IS_OK(status)) { talloc_free(tmp_ctx); return; } - talloc_steal(tmp_ctx, src_addr); + talloc_steal(tmp_ctx, src.addr); blob.length = nread; packet = talloc(tmp_ctx, struct nbt_name_packet); @@ -199,7 +198,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); } @@ -207,7 +206,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_addr, src_port); + nbtsock->incoming.handler(nbtsock, packet, &src); } talloc_free(tmp_ctx); return; @@ -217,7 +216,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_addr, src_port); + 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)); @@ -259,8 +258,8 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock) goto done; } - req->replies[req->num_replies].reply_addr = talloc_steal(req, src_addr); - req->replies[req->num_replies].reply_port = src_port; + 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); req->num_replies++; @@ -349,7 +348,7 @@ failed: send off a nbt name request */ struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock, - const char *dest_addr, int dest_port, + const struct nbt_peer_socket *dest, struct nbt_name_packet *request, int timeout, int retries, BOOL allow_multiple_replies) @@ -362,14 +361,14 @@ struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock, if (req == NULL) goto failed; req->nbtsock = nbtsock; - req->dest_port = dest_port; req->allow_multiple_replies = allow_multiple_replies; req->state = NBT_REQUEST_SEND; req->is_reply = False; req->timeout = timeout; req->num_retries = retries; - req->dest_addr = talloc_strdup(req, dest_addr); - if (req->dest_addr == NULL) goto failed; + req->dest.port = dest->port; + req->dest.addr = talloc_strdup(req, dest->addr); + if (req->dest.addr == NULL) goto failed; /* we select a random transaction id unless the user supplied one */ if (request->name_trn_id == 0) { @@ -398,7 +397,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); } @@ -416,7 +415,7 @@ failed: send off a nbt name reply */ NTSTATUS nbt_name_reply_send(struct nbt_name_socket *nbtsock, - const char *dest_addr, int dest_port, + const struct nbt_peer_socket *dest, struct nbt_name_packet *request) { struct nbt_name_request *req; @@ -426,9 +425,9 @@ NTSTATUS nbt_name_reply_send(struct nbt_name_socket *nbtsock, NT_STATUS_HAVE_NO_MEMORY(req); req->nbtsock = nbtsock; - req->dest_addr = talloc_strdup(req, dest_addr); - if (req->dest_addr == NULL) goto failed; - req->dest_port = dest_port; + req->dest.port = dest->port; + req->dest.addr = talloc_strdup(req, dest->addr); + if (req->dest.addr == NULL) goto failed; req->state = NBT_REQUEST_SEND; req->is_reply = True; @@ -481,7 +480,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 char *, int ), + const struct nbt_peer_socket *), void *private) { nbtsock->incoming.handler = handler; |