Fix a bunch of compiler warnings about wrong format types.
[ira/wip.git] / source3 / torture / cmd_vfs.c
index 132e0776aba8d5478d37c2339460f87aecc7234e..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,13 +87,13 @@ 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;
 }
 
 static NTSTATUS cmd_connect(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
 {
-       SMB_VFS_CONNECT(vfs->conn, lp_servicename(vfs->conn->service), "vfstest");
+       SMB_VFS_CONNECT(vfs->conn, lp_servicename(SNUM(vfs->conn)), "vfstest");
        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;
@@ -129,7 +128,7 @@ static NTSTATUS cmd_opendir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc
                return NT_STATUS_OK;
        }
 
-       vfs->currentdir = SMB_VFS_OPENDIR(vfs->conn, argv[1]);
+       vfs->currentdir = SMB_VFS_OPENDIR(vfs->conn, argv[1], NULL, 0);
        if (vfs->currentdir == NULL) {
                printf("opendir error=%d (%s)\n", errno, strerror(errno));
                return NT_STATUS_UNSUCCESSFUL;
@@ -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)
 {
-       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;
 }
 
@@ -200,9 +228,10 @@ static NTSTATUS cmd_closedir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int arg
 
 static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
 {
-       int flags, fd;
+       int flags;
        mode_t mode;
        const char *flagstr;
+       files_struct *fsp;
 
        mode = 00400;
 
@@ -272,23 +301,40 @@ 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;
                }
        }
 
-       fd = SMB_VFS_OPEN(vfs->conn, argv[1], flags, mode);
-       if (fd == -1) {
+       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;
        }
 
-       vfs->files[fd] = SMB_MALLOC_P(struct files_struct);
-       vfs->files[fd]->fsp_name = SMB_STRDUP(argv[1]);
-       vfs->files[fd]->fd = fd;
-       vfs->files[fd]->conn = vfs->conn;
-       printf("open: fd=%d\n", fd);
+       vfs->files[fsp->fh->fd] = fsp;
+       printf("open: fd=%d\n", fsp->fh->fd);
        return NT_STATUS_OK;
 }
 
@@ -338,13 +384,14 @@ 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
                printf("close: ok\n");
 
        SAFE_FREE(vfs->files[fd]->fsp_name);
+       SAFE_FREE(vfs->files[fd]->fh);
        SAFE_FREE(vfs->files[fd]);
        vfs->files[fd] = NULL;
        return NT_STATUS_OK;
@@ -371,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;
@@ -404,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));
@@ -435,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;
@@ -474,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;
@@ -531,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)));
@@ -557,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;
        }
@@ -567,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;
        }
@@ -597,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)));
@@ -651,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)));
@@ -692,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;
        }
@@ -701,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;
        }
@@ -745,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;
        }
@@ -753,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;
        }
@@ -777,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;
        }
@@ -804,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;
        }
@@ -813,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;
        }
@@ -824,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;
@@ -896,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;
        }
@@ -972,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;
        }