2009-01-06 21:09:57 +03:00
/*
Unix SMB / CIFS implementation .
RPC pipe client
Copyright ( C ) Volker Lendecke 2009
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
the Free Software Foundation ; either version 3 of the License , or
( 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
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
# include "rpcclient.h"
2011-01-28 12:31:39 +03:00
# include "../librpc/gen_ndr/ndr_epmapper_c.h"
2010-05-05 03:39:16 +04:00
# include "../librpc/gen_ndr/ndr_lsa.h"
2009-01-06 21:09:57 +03:00
static NTSTATUS cmd_epmapper_map ( struct rpc_pipe_client * p ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
2011-01-04 15:33:46 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2014-01-31 01:05:51 +04:00
struct dcerpc_binding * map_binding ;
2009-01-06 21:09:57 +03:00
struct epm_twr_t map_tower ;
2011-01-04 23:24:17 +03:00
struct epm_twr_p_t towers [ 500 ] ;
2009-01-06 21:09:57 +03:00
struct policy_handle entry_handle ;
struct ndr_syntax_id abstract_syntax ;
uint32_t num_towers ;
TALLOC_CTX * tmp_ctx = talloc_stackframe ( ) ;
NTSTATUS status ;
2011-01-04 15:33:46 +03:00
uint32_t result ;
2011-01-04 23:24:17 +03:00
uint32_t i ;
2009-01-06 21:09:57 +03:00
abstract_syntax = ndr_table_lsarpc . syntax_id ;
2014-01-31 01:05:51 +04:00
/* 127.0.0.1[0] => correct? needed? */
status = dcerpc_parse_binding ( tmp_ctx , " ncacn_np:127.0.0.1[0] " ,
& map_binding ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_fprintf ( stderr , " dcerpc_parse_binding returned %s \n " ,
nt_errstr ( status ) ) ;
goto done ;
}
2009-01-06 21:09:57 +03:00
2014-01-31 01:05:51 +04:00
status = dcerpc_binding_set_abstract_syntax ( map_binding ,
& abstract_syntax ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_fprintf ( stderr , " dcerpc_binding_set_abstract_syntax returned %s \n " ,
nt_errstr ( status ) ) ;
goto done ;
}
2014-01-31 01:05:51 +04:00
status = dcerpc_binding_build_tower ( tmp_ctx , map_binding ,
2009-01-06 21:09:57 +03:00
& map_tower . tower ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_fprintf ( stderr , " dcerpc_binding_build_tower returned %s \n " ,
nt_errstr ( status ) ) ;
2013-11-01 11:59:53 +04:00
goto done ;
2009-01-06 21:09:57 +03:00
}
2011-01-04 23:24:17 +03:00
ZERO_STRUCT ( towers ) ;
2009-01-06 21:09:57 +03:00
ZERO_STRUCT ( entry_handle ) ;
2011-01-04 23:24:17 +03:00
2011-01-04 15:33:46 +03:00
status = dcerpc_epm_Map (
b , tmp_ctx , & abstract_syntax . uuid ,
2011-01-04 23:24:17 +03:00
& map_tower , & entry_handle , ARRAY_SIZE ( towers ) ,
& num_towers , towers , & result ) ;
2011-01-04 15:33:46 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_fprintf ( stderr , " dcerpc_epm_Map returned %s \n " ,
nt_errstr ( status ) ) ;
2013-11-01 11:59:53 +04:00
goto done ;
2011-01-04 15:33:46 +03:00
}
2009-01-06 21:09:57 +03:00
2011-01-04 15:33:46 +03:00
if ( result ! = EPMAPPER_STATUS_OK ) {
d_fprintf ( stderr , " epm_Map returned %u (0x%08X) \n " ,
result , result ) ;
2013-11-01 11:59:53 +04:00
status = NT_STATUS_UNSUCCESSFUL ;
goto done ;
2011-01-04 15:33:46 +03:00
}
2011-01-04 23:24:17 +03:00
d_printf ( " num_tower[%u] \n " , num_towers ) ;
for ( i = 0 ; i < num_towers ; i + + ) {
struct dcerpc_binding * binding ;
if ( towers [ i ] . twr = = NULL ) {
d_fprintf ( stderr , " tower[%u] NULL \n " , i ) ;
break ;
}
status = dcerpc_binding_from_tower ( tmp_ctx , & towers [ i ] . twr - > tower ,
& binding ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
break ;
}
d_printf ( " tower[%u] %s \n " , i , dcerpc_binding_string ( tmp_ctx , binding ) ) ;
}
2013-11-01 11:59:53 +04:00
done :
TALLOC_FREE ( tmp_ctx ) ;
return status ;
2009-01-06 21:09:57 +03:00
}
static NTSTATUS cmd_epmapper_lookup ( struct rpc_pipe_client * p ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
2011-01-04 15:33:46 +03:00
struct dcerpc_binding_handle * b = p - > binding_handle ;
2009-01-06 21:09:57 +03:00
struct policy_handle entry_handle ;
ZERO_STRUCT ( entry_handle ) ;
while ( true ) {
TALLOC_CTX * tmp_ctx = talloc_new ( mem_ctx ) ;
uint32_t num_entries ;
struct epm_entry_t entry ;
NTSTATUS status ;
char * guid_string ;
struct dcerpc_binding * binding ;
2011-01-04 15:33:46 +03:00
uint32_t result ;
2009-01-06 21:09:57 +03:00
2011-01-04 15:33:46 +03:00
status = dcerpc_epm_Lookup ( b , tmp_ctx ,
2009-01-06 21:09:57 +03:00
0 , /* rpc_c_ep_all */
NULL ,
NULL ,
0 , /* rpc_c_vers_all */
& entry_handle ,
1 , /* max_ents */
2011-01-04 15:33:46 +03:00
& num_entries , & entry ,
& result ) ;
2009-01-06 21:09:57 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-01-04 15:33:46 +03:00
d_fprintf ( stderr , " dcerpc_epm_Lookup returned %s \n " ,
2009-01-06 21:09:57 +03:00
nt_errstr ( status ) ) ;
break ;
}
2011-01-04 15:33:46 +03:00
if ( result = = EPMAPPER_STATUS_NO_MORE_ENTRIES ) {
d_fprintf ( stderr , " epm_Lookup no more entries \n " ) ;
break ;
}
if ( result ! = EPMAPPER_STATUS_OK ) {
d_fprintf ( stderr , " epm_Lookup returned %u (0x%08X) \n " ,
result , result ) ;
break ;
}
2009-01-06 21:09:57 +03:00
if ( num_entries ! = 1 ) {
2011-01-04 15:33:46 +03:00
d_fprintf ( stderr , " epm_Lookup returned %d "
2009-01-06 21:09:57 +03:00
" entries, expected one \n " , ( int ) num_entries ) ;
break ;
}
guid_string = GUID_string ( tmp_ctx , & entry . object ) ;
if ( guid_string = = NULL ) {
break ;
}
status = dcerpc_binding_from_tower ( tmp_ctx , & entry . tower - > tower ,
& binding ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
break ;
}
d_printf ( " %s %s: %s \n " , guid_string ,
dcerpc_binding_string ( tmp_ctx , binding ) ,
entry . annotation ) ;
TALLOC_FREE ( tmp_ctx ) ;
}
return NT_STATUS_OK ;
}
/* List of commands exported by this module */
struct cmd_set epmapper_commands [ ] = {
{ " EPMAPPER " } ,
{ " epmmap " , RPC_RTYPE_NTSTATUS , cmd_epmapper_map , NULL ,
2012-01-10 14:53:42 +04:00
& ndr_table_epmapper , NULL , " Map a binding " , " " } ,
2009-01-06 21:09:57 +03:00
{ " epmlookup " , RPC_RTYPE_NTSTATUS , cmd_epmapper_lookup , NULL ,
2012-01-10 14:53:42 +04:00
& ndr_table_epmapper , NULL , " Lookup bindings " , " " } ,
2009-01-06 21:09:57 +03:00
{ NULL }
} ;