r3633: - moved module init functions to after smb.conf and command line
authorAndrew Tridgell <tridge@samba.org>
Tue, 9 Nov 2004 09:26:47 +0000 (09:26 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:05:41 +0000 (13:05 -0500)
  parsing, so that module init can take account of lp_ parms (thats
  why gensec:krb5=no wasn't working)

- added a BASE-DISCONNECT torture test that tests server response to
  clients disconnecting with open lock and open requests pending
(This used to be commit 5205f598b8c0be6985e61cc842cc5da109ba5b7e)

source4/client/client.c
source4/torture/basic/disconnect.c [new file with mode: 0644]
source4/torture/config.mk
source4/torture/gentest.c
source4/torture/locktest.c
source4/torture/masktest.c
source4/torture/torture.c
source4/utils/net/net.c
source4/utils/ntlm_auth.c

index 9c797e863cf5cefff213a850962c9e223f228ab3..81bf2a79305654f851663f9607a3914dc3a914d1 100644 (file)
@@ -3022,8 +3022,6 @@ static void remember_query_host(const char *arg,
                POPT_TABLEEND
        };
        
-       smbclient_init_subsystems;
-
 #ifdef KANJI
        pstrcpy(term_code, KANJI);
 #else /* KANJI */
@@ -3092,6 +3090,8 @@ static void remember_query_host(const char *arg,
 
        load_interfaces();
 
+       smbclient_init_subsystems;
+
        if(poptPeekArg(pc)) {
                pstrcpy(service,poptGetArg(pc));  
                /* Convert any '/' characters in the service name to '\' characters */
diff --git a/source4/torture/basic/disconnect.c b/source4/torture/basic/disconnect.c
new file mode 100644 (file)
index 0000000..b5f6eb5
--- /dev/null
@@ -0,0 +1,163 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   test server handling of unexpected client disconnects
+
+   Copyright (C) Andrew Tridgell 2004
+   
+   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 "libcli/raw/libcliraw.h"
+
+#define BASEDIR "\\test_disconnect"
+
+#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)); \
+               talloc_free(cli); \
+               return False; \
+       }} while (0)
+
+/*
+  test disconnect after async open
+*/
+static BOOL test_disconnect_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+{
+       union smb_open io;
+       NTSTATUS status;
+       struct smbcli_request *req1, *req2;
+
+       printf("trying open/disconnect\n");
+
+       io.generic.level = RAW_OPEN_NTCREATEX;
+       io.ntcreatex.in.root_fid = 0;
+       io.ntcreatex.in.flags = 0;
+       io.ntcreatex.in.access_mask = SA_RIGHT_FILE_READ_DATA;
+       io.ntcreatex.in.create_options = 0;
+       io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+       io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ;
+       io.ntcreatex.in.alloc_size = 0;
+       io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
+       io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
+       io.ntcreatex.in.security_flags = 0;
+       io.ntcreatex.in.fname = BASEDIR "\\open.dat";
+       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       req1 = smb_raw_open_send(cli->tree, &io);
+       req2 = smb_raw_open_send(cli->tree, &io);
+       
+       talloc_free(cli);
+
+       return True;
+}
+
+
+/*
+  test disconnect with timed lock
+*/
+static BOOL test_disconnect_lock(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+{
+       union smb_lock io;
+       NTSTATUS status;
+       int fnum;
+       struct smbcli_request *req;
+       struct smb_lock_entry lock[1];
+
+       printf("trying disconnect with async lock\n");
+
+       fnum = smbcli_open(cli->tree, BASEDIR "\\write.dat", 
+                          O_RDWR | O_CREAT, DENY_NONE);
+       if (fnum == -1) {
+               printf("open failed in mux_write - %s\n", smbcli_errstr(cli->tree));
+               return False;
+       }
+
+       io.lockx.level = RAW_LOCK_LOCKX;
+       io.lockx.in.fnum = fnum;
+       io.lockx.in.mode = 0;
+       io.lockx.in.timeout = 0;
+       io.lockx.in.lock_cnt = 1;
+       io.lockx.in.ulock_cnt = 0;
+       lock[0].pid = 1;
+       lock[0].offset = 0;
+       lock[0].count = 4;
+       io.lockx.in.locks = &lock[0];
+
+       status = smb_raw_lock(cli->tree, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       lock[0].pid = 2;
+       io.lockx.in.timeout = 3000;
+       req = smb_raw_lock_send(cli->tree, &io);
+
+       talloc_free(cli);
+
+       return True;
+}
+
+
+
+/* 
+   basic testing of disconnects
+*/
+BOOL torture_disconnect(void)
+{
+       struct smbcli_state *cli;
+       BOOL ret = True;
+       TALLOC_CTX *mem_ctx;
+       int i;
+
+       mem_ctx = talloc_init("torture_raw_mux");
+
+       if (!torture_open_connection(&cli)) {
+               return False;
+       }
+
+       /* cleanup */
+       if (smbcli_deltree(cli->tree, BASEDIR) == -1) {
+               printf("(%s) Failed to cleanup " BASEDIR "\n", __location__);
+               ret = False;
+               goto done;
+       }
+
+       if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
+               printf("Failed to create %s\n", BASEDIR);
+               ret = False;
+               goto done;
+       }
+
+       for (i=0;i<100;i++) {
+               ret &= test_disconnect_lock(cli, mem_ctx);
+               if (!torture_open_connection(&cli)) {
+                       return False;
+               }
+
+               ret &= test_disconnect_open(cli, mem_ctx);
+               if (!torture_open_connection(&cli)) {
+                       return False;
+               }
+       }
+
+done:
+       smb_raw_exit(cli->session);
+       smbcli_deltree(cli->tree, BASEDIR);
+       torture_close_connection(cli);
+       talloc_destroy(mem_ctx);
+       return ret;
+}
index 8a621e2f9f615341ebdc2d9c46ca71d8889d3bff..b2b301babde8894bc016f8317dec9246a9d063f4 100644 (file)
@@ -16,6 +16,7 @@ ADD_OBJ_FILES = \
                torture/basic/dir.o \
                torture/basic/delete.o \
                torture/basic/unlink.o \
+               torture/basic/disconnect.o \
                torture/basic/attr.o 
 REQUIRED_SUBSYSTEMS = \
                LIBSMB
index 563703bd2a79c7762fa0d6654e42259c7916d48b..4d3820793f5d8086ec462c2757188180fa999bc2 100644 (file)
@@ -2107,8 +2107,6 @@ static void usage(void)
 
        setup_logging(argv[0], DEBUG_STDOUT);
 
-       gentest_init_subsystems;
-
        for (i=0;i<NSERVERS;i++) {
                const char *share = argv[1+i];
                if (!split_unc_name(share, &servers[i].server_name, &servers[i].share_name)) {
@@ -2185,6 +2183,8 @@ static void usage(void)
                }
        }
 
+       gentest_init_subsystems;
+
        if (!servers[0].username) {
                usage();
                return -1;
index 9725bc37ec751a77dce1a51582a08375b6eb7692..d25625df1e067c1e6923e93068c8094eb65f99af 100644 (file)
@@ -459,8 +459,6 @@ static void usage(void)
        int opt;
        int seed, server, i;
 
-       locktest_init_subsystems;
-
        setlinebuf(stdout);
 
        setup_logging("locktest", DEBUG_STDOUT);
@@ -550,6 +548,8 @@ static void usage(void)
                servers[1].password = servers[0].password;
        }
 
+       locktest_init_subsystems;
+
        argc -= optind;
        argv += optind;
 
index bb0abf4b3e1ad7310bc0b02f478c643fb26e1b26..c0890118c305c87a7b94fadf538fd50b5c49632d 100644 (file)
@@ -277,8 +277,6 @@ static void usage(void)
        char *p;
        int seed;
 
-       masktest_init_subsystems;
-
        setlinebuf(stdout);
 
        setup_logging("masktest", DEBUG_STDOUT);
@@ -362,10 +360,11 @@ static void usage(void)
                }
        }
 
+       masktest_init_subsystems;
+
        argc -= optind;
        argv += optind;
 
-
        cli = connect_one(share);
        if (!cli) {
                DEBUG(0,("Failed to connect to %s\n", share));
index daf2da9c03467e3a5d76de8b94122b900ce1fc96..ce8b79943d3a52004ae08a0af629a1e88cf242bb 100644 (file)
@@ -2390,6 +2390,7 @@ static struct {
        {"BASE-CHARSET", torture_charset, 0},
        {"BASE-CHKPATH",  torture_chkpath_test, 0},
        {"BASE-SECLEAK",  torture_sec_leak, 0},
+       {"BASE-DISCONNECT",  torture_disconnect, 0},
 
        /* benchmarking tests */
        {"BENCH-HOLDCON",  torture_holdcon, 0},
@@ -2633,8 +2634,6 @@ static BOOL is_binding_string(const char *binding_string)
                POPT_TABLEEND
        };
 
-       smbtorture_init_subsystems;
-
        setup_logging("smbtorture", DEBUG_STDOUT);
 
 #ifdef HAVE_SETBUFFER
@@ -2673,6 +2672,10 @@ static BOOL is_binding_string(const char *binding_string)
 
        lp_load(dyn_CONFIGFILE,True,False,False);
        load_interfaces();
+
+       smbtorture_init_subsystems;
+
+
        if (torture_seed == 0) {
                torture_seed = time(NULL);
        } 
index dcd663d3fd5d02c5cca5da5e4d535ad1812c5b29..ac427c49353f1a2a33ef45bff4d3f64ce6366209 100644 (file)
@@ -207,6 +207,8 @@ static int binary_net(int argc, const char **argv)
                return 1;
        }
 
+       net_init_subsystems;
+
        mem_ctx = talloc_init("net_context");
        ctx = talloc_p(mem_ctx, struct net_context);
        if (!ctx) {
@@ -232,6 +234,5 @@ static int binary_net(int argc, const char **argv)
 
  int main(int argc, const char **argv)
 {
-       net_init_subsystems;
        return binary_net(argc, argv);
 }
index 5cc02ffbb25ba8d98b687e7efcfbf68fbbe3fa22..23586b1db598f09fa3f31b07d684164a68ccc528 100644 (file)
@@ -861,8 +861,6 @@ enum {
                POPT_TABLEEND
        };
 
-       ntlm_auth_init_subsystems;
-
        /* Samba client initialisation */
 
        setup_logging("ntlm_auth", DEBUG_STDERR);
@@ -899,6 +897,9 @@ enum {
                return 1;
        }
 
+       ntlm_auth_init_subsystems;
+
+
        if (opt_domain == NULL) {
                opt_domain = lp_workgroup();
        }