2023-10-31 17:48:09 +03:00
/*
2003-08-13 05:53:07 +04:00
Unix SMB / CIFS implementation .
client file operations
Copyright ( C ) Andrew Tridgell 1994 - 1998
Copyright ( C ) Jeremy Allison 2001 - 2002
Copyright ( C ) James Myers 2003
2023-10-31 17:48:09 +03:00
2003-08-13 05:53:07 +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-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 05:53:07 +04:00
( at your option ) any later version .
2023-10-31 17:48:09 +03:00
2003-08-13 05:53:07 +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 .
2023-10-31 17:48:09 +03:00
2003-08-13 05:53:07 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-08-13 05:53:07 +04:00
*/
# include "includes.h"
2004-11-01 04:03:22 +03:00
# include "libcli/raw/libcliraw.h"
2008-04-02 06:53:27 +04:00
# include "libcli/raw/raw_proto.h"
2006-03-16 03:23:11 +03:00
# include "librpc/gen_ndr/ndr_security.h"
2003-08-13 05:53:07 +04:00
# define SETUP_REQUEST(cmd, wct, buflen) do { \
2004-08-04 17:23:35 +04:00
req = smbcli_request_setup ( tree , cmd , wct , buflen ) ; \
2003-08-13 05:53:07 +04:00
if ( ! req ) return NULL ; \
} while ( 0 )
/****************************************************************************
Rename a file - async interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-08-04 17:23:35 +04:00
struct smbcli_request * smb_raw_rename_send ( struct smbcli_tree * tree ,
2003-08-13 20:04:21 +04:00
union smb_rename * parms )
2003-08-13 05:53:07 +04:00
{
2023-10-31 17:48:09 +03:00
struct smbcli_request * req = NULL ;
2008-03-11 21:11:57 +03:00
struct smb_nttrans nt ;
TALLOC_CTX * mem_ctx ;
2003-08-13 05:53:07 +04:00
2003-08-13 20:04:21 +04:00
switch ( parms - > generic . level ) {
case RAW_RENAME_RENAME :
SETUP_REQUEST ( SMBmv , 1 , 0 ) ;
SSVAL ( req - > out . vwv , VWV ( 0 ) , parms - > rename . in . attrib ) ;
2004-08-04 17:23:35 +04:00
smbcli_req_append_ascii4 ( req , parms - > rename . in . pattern1 , STR_TERMINATE ) ;
smbcli_req_append_ascii4 ( req , parms - > rename . in . pattern2 , STR_TERMINATE ) ;
2003-08-13 20:04:21 +04:00
break ;
case RAW_RENAME_NTRENAME :
SETUP_REQUEST ( SMBntrename , 4 , 0 ) ;
SSVAL ( req - > out . vwv , VWV ( 0 ) , parms - > ntrename . in . attrib ) ;
SSVAL ( req - > out . vwv , VWV ( 1 ) , parms - > ntrename . in . flags ) ;
2003-08-31 07:16:52 +04:00
SIVAL ( req - > out . vwv , VWV ( 2 ) , parms - > ntrename . in . cluster_size ) ;
2004-08-04 17:23:35 +04:00
smbcli_req_append_ascii4 ( req , parms - > ntrename . in . old_name , STR_TERMINATE ) ;
smbcli_req_append_ascii4 ( req , parms - > ntrename . in . new_name , STR_TERMINATE ) ;
2003-08-13 20:04:21 +04:00
break ;
2008-03-11 21:11:57 +03:00
case RAW_RENAME_NTTRANS :
mem_ctx = talloc_new ( tree ) ;
nt . in . max_setup = 0 ;
nt . in . max_param = 0 ;
nt . in . max_data = 0 ;
nt . in . setup_count = 0 ;
nt . in . setup = NULL ;
nt . in . function = NT_TRANSACT_RENAME ;
nt . in . params = data_blob_talloc ( mem_ctx , NULL , 4 ) ;
nt . in . data = data_blob ( NULL , 0 ) ;
SSVAL ( nt . in . params . data , VWV ( 0 ) , parms - > nttrans . in . file . fnum ) ;
SSVAL ( nt . in . params . data , VWV ( 1 ) , parms - > nttrans . in . flags ) ;
smbcli_blob_append_string ( tree - > session , mem_ctx ,
& nt . in . params , parms - > nttrans . in . new_name ,
STR_TERMINATE ) ;
req = smb_raw_nttrans_send ( tree , & nt ) ;
talloc_free ( mem_ctx ) ;
return req ;
2003-08-13 20:04:21 +04:00
}
2003-08-13 05:53:07 +04:00
2004-08-04 17:23:35 +04:00
if ( ! smbcli_request_send ( req ) ) {
smbcli_request_destroy ( req ) ;
2003-08-13 05:53:07 +04:00
return NULL ;
}
return req ;
}
/****************************************************************************
Rename a file - sync interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-02 06:53:27 +04:00
_PUBLIC_ NTSTATUS smb_raw_rename ( struct smbcli_tree * tree ,
2003-08-13 20:04:21 +04:00
union smb_rename * parms )
2003-08-13 05:53:07 +04:00
{
2004-08-04 17:23:35 +04:00
struct smbcli_request * req = smb_raw_rename_send ( tree , parms ) ;
return smbcli_request_simple_recv ( req ) ;
2003-08-13 05:53:07 +04:00
}
/****************************************************************************
Delete a file - async interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-08-04 17:23:35 +04:00
struct smbcli_request * smb_raw_unlink_send ( struct smbcli_tree * tree ,
2006-03-10 23:49:20 +03:00
union smb_unlink * parms )
2003-08-13 05:53:07 +04:00
{
2023-10-31 17:48:09 +03:00
struct smbcli_request * req ;
2003-08-13 05:53:07 +04:00
SETUP_REQUEST ( SMBunlink , 1 , 0 ) ;
2006-03-10 23:49:20 +03:00
SSVAL ( req - > out . vwv , VWV ( 0 ) , parms - > unlink . in . attrib ) ;
smbcli_req_append_ascii4 ( req , parms - > unlink . in . pattern , STR_TERMINATE ) ;
2003-08-13 05:53:07 +04:00
2004-08-04 17:23:35 +04:00
if ( ! smbcli_request_send ( req ) ) {
smbcli_request_destroy ( req ) ;
2003-08-13 05:53:07 +04:00
return NULL ;
}
return req ;
}
/*
delete a file - sync interface
*/
2008-04-02 06:53:27 +04:00
_PUBLIC_ NTSTATUS smb_raw_unlink ( struct smbcli_tree * tree ,
2006-03-10 23:49:20 +03:00
union smb_unlink * parms )
2003-08-13 05:53:07 +04:00
{
2004-08-04 17:23:35 +04:00
struct smbcli_request * req = smb_raw_unlink_send ( tree , parms ) ;
return smbcli_request_simple_recv ( req ) ;
2003-08-13 05:53:07 +04:00
}
/****************************************************************************
create a directory using TRANSACT2_MKDIR - async interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2023-10-31 17:48:09 +03:00
static struct smbcli_request * smb_raw_t2mkdir_send ( struct smbcli_tree * tree ,
2003-08-13 05:53:07 +04:00
union smb_mkdir * parms )
{
struct smb_trans2 t2 ;
2004-05-25 21:24:24 +04:00
uint16_t setup = TRANSACT2_MKDIR ;
2003-08-13 05:53:07 +04:00
TALLOC_CTX * mem_ctx ;
2004-08-04 17:23:35 +04:00
struct smbcli_request * req ;
2004-05-25 21:24:24 +04:00
uint16_t data_total ;
2003-08-13 05:53:07 +04:00
mem_ctx = talloc_init ( " t2mkdir " ) ;
data_total = ea_list_size ( parms - > t2mkdir . in . num_eas , parms - > t2mkdir . in . eas ) ;
2004-12-14 02:57:59 +03:00
t2 . in . max_param = 2 ;
2003-08-13 05:53:07 +04:00
t2 . in . max_data = 0 ;
t2 . in . max_setup = 0 ;
t2 . in . flags = 0 ;
t2 . in . timeout = 0 ;
t2 . in . setup_count = 1 ;
t2 . in . setup = & setup ;
t2 . in . params = data_blob_talloc ( mem_ctx , NULL , 4 ) ;
t2 . in . data = data_blob_talloc ( mem_ctx , NULL , data_total ) ;
SIVAL ( t2 . in . params . data , VWV ( 0 ) , 0 ) ; /* reserved */
2023-10-31 17:48:09 +03:00
smbcli_blob_append_string ( tree - > session , mem_ctx ,
2004-12-14 02:57:59 +03:00
& t2 . in . params , parms - > t2mkdir . in . path , STR_TERMINATE ) ;
2003-08-13 05:53:07 +04:00
ea_put_list ( t2 . in . data . data , parms - > t2mkdir . in . num_eas , parms - > t2mkdir . in . eas ) ;
req = smb_raw_trans2_send ( tree , & t2 ) ;
2005-01-27 10:08:20 +03:00
talloc_free ( mem_ctx ) ;
2003-08-13 05:53:07 +04:00
return req ;
}
/****************************************************************************
Create a directory - async interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-08-04 17:23:35 +04:00
struct smbcli_request * smb_raw_mkdir_send ( struct smbcli_tree * tree ,
2003-08-13 05:53:07 +04:00
union smb_mkdir * parms )
{
2023-10-31 17:48:09 +03:00
struct smbcli_request * req ;
2003-08-13 05:53:07 +04:00
if ( parms - > generic . level = = RAW_MKDIR_T2MKDIR ) {
return smb_raw_t2mkdir_send ( tree , parms ) ;
}
if ( parms - > generic . level ! = RAW_MKDIR_MKDIR ) {
return NULL ;
}
SETUP_REQUEST ( SMBmkdir , 0 , 0 ) ;
2023-10-31 17:48:09 +03:00
2004-08-04 17:23:35 +04:00
smbcli_req_append_ascii4 ( req , parms - > mkdir . in . path , STR_TERMINATE ) ;
2003-08-13 05:53:07 +04:00
2004-08-04 17:23:35 +04:00
if ( ! smbcli_request_send ( req ) ) {
2003-08-13 05:53:07 +04:00
return NULL ;
}
return req ;
}
/****************************************************************************
Create a directory - sync interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-02 06:53:27 +04:00
_PUBLIC_ NTSTATUS smb_raw_mkdir ( struct smbcli_tree * tree ,
2003-08-13 05:53:07 +04:00
union smb_mkdir * parms )
{
2004-08-04 17:23:35 +04:00
struct smbcli_request * req = smb_raw_mkdir_send ( tree , parms ) ;
return smbcli_request_simple_recv ( req ) ;
2003-08-13 05:53:07 +04:00
}
/****************************************************************************
Remove a directory - async interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-08-04 17:23:35 +04:00
struct smbcli_request * smb_raw_rmdir_send ( struct smbcli_tree * tree ,
2003-08-13 05:53:07 +04:00
struct smb_rmdir * parms )
{
2023-10-31 17:48:09 +03:00
struct smbcli_request * req ;
2003-08-13 05:53:07 +04:00
SETUP_REQUEST ( SMBrmdir , 0 , 0 ) ;
2023-10-31 17:48:09 +03:00
2004-08-04 17:23:35 +04:00
smbcli_req_append_ascii4 ( req , parms - > in . path , STR_TERMINATE ) ;
2003-08-13 05:53:07 +04:00
2004-08-04 17:23:35 +04:00
if ( ! smbcli_request_send ( req ) ) {
smbcli_request_destroy ( req ) ;
2003-08-13 05:53:07 +04:00
return NULL ;
}
return req ;
}
/****************************************************************************
Remove a directory - sync interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-02 06:53:27 +04:00
_PUBLIC_ NTSTATUS smb_raw_rmdir ( struct smbcli_tree * tree ,
2003-08-13 05:53:07 +04:00
struct smb_rmdir * parms )
{
2004-08-04 17:23:35 +04:00
struct smbcli_request * req = smb_raw_rmdir_send ( tree , parms ) ;
return smbcli_request_simple_recv ( req ) ;
2003-08-13 05:53:07 +04:00
}
2004-11-17 23:56:26 +03:00
/*
Open a file using TRANSACT2_OPEN - async recv
*/
2023-10-31 17:48:09 +03:00
static NTSTATUS smb_raw_nttrans_create_recv ( struct smbcli_request * req ,
TALLOC_CTX * mem_ctx ,
2004-11-17 23:56:26 +03:00
union smb_open * parms )
{
NTSTATUS status ;
struct smb_nttrans nt ;
uint8_t * params ;
status = smb_raw_nttrans_recv ( req , mem_ctx , & nt ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) return status ;
if ( nt . out . params . length < 69 ) {
return NT_STATUS_INVALID_PARAMETER ;
}
params = nt . out . params . data ;
parms - > ntcreatex . out . oplock_level = CVAL ( params , 0 ) ;
2006-03-13 01:48:25 +03:00
parms - > ntcreatex . out . file . fnum = SVAL ( params , 2 ) ;
2004-11-17 23:56:26 +03:00
parms - > ntcreatex . out . create_action = IVAL ( params , 4 ) ;
parms - > ntcreatex . out . create_time = smbcli_pull_nttime ( params , 12 ) ;
parms - > ntcreatex . out . access_time = smbcli_pull_nttime ( params , 20 ) ;
parms - > ntcreatex . out . write_time = smbcli_pull_nttime ( params , 28 ) ;
parms - > ntcreatex . out . change_time = smbcli_pull_nttime ( params , 36 ) ;
parms - > ntcreatex . out . attrib = IVAL ( params , 44 ) ;
parms - > ntcreatex . out . alloc_size = BVAL ( params , 48 ) ;
parms - > ntcreatex . out . size = BVAL ( params , 56 ) ;
parms - > ntcreatex . out . file_type = SVAL ( params , 64 ) ;
parms - > ntcreatex . out . ipc_state = SVAL ( params , 66 ) ;
parms - > ntcreatex . out . is_directory = CVAL ( params , 68 ) ;
2023-10-31 17:48:09 +03:00
2004-11-17 23:56:26 +03:00
return NT_STATUS_OK ;
}
/*
2023-10-31 17:48:09 +03:00
Open a file using NTTRANS CREATE - async send
2004-11-17 23:56:26 +03:00
*/
2023-10-31 17:48:09 +03:00
static struct smbcli_request * smb_raw_nttrans_create_send ( struct smbcli_tree * tree ,
2004-11-17 23:56:26 +03:00
union smb_open * parms )
{
struct smb_nttrans nt ;
uint8_t * params ;
2005-01-06 05:32:43 +03:00
TALLOC_CTX * mem_ctx = talloc_new ( tree ) ;
2004-11-17 23:56:26 +03:00
uint16_t fname_len ;
DATA_BLOB sd_blob , ea_blob ;
struct smbcli_request * req ;
nt . in . max_setup = 0 ;
nt . in . max_param = 101 ;
nt . in . max_data = 0 ;
nt . in . setup_count = 0 ;
nt . in . function = NT_TRANSACT_CREATE ;
nt . in . setup = NULL ;
sd_blob = data_blob ( NULL , 0 ) ;
ea_blob = data_blob ( NULL , 0 ) ;
if ( parms - > ntcreatex . in . sec_desc ) {
2007-11-09 21:24:51 +03:00
enum ndr_err_code ndr_err ;
2023-10-31 17:48:09 +03:00
ndr_err = ndr_push_struct_blob ( & sd_blob , mem_ctx ,
2007-11-09 21:24:51 +03:00
parms - > ntcreatex . in . sec_desc ,
( ndr_push_flags_fn_t ) ndr_push_security_descriptor ) ;
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
2004-11-17 23:56:26 +03:00
talloc_free ( mem_ctx ) ;
return NULL ;
}
}
if ( parms - > ntcreatex . in . ea_list ) {
2004-11-18 01:00:15 +03:00
uint32_t ea_size = ea_list_size_chained ( parms - > ntcreatex . in . ea_list - > num_eas ,
2008-05-22 16:46:29 +04:00
parms - > ntcreatex . in . ea_list - > eas , 4 ) ;
2004-11-17 23:56:26 +03:00
ea_blob = data_blob_talloc ( mem_ctx , NULL , ea_size ) ;
if ( ea_blob . data = = NULL ) {
return NULL ;
}
2023-10-31 17:48:09 +03:00
ea_put_list_chained ( ea_blob . data ,
2004-11-18 01:00:15 +03:00
parms - > ntcreatex . in . ea_list - > num_eas ,
2008-05-22 16:46:29 +04:00
parms - > ntcreatex . in . ea_list - > eas , 4 ) ;
2004-11-17 23:56:26 +03:00
}
2006-03-10 14:47:03 +03:00
nt . in . params = data_blob_talloc ( mem_ctx , NULL , 53 ) ;
2004-11-17 23:56:26 +03:00
if ( nt . in . params . data = = NULL ) {
talloc_free ( mem_ctx ) ;
return NULL ;
}
/* build the parameter section */
params = nt . in . params . data ;
SIVAL ( params , 0 , parms - > ntcreatex . in . flags ) ;
2009-10-15 11:26:19 +04:00
SIVAL ( params , 4 , parms - > ntcreatex . in . root_fid . fnum ) ;
2004-11-17 23:56:26 +03:00
SIVAL ( params , 8 , parms - > ntcreatex . in . access_mask ) ;
SBVAL ( params , 12 , parms - > ntcreatex . in . alloc_size ) ;
SIVAL ( params , 20 , parms - > ntcreatex . in . file_attr ) ;
SIVAL ( params , 24 , parms - > ntcreatex . in . share_access ) ;
SIVAL ( params , 28 , parms - > ntcreatex . in . open_disposition ) ;
SIVAL ( params , 32 , parms - > ntcreatex . in . create_options ) ;
SIVAL ( params , 36 , sd_blob . length ) ;
SIVAL ( params , 40 , ea_blob . length ) ;
SIVAL ( params , 48 , parms - > ntcreatex . in . impersonation ) ;
SCVAL ( params , 52 , parms - > ntcreatex . in . security_flags ) ;
2006-03-10 14:47:03 +03:00
/* the empty string first forces the correct alignment */
smbcli_blob_append_string ( tree - > session , mem_ctx , & nt . in . params , " " , 0 ) ;
2004-11-17 23:56:26 +03:00
fname_len = smbcli_blob_append_string ( tree - > session , mem_ctx , & nt . in . params ,
parms - > ntcreatex . in . fname , STR_TERMINATE ) ;
SIVAL ( nt . in . params . data , 44 , fname_len ) ;
/* build the data section */
nt . in . data = data_blob_talloc ( mem_ctx , NULL , sd_blob . length + ea_blob . length ) ;
2019-05-24 02:00:05 +03:00
if ( sd_blob . length > 0 ) {
memcpy ( nt . in . data . data , sd_blob . data , sd_blob . length ) ;
}
if ( ea_blob . length > 0 ) {
memcpy ( nt . in . data . data + sd_blob . length ,
ea_blob . data ,
ea_blob . length ) ;
}
2004-11-17 23:56:26 +03:00
/* send the request on its way */
req = smb_raw_nttrans_send ( tree , & nt ) ;
talloc_free ( mem_ctx ) ;
2023-10-31 17:48:09 +03:00
2004-11-17 23:56:26 +03:00
return req ;
}
2003-08-13 05:53:07 +04:00
/****************************************************************************
2023-10-31 17:48:09 +03:00
Open a file using TRANSACT2_OPEN - async send
2003-08-13 05:53:07 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2023-10-31 17:48:09 +03:00
static struct smbcli_request * smb_raw_t2open_send ( struct smbcli_tree * tree ,
2003-08-13 05:53:07 +04:00
union smb_open * parms )
{
struct smb_trans2 t2 ;
2004-05-25 21:24:24 +04:00
uint16_t setup = TRANSACT2_OPEN ;
2003-08-13 05:53:07 +04:00
TALLOC_CTX * mem_ctx = talloc_init ( " smb_raw_t2open " ) ;
2004-08-04 17:23:35 +04:00
struct smbcli_request * req ;
2004-05-25 21:24:24 +04:00
uint16_t list_size ;
2003-08-13 05:53:07 +04:00
list_size = ea_list_size ( parms - > t2open . in . num_eas , parms - > t2open . in . eas ) ;
t2 . in . max_param = 30 ;
t2 . in . max_data = 0 ;
t2 . in . max_setup = 0 ;
t2 . in . flags = 0 ;
t2 . in . timeout = 0 ;
t2 . in . setup_count = 1 ;
t2 . in . setup = & setup ;
t2 . in . params = data_blob_talloc ( mem_ctx , NULL , 28 ) ;
t2 . in . data = data_blob_talloc ( mem_ctx , NULL , list_size ) ;
SSVAL ( t2 . in . params . data , VWV ( 0 ) , parms - > t2open . in . flags ) ;
SSVAL ( t2 . in . params . data , VWV ( 1 ) , parms - > t2open . in . open_mode ) ;
2004-12-13 13:48:21 +03:00
SSVAL ( t2 . in . params . data , VWV ( 2 ) , parms - > t2open . in . search_attrs ) ;
2003-08-13 05:53:07 +04:00
SSVAL ( t2 . in . params . data , VWV ( 3 ) , parms - > t2open . in . file_attrs ) ;
2023-10-31 17:48:09 +03:00
raw_push_dos_date ( tree - > session - > transport ,
2004-12-13 13:48:21 +03:00
t2 . in . params . data , VWV ( 4 ) , parms - > t2open . in . write_time ) ;
2003-08-13 05:53:07 +04:00
SSVAL ( t2 . in . params . data , VWV ( 6 ) , parms - > t2open . in . open_func ) ;
SIVAL ( t2 . in . params . data , VWV ( 7 ) , parms - > t2open . in . size ) ;
SIVAL ( t2 . in . params . data , VWV ( 9 ) , parms - > t2open . in . timeout ) ;
SIVAL ( t2 . in . params . data , VWV ( 11 ) , 0 ) ;
SSVAL ( t2 . in . params . data , VWV ( 13 ) , 0 ) ;
2023-10-31 17:48:09 +03:00
smbcli_blob_append_string ( tree - > session , mem_ctx ,
& t2 . in . params , parms - > t2open . in . fname ,
2004-12-13 13:48:21 +03:00
STR_TERMINATE ) ;
2003-08-13 05:53:07 +04:00
ea_put_list ( t2 . in . data . data , parms - > t2open . in . num_eas , parms - > t2open . in . eas ) ;
req = smb_raw_trans2_send ( tree , & t2 ) ;
2005-01-27 10:08:20 +03:00
talloc_free ( mem_ctx ) ;
2003-08-13 05:53:07 +04:00
return req ;
}
/****************************************************************************
Open a file using TRANSACT2_OPEN - async recv
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-08-04 17:23:35 +04:00
static NTSTATUS smb_raw_t2open_recv ( struct smbcli_request * req , TALLOC_CTX * mem_ctx , union smb_open * parms )
2003-08-13 05:53:07 +04:00
{
2006-04-08 06:33:24 +04:00
struct smbcli_transport * transport = req - > transport ;
2003-08-13 05:53:07 +04:00
struct smb_trans2 t2 ;
NTSTATUS status ;
status = smb_raw_trans2_recv ( req , mem_ctx , & t2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) return status ;
if ( t2 . out . params . length < 30 ) {
return NT_STATUS_INFO_LENGTH_MISMATCH ;
}
2006-03-13 01:48:25 +03:00
parms - > t2open . out . file . fnum = SVAL ( t2 . out . params . data , VWV ( 0 ) ) ;
2003-08-13 05:53:07 +04:00
parms - > t2open . out . attrib = SVAL ( t2 . out . params . data , VWV ( 1 ) ) ;
2004-08-03 09:59:28 +04:00
parms - > t2open . out . write_time = raw_pull_dos_date3 ( transport , t2 . out . params . data + VWV ( 2 ) ) ;
2003-08-13 05:53:07 +04:00
parms - > t2open . out . size = IVAL ( t2 . out . params . data , VWV ( 4 ) ) ;
parms - > t2open . out . access = SVAL ( t2 . out . params . data , VWV ( 6 ) ) ;
parms - > t2open . out . ftype = SVAL ( t2 . out . params . data , VWV ( 7 ) ) ;
parms - > t2open . out . devstate = SVAL ( t2 . out . params . data , VWV ( 8 ) ) ;
parms - > t2open . out . action = SVAL ( t2 . out . params . data , VWV ( 9 ) ) ;
2004-12-13 13:48:21 +03:00
parms - > t2open . out . file_id = SVAL ( t2 . out . params . data , VWV ( 10 ) ) ;
2003-08-13 05:53:07 +04:00
return NT_STATUS_OK ;
}
/****************************************************************************
Open a file - async send
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-02 06:53:27 +04:00
_PUBLIC_ struct smbcli_request * smb_raw_open_send ( struct smbcli_tree * tree , union smb_open * parms )
2003-08-13 05:53:07 +04:00
{
int len ;
2023-10-31 17:48:09 +03:00
struct smbcli_request * req = NULL ;
2007-10-07 02:28:14 +04:00
bool bigoffset = false ;
2003-08-13 05:53:07 +04:00
2004-11-02 07:17:30 +03:00
switch ( parms - > generic . level ) {
2003-08-13 05:53:07 +04:00
case RAW_OPEN_T2OPEN :
return smb_raw_t2open_send ( tree , parms ) ;
case RAW_OPEN_OPEN :
SETUP_REQUEST ( SMBopen , 2 , 0 ) ;
2004-12-13 13:48:21 +03:00
SSVAL ( req - > out . vwv , VWV ( 0 ) , parms - > openold . in . open_mode ) ;
2004-11-02 07:17:30 +03:00
SSVAL ( req - > out . vwv , VWV ( 1 ) , parms - > openold . in . search_attrs ) ;
smbcli_req_append_ascii4 ( req , parms - > openold . in . fname , STR_TERMINATE ) ;
2003-08-13 05:53:07 +04:00
break ;
2023-10-31 17:48:09 +03:00
2003-08-13 05:53:07 +04:00
case RAW_OPEN_OPENX :
SETUP_REQUEST ( SMBopenX , 15 , 0 ) ;
SSVAL ( req - > out . vwv , VWV ( 0 ) , SMB_CHAIN_NONE ) ;
SSVAL ( req - > out . vwv , VWV ( 1 ) , 0 ) ;
SSVAL ( req - > out . vwv , VWV ( 2 ) , parms - > openx . in . flags ) ;
SSVAL ( req - > out . vwv , VWV ( 3 ) , parms - > openx . in . open_mode ) ;
SSVAL ( req - > out . vwv , VWV ( 4 ) , parms - > openx . in . search_attrs ) ;
SSVAL ( req - > out . vwv , VWV ( 5 ) , parms - > openx . in . file_attrs ) ;
2023-10-31 17:48:09 +03:00
raw_push_dos_date3 ( tree - > session - > transport ,
2004-04-11 00:18:22 +04:00
req - > out . vwv , VWV ( 6 ) , parms - > openx . in . write_time ) ;
2003-08-13 05:53:07 +04:00
SSVAL ( req - > out . vwv , VWV ( 8 ) , parms - > openx . in . open_func ) ;
SIVAL ( req - > out . vwv , VWV ( 9 ) , parms - > openx . in . size ) ;
SIVAL ( req - > out . vwv , VWV ( 11 ) , parms - > openx . in . timeout ) ;
SIVAL ( req - > out . vwv , VWV ( 13 ) , 0 ) ; /* reserved */
2004-08-04 17:23:35 +04:00
smbcli_req_append_string ( req , parms - > openx . in . fname , STR_TERMINATE ) ;
2003-08-13 05:53:07 +04:00
break ;
2023-10-31 17:48:09 +03:00
2003-08-13 05:53:07 +04:00
case RAW_OPEN_MKNEW :
SETUP_REQUEST ( SMBmknew , 3 , 0 ) ;
SSVAL ( req - > out . vwv , VWV ( 0 ) , parms - > mknew . in . attrib ) ;
2023-10-31 17:48:09 +03:00
raw_push_dos_date3 ( tree - > session - > transport ,
2004-04-11 00:18:22 +04:00
req - > out . vwv , VWV ( 1 ) , parms - > mknew . in . write_time ) ;
2004-08-04 17:23:35 +04:00
smbcli_req_append_ascii4 ( req , parms - > mknew . in . fname , STR_TERMINATE ) ;
2003-08-13 05:53:07 +04:00
break ;
2003-08-14 05:31:31 +04:00
case RAW_OPEN_CREATE :
SETUP_REQUEST ( SMBcreate , 3 , 0 ) ;
SSVAL ( req - > out . vwv , VWV ( 0 ) , parms - > create . in . attrib ) ;
2023-10-31 17:48:09 +03:00
raw_push_dos_date3 ( tree - > session - > transport ,
2004-04-11 00:18:22 +04:00
req - > out . vwv , VWV ( 1 ) , parms - > create . in . write_time ) ;
2004-08-04 17:23:35 +04:00
smbcli_req_append_ascii4 ( req , parms - > create . in . fname , STR_TERMINATE ) ;
2003-08-14 05:31:31 +04:00
break ;
2023-10-31 17:48:09 +03:00
2003-08-13 05:53:07 +04:00
case RAW_OPEN_CTEMP :
SETUP_REQUEST ( SMBctemp , 3 , 0 ) ;
SSVAL ( req - > out . vwv , VWV ( 0 ) , parms - > ctemp . in . attrib ) ;
2023-10-31 17:48:09 +03:00
raw_push_dos_date3 ( tree - > session - > transport ,
2004-04-11 00:18:22 +04:00
req - > out . vwv , VWV ( 1 ) , parms - > ctemp . in . write_time ) ;
2004-08-04 17:23:35 +04:00
smbcli_req_append_ascii4 ( req , parms - > ctemp . in . directory , STR_TERMINATE ) ;
2003-08-13 05:53:07 +04:00
break ;
2023-10-31 17:48:09 +03:00
2003-08-13 05:53:07 +04:00
case RAW_OPEN_SPLOPEN :
SETUP_REQUEST ( SMBsplopen , 2 , 0 ) ;
SSVAL ( req - > out . vwv , VWV ( 0 ) , parms - > splopen . in . setup_length ) ;
SSVAL ( req - > out . vwv , VWV ( 1 ) , parms - > splopen . in . mode ) ;
break ;
2023-10-31 17:48:09 +03:00
2003-08-13 05:53:07 +04:00
case RAW_OPEN_NTCREATEX :
SETUP_REQUEST ( SMBntcreateX , 24 , 0 ) ;
SSVAL ( req - > out . vwv , VWV ( 0 ) , SMB_CHAIN_NONE ) ;
SSVAL ( req - > out . vwv , VWV ( 1 ) , 0 ) ;
SCVAL ( req - > out . vwv , VWV ( 2 ) , 0 ) ; /* padding */
SIVAL ( req - > out . vwv , 7 , parms - > ntcreatex . in . flags ) ;
2009-10-15 11:26:19 +04:00
SIVAL ( req - > out . vwv , 11 , parms - > ntcreatex . in . root_fid . fnum ) ;
2003-08-13 05:53:07 +04:00
SIVAL ( req - > out . vwv , 15 , parms - > ntcreatex . in . access_mask ) ;
SBVAL ( req - > out . vwv , 19 , parms - > ntcreatex . in . alloc_size ) ;
SIVAL ( req - > out . vwv , 27 , parms - > ntcreatex . in . file_attr ) ;
SIVAL ( req - > out . vwv , 31 , parms - > ntcreatex . in . share_access ) ;
SIVAL ( req - > out . vwv , 35 , parms - > ntcreatex . in . open_disposition ) ;
SIVAL ( req - > out . vwv , 39 , parms - > ntcreatex . in . create_options ) ;
SIVAL ( req - > out . vwv , 43 , parms - > ntcreatex . in . impersonation ) ;
SCVAL ( req - > out . vwv , 47 , parms - > ntcreatex . in . security_flags ) ;
2023-10-31 17:48:09 +03:00
2004-08-04 17:23:35 +04:00
smbcli_req_append_string_len ( req , parms - > ntcreatex . in . fname , STR_TERMINATE , & len ) ;
2003-08-13 05:53:07 +04:00
SSVAL ( req - > out . vwv , 5 , len ) ;
break ;
2004-11-17 23:56:26 +03:00
case RAW_OPEN_NTTRANS_CREATE :
return smb_raw_nttrans_create_send ( tree , parms ) ;
2004-12-26 11:13:01 +03:00
case RAW_OPEN_OPENX_READX :
SETUP_REQUEST ( SMBopenX , 15 , 0 ) ;
SSVAL ( req - > out . vwv , VWV ( 0 ) , SMB_CHAIN_NONE ) ;
SSVAL ( req - > out . vwv , VWV ( 1 ) , 0 ) ;
SSVAL ( req - > out . vwv , VWV ( 2 ) , parms - > openxreadx . in . flags ) ;
SSVAL ( req - > out . vwv , VWV ( 3 ) , parms - > openxreadx . in . open_mode ) ;
SSVAL ( req - > out . vwv , VWV ( 4 ) , parms - > openxreadx . in . search_attrs ) ;
SSVAL ( req - > out . vwv , VWV ( 5 ) , parms - > openxreadx . in . file_attrs ) ;
2023-10-31 17:48:09 +03:00
raw_push_dos_date3 ( tree - > session - > transport ,
2004-12-26 11:13:01 +03:00
req - > out . vwv , VWV ( 6 ) , parms - > openxreadx . in . write_time ) ;
SSVAL ( req - > out . vwv , VWV ( 8 ) , parms - > openxreadx . in . open_func ) ;
SIVAL ( req - > out . vwv , VWV ( 9 ) , parms - > openxreadx . in . size ) ;
SIVAL ( req - > out . vwv , VWV ( 11 ) , parms - > openxreadx . in . timeout ) ;
SIVAL ( req - > out . vwv , VWV ( 13 ) , 0 ) ;
smbcli_req_append_string ( req , parms - > openxreadx . in . fname , STR_TERMINATE ) ;
if ( tree - > session - > transport - > negotiate . capabilities & CAP_LARGE_FILES ) {
2007-10-07 02:28:14 +04:00
bigoffset = true ;
2004-12-26 11:13:01 +03:00
}
smbcli_chained_request_setup ( req , SMBreadX , bigoffset ? 12 : 10 , 0 ) ;
SSVAL ( req - > out . vwv , VWV ( 0 ) , SMB_CHAIN_NONE ) ;
SSVAL ( req - > out . vwv , VWV ( 1 ) , 0 ) ;
SSVAL ( req - > out . vwv , VWV ( 2 ) , 0 ) ;
SIVAL ( req - > out . vwv , VWV ( 3 ) , parms - > openxreadx . in . offset ) ;
SSVAL ( req - > out . vwv , VWV ( 5 ) , parms - > openxreadx . in . maxcnt & 0xFFFF ) ;
SSVAL ( req - > out . vwv , VWV ( 6 ) , parms - > openxreadx . in . mincnt ) ;
SIVAL ( req - > out . vwv , VWV ( 7 ) , parms - > openxreadx . in . maxcnt > > 16 ) ;
SSVAL ( req - > out . vwv , VWV ( 9 ) , parms - > openxreadx . in . remaining ) ;
if ( bigoffset ) {
SIVAL ( req - > out . vwv , VWV ( 10 ) , parms - > openxreadx . in . offset > > 32 ) ;
}
break ;
2009-10-02 03:13:37 +04:00
case RAW_OPEN_NTCREATEX_READX :
SETUP_REQUEST ( SMBntcreateX , 24 , 0 ) ;
SSVAL ( req - > out . vwv , VWV ( 0 ) , SMB_CHAIN_NONE ) ;
SSVAL ( req - > out . vwv , VWV ( 1 ) , 0 ) ;
SCVAL ( req - > out . vwv , VWV ( 2 ) , 0 ) ; /* padding */
SIVAL ( req - > out . vwv , 7 , parms - > ntcreatexreadx . in . flags ) ;
2009-10-15 11:26:19 +04:00
SIVAL ( req - > out . vwv , 11 , parms - > ntcreatexreadx . in . root_fid . fnum ) ;
2009-10-02 03:13:37 +04:00
SIVAL ( req - > out . vwv , 15 , parms - > ntcreatexreadx . in . access_mask ) ;
SBVAL ( req - > out . vwv , 19 , parms - > ntcreatexreadx . in . alloc_size ) ;
SIVAL ( req - > out . vwv , 27 , parms - > ntcreatexreadx . in . file_attr ) ;
SIVAL ( req - > out . vwv , 31 , parms - > ntcreatexreadx . in . share_access ) ;
SIVAL ( req - > out . vwv , 35 , parms - > ntcreatexreadx . in . open_disposition ) ;
SIVAL ( req - > out . vwv , 39 , parms - > ntcreatexreadx . in . create_options ) ;
SIVAL ( req - > out . vwv , 43 , parms - > ntcreatexreadx . in . impersonation ) ;
SCVAL ( req - > out . vwv , 47 , parms - > ntcreatexreadx . in . security_flags ) ;
smbcli_req_append_string_len ( req , parms - > ntcreatexreadx . in . fname , STR_TERMINATE , & len ) ;
SSVAL ( req - > out . vwv , 5 , len ) ;
if ( tree - > session - > transport - > negotiate . capabilities & CAP_LARGE_FILES ) {
bigoffset = true ;
}
smbcli_chained_request_setup ( req , SMBreadX , bigoffset ? 12 : 10 , 0 ) ;
SSVAL ( req - > out . vwv , VWV ( 0 ) , SMB_CHAIN_NONE ) ;
SSVAL ( req - > out . vwv , VWV ( 1 ) , 0 ) ;
SSVAL ( req - > out . vwv , VWV ( 2 ) , 0 ) ;
SIVAL ( req - > out . vwv , VWV ( 3 ) , parms - > ntcreatexreadx . in . offset ) ;
SSVAL ( req - > out . vwv , VWV ( 5 ) , parms - > ntcreatexreadx . in . maxcnt & 0xFFFF ) ;
SSVAL ( req - > out . vwv , VWV ( 6 ) , parms - > ntcreatexreadx . in . mincnt ) ;
SIVAL ( req - > out . vwv , VWV ( 7 ) , parms - > ntcreatexreadx . in . maxcnt > > 16 ) ;
SSVAL ( req - > out . vwv , VWV ( 9 ) , parms - > ntcreatexreadx . in . remaining ) ;
if ( bigoffset ) {
SIVAL ( req - > out . vwv , VWV ( 10 ) , parms - > ntcreatexreadx . in . offset > > 32 ) ;
}
break ;
2006-05-20 14:46:38 +04:00
case RAW_OPEN_SMB2 :
return NULL ;
2003-08-13 05:53:07 +04:00
}
2004-08-04 17:23:35 +04:00
if ( ! smbcli_request_send ( req ) ) {
smbcli_request_destroy ( req ) ;
2003-08-13 05:53:07 +04:00
return NULL ;
}
return req ;
}
/****************************************************************************
Open a file - async recv
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-02 06:53:27 +04:00
_PUBLIC_ NTSTATUS smb_raw_open_recv ( struct smbcli_request * req , TALLOC_CTX * mem_ctx , union smb_open * parms )
2003-08-13 05:53:07 +04:00
{
2004-12-26 11:13:01 +03:00
NTSTATUS status ;
2004-08-04 17:23:35 +04:00
if ( ! smbcli_request_receive ( req ) | |
smbcli_request_is_error ( req ) ) {
2003-08-13 05:53:07 +04:00
goto failed ;
}
2004-11-02 07:17:30 +03:00
switch ( parms - > openold . level ) {
2003-08-13 05:53:07 +04:00
case RAW_OPEN_T2OPEN :
return smb_raw_t2open_recv ( req , mem_ctx , parms ) ;
case RAW_OPEN_OPEN :
2004-08-04 17:23:35 +04:00
SMBCLI_CHECK_WCT ( req , 7 ) ;
2006-03-13 01:48:25 +03:00
parms - > openold . out . file . fnum = SVAL ( req - > in . vwv , VWV ( 0 ) ) ;
2004-11-02 07:17:30 +03:00
parms - > openold . out . attrib = SVAL ( req - > in . vwv , VWV ( 1 ) ) ;
parms - > openold . out . write_time = raw_pull_dos_date3 ( req - > transport ,
2004-04-11 00:18:22 +04:00
req - > in . vwv + VWV ( 2 ) ) ;
2004-11-02 07:17:30 +03:00
parms - > openold . out . size = IVAL ( req - > in . vwv , VWV ( 4 ) ) ;
parms - > openold . out . rmode = SVAL ( req - > in . vwv , VWV ( 6 ) ) ;
2003-08-13 05:53:07 +04:00
break ;
case RAW_OPEN_OPENX :
2004-08-04 17:23:35 +04:00
SMBCLI_CHECK_MIN_WCT ( req , 15 ) ;
2006-03-13 01:48:25 +03:00
parms - > openx . out . file . fnum = SVAL ( req - > in . vwv , VWV ( 2 ) ) ;
2003-08-13 05:53:07 +04:00
parms - > openx . out . attrib = SVAL ( req - > in . vwv , VWV ( 3 ) ) ;
2004-04-11 00:18:22 +04:00
parms - > openx . out . write_time = raw_pull_dos_date3 ( req - > transport ,
req - > in . vwv + VWV ( 4 ) ) ;
2003-08-13 05:53:07 +04:00
parms - > openx . out . size = IVAL ( req - > in . vwv , VWV ( 6 ) ) ;
parms - > openx . out . access = SVAL ( req - > in . vwv , VWV ( 8 ) ) ;
parms - > openx . out . ftype = SVAL ( req - > in . vwv , VWV ( 9 ) ) ;
parms - > openx . out . devstate = SVAL ( req - > in . vwv , VWV ( 10 ) ) ;
parms - > openx . out . action = SVAL ( req - > in . vwv , VWV ( 11 ) ) ;
parms - > openx . out . unique_fid = IVAL ( req - > in . vwv , VWV ( 12 ) ) ;
if ( req - > in . wct > = 19 ) {
parms - > openx . out . access_mask = IVAL ( req - > in . vwv , VWV ( 15 ) ) ;
parms - > openx . out . unknown = IVAL ( req - > in . vwv , VWV ( 17 ) ) ;
} else {
parms - > openx . out . access_mask = 0 ;
parms - > openx . out . unknown = 0 ;
}
break ;
case RAW_OPEN_MKNEW :
2004-08-04 17:23:35 +04:00
SMBCLI_CHECK_WCT ( req , 1 ) ;
2006-03-13 01:48:25 +03:00
parms - > mknew . out . file . fnum = SVAL ( req - > in . vwv , VWV ( 0 ) ) ;
2003-08-13 05:53:07 +04:00
break ;
2003-08-14 05:31:31 +04:00
case RAW_OPEN_CREATE :
2004-08-04 17:23:35 +04:00
SMBCLI_CHECK_WCT ( req , 1 ) ;
2006-03-13 01:48:25 +03:00
parms - > create . out . file . fnum = SVAL ( req - > in . vwv , VWV ( 0 ) ) ;
2003-08-14 05:31:31 +04:00
break ;
2003-08-13 05:53:07 +04:00
case RAW_OPEN_CTEMP :
2004-08-04 17:23:35 +04:00
SMBCLI_CHECK_WCT ( req , 1 ) ;
2006-03-13 01:48:25 +03:00
parms - > ctemp . out . file . fnum = SVAL ( req - > in . vwv , VWV ( 0 ) ) ;
2008-02-14 02:12:33 +03:00
smbcli_req_pull_string ( & req - > in . bufinfo , mem_ctx , & parms - > ctemp . out . name , req - > in . data , - 1 , STR_TERMINATE | STR_ASCII ) ;
2003-08-13 05:53:07 +04:00
break ;
case RAW_OPEN_SPLOPEN :
2004-08-04 17:23:35 +04:00
SMBCLI_CHECK_WCT ( req , 1 ) ;
2006-03-13 01:48:25 +03:00
parms - > splopen . out . file . fnum = SVAL ( req - > in . vwv , VWV ( 0 ) ) ;
2003-08-13 05:53:07 +04:00
break ;
case RAW_OPEN_NTCREATEX :
2004-08-04 17:23:35 +04:00
SMBCLI_CHECK_MIN_WCT ( req , 34 ) ;
2003-08-13 05:53:07 +04:00
parms - > ntcreatex . out . oplock_level = CVAL ( req - > in . vwv , 4 ) ;
2006-03-13 01:48:25 +03:00
parms - > ntcreatex . out . file . fnum = SVAL ( req - > in . vwv , 5 ) ;
2003-08-13 05:53:07 +04:00
parms - > ntcreatex . out . create_action = IVAL ( req - > in . vwv , 7 ) ;
2004-08-04 17:23:35 +04:00
parms - > ntcreatex . out . create_time = smbcli_pull_nttime ( req - > in . vwv , 11 ) ;
parms - > ntcreatex . out . access_time = smbcli_pull_nttime ( req - > in . vwv , 19 ) ;
parms - > ntcreatex . out . write_time = smbcli_pull_nttime ( req - > in . vwv , 27 ) ;
parms - > ntcreatex . out . change_time = smbcli_pull_nttime ( req - > in . vwv , 35 ) ;
2003-08-13 05:53:07 +04:00
parms - > ntcreatex . out . attrib = IVAL ( req - > in . vwv , 43 ) ;
parms - > ntcreatex . out . alloc_size = BVAL ( req - > in . vwv , 47 ) ;
parms - > ntcreatex . out . size = BVAL ( req - > in . vwv , 55 ) ;
parms - > ntcreatex . out . file_type = SVAL ( req - > in . vwv , 63 ) ;
parms - > ntcreatex . out . ipc_state = SVAL ( req - > in . vwv , 65 ) ;
parms - > ntcreatex . out . is_directory = CVAL ( req - > in . vwv , 67 ) ;
break ;
2004-11-17 23:56:26 +03:00
case RAW_OPEN_NTTRANS_CREATE :
return smb_raw_nttrans_create_recv ( req , mem_ctx , parms ) ;
2004-12-26 11:13:01 +03:00
case RAW_OPEN_OPENX_READX :
SMBCLI_CHECK_MIN_WCT ( req , 15 ) ;
2006-03-13 01:48:25 +03:00
parms - > openxreadx . out . file . fnum = SVAL ( req - > in . vwv , VWV ( 2 ) ) ;
2004-12-26 11:13:01 +03:00
parms - > openxreadx . out . attrib = SVAL ( req - > in . vwv , VWV ( 3 ) ) ;
parms - > openxreadx . out . write_time = raw_pull_dos_date3 ( req - > transport ,
req - > in . vwv + VWV ( 4 ) ) ;
parms - > openxreadx . out . size = IVAL ( req - > in . vwv , VWV ( 6 ) ) ;
parms - > openxreadx . out . access = SVAL ( req - > in . vwv , VWV ( 8 ) ) ;
parms - > openxreadx . out . ftype = SVAL ( req - > in . vwv , VWV ( 9 ) ) ;
parms - > openxreadx . out . devstate = SVAL ( req - > in . vwv , VWV ( 10 ) ) ;
parms - > openxreadx . out . action = SVAL ( req - > in . vwv , VWV ( 11 ) ) ;
parms - > openxreadx . out . unique_fid = IVAL ( req - > in . vwv , VWV ( 12 ) ) ;
if ( req - > in . wct > = 19 ) {
parms - > openxreadx . out . access_mask = IVAL ( req - > in . vwv , VWV ( 15 ) ) ;
parms - > openxreadx . out . unknown = IVAL ( req - > in . vwv , VWV ( 17 ) ) ;
} else {
parms - > openxreadx . out . access_mask = 0 ;
parms - > openxreadx . out . unknown = 0 ;
}
status = smbcli_chained_advance ( req ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
SMBCLI_CHECK_WCT ( req , 12 ) ;
parms - > openxreadx . out . remaining = SVAL ( req - > in . vwv , VWV ( 2 ) ) ;
parms - > openxreadx . out . compaction_mode = SVAL ( req - > in . vwv , VWV ( 3 ) ) ;
parms - > openxreadx . out . nread = SVAL ( req - > in . vwv , VWV ( 5 ) ) ;
2023-10-31 17:48:09 +03:00
if ( parms - > openxreadx . out . nread >
2004-12-26 11:13:01 +03:00
MAX ( parms - > openxreadx . in . mincnt , parms - > openxreadx . in . maxcnt ) | |
2023-10-31 17:48:09 +03:00
! smbcli_raw_pull_data ( & req - > in . bufinfo , req - > in . hdr + SVAL ( req - > in . vwv , VWV ( 6 ) ) ,
parms - > openxreadx . out . nread ,
2004-12-26 11:13:01 +03:00
parms - > openxreadx . out . data ) ) {
req - > status = NT_STATUS_BUFFER_TOO_SMALL ;
}
break ;
2009-10-02 03:13:37 +04:00
case RAW_OPEN_NTCREATEX_READX :
SMBCLI_CHECK_MIN_WCT ( req , 34 ) ;
parms - > ntcreatexreadx . out . oplock_level = CVAL ( req - > in . vwv , 4 ) ;
parms - > ntcreatexreadx . out . file . fnum = SVAL ( req - > in . vwv , 5 ) ;
parms - > ntcreatexreadx . out . create_action = IVAL ( req - > in . vwv , 7 ) ;
parms - > ntcreatexreadx . out . create_time = smbcli_pull_nttime ( req - > in . vwv , 11 ) ;
parms - > ntcreatexreadx . out . access_time = smbcli_pull_nttime ( req - > in . vwv , 19 ) ;
parms - > ntcreatexreadx . out . write_time = smbcli_pull_nttime ( req - > in . vwv , 27 ) ;
parms - > ntcreatexreadx . out . change_time = smbcli_pull_nttime ( req - > in . vwv , 35 ) ;
parms - > ntcreatexreadx . out . attrib = IVAL ( req - > in . vwv , 43 ) ;
parms - > ntcreatexreadx . out . alloc_size = BVAL ( req - > in . vwv , 47 ) ;
parms - > ntcreatexreadx . out . size = BVAL ( req - > in . vwv , 55 ) ;
parms - > ntcreatexreadx . out . file_type = SVAL ( req - > in . vwv , 63 ) ;
parms - > ntcreatexreadx . out . ipc_state = SVAL ( req - > in . vwv , 65 ) ;
parms - > ntcreatexreadx . out . is_directory = CVAL ( req - > in . vwv , 67 ) ;
status = smbcli_chained_advance ( req ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
SMBCLI_CHECK_WCT ( req , 12 ) ;
parms - > ntcreatexreadx . out . remaining = SVAL ( req - > in . vwv , VWV ( 2 ) ) ;
parms - > ntcreatexreadx . out . compaction_mode = SVAL ( req - > in . vwv , VWV ( 3 ) ) ;
parms - > ntcreatexreadx . out . nread = SVAL ( req - > in . vwv , VWV ( 5 ) ) ;
if ( parms - > ntcreatexreadx . out . nread >
2009-10-15 11:52:56 +04:00
MAX ( parms - > ntcreatexreadx . in . mincnt , parms - > ntcreatexreadx . in . maxcnt ) | |
2009-10-02 03:13:37 +04:00
! smbcli_raw_pull_data ( & req - > in . bufinfo , req - > in . hdr + SVAL ( req - > in . vwv , VWV ( 6 ) ) ,
parms - > ntcreatexreadx . out . nread ,
parms - > ntcreatexreadx . out . data ) ) {
req - > status = NT_STATUS_BUFFER_TOO_SMALL ;
}
break ;
2006-05-20 14:46:38 +04:00
case RAW_OPEN_SMB2 :
req - > status = NT_STATUS_INTERNAL_ERROR ;
break ;
2003-08-13 05:53:07 +04:00
}
failed :
2004-08-04 17:23:35 +04:00
return smbcli_request_destroy ( req ) ;
2003-08-13 05:53:07 +04:00
}
/****************************************************************************
Open a file - sync interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-02 06:53:27 +04:00
_PUBLIC_ NTSTATUS smb_raw_open ( struct smbcli_tree * tree , TALLOC_CTX * mem_ctx , union smb_open * parms )
2003-08-13 05:53:07 +04:00
{
2004-08-04 17:23:35 +04:00
struct smbcli_request * req = smb_raw_open_send ( tree , parms ) ;
2003-08-13 05:53:07 +04:00
return smb_raw_open_recv ( req , mem_ctx , parms ) ;
}
/****************************************************************************
Close a file - async send
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-02 06:53:27 +04:00
_PUBLIC_ struct smbcli_request * smb_raw_close_send ( struct smbcli_tree * tree , union smb_close * parms )
2003-08-13 05:53:07 +04:00
{
2023-10-31 17:48:09 +03:00
struct smbcli_request * req = NULL ;
2003-08-13 05:53:07 +04:00
switch ( parms - > generic . level ) {
case RAW_CLOSE_CLOSE :
SETUP_REQUEST ( SMBclose , 3 , 0 ) ;
2006-03-13 01:48:25 +03:00
SSVAL ( req - > out . vwv , VWV ( 0 ) , parms - > close . in . file . fnum ) ;
2023-10-31 17:48:09 +03:00
raw_push_dos_date3 ( tree - > session - > transport ,
2004-04-11 00:18:22 +04:00
req - > out . vwv , VWV ( 1 ) , parms - > close . in . write_time ) ;
2003-08-13 05:53:07 +04:00
break ;
case RAW_CLOSE_SPLCLOSE :
SETUP_REQUEST ( SMBsplclose , 3 , 0 ) ;
2006-03-13 01:48:25 +03:00
SSVAL ( req - > out . vwv , VWV ( 0 ) , parms - > splclose . in . file . fnum ) ;
2003-08-13 05:53:07 +04:00
SIVAL ( req - > out . vwv , VWV ( 1 ) , 0 ) ; /* reserved */
break ;
2006-05-20 14:46:38 +04:00
case RAW_CLOSE_SMB2 :
2009-03-30 15:47:58 +04:00
case RAW_CLOSE_GENERIC :
2006-05-20 14:46:38 +04:00
return NULL ;
2003-08-13 05:53:07 +04:00
}
if ( ! req ) return NULL ;
2004-08-04 17:23:35 +04:00
if ( ! smbcli_request_send ( req ) ) {
smbcli_request_destroy ( req ) ;
2003-08-13 05:53:07 +04:00
return NULL ;
}
return req ;
}
/****************************************************************************
Close a file - sync interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-02 06:53:27 +04:00
_PUBLIC_ NTSTATUS smb_raw_close ( struct smbcli_tree * tree , union smb_close * parms )
2003-08-13 05:53:07 +04:00
{
2004-08-04 17:23:35 +04:00
struct smbcli_request * req = smb_raw_close_send ( tree , parms ) ;
return smbcli_request_simple_recv ( req ) ;
2003-08-13 05:53:07 +04:00
}
/****************************************************************************
Locking calls - async interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-08-04 17:23:35 +04:00
struct smbcli_request * smb_raw_lock_send ( struct smbcli_tree * tree , union smb_lock * parms )
2003-08-13 05:53:07 +04:00
{
2023-10-31 17:48:09 +03:00
struct smbcli_request * req = NULL ;
2003-08-13 05:53:07 +04:00
switch ( parms - > generic . level ) {
case RAW_LOCK_LOCK :
SETUP_REQUEST ( SMBlock , 5 , 0 ) ;
2006-03-13 01:48:25 +03:00
SSVAL ( req - > out . vwv , VWV ( 0 ) , parms - > lock . in . file . fnum ) ;
2003-08-13 05:53:07 +04:00
SIVAL ( req - > out . vwv , VWV ( 1 ) , parms - > lock . in . count ) ;
SIVAL ( req - > out . vwv , VWV ( 3 ) , parms - > lock . in . offset ) ;
break ;
2023-10-31 17:48:09 +03:00
2003-08-13 05:53:07 +04:00
case RAW_LOCK_UNLOCK :
SETUP_REQUEST ( SMBunlock , 5 , 0 ) ;
2006-03-13 01:48:25 +03:00
SSVAL ( req - > out . vwv , VWV ( 0 ) , parms - > unlock . in . file . fnum ) ;
2003-08-13 05:53:07 +04:00
SIVAL ( req - > out . vwv , VWV ( 1 ) , parms - > unlock . in . count ) ;
SIVAL ( req - > out . vwv , VWV ( 3 ) , parms - > unlock . in . offset ) ;
break ;
2023-10-31 17:48:09 +03:00
2003-08-13 05:53:07 +04:00
case RAW_LOCK_LOCKX : {
struct smb_lock_entry * lockp ;
2010-01-05 20:42:54 +03:00
unsigned int lck_size = ( parms - > lockx . in . mode & LOCKING_ANDX_LARGE_FILES ) ? 20 : 10 ;
unsigned int lock_count = parms - > lockx . in . ulock_cnt + parms - > lockx . in . lock_cnt ;
2003-08-13 05:53:07 +04:00
int i ;
SETUP_REQUEST ( SMBlockingX , 8 , lck_size * lock_count ) ;
SSVAL ( req - > out . vwv , VWV ( 0 ) , SMB_CHAIN_NONE ) ;
SSVAL ( req - > out . vwv , VWV ( 1 ) , 0 ) ;
2006-03-13 01:48:25 +03:00
SSVAL ( req - > out . vwv , VWV ( 2 ) , parms - > lockx . in . file . fnum ) ;
2003-08-13 05:53:07 +04:00
SSVAL ( req - > out . vwv , VWV ( 3 ) , parms - > lockx . in . mode ) ;
SIVAL ( req - > out . vwv , VWV ( 4 ) , parms - > lockx . in . timeout ) ;
SSVAL ( req - > out . vwv , VWV ( 6 ) , parms - > lockx . in . ulock_cnt ) ;
SSVAL ( req - > out . vwv , VWV ( 7 ) , parms - > lockx . in . lock_cnt ) ;
2023-10-31 17:48:09 +03:00
2003-08-13 05:53:07 +04:00
/* copy in all the locks */
lockp = & parms - > lockx . in . locks [ 0 ] ;
for ( i = 0 ; i < lock_count ; i + + ) {
2004-12-04 16:56:25 +03:00
uint8_t * p = req - > out . data + lck_size * i ;
2003-08-13 05:53:07 +04:00
SSVAL ( p , 0 , lockp [ i ] . pid ) ;
if ( parms - > lockx . in . mode & LOCKING_ANDX_LARGE_FILES ) {
SSVAL ( p , 2 , 0 ) ; /* reserved */
SIVAL ( p , 4 , lockp [ i ] . offset > > 32 ) ;
SIVAL ( p , 8 , lockp [ i ] . offset ) ;
SIVAL ( p , 12 , lockp [ i ] . count > > 32 ) ;
SIVAL ( p , 16 , lockp [ i ] . count ) ;
} else {
SIVAL ( p , 2 , lockp [ i ] . offset ) ;
SIVAL ( p , 6 , lockp [ i ] . count ) ;
}
2023-10-31 17:48:09 +03:00
}
2006-05-23 13:27:58 +04:00
break ;
2003-08-13 05:53:07 +04:00
}
2006-05-22 21:21:38 +04:00
case RAW_LOCK_SMB2 :
2011-06-11 18:55:16 +04:00
case RAW_LOCK_SMB2_BREAK :
2006-05-22 21:21:38 +04:00
return NULL ;
2003-08-13 05:53:07 +04:00
}
2004-08-04 17:23:35 +04:00
if ( ! smbcli_request_send ( req ) ) {
smbcli_request_destroy ( req ) ;
2003-08-13 05:53:07 +04:00
return NULL ;
}
return req ;
}
/****************************************************************************
Locking calls - sync interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-02 06:53:27 +04:00
_PUBLIC_ NTSTATUS smb_raw_lock ( struct smbcli_tree * tree , union smb_lock * parms )
2003-08-13 05:53:07 +04:00
{
2004-08-04 17:23:35 +04:00
struct smbcli_request * req = smb_raw_lock_send ( tree , parms ) ;
return smbcli_request_simple_recv ( req ) ;
2003-08-13 05:53:07 +04:00
}
2023-10-31 17:48:09 +03:00
2003-08-13 05:53:07 +04:00
/****************************************************************************
Check for existence of a dir - async send
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-03-10 23:49:20 +03:00
struct smbcli_request * smb_raw_chkpath_send ( struct smbcli_tree * tree , union smb_chkpath * parms )
2003-08-13 05:53:07 +04:00
{
2023-10-31 17:48:09 +03:00
struct smbcli_request * req ;
2003-08-13 05:53:07 +04:00
2011-07-12 11:26:53 +04:00
SETUP_REQUEST ( SMBcheckpath , 0 , 0 ) ;
2003-08-13 05:53:07 +04:00
2006-03-10 23:49:20 +03:00
smbcli_req_append_ascii4 ( req , parms - > chkpath . in . path , STR_TERMINATE ) ;
2003-08-13 05:53:07 +04:00
2004-08-04 17:23:35 +04:00
if ( ! smbcli_request_send ( req ) ) {
smbcli_request_destroy ( req ) ;
2003-08-13 05:53:07 +04:00
return NULL ;
}
return req ;
}
/****************************************************************************
Check for existence of a dir - sync interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-03-10 23:49:20 +03:00
NTSTATUS smb_raw_chkpath ( struct smbcli_tree * tree , union smb_chkpath * parms )
2003-08-13 05:53:07 +04:00
{
2004-08-04 17:23:35 +04:00
struct smbcli_request * req = smb_raw_chkpath_send ( tree , parms ) ;
return smbcli_request_simple_recv ( req ) ;
2003-08-13 05:53:07 +04:00
}
/****************************************************************************
flush a file - async send
2006-05-20 13:38:59 +04:00
a flush with RAW_FLUSH_ALL will flush all files
2003-08-13 05:53:07 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-03-10 23:49:20 +03:00
struct smbcli_request * smb_raw_flush_send ( struct smbcli_tree * tree , union smb_flush * parms )
2003-08-13 05:53:07 +04:00
{
2023-10-31 17:48:09 +03:00
struct smbcli_request * req ;
2006-09-09 14:05:58 +04:00
uint16_t fnum = 0 ;
2006-05-19 19:10:39 +04:00
switch ( parms - > generic . level ) {
case RAW_FLUSH_FLUSH :
fnum = parms - > flush . in . file . fnum ;
break ;
case RAW_FLUSH_ALL :
fnum = 0xFFFF ;
break ;
2006-05-20 14:46:38 +04:00
case RAW_FLUSH_SMB2 :
return NULL ;
2006-05-19 19:10:39 +04:00
}
2003-08-13 05:53:07 +04:00
SETUP_REQUEST ( SMBflush , 1 , 0 ) ;
2006-05-19 19:10:39 +04:00
SSVAL ( req - > out . vwv , VWV ( 0 ) , fnum ) ;
2003-08-13 05:53:07 +04:00
2004-08-04 17:23:35 +04:00
if ( ! smbcli_request_send ( req ) ) {
smbcli_request_destroy ( req ) ;
2003-08-13 05:53:07 +04:00
return NULL ;
}
return req ;
}
/****************************************************************************
flush a file - sync interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-02 06:53:27 +04:00
_PUBLIC_ NTSTATUS smb_raw_flush ( struct smbcli_tree * tree , union smb_flush * parms )
2003-08-13 05:53:07 +04:00
{
2004-08-04 17:23:35 +04:00
struct smbcli_request * req = smb_raw_flush_send ( tree , parms ) ;
return smbcli_request_simple_recv ( req ) ;
2003-08-13 05:53:07 +04:00
}
/****************************************************************************
seek a file - async send
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-08-04 17:23:35 +04:00
struct smbcli_request * smb_raw_seek_send ( struct smbcli_tree * tree ,
2006-03-10 23:49:20 +03:00
union smb_seek * parms )
2003-08-13 05:53:07 +04:00
{
2023-10-31 17:48:09 +03:00
struct smbcli_request * req ;
2003-08-13 05:53:07 +04:00
SETUP_REQUEST ( SMBlseek , 4 , 0 ) ;
2006-03-13 01:48:25 +03:00
SSVAL ( req - > out . vwv , VWV ( 0 ) , parms - > lseek . in . file . fnum ) ;
2006-03-10 23:49:20 +03:00
SSVAL ( req - > out . vwv , VWV ( 1 ) , parms - > lseek . in . mode ) ;
SIVALS ( req - > out . vwv , VWV ( 2 ) , parms - > lseek . in . offset ) ;
2003-08-13 05:53:07 +04:00
2004-08-04 17:23:35 +04:00
if ( ! smbcli_request_send ( req ) ) {
smbcli_request_destroy ( req ) ;
2003-08-13 05:53:07 +04:00
return NULL ;
}
return req ;
}
/****************************************************************************
seek a file - async receive
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-08-04 17:23:35 +04:00
NTSTATUS smb_raw_seek_recv ( struct smbcli_request * req ,
2006-03-10 23:49:20 +03:00
union smb_seek * parms )
2003-08-13 05:53:07 +04:00
{
2004-08-04 17:23:35 +04:00
if ( ! smbcli_request_receive ( req ) | |
smbcli_request_is_error ( req ) ) {
return smbcli_request_destroy ( req ) ;
2003-08-13 05:53:07 +04:00
}
2023-10-31 17:48:09 +03:00
SMBCLI_CHECK_WCT ( req , 2 ) ;
2006-03-10 23:49:20 +03:00
parms - > lseek . out . offset = IVAL ( req - > in . vwv , VWV ( 0 ) ) ;
2003-08-13 05:53:07 +04:00
2023-10-31 17:48:09 +03:00
failed :
2004-08-04 17:23:35 +04:00
return smbcli_request_destroy ( req ) ;
2003-08-13 05:53:07 +04:00
}
/*
seek a file - sync interface
*/
2008-04-02 06:53:27 +04:00
_PUBLIC_ NTSTATUS smb_raw_seek ( struct smbcli_tree * tree ,
2006-03-10 23:49:20 +03:00
union smb_seek * parms )
2003-08-13 05:53:07 +04:00
{
2004-08-04 17:23:35 +04:00
struct smbcli_request * req = smb_raw_seek_send ( tree , parms ) ;
2003-08-13 05:53:07 +04:00
return smb_raw_seek_recv ( req , parms ) ;
}