2003-08-13 01:53:07 +00:00
/*
Unix SMB / CIFS implementation .
2005-01-15 11:58:52 +00:00
2003-08-13 01:53:07 +00:00
SMB client negotiate context management functions
2005-01-15 11:58:52 +00:00
Copyright ( C ) Andrew Tridgell 1994 - 2005
2003-08-13 01:53:07 +00:00
Copyright ( C ) James Myers 2003 < myersjj @ samba . org >
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-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 01:53:07 +00:00
( 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
2007-07-10 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-08-13 01:53:07 +00:00
*/
# include "includes.h"
2011-09-23 08:35:17 +02:00
# include <tevent.h>
# include "system/time.h"
2004-11-01 01:03:22 +00:00
# include "libcli/raw/libcliraw.h"
2008-04-02 04:53:27 +02:00
# include "libcli/raw/raw_proto.h"
2011-09-23 08:35:17 +02:00
# include "../libcli/smb/smbXcli_base.h"
# include "../lib/util/tevent_ntstatus.h"
2003-08-13 01:53:07 +00:00
2011-09-23 08:35:17 +02:00
struct smb_raw_negotiate_state {
struct smbcli_transport * transport ;
2003-08-13 01:53:07 +00:00
} ;
2011-09-23 08:35:17 +02:00
static void smb_raw_negotiate_done ( struct tevent_req * subreq ) ;
2003-08-13 01:53:07 +00:00
2011-09-23 08:35:17 +02:00
struct tevent_req * smb_raw_negotiate_send ( TALLOC_CTX * mem_ctx ,
struct tevent_context * ev ,
struct smbcli_transport * transport ,
int maxprotocol )
{
struct tevent_req * req ;
struct smb_raw_negotiate_state * state ;
struct tevent_req * subreq ;
uint32_t timeout_msec = transport - > options . request_timeout * 1000 ;
req = tevent_req_create ( mem_ctx , & state ,
struct smb_raw_negotiate_state ) ; ;
if ( req = = NULL ) {
2003-08-13 01:53:07 +00:00
return NULL ;
}
2011-09-23 08:35:17 +02:00
state - > transport = transport ;
subreq = smbXcli_negprot_send ( state , ev ,
transport - > conn ,
timeout_msec ,
PROTOCOL_CORE ,
maxprotocol ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
2003-08-13 01:53:07 +00:00
}
2011-09-23 08:35:17 +02:00
tevent_req_set_callback ( subreq , smb_raw_negotiate_done , req ) ;
2003-08-13 01:53:07 +00:00
return req ;
}
2011-09-23 08:35:17 +02:00
static void smb_raw_negotiate_done ( struct tevent_req * subreq )
2003-08-13 01:53:07 +00:00
{
2011-09-23 08:35:17 +02:00
struct tevent_req * req =
tevent_req_callback_data ( subreq ,
struct tevent_req ) ;
struct smb_raw_negotiate_state * state =
tevent_req_data ( req ,
struct smb_raw_negotiate_state ) ;
struct smbcli_negotiate * n = & state - > transport - > negotiate ;
struct smbXcli_conn * c = state - > transport - > conn ;
NTSTATUS status ;
NTTIME ntt ;
status = smbXcli_negprot_recv ( subreq ) ;
TALLOC_FREE ( subreq ) ;
if ( tevent_req_nterror ( req , status ) ) {
return ;
2003-08-13 01:53:07 +00:00
}
2011-09-23 08:35:17 +02:00
n - > protocol = smbXcli_conn_protocol ( c ) ;
2003-08-13 01:53:07 +00:00
2011-09-23 08:35:17 +02:00
n - > sec_mode = smb1cli_conn_server_security_mode ( c ) ;
n - > max_mux = smbXcli_conn_max_requests ( c ) ;
n - > max_xmit = smb1cli_conn_max_xmit ( c ) ;
n - > sesskey = smb1cli_conn_server_session_key ( c ) ;
n - > capabilities = smb1cli_conn_capabilities ( c ) ; ;
2003-08-13 01:53:07 +00:00
2011-09-23 08:35:17 +02:00
/* this time arrives in real GMT */
ntt = smbXcli_conn_server_system_time ( c ) ;
n - > server_time = nt_time_to_unix ( ntt ) ;
n - > server_zone = smb1cli_conn_server_time_zone ( c ) ;
2009-11-17 23:25:58 +00:00
2011-09-23 08:35:17 +02:00
if ( n - > capabilities & CAP_EXTENDED_SECURITY ) {
const DATA_BLOB * b = smbXcli_conn_server_gss_blob ( c ) ;
if ( b ) {
n - > secblob = * b ;
2003-08-13 01:53:07 +00:00
}
} else {
2011-09-23 08:35:17 +02:00
const uint8_t * p = smb1cli_conn_server_challenge ( c ) ;
if ( p ) {
n - > secblob = data_blob_const ( p , 8 ) ;
}
2003-08-13 01:53:07 +00:00
}
2011-09-23 08:35:17 +02:00
n - > readbraw_supported = smb1cli_conn_server_readbraw ( c ) ;
n - > readbraw_supported = smb1cli_conn_server_writebraw ( c ) ;
n - > lockread_supported = smb1cli_conn_server_lockread ( c ) ;
2005-07-04 01:23:38 +00:00
2011-09-23 08:35:17 +02:00
tevent_req_done ( req ) ;
}
2008-03-06 15:11:16 +01:00
2011-09-23 08:35:17 +02:00
/*
Send a negprot command .
*/
NTSTATUS smb_raw_negotiate_recv ( struct tevent_req * req )
{
return tevent_req_simple_recv_ntstatus ( req ) ;
2003-08-13 01:53:07 +00:00
}
2005-01-15 11:58:52 +00:00
/*
Send a negprot command ( sync interface )
*/
2007-12-02 22:32:11 +01:00
NTSTATUS smb_raw_negotiate ( struct smbcli_transport * transport , bool unicode , int maxprotocol )
2005-01-15 11:58:52 +00:00
{
2011-09-23 08:35:17 +02:00
NTSTATUS status = NT_STATUS_INTERNAL_ERROR ;
struct tevent_req * subreq = NULL ;
bool ok ;
subreq = smb_raw_negotiate_send ( transport ,
transport - > ev ,
transport ,
maxprotocol ) ;
if ( subreq = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
ok = tevent_req_poll ( subreq , transport - > ev ) ;
if ( ! ok ) {
status = map_nt_error_from_unix_common ( errno ) ;
goto failed ;
}
status = smb_raw_negotiate_recv ( subreq ) ;
failed :
TALLOC_FREE ( subreq ) ;
return status ;
2005-01-15 11:58:52 +00:00
}