2003-08-13 01:53:07 +00:00
/*
Unix SMB / CIFS implementation .
2004-06-28 08:27:36 +00:00
Manage smbsrv_tcon structures
2003-08-13 01:53:07 +00:00
Copyright ( C ) Andrew Tridgell 1998
Copyright ( C ) Alexander Bokovoy 2002
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2004-11-02 03:44:52 +00:00
# include "system/filesys.h"
2003-08-13 01:53:07 +00:00
/****************************************************************************
2004-06-28 08:27:36 +00:00
init the tcon structures
2003-08-13 01:53:07 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-06-29 07:40:14 +00:00
void conn_init ( struct smbsrv_connection * smb_conn )
2003-08-13 01:53:07 +00:00
{
2004-10-19 07:08:35 +00:00
smb_conn - > tree . idtree_tid = idr_init ( smb_conn ) ;
2003-08-13 01:53:07 +00:00
}
/****************************************************************************
2004-06-28 08:27:36 +00:00
find a tcon given a cnum
2003-08-13 01:53:07 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-06-29 07:40:14 +00:00
struct smbsrv_tcon * conn_find ( struct smbsrv_connection * smb_conn , uint_t cnum )
2003-08-13 01:53:07 +00:00
{
2004-10-19 07:08:35 +00:00
return idr_find ( smb_conn - > tree . idtree_tid , cnum ) ;
2003-08-13 01:53:07 +00:00
}
2004-10-19 07:08:35 +00:00
/*
destroy a connection structure
*/
static int conn_destructor ( void * ptr )
{
struct smbsrv_tcon * tcon = ptr ;
idr_remove ( tcon - > smb_conn - > tree . idtree_tid , tcon - > cnum ) ;
DLIST_REMOVE ( tcon - > smb_conn - > tree . tcons , tcon ) ;
return 0 ;
}
2003-08-13 01:53:07 +00:00
2004-10-19 07:08:35 +00:00
/*
find first available connection slot
*/
2004-06-29 07:40:14 +00:00
struct smbsrv_tcon * conn_new ( struct smbsrv_connection * smb_conn )
2003-08-13 01:53:07 +00:00
{
2004-06-28 08:27:36 +00:00
struct smbsrv_tcon * tcon ;
2003-08-13 01:53:07 +00:00
int i ;
2004-10-19 07:08:35 +00:00
tcon = talloc_zero_p ( smb_conn , struct smbsrv_tcon ) ;
if ( ! tcon ) return NULL ;
2004-10-19 12:06:01 +00:00
i = idr_get_new ( smb_conn - > tree . idtree_tid , tcon , UINT16_MAX ) ;
2003-08-13 01:53:07 +00:00
if ( i = = - 1 ) {
DEBUG ( 1 , ( " ERROR! Out of connection structures \n " ) ) ;
return NULL ;
}
2004-06-28 08:27:36 +00:00
tcon - > cnum = i ;
2004-06-29 07:40:14 +00:00
tcon - > smb_conn = smb_conn ;
2003-08-13 01:53:07 +00:00
2004-10-19 07:08:35 +00:00
talloc_set_destructor ( tcon , conn_destructor ) ;
2003-08-13 01:53:07 +00:00
2004-06-29 07:40:14 +00:00
DLIST_ADD ( smb_conn - > tree . tcons , tcon ) ;
2003-08-13 01:53:07 +00:00
2004-06-28 08:27:36 +00:00
return tcon ;
2003-08-13 01:53:07 +00:00
}
/****************************************************************************
2004-06-28 08:27:36 +00:00
close all tcon structures
2003-08-13 01:53:07 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-06-29 07:40:14 +00:00
void conn_close_all ( struct smbsrv_connection * smb_conn )
2003-08-13 01:53:07 +00:00
{
2004-06-28 08:27:36 +00:00
struct smbsrv_tcon * tcon , * next ;
2004-06-29 07:40:14 +00:00
for ( tcon = smb_conn - > tree . tcons ; tcon ; tcon = next ) {
2004-06-28 08:27:36 +00:00
next = tcon - > next ;
close_cnum ( tcon ) ;
2003-08-13 01:53:07 +00:00
}
}
/****************************************************************************
2004-06-28 08:27:36 +00:00
Free a tcon structure .
2003-08-13 01:53:07 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-06-29 07:40:14 +00:00
void conn_free ( struct smbsrv_connection * smb_conn , struct smbsrv_tcon * tcon )
2003-08-13 01:53:07 +00:00
{
2004-10-19 07:08:35 +00:00
talloc_free ( tcon ) ;
2003-08-13 01:53:07 +00:00
}