s3: Remove unused "retry" from cli_full_connection
[nivanova/samba-autobuild/.git] / source3 / torture / torture.c
index 72b22969b8da09eb14d814ebe91a1350c2f83e01..1b492ce736b6f5a9d6e5f28dbc3f5c3584809859 100644 (file)
 */
 
 #include "includes.h"
-#include "nsswitch/libwbclient/wbc_async.h"
+#include "wbc_async.h"
 #include "torture/proto.h"
-#include "libcli/security/dom_sid.h"
+#include "libcli/security/security.h"
 #include "tldap.h"
 #include "tldap_util.h"
+#include "../librpc/gen_ndr/svcctl.h"
+#include "memcache.h"
+#include "nsswitch/winbind_client.h"
+#include "dbwrap.h"
+#include "talloc_dict.h"
+#include "async_smb.h"
 
 extern char *optarg;
 extern int optind;
@@ -46,6 +52,7 @@ static fstring multishare_conn_fname;
 static bool use_multishare_conn = False;
 static bool do_encrypt;
 static const char *local_path = NULL;
+static int signing_state = Undefined;
 
 bool torture_showall = False;
 
@@ -172,7 +179,7 @@ static struct cli_state *open_nbt_connection(void)
 
         zero_sockaddr(&ss);
 
-       if (!(c = cli_initialise())) {
+       if (!(c = cli_initialise_ex(signing_state))) {
                printf("Failed initialize cli_struct to connect with %s\n", host);
                return NULL;
        }
@@ -215,6 +222,120 @@ static struct cli_state *open_nbt_connection(void)
        return c;
 }
 
+/****************************************************************************
+ Send a corrupt session request. See rfc1002.txt 4.3 and 4.3.2.
+****************************************************************************/
+
+static bool cli_bad_session_request(struct cli_state *cli,
+                         struct nmb_name *calling, struct nmb_name *called)
+{
+        char *p;
+        int len = 4;
+        int namelen = 0;
+        char *tmp;
+
+        memcpy(&(cli->calling), calling, sizeof(*calling));
+        memcpy(&(cli->called ), called , sizeof(*called ));
+
+        /* put in the destination name */
+
+        tmp = name_mangle(talloc_tos(), cli->called.name,
+                          cli->called.name_type);
+        if (tmp == NULL) {
+                return false;
+        }
+
+        p = cli->outbuf+len;
+        namelen = name_len((unsigned char *)tmp, talloc_get_size(tmp));
+        if (namelen > 0) {
+                memcpy(p, tmp, namelen);
+                len += namelen;
+        }
+        TALLOC_FREE(tmp);
+
+       /* Deliberately corrupt the name len (first byte) */
+       *p = 100;
+
+        /* and my name */
+
+        tmp = name_mangle(talloc_tos(), cli->calling.name,
+                          cli->calling.name_type);
+        if (tmp == NULL) {
+                return false;
+        }
+
+        p = cli->outbuf+len;
+        namelen = name_len((unsigned char *)tmp, talloc_get_size(tmp));
+        if (namelen > 0) {
+                memcpy(p, tmp, namelen);
+                len += namelen;
+        }
+        TALLOC_FREE(tmp);
+       /* Deliberately corrupt the name len (first byte) */
+       *p = 100;
+
+        /* send a session request (RFC 1002) */
+        /* setup the packet length
+         * Remove four bytes from the length count, since the length
+         * field in the NBT Session Service header counts the number
+         * of bytes which follow.  The cli_send_smb() function knows
+         * about this and accounts for those four bytes.
+         * CRH.
+         */
+        len -= 4;
+        _smb_setlen(cli->outbuf,len);
+        SCVAL(cli->outbuf,0,0x81);
+
+        cli_send_smb(cli);
+        DEBUG(5,("Sent session request\n"));
+
+        if (!cli_receive_smb(cli))
+                return False;
+
+        if (CVAL(cli->inbuf,0) != 0x82) {
+                /* This is the wrong place to put the error... JRA. */
+                cli->rap_error = CVAL(cli->inbuf,4);
+                return False;
+        }
+        return(True);
+}
+
+static struct cli_state *open_bad_nbt_connection(void)
+{
+       struct nmb_name called, calling;
+       struct sockaddr_storage ss;
+       struct cli_state *c;
+       NTSTATUS status;
+
+       make_nmb_name(&calling, myname, 0x0);
+       make_nmb_name(&called , host, 0x20);
+
+        zero_sockaddr(&ss);
+
+       if (!(c = cli_initialise_ex(signing_state))) {
+               printf("Failed initialize cli_struct to connect with %s\n", host);
+               return NULL;
+       }
+
+       c->port = 139;
+
+       status = cli_connect(c, host, &ss);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
+               return NULL;
+       }
+
+       c->timeout = 4000; /* set a short timeout (4 seconds) */
+
+       if (!cli_bad_session_request(c, &calling, &called)) {
+               printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
+               return NULL;
+       }
+
+       return c;
+}
+
+
 /* Insert a NULL at the first separator of the given path and return a pointer
  * to the remainder of the string.
  */
@@ -277,7 +398,6 @@ static bool torture_open_connection_share(struct cli_state **c,
                                   const char *hostname, 
                                   const char *sharename)
 {
-       bool retry;
        int flags = 0;
        NTSTATUS status;
 
@@ -292,7 +412,7 @@ static bool torture_open_connection_share(struct cli_state **c,
                                     hostname, NULL, port_to_use, 
                                     sharename, "?????", 
                                     username, workgroup, 
-                                    password, flags, Undefined, &retry);
+                                    password, flags, signing_state);
        if (!NT_STATUS_IS_OK(status)) {
                printf("failed to open share connection: //%s/%s port:%d - %s\n",
                        hostname, sharename, port_to_use, nt_errstr(status));
@@ -767,7 +887,7 @@ static bool run_readwritemulti(int dummy)
        return test;
 }
 
-static bool run_readwritelarge(int dummy)
+static bool run_readwritelarge_internal(int max_xmit_k)
 {
        static struct cli_state *cli1;
        uint16_t fnum1;
@@ -782,9 +902,17 @@ static bool run_readwritelarge(int dummy)
        cli_sockopt(cli1, sockops);
        memset(buf,'\0',sizeof(buf));
 
-       cli1->max_xmit = 128*1024;
+       cli1->max_xmit = max_xmit_k*1024;
+
+       if (signing_state == Required) {
+               /* Horrible cheat to force
+                  multiple signed outstanding
+                  packets against a Samba server.
+               */
+               cli1->is_samba = false;
+       }
 
-       printf("starting readwritelarge\n");
+       printf("starting readwritelarge_internal\n");
 
        cli_unlink(cli1, lockfname, aSYSTEM | aHIDDEN);
 
@@ -795,16 +923,18 @@ static bool run_readwritelarge(int dummy)
 
        cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
 
-       if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
+       if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
+                                    cli1, fnum1, NULL, &fsize, NULL, NULL,
+                                    NULL, NULL, NULL))) {
                printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
                correct = False;
        }
 
        if (fsize == sizeof(buf))
-               printf("readwritelarge test 1 succeeded (size = %lx)\n", 
+               printf("readwritelarge_internal test 1 succeeded (size = %lx)\n",
                       (unsigned long)fsize);
        else {
-               printf("readwritelarge test 1 failed (size = %lx)\n", 
+               printf("readwritelarge_internal test 1 failed (size = %lx)\n",
                       (unsigned long)fsize);
                correct = False;
        }
@@ -828,16 +958,18 @@ static bool run_readwritelarge(int dummy)
 
        cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
 
-       if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
+       if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
+                                    cli1, fnum1, NULL, &fsize, NULL, NULL,
+                                    NULL, NULL, NULL))) {
                printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
                correct = False;
        }
 
        if (fsize == sizeof(buf))
-               printf("readwritelarge test 2 succeeded (size = %lx)\n", 
+               printf("readwritelarge_internal test 2 succeeded (size = %lx)\n",
                       (unsigned long)fsize);
        else {
-               printf("readwritelarge test 2 failed (size = %lx)\n", 
+               printf("readwritelarge_internal test 2 failed (size = %lx)\n",
                       (unsigned long)fsize);
                correct = False;
        }
@@ -848,7 +980,8 @@ static bool run_readwritelarge(int dummy)
                printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
                return False;
        }
-       if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
+       if (!cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL,
+                                NULL, NULL)) {
                printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
                correct = False;
        }
@@ -867,6 +1000,20 @@ static bool run_readwritelarge(int dummy)
        return correct;
 }
 
+static bool run_readwritelarge(int dummy)
+{
+       return run_readwritelarge_internal(128);
+}
+
+static bool run_readwritelarge_signtest(int dummy)
+{
+       bool ret;
+       signing_state = Required;
+       ret = run_readwritelarge_internal(2);
+       signing_state = Undefined;
+       return ret;
+}
+
 int line_count = 0;
 int nbio_id;
 
@@ -1306,7 +1453,6 @@ static bool tcon_devtest(struct cli_state *cli,
 static bool run_tcon_devtype_test(int dummy)
 {
        static struct cli_state *cli1 = NULL;
-       bool retry;
        int flags = 0;
        NTSTATUS status;
        bool ret = True;
@@ -1315,7 +1461,7 @@ static bool run_tcon_devtype_test(int dummy)
                                     host, NULL, port_to_use,
                                     NULL, NULL,
                                     username, workgroup,
-                                    password, flags, Undefined, &retry);
+                                    password, flags, signing_state);
 
        if (!NT_STATUS_IS_OK(status)) {
                printf("could not open connection\n");
@@ -2648,6 +2794,21 @@ static bool run_negprot_nowait(int dummy)
        return correct;
 }
 
+/* send smb negprot commands, not reading the response */
+static bool run_bad_nbt_session(int dummy)
+{
+       static struct cli_state *cli;
+
+       printf("starting bad nbt session test\n");
+
+       if (!(cli = open_bad_nbt_connection())) {
+               return False;
+       }
+
+       cli_shutdown(cli);
+       printf("finished bad nbt session test\n");
+       return true;
+}
 
 /* send random IPC commands */
 static bool run_randomipc(int dummy)
@@ -2839,13 +3000,15 @@ static bool run_trans2test(int dummy)
        cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
        cli_open(cli, fname, 
                        O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
-       if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time_ts, &a_time_ts, &w_time_ts,
-                          &m_time_ts, NULL)) {
+       if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
+                                    cli, fnum, NULL, &size, &c_time_ts,
+                                    &a_time_ts, &w_time_ts,
+                                    &m_time_ts, NULL))) {
                printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
                correct = False;
        }
 
-       if (!cli_qfilename(cli, fnum, pname, sizeof(pname))) {
+       if (!NT_STATUS_IS_OK(cli_qfilename(cli, fnum, pname, sizeof(pname)))) {
                printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
                correct = False;
        }
@@ -2868,8 +3031,10 @@ static bool run_trans2test(int dummy)
        }
        cli_close(cli, fnum);
 
-       if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
-               printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
+       status = cli_qpathinfo1(cli, fname, &c_time, &a_time, &m_time, &size,
+                               NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ERROR: qpathinfo failed (%s)\n", nt_errstr(status));
                correct = False;
        } else {
                if (c_time != m_time) {
@@ -2894,9 +3059,10 @@ static bool run_trans2test(int dummy)
        cli_open(cli, fname, 
                        O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
        cli_close(cli, fnum);
-       if (!cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts, 
-                           &m_time_ts, &size, NULL, NULL)) {
-               printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
+       status = cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
+                               &m_time_ts, &size, NULL, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
                correct = False;
        } else {
                if (w_time_ts.tv_sec < 60*60*24*2) {
@@ -2916,9 +3082,10 @@ static bool run_trans2test(int dummy)
                correct = False;
        }
        sleep(3);
-       if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts, 
-                           &m_time_ts, &size, NULL, NULL)) {
-               printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
+       status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
+                               &w_time_ts, &m_time_ts, &size, NULL, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
                correct = False;
        }
 
@@ -2926,9 +3093,10 @@ static bool run_trans2test(int dummy)
                        O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
        cli_write(cli, fnum,  0, (char *)&fnum, 0, sizeof(fnum));
        cli_close(cli, fnum);
-       if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts, 
-                           &m_time2_ts, &size, NULL, NULL)) {
-               printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
+       status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
+                               &w_time_ts, &m_time2_ts, &size, NULL, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
                correct = False;
        } else {
                if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
@@ -2953,22 +3121,24 @@ static bool run_trans2test(int dummy)
   This checks new W2K calls.
 */
 
-static bool new_trans(struct cli_state *pcli, int fnum, int level)
+static NTSTATUS new_trans(struct cli_state *pcli, int fnum, int level)
 {
-       char *buf = NULL;
+       uint8_t *buf = NULL;
        uint32 len;
-       bool correct = True;
+       NTSTATUS status;
 
-       if (!cli_qfileinfo_test(pcli, fnum, level, &buf, &len)) {
-               printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
-               correct = False;
+       status = cli_qfileinfo(talloc_tos(), pcli, fnum, level, 0,
+                              pcli->max_xmit, &buf, &len);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ERROR: qfileinfo (%d) failed (%s)\n", level,
+                      nt_errstr(status));
        } else {
                printf("qfileinfo: level %d, len = %u\n", level, len);
                dump_data(0, (uint8 *)buf, len);
                printf("\n");
        }
-       SAFE_FREE(buf);
-       return correct;
+       TALLOC_FREE(buf);
+       return status;
 }
 
 static bool run_w2ktest(int dummy)
@@ -3280,17 +3450,6 @@ static bool run_deletetest(int dummy)
                goto fail;
        }
 
-#if 0 /* JRATEST */
-        {
-                uint32 *accinfo = NULL;
-                uint32 len;
-                cli_qfileinfo_test(cli1, fnum1, SMB_FILE_ACCESS_INFORMATION, (char **)&accinfo, &len);
-               if (accinfo)
-                       printf("access mode = 0x%lx\n", *accinfo);
-                SAFE_FREE(accinfo);
-        }
-#endif
-
        if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("[1] close failed (%s)\n", cli_errstr(cli1));
                correct = False;
@@ -4150,8 +4309,7 @@ static bool run_opentest(int dummy)
 
        cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
-
-       printf("testing ctemp\n");
+       printf("Do ctemp tests\n");
        if (!NT_STATUS_IS_OK(cli_ctemp(cli1, talloc_tos(), "\\", &fnum1, &tmp_path))) {
                printf("ctemp failed (%s)\n", cli_errstr(cli1));
                return False;
@@ -4179,22 +4337,22 @@ static bool run_opentest(int dummy)
 
        if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
                                   FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+               printf("TEST #1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
        if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
                                   FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
-               printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+               printf("TEST #1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
                return False;
        }
 
        if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+               printf("TEST #1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
        if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
-               printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+               printf("TEST #1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
                return False;
        }
 
@@ -4206,22 +4364,22 @@ static bool run_opentest(int dummy)
 
        if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
                                   FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+               printf("TEST #2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
        if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
                                   FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
-               printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+               printf("TEST #2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
                return False;
        }
 
        if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+               printf("TEST #2 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
        if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
-               printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
+               printf("TEST #2 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
@@ -4233,22 +4391,22 @@ static bool run_opentest(int dummy)
 
        if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
                                   FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+               printf("TEST #3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
        if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
                                   FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
-               printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+               printf("TEST #3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
                return False;
        }
 
        if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+               printf("TEST #3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
        if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
-               printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+               printf("TEST #3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
                return False;
        }
 
@@ -4260,20 +4418,20 @@ static bool run_opentest(int dummy)
 
        if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
                                   FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+               printf("TEST #4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
        if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
                                   FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
-               printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
+               printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
                return False;
        }
 
-       printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
+       printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
 
        if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+               printf("TEST #4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
@@ -4285,23 +4443,23 @@ static bool run_opentest(int dummy)
 
        if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
                                   FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+               printf("TEST #5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
        if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
                                   FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) {
-               printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+               printf("TEST #5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
                return False;
        }
 
        if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+               printf("TEST #5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
        if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
-               printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+               printf("TEST #5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
                return False;
        }
 
@@ -4313,23 +4471,23 @@ static bool run_opentest(int dummy)
 
        if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
                                   FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+               printf("TEST #6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
        if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
                                   FILE_SHARE_READ, FILE_OPEN_IF, 0, 0, &fnum2))) {
-               printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+               printf("TEST #6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
                return False;
        }
 
        if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+               printf("TEST #6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
        if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
-               printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+               printf("TEST #6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
                return False;
        }
 
@@ -4341,20 +4499,20 @@ static bool run_opentest(int dummy)
 
        if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
                                   FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+               printf("TEST #7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
        if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
                                   FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) {
-               printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
+               printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
                return False;
        }
 
-       printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
+       printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
 
        if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+               printf("TEST #7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
@@ -4786,9 +4944,14 @@ static bool run_openattrtest(int dummy)
        return correct;
 }
 
-static void list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
+static NTSTATUS list_fn(const char *mnt, struct file_info *finfo,
+                   const char *name, void *state)
 {
-
+       int *matched = (int *)state;
+       if (matched != NULL) {
+               *matched += 1;
+       }
+       return NT_STATUS_OK;
 }
 
 /*
@@ -4801,6 +4964,7 @@ static bool run_dirtest(int dummy)
        uint16_t fnum;
        struct timeval core_start;
        bool correct = True;
+       int matched;
 
        printf("starting directory test\n");
 
@@ -4823,9 +4987,17 @@ static bool run_dirtest(int dummy)
 
        core_start = timeval_current();
 
-       printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
-       printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
-       printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
+       matched = 0;
+       cli_list(cli, "a*.*", 0, list_fn, &matched);
+       printf("Matched %d\n", matched);
+
+       matched = 0;
+       cli_list(cli, "b*.*", 0, list_fn, &matched);
+       printf("Matched %d\n", matched);
+
+       matched = 0;
+       cli_list(cli, "xyzabc", 0, list_fn, &matched);
+       printf("Matched %d\n", matched);
 
        printf("dirtest core %g seconds\n", timeval_elapsed(&core_start));
 
@@ -4845,14 +5017,15 @@ static bool run_dirtest(int dummy)
        return correct;
 }
 
-static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
+static NTSTATUS del_fn(const char *mnt, struct file_info *finfo, const char *mask,
+                  void *state)
 {
        struct cli_state *pcli = (struct cli_state *)state;
        fstring fname;
        slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
 
        if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
-               return;
+               return NT_STATUS_OK;
 
        if (finfo->mode & aDIR) {
                if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
@@ -4861,6 +5034,7 @@ static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *st
                if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN)))
                        printf("del_fn: failed to unlink %s\n,", fname );
        }
+       return NT_STATUS_OK;
 }
 
 
@@ -4896,7 +5070,7 @@ bool torture_ioctl_test(int dummy)
        printf("ioctl job info: %s\n", nt_errstr(status));
 
        for (device=0;device<0x100;device++) {
-               printf("testing device=0x%x\n", device);
+               printf("ioctl test with device = 0x%x\n", device);
                for (function=0;function<0x100;function++) {
                        uint32 code = (device<<16) | function;
 
@@ -5009,6 +5183,7 @@ static bool run_eatest(int dummy)
        size_t num_eas;
        struct ea_struct *ea_list = NULL;
        TALLOC_CTX *mem_ctx = talloc_init("eatest");
+       NTSTATUS status;
 
        printf("starting eatest\n");
 
@@ -5032,8 +5207,10 @@ static bool run_eatest(int dummy)
 
                slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
                memset(ea_val, (char)i+1, i+1);
-               if (!cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1)) {
-                       printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
+               status = cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("ea_set of name %s failed - %s\n", ea_name,
+                              nt_errstr(status));
                        talloc_destroy(mem_ctx);
                        return False;
                }
@@ -5045,15 +5222,18 @@ static bool run_eatest(int dummy)
 
                slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
                memset(ea_val, (char)i+1, i+1);
-               if (!cli_set_ea_path(cli, fname, ea_name, ea_val, i+1)) {
-                       printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
+               status = cli_set_ea_path(cli, fname, ea_name, ea_val, i+1);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("ea_set of name %s failed - %s\n", ea_name,
+                              nt_errstr(status));
                        talloc_destroy(mem_ctx);
                        return False;
                }
        }
 
-       if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
-               printf("ea_get list failed - %s\n", cli_errstr(cli));
+       status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ea_get list failed - %s\n", nt_errstr(status));
                correct = False;
        }
 
@@ -5079,16 +5259,19 @@ static bool run_eatest(int dummy)
        for (i = 0; i < 20; i++) {
                fstring ea_name;
                slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
-               if (!cli_set_ea_path(cli, fname, ea_name, "", 0)) {
-                       printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
+               status = cli_set_ea_path(cli, fname, ea_name, "", 0);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("ea_set of name %s failed - %s\n", ea_name,
+                              nt_errstr(status));
                        talloc_destroy(mem_ctx);
                        return False;
                }
        }
 #endif
 
-       if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
-               printf("ea_get list failed - %s\n", cli_errstr(cli));
+       status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ea_get list failed - %s\n", nt_errstr(status));
                correct = False;
        }
 
@@ -5105,8 +5288,10 @@ static bool run_eatest(int dummy)
        }
 
        /* Try and delete a non existant EA. */
-       if (!cli_set_ea_path(cli, fname, "foo", "", 0)) {
-               printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli));
+       status = cli_set_ea_path(cli, fname, "foo", "", 0);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("deleting non-existant EA 'foo' should succeed. %s\n",
+                      nt_errstr(status));
                correct = False;
        }
 
@@ -5160,7 +5345,8 @@ static bool run_dirtest1(int dummy)
        }
 
        /* Now ensure that doing an old list sees both files and directories. */
-       num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
+       num_seen = 0;
+       cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, &num_seen);
        printf("num_seen = %d\n", num_seen );
        /* We should see 100 files + 1000 directories + . and .. */
        if (num_seen != 2002)
@@ -5169,12 +5355,14 @@ static bool run_dirtest1(int dummy)
        /* Ensure if we have the "must have" bits we only see the
         * relevent entries.
         */
-       num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
+       num_seen = 0;
+       cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, &num_seen);
        printf("num_seen = %d\n", num_seen );
        if (num_seen != 1002)
                correct = False;
 
-       num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
+       num_seen = 0;
+       cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, &num_seen);
        printf("num_seen = %d\n", num_seen );
        if (num_seen != 1000)
                correct = False;
@@ -5959,10 +6147,11 @@ static bool run_mangle1(int dummy)
        }
        cli_close(cli, fnum);
 
-       if (!cli_qpathinfo(cli, alt_name, &change_time, &access_time,
-                          &write_time, &size, &mode)) {
-               d_printf("cli_qpathinfo(%s) failed: %s\n", alt_name,
-                        cli_errstr(cli));
+       status = cli_qpathinfo1(cli, alt_name, &change_time, &access_time,
+                               &write_time, &size, &mode);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("cli_qpathinfo1(%s) failed: %s\n", alt_name,
+                        nt_errstr(status));
                return false;
        }
 
@@ -6093,11 +6282,18 @@ static bool run_uid_regression_test(int dummy)
        cli->vuid = old_vuid;
 
        /* Try an operation. */
-       if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\uid_reg_test"))) {
-               /* We expect bad uid. */
+       status = cli_mkdir(cli, "\\uid_reg_test");
+       if (NT_STATUS_IS_OK(status)) {
+               d_printf("(%s) cli_mkdir succeeded\n",
+                        __location__);
+               correct = false;
+               goto out;
+       } else {
+               /* Should be bad uid. */
                if (!check_error(__LINE__, cli, ERRSRV, ERRbaduid,
-                               NT_STATUS_NO_SUCH_USER)) {
-                       return False;
+                               NT_STATUS_USER_SESSION_DELETED)) {
+                       correct = false;
+                       goto out;
                }
        }
 
@@ -6110,9 +6306,11 @@ static bool run_uid_regression_test(int dummy)
        status = cli_tdis(cli);
 
        if (NT_STATUS_IS_OK(status)) {
-               printf("First tdis with invalid vuid should succeed.\n");
+               d_printf("First tdis with invalid vuid should succeed.\n");
        } else {
-               printf("First tdis failed (%s)\n", nt_errstr(status));
+               d_printf("First tdis failed (%s)\n", nt_errstr(status));
+               correct = false;
+               goto out;
        }
 
        cli->vuid = old_vuid;
@@ -6121,12 +6319,15 @@ static bool run_uid_regression_test(int dummy)
        /* This should fail. */
        status = cli_tdis(cli);
        if (NT_STATUS_IS_OK(status)) {
-               printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
+               d_printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
+               correct = false;
+               goto out;
        } else {
                /* Should be bad tid. */
                if (!check_error(__LINE__, cli, ERRSRV, ERRinvnid,
                                NT_STATUS_NETWORK_NAME_DELETED)) {
-                       return False;
+                       correct = false;
+                       goto out;
                }
        }
 
@@ -6142,30 +6343,40 @@ static bool run_uid_regression_test(int dummy)
 static const char *illegal_chars = "*\\/?<>|\":";
 static char force_shortname_chars[] = " +,.[];=\177";
 
-static void shortname_del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
+static NTSTATUS shortname_del_fn(const char *mnt, struct file_info *finfo,
+                            const char *mask, void *state)
 {
        struct cli_state *pcli = (struct cli_state *)state;
        fstring fname;
+       NTSTATUS status = NT_STATUS_OK;
+
        slprintf(fname, sizeof(fname), "\\shortname\\%s", finfo->name);
 
        if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
-               return;
+               return NT_STATUS_OK;
 
        if (finfo->mode & aDIR) {
-               if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
+               status = cli_rmdir(pcli, fname);
+               if (!NT_STATUS_IS_OK(status)) {
                        printf("del_fn: failed to rmdir %s\n,", fname );
+               }
        } else {
-               if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN)))
+               status = cli_unlink(pcli, fname, aSYSTEM | aHIDDEN);
+               if (!NT_STATUS_IS_OK(status)) {
                        printf("del_fn: failed to unlink %s\n,", fname );
+               }
        }
+       return status;
 }
 
 struct sn_state {
+       int matched;
        int i;
        bool val;
 };
 
-static void shortname_list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
+static NTSTATUS shortname_list_fn(const char *mnt, struct file_info *finfo,
+                             const char *name, void *state)
 {
        struct sn_state *s = (struct sn_state  *)state;
        int i = s->i;
@@ -6188,6 +6399,8 @@ static void shortname_list_fn(const char *mnt, file_info *finfo, const char *nam
                        __location__, finfo->short_name, finfo->name);
                s->val = true;
        }
+       s->matched += 1;
+       return NT_STATUS_OK;
 }
 
 static bool run_shortname_test(int dummy)
@@ -6242,7 +6455,11 @@ static bool run_shortname_test(int dummy)
                        goto out;
                }
                cli_close(cli, fnum);
-               if (cli_list(cli, "\\shortname\\test*.*", 0, shortname_list_fn, &s) != 1) {
+
+               s.matched = 0;
+               cli_list(cli, "\\shortname\\test*.*", 0, shortname_list_fn,
+                        &s);
+               if (s.matched != 1) {
                        d_printf("(%s) failed to list %s: %s\n",
                                __location__, fname, cli_errstr(cli));
                        correct = false;
@@ -6402,16 +6619,9 @@ static bool run_dir_createtime(int dummy)
                goto out;
        }
 
-       if (!cli_qpathinfo2(cli,
-                       dname,
-                       &create_time,
-                       NULL,
-                       NULL,
-                       NULL,
-                       NULL,
-                       NULL,
-                       NULL)) {
-               status = cli_nt_error(cli);
+       status = cli_qpathinfo2(cli, dname, &create_time, NULL, NULL, NULL,
+                               NULL, NULL, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
                printf("cli_qpathinfo2 returned %s\n",
                       nt_errstr(status));
                goto out;
@@ -6427,16 +6637,9 @@ static bool run_dir_createtime(int dummy)
                goto out;
        }
 
-       if (!cli_qpathinfo2(cli,
-                       dname,
-                       &create_time1,
-                       NULL,
-                       NULL,
-                       NULL,
-                       NULL,
-                       NULL,
-                       NULL)) {
-               status = cli_nt_error(cli);
+       status = cli_qpathinfo2(cli, dname, &create_time1, NULL, NULL, NULL,
+                               NULL, NULL, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
                printf("cli_qpathinfo2 (2) returned %s\n",
                       nt_errstr(status));
                goto out;
@@ -6485,7 +6688,7 @@ static bool run_streamerror(int dummy)
                return false;
        }
 
-       cli_qpathinfo(cli, streamname, &change_time, &access_time, &write_time,
+       cli_qpathinfo1(cli, streamname, &change_time, &access_time, &write_time,
                      &size, &mode);
        status = cli_nt_error(cli);
 
@@ -6815,7 +7018,7 @@ static bool run_local_string_to_sid(int dummy) {
                printf("could not parse S-1-5-32-545\n");
                return false;
        }
-       if (!sid_equal(&sid, &global_sid_Builtin_Users)) {
+       if (!dom_sid_equal(&sid, &global_sid_Builtin_Users)) {
                printf("mis-parsed S-1-5-32-545 as %s\n",
                       sid_string_tos(&sid));
                return false;
@@ -6823,6 +7026,103 @@ static bool run_local_string_to_sid(int dummy) {
        return true;
 }
 
+static bool run_local_binary_to_sid(int dummy) {
+       struct dom_sid *sid = talloc(NULL, struct dom_sid);
+       static const char good_binary_sid[] = {
+               0x1, /* revision number */
+               15, /* num auths */
+               0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
+               0x1, 0x1, 0x1, 0x1, /* auth[0] */
+               0x1, 0x1, 0x1, 0x1, /* auth[1] */
+               0x1, 0x1, 0x1, 0x1, /* auth[2] */
+               0x1, 0x1, 0x1, 0x1, /* auth[3] */
+               0x1, 0x1, 0x1, 0x1, /* auth[4] */
+               0x1, 0x1, 0x1, 0x1, /* auth[5] */
+               0x1, 0x1, 0x1, 0x1, /* auth[6] */
+               0x1, 0x1, 0x1, 0x1, /* auth[7] */
+               0x1, 0x1, 0x1, 0x1, /* auth[8] */
+               0x1, 0x1, 0x1, 0x1, /* auth[9] */
+               0x1, 0x1, 0x1, 0x1, /* auth[10] */
+               0x1, 0x1, 0x1, 0x1, /* auth[11] */
+               0x1, 0x1, 0x1, 0x1, /* auth[12] */
+               0x1, 0x1, 0x1, 0x1, /* auth[13] */
+               0x1, 0x1, 0x1, 0x1, /* auth[14] */
+       };
+
+       static const char long_binary_sid[] = {
+               0x1, /* revision number */
+               15, /* num auths */
+               0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
+               0x1, 0x1, 0x1, 0x1, /* auth[0] */
+               0x1, 0x1, 0x1, 0x1, /* auth[1] */
+               0x1, 0x1, 0x1, 0x1, /* auth[2] */
+               0x1, 0x1, 0x1, 0x1, /* auth[3] */
+               0x1, 0x1, 0x1, 0x1, /* auth[4] */
+               0x1, 0x1, 0x1, 0x1, /* auth[5] */
+               0x1, 0x1, 0x1, 0x1, /* auth[6] */
+               0x1, 0x1, 0x1, 0x1, /* auth[7] */
+               0x1, 0x1, 0x1, 0x1, /* auth[8] */
+               0x1, 0x1, 0x1, 0x1, /* auth[9] */
+               0x1, 0x1, 0x1, 0x1, /* auth[10] */
+               0x1, 0x1, 0x1, 0x1, /* auth[11] */
+               0x1, 0x1, 0x1, 0x1, /* auth[12] */
+               0x1, 0x1, 0x1, 0x1, /* auth[13] */
+               0x1, 0x1, 0x1, 0x1, /* auth[14] */
+               0x1, 0x1, 0x1, 0x1, /* auth[15] */
+               0x1, 0x1, 0x1, 0x1, /* auth[16] */
+               0x1, 0x1, 0x1, 0x1, /* auth[17] */
+       };
+
+       static const char long_binary_sid2[] = {
+               0x1, /* revision number */
+               32, /* num auths */
+               0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
+               0x1, 0x1, 0x1, 0x1, /* auth[0] */
+               0x1, 0x1, 0x1, 0x1, /* auth[1] */
+               0x1, 0x1, 0x1, 0x1, /* auth[2] */
+               0x1, 0x1, 0x1, 0x1, /* auth[3] */
+               0x1, 0x1, 0x1, 0x1, /* auth[4] */
+               0x1, 0x1, 0x1, 0x1, /* auth[5] */
+               0x1, 0x1, 0x1, 0x1, /* auth[6] */
+               0x1, 0x1, 0x1, 0x1, /* auth[7] */
+               0x1, 0x1, 0x1, 0x1, /* auth[8] */
+               0x1, 0x1, 0x1, 0x1, /* auth[9] */
+               0x1, 0x1, 0x1, 0x1, /* auth[10] */
+               0x1, 0x1, 0x1, 0x1, /* auth[11] */
+               0x1, 0x1, 0x1, 0x1, /* auth[12] */
+               0x1, 0x1, 0x1, 0x1, /* auth[13] */
+               0x1, 0x1, 0x1, 0x1, /* auth[14] */
+               0x1, 0x1, 0x1, 0x1, /* auth[15] */
+               0x1, 0x1, 0x1, 0x1, /* auth[16] */
+               0x1, 0x1, 0x1, 0x1, /* auth[17] */
+               0x1, 0x1, 0x1, 0x1, /* auth[18] */
+               0x1, 0x1, 0x1, 0x1, /* auth[19] */
+               0x1, 0x1, 0x1, 0x1, /* auth[20] */
+               0x1, 0x1, 0x1, 0x1, /* auth[21] */
+               0x1, 0x1, 0x1, 0x1, /* auth[22] */
+               0x1, 0x1, 0x1, 0x1, /* auth[23] */
+               0x1, 0x1, 0x1, 0x1, /* auth[24] */
+               0x1, 0x1, 0x1, 0x1, /* auth[25] */
+               0x1, 0x1, 0x1, 0x1, /* auth[26] */
+               0x1, 0x1, 0x1, 0x1, /* auth[27] */
+               0x1, 0x1, 0x1, 0x1, /* auth[28] */
+               0x1, 0x1, 0x1, 0x1, /* auth[29] */
+               0x1, 0x1, 0x1, 0x1, /* auth[30] */
+               0x1, 0x1, 0x1, 0x1, /* auth[31] */
+       };
+
+       if (!sid_parse(good_binary_sid, sizeof(good_binary_sid), sid)) {
+               return false;
+       }
+       if (sid_parse(long_binary_sid2, sizeof(long_binary_sid2), sid)) {
+               return false;
+       }
+       if (sid_parse(long_binary_sid, sizeof(long_binary_sid), sid)) {
+               return false;
+       }
+       return true;
+}
+
 /* Split a path name into filename and stream name components. Canonicalise
  * such that an implicit $DATA token is always explicit.
  *
@@ -6945,7 +7245,7 @@ static bool test_stream_name(const char *fname, const char *expected_base,
        return true;
 
  error:
-       d_fprintf(stderr, "test_stream(%s, %s, %s, %s)\n",
+       d_fprintf(stderr, "Do test_stream(%s, %s, %s, %s)\n",
                  fname, expected_base ? expected_base : "<NULL>",
                  expected_stream ? expected_stream : "<NULL>",
                  nt_errstr(expected_status));
@@ -7335,6 +7635,48 @@ static bool run_local_dbtrans(int dummy)
        return true;
 }
 
+/*
+ * Just a dummy test to be run under a debugger. There's no real way
+ * to inspect the tevent_select specific function from outside of
+ * tevent_select.c.
+ */
+
+static bool run_local_tevent_select(int dummy)
+{
+       struct tevent_context *ev;
+       struct tevent_fd *fd1, *fd2;
+       bool result = false;
+
+       ev = tevent_context_init_byname(NULL, "select");
+       if (ev == NULL) {
+               d_fprintf(stderr, "tevent_context_init_byname failed\n");
+               goto fail;
+       }
+
+       fd1 = tevent_add_fd(ev, ev, 2, 0, NULL, NULL);
+       if (fd1 == NULL) {
+               d_fprintf(stderr, "tevent_add_fd failed\n");
+               goto fail;
+       }
+       fd2 = tevent_add_fd(ev, ev, 3, 0, NULL, NULL);
+       if (fd2 == NULL) {
+               d_fprintf(stderr, "tevent_add_fd failed\n");
+               goto fail;
+       }
+       TALLOC_FREE(fd2);
+
+       fd2 = tevent_add_fd(ev, ev, 1, 0, NULL, NULL);
+       if (fd2 == NULL) {
+               d_fprintf(stderr, "tevent_add_fd failed\n");
+               goto fail;
+       }
+
+       result = true;
+fail:
+       TALLOC_FREE(ev);
+       return result;
+}
+
 static double create_procs(bool (*fn)(int), bool *result)
 {
        int i, status;
@@ -7455,6 +7797,7 @@ static struct {
        {"RANDOMIPC", run_randomipc, 0},
        {"NEGNOWAIT", run_negprot_nowait, 0},
        {"NBENCH",  run_nbench, 0},
+       {"NBENCH2", run_nbench2, 0},
        {"OPLOCK1",  run_oplock1, 0},
        {"OPLOCK2",  run_oplock2, 0},
        {"OPLOCK3",  run_oplock3, 0},
@@ -7468,9 +7811,11 @@ static struct {
        {"RW1",  run_readwritetest, 0},
        {"RW2",  run_readwritemulti, FLAG_MULTIPROC},
        {"RW3",  run_readwritelarge, 0},
+       {"RW-SIGNING",  run_readwritelarge_signtest, 0},
        {"OPEN", run_opentest, 0},
        {"POSIX", run_simple_posix_open_test, 0},
        {"POSIX-APPEND", run_posix_append, 0},
+       {"ASYNC-ECHO", run_async_echo, 0},
        { "UID-REGRESSION-TEST", run_uid_regression_test, 0},
        { "SHORTNAME-TEST", run_shortname_test, 0},
 #if 1
@@ -7503,6 +7848,7 @@ static struct {
        { "TLDAP", run_tldap },
        { "STREAMERROR", run_streamerror },
        { "NOTIFY-BENCH", run_notify_bench },
+       { "BAD-NBT-SESSION", run_bad_nbt_session },
        { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
        { "LOCAL-GENCACHE", run_local_gencache, 0},
        { "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
@@ -7512,7 +7858,9 @@ static struct {
        { "LOCAL-STREAM-NAME", run_local_stream_name, 0},
        { "LOCAL-WBCLIENT", run_local_wbclient, 0},
        { "LOCAL-string_to_sid", run_local_string_to_sid, 0},
+       { "LOCAL-binary_to_sid", run_local_binary_to_sid, 0},
        { "LOCAL-DBTRANS", run_local_dbtrans, 0},
+       { "LOCAL-TEVENT-SELECT", run_local_tevent_select, 0},
        {NULL, NULL, 0}};
 
 
@@ -7619,15 +7967,13 @@ static void usage(void)
        TALLOC_CTX *frame = talloc_stackframe();
        int seed = time(NULL);
 
-       dbf = x_stdout;
-
 #ifdef HAVE_SETBUFFER
        setbuffer(stdout, NULL, 0);
 #endif
 
-       load_case_tables();
+       setup_logging("smbtorture", DEBUG_STDOUT);
 
-       setup_logging("smbtorture", true);
+       load_case_tables();
 
        if (is_default_dyn_CONFIGFILE()) {
                if(getenv("SMB_CONF_PATH")) {
@@ -7693,7 +8039,7 @@ static void usage(void)
                        torture_numops = atoi(optarg);
                        break;
                case 'd':
-                       DEBUGLEVEL = atoi(optarg);
+                       lp_set_cmdline("log level", optarg);
                        break;
                case 'O':
                        sockops = optarg;