5step:smb1 use smbXsrv_tcon_table: use smb1srv_tcon... smb1 TODO 'now'
authorStefan Metzmacher <metze@samba.org>
Wed, 28 Mar 2012 14:14:09 +0000 (16:14 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 16 May 2012 06:10:20 +0000 (08:10 +0200)
source3/include/smb.h
source3/smbd/conn.c
source3/smbd/conn_idle.c
source3/smbd/globals.h
source3/smbd/process.c
source3/smbd/proto.h
source3/smbd/reply.c
source3/smbd/service.c

index 9042d9f91c2ff9b72b70ed1656f69694a3c1a510..64ea9a469a2bdddea6b28dfb35f5b5c03533d59d 100644 (file)
@@ -367,7 +367,7 @@ struct share_params {
 typedef struct connection_struct {
        struct connection_struct *next, *prev;
        struct smbd_server_connection *sconn; /* can be NULL */
-       struct smbXsrv_tcon0 *tcon; /* for now NULL for SMB1 */
+       struct smbXsrv_tcon0 *tcon; /* can be NULL */
        unsigned cnum; /* an index passed over the wire */
        struct share_params *params;
        bool force_user;
index 12002e37a2a8192cb9c52f3d2e6b556011740cf0..fa25fdbe0fd48f2bb7502d9367efdf78de6a0719 100644 (file)
 #include "smbd/globals.h"
 #include "lib/util/bitmap.h"
 
-/* The connections bitmap is expanded in increments of BITMAP_BLOCK_SZ. The
- * maximum size of the bitmap is the largest positive integer, but you will hit
- * the "max connections" limit, looong before that.
- */
-
-#define BITMAP_BLOCK_SZ 128
-
-/****************************************************************************
- Init the conn structures.
-****************************************************************************/
-
-void conn_init(struct smbd_server_connection *sconn)
-{
-       sconn->smb1.tcons.bmap = bitmap_talloc(sconn, BITMAP_BLOCK_SZ);
-}
-
 /****************************************************************************
  Return the number of open connections.
 ****************************************************************************/
@@ -67,27 +51,6 @@ bool conn_snum_used(struct smbd_server_connection *sconn,
        return false;
 }
 
-/****************************************************************************
- Find a conn given a cnum.
-****************************************************************************/
-
-connection_struct *conn_find(struct smbd_server_connection *sconn,unsigned cnum)
-{
-       size_t count=0;
-       struct connection_struct *conn;
-
-       for (conn=sconn->connections; conn; conn=conn->next,count++) {
-               if (conn->cnum == cnum) {
-                       if (count > 10) {
-                               DLIST_PROMOTE(sconn->connections, conn);
-                       }
-                       return conn;
-               }
-       }
-
-       return NULL;
-}
-
 /****************************************************************************
  Find first available connection slot, starting from a random position.
  The randomisation stops problems with the server dieing and clients
@@ -97,69 +60,6 @@ connection_struct *conn_find(struct smbd_server_connection *sconn,unsigned cnum)
 connection_struct *conn_new(struct smbd_server_connection *sconn)
 {
        connection_struct *conn;
-       int i;
-        int find_offset = 1;
-
-       if (sconn->using_smb2) {
-               /* SMB2 */
-               if (!(conn=talloc_zero(NULL, connection_struct)) ||
-                   !(conn->params = talloc(conn, struct share_params))) {
-                       DEBUG(0,("TALLOC_ZERO() failed!\n"));
-                       TALLOC_FREE(conn);
-                       return NULL;
-               }
-               conn->sconn = sconn;
-
-               DLIST_ADD(sconn->connections, conn);
-               sconn->num_connections++;
-
-               return conn;
-       }
-
-       /* SMB1 */
-find_again:
-       i = bitmap_find(sconn->smb1.tcons.bmap, find_offset);
-
-       if (i == -1) {
-                /* Expand the connections bitmap. */
-                int             oldsz = sconn->smb1.tcons.bmap->n;
-                int             newsz = sconn->smb1.tcons.bmap->n +
-                                       BITMAP_BLOCK_SZ;
-                struct bitmap * nbmap;
-
-                if (newsz <= oldsz) {
-                        /* Integer wrap. */
-                       DEBUG(0,("ERROR! Out of connection structures\n"));
-                        return NULL;
-                }
-
-               DEBUG(4,("resizing connections bitmap from %d to %d\n",
-                        oldsz, newsz));
-
-                nbmap = bitmap_talloc(sconn, newsz);
-               if (!nbmap) {
-                       DEBUG(0,("ERROR! malloc fail.\n"));
-                       return NULL;
-               }
-
-                bitmap_copy(nbmap, sconn->smb1.tcons.bmap);
-               TALLOC_FREE(sconn->smb1.tcons.bmap);
-
-                sconn->smb1.tcons.bmap = nbmap;
-                find_offset = oldsz; /* Start next search in the new portion. */
-
-                goto find_again;
-       }
-
-       /* The bitmap position is used below as the connection number
-        * conn->cnum). This ends up as the TID field in the SMB header,
-        * which is limited to 16 bits (we skip 0xffff which is the
-        * NULL TID).
-        */
-       if (i > 65534) {
-               DEBUG(0, ("Maximum connection limit reached\n"));
-               return NULL;
-       }
 
        if (!(conn=talloc_zero(NULL, connection_struct)) ||
            !(conn->params = talloc(conn, struct share_params))) {
@@ -168,11 +68,8 @@ find_again:
                return NULL;
        }
        conn->sconn = sconn;
-       conn->cnum = i;
        conn->force_group_gid = (gid_t)-1;
 
-       bitmap_set(sconn->smb1.tcons.bmap, i);
-
        string_set(&conn->connectpath,"");
        string_set(&conn->origpath,"");
 
@@ -292,15 +189,6 @@ void conn_free(connection_struct *conn)
                return;
        }
 
-       if (!conn->sconn->using_smb2 &&
-           conn->sconn->smb1.tcons.bmap != NULL) {
-               /*
-                * Can be NULL for fake connections created by
-                * create_conn_struct()
-                */
-               bitmap_clear(conn->sconn->smb1.tcons.bmap, conn->cnum);
-       }
-
        DLIST_REMOVE(conn->sconn->connections, conn);
        SMB_ASSERT(conn->sconn->num_connections > 0);
        conn->sconn->num_connections--;
index 958558188a486aeaf0cfe9be4b5c3c59eb7d0dbe..354d177af5ea6d7d1be9bacd77f233880e46a24c 100644 (file)
@@ -112,7 +112,6 @@ bool conn_close_all(struct smbd_server_connection *sconn)
                set_current_service(conn, 0, True);
                close_cnum(conn, conn->vuid);
 
-               /* for now tcon is NULL for SMB1 */
                TALLOC_FREE(tcon);
 
                ret = true;
@@ -149,7 +148,6 @@ void conn_force_tdis(struct smbd_server_connection *sconn, const char *sharename
                        DEBUG(1,("Forcing close of share %s cnum=%d\n",
                                sharename, conn->cnum));
                        close_cnum(conn, (uint16_t)-1);
-                       /* for now tcon is NULL for SMB1 */
                        TALLOC_FREE(tcon);
                }
        }
index b56c19188ab96908b780a6b91f3ce588e1170b46..060c41c7ba7440fbc72a041bd7020346b8d780ae 100644 (file)
@@ -588,10 +588,6 @@ struct smbd_server_connection {
                         */
                        uint16_t next_vuid;
                } sessions;
-               struct {
-                       /* number of open connections */
-                       struct bitmap *bmap;
-               } tcons;
                struct smb_signing_state *signing_state;
 
                struct notify_mid_map *notify_mid_maps;
index dc62ec547972e90e3e98839d598594386230634e..67f50d93373bd9398285300abd5af68d8e473b4c 100644 (file)
@@ -515,7 +515,12 @@ static bool init_smb_request(struct smb_request *req,
                             size_t unread_bytes, bool encrypted,
                             uint32_t seqnum)
 {
+       struct smbXsrv_tcon *tcon;
+       NTSTATUS status;
+       NTTIME now = 0;
+       //TODO now
        size_t req_size = smb_len(inbuf) + 4;
+
        /* Ensure we have at least smb_size bytes. */
        if (req_size < smb_size) {
                DEBUG(0,("init_smb_request: invalid request size %u\n",
@@ -536,7 +541,12 @@ static bool init_smb_request(struct smb_request *req,
        req->unread_bytes = unread_bytes;
        req->encrypted = encrypted;
        req->sconn = sconn;
-       req->conn = conn_find(sconn,req->tid);
+       status = smb1srv_tcon_lookup(sconn->conn, req->tid, now, &tcon);
+       if (NT_STATUS_IS_OK(status)) {
+               req->conn = tcon->compat;
+       } else {
+               req->conn = NULL;
+       }
        req->chain_fsp = NULL;
        req->smb2req = NULL;
        req->priv_paths = NULL;
@@ -1662,10 +1672,18 @@ void smb_request_done(struct smb_request *req)
 
        while ((next_index < num_reqs) && (IVAL(req->outbuf, smb_rcls) == 0)) {
                struct smb_request *next = reqs[next_index];
+               struct smbXsrv_tcon *tcon;
+               NTTIME now = 0;
 
                next->vuid = SVAL(req->outbuf, smb_uid);
                next->tid  = SVAL(req->outbuf, smb_tid);
-               next->conn = conn_find(req->sconn, req->tid);
+               status = smb1srv_tcon_lookup(req->sconn->conn, req->tid,
+                                            now, &tcon);
+               if (NT_STATUS_IS_OK(status)) {
+                       req->conn = tcon->compat;
+               } else {
+                       req->conn = NULL;
+               }
                next->chain_fsp = req->chain_fsp;
                next->inbuf = (uint8_t *)req->inbuf;
 
@@ -3186,6 +3204,11 @@ NTSTATUS smbXsrv_connection_init_tables(struct smbXsrv_connection *conn,
                if (!NT_STATUS_IS_OK(status)) {
                        return status;
                }
+       } else {
+               status = smb1srv_tcon_table_init(conn);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
        }
 
        return NT_STATUS_OK;
@@ -3463,7 +3486,6 @@ void smbd_process(struct tevent_context *ev_ctx,
        /* this holds info on user ids that are already validated for this VC */
        sconn->smb1.sessions.next_vuid = VUID_OFFSET;
 
-       conn_init(sconn);
        if (!init_dptrs(sconn)) {
                exit_server("init_dptrs() failed");
        }
index 562527c8cea2c9f3ab18aa4ff212032c68938c0b..f3f1be8c56b02d2c084e1b844fa60b15c1ab6e87 100644 (file)
@@ -143,11 +143,8 @@ NTSTATUS delete_all_streams(connection_struct *conn, const char *fname);
 
 /* The following definitions come from smbd/conn.c  */
 
-void conn_init(struct smbd_server_connection *sconn);
 int conn_num_open(struct smbd_server_connection *sconn);
 bool conn_snum_used(struct smbd_server_connection *sconn, int snum);
-connection_struct *conn_find(struct smbd_server_connection *sconn,
-                            unsigned cnum);
 connection_struct *conn_new(struct smbd_server_connection *sconn);
 bool conn_close_all(struct smbd_server_connection *sconn);
 bool conn_idle_all(struct smbd_server_connection *sconn, time_t t);
index 91d12bd3e38502b568e27a4733c46ff544707afe..207a0b6dfcf4a4215f8c038d18c9f0e9b39eb627 100644 (file)
@@ -4373,6 +4373,9 @@ bool is_valid_writeX_buffer(struct smbd_server_connection *sconn,
        connection_struct *conn = NULL;
        unsigned int doff = 0;
        size_t len = smb_len_large(inbuf);
+       struct smbXsrv_tcon *tcon;
+       NTSTATUS status;
+       NTTIME now = 0;
 
        if (is_encrypted_packet(sconn, inbuf)) {
                /* Can't do this on encrypted
@@ -4391,11 +4394,14 @@ bool is_valid_writeX_buffer(struct smbd_server_connection *sconn,
                return false;
        }
 
-       conn = conn_find(sconn, SVAL(inbuf, smb_tid));
-       if (conn == NULL) {
+       status = smb1srv_tcon_lookup(sconn->conn, SVAL(inbuf, smb_tid),
+                                    now, &tcon);
+       if (!NT_STATUS_IS_OK(status)) {
                DEBUG(10,("is_valid_writeX_buffer: bad tid\n"));
                return false;
        }
+       conn = tcon->compat;
+
        if (IS_IPC(conn)) {
                DEBUG(10,("is_valid_writeX_buffer: IPC$ tid\n"));
                return false;
@@ -5059,6 +5065,8 @@ void reply_unlock(struct smb_request *req)
 void reply_tdis(struct smb_request *req)
 {
        connection_struct *conn = req->conn;
+       struct smbXsrv_tcon *tcon;
+
        START_PROFILE(SMBtdis);
 
        if (!conn) {
@@ -5070,7 +5078,10 @@ void reply_tdis(struct smb_request *req)
 
        conn->used = False;
 
+       tcon = conn->tcon;
+
        close_cnum(conn,req->vuid);
+       TALLOC_FREE(tcon);
        req->conn = NULL;
 
        reply_outbuf(req, 0, 0);
index 26c25e427a3af6b716127af5a28cf5872845b766..435713bd60445bca4a7649bed5c45704a6fd98ad 100644 (file)
@@ -921,12 +921,33 @@ static connection_struct *make_connection_smb1(struct smbd_server_connection *sc
                                        const char *pdev,
                                        NTSTATUS *pstatus)
 {
-       connection_struct *conn = conn_new(sconn);
+       struct smbXsrv_tcon *tcon;
+       NTSTATUS status;
+       NTTIME now = 0;
+       struct connection_struct *conn;
+
+       status = smb1srv_tcon_create(sconn->conn, now, &tcon);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0,("make_connection_smb1: Couldn't find free tcon %s.\n",
+                        nt_errstr(status)));
+               *pstatus = status;
+               return NULL;
+       }
+
+       conn = conn_new(sconn);
        if (!conn) {
+               TALLOC_FREE(tcon);
+
                DEBUG(0,("make_connection_smb1: Couldn't find free connection.\n"));
                *pstatus = NT_STATUS_INSUFFICIENT_RESOURCES;
                return NULL;
        }
+
+       conn->cnum = tcon->global->tcon_wire_id;
+       conn->tcon = tcon;
+       tcon->compat = conn;
+       talloc_steal(tcon, conn);
+
        *pstatus = make_connection_snum(sconn,
                                        conn,
                                        snum,
@@ -934,8 +955,19 @@ static connection_struct *make_connection_smb1(struct smbd_server_connection *sc
                                        pdev);
        if (!NT_STATUS_IS_OK(*pstatus)) {
                conn_free(conn);
+               TALLOC_FREE(tcon);
                return NULL;
        }
+
+       tcon->status = NT_STATUS_OK;
+
+       *pstatus = smbXsrv_tcon_update(tcon);
+       if (!NT_STATUS_IS_OK(*pstatus)) {
+               conn_free(conn);
+               TALLOC_FREE(tcon);
+               return NULL;
+       }
+
        return conn;
 }