s3-torture: replace cli_errstr() with nt_errstr()
[obnox/samba/samba-obnox.git] / source3 / torture / torture.c
index f2fad4988c1b98acf0acdf3b72bafa88115a949c..7b3c6a41917d9c3894c41528530df77fa2e29b66 100644 (file)
@@ -28,7 +28,9 @@
 #include "../librpc/gen_ndr/svcctl.h"
 #include "memcache.h"
 #include "nsswitch/winbind_client.h"
-#include "dbwrap.h"
+#include "dbwrap/dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
+#include "dbwrap/dbwrap_rbt.h"
 #include "talloc_dict.h"
 #include "async_smb.h"
 #include "libsmb/libsmb.h"
 #include "libsmb/nmblib.h"
 #include "../lib/util/tevent_ntstatus.h"
 #include "util_tdb.h"
-#include "libsmb/read_smb.h"
+#include "../libcli/smb/read_smb.h"
 
 extern char *optarg;
 extern int optind;
 
-static fstring host, workgroup, share, password, username, myname;
+fstring host, workgroup, share, password, username, myname;
 static int max_protocol = PROTOCOL_NT1;
 static const char *sockops="TCP_NODELAY";
 static int nprocs=1;
@@ -55,12 +57,14 @@ static fstring randomfname;
 static bool use_oplocks;
 static bool use_level_II_oplocks;
 static const char *client_txt = "client_oplocks.txt";
+static bool disable_spnego;
 static bool use_kerberos;
+static bool force_dos_errors;
 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;
+static int signing_state = SMB_SIGNING_DEFAULT;
 char *test_filename;
 
 bool torture_showall = False;
@@ -178,55 +182,38 @@ static bool force_cli_encryption(struct cli_state *c,
 
 static struct cli_state *open_nbt_connection(void)
 {
-       struct nmb_name called, calling;
-       struct sockaddr_storage ss;
        struct cli_state *c;
        NTSTATUS status;
+       int flags = 0;
 
-       make_nmb_name(&calling, myname, 0x0);
-       make_nmb_name(&called , host, 0x20);
+       if (disable_spnego) {
+               flags |= CLI_FULL_CONNECTION_DONT_SPNEGO;
+       }
 
-        zero_sockaddr(&ss);
+       if (use_oplocks) {
+               flags |= CLI_FULL_CONNECTION_OPLOCKS;
+       }
 
-       if (!(c = cli_initialise_ex(signing_state))) {
-               printf("Failed initialize cli_struct to connect with %s\n", host);
-               return NULL;
+       if (use_level_II_oplocks) {
+               flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
+       }
+
+       if (use_kerberos) {
+               flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
        }
 
-       c->port = port_to_use;
+       if (force_dos_errors) {
+               flags |= CLI_FULL_CONNECTION_FORCE_DOS_ERRORS;
+       }
 
-       status = cli_connect(c, host, &ss);
+       status = cli_connect_nb(host, NULL, port_to_use, 0x20, myname,
+                               signing_state, flags, &c);
        if (!NT_STATUS_IS_OK(status)) {
                printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
                return NULL;
        }
 
-       c->use_kerberos = use_kerberos;
-
-       c->timeout = 120000; /* set a really long timeout (2 minutes) */
-       if (use_oplocks) c->use_oplocks = True;
-       if (use_level_II_oplocks) c->use_level_II_oplocks = True;
-
-       if (!cli_session_request(c, &calling, &called)) {
-               /*
-                * Well, that failed, try *SMBSERVER ...
-                * However, we must reconnect as well ...
-                */
-               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;
-               }
-
-               make_nmb_name(&called, "*SMBSERVER", 0x20);
-               if (!cli_session_request(c, &calling, &called)) {
-                       printf("%s rejected the session\n",host);
-                       printf("We tried with a called name of %s & %s\n",
-                               host, "*SMBSERVER");
-                       cli_shutdown(c);
-                       return NULL;
-               }
-       }
+       cli_set_timeout(c, 120000); /* set a really long timeout (2 minutes) */
 
        return c;
 }
@@ -235,7 +222,7 @@ static struct cli_state *open_nbt_connection(void)
  Send a corrupt session request. See rfc1002.txt 4.3 and 4.3.2.
 ****************************************************************************/
 
-static bool cli_bad_session_request(struct cli_state *cli,
+static bool cli_bad_session_request(int fd,
                          struct nmb_name *calling, struct nmb_name *called)
 {
        TALLOC_CTX *frame;
@@ -245,13 +232,10 @@ static bool cli_bad_session_request(struct cli_state *cli,
        uint8_t *inbuf;
        int err;
        bool ret = false;
-
-        memcpy(&(cli->calling), calling, sizeof(*calling));
-        memcpy(&(cli->called ), called , sizeof(*called ));
-
-       /* 445 doesn't have session request */
-       if (cli->port == 445)
-               return True;
+       uint8_t message_type;
+       uint8_t error;
+       struct event_context *ev;
+       struct tevent_req *req;
 
        frame = talloc_stackframe();
 
@@ -293,19 +277,46 @@ static bool cli_bad_session_request(struct cli_state *cli,
        _smb_setlen(len_buf, iov[1].iov_len + iov[2].iov_len);
        SCVAL(len_buf,0,0x81);
 
-       len = write_data_iov(cli->fd, iov, 3);
+       len = write_data_iov(fd, iov, 3);
        if (len == -1) {
                goto fail;
        }
-       len = read_smb(cli->fd, talloc_tos(), &inbuf, &err);
+
+       ev = event_context_init(frame);
+       if (ev == NULL) {
+               goto fail;
+       }
+       req = read_smb_send(frame, ev, fd);
+       if (req == NULL) {
+               goto fail;
+       }
+       if (!tevent_req_poll(req, ev)) {
+               goto fail;
+       }
+       len = read_smb_recv(req, talloc_tos(), &inbuf, &err);
        if (len == -1) {
                errno = err;
                goto fail;
        }
+       TALLOC_FREE(ev);
 
-        if (CVAL(inbuf,0) != 0x82) {
-                /* This is the wrong place to put the error... JRA. */
-                cli->rap_error = CVAL(inbuf,4);
+       message_type = CVAL(inbuf, 0);
+       if (message_type != 0x83) {
+               d_fprintf(stderr, "Expected msg type 0x83, got 0x%2.2x\n",
+                         message_type);
+               goto fail;
+        }
+
+       if (smb_len(inbuf) != 1) {
+               d_fprintf(stderr, "Expected smb_len 1, got %d\n",
+                         (int)smb_len(inbuf));
+               goto fail;
+        }
+
+       error = CVAL(inbuf, 4);
+       if (error !=  0x82) {
+               d_fprintf(stderr, "Expected error 0x82, got %d\n",
+                         (int)error);
                goto fail;
         }
 
@@ -315,42 +326,6 @@ fail:
         return ret;
 }
 
-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.
  */
@@ -434,7 +409,7 @@ static bool torture_open_connection_share(struct cli_state **c,
                return False;
        }
 
-       (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */
+       cli_set_timeout(*c, 120000); /* set a really long timeout (2 minutes) */
 
        if (do_encrypt) {
                return force_cli_encryption(*c,
@@ -475,22 +450,35 @@ bool torture_open_connection(struct cli_state **c, int conn_index)
        return torture_open_connection_share(c, host, share);
 }
 
+bool torture_init_connection(struct cli_state **pcli)
+{
+       struct cli_state *cli;
+
+       cli = open_nbt_connection();
+       if (cli == NULL) {
+               return false;
+       }
+
+       *pcli = cli;
+       return true;
+}
+
 bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
 {
-       uint16 old_vuid = cli->vuid;
+       uint16_t old_vuid = cli_state_get_uid(cli);
        fstring old_user_name;
        size_t passlen = strlen(password);
        NTSTATUS status;
        bool ret;
 
        fstrcpy(old_user_name, cli->user_name);
-       cli->vuid = 0;
+       cli_state_set_uid(cli, 0);
        ret = NT_STATUS_IS_OK(cli_session_setup(cli, username,
                                                password, passlen,
                                                password, passlen,
                                                workgroup));
-       *new_vuid = cli->vuid;
-       cli->vuid = old_vuid;
+       *new_vuid = cli_state_get_uid(cli);
+       cli_state_set_uid(cli, old_vuid);
        status = cli_set_username(cli, old_user_name);
        if (!NT_STATUS_IS_OK(status)) {
                return false;
@@ -516,36 +504,70 @@ bool torture_close_connection(struct cli_state *c)
 }
 
 
+/* check if the server produced the expected dos or nt error code */
+static bool check_both_error(int line, NTSTATUS status,
+                            uint8 eclass, uint32 ecode, NTSTATUS nterr)
+{
+       if (NT_STATUS_IS_DOS(status)) {
+               uint8 cclass;
+               uint32 num;
+
+               /* Check DOS error */
+               cclass = NT_STATUS_DOS_CLASS(status);
+               num = NT_STATUS_DOS_CODE(status);
+
+               if (eclass != cclass || ecode != num) {
+                       printf("unexpected error code class=%d code=%d\n",
+                              (int)cclass, (int)num);
+                       printf(" expected %d/%d %s (line=%d)\n",
+                              (int)eclass, (int)ecode, nt_errstr(nterr), line);
+                       return false;
+               }
+       } else {
+               /* Check NT error */
+               if (!NT_STATUS_EQUAL(nterr, status)) {
+                       printf("unexpected error code %s\n",
+                               nt_errstr(status));
+                       printf(" expected %s (line=%d)\n",
+                               nt_errstr(nterr), line);
+                       return false;
+               }
+       }
+
+       return true;
+}
+
+
 /* check if the server produced the expected error code */
-static bool check_error(int line, struct cli_state *c, 
+static bool check_error(int line, NTSTATUS status,
                        uint8 eclass, uint32 ecode, NTSTATUS nterr)
 {
-        if (cli_is_dos_error(c)) {
+       if (NT_STATUS_IS_DOS(status)) {
                 uint8 cclass;
                 uint32 num;
 
                 /* Check DOS error */
 
-                cli_dos_error(c, &cclass, &num);
+               cclass = NT_STATUS_DOS_CLASS(status);
+               num = NT_STATUS_DOS_CODE(status);
 
                 if (eclass != cclass || ecode != num) {
                         printf("unexpected error code class=%d code=%d\n", 
                                (int)cclass, (int)num);
                         printf(" expected %d/%d %s (line=%d)\n", 
-                               (int)eclass, (int)ecode, nt_errstr(nterr), line);
+                               (int)eclass, (int)ecode, nt_errstr(nterr),
+                              line);
                         return False;
                 }
 
         } else {
-                NTSTATUS status;
-
                 /* Check NT error */
 
-                status = cli_nt_error(c);
-
                 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
-                        printf("unexpected error code %s\n", nt_errstr(status));
-                        printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
+                        printf("unexpected error code %s\n",
+                              nt_errstr(status));
+                        printf(" expected %s (line=%d)\n", nt_errstr(nterr),
+                              line);
                         return False;
                 }
         }
@@ -556,10 +578,20 @@ static bool check_error(int line, struct cli_state *c,
 
 static bool wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
 {
-       while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
-               if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
+       NTSTATUS status;
+
+       status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK);
+
+       while (!NT_STATUS_IS_OK(status)) {
+               if (!check_both_error(__LINE__, status, ERRDOS,
+                                     ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) {
+                       return false;
+               }
+
+               status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK);
        }
-       return True;
+
+       return true;
 }
 
 
@@ -573,6 +605,7 @@ static bool rw_torture(struct cli_state *c)
        int i, j;
        char buf[1024];
        bool correct = True;
+       size_t nread = 0;
        NTSTATUS status;
 
        memset(buf, '\0', sizeof(buf));
@@ -628,9 +661,16 @@ static bool rw_torture(struct cli_state *c)
 
                pid2 = 0;
 
-               if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
-                       printf("read failed (%s)\n", cli_errstr(c));
-                       correct = False;
+               status = cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid),
+                                 &nread);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("read failed (%s)\n", nt_errstr(status));
+                       correct = false;
+               } else if (nread != sizeof(pid)) {
+                       printf("read/write compare failed: "
+                              "recv %ld req %ld\n", (unsigned long)nread,
+                              (unsigned long)sizeof(pid));
+                       correct = false;
                }
 
                if (pid2 != pid) {
@@ -691,7 +731,7 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
        char buf_rd[131072];
        unsigned count;
        unsigned countprev = 0;
-       ssize_t sent = 0;
+       size_t sent = 0;
        bool correct = True;
        NTSTATUS status = NT_STATUS_OK;
 
@@ -703,8 +743,12 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
 
        if (procnum == 0)
        {
-               if (!NT_STATUS_IS_OK(cli_unlink(c, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
-                       printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c));
+               status = cli_unlink(
+                       c, lockfname,
+                       FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("unlink failed (%s) (normal, this file should "
+                              "not exist)\n", nt_errstr(status));
                }
 
                status = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
@@ -752,7 +796,7 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
                        }
 
                        status = cli_writeall(c, fnum, 0, (uint8_t *)buf+count,
-                                             count, (size_t)sent, NULL);
+                                             count, sent, NULL);
                        if (!NT_STATUS_IS_OK(status)) {
                                printf("write failed (%s)\n",
                                       nt_errstr(status));
@@ -761,18 +805,15 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
                }
                else
                {
-                       sent = cli_read(c, fnum, buf_rd+count, count,
-                                                 sizeof(buf)-count);
-                       if (sent < 0)
-                       {
+                       status = cli_read(c, fnum, buf_rd+count, count,
+                                         sizeof(buf)-count, &sent);
+                       if(!NT_STATUS_IS_OK(status)) {
                                printf("read failed offset:%d size:%ld (%s)\n",
                                       count, (unsigned long)sizeof(buf)-count,
-                                      cli_errstr(c));
+                                      nt_errstr(status));
                                correct = False;
                                sent = 0;
-                       }
-                       if (sent > 0)
-                       {
+                       } else if (sent > 0) {
                                if (memcmp(buf_rd+count, buf+count, sent) != 0)
                                {
                                        printf("read/write compare failed\n");
@@ -803,7 +844,7 @@ static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
        char buf[131072];
        char buf_rd[131072];
        bool correct = True;
-       ssize_t bytes_read;
+       size_t bytes_read;
        NTSTATUS status;
 
        status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
@@ -844,9 +885,15 @@ static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
                        break;
                }
 
-               if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
-                       printf("read failed (%s)\n", cli_errstr(c2));
-                       printf("read %d, expected %ld\n", (int)bytes_read, 
+               status = cli_read(c2, fnum2, buf_rd, 0, buf_size, &bytes_read);
+               if(!NT_STATUS_IS_OK(status)) {
+                       printf("read failed (%s)\n", nt_errstr(status));
+                       correct = false;
+                       break;
+               } else if (bytes_read != buf_size) {
+                       printf("read failed\n");
+                       printf("read %ld, expected %ld\n",
+                              (unsigned long)bytes_read,
                               (unsigned long)buf_size); 
                        correct = False;
                        break;
@@ -932,7 +979,7 @@ static bool run_readwritemulti(int dummy)
        return test;
 }
 
-static bool run_readwritelarge_internal(int max_xmit_k)
+static bool run_readwritelarge_internal(void)
 {
        static struct cli_state *cli1;
        uint16_t fnum1;
@@ -948,16 +995,6 @@ static bool run_readwritelarge_internal(int max_xmit_k)
        cli_sockopt(cli1, sockops);
        memset(buf,'\0',sizeof(buf));
 
-       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_internal\n");
 
        cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
@@ -1006,8 +1043,6 @@ static bool run_readwritelarge_internal(int max_xmit_k)
                return False;
        }
 
-       cli1->max_xmit = 4*1024;
-
        cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf), NULL);
 
        status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
@@ -1055,15 +1090,15 @@ static bool run_readwritelarge_internal(int max_xmit_k)
 
 static bool run_readwritelarge(int dummy)
 {
-       return run_readwritelarge_internal(128);
+       return run_readwritelarge_internal();
 }
 
 static bool run_readwritelarge_signtest(int dummy)
 {
        bool ret;
-       signing_state = Required;
-       ret = run_readwritelarge_internal(2);
-       signing_state = Undefined;
+       signing_state = SMB_SIGNING_REQUIRED;
+       ret = run_readwritelarge_internal();
+       signing_state = SMB_SIGNING_DEFAULT;
        return ret;
 }
 
@@ -1236,30 +1271,35 @@ static bool run_locktest1(int dummy)
                return False;
        }
 
-       if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
-               printf("lock1 failed (%s)\n", cli_errstr(cli1));
-               return False;
+       status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("lock1 failed (%s)\n", nt_errstr(status));
+               return false;
        }
 
-
-       if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
+       status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK);
+       if (NT_STATUS_IS_OK(status)) {
                printf("lock2 succeeded! This is a locking bug\n");
-               return False;
+               return false;
        } else {
-               if (!check_error(__LINE__, cli2, ERRDOS, ERRlock, 
-                                NT_STATUS_LOCK_NOT_GRANTED)) return False;
+               if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
+                                     NT_STATUS_LOCK_NOT_GRANTED)) {
+                       return false;
+               }
        }
 
-
        lock_timeout = (1 + (random() % 20));
        printf("Testing lock timeout with timeout=%u\n", lock_timeout);
        t1 = time(NULL);
-       if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
+       status = cli_lock32(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK);
+       if (NT_STATUS_IS_OK(status)) {
                printf("lock3 succeeded! This is a locking bug\n");
-               return False;
+               return false;
        } else {
-               if (!check_error(__LINE__, cli2, ERRDOS, ERRlock, 
-                                NT_STATUS_FILE_LOCK_CONFLICT)) return False;
+               if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
+                                     NT_STATUS_FILE_LOCK_CONFLICT)) {
+                       return false;
+               }
        }
        t2 = time(NULL);
 
@@ -1276,12 +1316,15 @@ static bool run_locktest1(int dummy)
                return False;
        }
 
-       if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
+       status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK);
+       if (NT_STATUS_IS_OK(status)) {
                printf("lock4 succeeded! This is a locking bug\n");
-               return False;
+               return false;
        } else {
-               if (!check_error(__LINE__, cli2, ERRDOS, ERRlock, 
-                                NT_STATUS_FILE_LOCK_CONFLICT)) return False;
+               if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
+                                     NT_STATUS_FILE_LOCK_CONFLICT)) {
+                       return false;
+               }
        }
 
        status = cli_close(cli1, fnum1);
@@ -1347,8 +1390,8 @@ static bool run_tcon_test(int dummy)
                return False;
        }
 
-       cnum1 = cli->cnum;
-       vuid1 = cli->vuid;
+       cnum1 = cli_state_get_tid(cli);
+       vuid1 = cli_state_get_uid(cli);
 
        status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
        if (!NT_STATUS_IS_OK(status)) {
@@ -1365,12 +1408,12 @@ static bool run_tcon_test(int dummy)
                return False;
        }
 
-       cnum2 = cli->cnum;
+       cnum2 = cli_state_get_tid(cli);
        cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
-       vuid2 = cli->vuid + 1;
+       vuid2 = cli_state_get_uid(cli) + 1;
 
        /* try a write with the wrong tid */
-       cli->cnum = cnum2;
+       cli_state_set_tid(cli, cnum2);
 
        status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
        if (NT_STATUS_IS_OK(status)) {
@@ -1383,7 +1426,7 @@ static bool run_tcon_test(int dummy)
 
 
        /* try a write with an invalid tid */
-       cli->cnum = cnum3;
+       cli_state_set_tid(cli, cnum3);
 
        status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
        if (NT_STATUS_IS_OK(status)) {
@@ -1395,8 +1438,8 @@ static bool run_tcon_test(int dummy)
        }
 
        /* try a write with an invalid vuid */
-       cli->vuid = vuid2;
-       cli->cnum = cnum1;
+       cli_state_set_uid(cli, vuid2);
+       cli_state_set_tid(cli, cnum1);
 
        status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
        if (NT_STATUS_IS_OK(status)) {
@@ -1407,8 +1450,8 @@ static bool run_tcon_test(int dummy)
                       nt_errstr(status));
        }
 
-       cli->cnum = cnum1;
-       cli->vuid = vuid1;
+       cli_state_set_tid(cli, cnum1);
+       cli_state_set_uid(cli, vuid1);
 
        status = cli_close(cli, fnum1);
        if (!NT_STATUS_IS_OK(status)) {
@@ -1416,7 +1459,7 @@ static bool run_tcon_test(int dummy)
                return False;
        }
 
-       cli->cnum = cnum2;
+       cli_state_set_tid(cli, cnum2);
 
        status = cli_tdis(cli);
        if (!NT_STATUS_IS_OK(status)) {
@@ -1424,7 +1467,7 @@ static bool run_tcon_test(int dummy)
                return False;
        }
 
-       cli->cnum = cnum1;
+       cli_state_set_tid(cli, cnum1);
 
        if (!torture_close_connection(cli)) {
                return False;
@@ -1635,37 +1678,48 @@ static bool run_locktest2(int dummy)
 
        cli_setpid(cli, 1);
 
-       if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
-               printf("lock1 failed (%s)\n", cli_errstr(cli));
-               return False;
+       status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("lock1 failed (%s)\n", nt_errstr(status));
+               return false;
        }
 
-       if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
+       status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK);
+       if (NT_STATUS_IS_OK(status)) {
                printf("WRITE lock1 succeeded! This is a locking bug\n");
-               correct = False;
+               correct = false;
        } else {
-               if (!check_error(__LINE__, cli, ERRDOS, ERRlock, 
-                                NT_STATUS_LOCK_NOT_GRANTED)) return False;
+               if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
+                                     NT_STATUS_LOCK_NOT_GRANTED)) {
+                       return false;
+               }
        }
 
-       if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
+       status = cli_lock32(cli, fnum2, 0, 4, 0, WRITE_LOCK);
+       if (NT_STATUS_IS_OK(status)) {
                printf("WRITE lock2 succeeded! This is a locking bug\n");
-               correct = False;
+               correct = false;
        } else {
-               if (!check_error(__LINE__, cli, ERRDOS, ERRlock, 
-                                NT_STATUS_LOCK_NOT_GRANTED)) return False;
+               if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
+                                     NT_STATUS_LOCK_NOT_GRANTED)) {
+                       return false;
+               }
        }
 
-       if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
+       status = cli_lock32(cli, fnum2, 0, 4, 0, READ_LOCK);
+       if (NT_STATUS_IS_OK(status)) {
                printf("READ lock2 succeeded! This is a locking bug\n");
-               correct = False;
+               correct = false;
        } else {
-               if (!check_error(__LINE__, cli, ERRDOS, ERRlock, 
-                                NT_STATUS_FILE_LOCK_CONFLICT)) return False;
+               if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
+                                NT_STATUS_FILE_LOCK_CONFLICT)) {
+                       return false;
+               }
        }
 
-       if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
-               printf("lock at 100 failed (%s)\n", cli_errstr(cli));
+       status = cli_lock32(cli, fnum1, 100, 4, 0, WRITE_LOCK);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("lock at 100 failed (%s)\n", nt_errstr(status));
        }
        cli_setpid(cli, 2);
        if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 100, 4))) {
@@ -1673,29 +1727,37 @@ static bool run_locktest2(int dummy)
                correct = False;
        }
 
-       if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 0, 4))) {
+       status = cli_unlock(cli, fnum1, 0, 4);
+       if (NT_STATUS_IS_OK(status)) {
                printf("unlock1 succeeded! This is a locking bug\n");
-               correct = False;
+               correct = false;
        } else {
-               if (!check_error(__LINE__, cli, 
-                                ERRDOS, ERRlock, 
-                                NT_STATUS_RANGE_NOT_LOCKED)) return False;
+               if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
+                                     NT_STATUS_RANGE_NOT_LOCKED)) {
+                       return false;
+               }
        }
 
-       if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 0, 8))) {
+       status = cli_unlock(cli, fnum1, 0, 8);
+       if (NT_STATUS_IS_OK(status)) {
                printf("unlock2 succeeded! This is a locking bug\n");
-               correct = False;
+               correct = false;
        } else {
-               if (!check_error(__LINE__, cli, 
-                                ERRDOS, ERRlock, 
-                                NT_STATUS_RANGE_NOT_LOCKED)) return False;
+               if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
+                                     NT_STATUS_RANGE_NOT_LOCKED)) {
+                       return false;
+               }
        }
 
-       if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
+       status = cli_lock32(cli, fnum3, 0, 4, 0, WRITE_LOCK);
+       if (NT_STATUS_IS_OK(status)) {
                printf("lock3 succeeded! This is a locking bug\n");
-               correct = False;
+               correct = false;
        } else {
-               if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
+               if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
+                                     NT_STATUS_LOCK_NOT_GRANTED)) {
+                       return false;
+               }
        }
 
        cli_setpid(cli, 1);
@@ -1770,17 +1832,20 @@ static bool run_locktest3(int dummy)
 
        for (offset=i=0;i<torture_numops;i++) {
                NEXT_OFFSET;
-               if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
+
+               status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK);
+               if (!NT_STATUS_IS_OK(status)) {
                        printf("lock1 %d failed (%s)\n", 
                               i,
-                              cli_errstr(cli1));
+                              nt_errstr(status));
                        return False;
                }
 
-               if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
+               status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK);
+               if (!NT_STATUS_IS_OK(status)) {
                        printf("lock2 %d failed (%s)\n", 
                               i,
-                              cli_errstr(cli1));
+                              nt_errstr(status));
                        return False;
                }
        }
@@ -1788,22 +1853,26 @@ static bool run_locktest3(int dummy)
        for (offset=i=0;i<torture_numops;i++) {
                NEXT_OFFSET;
 
-               if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
+               status = cli_lock32(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK);
+               if (NT_STATUS_IS_OK(status)) {
                        printf("error: lock1 %d succeeded!\n", i);
                        return False;
                }
 
-               if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
+               status = cli_lock32(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK);
+               if (NT_STATUS_IS_OK(status)) {
                        printf("error: lock2 %d succeeded!\n", i);
                        return False;
                }
 
-               if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
+               status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK);
+               if (NT_STATUS_IS_OK(status)) {
                        printf("error: lock3 %d succeeded!\n", i);
                        return False;
                }
 
-               if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
+               status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK);
+               if (NT_STATUS_IS_OK(status)) {
                        printf("error: lock4 %d succeeded!\n", i);
                        return False;
                }
@@ -1860,6 +1929,28 @@ static bool run_locktest3(int dummy)
        return correct;
 }
 
+static bool test_cli_read(struct cli_state *cli, uint16_t fnum,
+                           char *buf, off_t offset, size_t size,
+                           size_t *nread, size_t expect)
+{
+       NTSTATUS status;
+       size_t l_nread;
+
+       status = cli_read(cli, fnum, buf, offset, size, &l_nread);
+
+       if(!NT_STATUS_IS_OK(status)) {
+               return false;
+       } else if (l_nread != expect) {
+               return false;
+       }
+
+       if (nread) {
+               *nread = l_nread;
+       }
+
+       return true;
+}
+
 #define EXPECTED(ret, v) if ((ret) != (v)) { \
         printf("** "); correct = False; \
         }
@@ -1901,74 +1992,81 @@ static bool run_locktest4(int dummy)
                goto fail;
        }
 
-       ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
-             cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) &&
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 2, 4, 0, WRITE_LOCK));
        EXPECTED(ret, False);
        printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
 
-       ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
-             cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 10, 4, 0, READ_LOCK)) &&
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 12, 4, 0, READ_LOCK));
        EXPECTED(ret, True);
        printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
 
-       ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
-             cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 20, 4, 0, WRITE_LOCK)) &&
+             NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 22, 4, 0, WRITE_LOCK));
        EXPECTED(ret, False);
        printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
 
-       ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
-             cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 30, 4, 0, READ_LOCK)) &&
+             NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 32, 4, 0, READ_LOCK));
        EXPECTED(ret, True);
        printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
 
-       ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
-             (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
+       ret = (cli_setpid(cli1, 1),
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 40, 4, 0, WRITE_LOCK))) &&
+             (cli_setpid(cli1, 2),
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 42, 4, 0, WRITE_LOCK)));
        EXPECTED(ret, False);
        printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
 
-       ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
-             (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
+       ret = (cli_setpid(cli1, 1),
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 50, 4, 0, READ_LOCK))) &&
+             (cli_setpid(cli1, 2),
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 52, 4, 0, READ_LOCK)));
        EXPECTED(ret, True);
        printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
 
-       ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
-             cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK)) &&
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK));
        EXPECTED(ret, True);
        printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
 
-       ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
-             cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK)) &&
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK));
        EXPECTED(ret, False);
        printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
 
-       ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
-             cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, READ_LOCK)) &&
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, WRITE_LOCK));
        EXPECTED(ret, False);
        printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
 
-       ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
-             cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, WRITE_LOCK)) &&
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, READ_LOCK));
        EXPECTED(ret, True);
        printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
 
-       ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
-             (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
+       ret = (cli_setpid(cli1, 1),
+            NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, WRITE_LOCK))) &&
+            (cli_setpid(cli1, 2),
+            NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, READ_LOCK)));
        EXPECTED(ret, False);
        printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
 
-       ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
-             cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 110, 4, 0, READ_LOCK)) &&
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 112, 4, 0, READ_LOCK)) &&
              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 110, 6));
        EXPECTED(ret, False);
        printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
 
 
-       ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
-             (cli_read(cli2, fnum2, buf, 120, 4) == 4);
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 120, 4, 0, WRITE_LOCK)) &&
+             test_cli_read(cli2, fnum2, buf, 120, 4, NULL, 4);
        EXPECTED(ret, False);
        printf("this server %s strict write locking\n", ret?"doesn't do":"does");
 
-       ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK);
+       status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
+       ret = NT_STATUS_IS_OK(status);
        if (ret) {
                status = cli_writeall(cli2, fnum2, 0, (uint8_t *)buf, 130, 4,
                                      NULL);
@@ -1978,46 +2076,46 @@ static bool run_locktest4(int dummy)
        printf("this server %s strict read locking\n", ret?"doesn't do":"does");
 
 
-       ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
-             cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) &&
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) &&
              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4)) &&
              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4));
        EXPECTED(ret, True);
        printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
 
 
-       ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
-             cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, WRITE_LOCK)) &&
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, READ_LOCK)) &&
              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4)) &&
-             (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
+             test_cli_read(cli2, fnum2, buf, 150, 4, NULL, 4) &&
              !(NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
                                             150, 4, NULL))) &&
              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4));
        EXPECTED(ret, True);
        printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
 
-       ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 160, 4, 0, READ_LOCK)) &&
              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 160, 4)) &&
              NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
                                           160, 4, NULL)) &&
-             (cli_read(cli2, fnum2, buf, 160, 4) == 4);                
+             test_cli_read(cli2, fnum2, buf, 160, 4, NULL, 4);
        EXPECTED(ret, True);
        printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
 
-       ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 170, 4, 0, WRITE_LOCK)) &&
              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 170, 4)) &&
              NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
                                           170, 4, NULL)) &&
-             (cli_read(cli2, fnum2, buf, 170, 4) == 4);                
+             test_cli_read(cli2, fnum2, buf, 170, 4, NULL, 4);
        EXPECTED(ret, True);
        printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
 
-       ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
-             cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, WRITE_LOCK)) &&
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, READ_LOCK)) &&
              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 190, 4)) &&
              !NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
                                            190, 4, NULL)) &&
-             (cli_read(cli2, fnum2, buf, 190, 4) == 4);                
+             test_cli_read(cli2, fnum2, buf, 190, 4, NULL, 4);
        EXPECTED(ret, True);
        printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
 
@@ -2025,11 +2123,11 @@ static bool run_locktest4(int dummy)
        cli_close(cli2, fnum2);
        cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
        cli_open(cli1, fname, O_RDWR, DENY_NONE, &f);
-       ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
-             cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) &&
+             NT_STATUS_IS_OK(cli_lock32(cli1, f, 0, 1, 0, READ_LOCK)) &&
              NT_STATUS_IS_OK(cli_close(cli1, fnum1)) &&
              NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1)) &&
-             cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK));
         cli_close(cli1, f);
        cli_close(cli1, fnum1);
        EXPECTED(ret, True);
@@ -2085,23 +2183,25 @@ static bool run_locktest5(int dummy)
        }
 
        /* Check for NT bug... */
-       ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
-                 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) &&
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum3, 0, 1, 0, READ_LOCK));
        cli_close(cli1, fnum1);
        cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
-       ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
+       status = cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
+       ret = NT_STATUS_IS_OK(status);
        EXPECTED(ret, True);
        printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
        cli_close(cli1, fnum1);
        cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
        cli_unlock(cli1, fnum3, 0, 1);
 
-       ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
-             cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) &&
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 1, 1, 0, READ_LOCK));
        EXPECTED(ret, True);
        printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
 
-       ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
+       status = cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK);
+       ret = NT_STATUS_IS_OK(status);
        EXPECTED(ret, False);
 
        printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
@@ -2109,7 +2209,8 @@ static bool run_locktest5(int dummy)
        /* Unlock the process 2 lock. */
        cli_unlock(cli2, fnum2, 0, 4);
 
-       ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
+       status = cli_lock32(cli1, fnum3, 0, 4, 0, READ_LOCK);
+       ret = NT_STATUS_IS_OK(status);
        EXPECTED(ret, False);
 
        printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
@@ -2118,8 +2219,8 @@ static bool run_locktest5(int dummy)
        cli_unlock(cli1, fnum3, 0, 4);
 
        /* Stack 2 more locks here. */
-       ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
-                 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
+       ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK)) &&
+             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK));
 
        EXPECTED(ret, True);
        printf("the same process %s stack read locks\n", ret?"can":"cannot");
@@ -2128,7 +2229,7 @@ static bool run_locktest5(int dummy)
                removed. */
 
        ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
-                       cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
+             NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK));
 
        EXPECTED(ret, True);
        printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
@@ -2151,7 +2252,8 @@ static bool run_locktest5(int dummy)
        printf("the same process %s count the lock stack\n", !ret?"can":"cannot"); 
 
        /* Ensure connection 2 can get a write lock. */
-       ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
+       status = cli_lock32(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
+       ret = NT_STATUS_IS_OK(status);
        EXPECTED(ret, True);
 
        printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
@@ -2223,6 +2325,7 @@ static bool run_locktest7(int dummy)
        uint16_t fnum1;
        char buf[200];
        bool correct = False;
+       size_t nread;
        NTSTATUS status;
 
        if (!torture_open_connection(&cli1, 0)) {
@@ -2248,15 +2351,23 @@ static bool run_locktest7(int dummy)
 
        cli_setpid(cli1, 1);
 
-       if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
-               printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
+       status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Unable to apply read lock on range 130:4, "
+                      "error was %s\n", nt_errstr(status));
                goto fail;
        } else {
                printf("pid1 successfully locked range 130:4 for READ\n");
        }
 
-       if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
-               printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
+       status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("pid1 unable to read the range 130:4, error was %s\n",
+                     nt_errstr(status));
+               goto fail;
+       } else if (nread != 4) {
+               printf("pid1 unable to read the range 130:4, "
+                      "recv %ld req %d\n", (unsigned long)nread, 4);
                goto fail;
        } else {
                printf("pid1 successfully read the range 130:4\n");
@@ -2277,8 +2388,15 @@ static bool run_locktest7(int dummy)
 
        cli_setpid(cli1, 2);
 
-       if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
-               printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
+       status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("pid2 unable to read the range 130:4, error was %s\n",
+                     nt_errstr(status));
+               goto fail;
+       } else if (nread != 4) {
+               printf("pid2 unable to read the range 130:4, "
+                      "recv %ld req %d\n", (unsigned long)nread, 4);
+               goto fail;
        } else {
                printf("pid2 successfully read the range 130:4\n");
        }
@@ -2299,15 +2417,22 @@ static bool run_locktest7(int dummy)
        cli_setpid(cli1, 1);
        cli_unlock(cli1, fnum1, 130, 4);
 
-       if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
-               printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
+       status = cli_lock32(cli1, fnum1, 130, 4, 0, WRITE_LOCK);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Unable to apply write lock on range 130:4, error was %s\n", nt_errstr(status));
                goto fail;
        } else {
                printf("pid1 successfully locked range 130:4 for WRITE\n");
        }
 
-       if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
-               printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
+       status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("pid1 unable to read the range 130:4, error was %s\n",
+                     nt_errstr(status));
+               goto fail;
+       } else if (nread != 4) {
+               printf("pid1 unable to read the range 130:4, "
+                      "recv %ld req %d\n", (unsigned long)nread, 4);
                goto fail;
        } else {
                printf("pid1 successfully read the range 130:4\n");
@@ -2324,14 +2449,17 @@ static bool run_locktest7(int dummy)
 
        cli_setpid(cli1, 2);
 
-       if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
-               printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
-               if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
+       status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("pid2 unable to read the range 130:4, error was "
+                      "%s\n", nt_errstr(status));
+               if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
                        printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
                        goto fail;
                }
        } else {
-               printf("pid2 successfully read the range 130:4 (should be denied)\n");
+               printf("pid2 successfully read the range 130:4 (should be denied) recv %ld\n",
+                      (unsigned long)nread);
                goto fail;
        }
 
@@ -2403,9 +2531,10 @@ static bool run_locktest8(int dummy)
                goto fail;
        }
 
-       if (!cli_lock(cli1, fnum2, 1, 1, 0, READ_LOCK)) {
+       status = cli_lock32(cli1, fnum2, 1, 1, 0, READ_LOCK);
+       if (!NT_STATUS_IS_OK(status)) {
                printf("Unable to apply read lock on range 1:1, error was "
-                      "%s\n", cli_errstr(cli1));
+                      "%s\n", nt_errstr(status));
                goto fail;
        }
 
@@ -2442,7 +2571,7 @@ fail:
  */
 
 static bool got_alarm;
-static int alarm_fd;
+static struct cli_state *alarm_cli;
 
 static void alarm_handler(int dummy)
 {
@@ -2451,7 +2580,7 @@ static void alarm_handler(int dummy)
 
 static void alarm_handler_parent(int dummy)
 {
-       close(alarm_fd);
+       cli_state_disconnect(alarm_cli);
 }
 
 static void do_local_lock(int read_fd, int write_fd)
@@ -2585,7 +2714,8 @@ static bool run_locktest9(int dummy)
        }
 
        /* Ensure the child has the lock. */
-       if (cli_lock(cli1, fnum, 0, 4, 0, WRITE_LOCK)) {
+       status = cli_lock32(cli1, fnum, 0, 4, 0, WRITE_LOCK);
+       if (NT_STATUS_IS_OK(status)) {
                d_fprintf(stderr, "Got the lock on range 0:4 - this should not happen !\n");
                goto fail;
        } else {
@@ -2601,15 +2731,16 @@ static bool run_locktest9(int dummy)
        }
 
        /* Wait 20 seconds for the lock. */
-       alarm_fd = cli1->fd;
+       alarm_cli = cli1;
        CatchSignal(SIGALRM, alarm_handler_parent);
        alarm(20);
 
        start = timeval_current();
 
-       if (!cli_lock(cli1, fnum, 0, 4, -1, WRITE_LOCK)) {
+       status = cli_lock32(cli1, fnum, 0, 4, -1, WRITE_LOCK);
+       if (!NT_STATUS_IS_OK(status)) {
                d_fprintf(stderr, "Unable to apply write lock on range 0:4, error was "
-                      "%s\n", cli_errstr(cli1));
+                      "%s\n", nt_errstr(status));
                goto fail_nofd;
        }
        alarm(0);
@@ -2673,14 +2804,13 @@ static bool run_fdpasstest(int dummy)
                return False;
        }
 
-       cli2->vuid = cli1->vuid;
-       cli2->cnum = cli1->cnum;
-       cli2->pid = cli1->pid;
+       cli_state_set_uid(cli2, cli_state_get_uid(cli1));
+       cli_state_set_tid(cli2, cli_state_get_tid(cli1));
+       cli_setpid(cli2, cli_getpid(cli1));
 
-       if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
-               printf("read succeeded! nasty security hole [%s]\n",
-                      buf);
-               return False;
+       if (test_cli_read(cli2, fnum1, buf, 0, 13, NULL, 13)) {
+               printf("read succeeded! nasty security hole [%s]\n", buf);
+               return false;
        }
 
        cli_close(cli1, fnum1);
@@ -2715,11 +2845,11 @@ static bool run_fdsesstest(int dummy)
        if (!torture_cli_session_setup2(cli, &new_vuid))
                return False;
 
-       saved_cnum = cli->cnum;
+       saved_cnum = cli_state_get_tid(cli);
        if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, share, "?????", "", 1)))
                return False;
-       new_cnum = cli->cnum;
-       cli->cnum = saved_cnum;
+       new_cnum = cli_state_get_tid(cli);
+       cli_state_set_tid(cli, saved_cnum);
 
        printf("starting fdsesstest\n");
 
@@ -2739,13 +2869,13 @@ static bool run_fdsesstest(int dummy)
                return False;
        }
 
-       saved_vuid = cli->vuid;
-       cli->vuid = new_vuid;
+       saved_vuid = cli_state_get_uid(cli);
+       cli_state_set_uid(cli, new_vuid);
 
-       if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
-               printf("read succeeded with different vuid! nasty security hole [%s]\n",
-                      buf);
-               ret = False;
+       if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
+               printf("read succeeded with different vuid! "
+                      "nasty security hole [%s]\n", buf);
+               ret = false;
        }
        /* Try to open a file with different vuid, samba cnum. */
        if (NT_STATUS_IS_OK(cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {
@@ -2758,18 +2888,17 @@ static bool run_fdsesstest(int dummy)
                ret = False;
        }
 
-       cli->vuid = saved_vuid;
+       cli_state_set_uid(cli, saved_vuid);
 
        /* Try with same vuid, different cnum. */
-       cli->cnum = new_cnum;
+       cli_state_set_tid(cli, new_cnum);
 
-       if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
-               printf("read succeeded with different cnum![%s]\n",
-                      buf);
-               ret = False;
+       if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
+               printf("read succeeded with different cnum![%s]\n", buf);
+               ret = false;
        }
 
-       cli->cnum = saved_cnum;
+       cli_state_set_tid(cli, saved_cnum);
        cli_close(cli, fnum1);
        cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
@@ -2810,11 +2939,13 @@ static bool run_unlinktest(int dummy)
                return False;
        }
 
-       if (NT_STATUS_IS_OK(cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
+       status = cli_unlink(cli, fname,
+                           FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       if (NT_STATUS_IS_OK(status)) {
                printf("error: server allowed unlink on an open file\n");
                correct = False;
        } else {
-               correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare, 
+               correct = check_error(__LINE__, status, ERRDOS, ERRbadshare,
                                      NT_STATUS_SHARING_VIOLATION);
        }
 
@@ -2922,7 +3053,7 @@ static bool run_negprot_nowait(int dummy)
        for (i=0;i<50000;i++) {
                struct tevent_req *req;
 
-               req = cli_negprot_send(ev, ev, cli);
+               req = cli_negprot_send(ev, ev, cli, PROTOCOL_NT1);
                if (req == NULL) {
                        TALLOC_FREE(ev);
                        return false;
@@ -2948,15 +3079,37 @@ static bool run_negprot_nowait(int dummy)
 /* send smb negprot commands, not reading the response */
 static bool run_bad_nbt_session(int dummy)
 {
-       static struct cli_state *cli;
+       struct nmb_name called, calling;
+       struct sockaddr_storage ss;
+       NTSTATUS status;
+       int fd;
+       bool ret;
 
        printf("starting bad nbt session test\n");
 
-       if (!(cli = open_bad_nbt_connection())) {
-               return False;
+       make_nmb_name(&calling, myname, 0x0);
+       make_nmb_name(&called , host, 0x20);
+
+       if (!resolve_name(host, &ss, 0x20, true)) {
+               d_fprintf(stderr, "Could not resolve name %s\n", host);
+               return false;
+       }
+
+       status = open_socket_out(&ss, 139, 10000, &fd);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_fprintf(stderr, "open_socket_out failed: %s\n",
+                         nt_errstr(status));
+               return false;
+       }
+
+       ret = cli_bad_session_request(fd, &calling, &called);
+       close(fd);
+       if (!ret) {
+               d_fprintf(stderr, "open_socket_out failed: %s\n",
+                         nt_errstr(status));
+               return false;
        }
 
-       cli_shutdown(cli);
        printf("finished bad nbt session test\n");
        return true;
 }
@@ -3135,7 +3288,7 @@ static bool run_trans2test(int dummy)
        const char *fname = "\\trans2.tst";
        const char *dname = "\\trans2";
        const char *fname2 = "\\trans2\\trans2.tst";
-       char pname[1024];
+       char *pname;
        bool correct = True;
        NTSTATUS status;
        uint32_t fs_attr;
@@ -3162,7 +3315,7 @@ static bool run_trans2test(int dummy)
                correct = False;
        }
 
-       status = cli_qfilename(cli, fnum, pname, sizeof(pname));
+       status = cli_qfilename(cli, fnum, talloc_tos(), &pname);
        if (!NT_STATUS_IS_OK(status)) {
                printf("ERROR: qfilename failed (%s)\n", nt_errstr(status));
                correct = False;
@@ -3193,18 +3346,20 @@ static bool run_trans2test(int dummy)
                printf("ERROR: qpathinfo failed (%s)\n", nt_errstr(status));
                correct = False;
        } else {
+               time_t t = time(NULL);
+
                if (c_time != m_time) {
                        printf("create time=%s", ctime(&c_time));
                        printf("modify time=%s", ctime(&m_time));
                        printf("This system appears to have sticky create times\n");
                }
-               if (a_time % (60*60) == 0) {
+               if ((abs(a_time - t) > 60) && (a_time % (60*60) == 0)) {
                        printf("access time=%s", ctime(&a_time));
                        printf("This system appears to set a midnight access time\n");
                        correct = False;
                }
 
-               if (abs(m_time - time(NULL)) > 60*60*24*7) {
+               if (abs(m_time - t) > 60*60*24*7) {
                        printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
                        correct = False;
                }
@@ -3285,7 +3440,7 @@ static NTSTATUS new_trans(struct cli_state *pcli, int fnum, int level)
        NTSTATUS status;
 
        status = cli_qfileinfo(talloc_tos(), pcli, fnum, level, 0,
-                              pcli->max_xmit, &buf, &len);
+                              CLI_BUFFER_SIZE, NULL, &buf, &len);
        if (!NT_STATUS_IS_OK(status)) {
                printf("ERROR: qfileinfo (%d) failed (%s)\n", level,
                       nt_errstr(status));
@@ -3396,6 +3551,7 @@ static bool run_oplock2(int dummy)
        char buf[4];
        bool correct = True;
        volatile bool *shared_correct;
+       size_t nread;
        NTSTATUS status;
 
        shared_correct = (volatile bool *)shm_setup(sizeof(bool));
@@ -3412,18 +3568,12 @@ static bool run_oplock2(int dummy)
                return False;
        }
 
-       cli1->use_oplocks = True;
-       cli1->use_level_II_oplocks = True;
-
        if (!torture_open_connection(&cli2, 1)) {
                use_level_II_oplocks = False;
                use_oplocks = saved_use_oplocks;
                return False;
        }
 
-       cli2->use_oplocks = True;
-       cli2->use_level_II_oplocks = True;
-
        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        cli_sockopt(cli1, sockops);
@@ -3464,17 +3614,21 @@ static bool run_oplock2(int dummy)
 
        /* Ensure cli1 processes the break. Empty file should always return 0
         * bytes.  */
-
-       if (cli_read(cli1, fnum1, buf, 0, 4) != 0) {
-               printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
-               correct = False;
+       status = cli_read(cli1, fnum1, buf, 0, 4, &nread);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("read on fnum1 failed (%s)\n", nt_errstr(status));
+               correct = false;
+       } else if (nread != 0) {
+               printf("read on empty fnum1 failed. recv %ld expected %d\n",
+                     (unsigned long)nread, 0);
+               correct = false;
        }
 
        /* Should now be at level II. */
        /* Test if sending a write locks causes a break to none. */
-
-       if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
-               printf("lock failed (%s)\n", cli_errstr(cli1));
+       status = cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("lock failed (%s)\n", nt_errstr(status));
                correct = False;
        }
 
@@ -3482,8 +3636,9 @@ static bool run_oplock2(int dummy)
 
        sleep(2);
 
-       if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
-               printf("lock failed (%s)\n", cli_errstr(cli1));
+       status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("lock failed (%s)\n", nt_errstr(status));
                correct = False;
        }
 
@@ -3491,7 +3646,7 @@ static bool run_oplock2(int dummy)
 
        sleep(2);
 
-       cli_read(cli1, fnum1, buf, 0, 4);
+       cli_read(cli1, fnum1, buf, 0, 4, NULL);
 
        status = cli_close(cli1, fnum1);
        if (!NT_STATUS_IS_OK(status)) {
@@ -3520,63 +3675,6 @@ static bool run_oplock2(int dummy)
        return correct;
 }
 
-/* handler for oplock 3 tests */
-static NTSTATUS oplock3_handler(struct cli_state *cli, uint16_t fnum, unsigned char level)
-{
-       printf("got oplock break fnum=%d level=%d\n",
-              fnum, level);
-       return cli_oplock_ack(cli, fnum, level);
-}
-
-static bool run_oplock3(int dummy)
-{
-       struct cli_state *cli;
-       const char *fname = "\\oplockt3.dat";
-       uint16_t fnum;
-       char buf[4] = "abcd";
-       bool correct = True;
-       volatile bool *shared_correct;
-
-       shared_correct = (volatile bool *)shm_setup(sizeof(bool));
-       *shared_correct = True;
-
-       printf("starting oplock test 3\n");
-
-       if (fork() == 0) {
-               /* Child code */
-               use_oplocks = True;
-               use_level_II_oplocks = True;
-               if (!torture_open_connection(&cli, 0)) {
-                       *shared_correct = False;
-                       exit(0);
-               } 
-               sleep(2);
-               /* try to trigger a oplock break in parent */
-               cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
-               cli_writeall(cli, fnum, 0, (uint8_t *)buf, 0, 4, NULL);
-               exit(0);
-       }
-
-       /* parent code */
-       use_oplocks = True;
-       use_level_II_oplocks = True;
-       if (!torture_open_connection(&cli, 1)) { /* other is forked */
-               return False;
-       }
-       cli_oplock_handler(cli, oplock3_handler);
-       cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum);
-       cli_writeall(cli, fnum, 0, (uint8_t *)buf, 0, 4, NULL);
-       cli_close(cli, fnum);
-       cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
-       cli->timeout = 20000;
-       cli_receive_smb(cli);
-       printf("finished oplock test 3\n");
-
-       return (correct && *shared_correct);
-
-/* What are we looking for here?  What's sucess and what's FAILURE? */
-}
-
 struct oplock4_state {
        struct tevent_context *ev;
        struct cli_state *cli;
@@ -3671,10 +3769,7 @@ static bool run_oplock4(int dummy)
        }
 
        cli1->use_oplocks = true;
-       cli1->use_level_II_oplocks = true;
-
        cli2->use_oplocks = true;
-       cli2->use_level_II_oplocks = true;
 
        status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
        if (!NT_STATUS_IS_OK(status)) {
@@ -4424,7 +4519,7 @@ static bool run_properties(int dummy)
 
        cli_sockopt(cli, sockops);
 
-       d_printf("Capabilities 0x%08x\n", cli->capabilities);
+       d_printf("Capabilities 0x%08x\n", cli_state_capabilities(cli));
 
        if (!torture_close_connection(cli)) {
                correct = False;
@@ -4796,9 +4891,9 @@ static bool run_opentest(int dummy)
        }
 
        /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
-       cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
+       status = cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
 
-        if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess, 
+        if (check_error(__LINE__, status, ERRDOS, ERRnoaccess,
                        NT_STATUS_ACCESS_DENIED)) {
                printf("correct error code ERRDOS/ERRnoaccess returned\n");
        }
@@ -4818,9 +4913,9 @@ static bool run_opentest(int dummy)
        }
 
        /* This will fail - but the error should be ERRshare. */
-       cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
+       status = cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
 
-       if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare, 
+       if (check_error(__LINE__, status, ERRDOS, ERRbadshare,
                        NT_STATUS_SHARING_VIOLATION)) {
                printf("correct error code ERRDOS/ERRbadshare returned\n");
        }
@@ -5247,6 +5342,7 @@ static bool run_simple_posix_open_test(int dummy)
        SMB_STRUCT_STAT sbuf;
        bool correct = false;
        NTSTATUS status;
+       size_t nread;
 
        printf("Starting simple POSIX open test\n");
 
@@ -5344,20 +5440,23 @@ static bool run_simple_posix_open_test(int dummy)
        }
 
        /* Create again to test open with O_TRUNC. */
-       if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1))) {
-               printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
                goto out;
        }
 
        /* Test ftruncate - set file size. */
-       if (!NT_STATUS_IS_OK(cli_ftruncate(cli1, fnum1, 1000))) {
-               printf("ftruncate failed (%s)\n", cli_errstr(cli1));
+       status = cli_ftruncate(cli1, fnum1, 1000);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ftruncate failed (%s)\n", nt_errstr(status));
                goto out;
        }
 
        /* Ensure st_size == 1000 */
-       if (!NT_STATUS_IS_OK(cli_posix_stat(cli1, fname, &sbuf))) {
-               printf("stat failed (%s)\n", cli_errstr(cli1));
+       status = cli_posix_stat(cli1, fname, &sbuf);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("stat failed (%s)\n", nt_errstr(status));
                goto out;
        }
 
@@ -5366,20 +5465,23 @@ static bool run_simple_posix_open_test(int dummy)
                goto out;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("close(2) failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close(2) failed (%s)\n", nt_errstr(status));
                goto out;
        }
 
        /* Re-open with O_TRUNC. */
-       if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_WRONLY|O_TRUNC, 0600, &fnum1))) {
-               printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_posix_open(cli1, fname, O_WRONLY|O_TRUNC, 0600, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
                goto out;
        }
 
        /* Ensure st_size == 0 */
-       if (!NT_STATUS_IS_OK(cli_posix_stat(cli1, fname, &sbuf))) {
-               printf("stat failed (%s)\n", cli_errstr(cli1));
+       status = cli_posix_stat(cli1, fname, &sbuf);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("stat failed (%s)\n", nt_errstr(status));
                goto out;
        }
 
@@ -5388,30 +5490,34 @@ static bool run_simple_posix_open_test(int dummy)
                goto out;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("close failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close failed (%s)\n", nt_errstr(status));
                goto out;
        }
 
-       if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1, fname))) {
-               printf("POSIX unlink of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_posix_unlink(cli1, fname);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status));
                goto out;
        }
 
-       if (!NT_STATUS_IS_OK(cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1))) {
+       status = cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
                printf("POSIX open directory O_RDONLY of %s failed (%s)\n",
-                       dname, cli_errstr(cli1));
+                       dname, nt_errstr(status));
                goto out;
        }
 
        cli_close(cli1, fnum1);
 
        /* What happens when we try and POSIX open a directory for write ? */
-       if (NT_STATUS_IS_OK(cli_posix_open(cli1, dname, O_RDWR, 0, &fnum1))) {
+       status = cli_posix_open(cli1, dname, O_RDWR, 0, &fnum1);
+       if (NT_STATUS_IS_OK(status)) {
                printf("POSIX open of directory %s succeeded, should have failed.\n", fname);
                goto out;
        } else {
-               if (!check_error(__LINE__, cli1, ERRDOS, EISDIR,
+               if (!check_both_error(__LINE__, status, ERRDOS, EISDIR,
                                NT_STATUS_FILE_IS_A_DIRECTORY)) {
                        goto out;
                }
@@ -5456,8 +5562,14 @@ static bool run_simple_posix_open_test(int dummy)
                goto out;
        }
 
-       if (cli_read(cli1, fnum1, buf, 0, 10) != 10) {
-               printf("POSIX read of %s failed (%s)\n", hname, cli_errstr(cli1));
+       status = cli_read(cli1, fnum1, buf, 0, 10, &nread);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("POSIX read of %s failed (%s)\n", hname,
+                      nt_errstr(status));
+               goto out;
+       } else if (nread != 10) {
+               printf("POSIX read of %s failed. Received %ld, expected %d\n",
+                      hname, (unsigned long)nread, 10);
                goto out;
        }
 
@@ -5489,7 +5601,7 @@ static bool run_simple_posix_open_test(int dummy)
                printf("POSIX open of %s succeeded (should have failed)\n", sname);
                goto out;
        } else {
-               if (!check_error(__LINE__, cli1, ERRDOS, ERRbadpath,
+               if (!check_both_error(__LINE__, status, ERRDOS, ERRbadpath,
                                NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
                        printf("POSIX open of %s should have failed "
                                "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
@@ -5917,23 +6029,25 @@ bool torture_chkpath_test(int dummy)
 
        status = cli_chkpath(cli, "\\chkpath.dir\\foo.txt");
        if (!NT_STATUS_IS_OK(status)) {
-               ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath, 
+               ret = check_error(__LINE__, status, ERRDOS, ERRbadpath,
                                  NT_STATUS_NOT_A_DIRECTORY);
        } else {
                printf("* chkpath on a file should fail\n");
                ret = False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\bar.txt"))) {
-               ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile, 
+       status = cli_chkpath(cli, "\\chkpath.dir\\bar.txt");
+       if (!NT_STATUS_IS_OK(status)) {
+               ret = check_error(__LINE__, status, ERRDOS, ERRbadfile,
                                  NT_STATUS_OBJECT_NAME_NOT_FOUND);
        } else {
                printf("* chkpath on a non existant file should fail\n");
                ret = False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt"))) {
-               ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath, 
+       status = cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt");
+       if (!NT_STATUS_IS_OK(status)) {
+               ret = check_error(__LINE__, status, ERRDOS, ERRbadpath,
                                  NT_STATUS_OBJECT_PATH_NOT_FOUND);
        } else {
                printf("* chkpath on a non existent component should fail\n");
@@ -6175,7 +6289,7 @@ static bool run_error_map_extract(int dummy) {
 
        uint32 error;
 
-       uint32 flgs2, errnum;
+       uint32 errnum;
         uint8 errclass;
 
        NTSTATUS nt_status;
@@ -6184,13 +6298,14 @@ static bool run_error_map_extract(int dummy) {
 
        /* NT-Error connection */
 
+       disable_spnego = true;
        if (!(c_nt = open_nbt_connection())) {
+               disable_spnego = false;
                return False;
        }
+       disable_spnego = false;
 
-       c_nt->use_spnego = False;
-
-       status = cli_negprot(c_nt);
+       status = cli_negprot(c_nt, PROTOCOL_NT1);
 
        if (!NT_STATUS_IS_OK(status)) {
                printf("%s rejected the NT-error negprot (%s)\n", host,
@@ -6207,14 +6322,17 @@ static bool run_error_map_extract(int dummy) {
 
        /* DOS-Error connection */
 
+       disable_spnego = true;
+       force_dos_errors = true;
        if (!(c_dos = open_nbt_connection())) {
+               disable_spnego = false;
+               force_dos_errors = false;
                return False;
        }
+       disable_spnego = false;
+       force_dos_errors = false;
 
-       c_dos->use_spnego = False;
-       c_dos->force_dos_errors = True;
-
-       status = cli_negprot(c_dos);
+       status = cli_negprot(c_dos, PROTOCOL_NT1);
        if (!NT_STATUS_IS_OK(status)) {
                printf("%s rejected the DOS-error negprot (%s)\n", host,
                       nt_errstr(status));
@@ -6229,6 +6347,9 @@ static bool run_error_map_extract(int dummy) {
                return False;
        }
 
+       c_nt->map_dos_errors = false;
+       c_dos->map_dos_errors = false;
+
        for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
                fstr_sprintf(user, "%X", error);
 
@@ -6240,32 +6361,31 @@ static bool run_error_map_extract(int dummy) {
                        printf("/** Session setup succeeded.  This shouldn't happen...*/\n");
                }
 
-               flgs2 = SVAL(c_nt->inbuf,smb_flg2);
-
                /* Case #1: 32-bit NT errors */
-               if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
-                       nt_status = NT_STATUS(IVAL(c_nt->inbuf,smb_rcls));
+               if (!NT_STATUS_IS_DOS(status)) {
+                       nt_status = status;
                } else {
                        printf("/** Dos error on NT connection! (%s) */\n", 
-                              cli_errstr(c_nt));
+                              nt_errstr(status));
                        nt_status = NT_STATUS(0xc0000000);
                }
 
-               if (NT_STATUS_IS_OK(cli_session_setup(c_dos, user, 
-                                                     password, strlen(password),
-                                                     password, strlen(password),
-                                                     workgroup))) {
+               status = cli_session_setup(c_dos, user,
+                                          password, strlen(password),
+                                          password, strlen(password),
+                                          workgroup);
+               if (NT_STATUS_IS_OK(status)) {
                        printf("/** Session setup succeeded.  This shouldn't happen...*/\n");
                }
-               flgs2 = SVAL(c_dos->inbuf,smb_flg2), errnum;
 
                /* Case #1: 32-bit NT errors */
-               if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
+               if (NT_STATUS_IS_DOS(status)) {
                        printf("/** NT error on DOS connection! (%s) */\n", 
-                              cli_errstr(c_nt));
+                              nt_errstr(status));
                        errnum = errclass = 0;
                } else {
-                       cli_dos_error(c_dos, &errclass, &errnum);
+                       errclass = NT_STATUS_DOS_CLASS(status);
+                       errnum = NT_STATUS_DOS_CODE(status);
                }
 
                if (NT_STATUS_V(nt_status) != error) { 
@@ -6314,7 +6434,7 @@ static bool run_sesssetup_bench(int dummy)
                        return false;
                }
 
-               d_printf("\r%d   ", (int)c->vuid);
+               d_printf("\r%d   ", (int)cli_state_get_uid(c));
 
                status = cli_ulogoff(c);
                if (!NT_STATUS_IS_OK(status)) {
@@ -6322,7 +6442,6 @@ static bool run_sesssetup_bench(int dummy)
                                 __location__, nt_errstr(status));
                        return false;
                }
-               c->vuid = 0;
        }
 
        return true;
@@ -6422,7 +6541,7 @@ static bool run_chain1(int dummy)
        }
 
        while (!done) {
-               event_loop_once(evt);
+               tevent_loop_once(evt);
        }
 
        torture_close_connection(cli1);
@@ -6454,8 +6573,8 @@ static bool run_chain2(int dummy)
        NTSTATUS status;
 
        printf("starting chain2 test\n");
-       status = cli_start_connection(&cli1, global_myname(), host, NULL,
-                                     port_to_use, Undefined, 0);
+       status = cli_start_connection(&cli1, lp_netbios_name(), host, NULL,
+                                     port_to_use, SMB_SIGNING_DEFAULT, 0);
        if (!NT_STATUS_IS_OK(status)) {
                return False;
        }
@@ -6478,7 +6597,7 @@ static bool run_chain2(int dummy)
        }
 
        while (!done) {
-               event_loop_once(evt);
+               tevent_loop_once(evt);
        }
 
        torture_close_connection(cli1);
@@ -7055,7 +7174,7 @@ static bool run_uid_regression_test(int dummy)
        cli_sockopt(cli, sockops);
 
        /* Ok - now save then logoff our current user. */
-       old_vuid = cli->vuid;
+       old_vuid = cli_state_get_uid(cli);
 
        status = cli_ulogoff(cli);
        if (!NT_STATUS_IS_OK(status)) {
@@ -7065,7 +7184,7 @@ static bool run_uid_regression_test(int dummy)
                goto out;
        }
 
-       cli->vuid = old_vuid;
+       cli_state_set_uid(cli, old_vuid);
 
        /* Try an operation. */
        status = cli_mkdir(cli, "\\uid_reg_test");
@@ -7076,17 +7195,17 @@ static bool run_uid_regression_test(int dummy)
                goto out;
        } else {
                /* Should be bad uid. */
-               if (!check_error(__LINE__, cli, ERRSRV, ERRbaduid,
-                               NT_STATUS_USER_SESSION_DELETED)) {
+               if (!check_error(__LINE__, status, ERRSRV, ERRbaduid,
+                                NT_STATUS_USER_SESSION_DELETED)) {
                        correct = false;
                        goto out;
                }
        }
 
-       old_cnum = cli->cnum;
+       old_cnum = cli_state_get_tid(cli);
 
        /* Now try a SMBtdis with the invald vuid set to zero. */
-       cli->vuid = 0;
+       cli_state_set_uid(cli, 0);
 
        /* This should succeed. */
        status = cli_tdis(cli);
@@ -7099,8 +7218,8 @@ static bool run_uid_regression_test(int dummy)
                goto out;
        }
 
-       cli->vuid = old_vuid;
-       cli->cnum = old_cnum;
+       cli_state_set_uid(cli, old_vuid);
+       cli_state_set_tid(cli, old_cnum);
 
        /* This should fail. */
        status = cli_tdis(cli);
@@ -7110,7 +7229,7 @@ static bool run_uid_regression_test(int dummy)
                goto out;
        } else {
                /* Should be bad tid. */
-               if (!check_error(__LINE__, cli, ERRSRV, ERRinvnid,
+               if (!check_error(__LINE__, status, ERRSRV, ERRinvnid,
                                NT_STATUS_NETWORK_NAME_DELETED)) {
                        correct = false;
                        goto out;
@@ -7173,13 +7292,13 @@ static NTSTATUS shortname_list_fn(const char *mnt, struct file_info *finfo,
 #endif
 
        if (strchr(force_shortname_chars, i)) {
-               if (!finfo->short_name[0]) {
+               if (!finfo->short_name) {
                        /* Shortname not created when it should be. */
                        d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
                                __location__, finfo->name, i);
                        s->val = true;
                }
-       } else if (finfo->short_name[0]){
+       } else if (finfo->short_name){
                /* Shortname created when it should not be. */
                d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
                        __location__, finfo->short_name, finfo->name);
@@ -7244,11 +7363,11 @@ static bool run_shortname_test(int dummy)
                cli_close(cli, fnum);
 
                s.matched = 0;
-               cli_list(cli, "\\shortname\\test*.*", 0, shortname_list_fn,
-                        &s);
+               status = 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));
+                               __location__, fname, nt_errstr(status));
                        correct = false;
                        goto out;
                }
@@ -7654,26 +7773,29 @@ static bool rbt_testval(struct db_context *db, const char *key,
        TDB_DATA data = string_tdb_data(value);
        bool ret = false;
        NTSTATUS status;
+       TDB_DATA dbvalue;
 
-       rec = db->fetch_locked(db, db, string_tdb_data(key));
+       rec = dbwrap_fetch_locked(db, db, string_tdb_data(key));
        if (rec == NULL) {
                d_fprintf(stderr, "fetch_locked failed\n");
                goto done;
        }
-       status = rec->store(rec, data, 0);
+       status = dbwrap_record_store(rec, data, 0);
        if (!NT_STATUS_IS_OK(status)) {
                d_fprintf(stderr, "store failed: %s\n", nt_errstr(status));
                goto done;
        }
        TALLOC_FREE(rec);
 
-       rec = db->fetch_locked(db, db, string_tdb_data(key));
+       rec = dbwrap_fetch_locked(db, db, string_tdb_data(key));
        if (rec == NULL) {
                d_fprintf(stderr, "second fetch_locked failed\n");
                goto done;
        }
-       if ((rec->value.dsize != data.dsize)
-           || (memcmp(rec->value.dptr, data.dptr, data.dsize) != 0)) {
+
+       dbvalue = dbwrap_record_get_value(rec);
+       if ((dbvalue.dsize != data.dsize)
+           || (memcmp(dbvalue.dptr, data.dptr, data.dsize) != 0)) {
                d_fprintf(stderr, "Got wrong data back\n");
                goto done;
        }
@@ -8300,7 +8422,7 @@ static bool run_local_wbclient(int dummy)
                goto fail;
        }
 
-       wb_ctx = TALLOC_ARRAY(ev, struct wb_context *, nprocs);
+       wb_ctx = talloc_array(ev, struct wb_context *, nprocs);
        if (wb_ctx == NULL) {
                goto fail;
        }
@@ -8329,7 +8451,7 @@ static bool run_local_wbclient(int dummy)
        i = 0;
 
        while (i < nprocs * torture_numops) {
-               event_loop_once(ev);
+               tevent_loop_once(ev);
        }
 
        result = true;
@@ -8397,23 +8519,26 @@ static bool dbtrans_inc(struct db_context *db)
        uint32_t *val;
        bool ret = false;
        NTSTATUS status;
+       TDB_DATA value;
 
-       rec = db->fetch_locked(db, db, string_term_tdb_data("transtest"));
+       rec = dbwrap_fetch_locked(db, db, string_term_tdb_data("transtest"));
        if (rec == NULL) {
                printf(__location__ "fetch_lock failed\n");
                return false;
        }
 
-       if (rec->value.dsize != sizeof(uint32_t)) {
+       value = dbwrap_record_get_value(rec);
+
+       if (value.dsize != sizeof(uint32_t)) {
                printf(__location__ "value.dsize = %d\n",
-                      (int)rec->value.dsize);
+                      (int)value.dsize);
                goto fail;
        }
 
-       val = (uint32_t *)rec->value.dptr;
+       val = (uint32_t *)value.dptr;
        *val += 1;
 
-       status = rec->store(rec, make_tdb_data((uint8_t *)val,
+       status = dbwrap_record_store(rec, make_tdb_data((uint8_t *)val,
                                               sizeof(uint32_t)),
                            0);
        if (!NT_STATUS_IS_OK(status)) {
@@ -8435,6 +8560,7 @@ static bool run_local_dbtrans(int dummy)
        NTSTATUS status;
        uint32_t initial;
        int res;
+       TDB_DATA value;
 
        db = db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT,
                     O_RDWR|O_CREAT, 0600);
@@ -8443,21 +8569,23 @@ static bool run_local_dbtrans(int dummy)
                return false;
        }
 
-       res = db->transaction_start(db);
-       if (res == -1) {
+       res = dbwrap_transaction_start(db);
+       if (res != 0) {
                printf(__location__ "transaction_start failed\n");
                return false;
        }
 
-       rec = db->fetch_locked(db, db, string_term_tdb_data("transtest"));
+       rec = dbwrap_fetch_locked(db, db, string_term_tdb_data("transtest"));
        if (rec == NULL) {
                printf(__location__ "fetch_lock failed\n");
                return false;
        }
 
-       if (rec->value.dptr == NULL) {
+       value = dbwrap_record_get_value(rec);
+
+       if (value.dptr == NULL) {
                initial = 0;
-               status = rec->store(
+               status = dbwrap_record_store(
                        rec, make_tdb_data((uint8_t *)&initial,
                                           sizeof(initial)),
                        0);
@@ -8470,8 +8598,8 @@ static bool run_local_dbtrans(int dummy)
 
        TALLOC_FREE(rec);
 
-       res = db->transaction_commit(db);
-       if (res == -1) {
+       res = dbwrap_transaction_commit(db);
+       if (res != 0) {
                printf(__location__ "transaction_commit failed\n");
                return false;
        }
@@ -8480,14 +8608,16 @@ static bool run_local_dbtrans(int dummy)
                uint32_t val, val2;
                int i;
 
-               res = db->transaction_start(db);
-               if (res == -1) {
+               res = dbwrap_transaction_start(db);
+               if (res != 0) {
                        printf(__location__ "transaction_start failed\n");
                        break;
                }
 
-               if (!dbwrap_fetch_uint32(db, "transtest", &val)) {
-                       printf(__location__ "dbwrap_fetch_uint32 failed\n");
+               status = dbwrap_fetch_uint32(db, "transtest", &val);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf(__location__ "dbwrap_fetch_uint32 failed: %s\n",
+                              nt_errstr(status));
                        break;
                }
 
@@ -8497,8 +8627,10 @@ static bool run_local_dbtrans(int dummy)
                        }
                }
 
-               if (!dbwrap_fetch_uint32(db, "transtest", &val2)) {
-                       printf(__location__ "dbwrap_fetch_uint32 failed\n");
+               status = dbwrap_fetch_uint32(db, "transtest", &val2);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf(__location__ "dbwrap_fetch_uint32 failed: %s\n",
+                              nt_errstr(status));
                        break;
                }
 
@@ -8510,8 +8642,8 @@ static bool run_local_dbtrans(int dummy)
 
                printf("val2=%d\r", val2);
 
-               res = db->transaction_commit(db);
-               if (res == -1) {
+               res = dbwrap_transaction_commit(db);
+               if (res != 0) {
                        printf(__location__ "transaction_commit failed\n");
                        break;
                }
@@ -8686,7 +8818,6 @@ static struct {
        {"NBENCH2", run_nbench2, 0},
        {"OPLOCK1",  run_oplock1, 0},
        {"OPLOCK2",  run_oplock2, 0},
-       {"OPLOCK3",  run_oplock3, 0},
        {"OPLOCK4",  run_oplock4, 0},
        {"DIR",  run_dirtest, 0},
        {"DIR1",  run_dirtest1, 0},
@@ -8733,6 +8864,8 @@ static struct {
        { "CHAIN1", run_chain1, 0},
        { "CHAIN2", run_chain2, 0},
        { "WINDOWS-WRITE", run_windows_write, 0},
+       { "NTTRANS-CREATE", run_nttrans_create, 0},
+       { "NTTRANS-FSCTL", run_nttrans_fsctl, 0},
        { "CLI_ECHO", run_cli_echo, 0},
        { "GETADDRINFO", run_getaddrinfo_send, 0},
        { "TLDAP", run_tldap },
@@ -8741,6 +8874,7 @@ static struct {
        { "BAD-NBT-SESSION", run_bad_nbt_session },
        { "SMB-ANY-CONNECT", run_smb_any_connect },
        { "NOTIFY-ONLINE", run_notify_online },
+       { "SMB2-BASIC", run_smb2_basic },
        { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
        { "LOCAL-GENCACHE", run_local_gencache, 0},
        { "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
@@ -8754,6 +8888,8 @@ static struct {
        { "LOCAL-DBTRANS", run_local_dbtrans, 0},
        { "LOCAL-TEVENT-SELECT", run_local_tevent_select, 0},
        { "LOCAL-CONVERT-STRING", run_local_convert_string, 0},
+       { "LOCAL-CONV-AUTH-INFO", run_local_conv_auth_info, 0},
+       { "LOCAL-sprintf_append", run_local_sprintf_append, 0},
        {NULL, NULL, 0}};
 
 
@@ -8874,7 +9010,7 @@ static void usage(void)
                        set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH"));
                }
        }
-       lp_load(get_dyn_CONFIGFILE(),True,False,False,True);
+       lp_load_global(get_dyn_CONFIGFILE());
        load_interfaces();
 
        if (argc < 2) {