const struct smb_transports *transports,
const char *called_name, int called_type,
const char *calling_name, int calling_type,
- int *pfd, uint16_t *ret_port, int sec_timeout)
+ int sec_timeout,
+ TALLOC_CTX *mem_ctx,
+ struct smbXcli_transport **ptransport)
{
TALLOC_CTX *frame = talloc_stackframe();
struct tevent_context *ev;
struct tevent_req *req;
NTSTATUS status = NT_STATUS_NO_MEMORY;
+ int fd = -1;
+ uint16_t ret_port = 0;
ev = samba_tevent_context_init(frame);
if (ev == NULL) {
if (!tevent_req_poll_ntstatus(req, ev, &status)) {
goto fail;
}
- status = smbsock_connect_recv(req, pfd, ret_port);
+ status = smbsock_connect_recv(req, &fd, &ret_port);
+ if (NT_STATUS_IS_OK(status)) {
+ struct smb_transport tp = {
+ .type = SMB_TRANSPORT_TYPE_UNKNOWN,
+ .port = ret_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;
+ }
+ }
fail:
TALLOC_FREE(frame);
return status;
const struct smb_transports *transports,
const char *called_name, int called_type,
const char *calling_name, int calling_type,
- int *pfd, uint16_t *ret_port, int sec_timeout)
- NONNULL(1) NONNULL(2) NONNULL(3) NONNULL(8);
+ int sec_timeout,
+ TALLOC_CTX *mem_ctx,
+ struct smbXcli_transport **ptransport)
+ NONNULL(1) NONNULL(2) NONNULL(3) NONNULL(10);
struct tevent_req *smbsock_any_connect_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
static bool connect_preferred_dc(TALLOC_CTX *mem_ctx,
struct winbindd_domain *domain,
uint32_t request_flags,
- int *fd)
+ struct smbXcli_transport **ptransport)
{
char *saf_servername = NULL;
struct smb_transports ts =
status = smbsock_connect(&domain->dcaddr, lp_ctx, &ts,
domain->dcname, -1, NULL, -1,
- fd, NULL, 10);
+ 10, NULL, ptransport);
if (!NT_STATUS_IS_OK(status)) {
winbind_add_failed_connection_entry(domain,
domain->dcname,
NT_STATUS_UNSUCCESSFUL);
return false;
}
+ talloc_reparent(NULL, mem_ctx, *ptransport);
return true;
fail:
smb_transports_parse("client smb transports",
lp_client_smb_transports());
int i;
- int fd = -1;
size_t fd_index;
- struct smb_transport tp = { .type = SMB_TRANSPORT_TYPE_UNKNOWN, };
struct smbXcli_transport *xtp = NULL;
NTSTATUS status;
D_NOTICE("First try to connect to the closest DC (using server "
"affinity cache). If this fails, try to lookup the DC using "
"DNS afterwards.\n");
- ok = connect_preferred_dc(mem_ctx, domain, request_flags, &fd);
+ ok = connect_preferred_dc(mem_ctx, domain, request_flags, &xtp);
if (ok) {
goto return_transport;
}
TALLOC_FREE(addrs);
num_addrs = 0;
- if (fd != -1) {
- close(fd);
- fd = -1;
- }
TALLOC_FREE(xtp);
/*
goto again;
return_transport:
- if (fd != -1) {
- set_socket_options(fd, lp_socket_options());
- xtp = smbXcli_transport_bsd(NULL, fd, &tp);
- if (xtp == NULL) {
- close(fd);
- DBG_ERR("smbXcli_transport_bsd() failed\n");
- return false;
- }
- }
*ptransport = talloc_move(mem_ctx, &xtp);