Fix a bunch of compiler warnings about wrong format types.
[ira/wip.git] / source3 / torture / cmd_vfs.c
index 6cecd693f835497d5a857af6edd69d1cb753194b..80ee3ec0e8fb7f3ce700de958b853f638bf04aee 100644 (file)
@@ -7,7 +7,7 @@
 
    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,
@@ -16,8 +16,7 @@
    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"
@@ -88,7 +87,7 @@ static NTSTATUS cmd_show_data(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int ar
                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;
 }
 
@@ -106,7 +105,7 @@ static NTSTATUS cmd_disconnect(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int a
 
 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;
@@ -142,20 +141,49 @@ static NTSTATUS cmd_opendir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc
 
 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;
 }
 
@@ -273,21 +301,34 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
                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;
        }
@@ -343,7 +384,7 @@ static NTSTATUS cmd_close(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
                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
@@ -377,7 +418,7 @@ static NTSTATUS cmd_read(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
        }
        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;
@@ -410,7 +451,7 @@ static NTSTATUS cmd_write(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
                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));
@@ -441,7 +482,7 @@ static NTSTATUS cmd_lseek(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
                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;
@@ -480,7 +521,7 @@ static NTSTATUS cmd_fsync(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
        }
 
        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;
@@ -537,7 +578,7 @@ static NTSTATUS cmd_stat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
        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)));
@@ -563,7 +604,7 @@ static NTSTATUS cmd_fstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
        }
 
        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;
        }
@@ -573,7 +614,7 @@ static NTSTATUS cmd_fstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
                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;
        }
@@ -603,7 +644,7 @@ static NTSTATUS cmd_fstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
        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)));
@@ -657,7 +698,7 @@ static NTSTATUS cmd_lstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
        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)));
@@ -698,7 +739,7 @@ static NTSTATUS cmd_fchmod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
 
        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;
        }
@@ -707,7 +748,7 @@ static NTSTATUS cmd_fchmod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
                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;
        }
@@ -751,7 +792,7 @@ static NTSTATUS cmd_fchown(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
        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;
        }
@@ -759,7 +800,7 @@ static NTSTATUS cmd_fchown(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
                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;
        }
@@ -783,14 +824,17 @@ static NTSTATUS cmd_getwd(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
 
 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], &times) != 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;
        }
@@ -810,7 +854,7 @@ static NTSTATUS cmd_ftruncate(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int ar
 
        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;
        }
@@ -819,7 +863,7 @@ static NTSTATUS cmd_ftruncate(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int ar
                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;
        }
@@ -830,7 +874,6 @@ static NTSTATUS cmd_ftruncate(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int ar
 
 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;
@@ -902,7 +945,7 @@ static NTSTATUS cmd_lock(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
 
        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;
        }
@@ -978,7 +1021,7 @@ static NTSTATUS cmd_mknod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
                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;
        }