subreq, struct tevent_req);
struct cli_connect_sock_state *state = tevent_req_data(
req, struct cli_connect_sock_state);
- struct smb_transport tp = { .type = SMB_TRANSPORT_TYPE_UNKNOWN, };
- int fd;
NTSTATUS status;
- status = smbsock_any_connect_recv(subreq, &fd, NULL, &tp.port);
+ status = smbsock_any_connect_recv(subreq, state, &state->transport, NULL);
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
return;
}
- set_socket_options(fd, lp_socket_options());
-
- state->transport = smbXcli_transport_bsd(state, fd, &tp);
- if (tevent_req_nomem(state->transport, req)) {
- close(fd);
- return;
- }
tevent_req_done(req);
}
size_t num_sent;
size_t num_received;
- int fd;
- uint16_t chosen_port;
+ struct smbXcli_transport *transport;
size_t chosen_index;
};
state->calling_names = calling_names;
state->calling_types = calling_types;
state->transports = *transports;
- state->fd = -1;
tevent_req_set_cleanup_fn(req, smbsock_any_connect_cleanup);
return;
}
- if (state->fd != -1) {
- close(state->fd);
- state->fd = -1;
- }
+ TALLOC_FREE(state->transport);
}
static void smbsock_any_connect_trynext(struct tevent_req *subreq)
state->requests[chosen_index] = NULL;
if (NT_STATUS_IS_OK(status)) {
+ struct smb_transport tp = {
+ .type = SMB_TRANSPORT_TYPE_UNKNOWN,
+ .port = chosen_port,
+ };
+
/*
* tevent_req_done() will kill all the other requests
* via smbsock_any_connect_cleanup().
*/
- state->fd = fd;
- state->chosen_port = chosen_port;
+ set_socket_options(fd, lp_socket_options());
+ state->transport = smbXcli_transport_bsd(state, fd, &tp);
+ if (tevent_req_nomem(state->transport, req)) {
+ close(fd);
+ return;
+ }
state->chosen_index = chosen_index;
tevent_req_done(req);
return;
return;
}
-NTSTATUS smbsock_any_connect_recv(struct tevent_req *req, int *pfd,
- size_t *chosen_index,
- uint16_t *chosen_port)
+NTSTATUS smbsock_any_connect_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ struct smbXcli_transport **ptransport,
+ size_t *chosen_index)
{
struct smbsock_any_connect_state *state = tevent_req_data(
req, struct smbsock_any_connect_state);
tevent_req_received(req);
return status;
}
- *pfd = state->fd;
- state->fd = -1;
+ *ptransport = talloc_move(mem_ctx, &state->transport);
if (chosen_index != NULL) {
*chosen_index = state->chosen_index;
}
- if (chosen_port != NULL) {
- *chosen_port = state->chosen_port;
- }
tevent_req_received(req);
return NT_STATUS_OK;
}
struct tevent_context *ev;
struct tevent_req *req;
NTSTATUS status = NT_STATUS_NO_MEMORY;
- uint16_t chosen_port = 0;
- int fd = -1;
ev = samba_tevent_context_init(frame);
if (ev == NULL) {
if (!tevent_req_poll_ntstatus(req, ev, &status)) {
goto fail;
}
- status = smbsock_any_connect_recv(req, &fd, chosen_index, &chosen_port);
- if (NT_STATUS_IS_OK(status)) {
- struct smb_transport tp = {
- .type = SMB_TRANSPORT_TYPE_UNKNOWN,
- .port = chosen_port,
- };
-
- set_socket_options(fd, lp_socket_options());
- *ptransport = smbXcli_transport_bsd(mem_ctx, fd, &tp);
- if (*ptransport == NULL) {
- close(fd);
- status = NT_STATUS_NO_MEMORY;
- goto fail;
- }
- }
+ status = smbsock_any_connect_recv(req, mem_ctx, ptransport, chosen_index);
fail:
TALLOC_FREE(frame);
return status;
size_t num_addrs,
const struct smb_transports *transports)
NONNULL(2) NONNULL(3) NONNULL(4) NONNULL(10);
-NTSTATUS smbsock_any_connect_recv(struct tevent_req *req, int *pfd,
- size_t *chosen_index, uint16_t *chosen_port);
+NTSTATUS smbsock_any_connect_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ struct smbXcli_transport **ptransport,
+ size_t *chosen_index)
+ NONNULL(1) NONNULL(3);
NTSTATUS smbsock_any_connect(const struct sockaddr_storage *addrs,
const char **called_names,
int *called_types,
#include "includes.h"
#include "system/network.h"
-#include "../lib/async_req/async_sock.h"
#include "../lib/util/tevent_ntstatus.h"
-#include "lib/events/events.h"
#include "libcli/raw/libcliraw.h"
#include "libcli/composite/composite.h"
-#include "lib/socket/socket.h"
#include "libcli/resolve/resolve.h"
#include "param/param.h"
-#include "../libcli/smb/smbXcli_base.h"
#include "libcli/raw/raw_proto.h"
-#include "../libcli/smb/read_smb.h"
#include "lib/util/util_net.h"
#include "../source3/libsmb/smbsock_connect.h"
struct sock_connect_state *state =
tevent_req_callback_data(subreq,
struct sock_connect_state);
- struct smb_transport tp = { .type = SMB_TRANSPORT_TYPE_UNKNOWN, };
- int sockfd = -1;
+ struct smbXcli_transport *xtp = NULL;
state->ctx->status = smbsock_any_connect_recv(subreq,
- &sockfd,
- NULL,
+ state,
+ &xtp,
NULL);
if (!composite_is_ok(state->ctx)) return;
- set_socket_options(sockfd, state->socket_options);
-
state->result = talloc_zero(state, struct smbcli_socket);
if (composite_nomem(state->result, state->ctx)) {
- close(sockfd);
return;
}
- state->result->transport = smbXcli_transport_bsd(state->result,
- sockfd,
- &tp);
- if (composite_nomem(state->result->transport, state->ctx)) {
- close(sockfd);
- return;
- }
+ state->result->transport = talloc_move(state->result, &xtp);
state->result->hostname = talloc_steal(state->result, state->host_name);