r11716: added a read/write test
authorAndrew Tridgell <tridge@samba.org>
Mon, 14 Nov 2005 05:10:09 +0000 (05:10 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:46:17 +0000 (13:46 -0500)
(This used to be commit 7c229e5b9fc8774207b647214b9d03d26a60aae3)

source4/torture/smb2/connect.c

index 54991e27bab6626d2bea6b6c6021cbca1dbe2c21..4907aadecb4c922c9cb18a2567b0089f64ae81c3 100644 (file)
@@ -63,6 +63,53 @@ static NTSTATUS torture_smb2_close(struct smb2_tree *tree, struct smb2_handle ha
 }
 
 
+/*
+  test writing
+*/
+static NTSTATUS torture_smb2_write(struct smb2_tree *tree, struct smb2_handle handle)
+{
+       struct smb2_write w;
+       struct smb2_read r;
+       NTSTATUS status;
+       DATA_BLOB data;
+       
+       data = data_blob_talloc(tree, NULL, 700);
+       generate_random_buffer(data.data, data.length);
+
+       ZERO_STRUCT(w);
+       w.in.buffer_code = 0x31;
+       w.in.offset      = 0;
+       w.in.handle      = handle;
+       w.in.data        = data;
+
+       status = smb2_write(tree, &w);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("write 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;
+
+       status = smb2_read(tree, tree, &r);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("read failed - %s\n", nt_errstr(status));
+               return status;
+       }
+
+       if (data.length != r.out.data.length ||
+           memcmp(data.data, r.out.data.data, data.length) != 0) {
+               printf("read data mismatch\n");
+               return NT_STATUS_NET_WRITE_FAULT;
+       }
+
+       return status;
+}
+
+
 /*
   send a create
 */
@@ -136,6 +183,7 @@ BOOL torture_smb2_connect(void)
 
        h1 = torture_smb2_create(tree, "test9.dat");
        h2 = torture_smb2_create(tree, "test9.dat");
+       torture_smb2_write(tree, h1);
        torture_smb2_close(tree, h1);
        torture_smb2_close(tree, h2);