2003-08-13 01:53:07 +00:00
/*
Unix SMB / CIFS implementation .
client file operations
Copyright ( C ) Andrew Tridgell 2003
2003-12-04 02:03:06 +00:00
Copyright ( C ) James J Myers 2003 < myersjj @ samba . org >
2003-08-13 01:53:07 +00: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 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"
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"
2003-08-13 01:53:07 +00:00
# define SETUP_REQUEST(cmd, wct, buflen) do { \
2004-08-04 13:23:35 +00:00
req = smbcli_request_setup ( tree , cmd , wct , buflen ) ; \
2003-08-13 01:53:07 +00:00
if ( ! req ) return NULL ; \
} while ( 0 )
/*
2003-12-04 02:03:06 +00:00
send a raw smb ioctl - async send
2003-08-13 01:53:07 +00:00
*/
2004-08-04 13:23:35 +00:00
static struct smbcli_request * smb_raw_smbioctl_send ( struct smbcli_tree * tree ,
2003-12-04 02:03:06 +00:00
union smb_ioctl * parms )
2003-08-13 01:53:07 +00:00
{
2004-08-04 13:23:35 +00:00
struct smbcli_request * req ;
2003-08-13 01:53:07 +00:00
SETUP_REQUEST ( SMBioctl , 3 , 0 ) ;
2006-03-12 22:48:25 +00:00
SSVAL ( req - > out . vwv , VWV ( 0 ) , parms - > ioctl . in . file . fnum ) ;
2003-12-04 02:03:06 +00:00
SIVAL ( req - > out . vwv , VWV ( 1 ) , parms - > ioctl . in . request ) ;
2003-08-13 01:53:07 +00:00
2004-08-04 13:23:35 +00:00
if ( ! smbcli_request_send ( req ) ) {
smbcli_request_destroy ( req ) ;
2003-08-13 01:53:07 +00:00
return NULL ;
}
return req ;
}
/*
2003-12-04 02:03:06 +00:00
send a raw smb ioctl - async recv
2003-08-13 01:53:07 +00:00
*/
2004-08-04 13:23:35 +00:00
static NTSTATUS smb_raw_smbioctl_recv ( struct smbcli_request * req ,
2003-12-04 02:03:06 +00:00
TALLOC_CTX * mem_ctx ,
union smb_ioctl * parms )
2003-08-13 01:53:07 +00:00
{
2004-08-04 13:23:35 +00:00
if ( ! smbcli_request_receive ( req ) | |
smbcli_request_is_error ( req ) ) {
return smbcli_request_destroy ( req ) ;
2003-08-13 01:53:07 +00:00
}
2008-02-14 10:12:33 +11:00
parms - > ioctl . out . blob = smbcli_req_pull_blob ( & req - > in . bufinfo , mem_ctx , req - > in . data , - 1 ) ;
2004-08-04 13:23:35 +00:00
return smbcli_request_destroy ( req ) ;
2003-08-13 01:53:07 +00:00
}
/****************************************************************************
NT ioctl ( async send )
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-08-04 13:23:35 +00:00
static struct smbcli_request * smb_raw_ntioctl_send ( struct smbcli_tree * tree ,
2003-12-04 02:03:06 +00:00
union smb_ioctl * parms )
2003-08-13 01:53:07 +00:00
{
struct smb_nttrans nt ;
2006-04-08 02:35:00 +00:00
uint8_t setup [ 8 ] ;
2003-08-13 01:53:07 +00:00
2006-05-18 11:15:18 +00:00
nt . in . max_setup = 4 ;
2003-08-13 01:53:07 +00:00
nt . in . max_param = 0 ;
2006-05-17 09:52:14 +00:00
nt . in . max_data = parms - > ntioctl . in . max_data ;
2003-08-13 01:53:07 +00:00
nt . in . setup_count = 4 ;
2007-02-07 00:21:29 +00:00
nt . in . setup = setup ;
2003-12-04 02:03:06 +00:00
SIVAL ( setup , 0 , parms - > ntioctl . in . function ) ;
2006-03-12 22:48:25 +00:00
SSVAL ( setup , 4 , parms - > ntioctl . in . file . fnum ) ;
2003-12-04 02:03:06 +00:00
SCVAL ( setup , 6 , parms - > ntioctl . in . fsctl ) ;
SCVAL ( setup , 7 , parms - > ntioctl . in . filter ) ;
2003-08-13 01:53:07 +00:00
nt . in . function = NT_TRANSACT_IOCTL ;
nt . in . params = data_blob ( NULL , 0 ) ;
2006-05-16 16:50:50 +00:00
nt . in . data = parms - > ntioctl . in . blob ;
2003-08-13 01:53:07 +00:00
return smb_raw_nttrans_send ( tree , & nt ) ;
}
/****************************************************************************
NT ioctl ( async recv )
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-08-04 13:23:35 +00:00
static NTSTATUS smb_raw_ntioctl_recv ( struct smbcli_request * req ,
2003-12-04 02:03:06 +00:00
TALLOC_CTX * mem_ctx ,
union smb_ioctl * parms )
2003-08-13 01:53:07 +00:00
{
2006-05-16 16:50:50 +00:00
NTSTATUS status ;
struct smb_nttrans nt ;
TALLOC_CTX * tmp_mem ;
2003-08-13 01:53:07 +00:00
2006-05-16 16:50:50 +00:00
tmp_mem = talloc_new ( mem_ctx ) ;
NT_STATUS_HAVE_NO_MEMORY ( tmp_mem ) ;
status = smb_raw_nttrans_recv ( req , tmp_mem , & nt ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) goto fail ;
parms - > ntioctl . out . blob = nt . out . data ;
talloc_steal ( mem_ctx , parms - > ntioctl . out . blob . data ) ;
fail :
talloc_free ( tmp_mem ) ;
return status ;
2003-08-13 01:53:07 +00:00
}
2003-12-04 02:03:06 +00:00
/*
send a raw ioctl - async send
*/
2004-08-04 13:23:35 +00:00
struct smbcli_request * smb_raw_ioctl_send ( struct smbcli_tree * tree , union smb_ioctl * parms )
2003-12-04 02:03:06 +00:00
{
2004-08-04 13:23:35 +00:00
struct smbcli_request * req = NULL ;
2003-12-04 02:03:06 +00:00
switch ( parms - > generic . level ) {
case RAW_IOCTL_IOCTL :
req = smb_raw_smbioctl_send ( tree , parms ) ;
break ;
case RAW_IOCTL_NTIOCTL :
req = smb_raw_ntioctl_send ( tree , parms ) ;
break ;
2006-05-20 10:46:38 +00:00
case RAW_IOCTL_SMB2 :
2006-07-10 14:01:53 +00:00
case RAW_IOCTL_SMB2_NO_HANDLE :
2006-05-20 10:46:38 +00:00
return NULL ;
2003-12-04 02:03:06 +00:00
}
return req ;
}
/*
recv a raw ioctl - async recv
*/
2004-08-04 13:23:35 +00:00
NTSTATUS smb_raw_ioctl_recv ( struct smbcli_request * req ,
2003-12-04 02:03:06 +00:00
TALLOC_CTX * mem_ctx , union smb_ioctl * parms )
2003-08-13 01:53:07 +00:00
{
2003-12-04 02:03:06 +00:00
switch ( parms - > generic . level ) {
case RAW_IOCTL_IOCTL :
return smb_raw_smbioctl_recv ( req , mem_ctx , parms ) ;
case RAW_IOCTL_NTIOCTL :
return smb_raw_ntioctl_recv ( req , mem_ctx , parms ) ;
2006-05-20 10:46:38 +00:00
case RAW_IOCTL_SMB2 :
2006-07-10 14:01:53 +00:00
case RAW_IOCTL_SMB2_NO_HANDLE :
2006-05-20 10:46:38 +00:00
break ;
2003-12-04 02:03:06 +00:00
}
return NT_STATUS_INVALID_LEVEL ;
}
/*
send a raw ioctl - sync interface
*/
2008-04-02 04:53:27 +02:00
NTSTATUS smb_raw_ioctl ( struct smbcli_tree * tree ,
2003-12-04 02:03:06 +00:00
TALLOC_CTX * mem_ctx , union smb_ioctl * parms )
{
2004-08-04 13:23:35 +00:00
struct smbcli_request * req ;
2003-12-04 02:03:06 +00:00
req = smb_raw_ioctl_send ( tree , parms ) ;
return smb_raw_ioctl_recv ( req , mem_ctx , parms ) ;
2003-08-13 01:53:07 +00:00
}