s4-torture: Add tests for the smb2 copychunk ioctl
authorDavid Disseldorp <ddiss@suse.de>
Tue, 27 Sep 2011 14:40:20 +0000 (16:40 +0200)
committerDavid Disseldorp <ddiss@samba.org>
Mon, 31 Oct 2011 16:55:05 +0000 (17:55 +0100)
Add idls for parsing of copychunk ioctl args.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
librpc/idl/wscript_build
librpc/wscript_build
source4/torture/smb2/ioctl.c
source4/torture/smb2/wscript_build

index ffb7a9c808836d046fa2afe10424437c77652fce..d2112b47d83228b55e97fc3db7a3e3cfac181f58 100644 (file)
@@ -27,7 +27,7 @@ bld.SAMBA_PIDL_LIST('PIDL',
                     output_dir='../gen_ndr')
 
 bld.SAMBA_PIDL_LIST('PIDL',
-                    'rap.idl ntprinting.idl preg.idl',
+                    'rap.idl ntprinting.idl preg.idl ioctl.idl',
                     options='--header --ndr-parser',
                     output_dir='../gen_ndr')
 
index 14289a1e9132b156c31c0b3232db617b5f8a2072..dc35de5ecc66b7e11106aa4b5399273f92bf8551 100644 (file)
@@ -563,6 +563,11 @@ bld.SAMBA_SUBSYSTEM('RPC_NDR_DNSSERVER',
        public_deps='dcerpc-binding ndr-standard'
        )
 
+bld.SAMBA_SUBSYSTEM('NDR_IOCTL',
+       source='gen_ndr/ndr_ioctl.c',
+       public_deps='ndr'
+       )
+
 # a grouping library for NDR subsystems that may be used by more than one target
 bld.SAMBA_LIBRARY('ndr-samba',
        source=[],
index 169a001f31485f255f965daed3c8bdcd71d22104..67dabe8737dc6bc60aac31bbb2419fdf78c817e8 100644 (file)
 #include "libcli/smb2/smb2_calls.h"
 #include "torture/torture.h"
 #include "torture/smb2/proto.h"
+#include "librpc/gen_ndr/ndr_ioctl.h"
 
-#define FNAME "testfsctl.dat"
+#define FNAME  "testfsctl.dat"
+#define FNAME2 "testfsctl2.dat"
 
 /*
    basic testing of SMB2 shadow copy calls
@@ -71,6 +73,173 @@ static bool test_ioctl_get_shadow_copy(struct torture_context *torture,
        return true;
 }
 
+/*
+   basic testing of the SMB2 server side copy ioctls
+*/
+static bool test_ioctl_req_resume_key(struct torture_context *torture,
+                                     struct smb2_tree *tree)
+{
+       struct smb2_handle h;
+       uint8_t buf[100];
+       NTSTATUS status;
+       union smb_ioctl ioctl;
+       TALLOC_CTX *tmp_ctx = talloc_new(tree);
+       struct req_resume_key_rsp res_key;
+       enum ndr_err_code ndr_ret;
+
+       smb2_util_unlink(tree, FNAME);
+
+       status = torture_smb2_testfile(tree, FNAME, &h);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("create write\n");
+               return false;
+       }
+
+       ZERO_ARRAY(buf);
+       status = smb2_util_write(tree, h, buf, 0, ARRAY_SIZE(buf));
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("failed write\n");
+               return false;
+       }
+
+       ZERO_STRUCT(ioctl);
+       ioctl.smb2.level = RAW_IOCTL_SMB2;
+       ioctl.smb2.in.file.handle = h;
+       ioctl.smb2.in.function = FSCTL_SRV_REQUEST_RESUME_KEY;
+       ioctl.smb2.in.max_response_size = 32;
+       ioctl.smb2.in.flags = SMB2_IOCTL_FLAG_IS_FSCTL;
+
+       status = smb2_ioctl(tree, tmp_ctx, &ioctl.smb2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("FSCTL_SRV_REQUEST_RESUME_KEY failed\n");
+               return false;
+       }
+
+       ndr_ret = ndr_pull_struct_blob(&ioctl.smb2.out.out, tmp_ctx, &res_key,
+                       (ndr_pull_flags_fn_t)ndr_pull_req_resume_key_rsp);
+       if (ndr_ret != NDR_ERR_SUCCESS) {
+               return false;
+       }
+
+       ndr_print_debug((ndr_print_fn_t)ndr_print_req_resume_key_rsp, "yo", &res_key);
+
+       talloc_free(tmp_ctx);
+       return true;
+}
+
+static bool test_ioctl_copy_chunk(struct torture_context *torture,
+                                 struct smb2_tree *tree)
+{
+       struct smb2_handle h;
+       struct smb2_handle h2;
+       uint8_t buf[100];
+       NTSTATUS status;
+       union smb_ioctl ioctl;
+       TALLOC_CTX *tmp_ctx = talloc_new(tree);
+       struct req_resume_key_rsp res_key;
+       struct srv_copychunk chunk;
+       struct srv_copychunk_copy cc_copy;
+       struct srv_copychunk_rsp cc_rsp;
+       enum ndr_err_code ndr_ret;
+
+       smb2_util_unlink(tree, FNAME);
+       smb2_util_unlink(tree, FNAME2);
+
+       status = torture_smb2_testfile(tree, FNAME, &h);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("create write\n");
+               return false;
+       }
+
+       ZERO_ARRAY(buf);
+       status = smb2_util_write(tree, h, buf, 0, ARRAY_SIZE(buf));
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("failed write\n");
+               return false;
+       }
+
+       ZERO_STRUCT(ioctl);
+       ioctl.smb2.level = RAW_IOCTL_SMB2;
+       ioctl.smb2.in.file.handle = h;
+       ioctl.smb2.in.function = FSCTL_SRV_REQUEST_RESUME_KEY;
+       /* Allow for Key + ContextLength + Context */
+       ioctl.smb2.in.max_response_size = 32;
+       ioctl.smb2.in.flags = SMB2_IOCTL_FLAG_IS_FSCTL;
+
+       status = smb2_ioctl(tree, tmp_ctx, &ioctl.smb2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("FSCTL_SRV_REQUEST_RESUME_KEY failed\n");
+               return false;
+       }
+
+       ndr_ret = ndr_pull_struct_blob(&ioctl.smb2.out.out, tmp_ctx, &res_key,
+                       (ndr_pull_flags_fn_t)ndr_pull_req_resume_key_rsp);
+       if (ndr_ret != NDR_ERR_SUCCESS) {
+               return false;
+       }
+
+       status = torture_smb2_testfile(tree, FNAME2, &h2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("create write\n");
+               return false;
+       }
+
+       ZERO_STRUCT(ioctl);
+       ioctl.smb2.level = RAW_IOCTL_SMB2;
+       ioctl.smb2.in.file.handle = h2;
+       ioctl.smb2.in.function = FSCTL_SRV_COPYCHUNK;
+       ioctl.smb2.in.max_response_size = 12;   /* FIXME */
+       ioctl.smb2.in.flags = SMB2_IOCTL_FLAG_IS_FSCTL;
+
+       ZERO_STRUCT(chunk);
+       chunk.source_off = 0;
+       chunk.target_off = 0;
+       chunk.length = 100;
+
+       ZERO_STRUCT(cc_copy);
+       memcpy(cc_copy.source_key, res_key.resume_key, ARRAY_SIZE(cc_copy.source_key));
+       cc_copy.chunk_count = 1;
+       cc_copy.chunks = &chunk;
+
+       ndr_ret = ndr_push_struct_blob(&ioctl.smb2.in.out, tmp_ctx,
+                                      &cc_copy,
+                       (ndr_push_flags_fn_t)ndr_push_srv_copychunk_copy);
+       if (ndr_ret != NDR_ERR_SUCCESS) {
+               return false;
+       }
+
+       /* request a copy of all src file data (via a single chunk desc) */
+       status = smb2_ioctl(tree, tmp_ctx, &ioctl.smb2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("FSCTL_SRV_COPYCHUNK failed\n");
+               return false;
+       }
+
+       ndr_ret = ndr_pull_struct_blob(&ioctl.smb2.out.out, tmp_ctx,
+                                      &cc_rsp,
+                       (ndr_pull_flags_fn_t)ndr_pull_srv_copychunk_rsp);
+       if (ndr_ret != NDR_ERR_SUCCESS) {
+               return false;
+       }
+       if (cc_rsp.chunks_written != 1) {
+               printf("fail, expected 1 chunk, got %u\n", cc_rsp.chunks_written);
+               return false;
+       }
+       if (cc_rsp.chunk_bytes_written != 0) {
+               printf("fail, expected 0 chunk bytes remaining, got %u\n",
+                      cc_rsp.chunk_bytes_written);
+               return false;
+       }
+       if (cc_rsp.total_bytes_written != 100) {
+               printf("fail, expected 100 total bytes, got %u\n",
+                      cc_rsp.total_bytes_written);
+               return false;
+       }
+
+       talloc_free(tmp_ctx);
+       return true;
+}
+
 /*
    basic testing of SMB2 ioctls
 */
@@ -79,6 +248,8 @@ struct torture_suite *torture_smb2_ioctl_init(void)
        struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "ioctl");
 
        torture_suite_add_1smb2_test(suite, "shadow_copy", test_ioctl_get_shadow_copy);
+       torture_suite_add_1smb2_test(suite, "req_resume_key", test_ioctl_req_resume_key);
+       torture_suite_add_1smb2_test(suite, "copy_chunk", test_ioctl_copy_chunk);
 
        suite->description = talloc_strdup(suite, "SMB2-IOCTL tests");
 
index 458a27b00468313658516fa54168cbfa73498e97..81dc0e0d93b4c8570eaba63f74cd5acee9f8deff 100644 (file)
@@ -3,7 +3,7 @@
 bld.SAMBA_MODULE('TORTURE_SMB2',
        source='connect.c scan.c util.c getinfo.c setinfo.c lock.c notify.c smb2.c durable_open.c oplock.c dir.c lease.c create.c acls.c read.c compound.c streams.c ioctl.c',
        subsystem='smbtorture',
-       deps='LIBCLI_SMB2 POPT_CREDENTIALS torture',
+       deps='LIBCLI_SMB2 POPT_CREDENTIALS torture NDR_IOCTL',
        internal_module=True,
        autoproto='proto.h',
        init_function='torture_smb2_init'