summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2014-05-21 23:23:34 +0200
committerMichael Adam <obnox@samba.org>2014-08-06 09:51:11 +0200
commit0ccffffe0725e3a7dca2e723cdb5c10ce04da696 (patch)
tree5849b9397db6da47469e3a6f578de7c022b5ab98
parent25952d3ff114e06781c50eed244be60d9a9266f4 (diff)
downloadsamba-0ccffffe0725e3a7dca2e723cdb5c10ce04da696.tar.gz
samba-0ccffffe0725e3a7dca2e723cdb5c10ce04da696.tar.xz
samba-0ccffffe0725e3a7dca2e723cdb5c10ce04da696.zip
s3:smbd: move sconn->sock to xconn->transport.sock
This prepares the structures for multi-channel support. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
-rw-r--r--source3/smbd/globals.h3
-rw-r--r--source3/smbd/msdfs.c1
-rw-r--r--source3/smbd/process.c41
-rw-r--r--source3/smbd/reply.c26
-rw-r--r--source3/smbd/server_reload.c11
-rw-r--r--source3/smbd/smb2_read.c4
-rw-r--r--source3/smbd/smb2_server.c15
-rw-r--r--source3/smbd/vfs.c4
8 files changed, 62 insertions, 43 deletions
diff --git a/source3/smbd/globals.h b/source3/smbd/globals.h
index 8f4a0214ec..82b09f08ec 100644
--- a/source3/smbd/globals.h
+++ b/source3/smbd/globals.h
@@ -344,6 +344,8 @@ struct smbXsrv_connection {
enum protocol_types protocol;
struct {
+ int sock;
+
struct {
bool got_session;
} nbt;
@@ -656,7 +658,6 @@ struct user_struct {
struct smbd_server_connection {
NTSTATUS status;
- int sock;
const struct tsocket_address *local_address;
const struct tsocket_address *remote_address;
const char *remote_hostname;
diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c
index 98e406af25..5b38d586c9 100644
--- a/source3/smbd/msdfs.c
+++ b/source3/smbd/msdfs.c
@@ -246,7 +246,6 @@ static NTSTATUS create_conn_struct_as_root(TALLOC_CTX *ctx,
sconn->ev_ctx = ev;
sconn->msg_ctx = msg;
- sconn->sock = -1;
smbd_echo_init(sconn);
conn = conn_new(sconn);
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index 0e468a2483..41547bbe15 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -247,7 +247,7 @@ bool srv_send_smb(struct smbd_server_connection *sconn, char *buffer,
len = smb_len_large(buf_out) + 4;
- ret = write_data(sconn->sock, buf_out, len);
+ ret = write_data(xconn->transport.sock, buf_out, len);
if (ret <= 0) {
int saved_errno = errno;
/*
@@ -2442,6 +2442,7 @@ static void smbd_server_connection_write_handler(
static void smbd_server_connection_read_handler(
struct smbd_server_connection *sconn, int fd)
{
+ struct smbXsrv_connection *xconn = sconn->conn;
uint8_t *inbuf = NULL;
size_t inbuf_len = 0;
size_t unread_bytes = 0;
@@ -2464,7 +2465,7 @@ static void smbd_server_connection_read_handler(
}
}
- from_client = (sconn->sock == fd);
+ from_client = (xconn->transport.sock == fd);
if (async_echo && from_client) {
smbd_lock_socket(sconn);
@@ -2511,6 +2512,7 @@ static void smbd_server_connection_handler(struct tevent_context *ev,
{
struct smbd_server_connection *conn = talloc_get_type(private_data,
struct smbd_server_connection);
+ struct smbXsrv_connection *xconn = conn->conn;
if (!NT_STATUS_IS_OK(conn->status)) {
/*
@@ -2526,7 +2528,7 @@ static void smbd_server_connection_handler(struct tevent_context *ev,
return;
}
if (flags & TEVENT_FD_READ) {
- smbd_server_connection_read_handler(conn, conn->sock);
+ smbd_server_connection_read_handler(conn, xconn->transport.sock);
return;
}
}
@@ -2713,7 +2715,7 @@ static bool keepalive_fn(const struct timeval *now, void *private_data)
}
smbd_lock_socket(sconn);
- ret = send_keepalive(sconn->sock);
+ ret = send_keepalive(xconn->transport.sock);
smbd_unlock_socket(sconn);
if (!ret) {
@@ -2802,6 +2804,7 @@ static struct tevent_req *smbd_echo_read_send(
{
struct tevent_req *req, *subreq;
struct smbd_echo_read_state *state;
+ struct smbXsrv_connection *xconn = sconn->conn;
req = tevent_req_create(mem_ctx, &state,
struct smbd_echo_read_state);
@@ -2811,7 +2814,7 @@ static struct tevent_req *smbd_echo_read_send(
state->ev = ev;
state->sconn = sconn;
- subreq = wait_for_read_send(state, ev, sconn->sock);
+ subreq = wait_for_read_send(state, ev, xconn->transport.sock);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
@@ -2854,6 +2857,7 @@ static void smbd_echo_read_waited(struct tevent_req *subreq)
struct smbd_echo_read_state *state = tevent_req_data(
req, struct smbd_echo_read_state);
struct smbd_server_connection *sconn = state->sconn;
+ struct smbXsrv_connection *xconn = sconn->conn;
bool ok;
NTSTATUS status;
size_t unread = 0;
@@ -2873,7 +2877,7 @@ static void smbd_echo_read_waited(struct tevent_req *subreq)
return;
}
- if (!fd_is_readable(sconn->sock)) {
+ if (!fd_is_readable(xconn->transport.sock)) {
DEBUG(10,("echo_handler[%d] the parent smbd was faster\n",
(int)getpid()));
@@ -2885,7 +2889,8 @@ static void smbd_echo_read_waited(struct tevent_req *subreq)
return;
}
- subreq = wait_for_read_send(state, state->ev, sconn->sock);
+ subreq = wait_for_read_send(state, state->ev,
+ xconn->transport.sock);
if (tevent_req_nomem(subreq, req)) {
return;
}
@@ -2893,7 +2898,9 @@ static void smbd_echo_read_waited(struct tevent_req *subreq)
return;
}
- status = receive_smb_talloc(state, sconn, sconn->sock, &state->buf,
+ status = receive_smb_talloc(state, sconn,
+ xconn->transport.sock,
+ &state->buf,
0 /* timeout */,
&unread,
&encrypted,
@@ -3546,6 +3553,7 @@ void smbd_process(struct tevent_context *ev_ctx,
conn->ev_ctx = ev_ctx;
conn->msg_ctx = msg_ctx;
+ conn->transport.sock = sock_fd;
sconn = talloc_zero(conn, struct smbd_server_connection);
if (!sconn) {
@@ -3562,7 +3570,6 @@ void smbd_process(struct tevent_context *ev_ctx,
sconn->ev_ctx = ev_ctx;
sconn->msg_ctx = msg_ctx;
- sconn->sock = sock_fd;
smbd_echo_init(sconn);
if (!interactive) {
@@ -3590,10 +3597,10 @@ void smbd_process(struct tevent_context *ev_ctx,
}
/* Ensure child is set to blocking mode */
- set_blocking(sconn->sock,True);
+ set_blocking(sock_fd,True);
- set_socket_options(sconn->sock, "SO_KEEPALIVE");
- set_socket_options(sconn->sock, lp_socket_options());
+ set_socket_options(sock_fd, "SO_KEEPALIVE");
+ set_socket_options(sock_fd, lp_socket_options());
sa_socklen = sizeof(ss_clnt);
ret = getpeername(sock_fd, sa_clnt, &sa_socklen);
@@ -3828,11 +3835,11 @@ void smbd_process(struct tevent_context *ev_ctx,
}
sconn->smb1.fde = tevent_add_fd(ev_ctx,
- sconn,
- sconn->sock,
- TEVENT_FD_READ,
- smbd_server_connection_handler,
- sconn);
+ sconn,
+ sock_fd,
+ TEVENT_FD_READ,
+ smbd_server_connection_handler,
+ sconn);
if (!sconn->smb1.fde) {
exit_server("failed to create smbd_server_connection fde");
}
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 28c0426e7b..784f10ccbf 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -431,6 +431,7 @@ bool check_fsp_ntquota_handle(connection_struct *conn, struct smb_request *req,
static bool netbios_session_retarget(struct smbd_server_connection *sconn,
const char *name, int name_type)
{
+ struct smbXsrv_connection *xconn = sconn->conn;
char *trim_name;
char *trim_name_type;
const char *retarget_parm;
@@ -443,7 +444,7 @@ static bool netbios_session_retarget(struct smbd_server_connection *sconn,
bool ret = false;
uint8_t outbuf[10];
- if (get_socket_port(sconn->sock) != NBT_SMB_PORT) {
+ if (get_socket_port(xconn->transport.sock) != NBT_SMB_PORT) {
return false;
}
@@ -3059,7 +3060,7 @@ ssize_t fake_sendfile(files_struct *fsp, off_t startpos, size_t nread)
memset(buf + ret, '\0', cur_read - ret);
}
- ret = write_data(xconn->sconn->sock, buf, cur_read);
+ ret = write_data(xconn->transport.sock, buf, cur_read);
if (ret != cur_read) {
int saved_errno = errno;
/*
@@ -3133,7 +3134,7 @@ void sendfile_short_send(files_struct *fsp,
ssize_t ret;
to_write = MIN(SHORT_SEND_BUFSIZE, smb_maxcnt - nread);
- ret = write_data(xconn->sconn->sock, buf, to_write);
+ ret = write_data(xconn->transport.sock, buf, to_write);
if (ret != to_write) {
int saved_errno = errno;
/*
@@ -3166,7 +3167,7 @@ static void reply_readbraw_error(struct smbd_server_connection *sconn)
SIVAL(header,0,0);
smbd_lock_socket(sconn);
- if (write_data(sconn->sock,header,4) != 4) {
+ if (write_data(xconn->transport.sock,header,4) != 4) {
int saved_errno = errno;
/*
* Try and give an error message saying what
@@ -3216,7 +3217,7 @@ static void send_file_readbraw(connection_struct *conn,
_smb_setlen(header,nread);
header_blob = data_blob_const(header, 4);
- sendfile_read = SMB_VFS_SENDFILE(sconn->sock, fsp,
+ sendfile_read = SMB_VFS_SENDFILE(xconn->transport.sock, fsp,
&header_blob, startpos,
nread);
if (sendfile_read == -1) {
@@ -3294,7 +3295,7 @@ normal_readbraw:
}
_smb_setlen(outbuf,ret);
- if (write_data(sconn->sock, outbuf, 4+ret) != 4+ret) {
+ if (write_data(xconn->transport.sock, outbuf, 4+ret) != 4+ret) {
int saved_errno = errno;
/*
* Try and give an error message saying what
@@ -3750,7 +3751,7 @@ static void send_file_readX(connection_struct *conn, struct smb_request *req,
construct_reply_common_req(req, (char *)headerbuf);
setup_readX_header(req, (char *)headerbuf, smb_maxcnt);
- nread = SMB_VFS_SENDFILE(req->sconn->sock, fsp, &header,
+ nread = SMB_VFS_SENDFILE(xconn->transport.sock, fsp, &header,
startpos, smb_maxcnt);
if (nread == -1) {
saved_errno = errno;
@@ -3832,7 +3833,7 @@ normal_read:
setup_readX_header(req, (char *)headerbuf, smb_maxcnt);
/* Send out the header. */
- ret = write_data(req->sconn->sock, (char *)headerbuf,
+ ret = write_data(xconn->transport.sock, (char *)headerbuf,
sizeof(headerbuf));
if (ret != sizeof(headerbuf)) {
saved_errno = errno;
@@ -4255,7 +4256,7 @@ void reply_writebraw(struct smb_request *req)
}
/* Now read the raw data into the buffer and write it */
- status = read_smb_length(req->sconn->sock, buf, SMB_SECONDARY_WAIT,
+ status = read_smb_length(xconn->transport.sock, buf, SMB_SECONDARY_WAIT,
&numtowrite);
if (!NT_STATUS_IS_OK(status)) {
exit_server_cleanly("secondary writebraw failed");
@@ -4279,7 +4280,7 @@ void reply_writebraw(struct smb_request *req)
(int)tcount,(int)nwritten,(int)numtowrite));
}
- status = read_data(req->sconn->sock, buf+4, numtowrite);
+ status = read_data(xconn->transport.sock, buf+4, numtowrite);
if (!NT_STATUS_IS_OK(status)) {
/* Try and give an error message
@@ -4342,7 +4343,7 @@ void reply_writebraw(struct smb_request *req)
* sending a NBSSkeepalive. Thanks to DaveCB at Sun for this.
* JRA.
*/
- if (!send_keepalive(req->sconn->sock)) {
+ if (!send_keepalive(xconn->transport.sock)) {
exit_server_cleanly("reply_writebraw: send of "
"keepalive failed");
}
@@ -4710,6 +4711,7 @@ bool is_valid_writeX_buffer(struct smbd_server_connection *sconn,
void reply_write_and_X(struct smb_request *req)
{
connection_struct *conn = req->conn;
+ struct smbXsrv_connection *xconn = req->sconn->conn;
files_struct *fsp;
struct lock_struct lock;
off_t startpos;
@@ -4866,7 +4868,7 @@ void reply_write_and_X(struct smb_request *req)
out:
if (req->unread_bytes) {
/* writeX failed. drain socket. */
- if (drain_socket(req->sconn->sock, req->unread_bytes) !=
+ if (drain_socket(xconn->transport.sock, req->unread_bytes) !=
req->unread_bytes) {
smb_panic("failed to drain pending bytes");
}
diff --git a/source3/smbd/server_reload.c b/source3/smbd/server_reload.c
index e1e3f9acd0..627ad8ba22 100644
--- a/source3/smbd/server_reload.c
+++ b/source3/smbd/server_reload.c
@@ -139,8 +139,13 @@ bool reload_services(struct smbd_server_connection *sconn,
bool (*snumused) (struct smbd_server_connection *, int),
bool test)
{
+ struct smbXsrv_connection *xconn = NULL;
bool ret;
+ if (sconn != NULL) {
+ xconn = sconn->conn;
+ }
+
if (lp_loaded()) {
char *fname = lp_next_configfile(talloc_tos());
if (file_exist(fname) &&
@@ -173,9 +178,9 @@ bool reload_services(struct smbd_server_connection *sconn,
load_interfaces();
- if (sconn != NULL) {
- set_socket_options(sconn->sock, "SO_KEEPALIVE");
- set_socket_options(sconn->sock, lp_socket_options());
+ if (xconn != NULL) {
+ set_socket_options(xconn->transport.sock, "SO_KEEPALIVE");
+ set_socket_options(xconn->transport.sock, lp_socket_options());
}
mangle_reset_cache();
diff --git a/source3/smbd/smb2_read.c b/source3/smbd/smb2_read.c
index f27f1c007b..b68a1b6a2f 100644
--- a/source3/smbd/smb2_read.c
+++ b/source3/smbd/smb2_read.c
@@ -190,7 +190,7 @@ static int smb2_sendfile_send_data(struct smbd_smb2_read_state *state)
ssize_t ret;
int saved_errno;
- nread = SMB_VFS_SENDFILE(fsp->conn->sconn->sock,
+ nread = SMB_VFS_SENDFILE(xconn->transport.sock,
fsp,
hdr,
in_offset,
@@ -256,7 +256,7 @@ static int smb2_sendfile_send_data(struct smbd_smb2_read_state *state)
normal_read:
/* Send out the header. */
- ret = write_data(fsp->conn->sconn->sock,
+ ret = write_data(xconn->transport.sock,
(const char *)hdr->data, hdr->length);
if (ret != hdr->length) {
saved_errno = errno;
diff --git a/source3/smbd/smb2_server.c b/source3/smbd/smb2_server.c
index d61929ec06..59af738641 100644
--- a/source3/smbd/smb2_server.c
+++ b/source3/smbd/smb2_server.c
@@ -200,6 +200,8 @@ bool smbd_is_smb2_header(const uint8_t *inbuf, size_t size)
static NTSTATUS smbd_initialize_smb2(struct smbd_server_connection *sconn)
{
+ struct smbXsrv_connection *xconn = sconn->conn;
+
TALLOC_FREE(sconn->smb1.fde);
sconn->smb2.send_queue = NULL;
@@ -216,7 +218,7 @@ static NTSTATUS smbd_initialize_smb2(struct smbd_server_connection *sconn)
sconn->smb2.fde = tevent_add_fd(sconn->ev_ctx,
sconn,
- sconn->sock,
+ xconn->transport.sock,
TEVENT_FD_READ,
smbd_smb2_connection_handler,
sconn);
@@ -225,7 +227,7 @@ static NTSTATUS smbd_initialize_smb2(struct smbd_server_connection *sconn)
}
/* Ensure child is set to non-blocking mode */
- set_blocking(sconn->sock, false);
+ set_blocking(xconn->transport.sock, false);
return NT_STATUS_OK;
}
@@ -2661,6 +2663,7 @@ NTSTATUS smbd_smb2_request_error_ex(struct smbd_smb2_request *req,
DATA_BLOB *info,
const char *location)
{
+ struct smbXsrv_connection *xconn = req->sconn->conn;
DATA_BLOB body;
DATA_BLOB _dyn;
uint8_t *outhdr = SMBD_SMB2_OUT_HDR_PTR(req);
@@ -2675,7 +2678,7 @@ NTSTATUS smbd_smb2_request_error_ex(struct smbd_smb2_request *req,
size_t ret;
errno = 0;
- ret = drain_socket(req->sconn->sock, unread_bytes);
+ ret = drain_socket(xconn->transport.sock, unread_bytes);
if (ret != unread_bytes) {
NTSTATUS error;
@@ -3096,6 +3099,7 @@ static int socket_error_from_errno(int ret,
static NTSTATUS smbd_smb2_flush_send_queue(struct smbd_server_connection *sconn)
{
+ struct smbXsrv_connection *xconn = sconn->conn;
int ret;
int err;
bool retry;
@@ -3148,7 +3152,7 @@ static NTSTATUS smbd_smb2_flush_send_queue(struct smbd_server_connection *sconn)
continue;
}
- ret = writev(sconn->sock, e->vector, e->count);
+ ret = writev(xconn->transport.sock, e->vector, e->count);
if (ret == 0) {
/* propagate end of file */
return NT_STATUS_INTERNAL_ERROR;
@@ -3206,6 +3210,7 @@ static NTSTATUS smbd_smb2_flush_send_queue(struct smbd_server_connection *sconn)
static NTSTATUS smbd_smb2_io_handler(struct smbd_server_connection *sconn,
uint16_t fde_flags)
{
+ struct smbXsrv_connection *xconn = sconn->conn;
struct smbd_smb2_request_read_state *state = &sconn->smb2.request_read_state;
struct smbd_smb2_request *req = NULL;
size_t min_recvfile_size = UINT32_MAX;
@@ -3248,7 +3253,7 @@ again:
state->vector.iov_len = NBT_HDR_SIZE;
}
- ret = readv(sconn->sock, &state->vector, 1);
+ ret = readv(xconn->transport.sock, &state->vector, 1);
if (ret == 0) {
/* propagate end of file */
return NT_STATUS_END_OF_FILE;
diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c
index 35740497d7..82e0cdf07d 100644
--- a/source3/smbd/vfs.c
+++ b/source3/smbd/vfs.c
@@ -406,7 +406,7 @@ ssize_t vfs_write_data(struct smb_request *req,
ssize_t ret;
if (req && req->unread_bytes) {
- int sockfd = req->sconn->sock;
+ int sockfd = req->sconn->conn->transport.sock;
int old_flags;
SMB_ASSERT(req->unread_bytes == N);
/* VFS_RECVFILE must drain the socket
@@ -450,7 +450,7 @@ ssize_t vfs_pwrite_data(struct smb_request *req,
ssize_t ret;
if (req && req->unread_bytes) {
- int sockfd = req->sconn->sock;
+ int sockfd = req->sconn->conn->transport.sock;
SMB_ASSERT(req->unread_bytes == N);
/* VFS_RECVFILE must drain the socket
* before returning. */