2012-02-01 17:42:39 +04:00
/*
2002-08-18 22:04:00 +04:00
Unix SMB / CIFS implementation .
VFS module functions
Copyright ( C ) Simo Sorce 2002
Copyright ( C ) Eric Lorimer 2002
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
2002-08-18 22:04:00 +04:00
( at your option ) any later version .
2012-02-01 17:42:39 +04:00
2002-08-18 22:04:00 +04:00
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2012-02-01 17:42:39 +04:00
2002-08-18 22:04:00 +04:00
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/>.
2002-08-18 22:04:00 +04:00
*/
# include "includes.h"
2011-03-23 00:34:22 +03:00
# include "smbd/smbd.h"
2011-02-25 19:14:22 +03:00
# include "system/passwd.h"
2011-02-26 01:20:06 +03:00
# include "system/filesys.h"
2002-08-18 22:04:00 +04:00
# include "vfstest.h"
2011-03-02 18:06:32 +03:00
# include "../lib/util/util_pw.h"
2002-08-18 22:04:00 +04:00
2003-05-12 03:34:18 +04:00
static const char * null_string = " " ;
2002-08-18 22:04:00 +04:00
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_load_module ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
2003-05-12 03:34:18 +04:00
int i ;
2012-02-01 17:42:39 +04:00
2003-05-12 03:34:18 +04:00
if ( argc < 2 ) {
printf ( " Usage: load <modules> \n " ) ;
2002-08-18 22:04:00 +04:00
return NT_STATUS_OK ;
}
2002-08-21 06:34:49 +04:00
2003-05-12 03:34:18 +04:00
for ( i = argc - 1 ; i > 0 ; i - - ) {
if ( ! vfs_init_custom ( vfs - > conn , argv [ i ] ) ) {
DEBUG ( 0 , ( " load: (vfs_init_custom failed for %s) \n " , argv [ i ] ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
2002-08-18 22:04:00 +04:00
}
printf ( " load: ok \n " ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_populate ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
char c ;
size_t size ;
if ( argc ! = 3 ) {
printf ( " Usage: populate <char> <size> \n " ) ;
return NT_STATUS_OK ;
}
c = argv [ 1 ] [ 0 ] ;
size = atoi ( argv [ 2 ] ) ;
2011-06-07 05:30:12 +04:00
vfs - > data = talloc_array ( mem_ctx , char , size ) ;
2002-08-18 22:04:00 +04:00
if ( vfs - > data = = NULL ) {
2002-08-18 23:22:10 +04:00
printf ( " populate: error=-1 (not enough memory) " ) ;
2002-08-18 22:04:00 +04:00
return NT_STATUS_UNSUCCESSFUL ;
}
memset ( vfs - > data , c , size ) ;
vfs - > data_size = size ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_show_data ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
size_t offset ;
size_t len ;
if ( argc ! = 1 & & argc ! = 3 ) {
printf ( " Usage: showdata [<offset> <len>] \n " ) ;
return NT_STATUS_OK ;
}
if ( vfs - > data = = NULL | | vfs - > data_size = = 0 ) {
printf ( " show_data: error=-1 (buffer empty) \n " ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
if ( argc = = 3 ) {
offset = atoi ( argv [ 1 ] ) ;
len = atoi ( argv [ 2 ] ) ;
} else {
offset = 0 ;
len = vfs - > data_size ;
}
if ( ( offset + len ) > vfs - > data_size ) {
printf ( " show_data: error=-1 (not enough data in buffer) \n " ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
2007-03-28 17:34:59 +04:00
dump_data ( 0 , ( uint8 * ) ( vfs - > data ) + offset , len ) ;
2002-08-18 22:04:00 +04:00
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_connect ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
2006-07-11 22:01:26 +04:00
SMB_VFS_CONNECT ( vfs - > conn , lp_servicename ( SNUM ( vfs - > conn ) ) , " vfstest " ) ;
2002-08-18 22:04:00 +04:00
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_disconnect ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
2003-05-14 14:59:01 +04:00
SMB_VFS_DISCONNECT ( vfs - > conn ) ;
2002-08-18 22:04:00 +04:00
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_disk_free ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
2008-10-14 03:59:36 +04:00
uint64_t diskfree , bsize , dfree , dsize ;
2002-08-18 22:04:00 +04:00
if ( argc ! = 2 ) {
printf ( " Usage: disk_free <path> \n " ) ;
return NT_STATUS_OK ;
}
2003-05-14 14:59:01 +04:00
diskfree = SMB_VFS_DISK_FREE ( vfs - > conn , argv [ 1 ] , False , & bsize , & dfree , & dsize ) ;
2002-11-23 05:58:31 +03:00
printf ( " disk_free: %lu, bsize = %lu, dfree = %lu, dsize = %lu \n " ,
( unsigned long ) diskfree ,
( unsigned long ) bsize ,
( unsigned long ) dfree ,
( unsigned long ) dsize ) ;
2002-08-18 22:04:00 +04:00
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_opendir ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
if ( argc ! = 2 ) {
printf ( " Usage: opendir <fname> \n " ) ;
return NT_STATUS_OK ;
}
2005-06-25 13:07:42 +04:00
vfs - > currentdir = SMB_VFS_OPENDIR ( vfs - > conn , argv [ 1 ] , NULL , 0 ) ;
2002-08-18 22:04:00 +04:00
if ( vfs - > currentdir = = NULL ) {
printf ( " opendir error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " opendir: ok \n " ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_readdir ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
2009-01-23 07:14:38 +03:00
SMB_STRUCT_STAT st ;
SMB_STRUCT_DIRENT * dent = NULL ;
2002-08-18 22:04:00 +04:00
if ( vfs - > currentdir = = NULL ) {
printf ( " readdir: error=-1 (no open directory) \n " ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
2009-01-23 07:14:38 +03:00
dent = SMB_VFS_READDIR ( vfs - > conn , vfs - > currentdir , & st ) ;
2002-08-18 22:04:00 +04:00
if ( dent = = NULL ) {
printf ( " readdir: NULL \n " ) ;
return NT_STATUS_OK ;
}
printf ( " readdir: %s \n " , dent - > d_name ) ;
2009-01-23 07:14:38 +03:00
if ( VALID_STAT ( st ) ) {
2009-05-14 17:34:42 +04:00
time_t tmp_time ;
2009-01-23 07:14:38 +03:00
printf ( " stat available " ) ;
2009-05-14 17:34:42 +04:00
if ( S_ISREG ( st . st_ex_mode ) ) printf ( " Regular File \n " ) ;
else if ( S_ISDIR ( st . st_ex_mode ) ) printf ( " Directory \n " ) ;
else if ( S_ISCHR ( st . st_ex_mode ) ) printf ( " Character Device \n " ) ;
else if ( S_ISBLK ( st . st_ex_mode ) ) printf ( " Block Device \n " ) ;
else if ( S_ISFIFO ( st . st_ex_mode ) ) printf ( " Fifo \n " ) ;
else if ( S_ISLNK ( st . st_ex_mode ) ) printf ( " Symbolic Link \n " ) ;
else if ( S_ISSOCK ( st . st_ex_mode ) ) printf ( " Socket \n " ) ;
printf ( " Size: %10u " , ( unsigned int ) st . st_ex_size ) ;
2009-01-23 07:14:38 +03:00
# ifdef HAVE_STAT_ST_BLOCKS
2009-05-14 17:34:42 +04:00
printf ( " Blocks: %9u " , ( unsigned int ) st . st_ex_blocks ) ;
2009-01-23 07:14:38 +03:00
# endif
# ifdef HAVE_STAT_ST_BLKSIZE
2009-05-14 17:34:42 +04:00
printf ( " IO Block: %u \n " , ( unsigned int ) st . st_ex_blksize ) ;
2009-01-23 07:14:38 +03:00
# endif
2009-05-14 17:34:42 +04:00
printf ( " Device: 0x%10x " , ( unsigned int ) st . st_ex_dev ) ;
printf ( " Inode: %10u " , ( unsigned int ) st . st_ex_ino ) ;
printf ( " Links: %10u \n " , ( unsigned int ) st . st_ex_nlink ) ;
printf ( " Access: %05o " , ( int ) ( ( st . st_ex_mode ) & 007777 ) ) ;
2009-02-11 09:16:26 +03:00
printf ( " Uid: %5lu Gid: %5lu \n " ,
2009-05-14 17:34:42 +04:00
( unsigned long ) st . st_ex_uid ,
( unsigned long ) st . st_ex_gid ) ;
tmp_time = convert_timespec_to_time_t ( st . st_ex_atime ) ;
printf ( " Access: %s " , ctime ( & tmp_time ) ) ;
tmp_time = convert_timespec_to_time_t ( st . st_ex_mtime ) ;
printf ( " Modify: %s " , ctime ( & tmp_time ) ) ;
tmp_time = convert_timespec_to_time_t ( st . st_ex_ctime ) ;
printf ( " Change: %s " , ctime ( & tmp_time ) ) ;
2009-01-23 07:14:38 +03:00
}
2002-08-18 22:04:00 +04:00
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_mkdir ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
if ( argc ! = 2 ) {
printf ( " Usage: mkdir <path> \n " ) ;
return NT_STATUS_OK ;
}
2003-05-14 14:59:01 +04:00
if ( SMB_VFS_MKDIR ( vfs - > conn , argv [ 1 ] , 00755 ) = = - 1 ) {
2002-08-18 22:04:00 +04:00
printf ( " mkdir error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
2012-02-01 17:42:39 +04:00
2002-08-18 22:04:00 +04:00
printf ( " mkdir: ok \n " ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_closedir ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
int ret ;
2012-02-01 17:42:39 +04:00
2002-08-18 22:04:00 +04:00
if ( vfs - > currentdir = = NULL ) {
printf ( " closedir: failure (no directory open) \n " ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
2003-05-14 14:59:01 +04:00
ret = SMB_VFS_CLOSEDIR ( vfs - > conn , vfs - > currentdir ) ;
2002-08-18 22:04:00 +04:00
if ( ret = = - 1 ) {
printf ( " closedir failure: %s \n " , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " closedir: ok \n " ) ;
vfs - > currentdir = NULL ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_open ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
2006-07-11 22:01:26 +04:00
int flags ;
2002-08-21 06:34:49 +04:00
mode_t mode ;
2003-05-12 03:34:18 +04:00
const char * flagstr ;
2006-07-11 22:01:26 +04:00
files_struct * fsp ;
2009-06-16 23:01:13 +04:00
struct smb_filename * smb_fname = NULL ;
NTSTATUS status ;
2002-08-18 22:04:00 +04:00
mode = 00400 ;
2002-08-18 23:22:10 +04:00
if ( argc < 3 | | argc > 5 ) {
printf ( " Usage: open <filename> <flags> <mode> \n " ) ;
printf ( " flags: O = O_RDONLY \n " ) ;
printf ( " R = O_RDWR \n " ) ;
printf ( " W = O_WRONLY \n " ) ;
printf ( " C = O_CREAT \n " ) ;
printf ( " E = O_EXCL \n " ) ;
printf ( " T = O_TRUNC \n " ) ;
printf ( " A = O_APPEND \n " ) ;
printf ( " N = O_NONBLOCK/O_NDELAY \n " ) ;
2002-08-19 20:54:06 +04:00
# ifdef O_SYNC
2002-08-18 23:22:10 +04:00
printf ( " S = O_SYNC \n " ) ;
2002-08-19 20:54:06 +04:00
# endif
2002-08-19 00:28:16 +04:00
# ifdef O_NOFOLLOW
2002-08-18 23:22:10 +04:00
printf ( " F = O_NOFOLLOW \n " ) ;
2002-08-19 00:28:16 +04:00
# endif
2002-08-18 23:22:10 +04:00
printf ( " mode: see open.2 \n " ) ;
printf ( " mode is ignored if C flag not present \n " ) ;
printf ( " mode defaults to 00400 \n " ) ;
2002-08-18 22:04:00 +04:00
return NT_STATUS_OK ;
}
2002-08-18 23:22:10 +04:00
flags = 0 ;
flagstr = argv [ 2 ] ;
while ( * flagstr ) {
switch ( * flagstr ) {
case ' O ' :
flags | = O_RDONLY ;
break ;
case ' R ' :
flags | = O_RDWR ;
break ;
case ' W ' :
flags | = O_WRONLY ;
break ;
case ' C ' :
flags | = O_CREAT ;
break ;
case ' E ' :
flags | = O_EXCL ;
break ;
case ' T ' :
flags | = O_TRUNC ;
break ;
case ' A ' :
flags | = O_APPEND ;
break ;
case ' N ' :
flags | = O_NONBLOCK ;
break ;
2002-08-19 20:54:06 +04:00
# ifdef O_SYNC
2002-08-18 23:22:10 +04:00
case ' S ' :
flags | = O_SYNC ;
break ;
2002-08-19 20:54:06 +04:00
# endif
2002-08-19 00:28:16 +04:00
# ifdef O_NOFOLLOW
2002-08-18 23:22:10 +04:00
case ' F ' :
flags | = O_NOFOLLOW ;
break ;
2002-08-19 00:28:16 +04:00
# endif
2002-08-18 23:22:10 +04:00
default :
printf ( " open: error=-1 (invalid flag!) \n " ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
flagstr + + ;
}
if ( ( flags & O_CREAT ) & & argc = = 4 ) {
2008-09-16 02:47:43 +04:00
if ( sscanf ( argv [ 3 ] , " %ho " , ( unsigned short * ) & mode ) = = 0 ) {
2002-08-18 23:22:10 +04:00
printf ( " open: error=-1 (invalid mode!) \n " ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
}
2002-08-18 22:04:00 +04:00
2006-07-11 22:01:26 +04:00
fsp = SMB_MALLOC_P ( struct files_struct ) ;
2008-01-09 13:22:29 +03:00
if ( fsp = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
2006-07-11 22:01:26 +04:00
fsp - > fh = SMB_MALLOC_P ( struct fd_handle ) ;
2008-01-09 13:22:29 +03:00
if ( fsp - > fh = = NULL ) {
SAFE_FREE ( fsp - > fsp_name ) ;
SAFE_FREE ( fsp ) ;
return NT_STATUS_NO_MEMORY ;
}
2006-07-11 22:01:26 +04:00
fsp - > conn = vfs - > conn ;
2012-02-02 19:23:40 +04:00
status = create_synthetic_smb_fname_split ( NULL , argv [ 1 ] , NULL ,
2009-06-16 23:01:13 +04:00
& smb_fname ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
SAFE_FREE ( fsp ) ;
return status ;
}
2009-07-11 05:11:32 +04:00
fsp - > fsp_name = smb_fname ;
2009-06-16 23:01:13 +04:00
fsp - > fh - > fd = SMB_VFS_OPEN ( vfs - > conn , smb_fname , fsp , flags , mode ) ;
2006-07-11 22:01:26 +04:00
if ( fsp - > fh - > fd = = - 1 ) {
2002-08-18 22:04:00 +04:00
printf ( " open: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
2006-07-11 22:01:26 +04:00
SAFE_FREE ( fsp - > fh ) ;
SAFE_FREE ( fsp ) ;
2009-07-11 05:11:32 +04:00
TALLOC_FREE ( smb_fname ) ;
2002-08-18 22:04:00 +04:00
return NT_STATUS_UNSUCCESSFUL ;
}
2006-07-11 22:01:26 +04:00
vfs - > files [ fsp - > fh - > fd ] = fsp ;
printf ( " open: fd=%d \n " , fsp - > fh - > fd ) ;
2002-08-18 22:04:00 +04:00
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_pathfunc ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
int ret = - 1 ;
if ( argc ! = 2 ) {
printf ( " Usage: %s <path> \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2002-08-19 20:54:06 +04:00
if ( strcmp ( " rmdir " , argv [ 0 ] ) = = 0 ) {
2003-05-14 14:59:01 +04:00
ret = SMB_VFS_RMDIR ( vfs - > conn , argv [ 1 ] ) ;
2002-08-19 20:54:06 +04:00
} else if ( strcmp ( " unlink " , argv [ 0 ] ) = = 0 ) {
2009-07-02 20:27:44 +04:00
struct smb_filename * smb_fname = NULL ;
NTSTATUS status ;
status = create_synthetic_smb_fname_split ( mem_ctx , argv [ 1 ] ,
NULL , & smb_fname ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
ret = SMB_VFS_UNLINK ( vfs - > conn , smb_fname ) ;
TALLOC_FREE ( smb_fname ) ;
2002-08-19 20:54:06 +04:00
} else if ( strcmp ( " chdir " , argv [ 0 ] ) = = 0 ) {
2003-05-14 14:59:01 +04:00
ret = SMB_VFS_CHDIR ( vfs - > conn , argv [ 1 ] ) ;
2002-08-19 20:54:06 +04:00
} else {
printf ( " %s: error=%d (invalid function name!) \n " , argv [ 0 ] , errno ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
2002-08-18 22:04:00 +04:00
if ( ret = = - 1 ) {
printf ( " %s: error=%d (%s) \n " , argv [ 0 ] , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " %s: ok \n " , argv [ 0 ] ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_close ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
int fd , ret ;
if ( argc ! = 2 ) {
printf ( " Usage: close <fd> \n " ) ;
return NT_STATUS_OK ;
}
fd = atoi ( argv [ 1 ] ) ;
if ( vfs - > files [ fd ] = = NULL ) {
printf ( " close: error=-1 (invalid file descriptor) \n " ) ;
return NT_STATUS_OK ;
}
2008-01-11 16:19:28 +03:00
ret = SMB_VFS_CLOSE ( vfs - > files [ fd ] ) ;
2002-08-18 22:04:00 +04:00
if ( ret = = - 1 )
printf ( " close: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
else
printf ( " close: ok \n " ) ;
2009-07-11 05:11:32 +04:00
TALLOC_FREE ( vfs - > files [ fd ] - > fsp_name ) ;
2005-07-21 17:45:34 +04:00
SAFE_FREE ( vfs - > files [ fd ] - > fh ) ;
2002-08-18 22:04:00 +04:00
SAFE_FREE ( vfs - > files [ fd ] ) ;
vfs - > files [ fd ] = NULL ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_read ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
int fd ;
size_t size , rsize ;
if ( argc ! = 3 ) {
printf ( " Usage: read <fd> <size> \n " ) ;
return NT_STATUS_OK ;
}
/* do some error checking on these */
fd = atoi ( argv [ 1 ] ) ;
size = atoi ( argv [ 2 ] ) ;
2011-06-07 05:30:12 +04:00
vfs - > data = talloc_array ( mem_ctx , char , size ) ;
2002-08-18 22:04:00 +04:00
if ( vfs - > data = = NULL ) {
printf ( " read: error=-1 (not enough memory) " ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
vfs - > data_size = size ;
2012-02-01 17:42:39 +04:00
2008-01-10 17:33:51 +03:00
rsize = SMB_VFS_READ ( vfs - > files [ fd ] , vfs - > data , size ) ;
2002-08-18 23:22:10 +04:00
if ( rsize = = - 1 ) {
printf ( " read: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
2002-08-18 22:04:00 +04:00
}
printf ( " read: ok \n " ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_write ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
int fd , size , wsize ;
if ( argc ! = 3 ) {
printf ( " Usage: write <fd> <size> \n " ) ;
return NT_STATUS_OK ;
}
/* some error checking should go here */
fd = atoi ( argv [ 1 ] ) ;
size = atoi ( argv [ 2 ] ) ;
if ( vfs - > data = = NULL ) {
printf ( " write: error=-1 (buffer empty, please populate it before writing) " ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
if ( vfs - > data_size < size ) {
printf ( " write: error=-1 (buffer too small, please put some more data in) " ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
2008-01-10 17:49:35 +03:00
wsize = SMB_VFS_WRITE ( vfs - > files [ fd ] , vfs - > data , size ) ;
2002-08-18 22:04:00 +04:00
if ( wsize = = - 1 ) {
printf ( " write: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " write: ok \n " ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_lseek ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
int fd , offset , whence ;
SMB_OFF_T pos ;
if ( argc ! = 4 ) {
printf ( " Usage: lseek <fd> <offset> <whence> \n ...where whence is 1 => SEEK_SET, 2 => SEEK_CUR, 3 => SEEK_END \n " ) ;
return NT_STATUS_OK ;
}
fd = atoi ( argv [ 1 ] ) ;
offset = atoi ( argv [ 2 ] ) ;
whence = atoi ( argv [ 3 ] ) ;
switch ( whence ) {
case 1 : whence = SEEK_SET ; break ;
case 2 : whence = SEEK_CUR ; break ;
default : whence = SEEK_END ;
}
2008-01-07 12:15:08 +03:00
pos = SMB_VFS_LSEEK ( vfs - > files [ fd ] , offset , whence ) ;
2002-08-18 22:04:00 +04:00
if ( pos = = ( SMB_OFF_T ) - 1 ) {
printf ( " lseek: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " lseek: ok \n " ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_rename ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
int ret ;
2009-07-01 04:04:38 +04:00
struct smb_filename * smb_fname_src = NULL ;
struct smb_filename * smb_fname_dst = NULL ;
NTSTATUS status ;
2002-08-18 22:04:00 +04:00
if ( argc ! = 3 ) {
printf ( " Usage: rename <old> <new> \n " ) ;
return NT_STATUS_OK ;
}
2009-07-01 04:04:38 +04:00
status = create_synthetic_smb_fname_split ( mem_ctx , argv [ 1 ] , NULL ,
& smb_fname_src ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
status = create_synthetic_smb_fname_split ( mem_ctx , argv [ 2 ] , NULL ,
& smb_fname_dst ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
TALLOC_FREE ( smb_fname_src ) ;
return status ;
}
ret = SMB_VFS_RENAME ( vfs - > conn , smb_fname_src , smb_fname_dst ) ;
TALLOC_FREE ( smb_fname_src ) ;
TALLOC_FREE ( smb_fname_dst ) ;
2002-08-18 22:04:00 +04:00
if ( ret = = - 1 ) {
printf ( " rename: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " rename: ok \n " ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_fsync ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
int ret , fd ;
if ( argc ! = 2 ) {
printf ( " Usage: fsync <fd> \n " ) ;
return NT_STATUS_OK ;
}
fd = atoi ( argv [ 1 ] ) ;
2008-01-07 14:49:02 +03:00
ret = SMB_VFS_FSYNC ( vfs - > files [ fd ] ) ;
2002-08-18 22:04:00 +04:00
if ( ret = = - 1 ) {
printf ( " fsync: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " fsync: ok \n " ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_stat ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
int ret ;
2003-05-12 03:34:18 +04:00
const char * user ;
const char * group ;
2003-08-28 00:04:23 +04:00
struct passwd * pwd = NULL ;
struct group * grp = NULL ;
2009-06-23 02:26:56 +04:00
struct smb_filename * smb_fname = NULL ;
2002-08-18 22:04:00 +04:00
SMB_STRUCT_STAT st ;
2009-05-14 17:34:42 +04:00
time_t tmp_time ;
2009-06-23 02:26:56 +04:00
NTSTATUS status ;
2002-08-18 22:04:00 +04:00
if ( argc ! = 2 ) {
printf ( " Usage: stat <fname> \n " ) ;
return NT_STATUS_OK ;
}
2009-06-23 02:26:56 +04:00
status = create_synthetic_smb_fname_split ( mem_ctx , argv [ 1 ] , NULL ,
& smb_fname ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
ret = SMB_VFS_STAT ( vfs - > conn , smb_fname ) ;
2002-08-18 22:04:00 +04:00
if ( ret = = - 1 ) {
printf ( " stat: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
2009-06-23 02:26:56 +04:00
TALLOC_FREE ( smb_fname ) ;
2002-08-18 22:04:00 +04:00
return NT_STATUS_UNSUCCESSFUL ;
}
2009-06-23 02:26:56 +04:00
st = smb_fname - > st ;
TALLOC_FREE ( smb_fname ) ;
2002-08-18 22:04:00 +04:00
2012-03-24 18:25:05 +04:00
pwd = getpwuid ( st . st_ex_uid ) ;
2003-05-12 03:34:18 +04:00
if ( pwd ! = NULL ) user = pwd - > pw_name ;
2002-08-18 22:04:00 +04:00
else user = null_string ;
2009-05-14 17:34:42 +04:00
grp = sys_getgrgid ( st . st_ex_gid ) ;
2003-05-12 03:34:18 +04:00
if ( grp ! = NULL ) group = grp - > gr_name ;
2002-08-18 22:04:00 +04:00
else group = null_string ;
printf ( " stat: ok \n " ) ;
printf ( " File: %s " , argv [ 1 ] ) ;
2009-05-14 17:34:42 +04:00
if ( S_ISREG ( st . st_ex_mode ) ) printf ( " Regular File \n " ) ;
else if ( S_ISDIR ( st . st_ex_mode ) ) printf ( " Directory \n " ) ;
else if ( S_ISCHR ( st . st_ex_mode ) ) printf ( " Character Device \n " ) ;
else if ( S_ISBLK ( st . st_ex_mode ) ) printf ( " Block Device \n " ) ;
else if ( S_ISFIFO ( st . st_ex_mode ) ) printf ( " Fifo \n " ) ;
else if ( S_ISLNK ( st . st_ex_mode ) ) printf ( " Symbolic Link \n " ) ;
else if ( S_ISSOCK ( st . st_ex_mode ) ) printf ( " Socket \n " ) ;
printf ( " Size: %10u " , ( unsigned int ) st . st_ex_size ) ;
2003-10-14 07:56:42 +04:00
# ifdef HAVE_STAT_ST_BLOCKS
2009-05-14 17:34:42 +04:00
printf ( " Blocks: %9u " , ( unsigned int ) st . st_ex_blocks ) ;
2003-10-14 07:56:42 +04:00
# endif
# ifdef HAVE_STAT_ST_BLKSIZE
2009-05-14 17:34:42 +04:00
printf ( " IO Block: %u \n " , ( unsigned int ) st . st_ex_blksize ) ;
2003-10-14 07:56:42 +04:00
# endif
2009-05-14 17:34:42 +04:00
printf ( " Device: 0x%10x " , ( unsigned int ) st . st_ex_dev ) ;
printf ( " Inode: %10u " , ( unsigned int ) st . st_ex_ino ) ;
printf ( " Links: %10u \n " , ( unsigned int ) st . st_ex_nlink ) ;
printf ( " Access: %05o " , ( int ) ( ( st . st_ex_mode ) & 007777 ) ) ;
printf ( " Uid: %5lu/%.16s Gid: %5lu/%.16s \n " , ( unsigned long ) st . st_ex_uid , user ,
( unsigned long ) st . st_ex_gid , group ) ;
tmp_time = convert_timespec_to_time_t ( st . st_ex_atime ) ;
printf ( " Access: %s " , ctime ( & tmp_time ) ) ;
tmp_time = convert_timespec_to_time_t ( st . st_ex_mtime ) ;
printf ( " Modify: %s " , ctime ( & tmp_time ) ) ;
tmp_time = convert_timespec_to_time_t ( st . st_ex_ctime ) ;
printf ( " Change: %s " , ctime ( & tmp_time ) ) ;
2003-08-28 00:04:23 +04:00
2002-08-18 22:04:00 +04:00
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_fstat ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
int fd ;
2003-05-12 03:34:18 +04:00
const char * user ;
const char * group ;
2003-08-28 00:04:23 +04:00
struct passwd * pwd = NULL ;
struct group * grp = NULL ;
2002-08-18 22:04:00 +04:00
SMB_STRUCT_STAT st ;
2009-05-14 17:34:42 +04:00
time_t tmp_time ;
2002-08-18 22:04:00 +04:00
if ( argc ! = 2 ) {
printf ( " Usage: fstat <fd> \n " ) ;
return NT_STATUS_OK ;
}
fd = atoi ( argv [ 1 ] ) ;
2008-01-30 21:56:05 +03:00
if ( fd < 0 | | fd > = 1024 ) {
2002-08-18 22:04:00 +04:00
printf ( " fstat: error=%d (file descriptor out of range) \n " , EBADF ) ;
return NT_STATUS_OK ;
}
if ( vfs - > files [ fd ] = = NULL ) {
printf ( " fstat: error=%d (invalid file descriptor) \n " , EBADF ) ;
return NT_STATUS_OK ;
}
2008-01-07 15:21:26 +03:00
if ( SMB_VFS_FSTAT ( vfs - > files [ fd ] , & st ) = = - 1 ) {
2002-08-18 22:04:00 +04:00
printf ( " fstat: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
2012-03-24 18:25:05 +04:00
pwd = getpwuid ( st . st_ex_uid ) ;
2003-05-12 03:34:18 +04:00
if ( pwd ! = NULL ) user = pwd - > pw_name ;
2002-08-18 22:04:00 +04:00
else user = null_string ;
2009-05-14 17:34:42 +04:00
grp = sys_getgrgid ( st . st_ex_gid ) ;
2003-05-12 03:34:18 +04:00
if ( grp ! = NULL ) group = grp - > gr_name ;
2002-08-18 22:04:00 +04:00
else group = null_string ;
printf ( " fstat: ok \n " ) ;
2009-05-14 17:34:42 +04:00
if ( S_ISREG ( st . st_ex_mode ) ) printf ( " Regular File \n " ) ;
else if ( S_ISDIR ( st . st_ex_mode ) ) printf ( " Directory \n " ) ;
else if ( S_ISCHR ( st . st_ex_mode ) ) printf ( " Character Device \n " ) ;
else if ( S_ISBLK ( st . st_ex_mode ) ) printf ( " Block Device \n " ) ;
else if ( S_ISFIFO ( st . st_ex_mode ) ) printf ( " Fifo \n " ) ;
else if ( S_ISLNK ( st . st_ex_mode ) ) printf ( " Symbolic Link \n " ) ;
else if ( S_ISSOCK ( st . st_ex_mode ) ) printf ( " Socket \n " ) ;
printf ( " Size: %10u " , ( unsigned int ) st . st_ex_size ) ;
2003-10-14 07:56:42 +04:00
# ifdef HAVE_STAT_ST_BLOCKS
2009-05-14 17:34:42 +04:00
printf ( " Blocks: %9u " , ( unsigned int ) st . st_ex_blocks ) ;
2003-10-14 07:56:42 +04:00
# endif
# ifdef HAVE_STAT_ST_BLKSIZE
2009-05-14 17:34:42 +04:00
printf ( " IO Block: %u \n " , ( unsigned int ) st . st_ex_blksize ) ;
2003-10-14 07:56:42 +04:00
# endif
2009-05-14 17:34:42 +04:00
printf ( " Device: 0x%10x " , ( unsigned int ) st . st_ex_dev ) ;
printf ( " Inode: %10u " , ( unsigned int ) st . st_ex_ino ) ;
printf ( " Links: %10u \n " , ( unsigned int ) st . st_ex_nlink ) ;
printf ( " Access: %05o " , ( int ) ( ( st . st_ex_mode ) & 007777 ) ) ;
printf ( " Uid: %5lu/%.16s Gid: %5lu/%.16s \n " , ( unsigned long ) st . st_ex_uid , user ,
( unsigned long ) st . st_ex_gid , group ) ;
tmp_time = convert_timespec_to_time_t ( st . st_ex_atime ) ;
printf ( " Access: %s " , ctime ( & tmp_time ) ) ;
tmp_time = convert_timespec_to_time_t ( st . st_ex_mtime ) ;
printf ( " Modify: %s " , ctime ( & tmp_time ) ) ;
tmp_time = convert_timespec_to_time_t ( st . st_ex_ctime ) ;
printf ( " Change: %s " , ctime ( & tmp_time ) ) ;
2003-08-28 00:04:23 +04:00
2002-08-18 22:04:00 +04:00
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_lstat ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
2003-05-12 03:34:18 +04:00
const char * user ;
const char * group ;
2003-08-28 00:04:23 +04:00
struct passwd * pwd = NULL ;
struct group * grp = NULL ;
2009-06-23 02:26:56 +04:00
struct smb_filename * smb_fname = NULL ;
2002-08-18 22:04:00 +04:00
SMB_STRUCT_STAT st ;
2009-05-14 17:34:42 +04:00
time_t tmp_time ;
2009-06-23 02:26:56 +04:00
NTSTATUS status ;
2002-08-18 22:04:00 +04:00
if ( argc ! = 2 ) {
printf ( " Usage: lstat <path> \n " ) ;
return NT_STATUS_OK ;
}
2009-06-23 02:26:56 +04:00
status = create_synthetic_smb_fname_split ( mem_ctx , argv [ 1 ] , NULL ,
& smb_fname ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
if ( SMB_VFS_LSTAT ( vfs - > conn , smb_fname ) = = - 1 ) {
2002-08-18 22:04:00 +04:00
printf ( " lstat: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
2009-06-23 02:26:56 +04:00
TALLOC_FREE ( smb_fname ) ;
2002-08-18 22:04:00 +04:00
return NT_STATUS_UNSUCCESSFUL ;
}
2009-06-23 02:26:56 +04:00
st = smb_fname - > st ;
TALLOC_FREE ( smb_fname ) ;
2002-08-18 22:04:00 +04:00
2012-03-24 18:25:05 +04:00
pwd = getpwuid ( st . st_ex_uid ) ;
2003-05-12 03:34:18 +04:00
if ( pwd ! = NULL ) user = pwd - > pw_name ;
2002-08-18 22:04:00 +04:00
else user = null_string ;
2009-05-14 17:34:42 +04:00
grp = sys_getgrgid ( st . st_ex_gid ) ;
2003-05-12 03:34:18 +04:00
if ( grp ! = NULL ) group = grp - > gr_name ;
2002-08-18 22:04:00 +04:00
else group = null_string ;
printf ( " lstat: ok \n " ) ;
2009-05-14 17:34:42 +04:00
if ( S_ISREG ( st . st_ex_mode ) ) printf ( " Regular File \n " ) ;
else if ( S_ISDIR ( st . st_ex_mode ) ) printf ( " Directory \n " ) ;
else if ( S_ISCHR ( st . st_ex_mode ) ) printf ( " Character Device \n " ) ;
else if ( S_ISBLK ( st . st_ex_mode ) ) printf ( " Block Device \n " ) ;
else if ( S_ISFIFO ( st . st_ex_mode ) ) printf ( " Fifo \n " ) ;
else if ( S_ISLNK ( st . st_ex_mode ) ) printf ( " Symbolic Link \n " ) ;
else if ( S_ISSOCK ( st . st_ex_mode ) ) printf ( " Socket \n " ) ;
printf ( " Size: %10u " , ( unsigned int ) st . st_ex_size ) ;
2003-10-14 07:56:42 +04:00
# ifdef HAVE_STAT_ST_BLOCKS
2009-05-14 17:34:42 +04:00
printf ( " Blocks: %9u " , ( unsigned int ) st . st_ex_blocks ) ;
2003-10-14 07:56:42 +04:00
# endif
# ifdef HAVE_STAT_ST_BLKSIZE
2009-05-14 17:34:42 +04:00
printf ( " IO Block: %u \n " , ( unsigned int ) st . st_ex_blksize ) ;
2003-10-14 07:56:42 +04:00
# endif
2009-05-14 17:34:42 +04:00
printf ( " Device: 0x%10x " , ( unsigned int ) st . st_ex_dev ) ;
printf ( " Inode: %10u " , ( unsigned int ) st . st_ex_ino ) ;
printf ( " Links: %10u \n " , ( unsigned int ) st . st_ex_nlink ) ;
printf ( " Access: %05o " , ( int ) ( ( st . st_ex_mode ) & 007777 ) ) ;
printf ( " Uid: %5lu/%.16s Gid: %5lu/%.16s \n " , ( unsigned long ) st . st_ex_uid , user ,
( unsigned long ) st . st_ex_gid , group ) ;
tmp_time = convert_timespec_to_time_t ( st . st_ex_atime ) ;
printf ( " Access: %s " , ctime ( & tmp_time ) ) ;
tmp_time = convert_timespec_to_time_t ( st . st_ex_mtime ) ;
printf ( " Modify: %s " , ctime ( & tmp_time ) ) ;
tmp_time = convert_timespec_to_time_t ( st . st_ex_ctime ) ;
printf ( " Change: %s " , ctime ( & tmp_time ) ) ;
2012-02-01 17:42:39 +04:00
2002-08-18 22:04:00 +04:00
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_chmod ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
mode_t mode ;
if ( argc ! = 3 ) {
printf ( " Usage: chmod <path> <mode> \n " ) ;
return NT_STATUS_OK ;
}
mode = atoi ( argv [ 2 ] ) ;
2003-05-14 14:59:01 +04:00
if ( SMB_VFS_CHMOD ( vfs - > conn , argv [ 1 ] , mode ) = = - 1 ) {
2002-08-18 22:04:00 +04:00
printf ( " chmod: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " chmod: ok \n " ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_fchmod ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
int fd ;
mode_t mode ;
if ( argc ! = 3 ) {
printf ( " Usage: fchmod <fd> <mode> \n " ) ;
return NT_STATUS_OK ;
}
fd = atoi ( argv [ 1 ] ) ;
mode = atoi ( argv [ 2 ] ) ;
2008-01-30 21:56:05 +03:00
if ( fd < 0 | | fd > = 1024 ) {
2002-08-18 22:04:00 +04:00
printf ( " fchmod: error=%d (file descriptor out of range) \n " , EBADF ) ;
return NT_STATUS_OK ;
}
if ( vfs - > files [ fd ] = = NULL ) {
printf ( " fchmod: error=%d (invalid file descriptor) \n " , EBADF ) ;
return NT_STATUS_OK ;
}
2008-01-07 15:44:37 +03:00
if ( SMB_VFS_FCHMOD ( vfs - > files [ fd ] , mode ) = = - 1 ) {
2002-08-18 22:04:00 +04:00
printf ( " fchmod: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " fchmod: ok \n " ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_chown ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
uid_t uid ;
gid_t gid ;
if ( argc ! = 4 ) {
printf ( " Usage: chown <path> <uid> <gid> \n " ) ;
return NT_STATUS_OK ;
}
uid = atoi ( argv [ 2 ] ) ;
gid = atoi ( argv [ 3 ] ) ;
2003-05-14 14:59:01 +04:00
if ( SMB_VFS_CHOWN ( vfs - > conn , argv [ 1 ] , uid , gid ) = = - 1 ) {
2002-08-18 22:04:00 +04:00
printf ( " chown: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " chown: ok \n " ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_fchown ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
uid_t uid ;
gid_t gid ;
int fd ;
if ( argc ! = 4 ) {
printf ( " Usage: fchown <fd> <uid> <gid> \n " ) ;
return NT_STATUS_OK ;
}
uid = atoi ( argv [ 2 ] ) ;
gid = atoi ( argv [ 3 ] ) ;
fd = atoi ( argv [ 1 ] ) ;
2008-01-30 21:56:05 +03:00
if ( fd < 0 | | fd > = 1024 ) {
2002-08-18 22:04:00 +04:00
printf ( " fchown: faliure=%d (file descriptor out of range) \n " , EBADF ) ;
return NT_STATUS_OK ;
}
if ( vfs - > files [ fd ] = = NULL ) {
printf ( " fchown: error=%d (invalid file descriptor) \n " , EBADF ) ;
return NT_STATUS_OK ;
}
2008-01-07 16:26:00 +03:00
if ( SMB_VFS_FCHOWN ( vfs - > files [ fd ] , uid , gid ) = = - 1 ) {
2002-08-18 22:04:00 +04:00
printf ( " fchown error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " fchown: ok \n " ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_getwd ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
2011-06-01 03:36:06 +04:00
char * buf = SMB_VFS_GETWD ( vfs - > conn ) ;
if ( buf = = NULL ) {
2002-08-18 22:04:00 +04:00
printf ( " getwd: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " getwd: %s \n " , buf ) ;
2011-06-01 03:36:06 +04:00
SAFE_FREE ( buf ) ;
2002-08-18 22:04:00 +04:00
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_utime ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
2009-01-24 01:40:19 +03:00
struct smb_file_time ft ;
2009-07-03 00:39:20 +04:00
struct smb_filename * smb_fname = NULL ;
NTSTATUS status ;
2002-08-18 22:04:00 +04:00
if ( argc ! = 4 ) {
printf ( " Usage: utime <path> <access> <modify> \n " ) ;
return NT_STATUS_OK ;
}
2009-01-24 01:40:19 +03:00
ZERO_STRUCT ( ft ) ;
ft . atime = convert_time_t_to_timespec ( atoi ( argv [ 2 ] ) ) ;
ft . mtime = convert_time_t_to_timespec ( atoi ( argv [ 3 ] ) ) ;
2009-07-03 00:39:20 +04:00
status = create_synthetic_smb_fname_split ( mem_ctx , argv [ 1 ] ,
NULL , & smb_fname ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
if ( SMB_VFS_NTIMES ( vfs - > conn , smb_fname , & ft ) ! = 0 ) {
2002-08-18 22:04:00 +04:00
printf ( " utime: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
2009-07-03 00:39:20 +04:00
TALLOC_FREE ( smb_fname ) ;
2002-08-18 22:04:00 +04:00
return NT_STATUS_UNSUCCESSFUL ;
}
2009-07-03 00:39:20 +04:00
TALLOC_FREE ( smb_fname ) ;
2002-08-18 22:04:00 +04:00
printf ( " utime: ok \n " ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_ftruncate ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
int fd ;
SMB_OFF_T off ;
if ( argc ! = 3 ) {
printf ( " Usage: ftruncate <fd> <length> \n " ) ;
return NT_STATUS_OK ;
}
fd = atoi ( argv [ 1 ] ) ;
off = atoi ( argv [ 2 ] ) ;
2008-01-30 21:56:05 +03:00
if ( fd < 0 | | fd > = 1024 ) {
2002-08-18 22:04:00 +04:00
printf ( " ftruncate: error=%d (file descriptor out of range) \n " , EBADF ) ;
return NT_STATUS_OK ;
}
if ( vfs - > files [ fd ] = = NULL ) {
printf ( " ftruncate: error=%d (invalid file descriptor) \n " , EBADF ) ;
return NT_STATUS_OK ;
}
2008-01-07 17:55:09 +03:00
if ( SMB_VFS_FTRUNCATE ( vfs - > files [ fd ] , off ) = = - 1 ) {
2002-08-18 22:04:00 +04:00
printf ( " ftruncate: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " ftruncate: ok \n " ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_lock ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
2002-08-21 06:34:49 +04:00
int fd ;
int op ;
long offset ;
long count ;
int type ;
2003-05-12 03:34:18 +04:00
const char * typestr ;
2012-02-01 17:42:39 +04:00
2002-08-21 06:34:49 +04:00
if ( argc ! = 6 ) {
printf ( " Usage: lock <fd> <op> <offset> <count> <type> \n " ) ;
printf ( " ops: G = F_GETLK \n " ) ;
printf ( " S = F_SETLK \n " ) ;
printf ( " W = F_SETLKW \n " ) ;
printf ( " type: R = F_RDLCK \n " ) ;
printf ( " W = F_WRLCK \n " ) ;
printf ( " U = F_UNLCK \n " ) ;
return NT_STATUS_OK ;
}
if ( sscanf ( argv [ 1 ] , " %d " , & fd ) = = 0 ) {
printf ( " lock: error=-1 (error parsing fd) \n " ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
op = 0 ;
switch ( * argv [ 2 ] ) {
case ' G ' :
op = F_GETLK ;
break ;
case ' S ' :
op = F_SETLK ;
break ;
case ' W ' :
op = F_SETLKW ;
break ;
default :
printf ( " lock: error=-1 (invalid op flag!) \n " ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
if ( sscanf ( argv [ 3 ] , " %ld " , & offset ) = = 0 ) {
printf ( " lock: error=-1 (error parsing fd) \n " ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
if ( sscanf ( argv [ 4 ] , " %ld " , & count ) = = 0 ) {
printf ( " lock: error=-1 (error parsing fd) \n " ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
type = 0 ;
typestr = argv [ 5 ] ;
while ( * typestr ) {
switch ( * typestr ) {
case ' R ' :
type | = F_RDLCK ;
break ;
case ' W ' :
type | = F_WRLCK ;
break ;
case ' U ' :
type | = F_UNLCK ;
break ;
default :
printf ( " lock: error=-1 (invalid type flag!) \n " ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
typestr + + ;
}
printf ( " lock: debug lock(fd=%d, op=%d, offset=%ld, count=%ld, type=%d)) \n " , fd , op , offset , count , type ) ;
2008-02-28 13:31:20 +03:00
if ( SMB_VFS_LOCK ( vfs - > files [ fd ] , op , offset , count , type ) = = False ) {
2002-08-21 06:34:49 +04:00
printf ( " lock: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " lock: ok \n " ) ;
2002-08-18 22:04:00 +04:00
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_symlink ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
if ( argc ! = 3 ) {
printf ( " Usage: symlink <path> <link> \n " ) ;
return NT_STATUS_OK ;
}
2003-05-14 14:59:01 +04:00
if ( SMB_VFS_SYMLINK ( vfs - > conn , argv [ 1 ] , argv [ 2 ] ) = = - 1 ) {
2002-08-18 22:04:00 +04:00
printf ( " symlink: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " symlink: ok \n " ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_readlink ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
char buffer [ PATH_MAX ] ;
int size ;
if ( argc ! = 2 ) {
printf ( " Usage: readlink <path> \n " ) ;
return NT_STATUS_OK ;
}
2003-05-14 14:59:01 +04:00
if ( ( size = SMB_VFS_READLINK ( vfs - > conn , argv [ 1 ] , buffer , PATH_MAX ) ) = = - 1 ) {
2002-08-18 22:04:00 +04:00
printf ( " readlink: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
buffer [ size ] = ' \0 ' ;
printf ( " readlink: %s \n " , buffer ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_link ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
if ( argc ! = 3 ) {
printf ( " Usage: link <path> <link> \n " ) ;
return NT_STATUS_OK ;
}
2003-05-14 14:59:01 +04:00
if ( SMB_VFS_LINK ( vfs - > conn , argv [ 1 ] , argv [ 2 ] ) = = - 1 ) {
2002-08-18 22:04:00 +04:00
printf ( " link: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " link: ok \n " ) ;
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_mknod ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
2002-08-21 06:34:49 +04:00
mode_t mode ;
2002-11-23 05:58:31 +03:00
unsigned int dev_val ;
2002-08-21 06:34:49 +04:00
SMB_DEV_T dev ;
2012-02-01 17:42:39 +04:00
2002-08-21 06:34:49 +04:00
if ( argc ! = 4 ) {
printf ( " Usage: mknod <path> <mode> <dev> \n " ) ;
printf ( " mode is octal \n " ) ;
printf ( " dev is hex \n " ) ;
return NT_STATUS_OK ;
}
2008-09-16 02:47:43 +04:00
if ( sscanf ( argv [ 2 ] , " %ho " , ( unsigned short * ) & mode ) = = 0 ) {
2002-08-21 06:34:49 +04:00
printf ( " open: error=-1 (invalid mode!) \n " ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
2002-11-23 05:58:31 +03:00
if ( sscanf ( argv [ 3 ] , " %x " , & dev_val ) = = 0 ) {
2002-08-21 06:34:49 +04:00
printf ( " open: error=-1 (invalid dev!) \n " ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
2002-11-23 05:58:31 +03:00
dev = ( SMB_DEV_T ) dev_val ;
2002-08-21 06:34:49 +04:00
2003-05-14 14:59:01 +04:00
if ( SMB_VFS_MKNOD ( vfs - > conn , argv [ 1 ] , mode , dev ) = = - 1 ) {
2002-08-21 06:34:49 +04:00
printf ( " mknod: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " mknod: ok \n " ) ;
2002-08-18 22:04:00 +04:00
return NT_STATUS_OK ;
}
2003-05-12 03:34:18 +04:00
static NTSTATUS cmd_realpath ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx , int argc , const char * * argv )
2002-08-18 22:04:00 +04:00
{
if ( argc ! = 2 ) {
printf ( " Usage: realpath <path> \n " ) ;
return NT_STATUS_OK ;
}
2010-11-20 03:29:26 +03:00
if ( SMB_VFS_REALPATH ( vfs - > conn , argv [ 1 ] ) = = NULL ) {
2002-08-18 22:04:00 +04:00
printf ( " realpath: error=%d (%s) \n " , errno , strerror ( errno ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
printf ( " realpath: ok \n " ) ;
return NT_STATUS_OK ;
}
2012-02-02 19:36:18 +04:00
static NTSTATUS cmd_getxattr ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
uint8_t * buf ;
ssize_t ret ;
if ( argc ! = 3 ) {
printf ( " Usage: getxattr <path> <xattr> \n " ) ;
return NT_STATUS_OK ;
}
buf = NULL ;
ret = SMB_VFS_GETXATTR ( vfs - > conn , argv [ 1 ] , argv [ 2 ] , buf ,
talloc_get_size ( buf ) ) ;
if ( ret = = - 1 ) {
int err = errno ;
printf ( " getxattr returned (%s) \n " , strerror ( err ) ) ;
return map_nt_error_from_unix ( err ) ;
}
buf = talloc_array ( mem_ctx , uint8_t , ret ) ;
if ( buf = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
ret = SMB_VFS_GETXATTR ( vfs - > conn , argv [ 1 ] , argv [ 2 ] , buf ,
talloc_get_size ( buf ) ) ;
if ( ret = = - 1 ) {
int err = errno ;
printf ( " getxattr returned (%s) \n " , strerror ( err ) ) ;
return map_nt_error_from_unix ( err ) ;
}
dump_data_file ( buf , talloc_get_size ( buf ) , false , stdout ) ;
return NT_STATUS_OK ;
}
2012-02-02 20:45:09 +04:00
static NTSTATUS cmd_listxattr ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
char * buf , * p ;
ssize_t ret ;
if ( argc ! = 2 ) {
printf ( " Usage: listxattr <path> \n " ) ;
return NT_STATUS_OK ;
}
buf = NULL ;
ret = SMB_VFS_LISTXATTR ( vfs - > conn , argv [ 1 ] , buf , talloc_get_size ( buf ) ) ;
if ( ret = = - 1 ) {
int err = errno ;
printf ( " listxattr returned (%s) \n " , strerror ( err ) ) ;
return map_nt_error_from_unix ( err ) ;
}
buf = talloc_array ( mem_ctx , char , ret ) ;
if ( buf = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
ret = SMB_VFS_LISTXATTR ( vfs - > conn , argv [ 1 ] , buf , talloc_get_size ( buf ) ) ;
if ( ret = = - 1 ) {
int err = errno ;
printf ( " listxattr returned (%s) \n " , strerror ( err ) ) ;
return map_nt_error_from_unix ( err ) ;
}
if ( ret = = 0 ) {
return NT_STATUS_OK ;
}
if ( buf [ ret - 1 ] ! = ' \0 ' ) {
printf ( " listxattr returned non 0-terminated strings \n " ) ;
return NT_STATUS_INTERNAL_ERROR ;
}
p = buf ;
while ( p < buf + ret ) {
printf ( " %s \n " , p ) ;
p = strchr ( p , 0 ) ;
p + = 1 ;
}
return NT_STATUS_OK ;
}
2012-02-02 22:36:00 +04:00
static NTSTATUS cmd_setxattr ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
ssize_t ret ;
int flags = 0 ;
if ( ( argc < 4 ) | | ( argc > 5 ) ) {
printf ( " Usage: setxattr <path> <xattr> <value> [flags] \n " ) ;
return NT_STATUS_OK ;
}
if ( argc = = 5 ) {
flags = atoi ( argv [ 4 ] ) ;
}
ret = SMB_VFS_SETXATTR ( vfs - > conn , argv [ 1 ] , argv [ 2 ] ,
argv [ 3 ] , strlen ( argv [ 3 ] ) , flags ) ;
if ( ret = = - 1 ) {
int err = errno ;
printf ( " setxattr returned (%s) \n " , strerror ( err ) ) ;
return map_nt_error_from_unix ( err ) ;
}
return NT_STATUS_OK ;
}
2012-02-02 22:41:56 +04:00
static NTSTATUS cmd_removexattr ( struct vfs_state * vfs , TALLOC_CTX * mem_ctx ,
int argc , const char * * argv )
{
ssize_t ret ;
if ( argc ! = 3 ) {
printf ( " Usage: removexattr <path> <xattr> \n " ) ;
return NT_STATUS_OK ;
}
ret = SMB_VFS_REMOVEXATTR ( vfs - > conn , argv [ 1 ] , argv [ 2 ] ) ;
if ( ret = = - 1 ) {
int err = errno ;
printf ( " removexattr returned (%s) \n " , strerror ( err ) ) ;
return map_nt_error_from_unix ( err ) ;
}
return NT_STATUS_OK ;
}
2002-08-18 22:04:00 +04:00
struct cmd_set vfs_commands [ ] = {
{ " VFS Commands " } ,
{ " load " , cmd_load_module , " Load a module " , " load <module.so> " } ,
{ " populate " , cmd_populate , " Populate a data buffer " , " populate <char> <size> " } ,
{ " showdata " , cmd_show_data , " Show data currently in data buffer " , " show_data [<offset> <len>] " } ,
{ " connect " , cmd_connect , " VFS connect() " , " connect " } ,
{ " disconnect " , cmd_disconnect , " VFS disconnect() " , " disconnect " } ,
{ " disk_free " , cmd_disk_free , " VFS disk_free() " , " disk_free <path> " } ,
{ " opendir " , cmd_opendir , " VFS opendir() " , " opendir <fname> " } ,
{ " readdir " , cmd_readdir , " VFS readdir() " , " readdir " } ,
{ " mkdir " , cmd_mkdir , " VFS mkdir() " , " mkdir <path> " } ,
{ " rmdir " , cmd_pathfunc , " VFS rmdir() " , " rmdir <path> " } ,
{ " closedir " , cmd_closedir , " VFS closedir() " , " closedir " } ,
{ " open " , cmd_open , " VFS open() " , " open <fname> " } ,
{ " close " , cmd_close , " VFS close() " , " close <fd> " } ,
{ " read " , cmd_read , " VFS read() " , " read <fd> <size> " } ,
{ " write " , cmd_write , " VFS write() " , " write <fd> <size> " } ,
{ " lseek " , cmd_lseek , " VFS lseek() " , " lseek <fd> <offset> <whence> " } ,
{ " rename " , cmd_rename , " VFS rename() " , " rename <old> <new> " } ,
{ " fsync " , cmd_fsync , " VFS fsync() " , " fsync <fd> " } ,
{ " stat " , cmd_stat , " VFS stat() " , " stat <fname> " } ,
{ " fstat " , cmd_fstat , " VFS fstat() " , " fstat <fd> " } ,
{ " lstat " , cmd_lstat , " VFS lstat() " , " lstat <fname> " } ,
{ " unlink " , cmd_pathfunc , " VFS unlink() " , " unlink <fname> " } ,
{ " chmod " , cmd_chmod , " VFS chmod() " , " chmod <path> <mode> " } ,
{ " fchmod " , cmd_fchmod , " VFS fchmod() " , " fchmod <fd> <mode> " } ,
{ " chown " , cmd_chown , " VFS chown() " , " chown <path> <uid> <gid> " } ,
{ " fchown " , cmd_fchown , " VFS fchown() " , " fchown <fd> <uid> <gid> " } ,
{ " chdir " , cmd_pathfunc , " VFS chdir() " , " chdir <path> " } ,
{ " getwd " , cmd_getwd , " VFS getwd() " , " getwd " } ,
{ " utime " , cmd_utime , " VFS utime() " , " utime <path> <access> <modify> " } ,
{ " ftruncate " , cmd_ftruncate , " VFS ftruncate() " , " ftruncate <fd> <length> " } ,
2002-08-21 06:34:49 +04:00
{ " lock " , cmd_lock , " VFS lock() " , " lock <f> <op> <offset> <count> <type> " } ,
2002-08-18 22:04:00 +04:00
{ " symlink " , cmd_symlink , " VFS symlink() " , " symlink <old> <new> " } ,
{ " readlink " , cmd_readlink , " VFS readlink() " , " readlink <path> " } ,
{ " link " , cmd_link , " VFS link() " , " link <oldpath> <newpath> " } ,
2002-08-21 06:34:49 +04:00
{ " mknod " , cmd_mknod , " VFS mknod() " , " mknod <path> <mode> <dev> " } ,
2002-08-18 22:04:00 +04:00
{ " realpath " , cmd_realpath , " VFS realpath() " , " realpath <path> " } ,
2012-02-02 19:36:18 +04:00
{ " getxattr " , cmd_getxattr , " VFS getxattr() " ,
" getxattr <path> <name> " } ,
2012-02-02 20:45:09 +04:00
{ " listxattr " , cmd_listxattr , " VFS listxattr() " ,
" listxattr <path> " } ,
2012-02-02 22:36:00 +04:00
{ " setxattr " , cmd_setxattr , " VFS setxattr() " ,
" setxattr <path> <name> <value> [<flags>] " } ,
2012-02-02 22:41:56 +04:00
{ " removexattr " , cmd_removexattr , " VFS removexattr() " ,
" removexattr <path> <name> \n " } ,
2012-02-28 03:19:48 +04:00
{ " test_chain " , cmd_test_chain , " test chain code " ,
" test_chain " } ,
2002-08-18 22:04:00 +04:00
{ NULL }
} ;