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
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
printf("show_data: error=-1 (not enough data in buffer)\n");
return NT_STATUS_UNSUCCESSFUL;
}
- dump_data(0, (char *)(vfs->data) + offset, len);
+ dump_data(0, (uint8 *)(vfs->data) + offset, len);
return NT_STATUS_OK;
}
static NTSTATUS cmd_disk_free(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
{
- SMB_BIG_UINT diskfree, bsize, dfree, dsize;
+ uint64_t diskfree, bsize, dfree, dsize;
if (argc != 2) {
printf("Usage: disk_free <path>\n");
return NT_STATUS_OK;
static NTSTATUS cmd_readdir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
{
- SMB_STRUCT_DIRENT *dent;
+ SMB_STRUCT_STAT st;
+ SMB_STRUCT_DIRENT *dent = NULL;
if (vfs->currentdir == NULL) {
printf("readdir: error=-1 (no open directory)\n");
return NT_STATUS_UNSUCCESSFUL;
}
- dent = SMB_VFS_READDIR(vfs->conn, vfs->currentdir);
+ dent = SMB_VFS_READDIR(vfs->conn, vfs->currentdir, &st);
if (dent == NULL) {
printf("readdir: NULL\n");
return NT_STATUS_OK;
}
printf("readdir: %s\n", dent->d_name);
+ if (VALID_STAT(st)) {
+ printf(" stat available");
+ if (S_ISREG(st.st_mode)) printf(" Regular File\n");
+ else if (S_ISDIR(st.st_mode)) printf(" Directory\n");
+ else if (S_ISCHR(st.st_mode)) printf(" Character Device\n");
+ else if (S_ISBLK(st.st_mode)) printf(" Block Device\n");
+ else if (S_ISFIFO(st.st_mode)) printf(" Fifo\n");
+ else if (S_ISLNK(st.st_mode)) printf(" Symbolic Link\n");
+ else if (S_ISSOCK(st.st_mode)) printf(" Socket\n");
+ printf(" Size: %10u", (unsigned int)st.st_size);
+#ifdef HAVE_STAT_ST_BLOCKS
+ printf(" Blocks: %9u", (unsigned int)st.st_blocks);
+#endif
+#ifdef HAVE_STAT_ST_BLKSIZE
+ printf(" IO Block: %u\n", (unsigned int)st.st_blksize);
+#endif
+ printf(" Device: 0x%10x", (unsigned int)st.st_dev);
+ printf(" Inode: %10u", (unsigned int)st.st_ino);
+ printf(" Links: %10u\n", (unsigned int)st.st_nlink);
+ printf(" Access: %05o", (int)((st.st_mode) & 007777));
+ printf(" Uid: %5lu Gid: %5lu\n",
+ (unsigned long)st.st_uid,
+ (unsigned long)st.st_gid);
+ printf(" Access: %s", ctime(&(st.st_atime)));
+ printf(" Modify: %s", ctime(&(st.st_mtime)));
+ printf(" Change: %s", ctime(&(st.st_ctime)));
+ }
+
return NT_STATUS_OK;
}
flagstr++;
}
if ((flags & O_CREAT) && argc == 4) {
- if (sscanf(argv[3], "%o", &mode) == 0) {
+ if (sscanf(argv[3], "%ho", (unsigned short *)&mode) == 0) {
printf("open: error=-1 (invalid mode!)\n");
return NT_STATUS_UNSUCCESSFUL;
}
}
fsp = SMB_MALLOC_P(struct files_struct);
+ if (fsp == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
fsp->fsp_name = SMB_STRDUP(argv[1]);
+ if (fsp->fsp_name == NULL) {
+ SAFE_FREE(fsp);
+ return NT_STATUS_NO_MEMORY;
+ }
fsp->fh = SMB_MALLOC_P(struct fd_handle);
+ if (fsp->fh == NULL) {
+ SAFE_FREE(fsp->fsp_name);
+ SAFE_FREE(fsp);
+ return NT_STATUS_NO_MEMORY;
+ }
fsp->conn = vfs->conn;
fsp->fh->fd = SMB_VFS_OPEN(vfs->conn, argv[1], fsp, flags, mode);
if (fsp->fh->fd == -1) {
printf("open: error=%d (%s)\n", errno, strerror(errno));
SAFE_FREE(fsp->fh);
+ SAFE_FREE(fsp->fsp_name);
SAFE_FREE(fsp);
return NT_STATUS_UNSUCCESSFUL;
}
return NT_STATUS_OK;
}
- ret = SMB_VFS_CLOSE(vfs->files[fd], fd);
+ ret = SMB_VFS_CLOSE(vfs->files[fd]);
if (ret == -1 )
printf("close: error=%d (%s)\n", errno, strerror(errno));
else
}
vfs->data_size = size;
- rsize = SMB_VFS_READ(vfs->files[fd], fd, vfs->data, size);
+ rsize = SMB_VFS_READ(vfs->files[fd], vfs->data, size);
if (rsize == -1) {
printf("read: error=%d (%s)\n", errno, strerror(errno));
return NT_STATUS_UNSUCCESSFUL;
return NT_STATUS_UNSUCCESSFUL;
}
- wsize = SMB_VFS_WRITE(vfs->files[fd], fd, vfs->data, size);
+ wsize = SMB_VFS_WRITE(vfs->files[fd], vfs->data, size);
if (wsize == -1) {
printf("write: error=%d (%s)\n", errno, strerror(errno));
default: whence = SEEK_END;
}
- pos = SMB_VFS_LSEEK(vfs->files[fd], fd, offset, whence);
+ pos = SMB_VFS_LSEEK(vfs->files[fd], offset, whence);
if (pos == (SMB_OFF_T)-1) {
printf("lseek: error=%d (%s)\n", errno, strerror(errno));
return NT_STATUS_UNSUCCESSFUL;
}
fd = atoi(argv[1]);
- ret = SMB_VFS_FSYNC(vfs->files[fd], fd);
+ ret = SMB_VFS_FSYNC(vfs->files[fd]);
if (ret == -1) {
printf("fsync: error=%d (%s)\n", errno, strerror(errno));
return NT_STATUS_UNSUCCESSFUL;
printf(" Device: 0x%10x", (unsigned int)st.st_dev);
printf(" Inode: %10u", (unsigned int)st.st_ino);
printf(" Links: %10u\n", (unsigned int)st.st_nlink);
- printf(" Access: %05o", (st.st_mode) & 007777);
+ printf(" Access: %05o", (int)((st.st_mode) & 007777));
printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st.st_uid, user,
(unsigned long)st.st_gid, group);
printf(" Access: %s", ctime(&(st.st_atime)));
}
fd = atoi(argv[1]);
- if (fd < 0 || fd > 1024) {
+ if (fd < 0 || fd >= 1024) {
printf("fstat: error=%d (file descriptor out of range)\n", EBADF);
return NT_STATUS_OK;
}
return NT_STATUS_OK;
}
- if (SMB_VFS_FSTAT(vfs->files[fd], fd, &st) == -1) {
+ if (SMB_VFS_FSTAT(vfs->files[fd], &st) == -1) {
printf("fstat: error=%d (%s)\n", errno, strerror(errno));
return NT_STATUS_UNSUCCESSFUL;
}
printf(" Device: 0x%10x", (unsigned int)st.st_dev);
printf(" Inode: %10u", (unsigned int)st.st_ino);
printf(" Links: %10u\n", (unsigned int)st.st_nlink);
- printf(" Access: %05o", (st.st_mode) & 007777);
+ printf(" Access: %05o", (int)((st.st_mode) & 007777));
printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st.st_uid, user,
(unsigned long)st.st_gid, group);
printf(" Access: %s", ctime(&(st.st_atime)));
printf(" Device: 0x%10x", (unsigned int)st.st_dev);
printf(" Inode: %10u", (unsigned int)st.st_ino);
printf(" Links: %10u\n", (unsigned int)st.st_nlink);
- printf(" Access: %05o", (st.st_mode) & 007777);
+ printf(" Access: %05o", (int)((st.st_mode) & 007777));
printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st.st_uid, user,
(unsigned long)st.st_gid, group);
printf(" Access: %s", ctime(&(st.st_atime)));
fd = atoi(argv[1]);
mode = atoi(argv[2]);
- if (fd < 0 || fd > 1024) {
+ if (fd < 0 || fd >= 1024) {
printf("fchmod: error=%d (file descriptor out of range)\n", EBADF);
return NT_STATUS_OK;
}
return NT_STATUS_OK;
}
- if (SMB_VFS_FCHMOD(vfs->files[fd], fd, mode) == -1) {
+ if (SMB_VFS_FCHMOD(vfs->files[fd], mode) == -1) {
printf("fchmod: error=%d (%s)\n", errno, strerror(errno));
return NT_STATUS_UNSUCCESSFUL;
}
uid = atoi(argv[2]);
gid = atoi(argv[3]);
fd = atoi(argv[1]);
- if (fd < 0 || fd > 1024) {
+ if (fd < 0 || fd >= 1024) {
printf("fchown: faliure=%d (file descriptor out of range)\n", EBADF);
return NT_STATUS_OK;
}
printf("fchown: error=%d (invalid file descriptor)\n", EBADF);
return NT_STATUS_OK;
}
- if (SMB_VFS_FCHOWN(vfs->files[fd], fd, uid, gid) == -1) {
+ if (SMB_VFS_FCHOWN(vfs->files[fd], uid, gid) == -1) {
printf("fchown error=%d (%s)\n", errno, strerror(errno));
return NT_STATUS_UNSUCCESSFUL;
}
static NTSTATUS cmd_utime(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
{
- struct utimbuf times;
+ struct smb_file_time ft;
if (argc != 4) {
printf("Usage: utime <path> <access> <modify>\n");
return NT_STATUS_OK;
}
- times.actime = atoi(argv[2]);
- times.modtime = atoi(argv[3]);
- if (SMB_VFS_UTIME(vfs->conn, argv[1], ×) != 0) {
+
+ ZERO_STRUCT(ft);
+
+ ft.atime = convert_time_t_to_timespec(atoi(argv[2]));
+ ft.mtime = convert_time_t_to_timespec(atoi(argv[3]));
+ if (SMB_VFS_NTIMES(vfs->conn, argv[1], &ft) != 0) {
printf("utime: error=%d (%s)\n", errno, strerror(errno));
return NT_STATUS_UNSUCCESSFUL;
}
fd = atoi(argv[1]);
off = atoi(argv[2]);
- if (fd < 0 || fd > 1024) {
+ if (fd < 0 || fd >= 1024) {
printf("ftruncate: error=%d (file descriptor out of range)\n", EBADF);
return NT_STATUS_OK;
}
return NT_STATUS_OK;
}
- if (SMB_VFS_FTRUNCATE(vfs->files[fd], fd, off) == -1) {
+ if (SMB_VFS_FTRUNCATE(vfs->files[fd], off) == -1) {
printf("ftruncate: error=%d (%s)\n", errno, strerror(errno));
return NT_STATUS_UNSUCCESSFUL;
}
static NTSTATUS cmd_lock(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
{
- BOOL ret;
int fd;
int op;
long offset;
printf("lock: debug lock(fd=%d, op=%d, offset=%ld, count=%ld, type=%d))\n", fd, op, offset, count, type);
- if ((ret = SMB_VFS_LOCK(vfs->files[fd], fd, op, offset, count, type)) == False) {
+ if (SMB_VFS_LOCK(vfs->files[fd], op, offset, count, type) == False) {
printf("lock: error=%d (%s)\n", errno, strerror(errno));
return NT_STATUS_UNSUCCESSFUL;
}
return NT_STATUS_OK;
}
- if (sscanf(argv[2], "%o", &mode) == 0) {
+ if (sscanf(argv[2], "%ho", (unsigned short *)&mode) == 0) {
printf("open: error=-1 (invalid mode!)\n");
return NT_STATUS_UNSUCCESSFUL;
}