2003-01-15 16:10:57 +00:00
/*
2002-01-30 06:08:46 +00:00
Unix SMB / CIFS implementation .
2001-01-11 22:49:30 +00:00
RPC pipe client
2002-07-15 10:35:28 +00:00
Copyright ( C ) Tim Potter 2000
Copyright ( C ) Rafal Szczesniak 2002
2008-02-27 19:38:48 +01:00
Copyright ( C ) Guenther Deschner 2008
2001-01-11 22:49:30 +00:00
1998-09-25 21:01:52 +00: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 19:25:36 +00:00
the Free Software Foundation ; either version 3 of the License , or
1998-09-25 21:01:52 +00:00
( at your option ) any later version .
2010-01-23 13:33:10 +01:00
1998-09-25 21:01:52 +00: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 .
2010-01-23 13:33:10 +01:00
1998-09-25 21:01:52 +00:00
You should have received a copy of the GNU General Public License
2007-07-10 00:52:41 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
1998-09-25 21:01:52 +00:00
*/
# include "includes.h"
2001-10-12 05:56:23 +00:00
# include "rpcclient.h"
2009-03-16 21:27:58 +11:00
# include "../libcli/auth/libcli_auth.h"
2010-08-06 14:52:58 +02:00
# include "../librpc/gen_ndr/ndr_lsa.h"
2011-01-18 16:08:05 +01:00
# include "../librpc/gen_ndr/ndr_lsa_c.h"
2010-05-18 18:26:16 +02:00
# include "rpc_client/cli_lsarpc.h"
2010-08-19 23:15:22 +02:00
# include "rpc_client/init_lsa.h"
2010-10-12 15:27:50 +11:00
# include "../libcli/security/security.h"
2000-12-08 03:34:00 +00:00
2003-01-28 21:09:56 +00:00
/* useful function to allow entering a name instead of a SID and
* looking it up automatically */
2023-08-31 15:39:51 +02:00
static NTSTATUS name_to_sid ( struct rpc_pipe_client * cli ,
2003-01-29 02:24:12 +00:00
TALLOC_CTX * mem_ctx ,
2023-08-31 15:39:51 +02:00
struct dom_sid * sid ,
const char * name )
2003-01-28 21:09:56 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle pol ;
2006-09-08 14:28:06 +00:00
enum lsa_SidType * sid_types ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2010-05-21 11:25:01 +10:00
struct dom_sid * sids ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2003-01-28 21:09:56 +00:00
/* maybe its a raw SID */
if ( strncmp ( name , " S- " , 2 ) = = 0 & &
2003-01-29 02:24:12 +00:00
string_to_sid ( sid , name ) ) {
2003-01-28 21:09:56 +00:00
return NT_STATUS_OK ;
}
2011-01-18 15:42:47 +01:00
status = rpccli_lsa_open_policy ( cli , mem_ctx , True ,
2009-04-15 01:12:13 +02:00
SEC_FLAG_MAXIMUM_ALLOWED ,
2003-01-29 02:24:12 +00:00
& pol ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2003-01-28 21:09:56 +00:00
goto done ;
2011-01-18 15:42:47 +01:00
status = rpccli_lsa_lookup_names ( cli , mem_ctx , & pol , 1 , & name , NULL , 1 , & sids , & sid_types ) ;
if ( ! NT_STATUS_IS_OK ( status ) )
2003-01-28 21:09:56 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
2003-01-28 21:09:56 +00:00
* sid = sids [ 0 ] ;
done :
2011-01-18 15:42:47 +01:00
return status ;
2003-01-28 21:09:56 +00:00
}
2008-02-08 01:38:44 +01:00
static void display_query_info_1 ( struct lsa_AuditLogInfo * r )
2006-04-11 15:47:24 +00:00
{
2008-02-08 01:38:44 +01:00
d_printf ( " percent_full: \t %d \n " , r - > percent_full ) ;
2008-10-20 22:06:58 +02:00
d_printf ( " maximum_log_size: \t %d \n " , r - > maximum_log_size ) ;
2008-02-08 01:38:44 +01:00
d_printf ( " retention_time: \t %lld \n " , ( long long ) r - > retention_time ) ;
d_printf ( " shutdown_in_progress: \t %d \n " , r - > shutdown_in_progress ) ;
d_printf ( " time_to_shutdown: \t %lld \n " , ( long long ) r - > time_to_shutdown ) ;
d_printf ( " next_audit_record: \t %d \n " , r - > next_audit_record ) ;
2006-04-11 15:47:24 +00:00
}
2008-02-08 01:38:44 +01:00
static void display_query_info_2 ( struct lsa_AuditEventsInfo * r )
2006-04-11 15:47:24 +00:00
{
int i ;
2008-02-08 01:38:44 +01:00
d_printf ( " Auditing enabled: \t %d \n " , r - > auditing_mode ) ;
d_printf ( " Auditing categories: \t %d \n " , r - > count ) ;
2006-04-11 15:47:24 +00:00
d_printf ( " Auditsettings: \n " ) ;
2008-02-08 01:38:44 +01:00
for ( i = 0 ; i < r - > count ; i + + ) {
const char * val = audit_policy_str ( talloc_tos ( ) , r - > settings [ i ] ) ;
2006-04-11 15:47:24 +00:00
const char * policy = audit_description_str ( i ) ;
d_printf ( " %s: \t %s \n " , policy , val ) ;
}
}
2008-02-08 01:38:44 +01:00
static void display_query_info_3 ( struct lsa_DomainInfo * r )
2006-04-11 15:47:24 +00:00
{
2018-12-08 15:31:40 +01:00
struct dom_sid_buf buf ;
2008-02-08 01:38:44 +01:00
d_printf ( " Domain Name: %s \n " , r - > name . string ) ;
2018-12-08 15:31:40 +01:00
d_printf ( " Domain Sid: %s \n " , dom_sid_str_buf ( r - > sid , & buf ) ) ;
2006-04-11 15:47:24 +00:00
}
2008-02-08 01:38:44 +01:00
static void display_query_info_5 ( struct lsa_DomainInfo * r )
2006-04-11 15:47:24 +00:00
{
2018-12-08 15:31:40 +01:00
struct dom_sid_buf buf ;
2008-02-08 01:38:44 +01:00
d_printf ( " Domain Name: %s \n " , r - > name . string ) ;
2018-12-08 15:31:40 +01:00
d_printf ( " Domain Sid: %s \n " , dom_sid_str_buf ( r - > sid , & buf ) ) ;
2006-04-11 15:47:24 +00:00
}
2008-02-08 01:38:44 +01:00
static void display_query_info_10 ( struct lsa_AuditFullSetInfo * r )
2006-04-11 15:47:24 +00:00
{
2008-02-08 01:38:44 +01:00
d_printf ( " Shutdown on full: %d \n " , r - > shutdown_on_full ) ;
2006-04-11 15:47:24 +00:00
}
2008-02-08 01:38:44 +01:00
static void display_query_info_11 ( struct lsa_AuditFullQueryInfo * r )
2006-04-11 15:47:24 +00:00
{
2008-02-08 01:38:44 +01:00
d_printf ( " Shutdown on full: %d \n " , r - > shutdown_on_full ) ;
d_printf ( " Log is full: %d \n " , r - > log_is_full ) ;
2006-04-11 15:47:24 +00:00
}
2008-02-08 01:38:44 +01:00
static void display_query_info_12 ( struct lsa_DnsDomainInfo * r )
2006-04-11 15:47:24 +00:00
{
2018-12-08 15:31:40 +01:00
struct dom_sid_buf buf ;
2008-02-08 01:38:44 +01:00
d_printf ( " Domain NetBios Name: %s \n " , r - > name . string ) ;
d_printf ( " Domain DNS Name: %s \n " , r - > dns_domain . string ) ;
d_printf ( " Domain Forest Name: %s \n " , r - > dns_forest . string ) ;
2018-12-08 15:31:40 +01:00
d_printf ( " Domain Sid: %s \n " , dom_sid_str_buf ( r - > sid , & buf ) ) ;
2008-10-14 02:26:18 +02:00
d_printf ( " Domain GUID: %s \n " , GUID_string ( talloc_tos ( ) ,
& r - > domain_guid ) ) ;
2006-04-11 15:47:24 +00:00
}
2008-02-08 01:38:44 +01:00
static void display_lsa_query_info ( union lsa_PolicyInformation * info ,
enum lsa_PolicyInfo level )
2006-04-11 15:47:24 +00:00
{
2008-02-08 01:38:44 +01:00
switch ( level ) {
2006-04-11 15:47:24 +00:00
case 1 :
2008-02-08 01:38:44 +01:00
display_query_info_1 ( & info - > audit_log ) ;
2006-04-11 15:47:24 +00:00
break ;
case 2 :
2008-02-08 01:38:44 +01:00
display_query_info_2 ( & info - > audit_events ) ;
2006-04-11 15:47:24 +00:00
break ;
case 3 :
2008-02-08 01:38:44 +01:00
display_query_info_3 ( & info - > domain ) ;
2006-04-11 15:47:24 +00:00
break ;
case 5 :
2008-02-08 01:38:44 +01:00
display_query_info_5 ( & info - > account_domain ) ;
2006-04-11 15:47:24 +00:00
break ;
case 10 :
2008-02-08 01:38:44 +01:00
display_query_info_10 ( & info - > auditfullset ) ;
2006-04-11 15:47:24 +00:00
break ;
case 11 :
2008-02-08 01:38:44 +01:00
display_query_info_11 ( & info - > auditfullquery ) ;
2006-04-11 15:47:24 +00:00
break ;
case 12 :
2008-02-08 01:38:44 +01:00
display_query_info_12 ( & info - > dns ) ;
2006-04-11 15:47:24 +00:00
break ;
default :
2008-02-08 01:38:44 +01:00
printf ( " can't display info level: %d \n " , level ) ;
2006-04-11 15:47:24 +00:00
break ;
}
}
2001-10-12 05:56:23 +00:00
2023-08-31 15:39:51 +02:00
static NTSTATUS cmd_lsa_query_info_policy ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2001-01-11 22:49:30 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2008-02-08 01:38:44 +01:00
union lsa_PolicyInformation * info = NULL ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2004-01-08 08:19:18 +00:00
2015-05-09 07:33:08 -07:00
uint32_t info_class = 3 ;
2001-01-11 22:49:30 +00:00
if ( argc > 2 ) {
printf ( " Usage: %s [info_class] \n " , argv [ 0 ] ) ;
2001-09-04 07:13:01 +00:00
return NT_STATUS_OK ;
2000-12-08 03:34:00 +00:00
}
1999-11-01 22:25:38 +00:00
2001-10-12 05:56:23 +00:00
if ( argc = = 2 )
2001-01-11 22:49:30 +00:00
info_class = atoi ( argv [ 1 ] ) ;
2006-04-11 15:47:24 +00:00
2002-08-17 15:33:49 +00:00
switch ( info_class ) {
2023-08-31 16:08:39 +02:00
case 12 : {
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
status = dcerpc_lsa_open_policy_fallback (
b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& pol ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2002-08-17 15:33:49 +00:00
goto done ;
2023-08-31 16:08:39 +02:00
}
2010-01-23 13:33:10 +01:00
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_QueryInfoPolicy2 ( b , mem_ctx ,
2008-02-08 01:38:44 +01:00
& pol ,
info_class ,
2011-01-18 16:08:05 +01:00
& info ,
& result ) ;
2002-08-17 15:33:49 +00:00
break ;
2023-08-31 16:08:39 +02:00
}
2002-08-17 15:33:49 +00:00
default :
2011-01-18 15:42:47 +01:00
status = rpccli_lsa_open_policy ( cli , mem_ctx , True ,
2009-04-15 01:12:13 +02:00
SEC_FLAG_MAXIMUM_ALLOWED ,
2006-04-11 15:47:24 +00:00
& pol ) ;
1998-09-25 21:01:52 +00:00
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2002-08-17 15:33:49 +00:00
goto done ;
2010-01-23 13:33:10 +01:00
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_QueryInfoPolicy ( b , mem_ctx ,
2008-02-08 01:38:44 +01:00
& pol ,
info_class ,
2011-01-18 16:08:05 +01:00
& info ,
& result ) ;
2002-08-17 15:33:49 +00:00
}
2001-10-12 05:56:23 +00:00
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
status = result ;
if ( NT_STATUS_IS_OK ( result ) ) {
2008-02-11 10:28:36 +01:00
display_lsa_query_info ( info , info_class ) ;
}
2005-09-30 17:13:37 +00:00
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
2005-09-30 17:13:37 +00:00
2001-10-12 05:56:23 +00:00
done :
2011-01-18 15:42:47 +01:00
return status ;
2001-01-11 22:49:30 +00:00
}
1998-09-25 21:01:52 +00:00
2001-01-11 22:49:30 +00:00
/* Resolve a list of names to a list of sids */
2023-08-31 15:39:51 +02:00
static NTSTATUS cmd_lsa_lookup_names ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2001-01-11 22:49:30 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2010-05-21 11:25:01 +10:00
struct dom_sid * sids ;
2006-09-08 14:28:06 +00:00
enum lsa_SidType * types ;
2002-04-15 05:02:22 +00:00
int i ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
1998-09-25 21:01:52 +00:00
2001-01-11 22:49:30 +00:00
if ( argc = = 1 ) {
printf ( " Usage: %s [name1 [name2 [...]]] \n " , argv [ 0 ] ) ;
2001-09-04 07:13:01 +00:00
return NT_STATUS_OK ;
2000-12-08 03:34:00 +00:00
}
1998-09-25 21:01:52 +00:00
2011-01-18 15:42:47 +01:00
status = rpccli_lsa_open_policy ( cli , mem_ctx , True ,
2020-03-09 14:21:41 -07:00
LSA_POLICY_LOOKUP_NAMES ,
& pol ) ;
1998-09-25 21:01:52 +00:00
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2001-10-12 05:56:23 +00:00
goto done ;
1998-09-25 21:01:52 +00:00
2011-01-18 15:42:47 +01:00
status = rpccli_lsa_lookup_names ( cli , mem_ctx , & pol , argc - 1 ,
2007-06-27 11:42:17 +00:00
( const char * * ) ( argv + 1 ) , NULL , 1 , & sids , & types ) ;
2001-10-12 05:56:23 +00:00
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) & & NT_STATUS_V ( status ) ! =
2002-07-15 10:35:28 +00:00
NT_STATUS_V ( STATUS_SOME_UNMAPPED ) )
2001-01-11 22:49:30 +00:00
goto done ;
2000-12-08 03:34:00 +00:00
2011-01-18 15:42:47 +01:00
status = NT_STATUS_OK ;
2002-07-15 10:35:28 +00:00
2001-01-11 22:49:30 +00:00
/* Print results */
2000-12-08 03:34:00 +00:00
2002-04-15 05:02:22 +00:00
for ( i = 0 ; i < ( argc - 1 ) ; i + + ) {
2018-12-07 10:32:08 +01:00
struct dom_sid_buf sid_str ;
printf ( " %s %s (%s: %d) \n " ,
argv [ i + 1 ] ,
dom_sid_str_buf ( & sids [ i ] , & sid_str ) ,
sid_type_lookup ( types [ i ] ) ,
types [ i ] ) ;
1998-09-25 21:01:52 +00:00
}
2000-12-08 03:34:00 +00:00
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
2005-03-10 18:50:47 +00:00
2001-01-11 22:49:30 +00:00
done :
2011-01-18 15:42:47 +01:00
return status ;
1998-09-30 19:09:57 +00:00
}
2007-06-27 12:27:00 +00:00
/* Resolve a list of names to a list of sids */
2023-08-31 15:39:51 +02:00
static NTSTATUS cmd_lsa_lookup_names_level ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
2007-06-27 12:27:00 +00:00
const char * * argv )
{
2009-03-18 22:49:41 +01:00
struct policy_handle pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2018-02-20 15:57:37 +01:00
struct dom_sid * sids = NULL ;
enum lsa_SidType * types = NULL ;
2007-06-27 12:27:00 +00:00
int i , level ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2007-06-27 12:27:00 +00:00
if ( argc < 3 ) {
printf ( " Usage: %s [level] [name1 [name2 [...]]] \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2011-01-18 15:42:47 +01:00
status = rpccli_lsa_open_policy ( cli , mem_ctx , True ,
2020-03-09 14:21:41 -07:00
LSA_POLICY_LOOKUP_NAMES ,
& pol ) ;
2018-02-20 15:57:37 +01:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-06-27 12:27:00 +00:00
goto done ;
2018-02-20 15:57:37 +01:00
}
2007-06-27 12:27:00 +00:00
level = atoi ( argv [ 1 ] ) ;
2011-01-18 15:42:47 +01:00
status = rpccli_lsa_lookup_names ( cli , mem_ctx , & pol , argc - 2 ,
2007-06-27 12:27:00 +00:00
( const char * * ) ( argv + 2 ) , NULL , level , & sids , & types ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) & & NT_STATUS_V ( status ) ! =
2007-06-27 12:27:00 +00:00
NT_STATUS_V ( STATUS_SOME_UNMAPPED ) )
2018-02-20 15:57:37 +01:00
{
2007-06-27 12:27:00 +00:00
goto done ;
2018-02-20 15:57:37 +01:00
}
2007-06-27 12:27:00 +00:00
2011-01-18 15:42:47 +01:00
status = NT_STATUS_OK ;
2007-06-27 12:27:00 +00:00
/* Print results */
for ( i = 0 ; i < ( argc - 2 ) ; i + + ) {
2018-12-07 10:32:08 +01:00
struct dom_sid_buf sid_str ;
printf ( " %s %s (%s: %d) \n " ,
argv [ i + 2 ] ,
dom_sid_str_buf ( & sids [ i ] , & sid_str ) ,
sid_type_lookup ( types [ i ] ) ,
types [ i ] ) ;
2007-06-27 12:27:00 +00:00
}
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
2007-06-27 12:27:00 +00:00
done :
2011-01-18 15:42:47 +01:00
return status ;
2007-06-27 12:27:00 +00:00
}
2009-09-10 23:33:37 +02:00
static NTSTATUS cmd_lsa_lookup_names4 ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2009-09-10 23:33:37 +02:00
uint32_t num_names ;
struct lsa_String * names ;
2013-11-07 21:40:55 -08:00
struct lsa_RefDomainList * domains = NULL ;
2009-09-10 23:33:37 +02:00
struct lsa_TransSidArray3 sids ;
uint32_t count = 0 ;
int i ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2009-09-10 23:33:37 +02:00
if ( argc = = 1 ) {
printf ( " Usage: %s [name1 [name2 [...]]] \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
ZERO_STRUCT ( sids ) ;
num_names = argc - 1 ;
names = talloc_array ( mem_ctx , struct lsa_String , num_names ) ;
NT_STATUS_HAVE_NO_MEMORY ( names ) ;
for ( i = 0 ; i < num_names ; i + + ) {
init_lsa_String ( & names [ i ] , argv [ i + 1 ] ) ;
}
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_LookupNames4 ( b , mem_ctx ,
2009-09-10 23:33:37 +02:00
num_names ,
names ,
& domains ,
& sids ,
1 ,
& count ,
0 ,
2011-01-18 16:08:05 +01:00
0 ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2009-09-10 23:33:37 +02:00
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
}
2009-09-10 23:33:37 +02:00
2013-11-07 21:40:55 -08:00
if ( sids . count ! = num_names ) {
return NT_STATUS_INVALID_NETWORK_RESPONSE ;
}
2009-09-10 23:33:37 +02:00
for ( i = 0 ; i < sids . count ; i + + ) {
2018-12-07 10:32:08 +01:00
struct dom_sid_buf sid_str ;
printf ( " %s %s (%s: %d) \n " ,
argv [ i + 1 ] ,
dom_sid_str_buf ( sids . sids [ i ] . sid , & sid_str ) ,
2009-09-10 23:33:37 +02:00
sid_type_lookup ( sids . sids [ i ] . sid_type ) ,
sids . sids [ i ] . sid_type ) ;
}
2011-01-18 15:42:47 +01:00
return status ;
2009-09-10 23:33:37 +02:00
}
2007-06-27 12:27:00 +00:00
2001-01-11 22:49:30 +00:00
/* Resolve a list of SIDs to a list of names */
2000-12-08 03:34:00 +00:00
2005-09-30 17:13:37 +00:00
static NTSTATUS cmd_lsa_lookup_sids ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
2003-02-25 23:51:56 +00:00
int argc , const char * * argv )
1998-11-25 19:57:04 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2010-05-21 11:25:01 +10:00
struct dom_sid * sids ;
2002-01-20 01:24:59 +00:00
char * * domains ;
2000-12-08 03:34:00 +00:00
char * * names ;
2006-09-08 14:28:06 +00:00
enum lsa_SidType * types ;
2002-04-15 05:02:22 +00:00
int i ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
1998-09-30 19:09:57 +00:00
2000-12-08 03:34:00 +00:00
if ( argc = = 1 ) {
2001-01-11 22:49:30 +00:00
printf ( " Usage: %s [sid1 [sid2 [...]]] \n " , argv [ 0 ] ) ;
2001-09-04 07:13:01 +00:00
return NT_STATUS_OK ;
2000-12-08 03:34:00 +00:00
}
1998-09-30 19:09:57 +00:00
2011-01-18 15:42:47 +01:00
status = rpccli_lsa_open_policy ( cli , mem_ctx , True ,
2020-03-09 14:21:41 -07:00
LSA_POLICY_LOOKUP_NAMES ,
& pol ) ;
1998-11-11 14:23:55 +00:00
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2001-10-12 05:56:23 +00:00
goto done ;
1998-09-30 19:09:57 +00:00
2001-01-11 22:49:30 +00:00
/* Convert arguments to sids */
1999-12-13 13:27:58 +00:00
2011-06-07 11:30:12 +10:00
sids = talloc_array ( mem_ctx , struct dom_sid , argc - 1 ) ;
1998-09-30 19:09:57 +00:00
2001-01-11 22:49:30 +00:00
if ( ! sids ) {
2001-10-12 05:56:23 +00:00
printf ( " could not allocate memory for %d sids \n " , argc - 1 ) ;
2001-01-11 22:49:30 +00:00
goto done ;
2000-12-08 03:34:00 +00:00
}
1998-09-30 19:09:57 +00:00
2023-08-31 15:39:51 +02:00
for ( i = 0 ; i < argc - 1 ; i + + )
2005-02-28 11:11:55 +00:00
if ( ! string_to_sid ( & sids [ i ] , argv [ i + 1 ] ) ) {
2011-01-18 15:42:47 +01:00
status = NT_STATUS_INVALID_SID ;
2003-02-18 07:05:02 +00:00
goto done ;
}
1999-12-13 13:27:58 +00:00
2001-01-11 22:49:30 +00:00
/* Lookup the SIDs */
1998-09-30 19:09:57 +00:00
2011-01-18 15:42:47 +01:00
status = rpccli_lsa_lookup_sids ( cli , mem_ctx , & pol , argc - 1 , sids ,
2002-04-15 05:02:22 +00:00
& domains , & names , & types ) ;
2001-10-12 05:56:23 +00:00
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) & & NT_STATUS_V ( status ) ! =
2002-07-15 10:35:28 +00:00
NT_STATUS_V ( STATUS_SOME_UNMAPPED ) )
2001-01-11 22:49:30 +00:00
goto done ;
2000-12-08 03:34:00 +00:00
2011-01-18 15:42:47 +01:00
status = NT_STATUS_OK ;
2002-07-15 10:35:28 +00:00
2001-01-11 22:49:30 +00:00
/* Print results */
2005-03-10 18:50:47 +00:00
for ( i = 0 ; i < ( argc - 1 ) ; i + + ) {
2018-12-07 10:32:08 +01:00
struct dom_sid_buf sid_str ;
2000-12-08 03:34:00 +00:00
2018-12-07 10:32:08 +01:00
dom_sid_str_buf ( & sids [ i ] , & sid_str ) ;
2013-09-18 09:32:17 +02:00
if ( types [ i ] = = SID_NAME_DOMAIN ) {
2018-12-07 10:32:08 +01:00
printf ( " %s %s (%d) \n " , sid_str . buf ,
2013-09-18 09:32:17 +02:00
domains [ i ] ? domains [ i ] : " *unknown* " ,
types [ i ] ) ;
} else {
2018-12-07 10:32:08 +01:00
printf ( " %s %s \\ %s (%d) \n " , sid_str . buf ,
2013-09-18 09:32:17 +02:00
domains [ i ] ? domains [ i ] : " *unknown* " ,
names [ i ] ? names [ i ] : " *unknown* " ,
types [ i ] ) ;
}
1998-09-25 21:01:52 +00:00
}
2000-12-08 03:34:00 +00:00
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
2005-03-10 18:50:47 +00:00
2001-01-11 22:49:30 +00:00
done :
2011-01-18 15:42:47 +01:00
return status ;
1999-03-18 05:16:59 +00:00
}
2018-01-25 11:24:25 +01:00
static NTSTATUS cmd_lsa_lookup_sids_level ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
struct policy_handle pol ;
NTSTATUS status , result ;
struct dom_sid * sids = NULL ;
char * * domains = NULL ;
char * * names = NULL ;
enum lsa_SidType * types = NULL ;
int i , level ;
struct dcerpc_binding_handle * b = cli - > binding_handle ;
if ( argc < 3 ) {
printf ( " Usage: %s [level] [sid1 [sid2 [...]]] \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
status = rpccli_lsa_open_policy ( cli , mem_ctx , True ,
2020-03-09 14:21:41 -07:00
LSA_POLICY_LOOKUP_NAMES ,
& pol ) ;
2018-01-25 11:24:25 +01:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
level = atoi ( argv [ 1 ] ) ;
/* Convert arguments to sids */
sids = talloc_array ( mem_ctx , struct dom_sid , argc - 2 ) ;
if ( sids = = NULL ) {
printf ( " could not allocate memory for %d sids \n " , argc - 2 ) ;
goto done ;
}
for ( i = 0 ; i < argc - 2 ; i + + ) {
if ( ! string_to_sid ( & sids [ i ] , argv [ i + 2 ] ) ) {
status = NT_STATUS_INVALID_SID ;
goto done ;
}
}
/* Lookup the SIDs */
status = dcerpc_lsa_lookup_sids_generic ( cli - > binding_handle ,
mem_ctx ,
& pol ,
argc - 2 ,
sids ,
level ,
& domains ,
& names ,
& types ,
false ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
status = result ;
if ( ! NT_STATUS_IS_OK ( status ) & & NT_STATUS_V ( status ) ! =
NT_STATUS_V ( STATUS_SOME_UNMAPPED ) )
{
goto done ;
}
status = NT_STATUS_OK ;
/* Print results */
for ( i = 0 ; i < ( argc - 2 ) ; i + + ) {
2018-12-07 10:32:08 +01:00
struct dom_sid_buf sid_str ;
2018-01-25 11:24:25 +01:00
2018-12-07 10:32:08 +01:00
dom_sid_str_buf ( & sids [ i ] , & sid_str ) ;
2018-01-25 11:24:25 +01:00
if ( types [ i ] = = SID_NAME_DOMAIN ) {
2018-12-07 10:32:08 +01:00
printf ( " %s %s (%d) \n " , sid_str . buf ,
2018-01-25 11:24:25 +01:00
domains [ i ] ? domains [ i ] : " *unknown* " ,
types [ i ] ) ;
} else {
2018-12-07 10:32:08 +01:00
printf ( " %s %s \\ %s (%d) \n " , sid_str . buf ,
2018-01-25 11:24:25 +01:00
domains [ i ] ? domains [ i ] : " *unknown* " ,
names [ i ] ? names [ i ] : " *unknown* " ,
types [ i ] ) ;
}
}
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
done :
return status ;
}
2009-09-11 13:58:52 +02:00
/* Resolve a list of SIDs to a list of names */
static NTSTATUS cmd_lsa_lookup_sids3 ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
2011-01-18 16:08:05 +01:00
NTSTATUS status = NT_STATUS_UNSUCCESSFUL , result ;
2009-09-11 13:58:52 +02:00
int i ;
struct lsa_SidArray sids ;
2013-11-07 20:38:01 -08:00
struct lsa_RefDomainList * domains = NULL ;
2009-09-11 13:58:52 +02:00
struct lsa_TransNameArray2 names ;
uint32_t count = 0 ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2009-09-11 13:58:52 +02:00
if ( argc = = 1 ) {
printf ( " Usage: %s [sid1 [sid2 [...]]] \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
ZERO_STRUCT ( names ) ;
/* Convert arguments to sids */
sids . num_sids = argc - 1 ;
sids . sids = talloc_array ( mem_ctx , struct lsa_SidPtr , sids . num_sids ) ;
if ( ! sids . sids ) {
printf ( " could not allocate memory for %d sids \n " , sids . num_sids ) ;
goto done ;
}
for ( i = 0 ; i < sids . num_sids ; i + + ) {
2010-01-23 13:30:04 +01:00
sids . sids [ i ] . sid = talloc ( sids . sids , struct dom_sid ) ;
if ( sids . sids [ i ] . sid = = NULL ) {
2011-01-18 15:42:47 +01:00
status = NT_STATUS_NO_MEMORY ;
2010-01-23 13:30:04 +01:00
goto done ;
}
if ( ! string_to_sid ( sids . sids [ i ] . sid , argv [ i + 1 ] ) ) {
2011-01-18 15:42:47 +01:00
status = NT_STATUS_INVALID_SID ;
2009-09-11 13:58:52 +02:00
goto done ;
}
}
/* Lookup the SIDs */
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_LookupSids3 ( b , mem_ctx ,
2009-09-11 13:58:52 +02:00
& sids ,
& domains ,
& names ,
1 ,
& count ,
0 ,
2011-01-18 16:08:05 +01:00
0 ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-09-11 13:58:52 +02:00
goto done ;
2011-01-18 16:08:05 +01:00
}
if ( ! NT_STATUS_IS_OK ( result ) & & NT_STATUS_V ( result ) ! =
NT_STATUS_V ( STATUS_SOME_UNMAPPED ) ) {
status = result ;
goto done ;
}
2009-09-11 13:58:52 +02:00
2011-01-18 15:42:47 +01:00
status = NT_STATUS_OK ;
2009-09-11 13:58:52 +02:00
/* Print results */
2013-11-07 20:38:01 -08:00
for ( i = 0 ; i < names . count ; i + + ) {
2018-12-07 10:32:08 +01:00
struct dom_sid_buf sid_str ;
2009-09-11 13:58:52 +02:00
2013-11-07 20:38:01 -08:00
if ( i > = sids . num_sids ) {
break ;
}
2018-12-07 10:32:08 +01:00
printf ( " %s %s (%d) \n " ,
dom_sid_str_buf ( sids . sids [ i ] . sid , & sid_str ) ,
2009-09-11 13:58:52 +02:00
names . names [ i ] . name . string ,
names . names [ i ] . sid_type ) ;
}
done :
2011-01-18 15:42:47 +01:00
return status ;
2009-09-11 13:58:52 +02:00
}
2001-01-11 22:49:30 +00:00
/* Enumerate list of trusted domains */
2000-12-08 03:34:00 +00:00
2023-08-31 15:39:51 +02:00
static NTSTATUS cmd_lsa_enum_trust_dom ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2001-01-11 22:49:30 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2008-02-13 00:25:40 +01:00
struct lsa_DomainList domain_list ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2002-07-15 10:35:28 +00:00
/* defaults, but may be changed using params */
2015-05-09 07:33:08 -07:00
uint32_t enum_ctx = 0 ;
2001-03-23 20:41:22 +00:00
int i ;
2008-02-13 00:25:40 +01:00
uint32_t max_size = ( uint32_t ) - 1 ;
2001-01-11 22:49:30 +00:00
2002-08-17 15:33:49 +00:00
if ( argc > 2 ) {
printf ( " Usage: %s [enum context (0)] \n " , argv [ 0 ] ) ;
2001-09-04 07:13:01 +00:00
return NT_STATUS_OK ;
2001-01-11 22:49:30 +00:00
}
2000-12-08 03:34:00 +00:00
2002-08-17 15:33:49 +00:00
if ( argc = = 2 & & argv [ 1 ] ) {
2002-07-15 10:35:28 +00:00
enum_ctx = atoi ( argv [ 2 ] ) ;
2023-08-31 15:39:51 +02:00
}
2002-07-15 10:35:28 +00:00
2011-01-18 15:42:47 +01:00
status = rpccli_lsa_open_policy ( cli , mem_ctx , True ,
2008-02-27 15:49:31 +01:00
LSA_POLICY_VIEW_LOCAL_INFORMATION ,
2001-09-04 07:13:01 +00:00
& pol ) ;
2000-12-08 03:34:00 +00:00
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2001-10-12 05:56:23 +00:00
goto done ;
2001-01-11 22:49:30 +00:00
2011-01-18 15:42:47 +01:00
status = STATUS_MORE_ENTRIES ;
2005-01-22 17:12:19 +00:00
2011-01-18 15:42:47 +01:00
while ( NT_STATUS_EQUAL ( status , STATUS_MORE_ENTRIES ) ) {
2001-01-11 22:49:30 +00:00
2005-01-22 17:12:19 +00:00
/* Lookup list of trusted domains */
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_EnumTrustDom ( b , mem_ctx ,
2008-02-13 00:25:40 +01:00
& pol ,
& enum_ctx ,
& domain_list ,
2011-01-18 16:08:05 +01:00
max_size ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
if ( ! NT_STATUS_IS_OK ( result ) & &
! NT_STATUS_EQUAL ( result , NT_STATUS_NO_MORE_ENTRIES ) & &
! NT_STATUS_EQUAL ( result , STATUS_MORE_ENTRIES ) ) {
status = result ;
2005-01-22 17:12:19 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
}
2005-01-22 17:12:19 +00:00
/* Print results: list of names and sids returned in this
2023-08-31 15:39:51 +02:00
* response . */
2008-02-13 00:25:40 +01:00
for ( i = 0 ; i < domain_list . count ; i + + ) {
2018-12-07 10:32:08 +01:00
struct dom_sid_buf sid_str ;
2005-01-22 17:12:19 +00:00
2008-02-13 00:25:40 +01:00
printf ( " %s %s \n " ,
domain_list . domains [ i ] . name . string ?
domain_list . domains [ i ] . name . string : " *unknown* " ,
2018-12-07 10:32:08 +01:00
dom_sid_str_buf ( domain_list . domains [ i ] . sid ,
& sid_str ) ) ;
2005-01-22 17:12:19 +00:00
}
2001-01-11 22:49:30 +00:00
}
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
2001-01-11 22:49:30 +00:00
done :
2011-01-18 15:42:47 +01:00
return status ;
2000-12-08 03:34:00 +00:00
}
2001-01-11 22:49:30 +00:00
2001-11-22 16:12:43 +00:00
/* Enumerates privileges */
2023-08-31 15:39:51 +02:00
static NTSTATUS cmd_lsa_enum_privilege ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2001-11-22 16:12:43 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2008-02-11 10:33:31 +01:00
struct lsa_PrivArray priv_array ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2001-11-22 16:12:43 +00:00
2015-05-09 07:33:08 -07:00
uint32_t enum_context = 0 ;
uint32_t pref_max_length = 0x1000 ;
2001-11-22 16:12:43 +00:00
int i ;
2001-11-22 23:50:16 +00:00
if ( argc > 3 ) {
printf ( " Usage: %s [enum context] [max length] \n " , argv [ 0 ] ) ;
2001-11-22 16:12:43 +00:00
return NT_STATUS_OK ;
}
2001-11-22 23:50:16 +00:00
if ( argc > = 2 )
enum_context = atoi ( argv [ 1 ] ) ;
if ( argc = = 3 )
pref_max_length = atoi ( argv [ 2 ] ) ;
2011-01-18 15:42:47 +01:00
status = rpccli_lsa_open_policy ( cli , mem_ctx , True ,
2009-04-15 01:12:13 +02:00
SEC_FLAG_MAXIMUM_ALLOWED ,
2001-11-22 16:12:43 +00:00
& pol ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2001-11-22 16:12:43 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_EnumPrivs ( b , mem_ctx ,
2008-02-11 10:33:31 +01:00
& pol ,
& enum_context ,
& priv_array ,
2011-01-18 16:08:05 +01:00
pref_max_length ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2001-11-22 16:12:43 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2001-11-22 16:12:43 +00:00
/* Print results */
2008-02-11 10:33:31 +01:00
printf ( " found %d privileges \n \n " , priv_array . count ) ;
for ( i = 0 ; i < priv_array . count ; i + + ) {
printf ( " %s \t \t %d:%d (0x%x:0x%x) \n " ,
priv_array . privs [ i ] . name . string ? priv_array . privs [ i ] . name . string : " *unknown* " ,
priv_array . privs [ i ] . luid . high ,
priv_array . privs [ i ] . luid . low ,
priv_array . privs [ i ] . luid . high ,
priv_array . privs [ i ] . luid . low ) ;
2001-11-22 16:12:43 +00:00
}
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
2001-11-22 16:12:43 +00:00
done :
2011-01-18 15:42:47 +01:00
return status ;
2001-11-22 16:12:43 +00:00
}
2001-11-22 16:54:48 +00:00
/* Get privilege name */
2023-08-31 15:39:51 +02:00
static NTSTATUS cmd_lsa_get_dispname ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2001-11-22 16:54:48 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2001-11-22 16:54:48 +00:00
2015-05-09 07:33:08 -07:00
uint16_t lang_id = 0 ;
uint16_t lang_id_sys = 0 ;
uint16_t lang_id_desc ;
2008-02-11 12:17:27 +01:00
struct lsa_String lsa_name ;
struct lsa_StringLarge * description = NULL ;
2001-11-22 16:54:48 +00:00
if ( argc ! = 2 ) {
printf ( " Usage: %s privilege name \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2011-01-18 15:42:47 +01:00
status = rpccli_lsa_open_policy ( cli , mem_ctx , True ,
2009-04-15 01:12:13 +02:00
SEC_FLAG_MAXIMUM_ALLOWED ,
2001-11-22 16:54:48 +00:00
& pol ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2001-11-22 16:54:48 +00:00
goto done ;
2008-02-11 12:17:27 +01:00
init_lsa_String ( & lsa_name , argv [ 1 ] ) ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_LookupPrivDisplayName ( b , mem_ctx ,
2008-02-11 12:17:27 +01:00
& pol ,
& lsa_name ,
lang_id ,
lang_id_sys ,
& description ,
2011-01-18 16:08:05 +01:00
& lang_id_desc ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2001-11-22 16:54:48 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2001-11-22 16:54:48 +00:00
/* Print results */
2008-02-11 12:17:27 +01:00
printf ( " %s -> %s (language: 0x%x) \n " , argv [ 1 ] , description - > string , lang_id_desc ) ;
2001-11-22 16:54:48 +00:00
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
2001-11-22 16:54:48 +00:00
done :
2011-01-18 15:42:47 +01:00
return status ;
2001-11-22 16:54:48 +00:00
}
2001-11-22 23:50:16 +00:00
/* Enumerate the LSA SIDS */
2023-08-31 15:39:51 +02:00
static NTSTATUS cmd_lsa_enum_sids ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2001-11-22 23:50:16 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2001-11-22 23:50:16 +00:00
2015-05-09 07:33:08 -07:00
uint32_t enum_context = 0 ;
uint32_t pref_max_length = 0x1000 ;
2008-02-14 01:32:56 +01:00
struct lsa_SidArray sid_array ;
2001-11-22 23:50:16 +00:00
int i ;
if ( argc > 3 ) {
printf ( " Usage: %s [enum context] [max length] \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
if ( argc > = 2 )
enum_context = atoi ( argv [ 1 ] ) ;
if ( argc = = 3 )
pref_max_length = atoi ( argv [ 2 ] ) ;
2011-01-18 15:42:47 +01:00
status = rpccli_lsa_open_policy ( cli , mem_ctx , True ,
2009-04-15 01:12:13 +02:00
SEC_FLAG_MAXIMUM_ALLOWED ,
2001-11-22 23:50:16 +00:00
& pol ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2001-11-22 23:50:16 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_EnumAccounts ( b , mem_ctx ,
2008-02-14 01:32:56 +01:00
& pol ,
& enum_context ,
& sid_array ,
2011-01-18 16:08:05 +01:00
pref_max_length ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2001-11-22 23:50:16 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2001-11-22 23:50:16 +00:00
/* Print results */
2008-02-14 01:32:56 +01:00
printf ( " found %d SIDs \n \n " , sid_array . num_sids ) ;
2001-11-22 23:50:16 +00:00
2008-02-14 01:32:56 +01:00
for ( i = 0 ; i < sid_array . num_sids ; i + + ) {
2018-12-07 10:32:08 +01:00
struct dom_sid_buf sid_str ;
2001-11-22 23:50:16 +00:00
2018-12-07 10:32:08 +01:00
printf ( " %s \n " ,
dom_sid_str_buf ( sid_array . sids [ i ] . sid , & sid_str ) ) ;
2001-11-22 23:50:16 +00:00
}
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
2001-11-22 23:50:16 +00:00
done :
2011-01-18 15:42:47 +01:00
return status ;
2001-11-22 23:50:16 +00:00
}
2005-01-14 19:26:13 +00:00
/* Create a new account */
2023-08-31 15:39:51 +02:00
static NTSTATUS cmd_lsa_create_account ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2005-01-14 19:26:13 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle dom_pol ;
struct policy_handle user_pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2015-05-09 07:33:08 -07:00
uint32_t des_access = 0x000f000f ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2010-01-23 13:33:10 +01:00
2010-05-21 11:25:01 +10:00
struct dom_sid sid ;
2005-01-14 19:26:13 +00:00
if ( argc ! = 2 ) {
printf ( " Usage: %s SID \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2011-01-18 15:42:47 +01:00
status = name_to_sid ( cli , mem_ctx , & sid , argv [ 1 ] ) ;
if ( ! NT_STATUS_IS_OK ( status ) )
2023-08-31 15:39:51 +02:00
goto done ;
2005-01-14 19:26:13 +00:00
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& dom_pol ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2005-01-14 19:26:13 +00:00
goto done ;
2023-08-31 16:08:39 +02:00
}
2005-01-14 19:26:13 +00:00
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_CreateAccount ( b , mem_ctx ,
2008-02-06 19:07:31 +01:00
& dom_pol ,
& sid ,
des_access ,
2011-01-18 16:08:05 +01:00
& user_pol ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2005-01-14 19:26:13 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2005-01-14 19:26:13 +00:00
printf ( " Account for SID %s successfully created \n \n " , argv [ 1 ] ) ;
2011-01-18 15:42:47 +01:00
status = NT_STATUS_OK ;
2005-01-14 19:26:13 +00:00
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & dom_pol , & result ) ;
2005-01-14 19:26:13 +00:00
done :
2011-01-18 15:42:47 +01:00
return status ;
2005-01-14 19:26:13 +00:00
}
2001-11-24 00:13:41 +00:00
/* Enumerate the privileges of an SID */
2023-08-31 15:39:51 +02:00
static NTSTATUS cmd_lsa_enum_privsaccounts ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2001-11-24 00:13:41 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle dom_pol ;
struct policy_handle user_pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2015-05-09 07:33:08 -07:00
uint32_t access_desired = 0x000f000f ;
2010-05-21 11:25:01 +10:00
struct dom_sid sid ;
2008-02-14 12:13:13 +01:00
struct lsa_PrivilegeSet * privs = NULL ;
2001-11-24 00:13:41 +00:00
int i ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2001-11-24 00:13:41 +00:00
if ( argc ! = 2 ) {
printf ( " Usage: %s SID \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2011-01-18 15:42:47 +01:00
status = name_to_sid ( cli , mem_ctx , & sid , argv [ 1 ] ) ;
if ( ! NT_STATUS_IS_OK ( status ) )
2023-08-31 15:39:51 +02:00
goto done ;
2001-11-24 00:13:41 +00:00
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& dom_pol ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2001-11-24 00:13:41 +00:00
goto done ;
2023-08-31 16:08:39 +02:00
}
2001-11-24 00:13:41 +00:00
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_OpenAccount ( b , mem_ctx ,
2008-02-06 19:31:00 +01:00
& dom_pol ,
& sid ,
access_desired ,
2011-01-18 16:08:05 +01:00
& user_pol ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2001-11-24 00:13:41 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2001-11-24 00:13:41 +00:00
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_EnumPrivsAccount ( b , mem_ctx ,
2008-02-14 12:13:13 +01:00
& user_pol ,
2011-01-18 16:08:05 +01:00
& privs ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2001-11-24 00:13:41 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2001-11-24 00:13:41 +00:00
/* Print results */
2008-02-14 12:13:13 +01:00
printf ( " found %d privileges for SID %s \n \n " , privs - > count , argv [ 1 ] ) ;
2001-11-24 00:13:41 +00:00
printf ( " high \t low \t attribute \n " ) ;
2008-02-14 12:13:13 +01:00
for ( i = 0 ; i < privs - > count ; i + + ) {
printf ( " %u \t %u \t %u \n " ,
privs - > set [ i ] . luid . high ,
privs - > set [ i ] . luid . low ,
privs - > set [ i ] . attribute ) ;
2001-11-24 00:13:41 +00:00
}
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & dom_pol , & result ) ;
2001-11-24 00:13:41 +00:00
done :
2011-01-18 15:42:47 +01:00
return status ;
2001-11-24 00:13:41 +00:00
}
2003-01-15 17:22:48 +00:00
/* Enumerate the privileges of an SID via LsaEnumerateAccountRights */
2023-08-31 15:39:51 +02:00
static NTSTATUS cmd_lsa_enum_acct_rights ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2003-01-15 17:22:48 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle dom_pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2010-05-21 11:25:01 +10:00
struct dom_sid sid ;
2018-12-08 15:31:40 +01:00
struct dom_sid_buf buf ;
2008-02-14 15:09:21 +01:00
struct lsa_RightSet rights ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2003-01-15 17:22:48 +00:00
int i ;
if ( argc ! = 2 ) {
printf ( " Usage: %s SID \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2011-01-18 15:42:47 +01:00
status = name_to_sid ( cli , mem_ctx , & sid , argv [ 1 ] ) ;
if ( ! NT_STATUS_IS_OK ( status ) )
2023-08-31 15:39:51 +02:00
goto done ;
2003-01-15 17:22:48 +00:00
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& dom_pol ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2003-01-15 17:22:48 +00:00
goto done ;
2023-08-31 16:08:39 +02:00
}
2003-01-15 17:22:48 +00:00
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_EnumAccountRights ( b , mem_ctx ,
2008-02-14 15:09:21 +01:00
& dom_pol ,
& sid ,
2011-01-18 16:08:05 +01:00
& rights ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2003-01-15 17:22:48 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2003-01-15 17:22:48 +00:00
2008-02-14 15:09:21 +01:00
printf ( " found %d privileges for SID %s \n " , rights . count ,
2018-12-08 15:31:40 +01:00
dom_sid_str_buf ( & sid , & buf ) ) ;
2003-01-15 17:22:48 +00:00
2008-02-14 15:09:21 +01:00
for ( i = 0 ; i < rights . count ; i + + ) {
printf ( " \t %s \n " , rights . names [ i ] . string ) ;
2003-01-15 17:22:48 +00:00
}
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & dom_pol , & result ) ;
2003-01-15 17:22:48 +00:00
done :
2011-01-18 15:42:47 +01:00
return status ;
2003-01-15 17:22:48 +00:00
}
2003-01-28 21:09:56 +00:00
/* add some privileges to a SID via LsaAddAccountRights */
2023-08-31 15:39:51 +02:00
static NTSTATUS cmd_lsa_add_acct_rights ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2003-01-28 21:09:56 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle dom_pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2008-02-14 14:34:10 +01:00
struct lsa_RightSet rights ;
2010-05-21 11:25:01 +10:00
struct dom_sid sid ;
2008-02-14 14:34:10 +01:00
int i ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2003-01-28 21:09:56 +00:00
if ( argc < 3 ) {
printf ( " Usage: %s SID [rights...] \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2011-01-18 15:42:47 +01:00
status = name_to_sid ( cli , mem_ctx , & sid , argv [ 1 ] ) ;
if ( ! NT_STATUS_IS_OK ( status ) )
2023-08-31 15:39:51 +02:00
goto done ;
2003-01-28 21:09:56 +00:00
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& dom_pol ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2003-01-28 21:09:56 +00:00
goto done ;
2023-08-31 16:08:39 +02:00
}
2003-01-28 21:09:56 +00:00
2008-02-14 14:34:10 +01:00
rights . count = argc - 2 ;
2011-06-07 11:30:12 +10:00
rights . names = talloc_array ( mem_ctx , struct lsa_StringLarge ,
2008-02-14 14:34:10 +01:00
rights . count ) ;
if ( ! rights . names ) {
return NT_STATUS_NO_MEMORY ;
}
2008-10-22 14:26:05 +02:00
for ( i = 0 ; i < argc - 2 ; i + + ) {
2008-02-14 14:34:10 +01:00
init_lsa_StringLarge ( & rights . names [ i ] , argv [ i + 2 ] ) ;
}
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_AddAccountRights ( b , mem_ctx ,
2008-02-14 14:34:10 +01:00
& dom_pol ,
& sid ,
2011-01-18 16:08:05 +01:00
& rights ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2003-01-28 21:09:56 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2003-01-28 21:09:56 +00:00
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & dom_pol , & result ) ;
2003-01-28 21:09:56 +00:00
done :
2011-01-18 15:42:47 +01:00
return status ;
2003-01-28 21:09:56 +00:00
}
2003-01-29 02:24:12 +00:00
/* remove some privileges to a SID via LsaRemoveAccountRights */
2023-08-31 15:39:51 +02:00
static NTSTATUS cmd_lsa_remove_acct_rights ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2003-01-29 02:24:12 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle dom_pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2008-02-14 15:28:26 +01:00
struct lsa_RightSet rights ;
2010-05-21 11:25:01 +10:00
struct dom_sid sid ;
2008-02-14 15:28:26 +01:00
int i ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2003-01-29 02:24:12 +00:00
if ( argc < 3 ) {
printf ( " Usage: %s SID [rights...] \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2011-01-18 15:42:47 +01:00
status = name_to_sid ( cli , mem_ctx , & sid , argv [ 1 ] ) ;
if ( ! NT_STATUS_IS_OK ( status ) )
2023-08-31 15:39:51 +02:00
goto done ;
2003-01-29 02:24:12 +00:00
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& dom_pol ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2003-01-29 02:24:12 +00:00
goto done ;
2023-08-31 16:08:39 +02:00
}
2003-01-29 02:24:12 +00:00
2008-02-14 15:28:26 +01:00
rights . count = argc - 2 ;
2011-06-07 11:30:12 +10:00
rights . names = talloc_array ( mem_ctx , struct lsa_StringLarge ,
2008-02-14 15:28:26 +01:00
rights . count ) ;
if ( ! rights . names ) {
return NT_STATUS_NO_MEMORY ;
}
for ( i = 0 ; i < argc - 2 ; i + + ) {
init_lsa_StringLarge ( & rights . names [ i ] , argv [ i + 2 ] ) ;
}
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_RemoveAccountRights ( b , mem_ctx ,
2008-02-14 15:28:26 +01:00
& dom_pol ,
& sid ,
false ,
2011-01-18 16:08:05 +01:00
& rights ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2003-01-29 02:24:12 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2003-01-29 02:24:12 +00:00
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & dom_pol , & result ) ;
2005-09-30 17:13:37 +00:00
2003-01-29 02:24:12 +00:00
done :
2011-01-18 15:42:47 +01:00
return status ;
2003-01-29 02:24:12 +00:00
}
2001-11-24 00:13:41 +00:00
/* Get a privilege value given its name */
2023-08-31 15:39:51 +02:00
static NTSTATUS cmd_lsa_lookup_priv_value ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2001-11-24 00:13:41 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2008-02-14 13:29:18 +01:00
struct lsa_LUID luid ;
struct lsa_String name ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2001-11-24 00:13:41 +00:00
if ( argc ! = 2 ) {
printf ( " Usage: %s name \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& pol ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2001-11-24 00:13:41 +00:00
goto done ;
2023-08-31 16:08:39 +02:00
}
2001-11-24 00:13:41 +00:00
2008-02-14 13:29:18 +01:00
init_lsa_String ( & name , argv [ 1 ] ) ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_LookupPrivValue ( b , mem_ctx ,
2008-02-14 13:29:18 +01:00
& pol ,
& name ,
2011-01-18 16:08:05 +01:00
& luid ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2001-11-24 00:13:41 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2001-11-24 00:13:41 +00:00
/* Print results */
2002-07-15 10:35:28 +00:00
2001-11-24 00:13:41 +00:00
printf ( " %u:%u (0x%x:0x%x) \n " , luid . high , luid . low , luid . high , luid . low ) ;
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
2001-11-24 00:13:41 +00:00
done :
2011-01-18 15:42:47 +01:00
return status ;
2001-11-24 00:13:41 +00:00
}
2001-12-11 02:17:26 +00:00
/* Query LSA security object */
2023-08-31 15:39:51 +02:00
static NTSTATUS cmd_lsa_query_secobj ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2001-12-11 02:17:26 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2010-05-18 02:56:17 +02:00
struct sec_desc_buf * sdb ;
2015-05-09 07:33:08 -07:00
uint32_t sec_info = SECINFO_DACL ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2001-12-11 02:17:26 +00:00
2006-03-10 13:01:08 +00:00
if ( argc < 1 | | argc > 2 ) {
printf ( " Usage: %s [sec_info] \n " , argv [ 0 ] ) ;
2001-12-11 02:17:26 +00:00
return NT_STATUS_OK ;
}
2023-08-31 15:39:51 +02:00
if ( argc = = 2 )
2006-03-10 13:01:08 +00:00
sscanf ( argv [ 1 ] , " %x " , & sec_info ) ;
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& pol ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2001-12-11 02:17:26 +00:00
goto done ;
2023-08-31 16:08:39 +02:00
}
2001-12-11 02:17:26 +00:00
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_QuerySecurity ( b , mem_ctx ,
2008-02-04 21:40:15 +01:00
& pol ,
sec_info ,
2011-01-18 16:08:05 +01:00
& sdb ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2001-12-11 02:17:26 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2001-12-11 02:17:26 +00:00
/* Print results */
2006-09-20 22:23:12 +00:00
display_sec_desc ( sdb - > sd ) ;
2001-12-11 02:17:26 +00:00
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
2001-12-11 02:17:26 +00:00
done :
2011-01-18 15:42:47 +01:00
return status ;
2001-12-11 02:17:26 +00:00
}
2008-04-21 08:01:51 +02:00
static void display_trust_dom_info_4 ( struct lsa_TrustDomainInfoPassword * p ,
2011-07-25 11:21:31 +10:00
DATA_BLOB session_key )
2005-06-08 13:59:03 +00:00
{
char * pwd , * pwd_old ;
2010-01-23 13:33:10 +01:00
2009-03-16 21:27:58 +11:00
DATA_BLOB data = data_blob_const ( p - > password - > data , p - > password - > length ) ;
DATA_BLOB data_old = data_blob_const ( p - > old_password - > data , p - > old_password - > length ) ;
2005-06-08 13:59:03 +00:00
2011-07-25 11:21:31 +10:00
pwd = sess_decrypt_string ( talloc_tos ( ) , & data , & session_key ) ;
pwd_old = sess_decrypt_string ( talloc_tos ( ) , & data_old , & session_key ) ;
2010-01-23 13:33:10 +01:00
2005-06-13 14:39:40 +00:00
d_printf ( " Password: \t %s \n " , pwd ) ;
d_printf ( " Old Password: \t %s \n " , pwd_old ) ;
2005-06-08 13:59:03 +00:00
2009-03-16 21:27:58 +11:00
talloc_free ( pwd ) ;
talloc_free ( pwd_old ) ;
2005-06-08 13:59:03 +00:00
}
2008-01-15 23:06:23 +01:00
static void display_trust_dom_info ( TALLOC_CTX * mem_ctx ,
union lsa_TrustedDomainInfo * info ,
2008-01-14 15:15:47 +01:00
enum lsa_TrustDomInfoEnum info_class ,
2011-07-25 11:21:31 +10:00
DATA_BLOB session_key )
2005-06-08 13:59:03 +00:00
{
switch ( info_class ) {
2008-01-14 15:15:47 +01:00
case LSA_TRUSTED_DOMAIN_INFO_PASSWORD :
2011-07-25 11:21:31 +10:00
display_trust_dom_info_4 ( & info - > password , session_key ) ;
2008-01-14 15:15:47 +01:00
break ;
2008-01-15 23:06:23 +01:00
default : {
const char * str = NULL ;
str = NDR_PRINT_UNION_STRING ( mem_ctx ,
lsa_TrustedDomainInfo ,
info_class , info ) ;
if ( str ) {
d_printf ( " %s \n " , str ) ;
}
2008-01-14 15:15:47 +01:00
break ;
2008-01-15 23:06:23 +01:00
}
2005-06-08 13:59:03 +00:00
}
}
2005-09-30 17:13:37 +00:00
static NTSTATUS cmd_lsa_query_trustdominfobysid ( struct rpc_pipe_client * cli ,
2023-08-31 15:39:51 +02:00
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2005-06-08 13:59:03 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2010-05-21 11:25:01 +10:00
struct dom_sid dom_sid ;
2015-05-09 07:33:08 -07:00
uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
2008-04-08 22:55:52 +02:00
union lsa_TrustedDomainInfo * info = NULL ;
2008-01-14 15:15:47 +01:00
enum lsa_TrustDomInfoEnum info_class = 1 ;
2011-07-25 11:21:31 +10:00
DATA_BLOB session_key ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2005-06-08 13:59:03 +00:00
if ( argc > 3 | | argc < 2 ) {
printf ( " Usage: %s [sid] [info_class] \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
if ( ! string_to_sid ( & dom_sid , argv [ 1 ] ) )
return NT_STATUS_NO_MEMORY ;
if ( argc = = 3 )
info_class = atoi ( argv [ 2 ] ) ;
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
access_mask ,
& out_version ,
& out_revision_info ,
& pol ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2005-06-08 13:59:03 +00:00
goto done ;
2023-08-31 16:08:39 +02:00
}
2005-06-08 13:59:03 +00:00
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_QueryTrustedDomainInfoBySid ( b , mem_ctx ,
2008-01-14 15:15:47 +01:00
& pol ,
& dom_sid ,
info_class ,
2011-01-18 16:08:05 +01:00
& info ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2005-06-08 13:59:03 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2005-06-08 13:59:03 +00:00
2011-07-25 11:21:31 +10:00
status = cli_get_session_key ( mem_ctx , cli , & session_key ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " Could not retrieve session key: %s \n " , nt_errstr ( status ) ) ) ;
2008-04-21 08:01:51 +02:00
goto done ;
}
2011-07-25 11:21:31 +10:00
display_trust_dom_info ( mem_ctx , info , info_class , session_key ) ;
2005-06-08 13:59:03 +00:00
done :
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
2005-06-08 13:59:03 +00:00
2011-01-18 15:42:47 +01:00
return status ;
2005-06-08 13:59:03 +00:00
}
2005-09-30 17:13:37 +00:00
static NTSTATUS cmd_lsa_query_trustdominfobyname ( struct rpc_pipe_client * cli ,
2023-08-31 15:39:51 +02:00
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2005-06-08 13:59:03 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2015-05-09 07:33:08 -07:00
uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
2008-04-08 23:09:24 +02:00
union lsa_TrustedDomainInfo * info = NULL ;
2008-01-14 15:15:47 +01:00
enum lsa_TrustDomInfoEnum info_class = 1 ;
struct lsa_String trusted_domain ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2011-07-25 11:21:31 +10:00
DATA_BLOB session_key ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2005-06-08 13:59:03 +00:00
if ( argc > 3 | | argc < 2 ) {
printf ( " Usage: %s [name] [info_class] \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
if ( argc = = 3 )
info_class = atoi ( argv [ 2 ] ) ;
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
access_mask ,
& out_version ,
& out_revision_info ,
& pol ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2005-06-08 13:59:03 +00:00
goto done ;
2023-08-31 16:08:39 +02:00
}
2005-06-08 13:59:03 +00:00
2008-01-14 15:15:47 +01:00
init_lsa_String ( & trusted_domain , argv [ 1 ] ) ;
2005-06-08 13:59:03 +00:00
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_QueryTrustedDomainInfoByName ( b , mem_ctx ,
2008-01-14 15:15:47 +01:00
& pol ,
2008-02-08 18:02:57 +01:00
& trusted_domain ,
2008-01-14 15:15:47 +01:00
info_class ,
2011-01-18 16:08:05 +01:00
& info ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2005-06-08 13:59:03 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2005-06-08 13:59:03 +00:00
2011-07-25 11:21:31 +10:00
status = cli_get_session_key ( mem_ctx , cli , & session_key ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " Could not retrieve session key: %s \n " , nt_errstr ( status ) ) ) ;
2008-04-21 08:01:51 +02:00
goto done ;
}
2011-07-25 11:21:31 +10:00
display_trust_dom_info ( mem_ctx , info , info_class , session_key ) ;
2005-06-08 13:59:03 +00:00
done :
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
2005-06-08 13:59:03 +00:00
2011-01-18 15:42:47 +01:00
return status ;
2005-06-08 13:59:03 +00:00
}
2011-11-22 18:38:52 +01:00
static NTSTATUS cmd_lsa_set_trustdominfo ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
struct policy_handle pol , trustdom_pol ;
NTSTATUS status , result ;
2015-05-09 07:33:08 -07:00
uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
2011-11-22 18:38:52 +01:00
union lsa_TrustedDomainInfo info ;
struct dom_sid dom_sid ;
enum lsa_TrustDomInfoEnum info_class = 1 ;
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2011-11-22 18:38:52 +01:00
if ( argc > 4 | | argc < 3 ) {
printf ( " Usage: %s [sid] [info_class] [value] \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
if ( ! string_to_sid ( & dom_sid , argv [ 1 ] ) ) {
return NT_STATUS_NO_MEMORY ;
}
info_class = atoi ( argv [ 2 ] ) ;
switch ( info_class ) {
case 13 : /* LSA_TRUSTED_DOMAIN_SUPPORTED_ENCRYPTION_TYPES */
info . enc_types . enc_types = atoi ( argv [ 3 ] ) ;
break ;
default :
return NT_STATUS_INVALID_PARAMETER ;
}
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
access_mask ,
& out_version ,
& out_revision_info ,
& pol ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2011-11-22 18:38:52 +01:00
goto done ;
}
status = dcerpc_lsa_OpenTrustedDomain ( b , mem_ctx ,
& pol ,
& dom_sid ,
access_mask ,
& trustdom_pol ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
status = dcerpc_lsa_SetInformationTrustedDomain ( b , mem_ctx ,
& trustdom_pol ,
info_class ,
& info ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
done :
dcerpc_lsa_Close ( b , mem_ctx , & trustdom_pol , & result ) ;
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
return status ;
}
2005-09-30 17:13:37 +00:00
static NTSTATUS cmd_lsa_query_trustdominfo ( struct rpc_pipe_client * cli ,
2023-08-31 15:39:51 +02:00
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2005-06-08 13:59:03 +00:00
{
2009-03-18 22:49:41 +01:00
struct policy_handle pol , trustdom_pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2015-05-09 07:33:08 -07:00
uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
2008-04-08 22:55:52 +02:00
union lsa_TrustedDomainInfo * info = NULL ;
2010-05-21 11:25:01 +10:00
struct dom_sid dom_sid ;
2008-01-14 15:15:47 +01:00
enum lsa_TrustDomInfoEnum info_class = 1 ;
2011-07-25 11:21:31 +10:00
DATA_BLOB session_key ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2005-06-08 13:59:03 +00:00
if ( argc > 3 | | argc < 2 ) {
printf ( " Usage: %s [sid] [info_class] \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
if ( ! string_to_sid ( & dom_sid , argv [ 1 ] ) )
return NT_STATUS_NO_MEMORY ;
if ( argc = = 3 )
info_class = atoi ( argv [ 2 ] ) ;
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
access_mask ,
& out_version ,
& out_revision_info ,
& pol ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2005-06-08 13:59:03 +00:00
goto done ;
2023-08-31 16:08:39 +02:00
}
2008-01-14 15:27:57 +01:00
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_OpenTrustedDomain ( b , mem_ctx ,
2008-01-14 15:27:57 +01:00
& pol ,
& dom_sid ,
access_mask ,
2011-01-18 16:08:05 +01:00
& trustdom_pol ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2005-06-08 13:59:03 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2005-06-08 13:59:03 +00:00
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_QueryTrustedDomainInfo ( b , mem_ctx ,
2008-01-14 15:15:47 +01:00
& trustdom_pol ,
info_class ,
2011-01-18 16:08:05 +01:00
& info ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) )
2005-06-08 13:59:03 +00:00
goto done ;
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2005-06-08 13:59:03 +00:00
2011-07-25 11:21:31 +10:00
status = cli_get_session_key ( mem_ctx , cli , & session_key ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " Could not retrieve session key: %s \n " , nt_errstr ( status ) ) ) ;
2008-04-21 08:01:51 +02:00
goto done ;
}
2011-07-25 11:21:31 +10:00
display_trust_dom_info ( mem_ctx , info , info_class , session_key ) ;
2005-06-08 13:59:03 +00:00
done :
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
2005-06-08 13:59:03 +00:00
2011-01-18 15:42:47 +01:00
return status ;
2005-06-08 13:59:03 +00:00
}
2008-02-11 20:22:01 +01:00
static NTSTATUS cmd_lsa_get_username ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2008-04-19 21:56:43 +02:00
const char * servername = cli - > desthost ;
2008-02-11 20:22:01 +01:00
struct lsa_String * account_name = NULL ;
struct lsa_String * authority_name = NULL ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-02-11 20:22:01 +01:00
if ( argc > 2 ) {
printf ( " Usage: %s servername \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_GetUserName ( b , mem_ctx ,
2008-02-11 20:22:01 +01:00
servername ,
& account_name ,
2011-01-18 16:08:05 +01:00
& authority_name ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-02-11 20:22:01 +01:00
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2008-02-11 20:22:01 +01:00
/* Print results */
printf ( " Account Name: %s, Authority Name: %s \n " ,
2008-10-21 01:19:49 +02:00
account_name - > string , authority_name ? authority_name - > string :
" " ) ;
2008-02-11 20:22:01 +01:00
done :
2011-01-18 15:42:47 +01:00
return status ;
2008-02-11 20:22:01 +01:00
}
2005-06-08 13:59:03 +00:00
2008-02-14 13:46:39 +01:00
static NTSTATUS cmd_lsa_add_priv ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
2009-03-18 22:49:41 +01:00
struct policy_handle dom_pol , user_pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2008-02-14 13:46:39 +01:00
struct lsa_PrivilegeSet privs ;
struct lsa_LUIDAttribute * set = NULL ;
2010-05-21 11:25:01 +10:00
struct dom_sid sid ;
2008-02-14 13:46:39 +01:00
int i ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2008-02-14 13:46:39 +01:00
ZERO_STRUCT ( privs ) ;
if ( argc < 3 ) {
printf ( " Usage: %s SID [rights...] \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2011-01-18 15:42:47 +01:00
status = name_to_sid ( cli , mem_ctx , & sid , argv [ 1 ] ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-02-14 13:46:39 +01:00
goto done ;
}
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& dom_pol ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2008-02-14 13:46:39 +01:00
goto done ;
}
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_OpenAccount ( b , mem_ctx ,
2008-02-14 13:46:39 +01:00
& dom_pol ,
& sid ,
2009-04-15 01:12:13 +02:00
SEC_FLAG_MAXIMUM_ALLOWED ,
2011-01-18 16:08:05 +01:00
& user_pol ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-02-14 13:46:39 +01:00
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2008-02-14 13:46:39 +01:00
for ( i = 2 ; i < argc ; i + + ) {
struct lsa_String priv_name ;
struct lsa_LUID luid ;
init_lsa_String ( & priv_name , argv [ i ] ) ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_LookupPrivValue ( b , mem_ctx ,
2008-02-14 13:46:39 +01:00
& dom_pol ,
& priv_name ,
2011-01-18 16:08:05 +01:00
& luid ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-02-14 13:46:39 +01:00
continue ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
continue ;
}
2008-02-14 13:46:39 +01:00
privs . count + + ;
2011-06-07 11:10:15 +10:00
set = talloc_realloc ( mem_ctx , set ,
2008-02-14 13:46:39 +01:00
struct lsa_LUIDAttribute ,
privs . count ) ;
if ( ! set ) {
return NT_STATUS_NO_MEMORY ;
}
set [ privs . count - 1 ] . luid = luid ;
set [ privs . count - 1 ] . attribute = 0 ;
}
privs . set = set ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_AddPrivilegesToAccount ( b , mem_ctx ,
2008-02-14 13:46:39 +01:00
& user_pol ,
2011-01-18 16:08:05 +01:00
& privs ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-02-14 13:46:39 +01:00
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2008-02-14 13:46:39 +01:00
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & user_pol , & result ) ;
dcerpc_lsa_Close ( b , mem_ctx , & dom_pol , & result ) ;
2008-02-14 13:46:39 +01:00
done :
2011-01-18 15:42:47 +01:00
return status ;
2008-02-14 13:46:39 +01:00
}
static NTSTATUS cmd_lsa_del_priv ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
2009-03-18 22:49:41 +01:00
struct policy_handle dom_pol , user_pol ;
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2008-02-14 13:46:39 +01:00
struct lsa_PrivilegeSet privs ;
struct lsa_LUIDAttribute * set = NULL ;
2010-05-21 11:25:01 +10:00
struct dom_sid sid ;
2008-02-14 13:46:39 +01:00
int i ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2008-02-14 13:46:39 +01:00
ZERO_STRUCT ( privs ) ;
if ( argc < 3 ) {
printf ( " Usage: %s SID [rights...] \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2011-01-18 15:42:47 +01:00
status = name_to_sid ( cli , mem_ctx , & sid , argv [ 1 ] ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-02-14 13:46:39 +01:00
goto done ;
}
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& dom_pol ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2008-02-14 13:46:39 +01:00
goto done ;
}
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_OpenAccount ( b , mem_ctx ,
2008-02-14 13:46:39 +01:00
& dom_pol ,
& sid ,
2009-04-15 01:12:13 +02:00
SEC_FLAG_MAXIMUM_ALLOWED ,
2011-01-18 16:08:05 +01:00
& user_pol ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-02-14 13:46:39 +01:00
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2008-02-14 13:46:39 +01:00
for ( i = 2 ; i < argc ; i + + ) {
struct lsa_String priv_name ;
struct lsa_LUID luid ;
init_lsa_String ( & priv_name , argv [ i ] ) ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_LookupPrivValue ( b , mem_ctx ,
2008-02-14 13:46:39 +01:00
& dom_pol ,
& priv_name ,
2011-01-18 16:08:05 +01:00
& luid ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-02-14 13:46:39 +01:00
continue ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
continue ;
}
2008-02-14 13:46:39 +01:00
privs . count + + ;
2011-06-07 11:10:15 +10:00
set = talloc_realloc ( mem_ctx , set ,
2008-02-14 13:46:39 +01:00
struct lsa_LUIDAttribute ,
privs . count ) ;
if ( ! set ) {
return NT_STATUS_NO_MEMORY ;
}
set [ privs . count - 1 ] . luid = luid ;
set [ privs . count - 1 ] . attribute = 0 ;
}
privs . set = set ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_RemovePrivilegesFromAccount ( b , mem_ctx ,
2008-02-14 13:46:39 +01:00
& user_pol ,
false ,
2011-01-18 16:08:05 +01:00
& privs ,
& result ) ;
2011-01-18 15:42:47 +01:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-02-14 13:46:39 +01:00
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2008-02-14 13:46:39 +01:00
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & user_pol , & result ) ;
dcerpc_lsa_Close ( b , mem_ctx , & dom_pol , & result ) ;
2008-02-14 13:46:39 +01:00
done :
2011-01-18 15:42:47 +01:00
return status ;
2008-02-14 13:46:39 +01:00
}
2009-07-17 11:54:49 +02:00
static NTSTATUS cmd_lsa_create_secret ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2009-07-17 11:54:49 +02:00
struct policy_handle handle , sec_handle ;
struct lsa_String name ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2009-07-17 11:54:49 +02:00
if ( argc < 2 ) {
printf ( " Usage: %s name \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& sec_handle ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2009-07-17 11:54:49 +02:00
return status ;
}
init_lsa_String ( & name , argv [ 1 ] ) ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_CreateSecret ( b , mem_ctx ,
2009-07-17 11:54:49 +02:00
& handle ,
name ,
SEC_FLAG_MAXIMUM_ALLOWED ,
2011-01-18 16:08:05 +01:00
& sec_handle ,
& result ) ;
2009-07-17 11:54:49 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2009-07-17 11:54:49 +02:00
done :
if ( is_valid_policy_hnd ( & sec_handle ) ) {
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & sec_handle , & result ) ;
2009-07-17 11:54:49 +02:00
}
if ( is_valid_policy_hnd ( & handle ) ) {
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & handle , & result ) ;
2009-07-17 11:54:49 +02:00
}
return status ;
}
2002-10-04 04:10:23 +00:00
2009-07-17 11:58:10 +02:00
static NTSTATUS cmd_lsa_delete_secret ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2009-07-17 11:58:10 +02:00
struct policy_handle handle , sec_handle ;
struct lsa_String name ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2009-07-17 11:58:10 +02:00
if ( argc < 2 ) {
printf ( " Usage: %s name \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& handle ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2009-07-17 11:58:10 +02:00
return status ;
}
init_lsa_String ( & name , argv [ 1 ] ) ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_OpenSecret ( b , mem_ctx ,
2009-07-17 11:58:10 +02:00
& handle ,
name ,
SEC_FLAG_MAXIMUM_ALLOWED ,
2011-01-18 16:08:05 +01:00
& sec_handle ,
& result ) ;
2009-07-17 11:58:10 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2009-07-17 11:58:10 +02:00
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_DeleteObject ( b , mem_ctx ,
& sec_handle ,
& result ) ;
2009-07-17 11:58:10 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2009-07-17 11:58:10 +02:00
done :
if ( is_valid_policy_hnd ( & sec_handle ) ) {
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & sec_handle , & result ) ;
2009-07-17 11:58:10 +02:00
}
if ( is_valid_policy_hnd ( & handle ) ) {
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & handle , & result ) ;
2009-07-17 11:58:10 +02:00
}
return status ;
}
2009-07-17 12:03:58 +02:00
static NTSTATUS cmd_lsa_query_secret ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2009-07-17 12:03:58 +02:00
struct policy_handle handle , sec_handle ;
struct lsa_String name ;
struct lsa_DATA_BUF_PTR new_val ;
NTTIME new_mtime = 0 ;
struct lsa_DATA_BUF_PTR old_val ;
NTTIME old_mtime = 0 ;
DATA_BLOB session_key ;
DATA_BLOB new_blob = data_blob_null ;
DATA_BLOB old_blob = data_blob_null ;
char * new_secret , * old_secret ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2009-07-17 12:03:58 +02:00
if ( argc < 2 ) {
printf ( " Usage: %s name \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& handle ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2009-07-17 12:03:58 +02:00
return status ;
}
init_lsa_String ( & name , argv [ 1 ] ) ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_OpenSecret ( b , mem_ctx ,
2009-07-17 12:03:58 +02:00
& handle ,
name ,
SEC_FLAG_MAXIMUM_ALLOWED ,
2011-01-18 16:08:05 +01:00
& sec_handle ,
& result ) ;
2009-07-17 12:03:58 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2009-07-17 12:03:58 +02:00
ZERO_STRUCT ( new_val ) ;
ZERO_STRUCT ( old_val ) ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_QuerySecret ( b , mem_ctx ,
2009-07-17 12:03:58 +02:00
& sec_handle ,
& new_val ,
& new_mtime ,
& old_val ,
2011-01-18 16:08:05 +01:00
& old_mtime ,
& result ) ;
2009-07-17 12:03:58 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2009-07-17 12:03:58 +02:00
status = cli_get_session_key ( mem_ctx , cli , & session_key ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
if ( new_val . buf ) {
new_blob = data_blob_const ( new_val . buf - > data , new_val . buf - > length ) ;
}
if ( old_val . buf ) {
old_blob = data_blob_const ( old_val . buf - > data , old_val . buf - > length ) ;
}
new_secret = sess_decrypt_string ( mem_ctx , & new_blob , & session_key ) ;
old_secret = sess_decrypt_string ( mem_ctx , & old_blob , & session_key ) ;
if ( new_secret ) {
d_printf ( " new secret: %s \n " , new_secret ) ;
}
if ( old_secret ) {
d_printf ( " old secret: %s \n " , old_secret ) ;
}
done :
if ( is_valid_policy_hnd ( & sec_handle ) ) {
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & sec_handle , & result ) ;
2009-07-17 12:03:58 +02:00
}
if ( is_valid_policy_hnd ( & handle ) ) {
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & handle , & result ) ;
2009-07-17 12:03:58 +02:00
}
return status ;
}
2009-07-17 12:56:30 +02:00
static NTSTATUS cmd_lsa_set_secret ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2009-07-17 12:56:30 +02:00
struct policy_handle handle , sec_handle ;
struct lsa_String name ;
struct lsa_DATA_BUF new_val ;
struct lsa_DATA_BUF old_val ;
DATA_BLOB enc_key ;
DATA_BLOB session_key ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2009-07-17 12:56:30 +02:00
if ( argc < 3 ) {
printf ( " Usage: %s name secret \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& handle ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2009-07-17 12:56:30 +02:00
return status ;
}
init_lsa_String ( & name , argv [ 1 ] ) ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_OpenSecret ( b , mem_ctx ,
2009-07-17 12:56:30 +02:00
& handle ,
name ,
SEC_FLAG_MAXIMUM_ALLOWED ,
2011-01-18 16:08:05 +01:00
& sec_handle ,
& result ) ;
2009-07-17 12:56:30 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2009-07-17 12:56:30 +02:00
ZERO_STRUCT ( new_val ) ;
ZERO_STRUCT ( old_val ) ;
status = cli_get_session_key ( mem_ctx , cli , & session_key ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
enc_key = sess_encrypt_string ( argv [ 2 ] , & session_key ) ;
new_val . length = enc_key . length ;
new_val . size = enc_key . length ;
new_val . data = enc_key . data ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_SetSecret ( b , mem_ctx ,
2009-07-17 12:56:30 +02:00
& sec_handle ,
& new_val ,
2011-01-18 16:08:05 +01:00
NULL ,
& result ) ;
2009-07-17 12:56:30 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2009-07-17 12:56:30 +02:00
done :
if ( is_valid_policy_hnd ( & sec_handle ) ) {
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & sec_handle , & result ) ;
2009-07-17 12:56:30 +02:00
}
if ( is_valid_policy_hnd ( & handle ) ) {
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & handle , & result ) ;
2009-07-17 12:56:30 +02:00
}
return status ;
}
2009-07-17 13:30:37 +02:00
static NTSTATUS cmd_lsa_retrieve_private_data ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2009-07-17 13:30:37 +02:00
struct policy_handle handle ;
struct lsa_String name ;
struct lsa_DATA_BUF * val ;
DATA_BLOB session_key ;
2009-09-16 10:14:05 +02:00
DATA_BLOB blob = data_blob_null ;
2009-07-17 13:30:37 +02:00
char * secret ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2009-07-17 13:30:37 +02:00
if ( argc < 2 ) {
printf ( " Usage: %s name \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& handle ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2009-07-17 13:30:37 +02:00
return status ;
}
init_lsa_String ( & name , argv [ 1 ] ) ;
ZERO_STRUCT ( val ) ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_RetrievePrivateData ( b , mem_ctx ,
2009-07-17 13:30:37 +02:00
& handle ,
& name ,
2011-01-18 16:08:05 +01:00
& val ,
& result ) ;
2009-07-17 13:30:37 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2009-07-17 13:30:37 +02:00
status = cli_get_session_key ( mem_ctx , cli , & session_key ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
if ( val ) {
blob = data_blob_const ( val - > data , val - > length ) ;
}
secret = sess_decrypt_string ( mem_ctx , & blob , & session_key ) ;
if ( secret ) {
d_printf ( " secret: %s \n " , secret ) ;
}
done :
if ( is_valid_policy_hnd ( & handle ) ) {
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & handle , & result ) ;
2009-07-17 13:30:37 +02:00
}
return status ;
}
2009-07-17 13:37:08 +02:00
static NTSTATUS cmd_lsa_store_private_data ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2009-07-17 13:37:08 +02:00
struct policy_handle handle ;
struct lsa_String name ;
struct lsa_DATA_BUF val ;
DATA_BLOB session_key ;
DATA_BLOB enc_key ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2009-07-17 13:37:08 +02:00
if ( argc < 3 ) {
printf ( " Usage: %s name secret \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& handle ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2009-07-17 13:37:08 +02:00
return status ;
}
init_lsa_String ( & name , argv [ 1 ] ) ;
ZERO_STRUCT ( val ) ;
status = cli_get_session_key ( mem_ctx , cli , & session_key ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
enc_key = sess_encrypt_string ( argv [ 2 ] , & session_key ) ;
val . length = enc_key . length ;
val . size = enc_key . length ;
val . data = enc_key . data ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_StorePrivateData ( b , mem_ctx ,
2009-07-17 13:37:08 +02:00
& handle ,
& name ,
2011-01-18 16:08:05 +01:00
& val ,
& result ) ;
2009-07-17 13:37:08 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2009-07-17 13:37:08 +02:00
done :
if ( is_valid_policy_hnd ( & handle ) ) {
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & handle , & result ) ;
2009-07-17 13:37:08 +02:00
}
return status ;
}
2009-10-28 14:13:32 +01:00
static NTSTATUS cmd_lsa_create_trusted_domain ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2009-10-28 14:13:32 +01:00
struct policy_handle handle , trustdom_handle ;
2010-01-23 13:18:00 +01:00
struct dom_sid sid ;
2009-10-28 14:13:32 +01:00
struct lsa_DomainInfo info ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2009-10-28 14:13:32 +01:00
if ( argc < 3 ) {
printf ( " Usage: %s name sid \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& handle ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2009-10-28 14:13:32 +01:00
return status ;
}
init_lsa_StringLarge ( & info . name , argv [ 1 ] ) ;
2010-01-23 13:18:00 +01:00
info . sid = & sid ;
string_to_sid ( & sid , argv [ 2 ] ) ;
2009-10-28 14:13:32 +01:00
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_CreateTrustedDomain ( b , mem_ctx ,
2009-10-28 14:13:32 +01:00
& handle ,
& info ,
SEC_FLAG_MAXIMUM_ALLOWED ,
2011-01-18 16:08:05 +01:00
& trustdom_handle ,
& result ) ;
2009-10-28 14:13:32 +01:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2009-10-28 14:13:32 +01:00
done :
if ( is_valid_policy_hnd ( & trustdom_handle ) ) {
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & trustdom_handle , & result ) ;
2009-10-28 14:13:32 +01:00
}
if ( is_valid_policy_hnd ( & handle ) ) {
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & handle , & result ) ;
2009-10-28 14:13:32 +01:00
}
return status ;
}
2009-07-17 12:56:30 +02:00
2009-10-28 15:37:11 +01:00
static NTSTATUS cmd_lsa_delete_trusted_domain ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
2011-01-18 16:08:05 +01:00
NTSTATUS status , result ;
2009-10-28 15:37:11 +01:00
struct policy_handle handle , trustdom_handle ;
struct lsa_String name ;
struct dom_sid * sid = NULL ;
2011-01-18 16:08:05 +01:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2023-08-31 16:08:39 +02:00
union lsa_revision_info out_revision_info = {
. info1 = {
. revision = 0 ,
} ,
} ;
uint32_t out_version = 0 ;
2009-10-28 15:37:11 +01:00
if ( argc < 2 ) {
printf ( " Usage: %s name \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2023-08-31 16:08:39 +02:00
status = dcerpc_lsa_open_policy_fallback ( b ,
mem_ctx ,
cli - > srv_name_slash ,
true ,
SEC_FLAG_MAXIMUM_ALLOWED ,
& out_version ,
& out_revision_info ,
& handle ,
& result ) ;
if ( any_nt_status_not_ok ( status , result , & status ) ) {
2009-10-28 15:37:11 +01:00
return status ;
}
init_lsa_String ( & name , argv [ 1 ] ) ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_OpenTrustedDomainByName ( b , mem_ctx ,
2009-10-28 15:37:11 +01:00
& handle ,
name ,
SEC_FLAG_MAXIMUM_ALLOWED ,
2011-01-18 16:08:05 +01:00
& trustdom_handle ,
& result ) ;
if ( NT_STATUS_IS_OK ( status ) & & NT_STATUS_IS_OK ( result ) ) {
2009-10-28 15:37:11 +01:00
goto delete_object ;
}
{
uint32_t resume_handle = 0 ;
struct lsa_DomainList domains ;
int i ;
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_EnumTrustDom ( b , mem_ctx ,
2009-10-28 15:37:11 +01:00
& handle ,
& resume_handle ,
& domains ,
2011-01-18 16:08:05 +01:00
0xffff ,
& result ) ;
2009-10-28 15:37:11 +01:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2009-10-28 15:37:11 +01:00
for ( i = 0 ; i < domains . count ; i + + ) {
if ( strequal ( domains . domains [ i ] . name . string , argv [ 1 ] ) ) {
sid = domains . domains [ i ] . sid ;
break ;
}
}
if ( ! sid ) {
return NT_STATUS_INVALID_SID ;
}
}
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_OpenTrustedDomain ( b , mem_ctx ,
2009-10-28 15:37:11 +01:00
& handle ,
sid ,
SEC_FLAG_MAXIMUM_ALLOWED ,
2011-01-18 16:08:05 +01:00
& trustdom_handle ,
& result ) ;
2009-10-28 15:37:11 +01:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2009-10-28 15:37:11 +01:00
delete_object :
2011-01-18 16:08:05 +01:00
status = dcerpc_lsa_DeleteObject ( b , mem_ctx ,
& trustdom_handle ,
& result ) ;
2009-10-28 15:37:11 +01:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
2011-01-18 16:08:05 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2009-10-28 15:37:11 +01:00
done :
if ( is_valid_policy_hnd ( & trustdom_handle ) ) {
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & trustdom_handle , & result ) ;
2009-10-28 15:37:11 +01:00
}
if ( is_valid_policy_hnd ( & handle ) ) {
2011-01-18 16:08:05 +01:00
dcerpc_lsa_Close ( b , mem_ctx , & handle , & result ) ;
2009-10-28 15:37:11 +01:00
}
return status ;
}
2001-01-11 22:49:30 +00:00
/* List of commands exported by this module */
struct cmd_set lsarpc_commands [ ] = {
2001-07-20 04:38:58 +00:00
2019-01-11 14:05:57 +01:00
{
. name = " LSARPC " ,
} ,
2005-01-15 02:20:30 +00:00
2019-01-11 14:05:57 +01:00
{
. name = " lsaquery " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_query_info_policy ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Query info policy " ,
. usage = " " ,
} ,
{
. name = " lookupsids " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_lookup_sids ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Convert SIDs to names " ,
. usage = " " ,
} ,
{
. name = " lookupsids3 " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_lookup_sids3 ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Convert SIDs to names " ,
. usage = " " ,
} ,
{
. name = " lookupsids_level " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_lookup_sids_level ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Convert SIDs to names " ,
. usage = " " ,
} ,
{
. name = " lookupnames " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_lookup_names ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Convert names to SIDs " ,
. usage = " " ,
} ,
{
. name = " lookupnames4 " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_lookup_names4 ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Convert names to SIDs " ,
. usage = " " ,
} ,
{
. name = " lookupnames_level " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_lookup_names_level ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Convert names to SIDs " ,
. usage = " " ,
} ,
{
. name = " enumtrust " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_enum_trust_dom ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Enumerate trusted domains " ,
. usage = " Usage: [preferred max number] [enum context (0)] " ,
} ,
{
. name = " enumprivs " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_enum_privilege ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Enumerate privileges " ,
. usage = " " ,
} ,
{
. name = " getdispname " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_get_dispname ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Get the privilege name " ,
. usage = " " ,
} ,
{
. name = " lsaenumsid " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_enum_sids ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Enumerate the LSA SIDS " ,
. usage = " " ,
} ,
{
. name = " lsacreateaccount " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_create_account ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Create a new lsa account " ,
. usage = " " ,
} ,
{
. name = " lsaenumprivsaccount " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_enum_privsaccounts ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Enumerate the privileges of an SID " ,
. usage = " " ,
} ,
{
. name = " lsaenumacctrights " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_enum_acct_rights ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Enumerate the rights of an SID " ,
. usage = " " ,
} ,
{
. name = " lsaaddpriv " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_add_priv ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Assign a privilege to a SID " ,
. usage = " " ,
} ,
{
. name = " lsadelpriv " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_del_priv ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Revoke a privilege from a SID " ,
. usage = " " ,
} ,
{
. name = " lsaaddacctrights " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_add_acct_rights ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Add rights to an account " ,
. usage = " " ,
} ,
{
. name = " lsaremoveacctrights " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_remove_acct_rights ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Remove rights from an account " ,
. usage = " " ,
} ,
{
. name = " lsalookupprivvalue " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_lookup_priv_value ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Get a privilege value given its name " ,
. usage = " " ,
} ,
{
. name = " lsaquerysecobj " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_query_secobj ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Query LSA security object " ,
. usage = " " ,
} ,
{
. name = " lsaquerytrustdominfo " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_query_trustdominfo ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Query LSA trusted domains info (given a SID) " ,
. usage = " " ,
} ,
{
. name = " lsaquerytrustdominfobyname " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_query_trustdominfobyname ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Query LSA trusted domains info (given a name), only works for Windows > 2k " ,
. usage = " " ,
} ,
{
. name = " lsaquerytrustdominfobysid " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_query_trustdominfobysid ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Query LSA trusted domains info (given a SID) " ,
. usage = " " ,
} ,
{
. name = " lsasettrustdominfo " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_set_trustdominfo ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Set LSA trusted domain info " ,
. usage = " " ,
} ,
{
. name = " getusername " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_get_username ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Get username " ,
. usage = " " ,
} ,
{
. name = " createsecret " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_create_secret ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Create Secret " ,
. usage = " " ,
} ,
{
. name = " deletesecret " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_delete_secret ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Delete Secret " ,
. usage = " " ,
} ,
{
. name = " querysecret " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_query_secret ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Query Secret " ,
. usage = " " ,
} ,
{
. name = " setsecret " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_set_secret ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Set Secret " ,
. usage = " " ,
} ,
{
. name = " retrieveprivatedata " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_retrieve_private_data ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Retrieve Private Data " ,
. usage = " " ,
} ,
{
. name = " storeprivatedata " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_store_private_data ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Store Private Data " ,
. usage = " " ,
} ,
{
. name = " createtrustdom " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_create_trusted_domain ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Create Trusted Domain " ,
. usage = " " ,
} ,
{
. name = " deletetrustdom " ,
. returntype = RPC_RTYPE_NTSTATUS ,
. ntfn = cmd_lsa_delete_trusted_domain ,
. wfn = NULL ,
. table = & ndr_table_lsarpc ,
. rpc_pipe = NULL ,
. description = " Delete Trusted Domain " ,
. usage = " " ,
} ,
{
. name = NULL ,
} ,
} ;