2007-12-03 14:42:17 +03:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2007-12-03 14:42:17 +03:00
RPC pipe client
Copyright ( C ) Günther Deschner 2007
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 .
2007-12-03 14:42:17 +03:00
1998-09-26 01:01:52 +04: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 .
2007-12-03 14:42:17 +03:00
1998-09-26 01:01:52 +04: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/>.
1998-09-26 01:01:52 +04:00
*/
# include "includes.h"
2007-12-03 14:42:17 +03:00
# include "rpcclient.h"
2011-01-11 18:03:24 +03:00
# include "../librpc/gen_ndr/ndr_wkssvc_c.h"
1998-09-26 01:01:52 +04:00
2007-12-03 14:42:17 +03:00
static WERROR cmd_wkssvc_wkstagetinfo ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
1998-09-26 01:01:52 +04:00
{
2007-12-03 14:42:17 +03:00
NTSTATUS status ;
2007-12-03 20:40:09 +03:00
WERROR werr ;
2007-12-03 14:42:17 +03:00
uint32_t level = 100 ;
union wkssvc_NetWkstaInfo info ;
const char * server_name ;
2011-01-11 18:03:24 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2007-12-03 14:42:17 +03:00
2007-12-06 21:05:54 +03:00
if ( argc > 2 ) {
printf ( " usage: %s <level> \n " , argv [ 0 ] ) ;
return WERR_OK ;
}
if ( argc > 1 ) {
level = atoi ( argv [ 1 ] ) ;
}
2008-04-19 23:56:43 +04:00
server_name = cli - > desthost ;
2007-12-03 14:42:17 +03:00
2011-01-11 18:03:24 +03:00
status = dcerpc_wkssvc_NetWkstaGetInfo ( b , mem_ctx ,
2007-12-03 14:42:17 +03:00
server_name ,
level ,
2007-12-03 20:40:09 +03:00
& info ,
& werr ) ;
2007-12-03 14:42:17 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return ntstatus_to_werror ( status ) ;
1998-09-26 01:01:52 +04:00
}
2007-12-03 20:40:09 +03:00
return werr ;
2007-12-03 14:42:17 +03:00
}
1998-09-26 01:01:52 +04:00
2007-12-03 15:12:26 +03:00
static WERROR cmd_wkssvc_getjoininformation ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
{
const char * server_name ;
const char * name_buffer ;
enum wkssvc_NetJoinStatus name_type ;
NTSTATUS status ;
2007-12-04 00:12:31 +03:00
WERROR werr ;
2011-01-11 18:03:24 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2007-12-03 15:12:26 +03:00
2008-04-19 23:56:43 +04:00
server_name = cli - > desthost ;
2007-12-03 15:12:26 +03:00
name_buffer = " " ;
2011-01-11 18:03:24 +03:00
status = dcerpc_wkssvc_NetrGetJoinInformation ( b , mem_ctx ,
2007-12-04 00:12:31 +03:00
server_name ,
& name_buffer ,
& name_type ,
& werr ) ;
2007-12-03 15:12:26 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return ntstatus_to_werror ( status ) ;
}
2007-12-04 00:12:31 +03:00
if ( W_ERROR_IS_OK ( werr ) ) {
printf ( " %s (%d) \n " , name_buffer , name_type ) ;
}
2007-12-03 15:12:26 +03:00
2007-12-04 00:12:31 +03:00
return werr ;
2007-12-03 15:12:26 +03:00
}
2007-12-06 21:06:30 +03:00
static WERROR cmd_wkssvc_messagebuffersend ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
{
2008-04-19 23:56:43 +04:00
const char * server_name = cli - > desthost ;
const char * message_name = cli - > desthost ;
const char * message_sender_name = cli - > desthost ;
2007-12-06 21:06:30 +03:00
smb_ucs2_t * message_buffer = NULL ;
size_t message_size = 0 ;
2007-12-07 13:56:48 +03:00
const char * message = " my message " ;
2007-12-06 21:06:30 +03:00
NTSTATUS status ;
WERROR werr ;
2011-01-11 18:03:24 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2007-12-06 21:06:30 +03:00
2007-12-07 13:56:48 +03:00
if ( argc > 1 ) {
message = argv [ 1 ] ;
}
2008-04-30 01:36:24 +04:00
if ( ! push_ucs2_talloc ( mem_ctx , & message_buffer , message ,
& message_size ) )
{
2015-12-03 17:24:16 +03:00
return WERR_NOT_ENOUGH_MEMORY ;
2007-12-06 21:06:30 +03:00
}
2011-01-11 18:03:24 +03:00
status = dcerpc_wkssvc_NetrMessageBufferSend ( b , mem_ctx ,
2007-12-06 21:06:30 +03:00
server_name ,
message_name ,
message_sender_name ,
( uint8_t * ) message_buffer ,
message_size ,
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return ntstatus_to_werror ( status ) ;
}
return werr ;
}
2007-12-19 13:08:27 +03:00
static WERROR cmd_wkssvc_enumeratecomputernames ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
{
const char * server_name ;
enum wkssvc_ComputerNameType name_type = NetAllComputerNames ;
NTSTATUS status ;
struct wkssvc_ComputerNamesCtr * ctr = NULL ;
WERROR werr ;
2011-01-11 18:03:24 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2007-12-19 13:08:27 +03:00
2008-04-19 23:56:43 +04:00
server_name = cli - > desthost ;
2007-12-19 13:08:27 +03:00
if ( argc > = 2 ) {
name_type = atoi ( argv [ 1 ] ) ;
}
2011-01-11 18:03:24 +03:00
status = dcerpc_wkssvc_NetrEnumerateComputerNames ( b , mem_ctx ,
2007-12-19 13:08:27 +03:00
server_name ,
name_type , 0 ,
& ctr ,
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return ntstatus_to_werror ( status ) ;
}
if ( W_ERROR_IS_OK ( werr ) ) {
int i = 0 ;
for ( i = 0 ; i < ctr - > count ; i + + ) {
printf ( " name: %d %s \n " , i , ctr - > computer_name - > string ) ;
}
}
return werr ;
}
2009-12-06 14:40:44 +03:00
static WERROR cmd_wkssvc_enumerateusers ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
{
const char * server_name ;
NTSTATUS status ;
struct wkssvc_NetWkstaEnumUsersInfo info ;
WERROR werr ;
uint32_t i , num_entries , resume_handle ;
2011-01-11 18:03:24 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2009-12-06 14:40:44 +03:00
server_name = cli - > desthost ;
ZERO_STRUCT ( info ) ;
if ( argc > = 2 ) {
info . level = atoi ( argv [ 1 ] ) ;
}
2011-01-11 18:03:24 +03:00
status = dcerpc_wkssvc_NetWkstaEnumUsers ( b , mem_ctx , server_name ,
2009-12-06 14:40:44 +03:00
& info , 1000 , & num_entries ,
& resume_handle , & werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return ntstatus_to_werror ( status ) ;
}
if ( ! W_ERROR_IS_OK ( werr ) ) {
return werr ;
}
for ( i = 0 ; i < num_entries ; i + + ) {
2010-02-17 17:15:47 +03:00
const char * user = NULL ;
2009-12-06 14:40:44 +03:00
switch ( info . level ) {
case 0 :
user = info . ctr . user0 - > user0 [ i ] . user_name ;
break ;
case 1 :
user = talloc_asprintf (
talloc_tos ( ) , " %s \\ %s " ,
info . ctr . user1 - > user1 [ i ] . logon_domain ,
info . ctr . user1 - > user1 [ i ] . user_name ) ;
break ;
}
2010-02-17 17:15:47 +03:00
printf ( " %s \n " , user ? user : " (null) " ) ;
2009-12-06 14:40:44 +03:00
}
return werr ;
}
2007-12-03 14:42:17 +03:00
struct cmd_set wkssvc_commands [ ] = {
1998-09-26 01:01:52 +04:00
2019-01-09 17:14:05 +03:00
{
. name = " WKSSVC " ,
} ,
{
. name = " wkssvc_wkstagetinfo " ,
. returntype = RPC_RTYPE_WERROR ,
. ntfn = NULL ,
. wfn = cmd_wkssvc_wkstagetinfo ,
. table = & ndr_table_wkssvc ,
. rpc_pipe = NULL ,
. description = " Query WKSSVC Workstation Information " ,
. usage = " " ,
} ,
{
. name = " wkssvc_getjoininformation " ,
. returntype = RPC_RTYPE_WERROR ,
. ntfn = NULL ,
. wfn = cmd_wkssvc_getjoininformation ,
. table = & ndr_table_wkssvc ,
. rpc_pipe = NULL ,
. description = " Query WKSSVC Join Information " ,
. usage = " " ,
} ,
{
. name = " wkssvc_messagebuffersend " ,
. returntype = RPC_RTYPE_WERROR ,
. ntfn = NULL ,
. wfn = cmd_wkssvc_messagebuffersend ,
. table = & ndr_table_wkssvc ,
. rpc_pipe = NULL ,
. description = " Send WKSSVC message " ,
. usage = " " ,
} ,
{
. name = " wkssvc_enumeratecomputernames " ,
. returntype = RPC_RTYPE_WERROR ,
. ntfn = NULL ,
. wfn = cmd_wkssvc_enumeratecomputernames ,
. table = & ndr_table_wkssvc ,
. rpc_pipe = NULL ,
. description = " Enumerate WKSSVC computer names " ,
. usage = " " ,
} ,
{
. name = " wkssvc_enumerateusers " ,
. returntype = RPC_RTYPE_WERROR ,
. ntfn = NULL ,
. wfn = cmd_wkssvc_enumerateusers ,
. table = & ndr_table_wkssvc ,
. rpc_pipe = NULL ,
. description = " Enumerate WKSSVC users " ,
. usage = " " ,
} ,
{
. name = NULL ,
} ,
2007-12-03 14:42:17 +03:00
} ;