2010-08-17 02:46:25 +04:00
/*
* Unix SMB / CIFS implementation .
* RPC Pipe client / server routines
* Largely rewritten by Jeremy Allison 2005.
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
# include "../librpc/gen_ndr/ndr_schannel.h"
# include "../librpc/gen_ndr/ndr_netlogon.h"
# include "../libcli/auth/schannel.h"
# include "rpc_client/cli_netlogon.h"
2011-02-28 12:19:44 +03:00
# include "rpc_client/cli_pipe.h"
2010-08-17 02:46:25 +04:00
# include "librpc/rpc/dcerpc.h"
2011-03-22 18:50:02 +03:00
# include "passdb.h"
2011-07-22 18:44:28 +04:00
# include "libsmb/libsmb.h"
2012-05-19 19:31:50 +04:00
# include "../libcli/smb/smbXcli_base.h"
2013-09-11 12:06:41 +04:00
# include "libcli/auth/netlogon_creds_cli.h"
2010-08-17 02:46:25 +04:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_RPC_CLI
/****************************************************************************
Open a named pipe to an SMB server and bind using schannel ( bind type 68 ) .
Fetch the session key ourselves using a temporary netlogon pipe .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NTSTATUS cli_rpc_pipe_open_schannel ( struct cli_state * cli ,
2013-09-16 22:53:51 +04:00
struct messaging_context * msg_ctx ,
2013-05-24 15:03:23 +04:00
const struct ndr_interface_table * table ,
2010-08-17 02:46:25 +04:00
enum dcerpc_transport_t transport ,
const char * domain ,
2013-09-16 22:53:51 +04:00
struct rpc_pipe_client * * presult ,
TALLOC_CTX * mem_ctx ,
struct netlogon_creds_cli_context * * pcreds )
2010-08-17 02:46:25 +04:00
{
2013-09-11 12:06:41 +04:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
const char * dc_name = smbXcli_conn_remote_name ( cli - > conn ) ;
2010-08-17 02:46:25 +04:00
struct rpc_pipe_client * result = NULL ;
NTSTATUS status ;
2015-02-09 11:34:45 +03:00
struct cli_credentials * cli_creds = NULL ;
2013-09-11 12:06:41 +04:00
struct netlogon_creds_cli_context * netlogon_creds = NULL ;
2015-02-09 11:34:45 +03:00
status = pdb_get_trust_credentials ( domain , NULL ,
frame , & cli_creds ) ;
2013-09-11 12:06:41 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
TALLOC_FREE ( frame ) ;
return status ;
}
2010-08-17 02:46:25 +04:00
2015-02-09 11:34:45 +03:00
status = rpccli_create_netlogon_creds_with_creds ( cli_creds ,
dc_name ,
msg_ctx ,
frame ,
& netlogon_creds ) ;
2010-08-17 02:46:25 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2013-09-11 12:06:41 +04:00
TALLOC_FREE ( frame ) ;
2010-08-17 02:46:25 +04:00
return status ;
}
2015-02-09 11:34:45 +03:00
status = rpccli_setup_netlogon_creds_with_creds ( cli , transport ,
netlogon_creds ,
false , /* force_reauth */
cli_creds ) ;
2013-09-11 12:06:41 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
TALLOC_FREE ( frame ) ;
return status ;
}
2010-08-17 02:46:25 +04:00
2015-02-09 11:34:45 +03:00
status = cli_rpc_pipe_open_schannel_with_creds ( cli , table , transport ,
cli_creds , netlogon_creds ,
& result ) ;
2010-08-17 02:46:25 +04:00
if ( NT_STATUS_IS_OK ( status ) ) {
* presult = result ;
2013-09-16 22:53:51 +04:00
if ( pcreds ! = NULL ) {
* pcreds = talloc_move ( mem_ctx , & netlogon_creds ) ;
}
2010-08-17 02:46:25 +04:00
}
2013-09-11 12:06:41 +04:00
TALLOC_FREE ( frame ) ;
2010-08-17 02:46:25 +04:00
return status ;
}