#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;
struct sockaddr *sa = NULL;
socklen_t sa_length;
int ret;
+ size_t max_pdu_size = 0x1FFFF;
+ NTSTATUS status;
conn = talloc_zero(mem_ctx, struct smbXcli_conn);
if (!conn) {
ss = (void *)&conn->local_ss;
sa = (struct sockaddr *)ss;
sa_length = sizeof(conn->local_ss);
- ret = getsockname(fd, sa, &sa_length);
+ ret = 0;//getsockname(fd, sa, &sa_length);
if (ret == -1) {
goto error;
}
ss = (void *)&conn->remote_ss;
sa = (struct sockaddr *)ss;
sa_length = sizeof(conn->remote_ss);
- ret = getpeername(fd, sa, &sa_length);
+ ret = 0;//getpeername(fd, sa, &sa_length);
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 1
+ conn->transport = (struct smb_transport *)(void *)(uintptr_t)fd;
+ talloc_get_type_abort(conn->transport, struct smb_transport);
+ talloc_steal(conn, conn->transport);
+ conn->sock_fd = -1;
+#else
+#error
+ conn->sock_fd = fd;
+ status = smb_transport_tcp_existing(conn, fd,
+ max_pdu_size,
+ &conn->transport);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto error;
+ }
+#endif
+
talloc_set_destructor(conn, smbXcli_conn_destructor);
return conn;
return false;
}
- if (conn->sock_fd == -1) {
+ if (conn->transport == NULL) {
return false;
}
void smbXcli_conn_set_sockopt(struct smbXcli_conn *conn, const char *options)
{
- set_socket_options(conn->sock_fd, options);
+ if (conn->sock_fd != -1) {
+ 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[9];
+ uint8_t buf[5];
struct tevent_req *write_req;
};
return NULL;
}
state->conn = conn;
- SIVAL(state->buf, 4, 0x74697865);
- SCVAL(state->buf, 8, exitcode);
- _smb_setlen_nbt(state->buf, sizeof(state->buf)-4);
+ SIVAL(state->buf, 0, 0x74697865);
+ SCVAL(state->buf, 4, exitcode);
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 = writev_send(state, ev, conn->outgoing, conn->sock_fd,
- false, &state->iov, 1);
+ subreq = smb_transport_write_pdu_send(state, ev,
+ state->conn->transport,
+ &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);
- ssize_t nwritten;
- int err;
+ NTSTATUS status;
state->write_req = NULL;
- nwritten = writev_recv(subreq, &err);
+ status = smb_transport_write_pdu_recv(subreq);
TALLOC_FREE(subreq);
- if (nwritten == -1) {
- /* here, we need to notify all pending requests */
- NTSTATUS status = map_nt_error_from_unix_common(err);
+ if (!NT_STATUS_IS_OK(status)) {
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 = read_smb_send(conn->pending,
- state->ev,
- conn->sock_fd);
+ conn->read_smb_req = smb_transport_read_pdu_send(conn->pending,
+ state->ev,
+ conn->transport);
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);
- conn->sock_fd = -1;
+ TALLOC_FREE(conn->transport);
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 = talloc_get_size(buf);
- iov_count = 1;
+ iov[0].iov_len = 4;
+ iov[1].iov_base = (void *)(buf+4);
+ iov[1].iov_len = talloc_get_size(buf) - 4;
+ iov_count = 2;
}
if (state->conn->dispatch_incoming == NULL) {
tevent_req_set_cancel_fn(req, smbXcli_req_cancel);
- subreq = writev_send(state, state->ev, state->conn->outgoing,
- state->conn->sock_fd, false, iov, iov_count);
+ subreq = smb_transport_write_pdu_send(state, state->ev,
+ state->conn->transport,
+ &iov[1], iov_count-1);
if (subreq == NULL) {
return NT_STATUS_NO_MEMORY;
}
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
- ssize_t nwritten;
- int err;
+ NTSTATUS status;
state->write_req = NULL;
- nwritten = writev_recv(subreq, &err);
+ status = smb_transport_write_pdu_recv(subreq);
TALLOC_FREE(subreq);
- if (nwritten == -1) {
- /* here, we need to notify all pending requests */
- NTSTATUS status = map_nt_error_from_unix_common(err);
+ if (!NT_STATUS_IS_OK(status)) {
smbXcli_conn_disconnect(state->conn, status);
return;
}
TALLOC_CTX *frame = talloc_stackframe();
NTSTATUS status;
uint8_t *inbuf;
- ssize_t received;
- int err;
+ struct iovec iov;
if (subreq != conn->read_smb_req) {
DEBUG(1, ("Internal error: cli_smb_received called with "
}
conn->read_smb_req = NULL;
- received = read_smb_recv(subreq, frame, &inbuf, &err);
+ status = smb_transport_read_pdu_recv(subreq, frame, &iov);
TALLOC_FREE(subreq);
- if (received == -1) {
- status = map_nt_error_from_unix_common(err);
+ if (!NT_STATUS_IS_OK(status)) {
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 = writev_send(state, state->ev, state->conn->outgoing,
- state->conn->sock_fd, false, iov, num_iov);
+ subreq = smb_transport_write_pdu_send(state, state->ev,
+ state->conn->transport,
+ &iov[1], num_iov - 1);
if (subreq == NULL) {
return NT_STATUS_NO_MEMORY;
}
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
- ssize_t nwritten;
- int err;
+ NTSTATUS status;
state->write_req = NULL;
- nwritten = writev_recv(subreq, &err);
+ status = smb_transport_write_pdu_recv(subreq);
TALLOC_FREE(subreq);
- if (nwritten == -1) {
+ if (!NT_STATUS_IS_OK(status)) {
/* here, we need to notify all pending requests */
- NTSTATUS status = map_nt_error_from_unix_common(err);
smbXcli_conn_disconnect(state->conn, status);
return;
}