1998-09-26 01:01:52 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2001-01-12 01:49:30 +03:00
RPC pipe client
2001-08-28 01:32:06 +04:00
Copyright ( C ) Tim Potter 2000 - 2001
2003-02-26 02:53:38 +03:00
Copyright ( C ) Martin Pool 2003
2001-01-12 01:49:30 +03:00
1998-09-26 01:01:52 +04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
1998-09-26 01:01:52 +04:00
( at your option ) any later version .
2010-09-17 23:16:24 +04:00
1998-09-26 01:01:52 +04:00
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2010-09-17 23:16:24 +04:00
1998-09-26 01:01:52 +04: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/>.
1998-09-26 01:01:52 +04:00
*/
# include "includes.h"
2010-08-05 12:49:53 +04:00
# include "popt_common.h"
2001-10-12 09:56:23 +04:00
# include "rpcclient.h"
2009-03-16 13:27:58 +03:00
# include "../libcli/auth/libcli_auth.h"
2011-01-18 18:11:46 +03:00
# include "../librpc/gen_ndr/ndr_lsa_c.h"
2010-05-18 20:26:16 +04:00
# include "rpc_client/cli_lsarpc.h"
2010-05-05 03:39:16 +04:00
# include "../librpc/gen_ndr/ndr_netlogon.h"
2010-05-18 20:26:03 +04:00
# include "rpc_client/cli_netlogon.h"
2010-10-01 12:34:14 +04:00
# include "../libcli/smbreadline/smbreadline.h"
2010-10-12 08:27:50 +04:00
# include "../libcli/security/security.h"
2011-03-22 18:50:02 +03:00
# include "passdb.h"
2011-05-06 13:47:43 +04:00
# include "libsmb/libsmb.h"
2012-01-10 14:03:02 +04:00
# include "auth/gensec/gensec.h"
2012-05-19 19:31:50 +04:00
# include "../libcli/smb/smbXcli_base.h"
2001-01-12 01:49:30 +03:00
2010-09-03 19:03:49 +04:00
enum pipe_auth_type_spnego {
PIPE_AUTH_TYPE_SPNEGO_NONE = 0 ,
PIPE_AUTH_TYPE_SPNEGO_NTLMSSP ,
PIPE_AUTH_TYPE_SPNEGO_KRB5
} ;
2010-05-21 05:25:01 +04:00
struct dom_sid domain_sid ;
2001-01-16 02:35:59 +03:00
2010-07-20 21:26:36 +04:00
static enum dcerpc_AuthType pipe_default_auth_type = DCERPC_AUTH_TYPE_NONE ;
static enum pipe_auth_type_spnego pipe_default_auth_spnego_type = 0 ;
2009-09-14 22:39:54 +04:00
static enum dcerpc_AuthLevel pipe_default_auth_level = DCERPC_AUTH_LEVEL_NONE ;
2006-10-17 03:27:38 +04:00
static unsigned int timeout = 0 ;
2009-09-10 23:14:29 +04:00
static enum dcerpc_transport_t default_transport = NCACN_NP ;
2003-02-26 02:53:38 +03:00
2008-12-14 15:06:19 +03:00
struct user_auth_info * rpcclient_auth_info ;
2003-02-26 02:53:38 +03:00
/* List to hold groups of commands.
*
* Commands are defined in a list of arrays : arrays are easy to
* statically declare , and lists are easier to dynamically extend .
*/
2001-05-24 04:20:32 +04:00
2001-04-28 04:32:56 +04:00
static struct cmd_list {
struct cmd_list * prev , * next ;
struct cmd_set * cmd_set ;
} * cmd_list ;
/****************************************************************************
handle completion of commands for readline
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-08-15 08:42:05 +04:00
static char * * completion_fn ( const char * text , int start , int end )
2001-04-28 04:32:56 +04:00
{
2010-09-18 18:37:04 +04:00
# define MAX_COMPLETIONS 1000
2001-04-28 04:32:56 +04:00
char * * matches ;
int i , count = 0 ;
struct cmd_list * commands = cmd_list ;
#if 0 /* JERRY */
/* FIXME!!! -- what to do when completing argument? */
/* for words not at the start of the line fallback
to filename completion */
if ( start )
return NULL ;
# endif
/* make sure we have a list of valid commands */
2006-03-13 22:40:51 +03:00
if ( ! commands ) {
2001-04-28 04:32:56 +04:00
return NULL ;
2006-03-13 22:40:51 +03:00
}
2001-04-28 04:32:56 +04:00
2004-12-07 21:25:53 +03:00
matches = SMB_MALLOC_ARRAY ( char * , MAX_COMPLETIONS ) ;
2006-03-13 22:40:51 +03:00
if ( ! matches ) {
return NULL ;
}
2001-04-28 04:32:56 +04:00
2004-12-07 21:25:53 +03:00
matches [ count + + ] = SMB_STRDUP ( text ) ;
2006-03-13 22:40:51 +03:00
if ( ! matches [ 0 ] ) {
SAFE_FREE ( matches ) ;
return NULL ;
}
2001-04-28 04:32:56 +04:00
2006-03-13 22:40:51 +03:00
while ( commands & & count < MAX_COMPLETIONS - 1 ) {
if ( ! commands - > cmd_set ) {
2001-04-28 04:32:56 +04:00
break ;
2006-03-13 22:40:51 +03:00
}
2010-09-17 23:16:24 +04:00
2006-03-13 22:40:51 +03:00
for ( i = 0 ; commands - > cmd_set [ i ] . name ; i + + ) {
2001-04-28 04:32:56 +04:00
if ( ( strncmp ( text , commands - > cmd_set [ i ] . name , strlen ( text ) ) = = 0 ) & &
2003-03-18 09:30:30 +03:00
( ( commands - > cmd_set [ i ] . returntype = = RPC_RTYPE_NTSTATUS & &
commands - > cmd_set [ i ] . ntfn ) | |
( commands - > cmd_set [ i ] . returntype = = RPC_RTYPE_WERROR & &
2006-03-13 22:40:51 +03:00
commands - > cmd_set [ i ] . wfn ) ) ) {
2004-12-07 21:25:53 +03:00
matches [ count ] = SMB_STRDUP ( commands - > cmd_set [ i ] . name ) ;
2006-03-13 22:40:51 +03:00
if ( ! matches [ count ] ) {
for ( i = 0 ; i < count ; i + + ) {
SAFE_FREE ( matches [ count ] ) ;
}
SAFE_FREE ( matches ) ;
2001-04-28 04:32:56 +04:00
return NULL ;
2006-03-13 22:40:51 +03:00
}
2001-04-28 04:32:56 +04:00
count + + ;
}
}
commands = commands - > next ;
}
if ( count = = 2 ) {
2001-09-17 14:26:23 +04:00
SAFE_FREE ( matches [ 0 ] ) ;
2004-12-07 21:25:53 +03:00
matches [ 0 ] = SMB_STRDUP ( matches [ 1 ] ) ;
2001-04-28 04:32:56 +04:00
}
matches [ count ] = NULL ;
return matches ;
}
2007-06-07 05:13:43 +04:00
static char * next_command ( char * * cmdstr )
2001-05-31 22:35:14 +04:00
{
2007-06-07 05:13:43 +04:00
char * command ;
2001-05-31 22:35:14 +04:00
char * p ;
2010-09-17 23:16:24 +04:00
2001-05-31 22:35:14 +04:00
if ( ! cmdstr | | ! ( * cmdstr ) )
return NULL ;
2010-09-17 23:16:24 +04:00
2001-07-04 11:36:09 +04:00
p = strchr_m ( * cmdstr , ' ; ' ) ;
2001-05-31 22:35:14 +04:00
if ( p )
* p = ' \0 ' ;
2007-06-07 05:13:43 +04:00
command = SMB_STRDUP ( * cmdstr ) ;
2003-02-26 02:53:38 +03:00
if ( p )
* cmdstr = p + 1 ;
else
* cmdstr = NULL ;
2010-09-17 23:16:24 +04:00
2001-05-31 22:35:14 +04:00
return command ;
}
2001-10-22 10:13:38 +04:00
/* Fetch the SID for this computer */
2001-07-20 08:38:58 +04:00
2002-07-15 14:35:28 +04:00
static void fetch_machine_sid ( struct cli_state * cli )
2001-01-16 02:35:59 +03:00
{
2009-03-19 00:49:41 +03:00
struct policy_handle pol ;
2011-01-18 18:11:46 +03:00
NTSTATUS result = NT_STATUS_OK , status ;
2007-10-19 04:40:25 +04:00
static bool got_domain_sid ;
2001-04-28 04:32:56 +04:00
TALLOC_CTX * mem_ctx ;
2005-09-30 21:13:37 +04:00
struct rpc_pipe_client * lsapipe = NULL ;
2008-02-08 04:12:30 +03:00
union lsa_PolicyInformation * info = NULL ;
2011-01-18 18:11:46 +03:00
struct dcerpc_binding_handle * b ;
2001-01-16 02:35:59 +03:00
if ( got_domain_sid ) return ;
2005-09-30 21:13:37 +04:00
if ( ! ( mem_ctx = talloc_init ( " fetch_machine_sid " ) ) ) {
2002-07-15 14:35:28 +04:00
DEBUG ( 0 , ( " fetch_machine_sid: talloc_init returned NULL! \n " ) ) ;
2001-04-28 04:32:56 +04:00
goto error ;
}
2008-07-20 13:04:31 +04:00
result = cli_rpc_pipe_open_noauth ( cli , & ndr_table_lsarpc . syntax_id ,
& lsapipe ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
2005-09-30 21:13:37 +04:00
fprintf ( stderr , " could not initialise lsa pipe. Error was %s \n " , nt_errstr ( result ) ) ;
2001-01-16 02:35:59 +03:00
goto error ;
}
2010-09-17 23:16:24 +04:00
2011-01-18 18:11:46 +03:00
b = lsapipe - > binding_handle ;
2005-09-30 21:13:37 +04:00
result = rpccli_lsa_open_policy ( lsapipe , mem_ctx , True ,
2009-04-15 03:12:13 +04:00
SEC_FLAG_MAXIMUM_ALLOWED ,
2001-09-04 11:13:01 +04:00
& pol ) ;
if ( ! NT_STATUS_IS_OK ( result ) ) {
2001-01-16 02:35:59 +03:00
goto error ;
}
2011-01-18 18:11:46 +03:00
status = dcerpc_lsa_QueryInfoPolicy ( b , mem_ctx ,
2008-02-08 04:12:30 +03:00
& pol ,
LSA_POLICY_INFO_ACCOUNT_DOMAIN ,
2011-01-18 18:11:46 +03:00
& info ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
result = status ;
goto error ;
}
2001-09-04 11:13:01 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2001-01-16 02:35:59 +03:00
goto error ;
}
got_domain_sid = True ;
2008-02-08 04:12:30 +03:00
sid_copy ( & domain_sid , info - > account_domain . sid ) ;
2001-01-16 02:35:59 +03:00
2011-01-18 18:11:46 +03:00
dcerpc_lsa_Close ( b , mem_ctx , & pol , & result ) ;
2008-04-20 15:51:46 +04:00
TALLOC_FREE ( lsapipe ) ;
2001-04-28 04:32:56 +04:00
talloc_destroy ( mem_ctx ) ;
2001-01-16 02:35:59 +03:00
return ;
error :
2005-09-30 21:13:37 +04:00
if ( lsapipe ) {
2008-04-20 15:51:46 +04:00
TALLOC_FREE ( lsapipe ) ;
2005-09-30 21:13:37 +04:00
}
2001-03-16 01:06:53 +03:00
fprintf ( stderr , " could not obtain sid for domain %s \n " , cli - > domain ) ;
2001-01-16 02:35:59 +03:00
2001-09-04 11:13:01 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2002-03-17 07:36:35 +03:00
fprintf ( stderr , " error: %s \n " , nt_errstr ( result ) ) ;
2001-01-16 02:35:59 +03:00
}
exit ( 1 ) ;
}
2002-04-03 03:28:40 +04:00
/* List the available commands on a given pipe */
2005-09-30 21:13:37 +04:00
static NTSTATUS cmd_listcommands ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
2003-02-26 02:53:38 +03:00
int argc , const char * * argv )
2002-04-03 03:28:40 +04:00
{
struct cmd_list * tmp ;
struct cmd_set * tmp_set ;
int i ;
/* Usage */
if ( argc ! = 2 ) {
printf ( " Usage: %s <pipe> \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
/* Help on one command */
for ( tmp = cmd_list ; tmp ; tmp = tmp - > next )
{
tmp_set = tmp - > cmd_set ;
2010-09-17 23:16:24 +04:00
2011-05-13 22:21:30 +04:00
if ( ! strcasecmp_m ( argv [ 1 ] , tmp_set - > name ) )
2002-04-03 03:28:40 +04:00
{
printf ( " Available commands on the %s pipe: \n \n " , tmp_set - > name ) ;
i = 0 ;
tmp_set + + ;
while ( tmp_set - > name ) {
2005-06-08 17:59:03 +04:00
printf ( " %30s " , tmp_set - > name ) ;
2002-04-03 03:28:40 +04:00
tmp_set + + ;
i + + ;
2005-06-08 17:59:03 +04:00
if ( i % 3 = = 0 )
2002-04-03 03:28:40 +04:00
printf ( " \n " ) ;
}
2010-09-17 23:16:24 +04:00
2002-04-03 03:28:40 +04:00
/* drop out of the loop */
break ;
}
}
printf ( " \n \n " ) ;
return NT_STATUS_OK ;
}
2001-01-12 01:49:30 +03:00
2001-07-20 08:38:58 +04:00
/* Display help on commands */
2005-09-30 21:13:37 +04:00
static NTSTATUS cmd_help ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
2003-02-26 02:53:38 +03:00
int argc , const char * * argv )
2001-01-12 01:49:30 +03:00
{
2001-07-20 08:38:58 +04:00
struct cmd_list * tmp ;
struct cmd_set * tmp_set ;
/* Usage */
if ( argc > 2 ) {
printf ( " Usage: %s [command] \n " , argv [ 0 ] ) ;
2001-09-15 07:57:12 +04:00
return NT_STATUS_OK ;
2001-07-20 08:38:58 +04:00
}
/* Help on one command */
if ( argc = = 2 ) {
for ( tmp = cmd_list ; tmp ; tmp = tmp - > next ) {
2010-09-17 23:16:24 +04:00
2001-07-20 08:38:58 +04:00
tmp_set = tmp - > cmd_set ;
while ( tmp_set - > name ) {
if ( strequal ( argv [ 1 ] , tmp_set - > name ) ) {
if ( tmp_set - > usage & &
tmp_set - > usage [ 0 ] )
printf ( " %s \n " , tmp_set - > usage ) ;
else
printf ( " No help for %s \n " , tmp_set - > name ) ;
2001-09-15 07:57:12 +04:00
return NT_STATUS_OK ;
2001-07-20 08:38:58 +04:00
}
tmp_set + + ;
}
}
2001-01-12 01:49:30 +03:00
2001-07-20 08:38:58 +04:00
printf ( " No such command: %s \n " , argv [ 1 ] ) ;
2001-09-15 07:57:12 +04:00
return NT_STATUS_OK ;
2001-07-20 08:38:58 +04:00
}
/* List all commands */
for ( tmp = cmd_list ; tmp ; tmp = tmp - > next ) {
tmp_set = tmp - > cmd_set ;
while ( tmp_set - > name ) {
2001-01-12 01:49:30 +03:00
2001-07-20 08:38:58 +04:00
printf ( " %15s \t \t %s \n " , tmp_set - > name ,
2001-12-21 04:16:37 +03:00
tmp_set - > description ? tmp_set - > description :
" " ) ;
2001-07-20 08:38:58 +04:00
tmp_set + + ;
2001-01-12 01:49:30 +03:00
}
}
2001-09-15 07:57:12 +04:00
return NT_STATUS_OK ;
2001-01-12 01:49:30 +03:00
}
2001-07-20 08:38:58 +04:00
/* Change the debug level */
2005-09-30 21:13:37 +04:00
static NTSTATUS cmd_debuglevel ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
2003-02-26 02:53:38 +03:00
int argc , const char * * argv )
2001-01-12 01:49:30 +03:00
{
if ( argc > 2 ) {
printf ( " Usage: %s [debuglevel] \n " , argv [ 0 ] ) ;
2001-08-27 23:46:22 +04:00
return NT_STATUS_OK ;
2001-01-12 01:49:30 +03:00
}
if ( argc = = 2 ) {
2010-10-29 08:29:09 +04:00
lp_set_cmdline ( " log level " , argv [ 1 ] ) ;
2001-01-12 01:49:30 +03:00
}
printf ( " debuglevel is %d \n " , DEBUGLEVEL ) ;
2001-08-27 23:46:22 +04:00
return NT_STATUS_OK ;
2001-01-12 01:49:30 +03:00
}
2005-09-30 21:13:37 +04:00
static NTSTATUS cmd_quit ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
2003-02-26 02:53:38 +03:00
int argc , const char * * argv )
2001-01-16 02:35:59 +03:00
{
exit ( 0 ) ;
2001-08-27 23:46:22 +04:00
return NT_STATUS_OK ; /* NOTREACHED */
2001-01-16 02:35:59 +03:00
}
2005-09-30 21:13:37 +04:00
static NTSTATUS cmd_set_ss_level ( void )
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
{
2005-09-30 21:13:37 +04:00
struct cmd_list * tmp ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
2005-09-30 21:13:37 +04:00
/* Close any existing connections not at this level. */
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
2005-09-30 21:13:37 +04:00
for ( tmp = cmd_list ; tmp ; tmp = tmp - > next ) {
struct cmd_set * tmp_set ;
for ( tmp_set = tmp - > cmd_set ; tmp_set - > name ; tmp_set + + ) {
if ( tmp_set - > rpc_pipe = = NULL ) {
continue ;
}
2008-04-21 12:39:37 +04:00
if ( ( tmp_set - > rpc_pipe - > auth - > auth_type
! = pipe_default_auth_type )
| | ( tmp_set - > rpc_pipe - > auth - > auth_level
! = pipe_default_auth_level ) ) {
2008-04-20 15:51:46 +04:00
TALLOC_FREE ( tmp_set - > rpc_pipe ) ;
2005-09-30 21:13:37 +04:00
tmp_set - > rpc_pipe = NULL ;
}
}
}
return NT_STATUS_OK ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
}
2009-09-10 23:14:29 +04:00
static NTSTATUS cmd_set_transport ( void )
{
struct cmd_list * tmp ;
/* Close any existing connections not at this level. */
for ( tmp = cmd_list ; tmp ; tmp = tmp - > next ) {
struct cmd_set * tmp_set ;
for ( tmp_set = tmp - > cmd_set ; tmp_set - > name ; tmp_set + + ) {
if ( tmp_set - > rpc_pipe = = NULL ) {
continue ;
}
if ( tmp_set - > rpc_pipe - > transport - > transport ! = default_transport ) {
TALLOC_FREE ( tmp_set - > rpc_pipe ) ;
tmp_set - > rpc_pipe = NULL ;
}
}
}
return NT_STATUS_OK ;
}
2005-09-30 21:13:37 +04:00
static NTSTATUS cmd_sign ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
int argc , const char * * argv )
{
2010-08-26 00:22:03 +04:00
const char * p = " [KRB5|KRB5_SPNEGO|NTLMSSP|NTLMSSP_SPNEGO|SCHANNEL] " ;
2008-06-10 23:34:23 +04:00
const char * type = " NTLMSSP " ;
2009-09-14 22:39:54 +04:00
pipe_default_auth_level = DCERPC_AUTH_LEVEL_INTEGRITY ;
2010-07-20 21:26:36 +04:00
pipe_default_auth_type = DCERPC_AUTH_TYPE_NTLMSSP ;
2005-09-30 21:13:37 +04:00
if ( argc > 2 ) {
2010-08-26 00:22:03 +04:00
printf ( " Usage: %s %s \n " , argv [ 0 ] , p ) ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
return NT_STATUS_OK ;
}
2003-07-25 05:26:19 +04:00
if ( argc = = 2 ) {
2008-06-10 23:34:23 +04:00
type = argv [ 1 ] ;
2010-08-26 00:22:03 +04:00
if ( strequal ( type , " KRB5 " ) ) {
pipe_default_auth_type = DCERPC_AUTH_TYPE_KRB5 ;
} else if ( strequal ( type , " KRB5_SPNEGO " ) ) {
pipe_default_auth_type = DCERPC_AUTH_TYPE_SPNEGO ;
pipe_default_auth_spnego_type = PIPE_AUTH_TYPE_SPNEGO_KRB5 ;
} else if ( strequal ( type , " NTLMSSP " ) ) {
2010-07-20 21:26:36 +04:00
pipe_default_auth_type = DCERPC_AUTH_TYPE_NTLMSSP ;
2008-06-10 23:34:23 +04:00
} else if ( strequal ( type , " NTLMSSP_SPNEGO " ) ) {
2010-07-20 21:26:36 +04:00
pipe_default_auth_type = DCERPC_AUTH_TYPE_SPNEGO ;
pipe_default_auth_spnego_type = PIPE_AUTH_TYPE_SPNEGO_NTLMSSP ;
2008-06-10 23:34:23 +04:00
} else if ( strequal ( type , " SCHANNEL " ) ) {
2010-07-20 21:26:36 +04:00
pipe_default_auth_type = DCERPC_AUTH_TYPE_SCHANNEL ;
2005-09-30 21:13:37 +04:00
} else {
2008-06-10 23:34:23 +04:00
printf ( " unknown type %s \n " , type ) ;
2010-08-26 00:22:03 +04:00
printf ( " Usage: %s %s \n " , argv [ 0 ] , p ) ;
2005-09-30 21:13:37 +04:00
return NT_STATUS_INVALID_LEVEL ;
}
2003-07-25 05:26:19 +04:00
}
2008-06-10 23:34:23 +04:00
d_printf ( " Setting %s - sign \n " , type ) ;
2005-09-30 21:13:37 +04:00
return cmd_set_ss_level ( ) ;
}
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
2005-09-30 21:13:37 +04:00
static NTSTATUS cmd_seal ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
2010-08-26 00:22:03 +04:00
const char * p = " [KRB5|KRB5_SPNEGO|NTLMSSP|NTLMSSP_SPNEGO|SCHANNEL] " ;
2008-06-10 23:34:23 +04:00
const char * type = " NTLMSSP " ;
2009-09-14 22:39:54 +04:00
pipe_default_auth_level = DCERPC_AUTH_LEVEL_PRIVACY ;
2010-07-20 21:26:36 +04:00
pipe_default_auth_type = DCERPC_AUTH_TYPE_NTLMSSP ;
2005-09-30 21:13:37 +04:00
if ( argc > 2 ) {
2010-08-26 00:22:03 +04:00
printf ( " Usage: %s %s \n " , argv [ 0 ] , p ) ;
2005-09-30 21:13:37 +04:00
return NT_STATUS_OK ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
}
2005-09-30 21:13:37 +04:00
if ( argc = = 2 ) {
2008-06-10 23:34:23 +04:00
type = argv [ 1 ] ;
2010-08-26 00:22:03 +04:00
if ( strequal ( type , " KRB5 " ) ) {
pipe_default_auth_type = DCERPC_AUTH_TYPE_KRB5 ;
} else if ( strequal ( type , " KRB5_SPNEGO " ) ) {
pipe_default_auth_type = DCERPC_AUTH_TYPE_SPNEGO ;
pipe_default_auth_spnego_type = PIPE_AUTH_TYPE_SPNEGO_KRB5 ;
} else if ( strequal ( type , " NTLMSSP " ) ) {
2010-07-20 21:26:36 +04:00
pipe_default_auth_type = DCERPC_AUTH_TYPE_NTLMSSP ;
2008-06-10 23:34:23 +04:00
} else if ( strequal ( type , " NTLMSSP_SPNEGO " ) ) {
2010-07-20 21:26:36 +04:00
pipe_default_auth_type = DCERPC_AUTH_TYPE_SPNEGO ;
pipe_default_auth_spnego_type = PIPE_AUTH_TYPE_SPNEGO_NTLMSSP ;
2008-06-10 23:34:23 +04:00
} else if ( strequal ( type , " SCHANNEL " ) ) {
2010-07-20 21:26:36 +04:00
pipe_default_auth_type = DCERPC_AUTH_TYPE_SCHANNEL ;
2005-09-30 21:13:37 +04:00
} else {
2008-06-10 23:34:23 +04:00
printf ( " unknown type %s \n " , type ) ;
2010-08-26 00:22:03 +04:00
printf ( " Usage: %s %s \n " , argv [ 0 ] , p ) ;
2005-09-30 21:13:37 +04:00
return NT_STATUS_INVALID_LEVEL ;
}
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
}
2008-06-10 23:34:23 +04:00
d_printf ( " Setting %s - sign and seal \n " , type ) ;
2005-09-30 21:13:37 +04:00
return cmd_set_ss_level ( ) ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
}
2006-10-17 03:27:38 +04:00
static NTSTATUS cmd_timeout ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
struct cmd_list * tmp ;
if ( argc > 2 ) {
printf ( " Usage: %s timeout \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
if ( argc = = 2 ) {
timeout = atoi ( argv [ 1 ] ) ;
for ( tmp = cmd_list ; tmp ; tmp = tmp - > next ) {
2010-09-17 23:16:24 +04:00
2006-10-17 03:27:38 +04:00
struct cmd_set * tmp_set ;
for ( tmp_set = tmp - > cmd_set ; tmp_set - > name ; tmp_set + + ) {
if ( tmp_set - > rpc_pipe = = NULL ) {
continue ;
}
2008-04-20 01:27:35 +04:00
rpccli_set_timeout ( tmp_set - > rpc_pipe , timeout ) ;
2006-10-17 03:27:38 +04:00
}
}
}
printf ( " timeout is %d \n " , timeout ) ;
return NT_STATUS_OK ;
}
2005-09-30 21:13:37 +04:00
static NTSTATUS cmd_none ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
2009-09-14 22:39:54 +04:00
pipe_default_auth_level = DCERPC_AUTH_LEVEL_NONE ;
2010-07-20 21:26:36 +04:00
pipe_default_auth_type = DCERPC_AUTH_TYPE_NONE ;
pipe_default_auth_spnego_type = PIPE_AUTH_TYPE_SPNEGO_NONE ;
2005-09-30 21:13:37 +04:00
return cmd_set_ss_level ( ) ;
}
2003-10-02 01:18:32 +04:00
2005-09-30 21:13:37 +04:00
static NTSTATUS cmd_schannel ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
2003-10-02 01:18:32 +04:00
int argc , const char * * argv )
{
d_printf ( " Setting schannel - sign and seal \n " ) ;
2009-09-14 22:39:54 +04:00
pipe_default_auth_level = DCERPC_AUTH_LEVEL_PRIVACY ;
2010-07-20 21:26:36 +04:00
pipe_default_auth_type = DCERPC_AUTH_TYPE_SCHANNEL ;
2005-09-30 21:13:37 +04:00
return cmd_set_ss_level ( ) ;
2003-10-02 01:18:32 +04:00
}
2005-09-30 21:13:37 +04:00
static NTSTATUS cmd_schannel_sign ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
2003-10-02 01:18:32 +04:00
int argc , const char * * argv )
{
d_printf ( " Setting schannel - sign only \n " ) ;
2009-09-14 22:39:54 +04:00
pipe_default_auth_level = DCERPC_AUTH_LEVEL_INTEGRITY ;
2010-07-20 21:26:36 +04:00
pipe_default_auth_type = DCERPC_AUTH_TYPE_SCHANNEL ;
2005-09-30 21:13:37 +04:00
return cmd_set_ss_level ( ) ;
2003-10-02 01:18:32 +04:00
}
2009-09-10 23:14:29 +04:00
static NTSTATUS cmd_choose_transport ( struct rpc_pipe_client * cli , TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
NTSTATUS status ;
if ( argc ! = 2 ) {
printf ( " Usage: %s [NCACN_NP|NCACN_IP_TCP] \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
if ( strequal ( argv [ 1 ] , " NCACN_NP " ) ) {
default_transport = NCACN_NP ;
} else if ( strequal ( argv [ 1 ] , " NCACN_IP_TCP " ) ) {
default_transport = NCACN_IP_TCP ;
} else {
printf ( " transport type: %s unknown or not supported \n " , argv [ 1 ] ) ;
return NT_STATUS_NOT_SUPPORTED ;
}
status = cmd_set_transport ( ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
printf ( " default transport is now: %s \n " , argv [ 1 ] ) ;
return NT_STATUS_OK ;
}
2003-10-02 01:18:32 +04:00
2003-02-26 02:53:38 +03:00
/* Built in rpcclient commands */
2001-01-12 01:49:30 +03:00
static struct cmd_set rpcclient_commands [ ] = {
2001-07-20 08:38:58 +04:00
{ " GENERAL OPTIONS " } ,
2009-11-08 21:38:09 +03:00
{ " help " , RPC_RTYPE_NTSTATUS , cmd_help , NULL , NULL , NULL , " Get help on commands " , " [command] " } ,
{ " ? " , RPC_RTYPE_NTSTATUS , cmd_help , NULL , NULL , NULL , " Get help on commands " , " [command] " } ,
{ " debuglevel " , RPC_RTYPE_NTSTATUS , cmd_debuglevel , NULL , NULL , NULL , " Set debug level " , " level " } ,
{ " debug " , RPC_RTYPE_NTSTATUS , cmd_debuglevel , NULL , NULL , NULL , " Set debug level " , " level " } ,
{ " list " , RPC_RTYPE_NTSTATUS , cmd_listcommands , NULL , NULL , NULL , " List available commands on <pipe> " , " pipe " } ,
{ " exit " , RPC_RTYPE_NTSTATUS , cmd_quit , NULL , NULL , NULL , " Exit program " , " " } ,
{ " quit " , RPC_RTYPE_NTSTATUS , cmd_quit , NULL , NULL , NULL , " Exit program " , " " } ,
{ " sign " , RPC_RTYPE_NTSTATUS , cmd_sign , NULL , NULL , NULL , " Force RPC pipe connections to be signed " , " " } ,
{ " seal " , RPC_RTYPE_NTSTATUS , cmd_seal , NULL , NULL , NULL , " Force RPC pipe connections to be sealed " , " " } ,
{ " schannel " , RPC_RTYPE_NTSTATUS , cmd_schannel , NULL , NULL , NULL , " Force RPC pipe connections to be sealed with 'schannel'. Assumes valid machine account to this domain controller. " , " " } ,
{ " schannelsign " , RPC_RTYPE_NTSTATUS , cmd_schannel_sign , NULL , NULL , NULL , " Force RPC pipe connections to be signed (not sealed) with 'schannel'. Assumes valid machine account to this domain controller. " , " " } ,
2011-03-01 00:04:29 +03:00
{ " timeout " , RPC_RTYPE_NTSTATUS , cmd_timeout , NULL , NULL , NULL , " Set timeout (in milliseconds) for RPC operations " , " " } ,
2009-11-08 21:38:09 +03:00
{ " transport " , RPC_RTYPE_NTSTATUS , cmd_choose_transport , NULL , NULL , NULL , " Choose ncacn transport for RPC operations " , " " } ,
{ " none " , RPC_RTYPE_NTSTATUS , cmd_none , NULL , NULL , NULL , " Force RPC pipe connections to have no special properties " , " " } ,
2001-07-20 08:38:58 +04:00
{ NULL }
2001-01-12 01:49:30 +03:00
} ;
2001-03-15 05:15:05 +03:00
static struct cmd_set separator_command [ ] = {
2009-11-08 21:38:09 +03:00
{ " --------------- " , MAX_RPC_RETURN_TYPE , NULL , NULL , NULL , NULL , " ---------------------- " } ,
2001-07-20 08:38:58 +04:00
{ NULL }
2001-03-15 05:15:05 +03:00
} ;
2001-05-24 04:20:32 +04:00
/* Various pipe commands */
extern struct cmd_set lsarpc_commands [ ] ;
extern struct cmd_set samr_commands [ ] ;
extern struct cmd_set spoolss_commands [ ] ;
extern struct cmd_set netlogon_commands [ ] ;
extern struct cmd_set srvsvc_commands [ ] ;
2001-06-06 11:35:08 +04:00
extern struct cmd_set dfs_commands [ ] ;
2002-10-04 23:33:41 +04:00
extern struct cmd_set ds_commands [ ] ;
2003-04-14 06:08:03 +04:00
extern struct cmd_set echo_commands [ ] ;
2009-01-06 21:09:57 +03:00
extern struct cmd_set epmapper_commands [ ] ;
2003-10-24 17:49:29 +04:00
extern struct cmd_set shutdown_commands [ ] ;
2005-09-30 21:13:37 +04:00
extern struct cmd_set test_commands [ ] ;
2007-12-03 14:42:17 +03:00
extern struct cmd_set wkssvc_commands [ ] ;
2008-02-18 01:16:56 +03:00
extern struct cmd_set ntsvcs_commands [ ] ;
2008-05-24 03:28:22 +04:00
extern struct cmd_set drsuapi_commands [ ] ;
2009-01-08 21:13:22 +03:00
extern struct cmd_set eventlog_commands [ ] ;
2010-09-17 15:17:12 +04:00
extern struct cmd_set winreg_commands [ ] ;
2001-05-24 04:20:32 +04:00
static struct cmd_set * rpcclient_command_list [ ] = {
rpcclient_commands ,
lsarpc_commands ,
2002-10-04 23:33:41 +04:00
ds_commands ,
2001-05-24 04:20:32 +04:00
samr_commands ,
spoolss_commands ,
netlogon_commands ,
srvsvc_commands ,
2001-06-06 11:35:08 +04:00
dfs_commands ,
2003-04-14 06:08:03 +04:00
echo_commands ,
2009-01-06 21:09:57 +03:00
epmapper_commands ,
2003-10-24 17:49:29 +04:00
shutdown_commands ,
2005-09-30 21:13:37 +04:00
test_commands ,
2007-12-03 14:42:17 +03:00
wkssvc_commands ,
2008-02-18 01:16:56 +03:00
ntsvcs_commands ,
2008-05-24 03:28:22 +04:00
drsuapi_commands ,
2009-01-08 21:13:22 +03:00
eventlog_commands ,
2010-09-17 15:17:12 +04:00
winreg_commands ,
2001-05-24 04:20:32 +04:00
NULL
} ;
2001-10-12 09:56:23 +04:00
static void add_command_set ( struct cmd_set * cmd_set )
2001-01-12 01:49:30 +03:00
{
struct cmd_list * entry ;
2004-12-07 21:25:53 +03:00
if ( ! ( entry = SMB_MALLOC_P ( struct cmd_list ) ) ) {
2001-01-12 01:49:30 +03:00
DEBUG ( 0 , ( " out of memory \n " ) ) ;
return ;
}
ZERO_STRUCTP ( entry ) ;
entry - > cmd_set = cmd_set ;
DLIST_ADD ( cmd_list , entry ) ;
}
2003-02-26 02:53:38 +03:00
/**
* Call an rpcclient function , passing an argv array .
*
* @ param cmd Command to run , as a single string .
* */
static NTSTATUS do_cmd ( struct cli_state * cli ,
2008-12-14 15:06:19 +03:00
struct user_auth_info * auth_info ,
2003-02-26 02:53:38 +03:00
struct cmd_set * cmd_entry ,
2009-09-10 23:14:29 +04:00
struct dcerpc_binding * binding ,
2003-02-26 02:53:38 +03:00
int argc , char * * argv )
{
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
NTSTATUS ntresult ;
WERROR wresult ;
2010-09-17 23:16:24 +04:00
2003-02-26 02:53:38 +03:00
TALLOC_CTX * mem_ctx ;
2001-01-12 01:49:30 +03:00
2003-02-26 02:53:38 +03:00
/* Create mem_ctx */
2001-01-12 21:19:57 +03:00
2003-02-26 02:53:38 +03:00
if ( ! ( mem_ctx = talloc_init ( " do_cmd " ) ) ) {
DEBUG ( 0 , ( " talloc_init() failed \n " ) ) ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
return NT_STATUS_NO_MEMORY ;
2001-01-12 01:49:30 +03:00
}
2003-02-26 02:53:38 +03:00
/* Open pipe */
2001-10-12 09:56:23 +04:00
2012-01-10 14:53:42 +04:00
if ( ( cmd_entry - > table ! = NULL ) & & ( cmd_entry - > rpc_pipe = = NULL ) ) {
2005-09-30 21:13:37 +04:00
switch ( pipe_default_auth_type ) {
2010-07-20 21:26:36 +04:00
case DCERPC_AUTH_TYPE_NONE :
ntresult = cli_rpc_pipe_open_noauth_transport (
cli , default_transport ,
2012-01-10 14:53:42 +04:00
& cmd_entry - > table - > syntax_id ,
2010-07-20 21:26:36 +04:00
& cmd_entry - > rpc_pipe ) ;
break ;
case DCERPC_AUTH_TYPE_SPNEGO :
2012-01-10 14:03:02 +04:00
{
/* won't happen, but if it does it will fail in cli_rpc_pipe_open_spnego() eventually */
const char * oid = " INVALID " ;
2010-07-29 01:06:51 +04:00
switch ( pipe_default_auth_spnego_type ) {
case PIPE_AUTH_TYPE_SPNEGO_NTLMSSP :
2012-01-10 14:03:02 +04:00
oid = GENSEC_OID_NTLMSSP ;
2010-07-29 01:06:51 +04:00
break ;
case PIPE_AUTH_TYPE_SPNEGO_KRB5 :
2012-01-10 14:03:02 +04:00
oid = GENSEC_OID_KERBEROS5 ;
2010-07-29 01:06:51 +04:00
break ;
2010-07-20 21:26:36 +04:00
}
2012-01-10 14:03:02 +04:00
ntresult = cli_rpc_pipe_open_spnego (
2012-01-10 14:53:42 +04:00
cli , cmd_entry - > table ,
2012-01-10 14:03:02 +04:00
default_transport ,
oid ,
pipe_default_auth_level ,
2012-05-19 19:31:50 +04:00
smbXcli_conn_remote_name ( cli - > conn ) ,
2012-01-10 14:03:02 +04:00
get_cmdline_auth_info_domain ( auth_info ) ,
get_cmdline_auth_info_username ( auth_info ) ,
get_cmdline_auth_info_password ( auth_info ) ,
& cmd_entry - > rpc_pipe ) ;
2010-07-20 21:26:36 +04:00
break ;
2012-01-10 14:03:02 +04:00
}
2010-07-20 21:26:36 +04:00
case DCERPC_AUTH_TYPE_NTLMSSP :
2012-01-02 06:06:29 +04:00
case DCERPC_AUTH_TYPE_KRB5 :
2012-01-02 05:51:06 +04:00
ntresult = cli_rpc_pipe_open_generic_auth (
2012-01-10 14:53:42 +04:00
cli , cmd_entry - > table ,
2010-07-20 21:26:36 +04:00
default_transport ,
2012-01-02 05:51:06 +04:00
pipe_default_auth_type ,
2010-07-20 21:26:36 +04:00
pipe_default_auth_level ,
2012-05-19 19:31:50 +04:00
smbXcli_conn_remote_name ( cli - > conn ) ,
2010-07-20 21:26:36 +04:00
get_cmdline_auth_info_domain ( auth_info ) ,
get_cmdline_auth_info_username ( auth_info ) ,
get_cmdline_auth_info_password ( auth_info ) ,
& cmd_entry - > rpc_pipe ) ;
break ;
case DCERPC_AUTH_TYPE_SCHANNEL :
ntresult = cli_rpc_pipe_open_schannel (
2012-01-10 14:53:42 +04:00
cli , & cmd_entry - > table - > syntax_id ,
2010-07-20 21:26:36 +04:00
default_transport ,
pipe_default_auth_level ,
get_cmdline_auth_info_domain ( auth_info ) ,
& cmd_entry - > rpc_pipe ) ;
break ;
default :
DEBUG ( 0 , ( " Could not initialise %s. Invalid "
" auth type %u \n " ,
2012-01-10 14:53:42 +04:00
cmd_entry - > table - > name ,
2010-07-20 21:26:36 +04:00
pipe_default_auth_type ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
2005-09-30 21:13:37 +04:00
}
2008-07-20 13:04:31 +04:00
if ( ! NT_STATUS_IS_OK ( ntresult ) ) {
2005-09-30 21:13:37 +04:00
DEBUG ( 0 , ( " Could not initialise %s. Error was %s \n " ,
2012-01-10 14:53:42 +04:00
cmd_entry - > table - > name ,
2008-07-20 20:17:52 +04:00
nt_errstr ( ntresult ) ) ) ;
2005-09-30 21:13:37 +04:00
return ntresult ;
2003-05-08 12:02:52 +04:00
}
2003-07-30 21:29:00 +04:00
2012-01-10 14:53:42 +04:00
if ( ndr_syntax_id_equal ( & cmd_entry - > table - > syntax_id ,
2008-07-20 20:17:52 +04:00
& ndr_table_netlogon . syntax_id ) ) {
2008-04-02 04:29:48 +04:00
uint32_t neg_flags = NETLOGON_NEG_AUTH2_ADS_FLAGS ;
2009-10-13 12:15:34 +04:00
enum netr_SchannelType sec_channel_type ;
2005-09-30 21:13:37 +04:00
uchar trust_password [ 16 ] ;
2009-09-11 02:20:59 +04:00
const char * machine_account ;
if ( ! get_trust_pw_hash ( get_cmdline_auth_info_domain ( auth_info ) ,
trust_password , & machine_account ,
& sec_channel_type ) )
{
return NT_STATUS_CANT_ACCESS_DOMAIN_INFO ;
2005-09-30 21:13:37 +04:00
}
2009-09-11 02:20:59 +04:00
2005-09-30 21:13:37 +04:00
ntresult = rpccli_netlogon_setup_creds ( cmd_entry - > rpc_pipe ,
2011-07-22 18:45:12 +04:00
cmd_entry - > rpc_pipe - > desthost , /* server name */
2009-09-11 02:20:59 +04:00
get_cmdline_auth_info_domain ( auth_info ) , /* domain */
2011-06-09 09:31:03 +04:00
lp_netbios_name ( ) , /* client name */
2009-09-11 02:20:59 +04:00
machine_account , /* machine account name */
2005-09-30 21:13:37 +04:00
trust_password ,
sec_channel_type ,
& neg_flags ) ;
if ( ! NT_STATUS_IS_OK ( ntresult ) ) {
DEBUG ( 0 , ( " Could not initialise credentials for %s. \n " ,
2012-01-10 14:53:42 +04:00
cmd_entry - > table - > name ) ) ;
2005-09-30 21:13:37 +04:00
return ntresult ;
}
2003-02-26 02:53:38 +03:00
}
2003-04-09 19:54:17 +04:00
}
2001-10-12 09:56:23 +04:00
2005-09-30 21:13:37 +04:00
/* Run command */
2003-03-18 09:30:30 +03:00
2005-09-30 21:13:37 +04:00
if ( cmd_entry - > returntype = = RPC_RTYPE_NTSTATUS ) {
ntresult = cmd_entry - > ntfn ( cmd_entry - > rpc_pipe , mem_ctx , argc , ( const char * * ) argv ) ;
if ( ! NT_STATUS_IS_OK ( ntresult ) ) {
printf ( " result was %s \n " , nt_errstr ( ntresult ) ) ;
}
} else {
wresult = cmd_entry - > wfn ( cmd_entry - > rpc_pipe , mem_ctx , argc , ( const char * * ) argv ) ;
/* print out the DOS error */
if ( ! W_ERROR_IS_OK ( wresult ) ) {
2008-11-01 19:19:26 +03:00
printf ( " result was %s \n " , win_errstr ( wresult ) ) ;
2005-09-30 21:13:37 +04:00
}
ntresult = W_ERROR_IS_OK ( wresult ) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL ;
}
2001-10-12 09:56:23 +04:00
2003-02-26 02:53:38 +03:00
/* Cleanup */
2001-10-12 09:56:23 +04:00
2003-02-26 02:53:38 +03:00
talloc_destroy ( mem_ctx ) ;
2001-10-12 09:56:23 +04:00
2003-03-18 09:30:30 +03:00
return ntresult ;
2001-01-12 01:49:30 +03:00
}
2003-02-26 02:53:38 +03:00
/**
* Process a command entered at the prompt or as part of - c
*
* @ returns The NTSTATUS from running the command .
* */
2008-12-14 15:06:19 +03:00
static NTSTATUS process_cmd ( struct user_auth_info * auth_info ,
2009-09-10 23:14:29 +04:00
struct cli_state * cli ,
struct dcerpc_binding * binding ,
char * cmd )
2001-01-12 01:49:30 +03:00
{
struct cmd_list * temp_list ;
2001-09-04 11:13:01 +04:00
NTSTATUS result = NT_STATUS_OK ;
2003-02-26 02:53:38 +03:00
int ret ;
int argc ;
char * * argv = NULL ;
2001-05-04 08:15:48 +04:00
2003-02-26 02:53:38 +03:00
if ( ( ret = poptParseArgvString ( cmd , & argc , ( const char * * * ) & argv ) ) ! = 0 ) {
fprintf ( stderr , " rpcclient: %s \n " , poptStrerror ( ret ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
2001-01-12 01:49:30 +03:00
}
2003-02-26 02:53:38 +03:00
/* Walk through a dlist of arrays of commands. */
2001-01-12 01:49:30 +03:00
for ( temp_list = cmd_list ; temp_list ; temp_list = temp_list - > next ) {
struct cmd_set * temp_set = temp_list - > cmd_set ;
2003-02-26 02:53:38 +03:00
while ( temp_set - > name ) {
if ( strequal ( argv [ 0 ] , temp_set - > name ) ) {
2003-03-18 09:30:30 +03:00
if ( ! ( temp_set - > returntype = = RPC_RTYPE_NTSTATUS & & temp_set - > ntfn ) & &
! ( temp_set - > returntype = = RPC_RTYPE_WERROR & & temp_set - > wfn ) ) {
2003-02-26 02:53:38 +03:00
fprintf ( stderr , " Invalid command \n " ) ;
goto out_free ;
}
2008-12-14 15:06:19 +03:00
result = do_cmd ( cli , auth_info , temp_set ,
2009-09-10 23:14:29 +04:00
binding , argc , argv ) ;
2001-10-12 09:56:23 +04:00
2003-02-26 02:53:38 +03:00
goto out_free ;
2001-01-12 01:49:30 +03:00
}
temp_set + + ;
}
}
2003-02-26 02:53:38 +03:00
if ( argv [ 0 ] ) {
printf ( " command not found: %s \n " , argv [ 0 ] ) ;
2001-01-12 01:49:30 +03:00
}
2003-02-26 02:53:38 +03:00
out_free :
2003-03-18 09:30:30 +03:00
/* moved to do_cmd()
2001-09-04 11:13:01 +04:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
2002-03-17 07:36:35 +03:00
printf ( " result was %s \n " , nt_errstr ( result ) ) ;
2001-01-12 01:49:30 +03:00
}
2003-03-18 09:30:30 +03:00
*/
2001-01-12 01:49:30 +03:00
2006-03-12 20:44:00 +03:00
/* NOTE: popt allocates the whole argv, including the
* strings , as a single block . So a single free is
* enough to release it - - we don ' t free the
* individual strings . rtfm . */
free ( argv ) ;
2007-10-25 01:16:54 +04:00
2001-01-12 01:49:30 +03:00
return result ;
}
2001-03-14 23:22:57 +03:00
2001-01-12 01:49:30 +03:00
/* Main function */
1998-09-26 01:01:52 +04:00
2000-07-03 08:28:29 +04:00
int main ( int argc , char * argv [ ] )
1999-12-13 16:27:58 +03:00
{
2001-03-16 01:06:53 +03:00
int opt ;
2003-04-14 07:31:19 +04:00
static char * cmdstr = NULL ;
2002-07-15 14:35:28 +04:00
const char * server ;
2007-11-28 17:24:18 +03:00
struct cli_state * cli = NULL ;
2003-04-14 07:31:19 +04:00
static char * opt_ipaddr = NULL ;
2002-03-08 06:31:01 +03:00
struct cmd_set * * cmd_set ;
2007-10-25 01:16:54 +04:00
struct sockaddr_storage server_ss ;
2002-03-08 06:31:01 +03:00
NTSTATUS nt_status ;
2005-01-10 13:23:57 +03:00
static int opt_port = 0 ;
2007-11-28 17:24:18 +03:00
int result = 0 ;
TALLOC_CTX * frame = talloc_stackframe ( ) ;
2008-05-05 18:58:24 +04:00
uint32_t flags = 0 ;
2009-09-10 23:14:29 +04:00
struct dcerpc_binding * binding = NULL ;
const char * binding_string = NULL ;
2009-09-11 00:56:05 +04:00
char * user , * domain , * q ;
2002-03-08 06:31:01 +03:00
/* make sure the vars that get altered (4th field) are in
a fixed location or certain compilers complain */
2002-03-07 21:56:51 +03:00
poptContext pc ;
struct poptOption long_options [ ] = {
2002-09-25 19:19:00 +04:00
POPT_AUTOHELP
2002-10-28 22:45:47 +03:00
{ " command " , ' c ' , POPT_ARG_STRING , & cmdstr , ' c ' , " Execute semicolon separated cmds " , " COMMANDS " } ,
{ " dest-ip " , ' I ' , POPT_ARG_STRING , & opt_ipaddr , ' I ' , " Specify destination IP address " , " IP " } ,
2005-01-10 13:23:57 +03:00
{ " port " , ' p ' , POPT_ARG_INT , & opt_port , ' p ' , " Specify port number " , " PORT " } ,
2003-04-14 07:31:19 +04:00
POPT_COMMON_SAMBA
POPT_COMMON_CONNECTION
POPT_COMMON_CREDENTIALS
POPT_TABLEEND
2002-03-07 21:56:51 +03:00
} ;
2005-12-29 22:30:06 +03:00
load_case_tables ( ) ;
2008-12-03 10:29:57 +03:00
zero_sockaddr ( & server_ss ) ;
2003-03-18 09:30:30 +03:00
2001-01-12 01:49:30 +03:00
setlinebuf ( stdout ) ;
2003-04-28 11:05:50 +04:00
/* the following functions are part of the Samba debugging
facilities . See lib / debug . c */
2010-10-29 07:19:32 +04:00
setup_logging ( " rpcclient " , DEBUG_STDOUT ) ;
2007-10-25 01:16:54 +04:00
2008-12-14 15:06:19 +03:00
rpcclient_auth_info = user_auth_info_init ( frame ) ;
if ( rpcclient_auth_info = = NULL ) {
exit ( 1 ) ;
}
popt_common_set_auth_info ( rpcclient_auth_info ) ;
2002-02-26 23:04:54 +03:00
/* Parse options */
2002-03-07 07:03:21 +03:00
2002-09-25 19:19:00 +04:00
pc = poptGetContext ( " rpcclient " , argc , ( const char * * ) argv ,
long_options , 0 ) ;
2002-03-07 07:03:21 +03:00
if ( argc = = 1 ) {
2002-09-25 19:19:00 +04:00
poptPrintHelp ( pc , stderr , 0 ) ;
2007-11-28 17:24:18 +03:00
goto done ;
2002-02-26 23:04:54 +03:00
}
2007-10-25 01:16:54 +04:00
2002-03-07 21:56:51 +03:00
while ( ( opt = poptGetNextOpt ( pc ) ) ! = - 1 ) {
2001-01-12 01:49:30 +03:00
switch ( opt ) {
2002-07-15 14:35:28 +04:00
case ' I ' :
2007-10-25 01:16:54 +04:00
if ( ! interpret_string_addr ( & server_ss ,
opt_ipaddr ,
AI_NUMERICHOST ) ) {
2002-07-15 14:35:28 +04:00
fprintf ( stderr , " %s not a valid IP address \n " ,
opt_ipaddr ) ;
2007-11-28 17:24:18 +03:00
result = 1 ;
goto done ;
2002-07-15 14:35:28 +04:00
}
2001-01-12 01:49:30 +03:00
}
}
2001-07-08 22:25:56 +04:00
2002-07-15 14:35:28 +04:00
/* Get server as remaining unparsed argument. Print usage if more
than one unparsed argument is present . */
server = poptGetArg ( pc ) ;
2007-10-25 01:16:54 +04:00
2002-07-15 14:35:28 +04:00
if ( ! server | | poptGetArg ( pc ) ) {
2002-09-25 19:19:00 +04:00
poptPrintHelp ( pc , stderr , 0 ) ;
2007-11-28 17:24:18 +03:00
result = 1 ;
goto done ;
2002-07-15 14:35:28 +04:00
}
2002-04-04 08:29:09 +04:00
poptFreeContext ( pc ) ;
2007-11-28 17:24:18 +03:00
if ( ! init_names ( ) ) {
result = 1 ;
goto done ;
}
2006-02-08 02:30:31 +03:00
/* Load smb.conf file */
2011-07-27 18:36:14 +04:00
if ( ! lp_load_global ( get_dyn_CONFIGFILE ( ) ) )
2007-12-10 22:30:37 +03:00
fprintf ( stderr , " Can't load %s \n " , get_dyn_CONFIGFILE ( ) ) ;
2006-02-08 02:30:31 +03:00
2012-03-02 06:07:09 +04:00
/* We must load interfaces after we load the smb.conf */
load_interfaces ( ) ;
2001-03-14 23:22:57 +03:00
/*
2001-12-03 10:42:18 +03:00
* Get password
2001-03-14 23:22:57 +03:00
* from stdin if necessary
*/
2001-12-03 10:42:18 +03:00
2008-12-14 15:06:19 +03:00
if ( get_cmdline_auth_info_use_machine_account ( rpcclient_auth_info ) & &
! set_cmdline_auth_info_machine_account_creds ( rpcclient_auth_info ) ) {
2008-05-05 18:58:24 +04:00
result = 1 ;
goto done ;
}
2009-03-18 00:53:06 +03:00
set_cmdline_auth_info_getpass ( rpcclient_auth_info ) ;
2007-10-25 01:16:54 +04:00
2006-05-13 03:13:36 +04:00
if ( ( server [ 0 ] = = ' / ' & & server [ 1 ] = = ' / ' ) | |
( server [ 0 ] = = ' \\ ' & & server [ 1 ] = = ' \\ ' ) ) {
2006-05-11 22:59:41 +04:00
server + = 2 ;
}
2009-09-10 23:14:29 +04:00
nt_status = dcerpc_parse_binding ( frame , server , & binding ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
binding_string = talloc_asprintf ( frame , " ncacn_np:%s " ,
strip_hostname ( server ) ) ;
if ( ! binding_string ) {
result = 1 ;
goto done ;
}
nt_status = dcerpc_parse_binding ( frame , binding_string , & binding ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
result = - 1 ;
goto done ;
}
}
if ( binding - > transport = = NCA_UNKNOWN ) {
binding - > transport = NCACN_NP ;
}
2009-11-12 18:45:33 +03:00
if ( binding - > flags & DCERPC_SIGN ) {
pipe_default_auth_level = DCERPC_AUTH_LEVEL_INTEGRITY ;
2010-07-20 21:26:36 +04:00
pipe_default_auth_type = DCERPC_AUTH_TYPE_NTLMSSP ;
2009-11-12 18:45:33 +03:00
}
if ( binding - > flags & DCERPC_SEAL ) {
pipe_default_auth_level = DCERPC_AUTH_LEVEL_PRIVACY ;
2010-07-20 21:26:36 +04:00
pipe_default_auth_type = DCERPC_AUTH_TYPE_NTLMSSP ;
2009-11-12 18:45:33 +03:00
}
if ( binding - > flags & DCERPC_AUTH_SPNEGO ) {
2010-07-20 21:26:36 +04:00
pipe_default_auth_type = DCERPC_AUTH_TYPE_SPNEGO ;
pipe_default_auth_spnego_type = PIPE_AUTH_TYPE_SPNEGO_NTLMSSP ;
2009-11-12 18:45:33 +03:00
}
if ( binding - > flags & DCERPC_AUTH_NTLM ) {
2010-07-30 04:07:19 +04:00
/* If neither Integrity or Privacy are requested then
* Use just Connect level */
if ( pipe_default_auth_level = = DCERPC_AUTH_LEVEL_NONE ) {
pipe_default_auth_level = DCERPC_AUTH_LEVEL_CONNECT ;
}
2010-07-21 01:26:32 +04:00
if ( pipe_default_auth_type = = DCERPC_AUTH_TYPE_SPNEGO ) {
pipe_default_auth_spnego_type = PIPE_AUTH_TYPE_SPNEGO_NTLMSSP ;
} else {
pipe_default_auth_type = DCERPC_AUTH_TYPE_NTLMSSP ;
}
2009-11-12 18:45:33 +03:00
}
if ( binding - > flags & DCERPC_AUTH_KRB5 ) {
2010-07-21 20:11:37 +04:00
/* If neither Integrity or Privacy are requested then
* Use just Connect level */
if ( pipe_default_auth_level = = DCERPC_AUTH_LEVEL_NONE ) {
pipe_default_auth_level = DCERPC_AUTH_LEVEL_CONNECT ;
}
2010-07-21 01:26:32 +04:00
if ( pipe_default_auth_type = = DCERPC_AUTH_TYPE_SPNEGO ) {
pipe_default_auth_spnego_type = PIPE_AUTH_TYPE_SPNEGO_KRB5 ;
} else {
pipe_default_auth_type = DCERPC_AUTH_TYPE_KRB5 ;
}
2009-11-12 18:45:33 +03:00
}
2008-12-14 15:06:19 +03:00
if ( get_cmdline_auth_info_use_kerberos ( rpcclient_auth_info ) ) {
2008-05-05 18:58:24 +04:00
flags | = CLI_FULL_CONNECTION_USE_KERBEROS |
CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS ;
}
2010-01-24 19:35:04 +03:00
if ( get_cmdline_auth_info_use_ccache ( rpcclient_auth_info ) ) {
flags | = CLI_FULL_CONNECTION_USE_CCACHE ;
}
2008-05-05 18:58:24 +04:00
2009-09-11 00:56:05 +04:00
user = talloc_strdup ( frame , get_cmdline_auth_info_username ( rpcclient_auth_info ) ) ;
SMB_ASSERT ( user ! = NULL ) ;
domain = talloc_strdup ( frame , lp_workgroup ( ) ) ;
SMB_ASSERT ( domain ! = NULL ) ;
set_cmdline_auth_info_domain ( rpcclient_auth_info , domain ) ;
if ( ( q = strchr_m ( user , ' \\ ' ) ) ) {
* q = 0 ;
set_cmdline_auth_info_domain ( rpcclient_auth_info , user ) ;
set_cmdline_auth_info_username ( rpcclient_auth_info , q + 1 ) ;
}
2008-05-05 18:58:24 +04:00
2011-06-09 09:31:03 +04:00
nt_status = cli_full_connection ( & cli , lp_netbios_name ( ) , binding - > host ,
2007-10-25 01:16:54 +04:00
opt_ipaddr ? & server_ss : NULL , opt_port ,
" IPC$ " , " IPC " ,
2008-12-14 15:06:19 +03:00
get_cmdline_auth_info_username ( rpcclient_auth_info ) ,
2009-09-11 00:56:05 +04:00
get_cmdline_auth_info_domain ( rpcclient_auth_info ) ,
2008-12-14 15:06:19 +03:00
get_cmdline_auth_info_password ( rpcclient_auth_info ) ,
2008-05-05 18:58:24 +04:00
flags ,
2010-12-20 18:37:23 +03:00
get_cmdline_auth_info_signing_state ( rpcclient_auth_info ) ) ;
2007-10-25 01:16:54 +04:00
2001-12-03 10:42:18 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2002-08-17 19:33:49 +04:00
DEBUG ( 0 , ( " Cannot connect to server. Error was %s \n " , nt_errstr ( nt_status ) ) ) ;
2007-11-28 17:24:18 +03:00
result = 1 ;
goto done ;
2001-03-14 23:22:57 +03:00
}
2001-05-24 04:20:32 +04:00
2008-12-14 15:06:19 +03:00
if ( get_cmdline_auth_info_smb_encrypt ( rpcclient_auth_info ) ) {
2008-01-05 11:23:35 +03:00
nt_status = cli_cm_force_encryption ( cli ,
2008-12-14 15:06:19 +03:00
get_cmdline_auth_info_username ( rpcclient_auth_info ) ,
get_cmdline_auth_info_password ( rpcclient_auth_info ) ,
2009-09-11 00:56:05 +04:00
get_cmdline_auth_info_domain ( rpcclient_auth_info ) ,
2008-01-05 11:23:35 +03:00
" IPC$ " ) ;
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
result = 1 ;
goto done ;
}
}
2005-09-30 21:13:37 +04:00
#if 0 /* COMMENT OUT FOR TESTING */
2003-04-14 07:31:19 +04:00
memset ( cmdline_auth_info . password , ' X ' , sizeof ( cmdline_auth_info . password ) ) ;
2005-09-30 21:13:37 +04:00
# endif
2001-12-03 10:42:18 +03:00
2001-03-14 23:22:57 +03:00
/* Load command lists */
2001-03-16 01:06:53 +03:00
2006-10-17 03:27:38 +04:00
timeout = cli_set_timeout ( cli , 10000 ) ;
2001-05-24 04:20:32 +04:00
cmd_set = rpcclient_command_list ;
2001-03-16 01:06:53 +03:00
2001-05-24 04:20:32 +04:00
while ( * cmd_set ) {
add_command_set ( * cmd_set ) ;
add_command_set ( separator_command ) ;
cmd_set + + ;
}
2001-01-12 01:49:30 +03:00
2009-09-10 23:14:29 +04:00
default_transport = binding - > transport ;
2001-12-03 10:42:18 +03:00
fetch_machine_sid ( cli ) ;
2007-10-25 01:16:54 +04:00
2001-10-22 10:13:38 +04:00
/* Do anything specified with -c */
2003-04-14 07:31:19 +04:00
if ( cmdstr & & cmdstr [ 0 ] ) {
2001-05-31 22:35:14 +04:00
char * cmd ;
char * p = cmdstr ;
2007-11-28 17:24:18 +03:00
result = 0 ;
2007-10-25 01:16:54 +04:00
2001-05-31 22:35:14 +04:00
while ( ( cmd = next_command ( & p ) ) ! = NULL ) {
2009-09-10 23:14:29 +04:00
NTSTATUS cmd_result = process_cmd ( rpcclient_auth_info , cli ,
binding , cmd ) ;
2007-06-07 05:13:43 +04:00
SAFE_FREE ( cmd ) ;
2003-04-28 09:54:37 +04:00
result = NT_STATUS_IS_ERR ( cmd_result ) ;
2001-05-31 22:35:14 +04:00
}
2007-10-25 01:16:54 +04:00
2007-11-28 17:24:18 +03:00
goto done ;
2001-05-31 22:35:14 +04:00
}
2001-01-12 01:49:30 +03:00
2001-03-14 23:22:57 +03:00
/* Loop around accepting commands */
2001-05-24 04:20:32 +04:00
2001-01-12 01:49:30 +03:00
while ( 1 ) {
2007-12-07 04:16:33 +03:00
char * line = NULL ;
2001-01-12 21:19:57 +03:00
2007-11-21 02:31:37 +03:00
line = smb_readline ( " rpcclient $> " , NULL , completion_fn ) ;
2001-01-12 01:49:30 +03:00
2001-05-04 05:04:23 +04:00
if ( line = = NULL )
break ;
if ( line [ 0 ] ! = ' \n ' )
2009-09-10 23:14:29 +04:00
process_cmd ( rpcclient_auth_info , cli , binding , line ) ;
2007-12-07 04:16:33 +03:00
SAFE_FREE ( line ) ;
2001-01-12 01:49:30 +03:00
}
2007-10-25 01:16:54 +04:00
2007-11-28 17:24:18 +03:00
done :
if ( cli ! = NULL ) {
cli_shutdown ( cli ) ;
}
TALLOC_FREE ( frame ) ;
return result ;
2001-05-04 05:04:23 +04:00
}