0001-01-01 02:30:17 +02:30
/*
Unix SMB / Netbios implementation .
Version 1.9 .
NT Domain Authentication SMB / MSRPC client
0001-01-01 02:30:17 +02:30
Copyright ( C ) Andrew Tridgell 1994 - 1997
Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1997
0001-01-01 02:30:17 +02:30
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 2 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 , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
0001-01-01 02:30:17 +02:30
extern FILE * out_hnd ;
/* Convert SID_NAME_USE values to strings */
struct sid_name {
enum SID_NAME_USE name_type ;
char * name ;
} sid_name_type_str [ ] = {
{ SID_NAME_UNKNOWN , " UNKNOWN " } ,
{ SID_NAME_USER , " User " } ,
{ SID_NAME_DOM_GRP , " Domain Group " } ,
{ SID_NAME_DOMAIN , " Domain " } ,
{ SID_NAME_ALIAS , " Local Group " } ,
{ SID_NAME_WKN_GRP , " Well-known Group " } ,
{ SID_NAME_DELETED , " Deleted " } ,
{ SID_NAME_INVALID , " Invalid " } ,
{ 0 , NULL }
} ;
static char * get_sid_name_type_str ( enum SID_NAME_USE name_type )
{
int i = 0 ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
while ( sid_name_type_str [ i ] . name ) {
if ( name_type = = sid_name_type_str [ i ] . name_type ) {
return sid_name_type_str [ i ] . name ;
}
i + + ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
return NULL ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* Look up a list of sids */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
uint32 cmd_lsa_lookup_sids ( struct client_info * info , int argc , char * argv [ ] )
0001-01-01 02:30:17 +02:30
{
0001-01-01 02:30:17 +02:30
POLICY_HND lsa_pol ;
0001-01-01 02:30:17 +02:30
fstring srv_name ;
0001-01-01 02:30:17 +02:30
char * * names ;
DOM_SID * sids ;
int num_sids = 0 , num_names , i ;
uint32 * types , result ;
/* Check command arguments */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( argc = = 1 ) {
fprintf ( out_hnd , " lsa_lookupsids sid1 [sid2...] \n " ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
sids = ( DOM_SID * ) malloc ( ( argc - 1 ) * sizeof ( DOM_SID ) ) ;
for ( i = 1 ; i < argc ; i + + ) {
if ( string_to_sid ( & sids [ num_sids ] , argv [ i ] ) ) {
num_sids + + ;
} else {
fprintf ( out_hnd , " could not parse sid %s \n " , argv [ i ] ) ;
}
}
0001-01-01 02:30:17 +02:30
fstrcpy ( srv_name , " \\ \\ " ) ;
0001-01-01 02:30:17 +02:30
fstrcat ( srv_name , info - > dest_host ) ;
0001-01-01 02:30:17 +02:30
strupper ( srv_name ) ;
0001-01-01 02:30:17 +02:30
/* Lookup domain controller; receive a policy handle */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
result = lsa_open_policy ( srv_name , & lsa_pol , True ,
SEC_RIGHTS_MAXIMUM_ALLOWED ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( result ! = 0 ) {
report ( out_hnd , " open policy failed: %s \n " ,
get_nt_error_msg ( result ) ) ;
return result ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* Send lsa lookup sids call */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
result = lsa_lookup_sids ( & lsa_pol , num_sids , sids , & names ,
& types , & num_names ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( result ! = 0 ) {
report ( out_hnd , " lookup names failed: %s \n " ,
get_nt_error_msg ( result ) ) ;
return result ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
result = lsa_close ( & lsa_pol ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( result ! = 0 ) {
report ( out_hnd , " lsa close failed: %s \n " ,
get_nt_error_msg ( result ) ) ;
return result ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* Print output */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( names ! = NULL ) {
report ( out_hnd , " Lookup SIDS: \n " ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
for ( i = 0 ; i < num_names ; i + + ) {
fstring temp ;
sid_to_string ( temp , & sids [ i ] ) ;
report ( out_hnd , " SID: %s -> %s (%d: %s) \n " ,
temp , names [ i ] ? names [ i ] : " (null) " ,
types [ i ] , get_sid_name_type_str ( types [ i ] ) ) ;
if ( names [ i ] ! = NULL ) {
free ( names [ i ] ) ;
}
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
free ( names ) ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
if ( types ) {
free ( types ) ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
return result ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/* Look up a list of names */
uint32 cmd_lsa_lookup_names ( struct client_info * info , int argc , char * argv [ ] )
0001-01-01 02:30:17 +02:30
{
0001-01-01 02:30:17 +02:30
POLICY_HND lsa_pol ;
0001-01-01 02:30:17 +02:30
fstring srv_name ;
0001-01-01 02:30:17 +02:30
int num_names , i , num_sids ;
DOM_SID * sids ;
char * * names ;
uint32 * types , result ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* Check command arguments */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( argc = = 1 ) {
fprintf ( out_hnd , " lsa_lookupnames name1 [name2...] \n " ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
names = ( char * * ) malloc ( ( argc - 1 ) * sizeof ( char * ) ) ;
num_names = argc - 1 ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
for ( i = 1 ; i < argc ; i + + ) {
names [ i - 1 ] = argv [ i ] ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
fstrcpy ( srv_name , " \\ \\ " ) ;
fstrcat ( srv_name , info - > dest_host ) ;
strupper ( srv_name ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* Lookup domain controller; receive a policy handle */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
result = lsa_open_policy ( srv_name , & lsa_pol , True ,
SEC_RIGHTS_MAXIMUM_ALLOWED ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( result ! = 0 ) {
report ( out_hnd , " open policy failed: %s \n " ,
get_nt_error_msg ( result ) ) ;
return result ;
}
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
/* Send lsa lookup names call */
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
result = lsa_lookup_names ( & lsa_pol , num_names , names , & sids ,
& types , & num_sids ) ;
0001-01-01 02:30:17 +02:30
0001-01-01 02:30:17 +02:30
if ( result ! = 0 ) {
report ( out_hnd , " lookup sids failed: %s \n " ,
get_nt_error_msg ( result ) ) ;
return result ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
result = lsa_close ( & lsa_pol ) ;
if ( result ! = 0 ) {
report ( out_hnd , " lsa close failed: %s \n " ,
get_nt_error_msg ( result ) ) ;
return result ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/* Print output */
if ( sids ! = NULL ) {
fstring temp ;
report ( out_hnd , " Lookup Names: \n " ) ;
for ( i = 0 ; i < num_sids ; i + + ) {
sid_to_string ( temp , & sids [ i ] ) ;
report ( out_hnd , " Name: %s -> %s (%d: %s) \n " ,
names [ i ] , temp , types [ i ] ,
get_sid_name_type_str ( types [ i ] ) ) ;
#if 0
if ( sids [ i ] ! = NULL ) {
free ( sids [ i ] ) ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
# endif
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
free ( sids ) ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
return result ;
0001-01-01 02:30:17 +02:30
}
0001-01-01 02:30:17 +02:30
/* rpcclient interface */
static const struct command_set lsa_commands [ ] = {
{ " LSARPC " , NULL , NULL , { NULL , NULL } } ,
{ " lsa_lookup_sids " , cmd_lsa_lookup_sids } ,
{ " lsa_lookup_names " , cmd_lsa_lookup_names } ,
{ " " , NULL , NULL , { NULL , NULL } }
} ;
void add_lsa_commands ( void )
{
add_command_set ( lsa_commands ) ;
}