#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"
static int smbcli_socket_destructor(struct smbcli_socket *sock)
{
- if (sock->sockfd != -1) {
- close(sock->sockfd);
- sock->sockfd = -1;
- }
+ TALLOC_FREE(sock->transport);
return 0;
}
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;
state->ctx->status = smbsock_any_connect_recv(subreq,
return;
}
- state->result->sockfd = sockfd;
+ state->result->transport = smbXcli_transport_bsd(state->result,
+ sockfd,
+ &tp);
+ if (composite_nomem(state->result->transport, state->ctx)) {
+ close(sockfd);
+ return;
+ }
+
state->result->hostname = talloc_steal(state->result, state->host_name);
talloc_set_destructor(state->result, smbcli_socket_destructor);
struct smbcli_options *options)
{
struct smbcli_transport *transport;
- struct smb_transport tp = { .type = SMB_TRANSPORT_TYPE_UNKNOWN, };
- struct smbXcli_transport *xtp = NULL;
uint32_t smb1_capabilities;
transport = talloc_zero(parent_ctx, struct smbcli_transport);
smb1_capabilities |= CAP_LEVEL_II_OPLOCKS;
}
- xtp = smbXcli_transport_bsd(transport, sock->sockfd, &tp);
- if (xtp == NULL) {
- TALLOC_FREE(sock);
- TALLOC_FREE(transport);
- return NULL;
- }
- sock->sockfd = -1;
- TALLOC_FREE(sock);
-
transport->conn = smbXcli_conn_create(transport,
- &xtp,
+ &sock->transport,
sock->hostname,
options->signing,
smb1_capabilities,
NULL, /* client_guid */
0, /* smb2_capabilities */
NULL); /* smb3_ciphers */
+ TALLOC_FREE(sock);
if (transport->conn == NULL) {
- TALLOC_FREE(xtp);
TALLOC_FREE(transport);
return NULL;
}
/* this is the context for a SMB socket associated with the socket itself */
struct smbcli_socket {
- int sockfd;
+ struct smbXcli_transport *transport;
/* the hostname we connected to */
const char *hostname;
struct smbcli_options *options)
{
struct smb2_transport *transport;
- struct smb_transport tp = { .type = SMB_TRANSPORT_TYPE_UNKNOWN, };
- struct smbXcli_transport *xtp = NULL;
transport = talloc_zero(parent_ctx, struct smb2_transport);
if (!transport) return NULL;
transport->options.max_protocol = PROTOCOL_LATEST;
}
- xtp = smbXcli_transport_bsd(transport, sock->sockfd, &tp);
- if (xtp == NULL) {
- TALLOC_FREE(sock);
- TALLOC_FREE(transport);
- return NULL;
- }
- sock->sockfd = -1;
- TALLOC_FREE(sock);
-
transport->conn = smbXcli_conn_create(transport,
- &xtp,
+ &sock->transport,
sock->hostname,
options->signing,
0, /* smb1_capabilities */
&options->client_guid,
options->smb2_capabilities,
&options->smb3_capabilities);
+ TALLOC_FREE(sock);
if (transport->conn == NULL) {
- TALLOC_FREE(xtp);
TALLOC_FREE(transport);
return NULL;
}
struct smb_connect_nego_state);
struct tevent_req *subreq = NULL;
struct smbcli_socket *sock = NULL;
- struct smb_transport tp = { .type = SMB_TRANSPORT_TYPE_UNKNOWN, };
- struct smbXcli_transport *xtp = NULL;
uint32_t smb1_capabilities;
uint32_t timeout_msec = state->options.request_timeout * 1000;
NTSTATUS status;
smb1_capabilities |= CAP_LEVEL_II_OPLOCKS;
}
- xtp = smbXcli_transport_bsd(state, sock->sockfd, &tp);
- if (tevent_req_nomem(xtp, req)) {
- return;
- }
- sock->sockfd = -1;
- TALLOC_FREE(sock);
-
state->conn = smbXcli_conn_create(state,
- &xtp,
+ &sock->transport,
state->target_hostname,
state->options.signing,
smb1_capabilities,
&state->options.client_guid,
state->options.smb2_capabilities,
&state->options.smb3_capabilities);
+ TALLOC_FREE(sock);
if (tevent_req_nomem(state->conn, req)) {
return;
}