1998-03-15 05:37:52 +03:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
1998-03-15 05:37:52 +03:00
connection claim routines
Copyright ( C ) Andrew Tridgell 1998
2008-10-10 19:50:09 +04:00
1998-03-15 05:37:52 +03:00
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
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
1998-03-15 05:37:52 +03:00
( at your option ) any later version .
2008-10-10 19:50:09 +04:00
1998-03-15 05:37:52 +03:00
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 .
2008-10-10 19:50:09 +04:00
1998-03-15 05:37:52 +03:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
1998-03-15 05:37:52 +03:00
*/
# include "includes.h"
2011-03-22 18:57:01 +03:00
# include "smbd/smbd.h"
2010-07-04 20:15:36 +04:00
# include "smbd/globals.h"
2011-07-07 19:42:08 +04:00
# include "dbwrap/dbwrap.h"
2011-03-24 15:46:20 +03:00
# include "auth.h"
2011-06-16 16:29:36 +04:00
# include "../lib/tsocket/tsocket.h"
2011-12-15 14:51:20 +04:00
# include "messages.h"
1998-03-15 05:37:52 +03:00
2001-05-14 10:15:46 +04:00
struct count_stat {
int curr_connections ;
2006-07-11 22:01:26 +04:00
const char * name ;
2012-08-27 17:12:36 +04:00
bool verify ;
2001-05-14 10:15:46 +04:00
} ;
/****************************************************************************
Count the entries belonging to a service in the connection db .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-08-28 17:53:28 +04:00
static int count_fn ( struct smbXsrv_tcon_global0 * tcon ,
2007-05-28 15:38:42 +04:00
void * udp )
2001-05-14 10:15:46 +04:00
{
struct count_stat * cs = ( struct count_stat * ) udp ;
2008-10-10 19:50:09 +04:00
2012-08-28 17:53:28 +04:00
if ( cs - > verify & & ! process_exists ( tcon - > server_id ) ) {
2001-05-14 10:15:46 +04:00
return 0 ;
2007-04-21 01:09:44 +04:00
}
2001-05-14 10:15:46 +04:00
2012-08-28 17:53:28 +04:00
if ( strequal ( tcon - > share_name , cs - > name ) ) {
2001-05-14 10:15:46 +04:00
cs - > curr_connections + + ;
2012-08-27 17:12:36 +04:00
}
2001-05-14 10:15:46 +04:00
return 0 ;
}
1998-03-15 05:37:52 +03:00
1999-12-21 07:54:30 +03:00
/****************************************************************************
2001-05-14 10:15:46 +04:00
Claim an entry in the connections database .
1998-03-15 05:37:52 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-05-14 10:15:46 +04:00
2012-08-27 17:12:36 +04:00
int count_current_connections ( const char * sharename , bool verify )
1998-03-15 05:37:52 +03:00
{
2006-07-11 22:01:26 +04:00
struct count_stat cs ;
2012-08-28 17:53:28 +04:00
NTSTATUS status ;
2002-09-25 19:19:00 +04:00
2006-07-11 22:01:26 +04:00
cs . curr_connections = 0 ;
cs . name = sharename ;
2012-08-27 17:12:36 +04:00
cs . verify = verify ;
2001-05-14 10:15:46 +04:00
/*
2006-07-11 22:01:26 +04:00
* This has a race condition , but locking the chain before hand is worse
* as it leads to deadlock .
2001-05-14 10:15:46 +04:00
*/
2012-08-28 17:53:28 +04:00
status = smbXsrv_tcon_global_traverse ( count_fn , & cs ) ;
2011-06-14 19:52:42 +04:00
2012-08-28 17:53:28 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-05-28 15:38:42 +04:00
DEBUG ( 0 , ( " count_current_connections: traverse of "
2012-08-28 17:53:28 +04:00
" smbXsrv_tcon_global.tdb failed - %s \n " ,
nt_errstr ( status ) ) ) ;
2011-06-14 19:50:41 +04:00
return 0 ;
2006-07-11 22:01:26 +04:00
}
2007-04-21 01:09:44 +04:00
2006-07-11 22:01:26 +04:00
return cs . curr_connections ;
}
2001-05-14 10:15:46 +04:00
2011-12-13 15:18:01 +04:00
bool connections_snum_used ( struct smbd_server_connection * unused , int snum )
{
2019-11-07 13:01:05 +03:00
const struct loadparm_substitution * lp_sub =
loadparm_s3_global_substitution ( ) ;
2011-12-13 15:18:01 +04:00
int active ;
2019-11-07 13:01:05 +03:00
active = count_current_connections ( lp_servicename ( talloc_tos ( ) , lp_sub , snum ) ,
2012-07-18 09:37:23 +04:00
true ) ;
2011-12-13 15:18:01 +04:00
if ( active > 0 ) {
return true ;
}
return false ;
}