r12608: Remove some unused #include lines.
[bbaumbach/samba-autobuild/.git] / source4 / torture / smb2 / connect.c
index 34f8d5aa9fcd26b8d0e1e2055cbd1d9ddac23121..2077bb022767649bc864f37b80dae371a2f6c33a 100644 (file)
 */
 
 #include "includes.h"
-#include "libcli/raw/libcliraw.h"
 #include "libcli/smb2/smb2.h"
 #include "libcli/smb2/smb2_calls.h"
-#include "lib/cmdline/popt_common.h"
-#include "lib/events/events.h"
 
 /*
   send a close
@@ -37,7 +34,6 @@ static NTSTATUS torture_smb2_close(struct smb2_tree *tree, struct smb2_handle ha
        TALLOC_CTX *tmp_ctx = talloc_new(tree);
 
        ZERO_STRUCT(io);
-       io.in.buffer_code = 0x18;
        io.in.flags       = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
        io.in.handle   = handle;
        status = smb2_close(tree, &io);
@@ -52,8 +48,8 @@ static NTSTATUS torture_smb2_close(struct smb2_tree *tree, struct smb2_handle ha
                printf("access_time     = %s\n", nt_time_string(tmp_ctx, io.out.access_time));
                printf("write_time      = %s\n", nt_time_string(tmp_ctx, io.out.write_time));
                printf("change_time     = %s\n", nt_time_string(tmp_ctx, io.out.change_time));
-               printf("alloc_size      = %lld\n", io.out.alloc_size);
-               printf("size            = %lld\n", io.out.size);
+               printf("alloc_size      = %lld\n", (long long)io.out.alloc_size);
+               printf("size            = %lld\n", (long long)io.out.size);
                printf("file_attr       = 0x%x\n", io.out.file_attr);
        }
 
@@ -70,6 +66,7 @@ static NTSTATUS torture_smb2_write(struct smb2_tree *tree, struct smb2_handle ha
 {
        struct smb2_write w;
        struct smb2_read r;
+       struct smb2_flush f;
        NTSTATUS status;
        DATA_BLOB data;
        int i;
@@ -84,13 +81,10 @@ static NTSTATUS torture_smb2_write(struct smb2_tree *tree, struct smb2_handle ha
        }
 
        ZERO_STRUCT(w);
-       w.in.buffer_code = 0x31;
        w.in.offset      = 0;
        w.in.handle      = handle;
        w.in.data        = data;
 
-       memset(w.in._pad, 0xff, 16);
-
        status = smb2_write(tree, &w);
        if (!NT_STATUS_IS_OK(status)) {
                printf("write failed - %s\n", nt_errstr(status));
@@ -99,8 +93,6 @@ static NTSTATUS torture_smb2_write(struct smb2_tree *tree, struct smb2_handle ha
 
        torture_smb2_all_info(tree, handle);
 
-       memset(w.in._pad, 0xff, 16);
-
        status = smb2_write(tree, &w);
        if (!NT_STATUS_IS_OK(status)) {
                printf("write failed - %s\n", nt_errstr(status));
@@ -109,8 +101,16 @@ static NTSTATUS torture_smb2_write(struct smb2_tree *tree, struct smb2_handle ha
 
        torture_smb2_all_info(tree, handle);
 
+       ZERO_STRUCT(f);
+       f.in.handle      = handle;
+
+       status = smb2_flush(tree, &f);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("flush failed - %s\n", nt_errstr(status));
+               return status;
+       }
+
        ZERO_STRUCT(r);
-       r.in.buffer_code = 0x31;
        r.in.length      = data.length;
        r.in.offset      = 0;
        r.in.handle      = handle;
@@ -142,7 +142,6 @@ static struct smb2_handle torture_smb2_create(struct smb2_tree *tree,
        TALLOC_CTX *tmp_ctx = talloc_new(tree);
 
        ZERO_STRUCT(io);
-       io.in.buffer_code = 0x39;
        io.in.oplock_flags = 0;
        io.in.access_mask = SEC_RIGHTS_FILE_ALL;
        io.in.file_attr   = FILE_ATTRIBUTE_NORMAL;
@@ -154,7 +153,7 @@ static struct smb2_handle torture_smb2_create(struct smb2_tree *tree,
        io.in.create_options = NTCREATEX_OPTIONS_WRITE_THROUGH;
        io.in.fname = fname;
 
-       status = smb2_create(tree, &io);
+       status = smb2_create(tree, tmp_ctx, &io);
        if (!NT_STATUS_IS_OK(status)) {
                printf("create1 failed - %s\n", nt_errstr(status));
                return io.out.handle;
@@ -168,12 +167,12 @@ static struct smb2_handle torture_smb2_create(struct smb2_tree *tree,
                printf("access_time     = %s\n", nt_time_string(tmp_ctx, io.out.access_time));
                printf("write_time      = %s\n", nt_time_string(tmp_ctx, io.out.write_time));
                printf("change_time     = %s\n", nt_time_string(tmp_ctx, io.out.change_time));
-               printf("alloc_size      = %lld\n", io.out.alloc_size);
-               printf("size            = %lld\n", io.out.size);
+               printf("alloc_size      = %lld\n", (long long)io.out.alloc_size);
+               printf("size            = %lld\n", (long long)io.out.size);
                printf("file_attr       = 0x%x\n", io.out.file_attr);
                printf("handle          = %016llx%016llx\n", 
-                      io.out.handle.data[0], 
-                      io.out.handle.data[1]);
+                      (long long)io.out.handle.data[0], 
+                      (long long)io.out.handle.data[1]);
        }
 
        talloc_free(tmp_ctx);
@@ -190,6 +189,7 @@ BOOL torture_smb2_connect(void)
        TALLOC_CTX *mem_ctx = talloc_new(NULL);
        struct smb2_tree *tree;
        struct smb2_handle h1, h2;
+       NTSTATUS status;
 
        if (!torture_smb2_connection(mem_ctx, &tree)) {
                return False;
@@ -201,6 +201,36 @@ BOOL torture_smb2_connect(void)
        torture_smb2_close(tree, h1);
        torture_smb2_close(tree, h2);
 
+       status = smb2_tdis(tree);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("tdis failed - %s\n", nt_errstr(status));
+               return False;
+       }
+
+       status = smb2_tdis(tree);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
+               printf("tdis should have disabled session - %s\n", nt_errstr(status));
+               return False;
+       }
+
+       status = smb2_logoff(tree->session);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Logoff failed - %s\n", nt_errstr(status));
+               return False;
+       }
+
+       status = smb2_logoff(tree->session);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
+               printf("Logoff should have disabled session - %s\n", nt_errstr(status));
+               return False;
+       }
+
+       status = smb2_keepalive(tree->session->transport);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("keepalive failed? - %s\n", nt_errstr(status));
+               return False;
+       }
+
        talloc_free(mem_ctx);
 
        return True;