Add a test showing what ascii values cause an NTFS volume to
[ira/wip.git] / source3 / torture / torture.c
index 07945fccf1f9b5301c2bfaa588a8cafe150f2da4..99bf3785b6967912bb47eaa7b4a10441edfa6d96 100644 (file)
@@ -2,17 +2,17 @@
    Unix SMB/CIFS implementation.
    SMB torture tester
    Copyright (C) Andrew Tridgell 1997-1998
-   
+
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@@ -94,7 +94,7 @@ void *shm_setup(int size)
           See Stevens "advanced programming in unix env" for details
           */
        shmctl(shmid, IPC_RMID, 0);
-       
+
        return ret;
 }
 
@@ -226,7 +226,7 @@ terminate_path_at_separator(char * path)
                *p = '\0';
                return p + 1;
        }
-       
+
        /* No separator. */
        return NULL;
 }
@@ -419,25 +419,26 @@ static bool rw_torture(struct cli_state *c)
 {
        const char *lockfname = "\\torture.lck";
        fstring fname;
-       int fnum;
-       int fnum2;
+       uint16_t fnum;
+       uint16_t fnum2;
        pid_t pid2, pid = getpid();
        int i, j;
        char buf[1024];
        bool correct = True;
+       NTSTATUS status;
 
        memset(buf, '\0', sizeof(buf));
 
-       fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL, 
-                        DENY_NONE);
-       if (fnum2 == -1)
-               fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
-       if (fnum2 == -1) {
+       status = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL, 
+                        DENY_NONE, &fnum2);
+       if (!NT_STATUS_IS_OK(status)) {
+               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));
                return False;
        }
 
-
        for (i=0;i<torture_numops;i++) {
                unsigned n = (unsigned)sys_random()%10;
                if (i % 10 == 0) {
@@ -449,8 +450,7 @@ static bool rw_torture(struct cli_state *c)
                        return False;
                }
 
-               fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
-               if (fnum == -1) {
+               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));
                        correct = False;
                        break;
@@ -482,12 +482,12 @@ static bool rw_torture(struct cli_state *c)
                        correct = False;
                }
 
-               if (!cli_close(c, fnum)) {
+               if (!NT_STATUS_IS_OK(cli_close(c, fnum))) {
                        printf("close failed (%s)\n", cli_errstr(c));
                        correct = False;
                }
 
-               if (!cli_unlink(c, fname)) {
+               if (!NT_STATUS_IS_OK(cli_unlink(c, fname, aSYSTEM | aHIDDEN))) {
                        printf("unlink failed (%s)\n", cli_errstr(c));
                        correct = False;
                }
@@ -499,7 +499,7 @@ static bool rw_torture(struct cli_state *c)
        }
 
        cli_close(c, fnum2);
-       cli_unlink(c, lockfname);
+       cli_unlink(c, lockfname, aSYSTEM | aHIDDEN);
 
        printf("%d\n", i);
 
@@ -516,7 +516,7 @@ static bool run_torture(int dummy)
        cli_sockopt(cli, sockops);
 
        ret = rw_torture(cli);
-       
+
        if (!torture_close_connection(cli)) {
                ret = False;
        }
@@ -526,7 +526,7 @@ static bool run_torture(int dummy)
 
 static bool rw_torture3(struct cli_state *c, char *lockfname)
 {
-       int fnum = -1;
+       uint16_t fnum = (uint16_t)-1;
        unsigned int i = 0;
        char buf[131072];
        char buf_rd[131072];
@@ -534,6 +534,7 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
        unsigned countprev = 0;
        ssize_t sent = 0;
        bool correct = True;
+       NTSTATUS status;
 
        srandom(1);
        for (i = 0; i < sizeof(buf); i += sizeof(uint32))
@@ -543,9 +544,8 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
 
        if (procnum == 0)
        {
-               fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL, 
-                                DENY_NONE);
-               if (fnum == -1) {
+               if (!NT_STATUS_IS_OK(cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL, 
+                                DENY_NONE, &fnum))) {
                        printf("first open read/write of %s failed (%s)\n",
                                        lockfname, cli_errstr(c));
                        return False;
@@ -553,13 +553,16 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
        }
        else
        {
-               for (i = 0; i < 500 && fnum == -1; i++)
+               for (i = 0; i < 500 && fnum == (uint16_t)-1; i++)
                {
-                       fnum = cli_open(c, lockfname, O_RDONLY, 
-                                        DENY_NONE);
+                       status = cli_open(c, lockfname, O_RDONLY, 
+                                        DENY_NONE, &fnum);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               break;
+                       }
                        smb_msleep(10);
                }
-               if (fnum == -1) {
+               if (!NT_STATUS_IS_OK(status)) {
                        printf("second open read-only of %s failed (%s)\n",
                                        lockfname, cli_errstr(c));
                        return False;
@@ -615,7 +618,7 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
 
        }
 
-       if (!cli_close(c, fnum)) {
+       if (!NT_STATUS_IS_OK(cli_close(c, fnum))) {
                printf("close failed (%s)\n", cli_errstr(c));
                correct = False;
        }
@@ -626,28 +629,26 @@ static bool rw_torture3(struct cli_state *c, char *lockfname)
 static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
 {
        const char *lockfname = "\\torture2.lck";
-       int fnum1;
-       int fnum2;
+       uint16_t fnum1;
+       uint16_t fnum2;
        int i;
        char buf[131072];
        char buf_rd[131072];
        bool correct = True;
        ssize_t bytes_read;
 
-       if (!cli_unlink(c1, lockfname)) {
+       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));
        }
 
-       fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL, 
-                        DENY_NONE);
-       if (fnum1 == -1) {
+       if (!NT_STATUS_IS_OK(cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL, 
+                        DENY_NONE, &fnum1))) {
                printf("first open read/write of %s failed (%s)\n",
                                lockfname, cli_errstr(c1));
                return False;
        }
-       fnum2 = cli_open(c2, lockfname, O_RDONLY, 
-                        DENY_NONE);
-       if (fnum2 == -1) {
+       if (!NT_STATUS_IS_OK(cli_open(c2, lockfname, O_RDONLY, 
+                        DENY_NONE, &fnum2))) {
                printf("second open read-only of %s failed (%s)\n",
                                lockfname, cli_errstr(c2));
                cli_close(c1, fnum1);
@@ -685,16 +686,16 @@ static bool rw_torture2(struct cli_state *c1, struct cli_state *c2)
                }
        }
 
-       if (!cli_close(c2, fnum2)) {
+       if (!NT_STATUS_IS_OK(cli_close(c2, fnum2))) {
                printf("close failed (%s)\n", cli_errstr(c2));
                correct = False;
        }
-       if (!cli_close(c1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(c1, fnum1))) {
                printf("close failed (%s)\n", cli_errstr(c1));
                correct = False;
        }
 
-       if (!cli_unlink(c1, lockfname)) {
+       if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, aSYSTEM | aHIDDEN))) {
                printf("unlink failed (%s)\n", cli_errstr(c1));
                correct = False;
        }
@@ -749,37 +750,36 @@ static bool run_readwritemulti(int dummy)
        if (!torture_close_connection(cli)) {
                test = False;
        }
-       
+
        return test;
 }
 
 static bool run_readwritelarge(int dummy)
 {
        static struct cli_state *cli1;
-       int fnum1;
+       uint16_t fnum1;
        const char *lockfname = "\\large.dat";
        SMB_OFF_T fsize;
        char buf[126*1024];
        bool correct = True;
+
        if (!torture_open_connection(&cli1, 0)) {
                return False;
        }
        cli_sockopt(cli1, sockops);
        memset(buf,'\0',sizeof(buf));
-       
+
        cli1->max_xmit = 128*1024;
-       
+
        printf("starting readwritelarge\n");
-       cli_unlink(cli1, lockfname);
 
-       fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
-       if (fnum1 == -1) {
+       cli_unlink(cli1, lockfname, aSYSTEM | aHIDDEN);
+
+       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));
                return False;
        }
-   
+
        cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
 
        if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
@@ -796,26 +796,25 @@ static bool run_readwritelarge(int dummy)
                correct = False;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close failed (%s)\n", cli_errstr(cli1));
                correct = False;
        }
 
-       if (!cli_unlink(cli1, lockfname)) {
+       if (!NT_STATUS_IS_OK(cli_unlink(cli1, lockfname, aSYSTEM | aHIDDEN))) {
                printf("unlink failed (%s)\n", cli_errstr(cli1));
                correct = False;
        }
 
-       fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
-       if (fnum1 == -1) {
+       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));
                return False;
        }
-       
+
        cli1->max_xmit = 4*1024;
-       
+
        cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
-       
+
        if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
                printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
                correct = False;
@@ -844,11 +843,11 @@ static bool run_readwritelarge(int dummy)
                printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
 #endif
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close failed (%s)\n", cli_errstr(cli1));
                correct = False;
        }
-       
+
        if (!torture_close_connection(cli1)) {
                correct = False;
        }
@@ -953,7 +952,7 @@ static bool run_netbench(int client)
        if (!torture_close_connection(cli)) {
                correct = False;
        }
-       
+
        return correct;
 }
 
@@ -990,7 +989,7 @@ static bool run_locktest1(int dummy)
 {
        struct cli_state *cli1, *cli2;
        const char *fname = "\\lockt1.lck";
-       int fnum1, fnum2, fnum3;
+       uint16_t fnum1, fnum2, fnum3;
        time_t t1, t2;
        unsigned lock_timeout;
 
@@ -1002,20 +1001,17 @@ static bool run_locktest1(int dummy)
 
        printf("starting locktest1\n");
 
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
-       fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum1 == -1) {
+       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));
                return False;
        }
-       fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
-       if (fnum2 == -1) {
+       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));
                return False;
        }
-       fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
-       if (fnum3 == -1) {
+       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));
                return False;
        }
@@ -1054,7 +1050,7 @@ 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 (!cli_close(cli1, fnum2)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
                printf("close1 failed (%s)\n", cli_errstr(cli1));
                return False;
        }
@@ -1067,17 +1063,17 @@ static bool run_locktest1(int dummy)
                                 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close2 failed (%s)\n", cli_errstr(cli1));
                return False;
        }
 
-       if (!cli_close(cli2, fnum3)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli2, fnum3))) {
                printf("close3 failed (%s)\n", cli_errstr(cli2));
                return False;
        }
 
-       if (!cli_unlink(cli1, fname)) {
+       if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
                printf("unlink failed (%s)\n", cli_errstr(cli1));
                return False;
        }
@@ -1103,7 +1099,7 @@ static bool run_tcon_test(int dummy)
 {
        static struct cli_state *cli;
        const char *fname = "\\tcontest.tmp";
-       int fnum1;
+       uint16 fnum1;
        uint16 cnum1, cnum2, cnum3;
        uint16 vuid1, vuid2;
        char buf[4];
@@ -1119,10 +1115,9 @@ static bool run_tcon_test(int dummy)
 
        printf("starting tcontest\n");
 
-       cli_unlink(cli, fname);
+       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
 
-       fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum1 == -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));
                return False;
        }
@@ -1183,7 +1178,7 @@ static bool run_tcon_test(int dummy)
        cli->cnum = cnum1;
        cli->vuid = vuid1;
 
-       if (!cli_close(cli, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli, fnum1))) {
                printf("close failed (%s)\n", cli_errstr(cli));
                return False;
        }
@@ -1324,7 +1319,7 @@ static bool run_tcon_devtype_test(int dummy)
 
        if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
                ret = False;
-                       
+
        if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
                ret = False;
 
@@ -1339,7 +1334,7 @@ static bool run_tcon_devtype_test(int dummy)
 
        if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
                ret = False;
-                       
+
        if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
                ret = False;
 
@@ -1367,7 +1362,7 @@ static bool run_locktest2(int dummy)
 {
        static struct cli_state *cli;
        const char *fname = "\\lockt2.lck";
-       int fnum1, fnum2, fnum3;
+       uint16_t fnum1, fnum2, fnum3;
        bool correct = True;
 
        if (!torture_open_connection(&cli, 0)) {
@@ -1378,26 +1373,23 @@ static bool run_locktest2(int dummy)
 
        printf("starting locktest2\n");
 
-       cli_unlink(cli, fname);
+       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
 
        cli_setpid(cli, 1);
 
-       fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum1 == -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));
                return False;
        }
 
-       fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
-       if (fnum2 == -1) {
+       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));
                return False;
        }
 
        cli_setpid(cli, 2);
 
-       fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
-       if (fnum3 == -1) {
+       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));
                return False;
        }
@@ -1469,17 +1461,17 @@ static bool run_locktest2(int dummy)
 
        cli_setpid(cli, 1);
 
-       if (!cli_close(cli, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli, fnum1))) {
                printf("close1 failed (%s)\n", cli_errstr(cli));
                return False;
        }
 
-       if (!cli_close(cli, fnum2)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli, fnum2))) {
                printf("close2 failed (%s)\n", cli_errstr(cli));
                return False;
        }
 
-       if (!cli_close(cli, fnum3)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli, fnum3))) {
                printf("close3 failed (%s)\n", cli_errstr(cli));
                return False;
        }
@@ -1503,7 +1495,8 @@ static bool run_locktest3(int dummy)
 {
        static struct cli_state *cli1, *cli2;
        const char *fname = "\\lockt3.lck";
-       int fnum1, fnum2, i;
+       uint16_t fnum1, fnum2;
+       int i;
        uint32 offset;
        bool correct = True;
 
@@ -1517,15 +1510,13 @@ static bool run_locktest3(int dummy)
 
        printf("starting locktest3\n");
 
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
-       fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum1 == -1) {
+       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));
                return False;
        }
-       fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
-       if (fnum2 == -1) {
+       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));
                return False;
        }
@@ -1589,17 +1580,17 @@ static bool run_locktest3(int dummy)
                }
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close1 failed (%s)\n", cli_errstr(cli1));
                return False;
        }
 
-       if (!cli_close(cli2, fnum2)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
                printf("close2 failed (%s)\n", cli_errstr(cli2));
                return False;
        }
 
-       if (!cli_unlink(cli1, fname)) {
+       if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
                printf("unlink failed (%s)\n", cli_errstr(cli1));
                return False;
        }
@@ -1607,7 +1598,7 @@ static bool run_locktest3(int dummy)
        if (!torture_close_connection(cli1)) {
                correct = False;
        }
-       
+
        if (!torture_close_connection(cli2)) {
                correct = False;
        }
@@ -1628,7 +1619,7 @@ static bool run_locktest4(int dummy)
 {
        static struct cli_state *cli1, *cli2;
        const char *fname = "\\lockt4.lck";
-       int fnum1, fnum2, f;
+       uint16_t fnum1, fnum2, f;
        bool ret;
        char buf[1000];
        bool correct = True;
@@ -1642,10 +1633,10 @@ static bool run_locktest4(int dummy)
 
        printf("starting locktest4\n");
 
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
-       fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
+       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));
 
@@ -1659,7 +1650,7 @@ static bool run_locktest4(int dummy)
              cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
        EXPECTED(ret, False);
        printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
-           
+
        ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
              cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
        EXPECTED(ret, True);
@@ -1669,17 +1660,17 @@ static bool run_locktest4(int dummy)
              cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
        EXPECTED(ret, False);
        printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
-           
+
        ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
              cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
        EXPECTED(ret, True);
        printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
-       
+
        ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
              (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
        EXPECTED(ret, False);
        printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
-           
+
        ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
              (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
        EXPECTED(ret, True);
@@ -1769,12 +1760,12 @@ static bool run_locktest4(int dummy)
 
        cli_close(cli1, fnum1);
        cli_close(cli2, fnum2);
-       fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
-       f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
+       cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
+       cli_open(cli1, fname, O_RDWR, DENY_NONE, &f);
        ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
              cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
-             cli_close(cli1, fnum1) &&
-             ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
+             NT_STATUS_IS_OK(cli_close(cli1, fnum1)) &&
+             NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1)) &&
              cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
         cli_close(cli1, f);
        cli_close(cli1, fnum1);
@@ -1784,7 +1775,7 @@ static bool run_locktest4(int dummy)
  fail:
        cli_close(cli1, fnum1);
        cli_close(cli2, fnum2);
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
        torture_close_connection(cli1);
        torture_close_connection(cli2);
 
@@ -1799,7 +1790,7 @@ static bool run_locktest5(int dummy)
 {
        static struct cli_state *cli1, *cli2;
        const char *fname = "\\lockt5.lck";
-       int fnum1, fnum2, fnum3;
+       uint16_t fnum1, fnum2, fnum3;
        bool ret;
        char buf[1000];
        bool correct = True;
@@ -1813,11 +1804,11 @@ static bool run_locktest5(int dummy)
 
        printf("starting locktest5\n");
 
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
-       fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
-       fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
+       cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
+       cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
+       cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum3);
 
        memset(buf, 0, sizeof(buf));
 
@@ -1831,12 +1822,12 @@ static bool run_locktest5(int dummy)
        ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
                  cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
        cli_close(cli1, fnum1);
-       fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
+       cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
        ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
        EXPECTED(ret, True);
        printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
        cli_close(cli1, fnum1);
-       fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
+       cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
        cli_unlock(cli1, fnum3, 0, 1);
 
        ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
@@ -1903,7 +1894,7 @@ static bool run_locktest5(int dummy)
  fail:
        cli_close(cli1, fnum1);
        cli_close(cli2, fnum2);
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
        if (!torture_close_connection(cli1)) {
                correct = False;
        }
@@ -1912,7 +1903,7 @@ static bool run_locktest5(int dummy)
        }
 
        printf("finished locktest5\n");
-       
+
        return correct;
 }
 
@@ -1924,7 +1915,7 @@ static bool run_locktest6(int dummy)
        static struct cli_state *cli;
        const char *fname[1] = { "\\lock6.txt" };
        int i;
-       int fnum;
+       uint16_t fnum;
        NTSTATUS status;
 
        if (!torture_open_connection(&cli, 0)) {
@@ -1938,19 +1929,19 @@ static bool run_locktest6(int dummy)
        for (i=0;i<1;i++) {
                printf("Testing %s\n", fname[i]);
 
-               cli_unlink(cli, fname[i]);
+               cli_unlink(cli, fname[i], aSYSTEM | aHIDDEN);
 
-               fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
+               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);
                cli_close(cli, fnum);
                printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
 
-               fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
+               cli_open(cli, fname[i], O_RDWR, DENY_NONE, &fnum);
                status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
                cli_close(cli, fnum);
                printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
 
-               cli_unlink(cli, fname[i]);
+               cli_unlink(cli, fname[i], aSYSTEM | aHIDDEN);
        }
 
        torture_close_connection(cli);
@@ -1963,7 +1954,7 @@ static bool run_locktest7(int dummy)
 {
        struct cli_state *cli1;
        const char *fname = "\\lockt7.lck";
-       int fnum1;
+       uint16_t fnum1;
        char buf[200];
        bool correct = False;
 
@@ -1975,9 +1966,9 @@ static bool run_locktest7(int dummy)
 
        printf("starting locktest7\n");
 
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
-       fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
+       cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
 
        memset(buf, 0, sizeof(buf));
 
@@ -2085,7 +2076,7 @@ static bool run_locktest7(int dummy)
 
 fail:
        cli_close(cli1, fnum1);
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
        torture_close_connection(cli1);
 
        printf("finished locktest7\n");
@@ -2100,7 +2091,7 @@ static bool run_fdpasstest(int dummy)
 {
        struct cli_state *cli1, *cli2;
        const char *fname = "\\fdpass.tst";
-       int fnum1;
+       uint16_t fnum1;
        char buf[1024];
 
        if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
@@ -2111,10 +2102,9 @@ static bool run_fdpasstest(int dummy)
 
        printf("starting fdpasstest\n");
 
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
-       fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum1 == -1) {
+       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));
                return False;
        }
@@ -2135,7 +2125,7 @@ static bool run_fdpasstest(int dummy)
        }
 
        cli_close(cli1, fnum1);
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
        torture_close_connection(cli1);
        torture_close_connection(cli2);
@@ -2153,8 +2143,8 @@ static bool run_fdsesstest(int dummy)
        uint16 saved_cnum;
        const char *fname = "\\fdsess.tst";
        const char *fname1 = "\\fdsess1.tst";
-       int fnum1;
-       int fnum2;
+       uint16_t fnum1;
+       uint16_t fnum2;
        char buf[1024];
        bool ret = True;
 
@@ -2173,11 +2163,10 @@ static bool run_fdsesstest(int dummy)
 
        printf("starting fdsesstest\n");
 
-       cli_unlink(cli, fname);
-       cli_unlink(cli, fname1);
+       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli, fname1, aSYSTEM | aHIDDEN);
 
-       fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum1 == -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));
                return False;
        }
@@ -2196,11 +2185,10 @@ static bool run_fdsesstest(int dummy)
                ret = False;
        }
        /* Try to open a file with different vuid, samba cnum. */
-       fnum2 = cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum2 != -1) {
+       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);
+               cli_unlink(cli, fname1, aSYSTEM | aHIDDEN);
        } else {
                printf("create with different vuid, same cnum failed.\n");
                printf("This will cause problems with service clients.\n");
@@ -2220,7 +2208,7 @@ static bool run_fdsesstest(int dummy)
 
        cli->cnum = saved_cnum;
        cli_close(cli, fnum1);
-       cli_unlink(cli, fname);
+       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
 
        torture_close_connection(cli);
 
@@ -2237,7 +2225,7 @@ static bool run_unlinktest(int dummy)
 {
        struct cli_state *cli;
        const char *fname = "\\unlink.tst";
-       int fnum;
+       uint16_t fnum;
        bool correct = True;
 
        if (!torture_open_connection(&cli, 0)) {
@@ -2248,17 +2236,16 @@ static bool run_unlinktest(int dummy)
 
        printf("starting unlink test\n");
 
-       cli_unlink(cli, fname);
+       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
 
        cli_setpid(cli, 1);
 
-       fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum == -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));
                return False;
        }
 
-       if (cli_unlink(cli, fname)) {
+       if (NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
                printf("error: server allowed unlink on an open file\n");
                correct = False;
        } else {
@@ -2267,14 +2254,14 @@ static bool run_unlinktest(int dummy)
        }
 
        cli_close(cli, fnum);
-       cli_unlink(cli, fname);
+       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
 
        if (!torture_close_connection(cli)) {
                correct = False;
        }
 
        printf("unlink test finished\n");
-       
+
        return correct;
 }
 
@@ -2287,7 +2274,8 @@ static bool run_maxfidtest(int dummy)
        struct cli_state *cli;
        const char *ftemplate = "\\maxfid.%d.%d";
        fstring fname;
-       int fnums[0x11000], i;
+       uint16_t fnums[0x11000];
+       int i;
        int retries=4;
        bool correct = True;
 
@@ -2302,9 +2290,8 @@ static bool run_maxfidtest(int dummy)
 
        for (i=0; i<0x11000; i++) {
                slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
-               if ((fnums[i] = cli_open(cli, fname, 
-                                       O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
-                   -1) {
+               if (!NT_STATUS_IS_OK(cli_open(cli, fname, 
+                                       O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnums[i]))) {
                        printf("open of %s failed (%s)\n", 
                               fname, cli_errstr(cli));
                        printf("maximum fnum is %d\n", i);
@@ -2319,7 +2306,7 @@ static bool run_maxfidtest(int dummy)
        for (;i>=0;i--) {
                slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
                cli_close(cli, fnums[i]);
-               if (!cli_unlink(cli, fname)) {
+               if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, aSYSTEM | aHIDDEN))) {
                        printf("unlink of %s failed (%s)\n", 
                               fname, cli_errstr(cli));
                        correct = False;
@@ -2394,7 +2381,7 @@ static bool run_randomipc(int dummy)
                param_len = (sys_random() % 64);
 
                rand_buf(param, param_len);
-  
+
                SSVAL(param,0,api); 
 
                cli_api(cli, 
@@ -2469,7 +2456,7 @@ static bool run_browsetest(int dummy)
 static bool run_attrtest(int dummy)
 {
        struct cli_state *cli;
-       int fnum;
+       uint16_t fnum;
        time_t t, t2;
        const char *fname = "\\attrib123456789.tst";
        bool correct = True;
@@ -2480,11 +2467,11 @@ static bool run_attrtest(int dummy)
                return False;
        }
 
-       cli_unlink(cli, fname);
-       fnum = cli_open(cli, fname, 
-                       O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
+       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+       cli_open(cli, fname, 
+                       O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
        cli_close(cli, fnum);
-       if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
+       if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) {
                printf("getatr failed (%s)\n", cli_errstr(cli));
                correct = False;
        }
@@ -2498,12 +2485,12 @@ static bool run_attrtest(int dummy)
 
        t2 = t-60*60*24; /* 1 day ago */
 
-       if (!cli_setatr(cli, fname, 0, t2)) {
+       if (!NT_STATUS_IS_OK(cli_setatr(cli, fname, 0, t2))) {
                printf("setatr failed (%s)\n", cli_errstr(cli));
                correct = True;
        }
 
-       if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
+       if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) {
                printf("getatr failed (%s)\n", cli_errstr(cli));
                correct = True;
        }
@@ -2515,7 +2502,7 @@ static bool run_attrtest(int dummy)
                correct = True;
        }
 
-       cli_unlink(cli, fname);
+       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
 
        if (!torture_close_connection(cli)) {
                correct = False;
@@ -2533,7 +2520,7 @@ static bool run_attrtest(int dummy)
 static bool run_trans2test(int dummy)
 {
        struct cli_state *cli;
-       int fnum;
+       uint16_t fnum;
        SMB_OFF_T size;
        time_t c_time, a_time, m_time;
        struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
@@ -2549,9 +2536,9 @@ static bool run_trans2test(int dummy)
                return False;
        }
 
-       cli_unlink(cli, fname);
-       fnum = cli_open(cli, fname, 
-                       O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
+       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));
@@ -2573,10 +2560,9 @@ static bool run_trans2test(int dummy)
 
        sleep(2);
 
-       cli_unlink(cli, fname);
-       fnum = cli_open(cli, fname, 
-                       O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
-       if (fnum == -1) {
+       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));
                return False;
        }
@@ -2604,9 +2590,9 @@ static bool run_trans2test(int dummy)
        }
 
 
-       cli_unlink(cli, fname);
-       fnum = cli_open(cli, fname, 
-                       O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
+       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
+       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)) {
@@ -2620,12 +2606,12 @@ static bool run_trans2test(int dummy)
                }
        }
 
-       cli_unlink(cli, fname);
+       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
 
 
        /* check if the server updates the directory modification time
            when creating a new file */
-       if (!cli_mkdir(cli, dname)) {
+       if (!NT_STATUS_IS_OK(cli_mkdir(cli, dname))) {
                printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
                correct = False;
        }
@@ -2636,8 +2622,8 @@ static bool run_trans2test(int dummy)
                correct = False;
        }
 
-       fnum = cli_open(cli, fname2, 
-                       O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
+       cli_open(cli, fname2, 
+                       O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
        cli_write(cli, fnum,  0, (char *)&fnum, 0, sizeof(fnum));
        cli_close(cli, fnum);
        if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts, 
@@ -2651,7 +2637,7 @@ static bool run_trans2test(int dummy)
                        correct = False;
                }
        }
-       cli_unlink(cli, fname2);
+       cli_unlink(cli, fname2, aSYSTEM | aHIDDEN);
        cli_rmdir(cli, dname);
 
        if (!torture_close_connection(cli)) {
@@ -2688,7 +2674,7 @@ static bool new_trans(struct cli_state *pcli, int fnum, int level)
 static bool run_w2ktest(int dummy)
 {
        struct cli_state *cli;
-       int fnum;
+       uint16_t fnum;
        const char *fname = "\\w2ktest\\w2k.tst";
        int level;
        bool correct = True;
@@ -2699,8 +2685,8 @@ static bool run_w2ktest(int dummy)
                return False;
        }
 
-       fnum = cli_open(cli, fname, 
-                       O_RDWR | O_CREAT , DENY_NONE);
+       cli_open(cli, fname, 
+                       O_RDWR | O_CREAT , DENY_NONE, &fnum);
 
        for (level = 1004; level < 1040; level++) {
                new_trans(cli, fnum, level);
@@ -2713,7 +2699,7 @@ static bool run_w2ktest(int dummy)
        }
 
        printf("w2k test finished\n");
-       
+
        return correct;
 }
 
@@ -2725,7 +2711,7 @@ static bool run_oplock1(int dummy)
 {
        struct cli_state *cli1;
        const char *fname = "\\lockt1.lck";
-       int fnum1;
+       uint16_t fnum1;
        bool correct = True;
 
        printf("starting oplock test 1\n");
@@ -2734,29 +2720,28 @@ static bool run_oplock1(int dummy)
                return False;
        }
 
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
        cli_sockopt(cli1, sockops);
 
        cli1->use_oplocks = True;
 
-       fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum1 == -1) {
+       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));
                return False;
        }
 
        cli1->use_oplocks = False;
 
-       cli_unlink(cli1, fname);
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close2 failed (%s)\n", cli_errstr(cli1));
                return False;
        }
 
-       if (!cli_unlink(cli1, fname)) {
+       if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
                printf("unlink failed (%s)\n", cli_errstr(cli1));
                return False;
        }
@@ -2774,7 +2759,7 @@ static bool run_oplock2(int dummy)
 {
        struct cli_state *cli1, *cli2;
        const char *fname = "\\lockt2.lck";
-       int fnum1, fnum2;
+       uint16_t fnum1, fnum2;
        int saved_use_oplocks = use_oplocks;
        char buf[4];
        bool correct = True;
@@ -2806,13 +2791,12 @@ static bool run_oplock2(int dummy)
        cli2->use_oplocks = True;
        cli2->use_level_II_oplocks = True;
 
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
        cli_sockopt(cli1, sockops);
        cli_sockopt(cli2, sockops);
 
-       fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum1 == -1) {
+       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));
                return False;
        }
@@ -2823,8 +2807,7 @@ static bool run_oplock2(int dummy)
 
        if (fork() == 0) {
                /* Child code */
-               fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
-               if (fnum2 == -1) {
+               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));
                        *shared_correct = False;
                        exit(0);
@@ -2832,7 +2815,7 @@ static bool run_oplock2(int dummy)
 
                sleep(2);
 
-               if (!cli_close(cli2, fnum2)) {
+               if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
                        printf("close2 failed (%s)\n", cli_errstr(cli1));
                        *shared_correct = False;
                }
@@ -2880,14 +2863,14 @@ static bool run_oplock2(int dummy)
        }
 #endif
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close1 failed (%s)\n", cli_errstr(cli1));
                correct = False;
        }
 
        sleep(4);
 
-       if (!cli_unlink(cli1, fname)) {
+       if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, aSYSTEM | aHIDDEN))) {
                printf("unlink failed (%s)\n", cli_errstr(cli1));
                correct = False;
        }
@@ -2906,7 +2889,7 @@ static bool run_oplock2(int dummy)
 }
 
 /* handler for oplock 3 tests */
-static bool oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
+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);
@@ -2917,7 +2900,7 @@ static bool run_oplock3(int dummy)
 {
        struct cli_state *cli;
        const char *fname = "\\oplockt3.dat";
-       int fnum;
+       uint16_t fnum;
        char buf[4] = "abcd";
        bool correct = True;
        volatile bool *shared_correct;
@@ -2937,7 +2920,7 @@ static bool run_oplock3(int dummy)
                } 
                sleep(2);
                /* try to trigger a oplock break in parent */
-               fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
+               cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
                cli_write(cli, fnum, 0, buf, 0, 4);
                exit(0);
        }
@@ -2949,10 +2932,10 @@ static bool run_oplock3(int dummy)
                return False;
        }
        cli_oplock_handler(cli, oplock3_handler);
-       fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
+       cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum);
        cli_write(cli, fnum, 0, buf, 0, 4);
        cli_close(cli, fnum);
-       fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
+       cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
        cli->timeout = 20000;
        cli_receive_smb(cli);
        printf("finished oplock test 3\n");
@@ -2972,28 +2955,26 @@ static bool run_deletetest(int dummy)
        struct cli_state *cli1 = NULL;
        struct cli_state *cli2 = NULL;
        const char *fname = "\\delete.file";
-       int fnum1 = -1;
-       int fnum2 = -1;
+       uint16_t fnum1 = (uint16_t)-1;
+       uint16_t fnum2 = (uint16_t)-1;
        bool correct = True;
-       
+
        printf("starting delete test\n");
-       
+
        if (!torture_open_connection(&cli1, 0)) {
                return False;
        }
-       
+
        cli_sockopt(cli1, sockops);
 
        /* Test 1 - this should delete the file on close. */
-       
+
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname);
-       
-       fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+
+       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);
-       
-       if (fnum1 == -1) {
+                                  FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
                printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
                correct = False;
                goto fail;
@@ -3010,68 +2991,62 @@ static bool run_deletetest(int dummy)
         }
 #endif
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("[1] close failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
        }
 
-       fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
-       if (fnum1 != -1) {
+       if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1))) {
                printf("[1] open of %s succeeded (should fail)\n", fname);
                correct = False;
                goto fail;
        }
-       
+
        printf("first delete on close test succeeded.\n");
-       
+
        /* Test 2 - this should delete the file on close. */
-       
+
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname);
-       
-       fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS,
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+
+       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
                                   FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, 
-                                  FILE_OVERWRITE_IF, 0, 0);
-       
-       if (fnum1 == -1) {
+                                  FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
                printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
                correct = False;
                goto fail;
        }
-       
+
        if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
                printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
        }
-       
-       if (!cli_close(cli1, fnum1)) {
+
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("[2] close failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
        }
-       
-       fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
-       if (fnum1 != -1) {
+
+       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 (!cli_close(cli1, fnum1)) {
+               if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                        printf("[2] close failed (%s)\n", cli_errstr(cli1));
                        correct = False;
                        goto fail;
                }
-               cli_unlink(cli1, fname);
+               cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
        } else
                printf("second delete on close test succeeded.\n");
-       
+
        /* Test 3 - ... */
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
-       fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
-
-       if (fnum1 == -1) {
+       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));
                correct = False;
                goto fail;
@@ -3080,10 +3055,8 @@ static bool run_deletetest(int dummy)
        /* This should fail with a sharing violation - open for delete is only compatible
           with SHARE_DELETE. */
 
-       fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                       FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0);
-
-       if (fnum2 != -1) {
+       if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
+                       FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0, &fnum2))) {
                printf("[3] open  - 2 of %s succeeded - should have failed.\n", fname);
                correct = False;
                goto fail;
@@ -3091,10 +3064,8 @@ static bool run_deletetest(int dummy)
 
        /* This should succeed. */
 
-       fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                       FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
-
-       if (fnum2 == -1) {
+       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));
                correct = False;
                goto fail;
@@ -3105,28 +3076,27 @@ static bool run_deletetest(int dummy)
                correct = False;
                goto fail;
        }
-       
-       if (!cli_close(cli1, fnum1)) {
+
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
        }
-       
-       if (!cli_close(cli1, fnum2)) {
+
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
                printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
        }
-       
+
        /* This should fail - file should no longer be there. */
 
-       fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
-       if (fnum1 != -1) {
+       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 (!cli_close(cli1, fnum1)) {
+               if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                        printf("[3] close failed (%s)\n", cli_errstr(cli1));
                }
-               cli_unlink(cli1, fname);
+               cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
                correct = False;
                goto fail;
        } else
@@ -3134,61 +3104,56 @@ static bool run_deletetest(int dummy)
 
        /* Test 4 ... */
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
-       fnum1 = cli_nt_create_full(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);
-                                                               
-       if (fnum1 == -1) {
+       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));
                correct = False;
                goto fail;
        }
 
        /* This should succeed. */
-       fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
-                       FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
-       if (fnum2 == -1) {
+       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));
                correct = False;
                goto fail;
        }
-       
-       if (!cli_close(cli1, fnum2)) {
+
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
                printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
        }
-       
+
        if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
                printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
        }
-       
+
        /* This should fail - no more opens once delete on close set. */
-       fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
+       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);
-       if (fnum2 != -1) {
+                                  FILE_OPEN, 0, 0, &fnum2))) {
                printf("[4] open  - 3 of %s succeeded ! Should have failed.\n", fname );
                correct = False;
                goto fail;
        } else
                printf("fourth delete on close test succeeded.\n");
-       
-       if (!cli_close(cli1, fnum1)) {
+
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
        }
-       
+
        /* Test 5 ... */
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname);
-       
-       fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
-       if (fnum1 == -1) {
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+
+       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));
                correct = False;
                goto fail;
@@ -3202,52 +3167,48 @@ static bool run_deletetest(int dummy)
                goto fail;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
        }
-       
+
        printf("fifth delete on close test succeeded.\n");
-       
+
        /* Test 6 ... */
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname);
-       
-       fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+
+       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);
-       
-       if (fnum1 == -1) {
+                                  FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
                printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
                correct = False;
                goto fail;
        }
-       
+
        /* This should fail - only allowed on NT opens with DELETE access. */
-       
+
        if (cli_nt_delete_on_close(cli1, fnum1, True)) {
                printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
                correct = False;
                goto fail;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
        }
 
        printf("sixth delete on close test succeeded.\n");
-       
+
        /* Test 7 ... */
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname);
-       
-       fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
-                                  FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0);
-                                                               
-       if (fnum1 == -1) {
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+
+       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));
                correct = False;
                goto fail;
@@ -3258,40 +3219,39 @@ static bool run_deletetest(int dummy)
                correct = False;
                goto fail;
        }
-       
+
        if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
                printf("[7] unsetting delete_on_close on file failed !\n");
                correct = False;
                goto fail;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
        }
-       
+
        /* This next open should succeed - we reset the flag. */
-       
-       fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
-       if (fnum1 == -1) {
+
+       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));
                correct = False;
                goto fail;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
        }
 
        printf("seventh delete on close test succeeded.\n");
-       
+
        /* Test 7 ... */
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname);
-       
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+
        if (!torture_open_connection(&cli2, 1)) {
                printf("[8] failed to open second connection.\n");
                correct = False;
@@ -3299,22 +3259,18 @@ static bool run_deletetest(int dummy)
        }
 
        cli_sockopt(cli1, sockops);
-       
-       fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
+
+       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);
-       
-       if (fnum1 == -1) {
+                                  FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
                printf("[8] open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                correct = False;
                goto fail;
        }
 
-       fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
+       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);
-       
-       if (fnum2 == -1) {
+                                  FILE_OPEN, 0, 0, &fnum2))) {
                printf("[8] open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
                correct = False;
                goto fail;
@@ -3325,22 +3281,21 @@ static bool run_deletetest(int dummy)
                correct = False;
                goto fail;
        }
-       
-       if (!cli_close(cli1, fnum1)) {
+
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
        }
 
-       if (!cli_close(cli2, fnum2)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
                printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
                correct = False;
                goto fail;
        }
 
        /* This should fail.. */
-       fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
-       if (fnum1 != -1) {
+       if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
                printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
                goto fail;
                correct = False;
@@ -3348,10 +3303,8 @@ static bool run_deletetest(int dummy)
                printf("eighth delete on close test succeeded.\n");
 
        /* This should fail - we need to set DELETE_ACCESS. */
-       fnum1 = cli_nt_create_full(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
-                                  FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
-       
-       if (fnum1 != -1) {
+       if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
+                                  FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
                printf("[9] open of %s succeeded should have failed!\n", fname);
                correct = False;
                goto fail;
@@ -3359,24 +3312,22 @@ static bool run_deletetest(int dummy)
 
        printf("ninth delete on close test succeeded.\n");
 
-       fnum1 = cli_nt_create_full(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);
-       if (fnum1 == -1) {
+       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));
                correct = False;
                goto fail;
        }
 
        /* This should delete the file. */
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("[10] close failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
        }
 
        /* This should fail.. */
-       fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
-       if (fnum1 != -1) {
+       if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
                printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
                goto fail;
                correct = False;
@@ -3384,32 +3335,29 @@ static bool run_deletetest(int dummy)
                printf("tenth delete on close test succeeded.\n");
 
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
        /* What error do we get when attempting to open a read-only file with
           delete access ? */
 
        /* Create a readonly file. */
-       fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
-                                  FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
-       if (fnum1 == -1) {
+       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));
                correct = False;
                goto fail;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("[11] close failed (%s)\n", cli_errstr(cli1));
                correct = False;
                goto fail;
        }
 
        /* Now try open for delete access. */
-       fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
+       if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
                                   0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
-                                  FILE_OVERWRITE_IF, 0, 0);
-       
-       if (fnum1 != -1) {
+                                  FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
                printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
                cli_close(cli1, fnum1);
                goto fail;
@@ -3424,18 +3372,18 @@ static bool run_deletetest(int dummy)
                        printf("eleventh delete on close test succeeded.\n");
                }
        }
-       
+
        printf("finished delete test\n");
 
   fail:
        /* FIXME: This will crash if we aborted before cli2 got
         * intialized, because these functions don't handle
         * uninitialized connections. */
-               
-       if (fnum1 != -1) cli_close(cli1, fnum1);
-       if (fnum2 != -1) cli_close(cli1, fnum2);
+
+       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);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
        if (cli1 && !torture_close_connection(cli1)) {
                correct = False;
@@ -3452,17 +3400,17 @@ static bool run_deletetest(int dummy)
  */
 static bool run_properties(int dummy)
 {
-       static struct cli_state *cli;
+       struct cli_state *cli;
        bool correct = True;
-       
+
        printf("starting properties test\n");
-       
+
        ZERO_STRUCT(cli);
 
        if (!torture_open_connection(&cli, 0)) {
                return False;
        }
-       
+
        cli_sockopt(cli, sockops);
 
        d_printf("Capabilities 0x%08x\n", cli->capabilities);
@@ -3503,37 +3451,34 @@ static bool run_xcopy(int dummy)
        static struct cli_state *cli1;
        const char *fname = "\\test.txt";
        bool correct = True;
-       int fnum1, fnum2;
+       uint16_t fnum1, fnum2;
 
        printf("starting xcopy test\n");
-       
+
        if (!torture_open_connection(&cli1, 0)) {
                return False;
        }
-       
-       fnum1 = cli_nt_create_full(cli1, fname, 0,
+
+       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,
                                   FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
                                   FILE_SHARE_NONE, FILE_OVERWRITE_IF, 
-                                  0x4044, 0);
-
-       if (fnum1 == -1) {
+                                  0x4044, 0, &fnum1))) {
                printf("First open failed - %s\n", cli_errstr(cli1));
                return False;
        }
 
-       fnum2 = cli_nt_create_full(cli1, fname, 0,
+       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);
-       if (fnum2 == -1) {
+                                  0x200000, 0, &fnum2))) {
                printf("second open failed - %s\n", cli_errstr(cli1));
                return False;
        }
-       
+
        if (!torture_close_connection(cli1)) {
                correct = False;
        }
-       
+
        return correct;
 }
 
@@ -3546,69 +3491,66 @@ static bool run_rename(int dummy)
        const char *fname = "\\test.txt";
        const char *fname1 = "\\test1.txt";
        bool correct = True;
-       int fnum1;
+       uint16_t fnum1;
+       NTSTATUS status;
 
        printf("starting rename test\n");
-       
+
        if (!torture_open_connection(&cli1, 0)) {
                return False;
        }
-       
-       cli_unlink(cli1, fname);
-       cli_unlink(cli1, fname1);
-       fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
 
-       if (fnum1 == -1) {
+       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));
                return False;
        }
 
-       if (!cli_rename(cli1, fname, fname1)) {
+       if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
                printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1));
        } else {
                printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
                correct = False;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close - 1 failed (%s)\n", cli_errstr(cli1));
                return False;
        }
 
-       cli_unlink(cli1, fname);
-       cli_unlink(cli1, fname1);
-       fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
+       status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
 #if 0
-                                  FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
+                             FILE_SHARE_DELETE|FILE_SHARE_NONE,
 #else
-                                  FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
+                             FILE_SHARE_DELETE|FILE_SHARE_READ,
 #endif
-
-       if (fnum1 == -1) {
+                             FILE_OVERWRITE_IF, 0, 0, &fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
                printf("Second open failed - %s\n", cli_errstr(cli1));
                return False;
        }
 
-       if (!cli_rename(cli1, fname, fname1)) {
+       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));
                correct = False;
        } else {
                printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close - 2 failed (%s)\n", cli_errstr(cli1));
                return False;
        }
 
-       cli_unlink(cli1, fname);
-       cli_unlink(cli1, fname1);
-
-       fnum1 = cli_nt_create_full(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
 
-       if (fnum1 == -1) {
+       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));
                return False;
        }
@@ -3616,12 +3558,10 @@ static bool run_rename(int dummy)
 
 #if 0
   {
-  int fnum2;
-
-       fnum2 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
+       uint16_t fnum2;
 
-       if (fnum2 == -1) {
+       if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
+                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
                printf("Fourth open failed - %s\n", cli_errstr(cli1));
                return False;
        }
@@ -3629,65 +3569,61 @@ static bool run_rename(int dummy)
                printf("[8] setting delete_on_close on file failed !\n");
                return False;
        }
-       
-       if (!cli_close(cli1, fnum2)) {
+
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
                printf("close - 4 failed (%s)\n", cli_errstr(cli1));
                return False;
        }
   }
 #endif
 
-       if (!cli_rename(cli1, fname, fname1)) {
+       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));
                correct = False;
        } else {
                printf("Third rename succeeded (SHARE_NONE)\n");
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close - 3 failed (%s)\n", cli_errstr(cli1));
                return False;
        }
 
-       cli_unlink(cli1, fname);
-       cli_unlink(cli1, fname1);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
 
         /*----*/
 
-       fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
-
-       if (fnum1 == -1) {
+       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));
                return False;
        }
 
-       if (!cli_rename(cli1, fname, fname1)) {
+       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));
        } else {
                printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
                correct = False;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close - 4 failed (%s)\n", cli_errstr(cli1));
                return False;
        }
 
-       cli_unlink(cli1, fname);
-       cli_unlink(cli1, fname1);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
 
         /*--*/
 
-       fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
-
-       if (fnum1 == -1) {
+       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));
                return False;
        }
 
-       if (!cli_rename(cli1, fname, fname1)) {
+       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));
                correct = False;
@@ -3699,10 +3635,8 @@ static bool run_rename(int dummy)
          * Now check if the first name still exists ...
          */
 
-        /*fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
-
-        if (fnum2 == -1) {
+        /* if (!NT_STATUS_OP(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, &fnum2))) {
           printf("Opening original file after rename of open file fails: %s\n",
               cli_errstr(cli1));
         }
@@ -3714,18 +3648,18 @@ static bool run_rename(int dummy)
         /*--*/
 
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close - 5 failed (%s)\n", cli_errstr(cli1));
                return False;
        }
 
-       cli_unlink(cli1, fname);
-       cli_unlink(cli1, fname1);
-        
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+       cli_unlink(cli1, fname1, aSYSTEM | aHIDDEN);
+
        if (!torture_close_connection(cli1)) {
                correct = False;
        }
-       
+
        return correct;
 }
 
@@ -3733,7 +3667,7 @@ static bool run_pipe_number(int dummy)
 {
        struct cli_state *cli1;
        const char *pipe_name = "\\SPOOLSS";
-       int fnum;
+       uint16_t fnum;
        int num_pipes = 0;
 
        printf("starting pipenumber test\n");
@@ -3743,10 +3677,8 @@ static bool run_pipe_number(int dummy)
 
        cli_sockopt(cli1, sockops);
        while(1) {
-               fnum = cli_nt_create_full(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0);
-
-               if (fnum == -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));
                        break;
                }
@@ -3767,94 +3699,90 @@ static bool run_opentest(int dummy)
        static struct cli_state *cli1;
        static struct cli_state *cli2;
        const char *fname = "\\readonly.file";
-       int fnum1, fnum2;
+       uint16_t fnum1, fnum2;
        char buf[20];
        SMB_OFF_T fsize;
        bool correct = True;
        char *tmp_path;
 
        printf("starting open test\n");
-       
+
        if (!torture_open_connection(&cli1, 0)) {
                return False;
        }
-       
+
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname);
-       
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+
        cli_sockopt(cli1, sockops);
-       
-       fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum1 == -1) {
+
+       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));
                return False;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close2 failed (%s)\n", cli_errstr(cli1));
                return False;
        }
-       
-       if (!cli_setatr(cli1, fname, aRONLY, 0)) {
+
+       if (!NT_STATUS_IS_OK(cli_setatr(cli1, fname, aRONLY, 0))) {
                printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
                return False;
        }
-       
-       fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
-       if (fnum1 == -1) {
+
+       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));
                return False;
        }
-       
+
        /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
-       fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
-       
+       cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
+
         if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess, 
                        NT_STATUS_ACCESS_DENIED)) {
                printf("correct error code ERRDOS/ERRnoaccess returned\n");
        }
-       
+
        printf("finished open test 1\n");
-       
+
        cli_close(cli1, fnum1);
-       
+
        /* Now try not readonly and ensure ERRbadshare is returned. */
-       
+
        cli_setatr(cli1, fname, 0, 0);
-       
-       fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
-       if (fnum1 == -1) {
+
+       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));
                return False;
        }
-       
+
        /* This will fail - but the error should be ERRshare. */
-       fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
-       
+       cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
+
        if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare, 
                        NT_STATUS_SHARING_VIOLATION)) {
                printf("correct error code ERRDOS/ERRbadshare returned\n");
        }
-       
-       if (!cli_close(cli1, fnum1)) {
+
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close2 failed (%s)\n", cli_errstr(cli1));
                return False;
        }
-       
-       cli_unlink(cli1, fname);
-       
+
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
+
        printf("finished open test 2\n");
-       
+
        /* Test truncate open disposition on file opened for read. */
-       
-       fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum1 == -1) {
+
+       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));
                return False;
        }
-       
+
        /* write 20 bytes. */
-       
+
        memset(buf, '\0', 20);
 
        if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
@@ -3862,37 +3790,36 @@ static bool run_opentest(int dummy)
                correct = False;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
                return False;
        }
-       
+
        /* Ensure size == 20. */
-       if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
+       if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) {
                printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
                return False;
        }
-       
+
        if (fsize != 20) {
                printf("(3) file size != 20\n");
                return False;
        }
 
        /* Now test if we can truncate a file opened for readonly. */
-       
-       fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
-       if (fnum1 == -1) {
+
+       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));
                return False;
        }
-       
-       if (!cli_close(cli1, fnum1)) {
+
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close2 failed (%s)\n", cli_errstr(cli1));
                return False;
        }
 
        /* Ensure size == 0. */
-       if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
+       if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) {
                printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
                return False;
        }
@@ -3902,181 +3829,161 @@ static bool run_opentest(int dummy)
                return False;
        }
        printf("finished open test 3\n");
-       
-       cli_unlink(cli1, fname);
+
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
 
        printf("testing ctemp\n");
        fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
-       if (fnum1 == -1) {
+       if (fnum1 == (uint16_t)-1) {
                printf("ctemp failed (%s)\n", cli_errstr(cli1));
                return False;
        }
        printf("ctemp gave path %s\n", tmp_path);
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close of temp failed (%s)\n", cli_errstr(cli1));
        }
-       if (!cli_unlink(cli1, tmp_path)) {
+       if (!NT_STATUS_IS_OK(cli_unlink(cli1, tmp_path, aSYSTEM | aHIDDEN))) {
                printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
        }
-       
+
        /* Test the non-io opens... */
 
        if (!torture_open_connection(&cli2, 1)) {
                return False;
        }
-       
+
        cli_setatr(cli2, fname, 0, 0);
-       cli_unlink(cli2, fname);
-       
+       cli_unlink(cli2, fname, aSYSTEM | aHIDDEN);
+
        cli_sockopt(cli2, sockops);
 
        printf("TEST #1 testing 2 non-io opens (no delete)\n");
-       
-       fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
 
-       if (fnum1 == -1) {
+       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));
                return False;
        }
 
-       fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
-
-       if (fnum2 == -1) {
+       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));
                return False;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
-       if (!cli_close(cli2, fnum2)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
                printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
                return False;
        }
 
        printf("non-io open test #1 passed.\n");
 
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
        printf("TEST #2 testing 2 non-io opens (first with delete)\n");
-       
-       fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
 
-       if (fnum1 == -1) {
+       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));
                return False;
        }
 
-       fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
-
-       if (fnum2 == -1) {
+       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));
                return False;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
-       if (!cli_close(cli2, fnum2)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
                printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
        printf("non-io open test #2 passed.\n");
 
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
        printf("TEST #3 testing 2 non-io opens (second with delete)\n");
-       
-       fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
 
-       if (fnum1 == -1) {
+       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));
                return False;
        }
 
-       fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
-
-       if (fnum2 == -1) {
+       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));
                return False;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
-       if (!cli_close(cli2, fnum2)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
                printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
                return False;
        }
 
        printf("non-io open test #3 passed.\n");
 
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
        printf("TEST #4 testing 2 non-io opens (both with delete)\n");
-       
-       fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
 
-       if (fnum1 == -1) {
+       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));
                return False;
        }
 
-       fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
-
-       if (fnum2 != -1) {
+       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));
                return False;
        }
 
        printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
        printf("non-io open test #4 passed.\n");
 
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
        printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
-       
-       fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
 
-       if (fnum1 == -1) {
+       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));
                return False;
        }
 
-       fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
-
-       if (fnum2 == -1) {
+       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));
                return False;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
-       if (!cli_close(cli2, fnum2)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
                printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
                return False;
        }
@@ -4084,31 +3991,27 @@ static bool run_opentest(int dummy)
        printf("non-io open test #5 passed.\n");
 
        printf("TEST #6 testing 1 non-io open, one io open\n");
-       
-       cli_unlink(cli1, fname);
 
-       fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
-       if (fnum1 == -1) {
+       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));
                return False;
        }
 
-       fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_READ, FILE_OPEN_IF, 0, 0);
-
-       if (fnum2 == -1) {
+       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));
                return False;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
-       if (!cli_close(cli2, fnum2)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
                printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
                return False;
        }
@@ -4117,34 +4020,30 @@ static bool run_opentest(int dummy)
 
        printf("TEST #7 testing 1 non-io open, one io open with delete\n");
 
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
-       fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
-
-       if (fnum1 == -1) {
+       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));
                return False;
        }
 
-       fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
-                                  FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
-
-       if (fnum2 != -1) {
+       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));
                return False;
        }
 
        printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
                return False;
        }
 
        printf("non-io open test #7 passed.\n");
 
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
        if (!torture_close_connection(cli1)) {
                correct = False;
@@ -4152,7 +4051,7 @@ static bool run_opentest(int dummy)
        if (!torture_close_connection(cli2)) {
                correct = False;
        }
-       
+
        return correct;
 }
 
@@ -4201,7 +4100,7 @@ static bool run_simple_posix_open_test(int dummy)
 
        /* Create a directory. */
        if (cli_posix_mkdir(cli1, dname, 0777) == -1) {
-               printf("Server doesn't support setting UNIX CIFS extensions.\n");
+               printf("POSIX mkdir of %s failed (%s)\n", dname, cli_errstr(cli1));
                goto out;
        }
 
@@ -4211,7 +4110,7 @@ static bool run_simple_posix_open_test(int dummy)
                goto out;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close failed (%s)\n", cli_errstr(cli1));
                goto out;
        }
@@ -4224,12 +4123,12 @@ static bool run_simple_posix_open_test(int dummy)
        }
 
        /* Now unlink while open. */
-       if (!cli_posix_unlink(cli1, 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;
        }
 
-       if (!cli_close(cli1, fnum1)) {
+       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                printf("close(2) failed (%s)\n", cli_errstr(cli1));
                goto out;
        }
@@ -4241,7 +4140,7 @@ static bool run_simple_posix_open_test(int dummy)
                goto out;
        }
 
-       if (!cli_posix_rmdir(cli1, dname)) {
+       if (!NT_STATUS_IS_OK(cli_posix_rmdir(cli1, dname))) {
                printf("POSIX rmdir failed (%s)\n", cli_errstr(cli1));
                goto out;
        }
@@ -4329,40 +4228,36 @@ static bool run_openattrtest(int dummy)
 {
        static struct cli_state *cli1;
        const char *fname = "\\openattr.file";
-       int fnum1;
+       uint16_t fnum1;
        bool correct = True;
        uint16 attr;
        unsigned int i, j, k, l;
 
        printf("starting open attr test\n");
-       
+
        if (!torture_open_connection(&cli1, 0)) {
                return False;
        }
-       
+
        cli_sockopt(cli1, sockops);
 
        for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
                cli_setatr(cli1, fname, 0, 0);
-               cli_unlink(cli1, fname);
-               fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
-                                  FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
-
-               if (fnum1 == -1) {
+               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));
                        return False;
                }
 
-               if (!cli_close(cli1, fnum1)) {
+               if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                        printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
                        return False;
                }
 
                for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
-                       fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
-                                          FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0);
-
-                       if (fnum1 == -1) {
+                       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))) {
                                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",
@@ -4385,12 +4280,12 @@ static bool run_openattrtest(int dummy)
                                continue;
                        }
 
-                       if (!cli_close(cli1, fnum1)) {
+                       if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
                                printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
                                return False;
                        }
 
-                       if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
+                       if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, &attr, NULL, NULL))) {
                                printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
                                return False;
                        }
@@ -4420,7 +4315,7 @@ static bool run_openattrtest(int dummy)
        }
 
        cli_setatr(cli1, fname, 0, 0);
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
 
        printf("open attr test %s.\n", correct ? "passed" : "failed");
 
@@ -4432,7 +4327,7 @@ static bool run_openattrtest(int dummy)
 
 static void list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
 {
-       
+
 }
 
 /*
@@ -4442,7 +4337,7 @@ static bool run_dirtest(int dummy)
 {
        int i;
        static struct cli_state *cli;
-       int fnum;
+       uint16_t fnum;
        double t1;
        bool correct = True;
 
@@ -4458,8 +4353,7 @@ static bool run_dirtest(int dummy)
        for (i=0;i<torture_numops;i++) {
                fstring fname;
                slprintf(fname, sizeof(fname), "\\%x", (int)random());
-               fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
-               if (fnum == -1) {
+               if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum))) {
                        fprintf(stderr,"Failed to open %s\n", fname);
                        return False;
                }
@@ -4478,7 +4372,7 @@ static bool run_dirtest(int dummy)
        for (i=0;i<torture_numops;i++) {
                fstring fname;
                slprintf(fname, sizeof(fname), "\\%x", (int)random());
-               cli_unlink(cli, fname);
+               cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
        }
 
        if (!torture_close_connection(cli)) {
@@ -4500,10 +4394,10 @@ static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *st
                return;
 
        if (finfo->mode & aDIR) {
-               if (!cli_rmdir(pcli, fname))
+               if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
                        printf("del_fn: failed to rmdir %s\n,", fname );
        } else {
-               if (!cli_unlink(pcli, fname))
+               if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN)))
                        printf("del_fn: failed to unlink %s\n,", fname );
        }
 }
@@ -4515,8 +4409,8 @@ static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *st
 bool torture_ioctl_test(int dummy)
 {
        static struct cli_state *cli;
-       uint16 device, function;
-       int fnum;
+       uint16_t device, function;
+       uint16_t fnum;
        const char *fname = "\\ioctl.dat";
        DATA_BLOB blob;
        NTSTATUS status;
@@ -4527,10 +4421,9 @@ bool torture_ioctl_test(int dummy)
 
        printf("starting ioctl test\n");
 
-       cli_unlink(cli, fname);
+       cli_unlink(cli, fname, aSYSTEM | aHIDDEN);
 
-       fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum == -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));
                return False;
        }
@@ -4570,7 +4463,7 @@ bool torture_ioctl_test(int dummy)
 bool torture_chkpath_test(int dummy)
 {
        static struct cli_state *cli;
-       int fnum;
+       uint16_t fnum;
        bool ret;
 
        if (!torture_open_connection(&cli, 0)) {
@@ -4581,37 +4474,36 @@ bool torture_chkpath_test(int dummy)
 
        /* cleanup from an old run */
        cli_rmdir(cli, "\\chkpath.dir\\dir2");
-       cli_unlink(cli, "\\chkpath.dir\\*");
+       cli_unlink(cli, "\\chkpath.dir\\*", aSYSTEM | aHIDDEN);
        cli_rmdir(cli, "\\chkpath.dir");
 
-       if (!cli_mkdir(cli, "\\chkpath.dir")) {
+       if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir"))) {
                printf("mkdir1 failed : %s\n", cli_errstr(cli));
                return False;
        }
 
-       if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) {
+       if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir\\dir2"))) {
                printf("mkdir2 failed : %s\n", cli_errstr(cli));
                return False;
        }
 
-       fnum = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum == -1) {
+       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));
                return False;
        }
        cli_close(cli, fnum);
 
-       if (!cli_chkpath(cli, "\\chkpath.dir")) {
+       if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir"))) {
                printf("chkpath1 failed: %s\n", cli_errstr(cli));
                ret = False;
        }
 
-       if (!cli_chkpath(cli, "\\chkpath.dir\\dir2")) {
+       if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dir2"))) {
                printf("chkpath2 failed: %s\n", cli_errstr(cli));
                ret = False;
        }
 
-       if (!cli_chkpath(cli, "\\chkpath.dir\\foo.txt")) {
+       if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\foo.txt"))) {
                ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath, 
                                  NT_STATUS_NOT_A_DIRECTORY);
        } else {
@@ -4619,7 +4511,7 @@ bool torture_chkpath_test(int dummy)
                ret = False;
        }
 
-       if (!cli_chkpath(cli, "\\chkpath.dir\\bar.txt")) {
+       if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\bar.txt"))) {
                ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile, 
                                  NT_STATUS_OBJECT_NAME_NOT_FOUND);
        } else {
@@ -4627,7 +4519,7 @@ bool torture_chkpath_test(int dummy)
                ret = False;
        }
 
-       if (!cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt")) {
+       if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt"))) {
                ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath, 
                                  NT_STATUS_OBJECT_PATH_NOT_FOUND);
        } else {
@@ -4636,7 +4528,7 @@ bool torture_chkpath_test(int dummy)
        }
 
        cli_rmdir(cli, "\\chkpath.dir\\dir2");
-       cli_unlink(cli, "\\chkpath.dir\\*");
+       cli_unlink(cli, "\\chkpath.dir\\*", aSYSTEM | aHIDDEN);
        cli_rmdir(cli, "\\chkpath.dir");
 
        if (!torture_close_connection(cli)) {
@@ -4651,25 +4543,24 @@ static bool run_eatest(int dummy)
        static struct cli_state *cli;
        const char *fname = "\\eatest.txt";
        bool correct = True;
-       int fnum, i;
+       uint16_t fnum;
+       int i;
        size_t num_eas;
        struct ea_struct *ea_list = NULL;
        TALLOC_CTX *mem_ctx = talloc_init("eatest");
 
        printf("starting eatest\n");
-       
+
        if (!torture_open_connection(&cli, 0)) {
                talloc_destroy(mem_ctx);
                return False;
        }
-       
-       cli_unlink(cli, fname);
-       fnum = cli_nt_create_full(cli, fname, 0,
+
+       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);
-
-       if (fnum == -1) {
+                                  0x4044, 0, &fnum))) {
                printf("open failed - %s\n", cli_errstr(cli));
                talloc_destroy(mem_ctx);
                return False;
@@ -4686,7 +4577,7 @@ static bool run_eatest(int dummy)
                        return False;
                }
        }
-       
+
        cli_close(cli, fnum);
        for (i = 0; i < 10; i++) {
                fstring ea_name, ea_val;
@@ -4699,7 +4590,7 @@ static bool run_eatest(int dummy)
                        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));
                correct = False;
@@ -4762,7 +4653,7 @@ static bool run_eatest(int dummy)
        if (!torture_close_connection(cli)) {
                correct = False;
        }
-       
+
        return correct;
 }
 
@@ -4770,7 +4661,8 @@ static bool run_dirtest1(int dummy)
 {
        int i;
        static struct cli_state *cli;
-       int fnum, num_seen;
+       uint16_t fnum;
+       int num_seen;
        bool correct = True;
 
        printf("starting directory test\n");
@@ -4790,9 +4682,8 @@ static bool run_dirtest1(int dummy)
        for (i=0;i<1000;i++) {
                fstring fname;
                slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
-               fnum = cli_nt_create_full(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
-                                  FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
-               if (fnum == -1) {
+               if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
+                                  FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
                        fprintf(stderr,"Failed to open %s\n", fname);
                        return False;
                }
@@ -4801,7 +4692,7 @@ static bool run_dirtest1(int dummy)
        for (i=0;i<1000;i++) {
                fstring fname;
                slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
-               if (!cli_mkdir(cli, fname)) {
+               if (!NT_STATUS_IS_OK(cli_mkdir(cli, fname))) {
                        fprintf(stderr,"Failed to open %s\n", fname);
                        return False;
                }
@@ -4848,7 +4739,7 @@ static bool run_dirtest1(int dummy)
 }
 
 static bool run_error_map_extract(int dummy) {
-       
+
        static struct cli_state *c_dos;
        static struct cli_state *c_nt;
        NTSTATUS status;
@@ -4917,9 +4808,9 @@ static bool run_error_map_extract(int dummy) {
                                                      workgroup))) {
                        printf("/** Session setup succeeded.  This shouldn't happen...*/\n");
                }
-               
+
                flgs2 = SVAL(c_nt->inbuf,smb_flg2);
-               
+
                /* Case #1: 32-bit NT errors */
                if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
                        nt_status = NT_STATUS(IVAL(c_nt->inbuf,smb_rcls));
@@ -4936,7 +4827,7 @@ static bool run_error_map_extract(int dummy) {
                        printf("/** Session setup succeeded.  This shouldn't happen...*/\n");
                }
                flgs2 = SVAL(c_dos->inbuf,smb_flg2), errnum;
-               
+
                /* Case #1: 32-bit NT errors */
                if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
                        printf("/** NT error on DOS connection! (%s) */\n", 
@@ -4951,7 +4842,7 @@ static bool run_error_map_extract(int dummy) {
                               get_nt_error_c_code(NT_STATUS(error)), 
                               get_nt_error_c_code(nt_status));
                }
-               
+
                printf("\t{%s,\t%s,\t%s},\n", 
                       smb_dos_err_class(errclass), 
                       smb_dos_err_name(errclass, errnum), 
@@ -4964,7 +4855,7 @@ static bool run_sesssetup_bench(int dummy)
 {
        static struct cli_state *c;
        const char *fname = "\\file.dat";
-       int fnum;
+       uint16_t fnum;
        NTSTATUS status;
        int i;
 
@@ -4972,11 +4863,10 @@ static bool run_sesssetup_bench(int dummy)
                return false;
        }
 
-       fnum = cli_nt_create_full(
-               c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
-               FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
-               FILE_DELETE_ON_CLOSE, 0);
-       if (fnum == -1) {
+       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));
                return false;
        }
@@ -5027,7 +4917,7 @@ static bool subst_test(const char *str, const char *user, const char *domain,
 
 static void chain1_open_completion(struct tevent_req *req)
 {
-       int fnum;
+       uint16_t fnum;
        NTSTATUS status;
        status = cli_open_recv(req, &fnum);
        TALLOC_FREE(req);
@@ -5069,6 +4959,7 @@ static bool run_chain1(int dummy)
        struct tevent_req *reqs[3], *smbreqs[3];
        bool done = false;
        const char *str = "foobar";
+       NTSTATUS status;
 
        printf("starting chain1 test\n");
        if (!torture_open_connection(&cli1, 0)) {
@@ -5093,7 +4984,62 @@ static bool run_chain1(int dummy)
        if (reqs[2] == NULL) return false;
        tevent_req_set_callback(reqs[2], chain1_close_completion, &done);
 
-       if (!cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs))) {
+       status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
+       if (!NT_STATUS_IS_OK(status)) {
+               return false;
+       }
+
+       while (!done) {
+               event_loop_once(evt);
+       }
+
+       torture_close_connection(cli1);
+       return True;
+}
+
+static void chain2_sesssetup_completion(struct tevent_req *req)
+{
+       NTSTATUS status;
+       status = cli_session_setup_guest_recv(req);
+       d_printf("sesssetup returned %s\n", nt_errstr(status));
+}
+
+static void chain2_tcon_completion(struct tevent_req *req)
+{
+       bool *done = (bool *)tevent_req_callback_data_void(req);
+       NTSTATUS status;
+       status = cli_tcon_andx_recv(req);
+       d_printf("tcon_and_x returned %s\n", nt_errstr(status));
+       *done = true;
+}
+
+static bool run_chain2(int dummy)
+{
+       struct cli_state *cli1;
+       struct event_context *evt = event_context_init(NULL);
+       struct tevent_req *reqs[2], *smbreqs[2];
+       bool done = false;
+       NTSTATUS status;
+
+       printf("starting chain2 test\n");
+       if (!torture_open_connection(&cli1, 0)) {
+               return False;
+       }
+
+       cli_sockopt(cli1, sockops);
+
+       reqs[0] = cli_session_setup_guest_create(talloc_tos(), evt, cli1,
+                                                &smbreqs[0]);
+       if (reqs[0] == NULL) return false;
+       tevent_req_set_callback(reqs[0], chain2_sesssetup_completion, NULL);
+
+       reqs[1] = cli_tcon_andx_create(talloc_tos(), evt, cli1, "IPC$",
+                                      "?????", NULL, 0, &smbreqs[1]);
+       if (reqs[1] == NULL) return false;
+       tevent_req_set_callback(reqs[1], chain2_tcon_completion, &done);
+
+       status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
+       if (!NT_STATUS_IS_OK(status)) {
                return false;
        }
 
@@ -5109,24 +5055,23 @@ static bool run_mangle1(int dummy)
 {
        struct cli_state *cli;
        const char *fname = "this_is_a_long_fname_to_be_mangled.txt";
-       int fnum;
+       uint16_t fnum;
        fstring alt_name;
        NTSTATUS status;
-       time_t change, access, write;
+       time_t change_time, access_time, write_time;
        SMB_OFF_T size;
        uint16_t mode;
 
-       printf("starting chain1 test\n");
+       printf("starting mangle1 test\n");
        if (!torture_open_connection(&cli, 0)) {
                return False;
        }
 
        cli_sockopt(cli, sockops);
 
-       fnum = cli_nt_create_full(
-               cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
-               FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0);
-       if (fnum == -1) {
+       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));
                return false;
        }
@@ -5140,16 +5085,15 @@ static bool run_mangle1(int dummy)
        }
        d_printf("alt_name: %s\n", alt_name);
 
-       fnum = cli_open(cli, alt_name, O_RDONLY, DENY_NONE);
-       if (fnum == -1) {
+       if (!NT_STATUS_IS_OK(cli_open(cli, alt_name, O_RDONLY, DENY_NONE, &fnum))) {
                d_printf("cli_open(%s) failed: %s\n", alt_name,
                         cli_errstr(cli));
                return false;
        }
        cli_close(cli, fnum);
 
-       if (!cli_qpathinfo(cli, alt_name, &change, &access, &write, &size,
-                          &mode)) {
+       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));
                return false;
@@ -5176,7 +5120,7 @@ static size_t null_source(uint8_t *buf, size_t n, void *priv)
 static bool run_windows_write(int dummy)
 {
        struct cli_state *cli1;
-       int fnum;
+       uint16_t fnum;
        int i;
        bool ret = false;
        const char *fname = "\\writetest.txt";
@@ -5188,8 +5132,7 @@ static bool run_windows_write(int dummy)
                return False;
        }
 
-       fnum = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
-       if (fnum == -1) {
+       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));
                return False;
        }
@@ -5228,7 +5171,7 @@ static bool run_windows_write(int dummy)
        ret = true;
  fail:
        cli_close(cli1, fnum);
-       cli_unlink(cli1, fname);
+       cli_unlink(cli1, fname, aSYSTEM | aHIDDEN);
        torture_close_connection(cli1);
        return ret;
 }
@@ -5256,6 +5199,7 @@ static bool run_uid_regression_test(int dummy)
 {
        static struct cli_state *cli;
        int16_t old_vuid;
+       int16_t old_cnum;
        bool correct = True;
 
        printf("starting uid regression test\n");
@@ -5279,19 +5223,176 @@ static bool run_uid_regression_test(int dummy)
        cli->vuid = old_vuid;
 
        /* Try an operation. */
-       if (!cli_mkdir(cli, "\\uid_reg_test")) {
+       if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\uid_reg_test"))) {
                /* We expect bad uid. */
                if (!check_error(__LINE__, cli, ERRSRV, ERRbaduid,
                                NT_STATUS_NO_SUCH_USER)) {
                        return False;
                }
-               goto out;
+       }
+
+       old_cnum = cli->cnum;
+
+       /* Now try a SMBtdis with the invald vuid set to zero. */
+       cli->vuid = 0;
+
+       /* This should succeed. */
+       if (cli_tdis(cli)) {
+               printf("First tdis with invalid vuid should succeed.\n");
+       } else {
+               printf("First tdis failed (%s)\n", cli_errstr(cli));
+       }
+
+       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");
+       } else {
+               /* Should be bad tid. */
+               if (!check_error(__LINE__, cli, ERRSRV, ERRinvnid,
+                               NT_STATUS_NETWORK_NAME_DELETED)) {
+                       return False;
+               }
        }
 
        cli_rmdir(cli, "\\uid_reg_test");
 
   out:
 
+       cli_shutdown(cli);
+       return correct;
+}
+
+
+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)
+{
+       struct cli_state *pcli = (struct cli_state *)state;
+       fstring fname;
+       slprintf(fname, sizeof(fname), "\\shortname\\%s", finfo->name);
+
+       if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
+               return;
+
+       if (finfo->mode & aDIR) {
+               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)))
+                       printf("del_fn: failed to unlink %s\n,", fname );
+       }
+}
+
+struct sn_state {
+       int i;
+       bool val;
+};
+
+static void shortname_list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
+{
+       struct sn_state *s = (struct sn_state  *)state;
+       int i = s->i;
+
+#if 0
+       printf("shortname list: i = %d, name = |%s|, shortname = |%s|\n",
+               i, finfo->name, finfo->short_name);
+#endif
+
+       if (strchr(force_shortname_chars, i)) {
+               if (!finfo->short_name[0]) {
+                       /* Shortname not created when it should be. */
+                       d_printf("(%s) ERROR: Shortname was not created for file %s\n",
+                               __location__, finfo->name);
+                       s->val = true;
+               }
+       } else if (finfo->short_name[0]){
+               /* Shortname created when it should not be. */
+               d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
+                       __location__, finfo->short_name, finfo->name);
+               s->val = true;
+       }
+}
+
+static bool run_shortname_test(int dummy)
+{
+       static struct cli_state *cli;
+       bool correct = True;
+       int i;
+       struct sn_state s;
+       char fname[20];
+
+       printf("starting shortname test\n");
+
+       if (!torture_open_connection(&cli, 0)) {
+               return False;
+       }
+
+       cli_sockopt(cli, sockops);
+
+       cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
+       cli_list(cli, "\\shortname\\*", aDIR, shortname_del_fn, cli);
+       cli_rmdir(cli, "\\shortname");
+
+       if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\shortname"))) {
+               d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
+                       __location__, cli_errstr(cli));
+               correct = false;
+               goto out;
+       }
+
+       strlcpy(fname, "\\shortname\\", sizeof(fname));
+       strlcat(fname, "test .txt", sizeof(fname));
+
+       s.val = false;
+
+       for (i = 32; i < 128; i++) {
+               NTSTATUS status;
+               uint16_t fnum = (uint16_t)-1;
+
+               s.i = i;
+
+               if (strchr(illegal_chars, i)) {
+                       continue;
+               }
+               fname[15] = i;
+
+               status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
+                                   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));
+                       correct = false;
+                       goto out;
+               }
+               cli_close(cli, fnum);
+               if (cli_list(cli, "\\shortname\\test*.*", 0, shortname_list_fn, &s) != 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))) {
+                       d_printf("(%s) failed to delete %s: %s\n",
+                               __location__, fname, cli_errstr(cli));
+                       correct = false;
+                       goto out;
+               }
+
+               if (s.val) {
+                       correct = false;
+                       goto out;
+               }
+       }
+
+  out:
+
+       cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
+       cli_list(cli, "\\shortname\\*", aDIR, shortname_del_fn, cli);
+       cli_rmdir(cli, "\\shortname");
        torture_close_connection(cli);
        return correct;
 }
@@ -5356,7 +5457,7 @@ static bool run_local_gencache(int dummy)
                         __location__);
                return False;
        }
-                       
+
        if (gencache_get("foo", &val, &tm)) {
                d_printf("%s: gencache_get() on deleted entry "
                         "succeeded\n", __location__);
@@ -5744,6 +5845,60 @@ static bool run_local_wbclient(int dummy)
        return result;
 }
 
+static void getaddrinfo_finished(struct tevent_req *req)
+{
+       char *name = (char *)tevent_req_callback_data_void(req);
+       struct addrinfo *ainfo;
+       int res;
+
+       res = getaddrinfo_recv(req, &ainfo);
+       if (res != 0) {
+               d_printf("gai(%s) returned %s\n", name, gai_strerror(res));
+               return;
+       }
+       d_printf("gai(%s) succeeded\n", name);
+       freeaddrinfo(ainfo);
+}
+
+static bool run_getaddrinfo_send(int dummy)
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct fncall_context *ctx;
+       struct tevent_context *ev;
+       bool result = false;
+       const char *names[4] = { "www.samba.org", "notfound.samba.org",
+                                "www.slashdot.org", "heise.de" };
+       struct tevent_req *reqs[4];
+       int i;
+
+       ev = event_context_init(frame);
+       if (ev == NULL) {
+               goto fail;
+       }
+
+       ctx = fncall_context_init(frame, 4);
+
+       for (i=0; i<ARRAY_SIZE(names); i++) {
+               reqs[i] = getaddrinfo_send(frame, ev, ctx, names[i], NULL,
+                                          NULL);
+               if (reqs[i] == NULL) {
+                       goto fail;
+               }
+               tevent_req_set_callback(reqs[i], getaddrinfo_finished,
+                                       (void *)names[i]);
+       }
+
+       for (i=0; i<ARRAY_SIZE(reqs); i++) {
+               tevent_loop_once(ev);
+       }
+
+       result = true;
+fail:
+       TALLOC_FREE(frame);
+       return result;
+}
+
+
 static double create_procs(bool (*fn)(int), bool *result)
 {
        int i, status;
@@ -5828,7 +5983,7 @@ static double create_procs(bool (*fn)(int), bool *result)
        }
 
        printf("\n");
-       
+
        for (i=0;i<nprocs;i++) {
                if (!child_status_out[i]) {
                        *result = False;
@@ -5876,6 +6031,7 @@ static struct {
        {"OPEN", run_opentest, 0},
        {"POSIX", run_simple_posix_open_test, 0},
        { "UID-REGRESSION-TEST", run_uid_regression_test, 0},
+       { "SHORTNAME-TEST", run_shortname_test, 0},
 #if 1
        {"OPENATTR", run_openattrtest, 0},
 #endif
@@ -5899,8 +6055,10 @@ static struct {
        { "EATEST", run_eatest, 0},
        { "SESSSETUP_BENCH", run_sesssetup_bench, 0},
        { "CHAIN1", run_chain1, 0},
+       { "CHAIN2", run_chain2, 0},
        { "WINDOWS-WRITE", run_windows_write, 0},
        { "CLI_ECHO", run_cli_echo, 0},
+       { "GETADDRINFO", run_getaddrinfo_send, 0},
        { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
        { "LOCAL-GENCACHE", run_local_gencache, 0},
        { "LOCAL-RBTREE", run_local_rbtree, 0},
@@ -5927,7 +6085,7 @@ static bool run_test(const char *name)
                }
                found = True;
        }
-       
+
        for (i=0;torture_ops[i].name;i++) {
                fstr_sprintf(randomfname, "\\XX%x", 
                         (unsigned)random());
@@ -5941,7 +6099,6 @@ static bool run_test(const char *name)
                                        ret = False;
                                        printf("TEST %s FAILED!\n", name);
                                }
-                                        
                        } else {
                                start_timer();
                                if (!torture_ops[i].fn(0)) {
@@ -5996,7 +6153,7 @@ static void usage(void)
        printf("\n");
 
        printf("default test is ALL\n");
-       
+
        exit(1);
 }
 
@@ -6036,7 +6193,7 @@ static void usage(void)
         for(p = argv[1]; *p; p++)
           if(*p == '\\')
             *p = '/';
+
        if (strncmp(argv[1], "//", 2)) {
                usage();
        }