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"
2010-08-06 16:52:58 +04:00
# include "../librpc/gen_ndr/ndr_srvsvc.h"
2011-01-12 15:22:08 +03:00
# include "../librpc/gen_ndr/ndr_srvsvc_c.h"
2011-02-24 12:47:16 +03:00
# include "../libcli/security/display_sec.h"
1998-09-26 01:01:52 +04:00
2001-05-24 12:10:50 +04:00
/* Display server query info */
2015-05-09 17:33:08 +03:00
static char * get_server_type_str ( uint32_t type )
2001-05-24 12:10:50 +04:00
{
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 ;
}
2015-05-09 17:33:08 +03:00
static void display_server ( const char * sname , uint32_t 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 ) ;
}
2008-03-05 01:11:53 +03:00
static void display_srv_info_101 ( struct srvsvc_NetSrvInfo101 * r )
2001-05-24 12:10:50 +04:00
{
2008-03-05 01:11:53 +03:00
display_server ( r - > server_name , r - > server_type , r - > comment ) ;
2007-10-11 00:34:30 +04:00
2008-03-05 01:11:53 +03:00
printf ( " \t platform_id : \t %d \n " , r - > platform_id ) ;
printf ( " \t os version : \t %d.%d \n " ,
r - > version_major , r - > version_minor ) ;
printf ( " \t server type : \t 0x%x \n " , r - > server_type ) ;
2001-05-24 12:10:50 +04:00
}
2008-03-05 01:11:53 +03:00
static void display_srv_info_102 ( struct srvsvc_NetSrvInfo102 * r )
2001-05-24 12:10:50 +04:00
{
2008-03-05 01:11:53 +03:00
display_server ( r - > server_name , r - > server_type , r - > comment ) ;
printf ( " \t platform_id : \t %d \n " , r - > platform_id ) ;
printf ( " \t os version : \t %d.%d \n " ,
r - > version_major , r - > version_minor ) ;
printf ( " \t server type : \t 0x%x \n " , r - > server_type ) ;
printf ( " \t users : \t %x \n " , r - > users ) ;
printf ( " \t disc, hidden : \t %x, %x \n " , r - > disc , r - > hidden ) ;
printf ( " \t announce, delta : \t %d, %d \n " , r - > announce ,
r - > anndelta ) ;
printf ( " \t licenses : \t %d \n " , r - > licenses ) ;
printf ( " \t user path : \t %s \n " , r - > userpath ) ;
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
{
2015-05-09 17:33:08 +03:00
uint32_t info_level = 101 ;
2008-03-05 01:11:53 +03:00
union srvsvc_NetSrvInfo info ;
2007-10-11 00:34:30 +04:00
WERROR result ;
2008-03-05 01:11:53 +03:00
NTSTATUS status ;
2010-04-07 16:38:31 +04:00
const char * server_unc = cli - > srv_name_slash ;
2011-01-12 15:22:08 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
1998-09-26 01:01:52 +04:00
2010-04-07 16:38:31 +04:00
if ( argc > 3 ) {
printf ( " Usage: %s [infolevel] [server_unc] \n " , argv [ 0 ] ) ;
2007-10-11 00:34:30 +04:00
return WERR_OK ;
1998-09-26 01:01:52 +04:00
}
2010-04-07 16:38:31 +04:00
if ( argc > = 2 ) {
2001-05-24 04:20:32 +04:00
info_level = atoi ( argv [ 1 ] ) ;
2010-04-07 16:38:31 +04:00
}
if ( argc > = 3 ) {
server_unc = argv [ 2 ] ;
}
1999-12-13 16:27:58 +03:00
2011-01-12 15:22:08 +03:00
status = dcerpc_srvsvc_NetSrvGetInfo ( b , mem_ctx ,
2010-04-07 16:38:31 +04:00
server_unc ,
2008-03-05 01:11:53 +03:00
info_level ,
& info ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return ntstatus_to_werror ( status ) ;
}
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 :
2008-03-05 01:11:53 +03:00
display_srv_info_101 ( info . info101 ) ;
2001-05-24 12:10:50 +04:00
break ;
case 102 :
2008-03-05 01:11:53 +03:00
display_srv_info_102 ( info . info102 ) ;
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
}
2008-03-08 00:55:33 +03:00
static void display_share_info_1 ( struct srvsvc_NetShareInfo1 * r )
2002-07-15 14:35:28 +04:00
{
2008-03-08 00:55:33 +03:00
printf ( " netname: %s \n " , r - > name ) ;
printf ( " \t remark: \t %s \n " , r - > comment ) ;
2002-07-15 14:35:28 +04:00
}
2008-03-08 00:55:33 +03:00
static void display_share_info_2 ( struct srvsvc_NetShareInfo2 * r )
2002-07-15 14:35:28 +04:00
{
2008-03-08 00:55:33 +03:00
printf ( " netname: %s \n " , r - > name ) ;
printf ( " \t remark: \t %s \n " , r - > comment ) ;
printf ( " \t path: \t %s \n " , r - > path ) ;
printf ( " \t password: \t %s \n " , r - > password ) ;
2002-07-15 14:35:28 +04:00
}
2008-03-08 00:55:33 +03:00
static void display_share_info_502 ( struct srvsvc_NetShareInfo502 * r )
2004-07-21 05:32:09 +04:00
{
2008-03-08 00:55:33 +03:00
printf ( " netname: %s \n " , r - > name ) ;
printf ( " \t remark: \t %s \n " , r - > comment ) ;
printf ( " \t path: \t %s \n " , r - > path ) ;
printf ( " \t password: \t %s \n " , r - > password ) ;
printf ( " \t type: \t 0x%x \n " , r - > type ) ;
printf ( " \t perms: \t %d \n " , r - > permissions ) ;
printf ( " \t max_uses: \t %d \n " , r - > max_users ) ;
printf ( " \t num_uses: \t %d \n " , r - > current_users ) ;
2008-04-01 02:32:23 +04:00
if ( r - > sd_buf . sd )
display_sec_desc ( r - > sd_buf . sd ) ;
2004-07-21 05:32:09 +04:00
}
2008-03-08 00:55:33 +03:00
static WERROR cmd_srvsvc_net_share_enum_int ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv ,
uint32_t opcode )
2002-07-15 14:35:28 +04:00
{
2015-05-09 17:33:08 +03:00
uint32_t info_level = 2 ;
2008-03-08 00:55:33 +03:00
struct srvsvc_NetShareInfoCtr info_ctr ;
struct srvsvc_NetShareCtr0 ctr0 ;
struct srvsvc_NetShareCtr1 ctr1 ;
struct srvsvc_NetShareCtr2 ctr2 ;
struct srvsvc_NetShareCtr501 ctr501 ;
struct srvsvc_NetShareCtr502 ctr502 ;
struct srvsvc_NetShareCtr1004 ctr1004 ;
struct srvsvc_NetShareCtr1005 ctr1005 ;
struct srvsvc_NetShareCtr1006 ctr1006 ;
struct srvsvc_NetShareCtr1007 ctr1007 ;
struct srvsvc_NetShareCtr1501 ctr1501 ;
2007-10-11 00:34:30 +04:00
WERROR result ;
2008-03-08 00:55:33 +03:00
NTSTATUS status ;
uint32_t totalentries = 0 ;
2013-08-20 21:55:27 +04:00
uint32_t count = 0 ;
2008-03-08 00:55:33 +03:00
uint32_t resume_handle = 0 ;
2008-03-11 13:29:49 +03:00
uint32_t * resume_handle_p = NULL ;
2015-05-09 17:33:08 +03:00
uint32_t preferred_len = 0xffffffff , i ;
2011-01-12 15:22:08 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2006-09-27 03:43:58 +04:00
2008-03-08 00:55:33 +03:00
if ( argc > 3 ) {
printf ( " Usage: %s [infolevel] [resume_handle] \n " , argv [ 0 ] ) ;
2007-10-11 00:34:30 +04:00
return WERR_OK ;
2002-07-15 14:35:28 +04:00
}
2008-03-08 00:55:33 +03:00
if ( argc > = 2 ) {
2002-07-15 14:35:28 +04:00
info_level = atoi ( argv [ 1 ] ) ;
2008-03-08 00:55:33 +03:00
}
2002-07-15 14:35:28 +04:00
2008-03-08 00:55:33 +03:00
if ( argc = = 3 ) {
resume_handle = atoi ( argv [ 2 ] ) ;
2008-03-11 13:29:49 +03:00
resume_handle_p = & resume_handle ;
2008-03-08 00:55:33 +03:00
}
ZERO_STRUCT ( info_ctr ) ;
2006-09-27 03:43:58 +04:00
2008-03-08 00:55:33 +03:00
info_ctr . level = info_level ;
2002-07-15 14:35:28 +04:00
2008-03-08 00:55:33 +03:00
switch ( info_level ) {
case 0 :
ZERO_STRUCT ( ctr0 ) ;
info_ctr . ctr . ctr0 = & ctr0 ;
break ;
case 1 :
ZERO_STRUCT ( ctr1 ) ;
info_ctr . ctr . ctr1 = & ctr1 ;
break ;
case 2 :
ZERO_STRUCT ( ctr2 ) ;
info_ctr . ctr . ctr2 = & ctr2 ;
break ;
case 501 :
ZERO_STRUCT ( ctr501 ) ;
info_ctr . ctr . ctr501 = & ctr501 ;
break ;
case 502 :
ZERO_STRUCT ( ctr502 ) ;
info_ctr . ctr . ctr502 = & ctr502 ;
break ;
case 1004 :
ZERO_STRUCT ( ctr1004 ) ;
info_ctr . ctr . ctr1004 = & ctr1004 ;
break ;
case 1005 :
ZERO_STRUCT ( ctr1005 ) ;
info_ctr . ctr . ctr1005 = & ctr1005 ;
break ;
case 1006 :
ZERO_STRUCT ( ctr1006 ) ;
info_ctr . ctr . ctr1006 = & ctr1006 ;
break ;
case 1007 :
ZERO_STRUCT ( ctr1007 ) ;
info_ctr . ctr . ctr1007 = & ctr1007 ;
break ;
case 1501 :
ZERO_STRUCT ( ctr1501 ) ;
info_ctr . ctr . ctr1501 = & ctr1501 ;
break ;
}
switch ( opcode ) {
case NDR_SRVSVC_NETSHAREENUM :
2011-01-12 15:22:08 +03:00
status = dcerpc_srvsvc_NetShareEnum ( b , mem_ctx ,
2008-04-19 23:56:43 +04:00
cli - > desthost ,
2008-03-08 00:55:33 +03:00
& info_ctr ,
preferred_len ,
& totalentries ,
2008-03-11 13:29:49 +03:00
resume_handle_p ,
2008-03-08 00:55:33 +03:00
& result ) ;
break ;
case NDR_SRVSVC_NETSHAREENUMALL :
2011-01-12 15:22:08 +03:00
status = dcerpc_srvsvc_NetShareEnumAll ( b , mem_ctx ,
2008-04-19 23:56:43 +04:00
cli - > desthost ,
2008-03-08 00:55:33 +03:00
& info_ctr ,
preferred_len ,
& totalentries ,
2008-03-11 13:29:49 +03:00
resume_handle_p ,
2008-03-08 00:55:33 +03:00
& result ) ;
break ;
default :
return WERR_INVALID_PARAM ;
}
2011-01-12 15:22:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
result = ntstatus_to_werror ( status ) ;
goto done ;
}
if ( ! W_ERROR_IS_OK ( result ) ) {
2002-07-15 14:35:28 +04:00
goto done ;
2008-03-08 00:55:33 +03:00
}
2002-07-15 14:35:28 +04:00
/* Display results */
switch ( info_level ) {
case 1 :
2013-08-20 21:55:27 +04:00
count = info_ctr . ctr . ctr1 - > count ;
for ( i = 0 ; i < count ; i + + )
2008-03-08 00:55:33 +03:00
display_share_info_1 ( & info_ctr . ctr . ctr1 - > array [ i ] ) ;
2002-07-15 14:35:28 +04:00
break ;
case 2 :
2013-08-20 21:55:27 +04:00
count = info_ctr . ctr . ctr2 - > count ;
for ( i = 0 ; i < count ; i + + )
2008-03-08 00:55:33 +03:00
display_share_info_2 ( & info_ctr . ctr . ctr2 - > array [ i ] ) ;
2002-07-15 14:35:28 +04:00
break ;
2004-07-21 05:32:09 +04:00
case 502 :
2013-08-20 21:55:27 +04:00
count = info_ctr . ctr . ctr502 - > count ;
for ( i = 0 ; i < count ; i + + )
2008-03-08 00:55:33 +03:00
display_share_info_502 ( & info_ctr . ctr . ctr502 - > array [ 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
}
2008-03-08 00:55:33 +03:00
static WERROR cmd_srvsvc_net_share_enum ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
return cmd_srvsvc_net_share_enum_int ( cli , mem_ctx ,
argc , argv ,
NDR_SRVSVC_NETSHAREENUM ) ;
}
static WERROR cmd_srvsvc_net_share_enum_all ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
return cmd_srvsvc_net_share_enum_int ( cli , mem_ctx ,
argc , argv ,
NDR_SRVSVC_NETSHAREENUMALL ) ;
}
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 )
{
2015-05-09 17:33:08 +03:00
uint32_t info_level = 502 ;
2008-03-08 00:55:33 +03:00
union srvsvc_NetShareInfo info ;
2007-10-11 00:34:30 +04:00
WERROR result ;
2008-03-08 00:55:33 +03:00
NTSTATUS status ;
2011-01-12 15:22:08 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2005-06-13 17:16:55 +04:00
2008-03-08 00:55:33 +03:00
if ( argc < 2 | | argc > 3 ) {
2005-06-13 17:16:55 +04:00
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 ] ) ;
2011-01-12 15:22:08 +03:00
status = dcerpc_srvsvc_NetShareGetInfo ( b , mem_ctx ,
2008-04-19 23:56:43 +04:00
cli - > desthost ,
2008-03-08 00:55:33 +03:00
argv [ 1 ] ,
info_level ,
& info ,
& result ) ;
2005-06-13 17:16:55 +04:00
2011-01-12 15:22:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
result = ntstatus_to_werror ( status ) ;
goto done ;
}
if ( ! W_ERROR_IS_OK ( result ) ) {
2005-06-13 17:16:55 +04:00
goto done ;
2008-03-08 00:55:33 +03:00
}
2005-06-13 17:16:55 +04:00
/* Display results */
switch ( info_level ) {
case 1 :
2008-03-08 00:55:33 +03:00
display_share_info_1 ( info . info1 ) ;
2005-06-13 17:16:55 +04:00
break ;
case 2 :
2008-03-08 00:55:33 +03:00
display_share_info_2 ( info . info2 ) ;
2005-06-13 17:16:55 +04:00
break ;
case 502 :
2008-03-08 00:55:33 +03:00
display_share_info_502 ( info . 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 )
{
2015-05-09 17:33:08 +03:00
uint32_t info_level = 502 ;
2008-03-08 00:55:33 +03:00
union srvsvc_NetShareInfo info_get ;
2007-10-11 00:34:30 +04:00
WERROR result ;
2008-03-08 00:55:33 +03:00
NTSTATUS status ;
uint32_t parm_err = 0 ;
2011-01-12 15:22:08 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
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 */
2011-01-12 15:22:08 +03:00
status = dcerpc_srvsvc_NetShareGetInfo ( b , mem_ctx ,
2008-04-19 23:56:43 +04:00
cli - > desthost ,
2008-03-08 00:55:33 +03:00
argv [ 1 ] ,
info_level ,
& info_get ,
& result ) ;
2011-01-12 15:22:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
result = ntstatus_to_werror ( status ) ;
goto done ;
}
if ( ! W_ERROR_IS_OK ( result ) ) {
2005-06-13 17:16:55 +04:00
goto done ;
2008-03-08 00:55:33 +03:00
}
2005-06-13 17:16:55 +04:00
2008-03-08 00:55:33 +03:00
info_get . info502 - > comment = argv [ 2 ] ;
2005-06-13 17:16:55 +04:00
2008-03-08 00:55:33 +03:00
/* set share info */
2011-01-12 15:22:08 +03:00
status = dcerpc_srvsvc_NetShareSetInfo ( b , mem_ctx ,
2008-04-19 23:56:43 +04:00
cli - > desthost ,
2008-03-08 00:55:33 +03:00
argv [ 1 ] ,
info_level ,
& info_get ,
& parm_err ,
& result ) ;
2011-01-12 15:22:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
result = ntstatus_to_werror ( status ) ;
goto done ;
}
if ( ! W_ERROR_IS_OK ( result ) ) {
2005-06-13 17:16:55 +04:00
goto done ;
2008-03-08 00:55:33 +03:00
}
2005-06-13 17:16:55 +04:00
/* re-retrieve share info and display */
2011-01-12 15:22:08 +03:00
status = dcerpc_srvsvc_NetShareGetInfo ( b , mem_ctx ,
2008-04-19 23:56:43 +04:00
cli - > desthost ,
2008-03-08 00:55:33 +03:00
argv [ 1 ] ,
info_level ,
& info_get ,
& result ) ;
2011-01-12 15:22:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
result = ntstatus_to_werror ( status ) ;
goto done ;
}
if ( ! W_ERROR_IS_OK ( result ) ) {
2005-06-13 17:16:55 +04:00
goto done ;
2008-03-08 00:55:33 +03:00
}
display_share_info_502 ( info_get . 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
{
2008-03-05 12:38:13 +03:00
struct srvsvc_NetRemoteTODInfo * tod = NULL ;
2007-10-11 00:34:30 +04:00
WERROR result ;
2008-03-05 12:38:13 +03:00
NTSTATUS status ;
2011-01-12 15:22:08 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
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
}
2011-01-12 15:22:08 +03:00
status = dcerpc_srvsvc_NetRemoteTOD ( b , mem_ctx ,
2008-04-20 01:03:16 +04:00
cli - > srv_name_slash ,
2008-03-05 12:38:13 +03:00
& tod ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
result = ntstatus_to_werror ( status ) ;
goto done ;
}
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
{
2015-05-09 17:33:08 +03:00
uint32_t info_level = 3 ;
2008-03-10 19:08:55 +03:00
struct srvsvc_NetFileInfoCtr info_ctr ;
struct srvsvc_NetFileCtr3 ctr3 ;
2007-10-11 00:34:30 +04:00
WERROR result ;
2008-03-10 19:08:55 +03:00
NTSTATUS status ;
2015-05-09 17:33:08 +03:00
uint32_t preferred_len = 0xffff ;
2008-03-10 19:08:55 +03:00
uint32_t total_entries = 0 ;
uint32_t resume_handle = 0 ;
2011-01-12 15:22:08 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
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 ] ) ;
2008-03-10 19:08:55 +03:00
ZERO_STRUCT ( info_ctr ) ;
ZERO_STRUCT ( ctr3 ) ;
2002-07-15 14:35:28 +04:00
2008-03-10 19:08:55 +03:00
info_ctr . level = info_level ;
info_ctr . ctr . ctr3 = & ctr3 ;
2011-01-12 15:22:08 +03:00
status = dcerpc_srvsvc_NetFileEnum ( b , mem_ctx ,
2008-04-19 23:56:43 +04:00
cli - > desthost ,
2008-03-10 19:08:55 +03:00
NULL ,
NULL ,
& info_ctr ,
preferred_len ,
& total_entries ,
& resume_handle ,
& result ) ;
2011-01-12 15:22:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
result = ntstatus_to_werror ( status ) ;
goto done ;
}
2008-03-10 19:08:55 +03:00
2011-01-12 15:22:08 +03:00
if ( ! W_ERROR_IS_OK ( result ) ) {
2002-07-15 14:35:28 +04:00
goto done ;
2011-01-12 15:22:08 +03:00
}
2002-07-15 14:35:28 +04:00
done :
2003-03-18 09:30:30 +03:00
return result ;
2002-07-15 14:35:28 +04:00
}
2008-03-08 01:39:34 +03:00
static WERROR cmd_srvsvc_net_name_validate ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
WERROR result ;
NTSTATUS status ;
uint32_t name_type = 9 ;
uint32_t flags = 0 ;
2011-01-12 15:22:08 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-03-08 01:39:34 +03:00
if ( argc < 2 | | argc > 3 ) {
printf ( " Usage: %s [sharename] [type] \n " , argv [ 0 ] ) ;
return WERR_OK ;
}
if ( argc = = 3 ) {
name_type = atoi ( argv [ 2 ] ) ;
}
2011-01-12 15:22:08 +03:00
status = dcerpc_srvsvc_NetNameValidate ( b , mem_ctx ,
2008-04-19 23:56:43 +04:00
cli - > desthost ,
2008-03-08 01:39:34 +03:00
argv [ 1 ] ,
name_type ,
flags ,
& result ) ;
2011-01-12 15:22:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
result = ntstatus_to_werror ( status ) ;
goto done ;
}
2008-03-08 01:39:34 +03:00
if ( ! W_ERROR_IS_OK ( result ) )
goto done ;
done :
return result ;
}
2008-03-09 01:00:09 +03:00
static WERROR cmd_srvsvc_net_file_get_sec ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
WERROR result ;
NTSTATUS status ;
struct sec_desc_buf * sd_buf = NULL ;
2011-01-12 15:22:08 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-03-09 01:00:09 +03:00
if ( argc < 2 | | argc > 4 ) {
printf ( " Usage: %s [sharename] [file] \n " , argv [ 0 ] ) ;
return WERR_OK ;
}
2011-01-12 15:22:08 +03:00
status = dcerpc_srvsvc_NetGetFileSecurity ( b , mem_ctx ,
2008-04-19 23:56:43 +04:00
cli - > desthost ,
2008-03-09 01:00:09 +03:00
argv [ 1 ] ,
argv [ 2 ] ,
SECINFO_DACL ,
& sd_buf ,
& result ) ;
2011-01-12 15:22:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
result = ntstatus_to_werror ( status ) ;
goto done ;
}
2008-03-09 01:00:09 +03:00
2011-01-12 15:22:08 +03:00
if ( ! W_ERROR_IS_OK ( result ) ) {
2008-03-09 01:00:09 +03:00
goto done ;
}
display_sec_desc ( sd_buf - > sd ) ;
done :
return result ;
}
2008-03-08 01:39:34 +03:00
2008-03-09 22:04:35 +03:00
static WERROR cmd_srvsvc_net_sess_del ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
WERROR result ;
NTSTATUS status ;
2011-01-12 15:22:08 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-03-09 22:04:35 +03:00
if ( argc < 2 | | argc > 4 ) {
printf ( " Usage: %s [client] [user] \n " , argv [ 0 ] ) ;
return WERR_OK ;
}
2011-01-12 15:22:08 +03:00
status = dcerpc_srvsvc_NetSessDel ( b , mem_ctx ,
2008-04-19 23:56:43 +04:00
cli - > desthost ,
2008-03-09 22:04:35 +03:00
argv [ 1 ] ,
argv [ 2 ] ,
& result ) ;
2011-01-12 15:22:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
result = ntstatus_to_werror ( status ) ;
goto done ;
}
2008-03-09 22:04:35 +03:00
2011-01-12 15:22:08 +03:00
if ( ! W_ERROR_IS_OK ( result ) ) {
2008-03-09 22:04:35 +03:00
goto done ;
}
done :
return result ;
}
2008-03-09 22:55:19 +03:00
static WERROR cmd_srvsvc_net_sess_enum ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
WERROR result ;
NTSTATUS status ;
struct srvsvc_NetSessInfoCtr info_ctr ;
struct srvsvc_NetSessCtr0 ctr0 ;
struct srvsvc_NetSessCtr1 ctr1 ;
struct srvsvc_NetSessCtr2 ctr2 ;
struct srvsvc_NetSessCtr10 ctr10 ;
struct srvsvc_NetSessCtr502 ctr502 ;
uint32_t total_entries = 0 ;
uint32_t resume_handle = 0 ;
2008-03-21 05:50:49 +03:00
uint32_t * resume_handle_p = NULL ;
2008-03-09 22:55:19 +03:00
uint32_t level = 1 ;
const char * client = NULL ;
const char * user = NULL ;
2011-01-12 15:22:08 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-03-09 22:55:19 +03:00
2008-03-21 05:50:49 +03:00
if ( argc > 6 ) {
printf ( " Usage: %s [client] [user] [level] [resume_handle] \n " , argv [ 0 ] ) ;
2008-03-09 22:55:19 +03:00
return WERR_OK ;
}
if ( argc > = 2 ) {
client = argv [ 1 ] ;
}
if ( argc > = 3 ) {
user = argv [ 2 ] ;
}
if ( argc > = 4 ) {
level = atoi ( argv [ 3 ] ) ;
}
2008-03-21 05:50:49 +03:00
if ( argc > = 5 ) {
resume_handle = atoi ( argv [ 4 ] ) ;
resume_handle_p = & resume_handle ;
}
2008-03-09 22:55:19 +03:00
ZERO_STRUCT ( info_ctr ) ;
info_ctr . level = level ;
d_printf ( " trying level: %d \n " , level ) ;
switch ( level ) {
case 0 :
ZERO_STRUCT ( ctr0 ) ;
info_ctr . ctr . ctr0 = & ctr0 ;
break ;
case 1 :
ZERO_STRUCT ( ctr1 ) ;
info_ctr . ctr . ctr1 = & ctr1 ;
break ;
case 2 :
ZERO_STRUCT ( ctr2 ) ;
info_ctr . ctr . ctr2 = & ctr2 ;
break ;
case 10 :
ZERO_STRUCT ( ctr10 ) ;
info_ctr . ctr . ctr10 = & ctr10 ;
break ;
case 502 :
ZERO_STRUCT ( ctr502 ) ;
info_ctr . ctr . ctr502 = & ctr502 ;
break ;
}
2011-01-12 15:22:08 +03:00
status = dcerpc_srvsvc_NetSessEnum ( b , mem_ctx ,
2008-04-19 23:56:43 +04:00
cli - > desthost ,
2008-03-09 22:55:19 +03:00
client ,
user ,
& info_ctr ,
0xffffffff ,
& total_entries ,
2008-03-21 05:50:49 +03:00
resume_handle_p ,
2008-03-09 22:55:19 +03:00
& result ) ;
2011-01-12 15:22:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
result = ntstatus_to_werror ( status ) ;
goto done ;
}
if ( ! W_ERROR_IS_OK ( result ) ) {
2008-03-09 22:55:19 +03:00
goto done ;
}
done :
return result ;
}
2008-03-10 19:30:22 +03:00
static WERROR cmd_srvsvc_net_disk_enum ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
struct srvsvc_NetDiskInfo info ;
WERROR result ;
NTSTATUS status ;
uint32_t total_entries = 0 ;
uint32_t resume_handle = 0 ;
uint32_t level = 0 ;
2011-01-12 15:22:08 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-03-10 19:30:22 +03:00
2008-03-11 06:52:46 +03:00
if ( argc > 4 ) {
2008-03-10 19:30:22 +03:00
printf ( " Usage: %s [level] [resume_handle] \n " , argv [ 0 ] ) ;
return WERR_OK ;
}
if ( argc > = 2 ) {
level = atoi ( argv [ 1 ] ) ;
}
2008-03-09 22:55:19 +03:00
2008-03-10 19:30:22 +03:00
if ( argc > = 3 ) {
resume_handle = atoi ( argv [ 2 ] ) ;
}
ZERO_STRUCT ( info ) ;
2011-01-12 15:22:08 +03:00
status = dcerpc_srvsvc_NetDiskEnum ( b , mem_ctx ,
2008-04-19 23:56:43 +04:00
cli - > desthost ,
2008-03-10 19:30:22 +03:00
level ,
& info ,
0xffffffff ,
& total_entries ,
& resume_handle ,
& result ) ;
2011-01-12 15:22:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
result = ntstatus_to_werror ( status ) ;
goto done ;
}
2008-03-10 19:30:22 +03:00
2011-01-12 15:22:08 +03:00
if ( ! W_ERROR_IS_OK ( result ) ) {
2008-03-10 19:30:22 +03:00
goto done ;
}
done :
return result ;
}
2008-03-09 22:04:35 +03:00
2008-03-10 20:34:50 +03:00
static WERROR cmd_srvsvc_net_conn_enum ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
struct srvsvc_NetConnInfoCtr info_ctr ;
struct srvsvc_NetConnCtr0 ctr0 ;
struct srvsvc_NetConnCtr1 ctr1 ;
WERROR result ;
NTSTATUS status ;
uint32_t total_entries = 0 ;
uint32_t resume_handle = 0 ;
2008-03-21 03:14:23 +03:00
uint32_t * resume_handle_p = NULL ;
2008-03-10 20:34:50 +03:00
uint32_t level = 1 ;
const char * path = " IPC$ " ;
2011-01-12 15:22:08 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-03-10 20:34:50 +03:00
if ( argc > 4 ) {
printf ( " Usage: %s [level] [path] [resume_handle] \n " , argv [ 0 ] ) ;
return WERR_OK ;
}
if ( argc > = 2 ) {
level = atoi ( argv [ 1 ] ) ;
}
if ( argc > = 3 ) {
path = argv [ 2 ] ;
}
if ( argc > = 4 ) {
resume_handle = atoi ( argv [ 3 ] ) ;
2008-03-21 03:14:23 +03:00
resume_handle_p = & resume_handle ;
2008-03-10 20:34:50 +03:00
}
ZERO_STRUCT ( info_ctr ) ;
info_ctr . level = level ;
switch ( level ) {
case 0 :
ZERO_STRUCT ( ctr0 ) ;
info_ctr . ctr . ctr0 = & ctr0 ;
break ;
case 1 :
ZERO_STRUCT ( ctr1 ) ;
info_ctr . ctr . ctr1 = & ctr1 ;
break ;
default :
return WERR_INVALID_PARAM ;
}
2011-01-12 15:22:08 +03:00
status = dcerpc_srvsvc_NetConnEnum ( b , mem_ctx ,
2008-04-19 23:56:43 +04:00
cli - > desthost ,
2008-03-10 20:34:50 +03:00
path ,
& info_ctr ,
0xffffffff ,
& total_entries ,
2008-03-21 03:14:23 +03:00
resume_handle_p ,
2008-03-10 20:34:50 +03:00
& result ) ;
2011-01-12 15:22:08 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
result = ntstatus_to_werror ( status ) ;
goto done ;
}
if ( ! W_ERROR_IS_OK ( result ) ) {
2008-03-10 20:34:50 +03:00
goto done ;
}
done :
return result ;
}
2015-06-11 21:53:43 +03:00
static WERROR cmd_srvsvc_net_share_add ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
struct srvsvc_NetShareInfo502 info502 = { 0 } ;
union srvsvc_NetShareInfo info = { . info502 = & info502 } ;
WERROR result ;
NTSTATUS status ;
uint32_t max_users = - 1 , parm_error ;
struct sec_desc_buf sd_buf = { 0 } ;
const char * path , * share_name , * comment = NULL ;
struct dcerpc_binding_handle * b = cli - > binding_handle ;
if ( argc < 3 | | argc > 5 ) {
printf ( " Usage: %s path share_name [max_users] [comment] \n " ,
argv [ 0 ] ) ;
return WERR_OK ;
}
path = argv [ 1 ] ;
share_name = argv [ 2 ] ;
if ( argc > = 4 ) {
max_users = atoi ( argv [ 3 ] ) ;
}
if ( argc > = 5 ) {
comment = argv [ 4 ] ;
}
info . info502 - > name = share_name ;
info . info502 - > type = STYPE_DISKTREE ;
info . info502 - > comment = comment ;
info . info502 - > max_users = max_users ;
info . info502 - > path = path ;
info . info502 - > sd_buf = sd_buf ;
status = dcerpc_srvsvc_NetShareAdd ( b , mem_ctx , cli - > desthost ,
502 , & info , & parm_error , & result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
result = ntstatus_to_werror ( status ) ;
}
return result ;
}
2008-03-10 20:34:50 +03:00
2015-06-11 22:06:33 +03:00
static WERROR cmd_srvsvc_net_share_del ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
const char * share_name ;
WERROR result ;
NTSTATUS status ;
struct dcerpc_binding_handle * b = cli - > binding_handle ;
if ( argc < 2 ) {
printf ( " Usage: %s share_name \n " , argv [ 0 ] ) ;
return WERR_OK ;
}
share_name = argv [ 1 ] ;
status = dcerpc_srvsvc_NetShareDel ( b , mem_ctx , cli - > desthost ,
share_name , 0 , & result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
result = ntstatus_to_werror ( status ) ;
}
return result ;
}
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 " } ,
2012-01-10 14:53:42 +04:00
{ " srvinfo " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_srv_query_info , & ndr_table_srvsvc , NULL , " Server query info " , " " } ,
{ " netshareenum " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_share_enum , & ndr_table_srvsvc , NULL , " Enumerate shares " , " " } ,
{ " netshareenumall " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_share_enum_all , & ndr_table_srvsvc , NULL , " Enumerate all shares " , " " } ,
{ " netsharegetinfo " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_share_get_info , & ndr_table_srvsvc , NULL , " Get Share Info " , " " } ,
{ " netsharesetinfo " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_share_set_info , & ndr_table_srvsvc , NULL , " Set Share Info " , " " } ,
{ " netfileenum " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_file_enum , & ndr_table_srvsvc , NULL , " Enumerate open files " , " " } ,
{ " netremotetod " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_remote_tod , & ndr_table_srvsvc , NULL , " Fetch remote time of day " , " " } ,
{ " netnamevalidate " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_name_validate , & ndr_table_srvsvc , NULL , " Validate sharename " , " " } ,
{ " netfilegetsec " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_file_get_sec , & ndr_table_srvsvc , NULL , " Get File security " , " " } ,
{ " netsessdel " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_sess_del , & ndr_table_srvsvc , NULL , " Delete Session " , " " } ,
{ " netsessenum " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_sess_enum , & ndr_table_srvsvc , NULL , " Enumerate Sessions " , " " } ,
{ " netdiskenum " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_disk_enum , & ndr_table_srvsvc , NULL , " Enumerate Disks " , " " } ,
{ " netconnenum " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_conn_enum , & ndr_table_srvsvc , NULL , " Enumerate Connections " , " " } ,
2015-06-11 21:53:43 +03:00
{ " netshareadd " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_share_add , & ndr_table_srvsvc , NULL , " Add share " , " " } ,
2015-06-11 22:06:33 +03:00
{ " netsharedel " , RPC_RTYPE_WERROR , NULL , cmd_srvsvc_net_share_del , & ndr_table_srvsvc , NULL , " Delete share " , " " } ,
2001-07-20 08:38:58 +04:00
{ NULL }
2001-05-24 04:20:32 +04:00
} ;