s3:smbd: move smbXsrv_{session,tcon,open} tables to smbXsrv_client
authorStefan Metzmacher <metze@samba.org>
Thu, 12 Jun 2014 18:22:54 +0000 (20:22 +0200)
committerMichael Adam <obnox@samba.org>
Fri, 19 Sep 2014 07:15:12 +0000 (09:15 +0200)
These should be per client (based on the SMB >= 2.1 client_guid),
this is a preparation for multi-channel support.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
source3/librpc/idl/smbXsrv.idl
source3/smbd/globals.h
source3/smbd/process.c
source3/smbd/smb2_server.c
source3/smbd/smbXsrv_open.c
source3/smbd/smbXsrv_session.c
source3/smbd/smbXsrv_tcon.c

index 878b60805884784496309fd118471480d7ad8546..6d9e2c7a8e6b3cc57cb5f2edf18e7b4849266e36 100644 (file)
@@ -90,6 +90,22 @@ interface smbXsrv
                 */
                [ignore] struct smbd_server_connection  *sconn;
 
+               /*
+                * this session_table is used for SMB1 and SMB2,
+                */
+               [ignore] struct smbXsrv_session_table   *session_table;
+               [ignore] hyper                          last_session_id;
+               /*
+                * this tcon_table is only used for SMB1.
+                */
+               [ignore] struct smbXsrv_tcon_table      *tcon_table;
+               /*
+                * this open_table is used for SMB1 and SMB2,
+                * because we have a global sconn->real_max_open_files
+                * limit.
+                */
+               [ignore] struct smbXsrv_open_table      *open_table;
+
                /*
                 * For now this is only one connection!
                 * With multi-channel support we'll get more than
index 55a8263f7e7a8b62fb75d45bebf0320e62378e39..02275d8c1ee2b1dde870ceee80e885376dab4bcc 100644 (file)
@@ -505,22 +505,6 @@ struct smbXsrv_connection {
 
                struct smbd_smb2_request *requests;
        } smb2;
-
-       /*
-        * this session_table is used for SMB1 and SMB2,
-        */
-       struct smbXsrv_session_table *session_table;
-       uint64_t last_session_id;
-       /*
-        * this tcon_table is only used for SMB1.
-        */
-       struct smbXsrv_tcon_table *tcon_table;
-       /*
-        * this open_table is used for SMB1 and SMB2,
-        * because we have a global sconn->real_max_open_files
-        * limit.
-        */
-       struct smbXsrv_open_table *open_table;
 };
 
 const char *smbXsrv_connection_dbg(const struct smbXsrv_connection *xconn);
index 3cd3335e5e5a260d75ba065096d051039782e609..93dc4f2127300f53b4890d2aa4ced7395c459a33 100644 (file)
@@ -1523,10 +1523,10 @@ static connection_struct *switch_message(uint8 type, struct smb_request *req)
                }
        }
 
-       if (session_tag != xconn->last_session_id) {
+       if (session_tag != xconn->client->last_session_id) {
                struct user_struct *vuser = NULL;
 
-               xconn->last_session_id = session_tag;
+               xconn->client->last_session_id = session_tag;
                if (session) {
                        vuser = session->compat;
                }
index 33797c6b5bcd4becd73ccdd5f5c4a7c52c2d840a..a6b65138c4d1c4d1cbc27daf69e6e72bedaf8f6c 100644 (file)
@@ -1797,8 +1797,8 @@ static NTSTATUS smbd_smb2_request_check_session(struct smbd_smb2_request *req)
                return NT_STATUS_INVALID_HANDLE;
        }
 
-       if (in_session_id != req->xconn->last_session_id) {
-               req->xconn->last_session_id = in_session_id;
+       if (in_session_id != req->xconn->client->last_session_id) {
+               req->xconn->client->last_session_id = in_session_id;
                set_current_user_info(session_info->unix_info->sanitized_username,
                                      session_info->unix_info->unix_name,
                                      session_info->info->domain_name);
index 3123e6a2c7f98c3f8eddcf72d21eb2ea7255a4d6..bb2084ddbc11b0a0fb4296642589a31c59b69c8b 100644 (file)
@@ -153,6 +153,7 @@ static NTSTATUS smbXsrv_open_table_init(struct smbXsrv_connection *conn,
                                        uint32_t highest_id,
                                        uint32_t max_opens)
 {
+       struct smbXsrv_client *client = conn->client;
        struct smbXsrv_open_table *table;
        NTSTATUS status;
        uint64_t max_range;
@@ -169,7 +170,7 @@ static NTSTATUS smbXsrv_open_table_init(struct smbXsrv_connection *conn,
                return NT_STATUS_INTERNAL_ERROR;
        }
 
-       table = talloc_zero(conn, struct smbXsrv_open_table);
+       table = talloc_zero(client, struct smbXsrv_open_table);
        if (table == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -191,7 +192,7 @@ static NTSTATUS smbXsrv_open_table_init(struct smbXsrv_connection *conn,
 
        table->global.db_ctx = smbXsrv_open_global_db_ctx;
 
-       conn->open_table = table;
+       client->open_table = table;
        return NT_STATUS_OK;
 }
 
@@ -774,7 +775,7 @@ NTSTATUS smbXsrv_open_create(struct smbXsrv_connection *conn,
                             NTTIME now,
                             struct smbXsrv_open **_open)
 {
-       struct smbXsrv_open_table *table = conn->open_table;
+       struct smbXsrv_open_table *table = conn->client->open_table;
        struct db_record *local_rec = NULL;
        struct smbXsrv_open *op = NULL;
        void *ptr = NULL;
@@ -1113,7 +1114,7 @@ NTSTATUS smb1srv_open_lookup(struct smbXsrv_connection *conn,
                             uint16_t fnum, NTTIME now,
                             struct smbXsrv_open **_open)
 {
-       struct smbXsrv_open_table *table = conn->open_table;
+       struct smbXsrv_open_table *table = conn->client->open_table;
        uint32_t local_id = fnum;
        uint32_t global_id = 0;
 
@@ -1149,7 +1150,7 @@ NTSTATUS smb2srv_open_lookup(struct smbXsrv_connection *conn,
                             NTTIME now,
                             struct smbXsrv_open **_open)
 {
-       struct smbXsrv_open_table *table = conn->open_table;
+       struct smbXsrv_open_table *table = conn->client->open_table;
        uint32_t local_id = volatile_id & UINT32_MAX;
        uint64_t local_zeros = volatile_id & 0xFFFFFFFF00000000LLU;
        uint32_t global_id = persistent_id & UINT32_MAX;
@@ -1177,7 +1178,7 @@ NTSTATUS smb2srv_open_recreate(struct smbXsrv_connection *conn,
                               NTTIME now,
                               struct smbXsrv_open **_open)
 {
-       struct smbXsrv_open_table *table = conn->open_table;
+       struct smbXsrv_open_table *table = conn->client->open_table;
        struct db_record *local_rec = NULL;
        struct smbXsrv_open *op = NULL;
        void *ptr = NULL;
index fa60878f8e0862daf354b594081e0eab2b04c61f..9f0fa1d5afdbed6cfcf33a5ffcf093e9c302aeb2 100644 (file)
@@ -51,6 +51,10 @@ struct smbXsrv_session_table {
        } global;
 };
 
+static NTSTATUS smb2srv_session_lookup_raw(struct smbXsrv_session_table *table,
+                                          uint64_t session_id, NTTIME now,
+                                          struct smbXsrv_session **session);
+
 static struct db_context *smbXsrv_session_global_db_ctx = NULL;
 
 NTSTATUS smbXsrv_session_global_init(void)
@@ -164,6 +168,7 @@ static NTSTATUS smbXsrv_session_table_init(struct smbXsrv_connection *conn,
                                           uint32_t highest_id,
                                           uint32_t max_sessions)
 {
+       struct smbXsrv_client *client = conn->client;
        struct smbXsrv_session_table *table;
        NTSTATUS status;
        struct tevent_req *subreq;
@@ -181,7 +186,7 @@ static NTSTATUS smbXsrv_session_table_init(struct smbXsrv_connection *conn,
                return NT_STATUS_INTERNAL_ERROR;
        }
 
-       table = talloc_zero(conn, struct smbXsrv_session_table);
+       table = talloc_zero(client, struct smbXsrv_session_table);
        if (table == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -203,26 +208,26 @@ static NTSTATUS smbXsrv_session_table_init(struct smbXsrv_connection *conn,
 
        table->global.db_ctx = smbXsrv_session_global_db_ctx;
 
-       dbwrap_watch_db(table->global.db_ctx, conn->msg_ctx);
+       dbwrap_watch_db(table->global.db_ctx, client->msg_ctx);
 
-       subreq = messaging_read_send(table, conn->ev_ctx, conn->msg_ctx,
+       subreq = messaging_read_send(table, client->ev_ctx, client->msg_ctx,
                                     MSG_SMBXSRV_SESSION_CLOSE);
        if (subreq == NULL) {
                TALLOC_FREE(table);
                return NT_STATUS_NO_MEMORY;
        }
-       tevent_req_set_callback(subreq, smbXsrv_session_close_loop, conn);
+       tevent_req_set_callback(subreq, smbXsrv_session_close_loop, client);
 
-       conn->session_table = table;
+       client->session_table = table;
        return NT_STATUS_OK;
 }
 
 static void smbXsrv_session_close_loop(struct tevent_req *subreq)
 {
-       struct smbXsrv_connection *conn =
+       struct smbXsrv_client *client =
                tevent_req_callback_data(subreq,
-               struct smbXsrv_connection);
-       struct smbXsrv_session_table *table = conn->session_table;
+               struct smbXsrv_client);
+       struct smbXsrv_session_table *table = client->session_table;
        int ret;
        struct messaging_rec *rec = NULL;
        struct smbXsrv_session_closeB close_blob;
@@ -269,8 +274,9 @@ static void smbXsrv_session_close_loop(struct tevent_req *subreq)
                goto next;
        }
 
-       status = smb2srv_session_lookup(conn, close_info0->old_session_wire_id,
-                                       now, &session);
+       status = smb2srv_session_lookup_raw(client->session_table,
+                                           close_info0->old_session_wire_id,
+                                           now, &session);
        if (NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
                DEBUG(4,("smbXsrv_session_close_loop: "
                         "old_session_wire_id %llu not found\n",
@@ -338,14 +344,15 @@ static void smbXsrv_session_close_loop(struct tevent_req *subreq)
 next:
        TALLOC_FREE(rec);
 
-       subreq = messaging_read_send(table, conn->ev_ctx, conn->msg_ctx,
+       subreq = messaging_read_send(table, client->ev_ctx, client->msg_ctx,
                                     MSG_SMBXSRV_SESSION_CLOSE);
        if (subreq == NULL) {
-               smbd_server_connection_terminate(conn,
-                                                "msg_read_send() failed");
+               const char *r;
+               r = "messaging_read_send(MSG_SMBXSRV_SESSION_CLOSE) failed";
+               exit_server_cleanly(r);
                return;
        }
-       tevent_req_set_callback(subreq, smbXsrv_session_close_loop, conn);
+       tevent_req_set_callback(subreq, smbXsrv_session_close_loop, client);
 }
 
 struct smb1srv_session_local_allocate_state {
@@ -874,7 +881,7 @@ struct tevent_req *smb2srv_session_close_previous_send(TALLOC_CTX *mem_ctx,
        struct smb2srv_session_close_previous_state *state;
        uint32_t global_id = previous_session_id & UINT32_MAX;
        uint64_t global_zeros = previous_session_id & 0xFFFFFFFF00000000LLU;
-       struct smbXsrv_session_table *table = conn->session_table;
+       struct smbXsrv_session_table *table = conn->client->session_table;
        struct security_token *current_token = NULL;
        uint8_t key_buf[SMBXSRV_SESSION_GLOBAL_TDB_KEY_SIZE];
        TDB_DATA key;
@@ -1070,7 +1077,7 @@ NTSTATUS smbXsrv_session_create(struct smbXsrv_connection *conn,
                                NTTIME now,
                                struct smbXsrv_session **_session)
 {
-       struct smbXsrv_session_table *table = conn->session_table;
+       struct smbXsrv_session_table *table = conn->client->session_table;
        struct db_record *local_rec = NULL;
        struct smbXsrv_session *session = NULL;
        void *ptr = NULL;
@@ -1406,7 +1413,7 @@ static int smbXsrv_session_logoff_all_callback(struct db_record *local_rec,
 
 NTSTATUS smbXsrv_session_logoff_all(struct smbXsrv_connection *conn)
 {
-       struct smbXsrv_session_table *table = conn->session_table;
+       struct smbXsrv_session_table *table = conn->client->session_table;
        struct smbXsrv_session_logoff_all_state state;
        NTSTATUS status;
        int count = 0;
@@ -1489,7 +1496,7 @@ NTSTATUS smb1srv_session_lookup(struct smbXsrv_connection *conn,
                                uint16_t vuid, NTTIME now,
                                struct smbXsrv_session **session)
 {
-       struct smbXsrv_session_table *table = conn->session_table;
+       struct smbXsrv_session_table *table = conn->client->session_table;
        uint32_t local_id = vuid;
 
        return smbXsrv_session_local_lookup(table, local_id, now, session);
@@ -1504,11 +1511,10 @@ NTSTATUS smb2srv_session_table_init(struct smbXsrv_connection *conn)
                                          UINT16_MAX - 1);
 }
 
-NTSTATUS smb2srv_session_lookup(struct smbXsrv_connection *conn,
-                               uint64_t session_id, NTTIME now,
-                               struct smbXsrv_session **session)
+static NTSTATUS smb2srv_session_lookup_raw(struct smbXsrv_session_table *table,
+                                          uint64_t session_id, NTTIME now,
+                                          struct smbXsrv_session **session)
 {
-       struct smbXsrv_session_table *table = conn->session_table;
        uint32_t local_id = session_id & UINT32_MAX;
        uint64_t local_zeros = session_id & 0xFFFFFFFF00000000LLU;
 
@@ -1519,6 +1525,14 @@ NTSTATUS smb2srv_session_lookup(struct smbXsrv_connection *conn,
        return smbXsrv_session_local_lookup(table, local_id, now, session);
 }
 
+NTSTATUS smb2srv_session_lookup(struct smbXsrv_connection *conn,
+                               uint64_t session_id, NTTIME now,
+                               struct smbXsrv_session **session)
+{
+       struct smbXsrv_session_table *table = conn->client->session_table;
+       return smb2srv_session_lookup_raw(table, session_id, now, session);
+}
+
 struct smbXsrv_session_global_traverse_state {
        int (*fn)(struct smbXsrv_session_global0 *, void *);
        void *private_data;
index 353f09056f010788eef7c5dce3ae6bd8d9163780..8d0c292b0abce2039b781460baa9b2ffe504e746 100644 (file)
@@ -1071,15 +1071,17 @@ static int smbXsrv_tcon_disconnect_all_callback(struct db_record *local_rec,
 
 NTSTATUS smb1srv_tcon_table_init(struct smbXsrv_connection *conn)
 {
+       struct smbXsrv_client *client = conn->client;
+
        /*
         * Allow a range from 1..65534 with 65534 values.
         */
-       conn->tcon_table = talloc_zero(conn, struct smbXsrv_tcon_table);
-       if (conn->tcon_table == NULL) {
+       client->tcon_table = talloc_zero(client, struct smbXsrv_tcon_table);
+       if (client->tcon_table == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
 
-       return smbXsrv_tcon_table_init(conn, conn->tcon_table,
+       return smbXsrv_tcon_table_init(client, client->tcon_table,
                                       1, UINT16_MAX - 1,
                                       UINT16_MAX - 1);
 }
@@ -1090,7 +1092,7 @@ NTSTATUS smb1srv_tcon_create(struct smbXsrv_connection *conn,
 {
        struct server_id id = messaging_server_id(conn->msg_ctx);
 
-       return smbXsrv_tcon_create(conn->tcon_table,
+       return smbXsrv_tcon_create(conn->client->tcon_table,
                                   conn->protocol,
                                   id, now, _tcon);
 }
@@ -1101,12 +1103,14 @@ NTSTATUS smb1srv_tcon_lookup(struct smbXsrv_connection *conn,
 {
        uint32_t local_id = tree_id;
 
-       return smbXsrv_tcon_local_lookup(conn->tcon_table,
+       return smbXsrv_tcon_local_lookup(conn->client->tcon_table,
                                         local_id, now, tcon);
 }
 
 NTSTATUS smb1srv_tcon_disconnect_all(struct smbXsrv_connection *conn)
 {
+       struct smbXsrv_client *client = conn->client;
+
        /*
         * We do not pass a vuid here,
         * which means the vuid is taken from
@@ -1121,7 +1125,7 @@ NTSTATUS smb1srv_tcon_disconnect_all(struct smbXsrv_connection *conn)
         * conn_close_all(), but we should think
         * about how to fix this in future.
         */
-       return smbXsrv_tcon_disconnect_all(conn->tcon_table, 0);
+       return smbXsrv_tcon_disconnect_all(client->tcon_table, 0);
 }
 
 NTSTATUS smb2srv_tcon_table_init(struct smbXsrv_session *session)