1998-09-26 01:01:52 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2001-05-24 04:20:32 +04:00
RPC pipe client
2001-05-24 12:10:50 +04:00
Copyright ( C ) Andrew Tridgell 1992 - 1999
Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1999
2002-07-15 14:35:28 +04:00
Copyright ( C ) Tim Potter 2000 , 2002
2001-05-24 04:20:32 +04:00
1998-09-26 01:01:52 +04: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-09-26 01:01:52 +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 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
1998-09-26 01:01:52 +04:00
*/
# include "includes.h"
2001-10-12 09:56:23 +04:00
# include "rpcclient.h"
1998-09-26 01:01:52 +04:00
2001-05-24 12:10:50 +04:00
/* Display server query info */
static char * get_server_type_str ( uint32 type )
{
static fstring typestr ;
int i ;
if ( type = = SV_TYPE_ALL ) {
fstrcpy ( typestr , " All " ) ;
return typestr ;
}
typestr [ 0 ] = 0 ;
for ( i = 0 ; i < 32 ; i + + ) {
if ( type & ( 1 < < i ) ) {
switch ( 1 < < i ) {
case SV_TYPE_WORKSTATION :
fstrcat ( typestr , " Wk " ) ;
break ;
case SV_TYPE_SERVER :
fstrcat ( typestr , " Sv " ) ;
break ;
case SV_TYPE_SQLSERVER :
fstrcat ( typestr , " Sql " ) ;
break ;
case SV_TYPE_DOMAIN_CTRL :
fstrcat ( typestr , " PDC " ) ;
break ;
case SV_TYPE_DOMAIN_BAKCTRL :
fstrcat ( typestr , " BDC " ) ;
break ;
case SV_TYPE_TIME_SOURCE :
fstrcat ( typestr , " Tim " ) ;
break ;
case SV_TYPE_AFP :
fstrcat ( typestr , " AFP " ) ;
break ;
case SV_TYPE_NOVELL :
fstrcat ( typestr , " Nov " ) ;
break ;
case SV_TYPE_DOMAIN_MEMBER :
fstrcat ( typestr , " Dom " ) ;
break ;
case SV_TYPE_PRINTQ_SERVER :
fstrcat ( typestr , " PrQ " ) ;
break ;
case SV_TYPE_DIALIN_SERVER :
fstrcat ( typestr , " Din " ) ;
break ;
case SV_TYPE_SERVER_UNIX :
fstrcat ( typestr , " Unx " ) ;
break ;
case SV_TYPE_NT :
fstrcat ( typestr , " NT " ) ;
break ;
case SV_TYPE_WFW :
fstrcat ( typestr , " Wfw " ) ;
break ;
case SV_TYPE_SERVER_MFPN :
fstrcat ( typestr , " Mfp " ) ;
break ;
case SV_TYPE_SERVER_NT :
fstrcat ( typestr , " SNT " ) ;
break ;
case SV_TYPE_POTENTIAL_BROWSER :
fstrcat ( typestr , " PtB " ) ;
break ;
case SV_TYPE_BACKUP_BROWSER :
fstrcat ( typestr , " BMB " ) ;
break ;
case SV_TYPE_MASTER_BROWSER :
fstrcat ( typestr , " LMB " ) ;
break ;
case SV_TYPE_DOMAIN_MASTER :
fstrcat ( typestr , " DMB " ) ;
break ;
case SV_TYPE_SERVER_OSF :
fstrcat ( typestr , " OSF " ) ;
break ;
case SV_TYPE_SERVER_VMS :
fstrcat ( typestr , " VMS " ) ;
break ;
case SV_TYPE_WIN95_PLUS :
fstrcat ( typestr , " W95 " ) ;
break ;
case SV_TYPE_ALTERNATE_XPORT :
fstrcat ( typestr , " Xpt " ) ;
break ;
case SV_TYPE_LOCAL_LIST_ONLY :
fstrcat ( typestr , " Dom " ) ;
break ;
case SV_TYPE_DOMAIN_ENUM :
fstrcat ( typestr , " Loc " ) ;
break ;
}
}
}
i = strlen ( typestr ) - 1 ;
if ( typestr [ i ] = = ' ' )
typestr [ i ] = 0 ;
return typestr ;
}
2007-10-11 00:34:30 +04:00
static void display_server ( char * sname , uint32 type , const char * comment )
2001-05-24 12:10:50 +04:00
{
printf ( " \t %-15.15s%-20s %s \n " , sname , get_server_type_str ( type ) ,
comment ) ;
}
2007-10-11 00:34:30 +04:00
static void display_srv_info_101 ( SRV_INFO_101 * sv101 )
2001-05-24 12:10:50 +04:00
{
2007-10-11 00:34:30 +04:00
fstring name ;
fstring comment ;
unistr2_to_ascii ( name , & sv101 - > uni_name , sizeof ( name ) ) ;
unistr2_to_ascii ( comment , & sv101 - > uni_comment , sizeof ( comment ) ) ;
display_server ( name , sv101 - > srv_type , comment ) ;
2001-05-24 12:10:50 +04:00
printf ( " \t platform_id : \t %d \n " , sv101 - > platform_id ) ;
2007-10-11 00:34:30 +04:00
printf ( " \t os version : \t %d.%d \n " , sv101 - > ver_major ,
sv101 - > ver_minor ) ;
2001-05-24 12:10:50 +04:00
2007-10-11 00:34:30 +04:00
printf ( " \t server type : \t 0x%x \n " , sv101 - > srv_type ) ;
2001-05-24 12:10:50 +04:00
}
2007-10-11 00:34:30 +04:00
static void display_srv_info_102 ( SRV_INFO_102 * sv102 )
2001-05-24 12:10:50 +04:00
{
2007-10-11 00:34:30 +04:00
fstring name ;
fstring comment ;
fstring usr_path ;
unistr2_to_ascii ( name , & sv102 - > uni_name , sizeof ( name ) ) ;
unistr2_to_ascii ( comment , & sv102 - > uni_comment , sizeof ( comment ) ) ;
unistr2_to_ascii ( usr_path , & sv102 - > uni_usr_path , sizeof ( usr_path ) ) ;
display_server ( name , sv102 - > srv_type , comment ) ;
2001-05-24 12:10:50 +04:00
printf ( " \t platform_id : \t %d \n " , sv102 - > platform_id ) ;
2007-10-11 00:34:30 +04:00
printf ( " \t os version : \t %d.%d \n " , sv102 - > ver_major ,
sv102 - > ver_minor ) ;
2001-05-24 12:10:50 +04:00
printf ( " \t users : \t %x \n " , sv102 - > users ) ;
printf ( " \t disc, hidden : \t %x, %x \n " , sv102 - > disc , sv102 - > hidden ) ;
printf ( " \t announce, delta : \t %d, %d \n " , sv102 - > announce ,
2007-10-11 00:34:30 +04:00
sv102 - > ann_delta ) ;
2001-05-24 12:10:50 +04:00
printf ( " \t licenses : \t %d \n " , sv102 - > licenses ) ;
2007-10-11 00:34:30 +04:00
printf ( " \t user path : \t %s \n " , usr_path ) ;
2001-05-24 12:10:50 +04:00
}
2001-05-24 04:20:32 +04:00
/* Server query info */
2007-10-11 00:34:30 +04:00
static WERROR cmd_srvsvc_srv_query_info ( struct rpc_pipe_client * cli ,
2001-10-12 09:56:23 +04:00
TALLOC_CTX * mem_ctx ,
2003-02-26 02:51:56 +03:00
int argc , const char * * argv )
1998-09-26 01:01:52 +04:00
{
1999-12-13 16:27:58 +03:00
uint32 info_level = 101 ;
2007-10-11 00:34:30 +04:00
SRV_INFO_CTR ctr ;
WERROR result ;
1998-09-26 01:01:52 +04:00
2001-05-24 04:20:32 +04:00
if ( argc > 2 ) {
printf ( " Usage: %s [infolevel] \n " , argv [ 0 ] ) ;
2007-10-11 00:34:30 +04:00
return WERR_OK ;
1998-09-26 01:01:52 +04:00
}
2001-05-24 04:20:32 +04:00
if ( argc = = 2 )
info_level = atoi ( argv [ 1 ] ) ;
1999-12-13 16:27:58 +03:00
2007-10-11 00:34:30 +04:00
result = rpccli_srvsvc_net_srv_get_info ( cli , mem_ctx , info_level ,
2001-09-04 14:57:29 +04:00
& ctr ) ;
2001-10-12 09:56:23 +04:00
2007-10-11 00:34:30 +04:00
if ( ! W_ERROR_IS_OK ( result ) ) {
2001-05-24 12:10:50 +04:00
goto done ;
}
/* Display results */
switch ( info_level ) {
case 101 :
2007-10-11 00:34:30 +04:00
display_srv_info_101 ( & ctr . srv . sv101 ) ;
2001-05-24 12:10:50 +04:00
break ;
case 102 :
2007-10-11 00:34:30 +04:00
display_srv_info_102 ( & ctr . srv . sv102 ) ;
2001-05-24 12:10:50 +04:00
break ;
default :
printf ( " unsupported info level %d \n " , info_level ) ;
break ;
}
done :
2003-03-18 09:30:30 +03:00
return result ;
1998-09-26 01:01:52 +04:00
}
2007-10-11 00:34:30 +04:00
static void display_share_info_1 ( SRV_SHARE_INFO_1 * info1 )
2002-07-15 14:35:28 +04:00
{
2007-10-11 00:34:30 +04:00
fstring netname = " " , remark = " " ;
rpcstr_pull_unistr2_fstring ( netname , & info1 - > info_1_str . uni_netname ) ;
rpcstr_pull_unistr2_fstring ( remark , & info1 - > info_1_str . uni_remark ) ;
printf ( " netname: %s \n " , netname ) ;
printf ( " \t remark: \t %s \n " , remark ) ;
2002-07-15 14:35:28 +04:00
}
2007-10-11 00:34:30 +04:00
static void display_share_info_2 ( SRV_SHARE_INFO_2 * info2 )
2002-07-15 14:35:28 +04:00
{
2007-10-11 00:34:30 +04:00
fstring netname = " " , remark = " " , path = " " , passwd = " " ;
rpcstr_pull_unistr2_fstring ( netname , & info2 - > info_2_str . uni_netname ) ;
rpcstr_pull_unistr2_fstring ( remark , & info2 - > info_2_str . uni_remark ) ;
rpcstr_pull_unistr2_fstring ( path , & info2 - > info_2_str . uni_path ) ;
rpcstr_pull_unistr2_fstring ( passwd , & info2 - > info_2_str . uni_passwd ) ;
printf ( " netname: %s \n " , netname ) ;
printf ( " \t remark: \t %s \n " , remark ) ;
printf ( " \t path: \t %s \n " , path ) ;
printf ( " \t password: \t %s \n " , passwd ) ;
2002-07-15 14:35:28 +04:00
}
2007-10-11 00:34:30 +04:00
static void display_share_info_502 ( SRV_SHARE_INFO_502 * info502 )
2004-07-21 05:32:09 +04:00
{
2007-10-11 00:34:30 +04:00
fstring netname = " " , remark = " " , path = " " , passwd = " " ;
rpcstr_pull_unistr2_fstring ( netname , & info502 - > info_502_str . uni_netname ) ;
rpcstr_pull_unistr2_fstring ( remark , & info502 - > info_502_str . uni_remark ) ;
rpcstr_pull_unistr2_fstring ( path , & info502 - > info_502_str . uni_path ) ;
rpcstr_pull_unistr2_fstring ( passwd , & info502 - > info_502_str . uni_passwd ) ;
printf ( " netname: %s \n " , netname ) ;
printf ( " \t remark: \t %s \n " , remark ) ;
printf ( " \t path: \t %s \n " , path ) ;
printf ( " \t password: \t %s \n " , passwd ) ;
printf ( " \t type: \t 0x%x \n " , info502 - > info_502 . type ) ;
printf ( " \t perms: \t %d \n " , info502 - > info_502 . perms ) ;
printf ( " \t max_uses: \t %d \n " , info502 - > info_502 . max_uses ) ;
printf ( " \t num_uses: \t %d \n " , info502 - > info_502 . num_uses ) ;
2005-06-16 13:36:53 +04:00
2007-10-11 00:34:30 +04:00
if ( info502 - > info_502_str . sd )
display_sec_desc ( info502 - > info_502_str . sd ) ;
2004-07-21 05:32:09 +04:00
}
2007-10-11 00:34:30 +04:00
static WERROR cmd_srvsvc_net_share_enum ( struct rpc_pipe_client * cli ,
2002-07-15 14:35:28 +04:00
TALLOC_CTX * mem_ctx ,
2003-02-26 02:51:56 +03:00
int argc , const char * * argv )
2002-07-15 14:35:28 +04:00
{
uint32 info_level = 2 ;
2007-10-11 00:34:30 +04:00
SRV_SHARE_INFO_CTR ctr ;
WERROR result ;
ENUM_HND hnd ;
2002-07-15 14:35:28 +04:00
uint32 preferred_len = 0xffffffff , i ;
2006-09-27 03:43:58 +04:00
2002-07-15 14:35:28 +04:00
if ( argc > 2 ) {
printf ( " Usage: %s [infolevel] \n " , argv [ 0 ] ) ;
2007-10-11 00:34:30 +04:00
return WERR_OK ;
2002-07-15 14:35:28 +04:00
}
if ( argc = = 2 )
info_level = atoi ( argv [ 1 ] ) ;
2007-10-11 00:34:30 +04:00
init_enum_hnd ( & hnd , 0 ) ;
2006-09-27 03:43:58 +04:00
2007-10-11 00:34:30 +04:00
result = rpccli_srvsvc_net_share_enum (
cli , mem_ctx , info_level , & ctr , preferred_len , & hnd ) ;
2002-07-15 14:35:28 +04:00
2007-10-11 00:34:30 +04:00
if ( ! W_ERROR_IS_OK ( result ) | | ! ctr . num_entries )
2002-07-15 14:35:28 +04:00
goto done ;
/* Display results */
switch ( info_level ) {
case 1 :
2007-10-11 00:34:30 +04:00
for ( i = 0 ; i < ctr . num_entries ; i + + )
display_share_info_1 ( & ctr . share . info1 [ i ] ) ;
2002-07-15 14:35:28 +04:00
break ;
case 2 :
2007-10-11 00:34:30 +04:00
for ( i = 0 ; i < ctr . num_entries ; i + + )
display_share_info_2 ( & ctr . share . info2 [ i ] ) ;
2002-07-15 14:35:28 +04:00
break ;
2004-07-21 05:32:09 +04:00
case 502 :
2007-10-11 00:34:30 +04:00
for ( i = 0 ; i < ctr . num_entries ; i + + )
display_share_info_502 ( & ctr . share . info502 [ i ] ) ;
2004-07-21 05:32:09 +04:00
break ;
2002-07-15 14:35:28 +04:00
default :
printf ( " unsupported info level %d \n " , info_level ) ;
break ;
}
done :
2003-03-18 09:30:30 +03:00
return result ;
2002-07-15 14:35:28 +04:00
}
2007-10-11 00:34:30 +04:00
static WERROR cmd_srvsvc_net_share_get_info ( struct rpc_pipe_client * cli ,
2005-06-13 17:16:55 +04:00
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
uint32 info_level = 502 ;
2007-10-11 00:34:30 +04:00
SRV_SHARE_INFO info ;
WERROR result ;
2005-06-13 17:16:55 +04:00
if ( argc > 3 ) {
printf ( " Usage: %s [sharename] [infolevel] \n " , argv [ 0 ] ) ;
2007-10-11 00:34:30 +04:00
return WERR_OK ;
2005-06-13 17:16:55 +04:00
}
if ( argc = = 3 )
info_level = atoi ( argv [ 2 ] ) ;
2007-10-11 00:34:30 +04:00
result = rpccli_srvsvc_net_share_get_info ( cli , mem_ctx , argv [ 1 ] , info_level , & info ) ;
2005-06-13 17:16:55 +04:00
2007-10-11 00:34:30 +04:00
if ( ! W_ERROR_IS_OK ( result ) )
2005-06-13 17:16:55 +04:00
goto done ;
/* Display results */
switch ( info_level ) {
case 1 :
2007-10-11 00:34:30 +04:00
display_share_info_1 ( & info . share . info1 ) ;
2005-06-13 17:16:55 +04:00
break ;
case 2 :
2007-10-11 00:34:30 +04:00
display_share_info_2 ( & info . share . info2 ) ;
2005-06-13 17:16:55 +04:00
break ;
case 502 :
2007-10-11 00:34:30 +04:00
display_share_info_502 ( & info . share . info502 ) ;
2005-06-13 17:16:55 +04:00
break ;
default :
printf ( " unsupported info level %d \n " , info_level ) ;
break ;
}
done :
return result ;
}
2007-10-11 00:34:30 +04:00
static WERROR cmd_srvsvc_net_share_set_info ( struct rpc_pipe_client * cli ,
2005-06-13 17:16:55 +04:00
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
uint32 info_level = 502 ;
2007-10-11 00:34:30 +04:00
SRV_SHARE_INFO info_get ;
WERROR result ;
2005-06-13 17:16:55 +04:00
if ( argc > 3 ) {
printf ( " Usage: %s [sharename] [comment] \n " , argv [ 0 ] ) ;
2007-10-11 00:34:30 +04:00
return WERR_OK ;
2005-06-13 17:16:55 +04:00
}
/* retrieve share info */
2007-10-11 00:34:30 +04:00
result = rpccli_srvsvc_net_share_get_info ( cli , mem_ctx , argv [ 1 ] , info_level , & info_get ) ;
if ( ! W_ERROR_IS_OK ( result ) )
2005-06-13 17:16:55 +04:00
goto done ;
2007-10-11 00:34:30 +04:00
info_get . switch_value = info_level ;
info_get . ptr_share_ctr = 1 ;
init_unistr2 ( & ( info_get . share . info502 . info_502_str . uni_remark ) , argv [ 2 ] , UNI_STR_TERMINATE ) ;
2005-06-13 17:16:55 +04:00
/* set share info */
2007-10-11 00:34:30 +04:00
result = rpccli_srvsvc_net_share_set_info ( cli , mem_ctx , argv [ 1 ] , info_level , & info_get ) ;
2005-06-13 17:16:55 +04:00
2007-10-11 00:34:30 +04:00
if ( ! W_ERROR_IS_OK ( result ) )
2005-06-13 17:16:55 +04:00
goto done ;
/* re-retrieve share info and display */
2007-10-11 00:34:30 +04:00
result = rpccli_srvsvc_net_share_get_info ( cli , mem_ctx , argv [ 1 ] , info_level , & info_get ) ;
if ( ! W_ERROR_IS_OK ( result ) )
2005-06-13 17:16:55 +04:00
goto done ;
2007-10-11 00:34:30 +04:00
display_share_info_502 ( & info_get . share . info502 ) ;
2005-06-13 17:16:55 +04:00
done :
return result ;
}
2007-10-11 00:34:30 +04:00
static WERROR cmd_srvsvc_net_remote_tod ( struct rpc_pipe_client * cli ,
2002-07-15 14:35:28 +04:00
TALLOC_CTX * mem_ctx ,
2003-02-26 02:51:56 +03:00
int argc , const char * * argv )
2002-07-15 14:35:28 +04:00
{
2007-10-11 00:34:30 +04:00
TIME_OF_DAY_INFO tod ;
2005-09-30 21:13:37 +04:00
fstring srv_name_slash ;
2007-10-11 00:34:30 +04:00
WERROR result ;
2002-07-15 14:35:28 +04:00
if ( argc > 1 ) {
printf ( " Usage: %s \n " , argv [ 0 ] ) ;
2007-10-11 00:34:30 +04:00
return WERR_OK ;
2002-07-15 14:35:28 +04:00
}
2005-09-30 21:13:37 +04:00
fstr_sprintf ( srv_name_slash , " \\ \\ %s " , cli - > cli - > desthost ) ;
2007-10-11 00:34:30 +04:00
result = rpccli_srvsvc_net_remote_tod (
2005-09-30 21:13:37 +04:00
cli , mem_ctx , srv_name_slash , & tod ) ;
2002-07-15 14:35:28 +04:00
2007-10-11 00:34:30 +04:00
if ( ! W_ERROR_IS_OK ( result ) )
2002-07-15 14:35:28 +04:00
goto done ;
done :
2003-03-18 09:30:30 +03:00
return result ;
2002-07-15 14:35:28 +04:00
}
2007-10-11 00:34:30 +04:00
static WERROR cmd_srvsvc_net_file_enum ( struct rpc_pipe_client * cli ,
2002-07-15 14:35:28 +04:00
TALLOC_CTX * mem_ctx ,
2003-02-26 02:51:56 +03:00
int argc , const char * * argv )
2002-07-15 14:35:28 +04:00
{
uint32 info_level = 3 ;
2007-10-11 00:34:30 +04:00
SRV_FILE_INFO_CTR ctr ;
WERROR result ;
ENUM_HND hnd ;
2006-01-13 14:19:59 +03:00
uint32 preferred_len = 0xffff ;
2002-07-15 14:35:28 +04:00
if ( argc > 2 ) {
printf ( " Usage: %s [infolevel] \n " , argv [ 0 ] ) ;
2007-10-11 00:34:30 +04:00
return WERR_OK ;
2002-07-15 14:35:28 +04:00
}
if ( argc = = 2 )
info_level = atoi ( argv [ 1 ] ) ;
2007-10-11 00:34:30 +04:00
init_enum_hnd ( & hnd , 0 ) ;
2002-07-15 14:35:28 +04:00
ZERO_STRUCT ( ctr ) ;
2007-10-11 00:34:30 +04:00
result = rpccli_srvsvc_net_file_enum (
cli , mem_ctx , info_level , NULL , & ctr , preferred_len , & hnd ) ;
2002-07-15 14:35:28 +04:00
2007-10-11 00:34:30 +04:00
if ( ! W_ERROR_IS_OK ( result ) )
2002-07-15 14:35:28 +04:00
goto done ;
done :
2003-03-18 09:30:30 +03:00
return result ;
2002-07-15 14:35:28 +04:00
}
2001-05-24 04:20:32 +04:00
/* List of commands exported by this module */
1999-12-13 16:27:58 +03:00
2001-05-24 04:20:32 +04:00
struct cmd_set srvsvc_commands [ ] = {
2001-07-20 08:38:58 +04:00
{ " SRVSVC " } ,
2007-10-11 00:34:30 +04:00
{ " srvinfo " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_srv_query_info , PI_SRVSVC , NULL , " Server query info " , " " } ,
{ " netshareenum " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_share_enum , PI_SRVSVC , NULL , " Enumerate shares " , " " } ,
{ " netsharegetinfo " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_share_get_info , PI_SRVSVC , NULL , " Get Share Info " , " " } ,
{ " netsharesetinfo " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_share_set_info , PI_SRVSVC , NULL , " Set Share Info " , " " } ,
{ " netfileenum " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_file_enum , PI_SRVSVC , NULL , " Enumerate open files " , " " } ,
{ " netremotetod " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_remote_tod , PI_SRVSVC , NULL , " Fetch remote time of day " , " " } ,
2001-07-20 08:38:58 +04:00
{ NULL }
2001-05-24 04:20:32 +04:00
} ;