2008-05-08 13:23:38 +04:00
/*
Samba Unix / Linux SMB client library
Distributed SMB / CIFS Server Management Utility
2001-12-03 07:39:23 +03:00
Copyright ( C ) 2001 Steve French ( sfrench @ us . ibm . com )
Copyright ( C ) 2001 Jim McDonough ( jmcd @ us . ibm . com )
Copyright ( C ) 2001 Andrew Tridgell ( tridge @ samba . org )
Copyright ( C ) 2001 Andrew Bartlett ( abartlet @ samba . org )
Originally written by Steve and Jim . Largely rewritten by tridge in
November 2001.
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
2001-12-03 07:39:23 +03:00
( at your option ) any later version .
2008-05-08 13:23:38 +04:00
2001-12-03 07:39:23 +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-05-08 13:23:38 +04:00
2001-12-03 07:39:23 +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/>. */
2001-12-03 07:39:23 +03:00
# include "includes.h"
2010-04-26 17:42:47 +04:00
# include "../librpc/gen_ndr/rap.h"
2010-08-03 00:54:29 +04:00
# include "../librpc/gen_ndr/svcctl.h"
2010-05-27 01:17:35 +04:00
# include "utils/net.h"
2011-05-06 13:47:43 +04:00
# include "libsmb/libsmb.h"
2020-04-13 21:04:21 +03:00
# include "clirap2.h"
2012-05-19 19:31:50 +04:00
# include "../libcli/smb/smbXcli_base.h"
2001-12-03 07:39:23 +03:00
2008-05-08 13:23:38 +04:00
/* The following messages were for error checking that is not properly
2001-12-14 05:45:13 +03:00
reported at the moment . Which should be reinstated ? */
2001-12-03 07:39:23 +03:00
# define ERRMSG_TARGET_WG_NOT_VALID "\nTarget workgroup option not valid "\
" except on net rap server command, ignored "
# define ERRMSG_INVALID_HELP_OPTION "\nInvalid help option\n"
# define ERRMSG_BOTH_SERVER_IPADDRESS "\nTarget server and IP address both "\
" specified. Do not set both at the same time. The target IP address was used \n "
2001-12-14 05:15:04 +03:00
static int errmsg_not_implemented ( void )
{
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " \n Not implemented \n " ) ) ;
2001-12-14 05:15:04 +03:00
return 0 ;
}
2001-12-03 10:42:18 +03:00
2008-05-10 01:22:12 +04:00
int net_rap_file_usage ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2008-05-13 15:52:58 +04:00
return net_file_usage ( c , argc , argv ) ;
2001-12-03 07:39:23 +03:00
}
/***************************************************************************
list info on an open file
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2015-05-07 03:00:06 +03:00
static void file_fn ( const char * pPath , const char * pUser , uint16_t perms ,
uint16_t locks , uint32_t id )
2001-12-03 07:39:23 +03:00
{
2002-07-15 14:35:28 +04:00
d_printf ( " %-7.1d %-20.20s 0x%-4.2x %-6.1d %s \n " ,
2001-12-03 07:39:23 +03:00
id , pUser , perms , locks , pPath ) ;
}
2015-05-07 03:00:06 +03:00
static void one_file_fn ( const char * pPath , const char * pUser , uint16_t perms ,
uint16_t locks , uint32_t id )
2001-12-03 07:39:23 +03:00
{
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " File ID %d \n "
" User name %s \n "
" Locks 0x%-4.2x \n "
" Path %s \n "
" Permissions 0x%x \n " ) ,
2001-12-14 05:15:04 +03:00
id , pUser , locks , pPath , perms ) ;
2001-12-03 07:39:23 +03:00
}
2008-05-10 01:22:12 +04:00
static int rap_file_close ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2008-05-21 11:05:35 +04:00
if ( argc = = 0 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
return net_rap_file_usage ( c , argc , argv ) ;
2001-12-14 05:45:13 +03:00
}
2001-12-03 07:39:23 +03:00
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
ret = cli_NetFileClose ( cli , atoi ( argv [ 0 ] ) ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
static int rap_file_info ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2008-05-21 11:05:35 +04:00
if ( argc = = 0 | | c - > display_usage )
2008-05-10 01:22:12 +04:00
return net_rap_file_usage ( c , argc , argv ) ;
2008-05-08 13:23:38 +04:00
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
ret = cli_NetFileGetInfo ( cli , atoi ( argv [ 0 ] ) , one_file_fn ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
static int rap_file_user ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2007-10-18 15:00:46 +04:00
struct cli_state * cli ;
int ret ;
2008-05-21 11:05:35 +04:00
if ( argc = = 0 | | c - > display_usage )
2008-05-10 01:22:12 +04:00
return net_rap_file_usage ( c , argc , argv ) ;
2001-12-03 07:39:23 +03:00
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2007-10-18 15:00:46 +04:00
return - 1 ;
/* list open files */
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " \n Enumerating open files on remote server: \n \n "
" \n FileId Opened by Perms Locks Path \n "
" ------ --------- ----- ----- ---- \n " ) ) ;
2007-10-18 15:00:46 +04:00
ret = cli_NetFileEnum ( cli , argv [ 0 ] , NULL , file_fn ) ;
2007-10-22 15:10:55 +04:00
if ( ret = = - 1 )
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " \n Operation not supported by server! \n \n " ) ) ;
2007-10-22 15:10:55 +04:00
2007-10-18 15:00:46 +04:00
cli_shutdown ( cli ) ;
return ret ;
2001-12-03 07:39:23 +03:00
}
2008-05-10 01:22:12 +04:00
int net_rap_file ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 11:05:35 +04:00
{
" close " ,
rap_file_close ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Close specified file on server " ) ,
N_ ( " net rap file close \n "
" Close specified file on server " )
2008-05-21 11:05:35 +04:00
} ,
{
" user " ,
rap_file_user ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " List all files opened by username " ) ,
N_ ( " net rap file user \n "
" List all files opened by username " )
2008-05-21 11:05:35 +04:00
} ,
{
" info " ,
rap_file_info ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Display info about an opened file " ) ,
N_ ( " net rap file info \n "
" Display info about an opened file " )
2008-05-21 11:05:35 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2001-12-03 07:39:23 +03:00
} ;
2008-05-08 13:23:38 +04:00
2001-12-03 07:39:23 +03:00
if ( argc = = 0 ) {
struct cli_state * cli ;
int ret ;
2008-05-08 13:23:38 +04:00
2008-05-21 11:05:35 +04:00
if ( c - > display_usage ) {
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Usage: \n " ) ) ;
d_printf ( _ ( " net rap file \n "
" List all open files on rempte "
" server \n " ) ) ;
2008-05-21 11:05:35 +04:00
net_display_usage_from_functable ( func ) ;
return 0 ;
}
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
/* list open files */
2007-10-18 15:00:46 +04:00
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " \n Enumerating open files on remote server: \n \n "
" \n FileId Opened by Perms Locks Path \n "
" ------ --------- ----- ----- ---- \n " ) ) ;
2001-12-03 07:39:23 +03:00
ret = cli_NetFileEnum ( cli , NULL , NULL , file_fn ) ;
2007-10-22 15:10:55 +04:00
if ( ret = = - 1 )
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " \n Operation not supported by server! \n \n " ) ) ;
2007-10-22 15:10:55 +04:00
2001-12-03 07:39:23 +03:00
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-08 13:23:38 +04:00
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rap file " , func ) ;
2001-12-03 07:39:23 +03:00
}
2008-05-08 13:23:38 +04:00
2008-05-10 01:22:12 +04:00
int net_rap_share_usage ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2008-05-14 16:24:21 +04:00
return net_share_usage ( c , argc , argv ) ;
2001-12-03 07:39:23 +03:00
}
2015-05-07 03:00:06 +03:00
static void long_share_fn ( const char * share_name , uint32_t type ,
2001-12-14 05:15:04 +03:00
const char * comment , void * state )
2001-12-03 07:39:23 +03:00
{
2004-02-11 17:59:08 +03:00
d_printf ( " %-12s %-8.8s %-50s \n " ,
2008-09-25 01:23:01 +04:00
share_name , net_share_type_str ( type ) , comment ) ;
2001-12-03 07:39:23 +03:00
}
2015-05-07 03:00:06 +03:00
static void share_fn ( const char * share_name , uint32_t type ,
2001-12-14 05:15:04 +03:00
const char * comment , void * state )
2001-12-03 07:39:23 +03:00
{
2004-02-11 17:59:08 +03:00
d_printf ( " %s \n " , share_name ) ;
2001-12-03 07:39:23 +03:00
}
2008-05-10 01:22:12 +04:00
static int rap_share_delete ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2008-05-08 13:23:38 +04:00
2008-05-21 11:05:35 +04:00
if ( argc = = 0 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
return net_rap_share_usage ( c , argc , argv ) ;
2001-12-03 07:39:23 +03:00
}
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
ret = cli_NetShareDelete ( cli , argv [ 0 ] ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
static int rap_share_add ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2008-05-08 13:23:38 +04:00
2010-04-26 17:42:47 +04:00
struct rap_share_info_2 sinfo ;
2001-12-03 07:39:23 +03:00
char * p ;
char * sharename ;
2008-05-21 11:05:35 +04:00
if ( argc = = 0 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
return net_rap_share_usage ( c , argc , argv ) ;
2001-12-03 07:39:23 +03:00
}
2008-05-08 13:23:38 +04:00
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
2004-12-07 21:25:53 +03:00
sharename = SMB_STRDUP ( argv [ 0 ] ) ;
2001-12-03 07:39:23 +03:00
p = strchr ( sharename , ' = ' ) ;
2006-03-12 01:21:27 +03:00
if ( p = = NULL ) {
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Server path not specified \n " ) ) ;
2008-05-28 00:56:55 +04:00
SAFE_FREE ( sharename ) ;
2008-05-10 01:22:12 +04:00
return net_rap_share_usage ( c , argc , argv ) ;
2006-03-12 01:21:27 +03:00
}
2001-12-03 07:39:23 +03:00
* p = 0 ;
2010-04-27 00:09:21 +04:00
strlcpy ( ( char * ) sinfo . share_name , sharename , sizeof ( sinfo . share_name ) ) ;
2001-12-03 07:39:23 +03:00
sinfo . reserved1 = ' \0 ' ;
sinfo . share_type = 0 ;
2010-05-05 19:17:12 +04:00
sinfo . comment = c - > opt_comment ? smb_xstrdup ( c - > opt_comment ) : " " ;
2001-12-03 07:39:23 +03:00
sinfo . perms = 0 ;
2008-05-10 01:22:12 +04:00
sinfo . maximum_users = c - > opt_maxusers ;
2001-12-03 07:39:23 +03:00
sinfo . active_users = 0 ;
sinfo . path = p + 1 ;
memset ( sinfo . password , ' \0 ' , sizeof ( sinfo . password ) ) ;
sinfo . reserved2 = ' \0 ' ;
2008-05-08 13:23:38 +04:00
2001-12-03 07:39:23 +03:00
ret = cli_NetShareAdd ( cli , & sinfo ) ;
cli_shutdown ( cli ) ;
2008-05-28 00:56:55 +04:00
SAFE_FREE ( sharename ) ;
2001-12-03 07:39:23 +03:00
return ret ;
}
2008-05-10 01:22:12 +04:00
int net_rap_share ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 11:05:35 +04:00
{
" delete " ,
rap_share_delete ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Delete a share from server " ) ,
N_ ( " net rap share delete \n "
" Delete a share from server " )
2008-05-21 11:05:35 +04:00
} ,
{
" close " ,
rap_share_delete ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Delete a share from server " ) ,
N_ ( " net rap share close \n "
" Delete a share from server \n "
" Alias for net rap share delete " )
2008-05-21 11:05:35 +04:00
} ,
{
" add " ,
rap_share_add ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Add a share to server " ) ,
N_ ( " net rap share add \n "
" Add a share to server " )
2008-05-21 11:05:35 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2001-12-03 07:39:23 +03:00
} ;
if ( argc = = 0 ) {
struct cli_state * cli ;
int ret ;
2008-05-08 13:23:38 +04:00
2008-05-21 11:05:35 +04:00
if ( c - > display_usage ) {
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Usage: \n " ) ) ;
d_printf ( _ ( " net rap share \n "
" List all shares on remote server \n " ) ) ;
2008-05-21 11:05:35 +04:00
net_display_usage_from_functable ( func ) ;
return 0 ;
}
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
2008-05-08 13:23:38 +04:00
2008-05-10 01:22:12 +04:00
if ( c - > opt_long_list_entries ) {
2009-08-02 12:25:26 +04:00
d_printf ( _ (
2008-05-21 11:05:35 +04:00
" \n Enumerating shared resources (exports) on remote server: \n \n "
" \n Share name Type Description \n "
2009-08-02 12:25:26 +04:00
" ---------- ---- ----------- \n " ) ) ;
2001-12-03 07:39:23 +03:00
ret = cli_RNetShareEnum ( cli , long_share_fn , NULL ) ;
2004-02-11 17:59:08 +03:00
} else {
ret = cli_RNetShareEnum ( cli , share_fn , NULL ) ;
2001-12-03 07:39:23 +03:00
}
cli_shutdown ( cli ) ;
return ret ;
}
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rap share " , func ) ;
2001-12-03 07:39:23 +03:00
}
2008-05-08 13:23:38 +04:00
2008-05-10 01:22:12 +04:00
int net_rap_session_usage ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2009-08-02 12:25:26 +04:00
d_printf ( _ (
2008-05-21 11:05:35 +04:00
" \n net rap session [misc. options] [targets] "
2009-08-02 12:25:26 +04:00
" \n \t enumerates all active SMB/CIFS sessions on target server \n " ) ) ;
d_printf ( _ (
2008-05-21 11:05:35 +04:00
" \n net rap session DELETE <client_name> [misc. options] [targets] \n "
" \t or "
" \n net rap session CLOSE <client_name> [misc. options] [targets] "
2009-08-02 12:25:26 +04:00
" \n \t Deletes (closes) a session from specified client to server \n " ) ) ;
d_printf ( _ (
2008-05-21 11:05:35 +04:00
" \n net rap session INFO <client_name> "
2009-08-02 12:25:26 +04:00
" \n \t Enumerates all open files in specified session \n " ) ) ;
2001-12-14 05:15:04 +03:00
2008-05-10 01:22:12 +04:00
net_common_flags_usage ( c , argc , argv ) ;
2001-12-03 07:39:23 +03:00
return - 1 ;
}
2008-05-08 13:23:38 +04:00
2015-05-07 03:00:06 +03:00
static void list_sessions_func ( char * wsname , char * username , uint16_t conns ,
uint16_t opens , uint16_t users , uint32_t sess_time ,
2015-05-14 03:26:01 +03:00
uint32_t idle_time , uint32_t user_flags , char * clitype )
2001-12-03 07:39:23 +03:00
{
int hrs = idle_time / 3600 ;
int min = ( idle_time / 60 ) % 60 ;
int sec = idle_time % 60 ;
2008-05-08 13:23:38 +04:00
2001-12-03 07:39:23 +03:00
d_printf ( " \\ \\ %-18.18s %-20.20s %-18.18s %5d %2.2d:%2.2d:%2.2d \n " ,
wsname , username , clitype , opens , hrs , min , sec ) ;
}
2008-05-08 13:23:38 +04:00
static void display_session_func ( const char * wsname , const char * username ,
2015-05-14 03:26:01 +03:00
uint16_t conns , uint16_t opens , uint16_t users ,
uint32_t sess_time , uint32_t idle_time ,
2015-05-07 03:00:06 +03:00
uint32_t user_flags , const char * clitype )
2001-12-03 07:39:23 +03:00
{
int ihrs = idle_time / 3600 ;
int imin = ( idle_time / 60 ) % 60 ;
int isec = idle_time % 60 ;
int shrs = sess_time / 3600 ;
int smin = ( sess_time / 60 ) % 60 ;
int ssec = sess_time % 60 ;
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " User name %-20.20s \n "
" Computer %-20.20s \n "
" Guest logon %-20.20s \n "
" Client Type %-40.40s \n "
" Sess time %2.2d:%2.2d:%2.2d \n "
" Idle time %2.2d:%2.2d:%2.2d \n " ) ,
2008-05-08 13:23:38 +04:00
username , wsname ,
2009-08-02 12:25:26 +04:00
( user_flags & 0x0 ) ? _ ( " yes " ) : _ ( " no " ) , clitype ,
2001-12-03 07:39:23 +03:00
shrs , smin , ssec , ihrs , imin , isec ) ;
}
2015-05-14 03:26:01 +03:00
static void display_conns_func ( uint16_t conn_id , uint16_t conn_type , uint16_t opens ,
2015-05-07 03:00:06 +03:00
uint16_t users , uint32_t conn_time ,
2001-12-14 05:15:04 +03:00
const char * username , const char * netname )
2001-12-03 07:39:23 +03:00
{
2001-12-14 05:15:04 +03:00
d_printf ( " %-14.14s %-8.8s %5d \n " ,
2008-09-25 01:23:01 +04:00
netname , net_share_type_str ( conn_type ) , opens ) ;
2001-12-03 07:39:23 +03:00
}
2008-05-10 01:22:12 +04:00
static int rap_session_info ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
const char * sessname ;
struct cli_state * cli ;
int ret ;
2008-05-08 13:23:38 +04:00
2008-05-21 11:05:35 +04:00
if ( argc = = 0 | | c - > display_usage )
return net_rap_session_usage ( c , argc , argv ) ;
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
sessname = argv [ 0 ] ;
ret = cli_NetSessionGetInfo ( cli , sessname , display_session_func ) ;
if ( ret < 0 ) {
cli_shutdown ( cli ) ;
return ret ;
}
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Share name Type # Opens \n ------------------------- "
" ----------------------------------------------------- \n " ) ) ;
2001-12-03 07:39:23 +03:00
ret = cli_NetConnectionEnum ( cli , sessname , display_conns_func ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
static int rap_session_delete ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2008-05-08 13:23:38 +04:00
2008-05-21 11:05:35 +04:00
if ( argc = = 0 | | c - > display_usage )
return net_rap_session_usage ( c , argc , argv ) ;
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
ret = cli_NetSessionDel ( cli , argv [ 0 ] ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
int net_rap_session ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 11:05:35 +04:00
{
" info " ,
rap_session_info ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Display information about session " ) ,
N_ ( " net rap session info \n "
" Display information about session " )
2008-05-21 11:05:35 +04:00
} ,
{
" delete " ,
rap_session_delete ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Close specified session " ) ,
N_ ( " net rap session delete \n "
" Close specified session \n "
" Alias for net rap session close " )
2008-05-21 11:05:35 +04:00
} ,
{
" close " ,
rap_session_delete ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Close specified session " ) ,
N_ ( " net rap session close \n "
" Close specified session " )
2008-05-21 11:05:35 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2001-12-03 07:39:23 +03:00
} ;
if ( argc = = 0 ) {
struct cli_state * cli ;
int ret ;
2008-05-08 13:23:38 +04:00
2008-05-21 11:05:35 +04:00
if ( c - > display_usage ) {
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Usage: \n " ) ) ;
d_printf ( _ ( " net rap session \n "
" List all open sessions on remote "
" server \n " ) ) ;
2008-05-21 11:05:35 +04:00
net_display_usage_from_functable ( func ) ;
return 0 ;
}
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Computer User name "
" Client Type Opens Idle time \n "
" ------------------------------------------ "
" ------------------------------------ \n " ) ) ;
2001-12-03 07:39:23 +03:00
ret = cli_NetSessionEnum ( cli , list_sessions_func ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rap session " , func ) ;
2001-12-03 07:39:23 +03:00
}
2008-05-08 13:23:38 +04:00
2001-12-03 07:39:23 +03:00
/****************************************************************************
list a server name
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2015-05-07 03:00:06 +03:00
static void display_server_func ( const char * name , uint32_t m ,
2001-12-14 05:15:04 +03:00
const char * comment , void * reserved )
2001-12-03 07:39:23 +03:00
{
d_printf ( " \t %-16.16s %s \n " , name , comment ) ;
}
2008-05-10 01:22:12 +04:00
static int net_rap_server_name ( struct net_context * c , int argc , const char * argv [ ] )
2006-10-09 11:17:37 +04:00
{
struct cli_state * cli ;
char * name ;
2008-05-21 11:05:35 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net rap server name \n "
2009-08-02 12:25:26 +04:00
" Get the name of the server \n " ) ) ;
2008-05-21 11:05:35 +04:00
return 0 ;
}
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2006-10-09 11:17:37 +04:00
return - 1 ;
if ( ! cli_get_server_name ( NULL , cli , & name ) ) {
2009-08-02 12:25:26 +04:00
d_fprintf ( stderr , _ ( " cli_get_server_name failed \n " ) ) ;
2006-10-09 11:17:37 +04:00
cli_shutdown ( cli ) ;
return - 1 ;
}
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Server name = %s \n " ) , name ) ;
2006-10-09 11:17:37 +04:00
TALLOC_FREE ( name ) ;
cli_shutdown ( cli ) ;
return 0 ;
}
2008-05-08 13:23:38 +04:00
2008-05-21 11:05:35 +04:00
static int net_rap_server_domain ( struct net_context * c , int argc ,
const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2006-10-09 11:17:37 +04:00
2008-05-21 11:05:35 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net rap server domain \n "
2009-08-02 12:25:26 +04:00
" Enumerate servers in this domain/workgroup \n " ) ) ;
2008-05-21 11:05:35 +04:00
return 0 ;
2006-10-09 11:17:37 +04:00
}
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " \n Enumerating servers in this domain or workgroup: \n \n "
" \t Server name Server description \n "
" \t ------------- ---------------------------- \n " ) ) ;
2001-12-14 05:15:04 +03:00
2008-05-08 13:23:38 +04:00
ret = cli_NetServerEnum ( cli , cli - > server_domain , SV_TYPE_ALL ,
display_server_func , NULL ) ;
2001-12-03 07:39:23 +03:00
cli_shutdown ( cli ) ;
2008-05-08 13:23:38 +04:00
return ret ;
2001-12-03 07:39:23 +03:00
}
2008-05-08 13:23:38 +04:00
2008-05-21 11:05:35 +04:00
int net_rap_server ( struct net_context * c , int argc , const char * * argv )
{
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 11:05:35 +04:00
{
" name " ,
net_rap_server_name ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Get the name of the server " ) ,
N_ ( " net rap server name \n "
" Get the name of the server " )
2008-05-21 11:05:35 +04:00
} ,
{
" domain " ,
net_rap_server_domain ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Get the servers in this domain/workgroup " ) ,
N_ ( " net rap server domain \n "
" Get the servers in this domain/workgroup " )
2008-05-21 11:05:35 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
} ;
/* smb4k uses 'net [rap|rpc] server domain' to query servers in a domain */
/* Fall through for 'domain', any other forms will cause to show usage message */
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rap server " , func ) ;
2008-05-21 11:05:35 +04:00
}
2008-05-10 01:22:12 +04:00
int net_rap_domain_usage ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " net rap domain [misc. options] [target] \n \t lists the "
" domains or workgroups visible on the current network \n " ) ) ;
2001-12-14 05:15:04 +03:00
2008-05-10 01:22:12 +04:00
net_common_flags_usage ( c , argc , argv ) ;
2001-12-03 07:39:23 +03:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
int net_rap_domain ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2008-05-08 13:23:38 +04:00
2008-05-21 11:05:35 +04:00
if ( c - > display_usage )
return net_rap_domain_usage ( c , argc , argv ) ;
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " \n Enumerating domains: \n \n "
" \t Domain name Server name of Browse Master \n "
" \t ------------- ---------------------------- \n " ) ) ;
2001-12-14 05:15:04 +03:00
ret = cli_NetServerEnum ( cli , cli - > server_domain , SV_TYPE_DOMAIN_ENUM ,
2008-05-08 13:23:38 +04:00
display_server_func , NULL ) ;
2001-12-03 07:39:23 +03:00
cli_shutdown ( cli ) ;
2008-05-08 13:23:38 +04:00
return ret ;
2001-12-03 07:39:23 +03:00
}
2008-05-08 13:23:38 +04:00
2008-05-10 01:22:12 +04:00
int net_rap_printq_usage ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2009-08-02 12:25:26 +04:00
d_printf ( _ (
2008-05-21 11:05:35 +04:00
" net rap printq [misc. options] [targets] \n "
" \t or \n "
2008-11-17 10:37:21 +03:00
" net rap printq info [<queue_name>] [misc. options] [targets] \n "
2008-05-21 11:05:35 +04:00
" \t lists the specified queue and jobs on the target server. \n "
2009-08-02 12:25:26 +04:00
" \t If the queue name is not specified, all queues are listed. \n \n " ) ) ;
d_printf ( _ (
2008-05-21 11:05:35 +04:00
" net rap printq delete [<queue name>] [misc. options] [targets] \n "
" \t deletes the specified job number on the target server, or the \n "
2009-08-02 12:25:26 +04:00
" \t printer queue if no job number is specified \n " ) ) ;
2001-12-14 05:15:04 +03:00
2008-05-10 01:22:12 +04:00
net_common_flags_usage ( c , argc , argv ) ;
2001-12-14 05:15:04 +03:00
2001-12-03 07:39:23 +03:00
return - 1 ;
2008-05-08 13:23:38 +04:00
}
2001-12-03 07:39:23 +03:00
2015-05-07 03:00:06 +03:00
static void enum_queue ( const char * queuename , uint16_t pri , uint16_t start ,
uint16_t until , const char * sep , const char * pproc ,
2008-05-08 13:23:38 +04:00
const char * dest , const char * qparms ,
2015-05-07 03:00:06 +03:00
const char * qcomment , uint16_t status , uint16_t jobcount )
2001-12-14 05:15:04 +03:00
{
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " %-17.17s Queue %5d jobs " ) ,
2001-12-14 05:15:04 +03:00
queuename , jobcount ) ;
2001-12-03 07:39:23 +03:00
switch ( status ) {
case 0 :
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " *Printer Active* \n " ) ) ;
2001-12-03 07:39:23 +03:00
break ;
case 1 :
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " *Printer Paused* \n " ) ) ;
2001-12-03 07:39:23 +03:00
break ;
case 2 :
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " *Printer error* \n " ) ) ;
2001-12-03 07:39:23 +03:00
break ;
case 3 :
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " *Delete Pending* \n " ) ) ;
2001-12-03 07:39:23 +03:00
break ;
default :
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " **UNKNOWN STATUS** \n " ) ) ;
2001-12-03 07:39:23 +03:00
}
}
2015-05-07 03:00:06 +03:00
static void enum_jobs ( uint16_t jobid , const char * ownername ,
2001-12-14 05:15:04 +03:00
const char * notifyname , const char * datatype ,
2015-05-07 03:00:06 +03:00
const char * jparms , uint16_t pos , uint16_t status ,
2008-05-08 13:23:38 +04:00
const char * jstatus , unsigned int submitted , unsigned int jobsize ,
2001-12-14 05:15:04 +03:00
const char * comment )
{
d_printf ( " %-23.23s %5d %9d " ,
ownername , jobid , jobsize ) ;
2001-12-03 07:39:23 +03:00
switch ( status ) {
case 0 :
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Waiting \n " ) ) ;
2001-12-03 07:39:23 +03:00
break ;
case 1 :
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Held in queue \n " ) ) ;
2001-12-03 07:39:23 +03:00
break ;
case 2 :
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Spooling \n " ) ) ;
2001-12-03 07:39:23 +03:00
break ;
case 3 :
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Printing \n " ) ) ;
2001-12-03 07:39:23 +03:00
break ;
default :
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " **UNKNOWN STATUS** \n " ) ) ;
2001-12-03 07:39:23 +03:00
}
}
2001-12-14 05:15:04 +03:00
# define PRINTQ_ENUM_DISPLAY \
2009-08-02 12:25:26 +04:00
_ ( " Print queues at \\ \\ %s \n \n " \
" Name Job # Size Status \n \n " \
" ------------------------------------------------------------------ " \
" ------------- \n " )
2001-12-14 05:15:04 +03:00
2008-05-10 01:22:12 +04:00
static int rap_printq_info ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2008-05-08 13:23:38 +04:00
2008-08-07 20:18:10 +04:00
if ( argc = = 0 | | c - > display_usage )
2008-05-10 01:22:12 +04:00
return net_rap_printq_usage ( c , argc , argv ) ;
2001-12-03 07:39:23 +03:00
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
2012-05-19 19:31:50 +04:00
d_printf ( PRINTQ_ENUM_DISPLAY , smbXcli_conn_remote_name ( cli - > conn ) ) ; /* list header */
2001-12-03 07:39:23 +03:00
ret = cli_NetPrintQGetInfo ( cli , argv [ 0 ] , enum_queue , enum_jobs ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
static int rap_printq_delete ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2008-05-08 13:23:38 +04:00
2008-05-21 11:05:35 +04:00
if ( argc = = 0 | | c - > display_usage )
2008-05-10 01:22:12 +04:00
return net_rap_printq_usage ( c , argc , argv ) ;
2001-12-03 07:39:23 +03:00
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
ret = cli_printjob_del ( cli , atoi ( argv [ 0 ] ) ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
int net_rap_printq ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2008-05-08 13:23:38 +04:00
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 11:05:35 +04:00
{
" info " ,
rap_printq_info ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Display info about print queues and jobs " ) ,
N_ ( " net rap printq info [queue] \n "
" Display info about print jobs in queue. \n "
" If queue is not specified, all queues are "
" listed " )
2008-05-21 11:05:35 +04:00
} ,
{
" delete " ,
rap_printq_delete ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Delete print job(s) " ) ,
N_ ( " net rap printq delete \n "
" Delete print job(s) " )
2008-05-21 11:05:35 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2001-12-03 07:39:23 +03:00
} ;
if ( argc = = 0 ) {
2008-05-21 11:05:35 +04:00
if ( c - > display_usage ) {
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Usage: \n " ) ) ;
d_printf ( _ ( " net rap printq \n "
" List the print queue \n " ) ) ;
2008-05-21 11:05:35 +04:00
net_display_usage_from_functable ( func ) ;
return 0 ;
}
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
2012-05-19 19:31:50 +04:00
d_printf ( PRINTQ_ENUM_DISPLAY , smbXcli_conn_remote_name ( cli - > conn ) ) ; /* list header */
2001-12-03 07:39:23 +03:00
ret = cli_NetPrintQEnum ( cli , enum_queue , enum_jobs ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rap printq " , func ) ;
2001-12-03 07:39:23 +03:00
}
2008-05-10 01:22:12 +04:00
static int net_rap_user_usage ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2008-05-13 14:51:09 +04:00
return net_user_usage ( c , argc , argv ) ;
2008-05-08 13:23:38 +04:00
}
2005-04-10 18:44:56 +04:00
static void user_fn ( const char * user_name , void * state )
2001-12-03 07:39:23 +03:00
{
d_printf ( " %-21.21s \n " , user_name ) ;
}
2001-12-14 05:15:04 +03:00
static void long_user_fn ( const char * user_name , const char * comment ,
2008-05-08 13:23:38 +04:00
const char * home_dir , const char * logon_script ,
2001-12-14 05:15:04 +03:00
void * state )
2001-12-03 07:39:23 +03:00
{
2003-05-09 16:58:28 +04:00
d_printf ( " %-21.21s %s \n " ,
2002-03-30 00:09:44 +03:00
user_name , comment ) ;
2001-12-03 07:39:23 +03:00
}
static void group_member_fn ( const char * user_name , void * state )
{
d_printf ( " %-21.21s \n " , user_name ) ;
}
2008-05-10 01:22:12 +04:00
static int rap_user_delete ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2008-05-08 13:23:38 +04:00
2008-05-21 11:05:35 +04:00
if ( argc = = 0 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
return net_rap_user_usage ( c , argc , argv ) ;
2001-12-14 05:45:13 +03:00
}
2001-12-03 07:39:23 +03:00
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
ret = cli_NetUserDelete ( cli , argv [ 0 ] ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
static int rap_user_add ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2010-04-26 17:42:47 +04:00
struct rap_user_info_1 userinfo ;
2001-12-03 07:39:23 +03:00
2008-05-21 11:05:35 +04:00
if ( argc = = 0 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
return net_rap_user_usage ( c , argc , argv ) ;
2001-12-14 05:45:13 +03:00
}
2001-12-03 07:39:23 +03:00
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
2008-05-08 13:23:38 +04:00
2011-05-04 00:10:01 +04:00
strlcpy ( ( char * ) userinfo . user_name , argv [ 0 ] , sizeof ( userinfo . user_name ) ) ;
2011-03-18 01:51:12 +03:00
if ( c - > opt_flags = = 0 )
2008-05-10 01:22:12 +04:00
c - > opt_flags = 0x21 ;
2008-05-08 13:23:38 +04:00
2008-05-10 01:22:12 +04:00
userinfo . userflags = c - > opt_flags ;
2001-12-03 07:39:23 +03:00
userinfo . reserved1 = ' \0 ' ;
2009-06-08 11:45:21 +04:00
userinfo . comment = smb_xstrdup ( c - > opt_comment ? c - > opt_comment : " " ) ;
2008-05-08 13:23:38 +04:00
userinfo . priv = 1 ;
2001-12-03 07:39:23 +03:00
userinfo . home_dir = NULL ;
userinfo . logon_script = NULL ;
2009-06-08 11:46:52 +04:00
userinfo . passwrd [ 0 ] = ' \0 ' ;
2002-07-15 14:35:28 +04:00
2001-12-03 07:39:23 +03:00
ret = cli_NetUserAdd ( cli , & userinfo ) ;
2002-07-15 14:35:28 +04:00
2001-12-03 07:39:23 +03:00
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
static int rap_user_info ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2008-05-21 11:05:35 +04:00
if ( argc = = 0 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
return net_rap_user_usage ( c , argc , argv ) ;
2001-12-14 05:45:13 +03:00
}
2001-12-03 07:39:23 +03:00
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
ret = cli_NetUserGetGroups ( cli , argv [ 0 ] , group_member_fn , NULL ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
int net_rap_user ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2002-04-04 20:48:23 +04:00
int ret = - 1 ;
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 11:05:35 +04:00
{
" add " ,
rap_user_add ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Add specified user " ) ,
N_ ( " net rap user add \n "
" Add specified user " )
2008-05-21 11:05:35 +04:00
} ,
{
" info " ,
rap_user_info ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " List domain groups of specified user " ) ,
N_ ( " net rap user info \n "
" List domain groups of specified user " )
2008-05-21 11:05:35 +04:00
} ,
{
" delete " ,
rap_user_delete ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Remove specified user " ) ,
N_ ( " net rap user delete \n "
" Remove specified user " )
2008-05-21 11:05:35 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2001-12-03 07:39:23 +03:00
} ;
if ( argc = = 0 ) {
struct cli_state * cli ;
2008-05-21 11:05:35 +04:00
if ( c - > display_usage ) {
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Usage: \n " ) ) ;
d_printf ( _ ( " net rap user \n "
" List all users \n " ) ) ;
2008-05-21 11:05:35 +04:00
net_display_usage_from_functable ( func ) ;
return 0 ;
}
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2002-04-04 20:48:23 +04:00
goto done ;
2008-05-10 01:22:12 +04:00
if ( c - > opt_long_list_entries ) {
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " \n User name Comment "
" \n ----------------------------- \n " ) ) ;
2001-12-03 07:39:23 +03:00
ret = cli_RNetUserEnum ( cli , long_user_fn , NULL ) ;
cli_shutdown ( cli ) ;
2002-04-04 20:48:23 +04:00
goto done ;
2001-12-03 07:39:23 +03:00
}
2008-05-08 13:23:38 +04:00
ret = cli_RNetUserEnum0 ( cli , user_fn , NULL ) ;
2001-12-03 07:39:23 +03:00
cli_shutdown ( cli ) ;
2002-04-04 20:48:23 +04:00
goto done ;
2001-12-03 07:39:23 +03:00
}
2008-06-07 04:25:08 +04:00
ret = net_run_function ( c , argc , argv , " net rap user " , func ) ;
2002-04-04 20:48:23 +04:00
done :
if ( ret ! = 0 ) {
2009-08-02 12:25:26 +04:00
DEBUG ( 1 , ( _ ( " Net user returned: %d \n " ) , ret ) ) ;
2002-04-04 20:48:23 +04:00
}
return ret ;
2001-12-03 07:39:23 +03:00
}
2008-05-10 01:22:12 +04:00
int net_rap_group_usage ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2008-05-13 15:44:28 +04:00
return net_group_usage ( c , argc , argv ) ;
2001-12-03 07:39:23 +03:00
}
2001-12-14 05:15:04 +03:00
static void long_group_fn ( const char * group_name , const char * comment ,
void * state )
2001-12-03 07:39:23 +03:00
{
2003-05-09 16:58:28 +04:00
d_printf ( " %-21.21s %s \n " , group_name , comment ) ;
2001-12-03 07:39:23 +03:00
}
2005-04-10 18:44:56 +04:00
static void group_fn ( const char * group_name , void * state )
2001-12-03 07:39:23 +03:00
{
d_printf ( " %-21.21s \n " , group_name ) ;
}
2008-05-10 01:22:12 +04:00
static int rap_group_delete ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2008-05-21 11:05:35 +04:00
if ( argc = = 0 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
return net_rap_group_usage ( c , argc , argv ) ;
2001-12-14 05:45:13 +03:00
}
2001-12-03 07:39:23 +03:00
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
ret = cli_NetGroupDelete ( cli , argv [ 0 ] ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
static int rap_group_add ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2010-04-26 17:42:47 +04:00
struct rap_group_info_1 grinfo ;
2001-12-03 07:39:23 +03:00
2008-05-21 11:05:35 +04:00
if ( argc = = 0 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
return net_rap_group_usage ( c , argc , argv ) ;
2001-12-14 05:45:13 +03:00
}
2001-12-03 07:39:23 +03:00
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
2008-05-08 13:23:38 +04:00
2001-12-03 07:39:23 +03:00
/* BB check for length 21 or smaller explicitly ? BB */
2011-05-04 00:10:01 +04:00
strlcpy ( ( char * ) grinfo . group_name , argv [ 0 ] , sizeof ( grinfo . group_name ) ) ;
2001-12-03 07:39:23 +03:00
grinfo . reserved1 = ' \0 ' ;
2009-06-08 12:05:11 +04:00
grinfo . comment = smb_xstrdup ( c - > opt_comment ? c - > opt_comment : " " ) ;
2008-05-08 13:23:38 +04:00
2001-12-03 07:39:23 +03:00
ret = cli_NetGroupAdd ( cli , & grinfo ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
int net_rap_group ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 11:05:35 +04:00
{
" add " ,
rap_group_add ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Add specified group " ) ,
N_ ( " net rap group add \n "
" Add specified group " )
2008-05-21 11:05:35 +04:00
} ,
{
" delete " ,
rap_group_delete ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Delete specified group " ) ,
N_ ( " net rap group delete \n "
" Delete specified group " )
2008-05-21 11:05:35 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2001-12-03 07:39:23 +03:00
} ;
if ( argc = = 0 ) {
struct cli_state * cli ;
int ret ;
2008-05-21 11:05:35 +04:00
if ( c - > display_usage ) {
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Usage: \n " ) ) ;
d_printf ( _ ( " net rap group \n "
" List all groups \n " ) ) ;
2008-05-21 11:05:35 +04:00
net_display_usage_from_functable ( func ) ;
return 0 ;
}
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
2008-05-10 01:22:12 +04:00
if ( c - > opt_long_list_entries ) {
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Group name Comment \n "
" ----------------------------- \n " ) ) ;
2001-12-03 07:39:23 +03:00
ret = cli_RNetGroupEnum ( cli , long_group_fn , NULL ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-08 13:23:38 +04:00
ret = cli_RNetGroupEnum0 ( cli , group_fn , NULL ) ;
2001-12-03 07:39:23 +03:00
cli_shutdown ( cli ) ;
return ret ;
}
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rap group " , func ) ;
2001-12-03 07:39:23 +03:00
}
2008-05-10 01:22:12 +04:00
int net_rap_groupmember_usage ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2009-08-02 12:25:26 +04:00
d_printf ( _ (
2008-05-21 11:05:35 +04:00
" net rap groupmember LIST <group> [misc. options] [targets] "
" \n \t Enumerate users in a group \n "
" \n net rap groupmember DELETE <group> <user> [misc. options] "
2008-11-04 22:31:04 +03:00
" [targets] \n \t Delete specified user from specified group \n "
2008-05-21 11:05:35 +04:00
" \n net rap groupmember ADD <group> <user> [misc. options] [targets] "
2009-08-02 12:25:26 +04:00
" \n \t Add specified user to specified group \n " ) ) ;
2001-12-14 05:15:04 +03:00
2008-05-10 01:22:12 +04:00
net_common_flags_usage ( c , argc , argv ) ;
2001-12-03 07:39:23 +03:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
static int rap_groupmember_add ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2008-05-21 11:05:35 +04:00
if ( argc ! = 2 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
return net_rap_groupmember_usage ( c , argc , argv ) ;
2001-12-14 05:45:13 +03:00
}
2001-12-03 07:39:23 +03:00
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
ret = cli_NetGroupAddUser ( cli , argv [ 0 ] , argv [ 1 ] ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
static int rap_groupmember_delete ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2008-05-21 11:05:35 +04:00
if ( argc ! = 2 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
return net_rap_groupmember_usage ( c , argc , argv ) ;
2001-12-14 05:45:13 +03:00
}
2008-05-08 13:23:38 +04:00
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
ret = cli_NetGroupDelUser ( cli , argv [ 0 ] , argv [ 1 ] ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
static int rap_groupmember_list ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2008-05-21 11:05:35 +04:00
if ( argc = = 0 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
return net_rap_groupmember_usage ( c , argc , argv ) ;
2001-12-14 05:45:13 +03:00
}
2001-12-03 07:39:23 +03:00
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
2008-05-08 13:23:38 +04:00
ret = cli_NetGroupGetUsers ( cli , argv [ 0 ] , group_member_fn , NULL ) ;
2001-12-03 07:39:23 +03:00
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
int net_rap_groupmember ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 11:05:35 +04:00
{
" add " ,
rap_groupmember_add ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Add specified user to group " ) ,
N_ ( " net rap groupmember add \n "
" Add specified user to group " )
2008-05-21 11:05:35 +04:00
} ,
{
" list " ,
rap_groupmember_list ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " List users in group " ) ,
N_ ( " net rap groupmember list \n "
" List users in group " )
2008-05-21 11:05:35 +04:00
} ,
{
" delete " ,
rap_groupmember_delete ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Remove user from group " ) ,
N_ ( " net rap groupmember delete \n "
" Remove user from group " )
2008-05-21 11:05:35 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2001-12-03 07:39:23 +03:00
} ;
2008-05-08 13:23:38 +04:00
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rap groupmember " , func ) ;
2001-12-03 07:39:23 +03:00
}
2008-05-10 01:22:12 +04:00
int net_rap_validate_usage ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " net rap validate <username> [password] \n "
" \t Validate user and password to check whether they "
" can access target server or domain \n " ) ) ;
2001-12-14 05:15:04 +03:00
2008-05-10 01:22:12 +04:00
net_common_flags_usage ( c , argc , argv ) ;
2001-12-03 07:39:23 +03:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
int net_rap_validate ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2001-12-14 05:15:04 +03:00
return errmsg_not_implemented ( ) ;
2001-12-03 07:39:23 +03:00
}
2008-05-10 01:22:12 +04:00
int net_rap_service_usage ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " net rap service [misc. options] [targets] \n "
" \t lists all running service daemons on target server \n " ) ) ;
d_printf ( _ ( " \n net rap service START <name> [service startup arguments] "
2008-05-21 11:05:35 +04:00
" [misc. options] [targets] "
2009-08-02 12:25:26 +04:00
" \n \t Start named service on remote server \n " ) ) ;
d_printf ( _ ( " \n net rap service STOP <name> [misc. options] [targets] \n "
" \n \t Stop named service on remote server \n " ) ) ;
2008-05-08 13:23:38 +04:00
2008-05-10 01:22:12 +04:00
net_common_flags_usage ( c , argc , argv ) ;
2001-12-03 07:39:23 +03:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
static int rap_service_start ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2001-12-14 05:15:04 +03:00
return errmsg_not_implemented ( ) ;
2001-12-03 07:39:23 +03:00
}
2008-05-10 01:22:12 +04:00
static int rap_service_stop ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2001-12-14 05:15:04 +03:00
return errmsg_not_implemented ( ) ;
2001-12-03 07:39:23 +03:00
}
2005-04-10 18:44:56 +04:00
static void service_fn ( const char * service_name , const char * dummy ,
void * state )
{
d_printf ( " %-21.21s \n " , service_name ) ;
}
2008-05-10 01:22:12 +04:00
int net_rap_service ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 11:05:35 +04:00
{
" start " ,
rap_service_start ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Start service on remote server " ) ,
N_ ( " net rap service start \n "
" Start service on remote server " )
2008-05-21 11:05:35 +04:00
} ,
{
" stop " ,
rap_service_stop ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Stop named serve on remote server " ) ,
N_ ( " net rap service stop \n "
" Stop named serve on remote server " )
2008-05-21 11:05:35 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2001-12-03 07:39:23 +03:00
} ;
if ( argc = = 0 ) {
struct cli_state * cli ;
int ret ;
2008-05-21 11:05:35 +04:00
if ( c - > display_usage ) {
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Usage: \n " ) ) ;
d_printf ( _ ( " net rap service \n "
" List services on remote server \n " ) ) ;
2008-05-21 11:05:35 +04:00
net_display_usage_from_functable ( func ) ;
return 0 ;
}
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
2008-05-10 01:22:12 +04:00
if ( c - > opt_long_list_entries ) {
2009-08-02 12:25:26 +04:00
d_printf ( _ ( " Service name Comment \n "
" ----------------------------- \n " ) ) ;
2001-12-03 07:39:23 +03:00
ret = cli_RNetServiceEnum ( cli , long_group_fn , NULL ) ;
}
2008-05-08 13:23:38 +04:00
ret = cli_RNetServiceEnum ( cli , service_fn , NULL ) ;
2001-12-03 07:39:23 +03:00
cli_shutdown ( cli ) ;
return ret ;
}
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rap service " , func ) ;
2001-12-03 07:39:23 +03:00
}
2008-05-10 01:22:12 +04:00
int net_rap_password_usage ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2009-08-02 12:25:26 +04:00
d_printf ( _ (
2008-05-21 11:05:35 +04:00
" net rap password <user> <oldpwo> <newpw> [misc. options] [target] \n "
2009-08-02 12:25:26 +04:00
" \t changes the password for the specified user at target \n " ) ) ;
2008-05-08 13:23:38 +04:00
2001-12-03 07:39:23 +03:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
int net_rap_password ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
struct cli_state * cli ;
int ret ;
2008-05-08 13:23:38 +04:00
2008-05-21 11:05:35 +04:00
if ( argc < 3 | | c - > display_usage )
2008-05-10 01:22:12 +04:00
return net_rap_password_usage ( c , argc , argv ) ;
2001-12-03 07:39:23 +03:00
2008-05-10 01:22:12 +04:00
if ( ! NT_STATUS_IS_OK ( net_make_ipc_connection ( c , 0 , & cli ) ) )
2001-12-03 07:39:23 +03:00
return - 1 ;
/* BB Add check for password lengths? */
ret = cli_oem_change_password ( cli , argv [ 0 ] , argv [ 2 ] , argv [ 1 ] ) ;
cli_shutdown ( cli ) ;
return ret ;
}
2008-05-10 01:22:12 +04:00
int net_rap_admin_usage ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2009-08-02 12:25:26 +04:00
d_printf ( _ (
2008-05-21 11:05:35 +04:00
" net rap admin <remote command> [cmd args [env]] [misc. options] [targets] "
2009-08-02 12:25:26 +04:00
" \n \t executes a remote command on an os/2 target server \n " ) ) ;
2008-05-08 13:23:38 +04:00
2001-12-03 07:39:23 +03:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
int net_rap_admin ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2001-12-14 05:15:04 +03:00
return errmsg_not_implemented ( ) ;
2001-12-03 07:39:23 +03:00
}
/* Entry-point for all the RAP functions. */
2008-05-10 01:22:12 +04:00
int net_rap ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 11:05:35 +04:00
{
" file " ,
net_rap_file ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " List open files " ) ,
N_ ( " net rap file \n "
" List open files " )
2008-05-21 11:05:35 +04:00
} ,
{
" share " ,
net_rap_share ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " List shares exported by server " ) ,
N_ ( " net rap share \n "
" List shares exported by server " )
2008-05-21 11:05:35 +04:00
} ,
{
" session " ,
net_rap_session ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " List open sessions " ) ,
N_ ( " net rap session \n "
" List open sessions " )
2008-05-21 11:05:35 +04:00
} ,
{
" server " ,
net_rap_server ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " List servers in workgroup " ) ,
N_ ( " net rap server \n "
" List servers in domain/workgroup " )
2008-05-21 11:05:35 +04:00
} ,
{
" domain " ,
net_rap_domain ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " List domains in network " ) ,
N_ ( " net rap domain \n "
" List domains in network " )
2008-05-21 11:05:35 +04:00
} ,
{
" printq " ,
net_rap_printq ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " List printer queues on server " ) ,
N_ ( " net rap printq \n "
" List printer queues on server " )
2008-05-21 11:05:35 +04:00
} ,
{
" user " ,
net_rap_user ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " List users " ) ,
N_ ( " net rap user \n "
" List users " )
2008-05-21 11:05:35 +04:00
} ,
{
" group " ,
net_rap_group ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " List user groups " ) ,
N_ ( " net rap group \n "
" List user groups " )
2008-05-21 11:05:35 +04:00
} ,
{
" validate " ,
net_rap_validate ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Check username/password " ) ,
N_ ( " net rap validate \n "
" Check username/password " )
2008-05-21 11:05:35 +04:00
} ,
{
" groupmember " ,
net_rap_groupmember ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " List/modify group memberships " ) ,
N_ ( " net rap groupmember \n "
" List/modify group memberships " )
2008-05-21 11:05:35 +04:00
} ,
{
" admin " ,
net_rap_admin ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Execute commands on remote OS/2 " ) ,
N_ ( " net rap admin \n "
" Execute commands on remote OS/2 " )
2008-05-21 11:05:35 +04:00
} ,
{
" service " ,
net_rap_service ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Start/stop remote service " ) ,
N_ ( " net rap service \n "
" Start/stop remote service " )
2008-05-21 11:05:35 +04:00
} ,
{
" password " ,
net_rap_password ,
NET_TRANSPORT_RAP ,
2009-08-02 12:25:26 +04:00
N_ ( " Change user password " ) ,
N_ ( " net rap password \n "
" Change user password " )
2008-05-21 11:05:35 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2001-12-03 07:39:23 +03:00
} ;
2008-05-08 13:23:38 +04:00
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rap " , func ) ;
2001-12-03 07:39:23 +03:00
}