2005-07-19 07:58:44 +04:00
/*
Unix SMB / CIFS implementation .
management calls for smb server
Copyright ( C ) Andrew Tridgell 2005
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-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2005-07-19 07:58:44 +04:00
( 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
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-07-19 07:58:44 +04:00
*/
# include "includes.h"
# include "smb_server/smb_server.h"
2020-11-20 17:27:17 +03:00
# include "samba/service_stream.h"
2005-07-19 07:58:44 +04:00
# include "lib/messaging/irpc.h"
# include "librpc/gen_ndr/ndr_irpc.h"
# include "auth/auth.h"
2010-04-27 18:05:08 +04:00
# include "lib/tsocket/tsocket.h"
2005-07-19 07:58:44 +04:00
/*
return a list of open sessions
*/
static NTSTATUS smbsrv_session_information ( struct irpc_message * msg ,
struct smbsrv_information * r )
{
2009-02-01 02:03:47 +03:00
struct smbsrv_connection * smb_conn = talloc_get_type ( msg - > private_data ,
struct smbsrv_connection ) ;
2010-04-27 18:05:08 +04:00
struct tsocket_address * client_addr = smb_conn - > connection - > remote_address ;
char * client_addr_string ;
2005-07-19 07:58:44 +04:00
int i = 0 , count = 0 ;
struct smbsrv_session * sess ;
2010-04-27 18:05:08 +04:00
/* This is for debugging only! */
client_addr_string = tsocket_address_string ( client_addr , r ) ;
NT_STATUS_HAVE_NO_MEMORY ( client_addr_string ) ;
2005-07-19 07:58:44 +04:00
/* count the number of sessions */
for ( sess = smb_conn - > sessions . list ; sess ; sess = sess - > next ) {
count + + ;
}
r - > out . info . sessions . num_sessions = count ;
r - > out . info . sessions . sessions = talloc_array ( r , struct smbsrv_session_info , count ) ;
NT_STATUS_HAVE_NO_MEMORY ( r - > out . info . sessions . sessions ) ;
for ( sess = smb_conn - > sessions . list ; sess ; sess = sess - > next ) {
struct smbsrv_session_info * info = & r - > out . info . sessions . sessions [ i ] ;
2010-04-27 18:05:08 +04:00
info - > client_ip = client_addr_string ;
2006-01-10 01:12:53 +03:00
2005-07-19 07:58:44 +04:00
info - > vuid = sess - > vuid ;
2011-02-08 08:53:13 +03:00
info - > account_name = sess - > session_info - > info - > account_name ;
info - > domain_name = sess - > session_info - > info - > domain_name ;
2006-01-10 01:12:53 +03:00
2005-11-18 15:57:48 +03:00
info - > connect_time = timeval_to_nttime ( & sess - > statistics . connect_time ) ;
info - > auth_time = timeval_to_nttime ( & sess - > statistics . auth_time ) ;
2006-03-26 15:32:27 +04:00
info - > last_use_time = timeval_to_nttime ( & sess - > statistics . last_request_time ) ;
2005-07-19 07:58:44 +04:00
i + + ;
}
return NT_STATUS_OK ;
}
2005-07-19 08:26:58 +04:00
/*
return a list of tree connects
*/
2005-11-18 15:20:16 +03:00
static NTSTATUS smbsrv_tcon_information ( struct irpc_message * msg ,
struct smbsrv_information * r )
2005-07-19 08:26:58 +04:00
{
2009-02-01 02:03:47 +03:00
struct smbsrv_connection * smb_conn = talloc_get_type ( msg - > private_data ,
struct smbsrv_connection ) ;
2010-04-27 18:05:08 +04:00
struct tsocket_address * client_addr = smb_conn - > connection - > remote_address ;
char * client_addr_string ;
2005-07-19 08:26:58 +04:00
int i = 0 , count = 0 ;
struct smbsrv_tcon * tcon ;
2010-04-27 18:05:08 +04:00
/* This is for debugging only! */
client_addr_string = tsocket_address_string ( client_addr , r ) ;
NT_STATUS_HAVE_NO_MEMORY ( client_addr_string ) ;
2005-07-19 08:26:58 +04:00
/* count the number of tcons */
2005-12-06 20:59:20 +03:00
for ( tcon = smb_conn - > smb_tcons . list ; tcon ; tcon = tcon - > next ) {
2005-07-19 08:26:58 +04:00
count + + ;
}
2005-11-18 15:20:16 +03:00
r - > out . info . tcons . num_tcons = count ;
r - > out . info . tcons . tcons = talloc_array ( r , struct smbsrv_tcon_info , count ) ;
NT_STATUS_HAVE_NO_MEMORY ( r - > out . info . tcons . tcons ) ;
2005-07-19 08:26:58 +04:00
2005-12-06 20:59:20 +03:00
for ( tcon = smb_conn - > smb_tcons . list ; tcon ; tcon = tcon - > next ) {
2005-11-18 15:20:16 +03:00
struct smbsrv_tcon_info * info = & r - > out . info . tcons . tcons [ i ] ;
2010-04-27 18:05:08 +04:00
info - > client_ip = client_addr_string ;
2006-01-10 01:12:53 +03:00
2005-07-19 08:26:58 +04:00
info - > tid = tcon - > tid ;
2006-03-15 20:28:46 +03:00
info - > share_name = tcon - > share_name ;
2005-11-18 15:38:39 +03:00
info - > connect_time = timeval_to_nttime ( & tcon - > statistics . connect_time ) ;
2006-03-26 15:32:27 +04:00
info - > last_use_time = timeval_to_nttime ( & tcon - > statistics . last_request_time ) ;
2005-07-19 08:26:58 +04:00
i + + ;
2005-11-18 15:20:16 +03:00
}
2005-07-19 08:26:58 +04:00
return NT_STATUS_OK ;
}
2005-07-19 07:58:44 +04:00
/*
serve smbserver information via irpc
*/
static NTSTATUS smbsrv_information ( struct irpc_message * msg ,
struct smbsrv_information * r )
{
switch ( r - > in . level ) {
case SMBSRV_INFO_SESSIONS :
return smbsrv_session_information ( msg , r ) ;
2005-11-18 15:20:16 +03:00
case SMBSRV_INFO_TCONS :
return smbsrv_tcon_information ( msg , r ) ;
2005-07-19 07:58:44 +04:00
}
return NT_STATUS_OK ;
}
/*
initialise irpc management calls on a connection
*/
void smbsrv_management_init ( struct smbsrv_connection * smb_conn )
{
IRPC_REGISTER ( smb_conn - > connection - > msg_ctx , irpc , SMBSRV_INFORMATION ,
smbsrv_information , smb_conn ) ;
}