r12558: Support [flag(NULLTERM)] on [charset()] arrays
[samba.git] / source4 / torture / torture.c
index bc4feef3e9bfc68f540aa7bd3aa9d12f3532e9b2..1b591c6bb84cc932334edb03d04e12d1a358d261 100644 (file)
 */
 
 #include "includes.h"
-#include "dynconfig.h"
 #include "clilist.h"
 #include "lib/cmdline/popt_common.h"
 #include "libcli/raw/libcliraw.h"
 #include "system/time.h"
 #include "system/wait.h"
+#include "system/filesys.h"
 #include "ioctl.h"
 #include "librpc/gen_ndr/ndr_security.h"
+#include "smb_build.h"
+#include "libcli/nbt/libnbt.h"
 
 int torture_nprocs=4;
-int torture_numops=100;
+int torture_numops=10;
 int torture_entries=1000;
 int torture_failures=1;
 int torture_seed=0;
@@ -44,66 +46,48 @@ BOOL torture_showall = False;
 
 static struct smbcli_state *open_nbt_connection(void)
 {
-       struct nmb_name called, calling;
+       struct nbt_name called, calling;
        struct smbcli_state *cli;
        const char *host = lp_parm_string(-1, "torture", "host");
 
-       make_nmb_name(&calling, lp_netbios_name(), 0x0);
-       choose_called_name(&called, host, 0x20);
+       make_nbt_name_client(&calling, lp_netbios_name());
+
+       nbt_choose_called_name(NULL, &called, host, NBT_NAME_SERVER);
 
        cli = smbcli_state_init(NULL);
        if (!cli) {
                printf("Failed initialize smbcli_struct to connect with %s\n", host);
-               return NULL;
+               goto failed;
        }
 
        if (!smbcli_socket_connect(cli, host)) {
                printf("Failed to connect with %s\n", host);
-               return cli;
+               goto failed;
        }
 
-       cli->transport->socket->timeout = 120000; /* set a really long timeout (2 minutes) */
-
        if (!smbcli_transport_establish(cli, &calling, &called)) {
-               /*
-                * Well, that failed, try *SMBSERVER ... 
-                * However, we must reconnect as well ...
-                */
-               if (!smbcli_socket_connect(cli, host)) {
-                       printf("Failed to connect with %s\n", host);
-                       return False;
-               }
-
-               make_nmb_name(&called, "*SMBSERVER", 0x20);
-               if (!smbcli_transport_establish(cli, &calling, &called)) {
-                       printf("%s rejected the session\n",host);
-                       printf("We tried with a called name of %s & %s\n",
-                               host, "*SMBSERVER");
-                       smbcli_shutdown(cli);
-                       return NULL;
-               }
+               printf("%s rejected the session\n",host);
+               goto failed;
        }
 
        return cli;
+
+failed:
+       talloc_free(cli);
+       return NULL;
 }
 
-BOOL torture_open_connection_share(struct smbcli_state **c, 
+BOOL torture_open_connection_share(TALLOC_CTX *mem_ctx,
+                                  struct smbcli_state **c, 
                                   const char *hostname, 
-                                  const char *sharename)
+                                  const char *sharename,
+                                  struct event_context *ev)
 {
-       BOOL retry;
-       int flags = 0;
        NTSTATUS status;
-       const char *username = lp_parm_string(-1, "torture", "username");
-       const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
-       const char *password = lp_parm_string(-1, "torture", "password");
 
-       status = smbcli_full_connection(NULL,
-                                       c, lp_netbios_name(),
-                                       hostname, NULL, 
-                                       sharename, "?????", 
-                                       username, username[0]?userdomain:"",
-                                       password, flags, &retry);
+       status = smbcli_full_connection(mem_ctx, c, hostname, 
+                                       sharename, NULL,
+                                       cmdline_credentials, ev);
        if (!NT_STATUS_IS_OK(status)) {
                printf("Failed to open connection - %s\n", nt_errstr(status));
                return False;
@@ -111,7 +95,6 @@ BOOL torture_open_connection_share(struct smbcli_state **c,
 
        (*c)->transport->options.use_oplocks = use_oplocks;
        (*c)->transport->options.use_level2_oplocks = use_level_II_oplocks;
-       (*c)->transport->socket->timeout = 120000;
 
        return True;
 }
@@ -121,7 +104,7 @@ BOOL torture_open_connection(struct smbcli_state **c)
        const char *host = lp_parm_string(-1, "torture", "host");
        const char *share = lp_parm_string(-1, "torture", "share");
 
-       return torture_open_connection_share(c, host, share);
+       return torture_open_connection_share(NULL, c, host, share, NULL);
 }
 
 
@@ -134,25 +117,14 @@ BOOL torture_close_connection(struct smbcli_state *c)
                printf("tdis failed (%s)\n", smbcli_errstr(c->tree));
                ret = False;
        }
-       smbcli_shutdown(c);
+       talloc_free(c);
        return ret;
 }
 
-/* initialise a DCOM context */
-NTSTATUS torture_dcom_init(struct dcom_context **ctx)
-{
-       dcom_init(ctx, lp_parm_string(-1, "torture", "userdomain"),
-                                       lp_parm_string(-1, "torture", "username"), 
-                                       lp_parm_string(-1, "torture", "password"));
-
-       return NT_STATUS_OK;
-}
-
 /* open a rpc connection to the chosen binding string */
-NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p, 
-                               const char *pipe_name,
-                               const char *pipe_uuid, 
-                               uint32_t pipe_version)
+NTSTATUS torture_rpc_connection(TALLOC_CTX *parent_ctx, 
+                               struct dcerpc_pipe **p, 
+                               const struct dcerpc_interface_table *table)
 {
         NTSTATUS status;
        const char *binding = lp_parm_string(-1, "torture", "binding");
@@ -162,84 +134,71 @@ NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       status = dcerpc_pipe_connect(p, binding, pipe_uuid, pipe_version,
-                                    lp_parm_string(-1, "torture", "userdomain"), 
-                                    lp_parm_string(-1, "torture", "username"),
-                                    lp_parm_string(-1, "torture", "password"));
+       status = dcerpc_pipe_connect(parent_ctx, 
+                                    p, binding, table,
+                                    cmdline_credentials, NULL);
  
         return status;
 }
 
 /* open a rpc connection to a specific transport */
-NTSTATUS torture_rpc_connection_transport(struct dcerpc_pipe **p, 
-                                         const char *pipe_name,
-                                         const char *pipe_uuid, 
-                                         uint32_t pipe_version,
+NTSTATUS torture_rpc_connection_transport(TALLOC_CTX *parent_ctx, 
+                                         struct dcerpc_pipe **p, 
+                                         const struct dcerpc_interface_table *table,
                                          enum dcerpc_transport_t transport)
 {
         NTSTATUS status;
        const char *binding = lp_parm_string(-1, "torture", "binding");
-       struct dcerpc_binding b;
-       TALLOC_CTX *mem_ctx = talloc_init("torture_rpc_connection_smb");
+       struct dcerpc_binding *b;
+       TALLOC_CTX *mem_ctx = talloc_named(parent_ctx, 0, "torture_rpc_connection_smb");
 
        if (!binding) {
                printf("You must specify a ncacn binding string\n");
+               talloc_free(mem_ctx);
                return NT_STATUS_INVALID_PARAMETER;
        }
 
        status = dcerpc_parse_binding(mem_ctx, binding, &b);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("Failed to parse dcerpc binding '%s'\n", binding));
-               talloc_destroy(mem_ctx);
+               talloc_free(mem_ctx);
                return status;
        }
 
-       b.transport = transport;
+       b->transport = transport;
 
-       status = dcerpc_pipe_connect_b(p, &b, pipe_uuid, pipe_version,
-                                      lp_parm_string(-1, "torture", "userdomain"), 
-                                      lp_parm_string(-1, "torture", "username"),
-                                      lp_parm_string(-1, "torture", "password"));
+       status = dcerpc_pipe_connect_b(mem_ctx, p, b, table,
+                                      cmdline_credentials, NULL);
+                                          
+       if (NT_STATUS_IS_OK(status)) {
+               *p = talloc_reference(parent_ctx, *p);
+       } else {
+               *p = NULL;
+       }
+       talloc_free(mem_ctx);
         return status;
 }
 
-/* close a rpc connection to a named pipe */
-NTSTATUS torture_rpc_close(struct dcerpc_pipe *p)
-{
-       dcerpc_pipe_close(p);
-       return NT_STATUS_OK;
-}
-
-
 /* check if the server produced the expected error code */
 BOOL check_error(const char *location, struct smbcli_state *c, 
                 uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
 {
-        if (smbcli_is_dos_error(c->tree)) {
-                uint8_t class;
-                uint32_t num;
-
-                /* Check DOS error */
-
-                smbcli_dos_error(c, &class, &num);
-
+       NTSTATUS status;
+       
+       status = smbcli_nt_error(c->tree);
+       if (NT_STATUS_IS_DOS(status)) {
+               int class, num;
+               class = NT_STATUS_DOS_CLASS(status);
+               num = NT_STATUS_DOS_CODE(status);
                 if (eclass != class || ecode != num) {
-                        printf("unexpected error code class=%d code=%d\n", 
-                               (int)class, (int)num);
-                        printf(" expected %d/%d %s (at %s)\n"
-                               (int)eclass, (int)ecode, nt_errstr(nterr), location);
+                        printf("unexpected error code %s\n", nt_errstr(status));
+                        printf(" expected %s or %s (at %s)\n", 
+                              nt_errstr(NT_STATUS_DOS(eclass, ecode))
+                               nt_errstr(nterr), location);
                         return False;
                 }
-
         } else {
-                NTSTATUS status;
-
-                /* Check NT error */
-
-                status = smbcli_nt_error(c->tree);
-
-                if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
+                if (!NT_STATUS_EQUAL(nterr, status)) {
                         printf("unexpected error code %s\n", nt_errstr(status));
                         printf(" expected %s (at %s)\n", nt_errstr(nterr), location);
                         return False;
@@ -281,7 +240,7 @@ static BOOL rw_torture(struct smbcli_state *c)
 
 
        for (i=0;i<torture_numops;i++) {
-               uint_t n = (uint_t)sys_random()%10;
+               uint_t n = (uint_t)random()%10;
                if (i % 10 == 0) {
                        printf("%d\r", i); fflush(stdout);
                }
@@ -362,104 +321,6 @@ static BOOL run_torture(struct smbcli_state *cli, int dummy)
        return ret;
 }
 
-static BOOL rw_torture3(struct smbcli_state *c, const char *lockfname)
-{
-       int fnum = -1;
-       uint_t i = 0;
-       uint8_t buf[131072];
-       uint8_t buf_rd[131072];
-       uint_t count;
-       uint_t countprev = 0;
-       ssize_t sent = 0;
-       BOOL correct = True;
-
-       for (i = 0; i < sizeof(buf); i += sizeof(uint32_t))
-       {
-               SIVAL(buf, i, sys_random());
-       }
-
-       if (procnum == 0)
-       {
-               fnum = smbcli_open(c->tree, lockfname, O_RDWR | O_CREAT | O_EXCL, 
-                               DENY_NONE);
-               if (fnum == -1) {
-                       printf("first open read/write of %s failed (%s)\n",
-                                       lockfname, smbcli_errstr(c->tree));
-                       return False;
-               }
-       }
-       else
-       {
-               for (i = 0; i < 500 && fnum == -1; i++)
-               {
-                       fnum = smbcli_open(c->tree, lockfname, O_RDONLY, 
-                                       DENY_NONE);
-                       msleep(10);
-               }
-               if (fnum == -1) {
-                       printf("second open read-only of %s failed (%s)\n",
-                                       lockfname, smbcli_errstr(c->tree));
-                       return False;
-               }
-       }
-
-       i = 0;
-       for (count = 0; count < sizeof(buf); count += sent)
-       {
-               if (count >= countprev) {
-                       printf("%d %8d\r", i, count);
-                       fflush(stdout);
-                       i++;
-                       countprev += (sizeof(buf) / 20);
-               }
-
-               if (procnum == 0)
-               {
-                       sent = ((uint_t)sys_random()%(20))+ 1;
-                       if (sent > sizeof(buf) - count)
-                       {
-                               sent = sizeof(buf) - count;
-                       }
-
-                       if (smbcli_write(c->tree, fnum, 0, buf+count, count, (size_t)sent) != sent) {
-                               printf("write failed (%s)\n", smbcli_errstr(c->tree));
-                               correct = False;
-                       }
-               }
-               else
-               {
-                       sent = smbcli_read(c->tree, fnum, buf_rd+count, count,
-                                       sizeof(buf)-count);
-                       if (sent < 0)
-                       {
-                               printf("read failed offset:%d size:%d (%s)\n",
-                                               count, sizeof(buf)-count,
-                                               smbcli_errstr(c->tree));
-                               correct = False;
-                               sent = 0;
-                       }
-                       if (sent > 0)
-                       {
-                               if (memcmp(buf_rd+count, buf+count, sent) != 0)
-                               {
-                                       printf("read/write compare failed\n");
-                                       printf("offset: %d req %d recvd %d\n",
-                                               count, sizeof(buf)-count, sent);
-                                       correct = False;
-                                       break;
-                               }
-                       }
-               }
-
-       }
-
-       if (NT_STATUS_IS_ERR(smbcli_close(c->tree, fnum))) {
-               printf("close failed (%s)\n", smbcli_errstr(c->tree));
-               correct = False;
-       }
-
-       return correct;
-}
 
 static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
 {
@@ -496,7 +357,7 @@ static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
 
        for (i=0;i<torture_numops;i++)
        {
-               size_t buf_size = ((uint_t)sys_random()%(sizeof(buf)-1))+ 1;
+               size_t buf_size = ((uint_t)random()%(sizeof(buf)-1))+ 1;
                if (i % 10 == 0) {
                        printf("%d\r", i); fflush(stdout);
                }
@@ -505,14 +366,14 @@ static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
 
                if ((bytes_written = smbcli_write(c1->tree, fnum1, 0, buf, 0, buf_size)) != buf_size) {
                        printf("write failed (%s)\n", smbcli_errstr(c1->tree));
-                       printf("wrote %d, expected %d\n", bytes_written, buf_size); 
+                       printf("wrote %d, expected %d\n", (int)bytes_written, (int)buf_size); 
                        correct = False;
                        break;
                }
 
                if ((bytes_read = smbcli_read(c2->tree, fnum2, buf_rd, 0, buf_size)) != buf_size) {
                        printf("read failed (%s)\n", smbcli_errstr(c2->tree));
-                       printf("read %d, expected %d\n", bytes_read, buf_size); 
+                       printf("read %d, expected %d\n", (int)bytes_read, (int)buf_size); 
                        correct = False;
                        break;
                }
@@ -542,6 +403,8 @@ static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
        return correct;
 }
 
+#define BOOLSTR(b) ((b) ? "Yes" : "No")
+
 static BOOL run_readwritetest(void)
 {
        struct smbcli_state *cli1, *cli2;
@@ -572,20 +435,6 @@ static BOOL run_readwritetest(void)
        return (test1 && test2);
 }
 
-static BOOL run_readwritemulti(struct smbcli_state *cli, int dummy)
-{
-       BOOL test;
-
-       test = rw_torture3(cli, "\\multitest.txt");
-
-       if (!torture_close_connection(cli)) {
-               test = False;
-       }
-       
-       return test;
-}
-
-
 /*
   this checks to see if a secondary tconx can use open files from an
   earlier tconx
@@ -630,10 +479,10 @@ static BOOL run_tcon_test(void)
        }
 
        tree1 = cli->tree;      /* save old tree connection */
-       if (NT_STATUS_IS_ERR(smbcli_send_tconX(cli, share, "?????", password))) {
+       if (NT_STATUS_IS_ERR(smbcli_tconX(cli, share, "?????", password))) {
                printf("%s refused 2nd tree connect (%s)\n", host,
                           smbcli_errstr(cli->tree));
-               smbcli_shutdown(cli);
+               talloc_free(cli);
                return False;
        }
 
@@ -691,6 +540,8 @@ static BOOL run_tcon_test(void)
        cli->tree = tree1;  /* restore initial tree */
        cli->tree->tid = cnum1;
 
+       smbcli_unlink(tree1, fname);
+
        if (!torture_close_connection(cli)) {
                return False;
        }
@@ -708,7 +559,7 @@ static BOOL tcon_devtest(struct smbcli_state *cli,
        BOOL ret;
        const char *password = lp_parm_string(-1, "torture", "password");
 
-       status = NT_STATUS_IS_OK(smbcli_send_tconX(cli, myshare, devtype, 
+       status = NT_STATUS_IS_OK(smbcli_tconX(cli, myshare, devtype, 
                                                password));
 
        printf("Trying share %s with devtype %s\n", myshare, devtype);
@@ -748,22 +599,15 @@ static BOOL tcon_devtest(struct smbcli_state *cli,
 static BOOL run_tcon_devtype_test(void)
 {
        struct smbcli_state *cli1 = NULL;
-       BOOL retry;
-       int flags = 0;
        NTSTATUS status;
        BOOL ret = True;
        const char *host = lp_parm_string(-1, "torture", "host");
        const char *share = lp_parm_string(-1, "torture", "share");
-       const char *username = lp_parm_string(-1, "torture", "username");
-       const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
-       const char *password = lp_parm_string(-1, "torture", "password");
        
        status = smbcli_full_connection(NULL,
-                                       &cli1, lp_netbios_name(),
-                                       host, NULL, 
-                                       share, "?????",
-                                       username, userdomain,
-                                       password, flags, &retry);
+                                       &cli1, host, 
+                                       share, NULL,
+                                       cmdline_credentials, NULL);
 
        if (!NT_STATUS_IS_OK(status)) {
                printf("could not open connection\n");
@@ -800,7 +644,7 @@ static BOOL run_tcon_devtype_test(void)
        if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
                ret = False;
 
-       smbcli_shutdown(cli1);
+       talloc_free(cli1);
 
        if (ret)
                printf("Passed tcondevtest\n");
@@ -1054,33 +898,17 @@ static BOOL run_negprot_nowait(void)
 
        printf("Filling send buffer\n");
 
-       for (i=0;i<10000;i++) {
+       for (i=0;i<1000;i++) {
                struct smbcli_request *req;
-               time_t t1 = time(NULL);
-               req = smb_negprot_send(cli->transport, PROTOCOL_NT1);
-               while (req->state == SMBCLI_REQUEST_SEND && time(NULL) < t1+5) {
-                       smbcli_transport_process(cli->transport);
-               }
+               req = smb_raw_negotiate_send(cli->transport, PROTOCOL_NT1);
+               smbcli_transport_process(cli->transport);
                if (req->state == SMBCLI_REQUEST_ERROR) {
                        printf("Failed to fill pipe - %s\n", nt_errstr(req->status));
                        torture_close_connection(cli);
                        return correct;
                }
-               if (req->state == SMBCLI_REQUEST_SEND) {
-                       break;
-               }
-       }
-
-       if (i == 10000) {
-               printf("send buffer failed to fill\n");
-               if (!torture_close_connection(cli)) {
-                       correct = False;
-               }
-               return correct;
        }
 
-       printf("send buffer filled after %d requests\n", i);
-
        printf("Opening secondary connection\n");
        if (!torture_open_connection(&cli2)) {
                return False;
@@ -1500,9 +1328,10 @@ static BOOL run_vuidtest(void)
                correct = False;
        }
 
-       if ( (cli->transport->error.etype != ETYPE_DOS) ||
-            (cli->transport->error.e.dos.eclass != ERRSRV) ||
-            (cli->transport->error.e.dos.ecode != ERRbaduid) ) {
+       if (!NT_STATUS_EQUAL(cli->transport->error.e.nt_status, 
+                            NT_STATUS_DOS(ERRSRV, ERRbaduid)) &&
+           !NT_STATUS_EQUAL(cli->transport->error.e.nt_status, 
+                            NT_STATUS_INVALID_HANDLE)) {
                printf("ERROR: qfileinfo should have returned DOS error "
                       "ERRSRV:ERRbaduid\n  but returned %s\n",
                       smbcli_errstr(cli->tree));
@@ -1535,12 +1364,14 @@ static BOOL run_vuidtest(void)
        static struct smbcli_state *cli1;
        static struct smbcli_state *cli2;
        const char *fname = "\\readonly.file";
+       char *control_char_fname;
        int fnum1, fnum2;
        uint8_t buf[20];
        size_t fsize;
        BOOL correct = True;
        char *tmp_path;
        int failures = 0;
+       int i;
 
        printf("starting open test\n");
        
@@ -1548,6 +1379,30 @@ static BOOL run_vuidtest(void)
                return False;
        }
        
+       asprintf(&control_char_fname, "\\readonly.afile");
+       for (i = 1; i <= 0x1f; i++) {
+               control_char_fname[10] = i;
+               fnum1 = smbcli_nt_create_full(cli1->tree, control_char_fname, 0, SEC_FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,
+                                  NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
+               
+               if (!check_error(__location__, cli1, ERRDOS, ERRinvalidname, 
+                               NT_STATUS_OBJECT_NAME_INVALID)) {
+                       printf("Error code should be NT_STATUS_OBJECT_NAME_INVALID, was %s for file with %d char\n",
+                                       smbcli_errstr(cli1->tree), i);
+                       failures++;
+               }
+
+               if (fnum1 != -1) {
+                       smbcli_close(cli1->tree, fnum1);
+               }
+               smbcli_setatr(cli1->tree, control_char_fname, 0, 0);
+               smbcli_unlink(cli1->tree, control_char_fname);
+       }
+       free(control_char_fname);
+
+       if (!failures)
+               printf("Create file with control char names passed.\n");
+
        smbcli_setatr(cli1->tree, fname, 0, 0);
        smbcli_unlink(cli1->tree, fname);
        
@@ -2060,7 +1915,7 @@ BOOL torture_ioctl_test(void)
 
                        if (NT_STATUS_IS_OK(status)) {
                                printf("ioctl device=0x%x function=0x%x OK : %d bytes\n", 
-                                       device, function, parms.ioctl.out.blob.length);
+                                       device, function, (int)parms.ioctl.out.blob.length);
                        }
                }
        }
@@ -2131,7 +1986,7 @@ BOOL torture_chkpath_test(void)
        }
 
        if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\bar.txt"))) {
-               ret = check_error(__location__, cli, ERRDOS, ERRbadfile
+               ret = check_error(__location__, cli, ERRDOS, ERRbadpath
                                  NT_STATUS_OBJECT_NAME_NOT_FOUND);
        } else {
                printf("* chkpath on a non existent file should fail\n");
@@ -2158,30 +2013,6 @@ BOOL torture_chkpath_test(void)
 }
 
 
-/*
-  parse a //server/share type UNC name
-*/
-static BOOL parse_unc(const char *unc_name, char **hostname, char **sharename)
-{
-       char *p;
-
-       if (strncmp(unc_name, "//", 2)) {
-               return False;
-       }
-
-       *hostname = strdup(&unc_name[2]);
-       p = strchr_m(&(*hostname)[2],'/');
-       if (!p) {
-               return False;
-       }
-       *p = 0;
-       *sharename = strdup(p+1);
-
-       return True;
-}
-
-
-
 static void sigcont(int sig)
 {
 }
@@ -2219,7 +2050,7 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
 
        p = lp_parm_string(-1, "torture", "unclist");
        if (p) {
-               unc_list = file_lines_load(p, &num_unc_names);
+               unc_list = file_lines_load(p, &num_unc_names, NULL);
                if (!unc_list || num_unc_names <= 0) {
                        printf("Failed to load unc names list from '%s'\n", p);
                        exit(1);
@@ -2237,10 +2068,10 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
                procnum = i;
                if (fork() == 0) {
                        char *myname;
-                       char *hostname=NULL, *sharename;
+                       const char *hostname=NULL, *sharename;
 
                        pid_t mypid = getpid();
-                       sys_srandom(((int)mypid) ^ ((int)time(NULL)));
+                       srandom(((int)mypid) ^ ((int)time(NULL)));
 
                        asprintf(&myname, "CLIENT%d", i);
                        lp_set_cmdline("netbios name", myname);
@@ -2248,8 +2079,8 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
 
 
                        if (unc_list) {
-                               if (!parse_unc(unc_list[i % num_unc_names],
-                                              &hostname, &sharename)) {
+                               if (!smbcli_parse_unc(unc_list[i % num_unc_names],
+                                                     NULL, &hostname, &sharename)) {
                                        printf("Failed to parse UNC name %s\n",
                                               unc_list[i % num_unc_names]);
                                        exit(1);
@@ -2258,9 +2089,11 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
 
                        while (1) {
                                if (hostname) {
-                                       if (torture_open_connection_share(&current_cli,
+                                       if (torture_open_connection_share(NULL,
+                                                                         &current_cli,
                                                                          hostname, 
-                                                                         sharename)) {
+                                                                         sharename,
+                                                                         NULL)) {
                                                break;
                                        }
                                } else if (torture_open_connection(&current_cli)) {
@@ -2317,7 +2150,7 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
 
        for (i=0;i<torture_nprocs;i++) {
                int ret;
-               while ((ret=sys_waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
+               while ((ret=waitpid(0, &status, 0)) == -1 && errno == EINTR) /* noop */ ;
                if (ret == -1 || WEXITSTATUS(status) != 0) {
                        *result = False;
                }
@@ -2365,7 +2198,6 @@ static struct {
        {"BASE-TCONDEV",  run_tcon_devtype_test, 0},
        {"BASE-VUID", run_vuidtest, 0},
        {"BASE-RW1",  run_readwritetest, 0},
-       {"BASE-RW2",  NULL, run_readwritemulti},
        {"BASE-OPEN", run_opentest, 0},
        {"BASE-DEFER_OPEN", NULL, run_deferopen},
        {"BASE-XCOPY", run_xcopy, 0},
@@ -2384,6 +2216,10 @@ static struct {
        {"BENCH-HOLDCON",  torture_holdcon, 0},
        {"BENCH-NBENCH",  torture_nbench, 0},
        {"BENCH-TORTURE", NULL, run_torture},
+       {"BENCH-NBT",     torture_bench_nbt, 0},
+       {"BENCH-WINS",    torture_bench_wins, 0},
+       {"BENCH-RPC",     torture_bench_rpc, 0},
+       {"BENCH-CLDAP",   torture_bench_cldap, 0},
 
        /* RAW smb tests */
        {"RAW-QFSINFO", torture_raw_qfsinfo, 0},
@@ -2407,9 +2243,21 @@ static struct {
        {"RAW-RENAME", torture_raw_rename, 0},
        {"RAW-SEEK", torture_raw_seek, 0},
        {"RAW-EAS", torture_raw_eas, 0},
+       {"RAW-EAMAX", torture_max_eas, 0},
        {"RAW-STREAMS", torture_raw_streams, 0},
        {"RAW-ACLS", torture_raw_acls, 0},
        {"RAW-RAP", torture_raw_rap, 0},
+       {"RAW-COMPOSITE", torture_raw_composite, 0},
+
+       /* SMB2 tests */
+       {"SMB2-CONNECT", torture_smb2_connect, 0},
+       {"SMB2-SCAN", torture_smb2_scan, 0},
+       {"SMB2-SCANGETINFO", torture_smb2_getinfo_scan, 0},
+       {"SMB2-SCANSETINFO", torture_smb2_setinfo_scan, 0},
+       {"SMB2-SCANFIND", torture_smb2_find_scan, 0},
+       {"SMB2-GETINFO", torture_smb2_getinfo, 0},
+       {"SMB2-SETINFO", torture_smb2_setinfo, 0},
+       {"SMB2-FIND", torture_smb2_find, 0},
 
        /* protocol scanners */
        {"SCAN-TRANS2", torture_trans2_scan, 0},
@@ -2421,13 +2269,16 @@ static struct {
        {"SCAN-CASETABLE", torture_casetable, 0},
        {"SCAN-PIPE_NUMBER", run_pipe_number, 0},
        {"SCAN-IOCTL",  torture_ioctl_test, 0},
+       {"SCAN-RAP",  torture_rap_scan, 0},
 
        /* rpc testers */
         {"RPC-LSA", torture_rpc_lsa, 0},
+        {"RPC-SECRETS", torture_rpc_lsa_secrets, 0},
         {"RPC-ECHO", torture_rpc_echo, 0},
         {"RPC-DFS", torture_rpc_dfs, 0},
         {"RPC-SPOOLSS", torture_rpc_spoolss, 0},
         {"RPC-SAMR", torture_rpc_samr, 0},
+        {"RPC-UNIXINFO", torture_rpc_unixinfo, 0},
         {"RPC-NETLOGON", torture_rpc_netlogon, 0},
         {"RPC-SAMLOGON", torture_rpc_samlogon, 0},
         {"RPC-SAMSYNC", torture_rpc_samsync, 0},
@@ -2439,6 +2290,7 @@ static struct {
         {"RPC-EVENTLOG", torture_rpc_eventlog, 0},
         {"RPC-EPMAPPER", torture_rpc_epmapper, 0},
         {"RPC-WINREG", torture_rpc_winreg, 0},
+        {"RPC-INITSHUTDOWN", torture_rpc_initshutdown, 0},
         {"RPC-OXIDRESOLVE", torture_rpc_oxidresolve, 0},
         {"RPC-REMACT", torture_rpc_remact, 0},
         {"RPC-MGMT", torture_rpc_mgmt, 0},
@@ -2447,24 +2299,56 @@ static struct {
         {"RPC-COUNTCALLS", torture_rpc_countcalls, 0},
        {"RPC-MULTIBIND", torture_multi_bind, 0},
        {"RPC-DRSUAPI", torture_rpc_drsuapi, 0},
-       {"RPC-LOGIN", torture_rpc_login, 0},
+       {"RPC-CRACKNAMES", torture_rpc_drsuapi_cracknames, 0},
        {"RPC-ROT", torture_rpc_rot, 0},
        {"RPC-DSSETUP", torture_rpc_dssetup, 0},
         {"RPC-ALTERCONTEXT", torture_rpc_alter_context, 0},
-
-       /* Distributed COM testers */
-       {"DCOM-SIMPLE", torture_dcom_simple, 0},
+        {"RPC-JOIN", torture_rpc_join, 0},
+        {"RPC-DSSYNC", torture_rpc_dssync, 0},
+               {"RPC-NDR", torture_rpc_ndr, 0},
 
        /* local (no server) testers */
        {"LOCAL-NTLMSSP", torture_ntlmssp_self_check, 0},
        {"LOCAL-ICONV", torture_local_iconv, 0},
        {"LOCAL-TALLOC", torture_local_talloc, 0},
        {"LOCAL-MESSAGING", torture_local_messaging, 0},
+       {"LOCAL-IRPC",  torture_local_irpc, 0},
        {"LOCAL-BINDING", torture_local_binding_string, 0},
+       {"LOCAL-STRLIST", torture_local_util_strlist, 0},
+       {"LOCAL-FILE", torture_local_util_file, 0},
        {"LOCAL-IDTREE", torture_local_idtree, 0},
+       {"LOCAL-SOCKET", torture_local_socket, 0},
+       {"LOCAL-PAC", torture_pac, 0},
+       {"LOCAL-REGISTRY", torture_registry, 0},
+       {"LOCAL-RESOLVE", torture_local_resolve, 0},
+       {"LOCAL-SDDL", torture_local_sddl, 0},
+
+       /* COM (Component Object Model) testers */
+       {"COM-SIMPLE", torture_com_simple, 0 },
 
        /* ldap testers */
        {"LDAP-BASIC", torture_ldap_basic, 0},
+       {"LDAP-CLDAP", torture_cldap, 0},
+
+       /* nbt tests */
+       {"NBT-REGISTER", torture_nbt_register, 0},
+       {"NBT-WINS", torture_nbt_wins, 0},
+       {"NBT-DGRAM", torture_nbt_dgram, 0},
+       {"NBT-WINSREPLICATION", torture_nbt_winsreplication, 0},
+       
+       /* libnet tests */
+       {"NET-USERINFO", torture_userinfo, 0},
+       {"NET-USERADD", torture_useradd, 0},
+       {"NET-USERDEL", torture_userdel, 0},
+       {"NET-USERMOD", torture_usermod, 0},
+       {"NET-DOMOPEN", torture_domainopen, 0},
+       {"NET-API-LOOKUP", torture_lookup, 0},
+       {"NET-API-LOOKUPHOST", torture_lookup_host, 0},
+       {"NET-API-LOOKUPPDC", torture_lookup_pdc, 0},
+       {"NET-API-CREATEUSER", torture_createuser, 0},
+       {"NET-API-RPCCONNECT", torture_rpc_connect, 0},
+       {"NET-API-LISTSHARES", torture_listshares, 0},
+       {"NET-API-DELSHARE", torture_delshare, 0},
 
        {NULL, NULL, 0}};
 
@@ -2632,15 +2516,21 @@ static void usage(poptContext pc)
 static BOOL is_binding_string(const char *binding_string)
 {
        TALLOC_CTX *mem_ctx = talloc_init("is_binding_string");
-       struct dcerpc_binding binding_struct;
+       struct dcerpc_binding *binding_struct;
        NTSTATUS status;
        
        status = dcerpc_parse_binding(mem_ctx, binding_string, &binding_struct);
 
-       talloc_destroy(mem_ctx);
+       talloc_free(mem_ctx);
        return NT_STATUS_IS_OK(status);
 }
 
+static void max_runtime_handler(int sig)
+{
+       DEBUG(0,("maximum runtime exceeded for smbtorture - terminating\n"));
+       exit(1);
+}
+
 /****************************************************************************
   main program
 ****************************************************************************/
@@ -2649,6 +2539,7 @@ static BOOL is_binding_string(const char *binding_string)
        int opt, i;
        char *p;
        BOOL correct = True;
+       int max_runtime=0;
        int argc_new;
        char **argv_new;
        poptContext pc;
@@ -2668,6 +2559,8 @@ static BOOL is_binding_string(const char *binding_string)
                {"failures",    'f', POPT_ARG_INT,  &torture_failures,  0,      "failures",     NULL},
                {"parse-dns",   'D', POPT_ARG_STRING,   NULL,   OPT_DNS,        "parse-dns",    NULL},
                {"dangerous",   'X', POPT_ARG_NONE,     NULL,   OPT_DANGEROUS,  "dangerous",    NULL},
+               {"maximum-runtime", 0, POPT_ARG_INT, &max_runtime, 0, 
+                "set maximum time for smbtorture to live", "seconds"},
                POPT_COMMON_SAMBA
                POPT_COMMON_CONNECTION
                POPT_COMMON_CREDENTIALS
@@ -2675,14 +2568,12 @@ static BOOL is_binding_string(const char *binding_string)
                POPT_TABLEEND
        };
 
-       setup_logging("smbtorture", DEBUG_STDOUT);
-
 #ifdef HAVE_SETBUFFER
        setbuffer(stdout, NULL, 0);
 #endif
 
        pc = poptGetContext("smbtorture", argc, (const char **) argv, long_options, 
-                               POPT_CONTEXT_KEEP_FIRST);
+                           POPT_CONTEXT_KEEP_FIRST);
 
        poptSetOtherOptionHelp(pc, "<binding>|<unc> TEST1 TEST2 ...");
 
@@ -2711,8 +2602,15 @@ static BOOL is_binding_string(const char *binding_string)
                }
        }
 
-       lp_load(dyn_CONFIGFILE,True,False,False);
-       load_interfaces();
+       if (max_runtime) {
+               /* this will only work if nobody else uses alarm(),
+                  which means it won't work for some tests, but we
+                  can't use the event context method we use for smbd
+                  as so many tests create their own event
+                  context. This will at least catch most cases. */
+               signal(SIGALRM, max_runtime_handler);
+               alarm(max_runtime);
+       }
 
        smbtorture_init_subsystems;
 
@@ -2748,9 +2646,9 @@ static BOOL is_binding_string(const char *binding_string)
                lp_set_cmdline("torture:binding", argv_new[1]);
        } else {
                char *binding = NULL;
-               char *host = NULL, *share = NULL;
+               const char *host = NULL, *share = NULL;
 
-               if (!parse_unc(argv_new[1], &host, &share)) {
+               if (!smbcli_parse_unc(argv_new[1], NULL, &host, &share)) {
                        d_printf("Invalid option: %s is not a valid torture target (share or binding string)\n\n", argv_new[1]);
                        usage(pc);
                }
@@ -2761,25 +2659,6 @@ static BOOL is_binding_string(const char *binding_string)
                lp_set_cmdline("torture:binding", binding);
        }
 
-       if (!lp_parm_string(-1,"torture","username")) {
-               lp_set_cmdline("torture:username", cmdline_get_username());
-       }
-       if (!lp_parm_string(-1,"torture","userdomain")) {
-               /* 
-                * backward compatibility
-                * maybe we should remove this to make this consistent
-                * for all cmdline tools
-                * --metze
-                */
-               if (strequal(lp_netbios_name(),cmdline_get_userdomain())) {
-                       cmdline_set_userdomain(lp_workgroup());
-               }
-               lp_set_cmdline("torture:userdomain", cmdline_get_userdomain());
-       }
-       if (!lp_parm_string(-1,"torture","password")) {
-               lp_set_cmdline("torture:password", cmdline_get_userpassword());
-       }
-
        if (argc_new == 0) {
                printf("You must specify a test to run, or 'ALL'\n");
        } else {