summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/globals.c11
-rw-r--r--source3/smbd/globals.h2
-rw-r--r--source3/smbd/process.c49
-rw-r--r--source3/smbd/proto.h4
-rw-r--r--source3/smbd/server.c29
-rw-r--r--source3/smbd/server_exit.c10
6 files changed, 63 insertions, 42 deletions
diff --git a/source3/smbd/globals.c b/source3/smbd/globals.c
index ff8c51bbdf..196b643109 100644
--- a/source3/smbd/globals.c
+++ b/source3/smbd/globals.c
@@ -102,7 +102,7 @@ struct smbd_parent_context *am_parent = NULL;
struct memcache *smbd_memcache_ctx = NULL;
bool exit_firsttime = true;
-struct smbd_server_connection *smbd_server_conn = NULL;
+struct smbXsrv_connection *global_smbXsrv_connection = NULL;
struct memcache *smbd_memcache(void)
{
@@ -142,13 +142,4 @@ void smbd_init_globals(void)
ZERO_STRUCT(conn_ctx_stack);
ZERO_STRUCT(sec_ctx_stack);
-
- smbd_server_conn = talloc_zero(server_event_context(), struct smbd_server_connection);
- if (!smbd_server_conn) {
- exit_server("failed to create smbd_server_connection");
- }
-
- smbd_server_conn->ev_ctx = server_event_context();
- smbd_server_conn->smb1.echo_handler.trusted_fd = -1;
- smbd_server_conn->smb1.echo_handler.socket_lock_fd = -1;
}
diff --git a/source3/smbd/globals.h b/source3/smbd/globals.h
index 0a57013a68..24c21ffee4 100644
--- a/source3/smbd/globals.h
+++ b/source3/smbd/globals.h
@@ -638,6 +638,6 @@ struct smbd_server_connection {
struct smbXsrv_connection *conn;
};
-extern struct smbd_server_connection *smbd_server_conn;
+extern struct smbXsrv_connection *global_smbXsrv_connection;
void smbd_init_globals(void);
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index 24d6ec3976..f955959fd4 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -39,6 +39,7 @@
#include "../libcli/security/dom_sid.h"
#include "../libcli/security/security_token.h"
#include "lib/id_cache.h"
+#include "serverid.h"
extern bool global_machine_password_needs_changing;
@@ -3163,9 +3164,13 @@ NTSTATUS smbXsrv_connection_init_tables(struct smbXsrv_connection *conn,
****************************************************************************/
void smbd_process(struct tevent_context *ev_ctx,
- struct smbd_server_connection *sconn)
+ struct messaging_context *msg_ctx,
+ int sock_fd,
+ bool interactive)
{
TALLOC_CTX *frame = talloc_stackframe();
+ struct smbXsrv_connection *conn;
+ struct smbd_server_connection *sconn;
struct sockaddr_storage ss;
struct sockaddr *sa = NULL;
socklen_t sa_socklen;
@@ -3176,12 +3181,47 @@ void smbd_process(struct tevent_context *ev_ctx,
char *rhost;
int ret;
- sconn->conn = talloc_zero(sconn, struct smbXsrv_connection);
- if (sconn->conn == NULL) {
+ conn = talloc_zero(ev_ctx, struct smbXsrv_connection);
+ if (conn == NULL) {
DEBUG(0,("talloc_zero(struct smbXsrv_connection)\n"));
exit_server_cleanly("talloc_zero(struct smbXsrv_connection).\n");
}
+ conn->ev_ctx = ev_ctx;
+ conn->msg_ctx = msg_ctx;
+
+ sconn = talloc_zero(conn, struct smbd_server_connection);
+ if (!sconn) {
+ exit_server("failed to create smbd_server_connection");
+ }
+
+ conn->sconn = sconn;
+ sconn->conn = conn;
+
+ /*
+ * TODO: remove this...:-)
+ */
+ global_smbXsrv_connection = conn;
+
+ sconn->ev_ctx = ev_ctx;
+ sconn->msg_ctx = msg_ctx;
+ sconn->sock = sock_fd;
+ sconn->smb1.echo_handler.trusted_fd = -1;
+ sconn->smb1.echo_handler.socket_lock_fd = -1;
+
+ if (!interactive) {
+ smbd_setup_sig_term_handler(sconn);
+ smbd_setup_sig_hup_handler(sconn);
+
+ if (!serverid_register(messaging_server_id(msg_ctx),
+ FLAG_MSG_GENERAL|FLAG_MSG_SMBD
+ |FLAG_MSG_DBWRAP
+ |FLAG_MSG_PRINT_GENERAL)) {
+ exit_server_cleanly("Could not register myself in "
+ "serverid.tdb");
+ }
+ }
+
if (lp_srv_maxprotocol() >= PROTOCOL_SMB2_02) {
/*
* We're not making the decision here,
@@ -3449,9 +3489,6 @@ void smbd_process(struct tevent_context *ev_ctx,
exit_server("failed to create smbd_server_connection fde");
}
- sconn->conn->sconn = sconn;
- sconn->conn->ev_ctx = sconn->ev_ctx;
- sconn->conn->msg_ctx = sconn->msg_ctx;
sconn->conn->local_address = sconn->local_address;
sconn->conn->remote_address = sconn->remote_address;
sconn->conn->remote_hostname = sconn->remote_hostname;
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index 30eed73f8d..311072a8c0 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -802,7 +802,9 @@ bool smb1_parse_chain(TALLOC_CTX *mem_ctx, const uint8_t *buf,
struct smb_request ***reqs, unsigned *num_reqs);
bool req_is_in_chain(struct smb_request *req);
void smbd_process(struct tevent_context *ev_ctx,
- struct smbd_server_connection *sconn);
+ struct messaging_context *msg_ctx,
+ int sock_fd,
+ bool interactive);
bool fork_echo_handler(struct smbd_server_connection *sconn);
/* The following definitions come from smbd/quotas.c */
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 36048632e0..ab4e971459 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -534,7 +534,6 @@ static void smbd_accept_connection(struct tevent_context *ev,
struct smbd_open_socket *s = talloc_get_type_abort(private_data,
struct smbd_open_socket);
struct messaging_context *msg_ctx = s->parent->msg_ctx;
- struct smbd_server_connection *sconn = smbd_server_conn;
struct sockaddr_storage addr;
socklen_t in_addrlen = sizeof(addr);
int fd;
@@ -542,7 +541,6 @@ static void smbd_accept_connection(struct tevent_context *ev,
uint64_t unique_id;
fd = accept(s->fd, (struct sockaddr *)(void *)&addr,&in_addrlen);
- sconn->sock = fd;
if (fd == -1 && errno == EINTR)
return;
@@ -553,15 +551,14 @@ static void smbd_accept_connection(struct tevent_context *ev,
}
if (s->parent->interactive) {
- reinit_after_fork(msg_ctx, sconn->ev_ctx, true);
- smbd_process(ev, sconn);
+ reinit_after_fork(msg_ctx, ev, true);
+ smbd_process(ev, msg_ctx, fd, true);
exit_server_cleanly("end of interactive mode");
return;
}
if (!allowable_number_of_smbd_processes(s->parent)) {
close(fd);
- sconn->sock = -1;
return;
}
@@ -614,18 +611,7 @@ static void smbd_accept_connection(struct tevent_context *ev,
smb_panic("reinit_after_fork() failed");
}
- smbd_setup_sig_term_handler(sconn);
- smbd_setup_sig_hup_handler(sconn);
-
- if (!serverid_register(messaging_server_id(msg_ctx),
- FLAG_MSG_GENERAL|FLAG_MSG_SMBD
- |FLAG_MSG_DBWRAP
- |FLAG_MSG_PRINT_GENERAL)) {
- exit_server_cleanly("Could not register myself in "
- "serverid.tdb");
- }
-
- smbd_process(ev, sconn);
+ smbd_process(ev, msg_ctx, fd, false);
exit:
exit_server_cleanly("end of child");
return;
@@ -646,7 +632,6 @@ static void smbd_accept_connection(struct tevent_context *ev,
getpeername failure if we reopen the logs
and use %I in the filename.
*/
- sconn->sock = -1;
if (pid != 0) {
add_child_pid(s->parent, pid);
@@ -1329,8 +1314,6 @@ extern void build_options(bool screen);
}
}
- smbd_server_conn->msg_ctx = msg_ctx;
-
parent = talloc_zero(ev_ctx, struct smbd_parent_context);
if (!parent) {
exit_server("talloc(struct smbd_parent_context) failed");
@@ -1497,13 +1480,15 @@ extern void build_options(bool screen);
}
if (!is_daemon) {
+ int sock;
+
/* inetd mode */
TALLOC_FREE(frame);
/* Started from inetd. fd 0 is the socket. */
/* We will abort gracefully when the client or remote system
goes away */
- smbd_server_conn->sock = dup(0);
+ sock = dup(0);
/* close stdin, stdout (if not logging to it), but not stderr */
close_low_fds(true, !debug_get_output_is_stdout(), false);
@@ -1515,7 +1500,7 @@ extern void build_options(bool screen);
/* Stop zombies */
smbd_setup_sig_chld_handler(parent);
- smbd_process(ev_ctx, smbd_server_conn);
+ smbd_process(ev_ctx, msg_ctx, sock, true);
exit_server_cleanly(NULL);
return(0);
diff --git a/source3/smbd/server_exit.c b/source3/smbd/server_exit.c
index 4e10a09a2b..20f7b4dbba 100644
--- a/source3/smbd/server_exit.c
+++ b/source3/smbd/server_exit.c
@@ -85,7 +85,12 @@ static void exit_server_common(enum server_exit_reason how,
const char *const reason)
{
bool had_open_conn = false;
- struct smbd_server_connection *sconn = smbd_server_conn;
+ struct smbXsrv_connection *conn = global_smbXsrv_connection;
+ struct smbd_server_connection *sconn = NULL;
+
+ if (conn != NULL) {
+ sconn = conn->sconn;
+ }
if (!exit_firsttime)
exit(0);
@@ -158,7 +163,8 @@ static void exit_server_common(enum server_exit_reason how,
* because smbd_msg_ctx is not a talloc child of smbd_server_conn.
*/
sconn = NULL;
- TALLOC_FREE(smbd_server_conn);
+ conn = NULL;
+ TALLOC_FREE(global_smbXsrv_connection);
server_messaging_context_free();
server_event_context_free();
TALLOC_FREE(smbd_memcache_ctx);