1998-03-12 00:11:04 +03:00
/*
2002-01-30 09:08:46 +03:00
* Unix SMB / CIFS implementation .
1998-03-12 00:11:04 +03:00
* RPC Pipe client / server routines
* Copyright ( C ) Andrew Tridgell 1992 - 1997 ,
* Copyright ( C ) Luke Kenneth Casson Leighton 1996 - 1997 ,
* Copyright ( C ) Paul Ashton 1997.
1998-04-28 05:24:40 +04:00
* Copyright ( C ) Jeremy Allison 1998.
*
1998-03-12 00:11:04 +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
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
1999-12-13 16:27:58 +03:00
extern pstring global_myname ;
extern fstring global_myworkgroup ;
1998-03-12 00:11:04 +03:00
1998-04-29 04:02:57 +04:00
/****************************************************************************
Generate the next creds to use .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
static void gen_next_creds ( struct cli_state * cli , DOM_CRED * new_clnt_cred )
1998-04-29 04:02:57 +04:00
{
/*
* Create the new client credentials .
*/
cli - > clnt_cred . timestamp . time = time ( NULL ) ;
memcpy ( new_clnt_cred , & cli - > clnt_cred , sizeof ( * new_clnt_cred ) ) ;
/* Calculate the new credentials. */
cred_create ( cli - > sess_key , & ( cli - > clnt_cred . challenge ) ,
new_clnt_cred - > timestamp , & ( new_clnt_cred - > challenge ) ) ;
1998-04-29 23:22:01 +04:00
1998-04-29 04:02:57 +04:00
}
1999-12-13 16:27:58 +03:00
# if UNUSED_CODE
1998-03-12 00:11:04 +03:00
/****************************************************************************
do a LSA Logon Control2
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-08-27 23:46:22 +04:00
BOOL cli_net_logon_ctrl2 ( struct cli_state * cli , NTSTATUS status_level )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
prs_struct rbuf ;
prs_struct buf ;
NET_Q_LOGON_CTRL2 q_l ;
BOOL ok = False ;
1998-03-12 00:11:04 +03:00
2001-03-10 02:48:58 +03:00
prs_init ( & buf , 1024 , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
/* create and send a MSRPC command with api NET_LOGON_CTRL2 */
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
DEBUG ( 4 , ( " do_net_logon_ctrl2 from %s status level:%x \n " ,
global_myname , status_level ) ) ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
/* store the parameters */
2001-07-04 11:15:53 +04:00
init_q_logon_ctrl2 ( & q_l , cli - > srv_name_slash ,
2001-02-14 08:34:50 +03:00
status_level ) ;
1998-04-24 02:45:53 +04:00
1999-12-13 16:27:58 +03:00
/* turn parameters into data stream */
if ( ! net_io_q_logon_ctrl2 ( " " , & q_l , & buf , 0 ) ) {
DEBUG ( 0 , ( " cli_net_logon_ctrl2: Error : failed to marshall NET_Q_LOGON_CTRL2 struct. \n " ) ) ;
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
1998-04-24 02:45:53 +04:00
1999-12-13 16:27:58 +03:00
/* send the data on \PIPE\ */
if ( rpc_api_pipe_req ( cli , NET_LOGON_CTRL2 , & buf , & rbuf ) )
{
NET_R_LOGON_CTRL2 r_l ;
1999-11-29 22:46:57 +03:00
1999-12-13 16:27:58 +03:00
/*
* Unmarshall the return buffer .
*/
ok = net_io_r_logon_ctrl2 ( " " , & r_l , & rbuf , 0 ) ;
if ( ok & & r_l . status ! = 0 )
{
/* report error code */
2002-03-17 07:36:35 +03:00
DEBUG ( 0 , ( " do_net_logon_ctrl2: Error %s \n " , nt_errstr ( r_l . status ) ) ) ;
1999-12-13 16:27:58 +03:00
cli - > nt_error = r_l . status ;
ok = False ;
}
}
1999-11-29 22:46:57 +03:00
1999-12-13 16:27:58 +03:00
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
1999-11-29 22:46:57 +03:00
1999-12-13 16:27:58 +03:00
return ok ;
1998-03-12 00:11:04 +03:00
}
1999-12-13 16:27:58 +03:00
# endif
1998-03-12 00:11:04 +03:00
/****************************************************************************
1998-04-28 05:24:40 +04:00
LSA Authenticate 2
Send the client credential , receive back a server credential .
Ensure that the server credential returned matches the session key
encrypt of the server challenge originally received . JRA .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-04-24 02:45:53 +04:00
2001-09-18 06:49:35 +04:00
NTSTATUS cli_net_auth2 ( struct cli_state * cli , uint16 sec_chan ,
uint32 neg_flags , DOM_CHAL * srv_chal )
1998-03-12 00:11:04 +03:00
{
1999-12-13 16:27:58 +03:00
prs_struct rbuf ;
prs_struct buf ;
NET_Q_AUTH_2 q_a ;
BOOL ok = False ;
2001-09-18 06:49:35 +04:00
NTSTATUS result = NT_STATUS_UNSUCCESSFUL ;
1999-12-13 16:27:58 +03:00
2001-03-10 02:48:58 +03:00
prs_init ( & buf , 1024 , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
1999-12-13 16:27:58 +03:00
/* create and send a MSRPC command with api NET_AUTH2 */
DEBUG ( 4 , ( " cli_net_auth2: srv:%s acct:%s sc:%x mc: %s chal %s neg: %x \n " ,
2001-02-14 08:34:50 +03:00
cli - > srv_name_slash , cli - > mach_acct , sec_chan , global_myname ,
credstr ( cli - > clnt_cred . challenge . data ) , neg_flags ) ) ;
1999-12-13 16:27:58 +03:00
/* store the parameters */
2001-07-04 11:15:53 +04:00
init_q_auth_2 ( & q_a , cli - > srv_name_slash , cli - > mach_acct ,
2001-02-14 08:34:50 +03:00
sec_chan , global_myname , & cli - > clnt_cred . challenge , neg_flags ) ;
1999-12-13 16:27:58 +03:00
/* turn parameters into data stream */
if ( ! net_io_q_auth_2 ( " " , & q_a , & buf , 0 ) ) {
DEBUG ( 0 , ( " cli_net_auth2: Error : failed to marshall NET_Q_AUTH_2 struct. \n " ) ) ;
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
2001-09-18 06:49:35 +04:00
return result ;
1999-12-13 16:27:58 +03:00
}
/* send the data on \PIPE\ */
if ( rpc_api_pipe_req ( cli , NET_AUTH2 , & buf , & rbuf ) )
{
NET_R_AUTH_2 r_a ;
ok = net_io_r_auth_2 ( " " , & r_a , & rbuf , 0 ) ;
2001-09-18 06:49:35 +04:00
result = r_a . status ;
if ( ok & & ! NT_STATUS_IS_OK ( result ) )
1999-12-13 16:27:58 +03:00
{
/* report error code */
2002-03-17 07:36:35 +03:00
DEBUG ( 0 , ( " cli_net_auth2: Error %s \n " , nt_errstr ( result ) ) ) ;
1999-12-13 16:27:58 +03:00
ok = False ;
}
if ( ok )
{
/*
* Check the returned value using the initial
* server received challenge .
*/
UTIME zerotime ;
zerotime . time = 0 ;
if ( cred_assert ( & r_a . srv_chal , cli - > sess_key , srv_chal , zerotime ) = = 0 ) {
/*
* Server replied with bad credential . Fail .
*/
DEBUG ( 0 , ( " cli_net_auth2: server %s replied with bad credential (bad machine \
password ? ) . \ n " , cli->desthost ));
ok = False ;
}
}
1998-04-28 05:24:40 +04:00
1998-11-20 23:44:21 +03:00
#if 0
1999-12-13 16:27:58 +03:00
/*
* Try commenting this out to see if this makes the connect
* work for a NT 3.51 PDC . JRA .
*/
1998-04-24 02:45:53 +04:00
1999-12-13 16:27:58 +03:00
if ( ok & & r_a . srv_flgs . neg_flags ! = q_a . clnt_flgs . neg_flags )
{
/* report different neg_flags */
DEBUG ( 0 , ( " cli_net_auth2: error neg_flags (q,r) differ - (%x,%x) \n " ,
q_a . clnt_flgs . neg_flags , r_a . srv_flgs . neg_flags ) ) ;
ok = False ;
}
# endif
1998-04-24 02:45:53 +04:00
1999-12-13 16:27:58 +03:00
}
1999-10-21 20:53:50 +04:00
1999-12-13 16:27:58 +03:00
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
1998-04-24 02:45:53 +04:00
2001-09-18 06:49:35 +04:00
return result ;
1998-03-12 00:11:04 +03:00
}
/****************************************************************************
1998-04-28 05:24:40 +04:00
LSA Request Challenge . Sends our challenge to server , then gets
server response . These are used to generate the credentials .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-04-24 02:45:53 +04:00
1999-12-13 16:27:58 +03:00
BOOL cli_net_req_chal ( struct cli_state * cli , DOM_CHAL * clnt_chal , DOM_CHAL * srv_chal )
1998-03-12 00:11:04 +03:00
{
1998-04-24 02:45:53 +04:00
prs_struct rbuf ;
prs_struct buf ;
NET_Q_REQ_CHAL q_c ;
1999-12-13 16:27:58 +03:00
BOOL valid_chal = False ;
1998-03-12 00:11:04 +03:00
2001-03-10 02:48:58 +03:00
prs_init ( & buf , 1024 , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
1998-03-12 00:11:04 +03:00
1998-04-24 02:45:53 +04:00
/* create and send a MSRPC command with api NET_REQCHAL */
1998-03-12 00:11:04 +03:00
1998-04-25 05:12:08 +04:00
DEBUG ( 4 , ( " cli_net_req_chal: LSA Request Challenge from %s to %s: %s \n " ,
1999-12-13 16:27:58 +03:00
cli - > desthost , global_myname , credstr ( clnt_chal - > data ) ) ) ;
1998-03-12 00:11:04 +03:00
1998-04-24 02:45:53 +04:00
/* store the parameters */
2001-07-04 11:15:53 +04:00
init_q_req_chal ( & q_c , cli - > srv_name_slash ,
2001-02-14 08:34:50 +03:00
global_myname , clnt_chal ) ;
1998-03-12 00:11:04 +03:00
1998-04-24 02:45:53 +04:00
/* turn parameters into data stream */
1999-12-13 16:27:58 +03:00
if ( ! net_io_q_req_chal ( " " , & q_c , & buf , 0 ) ) {
DEBUG ( 0 , ( " cli_net_req_chal: Error : failed to marshall NET_Q_REQ_CHAL struct. \n " ) ) ;
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
1998-03-12 00:11:04 +03:00
1998-04-24 02:45:53 +04:00
/* send the data on \PIPE\ */
1999-12-13 16:27:58 +03:00
if ( rpc_api_pipe_req ( cli , NET_REQCHAL , & buf , & rbuf ) )
1998-04-24 02:45:53 +04:00
{
NET_R_REQ_CHAL r_c ;
1999-12-13 16:27:58 +03:00
BOOL ok ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
ok = net_io_r_req_chal ( " " , & r_c , & rbuf , 0 ) ;
1998-03-12 00:11:04 +03:00
2001-09-04 11:13:01 +04:00
if ( ok & & ! NT_STATUS_IS_OK ( r_c . status ) )
1998-04-24 02:45:53 +04:00
{
/* report error code */
2002-03-17 07:36:35 +03:00
DEBUG ( 0 , ( " cli_net_req_chal: Error %s \n " , nt_errstr ( r_c . status ) ) ) ;
1999-12-13 16:27:58 +03:00
ok = False ;
1998-04-24 02:45:53 +04:00
}
1999-12-13 16:27:58 +03:00
if ( ok )
1998-04-24 02:45:53 +04:00
{
/* ok, at last: we're happy. return the challenge */
memcpy ( srv_chal , r_c . srv_chal . data , sizeof ( srv_chal - > data ) ) ;
1999-12-13 16:27:58 +03:00
valid_chal = True ;
1998-04-24 02:45:53 +04:00
}
}
1999-12-13 16:27:58 +03:00
prs_mem_free ( & buf ) ;
1998-04-24 02:45:53 +04:00
prs_mem_free ( & rbuf ) ;
1999-12-13 16:27:58 +03:00
return valid_chal ;
1998-03-12 00:11:04 +03:00
}
/***************************************************************************
2001-02-24 03:42:41 +03:00
LSA SAM Logon internal - interactive or network . Does level 2 or 3 but always
returns level 3.
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-04-24 02:45:53 +04:00
2001-09-04 11:13:01 +04:00
static NTSTATUS cli_net_sam_logon_internal ( struct cli_state * cli , NET_ID_INFO_CTR * ctr ,
NET_USER_INFO_3 * user_info3 ,
uint16 validation_level )
1998-03-12 00:11:04 +03:00
{
2001-02-24 03:42:41 +03:00
DOM_CRED new_clnt_cred ;
DOM_CRED dummy_rtn_creds ;
prs_struct rbuf ;
prs_struct buf ;
NET_Q_SAM_LOGON q_s ;
NET_R_SAM_LOGON r_s ;
2001-09-04 11:13:01 +04:00
NTSTATUS retval = NT_STATUS_OK ;
1998-04-24 02:45:53 +04:00
2001-02-24 03:42:41 +03:00
gen_next_creds ( cli , & new_clnt_cred ) ;
1999-11-29 22:46:57 +03:00
2001-03-10 02:48:58 +03:00
prs_init ( & buf , 1024 , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
1998-03-12 00:11:04 +03:00
2001-02-24 03:42:41 +03:00
/* create and send a MSRPC command with api NET_SAMLOGON */
1998-03-12 00:11:04 +03:00
2001-02-24 03:42:41 +03:00
DEBUG ( 4 , ( " cli_net_sam_logon_internal: srv:%s mc:%s clnt %s %x ll: %d \n " ,
1999-12-13 16:27:58 +03:00
cli - > srv_name_slash , global_myname ,
credstr ( new_clnt_cred . challenge . data ) , cli - > clnt_cred . timestamp . time ,
1998-04-28 05:24:40 +04:00
ctr - > switch_value ) ) ;
1998-03-12 00:11:04 +03:00
2001-02-24 03:42:41 +03:00
memset ( & dummy_rtn_creds , ' \0 ' , sizeof ( dummy_rtn_creds ) ) ;
1998-10-27 18:03:47 +03:00
dummy_rtn_creds . timestamp . time = time ( NULL ) ;
1998-04-29 23:22:01 +04:00
2001-02-24 03:42:41 +03:00
/* store the parameters */
q_s . validation_level = validation_level ;
2001-07-04 11:15:53 +04:00
init_sam_info ( & q_s . sam_id , cli - > srv_name_slash ,
2001-02-14 08:34:50 +03:00
global_myname , & new_clnt_cred , & dummy_rtn_creds ,
ctr - > switch_value , ctr ) ;
1999-12-01 23:18:21 +03:00
2001-02-24 03:42:41 +03:00
/* turn parameters into data stream */
if ( ! net_io_q_sam_logon ( " " , & q_s , & buf , 0 ) ) {
DEBUG ( 0 , ( " cli_net_sam_logon_internal: Error : failed to marshall NET_Q_SAM_LOGON struct. \n " ) ) ;
retval = NT_STATUS_NO_MEMORY ;
goto out ;
}
/* send the data on \PIPE\ */
if ( ! rpc_api_pipe_req ( cli , NET_SAMLOGON , & buf , & rbuf ) ) {
2001-10-30 03:19:43 +03:00
DEBUG ( 0 , ( " cli_net_sam_logon_internal: Error rpc_api_pipe_req failed. \n " ) ) ;
2001-10-31 07:42:16 +03:00
retval = NT_STATUS_UNSUCCESSFUL ;
2001-02-24 03:42:41 +03:00
goto out ;
}
r_s . user = user_info3 ;
if ( ! net_io_r_sam_logon ( " " , & r_s , & rbuf , 0 ) ) {
DEBUG ( 0 , ( " cli_net_sam_logon_internal: Error : failed to unmarshal NET_R_SAM_LOGON struct. \n " ) ) ;
retval = NT_STATUS_NO_MEMORY ;
goto out ;
}
1998-03-12 00:11:04 +03:00
2001-02-24 03:42:41 +03:00
retval = r_s . status ;
/*
* Don ' t treat NT_STATUS_INVALID_INFO_CLASS as an error - we will re - issue
* the call .
*/
2001-09-04 11:13:01 +04:00
if ( NT_STATUS_V ( retval ) = = NT_STATUS_V ( NT_STATUS_INVALID_INFO_CLASS ) ) {
2001-02-24 03:42:41 +03:00
goto out ;
}
2001-09-04 11:13:01 +04:00
if ( ! NT_STATUS_IS_OK ( retval ) ) {
2001-02-24 03:42:41 +03:00
/* report error code */
2002-03-17 07:36:35 +03:00
DEBUG ( 0 , ( " cli_net_sam_logon_internal: %s \n " , nt_errstr ( r_s . status ) ) ) ;
2001-02-24 03:42:41 +03:00
goto out ;
2001-09-04 11:13:01 +04:00
}
1998-04-24 02:45:53 +04:00
2001-09-04 11:13:01 +04:00
/* Update the credentials. */
if ( ! clnt_deal_with_creds ( cli - > sess_key , & cli - > clnt_cred , & r_s . srv_creds ) ) {
2001-02-24 03:42:41 +03:00
/*
* Server replied with bad credential . Fail .
*/
DEBUG ( 0 , ( " cli_net_sam_logon_internal: server %s replied with bad credential (bad machine \
1999-12-13 16:27:58 +03:00
password ? ) . \ n " , cli->desthost ));
2001-02-24 03:42:41 +03:00
retval = NT_STATUS_WRONG_PASSWORD ;
2001-09-04 11:13:01 +04:00
}
if ( r_s . switch_value ! = validation_level ) {
2001-02-24 03:42:41 +03:00
/* report different switch_value */
2001-02-25 03:24:54 +03:00
DEBUG ( 0 , ( " cli_net_sam_logon: switch_value of %x expected %x \n " , ( unsigned int ) validation_level ,
2001-09-04 11:13:01 +04:00
( unsigned int ) r_s . switch_value ) ) ;
2001-02-24 03:42:41 +03:00
retval = NT_STATUS_INVALID_PARAMETER ;
2001-09-04 11:13:01 +04:00
}
1998-04-24 02:45:53 +04:00
2001-09-04 11:13:01 +04:00
out :
1998-04-24 02:45:53 +04:00
2001-02-24 03:42:41 +03:00
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
2001-09-04 11:13:01 +04:00
2001-02-24 03:42:41 +03:00
return retval ;
}
/***************************************************************************
LSA SAM Logon - interactive or network .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-09-04 11:13:01 +04:00
NTSTATUS cli_net_sam_logon ( struct cli_state * cli , NET_ID_INFO_CTR * ctr ,
2001-08-25 00:31:00 +04:00
NET_USER_INFO_3 * user_info3 )
2001-02-24 03:42:41 +03:00
{
uint16 validation_level = 3 ;
2001-09-04 11:13:01 +04:00
NTSTATUS result ;
2001-02-24 03:42:41 +03:00
2001-08-25 00:31:00 +04:00
result = cli_net_sam_logon_internal ( cli , ctr , user_info3 ,
validation_level ) ;
2001-02-24 03:42:41 +03:00
2001-09-04 11:13:01 +04:00
if ( NT_STATUS_IS_OK ( result ) ) {
2001-02-24 03:42:41 +03:00
DEBUG ( 10 , ( " cli_net_sam_logon: Success \n " ) ) ;
2001-09-04 11:13:01 +04:00
} else if ( NT_STATUS_V ( result ) = = NT_STATUS_V ( NT_STATUS_INVALID_INFO_CLASS ) ) {
2001-02-24 03:42:41 +03:00
DEBUG ( 10 , ( " cli_net_sam_logon: STATUS INVALID INFO CLASS \n " ) ) ;
validation_level = 2 ;
/*
* Since this is the second time we call this function , don ' t care
* for the error . If its error , return False .
*/
2001-08-25 00:31:00 +04:00
result = cli_net_sam_logon_internal ( cli , ctr , user_info3 ,
validation_level ) ;
2001-02-24 03:42:41 +03:00
}
2001-08-25 00:31:00 +04:00
return result ;
1998-03-12 00:11:04 +03:00
}
/***************************************************************************
1998-04-28 05:24:40 +04:00
LSA SAM Logoff .
1998-04-29 23:22:01 +04:00
This currently doesnt work correctly as the domain controller
returns NT_STATUS_INVALID_INFO_CLASS - we obviously need to
send a different info level . Right now though , I ' m not sure
what that needs to be ( I need to see one on the wire before
I can be sure ) . JRA .
1998-03-12 00:11:04 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
BOOL cli_net_sam_logoff ( struct cli_state * cli , NET_ID_INFO_CTR * ctr )
1998-03-12 00:11:04 +03:00
{
1998-04-28 05:24:40 +04:00
DOM_CRED new_clnt_cred ;
1998-04-29 23:22:01 +04:00
DOM_CRED dummy_rtn_creds ;
1998-04-24 02:45:53 +04:00
prs_struct rbuf ;
prs_struct buf ;
NET_Q_SAM_LOGOFF q_s ;
1998-04-28 05:24:40 +04:00
BOOL ok = False ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
gen_next_creds ( cli , & new_clnt_cred ) ;
1999-11-29 22:46:57 +03:00
2001-03-10 02:48:58 +03:00
prs_init ( & buf , 1024 , cli - > mem_ctx , MARSHALL ) ;
prs_init ( & rbuf , 0 , cli - > mem_ctx , UNMARSHALL ) ;
1998-03-12 00:11:04 +03:00
1998-04-28 05:24:40 +04:00
/* create and send a MSRPC command with api NET_SAMLOGOFF */
1998-03-12 00:11:04 +03:00
1998-08-14 21:38:29 +04:00
DEBUG ( 4 , ( " cli_net_sam_logoff: srv:%s mc:%s clnt %s %x ll: %d \n " ,
1999-12-13 16:27:58 +03:00
cli - > srv_name_slash , global_myname ,
1998-04-28 05:24:40 +04:00
credstr ( new_clnt_cred . challenge . data ) , new_clnt_cred . timestamp . time ,
ctr - > switch_value ) ) ;
1998-03-12 00:11:04 +03:00
1998-04-29 23:22:01 +04:00
memset ( & dummy_rtn_creds , ' \0 ' , sizeof ( dummy_rtn_creds ) ) ;
2001-07-04 11:15:53 +04:00
init_sam_info ( & q_s . sam_id , cli - > srv_name_slash ,
2001-02-14 08:34:50 +03:00
global_myname , & new_clnt_cred , & dummy_rtn_creds ,
ctr - > switch_value , ctr ) ;
1998-03-12 00:11:04 +03:00
1998-04-24 02:45:53 +04:00
/* turn parameters into data stream */
1999-12-13 16:27:58 +03:00
if ( ! net_io_q_sam_logoff ( " " , & q_s , & buf , 0 ) ) {
DEBUG ( 0 , ( " cli_net_sam_logoff: Error : failed to marshall NET_Q_SAM_LOGOFF struct. \n " ) ) ;
prs_mem_free ( & buf ) ;
prs_mem_free ( & rbuf ) ;
return False ;
}
1998-03-12 00:11:04 +03:00
1998-04-24 02:45:53 +04:00
/* send the data on \PIPE\ */
1999-12-13 16:27:58 +03:00
if ( rpc_api_pipe_req ( cli , NET_SAMLOGOFF , & buf , & rbuf ) )
1998-04-24 02:45:53 +04:00
{
NET_R_SAM_LOGOFF r_s ;
1998-03-12 00:11:04 +03:00
1999-12-13 16:27:58 +03:00
ok = net_io_r_sam_logoff ( " " , & r_s , & rbuf , 0 ) ;
1998-03-12 00:11:04 +03:00
2001-09-04 11:13:01 +04:00
if ( ok & & ! NT_STATUS_IS_OK ( r_s . status ) )
1998-04-24 02:45:53 +04:00
{
/* report error code */
2002-03-17 07:36:35 +03:00
DEBUG ( 0 , ( " cli_net_sam_logoff: %s \n " , nt_errstr ( r_s . status ) ) ) ;
1998-04-24 02:45:53 +04:00
ok = False ;
}
1998-04-28 05:24:40 +04:00
/* Update the credentials. */
1999-12-13 16:27:58 +03:00
if ( ok & & ! clnt_deal_with_creds ( cli - > sess_key , & ( cli - > clnt_cred ) , & ( r_s . srv_creds ) ) )
1998-04-24 02:45:53 +04:00
{
1998-04-28 05:24:40 +04:00
/*
* Server replied with bad credential . Fail .
*/
1999-12-13 16:27:58 +03:00
DEBUG ( 0 , ( " cli_net_sam_logoff: server %s replied with bad credential (bad machine \
password ? ) . \ n " , cli->desthost ));
1998-04-29 04:02:57 +04:00
ok = False ;
1998-04-24 02:45:53 +04:00
}
}
1999-12-13 16:27:58 +03:00
prs_mem_free ( & buf ) ;
1998-04-24 02:45:53 +04:00
prs_mem_free ( & rbuf ) ;
1998-04-28 05:24:40 +04:00
return ok ;
1998-03-12 00:11:04 +03:00
}