#include "lib/crypto/aes.h"
#include "lib/crypto/aes_ccm_128.h"
#include "lib/crypto/aes_gcm_128.h"
-#include "../libcli/smb/smb_transport.h"
struct smbXcli_conn;
struct smbXcli_req;
struct smbXcli_conn {
int sock_fd;
- struct smb_transport *transport;
struct sockaddr_storage local_ss;
struct sockaddr_storage remote_ss;
const char *remote_name;
- //struct tevent_queue *outgoing;
+ struct tevent_queue *outgoing;
struct tevent_req **pending;
struct tevent_req *read_smb_req;
struct tevent_req *suicide_req;
return 0;
}
-//int smb_direct_transport_fd = -1;
-//const struct smb_transport *smb_direct_transport_ptr;
-
struct smbXcli_conn *smbXcli_conn_create(TALLOC_CTX *mem_ctx,
int fd,
const char *remote_name,
struct sockaddr *sa = NULL;
socklen_t sa_length;
int ret;
- size_t max_pdu_size = 0xFFFFFF;//0x1FFFF;
- NTSTATUS status;
conn = talloc_zero(mem_ctx, struct smbXcli_conn);
if (!conn) {
goto error;
}
- if (0) {
ss = (void *)&conn->local_ss;
sa = (struct sockaddr *)ss;
sa_length = sizeof(conn->local_ss);
if (ret == -1) {
goto error;
}
- }
- /*conn->outgoing = tevent_queue_create(conn, "smbXcli_outgoing");
+
+ conn->outgoing = tevent_queue_create(conn, "smbXcli_outgoing");
if (conn->outgoing == NULL) {
goto error;
}
-*/ conn->pending = NULL;
+ conn->pending = NULL;
conn->min_protocol = PROTOCOL_NONE;
conn->max_protocol = PROTOCOL_NONE;
conn->smb2.cc_chunk_len = 1024 * 1024;
conn->smb2.cc_max_chunks = 16;
-// if (fd == smb_direct_transport_fd) {
-// void *ptr = (void *)(uintptr_t)fd;
-// conn->transport = discard_const_p(struct smb_transport, smb_direct_transport_ptr);
-// smb_direct_transport_ptr = NULL;
-// smb_direct_transport_fd = -1;
-//
-// DEBUG(0,("%s: %s: conn->transport [%p] ptr [%p] sock [%d]\n",
-// __location__, __func__, conn->transport, ptr, fd));
-//
-// talloc_get_type_abort(conn->transport, struct smb_transport);
-// talloc_steal(conn, conn->transport);
-// conn->sock_fd = -1;
-// } else {
-// smb_panic(__location__);
- conn->sock_fd = fd;
- status = smb_transport_tcp_existing(conn, fd,
- max_pdu_size,
- &conn->transport);
- if (!NT_STATUS_IS_OK(status)) {
- goto error;
- }
- //}
-
talloc_set_destructor(conn, smbXcli_conn_destructor);
return conn;
return false;
}
- if (conn->transport == NULL) {
+ if (conn->sock_fd == -1) {
return false;
}
void smbXcli_conn_set_sockopt(struct smbXcli_conn *conn, const char *options)
{
- if (conn->sock_fd != -1) {
- set_socket_options(conn->sock_fd, options);
- }
+ set_socket_options(conn->sock_fd, options);
}
const struct sockaddr_storage *smbXcli_conn_local_sockaddr(struct smbXcli_conn *conn)
struct smbXcli_conn_samba_suicide_state {
struct smbXcli_conn *conn;
struct iovec iov;
- uint8_t buf[5];
+ uint8_t buf[9];
struct tevent_req *write_req;
};
return NULL;
}
state->conn = conn;
- SIVAL(state->buf, 0, 0x74697865);
- SCVAL(state->buf, 4, exitcode);
+ SIVAL(state->buf, 4, 0x74697865);
+ SCVAL(state->buf, 8, exitcode);
+ _smb_setlen_nbt(state->buf, sizeof(state->buf)-4);
if (conn->suicide_req != NULL) {
tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
state->iov.iov_base = state->buf;
state->iov.iov_len = sizeof(state->buf);
- subreq = smb_transport_write_pdu_send(state, ev,
- state->conn->transport,
- &state->iov, 1);
+ subreq = writev_send(state, ev, conn->outgoing, conn->sock_fd,
+ false, &state->iov, 1);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
subreq, struct tevent_req);
struct smbXcli_conn_samba_suicide_state *state = tevent_req_data(
req, struct smbXcli_conn_samba_suicide_state);
- NTSTATUS status;
+ ssize_t nwritten;
+ int err;
state->write_req = NULL;
- status = smb_transport_write_pdu_recv(subreq);
+ nwritten = writev_recv(subreq, &err);
TALLOC_FREE(subreq);
- if (!NT_STATUS_IS_OK(status)) {
+ if (nwritten == -1) {
+ /* here, we need to notify all pending requests */
+ NTSTATUS status = map_nt_error_from_unix_common(err);
smbXcli_conn_disconnect(state->conn, status);
return;
}
* We're the first ones, add the read_smb request that waits for the
* answer from the server
*/
- conn->read_smb_req = smb_transport_read_pdu_send(conn->pending,
- state->ev,
- conn->transport);
+ conn->read_smb_req = read_smb_send(conn->pending,
+ state->ev,
+ conn->sock_fd);
if (conn->read_smb_req == NULL) {
return false;
}
struct smbXcli_session *session;
int sock_fd = conn->sock_fd;
- //tevent_queue_stop(conn->outgoing);
+ tevent_queue_stop(conn->outgoing);
- TALLOC_FREE(conn->transport);
+ conn->sock_fd = -1;
session = conn->sessions;
if (talloc_array_length(conn->pending) == 0) {
return NT_STATUS_NO_MEMORY;
}
iov[0].iov_base = (void *)buf;
- iov[0].iov_len = 4;
- iov[1].iov_base = (void *)(buf+4);
- iov[1].iov_len = talloc_get_size(buf) - 4;
- iov_count = 2;
+ iov[0].iov_len = talloc_get_size(buf);
+ iov_count = 1;
}
if (state->conn->dispatch_incoming == NULL) {
tevent_req_set_cancel_fn(req, smbXcli_req_cancel);
- subreq = smb_transport_write_pdu_send(state, state->ev,
- state->conn->transport,
- &iov[1], iov_count-1);
+ subreq = writev_send(state, state->ev, state->conn->outgoing,
+ state->conn->sock_fd, false, iov, iov_count);
if (subreq == NULL) {
return NT_STATUS_NO_MEMORY;
}
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
- NTSTATUS status;
+ ssize_t nwritten;
+ int err;
state->write_req = NULL;
- status = smb_transport_write_pdu_recv(subreq);
+ nwritten = writev_recv(subreq, &err);
TALLOC_FREE(subreq);
- if (!NT_STATUS_IS_OK(status)) {
+ if (nwritten == -1) {
+ /* here, we need to notify all pending requests */
+ NTSTATUS status = map_nt_error_from_unix_common(err);
smbXcli_conn_disconnect(state->conn, status);
return;
}
TALLOC_CTX *frame = talloc_stackframe();
NTSTATUS status;
uint8_t *inbuf;
- struct iovec iov;
+ ssize_t received;
+ int err;
if (subreq != conn->read_smb_req) {
DEBUG(1, ("Internal error: cli_smb_received called with "
}
conn->read_smb_req = NULL;
- status = smb_transport_read_pdu_recv(subreq, frame, &iov);
+ received = read_smb_recv(subreq, frame, &inbuf, &err);
TALLOC_FREE(subreq);
- if (!NT_STATUS_IS_OK(status)) {
+ if (received == -1) {
+ status = map_nt_error_from_unix_common(err);
smbXcli_conn_disconnect(conn, status);
TALLOC_FREE(frame);
return;
}
- inbuf = (uint8_t *)iov.iov_base;
status = conn->dispatch_incoming(conn, frame, inbuf);
TALLOC_FREE(frame);
bool smbXcli_conn_has_async_calls(struct smbXcli_conn *conn)
{
- return (talloc_array_length(conn->pending) != 0);
-/*
return ((tevent_queue_length(conn->outgoing) != 0)
|| (talloc_array_length(conn->pending) != 0));
-*/
}
bool smbXcli_conn_dfs_supported(struct smbXcli_conn *conn)
state->conn->dispatch_incoming = smb2cli_conn_dispatch_incoming;
}
- subreq = smb_transport_write_pdu_send(state, state->ev,
- state->conn->transport,
- &iov[1], num_iov - 1);
+ subreq = writev_send(state, state->ev, state->conn->outgoing,
+ state->conn->sock_fd, false, iov, num_iov);
if (subreq == NULL) {
return NT_STATUS_NO_MEMORY;
}
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
- NTSTATUS status;
+ ssize_t nwritten;
+ int err;
state->write_req = NULL;
- status = smb_transport_write_pdu_recv(subreq);
+ nwritten = writev_recv(subreq, &err);
TALLOC_FREE(subreq);
- if (!NT_STATUS_IS_OK(status)) {
+ if (nwritten == -1) {
/* here, we need to notify all pending requests */
+ NTSTATUS status = map_nt_error_from_unix_common(err);
smbXcli_conn_disconnect(state->conn, status);
return;
}