s3:smbd: remove global 'smbd_server_conn' !!!
authorStefan Metzmacher <metze@samba.org>
Thu, 24 May 2012 11:46:11 +0000 (13:46 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 24 May 2012 18:07:20 +0000 (20:07 +0200)
For now we still use a global 'global_smbXsrv_connection'
in order to pass the connection state to exit_server*().

metze

Autobuild-User: Stefan Metzmacher <metze@samba.org>
Autobuild-Date: Thu May 24 20:07:20 CEST 2012 on sn-devel-104

source3/smbd/globals.c
source3/smbd/globals.h
source3/smbd/process.c
source3/smbd/proto.h
source3/smbd/server.c
source3/smbd/server_exit.c

index ff8c51bbdf46c0178ccb7d38563e3ffee1764581..196b6431095ae071a3d7771a63fa08432c41e01d 100644 (file)
@@ -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;
 }
index 0a57013a6800ff7b8ce564356c590cd358ceed94..24c21ffee4e7db1d4a262cf764a928d84bf244e1 100644 (file)
@@ -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);
index 24d6ec397646affbc464f8c5b4be4022e7c1094a..f955959fd411cee0ab49eabbf7894b40c8c0039f 100644 (file)
@@ -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;
index 30eed73f8dab8d3d474a5f51bfa3a8b98b0703c0..311072a8c07da9770bbe50ca2f552922fc0c61e9 100644 (file)
@@ -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  */
index 36048632e08ec865c8795724091abf4f909abfc9..ab4e9714591c757e76b9c22970a877a7795f925e 100644 (file)
@@ -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);
index 4e10a09a2bad8c6d39329f34cdb9b3a393c398e1..20f7b4dbba66abffd3aaff683efeb29c016f0e53 100644 (file)
@@ -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);