Add torture test for bug #5986 - streams rename, so we don't regress.
authorJeremy Allison <jra@samba.org>
Sat, 20 Dec 2008 02:01:26 +0000 (18:01 -0800)
committerJeremy Allison <jra@samba.org>
Sat, 20 Dec 2008 02:01:26 +0000 (18:01 -0800)
Jeremy.

source4/torture/raw/streams.c

index 501da23..4e2a204 100644 (file)
@@ -1015,6 +1015,102 @@ done:
        return ret;
 }
 
+#define CHECK_CALL_FNUM(call, rightstatus) do { \
+        check_fnum = true; \
+        call_name = #call; \
+        sfinfo.generic.level = RAW_SFILEINFO_ ## call; \
+        sfinfo.generic.in.file.fnum = fnum; \
+        status = smb_raw_setfileinfo(cli->tree, &sfinfo); \
+        if (!NT_STATUS_EQUAL(status, rightstatus)) { \
+                printf("(%s) %s - %s (should be %s)\n", __location__, #call, \
+                        nt_errstr(status), nt_errstr(rightstatus)); \
+                ret = false; \
+        } \
+        finfo1.generic.level = RAW_FILEINFO_ALL_INFO; \
+        finfo1.generic.in.file.fnum = fnum; \
+        status2 = smb_raw_fileinfo(cli->tree, tctx, &finfo1); \
+        if (!NT_STATUS_IS_OK(status2)) { \
+                printf("(%s) %s pathinfo - %s\n", __location__, #call, nt_errstr(status)); \
+                ret = false; \
+        }} while (0)
+
+/*
+  test stream renames
+*/
+static bool test_stream_rename(struct torture_context *tctx,
+                                  struct smbcli_state *cli,
+                                  TALLOC_CTX *mem_ctx)
+{
+       NTSTATUS status, status2;
+       union smb_open io;
+       const char *fname = BASEDIR "\\stream_rename.txt";
+       const char *sname1, *sname2;
+       union smb_fileinfo finfo1;
+       union smb_setfileinfo sfinfo;
+       bool ret = true;
+       int fnum = -1;
+       bool check_fnum;
+       const char *call_name;
+
+       sname1 = talloc_asprintf(mem_ctx, "%s:%s", fname, "Stream One");
+       sname2 = talloc_asprintf(mem_ctx, "%s:%s:$DaTa", fname, "Second Stream");
+
+       printf("(%s) testing stream renames\n", __location__);
+       io.generic.level = RAW_OPEN_NTCREATEX;
+       io.ntcreatex.in.root_fid = 0;
+       io.ntcreatex.in.flags = 0;
+       io.ntcreatex.in.access_mask = SEC_FILE_READ_ATTRIBUTE |
+                                     SEC_FILE_WRITE_ATTRIBUTE |
+                                   SEC_RIGHTS_FILE_ALL;
+       io.ntcreatex.in.create_options = 0;
+       io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+       io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
+       io.ntcreatex.in.alloc_size = 0;
+       io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
+       io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
+       io.ntcreatex.in.security_flags = 0;
+       io.ntcreatex.in.fname = sname1;
+
+       /* Create two streams. */
+       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       fnum = io.ntcreatex.out.file.fnum;
+       if (fnum != -1) smbcli_close(cli->tree, fnum);
+
+       io.ntcreatex.in.fname = sname2;
+       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       fnum = io.ntcreatex.out.file.fnum;
+
+       if (fnum != -1) smbcli_close(cli->tree, fnum);
+
+       /*
+        * Open the second stream.
+        */
+
+       io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
+       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       fnum = io.ntcreatex.out.file.fnum;
+
+       /*
+        * Now rename the second stream onto the first.
+        */
+
+       ZERO_STRUCT(sfinfo);
+
+       sfinfo.rename_information.in.overwrite = 1;
+       sfinfo.rename_information.in.root_fid  = 0;
+       sfinfo.rename_information.in.new_name  = ":Stream One";
+       CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
+
+done:
+       if (fnum != -1) smbcli_close(cli->tree, fnum);
+       status = smbcli_unlink(cli->tree, fname);
+       return ret;
+}
+
+
 /* 
    basic testing of streams calls
 */
@@ -1037,6 +1133,8 @@ bool torture_raw_streams(struct torture_context *torture,
        smb_raw_exit(cli->session);
        ret &= test_stream_names2(torture, cli, torture);
        smb_raw_exit(cli->session);
+       ret &= test_stream_rename(torture, cli, torture);
+       smb_raw_exit(cli->session);
        if (!torture_setting_bool(torture, "samba4", false)) {
                ret &= test_stream_delete(torture, cli, torture);
        }