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)
{
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;
}
struct smbXsrv_connection *conn;
};
-extern struct smbd_server_connection *smbd_server_conn;
+extern struct smbXsrv_connection *global_smbXsrv_connection;
void smbd_init_globals(void);
#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;
****************************************************************************/
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;
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,
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;
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 */
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;
uint64_t unique_id;
fd = accept(s->fd, (struct sockaddr *)(void *)&addr,&in_addrlen);
- sconn->sock = fd;
if (fd == -1 && errno == EINTR)
return;
}
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;
}
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;
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);
}
}
- 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");
}
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);
/* 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);
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);
* 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);