s3: Remove the smbtorture3 OPLOCK3 test
[kai/samba.git] / source3 / torture / torture.c
index bf89ca35b1cef587c5a009375947ccca65c637bf..64ba5431d6a8b81d51e4c91e5dbf372968732378 100644 (file)
 */
 
 #include "includes.h"
-#include "nsswitch/libwbclient/wbc_async.h"
+#include "system/shmem.h"
+#include "wbc_async.h"
+#include "torture/proto.h"
+#include "libcli/security/security.h"
+#include "tldap.h"
+#include "tldap_util.h"
+#include "../librpc/gen_ndr/svcctl.h"
+#include "memcache.h"
+#include "nsswitch/winbind_client.h"
+#include "dbwrap.h"
+#include "talloc_dict.h"
+#include "async_smb.h"
+#include "libsmb/libsmb.h"
+#include "libsmb/clirap.h"
+#include "trans2.h"
+#include "libsmb/nmblib.h"
+#include "../lib/util/tevent_ntstatus.h"
+#include "util_tdb.h"
+#include "libsmb/read_smb.h"
 
 extern char *optarg;
 extern int optind;
@@ -42,28 +60,14 @@ 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;
+char *test_filename;
 
 bool torture_showall = False;
 
 static double create_procs(bool (*fn)(int), bool *result);
 
 
-static struct timeval tp1,tp2;
-
-
-void start_timer(void)
-{
-       GetTimeOfDay(&tp1);
-}
-
-double end_timer(void)
-{
-       GetTimeOfDay(&tp2);
-       return((tp2.tv_sec - tp1.tv_sec) + 
-              (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
-}
-
-
 /* return a pointer to a anonymous shared memory segment of size "size"
    which will persist across fork() but will disappear when all processes
    exit 
@@ -184,7 +188,7 @@ static struct cli_state *open_nbt_connection(void)
 
         zero_sockaddr(&ss);
 
-       if (!(c = cli_initialise())) {
+       if (!(c = cli_initialise_ex(signing_state))) {
                printf("Failed initialize cli_struct to connect with %s\n", host);
                return NULL;
        }
@@ -227,6 +231,126 @@ static struct cli_state *open_nbt_connection(void)
        return c;
 }
 
+/****************************************************************************
+ Send a corrupt session request. See rfc1002.txt 4.3 and 4.3.2.
+****************************************************************************/
+
+static bool cli_bad_session_request(struct cli_state *cli,
+                         struct nmb_name *calling, struct nmb_name *called)
+{
+       TALLOC_CTX *frame;
+       uint8_t len_buf[4];
+       struct iovec iov[3];
+       ssize_t len;
+       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;
+
+       frame = talloc_stackframe();
+
+       iov[0].iov_base = len_buf;
+       iov[0].iov_len  = sizeof(len_buf);
+
+       /* put in the destination name */
+
+       iov[1].iov_base = name_mangle(talloc_tos(), called->name,
+                                     called->name_type);
+       if (iov[1].iov_base == NULL) {
+               goto fail;
+       }
+       iov[1].iov_len = name_len((unsigned char *)iov[1].iov_base,
+                                 talloc_get_size(iov[1].iov_base));
+
+       /* and my name */
+
+       iov[2].iov_base = name_mangle(talloc_tos(), calling->name,
+                                     calling->name_type);
+       if (iov[2].iov_base == NULL) {
+               goto fail;
+       }
+       iov[2].iov_len = name_len((unsigned char *)iov[2].iov_base,
+                                 talloc_get_size(iov[2].iov_base));
+
+       /* Deliberately corrupt the name len (first byte) */
+       *((uint8_t *)iov[2].iov_base) = 100;
+
+       /* send a session request (RFC 1002) */
+       /* setup the packet length
+         * Remove four bytes from the length count, since the length
+         * field in the NBT Session Service header counts the number
+         * of bytes which follow.  The cli_send_smb() function knows
+         * about this and accounts for those four bytes.
+         * CRH.
+         */
+
+       _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);
+       if (len == -1) {
+               goto fail;
+       }
+       len = read_smb(cli->fd, talloc_tos(), &inbuf, &err);
+       if (len == -1) {
+               errno = err;
+               goto fail;
+       }
+
+        if (CVAL(inbuf,0) != 0x82) {
+                /* This is the wrong place to put the error... JRA. */
+                cli->rap_error = CVAL(inbuf,4);
+               goto fail;
+        }
+
+       ret = true;
+fail:
+       TALLOC_FREE(frame);
+        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.
  */
@@ -289,7 +413,6 @@ static bool torture_open_connection_share(struct cli_state **c,
                                   const char *hostname, 
                                   const char *sharename)
 {
-       bool retry;
        int flags = 0;
        NTSTATUS status;
 
@@ -304,7 +427,7 @@ static bool torture_open_connection_share(struct cli_state **c,
                                     hostname, NULL, port_to_use, 
                                     sharename, "?????", 
                                     username, workgroup, 
-                                    password, flags, Undefined, &retry);
+                                    password, flags, signing_state);
        if (!NT_STATUS_IS_OK(status)) {
                printf("failed to open share connection: //%s/%s port:%d - %s\n",
                        hostname, sharename, port_to_use, nt_errstr(status));
@@ -379,8 +502,11 @@ bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
 bool torture_close_connection(struct cli_state *c)
 {
        bool ret = True;
-       if (!cli_tdis(c)) {
-               printf("tdis failed (%s)\n", cli_errstr(c));
+       NTSTATUS status;
+
+       status = cli_tdis(c);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("tdis failed (%s)\n", nt_errstr(status));
                ret = False;
        }
 
@@ -457,12 +583,14 @@ static bool rw_torture(struct cli_state *c)
                status = cli_open(c, lockfname, O_RDWR, DENY_NONE, &fnum2);
        }
        if (!NT_STATUS_IS_OK(status)) {
-               printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
+               printf("open of %s failed (%s)\n",
+                      lockfname, nt_errstr(status));
                return False;
        }
 
        for (i=0;i<torture_numops;i++) {
                unsigned n = (unsigned)sys_random()%10;
+
                if (i % 10 == 0) {
                        printf("%d\r", i); fflush(stdout);
                }
@@ -472,22 +600,28 @@ static bool rw_torture(struct cli_state *c)
                        return False;
                }
 
-               if (!NT_STATUS_IS_OK(cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL, &fnum))) {
-                       printf("open failed (%s)\n", cli_errstr(c));
+               status = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC,
+                                  DENY_ALL, &fnum);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("open failed (%s)\n", nt_errstr(status));
                        correct = False;
                        break;
                }
 
-               if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
-                       printf("write failed (%s)\n", cli_errstr(c));
+               status = cli_writeall(c, fnum, 0, (uint8_t *)&pid, 0,
+                                     sizeof(pid), NULL);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("write failed (%s)\n", nt_errstr(status));
                        correct = False;
                }
 
                for (j=0;j<50;j++) {
-                       if (cli_write(c, fnum, 0, (char *)buf, 
-                                     sizeof(pid)+(j*sizeof(buf)), 
-                                     sizeof(buf)) != sizeof(buf)) {
-                               printf("write failed (%s)\n", cli_errstr(c));
+                       status = cli_writeall(c, fnum, 0, (uint8_t *)buf,
+                                             sizeof(pid)+(j*sizeof(buf)),
+                                             sizeof(buf), NULL);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               printf("write failed (%s)\n",
+                                      nt_errstr(status));
                                correct = False;
                        }
                }
@@ -504,24 +638,27 @@ static bool rw_torture(struct cli_state *c)
                        correct = False;
                }
 
-               if (!NT_STATUS_IS_OK(cli_close(c, fnum))) {
-                       printf("close failed (%s)\n", cli_errstr(c));
+               status = cli_close(c, fnum);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("close failed (%s)\n", nt_errstr(status));
                        correct = False;
                }
 
-               if (!NT_STATUS_IS_OK(cli_unlink(c, fname, aSYSTEM | aHIDDEN))) {
-                       printf("unlink failed (%s)\n", cli_errstr(c));
+               status = cli_unlink(c, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("unlink failed (%s)\n", nt_errstr(status));
                        correct = False;
                }
 
-               if (!NT_STATUS_IS_OK(cli_unlock(c, fnum2, n*sizeof(int), sizeof(int)))) {
-                       printf("unlock failed (%s)\n", cli_errstr(c));
+               status = cli_unlock(c, fnum2, n*sizeof(int), sizeof(int));
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("unlock failed (%s)\n", nt_errstr(status));
                        correct = False;
                }
        }
 
        cli_close(c, fnum2);
-       cli_unlink(c, lockfname, aSYSTEM | aHIDDEN);
+       cli_unlink(c, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        printf("%d\n", i);
 
@@ -556,7 +693,7 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
        unsigned countprev = 0;
        ssize_t sent = 0;
        bool correct = True;
-       NTSTATUS status;
+       NTSTATUS status = NT_STATUS_OK;
 
        srandom(1);
        for (i = 0; i < sizeof(buf); i += sizeof(uint32))
@@ -566,10 +703,15 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
 
        if (procnum == 0)
        {
-               if (!NT_STATUS_IS_OK(cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL, 
-                                DENY_NONE, &fnum))) {
+               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_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
+                                 DENY_NONE, &fnum);
+               if (!NT_STATUS_IS_OK(status)) {
                        printf("first open read/write of %s failed (%s)\n",
-                                       lockfname, cli_errstr(c));
+                                       lockfname, nt_errstr(status));
                        return False;
                }
        }
@@ -586,7 +728,7 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
                }
                if (!NT_STATUS_IS_OK(status)) {
                        printf("second open read-only of %s failed (%s)\n",
-                                       lockfname, cli_errstr(c));
+                                       lockfname, nt_errstr(status));
                        return False;
                }
        }
@@ -609,8 +751,11 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
                                sent = sizeof(buf) - count;
                        }
 
-                       if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
-                               printf("write failed (%s)\n", cli_errstr(c));
+                       status = cli_writeall(c, fnum, 0, (uint8_t *)buf+count,
+                                             count, (size_t)sent, NULL);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               printf("write failed (%s)\n",
+                                      nt_errstr(status));
                                correct = False;
                        }
                }
@@ -640,8 +785,9 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
 
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(c, fnum))) {
-               printf("close failed (%s)\n", cli_errstr(c));
+       status = cli_close(c, fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close failed (%s)\n", nt_errstr(status));
                correct = False;
        }
 
@@ -658,26 +804,30 @@ static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
        char buf_rd[131072];
        bool correct = True;
        ssize_t bytes_read;
+       NTSTATUS status;
 
-       if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, aSYSTEM | aHIDDEN))) {
-               printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
+       status = cli_unlink(c1, 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));
        }
 
-       if (!NT_STATUS_IS_OK(cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL, 
-                        DENY_NONE, &fnum1))) {
+       status = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
+                         DENY_NONE, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
                printf("first open read/write of %s failed (%s)\n",
-                               lockfname, cli_errstr(c1));
+                               lockfname, nt_errstr(status));
                return False;
        }
-       if (!NT_STATUS_IS_OK(cli_open(c2, lockfname, O_RDONLY, 
-                        DENY_NONE, &fnum2))) {
+
+       status = cli_open(c2, lockfname, O_RDONLY, DENY_NONE, &fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
                printf("second open read-only of %s failed (%s)\n",
-                               lockfname, cli_errstr(c2));
+                               lockfname, nt_errstr(status));
                cli_close(c1, fnum1);
                return False;
        }
 
-       for (i=0;i<torture_numops;i++)
+       for (i = 0; i < torture_numops; i++)
        {
                size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
                if (i % 10 == 0) {
@@ -686,8 +836,10 @@ static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
 
                generate_random_buffer((unsigned char *)buf, buf_size);
 
-               if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
-                       printf("write failed (%s)\n", cli_errstr(c1));
+               status = cli_writeall(c1, fnum1, 0, (uint8_t *)buf, 0,
+                                     buf_size, NULL);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("write failed (%s)\n", nt_errstr(status));
                        correct = False;
                        break;
                }
@@ -708,17 +860,21 @@ static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
                }
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(c2, fnum2))) {
-               printf("close failed (%s)\n", cli_errstr(c2));
+       status = cli_close(c2, fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close failed (%s)\n", nt_errstr(status));
                correct = False;
        }
-       if (!NT_STATUS_IS_OK(cli_close(c1, fnum1))) {
-               printf("close failed (%s)\n", cli_errstr(c1));
+
+       status = cli_close(c1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close failed (%s)\n", nt_errstr(status));
                correct = False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, aSYSTEM | aHIDDEN))) {
-               printf("unlink failed (%s)\n", cli_errstr(c1));
+       status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("unlink failed (%s)\n", nt_errstr(status));
                correct = False;
        }
 
@@ -776,7 +932,7 @@ static bool run_readwritemulti(int dummy)
        return test;
 }
 
-static bool run_readwritelarge(int dummy)
+static bool run_readwritelarge_internal(int max_xmit_k)
 {
        static struct cli_state *cli1;
        uint16_t fnum1;
@@ -784,6 +940,7 @@ static bool run_readwritelarge(int dummy)
        SMB_OFF_T fsize;
        char buf[126*1024];
        bool correct = True;
+       NTSTATUS status;
 
        if (!torture_open_connection(&cli1, 0)) {
                return False;
@@ -791,62 +948,80 @@ static bool run_readwritelarge(int dummy)
        cli_sockopt(cli1, sockops);
        memset(buf,'\0',sizeof(buf));
 
-       cli1->max_xmit = 128*1024;
+       cli1->max_xmit = max_xmit_k*1024;
 
-       printf("starting readwritelarge\n");
+       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, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE, &fnum1))) {
-               printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
+       status = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL,
+                         DENY_NONE, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status));
                return False;
        }
 
-       cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
+       cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf), NULL);
 
-       if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
-               printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
+       status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
+                                    NULL, NULL, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("qfileinfo failed (%s)\n", nt_errstr(status));
                correct = False;
        }
 
        if (fsize == sizeof(buf))
-               printf("readwritelarge test 1 succeeded (size = %lx)\n", 
+               printf("readwritelarge_internal test 1 succeeded (size = %lx)\n",
                       (unsigned long)fsize);
        else {
-               printf("readwritelarge test 1 failed (size = %lx)\n", 
+               printf("readwritelarge_internal test 1 failed (size = %lx)\n",
                       (unsigned long)fsize);
                correct = False;
        }
 
-       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));
                correct = False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_unlink(cli1, lockfname, aSYSTEM | aHIDDEN))) {
-               printf("unlink failed (%s)\n", cli_errstr(cli1));
+       status = cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("unlink failed (%s)\n", nt_errstr(status));
                correct = False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE, &fnum1))) {
-               printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
+       status = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL,
+                         DENY_NONE, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status));
                return False;
        }
 
        cli1->max_xmit = 4*1024;
 
-       cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
+       cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf), NULL);
 
-       if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
-               printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
+       status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
+                                    NULL, NULL, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("qfileinfo failed (%s)\n", nt_errstr(status));
                correct = False;
        }
 
        if (fsize == sizeof(buf))
-               printf("readwritelarge test 2 succeeded (size = %lx)\n", 
+               printf("readwritelarge_internal test 2 succeeded (size = %lx)\n",
                       (unsigned long)fsize);
        else {
-               printf("readwritelarge test 2 failed (size = %lx)\n", 
+               printf("readwritelarge_internal test 2 failed (size = %lx)\n",
                       (unsigned long)fsize);
                correct = False;
        }
@@ -857,7 +1032,8 @@ static bool run_readwritelarge(int dummy)
                printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
                return False;
        }
-       if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
+       if (!cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL,
+                                NULL, NULL)) {
                printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
                correct = False;
        }
@@ -865,8 +1041,9 @@ static bool run_readwritelarge(int dummy)
                printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
 #endif
 
-       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));
                correct = False;
        }
 
@@ -876,6 +1053,20 @@ static bool run_readwritelarge(int dummy)
        return correct;
 }
 
+static bool run_readwritelarge(int dummy)
+{
+       return run_readwritelarge_internal(128);
+}
+
+static bool run_readwritelarge_signtest(int dummy)
+{
+       bool ret;
+       signing_state = Required;
+       ret = run_readwritelarge_internal(2);
+       signing_state = Undefined;
+       return ret;
+}
+
 int line_count = 0;
 int nbio_id;
 
@@ -1014,6 +1205,7 @@ static bool run_locktest1(int dummy)
        uint16_t fnum1, fnum2, fnum3;
        time_t t1, t2;
        unsigned lock_timeout;
+       NTSTATUS status;
 
        if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
                return False;
@@ -1023,18 +1215,24 @@ static bool run_locktest1(int dummy)
 
        printf("starting locktest1\n");
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
-               printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
+                         &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
-       if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum2))) {
-               printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
+
+       status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
-       if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum3))) {
-               printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
+
+       status = cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum3);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open3 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
@@ -1072,8 +1270,9 @@ static bool run_locktest1(int dummy)
        printf("server slept for %u seconds for a %u second timeout\n",
               (unsigned int)(t2-t1), lock_timeout);
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
-               printf("close1 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close1 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
@@ -1085,18 +1284,21 @@ static bool run_locktest1(int dummy)
                                 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("close2 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close2 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli2, fnum3))) {
-               printf("close3 failed (%s)\n", cli_errstr(cli2));
+       status = cli_close(cli2, fnum3);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close3 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
-               printf("unlink failed (%s)\n", cli_errstr(cli1));
+       status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("unlink failed (%s)\n", nt_errstr(status));
                return False;
        }
 
@@ -1137,18 +1339,20 @@ static bool run_tcon_test(int dummy)
 
        printf("starting tcontest\n");
 
-       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
-               printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
+       status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
        cnum1 = cli->cnum;
        vuid1 = cli->vuid;
 
-       if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
-               printf("initial write failed (%s)", cli_errstr(cli));
+       status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("initial write failed (%s)", nt_errstr(status));
                return False;
        }
 
@@ -1168,47 +1372,55 @@ static bool run_tcon_test(int dummy)
        /* try a write with the wrong tid */
        cli->cnum = cnum2;
 
-       if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
+       status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
+       if (NT_STATUS_IS_OK(status)) {
                printf("* server allows write with wrong TID\n");
                ret = False;
        } else {
-               printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
+               printf("server fails write with wrong TID : %s\n",
+                      nt_errstr(status));
        }
 
 
        /* try a write with an invalid tid */
        cli->cnum = cnum3;
 
-       if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
+       status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
+       if (NT_STATUS_IS_OK(status)) {
                printf("* server allows write with invalid TID\n");
                ret = False;
        } else {
-               printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
+               printf("server fails write with invalid TID : %s\n",
+                      nt_errstr(status));
        }
 
        /* try a write with an invalid vuid */
        cli->vuid = vuid2;
        cli->cnum = cnum1;
 
-       if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
+       status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
+       if (NT_STATUS_IS_OK(status)) {
                printf("* server allows write with invalid VUID\n");
                ret = False;
        } else {
-               printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
+               printf("server fails write with invalid VUID : %s\n",
+                      nt_errstr(status));
        }
 
        cli->cnum = cnum1;
        cli->vuid = vuid1;
 
-       if (!NT_STATUS_IS_OK(cli_close(cli, fnum1))) {
-               printf("close failed (%s)\n", cli_errstr(cli));
+       status = cli_close(cli, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close failed (%s)\n", nt_errstr(status));
                return False;
        }
 
        cli->cnum = cnum2;
 
-       if (!cli_tdis(cli)) {
-               printf("secondary tdis failed (%s)\n", cli_errstr(cli));
+       status = cli_tdis(cli);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("secondary tdis failed (%s)\n", nt_errstr(status));
                return False;
        }
 
@@ -1245,11 +1457,13 @@ static bool run_tcon2_test(int dummy)
 
        status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
 
+       SAFE_FREE(service);
+
        if (!NT_STATUS_IS_OK(status)) {
-               printf("tcon2 failed : %s\n", cli_errstr(cli));
+               printf("tcon2 failed : %s\n", nt_errstr(status));
        } else {
-               printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n", 
-                      (int)max_xmit, (int)cnum, SVAL(cli->inbuf, smb_tid));
+               printf("tcon OK : max_xmit=%d cnum=%d\n",
+                      (int)max_xmit, (int)cnum);
        }
 
        if (!torture_close_connection(cli)) {
@@ -1314,7 +1528,6 @@ static bool tcon_devtest(struct cli_state *cli,
 static bool run_tcon_devtype_test(int dummy)
 {
        static struct cli_state *cli1 = NULL;
-       bool retry;
        int flags = 0;
        NTSTATUS status;
        bool ret = True;
@@ -1323,7 +1536,7 @@ static bool run_tcon_devtype_test(int dummy)
                                     host, NULL, port_to_use,
                                     NULL, NULL,
                                     username, workgroup,
-                                    password, flags, Undefined, &retry);
+                                    password, flags, signing_state);
 
        if (!NT_STATUS_IS_OK(status)) {
                printf("could not open connection\n");
@@ -1386,6 +1599,7 @@ static bool run_locktest2(int dummy)
        const char *fname = "\\lockt2.lck";
        uint16_t fnum1, fnum2, fnum3;
        bool correct = True;
+       NTSTATUS status;
 
        if (!torture_open_connection(&cli, 0)) {
                return False;
@@ -1395,24 +1609,27 @@ static bool run_locktest2(int dummy)
 
        printf("starting locktest2\n");
 
-       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        cli_setpid(cli, 1);
 
-       if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
-               printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
+       status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum2))) {
-               printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
+       status = cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
        cli_setpid(cli, 2);
 
-       if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum3))) {
-               printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
+       status = cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum3);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open3 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
@@ -1483,18 +1700,21 @@ static bool run_locktest2(int dummy)
 
        cli_setpid(cli, 1);
 
-       if (!NT_STATUS_IS_OK(cli_close(cli, fnum1))) {
-               printf("close1 failed (%s)\n", cli_errstr(cli));
+       status = cli_close(cli, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close1 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli, fnum2))) {
-               printf("close2 failed (%s)\n", cli_errstr(cli));
+       status = cli_close(cli, fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close2 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli, fnum3))) {
-               printf("close3 failed (%s)\n", cli_errstr(cli));
+       status = cli_close(cli, fnum3);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close3 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
@@ -1521,6 +1741,7 @@ static bool run_locktest3(int dummy)
        int i;
        uint32 offset;
        bool correct = True;
+       NTSTATUS status;
 
 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
 
@@ -1532,14 +1753,18 @@ static bool run_locktest3(int dummy)
 
        printf("starting locktest3\n");
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
-               printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
+                        &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
-       if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2))) {
-               printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+
+       status = cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
@@ -1587,33 +1812,38 @@ static bool run_locktest3(int dummy)
        for (offset=i=0;i<torture_numops;i++) {
                NEXT_OFFSET;
 
-               if (!NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, offset-1, 1))) {
+               status = cli_unlock(cli1, fnum1, offset-1, 1);
+               if (!NT_STATUS_IS_OK(status)) {
                        printf("unlock1 %d failed (%s)\n", 
                               i,
-                              cli_errstr(cli1));
+                              nt_errstr(status));
                        return False;
                }
 
-               if (!NT_STATUS_IS_OK(cli_unlock(cli2, fnum2, offset-2, 1))) {
+               status = cli_unlock(cli2, fnum2, offset-2, 1);
+               if (!NT_STATUS_IS_OK(status)) {
                        printf("unlock2 %d failed (%s)\n", 
                               i,
-                              cli_errstr(cli1));
+                              nt_errstr(status));
                        return False;
                }
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("close1 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close1 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
-               printf("close2 failed (%s)\n", cli_errstr(cli2));
+       status = cli_close(cli2, fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close2 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
-               printf("unlink failed (%s)\n", cli_errstr(cli1));
+       status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("unlink failed (%s)\n", nt_errstr(status));
                return False;
        }
 
@@ -1645,6 +1875,7 @@ static bool run_locktest4(int dummy)
        bool ret;
        char buf[1000];
        bool correct = True;
+       NTSTATUS status;
 
        if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
                return False;
@@ -1655,15 +1886,17 @@ static bool run_locktest4(int dummy)
 
        printf("starting locktest4\n");
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
        cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
 
        memset(buf, 0, sizeof(buf));
 
-       if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
-               printf("Failed to create file\n");
+       status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
+                             NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Failed to create file: %s\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
@@ -1735,8 +1968,12 @@ static bool run_locktest4(int dummy)
        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) &&
-             (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
+       ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK);
+       if (ret) {
+               status = cli_writeall(cli2, fnum2, 0, (uint8_t *)buf, 130, 4,
+                                     NULL);
+               ret = NT_STATUS_IS_OK(status);
+       }
        EXPECTED(ret, False);
        printf("this server %s strict read locking\n", ret?"doesn't do":"does");
 
@@ -1753,21 +1990,24 @@ static bool run_locktest4(int dummy)
              cli_lock(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) &&
-             !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 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) &&
              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 160, 4)) &&
-             (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&          
+             NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
+                                          160, 4, NULL)) &&
              (cli_read(cli2, fnum2, buf, 160, 4) == 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) &&
              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 170, 4)) &&
-             (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&          
+             NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
+                                          170, 4, NULL)) &&
              (cli_read(cli2, fnum2, buf, 170, 4) == 4);                
        EXPECTED(ret, True);
        printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
@@ -1775,7 +2015,8 @@ static bool run_locktest4(int dummy)
        ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
              cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 190, 4)) &&
-             !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&         
+             !NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
+                                           190, 4, NULL)) &&
              (cli_read(cli2, fnum2, buf, 190, 4) == 4);                
        EXPECTED(ret, True);
        printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
@@ -1797,7 +2038,7 @@ static bool run_locktest4(int dummy)
  fail:
        cli_close(cli1, fnum1);
        cli_close(cli2, fnum2);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        torture_close_connection(cli1);
        torture_close_connection(cli2);
 
@@ -1816,6 +2057,7 @@ static bool run_locktest5(int dummy)
        bool ret;
        char buf[1000];
        bool correct = True;
+       NTSTATUS status;
 
        if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
                return False;
@@ -1826,7 +2068,7 @@ static bool run_locktest5(int dummy)
 
        printf("starting locktest5\n");
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
        cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
@@ -1834,8 +2076,10 @@ static bool run_locktest5(int dummy)
 
        memset(buf, 0, sizeof(buf));
 
-       if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
-               printf("Failed to create file\n");
+       status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
+                             NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Failed to create file: %s\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
@@ -1916,7 +2160,7 @@ static bool run_locktest5(int dummy)
  fail:
        cli_close(cli1, fnum1);
        cli_close(cli2, fnum2);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        if (!torture_close_connection(cli1)) {
                correct = False;
        }
@@ -1951,7 +2195,7 @@ static bool run_locktest6(int dummy)
        for (i=0;i<1;i++) {
                printf("Testing %s\n", fname[i]);
 
-               cli_unlink(cli, fname[i], aSYSTEM | aHIDDEN);
+               cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
                cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
                status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
@@ -1963,7 +2207,7 @@ static bool run_locktest6(int dummy)
                cli_close(cli, fnum);
                printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
 
-               cli_unlink(cli, fname[i], aSYSTEM | aHIDDEN);
+               cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        }
 
        torture_close_connection(cli);
@@ -1979,6 +2223,7 @@ static bool run_locktest7(int dummy)
        uint16_t fnum1;
        char buf[200];
        bool correct = False;
+       NTSTATUS status;
 
        if (!torture_open_connection(&cli1, 0)) {
                return False;
@@ -1988,14 +2233,16 @@ static bool run_locktest7(int dummy)
 
        printf("starting locktest7\n");
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
 
        memset(buf, 0, sizeof(buf));
 
-       if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
-               printf("Failed to create file\n");
+       status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf),
+                             NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Failed to create file: %s\n", nt_errstr(status));
                goto fail;
        }
 
@@ -2015,9 +2262,11 @@ static bool run_locktest7(int dummy)
                printf("pid1 successfully read the range 130:4\n");
        }
 
-       if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
-               printf("pid1 unable to write to 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_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("pid1 unable to write to 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;
                }
@@ -2034,9 +2283,11 @@ static bool run_locktest7(int dummy)
                printf("pid2 successfully read the range 130:4\n");
        }
 
-       if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
-               printf("pid2 unable to write to 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_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("pid2 unable to write to 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;
                }
@@ -2062,8 +2313,10 @@ static bool run_locktest7(int dummy)
                printf("pid1 successfully read the range 130:4\n");
        }
 
-       if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
-               printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
+       status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("pid1 unable to write to the range 130:4, error was "
+                      "%s\n", nt_errstr(status));
                goto fail;
        } else {
                printf("pid1 successfully wrote to the range 130:4\n");
@@ -2082,9 +2335,11 @@ static bool run_locktest7(int dummy)
                goto fail;
        }
 
-       if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
-               printf("pid2 unable to write to 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_writeall(cli1, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("pid2 unable to write to 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;
                }
@@ -2098,7 +2353,7 @@ static bool run_locktest7(int dummy)
 
 fail:
        cli_close(cli1, fnum1);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        torture_close_connection(cli1);
 
        printf("finished locktest7\n");
@@ -2130,12 +2385,12 @@ static bool run_locktest8(int dummy)
 
        printf("starting locktest8\n");
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_WRITE,
                          &fnum1);
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "cli_open returned %s\n", cli_errstr(cli1));
+               d_fprintf(stderr, "cli_open returned %s\n", nt_errstr(status));
                return false;
        }
 
@@ -2144,7 +2399,7 @@ static bool run_locktest8(int dummy)
        status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum2);
        if (!NT_STATUS_IS_OK(status)) {
                d_fprintf(stderr, "cli_open second time returned %s\n",
-                         cli_errstr(cli1));
+                         nt_errstr(status));
                goto fail;
        }
 
@@ -2156,14 +2411,14 @@ static bool run_locktest8(int dummy)
 
        status = cli_close(cli1, fnum1);
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "cli_close(fnum1) %s\n", cli_errstr(cli1));
+               d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status));
                goto fail;
        }
 
        status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
        if (!NT_STATUS_IS_OK(status)) {
                d_fprintf(stderr, "cli_open third time returned %s\n",
-                          cli_errstr(cli1));
+                          nt_errstr(status));
                 goto fail;
         }
 
@@ -2172,7 +2427,7 @@ static bool run_locktest8(int dummy)
 fail:
        cli_close(cli1, fnum1);
        cli_close(cli1, fnum2);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        torture_close_connection(cli1);
 
        printf("finished locktest8\n");
@@ -2277,6 +2532,7 @@ static bool run_locktest9(int dummy)
        pid_t child_pid;
        char c = '\0';
        int ret;
+       struct timeval start;
        double seconds;
        NTSTATUS status;
 
@@ -2324,7 +2580,7 @@ static bool run_locktest9(int dummy)
        status = cli_open(cli1, fname, O_RDWR, DENY_NONE,
                          &fnum);
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "cli_open returned %s\n", cli_errstr(cli1));
+               d_fprintf(stderr, "cli_open returned %s\n", nt_errstr(status));
                return false;
        }
 
@@ -2349,7 +2605,7 @@ static bool run_locktest9(int dummy)
        CatchSignal(SIGALRM, alarm_handler_parent);
        alarm(20);
 
-       start_timer();
+       start = timeval_current();
 
        if (!cli_lock(cli1, fnum, 0, 4, -1, WRITE_LOCK)) {
                d_fprintf(stderr, "Unable to apply write lock on range 0:4, error was "
@@ -2358,14 +2614,14 @@ static bool run_locktest9(int dummy)
        }
        alarm(0);
 
-       seconds = end_timer();
+       seconds = timeval_elapsed(&start);
 
        printf("Parent got the lock after %.2f seconds.\n",
                seconds);
 
        status = cli_close(cli1, fnum);
        if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "cli_close(fnum1) %s\n", cli_errstr(cli1));
+               d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status));
                goto fail;
        }
 
@@ -2391,6 +2647,7 @@ static bool run_fdpasstest(int dummy)
        const char *fname = "\\fdpass.tst";
        uint16_t fnum1;
        char buf[1024];
+       NTSTATUS status;
 
        if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
                return False;
@@ -2400,15 +2657,19 @@ static bool run_fdpasstest(int dummy)
 
        printf("starting fdpasstest\n");
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
-               printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
+                         &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
-               printf("write failed (%s)\n", cli_errstr(cli1));
+       status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"hello world\n", 0,
+                             13, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("write failed (%s)\n", nt_errstr(status));
                return False;
        }
 
@@ -2423,7 +2684,7 @@ static bool run_fdpasstest(int dummy)
        }
 
        cli_close(cli1, fnum1);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        torture_close_connection(cli1);
        torture_close_connection(cli2);
@@ -2445,6 +2706,7 @@ static bool run_fdsesstest(int dummy)
        uint16_t fnum2;
        char buf[1024];
        bool ret = True;
+       NTSTATUS status;
 
        if (!torture_open_connection(&cli, 0))
                return False;
@@ -2461,16 +2723,19 @@ static bool run_fdsesstest(int dummy)
 
        printf("starting fdsesstest\n");
 
-       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
-       cli_unlink(cli, fname1, aSYSTEM | aHIDDEN);
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
-               printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
+       status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (cli_write(cli, fnum1, 0, "hello world\n", 0, 13) != 13) {
-               printf("write failed (%s)\n", cli_errstr(cli));
+       status = cli_writeall(cli, fnum1, 0, (const uint8_t *)"hello world\n", 0, 13,
+                             NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("write failed (%s)\n", nt_errstr(status));
                return False;
        }
 
@@ -2486,7 +2751,7 @@ static bool run_fdsesstest(int dummy)
        if (NT_STATUS_IS_OK(cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {
                printf("create with different vuid, same cnum succeeded.\n");
                cli_close(cli, fnum2);
-               cli_unlink(cli, fname1, aSYSTEM | aHIDDEN);
+               cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        } else {
                printf("create with different vuid, same cnum failed.\n");
                printf("This will cause problems with service clients.\n");
@@ -2506,7 +2771,7 @@ static bool run_fdsesstest(int dummy)
 
        cli->cnum = saved_cnum;
        cli_close(cli, fnum1);
-       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        torture_close_connection(cli);
 
@@ -2525,6 +2790,7 @@ static bool run_unlinktest(int dummy)
        const char *fname = "\\unlink.tst";
        uint16_t fnum;
        bool correct = True;
+       NTSTATUS status;
 
        if (!torture_open_connection(&cli, 0)) {
                return False;
@@ -2534,16 +2800,17 @@ static bool run_unlinktest(int dummy)
 
        printf("starting unlink test\n");
 
-       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        cli_setpid(cli, 1);
 
-       if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
-               printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
+       status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
+       if (NT_STATUS_IS_OK(cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
                printf("error: server allowed unlink on an open file\n");
                correct = False;
        } else {
@@ -2552,7 +2819,7 @@ static bool run_unlinktest(int dummy)
        }
 
        cli_close(cli, fnum);
-       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        if (!torture_close_connection(cli)) {
                correct = False;
@@ -2570,12 +2837,12 @@ test how many open files this server supports on the one socket
 static bool run_maxfidtest(int dummy)
 {
        struct cli_state *cli;
-       const char *ftemplate = "\\maxfid.%d.%d";
        fstring fname;
        uint16_t fnums[0x11000];
        int i;
        int retries=4;
        bool correct = True;
+       NTSTATUS status;
 
        cli = current_cli;
 
@@ -2587,11 +2854,12 @@ static bool run_maxfidtest(int dummy)
        cli_sockopt(cli, sockops);
 
        for (i=0; i<0x11000; i++) {
-               slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
-               if (!NT_STATUS_IS_OK(cli_open(cli, fname, 
-                                       O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnums[i]))) {
+               slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid());
+               status = cli_open(cli, fname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE,
+                                 &fnums[i]);
+               if (!NT_STATUS_IS_OK(status)) {
                        printf("open of %s failed (%s)\n", 
-                              fname, cli_errstr(cli));
+                              fname, nt_errstr(status));
                        printf("maximum fnum is %d\n", i);
                        break;
                }
@@ -2602,11 +2870,13 @@ static bool run_maxfidtest(int dummy)
 
        printf("cleaning up\n");
        for (;i>=0;i--) {
-               slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
+               slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid());
                cli_close(cli, fnums[i]);
-               if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
+
+               status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+               if (!NT_STATUS_IS_OK(status)) {
                        printf("unlink of %s failed (%s)\n", 
-                              fname, cli_errstr(cli));
+                              fname, nt_errstr(status));
                        correct = False;
                }
                printf("%6d\r", i);
@@ -2632,21 +2902,41 @@ static void rand_buf(char *buf, int len)
 /* send smb negprot commands, not reading the response */
 static bool run_negprot_nowait(int dummy)
 {
+       struct tevent_context *ev;
        int i;
-       static struct cli_state *cli;
+       struct cli_state *cli;
        bool correct = True;
 
        printf("starting negprot nowait test\n");
 
+       ev = tevent_context_init(talloc_tos());
+       if (ev == NULL) {
+               return false;
+       }
+
        if (!(cli = open_nbt_connection())) {
+               TALLOC_FREE(ev);
                return False;
        }
 
        for (i=0;i<50000;i++) {
-               cli_negprot_sendsync(cli);
+               struct tevent_req *req;
+
+               req = cli_negprot_send(ev, ev, cli);
+               if (req == NULL) {
+                       TALLOC_FREE(ev);
+                       return false;
+               }
+               if (!tevent_req_poll(req, ev)) {
+                       d_fprintf(stderr, "tevent_req_poll failed: %s\n",
+                                 strerror(errno));
+                       TALLOC_FREE(ev);
+                       return false;
+               }
+               TALLOC_FREE(req);
        }
 
-       if (!torture_close_connection(cli)) {
+       if (torture_close_connection(cli)) {
                correct = False;
        }
 
@@ -2655,6 +2945,21 @@ static bool run_negprot_nowait(int dummy)
        return correct;
 }
 
+/* send smb negprot commands, not reading the response */
+static bool run_bad_nbt_session(int dummy)
+{
+       static struct cli_state *cli;
+
+       printf("starting bad nbt session test\n");
+
+       if (!(cli = open_bad_nbt_connection())) {
+               return False;
+       }
+
+       cli_shutdown(cli);
+       printf("finished bad nbt session test\n");
+       return true;
+}
 
 /* send random IPC commands */
 static bool run_randomipc(int dummy)
@@ -2758,6 +3063,7 @@ static bool run_attrtest(int dummy)
        time_t t, t2;
        const char *fname = "\\attrib123456789.tst";
        bool correct = True;
+       NTSTATUS status;
 
        printf("starting attrib test\n");
 
@@ -2765,12 +3071,14 @@ static bool run_attrtest(int dummy)
                return False;
        }
 
-       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        cli_open(cli, fname, 
                        O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
        cli_close(cli, fnum);
-       if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) {
-               printf("getatr failed (%s)\n", cli_errstr(cli));
+
+       status = cli_getatr(cli, fname, NULL, NULL, &t);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("getatr failed (%s)\n", nt_errstr(status));
                correct = False;
        }
 
@@ -2783,13 +3091,15 @@ static bool run_attrtest(int dummy)
 
        t2 = t-60*60*24; /* 1 day ago */
 
-       if (!NT_STATUS_IS_OK(cli_setatr(cli, fname, 0, t2))) {
-               printf("setatr failed (%s)\n", cli_errstr(cli));
+       status = cli_setatr(cli, fname, 0, t2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("setatr failed (%s)\n", nt_errstr(status));
                correct = True;
        }
 
-       if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) {
-               printf("getatr failed (%s)\n", cli_errstr(cli));
+       status = cli_getatr(cli, fname, NULL, NULL, &t);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("getatr failed (%s)\n", nt_errstr(status));
                correct = True;
        }
 
@@ -2800,7 +3110,7 @@ static bool run_attrtest(int dummy)
                correct = True;
        }
 
-       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        if (!torture_close_connection(cli)) {
                correct = False;
@@ -2843,17 +3153,18 @@ static bool run_trans2test(int dummy)
                correct = false;
        }
 
-       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
-       cli_open(cli, fname, 
-                       O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
-       if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time_ts, &a_time_ts, &w_time_ts,
-                          &m_time_ts, NULL)) {
-               printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
+       status = cli_qfileinfo_basic(cli, fnum, NULL, &size, &c_time_ts,
+                                    &a_time_ts, &w_time_ts, &m_time_ts, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ERROR: qfileinfo failed (%s)\n", nt_errstr(status));
                correct = False;
        }
 
-       if (!cli_qfilename(cli, fnum, pname, sizeof(pname))) {
-               printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
+       status = cli_qfilename(cli, fnum, pname, sizeof(pname));
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ERROR: qfilename failed (%s)\n", nt_errstr(status));
                correct = False;
        }
 
@@ -2867,16 +3178,19 @@ static bool run_trans2test(int dummy)
 
        sleep(2);
 
-       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
-       if (!NT_STATUS_IS_OK(cli_open(cli, fname, 
-                       O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum))) {
-               printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       status = cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE,
+                         &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
        cli_close(cli, fnum);
 
-       if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
-               printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
+       status = cli_qpathinfo1(cli, fname, &c_time, &a_time, &m_time, &size,
+                               NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ERROR: qpathinfo failed (%s)\n", nt_errstr(status));
                correct = False;
        } else {
                if (c_time != m_time) {
@@ -2897,13 +3211,14 @@ static bool run_trans2test(int dummy)
        }
 
 
-       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        cli_open(cli, fname, 
                        O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
        cli_close(cli, fnum);
-       if (!cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts, 
-                           &m_time_ts, &size, NULL, NULL)) {
-               printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
+       status = cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
+                               &m_time_ts, &size, NULL, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
                correct = False;
        } else {
                if (w_time_ts.tv_sec < 60*60*24*2) {
@@ -2913,29 +3228,32 @@ static bool run_trans2test(int dummy)
                }
        }
 
-       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
 
        /* check if the server updates the directory modification time
            when creating a new file */
-       if (!NT_STATUS_IS_OK(cli_mkdir(cli, dname))) {
-               printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
+       status = cli_mkdir(cli, dname);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ERROR: mkdir failed (%s)\n", nt_errstr(status));
                correct = False;
        }
        sleep(3);
-       if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts, 
-                           &m_time_ts, &size, NULL, NULL)) {
-               printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
+       status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
+                               &w_time_ts, &m_time_ts, &size, NULL, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
                correct = False;
        }
 
        cli_open(cli, fname2, 
                        O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
-       cli_write(cli, fnum,  0, (char *)&fnum, 0, sizeof(fnum));
+       cli_writeall(cli, fnum,  0, (uint8_t *)&fnum, 0, sizeof(fnum), NULL);
        cli_close(cli, fnum);
-       if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts, 
-                           &m_time2_ts, &size, NULL, NULL)) {
-               printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
+       status = cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts,
+                               &w_time_ts, &m_time2_ts, &size, NULL, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
                correct = False;
        } else {
                if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
@@ -2944,7 +3262,7 @@ static bool run_trans2test(int dummy)
                        correct = False;
                }
        }
-       cli_unlink(cli, fname2, aSYSTEM | aHIDDEN);
+       cli_unlink(cli, fname2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        cli_rmdir(cli, dname);
 
        if (!torture_close_connection(cli)) {
@@ -2960,22 +3278,24 @@ static bool run_trans2test(int dummy)
   This checks new W2K calls.
 */
 
-static bool new_trans(struct cli_state *pcli, int fnum, int level)
+static NTSTATUS new_trans(struct cli_state *pcli, int fnum, int level)
 {
-       char *buf = NULL;
+       uint8_t *buf = NULL;
        uint32 len;
-       bool correct = True;
+       NTSTATUS status;
 
-       if (!cli_qfileinfo_test(pcli, fnum, level, &buf, &len)) {
-               printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
-               correct = False;
+       status = cli_qfileinfo(talloc_tos(), pcli, fnum, level, 0,
+                              pcli->max_xmit, &buf, &len);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ERROR: qfileinfo (%d) failed (%s)\n", level,
+                      nt_errstr(status));
        } else {
                printf("qfileinfo: level %d, len = %u\n", level, len);
                dump_data(0, (uint8 *)buf, len);
                printf("\n");
        }
-       SAFE_FREE(buf);
-       return correct;
+       TALLOC_FREE(buf);
+       return status;
 }
 
 static bool run_w2ktest(int dummy)
@@ -3020,6 +3340,7 @@ static bool run_oplock1(int dummy)
        const char *fname = "\\lockt1.lck";
        uint16_t fnum1;
        bool correct = True;
+       NTSTATUS status;
 
        printf("starting oplock test 1\n");
 
@@ -3027,29 +3348,33 @@ static bool run_oplock1(int dummy)
                return False;
        }
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        cli_sockopt(cli1, sockops);
 
        cli1->use_oplocks = True;
 
-       if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
-               printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
+                         &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
        cli1->use_oplocks = False;
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("close2 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close2 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
-               printf("unlink failed (%s)\n", cli_errstr(cli1));
+       status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("unlink failed (%s)\n", nt_errstr(status));
                return False;
        }
 
@@ -3071,6 +3396,7 @@ static bool run_oplock2(int dummy)
        char buf[4];
        bool correct = True;
        volatile bool *shared_correct;
+       NTSTATUS status;
 
        shared_correct = (volatile bool *)shm_setup(sizeof(bool));
        *shared_correct = True;
@@ -3098,13 +3424,15 @@ static bool run_oplock2(int dummy)
        cli2->use_oplocks = True;
        cli2->use_level_II_oplocks = True;
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        cli_sockopt(cli1, sockops);
        cli_sockopt(cli2, sockops);
 
-       if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
-               printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
+                         &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
@@ -3114,16 +3442,18 @@ static bool run_oplock2(int dummy)
 
        if (fork() == 0) {
                /* Child code */
-               if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2))) {
-                       printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
+               status = cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("second open of %s failed (%s)\n", fname, nt_errstr(status));
                        *shared_correct = False;
                        exit(0);
                }
 
                sleep(2);
 
-               if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
-                       printf("close2 failed (%s)\n", cli_errstr(cli1));
+               status = cli_close(cli2, fnum2);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("close2 failed (%s)\n", nt_errstr(status));
                        *shared_correct = False;
                }
 
@@ -3163,22 +3493,17 @@ static bool run_oplock2(int dummy)
 
        cli_read(cli1, fnum1, buf, 0, 4);
 
-#if 0
-       if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
-               printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
-               correct = False;
-       }
-#endif
-
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("close1 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close1 failed (%s)\n", nt_errstr(status));
                correct = False;
        }
 
        sleep(4);
 
-       if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
-               printf("unlink failed (%s)\n", cli_errstr(cli1));
+       status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("unlink failed (%s)\n", nt_errstr(status));
                correct = False;
        }
 
@@ -3195,64 +3520,230 @@ 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);
-}
+struct oplock4_state {
+       struct tevent_context *ev;
+       struct cli_state *cli;
+       bool *got_break;
+       uint16_t *fnum2;
+};
+
+static void oplock4_got_break(struct tevent_req *req);
+static void oplock4_got_open(struct tevent_req *req);
 
-static bool run_oplock3(int dummy)
+static bool run_oplock4(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;
+       struct tevent_context *ev;
+       struct cli_state *cli1, *cli2;
+       struct tevent_req *oplock_req, *open_req;
+       const char *fname = "\\lockt4.lck";
+       const char *fname_ln = "\\lockt4_ln.lck";
+       uint16_t fnum1, fnum2;
+       int saved_use_oplocks = use_oplocks;
+       NTSTATUS status;
+       bool correct = true;
 
-       shared_correct = (volatile bool *)shm_setup(sizeof(bool));
-       *shared_correct = True;
+       bool got_break;
 
-       printf("starting oplock test 3\n");
+       struct oplock4_state *state;
 
-       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_write(cli, fnum, 0, buf, 0, 4);
-               exit(0);
+       printf("starting oplock test 4\n");
+
+       if (!torture_open_connection(&cli1, 0)) {
+               use_level_II_oplocks = false;
+               use_oplocks = saved_use_oplocks;
+               return false;
        }
 
-       /* parent code */
-       use_oplocks = True;
-       use_level_II_oplocks = True;
-       if (!torture_open_connection(&cli, 1)) { /* other is forked */
-               return False;
+       if (!torture_open_connection(&cli2, 1)) {
+               use_level_II_oplocks = false;
+               use_oplocks = saved_use_oplocks;
+               return false;
        }
-       cli_oplock_handler(cli, oplock3_handler);
-       cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum);
-       cli_write(cli, fnum, 0, buf, 0, 4);
-       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);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+       cli_sockopt(cli1, sockops);
+       cli_sockopt(cli2, sockops);
+
+       /* Create the file. */
+       status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
+                         &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
+               return false;
+       }
+
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close1 failed (%s)\n", nt_errstr(status));
+               return false;
+       }
+
+       /* Now create a hardlink. */
+       status = cli_nt_hardlink(cli1, fname, fname_ln);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("nt hardlink failed (%s)\n", nt_errstr(status));
+               return false;
+       }
+
+       /* Prove that opening hardlinks cause deny modes to conflict. */
+       status = cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
+               return false;
+       }
+
+       status = cli_open(cli1, fname_ln, O_RDWR, DENY_NONE, &fnum2);
+       if (NT_STATUS_IS_OK(status)) {
+               printf("open of %s succeeded - should fail with sharing violation.\n",
+                       fname_ln);
+               return false;
+       }
+
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
+               printf("open of %s should fail with sharing violation. Got %s\n",
+                       fname_ln, nt_errstr(status));
+               return false;
+       }
+
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close1 failed (%s)\n", nt_errstr(status));
+               return false;
+       }
+
+       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)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
+               return false;
+       }
+
+       ev = tevent_context_init(talloc_tos());
+       if (ev == NULL) {
+               printf("tevent_req_create failed\n");
+               return false;
+       }
 
-/* What are we looking for here?  What's sucess and what's FAILURE? */
+       state = talloc(ev, struct oplock4_state);
+       if (state == NULL) {
+               printf("talloc failed\n");
+               return false;
+       }
+       state->ev = ev;
+       state->cli = cli1;
+       state->got_break = &got_break;
+       state->fnum2 = &fnum2;
+
+       oplock_req = cli_smb_oplock_break_waiter_send(
+               talloc_tos(), ev, cli1);
+       if (oplock_req == NULL) {
+               printf("cli_smb_oplock_break_waiter_send failed\n");
+               return false;
+       }
+       tevent_req_set_callback(oplock_req, oplock4_got_break, state);
+
+       open_req = cli_open_send(
+               talloc_tos(), ev, cli2, fname_ln, O_RDWR, DENY_NONE);
+       if (oplock_req == NULL) {
+               printf("cli_open_send failed\n");
+               return false;
+       }
+       tevent_req_set_callback(open_req, oplock4_got_open, state);
+
+       got_break = false;
+       fnum2 = 0xffff;
+
+       while (!got_break || fnum2 == 0xffff) {
+               int ret;
+               ret = tevent_loop_once(ev);
+               if (ret == -1) {
+                       printf("tevent_loop_once failed: %s\n",
+                              strerror(errno));
+                       return false;
+               }
+       }
+
+       status = cli_close(cli2, fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close2 failed (%s)\n", nt_errstr(status));
+               correct = false;
+       }
+
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close1 failed (%s)\n", nt_errstr(status));
+               correct = false;
+       }
+
+       status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("unlink failed (%s)\n", nt_errstr(status));
+               correct = false;
+       }
+
+       status = cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("unlink failed (%s)\n", nt_errstr(status));
+               correct = false;
+       }
+
+       if (!torture_close_connection(cli1)) {
+               correct = false;
+       }
+
+       if (!got_break) {
+               correct = false;
+       }
+
+       printf("finished oplock test 4\n");
+
+       return correct;
 }
 
+static void oplock4_got_break(struct tevent_req *req)
+{
+       struct oplock4_state *state = tevent_req_callback_data(
+               req, struct oplock4_state);
+       uint16_t fnum;
+       uint8_t level;
+       NTSTATUS status;
+
+       status = cli_smb_oplock_break_waiter_recv(req, &fnum, &level);
+       TALLOC_FREE(req);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_smb_oplock_break_waiter_recv returned %s\n",
+                      nt_errstr(status));
+               return;
+       }
+       *state->got_break = true;
+
+       req = cli_oplock_ack_send(state, state->ev, state->cli, fnum,
+                                 NO_OPLOCK);
+       if (req == NULL) {
+               printf("cli_oplock_ack_send failed\n");
+               return;
+       }
+}
 
+static void oplock4_got_open(struct tevent_req *req)
+{
+       struct oplock4_state *state = tevent_req_callback_data(
+               req, struct oplock4_state);
+       NTSTATUS status;
+
+       status = cli_open_recv(req, state->fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_open_recv returned %s\n", nt_errstr(status));
+               *state->fnum2 = 0xffff;
+       }
+}
 
 /*
   Test delete on close semantics.
@@ -3265,6 +3756,7 @@ static bool run_deletetest(int dummy)
        uint16_t fnum1 = (uint16_t)-1;
        uint16_t fnum2 = (uint16_t)-1;
        bool correct = True;
+       NTSTATUS status;
 
        printf("starting delete test\n");
 
@@ -3277,29 +3769,20 @@ static bool run_deletetest(int dummy)
        /* Test 1 - this should delete the file on close. */
 
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                                  0, FILE_OVERWRITE_IF, 
-                                  FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
-               printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
+                             FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
+                             FILE_DELETE_ON_CLOSE, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[1] open of %s failed (%s)\n", fname, nt_errstr(status));
                correct = False;
                goto fail;
        }
 
-#if 0 /* JRATEST */
-        {
-                uint32 *accinfo = NULL;
-                uint32 len;
-                cli_qfileinfo_test(cli1, fnum1, SMB_FILE_ACCESS_INFORMATION, (char **)&accinfo, &len);
-               if (accinfo)
-                       printf("access mode = 0x%lx\n", *accinfo);
-                SAFE_FREE(accinfo);
-        }
-#endif
-
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("[1] close failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[1] close failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
@@ -3315,46 +3798,53 @@ static bool run_deletetest(int dummy)
        /* Test 2 - this should delete the file on close. */
 
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
-                                  FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, 
-                                  FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
+                             FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
+                             FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[2] open of %s failed (%s)\n", fname, nt_errstr(status));
                correct = False;
                goto fail;
        }
 
-       if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
-               printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
+       status = cli_nt_delete_on_close(cli1, fnum1, true);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[2] setting delete_on_close failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("[2] close failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[2] close failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
 
        if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
                printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
-               if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-                       printf("[2] close failed (%s)\n", cli_errstr(cli1));
+               status = cli_close(cli1, fnum1);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("[2] close failed (%s)\n", nt_errstr(status));
                        correct = False;
                        goto fail;
                }
-               cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+               cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        } else
                printf("second delete on close test succeeded.\n");
 
        /* Test 3 - ... */
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
+                             FILE_ATTRIBUTE_NORMAL,
+                             FILE_SHARE_READ|FILE_SHARE_WRITE,
+                             FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[3] open - 1 of %s failed (%s)\n", fname, nt_errstr(status));
                correct = False;
                goto fail;
        }
@@ -3370,28 +3860,33 @@ static bool run_deletetest(int dummy)
        }
 
        /* This should succeed. */
-
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                       FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2))) {
-               printf("[3] open  - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
+                            FILE_ATTRIBUTE_NORMAL,
+                            FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+                            FILE_OPEN, 0, 0, &fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[3] open  - 2 of %s failed (%s)\n", fname, nt_errstr(status));
                correct = False;
                goto fail;
        }
 
-       if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
-               printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
+       status = cli_nt_delete_on_close(cli1, fnum1, true);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[3] setting delete_on_close failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[3] close 1 failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
-               printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[3] close 2 failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
@@ -3400,10 +3895,11 @@ static bool run_deletetest(int dummy)
 
        if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
                printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
-               if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-                       printf("[3] close failed (%s)\n", cli_errstr(cli1));
+               status = cli_close(cli1, fnum1);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("[3] close failed (%s)\n", nt_errstr(status));
                }
-               cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+               cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
                correct = False;
                goto fail;
        } else
@@ -3411,31 +3907,40 @@ static bool run_deletetest(int dummy)
 
        /* Test 4 ... */
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
-                       FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0,
+                             FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
+                             FILE_ATTRIBUTE_NORMAL,
+                             FILE_SHARE_READ|FILE_SHARE_WRITE,
+                             FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[4] open of %s failed (%s)\n", fname, nt_errstr(status));
                correct = False;
                goto fail;
        }
 
        /* This should succeed. */
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
-                       FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2))) {
-               printf("[4] open  - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
+                            FILE_ATTRIBUTE_NORMAL,
+                            FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+                            FILE_OPEN, 0, 0, &fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[4] open  - 2 of %s failed (%s)\n", fname, nt_errstr(status));
                correct = False;
                goto fail;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
-               printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[4] close - 1 failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
 
-       if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
-               printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
+       status = cli_nt_delete_on_close(cli1, fnum1, true);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[4] setting delete_on_close failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
@@ -3450,18 +3955,20 @@ static bool run_deletetest(int dummy)
        } else
                printf("fourth delete on close test succeeded.\n");
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[4] close - 2 failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
 
        /* Test 5 ... */
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1))) {
-               printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[5] open of %s failed (%s)\n", fname, nt_errstr(status));
                correct = False;
                goto fail;
        }
@@ -3474,8 +3981,9 @@ static bool run_deletetest(int dummy)
                goto fail;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[5] close - 2 failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
@@ -3484,12 +3992,15 @@ static bool run_deletetest(int dummy)
 
        /* Test 6 ... */
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
-                                  FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
-                                  FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
+                            FILE_ATTRIBUTE_NORMAL,
+                            FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+                            FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[6] open of %s failed (%s)\n", fname,
+                      nt_errstr(status));
                correct = False;
                goto fail;
        }
@@ -3502,8 +4013,9 @@ static bool run_deletetest(int dummy)
                goto fail;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[6] close - 2 failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
@@ -3512,11 +4024,14 @@ static bool run_deletetest(int dummy)
 
        /* Test 7 ... */
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
-                                  FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0,
+                             FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
+                             FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
+                             0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[7] open of %s failed (%s)\n", fname, nt_errstr(status));
                correct = False;
                goto fail;
        }
@@ -3533,22 +4048,24 @@ static bool run_deletetest(int dummy)
                goto fail;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[7] close - 2 failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
 
        /* This next open should succeed - we reset the flag. */
-
-       if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
-               printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[5] open of %s failed (%s)\n", fname, nt_errstr(status));
                correct = False;
                goto fail;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[7] close - 2 failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
@@ -3557,7 +4074,7 @@ static bool run_deletetest(int dummy)
 
        /* Test 7 ... */
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        if (!torture_open_connection(&cli2, 1)) {
                printf("[8] failed to open second connection.\n");
@@ -3567,18 +4084,24 @@ static bool run_deletetest(int dummy)
 
        cli_sockopt(cli1, sockops);
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
-                                  FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
-                                  FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("[8] open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0,
+                            FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
+                            FILE_ATTRIBUTE_NORMAL,
+                            FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+                            FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[8] open 1 of %s failed (%s)\n", fname, nt_errstr(status));
                correct = False;
                goto fail;
        }
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
-                                  FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
-                                  FILE_OPEN, 0, 0, &fnum2))) {
-               printf("[8] open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+       status = cli_ntcreate(cli2, fname, 0,
+                            FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
+                            FILE_ATTRIBUTE_NORMAL,
+                            FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+                            FILE_OPEN, 0, 0, &fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[8] open 2 of %s failed (%s)\n", fname, nt_errstr(status));
                correct = False;
                goto fail;
        }
@@ -3589,20 +4112,23 @@ static bool run_deletetest(int dummy)
                goto fail;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[8] close - 1 failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
-               printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
+       status = cli_close(cli2, fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[8] close - 2 failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
 
        /* This should fail.. */
-       if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
+       status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
+       if (NT_STATUS_IS_OK(status)) {
                printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
                goto fail;
                correct = False;
@@ -3619,16 +4145,21 @@ static bool run_deletetest(int dummy)
 
        printf("ninth delete on close test succeeded.\n");
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
-                                  FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
-               printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0,
+                            FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
+                            FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
+                            FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE,
+                            0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[10] open of %s failed (%s)\n", fname, nt_errstr(status));
                correct = False;
                goto fail;
        }
 
        /* This should delete the file. */
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("[10] close failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[10] close failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
@@ -3642,21 +4173,24 @@ static bool run_deletetest(int dummy)
                printf("tenth delete on close test succeeded.\n");
 
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        /* What error do we get when attempting to open a read-only file with
           delete access ? */
 
        /* Create a readonly file. */
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
-                                  FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("[11] open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
+                             FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE,
+                             FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[11] open of %s failed (%s)\n", fname, nt_errstr(status));
                correct = False;
                goto fail;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("[11] close failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("[11] close failed (%s)\n", nt_errstr(status));
                correct = False;
                goto fail;
        }
@@ -3690,7 +4224,7 @@ static bool run_deletetest(int dummy)
        if (fnum1 != (uint16_t)-1) cli_close(cli1, fnum1);
        if (fnum2 != (uint16_t)-1) cli_close(cli1, fnum2);
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        if (cli1 && !torture_close_connection(cli1)) {
                correct = False;
@@ -3701,6 +4235,119 @@ static bool run_deletetest(int dummy)
        return correct;
 }
 
+static bool run_deletetest_ln(int dummy)
+{
+       struct cli_state *cli;
+       const char *fname = "\\delete1";
+       const char *fname_ln = "\\delete1_ln";
+       uint16_t fnum;
+       uint16_t fnum1;
+       NTSTATUS status;
+       bool correct = true;
+       time_t t;
+
+       printf("starting deletetest-ln\n");
+
+       if (!torture_open_connection(&cli, 0)) {
+               return false;
+       }
+
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+       cli_sockopt(cli, sockops);
+
+       /* Create the file. */
+       status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
+               return false;
+       }
+
+       status = cli_close(cli, fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close1 failed (%s)\n", nt_errstr(status));
+               return false;
+       }
+
+       /* Now create a hardlink. */
+       status = cli_nt_hardlink(cli, fname, fname_ln);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("nt hardlink failed (%s)\n", nt_errstr(status));
+               return false;
+       }
+
+       /* Open the original file. */
+       status = cli_ntcreate(cli, fname, 0, FILE_READ_DATA,
+                       FILE_ATTRIBUTE_NORMAL,
+                       FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+                       FILE_OPEN_IF, 0, 0, &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ntcreate of %s failed (%s)\n", fname, nt_errstr(status));
+               return false;
+       }
+
+       /* Unlink the hard link path. */
+       status = cli_ntcreate(cli, fname_ln, 0, DELETE_ACCESS,
+                       FILE_ATTRIBUTE_NORMAL,
+                       FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+                       FILE_OPEN_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ntcreate of %s failed (%s)\n", fname_ln, nt_errstr(status));
+               return false;
+       }
+       status = cli_nt_delete_on_close(cli, fnum1, true);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("(%s) failed to set delete_on_close %s: %s\n",
+                       __location__, fname_ln, nt_errstr(status));
+               return false;
+       }
+
+       status = cli_close(cli, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close %s failed (%s)\n",
+                       fname_ln, nt_errstr(status));
+               return false;
+       }
+
+       status = cli_close(cli, fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close %s failed (%s)\n",
+                       fname, nt_errstr(status));
+               return false;
+       }
+
+       /* Ensure the original file is still there. */
+        status = cli_getatr(cli, fname, NULL, NULL, &t);
+        if (!NT_STATUS_IS_OK(status)) {
+                printf("%s getatr on file %s failed (%s)\n",
+                       __location__,
+                       fname,
+                       nt_errstr(status));
+                correct = False;
+        }
+
+       /* Ensure the link path is gone. */
+       status = cli_getatr(cli, fname_ln, NULL, NULL, &t);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+                printf("%s, getatr for file %s returned wrong error code %s "
+                       "- should have been deleted\n",
+                       __location__,
+                       fname_ln, nt_errstr(status));
+                correct = False;
+        }
+
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+       if (!torture_close_connection(cli)) {
+               correct = false;
+       }
+
+       printf("finished deletetest-ln\n");
+
+       return correct;
+}
 
 /*
   print out server properties
@@ -3759,6 +4406,7 @@ static bool run_xcopy(int dummy)
        const char *fname = "\\test.txt";
        bool correct = True;
        uint16_t fnum1, fnum2;
+       NTSTATUS status;
 
        printf("starting xcopy test\n");
 
@@ -3766,19 +4414,19 @@ static bool run_xcopy(int dummy)
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,
-                                  FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 
-                                  0x4044, 0, &fnum1))) {
-               printf("First open failed - %s\n", cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0, FIRST_DESIRED_ACCESS,
+                             FILE_ATTRIBUTE_ARCHIVE, FILE_SHARE_NONE,
+                             FILE_OVERWRITE_IF, 0x4044, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("First open failed - %s\n", nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,
-                                  SECOND_DESIRED_ACCESS, 0,
-                                  FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 
-                                  0x200000, 0, &fnum2))) {
-               printf("second open failed - %s\n", cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0, SECOND_DESIRED_ACCESS, 0,
+                            FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+                            FILE_OPEN, 0x200000, 0, &fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("second open failed - %s\n", nt_errstr(status));
                return False;
        }
 
@@ -3799,6 +4447,7 @@ static bool run_rename(int dummy)
        const char *fname1 = "\\test1.txt";
        bool correct = True;
        uint16_t fnum1;
+       uint16_t attr;
        NTSTATUS status;
 
        printf("starting rename test\n");
@@ -3807,28 +4456,33 @@ static bool run_rename(int dummy)
                return False;
        }
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
-       cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("First open failed - %s\n", cli_errstr(cli1));
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+       status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
+                             FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
+                             FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("First open failed - %s\n", nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
-               printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1));
+       status = cli_rename(cli1, fname, fname1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("First rename failed (SHARE_READ) (this is correct) - %s\n", nt_errstr(status));
        } else {
                printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
                correct = False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("close - 1 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close - 1 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
-       cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
 #if 0
                              FILE_SHARE_DELETE|FILE_SHARE_NONE,
@@ -3837,28 +4491,32 @@ static bool run_rename(int dummy)
 #endif
                              FILE_OVERWRITE_IF, 0, 0, &fnum1);
        if (!NT_STATUS_IS_OK(status)) {
-               printf("Second open failed - %s\n", cli_errstr(cli1));
+               printf("Second open failed - %s\n", nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
-               printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1));
+       status = cli_rename(cli1, fname, fname1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", nt_errstr(status));
                correct = False;
        } else {
                printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
        }
 
-       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));
                return False;
        }
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
-       cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("Third open failed - %s\n", cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS,
+                             FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
+                             FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Third open failed - %s\n", nt_errstr(status));
                return False;
        }
 
@@ -3884,58 +4542,68 @@ static bool run_rename(int dummy)
   }
 #endif
 
-       if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
-               printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1));
+       status = cli_rename(cli1, fname, fname1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", nt_errstr(status));
                correct = False;
        } else {
                printf("Third rename succeeded (SHARE_NONE)\n");
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("close - 3 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close - 3 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
-       cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
         /*----*/
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("Fourth open failed - %s\n", cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
+                             FILE_ATTRIBUTE_NORMAL,
+                             FILE_SHARE_READ | FILE_SHARE_WRITE,
+                             FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Fourth open failed - %s\n", nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
-               printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1));
+       status = cli_rename(cli1, fname, fname1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", nt_errstr(status));
        } else {
                printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
                correct = False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("close - 4 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close - 4 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
-       cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
         /*--*/
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("Fifth open failed - %s\n", cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
+                        FILE_ATTRIBUTE_NORMAL,
+                        FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+                        FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Fifth open failed - %s\n", nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
-               printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n",
-                       cli_errstr(cli1));
+       status = cli_rename(cli1, fname, fname1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n", nt_errstr(status));
                correct = False;
        } else {
-               printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1));
+               printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", nt_errstr(status));
        }
 
         /*
@@ -3953,15 +4621,33 @@ static bool run_rename(int dummy)
           } */
 
         /*--*/
-
-
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("close - 5 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close - 5 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
-       cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
+       /* Check that the renamed file has FILE_ATTRIBUTE_ARCHIVE. */
+       status = cli_getatr(cli1, fname1, &attr, NULL, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("getatr on file %s failed - %s ! \n",
+                       fname1, nt_errstr(status));
+               correct = False;
+       } else {
+               if (attr != FILE_ATTRIBUTE_ARCHIVE) {
+                       printf("Renamed file %s has wrong attr 0x%x "
+                               "(should be 0x%x)\n",
+                               fname1,
+                               attr,
+                               (unsigned int)FILE_ATTRIBUTE_ARCHIVE);
+                       correct = False;
+               } else {
+                       printf("Renamed file %s has archive bit set\n", fname1);
+               }
+       }
+
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        if (!torture_close_connection(cli1)) {
                correct = False;
@@ -3976,6 +4662,7 @@ static bool run_pipe_number(int dummy)
        const char *pipe_name = "\\SPOOLSS";
        uint16_t fnum;
        int num_pipes = 0;
+       NTSTATUS status;
 
        printf("starting pipenumber test\n");
        if (!torture_open_connection(&cli1, 0)) {
@@ -3984,9 +4671,12 @@ static bool run_pipe_number(int dummy)
 
        cli_sockopt(cli1, sockops);
        while(1) {
-               if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0, &fnum))) {
-                       printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
+               status = cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA,
+                                     FILE_ATTRIBUTE_NORMAL,
+                                     FILE_SHARE_READ|FILE_SHARE_WRITE,
+                                     FILE_OPEN_IF, 0, 0, &fnum);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("Open of pipe %s failed with error (%s)\n", pipe_name, nt_errstr(status));
                        break;
                }
                num_pipes++;
@@ -4011,6 +4701,7 @@ static bool run_opentest(int dummy)
        SMB_OFF_T fsize;
        bool correct = True;
        char *tmp_path;
+       NTSTATUS status;
 
        printf("starting open test\n");
 
@@ -4019,27 +4710,31 @@ static bool run_opentest(int dummy)
        }
 
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        cli_sockopt(cli1, sockops);
 
-       if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
-               printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("close2 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close2 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_setatr(cli1, fname, aRONLY, 0))) {
-               printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
+       status = cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_setatr failed (%s)\n", nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1))) {
-               printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
@@ -4059,8 +4754,9 @@ static bool run_opentest(int dummy)
 
        cli_setatr(cli1, fname, 0, 0);
 
-       if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1))) {
-               printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
@@ -4072,19 +4768,20 @@ static bool run_opentest(int dummy)
                printf("correct error code ERRDOS/ERRbadshare returned\n");
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("close2 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close2 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        printf("finished open test 2\n");
 
        /* Test truncate open disposition on file opened for read. */
-
-       if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
-               printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("(3) open (1) of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
@@ -4092,19 +4789,22 @@ static bool run_opentest(int dummy)
 
        memset(buf, '\0', 20);
 
-       if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
-               printf("write failed (%s)\n", cli_errstr(cli1));
+       status = cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, 20, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("write failed (%s)\n", nt_errstr(status));
                correct = False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("(3) close1 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
        /* Ensure size == 20. */
-       if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) {
-               printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
+       status = cli_getatr(cli1, fname, NULL, &fsize, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("(3) getatr failed (%s)\n", nt_errstr(status));
                return False;
        }
 
@@ -4114,20 +4814,22 @@ static bool run_opentest(int dummy)
        }
 
        /* Now test if we can truncate a file opened for readonly. */
-
-       if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1))) {
-               printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("(3) open (2) of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("close2 failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close2 failed (%s)\n", nt_errstr(status));
                return False;
        }
 
        /* Ensure size == 0. */
-       if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) {
-               printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
+       status = cli_getatr(cli1, fname, NULL, &fsize, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("(3) getatr failed (%s)\n", nt_errstr(status));
                return False;
        }
 
@@ -4137,20 +4839,24 @@ static bool run_opentest(int dummy)
        }
        printf("finished open test 3\n");
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-
-       printf("testing ctemp\n");
-       if (!NT_STATUS_IS_OK(cli_ctemp(cli1, talloc_tos(), "\\", &fnum1, &tmp_path))) {
-               printf("ctemp failed (%s)\n", cli_errstr(cli1));
+       printf("Do ctemp tests\n");
+       status = cli_ctemp(cli1, talloc_tos(), "\\", &fnum1, &tmp_path);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ctemp failed (%s)\n", nt_errstr(status));
                return False;
        }
+
        printf("ctemp gave path %s\n", tmp_path);
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("close of temp failed (%s)\n", cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close of temp failed (%s)\n", nt_errstr(status));
        }
-       if (!NT_STATUS_IS_OK(cli_unlink(cli1, tmp_path, aSYSTEM | aHIDDEN))) {
-               printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
+
+       status = cli_unlink(cli1, tmp_path, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("unlink of temp failed (%s)\n", nt_errstr(status));
        }
 
        /* Test the non-io opens... */
@@ -4160,137 +4866,174 @@ static bool run_opentest(int dummy)
        }
 
        cli_setatr(cli2, fname, 0, 0);
-       cli_unlink(cli2, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli2, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        cli_sockopt(cli2, sockops);
 
        printf("TEST #1 testing 2 non-io opens (no delete)\n");
-
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES,
+                             FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
+                             FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #1 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
-               printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+       status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
+                             FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
+                             FILE_OPEN_IF, 0, 0, &fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #1 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #1 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
-       if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
-               printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+
+       status = cli_close(cli2, fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #1 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
        printf("non-io open test #1 passed.\n");
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        printf("TEST #2 testing 2 non-io opens (first with delete)\n");
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0,
+                             DELETE_ACCESS|FILE_READ_ATTRIBUTES,
+                             FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
+                             FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #2 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
-               printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+       status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
+                             FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
+                             FILE_OPEN_IF, 0, 0, &fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #2 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #2 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
-       if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
-               printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
+
+       status = cli_close(cli2, fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #2 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
        printf("non-io open test #2 passed.\n");
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        printf("TEST #3 testing 2 non-io opens (second with delete)\n");
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES,
+                             FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
+                             FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #3 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
-               printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+       status = cli_ntcreate(cli2, fname, 0,
+                             DELETE_ACCESS|FILE_READ_ATTRIBUTES,
+                             FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
+                             FILE_OPEN_IF, 0, 0, &fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #3 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #3 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
-       if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
-               printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+
+       status = cli_close(cli2, fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #3 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
        printf("non-io open test #3 passed.\n");
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        printf("TEST #4 testing 2 non-io opens (both with delete)\n");
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0,
+                              DELETE_ACCESS|FILE_READ_ATTRIBUTES,
+                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
+                              FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #4 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
-               printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
+       status = cli_ntcreate(cli2, fname, 0,
+                             DELETE_ACCESS|FILE_READ_ATTRIBUTES,
+                             FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
+                             FILE_OPEN_IF, 0, 0, &fnum2);
+       if (NT_STATUS_IS_OK(status)) {
+               printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
+       printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation");
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #4 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
        printf("non-io open test #4 passed.\n");
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0,
+                             DELETE_ACCESS|FILE_READ_ATTRIBUTES,
+                             FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE,
+                             FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #5 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) {
-               printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+       status = cli_ntcreate(cli2, fname, 0,
+                             DELETE_ACCESS|FILE_READ_ATTRIBUTES,
+                             FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE,
+                             FILE_OPEN_IF, 0, 0, &fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #5 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #5 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
-               printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+       status = cli_close(cli2, fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #5 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
@@ -4298,27 +5041,33 @@ static bool run_opentest(int dummy)
 
        printf("TEST #6 testing 1 non-io open, one io open\n");
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA,
+                             FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
+                             FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #6 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_READ, FILE_OPEN_IF, 0, 0, &fnum2))) {
-               printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+       status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
+                             FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
+                             FILE_OPEN_IF, 0, 0, &fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #6 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #6 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
-               printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
+       status = cli_close(cli2, fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #6 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
@@ -4326,30 +5075,64 @@ static bool run_opentest(int dummy)
 
        printf("TEST #7 testing 1 non-io open, one io open with delete\n");
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-               printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA,
+                             FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
+                             FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #7 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) {
-               printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
+       status = cli_ntcreate(cli2, fname, 0,
+                             DELETE_ACCESS|FILE_READ_ATTRIBUTES,
+                             FILE_ATTRIBUTE_NORMAL,
+                             FILE_SHARE_READ|FILE_SHARE_DELETE,
+                             FILE_OPEN_IF, 0, 0, &fnum2);
+       if (NT_STATUS_IS_OK(status)) {
+               printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
-       printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
+       printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation");
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #7 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
        printf("non-io open test #7 passed.\n");
 
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+       printf("TEST #8 testing open without WRITE_ATTRIBUTES, updating close write time.\n");
+       status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,
+                               FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+                               FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #8 open of %s failed (%s)\n", fname, nt_errstr(status));
+               correct = false;
+               goto out;
+       }
+
+       /* Write to ensure we have to update the file time. */
+       status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
+                             NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("TEST #8 cli_write failed: %s\n", nt_errstr(status));
+               correct = false;
+               goto out;
+       }
+
+        status = cli_close(cli1, fnum1);
+        if (!NT_STATUS_IS_OK(status)) {
+                printf("TEST #8 close of %s failed (%s)\n", fname, nt_errstr(status));
+               correct = false;
+        }
+
+  out:
 
        if (!torture_close_connection(cli1)) {
                correct = False;
@@ -4361,6 +5144,36 @@ static bool run_opentest(int dummy)
        return correct;
 }
 
+NTSTATUS torture_setup_unix_extensions(struct cli_state *cli)
+{
+       uint16 major, minor;
+       uint32 caplow, caphigh;
+       NTSTATUS status;
+
+       if (!SERVER_HAS_UNIX_CIFS(cli)) {
+               printf("Server doesn't support UNIX CIFS extensions.\n");
+               return NT_STATUS_NOT_SUPPORTED;
+       }
+
+       status = cli_unix_extensions_version(cli, &major, &minor, &caplow,
+                                            &caphigh);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Server didn't return UNIX CIFS extensions: %s\n",
+                      nt_errstr(status));
+               return status;
+       }
+
+       status = cli_set_unix_extensions_capabilities(cli, major, minor,
+                                                     caplow, caphigh);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Server doesn't support setting UNIX CIFS extensions: "
+                      "%s.\n", nt_errstr(status));
+               return status;
+        }
+
+       return NT_STATUS_OK;
+}
+
 /*
   Test POSIX open /mkdir calls.
  */
@@ -4373,8 +5186,6 @@ static bool run_simple_posix_open_test(int dummy)
        const char *dname = "posix:dir";
        char buf[10];
        char namebuf[11];
-       uint16 major, minor;
-       uint32 caplow, caphigh;
        uint16_t fnum1 = (uint16_t)-1;
        SMB_STRUCT_STAT sbuf;
        bool correct = false;
@@ -4388,27 +5199,11 @@ static bool run_simple_posix_open_test(int dummy)
 
        cli_sockopt(cli1, sockops);
 
-       if (!SERVER_HAS_UNIX_CIFS(cli1)) {
-               printf("Server doesn't support UNIX CIFS extensions.\n");
-               return false;
-       }
-
-       status = cli_unix_extensions_version(cli1, &major, &minor, &caplow,
-                                            &caphigh);
+       status = torture_setup_unix_extensions(cli1);
        if (!NT_STATUS_IS_OK(status)) {
-               printf("Server didn't return UNIX CIFS extensions: %s\n",
-                      nt_errstr(status));
                return false;
        }
 
-       status = cli_set_unix_extensions_capabilities(cli1, major, minor,
-                                                     caplow, caphigh);
-       if (!NT_STATUS_IS_OK(status)) {
-               printf("Server doesn't support setting UNIX CIFS extensions: "
-                      "%s.\n", nt_errstr(status));
-               return false;
-        }
-
        cli_setatr(cli1, fname, 0, 0);
        cli_posix_unlink(cli1, fname);
        cli_setatr(cli1, dname, 0, 0);
@@ -4419,11 +5214,79 @@ static bool run_simple_posix_open_test(int dummy)
        cli_posix_unlink(cli1, sname);
 
        /* Create a directory. */
-       if (!NT_STATUS_IS_OK(cli_posix_mkdir(cli1, dname, 0777))) {
-               printf("POSIX mkdir of %s failed (%s)\n", dname, cli_errstr(cli1));
+       status = cli_posix_mkdir(cli1, dname, 0777);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("POSIX mkdir of %s failed (%s)\n", dname, nt_errstr(status));
+               goto out;
+       }
+
+       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. */
+       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 */
+       status = cli_posix_stat(cli1, fname, &sbuf);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("stat failed (%s)\n", nt_errstr(status));
+               goto out;
+       }
+
+       if (sbuf.st_ex_size != 1000) {
+               printf("ftruncate - stat size (%u) != 1000\n", (unsigned int)sbuf.st_ex_size);
+               goto out;
+       }
+
+       /* Test ftruncate - set file size back to zero. */
+       status = cli_ftruncate(cli1, fnum1, 0);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ftruncate failed (%s)\n", nt_errstr(status));
+               goto out;
+       }
+
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close failed (%s)\n", nt_errstr(status));
+               goto out;
+       }
+
+       /* Now open the file again for read only. */
+       status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("POSIX open of %s failed (%s)\n", fname, nt_errstr(status));
+               goto out;
+       }
+
+       /* Now unlink while open. */
+       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;
+       }
+
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close(2) failed (%s)\n", nt_errstr(status));
+               goto out;
+       }
+
+       /* Ensure the file has gone. */
+       status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1);
+       if (NT_STATUS_IS_OK(status)) {
+               printf("POSIX open of %s succeeded, should have been deleted.\n", fname);
+               goto out;
+       }
+
+       /* 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));
                goto out;
@@ -4446,42 +5309,48 @@ static bool run_simple_posix_open_test(int dummy)
                goto out;
        }
 
-       /* Test ftruncate - set file size back to zero. */
-       if (!NT_STATUS_IS_OK(cli_ftruncate(cli1, fnum1, 0))) {
-               printf("ftruncate failed (%s)\n", cli_errstr(cli1));
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
+               printf("close(2) failed (%s)\n", cli_errstr(cli1));
                goto out;
        }
 
-       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("close failed (%s)\n", cli_errstr(cli1));
+       /* 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));
                goto out;
        }
 
-       /* Now open the file again for read only. */
-       if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1))) {
-               printf("POSIX open of %s failed (%s)\n", fname, cli_errstr(cli1));
+       /* Ensure st_size == 0 */
+       if (!NT_STATUS_IS_OK(cli_posix_stat(cli1, fname, &sbuf))) {
+               printf("stat failed (%s)\n", cli_errstr(cli1));
                goto out;
        }
 
-       /* Now unlink while open. */
-       if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1, fname))) {
-               printf("POSIX unlink of %s failed (%s)\n", fname, cli_errstr(cli1));
+       if (sbuf.st_ex_size != 0) {
+               printf("O_TRUNC - stat size (%u) != 0\n", (unsigned int)sbuf.st_ex_size);
                goto out;
        }
 
        if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-               printf("close(2) failed (%s)\n", cli_errstr(cli1));
+               printf("close failed (%s)\n", cli_errstr(cli1));
                goto out;
        }
 
-       /* Ensure the file has gone. */
-       if (NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1))) {
-               printf("POSIX open of %s succeeded, should have been deleted.\n", fname);
+       if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1, fname))) {
+               printf("POSIX unlink of %s failed (%s)\n", fname, cli_errstr(cli1));
                goto out;
        }
 
-       /* What happens when we try and POSIX open a directory ? */
-       if (NT_STATUS_IS_OK(cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1))) {
+       if (!NT_STATUS_IS_OK(cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1))) {
+               printf("POSIX open directory O_RDONLY of %s failed (%s)\n",
+                       dname, cli_errstr(cli1));
+               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))) {
                printf("POSIX open of directory %s succeeded, should have failed.\n", fname);
                goto out;
        } else {
@@ -4492,34 +5361,41 @@ static bool run_simple_posix_open_test(int dummy)
        }
 
        /* Create the file. */
-       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;
        }
 
        /* Write some data into it. */
-       if (cli_write(cli1, fnum1, 0, "TEST DATA\n", 0, 10) != 10) {
-               printf("cli_write failed: %s\n", cli_errstr(cli1));
+       status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
+                             NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_write failed: %s\n", nt_errstr(status));
                goto out;
        }
 
        cli_close(cli1, fnum1);
 
        /* Now create a hardlink. */
-       if (!NT_STATUS_IS_OK(cli_posix_hardlink(cli1, fname, hname))) {
-               printf("POSIX hardlink of %s failed (%s)\n", hname, cli_errstr(cli1));
+       status = cli_posix_hardlink(cli1, fname, hname);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("POSIX hardlink of %s failed (%s)\n", hname, nt_errstr(status));
                goto out;
        }
 
        /* Now create a symlink. */
-       if (!NT_STATUS_IS_OK(cli_posix_symlink(cli1, fname, sname))) {
-               printf("POSIX symlink of %s failed (%s)\n", sname, cli_errstr(cli1));
+       status = cli_posix_symlink(cli1, fname, sname);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("POSIX symlink of %s failed (%s)\n", sname, nt_errstr(status));
                goto out;
        }
 
        /* Open the hardlink for read. */
-       if (!NT_STATUS_IS_OK(cli_posix_open(cli1, hname, O_RDONLY, 0, &fnum1))) {
-               printf("POSIX open of %s failed (%s)\n", hname, cli_errstr(cli1));
+       status = cli_posix_open(cli1, hname, O_RDONLY, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("POSIX open of %s failed (%s)\n", hname, nt_errstr(status));
                goto out;
        }
 
@@ -4534,14 +5410,16 @@ static bool run_simple_posix_open_test(int dummy)
        }
 
        /* Do a POSIX lock/unlock. */
-       if (!NT_STATUS_IS_OK(cli_posix_lock(cli1, fnum1, 0, 100, true, READ_LOCK))) {
-               printf("POSIX lock failed %s\n", cli_errstr(cli1));
+       status = cli_posix_lock(cli1, fnum1, 0, 100, true, READ_LOCK);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("POSIX lock failed %s\n", nt_errstr(status));
                goto out;
        }
 
        /* Punch a hole in the locked area. */
-       if (!NT_STATUS_IS_OK(cli_posix_unlock(cli1, fnum1, 10, 80))) {
-               printf("POSIX unlock failed %s\n", cli_errstr(cli1));
+       status = cli_posix_unlock(cli1, fnum1, 10, 80);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("POSIX unlock failed %s\n", nt_errstr(status));
                goto out;
        }
 
@@ -4549,7 +5427,8 @@ static bool run_simple_posix_open_test(int dummy)
 
        /* Open the symlink for read - this should fail. A POSIX
           client should not be doing opens on a symlink. */
-       if (NT_STATUS_IS_OK(cli_posix_open(cli1, sname, O_RDONLY, 0, &fnum1))) {
+       status = cli_posix_open(cli1, sname, O_RDONLY, 0, &fnum1);
+       if (NT_STATUS_IS_OK(status)) {
                printf("POSIX open of %s succeeded (should have failed)\n", sname);
                goto out;
        } else {
@@ -4558,13 +5437,14 @@ static bool run_simple_posix_open_test(int dummy)
                        printf("POSIX open of %s should have failed "
                                "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
                                "failed with %s instead.\n",
-                               sname, cli_errstr(cli1));
+                               sname, nt_errstr(status));
                        goto out;
                }
        }
 
-       if (!NT_STATUS_IS_OK(cli_posix_readlink(cli1, sname, namebuf, sizeof(namebuf)))) {
-               printf("POSIX readlink on %s failed (%s)\n", sname, cli_errstr(cli1));
+       status = cli_posix_readlink(cli1, sname, namebuf, sizeof(namebuf));
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("POSIX readlink on %s failed (%s)\n", sname, nt_errstr(status));
                goto out;
        }
 
@@ -4574,8 +5454,9 @@ static bool run_simple_posix_open_test(int dummy)
                goto out;
        }
 
-       if (!NT_STATUS_IS_OK(cli_posix_rmdir(cli1, dname))) {
-               printf("POSIX rmdir failed (%s)\n", cli_errstr(cli1));
+       status = cli_posix_rmdir(cli1, dname);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("POSIX rmdir failed (%s)\n", nt_errstr(status));
                goto out;
        }
 
@@ -4670,6 +5551,7 @@ static bool run_openattrtest(int dummy)
        bool correct = True;
        uint16 attr;
        unsigned int i, j, k, l;
+       NTSTATUS status;
 
        printf("starting open attr test\n");
 
@@ -4681,34 +5563,43 @@ static bool run_openattrtest(int dummy)
 
        for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
                cli_setatr(cli1, fname, 0, 0);
-               cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
-               if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
-                       printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
+               cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+               status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA,
+                                      open_attrs_table[i], FILE_SHARE_NONE,
+                                      FILE_OVERWRITE_IF, 0, 0, &fnum1);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("open %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status));
                        return False;
                }
 
-               if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-                       printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
+               status = cli_close(cli1, fnum1);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("close %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status));
                        return False;
                }
 
                for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
-                       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
-                                          FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0, &fnum1))) {
+                       status = cli_ntcreate(cli1, fname, 0,
+                                             FILE_READ_DATA|FILE_WRITE_DATA,
+                                             open_attrs_table[j],
+                                             FILE_SHARE_NONE, FILE_OVERWRITE,
+                                             0, 0, &fnum1);
+                       if (!NT_STATUS_IS_OK(status)) {
                                for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
                                        if (attr_results[l].num == k) {
                                                printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
                                                                k, open_attrs_table[i],
                                                                open_attrs_table[j],
-                                                               fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
+                                                               fname, NT_STATUS_V(status), nt_errstr(status));
                                                correct = False;
                                        }
                                }
-                               if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
+
+                               if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
                                        printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
                                                        k, open_attrs_table[i], open_attrs_table[j],
-                                                       cli_errstr(cli1));
+                                                       nt_errstr(status));
                                        correct = False;
                                }
 #if 0
@@ -4718,13 +5609,15 @@ static bool run_openattrtest(int dummy)
                                continue;
                        }
 
-                       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
-                               printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
+                       status = cli_close(cli1, fnum1);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               printf("close %d (2) of %s failed (%s)\n", j, fname, nt_errstr(status));
                                return False;
                        }
 
-                       if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, &attr, NULL, NULL))) {
-                               printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
+                       status = cli_getatr(cli1, fname, &attr, NULL, NULL);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               printf("getatr(2) failed (%s)\n", nt_errstr(status));
                                return False;
                        }
 
@@ -4753,7 +5646,7 @@ static bool run_openattrtest(int dummy)
        }
 
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
        printf("open attr test %s.\n", correct ? "passed" : "failed");
 
@@ -4763,9 +5656,14 @@ static bool run_openattrtest(int dummy)
        return correct;
 }
 
-static void list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
+static NTSTATUS list_fn(const char *mnt, struct file_info *finfo,
+                   const char *name, void *state)
 {
-
+       int *matched = (int *)state;
+       if (matched != NULL) {
+               *matched += 1;
+       }
+       return NT_STATUS_OK;
 }
 
 /*
@@ -4776,8 +5674,9 @@ static bool run_dirtest(int dummy)
        int i;
        static struct cli_state *cli;
        uint16_t fnum;
-       double t1;
+       struct timeval core_start;
        bool correct = True;
+       int matched;
 
        printf("starting directory test\n");
 
@@ -4798,19 +5697,27 @@ static bool run_dirtest(int dummy)
                cli_close(cli, fnum);
        }
 
-       t1 = end_timer();
+       core_start = timeval_current();
 
-       printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
-       printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
-       printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
+       matched = 0;
+       cli_list(cli, "a*.*", 0, list_fn, &matched);
+       printf("Matched %d\n", matched);
+
+       matched = 0;
+       cli_list(cli, "b*.*", 0, list_fn, &matched);
+       printf("Matched %d\n", matched);
+
+       matched = 0;
+       cli_list(cli, "xyzabc", 0, list_fn, &matched);
+       printf("Matched %d\n", matched);
 
-       printf("dirtest core %g seconds\n", end_timer() - t1);
+       printf("dirtest core %g seconds\n", timeval_elapsed(&core_start));
 
        srandom(0);
        for (i=0;i<torture_numops;i++) {
                fstring fname;
                slprintf(fname, sizeof(fname), "\\%x", (int)random());
-               cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+               cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        }
 
        if (!torture_close_connection(cli)) {
@@ -4822,22 +5729,24 @@ static bool run_dirtest(int dummy)
        return correct;
 }
 
-static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
+static NTSTATUS del_fn(const char *mnt, struct file_info *finfo, const char *mask,
+                  void *state)
 {
        struct cli_state *pcli = (struct cli_state *)state;
        fstring fname;
        slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
 
        if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
-               return;
+               return NT_STATUS_OK;
 
-       if (finfo->mode & aDIR) {
+       if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
                if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
                        printf("del_fn: failed to rmdir %s\n,", fname );
        } else {
-               if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN)))
+               if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN)))
                        printf("del_fn: failed to unlink %s\n,", fname );
        }
+       return NT_STATUS_OK;
 }
 
 
@@ -4859,21 +5768,22 @@ bool torture_ioctl_test(int dummy)
 
        printf("starting ioctl test\n");
 
-       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
-       if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
-               printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
+       status = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n", fname, nt_errstr(status));
                return False;
        }
 
        status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
-       printf("ioctl device info: %s\n", cli_errstr(cli));
+       printf("ioctl device info: %s\n", nt_errstr(status));
 
        status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
-       printf("ioctl job info: %s\n", cli_errstr(cli));
+       printf("ioctl job info: %s\n", nt_errstr(status));
 
        for (device=0;device<0x100;device++) {
-               printf("testing device=0x%x\n", device);
+               printf("ioctl test with device = 0x%x\n", device);
                for (function=0;function<0x100;function++) {
                        uint32 code = (device<<16) | function;
 
@@ -4903,6 +5813,7 @@ bool torture_chkpath_test(int dummy)
        static struct cli_state *cli;
        uint16_t fnum;
        bool ret;
+       NTSTATUS status;
 
        if (!torture_open_connection(&cli, 0)) {
                return False;
@@ -4912,36 +5823,43 @@ bool torture_chkpath_test(int dummy)
 
        /* cleanup from an old run */
        cli_rmdir(cli, "\\chkpath.dir\\dir2");
-       cli_unlink(cli, "\\chkpath.dir\\*", aSYSTEM | aHIDDEN);
+       cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        cli_rmdir(cli, "\\chkpath.dir");
 
-       if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir"))) {
-               printf("mkdir1 failed : %s\n", cli_errstr(cli));
+       status = cli_mkdir(cli, "\\chkpath.dir");
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("mkdir1 failed : %s\n", nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir\\dir2"))) {
-               printf("mkdir2 failed : %s\n", cli_errstr(cli));
+       status = cli_mkdir(cli, "\\chkpath.dir\\dir2");
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("mkdir2 failed : %s\n", nt_errstr(status));
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
-               printf("open1 failed (%s)\n", cli_errstr(cli));
+       status = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL,
+                         DENY_NONE, &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open1 failed (%s)\n", nt_errstr(status));
                return False;
        }
        cli_close(cli, fnum);
 
-       if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir"))) {
-               printf("chkpath1 failed: %s\n", cli_errstr(cli));
+       status = cli_chkpath(cli, "\\chkpath.dir");
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("chkpath1 failed: %s\n", nt_errstr(status));
                ret = False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dir2"))) {
-               printf("chkpath2 failed: %s\n", cli_errstr(cli));
+       status = cli_chkpath(cli, "\\chkpath.dir\\dir2");
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("chkpath2 failed: %s\n", nt_errstr(status));
                ret = False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\foo.txt"))) {
+       status = cli_chkpath(cli, "\\chkpath.dir\\foo.txt");
+       if (!NT_STATUS_IS_OK(status)) {
                ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath, 
                                  NT_STATUS_NOT_A_DIRECTORY);
        } else {
@@ -4966,7 +5884,7 @@ bool torture_chkpath_test(int dummy)
        }
 
        cli_rmdir(cli, "\\chkpath.dir\\dir2");
-       cli_unlink(cli, "\\chkpath.dir\\*", aSYSTEM | aHIDDEN);
+       cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        cli_rmdir(cli, "\\chkpath.dir");
 
        if (!torture_close_connection(cli)) {
@@ -4986,6 +5904,7 @@ static bool run_eatest(int dummy)
        size_t num_eas;
        struct ea_struct *ea_list = NULL;
        TALLOC_CTX *mem_ctx = talloc_init("eatest");
+       NTSTATUS status;
 
        printf("starting eatest\n");
 
@@ -4994,12 +5913,14 @@ static bool run_eatest(int dummy)
                return False;
        }
 
-       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
-       if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0,
-                                  FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 
-                                  0x4044, 0, &fnum))) {
-               printf("open failed - %s\n", cli_errstr(cli));
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+       status = cli_ntcreate(cli, fname, 0,
+                              FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
+                              FILE_SHARE_NONE, FILE_OVERWRITE_IF,
+                              0x4044, 0, &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open failed - %s\n", nt_errstr(status));
                talloc_destroy(mem_ctx);
                return False;
        }
@@ -5009,8 +5930,10 @@ static bool run_eatest(int dummy)
 
                slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
                memset(ea_val, (char)i+1, i+1);
-               if (!cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1)) {
-                       printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
+               status = cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("ea_set of name %s failed - %s\n", ea_name,
+                              nt_errstr(status));
                        talloc_destroy(mem_ctx);
                        return False;
                }
@@ -5022,15 +5945,18 @@ static bool run_eatest(int dummy)
 
                slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
                memset(ea_val, (char)i+1, i+1);
-               if (!cli_set_ea_path(cli, fname, ea_name, ea_val, i+1)) {
-                       printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
+               status = cli_set_ea_path(cli, fname, ea_name, ea_val, i+1);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("ea_set of name %s failed - %s\n", ea_name,
+                              nt_errstr(status));
                        talloc_destroy(mem_ctx);
                        return False;
                }
        }
 
-       if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
-               printf("ea_get list failed - %s\n", cli_errstr(cli));
+       status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ea_get list failed - %s\n", nt_errstr(status));
                correct = False;
        }
 
@@ -5056,16 +5982,19 @@ static bool run_eatest(int dummy)
        for (i = 0; i < 20; i++) {
                fstring ea_name;
                slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
-               if (!cli_set_ea_path(cli, fname, ea_name, "", 0)) {
-                       printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
+               status = cli_set_ea_path(cli, fname, ea_name, "", 0);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("ea_set of name %s failed - %s\n", ea_name,
+                              nt_errstr(status));
                        talloc_destroy(mem_ctx);
                        return False;
                }
        }
 #endif
 
-       if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
-               printf("ea_get list failed - %s\n", cli_errstr(cli));
+       status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ea_get list failed - %s\n", nt_errstr(status));
                correct = False;
        }
 
@@ -5082,8 +6011,10 @@ static bool run_eatest(int dummy)
        }
 
        /* Try and delete a non existant EA. */
-       if (!cli_set_ea_path(cli, fname, "foo", "", 0)) {
-               printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli));
+       status = cli_set_ea_path(cli, fname, "foo", "", 0);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("deleting non-existant EA 'foo' should succeed. %s\n",
+                      nt_errstr(status));
                correct = False;
        }
 
@@ -5112,7 +6043,7 @@ static bool run_dirtest1(int dummy)
        cli_sockopt(cli, sockops);
 
        cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
-       cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
+       cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
        cli_rmdir(cli, "\\LISTDIR");
        cli_mkdir(cli, "\\LISTDIR");
 
@@ -5137,7 +6068,8 @@ static bool run_dirtest1(int dummy)
        }
 
        /* Now ensure that doing an old list sees both files and directories. */
-       num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
+       num_seen = 0;
+       cli_list_old(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
        printf("num_seen = %d\n", num_seen );
        /* We should see 100 files + 1000 directories + . and .. */
        if (num_seen != 2002)
@@ -5146,19 +6078,21 @@ static bool run_dirtest1(int dummy)
        /* Ensure if we have the "must have" bits we only see the
         * relevent entries.
         */
-       num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
+       num_seen = 0;
+       cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
        printf("num_seen = %d\n", num_seen );
        if (num_seen != 1002)
                correct = False;
 
-       num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
+       num_seen = 0;
+       cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_ARCHIVE<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
        printf("num_seen = %d\n", num_seen );
        if (num_seen != 1000)
                correct = False;
 
        /* Delete everything. */
        cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
-       cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
+       cli_list(cli, "\\LISTDIR\\*", FILE_ATTRIBUTE_DIRECTORY, del_fn, cli);
        cli_rmdir(cli, "\\LISTDIR");
 
 #if 0
@@ -5208,9 +6142,9 @@ static bool run_error_map_extract(int dummy) {
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_session_setup(c_nt, "", "", 0, "", 0,
-                                              workgroup))) {
-               printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(c_nt));
+       status = cli_session_setup(c_nt, "", "", 0, "", 0, workgroup);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("%s rejected the NT-error initial session setup (%s)\n",host, nt_errstr(status));
                return False;
        }
 
@@ -5231,19 +6165,21 @@ static bool run_error_map_extract(int dummy) {
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_session_setup(c_dos, "", "", 0, "", 0,
-                                              workgroup))) {
-               printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(c_dos));
+       status = cli_session_setup(c_dos, "", "", 0, "", 0, workgroup);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("%s rejected the DOS-error initial session setup (%s)\n",
+                       host, nt_errstr(status));
                return False;
        }
 
        for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
                fstr_sprintf(user, "%X", error);
 
-               if (NT_STATUS_IS_OK(cli_session_setup(c_nt, user, 
-                                                     password, strlen(password),
-                                                     password, strlen(password),
-                                                     workgroup))) {
+               status = cli_session_setup(c_nt, user,
+                                          password, strlen(password),
+                                          password, strlen(password),
+                                          workgroup);
+               if (NT_STATUS_IS_OK(status)) {
                        printf("/** Session setup succeeded.  This shouldn't happen...*/\n");
                }
 
@@ -5277,14 +6213,14 @@ static bool run_error_map_extract(int dummy) {
 
                if (NT_STATUS_V(nt_status) != error) { 
                        printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n", 
-                              get_nt_error_c_code(NT_STATUS(error)), 
-                              get_nt_error_c_code(nt_status));
+                              get_nt_error_c_code(talloc_tos(), NT_STATUS(error)), 
+                              get_nt_error_c_code(talloc_tos(), nt_status));
                }
 
                printf("\t{%s,\t%s,\t%s},\n", 
                       smb_dos_err_class(errclass), 
                       smb_dos_err_name(errclass, errnum), 
-                      get_nt_error_c_code(NT_STATUS(error)));
+                      get_nt_error_c_code(talloc_tos(), NT_STATUS(error)));
        }
        return True;
 }
@@ -5301,11 +6237,11 @@ static bool run_sesssetup_bench(int dummy)
                return false;
        }
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(
-                       c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
-                       FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
-                       FILE_DELETE_ON_CLOSE, 0, &fnum))) {
-               d_printf("open %s failed: %s\n", fname, cli_errstr(c));
+       status = cli_ntcreate(c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
+                             FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
+                             FILE_DELETE_ON_CLOSE, 0, &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("open %s failed: %s\n", fname, nt_errstr(status));
                return false;
        }
 
@@ -5323,9 +6259,10 @@ static bool run_sesssetup_bench(int dummy)
 
                d_printf("\r%d   ", (int)c->vuid);
 
-               if (!cli_ulogoff(c)) {
+               status = cli_ulogoff(c);
+               if (!NT_STATUS_IS_OK(status)) {
                        d_printf("(%s) cli_ulogoff failed: %s\n",
-                                __location__, cli_errstr(c));
+                                __location__, nt_errstr(status));
                        return false;
                }
                c->vuid = 0;
@@ -5413,7 +6350,7 @@ static bool run_chain1(int dummy)
 
 
        reqs[1] = cli_write_andx_create(talloc_tos(), evt, cli1, 0, 0,
-                                       (uint8_t *)str, 0, strlen(str)+1,
+                                       (const uint8_t *)str, 0, strlen(str)+1,
                                        smbreqs, 1, &smbreqs[1]);
        if (reqs[1] == NULL) return false;
        tevent_req_set_callback(reqs[1], chain1_write_completion, NULL);
@@ -5461,7 +6398,7 @@ static bool run_chain2(int dummy)
 
        printf("starting chain2 test\n");
        status = cli_start_connection(&cli1, global_myname(), host, NULL,
-                                     port_to_use, Undefined, 0, NULL);
+                                     port_to_use, Undefined, 0);
        if (!NT_STATUS_IS_OK(status)) {
                return False;
        }
@@ -5798,7 +6735,8 @@ static bool run_notify_bench(int dummy)
        struct tevent_context *ev;
        NTSTATUS status;
        uint16_t dnum;
-       struct tevent_req *req1, *req2;
+       struct tevent_req *req1;
+       struct tevent_req *req2 = NULL;
        int i, num_unc_names;
        int num_finished = 0;
 
@@ -5911,10 +6849,11 @@ static bool run_mangle1(int dummy)
 
        cli_sockopt(cli, sockops);
 
-       if (!NT_STATUS_IS_OK(cli_ntcreate(
-                       cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
-                       FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
-               d_printf("open %s failed: %s\n", fname, cli_errstr(cli));
+       status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
+                             FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
+                             0, 0, &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("open %s failed: %s\n", fname, nt_errstr(status));
                return false;
        }
        cli_close(cli, fnum);
@@ -5927,17 +6866,19 @@ static bool run_mangle1(int dummy)
        }
        d_printf("alt_name: %s\n", alt_name);
 
-       if (!NT_STATUS_IS_OK(cli_open(cli, alt_name, O_RDONLY, DENY_NONE, &fnum))) {
+       status = cli_open(cli, alt_name, O_RDONLY, DENY_NONE, &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
                d_printf("cli_open(%s) failed: %s\n", alt_name,
-                        cli_errstr(cli));
+                        nt_errstr(status));
                return false;
        }
        cli_close(cli, fnum);
 
-       if (!cli_qpathinfo(cli, alt_name, &change_time, &access_time,
-                          &write_time, &size, &mode)) {
-               d_printf("cli_qpathinfo(%s) failed: %s\n", alt_name,
-                        cli_errstr(cli));
+       status = cli_qpathinfo1(cli, alt_name, &change_time, &access_time,
+                               &write_time, &size, &mode);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("cli_qpathinfo1(%s) failed: %s\n", alt_name,
+                        nt_errstr(status));
                return false;
        }
 
@@ -5966,32 +6907,35 @@ static bool run_windows_write(int dummy)
        int i;
        bool ret = false;
        const char *fname = "\\writetest.txt";
+       struct timeval start_time;
        double seconds;
        double kbytes;
+       NTSTATUS status;
 
        printf("starting windows_write test\n");
        if (!torture_open_connection(&cli1, 0)) {
                return False;
        }
 
-       if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
-               printf("open failed (%s)\n", cli_errstr(cli1));
+       status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open failed (%s)\n", nt_errstr(status));
                return False;
        }
 
        cli_sockopt(cli1, sockops);
 
-       start_timer();
+       start_time = timeval_current();
 
        for (i=0; i<torture_numops; i++) {
-               char c = 0;
+               uint8_t c = 0;
                off_t start = i * torture_blocksize;
-               NTSTATUS status;
                size_t to_pull = torture_blocksize - 1;
 
-               if (cli_write(cli1, fnum, 0, &c,
-                             start + torture_blocksize - 1, 1) != 1) {
-                       printf("cli_write failed: %s\n", cli_errstr(cli1));
+               status = cli_writeall(cli1, fnum, 0, &c,
+                                     start + torture_blocksize - 1, 1, NULL);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("cli_write failed: %s\n", nt_errstr(status));
                        goto fail;
                }
 
@@ -6003,7 +6947,7 @@ static bool run_windows_write(int dummy)
                }
        }
 
-       seconds = end_timer();
+       seconds = timeval_elapsed(&start_time);
        kbytes = (double)torture_blocksize * torture_numops;
        kbytes /= 1024;
 
@@ -6013,7 +6957,7 @@ static bool run_windows_write(int dummy)
        ret = true;
  fail:
        cli_close(cli1, fnum);
-       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        torture_close_connection(cli1);
        return ret;
 }
@@ -6043,6 +6987,7 @@ static bool run_uid_regression_test(int dummy)
        int16_t old_vuid;
        int16_t old_cnum;
        bool correct = True;
+       NTSTATUS status;
 
        printf("starting uid regression test\n");
 
@@ -6055,9 +7000,10 @@ static bool run_uid_regression_test(int dummy)
        /* Ok - now save then logoff our current user. */
        old_vuid = cli->vuid;
 
-       if (!cli_ulogoff(cli)) {
+       status = cli_ulogoff(cli);
+       if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) cli_ulogoff failed: %s\n",
-                       __location__, cli_errstr(cli));
+                        __location__, nt_errstr(status));
                correct = false;
                goto out;
        }
@@ -6065,11 +7011,18 @@ static bool run_uid_regression_test(int dummy)
        cli->vuid = old_vuid;
 
        /* Try an operation. */
-       if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\uid_reg_test"))) {
-               /* We expect bad uid. */
+       status = cli_mkdir(cli, "\\uid_reg_test");
+       if (NT_STATUS_IS_OK(status)) {
+               d_printf("(%s) cli_mkdir succeeded\n",
+                        __location__);
+               correct = false;
+               goto out;
+       } else {
+               /* Should be bad uid. */
                if (!check_error(__LINE__, cli, ERRSRV, ERRbaduid,
-                               NT_STATUS_NO_SUCH_USER)) {
-                       return False;
+                               NT_STATUS_USER_SESSION_DELETED)) {
+                       correct = false;
+                       goto out;
                }
        }
 
@@ -6079,23 +7032,31 @@ static bool run_uid_regression_test(int dummy)
        cli->vuid = 0;
 
        /* This should succeed. */
-       if (cli_tdis(cli)) {
-               printf("First tdis with invalid vuid should succeed.\n");
+       status = cli_tdis(cli);
+
+       if (NT_STATUS_IS_OK(status)) {
+               d_printf("First tdis with invalid vuid should succeed.\n");
        } else {
-               printf("First tdis failed (%s)\n", cli_errstr(cli));
+               d_printf("First tdis failed (%s)\n", nt_errstr(status));
+               correct = false;
+               goto out;
        }
 
        cli->vuid = old_vuid;
        cli->cnum = old_cnum;
 
        /* This should fail. */
-       if (cli_tdis(cli)) {
-               printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
+       status = cli_tdis(cli);
+       if (NT_STATUS_IS_OK(status)) {
+               d_printf("Second tdis with invalid vuid should fail - succeeded instead !.\n");
+               correct = false;
+               goto out;
        } else {
                /* Should be bad tid. */
                if (!check_error(__LINE__, cli, ERRSRV, ERRinvnid,
                                NT_STATUS_NETWORK_NAME_DELETED)) {
-                       return False;
+                       correct = false;
+                       goto out;
                }
        }
 
@@ -6111,30 +7072,40 @@ static bool run_uid_regression_test(int dummy)
 static const char *illegal_chars = "*\\/?<>|\":";
 static char force_shortname_chars[] = " +,.[];=\177";
 
-static void shortname_del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
+static NTSTATUS shortname_del_fn(const char *mnt, struct file_info *finfo,
+                            const char *mask, void *state)
 {
        struct cli_state *pcli = (struct cli_state *)state;
        fstring fname;
+       NTSTATUS status = NT_STATUS_OK;
+
        slprintf(fname, sizeof(fname), "\\shortname\\%s", finfo->name);
 
        if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
-               return;
+               return NT_STATUS_OK;
 
-       if (finfo->mode & aDIR) {
-               if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
+       if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
+               status = cli_rmdir(pcli, fname);
+               if (!NT_STATUS_IS_OK(status)) {
                        printf("del_fn: failed to rmdir %s\n,", fname );
+               }
        } else {
-               if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN)))
+               status = cli_unlink(pcli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+               if (!NT_STATUS_IS_OK(status)) {
                        printf("del_fn: failed to unlink %s\n,", fname );
+               }
        }
+       return status;
 }
 
 struct sn_state {
+       int matched;
        int i;
        bool val;
 };
 
-static void shortname_list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
+static NTSTATUS shortname_list_fn(const char *mnt, struct file_info *finfo,
+                             const char *name, void *state)
 {
        struct sn_state *s = (struct sn_state  *)state;
        int i = s->i;
@@ -6157,6 +7128,8 @@ static void shortname_list_fn(const char *mnt, file_info *finfo, const char *nam
                        __location__, finfo->short_name, finfo->name);
                s->val = true;
        }
+       s->matched += 1;
+       return NT_STATUS_OK;
 }
 
 static bool run_shortname_test(int dummy)
@@ -6166,6 +7139,7 @@ static bool run_shortname_test(int dummy)
        int i;
        struct sn_state s;
        char fname[20];
+       NTSTATUS status;
 
        printf("starting shortname test\n");
 
@@ -6176,12 +7150,13 @@ static bool run_shortname_test(int dummy)
        cli_sockopt(cli, sockops);
 
        cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
-       cli_list(cli, "\\shortname\\*", aDIR, shortname_del_fn, cli);
+       cli_list(cli, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY, shortname_del_fn, cli);
        cli_rmdir(cli, "\\shortname");
 
-       if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\shortname"))) {
+       status = cli_mkdir(cli, "\\shortname");
+       if (!NT_STATUS_IS_OK(status)) {
                d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
-                       __location__, cli_errstr(cli));
+                       __location__, nt_errstr(status));
                correct = false;
                goto out;
        }
@@ -6192,7 +7167,6 @@ static bool run_shortname_test(int dummy)
        s.val = false;
 
        for (i = 32; i < 128; i++) {
-               NTSTATUS status;
                uint16_t fnum = (uint16_t)-1;
 
                s.i = i;
@@ -6206,20 +7180,26 @@ static bool run_shortname_test(int dummy)
                                    FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum);
                if (!NT_STATUS_IS_OK(status)) {
                        d_printf("(%s) cli_nt_create of %s failed: %s\n",
-                               __location__, fname, cli_errstr(cli));
+                               __location__, fname, nt_errstr(status));
                        correct = false;
                        goto out;
                }
                cli_close(cli, fnum);
-               if (cli_list(cli, "\\shortname\\test*.*", 0, shortname_list_fn, &s) != 1) {
+
+               s.matched = 0;
+               cli_list(cli, "\\shortname\\test*.*", 0, shortname_list_fn,
+                        &s);
+               if (s.matched != 1) {
                        d_printf("(%s) failed to list %s: %s\n",
                                __location__, fname, cli_errstr(cli));
                        correct = false;
                        goto out;
                }
-               if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
+
+               status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+               if (!NT_STATUS_IS_OK(status)) {
                        d_printf("(%s) failed to delete %s: %s\n",
-                               __location__, fname, cli_errstr(cli));
+                               __location__, fname, nt_errstr(status));
                        correct = false;
                        goto out;
                }
@@ -6233,7 +7213,7 @@ static bool run_shortname_test(int dummy)
   out:
 
        cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
-       cli_list(cli, "\\shortname\\*", aDIR, shortname_del_fn, cli);
+       cli_list(cli, "\\shortname\\*", FILE_ATTRIBUTE_DIRECTORY, shortname_del_fn, cli);
        cli_rmdir(cli, "\\shortname");
        torture_close_connection(cli);
        return correct;
@@ -6272,6 +7252,7 @@ static bool run_tldap(int dummy)
        struct tevent_context *ev;
        struct tevent_req *req;
        char *basedn;
+       const char *filter;
 
        if (!resolve_name(host, &addr, 0, false)) {
                d_printf("could not find host %s\n", host);
@@ -6325,10 +7306,95 @@ static bool run_tldap(int dummy)
 
        TALLOC_FREE(req);
 
+       /* test search filters against rootDSE */
+       filter = "(&(|(name=samba)(nextRid<=10000000)(usnChanged>=10)(samba~=ambas)(!(name=s*m*a)))"
+                  "(|(name:=samba)(name:dn:2.5.13.5:=samba)(:dn:2.5.13.5:=samba)(!(name=*samba))))";
+
+       rc = tldap_search(ld, "", TLDAP_SCOPE_BASE, filter,
+                         NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0,
+                         talloc_tos(), NULL, NULL);
+       if (rc != TLDAP_SUCCESS) {
+               d_printf("tldap_search with complex filter failed: %s\n",
+                        tldap_errstr(talloc_tos(), ld, rc));
+               return false;
+       }
+
        TALLOC_FREE(ld);
        return true;
 }
 
+/* Torture test to ensure no regression of :
+https://bugzilla.samba.org/show_bug.cgi?id=7084
+*/
+
+static bool run_dir_createtime(int dummy)
+{
+       struct cli_state *cli;
+       const char *dname = "\\testdir";
+       const char *fname = "\\testdir\\testfile";
+       NTSTATUS status;
+       struct timespec create_time;
+       struct timespec create_time1;
+       uint16_t fnum;
+       bool ret = false;
+
+       if (!torture_open_connection(&cli, 0)) {
+               return false;
+       }
+
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       cli_rmdir(cli, dname);
+
+       status = cli_mkdir(cli, dname);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("mkdir failed: %s\n", nt_errstr(status));
+               goto out;
+       }
+
+       status = cli_qpathinfo2(cli, dname, &create_time, NULL, NULL, NULL,
+                               NULL, NULL, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_qpathinfo2 returned %s\n",
+                      nt_errstr(status));
+               goto out;
+       }
+
+       /* Sleep 3 seconds, then create a file. */
+       sleep(3);
+
+       status = cli_open(cli, fname, O_RDWR | O_CREAT | O_EXCL,
+                         DENY_NONE, &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_open failed: %s\n", nt_errstr(status));
+               goto out;
+       }
+
+       status = cli_qpathinfo2(cli, dname, &create_time1, NULL, NULL, NULL,
+                               NULL, NULL, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_qpathinfo2 (2) returned %s\n",
+                      nt_errstr(status));
+               goto out;
+       }
+
+       if (timespec_compare(&create_time1, &create_time)) {
+               printf("run_dir_createtime: create time was updated (error)\n");
+       } else {
+               printf("run_dir_createtime: create time was not updated (correct)\n");
+               ret = true;
+       }
+
+  out:
+
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       cli_rmdir(cli, dname);
+       if (!torture_close_connection(cli)) {
+               ret = false;
+       }
+       return ret;
+}
+
+
 static bool run_streamerror(int dummy)
 {
        struct cli_state *cli;
@@ -6345,6 +7411,7 @@ static bool run_streamerror(int dummy)
                return false;
        }
 
+       cli_unlink(cli, "\\testdir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        cli_rmdir(cli, dname);
 
        status = cli_mkdir(cli, dname);
@@ -6353,7 +7420,7 @@ static bool run_streamerror(int dummy)
                return false;
        }
 
-       cli_qpathinfo(cli, streamname, &change_time, &access_time, &write_time,
+       cli_qpathinfo1(cli, streamname, &change_time, &access_time, &write_time,
                      &size, &mode);
        status = cli_nt_error(cli);
 
@@ -6613,6 +7680,103 @@ static bool run_local_rbtree(int dummy)
        return ret;
 }
 
+
+/*
+  local test for character set functions
+
+  This is a very simple test for the functionality in convert_string_error()
+ */
+static bool run_local_convert_string(int dummy)
+{
+       TALLOC_CTX *tmp_ctx = talloc_new(NULL);
+       const char *test_strings[2] = { "March", "M\303\244rz" };
+       char dst[7];
+       int i;
+
+       for (i=0; i<2; i++) {
+               const char *str = test_strings[i];
+               int len = strlen(str);
+               size_t converted_size;
+               bool ret;
+
+               memset(dst, 'X', sizeof(dst));
+
+               /* first try with real source length */
+               ret = convert_string_error(CH_UNIX, CH_UTF8,
+                                          str, len,
+                                          dst, sizeof(dst),
+                                          &converted_size);
+               if (ret != true) {
+                       d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
+                       goto failed;
+               }
+
+               if (converted_size != len) {
+                       d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
+                                 str, len, (int)converted_size);
+                       goto failed;
+               }
+
+               if (strncmp(str, dst, converted_size) != 0) {
+                       d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
+                       goto failed;
+               }
+
+               if (strlen(str) != converted_size) {
+                       d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
+                                 (int)strlen(str), (int)converted_size);
+                       goto failed;
+               }
+
+               if (dst[converted_size] != 'X') {
+                       d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
+                       goto failed;
+               }
+
+               /* now with srclen==-1, this causes the nul to be
+                * converted too */
+               ret = convert_string_error(CH_UNIX, CH_UTF8,
+                                          str, -1,
+                                          dst, sizeof(dst),
+                                          &converted_size);
+               if (ret != true) {
+                       d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
+                       goto failed;
+               }
+
+               if (converted_size != len+1) {
+                       d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
+                                 str, len, (int)converted_size);
+                       goto failed;
+               }
+
+               if (strncmp(str, dst, converted_size) != 0) {
+                       d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
+                       goto failed;
+               }
+
+               if (len+1 != converted_size) {
+                       d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
+                                 len+1, (int)converted_size);
+                       goto failed;
+               }
+
+               if (dst[converted_size] != 'X') {
+                       d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
+                       goto failed;
+               }
+
+       }
+
+
+       TALLOC_FREE(tmp_ctx);
+       return true;
+failed:
+       TALLOC_FREE(tmp_ctx);
+       return false;
+}
+
+
 struct talloc_dict_test {
        int content;
 };
@@ -6660,6 +7824,134 @@ static bool run_local_talloc_dict(int dummy)
        return true;
 }
 
+static bool run_local_string_to_sid(int dummy) {
+       struct dom_sid sid;
+
+       if (string_to_sid(&sid, "S--1-5-32-545")) {
+               printf("allowing S--1-5-32-545\n");
+               return false;
+       }
+       if (string_to_sid(&sid, "S-1-5-32-+545")) {
+               printf("allowing S-1-5-32-+545\n");
+               return false;
+       }
+       if (string_to_sid(&sid, "S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0")) {
+               printf("allowing S-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6-7-8-9-0\n");
+               return false;
+       }
+       if (string_to_sid(&sid, "S-1-5-32-545-abc")) {
+               printf("allowing S-1-5-32-545-abc\n");
+               return false;
+       }
+       if (!string_to_sid(&sid, "S-1-5-32-545")) {
+               printf("could not parse S-1-5-32-545\n");
+               return false;
+       }
+       if (!dom_sid_equal(&sid, &global_sid_Builtin_Users)) {
+               printf("mis-parsed S-1-5-32-545 as %s\n",
+                      sid_string_tos(&sid));
+               return false;
+       }
+       return true;
+}
+
+static bool run_local_binary_to_sid(int dummy) {
+       struct dom_sid *sid = talloc(NULL, struct dom_sid);
+       static const char good_binary_sid[] = {
+               0x1, /* revision number */
+               15, /* num auths */
+               0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
+               0x1, 0x1, 0x1, 0x1, /* auth[0] */
+               0x1, 0x1, 0x1, 0x1, /* auth[1] */
+               0x1, 0x1, 0x1, 0x1, /* auth[2] */
+               0x1, 0x1, 0x1, 0x1, /* auth[3] */
+               0x1, 0x1, 0x1, 0x1, /* auth[4] */
+               0x1, 0x1, 0x1, 0x1, /* auth[5] */
+               0x1, 0x1, 0x1, 0x1, /* auth[6] */
+               0x1, 0x1, 0x1, 0x1, /* auth[7] */
+               0x1, 0x1, 0x1, 0x1, /* auth[8] */
+               0x1, 0x1, 0x1, 0x1, /* auth[9] */
+               0x1, 0x1, 0x1, 0x1, /* auth[10] */
+               0x1, 0x1, 0x1, 0x1, /* auth[11] */
+               0x1, 0x1, 0x1, 0x1, /* auth[12] */
+               0x1, 0x1, 0x1, 0x1, /* auth[13] */
+               0x1, 0x1, 0x1, 0x1, /* auth[14] */
+       };
+
+       static const char long_binary_sid[] = {
+               0x1, /* revision number */
+               15, /* num auths */
+               0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
+               0x1, 0x1, 0x1, 0x1, /* auth[0] */
+               0x1, 0x1, 0x1, 0x1, /* auth[1] */
+               0x1, 0x1, 0x1, 0x1, /* auth[2] */
+               0x1, 0x1, 0x1, 0x1, /* auth[3] */
+               0x1, 0x1, 0x1, 0x1, /* auth[4] */
+               0x1, 0x1, 0x1, 0x1, /* auth[5] */
+               0x1, 0x1, 0x1, 0x1, /* auth[6] */
+               0x1, 0x1, 0x1, 0x1, /* auth[7] */
+               0x1, 0x1, 0x1, 0x1, /* auth[8] */
+               0x1, 0x1, 0x1, 0x1, /* auth[9] */
+               0x1, 0x1, 0x1, 0x1, /* auth[10] */
+               0x1, 0x1, 0x1, 0x1, /* auth[11] */
+               0x1, 0x1, 0x1, 0x1, /* auth[12] */
+               0x1, 0x1, 0x1, 0x1, /* auth[13] */
+               0x1, 0x1, 0x1, 0x1, /* auth[14] */
+               0x1, 0x1, 0x1, 0x1, /* auth[15] */
+               0x1, 0x1, 0x1, 0x1, /* auth[16] */
+               0x1, 0x1, 0x1, 0x1, /* auth[17] */
+       };
+
+       static const char long_binary_sid2[] = {
+               0x1, /* revision number */
+               32, /* num auths */
+               0x1, 0x1, 0x1, 0x1, 0x1, 0x1, /* id_auth */
+               0x1, 0x1, 0x1, 0x1, /* auth[0] */
+               0x1, 0x1, 0x1, 0x1, /* auth[1] */
+               0x1, 0x1, 0x1, 0x1, /* auth[2] */
+               0x1, 0x1, 0x1, 0x1, /* auth[3] */
+               0x1, 0x1, 0x1, 0x1, /* auth[4] */
+               0x1, 0x1, 0x1, 0x1, /* auth[5] */
+               0x1, 0x1, 0x1, 0x1, /* auth[6] */
+               0x1, 0x1, 0x1, 0x1, /* auth[7] */
+               0x1, 0x1, 0x1, 0x1, /* auth[8] */
+               0x1, 0x1, 0x1, 0x1, /* auth[9] */
+               0x1, 0x1, 0x1, 0x1, /* auth[10] */
+               0x1, 0x1, 0x1, 0x1, /* auth[11] */
+               0x1, 0x1, 0x1, 0x1, /* auth[12] */
+               0x1, 0x1, 0x1, 0x1, /* auth[13] */
+               0x1, 0x1, 0x1, 0x1, /* auth[14] */
+               0x1, 0x1, 0x1, 0x1, /* auth[15] */
+               0x1, 0x1, 0x1, 0x1, /* auth[16] */
+               0x1, 0x1, 0x1, 0x1, /* auth[17] */
+               0x1, 0x1, 0x1, 0x1, /* auth[18] */
+               0x1, 0x1, 0x1, 0x1, /* auth[19] */
+               0x1, 0x1, 0x1, 0x1, /* auth[20] */
+               0x1, 0x1, 0x1, 0x1, /* auth[21] */
+               0x1, 0x1, 0x1, 0x1, /* auth[22] */
+               0x1, 0x1, 0x1, 0x1, /* auth[23] */
+               0x1, 0x1, 0x1, 0x1, /* auth[24] */
+               0x1, 0x1, 0x1, 0x1, /* auth[25] */
+               0x1, 0x1, 0x1, 0x1, /* auth[26] */
+               0x1, 0x1, 0x1, 0x1, /* auth[27] */
+               0x1, 0x1, 0x1, 0x1, /* auth[28] */
+               0x1, 0x1, 0x1, 0x1, /* auth[29] */
+               0x1, 0x1, 0x1, 0x1, /* auth[30] */
+               0x1, 0x1, 0x1, 0x1, /* auth[31] */
+       };
+
+       if (!sid_parse(good_binary_sid, sizeof(good_binary_sid), sid)) {
+               return false;
+       }
+       if (sid_parse(long_binary_sid2, sizeof(long_binary_sid2), sid)) {
+               return false;
+       }
+       if (sid_parse(long_binary_sid, sizeof(long_binary_sid), sid)) {
+               return false;
+       }
+       return true;
+}
+
 /* Split a path name into filename and stream name components. Canonicalise
  * such that an implicit $DATA token is always explicit.
  *
@@ -6702,7 +7994,7 @@ static NTSTATUS split_ntfs_stream_name(TALLOC_CTX *mem_ctx, const char *fname,
                stype = "$DATA";
        }
        else {
-               if (StrCaseCmp(stype, ":$DATA") != 0) {
+               if (strcasecmp_m(stype, ":$DATA") != 0) {
                        /*
                         * If there is an explicit stream type, so far we only
                         * allow $DATA. Is there anything else allowed? -- vl
@@ -6782,7 +8074,7 @@ static bool test_stream_name(const char *fname, const char *expected_base,
        return true;
 
  error:
-       d_fprintf(stderr, "test_stream(%s, %s, %s, %s)\n",
+       d_fprintf(stderr, "Do test_stream(%s, %s, %s, %s)\n",
                  fname, expected_base ? expected_base : "<NULL>",
                  expected_stream ? expected_stream : "<NULL>",
                  nt_errstr(expected_status));
@@ -7029,7 +8321,7 @@ static bool run_getaddrinfo_send(int dummy)
                        goto fail;
                }
                tevent_req_set_callback(reqs[i], getaddrinfo_finished,
-                                       (void *)names[i]);
+                                       discard_const_p(void, names[i]));
        }
 
        for (i=0; i<ARRAY_SIZE(reqs); i++) {
@@ -7042,6 +8334,177 @@ fail:
        return result;
 }
 
+static bool dbtrans_inc(struct db_context *db)
+{
+       struct db_record *rec;
+       uint32_t *val;
+       bool ret = false;
+       NTSTATUS status;
+
+       rec = db->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)) {
+               printf(__location__ "value.dsize = %d\n",
+                      (int)rec->value.dsize);
+               goto fail;
+       }
+
+       val = (uint32_t *)rec->value.dptr;
+       *val += 1;
+
+       status = rec->store(rec, make_tdb_data((uint8_t *)val,
+                                              sizeof(uint32_t)),
+                           0);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf(__location__ "store failed: %s\n",
+                      nt_errstr(status));
+               goto fail;
+       }
+
+       ret = true;
+fail:
+       TALLOC_FREE(rec);
+       return ret;
+}
+
+static bool run_local_dbtrans(int dummy)
+{
+       struct db_context *db;
+       struct db_record *rec;
+       NTSTATUS status;
+       uint32_t initial;
+       int res;
+
+       db = db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT,
+                    O_RDWR|O_CREAT, 0600);
+       if (db == NULL) {
+               printf("Could not open transtest.db\n");
+               return false;
+       }
+
+       res = db->transaction_start(db);
+       if (res == -1) {
+               printf(__location__ "transaction_start failed\n");
+               return false;
+       }
+
+       rec = db->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) {
+               initial = 0;
+               status = rec->store(
+                       rec, make_tdb_data((uint8_t *)&initial,
+                                          sizeof(initial)),
+                       0);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf(__location__ "store returned %s\n",
+                              nt_errstr(status));
+                       return false;
+               }
+       }
+
+       TALLOC_FREE(rec);
+
+       res = db->transaction_commit(db);
+       if (res == -1) {
+               printf(__location__ "transaction_commit failed\n");
+               return false;
+       }
+
+       while (true) {
+               uint32_t val, val2;
+               int i;
+
+               res = db->transaction_start(db);
+               if (res == -1) {
+                       printf(__location__ "transaction_start failed\n");
+                       break;
+               }
+
+               if (!dbwrap_fetch_uint32(db, "transtest", &val)) {
+                       printf(__location__ "dbwrap_fetch_uint32 failed\n");
+                       break;
+               }
+
+               for (i=0; i<10; i++) {
+                       if (!dbtrans_inc(db)) {
+                               return false;
+                       }
+               }
+
+               if (!dbwrap_fetch_uint32(db, "transtest", &val2)) {
+                       printf(__location__ "dbwrap_fetch_uint32 failed\n");
+                       break;
+               }
+
+               if (val2 != val + 10) {
+                       printf(__location__ "val=%d, val2=%d\n",
+                              (int)val, (int)val2);
+                       break;
+               }
+
+               printf("val2=%d\r", val2);
+
+               res = db->transaction_commit(db);
+               if (res == -1) {
+                       printf(__location__ "transaction_commit failed\n");
+                       break;
+               }
+       }
+
+       TALLOC_FREE(db);
+       return true;
+}
+
+/*
+ * Just a dummy test to be run under a debugger. There's no real way
+ * to inspect the tevent_select specific function from outside of
+ * tevent_select.c.
+ */
+
+static bool run_local_tevent_select(int dummy)
+{
+       struct tevent_context *ev;
+       struct tevent_fd *fd1, *fd2;
+       bool result = false;
+
+       ev = tevent_context_init_byname(NULL, "select");
+       if (ev == NULL) {
+               d_fprintf(stderr, "tevent_context_init_byname failed\n");
+               goto fail;
+       }
+
+       fd1 = tevent_add_fd(ev, ev, 2, 0, NULL, NULL);
+       if (fd1 == NULL) {
+               d_fprintf(stderr, "tevent_add_fd failed\n");
+               goto fail;
+       }
+       fd2 = tevent_add_fd(ev, ev, 3, 0, NULL, NULL);
+       if (fd2 == NULL) {
+               d_fprintf(stderr, "tevent_add_fd failed\n");
+               goto fail;
+       }
+       TALLOC_FREE(fd2);
+
+       fd2 = tevent_add_fd(ev, ev, 1, 0, NULL, NULL);
+       if (fd2 == NULL) {
+               d_fprintf(stderr, "tevent_add_fd failed\n");
+               goto fail;
+       }
+
+       result = true;
+fail:
+       TALLOC_FREE(ev);
+       return result;
+}
 
 static double create_procs(bool (*fn)(int), bool *result)
 {
@@ -7050,6 +8513,7 @@ static double create_procs(bool (*fn)(int), bool *result)
        volatile bool *child_status_out;
        int synccount;
        int tries = 8;
+       struct timeval start;
 
        synccount = 0;
 
@@ -7070,7 +8534,7 @@ static double create_procs(bool (*fn)(int), bool *result)
                child_status_out[i] = True;
        }
 
-       start_timer();
+       start = timeval_current();
 
        for (i=0;i<nprocs;i++) {
                procnum = i;
@@ -7091,7 +8555,7 @@ static double create_procs(bool (*fn)(int), bool *result)
 
                        child_status[i] = getpid();
 
-                       while (child_status[i] && end_timer() < 5) smb_msleep(2);
+                       while (child_status[i] && timeval_elapsed(&start) < 5) smb_msleep(2);
 
                        child_status_out[i] = fn(i);
                        _exit(0);
@@ -7105,16 +8569,16 @@ static double create_procs(bool (*fn)(int), bool *result)
                }
                if (synccount == nprocs) break;
                smb_msleep(10);
-       } while (end_timer() < 30);
+       } while (timeval_elapsed(&start) < 30);
 
        if (synccount != nprocs) {
                printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
                *result = False;
-               return end_timer();
+               return timeval_elapsed(&start);
        }
 
        /* start the client load */
-       start_timer();
+       start = timeval_current();
 
        for (i=0;i<nprocs;i++) {
                child_status[i] = 0;
@@ -7133,7 +8597,7 @@ static double create_procs(bool (*fn)(int), bool *result)
                        *result = False;
                }
        }
-       return end_timer();
+       return timeval_elapsed(&start);
 }
 
 #define FLAG_MULTIPROC 1
@@ -7162,11 +8626,13 @@ static struct {
        {"RANDOMIPC", run_randomipc, 0},
        {"NEGNOWAIT", run_negprot_nowait, 0},
        {"NBENCH",  run_nbench, 0},
+       {"NBENCH2", run_nbench2, 0},
        {"OPLOCK1",  run_oplock1, 0},
        {"OPLOCK2",  run_oplock2, 0},
-       {"OPLOCK3",  run_oplock3, 0},
+       {"OPLOCK4",  run_oplock4, 0},
        {"DIR",  run_dirtest, 0},
        {"DIR1",  run_dirtest1, 0},
+       {"DIR-CREATETIME",  run_dir_createtime, 0},
        {"DENY1",  torture_denytest1, 0},
        {"DENY2",  torture_denytest2, 0},
        {"TCON",  run_tcon_test, 0},
@@ -7174,16 +8640,22 @@ static struct {
        {"RW1",  run_readwritetest, 0},
        {"RW2",  run_readwritemulti, FLAG_MULTIPROC},
        {"RW3",  run_readwritelarge, 0},
+       {"RW-SIGNING",  run_readwritelarge_signtest, 0},
        {"OPEN", run_opentest, 0},
        {"POSIX", run_simple_posix_open_test, 0},
+       {"POSIX-APPEND", run_posix_append, 0},
+       {"CASE-INSENSITIVE-CREATE", run_case_insensitive_create, 0},
+       {"ASYNC-ECHO", run_async_echo, 0},
        { "UID-REGRESSION-TEST", run_uid_regression_test, 0},
        { "SHORTNAME-TEST", run_shortname_test, 0},
+       { "ADDRCHANGE", run_addrchange, 0},
 #if 1
        {"OPENATTR", run_openattrtest, 0},
 #endif
        {"XCOPY", run_xcopy, 0},
        {"RENAME", run_rename, 0},
        {"DELETE", run_deletetest, 0},
+       {"DELETE-LN", run_deletetest_ln, 0},
        {"PROPERTIES", run_properties, 0},
        {"MANGLE", torture_mangle, 0},
        {"MANGLE1", run_mangle1, 0},
@@ -7208,6 +8680,9 @@ static struct {
        { "TLDAP", run_tldap },
        { "STREAMERROR", run_streamerror },
        { "NOTIFY-BENCH", run_notify_bench },
+       { "BAD-NBT-SESSION", run_bad_nbt_session },
+       { "SMB-ANY-CONNECT", run_smb_any_connect },
+       { "NOTIFY-ONLINE", run_notify_online },
        { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
        { "LOCAL-GENCACHE", run_local_gencache, 0},
        { "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
@@ -7216,6 +8691,11 @@ static struct {
        { "LOCAL-MEMCACHE", run_local_memcache, 0},
        { "LOCAL-STREAM-NAME", run_local_stream_name, 0},
        { "LOCAL-WBCLIENT", run_local_wbclient, 0},
+       { "LOCAL-string_to_sid", run_local_string_to_sid, 0},
+       { "LOCAL-binary_to_sid", run_local_binary_to_sid, 0},
+       { "LOCAL-DBTRANS", run_local_dbtrans, 0},
+       { "LOCAL-TEVENT-SELECT", run_local_tevent_select, 0},
+       { "LOCAL-CONVERT-STRING", run_local_convert_string, 0},
        {NULL, NULL, 0}};
 
 
@@ -7251,12 +8731,13 @@ static bool run_test(const char *name)
                                        printf("TEST %s FAILED!\n", name);
                                }
                        } else {
-                               start_timer();
+                               struct timeval start;
+                               start = timeval_current();
                                if (!torture_ops[i].fn(0)) {
                                        ret = False;
                                        printf("TEST %s FAILED!\n", name);
                                }
-                               t = end_timer();
+                               t = timeval_elapsed(&start);
                        }
                        printf("%s took %g secs\n\n", name, t);
                }
@@ -7295,6 +8776,7 @@ static void usage(void)
        printf("\t-p port\n");
        printf("\t-s seed\n");
        printf("\t-b unclist_filename   specify multiple shares for multiple connections\n");
+       printf("\t-f filename   filename to test\n");
        printf("\n\n");
 
        printf("tests are:");
@@ -7321,12 +8803,12 @@ static void usage(void)
        TALLOC_CTX *frame = talloc_stackframe();
        int seed = time(NULL);
 
-       dbf = x_stdout;
-
 #ifdef HAVE_SETBUFFER
        setbuffer(stdout, NULL, 0);
 #endif
 
+       setup_logging("smbtorture", DEBUG_STDOUT);
+
        load_case_tables();
 
        if (is_default_dyn_CONFIGFILE()) {
@@ -7372,7 +8854,8 @@ static void usage(void)
 
        fstrcpy(workgroup, lp_workgroup());
 
-       while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:")) != EOF) {
+       while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:f:"))
+              != EOF) {
                switch (opt) {
                case 'p':
                        port_to_use = atoi(optarg);
@@ -7393,7 +8876,7 @@ static void usage(void)
                        torture_numops = atoi(optarg);
                        break;
                case 'd':
-                       DEBUGLEVEL = atoi(optarg);
+                       lp_set_cmdline("log level", optarg);
                        break;
                case 'O':
                        sockops = optarg;
@@ -7441,6 +8924,9 @@ static void usage(void)
                case 'B':
                        torture_blocksize = atoi(optarg);
                        break;
+               case 'f':
+                       test_filename = SMB_STRDUP(optarg);
+                       break;
                default:
                        printf("Unknown option %c (%d)\n", (char)opt, opt);
                        usage();