2 Unix SMB/CIFS implementation.
3 Manage smbsrv_tcon structures
4 Copyright (C) Andrew Tridgell 1998
5 Copyright (C) Alexander Bokovoy 2002
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "system/filesys.h"
24 #include "dlinklist.h"
25 #include "smb_server/smb_server.h"
26 #include "smbd/service_stream.h"
29 /****************************************************************************
30 init the tcon structures
31 ****************************************************************************/
32 void smbsrv_tcon_init(struct smbsrv_connection *smb_conn)
34 smb_conn->tree.idtree_tid = idr_init(smb_conn);
37 /****************************************************************************
38 find a tcon given a cnum
39 ****************************************************************************/
40 struct smbsrv_tcon *smbsrv_tcon_find(struct smbsrv_connection *smb_conn, uint_t tid)
42 return idr_find(smb_conn->tree.idtree_tid, tid);
46 destroy a connection structure
48 static int smbsrv_tcon_destructor(void *ptr)
50 struct smbsrv_tcon *tcon = ptr;
53 DEBUG(3,("%s closed connection to service %s\n",
54 socket_get_peer_addr(tcon->smb_conn->connection->socket, tcon),
55 lp_servicename(SNUM(tcon))));
57 /* tell the ntvfs backend that we are disconnecting */
58 ntvfs_disconnect(tcon);
60 idr_remove(tcon->smb_conn->tree.idtree_tid, tcon->tid);
61 DLIST_REMOVE(tcon->smb_conn->tree.tcons, tcon);
66 find first available connection slot
68 struct smbsrv_tcon *smbsrv_tcon_new(struct smbsrv_connection *smb_conn)
70 struct smbsrv_tcon *tcon;
73 tcon = talloc_zero(smb_conn, struct smbsrv_tcon);
74 if (!tcon) return NULL;
76 i = idr_get_new(smb_conn->tree.idtree_tid, tcon, UINT16_MAX);
78 DEBUG(1,("ERROR! Out of connection structures\n"));
83 tcon->smb_conn = smb_conn;
85 talloc_set_destructor(tcon, smbsrv_tcon_destructor);
87 DLIST_ADD(smb_conn->tree.tcons, tcon);