/*
Unix SMB / CIFS implementation .
2004-06-28 08:27:36 +00:00
Manage smbsrv_tcon structures
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"
/* set these to define the limits of the server. NOTE These are on a
per - client basis . Thus any one machine can ' t connect to more than
MAX_CONNECTIONS services , but any number of machines may connect at
one time . */
# define MAX_CONNECTIONS 128
/****************************************************************************
2004-06-28 08:27:36 +00:00
init the tcon structures
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-06-29 07:40:14 +00:00
void conn_init ( struct smbsrv_connection * smb_conn )
{
2004-06-29 07:40:14 +00:00
smb_conn - > tree . bmap = bitmap_allocate ( MAX_CONNECTIONS ) ;
}
/****************************************************************************
check if a snum is in use
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-06-29 07:40:14 +00:00
BOOL conn_snum_used ( struct smbsrv_connection * smb_conn , int snum )
{
2004-06-28 08:27:36 +00:00
struct smbsrv_tcon * tcon ;
2004-06-29 07:40:14 +00:00
for ( tcon = smb_conn - > tree . tcons ; tcon ; tcon = tcon - > next ) {
2004-06-28 08:27:36 +00:00
if ( tcon - > service = = snum ) {
return ( True ) ;
}
}
return ( False ) ;
}
/****************************************************************************
2004-06-28 08:27:36 +00:00
find a tcon given a cnum
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-06-29 07:40:14 +00:00
struct smbsrv_tcon * conn_find ( struct smbsrv_connection * smb_conn , uint_t cnum )
{
int count = 0 ;
2004-06-28 08:27:36 +00:00
struct smbsrv_tcon * tcon ;
2004-06-29 07:40:14 +00:00
for ( tcon = smb_conn - > tree . tcons ; tcon ; tcon = tcon - > next , count + + ) {
2004-06-28 08:27:36 +00:00
if ( tcon - > cnum = = cnum ) {
if ( count > 10 ) {
2004-06-29 07:40:14 +00:00
DLIST_PROMOTE ( smb_conn - > tree . tcons , tcon ) ;
}
2004-06-28 08:27:36 +00:00
return tcon ;
}
}
return NULL ;
}
/****************************************************************************
find first available connection slot , starting from a random position .
The randomisation stops problems with the server dieing and clients
thinking the server is still available .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-06-29 07:40:14 +00:00
struct smbsrv_tcon * conn_new ( struct smbsrv_connection * smb_conn )
{
2004-06-28 08:27:36 +00:00
struct smbsrv_tcon * tcon ;
int i ;
2004-06-29 07:40:14 +00:00
i = bitmap_find ( smb_conn - > tree . bmap , 1 ) ;
if ( i = = - 1 ) {
DEBUG ( 1 , ( " ERROR! Out of connection structures \n " ) ) ;
return NULL ;
}
2004-09-08 05:39:06 +00:00
tcon = talloc_p ( smb_conn , struct smbsrv_tcon ) ;
2004-06-28 08:27:36 +00:00
if ( ! tcon ) return NULL ;
2004-06-28 08:27:36 +00:00
ZERO_STRUCTP ( tcon ) ;
2004-06-28 08:27:36 +00:00
tcon - > cnum = i ;
2004-06-29 07:40:14 +00:00
tcon - > smb_conn = smb_conn ;
2004-06-29 07:40:14 +00:00
bitmap_set ( smb_conn - > tree . bmap , i ) ;
2004-06-29 07:40:14 +00:00
smb_conn - > tree . num_open + + ;
2004-06-29 07:40:14 +00:00
DLIST_ADD ( smb_conn - > tree . tcons , tcon ) ;
2004-06-28 08:27:36 +00:00
return tcon ;
}
/****************************************************************************
2004-06-28 08:27:36 +00:00
close all tcon structures
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-06-29 07:40:14 +00:00
void conn_close_all ( struct smbsrv_connection * smb_conn )
{
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 ) ;
}
}
# if REWRITE_REMOVED
/****************************************************************************
clear a vuid out of the validity cache , and as the ' owner ' of a connection .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-06-29 07:40:14 +00:00
void conn_clear_vuid_cache ( struct smbsrv_connection * smb_conn , uint16_t vuid )
{
2004-06-28 08:27:36 +00:00
struct smbsrv_tcon * tcon ;
2004-06-01 08:12:45 +00:00
uint_t i ;
2004-06-29 07:40:14 +00:00
for ( tcon = smb_conn - > tree . tcons ; tcon ; tcon = tcon - > next ) {
2004-06-28 08:27:36 +00:00
for ( i = 0 ; i < tcon - > vuid_cache . entries & & i < VUID_CACHE_SIZE ; i + + ) {
if ( tcon - > vuid_cache . list [ i ] = = vuid ) {
tcon - > vuid_cache . list [ i ] = UID_FIELD_INVALID ;
}
}
}
}
# endif
/****************************************************************************
2004-06-28 08:27:36 +00:00
Free a tcon structure .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-06-29 07:40:14 +00:00
void conn_free ( struct smbsrv_connection * smb_conn , struct smbsrv_tcon * tcon )
{
2004-06-29 07:40:14 +00:00
DLIST_REMOVE ( smb_conn - > tree . tcons , tcon ) ;
2004-06-29 07:40:14 +00:00
bitmap_clear ( smb_conn - > tree . bmap , tcon - > cnum ) ;
smb_conn - > tree . num_open - - ;
2004-09-08 05:39:06 +00:00
talloc_destroy ( tcon ) ;
}