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
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
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2001-10-12 09:56:23 +04:00
# include "rpcclient.h"
1998-09-26 01:01:52 +04:00
2001-10-12 09:56:23 +04:00
static NTSTATUS cmd_netlogon_logon_ctrl2 ( struct cli_state * cli ,
TALLOC_CTX * mem_ctx , int argc ,
2003-02-26 02:51:56 +03:00
const char * * argv )
2001-05-24 12:10:50 +04:00
{
uint32 query_level = 1 ;
2001-09-04 14:57:29 +04:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2001-05-24 12:10:50 +04:00
if ( argc > 1 ) {
2001-10-12 09:56:23 +04:00
fprintf ( stderr , " Usage: %s \n " , argv [ 0 ] ) ;
2001-09-04 14:57:29 +04:00
return NT_STATUS_OK ;
2001-05-24 12:10:50 +04:00
}
2001-09-04 14:57:29 +04:00
result = cli_netlogon_logon_ctrl2 ( cli , mem_ctx , query_level ) ;
2001-10-12 09:56:23 +04:00
if ( ! NT_STATUS_IS_OK ( result ) )
2001-05-24 12:10:50 +04:00
goto done ;
/* Display results */
done :
return result ;
}
2001-10-12 09:56:23 +04:00
static NTSTATUS cmd_netlogon_logon_ctrl ( struct cli_state * cli ,
TALLOC_CTX * mem_ctx , int argc ,
2003-02-26 02:51:56 +03:00
const char * * argv )
2001-05-24 12:10:50 +04:00
{
2001-06-23 18:58:38 +04:00
#if 0
2001-05-24 12:10:50 +04:00
uint32 query_level = 1 ;
2001-06-23 18:58:38 +04:00
# endif
2001-09-04 14:57:29 +04:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2001-05-24 12:10:50 +04:00
if ( argc > 1 ) {
2001-10-12 09:56:23 +04:00
fprintf ( stderr , " Usage: %s \n " , argv [ 0 ] ) ;
2001-09-04 14:57:29 +04:00
return NT_STATUS_OK ;
2001-05-24 12:10:50 +04:00
}
#if 0
2001-09-04 14:57:29 +04:00
result = cli_netlogon_logon_ctrl ( cli , mem_ctx , query_level ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
2001-05-24 12:10:50 +04:00
goto done ;
}
# endif
/* Display results */
return result ;
}
2001-08-28 10:43:43 +04:00
/* Display sam synchronisation information */
static void display_sam_sync ( uint32 num_deltas , SAM_DELTA_HDR * hdr_deltas ,
SAM_DELTA_CTR * deltas )
{
fstring name ;
uint32 i , j ;
for ( i = 0 ; i < num_deltas ; i + + ) {
switch ( hdr_deltas [ i ] . type ) {
case SAM_DELTA_DOMAIN_INFO :
unistr2_to_ascii ( name ,
& deltas [ i ] . domain_info . uni_dom_name ,
sizeof ( name ) - 1 ) ;
2001-10-12 09:56:23 +04:00
printf ( " Domain: %s \n " , name ) ;
2001-08-28 10:43:43 +04:00
break ;
case SAM_DELTA_GROUP_INFO :
unistr2_to_ascii ( name ,
& deltas [ i ] . group_info . uni_grp_name ,
sizeof ( name ) - 1 ) ;
2001-10-12 09:56:23 +04:00
printf ( " Group: %s \n " , name ) ;
2001-08-28 10:43:43 +04:00
break ;
case SAM_DELTA_ACCOUNT_INFO :
unistr2_to_ascii ( name ,
& deltas [ i ] . account_info . uni_acct_name ,
sizeof ( name ) - 1 ) ;
2001-10-12 09:56:23 +04:00
printf ( " Account: %s \n " , name ) ;
2001-08-28 10:43:43 +04:00
break ;
case SAM_DELTA_ALIAS_INFO :
unistr2_to_ascii ( name ,
& deltas [ i ] . alias_info . uni_als_name ,
sizeof ( name ) - 1 ) ;
2001-10-12 09:56:23 +04:00
printf ( " Alias: %s \n " , name ) ;
2001-08-28 10:43:43 +04:00
break ;
case SAM_DELTA_ALIAS_MEM : {
SAM_ALIAS_MEM_INFO * alias = & deltas [ i ] . als_mem_info ;
for ( j = 0 ; j < alias - > num_members ; j + + ) {
fstring sid_str ;
sid_to_string ( sid_str , & alias - > sids [ j ] . sid ) ;
2001-10-12 09:56:23 +04:00
printf ( " %s \n " , sid_str ) ;
2001-08-28 10:43:43 +04:00
}
break ;
}
case SAM_DELTA_GROUP_MEM : {
SAM_GROUP_MEM_INFO * group = & deltas [ i ] . grp_mem_info ;
for ( j = 0 ; j < group - > num_members ; j + + )
2001-10-12 09:56:23 +04:00
printf ( " rid 0x%x, attrib 0x%08x \n " ,
group - > rids [ j ] , group - > attribs [ j ] ) ;
2001-08-28 10:43:43 +04:00
break ;
}
2002-09-25 19:19:00 +04:00
case SAM_DELTA_MODIFIED_COUNT : {
SAM_DELTA_MOD_COUNT * mc = & deltas [ i ] . mod_count ;
2001-08-28 10:43:43 +04:00
2002-09-25 19:19:00 +04:00
printf ( " sam sequence update: 0x%04x \n " , mc - > seqnum ) ;
2001-08-28 10:43:43 +04:00
break ;
}
default :
2001-10-12 09:56:23 +04:00
printf ( " unknown delta type 0x%02x \n " ,
hdr_deltas [ i ] . type ) ;
2001-08-28 10:43:43 +04:00
break ;
}
}
}
/* Perform sam synchronisation */
2001-10-12 09:56:23 +04:00
static NTSTATUS cmd_netlogon_sam_sync ( struct cli_state * cli ,
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 ;
2001-08-28 10:43:43 +04:00
unsigned char trust_passwd [ 16 ] ;
uint32 database_id = 0 , num_deltas ;
SAM_DELTA_HDR * hdr_deltas ;
SAM_DELTA_CTR * deltas ;
2001-12-13 21:09:29 +03:00
DOM_CRED ret_creds ;
2002-09-25 19:19:00 +04:00
uint32 neg_flags = 0x000001ff ;
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
}
if ( argc = = 2 )
database_id = atoi ( argv [ 1 ] ) ;
if ( ! secrets_init ( ) ) {
2001-10-12 09:56:23 +04:00
fprintf ( stderr , " Unable to initialise secrets database \n " ) ;
2001-08-28 10:43:43 +04:00
return result ;
}
/* Initialise session credentials */
if ( ! secrets_fetch_trust_account_password ( lp_workgroup ( ) , trust_passwd ,
NULL ) ) {
2001-10-12 09:56:23 +04:00
fprintf ( stderr , " could not fetch trust account password \n " ) ;
2001-08-28 10:43:43 +04:00
goto done ;
}
2002-09-25 19:19:00 +04:00
result = cli_nt_setup_creds ( cli , get_sec_chan ( ) , trust_passwd , & neg_flags , 2 ) ;
2001-09-18 06:49:35 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2001-10-12 09:56:23 +04:00
fprintf ( stderr , " Error initialising session creds \n " ) ;
2001-08-28 10:43:43 +04:00
goto done ;
}
2001-12-13 21:09:29 +03:00
/* on first call the returnAuthenticator is empty */
memset ( & ret_creds , 0 , sizeof ( ret_creds ) ) ;
2001-08-28 10:43:43 +04:00
/* Synchronise sam database */
2001-12-13 21:09:29 +03:00
result = cli_netlogon_sam_sync ( cli , mem_ctx , & ret_creds , database_id ,
2002-09-25 19:19:00 +04:00
0 , & num_deltas , & hdr_deltas , & deltas ) ;
2001-10-12 09:56:23 +04:00
if ( ! NT_STATUS_IS_OK ( result ) )
2001-08-28 10:43:43 +04:00
goto done ;
/* Display results */
display_sam_sync ( num_deltas , hdr_deltas , deltas ) ;
done :
return result ;
}
/* Perform sam delta synchronisation */
2001-10-12 09:56:23 +04:00
static NTSTATUS cmd_netlogon_sam_deltas ( struct cli_state * cli ,
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 ;
2001-08-28 10:43:43 +04:00
unsigned char trust_passwd [ 16 ] ;
uint32 database_id , num_deltas , tmp ;
SAM_DELTA_HDR * hdr_deltas ;
SAM_DELTA_CTR * deltas ;
UINT64_S seqnum ;
2002-09-25 19:19:00 +04:00
uint32 neg_flags = 0x000001ff ;
2001-08-28 10:43:43 +04:00
if ( argc ! = 3 ) {
2001-10-12 09:56:23 +04:00
fprintf ( stderr , " Usage: %s database_id seqnum \n " , argv [ 0 ] ) ;
2001-09-04 14:57:29 +04:00
return NT_STATUS_OK ;
2001-08-28 10:43:43 +04:00
}
database_id = atoi ( argv [ 1 ] ) ;
tmp = atoi ( argv [ 2 ] ) ;
seqnum . low = tmp & 0xffff ;
seqnum . high = 0 ;
if ( ! secrets_init ( ) ) {
2001-10-12 09:56:23 +04:00
fprintf ( stderr , " Unable to initialise secrets database \n " ) ;
2001-08-28 10:43:43 +04:00
goto done ;
}
/* Initialise session credentials */
if ( ! secrets_fetch_trust_account_password ( lp_workgroup ( ) , trust_passwd ,
NULL ) ) {
2001-10-12 09:56:23 +04:00
fprintf ( stderr , " could not fetch trust account password \n " ) ;
2001-08-28 10:43:43 +04:00
goto done ;
}
2002-09-25 19:19:00 +04:00
result = cli_nt_setup_creds ( cli , get_sec_chan ( ) , trust_passwd , & neg_flags , 2 ) ;
2001-09-18 06:49:35 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2001-10-12 09:56:23 +04:00
fprintf ( stderr , " Error initialising session creds \n " ) ;
2001-08-28 10:43:43 +04:00
goto done ;
}
/* Synchronise sam database */
2001-09-04 14:57:29 +04:00
result = cli_netlogon_sam_deltas ( cli , mem_ctx , database_id ,
seqnum , & num_deltas ,
& hdr_deltas , & deltas ) ;
2001-10-12 09:56:23 +04:00
if ( ! NT_STATUS_IS_OK ( result ) )
2001-08-28 10:43:43 +04:00
goto done ;
/* Display results */
display_sam_sync ( num_deltas , hdr_deltas , deltas ) ;
done :
return result ;
}
2001-10-30 04:49:44 +03:00
/* Log on a domain user */
static NTSTATUS cmd_netlogon_sam_logon ( struct cli_state * cli ,
TALLOC_CTX * mem_ctx , int argc ,
2003-02-26 02:51:56 +03:00
const char * * argv )
2001-10-30 04:49:44 +03:00
{
unsigned char trust_passwd [ 16 ] ;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2001-10-30 08:41:07 +03:00
int logon_type = NET_LOGON_TYPE ;
2003-02-26 02:51:56 +03:00
const char * username , * password ;
2002-09-25 19:19:00 +04:00
uint32 neg_flags = 0x000001ff ;
int auth_level = 2 ;
2001-10-30 04:49:44 +03:00
/* Check arguments */
2002-09-25 19:19:00 +04:00
if ( argc < 3 | | argc > 6 ) {
2001-10-30 04:49:44 +03:00
fprintf ( stderr , " Usage: samlogon <username> <password> "
2002-09-25 19:19:00 +04:00
" [logon_type] [neg flags] [auth level (2 or 3)] \n "
" neg flags being 0x000001ff or 0x6007ffff \n " ) ;
2001-10-30 04:49:44 +03:00
return NT_STATUS_OK ;
}
username = argv [ 1 ] ;
password = argv [ 2 ] ;
if ( argc = = 4 )
2001-10-30 08:41:07 +03:00
sscanf ( argv [ 3 ] , " %i " , & logon_type ) ;
2001-10-30 04:49:44 +03:00
2002-09-25 19:19:00 +04:00
if ( argc = = 5 )
sscanf ( argv [ 4 ] , " %i " , & neg_flags ) ;
if ( argc = = 6 )
sscanf ( argv [ 5 ] , " %i " , & auth_level ) ;
2001-10-30 04:49:44 +03:00
/* Authenticate ourselves with the domain controller */
if ( ! secrets_init ( ) ) {
fprintf ( stderr , " Unable to initialise secrets database \n " ) ;
return result ;
}
2002-09-25 19:19:00 +04:00
if ( ! secrets_fetch_trust_account_password ( lp_workgroup ( ) , trust_passwd , NULL ) ) {
2001-10-30 04:49:44 +03:00
fprintf ( stderr , " could not fetch trust account password \n " ) ;
goto done ;
}
2002-09-25 19:19:00 +04:00
result = cli_nt_setup_creds ( cli , get_sec_chan ( ) , trust_passwd , & neg_flags , auth_level ) ;
2001-10-30 04:49:44 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
fprintf ( stderr , " Error initialising session creds \n " ) ;
goto done ;
}
/* Perform the sam logon */
2002-09-25 19:19:00 +04:00
result = cli_netlogon_sam_logon ( cli , mem_ctx , username , password , logon_type ) ;
2001-10-30 04:49:44 +03:00
if ( ! NT_STATUS_IS_OK ( result ) )
goto done ;
done :
return result ;
}
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 " } ,
2002-10-04 08:10:23 +04:00
{ " logonctrl2 " , cmd_netlogon_logon_ctrl2 , PI_NETLOGON , " Logon Control 2 " , " " } ,
{ " logonctrl " , cmd_netlogon_logon_ctrl , PI_NETLOGON , " Logon Control " , " " } ,
{ " samsync " , cmd_netlogon_sam_sync , PI_NETLOGON , " Sam Synchronisation " , " " } ,
{ " samdeltas " , cmd_netlogon_sam_deltas , PI_NETLOGON , " Query Sam Deltas " , " " } ,
{ " samlogon " , cmd_netlogon_sam_logon , PI_NETLOGON , " Sam Logon " , " " } ,
2001-07-20 08:38:58 +04:00
{ NULL }
2001-05-24 04:20:32 +04:00
} ;