r11691: added reply buffer code checks and oplock flags for create request/reply
[jelmer/samba4-debian.git] / source / torture / smb2 / connect.c
index 49b9582d4d6422d8c1a662faa8e64b2f4fb674b3..2af6bfb5763958c94365c26a790a6bfaa6e20076 100644 (file)
@@ -159,11 +159,124 @@ static struct smb2_session *torture_smb2_session(struct smb2_transport *transpor
                return NULL;
        }
 
-       printf("Session setup gave UID 0x%llx\n", session->uid);
+       printf("Session setup gave UID 0x%016llx\n", session->uid);
 
        return session;
 }
 
+
+/*
+  send a tree connect
+*/
+static struct smb2_tree *torture_smb2_tree(struct smb2_session *session, 
+                                          const char *share)
+{
+       struct smb2_tree *tree;
+       struct smb2_tree_connect io;
+       NTSTATUS status;
+
+       tree = smb2_tree_init(session, session, True);
+
+       io.in.unknown1 = 0x09;
+       io.in.path     = talloc_asprintf(tree, "\\\\%s\\%s",
+                                        session->transport->socket->hostname,
+                                        share);
+       
+       status = smb2_tree_connect(tree, &io);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("tcon failed - %s\n", nt_errstr(status));
+               return NULL;
+       }
+       
+       printf("Tree connect gave tid = 0x%x\n", io.out.tid);
+
+       tree->tid = io.out.tid;
+
+       return tree;
+}
+
+/*
+  send a close
+*/
+static NTSTATUS torture_smb2_close(struct smb2_tree *tree, struct smb2_handle handle)
+{
+       struct smb2_close io;
+       NTSTATUS status;
+       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);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close failed - %s\n", nt_errstr(status));
+               return status;
+       }
+
+       printf("Close gave:\n");
+       printf("create_time     = %s\n", nt_time_string(tmp_ctx, io.out.create_time));
+       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("file_attr       = 0x%x\n", io.out.file_attr);
+
+       talloc_free(tmp_ctx);
+       
+       return status;
+}
+
+
+/*
+  send a create
+*/
+static struct smb2_handle torture_smb2_create(struct smb2_tree *tree, 
+                                             const char *fname)
+{
+       struct smb2_create io;
+       NTSTATUS status;
+       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;
+       io.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
+       io.in.share_access = 
+               NTCREATEX_SHARE_ACCESS_DELETE|
+               NTCREATEX_SHARE_ACCESS_READ|
+               NTCREATEX_SHARE_ACCESS_WRITE;
+       io.in.create_options = NTCREATEX_OPTIONS_WRITE_THROUGH;
+       io.in.fname = fname;
+
+       status = smb2_create(tree, &io);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("create1 failed - %s\n", nt_errstr(status));
+               return io.out.handle;
+       }
+
+       printf("Open gave:\n");
+       printf("oplock_flags    = 0x%x\n", io.out.oplock_flags);
+       printf("create_action   = 0x%x\n", io.out.create_action);
+       printf("create_time     = %s\n", nt_time_string(tmp_ctx, io.out.create_time));
+       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("file_attr       = 0x%x\n", io.out.file_attr);
+       printf("handle          = %016llx%016llx\n", 
+              io.out.handle.data[0], 
+              io.out.handle.data[1]);
+
+       talloc_free(tmp_ctx);
+       
+       return io.out.handle;
+}
+
 /* 
    basic testing of SMB2 connection calls
 */
@@ -171,12 +284,20 @@ BOOL torture_smb2_connect(void)
 {
        TALLOC_CTX *mem_ctx = talloc_new(NULL);
        struct smb2_transport *transport;
-       struct smb2_session *session;
+       struct smb2_session *session;   
+       struct smb2_tree *tree;
        const char *host = lp_parm_string(-1, "torture", "host");
+       const char *share = lp_parm_string(-1, "torture", "share");
        struct cli_credentials *credentials = cmdline_credentials;
+       struct smb2_handle h1, h2;
 
        transport = torture_smb2_negprot(mem_ctx, host);
-       session = torture_smb2_session(transport, credentials);
+       session   = torture_smb2_session(transport, credentials);
+       tree      = torture_smb2_tree(session, share);
+       h1        = torture_smb2_create(tree, "test9.dat");
+       h2        = torture_smb2_create(tree, "test9.dat");
+       torture_smb2_close(tree, h1);
+       torture_smb2_close(tree, h2);
 
        talloc_free(mem_ctx);