#include "../lib/util/tevent_ntstatus.h"
#include "../lib/util/tevent_unix.h"
#include "client.h"
+#include "../libcli/smb/smbXcli_base.h"
#include "async_smb.h"
#include "../libcli/smb/read_smb.h"
#include "libsmb/nmblib.h"
struct loadparm_context *lp_ctx,
const struct smb_transports *transports,
int sec_timeout,
- int *pfd, size_t *chosen_index,
- uint16_t *chosen_port)
+ TALLOC_CTX *mem_ctx,
+ struct smbXcli_transport **ptransport,
+ size_t *chosen_index)
{
TALLOC_CTX *frame = talloc_stackframe();
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, pfd, chosen_index, chosen_port);
+ 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;
+ }
+ }
fail:
TALLOC_FREE(frame);
return status;
#ifndef _LIBSMB_SMBSOCK_CONNECT_H_
#define _LIBSMB_SMBSOCK_CONNECT_H_
+struct smbXcli_transport;
+
/* The following definitions come from libsmb/smbsock_connect.c */
struct smb_transports smbsock_transports_from_port(uint16_t port);
struct loadparm_context *lp_ctx,
const struct smb_transports *transports,
int sec_timeout,
- int *pfd, size_t *chosen_index,
- uint16_t *chosen_port)
- NONNULL(1) NONNULL(7) NONNULL(8) NONNULL(10);
+ TALLOC_CTX *mem_ctx,
+ struct smbXcli_transport **ptransport,
+ size_t *chosen_index)
+ NONNULL(1) NONNULL(7) NONNULL(8) NONNULL(11);
#endif /* _LIBSMB_SMBSOCK_CONNECT_H_ */
bool run_smb_any_connect(int dummy)
{
- int fd;
NTSTATUS status;
struct sockaddr_storage addrs[5];
struct smb_transports ts =
lp_client_smb_transports());
size_t chosen_index;
struct loadparm_context *lp_ctx = NULL;
- uint16_t port;
+ struct smbXcli_transport *xtp = NULL;
lp_ctx = loadparm_init_s3(NULL, loadparm_s3_helpers());
if (lp_ctx == NULL) {
status = smbsock_any_connect(addrs, NULL, NULL, NULL, NULL,
ARRAY_SIZE(addrs), lp_ctx, &ts, 0,
- &fd, &chosen_index, &port);
+ NULL, &xtp, &chosen_index);
TALLOC_FREE(lp_ctx);
- d_printf("smbsock_any_connect returned %s (fd %d)\n",
- nt_errstr(status), NT_STATUS_IS_OK(status) ? fd : -1);
+ d_printf("smbsock_any_connect returned %s\n",
+ nt_errstr(status));
if (NT_STATUS_IS_OK(status)) {
- close(fd);
+ TALLOC_FREE(xtp);
}
return true;
}
int fd = -1;
size_t fd_index;
struct smb_transport tp = { .type = SMB_TRANSPORT_TYPE_UNKNOWN, };
+ struct smbXcli_transport *xtp = NULL;
NTSTATUS status;
bool ok;
num_dcs);
status = smbsock_any_connect(addrs, dcnames, NULL, NULL, NULL,
num_addrs, lp_ctx, &ts,
- 10, &fd, &fd_index, NULL);
+ 10, NULL, &xtp, &fd_index);
if (!NT_STATUS_IS_OK(status)) {
for (i=0; i<num_dcs; i++) {
char ab[INET6_ADDRSTRLEN];
}
return False;
}
+ talloc_reparent(NULL, mem_ctx, xtp);
D_NOTICE("Successfully connected to DC '%s'.\n", dcs[fd_index].name);
domain->dcaddr = addrs[fd_index];
close(fd);
fd = -1;
}
+ TALLOC_FREE(xtp);
/*
* This should not be an infinite loop, since get_dcs() will not return
goto again;
return_transport:
- set_socket_options(fd, lp_socket_options());
- *ptransport = smbXcli_transport_bsd(NULL, fd, &tp);
- if (*ptransport == NULL) {
- close(fd);
- DBG_ERR("smbXcli_transport_bsd() failed\n");
- return false;
+ 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;
+ }
}
- talloc_reparent(NULL, mem_ctx, *ptransport);
+
+ *ptransport = talloc_move(mem_ctx, &xtp);
return true;
}