2008-05-08 13:23:38 +04:00
/*
Samba Unix / Linux SMB client library
Distributed SMB / CIFS Server Management Utility
2001-12-03 07:39:23 +03:00
Copyright ( C ) 2001 Andrew Bartlett ( abartlet @ samba . org )
2002-07-15 14:35:28 +04:00
Copyright ( C ) 2002 Jim McDonough ( jmcd @ us . ibm . com )
2008-02-27 21:38:48 +03:00
Copyright ( C ) 2004 , 2008 Guenther Deschner ( gd @ samba . org )
2005-09-30 21:13:37 +04:00
Copyright ( C ) 2005 Jeremy Allison ( jra @ samba . org )
2006-09-22 03:57:32 +04:00
Copyright ( C ) 2006 Jelmer Vernooij ( jelmer @ samba . org )
2001-12-03 07:39:23 +03: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
2001-12-03 07:39:23 +03:00
( at your option ) any later version .
2008-05-08 13:23:38 +04:00
2001-12-03 07:39:23 +03: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 .
2008-05-08 13:23:38 +04:00
2001-12-03 07:39:23 +03:00
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/>. */
2008-05-08 13:23:38 +04:00
2001-12-03 07:39:23 +03:00
# include "includes.h"
2004-10-07 08:01:18 +04:00
# include "utils/net.h"
2009-03-16 13:27:58 +03:00
# include "../libcli/auth/libcli_auth.h"
2009-11-26 20:21:28 +03:00
# include "../librpc/gen_ndr/cli_samr.h"
2010-05-18 20:25:50 +04:00
# include "rpc_client/cli_samr.h"
2010-05-18 20:59:45 +04:00
# include "rpc_client/init_samr.h"
2009-11-26 20:21:28 +03:00
# include "../librpc/gen_ndr/cli_lsa.h"
2010-05-18 20:26:16 +04:00
# include "rpc_client/cli_lsarpc.h"
2009-11-26 20:21:28 +03:00
# include "../librpc/gen_ndr/cli_netlogon.h"
# include "../librpc/gen_ndr/cli_srvsvc.h"
# include "../librpc/gen_ndr/cli_spoolss.h"
# include "../librpc/gen_ndr/cli_initshutdown.h"
# include "../librpc/gen_ndr/cli_winreg.h"
2010-08-05 04:25:37 +04:00
# include "secrets.h"
2010-08-03 02:03:03 +04:00
# include "lib/netapi/netapi.h"
2010-08-20 01:15:22 +04:00
# include "rpc_client/init_lsa.h"
2001-12-03 07:39:23 +03:00
2005-06-24 03:23:16 +04:00
static int net_mode_share ;
2009-07-05 11:21:07 +04:00
static bool sync_files ( struct copy_clistate * cp_clistate , const char * mask ) ;
2005-06-24 03:23:16 +04:00
2001-12-30 13:54:58 +03:00
/**
* @ file net_rpc . c
*
* @ brief RPC based subcommands for the ' net ' utility .
*
* This file should contain much of the functionality that used to
2008-05-08 13:23:38 +04:00
* be found in rpcclient , execpt that the commands should change
* less often , and the fucntionality should be sane ( the user is not
2001-12-30 13:54:58 +03:00
* expected to know a rid / sid before they conduct an operation etc . )
*
* @ todo Perhaps eventually these should be split out into a number
* of files , as this could get quite big .
* */
/**
* Many of the RPC functions need the domain sid . This function gets
2008-05-08 13:23:38 +04:00
* it at the start of every run
2001-12-30 13:54:58 +03:00
*
* @ param cli A cli_state already connected to the remote machine
*
* @ return The Domain SID of the remote machine .
2001-12-31 16:00:59 +03:00
* */
2001-12-05 03:26:36 +03:00
2006-02-04 01:19:41 +03:00
NTSTATUS net_get_remote_domain_sid ( struct cli_state * cli , TALLOC_CTX * mem_ctx ,
2010-05-21 05:25:01 +04:00
struct dom_sid * * domain_sid ,
2008-01-15 18:40:02 +03:00
const char * * domain_name )
2001-12-05 03:26:36 +03:00
{
2009-03-20 13:07:21 +03:00
struct rpc_pipe_client * lsa_pipe = NULL ;
2009-03-19 00:49:41 +03:00
struct policy_handle pol ;
2001-12-05 03:26:36 +03:00
NTSTATUS result = NT_STATUS_OK ;
2008-02-08 04:12:30 +03:00
union lsa_PolicyInformation * info = NULL ;
2008-07-20 13:04:31 +04:00
result = cli_rpc_pipe_open_noauth ( cli , & ndr_table_lsarpc . syntax_id ,
& lsa_pipe ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Could not initialise lsa pipe \n " ) ) ;
2006-02-04 01:19:41 +03:00
return result ;
2001-12-05 03:26:36 +03:00
}
2008-05-08 13:23:38 +04:00
2008-05-12 13:53:23 +04:00
result = rpccli_lsa_open_policy ( lsa_pipe , mem_ctx , false ,
2009-04-15 03:12:13 +04:00
SEC_FLAG_MAXIMUM_ALLOWED ,
2001-12-05 03:26:36 +03:00
& pol ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
2010-01-19 13:43:54 +03:00
d_fprintf ( stderr , " open_policy %s: %s \n " ,
_ ( " failed " ) ,
nt_errstr ( result ) ) ;
2006-02-04 01:19:41 +03:00
return result ;
2001-12-05 03:26:36 +03:00
}
2008-02-08 04:12:30 +03:00
result = rpccli_lsa_QueryInfoPolicy ( lsa_pipe , mem_ctx ,
& pol ,
LSA_POLICY_INFO_ACCOUNT_DOMAIN ,
& info ) ;
2001-12-05 03:26:36 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2010-01-19 13:43:54 +03:00
d_fprintf ( stderr , " lsaquery %s: %s \n " ,
_ ( " failed " ) ,
nt_errstr ( result ) ) ;
2006-02-04 01:19:41 +03:00
return result ;
2001-12-05 03:26:36 +03:00
}
2008-02-08 04:12:30 +03:00
* domain_name = info - > account_domain . name . string ;
* domain_sid = info - > account_domain . sid ;
2006-09-21 02:49:02 +04:00
rpccli_lsa_Close ( lsa_pipe , mem_ctx , & pol ) ;
2008-04-20 15:51:46 +04:00
TALLOC_FREE ( lsa_pipe ) ;
2001-12-05 03:26:36 +03:00
2006-02-04 01:19:41 +03:00
return NT_STATUS_OK ;
2001-12-05 03:26:36 +03:00
}
2001-12-30 13:54:58 +03:00
/**
* Run a single RPC command , from start to finish .
*
* @ param pipe_name the pipe to connect to ( usually a PIPE_ constant )
2008-05-08 13:23:38 +04:00
* @ param conn_flag a NET_FLAG_ combination . Passed to
2001-12-30 13:54:58 +03:00
* net_make_ipc_connection .
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
* @ return A shell status integer ( 0 for success ) .
2001-12-30 13:54:58 +03:00
*/
2001-12-05 03:26:36 +03:00
2008-05-10 01:22:12 +04:00
int run_rpc_command ( struct net_context * c ,
struct cli_state * cli_arg ,
2009-11-08 21:37:26 +03:00
const struct ndr_syntax_id * interface ,
2005-09-30 21:13:37 +04:00
int conn_flags ,
rpc_command_fn fn ,
int argc ,
2008-05-08 13:23:38 +04:00
const char * * argv )
2001-12-05 03:26:36 +03:00
{
2002-08-17 18:45:04 +04:00
struct cli_state * cli = NULL ;
2005-09-30 21:13:37 +04:00
struct rpc_pipe_client * pipe_hnd = NULL ;
2001-12-05 03:26:36 +03:00
TALLOC_CTX * mem_ctx ;
NTSTATUS nt_status ;
2010-05-21 05:25:01 +04:00
struct dom_sid * domain_sid ;
2008-01-15 18:40:02 +03:00
const char * domain_name ;
2009-03-26 22:29:24 +03:00
int ret = - 1 ;
2001-12-30 13:54:58 +03:00
2002-08-17 18:45:04 +04:00
/* make use of cli_state handed over as an argument, if possible */
2005-09-30 21:13:37 +04:00
if ( ! cli_arg ) {
2008-05-10 01:22:12 +04:00
nt_status = net_make_ipc_connection ( c , conn_flags , & cli ) ;
2007-09-17 19:11:20 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
DEBUG ( 1 , ( " failed to make ipc connection: %s \n " ,
nt_errstr ( nt_status ) ) ) ;
return - 1 ;
}
2005-09-30 21:13:37 +04:00
} else {
2002-08-17 18:45:04 +04:00
cli = cli_arg ;
2005-09-30 21:13:37 +04:00
}
2002-08-17 18:45:04 +04:00
2001-12-30 13:54:58 +03:00
if ( ! cli ) {
return - 1 ;
}
2001-12-05 03:26:36 +03:00
/* Create mem_ctx */
2008-05-08 13:23:38 +04:00
2002-12-20 23:21:31 +03:00
if ( ! ( mem_ctx = talloc_init ( " run_rpc_command " ) ) ) {
2001-12-05 03:26:36 +03:00
DEBUG ( 0 , ( " talloc_init() failed \n " ) ) ;
2009-03-26 22:29:24 +03:00
goto fail ;
2001-12-05 03:26:36 +03:00
}
2008-05-08 13:23:38 +04:00
2006-02-04 01:19:41 +03:00
nt_status = net_get_remote_domain_sid ( cli , mem_ctx , & domain_sid ,
& domain_name ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2009-03-26 22:29:24 +03:00
goto fail ;
2006-02-04 01:19:41 +03:00
}
2004-01-16 18:07:28 +03:00
2004-02-08 13:59:09 +03:00
if ( ! ( conn_flags & NET_FLAGS_NO_PIPE ) ) {
2008-07-20 20:36:31 +04:00
if ( lp_client_schannel ( )
2009-11-08 21:37:26 +03:00
& & ( ndr_syntax_id_equal ( interface ,
2008-07-20 20:36:31 +04:00
& ndr_table_netlogon . syntax_id ) ) ) {
2005-09-30 21:13:37 +04:00
/* Always try and create an schannel netlogon pipe. */
2008-07-20 13:04:31 +04:00
nt_status = cli_rpc_pipe_open_schannel (
2009-11-08 21:37:26 +03:00
cli , interface , NCACN_NP ,
2009-09-14 22:39:54 +04:00
DCERPC_AUTH_LEVEL_PRIVACY , domain_name ,
2008-07-20 13:04:31 +04:00
& pipe_hnd ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2005-09-30 21:13:37 +04:00
DEBUG ( 0 , ( " Could not initialise schannel netlogon pipe. Error was %s \n " ,
nt_errstr ( nt_status ) ) ) ;
2009-03-26 22:29:24 +03:00
goto fail ;
2005-09-30 21:13:37 +04:00
}
} else {
2008-06-24 12:34:16 +04:00
if ( conn_flags & NET_FLAGS_SEAL ) {
2008-07-20 13:04:31 +04:00
nt_status = cli_rpc_pipe_open_ntlmssp (
2009-11-08 21:37:26 +03:00
cli , interface ,
2009-09-11 00:23:21 +04:00
( conn_flags & NET_FLAGS_TCP ) ?
NCACN_IP_TCP : NCACN_NP ,
2009-09-14 22:39:54 +04:00
DCERPC_AUTH_LEVEL_PRIVACY ,
2009-07-05 11:21:07 +04:00
lp_workgroup ( ) , c - > opt_user_name ,
c - > opt_password , & pipe_hnd ) ;
2008-06-24 12:34:16 +04:00
} else {
2008-07-20 13:04:31 +04:00
nt_status = cli_rpc_pipe_open_noauth (
2009-11-08 21:37:26 +03:00
cli , interface ,
& pipe_hnd ) ;
2008-06-24 12:34:16 +04:00
}
2008-07-20 13:04:31 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2005-09-30 21:13:37 +04:00
DEBUG ( 0 , ( " Could not initialise pipe %s. Error was %s \n " ,
2009-10-31 21:28:16 +03:00
get_pipe_name_from_syntax (
2009-11-08 21:37:26 +03:00
talloc_tos ( ) , interface ) ,
2005-09-30 21:13:37 +04:00
nt_errstr ( nt_status ) ) ) ;
2009-03-26 22:29:24 +03:00
goto fail ;
2005-09-30 21:13:37 +04:00
}
2004-02-08 13:59:09 +03:00
}
2001-12-05 03:26:36 +03:00
}
2008-05-08 13:23:38 +04:00
2008-05-10 01:22:12 +04:00
nt_status = fn ( c , domain_sid , domain_name , cli , pipe_hnd , mem_ctx , argc , argv ) ;
2008-05-08 13:23:38 +04:00
2001-12-31 16:00:59 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2002-07-15 14:35:28 +04:00
DEBUG ( 1 , ( " rpc command function failed! (%s) \n " , nt_errstr ( nt_status ) ) ) ;
2001-12-31 16:00:59 +03:00
} else {
2009-03-26 22:29:24 +03:00
ret = 0 ;
2001-12-31 16:00:59 +03:00
DEBUG ( 5 , ( " rpc command function succedded \n " ) ) ;
}
2008-05-08 13:23:38 +04:00
2004-02-08 13:59:09 +03:00
if ( ! ( conn_flags & NET_FLAGS_NO_PIPE ) ) {
2005-09-30 21:13:37 +04:00
if ( pipe_hnd ) {
2008-04-20 15:51:46 +04:00
TALLOC_FREE ( pipe_hnd ) ;
2005-09-30 21:13:37 +04:00
}
2004-02-08 13:59:09 +03:00
}
2009-03-26 22:29:24 +03:00
fail :
2002-08-17 18:45:04 +04:00
/* close the connection only if it was opened here */
2005-09-30 21:13:37 +04:00
if ( ! cli_arg ) {
2002-08-17 18:45:04 +04:00
cli_shutdown ( cli ) ;
2005-09-30 21:13:37 +04:00
}
2008-05-08 13:23:38 +04:00
2001-12-05 03:26:36 +03:00
talloc_destroy ( mem_ctx ) ;
2009-03-26 22:29:24 +03:00
return ret ;
2001-12-05 03:26:36 +03:00
}
2008-05-08 13:23:38 +04:00
/**
2001-12-30 13:54:58 +03:00
* Force a change of the trust acccount password .
*
2002-09-25 19:19:00 +04:00
* All parameters are provided by the run_rpc_command function , except for
2008-06-12 12:55:55 +04:00
* argc , argv which are passed through .
2001-12-30 13:54:58 +03:00
*
2008-06-12 12:55:55 +04:00
* @ param domain_sid The domain sid acquired from the remote server .
2001-12-30 13:54:58 +03:00
* @ param cli A cli_state connected to the server .
2008-06-12 12:55:55 +04:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2001-12-30 13:54:58 +03:00
*
* @ return Normal NTSTATUS return .
* */
2001-12-05 03:26:36 +03:00
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_changetrustpw_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
2005-09-30 21:13:37 +04:00
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
2008-05-08 13:23:38 +04:00
TALLOC_CTX * mem_ctx ,
2005-09-30 21:13:37 +04:00
int argc ,
const char * * argv )
{
2009-10-05 15:01:53 +04:00
NTSTATUS status ;
2008-05-08 13:23:38 +04:00
2009-10-05 15:01:53 +04:00
status = trust_pw_find_change_and_store_it ( pipe_hnd , mem_ctx , c - > opt_target_workgroup ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_fprintf ( stderr , _ ( " Failed to change machine account password: %s \n " ) ,
nt_errstr ( status ) ) ;
return status ;
}
return NT_STATUS_OK ;
2001-12-05 14:00:26 +03:00
}
2008-05-08 13:23:38 +04:00
/**
2001-12-30 13:54:58 +03:00
* Force a change of the trust acccount password .
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2001-12-30 13:54:58 +03:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2001-12-30 13:54:58 +03:00
* */
2008-05-10 01:22:12 +04:00
int net_rpc_changetrustpw ( struct net_context * c , int argc , const char * * argv )
2001-12-05 14:00:26 +03:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc changetrustpw \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Change the machine trust password " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_netlogon . syntax_id ,
2008-07-20 20:36:31 +04:00
NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC ,
2004-02-08 13:59:09 +03:00
rpc_changetrustpw_internals ,
2001-12-05 14:00:26 +03:00
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2001-12-30 13:54:58 +03:00
* Join a domain , the old way .
*
2008-05-08 13:23:38 +04:00
* This uses ' machinename ' as the inital password , and changes it .
2001-12-30 13:54:58 +03:00
*
2003-04-14 08:00:15 +04:00
* The password should be created with ' server manager ' or equiv first .
2001-12-30 13:54:58 +03:00
*
2002-09-25 19:19:00 +04:00
* All parameters are provided by the run_rpc_command function , except for
2008-06-12 12:55:55 +04:00
* argc , argv which are passed through .
2001-12-30 13:54:58 +03:00
*
2008-06-12 12:55:55 +04:00
* @ param domain_sid The domain sid acquired from the remote server .
2001-12-30 13:54:58 +03:00
* @ param cli A cli_state connected to the server .
2008-06-12 12:55:55 +04:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2001-12-30 13:54:58 +03:00
*
* @ return Normal NTSTATUS return .
* */
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_oldjoin_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
struct cli_state * cli ,
2005-09-30 21:13:37 +04:00
struct rpc_pipe_client * pipe_hnd ,
2008-05-08 13:23:38 +04:00
TALLOC_CTX * mem_ctx ,
2005-09-30 21:13:37 +04:00
int argc ,
const char * * argv )
{
2008-05-08 13:23:38 +04:00
2001-12-05 14:00:26 +03:00
fstring trust_passwd ;
unsigned char orig_trust_passwd_hash [ 16 ] ;
2002-09-25 19:19:00 +04:00
NTSTATUS result ;
2009-10-13 12:15:34 +04:00
enum netr_SchannelType sec_channel_type ;
2001-12-05 14:00:26 +03:00
2008-07-20 13:04:31 +04:00
result = cli_rpc_pipe_open_noauth ( cli , & ndr_table_netlogon . syntax_id ,
& pipe_hnd ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
2005-09-30 21:13:37 +04:00
DEBUG ( 0 , ( " rpc_oldjoin_internals: netlogon pipe open to machine %s failed. "
" error was %s \n " ,
cli - > desthost ,
nt_errstr ( result ) ) ) ;
return result ;
}
2008-05-08 13:23:38 +04:00
/*
2003-05-01 06:51:49 +04:00
check what type of join - if the user want ' s to join as
a BDC , the server must agree that we are a BDC .
*/
if ( argc > = 0 ) {
sec_channel_type = get_sec_channel_type ( argv [ 0 ] ) ;
} else {
sec_channel_type = get_sec_channel_type ( NULL ) ;
}
2008-05-08 13:23:38 +04:00
2002-11-13 02:20:50 +03:00
fstrcpy ( trust_passwd , global_myname ( ) ) ;
2003-07-03 23:11:31 +04:00
strlower_m ( trust_passwd ) ;
2002-07-15 14:35:28 +04:00
/*
* Machine names can be 15 characters , but the max length on
* a password is 14. - - jerry
*/
trust_passwd [ 14 ] = ' \0 ' ;
2002-08-17 18:45:04 +04:00
E_md4hash ( trust_passwd , orig_trust_passwd_hash ) ;
2001-12-05 14:00:26 +03:00
2008-05-10 01:22:12 +04:00
result = trust_pw_change_and_store_it ( pipe_hnd , mem_ctx , c - > opt_target_workgroup ,
2009-10-08 02:34:05 +04:00
global_myname ( ) ,
2003-04-21 18:09:03 +04:00
orig_trust_passwd_hash ,
2003-05-01 06:51:49 +04:00
sec_channel_type ) ;
2002-09-25 19:19:00 +04:00
if ( NT_STATUS_IS_OK ( result ) )
2009-08-04 10:28:50 +04:00
printf ( _ ( " Joined domain %s. \n " ) , c - > opt_target_workgroup ) ;
2003-04-21 18:09:03 +04:00
2008-05-10 01:22:12 +04:00
if ( ! secrets_store_domain_sid ( c - > opt_target_workgroup , domain_sid ) ) {
DEBUG ( 0 , ( " error storing domain sid for %s \n " , c - > opt_target_workgroup ) ) ;
2003-04-21 18:09:03 +04:00
result = NT_STATUS_UNSUCCESSFUL ;
}
2002-09-25 19:19:00 +04:00
return result ;
2001-12-05 14:00:26 +03:00
}
2008-05-08 13:23:38 +04:00
/**
2003-04-21 18:09:03 +04:00
* Join a domain , the old way .
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2003-04-21 18:09:03 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2003-04-21 18:09:03 +04:00
* */
2008-05-10 01:22:12 +04:00
static int net_rpc_perform_oldjoin ( struct net_context * c , int argc , const char * * argv )
2003-04-21 18:09:03 +04:00
{
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_netlogon . syntax_id ,
2008-05-08 13:23:38 +04:00
NET_FLAGS_NO_PIPE | NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC ,
2003-05-01 06:51:49 +04:00
rpc_oldjoin_internals ,
2001-12-05 14:00:26 +03:00
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2004-01-16 18:07:28 +03:00
* Join a domain , the old way . This function exists to allow
2008-05-08 13:23:38 +04:00
* the message to be displayed when oldjoin was explicitly
2008-06-12 12:55:55 +04:00
* requested , but not when it was implied by " net rpc join " .
2004-01-16 18:07:28 +03:00
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-01-16 18:07:28 +03:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-01-16 18:07:28 +03:00
* */
2008-05-10 01:22:12 +04:00
static int net_rpc_oldjoin ( struct net_context * c , int argc , const char * * argv )
2004-01-16 18:07:28 +03:00
{
2008-05-21 12:27:59 +04:00
int rc = - 1 ;
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc oldjoin \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Join a domain the old way " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
rc = net_rpc_perform_oldjoin ( c , argc , argv ) ;
2004-01-16 18:07:28 +03:00
if ( rc ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Failed to join domain \n " ) ) ;
2004-01-16 18:07:28 +03:00
}
2004-01-21 17:48:02 +03:00
return rc ;
2004-01-16 18:07:28 +03:00
}
2008-05-08 13:23:38 +04:00
/**
2001-12-30 13:54:58 +03:00
* ' net rpc join ' entrypoint .
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
2001-12-30 13:54:58 +03:00
* stripped
*
2008-05-08 13:23:38 +04:00
* Main ' net_rpc_join ( ) ' ( where the admin username / password is used ) is
2008-06-12 12:55:55 +04:00
* in net_rpc_join . c .
2003-05-01 06:51:49 +04:00
* Try to just change the password , but if that doesn ' t work , use / prompt
* for a username / password .
2001-12-30 13:54:58 +03:00
* */
2008-05-10 01:22:12 +04:00
int net_rpc_join ( struct net_context * c , int argc , const char * * argv )
2001-12-05 14:00:26 +03:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net rpc join -U <username>[%%password] <type> \n "
2009-08-04 10:28:50 +04:00
" Join a domain \n "
" username \t Name of the admin user "
" password \t Password of the admin user, will "
" prompt if not specified \n "
" type \t Can be one of the following: \n "
" \t \t MEMBER \t Join as member server (default) \n "
" \t \t BDC \t Join as BDC \n "
" \t \t PDC \t Join as PDC \n " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2006-04-24 14:09:45 +04:00
if ( lp_server_role ( ) = = ROLE_STANDALONE ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " cannot join as standalone machine \n " ) ) ;
2006-04-18 17:22:14 +04:00
return - 1 ;
}
2006-04-19 19:43:48 +04:00
if ( strlen ( global_myname ( ) ) > 15 ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Our netbios name can be at most 15 chars long, "
" \" %s \" is %u chars long \n " ) ,
2006-06-16 05:47:02 +04:00
global_myname ( ) , ( unsigned int ) strlen ( global_myname ( ) ) ) ;
2006-04-19 19:43:48 +04:00
return - 1 ;
}
2008-05-10 01:22:12 +04:00
if ( ( net_rpc_perform_oldjoin ( c , argc , argv ) = = 0 ) )
2003-04-21 18:09:03 +04:00
return 0 ;
2008-05-08 13:23:38 +04:00
2008-05-10 01:22:12 +04:00
return net_rpc_join_newstyle ( c , argc , argv ) ;
2001-12-05 14:00:26 +03:00
}
2008-05-08 13:23:38 +04:00
/**
2002-07-15 14:35:28 +04:00
* display info about a rpc domain
*
2002-09-25 19:19:00 +04:00
* All parameters are provided by the run_rpc_command function , except for
2008-05-08 13:23:38 +04:00
* argc , argv which are passed through .
2002-07-15 14:35:28 +04:00
*
* @ param domain_sid The domain sid acquired from the remote server
* @ param cli A cli_state connected to the server .
2008-06-12 12:55:55 +04:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-07-15 14:35:28 +04:00
*
* @ return Normal NTSTATUS return .
* */
2008-05-10 01:22:12 +04:00
NTSTATUS rpc_info_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
2005-09-30 21:13:37 +04:00
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2002-07-15 14:35:28 +04:00
{
2009-03-19 00:49:41 +03:00
struct policy_handle connect_pol , domain_pol ;
2002-07-15 14:35:28 +04:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2008-02-05 17:55:11 +03:00
union samr_DomainInfo * info = NULL ;
2002-09-25 19:19:00 +04:00
fstring sid_str ;
2007-12-16 00:47:30 +03:00
sid_to_fstring ( sid_str , domain_sid ) ;
2002-07-15 14:35:28 +04:00
2008-02-04 21:43:07 +03:00
/* Get sam policy handle */
result = rpccli_samr_Connect2 ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2008-02-04 21:43:07 +03:00
MAXIMUM_ALLOWED_ACCESS ,
& connect_pol ) ;
2002-07-15 14:35:28 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Could not connect to SAM: %s \n " ) ,
nt_errstr ( result ) ) ;
2002-07-15 14:35:28 +04:00
goto done ;
}
2008-02-01 13:12:05 +03:00
2002-07-15 14:35:28 +04:00
/* Get domain policy handle */
2008-02-01 13:12:05 +03:00
result = rpccli_samr_OpenDomain ( pipe_hnd , mem_ctx ,
& connect_pol ,
MAXIMUM_ALLOWED_ACCESS ,
CONST_DISCARD ( struct dom_sid2 * , domain_sid ) ,
& domain_pol ) ;
2002-07-15 14:35:28 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Could not open domain: %s \n " ) ,
nt_errstr ( result ) ) ;
2002-07-15 14:35:28 +04:00
goto done ;
}
2008-02-05 17:55:11 +03:00
result = rpccli_samr_QueryDomainInfo ( pipe_hnd , mem_ctx ,
& domain_pol ,
2 ,
& info ) ;
2002-07-15 14:35:28 +04:00
if ( NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Domain Name: %s \n " ) ,
info - > general . domain_name . string ) ;
d_printf ( _ ( " Domain SID: %s \n " ) , sid_str ) ;
d_printf ( _ ( " Sequence number: %llu \n " ) ,
2008-10-15 19:10:53 +04:00
( unsigned long long ) info - > general . sequence_num ) ;
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Num users: %u \n " ) , info - > general . num_users ) ;
d_printf ( _ ( " Num domain groups: %u \n " ) , info - > general . num_groups ) ;
d_printf ( _ ( " Num local groups: %u \n " ) , info - > general . num_aliases ) ;
2002-07-15 14:35:28 +04:00
}
done :
return result ;
}
2008-05-08 13:23:38 +04:00
/**
2002-07-15 14:35:28 +04:00
* ' net rpc info ' entrypoint .
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-07-15 14:35:28 +04:00
* */
2005-09-30 21:13:37 +04:00
2008-05-10 01:22:12 +04:00
int net_rpc_info ( struct net_context * c , int argc , const char * * argv )
2002-07-15 14:35:28 +04:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc info \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Display information about the domain " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_samr . syntax_id ,
2008-07-20 20:36:31 +04:00
NET_FLAGS_PDC , rpc_info_internals ,
2002-07-15 14:35:28 +04:00
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Fetch domain SID into the local secrets . tdb .
2002-09-25 19:19:00 +04:00
*
* All parameters are provided by the run_rpc_command function , except for
2008-06-12 12:55:55 +04:00
* argc , argv which are passed through .
2002-09-25 19:19:00 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param domain_sid The domain sid acquired from the remote server .
2002-09-25 19:19:00 +04:00
* @ param cli A cli_state connected to the server .
2008-06-12 12:55:55 +04:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-09-25 19:19:00 +04:00
*
* @ return Normal NTSTATUS return .
* */
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_getsid_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
2005-09-30 21:13:37 +04:00
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2002-09-25 19:19:00 +04:00
{
fstring sid_str ;
2007-12-16 00:47:30 +03:00
sid_to_fstring ( sid_str , domain_sid ) ;
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Storing SID %s for Domain %s in secrets.tdb \n " ) ,
2004-02-08 13:59:09 +03:00
sid_str , domain_name ) ;
2002-09-25 19:19:00 +04:00
2004-02-08 13:59:09 +03:00
if ( ! secrets_store_domain_sid ( domain_name , domain_sid ) ) {
2002-09-25 19:19:00 +04:00
DEBUG ( 0 , ( " Can't store domain SID \n " ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
return NT_STATUS_OK ;
}
2008-05-08 13:23:38 +04:00
/**
2002-09-25 19:19:00 +04:00
* ' net rpc getsid ' entrypoint .
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-09-25 19:19:00 +04:00
* */
2005-09-30 21:13:37 +04:00
2008-05-10 01:22:12 +04:00
int net_rpc_getsid ( struct net_context * c , int argc , const char * * argv )
2002-09-25 19:19:00 +04:00
{
2010-01-15 02:39:30 +03:00
int conn_flags = NET_FLAGS_PDC ;
if ( ! c - > opt_user_specified ) {
conn_flags | = NET_FLAGS_ANONYMOUS ;
}
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc getsid \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Fetch domain SID into local secrets.tdb " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_samr . syntax_id ,
2010-01-15 02:39:30 +03:00
conn_flags ,
2002-09-25 19:19:00 +04:00
rpc_getsid_internals ,
argc , argv ) ;
}
2002-07-15 14:35:28 +04:00
2001-12-30 13:54:58 +03:00
/****************************************************************************/
2002-04-05 05:36:28 +04:00
/**
2008-06-12 12:55:55 +04:00
* Basic usage function for ' net rpc user ' .
2002-04-05 05:36:28 +04:00
* @ param argc Standard main ( ) style argc .
2008-06-12 12:55:55 +04:00
* @ param argv Standard main ( ) style argv . Initial components are already
2002-04-05 05:36:28 +04:00
* stripped .
* */
2008-05-10 01:22:12 +04:00
static int rpc_user_usage ( struct net_context * c , int argc , const char * * argv )
2002-04-05 05:36:28 +04:00
{
2008-05-13 14:51:09 +04:00
return net_user_usage ( c , argc , argv ) ;
2002-04-05 05:36:28 +04:00
}
2001-12-30 13:54:58 +03:00
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Add a new user to a remote RPC server .
2001-12-30 13:54:58 +03:00
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2001-12-30 13:54:58 +03:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2001-12-30 13:54:58 +03:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_user_add ( struct net_context * c , int argc , const char * * argv )
2001-12-05 03:26:36 +03:00
{
2008-04-16 04:41:52 +04:00
NET_API_STATUS status ;
struct USER_INFO_1 info1 ;
uint32_t parm_error = 0 ;
2008-05-21 12:27:59 +04:00
if ( argc < 1 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
rpc_user_usage ( c , argc , argv ) ;
2008-04-16 04:41:52 +04:00
return 0 ;
}
ZERO_STRUCT ( info1 ) ;
info1 . usri1_name = argv [ 0 ] ;
if ( argc = = 2 ) {
info1 . usri1_password = argv [ 1 ] ;
}
2008-05-10 01:22:12 +04:00
status = NetUserAdd ( c - > opt_host , 1 , ( uint8_t * ) & info1 , & parm_error ) ;
2008-04-16 04:41:52 +04:00
if ( status ! = 0 ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Failed to add user '%s' with error: %s. \n " ) ,
2008-05-10 01:22:12 +04:00
argv [ 0 ] , libnetapi_get_error_string ( c - > netapi_ctx ,
status ) ) ;
2008-04-16 04:41:52 +04:00
return - 1 ;
} else {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Added user '%s'. \n " ) , argv [ 0 ] ) ;
2008-04-16 04:41:52 +04:00
}
return 0 ;
2001-12-05 03:26:36 +03:00
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Rename a user on a remote RPC server .
2005-01-20 19:51:24 +03:00
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2005-01-20 19:51:24 +03:00
*
2008-08-26 23:10:19 +04:00
* @ return A shell status integer ( 0 for success ) .
2005-01-20 19:51:24 +03:00
* */
2008-08-26 23:10:19 +04:00
static int rpc_user_rename ( struct net_context * c , int argc , const char * * argv )
2005-09-30 21:13:37 +04:00
{
2008-08-26 23:10:19 +04:00
NET_API_STATUS status ;
struct USER_INFO_0 u0 ;
uint32_t parm_err = 0 ;
2005-01-20 19:51:24 +03:00
2008-05-21 12:27:59 +04:00
if ( argc ! = 2 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
rpc_user_usage ( c , argc , argv ) ;
2008-08-26 23:10:19 +04:00
return 0 ;
2005-01-20 19:51:24 +03:00
}
2008-08-26 23:10:19 +04:00
u0 . usri0_name = argv [ 1 ] ;
2005-01-20 19:51:24 +03:00
2008-08-26 23:10:19 +04:00
status = NetUserSetInfo ( c - > opt_host , argv [ 0 ] ,
0 , ( uint8_t * ) & u0 , & parm_err ) ;
if ( status ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr ,
_ ( " Failed to rename user from %s to %s - %s \n " ) ,
2008-08-26 23:10:19 +04:00
argv [ 0 ] , argv [ 1 ] ,
libnetapi_get_error_string ( c - > netapi_ctx , status ) ) ;
2005-01-20 19:51:24 +03:00
} else {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Renamed user from %s to %s \n " ) , argv [ 0 ] , argv [ 1 ] ) ;
2005-01-20 19:51:24 +03:00
}
2008-08-26 23:10:19 +04:00
return status ;
2005-01-20 19:51:24 +03:00
}
2010-04-26 18:44:34 +04:00
/**
* Set a user ' s primary group
*
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
*
* @ return A shell status integer ( 0 for success ) .
* */
static int rpc_user_setprimarygroup ( struct net_context * c , int argc ,
const char * * argv )
{
NET_API_STATUS status ;
uint8_t * buffer ;
struct GROUP_INFO_2 * g2 ;
struct USER_INFO_1051 u1051 ;
uint32_t parm_err = 0 ;
if ( argc ! = 2 | | c - > display_usage ) {
rpc_user_usage ( c , argc , argv ) ;
return 0 ;
}
status = NetGroupGetInfo ( c - > opt_host , argv [ 1 ] , 2 , & buffer ) ;
if ( status ) {
d_fprintf ( stderr , _ ( " Failed to find group name %s -- %s \n " ) ,
argv [ 1 ] ,
libnetapi_get_error_string ( c - > netapi_ctx , status ) ) ;
return status ;
}
g2 = ( struct GROUP_INFO_2 * ) buffer ;
u1051 . usri1051_primary_group_id = g2 - > grpi2_group_id ;
NetApiBufferFree ( buffer ) ;
status = NetUserSetInfo ( c - > opt_host , argv [ 0 ] , 1051 ,
( uint8_t * ) & u1051 , & parm_err ) ;
if ( status ) {
d_fprintf ( stderr ,
_ ( " Failed to set user's primary group %s to %s - "
" %s \n " ) , argv [ 0 ] , argv [ 1 ] ,
libnetapi_get_error_string ( c - > netapi_ctx , status ) ) ;
} else {
d_printf ( _ ( " Set primary group of user %s to %s \n " ) , argv [ 0 ] ,
argv [ 1 ] ) ;
}
return status ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Delete a user from a remote RPC server .
2002-04-05 05:36:28 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-04-05 05:36:28 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2002-04-05 05:36:28 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_user_delete ( struct net_context * c , int argc , const char * * argv )
2002-04-05 05:36:28 +04:00
{
2008-04-16 04:39:41 +04:00
NET_API_STATUS status ;
2008-05-21 12:27:59 +04:00
if ( argc < 1 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
rpc_user_usage ( c , argc , argv ) ;
2008-04-16 04:39:41 +04:00
return 0 ;
}
2008-05-10 01:22:12 +04:00
status = NetUserDel ( c - > opt_host , argv [ 0 ] ) ;
2008-04-16 04:39:41 +04:00
if ( status ! = 0 ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Failed to delete user '%s' with: %s. \n " ) ,
2008-04-16 04:39:41 +04:00
argv [ 0 ] ,
2008-05-10 01:22:12 +04:00
libnetapi_get_error_string ( c - > netapi_ctx , status ) ) ;
2008-04-16 04:39:41 +04:00
return - 1 ;
} else {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Deleted user '%s'. \n " ) , argv [ 0 ] ) ;
2008-04-16 04:39:41 +04:00
}
return 0 ;
2002-04-05 05:36:28 +04:00
}
2008-05-08 13:23:38 +04:00
/**
2008-08-27 13:19:49 +04:00
* Set a user ' s password on a remote RPC server .
2004-02-07 06:54:39 +03:00
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-02-07 06:54:39 +03:00
*
2008-08-27 13:19:49 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-02-07 06:54:39 +03:00
* */
2008-08-27 13:19:49 +04:00
static int rpc_user_password ( struct net_context * c , int argc , const char * * argv )
2004-02-07 06:54:39 +03:00
{
2008-08-27 13:19:49 +04:00
NET_API_STATUS status ;
2004-02-07 06:54:39 +03:00
char * prompt = NULL ;
2008-08-27 13:19:49 +04:00
struct USER_INFO_1003 u1003 ;
uint32_t parm_err = 0 ;
2009-08-04 10:28:50 +04:00
int ret ;
2004-02-07 06:54:39 +03:00
2008-05-21 12:27:59 +04:00
if ( argc < 1 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
rpc_user_usage ( c , argc , argv ) ;
2008-08-27 13:19:49 +04:00
return 0 ;
2004-02-07 06:54:39 +03:00
}
2008-05-08 13:23:38 +04:00
2004-02-07 06:54:39 +03:00
if ( argv [ 1 ] ) {
2008-08-27 13:19:49 +04:00
u1003 . usri1003_password = argv [ 1 ] ;
2004-02-07 06:54:39 +03:00
} else {
2009-08-04 10:28:50 +04:00
ret = asprintf ( & prompt , _ ( " Enter new password for %s: " ) ,
argv [ 0 ] ) ;
if ( ret = = - 1 ) {
2009-01-01 05:06:57 +03:00
return - 1 ;
}
2010-05-08 04:16:37 +04:00
u1003 . usri1003_password = talloc_strdup ( c , getpass ( prompt ) ) ;
2004-02-07 06:54:39 +03:00
SAFE_FREE ( prompt ) ;
2010-05-08 04:16:37 +04:00
if ( u1003 . usri1003_password = = NULL ) {
return - 1 ;
}
2004-02-07 06:54:39 +03:00
}
2008-08-27 13:19:49 +04:00
status = NetUserSetInfo ( c - > opt_host , argv [ 0 ] , 1003 , ( uint8_t * ) & u1003 , & parm_err ) ;
2004-02-07 06:54:39 +03:00
/* Display results */
2008-08-27 13:19:49 +04:00
if ( status ! = 0 ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr ,
_ ( " Failed to set password for '%s' with error: %s. \n " ) ,
2008-08-27 13:19:49 +04:00
argv [ 0 ] , libnetapi_get_error_string ( c - > netapi_ctx ,
status ) ) ;
return - 1 ;
}
2004-02-07 06:54:39 +03:00
2008-08-27 13:19:49 +04:00
return 0 ;
2004-02-07 06:54:39 +03:00
}
2008-05-08 13:23:38 +04:00
/**
2008-08-27 15:47:04 +04:00
* List a user ' s groups from a remote RPC server .
2002-04-05 05:36:28 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-04-05 05:36:28 +04:00
*
2008-08-27 15:47:04 +04:00
* @ return A shell status integer ( 0 for success )
2002-04-05 05:36:28 +04:00
* */
2008-08-27 15:47:04 +04:00
static int rpc_user_info ( struct net_context * c , int argc , const char * * argv )
2002-04-05 05:36:28 +04:00
{
2008-08-27 15:47:04 +04:00
NET_API_STATUS status ;
struct GROUP_USERS_INFO_0 * u0 = NULL ;
uint32_t entries_read = 0 ;
uint32_t total_entries = 0 ;
2002-04-05 05:36:28 +04:00
int i ;
2008-02-08 16:50:04 +03:00
2002-04-05 05:36:28 +04:00
2008-05-21 12:27:59 +04:00
if ( argc < 1 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
rpc_user_usage ( c , argc , argv ) ;
2008-08-27 15:47:04 +04:00
return 0 ;
2002-04-05 05:36:28 +04:00
}
2008-08-27 15:47:04 +04:00
status = NetUserGetGroups ( c - > opt_host ,
argv [ 0 ] ,
0 ,
2009-02-01 02:31:16 +03:00
( uint8_t * * ) ( void * ) & u0 ,
2008-08-27 15:47:04 +04:00
( uint32_t ) - 1 ,
& entries_read ,
& total_entries ) ;
if ( status ! = 0 ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr ,
_ ( " Failed to get groups for '%s' with error: %s. \n " ) ,
2008-08-27 15:47:04 +04:00
argv [ 0 ] , libnetapi_get_error_string ( c - > netapi_ctx ,
status ) ) ;
return - 1 ;
2005-02-10 21:27:23 +03:00
}
2002-04-05 05:36:28 +04:00
2008-08-27 15:47:04 +04:00
for ( i = 0 ; i < entries_read ; i + + ) {
printf ( " %s \n " , u0 - > grui0_name ) ;
u0 + + ;
}
2002-04-05 05:36:28 +04:00
2008-08-27 15:47:04 +04:00
return 0 ;
2002-04-05 05:36:28 +04:00
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* List users on a remote RPC server .
2002-04-05 05:36:28 +04:00
*
2002-09-25 19:19:00 +04:00
* All parameters are provided by the run_rpc_command function , except for
2008-06-12 12:55:55 +04:00
* argc , argv which are passed through .
2002-04-05 05:36:28 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param domain_sid The domain sid acquired from the remote server .
2002-04-05 05:36:28 +04:00
* @ param cli A cli_state connected to the server .
2008-06-12 12:55:55 +04:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-04-05 05:36:28 +04:00
*
* @ return Normal NTSTATUS return .
* */
2008-08-27 13:14:15 +04:00
static int rpc_user_list ( struct net_context * c , int argc , const char * * argv )
2002-04-05 05:36:28 +04:00
{
2008-08-27 13:14:15 +04:00
NET_API_STATUS status ;
uint32_t start_idx = 0 , num_entries , i , loop_count = 0 ;
struct NET_DISPLAY_USER * info = NULL ;
void * buffer = NULL ;
2002-04-05 05:36:28 +04:00
/* Query domain users */
2008-05-10 01:22:12 +04:00
if ( c - > opt_long_list_entries )
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " \n User name Comment "
" \n ----------------------------- \n " ) ) ;
2002-04-05 05:36:28 +04:00
do {
2008-08-27 13:14:15 +04:00
uint32_t max_entries , max_size ;
2003-01-29 23:15:35 +03:00
get_query_dispinfo_params (
loop_count , & max_entries , & max_size ) ;
2008-08-27 13:14:15 +04:00
status = NetQueryDisplayInformation ( c - > opt_host ,
1 ,
start_idx ,
max_entries ,
max_size ,
& num_entries ,
& buffer ) ;
if ( status ! = 0 & & status ! = ERROR_MORE_DATA ) {
return status ;
}
info = ( struct NET_DISPLAY_USER * ) buffer ;
2003-01-29 23:15:35 +03:00
2002-04-05 05:36:28 +04:00
for ( i = 0 ; i < num_entries ; i + + ) {
2008-08-27 13:14:15 +04:00
2008-05-10 01:22:12 +04:00
if ( c - > opt_long_list_entries )
2008-08-27 13:14:15 +04:00
printf ( " %-21.21s %s \n " , info - > usri1_name ,
info - > usri1_comment ) ;
2002-04-05 05:36:28 +04:00
else
2008-08-27 13:14:15 +04:00
printf ( " %s \n " , info - > usri1_name ) ;
info + + ;
2002-04-05 05:36:28 +04:00
}
2008-08-27 13:14:15 +04:00
NetApiBufferFree ( buffer ) ;
loop_count + + ;
start_idx + = num_entries ;
} while ( status = = ERROR_MORE_DATA ) ;
return status ;
2001-12-05 03:26:36 +03:00
}
2008-05-08 13:23:38 +04:00
/**
2001-12-30 13:54:58 +03:00
* ' net rpc user ' entrypoint .
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2001-12-30 13:54:58 +03:00
* */
2008-05-10 01:22:12 +04:00
int net_rpc_user ( struct net_context * c , int argc , const char * * argv )
2001-12-05 03:26:36 +03:00
{
2008-04-16 04:39:41 +04:00
NET_API_STATUS status ;
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 12:27:59 +04:00
{
" add " ,
rpc_user_add ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Add specified user " ) ,
N_ ( " net rpc user add \n "
" Add specified user " )
2008-05-21 12:27:59 +04:00
} ,
{
" info " ,
rpc_user_info ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " List domain groups of user " ) ,
N_ ( " net rpc user info \n "
2010-07-26 17:04:52 +04:00
" List domain groups of user " )
2008-05-21 12:27:59 +04:00
} ,
{
" delete " ,
rpc_user_delete ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Remove specified user " ) ,
N_ ( " net rpc user delete \n "
" Remove specified user " )
2008-05-21 12:27:59 +04:00
} ,
{
" password " ,
rpc_user_password ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Change user password " ) ,
N_ ( " net rpc user password \n "
" Change user password " )
2008-05-21 12:27:59 +04:00
} ,
{
" rename " ,
rpc_user_rename ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Rename specified user " ) ,
N_ ( " net rpc user rename \n "
" Rename specified user " )
2008-05-21 12:27:59 +04:00
} ,
2010-04-26 18:44:34 +04:00
{
" setprimarygroup " ,
rpc_user_setprimarygroup ,
NET_TRANSPORT_RPC ,
" Set a user's primary group " ,
" net rpc user setprimarygroup \n "
" Set a user's primary group "
} ,
2008-05-21 12:27:59 +04:00
{ NULL , NULL , 0 , NULL , NULL }
2001-12-05 03:26:36 +03:00
} ;
2008-04-16 04:39:41 +04:00
2008-05-10 01:22:12 +04:00
status = libnetapi_init ( & c - > netapi_ctx ) ;
2008-04-16 04:39:41 +04:00
if ( status ! = 0 ) {
return - 1 ;
}
2009-07-05 11:21:07 +04:00
libnetapi_set_username ( c - > netapi_ctx , c - > opt_user_name ) ;
libnetapi_set_password ( c - > netapi_ctx , c - > opt_password ) ;
if ( c - > opt_kerberos ) {
2008-07-31 17:14:14 +04:00
libnetapi_set_use_kerberos ( c - > netapi_ctx ) ;
}
2008-04-16 04:39:41 +04:00
2001-12-05 03:26:36 +03:00
if ( argc = = 0 ) {
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2010-01-19 01:39:19 +03:00
" net rpc user \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " List all users " ) ) ;
2008-05-21 12:27:59 +04:00
net_display_usage_from_functable ( func ) ;
return 0 ;
}
2008-08-27 13:14:15 +04:00
return rpc_user_list ( c , argc , argv ) ;
2001-12-05 03:26:36 +03:00
}
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rpc user " , func ) ;
2001-12-05 03:26:36 +03:00
}
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_sh_user_list ( struct net_context * c ,
TALLOC_CTX * mem_ctx ,
2006-02-04 01:19:41 +03:00
struct rpc_sh_ctx * ctx ,
struct rpc_pipe_client * pipe_hnd ,
int argc , const char * * argv )
{
2008-08-27 13:14:15 +04:00
return werror_to_ntstatus ( W_ERROR ( rpc_user_list ( c , argc , argv ) ) ) ;
2006-02-04 01:19:41 +03:00
}
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_sh_user_info ( struct net_context * c ,
TALLOC_CTX * mem_ctx ,
2006-02-04 01:19:41 +03:00
struct rpc_sh_ctx * ctx ,
struct rpc_pipe_client * pipe_hnd ,
int argc , const char * * argv )
{
2008-08-27 15:47:04 +04:00
return werror_to_ntstatus ( W_ERROR ( rpc_user_info ( c , argc , argv ) ) ) ;
2006-02-04 01:19:41 +03:00
}
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_sh_handle_user ( struct net_context * c ,
TALLOC_CTX * mem_ctx ,
2006-02-04 01:19:41 +03:00
struct rpc_sh_ctx * ctx ,
struct rpc_pipe_client * pipe_hnd ,
int argc , const char * * argv ,
NTSTATUS ( * fn ) (
2008-05-10 01:22:12 +04:00
struct net_context * c ,
2006-02-04 01:19:41 +03:00
TALLOC_CTX * mem_ctx ,
struct rpc_sh_ctx * ctx ,
struct rpc_pipe_client * pipe_hnd ,
2009-03-19 00:49:41 +03:00
struct policy_handle * user_hnd ,
2006-02-04 01:19:41 +03:00
int argc , const char * * argv ) )
{
2009-03-19 00:49:41 +03:00
struct policy_handle connect_pol , domain_pol , user_pol ;
2006-02-04 01:19:41 +03:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2010-05-21 05:25:01 +04:00
struct dom_sid sid ;
2006-02-04 01:19:41 +03:00
uint32 rid ;
2006-09-08 18:28:06 +04:00
enum lsa_SidType type ;
2006-02-04 01:19:41 +03:00
if ( argc = = 0 ) {
2010-01-19 13:43:54 +03:00
d_fprintf ( stderr , " %s %s <username> \n " , _ ( " Usage: " ) ,
ctx - > whoami ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_INVALID_PARAMETER ;
}
ZERO_STRUCT ( connect_pol ) ;
ZERO_STRUCT ( domain_pol ) ;
ZERO_STRUCT ( user_pol ) ;
2008-05-10 01:22:12 +04:00
result = net_rpc_lookup_name ( c , mem_ctx , rpc_pipe_np_smb_conn ( pipe_hnd ) ,
2008-04-20 16:05:25 +04:00
argv [ 0 ] , NULL , NULL , & sid , & type ) ;
2006-02-04 01:19:41 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Could not lookup %s: %s \n " ) , argv [ 0 ] ,
2006-02-04 01:19:41 +03:00
nt_errstr ( result ) ) ;
goto done ;
}
if ( type ! = SID_NAME_USER ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " %s is a %s, not a user \n " ) , argv [ 0 ] ,
2006-02-04 01:19:41 +03:00
sid_type_lookup ( type ) ) ;
result = NT_STATUS_NO_SUCH_USER ;
goto done ;
}
if ( ! sid_peek_check_rid ( ctx - > domain_sid , & sid , & rid ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " %s is not in our domain \n " ) , argv [ 0 ] ) ;
2006-02-04 01:19:41 +03:00
result = NT_STATUS_NO_SUCH_USER ;
goto done ;
}
2008-02-04 21:43:07 +03:00
result = rpccli_samr_Connect2 ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2008-02-04 21:43:07 +03:00
MAXIMUM_ALLOWED_ACCESS ,
& connect_pol ) ;
2006-02-04 01:19:41 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
goto done ;
}
2008-02-01 13:12:05 +03:00
result = rpccli_samr_OpenDomain ( pipe_hnd , mem_ctx ,
& connect_pol ,
MAXIMUM_ALLOWED_ACCESS ,
ctx - > domain_sid ,
& domain_pol ) ;
2006-02-04 01:19:41 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
goto done ;
}
2008-02-01 13:57:53 +03:00
result = rpccli_samr_OpenUser ( pipe_hnd , mem_ctx ,
& domain_pol ,
MAXIMUM_ALLOWED_ACCESS ,
rid ,
& user_pol ) ;
2006-02-04 01:19:41 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
goto done ;
}
2008-05-10 01:22:12 +04:00
result = fn ( c , mem_ctx , ctx , pipe_hnd , & user_pol , argc - 1 , argv + 1 ) ;
2006-02-04 01:19:41 +03:00
done :
if ( is_valid_policy_hnd ( & user_pol ) ) {
2008-01-30 14:39:20 +03:00
rpccli_samr_Close ( pipe_hnd , mem_ctx , & user_pol ) ;
2006-02-04 01:19:41 +03:00
}
if ( is_valid_policy_hnd ( & domain_pol ) ) {
2008-01-30 14:39:20 +03:00
rpccli_samr_Close ( pipe_hnd , mem_ctx , & domain_pol ) ;
2006-02-04 01:19:41 +03:00
}
if ( is_valid_policy_hnd ( & connect_pol ) ) {
2008-01-30 14:39:20 +03:00
rpccli_samr_Close ( pipe_hnd , mem_ctx , & connect_pol ) ;
2006-02-04 01:19:41 +03:00
}
return result ;
}
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_sh_user_show_internals ( struct net_context * c ,
TALLOC_CTX * mem_ctx ,
2006-02-04 01:19:41 +03:00
struct rpc_sh_ctx * ctx ,
struct rpc_pipe_client * pipe_hnd ,
2009-03-19 00:49:41 +03:00
struct policy_handle * user_hnd ,
2006-02-04 01:19:41 +03:00
int argc , const char * * argv )
{
NTSTATUS result ;
2008-02-12 20:13:30 +03:00
union samr_UserInfo * info = NULL ;
2006-02-04 01:19:41 +03:00
if ( argc ! = 0 ) {
2010-01-19 13:43:54 +03:00
d_fprintf ( stderr , " %s %s show <username> \n " , _ ( " Usage: " ) ,
ctx - > whoami ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_INVALID_PARAMETER ;
}
2008-02-12 20:13:30 +03:00
result = rpccli_samr_QueryUserInfo ( pipe_hnd , mem_ctx ,
2008-02-13 16:10:10 +03:00
user_hnd ,
2008-02-12 20:13:30 +03:00
21 ,
& info ) ;
2006-02-04 01:19:41 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
}
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " user rid: %d, group rid: %d \n " ) ,
2008-02-12 20:13:30 +03:00
info - > info21 . rid ,
info - > info21 . primary_gid ) ;
2006-02-04 01:19:41 +03:00
return result ;
}
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_sh_user_show ( struct net_context * c ,
TALLOC_CTX * mem_ctx ,
2006-02-04 01:19:41 +03:00
struct rpc_sh_ctx * ctx ,
struct rpc_pipe_client * pipe_hnd ,
int argc , const char * * argv )
{
2008-05-10 01:22:12 +04:00
return rpc_sh_handle_user ( c , mem_ctx , ctx , pipe_hnd , argc , argv ,
2006-02-04 01:19:41 +03:00
rpc_sh_user_show_internals ) ;
}
# define FETCHSTR(name, rec) \
do { if ( strequal ( ctx - > thiscmd , name ) ) { \
2008-02-12 20:13:30 +03:00
oldval = talloc_strdup ( mem_ctx , info - > info21 . rec . string ) ; } \
2006-02-04 01:19:41 +03:00
} while ( 0 ) ;
# define SETSTR(name, rec, flag) \
do { if ( strequal ( ctx - > thiscmd , name ) ) { \
2008-02-12 02:51:51 +03:00
init_lsa_String ( & ( info - > info21 . rec ) , argv [ 0 ] ) ; \
info - > info21 . fields_present | = SAMR_FIELD_ # # flag ; } \
2006-02-04 01:19:41 +03:00
} while ( 0 ) ;
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_sh_user_str_edit_internals ( struct net_context * c ,
TALLOC_CTX * mem_ctx ,
2006-02-04 01:19:41 +03:00
struct rpc_sh_ctx * ctx ,
struct rpc_pipe_client * pipe_hnd ,
2009-03-19 00:49:41 +03:00
struct policy_handle * user_hnd ,
2006-02-04 01:19:41 +03:00
int argc , const char * * argv )
{
NTSTATUS result ;
const char * username ;
const char * oldval = " " ;
2008-02-12 20:13:30 +03:00
union samr_UserInfo * info = NULL ;
2006-02-04 01:19:41 +03:00
if ( argc > 1 ) {
2010-01-19 13:43:54 +03:00
d_fprintf ( stderr , " %s %s <username> [new value|NULL] \n " ,
_ ( " Usage: " ) , ctx - > whoami ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_INVALID_PARAMETER ;
}
2008-02-12 20:13:30 +03:00
result = rpccli_samr_QueryUserInfo ( pipe_hnd , mem_ctx ,
2008-02-13 16:10:10 +03:00
user_hnd ,
2008-02-12 20:13:30 +03:00
21 ,
& info ) ;
2006-02-04 01:19:41 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
}
2008-02-12 20:13:30 +03:00
username = talloc_strdup ( mem_ctx , info - > info21 . account_name . string ) ;
2006-02-04 01:19:41 +03:00
FETCHSTR ( " fullname " , full_name ) ;
2008-02-12 20:13:30 +03:00
FETCHSTR ( " homedir " , home_directory ) ;
FETCHSTR ( " homedrive " , home_drive ) ;
2006-02-04 01:19:41 +03:00
FETCHSTR ( " logonscript " , logon_script ) ;
FETCHSTR ( " profilepath " , profile_path ) ;
2008-02-12 20:13:30 +03:00
FETCHSTR ( " description " , description ) ;
2006-02-04 01:19:41 +03:00
if ( argc = = 0 ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " %s's %s: [%s] \n " ) , username , ctx - > thiscmd , oldval ) ;
2006-02-04 01:19:41 +03:00
goto done ;
}
if ( strcmp ( argv [ 0 ] , " NULL " ) = = 0 ) {
argv [ 0 ] = " " ;
}
2008-02-12 02:51:51 +03:00
ZERO_STRUCT ( info - > info21 ) ;
2006-02-04 01:19:41 +03:00
SETSTR ( " fullname " , full_name , FULL_NAME ) ;
2008-02-12 02:51:51 +03:00
SETSTR ( " homedir " , home_directory , HOME_DIRECTORY ) ;
SETSTR ( " homedrive " , home_drive , HOME_DRIVE ) ;
2006-02-04 01:19:41 +03:00
SETSTR ( " logonscript " , logon_script , LOGON_SCRIPT ) ;
2008-02-12 02:07:41 +03:00
SETSTR ( " profilepath " , profile_path , PROFILE_PATH ) ;
2008-02-12 02:51:51 +03:00
SETSTR ( " description " , description , DESCRIPTION ) ;
2006-02-04 01:19:41 +03:00
2008-02-12 02:51:51 +03:00
result = rpccli_samr_SetUserInfo ( pipe_hnd , mem_ctx ,
2008-02-13 16:10:10 +03:00
user_hnd ,
2008-02-12 02:51:51 +03:00
21 ,
info ) ;
2006-02-04 01:19:41 +03:00
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Set %s's %s from [%s] to [%s] \n " ) , username ,
2006-02-04 01:19:41 +03:00
ctx - > thiscmd , oldval , argv [ 0 ] ) ;
done :
return result ;
}
# define HANDLEFLG(name, rec) \
do { if ( strequal ( ctx - > thiscmd , name ) ) { \
oldval = ( oldflags & ACB_ # # rec ) ? " yes " : " no " ; \
if ( newval ) { \
newflags = oldflags | ACB_ # # rec ; \
} else { \
newflags = oldflags & ~ ACB_ # # rec ; \
} } } while ( 0 ) ;
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_sh_user_str_edit ( struct net_context * c ,
TALLOC_CTX * mem_ctx ,
2006-02-04 01:19:41 +03:00
struct rpc_sh_ctx * ctx ,
struct rpc_pipe_client * pipe_hnd ,
int argc , const char * * argv )
{
2008-05-10 01:22:12 +04:00
return rpc_sh_handle_user ( c , mem_ctx , ctx , pipe_hnd , argc , argv ,
2006-02-04 01:19:41 +03:00
rpc_sh_user_str_edit_internals ) ;
}
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_sh_user_flag_edit_internals ( struct net_context * c ,
TALLOC_CTX * mem_ctx ,
2006-02-04 01:19:41 +03:00
struct rpc_sh_ctx * ctx ,
struct rpc_pipe_client * pipe_hnd ,
2009-03-19 00:49:41 +03:00
struct policy_handle * user_hnd ,
2006-02-04 01:19:41 +03:00
int argc , const char * * argv )
{
NTSTATUS result ;
const char * username ;
const char * oldval = " unknown " ;
uint32 oldflags , newflags ;
2007-10-19 04:40:25 +04:00
bool newval ;
2008-02-12 20:13:30 +03:00
union samr_UserInfo * info = NULL ;
2006-02-04 01:19:41 +03:00
if ( ( argc > 1 ) | |
( ( argc = = 1 ) & & ! strequal ( argv [ 0 ] , " yes " ) & &
! strequal ( argv [ 0 ] , " no " ) ) ) {
2009-08-04 10:28:50 +04:00
/* TRANSATORS: The yes|no here are program keywords. Please do
not translate . */
2010-01-19 11:23:42 +03:00
d_fprintf ( stderr , _ ( " Usage: %s <username> [yes|no] \n " ) ,
2006-02-04 01:19:41 +03:00
ctx - > whoami ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
newval = strequal ( argv [ 0 ] , " yes " ) ;
2008-02-12 20:13:30 +03:00
result = rpccli_samr_QueryUserInfo ( pipe_hnd , mem_ctx ,
2008-02-13 16:10:10 +03:00
user_hnd ,
2008-02-12 20:13:30 +03:00
21 ,
& info ) ;
2006-02-04 01:19:41 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
}
2008-02-12 20:13:30 +03:00
username = talloc_strdup ( mem_ctx , info - > info21 . account_name . string ) ;
oldflags = info - > info21 . acct_flags ;
newflags = info - > info21 . acct_flags ;
2006-02-04 01:19:41 +03:00
HANDLEFLG ( " disabled " , DISABLED ) ;
HANDLEFLG ( " pwnotreq " , PWNOTREQ ) ;
HANDLEFLG ( " autolock " , AUTOLOCK ) ;
HANDLEFLG ( " pwnoexp " , PWNOEXP ) ;
if ( argc = = 0 ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " %s's %s flag: %s \n " ) , username , ctx - > thiscmd ,
oldval ) ;
2006-02-04 01:19:41 +03:00
goto done ;
}
2008-02-12 02:51:51 +03:00
ZERO_STRUCT ( info - > info21 ) ;
2006-02-04 01:19:41 +03:00
2008-02-12 02:51:51 +03:00
info - > info21 . acct_flags = newflags ;
info - > info21 . fields_present = SAMR_FIELD_ACCT_FLAGS ;
2006-02-04 01:19:41 +03:00
2008-02-12 02:51:51 +03:00
result = rpccli_samr_SetUserInfo ( pipe_hnd , mem_ctx ,
2008-02-13 16:10:10 +03:00
user_hnd ,
2008-02-12 02:51:51 +03:00
21 ,
info ) ;
2006-02-04 01:19:41 +03:00
if ( NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Set %s's %s flag from [%s] to [%s] \n " ) , username ,
2006-02-04 01:19:41 +03:00
ctx - > thiscmd , oldval , argv [ 0 ] ) ;
}
done :
return result ;
}
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_sh_user_flag_edit ( struct net_context * c ,
TALLOC_CTX * mem_ctx ,
2006-02-04 01:19:41 +03:00
struct rpc_sh_ctx * ctx ,
struct rpc_pipe_client * pipe_hnd ,
int argc , const char * * argv )
{
2008-05-10 01:22:12 +04:00
return rpc_sh_handle_user ( c , mem_ctx , ctx , pipe_hnd , argc , argv ,
2006-02-04 01:19:41 +03:00
rpc_sh_user_flag_edit_internals ) ;
}
2008-05-10 01:22:12 +04:00
struct rpc_sh_cmd * net_rpc_user_edit_cmds ( struct net_context * c ,
TALLOC_CTX * mem_ctx ,
2006-02-04 01:19:41 +03:00
struct rpc_sh_ctx * ctx )
{
static struct rpc_sh_cmd cmds [ ] = {
2009-11-08 21:37:26 +03:00
{ " fullname " , NULL , & ndr_table_samr . syntax_id , rpc_sh_user_str_edit ,
2009-08-04 10:28:50 +04:00
N_ ( " Show/Set a user's full name " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ " homedir " , NULL , & ndr_table_samr . syntax_id , rpc_sh_user_str_edit ,
2009-08-04 10:28:50 +04:00
N_ ( " Show/Set a user's home directory " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ " homedrive " , NULL , & ndr_table_samr . syntax_id , rpc_sh_user_str_edit ,
2009-08-04 10:28:50 +04:00
N_ ( " Show/Set a user's home drive " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ " logonscript " , NULL , & ndr_table_samr . syntax_id , rpc_sh_user_str_edit ,
2009-08-04 10:28:50 +04:00
N_ ( " Show/Set a user's logon script " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ " profilepath " , NULL , & ndr_table_samr . syntax_id , rpc_sh_user_str_edit ,
2009-08-04 10:28:50 +04:00
N_ ( " Show/Set a user's profile path " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ " description " , NULL , & ndr_table_samr . syntax_id , rpc_sh_user_str_edit ,
2009-08-04 10:28:50 +04:00
N_ ( " Show/Set a user's description " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ " disabled " , NULL , & ndr_table_samr . syntax_id , rpc_sh_user_flag_edit ,
2009-08-04 10:28:50 +04:00
N_ ( " Show/Set whether a user is disabled " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ " autolock " , NULL , & ndr_table_samr . syntax_id , rpc_sh_user_flag_edit ,
2009-08-04 10:28:50 +04:00
N_ ( " Show/Set whether a user locked out " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ " pwnotreq " , NULL , & ndr_table_samr . syntax_id , rpc_sh_user_flag_edit ,
2009-08-04 10:28:50 +04:00
N_ ( " Show/Set whether a user does not need a password " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ " pwnoexp " , NULL , & ndr_table_samr . syntax_id , rpc_sh_user_flag_edit ,
2009-08-04 10:28:50 +04:00
N_ ( " Show/Set whether a user's password does not expire " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ NULL , NULL , 0 , NULL , NULL }
2006-02-04 01:19:41 +03:00
} ;
return cmds ;
}
2008-05-10 01:22:12 +04:00
struct rpc_sh_cmd * net_rpc_user_cmds ( struct net_context * c ,
TALLOC_CTX * mem_ctx ,
2006-02-04 01:19:41 +03:00
struct rpc_sh_ctx * ctx )
{
static struct rpc_sh_cmd cmds [ ] = {
2009-11-08 21:37:26 +03:00
{ " list " , NULL , & ndr_table_samr . syntax_id , rpc_sh_user_list ,
N_ ( " List available users " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ " info " , NULL , & ndr_table_samr . syntax_id , rpc_sh_user_info ,
2009-08-04 10:28:50 +04:00
N_ ( " List the domain groups a user is member of " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ " show " , NULL , & ndr_table_samr . syntax_id , rpc_sh_user_show ,
2009-08-04 10:28:50 +04:00
N_ ( " Show info about a user " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ " edit " , net_rpc_user_edit_cmds , 0 , NULL ,
2009-08-04 10:28:50 +04:00
N_ ( " Show/Modify a user's fields " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ NULL , NULL , 0 , NULL , NULL }
2006-02-04 01:19:41 +03:00
} ;
return cmds ;
2006-05-17 15:14:26 +04:00
}
2006-02-04 01:19:41 +03:00
2001-12-31 16:00:59 +03:00
/****************************************************************************/
2002-07-15 14:35:28 +04:00
/**
2008-06-12 12:55:55 +04:00
* Basic usage function for ' net rpc group ' .
2002-07-15 14:35:28 +04:00
* @ param argc Standard main ( ) style argc .
2008-06-12 12:55:55 +04:00
* @ param argv Standard main ( ) style argv . Initial components are already
2002-07-15 14:35:28 +04:00
* stripped .
* */
2001-12-31 16:00:59 +03:00
2008-05-10 01:22:12 +04:00
static int rpc_group_usage ( struct net_context * c , int argc , const char * * argv )
2002-07-15 14:35:28 +04:00
{
2008-05-13 15:44:28 +04:00
return net_group_usage ( c , argc , argv ) ;
2002-07-15 14:35:28 +04:00
}
2001-12-31 16:00:59 +03:00
2004-04-19 00:22:31 +04:00
/**
2008-06-12 12:55:55 +04:00
* Delete group on a remote RPC server .
2004-04-19 00:22:31 +04:00
*
* All parameters are provided by the run_rpc_command function , except for
2008-06-12 12:55:55 +04:00
* argc , argv which are passed through .
2004-04-19 00:22:31 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param domain_sid The domain sid acquired from the remote server .
2004-04-19 00:22:31 +04:00
* @ param cli A cli_state connected to the server .
2008-06-12 12:55:55 +04:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-04-19 00:22:31 +04:00
*
* @ return Normal NTSTATUS return .
* */
2008-05-08 13:23:38 +04:00
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_group_delete_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2005-09-30 21:13:37 +04:00
const char * domain_name ,
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2004-04-19 00:22:31 +04:00
{
2009-03-19 00:49:41 +03:00
struct policy_handle connect_pol , domain_pol , group_pol , user_pol ;
2008-05-12 13:53:23 +04:00
bool group_is_primary = false ;
2004-04-19 00:22:31 +04:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2008-02-08 16:50:04 +03:00
uint32_t group_rid ;
2008-02-05 12:58:37 +03:00
struct samr_RidTypeArray * rids = NULL ;
2004-04-19 00:22:31 +04:00
/* char **names; */
int i ;
2009-02-05 02:19:39 +03:00
/* struct samr_RidWithAttribute *user_gids; */
2004-04-19 00:22:31 +04:00
2008-02-08 16:50:04 +03:00
struct samr_Ids group_rids , name_types ;
struct lsa_String lsa_acct_name ;
2008-02-12 20:13:30 +03:00
union samr_UserInfo * info = NULL ;
2008-02-08 16:50:04 +03:00
2008-05-21 12:27:59 +04:00
if ( argc < 1 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
rpc_group_usage ( c , argc , argv ) ;
2004-04-19 00:22:31 +04:00
return NT_STATUS_OK ; /* ok? */
}
2008-02-04 21:43:07 +03:00
result = rpccli_samr_Connect2 ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2008-02-04 21:43:07 +03:00
MAXIMUM_ALLOWED_ACCESS ,
& connect_pol ) ;
2004-04-19 00:22:31 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Request samr_Connect2 failed \n " ) ) ;
2004-04-19 00:22:31 +04:00
goto done ;
}
2008-02-01 13:12:05 +03:00
result = rpccli_samr_OpenDomain ( pipe_hnd , mem_ctx ,
& connect_pol ,
MAXIMUM_ALLOWED_ACCESS ,
CONST_DISCARD ( struct dom_sid2 * , domain_sid ) ,
& domain_pol ) ;
2004-04-19 00:22:31 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Request open_domain failed \n " ) ) ;
2004-04-19 00:22:31 +04:00
goto done ;
}
2008-02-08 16:50:04 +03:00
init_lsa_String ( & lsa_acct_name , argv [ 0 ] ) ;
result = rpccli_samr_LookupNames ( pipe_hnd , mem_ctx ,
& domain_pol ,
1 ,
& lsa_acct_name ,
& group_rids ,
& name_types ) ;
2004-04-19 00:22:31 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Lookup of '%s' failed \n " ) , argv [ 0 ] ) ;
2004-04-19 00:22:31 +04:00
goto done ;
}
2008-02-08 16:50:04 +03:00
switch ( name_types . ids [ 0 ] )
2004-04-19 00:22:31 +04:00
{
case SID_NAME_DOM_GRP :
2008-02-01 13:24:01 +03:00
result = rpccli_samr_OpenGroup ( pipe_hnd , mem_ctx ,
& domain_pol ,
MAXIMUM_ALLOWED_ACCESS ,
2008-02-08 16:50:04 +03:00
group_rids . ids [ 0 ] ,
2008-02-01 13:24:01 +03:00
& group_pol ) ;
2004-04-19 00:22:31 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Request open_group failed " ) ) ;
2004-04-19 00:22:31 +04:00
goto done ;
}
2008-02-08 16:50:04 +03:00
group_rid = group_rids . ids [ 0 ] ;
2008-02-05 12:58:37 +03:00
result = rpccli_samr_QueryGroupMember ( pipe_hnd , mem_ctx ,
& group_pol ,
& rids ) ;
2004-04-19 00:22:31 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr ,
_ ( " Unable to query group members of %s " ) ,
argv [ 0 ] ) ;
2004-04-19 00:22:31 +04:00
goto done ;
}
2008-05-08 13:23:38 +04:00
2008-05-10 01:22:12 +04:00
if ( c - > opt_verbose ) {
2009-08-04 10:28:50 +04:00
d_printf (
_ ( " Domain Group %s (rid: %d) has %d members \n " ) ,
2008-02-05 12:58:37 +03:00
argv [ 0 ] , group_rid , rids - > count ) ;
2004-04-19 00:22:31 +04:00
}
/* Check if group is anyone's primary group */
2008-02-05 12:58:37 +03:00
for ( i = 0 ; i < rids - > count ; i + + )
2004-04-19 00:22:31 +04:00
{
2008-02-01 13:57:53 +03:00
result = rpccli_samr_OpenUser ( pipe_hnd , mem_ctx ,
& domain_pol ,
MAXIMUM_ALLOWED_ACCESS ,
2008-02-05 12:58:37 +03:00
rids - > rids [ i ] ,
2008-02-01 13:57:53 +03:00
& user_pol ) ;
2008-05-08 13:23:38 +04:00
2004-04-19 00:22:31 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr ,
_ ( " Unable to open group member %d \n " ) ,
2008-02-05 12:58:37 +03:00
rids - > rids [ i ] ) ;
2004-04-19 00:22:31 +04:00
goto done ;
}
2008-02-12 20:13:30 +03:00
result = rpccli_samr_QueryUserInfo ( pipe_hnd , mem_ctx ,
& user_pol ,
21 ,
& info ) ;
2004-04-19 00:22:31 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr ,
_ ( " Unable to lookup userinfo for group "
" member %d \n " ) ,
2008-02-05 12:58:37 +03:00
rids - > rids [ i ] ) ;
2004-04-19 00:22:31 +04:00
goto done ;
}
2008-02-12 20:13:30 +03:00
if ( info - > info21 . primary_gid = = group_rid ) {
2008-05-10 01:22:12 +04:00
if ( c - > opt_verbose ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Group is primary group "
" of %s \n " ) ,
2008-02-12 20:13:30 +03:00
info - > info21 . account_name . string ) ;
}
2008-05-12 13:53:23 +04:00
group_is_primary = true ;
2004-04-19 00:22:31 +04:00
}
2008-01-30 14:39:20 +03:00
rpccli_samr_Close ( pipe_hnd , mem_ctx , & user_pol ) ;
2004-04-19 00:22:31 +04:00
}
2008-05-08 13:23:38 +04:00
2004-04-19 00:22:31 +04:00
if ( group_is_primary ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Unable to delete group because "
" some of it's members have it as primary "
" group \n " ) ) ;
2004-04-19 00:22:31 +04:00
result = NT_STATUS_MEMBERS_PRIMARY_GROUP ;
goto done ;
}
2008-05-08 13:23:38 +04:00
2004-04-19 00:22:31 +04:00
/* remove all group members */
2008-02-05 12:58:37 +03:00
for ( i = 0 ; i < rids - > count ; i + + )
2004-04-19 00:22:31 +04:00
{
2008-05-10 01:22:12 +04:00
if ( c - > opt_verbose )
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Remove group member %d... " ) ,
2008-02-05 12:58:37 +03:00
rids - > rids [ i ] ) ;
2008-02-04 20:13:07 +03:00
result = rpccli_samr_DeleteGroupMember ( pipe_hnd , mem_ctx ,
& group_pol ,
2008-02-05 12:58:37 +03:00
rids - > rids [ i ] ) ;
2004-04-19 00:22:31 +04:00
if ( NT_STATUS_IS_OK ( result ) ) {
2008-05-10 01:22:12 +04:00
if ( c - > opt_verbose )
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " ok \n " ) ) ;
2004-04-19 00:22:31 +04:00
} else {
2008-05-10 01:22:12 +04:00
if ( c - > opt_verbose )
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n " , _ ( " failed " ) ) ;
2004-04-19 00:22:31 +04:00
goto done ;
2008-05-08 13:23:38 +04:00
}
2004-04-19 00:22:31 +04:00
}
2008-02-01 03:17:22 +03:00
result = rpccli_samr_DeleteDomainGroup ( pipe_hnd , mem_ctx ,
& group_pol ) ;
2004-04-19 00:22:31 +04:00
break ;
/* removing a local group is easier... */
case SID_NAME_ALIAS :
2008-02-01 13:38:29 +03:00
result = rpccli_samr_OpenAlias ( pipe_hnd , mem_ctx ,
& domain_pol ,
MAXIMUM_ALLOWED_ACCESS ,
2008-02-08 16:50:04 +03:00
group_rids . ids [ 0 ] ,
2008-02-01 13:38:29 +03:00
& group_pol ) ;
2004-04-19 00:22:31 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Request open_alias failed \n " ) ) ;
2004-04-19 00:22:31 +04:00
goto done ;
}
2008-02-01 03:22:22 +03:00
result = rpccli_samr_DeleteDomAlias ( pipe_hnd , mem_ctx ,
& group_pol ) ;
2004-04-19 00:22:31 +04:00
break ;
default :
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " %s is of type %s. This command is only "
" for deleting local or global groups \n " ) ,
2008-02-08 16:50:04 +03:00
argv [ 0 ] , sid_type_lookup ( name_types . ids [ 0 ] ) ) ;
2004-04-19 00:22:31 +04:00
result = NT_STATUS_UNSUCCESSFUL ;
goto done ;
}
2008-05-08 13:23:38 +04:00
2004-04-19 00:22:31 +04:00
if ( NT_STATUS_IS_OK ( result ) ) {
2008-05-10 01:22:12 +04:00
if ( c - > opt_verbose )
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Deleted %s '%s' \n " ) ,
sid_type_lookup ( name_types . ids [ 0 ] ) , argv [ 0 ] ) ;
2004-04-19 00:22:31 +04:00
} else {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Deleting of %s failed: %s \n " ) , argv [ 0 ] ,
2004-04-19 00:22:31 +04:00
get_friendly_nt_error_msg ( result ) ) ;
}
2008-05-08 13:23:38 +04:00
2004-04-19 00:22:31 +04:00
done :
2008-05-08 13:23:38 +04:00
return result ;
2004-04-19 00:22:31 +04:00
}
2008-05-10 01:22:12 +04:00
static int rpc_group_delete ( struct net_context * c , int argc , const char * * argv )
2004-04-19 00:22:31 +04:00
{
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_samr . syntax_id , 0 ,
2008-07-20 20:36:31 +04:00
rpc_group_delete_internals , argc , argv ) ;
2004-04-19 00:22:31 +04:00
}
2008-05-28 16:57:35 +04:00
static int rpc_group_add_internals ( struct net_context * c , int argc , const char * * argv )
2004-02-24 21:00:41 +03:00
{
2008-05-28 16:57:35 +04:00
NET_API_STATUS status ;
struct GROUP_INFO_1 info1 ;
uint32_t parm_error = 0 ;
2004-02-24 21:00:41 +03:00
2008-05-21 12:27:59 +04:00
if ( argc ! = 1 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
rpc_group_usage ( c , argc , argv ) ;
2008-05-28 16:57:35 +04:00
return 0 ;
2004-02-24 21:00:41 +03:00
}
2008-05-28 16:57:35 +04:00
ZERO_STRUCT ( info1 ) ;
2004-02-24 21:00:41 +03:00
2008-05-28 16:57:35 +04:00
info1 . grpi1_name = argv [ 0 ] ;
if ( c - > opt_comment & & strlen ( c - > opt_comment ) > 0 ) {
info1 . grpi1_comment = c - > opt_comment ;
}
2004-02-24 21:00:41 +03:00
2008-05-28 16:57:35 +04:00
status = NetGroupAdd ( c - > opt_host , 1 , ( uint8_t * ) & info1 , & parm_error ) ;
2008-05-08 13:23:38 +04:00
2008-05-28 16:57:35 +04:00
if ( status ! = 0 ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr ,
_ ( " Failed to add group '%s' with error: %s. \n " ) ,
2008-05-28 16:57:35 +04:00
argv [ 0 ] , libnetapi_get_error_string ( c - > netapi_ctx ,
status ) ) ;
return - 1 ;
} else {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Added group '%s'. \n " ) , argv [ 0 ] ) ;
2008-05-28 16:57:35 +04:00
}
2004-02-24 21:00:41 +03:00
2008-05-28 16:57:35 +04:00
return 0 ;
2004-02-24 21:00:41 +03:00
}
2008-07-31 17:12:09 +04:00
static int rpc_alias_add_internals ( struct net_context * c , int argc , const char * * argv )
2004-02-28 21:41:16 +03:00
{
2008-07-31 17:12:09 +04:00
NET_API_STATUS status ;
struct LOCALGROUP_INFO_1 info1 ;
uint32_t parm_error = 0 ;
2004-02-28 21:41:16 +03:00
2008-05-21 12:27:59 +04:00
if ( argc ! = 1 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
rpc_group_usage ( c , argc , argv ) ;
2008-07-31 17:12:09 +04:00
return 0 ;
2004-02-28 21:41:16 +03:00
}
2008-07-31 17:12:09 +04:00
ZERO_STRUCT ( info1 ) ;
2008-02-06 15:16:04 +03:00
2008-07-31 17:12:09 +04:00
info1 . lgrpi1_name = argv [ 0 ] ;
if ( c - > opt_comment & & strlen ( c - > opt_comment ) > 0 ) {
info1 . lgrpi1_comment = c - > opt_comment ;
}
2004-02-28 21:41:16 +03:00
2008-07-31 17:12:09 +04:00
status = NetLocalGroupAdd ( c - > opt_host , 1 , ( uint8_t * ) & info1 , & parm_error ) ;
2008-05-08 13:23:38 +04:00
2008-07-31 17:12:09 +04:00
if ( status ! = 0 ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr ,
_ ( " Failed to add alias '%s' with error: %s. \n " ) ,
2008-07-31 17:12:09 +04:00
argv [ 0 ] , libnetapi_get_error_string ( c - > netapi_ctx ,
status ) ) ;
return - 1 ;
} else {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Added alias '%s'. \n " ) , argv [ 0 ] ) ;
2008-07-31 17:12:09 +04:00
}
2004-02-28 21:41:16 +03:00
2008-07-31 17:12:09 +04:00
return 0 ;
2004-02-28 21:41:16 +03:00
}
2008-05-10 01:22:12 +04:00
static int rpc_group_add ( struct net_context * c , int argc , const char * * argv )
2004-02-24 21:00:41 +03:00
{
2008-05-10 01:22:12 +04:00
if ( c - > opt_localgroup )
2008-07-31 17:12:09 +04:00
return rpc_alias_add_internals ( c , argc , argv ) ;
2004-02-28 21:41:16 +03:00
2008-05-28 16:57:35 +04:00
return rpc_group_add_internals ( c , argc , argv ) ;
2004-02-24 21:00:41 +03:00
}
2005-09-30 21:13:37 +04:00
static NTSTATUS get_sid_from_name ( struct cli_state * cli ,
TALLOC_CTX * mem_ctx ,
const char * name ,
2010-05-21 05:25:01 +04:00
struct dom_sid * sid ,
2006-09-08 18:28:06 +04:00
enum lsa_SidType * type )
2004-02-28 21:41:16 +03:00
{
2010-05-21 05:25:01 +04:00
struct dom_sid * sids = NULL ;
2006-09-08 18:28:06 +04:00
enum lsa_SidType * types = NULL ;
2009-03-20 13:04:59 +03:00
struct rpc_pipe_client * pipe_hnd = NULL ;
2009-03-19 00:49:41 +03:00
struct policy_handle lsa_pol ;
2004-02-28 21:41:16 +03:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2008-07-20 13:04:31 +04:00
result = cli_rpc_pipe_open_noauth ( cli , & ndr_table_lsarpc . syntax_id ,
& pipe_hnd ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
2005-09-30 21:13:37 +04:00
goto done ;
2004-02-28 21:41:16 +03:00
}
2008-05-12 13:53:23 +04:00
result = rpccli_lsa_open_policy ( pipe_hnd , mem_ctx , false ,
2009-04-15 03:12:13 +04:00
SEC_FLAG_MAXIMUM_ALLOWED , & lsa_pol ) ;
2004-02-28 21:41:16 +03:00
2005-09-30 21:13:37 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2004-02-28 21:41:16 +03:00
goto done ;
2005-09-30 21:13:37 +04:00
}
2004-02-28 21:41:16 +03:00
2005-09-30 21:13:37 +04:00
result = rpccli_lsa_lookup_names ( pipe_hnd , mem_ctx , & lsa_pol , 1 ,
2007-06-27 15:42:17 +04:00
& name , NULL , 1 , & sids , & types ) ;
2004-02-28 21:41:16 +03:00
if ( NT_STATUS_IS_OK ( result ) ) {
sid_copy ( sid , & sids [ 0 ] ) ;
* type = types [ 0 ] ;
}
2006-09-21 02:49:02 +04:00
rpccli_lsa_Close ( pipe_hnd , mem_ctx , & lsa_pol ) ;
2004-02-28 21:41:16 +03:00
done :
2005-09-30 21:13:37 +04:00
if ( pipe_hnd ) {
2008-04-20 15:51:46 +04:00
TALLOC_FREE ( pipe_hnd ) ;
2004-02-28 21:41:16 +03:00
}
if ( ! NT_STATUS_IS_OK ( result ) & & ( StrnCaseCmp ( name , " S- " , 2 ) = = 0 ) ) {
/* Try as S-1-5-whatever */
2010-05-21 05:25:01 +04:00
struct dom_sid tmp_sid ;
2004-02-28 21:41:16 +03:00
if ( string_to_sid ( & tmp_sid , name ) ) {
sid_copy ( sid , & tmp_sid ) ;
* type = SID_NAME_UNKNOWN ;
result = NT_STATUS_OK ;
}
}
return result ;
}
2005-09-30 21:13:37 +04:00
static NTSTATUS rpc_add_groupmem ( struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * group_sid ,
2005-09-30 21:13:37 +04:00
const char * member )
2004-02-28 21:41:16 +03:00
{
2009-03-19 00:49:41 +03:00
struct policy_handle connect_pol , domain_pol ;
2004-02-28 21:41:16 +03:00
NTSTATUS result ;
uint32 group_rid ;
2009-03-19 00:49:41 +03:00
struct policy_handle group_pol ;
2004-02-28 21:41:16 +03:00
2008-02-08 16:50:04 +03:00
struct samr_Ids rids , rid_types ;
struct lsa_String lsa_acct_name ;
2004-02-28 21:41:16 +03:00
2010-05-21 05:25:01 +04:00
struct dom_sid sid ;
2004-02-28 21:41:16 +03:00
sid_copy ( & sid , group_sid ) ;
2005-09-30 21:13:37 +04:00
if ( ! sid_split_rid ( & sid , & group_rid ) ) {
2004-02-28 21:41:16 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2005-09-30 21:13:37 +04:00
}
2004-02-28 21:41:16 +03:00
2008-02-04 21:43:07 +03:00
/* Get sam policy handle */
result = rpccli_samr_Connect2 ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2008-02-04 21:43:07 +03:00
MAXIMUM_ALLOWED_ACCESS ,
& connect_pol ) ;
2005-09-30 21:13:37 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2004-02-28 21:41:16 +03:00
return result ;
2005-09-30 21:13:37 +04:00
}
2008-02-01 13:12:05 +03:00
2004-02-28 21:41:16 +03:00
/* Get domain policy handle */
2008-02-01 13:12:05 +03:00
result = rpccli_samr_OpenDomain ( pipe_hnd , mem_ctx ,
& connect_pol ,
MAXIMUM_ALLOWED_ACCESS ,
& sid ,
& domain_pol ) ;
2005-09-30 21:13:37 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2004-02-28 21:41:16 +03:00
return result ;
2005-09-30 21:13:37 +04:00
}
2004-02-28 21:41:16 +03:00
2008-02-08 16:50:04 +03:00
init_lsa_String ( & lsa_acct_name , member ) ;
result = rpccli_samr_LookupNames ( pipe_hnd , mem_ctx ,
& domain_pol ,
1 ,
& lsa_acct_name ,
& rids ,
& rid_types ) ;
2004-02-28 21:41:16 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Could not lookup up group member %s \n " ) ,
member ) ;
2004-02-28 21:41:16 +03:00
goto done ;
}
2008-02-01 13:24:01 +03:00
result = rpccli_samr_OpenGroup ( pipe_hnd , mem_ctx ,
& domain_pol ,
MAXIMUM_ALLOWED_ACCESS ,
group_rid ,
& group_pol ) ;
2004-02-28 21:41:16 +03:00
2005-09-30 21:13:37 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2004-02-28 21:41:16 +03:00
goto done ;
2005-09-30 21:13:37 +04:00
}
2004-02-28 21:41:16 +03:00
2008-02-04 20:45:07 +03:00
result = rpccli_samr_AddGroupMember ( pipe_hnd , mem_ctx ,
& group_pol ,
2008-02-08 16:50:04 +03:00
rids . ids [ 0 ] ,
2008-02-04 20:45:07 +03:00
0x0005 ) ; /* unknown flags */
2004-02-28 21:41:16 +03:00
done :
2008-01-30 14:39:20 +03:00
rpccli_samr_Close ( pipe_hnd , mem_ctx , & connect_pol ) ;
2004-02-28 21:41:16 +03:00
return result ;
}
2005-09-30 21:13:37 +04:00
static NTSTATUS rpc_add_aliasmem ( struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * alias_sid ,
2005-09-30 21:13:37 +04:00
const char * member )
2004-02-28 21:41:16 +03:00
{
2009-03-19 00:49:41 +03:00
struct policy_handle connect_pol , domain_pol ;
2004-02-28 21:41:16 +03:00
NTSTATUS result ;
uint32 alias_rid ;
2009-03-19 00:49:41 +03:00
struct policy_handle alias_pol ;
2004-02-28 21:41:16 +03:00
2010-05-21 05:25:01 +04:00
struct dom_sid member_sid ;
2006-09-08 18:28:06 +04:00
enum lsa_SidType member_type ;
2004-02-28 21:41:16 +03:00
2010-05-21 05:25:01 +04:00
struct dom_sid sid ;
2004-02-28 21:41:16 +03:00
sid_copy ( & sid , alias_sid ) ;
2005-09-30 21:13:37 +04:00
if ( ! sid_split_rid ( & sid , & alias_rid ) ) {
2004-02-28 21:41:16 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2005-09-30 21:13:37 +04:00
}
2004-02-28 21:41:16 +03:00
2008-04-20 16:05:25 +04:00
result = get_sid_from_name ( rpc_pipe_np_smb_conn ( pipe_hnd ) , mem_ctx ,
member , & member_sid , & member_type ) ;
2004-02-28 21:41:16 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Could not lookup up group member %s \n " ) ,
member ) ;
2004-02-28 21:41:16 +03:00
return result ;
}
2008-02-04 21:43:07 +03:00
/* Get sam policy handle */
result = rpccli_samr_Connect2 ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2008-02-04 21:43:07 +03:00
MAXIMUM_ALLOWED_ACCESS ,
& connect_pol ) ;
2004-02-28 21:41:16 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
goto done ;
}
2008-02-01 13:12:05 +03:00
2004-02-28 21:41:16 +03:00
/* Get domain policy handle */
2008-02-01 13:12:05 +03:00
result = rpccli_samr_OpenDomain ( pipe_hnd , mem_ctx ,
& connect_pol ,
MAXIMUM_ALLOWED_ACCESS ,
& sid ,
& domain_pol ) ;
2004-02-28 21:41:16 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
goto done ;
}
2008-02-01 13:38:29 +03:00
result = rpccli_samr_OpenAlias ( pipe_hnd , mem_ctx ,
& domain_pol ,
MAXIMUM_ALLOWED_ACCESS ,
alias_rid ,
& alias_pol ) ;
2004-02-28 21:41:16 +03:00
2005-09-30 21:13:37 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2004-02-28 21:41:16 +03:00
return result ;
2005-09-30 21:13:37 +04:00
}
2004-02-28 21:41:16 +03:00
2008-02-05 01:42:05 +03:00
result = rpccli_samr_AddAliasMember ( pipe_hnd , mem_ctx ,
& alias_pol ,
& member_sid ) ;
2004-02-28 21:41:16 +03:00
2005-09-30 21:13:37 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2004-02-28 21:41:16 +03:00
return result ;
2005-09-30 21:13:37 +04:00
}
2004-02-28 21:41:16 +03:00
done :
2008-01-30 14:39:20 +03:00
rpccli_samr_Close ( pipe_hnd , mem_ctx , & connect_pol ) ;
2004-02-28 21:41:16 +03:00
return result ;
}
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_group_addmem_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
2005-09-30 21:13:37 +04:00
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2004-02-28 21:41:16 +03:00
{
2010-05-21 05:25:01 +04:00
struct dom_sid group_sid ;
2006-09-08 18:28:06 +04:00
enum lsa_SidType group_type ;
2004-02-28 21:41:16 +03:00
2008-05-21 12:27:59 +04:00
if ( argc ! = 2 | | c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net rpc group addmem <group> <member> \n "
2009-08-04 10:28:50 +04:00
" Add a member to a group \n "
" group \t Group to add member to \n "
" member \t Member to add to group \n " ) ) ;
2004-02-28 21:41:16 +03:00
return NT_STATUS_UNSUCCESSFUL ;
}
if ( ! NT_STATUS_IS_OK ( get_sid_from_name ( cli , mem_ctx , argv [ 0 ] ,
& group_sid , & group_type ) ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Could not lookup group name %s \n " ) ,
argv [ 0 ] ) ;
2004-02-28 21:41:16 +03:00
return NT_STATUS_UNSUCCESSFUL ;
}
if ( group_type = = SID_NAME_DOM_GRP ) {
2005-09-30 21:13:37 +04:00
NTSTATUS result = rpc_add_groupmem ( pipe_hnd , mem_ctx ,
2004-02-28 21:41:16 +03:00
& group_sid , argv [ 1 ] ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Could not add %s to %s: %s \n " ) ,
2004-02-28 21:41:16 +03:00
argv [ 1 ] , argv [ 0 ] , nt_errstr ( result ) ) ;
}
2004-02-29 19:34:33 +03:00
return result ;
2004-02-28 21:41:16 +03:00
}
if ( group_type = = SID_NAME_ALIAS ) {
2005-09-30 21:13:37 +04:00
NTSTATUS result = rpc_add_aliasmem ( pipe_hnd , mem_ctx ,
2004-02-28 21:41:16 +03:00
& group_sid , argv [ 1 ] ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Could not add %s to %s: %s \n " ) ,
2004-02-28 21:41:16 +03:00
argv [ 1 ] , argv [ 0 ] , nt_errstr ( result ) ) ;
}
2004-02-29 19:34:33 +03:00
return result ;
2004-02-28 21:41:16 +03:00
}
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Can only add members to global or local groups "
" which %s is not \n " ) , argv [ 0 ] ) ;
2004-02-29 15:47:45 +03:00
2004-02-28 21:41:16 +03:00
return NT_STATUS_UNSUCCESSFUL ;
}
2008-05-10 01:22:12 +04:00
static int rpc_group_addmem ( struct net_context * c , int argc , const char * * argv )
2004-02-28 21:41:16 +03:00
{
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_samr . syntax_id , 0 ,
2004-02-28 21:41:16 +03:00
rpc_group_addmem_internals ,
argc , argv ) ;
}
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_del_groupmem ( struct net_context * c ,
struct rpc_pipe_client * pipe_hnd ,
2005-09-30 21:13:37 +04:00
TALLOC_CTX * mem_ctx ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * group_sid ,
2005-09-30 21:13:37 +04:00
const char * member )
2004-02-28 21:41:16 +03:00
{
2009-03-19 00:49:41 +03:00
struct policy_handle connect_pol , domain_pol ;
2004-02-28 21:41:16 +03:00
NTSTATUS result ;
uint32 group_rid ;
2009-03-19 00:49:41 +03:00
struct policy_handle group_pol ;
2004-02-28 21:41:16 +03:00
2008-02-08 16:50:04 +03:00
struct samr_Ids rids , rid_types ;
struct lsa_String lsa_acct_name ;
2004-02-28 21:41:16 +03:00
2010-05-21 05:25:01 +04:00
struct dom_sid sid ;
2004-02-28 21:41:16 +03:00
sid_copy ( & sid , group_sid ) ;
if ( ! sid_split_rid ( & sid , & group_rid ) )
return NT_STATUS_UNSUCCESSFUL ;
2008-02-04 21:43:07 +03:00
/* Get sam policy handle */
result = rpccli_samr_Connect2 ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2008-02-04 21:43:07 +03:00
MAXIMUM_ALLOWED_ACCESS ,
& connect_pol ) ;
2004-02-28 21:41:16 +03:00
if ( ! NT_STATUS_IS_OK ( result ) )
return result ;
2008-02-01 13:12:05 +03:00
2004-02-28 21:41:16 +03:00
/* Get domain policy handle */
2008-02-01 13:12:05 +03:00
result = rpccli_samr_OpenDomain ( pipe_hnd , mem_ctx ,
& connect_pol ,
MAXIMUM_ALLOWED_ACCESS ,
& sid ,
& domain_pol ) ;
2004-02-28 21:41:16 +03:00
if ( ! NT_STATUS_IS_OK ( result ) )
return result ;
2008-02-08 16:50:04 +03:00
init_lsa_String ( & lsa_acct_name , member ) ;
2004-02-28 21:41:16 +03:00
2008-02-08 16:50:04 +03:00
result = rpccli_samr_LookupNames ( pipe_hnd , mem_ctx ,
& domain_pol ,
1 ,
& lsa_acct_name ,
& rids ,
& rid_types ) ;
2004-02-28 21:41:16 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Could not lookup up group member %s \n " ) ,
member ) ;
2004-02-28 21:41:16 +03:00
goto done ;
}
2008-02-01 13:24:01 +03:00
result = rpccli_samr_OpenGroup ( pipe_hnd , mem_ctx ,
& domain_pol ,
MAXIMUM_ALLOWED_ACCESS ,
group_rid ,
& group_pol ) ;
2004-02-28 21:41:16 +03:00
if ( ! NT_STATUS_IS_OK ( result ) )
goto done ;
2008-02-04 20:13:07 +03:00
result = rpccli_samr_DeleteGroupMember ( pipe_hnd , mem_ctx ,
& group_pol ,
2008-02-08 16:50:04 +03:00
rids . ids [ 0 ] ) ;
2004-02-28 21:41:16 +03:00
done :
2008-01-30 14:39:20 +03:00
rpccli_samr_Close ( pipe_hnd , mem_ctx , & connect_pol ) ;
2004-02-28 21:41:16 +03:00
return result ;
}
2005-09-30 21:13:37 +04:00
static NTSTATUS rpc_del_aliasmem ( struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * alias_sid ,
2005-09-30 21:13:37 +04:00
const char * member )
2004-02-28 21:41:16 +03:00
{
2009-03-19 00:49:41 +03:00
struct policy_handle connect_pol , domain_pol ;
2004-02-28 21:41:16 +03:00
NTSTATUS result ;
uint32 alias_rid ;
2009-03-19 00:49:41 +03:00
struct policy_handle alias_pol ;
2004-02-28 21:41:16 +03:00
2010-05-21 05:25:01 +04:00
struct dom_sid member_sid ;
2006-09-08 18:28:06 +04:00
enum lsa_SidType member_type ;
2004-02-28 21:41:16 +03:00
2010-05-21 05:25:01 +04:00
struct dom_sid sid ;
2004-02-28 21:41:16 +03:00
sid_copy ( & sid , alias_sid ) ;
if ( ! sid_split_rid ( & sid , & alias_rid ) )
return NT_STATUS_UNSUCCESSFUL ;
2008-04-20 16:05:25 +04:00
result = get_sid_from_name ( rpc_pipe_np_smb_conn ( pipe_hnd ) , mem_ctx ,
member , & member_sid , & member_type ) ;
2004-02-28 21:41:16 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Could not lookup up group member %s \n " ) ,
member ) ;
2004-02-28 21:41:16 +03:00
return result ;
}
2008-02-04 21:43:07 +03:00
/* Get sam policy handle */
result = rpccli_samr_Connect2 ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2008-02-04 21:43:07 +03:00
MAXIMUM_ALLOWED_ACCESS ,
& connect_pol ) ;
2004-02-28 21:41:16 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
goto done ;
}
2008-02-01 13:12:05 +03:00
2004-02-28 21:41:16 +03:00
/* Get domain policy handle */
2008-02-01 13:12:05 +03:00
result = rpccli_samr_OpenDomain ( pipe_hnd , mem_ctx ,
& connect_pol ,
MAXIMUM_ALLOWED_ACCESS ,
& sid ,
& domain_pol ) ;
2004-02-28 21:41:16 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
goto done ;
}
2008-02-01 13:38:29 +03:00
result = rpccli_samr_OpenAlias ( pipe_hnd , mem_ctx ,
& domain_pol ,
MAXIMUM_ALLOWED_ACCESS ,
alias_rid ,
& alias_pol ) ;
2004-02-28 21:41:16 +03:00
if ( ! NT_STATUS_IS_OK ( result ) )
return result ;
2008-02-05 01:28:38 +03:00
result = rpccli_samr_DeleteAliasMember ( pipe_hnd , mem_ctx ,
& alias_pol ,
& member_sid ) ;
2004-02-28 21:41:16 +03:00
if ( ! NT_STATUS_IS_OK ( result ) )
return result ;
done :
2008-01-30 14:39:20 +03:00
rpccli_samr_Close ( pipe_hnd , mem_ctx , & connect_pol ) ;
2004-02-28 21:41:16 +03:00
return result ;
}
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_group_delmem_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
2005-09-30 21:13:37 +04:00
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2004-02-28 21:41:16 +03:00
{
2010-05-21 05:25:01 +04:00
struct dom_sid group_sid ;
2006-09-08 18:28:06 +04:00
enum lsa_SidType group_type ;
2004-02-28 21:41:16 +03:00
2008-05-21 12:27:59 +04:00
if ( argc ! = 2 | | c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net rpc group delmem <group> <member> \n "
2009-08-04 10:28:50 +04:00
" Delete a member from a group \n "
" group \t Group to delete member from \n "
" member \t Member to delete from group \n " ) ) ;
2004-02-28 21:41:16 +03:00
return NT_STATUS_UNSUCCESSFUL ;
}
if ( ! NT_STATUS_IS_OK ( get_sid_from_name ( cli , mem_ctx , argv [ 0 ] ,
& group_sid , & group_type ) ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Could not lookup group name %s \n " ) ,
argv [ 0 ] ) ;
2004-02-28 21:41:16 +03:00
return NT_STATUS_UNSUCCESSFUL ;
}
if ( group_type = = SID_NAME_DOM_GRP ) {
2008-05-10 01:22:12 +04:00
NTSTATUS result = rpc_del_groupmem ( c , pipe_hnd , mem_ctx ,
2004-02-28 21:41:16 +03:00
& group_sid , argv [ 1 ] ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Could not del %s from %s: %s \n " ) ,
2004-02-28 21:41:16 +03:00
argv [ 1 ] , argv [ 0 ] , nt_errstr ( result ) ) ;
}
2004-02-29 19:34:33 +03:00
return result ;
2004-02-28 21:41:16 +03:00
}
if ( group_type = = SID_NAME_ALIAS ) {
2008-05-08 13:23:38 +04:00
NTSTATUS result = rpc_del_aliasmem ( pipe_hnd , mem_ctx ,
2004-02-28 21:41:16 +03:00
& group_sid , argv [ 1 ] ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Could not del %s from %s: %s \n " ) ,
2004-02-28 21:41:16 +03:00
argv [ 1 ] , argv [ 0 ] , nt_errstr ( result ) ) ;
}
2004-02-29 19:34:33 +03:00
return result ;
2004-02-28 21:41:16 +03:00
}
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Can only delete members from global or local "
" groups which %s is not \n " ) , argv [ 0 ] ) ;
2004-02-29 15:47:45 +03:00
2004-02-28 21:41:16 +03:00
return NT_STATUS_UNSUCCESSFUL ;
}
2008-05-10 01:22:12 +04:00
static int rpc_group_delmem ( struct net_context * c , int argc , const char * * argv )
2004-02-28 21:41:16 +03:00
{
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_samr . syntax_id , 0 ,
2004-02-28 21:41:16 +03:00
rpc_group_delmem_internals ,
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* List groups on a remote RPC server .
2002-07-15 14:35:28 +04:00
*
2002-09-25 19:19:00 +04:00
* All parameters are provided by the run_rpc_command function , except for
2008-05-08 13:23:38 +04:00
* argc , argv which are passes through .
2002-07-15 14:35:28 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param domain_sid The domain sid acquired from the remote server .
2002-07-15 14:35:28 +04:00
* @ param cli A cli_state connected to the server .
2008-06-12 12:55:55 +04:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-07-15 14:35:28 +04:00
*
* @ return Normal NTSTATUS return .
* */
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_group_list_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
2005-09-30 21:13:37 +04:00
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2002-07-15 14:35:28 +04:00
{
2009-03-19 00:49:41 +03:00
struct policy_handle connect_pol , domain_pol ;
2002-07-15 14:35:28 +04:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2003-06-12 20:21:22 +04:00
uint32 start_idx = 0 , max_entries = 250 , num_entries , i , loop_count = 0 ;
2008-02-12 13:09:23 +03:00
struct samr_SamArray * groups = NULL ;
2008-05-12 13:53:23 +04:00
bool global = false ;
bool local = false ;
bool builtin = false ;
2003-11-28 18:10:00 +03:00
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net rpc group list [global] [local] [builtin] \n "
2009-08-04 10:28:50 +04:00
" List groups on RPC server \n "
" global \t List global groups \n "
" local \t List local groups \n "
" builtin \t List builtin groups \n "
" If none of global, local or builtin is "
" specified, all three options are considered "
" set \n " ) ) ;
2008-05-21 12:27:59 +04:00
return NT_STATUS_OK ;
}
2003-11-28 18:10:00 +03:00
if ( argc = = 0 ) {
2008-05-12 13:53:23 +04:00
global = true ;
local = true ;
builtin = true ;
2003-11-28 18:10:00 +03:00
}
for ( i = 0 ; i < argc ; i + + ) {
if ( strequal ( argv [ i ] , " global " ) )
2008-05-12 13:53:23 +04:00
global = true ;
2003-11-28 18:10:00 +03:00
if ( strequal ( argv [ i ] , " local " ) )
2008-05-12 13:53:23 +04:00
local = true ;
2003-11-28 18:10:00 +03:00
if ( strequal ( argv [ i ] , " builtin " ) )
2008-05-12 13:53:23 +04:00
builtin = true ;
2003-11-28 18:10:00 +03:00
}
2002-07-15 14:35:28 +04:00
/* Get sam policy handle */
2008-02-04 21:43:07 +03:00
result = rpccli_samr_Connect2 ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2008-02-04 21:43:07 +03:00
MAXIMUM_ALLOWED_ACCESS ,
& connect_pol ) ;
2002-07-15 14:35:28 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
goto done ;
}
2008-05-08 13:23:38 +04:00
2002-07-15 14:35:28 +04:00
/* Get domain policy handle */
2008-02-01 13:12:05 +03:00
result = rpccli_samr_OpenDomain ( pipe_hnd , mem_ctx ,
& connect_pol ,
MAXIMUM_ALLOWED_ACCESS ,
CONST_DISCARD ( struct dom_sid2 * , domain_sid ) ,
& domain_pol ) ;
2002-07-15 14:35:28 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
goto done ;
}
/* Query domain groups */
2008-05-10 01:22:12 +04:00
if ( c - > opt_long_list_entries )
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " \n Group name Comment "
" \n ----------------------------- \n " ) ) ;
2002-07-15 14:35:28 +04:00
do {
2008-02-07 22:46:02 +03:00
uint32_t max_size , total_size , returned_size ;
union samr_DispInfo info ;
2003-06-12 20:21:22 +04:00
2003-11-28 18:10:00 +03:00
if ( ! global ) break ;
2003-06-12 20:21:22 +04:00
get_query_dispinfo_params (
loop_count , & max_entries , & max_size ) ;
2008-02-07 22:46:02 +03:00
result = rpccli_samr_QueryDisplayInfo ( pipe_hnd , mem_ctx ,
& domain_pol ,
3 ,
start_idx ,
max_entries ,
max_size ,
& total_size ,
& returned_size ,
& info ) ;
num_entries = info . info3 . count ;
start_idx + = info . info3 . count ;
2004-02-17 18:24:28 +03:00
2004-02-28 11:18:09 +03:00
if ( ! NT_STATUS_IS_OK ( result ) & &
! NT_STATUS_EQUAL ( result , STATUS_MORE_ENTRIES ) )
2004-02-17 18:24:28 +03:00
break ;
2008-02-07 22:46:02 +03:00
2002-07-15 14:35:28 +04:00
for ( i = 0 ; i < num_entries ; i + + ) {
2003-06-12 20:21:22 +04:00
2008-02-07 22:46:02 +03:00
const char * group = NULL ;
const char * desc = NULL ;
group = info . info3 . entries [ i ] . account_name . string ;
desc = info . info3 . entries [ i ] . description . string ;
2003-06-12 20:21:22 +04:00
2008-05-10 01:22:12 +04:00
if ( c - > opt_long_list_entries )
2003-06-12 20:21:22 +04:00
printf ( " %-21.21s %-50.50s \n " ,
group , desc ) ;
2002-07-15 14:35:28 +04:00
else
2003-12-01 17:12:26 +03:00
printf ( " %s \n " , group ) ;
2002-07-15 14:35:28 +04:00
}
2003-05-08 02:56:02 +04:00
} while ( NT_STATUS_EQUAL ( result , STATUS_MORE_ENTRIES ) ) ;
2002-07-15 14:35:28 +04:00
/* query domain aliases */
2003-06-12 19:37:06 +04:00
start_idx = 0 ;
2002-07-15 14:35:28 +04:00
do {
2003-11-28 18:10:00 +03:00
if ( ! local ) break ;
2008-02-12 13:09:23 +03:00
result = rpccli_samr_EnumDomainAliases ( pipe_hnd , mem_ctx ,
& domain_pol ,
& start_idx ,
& groups ,
0xffff ,
& num_entries ) ;
2004-02-28 11:18:09 +03:00
if ( ! NT_STATUS_IS_OK ( result ) & &
! NT_STATUS_EQUAL ( result , STATUS_MORE_ENTRIES ) )
2004-02-17 18:24:28 +03:00
break ;
2008-02-12 13:09:23 +03:00
2002-07-15 14:35:28 +04:00
for ( i = 0 ; i < num_entries ; i + + ) {
2003-06-12 20:21:22 +04:00
2008-02-07 15:07:07 +03:00
const char * description = NULL ;
2003-06-12 20:21:22 +04:00
2008-05-10 01:22:12 +04:00
if ( c - > opt_long_list_entries ) {
2003-06-12 20:21:22 +04:00
2009-03-19 00:49:41 +03:00
struct policy_handle alias_pol ;
2008-02-07 15:07:07 +03:00
union samr_AliasInfo * info = NULL ;
2003-06-12 20:21:22 +04:00
2008-02-01 13:38:29 +03:00
if ( ( NT_STATUS_IS_OK ( rpccli_samr_OpenAlias ( pipe_hnd , mem_ctx ,
& domain_pol ,
0x8 ,
2008-02-12 13:09:23 +03:00
groups - > entries [ i ] . idx ,
2008-02-01 13:38:29 +03:00
& alias_pol ) ) ) & &
2008-02-07 15:07:07 +03:00
( NT_STATUS_IS_OK ( rpccli_samr_QueryAliasInfo ( pipe_hnd , mem_ctx ,
& alias_pol ,
3 ,
& info ) ) ) & &
2008-01-30 14:39:20 +03:00
( NT_STATUS_IS_OK ( rpccli_samr_Close ( pipe_hnd , mem_ctx ,
2003-06-12 20:21:22 +04:00
& alias_pol ) ) ) ) {
2008-02-07 15:07:07 +03:00
description = info - > description . string ;
2003-06-12 20:21:22 +04:00
}
}
2008-02-12 13:09:23 +03:00
2003-06-12 20:21:22 +04:00
if ( description ! = NULL ) {
2008-02-12 13:09:23 +03:00
printf ( " %-21.21s %-50.50s \n " ,
groups - > entries [ i ] . name . string ,
2003-06-12 20:21:22 +04:00
description ) ;
} else {
2008-02-12 13:09:23 +03:00
printf ( " %s \n " , groups - > entries [ i ] . name . string ) ;
2003-06-12 20:21:22 +04:00
}
2002-07-15 14:35:28 +04:00
}
2003-05-08 02:56:02 +04:00
} while ( NT_STATUS_EQUAL ( result , STATUS_MORE_ENTRIES ) ) ;
2008-01-30 14:39:20 +03:00
rpccli_samr_Close ( pipe_hnd , mem_ctx , & domain_pol ) ;
2002-07-15 14:35:28 +04:00
/* Get builtin policy handle */
2008-02-01 13:12:05 +03:00
result = rpccli_samr_OpenDomain ( pipe_hnd , mem_ctx ,
& connect_pol ,
MAXIMUM_ALLOWED_ACCESS ,
CONST_DISCARD ( struct dom_sid2 * , & global_sid_Builtin ) ,
& domain_pol ) ;
2002-07-15 14:35:28 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
goto done ;
}
/* query builtin aliases */
2003-06-12 19:37:06 +04:00
start_idx = 0 ;
2002-07-15 14:35:28 +04:00
do {
2003-11-28 18:10:00 +03:00
if ( ! builtin ) break ;
2008-02-12 13:09:23 +03:00
result = rpccli_samr_EnumDomainAliases ( pipe_hnd , mem_ctx ,
& domain_pol ,
& start_idx ,
& groups ,
max_entries ,
& num_entries ) ;
2004-02-28 11:18:09 +03:00
if ( ! NT_STATUS_IS_OK ( result ) & &
! NT_STATUS_EQUAL ( result , STATUS_MORE_ENTRIES ) )
2004-02-17 18:24:28 +03:00
break ;
2008-02-12 13:09:23 +03:00
2002-07-15 14:35:28 +04:00
for ( i = 0 ; i < num_entries ; i + + ) {
2003-06-12 20:21:22 +04:00
2008-02-07 15:07:07 +03:00
const char * description = NULL ;
2003-06-12 20:21:22 +04:00
2008-05-10 01:22:12 +04:00
if ( c - > opt_long_list_entries ) {
2003-06-12 20:21:22 +04:00
2009-03-19 00:49:41 +03:00
struct policy_handle alias_pol ;
2008-02-07 15:07:07 +03:00
union samr_AliasInfo * info = NULL ;
2003-06-12 20:21:22 +04:00
2008-02-01 13:38:29 +03:00
if ( ( NT_STATUS_IS_OK ( rpccli_samr_OpenAlias ( pipe_hnd , mem_ctx ,
& domain_pol ,
0x8 ,
2008-02-12 13:09:23 +03:00
groups - > entries [ i ] . idx ,
2008-02-01 13:38:29 +03:00
& alias_pol ) ) ) & &
2008-02-07 15:07:07 +03:00
( NT_STATUS_IS_OK ( rpccli_samr_QueryAliasInfo ( pipe_hnd , mem_ctx ,
& alias_pol ,
3 ,
& info ) ) ) & &
2008-01-30 14:39:20 +03:00
( NT_STATUS_IS_OK ( rpccli_samr_Close ( pipe_hnd , mem_ctx ,
2003-06-12 20:21:22 +04:00
& alias_pol ) ) ) ) {
2008-02-07 15:07:07 +03:00
description = info - > description . string ;
2003-06-12 20:21:22 +04:00
}
}
2008-02-12 13:09:23 +03:00
2003-06-12 20:21:22 +04:00
if ( description ! = NULL ) {
2008-02-12 13:09:23 +03:00
printf ( " %-21.21s %-50.50s \n " ,
groups - > entries [ i ] . name . string ,
2003-06-12 20:21:22 +04:00
description ) ;
} else {
2008-02-12 13:09:23 +03:00
printf ( " %s \n " , groups - > entries [ i ] . name . string ) ;
2003-06-12 20:21:22 +04:00
}
2002-07-15 14:35:28 +04:00
}
2003-05-08 02:56:02 +04:00
} while ( NT_STATUS_EQUAL ( result , STATUS_MORE_ENTRIES ) ) ;
2002-07-15 14:35:28 +04:00
done :
return result ;
}
2008-05-10 01:22:12 +04:00
static int rpc_group_list ( struct net_context * c , int argc , const char * * argv )
2003-11-28 18:10:00 +03:00
{
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_samr . syntax_id , 0 ,
2003-11-28 18:10:00 +03:00
rpc_group_list_internals ,
argc , argv ) ;
}
2004-02-09 21:19:25 +03:00
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_list_group_members ( struct net_context * c ,
struct rpc_pipe_client * pipe_hnd ,
2005-09-30 21:13:37 +04:00
TALLOC_CTX * mem_ctx ,
const char * domain_name ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2009-03-19 00:49:41 +03:00
struct policy_handle * domain_pol ,
2005-09-30 21:13:37 +04:00
uint32 rid )
2003-11-26 13:07:07 +03:00
{
NTSTATUS result ;
2009-03-19 00:49:41 +03:00
struct policy_handle group_pol ;
2008-02-05 12:58:37 +03:00
uint32 num_members , * group_rids ;
2003-11-26 13:07:07 +03:00
int i ;
2008-02-05 12:58:37 +03:00
struct samr_RidTypeArray * rids = NULL ;
2008-02-08 14:05:29 +03:00
struct lsa_Strings names ;
struct samr_Ids types ;
2003-11-26 13:07:07 +03:00
2004-02-09 21:19:25 +03:00
fstring sid_str ;
2007-12-16 00:47:30 +03:00
sid_to_fstring ( sid_str , domain_sid ) ;
2003-11-26 13:07:07 +03:00
2008-02-01 13:24:01 +03:00
result = rpccli_samr_OpenGroup ( pipe_hnd , mem_ctx ,
domain_pol ,
MAXIMUM_ALLOWED_ACCESS ,
rid ,
& group_pol ) ;
2003-11-26 13:07:07 +03:00
if ( ! NT_STATUS_IS_OK ( result ) )
2004-02-09 21:19:25 +03:00
return result ;
2003-11-26 13:07:07 +03:00
2008-02-05 12:58:37 +03:00
result = rpccli_samr_QueryGroupMember ( pipe_hnd , mem_ctx ,
& group_pol ,
& rids ) ;
2003-11-26 13:07:07 +03:00
if ( ! NT_STATUS_IS_OK ( result ) )
2004-02-09 21:19:25 +03:00
return result ;
2003-11-26 13:07:07 +03:00
2008-02-05 12:58:37 +03:00
num_members = rids - > count ;
group_rids = rids - > rids ;
2004-01-02 08:32:07 +03:00
while ( num_members > 0 ) {
2003-11-27 20:31:18 +03:00
int this_time = 512 ;
2003-11-26 13:07:07 +03:00
2003-11-27 20:31:18 +03:00
if ( num_members < this_time )
this_time = num_members ;
2003-11-26 13:07:07 +03:00
2008-02-08 14:05:29 +03:00
result = rpccli_samr_LookupRids ( pipe_hnd , mem_ctx ,
domain_pol ,
this_time ,
group_rids ,
& names ,
& types ) ;
2003-11-27 20:31:18 +03:00
if ( ! NT_STATUS_IS_OK ( result ) )
2004-02-09 21:19:25 +03:00
return result ;
/* We only have users as members, but make the output
the same as the output of alias members */
2003-11-27 20:31:18 +03:00
for ( i = 0 ; i < this_time ; i + + ) {
2004-02-09 21:19:25 +03:00
2008-05-10 01:22:12 +04:00
if ( c - > opt_long_list_entries ) {
2004-02-09 21:19:25 +03:00
printf ( " %s-%d %s \\ %s %d \n " , sid_str ,
2008-02-08 14:05:29 +03:00
group_rids [ i ] , domain_name ,
names . names [ i ] . string ,
2004-02-09 21:19:25 +03:00
SID_NAME_USER ) ;
} else {
2008-02-08 14:05:29 +03:00
printf ( " %s \\ %s \n " , domain_name ,
names . names [ i ] . string ) ;
2004-02-09 21:19:25 +03:00
}
2003-11-27 20:31:18 +03:00
}
num_members - = this_time ;
group_rids + = 512 ;
2004-01-02 08:32:07 +03:00
}
2003-11-26 13:07:07 +03:00
2004-02-09 21:19:25 +03:00
return NT_STATUS_OK ;
}
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_list_alias_members ( struct net_context * c ,
struct rpc_pipe_client * pipe_hnd ,
2005-09-30 21:13:37 +04:00
TALLOC_CTX * mem_ctx ,
2009-03-19 00:49:41 +03:00
struct policy_handle * domain_pol ,
2005-09-30 21:13:37 +04:00
uint32 rid )
2004-02-09 21:19:25 +03:00
{
NTSTATUS result ;
2005-09-30 21:13:37 +04:00
struct rpc_pipe_client * lsa_pipe ;
2009-03-19 00:49:41 +03:00
struct policy_handle alias_pol , lsa_pol ;
2004-02-09 21:19:25 +03:00
uint32 num_members ;
2010-05-21 05:25:01 +04:00
struct dom_sid * alias_sids ;
2004-02-09 21:19:25 +03:00
char * * domains ;
char * * names ;
2006-09-08 18:28:06 +04:00
enum lsa_SidType * types ;
2004-02-09 21:19:25 +03:00
int i ;
2008-02-05 03:18:56 +03:00
struct lsa_SidArray sid_array ;
2004-02-09 21:19:25 +03:00
2008-02-01 13:38:29 +03:00
result = rpccli_samr_OpenAlias ( pipe_hnd , mem_ctx ,
domain_pol ,
MAXIMUM_ALLOWED_ACCESS ,
rid ,
& alias_pol ) ;
2004-02-09 21:19:25 +03:00
if ( ! NT_STATUS_IS_OK ( result ) )
return result ;
2008-02-05 03:18:56 +03:00
result = rpccli_samr_GetMembersInAlias ( pipe_hnd , mem_ctx ,
& alias_pol ,
& sid_array ) ;
2004-02-09 21:19:25 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Couldn't list alias members \n " ) ) ;
2004-02-09 21:19:25 +03:00
return result ;
}
2008-02-05 03:18:56 +03:00
num_members = sid_array . num_sids ;
2004-02-17 13:08:18 +03:00
if ( num_members = = 0 ) {
return NT_STATUS_OK ;
}
2008-07-20 13:04:31 +04:00
result = cli_rpc_pipe_open_noauth ( rpc_pipe_np_smb_conn ( pipe_hnd ) ,
& ndr_table_lsarpc . syntax_id ,
& lsa_pipe ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Couldn't open LSA pipe. Error was %s \n " ) ,
2005-09-30 21:13:37 +04:00
nt_errstr ( result ) ) ;
2004-02-09 21:19:25 +03:00
return result ;
}
2008-05-12 13:53:23 +04:00
result = rpccli_lsa_open_policy ( lsa_pipe , mem_ctx , true ,
2009-04-15 03:12:13 +04:00
SEC_FLAG_MAXIMUM_ALLOWED , & lsa_pol ) ;
2004-02-09 21:19:25 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Couldn't open LSA policy handle \n " ) ) ;
2008-04-20 15:51:46 +04:00
TALLOC_FREE ( lsa_pipe ) ;
2004-02-09 21:19:25 +03:00
return result ;
}
2010-05-21 05:25:01 +04:00
alias_sids = TALLOC_ZERO_ARRAY ( mem_ctx , struct dom_sid , num_members ) ;
2008-02-05 03:18:56 +03:00
if ( ! alias_sids ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Out of memory \n " ) ) ;
2008-04-20 15:51:46 +04:00
TALLOC_FREE ( lsa_pipe ) ;
2008-02-05 03:18:56 +03:00
return NT_STATUS_NO_MEMORY ;
}
for ( i = 0 ; i < num_members ; i + + ) {
sid_copy ( & alias_sids [ i ] , sid_array . sids [ i ] . sid ) ;
}
2008-05-10 01:22:12 +04:00
result = rpccli_lsa_lookup_sids ( lsa_pipe , mem_ctx , & lsa_pol ,
num_members , alias_sids ,
2004-02-09 21:19:25 +03:00
& domains , & names , & types ) ;
if ( ! NT_STATUS_IS_OK ( result ) & &
! NT_STATUS_EQUAL ( result , STATUS_SOME_UNMAPPED ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Couldn't lookup SIDs \n " ) ) ;
2008-04-20 15:51:46 +04:00
TALLOC_FREE ( lsa_pipe ) ;
2004-02-09 21:19:25 +03:00
return result ;
}
for ( i = 0 ; i < num_members ; i + + ) {
fstring sid_str ;
2007-12-16 00:47:30 +03:00
sid_to_fstring ( sid_str , & alias_sids [ i ] ) ;
2004-02-09 21:19:25 +03:00
2008-05-10 01:22:12 +04:00
if ( c - > opt_long_list_entries ) {
2008-05-08 13:23:38 +04:00
printf ( " %s %s \\ %s %d \n " , sid_str ,
2009-08-04 10:28:50 +04:00
domains [ i ] ? domains [ i ] : _ ( " *unknown* " ) ,
names [ i ] ? names [ i ] : _ ( " *unknown* " ) , types [ i ] ) ;
2004-02-09 21:19:25 +03:00
} else {
if ( domains [ i ] )
printf ( " %s \\ %s \n " , domains [ i ] , names [ i ] ) ;
else
printf ( " %s \n " , sid_str ) ;
}
}
2008-04-20 15:51:46 +04:00
TALLOC_FREE ( lsa_pipe ) ;
2004-02-09 21:19:25 +03:00
return NT_STATUS_OK ;
}
2008-05-08 13:23:38 +04:00
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_group_members_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
2005-09-30 21:13:37 +04:00
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2004-02-09 21:19:25 +03:00
{
NTSTATUS result ;
2009-03-19 00:49:41 +03:00
struct policy_handle connect_pol , domain_pol ;
2008-02-08 16:50:04 +03:00
struct samr_Ids rids , rid_types ;
struct lsa_String lsa_acct_name ;
2004-02-09 21:19:25 +03:00
/* Get sam policy handle */
2008-02-04 21:43:07 +03:00
result = rpccli_samr_Connect2 ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2008-02-04 21:43:07 +03:00
MAXIMUM_ALLOWED_ACCESS ,
& connect_pol ) ;
2004-02-09 21:19:25 +03:00
if ( ! NT_STATUS_IS_OK ( result ) )
return result ;
2008-05-08 13:23:38 +04:00
2004-02-09 21:19:25 +03:00
/* Get domain policy handle */
2008-02-01 13:12:05 +03:00
result = rpccli_samr_OpenDomain ( pipe_hnd , mem_ctx ,
& connect_pol ,
MAXIMUM_ALLOWED_ACCESS ,
CONST_DISCARD ( struct dom_sid2 * , domain_sid ) ,
& domain_pol ) ;
2004-02-09 21:19:25 +03:00
if ( ! NT_STATUS_IS_OK ( result ) )
return result ;
2008-02-08 16:50:04 +03:00
init_lsa_String ( & lsa_acct_name , argv [ 0 ] ) ; /* sure? */
result = rpccli_samr_LookupNames ( pipe_hnd , mem_ctx ,
& domain_pol ,
1 ,
& lsa_acct_name ,
& rids ,
& rid_types ) ;
2004-02-09 21:19:25 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
/* Ok, did not find it in the global sam, try with builtin */
2010-05-21 05:25:01 +04:00
struct dom_sid sid_Builtin ;
2004-02-09 21:19:25 +03:00
2008-01-30 14:39:20 +03:00
rpccli_samr_Close ( pipe_hnd , mem_ctx , & domain_pol ) ;
2004-02-09 21:19:25 +03:00
2008-03-17 23:00:16 +03:00
sid_copy ( & sid_Builtin , & global_sid_Builtin ) ;
2004-02-09 21:19:25 +03:00
2008-02-01 13:12:05 +03:00
result = rpccli_samr_OpenDomain ( pipe_hnd , mem_ctx ,
& connect_pol ,
MAXIMUM_ALLOWED_ACCESS ,
& sid_Builtin ,
& domain_pol ) ;
2004-02-09 21:19:25 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Couldn't find group %s \n " ) ,
argv [ 0 ] ) ;
2004-02-09 21:19:25 +03:00
return result ;
}
2008-02-08 16:50:04 +03:00
result = rpccli_samr_LookupNames ( pipe_hnd , mem_ctx ,
& domain_pol ,
1 ,
& lsa_acct_name ,
& rids ,
& rid_types ) ;
2004-02-09 21:19:25 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Couldn't find group %s \n " ) ,
argv [ 0 ] ) ;
2004-02-09 21:19:25 +03:00
return result ;
}
}
2008-02-08 16:50:04 +03:00
if ( rids . count ! = 1 ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Couldn't find group %s \n " ) ,
argv [ 0 ] ) ;
2004-02-09 21:19:25 +03:00
return result ;
}
2008-02-08 16:50:04 +03:00
if ( rid_types . ids [ 0 ] = = SID_NAME_DOM_GRP ) {
2008-05-10 01:22:12 +04:00
return rpc_list_group_members ( c , pipe_hnd , mem_ctx , domain_name ,
2004-02-09 21:19:25 +03:00
domain_sid , & domain_pol ,
2008-02-08 16:50:04 +03:00
rids . ids [ 0 ] ) ;
2004-02-09 21:19:25 +03:00
}
2008-02-08 16:50:04 +03:00
if ( rid_types . ids [ 0 ] = = SID_NAME_ALIAS ) {
2008-05-10 01:22:12 +04:00
return rpc_list_alias_members ( c , pipe_hnd , mem_ctx , & domain_pol ,
2008-02-08 16:50:04 +03:00
rids . ids [ 0 ] ) ;
2004-02-09 21:19:25 +03:00
}
return NT_STATUS_NO_SUCH_GROUP ;
2003-11-26 13:07:07 +03:00
}
2008-05-10 01:22:12 +04:00
static int rpc_group_members ( struct net_context * c , int argc , const char * * argv )
2003-11-26 13:07:07 +03:00
{
2008-05-21 12:27:59 +04:00
if ( argc ! = 1 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
return rpc_group_usage ( c , argc , argv ) ;
2003-11-26 13:07:07 +03:00
}
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_samr . syntax_id , 0 ,
2003-11-26 13:07:07 +03:00
rpc_group_members_internals ,
argc , argv ) ;
}
2008-06-06 15:52:51 +04:00
static int rpc_group_rename_internals ( struct net_context * c , int argc , const char * * argv )
2004-06-02 18:25:29 +04:00
{
2008-06-06 15:52:51 +04:00
NET_API_STATUS status ;
struct GROUP_INFO_0 g0 ;
uint32_t parm_err ;
2004-06-02 18:25:29 +04:00
if ( argc ! = 2 ) {
2010-01-19 13:43:54 +03:00
d_printf ( _ ( " Usage: \n " ) ) ;
d_printf ( " net rpc group rename group newname \n " ) ;
2008-06-06 15:52:51 +04:00
return - 1 ;
2004-06-02 18:25:29 +04:00
}
2008-06-06 15:52:51 +04:00
g0 . grpi0_name = argv [ 1 ] ;
2008-05-08 13:23:38 +04:00
2008-06-06 15:52:51 +04:00
status = NetGroupSetInfo ( c - > opt_host ,
argv [ 0 ] ,
0 ,
( uint8_t * ) & g0 ,
& parm_err ) ;
2008-02-08 16:50:04 +03:00
2008-06-06 15:52:51 +04:00
if ( status ! = 0 ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Renaming group %s failed with: %s \n " ) ,
2008-06-06 15:52:51 +04:00
argv [ 0 ] , libnetapi_get_error_string ( c - > netapi_ctx ,
status ) ) ;
return - 1 ;
2004-06-02 18:25:29 +04:00
}
2008-06-06 15:52:51 +04:00
return 0 ;
2004-06-02 18:25:29 +04:00
}
2008-05-10 01:22:12 +04:00
static int rpc_group_rename ( struct net_context * c , int argc , const char * * argv )
2004-06-02 18:25:29 +04:00
{
2008-05-21 12:27:59 +04:00
if ( argc ! = 2 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
return rpc_group_usage ( c , argc , argv ) ;
2004-06-02 18:25:29 +04:00
}
2008-06-06 15:52:51 +04:00
return rpc_group_rename_internals ( c , argc , argv ) ;
2004-06-02 18:25:29 +04:00
}
2008-05-08 13:23:38 +04:00
/**
2002-07-15 14:35:28 +04:00
* ' net rpc group ' entrypoint .
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-07-15 14:35:28 +04:00
* */
2008-05-10 01:22:12 +04:00
int net_rpc_group ( struct net_context * c , int argc , const char * * argv )
2002-07-15 14:35:28 +04:00
{
2008-05-28 16:57:35 +04:00
NET_API_STATUS status ;
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 12:27:59 +04:00
{
" add " ,
rpc_group_add ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Create specified group " ) ,
N_ ( " net rpc group add \n "
" Create specified group " )
2008-05-21 12:27:59 +04:00
} ,
{
" delete " ,
rpc_group_delete ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Delete specified group " ) ,
N_ ( " net rpc group delete \n "
" Delete specified group " )
2008-05-21 12:27:59 +04:00
} ,
{
" addmem " ,
rpc_group_addmem ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Add member to group " ) ,
N_ ( " net rpc group addmem \n "
" Add member to group " )
2008-05-21 12:27:59 +04:00
} ,
{
" delmem " ,
rpc_group_delmem ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Remove member from group " ) ,
N_ ( " net rpc group delmem \n "
" Remove member from group " )
2008-05-21 12:27:59 +04:00
} ,
{
" list " ,
rpc_group_list ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " List groups " ) ,
N_ ( " net rpc group list \n "
" List groups " )
2008-05-21 12:27:59 +04:00
} ,
{
" members " ,
rpc_group_members ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " List group members " ) ,
N_ ( " net rpc group members \n "
" List group members " )
2008-05-21 12:27:59 +04:00
} ,
{
" rename " ,
rpc_group_rename ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Rename group " ) ,
N_ ( " net rpc group rename \n "
" Rename group " )
2008-05-21 12:27:59 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2002-07-15 14:35:28 +04:00
} ;
2008-05-08 13:23:38 +04:00
2008-05-28 16:57:35 +04:00
status = libnetapi_init ( & c - > netapi_ctx ) ;
if ( status ! = 0 ) {
return - 1 ;
}
2009-07-05 11:21:07 +04:00
libnetapi_set_username ( c - > netapi_ctx , c - > opt_user_name ) ;
libnetapi_set_password ( c - > netapi_ctx , c - > opt_password ) ;
if ( c - > opt_kerberos ) {
2008-07-31 17:14:14 +04:00
libnetapi_set_use_kerberos ( c - > netapi_ctx ) ;
}
2008-05-28 16:57:35 +04:00
2002-07-15 14:35:28 +04:00
if ( argc = = 0 ) {
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Usage: \n " ) ) ;
d_printf ( _ ( " net rpc group \n "
" Alias for net rpc group list global "
" local builtin \n " ) ) ;
2008-05-21 12:27:59 +04:00
net_display_usage_from_functable ( func ) ;
return 0 ;
}
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_samr . syntax_id , 0 ,
2002-07-15 14:35:28 +04:00
rpc_group_list_internals ,
argc , argv ) ;
}
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rpc group " , func ) ;
2002-07-15 14:35:28 +04:00
}
/****************************************************************************/
2008-05-10 01:22:12 +04:00
static int rpc_share_usage ( struct net_context * c , int argc , const char * * argv )
2002-07-15 14:35:28 +04:00
{
2008-05-14 16:24:21 +04:00
return net_share_usage ( c , argc , argv ) ;
2002-07-15 14:35:28 +04:00
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Add a share on a remote RPC server .
2002-07-15 14:35:28 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-07-15 14:35:28 +04:00
*
2008-09-04 17:37:03 +04:00
* @ return A shell status integer ( 0 for success ) .
2002-07-15 14:35:28 +04:00
* */
2008-09-04 17:37:03 +04:00
static int rpc_share_add ( struct net_context * c , int argc , const char * * argv )
2002-07-15 14:35:28 +04:00
{
2008-09-04 17:37:03 +04:00
NET_API_STATUS status ;
2006-06-19 23:07:39 +04:00
char * sharename ;
2002-07-15 14:35:28 +04:00
char * path ;
2005-06-16 13:36:53 +04:00
uint32 type = STYPE_DISKTREE ; /* only allow disk shares to be added */
2002-07-15 14:35:28 +04:00
uint32 num_users = 0 , perms = 0 ;
char * password = NULL ; /* don't allow a share password */
2008-09-04 17:37:03 +04:00
struct SHARE_INFO_2 i2 ;
2008-03-10 16:25:45 +03:00
uint32_t parm_error = 0 ;
2002-07-15 14:35:28 +04:00
2008-09-04 17:37:03 +04:00
if ( ( argc < 1 ) | | ! strchr ( argv [ 0 ] , ' = ' ) | | c - > display_usage ) {
return rpc_share_usage ( c , argc , argv ) ;
}
if ( ( sharename = talloc_strdup ( c , argv [ 0 ] ) ) = = NULL ) {
return - 1 ;
2006-06-19 23:07:39 +04:00
}
2002-07-15 14:35:28 +04:00
path = strchr ( sharename , ' = ' ) ;
2008-09-04 17:37:03 +04:00
if ( ! path ) {
return - 1 ;
}
2002-07-15 14:35:28 +04:00
2008-09-04 17:37:03 +04:00
* path + + = ' \0 ' ;
2002-07-15 14:35:28 +04:00
2008-09-04 17:37:03 +04:00
i2 . shi2_netname = sharename ;
i2 . shi2_type = type ;
i2 . shi2_remark = c - > opt_comment ;
i2 . shi2_permissions = perms ;
i2 . shi2_max_uses = c - > opt_maxusers ;
i2 . shi2_current_uses = num_users ;
i2 . shi2_path = path ;
i2 . shi2_passwd = password ;
status = NetShareAdd ( c - > opt_host ,
2 ,
( uint8_t * ) & i2 ,
& parm_error ) ;
if ( status ! = 0 ) {
2009-08-04 10:28:50 +04:00
printf ( _ ( " NetShareAdd failed with: %s \n " ) ,
2008-09-04 17:37:03 +04:00
libnetapi_get_error_string ( c - > netapi_ctx , status ) ) ;
2002-07-15 14:35:28 +04:00
}
2008-09-04 17:37:03 +04:00
return status ;
2002-07-15 14:35:28 +04:00
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Delete a share on a remote RPC server .
2002-07-15 14:35:28 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param domain_sid The domain sid acquired from the remote server .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-07-15 14:35:28 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2002-07-15 14:35:28 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_share_delete ( struct net_context * c , int argc , const char * * argv )
2002-07-15 14:35:28 +04:00
{
2008-05-21 12:27:59 +04:00
if ( argc < 1 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
return rpc_share_usage ( c , argc , argv ) ;
2002-07-15 14:35:28 +04:00
}
2008-09-04 17:44:50 +04:00
return NetShareDel ( c - > opt_host , argv [ 0 ] , 0 ) ;
2002-07-15 14:35:28 +04:00
}
/**
* Formatted print of share info
*
2008-09-10 12:53:46 +04:00
* @ param r pointer to SHARE_INFO_1 to format
2002-07-15 14:35:28 +04:00
* */
2007-10-11 00:34:30 +04:00
2008-05-10 01:22:12 +04:00
static void display_share_info_1 ( struct net_context * c ,
2008-09-10 12:53:46 +04:00
struct SHARE_INFO_1 * r )
2008-03-10 18:19:25 +03:00
{
2008-05-10 01:22:12 +04:00
if ( c - > opt_long_list_entries ) {
2004-02-11 17:59:08 +03:00
d_printf ( " %-12s %-8.8s %-50s \n " ,
2008-09-10 12:53:46 +04:00
r - > shi1_netname ,
2008-09-25 01:23:01 +04:00
net_share_type_str ( r - > shi1_type & ~ ( STYPE_TEMPORARY | STYPE_HIDDEN ) ) ,
2008-09-10 12:53:46 +04:00
r - > shi1_remark ) ;
2002-07-15 14:35:28 +04:00
} else {
2008-09-10 12:53:46 +04:00
d_printf ( " %s \n " , r - > shi1_netname ) ;
2002-07-15 14:35:28 +04:00
}
}
2008-05-10 01:22:12 +04:00
static WERROR get_share_info ( struct net_context * c ,
struct rpc_pipe_client * pipe_hnd ,
2008-03-10 18:19:25 +03:00
TALLOC_CTX * mem_ctx ,
uint32 level ,
int argc ,
const char * * argv ,
struct srvsvc_NetShareInfoCtr * info_ctr )
2005-06-16 13:36:53 +04:00
{
2007-10-11 00:34:30 +04:00
WERROR result ;
2008-03-10 18:19:25 +03:00
NTSTATUS status ;
union srvsvc_NetShareInfo info ;
2005-06-16 13:36:53 +04:00
/* no specific share requested, enumerate all */
if ( argc = = 0 ) {
2008-03-10 18:19:25 +03:00
uint32_t preferred_len = 0xffffffff ;
uint32_t total_entries = 0 ;
uint32_t resume_handle = 0 ;
2007-10-11 00:34:30 +04:00
2008-03-10 18:19:25 +03:00
info_ctr - > level = level ;
2007-10-11 00:34:30 +04:00
2008-03-10 18:19:25 +03:00
status = rpccli_srvsvc_NetShareEnumAll ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2008-03-10 18:19:25 +03:00
info_ctr ,
preferred_len ,
& total_entries ,
& resume_handle ,
& result ) ;
return result ;
2005-06-16 13:36:53 +04:00
}
/* request just one share */
2008-03-10 18:19:25 +03:00
status = rpccli_srvsvc_NetShareGetInfo ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2008-03-10 18:19:25 +03:00
argv [ 0 ] ,
level ,
& info ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) | | ! W_ERROR_IS_OK ( result ) ) {
2007-10-11 00:34:30 +04:00
goto done ;
2008-03-10 18:19:25 +03:00
}
2007-10-11 00:34:30 +04:00
/* construct ctr */
2008-03-10 18:19:25 +03:00
ZERO_STRUCTP ( info_ctr ) ;
2007-10-11 00:34:30 +04:00
2008-03-10 18:19:25 +03:00
info_ctr - > level = level ;
2006-10-21 20:27:38 +04:00
2007-10-11 00:34:30 +04:00
switch ( level ) {
2006-10-21 20:27:38 +04:00
case 1 :
2007-10-11 00:34:30 +04:00
{
2008-03-10 18:19:25 +03:00
struct srvsvc_NetShareCtr1 * ctr1 ;
2007-10-11 00:34:30 +04:00
2008-03-10 18:19:25 +03:00
ctr1 = TALLOC_ZERO_P ( mem_ctx , struct srvsvc_NetShareCtr1 ) ;
W_ERROR_HAVE_NO_MEMORY ( ctr1 ) ;
2007-10-11 00:34:30 +04:00
2008-03-10 18:19:25 +03:00
ctr1 - > count = 1 ;
ctr1 - > array = info . info1 ;
2007-10-11 00:34:30 +04:00
2008-03-10 18:19:25 +03:00
info_ctr - > ctr . ctr1 = ctr1 ;
2007-10-11 00:34:30 +04:00
}
case 2 :
{
2008-03-10 18:19:25 +03:00
struct srvsvc_NetShareCtr2 * ctr2 ;
2007-10-11 00:34:30 +04:00
2008-03-10 18:19:25 +03:00
ctr2 = TALLOC_ZERO_P ( mem_ctx , struct srvsvc_NetShareCtr2 ) ;
W_ERROR_HAVE_NO_MEMORY ( ctr2 ) ;
2007-10-11 00:34:30 +04:00
2008-03-10 18:19:25 +03:00
ctr2 - > count = 1 ;
ctr2 - > array = info . info2 ;
2007-10-11 00:34:30 +04:00
2008-03-10 18:19:25 +03:00
info_ctr - > ctr . ctr2 = ctr2 ;
2007-10-11 00:34:30 +04:00
}
2006-10-21 20:27:38 +04:00
case 502 :
2007-10-11 00:34:30 +04:00
{
2008-03-10 18:19:25 +03:00
struct srvsvc_NetShareCtr502 * ctr502 ;
2007-10-11 00:34:30 +04:00
2008-03-10 18:19:25 +03:00
ctr502 = TALLOC_ZERO_P ( mem_ctx , struct srvsvc_NetShareCtr502 ) ;
W_ERROR_HAVE_NO_MEMORY ( ctr502 ) ;
2007-10-11 00:34:30 +04:00
2008-03-10 18:19:25 +03:00
ctr502 - > count = 1 ;
ctr502 - > array = info . info502 ;
2007-10-11 00:34:30 +04:00
2008-03-10 18:19:25 +03:00
info_ctr - > ctr . ctr502 = ctr502 ;
2006-10-21 20:27:38 +04:00
}
2007-10-11 00:34:30 +04:00
} /* switch */
done :
return result ;
2005-06-16 13:36:53 +04:00
}
2008-09-10 12:53:46 +04:00
/***
* ' net rpc share list ' entrypoint .
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-07-15 14:35:28 +04:00
* */
2008-09-10 12:53:46 +04:00
static int rpc_share_list ( struct net_context * c , int argc , const char * * argv )
2002-07-15 14:35:28 +04:00
{
2008-09-10 12:53:46 +04:00
NET_API_STATUS status ;
struct SHARE_INFO_1 * i1 = NULL ;
uint32_t entries_read = 0 ;
uint32_t total_entries = 0 ;
uint32_t resume_handle = 0 ;
uint32_t i , level = 1 ;
2008-03-10 18:19:25 +03:00
2008-09-10 12:53:46 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc share list \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " List shares on remote server " ) ) ;
2008-09-10 12:53:46 +04:00
return 0 ;
}
2008-03-10 18:19:25 +03:00
2008-09-10 12:53:46 +04:00
status = NetShareEnum ( c - > opt_host ,
level ,
2009-02-01 02:31:16 +03:00
( uint8_t * * ) ( void * ) & i1 ,
2008-09-10 12:53:46 +04:00
( uint32_t ) - 1 ,
& entries_read ,
& total_entries ,
& resume_handle ) ;
if ( status ! = 0 ) {
2002-07-15 14:35:28 +04:00
goto done ;
2008-09-10 12:53:46 +04:00
}
2002-07-15 14:35:28 +04:00
/* Display results */
2008-05-10 01:22:12 +04:00
if ( c - > opt_long_list_entries ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ (
2008-05-21 12:27:59 +04:00
" \n Enumerating shared resources (exports) on remote server: \n \n "
" \n Share name Type Description \n "
2009-08-04 10:28:50 +04:00
" ---------- ---- ----------- \n " ) ) ;
2002-07-15 14:35:28 +04:00
}
2008-09-10 12:53:46 +04:00
for ( i = 0 ; i < entries_read ; i + + )
display_share_info_1 ( c , & i1 [ i ] ) ;
2002-07-15 14:35:28 +04:00
done :
2008-09-10 12:53:46 +04:00
return status ;
2005-06-16 13:36:53 +04:00
}
2007-10-19 04:40:25 +04:00
static bool check_share_availability ( struct cli_state * cli , const char * netname )
2005-06-16 13:36:53 +04:00
{
2010-01-03 20:46:57 +03:00
NTSTATUS status ;
status = cli_tcon_andx ( cli , netname , " A: " , " " , 0 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " skipping [%s]: not a file share. \n " ) , netname ) ;
2008-05-12 13:53:23 +04:00
return false ;
2005-06-16 13:36:53 +04:00
}
2010-01-03 20:46:57 +03:00
status = cli_tdis ( cli ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_printf ( _ ( " cli_tdis returned %s \n " ) , nt_errstr ( status ) ) ;
2008-05-12 13:53:23 +04:00
return false ;
2010-01-03 20:46:57 +03:00
}
2005-06-16 13:36:53 +04:00
2008-05-12 13:53:23 +04:00
return true ;
2005-06-16 13:36:53 +04:00
}
2008-05-10 01:22:12 +04:00
static bool check_share_sanity ( struct net_context * c , struct cli_state * cli ,
const char * netname , uint32 type )
2005-06-16 13:36:53 +04:00
{
/* only support disk shares */
if ( ! ( type = = STYPE_DISKTREE | | type = = ( STYPE_DISKTREE | STYPE_HIDDEN ) ) ) {
2009-08-04 10:28:50 +04:00
printf ( _ ( " share [%s] is not a diskshare (type: %x) \n " ) , netname ,
type ) ;
2008-05-12 13:53:23 +04:00
return false ;
2005-06-16 13:36:53 +04:00
}
/* skip builtin shares */
/* FIXME: should print$ be added too ? */
2008-05-08 13:23:38 +04:00
if ( strequal ( netname , " IPC$ " ) | | strequal ( netname , " ADMIN$ " ) | |
strequal ( netname , " global " ) )
2008-05-12 13:53:23 +04:00
return false ;
2005-06-16 13:36:53 +04:00
2008-05-12 13:53:23 +04:00
if ( c - > opt_exclude & & in_list ( netname , c - > opt_exclude , false ) ) {
2009-08-04 10:28:50 +04:00
printf ( _ ( " excluding [%s] \n " ) , netname ) ;
2008-05-12 13:53:23 +04:00
return false ;
2005-06-16 13:36:53 +04:00
}
return check_share_availability ( cli , netname ) ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Migrate shares from a remote RPC server to the local RPC server .
2004-08-10 18:27:17 +04:00
*
* All parameters are provided by the run_rpc_command function , except for
2008-05-08 13:23:38 +04:00
* argc , argv which are passed through .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param domain_sid The domain sid acquired from the remote server .
2004-08-10 18:27:17 +04:00
* @ param cli A cli_state connected to the server .
2008-02-26 12:26:10 +03:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-08-10 18:27:17 +04:00
*
* @ return Normal NTSTATUS return .
* */
2005-09-30 21:13:37 +04:00
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_share_migrate_shares_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
2005-09-30 21:13:37 +04:00
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
2008-05-08 13:23:38 +04:00
TALLOC_CTX * mem_ctx ,
2005-09-30 21:13:37 +04:00
int argc ,
const char * * argv )
2004-08-10 18:27:17 +04:00
{
2007-10-11 00:34:30 +04:00
WERROR result ;
2004-08-10 18:27:17 +04:00
NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL ;
2008-03-10 18:19:25 +03:00
struct srvsvc_NetShareInfoCtr ctr_src ;
2005-06-16 13:36:53 +04:00
uint32 i ;
2005-09-30 21:13:37 +04:00
struct rpc_pipe_client * srvsvc_pipe = NULL ;
2004-08-10 18:27:17 +04:00
struct cli_state * cli_dst = NULL ;
uint32 level = 502 ; /* includes secdesc */
2008-03-10 18:19:25 +03:00
uint32_t parm_error = 0 ;
2004-08-10 18:27:17 +04:00
2008-05-10 01:22:12 +04:00
result = get_share_info ( c , pipe_hnd , mem_ctx , level , argc , argv ,
& ctr_src ) ;
2007-10-11 00:34:30 +04:00
if ( ! W_ERROR_IS_OK ( result ) )
2004-08-10 18:27:17 +04:00
goto done ;
2005-06-16 13:36:53 +04:00
/* connect destination PI_SRVSVC */
2008-07-20 20:44:32 +04:00
nt_status = connect_dst_pipe ( c , & cli_dst , & srvsvc_pipe ,
& ndr_table_srvsvc . syntax_id ) ;
2004-08-10 18:27:17 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) )
return nt_status ;
2008-03-10 18:19:25 +03:00
for ( i = 0 ; i < ctr_src . ctr . ctr502 - > count ; i + + ) {
union srvsvc_NetShareInfo info ;
struct srvsvc_NetShareInfo502 info502 =
ctr_src . ctr . ctr502 - > array [ i ] ;
2004-08-10 18:27:17 +04:00
/* reset error-code */
nt_status = NT_STATUS_UNSUCCESSFUL ;
2008-05-10 01:22:12 +04:00
if ( ! check_share_sanity ( c , cli , info502 . name , info502 . type ) )
2005-03-22 18:45:38 +03:00
continue ;
2004-08-10 18:27:17 +04:00
2008-05-08 13:23:38 +04:00
/* finally add the share on the dst server */
2004-08-10 18:27:17 +04:00
2009-08-04 10:28:50 +04:00
printf ( _ ( " migrating: [%s], path: %s, comment: %s, without "
" share-ACLs \n " ) ,
2008-03-10 18:19:25 +03:00
info502 . name , info502 . path , info502 . comment ) ;
info . info502 = & info502 ;
nt_status = rpccli_srvsvc_NetShareAdd ( srvsvc_pipe , mem_ctx ,
2008-04-19 23:56:43 +04:00
srvsvc_pipe - > desthost ,
2008-03-10 18:19:25 +03:00
502 ,
& info ,
& parm_error ,
& result ) ;
2008-10-23 17:37:39 +04:00
if ( W_ERROR_V ( result ) = = W_ERROR_V ( WERR_FILE_EXISTS ) ) {
2009-08-04 10:28:50 +04:00
printf ( _ ( " [%s] does already exist \n " ) ,
2008-03-10 18:19:25 +03:00
info502 . name ) ;
2004-08-10 18:27:17 +04:00
continue ;
2004-08-21 00:13:05 +04:00
}
2008-03-10 18:19:25 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) | | ! W_ERROR_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
printf ( _ ( " cannot add share: %s \n " ) , win_errstr ( result ) ) ;
2004-08-10 18:27:17 +04:00
goto done ;
}
}
nt_status = NT_STATUS_OK ;
done :
2005-09-30 21:13:37 +04:00
if ( cli_dst ) {
2004-08-10 18:27:17 +04:00
cli_shutdown ( cli_dst ) ;
}
return nt_status ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Migrate shares from a RPC server to another .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-08-10 18:27:17 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_share_migrate_shares ( struct net_context * c , int argc ,
const char * * argv )
2004-08-10 18:27:17 +04:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc share migrate shares \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Migrate shares to local server " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2004-08-10 18:27:17 +04:00
2008-05-10 01:22:12 +04:00
if ( ! c - > opt_host ) {
2009-08-04 10:28:50 +04:00
printf ( _ ( " no server to migrate \n " ) ) ;
2004-08-21 00:13:05 +04:00
return - 1 ;
}
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_srvsvc . syntax_id , 0 ,
2004-08-10 18:27:17 +04:00
rpc_share_migrate_shares_internals ,
argc , argv ) ;
}
/**
2008-05-08 13:23:38 +04:00
* Copy a file / dir
2004-08-10 18:27:17 +04:00
*
* @ param f file_info
* @ param mask current search mask
* @ param state arg - pointer
*
* */
2010-07-27 12:59:55 +04:00
static void copy_fn ( const char * mnt , struct file_info * f ,
2008-05-10 01:22:12 +04:00
const char * mask , void * state )
2004-08-10 18:27:17 +04:00
{
2005-06-13 01:18:16 +04:00
static NTSTATUS nt_status ;
static struct copy_clistate * local_state ;
static fstring filename , new_mask ;
fstring dir ;
char * old_dir ;
2008-05-10 01:22:12 +04:00
struct net_context * c ;
2005-06-13 01:18:16 +04:00
local_state = ( struct copy_clistate * ) state ;
nt_status = NT_STATUS_UNSUCCESSFUL ;
2008-05-10 01:22:12 +04:00
c = local_state - > c ;
2005-06-15 18:24:11 +04:00
if ( strequal ( f - > name , " . " ) | | strequal ( f - > name , " .. " ) )
2004-08-10 18:27:17 +04:00
return ;
DEBUG ( 3 , ( " got mask: %s, name: %s \n " , mask , f - > name ) ) ;
/* DIRECTORY */
if ( f - > mode & aDIR ) {
DEBUG ( 3 , ( " got dir: %s \n " , f - > name ) ) ;
fstrcpy ( dir , local_state - > cwd ) ;
fstrcat ( dir , " \\ " ) ;
fstrcat ( dir , f - > name ) ;
2005-06-24 03:23:16 +04:00
switch ( net_mode_share )
2005-06-13 01:18:16 +04:00
{
case NET_MODE_SHARE_MIGRATE :
/* create that directory */
2008-05-10 01:22:12 +04:00
nt_status = net_copy_file ( c , local_state - > mem_ctx ,
2005-06-13 01:18:16 +04:00
local_state - > cli_share_src ,
local_state - > cli_share_dst ,
dir , dir ,
2008-05-10 01:22:12 +04:00
c - > opt_acls ? true : false ,
c - > opt_attrs ? true : false ,
c - > opt_timestamps ? true : false ,
false ) ;
2005-06-13 01:18:16 +04:00
break ;
default :
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Unsupported mode %d \n " ) , net_mode_share ) ;
2005-06-13 01:18:16 +04:00
return ;
}
2004-08-10 18:27:17 +04:00
2008-05-08 13:23:38 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) )
2009-08-04 10:28:50 +04:00
printf ( _ ( " could not handle dir %s: %s \n " ) ,
2004-08-10 18:27:17 +04:00
dir , nt_errstr ( nt_status ) ) ;
2005-06-15 18:24:11 +04:00
/* search below that directory */
fstrcpy ( new_mask , dir ) ;
fstrcat ( new_mask , " \\ * " ) ;
old_dir = local_state - > cwd ;
local_state - > cwd = dir ;
2009-07-05 11:21:07 +04:00
if ( ! sync_files ( local_state , new_mask ) )
2009-08-04 10:28:50 +04:00
printf ( _ ( " could not handle files \n " ) ) ;
2005-06-15 18:24:11 +04:00
local_state - > cwd = old_dir ;
2004-08-10 18:27:17 +04:00
return ;
}
/* FILE */
fstrcpy ( filename , local_state - > cwd ) ;
fstrcat ( filename , " \\ " ) ;
fstrcat ( filename , f - > name ) ;
DEBUG ( 3 , ( " got file: %s \n " , filename ) ) ;
2005-06-24 03:23:16 +04:00
switch ( net_mode_share )
2005-06-13 01:18:16 +04:00
{
case NET_MODE_SHARE_MIGRATE :
2008-05-10 01:22:12 +04:00
nt_status = net_copy_file ( c , local_state - > mem_ctx ,
2008-05-08 13:23:38 +04:00
local_state - > cli_share_src ,
local_state - > cli_share_dst ,
filename , filename ,
2008-05-10 01:22:12 +04:00
c - > opt_acls ? true : false ,
c - > opt_attrs ? true : false ,
c - > opt_timestamps ? true : false ,
true ) ;
2005-06-13 01:18:16 +04:00
break ;
default :
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Unsupported file mode %d \n " ) ,
net_mode_share ) ;
2005-06-13 01:18:16 +04:00
return ;
}
2004-08-10 18:27:17 +04:00
2008-05-08 13:23:38 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) )
2009-08-04 10:28:50 +04:00
printf ( _ ( " could not handle file %s: %s \n " ) ,
2004-08-10 18:27:17 +04:00
filename , nt_errstr ( nt_status ) ) ;
}
/**
2008-05-08 13:23:38 +04:00
* sync files , can be called recursivly to list files
* and then call copy_fn for each file
2004-08-10 18:27:17 +04:00
*
2005-06-13 01:18:16 +04:00
* @ param cp_clistate pointer to the copy_clistate we work with
2004-08-10 18:27:17 +04:00
* @ param mask the current search mask
*
* @ return Boolean result
* */
2009-07-05 11:21:07 +04:00
static bool sync_files ( struct copy_clistate * cp_clistate , const char * mask )
2004-08-10 18:27:17 +04:00
{
2007-03-09 02:54:57 +03:00
struct cli_state * targetcli ;
2007-11-30 04:25:41 +03:00
char * targetpath = NULL ;
2010-08-02 21:22:22 +04:00
NTSTATUS status ;
2004-08-10 18:27:17 +04:00
DEBUG ( 3 , ( " calling cli_list with mask: %s \n " , mask ) ) ;
2009-07-05 11:21:07 +04:00
if ( ! cli_resolve_path ( talloc_tos ( ) , " " , NULL , cp_clistate - > cli_share_src ,
mask , & targetcli , & targetpath ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " cli_resolve_path %s failed with error: "
" %s \n " ) ,
2005-06-13 01:18:16 +04:00
mask , cli_errstr ( cp_clistate - > cli_share_src ) ) ;
2008-05-12 13:53:23 +04:00
return false ;
2004-08-10 18:27:17 +04:00
}
2010-08-02 21:22:22 +04:00
status = cli_list ( targetcli , targetpath , cp_clistate - > attribute ,
copy_fn , cp_clistate ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " listing %s failed with error: %s \n " ) ,
2010-08-02 21:22:22 +04:00
mask , nt_errstr ( status ) ) ;
2008-05-12 13:53:23 +04:00
return false ;
2007-03-09 02:54:57 +03:00
}
2008-05-12 13:53:23 +04:00
return true ;
2004-08-10 18:27:17 +04:00
}
2005-06-15 18:24:11 +04:00
/**
* Set the top level directory permissions before we do any further copies .
* Should set up ACL inheritance .
* */
2008-05-10 01:22:12 +04:00
bool copy_top_level_perms ( struct net_context * c ,
struct copy_clistate * cp_clistate ,
2005-06-15 18:24:11 +04:00
const char * sharename )
{
2005-09-30 21:13:37 +04:00
NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL ;
2005-06-15 18:24:11 +04:00
2005-06-24 03:23:16 +04:00
switch ( net_mode_share ) {
2005-06-15 18:24:11 +04:00
case NET_MODE_SHARE_MIGRATE :
DEBUG ( 3 , ( " calling net_copy_fileattr for '.' directory in share %s \n " , sharename ) ) ;
2008-05-10 01:22:12 +04:00
nt_status = net_copy_fileattr ( c ,
cp_clistate - > mem_ctx ,
2008-05-08 13:23:38 +04:00
cp_clistate - > cli_share_src ,
2005-06-15 18:24:11 +04:00
cp_clistate - > cli_share_dst ,
" \\ " , " \\ " ,
2008-05-10 01:22:12 +04:00
c - > opt_acls ? true : false ,
c - > opt_attrs ? true : false ,
c - > opt_timestamps ? true : false ,
false ) ;
2005-06-15 18:24:11 +04:00
break ;
default :
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Unsupported mode %d \n " ) , net_mode_share ) ;
2005-06-15 18:24:11 +04:00
break ;
}
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2009-08-04 10:28:50 +04:00
printf ( _ ( " Could handle directory attributes for top level "
" directory of share %s. Error %s \n " ) ,
2005-06-15 18:24:11 +04:00
sharename , nt_errstr ( nt_status ) ) ;
2008-05-12 13:53:23 +04:00
return false ;
2005-06-15 18:24:11 +04:00
}
2008-05-12 13:53:23 +04:00
return true ;
2005-06-15 18:24:11 +04:00
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Sync all files inside a remote share to another share ( over smb ) .
2004-08-10 18:27:17 +04:00
*
* All parameters are provided by the run_rpc_command function , except for
2008-06-12 12:55:55 +04:00
* argc , argv which are passed through .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param domain_sid The domain sid acquired from the remote server .
2004-08-10 18:27:17 +04:00
* @ param cli A cli_state connected to the server .
2008-06-12 12:55:55 +04:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-08-10 18:27:17 +04:00
*
* @ return Normal NTSTATUS return .
* */
2005-09-30 21:13:37 +04:00
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_share_migrate_files_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
2005-09-30 21:13:37 +04:00
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2004-08-10 18:27:17 +04:00
{
2007-10-11 00:34:30 +04:00
WERROR result ;
2004-08-10 18:27:17 +04:00
NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL ;
2008-03-10 18:19:25 +03:00
struct srvsvc_NetShareInfoCtr ctr_src ;
2005-06-16 13:36:53 +04:00
uint32 i ;
uint32 level = 502 ;
2005-06-13 01:18:16 +04:00
struct copy_clistate cp_clistate ;
2008-05-12 13:53:23 +04:00
bool got_src_share = false ;
bool got_dst_share = false ;
2007-12-05 03:35:24 +03:00
const char * mask = " \\ * " ;
2004-08-27 01:37:20 +04:00
char * dst = NULL ;
2008-05-10 01:22:12 +04:00
dst = SMB_STRDUP ( c - > opt_destination ? c - > opt_destination : " 127.0.0.1 " ) ;
2008-05-28 00:56:55 +04:00
if ( dst = = NULL ) {
nt_status = NT_STATUS_NO_MEMORY ;
goto done ;
}
2004-08-10 18:27:17 +04:00
2008-05-10 01:22:12 +04:00
result = get_share_info ( c , pipe_hnd , mem_ctx , level , argc , argv ,
& ctr_src ) ;
2004-08-10 18:27:17 +04:00
2007-10-11 00:34:30 +04:00
if ( ! W_ERROR_IS_OK ( result ) )
2004-08-10 18:27:17 +04:00
goto done ;
2008-03-10 18:19:25 +03:00
for ( i = 0 ; i < ctr_src . ctr . ctr502 - > count ; i + + ) {
2007-10-11 00:34:30 +04:00
2008-03-10 18:19:25 +03:00
struct srvsvc_NetShareInfo502 info502 =
ctr_src . ctr . ctr502 - > array [ i ] ;
2007-10-11 00:34:30 +04:00
2008-05-10 01:22:12 +04:00
if ( ! check_share_sanity ( c , cli , info502 . name , info502 . type ) )
2004-08-10 18:27:17 +04:00
continue ;
2005-06-16 13:36:53 +04:00
/* one might not want to mirror whole discs :) */
2008-03-10 18:19:25 +03:00
if ( strequal ( info502 . name , " print$ " ) | | info502 . name [ 1 ] = = ' $ ' ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " skipping [%s]: builtin/hidden share \n " ) ,
info502 . name ) ;
2004-08-10 18:27:17 +04:00
continue ;
}
2005-06-24 03:23:16 +04:00
switch ( net_mode_share )
2005-06-13 01:18:16 +04:00
{
case NET_MODE_SHARE_MIGRATE :
printf ( " syncing " ) ;
break ;
default :
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Unsupported mode %d \n " ) ,
net_mode_share ) ;
2005-06-13 01:18:16 +04:00
break ;
}
2009-08-04 10:28:50 +04:00
printf ( _ ( " [%s] files and directories %s ACLs, %s DOS "
" Attributes %s \n " ) ,
2008-03-10 18:19:25 +03:00
info502 . name ,
2009-08-04 10:28:50 +04:00
c - > opt_acls ? _ ( " including " ) : _ ( " without " ) ,
c - > opt_attrs ? _ ( " including " ) : _ ( " without " ) ,
c - > opt_timestamps ? _ ( " (preserving timestamps) " ) : " " ) ;
2004-08-10 18:27:17 +04:00
2005-06-13 01:18:16 +04:00
cp_clistate . mem_ctx = mem_ctx ;
cp_clistate . cli_share_src = NULL ;
cp_clistate . cli_share_dst = NULL ;
cp_clistate . cwd = NULL ;
cp_clistate . attribute = aSYSTEM | aHIDDEN | aDIR ;
2008-05-10 01:22:12 +04:00
cp_clistate . c = c ;
2004-08-10 18:27:17 +04:00
/* open share source */
2008-05-10 01:22:12 +04:00
nt_status = connect_to_service ( c , & cp_clistate . cli_share_src ,
2007-10-25 01:16:54 +04:00
& cli - > dest_ss , cli - > desthost ,
2008-03-10 18:19:25 +03:00
info502 . name , " A: " ) ;
2004-08-10 18:27:17 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) )
goto done ;
2008-05-12 13:53:23 +04:00
got_src_share = true ;
2004-08-10 18:27:17 +04:00
2005-06-24 03:23:16 +04:00
if ( net_mode_share = = NET_MODE_SHARE_MIGRATE ) {
2005-06-13 01:18:16 +04:00
/* open share destination */
2008-05-10 01:22:12 +04:00
nt_status = connect_to_service ( c , & cp_clistate . cli_share_dst ,
2008-03-10 18:19:25 +03:00
NULL , dst , info502 . name , " A: " ) ;
2005-06-13 01:18:16 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) )
goto done ;
2004-08-10 18:27:17 +04:00
2008-05-12 13:53:23 +04:00
got_dst_share = true ;
2005-06-13 01:18:16 +04:00
}
2004-08-10 18:27:17 +04:00
2008-05-10 01:22:12 +04:00
if ( ! copy_top_level_perms ( c , & cp_clistate , info502 . name ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " Could not handle the top level "
" directory permissions for the "
" share: %s \n " ) , info502 . name ) ;
2005-06-15 18:24:11 +04:00
nt_status = NT_STATUS_UNSUCCESSFUL ;
goto done ;
}
2004-08-10 18:27:17 +04:00
2009-07-05 11:21:07 +04:00
if ( ! sync_files ( & cp_clistate , mask ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " could not handle files for share: "
" %s \n " ) , info502 . name ) ;
2004-08-10 18:27:17 +04:00
nt_status = NT_STATUS_UNSUCCESSFUL ;
goto done ;
}
}
nt_status = NT_STATUS_OK ;
done :
if ( got_src_share )
2005-06-13 01:18:16 +04:00
cli_shutdown ( cp_clistate . cli_share_src ) ;
2004-08-10 18:27:17 +04:00
if ( got_dst_share )
2005-06-13 01:18:16 +04:00
cli_shutdown ( cp_clistate . cli_share_dst ) ;
2008-05-28 00:56:55 +04:00
SAFE_FREE ( dst ) ;
2004-08-10 18:27:17 +04:00
return nt_status ;
}
2008-05-10 01:22:12 +04:00
static int rpc_share_migrate_files ( struct net_context * c , int argc , const char * * argv )
2004-08-10 18:27:17 +04:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net share migrate files \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Migrate files to local server " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2004-08-21 00:13:05 +04:00
2008-05-10 01:22:12 +04:00
if ( ! c - > opt_host ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " no server to migrate \n " ) ) ;
2004-08-21 00:13:05 +04:00
return - 1 ;
}
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_srvsvc . syntax_id , 0 ,
2004-08-10 18:27:17 +04:00
rpc_share_migrate_files_internals ,
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Migrate share - ACLs from a remote RPC server to the local RPC server .
2005-06-16 13:36:53 +04:00
*
* All parameters are provided by the run_rpc_command function , except for
2008-06-12 12:55:55 +04:00
* argc , argv which are passed through .
2005-06-16 13:36:53 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param domain_sid The domain sid acquired from the remote server .
2005-06-16 13:36:53 +04:00
* @ param cli A cli_state connected to the server .
2008-06-12 12:55:55 +04:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2005-06-16 13:36:53 +04:00
*
* @ return Normal NTSTATUS return .
* */
2005-09-30 21:13:37 +04:00
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_share_migrate_security_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
2005-09-30 21:13:37 +04:00
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
2008-05-08 13:23:38 +04:00
TALLOC_CTX * mem_ctx ,
2005-09-30 21:13:37 +04:00
int argc ,
const char * * argv )
2005-06-16 13:36:53 +04:00
{
2007-10-11 00:34:30 +04:00
WERROR result ;
2005-06-16 13:36:53 +04:00
NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL ;
2008-03-10 18:19:25 +03:00
struct srvsvc_NetShareInfoCtr ctr_src ;
union srvsvc_NetShareInfo info ;
2005-06-16 13:36:53 +04:00
uint32 i ;
2005-09-30 21:13:37 +04:00
struct rpc_pipe_client * srvsvc_pipe = NULL ;
2005-06-16 13:36:53 +04:00
struct cli_state * cli_dst = NULL ;
uint32 level = 502 ; /* includes secdesc */
2008-03-10 18:19:25 +03:00
uint32_t parm_error = 0 ;
2005-06-16 13:36:53 +04:00
2008-05-10 01:22:12 +04:00
result = get_share_info ( c , pipe_hnd , mem_ctx , level , argc , argv ,
& ctr_src ) ;
2005-06-16 13:36:53 +04:00
2007-10-11 00:34:30 +04:00
if ( ! W_ERROR_IS_OK ( result ) )
2005-06-16 13:36:53 +04:00
goto done ;
/* connect destination PI_SRVSVC */
2008-07-20 20:44:32 +04:00
nt_status = connect_dst_pipe ( c , & cli_dst , & srvsvc_pipe ,
& ndr_table_srvsvc . syntax_id ) ;
2005-06-16 13:36:53 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) )
return nt_status ;
2008-03-10 18:19:25 +03:00
for ( i = 0 ; i < ctr_src . ctr . ctr502 - > count ; i + + ) {
struct srvsvc_NetShareInfo502 info502 =
ctr_src . ctr . ctr502 - > array [ i ] ;
2007-10-11 00:34:30 +04:00
2005-06-16 13:36:53 +04:00
/* reset error-code */
nt_status = NT_STATUS_UNSUCCESSFUL ;
2008-05-10 01:22:12 +04:00
if ( ! check_share_sanity ( c , cli , info502 . name , info502 . type ) )
2005-06-16 13:36:53 +04:00
continue ;
2009-08-04 10:28:50 +04:00
printf ( _ ( " migrating: [%s], path: %s, comment: %s, including "
" share-ACLs \n " ) ,
2008-03-10 18:19:25 +03:00
info502 . name , info502 . path , info502 . comment ) ;
2005-06-16 13:36:53 +04:00
2008-05-10 01:22:12 +04:00
if ( c - > opt_verbose )
2008-04-01 02:11:55 +04:00
display_sec_desc ( info502 . sd_buf . sd ) ;
2007-10-11 00:34:30 +04:00
/* FIXME: shouldn't we be able to just set the security descriptor ? */
2008-03-10 18:19:25 +03:00
info . info502 = & info502 ;
2007-10-11 00:34:30 +04:00
2005-06-16 13:36:53 +04:00
/* finally modify the share on the dst server */
2008-03-10 18:19:25 +03:00
nt_status = rpccli_srvsvc_NetShareSetInfo ( srvsvc_pipe , mem_ctx ,
2008-04-19 23:56:43 +04:00
srvsvc_pipe - > desthost ,
2008-03-10 18:19:25 +03:00
info502 . name ,
level ,
& info ,
& parm_error ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) | | ! W_ERROR_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
printf ( _ ( " cannot set share-acl: %s \n " ) ,
win_errstr ( result ) ) ;
2005-06-16 13:36:53 +04:00
goto done ;
}
}
nt_status = NT_STATUS_OK ;
done :
2005-09-30 21:13:37 +04:00
if ( cli_dst ) {
2005-06-16 13:36:53 +04:00
cli_shutdown ( cli_dst ) ;
}
return nt_status ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Migrate share - acls from a RPC server to another .
2005-06-16 13:36:53 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2005-06-16 13:36:53 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2005-06-16 13:36:53 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_share_migrate_security ( struct net_context * c , int argc ,
const char * * argv )
2005-06-16 13:36:53 +04:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc share migrate security \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Migrate share-acls to local server " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2005-06-16 13:36:53 +04:00
2008-05-10 01:22:12 +04:00
if ( ! c - > opt_host ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " no server to migrate \n " ) ) ;
2005-06-16 13:36:53 +04:00
return - 1 ;
}
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_srvsvc . syntax_id , 0 ,
2005-06-16 13:36:53 +04:00
rpc_share_migrate_security_internals ,
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2004-08-21 00:13:05 +04:00
* Migrate shares ( including share - definitions , share - acls and files with acls / attrs )
2008-06-12 12:55:55 +04:00
* from one server to another .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-08-10 18:27:17 +04:00
*
* */
2008-05-10 01:22:12 +04:00
static int rpc_share_migrate_all ( struct net_context * c , int argc ,
const char * * argv )
2004-08-10 18:27:17 +04:00
{
int ret ;
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc share migrate all \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Migrates shares including all share settings " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2008-05-10 01:22:12 +04:00
if ( ! c - > opt_host ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " no server to migrate \n " ) ) ;
2004-08-21 00:13:05 +04:00
return - 1 ;
}
2005-06-16 13:36:53 +04:00
/* order is important. we don't want to be locked out by the share-acl
* before copying files - gd */
2008-05-08 13:23:38 +04:00
2009-11-08 21:37:26 +03:00
ret = run_rpc_command ( c , NULL , & ndr_table_srvsvc . syntax_id , 0 ,
2008-05-10 01:22:12 +04:00
rpc_share_migrate_shares_internals , argc , argv ) ;
2004-08-10 18:27:17 +04:00
if ( ret )
return ret ;
2005-06-16 13:36:53 +04:00
2009-11-08 21:37:26 +03:00
ret = run_rpc_command ( c , NULL , & ndr_table_srvsvc . syntax_id , 0 ,
2008-05-10 01:22:12 +04:00
rpc_share_migrate_files_internals , argc , argv ) ;
2004-08-10 18:27:17 +04:00
if ( ret )
return ret ;
2008-05-08 13:23:38 +04:00
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_srvsvc . syntax_id , 0 ,
2008-05-10 01:22:12 +04:00
rpc_share_migrate_security_internals , argc ,
argv ) ;
2004-08-10 18:27:17 +04:00
}
2008-05-08 13:23:38 +04:00
/**
2004-08-10 18:27:17 +04:00
* ' net rpc share migrate ' entrypoint .
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-08-10 18:27:17 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_share_migrate ( struct net_context * c , int argc , const char * * argv )
2004-08-10 18:27:17 +04:00
{
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 12:27:59 +04:00
{
" all " ,
rpc_share_migrate_all ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Migrate shares from remote to local server " ) ,
N_ ( " net rpc share migrate all \n "
" Migrate shares from remote to local server " )
2008-05-21 12:27:59 +04:00
} ,
{
" files " ,
rpc_share_migrate_files ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Migrate files from remote to local server " ) ,
N_ ( " net rpc share migrate files \n "
" Migrate files from remote to local server " )
2008-05-21 12:27:59 +04:00
} ,
{
" security " ,
rpc_share_migrate_security ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Migrate share-ACLs from remote to local server " ) ,
N_ ( " net rpc share migrate security \n "
" Migrate share-ACLs from remote to local server " )
2008-05-21 12:27:59 +04:00
} ,
{
" shares " ,
rpc_share_migrate_shares ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Migrate shares from remote to local server " ) ,
N_ ( " net rpc share migrate shares \n "
" Migrate shares from remote to local server " )
2008-05-21 12:27:59 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2004-08-10 18:27:17 +04:00
} ;
2005-06-24 03:23:16 +04:00
net_mode_share = NET_MODE_SHARE_MIGRATE ;
2005-06-13 01:18:16 +04:00
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rpc share migrate " , func ) ;
2004-08-10 18:27:17 +04:00
}
2004-10-12 15:58:01 +04:00
struct full_alias {
2010-05-21 05:25:01 +04:00
struct dom_sid sid ;
2005-06-16 13:36:53 +04:00
uint32 num_members ;
2010-05-21 05:25:01 +04:00
struct dom_sid * members ;
2004-10-12 15:58:01 +04:00
} ;
static int num_server_aliases ;
static struct full_alias * server_aliases ;
/*
* Add an alias to the static list .
*/
static void push_alias ( TALLOC_CTX * mem_ctx , struct full_alias * alias )
{
if ( server_aliases = = NULL )
2004-12-07 21:25:53 +03:00
server_aliases = SMB_MALLOC_ARRAY ( struct full_alias , 100 ) ;
2004-10-12 15:58:01 +04:00
server_aliases [ num_server_aliases ] = * alias ;
num_server_aliases + = 1 ;
}
/*
* For a specific domain on the server , fetch all the aliases
* and their members . Add all of them to the server_aliases .
*/
2005-09-30 21:13:37 +04:00
static NTSTATUS rpc_fetch_domain_aliases ( struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
2009-03-19 00:49:41 +03:00
struct policy_handle * connect_pol ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid )
2004-10-12 15:58:01 +04:00
{
uint32 start_idx , max_entries , num_entries , i ;
2008-02-12 13:09:23 +03:00
struct samr_SamArray * groups = NULL ;
2004-10-12 15:58:01 +04:00
NTSTATUS result ;
2009-03-19 00:49:41 +03:00
struct policy_handle domain_pol ;
2004-10-12 15:58:01 +04:00
/* Get domain policy handle */
2008-02-01 13:12:05 +03:00
result = rpccli_samr_OpenDomain ( pipe_hnd , mem_ctx ,
connect_pol ,
MAXIMUM_ALLOWED_ACCESS ,
CONST_DISCARD ( struct dom_sid2 * , domain_sid ) ,
& domain_pol ) ;
2004-10-12 15:58:01 +04:00
if ( ! NT_STATUS_IS_OK ( result ) )
return result ;
start_idx = 0 ;
max_entries = 250 ;
do {
2008-02-12 13:09:23 +03:00
result = rpccli_samr_EnumDomainAliases ( pipe_hnd , mem_ctx ,
& domain_pol ,
& start_idx ,
& groups ,
max_entries ,
& num_entries ) ;
2004-10-12 15:58:01 +04:00
for ( i = 0 ; i < num_entries ; i + + ) {
2009-03-19 00:49:41 +03:00
struct policy_handle alias_pol ;
2004-10-12 15:58:01 +04:00
struct full_alias alias ;
2008-02-05 03:18:56 +03:00
struct lsa_SidArray sid_array ;
2004-10-12 15:58:01 +04:00
int j ;
2008-02-01 13:38:29 +03:00
result = rpccli_samr_OpenAlias ( pipe_hnd , mem_ctx ,
& domain_pol ,
MAXIMUM_ALLOWED_ACCESS ,
2008-02-12 13:09:23 +03:00
groups - > entries [ i ] . idx ,
2008-02-01 13:38:29 +03:00
& alias_pol ) ;
2004-10-12 15:58:01 +04:00
if ( ! NT_STATUS_IS_OK ( result ) )
goto done ;
2008-02-05 03:18:56 +03:00
result = rpccli_samr_GetMembersInAlias ( pipe_hnd , mem_ctx ,
& alias_pol ,
& sid_array ) ;
2004-10-12 15:58:01 +04:00
if ( ! NT_STATUS_IS_OK ( result ) )
goto done ;
2008-02-05 03:18:56 +03:00
alias . num_members = sid_array . num_sids ;
2008-01-30 14:39:20 +03:00
result = rpccli_samr_Close ( pipe_hnd , mem_ctx , & alias_pol ) ;
2004-10-12 15:58:01 +04:00
if ( ! NT_STATUS_IS_OK ( result ) )
goto done ;
alias . members = NULL ;
if ( alias . num_members > 0 ) {
2010-05-21 05:25:01 +04:00
alias . members = SMB_MALLOC_ARRAY ( struct dom_sid , alias . num_members ) ;
2004-10-12 15:58:01 +04:00
for ( j = 0 ; j < alias . num_members ; j + + )
sid_copy ( & alias . members [ j ] ,
2008-02-05 03:18:56 +03:00
sid_array . sids [ j ] . sid ) ;
2004-10-12 15:58:01 +04:00
}
2010-01-10 19:39:27 +03:00
sid_compose ( & alias . sid , domain_sid ,
groups - > entries [ i ] . idx ) ;
2004-10-12 15:58:01 +04:00
push_alias ( mem_ctx , & alias ) ;
}
} while ( NT_STATUS_EQUAL ( result , STATUS_MORE_ENTRIES ) ) ;
result = NT_STATUS_OK ;
done :
2008-01-30 14:39:20 +03:00
rpccli_samr_Close ( pipe_hnd , mem_ctx , & domain_pol ) ;
2004-10-12 15:58:01 +04:00
return result ;
}
/*
* Dump server_aliases as names for debugging purposes .
*/
2005-09-30 21:13:37 +04:00
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_aliaslist_dump ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2005-09-30 21:13:37 +04:00
const char * domain_name ,
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
2008-05-08 13:23:38 +04:00
TALLOC_CTX * mem_ctx ,
2005-09-30 21:13:37 +04:00
int argc ,
const char * * argv )
2004-10-12 15:58:01 +04:00
{
int i ;
NTSTATUS result ;
2009-03-19 00:49:41 +03:00
struct policy_handle lsa_pol ;
2004-10-12 15:58:01 +04:00
2008-05-12 13:53:23 +04:00
result = rpccli_lsa_open_policy ( pipe_hnd , mem_ctx , true ,
2009-04-15 03:12:13 +04:00
SEC_FLAG_MAXIMUM_ALLOWED ,
2004-10-12 15:58:01 +04:00
& lsa_pol ) ;
if ( ! NT_STATUS_IS_OK ( result ) )
return result ;
for ( i = 0 ; i < num_server_aliases ; i + + ) {
char * * names ;
char * * domains ;
2006-09-08 18:28:06 +04:00
enum lsa_SidType * types ;
2004-10-12 15:58:01 +04:00
int j ;
struct full_alias * alias = & server_aliases [ i ] ;
2005-09-30 21:13:37 +04:00
result = rpccli_lsa_lookup_sids ( pipe_hnd , mem_ctx , & lsa_pol , 1 ,
2004-10-12 15:58:01 +04:00
& alias - > sid ,
& domains , & names , & types ) ;
if ( ! NT_STATUS_IS_OK ( result ) )
continue ;
DEBUG ( 1 , ( " %s \\ %s %d: " , domains [ 0 ] , names [ 0 ] , types [ 0 ] ) ) ;
if ( alias - > num_members = = 0 ) {
DEBUG ( 1 , ( " \n " ) ) ;
continue ;
}
2005-09-30 21:13:37 +04:00
result = rpccli_lsa_lookup_sids ( pipe_hnd , mem_ctx , & lsa_pol ,
2004-10-12 15:58:01 +04:00
alias - > num_members ,
alias - > members ,
& domains , & names , & types ) ;
if ( ! NT_STATUS_IS_OK ( result ) & &
! NT_STATUS_EQUAL ( result , STATUS_SOME_UNMAPPED ) )
continue ;
for ( j = 0 ; j < alias - > num_members ; j + + )
DEBUG ( 1 , ( " %s \\ %s (%d); " ,
domains [ j ] ? domains [ j ] : " *unknown* " ,
names [ j ] ? names [ j ] : " *unknown* " , types [ j ] ) ) ;
DEBUG ( 1 , ( " \n " ) ) ;
}
2006-09-21 02:49:02 +04:00
rpccli_lsa_Close ( pipe_hnd , mem_ctx , & lsa_pol ) ;
2004-10-12 15:58:01 +04:00
return NT_STATUS_OK ;
}
/*
* Fetch a list of all server aliases and their members into
* server_aliases .
*/
2005-09-30 21:13:37 +04:00
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_aliaslist_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2005-09-30 21:13:37 +04:00
const char * domain_name ,
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
2008-05-08 13:23:38 +04:00
TALLOC_CTX * mem_ctx ,
2005-09-30 21:13:37 +04:00
int argc ,
const char * * argv )
2004-10-12 15:58:01 +04:00
{
NTSTATUS result ;
2009-03-19 00:49:41 +03:00
struct policy_handle connect_pol ;
2004-10-12 15:58:01 +04:00
2008-02-04 21:43:07 +03:00
result = rpccli_samr_Connect2 ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2008-02-04 21:43:07 +03:00
MAXIMUM_ALLOWED_ACCESS ,
& connect_pol ) ;
2004-10-12 15:58:01 +04:00
if ( ! NT_STATUS_IS_OK ( result ) )
goto done ;
2008-05-08 13:23:38 +04:00
2005-09-30 21:13:37 +04:00
result = rpc_fetch_domain_aliases ( pipe_hnd , mem_ctx , & connect_pol ,
2004-10-12 15:58:01 +04:00
& global_sid_Builtin ) ;
if ( ! NT_STATUS_IS_OK ( result ) )
goto done ;
2008-05-08 13:23:38 +04:00
2005-09-30 21:13:37 +04:00
result = rpc_fetch_domain_aliases ( pipe_hnd , mem_ctx , & connect_pol ,
2004-10-12 15:58:01 +04:00
domain_sid ) ;
2008-01-30 14:39:20 +03:00
rpccli_samr_Close ( pipe_hnd , mem_ctx , & connect_pol ) ;
2004-10-12 15:58:01 +04:00
done :
return result ;
}
2010-05-21 05:25:01 +04:00
static void init_user_token ( NT_USER_TOKEN * token , struct dom_sid * user_sid )
2004-10-12 15:58:01 +04:00
{
token - > num_sids = 4 ;
2010-08-31 03:32:52 +04:00
if ( ! ( token - > sids = SMB_MALLOC_ARRAY ( struct dom_sid , 4 ) ) ) {
2010-01-19 13:43:54 +03:00
d_fprintf ( stderr , " malloc %s \n " , _ ( " failed " ) ) ;
2007-07-09 12:00:50 +04:00
token - > num_sids = 0 ;
return ;
}
2004-10-12 15:58:01 +04:00
2010-08-31 03:32:52 +04:00
token - > sids [ 0 ] = * user_sid ;
sid_copy ( & token - > sids [ 1 ] , & global_sid_World ) ;
sid_copy ( & token - > sids [ 2 ] , & global_sid_Network ) ;
sid_copy ( & token - > sids [ 3 ] , & global_sid_Authenticated_Users ) ;
2004-10-12 15:58:01 +04:00
}
static void free_user_token ( NT_USER_TOKEN * token )
{
2010-08-31 03:32:52 +04:00
SAFE_FREE ( token - > sids ) ;
2004-10-12 15:58:01 +04:00
}
2010-05-21 05:25:01 +04:00
static void add_sid_to_token ( NT_USER_TOKEN * token , struct dom_sid * sid )
2004-10-12 15:58:01 +04:00
{
if ( is_sid_in_token ( token , sid ) )
return ;
2010-08-31 03:32:52 +04:00
token - > sids = SMB_REALLOC_ARRAY ( token - > sids , struct dom_sid , token - > num_sids + 1 ) ;
if ( ! token - > sids ) {
r13915: Fixed a very interesting class of realloc() bugs found by Coverity.
realloc can return NULL in one of two cases - (1) the realloc failed,
(2) realloc succeeded but the new size requested was zero, in which
case this is identical to a free() call.
The error paths dealing with these two cases should be different,
but mostly weren't. Secondly the standard idiom for dealing with
realloc when you know the new size is non-zero is the following :
tmp = realloc(p, size);
if (!tmp) {
SAFE_FREE(p);
return error;
} else {
p = tmp;
}
However, there were *many* *many* places in Samba where we were
using the old (broken) idiom of :
p = realloc(p, size)
if (!p) {
return error;
}
which will leak the memory pointed to by p on realloc fail.
This commit (hopefully) fixes all these cases by moving to
a standard idiom of :
p = SMB_REALLOC(p, size)
if (!p) {
return error;
}
Where if the realloc returns null due to the realloc failing
or size == 0 we *guarentee* that the storage pointed to by p
has been freed. This allows me to remove a lot of code that
was dealing with the standard (more verbose) method that required
a tmp pointer. This is almost always what you want. When a
realloc fails you never usually want the old memory, you
want to free it and get into your error processing asap.
For the 11 remaining cases where we really do need to keep the
old pointer I have invented the new macro SMB_REALLOC_KEEP_OLD_ON_ERROR,
which can be used as follows :
tmp = SMB_REALLOC_KEEP_OLD_ON_ERROR(p, size);
if (!tmp) {
SAFE_FREE(p);
return error;
} else {
p = tmp;
}
SMB_REALLOC_KEEP_OLD_ON_ERROR guarentees never to free the
pointer p, even on size == 0 or realloc fail. All this is
done by a hidden extra argument to Realloc(), BOOL free_old_on_error
which is set appropriately by the SMB_REALLOC and SMB_REALLOC_KEEP_OLD_ON_ERROR
macros (and their array counterparts).
It remains to be seen what this will do to our Coverity bug count :-).
Jeremy.
(This used to be commit 1d710d06a214f3f1740e80e0bffd6aab44aac2b0)
2006-03-07 09:31:04 +03:00
return ;
}
2004-10-12 15:58:01 +04:00
2010-08-31 03:32:52 +04:00
sid_copy ( & token - > sids [ token - > num_sids ] , sid ) ;
2004-10-12 15:58:01 +04:00
token - > num_sids + = 1 ;
}
struct user_token {
fstring name ;
NT_USER_TOKEN token ;
} ;
static void dump_user_token ( struct user_token * token )
{
int i ;
d_printf ( " %s \n " , token - > name ) ;
for ( i = 0 ; i < token - > token . num_sids ; i + + ) {
2010-08-31 03:32:52 +04:00
d_printf ( " %s \n " , sid_string_tos ( & token - > token . sids [ i ] ) ) ;
2004-10-12 15:58:01 +04:00
}
}
2010-05-21 05:25:01 +04:00
static bool is_alias_member ( struct dom_sid * sid , struct full_alias * alias )
2004-10-12 15:58:01 +04:00
{
int i ;
for ( i = 0 ; i < alias - > num_members ; i + + ) {
if ( sid_compare ( sid , & alias - > members [ i ] ) = = 0 )
2008-05-12 13:53:23 +04:00
return true ;
2004-10-12 15:58:01 +04:00
}
2008-05-12 13:53:23 +04:00
return false ;
2004-10-12 15:58:01 +04:00
}
2010-05-21 05:25:01 +04:00
static void collect_sid_memberships ( NT_USER_TOKEN * token , struct dom_sid sid )
2004-10-12 15:58:01 +04:00
{
int i ;
for ( i = 0 ; i < num_server_aliases ; i + + ) {
if ( is_alias_member ( & sid , & server_aliases [ i ] ) )
add_sid_to_token ( token , & server_aliases [ i ] . sid ) ;
}
}
/*
* We got a user token with all the SIDs we can know about without asking the
* server directly . These are the user and domain group sids . All of these can
* be members of aliases . So scan the list of aliases for each of the SIDs and
* add them to the token .
*/
static void collect_alias_memberships ( NT_USER_TOKEN * token )
{
int num_global_sids = token - > num_sids ;
int i ;
for ( i = 0 ; i < num_global_sids ; i + + ) {
2010-08-31 03:32:52 +04:00
collect_sid_memberships ( token , token - > sids [ i ] ) ;
2004-10-12 15:58:01 +04:00
}
}
2007-10-19 04:40:25 +04:00
static bool get_user_sids ( const char * domain , const char * user , NT_USER_TOKEN * token )
2004-10-12 15:58:01 +04:00
{
2008-04-02 10:03:11 +04:00
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE ;
enum wbcSidType type ;
2004-10-12 15:58:01 +04:00
fstring full_name ;
2008-04-02 10:03:11 +04:00
struct wbcDomainSid wsid ;
char * sid_str = NULL ;
2010-05-21 05:25:01 +04:00
struct dom_sid user_sid ;
2008-04-02 10:03:11 +04:00
uint32_t num_groups ;
gid_t * groups = NULL ;
uint32_t i ;
2004-10-12 15:58:01 +04:00
fstr_sprintf ( full_name , " %s%c%s " ,
domain , * lp_winbind_separator ( ) , user ) ;
/* First let's find out the user sid */
2008-04-02 10:03:11 +04:00
wbc_status = wbcLookupName ( domain , user , & wsid , & type ) ;
2004-10-12 15:58:01 +04:00
2008-04-02 10:03:11 +04:00
if ( ! WBC_ERROR_IS_OK ( wbc_status ) ) {
DEBUG ( 1 , ( " winbind could not find %s: %s \n " ,
full_name , wbcErrorString ( wbc_status ) ) ) ;
return false ;
}
2004-10-12 15:58:01 +04:00
2008-04-02 10:03:11 +04:00
wbc_status = wbcSidToString ( & wsid , & sid_str ) ;
if ( ! WBC_ERROR_IS_OK ( wbc_status ) ) {
return false ;
2004-10-12 15:58:01 +04:00
}
2008-04-02 10:03:11 +04:00
if ( type ! = SID_NAME_USER ) {
wbcFreeMemory ( sid_str ) ;
2004-10-12 15:58:01 +04:00
DEBUG ( 1 , ( " %s is not a user \n " , full_name ) ) ;
2008-04-02 10:03:11 +04:00
return false ;
2004-10-12 15:58:01 +04:00
}
2009-01-20 02:09:51 +03:00
if ( ! string_to_sid ( & user_sid , sid_str ) ) {
DEBUG ( 1 , ( " Could not convert sid %s from string \n " , sid_str ) ) ;
return false ;
}
2008-04-02 10:03:11 +04:00
wbcFreeMemory ( sid_str ) ;
sid_str = NULL ;
2004-10-12 15:58:01 +04:00
init_user_token ( token , & user_sid ) ;
/* And now the groups winbind knows about */
2008-04-02 10:03:11 +04:00
wbc_status = wbcGetGroups ( full_name , & num_groups , & groups ) ;
if ( ! WBC_ERROR_IS_OK ( wbc_status ) ) {
DEBUG ( 1 , ( " winbind could not get groups of %s: %s \n " ,
full_name , wbcErrorString ( wbc_status ) ) ) ;
return false ;
2004-10-12 15:58:01 +04:00
}
2008-04-02 10:03:11 +04:00
for ( i = 0 ; i < num_groups ; i + + ) {
gid_t gid = groups [ i ] ;
2010-05-21 05:25:01 +04:00
struct dom_sid sid ;
2004-10-12 15:58:01 +04:00
2008-04-02 10:03:11 +04:00
wbc_status = wbcGidToSid ( gid , & wsid ) ;
if ( ! WBC_ERROR_IS_OK ( wbc_status ) ) {
2009-05-12 08:56:57 +04:00
DEBUG ( 1 , ( " winbind could not find SID of gid %u: %s \n " ,
( unsigned int ) gid , wbcErrorString ( wbc_status ) ) ) ;
2008-04-02 10:03:11 +04:00
wbcFreeMemory ( groups ) ;
return false ;
}
2004-10-12 15:58:01 +04:00
2008-04-02 10:03:11 +04:00
wbc_status = wbcSidToString ( & wsid , & sid_str ) ;
if ( ! WBC_ERROR_IS_OK ( wbc_status ) ) {
wbcFreeMemory ( groups ) ;
return false ;
2004-10-12 15:58:01 +04:00
}
2008-04-02 10:03:11 +04:00
DEBUG ( 3 , ( " %s \n " , sid_str ) ) ;
string_to_sid ( & sid , sid_str ) ;
wbcFreeMemory ( sid_str ) ;
sid_str = NULL ;
2004-10-12 15:58:01 +04:00
add_sid_to_token ( token , & sid ) ;
}
2008-04-02 10:03:11 +04:00
wbcFreeMemory ( groups ) ;
2004-10-12 15:58:01 +04:00
2008-04-02 10:03:11 +04:00
return true ;
2004-10-12 15:58:01 +04:00
}
2008-05-08 13:23:38 +04:00
2004-10-12 15:58:01 +04:00
/**
* Get a list of all user tokens we want to look at
* */
2005-09-30 21:13:37 +04:00
2008-05-10 01:22:12 +04:00
static bool get_user_tokens ( struct net_context * c , int * num_tokens ,
struct user_token * * user_tokens )
2004-10-12 15:58:01 +04:00
{
2008-04-02 10:02:02 +04:00
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE ;
uint32_t i , num_users ;
const char * * users ;
2004-10-12 15:58:01 +04:00
struct user_token * result ;
2007-12-08 04:32:32 +03:00
TALLOC_CTX * frame = NULL ;
2004-10-12 15:58:01 +04:00
2005-05-18 15:57:53 +04:00
if ( lp_winbind_use_default_domain ( ) & &
2008-05-10 01:22:12 +04:00
( c - > opt_target_workgroup = = NULL ) ) {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " winbind use default domain = yes set, "
" please specify a workgroup \n " ) ) ;
2008-04-02 10:02:02 +04:00
return false ;
2005-05-18 15:57:53 +04:00
}
2004-10-12 15:58:01 +04:00
/* Send request to winbind daemon */
2008-04-02 10:02:02 +04:00
wbc_status = wbcListUsers ( NULL , & num_users , & users ) ;
if ( ! WBC_ERROR_IS_OK ( wbc_status ) ) {
2009-08-04 10:28:50 +04:00
DEBUG ( 1 , ( _ ( " winbind could not list users: %s \n " ) ,
2008-04-02 10:02:02 +04:00
wbcErrorString ( wbc_status ) ) ) ;
return false ;
2004-10-12 15:58:01 +04:00
}
2008-04-02 10:02:02 +04:00
result = SMB_MALLOC_ARRAY ( struct user_token , num_users ) ;
2004-10-12 15:58:01 +04:00
if ( result = = NULL ) {
DEBUG ( 1 , ( " Could not malloc sid array \n " ) ) ;
2008-04-02 10:02:02 +04:00
wbcFreeMemory ( users ) ;
return false ;
2004-10-12 15:58:01 +04:00
}
2008-04-02 10:02:02 +04:00
frame = talloc_stackframe ( ) ;
for ( i = 0 ; i < num_users ; i + + ) {
2004-10-12 15:58:01 +04:00
fstring domain , user ;
char * p ;
2008-04-02 10:02:02 +04:00
fstrcpy ( result [ i ] . name , users [ i ] ) ;
2004-10-12 15:58:01 +04:00
2008-04-02 10:02:02 +04:00
p = strchr ( users [ i ] , * lp_winbind_separator ( ) ) ;
2004-10-12 15:58:01 +04:00
2008-04-02 10:02:02 +04:00
DEBUG ( 3 , ( " %s \n " , users [ i ] ) ) ;
2004-10-12 15:58:01 +04:00
2005-05-18 15:57:53 +04:00
if ( p = = NULL ) {
2008-05-10 01:22:12 +04:00
fstrcpy ( domain , c - > opt_target_workgroup ) ;
2008-04-02 10:02:02 +04:00
fstrcpy ( user , users [ i ] ) ;
2005-05-18 15:57:53 +04:00
} else {
* p + + = ' \0 ' ;
2008-04-02 10:02:02 +04:00
fstrcpy ( domain , users [ i ] ) ;
2005-05-18 15:57:53 +04:00
strupper_m ( domain ) ;
fstrcpy ( user , p ) ;
}
2004-10-12 15:58:01 +04:00
get_user_sids ( domain , user , & ( result [ i ] . token ) ) ;
i + = 1 ;
}
2007-12-08 04:32:32 +03:00
TALLOC_FREE ( frame ) ;
2008-04-02 10:02:02 +04:00
wbcFreeMemory ( users ) ;
2004-10-12 15:58:01 +04:00
2008-04-02 10:02:02 +04:00
* num_tokens = num_users ;
2004-10-12 15:58:01 +04:00
* user_tokens = result ;
2008-04-02 10:02:02 +04:00
return true ;
2004-10-12 15:58:01 +04:00
}
2007-10-19 04:40:25 +04:00
static bool get_user_tokens_from_file ( FILE * f ,
2004-10-12 15:58:01 +04:00
int * num_tokens ,
struct user_token * * tokens )
{
struct user_token * token = NULL ;
while ( ! feof ( f ) ) {
fstring line ;
if ( fgets ( line , sizeof ( line ) - 1 , f ) = = NULL ) {
2008-05-12 13:53:23 +04:00
return true ;
2004-10-12 15:58:01 +04:00
}
2009-11-30 23:48:33 +03:00
if ( ( strlen ( line ) > 0 ) & & ( line [ strlen ( line ) - 1 ] = = ' \n ' ) ) {
2004-10-12 15:58:01 +04:00
line [ strlen ( line ) - 1 ] = ' \0 ' ;
2009-11-30 23:48:33 +03:00
}
2004-10-12 15:58:01 +04:00
if ( line [ 0 ] = = ' ' ) {
/* We have a SID */
2010-05-21 05:25:01 +04:00
struct dom_sid sid ;
2009-01-20 02:09:51 +03:00
if ( ! string_to_sid ( & sid , & line [ 1 ] ) ) {
DEBUG ( 1 , ( " get_user_tokens_from_file: Could "
" not convert sid %s \n " , & line [ 1 ] ) ) ;
return false ;
}
2004-10-12 15:58:01 +04:00
if ( token = = NULL ) {
DEBUG ( 0 , ( " File does not begin with username " ) ) ;
2008-05-12 13:53:23 +04:00
return false ;
2004-10-12 15:58:01 +04:00
}
add_sid_to_token ( & token - > token , & sid ) ;
continue ;
}
/* And a new user... */
* num_tokens + = 1 ;
2004-12-07 21:25:53 +03:00
* tokens = SMB_REALLOC_ARRAY ( * tokens , struct user_token , * num_tokens ) ;
2004-10-12 15:58:01 +04:00
if ( * tokens = = NULL ) {
DEBUG ( 0 , ( " Could not realloc tokens \n " ) ) ;
2008-05-12 13:53:23 +04:00
return false ;
2004-10-12 15:58:01 +04:00
}
token = & ( ( * tokens ) [ * num_tokens - 1 ] ) ;
fstrcpy ( token - > name , line ) ;
token - > token . num_sids = 0 ;
2010-08-31 03:32:52 +04:00
token - > token . sids = NULL ;
2004-10-12 15:58:01 +04:00
continue ;
}
2008-05-12 13:53:23 +04:00
return false ;
2004-10-12 15:58:01 +04:00
}
/*
* Show the list of all users that have access to a share
*/
2005-09-30 21:13:37 +04:00
static void show_userlist ( struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
const char * netname ,
int num_tokens ,
struct user_token * tokens )
2004-10-12 15:58:01 +04:00
{
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
2010-05-18 12:29:34 +04:00
struct security_descriptor * share_sd = NULL ;
struct security_descriptor * root_sd = NULL ;
2008-04-20 16:05:25 +04:00
struct cli_state * cli = rpc_pipe_np_smb_conn ( pipe_hnd ) ;
2004-10-12 15:58:01 +04:00
int i ;
2008-03-10 07:17:09 +03:00
union srvsvc_NetShareInfo info ;
2007-10-11 00:34:30 +04:00
WERROR result ;
2008-03-10 07:17:09 +03:00
NTSTATUS status ;
2004-10-12 15:58:01 +04:00
uint16 cnum ;
2008-03-10 07:17:09 +03:00
status = rpccli_srvsvc_NetShareGetInfo ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2008-03-10 07:17:09 +03:00
netname ,
502 ,
& info ,
& result ) ;
2004-10-12 15:58:01 +04:00
2008-03-10 07:17:09 +03:00
if ( ! NT_STATUS_IS_OK ( status ) | | ! W_ERROR_IS_OK ( result ) ) {
2004-10-12 15:58:01 +04:00
DEBUG ( 1 , ( " Coult not query secdesc for share %s \n " ,
netname ) ) ;
return ;
}
2008-04-01 02:11:55 +04:00
share_sd = info . info502 - > sd_buf . sd ;
2004-10-12 15:58:01 +04:00
if ( share_sd = = NULL ) {
DEBUG ( 1 , ( " Got no secdesc for share %s \n " ,
netname ) ) ;
}
cnum = cli - > cnum ;
2009-01-26 10:37:13 +03:00
if ( ! NT_STATUS_IS_OK ( cli_tcon_andx ( cli , netname , " A: " , " " , 0 ) ) ) {
2004-10-12 15:58:01 +04:00
return ;
}
2009-05-01 02:26:43 +04:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli , " \\ " , 0 , READ_CONTROL_ACCESS , 0 ,
FILE_SHARE_READ | FILE_SHARE_WRITE , FILE_OPEN , 0x0 , 0x0 , & fnum ) ) ) {
2004-10-12 15:58:01 +04:00
root_sd = cli_query_secdesc ( cli , fnum , mem_ctx ) ;
}
for ( i = 0 ; i < num_tokens ; i + + ) {
uint32 acc_granted ;
if ( share_sd ! = NULL ) {
2008-10-31 20:51:45 +03:00
status = se_access_check ( share_sd , & tokens [ i ] . token ,
1 , & acc_granted ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2004-10-12 15:58:01 +04:00
DEBUG ( 1 , ( " Could not check share_sd for "
" user %s \n " ,
tokens [ i ] . name ) ) ;
continue ;
}
}
if ( root_sd = = NULL ) {
d_printf ( " %s \n " , tokens [ i ] . name ) ;
continue ;
}
2008-10-31 20:51:45 +03:00
status = se_access_check ( root_sd , & tokens [ i ] . token ,
1 , & acc_granted ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2004-10-12 15:58:01 +04:00
DEBUG ( 1 , ( " Could not check root_sd for user %s \n " ,
tokens [ i ] . name ) ) ;
continue ;
}
d_printf ( " %s \n " , tokens [ i ] . name ) ;
}
2009-05-04 00:45:42 +04:00
if ( fnum ! = ( uint16_t ) - 1 )
2004-10-12 15:58:01 +04:00
cli_close ( cli , fnum ) ;
cli_tdis ( cli ) ;
cli - > cnum = cnum ;
return ;
}
struct share_list {
int num_shares ;
char * * shares ;
} ;
static void collect_share ( const char * name , uint32 m ,
const char * comment , void * state )
{
struct share_list * share_list = ( struct share_list * ) state ;
if ( m ! = STYPE_DISKTREE )
return ;
share_list - > num_shares + = 1 ;
2004-12-07 21:25:53 +03:00
share_list - > shares = SMB_REALLOC_ARRAY ( share_list - > shares , char * , share_list - > num_shares ) ;
r13915: Fixed a very interesting class of realloc() bugs found by Coverity.
realloc can return NULL in one of two cases - (1) the realloc failed,
(2) realloc succeeded but the new size requested was zero, in which
case this is identical to a free() call.
The error paths dealing with these two cases should be different,
but mostly weren't. Secondly the standard idiom for dealing with
realloc when you know the new size is non-zero is the following :
tmp = realloc(p, size);
if (!tmp) {
SAFE_FREE(p);
return error;
} else {
p = tmp;
}
However, there were *many* *many* places in Samba where we were
using the old (broken) idiom of :
p = realloc(p, size)
if (!p) {
return error;
}
which will leak the memory pointed to by p on realloc fail.
This commit (hopefully) fixes all these cases by moving to
a standard idiom of :
p = SMB_REALLOC(p, size)
if (!p) {
return error;
}
Where if the realloc returns null due to the realloc failing
or size == 0 we *guarentee* that the storage pointed to by p
has been freed. This allows me to remove a lot of code that
was dealing with the standard (more verbose) method that required
a tmp pointer. This is almost always what you want. When a
realloc fails you never usually want the old memory, you
want to free it and get into your error processing asap.
For the 11 remaining cases where we really do need to keep the
old pointer I have invented the new macro SMB_REALLOC_KEEP_OLD_ON_ERROR,
which can be used as follows :
tmp = SMB_REALLOC_KEEP_OLD_ON_ERROR(p, size);
if (!tmp) {
SAFE_FREE(p);
return error;
} else {
p = tmp;
}
SMB_REALLOC_KEEP_OLD_ON_ERROR guarentees never to free the
pointer p, even on size == 0 or realloc fail. All this is
done by a hidden extra argument to Realloc(), BOOL free_old_on_error
which is set appropriately by the SMB_REALLOC and SMB_REALLOC_KEEP_OLD_ON_ERROR
macros (and their array counterparts).
It remains to be seen what this will do to our Coverity bug count :-).
Jeremy.
(This used to be commit 1d710d06a214f3f1740e80e0bffd6aab44aac2b0)
2006-03-07 09:31:04 +03:00
if ( ! share_list - > shares ) {
share_list - > num_shares = 0 ;
return ;
}
2004-12-07 21:25:53 +03:00
share_list - > shares [ share_list - > num_shares - 1 ] = SMB_STRDUP ( name ) ;
2004-10-12 15:58:01 +04:00
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* List shares on a remote RPC server , including the security descriptors .
2004-10-12 15:58:01 +04:00
*
* All parameters are provided by the run_rpc_command function , except for
2008-06-12 12:55:55 +04:00
* argc , argv which are passed through .
2004-10-12 15:58:01 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param domain_sid The domain sid acquired from the remote server .
2004-10-12 15:58:01 +04:00
* @ param cli A cli_state connected to the server .
2008-06-12 12:55:55 +04:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-10-12 15:58:01 +04:00
*
* @ return Normal NTSTATUS return .
* */
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_share_allowedusers_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2005-09-30 21:13:37 +04:00
const char * domain_name ,
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2004-10-12 15:58:01 +04:00
{
int ret ;
2007-10-19 04:40:25 +04:00
bool r ;
2004-10-12 15:58:01 +04:00
uint32 i ;
FILE * f ;
struct user_token * tokens = NULL ;
int num_tokens = 0 ;
struct share_list share_list ;
if ( argc = = 0 ) {
f = stdin ;
} else {
f = fopen ( argv [ 0 ] , " r " ) ;
}
if ( f = = NULL ) {
DEBUG ( 0 , ( " Could not open userlist: %s \n " , strerror ( errno ) ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
r = get_user_tokens_from_file ( f , & num_tokens , & tokens ) ;
if ( f ! = stdin )
fclose ( f ) ;
if ( ! r ) {
DEBUG ( 0 , ( " Could not read users from file \n " ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
for ( i = 0 ; i < num_tokens ; i + + )
collect_alias_memberships ( & tokens [ i ] . token ) ;
share_list . num_shares = 0 ;
share_list . shares = NULL ;
ret = cli_RNetShareEnum ( cli , collect_share , & share_list ) ;
if ( ret = = - 1 ) {
DEBUG ( 0 , ( " Error returning browse list: %s \n " ,
cli_errstr ( cli ) ) ) ;
goto done ;
}
for ( i = 0 ; i < share_list . num_shares ; i + + ) {
char * netname = share_list . shares [ i ] ;
if ( netname [ strlen ( netname ) - 1 ] = = ' $ ' )
continue ;
d_printf ( " %s \n " , netname ) ;
2005-09-30 21:13:37 +04:00
show_userlist ( pipe_hnd , mem_ctx , netname ,
2004-10-12 15:58:01 +04:00
num_tokens , tokens ) ;
}
done :
for ( i = 0 ; i < num_tokens ; i + + ) {
free_user_token ( & tokens [ i ] . token ) ;
}
SAFE_FREE ( tokens ) ;
SAFE_FREE ( share_list . shares ) ;
return NT_STATUS_OK ;
}
2008-05-10 01:22:12 +04:00
static int rpc_share_allowedusers ( struct net_context * c , int argc ,
const char * * argv )
2004-10-12 15:58:01 +04:00
{
int result ;
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc share allowedusers \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " List allowed users " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2009-11-08 21:37:26 +03:00
result = run_rpc_command ( c , NULL , & ndr_table_samr . syntax_id , 0 ,
2004-10-12 15:58:01 +04:00
rpc_aliaslist_internals ,
argc , argv ) ;
if ( result ! = 0 )
return result ;
2009-11-08 21:37:26 +03:00
result = run_rpc_command ( c , NULL , & ndr_table_lsarpc . syntax_id , 0 ,
2004-10-12 15:58:01 +04:00
rpc_aliaslist_dump ,
argc , argv ) ;
if ( result ! = 0 )
return result ;
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_srvsvc . syntax_id , 0 ,
2004-10-12 15:58:01 +04:00
rpc_share_allowedusers_internals ,
argc , argv ) ;
}
2008-05-10 01:22:12 +04:00
int net_usersidlist ( struct net_context * c , int argc , const char * * argv )
2004-10-12 15:58:01 +04:00
{
int num_tokens = 0 ;
struct user_token * tokens = NULL ;
int i ;
if ( argc ! = 0 ) {
2008-05-10 01:22:12 +04:00
net_usersidlist_usage ( c , argc , argv ) ;
2004-10-12 15:58:01 +04:00
return 0 ;
}
2008-05-10 01:22:12 +04:00
if ( ! get_user_tokens ( c , & num_tokens , & tokens ) ) {
2004-10-12 15:58:01 +04:00
DEBUG ( 0 , ( " Could not get the user/sid list \n " ) ) ;
return 0 ;
}
for ( i = 0 ; i < num_tokens ; i + + ) {
dump_user_token ( & tokens [ i ] ) ;
free_user_token ( & tokens [ i ] . token ) ;
}
SAFE_FREE ( tokens ) ;
return 1 ;
}
2008-05-10 01:22:12 +04:00
int net_usersidlist_usage ( struct net_context * c , int argc , const char * * argv )
2004-10-12 15:58:01 +04:00
{
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " net usersidlist \n "
" \t prints out a list of all users the running winbind knows \n "
" \t about, together with all their SIDs. This is used as \n "
" \t input to the 'net rpc share allowedusers' command. \n \n " ) ) ;
2004-10-12 15:58:01 +04:00
2008-05-10 01:22:12 +04:00
net_common_flags_usage ( c , argc , argv ) ;
2004-10-12 15:58:01 +04:00
return - 1 ;
}
2008-05-08 13:23:38 +04:00
/**
2002-07-15 14:35:28 +04:00
* ' net rpc share ' entrypoint .
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-07-15 14:35:28 +04:00
* */
2008-05-10 01:22:12 +04:00
int net_rpc_share ( struct net_context * c , int argc , const char * * argv )
2002-07-15 14:35:28 +04:00
{
2008-09-04 17:37:03 +04:00
NET_API_STATUS status ;
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 12:27:59 +04:00
{
" add " ,
rpc_share_add ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Add share " ) ,
N_ ( " net rpc share add \n "
" Add share " )
2008-05-21 12:27:59 +04:00
} ,
{
" delete " ,
rpc_share_delete ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Remove share " ) ,
N_ ( " net rpc share delete \n "
" Remove share " )
2008-05-21 12:27:59 +04:00
} ,
{
" allowedusers " ,
rpc_share_allowedusers ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Modify allowed users " ) ,
N_ ( " net rpc share allowedusers \n "
" Modify allowed users " )
2008-05-21 12:27:59 +04:00
} ,
{
" migrate " ,
rpc_share_migrate ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Migrate share to local server " ) ,
N_ ( " net rpc share migrate \n "
" Migrate share to local server " )
2008-05-21 12:27:59 +04:00
} ,
{
" list " ,
rpc_share_list ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " List shares " ) ,
N_ ( " net rpc share list \n "
" List shares " )
2008-05-21 12:27:59 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2002-07-15 14:35:28 +04:00
} ;
2008-09-04 17:37:03 +04:00
status = libnetapi_init ( & c - > netapi_ctx ) ;
if ( status ! = 0 ) {
return - 1 ;
}
2009-07-05 11:21:07 +04:00
libnetapi_set_username ( c - > netapi_ctx , c - > opt_user_name ) ;
libnetapi_set_password ( c - > netapi_ctx , c - > opt_password ) ;
if ( c - > opt_kerberos ) {
2008-09-04 17:37:03 +04:00
libnetapi_set_use_kerberos ( c - > netapi_ctx ) ;
}
2008-05-21 12:27:59 +04:00
if ( argc = = 0 ) {
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net rpc share \n "
2009-08-04 10:28:50 +04:00
" List shares \n "
" Alias for net rpc share list \n " ) ) ;
2008-05-21 12:27:59 +04:00
net_display_usage_from_functable ( func ) ;
return 0 ;
}
2008-09-10 12:53:46 +04:00
return rpc_share_list ( c , argc , argv ) ;
2008-05-21 12:27:59 +04:00
}
2002-07-15 14:35:28 +04:00
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rpc share " , func ) ;
2002-07-15 14:35:28 +04:00
}
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_sh_share_list ( struct net_context * c ,
TALLOC_CTX * mem_ctx ,
2006-02-04 01:19:41 +03:00
struct rpc_sh_ctx * ctx ,
struct rpc_pipe_client * pipe_hnd ,
int argc , const char * * argv )
{
2008-09-10 12:53:46 +04:00
return werror_to_ntstatus ( W_ERROR ( rpc_share_list ( c , argc , argv ) ) ) ;
2006-02-04 01:19:41 +03:00
}
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_sh_share_add ( struct net_context * c ,
TALLOC_CTX * mem_ctx ,
2006-02-04 01:19:41 +03:00
struct rpc_sh_ctx * ctx ,
struct rpc_pipe_client * pipe_hnd ,
int argc , const char * * argv )
{
2008-09-04 17:41:45 +04:00
NET_API_STATUS status ;
2008-03-10 16:25:45 +03:00
uint32_t parm_err = 0 ;
2008-09-04 17:41:45 +04:00
struct SHARE_INFO_2 i2 ;
2006-02-04 01:19:41 +03:00
if ( ( argc < 2 ) | | ( argc > 3 ) ) {
2010-01-19 11:23:42 +03:00
d_fprintf ( stderr , _ ( " Usage: %s <share> <path> [comment] \n " ) ,
2006-02-04 01:19:41 +03:00
ctx - > whoami ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
2008-09-04 17:41:45 +04:00
i2 . shi2_netname = argv [ 0 ] ;
i2 . shi2_type = STYPE_DISKTREE ;
i2 . shi2_remark = ( argc = = 3 ) ? argv [ 2 ] : " " ;
i2 . shi2_permissions = 0 ;
i2 . shi2_max_uses = 0 ;
i2 . shi2_current_uses = 0 ;
i2 . shi2_path = argv [ 1 ] ;
i2 . shi2_passwd = NULL ;
2008-03-10 16:25:45 +03:00
2008-09-04 17:41:45 +04:00
status = NetShareAdd ( pipe_hnd - > desthost ,
2 ,
( uint8_t * ) & i2 ,
& parm_err ) ;
2008-03-10 16:25:45 +03:00
2008-09-04 17:41:45 +04:00
return werror_to_ntstatus ( W_ERROR ( status ) ) ;
2006-02-04 01:19:41 +03:00
}
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_sh_share_delete ( struct net_context * c ,
TALLOC_CTX * mem_ctx ,
2006-02-04 01:19:41 +03:00
struct rpc_sh_ctx * ctx ,
struct rpc_pipe_client * pipe_hnd ,
int argc , const char * * argv )
{
if ( argc ! = 1 ) {
2010-01-19 13:43:54 +03:00
d_fprintf ( stderr , " %s %s <share> \n " , _ ( " Usage: " ) , ctx - > whoami ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_INVALID_PARAMETER ;
}
2008-09-04 17:46:21 +04:00
return werror_to_ntstatus ( W_ERROR ( NetShareDel ( pipe_hnd - > desthost , argv [ 0 ] , 0 ) ) ) ;
2006-02-04 01:19:41 +03:00
}
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_sh_share_info ( struct net_context * c ,
TALLOC_CTX * mem_ctx ,
2006-02-04 01:19:41 +03:00
struct rpc_sh_ctx * ctx ,
struct rpc_pipe_client * pipe_hnd ,
int argc , const char * * argv )
{
2008-03-10 07:17:09 +03:00
union srvsvc_NetShareInfo info ;
2007-10-11 00:34:30 +04:00
WERROR result ;
2008-03-10 07:17:09 +03:00
NTSTATUS status ;
2006-02-04 01:19:41 +03:00
if ( argc ! = 1 ) {
2010-01-19 13:43:54 +03:00
d_fprintf ( stderr , " %s %s <share> \n " , _ ( " Usage: " ) , ctx - > whoami ) ;
2006-02-04 01:19:41 +03:00
return NT_STATUS_INVALID_PARAMETER ;
}
2008-03-10 07:17:09 +03:00
status = rpccli_srvsvc_NetShareGetInfo ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2008-03-10 07:17:09 +03:00
argv [ 0 ] ,
2 ,
& info ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) | | ! W_ERROR_IS_OK ( result ) ) {
2006-02-04 01:19:41 +03:00
goto done ;
}
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Name: %s \n " ) , info . info2 - > name ) ;
d_printf ( _ ( " Comment: %s \n " ) , info . info2 - > comment ) ;
d_printf ( _ ( " Path: %s \n " ) , info . info2 - > path ) ;
d_printf ( _ ( " Password: %s \n " ) , info . info2 - > password ) ;
2006-02-04 01:19:41 +03:00
done :
2007-10-11 00:34:30 +04:00
return werror_to_ntstatus ( result ) ;
2006-02-04 01:19:41 +03:00
}
2008-05-10 01:22:12 +04:00
struct rpc_sh_cmd * net_rpc_share_cmds ( struct net_context * c , TALLOC_CTX * mem_ctx ,
2006-02-04 01:19:41 +03:00
struct rpc_sh_ctx * ctx )
{
static struct rpc_sh_cmd cmds [ ] = {
2009-11-08 21:37:26 +03:00
{ " list " , NULL , & ndr_table_srvsvc . syntax_id , rpc_sh_share_list ,
N_ ( " List available shares " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ " add " , NULL , & ndr_table_srvsvc . syntax_id , rpc_sh_share_add ,
N_ ( " Add a share " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ " delete " , NULL , & ndr_table_srvsvc . syntax_id , rpc_sh_share_delete ,
N_ ( " Delete a share " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ " info " , NULL , & ndr_table_srvsvc . syntax_id , rpc_sh_share_info ,
N_ ( " Get information about a share " ) } ,
2006-02-04 01:19:41 +03:00
2009-11-08 21:37:26 +03:00
{ NULL , NULL , 0 , NULL , NULL }
2006-02-04 01:19:41 +03:00
} ;
return cmds ;
2006-05-17 15:14:26 +04:00
}
2006-02-04 01:19:41 +03:00
2002-07-15 14:35:28 +04:00
/****************************************************************************/
2008-05-10 01:22:12 +04:00
static int rpc_file_usage ( struct net_context * c , int argc , const char * * argv )
2002-07-15 14:35:28 +04:00
{
2008-05-13 15:52:58 +04:00
return net_file_usage ( c , argc , argv ) ;
2002-07-15 14:35:28 +04:00
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Close a file on a remote RPC server .
2002-07-15 14:35:28 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-07-15 14:35:28 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2002-07-15 14:35:28 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_file_close ( struct net_context * c , int argc , const char * * argv )
2002-07-15 14:35:28 +04:00
{
2008-05-21 12:27:59 +04:00
if ( argc < 1 | | c - > display_usage ) {
2008-05-10 01:22:12 +04:00
return rpc_file_usage ( c , argc , argv ) ;
2002-07-15 14:35:28 +04:00
}
2008-09-10 12:34:13 +04:00
return NetFileClose ( c - > opt_host , atoi ( argv [ 0 ] ) ) ;
2002-07-15 14:35:28 +04:00
}
2008-05-08 13:23:38 +04:00
/**
* Formatted print of open file info
2002-07-15 14:35:28 +04:00
*
2008-09-10 12:34:28 +04:00
* @ param r struct FILE_INFO_3 contents
2002-07-15 14:35:28 +04:00
* */
2008-09-10 12:34:28 +04:00
static void display_file_info_3 ( struct FILE_INFO_3 * r )
2002-07-15 14:35:28 +04:00
{
d_printf ( " %-7.1d %-20.20s 0x%-4.2x %-6.1d %s \n " ,
2008-09-10 12:34:28 +04:00
r - > fi3_id , r - > fi3_username , r - > fi3_permissions ,
r - > fi3_num_locks , r - > fi3_pathname ) ;
2002-07-15 14:35:28 +04:00
}
2008-05-08 13:23:38 +04:00
/**
2008-09-10 12:34:28 +04:00
* List files for a user on a remote RPC server .
2002-07-15 14:35:28 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-07-15 14:35:28 +04:00
*
2008-09-10 12:34:28 +04:00
* @ return A shell status integer ( 0 for success ) . .
2002-07-15 14:35:28 +04:00
* */
2008-09-10 12:34:28 +04:00
static int rpc_file_user ( struct net_context * c , int argc , const char * * argv )
2002-07-15 14:35:28 +04:00
{
2008-09-10 12:34:28 +04:00
NET_API_STATUS status ;
2002-07-15 14:35:28 +04:00
uint32 preferred_len = 0xffffffff , i ;
2002-08-17 18:45:04 +04:00
const char * username = NULL ;
2008-03-10 19:08:55 +03:00
uint32_t total_entries = 0 ;
2008-09-10 12:34:28 +04:00
uint32_t entries_read = 0 ;
2008-03-10 19:08:55 +03:00
uint32_t resume_handle = 0 ;
2008-09-10 12:34:28 +04:00
struct FILE_INFO_3 * i3 = NULL ;
if ( c - > display_usage ) {
return rpc_file_usage ( c , argc , argv ) ;
}
2002-07-15 14:35:28 +04:00
/* if argc > 0, must be user command */
2008-09-10 12:34:28 +04:00
if ( argc > 0 ) {
2002-08-17 18:45:04 +04:00
username = smb_xstrdup ( argv [ 0 ] ) ;
2008-09-10 12:34:28 +04:00
}
2002-07-15 14:35:28 +04:00
2008-09-10 12:34:28 +04:00
status = NetFileEnum ( c - > opt_host ,
NULL ,
username ,
3 ,
2009-02-01 02:31:16 +03:00
( uint8_t * * ) ( void * ) & i3 ,
2008-09-10 12:34:28 +04:00
preferred_len ,
& entries_read ,
& total_entries ,
& resume_handle ) ;
2008-03-10 19:08:55 +03:00
2008-09-10 12:34:28 +04:00
if ( status ! = 0 ) {
2002-07-15 14:35:28 +04:00
goto done ;
2008-09-10 12:34:28 +04:00
}
2002-07-15 14:35:28 +04:00
/* Display results */
2009-08-04 10:28:50 +04:00
d_printf ( _ (
2008-05-21 12:27:59 +04:00
" \n Enumerating open files on remote server: \n \n "
" \n FileId Opened by Perms Locks Path "
2009-08-04 10:28:50 +04:00
" \n ------ --------- ----- ----- ---- \n " ) ) ;
2008-09-10 12:34:28 +04:00
for ( i = 0 ; i < entries_read ; i + + ) {
display_file_info_3 ( & i3 [ i ] ) ;
2002-07-15 14:35:28 +04:00
}
2008-09-10 12:34:28 +04:00
done :
return status ;
2002-07-15 14:35:28 +04:00
}
2008-05-08 13:23:38 +04:00
/**
2002-07-15 14:35:28 +04:00
* ' net rpc file ' entrypoint .
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-07-15 14:35:28 +04:00
* */
2008-05-10 01:22:12 +04:00
int net_rpc_file ( struct net_context * c , int argc , const char * * argv )
2002-07-15 14:35:28 +04:00
{
2008-09-10 12:34:13 +04:00
NET_API_STATUS status ;
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 12:27:59 +04:00
{
" close " ,
rpc_file_close ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Close opened file " ) ,
N_ ( " net rpc file close \n "
" Close opened file " )
2008-05-21 12:27:59 +04:00
} ,
{
" user " ,
rpc_file_user ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " List files opened by user " ) ,
N_ ( " net rpc file user \n "
" List files opened by user " )
2008-05-21 12:27:59 +04:00
} ,
2002-07-15 14:35:28 +04:00
#if 0
2008-05-21 12:27:59 +04:00
{
" info " ,
rpc_file_info ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Display information about opened file " ) ,
N_ ( " net rpc file info \n "
" Display information about opened file " )
2008-05-21 12:27:59 +04:00
} ,
2002-07-15 14:35:28 +04:00
# endif
2008-05-21 12:27:59 +04:00
{ NULL , NULL , 0 , NULL , NULL }
2002-07-15 14:35:28 +04:00
} ;
2008-09-10 12:34:13 +04:00
status = libnetapi_init ( & c - > netapi_ctx ) ;
if ( status ! = 0 ) {
return - 1 ;
}
2009-07-05 11:21:07 +04:00
libnetapi_set_username ( c - > netapi_ctx , c - > opt_user_name ) ;
libnetapi_set_password ( c - > netapi_ctx , c - > opt_password ) ;
if ( c - > opt_kerberos ) {
2008-09-10 12:34:13 +04:00
libnetapi_set_use_kerberos ( c - > netapi_ctx ) ;
}
2008-05-21 12:27:59 +04:00
if ( argc = = 0 ) {
if ( c - > display_usage ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Usage: \n " ) ) ;
d_printf ( _ ( " net rpc file \n "
" List opened files \n " ) ) ;
2008-05-21 12:27:59 +04:00
net_display_usage_from_functable ( func ) ;
return 0 ;
}
2008-09-10 12:34:28 +04:00
return rpc_file_user ( c , argc , argv ) ;
2008-05-21 12:27:59 +04:00
}
2002-07-15 14:35:28 +04:00
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rpc file " , func ) ;
2002-07-15 14:35:28 +04:00
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* ABORT the shutdown of a remote RPC Server , over initshutdown pipe .
2002-07-15 14:35:28 +04:00
*
2002-09-25 19:19:00 +04:00
* All parameters are provided by the run_rpc_command function , except for
2008-05-08 13:23:38 +04:00
* argc , argv which are passed through .
2001-12-31 16:00:59 +03:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param domain_sid The domain sid acquired from the remote server .
2001-12-31 16:00:59 +03:00
* @ param cli A cli_state connected to the server .
2008-06-12 12:55:55 +04:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2001-12-31 16:00:59 +03:00
*
* @ return Normal NTSTATUS return .
* */
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_shutdown_abort_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
struct cli_state * cli ,
2005-09-30 21:13:37 +04:00
struct rpc_pipe_client * pipe_hnd ,
2008-05-08 13:23:38 +04:00
TALLOC_CTX * mem_ctx ,
2005-09-30 21:13:37 +04:00
int argc ,
2008-05-08 13:23:38 +04:00
const char * * argv )
2001-12-31 16:00:59 +03:00
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2008-05-08 13:23:38 +04:00
2007-12-03 20:40:36 +03:00
result = rpccli_initshutdown_Abort ( pipe_hnd , mem_ctx , NULL , NULL ) ;
2008-05-08 13:23:38 +04:00
2004-11-15 23:57:27 +03:00
if ( NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " \n Shutdown successfully aborted \n " ) ) ;
2003-10-24 18:03:18 +04:00
DEBUG ( 5 , ( " cmd_shutdown_abort: query succeeded \n " ) ) ;
2004-11-15 23:57:27 +03:00
} else
2003-10-24 18:03:18 +04:00
DEBUG ( 5 , ( " cmd_shutdown_abort: query failed \n " ) ) ;
2008-05-08 13:23:38 +04:00
2003-10-24 18:03:18 +04:00
return result ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* ABORT the shutdown of a remote RPC Server , over winreg pipe .
2003-10-24 18:03:18 +04:00
*
* All parameters are provided by the run_rpc_command function , except for
2008-05-08 13:23:38 +04:00
* argc , argv which are passed through .
2003-10-24 18:03:18 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param domain_sid The domain sid acquired from the remote server .
2003-10-24 18:03:18 +04:00
* @ param cli A cli_state connected to the server .
2008-06-12 12:55:55 +04:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2003-10-24 18:03:18 +04:00
*
* @ return Normal NTSTATUS return .
* */
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_reg_shutdown_abort_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
struct cli_state * cli ,
2005-09-30 21:13:37 +04:00
struct rpc_pipe_client * pipe_hnd ,
2008-05-08 13:23:38 +04:00
TALLOC_CTX * mem_ctx ,
2005-09-30 21:13:37 +04:00
int argc ,
2008-05-08 13:23:38 +04:00
const char * * argv )
2003-10-24 18:03:18 +04:00
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2008-05-08 13:23:38 +04:00
2007-12-03 20:40:36 +03:00
result = rpccli_winreg_AbortSystemShutdown ( pipe_hnd , mem_ctx , NULL , NULL ) ;
2008-05-08 13:23:38 +04:00
2004-11-15 23:57:27 +03:00
if ( NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " \n Shutdown successfully aborted \n " ) ) ;
2001-12-31 16:00:59 +03:00
DEBUG ( 5 , ( " cmd_reg_abort_shutdown: query succeeded \n " ) ) ;
2004-11-15 23:57:27 +03:00
} else
2001-12-31 16:00:59 +03:00
DEBUG ( 5 , ( " cmd_reg_abort_shutdown: query failed \n " ) ) ;
2008-05-08 13:23:38 +04:00
2001-12-31 16:00:59 +03:00
return result ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* ABORT the shutdown of a remote RPC server .
2001-12-31 16:00:59 +03:00
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2001-12-31 16:00:59 +03:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2001-12-31 16:00:59 +03:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_shutdown_abort ( struct net_context * c , int argc ,
const char * * argv )
2001-12-31 16:00:59 +03:00
{
2008-05-21 12:27:59 +04:00
int rc = - 1 ;
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc abortshutdown \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Abort a scheduled shutdown " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2009-11-08 21:37:26 +03:00
rc = run_rpc_command ( c , NULL , & ndr_table_initshutdown . syntax_id , 0 ,
2008-05-21 12:27:59 +04:00
rpc_shutdown_abort_internals , argc , argv ) ;
2003-10-24 18:03:18 +04:00
if ( rc = = 0 )
return rc ;
DEBUG ( 1 , ( " initshutdown pipe didn't work, trying winreg pipe \n " ) ) ;
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_winreg . syntax_id , 0 ,
2003-10-24 18:03:18 +04:00
rpc_reg_shutdown_abort_internals ,
2001-12-31 16:00:59 +03:00
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Shut down a remote RPC Server via initshutdown pipe .
2001-12-31 16:00:59 +03:00
*
2002-09-25 19:19:00 +04:00
* All parameters are provided by the run_rpc_command function , except for
2008-06-12 12:55:55 +04:00
* argc , argv which are passed through .
2001-12-31 16:00:59 +03:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param domain_sid The domain sid acquired from the remote server .
2001-12-31 16:00:59 +03:00
* @ param cli A cli_state connected to the server .
2008-06-12 12:55:55 +04:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2001-12-31 16:00:59 +03:00
*
* @ return Normal NTSTATUS return .
* */
2008-05-10 01:22:12 +04:00
NTSTATUS rpc_init_shutdown_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2004-11-15 23:57:27 +03:00
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
2009-08-04 10:28:50 +04:00
const char * msg = N_ ( " This machine will be shutdown shortly " ) ;
2004-11-15 23:57:27 +03:00
uint32 timeout = 20 ;
2008-10-15 18:13:02 +04:00
struct lsa_StringLarge msg_string ;
2004-11-15 23:57:27 +03:00
2008-05-10 01:22:12 +04:00
if ( c - > opt_comment ) {
msg = c - > opt_comment ;
2004-11-15 23:57:27 +03:00
}
2008-05-10 01:22:12 +04:00
if ( c - > opt_timeout ) {
timeout = c - > opt_timeout ;
2004-11-15 23:57:27 +03:00
}
2008-10-15 18:13:02 +04:00
msg_string . string = msg ;
2006-09-26 19:15:26 +04:00
2004-11-15 23:57:27 +03:00
/* create an entry */
2006-09-26 19:15:26 +04:00
result = rpccli_initshutdown_Init ( pipe_hnd , mem_ctx , NULL ,
2008-05-10 01:22:12 +04:00
& msg_string , timeout , c - > opt_force , c - > opt_reboot ,
NULL ) ;
2004-11-15 23:57:27 +03:00
if ( NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " \n Shutdown of remote machine succeeded \n " ) ) ;
2004-11-15 23:57:27 +03:00
DEBUG ( 5 , ( " Shutdown of remote machine succeeded \n " ) ) ;
2005-10-11 22:42:25 +04:00
} else {
DEBUG ( 1 , ( " Shutdown of remote machine failed! \n " ) ) ;
}
2004-11-15 23:57:27 +03:00
return result ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Shut down a remote RPC Server via winreg pipe .
2004-11-15 23:57:27 +03:00
*
* All parameters are provided by the run_rpc_command function , except for
2008-06-12 12:55:55 +04:00
* argc , argv which are passed through .
2004-11-15 23:57:27 +03:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param domain_sid The domain sid acquired from the remote server .
2004-11-15 23:57:27 +03:00
* @ param cli A cli_state connected to the server .
2008-06-12 12:55:55 +04:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-11-15 23:57:27 +03:00
*
* @ return Normal NTSTATUS return .
* */
2008-05-10 01:22:12 +04:00
NTSTATUS rpc_reg_shutdown_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2001-12-31 16:00:59 +03:00
{
2009-08-04 10:28:50 +04:00
const char * msg = N_ ( " This machine will be shutdown shortly " ) ;
2001-12-31 16:00:59 +03:00
uint32 timeout = 20 ;
2008-10-15 18:13:02 +04:00
struct lsa_StringLarge msg_string ;
2006-09-26 19:15:26 +04:00
NTSTATUS result ;
2007-12-03 20:40:36 +03:00
WERROR werr ;
2001-12-31 16:00:59 +03:00
2008-05-10 01:22:12 +04:00
if ( c - > opt_comment ) {
msg = c - > opt_comment ;
2001-12-31 16:00:59 +03:00
}
2008-10-15 18:13:02 +04:00
msg_string . string = msg ;
2006-09-26 19:15:26 +04:00
2008-05-10 01:22:12 +04:00
if ( c - > opt_timeout ) {
timeout = c - > opt_timeout ;
2001-12-31 16:00:59 +03:00
}
/* create an entry */
2006-09-26 19:15:26 +04:00
result = rpccli_winreg_InitiateSystemShutdown ( pipe_hnd , mem_ctx , NULL ,
2008-05-10 01:22:12 +04:00
& msg_string , timeout , c - > opt_force , c - > opt_reboot ,
& werr ) ;
2001-12-31 16:00:59 +03:00
2006-09-26 19:15:26 +04:00
if ( NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " \n Shutdown of remote machine succeeded \n " ) ) ;
2005-10-11 22:42:25 +04:00
} else {
2006-01-18 00:22:00 +03:00
d_fprintf ( stderr , " \n Shutdown of remote machine failed \n " ) ;
2007-12-03 20:40:36 +03:00
if ( W_ERROR_EQUAL ( werr , WERR_MACHINE_LOCKED ) )
2006-01-18 00:22:00 +03:00
d_fprintf ( stderr , " \n Machine locked, use -f switch to force \n " ) ;
2005-10-11 22:42:25 +04:00
else
2008-11-01 19:19:26 +03:00
d_fprintf ( stderr , " \n result was: %s \n " , win_errstr ( werr ) ) ;
2004-11-15 23:57:27 +03:00
}
2001-12-31 16:00:59 +03:00
2006-09-26 19:15:26 +04:00
return result ;
2001-12-31 16:00:59 +03:00
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Shut down a remote RPC server .
2001-12-31 16:00:59 +03:00
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2001-12-31 16:00:59 +03:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2001-12-31 16:00:59 +03:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_shutdown ( struct net_context * c , int argc , const char * * argv )
2001-12-31 16:00:59 +03:00
{
2008-05-21 12:27:59 +04:00
int rc = - 1 ;
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc shutdown \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Shut down a remote RPC server " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2009-11-08 21:37:26 +03:00
rc = run_rpc_command ( c , NULL , & ndr_table_initshutdown . syntax_id , 0 ,
rpc_init_shutdown_internals , argc , argv ) ;
2004-11-15 23:57:27 +03:00
2005-10-11 22:42:25 +04:00
if ( rc ) {
DEBUG ( 1 , ( " initshutdown pipe failed, trying winreg pipe \n " ) ) ;
2009-11-08 21:37:26 +03:00
rc = run_rpc_command ( c , NULL , & ndr_table_winreg . syntax_id , 0 ,
2005-10-11 22:42:25 +04:00
rpc_reg_shutdown_internals , argc , argv ) ;
}
2004-11-15 23:57:27 +03:00
2005-10-11 22:42:25 +04:00
return rc ;
2001-12-31 16:00:59 +03:00
}
2002-03-01 05:56:35 +03:00
/***************************************************************************
NT Domain trusts code ( i . e . ' net rpc trustdom ' functionality )
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* Add interdomain trust account to the RPC server .
* All parameters ( except for argc and argv ) are passed by run_rpc_command
* function .
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param domain_sid The domain sid acquired from the server .
2002-03-01 05:56:35 +03:00
* @ param cli A cli_state connected to the server .
2008-06-12 12:55:55 +04:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2002-03-01 05:56:35 +03:00
*
2008-06-12 12:55:55 +04:00
* @ return normal NTSTATUS return code .
2002-03-01 05:56:35 +03:00
*/
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_trustdom_add_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
2005-09-30 21:13:37 +04:00
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
2008-05-08 13:23:38 +04:00
TALLOC_CTX * mem_ctx ,
2005-09-30 21:13:37 +04:00
int argc ,
const char * * argv )
{
2009-03-19 00:49:41 +03:00
struct policy_handle connect_pol , domain_pol , user_pol ;
2002-03-01 05:56:35 +03:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
char * acct_name ;
2008-02-01 16:21:54 +03:00
struct lsa_String lsa_acct_name ;
2006-02-27 13:32:45 +03:00
uint32 acb_info ;
2008-01-24 00:54:02 +03:00
uint32 acct_flags = 0 ;
uint32 user_rid ;
2008-02-01 16:21:54 +03:00
uint32_t access_granted = 0 ;
2008-02-12 22:01:36 +03:00
union samr_UserInfo info ;
2008-06-28 04:26:41 +04:00
unsigned int orig_timeout ;
2002-03-01 05:56:35 +03:00
2003-05-11 20:59:06 +04:00
if ( argc ! = 2 ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net rpc trustdom add <domain_name> "
2009-08-04 10:28:50 +04:00
" <trust password> \n " ) ) ;
2002-07-15 14:35:28 +04:00
return NT_STATUS_INVALID_PARAMETER ;
2002-03-01 05:56:35 +03:00
}
2010-01-19 13:43:54 +03:00
/*
2002-03-01 05:56:35 +03:00
* Make valid trusting domain account ( ie . uppercased and with ' $ ' appended )
*/
2008-02-01 16:21:54 +03:00
2002-03-01 05:56:35 +03:00
if ( asprintf ( & acct_name , " %s$ " , argv [ 0 ] ) < 0 ) {
return NT_STATUS_NO_MEMORY ;
}
2003-07-03 23:11:31 +04:00
strupper_m ( acct_name ) ;
2002-03-01 05:56:35 +03:00
2008-02-01 16:21:54 +03:00
init_lsa_String ( & lsa_acct_name , acct_name ) ;
2002-08-17 18:45:04 +04:00
/* Get samr policy handle */
2008-02-04 21:43:07 +03:00
result = rpccli_samr_Connect2 ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2008-02-04 21:43:07 +03:00
MAXIMUM_ALLOWED_ACCESS ,
& connect_pol ) ;
2002-03-01 05:56:35 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
goto done ;
}
2008-02-01 13:12:05 +03:00
2002-03-01 05:56:35 +03:00
/* Get domain policy handle */
2008-02-01 13:12:05 +03:00
result = rpccli_samr_OpenDomain ( pipe_hnd , mem_ctx ,
& connect_pol ,
MAXIMUM_ALLOWED_ACCESS ,
CONST_DISCARD ( struct dom_sid2 * , domain_sid ) ,
& domain_pol ) ;
2002-03-01 05:56:35 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
goto done ;
}
2008-06-28 04:26:41 +04:00
/* This call can take a long time - allow the server to time out.
* 35 seconds should do it . */
2008-06-28 12:38:33 +04:00
orig_timeout = rpccli_set_timeout ( pipe_hnd , 35000 ) ;
2008-06-28 04:26:41 +04:00
2002-03-01 05:56:35 +03:00
/* Create trusting domain's account */
2008-01-25 03:00:51 +03:00
acb_info = ACB_NORMAL ;
acct_flags = SEC_GENERIC_READ | SEC_GENERIC_WRITE | SEC_GENERIC_EXECUTE |
SEC_STD_WRITE_DAC | SEC_STD_DELETE |
SAMR_USER_ACCESS_SET_PASSWORD |
SAMR_USER_ACCESS_GET_ATTRIBUTES |
SAMR_USER_ACCESS_SET_ATTRIBUTES ;
2002-03-01 05:56:35 +03:00
2008-02-01 16:21:54 +03:00
result = rpccli_samr_CreateUser2 ( pipe_hnd , mem_ctx ,
& domain_pol ,
& lsa_acct_name ,
acb_info ,
acct_flags ,
& user_pol ,
& access_granted ,
& user_rid ) ;
2008-06-28 04:26:41 +04:00
/* And restore our original timeout. */
2008-06-28 12:38:33 +04:00
rpccli_set_timeout ( pipe_hnd , orig_timeout ) ;
2008-06-28 04:26:41 +04:00
2002-03-01 05:56:35 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " net rpc trustdom add: create user %s failed %s \n " ) ,
2008-06-28 04:26:41 +04:00
acct_name , nt_errstr ( result ) ) ;
2002-03-01 05:56:35 +03:00
goto done ;
}
2003-05-11 20:59:06 +04:00
{
2008-07-30 21:52:56 +04:00
struct samr_CryptPassword crypt_pwd ;
2003-05-11 20:59:06 +04:00
2008-12-06 02:28:34 +03:00
ZERO_STRUCT ( info . info23 ) ;
2008-02-12 22:01:36 +03:00
2008-07-30 21:52:56 +04:00
init_samr_CryptPassword ( argv [ 1 ] ,
& cli - > user_session_key ,
& crypt_pwd ) ;
2008-12-06 02:28:34 +03:00
info . info23 . info . fields_present = SAMR_FIELD_ACCT_FLAGS |
SAMR_FIELD_NT_PASSWORD_PRESENT ;
info . info23 . info . acct_flags = ACB_DOMTRUST ;
info . info23 . password = crypt_pwd ;
2008-02-12 22:01:36 +03:00
result = rpccli_samr_SetUserInfo2 ( pipe_hnd , mem_ctx ,
& user_pol ,
23 ,
& info ) ;
2003-05-11 20:59:06 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2003-05-12 03:49:36 +04:00
DEBUG ( 0 , ( " Could not set trust account password: %s \n " ,
2003-05-11 20:59:06 +04:00
nt_errstr ( result ) ) ) ;
goto done ;
}
}
2002-03-01 05:56:35 +03:00
done :
SAFE_FREE ( acct_name ) ;
return result ;
}
/**
* Create interdomain trust account for a remote domain .
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard argc .
* @ param argv Standard argv without initial components .
2002-03-01 05:56:35 +03:00
*
2008-06-12 12:55:55 +04:00
* @ return Integer status ( 0 means success ) .
2002-03-01 05:56:35 +03:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_trustdom_add ( struct net_context * c , int argc , const char * * argv )
2002-03-01 05:56:35 +03:00
{
2008-05-21 12:27:59 +04:00
if ( argc > 0 & & ! c - > display_usage ) {
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_samr . syntax_id , 0 ,
2008-05-10 01:22:12 +04:00
rpc_trustdom_add_internals , argc , argv ) ;
2003-08-16 01:57:59 +04:00
} else {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net rpc trustdom add <domain_name> <trust "
2009-08-04 10:28:50 +04:00
" password> \n " ) ) ;
2003-08-16 01:57:59 +04:00
return - 1 ;
}
2002-03-01 05:56:35 +03:00
}
2005-06-09 02:10:34 +04:00
2005-02-28 13:55:13 +03:00
/**
2005-02-28 14:17:13 +03:00
* Remove interdomain trust account from the RPC server .
2005-02-28 13:55:13 +03:00
* All parameters ( except for argc and argv ) are passed by run_rpc_command
* function .
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param domain_sid The domain sid acquired from the server .
2005-02-28 13:55:13 +03:00
* @ param cli A cli_state connected to the server .
2008-06-12 12:55:55 +04:00
* @ param mem_ctx Talloc context , destroyed on completion of the function .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2005-02-28 13:55:13 +03:00
*
2008-06-12 12:55:55 +04:00
* @ return normal NTSTATUS return code .
2005-02-28 13:55:13 +03:00
*/
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_trustdom_del_internals ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
2005-09-30 21:13:37 +04:00
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
2008-05-08 13:23:38 +04:00
TALLOC_CTX * mem_ctx ,
2005-09-30 21:13:37 +04:00
int argc ,
const char * * argv )
{
2009-03-19 00:49:41 +03:00
struct policy_handle connect_pol , domain_pol , user_pol ;
2005-02-28 13:55:13 +03:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
char * acct_name ;
2010-05-21 05:25:01 +04:00
struct dom_sid trust_acct_sid ;
2008-02-08 16:50:04 +03:00
struct samr_Ids user_rids , name_types ;
struct lsa_String lsa_acct_name ;
2005-02-28 13:55:13 +03:00
if ( argc ! = 1 ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net rpc trustdom del <domain_name> \n " ) ) ;
2005-02-28 13:55:13 +03:00
return NT_STATUS_INVALID_PARAMETER ;
}
2008-05-08 13:23:38 +04:00
/*
2005-02-28 13:55:13 +03:00
* Make valid trusting domain account ( ie . uppercased and with ' $ ' appended )
*/
2005-03-22 18:45:38 +03:00
acct_name = talloc_asprintf ( mem_ctx , " %s$ " , argv [ 0 ] ) ;
if ( acct_name = = NULL )
2005-02-28 13:55:13 +03:00
return NT_STATUS_NO_MEMORY ;
strupper_m ( acct_name ) ;
/* Get samr policy handle */
2008-02-04 21:43:07 +03:00
result = rpccli_samr_Connect2 ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2008-02-04 21:43:07 +03:00
MAXIMUM_ALLOWED_ACCESS ,
& connect_pol ) ;
2005-02-28 13:55:13 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
goto done ;
}
2008-02-01 13:12:05 +03:00
2005-02-28 13:55:13 +03:00
/* Get domain policy handle */
2008-02-01 13:12:05 +03:00
result = rpccli_samr_OpenDomain ( pipe_hnd , mem_ctx ,
& connect_pol ,
MAXIMUM_ALLOWED_ACCESS ,
CONST_DISCARD ( struct dom_sid2 * , domain_sid ) ,
& domain_pol ) ;
2005-02-28 13:55:13 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
goto done ;
}
2008-02-08 16:50:04 +03:00
init_lsa_String ( & lsa_acct_name , acct_name ) ;
result = rpccli_samr_LookupNames ( pipe_hnd , mem_ctx ,
& domain_pol ,
1 ,
& lsa_acct_name ,
& user_rids ,
& name_types ) ;
2005-02-28 13:55:13 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " net rpc trustdom del: LookupNames on user %s "
" failed %s \n " ) ,
2008-06-28 04:26:41 +04:00
acct_name , nt_errstr ( result ) ) ;
2005-02-28 13:55:13 +03:00
goto done ;
}
2008-02-01 13:57:53 +03:00
result = rpccli_samr_OpenUser ( pipe_hnd , mem_ctx ,
& domain_pol ,
MAXIMUM_ALLOWED_ACCESS ,
2008-02-08 16:50:04 +03:00
user_rids . ids [ 0 ] ,
2008-02-01 13:57:53 +03:00
& user_pol ) ;
2005-02-28 13:55:13 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " net rpc trustdom del: OpenUser on user %s failed "
" %s \n " ) ,
2008-06-28 04:26:41 +04:00
acct_name , nt_errstr ( result ) ) ;
2005-02-28 13:55:13 +03:00
goto done ;
}
/* append the rid to the domain sid */
2010-01-10 19:39:27 +03:00
if ( ! sid_compose ( & trust_acct_sid , domain_sid , user_rids . ids [ 0 ] ) ) {
2005-02-28 13:55:13 +03:00
goto done ;
}
/* remove the sid */
2008-02-05 13:21:07 +03:00
result = rpccli_samr_RemoveMemberFromForeignDomain ( pipe_hnd , mem_ctx ,
& user_pol ,
& trust_acct_sid ) ;
2005-02-28 13:55:13 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " net rpc trustdom del: RemoveMemberFromForeignDomain "
" on user %s failed %s \n " ) ,
2008-06-28 04:26:41 +04:00
acct_name , nt_errstr ( result ) ) ;
2005-02-28 13:55:13 +03:00
goto done ;
}
/* Delete user */
2008-02-01 03:26:36 +03:00
result = rpccli_samr_DeleteUser ( pipe_hnd , mem_ctx ,
& user_pol ) ;
2005-02-28 13:55:13 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " net rpc trustdom del: DeleteUser on user %s failed "
" %s \n " ) ,
2008-06-28 04:26:41 +04:00
acct_name , nt_errstr ( result ) ) ;
2005-02-28 13:55:13 +03:00
goto done ;
}
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Could not set trust account password: %s \n " ) ,
2008-06-28 04:26:41 +04:00
nt_errstr ( result ) ) ;
goto done ;
2005-02-28 13:55:13 +03:00
}
done :
return result ;
}
2002-03-01 05:56:35 +03:00
/**
* Delete interdomain trust account for a remote domain .
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard argc .
* @ param argv Standard argv without initial components .
2002-03-01 05:56:35 +03:00
*
2008-06-12 12:55:55 +04:00
* @ return Integer status ( 0 means success ) .
2002-03-01 05:56:35 +03:00
* */
2005-02-28 13:55:13 +03:00
2008-05-10 01:22:12 +04:00
static int rpc_trustdom_del ( struct net_context * c , int argc , const char * * argv )
2002-03-01 05:56:35 +03:00
{
2008-05-21 12:27:59 +04:00
if ( argc > 0 & & ! c - > display_usage ) {
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_samr . syntax_id , 0 ,
2008-05-10 01:22:12 +04:00
rpc_trustdom_del_internals , argc , argv ) ;
2005-02-28 13:55:13 +03:00
} else {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net rpc trustdom del <domain> \n " ) ) ;
2005-02-28 13:55:13 +03:00
return - 1 ;
}
2002-03-01 05:56:35 +03:00
}
2008-04-02 14:29:24 +04:00
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_trustdom_get_pdc ( struct net_context * c ,
struct cli_state * cli ,
2008-04-02 14:29:24 +04:00
TALLOC_CTX * mem_ctx ,
const char * domain_name )
{
char * dc_name = NULL ;
const char * buffer = NULL ;
struct rpc_pipe_client * netr ;
NTSTATUS status ;
/* Use NetServerEnum2 */
if ( cli_get_pdc_name ( cli , domain_name , & dc_name ) ) {
SAFE_FREE ( dc_name ) ;
return NT_STATUS_OK ;
}
DEBUG ( 1 , ( " NetServerEnum2 error: Couldn't find primary domain controller \
for domain % s \ n " , domain_name));
/* Try netr_GetDcName */
2008-07-20 13:04:31 +04:00
status = cli_rpc_pipe_open_noauth ( cli , & ndr_table_netlogon . syntax_id ,
& netr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-04-02 14:29:24 +04:00
return status ;
}
status = rpccli_netr_GetDcName ( netr , mem_ctx ,
cli - > desthost ,
domain_name ,
& buffer ,
NULL ) ;
2008-04-20 15:51:46 +04:00
TALLOC_FREE ( netr ) ;
2008-04-02 14:29:24 +04:00
if ( NT_STATUS_IS_OK ( status ) ) {
return status ;
}
DEBUG ( 1 , ( " netr_GetDcName error: Couldn't find primary domain controller \
for domain % s \ n " , domain_name));
return status ;
}
2002-03-01 05:56:35 +03:00
/**
* Establish trust relationship to a trusting domain .
* Interdomain account must already be created on remote PDC .
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard argc .
* @ param argv Standard argv without initial components .
2002-03-01 05:56:35 +03:00
*
2008-06-12 12:55:55 +04:00
* @ return Integer status ( 0 means success ) .
2002-03-01 05:56:35 +03:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_trustdom_establish ( struct net_context * c , int argc ,
const char * * argv )
2002-08-17 18:45:04 +04:00
{
2005-09-30 21:13:37 +04:00
struct cli_state * cli = NULL ;
2007-10-25 01:16:54 +04:00
struct sockaddr_storage server_ss ;
2005-09-30 21:13:37 +04:00
struct rpc_pipe_client * pipe_hnd = NULL ;
2009-03-19 00:49:41 +03:00
struct policy_handle connect_hnd ;
2002-03-01 05:56:35 +03:00
TALLOC_CTX * mem_ctx ;
NTSTATUS nt_status ;
2010-05-21 05:25:01 +04:00
struct dom_sid * domain_sid ;
2007-10-25 01:16:54 +04:00
2002-03-01 05:56:35 +03:00
char * domain_name ;
char * acct_name ;
fstring pdc_name ;
2008-02-08 04:12:30 +03:00
union lsa_PolicyInformation * info = NULL ;
2002-03-01 05:56:35 +03:00
/*
* Connect to \ \ server \ ipc $ as ' our domain ' account with password
*/
2008-05-21 12:27:59 +04:00
if ( argc ! = 1 | | c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net rpc trustdom establish <domain_name> \n " ) ) ;
2002-07-15 14:35:28 +04:00
return - 1 ;
}
2002-03-01 05:56:35 +03:00
domain_name = smb_xstrdup ( argv [ 0 ] ) ;
2003-07-03 23:11:31 +04:00
strupper_m ( domain_name ) ;
2002-11-29 05:58:59 +03:00
/* account name used at first is our domain's name with '$' */
2009-01-01 05:06:57 +03:00
if ( asprintf ( & acct_name , " %s$ " , lp_workgroup ( ) ) = = - 1 ) {
return - 1 ;
}
2003-07-03 23:11:31 +04:00
strupper_m ( acct_name ) ;
2007-10-25 01:16:54 +04:00
2002-08-17 18:45:04 +04:00
/*
* opt_workgroup will be used by connection functions further ,
* hence it should be set to remote domain name instead of ours
*/
2008-05-10 01:22:12 +04:00
if ( c - > opt_workgroup ) {
c - > opt_workgroup = smb_xstrdup ( domain_name ) ;
2002-08-17 18:45:04 +04:00
} ;
2007-10-25 01:16:54 +04:00
2009-07-05 11:21:07 +04:00
c - > opt_user_name = acct_name ;
2002-03-01 05:56:35 +03:00
/* find the domain controller */
2007-10-25 01:16:54 +04:00
if ( ! net_find_pdc ( & server_ss , pdc_name , domain_name ) ) {
2003-08-14 00:53:48 +04:00
DEBUG ( 0 , ( " Couldn't find domain controller for domain %s \n " , domain_name ) ) ;
2002-03-01 05:56:35 +03:00
return - 1 ;
}
/* connect to ipc$ as username/password */
2008-05-10 01:22:12 +04:00
nt_status = connect_to_ipc ( c , & cli , & server_ss , pdc_name ) ;
2002-03-01 05:56:35 +03:00
if ( ! NT_STATUS_EQUAL ( nt_status , NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT ) ) {
/* Is it trusting domain account for sure ? */
DEBUG ( 0 , ( " Couldn't verify trusting domain account. Error was %s \n " ,
2002-03-17 07:36:35 +03:00
nt_errstr ( nt_status ) ) ) ;
2002-03-01 05:56:35 +03:00
return - 1 ;
}
2006-02-08 07:03:47 +03:00
/* store who we connected to */
2006-03-10 00:07:15 +03:00
saf_store ( domain_name , pdc_name ) ;
2007-10-25 01:16:54 +04:00
2002-03-01 05:56:35 +03:00
/*
* Connect to \ \ server \ ipc $ again ( this time anonymously )
*/
2007-10-25 01:16:54 +04:00
2008-05-10 01:22:12 +04:00
nt_status = connect_to_ipc_anonymous ( c , & cli , & server_ss ,
( char * ) pdc_name ) ;
2007-12-04 01:09:48 +03:00
2002-03-01 05:56:35 +03:00
if ( NT_STATUS_IS_ERR ( nt_status ) ) {
DEBUG ( 0 , ( " Couldn't connect to domain %s controller. Error was %s. \n " ,
2002-03-17 07:36:35 +03:00
domain_name , nt_errstr ( nt_status ) ) ) ;
2007-01-20 02:08:20 +03:00
return - 1 ;
2002-03-01 05:56:35 +03:00
}
2005-03-20 14:51:01 +03:00
if ( ! ( mem_ctx = talloc_init ( " establishing trust relationship to "
" domain %s " , domain_name ) ) ) {
2002-03-01 05:56:35 +03:00
DEBUG ( 0 , ( " talloc_init() failed \n " ) ) ;
cli_shutdown ( cli ) ;
return - 1 ;
}
2005-06-09 02:10:34 +04:00
2008-04-02 14:29:24 +04:00
/* Make sure we're talking to a proper server */
2008-05-10 01:22:12 +04:00
nt_status = rpc_trustdom_get_pdc ( c , cli , mem_ctx , domain_name ) ;
2008-04-02 14:29:24 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
cli_shutdown ( cli ) ;
talloc_destroy ( mem_ctx ) ;
return - 1 ;
}
2002-03-01 05:56:35 +03:00
/*
* Call LsaOpenPolicy and LsaQueryInfo
*/
2008-05-08 13:23:38 +04:00
2008-07-20 13:04:31 +04:00
nt_status = cli_rpc_pipe_open_noauth ( cli , & ndr_table_lsarpc . syntax_id ,
& pipe_hnd ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2005-09-30 21:13:37 +04:00
DEBUG ( 0 , ( " Could not initialise lsa pipe. Error was %s \n " , nt_errstr ( nt_status ) ) ) ;
2002-08-17 18:45:04 +04:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2002-08-17 18:45:04 +04:00
return - 1 ;
2002-03-01 05:56:35 +03:00
}
2009-04-15 03:30:12 +04:00
nt_status = rpccli_lsa_open_policy2 ( pipe_hnd , mem_ctx , true , KEY_QUERY_VALUE ,
2002-08-17 18:45:04 +04:00
& connect_hnd ) ;
2002-03-01 05:56:35 +03:00
if ( NT_STATUS_IS_ERR ( nt_status ) ) {
DEBUG ( 0 , ( " Couldn't open policy handle. Error was %s \n " ,
2002-03-17 07:36:35 +03:00
nt_errstr ( nt_status ) ) ) ;
2005-09-30 21:13:37 +04:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2002-03-01 05:56:35 +03:00
return - 1 ;
}
/* Querying info level 5 */
2008-02-08 04:12:30 +03:00
nt_status = rpccli_lsa_QueryInfoPolicy ( pipe_hnd , mem_ctx ,
& connect_hnd ,
LSA_POLICY_INFO_ACCOUNT_DOMAIN ,
& info ) ;
2002-03-01 05:56:35 +03:00
if ( NT_STATUS_IS_ERR ( nt_status ) ) {
DEBUG ( 0 , ( " LSA Query Info failed. Returned error was %s \n " ,
2002-03-17 07:36:35 +03:00
nt_errstr ( nt_status ) ) ) ;
2005-09-30 21:13:37 +04:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2002-03-01 05:56:35 +03:00
return - 1 ;
}
2008-02-08 04:12:30 +03:00
domain_sid = info - > account_domain . sid ;
2002-03-01 05:56:35 +03:00
/* There should be actually query info level 3 (following nt serv behaviour),
but I still don ' t know if it ' s _really_ necessary */
2008-05-08 13:23:38 +04:00
2002-07-15 14:35:28 +04:00
/*
* Store the password in secrets db
*/
2009-07-05 11:21:07 +04:00
if ( ! pdb_set_trusteddom_pw ( domain_name , c - > opt_password , domain_sid ) ) {
2002-07-15 14:35:28 +04:00
DEBUG ( 0 , ( " Storing password for trusted domain failed. \n " ) ) ;
2005-09-30 21:13:37 +04:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2002-07-15 14:35:28 +04:00
return - 1 ;
}
2008-05-08 13:23:38 +04:00
2002-03-01 05:56:35 +03:00
/*
* Close the pipes and clean up
*/
2008-05-08 13:23:38 +04:00
2006-09-21 02:49:02 +04:00
nt_status = rpccli_lsa_Close ( pipe_hnd , mem_ctx , & connect_hnd ) ;
2002-03-01 05:56:35 +03:00
if ( NT_STATUS_IS_ERR ( nt_status ) ) {
DEBUG ( 0 , ( " Couldn't close LSA pipe. Error was %s \n " ,
2002-03-17 07:36:35 +03:00
nt_errstr ( nt_status ) ) ) ;
2005-09-30 21:13:37 +04:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2002-03-01 05:56:35 +03:00
return - 1 ;
}
2005-03-20 14:51:01 +03:00
cli_shutdown ( cli ) ;
2008-05-08 13:23:38 +04:00
2002-07-15 14:35:28 +04:00
talloc_destroy ( mem_ctx ) ;
2008-05-08 13:23:38 +04:00
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Trust to domain %s established \n " ) , domain_name ) ;
2002-03-01 05:56:35 +03:00
return 0 ;
}
/**
2008-06-12 12:55:55 +04:00
* Revoke trust relationship to the remote domain .
2002-03-01 05:56:35 +03:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard argc .
* @ param argv Standard argv without initial components .
2002-03-01 05:56:35 +03:00
*
2008-06-12 12:55:55 +04:00
* @ return Integer status ( 0 means success ) .
2002-03-01 05:56:35 +03:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_trustdom_revoke ( struct net_context * c , int argc ,
const char * * argv )
2002-08-17 18:45:04 +04:00
{
2002-03-01 05:56:35 +03:00
char * domain_name ;
2007-01-16 11:17:26 +03:00
int rc = - 1 ;
2002-03-01 05:56:35 +03:00
2008-05-21 12:27:59 +04:00
if ( argc < 1 | | c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n %s " ,
_ ( " Usage: " ) ,
_ ( " net rpc trustdom revoke <domain_name> \n "
2009-08-04 10:28:50 +04:00
" Revoke trust relationship \n "
" domain_name \t Name of domain to revoke trust \n " ) ) ;
2008-05-21 12:27:59 +04:00
return - 1 ;
}
2008-05-08 13:23:38 +04:00
2002-03-01 05:56:35 +03:00
/* generate upper cased domain name */
domain_name = smb_xstrdup ( argv [ 0 ] ) ;
2003-07-03 23:11:31 +04:00
strupper_m ( domain_name ) ;
2002-03-01 05:56:35 +03:00
/* delete password of the trust */
2007-01-16 11:17:26 +03:00
if ( ! pdb_del_trusteddom_pw ( domain_name ) ) {
2002-03-01 05:56:35 +03:00
DEBUG ( 0 , ( " Failed to revoke relationship to the trusted domain %s \n " ,
domain_name ) ) ;
2007-01-16 11:17:26 +03:00
goto done ;
2002-03-01 05:56:35 +03:00
} ;
2008-05-08 13:23:38 +04:00
2007-01-16 11:17:26 +03:00
rc = 0 ;
done :
SAFE_FREE ( domain_name ) ;
return rc ;
2002-03-01 05:56:35 +03:00
}
2008-05-10 01:22:12 +04:00
static NTSTATUS rpc_query_domain_sid ( struct net_context * c ,
2010-05-21 05:25:01 +04:00
const struct dom_sid * domain_sid ,
2008-05-08 13:23:38 +04:00
const char * domain_name ,
2005-09-30 21:13:37 +04:00
struct cli_state * cli ,
struct rpc_pipe_client * pipe_hnd ,
TALLOC_CTX * mem_ctx ,
int argc ,
const char * * argv )
2002-08-17 18:45:04 +04:00
{
fstring str_sid ;
2009-10-28 16:33:40 +03:00
if ( ! sid_to_fstring ( str_sid , domain_sid ) ) {
return NT_STATUS_UNSUCCESSFUL ;
}
2002-08-17 18:45:04 +04:00
d_printf ( " %s \n " , str_sid ) ;
return NT_STATUS_OK ;
2003-09-22 21:53:59 +04:00
}
2002-08-17 18:45:04 +04:00
2010-05-21 05:25:01 +04:00
static void print_trusted_domain ( struct dom_sid * dom_sid , const char * trusted_dom_name )
2005-06-08 17:59:03 +04:00
{
2009-10-14 02:19:35 +04:00
fstring ascii_sid ;
2005-06-08 17:59:03 +04:00
/* convert sid into ascii string */
2007-12-16 00:47:30 +03:00
sid_to_fstring ( ascii_sid , dom_sid ) ;
2005-06-08 17:59:03 +04:00
2009-10-14 02:19:35 +04:00
d_printf ( " %-20s%s \n " , trusted_dom_name , ascii_sid ) ;
2005-06-08 17:59:03 +04:00
}
2005-09-30 21:13:37 +04:00
static NTSTATUS vampire_trusted_domain ( struct rpc_pipe_client * pipe_hnd ,
2008-05-08 13:23:38 +04:00
TALLOC_CTX * mem_ctx ,
2009-03-19 00:49:41 +03:00
struct policy_handle * pol ,
2010-05-21 05:25:01 +04:00
struct dom_sid dom_sid ,
2005-06-08 17:59:03 +04:00
const char * trusted_dom_name )
{
NTSTATUS nt_status ;
2008-04-09 00:55:52 +04:00
union lsa_TrustedDomainInfo * info = NULL ;
2005-07-28 19:01:29 +04:00
char * cleartextpwd = NULL ;
2009-03-16 13:27:58 +03:00
uint8_t session_key [ 16 ] ;
DATA_BLOB session_key_blob ;
2009-05-13 17:17:46 +04:00
DATA_BLOB data = data_blob_null ;
2005-06-08 17:59:03 +04:00
2008-01-14 17:33:26 +03:00
nt_status = rpccli_lsa_QueryTrustedDomainInfoBySid ( pipe_hnd , mem_ctx ,
pol ,
& dom_sid ,
LSA_TRUSTED_DOMAIN_INFO_PASSWORD ,
& info ) ;
2005-06-08 17:59:03 +04:00
if ( NT_STATUS_IS_ERR ( nt_status ) ) {
DEBUG ( 0 , ( " Could not query trusted domain info. Error was %s \n " ,
nt_errstr ( nt_status ) ) ) ;
goto done ;
}
2008-04-09 00:55:52 +04:00
data = data_blob ( info - > password . password - > data ,
info - > password . password - > length ) ;
2008-01-14 17:33:26 +03:00
2009-03-16 13:27:58 +03:00
if ( ! rpccli_get_pwd_hash ( pipe_hnd , session_key ) ) {
2008-04-21 10:01:51 +04:00
DEBUG ( 0 , ( " Could not retrieve password hash \n " ) ) ;
goto done ;
}
2009-03-16 13:27:58 +03:00
session_key_blob = data_blob_const ( session_key , sizeof ( session_key ) ) ;
cleartextpwd = sess_decrypt_string ( mem_ctx , & data , & session_key_blob ) ;
2005-06-08 17:59:03 +04:00
if ( cleartextpwd = = NULL ) {
DEBUG ( 0 , ( " retrieved NULL password \n " ) ) ;
nt_status = NT_STATUS_UNSUCCESSFUL ;
goto done ;
}
2008-05-08 13:23:38 +04:00
2007-01-16 11:17:26 +03:00
if ( ! pdb_set_trusteddom_pw ( trusted_dom_name , cleartextpwd , & dom_sid ) ) {
2005-06-08 17:59:03 +04:00
DEBUG ( 0 , ( " Storing password for trusted domain failed. \n " ) ) ;
nt_status = NT_STATUS_UNSUCCESSFUL ;
goto done ;
}
2005-12-19 05:22:13 +03:00
# ifdef DEBUG_PASSWORD
2008-04-09 18:14:04 +04:00
DEBUG ( 100 , ( " successfully vampired trusted domain [%s], sid: [%s], "
2007-12-15 23:11:36 +03:00
" password: [%s] \n " , trusted_dom_name ,
sid_string_dbg ( & dom_sid ) , cleartextpwd ) ) ;
2005-12-19 05:22:13 +03:00
# endif
2005-06-08 17:59:03 +04:00
done :
SAFE_FREE ( cleartextpwd ) ;
data_blob_free ( & data ) ;
return nt_status ;
}
2008-05-10 01:22:12 +04:00
static int rpc_trustdom_vampire ( struct net_context * c , int argc ,
const char * * argv )
2005-06-08 17:59:03 +04:00
{
/* common variables */
TALLOC_CTX * mem_ctx ;
2005-09-30 21:13:37 +04:00
struct cli_state * cli = NULL ;
struct rpc_pipe_client * pipe_hnd = NULL ;
2005-06-08 17:59:03 +04:00
NTSTATUS nt_status ;
const char * domain_name = NULL ;
2010-05-21 05:25:01 +04:00
struct dom_sid * queried_dom_sid ;
2009-03-19 00:49:41 +03:00
struct policy_handle connect_hnd ;
2008-02-08 04:12:30 +03:00
union lsa_PolicyInformation * info = NULL ;
2005-06-08 17:59:03 +04:00
/* trusted domains listing variables */
2008-02-13 02:25:40 +03:00
unsigned int enum_ctx = 0 ;
2005-06-08 17:59:03 +04:00
int i ;
2008-02-13 02:25:40 +03:00
struct lsa_DomainList dom_list ;
2005-06-08 17:59:03 +04:00
fstring pdc_name ;
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc trustdom vampire \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Vampire trust relationship from remote server " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2005-06-08 17:59:03 +04:00
/*
* Listing trusted domains ( stored in secrets . tdb , if local )
*/
mem_ctx = talloc_init ( " trust relationships vampire " ) ;
/*
* set domain and pdc name to local samba server ( default )
* or to remote one given in command line
*/
2008-05-10 01:22:12 +04:00
if ( StrCaseCmp ( c - > opt_workgroup , lp_workgroup ( ) ) ) {
domain_name = c - > opt_workgroup ;
c - > opt_target_workgroup = c - > opt_workgroup ;
2005-06-08 17:59:03 +04:00
} else {
fstrcpy ( pdc_name , global_myname ( ) ) ;
domain_name = talloc_strdup ( mem_ctx , lp_workgroup ( ) ) ;
2008-05-10 01:22:12 +04:00
c - > opt_target_workgroup = domain_name ;
2005-06-08 17:59:03 +04:00
} ;
/* open \PIPE\lsarpc and open policy handle */
2008-05-10 01:22:12 +04:00
nt_status = net_make_ipc_connection ( c , NET_FLAGS_PDC , & cli ) ;
2007-09-17 19:11:20 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
DEBUG ( 0 , ( " Couldn't connect to domain controller: %s \n " ,
nt_errstr ( nt_status ) ) ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2005-06-08 17:59:03 +04:00
return - 1 ;
} ;
2008-07-20 13:04:31 +04:00
nt_status = cli_rpc_pipe_open_noauth ( cli , & ndr_table_lsarpc . syntax_id ,
& pipe_hnd ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2005-09-30 21:13:37 +04:00
DEBUG ( 0 , ( " Could not initialise lsa pipe. Error was %s \n " ,
nt_errstr ( nt_status ) ) ) ;
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2005-06-08 17:59:03 +04:00
return - 1 ;
} ;
2009-04-15 03:30:12 +04:00
nt_status = rpccli_lsa_open_policy2 ( pipe_hnd , mem_ctx , false , KEY_QUERY_VALUE ,
2005-06-08 17:59:03 +04:00
& connect_hnd ) ;
if ( NT_STATUS_IS_ERR ( nt_status ) ) {
DEBUG ( 0 , ( " Couldn't open policy handle. Error was %s \n " ,
nt_errstr ( nt_status ) ) ) ;
2005-09-30 21:13:37 +04:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2005-06-08 17:59:03 +04:00
return - 1 ;
} ;
/* query info level 5 to obtain sid of a domain being queried */
2008-02-08 04:12:30 +03:00
nt_status = rpccli_lsa_QueryInfoPolicy ( pipe_hnd , mem_ctx ,
& connect_hnd ,
LSA_POLICY_INFO_ACCOUNT_DOMAIN ,
& info ) ;
2005-06-08 17:59:03 +04:00
if ( NT_STATUS_IS_ERR ( nt_status ) ) {
DEBUG ( 0 , ( " LSA Query Info failed. Returned error was %s \n " ,
nt_errstr ( nt_status ) ) ) ;
2005-09-30 21:13:37 +04:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2005-06-08 17:59:03 +04:00
return - 1 ;
}
2008-02-08 04:12:30 +03:00
queried_dom_sid = info - > account_domain . sid ;
2005-06-08 17:59:03 +04:00
/*
* Keep calling LsaEnumTrustdom over opened pipe until
* the end of enumeration is reached
*/
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Vampire trusted domains: \n \n " ) ) ;
2005-06-08 17:59:03 +04:00
do {
2008-02-13 02:25:40 +03:00
nt_status = rpccli_lsa_EnumTrustDom ( pipe_hnd , mem_ctx ,
& connect_hnd ,
& enum_ctx ,
& dom_list ,
( uint32_t ) - 1 ) ;
2005-06-08 17:59:03 +04:00
if ( NT_STATUS_IS_ERR ( nt_status ) ) {
DEBUG ( 0 , ( " Couldn't enumerate trusted domains. Error was %s \n " ,
nt_errstr ( nt_status ) ) ) ;
2005-09-30 21:13:37 +04:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2005-06-08 17:59:03 +04:00
return - 1 ;
} ;
2008-02-13 02:25:40 +03:00
for ( i = 0 ; i < dom_list . count ; i + + ) {
print_trusted_domain ( dom_list . domains [ i ] . sid ,
dom_list . domains [ i ] . name . string ) ;
2005-06-08 17:59:03 +04:00
2005-09-30 21:13:37 +04:00
nt_status = vampire_trusted_domain ( pipe_hnd , mem_ctx , & connect_hnd ,
2008-02-13 02:25:40 +03:00
* dom_list . domains [ i ] . sid ,
dom_list . domains [ i ] . name . string ) ;
2005-09-30 21:13:37 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2005-06-08 17:59:03 +04:00
return - 1 ;
2005-09-30 21:13:37 +04:00
}
2005-06-08 17:59:03 +04:00
} ;
/*
* in case of no trusted domains say something rather
* than just display blank line
*/
2009-08-04 10:28:50 +04:00
if ( ! dom_list . count ) d_printf ( _ ( " none \n " ) ) ;
2005-06-08 17:59:03 +04:00
} while ( NT_STATUS_EQUAL ( nt_status , STATUS_MORE_ENTRIES ) ) ;
/* close this connection before doing next one */
2006-09-21 02:49:02 +04:00
nt_status = rpccli_lsa_Close ( pipe_hnd , mem_ctx , & connect_hnd ) ;
2005-06-08 17:59:03 +04:00
if ( NT_STATUS_IS_ERR ( nt_status ) ) {
DEBUG ( 0 , ( " Couldn't properly close lsa policy handle. Error was %s \n " ,
nt_errstr ( nt_status ) ) ) ;
2005-09-30 21:13:37 +04:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2005-06-08 17:59:03 +04:00
return - 1 ;
} ;
/* close lsarpc pipe and connection to IPC$ */
cli_shutdown ( cli ) ;
2008-05-08 13:23:38 +04:00
talloc_destroy ( mem_ctx ) ;
2005-06-08 17:59:03 +04:00
return 0 ;
}
2002-08-17 18:45:04 +04:00
2008-05-10 01:22:12 +04:00
static int rpc_trustdom_list ( struct net_context * c , int argc , const char * * argv )
2002-08-17 18:45:04 +04:00
{
/* common variables */
TALLOC_CTX * mem_ctx ;
2005-09-30 21:13:37 +04:00
struct cli_state * cli = NULL , * remote_cli = NULL ;
struct rpc_pipe_client * pipe_hnd = NULL ;
2002-08-17 18:45:04 +04:00
NTSTATUS nt_status ;
2003-01-03 11:28:12 +03:00
const char * domain_name = NULL ;
2010-05-21 05:25:01 +04:00
struct dom_sid * queried_dom_sid ;
2002-08-17 18:45:04 +04:00
int ascii_dom_name_len ;
2009-03-19 00:49:41 +03:00
struct policy_handle connect_hnd ;
2008-02-08 04:12:30 +03:00
union lsa_PolicyInformation * info = NULL ;
2002-08-17 18:45:04 +04:00
/* trusted domains listing variables */
2003-08-15 08:42:05 +04:00
unsigned int num_domains , enum_ctx = 0 ;
2009-10-13 17:56:00 +04:00
int i ;
2008-02-13 02:25:40 +03:00
struct lsa_DomainList dom_list ;
2004-01-08 11:19:18 +03:00
fstring pdc_name ;
2009-11-23 00:38:45 +03:00
bool found_domain ;
2008-02-08 04:12:30 +03:00
2002-08-17 18:45:04 +04:00
/* trusting domains listing variables */
2009-03-19 00:49:41 +03:00
struct policy_handle domain_hnd ;
2008-02-12 13:36:33 +03:00
struct samr_SamArray * trusts = NULL ;
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc trustdom list \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " List incoming and outgoing trust relationships " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2002-08-17 18:45:04 +04:00
/*
* Listing trusted domains ( stored in secrets . tdb , if local )
*/
2002-12-20 23:21:31 +03:00
mem_ctx = talloc_init ( " trust relationships listing " ) ;
2002-08-17 18:45:04 +04:00
/*
* set domain and pdc name to local samba server ( default )
* or to remote one given in command line
*/
2008-05-08 13:23:38 +04:00
2008-05-10 01:22:12 +04:00
if ( StrCaseCmp ( c - > opt_workgroup , lp_workgroup ( ) ) ) {
domain_name = c - > opt_workgroup ;
c - > opt_target_workgroup = c - > opt_workgroup ;
2002-08-17 18:45:04 +04:00
} else {
2003-01-03 11:28:12 +03:00
fstrcpy ( pdc_name , global_myname ( ) ) ;
2002-08-17 18:45:04 +04:00
domain_name = talloc_strdup ( mem_ctx , lp_workgroup ( ) ) ;
2008-05-10 01:22:12 +04:00
c - > opt_target_workgroup = domain_name ;
2002-08-17 18:45:04 +04:00
} ;
/* open \PIPE\lsarpc and open policy handle */
2008-05-10 01:22:12 +04:00
nt_status = net_make_ipc_connection ( c , NET_FLAGS_PDC , & cli ) ;
2007-09-17 19:11:20 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
DEBUG ( 0 , ( " Couldn't connect to domain controller: %s \n " ,
nt_errstr ( nt_status ) ) ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2002-08-17 18:45:04 +04:00
return - 1 ;
} ;
2008-07-20 13:04:31 +04:00
nt_status = cli_rpc_pipe_open_noauth ( cli , & ndr_table_lsarpc . syntax_id ,
& pipe_hnd ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2005-09-30 21:13:37 +04:00
DEBUG ( 0 , ( " Could not initialise lsa pipe. Error was %s \n " ,
nt_errstr ( nt_status ) ) ) ;
2007-03-08 01:29:21 +03:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2002-08-17 18:45:04 +04:00
return - 1 ;
} ;
2009-04-15 03:30:12 +04:00
nt_status = rpccli_lsa_open_policy2 ( pipe_hnd , mem_ctx , false , KEY_QUERY_VALUE ,
2002-08-17 18:45:04 +04:00
& connect_hnd ) ;
if ( NT_STATUS_IS_ERR ( nt_status ) ) {
DEBUG ( 0 , ( " Couldn't open policy handle. Error was %s \n " ,
nt_errstr ( nt_status ) ) ) ;
2007-03-08 01:29:21 +03:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2002-08-17 18:45:04 +04:00
return - 1 ;
} ;
/* query info level 5 to obtain sid of a domain being queried */
2008-02-08 04:12:30 +03:00
nt_status = rpccli_lsa_QueryInfoPolicy ( pipe_hnd , mem_ctx ,
& connect_hnd ,
LSA_POLICY_INFO_ACCOUNT_DOMAIN ,
& info ) ;
2003-04-14 08:00:15 +04:00
2002-08-17 18:45:04 +04:00
if ( NT_STATUS_IS_ERR ( nt_status ) ) {
DEBUG ( 0 , ( " LSA Query Info failed. Returned error was %s \n " ,
nt_errstr ( nt_status ) ) ) ;
2007-03-08 01:29:21 +03:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2002-08-17 18:45:04 +04:00
return - 1 ;
}
2008-02-08 04:12:30 +03:00
queried_dom_sid = info - > account_domain . sid ;
2002-08-17 18:45:04 +04:00
/*
* Keep calling LsaEnumTrustdom over opened pipe until
* the end of enumeration is reached
*/
2009-11-23 00:38:45 +03:00
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Trusted domains list: \n \n " ) ) ;
2002-08-17 18:45:04 +04:00
2009-11-23 00:38:45 +03:00
found_domain = false ;
2002-08-17 18:45:04 +04:00
do {
2008-02-13 02:25:40 +03:00
nt_status = rpccli_lsa_EnumTrustDom ( pipe_hnd , mem_ctx ,
& connect_hnd ,
& enum_ctx ,
& dom_list ,
( uint32_t ) - 1 ) ;
2002-08-17 18:45:04 +04:00
if ( NT_STATUS_IS_ERR ( nt_status ) ) {
DEBUG ( 0 , ( " Couldn't enumerate trusted domains. Error was %s \n " ,
nt_errstr ( nt_status ) ) ) ;
2007-03-08 01:29:21 +03:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2002-08-17 18:45:04 +04:00
return - 1 ;
} ;
2008-02-13 02:25:40 +03:00
for ( i = 0 ; i < dom_list . count ; i + + ) {
print_trusted_domain ( dom_list . domains [ i ] . sid ,
dom_list . domains [ i ] . name . string ) ;
2009-11-23 00:38:45 +03:00
found_domain = true ;
2002-08-17 18:45:04 +04:00
} ;
2008-02-13 02:25:40 +03:00
2002-08-17 18:45:04 +04:00
} while ( NT_STATUS_EQUAL ( nt_status , STATUS_MORE_ENTRIES ) ) ;
2009-11-23 00:38:45 +03:00
/*
* in case of no trusted domains say something rather
* than just display blank line
*/
if ( ! found_domain ) {
d_printf ( _ ( " none \n " ) ) ;
}
2002-08-17 18:45:04 +04:00
/* close this connection before doing next one */
2006-09-21 02:49:02 +04:00
nt_status = rpccli_lsa_Close ( pipe_hnd , mem_ctx , & connect_hnd ) ;
2002-08-17 18:45:04 +04:00
if ( NT_STATUS_IS_ERR ( nt_status ) ) {
DEBUG ( 0 , ( " Couldn't properly close lsa policy handle. Error was %s \n " ,
nt_errstr ( nt_status ) ) ) ;
2007-03-08 01:29:21 +03:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2002-08-17 18:45:04 +04:00
return - 1 ;
} ;
2008-04-20 15:51:46 +04:00
TALLOC_FREE ( pipe_hnd ) ;
2002-08-17 18:45:04 +04:00
/*
* Listing trusting domains ( stored in passdb backend , if local )
*/
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " \n Trusting domains list: \n \n " ) ) ;
2002-08-17 18:45:04 +04:00
/*
* Open \ PIPE \ samr and get needed policy handles
*/
2008-07-20 13:04:31 +04:00
nt_status = cli_rpc_pipe_open_noauth ( cli , & ndr_table_samr . syntax_id ,
& pipe_hnd ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2005-09-30 21:13:37 +04:00
DEBUG ( 0 , ( " Could not initialise samr pipe. Error was %s \n " , nt_errstr ( nt_status ) ) ) ;
2007-03-08 01:29:21 +03:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2002-08-17 18:45:04 +04:00
return - 1 ;
} ;
2008-02-04 21:43:07 +03:00
/* SamrConnect2 */
nt_status = rpccli_samr_Connect2 ( pipe_hnd , mem_ctx ,
2008-04-19 23:56:43 +04:00
pipe_hnd - > desthost ,
2009-04-16 02:40:00 +04:00
SAMR_ACCESS_LOOKUP_DOMAIN ,
2008-02-04 21:43:07 +03:00
& connect_hnd ) ;
2002-08-17 18:45:04 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
DEBUG ( 0 , ( " Couldn't open SAMR policy handle. Error was %s \n " ,
nt_errstr ( nt_status ) ) ) ;
2007-03-08 01:29:21 +03:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2002-08-17 18:45:04 +04:00
return - 1 ;
} ;
2008-02-01 13:12:05 +03:00
2002-08-17 18:45:04 +04:00
/* SamrOpenDomain - we have to open domain policy handle in order to be
able to enumerate accounts */
2008-02-01 13:12:05 +03:00
nt_status = rpccli_samr_OpenDomain ( pipe_hnd , mem_ctx ,
& connect_hnd ,
2008-10-23 21:39:14 +04:00
SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS ,
2008-02-01 13:12:05 +03:00
queried_dom_sid ,
& domain_hnd ) ;
2002-08-17 18:45:04 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
DEBUG ( 0 , ( " Couldn't open domain object. Error was %s \n " ,
nt_errstr ( nt_status ) ) ) ;
2007-03-08 01:29:21 +03:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2002-08-17 18:45:04 +04:00
return - 1 ;
} ;
2008-05-08 13:23:38 +04:00
2002-08-17 18:45:04 +04:00
/*
* perform actual enumeration
*/
2008-05-08 13:23:38 +04:00
2009-11-23 00:38:45 +03:00
found_domain = false ;
2002-08-17 18:45:04 +04:00
enum_ctx = 0 ; /* reset enumeration context from last enumeration */
do {
2008-02-12 13:36:33 +03:00
nt_status = rpccli_samr_EnumDomainUsers ( pipe_hnd , mem_ctx ,
& domain_hnd ,
& enum_ctx ,
ACB_DOMTRUST ,
& trusts ,
0xffff ,
& num_domains ) ;
2002-08-17 18:45:04 +04:00
if ( NT_STATUS_IS_ERR ( nt_status ) ) {
DEBUG ( 0 , ( " Couldn't enumerate accounts. Error was: %s \n " ,
nt_errstr ( nt_status ) ) ) ;
2007-03-08 01:29:21 +03:00
cli_shutdown ( cli ) ;
2007-03-01 05:43:33 +03:00
talloc_destroy ( mem_ctx ) ;
2002-08-17 18:45:04 +04:00
return - 1 ;
} ;
2008-02-12 13:36:33 +03:00
2002-08-17 18:45:04 +04:00
for ( i = 0 ; i < num_domains ; i + + ) {
2008-02-12 13:36:33 +03:00
char * str = CONST_DISCARD ( char * , trusts - > entries [ i ] . name . string ) ;
2009-11-23 00:38:45 +03:00
found_domain = true ;
2002-08-17 18:45:04 +04:00
/*
* get each single domain ' s sid ( do we _really_ need this ? ) :
* 1 ) connect to domain ' s pdc
* 2 ) query the pdc for domain ' s sid
*/
/* get rid of '$' tail */
2008-02-12 13:36:33 +03:00
ascii_dom_name_len = strlen ( str ) ;
2002-08-17 18:45:04 +04:00
if ( ascii_dom_name_len & & ascii_dom_name_len < FSTRING_LEN )
2008-02-12 13:36:33 +03:00
str [ ascii_dom_name_len - 1 ] = ' \0 ' ;
2002-08-17 18:45:04 +04:00
/* set opt_* variables to remote domain */
2008-02-12 13:36:33 +03:00
strupper_m ( str ) ;
2008-05-10 01:22:12 +04:00
c - > opt_workgroup = talloc_strdup ( mem_ctx , str ) ;
c - > opt_target_workgroup = c - > opt_workgroup ;
2008-02-12 13:36:33 +03:00
2009-10-13 17:56:00 +04:00
d_printf ( " %-20s " , str ) ;
2008-02-12 13:36:33 +03:00
2002-08-17 18:45:04 +04:00
/* connect to remote domain controller */
2008-05-10 01:22:12 +04:00
nt_status = net_make_ipc_connection ( c ,
2007-09-17 19:11:20 +04:00
NET_FLAGS_PDC | NET_FLAGS_ANONYMOUS ,
& remote_cli ) ;
if ( NT_STATUS_IS_OK ( nt_status ) ) {
2002-08-17 18:45:04 +04:00
/* query for domain's sid */
2008-07-20 20:36:31 +04:00
if ( run_rpc_command (
c , remote_cli ,
2009-11-08 21:37:26 +03:00
& ndr_table_lsarpc . syntax_id , 0 ,
2008-07-20 20:36:31 +04:00
rpc_query_domain_sid , argc ,
argv ) )
2009-10-28 16:33:40 +03:00
d_printf ( _ ( " strange - couldn't get domain's sid \n " ) ) ;
2002-08-17 18:45:04 +04:00
cli_shutdown ( remote_cli ) ;
2008-05-08 13:23:38 +04:00
2002-08-17 18:45:04 +04:00
} else {
2009-08-04 10:28:50 +04:00
d_fprintf ( stderr , _ ( " domain controller is not "
" responding: %s \n " ) ,
2007-09-17 19:11:20 +04:00
nt_errstr ( nt_status ) ) ;
2009-10-28 16:33:40 +03:00
d_printf ( _ ( " couldn't get domain's sid \n " ) ) ;
2009-11-23 00:38:45 +03:00
}
}
2008-05-08 13:23:38 +04:00
2002-08-17 18:45:04 +04:00
} while ( NT_STATUS_EQUAL ( nt_status , STATUS_MORE_ENTRIES ) ) ;
2009-11-23 00:38:45 +03:00
if ( ! found_domain ) {
d_printf ( " none \n " ) ;
}
2002-08-17 18:45:04 +04:00
/* close opened samr and domain policy handles */
2008-01-30 14:39:20 +03:00
nt_status = rpccli_samr_Close ( pipe_hnd , mem_ctx , & domain_hnd ) ;
2002-08-17 18:45:04 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
DEBUG ( 0 , ( " Couldn't properly close domain policy handle for domain %s \n " , domain_name ) ) ;
} ;
2008-05-08 13:23:38 +04:00
2008-01-30 14:39:20 +03:00
nt_status = rpccli_samr_Close ( pipe_hnd , mem_ctx , & connect_hnd ) ;
2002-08-17 18:45:04 +04:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
DEBUG ( 0 , ( " Couldn't properly close samr policy handle for domain %s \n " , domain_name ) ) ;
} ;
2008-05-08 13:23:38 +04:00
2002-08-17 18:45:04 +04:00
/* close samr pipe and connection to IPC$ */
cli_shutdown ( cli ) ;
2008-05-08 13:23:38 +04:00
talloc_destroy ( mem_ctx ) ;
2002-08-17 18:45:04 +04:00
return 0 ;
}
2002-03-01 05:56:35 +03:00
/**
2008-06-12 12:55:55 +04:00
* Entrypoint for ' net rpc trustdom ' code .
2002-03-01 05:56:35 +03:00
*
2008-06-12 12:55:55 +04:00
* @ param argc Standard argc .
* @ param argv Standard argv without initial components .
2002-03-01 05:56:35 +03:00
*
2008-06-12 12:55:55 +04:00
* @ return Integer status ( 0 means success ) .
2002-03-01 05:56:35 +03:00
*/
2008-05-10 01:22:12 +04:00
static int rpc_trustdom ( struct net_context * c , int argc , const char * * argv )
2002-03-01 05:56:35 +03:00
{
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 12:27:59 +04:00
{
" add " ,
rpc_trustdom_add ,
NET_TRANSPORT_RPC ,
2009-10-13 00:37:34 +04:00
N_ ( " Add trusting domain's account " ) ,
2009-08-04 10:28:50 +04:00
N_ ( " net rpc trustdom add \n "
2009-10-13 00:37:34 +04:00
" Add trusting domain's account " )
2008-05-21 12:27:59 +04:00
} ,
{
" del " ,
rpc_trustdom_del ,
NET_TRANSPORT_RPC ,
2009-10-13 00:37:34 +04:00
N_ ( " Remove trusting domain's account " ) ,
2009-08-04 10:28:50 +04:00
N_ ( " net rpc trustdom del \n "
2009-10-13 00:37:34 +04:00
" Remove trusting domain's account " )
2008-05-21 12:27:59 +04:00
} ,
{
" establish " ,
rpc_trustdom_establish ,
NET_TRANSPORT_RPC ,
2009-10-13 00:37:34 +04:00
N_ ( " Establish outgoing trust relationship " ) ,
2009-08-04 10:28:50 +04:00
N_ ( " net rpc trustdom establish \n "
2009-10-13 00:37:34 +04:00
" Establish outgoing trust relationship " )
2008-05-21 12:27:59 +04:00
} ,
{
" revoke " ,
rpc_trustdom_revoke ,
NET_TRANSPORT_RPC ,
2009-10-13 00:37:34 +04:00
N_ ( " Revoke outgoing trust relationship " ) ,
2009-08-04 10:28:50 +04:00
N_ ( " net rpc trustdom revoke \n "
2009-10-13 00:37:34 +04:00
" Revoke outgoing trust relationship " )
2008-05-21 12:27:59 +04:00
} ,
{
" list " ,
rpc_trustdom_list ,
NET_TRANSPORT_RPC ,
2009-10-13 00:37:34 +04:00
N_ ( " List in- and outgoing domain trusts " ) ,
2009-08-04 10:28:50 +04:00
N_ ( " net rpc trustdom list \n "
2009-10-13 00:37:34 +04:00
" List in- and outgoing domain trusts " )
2008-05-21 12:27:59 +04:00
} ,
{
" vampire " ,
rpc_trustdom_vampire ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Vampire trusts from remote server " ) ,
N_ ( " net rpc trustdom vampire \n "
" Vampire trusts from remote server " )
2008-05-21 12:27:59 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2002-03-01 05:56:35 +03:00
} ;
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rpc trustdom " , func ) ;
2002-03-01 05:56:35 +03:00
}
2002-04-05 05:36:28 +04:00
/**
* Check if a server will take rpc commands
* @ param flags Type of server to connect to ( PDC , DMB , localhost )
* if the host is not explicitly specified
2007-10-19 04:40:25 +04:00
* @ return bool ( true means rpc supported )
2002-04-05 05:36:28 +04:00
*/
2008-05-10 01:22:12 +04:00
bool net_rpc_check ( struct net_context * c , unsigned flags )
2002-04-05 05:36:28 +04:00
{
2006-07-11 22:01:26 +04:00
struct cli_state * cli ;
2008-05-12 13:53:23 +04:00
bool ret = false ;
2007-10-25 01:16:54 +04:00
struct sockaddr_storage server_ss ;
2002-04-05 05:36:28 +04:00
char * server_name = NULL ;
2007-06-20 21:38:42 +04:00
NTSTATUS status ;
2002-04-05 05:36:28 +04:00
/* flags (i.e. server type) may depend on command */
2008-05-10 01:22:12 +04:00
if ( ! net_find_server ( c , NULL , flags , & server_ss , & server_name ) )
2008-05-12 13:53:23 +04:00
return false ;
2002-04-05 05:36:28 +04:00
2006-07-11 22:01:26 +04:00
if ( ( cli = cli_initialise ( ) ) = = NULL ) {
2008-05-12 13:53:23 +04:00
return false ;
2006-07-11 22:01:26 +04:00
}
2002-04-05 05:36:28 +04:00
2007-10-25 01:16:54 +04:00
status = cli_connect ( cli , server_name , & server_ss ) ;
2007-06-20 21:38:42 +04:00
if ( ! NT_STATUS_IS_OK ( status ) )
2002-04-05 05:36:28 +04:00
goto done ;
2007-10-25 01:16:54 +04:00
if ( ! attempt_netbios_session_request ( & cli , global_myname ( ) ,
server_name , & server_ss ) )
2002-04-05 05:36:28 +04:00
goto done ;
2008-09-11 20:57:49 +04:00
status = cli_negprot ( cli ) ;
if ( ! NT_STATUS_IS_OK ( status ) )
2002-04-05 05:36:28 +04:00
goto done ;
2006-07-11 22:01:26 +04:00
if ( cli - > protocol < PROTOCOL_NT1 )
2002-04-05 05:36:28 +04:00
goto done ;
2008-05-12 13:53:23 +04:00
ret = true ;
2002-04-05 05:36:28 +04:00
done :
2006-07-11 22:01:26 +04:00
cli_shutdown ( cli ) ;
2002-04-05 05:36:28 +04:00
return ret ;
}
2004-02-08 13:59:09 +03:00
/* dump sam database via samsync rpc calls */
2008-05-10 01:22:12 +04:00
static int rpc_samdump ( struct net_context * c , int argc , const char * * argv ) {
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc samdump \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Dump remote SAM database " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_netlogon . syntax_id ,
2008-07-20 20:36:31 +04:00
NET_FLAGS_ANONYMOUS ,
2008-05-10 01:22:12 +04:00
rpc_samdump_internals , argc , argv ) ;
2004-02-08 13:59:09 +03:00
}
2002-04-05 05:36:28 +04:00
2004-02-08 13:59:09 +03:00
/* syncronise sam database via samsync rpc calls */
2008-06-13 23:46:59 +04:00
static int rpc_vampire ( struct net_context * c , int argc , const char * * argv )
{
struct functable func [ ] = {
{
" ldif " ,
rpc_vampire_ldif ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Dump remote SAM database to ldif " ) ,
N_ ( " net rpc vampire ldif \n "
" Dump remote SAM database to LDIF file or "
" stdout " )
2008-06-13 23:46:59 +04:00
} ,
2008-06-18 14:52:00 +04:00
{
" keytab " ,
rpc_vampire_keytab ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Dump remote SAM database to Kerberos Keytab " ) ,
N_ ( " net rpc vampire keytab \n "
" Dump remote SAM database to Kerberos keytab "
" file " )
2008-06-18 14:52:00 +04:00
} ,
2008-11-18 15:25:50 +03:00
{
" passdb " ,
rpc_vampire_passdb ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Dump remote SAM database to passdb " ) ,
N_ ( " net rpc vampire passdb \n "
" Dump remote SAM database to passdb " )
2008-11-18 15:25:50 +03:00
} ,
2008-06-18 14:52:00 +04:00
2008-06-13 23:46:59 +04:00
{ NULL , NULL , 0 , NULL , NULL }
} ;
if ( argc = = 0 ) {
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc vampire \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Vampire remote SAM database " ) ) ;
2008-06-13 23:46:59 +04:00
return 0 ;
}
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_netlogon . syntax_id ,
2008-07-20 20:36:31 +04:00
NET_FLAGS_ANONYMOUS ,
2008-06-13 23:46:59 +04:00
rpc_vampire_internals ,
argc , argv ) ;
2008-05-21 12:27:59 +04:00
}
2008-06-13 23:46:59 +04:00
return net_run_function ( c , argc , argv , " net rpc vampire " , func ) ;
2004-02-08 13:59:09 +03:00
}
2004-08-10 18:27:17 +04:00
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Migrate everything from a print server .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-08-10 18:27:17 +04:00
*
* The order is important !
2008-06-12 12:55:55 +04:00
* To successfully add drivers the print queues have to exist !
* Applying ACLs should be the last step , because you ' re easily locked out .
2004-08-10 18:27:17 +04:00
*
* */
2008-05-10 01:22:12 +04:00
static int rpc_printer_migrate_all ( struct net_context * c , int argc ,
const char * * argv )
2004-08-10 18:27:17 +04:00
{
int ret ;
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc printer migrate all \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Migrate everything from a print server " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2008-05-10 01:22:12 +04:00
if ( ! c - > opt_host ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " no server to migrate \n " ) ) ;
2004-08-21 00:13:05 +04:00
return - 1 ;
}
2009-11-08 21:37:26 +03:00
ret = run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
2008-05-10 01:22:12 +04:00
rpc_printer_migrate_printers_internals , argc ,
argv ) ;
2004-08-10 18:27:17 +04:00
if ( ret )
return ret ;
2009-11-08 21:37:26 +03:00
ret = run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
2008-05-10 01:22:12 +04:00
rpc_printer_migrate_drivers_internals , argc ,
argv ) ;
2004-08-10 18:27:17 +04:00
if ( ret )
return ret ;
2009-11-08 21:37:26 +03:00
ret = run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
2008-05-10 01:22:12 +04:00
rpc_printer_migrate_forms_internals , argc , argv ) ;
2004-08-10 18:27:17 +04:00
if ( ret )
return ret ;
2009-11-08 21:37:26 +03:00
ret = run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
2008-05-10 01:22:12 +04:00
rpc_printer_migrate_settings_internals , argc ,
argv ) ;
2004-08-10 18:27:17 +04:00
if ( ret )
return ret ;
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
2008-05-10 01:22:12 +04:00
rpc_printer_migrate_security_internals , argc ,
argv ) ;
2004-08-10 18:27:17 +04:00
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Migrate print drivers from a print server .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-08-10 18:27:17 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_printer_migrate_drivers ( struct net_context * c , int argc ,
const char * * argv )
2004-08-10 18:27:17 +04:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc printer migrate drivers \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Migrate print-drivers from a print-server " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2008-05-10 01:22:12 +04:00
if ( ! c - > opt_host ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " no server to migrate \n " ) ) ;
2004-08-21 00:13:05 +04:00
return - 1 ;
}
2004-08-10 18:27:17 +04:00
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
2004-08-10 18:27:17 +04:00
rpc_printer_migrate_drivers_internals ,
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Migrate print - forms from a print - server .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-08-10 18:27:17 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_printer_migrate_forms ( struct net_context * c , int argc ,
const char * * argv )
2004-08-10 18:27:17 +04:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc printer migrate forms \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Migrate print-forms from a print-server " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2008-05-10 01:22:12 +04:00
if ( ! c - > opt_host ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " no server to migrate \n " ) ) ;
2004-08-21 00:13:05 +04:00
return - 1 ;
}
2004-08-10 18:27:17 +04:00
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
2004-08-10 18:27:17 +04:00
rpc_printer_migrate_forms_internals ,
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Migrate printers from a print - server .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-08-10 18:27:17 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_printer_migrate_printers ( struct net_context * c , int argc ,
const char * * argv )
2004-08-10 18:27:17 +04:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc printer migrate printers \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Migrate printers from a print-server " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2008-05-10 01:22:12 +04:00
if ( ! c - > opt_host ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " no server to migrate \n " ) ) ;
2004-08-21 00:13:05 +04:00
return - 1 ;
}
2004-08-10 18:27:17 +04:00
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
2004-08-10 18:27:17 +04:00
rpc_printer_migrate_printers_internals ,
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2004-08-10 18:27:17 +04:00
* Migrate printer - ACLs from a print - server
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-08-10 18:27:17 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_printer_migrate_security ( struct net_context * c , int argc ,
const char * * argv )
2004-08-10 18:27:17 +04:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc printer migrate security \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Migrate printer-ACLs from a print-server " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2008-05-10 01:22:12 +04:00
if ( ! c - > opt_host ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " no server to migrate \n " ) ) ;
2004-08-21 00:13:05 +04:00
return - 1 ;
}
2004-08-10 18:27:17 +04:00
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
2004-08-10 18:27:17 +04:00
rpc_printer_migrate_security_internals ,
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Migrate printer - settings from a print - server .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-08-10 18:27:17 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_printer_migrate_settings ( struct net_context * c , int argc ,
const char * * argv )
2004-08-10 18:27:17 +04:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc printer migrate settings \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Migrate printer-settings from a "
" print-server " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2008-05-10 01:22:12 +04:00
if ( ! c - > opt_host ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " no server to migrate \n " ) ) ;
2004-08-21 00:13:05 +04:00
return - 1 ;
}
2004-08-10 18:27:17 +04:00
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
2004-08-10 18:27:17 +04:00
rpc_printer_migrate_settings_internals ,
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2004-08-10 18:27:17 +04:00
* ' net rpc printer ' entrypoint .
2008-05-10 01:22:12 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-08-10 18:27:17 +04:00
* */
2008-05-10 01:22:12 +04:00
int rpc_printer_migrate ( struct net_context * c , int argc , const char * * argv )
2004-08-10 18:27:17 +04:00
{
/* ouch: when addriver and setdriver are called from within
rpc_printer_migrate_drivers_internals , the printer - queue already
* has * to exist */
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 12:27:59 +04:00
{
" all " ,
rpc_printer_migrate_all ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Migrate all from remote to local print server " ) ,
N_ ( " net rpc printer migrate all \n "
" Migrate all from remote to local print server " )
2008-05-21 12:27:59 +04:00
} ,
{
" drivers " ,
rpc_printer_migrate_drivers ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Migrate drivers to local server " ) ,
N_ ( " net rpc printer migrate drivers \n "
" Migrate drivers to local server " )
2008-05-21 12:27:59 +04:00
} ,
{
" forms " ,
rpc_printer_migrate_forms ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Migrate froms to local server " ) ,
N_ ( " net rpc printer migrate forms \n "
" Migrate froms to local server " )
2008-05-21 12:27:59 +04:00
} ,
{
" printers " ,
rpc_printer_migrate_printers ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Migrate printers to local server " ) ,
N_ ( " net rpc printer migrate printers \n "
" Migrate printers to local server " )
2008-05-21 12:27:59 +04:00
} ,
{
" security " ,
rpc_printer_migrate_security ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Mirgate printer ACLs to local server " ) ,
N_ ( " net rpc printer migrate security \n "
" Mirgate printer ACLs to local server " )
2008-05-21 12:27:59 +04:00
} ,
{
" settings " ,
rpc_printer_migrate_settings ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Migrate printer settings to local server " ) ,
N_ ( " net rpc printer migrate settings \n "
" Migrate printer settings to local server " )
2008-05-21 12:27:59 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2004-08-10 18:27:17 +04:00
} ;
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rpc printer migrate " , func ) ;
2004-08-10 18:27:17 +04:00
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* List printers on a remote RPC server .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-08-10 18:27:17 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_printer_list ( struct net_context * c , int argc , const char * * argv )
2004-08-10 18:27:17 +04:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc printer list \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " List printers on a remote RPC server " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2004-08-10 18:27:17 +04:00
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
2004-08-10 18:27:17 +04:00
rpc_printer_list_internals ,
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* List printer - drivers on a remote RPC server .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-08-10 18:27:17 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-08-10 18:27:17 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_printer_driver_list ( struct net_context * c , int argc ,
const char * * argv )
2004-08-10 18:27:17 +04:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc printer driver \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " List printer-drivers on a remote RPC server " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2004-08-10 18:27:17 +04:00
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
rpc_printer_driver_list_internals ,
2004-08-10 18:27:17 +04:00
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Publish printer in ADS via MSRPC .
2004-10-13 05:40:35 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-10-13 05:40:35 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-10-13 05:40:35 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_printer_publish_publish ( struct net_context * c , int argc ,
const char * * argv )
2004-10-13 05:40:35 +04:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc printer publish publish \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Publish printer in ADS via MSRPC " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2004-10-13 05:40:35 +04:00
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
rpc_printer_publish_publish_internals ,
2004-10-13 05:40:35 +04:00
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Update printer in ADS via MSRPC .
2004-10-13 05:40:35 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-10-13 05:40:35 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-10-13 05:40:35 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_printer_publish_update ( struct net_context * c , int argc , const char * * argv )
2004-10-13 05:40:35 +04:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc printer publish update \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " Update printer in ADS via MSRPC " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2004-10-13 05:40:35 +04:00
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
2004-10-13 05:40:35 +04:00
rpc_printer_publish_update_internals ,
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* UnPublish printer in ADS via MSRPC .
2004-10-13 05:40:35 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-10-13 05:40:35 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-10-13 05:40:35 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_printer_publish_unpublish ( struct net_context * c , int argc ,
const char * * argv )
2004-10-13 05:40:35 +04:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc printer publish unpublish \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: \n " ) ,
_ ( " UnPublish printer in ADS via MSRPC " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2004-10-13 05:40:35 +04:00
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
2004-10-13 05:40:35 +04:00
rpc_printer_publish_unpublish_internals ,
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* List published printers via MSRPC .
2004-10-13 05:40:35 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-10-13 05:40:35 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-10-13 05:40:35 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_printer_publish_list ( struct net_context * c , int argc ,
const char * * argv )
2004-10-13 05:40:35 +04:00
{
2008-05-21 12:27:59 +04:00
if ( c - > display_usage ) {
2010-01-19 13:43:54 +03:00
d_printf ( " %s \n "
2009-08-04 10:28:50 +04:00
" net rpc printer publish list \n "
2010-01-19 13:43:54 +03:00
" %s \n " ,
_ ( " Usage: " ) ,
_ ( " List published printers via MSRPC " ) ) ;
2008-05-21 12:27:59 +04:00
return 0 ;
}
2004-10-13 05:40:35 +04:00
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
2004-10-13 05:40:35 +04:00
rpc_printer_publish_list_internals ,
argc , argv ) ;
}
2008-05-08 13:23:38 +04:00
/**
2008-06-12 12:55:55 +04:00
* Publish printer in ADS .
2004-10-13 05:40:35 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-10-13 05:40:35 +04:00
*
2008-06-12 12:55:55 +04:00
* @ return A shell status integer ( 0 for success ) .
2004-10-13 05:40:35 +04:00
* */
2008-05-10 01:22:12 +04:00
static int rpc_printer_publish ( struct net_context * c , int argc ,
const char * * argv )
2004-10-13 05:40:35 +04:00
{
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 12:27:59 +04:00
{
" publish " ,
rpc_printer_publish_publish ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Publish printer in AD " ) ,
N_ ( " net rpc printer publish publish \n "
" Publish printer in AD " )
2008-05-21 12:27:59 +04:00
} ,
{
" update " ,
rpc_printer_publish_update ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Update printer in AD " ) ,
N_ ( " net rpc printer publish update \n "
" Update printer in AD " )
2008-05-21 12:27:59 +04:00
} ,
{
" unpublish " ,
rpc_printer_publish_unpublish ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Unpublish printer " ) ,
N_ ( " net rpc printer publish unpublish \n "
" Unpublish printer " )
2008-05-21 12:27:59 +04:00
} ,
{
" list " ,
rpc_printer_publish_list ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " List published printers " ) ,
N_ ( " net rpc printer publish list \n "
" List published printers " )
2008-05-21 12:27:59 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2004-10-13 05:40:35 +04:00
} ;
2008-05-21 12:27:59 +04:00
if ( argc = = 0 ) {
if ( c - > display_usage ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Usage: \n " ) ) ;
d_printf ( _ ( " net rpc printer publish \n "
" List published printers \n "
" Alias of net rpc printer publish "
" list \n " ) ) ;
2008-05-21 12:27:59 +04:00
net_display_usage_from_functable ( func ) ;
return 0 ;
}
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
rpc_printer_publish_list_internals ,
argc , argv ) ;
2008-05-21 12:27:59 +04:00
}
2004-10-13 05:40:35 +04:00
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rpc printer publish " , func ) ;
2004-10-13 05:40:35 +04:00
}
2008-05-08 13:23:38 +04:00
/**
2004-08-10 18:27:17 +04:00
* Display rpc printer help page .
2008-05-10 01:22:12 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-08-10 18:27:17 +04:00
* */
2008-05-10 01:22:12 +04:00
int rpc_printer_usage ( struct net_context * c , int argc , const char * * argv )
2004-08-10 18:27:17 +04:00
{
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " net rpc printer LIST [printer] [misc. options] [targets] \n "
" \t lists all printers on print-server \n \n " ) ) ;
d_printf ( _ ( " net rpc printer DRIVER [printer] [misc. options] [targets] \n "
" \t lists all printer-drivers on print-server \n \n " ) ) ;
d_printf ( _ ( " net rpc printer PUBLISH action [printer] [misc. options] [targets] \n "
" \t publishes printer settings in Active Directory \n "
" \t action can be one of PUBLISH, UPDATE, UNPUBLISH or LIST \n \n " ) ) ;
d_printf ( _ ( " net rpc printer MIGRATE PRINTERS [printer] [misc. options] [targets] "
" \n \t migrates printers from remote to local server \n \n " ) ) ;
d_printf ( _ ( " net rpc printer MIGRATE SETTINGS [printer] [misc. options] [targets] "
" \n \t migrates printer-settings from remote to local server \n \n " ) ) ;
d_printf ( _ ( " net rpc printer MIGRATE DRIVERS [printer] [misc. options] [targets] "
" \n \t migrates printer-drivers from remote to local server \n \n " ) ) ;
d_printf ( _ ( " net rpc printer MIGRATE FORMS [printer] [misc. options] [targets] "
" \n \t migrates printer-forms from remote to local server \n \n " ) ) ;
d_printf ( _ ( " net rpc printer MIGRATE SECURITY [printer] [misc. options] [targets] "
" \n \t migrates printer-ACLs from remote to local server \n \n " ) ) ;
d_printf ( _ ( " net rpc printer MIGRATE ALL [printer] [misc. options] [targets] "
" \n \t migrates drivers, forms, queues, settings and acls from \n "
" \t remote to local print-server \n \n " ) ) ;
2008-05-14 16:29:52 +04:00
net_common_methods_usage ( c , argc , argv ) ;
net_common_flags_usage ( c , argc , argv ) ;
2009-08-04 10:28:50 +04:00
d_printf ( _ (
2008-05-14 16:29:52 +04:00
" \t -v or --verbose \t \t \t give verbose output \n "
2009-08-04 10:28:50 +04:00
" \t --destination \t \t migration target server (default: localhost) \n " ) ) ;
2008-05-14 16:29:52 +04:00
return - 1 ;
2004-08-10 18:27:17 +04:00
}
2008-05-08 13:23:38 +04:00
/**
2004-08-10 18:27:17 +04:00
* ' net rpc printer ' entrypoint .
2008-05-10 01:22:12 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2004-08-10 18:27:17 +04:00
* */
2008-05-10 01:22:12 +04:00
int net_rpc_printer ( struct net_context * c , int argc , const char * * argv )
2004-08-10 18:27:17 +04:00
{
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 12:27:59 +04:00
{
" list " ,
rpc_printer_list ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " List all printers on print server " ) ,
N_ ( " net rpc printer list \n "
" List all printers on print server " )
2008-05-21 12:27:59 +04:00
} ,
{
" migrate " ,
rpc_printer_migrate ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Migrate printer to local server " ) ,
N_ ( " net rpc printer migrate \n "
" Migrate printer to local server " )
2008-05-21 12:27:59 +04:00
} ,
{
" driver " ,
rpc_printer_driver_list ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " List printer drivers " ) ,
N_ ( " net rpc printer driver \n "
" List printer drivers " )
2008-05-21 12:27:59 +04:00
} ,
{
" publish " ,
rpc_printer_publish ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Publish printer in AD " ) ,
N_ ( " net rpc printer publish \n "
" Publish printer in AD " )
2008-05-21 12:27:59 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2004-08-10 18:27:17 +04:00
} ;
2008-05-21 12:27:59 +04:00
if ( argc = = 0 ) {
if ( c - > display_usage ) {
2009-08-04 10:28:50 +04:00
d_printf ( _ ( " Usage: \n " ) ) ;
d_printf ( _ ( " net rpc printer \n "
" List printers \n " ) ) ;
2008-05-21 12:27:59 +04:00
net_display_usage_from_functable ( func ) ;
return 0 ;
}
2009-11-08 21:37:26 +03:00
return run_rpc_command ( c , NULL , & ndr_table_spoolss . syntax_id , 0 ,
rpc_printer_list_internals ,
argc , argv ) ;
2002-03-15 23:03:07 +03:00
}
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rpc printer " , func ) ;
2002-03-15 23:03:07 +03:00
}
2008-05-08 13:23:38 +04:00
/**
2001-12-31 16:00:59 +03:00
* ' net rpc ' entrypoint .
2008-05-10 01:22:12 +04:00
*
2008-06-12 12:55:55 +04:00
* @ param c A net_context structure .
* @ param argc Standard main ( ) style argc .
* @ param argv Standard main ( ) style argv . Initial components are already
* stripped .
2001-12-30 13:54:58 +03:00
* */
2008-05-10 01:22:12 +04:00
int net_rpc ( struct net_context * c , int argc , const char * * argv )
2001-12-03 07:39:23 +03:00
{
2009-04-27 16:39:02 +04:00
NET_API_STATUS status ;
2008-06-07 04:25:08 +04:00
struct functable func [ ] = {
2008-05-21 12:27:59 +04:00
{
" audit " ,
net_rpc_audit ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Modify global audit settings " ) ,
N_ ( " net rpc audit \n "
" Modify global audit settings " )
2008-05-21 12:27:59 +04:00
} ,
{
" info " ,
net_rpc_info ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Show basic info about a domain " ) ,
N_ ( " net rpc info \n "
" Show basic info about a domain " )
2008-05-21 12:27:59 +04:00
} ,
{
" join " ,
net_rpc_join ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Join a domain " ) ,
N_ ( " net rpc join \n "
" Join a domain " )
2008-05-21 12:27:59 +04:00
} ,
{
" oldjoin " ,
net_rpc_oldjoin ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Join a domain created in server manager " ) ,
N_ ( " net rpc oldjoin \n "
" Join a domain created in server manager " )
2008-05-21 12:27:59 +04:00
} ,
{
" testjoin " ,
net_rpc_testjoin ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Test that a join is valid " ) ,
N_ ( " net rpc testjoin \n "
" Test that a join is valid " )
2008-05-21 12:27:59 +04:00
} ,
{
" user " ,
net_rpc_user ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " List/modify users " ) ,
N_ ( " net rpc user \n "
" List/modify users " )
2008-05-21 12:27:59 +04:00
} ,
{
" password " ,
rpc_user_password ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Change a user password " ) ,
N_ ( " net rpc password \n "
" Change a user password \n "
" Alias for net rpc user password " )
2008-05-21 12:27:59 +04:00
} ,
{
" group " ,
net_rpc_group ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " List/modify groups " ) ,
N_ ( " net rpc group \n "
" List/modify groups " )
2008-05-21 12:27:59 +04:00
} ,
{
" share " ,
net_rpc_share ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " List/modify shares " ) ,
N_ ( " net rpc share \n "
" List/modify shares " )
2008-05-21 12:27:59 +04:00
} ,
{
" file " ,
net_rpc_file ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " List open files " ) ,
N_ ( " net rpc file \n "
" List open files " )
2008-05-21 12:27:59 +04:00
} ,
{
" printer " ,
net_rpc_printer ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " List/modify printers " ) ,
N_ ( " net rpc printer \n "
" List/modify printers " )
2008-05-21 12:27:59 +04:00
} ,
{
" changetrustpw " ,
net_rpc_changetrustpw ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Change trust account password " ) ,
N_ ( " net rpc changetrustpw \n "
" Change trust account password " )
2008-05-21 12:27:59 +04:00
} ,
{
" trustdom " ,
rpc_trustdom ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Modify domain trusts " ) ,
N_ ( " net rpc trustdom \n "
" Modify domain trusts " )
2008-05-21 12:27:59 +04:00
} ,
{
" abortshutdown " ,
rpc_shutdown_abort ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Abort a remote shutdown " ) ,
N_ ( " net rpc abortshutdown \n "
" Abort a remote shutdown " )
2008-05-21 12:27:59 +04:00
} ,
{
" shutdown " ,
rpc_shutdown ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Shutdown a remote server " ) ,
N_ ( " net rpc shutdown \n "
" Shutdown a remote server " )
2008-05-21 12:27:59 +04:00
} ,
{
" samdump " ,
rpc_samdump ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Dump SAM data of remote NT PDC " ) ,
N_ ( " net rpc samdump \n "
" Dump SAM data of remote NT PDC " )
2008-05-21 12:27:59 +04:00
} ,
{
" vampire " ,
rpc_vampire ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Sync a remote NT PDC's data into local passdb " ) ,
N_ ( " net rpc vampire \n "
" Sync a remote NT PDC's data into local passdb " )
2008-05-21 12:27:59 +04:00
} ,
{
" getsid " ,
net_rpc_getsid ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Fetch the domain sid into local secrets.tdb " ) ,
N_ ( " net rpc getsid \n "
" Fetch the domain sid into local secrets.tdb " )
2008-05-21 12:27:59 +04:00
} ,
{
" rights " ,
net_rpc_rights ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Manage privileges assigned to SID " ) ,
N_ ( " net rpc rights \n "
" Manage privileges assigned to SID " )
2008-05-21 12:27:59 +04:00
} ,
{
" service " ,
net_rpc_service ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Start/stop/query remote services " ) ,
N_ ( " net rpc service \n "
" Start/stop/query remote services " )
2008-05-21 12:27:59 +04:00
} ,
{
" registry " ,
net_rpc_registry ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Manage registry hives " ) ,
N_ ( " net rpc registry \n "
" Manage registry hives " )
2008-05-21 12:27:59 +04:00
} ,
{
" shell " ,
net_rpc_shell ,
NET_TRANSPORT_RPC ,
2009-08-04 10:28:50 +04:00
N_ ( " Open interactive shell on remote server " ) ,
N_ ( " net rpc shell \n "
" Open interactive shell on remote server " )
2008-05-21 12:27:59 +04:00
} ,
{ NULL , NULL , 0 , NULL , NULL }
2001-12-03 07:39:23 +03:00
} ;
2009-04-27 16:39:02 +04:00
status = libnetapi_init ( & c - > netapi_ctx ) ;
if ( status ! = 0 ) {
return - 1 ;
}
2009-07-05 11:21:07 +04:00
libnetapi_set_username ( c - > netapi_ctx , c - > opt_user_name ) ;
libnetapi_set_password ( c - > netapi_ctx , c - > opt_password ) ;
if ( c - > opt_kerberos ) {
2009-04-27 16:39:02 +04:00
libnetapi_set_use_kerberos ( c - > netapi_ctx ) ;
}
2010-01-24 20:50:48 +03:00
if ( c - > opt_ccache ) {
libnetapi_set_use_ccache ( c - > netapi_ctx ) ;
}
2009-04-27 16:39:02 +04:00
2008-06-07 04:25:08 +04:00
return net_run_function ( c , argc , argv , " net rpc " , func ) ;
2001-12-03 07:39:23 +03:00
}