samldb: Allow automatic generation of mAPIIDs
[sfrench/samba-autobuild/.git] / source4 / torture / raw / close.c
index 67050f30a3a7ee6896f176e7d837e7cf8f3b4cc7..56b63c6432438369cc30d52906494c89c239f7b7 100644 (file)
@@ -5,7 +5,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,
    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"
 #include "torture/torture.h"
 #include "system/time.h"
 #include "libcli/raw/libcliraw.h"
+#include "libcli/raw/raw_proto.h"
+#include "libcli/libcli.h"
+#include "torture/util.h"
+#include "torture/raw/proto.h"
 
-
-/* basic testing of all RAW_CLOSE_* calls 
+/**
+ * basic testing of all RAW_CLOSE_* calls 
 */
-BOOL torture_raw_close(void)
+bool torture_raw_close(struct torture_context *torture,
+                      struct smbcli_state *cli)
 {
-       struct smbcli_state *cli;
-       BOOL ret = True;
-       TALLOC_CTX *mem_ctx;
+       bool ret = true;
        union smb_close io;
-       struct smb_flush io_flush;
+       union smb_flush io_flush;
        int fnum;
        const char *fname = "\\torture_close.txt";
        time_t basetime = (time(NULL) + 3*86400) & ~1;
        union smb_fileinfo finfo, finfo2;
        NTSTATUS status;
 
-       if (!torture_open_connection(&cli)) {
-               return False;
-       }
-
-       mem_ctx = talloc_init("torture_raw_close");
-
 #define REOPEN do { \
-       fnum = create_complex_file(cli, mem_ctx, fname); \
+       fnum = create_complex_file(cli, torture, fname); \
        if (fnum == -1) { \
                printf("(%d) Failed to create %s\n", __LINE__, fname); \
-               ret = False; \
+               ret = false; \
                goto done; \
        }} while (0)
 
@@ -57,14 +53,14 @@ BOOL torture_raw_close(void)
        if (!NT_STATUS_EQUAL(status, correct)) { \
                printf("(%d) Incorrect status %s - should be %s\n", \
                       __LINE__, nt_errstr(status), nt_errstr(correct)); \
-               ret = False; \
+               ret = false; \
                goto done; \
        }} while (0)
 
        REOPEN;
 
        io.close.level = RAW_CLOSE_CLOSE;
-       io.close.in.fnum = fnum;
+       io.close.in.file.fnum = fnum;
        io.close.in.write_time = basetime;
        status = smb_raw_close(cli->tree, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
@@ -72,23 +68,23 @@ BOOL torture_raw_close(void)
        status = smb_raw_close(cli->tree, &io);
        CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
        
-       printf("testing close.in.write_time\n");
+       printf("Testing close.in.write_time\n");
 
        /* the file should have the write time set */
-       finfo.generic.in.fname = fname;
        finfo.generic.level = RAW_FILEINFO_ALL_INFO;
-       status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
+       finfo.generic.in.file.path = fname;
+       status = smb_raw_pathinfo(cli->tree, torture, &finfo);
        CHECK_STATUS(status, NT_STATUS_OK);
 
        if (basetime != nt_time_to_unix(finfo.all_info.out.write_time)) {
                printf("Incorrect write time on file - %s - %s\n",
-                      timestring(mem_ctx, basetime), 
-                      nt_time_string(mem_ctx, finfo.all_info.out.write_time));
-               dump_all_info(mem_ctx, &finfo);
-               ret = False;
+                      timestring(torture, basetime), 
+                      nt_time_string(torture, finfo.all_info.out.write_time));
+               dump_all_info(torture, &finfo);
+               ret = false;
        }
 
-       printf("testing other times\n");
+       printf("Testing other times\n");
 
        /* none of the other times should be set to that time */
        if (nt_time_equal(&finfo.all_info.out.write_time, 
@@ -98,68 +94,79 @@ BOOL torture_raw_close(void)
            nt_time_equal(&finfo.all_info.out.write_time, 
                          &finfo.all_info.out.change_time)) {
                printf("Incorrect times after close - only write time should be set\n");
-               dump_all_info(mem_ctx, &finfo);
-               ret = False;
+               dump_all_info(torture, &finfo);
+
+               if (!torture_setting_bool(torture, "samba3", false)) {
+                       /*
+                        * In Samba3 as of 3.0.23d we don't yet support all
+                        * file times, so don't mark this as a critical
+                        * failure
+                        */
+                       ret = false;
+               }
        }
            
 
        smbcli_unlink(cli->tree, fname);
        REOPEN;
 
-       finfo2.generic.in.fname = fname;
        finfo2.generic.level = RAW_FILEINFO_ALL_INFO;
-       status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2);
+       finfo2.generic.in.file.path = fname;
+       status = smb_raw_pathinfo(cli->tree, torture, &finfo2);
        CHECK_STATUS(status, NT_STATUS_OK);
 
        io.close.level = RAW_CLOSE_CLOSE;
-       io.close.in.fnum = fnum;
+       io.close.in.file.fnum = fnum;
        io.close.in.write_time = 0;
        status = smb_raw_close(cli->tree, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
 
        /* the file should have the write time set equal to access time */
-       finfo.generic.in.fname = fname;
        finfo.generic.level = RAW_FILEINFO_ALL_INFO;
-       status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
+       finfo.generic.in.file.path = fname;
+       status = smb_raw_pathinfo(cli->tree, torture, &finfo);
        CHECK_STATUS(status, NT_STATUS_OK);
 
        if (!nt_time_equal(&finfo.all_info.out.write_time, 
                           &finfo2.all_info.out.write_time)) {
                printf("Incorrect write time on file - 0 time should be ignored\n");
-               dump_all_info(mem_ctx, &finfo);
-               ret = False;
+               dump_all_info(torture, &finfo);
+               ret = false;
        }
 
-       printf("testing splclose\n");
+       printf("Testing splclose\n");
 
        /* check splclose on a file */
        REOPEN;
        io.splclose.level = RAW_CLOSE_SPLCLOSE;
-       io.splclose.in.fnum = fnum;
+       io.splclose.in.file.fnum = fnum;
        status = smb_raw_close(cli->tree, &io);
        CHECK_STATUS(status, NT_STATUS_DOS(ERRSRV, ERRerror));
 
-       printf("testing flush\n");
+       printf("Testing flush\n");
        smbcli_close(cli->tree, fnum);
 
-       io_flush.in.fnum = fnum;
+       io_flush.flush.level            = RAW_FLUSH_FLUSH;
+       io_flush.flush.in.file.fnum     = fnum;
        status = smb_raw_flush(cli->tree, &io_flush);
        CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
 
-       io_flush.in.fnum = 0xffff;
+       io_flush.flush_all.level        = RAW_FLUSH_ALL;
        status = smb_raw_flush(cli->tree, &io_flush);
        CHECK_STATUS(status, NT_STATUS_OK);
 
        REOPEN;
 
-       io_flush.in.fnum = fnum;
+       io_flush.flush.level            = RAW_FLUSH_FLUSH;
+       io_flush.flush.in.file.fnum     = fnum;
        status = smb_raw_flush(cli->tree, &io_flush);
        CHECK_STATUS(status, NT_STATUS_OK);
 
        printf("Testing SMBexit\n");
        smb_raw_exit(cli->session);
 
-       io_flush.in.fnum = fnum;
+       io_flush.flush.level            = RAW_FLUSH_FLUSH;
+       io_flush.flush.in.file.fnum     = fnum;
        status = smb_raw_flush(cli->tree, &io_flush);
        CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
        
@@ -167,7 +174,5 @@ BOOL torture_raw_close(void)
 done:
        smbcli_close(cli->tree, fnum);
        smbcli_unlink(cli->tree, fname);
-       torture_close_connection(cli);
-       talloc_free(mem_ctx);
        return ret;
 }