r4726: - use the name tcon and tid instead of conn and cnum
authorStefan Metzmacher <metze@samba.org>
Thu, 13 Jan 2005 18:49:10 +0000 (18:49 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:08:48 +0000 (13:08 -0500)
- make use of talloc destructors

metze
(This used to be commit 8308da6ce4a95f8c10e22949ef00e9e64f2dbb85)

12 files changed:
source4/include/smb_interfaces.h
source4/libcli/cliconnect.c
source4/libcli/raw/clitree.c
source4/libcli/util/clilsa.c
source4/ntvfs/cifs/vfs_cifs.c
source4/smb_server/conn.c
source4/smb_server/reply.c
source4/smb_server/service.c
source4/smb_server/smb_server.c
source4/smb_server/smb_server.h
source4/torture/raw/context.c
source4/torture/rpc/xplogin.c

index 1eca1fe360150c22e4f5068e9a027f4bbac7cab3..5fae275f102299da309b3483a805df53bffc263f 100644 (file)
@@ -177,7 +177,7 @@ union smb_tcon {
                } in;
                struct {
                        uint16_t max_xmit;
-                       uint16_t cnum;
+                       uint16_t tid;
                } out;
        } tcon;
 
@@ -195,7 +195,7 @@ union smb_tcon {
                        uint16_t options;
                        char *dev_type;
                        char *fs_type;
-                       uint16_t cnum;
+                       uint16_t tid;
                } out;
        } tconx;
 };
index 6185ba7b7d0f737c8dc1c429f78fdb903e4f56cb..a0ba5ae0a1a7ffdd88be6664ae7cf4c26059b368 100644 (file)
@@ -140,7 +140,7 @@ NTSTATUS smbcli_send_tconX(struct smbcli_state *cli, const char *sharename,
        
        status = smb_tree_connect(cli->tree, mem_ctx, &tcon);
 
-       cli->tree->tid = tcon.tconx.out.cnum;
+       cli->tree->tid = tcon.tconx.out.tid;
 
        talloc_free(mem_ctx);
 
index 777279f5f94bdf076fd5eb9cf8bcdcc8a824a46a..0f56c0fe2e7fb50bdce6d99a5aa7693e24f46681 100644 (file)
@@ -96,12 +96,12 @@ NTSTATUS smb_tree_connect_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx,
        case RAW_TCON_TCON:
                SMBCLI_CHECK_WCT(req, 2);
                parms->tcon.out.max_xmit = SVAL(req->in.vwv, VWV(0));
-               parms->tcon.out.cnum = SVAL(req->in.vwv, VWV(1));
+               parms->tcon.out.tid = SVAL(req->in.vwv, VWV(1));
                break;
 
        case RAW_TCON_TCONX:
                ZERO_STRUCT(parms->tconx.out);
-               parms->tconx.out.cnum = SVAL(req->in.hdr, HDR_TID);
+               parms->tconx.out.tid = SVAL(req->in.hdr, HDR_TID);
                if (req->in.wct >= 4) {
                        parms->tconx.out.options = SVAL(req->in.vwv, VWV(3));
                }
@@ -274,7 +274,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx,
                return status;
        }
 
-       tree->tid = tcon.tconx.out.cnum;
+       tree->tid = tcon.tconx.out.tid;
        if (tcon.tconx.out.dev_type) {
                tree->device = talloc_strdup(tree, tcon.tconx.out.dev_type);
        }
index c032af0abc58fe13a08490e21f7c86de35d7cd9f..eac698425425bd4a661487023f71bc05b592ba04 100644 (file)
@@ -74,7 +74,7 @@ static NTSTATUS smblsa_connect(struct smbcli_state *cli)
                talloc_free(lsa);
                return status;
        }
-       lsa->ipc_tree->tid = tcon.tconx.out.cnum;
+       lsa->ipc_tree->tid = tcon.tconx.out.tid;
 
        lsa->pipe = dcerpc_pipe_init(lsa);
        if (lsa->pipe == NULL) {
index 736aa3652f1bd75598ee12fd6c1716e840d2c6b4..2a76d245ace0bdf34449a2f0bd79bb4b54dc76b5 100644 (file)
@@ -88,7 +88,7 @@ static void cifs_socket_handler(struct event_context *ev, struct fd_event *fde,
        
        if (!smbcli_transport_process(private->transport)) {
                /* the connection to our server is dead */
-               close_cnum(tcon);
+               talloc_free(tcon);
        }
 }
 
index a4bf2716febd4f422b5a7ae0dd71aa4fdda0c7ef..c70ed95915c1f05640eb7f9ca0419e5aced257fb 100644 (file)
@@ -28,7 +28,7 @@
 /****************************************************************************
 init the tcon structures
 ****************************************************************************/
-void conn_init(struct smbsrv_connection *smb_conn)
+void smbsrv_tcon_init(struct smbsrv_connection *smb_conn)
 {
        smb_conn->tree.idtree_tid = idr_init(smb_conn);
 }
@@ -36,18 +36,27 @@ void conn_init(struct smbsrv_connection *smb_conn)
 /****************************************************************************
 find a tcon given a cnum
 ****************************************************************************/
-struct smbsrv_tcon *conn_find(struct smbsrv_connection *smb_conn, uint_t cnum)
+struct smbsrv_tcon *smbsrv_tcon_find(struct smbsrv_connection *smb_conn, uint_t tid)
 {
-       return idr_find(smb_conn->tree.idtree_tid, cnum);
+       return idr_find(smb_conn->tree.idtree_tid, tid);
 }
 
 /*
   destroy a connection structure
 */
-static int conn_destructor(void *ptr)
+static int smbsrv_tcon_destructor(void *ptr)
 {
        struct smbsrv_tcon *tcon = ptr;
-       idr_remove(tcon->smb_conn->tree.idtree_tid, tcon->cnum);
+
+
+       DEBUG(3,("%s closed connection to service %s\n",
+                socket_get_peer_addr(tcon->smb_conn->connection->socket, tcon),
+                lp_servicename(SNUM(tcon))));
+
+       /* tell the ntvfs backend that we are disconnecting */
+       ntvfs_disconnect(tcon);
+
+       idr_remove(tcon->smb_conn->tree.idtree_tid, tcon->tid);
        DLIST_REMOVE(tcon->smb_conn->tree.tcons, tcon);
        return 0;
 }
@@ -55,7 +64,7 @@ static int conn_destructor(void *ptr)
 /*
   find first available connection slot
 */
-struct smbsrv_tcon *conn_new(struct smbsrv_connection *smb_conn)
+struct smbsrv_tcon *smbsrv_tcon_new(struct smbsrv_connection *smb_conn)
 {
        struct smbsrv_tcon *tcon;
        int i;
@@ -69,34 +78,12 @@ struct smbsrv_tcon *conn_new(struct smbsrv_connection *smb_conn)
                return NULL;
        }
 
-       tcon->cnum = i;
+       tcon->tid = i;
        tcon->smb_conn = smb_conn;
 
-       talloc_set_destructor(tcon, conn_destructor);
+       talloc_set_destructor(tcon, smbsrv_tcon_destructor);
 
        DLIST_ADD(smb_conn->tree.tcons, tcon);
 
        return tcon;
 }
-
-/****************************************************************************
-close all tcon structures
-****************************************************************************/
-void conn_close_all(struct smbsrv_connection *smb_conn)
-{
-       struct smbsrv_tcon *tcon, *next;
-       for (tcon=smb_conn->tree.tcons;tcon;tcon=next) {
-               next=tcon->next;
-               close_cnum(tcon);
-       }
-}
-
-
-/****************************************************************************
- Free a tcon structure.
-****************************************************************************/
-void conn_free(struct smbsrv_connection *smb_conn, struct smbsrv_tcon *tcon)
-{
-       talloc_free(tcon);
-}
-
index 2dfa3726e2b67ecfd630cf20d3ed9176b43e4e96..2dc36a3b653cbba83ffc21ebe6c5ab92a0928db1 100644 (file)
@@ -112,8 +112,8 @@ void reply_tcon(struct smbsrv_request *req)
        req_setup_reply(req, 2, 0);
 
        SSVAL(req->out.vwv, VWV(0), con.tcon.out.max_xmit);
-       SSVAL(req->out.vwv, VWV(1), con.tcon.out.cnum);
-       SSVAL(req->out.hdr, HDR_TID, req->tcon->cnum);
+       SSVAL(req->out.vwv, VWV(1), con.tcon.out.tid);
+       SSVAL(req->out.hdr, HDR_TID, req->tcon->tid);
   
        req_send_reply(req);
 }
@@ -181,8 +181,8 @@ void reply_tcon_and_X(struct smbsrv_request *req)
        }
 
        /* set the incoming and outgoing tid to the just created one */
-       SSVAL(req->in.hdr, HDR_TID, con.tconx.out.cnum);
-       SSVAL(req->out.hdr,HDR_TID, con.tconx.out.cnum);
+       SSVAL(req->in.hdr, HDR_TID, con.tconx.out.tid);
+       SSVAL(req->out.hdr,HDR_TID, con.tconx.out.tid);
 
        chain_reply(req);
 }
@@ -1360,7 +1360,7 @@ void reply_tdis(struct smbsrv_request *req)
                return;
        }
 
-       close_cnum(req->tcon);
+       talloc_free(req->tcon);
 
        /* construct reply */
        req_setup_reply(req, 0, 0);
index 12a983e41b80f64762ee36dfb262862eba1e2cbd..1aa41d17a859a1bc9fd09eb986cbee2d093a9e2b 100644 (file)
@@ -152,7 +152,7 @@ static NTSTATUS make_connection_snum(struct smbsrv_request *req,
                return NT_STATUS_ACCESS_DENIED;
        }
 
-       tcon = conn_new(req->smb_conn);
+       tcon = smbsrv_tcon_new(req->smb_conn);
        if (!tcon) {
                DEBUG(0,("Couldn't find free connection.\n"));
                return NT_STATUS_INSUFFICIENT_RESOURCES;
@@ -165,18 +165,16 @@ static NTSTATUS make_connection_snum(struct smbsrv_request *req,
        status = ntvfs_init_connection(req, type);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("ntvfs_init_connection failed for service %s\n", lp_servicename(SNUM(tcon))));
-               conn_free(req->smb_conn, tcon);
                return status;
        }
-       
+
        /* Invoke NTVFS connection hook */
        status = ntvfs_connect(req, lp_servicename(snum));
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("make_connection: NTVFS make connection failed!\n"));
-               conn_free(req->smb_conn, tcon);
                return status;
        }
-       
+
        return NT_STATUS_OK;
 }
 
@@ -229,23 +227,6 @@ static NTSTATUS make_connection(struct smbsrv_request *req,
        return make_connection_snum(req, snum, type, password, dev);
 }
 
-/****************************************************************************
-close a cnum
-****************************************************************************/
-void close_cnum(struct smbsrv_tcon *tcon)
-{
-       DEBUG(3,("%s closed connection to service %s\n",
-                socket_get_peer_addr(tcon->smb_conn->connection->socket, tcon),
-                lp_servicename(SNUM(tcon))));
-
-       /* tell the ntvfs backend that we are disconnecting */
-       ntvfs_disconnect(tcon);
-
-       conn_free(tcon->smb_conn, tcon);
-}
-
-
-
 /*
   backend for tree connect call
 */
@@ -274,8 +255,8 @@ NTSTATUS tcon_backend(struct smbsrv_request *req, union smb_tcon *con)
                }
 
                con->tcon.out.max_xmit = req->smb_conn->negotiate.max_recv;
-               con->tcon.out.cnum = req->tcon->cnum;
-               
+               con->tcon.out.tid = req->tcon->tid;
+
                return status;
        } 
 
@@ -285,7 +266,7 @@ NTSTATUS tcon_backend(struct smbsrv_request *req, union smb_tcon *con)
                return status;
        }
 
-       con->tconx.out.cnum = req->tcon->cnum;
+       con->tconx.out.tid = req->tcon->tid;
        con->tconx.out.dev_type = talloc_strdup(req, req->tcon->dev_type);
        con->tconx.out.fs_type = talloc_strdup(req, req->tcon->fs_type);
        con->tconx.out.options = SMB_SUPPORT_SEARCH_BITS | (lp_csc_policy(req->tcon->service) << 2);
index 0b2fe668af0b7e704bbcfe009297b285c7b1c59a..ddbaf43cc92299d1630bb56fea1bf83d0741cadc 100644 (file)
@@ -39,7 +39,7 @@ BOOL req_send_oplock_break(struct smbsrv_tcon *tcon, uint16_t fnum, uint8_t leve
        req_setup_reply(req, 8, 0);
        
        SCVAL(req->out.hdr,HDR_COM,SMBlockingX);
-       SSVAL(req->out.hdr,HDR_TID,tcon->cnum);
+       SSVAL(req->out.hdr,HDR_TID,tcon->tid);
        SSVAL(req->out.hdr,HDR_PID,0xFFFF);
        SSVAL(req->out.hdr,HDR_UID,0);
        SSVAL(req->out.hdr,HDR_MID,0xFFFF);
@@ -484,7 +484,7 @@ static void switch_message(int type, struct smbsrv_request *req)
 
        flags = smb_messages[type].flags;
 
-       req->tcon = conn_find(smb_conn, SVAL(req->in.hdr,HDR_TID));
+       req->tcon = smbsrv_tcon_find(smb_conn, SVAL(req->in.hdr,HDR_TID));
 
        if (req->session == NULL) {
                /* setup the user context for this request if it
@@ -792,8 +792,6 @@ static void smbsrv_close(struct server_connection *conn, const char *reason)
 
        DEBUG(5,("smbsrv_close: %s\n",reason));
 
-       conn_close_all(smb_conn);
-
        talloc_free(smb_conn);
 
        return;
@@ -846,7 +844,7 @@ void smbsrv_accept(struct server_connection *conn)
 
        srv_init_signing(smb_conn);
 
-       conn_init(smb_conn);
+       smbsrv_tcon_init(smb_conn);
 
        smb_conn->connection = conn;
 
index 8486ad0da6fe17db708d393f7958fedc9fbb79d4..8a21051b65c2072580ec2d12b12c892517a7ba4b 100644 (file)
@@ -59,7 +59,8 @@ struct smbsrv_tcon {
        /* the server context that this was created on */
        struct smbsrv_connection *smb_conn;
 
-       uint16_t cnum; /* an index passed over the wire (the TID) */
+       uint16_t tid; /* an index passed over the wire (the TID) */
+
        int service;
        BOOL read_only;
        BOOL admin_user;
index d0a948c401a4abe583cf89679344aff64902c3f7..20b93792dfe716bbab79c9743297447333c17836 100644 (file)
@@ -229,7 +229,7 @@ static BOOL test_tree(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        status = smb_tree_connect(tree, mem_ctx, &tcon);
        CHECK_STATUS(status, NT_STATUS_OK);
 
-       tree->tid = tcon.tconx.out.cnum;
+       tree->tid = tcon.tconx.out.tid;
        printf("tid1=%d tid2=%d\n", cli->tree->tid, tree->tid);
 
        printf("try a tconx with a bad device type\n");
index 9002e4649a500d884526ee48425b10597a0cb46f..ce16cf2b1d1727d1a592b2065a25030ebaa8f20c 100644 (file)
@@ -163,7 +163,7 @@ static NTSTATUS anon_ipc(struct smbcli_transport *transport,
                return NT_STATUS_UNSUCCESSFUL;
        }
 
-       tree->tid = tcon.tconx.out.cnum;
+       tree->tid = tcon.tconx.out.tid;
 
        if (tcon.tconx.out.dev_type != NULL)
                tree->device = talloc_strdup(tree, tcon.tconx.out.dev_type);