Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

Location:
vendor/current/source3/torture
Files:
19 added
7 deleted
23 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/torture/cmd_vfs.c

    r740 r988  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   VFS module functions
     
    1010   the Free Software Foundation; either version 3 of the License, or
    1111   (at your option) any later version.
    12    
     12
    1313   This program is distributed in the hope that it will be useful,
    1414   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1515   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1616   GNU General Public License for more details.
    17    
     17
    1818   You should have received a copy of the GNU General Public License
    1919   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2626#include "vfstest.h"
    2727#include "../lib/util/util_pw.h"
     28#include "libcli/security/security.h"
     29#include "passdb/machine_sid.h"
    2830
    2931static const char *null_string = "";
     
    3234{
    3335        int i;
    34        
     36
    3537        if (argc < 2) {
    3638                printf("Usage: load <modules>\n");
     
    5860        c = argv[1][0];
    5961        size = atoi(argv[2]);
    60         vfs->data = TALLOC_ARRAY(mem_ctx, char, size);
     62        vfs->data = talloc_array(mem_ctx, char, size);
    6163        if (vfs->data == NULL) {
    6264                printf("populate: error=-1 (not enough memory)");
     
    9294                return NT_STATUS_UNSUCCESSFUL;
    9395        }
    94         dump_data(0, (uint8 *)(vfs->data) + offset, len);
     96        dump_data(0, (uint8_t *)(vfs->data) + offset, len);
    9597        return NT_STATUS_OK;
    9698}
     
    98100static NTSTATUS cmd_connect(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
    99101{
    100         SMB_VFS_CONNECT(vfs->conn, lp_servicename(SNUM(vfs->conn)), "vfstest");
     102        SMB_VFS_CONNECT(vfs->conn, lp_servicename(talloc_tos(), SNUM(vfs->conn)), "vfstest");
    101103        return NT_STATUS_OK;
    102104}
     
    116118        }
    117119
    118         diskfree = SMB_VFS_DISK_FREE(vfs->conn, argv[1], False, &bsize, &dfree, &dsize);
     120        diskfree = SMB_VFS_DISK_FREE(vfs->conn, argv[1], &bsize, &dfree, &dsize);
    119121        printf("disk_free: %lu, bsize = %lu, dfree = %lu, dsize = %lu\n",
    120122                        (unsigned long)diskfree,
     
    147149{
    148150        SMB_STRUCT_STAT st;
    149         SMB_STRUCT_DIRENT *dent = NULL;
     151        struct dirent *dent = NULL;
    150152
    151153        if (vfs->currentdir == NULL) {
     
    208210                return NT_STATUS_UNSUCCESSFUL;
    209211        }
    210        
     212
    211213        printf("mkdir: ok\n");
    212214        return NT_STATUS_OK;
     
    217219{
    218220        int ret;
    219        
     221
    220222        if (vfs->currentdir == NULL) {
    221223                printf("closedir: failure (no directory open)\n");
     
    243245        struct smb_filename *smb_fname = NULL;
    244246        NTSTATUS status;
     247        int ret;
    245248
    246249        mode = 00400;
     
    318321        }
    319322
    320         fsp = SMB_MALLOC_P(struct files_struct);
     323        fsp = talloc_zero(vfs, struct files_struct);
    321324        if (fsp == NULL) {
    322325                return NT_STATUS_NO_MEMORY;
    323326        }
    324         fsp->fh = SMB_MALLOC_P(struct fd_handle);
     327        fsp->fh = talloc_zero(fsp, struct fd_handle);
    325328        if (fsp->fh == NULL) {
    326                 SAFE_FREE(fsp->fsp_name);
    327                 SAFE_FREE(fsp);
     329                TALLOC_FREE(fsp);
    328330                return NT_STATUS_NO_MEMORY;
    329331        }
    330332        fsp->conn = vfs->conn;
    331333
    332         status = create_synthetic_smb_fname_split(mem_ctx, argv[1], NULL,
    333                                                   &smb_fname);
    334         if (!NT_STATUS_IS_OK(status)) {
    335                 SAFE_FREE(fsp);
    336                 return status;
     334        smb_fname = synthetic_smb_fname_split(NULL, argv[1], NULL);
     335        if (smb_fname == NULL) {
     336                TALLOC_FREE(fsp);
     337                return NT_STATUS_NO_MEMORY;
    337338        }
    338339
     
    342343        if (fsp->fh->fd == -1) {
    343344                printf("open: error=%d (%s)\n", errno, strerror(errno));
    344                 SAFE_FREE(fsp->fh);
    345                 SAFE_FREE(fsp);
     345                TALLOC_FREE(fsp);
    346346                TALLOC_FREE(smb_fname);
    347347                return NT_STATUS_UNSUCCESSFUL;
    348348        }
     349
     350        status = NT_STATUS_OK;
     351        ret = SMB_VFS_FSTAT(fsp, &smb_fname->st);
     352        if (ret == -1) {
     353                /* If we have an fd, this stat should succeed. */
     354                DEBUG(0,("Error doing fstat on open file %s "
     355                         "(%s)\n",
     356                         smb_fname_str_dbg(smb_fname),
     357                         strerror(errno) ));
     358                status = map_nt_error_from_unix(errno);
     359        } else if (S_ISDIR(smb_fname->st.st_ex_mode)) {
     360                errno = EISDIR;
     361                status = NT_STATUS_FILE_IS_A_DIRECTORY;
     362        }
     363
     364        if (!NT_STATUS_IS_OK(status)) {
     365                SMB_VFS_CLOSE(fsp);
     366                TALLOC_FREE(fsp);
     367                TALLOC_FREE(smb_fname);
     368                return status;
     369        }
     370
     371        fsp->file_id = vfs_file_id_from_sbuf(vfs->conn, &smb_fname->st);
     372        fsp->vuid = UID_FIELD_INVALID;
     373        fsp->file_pid = 0;
     374        fsp->can_lock = True;
     375        fsp->can_read = True;
     376        fsp->can_write =
     377                CAN_WRITE(vfs->conn);
     378        fsp->print_file = NULL;
     379        fsp->modified = False;
     380        fsp->sent_oplock_break = NO_BREAK_SENT;
     381        fsp->is_directory = False;
    349382
    350383        vfs->files[fsp->fh->fd] = fsp;
     
    366399                ret = SMB_VFS_RMDIR(vfs->conn, argv[1]);
    367400        } else if (strcmp("unlink", argv[0]) == 0 ) {
    368                 struct smb_filename *smb_fname = NULL;
    369                 NTSTATUS status;
    370 
    371                 status = create_synthetic_smb_fname_split(mem_ctx, argv[1],
    372                                                           NULL, &smb_fname);
    373                 if (!NT_STATUS_IS_OK(status)) {
    374                         return status;
     401                struct smb_filename *smb_fname;
     402
     403                smb_fname = synthetic_smb_fname_split(mem_ctx, argv[1], NULL);
     404                if (smb_fname == NULL) {
     405                        return NT_STATUS_NO_MEMORY;
    375406                }
    376407
     
    415446                printf("close: ok\n");
    416447
    417         TALLOC_FREE(vfs->files[fd]->fsp_name);
    418         SAFE_FREE(vfs->files[fd]->fh);
    419         SAFE_FREE(vfs->files[fd]);
     448        TALLOC_FREE(vfs->files[fd]);
    420449        vfs->files[fd] = NULL;
    421450        return NT_STATUS_OK;
     
    436465        fd = atoi(argv[1]);
    437466        size = atoi(argv[2]);
    438         vfs->data = TALLOC_ARRAY(mem_ctx, char, size);
     467        vfs->data = talloc_array(mem_ctx, char, size);
    439468        if (vfs->data == NULL) {
    440469                printf("read: error=-1 (not enough memory)");
     
    442471        }
    443472        vfs->data_size = size;
    444        
     473
    445474        rsize = SMB_VFS_READ(vfs->files[fd], vfs->data, size);
    446475        if (rsize == -1) {
     
    491520{
    492521        int fd, offset, whence;
    493         SMB_OFF_T pos;
     522        off_t pos;
    494523
    495524        if (argc != 4) {
     
    508537
    509538        pos = SMB_VFS_LSEEK(vfs->files[fd], offset, whence);
    510         if (pos == (SMB_OFF_T)-1) {
     539        if (pos == (off_t)-1) {
    511540                printf("lseek: error=%d (%s)\n", errno, strerror(errno));
    512541                return NT_STATUS_UNSUCCESSFUL;
     
    523552        struct smb_filename *smb_fname_src = NULL;
    524553        struct smb_filename *smb_fname_dst = NULL;
    525         NTSTATUS status;
    526554
    527555        if (argc != 3) {
     
    530558        }
    531559
    532         status = create_synthetic_smb_fname_split(mem_ctx, argv[1], NULL,
    533                                                   &smb_fname_src);
    534         if (!NT_STATUS_IS_OK(status)) {
    535                 return status;
    536         }
    537 
    538         status = create_synthetic_smb_fname_split(mem_ctx, argv[2], NULL,
    539                                                   &smb_fname_dst);
    540         if (!NT_STATUS_IS_OK(status)) {
     560        smb_fname_src = synthetic_smb_fname_split(mem_ctx, argv[1], NULL);
     561        if (smb_fname_src == NULL) {
     562                return NT_STATUS_NO_MEMORY;
     563        }
     564
     565        smb_fname_dst = synthetic_smb_fname_split(mem_ctx, argv[2], NULL);
     566        if (smb_fname_dst == NULL) {
    541567                TALLOC_FREE(smb_fname_src);
    542                 return status;
     568                return NT_STATUS_NO_MEMORY;
    543569        }
    544570
     
    586612        SMB_STRUCT_STAT st;
    587613        time_t tmp_time;
    588         NTSTATUS status;
    589614
    590615        if (argc != 2) {
     
    593618        }
    594619
    595         status = create_synthetic_smb_fname_split(mem_ctx, argv[1], NULL,
    596                                                   &smb_fname);
    597         if (!NT_STATUS_IS_OK(status)) {
    598                 return status;
     620        smb_fname = synthetic_smb_fname_split(mem_ctx, argv[1], NULL);
     621        if (smb_fname == NULL) {
     622                return NT_STATUS_NO_MEMORY;
    599623        }
    600624
     
    608632        TALLOC_FREE(smb_fname);
    609633
    610         pwd = sys_getpwuid(st.st_ex_uid);
     634        pwd = getpwuid(st.st_ex_uid);
    611635        if (pwd != NULL) user = pwd->pw_name;
    612636        else user = null_string;
    613         grp = sys_getgrgid(st.st_ex_gid);
     637        grp = getgrgid(st.st_ex_gid);
    614638        if (grp != NULL) group = grp->gr_name;
    615639        else group = null_string;
     
    679703        }
    680704
    681         pwd = sys_getpwuid(st.st_ex_uid);
     705        pwd = getpwuid(st.st_ex_uid);
    682706        if (pwd != NULL) user = pwd->pw_name;
    683707        else user = null_string;
    684         grp = sys_getgrgid(st.st_ex_gid);
     708        grp = getgrgid(st.st_ex_gid);
    685709        if (grp != NULL) group = grp->gr_name;
    686710        else group = null_string;
     
    727751        SMB_STRUCT_STAT st;
    728752        time_t tmp_time;
    729         NTSTATUS status;
    730753
    731754        if (argc != 2) {
     
    734757        }
    735758
    736         status = create_synthetic_smb_fname_split(mem_ctx, argv[1], NULL,
    737                                                   &smb_fname);
    738         if (!NT_STATUS_IS_OK(status)) {
    739                 return status;
     759        smb_fname = synthetic_smb_fname_split(mem_ctx, argv[1], NULL);
     760        if (smb_fname == NULL) {
     761                return NT_STATUS_NO_MEMORY;
    740762        }
    741763
     
    748770        TALLOC_FREE(smb_fname);
    749771
    750         pwd = sys_getpwuid(st.st_ex_uid);
     772        pwd = getpwuid(st.st_ex_uid);
    751773        if (pwd != NULL) user = pwd->pw_name;
    752774        else user = null_string;
    753         grp = sys_getgrgid(st.st_ex_gid);
     775        grp = getgrgid(st.st_ex_gid);
    754776        if (grp != NULL) group = grp->gr_name;
    755777        else group = null_string;
     
    782804        tmp_time = convert_timespec_to_time_t(st.st_ex_ctime);
    783805        printf("  Change: %s", ctime(&tmp_time));
    784        
     806
    785807        return NT_STATUS_OK;
    786808}
     
    832854
    833855        printf("fchmod: ok\n");
     856        return NT_STATUS_OK;
     857}
     858
     859
     860static NTSTATUS cmd_chmod_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
     861{
     862        mode_t mode;
     863        if (argc != 3) {
     864                printf("Usage: chmod_acl <path> <mode>\n");
     865                return NT_STATUS_OK;
     866        }
     867
     868        mode = atoi(argv[2]);
     869        if (SMB_VFS_CHMOD_ACL(vfs->conn, argv[1], mode) == -1) {
     870                printf("chmod_acl: error=%d (%s)\n", errno, strerror(errno));
     871                return NT_STATUS_UNSUCCESSFUL;
     872        }
     873
     874        printf("chmod_acl: ok\n");
     875        return NT_STATUS_OK;
     876}
     877
     878
     879static NTSTATUS cmd_fchmod_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
     880{
     881        int fd;
     882        mode_t mode;
     883        if (argc != 3) {
     884                printf("Usage: fchmod_acl <fd> <mode>\n");
     885                return NT_STATUS_OK;
     886        }
     887
     888        fd = atoi(argv[1]);
     889        mode = atoi(argv[2]);
     890        if (fd < 0 || fd >= 1024) {
     891                printf("fchmod_acl: error=%d (file descriptor out of range)\n", EBADF);
     892                return NT_STATUS_OK;
     893        }
     894        if (vfs->files[fd] == NULL) {
     895                printf("fchmod_acl: error=%d (invalid file descriptor)\n", EBADF);
     896                return NT_STATUS_OK;
     897        }
     898
     899        if (SMB_VFS_FCHMOD_ACL(vfs->files[fd], mode) == -1) {
     900                printf("fchmod_acl: error=%d (%s)\n", errno, strerror(errno));
     901                return NT_STATUS_UNSUCCESSFUL;
     902        }
     903
     904        printf("fchmod_acl: ok\n");
    834905        return NT_STATUS_OK;
    835906}
     
    890961static NTSTATUS cmd_getwd(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
    891962{
    892         char buf[PATH_MAX];
    893         if (SMB_VFS_GETWD(vfs->conn, buf) == NULL) {
     963        char *buf = SMB_VFS_GETWD(vfs->conn);
     964        if (buf == NULL) {
    894965                printf("getwd: error=%d (%s)\n", errno, strerror(errno));
    895966                return NT_STATUS_UNSUCCESSFUL;
     
    897968
    898969        printf("getwd: %s\n", buf);
     970        SAFE_FREE(buf);
    899971        return NT_STATUS_OK;
    900972}
     
    904976        struct smb_file_time ft;
    905977        struct smb_filename *smb_fname = NULL;
    906         NTSTATUS status;
    907978
    908979        if (argc != 4) {
     
    916987        ft.mtime = convert_time_t_to_timespec(atoi(argv[3]));
    917988
    918         status = create_synthetic_smb_fname_split(mem_ctx, argv[1],
    919                                                   NULL, &smb_fname);
    920         if (!NT_STATUS_IS_OK(status)) {
    921                 return status;
     989        smb_fname = synthetic_smb_fname_split(mem_ctx, argv[1], NULL);
     990        if (smb_fname == NULL) {
     991                return NT_STATUS_NO_MEMORY;
    922992        }
    923993
     
    9361006{
    9371007        int fd;
    938         SMB_OFF_T off;
     1008        off_t off;
    9391009        if (argc != 3) {
    9401010                printf("Usage: ftruncate <fd> <length>\n");
     
    9701040        int type;
    9711041        const char *typestr;
    972        
     1042
    9731043        if (argc != 6) {
    9741044                printf("Usage: lock <fd> <op> <offset> <count> <type>\n");
     
    11031173        unsigned int dev_val;
    11041174        SMB_DEV_T dev;
    1105        
     1175
    11061176        if (argc != 4) {
    11071177                printf("Usage: mknod <path> <mode> <dev>\n");
     
    11461216        return NT_STATUS_OK;
    11471217}
     1218
     1219static NTSTATUS cmd_getxattr(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
     1220                             int argc, const char **argv)
     1221{
     1222        uint8_t *buf;
     1223        ssize_t ret;
     1224
     1225        if (argc != 3) {
     1226                printf("Usage: getxattr <path> <xattr>\n");
     1227                return NT_STATUS_OK;
     1228        }
     1229
     1230        buf = NULL;
     1231
     1232        ret = SMB_VFS_GETXATTR(vfs->conn, argv[1], argv[2], buf,
     1233                               talloc_get_size(buf));
     1234        if (ret == -1) {
     1235                int err = errno;
     1236                printf("getxattr returned (%s)\n", strerror(err));
     1237                return map_nt_error_from_unix(err);
     1238        }
     1239        buf = talloc_array(mem_ctx, uint8_t, ret);
     1240        if (buf == NULL) {
     1241                return NT_STATUS_NO_MEMORY;
     1242        }
     1243        ret = SMB_VFS_GETXATTR(vfs->conn, argv[1], argv[2], buf,
     1244                               talloc_get_size(buf));
     1245        if (ret == -1) {
     1246                int err = errno;
     1247                printf("getxattr returned (%s)\n", strerror(err));
     1248                return map_nt_error_from_unix(err);
     1249        }
     1250        dump_data_file(buf, talloc_get_size(buf), false, stdout);
     1251        return NT_STATUS_OK;
     1252}
     1253
     1254static NTSTATUS cmd_listxattr(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
     1255                              int argc, const char **argv)
     1256{
     1257        char *buf, *p;
     1258        ssize_t ret;
     1259
     1260        if (argc != 2) {
     1261                printf("Usage: listxattr <path>\n");
     1262                return NT_STATUS_OK;
     1263        }
     1264
     1265        buf = NULL;
     1266
     1267        ret = SMB_VFS_LISTXATTR(vfs->conn, argv[1], buf, talloc_get_size(buf));
     1268        if (ret == -1) {
     1269                int err = errno;
     1270                printf("listxattr returned (%s)\n", strerror(err));
     1271                return map_nt_error_from_unix(err);
     1272        }
     1273        buf = talloc_array(mem_ctx, char, ret);
     1274        if (buf == NULL) {
     1275                return NT_STATUS_NO_MEMORY;
     1276        }
     1277        ret = SMB_VFS_LISTXATTR(vfs->conn, argv[1], buf, talloc_get_size(buf));
     1278        if (ret == -1) {
     1279                int err = errno;
     1280                printf("listxattr returned (%s)\n", strerror(err));
     1281                return map_nt_error_from_unix(err);
     1282        }
     1283        if (ret == 0) {
     1284                return NT_STATUS_OK;
     1285        }
     1286        if (buf[ret-1] != '\0') {
     1287                printf("listxattr returned non 0-terminated strings\n");
     1288                return NT_STATUS_INTERNAL_ERROR;
     1289        }
     1290
     1291        p = buf;
     1292        while (p < buf+ret) {
     1293                printf("%s\n", p);
     1294                p = strchr(p, 0);
     1295                p += 1;
     1296        }
     1297        return NT_STATUS_OK;
     1298}
     1299
     1300static NTSTATUS cmd_setxattr(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
     1301                             int argc, const char **argv)
     1302{
     1303        ssize_t ret;
     1304        int flags = 0;
     1305
     1306        if ((argc < 4) || (argc > 5)) {
     1307                printf("Usage: setxattr <path> <xattr> <value> [flags]\n");
     1308                return NT_STATUS_OK;
     1309        }
     1310
     1311        if (argc == 5) {
     1312                flags = atoi(argv[4]);
     1313        }
     1314
     1315        ret = SMB_VFS_SETXATTR(vfs->conn, argv[1], argv[2],
     1316                               argv[3], strlen(argv[3]), flags);
     1317        if (ret == -1) {
     1318                int err = errno;
     1319                printf("setxattr returned (%s)\n", strerror(err));
     1320                return map_nt_error_from_unix(err);
     1321        }
     1322        return NT_STATUS_OK;
     1323}
     1324
     1325static NTSTATUS cmd_removexattr(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
     1326                                int argc, const char **argv)
     1327{
     1328        ssize_t ret;
     1329
     1330        if (argc != 3) {
     1331                printf("Usage: removexattr <path> <xattr>\n");
     1332                return NT_STATUS_OK;
     1333        }
     1334
     1335        ret = SMB_VFS_REMOVEXATTR(vfs->conn, argv[1], argv[2]);
     1336        if (ret == -1) {
     1337                int err = errno;
     1338                printf("removexattr returned (%s)\n", strerror(err));
     1339                return map_nt_error_from_unix(err);
     1340        }
     1341        return NT_STATUS_OK;
     1342}
     1343
     1344static NTSTATUS cmd_fget_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
     1345                                int argc, const char **argv)
     1346{
     1347        int fd;
     1348        NTSTATUS status;
     1349        struct security_descriptor *sd;
     1350
     1351        if (argc != 2) {
     1352                printf("Usage: fget_nt_acl <fd>\n");
     1353                return NT_STATUS_OK;
     1354        }
     1355
     1356        fd = atoi(argv[1]);
     1357        if (fd < 0 || fd >= 1024) {
     1358                printf("fget_nt_acl: error=%d (file descriptor out of range)\n", EBADF);
     1359                return NT_STATUS_OK;
     1360        }
     1361        if (vfs->files[fd] == NULL) {
     1362                printf("fget_nt_acl: error=%d (invalid file descriptor)\n", EBADF);
     1363                return NT_STATUS_OK;
     1364        }
     1365
     1366        status = SMB_VFS_FGET_NT_ACL(vfs->files[fd],
     1367                                     SECINFO_OWNER | SECINFO_GROUP | SECINFO_DACL,
     1368                                     talloc_tos(), &sd);
     1369        if (!NT_STATUS_IS_OK(status)) {
     1370                printf("fget_nt_acl returned (%s)\n", nt_errstr(status));
     1371                return status;
     1372        }
     1373        printf("%s\n", sddl_encode(talloc_tos(), sd, get_global_sam_sid()));
     1374        TALLOC_FREE(sd);
     1375        return NT_STATUS_OK;
     1376}
     1377
     1378static NTSTATUS cmd_get_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
     1379                               int argc, const char **argv)
     1380{
     1381        NTSTATUS status;
     1382        struct security_descriptor *sd;
     1383
     1384        if (argc != 2) {
     1385                printf("Usage: get_nt_acl <path>\n");
     1386                return NT_STATUS_OK;
     1387        }
     1388
     1389        status = SMB_VFS_GET_NT_ACL(vfs->conn, argv[1],
     1390                                    SECINFO_OWNER | SECINFO_GROUP | SECINFO_DACL,
     1391                                    talloc_tos(), &sd);
     1392        if (!NT_STATUS_IS_OK(status)) {
     1393                printf("get_nt_acl returned (%s)\n", nt_errstr(status));
     1394                return status;
     1395        }
     1396        printf("%s\n", sddl_encode(talloc_tos(), sd, get_global_sam_sid()));
     1397        TALLOC_FREE(sd);
     1398        return NT_STATUS_OK;
     1399}
     1400
     1401static NTSTATUS cmd_fset_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
     1402                                int argc, const char **argv)
     1403{
     1404        int fd;
     1405        NTSTATUS status;
     1406        struct security_descriptor *sd;
     1407
     1408        if (argc != 3) {
     1409                printf("Usage: fset_nt_acl <fd> <sddl>\n");
     1410                return NT_STATUS_OK;
     1411        }
     1412
     1413        fd = atoi(argv[1]);
     1414        if (fd < 0 || fd >= 1024) {
     1415                printf("fset_nt_acl: error=%d (file descriptor out of range)\n", EBADF);
     1416                return NT_STATUS_OK;
     1417        }
     1418        if (vfs->files[fd] == NULL) {
     1419                printf("fset_nt_acl: error=%d (invalid file descriptor)\n", EBADF);
     1420                return NT_STATUS_OK;
     1421        }
     1422
     1423        sd = sddl_decode(talloc_tos(), argv[2], get_global_sam_sid());
     1424        if (!sd) {
     1425                printf("sddl_decode failed to parse %s as SDDL\n", argv[2]);
     1426                return NT_STATUS_INVALID_PARAMETER;
     1427        }
     1428
     1429        status = SMB_VFS_FSET_NT_ACL(vfs->files[fd], SECINFO_OWNER | SECINFO_GROUP | SECINFO_DACL, sd);
     1430        if (!NT_STATUS_IS_OK(status)) {
     1431                printf("fset_nt_acl returned (%s)\n", nt_errstr(status));
     1432                return status;
     1433        }
     1434        TALLOC_FREE(sd);
     1435        return NT_STATUS_OK;
     1436}
     1437
     1438static NTSTATUS cmd_set_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
     1439{
     1440        int flags;
     1441        int ret;
     1442        mode_t mode;
     1443        files_struct *fsp;
     1444        struct smb_filename *smb_fname = NULL;
     1445        NTSTATUS status;
     1446        struct security_descriptor *sd = NULL;
     1447
     1448        if (argc != 3) {
     1449                printf("Usage: set_nt_acl <file> <sddl>\n");
     1450                return NT_STATUS_OK;
     1451        }
     1452
     1453        mode = 00400;
     1454
     1455        fsp = talloc_zero(vfs, struct files_struct);
     1456        if (fsp == NULL) {
     1457                return NT_STATUS_NO_MEMORY;
     1458        }
     1459        fsp->fh = talloc_zero(fsp, struct fd_handle);
     1460        if (fsp->fh == NULL) {
     1461                TALLOC_FREE(fsp);
     1462                return NT_STATUS_NO_MEMORY;
     1463        }
     1464        fsp->conn = vfs->conn;
     1465
     1466        smb_fname = synthetic_smb_fname_split(NULL, argv[1], NULL);
     1467        if (smb_fname == NULL) {
     1468                TALLOC_FREE(fsp);
     1469                return NT_STATUS_NO_MEMORY;
     1470        }
     1471
     1472        fsp->fsp_name = smb_fname;
     1473
     1474#ifdef O_DIRECTORY
     1475        flags = O_RDONLY|O_DIRECTORY;
     1476#else
     1477        /* POSIX allows us to open a directory with O_RDONLY. */
     1478        flags = O_RDONLY;
     1479#endif
     1480
     1481        fsp->fh->fd = SMB_VFS_OPEN(vfs->conn, smb_fname, fsp, O_RDWR, mode);
     1482        if (fsp->fh->fd == -1 && errno == EISDIR) {
     1483                fsp->fh->fd = SMB_VFS_OPEN(vfs->conn, smb_fname, fsp, flags, mode);
     1484        }
     1485        if (fsp->fh->fd == -1) {
     1486                printf("open: error=%d (%s)\n", errno, strerror(errno));
     1487                TALLOC_FREE(fsp);
     1488                TALLOC_FREE(smb_fname);
     1489                return NT_STATUS_UNSUCCESSFUL;
     1490        }
     1491
     1492        status = NT_STATUS_OK;
     1493        ret = SMB_VFS_FSTAT(fsp, &smb_fname->st);
     1494        if (ret == -1) {
     1495                /* If we have an fd, this stat should succeed. */
     1496                DEBUG(0,("Error doing fstat on open file %s "
     1497                         "(%s)\n",
     1498                         smb_fname_str_dbg(smb_fname),
     1499                         strerror(errno) ));
     1500                status = map_nt_error_from_unix(errno);
     1501        }
     1502       
     1503        if (!NT_STATUS_IS_OK(status)) {
     1504                goto out;
     1505        }
     1506
     1507        fsp->file_id = vfs_file_id_from_sbuf(vfs->conn, &smb_fname->st);
     1508        fsp->vuid = UID_FIELD_INVALID;
     1509        fsp->file_pid = 0;
     1510        fsp->can_lock = True;
     1511        fsp->can_read = True;
     1512        fsp->can_write = True;
     1513        fsp->print_file = NULL;
     1514        fsp->modified = False;
     1515        fsp->sent_oplock_break = NO_BREAK_SENT;
     1516        fsp->is_directory = S_ISDIR(smb_fname->st.st_ex_mode);
     1517
     1518
     1519        sd = sddl_decode(talloc_tos(), argv[2], get_global_sam_sid());
     1520        if (!sd) {
     1521                printf("sddl_decode failed to parse %s as SDDL\n", argv[2]);
     1522                status = NT_STATUS_INVALID_PARAMETER;
     1523                goto out;
     1524        }
     1525
     1526        status = SMB_VFS_FSET_NT_ACL(fsp, SECINFO_OWNER | SECINFO_GROUP | SECINFO_DACL, sd);
     1527        if (!NT_STATUS_IS_OK(status)) {
     1528                printf("fset_nt_acl returned (%s)\n", nt_errstr(status));
     1529                goto out;
     1530        }
     1531out:
     1532        TALLOC_FREE(sd);
     1533
     1534        ret = SMB_VFS_CLOSE(fsp);
     1535        if (ret == -1 )
     1536                printf("close: error=%d (%s)\n", errno, strerror(errno));
     1537
     1538        TALLOC_FREE(fsp);
     1539
     1540        return status;
     1541}
     1542
     1543
     1544
     1545static NTSTATUS cmd_sys_acl_get_fd(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
     1546                                   int argc, const char **argv)
     1547{
     1548        int fd;
     1549        SMB_ACL_T acl;
     1550        char *acl_text;
     1551
     1552        if (argc != 2) {
     1553                printf("Usage: sys_acl_get_fd <fd>\n");
     1554                return NT_STATUS_OK;
     1555        }
     1556
     1557        fd = atoi(argv[1]);
     1558        if (fd < 0 || fd >= 1024) {
     1559                printf("sys_acl_get_fd: error=%d (file descriptor out of range)\n", EBADF);
     1560                return NT_STATUS_OK;
     1561        }
     1562        if (vfs->files[fd] == NULL) {
     1563                printf("sys_acl_get_fd: error=%d (invalid file descriptor)\n", EBADF);
     1564                return NT_STATUS_OK;
     1565        }
     1566
     1567        acl = SMB_VFS_SYS_ACL_GET_FD(vfs->files[fd], talloc_tos());
     1568        if (!acl) {
     1569                printf("sys_acl_get_fd failed (%s)\n", strerror(errno));
     1570                return NT_STATUS_UNSUCCESSFUL;
     1571        }
     1572        acl_text = sys_acl_to_text(acl, NULL);
     1573        printf("%s", acl_text);
     1574        TALLOC_FREE(acl);
     1575        SAFE_FREE(acl_text);
     1576        return NT_STATUS_OK;
     1577}
     1578
     1579static NTSTATUS cmd_sys_acl_get_file(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
     1580                                     int argc, const char **argv)
     1581{
     1582        SMB_ACL_T acl;
     1583        char *acl_text;
     1584        int type;
     1585        if (argc != 3) {
     1586                printf("Usage: sys_acl_get_file <path> <type>\n");
     1587                return NT_STATUS_OK;
     1588        }
     1589
     1590        type = atoi(argv[2]);
     1591        acl = SMB_VFS_SYS_ACL_GET_FILE(vfs->conn, argv[1], type, talloc_tos());
     1592        if (!acl) {
     1593                printf("sys_acl_get_file failed (%s)\n", strerror(errno));
     1594                return NT_STATUS_UNSUCCESSFUL;
     1595        }
     1596        acl_text = sys_acl_to_text(acl, NULL);
     1597        printf("%s", acl_text);
     1598        TALLOC_FREE(acl);
     1599        SAFE_FREE(acl_text);
     1600        return NT_STATUS_OK;
     1601}
     1602
     1603static NTSTATUS cmd_sys_acl_blob_get_file(struct vfs_state *vfs,
     1604                                          TALLOC_CTX *mem_ctx,
     1605                                          int argc, const char **argv)
     1606{
     1607        char *description;
     1608        DATA_BLOB blob;
     1609        int ret;
     1610        size_t i;
     1611
     1612        if (argc != 2) {
     1613                printf("Usage: sys_acl_get_file <path>\n");
     1614                return NT_STATUS_OK;
     1615        }
     1616
     1617        ret = SMB_VFS_SYS_ACL_BLOB_GET_FILE(vfs->conn, argv[1], talloc_tos(),
     1618                                            &description, &blob);
     1619        if (ret != 0) {
     1620                printf("sys_acl_blob_get_file failed (%s)\n", strerror(errno));
     1621                return map_nt_error_from_unix(errno);
     1622        }
     1623        printf("Description: %s\n", description);
     1624        for (i = 0; i < blob.length; i++) {
     1625                printf("%.2x ", blob.data[i]);
     1626        }
     1627        printf("\n");
     1628
     1629        return NT_STATUS_OK;
     1630}
     1631
     1632static NTSTATUS cmd_sys_acl_blob_get_fd(struct vfs_state *vfs,
     1633                                        TALLOC_CTX *mem_ctx,
     1634                                        int argc, const char **argv)
     1635{
     1636        int fd;
     1637        char *description;
     1638        DATA_BLOB blob;
     1639        int ret;
     1640        size_t i;
     1641
     1642        if (argc != 2) {
     1643                printf("Usage: sys_acl_blob_get_fd <fd>\n");
     1644                return NT_STATUS_OK;
     1645        }
     1646
     1647        fd = atoi(argv[1]);
     1648        if (fd < 0 || fd >= 1024) {
     1649                printf("sys_acl_blob_get_fd: error=%d "
     1650                       "(file descriptor out of range)\n", EBADF);
     1651                return NT_STATUS_OK;
     1652        }
     1653        if (vfs->files[fd] == NULL) {
     1654                printf("sys_acl_blob_get_fd: error=%d "
     1655                       "(invalid file descriptor)\n", EBADF);
     1656                return NT_STATUS_OK;
     1657        }
     1658
     1659        ret = SMB_VFS_SYS_ACL_BLOB_GET_FD(vfs->files[fd], talloc_tos(),
     1660                                          &description, &blob);
     1661        if (ret != 0) {
     1662                printf("sys_acl_blob_get_fd failed (%s)\n", strerror(errno));
     1663                return map_nt_error_from_unix(errno);
     1664        }
     1665        printf("Description: %s\n", description);
     1666        for (i = 0; i < blob.length; i++) {
     1667                printf("%.2x ", blob.data[i]);
     1668        }
     1669        printf("\n");
     1670
     1671        return NT_STATUS_OK;
     1672}
     1673
     1674
     1675
     1676static NTSTATUS cmd_sys_acl_delete_def_file(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
     1677                                            int argc, const char **argv)
     1678{
     1679        int ret;
     1680
     1681        if (argc != 2) {
     1682                printf("Usage: sys_acl_delete_def_file <path>\n");
     1683                return NT_STATUS_OK;
     1684        }
     1685
     1686        ret = SMB_VFS_SYS_ACL_DELETE_DEF_FILE(vfs->conn, argv[1]);
     1687        if (ret == -1) {
     1688                printf("sys_acl_delete_def_file failed (%s)\n", strerror(errno));
     1689                return NT_STATUS_UNSUCCESSFUL;
     1690        }
     1691        return NT_STATUS_OK;
     1692}
     1693
     1694/* Afaik translate name was first introduced with vfs_catia, to be able
     1695   to translate unix file/dir-names, containing invalid windows characters,
     1696   to valid windows names.
     1697   The used translation direction is always unix --> windows
     1698*/
     1699static NTSTATUS cmd_translate_name(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
     1700                                            int argc, const char **argv)
     1701{
     1702        int ret;
     1703        struct dirent *dent = NULL;
     1704        SMB_STRUCT_STAT st;
     1705        bool found = false;
     1706        char *translated = NULL;
     1707        NTSTATUS status;
     1708
     1709        if (argc != 2) {
     1710                DEBUG(0, ("Usage: translate_name unix_filename\n"));
     1711                return NT_STATUS_UNSUCCESSFUL;
     1712        }
     1713
     1714        vfs->currentdir = SMB_VFS_OPENDIR(vfs->conn, ".", NULL, 0);
     1715        if (vfs->currentdir == NULL) {
     1716                DEBUG(0, ("cmd_translate_name: opendir error=%d (%s)\n",
     1717                          errno, strerror(errno)));
     1718                return NT_STATUS_UNSUCCESSFUL;
     1719        }
     1720
     1721        while (true) {
     1722                dent = SMB_VFS_READDIR(vfs->conn, vfs->currentdir, &st);
     1723                if (dent == NULL) {
     1724                        break;
     1725                }
     1726                if (strcmp (dent->d_name, argv[1]) == 0) {
     1727                        found = true;
     1728                        break;
     1729                }
     1730        };
     1731
     1732        if (!found) {
     1733                DEBUG(0, ("cmd_translate_name: file '%s' not found.\n",
     1734                          argv[1]));
     1735                status = NT_STATUS_UNSUCCESSFUL;
     1736                goto cleanup;
     1737        }
     1738        status = SMB_VFS_TRANSLATE_NAME(vfs->conn, dent->d_name,
     1739                                        vfs_translate_to_windows,
     1740                                        talloc_tos(), &translated);
     1741        if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
     1742                DEBUG(0, ("cmd_translate_name: file '%s' cannot be "
     1743                          "translated\n", argv[1]));
     1744                TALLOC_FREE(translated);
     1745                goto cleanup;
     1746        }
     1747        /* translation success. But that could also mean
     1748           that translating "aaa" to "aaa" was successful :-(
     1749        */
     1750        DEBUG(0, ("cmd_translate_name: file '%s' --> '%s'\n",
     1751                  argv[1], translated));
     1752
     1753        TALLOC_FREE(translated);
     1754
     1755cleanup:
     1756        ret = SMB_VFS_CLOSEDIR(vfs->conn, vfs->currentdir);
     1757        if (ret == -1) {
     1758                DEBUG(0, ("cmd_translate_name: closedir failure: %s\n",
     1759                          strerror(errno)));
     1760                return NT_STATUS_UNSUCCESSFUL;
     1761        }
     1762
     1763        vfs->currentdir = NULL;
     1764        return status;;
     1765}
     1766
    11481767
    11491768struct cmd_set vfs_commands[] = {
     
    11621781        { "rmdir",   cmd_pathfunc,   "VFS rmdir()",    "rmdir <path>" },
    11631782        { "closedir",   cmd_closedir,   "VFS closedir()",    "closedir" },
    1164         { "open",   cmd_open,   "VFS open()",    "open <fname>" },
     1783        { "open",   cmd_open,   "VFS open()",    "open <fname> <flags> <mode>" },
    11651784        { "close",   cmd_close,   "VFS close()",    "close <fd>" },
    11661785        { "read",   cmd_read,   "VFS read()",    "read <fd> <size>" },
     
    11871806        { "mknod",   cmd_mknod,   "VFS mknod()",    "mknod <path> <mode> <dev>" },
    11881807        { "realpath",   cmd_realpath,   "VFS realpath()",    "realpath <path>" },
     1808        { "getxattr", cmd_getxattr, "VFS getxattr()",
     1809          "getxattr <path> <name>" },
     1810        { "listxattr", cmd_listxattr, "VFS listxattr()",
     1811          "listxattr <path>" },
     1812        { "setxattr", cmd_setxattr, "VFS setxattr()",
     1813          "setxattr <path> <name> <value> [<flags>]" },
     1814        { "removexattr", cmd_removexattr, "VFS removexattr()",
     1815          "removexattr <path> <name>\n" },
     1816        { "fget_nt_acl", cmd_fget_nt_acl, "VFS fget_nt_acl()",
     1817          "fget_nt_acl <fd>\n" },
     1818        { "get_nt_acl", cmd_get_nt_acl, "VFS get_nt_acl()",
     1819          "get_nt_acl <path>\n" },
     1820        { "fset_nt_acl", cmd_fset_nt_acl, "VFS fset_nt_acl()",
     1821          "fset_nt_acl <fd>\n" },
     1822        { "set_nt_acl", cmd_set_nt_acl, "VFS open() and fset_nt_acl()",
     1823          "set_nt_acl <file>\n" },
     1824        { "fchmod_acl",   cmd_fchmod_acl,   "VFS fchmod_acl()",    "fchmod_acl <fd> <mode>" },
     1825        { "chmod_acl",   cmd_chmod_acl,   "VFS chmod_acl()",    "chmod_acl <path> <mode>" },
     1826        { "sys_acl_get_file", cmd_sys_acl_get_file, "VFS sys_acl_get_file()", "sys_acl_get_file <path>" },
     1827        { "sys_acl_get_fd", cmd_sys_acl_get_fd, "VFS sys_acl_get_fd()", "sys_acl_get_fd <fd>" },
     1828        { "sys_acl_blob_get_file", cmd_sys_acl_blob_get_file,
     1829          "VFS sys_acl_blob_get_file()", "sys_acl_blob_get_file <path>" },
     1830        { "sys_acl_blob_get_fd", cmd_sys_acl_blob_get_fd,
     1831          "VFS sys_acl_blob_get_fd()", "sys_acl_blob_get_fd <path>" },
     1832        { "sys_acl_delete_def_file", cmd_sys_acl_delete_def_file, "VFS sys_acl_delete_def_file()", "sys_acl_delete_def_file <path>" },
     1833
     1834
     1835        { "test_chain", cmd_test_chain, "test chain code",
     1836          "test_chain" },
     1837        { "translate_name", cmd_translate_name, "VFS translate_name()", "translate_name unix_filename" },
    11891838        { NULL }
    11901839};
  • vendor/current/source3/torture/denytest.c

    r740 r988  
    14131413        int i;
    14141414        bool correct = True;
    1415         NTSTATUS ret1, ret2;
     1415        NTSTATUS ret1, ret2, status;
    14161416        const char *fnames[2] = {"\\denytest1.dat", "\\denytest1.exe"};
     1417        size_t nread;
    14171418
    14181419        if (!torture_open_connection(&cli1, 0)) {
     
    14241425        for (i=0;i<2;i++) {
    14251426                cli_unlink(cli1, fnames[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    1426                 cli_open(cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE, &fnum1);
    1427                 cli_writeall(cli1, fnum1, 0, (uint8_t *)fnames[i], 0,
     1427                cli_openx(cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE, &fnum1);
     1428                cli_writeall(cli1, fnum1, 0, (const uint8_t *)fnames[i], 0,
    14281429                             strlen(fnames[i]), NULL);
    14291430                cli_close(cli1, fnum1);
     
    14381439                progress_bar(i, ARRAY_SIZE(denytable1));
    14391440
    1440                 ret1 = cli_open(cli1, fname,
     1441                ret1 = cli_openx(cli1, fname,
    14411442                                 denytable1[i].mode1,
    14421443                                 denytable1[i].deny1, &fnum1);
    1443                 ret2 = cli_open(cli1, fname,
     1444                ret2 = cli_openx(cli1, fname,
    14441445                                 denytable1[i].mode2,
    14451446                                 denytable1[i].deny2, &fnum2);
     
    14521453                        char x = 1;
    14531454                        res = A_0;
    1454                         if (cli_read(cli1, fnum2, (char *)&x, 0, 1) == 1) {
     1455
     1456                        status = cli_read(cli1, fnum2, (char *)&x, 0, 1,
     1457                                          &nread);
     1458                        if (NT_STATUS_IS_OK(status) && nread == 1) {
    14551459                                res += A_R;
    14561460                        }
     
    15071511        int i;
    15081512        bool correct = True;
    1509         NTSTATUS ret1, ret2;
     1513        NTSTATUS ret1, ret2, status;
    15101514        const char *fnames[2] = {"\\denytest2.dat", "\\denytest2.exe"};
     1515        size_t nread;
    15111516
    15121517        if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
     
    15181523        for (i=0;i<2;i++) {
    15191524                cli_unlink(cli1, fnames[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    1520                 cli_open(cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE, &fnum1);
    1521                 cli_writeall(cli1, fnum1, 0, (uint8_t *)fnames[i], 0,
     1525                cli_openx(cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE, &fnum1);
     1526                cli_writeall(cli1, fnum1, 0, (const uint8_t *)fnames[i], 0,
    15221527                             strlen(fnames[i]), NULL);
    15231528                cli_close(cli1, fnum1);
     
    15301535                progress_bar(i, ARRAY_SIZE(denytable2));
    15311536
    1532                 ret1 = cli_open(cli1, fname,
     1537                ret1 = cli_openx(cli1, fname,
    15331538                                 denytable2[i].mode1,
    15341539                                 denytable2[i].deny1, &fnum1);
    1535                 ret2 = cli_open(cli2, fname,
     1540                ret2 = cli_openx(cli2, fname,
    15361541                                 denytable2[i].mode2,
    15371542                                 denytable2[i].deny2, &fnum2);
     
    15441549                        char x = 1;
    15451550                        res = A_0;
    1546                         if (cli_read(cli2, fnum2, (char *)&x, 0, 1) == 1) {
    1547                                 res += A_R;
    1548                         }
     1551
     1552                        status = cli_read(cli2, fnum2, (char *)&x, 0, 1,
     1553                                          &nread);
     1554                        if (NT_STATUS_IS_OK(status) && nread == 1) {
     1555                                res += A_R;
     1556                        }
    15491557                        if (NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0,
    15501558                                                         (uint8_t *)&x, 0, 1,
  • vendor/current/source3/torture/locktest2.c

    r740 r988  
    7474                {
    7575                        uint16_t fd;
    76                         if (!NT_STATUS_IS_OK(cli_open(c, fname, flags, DENY_NONE, &fd))) {
     76                        if (!NT_STATUS_IS_OK(cli_openx(c, fname, flags, DENY_NONE, &fd))) {
    7777                                return -1;
    7878                        }
     
    115115        switch (fstype) {
    116116        case FSTYPE_SMB:
    117                 return cli_lock(c, fd, start, len, LOCK_TIMEOUT, op);
     117                return NT_STATUS_IS_OK(cli_lock32(c, fd, start, len,
     118                                       LOCK_TIMEOUT, op));
    118119
    119120        case FSTYPE_NFS:
     
    184185       
    185186        if (!got_pass) {
    186                 char *pass = getpass("Password: ");
    187                 if (pass) {
    188                         fstrcpy(password, pass);
     187                char pwd[256] = {0};
     188                int rc;
     189
     190                rc = samba_getpass("Password: ", pwd, sizeof(pwd), false, false);
     191                if (rc == 0) {
     192                        fstrcpy(password, pwd);
    189193                }
    190194        }
     
    194198        nt_status = cli_full_connection(&c, myname, server_n, NULL, 0, share, "?????",
    195199                                        username, lp_workgroup(), password, 0,
    196                                         Undefined);
     200                                        SMB_SIGNING_DEFAULT);
    197201
    198202        if (!NT_STATUS_IS_OK(nt_status)) {
     
    513517        argv += 4;
    514518
    515         lp_load(get_dyn_CONFIGFILE(),True,False,False,True);
     519        lp_load_global(get_dyn_CONFIGFILE());
    516520        load_interfaces();
    517521
  • vendor/current/source3/torture/mangle_test.c

    r740 r988  
    4343        total++;
    4444
    45         if (!NT_STATUS_IS_OK(cli_open(cli, name, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
    46                 printf("open of %s failed (%s)\n", name, cli_errstr(cli));
    47                 return False;
    48         }
    49 
    50         if (!NT_STATUS_IS_OK(cli_close(cli, fnum))) {
    51                 printf("close of %s failed (%s)\n", name, cli_errstr(cli));
     45        status = cli_openx(cli, name, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
     46        if (!NT_STATUS_IS_OK(status)) {
     47                printf("open of %s failed (%s)\n", name, nt_errstr(status));
     48                return False;
     49        }
     50
     51        status = cli_close(cli, fnum);
     52        if (!NT_STATUS_IS_OK(status)) {
     53                printf("close of %s failed (%s)\n", name, nt_errstr(status));
    5254                return False;
    5355        }
     
    5658        status = cli_qpathinfo_alt_name(cli, name, shortname);
    5759        if (!NT_STATUS_IS_OK(status)) {
    58                 printf("query altname of %s failed (%s)\n", name, cli_errstr(cli));
     60                printf("query altname of %s failed (%s)\n", name, nt_errstr(status));
    5961                return False;
    6062        }
    6163
    6264        fstr_sprintf(name2, "\\mangle_test\\%s", shortname);
    63         if (!NT_STATUS_IS_OK(cli_unlink(cli, name2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
     65        status = cli_unlink(cli, name2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     66        if (!NT_STATUS_IS_OK(status)) {
    6467                printf("unlink of %s  (%s) failed (%s)\n",
    65                        name2, name, cli_errstr(cli));
     68                       name2, name, nt_errstr(status));
    6669                return False;
    6770        }
    6871
    6972        /* recreate by short name */
    70         if (!NT_STATUS_IS_OK(cli_open(cli, name2, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
    71                 printf("open2 of %s failed (%s)\n", name2, cli_errstr(cli));
    72                 return False;
    73         }
    74         if (!NT_STATUS_IS_OK(cli_close(cli, fnum))) {
    75                 printf("close of %s failed (%s)\n", name, cli_errstr(cli));
     73        status = cli_openx(cli, name2, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
     74        if (!NT_STATUS_IS_OK(status)) {
     75                printf("open2 of %s failed (%s)\n", name2, nt_errstr(status));
     76                return False;
     77        }
     78
     79        status = cli_close(cli, fnum);
     80        if (!NT_STATUS_IS_OK(status)) {
     81                printf("close of %s failed (%s)\n", name, nt_errstr(status));
    7682                return False;
    7783        }
    7884
    7985        /* and unlink by long name */
    80         if (!NT_STATUS_IS_OK(cli_unlink(cli, name, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
     86        status = cli_unlink(cli, name, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     87        if (!NT_STATUS_IS_OK(status)) {
    8188                printf("unlink2 of %s  (%s) failed (%s)\n",
    82                        name, name2, cli_errstr(cli));
     89                       name, name2, nt_errstr(status));
    8390                failures++;
    8491                cli_unlink(cli, name2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     
    101108                TDB_DATA namedata;
    102109                /* store it for later */
    103                 namedata.dptr = CONST_DISCARD(uint8 *, name);
     110                namedata.dptr = discard_const_p(uint8_t, name);
    104111                namedata.dsize = strlen(name)+1;
    105112                tdb_store_bystring(tdb, shortname, namedata, TDB_REPLACE);
  • vendor/current/source3/torture/masktest.c

    r740 r988  
    33   mask_match tester
    44   Copyright (C) Andrew Tridgell 1999
    5    
     5
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    88   the Free Software Foundation; either version 3 of the License, or
    99   (at your option) any later version.
    10    
     10
    1111   This program is distributed in the hope that it will be useful,
    1212   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1313   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1414   GNU General Public License for more details.
    15    
     15
    1616   You should have received a copy of the GNU General Public License
    1717   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2323#include "libsmb/libsmb.h"
    2424#include "libsmb/nmblib.h"
     25#include "../libcli/smb/smbXcli_base.h"
    2526
    2627static fstring password;
    2728static fstring username;
    2829static int got_pass;
    29 static int max_protocol = PROTOCOL_NT1;
     30static int max_protocol = -1;
    3031static bool showall = False;
    3132static bool old_list = False;
     
    145146        if (strcmp(file,"..") == 0) file = ".";
    146147
    147         return ms_fnmatch(pattern, file, cli->protocol, False) == 0;
     148        return ms_fnmatch(pattern, file, smbXcli_conn_protocol(cli->conn), False) == 0;
    148149}
    149150
     
    168169{
    169170        struct cli_state *c;
    170         struct nmb_name called, calling;
    171171        char *server_n;
    172172        char *server;
    173         struct sockaddr_storage ss;
    174173        NTSTATUS status;
    175174
     
    182181        server_n = server;
    183182
    184         zero_sockaddr(&ss);
    185 
    186         make_nmb_name(&calling, "masktest", 0x0);
    187         make_nmb_name(&called , server, 0x20);
    188 
    189  again:
    190         zero_sockaddr(&ss);
    191 
    192         /* have to open a new connection */
    193         if (!(c=cli_initialise())) {
    194                 DEBUG(0,("Connection to %s failed\n", server_n));
     183        status = cli_connect_nb(server, NULL, 0, 0x20, "masktest",
     184                                SMB_SIGNING_DEFAULT, 0, &c);
     185        if (!NT_STATUS_IS_OK(status)) {
     186                DEBUG(0,("Connection to %s failed. Error %s\n", server_n,
     187                         nt_errstr(status)));
    195188                return NULL;
    196189        }
    197190
    198         status = cli_connect(c, server_n, &ss);
    199         if (!NT_STATUS_IS_OK(status)) {
    200                 DEBUG(0,("Connection to %s failed. Error %s\n", server_n, nt_errstr(status) ));
    201                 return NULL;
    202         }
    203 
    204         c->protocol = max_protocol;
    205 
    206         if (!cli_session_request(c, &calling, &called)) {
    207                 DEBUG(0,("session request to %s failed\n", called.name));
    208                 cli_shutdown(c);
    209                 if (strcmp(called.name, "*SMBSERVER")) {
    210                         make_nmb_name(&called , "*SMBSERVER", 0x20);
    211                         goto again;
    212                 }
    213                 return NULL;
    214         }
    215 
    216         DEBUG(4,(" session request ok\n"));
    217 
    218         status = cli_negprot(c);
     191        status = smbXcli_negprot(c->conn, c->timeout, PROTOCOL_CORE,
     192                                 max_protocol);
    219193        if (!NT_STATUS_IS_OK(status)) {
    220194                DEBUG(0, ("protocol negotiation failed: %s\n",
     
    225199
    226200        if (!got_pass) {
    227                 char *pass = getpass("Password: ");
    228                 if (pass) {
     201                char pwd[256] = {0};
     202                int rc;
     203
     204                rc = samba_getpass("Password: ", pwd, sizeof(pwd), false, false);
     205                if (rc == 0) {
    229206                        fstrcpy(password, pass);
    230207                }
     
    254231        DEBUG(4,(" session setup ok\n"));
    255232
    256         status = cli_tcon_andx(c, share, "?????", password,
    257                                strlen(password)+1);
     233        status = cli_tree_connect(c, share, "?????", password,
     234                                  strlen(password)+1);
    258235        if (!NT_STATUS_IS_OK(status)) {
    259236                DEBUG(0,("tree connect failed: %s\n", nt_errstr(status)));
     
    294271        }
    295272
    296         fstrcpy(state->short_name, f->short_name);
    297         strlower_m(state->short_name);
     273
     274        fstrcpy(state->short_name, f->short_name ? f->short_name : "");
     275        (void)strlower_m(state->short_name);
    298276        *state->pp_long_name = SMB_STRDUP(f->name);
    299277        if (!*state->pp_long_name) {
    300278                return NT_STATUS_NO_MEMORY;
    301279        }
    302         strlower_m(*state->pp_long_name);
     280        (void)strlower_m(*state->pp_long_name);
    303281        return NT_STATUS_OK;
    304282}
     
    348326        fstrcpy(res1, "---");
    349327
    350         if (!NT_STATUS_IS_OK(cli_open(cli, file, O_CREAT|O_TRUNC|O_RDWR, 0, &fnum))) {
     328        if (!NT_STATUS_IS_OK(cli_openx(cli, file, O_CREAT|O_TRUNC|O_RDWR, 0, &fnum))) {
    351329                DEBUG(0,("Can't create %s\n", file));
    352330                return;
     
    413391                l1 = 1 + random() % 20;
    414392                l2 = 1 + random() % 20;
    415                 mask = TALLOC_ARRAY(ctx, char, strlen("\\masktest\\")+1+22);
    416                 file = TALLOC_ARRAY(ctx, char, strlen("\\masktest\\")+1+22);
     393                mask = talloc_array(ctx, char, strlen("\\masktest\\")+1+22);
     394                file = talloc_array(ctx, char, strlen("\\masktest\\")+1+22);
    417395                if (!mask || !file) {
    418396                        goto finished;
     
    505483        argv += 1;
    506484
    507         load_case_tables();
    508         lp_load(get_dyn_CONFIGFILE(),True,False,False,True);
     485        smb_init_locale();
     486        lp_load_global(get_dyn_CONFIGFILE());
    509487        load_interfaces();
    510488
     
    533511                        break;
    534512                case 'M':
    535                         max_protocol = interpret_protocol(optarg, max_protocol);
     513                        lp_set_cmdline("client max protocol", optarg);
    536514                        break;
    537515                case 'U':
     
    571549        argv += optind;
    572550
     551        max_protocol = lp_client_max_protocol();
    573552
    574553        cli = connect_one(share);
  • vendor/current/source3/torture/msgtest.c

    r740 r988  
    4747        char buf[12];
    4848        int ret;
     49        TALLOC_CTX *frame = talloc_stackframe();
    4950
    50         load_case_tables();
     51        smb_init_locale();
    5152
    5253        setup_logging(argv[0], DEBUG_STDOUT);
    5354
    54         lp_load(get_dyn_CONFIGFILE(),False,False,False,True);
     55        lp_load_global(get_dyn_CONFIGFILE());
    5556
    56         if (!(evt_ctx = tevent_context_init(NULL)) ||
    57             !(msg_ctx = messaging_init(NULL, procid_self(), evt_ctx))) {
     57        if (!(evt_ctx = samba_tevent_context_init(NULL)) ||
     58            !(msg_ctx = messaging_init(NULL, evt_ctx))) {
    5859                fprintf(stderr, "could not init messaging context\n");
     60                TALLOC_FREE(frame);
    5961                exit(1);
    6062        }
     
    6365                fprintf(stderr, "%s: Usage - %s pid count\n", argv[0],
    6466                        argv[0]);
     67                TALLOC_FREE(frame);
    6568                exit(1);
    6669        }
     
    8386        }
    8487
    85         /* Now test that the duplicate filtering code works. */
     88        /* Ensure all messages get through to ourselves. */
    8689        pong_count = 0;
    8790
    88         safe_strcpy(buf, "1234567890", sizeof(buf)-1);
     91        strlcpy(buf, "1234567890", sizeof(buf));
    8992
    9093        for (i=0;i<n;i++) {
     
    9295                               &data_blob_null);
    9396                messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
    94                                    MSG_PING,(uint8 *)buf, 11);
     97                                   MSG_PING,(uint8_t *)buf, 11);
    9598        }
    9699
    97         for (i=0;i<n;i++) {
     100        /*
     101         * We have to loop at least 2 times for
     102         * each message as local ping messages are
     103         * handled by an immediate callback, that
     104         * has to be dispatched, which sends a pong
     105         * message, which also has to be dispatched.
     106         * Above we sent 2*n messages, which means
     107         * we have to dispatch 4*n times.
     108         */
     109
     110        while (pong_count < n*2) {
    98111                ret = tevent_loop_once(evt_ctx);
    99112                if (ret != 0) {
     
    102115        }
    103116
    104         if (pong_count != 2) {
    105                 fprintf(stderr, "Duplicate filter failed (%d).\n", pong_count);
     117        if (pong_count != 2*n) {
     118                fprintf(stderr, "Message count failed (%d).\n", pong_count);
    106119        }
    107120
     
    120133                                                   msg_ctx, pid_to_procid(pid),
    121134                                                   MSG_PING,
    122                                                    (uint8 *)buf, 11)))
     135                                                   (uint8_t *)buf, 11)))
    123136                           ping_count++;
    124137                        if(NT_STATUS_IS_OK(messaging_send(
     
    153166        }
    154167
     168        TALLOC_FREE(frame);
    155169        return (0);
    156170}
  • vendor/current/source3/torture/nbench.c

    r740 r988  
    9797        char *status;
    9898
    99         result = TALLOC_P(mem_ctx, struct nbench_cmd_struct);
     99        result = talloc(mem_ctx, struct nbench_cmd_struct);
    100100        if (result == NULL) {
    101101                return NULL;
     
    299299                subreq = cli_qpathinfo_send(state, ev, nb_state->cli, fname,
    300300                                            ival(state->cmd->params[2]),
    301                                             0, nb_state->cli->max_xmit);
     301                                            0, CLI_BUFFER_SIZE);
    302302                break;
    303303        }
     
    339339        case NBENCH_CMD_NTCREATEX: {
    340340                struct ftable *ft;
    341                 status = cli_ntcreate_recv(subreq, &state->ft->fnum);
     341                status = cli_ntcreate_recv(subreq, &state->ft->fnum, NULL);
    342342                TALLOC_FREE(subreq);
    343343                if (status_wrong(req, state->cmd->status, status)) {
     
    466466                return false;
    467467        }
    468         ev = tevent_context_init(talloc_tos());
     468        ev = samba_tevent_context_init(talloc_tos());
    469469        if (ev == NULL) {
    470470                goto fail;
  • vendor/current/source3/torture/nbio.c

    r740 r988  
    7777{
    7878        nprocs = n;
    79         children = (struct children *)shm_setup(sizeof(*children) * nprocs);
     79        children = (struct children *)anonymous_shared_allocate(sizeof(*children) * nprocs);
    8080        if (!children) {
    8181                printf("Failed to setup shared memory!\n");
     
    136136void nb_unlink(const char *fname)
    137137{
    138         if (!NT_STATUS_IS_OK(cli_unlink(c, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
     138        NTSTATUS status;
     139
     140        status = cli_unlink(c, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     141        if (!NT_STATUS_IS_OK(status)) {
    139142#if NBDEBUG
    140143                printf("(%d) unlink %s failed (%s)\n",
    141                        line_count, fname, cli_errstr(c));
     144                       line_count, fname, nt_errstr(status));
    142145#endif
    143146        }
     
    151154        int i;
    152155        NTSTATUS status;
    153         uint32 desired_access;
     156        uint32_t desired_access;
    154157
    155158        if (create_options & FILE_DIRECTORY_FILE) {
     
    164167                                FILE_SHARE_READ|FILE_SHARE_WRITE,
    165168                                create_disposition,
    166                                 create_options, 0, &fd);
     169                                create_options, 0, &fd, NULL);
    167170        if (!NT_STATUS_IS_OK(status) && handle != -1) {
    168171                printf("ERROR: cli_ntcreate failed for %s - %s\n",
    169                        fname, cli_errstr(c));
     172                       fname, nt_errstr(status));
    170173                exit(1);
    171174        }
     
    210213void nb_readx(int handle, int offset, int size, int ret_size)
    211214{
    212         int i, ret;
     215        int i;
     216        NTSTATUS status;
     217        size_t nread;
    213218
    214219        i = find_handle(handle);
    215         if ((ret=cli_read(c, ftable[i].fd, buf, offset, size)) != ret_size) {
    216                 printf("(%d) ERROR: read failed on handle %d ofs=%d size=%d res=%d fd %d errno %d (%s)\n",
    217                         line_count, handle, offset, size, ret, ftable[i].fd, errno, strerror(errno));
     220        status = cli_read(c, ftable[i].fd, buf, offset, size, &nread);
     221        if (!NT_STATUS_IS_OK(status)) {
     222                printf("(%d) ERROR: read failed on handle %d ofs=%d size=%d "
     223                       "fd %d nterror %s\n",
     224                       line_count, handle, offset, size,
     225                       ftable[i].fd, nt_errstr(status));
     226                exit(1);
     227        } else if (nread != ret_size) {
     228                printf("(%d) ERROR: read failed on handle %d ofs=%d size=%d "
     229                       "nread=%lu ret_size=%d fd %d\n",
     230                       line_count, handle, offset, size, (unsigned long)nread,
     231                       ret_size, ftable[i].fd);
    218232                exit(1);
    219233        }
     
    234248void nb_rmdir(const char *fname)
    235249{
    236         if (!NT_STATUS_IS_OK(cli_rmdir(c, fname))) {
     250        NTSTATUS status;
     251
     252        status = cli_rmdir(c, fname);
     253        if (!NT_STATUS_IS_OK(status)) {
    237254                printf("ERROR: rmdir %s failed (%s)\n",
    238                        fname, cli_errstr(c));
     255                       fname, nt_errstr(status));
    239256                exit(1);
    240257        }
     
    243260void nb_rename(const char *oldname, const char *newname)
    244261{
    245         if (!NT_STATUS_IS_OK(cli_rename(c, oldname, newname))) {
     262        NTSTATUS status;
     263
     264        status = cli_rename(c, oldname, newname);
     265        if (!NT_STATUS_IS_OK(status)) {
    246266                printf("ERROR: rename %s %s failed (%s)\n",
    247                        oldname, newname, cli_errstr(c));
     267                       oldname, newname, nt_errstr(status));
    248268                exit(1);
    249269        }
     
    266286void nb_qfsinfo(int level)
    267287{
    268         int bsize, total, avail;
     288        uint64_t bsize, total, avail;
    269289        /* this is not the right call - we need cli_qfsinfo() */
    270         cli_dskattr(c, &bsize, &total, &avail);
     290        cli_disk_size(c, "", &bsize, &total, &avail);
    271291}
    272292
     
    287307        int i;
    288308        i = find_handle(fnum);
    289         /* hmmm, we don't have cli_flush() yet */
     309
     310        cli_flush(NULL, c, i);
    290311}
    291312
     
    304325        n[strlen(n)-1] = 0;
    305326        if (asprintf(&s, "%s%s", n, finfo->name) == -1) {
     327                free(n);
    306328                printf("asprintf failed\n");
    307329                return NT_STATUS_NO_MEMORY;
     
    311333                if (asprintf(&s2, "%s\\*", s) == -1) {
    312334                        printf("asprintf failed\n");
     335                        free(s);
     336                        free(n);
    313337                        return NT_STATUS_NO_MEMORY;
    314338                }
    315339                status = cli_list(c, s2, FILE_ATTRIBUTE_DIRECTORY, delete_fn, NULL);
     340                free(s2);
    316341                if (!NT_STATUS_IS_OK(status)) {
     342                        free(s);
    317343                        free(n);
    318                         free(s2);
    319344                        return status;
    320345                }
  • vendor/current/source3/torture/pdbtest.c

    r740 r988  
    22   Unix SMB/CIFS implementation.
    33   passdb testing utility
    4    
     4
    55   Copyright (C) Wilco Baan Hofman 2006
    66   Copyright (C) Jelmer Vernooij 2006
     7   Copyright (C) Andrew Bartlett 2012
    78
    89   This program is free software; you can redistribute it and/or modify
     
    1011   the Free Software Foundation; either version 3 of the License, or
    1112   (at your option) any later version.
    12    
     13
    1314   This program is distributed in the hope that it will be useful,
    1415   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1516   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1617   GNU General Public License for more details.
    17    
     18
    1819   You should have received a copy of the GNU General Public License
    1920   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2526#include "passdb.h"
    2627
     28#include "../librpc/gen_ndr/drsblobs.h"
     29#include "../librpc/gen_ndr/ndr_drsblobs.h"
     30#include "../libcli/security/dom_sid.h"
     31#include "../libcli/auth/libcli_auth.h"
     32#include "../auth/common_auth.h"
     33#include "lib/tsocket/tsocket.h"
     34#include "include/auth.h"
     35
     36#define TRUST_DOM "trustdom"
     37#define TRUST_PWD "trustpwd1232"
     38#define TRUST_SID "S-1-5-21-1111111111-2222222222-3333333333"
     39
    2740static bool samu_correct(struct samu *s1, struct samu *s2)
    2841{
    2942        bool ret = True;
    30         uint32 s1_len, s2_len;
     43        uint32_t s1_len, s2_len;
    3144        const char *s1_buf, *s2_buf;
    32         const uint8 *d1_buf, *d2_buf;
    33                
     45        const uint8_t *d1_buf, *d2_buf;
     46        const struct dom_sid *s1_sid, *s2_sid;
     47
    3448        /* Check Unix username */
    3549        s1_buf = pdb_get_username(s1);
     
    104118        } else if (d1_buf == NULL) {
    105119                /* Do nothing */
    106         } else if (s1_len != s1_len) {
     120        } else if (s1_len != s2_len) {
    107121                DEBUG(0, ("Password history not written correctly, lengths differ, want %d, got %d\n",
    108122                                        s1_len, s2_len));
     
    121135        /* Check logoff time */
    122136        if (pdb_get_logoff_time(s1) != pdb_get_logoff_time(s2)) {
    123                 DEBUG(0, ("Logoff time is not written correctly\n"));
    124                 ret = False;
    125         }
    126        
     137                DEBUG(0, ("Logoff time is not written correctly: %s vs %s \n",
     138                          http_timestring(talloc_tos(), pdb_get_logoff_time(s1)),
     139                          http_timestring(talloc_tos(), pdb_get_logoff_time(s2))));
     140                ret = False;
     141        }
     142
    127143        /* Check kickoff time */
    128         if (pdb_get_kickoff_time(s1) != pdb_get_logoff_time(s2)) {
    129                 DEBUG(0, ("Kickoff time is not written correctly\n"));
    130                 ret = False;
    131         }
    132        
     144        if (pdb_get_kickoff_time(s1) != pdb_get_kickoff_time(s2)) {
     145                DEBUG(0, ("Kickoff time is not written correctly: %s vs %s \n",
     146                          http_timestring(talloc_tos(), pdb_get_kickoff_time(s1)),
     147                          http_timestring(talloc_tos(), pdb_get_kickoff_time(s2))));
     148                ret = False;
     149        }
     150
    133151        /* Check bad password time */
    134152        if (pdb_get_bad_password_time(s1) != pdb_get_bad_password_time(s2)) {
     
    136154                ret = False;
    137155        }
    138        
     156
    139157        /* Check password last set time */
    140158        if (pdb_get_pass_last_set_time(s1) != pdb_get_pass_last_set_time(s2)) {
    141                 DEBUG(0, ("Password last set time is not written correctly\n"));
    142                 ret = False;
    143         }
    144        
     159                DEBUG(0, ("Password last set time is not written correctly: %s vs %s \n",
     160                          http_timestring(talloc_tos(), pdb_get_pass_last_set_time(s1)),
     161                          http_timestring(talloc_tos(), pdb_get_pass_last_set_time(s2))));
     162                ret = False;
     163        }
     164
    145165        /* Check password can change time */
    146166        if (pdb_get_pass_can_change_time(s1) != pdb_get_pass_can_change_time(s2)) {
    147                 DEBUG(0, ("Password can change time is not written correctly\n"));
    148                 ret = False;
    149         }
    150        
     167                DEBUG(0, ("Password can change time is not written correctly %s vs %s \n",
     168                          http_timestring(talloc_tos(), pdb_get_pass_can_change_time(s1)),
     169                          http_timestring(talloc_tos(), pdb_get_pass_can_change_time(s2))));
     170                ret = False;
     171        }
     172
    151173        /* Check password must change time */
    152174        if (pdb_get_pass_must_change_time(s1) != pdb_get_pass_must_change_time(s2)) {
     
    154176                ret = False;
    155177        }
    156        
     178
    157179        /* Check logon divs */
    158180        if (pdb_get_logon_divs(s1) != pdb_get_logon_divs(s2)) {
     
    160182                ret = False;
    161183        }
    162        
     184
    163185        /* Check logon hours */
    164186        if (pdb_get_hours_len(s1) != pdb_get_hours_len(s2)) {
     
    178200                }
    179201        }
    180        
     202
    181203        /* Check profile path */
    182204        s1_buf = pdb_get_profile_path(s1);
     
    204226                ret = False;
    205227        }
    206        
     228
    207229        /* Check logon script */
    208230        s1_buf = pdb_get_logon_script(s1);
     
    217239                ret = False;
    218240        }
    219        
    220         /* TODO Check user and group sids */
    221                
     241
     242        /* Check user and group sids */
     243        s1_sid = pdb_get_user_sid(s1);
     244        s2_sid = pdb_get_user_sid(s2);
     245        if (s2_sid == NULL && s1_sid != NULL) {
     246                DEBUG(0, ("USER SID not set\n"));
     247                ret = False;
     248        } else if (s1_sid == NULL) {
     249                /* Do nothing */
     250        } else if (!dom_sid_equal(s1_sid, s2_sid)) {
     251                DEBUG(0, ("USER SID is not written correctly\n"));
     252                ret = False;
     253        }
     254
    222255        return ret;     
    223256}
    224257
    225 
    226 int main(int argc, char **argv)
     258static bool test_auth(TALLOC_CTX *mem_ctx, struct samu *pdb_entry)
     259{
     260        struct auth_usersupplied_info *user_info;
     261        struct auth_context *auth_context;
     262        static const uint8_t challenge_8[8] = {1, 2, 3, 4, 5, 6, 7, 8};
     263        DATA_BLOB challenge = data_blob_const(challenge_8, sizeof(challenge_8));
     264        struct tsocket_address *tsocket_address;
     265        unsigned char local_nt_response[24];
     266        DATA_BLOB nt_resp = data_blob_const(local_nt_response, sizeof(local_nt_response));
     267        unsigned char local_nt_session_key[16];
     268        struct netr_SamInfo3 *info3_sam, *info3_auth;
     269        struct auth_serversupplied_info *server_info;
     270        NTSTATUS status;
     271       
     272        SMBOWFencrypt(pdb_get_nt_passwd(pdb_entry), challenge_8,
     273                      local_nt_response);
     274        SMBsesskeygen_ntv1(pdb_get_nt_passwd(pdb_entry), local_nt_session_key);
     275
     276        if (tsocket_address_inet_from_strings(NULL, "ip", NULL, 0, &tsocket_address) != 0) {
     277                return False;
     278        }
     279       
     280        status = make_user_info(mem_ctx,
     281                                &user_info, pdb_get_username(pdb_entry), pdb_get_username(pdb_entry),
     282                                pdb_get_domain(pdb_entry), pdb_get_domain(pdb_entry), lp_netbios_name(),
     283                                tsocket_address, NULL, &nt_resp, NULL, NULL, NULL,
     284                                AUTH_PASSWORD_RESPONSE);
     285        if (!NT_STATUS_IS_OK(status)) {
     286                DEBUG(0, ("Failed to test authentication with check_sam_security_info3: %s\n", nt_errstr(status)));
     287                return False;
     288        }
     289
     290        status = check_sam_security_info3(&challenge, NULL, user_info, &info3_sam);
     291        if (!NT_STATUS_IS_OK(status)) {
     292                DEBUG(0, ("Failed to test authentication with check_sam_security_info3: %s\n", nt_errstr(status)));
     293                return False;
     294        }
     295
     296        if (memcmp(info3_sam->base.key.key, local_nt_session_key, 16) != 0) {
     297                DEBUG(0, ("Returned NT session key is incorrect\n"));
     298                return False;
     299        }
     300
     301        status = make_auth_context_fixed(NULL, &auth_context, challenge.data);
     302
     303        if (!NT_STATUS_IS_OK(status)) {
     304                DEBUG(0, ("Failed to test authentication with check_sam_security_info3: %s\n", nt_errstr(status)));
     305                return False;
     306        }
     307       
     308        status = auth_check_ntlm_password(mem_ctx,
     309                                          auth_context,
     310                                          user_info,
     311                                          &server_info);
     312
     313        if (!NT_STATUS_IS_OK(status)) {
     314                DEBUG(0, ("Failed to test authentication with auth module: %s\n", nt_errstr(status)));
     315                return False;
     316        }
     317       
     318        info3_auth = talloc_zero(mem_ctx, struct netr_SamInfo3);
     319        if (info3_auth == NULL) {
     320                return False;
     321        }
     322
     323        status = serverinfo_to_SamInfo3(server_info, info3_auth);
     324        if (!NT_STATUS_IS_OK(status)) {
     325                DEBUG(0, ("serverinfo_to_SamInfo3 failed: %s\n",
     326                          nt_errstr(status)));
     327                return False;
     328        }
     329
     330        if (memcmp(info3_auth->base.key.key, local_nt_session_key, 16) != 0) {
     331                DEBUG(0, ("Returned NT session key is incorrect\n"));
     332                return False;
     333        }
     334
     335        if (!dom_sid_equal(info3_sam->base.domain_sid, info3_auth->base.domain_sid)) {
     336                DEBUG(0, ("domain_sid in SAM info3 %s does not match domain_sid in AUTH info3 %s\n",
     337                          dom_sid_string(NULL, info3_sam->base.domain_sid),
     338                          dom_sid_string(NULL, info3_auth->base.domain_sid)));
     339                return False;
     340        }
     341       
     342        /* TODO:
     343         * Compre more details from the two info3 structures,
     344         * then test that an expired/disabled/pwdmustchange account
     345         * returns the correct errors
     346         */
     347
     348        return True;
     349}
     350
     351static bool test_trusted_domains(TALLOC_CTX *ctx,
     352                                 struct pdb_methods *pdb,
     353                                 bool *error)
     354{
     355        NTSTATUS rv;
     356        /* test trustdom calls */
     357        struct pdb_trusted_domain *td;
     358        struct pdb_trusted_domain *new_td;
     359        struct trustAuthInOutBlob taiob;
     360        struct AuthenticationInformation aia;
     361        enum ndr_err_code ndr_err;
     362
     363        td = talloc_zero(ctx ,struct pdb_trusted_domain);
     364        if (!td) {
     365                fprintf(stderr, "talloc failed\n");
     366                return false;
     367        }
     368
     369        td->domain_name = talloc_strdup(td, TRUST_DOM);
     370        td->netbios_name = talloc_strdup(td, TRUST_DOM);
     371        if (!td->domain_name || !td->netbios_name) {
     372                fprintf(stderr, "talloc failed\n");
     373                return false;
     374        }
     375
     376        td->trust_auth_incoming = data_blob_null;
     377
     378        ZERO_STRUCT(taiob);
     379        ZERO_STRUCT(aia);
     380        taiob.count = 1;
     381        taiob.current.count = 1;
     382        taiob.current.array = &aia;
     383        unix_to_nt_time(&aia.LastUpdateTime, time(NULL));
     384        aia.AuthType = TRUST_AUTH_TYPE_CLEAR;
     385        aia.AuthInfo.clear.password = (uint8_t *) talloc_strdup(ctx, TRUST_PWD);
     386        aia.AuthInfo.clear.size = strlen(TRUST_PWD);
     387
     388        taiob.previous.count = 0;
     389        taiob.previous.array = NULL;
     390
     391        ndr_err = ndr_push_struct_blob(&td->trust_auth_outgoing,
     392                                        td, &taiob,
     393                        (ndr_push_flags_fn_t) ndr_push_trustAuthInOutBlob);
     394        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     395                fprintf(stderr, "ndr_push_struct_blob failed.\n");
     396                return false;
     397        }
     398
     399        td->trust_direction = LSA_TRUST_DIRECTION_OUTBOUND;
     400        td->trust_type = LSA_TRUST_TYPE_DOWNLEVEL;
     401        td->trust_attributes = 0;
     402        td->trust_forest_trust_info = data_blob_null;
     403
     404        rv = pdb->set_trusted_domain(pdb, TRUST_DOM, td);
     405        if (!NT_STATUS_IS_OK(rv)) {
     406                fprintf(stderr, "Error in set_trusted_domain %s\n",
     407                                get_friendly_nt_error_msg(rv));
     408                *error = true;
     409        }
     410
     411        rv = pdb->get_trusted_domain(pdb, ctx, TRUST_DOM, &new_td);
     412        if (!NT_STATUS_IS_OK(rv)) {
     413                fprintf(stderr, "Error in set_trusted_domain %s\n",
     414                                get_friendly_nt_error_msg(rv));
     415                *error = true;
     416        }
     417
     418        if (!strequal(td->domain_name, new_td->domain_name) ||
     419            !strequal(td->netbios_name, new_td->netbios_name) ||
     420            !dom_sid_equal(&td->security_identifier,
     421                           &new_td->security_identifier) ||
     422            td->trust_direction != new_td->trust_direction ||
     423            td->trust_type != new_td->trust_type ||
     424            td->trust_attributes != new_td->trust_attributes ||
     425            td->trust_auth_incoming.length != new_td->trust_auth_incoming.length ||
     426            td->trust_forest_trust_info.length != new_td->trust_forest_trust_info.length ||
     427            data_blob_cmp(&td->trust_auth_outgoing, &new_td->trust_auth_outgoing) != 0) {
     428                fprintf(stderr, "Old and new trusdet domain data do not match\n");
     429                *error = true;
     430        }
     431
     432        return true;
     433}
     434
     435
     436int main(int argc, const char **argv)
    227437{
    228438        TALLOC_CTX *ctx;
     
    234444        bool error = False;
    235445        struct passwd *pwd;
    236         uint8 *buf;
    237         uint32 expire, min_age, history;
     446        uint8_t *buf;
     447        uint32_t expire, min_age, history;
    238448        struct pdb_methods *pdb;
    239449        poptContext pc;
     
    248458        };
    249459
    250         load_case_tables();
    251 
    252         pc = poptGetContext("pdbtest", argc, (const char **) argv,
    253                             long_options, 0);
     460        ctx = talloc_stackframe();
     461
     462        smb_init_locale();
     463
     464        pc = poptGetContext("pdbtest", argc, argv, long_options, 0);
    254465
    255466        poptSetOtherOptionHelp(pc, "backend[:settings] username");
    256        
     467
    257468        while(poptGetNextOpt(pc) != -1);
    258469
     
    260471
    261472        /* Load configuration */
    262         lp_load(get_dyn_CONFIGFILE(), False, False, True, True);
     473        lp_load_global(get_dyn_CONFIGFILE());
    263474        setup_logging("pdbtest", DEBUG_STDOUT);
     475        init_names();
    264476
    265477        if (backend == NULL) {
     
    272484                exit(1);
    273485        }
    274        
    275         ctx = talloc_init("PDBTEST");
    276        
     486
    277487        if (!(out = samu_new(ctx))) {
    278488                fprintf(stderr, "Can't create samu structure.\n");
    279489                exit(1);
    280490        }
    281        
     491
    282492        if ((pwd = Get_Pwnam_alloc(ctx, unix_user)) == NULL) {
    283493                fprintf(stderr, "Error getting user information for %s\n", unix_user);
    284494                exit(1);
    285495        }
    286        
     496
    287497        samu_set_unix(out, pwd);
    288498
     
    291501        pdb_set_logon_script(out, "torture_script.cmd", PDB_SET);
    292502
     503        pdb_set_acct_ctrl(out, ACB_NORMAL, PDB_SET);
     504
    293505        pdb_get_account_policy(PDB_POLICY_PASSWORD_HISTORY, &history);
    294506        if (history * PW_HISTORY_ENTRY_LEN < NT_HASH_LEN) {
    295                 buf = (uint8 *)TALLOC(ctx, NT_HASH_LEN);
     507                buf = (uint8_t *)TALLOC(ctx, NT_HASH_LEN);
    296508        } else {
    297                 buf = (uint8 *)TALLOC(ctx, history * PW_HISTORY_ENTRY_LEN);
     509                buf = (uint8_t *)TALLOC(ctx, history * PW_HISTORY_ENTRY_LEN);
    298510        }
    299511
     
    302514        srand(tv.tv_usec);
    303515        for (i = 0; i < NT_HASH_LEN; i++) {
    304                 buf[i] = (uint8) rand();
     516                buf[i] = (uint8_t) rand();
    305517        }
    306518        pdb_set_nt_passwd(out, buf, PDB_SET);
    307519        for (i = 0; i < LM_HASH_LEN; i++) {
    308                 buf[i] = (uint8) rand();
     520                buf[i] = (uint8_t) rand();
    309521        }
    310522        pdb_set_lanman_passwd(out, buf, PDB_SET);
    311523        for (i = 0; i < history * PW_HISTORY_ENTRY_LEN; i++) {
    312                 buf[i] = (uint8) rand();
     524                buf[i] = (uint8_t) rand();
    313525        }
    314526        pdb_set_pw_history(out, buf, history, PDB_SET);
     
    317529        pdb_get_account_policy(PDB_POLICY_MIN_PASSWORD_AGE, &min_age);
    318530        pdb_set_pass_last_set_time(out, time(NULL), PDB_SET);
    319        
    320         if (expire == 0 || expire == (uint32)-1) {
    321                 pdb_set_pass_must_change_time(out, get_time_t_max(), PDB_SET);
    322         } else {
    323                 pdb_set_pass_must_change_time(out, time(NULL)+expire, PDB_SET);
    324         }
    325 
    326         if (min_age == (uint32)-1) {
     531
     532        if (min_age == (uint32_t)-1) {
    327533                pdb_set_pass_can_change_time(out, 0, PDB_SET);
    328534        } else {
    329535                pdb_set_pass_can_change_time(out, time(NULL)+min_age, PDB_SET);
    330536        }
    331        
     537
     538        pdb_set_logon_time(out, time(NULL)-3600, PDB_SET);
     539
     540        pdb_set_logoff_time(out, time(NULL), PDB_SET);
     541
     542        pdb_set_kickoff_time(out, time(NULL)+3600, PDB_SET);
     543
    332544        /* Create account */
    333545        if (!NT_STATUS_IS_OK(rv = pdb->add_sam_account(pdb, out))) {
     
    341553                exit(1);
    342554        }
    343        
     555
    344556        /* Get account information through getsampwnam() */
    345         if (NT_STATUS_IS_ERR(pdb->getsampwnam(pdb, in, out->username))) {
    346                 fprintf(stderr, "Error getting sampw of added user %s.\n",
    347                                 out->username);
     557        rv = pdb->getsampwnam(pdb, in, out->username);
     558        if (NT_STATUS_IS_ERR(rv)) {
     559                fprintf(stderr, "Error getting sampw of added user %s: %s\n",
     560                        out->username, nt_errstr(rv));
    348561                if (!NT_STATUS_IS_OK(rv = pdb->delete_sam_account(pdb, out))) {
    349562                        fprintf(stderr, "Error in delete_sam_account %s\n",
     
    351564                }
    352565                TALLOC_FREE(ctx);
    353         }
    354        
     566                exit(1);
     567        }
     568
    355569        /* Verify integrity */
    356570        if (samu_correct(out, in)) {
     
    360574                error = True;
    361575        }
    362        
     576
     577        if (test_auth(ctx, out)) {
     578                printf("Authentication module test passed\n");
     579        } else {
     580                printf("Authentication module test failed!\n");
     581                error = True;
     582        }
     583                       
     584
    363585        /* Delete account */
    364586        if (!NT_STATUS_IS_OK(rv = pdb->delete_sam_account(pdb, out))) {
     
    367589        }
    368590
     591        if (pdb_capabilities() & PDB_CAP_TRUSTED_DOMAINS_EX) {
     592                if (!test_trusted_domains(ctx, pdb, &error)) {
     593                        fprintf(stderr, "failed testing trusted domains.\n");
     594                        exit(1);
     595                }
     596        }
     597
    369598        TALLOC_FREE(ctx);
    370599
  • vendor/current/source3/torture/proto.h

    r740 r988  
    6464/* The following definitions come from torture/torture.c  */
    6565
    66 void *shm_setup(int size);
    6766bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
    6867                      char **hostname, char **sharename);
    6968bool torture_open_connection(struct cli_state **c, int conn_index);
    70 bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid);
     69bool torture_init_connection(struct cli_state **pcli);
     70bool torture_cli_session_setup2(struct cli_state *cli, uint16_t *new_vuid);
    7171bool torture_close_connection(struct cli_state *c);
    7272bool torture_ioctl_test(int dummy);
     
    8484
    8585bool run_posix_append(int dummy);
     86bool run_case_insensitive_create(int dummy);
    8687
    8788bool run_nbench2(int dummy);
     
    8990bool run_smb_any_connect(int dummy);
    9091bool run_addrchange(int dummy);
     92bool run_notify_online(int dummy);
     93bool run_nttrans_create(int dummy);
     94bool run_nttrans_fsctl(int dummy);
     95bool run_smb2_basic(int dummy);
     96bool run_smb2_negprot(int dummy);
     97bool run_smb2_session_reconnect(int dummy);
     98bool run_smb2_tcon_dependence(int dummy);
     99bool run_smb2_multi_channel(int dummy);
     100bool run_smb2_session_reauth(int dummy);
     101bool run_chain3(int dummy);
     102bool run_local_conv_auth_info(int dummy);
     103bool run_local_sprintf_append(int dummy);
     104bool run_cleanup1(int dummy);
     105bool run_cleanup2(int dummy);
     106bool run_cleanup3(int dummy);
     107bool run_cleanup4(int dummy);
     108bool run_notify_bench2(int dummy);
     109bool run_notify_bench3(int dummy);
     110bool run_dbwrap_watch1(int dummy);
     111bool run_idmap_tdb_common_test(int dummy);
     112bool run_local_dbwrap_ctdb(int dummy);
     113bool run_qpathinfo_bufsize(int dummy);
     114bool run_bench_pthreadpool(int dummy);
     115bool run_messaging_read1(int dummy);
     116bool run_messaging_read2(int dummy);
     117bool run_messaging_read3(int dummy);
     118bool run_messaging_read4(int dummy);
     119bool run_messaging_fdpass1(int dummy);
     120bool run_messaging_fdpass2(int dummy);
     121bool run_messaging_fdpass2a(int dummy);
     122bool run_messaging_fdpass2b(int dummy);
     123bool run_oplock_cancel(int dummy);
    91124
    92125#endif /* __TORTURE_H__ */
  • vendor/current/source3/torture/rpc_open_tcp.c

    r740 r988  
    9595        }
    9696
    97         status = rpc_pipe_open_tcp(mem_ctx, argv[2], &((*table)->syntax_id),
     97        status = rpc_pipe_open_tcp(mem_ctx, argv[2], NULL,
     98                                   *table,
    9899                                   &rpc_pipe);
    99100        if (!NT_STATUS_IS_OK(status)) {
  • vendor/current/source3/torture/scanner.c

    r740 r988  
    2222#include "torture/proto.h"
    2323#include "libsmb/libsmb.h"
     24#include "../libcli/smb/smbXcli_base.h"
    2425
    2526#define VERBOSE 0
     
    6869                           NULL, 0, 0, /* setup */
    6970                           param, param_len, 2,
    70                            data, data_len, cli->max_xmit,
     71                           data, data_len, CLI_BUFFER_SIZE,
    7172                           NULL,                /* recv_flags2 */
    7273                           NULL, 0, NULL,       /* rsetup */
     
    122123        uint32_t param_len = 0;
    123124        uint32_t rparam_len, rdata_len;
    124         uint8_t param[PARAM_SIZE], data[DATA_SIZE];
     125        uint8_t *param = NULL;
     126        uint8_t data[DATA_SIZE];
     127        const char *newfname;
     128        const char *dname;
    125129        NTSTATUS status;
    126130
     
    129133
    130134        /* try with a info level only */
    131         param_len = 2;
    132         SSVAL(param, 0, level);
     135        TALLOC_FREE(param);
     136        param = talloc_array(talloc_tos(), uint8_t, 2);
     137        if (param == NULL) return True;
     138
     139        SSVAL(param, 0, level);
     140
     141        param_len = talloc_get_size(param);
    133142        status = try_trans2_len(cli, "void", op, level, param, data, param_len, &data_len,
    134143                            &rparam_len, &rdata_len);
     
    136145
    137146        /* try with a file descriptor */
    138         param_len = 6;
     147        TALLOC_FREE(param);
     148        param = talloc_array(talloc_tos(), uint8_t, 6);
     149        if (param == NULL) return True;
     150
    139151        SSVAL(param, 0, fnum);
    140152        SSVAL(param, 2, level);
    141153        SSVAL(param, 4, 0);
     154
     155        param_len = talloc_get_size(param);
    142156        status = try_trans2_len(cli, "fnum", op, level, param, data, param_len, &data_len,
    143157                                &rparam_len, &rdata_len);
     
    146160
    147161        /* try with a notify style */
    148         param_len = 6;
     162        TALLOC_FREE(param);
     163        param = talloc_array(talloc_tos(), uint8_t, 6);
     164        if (param == NULL) return True;
     165
    149166        SSVAL(param, 0, dnum);
    150167        SSVAL(param, 2, dnum);
    151168        SSVAL(param, 4, level);
     169
     170        param_len = talloc_get_size(param);
    152171        status = try_trans2_len(cli, "notify", op, level, param, data, param_len, &data_len,
    153172                                &rparam_len, &rdata_len);
     
    155174
    156175        /* try with a file name */
    157         param_len = 6;
     176        TALLOC_FREE(param);
     177        param = talloc_array(talloc_tos(), uint8_t, 6);
     178        if (param == NULL) return True;
     179
    158180        SSVAL(param, 0, level);
    159181        SSVAL(param, 2, 0);
    160182        SSVAL(param, 4, 0);
    161         param_len += clistr_push(cli, &param[6], fname, -1, STR_TERMINATE);
    162 
     183        param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn),
     184                                      fname, strlen(fname)+1, NULL);
     185        if (param == NULL) return True;
     186
     187        param_len = talloc_get_size(param);
    163188        status = try_trans2_len(cli, "fname", op, level, param, data, param_len, &data_len,
    164189                                &rparam_len, &rdata_len);
     
    166191
    167192        /* try with a new file name */
    168         param_len = 6;
     193        newfname = "\\newfile.dat";
     194        TALLOC_FREE(param);
     195        param = talloc_array(talloc_tos(), uint8_t, 6);
     196        if (param == NULL) return True;
     197
    169198        SSVAL(param, 0, level);
    170199        SSVAL(param, 2, 0);
    171200        SSVAL(param, 4, 0);
    172         param_len += clistr_push(cli, &param[6], "\\newfile.dat", -1, STR_TERMINATE);
    173 
     201        param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn),
     202                                      newfname, strlen(newfname)+1, NULL);
     203        if (param == NULL) return True;
     204
     205        param_len = talloc_get_size(param);
    174206        status = try_trans2_len(cli, "newfile", op, level, param, data, param_len, &data_len,
    175207                                &rparam_len, &rdata_len);
    176         cli_unlink(cli, "\\newfile.dat", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    177         cli_rmdir(cli, "\\newfile.dat");
     208        cli_unlink(cli, newfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     209        cli_rmdir(cli, newfname);
    178210        if (NT_STATUS_IS_OK(status)) return True;
    179211
    180212        /* try dfs style  */
    181         cli_mkdir(cli, "\\testdir");
    182         param_len = 2;
    183         SSVAL(param, 0, level);
    184         param_len += clistr_push(cli, &param[2], "\\testdir", -1, STR_TERMINATE);
    185 
     213        dname = "\\testdir";
     214        cli_mkdir(cli, dname);
     215        TALLOC_FREE(param);
     216        param = talloc_array(talloc_tos(), uint8_t, 2);
     217        if (param == NULL) return True;
     218
     219        SSVAL(param, 0, level);
     220        param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn),
     221                                      dname, strlen(dname)+1, NULL);
     222        if (param == NULL) return True;
     223
     224        param_len = talloc_get_size(param);
    186225        status = try_trans2_len(cli, "dfs", op, level, param, data, param_len, &data_len,
    187226                                &rparam_len, &rdata_len);
    188         cli_rmdir(cli, "\\testdir");
     227        cli_rmdir(cli, dname);
    189228        if (NT_STATUS_IS_OK(status)) return True;
    190229
     
    206245        }
    207246
    208         if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC,
     247        if (!NT_STATUS_IS_OK(cli_openx(cli, fname, O_RDWR | O_CREAT | O_TRUNC,
    209248                         DENY_NONE, &fnum))) {
    210249                printf("open of %s failed\n", fname);
    211250                return false;
    212251        }
    213         if (!NT_STATUS_IS_OK(cli_open(cli, "\\", O_RDONLY, DENY_NONE, &dnum))) {
     252        if (!NT_STATUS_IS_OK(cli_openx(cli, "\\", O_RDONLY, DENY_NONE, &dnum))) {
    214253                printf("open of \\ failed\n");
    215254                return false;
     
    276315                           NULL, 0, 0, /* setup */
    277316                           param, param_len, 2,
    278                            data, data_len, cli->max_xmit,
     317                           data, data_len, CLI_BUFFER_SIZE,
    279318                           NULL,                /* recv_flags2 */
    280319                           NULL, 0, NULL,       /* rsetup */
     
    329368        uint32_t param_len = 0;
    330369        uint32_t rparam_len, rdata_len;
    331         uint8_t param[PARAM_SIZE], data[DATA_SIZE];
     370        uint8_t *param = NULL;
     371        uint8_t data[DATA_SIZE];
    332372        NTSTATUS status;
     373        const char *newfname;
     374        const char *dname;
    333375
    334376        memset(data, 0, sizeof(data));
     
    336378
    337379        /* try with a info level only */
    338         param_len = 2;
    339         SSVAL(param, 0, level);
     380        TALLOC_FREE(param);
     381        param = talloc_array(talloc_tos(), uint8_t, 2);
     382        if (param == NULL) return True;
     383
     384        SSVAL(param, 0, level);
     385
     386        param_len = talloc_get_size(param);
    340387        status = try_nttrans_len(cli, "void", op, level, param, data, param_len, &data_len,
    341388                            &rparam_len, &rdata_len);
     
    343390
    344391        /* try with a file descriptor */
    345         param_len = 6;
     392        TALLOC_FREE(param);
     393        param = talloc_array(talloc_tos(), uint8_t, 6);
     394        if (param == NULL) return True;
     395
    346396        SSVAL(param, 0, fnum);
    347397        SSVAL(param, 2, level);
    348398        SSVAL(param, 4, 0);
     399
     400        param_len = talloc_get_size(param);
    349401        status = try_nttrans_len(cli, "fnum", op, level, param, data, param_len, &data_len,
    350402                                &rparam_len, &rdata_len);
     
    353405
    354406        /* try with a notify style */
    355         param_len = 6;
     407        TALLOC_FREE(param);
     408        param = talloc_array(talloc_tos(), uint8_t, 6);
     409        if (param == NULL) return True;
     410
    356411        SSVAL(param, 0, dnum);
    357412        SSVAL(param, 2, dnum);
    358413        SSVAL(param, 4, level);
     414
     415        param_len = talloc_get_size(param);
    359416        status = try_nttrans_len(cli, "notify", op, level, param, data, param_len, &data_len,
    360417                                &rparam_len, &rdata_len);
     
    362419
    363420        /* try with a file name */
    364         param_len = 6;
     421        TALLOC_FREE(param);
     422        param = talloc_array(talloc_tos(), uint8_t, 6);
     423        if (param == NULL) return True;
     424
    365425        SSVAL(param, 0, level);
    366426        SSVAL(param, 2, 0);
    367427        SSVAL(param, 4, 0);
    368         param_len += clistr_push(cli, &param[6], fname, -1, STR_TERMINATE);
    369 
     428        param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn),
     429                                      fname, strlen(fname)+1, NULL);
     430        if (param == NULL) return True;
     431
     432        param_len = talloc_get_size(param);
    370433        status = try_nttrans_len(cli, "fname", op, level, param, data, param_len, &data_len,
    371434                                &rparam_len, &rdata_len);
     
    373436
    374437        /* try with a new file name */
    375         param_len = 6;
     438        newfname = "\\newfile.dat";
     439        TALLOC_FREE(param);
     440        param = talloc_array(talloc_tos(), uint8_t, 6);
     441        if (param == NULL) return True;
     442
    376443        SSVAL(param, 0, level);
    377444        SSVAL(param, 2, 0);
    378445        SSVAL(param, 4, 0);
    379         param_len += clistr_push(cli, &param[6], "\\newfile.dat", -1, STR_TERMINATE);
    380 
     446        param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn),
     447                                      newfname, strlen(newfname)+1, NULL);
     448        if (param == NULL) return True;
     449
     450        param_len = talloc_get_size(param);
    381451        status = try_nttrans_len(cli, "newfile", op, level, param, data, param_len, &data_len,
    382452                                &rparam_len, &rdata_len);
    383         cli_unlink(cli, "\\newfile.dat", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    384         cli_rmdir(cli, "\\newfile.dat");
     453        cli_unlink(cli, newfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     454        cli_rmdir(cli, newfname);
    385455        if (NT_STATUS_IS_OK(status)) return True;
    386456
    387457        /* try dfs style  */
    388         cli_mkdir(cli, "\\testdir");
    389         param_len = 2;
    390         SSVAL(param, 0, level);
    391         param_len += clistr_push(cli, &param[2], "\\testdir", -1, STR_TERMINATE);
    392 
     458        dname = "\\testdir";
     459        cli_mkdir(cli, dname);
     460        TALLOC_FREE(param);
     461        param = talloc_array(talloc_tos(), uint8_t, 2);
     462        if (param == NULL) return True;
     463
     464        SSVAL(param, 0, level);
     465        param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn),
     466                                      dname, strlen(dname)+1, NULL);
     467        if (param == NULL) return True;
     468
     469        param_len = talloc_get_size(param);
    393470        status = try_nttrans_len(cli, "dfs", op, level, param, data, param_len, &data_len,
    394471                                &rparam_len, &rdata_len);
    395         cli_rmdir(cli, "\\testdir");
     472        cli_rmdir(cli, dname);
    396473        if (NT_STATUS_IS_OK(status)) return True;
    397474
     
    413490        }
    414491
    415         cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC,
     492        cli_openx(cli, fname, O_RDWR | O_CREAT | O_TRUNC,
    416493                         DENY_NONE, &fnum);
    417         cli_open(cli, "\\", O_RDONLY, DENY_NONE, &dnum);
     494        cli_openx(cli, "\\", O_RDONLY, DENY_NONE, &dnum);
    418495
    419496        for (op=OP_MIN; op<=OP_MAX; op++) {
  • vendor/current/source3/torture/t_strappend.c

    r414 r988  
    66
    77#include "includes.h"
    8 #include <assert.h>
     8#include "torture/proto.h"
    99
    10 int main(int argc, char *argv[])
     10bool run_local_sprintf_append(int dummy)
    1111{
    1212        TALLOC_CTX *mem_ctx;
    1313        char *string = NULL;
    14         int len = 0;
    15         int bufsize = 4;
     14        ssize_t len = 0;
     15        size_t bufsize = 4;
    1616        int i;
    1717
     
    1919        if (mem_ctx == NULL) {
    2020                fprintf(stderr, "talloc_init failed\n");
    21                 return 1;
     21                return false;
    2222        }
    2323
     
    3131
    3232
    33         for (i=0; i<(100000); i++) {
     33        for (i=0; i<(10000); i++) {
    3434                if (i%1000 == 0) {
    35                         printf("%d %d\r", i, bufsize);
     35                        printf("%d %lld\r", i, (long long int)bufsize);
    3636                        fflush(stdout);
    3737                }
    3838                sprintf_append(mem_ctx, &string, &len, &bufsize, "%d\n", i);
    39                 assert(strlen(string) == len);
     39                if (strlen(string) != len) {
     40                        fprintf(stderr, "sprintf_append failed: strlen(string) %lld != len %lld\n",
     41                                (long long int)strlen(string), (long long int)len);
     42                        return false;
     43                }
    4044        }
    4145
    4246        talloc_destroy(mem_ctx);
    4347
    44         return 0;
     48        return true;
    4549}
  • vendor/current/source3/torture/test_addrchange.c

    r740 r988  
    2020#include "includes.h"
    2121#include "lib/addrchange.h"
     22#include "lib/util/tevent_ntstatus.h"
    2223#include "proto.h"
    2324
     
    3132        int i;
    3233
    33         ev = tevent_context_init(talloc_tos());
     34        ev = samba_tevent_context_init(talloc_tos());
    3435        if (ev == NULL) {
    3536                d_fprintf(stderr, "tevent_context_init failed\n");
  • vendor/current/source3/torture/test_async_echo.c

    r740 r988  
    4747}
    4848
    49 static void cli_close_done(struct tevent_req *req)
     49static void write_andx_done(struct tevent_req *req)
    5050{
    5151        int *done = (int *)tevent_req_callback_data_void(req);
     
    5555        status = cli_write_andx_recv(req, &written);
    5656        TALLOC_FREE(req);
    57         printf("close returned %s\n", nt_errstr(status));
     57        printf("cli_write_andx returned %s\n", nt_errstr(status));
    5858        *done -= 1;
    5959}
     
    6969        bool ret = false;
    7070        int i, num_reqs;
    71         uint8_t buf[32768];
     71        uint8_t buf[65536];
    7272
    7373        printf("Starting ASYNC_ECHO\n");
    7474
    75         ev = tevent_context_init(talloc_tos());
     75        ev = samba_tevent_context_init(talloc_tos());
    7676        if (ev == NULL) {
    7777                printf("tevent_context_init failed\n");
     
    8383                goto fail;
    8484        }
    85         status = cli_rpc_pipe_open_noauth(cli, &ndr_table_rpcecho.syntax_id,
     85        status = cli_rpc_pipe_open_noauth(cli, &ndr_table_rpcecho,
    8686                                          &p);
    8787        if (!NT_STATUS_IS_OK(status)) {
     
    112112
    113113        for (i=0; i<10; i++) {
    114                 req = cli_write_andx_send(ev, ev, cli, 4711, 0, buf, 0, sizeof(buf));
     114                req = cli_write_andx_send(ev, ev, cli, 4711, 0, buf, 0,
     115                                          sizeof(buf));
    115116                if (req == NULL) {
    116                         printf("cli_close_send failed\n");
     117                        printf("cli_write_andx_send failed\n");
    117118                        goto fail;
    118119                }
    119                 tevent_req_set_callback(req, cli_close_done, &num_reqs);
     120                tevent_req_set_callback(req, write_andx_done, &num_reqs);
    120121                num_reqs += 1;
    121122
    122                 req = cli_echo_send(ev, ev, cli, 1, data_blob_const("hello", 5));
     123                req = cli_echo_send(ev, ev, cli, 1,
     124                                    data_blob_const("hello", 5));
    123125                if (req == NULL) {
    124126                        printf("cli_echo_send failed\n");
  • vendor/current/source3/torture/test_case_insensitive.c

    r740 r988  
    5050                goto rmdir;
    5151        }
    52         status = cli_open(cli, "x\\y", O_RDWR|O_CREAT, 0, &fnum);
     52        status = cli_openx(cli, "x\\y", O_RDWR|O_CREAT, 0, &fnum);
    5353        if (!NT_STATUS_IS_OK(status)) {
    54                 printf("cli_open failed: %s\n", nt_errstr(status));
     54                printf("cli_openx failed: %s\n", nt_errstr(status));
    5555
    5656                if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_IS_A_DIRECTORY)) {
  • vendor/current/source3/torture/test_ntlm_auth.py

    r414 r988  
    2828
    2929class ReadChildError(Exception):
    30         pass
     30    pass
    3131
    3232class WriteChildError(Exception):
    33         pass
     33    pass
    3434
    3535def readLine(pipe):
    36         """readLine(pipe) -> str
    37         Read a line from the child's pipe, returns the string read.
    38         Throws ReadChildError if the read fails.
    39         """
    40         buf = os.read(pipe, 2047)
    41         newline = buf.find('\n')
    42         if newline == -1:
    43                 raise ReadChildError()
    44         return buf[:newline]
     36    """readLine(pipe) -> str
     37    Read a line from the child's pipe, returns the string read.
     38    Throws ReadChildError if the read fails.
     39    """
     40    buf = os.read(pipe, 2047)
     41    newline = buf.find('\n')
     42    if newline == -1:
     43        raise ReadChildError()
     44    return buf[:newline]
    4545
    4646def writeLine(pipe, buf):
    47         """writeLine(pipe, buf) -> nul
    48         Write a line to the child's pipe.
    49         Raises WriteChildError if the write fails.
    50         """
    51         written = os.write(pipe, buf)
    52         if written != len(buf):
    53                 raise WriteChildError()
    54         os.write(pipe, "\n")
     47    """writeLine(pipe, buf) -> nul
     48    Write a line to the child's pipe.
     49    Raises WriteChildError if the write fails.
     50    """
     51    written = os.write(pipe, buf)
     52    if written != len(buf):
     53        raise WriteChildError()
     54    os.write(pipe, "\n")
    5555
    5656def parseCommandLine():
    57         """parseCommandLine() -> (opts, ntlm_auth_path)
    58         Parse the command line.
    59         Return a tuple consisting of the options and the path to ntlm_auth.
    60         """
    61         usage = "usage: %prog [options] path/to/ntlm_auth"
    62         parser = OptionParser(usage)
    63 
    64         parser.set_defaults(client_username="foo")
    65         parser.set_defaults(client_password="secret")
    66         parser.set_defaults(client_domain="FOO")
    67         parser.set_defaults(client_helper="ntlmssp-client-1")
    68 
    69         parser.set_defaults(server_username="foo")
    70         parser.set_defaults(server_password="secret")
    71         parser.set_defaults(server_domain="FOO")
    72         parser.set_defaults(server_helper="squid-2.5-ntlmssp")
    73         parser.set_defaults(config_file="/etc/samba/smb.conf")
    74 
    75         parser.add_option("--client-username", dest="client_username",\
    76                                 help="User name for the client. [default: foo]")
    77         parser.add_option("--client-password", dest="client_password",\
    78                                 help="Password the client will send. [default: secret]")
    79         parser.add_option("--client-domain", dest="client_domain",\
    80                                 help="Domain the client authenticates for. [default: FOO]")
    81         parser.add_option("--client-helper", dest="client_helper",\
    82                                 help="Helper mode for the ntlm_auth client. [default: ntlmssp-client-1]")
    83 
    84         parser.add_option("--server-username", dest="server_username",\
    85                                 help="User name server uses for local auth. [default: foo]")
    86         parser.add_option("--server-password", dest="server_password",\
    87                                 help="Password server uses for local auth. [default: secret]")
    88         parser.add_option("--server-domain", dest="server_domain",\
    89                                 help="Domain server uses for local auth. [default: FOO]")
    90         parser.add_option("--server-helper", dest="server_helper",\
    91                                 help="Helper mode for the ntlm_auth server. [default: squid-2.5-server]")
    92 
    93         parser.add_option("-s", "--configfile", dest="config_file",\
    94                                 help="Path to smb.conf file. [default:/etc/samba/smb.conf")
    95 
    96         (opts, args) = parser.parse_args()
    97         if len(args) != 1:
    98                 parser.error("Invalid number of arguments.")
    99 
    100         if not os.access(args[0], os.X_OK):
    101                 parser.error("%s is not executable." % args[0])
    102 
    103         return (opts, args[0])
     57    """parseCommandLine() -> (opts, ntlm_auth_path)
     58    Parse the command line.
     59    Return a tuple consisting of the options and the path to ntlm_auth.
     60    """
     61    usage = "usage: %prog [options] path/to/ntlm_auth"
     62    parser = OptionParser(usage)
     63
     64    parser.set_defaults(client_username="foo")
     65    parser.set_defaults(client_password="secret")
     66    parser.set_defaults(client_domain="FOO")
     67    parser.set_defaults(client_helper="ntlmssp-client-1")
     68
     69    parser.set_defaults(server_username="foo")
     70    parser.set_defaults(server_password="secret")
     71    parser.set_defaults(server_domain="FOO")
     72    parser.set_defaults(server_helper="squid-2.5-ntlmssp")
     73    parser.set_defaults(config_file="/etc/samba/smb.conf")
     74
     75    parser.add_option("--client-username", dest="client_username",\
     76                help="User name for the client. [default: foo]")
     77    parser.add_option("--client-password", dest="client_password",\
     78                help="Password the client will send. [default: secret]")
     79    parser.add_option("--client-domain", dest="client_domain",\
     80                help="Domain the client authenticates for. [default: FOO]")
     81    parser.add_option("--client-helper", dest="client_helper",\
     82                help="Helper mode for the ntlm_auth client. [default: ntlmssp-client-1]")
     83    parser.add_option("--client-use-cached-creds", dest="client_use_cached_creds",\
     84                help="Use winbindd credentials cache (rather than default username/pw)", action="store_true")
     85
     86    parser.add_option("--target-hostname", dest="target_hostname",\
     87                help="Target hostname for kerberos")
     88    parser.add_option("--target-service", dest="target_service",\
     89                help="Target service for kerberos")
     90
     91
     92    parser.add_option("--server-username", dest="server_username",\
     93                help="User name server uses for local auth. [default: foo]")
     94    parser.add_option("--server-password", dest="server_password",\
     95                help="Password server uses for local auth. [default: secret]")
     96    parser.add_option("--server-domain", dest="server_domain",\
     97                help="Domain server uses for local auth. [default: FOO]")
     98    parser.add_option("--server-helper", dest="server_helper",\
     99                help="Helper mode for the ntlm_auth server. [default: squid-2.5-server]")
     100    parser.add_option("--server-use-winbindd", dest="server_use_winbindd",\
     101                help="Use winbindd to check the password (rather than default username/pw)", action="store_true")
     102    parser.add_option("--require-membership-of", dest="sid",\
     103                help="Require that the user is a member of this group to authenticate.")
     104
     105
     106    parser.add_option("-s", "--configfile", dest="config_file",\
     107                help="Path to smb.conf file. [default:/etc/samba/smb.conf")
     108
     109    (opts, args) = parser.parse_args()
     110    if len(args) != 1:
     111        parser.error("Invalid number of arguments.")
     112
     113    if not os.access(args[0], os.X_OK):
     114        parser.error("%s is not executable." % args[0])
     115
     116    return (opts, args[0])
    104117
    105118
    106119def main():
    107         """main() -> int
    108         Run the test.
    109         Returns 0 if test succeeded, <>0 otherwise.
    110         """
    111         (opts, ntlm_auth_path) = parseCommandLine()
    112 
    113         (client_in_r,  client_in_w)  = os.pipe()
    114         (client_out_r, client_out_w) = os.pipe()
    115 
    116         client_pid = os.fork()
    117 
    118         if not client_pid:
    119                 # We're in the client child
    120                 os.close(0)
    121                 os.close(1)
    122 
    123                 os.dup2(client_out_r, 0)
    124                 os.close(client_out_r)
    125                 os.close(client_out_w)
    126 
    127                 os.dup2(client_in_w, 1)
    128                 os.close(client_in_r)
    129                 os.close(client_in_w)
    130 
    131                 client_args = []
    132                 client_args.append("--helper-protocol=%s" % opts.client_helper)
    133                 client_args.append("--username=%s" % opts.client_username)
    134                 client_args.append("--password=%s" % opts.client_password)
    135                 client_args.append("--domain=%s" % opts.client_domain)
    136                 client_args.append("--configfile=%s" % opts.config_file)
    137 
    138                 os.execv(ntlm_auth_path, client_args)
    139 
    140         client_in = client_in_r
    141         os.close(client_in_w)
    142 
    143         client_out = client_out_w
    144         os.close(client_out_r)
    145 
    146         (server_in_r,  server_in_w)  = os.pipe()
    147         (server_out_r, server_out_w) = os.pipe()
    148 
    149         server_pid = os.fork()
    150 
    151         if not server_pid:
    152                 # We're in the server child
    153                 os.close(0)
    154                 os.close(1)
    155 
    156                 os.dup2(server_out_r, 0)
    157                 os.close(server_out_r)
    158                 os.close(server_out_w)
    159 
    160                 os.dup2(server_in_w, 1)
    161                 os.close(server_in_r)
    162                 os.close(server_in_w)
    163 
    164                 server_args = []
    165                 server_args.append("--helper-protocol=%s" % opts.server_helper)
    166                 server_args.append("--username=%s" % opts.server_username)
    167                 server_args.append("--password=%s" % opts.server_password)
    168                 server_args.append("--domain=%s" % opts.server_domain)
    169                 server_args.append("--configfile=%s" % opts.config_file)
    170 
    171                 os.execv(ntlm_auth_path, server_args)
    172 
    173         server_in = server_in_r
    174         os.close(server_in_w)
    175 
    176         server_out = server_out_w
    177         os.close(server_out_r)
    178 
    179         # We're in the parent
    180         writeLine(client_out, "YR")
    181         buf = readLine(client_in)
    182 
    183         if buf.count("YR ", 0, 3) != 1:
    184                 sys.exit(1)
    185 
    186         writeLine(server_out, buf)
    187         buf = readLine(server_in)
    188 
    189         if buf.count("TT ", 0, 3) != 1:
    190                 sys.exit(2)
    191 
    192         writeLine(client_out, buf)
    193         buf = readLine(client_in)
    194 
    195         if buf.count("AF ", 0, 3) != 1:
    196                 sys.exit(3)
    197 
    198         # Client sends 'AF <base64 blob>' but server expects 'KK <abse64 blob>'
    199         buf = buf.replace("AF", "KK", 1)
    200 
    201         writeLine(server_out, buf)
    202         buf = readLine(server_in)
    203 
    204         if buf.count("AF ", 0, 3) != 1:
    205                 sys.exit(4)
    206 
    207         os.close(server_in)
    208         os.close(server_out)
    209         os.close(client_in)
    210         os.close(client_out)
    211         os.waitpid(server_pid, 0)
    212         os.waitpid(client_pid, 0)
    213         sys.exit(0)
     120    """main() -> int
     121    Run the test.
     122    Returns 0 if test succeeded, <>0 otherwise.
     123    """
     124    (opts, ntlm_auth_path) = parseCommandLine()
     125
     126    (client_in_r,  client_in_w)  = os.pipe()
     127    (client_out_r, client_out_w) = os.pipe()
     128
     129    client_pid = os.fork()
     130
     131    if not client_pid:
     132        # We're in the client child
     133        os.close(0)
     134        os.close(1)
     135
     136        os.dup2(client_out_r, 0)
     137        os.close(client_out_r)
     138        os.close(client_out_w)
     139
     140        os.dup2(client_in_w, 1)
     141        os.close(client_in_r)
     142        os.close(client_in_w)
     143
     144        client_args = []
     145        client_args.append("--helper-protocol=%s" % opts.client_helper)
     146        client_args.append("--username=%s" % opts.client_username)
     147        if opts.client_use_cached_creds:
     148            client_args.append("--use-cached-creds")
     149        else:
     150            client_args.append("--password=%s" % opts.client_password)
     151        client_args.append("--domain=%s" % opts.client_domain)
     152        client_args.append("--configfile=%s" % opts.config_file)
     153        if opts.target_service:
     154            client_args.append("--target-service=%s" % opts.target_service)
     155        if opts.target_hostname:
     156            client_args.append("--target-hostname=%s" % opts.target_hostname)
     157
     158        os.execv(ntlm_auth_path, client_args)
     159
     160    client_in = client_in_r
     161    os.close(client_in_w)
     162
     163    client_out = client_out_w
     164    os.close(client_out_r)
     165
     166    (server_in_r,  server_in_w)  = os.pipe()
     167    (server_out_r, server_out_w) = os.pipe()
     168
     169    server_pid = os.fork()
     170
     171    if not server_pid:
     172        # We're in the server child
     173        os.close(0)
     174        os.close(1)
     175
     176        os.dup2(server_out_r, 0)
     177        os.close(server_out_r)
     178        os.close(server_out_w)
     179
     180        os.dup2(server_in_w, 1)
     181        os.close(server_in_r)
     182        os.close(server_in_w)
     183
     184        server_args = []
     185        server_args.append("--helper-protocol=%s" % opts.server_helper)
     186        if not opts.server_use_winbindd:
     187            server_args.append("--username=%s" % opts.server_username)
     188            server_args.append("--password=%s" % opts.server_password)
     189            server_args.append("--domain=%s" % opts.server_domain)
     190            if opts.sid:
     191                raise Exception("Server must be using winbindd for require-membership-of.")
     192        else:
     193            if opts.sid:
     194                server_args.append("--require-membership-of=%s" % opts.sid)
     195
     196        server_args.append("--configfile=%s" % opts.config_file)
     197
     198        os.execv(ntlm_auth_path, server_args)
     199
     200    server_in = server_in_r
     201    os.close(server_in_w)
     202
     203    server_out = server_out_w
     204    os.close(server_out_r)
     205
     206    if opts.client_helper == "ntlmssp-client-1" and opts.server_helper == "squid-2.5-ntlmssp":
     207
     208        # We're in the parent
     209        writeLine(client_out, "YR")
     210        buf = readLine(client_in)
     211
     212        if buf.count("YR ", 0, 3) != 1:
     213            sys.exit(1)
     214
     215        writeLine(server_out, buf)
     216        buf = readLine(server_in)
     217
     218        if buf.count("TT ", 0, 3) != 1:
     219            sys.exit(2)
     220
     221        writeLine(client_out, buf)
     222        buf = readLine(client_in)
     223
     224        if buf.count("AF ", 0, 3) != 1:
     225            sys.exit(3)
     226
     227        # Client sends 'AF <base64 blob>' but server expects 'KK <abse64 blob>'
     228        buf = buf.replace("AF", "KK", 1)
     229
     230        writeLine(server_out, buf)
     231        buf = readLine(server_in)
     232
     233        if buf.count("AF ", 0, 3) != 1:
     234            sys.exit(4)
     235
     236
     237    elif opts.client_helper == "ntlmssp-client-1" and opts.server_helper == "gss-spnego":
     238        # We're in the parent
     239        writeLine(client_out, "YR")
     240        buf = readLine(client_in)
     241
     242        if buf.count("YR ", 0, 3) != 1:
     243            sys.exit(1)
     244
     245        writeLine(server_out, buf)
     246        buf = readLine(server_in)
     247
     248        if buf.count("TT ", 0, 3) != 1:
     249            sys.exit(2)
     250
     251        writeLine(client_out, buf)
     252        buf = readLine(client_in)
     253
     254        if buf.count("AF ", 0, 3) != 1:
     255            sys.exit(3)
     256
     257        # Client sends 'AF <base64 blob>' but server expects 'KK <abse64 blob>'
     258        buf = buf.replace("AF", "KK", 1)
     259
     260        writeLine(server_out, buf)
     261        buf = readLine(server_in)
     262
     263        if buf.count("AF * ", 0, 5) != 1:
     264            sys.exit(4)
     265
     266
     267    elif opts.client_helper == "gss-spnego-client" and opts.server_helper == "gss-spnego":
     268        # We're in the parent
     269        writeLine(server_out, "YR")
     270        buf = readLine(server_in)
     271
     272        while True:
     273            if buf.count("AF ", 0, 3) != 1 and buf.count("TT ", 0, 3) != 1:
     274                sys.exit(1)
     275
     276            writeLine(client_out, buf)
     277            buf = readLine(client_in)
     278
     279            if buf.count("AF", 0, 2) == 1:
     280                break
     281
     282            if buf.count("AF ", 0, 5) != 1 and buf.count("KK ", 0, 3) != 1 and buf.count("TT ", 0, 3) != 1:
     283                sys.exit(2)
     284
     285            writeLine(server_out, buf)
     286            buf = readLine(server_in)
     287
     288            if buf.count("AF * ", 0, 5) == 1:
     289                break
     290
     291    else:
     292        sys.exit(5)
     293
     294    if opts.client_helper == "ntlmssp-client-1":
     295        writeLine(client_out, "GK")
     296        buf = readLine(client_in)
     297
     298        if buf.count("GK ", 0, 3) != 1:
     299            sys.exit(4)
     300
     301        writeLine(client_out, "GF")
     302        buf = readLine(client_in)
     303
     304        if buf.count("GF ", 0, 3) != 1:
     305            sys.exit(4)
     306
     307    if opts.server_helper == "squid-2.5-ntlmssp":
     308        writeLine(server_out, "GK")
     309        buf = readLine(server_in)
     310
     311        if buf.count("GK ", 0, 3) != 1:
     312            sys.exit(4)
     313
     314        writeLine(server_out, "GF")
     315        buf = readLine(server_in)
     316
     317        if buf.count("GF ", 0, 3) != 1:
     318            sys.exit(4)
     319
     320    os.close(server_in)
     321    os.close(server_out)
     322    os.close(client_in)
     323    os.close(client_out)
     324    os.waitpid(server_pid, 0)
     325    os.waitpid(client_pid, 0)
     326    sys.exit(0)
    214327
    215328if __name__ == "__main__":
    216         main()
    217 
    218 
     329    main()
     330
     331
  • vendor/current/source3/torture/test_posix_append.c

    r740 r988  
    3434        NTSTATUS status;
    3535        uint16_t fnum;
    36         SMB_OFF_T size;
     36        off_t size;
    3737        uint8_t c = '\0';
    3838        bool ret = false;
     
    5858                FILE_OVERWRITE_IF,
    5959                FILE_NON_DIRECTORY_FILE|FILE_DELETE_ON_CLOSE,
    60                 0, &fnum);
     60                0, &fnum, NULL);
    6161
    6262        if (!NT_STATUS_IS_OK(status)) {
  • vendor/current/source3/torture/torture.c

    r746 r988  
    2727#include "tldap_util.h"
    2828#include "../librpc/gen_ndr/svcctl.h"
    29 #include "memcache.h"
     29#include "../lib/util/memcache.h"
    3030#include "nsswitch/winbind_client.h"
    31 #include "dbwrap.h"
     31#include "dbwrap/dbwrap.h"
     32#include "dbwrap/dbwrap_open.h"
     33#include "dbwrap/dbwrap_rbt.h"
    3234#include "talloc_dict.h"
    3335#include "async_smb.h"
     
    3840#include "../lib/util/tevent_ntstatus.h"
    3941#include "util_tdb.h"
     42#include "../libcli/smb/read_smb.h"
     43#include "../libcli/smb/smbXcli_base.h"
     44#include "lib/util/sys_rw_data.h"
    4045
    4146extern char *optarg;
    4247extern int optind;
    4348
    44 static fstring host, workgroup, share, password, username, myname;
    45 static int max_protocol = PROTOCOL_NT1;
     49fstring host, workgroup, share, password, username, myname;
    4650static const char *sockops="TCP_NODELAY";
    47 static int nprocs=1;
     51int torture_nprocs=1;
    4852static int port_to_use=0;
    4953int torture_numops=100;
     
    5559static bool use_level_II_oplocks;
    5660static const char *client_txt = "client_oplocks.txt";
     61static bool disable_spnego;
    5762static bool use_kerberos;
     63static bool force_dos_errors;
    5864static fstring multishare_conn_fname;
    5965static bool use_multishare_conn = False;
    6066static bool do_encrypt;
    6167static const char *local_path = NULL;
    62 static int signing_state = Undefined;
     68static enum smb_signing_setting signing_state = SMB_SIGNING_DEFAULT;
     69char *test_filename;
    6370
    6471bool torture_showall = False;
    6572
    6673static double create_procs(bool (*fn)(int), bool *result);
    67 
    68 
    69 /* return a pointer to a anonymous shared memory segment of size "size"
    70    which will persist across fork() but will disappear when all processes
    71    exit
    72 
    73    The memory is not zeroed
    74 
    75    This function uses system5 shared memory. It takes advantage of a property
    76    that the memory is not destroyed if it is attached when the id is removed
    77    */
    78 void *shm_setup(int size)
    79 {
    80         int shmid;
    81         void *ret;
    82 
    83 #ifdef __QNXNTO__
    84         shmid = shm_open("private", O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
    85         if (shmid == -1) {
    86                 printf("can't get shared memory\n");
    87                 exit(1);
    88         }
    89         shm_unlink("private");
    90         if (ftruncate(shmid, size) == -1) {
    91                 printf("can't set shared memory size\n");
    92                 exit(1);
    93         }
    94         ret = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, shmid, 0);
    95         if (ret == MAP_FAILED) {
    96                 printf("can't map shared memory\n");
    97                 exit(1);
    98         }
    99 #else
    100         shmid = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
    101         if (shmid == -1) {
    102                 printf("can't get shared memory\n");
    103                 exit(1);
    104         }
    105         ret = (void *)shmat(shmid, 0, 0);
    106         if (!ret || ret == (void *)-1) {
    107                 printf("can't attach to shared memory\n");
    108                 return NULL;
    109         }
    110         /* the following releases the ipc, but note that this process
    111            and all its children will still have access to the memory, its
    112            just that the shmid is no longer valid for other shm calls. This
    113            means we don't leave behind lots of shm segments after we exit
    114 
    115            See Stevens "advanced programming in unix env" for details
    116            */
    117         shmctl(shmid, IPC_RMID, 0);
    118 #endif
    119 
    120         return ret;
    121 }
    12274
    12375/********************************************************************
     
    12880                        const char *sharename)
    12981{
    130         uint16 major, minor;
    131         uint32 caplow, caphigh;
     82        uint16_t major, minor;
     83        uint32_t caplow, caphigh;
    13284        NTSTATUS status;
    13385
     
    177129static struct cli_state *open_nbt_connection(void)
    178130{
    179         struct nmb_name called, calling;
    180         struct sockaddr_storage ss;
    181131        struct cli_state *c;
    182132        NTSTATUS status;
    183 
    184         make_nmb_name(&calling, myname, 0x0);
    185         make_nmb_name(&called , host, 0x20);
    186 
    187         zero_sockaddr(&ss);
    188 
    189         if (!(c = cli_initialise_ex(signing_state))) {
    190                 printf("Failed initialize cli_struct to connect with %s\n", host);
    191                 return NULL;
    192         }
    193 
    194         c->port = port_to_use;
    195 
    196         status = cli_connect(c, host, &ss);
     133        int flags = 0;
     134
     135        if (disable_spnego) {
     136                flags |= CLI_FULL_CONNECTION_DONT_SPNEGO;
     137        }
     138
     139        if (use_oplocks) {
     140                flags |= CLI_FULL_CONNECTION_OPLOCKS;
     141        }
     142
     143        if (use_level_II_oplocks) {
     144                flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
     145        }
     146
     147        if (use_kerberos) {
     148                flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
     149        }
     150
     151        if (force_dos_errors) {
     152                flags |= CLI_FULL_CONNECTION_FORCE_DOS_ERRORS;
     153        }
     154
     155        status = cli_connect_nb(host, NULL, port_to_use, 0x20, myname,
     156                                signing_state, flags, &c);
    197157        if (!NT_STATUS_IS_OK(status)) {
    198158                printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
     
    200160        }
    201161
    202         c->use_kerberos = use_kerberos;
    203 
    204         c->timeout = 120000; /* set a really long timeout (2 minutes) */
    205         if (use_oplocks) c->use_oplocks = True;
    206         if (use_level_II_oplocks) c->use_level_II_oplocks = True;
    207 
    208         if (!cli_session_request(c, &calling, &called)) {
    209                 /*
    210                  * Well, that failed, try *SMBSERVER ...
    211                  * However, we must reconnect as well ...
    212                  */
    213                 status = cli_connect(c, host, &ss);
    214                 if (!NT_STATUS_IS_OK(status)) {
    215                         printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
    216                         return NULL;
    217                 }
    218 
    219                 make_nmb_name(&called, "*SMBSERVER", 0x20);
    220                 if (!cli_session_request(c, &calling, &called)) {
    221                         printf("%s rejected the session\n",host);
    222                         printf("We tried with a called name of %s & %s\n",
    223                                 host, "*SMBSERVER");
    224                         cli_shutdown(c);
    225                         return NULL;
    226                 }
    227         }
     162        cli_set_timeout(c, 120000); /* set a really long timeout (2 minutes) */
    228163
    229164        return c;
     
    234169****************************************************************************/
    235170
    236 static bool cli_bad_session_request(struct cli_state *cli,
     171static bool cli_bad_session_request(int fd,
    237172                         struct nmb_name *calling, struct nmb_name *called)
    238173{
    239         char *p;
    240         int len = 4;
    241         int namelen = 0;
    242         char *tmp;
    243 
    244         memcpy(&(cli->calling), calling, sizeof(*calling));
    245         memcpy(&(cli->called ), called , sizeof(*called ));
    246 
    247         /* put in the destination name */
    248 
    249         tmp = name_mangle(talloc_tos(), cli->called.name,
    250                           cli->called.name_type);
    251         if (tmp == NULL) {
    252                 return false;
    253         }
    254 
    255         p = cli->outbuf+len;
    256         namelen = name_len((unsigned char *)tmp, talloc_get_size(tmp));
    257         if (namelen > 0) {
    258                 memcpy(p, tmp, namelen);
    259                 len += namelen;
    260         }
    261         TALLOC_FREE(tmp);
     174        TALLOC_CTX *frame;
     175        uint8_t len_buf[4];
     176        struct iovec iov[3];
     177        ssize_t len;
     178        uint8_t *inbuf;
     179        int err;
     180        bool ret = false;
     181        uint8_t message_type;
     182        uint8_t error;
     183        struct tevent_context *ev;
     184        struct tevent_req *req;
     185
     186        frame = talloc_stackframe();
     187
     188        iov[0].iov_base = len_buf;
     189        iov[0].iov_len  = sizeof(len_buf);
     190
     191        /* put in the destination name */
     192
     193        iov[1].iov_base = name_mangle(talloc_tos(), called->name,
     194                                      called->name_type);
     195        if (iov[1].iov_base == NULL) {
     196                goto fail;
     197        }
     198        iov[1].iov_len = name_len((unsigned char *)iov[1].iov_base,
     199                                  talloc_get_size(iov[1].iov_base));
     200
     201        /* and my name */
     202
     203        iov[2].iov_base = name_mangle(talloc_tos(), calling->name,
     204                                      calling->name_type);
     205        if (iov[2].iov_base == NULL) {
     206                goto fail;
     207        }
     208        iov[2].iov_len = name_len((unsigned char *)iov[2].iov_base,
     209                                  talloc_get_size(iov[2].iov_base));
    262210
    263211        /* Deliberately corrupt the name len (first byte) */
    264         *p = 100;
    265 
    266         /* and my name */
    267 
    268         tmp = name_mangle(talloc_tos(), cli->calling.name,
    269                           cli->calling.name_type);
    270         if (tmp == NULL) {
    271                 return false;
    272         }
    273 
    274         p = cli->outbuf+len;
    275         namelen = name_len((unsigned char *)tmp, talloc_get_size(tmp));
    276         if (namelen > 0) {
    277                 memcpy(p, tmp, namelen);
    278                 len += namelen;
    279         }
    280         TALLOC_FREE(tmp);
    281         /* Deliberately corrupt the name len (first byte) */
    282         *p = 100;
    283 
    284         /* send a session request (RFC 1002) */
    285         /* setup the packet length
     212        *((uint8_t *)iov[2].iov_base) = 100;
     213
     214        /* send a session request (RFC 1002) */
     215        /* setup the packet length
    286216         * Remove four bytes from the length count, since the length
    287217         * field in the NBT Session Service header counts the number
     
    290220         * CRH.
    291221         */
    292         len -= 4;
    293         _smb_setlen(cli->outbuf,len);
    294         SCVAL(cli->outbuf,0,0x81);
    295 
    296         cli_send_smb(cli);
    297         DEBUG(5,("Sent session request\n"));
    298 
    299         if (!cli_receive_smb(cli))
    300                 return False;
    301 
    302         if (CVAL(cli->inbuf,0) != 0x82) {
    303                 /* This is the wrong place to put the error... JRA. */
    304                 cli->rap_error = CVAL(cli->inbuf,4);
    305                 return False;
     222
     223        _smb_setlen(len_buf, iov[1].iov_len + iov[2].iov_len);
     224        SCVAL(len_buf,0,0x81);
     225
     226        len = write_data_iov(fd, iov, 3);
     227        if (len == -1) {
     228                goto fail;
     229        }
     230
     231        ev = samba_tevent_context_init(frame);
     232        if (ev == NULL) {
     233                goto fail;
     234        }
     235        req = read_smb_send(frame, ev, fd);
     236        if (req == NULL) {
     237                goto fail;
     238        }
     239        if (!tevent_req_poll(req, ev)) {
     240                goto fail;
     241        }
     242        len = read_smb_recv(req, talloc_tos(), &inbuf, &err);
     243        if (len == -1) {
     244                errno = err;
     245                goto fail;
     246        }
     247        TALLOC_FREE(ev);
     248
     249        message_type = CVAL(inbuf, 0);
     250        if (message_type != 0x83) {
     251                d_fprintf(stderr, "Expected msg type 0x83, got 0x%2.2x\n",
     252                          message_type);
     253                goto fail;
    306254        }
    307         return(True);
    308 }
    309 
    310 static struct cli_state *open_bad_nbt_connection(void)
    311 {
    312         struct nmb_name called, calling;
    313         struct sockaddr_storage ss;
    314         struct cli_state *c;
    315         NTSTATUS status;
    316 
    317         make_nmb_name(&calling, myname, 0x0);
    318         make_nmb_name(&called , host, 0x20);
    319 
    320         zero_sockaddr(&ss);
    321 
    322         if (!(c = cli_initialise_ex(signing_state))) {
    323                 printf("Failed initialize cli_struct to connect with %s\n", host);
    324                 return NULL;
    325         }
    326 
    327         c->port = 139;
    328 
    329         status = cli_connect(c, host, &ss);
    330         if (!NT_STATUS_IS_OK(status)) {
    331                 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
    332                 return NULL;
    333         }
    334 
    335         c->timeout = 4000; /* set a short timeout (4 seconds) */
    336 
    337         if (!cli_bad_session_request(c, &calling, &called)) {
    338                 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
    339                 return NULL;
    340         }
    341 
    342         return c;
    343 }
    344 
     255
     256        if (smb_len(inbuf) != 1) {
     257                d_fprintf(stderr, "Expected smb_len 1, got %d\n",
     258                          (int)smb_len(inbuf));
     259                goto fail;
     260        }
     261
     262        error = CVAL(inbuf, 4);
     263        if (error !=  0x82) {
     264                d_fprintf(stderr, "Expected error 0x82, got %d\n",
     265                          (int)error);
     266                goto fail;
     267        }
     268
     269        ret = true;
     270fail:
     271        TALLOC_FREE(frame);
     272        return ret;
     273}
    345274
    346275/* Insert a NULL at the first separator of the given path and return a pointer
     
    427356        }
    428357
    429         (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */
     358        cli_set_timeout(*c, 120000); /* set a really long timeout (2 minutes) */
    430359
    431360        if (do_encrypt) {
     
    468397}
    469398
    470 bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
    471 {
    472         uint16 old_vuid = cli->vuid;
    473         fstring old_user_name;
     399bool torture_init_connection(struct cli_state **pcli)
     400{
     401        struct cli_state *cli;
     402
     403        cli = open_nbt_connection();
     404        if (cli == NULL) {
     405                return false;
     406        }
     407
     408        *pcli = cli;
     409        return true;
     410}
     411
     412bool torture_cli_session_setup2(struct cli_state *cli, uint16_t *new_vuid)
     413{
     414        uint16_t old_vuid = cli_state_get_uid(cli);
    474415        size_t passlen = strlen(password);
    475416        NTSTATUS status;
    476417        bool ret;
    477418
    478         fstrcpy(old_user_name, cli->user_name);
    479         cli->vuid = 0;
    480         ret = NT_STATUS_IS_OK(cli_session_setup(cli, username,
    481                                                 password, passlen,
    482                                                 password, passlen,
    483                                                 workgroup));
    484         *new_vuid = cli->vuid;
    485         cli->vuid = old_vuid;
    486         status = cli_set_username(cli, old_user_name);
    487         if (!NT_STATUS_IS_OK(status)) {
    488                 return false;
    489         }
     419        cli_state_set_uid(cli, 0);
     420        status = cli_session_setup(cli, username,
     421                                   password, passlen,
     422                                   password, passlen,
     423                                   workgroup);
     424        ret = NT_STATUS_IS_OK(status);
     425        *new_vuid = cli_state_get_uid(cli);
     426        cli_state_set_uid(cli, old_vuid);
    490427        return ret;
    491428}
     
    509446
    510447
     448/* check if the server produced the expected dos or nt error code */
     449static bool check_both_error(int line, NTSTATUS status,
     450                             uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
     451{
     452        if (NT_STATUS_IS_DOS(status)) {
     453                uint8_t cclass;
     454                uint32_t num;
     455
     456                /* Check DOS error */
     457                cclass = NT_STATUS_DOS_CLASS(status);
     458                num = NT_STATUS_DOS_CODE(status);
     459
     460                if (eclass != cclass || ecode != num) {
     461                        printf("unexpected error code class=%d code=%d\n",
     462                               (int)cclass, (int)num);
     463                        printf(" expected %d/%d %s (line=%d)\n",
     464                               (int)eclass, (int)ecode, nt_errstr(nterr), line);
     465                        return false;
     466                }
     467        } else {
     468                /* Check NT error */
     469                if (!NT_STATUS_EQUAL(nterr, status)) {
     470                        printf("unexpected error code %s\n",
     471                                nt_errstr(status));
     472                        printf(" expected %s (line=%d)\n",
     473                                nt_errstr(nterr), line);
     474                        return false;
     475                }
     476        }
     477
     478        return true;
     479}
     480
     481
    511482/* check if the server produced the expected error code */
    512 static bool check_error(int line, struct cli_state *c,
    513                         uint8 eclass, uint32 ecode, NTSTATUS nterr)
    514 {
    515         if (cli_is_dos_error(c)) {
    516                 uint8 cclass;
    517                 uint32 num;
     483static bool check_error(int line, NTSTATUS status,
     484                        uint8_t eclass, uint32_t ecode, NTSTATUS nterr)
     485{
     486        if (NT_STATUS_IS_DOS(status)) {
     487                uint8_t cclass;
     488                uint32_t num;
    518489
    519490                /* Check DOS error */
    520491
    521                 cli_dos_error(c, &cclass, &num);
     492                cclass = NT_STATUS_DOS_CLASS(status);
     493                num = NT_STATUS_DOS_CODE(status);
    522494
    523495                if (eclass != cclass || ecode != num) {
     
    525497                               (int)cclass, (int)num);
    526498                        printf(" expected %d/%d %s (line=%d)\n",
    527                                (int)eclass, (int)ecode, nt_errstr(nterr), line);
     499                               (int)eclass, (int)ecode, nt_errstr(nterr),
     500                               line);
    528501                        return False;
    529502                }
    530503
    531504        } else {
    532                 NTSTATUS status;
    533 
    534505                /* Check NT error */
    535506
    536                 status = cli_nt_error(c);
    537 
    538507                if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
    539                         printf("unexpected error code %s\n", nt_errstr(status));
    540                         printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
     508                        printf("unexpected error code %s\n",
     509                               nt_errstr(status));
     510                        printf(" expected %s (line=%d)\n", nt_errstr(nterr),
     511                               line);
    541512                        return False;
    542513                }
     
    547518
    548519
    549 static bool wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
    550 {
    551         while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
    552                 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
    553         }
    554         return True;
     520static bool wait_lock(struct cli_state *c, int fnum, uint32_t offset, uint32_t len)
     521{
     522        NTSTATUS status;
     523
     524        status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK);
     525
     526        while (!NT_STATUS_IS_OK(status)) {
     527                if (!check_both_error(__LINE__, status, ERRDOS,
     528                                      ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) {
     529                        return false;
     530                }
     531
     532                status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK);
     533        }
     534
     535        return true;
    555536}
    556537
     
    566547        char buf[1024];
    567548        bool correct = True;
     549        size_t nread = 0;
    568550        NTSTATUS status;
    569551
    570552        memset(buf, '\0', sizeof(buf));
    571553
    572         status = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
     554        status = cli_openx(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
    573555                         DENY_NONE, &fnum2);
    574556        if (!NT_STATUS_IS_OK(status)) {
    575                 status = cli_open(c, lockfname, O_RDWR, DENY_NONE, &fnum2);
    576         }
    577         if (!NT_STATUS_IS_OK(status)) {
    578                 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
     557                status = cli_openx(c, lockfname, O_RDWR, DENY_NONE, &fnum2);
     558        }
     559        if (!NT_STATUS_IS_OK(status)) {
     560                printf("open of %s failed (%s)\n",
     561                       lockfname, nt_errstr(status));
    579562                return False;
    580563        }
     
    592575                }
    593576
    594                 if (!NT_STATUS_IS_OK(cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL, &fnum))) {
    595                         printf("open failed (%s)\n", cli_errstr(c));
     577                status = cli_openx(c, fname, O_RDWR | O_CREAT | O_TRUNC,
     578                                  DENY_ALL, &fnum);
     579                if (!NT_STATUS_IS_OK(status)) {
     580                        printf("open failed (%s)\n", nt_errstr(status));
    596581                        correct = False;
    597582                        break;
     
    618603                pid2 = 0;
    619604
    620                 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
    621                         printf("read failed (%s)\n", cli_errstr(c));
    622                         correct = False;
     605                status = cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid),
     606                                  &nread);
     607                if (!NT_STATUS_IS_OK(status)) {
     608                        printf("read failed (%s)\n", nt_errstr(status));
     609                        correct = false;
     610                } else if (nread != sizeof(pid)) {
     611                        printf("read/write compare failed: "
     612                               "recv %ld req %ld\n", (unsigned long)nread,
     613                               (unsigned long)sizeof(pid));
     614                        correct = false;
    623615                }
    624616
     
    628620                }
    629621
    630                 if (!NT_STATUS_IS_OK(cli_close(c, fnum))) {
    631                         printf("close failed (%s)\n", cli_errstr(c));
     622                status = cli_close(c, fnum);
     623                if (!NT_STATUS_IS_OK(status)) {
     624                        printf("close failed (%s)\n", nt_errstr(status));
    632625                        correct = False;
    633626                }
    634627
    635                 if (!NT_STATUS_IS_OK(cli_unlink(c, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
    636                         printf("unlink failed (%s)\n", cli_errstr(c));
     628                status = cli_unlink(c, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     629                if (!NT_STATUS_IS_OK(status)) {
     630                        printf("unlink failed (%s)\n", nt_errstr(status));
    637631                        correct = False;
    638632                }
    639633
    640                 if (!NT_STATUS_IS_OK(cli_unlock(c, fnum2, n*sizeof(int), sizeof(int)))) {
    641                         printf("unlock failed (%s)\n", cli_errstr(c));
     634                status = cli_unlock(c, fnum2, n*sizeof(int), sizeof(int));
     635                if (!NT_STATUS_IS_OK(status)) {
     636                        printf("unlock failed (%s)\n", nt_errstr(status));
    642637                        correct = False;
    643638                }
     
    659654        cli = current_cli;
    660655
    661         cli_sockopt(cli, sockops);
     656        smbXcli_conn_set_sockopt(cli->conn, sockops);
    662657
    663658        ret = rw_torture(cli);
     
    678673        unsigned count;
    679674        unsigned countprev = 0;
    680         ssize_t sent = 0;
     675        size_t sent = 0;
    681676        bool correct = True;
    682677        NTSTATUS status = NT_STATUS_OK;
    683678
    684679        srandom(1);
    685         for (i = 0; i < sizeof(buf); i += sizeof(uint32))
     680        for (i = 0; i < sizeof(buf); i += sizeof(uint32_t))
    686681        {
    687682                SIVAL(buf, i, sys_random());
     
    690685        if (procnum == 0)
    691686        {
    692                 if (!NT_STATUS_IS_OK(cli_unlink(c, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
    693                         printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c));
    694                 }
    695 
    696                 if (!NT_STATUS_IS_OK(cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
    697                                  DENY_NONE, &fnum))) {
     687                status = cli_unlink(
     688                        c, lockfname,
     689                        FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     690                if (!NT_STATUS_IS_OK(status)) {
     691                        printf("unlink failed (%s) (normal, this file should "
     692                               "not exist)\n", nt_errstr(status));
     693                }
     694
     695                status = cli_openx(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
     696                                  DENY_NONE, &fnum);
     697                if (!NT_STATUS_IS_OK(status)) {
    698698                        printf("first open read/write of %s failed (%s)\n",
    699                                         lockfname, cli_errstr(c));
     699                                        lockfname, nt_errstr(status));
    700700                        return False;
    701701                }
     
    705705                for (i = 0; i < 500 && fnum == (uint16_t)-1; i++)
    706706                {
    707                         status = cli_open(c, lockfname, O_RDONLY,
     707                        status = cli_openx(c, lockfname, O_RDONLY,
    708708                                         DENY_NONE, &fnum);
    709                         if (!NT_STATUS_IS_OK(status)) {
     709                        if (NT_STATUS_IS_OK(status)) {
    710710                                break;
    711711                        }
     
    714714                if (!NT_STATUS_IS_OK(status)) {
    715715                        printf("second open read-only of %s failed (%s)\n",
    716                                         lockfname, cli_errstr(c));
     716                                        lockfname, nt_errstr(status));
    717717                        return False;
    718718                }
     
    738738
    739739                        status = cli_writeall(c, fnum, 0, (uint8_t *)buf+count,
    740                                               count, (size_t)sent, NULL);
     740                                              count, sent, NULL);
    741741                        if (!NT_STATUS_IS_OK(status)) {
    742742                                printf("write failed (%s)\n",
     
    747747                else
    748748                {
    749                         sent = cli_read(c, fnum, buf_rd+count, count,
    750                                                   sizeof(buf)-count);
    751                         if (sent < 0)
    752                         {
     749                        status = cli_read(c, fnum, buf_rd+count, count,
     750                                          sizeof(buf)-count, &sent);
     751                        if(!NT_STATUS_IS_OK(status)) {
    753752                                printf("read failed offset:%d size:%ld (%s)\n",
    754753                                       count, (unsigned long)sizeof(buf)-count,
    755                                        cli_errstr(c));
     754                                       nt_errstr(status));
    756755                                correct = False;
    757756                                sent = 0;
    758                         }
    759                         if (sent > 0)
    760                         {
     757                        } else if (sent > 0) {
    761758                                if (memcmp(buf_rd+count, buf+count, sent) != 0)
    762759                                {
     
    771768        }
    772769
    773         if (!NT_STATUS_IS_OK(cli_close(c, fnum))) {
    774                 printf("close failed (%s)\n", cli_errstr(c));
     770        status = cli_close(c, fnum);
     771        if (!NT_STATUS_IS_OK(status)) {
     772                printf("close failed (%s)\n", nt_errstr(status));
    775773                correct = False;
    776774        }
     
    788786        char buf_rd[131072];
    789787        bool correct = True;
    790         ssize_t bytes_read;
    791 
    792         if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
    793                 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
    794         }
    795 
    796         if (!NT_STATUS_IS_OK(cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
    797                          DENY_NONE, &fnum1))) {
     788        size_t bytes_read;
     789        NTSTATUS status;
     790
     791        status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     792        if (!NT_STATUS_IS_OK(status)) {
     793                printf("unlink failed (%s) (normal, this file should not exist)\n", nt_errstr(status));
     794        }
     795
     796        status = cli_openx(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
     797                          DENY_NONE, &fnum1);
     798        if (!NT_STATUS_IS_OK(status)) {
    798799                printf("first open read/write of %s failed (%s)\n",
    799                                 lockfname, cli_errstr(c1));
    800                 return False;
    801         }
    802         if (!NT_STATUS_IS_OK(cli_open(c2, lockfname, O_RDONLY,
    803                          DENY_NONE, &fnum2))) {
     800                                lockfname, nt_errstr(status));
     801                return False;
     802        }
     803
     804        status = cli_openx(c2, lockfname, O_RDONLY, DENY_NONE, &fnum2);
     805        if (!NT_STATUS_IS_OK(status)) {
    804806                printf("second open read-only of %s failed (%s)\n",
    805                                 lockfname, cli_errstr(c2));
     807                                lockfname, nt_errstr(status));
    806808                cli_close(c1, fnum1);
    807809                return False;
    808810        }
    809811
    810         for (i=0;i<torture_numops;i++)
     812        for (i = 0; i < torture_numops; i++)
    811813        {
    812                 NTSTATUS status;
    813814                size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
    814815                if (i % 10 == 0) {
     
    826827                }
    827828
    828                 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
    829                         printf("read failed (%s)\n", cli_errstr(c2));
    830                         printf("read %d, expected %ld\n", (int)bytes_read,
     829                status = cli_read(c2, fnum2, buf_rd, 0, buf_size, &bytes_read);
     830                if(!NT_STATUS_IS_OK(status)) {
     831                        printf("read failed (%s)\n", nt_errstr(status));
     832                        correct = false;
     833                        break;
     834                } else if (bytes_read != buf_size) {
     835                        printf("read failed\n");
     836                        printf("read %ld, expected %ld\n",
     837                               (unsigned long)bytes_read,
    831838                               (unsigned long)buf_size);
    832839                        correct = False;
     
    842849        }
    843850
    844         if (!NT_STATUS_IS_OK(cli_close(c2, fnum2))) {
    845                 printf("close failed (%s)\n", cli_errstr(c2));
     851        status = cli_close(c2, fnum2);
     852        if (!NT_STATUS_IS_OK(status)) {
     853                printf("close failed (%s)\n", nt_errstr(status));
    846854                correct = False;
    847855        }
    848         if (!NT_STATUS_IS_OK(cli_close(c1, fnum1))) {
    849                 printf("close failed (%s)\n", cli_errstr(c1));
     856
     857        status = cli_close(c1, fnum1);
     858        if (!NT_STATUS_IS_OK(status)) {
     859                printf("close failed (%s)\n", nt_errstr(status));
    850860                correct = False;
    851861        }
    852862
    853         if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
    854                 printf("unlink failed (%s)\n", cli_errstr(c1));
     863        status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     864        if (!NT_STATUS_IS_OK(status)) {
     865                printf("unlink failed (%s)\n", nt_errstr(status));
    855866                correct = False;
    856867        }
     
    867878                return False;
    868879        }
    869         cli_sockopt(cli1, sockops);
    870         cli_sockopt(cli2, sockops);
     880        smbXcli_conn_set_sockopt(cli1->conn, sockops);
     881        smbXcli_conn_set_sockopt(cli2->conn, sockops);
    871882
    872883        printf("starting readwritetest\n");
     
    898909        cli = current_cli;
    899910
    900         cli_sockopt(cli, sockops);
     911        smbXcli_conn_set_sockopt(cli->conn, sockops);
    901912
    902913        printf("run_readwritemulti: fname %s\n", randomfname);
     
    910921}
    911922
    912 static bool run_readwritelarge_internal(int max_xmit_k)
     923static bool run_readwritelarge_internal(void)
    913924{
    914925        static struct cli_state *cli1;
    915926        uint16_t fnum1;
    916927        const char *lockfname = "\\large.dat";
    917         SMB_OFF_T fsize;
     928        off_t fsize;
    918929        char buf[126*1024];
    919930        bool correct = True;
     931        NTSTATUS status;
    920932
    921933        if (!torture_open_connection(&cli1, 0)) {
    922934                return False;
    923935        }
    924         cli_sockopt(cli1, sockops);
     936        smbXcli_conn_set_sockopt(cli1->conn, sockops);
    925937        memset(buf,'\0',sizeof(buf));
    926938
    927         cli1->max_xmit = max_xmit_k*1024;
    928 
    929         if (signing_state == Required) {
    930                 /* Horrible cheat to force
    931                    multiple signed outstanding
    932                    packets against a Samba server.
    933                 */
    934                 cli1->is_samba = false;
    935         }
    936 
    937939        printf("starting readwritelarge_internal\n");
    938940
    939941        cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    940942
    941         if (!NT_STATUS_IS_OK(cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE, &fnum1))) {
    942                 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
     943        status = cli_openx(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL,
     944                          DENY_NONE, &fnum1);
     945        if (!NT_STATUS_IS_OK(status)) {
     946                printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status));
    943947                return False;
    944948        }
     
    946950        cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf), NULL);
    947951
    948         if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
    949                                      cli1, fnum1, NULL, &fsize, NULL, NULL,
    950                                      NULL, NULL, NULL))) {
    951                 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
     952        status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
     953                                     NULL, NULL, NULL);
     954        if (!NT_STATUS_IS_OK(status)) {
     955                printf("qfileinfo failed (%s)\n", nt_errstr(status));
    952956                correct = False;
    953957        }
     
    962966        }
    963967
    964         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    965                 printf("close failed (%s)\n", cli_errstr(cli1));
     968        status = cli_close(cli1, fnum1);
     969        if (!NT_STATUS_IS_OK(status)) {
     970                printf("close failed (%s)\n", nt_errstr(status));
    966971                correct = False;
    967972        }
    968973
    969         if (!NT_STATUS_IS_OK(cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
    970                 printf("unlink failed (%s)\n", cli_errstr(cli1));
     974        status = cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     975        if (!NT_STATUS_IS_OK(status)) {
     976                printf("unlink failed (%s)\n", nt_errstr(status));
    971977                correct = False;
    972978        }
    973979
    974         if (!NT_STATUS_IS_OK(cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE, &fnum1))) {
    975                 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
    976                 return False;
    977         }
    978 
    979         cli1->max_xmit = 4*1024;
     980        status = cli_openx(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL,
     981                          DENY_NONE, &fnum1);
     982        if (!NT_STATUS_IS_OK(status)) {
     983                printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status));
     984                return False;
     985        }
    980986
    981987        cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf), NULL);
    982988
    983         if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
    984                                      cli1, fnum1, NULL, &fsize, NULL, NULL,
    985                                      NULL, NULL, NULL))) {
    986                 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
     989        status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL,
     990                                     NULL, NULL, NULL);
     991        if (!NT_STATUS_IS_OK(status)) {
     992                printf("qfileinfo failed (%s)\n", nt_errstr(status));
    987993                correct = False;
    988994        }
     
    10121018#endif
    10131019
    1014         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    1015                 printf("close failed (%s)\n", cli_errstr(cli1));
     1020        status = cli_close(cli1, fnum1);
     1021        if (!NT_STATUS_IS_OK(status)) {
     1022                printf("close failed (%s)\n", nt_errstr(status));
    10161023                correct = False;
    10171024        }
     
    10251032static bool run_readwritelarge(int dummy)
    10261033{
    1027         return run_readwritelarge_internal(128);
     1034        return run_readwritelarge_internal();
    10281035}
    10291036
     
    10311038{
    10321039        bool ret;
    1033         signing_state = Required;
    1034         ret = run_readwritelarge_internal(2);
    1035         signing_state = Undefined;
     1040        signing_state = SMB_SIGNING_REQUIRED;
     1041        ret = run_readwritelarge_internal();
     1042        signing_state = SMB_SIGNING_DEFAULT;
    10361043        return ret;
    10371044}
     
    10571064        nbio_id = client;
    10581065
    1059         cli_sockopt(cli, sockops);
     1066        smbXcli_conn_set_sockopt(cli->conn, sockops);
    10601067
    10611068        nb_setup(cli);
     
    11461153        bool correct = True;
    11471154
    1148         nbio_shmem(nprocs);
     1155        nbio_shmem(torture_nprocs);
    11491156
    11501157        nbio_id = -1;
     
    11751182        time_t t1, t2;
    11761183        unsigned lock_timeout;
     1184        NTSTATUS status;
    11771185
    11781186        if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
    11791187                return False;
    11801188        }
    1181         cli_sockopt(cli1, sockops);
    1182         cli_sockopt(cli2, sockops);
     1189        smbXcli_conn_set_sockopt(cli1->conn, sockops);
     1190        smbXcli_conn_set_sockopt(cli2->conn, sockops);
    11831191
    11841192        printf("starting locktest1\n");
     
    11861194        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    11871195
    1188         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
    1189                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
    1190                 return False;
    1191         }
    1192         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum2))) {
    1193                 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
    1194                 return False;
    1195         }
    1196         if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum3))) {
    1197                 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
    1198                 return False;
    1199         }
    1200 
    1201         if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
    1202                 printf("lock1 failed (%s)\n", cli_errstr(cli1));
    1203                 return False;
    1204         }
    1205 
    1206 
    1207         if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
     1196        status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
     1197                          &fnum1);
     1198        if (!NT_STATUS_IS_OK(status)) {
     1199                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
     1200                return False;
     1201        }
     1202
     1203        status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum2);
     1204        if (!NT_STATUS_IS_OK(status)) {
     1205                printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
     1206                return False;
     1207        }
     1208
     1209        status = cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum3);
     1210        if (!NT_STATUS_IS_OK(status)) {
     1211                printf("open3 of %s failed (%s)\n", fname, nt_errstr(status));
     1212                return False;
     1213        }
     1214
     1215        status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK);
     1216        if (!NT_STATUS_IS_OK(status)) {
     1217                printf("lock1 failed (%s)\n", nt_errstr(status));
     1218                return false;
     1219        }
     1220
     1221        status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK);
     1222        if (NT_STATUS_IS_OK(status)) {
    12081223                printf("lock2 succeeded! This is a locking bug\n");
    1209                 return False;
     1224                return false;
    12101225        } else {
    1211                 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
    1212                                  NT_STATUS_LOCK_NOT_GRANTED)) return False;
    1213         }
    1214 
     1226                if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
     1227                                      NT_STATUS_LOCK_NOT_GRANTED)) {
     1228                        return false;
     1229                }
     1230        }
    12151231
    12161232        lock_timeout = (1 + (random() % 20));
    12171233        printf("Testing lock timeout with timeout=%u\n", lock_timeout);
    12181234        t1 = time(NULL);
    1219         if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
     1235        status = cli_lock32(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK);
     1236        if (NT_STATUS_IS_OK(status)) {
    12201237                printf("lock3 succeeded! This is a locking bug\n");
    1221                 return False;
     1238                return false;
    12221239        } else {
    1223                 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
    1224                                  NT_STATUS_FILE_LOCK_CONFLICT)) return False;
     1240                if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
     1241                                      NT_STATUS_FILE_LOCK_CONFLICT)) {
     1242                        return false;
     1243                }
    12251244        }
    12261245        t2 = time(NULL);
     
    12331252               (unsigned int)(t2-t1), lock_timeout);
    12341253
    1235         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
    1236                 printf("close1 failed (%s)\n", cli_errstr(cli1));
    1237                 return False;
    1238         }
    1239 
    1240         if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
     1254        status = cli_close(cli1, fnum2);
     1255        if (!NT_STATUS_IS_OK(status)) {
     1256                printf("close1 failed (%s)\n", nt_errstr(status));
     1257                return False;
     1258        }
     1259
     1260        status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK);
     1261        if (NT_STATUS_IS_OK(status)) {
    12411262                printf("lock4 succeeded! This is a locking bug\n");
    1242                 return False;
     1263                return false;
    12431264        } else {
    1244                 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
    1245                                  NT_STATUS_FILE_LOCK_CONFLICT)) return False;
    1246         }
    1247 
    1248         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    1249                 printf("close2 failed (%s)\n", cli_errstr(cli1));
    1250                 return False;
    1251         }
    1252 
    1253         if (!NT_STATUS_IS_OK(cli_close(cli2, fnum3))) {
    1254                 printf("close3 failed (%s)\n", cli_errstr(cli2));
    1255                 return False;
    1256         }
    1257 
    1258         if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
    1259                 printf("unlink failed (%s)\n", cli_errstr(cli1));
     1265                if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
     1266                                      NT_STATUS_FILE_LOCK_CONFLICT)) {
     1267                        return false;
     1268                }
     1269        }
     1270
     1271        status = cli_close(cli1, fnum1);
     1272        if (!NT_STATUS_IS_OK(status)) {
     1273                printf("close2 failed (%s)\n", nt_errstr(status));
     1274                return False;
     1275        }
     1276
     1277        status = cli_close(cli2, fnum3);
     1278        if (!NT_STATUS_IS_OK(status)) {
     1279                printf("close3 failed (%s)\n", nt_errstr(status));
     1280                return False;
     1281        }
     1282
     1283        status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     1284        if (!NT_STATUS_IS_OK(status)) {
     1285                printf("unlink failed (%s)\n", nt_errstr(status));
    12601286                return False;
    12611287        }
     
    12821308        static struct cli_state *cli;
    12831309        const char *fname = "\\tcontest.tmp";
    1284         uint16 fnum1;
    1285         uint16 cnum1, cnum2, cnum3;
    1286         uint16 vuid1, vuid2;
     1310        uint16_t fnum1;
     1311        uint16_t cnum1, cnum2, cnum3;
     1312        uint16_t vuid1, vuid2;
    12871313        char buf[4];
    12881314        bool ret = True;
     
    12941320                return False;
    12951321        }
    1296         cli_sockopt(cli, sockops);
     1322        smbXcli_conn_set_sockopt(cli->conn, sockops);
    12971323
    12981324        printf("starting tcontest\n");
     
    13001326        cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    13011327
    1302         if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
    1303                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
    1304                 return False;
    1305         }
    1306 
    1307         cnum1 = cli->cnum;
    1308         vuid1 = cli->vuid;
     1328        status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
     1329        if (!NT_STATUS_IS_OK(status)) {
     1330                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
     1331                return False;
     1332        }
     1333
     1334        cnum1 = cli_state_get_tid(cli);
     1335        vuid1 = cli_state_get_uid(cli);
    13091336
    13101337        status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
     
    13141341        }
    13151342
    1316         status = cli_tcon_andx(cli, share, "?????",
    1317                                password, strlen(password)+1);
     1343        status = cli_tree_connect(cli, share, "?????",
     1344                                  password, strlen(password)+1);
    13181345        if (!NT_STATUS_IS_OK(status)) {
    13191346                printf("%s refused 2nd tree connect (%s)\n", host,
     
    13231350        }
    13241351
    1325         cnum2 = cli->cnum;
     1352        cnum2 = cli_state_get_tid(cli);
    13261353        cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
    1327         vuid2 = cli->vuid + 1;
     1354        vuid2 = cli_state_get_uid(cli) + 1;
    13281355
    13291356        /* try a write with the wrong tid */
    1330         cli->cnum = cnum2;
     1357        cli_state_set_tid(cli, cnum2);
    13311358
    13321359        status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
     
    13411368
    13421369        /* try a write with an invalid tid */
    1343         cli->cnum = cnum3;
     1370        cli_state_set_tid(cli, cnum3);
    13441371
    13451372        status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
     
    13531380
    13541381        /* try a write with an invalid vuid */
    1355         cli->vuid = vuid2;
    1356         cli->cnum = cnum1;
     1382        cli_state_set_uid(cli, vuid2);
     1383        cli_state_set_tid(cli, cnum1);
    13571384
    13581385        status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL);
     
    13651392        }
    13661393
    1367         cli->cnum = cnum1;
    1368         cli->vuid = vuid1;
    1369 
    1370         if (!NT_STATUS_IS_OK(cli_close(cli, fnum1))) {
    1371                 printf("close failed (%s)\n", cli_errstr(cli));
    1372                 return False;
    1373         }
    1374 
    1375         cli->cnum = cnum2;
     1394        cli_state_set_tid(cli, cnum1);
     1395        cli_state_set_uid(cli, vuid1);
     1396
     1397        status = cli_close(cli, fnum1);
     1398        if (!NT_STATUS_IS_OK(status)) {
     1399                printf("close failed (%s)\n", nt_errstr(status));
     1400                return False;
     1401        }
     1402
     1403        cli_state_set_tid(cli, cnum2);
    13761404
    13771405        status = cli_tdis(cli);
     
    13811409        }
    13821410
    1383         cli->cnum = cnum1;
     1411        cli_state_set_tid(cli, cnum1);
    13841412
    13851413        if (!torture_close_connection(cli)) {
     
    13971425{
    13981426        static struct cli_state *cli;
    1399         uint16 cnum, max_xmit;
     1427        uint16_t cnum, max_xmit;
    14001428        char *service;
    14011429        NTSTATUS status;
     
    14041432                return False;
    14051433        }
    1406         cli_sockopt(cli, sockops);
     1434        smbXcli_conn_set_sockopt(cli->conn, sockops);
    14071435
    14081436        printf("starting tcon2 test\n");
     
    14391467        bool ret;
    14401468
    1441         status = cli_tcon_andx(cli, myshare, devtype,
    1442                                password, strlen(password)+1);
     1469        status = cli_tree_connect(cli, myshare, devtype,
     1470                                  password, strlen(password)+1);
    14431471
    14441472        if (NT_STATUS_IS_OK(expected_error)) {
     
    14671495                        ret = False;
    14681496                } else {
    1469                         if (NT_STATUS_EQUAL(cli_nt_error(cli),
    1470                                             expected_error)) {
     1497                        if (NT_STATUS_EQUAL(status, expected_error)) {
    14711498                                ret = True;
    14721499                        } else {
     
    15561583        uint16_t fnum1, fnum2, fnum3;
    15571584        bool correct = True;
     1585        NTSTATUS status;
    15581586
    15591587        if (!torture_open_connection(&cli, 0)) {
     
    15611589        }
    15621590
    1563         cli_sockopt(cli, sockops);
     1591        smbXcli_conn_set_sockopt(cli->conn, sockops);
    15641592
    15651593        printf("starting locktest2\n");
     
    15691597        cli_setpid(cli, 1);
    15701598
    1571         if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
    1572                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
    1573                 return False;
    1574         }
    1575 
    1576         if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum2))) {
    1577                 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
     1599        status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
     1600        if (!NT_STATUS_IS_OK(status)) {
     1601                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
     1602                return False;
     1603        }
     1604
     1605        status = cli_openx(cli, fname, O_RDWR, DENY_NONE, &fnum2);
     1606        if (!NT_STATUS_IS_OK(status)) {
     1607                printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
    15781608                return False;
    15791609        }
     
    15811611        cli_setpid(cli, 2);
    15821612
    1583         if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum3))) {
    1584                 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
     1613        status = cli_openx(cli, fname, O_RDWR, DENY_NONE, &fnum3);
     1614        if (!NT_STATUS_IS_OK(status)) {
     1615                printf("open3 of %s failed (%s)\n", fname, nt_errstr(status));
    15851616                return False;
    15861617        }
     
    15881619        cli_setpid(cli, 1);
    15891620
    1590         if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
    1591                 printf("lock1 failed (%s)\n", cli_errstr(cli));
    1592                 return False;
    1593         }
    1594 
    1595         if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
     1621        status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK);
     1622        if (!NT_STATUS_IS_OK(status)) {
     1623                printf("lock1 failed (%s)\n", nt_errstr(status));
     1624                return false;
     1625        }
     1626
     1627        status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK);
     1628        if (NT_STATUS_IS_OK(status)) {
    15961629                printf("WRITE lock1 succeeded! This is a locking bug\n");
    1597                 correct = False;
     1630                correct = false;
    15981631        } else {
    1599                 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
    1600                                  NT_STATUS_LOCK_NOT_GRANTED)) return False;
    1601         }
    1602 
    1603         if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
     1632                if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
     1633                                      NT_STATUS_LOCK_NOT_GRANTED)) {
     1634                        return false;
     1635                }
     1636        }
     1637
     1638        status = cli_lock32(cli, fnum2, 0, 4, 0, WRITE_LOCK);
     1639        if (NT_STATUS_IS_OK(status)) {
    16041640                printf("WRITE lock2 succeeded! This is a locking bug\n");
    1605                 correct = False;
     1641                correct = false;
    16061642        } else {
    1607                 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
    1608                                  NT_STATUS_LOCK_NOT_GRANTED)) return False;
    1609         }
    1610 
    1611         if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
     1643                if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
     1644                                      NT_STATUS_LOCK_NOT_GRANTED)) {
     1645                        return false;
     1646                }
     1647        }
     1648
     1649        status = cli_lock32(cli, fnum2, 0, 4, 0, READ_LOCK);
     1650        if (NT_STATUS_IS_OK(status)) {
    16121651                printf("READ lock2 succeeded! This is a locking bug\n");
    1613                 correct = False;
     1652                correct = false;
    16141653        } else {
    1615                 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
    1616                                  NT_STATUS_FILE_LOCK_CONFLICT)) return False;
    1617         }
    1618 
    1619         if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
    1620                 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
     1654                if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
     1655                                 NT_STATUS_FILE_LOCK_CONFLICT)) {
     1656                        return false;
     1657                }
     1658        }
     1659
     1660        status = cli_lock32(cli, fnum1, 100, 4, 0, WRITE_LOCK);
     1661        if (!NT_STATUS_IS_OK(status)) {
     1662                printf("lock at 100 failed (%s)\n", nt_errstr(status));
    16211663        }
    16221664        cli_setpid(cli, 2);
     
    16261668        }
    16271669
    1628         if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 0, 4))) {
     1670        status = cli_unlock(cli, fnum1, 0, 4);
     1671        if (NT_STATUS_IS_OK(status)) {
    16291672                printf("unlock1 succeeded! This is a locking bug\n");
    1630                 correct = False;
     1673                correct = false;
    16311674        } else {
    1632                 if (!check_error(__LINE__, cli,
    1633                                  ERRDOS, ERRlock,
    1634                                  NT_STATUS_RANGE_NOT_LOCKED)) return False;
    1635         }
    1636 
    1637         if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 0, 8))) {
     1675                if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
     1676                                      NT_STATUS_RANGE_NOT_LOCKED)) {
     1677                        return false;
     1678                }
     1679        }
     1680
     1681        status = cli_unlock(cli, fnum1, 0, 8);
     1682        if (NT_STATUS_IS_OK(status)) {
    16381683                printf("unlock2 succeeded! This is a locking bug\n");
    1639                 correct = False;
     1684                correct = false;
    16401685        } else {
    1641                 if (!check_error(__LINE__, cli,
    1642                                  ERRDOS, ERRlock,
    1643                                  NT_STATUS_RANGE_NOT_LOCKED)) return False;
    1644         }
    1645 
    1646         if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
     1686                if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
     1687                                      NT_STATUS_RANGE_NOT_LOCKED)) {
     1688                        return false;
     1689                }
     1690        }
     1691
     1692        status = cli_lock32(cli, fnum3, 0, 4, 0, WRITE_LOCK);
     1693        if (NT_STATUS_IS_OK(status)) {
    16471694                printf("lock3 succeeded! This is a locking bug\n");
    1648                 correct = False;
     1695                correct = false;
    16491696        } else {
    1650                 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
     1697                if (!check_both_error(__LINE__, status, ERRDOS, ERRlock,
     1698                                      NT_STATUS_LOCK_NOT_GRANTED)) {
     1699                        return false;
     1700                }
    16511701        }
    16521702
    16531703        cli_setpid(cli, 1);
    16541704
    1655         if (!NT_STATUS_IS_OK(cli_close(cli, fnum1))) {
    1656                 printf("close1 failed (%s)\n", cli_errstr(cli));
    1657                 return False;
    1658         }
    1659 
    1660         if (!NT_STATUS_IS_OK(cli_close(cli, fnum2))) {
    1661                 printf("close2 failed (%s)\n", cli_errstr(cli));
    1662                 return False;
    1663         }
    1664 
    1665         if (!NT_STATUS_IS_OK(cli_close(cli, fnum3))) {
    1666                 printf("close3 failed (%s)\n", cli_errstr(cli));
     1705        status = cli_close(cli, fnum1);
     1706        if (!NT_STATUS_IS_OK(status)) {
     1707                printf("close1 failed (%s)\n", nt_errstr(status));
     1708                return False;
     1709        }
     1710
     1711        status = cli_close(cli, fnum2);
     1712        if (!NT_STATUS_IS_OK(status)) {
     1713                printf("close2 failed (%s)\n", nt_errstr(status));
     1714                return False;
     1715        }
     1716
     1717        status = cli_close(cli, fnum3);
     1718        if (!NT_STATUS_IS_OK(status)) {
     1719                printf("close3 failed (%s)\n", nt_errstr(status));
    16671720                return False;
    16681721        }
     
    16891742        uint16_t fnum1, fnum2;
    16901743        int i;
    1691         uint32 offset;
     1744        uint32_t offset;
    16921745        bool correct = True;
    1693 
    1694 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
     1746        NTSTATUS status;
     1747
     1748#define NEXT_OFFSET offset += (~(uint32_t)0) / torture_numops
    16951749
    16961750        if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
    16971751                return False;
    16981752        }
    1699         cli_sockopt(cli1, sockops);
    1700         cli_sockopt(cli2, sockops);
     1753        smbXcli_conn_set_sockopt(cli1->conn, sockops);
     1754        smbXcli_conn_set_sockopt(cli2->conn, sockops);
    17011755
    17021756        printf("starting locktest3\n");
     
    17041758        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    17051759
    1706         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
    1707                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
    1708                 return False;
    1709         }
    1710         if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2))) {
    1711                 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
     1760        status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
     1761                         &fnum1);
     1762        if (!NT_STATUS_IS_OK(status)) {
     1763                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
     1764                return False;
     1765        }
     1766
     1767        status = cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
     1768        if (!NT_STATUS_IS_OK(status)) {
     1769                printf("open2 of %s failed (%s)\n", fname, nt_errstr(status));
    17121770                return False;
    17131771        }
     
    17151773        for (offset=i=0;i<torture_numops;i++) {
    17161774                NEXT_OFFSET;
    1717                 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
     1775
     1776                status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK);
     1777                if (!NT_STATUS_IS_OK(status)) {
    17181778                        printf("lock1 %d failed (%s)\n",
    17191779                               i,
    1720                                cli_errstr(cli1));
     1780                               nt_errstr(status));
    17211781                        return False;
    17221782                }
    17231783
    1724                 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
     1784                status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK);
     1785                if (!NT_STATUS_IS_OK(status)) {
    17251786                        printf("lock2 %d failed (%s)\n",
    17261787                               i,
    1727                                cli_errstr(cli1));
     1788                               nt_errstr(status));
    17281789                        return False;
    17291790                }
     
    17331794                NEXT_OFFSET;
    17341795
    1735                 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
     1796                status = cli_lock32(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK);
     1797                if (NT_STATUS_IS_OK(status)) {
    17361798                        printf("error: lock1 %d succeeded!\n", i);
    17371799                        return False;
    17381800                }
    17391801
    1740                 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
     1802                status = cli_lock32(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK);
     1803                if (NT_STATUS_IS_OK(status)) {
    17411804                        printf("error: lock2 %d succeeded!\n", i);
    17421805                        return False;
    17431806                }
    17441807
    1745                 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
     1808                status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK);
     1809                if (NT_STATUS_IS_OK(status)) {
    17461810                        printf("error: lock3 %d succeeded!\n", i);
    17471811                        return False;
    17481812                }
    17491813
    1750                 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
     1814                status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK);
     1815                if (NT_STATUS_IS_OK(status)) {
    17511816                        printf("error: lock4 %d succeeded!\n", i);
    17521817                        return False;
     
    17571822                NEXT_OFFSET;
    17581823
    1759                 if (!NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, offset-1, 1))) {
     1824                status = cli_unlock(cli1, fnum1, offset-1, 1);
     1825                if (!NT_STATUS_IS_OK(status)) {
    17601826                        printf("unlock1 %d failed (%s)\n",
    17611827                               i,
    1762                                cli_errstr(cli1));
     1828                               nt_errstr(status));
    17631829                        return False;
    17641830                }
    17651831
    1766                 if (!NT_STATUS_IS_OK(cli_unlock(cli2, fnum2, offset-2, 1))) {
     1832                status = cli_unlock(cli2, fnum2, offset-2, 1);
     1833                if (!NT_STATUS_IS_OK(status)) {
    17671834                        printf("unlock2 %d failed (%s)\n",
    17681835                               i,
    1769                                cli_errstr(cli1));
     1836                               nt_errstr(status));
    17701837                        return False;
    17711838                }
    17721839        }
    17731840
    1774         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    1775                 printf("close1 failed (%s)\n", cli_errstr(cli1));
    1776                 return False;
    1777         }
    1778 
    1779         if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
    1780                 printf("close2 failed (%s)\n", cli_errstr(cli2));
    1781                 return False;
    1782         }
    1783 
    1784         if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
    1785                 printf("unlink failed (%s)\n", cli_errstr(cli1));
     1841        status = cli_close(cli1, fnum1);
     1842        if (!NT_STATUS_IS_OK(status)) {
     1843                printf("close1 failed (%s)\n", nt_errstr(status));
     1844                return False;
     1845        }
     1846
     1847        status = cli_close(cli2, fnum2);
     1848        if (!NT_STATUS_IS_OK(status)) {
     1849                printf("close2 failed (%s)\n", nt_errstr(status));
     1850                return False;
     1851        }
     1852
     1853        status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     1854        if (!NT_STATUS_IS_OK(status)) {
     1855                printf("unlink failed (%s)\n", nt_errstr(status));
    17861856                return False;
    17871857        }
     
    17981868
    17991869        return correct;
     1870}
     1871
     1872static bool test_cli_read(struct cli_state *cli, uint16_t fnum,
     1873                           char *buf, off_t offset, size_t size,
     1874                           size_t *nread, size_t expect)
     1875{
     1876        NTSTATUS status;
     1877        size_t l_nread;
     1878
     1879        status = cli_read(cli, fnum, buf, offset, size, &l_nread);
     1880
     1881        if(!NT_STATUS_IS_OK(status)) {
     1882                return false;
     1883        } else if (l_nread != expect) {
     1884                return false;
     1885        }
     1886
     1887        if (nread) {
     1888                *nread = l_nread;
     1889        }
     1890
     1891        return true;
    18001892}
    18011893
     
    18211913        }
    18221914
    1823         cli_sockopt(cli1, sockops);
    1824         cli_sockopt(cli2, sockops);
     1915        smbXcli_conn_set_sockopt(cli1->conn, sockops);
     1916        smbXcli_conn_set_sockopt(cli2->conn, sockops);
    18251917
    18261918        printf("starting locktest4\n");
     
    18281920        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    18291921
    1830         cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
    1831         cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
     1922        cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
     1923        cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
    18321924
    18331925        memset(buf, 0, sizeof(buf));
     
    18411933        }
    18421934
    1843         ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
    1844               cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
     1935        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) &&
     1936              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 2, 4, 0, WRITE_LOCK));
    18451937        EXPECTED(ret, False);
    18461938        printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
    18471939
    1848         ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
    1849               cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
     1940        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 10, 4, 0, READ_LOCK)) &&
     1941              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 12, 4, 0, READ_LOCK));
    18501942        EXPECTED(ret, True);
    18511943        printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
    18521944
    1853         ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
    1854               cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
     1945        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 20, 4, 0, WRITE_LOCK)) &&
     1946              NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 22, 4, 0, WRITE_LOCK));
    18551947        EXPECTED(ret, False);
    18561948        printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
    18571949
    1858         ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
    1859               cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
     1950        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 30, 4, 0, READ_LOCK)) &&
     1951              NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 32, 4, 0, READ_LOCK));
    18601952        EXPECTED(ret, True);
    18611953        printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
    18621954
    1863         ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
    1864               (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
     1955        ret = (cli_setpid(cli1, 1),
     1956              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 40, 4, 0, WRITE_LOCK))) &&
     1957              (cli_setpid(cli1, 2),
     1958              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 42, 4, 0, WRITE_LOCK)));
    18651959        EXPECTED(ret, False);
    18661960        printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
    18671961
    1868         ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
    1869               (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
     1962        ret = (cli_setpid(cli1, 1),
     1963              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 50, 4, 0, READ_LOCK))) &&
     1964              (cli_setpid(cli1, 2),
     1965              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 52, 4, 0, READ_LOCK)));
    18701966        EXPECTED(ret, True);
    18711967        printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
    18721968
    1873         ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
    1874               cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
     1969        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK)) &&
     1970              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK));
    18751971        EXPECTED(ret, True);
    18761972        printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
    18771973
    1878         ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
    1879               cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
     1974        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK)) &&
     1975              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK));
    18801976        EXPECTED(ret, False);
    18811977        printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
    18821978
    1883         ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
    1884               cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
     1979        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, READ_LOCK)) &&
     1980              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, WRITE_LOCK));
    18851981        EXPECTED(ret, False);
    18861982        printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
    18871983
    1888         ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
    1889               cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
     1984        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, WRITE_LOCK)) &&
     1985              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, READ_LOCK));
    18901986        EXPECTED(ret, True);
    18911987        printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
    18921988
    1893         ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
    1894               (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
     1989        ret = (cli_setpid(cli1, 1),
     1990             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, WRITE_LOCK))) &&
     1991             (cli_setpid(cli1, 2),
     1992             NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, READ_LOCK)));
    18951993        EXPECTED(ret, False);
    18961994        printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
    18971995
    1898         ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
    1899               cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
     1996        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 110, 4, 0, READ_LOCK)) &&
     1997              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 112, 4, 0, READ_LOCK)) &&
    19001998              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 110, 6));
    19011999        EXPECTED(ret, False);
     
    19032001
    19042002
    1905         ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
    1906               (cli_read(cli2, fnum2, buf, 120, 4) == 4);
     2003        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 120, 4, 0, WRITE_LOCK)) &&
     2004              test_cli_read(cli2, fnum2, buf, 120, 4, NULL, 4);
    19072005        EXPECTED(ret, False);
    19082006        printf("this server %s strict write locking\n", ret?"doesn't do":"does");
    19092007
    1910         ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK);
     2008        status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
     2009        ret = NT_STATUS_IS_OK(status);
    19112010        if (ret) {
    19122011                status = cli_writeall(cli2, fnum2, 0, (uint8_t *)buf, 130, 4,
     
    19182017
    19192018
    1920         ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
    1921               cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
     2019        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) &&
     2020              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) &&
    19222021              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4)) &&
    19232022              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4));
     
    19262025
    19272026
    1928         ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
    1929               cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
     2027        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, WRITE_LOCK)) &&
     2028              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, READ_LOCK)) &&
    19302029              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4)) &&
    1931               (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
     2030              test_cli_read(cli2, fnum2, buf, 150, 4, NULL, 4) &&
    19322031              !(NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
    19332032                                             150, 4, NULL))) &&
     
    19362035        printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
    19372036
    1938         ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
     2037        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 160, 4, 0, READ_LOCK)) &&
    19392038              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 160, 4)) &&
    19402039              NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
    19412040                                           160, 4, NULL)) &&
    1942               (cli_read(cli2, fnum2, buf, 160, 4) == 4);               
     2041              test_cli_read(cli2, fnum2, buf, 160, 4, NULL, 4);
    19432042        EXPECTED(ret, True);
    19442043        printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
    19452044
    1946         ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
     2045        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 170, 4, 0, WRITE_LOCK)) &&
    19472046              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 170, 4)) &&
    19482047              NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
    19492048                                           170, 4, NULL)) &&
    1950               (cli_read(cli2, fnum2, buf, 170, 4) == 4);               
     2049              test_cli_read(cli2, fnum2, buf, 170, 4, NULL, 4);
    19512050        EXPECTED(ret, True);
    19522051        printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
    19532052
    1954         ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
    1955               cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
     2053        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, WRITE_LOCK)) &&
     2054              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, READ_LOCK)) &&
    19562055              NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 190, 4)) &&
    19572056              !NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf,
    19582057                                            190, 4, NULL)) &&
    1959               (cli_read(cli2, fnum2, buf, 190, 4) == 4);               
     2058              test_cli_read(cli2, fnum2, buf, 190, 4, NULL, 4);
    19602059        EXPECTED(ret, True);
    19612060        printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
     
    19632062        cli_close(cli1, fnum1);
    19642063        cli_close(cli2, fnum2);
    1965         cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
    1966         cli_open(cli1, fname, O_RDWR, DENY_NONE, &f);
    1967         ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
    1968               cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
     2064        cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
     2065        cli_openx(cli1, fname, O_RDWR, DENY_NONE, &f);
     2066        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) &&
     2067              NT_STATUS_IS_OK(cli_lock32(cli1, f, 0, 1, 0, READ_LOCK)) &&
    19692068              NT_STATUS_IS_OK(cli_close(cli1, fnum1)) &&
    1970               NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1)) &&
    1971               cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
     2069              NT_STATUS_IS_OK(cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1)) &&
     2070              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK));
    19722071        cli_close(cli1, f);
    19732072        cli_close(cli1, fnum1);
     
    20032102        }
    20042103
    2005         cli_sockopt(cli1, sockops);
    2006         cli_sockopt(cli2, sockops);
     2104        smbXcli_conn_set_sockopt(cli1->conn, sockops);
     2105        smbXcli_conn_set_sockopt(cli2->conn, sockops);
    20072106
    20082107        printf("starting locktest5\n");
     
    20102109        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    20112110
    2012         cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
    2013         cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
    2014         cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum3);
     2111        cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
     2112        cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
     2113        cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum3);
    20152114
    20162115        memset(buf, 0, sizeof(buf));
     
    20252124
    20262125        /* Check for NT bug... */
    2027         ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
    2028                   cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
     2126        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) &&
     2127              NT_STATUS_IS_OK(cli_lock32(cli1, fnum3, 0, 1, 0, READ_LOCK));
    20292128        cli_close(cli1, fnum1);
    2030         cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
    2031         ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
     2129        cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
     2130        status = cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
     2131        ret = NT_STATUS_IS_OK(status);
    20322132        EXPECTED(ret, True);
    20332133        printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
    20342134        cli_close(cli1, fnum1);
    2035         cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
     2135        cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
    20362136        cli_unlock(cli1, fnum3, 0, 1);
    20372137
    2038         ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
    2039               cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
     2138        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) &&
     2139              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 1, 1, 0, READ_LOCK));
    20402140        EXPECTED(ret, True);
    20412141        printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
    20422142
    2043         ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
     2143        status = cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK);
     2144        ret = NT_STATUS_IS_OK(status);
    20442145        EXPECTED(ret, False);
    20452146
     
    20492150        cli_unlock(cli2, fnum2, 0, 4);
    20502151
    2051         ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
     2152        status = cli_lock32(cli1, fnum3, 0, 4, 0, READ_LOCK);
     2153        ret = NT_STATUS_IS_OK(status);
    20522154        EXPECTED(ret, False);
    20532155
     
    20582160
    20592161        /* Stack 2 more locks here. */
    2060         ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
    2061                   cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
     2162        ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK)) &&
     2163              NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK));
    20622164
    20632165        EXPECTED(ret, True);
     
    20682170
    20692171        ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) &&
    2070                         cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
     2172              NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK));
    20712173
    20722174        EXPECTED(ret, True);
     
    20912193
    20922194        /* Ensure connection 2 can get a write lock. */
    2093         ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
     2195        status = cli_lock32(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
     2196        ret = NT_STATUS_IS_OK(status);
    20942197        EXPECTED(ret, True);
    20952198
     
    21282231        }
    21292232
    2130         cli_sockopt(cli, sockops);
     2233        smbXcli_conn_set_sockopt(cli->conn, sockops);
    21312234
    21322235        printf("starting locktest6\n");
     
    21372240                cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    21382241
    2139                 cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
     2242                cli_openx(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
    21402243                status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
    21412244                cli_close(cli, fnum);
    21422245                printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
    21432246
    2144                 cli_open(cli, fname[i], O_RDWR, DENY_NONE, &fnum);
     2247                cli_openx(cli, fname[i], O_RDWR, DENY_NONE, &fnum);
    21452248                status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
    21462249                cli_close(cli, fnum);
     
    21632266        char buf[200];
    21642267        bool correct = False;
     2268        size_t nread;
    21652269        NTSTATUS status;
    21662270
     
    21692273        }
    21702274
    2171         cli_sockopt(cli1, sockops);
     2275        smbXcli_conn_set_sockopt(cli1->conn, sockops);
    21722276
    21732277        printf("starting locktest7\n");
     
    21752279        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    21762280
    2177         cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
     2281        cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
    21782282
    21792283        memset(buf, 0, sizeof(buf));
     
    21882292        cli_setpid(cli1, 1);
    21892293
    2190         if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
    2191                 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
     2294        status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK);
     2295        if (!NT_STATUS_IS_OK(status)) {
     2296                printf("Unable to apply read lock on range 130:4, "
     2297                       "error was %s\n", nt_errstr(status));
    21922298                goto fail;
    21932299        } else {
     
    21952301        }
    21962302
    2197         if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
    2198                 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
     2303        status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
     2304        if (!NT_STATUS_IS_OK(status)) {
     2305                printf("pid1 unable to read the range 130:4, error was %s\n",
     2306                      nt_errstr(status));
     2307                goto fail;
     2308        } else if (nread != 4) {
     2309                printf("pid1 unable to read the range 130:4, "
     2310                       "recv %ld req %d\n", (unsigned long)nread, 4);
    21992311                goto fail;
    22002312        } else {
     
    22172329        cli_setpid(cli1, 2);
    22182330
    2219         if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
    2220                 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
     2331        status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
     2332        if (!NT_STATUS_IS_OK(status)) {
     2333                printf("pid2 unable to read the range 130:4, error was %s\n",
     2334                      nt_errstr(status));
     2335                goto fail;
     2336        } else if (nread != 4) {
     2337                printf("pid2 unable to read the range 130:4, "
     2338                       "recv %ld req %d\n", (unsigned long)nread, 4);
     2339                goto fail;
    22212340        } else {
    22222341                printf("pid2 successfully read the range 130:4\n");
     
    22392358        cli_unlock(cli1, fnum1, 130, 4);
    22402359
    2241         if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
    2242                 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
     2360        status = cli_lock32(cli1, fnum1, 130, 4, 0, WRITE_LOCK);
     2361        if (!NT_STATUS_IS_OK(status)) {
     2362                printf("Unable to apply write lock on range 130:4, error was %s\n", nt_errstr(status));
    22432363                goto fail;
    22442364        } else {
     
    22462366        }
    22472367
    2248         if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
    2249                 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
     2368        status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
     2369        if (!NT_STATUS_IS_OK(status)) {
     2370                printf("pid1 unable to read the range 130:4, error was %s\n",
     2371                      nt_errstr(status));
     2372                goto fail;
     2373        } else if (nread != 4) {
     2374                printf("pid1 unable to read the range 130:4, "
     2375                       "recv %ld req %d\n", (unsigned long)nread, 4);
    22502376                goto fail;
    22512377        } else {
     
    22642390        cli_setpid(cli1, 2);
    22652391
    2266         if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
    2267                 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
    2268                 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
     2392        status = cli_read(cli1, fnum1, buf, 130, 4, &nread);
     2393        if (!NT_STATUS_IS_OK(status)) {
     2394                printf("pid2 unable to read the range 130:4, error was "
     2395                       "%s\n", nt_errstr(status));
     2396                if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
    22692397                        printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
    22702398                        goto fail;
    22712399                }
    22722400        } else {
    2273                 printf("pid2 successfully read the range 130:4 (should be denied)\n");
     2401                printf("pid2 successfully read the range 130:4 (should be denied) recv %ld\n",
     2402                       (unsigned long)nread);
    22742403                goto fail;
    22752404        }
     
    23212450        }
    23222451
    2323         cli_sockopt(cli1, sockops);
     2452        smbXcli_conn_set_sockopt(cli1->conn, sockops);
    23242453
    23252454        printf("starting locktest8\n");
     
    23272456        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    23282457
    2329         status = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_WRITE,
     2458        status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_WRITE,
    23302459                          &fnum1);
    23312460        if (!NT_STATUS_IS_OK(status)) {
    2332                 d_fprintf(stderr, "cli_open returned %s\n", cli_errstr(cli1));
     2461                d_fprintf(stderr, "cli_openx returned %s\n", nt_errstr(status));
    23332462                return false;
    23342463        }
     
    23362465        memset(buf, 0, sizeof(buf));
    23372466
    2338         status = cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum2);
    2339         if (!NT_STATUS_IS_OK(status)) {
    2340                 d_fprintf(stderr, "cli_open second time returned %s\n",
    2341                           cli_errstr(cli1));
     2467        status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum2);
     2468        if (!NT_STATUS_IS_OK(status)) {
     2469                d_fprintf(stderr, "cli_openx second time returned %s\n",
     2470                          nt_errstr(status));
    23422471                goto fail;
    23432472        }
    23442473
    2345         if (!cli_lock(cli1, fnum2, 1, 1, 0, READ_LOCK)) {
     2474        status = cli_lock32(cli1, fnum2, 1, 1, 0, READ_LOCK);
     2475        if (!NT_STATUS_IS_OK(status)) {
    23462476                printf("Unable to apply read lock on range 1:1, error was "
    2347                        "%s\n", cli_errstr(cli1));
     2477                       "%s\n", nt_errstr(status));
    23482478                goto fail;
    23492479        }
     
    23512481        status = cli_close(cli1, fnum1);
    23522482        if (!NT_STATUS_IS_OK(status)) {
    2353                 d_fprintf(stderr, "cli_close(fnum1) %s\n", cli_errstr(cli1));
     2483                d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status));
    23542484                goto fail;
    23552485        }
    23562486
    2357         status = cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
    2358         if (!NT_STATUS_IS_OK(status)) {
    2359                 d_fprintf(stderr, "cli_open third time returned %s\n",
    2360                           cli_errstr(cli1));
     2487        status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
     2488        if (!NT_STATUS_IS_OK(status)) {
     2489                d_fprintf(stderr, "cli_openx third time returned %s\n",
     2490                          nt_errstr(status));
    23612491                goto fail;
    23622492        }
     
    23822512
    23832513static bool got_alarm;
    2384 static int alarm_fd;
     2514static struct cli_state *alarm_cli;
    23852515
    23862516static void alarm_handler(int dummy)
     
    23912521static void alarm_handler_parent(int dummy)
    23922522{
    2393         close(alarm_fd);
     2523        smbXcli_conn_disconnect(alarm_cli->conn, NT_STATUS_OK);
    23942524}
    23952525
     
    25152645        }
    25162646
    2517         cli_sockopt(cli1, sockops);
    2518 
    2519         status = cli_open(cli1, fname, O_RDWR, DENY_NONE,
     2647        smbXcli_conn_set_sockopt(cli1->conn, sockops);
     2648
     2649        status = cli_openx(cli1, fname, O_RDWR, DENY_NONE,
    25202650                          &fnum);
    25212651        if (!NT_STATUS_IS_OK(status)) {
    2522                 d_fprintf(stderr, "cli_open returned %s\n", cli_errstr(cli1));
     2652                d_fprintf(stderr, "cli_openx returned %s\n", nt_errstr(status));
    25232653                return false;
    25242654        }
    25252655
    25262656        /* Ensure the child has the lock. */
    2527         if (cli_lock(cli1, fnum, 0, 4, 0, WRITE_LOCK)) {
     2657        status = cli_lock32(cli1, fnum, 0, 4, 0, WRITE_LOCK);
     2658        if (NT_STATUS_IS_OK(status)) {
    25282659                d_fprintf(stderr, "Got the lock on range 0:4 - this should not happen !\n");
    25292660                goto fail;
     
    25412672
    25422673        /* Wait 20 seconds for the lock. */
    2543         alarm_fd = cli1->fd;
     2674        alarm_cli = cli1;
    25442675        CatchSignal(SIGALRM, alarm_handler_parent);
    25452676        alarm(20);
     
    25472678        start = timeval_current();
    25482679
    2549         if (!cli_lock(cli1, fnum, 0, 4, -1, WRITE_LOCK)) {
     2680        status = cli_lock32(cli1, fnum, 0, 4, -1, WRITE_LOCK);
     2681        if (!NT_STATUS_IS_OK(status)) {
    25502682                d_fprintf(stderr, "Unable to apply write lock on range 0:4, error was "
    2551                        "%s\n", cli_errstr(cli1));
     2683                       "%s\n", nt_errstr(status));
    25522684                goto fail_nofd;
    25532685        }
     
    25612693        status = cli_close(cli1, fnum);
    25622694        if (!NT_STATUS_IS_OK(status)) {
    2563                 d_fprintf(stderr, "cli_close(fnum1) %s\n", cli_errstr(cli1));
     2695                d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status));
    25642696                goto fail;
    25652697        }
     
    25922724                return False;
    25932725        }
    2594         cli_sockopt(cli1, sockops);
    2595         cli_sockopt(cli2, sockops);
     2726        smbXcli_conn_set_sockopt(cli1->conn, sockops);
     2727        smbXcli_conn_set_sockopt(cli2->conn, sockops);
    25962728
    25972729        printf("starting fdpasstest\n");
     
    25992731        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    26002732
    2601         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
    2602                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
    2603                 return False;
    2604         }
    2605 
    2606         status = cli_writeall(cli1, fnum1, 0, (uint8_t *)"hello world\n", 0,
     2733        status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
     2734                          &fnum1);
     2735        if (!NT_STATUS_IS_OK(status)) {
     2736                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
     2737                return False;
     2738        }
     2739
     2740        status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"hello world\n", 0,
    26072741                              13, NULL);
    26082742        if (!NT_STATUS_IS_OK(status)) {
     
    26112745        }
    26122746
    2613         cli2->vuid = cli1->vuid;
    2614         cli2->cnum = cli1->cnum;
    2615         cli2->pid = cli1->pid;
    2616 
    2617         if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
    2618                 printf("read succeeded! nasty security hole [%s]\n",
    2619                        buf);
    2620                 return False;
     2747        cli_state_set_uid(cli2, cli_state_get_uid(cli1));
     2748        cli_state_set_tid(cli2, cli_state_get_tid(cli1));
     2749        cli_setpid(cli2, cli_getpid(cli1));
     2750
     2751        if (test_cli_read(cli2, fnum1, buf, 0, 13, NULL, 13)) {
     2752                printf("read succeeded! nasty security hole [%s]\n", buf);
     2753                return false;
    26212754        }
    26222755
     
    26342767{
    26352768        struct cli_state *cli;
    2636         uint16 new_vuid;
    2637         uint16 saved_vuid;
    2638         uint16 new_cnum;
    2639         uint16 saved_cnum;
     2769        uint16_t new_vuid;
     2770        uint16_t saved_vuid;
     2771        uint16_t new_cnum;
     2772        uint16_t saved_cnum;
    26402773        const char *fname = "\\fdsess.tst";
    26412774        const char *fname1 = "\\fdsess1.tst";
     
    26482781        if (!torture_open_connection(&cli, 0))
    26492782                return False;
    2650         cli_sockopt(cli, sockops);
     2783        smbXcli_conn_set_sockopt(cli->conn, sockops);
    26512784
    26522785        if (!torture_cli_session_setup2(cli, &new_vuid))
    26532786                return False;
    26542787
    2655         saved_cnum = cli->cnum;
    2656         if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, share, "?????", "", 1)))
    2657                 return False;
    2658         new_cnum = cli->cnum;
    2659         cli->cnum = saved_cnum;
     2788        saved_cnum = cli_state_get_tid(cli);
     2789        if (!NT_STATUS_IS_OK(cli_tree_connect(cli, share, "?????", "", 1)))
     2790                return False;
     2791        new_cnum = cli_state_get_tid(cli);
     2792        cli_state_set_tid(cli, saved_cnum);
    26602793
    26612794        printf("starting fdsesstest\n");
     
    26642797        cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    26652798
    2666         if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
    2667                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
    2668                 return False;
    2669         }
    2670 
    2671         status = cli_writeall(cli, fnum1, 0, (uint8_t *)"hello world\n", 0, 13,
     2799        status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
     2800        if (!NT_STATUS_IS_OK(status)) {
     2801                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
     2802                return False;
     2803        }
     2804
     2805        status = cli_writeall(cli, fnum1, 0, (const uint8_t *)"hello world\n", 0, 13,
    26722806                              NULL);
    26732807        if (!NT_STATUS_IS_OK(status)) {
     
    26762810        }
    26772811
    2678         saved_vuid = cli->vuid;
    2679         cli->vuid = new_vuid;
    2680 
    2681         if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
    2682                 printf("read succeeded with different vuid! nasty security hole [%s]\n",
    2683                        buf);
    2684                 ret = False;
     2812        saved_vuid = cli_state_get_uid(cli);
     2813        cli_state_set_uid(cli, new_vuid);
     2814
     2815        if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
     2816                printf("read succeeded with different vuid! "
     2817                       "nasty security hole [%s]\n", buf);
     2818                ret = false;
    26852819        }
    26862820        /* Try to open a file with different vuid, samba cnum. */
    2687         if (NT_STATUS_IS_OK(cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {
     2821        if (NT_STATUS_IS_OK(cli_openx(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {
    26882822                printf("create with different vuid, same cnum succeeded.\n");
    26892823                cli_close(cli, fnum2);
     
    26952829        }
    26962830
    2697         cli->vuid = saved_vuid;
     2831        cli_state_set_uid(cli, saved_vuid);
    26982832
    26992833        /* Try with same vuid, different cnum. */
    2700         cli->cnum = new_cnum;
    2701 
    2702         if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
    2703                 printf("read succeeded with different cnum![%s]\n",
    2704                        buf);
    2705                 ret = False;
    2706         }
    2707 
    2708         cli->cnum = saved_cnum;
     2834        cli_state_set_tid(cli, new_cnum);
     2835
     2836        if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) {
     2837                printf("read succeeded with different cnum![%s]\n", buf);
     2838                ret = false;
     2839        }
     2840
     2841        cli_state_set_tid(cli, saved_cnum);
    27092842        cli_close(cli, fnum1);
    27102843        cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     
    27272860        uint16_t fnum;
    27282861        bool correct = True;
     2862        NTSTATUS status;
    27292863
    27302864        if (!torture_open_connection(&cli, 0)) {
     
    27322866        }
    27332867
    2734         cli_sockopt(cli, sockops);
     2868        smbXcli_conn_set_sockopt(cli->conn, sockops);
    27352869
    27362870        printf("starting unlink test\n");
     
    27402874        cli_setpid(cli, 1);
    27412875
    2742         if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
    2743                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
    2744                 return False;
    2745         }
    2746 
    2747         if (NT_STATUS_IS_OK(cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
     2876        status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
     2877        if (!NT_STATUS_IS_OK(status)) {
     2878                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
     2879                return False;
     2880        }
     2881
     2882        status = cli_unlink(cli, fname,
     2883                            FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     2884        if (NT_STATUS_IS_OK(status)) {
    27482885                printf("error: server allowed unlink on an open file\n");
    27492886                correct = False;
    27502887        } else {
    2751                 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
     2888                correct = check_error(__LINE__, status, ERRDOS, ERRbadshare,
    27522889                                      NT_STATUS_SHARING_VIOLATION);
    27532890        }
     
    27722909{
    27732910        struct cli_state *cli;
    2774         const char *ftemplate = "\\maxfid.%d.%d";
    27752911        fstring fname;
    27762912        uint16_t fnums[0x11000];
     
    27782914        int retries=4;
    27792915        bool correct = True;
     2916        NTSTATUS status;
    27802917
    27812918        cli = current_cli;
     
    27862923        }
    27872924
    2788         cli_sockopt(cli, sockops);
     2925        smbXcli_conn_set_sockopt(cli->conn, sockops);
    27892926
    27902927        for (i=0; i<0x11000; i++) {
    2791                 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
    2792                 if (!NT_STATUS_IS_OK(cli_open(cli, fname,
    2793                                         O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnums[i]))) {
     2928                slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid());
     2929                status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE,
     2930                                  &fnums[i]);
     2931                if (!NT_STATUS_IS_OK(status)) {
    27942932                        printf("open of %s failed (%s)\n",
    2795                                fname, cli_errstr(cli));
     2933                               fname, nt_errstr(status));
    27962934                        printf("maximum fnum is %d\n", i);
    27972935                        break;
     
    28042942        printf("cleaning up\n");
    28052943        for (;i>=0;i--) {
    2806                 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
     2944                slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid());
    28072945                cli_close(cli, fnums[i]);
    2808                 if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
     2946
     2947                status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     2948                if (!NT_STATUS_IS_OK(status)) {
    28092949                        printf("unlink of %s failed (%s)\n",
    2810                                fname, cli_errstr(cli));
     2950                               fname, nt_errstr(status));
    28112951                        correct = False;
    28122952                }
     
    28412981        printf("starting negprot nowait test\n");
    28422982
    2843         ev = tevent_context_init(talloc_tos());
     2983        ev = samba_tevent_context_init(talloc_tos());
    28442984        if (ev == NULL) {
    28452985                return false;
     
    28542994                struct tevent_req *req;
    28552995
    2856                 req = cli_negprot_send(ev, ev, cli);
     2996                req = smbXcli_negprot_send(ev, ev, cli->conn, cli->timeout,
     2997                                           PROTOCOL_CORE, PROTOCOL_NT1);
    28572998                if (req == NULL) {
    28582999                        TALLOC_FREE(ev);
     
    28803021static bool run_bad_nbt_session(int dummy)
    28813022{
    2882         static struct cli_state *cli;
     3023        struct nmb_name called, calling;
     3024        struct sockaddr_storage ss;
     3025        NTSTATUS status;
     3026        int fd;
     3027        bool ret;
    28833028
    28843029        printf("starting bad nbt session test\n");
    28853030
    2886         if (!(cli = open_bad_nbt_connection())) {
    2887                 return False;
    2888         }
    2889 
    2890         cli_shutdown(cli);
     3031        make_nmb_name(&calling, myname, 0x0);
     3032        make_nmb_name(&called , host, 0x20);
     3033
     3034        if (!resolve_name(host, &ss, 0x20, true)) {
     3035                d_fprintf(stderr, "Could not resolve name %s\n", host);
     3036                return false;
     3037        }
     3038
     3039        status = open_socket_out(&ss, NBT_SMB_PORT, 10000, &fd);
     3040        if (!NT_STATUS_IS_OK(status)) {
     3041                d_fprintf(stderr, "open_socket_out failed: %s\n",
     3042                          nt_errstr(status));
     3043                return false;
     3044        }
     3045
     3046        ret = cli_bad_session_request(fd, &calling, &called);
     3047        close(fd);
     3048        if (!ret) {
     3049                d_fprintf(stderr, "open_socket_out failed: %s\n",
     3050                          nt_errstr(status));
     3051                return false;
     3052        }
     3053
    28913054        printf("finished bad nbt session test\n");
    28923055        return true;
     
    29213084                cli_api(cli,
    29223085                        param, param_len, 8, 
    2923                         NULL, 0, BUFFER_SIZE,
     3086                        NULL, 0, CLI_BUFFER_SIZE,
    29243087                        &rparam, &rprcnt,     
    29253088                        &rdata, &rdrcnt);
     
    29343097        }
    29353098
     3099        SAFE_FREE(rparam);
     3100        SAFE_FREE(rdata);
     3101
    29363102        printf("finished random ipc test\n");
    29373103
     
    29413107
    29423108
    2943 static void browse_callback(const char *sname, uint32 stype,
     3109static void browse_callback(const char *sname, uint32_t stype,
    29443110                            const char *comment, void *state)
    29453111{
     
    29953161        const char *fname = "\\attrib123456789.tst";
    29963162        bool correct = True;
     3163        NTSTATUS status;
    29973164
    29983165        printf("starting attrib test\n");
     
    30033170
    30043171        cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    3005         cli_open(cli, fname,
     3172        cli_openx(cli, fname,
    30063173                        O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
    30073174        cli_close(cli, fnum);
    3008         if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) {
    3009                 printf("getatr failed (%s)\n", cli_errstr(cli));
     3175
     3176        status = cli_getatr(cli, fname, NULL, NULL, &t);
     3177        if (!NT_STATUS_IS_OK(status)) {
     3178                printf("getatr failed (%s)\n", nt_errstr(status));
    30103179                correct = False;
    30113180        }
     
    30203189        t2 = t-60*60*24; /* 1 day ago */
    30213190
    3022         if (!NT_STATUS_IS_OK(cli_setatr(cli, fname, 0, t2))) {
    3023                 printf("setatr failed (%s)\n", cli_errstr(cli));
     3191        status = cli_setatr(cli, fname, 0, t2);
     3192        if (!NT_STATUS_IS_OK(status)) {
     3193                printf("setatr failed (%s)\n", nt_errstr(status));
    30243194                correct = True;
    30253195        }
    30263196
    3027         if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) {
    3028                 printf("getatr failed (%s)\n", cli_errstr(cli));
     3197        status = cli_getatr(cli, fname, NULL, NULL, &t);
     3198        if (!NT_STATUS_IS_OK(status)) {
     3199                printf("getatr failed (%s)\n", nt_errstr(status));
    30293200                correct = True;
    30303201        }
     
    30563227        struct cli_state *cli;
    30573228        uint16_t fnum;
    3058         SMB_OFF_T size;
     3229        off_t size;
    30593230        time_t c_time, a_time, m_time;
    30603231        struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
     
    30623233        const char *dname = "\\trans2";
    30633234        const char *fname2 = "\\trans2\\trans2.tst";
    3064         char pname[1024];
     3235        char *pname;
    30653236        bool correct = True;
    30663237        NTSTATUS status;
     
    30813252
    30823253        cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    3083         cli_open(cli, fname,
    3084                         O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
    3085         if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
    3086                                      cli, fnum, NULL, &size, &c_time_ts,
    3087                                      &a_time_ts, &w_time_ts,
    3088                                      &m_time_ts, NULL))) {
    3089                 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
     3254        cli_openx(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
     3255        status = cli_qfileinfo_basic(cli, fnum, NULL, &size, &c_time_ts,
     3256                                     &a_time_ts, &w_time_ts, &m_time_ts, NULL);
     3257        if (!NT_STATUS_IS_OK(status)) {
     3258                printf("ERROR: qfileinfo failed (%s)\n", nt_errstr(status));
    30903259                correct = False;
    30913260        }
    30923261
    3093         if (!NT_STATUS_IS_OK(cli_qfilename(cli, fnum, pname, sizeof(pname)))) {
    3094                 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
     3262        status = cli_qfilename(cli, fnum, talloc_tos(), &pname);
     3263        if (!NT_STATUS_IS_OK(status)) {
     3264                printf("ERROR: qfilename failed (%s)\n", nt_errstr(status));
    30953265                correct = False;
    30963266        }
    3097 
    3098         if (strcmp(pname, fname)) {
     3267        else if (strcmp(pname, fname)) {
    30993268                printf("qfilename gave different name? [%s] [%s]\n",
    31003269                       fname, pname);
     
    31073276
    31083277        cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    3109         if (!NT_STATUS_IS_OK(cli_open(cli, fname,
    3110                         O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum))) {
    3111                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
     3278        status = cli_openx(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE,
     3279                          &fnum);
     3280        if (!NT_STATUS_IS_OK(status)) {
     3281                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
    31123282                return False;
    31133283        }
     
    31203290                correct = False;
    31213291        } else {
     3292                time_t t = time(NULL);
     3293
    31223294                if (c_time != m_time) {
    31233295                        printf("create time=%s", ctime(&c_time));
     
    31253297                        printf("This system appears to have sticky create times\n");
    31263298                }
    3127                 if (a_time % (60*60) == 0) {
     3299                if ((abs(a_time - t) > 60) && (a_time % (60*60) == 0)) {
    31283300                        printf("access time=%s", ctime(&a_time));
    31293301                        printf("This system appears to set a midnight access time\n");
     
    31313303                }
    31323304
    3133                 if (abs(m_time - time(NULL)) > 60*60*24*7) {
     3305                if (abs(m_time - t) > 60*60*24*7) {
    31343306                        printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
    31353307                        correct = False;
     
    31393311
    31403312        cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    3141         cli_open(cli, fname,
     3313        cli_openx(cli, fname,
    31423314                        O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
    31433315        cli_close(cli, fnum);
     
    31603332        /* check if the server updates the directory modification time
    31613333           when creating a new file */
    3162         if (!NT_STATUS_IS_OK(cli_mkdir(cli, dname))) {
    3163                 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
     3334        status = cli_mkdir(cli, dname);
     3335        if (!NT_STATUS_IS_OK(status)) {
     3336                printf("ERROR: mkdir failed (%s)\n", nt_errstr(status));
    31643337                correct = False;
    31653338        }
     
    31723345        }
    31733346
    3174         cli_open(cli, fname2,
     3347        cli_openx(cli, fname2,
    31753348                        O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
    31763349        cli_writeall(cli, fnum,  0, (uint8_t *)&fnum, 0, sizeof(fnum), NULL);
     
    32073380{
    32083381        uint8_t *buf = NULL;
    3209         uint32 len;
     3382        uint32_t len;
    32103383        NTSTATUS status;
    32113384
    32123385        status = cli_qfileinfo(talloc_tos(), pcli, fnum, level, 0,
    3213                                pcli->max_xmit, &buf, &len);
     3386                               CLI_BUFFER_SIZE, NULL, &buf, &len);
    32143387        if (!NT_STATUS_IS_OK(status)) {
    32153388                printf("ERROR: qfileinfo (%d) failed (%s)\n", level,
     
    32173390        } else {
    32183391                printf("qfileinfo: level %d, len = %u\n", level, len);
    3219                 dump_data(0, (uint8 *)buf, len);
     3392                dump_data(0, (uint8_t *)buf, len);
    32203393                printf("\n");
    32213394        }
     
    32383411        }
    32393412
    3240         cli_open(cli, fname,
     3413        cli_openx(cli, fname,
    32413414                        O_RDWR | O_CREAT , DENY_NONE, &fnum);
    32423415
     
    32663439        uint16_t fnum1;
    32673440        bool correct = True;
     3441        NTSTATUS status;
    32683442
    32693443        printf("starting oplock test 1\n");
     
    32753449        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    32763450
    3277         cli_sockopt(cli1, sockops);
     3451        smbXcli_conn_set_sockopt(cli1->conn, sockops);
    32783452
    32793453        cli1->use_oplocks = True;
    32803454
    3281         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
    3282                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
     3455        status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
     3456                          &fnum1);
     3457        if (!NT_STATUS_IS_OK(status)) {
     3458                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
    32833459                return False;
    32843460        }
     
    32893465        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    32903466
    3291         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    3292                 printf("close2 failed (%s)\n", cli_errstr(cli1));
    3293                 return False;
    3294         }
    3295 
    3296         if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
    3297                 printf("unlink failed (%s)\n", cli_errstr(cli1));
     3467        status = cli_close(cli1, fnum1);
     3468        if (!NT_STATUS_IS_OK(status)) {
     3469                printf("close2 failed (%s)\n", nt_errstr(status));
     3470                return False;
     3471        }
     3472
     3473        status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     3474        if (!NT_STATUS_IS_OK(status)) {
     3475                printf("unlink failed (%s)\n", nt_errstr(status));
    32983476                return False;
    32993477        }
     
    33173495        bool correct = True;
    33183496        volatile bool *shared_correct;
    3319 
    3320         shared_correct = (volatile bool *)shm_setup(sizeof(bool));
     3497        size_t nread;
     3498        NTSTATUS status;
     3499
     3500        shared_correct = (volatile bool *)anonymous_shared_allocate(sizeof(bool));
    33213501        *shared_correct = True;
    33223502
     
    33323512        }
    33333513
    3334         cli1->use_oplocks = True;
    3335         cli1->use_level_II_oplocks = True;
    3336 
    33373514        if (!torture_open_connection(&cli2, 1)) {
    33383515                use_level_II_oplocks = False;
     
    33413518        }
    33423519
    3343         cli2->use_oplocks = True;
    3344         cli2->use_level_II_oplocks = True;
    3345 
    33463520        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    33473521
    3348         cli_sockopt(cli1, sockops);
    3349         cli_sockopt(cli2, sockops);
    3350 
    3351         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
    3352                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
     3522        smbXcli_conn_set_sockopt(cli1->conn, sockops);
     3523        smbXcli_conn_set_sockopt(cli2->conn, sockops);
     3524
     3525        status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
     3526                          &fnum1);
     3527        if (!NT_STATUS_IS_OK(status)) {
     3528                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
    33533529                return False;
    33543530        }
     
    33603536        if (fork() == 0) {
    33613537                /* Child code */
    3362                 if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2))) {
    3363                         printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
     3538                status = cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum2);
     3539                if (!NT_STATUS_IS_OK(status)) {
     3540                        printf("second open of %s failed (%s)\n", fname, nt_errstr(status));
    33643541                        *shared_correct = False;
    33653542                        exit(0);
     
    33683545                sleep(2);
    33693546
    3370                 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
    3371                         printf("close2 failed (%s)\n", cli_errstr(cli1));
     3547                status = cli_close(cli2, fnum2);
     3548                if (!NT_STATUS_IS_OK(status)) {
     3549                        printf("close2 failed (%s)\n", nt_errstr(status));
    33723550                        *shared_correct = False;
    33733551                }
     
    33803558        /* Ensure cli1 processes the break. Empty file should always return 0
    33813559         * bytes.  */
    3382 
    3383         if (cli_read(cli1, fnum1, buf, 0, 4) != 0) {
    3384                 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
    3385                 correct = False;
     3560        status = cli_read(cli1, fnum1, buf, 0, 4, &nread);
     3561        if (!NT_STATUS_IS_OK(status)) {
     3562                printf("read on fnum1 failed (%s)\n", nt_errstr(status));
     3563                correct = false;
     3564        } else if (nread != 0) {
     3565                printf("read on empty fnum1 failed. recv %ld expected %d\n",
     3566                      (unsigned long)nread, 0);
     3567                correct = false;
    33863568        }
    33873569
    33883570        /* Should now be at level II. */
    33893571        /* Test if sending a write locks causes a break to none. */
    3390 
    3391         if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
    3392                 printf("lock failed (%s)\n", cli_errstr(cli1));
     3572        status = cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK);
     3573        if (!NT_STATUS_IS_OK(status)) {
     3574                printf("lock failed (%s)\n", nt_errstr(status));
    33933575                correct = False;
    33943576        }
     
    33983580        sleep(2);
    33993581
    3400         if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
    3401                 printf("lock failed (%s)\n", cli_errstr(cli1));
     3582        status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK);
     3583        if (!NT_STATUS_IS_OK(status)) {
     3584                printf("lock failed (%s)\n", nt_errstr(status));
    34023585                correct = False;
    34033586        }
     
    34073590        sleep(2);
    34083591
    3409         cli_read(cli1, fnum1, buf, 0, 4);
    3410 
    3411         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    3412                 printf("close1 failed (%s)\n", cli_errstr(cli1));
     3592        cli_read(cli1, fnum1, buf, 0, 4, NULL);
     3593
     3594        status = cli_close(cli1, fnum1);
     3595        if (!NT_STATUS_IS_OK(status)) {
     3596                printf("close1 failed (%s)\n", nt_errstr(status));
    34133597                correct = False;
    34143598        }
     
    34163600        sleep(4);
    34173601
    3418         if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
    3419                 printf("unlink failed (%s)\n", cli_errstr(cli1));
     3602        status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     3603        if (!NT_STATUS_IS_OK(status)) {
     3604                printf("unlink failed (%s)\n", nt_errstr(status));
    34203605                correct = False;
    34213606        }
     
    34343619}
    34353620
    3436 /* handler for oplock 3 tests */
    3437 static NTSTATUS oplock3_handler(struct cli_state *cli, uint16_t fnum, unsigned char level)
    3438 {
    3439         printf("got oplock break fnum=%d level=%d\n",
    3440                fnum, level);
    3441         return cli_oplock_ack(cli, fnum, level);
    3442 }
    3443 
    3444 static bool run_oplock3(int dummy)
    3445 {
     3621struct oplock4_state {
     3622        struct tevent_context *ev;
    34463623        struct cli_state *cli;
    3447         const char *fname = "\\oplockt3.dat";
    3448         uint16_t fnum;
    3449         char buf[4] = "abcd";
    3450         bool correct = True;
    3451         volatile bool *shared_correct;
    3452 
    3453         shared_correct = (volatile bool *)shm_setup(sizeof(bool));
    3454         *shared_correct = True;
    3455 
    3456         printf("starting oplock test 3\n");
    3457 
    3458         if (fork() == 0) {
    3459                 /* Child code */
    3460                 use_oplocks = True;
    3461                 use_level_II_oplocks = True;
    3462                 if (!torture_open_connection(&cli, 0)) {
    3463                         *shared_correct = False;
    3464                         exit(0);
    3465                 }
    3466                 sleep(2);
    3467                 /* try to trigger a oplock break in parent */
    3468                 cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
    3469                 cli_writeall(cli, fnum, 0, (uint8_t *)buf, 0, 4, NULL);
    3470                 exit(0);
    3471         }
    3472 
    3473         /* parent code */
    3474         use_oplocks = True;
    3475         use_level_II_oplocks = True;
    3476         if (!torture_open_connection(&cli, 1)) { /* other is forked */
    3477                 return False;
    3478         }
    3479         cli_oplock_handler(cli, oplock3_handler);
    3480         cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum);
    3481         cli_writeall(cli, fnum, 0, (uint8_t *)buf, 0, 4, NULL);
    3482         cli_close(cli, fnum);
    3483         cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum);
    3484         cli->timeout = 20000;
    3485         cli_receive_smb(cli);
    3486         printf("finished oplock test 3\n");
    3487 
    3488         return (correct && *shared_correct);
    3489 
    3490 /* What are we looking for here?  What's sucess and what's FAILURE? */
    3491 }
    3492 
    3493 /* handler for oplock 4 tests */
    3494 bool *oplock4_shared_correct;
    3495 
    3496 static NTSTATUS oplock4_handler(struct cli_state *cli, uint16_t fnum, unsigned char level)
    3497 {
    3498         printf("got oplock break fnum=%d level=%d\n",
    3499                fnum, level);
    3500         *oplock4_shared_correct = true;
    3501         cli_oplock_ack(cli, fnum, level);
    3502         return NT_STATUS_UNSUCCESSFUL; /* Cause cli_receive_smb to return. */
    3503 }
     3624        bool *got_break;
     3625        uint16_t *fnum2;
     3626};
     3627
     3628static void oplock4_got_break(struct tevent_req *req);
     3629static void oplock4_got_open(struct tevent_req *req);
    35043630
    35053631static bool run_oplock4(int dummy)
    35063632{
     3633        struct tevent_context *ev;
    35073634        struct cli_state *cli1, *cli2;
     3635        struct tevent_req *oplock_req, *open_req;
    35083636        const char *fname = "\\lockt4.lck";
    35093637        const char *fname_ln = "\\lockt4_ln.lck";
     
    35133641        bool correct = true;
    35143642
    3515         oplock4_shared_correct = (bool *)shm_setup(sizeof(bool));
    3516         *oplock4_shared_correct = false;
     3643        bool got_break;
     3644
     3645        struct oplock4_state *state;
    35173646
    35183647        printf("starting oplock test 4\n");
     
    35333662        cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    35343663
    3535         cli_sockopt(cli1, sockops);
    3536         cli_sockopt(cli2, sockops);
     3664        smbXcli_conn_set_sockopt(cli1->conn, sockops);
     3665        smbXcli_conn_set_sockopt(cli2->conn, sockops);
    35373666
    35383667        /* Create the file. */
    3539         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
    3540                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
    3541                 return false;
    3542         }
    3543 
    3544         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    3545                 printf("close1 failed (%s)\n", cli_errstr(cli1));
     3668        status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE,
     3669                          &fnum1);
     3670        if (!NT_STATUS_IS_OK(status)) {
     3671                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
     3672                return false;
     3673        }
     3674
     3675        status = cli_close(cli1, fnum1);
     3676        if (!NT_STATUS_IS_OK(status)) {
     3677                printf("close1 failed (%s)\n", nt_errstr(status));
    35463678                return false;
    35473679        }
    35483680
    35493681        /* Now create a hardlink. */
    3550         if (!NT_STATUS_IS_OK(cli_nt_hardlink(cli1, fname, fname_ln))) {
    3551                 printf("nt hardlink failed (%s)\n", cli_errstr(cli1));
     3682        status = cli_nt_hardlink(cli1, fname, fname_ln);
     3683        if (!NT_STATUS_IS_OK(status)) {
     3684                printf("nt hardlink failed (%s)\n", nt_errstr(status));
    35523685                return false;
    35533686        }
    35543687
    35553688        /* Prove that opening hardlinks cause deny modes to conflict. */
    3556         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum1))) {
    3557                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
    3558                 return false;
    3559         }
    3560 
    3561         status = cli_open(cli1, fname_ln, O_RDWR, DENY_NONE, &fnum2);
     3689        status = cli_openx(cli1, fname, O_RDWR, DENY_ALL, &fnum1);
     3690        if (!NT_STATUS_IS_OK(status)) {
     3691                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
     3692                return false;
     3693        }
     3694
     3695        status = cli_openx(cli1, fname_ln, O_RDWR, DENY_NONE, &fnum2);
    35623696        if (NT_STATUS_IS_OK(status)) {
    35633697                printf("open of %s succeeded - should fail with sharing violation.\n",
     
    35723706        }
    35733707
    3574         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    3575                 printf("close1 failed (%s)\n", cli_errstr(cli1));
     3708        status = cli_close(cli1, fnum1);
     3709        if (!NT_STATUS_IS_OK(status)) {
     3710                printf("close1 failed (%s)\n", nt_errstr(status));
    35763711                return false;
    35773712        }
    35783713
    35793714        cli1->use_oplocks = true;
    3580         cli1->use_level_II_oplocks = true;
    3581 
    35823715        cli2->use_oplocks = true;
    3583         cli2->use_level_II_oplocks = true;
    3584 
    3585         cli_oplock_handler(cli1, oplock4_handler);
    3586         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1))) {
    3587                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
    3588                 return false;
    3589         }
    3590 
    3591         if (fork() == 0) {
    3592                 /* Child code */
    3593                 if (!NT_STATUS_IS_OK(cli_open(cli2, fname_ln, O_RDWR, DENY_NONE, &fnum2))) {
    3594                         printf("open of %s failed (%s)\n", fname_ln, cli_errstr(cli1));
    3595                         *oplock4_shared_correct = false;
    3596                         exit(0);
    3597                 }
    3598 
    3599                 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
    3600                         printf("close2 failed (%s)\n", cli_errstr(cli1));
    3601                         *oplock4_shared_correct = false;
    3602                 }
    3603 
    3604                 exit(0);
    3605         }
    3606 
    3607         sleep(2);
    3608 
    3609         /* Process the oplock break. */
    3610         cli_receive_smb(cli1);
    3611 
    3612         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    3613                 printf("close1 failed (%s)\n", cli_errstr(cli1));
     3716
     3717        status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
     3718        if (!NT_STATUS_IS_OK(status)) {
     3719                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
     3720                return false;
     3721        }
     3722
     3723        ev = samba_tevent_context_init(talloc_tos());
     3724        if (ev == NULL) {
     3725                printf("tevent_context_init failed\n");
     3726                return false;
     3727        }
     3728
     3729        state = talloc(ev, struct oplock4_state);
     3730        if (state == NULL) {
     3731                printf("talloc failed\n");
     3732                return false;
     3733        }
     3734        state->ev = ev;
     3735        state->cli = cli1;
     3736        state->got_break = &got_break;
     3737        state->fnum2 = &fnum2;
     3738
     3739        oplock_req = cli_smb_oplock_break_waiter_send(
     3740                talloc_tos(), ev, cli1);
     3741        if (oplock_req == NULL) {
     3742                printf("cli_smb_oplock_break_waiter_send failed\n");
     3743                return false;
     3744        }
     3745        tevent_req_set_callback(oplock_req, oplock4_got_break, state);
     3746
     3747        open_req = cli_openx_send(
     3748                talloc_tos(), ev, cli2, fname_ln, O_RDWR, DENY_NONE);
     3749        if (open_req == NULL) {
     3750                printf("cli_openx_send failed\n");
     3751                return false;
     3752        }
     3753        tevent_req_set_callback(open_req, oplock4_got_open, state);
     3754
     3755        got_break = false;
     3756        fnum2 = 0xffff;
     3757
     3758        while (!got_break || fnum2 == 0xffff) {
     3759                int ret;
     3760                ret = tevent_loop_once(ev);
     3761                if (ret == -1) {
     3762                        printf("tevent_loop_once failed: %s\n",
     3763                               strerror(errno));
     3764                        return false;
     3765                }
     3766        }
     3767
     3768        status = cli_close(cli2, fnum2);
     3769        if (!NT_STATUS_IS_OK(status)) {
     3770                printf("close2 failed (%s)\n", nt_errstr(status));
    36143771                correct = false;
    36153772        }
    36163773
    3617         if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
    3618                 printf("unlink failed (%s)\n", cli_errstr(cli1));
     3774        status = cli_close(cli1, fnum1);
     3775        if (!NT_STATUS_IS_OK(status)) {
     3776                printf("close1 failed (%s)\n", nt_errstr(status));
    36193777                correct = false;
    36203778        }
    3621         if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
    3622                 printf("unlink failed (%s)\n", cli_errstr(cli1));
     3779
     3780        status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     3781        if (!NT_STATUS_IS_OK(status)) {
     3782                printf("unlink failed (%s)\n", nt_errstr(status));
     3783                correct = false;
     3784        }
     3785
     3786        status = cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     3787        if (!NT_STATUS_IS_OK(status)) {
     3788                printf("unlink failed (%s)\n", nt_errstr(status));
    36233789                correct = false;
    36243790        }
     
    36283794        }
    36293795
    3630         if (!*oplock4_shared_correct) {
     3796        if (!got_break) {
    36313797                correct = false;
    36323798        }
     
    36373803}
    36383804
     3805static void oplock4_got_break(struct tevent_req *req)
     3806{
     3807        struct oplock4_state *state = tevent_req_callback_data(
     3808                req, struct oplock4_state);
     3809        uint16_t fnum;
     3810        uint8_t level;
     3811        NTSTATUS status;
     3812
     3813        status = cli_smb_oplock_break_waiter_recv(req, &fnum, &level);
     3814        TALLOC_FREE(req);
     3815        if (!NT_STATUS_IS_OK(status)) {
     3816                printf("cli_smb_oplock_break_waiter_recv returned %s\n",
     3817                       nt_errstr(status));
     3818                return;
     3819        }
     3820        *state->got_break = true;
     3821
     3822        req = cli_oplock_ack_send(state, state->ev, state->cli, fnum,
     3823                                  NO_OPLOCK);
     3824        if (req == NULL) {
     3825                printf("cli_oplock_ack_send failed\n");
     3826                return;
     3827        }
     3828}
     3829
     3830static void oplock4_got_open(struct tevent_req *req)
     3831{
     3832        struct oplock4_state *state = tevent_req_callback_data(
     3833                req, struct oplock4_state);
     3834        NTSTATUS status;
     3835
     3836        status = cli_openx_recv(req, state->fnum2);
     3837        if (!NT_STATUS_IS_OK(status)) {
     3838                printf("cli_openx_recv returned %s\n", nt_errstr(status));
     3839                *state->fnum2 = 0xffff;
     3840        }
     3841}
    36393842
    36403843/*
     
    36483851        uint16_t fnum1 = (uint16_t)-1;
    36493852        uint16_t fnum2 = (uint16_t)-1;
    3650         bool correct = True;
     3853        bool correct = false;
     3854        NTSTATUS status;
    36513855
    36523856        printf("starting delete test\n");
     
    36563860        }
    36573861
    3658         cli_sockopt(cli1, sockops);
     3862        smbXcli_conn_set_sockopt(cli1->conn, sockops);
    36593863
    36603864        /* Test 1 - this should delete the file on close. */
     
    36633867        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    36643868
    3665         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
    3666                                    0, FILE_OVERWRITE_IF,
    3667                                    FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
    3668                 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
    3669                 correct = False;
     3869        status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
     3870                              FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
     3871                              FILE_DELETE_ON_CLOSE, 0, &fnum1, NULL);
     3872        if (!NT_STATUS_IS_OK(status)) {
     3873                printf("[1] open of %s failed (%s)\n", fname, nt_errstr(status));
    36703874                goto fail;
    36713875        }
    36723876
    3673         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    3674                 printf("[1] close failed (%s)\n", cli_errstr(cli1));
    3675                 correct = False;
     3877        status = cli_close(cli1, fnum1);
     3878        if (!NT_STATUS_IS_OK(status)) {
     3879                printf("[1] close failed (%s)\n", nt_errstr(status));
    36763880                goto fail;
    36773881        }
    36783882
    3679         if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1))) {
     3883        status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
     3884        if (NT_STATUS_IS_OK(status)) {
    36803885                printf("[1] open of %s succeeded (should fail)\n", fname);
    3681                 correct = False;
    36823886                goto fail;
    36833887        }
     
    36903894        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    36913895
    3692         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
    3693                                    FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
    3694                                    FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    3695                 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
    3696                 correct = False;
     3896        status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
     3897                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
     3898                              FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     3899        if (!NT_STATUS_IS_OK(status)) {
     3900                printf("[2] open of %s failed (%s)\n", fname, nt_errstr(status));
    36973901                goto fail;
    36983902        }
    36993903
    3700         if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
    3701                 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
    3702                 correct = False;
     3904        status = cli_nt_delete_on_close(cli1, fnum1, true);
     3905        if (!NT_STATUS_IS_OK(status)) {
     3906                printf("[2] setting delete_on_close failed (%s)\n", nt_errstr(status));
    37033907                goto fail;
    37043908        }
    37053909
    3706         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    3707                 printf("[2] close failed (%s)\n", cli_errstr(cli1));
    3708                 correct = False;
     3910        status = cli_close(cli1, fnum1);
     3911        if (!NT_STATUS_IS_OK(status)) {
     3912                printf("[2] close failed (%s)\n", nt_errstr(status));
    37093913                goto fail;
    37103914        }
    37113915
    3712         if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
     3916        status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
     3917        if (NT_STATUS_IS_OK(status)) {
    37133918                printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
    3714                 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    3715                         printf("[2] close failed (%s)\n", cli_errstr(cli1));
    3716                         correct = False;
    3717                         goto fail;
     3919                status = cli_close(cli1, fnum1);
     3920                if (!NT_STATUS_IS_OK(status)) {
     3921                        printf("[2] close failed (%s)\n", nt_errstr(status));
    37183922                }
    37193923                cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    3720         } else
    3721                 printf("second delete on close test succeeded.\n");
     3924                goto fail;
     3925        }
     3926
     3927        printf("second delete on close test succeeded.\n");
    37223928
    37233929        /* Test 3 - ... */
     
    37253931        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    37263932
    3727         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
    3728                                    FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    3729                 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
    3730                 correct = False;
     3933        status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
     3934                              FILE_ATTRIBUTE_NORMAL,
     3935                              FILE_SHARE_READ|FILE_SHARE_WRITE,
     3936                              FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     3937        if (!NT_STATUS_IS_OK(status)) {
     3938                printf("[3] open - 1 of %s failed (%s)\n", fname, nt_errstr(status));
    37313939                goto fail;
    37323940        }
     
    37353943           with SHARE_DELETE. */
    37363944
    3737         if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
    3738                         FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0, &fnum2))) {
     3945        status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
     3946                              FILE_ATTRIBUTE_NORMAL,
     3947                              FILE_SHARE_READ|FILE_SHARE_WRITE,
     3948                              FILE_OPEN, 0, 0, &fnum2, NULL);
     3949        if (NT_STATUS_IS_OK(status)) {
    37393950                printf("[3] open  - 2 of %s succeeded - should have failed.\n", fname);
    3740                 correct = False;
    37413951                goto fail;
    37423952        }
    37433953
    37443954        /* This should succeed. */
    3745 
    3746         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
    3747                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2))) {
    3748                 printf("[3] open  - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
    3749                 correct = False;
     3955        status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
     3956                             FILE_ATTRIBUTE_NORMAL,
     3957                             FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
     3958                             FILE_OPEN, 0, 0, &fnum2, NULL);
     3959        if (!NT_STATUS_IS_OK(status)) {
     3960                printf("[3] open  - 3 of %s failed (%s)\n", fname, nt_errstr(status));
    37503961                goto fail;
    37513962        }
    37523963
    3753         if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
    3754                 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
    3755                 correct = False;
     3964        status = cli_nt_delete_on_close(cli1, fnum1, true);
     3965        if (!NT_STATUS_IS_OK(status)) {
     3966                printf("[3] setting delete_on_close failed (%s)\n", nt_errstr(status));
    37563967                goto fail;
    37573968        }
    37583969
    3759         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    3760                 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
    3761                 correct = False;
     3970        status = cli_close(cli1, fnum1);
     3971        if (!NT_STATUS_IS_OK(status)) {
     3972                printf("[3] close 1 failed (%s)\n", nt_errstr(status));
    37623973                goto fail;
    37633974        }
    37643975
    3765         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
    3766                 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
    3767                 correct = False;
     3976        status = cli_close(cli1, fnum2);
     3977        if (!NT_STATUS_IS_OK(status)) {
     3978                printf("[3] close 2 failed (%s)\n", nt_errstr(status));
    37683979                goto fail;
    37693980        }
     
    37713982        /* This should fail - file should no longer be there. */
    37723983
    3773         if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
     3984        status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
     3985        if (NT_STATUS_IS_OK(status)) {
    37743986                printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
    3775                 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    3776                         printf("[3] close failed (%s)\n", cli_errstr(cli1));
     3987                status = cli_close(cli1, fnum1);
     3988                if (!NT_STATUS_IS_OK(status)) {
     3989                        printf("[3] close failed (%s)\n", nt_errstr(status));
    37773990                }
    37783991                cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    3779                 correct = False;
    37803992                goto fail;
    3781         } else
    3782                 printf("third delete on close test succeeded.\n");
     3993        }
     3994
     3995        printf("third delete on close test succeeded.\n");
    37833996
    37843997        /* Test 4 ... */
     
    37863999        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    37874000
    3788         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
    3789                         FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    3790                 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
    3791                 correct = False;
     4001        status = cli_ntcreate(cli1, fname, 0,
     4002                              FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
     4003                              FILE_ATTRIBUTE_NORMAL,
     4004                              FILE_SHARE_READ|FILE_SHARE_WRITE,
     4005                              FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     4006        if (!NT_STATUS_IS_OK(status)) {
     4007                printf("[4] open of %s failed (%s)\n", fname, nt_errstr(status));
    37924008                goto fail;
    37934009        }
    37944010
    37954011        /* This should succeed. */
    3796         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
    3797                         FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2))) {
    3798                 printf("[4] open  - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
    3799                 correct = False;
     4012        status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
     4013                             FILE_ATTRIBUTE_NORMAL,
     4014                             FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
     4015                             FILE_OPEN, 0, 0, &fnum2, NULL);
     4016        if (!NT_STATUS_IS_OK(status)) {
     4017                printf("[4] open  - 2 of %s failed (%s)\n", fname, nt_errstr(status));
    38004018                goto fail;
    38014019        }
    38024020
    3803         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
    3804                 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
    3805                 correct = False;
     4021        status = cli_close(cli1, fnum2);
     4022        if (!NT_STATUS_IS_OK(status)) {
     4023                printf("[4] close - 1 failed (%s)\n", nt_errstr(status));
    38064024                goto fail;
    38074025        }
    38084026
    3809         if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
    3810                 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
    3811                 correct = False;
     4027        status = cli_nt_delete_on_close(cli1, fnum1, true);
     4028        if (!NT_STATUS_IS_OK(status)) {
     4029                printf("[4] setting delete_on_close failed (%s)\n", nt_errstr(status));
    38124030                goto fail;
    38134031        }
    38144032
    38154033        /* This should fail - no more opens once delete on close set. */
    3816         if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
    3817                                    FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
    3818                                    FILE_OPEN, 0, 0, &fnum2))) {
     4034        status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
     4035                              FILE_ATTRIBUTE_NORMAL,
     4036                              FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
     4037                              FILE_OPEN, 0, 0, &fnum2, NULL);
     4038        if (NT_STATUS_IS_OK(status)) {
    38194039                printf("[4] open  - 3 of %s succeeded ! Should have failed.\n", fname );
    3820                 correct = False;
    38214040                goto fail;
    3822         } else
    3823                 printf("fourth delete on close test succeeded.\n");
    3824 
    3825         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    3826                 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
    3827                 correct = False;
     4041        }
     4042
     4043        status = cli_close(cli1, fnum1);
     4044        if (!NT_STATUS_IS_OK(status)) {
     4045                printf("[4] close - 2 failed (%s)\n", nt_errstr(status));
    38284046                goto fail;
    38294047        }
     4048
     4049        printf("fourth delete on close test succeeded.\n");
    38304050
    38314051        /* Test 5 ... */
     
    38334053        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    38344054
    3835         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1))) {
    3836                 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
    3837                 correct = False;
     4055        status = cli_openx(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1);
     4056        if (!NT_STATUS_IS_OK(status)) {
     4057                printf("[5] open of %s failed (%s)\n", fname, nt_errstr(status));
    38384058                goto fail;
    38394059        }
     
    38414061        /* This should fail - only allowed on NT opens with DELETE access. */
    38424062
    3843         if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
     4063        status = cli_nt_delete_on_close(cli1, fnum1, true);
     4064        if (NT_STATUS_IS_OK(status)) {
    38444065                printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
    3845                 correct = False;
    38464066                goto fail;
    38474067        }
    38484068
    3849         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    3850                 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
    3851                 correct = False;
     4069        status = cli_close(cli1, fnum1);
     4070        if (!NT_STATUS_IS_OK(status)) {
     4071                printf("[5] close failed (%s)\n", nt_errstr(status));
    38524072                goto fail;
    38534073        }
     
    38594079        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    38604080
    3861         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
    3862                                    FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
    3863                                    FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    3864                 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
    3865                 correct = False;
     4081        status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
     4082                             FILE_ATTRIBUTE_NORMAL,
     4083                             FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
     4084                             FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     4085        if (!NT_STATUS_IS_OK(status)) {
     4086                printf("[6] open of %s failed (%s)\n", fname,
     4087                       nt_errstr(status));
    38664088                goto fail;
    38674089        }
     
    38694091        /* This should fail - only allowed on NT opens with DELETE access. */
    38704092
    3871         if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
     4093        status = cli_nt_delete_on_close(cli1, fnum1, true);
     4094        if (NT_STATUS_IS_OK(status)) {
    38724095                printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
    3873                 correct = False;
    38744096                goto fail;
    38754097        }
    38764098
    3877         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    3878                 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
    3879                 correct = False;
     4099        status = cli_close(cli1, fnum1);
     4100        if (!NT_STATUS_IS_OK(status)) {
     4101                printf("[6] close failed (%s)\n", nt_errstr(status));
    38804102                goto fail;
    38814103        }
     
    38874109        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    38884110
    3889         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
    3890                                    FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    3891                 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
    3892                 correct = False;
     4111        status = cli_ntcreate(cli1, fname, 0,
     4112                              FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
     4113                              FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
     4114                              0, 0, &fnum1, NULL);
     4115        if (!NT_STATUS_IS_OK(status)) {
     4116                printf("[7] open of %s failed (%s)\n", fname, nt_errstr(status));
    38934117                goto fail;
    38944118        }
    38954119
    3896         if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
     4120        status = cli_nt_delete_on_close(cli1, fnum1, true);
     4121        if (!NT_STATUS_IS_OK(status)) {
    38974122                printf("[7] setting delete_on_close on file failed !\n");
    3898                 correct = False;
    38994123                goto fail;
    39004124        }
    39014125
    3902         if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, false))) {
     4126        status = cli_nt_delete_on_close(cli1, fnum1, false);
     4127        if (!NT_STATUS_IS_OK(status)) {
    39034128                printf("[7] unsetting delete_on_close on file failed !\n");
    3904                 correct = False;
    39054129                goto fail;
    39064130        }
    39074131
    3908         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    3909                 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
    3910                 correct = False;
     4132        status = cli_close(cli1, fnum1);
     4133        if (!NT_STATUS_IS_OK(status)) {
     4134                printf("[7] close - 1 failed (%s)\n", nt_errstr(status));
    39114135                goto fail;
    39124136        }
    39134137
    39144138        /* This next open should succeed - we reset the flag. */
    3915 
    3916         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
    3917                 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
    3918                 correct = False;
     4139        status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
     4140        if (!NT_STATUS_IS_OK(status)) {
     4141                printf("[7] open of %s failed (%s)\n", fname, nt_errstr(status));
    39194142                goto fail;
    39204143        }
    39214144
    3922         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    3923                 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
    3924                 correct = False;
     4145        status = cli_close(cli1, fnum1);
     4146        if (!NT_STATUS_IS_OK(status)) {
     4147                printf("[7] close - 2 failed (%s)\n", nt_errstr(status));
    39254148                goto fail;
    39264149        }
     
    39284151        printf("seventh delete on close test succeeded.\n");
    39294152
    3930         /* Test 7 ... */
     4153        /* Test 8 ... */
    39314154        cli_setatr(cli1, fname, 0, 0);
    39324155        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     
    39344157        if (!torture_open_connection(&cli2, 1)) {
    39354158                printf("[8] failed to open second connection.\n");
    3936                 correct = False;
    39374159                goto fail;
    39384160        }
    39394161
    3940         cli_sockopt(cli1, sockops);
    3941 
    3942         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
    3943                                    FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
    3944                                    FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    3945                 printf("[8] open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
    3946                 correct = False;
     4162        smbXcli_conn_set_sockopt(cli1->conn, sockops);
     4163
     4164        status = cli_ntcreate(cli1, fname, 0,
     4165                             FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
     4166                             FILE_ATTRIBUTE_NORMAL,
     4167                             FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
     4168                             FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     4169        if (!NT_STATUS_IS_OK(status)) {
     4170                printf("[8] open 1 of %s failed (%s)\n", fname, nt_errstr(status));
    39474171                goto fail;
    39484172        }
    39494173
    3950         if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
    3951                                    FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
    3952                                    FILE_OPEN, 0, 0, &fnum2))) {
    3953                 printf("[8] open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
    3954                 correct = False;
     4174        status = cli_ntcreate(cli2, fname, 0,
     4175                             FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
     4176                             FILE_ATTRIBUTE_NORMAL,
     4177                             FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
     4178                             FILE_OPEN, 0, 0, &fnum2, NULL);
     4179        if (!NT_STATUS_IS_OK(status)) {
     4180                printf("[8] open 2 of %s failed (%s)\n", fname, nt_errstr(status));
    39554181                goto fail;
    39564182        }
    39574183
    3958         if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {
     4184        status = cli_nt_delete_on_close(cli1, fnum1, true);
     4185        if (!NT_STATUS_IS_OK(status)) {
    39594186                printf("[8] setting delete_on_close on file failed !\n");
    3960                 correct = False;
    39614187                goto fail;
    39624188        }
    39634189
    3964         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    3965                 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
    3966                 correct = False;
     4190        status = cli_close(cli1, fnum1);
     4191        if (!NT_STATUS_IS_OK(status)) {
     4192                printf("[8] close - 1 failed (%s)\n", nt_errstr(status));
    39674193                goto fail;
    39684194        }
    39694195
    3970         if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
    3971                 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
    3972                 correct = False;
     4196        status = cli_close(cli2, fnum2);
     4197        if (!NT_STATUS_IS_OK(status)) {
     4198                printf("[8] close - 2 failed (%s)\n", nt_errstr(status));
    39734199                goto fail;
    39744200        }
    39754201
    39764202        /* This should fail.. */
    3977         if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
     4203        status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
     4204        if (NT_STATUS_IS_OK(status)) {
    39784205                printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
    39794206                goto fail;
    3980                 correct = False;
    3981         } else
    3982                 printf("eighth delete on close test succeeded.\n");
     4207        }
     4208
     4209        printf("eighth delete on close test succeeded.\n");
     4210
     4211        /* Test 9 ... */
    39834212
    39844213        /* This should fail - we need to set DELETE_ACCESS. */
    3985         if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
    3986                                    FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
     4214        status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
     4215                              FILE_ATTRIBUTE_NORMAL,
     4216                              FILE_SHARE_NONE,
     4217                              FILE_OVERWRITE_IF,
     4218                              FILE_DELETE_ON_CLOSE, 0, &fnum1, NULL);
     4219        if (NT_STATUS_IS_OK(status)) {
    39874220                printf("[9] open of %s succeeded should have failed!\n", fname);
    3988                 correct = False;
    39894221                goto fail;
    39904222        }
     
    39924224        printf("ninth delete on close test succeeded.\n");
    39934225
    3994         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
    3995                                    FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) {
    3996                 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
    3997                 correct = False;
     4226        /* Test 10 ... */
     4227
     4228        status = cli_ntcreate(cli1, fname, 0,
     4229                             FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
     4230                             FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
     4231                             FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE,
     4232                             0, &fnum1, NULL);
     4233        if (!NT_STATUS_IS_OK(status)) {
     4234                printf("[10] open of %s failed (%s)\n", fname, nt_errstr(status));
    39984235                goto fail;
    39994236        }
    40004237
    40014238        /* This should delete the file. */
    4002         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4003                 printf("[10] close failed (%s)\n", cli_errstr(cli1));
    4004                 correct = False;
     4239        status = cli_close(cli1, fnum1);
     4240        if (!NT_STATUS_IS_OK(status)) {
     4241                printf("[10] close failed (%s)\n", nt_errstr(status));
    40054242                goto fail;
    40064243        }
    40074244
    40084245        /* This should fail.. */
    4009         if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) {
     4246        status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
     4247        if (NT_STATUS_IS_OK(status)) {
    40104248                printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
    40114249                goto fail;
    4012                 correct = False;
    4013         } else
    4014                 printf("tenth delete on close test succeeded.\n");
     4250        }
     4251
     4252        printf("tenth delete on close test succeeded.\n");
     4253
     4254        /* Test 11 ... */
    40154255
    40164256        cli_setatr(cli1, fname, 0, 0);
    40174257        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    40184258
    4019         /* What error do we get when attempting to open a read-only file with
    4020            delete access ? */
     4259        /* Can we open a read-only file with delete access? */
    40214260
    40224261        /* Create a readonly file. */
    4023         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
    4024                                    FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    4025                 printf("[11] open of %s failed (%s)\n", fname, cli_errstr(cli1));
    4026                 correct = False;
     4262        status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
     4263                              FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE,
     4264                              FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     4265        if (!NT_STATUS_IS_OK(status)) {
     4266                printf("[11] open of %s failed (%s)\n", fname, nt_errstr(status));
    40274267                goto fail;
    40284268        }
    40294269
    4030         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4031                 printf("[11] close failed (%s)\n", cli_errstr(cli1));
    4032                 correct = False;
     4270        status = cli_close(cli1, fnum1);
     4271        if (!NT_STATUS_IS_OK(status)) {
     4272                printf("[11] close failed (%s)\n", nt_errstr(status));
    40334273                goto fail;
    40344274        }
    40354275
    40364276        /* Now try open for delete access. */
    4037         if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
    4038                                    0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
    4039                                    FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    4040                 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
    4041                 cli_close(cli1, fnum1);
     4277        status = cli_ntcreate(cli1, fname, 0,
     4278                             FILE_READ_ATTRIBUTES|DELETE_ACCESS,
     4279                             0,
     4280                             FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
     4281                             FILE_OPEN, 0, 0, &fnum1, NULL);
     4282        if (!NT_STATUS_IS_OK(status)) {
     4283                printf("[11] open of %s failed: %s\n", fname, nt_errstr(status));
    40424284                goto fail;
    4043                 correct = False;
    4044         } else {
    4045                 NTSTATUS nterr = cli_nt_error(cli1);
    4046                 if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) {
    4047                         printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr));
    4048                         goto fail;
    4049                         correct = False;
    4050                 } else {
    4051                         printf("eleventh delete on close test succeeded.\n");
    4052                 }
    4053         }
     4285        }
     4286
     4287        cli_close(cli1, fnum1);
     4288
     4289        printf("eleventh delete on close test succeeded.\n");
     4290
     4291        /*
     4292         * Test 12
     4293         * like test 4 but with initial delete on close
     4294         */
     4295
     4296        cli_setatr(cli1, fname, 0, 0);
     4297        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     4298
     4299        status = cli_ntcreate(cli1, fname, 0,
     4300                              FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
     4301                              FILE_ATTRIBUTE_NORMAL,
     4302                              FILE_SHARE_READ|FILE_SHARE_WRITE,
     4303                              FILE_OVERWRITE_IF,
     4304                              FILE_DELETE_ON_CLOSE, 0, &fnum1, NULL);
     4305        if (!NT_STATUS_IS_OK(status)) {
     4306                printf("[12] open 1 of %s failed (%s)\n", fname, nt_errstr(status));
     4307                goto fail;
     4308        }
     4309
     4310        status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
     4311                              FILE_ATTRIBUTE_NORMAL,
     4312                              FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
     4313                              FILE_OPEN, 0, 0, &fnum2, NULL);
     4314        if (!NT_STATUS_IS_OK(status)) {
     4315                printf("[12] open 2 of %s failed(%s).\n", fname, nt_errstr(status));
     4316                goto fail;
     4317        }
     4318
     4319        status = cli_close(cli1, fnum2);
     4320        if (!NT_STATUS_IS_OK(status)) {
     4321                printf("[12] close 1 failed (%s)\n", nt_errstr(status));
     4322                goto fail;
     4323        }
     4324
     4325        status = cli_nt_delete_on_close(cli1, fnum1, true);
     4326        if (!NT_STATUS_IS_OK(status)) {
     4327                printf("[12] setting delete_on_close failed (%s)\n", nt_errstr(status));
     4328                goto fail;
     4329        }
     4330
     4331        /* This should fail - no more opens once delete on close set. */
     4332        status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
     4333                              FILE_ATTRIBUTE_NORMAL,
     4334                              FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
     4335                              FILE_OPEN, 0, 0, &fnum2, NULL);
     4336        if (NT_STATUS_IS_OK(status)) {
     4337                printf("[12] open 3 of %s succeeded - should fail).\n", fname);
     4338                goto fail;
     4339        }
     4340
     4341        status = cli_nt_delete_on_close(cli1, fnum1, false);
     4342        if (!NT_STATUS_IS_OK(status)) {
     4343                printf("[12] unsetting delete_on_close failed (%s)\n", nt_errstr(status));
     4344                goto fail;
     4345        }
     4346
     4347        status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
     4348                              FILE_ATTRIBUTE_NORMAL,
     4349                              FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
     4350                              FILE_OPEN, 0, 0, &fnum2, NULL);
     4351        if (!NT_STATUS_IS_OK(status)) {
     4352                printf("[12] open 4 of %s failed (%s)\n", fname, nt_errstr(status));
     4353                goto fail;
     4354        }
     4355
     4356        status = cli_close(cli1, fnum2);
     4357        if (!NT_STATUS_IS_OK(status)) {
     4358                printf("[12] close 2 failed (%s)\n", nt_errstr(status));
     4359                goto fail;
     4360        }
     4361
     4362        status = cli_close(cli1, fnum1);
     4363        if (!NT_STATUS_IS_OK(status)) {
     4364                printf("[12] close 3 failed (%s)\n", nt_errstr(status));
     4365                goto fail;
     4366        }
     4367
     4368        /*
     4369         * setting delete on close on the handle does
     4370         * not unset the initial delete on close...
     4371         */
     4372        status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
     4373                              FILE_ATTRIBUTE_NORMAL,
     4374                              FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
     4375                              FILE_OPEN, 0, 0, &fnum2, NULL);
     4376        if (NT_STATUS_IS_OK(status)) {
     4377                printf("[12] open 5 of %s succeeded - should fail).\n", fname);
     4378                goto fail;
     4379        } else if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
     4380                printf("ntcreate returned %s, expected "
     4381                       "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
     4382                       nt_errstr(status));
     4383                goto fail;
     4384        }
     4385
     4386        printf("twelfth delete on close test succeeded.\n");
     4387
    40544388
    40554389        printf("finished delete test\n");
     4390
     4391        correct = true;
    40564392
    40574393  fail:
     
    40704406        if (cli2 && !torture_close_connection(cli2)) {
    40714407                correct = False;
     4408        }
     4409        return correct;
     4410}
     4411
     4412
     4413/*
     4414  Test wildcard delete.
     4415 */
     4416static bool run_wild_deletetest(int dummy)
     4417{
     4418        struct cli_state *cli = NULL;
     4419        const char *dname = "\\WTEST";
     4420        const char *fname = "\\WTEST\\A";
     4421        const char *wunlink_name = "\\WTEST\\*";
     4422        uint16_t fnum1 = (uint16_t)-1;
     4423        bool correct = false;
     4424        NTSTATUS status;
     4425
     4426        printf("starting wildcard delete test\n");
     4427
     4428        if (!torture_open_connection(&cli, 0)) {
     4429                return false;
     4430        }
     4431
     4432        smbXcli_conn_set_sockopt(cli->conn, sockops);
     4433
     4434        cli_unlink(cli, fname, 0);
     4435        cli_rmdir(cli, dname);
     4436        status = cli_mkdir(cli, dname);
     4437        if (!NT_STATUS_IS_OK(status)) {
     4438                printf("mkdir of %s failed %s!\n", dname, nt_errstr(status));
     4439                goto fail;
     4440        }
     4441        status = cli_openx(cli, fname, O_CREAT|O_RDONLY, DENY_NONE, &fnum1);
     4442        if (!NT_STATUS_IS_OK(status)) {
     4443                printf("open of %s failed %s!\n", fname, nt_errstr(status));
     4444                goto fail;
     4445        }
     4446        status = cli_close(cli, fnum1);
     4447        fnum1 = -1;
     4448
     4449        /*
     4450         * Note the unlink attribute-type of zero. This should
     4451         * map into FILE_ATTRIBUTE_NORMAL at the server even
     4452         * on a wildcard delete.
     4453         */
     4454
     4455        status = cli_unlink(cli, wunlink_name, 0);
     4456        if (!NT_STATUS_IS_OK(status)) {
     4457                printf("unlink of %s failed %s!\n",
     4458                        wunlink_name, nt_errstr(status));
     4459                goto fail;
     4460        }
     4461
     4462        printf("finished wildcard delete test\n");
     4463
     4464        correct = true;
     4465
     4466  fail:
     4467
     4468        if (fnum1 != (uint16_t)-1) cli_close(cli, fnum1);
     4469        cli_unlink(cli, fname, 0);
     4470        cli_rmdir(cli, dname);
     4471
     4472        if (cli && !torture_close_connection(cli)) {
     4473                correct = false;
    40724474        }
    40734475        return correct;
     
    40944496        cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    40954497
    4096         cli_sockopt(cli, sockops);
     4498        smbXcli_conn_set_sockopt(cli->conn, sockops);
    40974499
    40984500        /* Create the file. */
    4099         if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
    4100                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
    4101                 return false;
    4102         }
    4103 
    4104         if (!NT_STATUS_IS_OK(cli_close(cli, fnum))) {
    4105                 printf("close1 failed (%s)\n", cli_errstr(cli));
     4501        status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
     4502        if (!NT_STATUS_IS_OK(status)) {
     4503                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
     4504                return false;
     4505        }
     4506
     4507        status = cli_close(cli, fnum);
     4508        if (!NT_STATUS_IS_OK(status)) {
     4509                printf("close1 failed (%s)\n", nt_errstr(status));
    41064510                return false;
    41074511        }
    41084512
    41094513        /* Now create a hardlink. */
    4110         if (!NT_STATUS_IS_OK(cli_nt_hardlink(cli, fname, fname_ln))) {
    4111                 printf("nt hardlink failed (%s)\n", cli_errstr(cli));
     4514        status = cli_nt_hardlink(cli, fname, fname_ln);
     4515        if (!NT_STATUS_IS_OK(status)) {
     4516                printf("nt hardlink failed (%s)\n", nt_errstr(status));
    41124517                return false;
    41134518        }
     
    41174522                        FILE_ATTRIBUTE_NORMAL,
    41184523                        FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
    4119                         FILE_OPEN_IF, 0, 0, &fnum);
     4524                        FILE_OPEN_IF, 0, 0, &fnum, NULL);
    41204525        if (!NT_STATUS_IS_OK(status)) {
    41214526                printf("ntcreate of %s failed (%s)\n", fname, nt_errstr(status));
     
    41274532                        FILE_ATTRIBUTE_NORMAL,
    41284533                        FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
    4129                         FILE_OPEN_IF, 0, 0, &fnum1);
     4534                        FILE_OPEN_IF, 0, 0, &fnum1, NULL);
    41304535        if (!NT_STATUS_IS_OK(status)) {
    41314536                printf("ntcreate of %s failed (%s)\n", fname_ln, nt_errstr(status));
     
    42014606        }
    42024607
    4203         cli_sockopt(cli, sockops);
    4204 
    4205         d_printf("Capabilities 0x%08x\n", cli->capabilities);
     4608        smbXcli_conn_set_sockopt(cli->conn, sockops);
     4609
     4610        d_printf("Capabilities 0x%08x\n", smb1cli_conn_capabilities(cli->conn));
    42064611
    42074612        if (!torture_close_connection(cli)) {
     
    42424647        bool correct = True;
    42434648        uint16_t fnum1, fnum2;
     4649        NTSTATUS status;
    42444650
    42454651        printf("starting xcopy test\n");
     
    42494655        }
    42504656
    4251         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,
    4252                                    FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
    4253                                    FILE_SHARE_NONE, FILE_OVERWRITE_IF,
    4254                                    0x4044, 0, &fnum1))) {
    4255                 printf("First open failed - %s\n", cli_errstr(cli1));
    4256                 return False;
    4257         }
    4258 
    4259         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,
    4260                                    SECOND_DESIRED_ACCESS, 0,
    4261                                    FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
    4262                                    0x200000, 0, &fnum2))) {
    4263                 printf("second open failed - %s\n", cli_errstr(cli1));
     4657        status = cli_ntcreate(cli1, fname, 0, FIRST_DESIRED_ACCESS,
     4658                              FILE_ATTRIBUTE_ARCHIVE, FILE_SHARE_NONE,
     4659                              FILE_OVERWRITE_IF, 0x4044, 0, &fnum1, NULL);
     4660        if (!NT_STATUS_IS_OK(status)) {
     4661                printf("First open failed - %s\n", nt_errstr(status));
     4662                return False;
     4663        }
     4664
     4665        status = cli_ntcreate(cli1, fname, 0, SECOND_DESIRED_ACCESS, 0,
     4666                             FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
     4667                             FILE_OPEN, 0x200000, 0, &fnum2, NULL);
     4668        if (!NT_STATUS_IS_OK(status)) {
     4669                printf("second open failed - %s\n", nt_errstr(status));
    42644670                return False;
    42654671        }
     
    42934699        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    42944700        cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    4295         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
    4296                                    FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    4297                 printf("First open failed - %s\n", cli_errstr(cli1));
    4298                 return False;
    4299         }
    4300 
    4301         if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
    4302                 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1));
     4701
     4702        status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
     4703                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
     4704                              FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     4705        if (!NT_STATUS_IS_OK(status)) {
     4706                printf("First open failed - %s\n", nt_errstr(status));
     4707                return False;
     4708        }
     4709
     4710        status = cli_rename(cli1, fname, fname1);
     4711        if (!NT_STATUS_IS_OK(status)) {
     4712                printf("First rename failed (SHARE_READ) (this is correct) - %s\n", nt_errstr(status));
    43034713        } else {
    43044714                printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
     
    43064716        }
    43074717
    4308         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4309                 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
     4718        status = cli_close(cli1, fnum1);
     4719        if (!NT_STATUS_IS_OK(status)) {
     4720                printf("close - 1 failed (%s)\n", nt_errstr(status));
    43104721                return False;
    43114722        }
     
    43194730                              FILE_SHARE_DELETE|FILE_SHARE_READ,
    43204731#endif
    4321                               FILE_OVERWRITE_IF, 0, 0, &fnum1);
    4322         if (!NT_STATUS_IS_OK(status)) {
    4323                 printf("Second open failed - %s\n", cli_errstr(cli1));
    4324                 return False;
    4325         }
    4326 
    4327         if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
    4328                 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1));
     4732                              FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     4733        if (!NT_STATUS_IS_OK(status)) {
     4734                printf("Second open failed - %s\n", nt_errstr(status));
     4735                return False;
     4736        }
     4737
     4738        status = cli_rename(cli1, fname, fname1);
     4739        if (!NT_STATUS_IS_OK(status)) {
     4740                printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", nt_errstr(status));
    43294741                correct = False;
    43304742        } else {
     
    43324744        }
    43334745
    4334         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4335                 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
     4746        status = cli_close(cli1, fnum1);
     4747        if (!NT_STATUS_IS_OK(status)) {
     4748                printf("close - 2 failed (%s)\n", nt_errstr(status));
    43364749                return False;
    43374750        }
     
    43404753        cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    43414754
    4342         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
    4343                                    FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    4344                 printf("Third open failed - %s\n", cli_errstr(cli1));
     4755        status = cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS,
     4756                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
     4757                              FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     4758        if (!NT_STATUS_IS_OK(status)) {
     4759                printf("Third open failed - %s\n", nt_errstr(status));
    43454760                return False;
    43464761        }
     
    43524767
    43534768        if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
    4354                                    FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
     4769                                   FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2, NULL))) {
    43554770                printf("Fourth open failed - %s\n", cli_errstr(cli1));
    43564771                return False;
     
    43684783#endif
    43694784
    4370         if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
    4371                 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1));
     4785        status = cli_rename(cli1, fname, fname1);
     4786        if (!NT_STATUS_IS_OK(status)) {
     4787                printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", nt_errstr(status));
    43724788                correct = False;
    43734789        } else {
     
    43754791        }
    43764792
    4377         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4378                 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
     4793        status = cli_close(cli1, fnum1);
     4794        if (!NT_STATUS_IS_OK(status)) {
     4795                printf("close - 3 failed (%s)\n", nt_errstr(status));
    43794796                return False;
    43804797        }
     
    43854802        /*----*/
    43864803
    4387         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
    4388                                    FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    4389                 printf("Fourth open failed - %s\n", cli_errstr(cli1));
    4390                 return False;
    4391         }
    4392 
    4393         if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
    4394                 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1));
     4804        status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
     4805                              FILE_ATTRIBUTE_NORMAL,
     4806                              FILE_SHARE_READ | FILE_SHARE_WRITE,
     4807                              FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     4808        if (!NT_STATUS_IS_OK(status)) {
     4809                printf("Fourth open failed - %s\n", nt_errstr(status));
     4810                return False;
     4811        }
     4812
     4813        status = cli_rename(cli1, fname, fname1);
     4814        if (!NT_STATUS_IS_OK(status)) {
     4815                printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", nt_errstr(status));
    43954816        } else {
    43964817                printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
     
    43984819        }
    43994820
    4400         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4401                 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
     4821        status = cli_close(cli1, fnum1);
     4822        if (!NT_STATUS_IS_OK(status)) {
     4823                printf("close - 4 failed (%s)\n", nt_errstr(status));
    44024824                return False;
    44034825        }
     
    44084830        /*--*/
    44094831
    4410         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
    4411                                    FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    4412                 printf("Fifth open failed - %s\n", cli_errstr(cli1));
    4413                 return False;
    4414         }
    4415 
    4416         if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) {
    4417                 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n",
    4418                         cli_errstr(cli1));
     4832        status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
     4833                         FILE_ATTRIBUTE_NORMAL,
     4834                         FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
     4835                         FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     4836        if (!NT_STATUS_IS_OK(status)) {
     4837                printf("Fifth open failed - %s\n", nt_errstr(status));
     4838                return False;
     4839        }
     4840
     4841        status = cli_rename(cli1, fname, fname1);
     4842        if (!NT_STATUS_IS_OK(status)) {
     4843                printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n", nt_errstr(status));
    44194844                correct = False;
    44204845        } else {
    4421                 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1));
     4846                printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", nt_errstr(status));
    44224847        }
    44234848
     
    44274852
    44284853        /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
    4429                                    FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) {
     4854                                   FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
     4855                                   FILE_OVERWRITE_IF, 0, 0, &fnum2, NULL))) {
    44304856          printf("Opening original file after rename of open file fails: %s\n",
    44314857              cli_errstr(cli1));
     
    44374863
    44384864        /*--*/
    4439         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4440                 printf("close - 5 failed (%s)\n", cli_errstr(cli1));
     4865        status = cli_close(cli1, fnum1);
     4866        if (!NT_STATUS_IS_OK(status)) {
     4867                printf("close - 5 failed (%s)\n", nt_errstr(status));
    44414868                return False;
    44424869        }
    44434870
    44444871        /* Check that the renamed file has FILE_ATTRIBUTE_ARCHIVE. */
    4445         if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname1, &attr, NULL, NULL))) {
     4872        status = cli_getatr(cli1, fname1, &attr, NULL, NULL);
     4873        if (!NT_STATUS_IS_OK(status)) {
    44464874                printf("getatr on file %s failed - %s ! \n",
    4447                         fname1,
    4448                         cli_errstr(cli1));
     4875                        fname1, nt_errstr(status));
    44494876                correct = False;
    44504877        } else {
     
    44774904        uint16_t fnum;
    44784905        int num_pipes = 0;
     4906        NTSTATUS status;
    44794907
    44804908        printf("starting pipenumber test\n");
     
    44834911        }
    44844912
    4485         cli_sockopt(cli1, sockops);
     4913        smbXcli_conn_set_sockopt(cli1->conn, sockops);
    44864914        while(1) {
    4487                 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
    4488                                    FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0, &fnum))) {
    4489                         printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
     4915                status = cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA,
     4916                                      FILE_ATTRIBUTE_NORMAL,
     4917                                      FILE_SHARE_READ|FILE_SHARE_WRITE,
     4918                                      FILE_OPEN_IF, 0, 0, &fnum, NULL);
     4919                if (!NT_STATUS_IS_OK(status)) {
     4920                        printf("Open of pipe %s failed with error (%s)\n", pipe_name, nt_errstr(status));
    44904921                        break;
    44914922                }
     
    45094940        uint16_t fnum1, fnum2;
    45104941        char buf[20];
    4511         SMB_OFF_T fsize;
     4942        off_t fsize;
    45124943        bool correct = True;
    45134944        char *tmp_path;
     
    45234954        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    45244955
    4525         cli_sockopt(cli1, sockops);
    4526 
    4527         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
    4528                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
    4529                 return False;
    4530         }
    4531 
    4532         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4533                 printf("close2 failed (%s)\n", cli_errstr(cli1));
    4534                 return False;
    4535         }
    4536 
    4537         if (!NT_STATUS_IS_OK(cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0))) {
    4538                 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
    4539                 return False;
    4540         }
    4541 
    4542         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1))) {
    4543                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
     4956        smbXcli_conn_set_sockopt(cli1->conn, sockops);
     4957
     4958        status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
     4959        if (!NT_STATUS_IS_OK(status)) {
     4960                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
     4961                return False;
     4962        }
     4963
     4964        status = cli_close(cli1, fnum1);
     4965        if (!NT_STATUS_IS_OK(status)) {
     4966                printf("close2 failed (%s)\n", nt_errstr(status));
     4967                return False;
     4968        }
     4969
     4970        status = cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0);
     4971        if (!NT_STATUS_IS_OK(status)) {
     4972                printf("cli_setatr failed (%s)\n", nt_errstr(status));
     4973                return False;
     4974        }
     4975
     4976        status = cli_openx(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1);
     4977        if (!NT_STATUS_IS_OK(status)) {
     4978                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
    45444979                return False;
    45454980        }
    45464981
    45474982        /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
    4548         cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
    4549 
    4550         if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
     4983        status = cli_openx(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
     4984
     4985        if (check_error(__LINE__, status, ERRDOS, ERRnoaccess,
    45514986                        NT_STATUS_ACCESS_DENIED)) {
    45524987                printf("correct error code ERRDOS/ERRnoaccess returned\n");
     
    45614996        cli_setatr(cli1, fname, 0, 0);
    45624997
    4563         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1))) {
    4564                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
     4998        status = cli_openx(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1);
     4999        if (!NT_STATUS_IS_OK(status)) {
     5000                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
    45655001                return False;
    45665002        }
    45675003
    45685004        /* This will fail - but the error should be ERRshare. */
    4569         cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
    4570 
    4571         if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
     5005        status = cli_openx(cli1, fname, O_RDWR, DENY_ALL, &fnum2);
     5006
     5007        if (check_error(__LINE__, status, ERRDOS, ERRbadshare,
    45725008                        NT_STATUS_SHARING_VIOLATION)) {
    45735009                printf("correct error code ERRDOS/ERRbadshare returned\n");
    45745010        }
    45755011
    4576         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4577                 printf("close2 failed (%s)\n", cli_errstr(cli1));
     5012        status = cli_close(cli1, fnum1);
     5013        if (!NT_STATUS_IS_OK(status)) {
     5014                printf("close2 failed (%s)\n", nt_errstr(status));
    45785015                return False;
    45795016        }
     
    45845021
    45855022        /* Test truncate open disposition on file opened for read. */
    4586 
    4587         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {
    4588                 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
     5023        status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);
     5024        if (!NT_STATUS_IS_OK(status)) {
     5025                printf("(3) open (1) of %s failed (%s)\n", fname, nt_errstr(status));
    45895026                return False;
    45905027        }
     
    46005037        }
    46015038
    4602         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4603                 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
     5039        status = cli_close(cli1, fnum1);
     5040        if (!NT_STATUS_IS_OK(status)) {
     5041                printf("(3) close1 failed (%s)\n", nt_errstr(status));
    46045042                return False;
    46055043        }
    46065044
    46075045        /* Ensure size == 20. */
    4608         if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) {
    4609                 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
     5046        status = cli_getatr(cli1, fname, NULL, &fsize, NULL);
     5047        if (!NT_STATUS_IS_OK(status)) {
     5048                printf("(3) getatr failed (%s)\n", nt_errstr(status));
    46105049                return False;
    46115050        }
     
    46175056
    46185057        /* Now test if we can truncate a file opened for readonly. */
    4619 
    4620         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1))) {
    4621                 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
    4622                 return False;
    4623         }
    4624 
    4625         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4626                 printf("close2 failed (%s)\n", cli_errstr(cli1));
     5058        status = cli_openx(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1);
     5059        if (!NT_STATUS_IS_OK(status)) {
     5060                printf("(3) open (2) of %s failed (%s)\n", fname, nt_errstr(status));
     5061                return False;
     5062        }
     5063
     5064        status = cli_close(cli1, fnum1);
     5065        if (!NT_STATUS_IS_OK(status)) {
     5066                printf("close2 failed (%s)\n", nt_errstr(status));
    46275067                return False;
    46285068        }
    46295069
    46305070        /* Ensure size == 0. */
    4631         if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) {
    4632                 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
     5071        status = cli_getatr(cli1, fname, NULL, &fsize, NULL);
     5072        if (!NT_STATUS_IS_OK(status)) {
     5073                printf("(3) getatr failed (%s)\n", nt_errstr(status));
    46335074                return False;
    46345075        }
     
    46435084
    46445085        printf("Do ctemp tests\n");
    4645         if (!NT_STATUS_IS_OK(cli_ctemp(cli1, talloc_tos(), "\\", &fnum1, &tmp_path))) {
    4646                 printf("ctemp failed (%s)\n", cli_errstr(cli1));
    4647                 return False;
    4648         }
     5086        status = cli_ctemp(cli1, talloc_tos(), "\\", &fnum1, &tmp_path);
     5087        if (!NT_STATUS_IS_OK(status)) {
     5088                printf("ctemp failed (%s)\n", nt_errstr(status));
     5089                return False;
     5090        }
     5091
    46495092        printf("ctemp gave path %s\n", tmp_path);
    4650         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4651                 printf("close of temp failed (%s)\n", cli_errstr(cli1));
    4652         }
    4653         if (!NT_STATUS_IS_OK(cli_unlink(cli1, tmp_path, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
    4654                 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
     5093        status = cli_close(cli1, fnum1);
     5094        if (!NT_STATUS_IS_OK(status)) {
     5095                printf("close of temp failed (%s)\n", nt_errstr(status));
     5096        }
     5097
     5098        status = cli_unlink(cli1, tmp_path, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     5099        if (!NT_STATUS_IS_OK(status)) {
     5100                printf("unlink of temp failed (%s)\n", nt_errstr(status));
    46555101        }
    46565102
     
    46645110        cli_unlink(cli2, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    46655111
    4666         cli_sockopt(cli2, sockops);
     5112        smbXcli_conn_set_sockopt(cli2->conn, sockops);
    46675113
    46685114        printf("TEST #1 testing 2 non-io opens (no delete)\n");
    4669 
    4670         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
    4671                                    FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    4672                 printf("TEST #1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
    4673                 return False;
    4674         }
    4675 
    4676         if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
    4677                                    FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
    4678                 printf("TEST #1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
    4679                 return False;
    4680         }
    4681 
    4682         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4683                 printf("TEST #1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
    4684                 return False;
    4685         }
    4686         if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
    4687                 printf("TEST #1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
     5115        status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES,
     5116                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
     5117                              FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     5118        if (!NT_STATUS_IS_OK(status)) {
     5119                printf("TEST #1 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
     5120                return False;
     5121        }
     5122
     5123        status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
     5124                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
     5125                              FILE_OPEN_IF, 0, 0, &fnum2, NULL);
     5126        if (!NT_STATUS_IS_OK(status)) {
     5127                printf("TEST #1 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
     5128                return False;
     5129        }
     5130
     5131        status = cli_close(cli1, fnum1);
     5132        if (!NT_STATUS_IS_OK(status)) {
     5133                printf("TEST #1 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
     5134                return False;
     5135        }
     5136
     5137        status = cli_close(cli2, fnum2);
     5138        if (!NT_STATUS_IS_OK(status)) {
     5139                printf("TEST #1 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
    46885140                return False;
    46895141        }
     
    46955147        printf("TEST #2 testing 2 non-io opens (first with delete)\n");
    46965148
    4697         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
    4698                                    FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    4699                 printf("TEST #2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
    4700                 return False;
    4701         }
    4702 
    4703         if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
    4704                                    FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
    4705                 printf("TEST #2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
    4706                 return False;
    4707         }
    4708 
    4709         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4710                 printf("TEST #2 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
    4711                 return False;
    4712         }
    4713         if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
    4714                 printf("TEST #2 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
     5149        status = cli_ntcreate(cli1, fname, 0,
     5150                              DELETE_ACCESS|FILE_READ_ATTRIBUTES,
     5151                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
     5152                              FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     5153        if (!NT_STATUS_IS_OK(status)) {
     5154                printf("TEST #2 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
     5155                return False;
     5156        }
     5157
     5158        status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
     5159                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
     5160                              FILE_OPEN_IF, 0, 0, &fnum2, NULL);
     5161        if (!NT_STATUS_IS_OK(status)) {
     5162                printf("TEST #2 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
     5163                return False;
     5164        }
     5165
     5166        status = cli_close(cli1, fnum1);
     5167        if (!NT_STATUS_IS_OK(status)) {
     5168                printf("TEST #2 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
     5169                return False;
     5170        }
     5171
     5172        status = cli_close(cli2, fnum2);
     5173        if (!NT_STATUS_IS_OK(status)) {
     5174                printf("TEST #2 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
    47155175                return False;
    47165176        }
     
    47225182        printf("TEST #3 testing 2 non-io opens (second with delete)\n");
    47235183
    4724         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
    4725                                    FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    4726                 printf("TEST #3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
    4727                 return False;
    4728         }
    4729 
    4730         if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
    4731                                    FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
    4732                 printf("TEST #3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
    4733                 return False;
    4734         }
    4735 
    4736         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4737                 printf("TEST #3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
    4738                 return False;
    4739         }
    4740         if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
    4741                 printf("TEST #3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
     5184        status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES,
     5185                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
     5186                              FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     5187        if (!NT_STATUS_IS_OK(status)) {
     5188                printf("TEST #3 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
     5189                return False;
     5190        }
     5191
     5192        status = cli_ntcreate(cli2, fname, 0,
     5193                              DELETE_ACCESS|FILE_READ_ATTRIBUTES,
     5194                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
     5195                              FILE_OPEN_IF, 0, 0, &fnum2, NULL);
     5196        if (!NT_STATUS_IS_OK(status)) {
     5197                printf("TEST #3 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
     5198                return False;
     5199        }
     5200
     5201        status = cli_close(cli1, fnum1);
     5202        if (!NT_STATUS_IS_OK(status)) {
     5203                printf("TEST #3 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
     5204                return False;
     5205        }
     5206
     5207        status = cli_close(cli2, fnum2);
     5208        if (!NT_STATUS_IS_OK(status)) {
     5209                printf("TEST #3 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
    47425210                return False;
    47435211        }
     
    47495217        printf("TEST #4 testing 2 non-io opens (both with delete)\n");
    47505218
    4751         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
    4752                                    FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    4753                 printf("TEST #4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
    4754                 return False;
    4755         }
    4756 
    4757         if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
    4758                                    FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) {
    4759                 printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
    4760                 return False;
    4761         }
    4762 
    4763         printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
    4764 
    4765         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4766                 printf("TEST #4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
     5219        status = cli_ntcreate(cli1, fname, 0,
     5220                               DELETE_ACCESS|FILE_READ_ATTRIBUTES,
     5221                               FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
     5222                               FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     5223        if (!NT_STATUS_IS_OK(status)) {
     5224                printf("TEST #4 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
     5225                return False;
     5226        }
     5227
     5228        status = cli_ntcreate(cli2, fname, 0,
     5229                              DELETE_ACCESS|FILE_READ_ATTRIBUTES,
     5230                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
     5231                              FILE_OPEN_IF, 0, 0, &fnum2, NULL);
     5232        if (NT_STATUS_IS_OK(status)) {
     5233                printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status));
     5234                return False;
     5235        }
     5236
     5237        printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation");
     5238
     5239        status = cli_close(cli1, fnum1);
     5240        if (!NT_STATUS_IS_OK(status)) {
     5241                printf("TEST #4 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
    47675242                return False;
    47685243        }
     
    47745249        printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
    47755250
    4776         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
    4777                                    FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    4778                 printf("TEST #5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
    4779                 return False;
    4780         }
    4781 
    4782         if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
    4783                                    FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) {
    4784                 printf("TEST #5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
    4785                 return False;
    4786         }
    4787 
    4788         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4789                 printf("TEST #5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
    4790                 return False;
    4791         }
    4792 
    4793         if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
    4794                 printf("TEST #5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
     5251        status = cli_ntcreate(cli1, fname, 0,
     5252                              DELETE_ACCESS|FILE_READ_ATTRIBUTES,
     5253                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE,
     5254                              FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     5255        if (!NT_STATUS_IS_OK(status)) {
     5256                printf("TEST #5 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
     5257                return False;
     5258        }
     5259
     5260        status = cli_ntcreate(cli2, fname, 0,
     5261                              DELETE_ACCESS|FILE_READ_ATTRIBUTES,
     5262                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE,
     5263                              FILE_OPEN_IF, 0, 0, &fnum2, NULL);
     5264        if (!NT_STATUS_IS_OK(status)) {
     5265                printf("TEST #5 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
     5266                return False;
     5267        }
     5268
     5269        status = cli_close(cli1, fnum1);
     5270        if (!NT_STATUS_IS_OK(status)) {
     5271                printf("TEST #5 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
     5272                return False;
     5273        }
     5274
     5275        status = cli_close(cli2, fnum2);
     5276        if (!NT_STATUS_IS_OK(status)) {
     5277                printf("TEST #5 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
    47955278                return False;
    47965279        }
     
    48025285        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    48035286
    4804         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
    4805                                    FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    4806                 printf("TEST #6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
    4807                 return False;
    4808         }
    4809 
    4810         if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
    4811                                    FILE_SHARE_READ, FILE_OPEN_IF, 0, 0, &fnum2))) {
    4812                 printf("TEST #6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
    4813                 return False;
    4814         }
    4815 
    4816         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4817                 printf("TEST #6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
    4818                 return False;
    4819         }
    4820 
    4821         if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {
    4822                 printf("TEST #6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
     5287        status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA,
     5288                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
     5289                              FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     5290        if (!NT_STATUS_IS_OK(status)) {
     5291                printf("TEST #6 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
     5292                return False;
     5293        }
     5294
     5295        status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES,
     5296                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
     5297                              FILE_OPEN_IF, 0, 0, &fnum2, NULL);
     5298        if (!NT_STATUS_IS_OK(status)) {
     5299                printf("TEST #6 open 2 of %s failed (%s)\n", fname, nt_errstr(status));
     5300                return False;
     5301        }
     5302
     5303        status = cli_close(cli1, fnum1);
     5304        if (!NT_STATUS_IS_OK(status)) {
     5305                printf("TEST #6 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
     5306                return False;
     5307        }
     5308
     5309        status = cli_close(cli2, fnum2);
     5310        if (!NT_STATUS_IS_OK(status)) {
     5311                printf("TEST #6 close 2 of %s failed (%s)\n", fname, nt_errstr(status));
    48235312                return False;
    48245313        }
     
    48305319        cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    48315320
    4832         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
    4833                                    FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    4834                 printf("TEST #7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
    4835                 return False;
    4836         }
    4837 
    4838         if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
    4839                                    FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) {
    4840                 printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
    4841                 return False;
    4842         }
    4843 
    4844         printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
    4845 
    4846         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4847                 printf("TEST #7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
     5321        status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA,
     5322                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
     5323                              FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     5324        if (!NT_STATUS_IS_OK(status)) {
     5325                printf("TEST #7 open 1 of %s failed (%s)\n", fname, nt_errstr(status));
     5326                return False;
     5327        }
     5328
     5329        status = cli_ntcreate(cli2, fname, 0,
     5330                              DELETE_ACCESS|FILE_READ_ATTRIBUTES,
     5331                              FILE_ATTRIBUTE_NORMAL,
     5332                              FILE_SHARE_READ|FILE_SHARE_DELETE,
     5333                              FILE_OPEN_IF, 0, 0, &fnum2, NULL);
     5334        if (NT_STATUS_IS_OK(status)) {
     5335                printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status));
     5336                return False;
     5337        }
     5338
     5339        printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation");
     5340
     5341        status = cli_close(cli1, fnum1);
     5342        if (!NT_STATUS_IS_OK(status)) {
     5343                printf("TEST #7 close 1 of %s failed (%s)\n", fname, nt_errstr(status));
    48485344                return False;
    48495345        }
     
    48565352        status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,
    48575353                                FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
    4858                                 FILE_OVERWRITE_IF, 0, 0, &fnum1);
     5354                                FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
    48595355        if (!NT_STATUS_IS_OK(status)) {
    48605356                printf("TEST #8 open of %s failed (%s)\n", fname, nt_errstr(status));
     
    48645360
    48655361        /* Write to ensure we have to update the file time. */
    4866         status = cli_writeall(cli1, fnum1, 0, (uint8_t *)"TEST DATA\n", 0, 10,
     5362        status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
    48675363                              NULL);
    48685364        if (!NT_STATUS_IS_OK(status)) {
     
    48925388NTSTATUS torture_setup_unix_extensions(struct cli_state *cli)
    48935389{
    4894         uint16 major, minor;
    4895         uint32 caplow, caphigh;
     5390        uint16_t major, minor;
     5391        uint32_t caplow, caphigh;
    48965392        NTSTATUS status;
    48975393
     
    49365432        bool correct = false;
    49375433        NTSTATUS status;
     5434        size_t nread;
     5435        const char *fname_windows = "windows_file";
     5436        uint16_t fnum2 = (uint16_t)-1;
    49385437
    49395438        printf("Starting simple POSIX open test\n");
     
    49435442        }
    49445443
    4945         cli_sockopt(cli1, sockops);
     5444        smbXcli_conn_set_sockopt(cli1->conn, sockops);
    49465445
    49475446        status = torture_setup_unix_extensions(cli1);
     
    49585457        cli_setatr(cli1, sname, 0, 0);
    49595458        cli_posix_unlink(cli1, sname);
     5459        cli_setatr(cli1, fname_windows, 0, 0);
     5460        cli_posix_unlink(cli1, fname_windows);
    49605461
    49615462        /* Create a directory. */
    4962         if (!NT_STATUS_IS_OK(cli_posix_mkdir(cli1, dname, 0777))) {
    4963                 printf("POSIX mkdir of %s failed (%s)\n", dname, cli_errstr(cli1));
     5463        status = cli_posix_mkdir(cli1, dname, 0777);
     5464        if (!NT_STATUS_IS_OK(status)) {
     5465                printf("POSIX mkdir of %s failed (%s)\n", dname, nt_errstr(status));
    49645466                goto out;
    49655467        }
    49665468
    4967         if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1))) {
    4968                 printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1));
     5469        status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL,
     5470                                0600, &fnum1);
     5471        if (!NT_STATUS_IS_OK(status)) {
     5472                printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
    49695473                goto out;
    49705474        }
    49715475
    49725476        /* Test ftruncate - set file size. */
    4973         if (!NT_STATUS_IS_OK(cli_ftruncate(cli1, fnum1, 1000))) {
    4974                 printf("ftruncate failed (%s)\n", cli_errstr(cli1));
     5477        status = cli_ftruncate(cli1, fnum1, 1000);
     5478        if (!NT_STATUS_IS_OK(status)) {
     5479                printf("ftruncate failed (%s)\n", nt_errstr(status));
    49755480                goto out;
    49765481        }
    49775482
    49785483        /* Ensure st_size == 1000 */
    4979         if (!NT_STATUS_IS_OK(cli_posix_stat(cli1, fname, &sbuf))) {
    4980                 printf("stat failed (%s)\n", cli_errstr(cli1));
     5484        status = cli_posix_stat(cli1, fname, &sbuf);
     5485        if (!NT_STATUS_IS_OK(status)) {
     5486                printf("stat failed (%s)\n", nt_errstr(status));
    49815487                goto out;
    49825488        }
     
    49875493        }
    49885494
     5495        /* Ensure st_mode == 0600 */
     5496        if ((sbuf.st_ex_mode & 07777) != 0600) {
     5497                printf("posix_open - bad permissions 0%o != 0600\n",
     5498                                (unsigned int)(sbuf.st_ex_mode & 07777));
     5499                goto out;
     5500        }
     5501
    49895502        /* Test ftruncate - set file size back to zero. */
    4990         if (!NT_STATUS_IS_OK(cli_ftruncate(cli1, fnum1, 0))) {
    4991                 printf("ftruncate failed (%s)\n", cli_errstr(cli1));
     5503        status = cli_ftruncate(cli1, fnum1, 0);
     5504        if (!NT_STATUS_IS_OK(status)) {
     5505                printf("ftruncate failed (%s)\n", nt_errstr(status));
    49925506                goto out;
    49935507        }
    49945508
    4995         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    4996                 printf("close failed (%s)\n", cli_errstr(cli1));
     5509        status = cli_close(cli1, fnum1);
     5510        if (!NT_STATUS_IS_OK(status)) {
     5511                printf("close failed (%s)\n", nt_errstr(status));
    49975512                goto out;
    49985513        }
    49995514
    50005515        /* Now open the file again for read only. */
    5001         if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1))) {
    5002                 printf("POSIX open of %s failed (%s)\n", fname, cli_errstr(cli1));
     5516        status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1);
     5517        if (!NT_STATUS_IS_OK(status)) {
     5518                printf("POSIX open of %s failed (%s)\n", fname, nt_errstr(status));
    50035519                goto out;
    50045520        }
    50055521
    50065522        /* Now unlink while open. */
    5007         if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1, fname))) {
    5008                 printf("POSIX unlink of %s failed (%s)\n", fname, cli_errstr(cli1));
     5523        status = cli_posix_unlink(cli1, fname);
     5524        if (!NT_STATUS_IS_OK(status)) {
     5525                printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status));
    50095526                goto out;
    50105527        }
    50115528
    5012         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    5013                 printf("close(2) failed (%s)\n", cli_errstr(cli1));
     5529        status = cli_close(cli1, fnum1);
     5530        if (!NT_STATUS_IS_OK(status)) {
     5531                printf("close(2) failed (%s)\n", nt_errstr(status));
    50145532                goto out;
    50155533        }
    50165534
    50175535        /* Ensure the file has gone. */
    5018         if (NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1))) {
     5536        status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1);
     5537        if (NT_STATUS_IS_OK(status)) {
    50195538                printf("POSIX open of %s succeeded, should have been deleted.\n", fname);
    50205539                goto out;
     
    50225541
    50235542        /* Create again to test open with O_TRUNC. */
    5024         if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1))) {
    5025                 printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1));
     5543        status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1);
     5544        if (!NT_STATUS_IS_OK(status)) {
     5545                printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
    50265546                goto out;
    50275547        }
    50285548
    50295549        /* Test ftruncate - set file size. */
    5030         if (!NT_STATUS_IS_OK(cli_ftruncate(cli1, fnum1, 1000))) {
    5031                 printf("ftruncate failed (%s)\n", cli_errstr(cli1));
     5550        status = cli_ftruncate(cli1, fnum1, 1000);
     5551        if (!NT_STATUS_IS_OK(status)) {
     5552                printf("ftruncate failed (%s)\n", nt_errstr(status));
    50325553                goto out;
    50335554        }
    50345555
    50355556        /* Ensure st_size == 1000 */
    5036         if (!NT_STATUS_IS_OK(cli_posix_stat(cli1, fname, &sbuf))) {
    5037                 printf("stat failed (%s)\n", cli_errstr(cli1));
     5557        status = cli_posix_stat(cli1, fname, &sbuf);
     5558        if (!NT_STATUS_IS_OK(status)) {
     5559                printf("stat failed (%s)\n", nt_errstr(status));
    50385560                goto out;
    50395561        }
     
    50445566        }
    50455567
    5046         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    5047                 printf("close(2) failed (%s)\n", cli_errstr(cli1));
     5568        status = cli_close(cli1, fnum1);
     5569        if (!NT_STATUS_IS_OK(status)) {
     5570                printf("close(2) failed (%s)\n", nt_errstr(status));
    50485571                goto out;
    50495572        }
    50505573
    50515574        /* Re-open with O_TRUNC. */
    5052         if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_WRONLY|O_TRUNC, 0600, &fnum1))) {
    5053                 printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1));
     5575        status = cli_posix_open(cli1, fname, O_WRONLY|O_TRUNC, 0600, &fnum1);
     5576        if (!NT_STATUS_IS_OK(status)) {
     5577                printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
    50545578                goto out;
    50555579        }
    50565580
    50575581        /* Ensure st_size == 0 */
    5058         if (!NT_STATUS_IS_OK(cli_posix_stat(cli1, fname, &sbuf))) {
    5059                 printf("stat failed (%s)\n", cli_errstr(cli1));
     5582        status = cli_posix_stat(cli1, fname, &sbuf);
     5583        if (!NT_STATUS_IS_OK(status)) {
     5584                printf("stat failed (%s)\n", nt_errstr(status));
    50605585                goto out;
    50615586        }
     
    50665591        }
    50675592
    5068         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    5069                 printf("close failed (%s)\n", cli_errstr(cli1));
     5593        status = cli_close(cli1, fnum1);
     5594        if (!NT_STATUS_IS_OK(status)) {
     5595                printf("close failed (%s)\n", nt_errstr(status));
    50705596                goto out;
    50715597        }
    50725598
    5073         if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1, fname))) {
    5074                 printf("POSIX unlink of %s failed (%s)\n", fname, cli_errstr(cli1));
     5599        status = cli_posix_unlink(cli1, fname);
     5600        if (!NT_STATUS_IS_OK(status)) {
     5601                printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status));
    50755602                goto out;
    50765603        }
    50775604
    5078         if (!NT_STATUS_IS_OK(cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1))) {
     5605        status = cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1);
     5606        if (!NT_STATUS_IS_OK(status)) {
    50795607                printf("POSIX open directory O_RDONLY of %s failed (%s)\n",
    5080                         dname, cli_errstr(cli1));
     5608                        dname, nt_errstr(status));
    50815609                goto out;
    50825610        }
     
    50855613
    50865614        /* What happens when we try and POSIX open a directory for write ? */
    5087         if (NT_STATUS_IS_OK(cli_posix_open(cli1, dname, O_RDWR, 0, &fnum1))) {
     5615        status = cli_posix_open(cli1, dname, O_RDWR, 0, &fnum1);
     5616        if (NT_STATUS_IS_OK(status)) {
    50885617                printf("POSIX open of directory %s succeeded, should have failed.\n", fname);
    50895618                goto out;
    50905619        } else {
    5091                 if (!check_error(__LINE__, cli1, ERRDOS, EISDIR,
     5620                if (!check_both_error(__LINE__, status, ERRDOS, EISDIR,
    50925621                                NT_STATUS_FILE_IS_A_DIRECTORY)) {
    50935622                        goto out;
     
    50965625
    50975626        /* Create the file. */
    5098         if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1))) {
    5099                 printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1));
     5627        status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL,
     5628                                0600, &fnum1);
     5629        if (!NT_STATUS_IS_OK(status)) {
     5630                printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status));
    51005631                goto out;
    51015632        }
    51025633
    51035634        /* Write some data into it. */
    5104         status = cli_writeall(cli1, fnum1, 0, (uint8_t *)"TEST DATA\n", 0, 10,
     5635        status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10,
    51055636                              NULL);
    51065637        if (!NT_STATUS_IS_OK(status)) {
     
    51125643
    51135644        /* Now create a hardlink. */
    5114         if (!NT_STATUS_IS_OK(cli_posix_hardlink(cli1, fname, hname))) {
    5115                 printf("POSIX hardlink of %s failed (%s)\n", hname, cli_errstr(cli1));
     5645        status = cli_posix_hardlink(cli1, fname, hname);
     5646        if (!NT_STATUS_IS_OK(status)) {
     5647                printf("POSIX hardlink of %s failed (%s)\n", hname, nt_errstr(status));
    51165648                goto out;
    51175649        }
    51185650
    51195651        /* Now create a symlink. */
    5120         if (!NT_STATUS_IS_OK(cli_posix_symlink(cli1, fname, sname))) {
    5121                 printf("POSIX symlink of %s failed (%s)\n", sname, cli_errstr(cli1));
     5652        status = cli_posix_symlink(cli1, fname, sname);
     5653        if (!NT_STATUS_IS_OK(status)) {
     5654                printf("POSIX symlink of %s failed (%s)\n", sname, nt_errstr(status));
    51225655                goto out;
    51235656        }
    51245657
    51255658        /* Open the hardlink for read. */
    5126         if (!NT_STATUS_IS_OK(cli_posix_open(cli1, hname, O_RDONLY, 0, &fnum1))) {
    5127                 printf("POSIX open of %s failed (%s)\n", hname, cli_errstr(cli1));
     5659        status = cli_posix_open(cli1, hname, O_RDONLY, 0, &fnum1);
     5660        if (!NT_STATUS_IS_OK(status)) {
     5661                printf("POSIX open of %s failed (%s)\n", hname, nt_errstr(status));
    51285662                goto out;
    51295663        }
    51305664
    5131         if (cli_read(cli1, fnum1, buf, 0, 10) != 10) {
    5132                 printf("POSIX read of %s failed (%s)\n", hname, cli_errstr(cli1));
     5665        status = cli_read(cli1, fnum1, buf, 0, 10, &nread);
     5666        if (!NT_STATUS_IS_OK(status)) {
     5667                printf("POSIX read of %s failed (%s)\n", hname,
     5668                       nt_errstr(status));
     5669                goto out;
     5670        } else if (nread != 10) {
     5671                printf("POSIX read of %s failed. Received %ld, expected %d\n",
     5672                       hname, (unsigned long)nread, 10);
    51335673                goto out;
    51345674        }
     
    51405680
    51415681        /* Do a POSIX lock/unlock. */
    5142         if (!NT_STATUS_IS_OK(cli_posix_lock(cli1, fnum1, 0, 100, true, READ_LOCK))) {
    5143                 printf("POSIX lock failed %s\n", cli_errstr(cli1));
     5682        status = cli_posix_lock(cli1, fnum1, 0, 100, true, READ_LOCK);
     5683        if (!NT_STATUS_IS_OK(status)) {
     5684                printf("POSIX lock failed %s\n", nt_errstr(status));
    51445685                goto out;
    51455686        }
    51465687
    51475688        /* Punch a hole in the locked area. */
    5148         if (!NT_STATUS_IS_OK(cli_posix_unlock(cli1, fnum1, 10, 80))) {
    5149                 printf("POSIX unlock failed %s\n", cli_errstr(cli1));
     5689        status = cli_posix_unlock(cli1, fnum1, 10, 80);
     5690        if (!NT_STATUS_IS_OK(status)) {
     5691                printf("POSIX unlock failed %s\n", nt_errstr(status));
    51505692                goto out;
    51515693        }
     
    51555697        /* Open the symlink for read - this should fail. A POSIX
    51565698           client should not be doing opens on a symlink. */
    5157         if (NT_STATUS_IS_OK(cli_posix_open(cli1, sname, O_RDONLY, 0, &fnum1))) {
     5699        status = cli_posix_open(cli1, sname, O_RDONLY, 0, &fnum1);
     5700        if (NT_STATUS_IS_OK(status)) {
    51585701                printf("POSIX open of %s succeeded (should have failed)\n", sname);
    51595702                goto out;
    51605703        } else {
    5161                 if (!check_error(__LINE__, cli1, ERRDOS, ERRbadpath,
     5704                if (!check_both_error(__LINE__, status, ERRDOS, ERRbadpath,
    51625705                                NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
    51635706                        printf("POSIX open of %s should have failed "
    51645707                                "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
    51655708                                "failed with %s instead.\n",
    5166                                 sname, cli_errstr(cli1));
     5709                                sname, nt_errstr(status));
    51675710                        goto out;
    51685711                }
    51695712        }
    51705713
    5171         if (!NT_STATUS_IS_OK(cli_posix_readlink(cli1, sname, namebuf, sizeof(namebuf)))) {
    5172                 printf("POSIX readlink on %s failed (%s)\n", sname, cli_errstr(cli1));
     5714        status = cli_posix_readlink(cli1, sname, namebuf, sizeof(namebuf));
     5715        if (!NT_STATUS_IS_OK(status)) {
     5716                printf("POSIX readlink on %s failed (%s)\n", sname, nt_errstr(status));
    51735717                goto out;
    51745718        }
     
    51805724        }
    51815725
    5182         if (!NT_STATUS_IS_OK(cli_posix_rmdir(cli1, dname))) {
    5183                 printf("POSIX rmdir failed (%s)\n", cli_errstr(cli1));
     5726        status = cli_posix_rmdir(cli1, dname);
     5727        if (!NT_STATUS_IS_OK(status)) {
     5728                printf("POSIX rmdir failed (%s)\n", nt_errstr(status));
    51845729                goto out;
    51855730        }
     5731
     5732        /* Check directory opens with a specific permission. */
     5733        status = cli_posix_mkdir(cli1, dname, 0700);
     5734        if (!NT_STATUS_IS_OK(status)) {
     5735                printf("POSIX mkdir of %s failed (%s)\n", dname, nt_errstr(status));
     5736                goto out;
     5737        }
     5738
     5739        /* Ensure st_mode == 0700 */
     5740        status = cli_posix_stat(cli1, dname, &sbuf);
     5741        if (!NT_STATUS_IS_OK(status)) {
     5742                printf("stat failed (%s)\n", nt_errstr(status));
     5743                goto out;
     5744        }
     5745
     5746        if ((sbuf.st_ex_mode & 07777) != 0700) {
     5747                printf("posix_mkdir - bad permissions 0%o != 0700\n",
     5748                                (unsigned int)(sbuf.st_ex_mode & 07777));
     5749                goto out;
     5750        }
     5751
     5752        /*
     5753         * Now create a Windows file, and attempt a POSIX unlink.
     5754         * This should fail with a sharing violation but due to:
     5755         *
     5756         * [Bug 9571] Unlink after open causes smbd to panic
     5757         *
     5758         * ensure we've fixed the lock ordering violation.
     5759         */
     5760
     5761        status = cli_ntcreate(cli1, fname_windows, 0,
     5762                        FILE_READ_DATA|FILE_WRITE_DATA, 0,
     5763                        FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
     5764                        FILE_CREATE,
     5765                        0x0, 0x0, &fnum2, NULL);
     5766        if (!NT_STATUS_IS_OK(status)) {
     5767                printf("Windows create of %s failed (%s)\n", fname_windows,
     5768                        nt_errstr(status));
     5769                goto out;
     5770        }
     5771
     5772        /* Now try posix_unlink. */
     5773        status = cli_posix_unlink(cli1, fname_windows);
     5774        if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
     5775                printf("POSIX unlink of %s should fail "
     5776                        "with NT_STATUS_SHARING_VIOLATION "
     5777                        "got %s instead !\n",
     5778                        fname_windows,
     5779                        nt_errstr(status));
     5780                goto out;
     5781        }
     5782
     5783        cli_close(cli1, fnum2);
    51865784
    51875785        printf("Simple POSIX open test passed\n");
     
    51935791                cli_close(cli1, fnum1);
    51945792                fnum1 = (uint16_t)-1;
     5793        }
     5794
     5795        if (fnum2 != (uint16_t)-1) {
     5796                cli_close(cli1, fnum2);
     5797                fnum2 = (uint16_t)-1;
    51955798        }
    51965799
     
    52035806        cli_setatr(cli1, dname, 0, 0);
    52045807        cli_posix_rmdir(cli1, dname);
     5808        cli_setatr(cli1, fname_windows, 0, 0);
     5809        cli_posix_unlink(cli1, fname_windows);
    52055810
    52065811        if (!torture_close_connection(cli1)) {
     
    52115816}
    52125817
    5213 
    5214 static uint32 open_attrs_table[] = {
     5818/*
     5819  Test POSIX and Windows ACLs are rejected on symlinks.
     5820 */
     5821static bool run_acl_symlink_test(int dummy)
     5822{
     5823        static struct cli_state *cli;
     5824        const char *fname = "posix_file";
     5825        const char *sname = "posix_symlink";
     5826        uint16_t fnum = (uint16_t)-1;
     5827        bool correct = false;
     5828        NTSTATUS status;
     5829        char *posix_acl = NULL;
     5830        size_t posix_acl_len = 0;
     5831        char *posix_acl_sym = NULL;
     5832        size_t posix_acl_len_sym = 0;
     5833        struct security_descriptor *sd = NULL;
     5834        struct security_descriptor *sd_sym = NULL;
     5835        TALLOC_CTX *frame = NULL;
     5836
     5837        frame = talloc_stackframe();
     5838
     5839        printf("Starting acl symlink test\n");
     5840
     5841        if (!torture_open_connection(&cli, 0)) {
     5842                TALLOC_FREE(frame);
     5843                return false;
     5844        }
     5845
     5846        smbXcli_conn_set_sockopt(cli->conn, sockops);
     5847
     5848        status = torture_setup_unix_extensions(cli);
     5849        if (!NT_STATUS_IS_OK(status)) {
     5850                TALLOC_FREE(frame);
     5851                return false;
     5852        }
     5853
     5854        cli_setatr(cli, fname, 0, 0);
     5855        cli_posix_unlink(cli, fname);
     5856        cli_setatr(cli, sname, 0, 0);
     5857        cli_posix_unlink(cli, sname);
     5858
     5859        status = cli_ntcreate(cli,
     5860                        fname,
     5861                        0,
     5862                        READ_CONTROL_ACCESS,
     5863                        0,
     5864                        FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
     5865                        FILE_CREATE,
     5866                        0x0,
     5867                        0x0,
     5868                        &fnum,
     5869                        NULL);
     5870
     5871        if (!NT_STATUS_IS_OK(status)) {
     5872                printf("cli_ntcreate of %s failed (%s)\n",
     5873                        fname,
     5874                        nt_errstr(status));
     5875                goto out;
     5876        }
     5877
     5878        /* Get the Windows ACL on the file. */
     5879        status = cli_query_secdesc(cli,
     5880                                fnum,
     5881                                frame,
     5882                                &sd);
     5883        if (!NT_STATUS_IS_OK(status)) {
     5884                printf("cli_query_secdesc failed (%s)\n",
     5885                        nt_errstr(status));
     5886                goto out;
     5887        }
     5888
     5889        /* Get the POSIX ACL on the file. */
     5890        status = cli_posix_getacl(cli,
     5891                                fname,
     5892                                frame,
     5893                                &posix_acl_len,
     5894                                &posix_acl);
     5895
     5896        if (!NT_STATUS_IS_OK(status)) {
     5897                printf("cli_posix_getacl failed (%s)\n",
     5898                        nt_errstr(status));
     5899                goto out;
     5900        }
     5901
     5902        status = cli_close(cli, fnum);
     5903        if (!NT_STATUS_IS_OK(status)) {
     5904                printf("close failed (%s)\n", nt_errstr(status));
     5905                goto out;
     5906        }
     5907        fnum = (uint16_t)-1;
     5908
     5909        /* Now create a symlink. */
     5910        status = cli_posix_symlink(cli, fname, sname);
     5911        if (!NT_STATUS_IS_OK(status)) {
     5912                printf("cli_posix_symlink of %s -> %s failed (%s)\n",
     5913                        sname,
     5914                        fname,
     5915                        nt_errstr(status));
     5916                goto out;
     5917        }
     5918
     5919        /* Open a handle on the symlink. */
     5920        status = cli_ntcreate(cli,
     5921                        sname,
     5922                        0,
     5923                        READ_CONTROL_ACCESS|SEC_STD_WRITE_DAC,
     5924                        0,
     5925                        FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
     5926                        FILE_OPEN,
     5927                        0x0,
     5928                        0x0,
     5929                        &fnum,
     5930                        NULL);
     5931
     5932        if (!NT_STATUS_IS_OK(status)) {
     5933                printf("cli_posix_open of %s failed (%s)\n",
     5934                        sname,
     5935                        nt_errstr(status));
     5936                goto out;
     5937        }
     5938
     5939        /* Get the Windows ACL on the symlink handle. Should fail */
     5940        status = cli_query_secdesc(cli,
     5941                                fnum,
     5942                                frame,
     5943                                &sd_sym);
     5944
     5945        if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
     5946                printf("cli_query_secdesc on a symlink gave %s. "
     5947                        "Should be NT_STATUS_ACCESS_DENIED.\n",
     5948                        nt_errstr(status));
     5949                goto out;
     5950        }
     5951
     5952        /* Get the POSIX ACL on the symlink pathname. Should fail. */
     5953        status = cli_posix_getacl(cli,
     5954                                sname,
     5955                                frame,
     5956                                &posix_acl_len_sym,
     5957                                &posix_acl_sym);
     5958
     5959        if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
     5960                printf("cli_posix_getacl on a symlink gave %s. "
     5961                        "Should be NT_STATUS_ACCESS_DENIED.\n",
     5962                        nt_errstr(status));
     5963                goto out;
     5964        }
     5965
     5966        /* Set the Windows ACL on the symlink handle. Should fail */
     5967        status = cli_set_security_descriptor(cli,
     5968                                fnum,
     5969                                SECINFO_DACL,
     5970                                sd);
     5971
     5972        if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
     5973                printf("cli_query_secdesc on a symlink gave %s. "
     5974                        "Should be NT_STATUS_ACCESS_DENIED.\n",
     5975                        nt_errstr(status));
     5976                goto out;
     5977        }
     5978
     5979        /* Set the POSIX ACL on the symlink pathname. Should fail. */
     5980        status = cli_posix_setacl(cli,
     5981                                sname,
     5982                                posix_acl,
     5983                                posix_acl_len);
     5984
     5985        if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
     5986                printf("cli_posix_getacl on a symlink gave %s. "
     5987                        "Should be NT_STATUS_ACCESS_DENIED.\n",
     5988                        nt_errstr(status));
     5989                goto out;
     5990        }
     5991
     5992        printf("ACL symlink test passed\n");
     5993        correct = true;
     5994
     5995  out:
     5996
     5997        if (fnum != (uint16_t)-1) {
     5998                cli_close(cli, fnum);
     5999                fnum = (uint16_t)-1;
     6000        }
     6001
     6002        cli_setatr(cli, sname, 0, 0);
     6003        cli_posix_unlink(cli, sname);
     6004        cli_setatr(cli, fname, 0, 0);
     6005        cli_posix_unlink(cli, fname);
     6006
     6007        if (!torture_close_connection(cli)) {
     6008                correct = false;
     6009        }
     6010
     6011        TALLOC_FREE(frame);
     6012        return correct;
     6013}
     6014
     6015/*
     6016  Test setting EA's are rejected on symlinks.
     6017 */
     6018static bool run_ea_symlink_test(int dummy)
     6019{
     6020        static struct cli_state *cli;
     6021        const char *fname = "posix_file_ea";
     6022        const char *sname = "posix_symlink_ea";
     6023        const char *ea_name = "testea_name";
     6024        const char *ea_value = "testea_value";
     6025        uint16_t fnum = (uint16_t)-1;
     6026        bool correct = false;
     6027        NTSTATUS status;
     6028        size_t i, num_eas;
     6029        struct ea_struct *eas = NULL;
     6030        TALLOC_CTX *frame = NULL;
     6031
     6032        frame = talloc_stackframe();
     6033
     6034        printf("Starting EA symlink test\n");
     6035
     6036        if (!torture_open_connection(&cli, 0)) {
     6037                TALLOC_FREE(frame);
     6038                return false;
     6039        }
     6040
     6041        smbXcli_conn_set_sockopt(cli->conn, sockops);
     6042
     6043        status = torture_setup_unix_extensions(cli);
     6044        if (!NT_STATUS_IS_OK(status)) {
     6045                TALLOC_FREE(frame);
     6046                return false;
     6047        }
     6048
     6049        cli_setatr(cli, fname, 0, 0);
     6050        cli_posix_unlink(cli, fname);
     6051        cli_setatr(cli, sname, 0, 0);
     6052        cli_posix_unlink(cli, sname);
     6053
     6054        status = cli_ntcreate(cli,
     6055                        fname,
     6056                        0,
     6057                        READ_CONTROL_ACCESS,
     6058                        0,
     6059                        FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
     6060                        FILE_CREATE,
     6061                        0x0,
     6062                        0x0,
     6063                        &fnum,
     6064                        NULL);
     6065
     6066        if (!NT_STATUS_IS_OK(status)) {
     6067                printf("cli_ntcreate of %s failed (%s)\n",
     6068                        fname,
     6069                        nt_errstr(status));
     6070                goto out;
     6071        }
     6072
     6073        status = cli_close(cli, fnum);
     6074        if (!NT_STATUS_IS_OK(status)) {
     6075                printf("close failed (%s)\n",
     6076                        nt_errstr(status));
     6077                goto out;
     6078        }
     6079        fnum = (uint16_t)-1;
     6080
     6081        /* Set an EA on the path. */
     6082        status = cli_set_ea_path(cli,
     6083                                fname,
     6084                                ea_name,
     6085                                ea_value,
     6086                                strlen(ea_value)+1);
     6087
     6088        if (!NT_STATUS_IS_OK(status)) {
     6089                printf("cli_set_ea_path failed (%s)\n",
     6090                        nt_errstr(status));
     6091                goto out;
     6092        }
     6093
     6094        /* Now create a symlink. */
     6095        status = cli_posix_symlink(cli, fname, sname);
     6096        if (!NT_STATUS_IS_OK(status)) {
     6097                printf("cli_posix_symlink of %s -> %s failed (%s)\n",
     6098                        sname,
     6099                        fname,
     6100                        nt_errstr(status));
     6101                goto out;
     6102        }
     6103
     6104        /* Get the EA list on the path. Should return value set. */
     6105        status = cli_get_ea_list_path(cli,
     6106                                fname,
     6107                                frame,
     6108                                &num_eas,
     6109                                &eas);
     6110
     6111        if (!NT_STATUS_IS_OK(status)) {
     6112                printf("cli_get_ea_list_path failed (%s)\n",
     6113                        nt_errstr(status));
     6114                goto out;
     6115        }
     6116
     6117        /* Ensure the EA we set is there. */
     6118        for (i=0; i<num_eas; i++) {
     6119                if (strcmp(eas[i].name, ea_name) == 0 &&
     6120                                eas[i].value.length == strlen(ea_value)+1 &&
     6121                                memcmp(eas[i].value.data,
     6122                                        ea_value,
     6123                                        eas[i].value.length) == 0) {
     6124                        break;
     6125                }
     6126        }
     6127
     6128        if (i == num_eas) {
     6129                printf("Didn't find EA on pathname %s\n",
     6130                        fname);
     6131                goto out;
     6132        }
     6133
     6134        num_eas = 0;
     6135        TALLOC_FREE(eas);
     6136
     6137        /* Get the EA list on the symlink. Should return empty list. */
     6138        status = cli_get_ea_list_path(cli,
     6139                                sname,
     6140                                frame,
     6141                                &num_eas,
     6142                                &eas);
     6143
     6144        if (!NT_STATUS_IS_OK(status)) {
     6145                printf("cli_get_ea_list_path failed (%s)\n",
     6146                        nt_errstr(status));
     6147                goto out;
     6148        }
     6149
     6150        if (num_eas != 0) {
     6151                printf("cli_get_ea_list_path failed (%s)\n",
     6152                        nt_errstr(status));
     6153                goto out;
     6154        }
     6155
     6156        /* Set an EA on the symlink. Should fail. */
     6157        status = cli_set_ea_path(cli,
     6158                                sname,
     6159                                ea_name,
     6160                                ea_value,
     6161                                strlen(ea_value)+1);
     6162
     6163        if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
     6164                printf("cli_set_ea_path on a symlink gave %s. "
     6165                        "Should be NT_STATUS_ACCESS_DENIED.\n",
     6166                        nt_errstr(status));
     6167                goto out;
     6168        }
     6169
     6170        printf("EA symlink test passed\n");
     6171        correct = true;
     6172
     6173  out:
     6174
     6175        if (fnum != (uint16_t)-1) {
     6176                cli_close(cli, fnum);
     6177                fnum = (uint16_t)-1;
     6178        }
     6179
     6180        cli_setatr(cli, sname, 0, 0);
     6181        cli_posix_unlink(cli, sname);
     6182        cli_setatr(cli, fname, 0, 0);
     6183        cli_posix_unlink(cli, fname);
     6184
     6185        if (!torture_close_connection(cli)) {
     6186                correct = false;
     6187        }
     6188
     6189        TALLOC_FREE(frame);
     6190        return correct;
     6191}
     6192
     6193static uint32_t open_attrs_table[] = {
    52156194                FILE_ATTRIBUTE_NORMAL,
    52166195                FILE_ATTRIBUTE_ARCHIVE,
     
    52346213struct trunc_open_results {
    52356214        unsigned int num;
    5236         uint32 init_attr;
    5237         uint32 trunc_attr;
    5238         uint32 result_attr;
     6215        uint32_t init_attr;
     6216        uint32_t trunc_attr;
     6217        uint32_t result_attr;
    52396218};
    52406219
     
    52746253        uint16_t fnum1;
    52756254        bool correct = True;
    5276         uint16 attr;
     6255        uint16_t attr;
    52776256        unsigned int i, j, k, l;
     6257        NTSTATUS status;
    52786258
    52796259        printf("starting open attr test\n");
     
    52836263        }
    52846264
    5285         cli_sockopt(cli1, sockops);
    5286 
    5287         for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
     6265        smbXcli_conn_set_sockopt(cli1->conn, sockops);
     6266
     6267        for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32_t); i++) {
    52886268                cli_setatr(cli1, fname, 0, 0);
    52896269                cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    5290                 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
    5291                                    FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) {
    5292                         printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
     6270
     6271                status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA,
     6272                                       open_attrs_table[i], FILE_SHARE_NONE,
     6273                                       FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL);
     6274                if (!NT_STATUS_IS_OK(status)) {
     6275                        printf("open %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status));
    52936276                        return False;
    52946277                }
    52956278
    5296                 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    5297                         printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
     6279                status = cli_close(cli1, fnum1);
     6280                if (!NT_STATUS_IS_OK(status)) {
     6281                        printf("close %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status));
    52986282                        return False;
    52996283                }
    53006284
    5301                 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
    5302                         if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
    5303                                            FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0, &fnum1))) {
     6285                for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32_t); j++) {
     6286                        status = cli_ntcreate(cli1, fname, 0,
     6287                                              FILE_READ_DATA|FILE_WRITE_DATA,
     6288                                              open_attrs_table[j],
     6289                                              FILE_SHARE_NONE, FILE_OVERWRITE,
     6290                                              0, 0, &fnum1, NULL);
     6291                        if (!NT_STATUS_IS_OK(status)) {
    53046292                                for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
    53056293                                        if (attr_results[l].num == k) {
     
    53076295                                                                k, open_attrs_table[i],
    53086296                                                                open_attrs_table[j],
    5309                                                                 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
     6297                                                                fname, NT_STATUS_V(status), nt_errstr(status));
    53106298                                                correct = False;
    53116299                                        }
    53126300                                }
    5313                                 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
     6301
     6302                                if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
    53146303                                        printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
    53156304                                                        k, open_attrs_table[i], open_attrs_table[j],
    5316                                                         cli_errstr(cli1));
     6305                                                        nt_errstr(status));
    53176306                                        correct = False;
    53186307                                }
     
    53246313                        }
    53256314
    5326                         if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {
    5327                                 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
     6315                        status = cli_close(cli1, fnum1);
     6316                        if (!NT_STATUS_IS_OK(status)) {
     6317                                printf("close %d (2) of %s failed (%s)\n", j, fname, nt_errstr(status));
    53286318                                return False;
    53296319                        }
    53306320
    5331                         if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, &attr, NULL, NULL))) {
    5332                                 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
     6321                        status = cli_getatr(cli1, fname, &attr, NULL, NULL);
     6322                        if (!NT_STATUS_IS_OK(status)) {
     6323                                printf("getatr(2) failed (%s)\n", nt_errstr(status));
    53336324                                return False;
    53346325                        }
     
    53976388        }
    53986389
    5399         cli_sockopt(cli, sockops);
     6390        smbXcli_conn_set_sockopt(cli->conn, sockops);
    54006391
    54016392        srandom(0);
     
    54036394                fstring fname;
    54046395                slprintf(fname, sizeof(fname), "\\%x", (int)random());
    5405                 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum))) {
     6396                if (!NT_STATUS_IS_OK(cli_openx(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum))) {
    54066397                        fprintf(stderr,"Failed to open %s\n", fname);
    54076398                        return False;
     
    54836474        cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    54846475
    5485         if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
    5486                 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
     6476        status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
     6477        if (!NT_STATUS_IS_OK(status)) {
     6478                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
    54876479                return False;
    54886480        }
     
    54976489                printf("ioctl test with device = 0x%x\n", device);
    54986490                for (function=0;function<0x100;function++) {
    5499                         uint32 code = (device<<16) | function;
     6491                        uint32_t code = (device<<16) | function;
    55006492
    55016493                        status = cli_raw_ioctl(cli, fnum, code, &blob);
     
    55256517        uint16_t fnum;
    55266518        bool ret;
     6519        NTSTATUS status;
    55276520
    55286521        if (!torture_open_connection(&cli, 0)) {
     
    55376530        cli_rmdir(cli, "\\chkpath.dir");
    55386531
    5539         if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir"))) {
    5540                 printf("mkdir1 failed : %s\n", cli_errstr(cli));
    5541                 return False;
    5542         }
    5543 
    5544         if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir\\dir2"))) {
    5545                 printf("mkdir2 failed : %s\n", cli_errstr(cli));
    5546                 return False;
    5547         }
    5548 
    5549         if (!NT_STATUS_IS_OK(cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
    5550                 printf("open1 failed (%s)\n", cli_errstr(cli));
     6532        status = cli_mkdir(cli, "\\chkpath.dir");
     6533        if (!NT_STATUS_IS_OK(status)) {
     6534                printf("mkdir1 failed : %s\n", nt_errstr(status));
     6535                return False;
     6536        }
     6537
     6538        status = cli_mkdir(cli, "\\chkpath.dir\\dir2");
     6539        if (!NT_STATUS_IS_OK(status)) {
     6540                printf("mkdir2 failed : %s\n", nt_errstr(status));
     6541                return False;
     6542        }
     6543
     6544        status = cli_openx(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL,
     6545                          DENY_NONE, &fnum);
     6546        if (!NT_STATUS_IS_OK(status)) {
     6547                printf("open1 failed (%s)\n", nt_errstr(status));
    55516548                return False;
    55526549        }
    55536550        cli_close(cli, fnum);
    55546551
    5555         if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir"))) {
    5556                 printf("chkpath1 failed: %s\n", cli_errstr(cli));
     6552        status = cli_chkpath(cli, "\\chkpath.dir");
     6553        if (!NT_STATUS_IS_OK(status)) {
     6554                printf("chkpath1 failed: %s\n", nt_errstr(status));
    55576555                ret = False;
    55586556        }
    55596557
    5560         if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dir2"))) {
    5561                 printf("chkpath2 failed: %s\n", cli_errstr(cli));
     6558        status = cli_chkpath(cli, "\\chkpath.dir\\dir2");
     6559        if (!NT_STATUS_IS_OK(status)) {
     6560                printf("chkpath2 failed: %s\n", nt_errstr(status));
    55626561                ret = False;
    55636562        }
    55646563
    5565         if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\foo.txt"))) {
    5566                 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
     6564        status = cli_chkpath(cli, "\\chkpath.dir\\foo.txt");
     6565        if (!NT_STATUS_IS_OK(status)) {
     6566                ret = check_error(__LINE__, status, ERRDOS, ERRbadpath,
    55676567                                  NT_STATUS_NOT_A_DIRECTORY);
    55686568        } else {
     
    55716571        }
    55726572
    5573         if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\bar.txt"))) {
    5574                 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
     6573        status = cli_chkpath(cli, "\\chkpath.dir\\bar.txt");
     6574        if (!NT_STATUS_IS_OK(status)) {
     6575                ret = check_error(__LINE__, status, ERRDOS, ERRbadfile,
    55756576                                  NT_STATUS_OBJECT_NAME_NOT_FOUND);
    55766577        } else {
    5577                 printf("* chkpath on a non existant file should fail\n");
     6578                printf("* chkpath on a non existent file should fail\n");
    55786579                ret = False;
    55796580        }
    55806581
    5581         if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt"))) {
    5582                 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
     6582        status = cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt");
     6583        if (!NT_STATUS_IS_OK(status)) {
     6584                ret = check_error(__LINE__, status, ERRDOS, ERRbadpath,
    55836585                                  NT_STATUS_OBJECT_PATH_NOT_FOUND);
    55846586        } else {
     
    56186620
    56196621        cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    5620         if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0,
    5621                                    FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
    5622                                    FILE_SHARE_NONE, FILE_OVERWRITE_IF,
    5623                                    0x4044, 0, &fnum))) {
    5624                 printf("open failed - %s\n", cli_errstr(cli));
     6622
     6623        status = cli_ntcreate(cli, fname, 0,
     6624                              FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
     6625                              FILE_SHARE_NONE, FILE_OVERWRITE_IF,
     6626                              0x4044, 0, &fnum, NULL);
     6627        if (!NT_STATUS_IS_OK(status)) {
     6628                printf("open failed - %s\n", nt_errstr(status));
    56256629                talloc_destroy(mem_ctx);
    56266630                return False;
     
    57126716        }
    57136717
    5714         /* Try and delete a non existant EA. */
     6718        /* Try and delete a non existent EA. */
    57156719        status = cli_set_ea_path(cli, fname, "foo", "", 0);
    57166720        if (!NT_STATUS_IS_OK(status)) {
    5717                 printf("deleting non-existant EA 'foo' should succeed. %s\n",
     6721                printf("deleting non-existent EA 'foo' should succeed. %s\n",
    57186722                       nt_errstr(status));
    57196723                correct = False;
     
    57426746        }
    57436747
    5744         cli_sockopt(cli, sockops);
     6748        smbXcli_conn_set_sockopt(cli->conn, sockops);
    57456749
    57466750        cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
     
    57546758                slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
    57556759                if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
    5756                                    FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
     6760                                   FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF,
     6761                                   0, 0, &fnum, NULL))) {
    57576762                        fprintf(stderr,"Failed to open %s\n", fname);
    57586763                        return False;
     
    58186823        NTSTATUS status;
    58196824
    5820         uint32 error;
    5821 
    5822         uint32 flgs2, errnum;
    5823         uint8 errclass;
     6825        uint32_t error;
     6826
     6827        uint32_t errnum;
     6828        uint8_t errclass;
    58246829
    58256830        NTSTATUS nt_status;
     
    58296834        /* NT-Error connection */
    58306835
     6836        disable_spnego = true;
    58316837        if (!(c_nt = open_nbt_connection())) {
    5832                 return False;
    5833         }
    5834 
    5835         c_nt->use_spnego = False;
    5836 
    5837         status = cli_negprot(c_nt);
     6838                disable_spnego = false;
     6839                return False;
     6840        }
     6841        disable_spnego = false;
     6842
     6843        status = smbXcli_negprot(c_nt->conn, c_nt->timeout, PROTOCOL_CORE,
     6844                                 PROTOCOL_NT1);
    58386845
    58396846        if (!NT_STATUS_IS_OK(status)) {
     
    58446851        }
    58456852
    5846         if (!NT_STATUS_IS_OK(cli_session_setup(c_nt, "", "", 0, "", 0,
    5847                                                workgroup))) {
    5848                 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(c_nt));
     6853        status = cli_session_setup(c_nt, "", "", 0, "", 0, workgroup);
     6854        if (!NT_STATUS_IS_OK(status)) {
     6855                printf("%s rejected the NT-error initial session setup (%s)\n",host, nt_errstr(status));
    58496856                return False;
    58506857        }
     
    58526859        /* DOS-Error connection */
    58536860
     6861        disable_spnego = true;
     6862        force_dos_errors = true;
    58546863        if (!(c_dos = open_nbt_connection())) {
    5855                 return False;
    5856         }
    5857 
    5858         c_dos->use_spnego = False;
    5859         c_dos->force_dos_errors = True;
    5860 
    5861         status = cli_negprot(c_dos);
     6864                disable_spnego = false;
     6865                force_dos_errors = false;
     6866                return False;
     6867        }
     6868        disable_spnego = false;
     6869        force_dos_errors = false;
     6870
     6871        status = smbXcli_negprot(c_dos->conn, c_dos->timeout, PROTOCOL_CORE,
     6872                                 PROTOCOL_NT1);
    58626873        if (!NT_STATUS_IS_OK(status)) {
    58636874                printf("%s rejected the DOS-error negprot (%s)\n", host,
     
    58676878        }
    58686879
    5869         if (!NT_STATUS_IS_OK(cli_session_setup(c_dos, "", "", 0, "", 0,
    5870                                                workgroup))) {
    5871                 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(c_dos));
    5872                 return False;
    5873         }
     6880        status = cli_session_setup(c_dos, "", "", 0, "", 0, workgroup);
     6881        if (!NT_STATUS_IS_OK(status)) {
     6882                printf("%s rejected the DOS-error initial session setup (%s)\n",
     6883                        host, nt_errstr(status));
     6884                return False;
     6885        }
     6886
     6887        c_nt->map_dos_errors = false;
     6888        c_dos->map_dos_errors = false;
    58746889
    58756890        for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
    58766891                fstr_sprintf(user, "%X", error);
    58776892
    5878                 if (NT_STATUS_IS_OK(cli_session_setup(c_nt, user,
    5879                                                       password, strlen(password),
    5880                                                       password, strlen(password),
    5881                                                       workgroup))) {
     6893                status = cli_session_setup(c_nt, user,
     6894                                           password, strlen(password),
     6895                                           password, strlen(password),
     6896                                           workgroup);
     6897                if (NT_STATUS_IS_OK(status)) {
    58826898                        printf("/** Session setup succeeded.  This shouldn't happen...*/\n");
    58836899                }
    58846900
    5885                 flgs2 = SVAL(c_nt->inbuf,smb_flg2);
    5886 
    58876901                /* Case #1: 32-bit NT errors */
    5888                 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
    5889                         nt_status = NT_STATUS(IVAL(c_nt->inbuf,smb_rcls));
     6902                if (!NT_STATUS_IS_DOS(status)) {
     6903                        nt_status = status;
    58906904                } else {
    58916905                        printf("/** Dos error on NT connection! (%s) */\n",
    5892                                cli_errstr(c_nt));
     6906                               nt_errstr(status));
    58936907                        nt_status = NT_STATUS(0xc0000000);
    58946908                }
    58956909
    5896                 if (NT_STATUS_IS_OK(cli_session_setup(c_dos, user,
    5897                                                       password, strlen(password),
    5898                                                       password, strlen(password),
    5899                                                       workgroup))) {
     6910                status = cli_session_setup(c_dos, user,
     6911                                           password, strlen(password),
     6912                                           password, strlen(password),
     6913                                           workgroup);
     6914                if (NT_STATUS_IS_OK(status)) {
    59006915                        printf("/** Session setup succeeded.  This shouldn't happen...*/\n");
    59016916                }
    5902                 flgs2 = SVAL(c_dos->inbuf,smb_flg2), errnum;
    59036917
    59046918                /* Case #1: 32-bit NT errors */
    5905                 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
     6919                if (NT_STATUS_IS_DOS(status)) {
    59066920                        printf("/** NT error on DOS connection! (%s) */\n",
    5907                                cli_errstr(c_nt));
     6921                               nt_errstr(status));
    59086922                        errnum = errclass = 0;
    59096923                } else {
    5910                         cli_dos_error(c_dos, &errclass, &errnum);
     6924                        errclass = NT_STATUS_DOS_CLASS(status);
     6925                        errnum = NT_STATUS_DOS_CODE(status);
    59116926                }
    59126927
    59136928                if (NT_STATUS_V(nt_status) != error) {
    59146929                        printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
    5915                                get_nt_error_c_code(NT_STATUS(error)),
    5916                                get_nt_error_c_code(nt_status));
     6930                               get_nt_error_c_code(talloc_tos(), NT_STATUS(error)),
     6931                               get_nt_error_c_code(talloc_tos(), nt_status));
    59176932                }
    59186933
     
    59206935                       smb_dos_err_class(errclass),
    59216936                       smb_dos_err_name(errclass, errnum),
    5922                        get_nt_error_c_code(NT_STATUS(error)));
     6937                       get_nt_error_c_code(talloc_tos(), NT_STATUS(error)));
    59236938        }
    59246939        return True;
     
    59376952        }
    59386953
    5939         if (!NT_STATUS_IS_OK(cli_ntcreate(
    5940                         c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
    5941                         FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
    5942                         FILE_DELETE_ON_CLOSE, 0, &fnum))) {
    5943                 d_printf("open %s failed: %s\n", fname, cli_errstr(c));
     6954        status = cli_ntcreate(c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
     6955                              FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
     6956                              FILE_DELETE_ON_CLOSE, 0, &fnum, NULL);
     6957        if (!NT_STATUS_IS_OK(status)) {
     6958                d_printf("open %s failed: %s\n", fname, nt_errstr(status));
    59446959                return false;
    59456960        }
     
    59576972                }
    59586973
    5959                 d_printf("\r%d   ", (int)c->vuid);
     6974                d_printf("\r%d   ", (int)cli_state_get_uid(c));
    59606975
    59616976                status = cli_ulogoff(c);
     
    59656980                        return false;
    59666981                }
    5967                 c->vuid = 0;
    59686982        }
    59696983
     
    59776991        bool result = true;
    59786992
    5979         subst = talloc_sub_specified(talloc_tos(), str, user, domain, uid, gid);
     6993        subst = talloc_sub_specified(talloc_tos(), str, user, NULL, domain, uid, gid);
    59806994
    59816995        if (strcmp(subst, expected) != 0) {
     
    59947008        uint16_t fnum;
    59957009        NTSTATUS status;
    5996         status = cli_open_recv(req, &fnum);
     7010        status = cli_openx_recv(req, &fnum);
    59977011        TALLOC_FREE(req);
    59987012
    5999         d_printf("cli_open_recv returned %s: %d\n",
     7013        d_printf("cli_openx_recv returned %s: %d\n",
    60007014                 nt_errstr(status),
    60017015                 NT_STATUS_IS_OK(status) ? fnum : -1);
     
    60307044{
    60317045        struct cli_state *cli1;
    6032         struct event_context *evt = event_context_init(NULL);
     7046        struct tevent_context *evt = samba_tevent_context_init(NULL);
    60337047        struct tevent_req *reqs[3], *smbreqs[3];
    60347048        bool done = false;
     
    60417055        }
    60427056
    6043         cli_sockopt(cli1, sockops);
    6044 
    6045         reqs[0] = cli_open_create(talloc_tos(), evt, cli1, "\\test",
     7057        smbXcli_conn_set_sockopt(cli1->conn, sockops);
     7058
     7059        reqs[0] = cli_openx_create(talloc_tos(), evt, cli1, "\\test",
    60467060                                  O_CREAT|O_RDWR, 0, &smbreqs[0]);
    60477061        if (reqs[0] == NULL) return false;
     
    60507064
    60517065        reqs[1] = cli_write_andx_create(talloc_tos(), evt, cli1, 0, 0,
    6052                                         (uint8_t *)str, 0, strlen(str)+1,
     7066                                        (const uint8_t *)str, 0, strlen(str)+1,
    60537067                                        smbreqs, 1, &smbreqs[1]);
    60547068        if (reqs[1] == NULL) return false;
     
    60597073        tevent_req_set_callback(reqs[2], chain1_close_completion, &done);
    60607074
    6061         status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
     7075        status = smb1cli_req_chain_submit(smbreqs, ARRAY_SIZE(smbreqs));
    60627076        if (!NT_STATUS_IS_OK(status)) {
    60637077                return false;
     
    60657079
    60667080        while (!done) {
    6067                 event_loop_once(evt);
     7081                tevent_loop_once(evt);
    60687082        }
    60697083
     
    60917105{
    60927106        struct cli_state *cli1;
    6093         struct event_context *evt = event_context_init(NULL);
     7107        struct tevent_context *evt = samba_tevent_context_init(NULL);
    60947108        struct tevent_req *reqs[2], *smbreqs[2];
    60957109        bool done = false;
     
    60977111
    60987112        printf("starting chain2 test\n");
    6099         status = cli_start_connection(&cli1, global_myname(), host, NULL,
    6100                                       port_to_use, Undefined, 0);
    6101         if (!NT_STATUS_IS_OK(status)) {
    6102                 return False;
    6103         }
    6104 
    6105         cli_sockopt(cli1, sockops);
     7113        status = cli_start_connection(&cli1, lp_netbios_name(), host, NULL,
     7114                                      port_to_use, SMB_SIGNING_DEFAULT, 0);
     7115        if (!NT_STATUS_IS_OK(status)) {
     7116                return False;
     7117        }
     7118
     7119        smbXcli_conn_set_sockopt(cli1->conn, sockops);
    61067120
    61077121        reqs[0] = cli_session_setup_guest_create(talloc_tos(), evt, cli1,
     
    61157129        tevent_req_set_callback(reqs[1], chain2_tcon_completion, &done);
    61167130
    6117         status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));
     7131        status = smb1cli_req_chain_submit(smbreqs, ARRAY_SIZE(smbreqs));
    61187132        if (!NT_STATUS_IS_OK(status)) {
    61197133                return false;
     
    61217135
    61227136        while (!done) {
    6123                 event_loop_once(evt);
     7137                tevent_loop_once(evt);
    61247138        }
    61257139
     
    61767190        uint16_t fnum;
    61777191
    6178         status = cli_ntcreate_recv(subreq, &fnum);
     7192        status = cli_ntcreate_recv(subreq, &fnum, NULL);
    61797193        TALLOC_FREE(subreq);
    6180         if (!NT_STATUS_IS_OK(status)) {
     7194        if (tevent_req_nterror(req, status)) {
    61817195                DEBUG(10, ("cli_ntcreate_recv returned %s\n",
    61827196                           nt_errstr(status)));
    6183                 tevent_req_nterror(req, status);
    61847197                return;
    61857198        }
     
    61997212
    62007213        status = cli_close_recv(subreq);
    6201         if (!NT_STATUS_IS_OK(status)) {
     7214        if (tevent_req_nterror(req, status)) {
    62027215                DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status)));
    6203                 tevent_req_nterror(req, status);
    62047216                return;
    62057217        }
     
    64567468        }
    64577469
    6458         ev = tevent_context_init(talloc_tos());
     7470        ev = samba_tevent_context_init(talloc_tos());
    64597471        if (ev == NULL) {
    64607472                d_printf("tevent_context_init failed\n");
     
    64817493                                      FILE_SHARE_DELETE,
    64827494                                      FILE_OPEN_IF, FILE_DIRECTORY_FILE, 0,
    6483                                       &dnum);
     7495                                      &dnum, NULL);
    64847496
    64857497                if (!NT_STATUS_IS_OK(status)) {
     
    65397551        NTSTATUS status;
    65407552        time_t change_time, access_time, write_time;
    6541         SMB_OFF_T size;
     7553        off_t size;
    65427554        uint16_t mode;
    65437555
     
    65477559        }
    65487560
    6549         cli_sockopt(cli, sockops);
    6550 
    6551         if (!NT_STATUS_IS_OK(cli_ntcreate(
    6552                         cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
    6553                         FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0, &fnum))) {
    6554                 d_printf("open %s failed: %s\n", fname, cli_errstr(cli));
     7561        smbXcli_conn_set_sockopt(cli->conn, sockops);
     7562
     7563        status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
     7564                              FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
     7565                              0, 0, &fnum, NULL);
     7566        if (!NT_STATUS_IS_OK(status)) {
     7567                d_printf("open %s failed: %s\n", fname, nt_errstr(status));
    65557568                return false;
    65567569        }
     
    65657578        d_printf("alt_name: %s\n", alt_name);
    65667579
    6567         if (!NT_STATUS_IS_OK(cli_open(cli, alt_name, O_RDONLY, DENY_NONE, &fnum))) {
    6568                 d_printf("cli_open(%s) failed: %s\n", alt_name,
    6569                          cli_errstr(cli));
     7580        status = cli_openx(cli, alt_name, O_RDONLY, DENY_NONE, &fnum);
     7581        if (!NT_STATUS_IS_OK(status)) {
     7582                d_printf("cli_openx(%s) failed: %s\n", alt_name,
     7583                         nt_errstr(status));
    65707584                return false;
    65717585        }
     
    66087622        double seconds;
    66097623        double kbytes;
     7624        NTSTATUS status;
    66107625
    66117626        printf("starting windows_write test\n");
     
    66147629        }
    66157630
    6616         if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) {
    6617                 printf("open failed (%s)\n", cli_errstr(cli1));
    6618                 return False;
    6619         }
    6620 
    6621         cli_sockopt(cli1, sockops);
     7631        status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
     7632        if (!NT_STATUS_IS_OK(status)) {
     7633                printf("open failed (%s)\n", nt_errstr(status));
     7634                return False;
     7635        }
     7636
     7637        smbXcli_conn_set_sockopt(cli1->conn, sockops);
    66227638
    66237639        start_time = timeval_current();
     
    66267642                uint8_t c = 0;
    66277643                off_t start = i * torture_blocksize;
    6628                 NTSTATUS status;
    66297644                size_t to_pull = torture_blocksize - 1;
    66307645
     
    66597674}
    66607675
     7676static size_t calc_expected_return(struct cli_state *cli, size_t len_requested)
     7677{
     7678        size_t max_pdu = 0x1FFFF;
     7679
     7680        if (cli->server_posix_capabilities & CIFS_UNIX_LARGE_READ_CAP) {
     7681                max_pdu = 0xFFFFFF;
     7682        }
     7683
     7684        if (smb1cli_conn_signing_is_active(cli->conn)) {
     7685                max_pdu = 0x1FFFF;
     7686        }
     7687
     7688        if (smb1cli_conn_encryption_on(cli->conn)) {
     7689                max_pdu = CLI_BUFFER_SIZE;
     7690        }
     7691
     7692        if ((len_requested & 0xFFFF0000) == 0xFFFF0000) {
     7693                len_requested &= 0xFFFF;
     7694        }
     7695
     7696        return MIN(len_requested,
     7697                   max_pdu - (MIN_SMB_SIZE + VWV(12) + 1 /* padding byte */));
     7698}
     7699
     7700static bool check_read_call(struct cli_state *cli,
     7701                            uint16_t fnum,
     7702                            uint8_t *buf,
     7703                            size_t len_requested)
     7704{
     7705        NTSTATUS status;
     7706        struct tevent_req *subreq = NULL;
     7707        ssize_t len_read = 0;
     7708        size_t len_expected = 0;
     7709        struct tevent_context *ev = NULL;
     7710
     7711        ev = samba_tevent_context_init(talloc_tos());
     7712        if (ev == NULL) {
     7713                return false;
     7714        }
     7715
     7716        subreq = cli_read_andx_send(talloc_tos(),
     7717                                    ev,
     7718                                    cli,
     7719                                    fnum,
     7720                                    0,
     7721                                    len_requested);
     7722
     7723        if (!tevent_req_poll_ntstatus(subreq, ev, &status)) {
     7724                return false;
     7725        }
     7726
     7727        status = cli_read_andx_recv(subreq, &len_read, &buf);
     7728        if (!NT_STATUS_IS_OK(status)) {
     7729                d_printf("cli_read_andx_recv failed: %s\n", nt_errstr(status));
     7730                return false;
     7731        }
     7732
     7733        TALLOC_FREE(subreq);
     7734        TALLOC_FREE(ev);
     7735
     7736        len_expected = calc_expected_return(cli, len_requested);
     7737
     7738        if (len_expected > 0x10000 && len_read == 0x10000) {
     7739                /* Windows servers only return a max of 0x10000,
     7740                   doesn't matter if you set CAP_LARGE_READX in
     7741                   the client sessionsetupX call or not. */
     7742                d_printf("Windows server - returned 0x10000 on a read of 0x%x\n",
     7743                        (unsigned int)len_requested);
     7744        } else if (len_read != len_expected) {
     7745                d_printf("read of 0x%x failed: got 0x%x, expected 0x%x\n",
     7746                        (unsigned int)len_requested,
     7747                        (unsigned int)len_read,
     7748                        (unsigned int)len_expected);
     7749                return false;
     7750        } else {
     7751                d_printf("Correct read reply.\n");
     7752        }
     7753
     7754        return true;
     7755}
     7756
     7757/* Test large readX variants. */
     7758static bool large_readx_tests(struct cli_state *cli,
     7759                                uint16_t fnum,
     7760                                uint8_t *buf)
     7761{
     7762        /* A read of 0xFFFF0001 should *always* return 1 byte. */
     7763        if (check_read_call(cli, fnum, buf, 0xFFFF0001) == false) {
     7764                return false;
     7765        }
     7766        /* A read of 0x10000 should return 0x10000 bytes. */
     7767        if (check_read_call(cli, fnum, buf,    0x10000) == false) {
     7768                return false;
     7769        }
     7770        /* A read of 0x10000 should return 0x10001 bytes. */
     7771        if (check_read_call(cli, fnum, buf,    0x10001) == false) {
     7772                return false;
     7773        }
     7774        /* A read of 0x1FFFF - (MIN_SMB_SIZE + VWV(12) should return
     7775           the requested number of bytes. */
     7776        if (check_read_call(cli, fnum, buf, 0x1FFFF - (MIN_SMB_SIZE + VWV(12))) == false) {
     7777                return false;
     7778        }
     7779        /* A read of 1MB should return 1MB bytes (on Samba). */
     7780        if (check_read_call(cli, fnum, buf,   0x100000) == false) {
     7781                return false;
     7782        }
     7783
     7784        if (check_read_call(cli, fnum, buf,    0x20001) == false) {
     7785                return false;
     7786        }
     7787        if (check_read_call(cli, fnum, buf, 0x22000001) == false) {
     7788                return false;
     7789        }
     7790        if (check_read_call(cli, fnum, buf, 0xFFFE0001) == false) {
     7791                return false;
     7792        }
     7793        return true;
     7794}
     7795
     7796static bool run_large_readx(int dummy)
     7797{
     7798        uint8_t *buf = NULL;
     7799        struct cli_state *cli1 = NULL;
     7800        struct cli_state *cli2 = NULL;
     7801        bool correct = false;
     7802        const char *fname = "\\large_readx.dat";
     7803        NTSTATUS status;
     7804        uint16_t fnum1 = UINT16_MAX;
     7805        uint32_t normal_caps = 0;
     7806        size_t file_size = 20*1024*1024;
     7807        TALLOC_CTX *frame = talloc_stackframe();
     7808        size_t i;
     7809        struct {
     7810                const char *name;
     7811                enum smb_signing_setting signing_setting;
     7812                enum protocol_types protocol;
     7813        } runs[] = {
     7814                {
     7815                        .name = "NT1",
     7816                        .signing_setting = SMB_SIGNING_IF_REQUIRED,
     7817                        .protocol = PROTOCOL_NT1,
     7818                },{
     7819                        .name = "NT1 - SIGNING_REQUIRED",
     7820                        .signing_setting = SMB_SIGNING_REQUIRED,
     7821                        .protocol = PROTOCOL_NT1,
     7822                },
     7823        };
     7824
     7825        printf("starting large_readx test\n");
     7826
     7827        if (!torture_open_connection(&cli1, 0)) {
     7828                goto out;
     7829        }
     7830
     7831        normal_caps = smb1cli_conn_capabilities(cli1->conn);
     7832
     7833        if (!(normal_caps & CAP_LARGE_READX)) {
     7834                d_printf("Server doesn't have CAP_LARGE_READX 0x%x\n",
     7835                        (unsigned int)normal_caps);
     7836                goto out;
     7837        }
     7838
     7839        /* Create a file of size 4MB. */
     7840        status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
     7841                        FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
     7842                        0, 0, &fnum1, NULL);
     7843
     7844        if (!NT_STATUS_IS_OK(status)) {
     7845                d_printf("open %s failed: %s\n", fname, nt_errstr(status));
     7846                goto out;
     7847        }
     7848
     7849        /* Write file_size bytes. */
     7850        buf = talloc_zero_array(frame, uint8_t, file_size);
     7851        if (buf == NULL) {
     7852                goto out;
     7853        }
     7854
     7855        status = cli_writeall(cli1,
     7856                              fnum1,
     7857                              0,
     7858                              buf,
     7859                              0,
     7860                              file_size,
     7861                              NULL);
     7862        if (!NT_STATUS_IS_OK(status)) {
     7863                d_printf("cli_writeall failed: %s\n", nt_errstr(status));
     7864                goto out;
     7865        }
     7866
     7867        status = cli_close(cli1, fnum1);
     7868        if (!NT_STATUS_IS_OK(status)) {
     7869                d_printf("cli_close failed: %s\n", nt_errstr(status));
     7870                goto out;
     7871        }
     7872
     7873        fnum1 = UINT16_MAX;
     7874
     7875        for (i=0; i < ARRAY_SIZE(runs); i++) {
     7876                enum smb_signing_setting saved_signing_setting = signing_state;
     7877                uint16_t fnum2 = -1;
     7878
     7879                if (do_encrypt &&
     7880                    (runs[i].signing_setting == SMB_SIGNING_REQUIRED))
     7881                {
     7882                        d_printf("skip[%u] - %s\n", (unsigned)i, runs[i].name);
     7883                        continue;
     7884                }
     7885
     7886                d_printf("run[%u] - %s\n", (unsigned)i, runs[i].name);
     7887
     7888                signing_state = runs[i].signing_setting;
     7889                cli2 = open_nbt_connection();
     7890                signing_state = saved_signing_setting;
     7891                if (cli2 == NULL) {
     7892                        goto out;
     7893                }
     7894
     7895                status = smbXcli_negprot(cli2->conn,
     7896                                         cli2->timeout,
     7897                                         runs[i].protocol,
     7898                                         runs[i].protocol);
     7899                if (!NT_STATUS_IS_OK(status)) {
     7900                        goto out;
     7901                }
     7902
     7903                status = cli_session_setup(cli2,
     7904                                        username,
     7905                                        password,
     7906                                        strlen(password)+1,
     7907                                        password,
     7908                                        strlen(password)+1,
     7909                                        workgroup);
     7910                if (!NT_STATUS_IS_OK(status)) {
     7911                        goto out;
     7912                }
     7913
     7914                status = cli_tree_connect(cli2,
     7915                                        share,
     7916                                        "?????",
     7917                                        password,
     7918                                        strlen(password)+1);
     7919                if (!NT_STATUS_IS_OK(status)) {
     7920                        goto out;
     7921                }
     7922
     7923                cli_set_timeout(cli2, 120000); /* set a really long timeout (2 minutes) */
     7924
     7925                normal_caps = smb1cli_conn_capabilities(cli2->conn);
     7926
     7927                if (!(normal_caps & CAP_LARGE_READX)) {
     7928                        d_printf("Server doesn't have CAP_LARGE_READX 0x%x\n",
     7929                                (unsigned int)normal_caps);
     7930                        goto out;
     7931                }
     7932
     7933                if (do_encrypt) {
     7934                        if (force_cli_encryption(cli2, share) == false) {
     7935                                goto out;
     7936                        }
     7937                } else if (SERVER_HAS_UNIX_CIFS(cli2)) {
     7938                        uint16_t major, minor;
     7939                        uint32_t caplow, caphigh;
     7940
     7941                        status = cli_unix_extensions_version(cli2,
     7942                                                             &major, &minor,
     7943                                                             &caplow, &caphigh);
     7944                        if (!NT_STATUS_IS_OK(status)) {
     7945                                goto out;
     7946                        }
     7947                }
     7948
     7949                status = cli_ntcreate(cli2, fname, 0, FILE_READ_DATA,
     7950                                FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN,
     7951                                0, 0, &fnum2, NULL);
     7952                if (!NT_STATUS_IS_OK(status)) {
     7953                        d_printf("Second open %s failed: %s\n", fname, nt_errstr(status));
     7954                        goto out;
     7955                }
     7956
     7957                /* All reads must return less than file_size bytes. */
     7958                if (!large_readx_tests(cli2, fnum2, buf)) {
     7959                        goto out;
     7960                }
     7961
     7962                status = cli_close(cli2, fnum2);
     7963                if (!NT_STATUS_IS_OK(status)) {
     7964                        d_printf("cli_close failed: %s\n", nt_errstr(status));
     7965                        goto out;
     7966                }
     7967                fnum2 = -1;
     7968
     7969                if (!torture_close_connection(cli2)) {
     7970                        goto out;
     7971                }
     7972                cli2 = NULL;
     7973        }
     7974
     7975        correct = true;
     7976        printf("Success on large_readx test\n");
     7977
     7978  out:
     7979
     7980        if (cli2) {
     7981                if (!torture_close_connection(cli2)) {
     7982                        correct = false;
     7983                }
     7984        }
     7985
     7986        if (cli1) {
     7987                if (fnum1 != UINT16_MAX) {
     7988                        status = cli_close(cli1, fnum1);
     7989                        if (!NT_STATUS_IS_OK(status)) {
     7990                                d_printf("cli_close failed: %s\n", nt_errstr(status));
     7991                        }
     7992                        fnum1 = UINT16_MAX;
     7993                }
     7994
     7995                status = cli_unlink(cli1, fname,
     7996                                    FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     7997                if (!NT_STATUS_IS_OK(status)) {
     7998                        printf("unlink failed (%s)\n", nt_errstr(status));
     7999                }
     8000
     8001                if (!torture_close_connection(cli1)) {
     8002                        correct = false;
     8003                }
     8004        }
     8005
     8006        TALLOC_FREE(frame);
     8007
     8008        printf("finished large_readx test\n");
     8009        return correct;
     8010}
     8011
    66618012static bool run_cli_echo(int dummy)
    66628013{
     
    66688019                return false;
    66698020        }
    6670         cli_sockopt(cli, sockops);
     8021        smbXcli_conn_set_sockopt(cli->conn, sockops);
    66718022
    66728023        status = cli_echo(cli, 5, data_blob_const("hello", 5));
     
    66928043        }
    66938044
    6694         cli_sockopt(cli, sockops);
     8045        smbXcli_conn_set_sockopt(cli->conn, sockops);
    66958046
    66968047        /* Ok - now save then logoff our current user. */
    6697         old_vuid = cli->vuid;
     8048        old_vuid = cli_state_get_uid(cli);
    66988049
    66998050        status = cli_ulogoff(cli);
     
    67058056        }
    67068057
    6707         cli->vuid = old_vuid;
     8058        cli_state_set_uid(cli, old_vuid);
    67088059
    67098060        /* Try an operation. */
     
    67168067        } else {
    67178068                /* Should be bad uid. */
    6718                 if (!check_error(__LINE__, cli, ERRSRV, ERRbaduid,
    6719                                 NT_STATUS_USER_SESSION_DELETED)) {
     8069                if (!check_error(__LINE__, status, ERRSRV, ERRbaduid,
     8070                                 NT_STATUS_USER_SESSION_DELETED)) {
    67208071                        correct = false;
    67218072                        goto out;
     
    67238074        }
    67248075
    6725         old_cnum = cli->cnum;
     8076        old_cnum = cli_state_get_tid(cli);
    67268077
    67278078        /* Now try a SMBtdis with the invald vuid set to zero. */
    6728         cli->vuid = 0;
     8079        cli_state_set_uid(cli, 0);
    67298080
    67308081        /* This should succeed. */
     
    67398090        }
    67408091
    6741         cli->vuid = old_vuid;
    6742         cli->cnum = old_cnum;
     8092        cli_state_set_uid(cli, old_vuid);
     8093        cli_state_set_tid(cli, old_cnum);
    67438094
    67448095        /* This should fail. */
     
    67508101        } else {
    67518102                /* Should be bad tid. */
    6752                 if (!check_error(__LINE__, cli, ERRSRV, ERRinvnid,
     8103                if (!check_error(__LINE__, status, ERRSRV, ERRinvnid,
    67538104                                NT_STATUS_NETWORK_NAME_DELETED)) {
    67548105                        correct = false;
     
    68138164
    68148165        if (strchr(force_shortname_chars, i)) {
    6815                 if (!finfo->short_name[0]) {
     8166                if (!finfo->short_name) {
    68168167                        /* Shortname not created when it should be. */
    68178168                        d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n",
     
    68198170                        s->val = true;
    68208171                }
    6821         } else if (finfo->short_name[0]){
     8172        } else if (finfo->short_name){
    68228173                /* Shortname created when it should not be. */
    68238174                d_printf("(%s) ERROR: Shortname %s was created for file %s\n",
     
    68358186        int i;
    68368187        struct sn_state s;
    6837         char fname[20];
     8188        char fname[40];
     8189        NTSTATUS status;
    68388190
    68398191        printf("starting shortname test\n");
     
    68438195        }
    68448196
    6845         cli_sockopt(cli, sockops);
     8197        smbXcli_conn_set_sockopt(cli->conn, sockops);
    68468198
    68478199        cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli);
     
    68498201        cli_rmdir(cli, "\\shortname");
    68508202
    6851         if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\shortname"))) {
     8203        status = cli_mkdir(cli, "\\shortname");
     8204        if (!NT_STATUS_IS_OK(status)) {
    68528205                d_printf("(%s) cli_mkdir of \\shortname failed: %s\n",
    6853                         __location__, cli_errstr(cli));
     8206                        __location__, nt_errstr(status));
    68548207                correct = false;
    68558208                goto out;
    68568209        }
    68578210
    6858         strlcpy(fname, "\\shortname\\", sizeof(fname));
    6859         strlcat(fname, "test .txt", sizeof(fname));
     8211        if (strlcpy(fname, "\\shortname\\", sizeof(fname)) >= sizeof(fname)) {
     8212                correct = false;
     8213                goto out;
     8214        }
     8215        if (strlcat(fname, "test .txt", sizeof(fname)) >= sizeof(fname)) {
     8216                correct = false;
     8217                goto out;
     8218        }
    68608219
    68618220        s.val = false;
    68628221
    68638222        for (i = 32; i < 128; i++) {
    6864                 NTSTATUS status;
    68658223                uint16_t fnum = (uint16_t)-1;
    68668224
     
    68738231
    68748232                status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
    6875                                    FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum);
     8233                                   FILE_SHARE_READ|FILE_SHARE_WRITE,
     8234                                   FILE_OVERWRITE_IF, 0, 0, &fnum, NULL);
    68768235                if (!NT_STATUS_IS_OK(status)) {
    68778236                        d_printf("(%s) cli_nt_create of %s failed: %s\n",
    6878                                 __location__, fname, cli_errstr(cli));
     8237                                __location__, fname, nt_errstr(status));
    68798238                        correct = false;
    68808239                        goto out;
     
    68838242
    68848243                s.matched = 0;
    6885                 cli_list(cli, "\\shortname\\test*.*", 0, shortname_list_fn,
    6886                         &s);
     8244                status = cli_list(cli, "\\shortname\\test*.*", 0,
     8245                                  shortname_list_fn, &s);
    68878246                if (s.matched != 1) {
    68888247                        d_printf("(%s) failed to list %s: %s\n",
    6889                                 __location__, fname, cli_errstr(cli));
     8248                                __location__, fname, nt_errstr(status));
    68908249                        correct = false;
    68918250                        goto out;
    68928251                }
    6893                 if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) {
     8252
     8253                status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
     8254                if (!NT_STATUS_IS_OK(status)) {
    68948255                        d_printf("(%s) failed to delete %s: %s\n",
    6895                                 __location__, fname, cli_errstr(cli));
     8256                                __location__, fname, nt_errstr(status));
    68968257                        correct = false;
    68978258                        goto out;
     
    69808341        d_printf("defaultNamingContext: %s\n", basedn);
    69818342
    6982         ev = tevent_context_init(talloc_tos());
     8343        ev = samba_tevent_context_init(talloc_tos());
    69838344        if (ev == NULL) {
    69848345                d_printf("tevent_context_init failed\n");
     
    70568417        sleep(3);
    70578418
    7058         status = cli_open(cli, fname, O_RDWR | O_CREAT | O_EXCL,
     8419        status = cli_openx(cli, fname, O_RDWR | O_CREAT | O_EXCL,
    70598420                         DENY_NONE, &fnum);
    70608421        if (!NT_STATUS_IS_OK(status)) {
    7061                 printf("cli_open failed: %s\n", nt_errstr(status));
     8422                printf("cli_openx failed: %s\n", nt_errstr(status));
    70628423                goto out;
    70638424        }
     
    70978458        NTSTATUS status;
    70988459        time_t change_time, access_time, write_time;
    7099         SMB_OFF_T size;
     8460        off_t size;
    71008461        uint16_t mode, fnum;
    71018462        bool ret = true;
     
    71148475        }
    71158476
    7116         cli_qpathinfo1(cli, streamname, &change_time, &access_time, &write_time,
    7117                       &size, &mode);
    7118         status = cli_nt_error(cli);
    7119 
     8477        status = cli_qpathinfo1(cli, streamname, &change_time, &access_time,
     8478                                &write_time, &size, &mode);
    71208479        if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
    71218480                printf("pathinfo returned %s, expected "
     
    71298488                              FILE_READ_ATTRIBUTES|READ_CONTROL_ACCESS,
    71308489                              FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
    7131                               FILE_OPEN, 0, 0, &fnum);
     8490                              FILE_OPEN, 0, 0, &fnum, NULL);
    71328491
    71338492        if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
     
    71978556}
    71988557
     8558static void parse_fn(time_t timeout, DATA_BLOB blob, void *private_data)
     8559{
     8560        return;
     8561}
     8562
    71998563static bool run_local_gencache(int dummy)
    72008564{
     
    72028566        time_t tm;
    72038567        DATA_BLOB blob;
     8568        char v;
     8569        struct memcache *mem;
     8570        int i;
     8571
     8572        mem = memcache_init(NULL, 0);
     8573        if (mem == NULL) {
     8574                d_printf("%s: memcache_init failed\n", __location__);
     8575                return false;
     8576        }
     8577        memcache_set_global(mem);
    72048578
    72058579        if (!gencache_set("foo", "bar", time(NULL) + 1000)) {
     
    72088582        }
    72098583
    7210         if (!gencache_get("foo", NULL, NULL)) {
     8584        if (!gencache_get("foo", NULL, NULL, NULL)) {
    72118585                d_printf("%s: gencache_get() failed\n", __location__);
    72128586                return False;
    72138587        }
    72148588
    7215         if (!gencache_get("foo", &val, &tm)) {
     8589        for (i=0; i<1000000; i++) {
     8590                gencache_parse("foo", parse_fn, NULL);
     8591        }
     8592
     8593        if (!gencache_get("foo", talloc_tos(), &val, &tm)) {
     8594                d_printf("%s: gencache_get() failed\n", __location__);
     8595                return False;
     8596        }
     8597        TALLOC_FREE(val);
     8598
     8599        if (!gencache_get("foo", talloc_tos(), &val, &tm)) {
    72168600                d_printf("%s: gencache_get() failed\n", __location__);
    72178601                return False;
     
    72218605                d_printf("%s: gencache_get() returned %s, expected %s\n",
    72228606                         __location__, val, "bar");
    7223                 SAFE_FREE(val);
    7224                 return False;
    7225         }
    7226 
    7227         SAFE_FREE(val);
     8607                TALLOC_FREE(val);
     8608                return False;
     8609        }
     8610
     8611        TALLOC_FREE(val);
    72288612
    72298613        if (!gencache_del("foo")) {
     
    72378621        }
    72388622
    7239         if (gencache_get("foo", &val, &tm)) {
     8623        if (gencache_get("foo", talloc_tos(), &val, &tm)) {
    72408624                d_printf("%s: gencache_get() on deleted entry "
    72418625                         "succeeded\n", __location__);
     
    72518635        }
    72528636
    7253         if (!gencache_get_data_blob("foo", &blob, NULL, NULL)) {
     8637        if (!gencache_get_data_blob("foo", talloc_tos(), &blob, NULL, NULL)) {
    72548638                d_printf("%s: gencache_get_data_blob() failed\n", __location__);
    72558639                return False;
     
    72758659        }
    72768660
    7277         if (gencache_get_data_blob("foo", &blob, NULL, NULL)) {
     8661        if (gencache_get_data_blob("foo", talloc_tos(), &blob, NULL, NULL)) {
    72788662                d_printf("%s: gencache_get_data_blob() on deleted entry "
    72798663                         "succeeded\n", __location__);
    72808664                return False;
     8665        }
     8666
     8667        v = 1;
     8668        blob.data = (uint8_t *)&v;
     8669        blob.length = sizeof(v);
     8670
     8671        if (!gencache_set_data_blob("blob", &blob, tm)) {
     8672                d_printf("%s: gencache_set_data_blob() failed\n",
     8673                         __location__);
     8674                return false;
     8675        }
     8676        if (gencache_get("blob", talloc_tos(), &val, &tm)) {
     8677                d_printf("%s: gencache_get succeeded\n", __location__);
     8678                return false;
    72818679        }
    72828680
     
    72918689        bool ret = false;
    72928690        NTSTATUS status;
    7293 
    7294         rec = db->fetch_locked(db, db, string_tdb_data(key));
     8691        TDB_DATA dbvalue;
     8692
     8693        rec = dbwrap_fetch_locked(db, db, string_tdb_data(key));
    72958694        if (rec == NULL) {
    72968695                d_fprintf(stderr, "fetch_locked failed\n");
    72978696                goto done;
    72988697        }
    7299         status = rec->store(rec, data, 0);
     8698        status = dbwrap_record_store(rec, data, 0);
    73008699        if (!NT_STATUS_IS_OK(status)) {
    73018700                d_fprintf(stderr, "store failed: %s\n", nt_errstr(status));
     
    73048703        TALLOC_FREE(rec);
    73058704
    7306         rec = db->fetch_locked(db, db, string_tdb_data(key));
     8705        rec = dbwrap_fetch_locked(db, db, string_tdb_data(key));
    73078706        if (rec == NULL) {
    73088707                d_fprintf(stderr, "second fetch_locked failed\n");
    73098708                goto done;
    73108709        }
    7311         if ((rec->value.dsize != data.dsize)
    7312             || (memcmp(rec->value.dptr, data.dptr, data.dsize) != 0)) {
     8710
     8711        dbvalue = dbwrap_record_get_value(rec);
     8712        if ((dbvalue.dsize != data.dsize)
     8713            || (memcmp(dbvalue.dptr, data.dptr, data.dsize) != 0)) {
    73138714                d_fprintf(stderr, "Got wrong data back\n");
    73148715                goto done;
     
    73218722}
    73228723
     8724static int local_rbtree_traverse_read(struct db_record *rec, void *private_data)
     8725{
     8726        int *count2 = (int *)private_data;
     8727        (*count2)++;
     8728        return 0;
     8729}
     8730
     8731static int local_rbtree_traverse_delete(struct db_record *rec, void *private_data)
     8732{
     8733        int *count2 = (int *)private_data;
     8734        (*count2)++;
     8735        dbwrap_record_delete(rec);
     8736        return 0;
     8737}
     8738
    73238739static bool run_local_rbtree(int dummy)
    73248740{
     
    73268742        bool ret = false;
    73278743        int i;
     8744        NTSTATUS status;
     8745        int count = 0;
     8746        int count2 = 0;
    73288747
    73298748        db = db_open_rbt(NULL);
     
    73688787
    73698788        ret = true;
     8789        count = 0; count2 = 0;
     8790        status = dbwrap_traverse_read(db, local_rbtree_traverse_read,
     8791                                      &count2, &count);
     8792        printf("%s: read1: %d %d, %s\n", __func__, count, count2, nt_errstr(status));
     8793        if ((count != count2) || (count != 1000)) {
     8794                ret = false;
     8795        }
     8796        count = 0; count2 = 0;
     8797        status = dbwrap_traverse(db, local_rbtree_traverse_delete,
     8798                                 &count2, &count);
     8799        printf("%s: delete: %d %d, %s\n", __func__, count, count2, nt_errstr(status));
     8800        if ((count != count2) || (count != 1000)) {
     8801                ret = false;
     8802        }
     8803        count = 0; count2 = 0;
     8804        status = dbwrap_traverse_read(db, local_rbtree_traverse_read,
     8805                                      &count2, &count);
     8806        printf("%s: read2: %d %d, %s\n", __func__, count, count2, nt_errstr(status));
     8807        if ((count != count2) || (count != 0)) {
     8808                ret = false;
     8809        }
    73708810
    73718811 done:
     
    73748814}
    73758815
     8816
     8817/*
     8818  local test for character set functions
     8819
     8820  This is a very simple test for the functionality in convert_string_error()
     8821 */
     8822static bool run_local_convert_string(int dummy)
     8823{
     8824        TALLOC_CTX *tmp_ctx = talloc_new(NULL);
     8825        const char *test_strings[2] = { "March", "M\303\244rz" };
     8826        char dst[7];
     8827        int i;
     8828
     8829        for (i=0; i<2; i++) {
     8830                const char *str = test_strings[i];
     8831                int len = strlen(str);
     8832                size_t converted_size;
     8833                bool ret;
     8834
     8835                memset(dst, 'X', sizeof(dst));
     8836
     8837                /* first try with real source length */
     8838                ret = convert_string_error(CH_UNIX, CH_UTF8,
     8839                                           str, len,
     8840                                           dst, sizeof(dst),
     8841                                           &converted_size);
     8842                if (ret != true) {
     8843                        d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
     8844                        goto failed;
     8845                }
     8846
     8847                if (converted_size != len) {
     8848                        d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
     8849                                  str, len, (int)converted_size);
     8850                        goto failed;
     8851                }
     8852
     8853                if (strncmp(str, dst, converted_size) != 0) {
     8854                        d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
     8855                        goto failed;
     8856                }
     8857
     8858                if (strlen(str) != converted_size) {
     8859                        d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
     8860                                  (int)strlen(str), (int)converted_size);
     8861                        goto failed;
     8862                }
     8863
     8864                if (dst[converted_size] != 'X') {
     8865                        d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
     8866                        goto failed;
     8867                }
     8868
     8869                /* now with srclen==-1, this causes the nul to be
     8870                 * converted too */
     8871                ret = convert_string_error(CH_UNIX, CH_UTF8,
     8872                                           str, -1,
     8873                                           dst, sizeof(dst),
     8874                                           &converted_size);
     8875                if (ret != true) {
     8876                        d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str);
     8877                        goto failed;
     8878                }
     8879
     8880                if (converted_size != len+1) {
     8881                        d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n",
     8882                                  str, len, (int)converted_size);
     8883                        goto failed;
     8884                }
     8885
     8886                if (strncmp(str, dst, converted_size) != 0) {
     8887                        d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst);
     8888                        goto failed;
     8889                }
     8890
     8891                if (len+1 != converted_size) {
     8892                        d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str,
     8893                                  len+1, (int)converted_size);
     8894                        goto failed;
     8895                }
     8896
     8897                if (dst[converted_size] != 'X') {
     8898                        d_fprintf(stderr, "Expected no termination of '%s'\n", dst);
     8899                        goto failed;
     8900                }
     8901
     8902        }
     8903
     8904
     8905        TALLOC_FREE(tmp_ctx);
     8906        return true;
     8907failed:
     8908        TALLOC_FREE(tmp_ctx);
     8909        return false;
     8910}
     8911
     8912
    73768913struct talloc_dict_test {
    73778914        int content;
     
    73898926        struct talloc_dict *dict;
    73908927        struct talloc_dict_test *t;
    7391         int key, count;
     8928        int key, count, res;
     8929        bool ok;
    73928930
    73938931        dict = talloc_dict_init(talloc_tos());
     
    74038941        key = 1;
    74048942        t->content = 1;
    7405         if (!talloc_dict_set(dict, data_blob_const(&key, sizeof(key)), t)) {
     8943        ok = talloc_dict_set(dict, data_blob_const(&key, sizeof(key)), &t);
     8944        if (!ok) {
    74068945                return false;
    74078946        }
    74088947
    74098948        count = 0;
    7410         if (talloc_dict_traverse(dict, talloc_dict_traverse_fn, &count) != 0) {
     8949        res = talloc_dict_traverse(dict, talloc_dict_traverse_fn, &count);
     8950        if (res == -1) {
    74118951                return false;
    74128952        }
    74138953
    74148954        if (count != 1) {
     8955                return false;
     8956        }
     8957
     8958        if (count != res) {
    74158959                return false;
    74168960        }
     
    74388982        if (string_to_sid(&sid, "S-1-5-32-545-abc")) {
    74398983                printf("allowing S-1-5-32-545-abc\n");
     8984                return false;
     8985        }
     8986        if (string_to_sid(&sid, "S-300-5-32-545")) {
     8987                printf("allowing S-300-5-32-545\n");
     8988                return false;
     8989        }
     8990        if (string_to_sid(&sid, "S-1-0xfffffffffffffe-32-545")) {
     8991                printf("allowing S-1-0xfffffffffffffe-32-545\n");
     8992                return false;
     8993        }
     8994        if (string_to_sid(&sid, "S-1-0xffffffffffff-5294967297-545")) {
     8995                printf("allowing S-1-0xffffffffffff-5294967297-545\n");
     8996                return false;
     8997        }
     8998        if (!string_to_sid(&sid, "S-1-0xfffffffffffe-32-545")) {
     8999                printf("could not parse S-1-0xfffffffffffe-32-545\n");
    74409000                return false;
    74419001        }
     
    74529012}
    74539013
     9014static bool sid_to_string_test(const char *expected) {
     9015        char *str;
     9016        bool res = true;
     9017        struct dom_sid sid;
     9018
     9019        if (!string_to_sid(&sid, expected)) {
     9020                printf("could not parse %s\n", expected);
     9021                return false;
     9022        }
     9023
     9024        str = dom_sid_string(NULL, &sid);
     9025        if (strcmp(str, expected)) {
     9026                printf("Comparison failed (%s != %s)\n", str, expected);
     9027                res = false;
     9028        }
     9029        TALLOC_FREE(str);
     9030        return res;
     9031}
     9032
     9033static bool run_local_sid_to_string(int dummy) {
     9034        if (!sid_to_string_test("S-1-0xffffffffffff-1-1-1-1-1-1-1-1-1-1-1-1"))
     9035                return false;
     9036        if (!sid_to_string_test("S-1-545"))
     9037                return false;
     9038        if (!sid_to_string_test("S-255-3840-1-1-1-1"))
     9039                return false;
     9040        return true;
     9041}
     9042
    74549043static bool run_local_binary_to_sid(int dummy) {
    74559044        struct dom_sid *sid = talloc(NULL, struct dom_sid);
    7456         static const char good_binary_sid[] = {
     9045        static const uint8_t good_binary_sid[] = {
    74579046                0x1, /* revision number */
    74589047                15, /* num auths */
     
    74759064        };
    74769065
    7477         static const char long_binary_sid[] = {
     9066        static const uint8_t long_binary_sid[] = {
    74789067                0x1, /* revision number */
    74799068                15, /* num auths */
     
    74999088        };
    75009089
    7501         static const char long_binary_sid2[] = {
     9090        static const uint8_t long_binary_sid2[] = {
    75029091                0x1, /* revision number */
    75039092                32, /* num auths */
     
    75919180        }
    75929181        else {
    7593                 if (StrCaseCmp(stype, ":$DATA") != 0) {
     9182                if (strcasecmp_m(stype, ":$DATA") != 0) {
    75949183                        /*
    75959184                         * If there is an explicit stream type, so far we only
     
    76269215                 * upper-case the type field
    76279216                 */
    7628                 strupper_m(strchr_m(stream, ':')+1);
     9217                (void)strupper_m(strchr_m(stream, ':')+1);
    76299218        }
    76309219
     
    77339322        bool ret = false;
    77349323
    7735         cache = memcache_init(NULL, 100);
     9324        cache = memcache_init(NULL, sizeof(void *) == 8 ? 200 : 100);
    77369325
    77379326        if (cache == NULL) {
     
    78259414}
    78269415
    7827 static bool run_local_wbclient(int dummy)
    7828 {
    7829         struct event_context *ev;
     9416static bool run_wbclient_multi_ping(int dummy)
     9417{
     9418        struct tevent_context *ev;
    78309419        struct wb_context **wb_ctx;
    78319420        struct winbindd_request wb_req;
     
    78359424        BlockSignals(True, SIGPIPE);
    78369425
    7837         ev = tevent_context_init_byname(talloc_tos(), "epoll");
     9426        ev = tevent_context_init(talloc_tos());
    78389427        if (ev == NULL) {
    78399428                goto fail;
    78409429        }
    78419430
    7842         wb_ctx = TALLOC_ARRAY(ev, struct wb_context *, nprocs);
     9431        wb_ctx = talloc_array(ev, struct wb_context *, torture_nprocs);
    78439432        if (wb_ctx == NULL) {
    78449433                goto fail;
     
    78489437        wb_req.cmd = WINBINDD_PING;
    78499438
    7850         d_printf("nprocs=%d, numops=%d\n", (int)nprocs, (int)torture_numops);
    7851 
    7852         for (i=0; i<nprocs; i++) {
     9439        d_printf("torture_nprocs=%d, numops=%d\n", (int)torture_nprocs, (int)torture_numops);
     9440
     9441        for (i=0; i<torture_nprocs; i++) {
    78539442                wb_ctx[i] = wb_context_init(ev, NULL);
    78549443                if (wb_ctx[i] == NULL) {
     
    78689457        i = 0;
    78699458
    7870         while (i < nprocs * torture_numops) {
    7871                 event_loop_once(ev);
     9459        while (i < torture_nprocs * torture_numops) {
     9460                tevent_loop_once(ev);
    78729461        }
    78739462
     
    79049493        int i;
    79059494
    7906         ev = event_context_init(frame);
     9495        ev = samba_tevent_context_init(frame);
    79079496        if (ev == NULL) {
    79089497                goto fail;
     
    79189507                }
    79199508                tevent_req_set_callback(reqs[i], getaddrinfo_finished,
    7920                                         (void *)names[i]);
     9509                                        discard_const_p(void, names[i]));
    79219510        }
    79229511
     
    79349523{
    79359524        struct db_record *rec;
    7936         uint32_t *val;
     9525        uint32_t val;
    79379526        bool ret = false;
    79389527        NTSTATUS status;
    7939 
    7940         rec = db->fetch_locked(db, db, string_term_tdb_data("transtest"));
     9528        TDB_DATA value;
     9529
     9530        rec = dbwrap_fetch_locked(db, db, string_term_tdb_data("transtest"));
    79419531        if (rec == NULL) {
    79429532                printf(__location__ "fetch_lock failed\n");
     
    79449534        }
    79459535
    7946         if (rec->value.dsize != sizeof(uint32_t)) {
     9536        value = dbwrap_record_get_value(rec);
     9537
     9538        if (value.dsize != sizeof(uint32_t)) {
    79479539                printf(__location__ "value.dsize = %d\n",
    7948                        (int)rec->value.dsize);
     9540                       (int)value.dsize);
    79499541                goto fail;
    79509542        }
    79519543
    7952         val = (uint32_t *)rec->value.dptr;
    7953         *val += 1;
    7954 
    7955         status = rec->store(rec, make_tdb_data((uint8_t *)val,
    7956                                                sizeof(uint32_t)),
    7957                             0);
     9544        memcpy(&val, value.dptr, sizeof(val));
     9545        val += 1;
     9546
     9547        status = dbwrap_record_store(
     9548                rec, make_tdb_data((uint8_t *)&val, sizeof(val)), 0);
    79589549        if (!NT_STATUS_IS_OK(status)) {
    79599550                printf(__location__ "store failed: %s\n",
     
    79759566        uint32_t initial;
    79769567        int res;
     9568        TDB_DATA value;
    79779569
    79789570        db = db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT,
    7979                      O_RDWR|O_CREAT, 0600);
     9571                     O_RDWR|O_CREAT, 0600, DBWRAP_LOCK_ORDER_1,
     9572                     DBWRAP_FLAG_NONE);
    79809573        if (db == NULL) {
    79819574                printf("Could not open transtest.db\n");
     
    79839576        }
    79849577
    7985         res = db->transaction_start(db);
    7986         if (res == -1) {
     9578        res = dbwrap_transaction_start(db);
     9579        if (res != 0) {
    79879580                printf(__location__ "transaction_start failed\n");
    79889581                return false;
    79899582        }
    79909583
    7991         rec = db->fetch_locked(db, db, string_term_tdb_data("transtest"));
     9584        rec = dbwrap_fetch_locked(db, db, string_term_tdb_data("transtest"));
    79929585        if (rec == NULL) {
    79939586                printf(__location__ "fetch_lock failed\n");
     
    79959588        }
    79969589
    7997         if (rec->value.dptr == NULL) {
     9590        value = dbwrap_record_get_value(rec);
     9591
     9592        if (value.dptr == NULL) {
    79989593                initial = 0;
    7999                 status = rec->store(
     9594                status = dbwrap_record_store(
    80009595                        rec, make_tdb_data((uint8_t *)&initial,
    80019596                                           sizeof(initial)),
     
    80109605        TALLOC_FREE(rec);
    80119606
    8012         res = db->transaction_commit(db);
    8013         if (res == -1) {
     9607        res = dbwrap_transaction_commit(db);
     9608        if (res != 0) {
    80149609                printf(__location__ "transaction_commit failed\n");
    80159610                return false;
     
    80209615                int i;
    80219616
    8022                 res = db->transaction_start(db);
    8023                 if (res == -1) {
     9617                res = dbwrap_transaction_start(db);
     9618                if (res != 0) {
    80249619                        printf(__location__ "transaction_start failed\n");
    80259620                        break;
    80269621                }
    80279622
    8028                 if (!dbwrap_fetch_uint32(db, "transtest", &val)) {
    8029                         printf(__location__ "dbwrap_fetch_uint32 failed\n");
     9623                status = dbwrap_fetch_uint32_bystring(db, "transtest", &val);
     9624                if (!NT_STATUS_IS_OK(status)) {
     9625                        printf(__location__ "dbwrap_fetch_uint32 failed: %s\n",
     9626                               nt_errstr(status));
    80309627                        break;
    80319628                }
     
    80379634                }
    80389635
    8039                 if (!dbwrap_fetch_uint32(db, "transtest", &val2)) {
    8040                         printf(__location__ "dbwrap_fetch_uint32 failed\n");
     9636                status = dbwrap_fetch_uint32_bystring(db, "transtest", &val2);
     9637                if (!NT_STATUS_IS_OK(status)) {
     9638                        printf(__location__ "dbwrap_fetch_uint32 failed: %s\n",
     9639                               nt_errstr(status));
    80419640                        break;
    80429641                }
     
    80509649                printf("val2=%d\r", val2);
    80519650
    8052                 res = db->transaction_commit(db);
    8053                 if (res == -1) {
     9651                res = dbwrap_transaction_commit(db);
     9652                if (res != 0) {
    80549653                        printf(__location__ "transaction_commit failed\n");
    80559654                        break;
     
    81019700        TALLOC_FREE(ev);
    81029701        return result;
     9702}
     9703
     9704static bool run_local_hex_encode_buf(int dummy)
     9705{
     9706        char buf[17];
     9707        uint8_t src[8];
     9708        int i;
     9709
     9710        for (i=0; i<sizeof(src); i++) {
     9711                src[i] = i;
     9712        }
     9713        hex_encode_buf(buf, src, sizeof(src));
     9714        if (strcmp(buf, "0001020304050607") != 0) {
     9715                return false;
     9716        }
     9717        hex_encode_buf(buf, NULL, 0);
     9718        if (buf[0] != '\0') {
     9719                return false;
     9720        }
     9721        return true;
     9722}
     9723
     9724static const char *remove_duplicate_addrs2_test_strings_vector[] = {
     9725        "0.0.0.0",
     9726        "::0",
     9727        "1.2.3.1",
     9728        "0.0.0.0",
     9729        "0.0.0.0",
     9730        "1.2.3.2",
     9731        "1.2.3.3",
     9732        "1.2.3.4",
     9733        "1.2.3.5",
     9734        "::0",
     9735        "1.2.3.6",
     9736        "1.2.3.7",
     9737        "::0",
     9738        "::0",
     9739        "::0",
     9740        "1.2.3.8",
     9741        "1.2.3.9",
     9742        "1.2.3.10",
     9743        "1.2.3.11",
     9744        "1.2.3.12",
     9745        "1.2.3.13",
     9746        "1001:1111:1111:1000:0:1111:1111:1111",
     9747        "1.2.3.1",
     9748        "1.2.3.2",
     9749        "1.2.3.3",
     9750        "1.2.3.12",
     9751        "::0",
     9752        "::0"
     9753};
     9754
     9755static const char *remove_duplicate_addrs2_test_strings_result[] = {
     9756        "1.2.3.1",
     9757        "1.2.3.2",
     9758        "1.2.3.3",
     9759        "1.2.3.4",
     9760        "1.2.3.5",
     9761        "1.2.3.6",
     9762        "1.2.3.7",
     9763        "1.2.3.8",
     9764        "1.2.3.9",
     9765        "1.2.3.10",
     9766        "1.2.3.11",
     9767        "1.2.3.12",
     9768        "1.2.3.13",
     9769        "1001:1111:1111:1000:0:1111:1111:1111"
     9770};
     9771
     9772static bool run_local_remove_duplicate_addrs2(int dummy)
     9773{
     9774        struct ip_service test_vector[28];
     9775        int count, i;
     9776
     9777        /* Construct the sockaddr_storage test vector. */
     9778        for (i = 0; i < 28; i++) {
     9779                struct addrinfo hints;
     9780                struct addrinfo *res = NULL;
     9781                int ret;
     9782
     9783                memset(&hints, '\0', sizeof(hints));
     9784                hints.ai_flags = AI_NUMERICHOST;
     9785                ret = getaddrinfo(remove_duplicate_addrs2_test_strings_vector[i],
     9786                                NULL,
     9787                                &hints,
     9788                                &res);
     9789                if (ret) {
     9790                        fprintf(stderr, "getaddrinfo failed on [%s]\n",
     9791                                remove_duplicate_addrs2_test_strings_vector[i]);
     9792                        return false;
     9793                }
     9794                memset(&test_vector[i], '\0', sizeof(test_vector[i]));
     9795                memcpy(&test_vector[i].ss,
     9796                        res->ai_addr,
     9797                        res->ai_addrlen);
     9798                freeaddrinfo(res);
     9799        }
     9800
     9801        count = remove_duplicate_addrs2(test_vector, i);
     9802
     9803        if (count != 14) {
     9804                fprintf(stderr, "count wrong (%d) should be 14\n",
     9805                        count);
     9806                return false;
     9807        }
     9808
     9809        for (i = 0; i < count; i++) {
     9810                char addr[INET6_ADDRSTRLEN];
     9811
     9812                print_sockaddr(addr, sizeof(addr), &test_vector[i].ss);
     9813
     9814                if (strcmp(addr, remove_duplicate_addrs2_test_strings_result[i]) != 0) {
     9815                        fprintf(stderr, "mismatch on [%d] [%s] [%s]\n",
     9816                                i,
     9817                                addr,
     9818                                remove_duplicate_addrs2_test_strings_result[i]);
     9819                        return false;
     9820                }
     9821        }
     9822
     9823        printf("run_local_remove_duplicate_addrs2: success\n");
     9824        return true;
    81039825}
    81049826
     
    81689890        synccount = 0;
    81699891
    8170         child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
     9892        child_status = (volatile pid_t *)anonymous_shared_allocate(sizeof(pid_t)*torture_nprocs);
    81719893        if (!child_status) {
    81729894                printf("Failed to setup shared memory\n");
     
    81749896        }
    81759897
    8176         child_status_out = (volatile bool *)shm_setup(sizeof(bool)*nprocs);
     9898        child_status_out = (volatile bool *)anonymous_shared_allocate(sizeof(bool)*torture_nprocs);
    81779899        if (!child_status_out) {
    81789900                printf("Failed to setup result status shared memory\n");
     
    81809902        }
    81819903
    8182         for (i = 0; i < nprocs; i++) {
     9904        for (i = 0; i < torture_nprocs; i++) {
    81839905                child_status[i] = 0;
    81849906                child_status_out[i] = True;
     
    81879909        start = timeval_current();
    81889910
    8189         for (i=0;i<nprocs;i++) {
     9911        for (i=0;i<torture_nprocs;i++) {
    81909912                procnum = i;
    81919913                if (fork() == 0) {
     
    82159937        do {
    82169938                synccount = 0;
    8217                 for (i=0;i<nprocs;i++) {
     9939                for (i=0;i<torture_nprocs;i++) {
    82189940                        if (child_status[i]) synccount++;
    82199941                }
    8220                 if (synccount == nprocs) break;
     9942                if (synccount == torture_nprocs) break;
    82219943                smb_msleep(10);
    82229944        } while (timeval_elapsed(&start) < 30);
    82239945
    8224         if (synccount != nprocs) {
    8225                 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
     9946        if (synccount != torture_nprocs) {
     9947                printf("FAILED TO START %d CLIENTS (started %d)\n", torture_nprocs, synccount);
    82269948                *result = False;
    82279949                return timeval_elapsed(&start);
     
    82319953        start = timeval_current();
    82329954
    8233         for (i=0;i<nprocs;i++) {
     9955        for (i=0;i<torture_nprocs;i++) {
    82349956                child_status[i] = 0;
    82359957        }
    82369958
    8237         printf("%d clients started\n", nprocs);
    8238 
    8239         for (i=0;i<nprocs;i++) {
     9959        printf("%d clients started\n", torture_nprocs);
     9960
     9961        for (i=0;i<torture_nprocs;i++) {
    82409962                while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ;
    82419963        }
     
    82439965        printf("\n");
    82449966
    8245         for (i=0;i<nprocs;i++) {
     9967        for (i=0;i<torture_nprocs;i++) {
    82469968                if (!child_status_out[i]) {
    82479969                        *result = False;
     
    828010002        {"OPLOCK1",  run_oplock1, 0},
    828110003        {"OPLOCK2",  run_oplock2, 0},
    8282         {"OPLOCK3",  run_oplock3, 0},
    828310004        {"OPLOCK4",  run_oplock4, 0},
    828410005        {"DIR",  run_dirtest, 0},
     
    829610017        {"POSIX", run_simple_posix_open_test, 0},
    829710018        {"POSIX-APPEND", run_posix_append, 0},
     10019        {"POSIX-SYMLINK-ACL", run_acl_symlink_test, 0},
     10020        {"POSIX-SYMLINK-EA", run_ea_symlink_test, 0},
     10021        {"CASE-INSENSITIVE-CREATE", run_case_insensitive_create, 0},
    829810022        {"ASYNC-ECHO", run_async_echo, 0},
    829910023        { "UID-REGRESSION-TEST", run_uid_regression_test, 0},
     
    830610030        {"RENAME", run_rename, 0},
    830710031        {"DELETE", run_deletetest, 0},
     10032        {"WILDDELETE", run_wild_deletetest, 0},
    830810033        {"DELETE-LN", run_deletetest_ln, 0},
    830910034        {"PROPERTIES", run_properties, 0},
     
    832510050        { "CHAIN1", run_chain1, 0},
    832610051        { "CHAIN2", run_chain2, 0},
     10052        { "CHAIN3", run_chain3, 0},
    832710053        { "WINDOWS-WRITE", run_windows_write, 0},
     10054        { "LARGE_READX", run_large_readx, 0},
     10055        { "NTTRANS-CREATE", run_nttrans_create, 0},
     10056        { "NTTRANS-FSCTL", run_nttrans_fsctl, 0},
    832810057        { "CLI_ECHO", run_cli_echo, 0},
    832910058        { "GETADDRINFO", run_getaddrinfo_send, 0},
     
    833110060        { "STREAMERROR", run_streamerror },
    833210061        { "NOTIFY-BENCH", run_notify_bench },
     10062        { "NOTIFY-BENCH2", run_notify_bench2 },
     10063        { "NOTIFY-BENCH3", run_notify_bench3 },
    833310064        { "BAD-NBT-SESSION", run_bad_nbt_session },
    833410065        { "SMB-ANY-CONNECT", run_smb_any_connect },
     10066        { "NOTIFY-ONLINE", run_notify_online },
     10067        { "SMB2-BASIC", run_smb2_basic },
     10068        { "SMB2-NEGPROT", run_smb2_negprot },
     10069        { "SMB2-SESSION-RECONNECT", run_smb2_session_reconnect },
     10070        { "SMB2-TCON-DEPENDENCE", run_smb2_tcon_dependence },
     10071        { "SMB2-MULTI-CHANNEL", run_smb2_multi_channel },
     10072        { "SMB2-SESSION-REAUTH", run_smb2_session_reauth },
     10073        { "CLEANUP1", run_cleanup1 },
     10074        { "CLEANUP2", run_cleanup2 },
     10075        { "CLEANUP3", run_cleanup3 },
     10076        { "CLEANUP4", run_cleanup4 },
     10077        { "OPLOCK-CANCEL", run_oplock_cancel },
    833510078        { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
    833610079        { "LOCAL-GENCACHE", run_local_gencache, 0},
    833710080        { "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
     10081        { "LOCAL-DBWRAP-WATCH1", run_dbwrap_watch1, 0 },
     10082        { "LOCAL-MESSAGING-READ1", run_messaging_read1, 0 },
     10083        { "LOCAL-MESSAGING-READ2", run_messaging_read2, 0 },
     10084        { "LOCAL-MESSAGING-READ3", run_messaging_read3, 0 },
     10085        { "LOCAL-MESSAGING-READ4", run_messaging_read4, 0 },
     10086        { "LOCAL-MESSAGING-FDPASS1", run_messaging_fdpass1, 0 },
     10087        { "LOCAL-MESSAGING-FDPASS2", run_messaging_fdpass2, 0 },
     10088        { "LOCAL-MESSAGING-FDPASS2a", run_messaging_fdpass2a, 0 },
     10089        { "LOCAL-MESSAGING-FDPASS2b", run_messaging_fdpass2b, 0 },
    833810090        { "LOCAL-BASE64", run_local_base64, 0},
    833910091        { "LOCAL-RBTREE", run_local_rbtree, 0},
    834010092        { "LOCAL-MEMCACHE", run_local_memcache, 0},
    834110093        { "LOCAL-STREAM-NAME", run_local_stream_name, 0},
    8342         { "LOCAL-WBCLIENT", run_local_wbclient, 0},
     10094        { "WBCLIENT-MULTI-PING", run_wbclient_multi_ping, 0},
    834310095        { "LOCAL-string_to_sid", run_local_string_to_sid, 0},
     10096        { "LOCAL-sid_to_string", run_local_sid_to_string, 0},
    834410097        { "LOCAL-binary_to_sid", run_local_binary_to_sid, 0},
    834510098        { "LOCAL-DBTRANS", run_local_dbtrans, 0},
    834610099        { "LOCAL-TEVENT-SELECT", run_local_tevent_select, 0},
    8347         { "LOCAL-TDB-OPENER", run_local_tdb_opener, 0 },
    8348         { "LOCAL-TDB-WRITER", run_local_tdb_writer, 0 },
     10100        { "LOCAL-CONVERT-STRING", run_local_convert_string, 0},
     10101        { "LOCAL-CONV-AUTH-INFO", run_local_conv_auth_info, 0},
     10102        { "LOCAL-sprintf_append", run_local_sprintf_append, 0},
     10103        { "LOCAL-hex_encode_buf", run_local_hex_encode_buf, 0},
     10104        { "LOCAL-IDMAP-TDB-COMMON", run_idmap_tdb_common_test, 0},
     10105        { "LOCAL-remove_duplicate_addrs2", run_local_remove_duplicate_addrs2, 0},
     10106        { "local-tdb-opener", run_local_tdb_opener, 0 },
     10107        { "local-tdb-writer", run_local_tdb_writer, 0 },
     10108        { "LOCAL-DBWRAP-CTDB", run_local_dbwrap_ctdb, 0 },
     10109        { "LOCAL-BENCH-PTHREADPOOL", run_bench_pthreadpool, 0 },
     10110        { "qpathinfo-bufsize", run_qpathinfo_bufsize, 0 },
    834910111        {NULL, NULL, 0}};
    835010112
    8351 
     10113/*
     10114 * dummy function to satisfy linker dependency
     10115 */
     10116struct tevent_context *winbind_event_context(void);
     10117struct tevent_context *winbind_event_context(void)
     10118{
     10119        return NULL;
     10120}
    835210121
    835310122/****************************************************************************
     
    841410183        printf("\t-d debuglevel\n");
    841510184        printf("\t-U user%%pass\n");
    8416         printf("\t-k               use kerberos\n");
     10185        printf("\t-k                    use kerberos\n");
    841710186        printf("\t-N numprocs\n");
    841810187        printf("\t-n my_netbios_name\n");
     
    842210191        printf("\t-m maximum protocol\n");
    842310192        printf("\t-L use oplocks\n");
    8424         printf("\t-c CLIENT.TXT   specify client load file for NBENCH\n");
     10193        printf("\t-c CLIENT.TXT         specify client load file for NBENCH\n");
    842510194        printf("\t-A showall\n");
    842610195        printf("\t-p port\n");
    842710196        printf("\t-s seed\n");
    842810197        printf("\t-b unclist_filename   specify multiple shares for multiple connections\n");
     10198        printf("\t-f filename           filename to test\n");
     10199        printf("\t-e                    encrypt\n");
    842910200        printf("\n\n");
    843010201
     
    845910230        setup_logging("smbtorture", DEBUG_STDOUT);
    846010231
    8461         load_case_tables();
     10232        smb_init_locale();
     10233        fault_setup();
    846210234
    846310235        if (is_default_dyn_CONFIGFILE()) {
     
    846610238                }
    846710239        }
    8468         lp_load(get_dyn_CONFIGFILE(),True,False,False,True);
     10240        lp_load_global(get_dyn_CONFIGFILE());
    846910241        load_interfaces();
    847010242
     
    850410276        fstrcpy(workgroup, lp_workgroup());
    850510277
    8506         while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:")) != EOF) {
     10278        while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:f:"))
     10279               != EOF) {
    850710280                switch (opt) {
    850810281                case 'p':
     
    851610289                        break;
    851710290                case 'm':
    8518                         max_protocol = interpret_protocol(optarg, max_protocol);
     10291                        lp_set_cmdline("client max protocol", optarg);
    851910292                        break;
    852010293                case 'N':
    8521                         nprocs = atoi(optarg);
     10294                        torture_nprocs = atoi(optarg);
    852210295                        break;
    852310296                case 'o':
     
    857310346                        torture_blocksize = atoi(optarg);
    857410347                        break;
     10348                case 'f':
     10349                        test_filename = SMB_STRDUP(optarg);
     10350                        break;
    857510351                default:
    857610352                        printf("Unknown option %c (%d)\n", (char)opt, opt);
     
    858610362
    858710363        while (!gotpass) {
    8588                 p = getpass("Password:");
    8589                 if (p) {
    8590                         fstrcpy(password, p);
     10364                char pwd[256] = {0};
     10365                int rc;
     10366
     10367                rc = samba_getpass("Password:", pwd, sizeof(pwd), false, false);
     10368                if (rc == 0) {
     10369                        fstrcpy(password, pwd);
    859110370                        gotpass = 1;
    859210371                }
  • vendor/current/source3/torture/utable.c

    r740 r988  
    3333        int c, len, fd;
    3434        int chars_allowed=0, alt_allowed=0;
    35         uint8 valid[0x10000];
     35        uint8_t valid[0x10000];
    3636
    3737        printf("starting utable\n");
     
    4747
    4848        for (c=1; c < 0x10000; c++) {
     49                size_t size = 0;
    4950                char *p;
    5051
     
    5253                fstrcpy(fname, "\\utable\\x");
    5354                p = fname+strlen(fname);
    54                 len = convert_string(CH_UTF16LE, CH_UNIX,
     55                if (!convert_string(CH_UTF16LE, CH_UNIX,
    5556                                     &c2, 2,
    56                                      p, sizeof(fname)-strlen(fname), True);
     57                                     p, sizeof(fname)-strlen(fname),&size)) {
     58                        d_printf("convert_string %s failed !\n", fname);
     59                        continue;
     60                }
     61                len = size;
    5762                p[len] = 0;
    5863                fstrcat(fname,"_a_long_extension");
    5964
    60                 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC,
     65                if (!NT_STATUS_IS_OK(cli_openx(cli, fname, O_RDWR | O_CREAT | O_TRUNC,
    6166                                DENY_NONE, &fnum))) {
    6267                        continue;
     
    108113        smb_ucs2_t c2;
    109114        char *p;
    110         int len;
     115        size_t len = 0;
    111116
    112117        fstrcpy(fname, "\\utable\\");
     
    114119        SSVAL(&c2, 0, c);
    115120
    116         len = convert_string(CH_UTF16LE, CH_UNIX,
     121        if (!convert_string(CH_UTF16LE, CH_UNIX,
    117122                             &c2, 2,
    118                              p, sizeof(fname)-strlen(fname), True);
     123                             p, sizeof(fname)-strlen(fname), &len)) {
     124                d_printf("form_name: convert string %s failed\n",
     125                        fname);
     126                return NULL;
     127        }
    119128        p[len] = 0;
    120129        return fname;
     
    145154
    146155        for (c=1; c < 0x10000; c++) {
    147                 SMB_OFF_T size;
     156                off_t size;
    148157
    149158                if (c == '.' || c == '\\') continue;
     
    156165                                          FILE_ATTRIBUTE_NORMAL,
    157166                                          FILE_SHARE_NONE,
    158                                           FILE_OPEN_IF, 0, 0, &fnum))) {
     167                                          FILE_OPEN_IF, 0, 0, &fnum, NULL))) {
    159168                        printf("Failed to create file with char %04x\n", c);
    160169                        continue;
     
    180189                        }
    181190
    182                         cli_read(cli, fnum, (char *)c2, 0, size);
     191                        cli_read(cli, fnum, (char *)c2, 0, size, NULL);
    183192                        printf("%04x: ", c);
    184193                        equiv[c][0] = c;
  • vendor/current/source3/torture/vfstest.c

    r740 r988  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   VFS module tester
     
    1414   the Free Software Foundation; either version 3 of the License, or
    1515   (at your option) any later version.
    16    
     16
    1717   This program is distributed in the hope that it will be useful,
    1818   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1919   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2020   GNU General Public License for more details.
    21    
     21
    2222   You should have received a copy of the GNU General Public License
    2323   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2626#include "includes.h"
    2727#include "smbd/smbd.h"
     28#include "smbd/globals.h"
    2829#include "popt_common.h"
    2930#include "vfstest.h"
    3031#include "../libcli/smbreadline/smbreadline.h"
     32#include "auth.h"
     33#include "serverid.h"
     34#include "messages.h"
     35#include "libcli/security/security.h"
     36#include "lib/smbd_shim.h"
     37#include "system/filesys.h"
    3138
    3239/* List to hold groups of commands */
     
    3643} *cmd_list;
    3744
     45/* shall we do talloc_report after each command? */
     46static int memreports = 0;
     47
    3848/****************************************************************************
    3949handle completion of commands for readline
     
    4656        struct cmd_list *commands = cmd_list;
    4757
    48         if (start) 
     58        if (start)
    4959                return NULL;
    5060
    5161        /* make sure we have a list of valid commands */
    52         if (!commands) 
     62        if (!commands)
    5363                return NULL;
    5464
     
    5969        if (!matches[0]) return NULL;
    6070
    61         while (commands && count < MAX_COMPLETIONS-1) 
     71        while (commands && count < MAX_COMPLETIONS-1)
    6272        {
    6373                if (!commands->cmd_set)
    6474                        break;
    65                
     75
    6676                for (i=0; commands->cmd_set[i].name; i++)
    6777                {
    6878                        if ((strncmp(text, commands->cmd_set[i].name, strlen(text)) == 0) &&
    69                                 commands->cmd_set[i].fn) 
     79                                commands->cmd_set[i].fn)
    7080                        {
    7181                                matches[count] = SMB_STRDUP(commands->cmd_set[i].name);
    72                                 if (!matches[count]) 
     82                                if (!matches[count])
    7383                                        return NULL;
    7484                                count++;
    7585                        }
    7686                }
    77                
     87
    7888                commands = commands->next;
    79                
    8089        }
    8190
     
    100109                *p = '\0';
    101110        command = talloc_strdup(ctx, *cmdstr);
    102         *cmdstr = p;
     111
     112        /* Pass back the remaining cmdstring
     113           (a trailing delimiter ";" does also work),
     114           or NULL at last cmdstring.
     115        */
     116        *cmdstr = p ? p + 1 : p;
    103117
    104118        return command;
     
    114128        }
    115129
    116         if (!lp_load(argv[1], False, True, False, True)) {
     130        if (!lp_load_with_shares(argv[1])) {
    117131                printf("Error loading \"%s\"\n", argv[1]);
    118132                return NT_STATUS_OK;
     
    122136        return NT_STATUS_OK;
    123137}
    124        
     138
    125139/* Display help on commands */
    126140static NTSTATUS cmd_help(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
     
    140154        if (argc == 2) {
    141155                for (tmp = cmd_list; tmp; tmp = tmp->next) {
    142                        
     156
    143157                        tmp_set = tmp->cmd_set;
    144158
     
    263277{
    264278        const char *p = cmd;
    265         char **argv = NULL;
     279        const char **argv = NULL;
    266280        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
    267281        char *buf;
    268282        TALLOC_CTX *mem_ctx = talloc_stackframe();
    269         int argc = 0, i;
     283        int argc = 0;
    270284
    271285        /* Count number of arguments first time through the loop then
     
    275289        while(next_token_talloc(mem_ctx, &p, &buf, " ")) {
    276290                if (argv) {
    277                         argv[argc] = SMB_STRDUP(buf);
     291                        argv[argc] = talloc_strdup(argv, buf);
    278292                }
    279293                argc++;
     
    283297                /* Create argument list */
    284298
    285                 argv = SMB_MALLOC_ARRAY(char *, argc);
    286                 memset(argv, 0, sizeof(char *) * argc);
    287 
    288                 if (!argv) {
     299                argv = talloc_zero_array(mem_ctx, const char *, argc);
     300                if (argv == NULL) {
    289301                        fprintf(stderr, "out of memory\n");
    290302                        result = NT_STATUS_NO_MEMORY;
     
    313325
    314326        if (argv) {
    315                 for (i = 0; i < argc; i++)
    316                         SAFE_FREE(argv[i]);
    317 
    318                 SAFE_FREE(argv);
    319         }
    320 
     327                char **_argv = discard_const_p(char *, argv);
     328                TALLOC_FREE(_argv);
     329                argv = NULL;
     330        }
     331
     332        if (memreports != 0) {
     333                talloc_report_full(mem_ctx, stdout);
     334        }
    321335        TALLOC_FREE(mem_ctx);
    322336        return result;
     
    402416}
    403417
    404 void exit_server(const char *reason)
     418static void vfstest_exit_server(const char * const reason) _NORETURN_;
     419static void vfstest_exit_server(const char * const reason)
    405420{
    406421        DEBUG(3,("Server exit (%s)\n", (reason ? reason : "")));
     
    408423}
    409424
    410 void exit_server_cleanly(const char *const reason)
    411 {
    412         exit_server("normal exit");
    413 }
    414 
    415 int last_message = -1;
    416 
    417 struct event_context *smbd_event_context(void)
    418 {
    419         static struct event_context *ctx;
    420 
    421         if (!ctx && !(ctx = event_context_init(NULL))) {
    422                 smb_panic("Could not init smbd event context\n");
    423         }
    424         return ctx;
     425static void vfstest_exit_server_cleanly(const char * const reason) _NORETURN_;
     426static void vfstest_exit_server_cleanly(const char * const reason)
     427{
     428        vfstest_exit_server("normal exit");
     429}
     430
     431struct smb_request *vfstest_get_smbreq(TALLOC_CTX *mem_ctx,
     432                                       struct vfs_state *vfs)
     433{
     434        struct smb_request *result;
     435        uint8_t *inbuf;
     436
     437        result = talloc_zero(mem_ctx, struct smb_request);
     438        if (result == NULL) {
     439                return NULL;
     440        }
     441        result->sconn = vfs->conn->sconn;
     442        result->mid = ++vfs->mid;
     443
     444        inbuf = talloc_array(result, uint8_t, smb_size);
     445        if (inbuf == NULL) {
     446                goto fail;
     447        }
     448        SSVAL(inbuf, smb_mid, result->mid);
     449        smb_setlen(inbuf, smb_size-4);
     450        result->inbuf = inbuf;
     451        return result;
     452fail:
     453        TALLOC_FREE(result);
     454        return NULL;
    425455}
    426456
    427457/* Main function */
    428458
    429 int main(int argc, char *argv[])
    430 {
    431         static char             *cmdstr = NULL;
    432         struct cmd_set          **cmd_set;
    433         static struct vfs_state vfs;
     459int main(int argc, const char *argv[])
     460{
     461        char *cmdstr = NULL;
     462        struct cmd_set  **cmd_set;
     463        struct vfs_state *vfs;
    434464        int i;
    435         static char             *filename = NULL;
     465        char *filename = NULL;
     466        char cwd[MAXPATHLEN];
    436467        TALLOC_CTX *frame = talloc_stackframe();
     468        struct tevent_context *ev;
     469        struct auth_session_info *session_info = NULL;
     470        NTSTATUS status = NT_STATUS_OK;
    437471
    438472        /* make sure the vars that get altered (4th field) are in
     
    443477                {"file",        'f', POPT_ARG_STRING,   &filename, 0, },
    444478                {"command",     'c', POPT_ARG_STRING,   &cmdstr, 0, "Execute specified list of commands" },
     479                {"memreport",   'm', POPT_ARG_INT,      &memreports, 0,
     480                 "Report memory left on talloc stackframe after each command" },
    445481                POPT_COMMON_SAMBA
    446482                POPT_TABLEEND
    447483        };
    448 
    449         load_case_tables();
     484        static const struct smbd_shim vfstest_shim_fns =
     485        {
     486                .exit_server = vfstest_exit_server,
     487                .exit_server_cleanly = vfstest_exit_server_cleanly,
     488        };
     489
     490        smb_init_locale();
    450491
    451492        setlinebuf(stdout);
    452493
    453         pc = poptGetContext("vfstest", argc, (const char **) argv,
    454                             long_options, 0);
    455        
     494        pc = poptGetContext("vfstest", argc, argv, long_options, 0);
     495
    456496        while(poptGetNextOpt(pc) != -1);
    457497
     
    459499        poptFreeContext(pc);
    460500
     501        /* we want total control over the permissions on created files,
     502           so set our umask to 0 */
     503        umask(0);
     504
    461505        lp_load_initial_only(get_dyn_CONFIGFILE());
    462506
    463507        /* TODO: check output */
    464         reload_services(smbd_messaging_context(), -1, False);
     508        reload_services(NULL, NULL, false);
    465509
    466510        /* the following functions are part of the Samba debugging
    467511           facilities.  See lib/debug.c */
    468512        setup_logging("vfstest", DEBUG_STDOUT);
    469        
     513
     514        set_smbd_shim(&vfstest_shim_fns);
     515
    470516        /* Load command lists */
    471517
     
    480526        /* some basic initialization stuff */
    481527        sec_init();
    482         vfs.conn = TALLOC_ZERO_P(NULL, connection_struct);
    483         vfs.conn->params = TALLOC_P(vfs.conn, struct share_params);
     528        init_guest_info();
     529        locking_init();
     530        serverid_parent_init(NULL);
     531        vfs = talloc_zero(NULL, struct vfs_state);
     532        if (vfs == NULL) {
     533                return 1;
     534        }
     535        status = make_session_info_guest(vfs, &session_info);
     536        if (!NT_STATUS_IS_OK(status)) {
     537                return 1;
     538        }
     539
     540        ev = server_event_context();
     541
     542        status = create_conn_struct(vfs,
     543                                ev,
     544                                server_messaging_context(),
     545                                &vfs->conn,
     546                                -1,
     547                                getcwd(cwd, sizeof(cwd)),
     548                                session_info);
     549        if (!NT_STATUS_IS_OK(status)) {
     550                return 1;
     551        }
     552
     553        vfs->conn->share_access = FILE_GENERIC_ALL;
     554        vfs->conn->read_only = false;
     555
     556        serverid_register(messaging_server_id(vfs->conn->sconn->msg_ctx), 0);
     557        file_init(vfs->conn->sconn);
    484558        for (i=0; i < 1024; i++)
    485                 vfs.files[i] = NULL;
    486 
    487         /* some advanced initiliazation stuff */
    488         smbd_vfs_init(vfs.conn);
     559                vfs->files[i] = NULL;
     560
     561        if (!posix_locking_init(false)) {
     562                return 1;
     563        }
    489564
    490565        /* Do we have a file input? */
    491566        if (filename && filename[0]) {
    492                 process_file(&vfs, filename);
     567                process_file(vfs, filename);
    493568                return 0;
    494569        }
     
    500575
    501576                while((cmd=next_command(frame, &p)) != NULL) {
    502                         process_cmd(&vfs, cmd);
     577                        status = process_cmd(vfs, cmd);
    503578                }
    504579
    505580                TALLOC_FREE(cmd);
    506                 return 0;
     581                return NT_STATUS_IS_OK(status) ? 0 : 1;
    507582        }
    508583
     
    519594
    520595                if (line[0] != '\n') {
    521                         process_cmd(&vfs, line);
     596                        status = process_cmd(vfs, line);
    522597                }
    523598                SAFE_FREE(line);
    524599        }
    525600
    526         TALLOC_FREE(vfs.conn);
     601        TALLOC_FREE(vfs);
    527602        TALLOC_FREE(frame);
    528         return 0;
    529 }
     603        return NT_STATUS_IS_OK(status) ? 0 : 1;
     604}
  • vendor/current/source3/torture/vfstest.h

    r414 r988  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   VFS module tester
     
    1313   the Free Software Foundation; either version 3 of the License, or
    1414   (at your option) any later version.
    15    
     15
    1616   This program is distributed in the hope that it will be useful,
    1717   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1818   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1919   GNU General Public License for more details.
    20    
     20
    2121   You should have received a copy of the GNU General Public License
    2222   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    3030struct vfs_state {
    3131        struct connection_struct *conn;
     32        uint64_t mid;
    3233        struct files_struct *files[1024];
    3334        DIR *currentdir;
     
    3536        size_t data_size;
    3637};
     38
     39struct smb_request *vfstest_get_smbreq(TALLOC_CTX *mem_ctx,
     40                                       struct vfs_state *vfs);
    3741
    3842struct cmd_set {
     
    4347        const char *usage;
    4448};
     49
     50NTSTATUS cmd_test_chain(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
     51                        int argc, const char **argv);
  • vendor/current/source3/torture/wbc_async.c

    r740 r988  
    289289        subreq = async_connect_send(mem_ctx, ev, wb_ctx->fd,
    290290                                    (struct sockaddr *)(void *)&sunaddr,
    291                                     sizeof(sunaddr));
     291                                    sizeof(sunaddr), NULL, NULL, NULL);
    292292        if (subreq == NULL) {
    293293                goto nomem;
     
    326326static const char *winbindd_socket_dir(void)
    327327{
    328 #ifdef SOCKET_WRAPPER
    329         const char *env_dir;
    330 
    331         env_dir = getenv(WINBINDD_SOCKET_DIR_ENVVAR);
    332         if (env_dir) {
    333                 return env_dir;
    334         }
    335 #endif
     328        if (nss_wrapper_enabled()) {
     329                const char *env_dir;
     330
     331                env_dir = getenv("SELFTEST_WINBINDD_SOCKET_DIR");
     332                if (env_dir != NULL) {
     333                        return env_dir;
     334                }
     335        }
    336336
    337337        return WINBINDD_SOCKET_DIR;
     
    552552        if (!tevent_queue_add(wb_ctx->queue, ev, req, wb_trans_trigger,
    553553                              NULL)) {
    554                 tevent_req_nomem(NULL, req);
     554                tevent_req_oom(req);
    555555                return tevent_req_post(req, ev);
    556556        }
Note: See TracChangeset for help on using the changeset viewer.