2001-06-06 11:32:51 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2001-06-06 11:32:51 +04:00
RPC pipe client
Copyright ( C ) Tim Potter 2000
2006-02-04 01:19:41 +03:00
Copyright ( C ) Jelmer Vernooij 2005.
2001-06-06 11:32:51 +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
2001-06-06 11:32:51 +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/>.
2001-06-06 11:32:51 +04:00
*/
# include "includes.h"
2001-10-12 09:56:23 +04:00
# include "rpcclient.h"
2011-01-11 13:24:41 +03:00
# include "../librpc/gen_ndr/ndr_dfs_c.h"
2001-06-06 11:32:51 +04:00
2001-06-13 10:37:02 +04:00
/* Check DFS is supported by the remote server */
2007-12-03 20:36:25 +03:00
static WERROR cmd_dfs_version ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
2001-06-13 10:37:02 +04:00
{
2007-06-27 13:23:50 +04:00
enum dfs_ManagerVersion version ;
2001-09-04 14:57:29 +04:00
NTSTATUS result ;
2011-01-05 19:22:24 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2001-06-13 10:37:02 +04:00
if ( argc ! = 1 ) {
printf ( " Usage: %s \n " , argv [ 0 ] ) ;
2007-12-03 20:36:25 +03:00
return WERR_OK ;
2001-06-13 10:37:02 +04:00
}
2011-01-05 19:22:24 +03:00
result = dcerpc_dfs_GetManagerVersion ( b , mem_ctx , & version ) ;
2001-06-13 10:37:02 +04:00
2007-06-27 13:23:50 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2007-12-03 20:36:25 +03:00
return ntstatus_to_werror ( result ) ;
2007-06-27 13:23:50 +04:00
}
2001-06-13 10:37:02 +04:00
2007-06-27 13:23:50 +04:00
if ( version > 0 ) {
printf ( " dfs is present (%d) \n " , version ) ;
} else {
printf ( " dfs is not present \n " ) ;
}
2007-12-03 20:36:25 +03:00
return WERR_OK ;
2001-06-13 10:37:02 +04:00
}
2007-12-03 20:36:25 +03:00
static WERROR cmd_dfs_add ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
2001-06-13 10:37:02 +04:00
{
2001-09-04 14:57:29 +04:00
NTSTATUS result ;
2007-12-03 20:36:25 +03:00
WERROR werr ;
2006-02-04 01:19:41 +03:00
const char * path , * servername , * sharename , * comment ;
2001-06-13 10:37:02 +04:00
uint32 flags = 0 ;
2011-01-05 19:22:24 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2001-06-13 10:37:02 +04:00
if ( argc ! = 5 ) {
2006-02-04 01:19:41 +03:00
printf ( " Usage: %s path servername sharename comment \n " ,
2001-06-13 10:37:02 +04:00
argv [ 0 ] ) ;
2007-12-03 20:36:25 +03:00
return WERR_OK ;
2001-06-13 10:37:02 +04:00
}
2006-02-04 01:19:41 +03:00
path = argv [ 1 ] ;
2001-06-13 10:37:02 +04:00
servername = argv [ 2 ] ;
sharename = argv [ 3 ] ;
comment = argv [ 4 ] ;
2011-01-05 19:22:24 +03:00
result = dcerpc_dfs_Add ( b , mem_ctx , path , servername ,
2007-12-03 20:36:25 +03:00
sharename , comment , flags , & werr ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
return ntstatus_to_werror ( result ) ;
}
2001-06-13 10:37:02 +04:00
2007-12-03 20:36:25 +03:00
return werr ;
2001-06-13 10:37:02 +04:00
}
2007-12-03 20:36:25 +03:00
static WERROR cmd_dfs_remove ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
2001-06-13 10:37:02 +04:00
{
2001-09-04 14:57:29 +04:00
NTSTATUS result ;
2007-12-03 20:36:25 +03:00
WERROR werr ;
2006-02-04 01:19:41 +03:00
const char * path , * servername , * sharename ;
2011-01-05 19:22:24 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2001-06-13 10:37:02 +04:00
if ( argc ! = 4 ) {
2006-02-04 01:19:41 +03:00
printf ( " Usage: %s path servername sharename \n " , argv [ 0 ] ) ;
2007-12-03 20:36:25 +03:00
return WERR_OK ;
2001-06-13 10:37:02 +04:00
}
2006-02-04 01:19:41 +03:00
path = argv [ 1 ] ;
2001-06-13 10:37:02 +04:00
servername = argv [ 2 ] ;
sharename = argv [ 3 ] ;
2011-01-05 19:22:24 +03:00
result = dcerpc_dfs_Remove ( b , mem_ctx , path , servername ,
2007-12-03 20:36:25 +03:00
sharename , & werr ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
return ntstatus_to_werror ( result ) ;
}
2001-06-13 10:37:02 +04:00
2007-12-03 20:36:25 +03:00
return werr ;
2001-06-13 10:37:02 +04:00
}
/* Display a DFS_INFO_1 structure */
2006-09-13 17:42:23 +04:00
static void display_dfs_info_1 ( struct dfs_Info1 * info1 )
2001-06-13 10:37:02 +04:00
{
2006-09-13 17:42:23 +04:00
printf ( " path: %s \n " , info1 - > path ) ;
2001-06-13 10:37:02 +04:00
}
/* Display a DFS_INFO_2 structure */
2006-09-13 17:42:23 +04:00
static void display_dfs_info_2 ( struct dfs_Info2 * info2 )
2001-06-13 10:37:02 +04:00
{
2006-09-13 17:42:23 +04:00
printf ( " path: %s \n " , info2 - > path ) ;
printf ( " \t comment: %s \n " , info2 - > comment ) ;
2001-06-13 10:37:02 +04:00
printf ( " \t state: %d \n " , info2 - > state ) ;
2006-02-04 01:19:41 +03:00
printf ( " \t num_stores: %d \n " , info2 - > num_stores ) ;
2001-06-13 10:37:02 +04:00
}
/* Display a DFS_INFO_3 structure */
2006-09-13 17:42:23 +04:00
static void display_dfs_info_3 ( struct dfs_Info3 * info3 )
2001-06-13 10:37:02 +04:00
{
int i ;
2006-09-13 17:42:23 +04:00
printf ( " path: %s \n " , info3 - > path ) ;
2001-06-13 10:37:02 +04:00
2006-09-13 17:42:23 +04:00
printf ( " \t comment: %s \n " , info3 - > comment ) ;
2001-06-13 10:37:02 +04:00
printf ( " \t state: %d \n " , info3 - > state ) ;
2006-02-04 01:19:41 +03:00
printf ( " \t num_stores: %d \n " , info3 - > num_stores ) ;
2001-06-13 10:37:02 +04:00
2006-02-04 01:19:41 +03:00
for ( i = 0 ; i < info3 - > num_stores ; i + + ) {
2006-09-13 17:42:23 +04:00
struct dfs_StorageInfo * dsi = & info3 - > stores [ i ] ;
2001-06-13 10:37:02 +04:00
2006-09-13 17:42:23 +04:00
printf ( " \t \t storage[%d] server: %s \n " , i , dsi - > server ) ;
2001-06-13 10:37:02 +04:00
2006-09-13 17:42:23 +04:00
printf ( " \t \t storage[%d] share: %s \n " , i , dsi - > share ) ;
2001-06-13 10:37:02 +04:00
}
}
2006-02-04 01:19:41 +03:00
/* Display a DFS_INFO_CTR structure */
2006-09-13 17:42:23 +04:00
static void display_dfs_info ( uint32 level , union dfs_Info * ctr )
2001-06-13 10:37:02 +04:00
{
2006-09-13 17:42:23 +04:00
switch ( level ) {
2001-06-13 10:37:02 +04:00
case 0x01 :
2006-09-13 17:42:23 +04:00
display_dfs_info_1 ( ctr - > info1 ) ;
2001-06-13 10:37:02 +04:00
break ;
case 0x02 :
2006-09-13 17:42:23 +04:00
display_dfs_info_2 ( ctr - > info2 ) ;
2001-06-13 10:37:02 +04:00
break ;
case 0x03 :
2006-09-13 17:42:23 +04:00
display_dfs_info_3 ( ctr - > info3 ) ;
2001-06-13 10:37:02 +04:00
break ;
default :
printf ( " unsupported info level %d \n " ,
2006-09-13 17:42:23 +04:00
level ) ;
2001-06-13 10:37:02 +04:00
break ;
2006-02-04 01:19:41 +03:00
}
}
2006-09-13 17:42:23 +04:00
static void display_dfs_enumstruct ( struct dfs_EnumStruct * ctr )
2006-02-04 01:19:41 +03:00
{
int i ;
/* count is always the first element, so we can just use info1 here */
2006-09-13 17:42:23 +04:00
for ( i = 0 ; i < ctr - > e . info1 - > count ; i + + ) {
2006-02-04 01:19:41 +03:00
switch ( ctr - > level ) {
2006-09-13 17:42:23 +04:00
case 1 : display_dfs_info_1 ( & ctr - > e . info1 - > s [ i ] ) ; break ;
case 2 : display_dfs_info_2 ( & ctr - > e . info2 - > s [ i ] ) ; break ;
case 3 : display_dfs_info_3 ( & ctr - > e . info3 - > s [ i ] ) ; break ;
2006-02-04 01:19:41 +03:00
default :
printf ( " unsupported info level %d \n " ,
ctr - > level ) ;
return ;
2001-06-13 10:37:02 +04:00
}
}
}
/* Enumerate dfs shares */
2007-12-03 20:36:25 +03:00
static WERROR cmd_dfs_enum ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
2001-06-13 10:37:02 +04:00
{
2006-09-13 17:42:23 +04:00
struct dfs_EnumStruct str ;
struct dfs_EnumArray1 info1 ;
struct dfs_EnumArray2 info2 ;
struct dfs_EnumArray3 info3 ;
struct dfs_EnumArray4 info4 ;
struct dfs_EnumArray200 info200 ;
struct dfs_EnumArray300 info300 ;
2011-01-05 19:22:24 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2006-09-13 17:42:23 +04:00
2001-09-04 14:57:29 +04:00
NTSTATUS result ;
2007-12-03 20:36:25 +03:00
WERROR werr ;
2006-08-08 15:00:16 +04:00
uint32 total = 0 ;
2001-06-13 10:37:02 +04:00
if ( argc > 2 ) {
printf ( " Usage: %s [info_level] \n " , argv [ 0 ] ) ;
2007-12-03 20:36:25 +03:00
return WERR_OK ;
2001-06-13 10:37:02 +04:00
}
2006-09-13 17:42:23 +04:00
str . level = 1 ;
2001-06-13 10:37:02 +04:00
if ( argc = = 2 )
2006-09-13 17:42:23 +04:00
str . level = atoi ( argv [ 1 ] ) ;
switch ( str . level ) {
case 1 : str . e . info1 = & info1 ; ZERO_STRUCT ( info1 ) ; break ;
case 2 : str . e . info2 = & info2 ; ZERO_STRUCT ( info2 ) ; break ;
case 3 : str . e . info3 = & info3 ; ZERO_STRUCT ( info3 ) ; break ;
case 4 : str . e . info4 = & info4 ; ZERO_STRUCT ( info4 ) ; break ;
case 200 : str . e . info200 = & info200 ; ZERO_STRUCT ( info200 ) ; break ;
case 300 : str . e . info300 = & info300 ; ZERO_STRUCT ( info300 ) ; break ;
default :
printf ( " Unknown info level %d \n " , str . level ) ;
break ;
}
2006-02-04 01:19:41 +03:00
2011-01-05 19:22:24 +03:00
result = dcerpc_dfs_Enum ( b , mem_ctx , str . level , 0xFFFFFFFF , & str ,
2007-12-03 20:36:25 +03:00
& total , & werr ) ;
2011-01-05 19:22:24 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
return ntstatus_to_werror ( result ) ;
}
if ( W_ERROR_IS_OK ( werr ) ) {
2006-02-04 01:19:41 +03:00
display_dfs_enumstruct ( & str ) ;
2007-12-03 20:36:25 +03:00
}
2001-06-13 10:37:02 +04:00
2007-12-03 20:36:25 +03:00
return werr ;
2001-06-13 10:37:02 +04:00
}
2006-08-08 15:45:57 +04:00
/* Enumerate dfs shares */
2007-12-03 20:36:25 +03:00
static WERROR cmd_dfs_enumex ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
2006-08-08 15:45:57 +04:00
{
2006-09-13 17:42:23 +04:00
struct dfs_EnumStruct str ;
struct dfs_EnumArray1 info1 ;
struct dfs_EnumArray2 info2 ;
struct dfs_EnumArray3 info3 ;
struct dfs_EnumArray4 info4 ;
struct dfs_EnumArray200 info200 ;
struct dfs_EnumArray300 info300 ;
2011-01-05 19:22:24 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2006-09-13 17:42:23 +04:00
2006-08-08 15:45:57 +04:00
NTSTATUS result ;
2007-12-03 20:36:25 +03:00
WERROR werr ;
2006-08-08 15:45:57 +04:00
uint32 total = 0 ;
if ( argc < 2 | | argc > 3 ) {
printf ( " Usage: %s dfs_name [info_level] \n " , argv [ 0 ] ) ;
2007-12-03 20:36:25 +03:00
return WERR_OK ;
2006-08-08 15:45:57 +04:00
}
2008-03-21 13:45:57 +03:00
str . level = 1 ;
2006-08-08 15:45:57 +04:00
if ( argc = = 3 )
2006-09-13 17:42:23 +04:00
str . level = atoi ( argv [ 2 ] ) ;
switch ( str . level ) {
case 1 : str . e . info1 = & info1 ; ZERO_STRUCT ( info1 ) ; break ;
case 2 : str . e . info2 = & info2 ; ZERO_STRUCT ( info2 ) ; break ;
case 3 : str . e . info3 = & info3 ; ZERO_STRUCT ( info3 ) ; break ;
case 4 : str . e . info4 = & info4 ; ZERO_STRUCT ( info4 ) ; break ;
case 200 : str . e . info200 = & info200 ; ZERO_STRUCT ( info200 ) ; break ;
case 300 : str . e . info300 = & info300 ; ZERO_STRUCT ( info300 ) ; break ;
default :
printf ( " Unknown info level %d \n " , str . level ) ;
break ;
}
2006-08-08 15:45:57 +04:00
2011-01-05 19:22:24 +03:00
result = dcerpc_dfs_EnumEx ( b , mem_ctx , argv [ 1 ] , str . level ,
2007-12-03 20:36:25 +03:00
0xFFFFFFFF , & str , & total , & werr ) ;
2011-01-05 19:22:24 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
return ntstatus_to_werror ( result ) ;
}
if ( W_ERROR_IS_OK ( werr ) ) {
2006-08-08 15:45:57 +04:00
display_dfs_enumstruct ( & str ) ;
2007-12-03 20:36:25 +03:00
}
2006-08-08 15:45:57 +04:00
2007-12-03 20:36:25 +03:00
return werr ;
2006-08-08 15:45:57 +04:00
}
2007-12-03 20:36:25 +03:00
static WERROR cmd_dfs_getinfo ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
2001-06-13 10:37:02 +04:00
{
2001-09-04 14:57:29 +04:00
NTSTATUS result ;
2007-12-03 20:36:25 +03:00
WERROR werr ;
2006-02-04 01:19:41 +03:00
const char * path , * servername , * sharename ;
2001-06-13 10:37:02 +04:00
uint32 info_level = 1 ;
2006-09-13 17:42:23 +04:00
union dfs_Info ctr ;
2011-01-05 19:22:24 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2001-06-13 10:37:02 +04:00
if ( argc < 4 | | argc > 5 ) {
2006-02-04 01:19:41 +03:00
printf ( " Usage: %s path servername sharename "
2001-10-12 09:56:23 +04:00
" [info_level] \n " , argv [ 0 ] ) ;
2007-12-03 20:36:25 +03:00
return WERR_OK ;
2001-06-13 10:37:02 +04:00
}
2006-02-04 01:19:41 +03:00
path = argv [ 1 ] ;
2001-06-13 10:37:02 +04:00
servername = argv [ 2 ] ;
sharename = argv [ 3 ] ;
if ( argc = = 5 )
info_level = atoi ( argv [ 4 ] ) ;
2011-01-05 19:22:24 +03:00
result = dcerpc_dfs_GetInfo ( b , mem_ctx , path , servername ,
2007-12-03 20:36:25 +03:00
sharename , info_level , & ctr , & werr ) ;
2011-01-05 19:22:24 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
return ntstatus_to_werror ( result ) ;
}
if ( W_ERROR_IS_OK ( werr ) ) {
2006-09-13 17:42:23 +04:00
display_dfs_info ( info_level , & ctr ) ;
2007-12-03 20:36:25 +03:00
}
2001-06-13 10:37:02 +04:00
2007-12-03 20:36:25 +03:00
return werr ;
2001-06-13 10:37:02 +04:00
}
2001-06-06 11:32:51 +04:00
/* List of commands exported by this module */
struct cmd_set dfs_commands [ ] = {
2001-06-13 10:37:02 +04:00
2001-07-20 08:38:58 +04:00
{ " DFS " } ,
2001-06-13 10:37:02 +04:00
2012-01-10 14:53:42 +04:00
{ " dfsversion " , RPC_RTYPE_WERROR , NULL , cmd_dfs_version , & ndr_table_netdfs , NULL , " Query DFS support " , " " } ,
{ " dfsadd " , RPC_RTYPE_WERROR , NULL , cmd_dfs_add , & ndr_table_netdfs , NULL , " Add a DFS share " , " " } ,
{ " dfsremove " , RPC_RTYPE_WERROR , NULL , cmd_dfs_remove , & ndr_table_netdfs , NULL , " Remove a DFS share " , " " } ,
{ " dfsgetinfo " , RPC_RTYPE_WERROR , NULL , cmd_dfs_getinfo , & ndr_table_netdfs , NULL , " Query DFS share info " , " " } ,
{ " dfsenum " , RPC_RTYPE_WERROR , NULL , cmd_dfs_enum , & ndr_table_netdfs , NULL , " Enumerate dfs shares " , " " } ,
{ " dfsenumex " , RPC_RTYPE_WERROR , NULL , cmd_dfs_enumex , & ndr_table_netdfs , NULL , " Enumerate dfs shares " , " " } ,
2001-07-20 08:38:58 +04:00
{ NULL }
2001-06-06 11:32:51 +04:00
} ;