2000-04-25 18:04:06 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2000-04-25 18:04:06 +04:00
client file operations
Copyright ( C ) Andrew Tridgell 1994 - 1998
2009-04-29 00:18:51 +04:00
Copyright ( C ) Jeremy Allison 2001 - 2009
2000-04-25 18:04:06 +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-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2000-04-25 18:04:06 +04: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 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2000-04-25 18:04:06 +04:00
*/
# include "includes.h"
2009-05-28 04:28:23 +04:00
/***********************************************************
Common function for pushing stings , used by smb_bytes_push_str ( )
and trans_bytes_push_str ( ) . Only difference is the align_odd
parameter setting .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static uint8_t * internal_bytes_push_str ( uint8_t * buf , bool ucs2 ,
const char * str , size_t str_len ,
bool align_odd ,
size_t * pconverted_size )
{
size_t buflen ;
char * converted ;
size_t converted_size ;
if ( buf = = NULL ) {
return NULL ;
}
buflen = talloc_get_size ( buf ) ;
if ( align_odd & & ucs2 & & ( buflen % 2 = = 0 ) ) {
/*
* We ' re pushing into an SMB buffer , align odd
*/
buf = TALLOC_REALLOC_ARRAY ( NULL , buf , uint8_t , buflen + 1 ) ;
if ( buf = = NULL ) {
return NULL ;
}
buf [ buflen ] = ' \0 ' ;
buflen + = 1 ;
}
if ( ! convert_string_talloc ( talloc_tos ( ) , CH_UNIX ,
ucs2 ? CH_UTF16LE : CH_DOS ,
str , str_len , & converted ,
& converted_size , true ) ) {
return NULL ;
}
buf = TALLOC_REALLOC_ARRAY ( NULL , buf , uint8_t ,
buflen + converted_size ) ;
if ( buf = = NULL ) {
TALLOC_FREE ( converted ) ;
return NULL ;
}
memcpy ( buf + buflen , converted , converted_size ) ;
TALLOC_FREE ( converted ) ;
if ( pconverted_size ) {
* pconverted_size = converted_size ;
}
return buf ;
}
/***********************************************************
Push a string into an SMB buffer , with odd byte alignment
if it ' s a UCS2 string .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
uint8_t * smb_bytes_push_str ( uint8_t * buf , bool ucs2 ,
const char * str , size_t str_len ,
size_t * pconverted_size )
{
return internal_bytes_push_str ( buf , ucs2 , str , str_len ,
true , pconverted_size ) ;
}
/***********************************************************
Same as smb_bytes_push_str ( ) , but without the odd byte
align for ucs2 ( we ' re pushing into a param or data block ) .
static for now , although this will probably change when
other modules use async trans calls .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static uint8_t * trans2_bytes_push_str ( uint8_t * buf , bool ucs2 ,
const char * str , size_t str_len ,
size_t * pconverted_size )
{
return internal_bytes_push_str ( buf , ucs2 , str , str_len ,
false , pconverted_size ) ;
}
2002-01-16 23:13:28 +03:00
/****************************************************************************
Hard / Symlink a file ( UNIX extensions ) .
2004-04-07 03:01:09 +04:00
Creates new name ( sym ) linked to oldname .
2002-01-16 23:13:28 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-05-28 04:28:23 +04:00
struct link_state {
uint16_t setup ;
uint8_t * param ;
uint8_t * data ;
} ;
static void cli_posix_link_internal_done ( struct tevent_req * subreq )
2002-01-16 23:13:28 +03:00
{
2009-11-16 11:59:58 +03:00
NTSTATUS status = cli_trans_recv ( subreq , NULL , NULL , 0 , NULL ,
NULL , 0 , NULL , NULL , 0 , NULL ) ;
2009-11-17 17:15:35 +03:00
tevent_req_simple_finish_ntstatus ( subreq , status ) ;
2009-05-28 04:28:23 +04:00
}
2008-02-18 13:00:51 +03:00
2009-05-28 04:28:23 +04:00
static struct tevent_req * cli_posix_link_internal_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * oldname ,
const char * newname ,
bool hardlink )
{
struct tevent_req * req = NULL , * subreq = NULL ;
struct link_state * state = NULL ;
req = tevent_req_create ( mem_ctx , & state , struct link_state ) ;
if ( req = = NULL ) {
return NULL ;
2008-02-18 13:00:51 +03:00
}
2009-05-28 04:28:23 +04:00
/* Setup setup word. */
SSVAL ( & state - > setup , 0 , TRANSACT2_SETPATHINFO ) ;
2008-02-18 13:00:51 +03:00
2009-05-28 04:28:23 +04:00
/* Setup param array. */
state - > param = talloc_array ( state , uint8_t , 6 ) ;
if ( tevent_req_nomem ( state - > param , req ) ) {
return tevent_req_post ( req , ev ) ;
2007-12-06 00:31:24 +03:00
}
2009-05-28 04:28:23 +04:00
memset ( state - > param , ' \0 ' , 6 ) ;
SSVAL ( state - > param , 0 , hardlink ? SMB_SET_FILE_UNIX_HLINK : SMB_SET_FILE_UNIX_LINK ) ;
2007-12-06 00:31:24 +03:00
2009-05-28 04:28:23 +04:00
state - > param = trans2_bytes_push_str ( state - > param , cli_ucs2 ( cli ) , newname ,
strlen ( newname ) + 1 , NULL ) ;
2002-01-16 23:13:28 +03:00
2009-05-28 04:28:23 +04:00
if ( tevent_req_nomem ( state - > param , req ) ) {
return tevent_req_post ( req , ev ) ;
}
2002-01-16 23:13:28 +03:00
2009-05-28 04:28:23 +04:00
/* Setup data array. */
state - > data = talloc_array ( state , uint8_t , 0 ) ;
if ( tevent_req_nomem ( state - > data , req ) ) {
return tevent_req_post ( req , ev ) ;
}
state - > data = trans2_bytes_push_str ( state - > data , cli_ucs2 ( cli ) , oldname ,
strlen ( oldname ) + 1 , NULL ) ;
subreq = cli_trans_send ( state , /* mem ctx. */
ev , /* event ctx. */
cli , /* cli_state. */
SMBtrans2 , /* cmd. */
NULL , /* pipe name. */
- 1 , /* fid. */
0 , /* function. */
0 , /* flags. */
& state - > setup , /* setup. */
1 , /* num setup uint16_t words. */
0 , /* max returned setup. */
state - > param , /* param. */
talloc_get_size ( state - > param ) , /* num param. */
2 , /* max returned param. */
state - > data , /* data. */
talloc_get_size ( state - > data ) , /* num data. */
0 ) ; /* max returned data. */
2002-01-16 23:13:28 +03:00
2009-05-28 04:28:23 +04:00
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
2002-01-16 23:13:28 +03:00
}
2009-05-28 04:28:23 +04:00
tevent_req_set_callback ( subreq , cli_posix_link_internal_done , req ) ;
return req ;
}
2002-01-16 23:13:28 +03:00
2009-05-28 04:28:23 +04:00
/****************************************************************************
Symlink a file ( UNIX extensions ) .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-06 00:31:24 +03:00
2009-05-28 04:28:23 +04:00
struct tevent_req * cli_posix_symlink_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * oldname ,
const char * newname )
{
return cli_posix_link_internal_send ( mem_ctx , ev , cli ,
oldname , newname , false ) ;
}
NTSTATUS cli_posix_symlink_recv ( struct tevent_req * req )
{
NTSTATUS status ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
2002-01-16 23:13:28 +03:00
}
2009-05-28 04:28:23 +04:00
return NT_STATUS_OK ;
}
2002-01-16 23:13:28 +03:00
2009-05-28 04:28:23 +04:00
NTSTATUS cli_posix_symlink ( struct cli_state * cli ,
const char * oldname ,
const char * newname )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
2002-01-16 23:13:28 +03:00
2009-05-28 04:28:23 +04:00
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_posix_symlink_send ( frame ,
ev ,
cli ,
oldname ,
newname ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_posix_symlink_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
}
2009-05-28 08:51:15 +04:00
/****************************************************************************
Read a POSIX symlink .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
struct readlink_state {
uint16_t setup ;
uint8_t * param ;
uint8_t * data ;
uint32_t num_data ;
} ;
static void cli_posix_readlink_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct readlink_state * state = tevent_req_data ( req , struct readlink_state ) ;
NTSTATUS status ;
2009-11-14 13:12:50 +03:00
status = cli_trans_recv ( subreq , state , NULL , 0 , NULL , NULL , 0 , NULL ,
& state - > data , 0 , & state - > num_data ) ;
2009-05-28 08:51:15 +04:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
}
if ( state - > num_data = = 0 ) {
tevent_req_nterror ( req , NT_STATUS_DATA_ERROR ) ;
return ;
}
if ( state - > data [ state - > num_data - 1 ] ! = ' \0 ' ) {
tevent_req_nterror ( req , NT_STATUS_DATA_ERROR ) ;
return ;
}
tevent_req_done ( req ) ;
}
struct tevent_req * cli_posix_readlink_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname ,
size_t len )
{
struct tevent_req * req = NULL , * subreq = NULL ;
struct readlink_state * state = NULL ;
uint32_t maxbytelen = ( uint32_t ) ( cli_ucs2 ( cli ) ? len * 3 : len ) ;
if ( maxbytelen < len ) {
return NULL ;
}
req = tevent_req_create ( mem_ctx , & state , struct readlink_state ) ;
if ( req = = NULL ) {
return NULL ;
}
/* Setup setup word. */
SSVAL ( & state - > setup , 0 , TRANSACT2_QPATHINFO ) ;
/* Setup param array. */
state - > param = talloc_array ( state , uint8_t , 6 ) ;
if ( tevent_req_nomem ( state - > param , req ) ) {
return tevent_req_post ( req , ev ) ;
}
memset ( state - > param , ' \0 ' , 6 ) ;
SSVAL ( state - > param , 0 , SMB_QUERY_FILE_UNIX_LINK ) ;
state - > param = trans2_bytes_push_str ( state - > param , cli_ucs2 ( cli ) , fname ,
strlen ( fname ) + 1 , NULL ) ;
if ( tevent_req_nomem ( state - > param , req ) ) {
return tevent_req_post ( req , ev ) ;
}
subreq = cli_trans_send ( state , /* mem ctx. */
ev , /* event ctx. */
cli , /* cli_state. */
SMBtrans2 , /* cmd. */
NULL , /* pipe name. */
- 1 , /* fid. */
0 , /* function. */
0 , /* flags. */
& state - > setup , /* setup. */
1 , /* num setup uint16_t words. */
0 , /* max returned setup. */
state - > param , /* param. */
talloc_get_size ( state - > param ) , /* num param. */
2 , /* max returned param. */
NULL , /* data. */
0 , /* num data. */
maxbytelen ) ; /* max returned data. */
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , cli_posix_readlink_done , req ) ;
return req ;
}
NTSTATUS cli_posix_readlink_recv ( struct tevent_req * req , struct cli_state * cli ,
char * retpath , size_t len )
{
NTSTATUS status ;
char * converted = NULL ;
size_t converted_size = 0 ;
struct readlink_state * state = tevent_req_data ( req , struct readlink_state ) ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
/* The returned data is a pushed string, not raw data. */
if ( ! convert_string_talloc ( state ,
cli_ucs2 ( cli ) ? CH_UTF16LE : CH_DOS ,
CH_UNIX ,
state - > data ,
state - > num_data ,
& converted ,
& converted_size ,
true ) ) {
return NT_STATUS_NO_MEMORY ;
}
len = MIN ( len , converted_size ) ;
if ( len = = 0 ) {
return NT_STATUS_DATA_ERROR ;
}
memcpy ( retpath , converted , len ) ;
return NT_STATUS_OK ;
}
NTSTATUS cli_posix_readlink ( struct cli_state * cli , const char * fname ,
char * linkpath , size_t len )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
/* Len is in bytes, we need it in UCS2 units. */
if ( 2 * len < len ) {
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
req = cli_posix_readlink_send ( frame ,
ev ,
cli ,
fname ,
len ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_posix_readlink_recv ( req , cli , linkpath , len ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
}
2009-05-28 04:28:23 +04:00
/****************************************************************************
Hard link a file ( UNIX extensions ) .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
struct tevent_req * cli_posix_hardlink_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * oldname ,
const char * newname )
{
return cli_posix_link_internal_send ( mem_ctx , ev , cli ,
oldname , newname , true ) ;
}
NTSTATUS cli_posix_hardlink_recv ( struct tevent_req * req )
{
NTSTATUS status ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
return NT_STATUS_OK ;
}
NTSTATUS cli_posix_hardlink ( struct cli_state * cli ,
const char * oldname ,
const char * newname )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_posix_hardlink_send ( frame ,
ev ,
cli ,
oldname ,
newname ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_posix_hardlink_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2002-01-16 23:13:28 +03:00
}
/****************************************************************************
Map standard UNIX permissions onto wire representations .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-04-24 18:06:48 +04:00
uint32_t unix_perms_to_wire ( mode_t perms )
2002-01-16 23:13:28 +03:00
{
2002-07-15 14:35:28 +04:00
unsigned int ret = 0 ;
2002-01-16 23:13:28 +03:00
ret | = ( ( perms & S_IXOTH ) ? UNIX_X_OTH : 0 ) ;
ret | = ( ( perms & S_IWOTH ) ? UNIX_W_OTH : 0 ) ;
ret | = ( ( perms & S_IROTH ) ? UNIX_R_OTH : 0 ) ;
ret | = ( ( perms & S_IXGRP ) ? UNIX_X_GRP : 0 ) ;
ret | = ( ( perms & S_IWGRP ) ? UNIX_W_GRP : 0 ) ;
ret | = ( ( perms & S_IRGRP ) ? UNIX_R_GRP : 0 ) ;
ret | = ( ( perms & S_IXUSR ) ? UNIX_X_USR : 0 ) ;
ret | = ( ( perms & S_IWUSR ) ? UNIX_W_USR : 0 ) ;
ret | = ( ( perms & S_IRUSR ) ? UNIX_R_USR : 0 ) ;
# ifdef S_ISVTX
ret | = ( ( perms & S_ISVTX ) ? UNIX_STICKY : 0 ) ;
# endif
# ifdef S_ISGID
ret | = ( ( perms & S_ISGID ) ? UNIX_SET_GID : 0 ) ;
# endif
# ifdef S_ISUID
2002-09-25 19:19:00 +04:00
ret | = ( ( perms & S_ISUID ) ? UNIX_SET_UID : 0 ) ;
2002-01-16 23:13:28 +03:00
# endif
return ret ;
}
2004-09-26 10:27:54 +04:00
/****************************************************************************
Map wire permissions to standard UNIX .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-04-24 18:06:48 +04:00
mode_t wire_perms_to_unix ( uint32_t perms )
2004-09-26 10:27:54 +04:00
{
mode_t ret = ( mode_t ) 0 ;
ret | = ( ( perms & UNIX_X_OTH ) ? S_IXOTH : 0 ) ;
ret | = ( ( perms & UNIX_W_OTH ) ? S_IWOTH : 0 ) ;
ret | = ( ( perms & UNIX_R_OTH ) ? S_IROTH : 0 ) ;
ret | = ( ( perms & UNIX_X_GRP ) ? S_IXGRP : 0 ) ;
ret | = ( ( perms & UNIX_W_GRP ) ? S_IWGRP : 0 ) ;
ret | = ( ( perms & UNIX_R_GRP ) ? S_IRGRP : 0 ) ;
ret | = ( ( perms & UNIX_X_USR ) ? S_IXUSR : 0 ) ;
ret | = ( ( perms & UNIX_W_USR ) ? S_IWUSR : 0 ) ;
ret | = ( ( perms & UNIX_R_USR ) ? S_IRUSR : 0 ) ;
# ifdef S_ISVTX
ret | = ( ( perms & UNIX_STICKY ) ? S_ISVTX : 0 ) ;
# endif
# ifdef S_ISGID
ret | = ( ( perms & UNIX_SET_GID ) ? S_ISGID : 0 ) ;
# endif
# ifdef S_ISUID
ret | = ( ( perms & UNIX_SET_UID ) ? S_ISUID : 0 ) ;
# endif
return ret ;
}
/****************************************************************************
Return the file type from the wire filetype for UNIX extensions .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-06 00:31:24 +03:00
2009-04-24 18:06:48 +04:00
static mode_t unix_filetype_from_wire ( uint32_t wire_type )
2004-09-26 10:27:54 +04:00
{
switch ( wire_type ) {
case UNIX_TYPE_FILE :
return S_IFREG ;
case UNIX_TYPE_DIR :
return S_IFDIR ;
# ifdef S_IFLNK
case UNIX_TYPE_SYMLINK :
return S_IFLNK ;
# endif
# ifdef S_IFCHR
case UNIX_TYPE_CHARDEV :
return S_IFCHR ;
# endif
# ifdef S_IFBLK
case UNIX_TYPE_BLKDEV :
return S_IFBLK ;
# endif
# ifdef S_IFIFO
case UNIX_TYPE_FIFO :
return S_IFIFO ;
# endif
# ifdef S_IFSOCK
case UNIX_TYPE_SOCKET :
return S_IFSOCK ;
# endif
default :
return ( mode_t ) 0 ;
}
}
2004-11-13 02:42:12 +03:00
/****************************************************************************
Do a POSIX getfacl ( UNIX extensions ) .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-05-29 00:05:50 +04:00
struct getfacl_state {
uint16_t setup ;
uint8_t * param ;
uint32_t num_data ;
uint8_t * data ;
} ;
static void cli_posix_getfacl_done ( struct tevent_req * subreq )
2004-11-13 02:42:12 +03:00
{
2009-05-29 00:05:50 +04:00
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct getfacl_state * state = tevent_req_data ( req , struct getfacl_state ) ;
NTSTATUS status ;
2009-11-14 13:12:50 +03:00
status = cli_trans_recv ( subreq , state , NULL , 0 , NULL , NULL , 0 , NULL ,
& state - > data , 0 , & state - > num_data ) ;
2009-05-29 00:05:50 +04:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
}
tevent_req_done ( req ) ;
}
struct tevent_req * cli_posix_getfacl_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname )
{
struct tevent_req * req = NULL , * subreq = NULL ;
struct link_state * state = NULL ;
req = tevent_req_create ( mem_ctx , & state , struct getfacl_state ) ;
if ( req = = NULL ) {
return NULL ;
}
/* Setup setup word. */
SSVAL ( & state - > setup , 0 , TRANSACT2_QPATHINFO ) ;
/* Setup param array. */
state - > param = talloc_array ( state , uint8_t , 6 ) ;
if ( tevent_req_nomem ( state - > param , req ) ) {
return tevent_req_post ( req , ev ) ;
}
memset ( state - > param , ' \0 ' , 6 ) ;
SSVAL ( state - > param , 0 , SMB_QUERY_POSIX_ACL ) ;
state - > param = trans2_bytes_push_str ( state - > param , cli_ucs2 ( cli ) , fname ,
strlen ( fname ) + 1 , NULL ) ;
if ( tevent_req_nomem ( state - > param , req ) ) {
return tevent_req_post ( req , ev ) ;
}
subreq = cli_trans_send ( state , /* mem ctx. */
ev , /* event ctx. */
cli , /* cli_state. */
SMBtrans2 , /* cmd. */
NULL , /* pipe name. */
- 1 , /* fid. */
0 , /* function. */
0 , /* flags. */
& state - > setup , /* setup. */
1 , /* num setup uint16_t words. */
0 , /* max returned setup. */
state - > param , /* param. */
talloc_get_size ( state - > param ) , /* num param. */
2 , /* max returned param. */
NULL , /* data. */
0 , /* num data. */
cli - > max_xmit ) ; /* max returned data. */
2004-11-13 02:42:12 +03:00
2009-05-29 00:05:50 +04:00
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
2007-12-06 00:31:24 +03:00
}
2009-05-29 00:05:50 +04:00
tevent_req_set_callback ( subreq , cli_posix_getfacl_done , req ) ;
return req ;
}
2007-12-06 00:31:24 +03:00
2009-05-29 00:05:50 +04:00
NTSTATUS cli_posix_getfacl_recv ( struct tevent_req * req ,
TALLOC_CTX * mem_ctx ,
size_t * prb_size ,
char * * retbuf )
{
struct getfacl_state * state = tevent_req_data ( req , struct getfacl_state ) ;
NTSTATUS status ;
2004-11-13 02:42:12 +03:00
2009-05-29 00:05:50 +04:00
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
2004-11-13 02:42:12 +03:00
}
2009-05-29 00:05:50 +04:00
* prb_size = ( size_t ) state - > num_data ;
* retbuf = ( char * ) talloc_move ( mem_ctx , & state - > data ) ;
return NT_STATUS_OK ;
}
2004-11-13 02:42:12 +03:00
2009-05-29 00:05:50 +04:00
NTSTATUS cli_posix_getfacl ( struct cli_state * cli ,
const char * fname ,
TALLOC_CTX * mem_ctx ,
size_t * prb_size ,
char * * retbuf )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
2007-12-06 00:31:24 +03:00
2009-05-29 00:05:50 +04:00
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
2004-11-13 02:42:12 +03:00
}
2009-05-29 00:05:50 +04:00
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
2004-11-13 02:42:12 +03:00
}
2009-05-29 00:05:50 +04:00
req = cli_posix_getfacl_send ( frame ,
ev ,
cli ,
fname ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_posix_getfacl_recv ( req , mem_ctx , prb_size , retbuf ) ;
2004-11-13 02:42:12 +03:00
2009-05-29 00:05:50 +04:00
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2004-11-13 02:42:12 +03:00
}
2004-09-26 10:27:54 +04:00
/****************************************************************************
Stat a file ( UNIX extensions ) .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-05-29 00:32:00 +04:00
struct stat_state {
uint16_t setup ;
uint8_t * param ;
uint32_t num_data ;
uint8_t * data ;
} ;
static void cli_posix_stat_done ( struct tevent_req * subreq )
2004-09-26 10:27:54 +04:00
{
2009-05-29 00:32:00 +04:00
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct stat_state * state = tevent_req_data ( req , struct stat_state ) ;
NTSTATUS status ;
2009-11-14 13:12:50 +03:00
status = cli_trans_recv ( subreq , state , NULL , 0 , NULL , NULL , 0 , NULL ,
& state - > data , 96 , & state - > num_data ) ;
2009-05-29 00:32:00 +04:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
}
tevent_req_done ( req ) ;
}
2004-09-26 10:27:54 +04:00
2009-05-29 00:32:00 +04:00
struct tevent_req * cli_posix_stat_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname )
{
struct tevent_req * req = NULL , * subreq = NULL ;
struct stat_state * state = NULL ;
2004-09-26 10:27:54 +04:00
2009-05-29 00:32:00 +04:00
req = tevent_req_create ( mem_ctx , & state , struct stat_state ) ;
if ( req = = NULL ) {
return NULL ;
2007-12-06 00:31:24 +03:00
}
2004-09-26 10:27:54 +04:00
2009-05-29 00:32:00 +04:00
/* Setup setup word. */
SSVAL ( & state - > setup , 0 , TRANSACT2_QPATHINFO ) ;
/* Setup param array. */
state - > param = talloc_array ( state , uint8_t , 6 ) ;
if ( tevent_req_nomem ( state - > param , req ) ) {
return tevent_req_post ( req , ev ) ;
2004-09-26 10:27:54 +04:00
}
2009-05-29 00:32:00 +04:00
memset ( state - > param , ' \0 ' , 6 ) ;
SSVAL ( state - > param , 0 , SMB_QUERY_FILE_UNIX_BASIC ) ;
2004-09-26 10:27:54 +04:00
2009-05-29 00:32:00 +04:00
state - > param = trans2_bytes_push_str ( state - > param , cli_ucs2 ( cli ) , fname ,
strlen ( fname ) + 1 , NULL ) ;
2007-12-06 00:31:24 +03:00
2009-05-29 00:32:00 +04:00
if ( tevent_req_nomem ( state - > param , req ) ) {
return tevent_req_post ( req , ev ) ;
2004-09-27 02:16:00 +04:00
}
2009-05-29 00:32:00 +04:00
subreq = cli_trans_send ( state , /* mem ctx. */
ev , /* event ctx. */
cli , /* cli_state. */
SMBtrans2 , /* cmd. */
NULL , /* pipe name. */
- 1 , /* fid. */
0 , /* function. */
0 , /* flags. */
& state - > setup , /* setup. */
1 , /* num setup uint16_t words. */
0 , /* max returned setup. */
state - > param , /* param. */
talloc_get_size ( state - > param ) , /* num param. */
2 , /* max returned param. */
NULL , /* data. */
0 , /* num data. */
96 ) ; /* max returned data. */
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , cli_posix_stat_done , req ) ;
return req ;
}
NTSTATUS cli_posix_stat_recv ( struct tevent_req * req ,
SMB_STRUCT_STAT * sbuf )
{
struct stat_state * state = tevent_req_data ( req , struct stat_state ) ;
NTSTATUS status ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
2004-09-26 10:27:54 +04:00
}
2009-05-29 00:32:00 +04:00
if ( state - > num_data ! = 96 ) {
return NT_STATUS_DATA_ERROR ;
}
sbuf - > st_ex_size = IVAL2_TO_SMB_BIG_UINT ( state - > data , 0 ) ; /* total size, in bytes */
sbuf - > st_ex_blocks = IVAL2_TO_SMB_BIG_UINT ( state - > data , 8 ) ; /* number of blocks allocated */
2005-07-06 18:46:36 +04:00
# if defined (HAVE_STAT_ST_BLOCKS) && defined(STAT_ST_BLOCKSIZE)
2009-05-14 17:34:42 +04:00
sbuf - > st_ex_blocks / = STAT_ST_BLOCKSIZE ;
2005-07-06 18:46:36 +04:00
# else
/* assume 512 byte blocks */
2009-05-14 17:34:42 +04:00
sbuf - > st_ex_blocks / = 512 ;
2005-07-06 18:46:36 +04:00
# endif
2009-05-29 00:32:00 +04:00
sbuf - > st_ex_ctime = interpret_long_date ( ( char * ) ( state - > data + 16 ) ) ; /* time of last change */
sbuf - > st_ex_atime = interpret_long_date ( ( char * ) ( state - > data + 24 ) ) ; /* time of last access */
sbuf - > st_ex_mtime = interpret_long_date ( ( char * ) ( state - > data + 32 ) ) ; /* time of last modification */
2006-08-24 20:44:00 +04:00
2009-05-29 00:32:00 +04:00
sbuf - > st_ex_uid = ( uid_t ) IVAL ( state - > data , 40 ) ; /* user ID of owner */
sbuf - > st_ex_gid = ( gid_t ) IVAL ( state - > data , 48 ) ; /* group ID of owner */
sbuf - > st_ex_mode = unix_filetype_from_wire ( IVAL ( state - > data , 56 ) ) ;
2004-09-26 10:27:54 +04:00
# if defined(HAVE_MAKEDEV)
{
2009-05-29 00:32:00 +04:00
uint32_t dev_major = IVAL ( state - > data , 60 ) ;
uint32_t dev_minor = IVAL ( state - > data , 68 ) ;
2009-05-14 17:34:42 +04:00
sbuf - > st_ex_rdev = makedev ( dev_major , dev_minor ) ;
2004-09-26 10:27:54 +04:00
}
# endif
2009-05-29 00:32:00 +04:00
sbuf - > st_ex_ino = ( SMB_INO_T ) IVAL2_TO_SMB_BIG_UINT ( state - > data , 76 ) ; /* inode */
sbuf - > st_ex_mode | = wire_perms_to_unix ( IVAL ( state - > data , 84 ) ) ; /* protection */
sbuf - > st_ex_nlink = IVAL ( state - > data , 92 ) ; /* number of hard links */
return NT_STATUS_OK ;
}
NTSTATUS cli_posix_stat ( struct cli_state * cli ,
const char * fname ,
SMB_STRUCT_STAT * sbuf )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
2004-09-26 10:27:54 +04:00
2009-05-29 00:32:00 +04:00
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
2004-09-26 10:27:54 +04:00
2009-05-29 00:32:00 +04:00
req = cli_posix_stat_send ( frame ,
ev ,
cli ,
fname ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_posix_stat_recv ( req , sbuf ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2004-09-26 10:27:54 +04:00
}
2009-05-29 00:32:00 +04:00
2002-01-16 23:13:28 +03:00
/****************************************************************************
Chmod or chown a file internal ( UNIX extensions ) .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-05-29 03:15:09 +04:00
struct ch_state {
uint16_t setup ;
uint8_t * param ;
uint8_t * data ;
} ;
static void cli_posix_chown_chmod_internal_done ( struct tevent_req * subreq )
2002-01-16 23:13:28 +03:00
{
2009-11-16 11:59:58 +03:00
NTSTATUS status = cli_trans_recv ( subreq , NULL , NULL , 0 , NULL ,
NULL , 0 , NULL , NULL , 0 , NULL ) ;
2009-11-17 17:15:35 +03:00
tevent_req_simple_finish_ntstatus ( subreq , status ) ;
2009-05-29 03:15:09 +04:00
}
2007-12-06 00:31:24 +03:00
2009-05-29 03:15:09 +04:00
static struct tevent_req * cli_posix_chown_chmod_internal_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname ,
uint32_t mode ,
uint32_t uid ,
uint32_t gid )
{
struct tevent_req * req = NULL , * subreq = NULL ;
struct ch_state * state = NULL ;
2002-01-16 23:13:28 +03:00
2009-05-29 03:15:09 +04:00
req = tevent_req_create ( mem_ctx , & state , struct ch_state ) ;
if ( req = = NULL ) {
return NULL ;
}
2002-01-16 23:13:28 +03:00
2009-05-29 03:15:09 +04:00
/* Setup setup word. */
SSVAL ( & state - > setup , 0 , TRANSACT2_SETPATHINFO ) ;
2007-03-01 01:29:14 +03:00
2009-05-29 03:15:09 +04:00
/* Setup param array. */
state - > param = talloc_array ( state , uint8_t , 6 ) ;
if ( tevent_req_nomem ( state - > param , req ) ) {
return tevent_req_post ( req , ev ) ;
}
memset ( state - > param , ' \0 ' , 6 ) ;
SSVAL ( state - > param , 0 , SMB_SET_FILE_UNIX_BASIC ) ;
2002-01-16 23:13:28 +03:00
2009-05-29 03:15:09 +04:00
state - > param = trans2_bytes_push_str ( state - > param , cli_ucs2 ( cli ) , fname ,
strlen ( fname ) + 1 , NULL ) ;
2002-01-16 23:13:28 +03:00
2009-05-29 03:15:09 +04:00
if ( tevent_req_nomem ( state - > param , req ) ) {
return tevent_req_post ( req , ev ) ;
2002-01-16 23:13:28 +03:00
}
2009-05-29 03:15:09 +04:00
/* Setup data array. */
state - > data = talloc_array ( state , uint8_t , 100 ) ;
if ( tevent_req_nomem ( state - > data , req ) ) {
return tevent_req_post ( req , ev ) ;
2002-01-16 23:13:28 +03:00
}
2009-05-29 03:15:09 +04:00
memset ( state - > data , 0xff , 40 ) ; /* Set all sizes/times to no change. */
memset ( & state - > data [ 40 ] , ' \0 ' , 60 ) ;
SIVAL ( state - > data , 40 , uid ) ;
SIVAL ( state - > data , 48 , gid ) ;
SIVAL ( state - > data , 84 , mode ) ;
2002-01-16 23:13:28 +03:00
2009-05-29 03:15:09 +04:00
subreq = cli_trans_send ( state , /* mem ctx. */
ev , /* event ctx. */
cli , /* cli_state. */
SMBtrans2 , /* cmd. */
NULL , /* pipe name. */
- 1 , /* fid. */
0 , /* function. */
0 , /* flags. */
& state - > setup , /* setup. */
1 , /* num setup uint16_t words. */
0 , /* max returned setup. */
state - > param , /* param. */
talloc_get_size ( state - > param ) , /* num param. */
2 , /* max returned param. */
state - > data , /* data. */
talloc_get_size ( state - > data ) , /* num data. */
0 ) ; /* max returned data. */
2002-01-16 23:13:28 +03:00
2009-05-29 03:15:09 +04:00
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , cli_posix_chown_chmod_internal_done , req ) ;
return req ;
2002-01-16 23:13:28 +03:00
}
/****************************************************************************
chmod a file ( UNIX extensions ) .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-05-29 03:15:09 +04:00
struct tevent_req * cli_posix_chmod_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname ,
mode_t mode )
{
return cli_posix_chown_chmod_internal_send ( mem_ctx , ev , cli ,
fname ,
unix_perms_to_wire ( mode ) ,
SMB_UID_NO_CHANGE ,
SMB_GID_NO_CHANGE ) ;
}
NTSTATUS cli_posix_chmod_recv ( struct tevent_req * req )
2002-01-16 23:13:28 +03:00
{
2009-05-29 03:15:09 +04:00
NTSTATUS status ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
return NT_STATUS_OK ;
}
NTSTATUS cli_posix_chmod ( struct cli_state * cli , const char * fname , mode_t mode )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_posix_chmod_send ( frame ,
ev ,
cli ,
fname ,
mode ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_posix_chmod_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2002-01-16 23:13:28 +03:00
}
/****************************************************************************
chown a file ( UNIX extensions ) .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-05-29 03:15:09 +04:00
struct tevent_req * cli_posix_chown_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname ,
uid_t uid ,
gid_t gid )
{
return cli_posix_chown_chmod_internal_send ( mem_ctx , ev , cli ,
fname ,
SMB_MODE_NO_CHANGE ,
( uint32_t ) uid ,
( uint32_t ) gid ) ;
}
NTSTATUS cli_posix_chown_recv ( struct tevent_req * req )
{
NTSTATUS status ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
return NT_STATUS_OK ;
}
NTSTATUS cli_posix_chown ( struct cli_state * cli ,
const char * fname ,
uid_t uid ,
gid_t gid )
2002-01-16 23:13:28 +03:00
{
2009-05-29 03:15:09 +04:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_posix_chown_send ( frame ,
ev ,
cli ,
fname ,
uid ,
gid ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_posix_chown_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2002-01-16 23:13:28 +03:00
}
2000-04-25 18:04:06 +04:00
/****************************************************************************
2001-11-04 03:14:08 +03:00
Rename a file .
2000-04-25 18:04:06 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-11-04 03:14:08 +03:00
2009-04-29 03:43:16 +04:00
static void cli_rename_done ( struct tevent_req * subreq ) ;
struct cli_rename_state {
uint16_t vwv [ 1 ] ;
} ;
struct tevent_req * cli_rename_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname_src ,
const char * fname_dst )
2000-04-25 18:04:06 +04:00
{
2009-04-29 03:43:16 +04:00
struct tevent_req * req = NULL , * subreq = NULL ;
struct cli_rename_state * state = NULL ;
uint8_t additional_flags = 0 ;
uint8_t * bytes = NULL ;
req = tevent_req_create ( mem_ctx , & state , struct cli_rename_state ) ;
if ( req = = NULL ) {
return NULL ;
}
2000-04-25 18:04:06 +04:00
2009-04-29 03:43:16 +04:00
SSVAL ( state - > vwv + 0 , 0 , aSYSTEM | aHIDDEN | aDIR ) ;
2000-04-25 18:04:06 +04:00
2009-04-29 03:43:16 +04:00
bytes = talloc_array ( state , uint8_t , 1 ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
bytes [ 0 ] = 4 ;
bytes = smb_bytes_push_str ( bytes , cli_ucs2 ( cli ) , fname_src ,
strlen ( fname_src ) + 1 , NULL ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
2000-04-25 18:04:06 +04:00
2009-04-29 03:43:16 +04:00
bytes = TALLOC_REALLOC_ARRAY ( state , bytes , uint8_t ,
talloc_get_size ( bytes ) + 1 ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
2000-04-25 18:04:06 +04:00
2009-04-29 03:43:16 +04:00
bytes [ talloc_get_size ( bytes ) - 1 ] = 4 ;
bytes = smb_bytes_push_str ( bytes , cli_ucs2 ( cli ) , fname_dst ,
strlen ( fname_dst ) + 1 , NULL ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
2000-04-25 18:04:06 +04:00
2009-04-29 03:43:16 +04:00
subreq = cli_smb_send ( state , ev , cli , SMBmv , additional_flags ,
1 , state - > vwv , talloc_get_size ( bytes ) , bytes ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , cli_rename_done , req ) ;
return req ;
}
static void cli_rename_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
NTSTATUS status ;
2010-02-20 11:53:58 +03:00
status = cli_smb_recv ( subreq , NULL , NULL , 0 , NULL , NULL , NULL , NULL ) ;
2009-04-29 03:43:16 +04:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
}
tevent_req_done ( req ) ;
}
2001-02-20 15:45:50 +03:00
2009-04-29 03:43:16 +04:00
NTSTATUS cli_rename_recv ( struct tevent_req * req )
{
return tevent_req_simple_recv_ntstatus ( req ) ;
}
2000-04-25 18:04:06 +04:00
2009-04-29 03:43:16 +04:00
NTSTATUS cli_rename ( struct cli_state * cli , const char * fname_src , const char * fname_dst )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev ;
struct tevent_req * req ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
2007-12-06 00:31:24 +03:00
}
2000-04-25 18:04:06 +04:00
2009-04-29 03:43:16 +04:00
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
2007-12-06 00:31:24 +03:00
}
2000-04-25 18:04:06 +04:00
2009-04-29 03:43:16 +04:00
req = cli_rename_send ( frame , ev , cli , fname_src , fname_dst ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_rename_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2000-04-25 18:04:06 +04:00
}
2004-03-03 23:55:59 +03:00
/****************************************************************************
NT Rename a file .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-05-08 20:40:35 +04:00
static void cli_ntrename_internal_done ( struct tevent_req * subreq ) ;
2009-04-29 21:48:16 +04:00
2009-05-08 20:40:35 +04:00
struct cli_ntrename_internal_state {
2009-04-29 21:48:16 +04:00
uint16_t vwv [ 4 ] ;
} ;
2009-05-08 20:40:35 +04:00
static struct tevent_req * cli_ntrename_internal_send ( TALLOC_CTX * mem_ctx ,
2009-04-29 21:48:16 +04:00
struct event_context * ev ,
struct cli_state * cli ,
const char * fname_src ,
const char * fname_dst ,
uint16_t rename_flag )
2004-03-03 23:55:59 +03:00
{
2009-04-29 21:48:16 +04:00
struct tevent_req * req = NULL , * subreq = NULL ;
2009-05-08 20:40:35 +04:00
struct cli_ntrename_internal_state * state = NULL ;
2009-04-29 21:48:16 +04:00
uint8_t additional_flags = 0 ;
uint8_t * bytes = NULL ;
2004-03-03 23:55:59 +03:00
2009-05-08 20:40:35 +04:00
req = tevent_req_create ( mem_ctx , & state ,
struct cli_ntrename_internal_state ) ;
2009-04-29 21:48:16 +04:00
if ( req = = NULL ) {
return NULL ;
}
2004-03-03 23:55:59 +03:00
2009-04-29 21:48:16 +04:00
SSVAL ( state - > vwv + 0 , 0 , aSYSTEM | aHIDDEN | aDIR ) ;
SSVAL ( state - > vwv + 1 , 0 , rename_flag ) ;
2004-03-03 23:55:59 +03:00
2009-04-29 21:48:16 +04:00
bytes = talloc_array ( state , uint8_t , 1 ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
bytes [ 0 ] = 4 ;
bytes = smb_bytes_push_str ( bytes , cli_ucs2 ( cli ) , fname_src ,
strlen ( fname_src ) + 1 , NULL ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
2004-03-03 23:55:59 +03:00
2009-04-29 21:48:16 +04:00
bytes = TALLOC_REALLOC_ARRAY ( state , bytes , uint8_t ,
talloc_get_size ( bytes ) + 1 ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
2004-03-03 23:55:59 +03:00
2009-04-29 21:48:16 +04:00
bytes [ talloc_get_size ( bytes ) - 1 ] = 4 ;
bytes = smb_bytes_push_str ( bytes , cli_ucs2 ( cli ) , fname_dst ,
strlen ( fname_dst ) + 1 , NULL ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
2004-03-03 23:55:59 +03:00
2009-04-29 21:48:16 +04:00
subreq = cli_smb_send ( state , ev , cli , SMBntrename , additional_flags ,
4 , state - > vwv , talloc_get_size ( bytes ) , bytes ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
2009-05-08 20:40:35 +04:00
tevent_req_set_callback ( subreq , cli_ntrename_internal_done , req ) ;
2009-04-29 21:48:16 +04:00
return req ;
}
2004-03-03 23:55:59 +03:00
2009-05-08 20:40:35 +04:00
static void cli_ntrename_internal_done ( struct tevent_req * subreq )
2009-04-29 21:48:16 +04:00
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
NTSTATUS status ;
2010-02-20 11:53:58 +03:00
status = cli_smb_recv ( subreq , NULL , NULL , 0 , NULL , NULL , NULL , NULL ) ;
2009-04-29 21:48:16 +04:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
2007-12-06 00:31:24 +03:00
}
2009-04-29 21:48:16 +04:00
tevent_req_done ( req ) ;
}
2004-03-03 23:55:59 +03:00
2009-05-08 20:40:35 +04:00
static NTSTATUS cli_ntrename_internal_recv ( struct tevent_req * req )
2009-04-29 21:48:16 +04:00
{
return tevent_req_simple_recv_ntstatus ( req ) ;
}
2009-05-08 20:40:35 +04:00
struct tevent_req * cli_ntrename_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname_src ,
const char * fname_dst )
{
return cli_ntrename_internal_send ( mem_ctx ,
ev ,
cli ,
fname_src ,
fname_dst ,
RENAME_FLAG_RENAME ) ;
}
NTSTATUS cli_ntrename_recv ( struct tevent_req * req )
{
return cli_ntrename_internal_recv ( req ) ;
}
2009-04-29 21:48:16 +04:00
NTSTATUS cli_ntrename ( struct cli_state * cli , const char * fname_src , const char * fname_dst )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev ;
struct tevent_req * req ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
2007-12-06 00:31:24 +03:00
}
2004-03-03 23:55:59 +03:00
2009-04-29 21:48:16 +04:00
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_ntrename_send ( frame , ev , cli , fname_src , fname_dst ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_ntrename_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2004-03-03 23:55:59 +03:00
}
2004-03-04 02:14:23 +03:00
/****************************************************************************
NT hardlink a file .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-04-29 21:48:16 +04:00
struct tevent_req * cli_nt_hardlink_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname_src ,
const char * fname_dst )
2004-03-04 02:14:23 +03:00
{
2009-05-08 20:40:35 +04:00
return cli_ntrename_internal_send ( mem_ctx ,
ev ,
cli ,
fname_src ,
fname_dst ,
RENAME_FLAG_HARD_LINK ) ;
2009-04-29 21:48:16 +04:00
}
2004-03-04 02:14:23 +03:00
2009-04-29 21:48:16 +04:00
NTSTATUS cli_nt_hardlink_recv ( struct tevent_req * req )
{
2009-05-08 20:40:35 +04:00
return cli_ntrename_internal_recv ( req ) ;
2009-04-29 21:48:16 +04:00
}
2004-03-04 02:14:23 +03:00
2009-04-29 21:48:16 +04:00
NTSTATUS cli_nt_hardlink ( struct cli_state * cli , const char * fname_src , const char * fname_dst )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev ;
struct tevent_req * req ;
NTSTATUS status = NT_STATUS_OK ;
2004-03-04 02:14:23 +03:00
2009-04-29 21:48:16 +04:00
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
2004-03-04 02:14:23 +03:00
2009-04-29 21:48:16 +04:00
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
2004-03-04 02:14:23 +03:00
2009-04-29 21:48:16 +04:00
req = cli_nt_hardlink_send ( frame , ev , cli , fname_src , fname_dst ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
2007-12-06 00:31:24 +03:00
}
2004-03-04 02:14:23 +03:00
2009-04-29 21:48:16 +04:00
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
2007-12-06 00:31:24 +03:00
}
2004-03-04 02:14:23 +03:00
2009-04-29 21:48:16 +04:00
status = cli_nt_hardlink_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2004-03-04 02:14:23 +03:00
}
2000-04-25 18:04:06 +04:00
/****************************************************************************
2001-11-04 03:14:08 +03:00
Delete a file .
2000-04-25 18:04:06 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-11-04 03:14:08 +03:00
2009-04-30 05:26:02 +04:00
static void cli_unlink_done ( struct tevent_req * subreq ) ;
2000-04-25 18:04:06 +04:00
2009-04-30 05:26:02 +04:00
struct cli_unlink_state {
uint16_t vwv [ 1 ] ;
} ;
2000-04-25 18:04:06 +04:00
2009-04-30 05:26:02 +04:00
struct tevent_req * cli_unlink_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname ,
uint16_t mayhave_attrs )
{
struct tevent_req * req = NULL , * subreq = NULL ;
struct cli_unlink_state * state = NULL ;
uint8_t additional_flags = 0 ;
uint8_t * bytes = NULL ;
2000-04-25 18:04:06 +04:00
2009-04-30 05:26:02 +04:00
req = tevent_req_create ( mem_ctx , & state , struct cli_unlink_state ) ;
if ( req = = NULL ) {
return NULL ;
}
2000-04-25 18:04:06 +04:00
2009-04-30 05:26:02 +04:00
SSVAL ( state - > vwv + 0 , 0 , mayhave_attrs ) ;
2007-12-06 00:31:24 +03:00
2009-04-30 05:26:02 +04:00
bytes = talloc_array ( state , uint8_t , 1 ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
bytes [ 0 ] = 4 ;
bytes = smb_bytes_push_str ( bytes , cli_ucs2 ( cli ) , fname ,
strlen ( fname ) + 1 , NULL ) ;
2000-04-25 18:04:06 +04:00
2009-04-30 05:26:02 +04:00
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
2000-04-25 18:04:06 +04:00
}
2009-04-30 05:26:02 +04:00
subreq = cli_smb_send ( state , ev , cli , SMBunlink , additional_flags ,
1 , state - > vwv , talloc_get_size ( bytes ) , bytes ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
2000-04-25 18:04:06 +04:00
}
2009-04-30 05:26:02 +04:00
tevent_req_set_callback ( subreq , cli_unlink_done , req ) ;
return req ;
}
2000-04-25 18:04:06 +04:00
2009-04-30 05:26:02 +04:00
static void cli_unlink_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
NTSTATUS status ;
2010-02-20 11:53:58 +03:00
status = cli_smb_recv ( subreq , NULL , NULL , 0 , NULL , NULL , NULL , NULL ) ;
2009-04-30 05:26:02 +04:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
}
tevent_req_done ( req ) ;
2000-04-25 18:04:06 +04:00
}
2009-04-30 05:26:02 +04:00
NTSTATUS cli_unlink_recv ( struct tevent_req * req )
{
return tevent_req_simple_recv_ntstatus ( req ) ;
}
2007-03-07 22:45:22 +03:00
2009-04-30 05:26:02 +04:00
NTSTATUS cli_unlink ( struct cli_state * cli , const char * fname , uint16_t mayhave_attrs )
2007-03-07 22:45:22 +03:00
{
2009-04-30 05:26:02 +04:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev ;
struct tevent_req * req ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_unlink_send ( frame , ev , cli , fname , mayhave_attrs ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_unlink_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2007-03-07 22:45:22 +03:00
}
2009-04-21 16:52:34 +04:00
/****************************************************************************
Create a directory .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void cli_mkdir_done ( struct tevent_req * subreq ) ;
struct cli_mkdir_state {
int dummy ;
} ;
struct tevent_req * cli_mkdir_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * dname )
{
struct tevent_req * req = NULL , * subreq = NULL ;
struct cli_mkdir_state * state = NULL ;
uint8_t additional_flags = 0 ;
uint8_t * bytes = NULL ;
req = tevent_req_create ( mem_ctx , & state , struct cli_mkdir_state ) ;
if ( req = = NULL ) {
return NULL ;
}
bytes = talloc_array ( state , uint8_t , 1 ) ;
2009-04-21 19:42:39 +04:00
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
2009-04-21 16:52:34 +04:00
}
bytes [ 0 ] = 4 ;
bytes = smb_bytes_push_str ( bytes , cli_ucs2 ( cli ) , dname ,
strlen ( dname ) + 1 , NULL ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
subreq = cli_smb_send ( state , ev , cli , SMBmkdir , additional_flags ,
2009-04-21 19:42:39 +04:00
0 , NULL , talloc_get_size ( bytes ) , bytes ) ;
2009-04-21 16:52:34 +04:00
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , cli_mkdir_done , req ) ;
return req ;
}
static void cli_mkdir_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
NTSTATUS status ;
2010-02-20 11:53:58 +03:00
status = cli_smb_recv ( subreq , NULL , NULL , 0 , NULL , NULL , NULL , NULL ) ;
2009-04-21 16:52:34 +04:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
}
tevent_req_done ( req ) ;
}
NTSTATUS cli_mkdir_recv ( struct tevent_req * req )
{
return tevent_req_simple_recv_ntstatus ( req ) ;
}
NTSTATUS cli_mkdir ( struct cli_state * cli , const char * dname )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev ;
struct tevent_req * req ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_mkdir_send ( frame , ev , cli , dname ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_mkdir_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
}
2000-04-25 18:04:06 +04:00
/****************************************************************************
2001-11-04 03:14:08 +03:00
Remove a directory .
2000-04-25 18:04:06 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-11-04 03:14:08 +03:00
2009-04-21 17:52:54 +04:00
static void cli_rmdir_done ( struct tevent_req * subreq ) ;
struct cli_rmdir_state {
int dummy ;
} ;
struct tevent_req * cli_rmdir_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * dname )
2000-04-25 18:04:06 +04:00
{
2009-04-21 17:52:54 +04:00
struct tevent_req * req = NULL , * subreq = NULL ;
struct cli_rmdir_state * state = NULL ;
uint8_t additional_flags = 0 ;
uint8_t * bytes = NULL ;
2000-04-25 18:04:06 +04:00
2009-04-21 17:52:54 +04:00
req = tevent_req_create ( mem_ctx , & state , struct cli_rmdir_state ) ;
if ( req = = NULL ) {
return NULL ;
}
2000-04-25 18:04:06 +04:00
2009-04-21 17:52:54 +04:00
bytes = talloc_array ( state , uint8_t , 1 ) ;
2009-04-21 19:42:39 +04:00
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
2009-04-21 17:52:54 +04:00
}
bytes [ 0 ] = 4 ;
bytes = smb_bytes_push_str ( bytes , cli_ucs2 ( cli ) , dname ,
strlen ( dname ) + 1 , NULL ) ;
2000-04-25 18:04:06 +04:00
2009-04-21 17:52:54 +04:00
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
2000-04-25 18:04:06 +04:00
2009-04-21 17:52:54 +04:00
subreq = cli_smb_send ( state , ev , cli , SMBrmdir , additional_flags ,
2009-04-21 19:42:39 +04:00
0 , NULL , talloc_get_size ( bytes ) , bytes ) ;
2009-04-21 17:52:54 +04:00
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , cli_rmdir_done , req ) ;
return req ;
}
2001-02-20 15:30:01 +03:00
2009-04-21 17:52:54 +04:00
static void cli_rmdir_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
NTSTATUS status ;
2000-04-25 18:04:06 +04:00
2010-02-20 11:53:58 +03:00
status = cli_smb_recv ( subreq , NULL , NULL , 0 , NULL , NULL , NULL , NULL ) ;
2009-04-21 17:52:54 +04:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
2000-04-25 18:04:06 +04:00
}
2009-04-21 17:52:54 +04:00
tevent_req_done ( req ) ;
}
2000-04-25 18:04:06 +04:00
2009-04-21 17:52:54 +04:00
NTSTATUS cli_rmdir_recv ( struct tevent_req * req )
{
return tevent_req_simple_recv_ntstatus ( req ) ;
}
NTSTATUS cli_rmdir ( struct cli_state * cli , const char * dname )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev ;
struct tevent_req * req ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
2000-04-25 18:04:06 +04:00
}
2009-04-21 17:52:54 +04:00
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_rmdir_send ( frame , ev , cli , dname ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_rmdir_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
This is a big, rather ugly patch. Whilst investigating the files not truncated
when copying to a full disk problem, I discovered that we were not allowing
the delete on close flag to be set properly, this led to other things, and
after investigation of the proper delete on close semantics and their relationship
to the file_share_delete flag I discovered there were some cases where we
weren't doing the deny modes properly. And this after only 5 years working
on them..... :-) :-).
So here's the latest attempt. I realised the delete on close flag needs to
be set across all smbds with a dev/ino pair open - in addition, the delete
on close flag, allow share delete and delete access requested all need to
be stored in the share mode tdb.
The "delete_on_close" entry in the fsp struct is now redundant and should
really be removed. This may also mean we can get rid of the "iterate_fsp"
calls that I didn't like adding in the first place. Whilst doing this patch,
I also discovered we needed to do the se_map_generic() call for file opens
and POSIX ACL mapping, so I added that also.
This code, although ugly, now passes the deny mode torture tests plus the
delete on close tests I added. I do need to add one more multiple connection
delete on close test to make sure I got the semantics exactly right, plus we
should also (as Andrew suggested) move to random testing here.
The good news is that NT should now correctly delete the file on disk
full error when copying to a disk :-).
Jeremy.
(This used to be commit 51987684bd231c744da2e5f3705fd236d5616173)
2001-03-30 12:57:24 +04:00
}
/****************************************************************************
2001-03-29 06:58:47 +04:00
Set or clear the delete on close flag .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-05-30 01:58:34 +04:00
struct doc_state {
uint16_t setup ;
uint8_t param [ 6 ] ;
uint8_t data [ 1 ] ;
} ;
static void cli_nt_delete_on_close_done ( struct tevent_req * subreq )
{
2009-11-16 11:59:58 +03:00
NTSTATUS status = cli_trans_recv ( subreq , NULL , NULL , 0 , NULL ,
NULL , 0 , NULL , NULL , 0 , NULL ) ;
2009-11-17 17:15:35 +03:00
tevent_req_simple_finish_ntstatus ( subreq , status ) ;
2009-05-30 01:58:34 +04:00
}
struct tevent_req * cli_nt_delete_on_close_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
uint16_t fnum ,
bool flag )
{
struct tevent_req * req = NULL , * subreq = NULL ;
struct doc_state * state = NULL ;
req = tevent_req_create ( mem_ctx , & state , struct doc_state ) ;
if ( req = = NULL ) {
return NULL ;
}
/* Setup setup word. */
SSVAL ( & state - > setup , 0 , TRANSACT2_SETFILEINFO ) ;
/* Setup param array. */
SSVAL ( state - > param , 0 , fnum ) ;
SSVAL ( state - > param , 2 , SMB_SET_FILE_DISPOSITION_INFO ) ;
/* Setup data array. */
SCVAL ( & state - > data [ 0 ] , 0 , flag ? 1 : 0 ) ;
subreq = cli_trans_send ( state , /* mem ctx. */
ev , /* event ctx. */
cli , /* cli_state. */
SMBtrans2 , /* cmd. */
NULL , /* pipe name. */
- 1 , /* fid. */
0 , /* function. */
0 , /* flags. */
& state - > setup , /* setup. */
1 , /* num setup uint16_t words. */
0 , /* max returned setup. */
state - > param , /* param. */
6 , /* num param. */
2 , /* max returned param. */
state - > data , /* data. */
1 , /* num data. */
0 ) ; /* max returned data. */
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , cli_nt_delete_on_close_done , req ) ;
return req ;
}
NTSTATUS cli_nt_delete_on_close_recv ( struct tevent_req * req )
{
NTSTATUS status ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
return NT_STATUS_OK ;
}
NTSTATUS cli_nt_delete_on_close ( struct cli_state * cli , uint16_t fnum , bool flag )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_nt_delete_on_close_send ( frame ,
ev ,
cli ,
fnum ,
flag ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_nt_delete_on_close_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
}
2009-03-29 22:00:58 +04:00
struct cli_ntcreate_state {
uint16_t vwv [ 24 ] ;
uint16_t fnum ;
} ;
static void cli_ntcreate_done ( struct tevent_req * subreq ) ;
struct tevent_req * cli_ntcreate_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname ,
uint32_t CreatFlags ,
uint32_t DesiredAccess ,
uint32_t FileAttributes ,
uint32_t ShareAccess ,
uint32_t CreateDisposition ,
uint32_t CreateOptions ,
uint8_t SecurityFlags )
2009-01-26 22:45:19 +03:00
{
2009-03-29 22:00:58 +04:00
struct tevent_req * req , * subreq ;
struct cli_ntcreate_state * state ;
uint16_t * vwv ;
2009-01-26 22:45:19 +03:00
uint8_t * bytes ;
size_t converted_len ;
2009-03-29 22:00:58 +04:00
req = tevent_req_create ( mem_ctx , & state , struct cli_ntcreate_state ) ;
if ( req = = NULL ) {
return NULL ;
}
2009-07-15 22:49:33 +04:00
2009-03-29 22:00:58 +04:00
vwv = state - > vwv ;
2009-01-26 22:45:19 +03:00
SCVAL ( vwv + 0 , 0 , 0xFF ) ;
SCVAL ( vwv + 0 , 1 , 0 ) ;
SSVAL ( vwv + 1 , 0 , 0 ) ;
SCVAL ( vwv + 2 , 0 , 0 ) ;
if ( cli - > use_oplocks ) {
CreatFlags | = ( REQUEST_OPLOCK | REQUEST_BATCH_OPLOCK ) ;
}
SIVAL ( vwv + 3 , 1 , CreatFlags ) ;
SIVAL ( vwv + 5 , 1 , 0x0 ) ; /* RootDirectoryFid */
SIVAL ( vwv + 7 , 1 , DesiredAccess ) ;
SIVAL ( vwv + 9 , 1 , 0x0 ) ; /* AllocationSize */
SIVAL ( vwv + 11 , 1 , 0x0 ) ; /* AllocationSize */
SIVAL ( vwv + 13 , 1 , FileAttributes ) ;
SIVAL ( vwv + 15 , 1 , ShareAccess ) ;
SIVAL ( vwv + 17 , 1 , CreateDisposition ) ;
SIVAL ( vwv + 19 , 1 , CreateOptions ) ;
SIVAL ( vwv + 21 , 1 , 0x02 ) ; /* ImpersonationLevel */
SCVAL ( vwv + 23 , 1 , SecurityFlags ) ;
2009-03-29 22:00:58 +04:00
bytes = talloc_array ( state , uint8_t , 0 ) ;
2009-01-26 22:45:19 +03:00
bytes = smb_bytes_push_str ( bytes , cli_ucs2 ( cli ) ,
fname , strlen ( fname ) + 1 ,
& converted_len ) ;
/* sigh. this copes with broken netapp filer behaviour */
bytes = smb_bytes_push_str ( bytes , cli_ucs2 ( cli ) , " " , 1 , NULL ) ;
2009-03-29 22:00:58 +04:00
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
2009-01-26 22:45:19 +03:00
}
2009-09-15 02:06:37 +04:00
SSVAL ( vwv + 2 , 1 , converted_len ) ;
2009-01-26 22:45:19 +03:00
2009-03-29 22:00:58 +04:00
subreq = cli_smb_send ( state , ev , cli , SMBntcreateX , 0 , 24 , vwv ,
talloc_get_size ( bytes ) , bytes ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , cli_ntcreate_done , req ) ;
return req ;
2009-01-26 22:45:19 +03:00
}
2009-03-29 22:00:58 +04:00
static void cli_ntcreate_done ( struct tevent_req * subreq )
2009-01-26 22:45:19 +03:00
{
2009-03-29 22:00:58 +04:00
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct cli_ntcreate_state * state = tevent_req_data (
req , struct cli_ntcreate_state ) ;
2009-01-26 22:45:19 +03:00
uint8_t wct ;
uint16_t * vwv ;
2009-03-29 22:00:58 +04:00
uint32_t num_bytes ;
2009-01-26 22:45:19 +03:00
uint8_t * bytes ;
2010-02-20 17:19:28 +03:00
uint8_t * inbuf ;
2009-01-26 22:45:19 +03:00
NTSTATUS status ;
2010-02-20 17:19:28 +03:00
status = cli_smb_recv ( subreq , state , & inbuf , 3 , & wct , & vwv ,
2010-02-20 11:53:58 +03:00
& num_bytes , & bytes ) ;
2010-02-20 17:19:28 +03:00
TALLOC_FREE ( subreq ) ;
2009-01-26 22:45:19 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-03-29 22:00:58 +04:00
tevent_req_nterror ( req , status ) ;
return ;
2009-01-26 22:45:19 +03:00
}
2009-03-29 22:00:58 +04:00
state - > fnum = SVAL ( vwv + 2 , 1 ) ;
tevent_req_done ( req ) ;
}
2009-01-26 22:45:19 +03:00
2009-03-29 22:00:58 +04:00
NTSTATUS cli_ntcreate_recv ( struct tevent_req * req , uint16_t * pfnum )
{
struct cli_ntcreate_state * state = tevent_req_data (
req , struct cli_ntcreate_state ) ;
NTSTATUS status ;
2009-01-26 22:45:19 +03:00
2009-03-29 22:00:58 +04:00
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
* pfnum = state - > fnum ;
2009-01-26 22:45:19 +03:00
return NT_STATUS_OK ;
}
NTSTATUS cli_ntcreate ( struct cli_state * cli ,
const char * fname ,
uint32_t CreatFlags ,
uint32_t DesiredAccess ,
uint32_t FileAttributes ,
uint32_t ShareAccess ,
uint32_t CreateDisposition ,
uint32_t CreateOptions ,
uint8_t SecurityFlags ,
uint16_t * pfid )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev ;
2009-03-29 22:00:58 +04:00
struct tevent_req * req ;
NTSTATUS status = NT_STATUS_OK ;
2009-01-26 22:45:19 +03:00
2009-03-29 22:00:58 +04:00
if ( cli_has_async_calls ( cli ) ) {
2009-01-26 22:45:19 +03:00
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_ntcreate_send ( frame , ev , cli , fname , CreatFlags ,
DesiredAccess , FileAttributes , ShareAccess ,
CreateDisposition , CreateOptions ,
SecurityFlags ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
2009-03-29 22:00:58 +04:00
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
2009-01-26 22:45:19 +03:00
}
status = cli_ntcreate_recv ( req , pfid ) ;
fail :
TALLOC_FREE ( frame ) ;
2009-03-29 22:00:58 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
2009-01-26 22:45:19 +03:00
return status ;
}
2000-04-25 18:04:06 +04:00
/****************************************************************************
2001-11-04 03:14:08 +03:00
Open a file
WARNING : if you open with O_WRONLY then getattrE won ' t work !
2000-04-25 18:04:06 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-11-04 03:14:08 +03:00
2009-04-06 01:17:55 +04:00
struct cli_open_state {
uint16_t vwv [ 15 ] ;
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
2009-04-06 01:17:55 +04:00
struct iovec bytes ;
} ;
static void cli_open_done ( struct tevent_req * subreq ) ;
struct tevent_req * cli_open_create ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli , const char * fname ,
int flags , int share_mode ,
struct tevent_req * * psmbreq )
2000-04-25 18:04:06 +04:00
{
2009-04-06 01:17:55 +04:00
struct tevent_req * req , * subreq ;
struct cli_open_state * state ;
unsigned openfn ;
unsigned accessmode ;
uint8_t additional_flags ;
2008-08-02 20:44:39 +04:00
uint8_t * bytes ;
2009-04-06 01:17:55 +04:00
req = tevent_req_create ( mem_ctx , & state , struct cli_open_state ) ;
if ( req = = NULL ) {
return NULL ;
}
openfn = 0 ;
2008-08-02 20:44:39 +04:00
if ( flags & O_CREAT ) {
2000-04-25 18:04:06 +04:00
openfn | = ( 1 < < 4 ) ;
2008-08-02 20:44:39 +04:00
}
2000-04-25 18:04:06 +04:00
if ( ! ( flags & O_EXCL ) ) {
if ( flags & O_TRUNC )
openfn | = ( 1 < < 1 ) ;
else
openfn | = ( 1 < < 0 ) ;
}
accessmode = ( share_mode < < 4 ) ;
if ( ( flags & O_ACCMODE ) = = O_RDWR ) {
accessmode | = 2 ;
} else if ( ( flags & O_ACCMODE ) = = O_WRONLY ) {
accessmode | = 1 ;
2007-12-06 00:31:24 +03:00
}
2000-04-25 18:04:06 +04:00
# if defined(O_SYNC)
if ( ( flags & O_SYNC ) = = O_SYNC ) {
accessmode | = ( 1 < < 14 ) ;
}
# endif /* O_SYNC */
if ( share_mode = = DENY_FCB ) {
accessmode = 0xFF ;
}
2009-04-06 01:17:55 +04:00
SCVAL ( state - > vwv + 0 , 0 , 0xFF ) ;
SCVAL ( state - > vwv + 0 , 1 , 0 ) ;
SSVAL ( state - > vwv + 1 , 0 , 0 ) ;
SSVAL ( state - > vwv + 2 , 0 , 0 ) ; /* no additional info */
SSVAL ( state - > vwv + 3 , 0 , accessmode ) ;
SSVAL ( state - > vwv + 4 , 0 , aSYSTEM | aHIDDEN ) ;
SSVAL ( state - > vwv + 5 , 0 , 0 ) ;
SIVAL ( state - > vwv + 6 , 0 , 0 ) ;
SSVAL ( state - > vwv + 8 , 0 , openfn ) ;
SIVAL ( state - > vwv + 9 , 0 , 0 ) ;
SIVAL ( state - > vwv + 11 , 0 , 0 ) ;
SIVAL ( state - > vwv + 13 , 0 , 0 ) ;
additional_flags = 0 ;
2000-04-25 18:04:06 +04:00
if ( cli - > use_oplocks ) {
/* if using oplocks then ask for a batch oplock via
core and extended methods */
2008-08-02 20:44:39 +04:00
additional_flags =
FLAG_REQUEST_OPLOCK | FLAG_REQUEST_BATCH_OPLOCK ;
2009-04-06 01:17:55 +04:00
SSVAL ( state - > vwv + 2 , 0 , SVAL ( state - > vwv + 2 , 0 ) | 6 ) ;
2000-04-25 18:04:06 +04:00
}
2007-12-06 00:31:24 +03:00
2009-04-06 01:17:55 +04:00
bytes = talloc_array ( state , uint8_t , 0 ) ;
2009-01-26 22:45:09 +03:00
bytes = smb_bytes_push_str ( bytes , cli_ucs2 ( cli ) , fname ,
strlen ( fname ) + 1 , NULL ) ;
2009-04-06 01:17:55 +04:00
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
2009-05-12 22:45:37 +04:00
state - > bytes . iov_base = ( void * ) bytes ;
2009-04-06 01:17:55 +04:00
state - > bytes . iov_len = talloc_get_size ( bytes ) ;
subreq = cli_smb_req_create ( state , ev , cli , SMBopenX , additional_flags ,
15 , state - > vwv , 1 , & state - > bytes ) ;
if ( subreq = = NULL ) {
TALLOC_FREE ( req ) ;
2008-08-02 20:44:39 +04:00
return NULL ;
}
2009-04-06 01:17:55 +04:00
tevent_req_set_callback ( subreq , cli_open_done , req ) ;
* psmbreq = subreq ;
return req ;
}
2000-04-25 18:04:06 +04:00
2009-04-06 01:17:55 +04:00
struct tevent_req * cli_open_send ( TALLOC_CTX * mem_ctx , struct event_context * ev ,
struct cli_state * cli , const char * fname ,
int flags , int share_mode )
{
struct tevent_req * req , * subreq ;
2009-05-14 06:13:12 +04:00
NTSTATUS status ;
2009-04-06 01:17:55 +04:00
req = cli_open_create ( mem_ctx , ev , cli , fname , flags , share_mode ,
& subreq ) ;
2009-05-14 06:13:12 +04:00
if ( req = = NULL ) {
2009-04-06 01:17:55 +04:00
return NULL ;
}
2009-05-14 06:13:12 +04:00
status = cli_smb_req_send ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return tevent_req_post ( req , ev ) ;
}
2009-04-06 01:17:55 +04:00
return req ;
2008-08-02 20:44:39 +04:00
}
2009-04-06 01:17:55 +04:00
static void cli_open_done ( struct tevent_req * subreq )
2008-08-02 20:44:39 +04:00
{
2009-04-06 01:17:55 +04:00
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct cli_open_state * state = tevent_req_data (
req , struct cli_open_state ) ;
2008-08-25 15:33:41 +04:00
uint8_t wct ;
uint16_t * vwv ;
2010-02-20 17:19:45 +03:00
uint8_t * inbuf ;
2008-08-02 20:44:39 +04:00
NTSTATUS status ;
2010-02-20 17:19:45 +03:00
status = cli_smb_recv ( subreq , state , & inbuf , 3 , & wct , & vwv , NULL ,
NULL ) ;
TALLOC_FREE ( subreq ) ;
2008-08-02 20:44:39 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-04-06 01:17:55 +04:00
tevent_req_nterror ( req , status ) ;
return ;
2008-08-25 15:33:41 +04:00
}
2009-04-06 01:17:55 +04:00
state - > fnum = SVAL ( vwv + 2 , 0 ) ;
tevent_req_done ( req ) ;
}
2008-08-25 15:33:41 +04:00
2009-05-01 02:26:43 +04:00
NTSTATUS cli_open_recv ( struct tevent_req * req , uint16_t * pfnum )
2009-04-06 01:17:55 +04:00
{
struct cli_open_state * state = tevent_req_data (
req , struct cli_open_state ) ;
NTSTATUS status ;
2008-08-02 20:44:39 +04:00
2009-04-06 01:17:55 +04:00
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
2009-05-01 02:26:43 +04:00
* pfnum = state - > fnum ;
2008-08-02 20:44:39 +04:00
return NT_STATUS_OK ;
}
2009-05-01 02:26:43 +04:00
NTSTATUS cli_open ( struct cli_state * cli , const char * fname , int flags ,
int share_mode , uint16_t * pfnum )
2008-08-02 20:44:39 +04:00
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
2008-08-24 16:17:43 +04:00
struct event_context * ev ;
2009-04-06 01:17:55 +04:00
struct tevent_req * req ;
NTSTATUS status = NT_STATUS_OK ;
2008-08-02 20:44:39 +04:00
2009-04-06 01:17:55 +04:00
if ( cli_has_async_calls ( cli ) ) {
2008-08-24 16:17:43 +04:00
/*
* Can ' t use sync call while an async call is in flight
*/
2009-04-06 01:17:55 +04:00
status = NT_STATUS_INVALID_PARAMETER ;
2008-08-02 20:44:39 +04:00
goto fail ;
}
2008-08-24 16:17:43 +04:00
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
2009-04-06 01:17:55 +04:00
status = NT_STATUS_NO_MEMORY ;
2008-08-24 16:17:43 +04:00
goto fail ;
}
req = cli_open_send ( frame , ev , cli , fname , flags , share_mode ) ;
2008-08-02 20:44:39 +04:00
if ( req = = NULL ) {
2009-04-06 01:17:55 +04:00
status = NT_STATUS_NO_MEMORY ;
2008-08-02 20:44:39 +04:00
goto fail ;
}
2009-04-06 01:17:55 +04:00
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
2000-04-25 18:04:06 +04:00
}
2009-05-01 02:26:43 +04:00
status = cli_open_recv ( req , pfnum ) ;
2008-08-02 20:44:39 +04:00
fail :
TALLOC_FREE ( frame ) ;
2009-04-06 01:17:55 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
2009-05-01 02:26:43 +04:00
return status ;
2000-04-25 18:04:06 +04:00
}
/****************************************************************************
2001-11-04 03:14:08 +03:00
Close a file .
2000-04-25 18:04:06 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-11-04 03:14:08 +03:00
2009-03-29 15:46:24 +04:00
struct cli_close_state {
2008-08-02 01:18:15 +04:00
uint16_t vwv [ 3 ] ;
2009-03-29 15:46:24 +04:00
} ;
2000-04-25 18:04:06 +04:00
2009-03-29 15:46:24 +04:00
static void cli_close_done ( struct tevent_req * subreq ) ;
2000-04-25 18:04:06 +04:00
2009-03-29 15:46:24 +04:00
struct tevent_req * cli_close_create ( TALLOC_CTX * mem_ctx ,
2009-05-01 02:26:43 +04:00
struct event_context * ev ,
struct cli_state * cli ,
uint16_t fnum ,
struct tevent_req * * psubreq )
2009-03-29 15:46:24 +04:00
{
struct tevent_req * req , * subreq ;
struct cli_close_state * state ;
req = tevent_req_create ( mem_ctx , & state , struct cli_close_state ) ;
if ( req = = NULL ) {
return NULL ;
}
2009-07-15 22:49:33 +04:00
2009-03-29 15:46:24 +04:00
SSVAL ( state - > vwv + 0 , 0 , fnum ) ;
SIVALS ( state - > vwv + 1 , 0 , - 1 ) ;
subreq = cli_smb_req_create ( state , ev , cli , SMBclose , 0 , 3 , state - > vwv ,
0 , NULL ) ;
if ( subreq = = NULL ) {
TALLOC_FREE ( req ) ;
return NULL ;
}
tevent_req_set_callback ( subreq , cli_close_done , req ) ;
* psubreq = subreq ;
return req ;
2008-08-02 01:18:15 +04:00
}
2000-04-25 18:04:06 +04:00
2009-03-29 15:46:24 +04:00
struct tevent_req * cli_close_send ( TALLOC_CTX * mem_ctx ,
2009-05-01 02:26:43 +04:00
struct event_context * ev ,
struct cli_state * cli ,
uint16_t fnum )
2008-08-02 01:18:15 +04:00
{
2009-03-29 15:46:24 +04:00
struct tevent_req * req , * subreq ;
2009-05-14 06:13:12 +04:00
NTSTATUS status ;
2009-03-29 15:46:24 +04:00
req = cli_close_create ( mem_ctx , ev , cli , fnum , & subreq ) ;
2009-05-14 06:13:12 +04:00
if ( req = = NULL ) {
2009-03-29 15:46:24 +04:00
return NULL ;
}
2009-05-14 06:13:12 +04:00
status = cli_smb_req_send ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return tevent_req_post ( req , ev ) ;
}
2009-03-29 15:46:24 +04:00
return req ;
}
static void cli_close_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
2008-12-01 10:23:35 +03:00
NTSTATUS status ;
2000-04-25 18:04:06 +04:00
2010-02-20 11:53:58 +03:00
status = cli_smb_recv ( subreq , NULL , NULL , 0 , NULL , NULL , NULL , NULL ) ;
2009-03-29 15:46:24 +04:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
2000-04-25 18:04:06 +04:00
}
2009-03-29 15:46:24 +04:00
tevent_req_done ( req ) ;
}
2000-04-25 18:04:06 +04:00
2009-03-29 15:46:24 +04:00
NTSTATUS cli_close_recv ( struct tevent_req * req )
{
return tevent_req_simple_recv_ntstatus ( req ) ;
2000-04-25 18:04:06 +04:00
}
2009-05-01 03:57:42 +04:00
NTSTATUS cli_close ( struct cli_state * cli , uint16_t fnum )
2008-08-02 01:18:15 +04:00
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
2008-08-24 16:17:43 +04:00
struct event_context * ev ;
2009-03-29 15:46:24 +04:00
struct tevent_req * req ;
NTSTATUS status = NT_STATUS_OK ;
2008-08-02 01:18:15 +04:00
2009-03-29 15:46:24 +04:00
if ( cli_has_async_calls ( cli ) ) {
2008-08-24 16:17:43 +04:00
/*
* Can ' t use sync call while an async call is in flight
*/
2009-03-29 15:46:24 +04:00
status = NT_STATUS_INVALID_PARAMETER ;
2008-08-24 16:17:43 +04:00
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
2009-03-29 15:46:24 +04:00
status = NT_STATUS_NO_MEMORY ;
2008-08-02 01:18:15 +04:00
goto fail ;
}
2008-08-24 16:17:43 +04:00
req = cli_close_send ( frame , ev , cli , fnum ) ;
2008-08-02 01:18:15 +04:00
if ( req = = NULL ) {
2009-03-29 15:46:24 +04:00
status = NT_STATUS_NO_MEMORY ;
2008-08-02 01:18:15 +04:00
goto fail ;
}
2009-03-29 15:46:24 +04:00
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
2008-08-02 01:18:15 +04:00
}
2009-05-01 03:57:42 +04:00
status = cli_close_recv ( req ) ;
2008-08-02 01:18:15 +04:00
fail :
TALLOC_FREE ( frame ) ;
2009-03-29 15:46:24 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
2009-05-01 03:57:42 +04:00
return status ;
2008-08-02 01:18:15 +04:00
}
2002-03-11 04:33:06 +03:00
2008-02-27 05:42:26 +03:00
/****************************************************************************
Truncate a file to a specified size
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-06-06 03:06:05 +04:00
struct ftrunc_state {
uint16_t setup ;
uint8_t param [ 6 ] ;
uint8_t data [ 8 ] ;
} ;
static void cli_ftruncate_done ( struct tevent_req * subreq )
2008-02-27 05:42:26 +03:00
{
2009-11-16 11:59:58 +03:00
NTSTATUS status = cli_trans_recv ( subreq , NULL , NULL , 0 , NULL ,
NULL , 0 , NULL , NULL , 0 , NULL ) ;
2009-11-17 17:15:35 +03:00
tevent_req_simple_finish_ntstatus ( subreq , status ) ;
2009-06-06 03:06:05 +04:00
}
2008-02-27 05:42:26 +03:00
2009-06-06 03:06:05 +04:00
struct tevent_req * cli_ftruncate_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
uint16_t fnum ,
uint64_t size )
{
struct tevent_req * req = NULL , * subreq = NULL ;
struct ftrunc_state * state = NULL ;
2008-02-27 05:42:26 +03:00
2009-06-06 03:06:05 +04:00
req = tevent_req_create ( mem_ctx , & state , struct ftrunc_state ) ;
if ( req = = NULL ) {
return NULL ;
2008-02-27 05:42:26 +03:00
}
2009-06-06 03:06:05 +04:00
/* Setup setup word. */
SSVAL ( & state - > setup , 0 , TRANSACT2_SETFILEINFO ) ;
/* Setup param array. */
SSVAL ( state - > param , 0 , fnum ) ;
SSVAL ( state - > param , 2 , SMB_SET_FILE_END_OF_FILE_INFO ) ;
SSVAL ( state - > param , 4 , 0 ) ;
/* Setup data array. */
SBVAL ( state - > data , 0 , size ) ;
subreq = cli_trans_send ( state , /* mem ctx. */
ev , /* event ctx. */
cli , /* cli_state. */
SMBtrans2 , /* cmd. */
NULL , /* pipe name. */
- 1 , /* fid. */
0 , /* function. */
0 , /* flags. */
& state - > setup , /* setup. */
1 , /* num setup uint16_t words. */
0 , /* max returned setup. */
state - > param , /* param. */
6 , /* num param. */
2 , /* max returned param. */
state - > data , /* data. */
8 , /* num data. */
0 ) ; /* max returned data. */
2008-02-27 05:42:26 +03:00
2009-06-06 03:06:05 +04:00
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , cli_ftruncate_done , req ) ;
return req ;
}
2008-02-27 05:42:26 +03:00
2009-06-06 03:06:05 +04:00
NTSTATUS cli_ftruncate_recv ( struct tevent_req * req )
{
NTSTATUS status ;
2008-02-27 05:42:26 +03:00
2009-06-06 03:06:05 +04:00
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
return NT_STATUS_OK ;
2008-02-27 05:42:26 +03:00
}
2009-06-06 03:06:05 +04:00
NTSTATUS cli_ftruncate ( struct cli_state * cli , uint16_t fnum , uint64_t size )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_ftruncate_send ( frame ,
ev ,
cli ,
fnum ,
size ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_ftruncate_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
}
2008-02-27 05:42:26 +03:00
2002-03-11 04:33:06 +03:00
/****************************************************************************
2007-12-06 00:31:24 +03:00
send a lock with a specified locktype
2002-03-11 04:33:06 +03:00
this is used for testing LOCKING_ANDX_CANCEL_LOCK
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-04-10 19:33:04 +04:00
2009-05-01 02:26:43 +04:00
NTSTATUS cli_locktype ( struct cli_state * cli , uint16_t fnum ,
2009-04-24 18:06:48 +04:00
uint32_t offset , uint32_t len ,
2007-12-06 00:31:24 +03:00
int timeout , unsigned char locktype )
2002-03-11 04:33:06 +03:00
{
char * p ;
int saved_timeout = cli - > timeout ;
memset ( cli - > outbuf , ' \0 ' , smb_size ) ;
memset ( cli - > inbuf , ' \0 ' , smb_size ) ;
2007-12-27 04:12:36 +03:00
cli_set_message ( cli - > outbuf , 8 , 0 , True ) ;
2002-03-11 04:33:06 +03:00
SCVAL ( cli - > outbuf , smb_com , SMBlockingX ) ;
SSVAL ( cli - > outbuf , smb_tid , cli - > cnum ) ;
cli_setup_packet ( cli ) ;
SCVAL ( cli - > outbuf , smb_vwv0 , 0xFF ) ;
SSVAL ( cli - > outbuf , smb_vwv2 , fnum ) ;
SCVAL ( cli - > outbuf , smb_vwv3 , locktype ) ;
SIVALS ( cli - > outbuf , smb_vwv4 , timeout ) ;
SSVAL ( cli - > outbuf , smb_vwv6 , 0 ) ;
SSVAL ( cli - > outbuf , smb_vwv7 , 1 ) ;
p = smb_buf ( cli - > outbuf ) ;
SSVAL ( p , 0 , cli - > pid ) ;
SIVAL ( p , 2 , offset ) ;
SIVAL ( p , 6 , len ) ;
p + = 10 ;
cli_setup_bcc ( cli , p ) ;
cli_send_smb ( cli ) ;
if ( timeout ! = 0 ) {
cli - > timeout = ( timeout = = - 1 ) ? 0x7FFFFFFF : ( timeout + 2 * 1000 ) ;
}
if ( ! cli_receive_smb ( cli ) ) {
cli - > timeout = saved_timeout ;
return NT_STATUS_UNSUCCESSFUL ;
}
cli - > timeout = saved_timeout ;
return cli_nt_error ( cli ) ;
}
2000-04-25 18:04:06 +04:00
/****************************************************************************
2001-11-04 03:14:08 +03:00
Lock a file .
2003-06-10 18:02:46 +04:00
note that timeout is in units of 2 milliseconds
2000-04-25 18:04:06 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-04-10 19:33:04 +04:00
2009-05-01 02:26:43 +04:00
bool cli_lock ( struct cli_state * cli , uint16_t fnum ,
2009-04-24 18:06:48 +04:00
uint32_t offset , uint32_t len , int timeout , enum brl_type lock_type )
2000-04-25 18:04:06 +04:00
{
char * p ;
2001-11-04 03:14:08 +03:00
int saved_timeout = cli - > timeout ;
2000-04-25 18:04:06 +04:00
memset ( cli - > outbuf , ' \0 ' , smb_size ) ;
memset ( cli - > inbuf , ' \0 ' , smb_size ) ;
2007-12-27 04:12:36 +03:00
cli_set_message ( cli - > outbuf , 8 , 0 , True ) ;
2000-04-25 18:04:06 +04:00
2002-01-11 22:10:25 +03:00
SCVAL ( cli - > outbuf , smb_com , SMBlockingX ) ;
2000-04-25 18:04:06 +04:00
SSVAL ( cli - > outbuf , smb_tid , cli - > cnum ) ;
cli_setup_packet ( cli ) ;
2002-01-11 22:10:25 +03:00
SCVAL ( cli - > outbuf , smb_vwv0 , 0xFF ) ;
2000-04-25 18:04:06 +04:00
SSVAL ( cli - > outbuf , smb_vwv2 , fnum ) ;
2002-01-11 22:10:25 +03:00
SCVAL ( cli - > outbuf , smb_vwv3 , ( lock_type = = READ_LOCK ? 1 : 0 ) ) ;
2000-04-25 18:04:06 +04:00
SIVALS ( cli - > outbuf , smb_vwv4 , timeout ) ;
SSVAL ( cli - > outbuf , smb_vwv6 , 0 ) ;
SSVAL ( cli - > outbuf , smb_vwv7 , 1 ) ;
p = smb_buf ( cli - > outbuf ) ;
SSVAL ( p , 0 , cli - > pid ) ;
SIVAL ( p , 2 , offset ) ;
SIVAL ( p , 6 , len ) ;
2001-02-20 16:16:01 +03:00
p + = 10 ;
cli_setup_bcc ( cli , p ) ;
2000-04-25 18:04:06 +04:00
cli_send_smb ( cli ) ;
2002-03-11 02:16:15 +03:00
if ( timeout ! = 0 ) {
2003-06-10 18:02:46 +04:00
cli - > timeout = ( timeout = = - 1 ) ? 0x7FFFFFFF : ( timeout * 2 + 5 * 1000 ) ;
2002-03-11 02:16:15 +03:00
}
2000-04-25 18:04:06 +04:00
if ( ! cli_receive_smb ( cli ) ) {
2001-11-04 03:14:08 +03:00
cli - > timeout = saved_timeout ;
2000-04-25 18:04:06 +04:00
return False ;
}
cli - > timeout = saved_timeout ;
2001-09-05 15:32:59 +04:00
if ( cli_is_error ( cli ) ) {
2000-04-25 18:04:06 +04:00
return False ;
}
return True ;
}
/****************************************************************************
2001-11-04 03:14:08 +03:00
Unlock a file .
2000-04-25 18:04:06 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-11-04 03:14:08 +03:00
2009-07-15 22:49:33 +04:00
struct cli_unlock_state {
uint16_t vwv [ 8 ] ;
uint8_t data [ 10 ] ;
} ;
static void cli_unlock_done ( struct tevent_req * subreq ) ;
struct tevent_req * cli_unlock_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
uint16_t fnum ,
uint64_t offset ,
uint64_t len )
2000-04-25 18:04:06 +04:00
{
2009-07-15 22:49:33 +04:00
struct tevent_req * req = NULL , * subreq = NULL ;
struct cli_unlock_state * state = NULL ;
uint8_t additional_flags = 0 ;
2000-04-25 18:04:06 +04:00
2009-07-15 22:49:33 +04:00
req = tevent_req_create ( mem_ctx , & state , struct cli_unlock_state ) ;
if ( req = = NULL ) {
return NULL ;
}
2000-04-25 18:04:06 +04:00
2009-07-15 22:49:33 +04:00
SCVAL ( state - > vwv + 0 , 0 , 0xFF ) ;
SSVAL ( state - > vwv + 2 , 0 , fnum ) ;
SCVAL ( state - > vwv + 3 , 0 , 0 ) ;
SIVALS ( state - > vwv + 4 , 0 , 0 ) ;
SSVAL ( state - > vwv + 6 , 0 , 1 ) ;
SSVAL ( state - > vwv + 7 , 0 , 0 ) ;
2000-04-25 18:04:06 +04:00
2009-07-15 22:49:33 +04:00
SSVAL ( state - > data , 0 , cli - > pid ) ;
SIVAL ( state - > data , 2 , offset ) ;
SIVAL ( state - > data , 6 , len ) ;
2000-04-25 18:04:06 +04:00
2009-07-15 22:49:33 +04:00
subreq = cli_smb_send ( state , ev , cli , SMBlockingX , additional_flags ,
8 , state - > vwv , 10 , state - > data ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , cli_unlock_done , req ) ;
return req ;
}
2000-04-25 18:04:06 +04:00
2009-07-15 22:49:33 +04:00
static void cli_unlock_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
NTSTATUS status ;
2010-02-20 11:53:58 +03:00
status = cli_smb_recv ( subreq , NULL , NULL , 0 , NULL , NULL , NULL , NULL ) ;
2009-07-15 22:49:33 +04:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
2000-04-25 18:04:06 +04:00
}
2009-07-15 22:49:33 +04:00
tevent_req_done ( req ) ;
}
2000-04-25 18:04:06 +04:00
2009-07-15 22:49:33 +04:00
NTSTATUS cli_unlock_recv ( struct tevent_req * req )
{
return tevent_req_simple_recv_ntstatus ( req ) ;
}
NTSTATUS cli_unlock ( struct cli_state * cli ,
uint16_t fnum ,
uint32_t offset ,
uint32_t len )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev ;
struct tevent_req * req ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
2000-04-25 18:04:06 +04:00
}
2009-07-15 22:49:33 +04:00
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_unlock_send ( frame , ev , cli ,
fnum , offset , len ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_unlock_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2000-04-25 18:04:06 +04:00
}
2000-09-29 08:41:52 +04:00
/****************************************************************************
2001-11-04 03:14:08 +03:00
Lock a file with 64 bit offsets .
2000-09-29 08:41:52 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-11-04 03:14:08 +03:00
2009-05-01 02:26:43 +04:00
bool cli_lock64 ( struct cli_state * cli , uint16_t fnum ,
2008-10-14 03:59:36 +04:00
uint64_t offset , uint64_t len , int timeout , enum brl_type lock_type )
2000-09-29 08:41:52 +04:00
{
char * p ;
int saved_timeout = cli - > timeout ;
int ltype ;
2001-08-24 03:15:18 +04:00
if ( ! ( cli - > capabilities & CAP_LARGE_FILES ) ) {
return cli_lock ( cli , fnum , offset , len , timeout , lock_type ) ;
}
2000-09-29 08:41:52 +04:00
ltype = ( lock_type = = READ_LOCK ? 1 : 0 ) ;
ltype | = LOCKING_ANDX_LARGE_FILES ;
memset ( cli - > outbuf , ' \0 ' , smb_size ) ;
memset ( cli - > inbuf , ' \0 ' , smb_size ) ;
2007-12-27 04:12:36 +03:00
cli_set_message ( cli - > outbuf , 8 , 0 , True ) ;
2000-09-29 08:41:52 +04:00
2002-01-11 22:10:25 +03:00
SCVAL ( cli - > outbuf , smb_com , SMBlockingX ) ;
2000-09-29 08:41:52 +04:00
SSVAL ( cli - > outbuf , smb_tid , cli - > cnum ) ;
cli_setup_packet ( cli ) ;
2002-01-11 22:10:25 +03:00
SCVAL ( cli - > outbuf , smb_vwv0 , 0xFF ) ;
2000-09-29 08:41:52 +04:00
SSVAL ( cli - > outbuf , smb_vwv2 , fnum ) ;
2002-01-11 22:10:25 +03:00
SCVAL ( cli - > outbuf , smb_vwv3 , ltype ) ;
2000-09-29 08:41:52 +04:00
SIVALS ( cli - > outbuf , smb_vwv4 , timeout ) ;
SSVAL ( cli - > outbuf , smb_vwv6 , 0 ) ;
SSVAL ( cli - > outbuf , smb_vwv7 , 1 ) ;
p = smb_buf ( cli - > outbuf ) ;
SIVAL ( p , 0 , cli - > pid ) ;
2001-04-22 06:54:04 +04:00
SOFF_T_R ( p , 4 , offset ) ;
SOFF_T_R ( p , 12 , len ) ;
2001-02-20 16:16:01 +03:00
p + = 20 ;
cli_setup_bcc ( cli , p ) ;
2000-09-29 08:41:52 +04:00
cli_send_smb ( cli ) ;
2002-03-11 02:16:15 +03:00
if ( timeout ! = 0 ) {
cli - > timeout = ( timeout = = - 1 ) ? 0x7FFFFFFF : ( timeout + 5 * 1000 ) ;
}
2000-09-29 08:41:52 +04:00
if ( ! cli_receive_smb ( cli ) ) {
cli - > timeout = saved_timeout ;
return False ;
}
cli - > timeout = saved_timeout ;
2001-09-05 15:32:59 +04:00
if ( cli_is_error ( cli ) ) {
2000-09-29 08:41:52 +04:00
return False ;
}
return True ;
}
/****************************************************************************
2001-11-04 03:14:08 +03:00
Unlock a file with 64 bit offsets .
2000-09-29 08:41:52 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-11-04 03:14:08 +03:00
2009-07-15 22:49:33 +04:00
struct cli_unlock64_state {
uint16_t vwv [ 8 ] ;
uint8_t data [ 20 ] ;
} ;
static void cli_unlock64_done ( struct tevent_req * subreq ) ;
struct tevent_req * cli_unlock64_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
uint16_t fnum ,
uint64_t offset ,
uint64_t len )
2000-09-29 08:41:52 +04:00
{
2009-07-15 22:49:33 +04:00
struct tevent_req * req = NULL , * subreq = NULL ;
struct cli_unlock64_state * state = NULL ;
uint8_t additional_flags = 0 ;
2000-09-29 08:41:52 +04:00
2009-07-15 22:49:33 +04:00
req = tevent_req_create ( mem_ctx , & state , struct cli_unlock64_state ) ;
if ( req = = NULL ) {
return NULL ;
2001-08-24 03:15:18 +04:00
}
2009-07-15 22:49:33 +04:00
SCVAL ( state - > vwv + 0 , 0 , 0xff ) ;
SSVAL ( state - > vwv + 2 , 0 , fnum ) ;
SCVAL ( state - > vwv + 3 , 0 , LOCKING_ANDX_LARGE_FILES ) ;
SIVALS ( state - > vwv + 4 , 0 , 0 ) ;
SSVAL ( state - > vwv + 6 , 0 , 1 ) ;
SSVAL ( state - > vwv + 7 , 0 , 0 ) ;
2000-09-29 08:41:52 +04:00
2009-07-15 22:49:33 +04:00
SIVAL ( state - > data , 0 , cli - > pid ) ;
SOFF_T_R ( state - > data , 4 , offset ) ;
SOFF_T_R ( state - > data , 12 , len ) ;
2000-09-29 08:41:52 +04:00
2009-07-15 22:49:33 +04:00
subreq = cli_smb_send ( state , ev , cli , SMBlockingX , additional_flags ,
8 , state - > vwv , 20 , state - > data ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , cli_unlock64_done , req ) ;
return req ;
}
2000-09-29 08:41:52 +04:00
2009-07-15 22:49:33 +04:00
static void cli_unlock64_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
NTSTATUS status ;
2000-09-29 08:41:52 +04:00
2010-02-20 11:53:58 +03:00
status = cli_smb_recv ( subreq , NULL , NULL , 0 , NULL , NULL , NULL , NULL ) ;
2009-07-15 22:49:33 +04:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
2000-09-29 08:41:52 +04:00
}
2009-07-15 22:49:33 +04:00
tevent_req_done ( req ) ;
}
2000-09-29 08:41:52 +04:00
2009-07-15 22:49:33 +04:00
NTSTATUS cli_unlock64_recv ( struct tevent_req * req )
{
return tevent_req_simple_recv_ntstatus ( req ) ;
}
NTSTATUS cli_unlock64 ( struct cli_state * cli ,
uint16_t fnum ,
uint64_t offset ,
uint64_t len )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev ;
struct tevent_req * req ;
NTSTATUS status = NT_STATUS_OK ;
if ( ! ( cli - > capabilities & CAP_LARGE_FILES ) ) {
return cli_unlock ( cli , fnum , offset , len ) ;
2000-09-29 08:41:52 +04:00
}
2009-07-15 22:49:33 +04:00
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_unlock64_send ( frame , ev , cli ,
fnum , offset , len ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_unlock64_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2000-09-29 08:41:52 +04:00
}
2006-04-10 19:33:04 +04:00
/****************************************************************************
Get / unlock a POSIX lock on a file - internal function .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-07-14 05:43:10 +04:00
struct posix_lock_state {
uint16_t setup ;
uint8_t param [ 4 ] ;
uint8_t data [ POSIX_LOCK_DATA_SIZE ] ;
} ;
static void cli_posix_unlock_internal_done ( struct tevent_req * subreq )
{
2009-11-16 11:59:58 +03:00
NTSTATUS status = cli_trans_recv ( subreq , NULL , NULL , 0 , NULL ,
NULL , 0 , NULL , NULL , 0 , NULL ) ;
2009-11-17 17:15:35 +03:00
tevent_req_simple_finish_ntstatus ( subreq , status ) ;
2009-07-14 05:43:10 +04:00
}
static struct tevent_req * cli_posix_lock_internal_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
uint16_t fnum ,
uint64_t offset ,
uint64_t len ,
bool wait_lock ,
enum brl_type lock_type )
{
struct tevent_req * req = NULL , * subreq = NULL ;
struct posix_lock_state * state = NULL ;
req = tevent_req_create ( mem_ctx , & state , struct posix_lock_state ) ;
if ( req = = NULL ) {
return NULL ;
}
2006-04-10 19:33:04 +04:00
2009-07-14 05:43:10 +04:00
/* Setup setup word. */
SSVAL ( & state - > setup , 0 , TRANSACT2_SETFILEINFO ) ;
2006-04-10 19:33:04 +04:00
2009-07-14 05:43:10 +04:00
/* Setup param array. */
SSVAL ( & state - > param , 0 , fnum ) ;
SSVAL ( & state - > param , 2 , SMB_SET_POSIX_LOCK ) ;
/* Setup data array. */
2006-04-10 19:33:04 +04:00
switch ( lock_type ) {
case READ_LOCK :
2009-07-14 05:43:10 +04:00
SSVAL ( & state - > data , POSIX_LOCK_TYPE_OFFSET ,
POSIX_LOCK_TYPE_READ ) ;
2006-04-10 19:33:04 +04:00
break ;
case WRITE_LOCK :
2009-07-14 05:43:10 +04:00
SSVAL ( & state - > data , POSIX_LOCK_TYPE_OFFSET ,
POSIX_LOCK_TYPE_WRITE ) ;
2006-04-10 19:33:04 +04:00
break ;
case UNLOCK_LOCK :
2009-07-14 05:43:10 +04:00
SSVAL ( & state - > data , POSIX_LOCK_TYPE_OFFSET ,
POSIX_LOCK_TYPE_UNLOCK ) ;
2006-04-10 19:33:04 +04:00
break ;
default :
2009-07-14 05:43:10 +04:00
return NULL ;
2006-04-10 19:33:04 +04:00
}
if ( wait_lock ) {
2009-07-14 05:43:10 +04:00
SSVAL ( & state - > data , POSIX_LOCK_FLAGS_OFFSET ,
POSIX_LOCK_FLAG_WAIT ) ;
2006-04-10 19:33:04 +04:00
} else {
2009-07-14 05:43:10 +04:00
SSVAL ( state - > data , POSIX_LOCK_FLAGS_OFFSET ,
POSIX_LOCK_FLAG_NOWAIT ) ;
}
SIVAL ( & state - > data , POSIX_LOCK_PID_OFFSET , cli - > pid ) ;
SOFF_T ( & state - > data , POSIX_LOCK_START_OFFSET , offset ) ;
SOFF_T ( & state - > data , POSIX_LOCK_LEN_OFFSET , len ) ;
subreq = cli_trans_send ( state , /* mem ctx. */
ev , /* event ctx. */
cli , /* cli_state. */
SMBtrans2 , /* cmd. */
NULL , /* pipe name. */
- 1 , /* fid. */
0 , /* function. */
0 , /* flags. */
& state - > setup , /* setup. */
1 , /* num setup uint16_t words. */
0 , /* max returned setup. */
state - > param , /* param. */
4 , /* num param. */
2 , /* max returned param. */
state - > data , /* data. */
POSIX_LOCK_DATA_SIZE , /* num data. */
0 ) ; /* max returned data. */
2006-04-10 19:33:04 +04:00
2009-07-14 05:43:10 +04:00
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
2006-04-10 19:33:04 +04:00
}
2009-07-14 05:43:10 +04:00
tevent_req_set_callback ( subreq , cli_posix_unlock_internal_done , req ) ;
return req ;
2006-04-10 19:33:04 +04:00
}
/****************************************************************************
POSIX Lock a file .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-07-14 05:43:10 +04:00
struct tevent_req * cli_posix_lock_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
uint16_t fnum ,
uint64_t offset ,
uint64_t len ,
bool wait_lock ,
enum brl_type lock_type )
{
return cli_posix_lock_internal_send ( mem_ctx , ev , cli , fnum , offset , len ,
wait_lock , lock_type ) ;
}
NTSTATUS cli_posix_lock_recv ( struct tevent_req * req )
{
NTSTATUS status ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
return NT_STATUS_OK ;
}
NTSTATUS cli_posix_lock ( struct cli_state * cli , uint16_t fnum ,
2008-10-14 03:59:36 +04:00
uint64_t offset , uint64_t len ,
2007-10-19 04:40:25 +04:00
bool wait_lock , enum brl_type lock_type )
2006-04-10 19:33:04 +04:00
{
2009-07-14 05:43:10 +04:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
2006-04-11 03:32:05 +04:00
if ( lock_type ! = READ_LOCK & & lock_type ! = WRITE_LOCK ) {
2009-07-14 05:43:10 +04:00
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
2006-04-10 19:33:04 +04:00
}
2009-07-14 05:43:10 +04:00
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_posix_lock_send ( frame ,
ev ,
cli ,
fnum ,
offset ,
len ,
wait_lock ,
lock_type ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_posix_lock_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2006-04-10 19:33:04 +04:00
}
/****************************************************************************
POSIX Unlock a file .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-07-14 05:43:10 +04:00
struct tevent_req * cli_posix_unlock_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
uint16_t fnum ,
uint64_t offset ,
uint64_t len )
2006-04-10 19:33:04 +04:00
{
2009-07-14 05:43:10 +04:00
return cli_posix_lock_internal_send ( mem_ctx , ev , cli , fnum , offset , len ,
false , UNLOCK_LOCK ) ;
2006-04-10 19:33:04 +04:00
}
2009-07-14 05:43:10 +04:00
NTSTATUS cli_posix_unlock_recv ( struct tevent_req * req )
{
NTSTATUS status ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
return NT_STATUS_OK ;
}
2006-04-10 19:33:04 +04:00
2009-07-14 05:43:10 +04:00
NTSTATUS cli_posix_unlock ( struct cli_state * cli , uint16_t fnum , uint64_t offset , uint64_t len )
2006-04-10 19:33:04 +04:00
{
2009-07-14 05:43:10 +04:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_posix_unlock_send ( frame ,
ev ,
cli ,
fnum ,
offset ,
len ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_posix_unlock_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2006-04-10 19:33:04 +04:00
}
2002-03-11 04:33:06 +03:00
2000-04-25 18:04:06 +04:00
/****************************************************************************
2001-11-04 03:14:08 +03:00
Do a SMBgetattrE call .
2000-04-25 18:04:06 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-11-04 03:14:08 +03:00
2009-05-06 03:28:44 +04:00
static void cli_getattrE_done ( struct tevent_req * subreq ) ;
struct cli_getattrE_state {
2009-05-07 21:01:28 +04:00
uint16_t vwv [ 1 ] ;
2009-05-06 03:28:44 +04:00
int zone_offset ;
uint16_t attr ;
SMB_OFF_T size ;
time_t change_time ;
time_t access_time ;
time_t write_time ;
} ;
2000-04-25 18:04:06 +04:00
2009-05-06 03:28:44 +04:00
struct tevent_req * cli_getattrE_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
uint16_t fnum )
{
struct tevent_req * req = NULL , * subreq = NULL ;
struct cli_getattrE_state * state = NULL ;
uint8_t additional_flags = 0 ;
2000-04-25 18:04:06 +04:00
2009-05-06 03:28:44 +04:00
req = tevent_req_create ( mem_ctx , & state , struct cli_getattrE_state ) ;
if ( req = = NULL ) {
return NULL ;
}
2000-04-25 18:04:06 +04:00
2009-05-06 03:28:44 +04:00
state - > zone_offset = cli - > serverzone ;
2009-05-07 21:01:28 +04:00
SSVAL ( state - > vwv + 0 , 0 , fnum ) ;
2000-04-25 18:04:06 +04:00
2009-05-06 03:28:44 +04:00
subreq = cli_smb_send ( state , ev , cli , SMBgetattrE , additional_flags ,
2009-05-07 21:01:28 +04:00
1 , state - > vwv , 0 , NULL ) ;
2009-05-06 03:28:44 +04:00
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
2000-04-25 18:04:06 +04:00
}
2009-05-06 03:28:44 +04:00
tevent_req_set_callback ( subreq , cli_getattrE_done , req ) ;
return req ;
}
2007-12-06 00:31:24 +03:00
2009-05-06 03:28:44 +04:00
static void cli_getattrE_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct cli_getattrE_state * state = tevent_req_data (
req , struct cli_getattrE_state ) ;
uint8_t wct ;
uint16_t * vwv = NULL ;
2010-02-20 17:20:38 +03:00
uint8_t * inbuf ;
2009-05-06 03:28:44 +04:00
NTSTATUS status ;
2010-02-20 17:20:38 +03:00
status = cli_smb_recv ( subreq , state , & inbuf , 11 , & wct , & vwv ,
NULL , NULL ) ;
TALLOC_FREE ( subreq ) ;
2009-05-06 03:28:44 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
2000-04-25 18:04:06 +04:00
}
2009-05-06 03:28:44 +04:00
state - > size = ( SMB_OFF_T ) IVAL ( vwv + 6 , 0 ) ;
state - > attr = SVAL ( vwv + 10 , 0 ) ;
state - > change_time = make_unix_date2 ( vwv + 0 , state - > zone_offset ) ;
state - > access_time = make_unix_date2 ( vwv + 2 , state - > zone_offset ) ;
state - > write_time = make_unix_date2 ( vwv + 4 , state - > zone_offset ) ;
tevent_req_done ( req ) ;
}
NTSTATUS cli_getattrE_recv ( struct tevent_req * req ,
uint16_t * attr ,
SMB_OFF_T * size ,
time_t * change_time ,
time_t * access_time ,
time_t * write_time )
{
struct cli_getattrE_state * state = tevent_req_data (
req , struct cli_getattrE_state ) ;
NTSTATUS status ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
if ( attr ) {
* attr = state - > attr ;
}
2000-04-25 18:04:06 +04:00
if ( size ) {
2009-05-06 03:28:44 +04:00
* size = state - > size ;
2000-04-25 18:04:06 +04:00
}
2009-05-06 03:28:44 +04:00
if ( change_time ) {
* change_time = state - > change_time ;
}
if ( access_time ) {
* access_time = state - > access_time ;
}
if ( write_time ) {
* write_time = state - > write_time ;
}
return NT_STATUS_OK ;
}
2000-04-25 18:04:06 +04:00
2009-05-06 03:28:44 +04:00
NTSTATUS cli_getattrE ( struct cli_state * cli ,
uint16_t fnum ,
uint16_t * attr ,
SMB_OFF_T * size ,
time_t * change_time ,
time_t * access_time ,
time_t * write_time )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
2000-04-25 18:04:06 +04:00
}
2009-05-06 03:28:44 +04:00
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
2000-04-25 18:04:06 +04:00
}
2009-05-06 03:28:44 +04:00
req = cli_getattrE_send ( frame , ev , cli , fnum ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
2000-04-25 18:04:06 +04:00
}
2009-05-06 03:28:44 +04:00
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
2000-04-25 18:04:06 +04:00
}
2009-05-06 03:28:44 +04:00
status = cli_getattrE_recv ( req ,
attr ,
size ,
change_time ,
access_time ,
write_time ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2000-04-25 18:04:06 +04:00
}
/****************************************************************************
2001-11-04 03:14:08 +03:00
Do a SMBgetatr call
2000-04-25 18:04:06 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-11-04 03:14:08 +03:00
2009-05-06 07:59:22 +04:00
static void cli_getatr_done ( struct tevent_req * subreq ) ;
2000-04-25 18:04:06 +04:00
2009-05-06 07:59:22 +04:00
struct cli_getatr_state {
int zone_offset ;
uint16_t attr ;
SMB_OFF_T size ;
time_t write_time ;
} ;
2000-04-25 18:04:06 +04:00
2009-05-06 07:59:22 +04:00
struct tevent_req * cli_getatr_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname )
{
struct tevent_req * req = NULL , * subreq = NULL ;
struct cli_getatr_state * state = NULL ;
uint8_t additional_flags = 0 ;
uint8_t * bytes = NULL ;
2000-04-25 18:04:06 +04:00
2009-05-06 07:59:22 +04:00
req = tevent_req_create ( mem_ctx , & state , struct cli_getatr_state ) ;
if ( req = = NULL ) {
return NULL ;
}
2000-04-25 18:04:06 +04:00
2009-05-06 07:59:22 +04:00
state - > zone_offset = cli - > serverzone ;
2001-02-20 15:49:55 +03:00
2009-05-06 07:59:22 +04:00
bytes = talloc_array ( state , uint8_t , 1 ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
bytes [ 0 ] = 4 ;
bytes = smb_bytes_push_str ( bytes , cli_ucs2 ( cli ) , fname ,
strlen ( fname ) + 1 , NULL ) ;
2000-04-25 18:04:06 +04:00
2009-05-06 07:59:22 +04:00
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
2000-04-25 18:04:06 +04:00
}
2007-12-06 00:31:24 +03:00
2009-05-06 07:59:22 +04:00
subreq = cli_smb_send ( state , ev , cli , SMBgetatr , additional_flags ,
0 , NULL , talloc_get_size ( bytes ) , bytes ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
2000-04-25 18:04:06 +04:00
}
2009-05-06 07:59:22 +04:00
tevent_req_set_callback ( subreq , cli_getatr_done , req ) ;
return req ;
}
2000-04-25 18:04:06 +04:00
2009-05-06 07:59:22 +04:00
static void cli_getatr_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct cli_getatr_state * state = tevent_req_data (
req , struct cli_getatr_state ) ;
uint8_t wct ;
uint16_t * vwv = NULL ;
2010-02-20 17:21:01 +03:00
uint8_t * inbuf ;
2009-05-06 07:59:22 +04:00
NTSTATUS status ;
2010-02-20 17:21:01 +03:00
status = cli_smb_recv ( subreq , state , & inbuf , 4 , & wct , & vwv , NULL ,
NULL ) ;
TALLOC_FREE ( subreq ) ;
2009-05-06 07:59:22 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
2000-04-25 18:04:06 +04:00
}
2009-05-06 07:59:22 +04:00
state - > attr = SVAL ( vwv + 0 , 0 ) ;
state - > size = ( SMB_OFF_T ) IVAL ( vwv + 3 , 0 ) ;
state - > write_time = make_unix_date3 ( vwv + 1 , state - > zone_offset ) ;
tevent_req_done ( req ) ;
}
NTSTATUS cli_getatr_recv ( struct tevent_req * req ,
uint16_t * attr ,
SMB_OFF_T * size ,
time_t * write_time )
{
struct cli_getatr_state * state = tevent_req_data (
req , struct cli_getatr_state ) ;
NTSTATUS status ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
if ( attr ) {
* attr = state - > attr ;
}
if ( size ) {
* size = state - > size ;
}
r18009: Fixes bug 4026.
This completes the work Jeremy began last week, disambiguating the meaning of
c_time. (In POSIX terminology, c_time means "status Change time", not "create
time".) All uses of c_time, a_time and m_time have now been replaced with
change_time, access_time, and write_time, and when creation time is intended,
create_time is used.
Additionally, the capability of setting and retrieving the create time have
been added to the smbc_setxattr() and smbc_getxattr() functions. An example
of setting all four times can be seen with the program
examples/libsmbclient/testacl
with the following command line similar to:
testacl -f -S "system.*:CREATE_TIME:1000000000,ACCESS_TIME:1000000060,WRITE_TIME:1000000120,CHANGE_TIME:1000000180" 'smb://server/share/testfile.txt'
The -f option turns on the new mode which uses full time names in the
attribute specification (e.g. ACCESS_TIME vs A_TIME).
(This used to be commit 8e119b64f1d92026dda855d904be09912a40601c)
2006-09-03 01:47:56 +04:00
if ( write_time ) {
2009-05-06 07:59:22 +04:00
* write_time = state - > write_time ;
2000-04-25 18:04:06 +04:00
}
2009-05-06 07:59:22 +04:00
return NT_STATUS_OK ;
}
2000-04-25 18:04:06 +04:00
2009-05-06 07:59:22 +04:00
NTSTATUS cli_getatr ( struct cli_state * cli ,
const char * fname ,
uint16_t * attr ,
SMB_OFF_T * size ,
time_t * write_time )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
2000-04-25 18:04:06 +04:00
}
2009-05-06 07:59:22 +04:00
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_getatr_send ( frame , ev , cli , fname ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_getatr_recv ( req ,
attr ,
size ,
write_time ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2000-04-25 18:04:06 +04:00
}
2004-08-21 00:07:17 +04:00
/****************************************************************************
Do a SMBsetattrE call .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-05-07 02:07:05 +04:00
static void cli_setattrE_done ( struct tevent_req * subreq ) ;
2004-08-21 00:07:17 +04:00
2009-05-07 02:07:05 +04:00
struct cli_setattrE_state {
2009-07-15 22:49:33 +04:00
uint16_t vwv [ 7 ] ;
2009-05-07 02:07:05 +04:00
} ;
struct tevent_req * cli_setattrE_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
uint16_t fnum ,
time_t change_time ,
time_t access_time ,
time_t write_time )
2004-08-21 00:07:17 +04:00
{
2009-05-07 02:07:05 +04:00
struct tevent_req * req = NULL , * subreq = NULL ;
struct cli_setattrE_state * state = NULL ;
uint8_t additional_flags = 0 ;
2004-08-21 00:07:17 +04:00
2009-05-07 02:07:05 +04:00
req = tevent_req_create ( mem_ctx , & state , struct cli_setattrE_state ) ;
if ( req = = NULL ) {
return NULL ;
}
2004-08-21 00:07:17 +04:00
2009-07-15 22:49:33 +04:00
SSVAL ( state - > vwv + 0 , 0 , fnum ) ;
cli_put_dos_date2 ( cli , ( char * ) & state - > vwv [ 1 ] , 0 , change_time ) ;
cli_put_dos_date2 ( cli , ( char * ) & state - > vwv [ 3 ] , 0 , access_time ) ;
cli_put_dos_date2 ( cli , ( char * ) & state - > vwv [ 5 ] , 0 , write_time ) ;
2004-08-21 00:07:17 +04:00
2009-05-07 02:07:05 +04:00
subreq = cli_smb_send ( state , ev , cli , SMBsetattrE , additional_flags ,
2009-07-15 22:49:33 +04:00
7 , state - > vwv , 0 , NULL ) ;
2009-05-07 02:07:05 +04:00
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , cli_setattrE_done , req ) ;
return req ;
}
2004-08-21 00:07:17 +04:00
2009-05-07 02:07:05 +04:00
static void cli_setattrE_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
NTSTATUS status ;
2004-08-21 00:07:17 +04:00
2010-02-20 11:53:58 +03:00
status = cli_smb_recv ( subreq , NULL , NULL , 0 , NULL , NULL , NULL , NULL ) ;
2009-05-07 02:07:05 +04:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
}
tevent_req_done ( req ) ;
}
2004-08-21 00:07:17 +04:00
2009-05-07 02:07:05 +04:00
NTSTATUS cli_setattrE_recv ( struct tevent_req * req )
{
return tevent_req_simple_recv_ntstatus ( req ) ;
}
2004-08-21 00:07:17 +04:00
2009-05-07 02:07:05 +04:00
NTSTATUS cli_setattrE ( struct cli_state * cli ,
uint16_t fnum ,
time_t change_time ,
time_t access_time ,
time_t write_time )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
2004-08-21 00:07:17 +04:00
}
2007-12-06 00:31:24 +03:00
2009-05-07 02:07:05 +04:00
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
2004-08-21 00:07:17 +04:00
}
2009-05-07 02:07:05 +04:00
req = cli_setattrE_send ( frame , ev ,
cli ,
fnum ,
change_time ,
access_time ,
write_time ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_setattrE_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2004-08-21 00:07:17 +04:00
}
2000-04-25 18:04:06 +04:00
/****************************************************************************
2001-11-04 03:14:08 +03:00
Do a SMBsetatr call .
2000-04-25 18:04:06 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-11-04 03:14:08 +03:00
2009-05-07 03:13:42 +04:00
static void cli_setatr_done ( struct tevent_req * subreq ) ;
struct cli_setatr_state {
2009-05-07 21:01:28 +04:00
uint16_t vwv [ 8 ] ;
2009-05-07 03:13:42 +04:00
} ;
struct tevent_req * cli_setatr_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname ,
uint16_t attr ,
time_t mtime )
{
struct tevent_req * req = NULL , * subreq = NULL ;
struct cli_setatr_state * state = NULL ;
uint8_t additional_flags = 0 ;
uint8_t * bytes = NULL ;
req = tevent_req_create ( mem_ctx , & state , struct cli_setatr_state ) ;
if ( req = = NULL ) {
return NULL ;
}
2009-05-07 21:01:28 +04:00
SSVAL ( state - > vwv + 0 , 0 , attr ) ;
cli_put_dos_date3 ( cli , ( char * ) & state - > vwv [ 1 ] , 0 , mtime ) ;
2009-05-07 03:13:42 +04:00
bytes = talloc_array ( state , uint8_t , 1 ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
bytes [ 0 ] = 4 ;
bytes = smb_bytes_push_str ( bytes , cli_ucs2 ( cli ) , fname ,
strlen ( fname ) + 1 , NULL ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
bytes = TALLOC_REALLOC_ARRAY ( state , bytes , uint8_t ,
talloc_get_size ( bytes ) + 1 ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
bytes [ talloc_get_size ( bytes ) - 1 ] = 4 ;
bytes = smb_bytes_push_str ( bytes , cli_ucs2 ( cli ) , " " ,
1 , NULL ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
subreq = cli_smb_send ( state , ev , cli , SMBsetatr , additional_flags ,
2009-05-07 21:01:28 +04:00
8 , state - > vwv , talloc_get_size ( bytes ) , bytes ) ;
2009-05-07 03:13:42 +04:00
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , cli_setatr_done , req ) ;
return req ;
}
static void cli_setatr_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
NTSTATUS status ;
2010-02-20 11:53:58 +03:00
status = cli_smb_recv ( subreq , NULL , NULL , 0 , NULL , NULL , NULL , NULL ) ;
2009-05-07 03:13:42 +04:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
}
tevent_req_done ( req ) ;
}
NTSTATUS cli_setatr_recv ( struct tevent_req * req )
{
return tevent_req_simple_recv_ntstatus ( req ) ;
}
NTSTATUS cli_setatr ( struct cli_state * cli ,
const char * fname ,
uint16_t attr ,
time_t mtime )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_setatr_send ( frame , ev , cli , fname , attr , mtime ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_setatr_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
}
2000-04-25 18:04:06 +04:00
/****************************************************************************
2001-11-04 03:14:08 +03:00
Check for existance of a dir .
2000-04-25 18:04:06 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-11-30 04:47:31 +03:00
2009-04-22 17:46:42 +04:00
static void cli_chkpath_done ( struct tevent_req * subreq ) ;
struct cli_chkpath_state {
int dummy ;
} ;
struct tevent_req * cli_chkpath_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname )
{
struct tevent_req * req = NULL , * subreq = NULL ;
struct cli_chkpath_state * state = NULL ;
uint8_t additional_flags = 0 ;
uint8_t * bytes = NULL ;
req = tevent_req_create ( mem_ctx , & state , struct cli_chkpath_state ) ;
if ( req = = NULL ) {
return NULL ;
}
bytes = talloc_array ( state , uint8_t , 1 ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
bytes [ 0 ] = 4 ;
bytes = smb_bytes_push_str ( bytes , cli_ucs2 ( cli ) , fname ,
strlen ( fname ) + 1 , NULL ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
subreq = cli_smb_send ( state , ev , cli , SMBcheckpath , additional_flags ,
0 , NULL , talloc_get_size ( bytes ) , bytes ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , cli_chkpath_done , req ) ;
return req ;
}
static void cli_chkpath_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
NTSTATUS status ;
2010-02-20 11:53:58 +03:00
status = cli_smb_recv ( subreq , NULL , NULL , 0 , NULL , NULL , NULL , NULL ) ;
2009-04-22 17:46:42 +04:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
}
tevent_req_done ( req ) ;
}
NTSTATUS cli_chkpath_recv ( struct tevent_req * req )
{
return tevent_req_simple_recv_ntstatus ( req ) ;
}
NTSTATUS cli_chkpath ( struct cli_state * cli , const char * path )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
char * path2 = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
path2 = talloc_strdup ( frame , path ) ;
if ( ! path2 ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
trim_char ( path2 , ' \0 ' , ' \\ ' ) ;
if ( ! * path2 ) {
path2 = talloc_strdup ( frame , " \\ " ) ;
if ( ! path2 ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_chkpath_send ( frame , ev , cli , path2 ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_chkpath_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
}
2009-04-22 19:04:53 +04:00
/****************************************************************************
Query disk space .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void cli_dskattr_done ( struct tevent_req * subreq ) ;
struct cli_dskattr_state {
int bsize ;
int total ;
int avail ;
} ;
struct tevent_req * cli_dskattr_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli )
2000-04-25 18:04:06 +04:00
{
2009-04-22 19:04:53 +04:00
struct tevent_req * req = NULL , * subreq = NULL ;
struct cli_dskattr_state * state = NULL ;
uint8_t additional_flags = 0 ;
2007-11-30 04:47:31 +03:00
2009-04-22 19:04:53 +04:00
req = tevent_req_create ( mem_ctx , & state , struct cli_dskattr_state ) ;
if ( req = = NULL ) {
return NULL ;
2007-11-30 04:47:31 +03:00
}
2009-04-22 19:04:53 +04:00
subreq = cli_smb_send ( state , ev , cli , SMBdskattr , additional_flags ,
0 , NULL , 0 , NULL ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
2007-12-06 00:31:24 +03:00
}
2009-04-22 19:04:53 +04:00
tevent_req_set_callback ( subreq , cli_dskattr_done , req ) ;
return req ;
}
2007-11-30 04:47:31 +03:00
2009-04-22 19:04:53 +04:00
static void cli_dskattr_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct cli_dskattr_state * state = tevent_req_data (
req , struct cli_dskattr_state ) ;
uint8_t wct ;
uint16_t * vwv = NULL ;
2010-02-20 17:23:31 +03:00
uint8_t * inbuf ;
2009-04-22 19:04:53 +04:00
NTSTATUS status ;
2001-02-20 15:25:42 +03:00
2010-02-20 17:23:31 +03:00
status = cli_smb_recv ( subreq , state , & inbuf , 4 , & wct , & vwv , NULL ,
NULL ) ;
TALLOC_FREE ( subreq ) ;
2009-04-22 19:04:53 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
}
state - > bsize = SVAL ( vwv + 1 , 0 ) * SVAL ( vwv + 2 , 0 ) ;
state - > total = SVAL ( vwv + 0 , 0 ) ;
state - > avail = SVAL ( vwv + 3 , 0 ) ;
tevent_req_done ( req ) ;
}
2000-04-25 18:04:06 +04:00
2009-04-22 19:04:53 +04:00
NTSTATUS cli_dskattr_recv ( struct tevent_req * req , int * bsize , int * total , int * avail )
{
struct cli_dskattr_state * state = tevent_req_data (
req , struct cli_dskattr_state ) ;
NTSTATUS status ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
2000-04-25 18:04:06 +04:00
}
2009-04-22 19:04:53 +04:00
* bsize = state - > bsize ;
* total = state - > total ;
* avail = state - > avail ;
return NT_STATUS_OK ;
}
2000-04-25 18:04:06 +04:00
2009-04-22 19:04:53 +04:00
NTSTATUS cli_dskattr ( struct cli_state * cli , int * bsize , int * total , int * avail )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
2007-11-30 04:47:31 +03:00
2009-04-22 19:04:53 +04:00
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
2000-04-25 18:04:06 +04:00
2009-04-22 19:04:53 +04:00
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
2000-04-25 18:04:06 +04:00
2009-04-22 19:04:53 +04:00
req = cli_dskattr_send ( frame , ev , cli ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
2001-11-04 03:14:08 +03:00
2009-04-22 19:04:53 +04:00
status = cli_dskattr_recv ( req , bsize , total , avail ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
}
2001-04-22 06:54:04 +04:00
/****************************************************************************
2001-11-04 03:14:08 +03:00
Create and open a temporary file .
2001-04-22 06:54:04 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-11-04 03:14:08 +03:00
2009-06-10 22:58:00 +04:00
static void cli_ctemp_done ( struct tevent_req * subreq ) ;
struct ctemp_state {
uint16_t vwv [ 3 ] ;
char * ret_path ;
uint16_t fnum ;
} ;
struct tevent_req * cli_ctemp_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * path )
2001-04-22 06:54:04 +04:00
{
2009-06-10 22:58:00 +04:00
struct tevent_req * req = NULL , * subreq = NULL ;
struct ctemp_state * state = NULL ;
uint8_t additional_flags = 0 ;
uint8_t * bytes = NULL ;
2001-04-22 06:54:04 +04:00
2009-06-10 22:58:00 +04:00
req = tevent_req_create ( mem_ctx , & state , struct ctemp_state ) ;
if ( req = = NULL ) {
return NULL ;
}
2001-04-22 06:54:04 +04:00
2009-06-10 22:58:00 +04:00
SSVAL ( state - > vwv , 0 , 0 ) ;
SIVALS ( state - > vwv + 1 , 0 , - 1 ) ;
2001-04-22 06:54:04 +04:00
2009-06-10 22:58:00 +04:00
bytes = talloc_array ( state , uint8_t , 1 ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
bytes [ 0 ] = 4 ;
bytes = smb_bytes_push_str ( bytes , cli_ucs2 ( cli ) , path ,
strlen ( path ) + 1 , NULL ) ;
if ( tevent_req_nomem ( bytes , req ) ) {
return tevent_req_post ( req , ev ) ;
}
2001-04-22 06:54:04 +04:00
2009-06-10 22:58:00 +04:00
subreq = cli_smb_send ( state , ev , cli , SMBctemp , additional_flags ,
3 , state - > vwv , talloc_get_size ( bytes ) , bytes ) ;
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , cli_ctemp_done , req ) ;
return req ;
}
2001-04-22 06:54:04 +04:00
2009-06-10 22:58:00 +04:00
static void cli_ctemp_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct ctemp_state * state = tevent_req_data (
req , struct ctemp_state ) ;
NTSTATUS status ;
uint8_t wcnt ;
uint16_t * vwv ;
uint32_t num_bytes = 0 ;
uint8_t * bytes = NULL ;
2010-02-20 17:25:34 +03:00
uint8_t * inbuf ;
2001-04-22 06:54:04 +04:00
2010-02-20 17:25:34 +03:00
status = cli_smb_recv ( subreq , state , & inbuf , 1 , & wcnt , & vwv ,
2010-02-20 11:53:58 +03:00
& num_bytes , & bytes ) ;
2010-02-20 17:25:34 +03:00
TALLOC_FREE ( subreq ) ;
2009-06-10 22:58:00 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
}
2001-06-21 09:38:28 +04:00
2009-06-10 22:58:00 +04:00
state - > fnum = SVAL ( vwv + 0 , 0 ) ;
/* From W2K3, the result is just the ASCII name */
if ( num_bytes < 2 ) {
tevent_req_nterror ( req , NT_STATUS_DATA_ERROR ) ;
return ;
2001-04-22 06:54:04 +04:00
}
2009-06-10 22:58:00 +04:00
if ( pull_string_talloc ( state ,
NULL ,
0 ,
& state - > ret_path ,
bytes ,
num_bytes ,
STR_ASCII ) = = 0 ) {
tevent_req_nterror ( req , NT_STATUS_NO_MEMORY ) ;
return ;
2001-04-22 06:54:04 +04:00
}
2009-06-10 22:58:00 +04:00
tevent_req_done ( req ) ;
}
2001-04-22 06:54:04 +04:00
2009-06-10 22:58:00 +04:00
NTSTATUS cli_ctemp_recv ( struct tevent_req * req ,
TALLOC_CTX * ctx ,
uint16_t * pfnum ,
char * * outfile )
{
struct ctemp_state * state = tevent_req_data ( req ,
struct ctemp_state ) ;
NTSTATUS status ;
2001-09-17 08:23:48 +04:00
2009-06-10 22:58:00 +04:00
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
* pfnum = state - > fnum ;
* outfile = talloc_strdup ( ctx , state - > ret_path ) ;
if ( ! * outfile ) {
return NT_STATUS_NO_MEMORY ;
}
return NT_STATUS_OK ;
}
NTSTATUS cli_ctemp ( struct cli_state * cli ,
TALLOC_CTX * ctx ,
const char * path ,
uint16_t * pfnum ,
char * * out_path )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev ;
struct tevent_req * req ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_ctemp_send ( frame , ev , cli , path ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
2001-04-22 06:54:04 +04:00
}
2009-06-10 22:58:00 +04:00
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_ctemp_recv ( req , ctx , pfnum , out_path ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2001-04-22 06:54:04 +04:00
}
2003-04-23 12:12:34 +04:00
2007-11-30 04:47:31 +03:00
/*
2003-04-23 12:12:34 +04:00
send a raw ioctl - used by the torture code
*/
2009-05-01 02:26:43 +04:00
NTSTATUS cli_raw_ioctl ( struct cli_state * cli , uint16_t fnum , uint32_t code , DATA_BLOB * blob )
2003-04-23 12:12:34 +04:00
{
2010-02-07 15:36:49 +03:00
uint16_t vwv [ 3 ] ;
NTSTATUS status ;
struct tevent_req * result_parent ;
2003-04-23 12:12:34 +04:00
2010-02-07 15:36:49 +03:00
SSVAL ( vwv + 0 , 0 , fnum ) ;
SSVAL ( vwv + 1 , 0 , code > > 16 ) ;
SSVAL ( vwv + 2 , 0 , ( code & 0xFFFF ) ) ;
2003-04-23 12:12:34 +04:00
2010-02-07 15:36:49 +03:00
status = cli_smb ( talloc_tos ( ) , cli , SMBioctl , 0 , 3 , vwv , 0 , NULL ,
& result_parent , 0 , NULL , NULL , NULL , NULL ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2003-04-23 12:12:34 +04:00
}
2007-05-14 16:16:20 +04:00
* blob = data_blob_null ;
2003-04-23 12:12:34 +04:00
return NT_STATUS_OK ;
}
2004-03-24 06:48:08 +03:00
/*********************************************************
2004-03-30 02:21:47 +04:00
Set an extended attribute utility fn .
2004-03-24 06:48:08 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-04-24 18:06:48 +04:00
static bool cli_set_ea ( struct cli_state * cli , uint16_t setup , char * param , unsigned int param_len ,
2004-03-30 02:21:47 +04:00
const char * ea_name , const char * ea_val , size_t ea_len )
2007-12-06 00:31:24 +03:00
{
2004-03-24 06:48:08 +03:00
unsigned int data_len = 0 ;
char * data = NULL ;
char * rparam = NULL , * rdata = NULL ;
char * p ;
size_t ea_namelen = strlen ( ea_name ) ;
2005-10-31 23:11:58 +03:00
if ( ea_namelen = = 0 & & ea_len = = 0 ) {
data_len = 4 ;
2006-07-31 07:53:39 +04:00
data = ( char * ) SMB_MALLOC ( data_len ) ;
2005-10-31 23:11:58 +03:00
if ( ! data ) {
return False ;
}
p = data ;
SIVAL ( p , 0 , data_len ) ;
} else {
data_len = 4 + 4 + ea_namelen + 1 + ea_len ;
2006-07-31 07:53:39 +04:00
data = ( char * ) SMB_MALLOC ( data_len ) ;
2005-10-31 23:11:58 +03:00
if ( ! data ) {
return False ;
}
p = data ;
SIVAL ( p , 0 , data_len ) ;
p + = 4 ;
SCVAL ( p , 0 , 0 ) ; /* EA flags. */
SCVAL ( p , 1 , ea_namelen ) ;
SSVAL ( p , 2 , ea_len ) ;
memcpy ( p + 4 , ea_name , ea_namelen + 1 ) ; /* Copy in the name. */
memcpy ( p + 4 + ea_namelen + 1 , ea_val , ea_len ) ;
2004-03-24 06:48:08 +03:00
}
if ( ! cli_send_trans ( cli , SMBtrans2 ,
2007-12-06 00:31:24 +03:00
NULL , /* name */
- 1 , 0 , /* fid, flags */
& setup , 1 , 0 , /* setup, length, max */
param , param_len , 2 , /* param, length, max */
data , data_len , cli - > max_xmit /* data, length, max */
) ) {
SAFE_FREE ( data ) ;
return False ;
2004-03-27 05:13:58 +03:00
}
if ( ! cli_receive_trans ( cli , SMBtrans2 ,
2007-12-06 00:31:24 +03:00
& rparam , & param_len ,
& rdata , & data_len ) ) {
SAFE_FREE ( data ) ;
return false ;
2004-03-27 05:13:58 +03:00
}
SAFE_FREE ( data ) ;
SAFE_FREE ( rdata ) ;
SAFE_FREE ( rparam ) ;
return True ;
}
/*********************************************************
2004-03-30 02:21:47 +04:00
Set an extended attribute on a pathname .
2004-03-27 05:13:58 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool cli_set_ea_path ( struct cli_state * cli , const char * path , const char * ea_name , const char * ea_val , size_t ea_len )
2004-03-27 05:13:58 +03:00
{
2009-04-24 18:06:48 +04:00
uint16_t setup = TRANSACT2_SETPATHINFO ;
2004-03-30 02:21:47 +04:00
unsigned int param_len = 0 ;
2007-12-06 00:31:24 +03:00
char * param ;
2004-03-30 02:21:47 +04:00
size_t srclen = 2 * ( strlen ( path ) + 1 ) ;
2004-03-27 05:13:58 +03:00
char * p ;
2007-12-06 00:31:24 +03:00
bool ret ;
2004-03-27 05:13:58 +03:00
2007-12-08 13:21:08 +03:00
param = SMB_MALLOC_ARRAY ( char , 6 + srclen + 2 ) ;
2007-12-06 00:31:24 +03:00
if ( ! param ) {
return false ;
}
memset ( param , ' \0 ' , 6 ) ;
2004-03-30 02:21:47 +04:00
SSVAL ( param , 0 , SMB_INFO_SET_EA ) ;
p = & param [ 6 ] ;
2004-03-27 05:13:58 +03:00
2007-12-06 00:31:24 +03:00
p + = clistr_push ( cli , p , path , srclen , STR_TERMINATE ) ;
2004-03-30 02:21:47 +04:00
param_len = PTR_DIFF ( p , param ) ;
2004-03-27 05:13:58 +03:00
2007-12-06 00:31:24 +03:00
ret = cli_set_ea ( cli , setup , param , param_len , ea_name , ea_val , ea_len ) ;
SAFE_FREE ( param ) ;
return ret ;
2004-03-30 02:21:47 +04:00
}
2004-03-24 06:48:08 +03:00
2004-03-30 02:21:47 +04:00
/*********************************************************
Set an extended attribute on an fnum .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2004-03-24 06:48:08 +03:00
2009-05-01 02:26:43 +04:00
bool cli_set_ea_fnum ( struct cli_state * cli , uint16_t fnum , const char * ea_name , const char * ea_val , size_t ea_len )
2004-03-30 02:21:47 +04:00
{
char param [ 6 ] ;
2009-04-24 18:06:48 +04:00
uint16_t setup = TRANSACT2_SETFILEINFO ;
2004-03-24 06:48:08 +03:00
2004-03-30 02:21:47 +04:00
memset ( param , 0 , 6 ) ;
SSVAL ( param , 0 , fnum ) ;
SSVAL ( param , 2 , SMB_INFO_SET_EA ) ;
return cli_set_ea ( cli , setup , param , 6 , ea_name , ea_val , ea_len ) ;
2004-03-24 06:48:08 +03:00
}
2004-03-30 02:21:47 +04:00
/*********************************************************
2008-09-01 18:22:04 +04:00
Get an extended attribute list utility fn .
2004-03-30 02:21:47 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
static bool cli_get_ea_list ( struct cli_state * cli ,
2009-04-24 18:06:48 +04:00
uint16_t setup , char * param , unsigned int param_len ,
2004-03-27 05:13:58 +03:00
TALLOC_CTX * ctx ,
size_t * pnum_eas ,
2004-03-30 02:21:47 +04:00
struct ea_struct * * pea_list )
2004-03-24 06:48:08 +03:00
{
2004-03-27 05:13:58 +03:00
unsigned int data_len = 0 ;
unsigned int rparam_len , rdata_len ;
char * rparam = NULL , * rdata = NULL ;
char * p ;
2004-03-30 02:21:47 +04:00
size_t ea_size ;
size_t num_eas ;
2007-10-19 04:40:25 +04:00
bool ret = False ;
2004-03-30 02:21:47 +04:00
struct ea_struct * ea_list ;
* pnum_eas = 0 ;
2006-08-29 05:11:02 +04:00
if ( pea_list ) {
* pea_list = NULL ;
}
2004-03-30 02:21:47 +04:00
2004-03-27 05:13:58 +03:00
if ( ! cli_send_trans ( cli , SMBtrans2 ,
NULL , /* Name */
- 1 , 0 , /* fid, flags */
& setup , 1 , 0 , /* setup, length, max */
param , param_len , 10 , /* param, length, max */
NULL , data_len , cli - > max_xmit /* data, length, max */
) ) {
return False ;
}
2004-03-30 02:21:47 +04:00
2004-03-27 05:13:58 +03:00
if ( ! cli_receive_trans ( cli , SMBtrans2 ,
& rparam , & rparam_len ,
& rdata , & rdata_len ) ) {
return False ;
}
2004-03-30 02:21:47 +04:00
2004-03-27 05:13:58 +03:00
if ( ! rdata | | rdata_len < 4 ) {
2004-03-30 02:21:47 +04:00
goto out ;
2004-03-27 05:13:58 +03:00
}
2004-03-30 02:21:47 +04:00
ea_size = ( size_t ) IVAL ( rdata , 0 ) ;
if ( ea_size > rdata_len ) {
goto out ;
}
2004-03-30 22:38:21 +04:00
if ( ea_size = = 0 ) {
/* No EA's present. */
ret = True ;
goto out ;
}
2004-03-30 02:21:47 +04:00
p = rdata + 4 ;
ea_size - = 4 ;
/* Validate the EA list and count it. */
for ( num_eas = 0 ; ea_size > = 4 ; num_eas + + ) {
unsigned int ea_namelen = CVAL ( p , 1 ) ;
unsigned int ea_valuelen = SVAL ( p , 2 ) ;
if ( ea_namelen = = 0 ) {
goto out ;
}
if ( 4 + ea_namelen + 1 + ea_valuelen > ea_size ) {
goto out ;
}
ea_size - = 4 + ea_namelen + 1 + ea_valuelen ;
p + = 4 + ea_namelen + 1 + ea_valuelen ;
}
if ( num_eas = = 0 ) {
ret = True ;
goto out ;
}
* pnum_eas = num_eas ;
if ( ! pea_list ) {
/* Caller only wants number of EA's. */
ret = True ;
goto out ;
}
2007-06-05 03:31:34 +04:00
ea_list = TALLOC_ARRAY ( ctx , struct ea_struct , num_eas ) ;
if ( ! ea_list ) {
goto out ;
2004-03-30 02:21:47 +04:00
}
ea_size = ( size_t ) IVAL ( rdata , 0 ) ;
p = rdata + 4 ;
for ( num_eas = 0 ; num_eas < * pnum_eas ; num_eas + + ) {
struct ea_struct * ea = & ea_list [ num_eas ] ;
fstring unix_ea_name ;
unsigned int ea_namelen = CVAL ( p , 1 ) ;
unsigned int ea_valuelen = SVAL ( p , 2 ) ;
ea - > flags = CVAL ( p , 0 ) ;
unix_ea_name [ 0 ] = ' \0 ' ;
pull_ascii_fstring ( unix_ea_name , p + 4 ) ;
ea - > name = talloc_strdup ( ctx , unix_ea_name ) ;
/* Ensure the value is null terminated (in case it's a string). */
ea - > value = data_blob_talloc ( ctx , NULL , ea_valuelen + 1 ) ;
if ( ! ea - > value . data ) {
goto out ;
}
if ( ea_valuelen ) {
memcpy ( ea - > value . data , p + 4 + ea_namelen + 1 , ea_valuelen ) ;
}
ea - > value . data [ ea_valuelen ] = 0 ;
ea - > value . length - - ;
p + = 4 + ea_namelen + 1 + ea_valuelen ;
}
* pea_list = ea_list ;
ret = True ;
out :
SAFE_FREE ( rdata ) ;
SAFE_FREE ( rparam ) ;
return ret ;
}
/*********************************************************
Get an extended attribute list from a pathname .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool cli_get_ea_list_path ( struct cli_state * cli , const char * path ,
2004-03-30 02:21:47 +04:00
TALLOC_CTX * ctx ,
size_t * pnum_eas ,
struct ea_struct * * pea_list )
{
2009-04-24 18:06:48 +04:00
uint16_t setup = TRANSACT2_QPATHINFO ;
2004-03-30 02:21:47 +04:00
unsigned int param_len = 0 ;
2007-12-06 00:31:24 +03:00
char * param ;
2004-03-30 02:21:47 +04:00
char * p ;
2007-12-06 00:31:24 +03:00
size_t srclen = 2 * ( strlen ( path ) + 1 ) ;
bool ret ;
2004-03-30 02:21:47 +04:00
2007-12-08 13:21:08 +03:00
param = SMB_MALLOC_ARRAY ( char , 6 + srclen + 2 ) ;
2007-12-06 00:31:24 +03:00
if ( ! param ) {
return false ;
}
2004-03-30 02:21:47 +04:00
p = param ;
memset ( p , 0 , 6 ) ;
SSVAL ( p , 0 , SMB_INFO_QUERY_ALL_EAS ) ;
p + = 6 ;
2007-12-06 00:31:24 +03:00
p + = clistr_push ( cli , p , path , srclen , STR_TERMINATE ) ;
2004-03-30 02:21:47 +04:00
param_len = PTR_DIFF ( p , param ) ;
2007-12-06 00:31:24 +03:00
ret = cli_get_ea_list ( cli , setup , param , param_len , ctx , pnum_eas , pea_list ) ;
SAFE_FREE ( param ) ;
return ret ;
2004-03-30 02:21:47 +04:00
}
/*********************************************************
Get an extended attribute list from an fnum .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-05-01 02:26:43 +04:00
bool cli_get_ea_list_fnum ( struct cli_state * cli , uint16_t fnum ,
2004-03-30 02:21:47 +04:00
TALLOC_CTX * ctx ,
size_t * pnum_eas ,
struct ea_struct * * pea_list )
{
2009-04-24 18:06:48 +04:00
uint16_t setup = TRANSACT2_QFILEINFO ;
2004-03-30 02:21:47 +04:00
char param [ 6 ] ;
memset ( param , 0 , 6 ) ;
SSVAL ( param , 0 , fnum ) ;
SSVAL ( param , 2 , SMB_INFO_SET_EA ) ;
return cli_get_ea_list ( cli , setup , param , 6 , ctx , pnum_eas , pea_list ) ;
2004-03-24 06:48:08 +03:00
}
2007-03-02 00:05:29 +03:00
/****************************************************************************
2009-04-24 18:06:48 +04:00
Convert open " flags " arg to uint32_t on wire .
2007-03-02 00:05:29 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-04-24 18:06:48 +04:00
static uint32_t open_flags_to_wire ( int flags )
2007-03-02 00:05:29 +03:00
{
int open_mode = flags & O_ACCMODE ;
2009-04-24 18:06:48 +04:00
uint32_t ret = 0 ;
2007-03-02 00:05:29 +03:00
switch ( open_mode ) {
case O_WRONLY :
ret | = SMB_O_WRONLY ;
break ;
case O_RDWR :
ret | = SMB_O_RDWR ;
break ;
default :
2007-03-02 01:15:30 +03:00
case O_RDONLY :
2007-03-02 00:05:29 +03:00
ret | = SMB_O_RDONLY ;
break ;
}
if ( flags & O_CREAT ) {
ret | = SMB_O_CREAT ;
}
if ( flags & O_EXCL ) {
ret | = SMB_O_EXCL ;
}
if ( flags & O_TRUNC ) {
ret | = SMB_O_TRUNC ;
}
2007-03-05 20:02:20 +03:00
# if defined(O_SYNC)
2007-03-02 00:05:29 +03:00
if ( flags & O_SYNC ) {
ret | = SMB_O_SYNC ;
}
2007-03-05 20:02:20 +03:00
# endif /* O_SYNC */
2007-03-02 00:05:29 +03:00
if ( flags & O_APPEND ) {
ret | = SMB_O_APPEND ;
}
2007-03-02 00:36:05 +03:00
# if defined(O_DIRECT)
2007-03-02 00:05:29 +03:00
if ( flags & O_DIRECT ) {
ret | = SMB_O_DIRECT ;
}
2007-03-02 00:36:05 +03:00
# endif
# if defined(O_DIRECTORY)
2007-03-02 00:05:29 +03:00
if ( flags & O_DIRECTORY ) {
2007-03-02 01:15:30 +03:00
ret & = ~ ( SMB_O_RDONLY | SMB_O_RDWR | SMB_O_WRONLY ) ;
2007-03-02 00:05:29 +03:00
ret | = SMB_O_DIRECTORY ;
}
2007-03-02 00:36:05 +03:00
# endif
2007-03-02 00:05:29 +03:00
return ret ;
}
/****************************************************************************
Open a file - POSIX semantics . Returns fnum . Doesn ' t request oplock .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-05-21 05:31:36 +04:00
struct posix_open_state {
uint16_t setup ;
uint8_t * param ;
uint8_t data [ 18 ] ;
uint16_t fnum ; /* Out */
} ;
static void cli_posix_open_internal_done ( struct tevent_req * subreq )
2007-03-02 00:05:29 +03:00
{
2009-05-21 05:31:36 +04:00
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct posix_open_state * state = tevent_req_data ( req , struct posix_open_state ) ;
NTSTATUS status ;
uint8_t * data ;
uint32_t num_data ;
2009-11-14 13:12:50 +03:00
status = cli_trans_recv ( subreq , state , NULL , 0 , NULL , NULL , 0 , NULL ,
& data , 12 , & num_data ) ;
2009-05-21 05:31:36 +04:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
tevent_req_nterror ( req , status ) ;
return ;
}
state - > fnum = SVAL ( data , 2 ) ;
tevent_req_done ( req ) ;
}
static struct tevent_req * cli_posix_open_internal_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname ,
int flags ,
mode_t mode ,
bool is_dir )
{
struct tevent_req * req = NULL , * subreq = NULL ;
struct posix_open_state * state = NULL ;
2009-04-24 18:06:48 +04:00
uint32_t wire_flags = open_flags_to_wire ( flags ) ;
2007-03-02 00:05:29 +03:00
2009-05-21 05:31:36 +04:00
req = tevent_req_create ( mem_ctx , & state , struct posix_open_state ) ;
if ( req = = NULL ) {
return NULL ;
2007-12-06 00:31:24 +03:00
}
2007-03-02 00:05:29 +03:00
2009-05-21 05:31:36 +04:00
/* Setup setup word. */
SSVAL ( & state - > setup , 0 , TRANSACT2_SETPATHINFO ) ;
2007-03-02 00:05:29 +03:00
2009-05-21 05:31:36 +04:00
/* Setup param array. */
state - > param = talloc_array ( state , uint8_t , 6 ) ;
if ( tevent_req_nomem ( state - > param , req ) ) {
return tevent_req_post ( req , ev ) ;
2007-03-02 01:44:02 +03:00
}
2009-05-21 05:31:36 +04:00
memset ( state - > param , ' \0 ' , 6 ) ;
SSVAL ( state - > param , 0 , SMB_POSIX_PATH_OPEN ) ;
2007-03-02 00:05:29 +03:00
2009-05-21 05:31:36 +04:00
state - > param = trans2_bytes_push_str ( state - > param , cli_ucs2 ( cli ) , fname ,
strlen ( fname ) + 1 , NULL ) ;
2007-03-02 00:05:29 +03:00
2009-05-21 05:31:36 +04:00
if ( tevent_req_nomem ( state - > param , req ) ) {
return tevent_req_post ( req , ev ) ;
}
2007-03-02 00:05:29 +03:00
2009-05-21 05:31:36 +04:00
/* Setup data words. */
if ( is_dir ) {
wire_flags & = ~ ( SMB_O_RDONLY | SMB_O_RDWR | SMB_O_WRONLY ) ;
wire_flags | = SMB_O_DIRECTORY ;
2007-03-02 00:05:29 +03:00
}
2009-05-21 05:31:36 +04:00
SIVAL ( state - > data , 0 , 0 ) ; /* No oplock. */
SIVAL ( state - > data , 4 , wire_flags ) ;
SIVAL ( state - > data , 8 , unix_perms_to_wire ( mode ) ) ;
SIVAL ( state - > data , 12 , 0 ) ; /* Top bits of perms currently undefined. */
SSVAL ( state - > data , 16 , SMB_NO_INFO_LEVEL_RETURNED ) ; /* No info level returned. */
2007-12-06 00:31:24 +03:00
2009-05-21 05:31:36 +04:00
subreq = cli_trans_send ( state , /* mem ctx. */
ev , /* event ctx. */
cli , /* cli_state. */
SMBtrans2 , /* cmd. */
NULL , /* pipe name. */
- 1 , /* fid. */
0 , /* function. */
0 , /* flags. */
& state - > setup , /* setup. */
1 , /* num setup uint16_t words. */
0 , /* max returned setup. */
state - > param , /* param. */
talloc_get_size ( state - > param ) , /* num param. */
2 , /* max returned param. */
state - > data , /* data. */
18 , /* num data. */
12 ) ; /* max returned data. */
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
2007-03-02 00:05:29 +03:00
}
2009-05-21 05:31:36 +04:00
tevent_req_set_callback ( subreq , cli_posix_open_internal_done , req ) ;
return req ;
}
2007-03-02 00:05:29 +03:00
2009-05-21 05:31:36 +04:00
struct tevent_req * cli_posix_open_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname ,
int flags ,
mode_t mode )
{
return cli_posix_open_internal_send ( mem_ctx , ev ,
cli , fname , flags , mode , false ) ;
}
2007-03-02 00:05:29 +03:00
2009-05-21 05:31:36 +04:00
NTSTATUS cli_posix_open_recv ( struct tevent_req * req , uint16_t * pfnum )
{
struct posix_open_state * state = tevent_req_data ( req , struct posix_open_state ) ;
NTSTATUS status ;
2007-03-02 00:05:29 +03:00
2009-05-21 05:31:36 +04:00
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
* pfnum = state - > fnum ;
return NT_STATUS_OK ;
2007-03-02 00:05:29 +03:00
}
2007-03-02 01:44:02 +03:00
/****************************************************************************
2009-05-21 05:31:36 +04:00
Open - POSIX semantics . Doesn ' t request oplock .
2007-03-02 01:44:02 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-05-21 05:31:36 +04:00
NTSTATUS cli_posix_open ( struct cli_state * cli , const char * fname ,
int flags , mode_t mode , uint16_t * pfnum )
2007-03-02 01:44:02 +03:00
{
2009-05-21 05:31:36 +04:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_posix_open_send ( frame ,
ev ,
cli ,
fname ,
flags ,
mode ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_posix_open_recv ( req , pfnum ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2007-03-02 01:44:02 +03:00
}
2009-05-21 05:31:36 +04:00
struct tevent_req * cli_posix_mkdir_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname ,
mode_t mode )
{
return cli_posix_open_internal_send ( mem_ctx , ev ,
cli , fname , O_CREAT , mode , true ) ;
}
2007-03-02 00:05:29 +03:00
2009-05-21 05:31:36 +04:00
NTSTATUS cli_posix_mkdir_recv ( struct tevent_req * req )
2007-03-02 00:05:29 +03:00
{
2009-05-21 05:31:36 +04:00
NTSTATUS status ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
return NT_STATUS_OK ;
}
NTSTATUS cli_posix_mkdir ( struct cli_state * cli , const char * fname , mode_t mode )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_posix_mkdir_send ( frame ,
ev ,
cli ,
fname ,
mode ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_posix_mkdir_recv ( req ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2007-03-02 00:05:29 +03:00
}
/****************************************************************************
unlink or rmdir - POSIX semantics .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-04-29 00:18:51 +04:00
struct unlink_state {
2009-05-07 21:01:28 +04:00
uint16_t setup ;
uint8_t data [ 2 ] ;
2009-04-29 00:18:51 +04:00
} ;
static void cli_posix_unlink_internal_done ( struct tevent_req * subreq )
2007-03-02 00:05:29 +03:00
{
2009-11-16 11:59:58 +03:00
NTSTATUS status = cli_trans_recv ( subreq , NULL , NULL , 0 , NULL ,
NULL , 0 , NULL , NULL , 0 , NULL ) ;
2009-11-17 17:15:35 +03:00
tevent_req_simple_finish_ntstatus ( subreq , status ) ;
2009-04-29 00:18:51 +04:00
}
static struct tevent_req * cli_posix_unlink_internal_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname ,
bool is_dir )
{
struct tevent_req * req = NULL , * subreq = NULL ;
struct unlink_state * state = NULL ;
uint8_t * param = NULL ;
req = tevent_req_create ( mem_ctx , & state , struct unlink_state ) ;
if ( req = = NULL ) {
return NULL ;
}
/* Setup setup word. */
2009-05-07 21:01:28 +04:00
SSVAL ( & state - > setup , 0 , TRANSACT2_SETPATHINFO ) ;
2009-04-29 00:18:51 +04:00
/* Setup param array. */
param = talloc_array ( state , uint8_t , 6 ) ;
2009-05-07 21:01:28 +04:00
if ( tevent_req_nomem ( param , req ) ) {
2009-04-29 00:18:51 +04:00
return tevent_req_post ( req , ev ) ;
2007-12-06 00:31:24 +03:00
}
memset ( param , ' \0 ' , 6 ) ;
2009-04-29 00:18:51 +04:00
SSVAL ( param , 0 , SMB_POSIX_PATH_UNLINK ) ;
2007-03-02 00:05:29 +03:00
2009-05-05 02:50:35 +04:00
param = trans2_bytes_push_str ( param , cli_ucs2 ( cli ) , fname ,
2009-04-29 00:18:51 +04:00
strlen ( fname ) + 1 , NULL ) ;
if ( tevent_req_nomem ( param , req ) ) {
return tevent_req_post ( req , ev ) ;
}
2007-03-02 00:05:29 +03:00
2009-04-29 00:18:51 +04:00
/* Setup data word. */
2009-05-07 21:01:28 +04:00
SSVAL ( state - > data , 0 , is_dir ? SMB_POSIX_UNLINK_DIRECTORY_TARGET :
2007-03-02 00:05:29 +03:00
SMB_POSIX_UNLINK_FILE_TARGET ) ;
2009-04-29 00:18:51 +04:00
subreq = cli_trans_send ( state , /* mem ctx. */
ev , /* event ctx. */
cli , /* cli_state. */
SMBtrans2 , /* cmd. */
NULL , /* pipe name. */
- 1 , /* fid. */
0 , /* function. */
0 , /* flags. */
2009-05-07 21:01:28 +04:00
& state - > setup , /* setup. */
2009-05-05 02:50:35 +04:00
1 , /* num setup uint16_t words. */
0 , /* max returned setup. */
2009-04-29 00:18:51 +04:00
param , /* param. */
talloc_get_size ( param ) , /* num param. */
2009-05-05 02:50:35 +04:00
2 , /* max returned param. */
2009-05-07 21:01:28 +04:00
state - > data , /* data. */
2009-04-29 00:18:51 +04:00
2 , /* num data. */
2009-05-05 02:50:35 +04:00
0 ) ; /* max returned data. */
2007-03-02 00:05:29 +03:00
2009-04-29 00:18:51 +04:00
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
2007-03-02 00:05:29 +03:00
}
2009-04-29 00:18:51 +04:00
tevent_req_set_callback ( subreq , cli_posix_unlink_internal_done , req ) ;
return req ;
}
2007-03-02 00:05:29 +03:00
2009-04-29 00:18:51 +04:00
struct tevent_req * cli_posix_unlink_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname )
{
return cli_posix_unlink_internal_send ( mem_ctx , ev , cli , fname , false ) ;
}
2007-03-02 00:05:29 +03:00
2009-05-21 05:31:36 +04:00
NTSTATUS cli_posix_unlink_recv ( struct tevent_req * req )
2009-04-29 00:18:51 +04:00
{
NTSTATUS status ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
return NT_STATUS_OK ;
2007-03-02 00:05:29 +03:00
}
/****************************************************************************
unlink - POSIX semantics .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-04-29 00:18:51 +04:00
NTSTATUS cli_posix_unlink ( struct cli_state * cli , const char * fname )
2007-03-02 00:05:29 +03:00
{
2009-04-29 00:18:51 +04:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_posix_unlink_send ( frame ,
ev ,
cli ,
fname ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
2009-05-21 05:31:36 +04:00
status = cli_posix_unlink_recv ( req ) ;
2009-04-29 00:18:51 +04:00
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2007-03-02 00:05:29 +03:00
}
/****************************************************************************
rmdir - POSIX semantics .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-04-29 00:18:51 +04:00
struct tevent_req * cli_posix_rmdir_send ( TALLOC_CTX * mem_ctx ,
struct event_context * ev ,
struct cli_state * cli ,
const char * fname )
{
return cli_posix_unlink_internal_send ( mem_ctx , ev , cli , fname , true ) ;
}
NTSTATUS cli_posix_rmdir_recv ( struct tevent_req * req , TALLOC_CTX * mem_ctx )
2007-03-02 00:05:29 +03:00
{
2009-04-29 00:18:51 +04:00
NTSTATUS status ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
return NT_STATUS_OK ;
}
NTSTATUS cli_posix_rmdir ( struct cli_state * cli , const char * fname )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
struct event_context * ev = NULL ;
struct tevent_req * req = NULL ;
NTSTATUS status = NT_STATUS_OK ;
if ( cli_has_async_calls ( cli ) ) {
/*
* Can ' t use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER ;
goto fail ;
}
ev = event_context_init ( frame ) ;
if ( ev = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
req = cli_posix_rmdir_send ( frame ,
ev ,
cli ,
fname ) ;
if ( req = = NULL ) {
status = NT_STATUS_NO_MEMORY ;
goto fail ;
}
if ( ! tevent_req_poll ( req , ev ) ) {
status = map_nt_error_from_unix ( errno ) ;
goto fail ;
}
status = cli_posix_rmdir_recv ( req , frame ) ;
fail :
TALLOC_FREE ( frame ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
cli_set_error ( cli , status ) ;
}
return status ;
2007-03-02 00:05:29 +03:00
}
2009-10-12 18:43:19 +04:00
2009-10-12 19:29:45 +04:00
/****************************************************************************
filechangenotify
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-10-12 18:43:19 +04:00
struct cli_notify_state {
uint8_t setup [ 8 ] ;
uint32_t num_changes ;
struct notify_change * changes ;
} ;
static void cli_notify_done ( struct tevent_req * subreq ) ;
struct tevent_req * cli_notify_send ( TALLOC_CTX * mem_ctx ,
struct tevent_context * ev ,
struct cli_state * cli , uint16_t fnum ,
uint32_t buffer_size ,
uint32_t completion_filter , bool recursive )
{
struct tevent_req * req , * subreq ;
struct cli_notify_state * state ;
req = tevent_req_create ( mem_ctx , & state , struct cli_notify_state ) ;
if ( req = = NULL ) {
return NULL ;
}
SIVAL ( state - > setup , 0 , completion_filter ) ;
SSVAL ( state - > setup , 4 , fnum ) ;
SSVAL ( state - > setup , 6 , recursive ) ;
subreq = cli_trans_send (
state , /* mem ctx. */
ev , /* event ctx. */
cli , /* cli_state. */
SMBnttrans , /* cmd. */
NULL , /* pipe name. */
- 1 , /* fid. */
NT_TRANSACT_NOTIFY_CHANGE , /* function. */
0 , /* flags. */
( uint16_t * ) state - > setup , /* setup. */
4 , /* num setup uint16_t words. */
0 , /* max returned setup. */
NULL , /* param. */
0 , /* num param. */
buffer_size , /* max returned param. */
NULL , /* data. */
0 , /* num data. */
0 ) ; /* max returned data. */
if ( tevent_req_nomem ( subreq , req ) ) {
return tevent_req_post ( req , ev ) ;
}
tevent_req_set_callback ( subreq , cli_notify_done , req ) ;
return req ;
}
static void cli_notify_done ( struct tevent_req * subreq )
{
struct tevent_req * req = tevent_req_callback_data (
subreq , struct tevent_req ) ;
struct cli_notify_state * state = tevent_req_data (
req , struct cli_notify_state ) ;
NTSTATUS status ;
uint8_t * params ;
uint32_t i , ofs , num_params ;
2009-11-14 13:12:50 +03:00
status = cli_trans_recv ( subreq , talloc_tos ( ) , NULL , 0 , NULL ,
& params , 0 , & num_params , NULL , 0 , NULL ) ;
2009-10-12 18:43:19 +04:00
TALLOC_FREE ( subreq ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 10 , ( " cli_trans_recv returned %s \n " , nt_errstr ( status ) ) ) ;
tevent_req_nterror ( req , status ) ;
return ;
}
state - > num_changes = 0 ;
ofs = 0 ;
while ( num_params - ofs > 12 ) {
uint32_t len = IVAL ( params , ofs ) ;
state - > num_changes + = 1 ;
if ( ( len = = 0 ) | | ( ofs + len > = num_params ) ) {
break ;
}
ofs + = len ;
}
state - > changes = talloc_array ( state , struct notify_change ,
state - > num_changes ) ;
if ( tevent_req_nomem ( state - > changes , req ) ) {
TALLOC_FREE ( params ) ;
return ;
}
ofs = 0 ;
for ( i = 0 ; i < state - > num_changes ; i + + ) {
uint32_t next = IVAL ( params , ofs ) ;
uint32_t len = IVAL ( params , ofs + 8 ) ;
ssize_t ret ;
char * name ;
if ( ( next ! = 0 ) & & ( len + 12 ! = next ) ) {
TALLOC_FREE ( params ) ;
tevent_req_nterror (
req , NT_STATUS_INVALID_NETWORK_RESPONSE ) ;
return ;
}
state - > changes [ i ] . action = IVAL ( params , ofs + 4 ) ;
ret = clistr_pull_talloc ( params , ( char * ) params , & name ,
params + ofs + 12 , len ,
STR_TERMINATE | STR_UNICODE ) ;
if ( ret = = - 1 ) {
TALLOC_FREE ( params ) ;
tevent_req_nterror ( req , NT_STATUS_INTERNAL_ERROR ) ;
return ;
}
state - > changes [ i ] . name = name ;
ofs + = next ;
}
TALLOC_FREE ( params ) ;
tevent_req_done ( req ) ;
}
NTSTATUS cli_notify_recv ( struct tevent_req * req , TALLOC_CTX * mem_ctx ,
uint32_t * pnum_changes ,
struct notify_change * * pchanges )
{
struct cli_notify_state * state = tevent_req_data (
req , struct cli_notify_state ) ;
NTSTATUS status ;
if ( tevent_req_is_nterror ( req , & status ) ) {
return status ;
}
* pnum_changes = state - > num_changes ;
* pchanges = talloc_move ( mem_ctx , & state - > changes ) ;
return NT_STATUS_OK ;
}