r16657: Test Jerry's iTunes bug, along with some more error conditions
authorVolker Lendecke <vlendec@samba.org>
Wed, 28 Jun 2006 22:09:03 +0000 (22:09 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:09:36 +0000 (14:09 -0500)
Volker
(This used to be commit 12aa900eb2ffde3711a30c7e063bfba95128e91d)

source4/torture/basic/base.c
source4/torture/config.mk
source4/torture/raw/raw.c
source4/torture/raw/samba3hide.c
source4/torture/raw/samba3misc.c [new file with mode: 0644]
source4/torture/util.c

index b670b8a30aa4cb348606d4b38b0472a80dfdcf41..55f0b6e54394af5856da816a6efb61b7f5bb083b 100644 (file)
@@ -1621,7 +1621,7 @@ static BOOL torture_samba3_errorpaths(struct torture_context *torture)
        const char *os2_fname = ".+,;=[].";
        const char *dname = "samba3_errordir";
        union smb_open io;
-       TALLOC_CTX *mem_ctx = talloc_init(NULL);
+       TALLOC_CTX *mem_ctx = talloc_init("samba3_errorpaths");
        NTSTATUS status;
 
        if (mem_ctx == NULL) {
@@ -1707,6 +1707,23 @@ static BOOL torture_samba3_errorpaths(struct torture_context *torture)
                goto fail;
        }
 
+       io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+       status = smb_raw_open(cli_nt->tree, mem_ctx, &io);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
+               printf("(%s) incorrect status %s should be %s\n",
+                      __location__, nt_errstr(status),
+                      nt_errstr(NT_STATUS_OBJECT_NAME_COLLISION));
+               goto fail;
+       }
+
+       status = smb_raw_open(cli_dos->tree, mem_ctx, &io);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_DOS(ERRDOS, ERRfilexists))) {
+               printf("(%s) incorrect status %s should be %s\n",
+                      __location__, nt_errstr(status),
+                      nt_errstr(NT_STATUS_DOS(ERRDOS, ERRfilexists)));
+               goto fail;
+       }
+
        {
                /* Test an invalid DOS deny mode */
                const char *fname = "test.txt";
index 07469ab25273f4bc143dd10621fd738fc533b8c8..8141d5f2cc41c2c753fb050864ab393b5d0ad323 100644 (file)
@@ -83,6 +83,7 @@ OBJ_FILES = \
                raw/acls.o \
                raw/seek.o \
                raw/samba3hide.o \
+               raw/samba3misc.o \
                raw/composite.o \
                raw/raw.o
 PUBLIC_DEPENDENCIES = \
index 0156925a73d5ab2f37800b720ab57ae7682b08e0..feff72d4e8429af58803c49ae3cf530912051b90 100644 (file)
@@ -53,6 +53,7 @@ NTSTATUS torture_raw_init(void)
        register_torture_op("RAW-ACLS", torture_raw_acls);
        register_torture_op("RAW-COMPOSITE", torture_raw_composite);
        register_torture_op("RAW-SAMBA3HIDE", torture_samba3_hide);
+       register_torture_op("RAW-SAMBA3CHECKFSP", torture_samba3_checkfsp);
        register_torture_op("SCAN-EAMAX", torture_max_eas);
 
        return NT_STATUS_OK;
index 1f4f987a43e56762ca76d120b3cbc85b8ab5eded..da23cfb1f190f6ba7ae0c9449d6f52fea0cbdfdb 100644 (file)
@@ -126,46 +126,6 @@ static NTSTATUS smbcli_chmod(struct smbcli_tree *tree, const char *fname,
        return smb_raw_setpathinfo(tree, &sfinfo);
 }
 
-static NTSTATUS second_tcon(TALLOC_CTX *mem_ctx,
-                           struct smbcli_session *session,
-                           const char *sharename,
-                           struct smbcli_tree **res)
-{
-       union smb_tcon tcon;
-       struct smbcli_tree *result;
-       TALLOC_CTX *tmp_ctx;
-       NTSTATUS status;
-
-       if ((tmp_ctx = talloc_new(mem_ctx)) == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       result = smbcli_tree_init(session, tmp_ctx, False);
-       if (result == NULL) {
-               talloc_free(tmp_ctx);
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       tcon.generic.level = RAW_TCON_TCONX;
-       tcon.tconx.in.flags = 0;
-
-       /* Ignore share mode security here */
-       tcon.tconx.in.password = data_blob(NULL, 0);
-       tcon.tconx.in.path = sharename;
-       tcon.tconx.in.device = "????";
-
-       status = smb_raw_tcon(result, tmp_ctx, &tcon);
-       if (!NT_STATUS_IS_OK(status)) {
-               talloc_free(tmp_ctx);
-               return status;
-       }
-
-       result->tid = tcon.tconx.out.tid;
-       *res = talloc_steal(mem_ctx, result);
-       talloc_free(tmp_ctx);
-       return NT_STATUS_OK;
-}
-
 BOOL torture_samba3_hide(struct torture_context *torture)
 {
        struct smbcli_state *cli;
@@ -182,16 +142,16 @@ BOOL torture_samba3_hide(struct torture_context *torture)
                return False;
        }
 
-       status = second_tcon(torture, cli->session, "hideunread",
-                            &hideunread);
+       status = torture_second_tcon(torture, cli->session, "hideunread",
+                                    &hideunread);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("second_tcon(hideunread) failed: %s\n",
                         nt_errstr(status));
                return False;
        }
 
-       status = second_tcon(torture, cli->session, "hideunwrite",
-                            &hideunwrite);
+       status = torture_second_tcon(torture, cli->session, "hideunwrite",
+                                    &hideunwrite);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("second_tcon(hideunwrite) failed: %s\n",
                         nt_errstr(status));
@@ -305,4 +265,3 @@ BOOL torture_samba3_hide(struct torture_context *torture)
 
        return True;
 }
-
diff --git a/source4/torture/raw/samba3misc.c b/source4/torture/raw/samba3misc.c
new file mode 100644 (file)
index 0000000..cc996ca
--- /dev/null
@@ -0,0 +1,157 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Test some misc Samba3 code paths
+   Copyright (C) Volker Lendecke 2006
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "torture/torture.h"
+#include "libcli/raw/libcliraw.h"
+#include "system/time.h"
+#include "system/filesys.h"
+#include "libcli/libcli.h"
+#include "torture/util.h"
+
+#define CHECK_STATUS(status, correct) do { \
+       if (!NT_STATUS_EQUAL(status, correct)) { \
+               printf("(%s) Incorrect status %s - should be %s\n", \
+                      __location__, nt_errstr(status), nt_errstr(correct)); \
+               ret = False; \
+       } \
+} while (0)
+
+BOOL torture_samba3_checkfsp(struct torture_context *torture)
+{
+       struct smbcli_state *cli;
+       const char *fname = "test.txt";
+       const char *dirname = "testdir";
+       int fnum;
+       NTSTATUS status;
+       BOOL ret = True;
+       TALLOC_CTX *mem_ctx;
+       ssize_t nread;
+       char buf[16];
+       struct smbcli_tree *tree2;
+
+       if ((mem_ctx = talloc_init("torture_samba3_checkfsp")) == NULL) {
+               d_printf("talloc_init failed\n");
+               return False;
+       }
+
+       if (!torture_open_connection_share(
+                   torture, &cli, lp_parm_string(-1, "torture", "host"),
+                   lp_parm_string(-1, "torture", "share"), NULL)) {
+               d_printf("torture_open_connection_share failed\n");
+               ret = False;
+               goto done;
+       }
+
+       smbcli_deltree(cli->tree, dirname);
+
+       status = torture_second_tcon(torture, cli->session,
+                                    lp_parm_string(-1, "torture", "share"),
+                                    &tree2);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       if (!NT_STATUS_IS_OK(status))
+               goto done;
+
+       /* Try a read on an invalid FID */
+
+       nread = smbcli_read(cli->tree, 4711, buf, 0, sizeof(buf));
+       CHECK_STATUS(smbcli_nt_error(cli->tree), NT_STATUS_INVALID_HANDLE);
+
+       /* Try a read on a directory handle */
+
+       status = smbcli_mkdir(cli->tree, dirname);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("smbcli_mkdir failed: %s\n", nt_errstr(status));
+               ret = False;
+               goto done;
+       }
+
+       /* Open the directory */
+       {
+               union smb_open io;
+               io.generic.level = RAW_OPEN_NTCREATEX;
+               io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
+               io.ntcreatex.in.root_fid = 0;
+               io.ntcreatex.in.security_flags = 0;
+               io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
+               io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
+               io.ntcreatex.in.alloc_size = 0;
+               io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
+               io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
+               io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
+               io.ntcreatex.in.create_options = 0;
+               io.ntcreatex.in.fname = dirname;
+               status = smb_raw_open(cli->tree, mem_ctx, &io);
+               if (!NT_STATUS_IS_OK(status)) {
+                       d_printf("smb_open on the directory failed: %s\n",
+                                nt_errstr(status));
+                       ret = False;
+                       goto done;
+               }
+               fnum = io.ntcreatex.out.file.fnum;
+       }
+
+       /* Try a read on the directory */
+
+       nread = smbcli_read(cli->tree, fnum, buf, 0, sizeof(buf));
+       if (nread >= 0) {
+               d_printf("smbcli_read on a directory succeeded, expected "
+                        "failure\n");
+               ret = False;
+       }
+
+       CHECK_STATUS(smbcli_nt_error(cli->tree),
+                    NT_STATUS_INVALID_DEVICE_REQUEST);
+
+       /* Same test on the second tcon */
+
+       nread = smbcli_read(tree2, fnum, buf, 0, sizeof(buf));
+       if (nread >= 0) {
+               d_printf("smbcli_read on a directory succeeded, expected "
+                        "failure\n");
+               ret = False;
+       }
+
+       CHECK_STATUS(smbcli_nt_error(tree2), NT_STATUS_INVALID_HANDLE);
+
+       smbcli_close(cli->tree, fnum);
+
+       /* Try a normal file read on a second tcon */
+
+       fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
+       if (fnum == -1) {
+               d_printf("Failed to create %s - %s\n", fname,
+                        smbcli_errstr(cli->tree));
+               ret = False;
+               goto done;
+       }
+
+       nread = smbcli_read(tree2, fnum, buf, 0, sizeof(buf));
+       CHECK_STATUS(smbcli_nt_error(tree2), NT_STATUS_INVALID_HANDLE);
+
+       smbcli_close(cli->tree, fnum);
+
+ done:
+       smbcli_deltree(cli->tree, dirname);
+       torture_close_connection(cli);
+       talloc_free(mem_ctx);
+
+       return ret;
+}
index d59de9459f1feee621145d377c18eb5042daae92..fd2423ab67606f2b22859b1b7acfe9aa6e8e2657 100644 (file)
@@ -22,6 +22,8 @@
 #include "system/filesys.h"
 #include "system/wait.h"
 #include "torture/torture.h"
+#include "libcli/raw/interfaces.h"
+#include "libcli/raw/libcliraw.h"
 
 /**
  create a temporary directory.
@@ -115,3 +117,43 @@ NTSTATUS torture_setup_server(TALLOC_CTX *mem_ctx,
 
        return NT_STATUS_OK;
 }
+
+NTSTATUS torture_second_tcon(TALLOC_CTX *mem_ctx,
+                            struct smbcli_session *session,
+                            const char *sharename,
+                            struct smbcli_tree **res)
+{
+       union smb_tcon tcon;
+       struct smbcli_tree *result;
+       TALLOC_CTX *tmp_ctx;
+       NTSTATUS status;
+
+       if ((tmp_ctx = talloc_new(mem_ctx)) == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       result = smbcli_tree_init(session, tmp_ctx, False);
+       if (result == NULL) {
+               talloc_free(tmp_ctx);
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       tcon.generic.level = RAW_TCON_TCONX;
+       tcon.tconx.in.flags = 0;
+
+       /* Ignore share mode security here */
+       tcon.tconx.in.password = data_blob(NULL, 0);
+       tcon.tconx.in.path = sharename;
+       tcon.tconx.in.device = "?????";
+
+       status = smb_raw_tcon(result, tmp_ctx, &tcon);
+       if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(tmp_ctx);
+               return status;
+       }
+
+       result->tid = tcon.tconx.out.tid;
+       *res = talloc_steal(mem_ctx, result);
+       talloc_free(tmp_ctx);
+       return NT_STATUS_OK;
+}