1998-09-26 01:01:52 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2001-05-24 04:20:32 +04:00
RPC pipe client
Copyright ( C ) Tim Potter 2000
2008-02-27 21:38:48 +03:00
Copyright ( C ) Guenther Deschner 2008
2001-05-24 04:20:32 +04:00
1998-09-26 01:01:52 +04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
1998-09-26 01:01:52 +04:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
1998-09-26 01:01:52 +04:00
*/
# include "includes.h"
2001-10-12 09:56:23 +04:00
# include "rpcclient.h"
2009-03-16 13:27:58 +03:00
# include "../libcli/auth/libcli_auth.h"
2010-08-06 16:52:58 +04:00
# include "../librpc/gen_ndr/ndr_netlogon.h"
2011-01-12 14:08:42 +03:00
# include "../librpc/gen_ndr/ndr_netlogon_c.h"
2010-05-18 20:26:03 +04:00
# include "rpc_client/cli_netlogon.h"
2010-08-05 04:25:37 +04:00
# include "secrets.h"
2013-07-27 13:30:13 +04:00
# include "../libcli/auth/netlogon_creds_cli.h"
1998-09-26 01:01:52 +04:00
2008-02-14 00:54:43 +03:00
static WERROR cmd_netlogon_logon_ctrl2 ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
2001-05-24 12:10:50 +04:00
{
2008-02-14 00:54:43 +03:00
NTSTATUS status = NT_STATUS_UNSUCCESSFUL ;
WERROR werr ;
2008-04-19 23:56:43 +04:00
const char * logon_server = cli - > desthost ;
2008-02-14 00:54:43 +03:00
enum netr_LogonControlCode function_code = NETLOGON_CONTROL_REDISCOVER ;
uint32_t level = 1 ;
union netr_CONTROL_DATA_INFORMATION data ;
union netr_CONTROL_QUERY_INFORMATION query ;
2008-02-14 03:45:07 +03:00
const char * domain = lp_workgroup ( ) ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2012-06-13 18:02:18 +04:00
int i ;
# define fn_code_level(x, item) { x, #x, #item }
struct {
enum netr_LogonControlCode code ;
const char * name ;
const char * argument ;
} supported_levels [ ] = {
fn_code_level ( NETLOGON_CONTROL_REDISCOVER , domain ) ,
fn_code_level ( NETLOGON_CONTROL_TC_QUERY , domain ) ,
fn_code_level ( NETLOGON_CONTROL_TRANSPORT_NOTIFY , domain ) ,
fn_code_level ( NETLOGON_CONTROL_FIND_USER , user ) ,
fn_code_level ( NETLOGON_CONTROL_CHANGE_PASSWORD , domain ) ,
fn_code_level ( NETLOGON_CONTROL_TC_VERIFY , domain ) ,
fn_code_level ( NETLOGON_CONTROL_SET_DBFLAG , debug_level ) ,
{ 0 , 0 , 0 }
} ;
# undef fn_code_level
if ( ( argc > 5 ) | | ( argc < 2 ) ) {
2008-02-14 00:54:43 +03:00
fprintf ( stderr , " Usage: %s <logon_server> <function_code> "
2012-06-13 18:02:18 +04:00
" <level:1..4> <argument> \n " , argv [ 0 ] ) ;
fprintf ( stderr , " Supported combinations: \n " ) ;
fprintf ( stderr , " function_code \t argument \n " ) ;
for ( i = 0 ; supported_levels [ i ] . code ; i + + ) {
fprintf ( stderr , " %7d \t \t %s \t (%s) \n " ,
supported_levels [ i ] . code ,
supported_levels [ i ] . argument ,
supported_levels [ i ] . name ) ;
}
2008-02-14 00:54:43 +03:00
return WERR_OK ;
}
if ( argc > = 2 ) {
logon_server = argv [ 1 ] ;
2001-05-24 12:10:50 +04:00
}
2008-02-14 00:54:43 +03:00
if ( argc > = 3 ) {
function_code = atoi ( argv [ 2 ] ) ;
}
2001-10-12 09:56:23 +04:00
2008-02-14 00:54:43 +03:00
if ( argc > = 4 ) {
level = atoi ( argv [ 3 ] ) ;
}
if ( argc > = 5 ) {
domain = argv [ 4 ] ;
}
switch ( function_code ) {
case NETLOGON_CONTROL_REDISCOVER :
case NETLOGON_CONTROL_TC_QUERY :
2012-06-13 18:02:18 +04:00
case NETLOGON_CONTROL_CHANGE_PASSWORD :
case NETLOGON_CONTROL_TRANSPORT_NOTIFY :
case NETLOGON_CONTROL_TC_VERIFY :
2008-02-14 00:54:43 +03:00
data . domain = domain ;
break ;
2012-06-13 18:02:18 +04:00
case NETLOGON_CONTROL_FIND_USER :
data . user = domain ;
break ;
case NETLOGON_CONTROL_SET_DBFLAG :
data . debug_level = atoi ( domain ) ;
2008-02-14 00:54:43 +03:00
default :
break ;
}
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_LogonControl2 ( b , mem_ctx ,
2008-02-14 00:54:43 +03:00
logon_server ,
function_code ,
level ,
& data ,
& query ,
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return ntstatus_to_werror ( status ) ;
}
if ( ! W_ERROR_IS_OK ( werr ) ) {
return werr ;
}
2001-05-24 12:10:50 +04:00
/* Display results */
2008-02-14 00:54:43 +03:00
return werr ;
2001-05-24 12:10:50 +04:00
}
2007-05-29 19:27:13 +04:00
static WERROR cmd_netlogon_getanydcname ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
2004-04-02 16:56:18 +04:00
{
2008-02-07 12:24:18 +03:00
const char * dcname = NULL ;
WERROR werr ;
NTSTATUS status ;
2006-10-07 09:26:21 +04:00
int old_timeout ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2004-04-02 16:56:18 +04:00
if ( argc ! = 2 ) {
fprintf ( stderr , " Usage: %s domainname \n " , argv [ 0 ] ) ;
2006-10-06 20:13:10 +04:00
return WERR_OK ;
2004-04-02 16:56:18 +04:00
}
2006-10-07 09:26:21 +04:00
/* Make sure to wait for our DC's reply */
2008-04-20 01:27:35 +04:00
old_timeout = rpccli_set_timeout ( cli , 30000 ) ; /* 30 seconds. */
rpccli_set_timeout ( cli , MAX ( old_timeout , 30000 ) ) ; /* At least 30 sec */
2006-10-07 09:26:21 +04:00
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_GetAnyDCName ( b , mem_ctx ,
2008-04-19 23:56:43 +04:00
cli - > desthost ,
2008-02-07 12:24:18 +03:00
argv [ 1 ] ,
& dcname ,
& werr ) ;
2008-04-20 01:27:35 +04:00
rpccli_set_timeout ( cli , old_timeout ) ;
2006-10-07 09:26:21 +04:00
2008-02-07 12:24:18 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return ntstatus_to_werror ( status ) ;
}
if ( ! W_ERROR_IS_OK ( werr ) ) {
return werr ;
}
2006-10-07 09:26:21 +04:00
/* Display results */
printf ( " %s \n " , dcname ) ;
2008-02-07 12:24:18 +03:00
return werr ;
2006-10-07 09:26:21 +04:00
}
2008-02-07 12:24:18 +03:00
static WERROR cmd_netlogon_getdcname ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
2007-06-08 14:29:46 +04:00
const char * * argv )
2006-10-07 09:26:21 +04:00
{
2008-02-07 12:24:18 +03:00
const char * dcname = NULL ;
NTSTATUS status ;
WERROR werr ;
2006-10-07 09:26:21 +04:00
int old_timeout ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2006-10-07 09:26:21 +04:00
if ( argc ! = 2 ) {
fprintf ( stderr , " Usage: %s domainname \n " , argv [ 0 ] ) ;
2007-06-08 14:29:46 +04:00
return WERR_OK ;
2006-10-07 09:26:21 +04:00
}
/* Make sure to wait for our DC's reply */
2008-04-20 01:27:35 +04:00
old_timeout = rpccli_set_timeout ( cli , 30000 ) ; /* 30 seconds. */
rpccli_set_timeout ( cli , MAX ( 30000 , old_timeout ) ) ; /* At least 30 sec */
2006-10-07 09:26:21 +04:00
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_GetDcName ( b , mem_ctx ,
2008-04-19 23:56:43 +04:00
cli - > desthost ,
2008-02-07 12:24:18 +03:00
argv [ 1 ] ,
& dcname ,
& werr ) ;
2008-04-20 01:27:35 +04:00
rpccli_set_timeout ( cli , old_timeout ) ;
2006-10-07 09:26:21 +04:00
2008-02-07 12:24:18 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return ntstatus_to_werror ( status ) ;
}
if ( ! W_ERROR_IS_OK ( werr ) ) {
return werr ;
}
2004-04-02 16:56:18 +04:00
/* Display results */
printf ( " %s \n " , dcname ) ;
2008-02-07 12:24:18 +03:00
return werr ;
2004-04-02 16:56:18 +04:00
}
2005-11-13 14:38:17 +03:00
static WERROR cmd_netlogon_dsr_getdcname ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
2008-02-09 01:28:02 +03:00
NTSTATUS result ;
WERROR werr = WERR_OK ;
2015-05-09 17:33:08 +03:00
uint32_t flags = DS_RETURN_DNS_NAME ;
2008-04-19 23:56:43 +04:00
const char * server_name = cli - > desthost ;
2007-05-25 03:11:11 +04:00
const char * domain_name ;
struct GUID domain_guid = GUID_zero ( ) ;
struct GUID site_guid = GUID_zero ( ) ;
2008-02-09 01:28:02 +03:00
struct netr_DsRGetDCNameInfo * info = NULL ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2007-05-25 03:11:11 +04:00
if ( argc < 2 ) {
2007-08-28 19:01:23 +04:00
fprintf ( stderr , " Usage: %s [domain_name] [domain_guid] "
" [site_guid] [flags] \n " , argv [ 0 ] ) ;
2005-11-13 14:38:17 +03:00
return WERR_OK ;
}
2007-05-25 03:11:11 +04:00
if ( argc > = 2 )
domain_name = argv [ 1 ] ;
if ( argc > = 3 ) {
if ( ! NT_STATUS_IS_OK ( GUID_from_string ( argv [ 2 ] , & domain_guid ) ) ) {
2015-12-03 17:24:16 +03:00
return WERR_NOT_ENOUGH_MEMORY ;
2007-05-25 03:11:11 +04:00
}
}
if ( argc > = 4 ) {
if ( ! NT_STATUS_IS_OK ( GUID_from_string ( argv [ 3 ] , & site_guid ) ) ) {
2015-12-03 17:24:16 +03:00
return WERR_NOT_ENOUGH_MEMORY ;
2007-05-25 03:11:11 +04:00
}
}
if ( argc > = 5 )
sscanf ( argv [ 4 ] , " %x " , & flags ) ;
2007-08-28 19:01:23 +04:00
2011-01-12 14:08:42 +03:00
result = dcerpc_netr_DsRGetDCName ( b , mem_ctx ,
2008-02-09 01:28:02 +03:00
server_name ,
domain_name ,
& domain_guid ,
& site_guid ,
flags ,
& info ,
& werr ) ;
2011-01-12 14:08:42 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
return ntstatus_to_werror ( result ) ;
}
2005-11-13 14:38:17 +03:00
2008-02-09 01:28:02 +03:00
if ( W_ERROR_IS_OK ( werr ) ) {
d_printf ( " DsGetDcName gave: %s \n " ,
NDR_PRINT_STRUCT_STRING ( mem_ctx , netr_DsRGetDCNameInfo , info ) ) ;
2005-11-13 14:38:17 +03:00
return WERR_OK ;
}
printf ( " rpccli_netlogon_dsr_getdcname returned %s \n " ,
2008-11-01 19:19:26 +03:00
win_errstr ( werr ) ) ;
2007-05-25 03:11:11 +04:00
2008-02-09 01:28:02 +03:00
return werr ;
2007-05-25 03:11:11 +04:00
}
static WERROR cmd_netlogon_dsr_getdcnameex ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
WERROR result ;
2008-01-25 23:17:44 +03:00
NTSTATUS status ;
uint32_t flags = DS_RETURN_DNS_NAME ;
2008-04-19 23:56:43 +04:00
const char * server_name = cli - > desthost ;
2007-05-25 03:11:11 +04:00
const char * domain_name ;
const char * site_name = NULL ;
struct GUID domain_guid = GUID_zero ( ) ;
2008-01-25 23:17:44 +03:00
struct netr_DsRGetDCNameInfo * info = NULL ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2007-05-25 03:11:11 +04:00
if ( argc < 2 ) {
2007-08-28 19:01:23 +04:00
fprintf ( stderr , " Usage: %s [domain_name] [domain_guid] "
" [site_name] [flags] \n " , argv [ 0 ] ) ;
2007-05-25 03:11:11 +04:00
return WERR_OK ;
}
2008-01-25 23:17:44 +03:00
domain_name = argv [ 1 ] ;
2007-05-25 03:11:11 +04:00
if ( argc > = 3 ) {
if ( ! NT_STATUS_IS_OK ( GUID_from_string ( argv [ 2 ] , & domain_guid ) ) ) {
2015-12-03 17:24:16 +03:00
return WERR_NOT_ENOUGH_MEMORY ;
2007-05-25 03:11:11 +04:00
}
}
2008-01-25 23:17:44 +03:00
if ( argc > = 4 ) {
2007-05-25 03:11:11 +04:00
site_name = argv [ 3 ] ;
2008-01-25 23:17:44 +03:00
}
2007-05-25 03:11:11 +04:00
2008-01-25 23:17:44 +03:00
if ( argc > = 5 ) {
2007-05-25 03:11:11 +04:00
sscanf ( argv [ 4 ] , " %x " , & flags ) ;
2008-01-25 23:17:44 +03:00
}
2007-05-25 03:11:11 +04:00
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_DsRGetDCNameEx ( b , mem_ctx ,
2008-01-25 23:17:44 +03:00
server_name ,
domain_name ,
& domain_guid ,
site_name ,
flags ,
& info ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return ntstatus_to_werror ( status ) ;
}
2007-05-25 03:11:11 +04:00
2008-01-25 23:17:44 +03:00
if ( ! W_ERROR_IS_OK ( result ) ) {
return result ;
2007-05-25 03:11:11 +04:00
}
2008-01-25 23:17:44 +03:00
d_printf ( " DsRGetDCNameEx gave %s \n " ,
NDR_PRINT_STRUCT_STRING ( mem_ctx , netr_DsRGetDCNameInfo , info ) ) ;
2007-05-25 03:11:11 +04:00
return result ;
}
static WERROR cmd_netlogon_dsr_getdcnameex2 ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
WERROR result ;
2008-01-25 23:17:44 +03:00
NTSTATUS status ;
uint32_t flags = DS_RETURN_DNS_NAME ;
2008-04-19 23:56:43 +04:00
const char * server_name = cli - > desthost ;
2007-05-29 21:57:52 +04:00
const char * domain_name = NULL ;
2007-05-25 03:11:11 +04:00
const char * client_account = NULL ;
2008-01-25 23:17:44 +03:00
uint32_t mask = 0 ;
2007-05-25 03:11:11 +04:00
const char * site_name = NULL ;
struct GUID domain_guid = GUID_zero ( ) ;
2008-01-25 23:17:44 +03:00
struct netr_DsRGetDCNameInfo * info = NULL ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2007-05-25 03:11:11 +04:00
if ( argc < 2 ) {
2007-08-28 19:01:23 +04:00
fprintf ( stderr , " Usage: %s [client_account] [acb_mask] "
" [domain_name] [domain_guid] [site_name] "
" [flags] \n " , argv [ 0 ] ) ;
2007-05-25 03:11:11 +04:00
return WERR_OK ;
}
2008-01-25 23:17:44 +03:00
if ( argc > = 2 ) {
2007-05-25 03:11:11 +04:00
client_account = argv [ 1 ] ;
2008-01-25 23:17:44 +03:00
}
2007-05-25 03:11:11 +04:00
2008-01-25 23:17:44 +03:00
if ( argc > = 3 ) {
2007-05-25 03:11:11 +04:00
mask = atoi ( argv [ 2 ] ) ;
2008-01-25 23:17:44 +03:00
}
2007-08-28 19:01:23 +04:00
2008-01-25 23:17:44 +03:00
if ( argc > = 4 ) {
2007-05-25 03:11:11 +04:00
domain_name = argv [ 3 ] ;
2008-01-25 23:17:44 +03:00
}
2007-05-25 03:11:11 +04:00
if ( argc > = 5 ) {
if ( ! NT_STATUS_IS_OK ( GUID_from_string ( argv [ 4 ] , & domain_guid ) ) ) {
2015-12-03 17:24:16 +03:00
return WERR_NOT_ENOUGH_MEMORY ;
2007-05-25 03:11:11 +04:00
}
}
2008-01-25 23:17:44 +03:00
if ( argc > = 6 ) {
2007-05-25 03:11:11 +04:00
site_name = argv [ 5 ] ;
2008-01-25 23:17:44 +03:00
}
2007-05-25 03:11:11 +04:00
2008-01-25 23:17:44 +03:00
if ( argc > = 7 ) {
2007-05-25 03:11:11 +04:00
sscanf ( argv [ 6 ] , " %x " , & flags ) ;
2008-01-25 23:17:44 +03:00
}
2007-05-25 03:11:11 +04:00
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_DsRGetDCNameEx2 ( b , mem_ctx ,
2008-01-25 23:17:44 +03:00
server_name ,
client_account ,
mask ,
domain_name ,
& domain_guid ,
site_name ,
flags ,
& info ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return ntstatus_to_werror ( status ) ;
}
2007-05-25 03:11:11 +04:00
2008-01-25 23:17:44 +03:00
if ( ! W_ERROR_IS_OK ( result ) ) {
return result ;
2007-05-25 03:11:11 +04:00
}
2008-01-25 23:17:44 +03:00
d_printf ( " DsRGetDCNameEx2 gave %s \n " ,
NDR_PRINT_STRUCT_STRING ( mem_ctx , netr_DsRGetDCNameInfo , info ) ) ;
2005-11-13 14:38:17 +03:00
return result ;
}
2007-05-25 03:11:11 +04:00
2005-11-22 17:10:49 +03:00
static WERROR cmd_netlogon_dsr_getsitename ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
2008-02-07 12:39:08 +03:00
WERROR werr ;
NTSTATUS status ;
const char * sitename = NULL ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2005-11-22 17:10:49 +03:00
if ( argc ! = 2 ) {
fprintf ( stderr , " Usage: %s computername \n " , argv [ 0 ] ) ;
return WERR_OK ;
}
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_DsRGetSiteName ( b , mem_ctx ,
2008-02-07 12:39:08 +03:00
argv [ 1 ] ,
& sitename ,
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return ntstatus_to_werror ( status ) ;
}
2005-11-22 17:10:49 +03:00
2008-02-07 12:39:08 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2005-11-22 17:10:49 +03:00
printf ( " rpccli_netlogon_dsr_gesitename returned %s \n " ,
2008-02-07 12:39:08 +03:00
nt_errstr ( werror_to_ntstatus ( werr ) ) ) ;
return werr ;
2005-11-22 17:10:49 +03:00
}
printf ( " Computer %s is on Site: %s \n " , argv [ 1 ] , sitename ) ;
return WERR_OK ;
}
2008-01-31 01:43:57 +03:00
static WERROR cmd_netlogon_logon_ctrl ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
2001-05-24 12:10:50 +04:00
{
2008-01-31 01:43:57 +03:00
NTSTATUS status = NT_STATUS_UNSUCCESSFUL ;
WERROR werr ;
2008-04-19 23:56:43 +04:00
const char * logon_server = cli - > desthost ;
2008-01-31 01:43:57 +03:00
enum netr_LogonControlCode function_code = 1 ;
uint32_t level = 1 ;
union netr_CONTROL_QUERY_INFORMATION info ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-01-31 01:43:57 +03:00
if ( argc > 4 ) {
fprintf ( stderr , " Usage: %s <logon_server> <function_code> "
" <level> \n " , argv [ 0 ] ) ;
return WERR_OK ;
}
2001-05-24 12:10:50 +04:00
2008-01-31 01:43:57 +03:00
if ( argc > = 2 ) {
logon_server = argv [ 1 ] ;
2001-05-24 12:10:50 +04:00
}
2008-01-31 01:43:57 +03:00
if ( argc > = 3 ) {
function_code = atoi ( argv [ 2 ] ) ;
}
if ( argc > = 4 ) {
level = atoi ( argv [ 3 ] ) ;
}
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_LogonControl ( b , mem_ctx ,
2008-01-31 01:43:57 +03:00
logon_server ,
function_code ,
level ,
& info ,
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return ntstatus_to_werror ( status ) ;
}
if ( ! W_ERROR_IS_OK ( werr ) ) {
return werr ;
2001-05-24 12:10:50 +04:00
}
/* Display results */
2008-01-31 01:43:57 +03:00
return werr ;
2001-05-24 12:10:50 +04:00
}
2001-08-28 10:43:43 +04:00
/* Display sam synchronisation information */
2008-02-15 15:55:18 +03:00
static void display_sam_sync ( struct netr_DELTA_ENUM_ARRAY * r )
2001-08-28 10:43:43 +04:00
{
2008-02-15 15:55:18 +03:00
uint32_t i , j ;
for ( i = 0 ; i < r - > num_deltas ; i + + ) {
union netr_DELTA_UNION u = r - > delta_enum [ i ] . delta_union ;
union netr_DELTA_ID_UNION id = r - > delta_enum [ i ] . delta_id_union ;
switch ( r - > delta_enum [ i ] . delta_type ) {
case NETR_DELTA_DOMAIN :
printf ( " Domain: %s \n " ,
u . domain - > domain_name . string ) ;
break ;
case NETR_DELTA_GROUP :
printf ( " Group: %s \n " ,
u . group - > group_name . string ) ;
break ;
case NETR_DELTA_DELETE_GROUP :
printf ( " Delete Group: %d \n " ,
2011-02-01 19:36:33 +03:00
id . rid ) ;
2008-02-15 15:55:18 +03:00
break ;
case NETR_DELTA_RENAME_GROUP :
printf ( " Rename Group: %s -> %s \n " ,
u . rename_group - > OldName . string ,
u . rename_group - > NewName . string ) ;
break ;
case NETR_DELTA_USER :
printf ( " Account: %s \n " ,
u . user - > account_name . string ) ;
break ;
case NETR_DELTA_DELETE_USER :
printf ( " Delete User: %d \n " ,
id . rid ) ;
break ;
case NETR_DELTA_RENAME_USER :
printf ( " Rename user: %s -> %s \n " ,
u . rename_user - > OldName . string ,
u . rename_user - > NewName . string ) ;
break ;
case NETR_DELTA_GROUP_MEMBER :
for ( j = 0 ; j < u . group_member - > num_rids ; j + + ) {
printf ( " rid 0x%x, attrib 0x%08x \n " ,
u . group_member - > rids [ j ] ,
u . group_member - > attribs [ j ] ) ;
}
break ;
case NETR_DELTA_ALIAS :
printf ( " Alias: %s \n " ,
u . alias - > alias_name . string ) ;
break ;
case NETR_DELTA_DELETE_ALIAS :
printf ( " Delete Alias: %d \n " ,
2011-02-01 19:36:33 +03:00
id . rid ) ;
2008-02-15 15:55:18 +03:00
break ;
case NETR_DELTA_RENAME_ALIAS :
printf ( " Rename alias: %s -> %s \n " ,
u . rename_alias - > OldName . string ,
u . rename_alias - > NewName . string ) ;
break ;
case NETR_DELTA_ALIAS_MEMBER :
for ( j = 0 ; j < u . alias_member - > sids . num_sids ; j + + ) {
fstring sid_str ;
sid_to_fstring ( sid_str ,
u . alias_member - > sids . sids [ j ] . sid ) ;
printf ( " %s \n " , sid_str ) ;
}
break ;
case NETR_DELTA_POLICY :
2011-02-01 19:36:33 +03:00
printf ( " Policy: %s \n " ,
sid_string_dbg ( id . sid ) ) ;
2008-02-15 15:55:18 +03:00
break ;
case NETR_DELTA_TRUSTED_DOMAIN :
printf ( " Trusted Domain: %s \n " ,
u . trusted_domain - > domain_name . string ) ;
break ;
case NETR_DELTA_DELETE_TRUST :
2011-02-01 19:36:33 +03:00
printf ( " Delete Trust: %s \n " ,
sid_string_dbg ( id . sid ) ) ;
2008-02-15 15:55:18 +03:00
break ;
case NETR_DELTA_ACCOUNT :
2011-02-01 19:36:33 +03:00
printf ( " Account: %s \n " ,
sid_string_dbg ( id . sid ) ) ;
2008-02-15 15:55:18 +03:00
break ;
case NETR_DELTA_DELETE_ACCOUNT :
2011-02-01 19:36:33 +03:00
printf ( " Delete Account: %s \n " ,
sid_string_dbg ( id . sid ) ) ;
2008-02-15 15:55:18 +03:00
break ;
case NETR_DELTA_SECRET :
2011-02-01 19:36:33 +03:00
printf ( " Secret: %s \n " ,
id . name ) ;
2008-02-15 15:55:18 +03:00
break ;
case NETR_DELTA_DELETE_SECRET :
2011-02-01 19:36:33 +03:00
printf ( " Delete Secret: %s \n " ,
id . name ) ;
2008-02-15 15:55:18 +03:00
break ;
case NETR_DELTA_DELETE_GROUP2 :
printf ( " Delete Group2: %s \n " ,
u . delete_group - > account_name ) ;
break ;
case NETR_DELTA_DELETE_USER2 :
printf ( " Delete User2: %s \n " ,
u . delete_user - > account_name ) ;
break ;
case NETR_DELTA_MODIFY_COUNT :
printf ( " sam sequence update: 0x%016llx \n " ,
( unsigned long long ) * u . modified_count ) ;
break ;
default :
printf ( " unknown delta type 0x%02x \n " ,
r - > delta_enum [ i ] . delta_type ) ;
break ;
}
}
2001-08-28 10:43:43 +04:00
}
/* Perform sam synchronisation */
2008-02-15 16:11:20 +03:00
static NTSTATUS cmd_netlogon_sam_sync ( struct rpc_pipe_client * cli ,
2001-10-12 09:56:23 +04:00
TALLOC_CTX * mem_ctx , int argc ,
2003-02-26 02:51:56 +03:00
const char * * argv )
2001-08-28 10:43:43 +04:00
{
2001-09-04 14:57:29 +04:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2011-01-12 14:08:42 +03:00
NTSTATUS status ;
2008-04-19 23:56:43 +04:00
const char * logon_server = cli - > desthost ;
2011-06-09 09:31:03 +04:00
const char * computername = lp_netbios_name ( ) ;
2008-02-15 16:11:20 +03:00
struct netr_Authenticator credential ;
struct netr_Authenticator return_authenticator ;
enum netr_SamDatabaseID database_id = SAM_DATABASE_DOMAIN ;
uint16_t restart_state = 0 ;
uint32_t sync_context = 0 ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2001-08-28 10:43:43 +04:00
if ( argc > 2 ) {
2001-10-12 09:56:23 +04:00
fprintf ( stderr , " Usage: %s [database_id] \n " , argv [ 0 ] ) ;
2001-09-04 14:57:29 +04:00
return NT_STATUS_OK ;
2001-08-28 10:43:43 +04:00
}
2008-02-15 16:11:20 +03:00
if ( argc = = 2 ) {
database_id = atoi ( argv [ 1 ] ) ;
}
2001-08-28 10:43:43 +04:00
2008-02-15 16:11:20 +03:00
/* Synchronise sam database */
2001-08-28 10:43:43 +04:00
2008-02-15 16:11:20 +03:00
do {
struct netr_DELTA_ENUM_ARRAY * delta_enum_array = NULL ;
2013-07-27 13:30:13 +04:00
struct netlogon_creds_CredentialState * creds = NULL ;
2001-10-12 09:56:23 +04:00
2013-09-16 21:00:22 +04:00
if ( rpcclient_netlogon_creds = = NULL ) {
return NT_STATUS_UNSUCCESSFUL ;
}
status = netlogon_creds_cli_lock ( rpcclient_netlogon_creds ,
2013-07-27 13:30:13 +04:00
mem_ctx , & creds ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
netlogon_creds_client_authenticator ( creds , & credential ) ;
2001-08-28 10:43:43 +04:00
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_DatabaseSync2 ( b , mem_ctx ,
2008-02-15 16:11:20 +03:00
logon_server ,
computername ,
& credential ,
& return_authenticator ,
database_id ,
restart_state ,
& sync_context ,
& delta_enum_array ,
2011-01-12 14:08:42 +03:00
0xffff ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2013-07-27 13:30:13 +04:00
TALLOC_FREE ( creds ) ;
2011-01-12 14:08:42 +03:00
return status ;
}
2001-08-28 10:43:43 +04:00
2008-02-15 16:11:20 +03:00
/* Check returned credentials. */
2013-07-27 13:30:13 +04:00
if ( ! netlogon_creds_client_check ( creds ,
2008-02-15 16:11:20 +03:00
& return_authenticator . cred ) ) {
DEBUG ( 0 , ( " credentials chain check failed \n " ) ) ;
2013-07-27 13:30:13 +04:00
TALLOC_FREE ( creds ) ;
2008-02-15 16:11:20 +03:00
return NT_STATUS_ACCESS_DENIED ;
}
2013-07-27 13:30:13 +04:00
TALLOC_FREE ( creds ) ;
2001-08-28 10:43:43 +04:00
2008-02-15 16:11:20 +03:00
if ( NT_STATUS_IS_ERR ( result ) ) {
break ;
}
/* Display results */
display_sam_sync ( delta_enum_array ) ;
TALLOC_FREE ( delta_enum_array ) ;
} while ( NT_STATUS_EQUAL ( result , STATUS_MORE_ENTRIES ) ) ;
return result ;
2001-08-28 10:43:43 +04:00
}
/* Perform sam delta synchronisation */
2008-02-15 15:55:18 +03:00
static NTSTATUS cmd_netlogon_sam_deltas ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
2001-08-28 10:43:43 +04:00
{
2001-09-04 14:57:29 +04:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2011-01-12 14:08:42 +03:00
NTSTATUS status ;
2008-02-15 15:55:18 +03:00
uint32_t tmp ;
2008-04-19 23:56:43 +04:00
const char * logon_server = cli - > desthost ;
2011-06-09 09:31:03 +04:00
const char * computername = lp_netbios_name ( ) ;
2008-02-15 15:55:18 +03:00
struct netr_Authenticator credential ;
struct netr_Authenticator return_authenticator ;
enum netr_SamDatabaseID database_id = SAM_DATABASE_DOMAIN ;
uint64_t sequence_num ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-02-15 15:55:18 +03:00
if ( argc ! = 3 ) {
fprintf ( stderr , " Usage: %s database_id seqnum \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
database_id = atoi ( argv [ 1 ] ) ;
tmp = atoi ( argv [ 2 ] ) ;
sequence_num = tmp & 0xffff ;
do {
struct netr_DELTA_ENUM_ARRAY * delta_enum_array = NULL ;
2013-07-27 13:30:13 +04:00
struct netlogon_creds_CredentialState * creds = NULL ;
2013-09-16 21:00:22 +04:00
if ( rpcclient_netlogon_creds = = NULL ) {
return NT_STATUS_UNSUCCESSFUL ;
}
status = netlogon_creds_cli_lock ( rpcclient_netlogon_creds ,
2013-07-27 13:30:13 +04:00
mem_ctx , & creds ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2008-02-15 15:55:18 +03:00
2013-07-27 13:30:13 +04:00
netlogon_creds_client_authenticator ( creds , & credential ) ;
2008-02-15 15:55:18 +03:00
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_DatabaseDeltas ( b , mem_ctx ,
2008-02-15 15:55:18 +03:00
logon_server ,
computername ,
& credential ,
& return_authenticator ,
database_id ,
& sequence_num ,
& delta_enum_array ,
2011-01-12 14:08:42 +03:00
0xffff ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2013-07-27 13:30:13 +04:00
TALLOC_FREE ( creds ) ;
2011-01-12 14:08:42 +03:00
return status ;
}
2008-02-15 15:55:18 +03:00
/* Check returned credentials. */
2013-07-27 13:30:13 +04:00
if ( ! netlogon_creds_client_check ( creds ,
2008-02-15 15:55:18 +03:00
& return_authenticator . cred ) ) {
DEBUG ( 0 , ( " credentials chain check failed \n " ) ) ;
2013-07-27 13:30:13 +04:00
TALLOC_FREE ( creds ) ;
2008-02-15 15:55:18 +03:00
return NT_STATUS_ACCESS_DENIED ;
}
2013-07-27 13:30:13 +04:00
TALLOC_FREE ( creds ) ;
2001-08-28 10:43:43 +04:00
2008-02-15 15:55:18 +03:00
if ( NT_STATUS_IS_ERR ( result ) ) {
break ;
}
2001-08-28 10:43:43 +04:00
2008-02-15 15:55:18 +03:00
/* Display results */
2001-08-28 10:43:43 +04:00
2008-02-15 15:55:18 +03:00
display_sam_sync ( delta_enum_array ) ;
2001-10-12 09:56:23 +04:00
2008-02-15 15:55:18 +03:00
TALLOC_FREE ( delta_enum_array ) ;
2001-08-28 10:43:43 +04:00
2008-02-15 15:55:18 +03:00
} while ( NT_STATUS_EQUAL ( result , STATUS_MORE_ENTRIES ) ) ;
2001-08-28 10:43:43 +04:00
return result ;
}
2001-10-30 04:49:44 +03:00
/* Log on a domain user */
2005-09-30 21:13:37 +04:00
static NTSTATUS cmd_netlogon_sam_logon ( struct rpc_pipe_client * cli ,
2006-03-17 01:54:07 +03:00
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
2001-10-30 04:49:44 +03:00
{
2006-03-17 01:54:07 +03:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2008-10-15 18:14:15 +04:00
int logon_type = NetlogonNetworkInformation ;
2006-03-17 01:54:07 +03:00
const char * username , * password ;
2015-05-09 17:33:08 +03:00
uint32_t logon_param = 0 ;
2007-01-23 13:51:35 +03:00
const char * workstation = NULL ;
2014-07-15 10:28:42 +04:00
struct netr_SamInfo3 * info3 = NULL ;
2001-10-30 04:49:44 +03:00
2006-03-17 01:54:07 +03:00
/* Check arguments */
2001-10-30 04:49:44 +03:00
2013-09-17 02:46:09 +04:00
if ( argc < 3 | | argc > 6 ) {
2007-01-23 13:51:35 +03:00
fprintf ( stderr , " Usage: samlogon <username> <password> [workstation] "
2013-09-17 02:46:09 +04:00
" [logon_type (1 or 2)] [logon_parameter] \n " ) ;
2006-03-17 01:54:07 +03:00
return NT_STATUS_OK ;
}
2001-10-30 04:49:44 +03:00
2006-03-17 01:54:07 +03:00
username = argv [ 1 ] ;
password = argv [ 2 ] ;
2001-10-30 04:49:44 +03:00
2007-01-23 13:51:35 +03:00
if ( argc > = 4 )
workstation = argv [ 3 ] ;
2001-10-30 04:49:44 +03:00
2004-07-26 14:08:03 +04:00
if ( argc > = 5 )
2007-01-23 13:51:35 +03:00
sscanf ( argv [ 4 ] , " %i " , & logon_type ) ;
2002-09-25 19:19:00 +04:00
2013-09-17 02:46:09 +04:00
if ( argc = = 6 )
sscanf ( argv [ 5 ] , " %x " , & logon_param ) ;
2002-09-25 19:19:00 +04:00
2015-11-02 12:59:12 +03:00
if ( rpcclient_netlogon_creds = = NULL ) {
result = NT_STATUS_UNSUCCESSFUL ;
goto done ;
}
2006-03-17 01:54:07 +03:00
/* Perform the sam logon */
2001-10-30 04:49:44 +03:00
2013-09-17 02:48:31 +04:00
result = rpccli_netlogon_password_logon ( rpcclient_netlogon_creds ,
cli - > binding_handle ,
2014-07-15 10:28:42 +04:00
mem_ctx ,
2013-09-17 02:48:31 +04:00
logon_param ,
lp_workgroup ( ) ,
username ,
password ,
workstation ,
2014-07-15 10:28:42 +04:00
logon_type ,
& info3 ) ;
2001-10-30 04:49:44 +03:00
if ( ! NT_STATUS_IS_OK ( result ) )
goto done ;
done :
2006-03-17 01:54:07 +03:00
return result ;
2001-10-30 04:49:44 +03:00
}
2003-08-20 00:39:32 +04:00
/* Change the trust account password */
2005-09-30 21:13:37 +04:00
static NTSTATUS cmd_netlogon_change_trust_pw ( struct rpc_pipe_client * cli ,
2003-08-20 00:39:32 +04:00
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
/* Check arguments */
if ( argc > 1 ) {
fprintf ( stderr , " Usage: change_trust_pw " ) ;
return NT_STATUS_OK ;
}
2013-09-16 20:33:51 +04:00
result = trust_pw_change ( rpcclient_netlogon_creds ,
rpcclient_msg_ctx ,
cli - > binding_handle ,
lp_workgroup ( ) ,
true ) ; /* force */
2003-08-20 00:39:32 +04:00
if ( ! NT_STATUS_IS_OK ( result ) )
goto done ;
done :
return result ;
}
2008-01-25 01:38:43 +03:00
static WERROR cmd_netlogon_gettrustrid ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL ;
WERROR werr = WERR_GENERAL_FAILURE ;
2008-04-19 23:56:43 +04:00
const char * server_name = cli - > desthost ;
2008-01-25 01:38:43 +03:00
const char * domain_name = lp_workgroup ( ) ;
uint32_t rid = 0 ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-01-25 01:38:43 +03:00
if ( argc < 1 | | argc > 3 ) {
fprintf ( stderr , " Usage: %s <server_name> <domain_name> \n " ,
argv [ 0 ] ) ;
return WERR_OK ;
}
if ( argc > = 2 ) {
server_name = argv [ 1 ] ;
}
if ( argc > = 3 ) {
domain_name = argv [ 2 ] ;
}
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_LogonGetTrustRid ( b , mem_ctx ,
2008-01-25 01:38:43 +03:00
server_name ,
domain_name ,
& rid ,
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-01-12 14:08:42 +03:00
werr = ntstatus_to_werror ( status ) ;
2008-01-25 01:38:43 +03:00
goto done ;
}
if ( W_ERROR_IS_OK ( werr ) ) {
printf ( " Rid: %d \n " , rid ) ;
}
done :
return werr ;
}
2008-01-25 18:35:09 +03:00
static WERROR cmd_netlogon_dsr_enumtrustdom ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL ;
WERROR werr = WERR_GENERAL_FAILURE ;
2008-04-19 23:56:43 +04:00
const char * server_name = cli - > desthost ;
2008-01-25 18:35:09 +03:00
uint32_t trust_flags = NETR_TRUST_FLAG_IN_FOREST ;
struct netr_DomainTrustList trusts ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-01-25 18:35:09 +03:00
if ( argc < 1 | | argc > 3 ) {
fprintf ( stderr , " Usage: %s <server_name> <trust_flags> \n " ,
argv [ 0 ] ) ;
return WERR_OK ;
}
if ( argc > = 2 ) {
server_name = argv [ 1 ] ;
}
if ( argc > = 3 ) {
sscanf ( argv [ 2 ] , " %x " , & trust_flags ) ;
}
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_DsrEnumerateDomainTrusts ( b , mem_ctx ,
2008-01-25 18:35:09 +03:00
server_name ,
trust_flags ,
& trusts ,
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-01-12 14:08:42 +03:00
werr = ntstatus_to_werror ( status ) ;
2008-01-25 18:35:09 +03:00
goto done ;
}
if ( W_ERROR_IS_OK ( werr ) ) {
int i ;
printf ( " %d domains returned \n " , trusts . count ) ;
for ( i = 0 ; i < trusts . count ; i + + ) {
printf ( " %s (%s) \n " ,
trusts . array [ i ] . dns_name ,
trusts . array [ i ] . netbios_name ) ;
}
}
done :
return werr ;
}
2008-01-25 01:38:43 +03:00
2008-01-25 23:17:44 +03:00
static WERROR cmd_netlogon_deregisterdnsrecords ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL ;
WERROR werr = WERR_GENERAL_FAILURE ;
2008-04-19 23:56:43 +04:00
const char * server_name = cli - > desthost ;
2008-01-25 23:17:44 +03:00
const char * domain = lp_workgroup ( ) ;
const char * dns_host = NULL ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-01-25 23:17:44 +03:00
if ( argc < 1 | | argc > 4 ) {
fprintf ( stderr , " Usage: %s <server_name> <domain_name> "
" <dns_host> \n " , argv [ 0 ] ) ;
return WERR_OK ;
}
if ( argc > = 2 ) {
server_name = argv [ 1 ] ;
}
if ( argc > = 3 ) {
domain = argv [ 2 ] ;
}
if ( argc > = 4 ) {
dns_host = argv [ 3 ] ;
}
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_DsrDeregisterDNSHostRecords ( b , mem_ctx ,
2008-01-25 23:17:44 +03:00
server_name ,
domain ,
NULL ,
NULL ,
dns_host ,
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-01-12 14:08:42 +03:00
werr = ntstatus_to_werror ( status ) ;
2008-01-25 23:17:44 +03:00
goto done ;
}
if ( W_ERROR_IS_OK ( werr ) ) {
printf ( " success \n " ) ;
}
done :
return werr ;
}
2003-08-20 00:39:32 +04:00
2008-01-25 23:21:33 +03:00
static WERROR cmd_netlogon_dsr_getforesttrustinfo ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL ;
WERROR werr = WERR_GENERAL_FAILURE ;
2008-04-19 23:56:43 +04:00
const char * server_name = cli - > desthost ;
2008-01-25 23:21:33 +03:00
const char * trusted_domain_name = NULL ;
struct lsa_ForestTrustInformation * info = NULL ;
uint32_t flags = 0 ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-01-25 23:21:33 +03:00
if ( argc < 1 | | argc > 4 ) {
fprintf ( stderr , " Usage: %s <server_name> <trusted_domain_name> "
" <flags> \n " , argv [ 0 ] ) ;
return WERR_OK ;
}
if ( argc > = 2 ) {
server_name = argv [ 1 ] ;
}
if ( argc > = 3 ) {
trusted_domain_name = argv [ 2 ] ;
}
if ( argc > = 4 ) {
sscanf ( argv [ 3 ] , " %x " , & flags ) ;
}
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_DsRGetForestTrustInformation ( b , mem_ctx ,
2008-01-25 23:21:33 +03:00
server_name ,
trusted_domain_name ,
flags ,
& info ,
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-01-12 14:08:42 +03:00
werr = ntstatus_to_werror ( status ) ;
2008-01-25 23:21:33 +03:00
goto done ;
}
if ( W_ERROR_IS_OK ( werr ) ) {
printf ( " success \n " ) ;
}
done :
return werr ;
}
2010-05-31 12:15:25 +04:00
static NTSTATUS cmd_netlogon_enumtrusteddomains ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
2008-01-30 04:08:23 +03:00
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL ;
2011-01-12 14:08:42 +03:00
NTSTATUS result ;
2008-04-19 23:56:43 +04:00
const char * server_name = cli - > desthost ;
2008-01-30 04:08:23 +03:00
struct netr_Blob blob ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-01-30 04:08:23 +03:00
if ( argc < 1 | | argc > 3 ) {
fprintf ( stderr , " Usage: %s <server_name> \n " , argv [ 0 ] ) ;
2010-05-31 12:15:25 +04:00
return NT_STATUS_OK ;
2008-01-30 04:08:23 +03:00
}
if ( argc > = 2 ) {
server_name = argv [ 1 ] ;
}
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_NetrEnumerateTrustedDomains ( b , mem_ctx ,
2008-01-30 04:08:23 +03:00
server_name ,
2011-01-12 14:08:42 +03:00
& blob ,
& result ) ;
2008-01-30 04:08:23 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
2011-01-12 14:08:42 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2010-05-31 12:15:25 +04:00
printf ( " success \n " ) ;
dump_data ( 1 , blob . data , blob . length ) ;
2008-01-30 04:08:23 +03:00
done :
2010-05-31 12:15:25 +04:00
return status ;
2008-01-30 04:08:23 +03:00
}
static WERROR cmd_netlogon_enumtrusteddomainsex ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL ;
WERROR werr = WERR_GENERAL_FAILURE ;
2008-04-19 23:56:43 +04:00
const char * server_name = cli - > desthost ;
2008-01-30 04:08:23 +03:00
struct netr_DomainTrustList list ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-01-30 04:08:23 +03:00
if ( argc < 1 | | argc > 3 ) {
fprintf ( stderr , " Usage: %s <server_name> \n " , argv [ 0 ] ) ;
return WERR_OK ;
}
if ( argc > = 2 ) {
server_name = argv [ 1 ] ;
}
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_NetrEnumerateTrustedDomainsEx ( b , mem_ctx ,
2008-01-30 04:08:23 +03:00
server_name ,
& list ,
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-01-12 14:08:42 +03:00
werr = ntstatus_to_werror ( status ) ;
2008-01-30 04:08:23 +03:00
goto done ;
}
if ( W_ERROR_IS_OK ( werr ) ) {
printf ( " success \n " ) ;
}
done :
return werr ;
}
2008-10-27 16:25:03 +03:00
static WERROR cmd_netlogon_getdcsitecoverage ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL ;
WERROR werr = WERR_GENERAL_FAILURE ;
const char * server_name = cli - > desthost ;
struct DcSitesCtr * ctr = NULL ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2008-10-27 16:25:03 +03:00
if ( argc < 1 | | argc > 3 ) {
fprintf ( stderr , " Usage: %s <server_name> \n " , argv [ 0 ] ) ;
return WERR_OK ;
}
if ( argc > = 2 ) {
server_name = argv [ 1 ] ;
}
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_DsrGetDcSiteCoverageW ( b , mem_ctx ,
2008-10-27 16:25:03 +03:00
server_name ,
& ctr ,
& werr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-01-12 14:08:42 +03:00
werr = ntstatus_to_werror ( status ) ;
2008-10-27 16:25:03 +03:00
goto done ;
}
if ( W_ERROR_IS_OK ( werr ) & & ctr - > num_sites ) {
int i ;
printf ( " sites covered by this DC: %d \n " , ctr - > num_sites ) ;
for ( i = 0 ; i < ctr - > num_sites ; i + + ) {
printf ( " %s \n " , ctr - > sites [ i ] . string ) ;
}
}
done :
return werr ;
}
2008-10-31 12:00:28 +03:00
static NTSTATUS cmd_netlogon_database_redo ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL ;
2011-01-12 14:08:42 +03:00
NTSTATUS result ;
2008-10-31 12:00:28 +03:00
const char * server_name = cli - > desthost ;
struct netr_Authenticator clnt_creds , srv_cred ;
struct netr_DELTA_ENUM_ARRAY * delta_enum_array = NULL ;
struct netr_ChangeLogEntry e ;
uint32_t rid = 500 ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2013-07-27 13:30:13 +04:00
struct netlogon_creds_CredentialState * creds = NULL ;
2008-10-31 12:00:28 +03:00
if ( argc > 2 ) {
fprintf ( stderr , " Usage: %s <user rid> \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
if ( argc = = 2 ) {
sscanf ( argv [ 1 ] , " %d " , & rid ) ;
}
2013-09-16 21:00:22 +04:00
if ( rpcclient_netlogon_creds = = NULL ) {
2008-10-31 12:00:28 +03:00
return NT_STATUS_UNSUCCESSFUL ;
}
2013-09-16 21:00:22 +04:00
status = netlogon_creds_cli_lock ( rpcclient_netlogon_creds ,
2013-07-27 13:30:13 +04:00
mem_ctx , & creds ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
netlogon_creds_client_authenticator ( creds , & clnt_creds ) ;
2008-10-31 12:00:28 +03:00
ZERO_STRUCT ( e ) ;
e . object_rid = rid ;
e . db_index = SAM_DATABASE_DOMAIN ;
e . delta_type = NETR_DELTA_USER ;
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_DatabaseRedo ( b , mem_ctx ,
2008-10-31 12:00:28 +03:00
server_name ,
2011-06-09 09:31:03 +04:00
lp_netbios_name ( ) ,
2008-10-31 12:00:28 +03:00
& clnt_creds ,
& srv_cred ,
e ,
0 , /* is calculated automatically */
2011-01-12 14:08:42 +03:00
& delta_enum_array ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2013-07-27 13:30:13 +04:00
TALLOC_FREE ( creds ) ;
2011-01-12 14:08:42 +03:00
return status ;
}
2008-10-31 12:00:28 +03:00
2013-07-27 13:30:13 +04:00
if ( ! netlogon_creds_client_check ( creds , & srv_cred . cred ) ) {
2008-10-31 12:00:28 +03:00
DEBUG ( 0 , ( " credentials chain check failed \n " ) ) ;
2013-07-27 13:30:13 +04:00
TALLOC_FREE ( creds ) ;
2008-10-31 12:00:28 +03:00
return NT_STATUS_ACCESS_DENIED ;
}
2013-07-27 13:30:13 +04:00
TALLOC_FREE ( creds ) ;
2008-10-31 12:00:28 +03:00
2011-01-12 14:08:42 +03:00
return result ;
2008-10-31 12:00:28 +03:00
}
2008-01-30 04:08:23 +03:00
2009-02-26 00:10:21 +03:00
static NTSTATUS cmd_netlogon_capabilities ( struct rpc_pipe_client * cli ,
TALLOC_CTX * mem_ctx , int argc ,
const char * * argv )
{
NTSTATUS status = NT_STATUS_UNSUCCESSFUL ;
2011-01-12 14:08:42 +03:00
NTSTATUS result ;
2009-02-26 00:10:21 +03:00
struct netr_Authenticator credential ;
struct netr_Authenticator return_authenticator ;
union netr_Capabilities capabilities ;
uint32_t level = 1 ;
2011-01-12 14:08:42 +03:00
struct dcerpc_binding_handle * b = cli - > binding_handle ;
2013-07-27 13:30:13 +04:00
struct netlogon_creds_CredentialState * creds = NULL ;
2009-02-26 00:10:21 +03:00
if ( argc > 2 ) {
fprintf ( stderr , " Usage: %s <level> \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
if ( argc = = 2 ) {
level = atoi ( argv [ 1 ] ) ;
}
2009-08-17 19:57:47 +04:00
ZERO_STRUCT ( return_authenticator ) ;
2013-09-16 21:00:22 +04:00
if ( rpcclient_netlogon_creds = = NULL ) {
return NT_STATUS_UNSUCCESSFUL ;
}
status = netlogon_creds_cli_lock ( rpcclient_netlogon_creds ,
2013-07-27 13:30:13 +04:00
mem_ctx , & creds ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
netlogon_creds_client_authenticator ( creds , & credential ) ;
2009-02-26 00:10:21 +03:00
2011-01-12 14:08:42 +03:00
status = dcerpc_netr_LogonGetCapabilities ( b , mem_ctx ,
2009-02-26 00:10:21 +03:00
cli - > desthost ,
2011-06-09 09:31:03 +04:00
lp_netbios_name ( ) ,
2009-02-26 00:10:21 +03:00
& credential ,
& return_authenticator ,
level ,
2011-01-12 14:08:42 +03:00
& capabilities ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2013-07-27 13:30:13 +04:00
TALLOC_FREE ( creds ) ;
2011-01-12 14:08:42 +03:00
return status ;
}
2009-08-17 19:57:47 +04:00
2013-07-27 13:30:13 +04:00
if ( ! netlogon_creds_client_check ( creds ,
2009-02-26 00:10:21 +03:00
& return_authenticator . cred ) ) {
DEBUG ( 0 , ( " credentials chain check failed \n " ) ) ;
2013-07-27 13:30:13 +04:00
TALLOC_FREE ( creds ) ;
2009-02-26 00:10:21 +03:00
return NT_STATUS_ACCESS_DENIED ;
}
2013-07-27 13:30:13 +04:00
TALLOC_FREE ( creds ) ;
2009-08-17 19:57:47 +04:00
printf ( " capabilities: 0x%08x \n " , capabilities . server_capabilities ) ;
2009-02-26 00:10:21 +03:00
2011-01-12 14:08:42 +03:00
return result ;
2009-02-26 00:10:21 +03:00
}
2001-05-24 04:20:32 +04:00
/* List of commands exported by this module */
1999-03-12 08:47:06 +03:00
2001-05-24 04:20:32 +04:00
struct cmd_set netlogon_commands [ ] = {
2001-07-20 08:38:58 +04:00
{ " NETLOGON " } ,
2012-01-10 14:53:42 +04:00
{ " logonctrl2 " , RPC_RTYPE_WERROR , NULL , cmd_netlogon_logon_ctrl2 , & ndr_table_netlogon , NULL , " Logon Control 2 " , " " } ,
{ " getanydcname " , RPC_RTYPE_WERROR , NULL , cmd_netlogon_getanydcname , & ndr_table_netlogon , NULL , " Get trusted DC name " , " " } ,
{ " getdcname " , RPC_RTYPE_WERROR , NULL , cmd_netlogon_getdcname , & ndr_table_netlogon , NULL , " Get trusted PDC name " , " " } ,
{ " dsr_getdcname " , RPC_RTYPE_WERROR , NULL , cmd_netlogon_dsr_getdcname , & ndr_table_netlogon , NULL , " Get trusted DC name " , " " } ,
{ " dsr_getdcnameex " , RPC_RTYPE_WERROR , NULL , cmd_netlogon_dsr_getdcnameex , & ndr_table_netlogon , NULL , " Get trusted DC name " , " " } ,
{ " dsr_getdcnameex2 " , RPC_RTYPE_WERROR , NULL , cmd_netlogon_dsr_getdcnameex2 , & ndr_table_netlogon , NULL , " Get trusted DC name " , " " } ,
{ " dsr_getsitename " , RPC_RTYPE_WERROR , NULL , cmd_netlogon_dsr_getsitename , & ndr_table_netlogon , NULL , " Get sitename " , " " } ,
{ " dsr_getforesttrustinfo " , RPC_RTYPE_WERROR , NULL , cmd_netlogon_dsr_getforesttrustinfo , & ndr_table_netlogon , NULL , " Get Forest Trust Info " , " " } ,
{ " logonctrl " , RPC_RTYPE_WERROR , NULL , cmd_netlogon_logon_ctrl , & ndr_table_netlogon , NULL , " Logon Control " , " " } ,
2015-03-26 16:41:09 +03:00
{ " samsync " , RPC_RTYPE_NTSTATUS , cmd_netlogon_sam_sync , NULL , & ndr_table_netlogon , NULL , " Sam Synchronisation " , " " , . use_netlogon_creds = true , } ,
{ " samdeltas " , RPC_RTYPE_NTSTATUS , cmd_netlogon_sam_deltas , NULL , & ndr_table_netlogon , NULL , " Query Sam Deltas " , " " , . use_netlogon_creds = true , } ,
{ " samlogon " , RPC_RTYPE_NTSTATUS , cmd_netlogon_sam_logon , NULL , & ndr_table_netlogon , NULL , " Sam Logon " , " " , . use_netlogon_creds = true , } ,
{ " change_trust_pw " , RPC_RTYPE_NTSTATUS , cmd_netlogon_change_trust_pw , NULL , & ndr_table_netlogon , NULL , " Change Trust Account Password " , " " , . use_netlogon_creds = true , } ,
2012-01-10 14:53:42 +04:00
{ " gettrustrid " , RPC_RTYPE_WERROR , NULL , cmd_netlogon_gettrustrid , & ndr_table_netlogon , NULL , " Get trust rid " , " " } ,
{ " dsr_enumtrustdom " , RPC_RTYPE_WERROR , NULL , cmd_netlogon_dsr_enumtrustdom , & ndr_table_netlogon , NULL , " Enumerate trusted domains " , " " } ,
{ " dsenumdomtrusts " , RPC_RTYPE_WERROR , NULL , cmd_netlogon_dsr_enumtrustdom , & ndr_table_netlogon , NULL , " Enumerate all trusted domains in an AD forest " , " " } ,
{ " deregisterdnsrecords " , RPC_RTYPE_WERROR , NULL , cmd_netlogon_deregisterdnsrecords , & ndr_table_netlogon , NULL , " Deregister DNS records " , " " } ,
{ " netrenumtrusteddomains " , RPC_RTYPE_NTSTATUS , cmd_netlogon_enumtrusteddomains , NULL , & ndr_table_netlogon , NULL , " Enumerate trusted domains " , " " } ,
{ " netrenumtrusteddomainsex " , RPC_RTYPE_WERROR , NULL , cmd_netlogon_enumtrusteddomainsex , & ndr_table_netlogon , NULL , " Enumerate trusted domains " , " " } ,
{ " getdcsitecoverage " , RPC_RTYPE_WERROR , NULL , cmd_netlogon_getdcsitecoverage , & ndr_table_netlogon , NULL , " Get the Site-Coverage from a DC " , " " } ,
2015-03-26 16:41:09 +03:00
{ " database_redo " , RPC_RTYPE_NTSTATUS , cmd_netlogon_database_redo , NULL , & ndr_table_netlogon , NULL , " Replicate single object from a DC " , " " , . use_netlogon_creds = true , } ,
{ " capabilities " , RPC_RTYPE_NTSTATUS , cmd_netlogon_capabilities , NULL , & ndr_table_netlogon , NULL , " Return Capabilities " , " " , . use_netlogon_creds = true , } ,
2001-07-20 08:38:58 +04:00
{ NULL }
2001-05-24 04:20:32 +04:00
} ;