Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
33 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source4/torture/raw/acls.c

    r414 r745  
    3434#define CHECK_STATUS(status, correct) do { \
    3535        if (!NT_STATUS_EQUAL(status, correct)) { \
    36                 printf("(%s) Incorrect status %s - should be %s\n", \
     36                ret = false; \
     37                torture_result(tctx, TORTURE_FAIL, "(%s) Incorrect status %s - should be %s\n", \
    3738                       __location__, nt_errstr(status), nt_errstr(correct)); \
    38                 ret = false; \
    3939                goto done; \
    4040        }} while (0)
    4141
    42 
    43 static bool test_sd(struct torture_context *tctx,
    44                                         struct smbcli_state *cli)
     42#define FAIL_UNLESS(__cond)                                     \
     43        do {                                                    \
     44                if (__cond) {} else {                           \
     45                        ret = false; \
     46                        torture_result(tctx, TORTURE_FAIL, "%s) condition violated: %s\n", \
     47                            __location__, #__cond); \
     48                        goto done; \
     49                }                                               \
     50        } while(0)
     51
     52#define CHECK_SECURITY_DESCRIPTOR(_sd1, _sd2) do { \
     53        if (!security_descriptor_equal(_sd1, _sd2)) { \
     54                torture_warning(tctx, "%s: security descriptors don't match!\n", __location__); \
     55                torture_warning(tctx, "got:\n"); \
     56                NDR_PRINT_DEBUG(security_descriptor, _sd1); \
     57                torture_warning(tctx, "expected:\n"); \
     58                NDR_PRINT_DEBUG(security_descriptor, _sd2); \
     59                ret = false; \
     60        } \
     61} while (0)
     62
     63/*
     64 * Helper function to verify a security descriptor, by querying
     65 * and comparing against the passed in sd.
     66 * Copied to smb2_util_verify_sd() for SMB2.
     67 */
     68static bool verify_sd(TALLOC_CTX *tctx, struct smbcli_state *cli,
     69    int fnum, struct security_descriptor *sd)
     70{
     71        NTSTATUS status;
     72        bool ret = true;
     73        union smb_fileinfo q = {};
     74
     75        if (sd) {
     76                q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
     77                q.query_secdesc.in.file.fnum = fnum;
     78                q.query_secdesc.in.secinfo_flags =
     79                    SECINFO_OWNER |
     80                    SECINFO_GROUP |
     81                    SECINFO_DACL;
     82                status = smb_raw_fileinfo(cli->tree, tctx, &q);
     83                CHECK_STATUS(status, NT_STATUS_OK);
     84
     85                /* More work is needed if we're going to check this bit. */
     86                sd->type &= ~SEC_DESC_DACL_AUTO_INHERITED;
     87
     88                CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd);
     89        }
     90
     91 done:
     92        return ret;
     93}
     94
     95/*
     96 * Helper function to verify attributes, by querying
     97 * and comparing against the passed attrib.
     98 * Copied to smb2_util_verify_attrib() for SMB2.
     99 */
     100static bool verify_attrib(TALLOC_CTX *tctx, struct smbcli_state *cli,
     101    int fnum, uint32_t attrib)
     102{
     103        NTSTATUS status;
     104        bool ret = true;
     105        union smb_fileinfo q2 = {};
     106
     107        if (attrib) {
     108                q2.standard.level = RAW_FILEINFO_STANDARD;
     109                q2.standard.in.file.fnum = fnum;
     110                status = smb_raw_fileinfo(cli->tree, tctx, &q2);
     111                CHECK_STATUS(status, NT_STATUS_OK);
     112
     113                q2.standard.out.attrib &= ~FILE_ATTRIBUTE_ARCHIVE;
     114
     115                if (q2.standard.out.attrib != attrib) {
     116                        torture_warning(tctx, "%s: attributes don't match! "
     117                            "got %x, expected %x\n", __location__,
     118                            (uint32_t)q2.standard.out.attrib,
     119                            (uint32_t)attrib);
     120                        ret = false;
     121                }
     122        }
     123
     124 done:
     125        return ret;
     126}
     127
     128/**
     129 * Test setting and removing a DACL.
     130 * Test copied to torture_smb2_setinfo() for SMB2.
     131 */
     132static bool test_sd(struct torture_context *tctx, struct smbcli_state *cli)
    45133{
    46134        NTSTATUS status;
     
    55143        struct dom_sid *test_sid;
    56144
    57         printf("TESTING SETFILEINFO EA_SET\n");
     145        if (!torture_setup_dir(cli, BASEDIR))
     146                return false;
     147
     148        torture_comment(tctx, "TESTING SETFILEINFO EA_SET\n");
    58149
    59150        io.generic.level = RAW_OPEN_NTCREATEX;
    60         io.ntcreatex.in.root_fid = 0;
     151        io.ntcreatex.in.root_fid.fnum = 0;
    61152        io.ntcreatex.in.flags = 0;
    62153        io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    85176        sd = q.query_secdesc.out.sd;
    86177
    87         printf("add a new ACE to the DACL\n");
    88 
    89         test_sid = dom_sid_parse_talloc(tctx, "S-1-5-32-1234-5432");
     178        torture_comment(tctx, "add a new ACE to the DACL\n");
     179
     180        test_sid = dom_sid_parse_talloc(tctx, SID_NT_AUTHENTICATED_USERS);
    90181
    91182        ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
     
    104195        status = smb_raw_setfileinfo(cli->tree, &set);
    105196        CHECK_STATUS(status, NT_STATUS_OK);
    106 
    107         status = smb_raw_fileinfo(cli->tree, tctx, &q);
    108         CHECK_STATUS(status, NT_STATUS_OK);
    109 
    110         if (!security_acl_equal(q.query_secdesc.out.sd->dacl, sd->dacl)) {
    111                 printf("%s: security descriptors don't match!\n", __location__);
    112                 printf("got:\n");
    113                 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
    114                 printf("expected:\n");
    115                 NDR_PRINT_DEBUG(security_descriptor, sd);
    116                 ret = false;
    117         }
    118 
    119         printf("remove it again\n");
     197        FAIL_UNLESS(verify_sd(tctx, cli, fnum, sd));
     198
     199        torture_comment(tctx, "remove it again\n");
    120200
    121201        status = security_descriptor_dacl_del(sd, test_sid);
     
    124204        status = smb_raw_setfileinfo(cli->tree, &set);
    125205        CHECK_STATUS(status, NT_STATUS_OK);
    126 
    127         status = smb_raw_fileinfo(cli->tree, tctx, &q);
    128         CHECK_STATUS(status, NT_STATUS_OK);
    129 
    130         if (!security_acl_equal(q.query_secdesc.out.sd->dacl, sd->dacl)) {
    131                 printf("%s: security descriptors don't match!\n", __location__);
    132                 printf("got:\n");
    133                 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
    134                 printf("expected:\n");
    135                 NDR_PRINT_DEBUG(security_descriptor, sd);
    136                 ret = false;
    137         }
     206        FAIL_UNLESS(verify_sd(tctx, cli, fnum, sd));
    138207
    139208done:
    140209        smbcli_close(cli->tree, fnum);
     210        smb_raw_exit(cli->session);
     211        smbcli_deltree(cli->tree, BASEDIR);
     212
    141213        return ret;
    142214}
     
    145217/*
    146218  test using nttrans create to create a file with an initial acl set
     219  Test copied to test_create_acl() for SMB2.
    147220*/
    148 static bool test_nttrans_create(struct torture_context *tctx,
    149                                                                 struct smbcli_state *cli)
     221static bool test_nttrans_create_ext(struct torture_context *tctx,
     222                                    struct smbcli_state *cli, bool test_dir)
    150223{
    151224        NTSTATUS status;
     
    154227        bool ret = true;
    155228        int fnum = -1;
    156         union smb_fileinfo q;
     229        union smb_fileinfo q = {};
    157230        struct security_ace ace;
    158231        struct security_descriptor *sd;
    159232        struct dom_sid *test_sid;
    160 
    161         printf("testing nttrans create with sec_desc\n");
     233        uint32_t attrib =
     234            FILE_ATTRIBUTE_HIDDEN |
     235            FILE_ATTRIBUTE_SYSTEM |
     236            (test_dir ? FILE_ATTRIBUTE_DIRECTORY : 0);
     237        NTSTATUS (*delete_func)(struct smbcli_tree *, const char *) =
     238            test_dir ? smbcli_rmdir : smbcli_unlink;
     239
     240        if (!torture_setup_dir(cli, BASEDIR))
     241                return false;
    162242
    163243        io.generic.level = RAW_OPEN_NTTRANS_CREATE;
    164         io.ntcreatex.in.root_fid = 0;
     244        io.ntcreatex.in.root_fid.fnum = 0;
    165245        io.ntcreatex.in.flags = 0;
    166246        io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
    167         io.ntcreatex.in.create_options = 0;
     247        io.ntcreatex.in.create_options =
     248            test_dir ? NTCREATEX_OPTIONS_DIRECTORY : 0;
    168249        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
    169250        io.ntcreatex.in.share_access =
     
    178259        io.ntcreatex.in.ea_list = NULL;
    179260
    180         printf("creating normal file\n");
     261        torture_comment(tctx, "basic create\n");
    181262
    182263        status = smb_raw_open(cli->tree, tctx, &io);
     
    184265        fnum = io.ntcreatex.out.file.fnum;
    185266
    186         printf("querying ACL\n");
     267        torture_comment(tctx, "querying ACL\n");
    187268
    188269        q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
     
    196277        sd = q.query_secdesc.out.sd;
    197278
    198         smbcli_close(cli->tree, fnum);
    199         smbcli_unlink(cli->tree, fname);
    200 
    201         printf("adding a new ACE\n");
    202         test_sid = dom_sid_parse_talloc(tctx, "S-1-5-32-1234-54321");
     279        status = smbcli_close(cli->tree, fnum);
     280        CHECK_STATUS(status, NT_STATUS_OK);
     281
     282        status = delete_func(cli->tree, fname);
     283        CHECK_STATUS(status, NT_STATUS_OK);
     284
     285        torture_comment(tctx, "adding a new ACE\n");
     286        test_sid = dom_sid_parse_talloc(tctx, SID_NT_AUTHENTICATED_USERS);
    203287
    204288        ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
     
    210294        CHECK_STATUS(status, NT_STATUS_OK);
    211295       
    212         printf("creating a file with an initial ACL\n");
     296        torture_comment(tctx, "creating with an initial ACL\n");
    213297
    214298        io.ntcreatex.in.sec_desc = sd;
     
    217301        fnum = io.ntcreatex.out.file.fnum;
    218302       
    219         q.query_secdesc.in.file.fnum = fnum;
    220         status = smb_raw_fileinfo(cli->tree, tctx, &q);
    221         CHECK_STATUS(status, NT_STATUS_OK);
    222 
    223         if (!security_acl_equal(q.query_secdesc.out.sd->dacl, sd->dacl)) {
    224                 printf("%s: security descriptors don't match!\n", __location__);
    225                 printf("got:\n");
    226                 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
    227                 printf("expected:\n");
    228                 NDR_PRINT_DEBUG(security_descriptor, sd);
    229                 ret = false;
    230         }
    231 
    232 done:
     303        FAIL_UNLESS(verify_sd(tctx, cli, fnum, sd));
     304
     305        status = smbcli_close(cli->tree, fnum);
     306        CHECK_STATUS(status, NT_STATUS_OK);
     307        status = delete_func(cli->tree, fname);
     308        CHECK_STATUS(status, NT_STATUS_OK);
     309
     310        torture_comment(tctx, "creating with attributes\n");
     311
     312        io.ntcreatex.in.sec_desc = NULL;
     313        io.ntcreatex.in.file_attr = attrib;
     314        status = smb_raw_open(cli->tree, tctx, &io);
     315        CHECK_STATUS(status, NT_STATUS_OK);
     316        fnum = io.ntcreatex.out.file.fnum;
     317
     318        FAIL_UNLESS(verify_attrib(tctx, cli, fnum, attrib));
     319
     320        status = smbcli_close(cli->tree, fnum);
     321        CHECK_STATUS(status, NT_STATUS_OK);
     322
     323        status = delete_func(cli->tree, fname);
     324        CHECK_STATUS(status, NT_STATUS_OK);
     325
     326        torture_comment(tctx, "creating with attributes and ACL\n");
     327
     328        io.ntcreatex.in.sec_desc = sd;
     329        io.ntcreatex.in.file_attr = attrib;
     330        status = smb_raw_open(cli->tree, tctx, &io);
     331        CHECK_STATUS(status, NT_STATUS_OK);
     332        fnum = io.ntcreatex.out.file.fnum;
     333
     334        FAIL_UNLESS(verify_sd(tctx, cli, fnum, sd));
     335        FAIL_UNLESS(verify_attrib(tctx, cli, fnum, attrib));
     336
     337        status = smbcli_close(cli->tree, fnum);
     338        CHECK_STATUS(status, NT_STATUS_OK);
     339        status = delete_func(cli->tree, fname);
     340        CHECK_STATUS(status, NT_STATUS_OK);
     341
     342        torture_comment(tctx, "creating with attributes, ACL and owner\n");
     343
     344        sd = security_descriptor_dacl_create(tctx,
     345                                        0, SID_WORLD, SID_BUILTIN_USERS,
     346                                        SID_WORLD,
     347                                        SEC_ACE_TYPE_ACCESS_ALLOWED,
     348                                        SEC_RIGHTS_FILE_READ | SEC_STD_ALL,
     349                                        0,
     350                                        NULL);
     351
     352        io.ntcreatex.in.sec_desc = sd;
     353        io.ntcreatex.in.file_attr = attrib;
     354        status = smb_raw_open(cli->tree, tctx, &io);
     355        CHECK_STATUS(status, NT_STATUS_OK);
     356        fnum = io.ntcreatex.out.file.fnum;
     357
     358        FAIL_UNLESS(verify_sd(tctx, cli, fnum, sd));
     359        FAIL_UNLESS(verify_attrib(tctx, cli, fnum, attrib));
     360
     361        status = smbcli_close(cli->tree, fnum);
     362        CHECK_STATUS(status, NT_STATUS_OK);
     363        status = delete_func(cli->tree, fname);
     364        CHECK_STATUS(status, NT_STATUS_OK);
     365
     366 done:
    233367        smbcli_close(cli->tree, fnum);
     368        smb_raw_exit(cli->session);
     369        smbcli_deltree(cli->tree, BASEDIR);
    234370        return ret;
     371}
     372
     373static bool test_nttrans_create_file(struct torture_context *tctx,
     374    struct smbcli_state *cli)
     375{
     376        torture_comment(tctx, "Testing nttrans create with sec_desc on files\n");
     377
     378        return test_nttrans_create_ext(tctx, cli, false);
     379}
     380
     381static bool test_nttrans_create_dir(struct torture_context *tctx,
     382    struct smbcli_state *cli)
     383{
     384        torture_comment(tctx, "Testing nttrans create with sec_desc on directories\n");
     385
     386        return test_nttrans_create_ext(tctx, cli, true);
    235387}
    236388
     
    242394        CHECK_STATUS(status, NT_STATUS_OK); \
    243395        if (_q.access_information.out.access_flags != (flags)) { \
    244                 printf("(%s) Incorrect access_flags 0x%08x - should be 0x%08x\n", \
     396                ret = false; \
     397                torture_result(tctx, TORTURE_FAIL, "(%s) Incorrect access_flags 0x%08x - should be 0x%08x\n", \
    245398                       __location__, _q.access_information.out.access_flags, (flags)); \
    246                 ret = false; \
    247399                goto done; \
    248400        } \
     
    251403/*
    252404  test using NTTRANS CREATE to create a file with a null ACL set
     405  Test copied to test_create_null_dacl() for SMB2.
    253406*/
    254407static bool test_nttrans_create_null_dacl(struct torture_context *tctx,
     
    257410        NTSTATUS status;
    258411        union smb_open io;
    259         const char *fname = BASEDIR "\\acl3.txt";
     412        const char *fname = BASEDIR "\\nulldacl.txt";
    260413        bool ret = true;
    261414        int fnum = -1;
     
    265418        struct security_acl dacl;
    266419
    267         printf("TESTING SEC_DESC WITH A NULL DACL\n");
     420        if (!torture_setup_dir(cli, BASEDIR))
     421                return false;
     422
     423        torture_comment(tctx, "TESTING SEC_DESC WITH A NULL DACL\n");
    268424
    269425        io.generic.level = RAW_OPEN_NTTRANS_CREATE;
    270         io.ntcreatex.in.root_fid = 0;
     426        io.ntcreatex.in.root_fid.fnum = 0;
    271427        io.ntcreatex.in.flags = 0;
    272428        io.ntcreatex.in.access_mask = SEC_STD_READ_CONTROL | SEC_STD_WRITE_DAC
     
    284440        io.ntcreatex.in.ea_list = NULL;
    285441
    286         printf("creating a file with a empty sd\n");
     442        torture_comment(tctx, "creating a file with a empty sd\n");
    287443        status = smb_raw_open(cli->tree, tctx, &io);
    288444        CHECK_STATUS(status, NT_STATUS_OK);
    289445        fnum = io.ntcreatex.out.file.fnum;
    290446
    291         printf("get the original sd\n");
     447        torture_comment(tctx, "get the original sd\n");
    292448        q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
    293449        q.query_secdesc.in.file.fnum = fnum;
     
    305461         */
    306462        if (!(q.query_secdesc.out.sd->type & SEC_DESC_DACL_PRESENT)) {
    307                 printf("DACL_PRESENT flag not set by the server!\n");
    308463                ret = false;
     464                torture_result(tctx, TORTURE_FAIL, "DACL_PRESENT flag not set by the server!\n");
    309465                goto done;
    310466        }
    311467        if (q.query_secdesc.out.sd->dacl == NULL) {
    312                 printf("no DACL has been created on the server!\n");
    313468                ret = false;
     469                torture_result(tctx, TORTURE_FAIL, "no DACL has been created on the server!\n");
    314470                goto done;
    315471        }
    316472
    317         printf("set NULL DACL\n");
     473        torture_comment(tctx, "set NULL DACL\n");
    318474        sd->type |= SEC_DESC_DACL_PRESENT;
    319475
     
    325481        CHECK_STATUS(status, NT_STATUS_OK);
    326482
    327         printf("get the sd\n");
     483        torture_comment(tctx, "get the sd\n");
    328484        q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
    329485        q.query_secdesc.in.file.fnum = fnum;
     
    337493        /* Testing the modified DACL */
    338494        if (!(q.query_secdesc.out.sd->type & SEC_DESC_DACL_PRESENT)) {
    339                 printf("DACL_PRESENT flag not set by the server!\n");
    340495                ret = false;
     496                torture_result(tctx, TORTURE_FAIL, "DACL_PRESENT flag not set by the server!\n");
    341497                goto done;
    342498        }
    343499        if (q.query_secdesc.out.sd->dacl != NULL) {
    344                 printf("DACL has been created on the server!\n");
    345500                ret = false;
     501                torture_result(tctx, TORTURE_FAIL, "DACL has been created on the server!\n");
    346502                goto done;
    347503        }
    348504
    349         printf("try open for read control\n");
     505        torture_comment(tctx, "try open for read control\n");
    350506        io.ntcreatex.in.access_mask = SEC_STD_READ_CONTROL;
    351507        status = smb_raw_open(cli->tree, tctx, &io);
     
    355511        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    356512
    357         printf("try open for write\n");
     513        torture_comment(tctx, "try open for write\n");
    358514        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
    359515        status = smb_raw_open(cli->tree, tctx, &io);
     
    363519        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    364520
    365         printf("try open for read\n");
     521        torture_comment(tctx, "try open for read\n");
    366522        io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
    367523        status = smb_raw_open(cli->tree, tctx, &io);
     
    371527        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    372528
    373         printf("try open for generic write\n");
     529        torture_comment(tctx, "try open for generic write\n");
    374530        io.ntcreatex.in.access_mask = SEC_GENERIC_WRITE;
    375531        status = smb_raw_open(cli->tree, tctx, &io);
     
    379535        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    380536
    381         printf("try open for generic read\n");
     537        torture_comment(tctx, "try open for generic read\n");
    382538        io.ntcreatex.in.access_mask = SEC_GENERIC_READ;
    383539        status = smb_raw_open(cli->tree, tctx, &io);
     
    387543        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    388544
    389         printf("set DACL with 0 aces\n");
     545        torture_comment(tctx, "set DACL with 0 aces\n");
    390546        ZERO_STRUCT(dacl);
    391547        dacl.revision = SECURITY_ACL_REVISION_NT4;
     
    400556        CHECK_STATUS(status, NT_STATUS_OK);
    401557
    402         printf("get the sd\n");
     558        torture_comment(tctx, "get the sd\n");
    403559        q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
    404560        q.query_secdesc.in.file.fnum = fnum;
     
    412568        /* Testing the modified DACL */
    413569        if (!(q.query_secdesc.out.sd->type & SEC_DESC_DACL_PRESENT)) {
    414                 printf("DACL_PRESENT flag not set by the server!\n");
    415570                ret = false;
     571                torture_result(tctx, TORTURE_FAIL, "DACL_PRESENT flag not set by the server!\n");
    416572                goto done;
    417573        }
    418574        if (q.query_secdesc.out.sd->dacl == NULL) {
    419                 printf("no DACL has been created on the server!\n");
    420575                ret = false;
     576                torture_result(tctx, TORTURE_FAIL, "no DACL has been created on the server!\n");
    421577                goto done;
    422578        }
    423579        if (q.query_secdesc.out.sd->dacl->num_aces != 0) {
    424                 printf("DACL has %u aces!\n",
     580                ret = false;
     581                torture_result(tctx, TORTURE_FAIL, "DACL has %u aces!\n",
    425582                       q.query_secdesc.out.sd->dacl->num_aces);
    426                 ret = false;
    427583                goto done;
    428584        }
    429585
    430         printf("try open for read control\n");
     586        torture_comment(tctx, "try open for read control\n");
    431587        io.ntcreatex.in.access_mask = SEC_STD_READ_CONTROL;
    432588        status = smb_raw_open(cli->tree, tctx, &io);
     
    436592        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    437593
    438         printf("try open for write => access_denied\n");
     594        torture_comment(tctx, "try open for write => access_denied\n");
    439595        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
    440596        status = smb_raw_open(cli->tree, tctx, &io);
    441597        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    442598
    443         printf("try open for read => access_denied\n");
     599        torture_comment(tctx, "try open for read => access_denied\n");
    444600        io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
    445601        status = smb_raw_open(cli->tree, tctx, &io);
    446602        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    447603
    448         printf("try open for generic write => access_denied\n");
     604        torture_comment(tctx, "try open for generic write => access_denied\n");
    449605        io.ntcreatex.in.access_mask = SEC_GENERIC_WRITE;
    450606        status = smb_raw_open(cli->tree, tctx, &io);
    451607        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    452608
    453         printf("try open for generic read => access_denied\n");
     609        torture_comment(tctx, "try open for generic read => access_denied\n");
    454610        io.ntcreatex.in.access_mask = SEC_GENERIC_READ;
    455611        status = smb_raw_open(cli->tree, tctx, &io);
    456612        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    457613
    458         printf("set empty sd\n");
     614        torture_comment(tctx, "set empty sd\n");
    459615        sd->type &= ~SEC_DESC_DACL_PRESENT;
    460616        sd->dacl = NULL;
     
    467623        CHECK_STATUS(status, NT_STATUS_OK);
    468624
    469         printf("get the sd\n");
     625        torture_comment(tctx, "get the sd\n");
    470626        q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
    471627        q.query_secdesc.in.file.fnum = fnum;
     
    479635        /* Testing the modified DACL */
    480636        if (!(q.query_secdesc.out.sd->type & SEC_DESC_DACL_PRESENT)) {
    481                 printf("DACL_PRESENT flag not set by the server!\n");
    482637                ret = false;
     638                torture_result(tctx, TORTURE_FAIL, "DACL_PRESENT flag not set by the server!\n");
    483639                goto done;
    484640        }
    485641        if (q.query_secdesc.out.sd->dacl != NULL) {
    486                 printf("DACL has been created on the server!\n");
    487642                ret = false;
     643                torture_result(tctx, TORTURE_FAIL, "DACL has been created on the server!\n");
    488644                goto done;
    489645        }
    490646done:
    491647        smbcli_close(cli->tree, fnum);
     648        smb_raw_exit(cli->session);
     649        smbcli_deltree(cli->tree, BASEDIR);
    492650        return ret;
    493651}
     
    496654  test the behaviour of the well known SID_CREATOR_OWNER sid, and some generic
    497655  mapping bits
     656  Test copied to smb2/acls.c for SMB2.
    498657*/
    499658static bool test_creator_sid(struct torture_context *tctx,
     
    510669        const char *owner_sid;
    511670
    512         printf("TESTING SID_CREATOR_OWNER\n");
     671        if (!torture_setup_dir(cli, BASEDIR))
     672                return false;
     673
     674        torture_comment(tctx, "TESTING SID_CREATOR_OWNER\n");
    513675
    514676        io.generic.level = RAW_OPEN_NTCREATEX;
    515         io.ntcreatex.in.root_fid = 0;
     677        io.ntcreatex.in.root_fid.fnum = 0;
    516678        io.ntcreatex.in.flags = 0;
    517679        io.ntcreatex.in.access_mask = SEC_STD_READ_CONTROL | SEC_STD_WRITE_DAC | SEC_STD_WRITE_OWNER;
     
    530692        fnum = io.ntcreatex.out.file.fnum;
    531693
    532         printf("get the original sd\n");
     694        torture_comment(tctx, "get the original sd\n");
    533695        q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
    534696        q.query_secdesc.in.file.fnum = fnum;
     
    540702        owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
    541703
    542         printf("set a sec desc allowing no write by CREATOR_OWNER\n");
     704        torture_comment(tctx, "set a sec desc allowing no write by CREATOR_OWNER\n");
    543705        sd = security_descriptor_dacl_create(tctx,
    544706                                        0, NULL, NULL,
     
    557719        CHECK_STATUS(status, NT_STATUS_OK);
    558720
    559         printf("try open for write\n");
     721        torture_comment(tctx, "try open for write\n");
    560722        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
    561723        status = smb_raw_open(cli->tree, tctx, &io);
    562724        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    563725
    564         printf("try open for read\n");
     726        torture_comment(tctx, "try open for read\n");
    565727        io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
    566728        status = smb_raw_open(cli->tree, tctx, &io);
    567729        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    568730
    569         printf("try open for generic write\n");
     731        torture_comment(tctx, "try open for generic write\n");
    570732        io.ntcreatex.in.access_mask = SEC_GENERIC_WRITE;
    571733        status = smb_raw_open(cli->tree, tctx, &io);
    572734        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    573735
    574         printf("try open for generic read\n");
     736        torture_comment(tctx, "try open for generic read\n");
    575737        io.ntcreatex.in.access_mask = SEC_GENERIC_READ;
    576738        status = smb_raw_open(cli->tree, tctx, &io);
    577739        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    578740
    579         printf("set a sec desc allowing no write by owner\n");
     741        torture_comment(tctx, "set a sec desc allowing no write by owner\n");
    580742        sd = security_descriptor_dacl_create(tctx,
    581743                                        0, owner_sid, NULL,
     
    593755        CHECK_STATUS(status, NT_STATUS_OK);
    594756
    595         printf("check that sd has been mapped correctly\n");
     757        torture_comment(tctx, "check that sd has been mapped correctly\n");
    596758        status = smb_raw_fileinfo(cli->tree, tctx, &q);
    597759        CHECK_STATUS(status, NT_STATUS_OK);
    598         if (!security_descriptor_equal(q.query_secdesc.out.sd, sd)) {
    599                 printf("%s: security descriptors don't match!\n", __location__);
    600                 printf("got:\n");
    601                 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
    602                 printf("expected:\n");
    603                 NDR_PRINT_DEBUG(security_descriptor, sd);
    604                 ret = false;
    605         }
    606 
    607         printf("try open for write\n");
     760        CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd);
     761
     762        torture_comment(tctx, "try open for write\n");
    608763        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
    609764        status = smb_raw_open(cli->tree, tctx, &io);
    610765        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    611766
    612         printf("try open for read\n");
     767        torture_comment(tctx, "try open for read\n");
    613768        io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
    614769        status = smb_raw_open(cli->tree, tctx, &io);
     
    619774        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    620775
    621         printf("try open for generic write\n");
     776        torture_comment(tctx, "try open for generic write\n");
    622777        io.ntcreatex.in.access_mask = SEC_GENERIC_WRITE;
    623778        status = smb_raw_open(cli->tree, tctx, &io);
    624779        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    625780
    626         printf("try open for generic read\n");
     781        torture_comment(tctx, "try open for generic read\n");
    627782        io.ntcreatex.in.access_mask = SEC_GENERIC_READ;
    628783        status = smb_raw_open(cli->tree, tctx, &io);
     
    632787        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    633788
    634         printf("set a sec desc allowing generic read by owner\n");
     789        torture_comment(tctx, "set a sec desc allowing generic read by owner\n");
    635790        sd = security_descriptor_dacl_create(tctx,
    636791                                        0, NULL, NULL,
     
    645800        CHECK_STATUS(status, NT_STATUS_OK);
    646801
    647         printf("check that generic read has been mapped correctly\n");
     802        torture_comment(tctx, "check that generic read has been mapped correctly\n");
    648803        sd2 = security_descriptor_dacl_create(tctx,
    649804                                         0, owner_sid, NULL,
     
    656811        status = smb_raw_fileinfo(cli->tree, tctx, &q);
    657812        CHECK_STATUS(status, NT_STATUS_OK);
    658         if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
    659                 printf("%s: security descriptors don't match!\n", __location__);
    660                 printf("got:\n");
    661                 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
    662                 printf("expected:\n");
    663                 NDR_PRINT_DEBUG(security_descriptor, sd2);
    664                 ret = false;
    665         }
    666        
    667 
    668         printf("try open for write\n");
     813        CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
     814
     815        torture_comment(tctx, "try open for write\n");
    669816        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
    670817        status = smb_raw_open(cli->tree, tctx, &io);
    671818        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    672819
    673         printf("try open for read\n");
     820        torture_comment(tctx, "try open for read\n");
    674821        io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
    675822        status = smb_raw_open(cli->tree, tctx, &io);
     
    680827        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    681828
    682         printf("try open for generic write\n");
     829        torture_comment(tctx, "try open for generic write\n");
    683830        io.ntcreatex.in.access_mask = SEC_GENERIC_WRITE;
    684831        status = smb_raw_open(cli->tree, tctx, &io);
    685832        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    686833
    687         printf("try open for generic read\n");
     834        torture_comment(tctx, "try open for generic read\n");
    688835        io.ntcreatex.in.access_mask = SEC_GENERIC_READ;
    689836        status = smb_raw_open(cli->tree, tctx, &io);
     
    693840
    694841
    695         printf("put back original sd\n");
     842        torture_comment(tctx, "put back original sd\n");
    696843        set.set_secdesc.in.sd = sd_orig;
    697844        status = smb_raw_setfileinfo(cli->tree, &set);
     
    701848done:
    702849        smbcli_close(cli->tree, fnum);
     850        smb_raw_exit(cli->session);
     851        smbcli_deltree(cli->tree, BASEDIR);
    703852        return ret;
    704853}
     
    708857  test the mapping of the SEC_GENERIC_xx bits to SEC_STD_xx and
    709858  SEC_FILE_xx bits
     859  Test copied to smb2/acls.c for SMB2.
    710860*/
    711861static bool test_generic_bits(struct torture_context *tctx,
     
    746896        bool has_take_ownership_privilege;
    747897
    748         printf("TESTING FILE GENERIC BITS\n");
     898        if (!torture_setup_dir(cli, BASEDIR))
     899                return false;
     900
     901        torture_comment(tctx, "TESTING FILE GENERIC BITS\n");
    749902
    750903        io.generic.level = RAW_OPEN_NTCREATEX;
    751         io.ntcreatex.in.root_fid = 0;
     904        io.ntcreatex.in.root_fid.fnum = 0;
    752905        io.ntcreatex.in.flags = 0;
    753906        io.ntcreatex.in.access_mask =
     
    769922        fnum = io.ntcreatex.out.file.fnum;
    770923
    771         printf("get the original sd\n");
     924        torture_comment(tctx, "get the original sd\n");
    772925        q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
    773926        q.query_secdesc.in.file.fnum = fnum;
     
    779932        owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
    780933
    781         status = smblsa_sid_check_privilege(cli,
     934        status = torture_check_privilege(cli,
    782935                                            owner_sid,
    783936                                            sec_privilege_name(SEC_PRIV_RESTORE));
    784937        has_restore_privilege = NT_STATUS_IS_OK(status);
    785938        if (!NT_STATUS_IS_OK(status)) {
    786                 printf("smblsa_sid_check_privilege - %s\n", nt_errstr(status));
    787         }
    788         printf("SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
    789 
    790         status = smblsa_sid_check_privilege(cli,
     939                torture_warning(tctx, "torture_check_privilege - %s\n",
     940                    nt_errstr(status));
     941        }
     942        torture_comment(tctx, "SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
     943
     944        status = torture_check_privilege(cli,
    791945                                            owner_sid,
    792946                                            sec_privilege_name(SEC_PRIV_TAKE_OWNERSHIP));
    793947        has_take_ownership_privilege = NT_STATUS_IS_OK(status);
    794948        if (!NT_STATUS_IS_OK(status)) {
    795                 printf("smblsa_sid_check_privilege - %s\n", nt_errstr(status));
    796         }
    797         printf("SEC_PRIV_TAKE_OWNERSHIP - %s\n", has_take_ownership_privilege?"Yes":"No");
     949                torture_warning(tctx, "torture_check_privilege - %s\n",
     950                    nt_errstr(status));
     951        }
     952        torture_comment(tctx, "SEC_PRIV_TAKE_OWNERSHIP - %s\n", has_take_ownership_privilege?"Yes":"No");
    798953
    799954        for (i=0;i<ARRAY_SIZE(file_mappings);i++) {
     
    809964                }
    810965
    811                 printf("testing generic bits 0x%08x\n",
     966                torture_comment(tctx, "Testing generic bits 0x%08x\n",
    812967                       file_mappings[i].gen_bits);
    813968                sd = security_descriptor_dacl_create(tctx,
     
    837992                status = smb_raw_fileinfo(cli->tree, tctx, &q);
    838993                CHECK_STATUS(status, NT_STATUS_OK);
    839                 if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
    840                         printf("%s: security descriptors don't match!\n", __location__);
    841                         printf("got:\n");
    842                         NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
    843                         printf("expected:\n");
    844                         NDR_PRINT_DEBUG(security_descriptor, sd2);
    845                         ret = false;
    846                 }
     994                CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
    847995
    848996                io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    8571005                }
    8581006
    859                 printf("testing generic bits 0x%08x (anonymous)\n",
     1007                torture_comment(tctx, "Testing generic bits 0x%08x (anonymous)\n",
    8601008                       file_mappings[i].gen_bits);
    8611009                sd = security_descriptor_dacl_create(tctx,
     
    8851033                status = smb_raw_fileinfo(cli->tree, tctx, &q);
    8861034                CHECK_STATUS(status, NT_STATUS_OK);
    887                 if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
    888                         printf("%s: security descriptors don't match!\n", __location__);
    889                         printf("got:\n");
    890                         NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
    891                         printf("expected:\n");
    892                         NDR_PRINT_DEBUG(security_descriptor, sd2);
    893                         ret = false;
    894                 }
     1035                CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
    8951036
    8961037                io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    9021043        }
    9031044
    904         printf("put back original sd\n");
     1045        torture_comment(tctx, "put back original sd\n");
    9051046        set.set_secdesc.in.sd = sd_orig;
    9061047        status = smb_raw_setfileinfo(cli->tree, &set);
     
    9111052
    9121053
    913         printf("TESTING DIR GENERIC BITS\n");
     1054        torture_comment(tctx, "TESTING DIR GENERIC BITS\n");
    9141055
    9151056        io.generic.level = RAW_OPEN_NTCREATEX;
    916         io.ntcreatex.in.root_fid = 0;
     1057        io.ntcreatex.in.root_fid.fnum = 0;
    9171058        io.ntcreatex.in.flags = 0;
    9181059        io.ntcreatex.in.access_mask =
     
    9341075        fnum = io.ntcreatex.out.file.fnum;
    9351076
    936         printf("get the original sd\n");
     1077        torture_comment(tctx, "get the original sd\n");
    9371078        q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
    9381079        q.query_secdesc.in.file.fnum = fnum;
     
    9441085        owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
    9451086
    946         status = smblsa_sid_check_privilege(cli,
     1087        status = torture_check_privilege(cli,
    9471088                                            owner_sid,
    9481089                                            sec_privilege_name(SEC_PRIV_RESTORE));
    9491090        has_restore_privilege = NT_STATUS_IS_OK(status);
    9501091        if (!NT_STATUS_IS_OK(status)) {
    951                 printf("smblsa_sid_check_privilege - %s\n", nt_errstr(status));
    952         }
    953         printf("SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
    954 
    955         status = smblsa_sid_check_privilege(cli,
     1092                torture_warning(tctx, "torture_check_privilege - %s\n",
     1093                    nt_errstr(status));
     1094        }
     1095        torture_comment(tctx, "SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
     1096
     1097        status = torture_check_privilege(cli,
    9561098                                            owner_sid,
    9571099                                            sec_privilege_name(SEC_PRIV_TAKE_OWNERSHIP));
    9581100        has_take_ownership_privilege = NT_STATUS_IS_OK(status);
    9591101        if (!NT_STATUS_IS_OK(status)) {
    960                 printf("smblsa_sid_check_privilege - %s\n", nt_errstr(status));
    961         }
    962         printf("SEC_PRIV_TAKE_OWNERSHIP - %s\n", has_take_ownership_privilege?"Yes":"No");
     1102                torture_warning(tctx, "torture_check_privilege - %s\n",
     1103                    nt_errstr(status));
     1104        }
     1105        torture_comment(tctx, "SEC_PRIV_TAKE_OWNERSHIP - %s\n", has_take_ownership_privilege?"Yes":"No");
    9631106
    9641107        for (i=0;i<ARRAY_SIZE(dir_mappings);i++) {
     
    9741117                }
    9751118
    976                 printf("testing generic bits 0x%08x\n",
     1119                torture_comment(tctx, "Testing generic bits 0x%08x\n",
    9771120                       file_mappings[i].gen_bits);
    9781121                sd = security_descriptor_dacl_create(tctx,
     
    10021145                status = smb_raw_fileinfo(cli->tree, tctx, &q);
    10031146                CHECK_STATUS(status, NT_STATUS_OK);
    1004                 if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
    1005                         printf("%s: security descriptors don't match!\n", __location__);
    1006                         printf("got:\n");
    1007                         NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
    1008                         printf("expected:\n");
    1009                         NDR_PRINT_DEBUG(security_descriptor, sd2);
    1010                         ret = false;
    1011                 }
     1147                CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
    10121148
    10131149                io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    10221158                }
    10231159
    1024                 printf("testing generic bits 0x%08x (anonymous)\n",
     1160                torture_comment(tctx, "Testing generic bits 0x%08x (anonymous)\n",
    10251161                       file_mappings[i].gen_bits);
    10261162                sd = security_descriptor_dacl_create(tctx,
     
    10501186                status = smb_raw_fileinfo(cli->tree, tctx, &q);
    10511187                CHECK_STATUS(status, NT_STATUS_OK);
    1052                 if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
    1053                         printf("%s: security descriptors don't match!\n", __location__);
    1054                         printf("got:\n");
    1055                         NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
    1056                         printf("expected:\n");
    1057                         NDR_PRINT_DEBUG(security_descriptor, sd2);
    1058                         ret = false;
    1059                 }
     1188                CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
    10601189
    10611190                io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    10671196        }
    10681197
    1069         printf("put back original sd\n");
     1198        torture_comment(tctx, "put back original sd\n");
    10701199        set.set_secdesc.in.sd = sd_orig;
    10711200        status = smb_raw_setfileinfo(cli->tree, &set);
     
    10771206done:
    10781207        smbcli_close(cli->tree, fnum);
     1208        smb_raw_exit(cli->session);
     1209        smbcli_deltree(cli->tree, BASEDIR);
    10791210        return ret;
    10801211}
     
    10831214/*
    10841215  see what access bits the owner of a file always gets
     1216  Test copied to smb2/acls.c for SMB2.
    10851217*/
    10861218static bool test_owner_bits(struct torture_context *tctx,
     
    11001232        uint32_t expected_bits;
    11011233
    1102         printf("TESTING FILE OWNER BITS\n");
     1234        if (!torture_setup_dir(cli, BASEDIR))
     1235                return false;
     1236
     1237        torture_comment(tctx, "TESTING FILE OWNER BITS\n");
    11031238
    11041239        io.generic.level = RAW_OPEN_NTCREATEX;
    1105         io.ntcreatex.in.root_fid = 0;
     1240        io.ntcreatex.in.root_fid.fnum = 0;
    11061241        io.ntcreatex.in.flags = 0;
    11071242        io.ntcreatex.in.access_mask =
     
    11231258        fnum = io.ntcreatex.out.file.fnum;
    11241259
    1125         printf("get the original sd\n");
     1260        torture_comment(tctx, "get the original sd\n");
    11261261        q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
    11271262        q.query_secdesc.in.file.fnum = fnum;
     
    11331268        owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
    11341269
    1135         status = smblsa_sid_check_privilege(cli,
     1270        status = torture_check_privilege(cli,
    11361271                                            owner_sid,
    11371272                                            sec_privilege_name(SEC_PRIV_RESTORE));
    11381273        has_restore_privilege = NT_STATUS_IS_OK(status);
    11391274        if (!NT_STATUS_IS_OK(status)) {
    1140                 printf("smblsa_sid_check_privilege - %s\n", nt_errstr(status));
    1141         }
    1142         printf("SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
    1143 
    1144         status = smblsa_sid_check_privilege(cli,
     1275                torture_warning(tctx, "torture_check_privilege - %s\n", nt_errstr(status));
     1276        }
     1277        torture_comment(tctx, "SEC_PRIV_RESTORE - %s\n", has_restore_privilege?"Yes":"No");
     1278
     1279        status = torture_check_privilege(cli,
    11451280                                            owner_sid,
    11461281                                            sec_privilege_name(SEC_PRIV_TAKE_OWNERSHIP));
    11471282        has_take_ownership_privilege = NT_STATUS_IS_OK(status);
    11481283        if (!NT_STATUS_IS_OK(status)) {
    1149                 printf("smblsa_sid_check_privilege - %s\n", nt_errstr(status));
    1150         }
    1151         printf("SEC_PRIV_TAKE_OWNERSHIP - %s\n", has_take_ownership_privilege?"Yes":"No");
     1284                torture_warning(tctx, "torture_check_privilege - %s\n", nt_errstr(status));
     1285        }
     1286        torture_comment(tctx, "SEC_PRIV_TAKE_OWNERSHIP - %s\n", has_take_ownership_privilege?"Yes":"No");
    11521287
    11531288        sd = security_descriptor_dacl_create(tctx,
     
    11751310                if (expected_bits & bit) {
    11761311                        if (!NT_STATUS_IS_OK(status)) {
    1177                                 printf("failed with access mask 0x%08x of expected 0x%08x\n",
     1312                                torture_warning(tctx, "failed with access mask 0x%08x of expected 0x%08x\n",
    11781313                                       bit, expected_bits);
    11791314                        }
     
    11831318                } else {
    11841319                        if (NT_STATUS_IS_OK(status)) {
    1185                                 printf("open succeeded with access mask 0x%08x of "
     1320                                torture_warning(tctx, "open succeeded with access mask 0x%08x of "
    11861321                                        "expected 0x%08x - should fail\n",
    11871322                                       bit, expected_bits);
     
    11911326        }
    11921327
    1193         printf("put back original sd\n");
     1328        torture_comment(tctx, "put back original sd\n");
    11941329        set.set_secdesc.in.sd = sd_orig;
    11951330        status = smb_raw_setfileinfo(cli->tree, &set);
     
    11991334        smbcli_close(cli->tree, fnum);
    12001335        smbcli_unlink(cli->tree, fname);
     1336        smb_raw_exit(cli->session);
     1337        smbcli_deltree(cli->tree, BASEDIR);
    12011338        return ret;
    12021339}
     
    12061343/*
    12071344  test the inheritance of ACL flags onto new files and directories
     1345  Test copied to smb2/acls.c for SMB2.
    12081346*/
    12091347static bool test_inheritance(struct torture_context *tctx,
     
    12191357        union smb_fileinfo q;
    12201358        union smb_setfileinfo set;
    1221         struct security_descriptor *sd, *sd2, *sd_orig=NULL, *sd_def;
    1222         const char *owner_sid;
     1359        struct security_descriptor *sd, *sd2, *sd_orig=NULL, *sd_def1, *sd_def2;
     1360        const char *owner_sid, *group_sid;
    12231361        const struct dom_sid *creator_owner;
    12241362        const struct {
     
    13301468        };
    13311469
    1332         smbcli_rmdir(cli->tree, dname);
    1333 
    1334         printf("TESTING ACL INHERITANCE\n");
     1470        if (!torture_setup_dir(cli, BASEDIR))
     1471                return false;
     1472
     1473        torture_comment(tctx, "TESTING ACL INHERITANCE\n");
    13351474
    13361475        io.generic.level = RAW_OPEN_NTCREATEX;
    1337         io.ntcreatex.in.root_fid = 0;
     1476        io.ntcreatex.in.root_fid.fnum = 0;
    13381477        io.ntcreatex.in.flags = 0;
    13391478        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     
    13511490        fnum = io.ntcreatex.out.file.fnum;
    13521491
    1353         printf("get the original sd\n");
     1492        torture_comment(tctx, "get the original sd\n");
    13541493        q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
    13551494        q.query_secdesc.in.file.fnum = fnum;
     1495        q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER | SECINFO_GROUP;
     1496        status = smb_raw_fileinfo(cli->tree, tctx, &q);
     1497        CHECK_STATUS(status, NT_STATUS_OK);
     1498        sd_orig = q.query_secdesc.out.sd;
     1499
     1500        owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
     1501        group_sid = dom_sid_string(tctx, sd_orig->group_sid);
     1502
     1503        torture_comment(tctx, "owner_sid is %s\n", owner_sid);
     1504        torture_comment(tctx, "group_sid is %s\n", group_sid);
     1505
    13561506        q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
    1357         status = smb_raw_fileinfo(cli->tree, tctx, &q);
    1358         CHECK_STATUS(status, NT_STATUS_OK);
    1359         sd_orig = q.query_secdesc.out.sd;
    1360 
    1361         owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
    1362 
    1363         printf("owner_sid is %s\n", owner_sid);
    1364 
    1365         sd_def = security_descriptor_dacl_create(tctx,
     1507
     1508        if (torture_setting_bool(tctx, "samba4", false)) {
     1509                /* the default ACL in Samba4 includes the group and
     1510                   other permissions */
     1511                sd_def1 = security_descriptor_dacl_create(tctx,
     1512                                                         0, owner_sid, NULL,
     1513                                                         owner_sid,
     1514                                                         SEC_ACE_TYPE_ACCESS_ALLOWED,
     1515                                                         SEC_RIGHTS_FILE_ALL,
     1516                                                         0,
     1517                                                         group_sid,
     1518                                                         SEC_ACE_TYPE_ACCESS_ALLOWED,
     1519                                                         SEC_RIGHTS_FILE_READ | SEC_FILE_EXECUTE,
     1520                                                         0,
     1521                                                         SID_WORLD,
     1522                                                         SEC_ACE_TYPE_ACCESS_ALLOWED,
     1523                                                         SEC_RIGHTS_FILE_READ | SEC_FILE_EXECUTE,
     1524                                                         0,
     1525                                                         SID_NT_SYSTEM,
     1526                                                         SEC_ACE_TYPE_ACCESS_ALLOWED,
     1527                                                         SEC_RIGHTS_FILE_ALL,
     1528                                                         0,
     1529                                                         NULL);
     1530        } else {
     1531                /*
     1532                 * The Windows Default ACL for a new file, when there is no ACL to be
     1533                 * inherited: FullControl for the owner and SYSTEM.
     1534                 */
     1535                sd_def1 = security_descriptor_dacl_create(tctx,
     1536                                                         0, owner_sid, NULL,
     1537                                                         owner_sid,
     1538                                                         SEC_ACE_TYPE_ACCESS_ALLOWED,
     1539                                                         SEC_RIGHTS_FILE_ALL,
     1540                                                         0,
     1541                                                         SID_NT_SYSTEM,
     1542                                                         SEC_ACE_TYPE_ACCESS_ALLOWED,
     1543                                                         SEC_RIGHTS_FILE_ALL,
     1544                                                         0,
     1545                                                         NULL);
     1546        }
     1547
     1548        /*
     1549         * Use this in the case the system being tested does not add an ACE for
     1550         * the SYSTEM SID.
     1551         */
     1552        sd_def2 = security_descriptor_dacl_create(tctx,
    13661553                                            0, owner_sid, NULL,
    13671554                                            owner_sid,
    1368                                             SEC_ACE_TYPE_ACCESS_ALLOWED,
    1369                                             SEC_RIGHTS_FILE_ALL,
    1370                                             0,
    1371                                             SID_NT_SYSTEM,
    13721555                                            SEC_ACE_TYPE_ACCESS_ALLOWED,
    13731556                                            SEC_RIGHTS_FILE_ALL,
     
    14101593
    14111594                if (!(test_flags[i].parent_flags & SEC_ACE_FLAG_OBJECT_INHERIT)) {
    1412                         if (!security_descriptor_equal(q.query_secdesc.out.sd, sd_def)) {
    1413                                 printf("Expected default sd:\n");
    1414                                 NDR_PRINT_DEBUG(security_descriptor, sd_def);
    1415                                 printf("at %d - got:\n", i);
     1595                        if (!security_descriptor_equal(q.query_secdesc.out.sd, sd_def1) &&
     1596                            !security_descriptor_equal(q.query_secdesc.out.sd, sd_def2)) {
     1597                                torture_warning(tctx, "Expected default sd "
     1598                                    "for i=%d:\n", i);
     1599                                NDR_PRINT_DEBUG(security_descriptor, sd_def1);
     1600                                torture_warning(tctx, "at %d - got:\n", i);
    14161601                                NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
    14171602                        }
     
    14241609                    !dom_sid_equal(&q.query_secdesc.out.sd->dacl->aces[0].trustee,
    14251610                                   sd_orig->owner_sid)) {
    1426                         printf("Bad sd in child file at %d\n", i);
     1611                        ret = false;
     1612                        torture_warning(tctx, "Bad sd in child file at %d\n", i);
    14271613                        NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
    1428                         ret = false;
    14291614                        goto check_dir;
    14301615                }
     
    14321617                if (q.query_secdesc.out.sd->dacl->aces[0].flags !=
    14331618                    test_flags[i].file_flags) {
    1434                         printf("incorrect file_flags 0x%x - expected 0x%x for parent 0x%x with (i=%d)\n",
     1619                        torture_warning(tctx, "incorrect file_flags 0x%x - expected 0x%x for parent 0x%x with (i=%d)\n",
    14351620                               q.query_secdesc.out.sd->dacl->aces[0].flags,
    14361621                               test_flags[i].file_flags,
     
    14571642                    (!(test_flags[i].parent_flags & SEC_ACE_FLAG_OBJECT_INHERIT) ||
    14581643                     (test_flags[i].parent_flags & SEC_ACE_FLAG_NO_PROPAGATE_INHERIT))) {
    1459                         if (!security_descriptor_equal(q.query_secdesc.out.sd, sd_def)) {
    1460                                 printf("Expected default sd for dir at %d:\n", i);
    1461                                 NDR_PRINT_DEBUG(security_descriptor, sd_def);
    1462                                 printf("got:\n");
     1644                        if (!security_descriptor_equal(q.query_secdesc.out.sd, sd_def1) &&
     1645                            !security_descriptor_equal(q.query_secdesc.out.sd, sd_def2)) {
     1646                                torture_warning(tctx, "Expected default sd for dir at %d:\n", i);
     1647                                NDR_PRINT_DEBUG(security_descriptor, sd_def1);
     1648                                torture_warning(tctx, "got:\n");
    14631649                                NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
    14641650                        }
     
    14741660                                           sd_orig->owner_sid) ||
    14751661                            q.query_secdesc.out.sd->dacl->aces[0].flags != test_flags[i].dir_flags) {
    1476                                 printf("(CI & NP) Bad sd in child dir at %d (parent 0x%x)\n",
    1477                                        i, test_flags[i].parent_flags);
     1662                                torture_warning(tctx, "(CI & NP) Bad sd in child dir - expected 0x%x for parent 0x%x (i=%d)\n",
     1663                                       test_flags[i].dir_flags,
     1664                                       test_flags[i].parent_flags, i);
    14781665                                NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
     1666                                torture_comment(tctx, "FYI, here is the parent sd:\n");
     1667                                NDR_PRINT_DEBUG(security_descriptor, sd);
    14791668                                ret = false;
    14801669                                continue;
     
    14921681                            q.query_secdesc.out.sd->dacl->aces[1].flags !=
    14931682                            (test_flags[i].dir_flags | SEC_ACE_FLAG_INHERIT_ONLY)) {
    1494                                 printf("(CI) Bad sd in child dir at %d (parent 0x%x)\n",
    1495                                        i, test_flags[i].parent_flags);
     1683                                torture_warning(tctx, "(CI) Bad sd in child dir - expected 0x%x for parent 0x%x (i=%d)\n",
     1684                                       test_flags[i].dir_flags,
     1685                                       test_flags[i].parent_flags, i);
    14961686                                NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
     1687                                torture_comment(tctx, "FYI, here is the parent sd:\n");
     1688                                NDR_PRINT_DEBUG(security_descriptor, sd);
    14971689                                ret = false;
    14981690                                continue;
     
    15051697                                           creator_owner) ||
    15061698                            q.query_secdesc.out.sd->dacl->aces[0].flags != test_flags[i].dir_flags) {
    1507                                 printf("(0) Bad sd in child dir at %d (parent 0x%x)\n",
    1508                                         i, test_flags[i].parent_flags);
     1699                                torture_warning(tctx, "(0) Bad sd in child dir - expected 0x%x for parent 0x%x (i=%d)\n",
     1700                                       test_flags[i].dir_flags,
     1701                                       test_flags[i].parent_flags, i);
    15091702                                NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
     1703                                torture_comment(tctx, "FYI, here is the parent sd:\n");
     1704                                NDR_PRINT_DEBUG(security_descriptor, sd);
    15101705                                ret = false;
    15111706                                continue;
     
    15141709        }
    15151710
    1516         printf("testing access checks on inherited create with %s\n", fname1);
     1711        torture_comment(tctx, "Testing access checks on inherited create with %s\n", fname1);
    15171712        sd = security_descriptor_dacl_create(tctx,
    15181713                                        0, NULL, NULL,
     
    15331728        CHECK_STATUS(status, NT_STATUS_OK);
    15341729
     1730        /* Check DACL we just set. */
     1731        torture_comment(tctx, "checking new sd\n");
     1732        q.query_secdesc.in.file.fnum = fnum;
     1733        q.query_secdesc.in.secinfo_flags = SECINFO_DACL;
     1734        status = smb_raw_fileinfo(cli->tree, tctx, &q);
     1735        CHECK_STATUS(status, NT_STATUS_OK);
     1736        CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd);
     1737
    15351738        io.ntcreatex.in.fname = fname1;
    15361739        io.ntcreatex.in.create_options = 0;
     
    15551758                                         0,
    15561759                                         NULL);
    1557         if (!security_descriptor_equal(q.query_secdesc.out.sd, sd2)) {
    1558                 printf("%s: security descriptors don't match!\n", __location__);
    1559                 printf("got:\n");
    1560                 NDR_PRINT_DEBUG(security_descriptor, q.query_secdesc.out.sd);
    1561                 printf("expected:\n");
    1562                 NDR_PRINT_DEBUG(security_descriptor, sd2);
    1563                 ret = false;
    1564         }
     1760        CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
    15651761
    15661762        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
     
    15681764        status = smb_raw_open(cli->tree, tctx, &io);
    15691765        if (NT_STATUS_IS_OK(status)) {
    1570                 printf("failed: w2k3 ACL bug (allowed open when ACL should deny)\n");
     1766                torture_warning(tctx, "failed: w2k3 ACL bug (allowed open when ACL should deny)\n");
    15711767                ret = false;
    15721768                fnum2 = io.ntcreatex.out.file.fnum;
     
    15741770                smbcli_close(cli->tree, fnum2);
    15751771        } else {
    1576                 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    1577         }
    1578 
    1579         printf("trying without execute\n");
     1772                if (TARGET_IS_WIN7(tctx)) {
     1773                        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
     1774                } else {
     1775                        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
     1776                }
     1777        }
     1778
     1779        torture_comment(tctx, "trying without execute\n");
    15801780        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
    15811781        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL & ~SEC_FILE_EXECUTE;
    15821782        status = smb_raw_open(cli->tree, tctx, &io);
    1583         CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    1584 
    1585         printf("and with full permissions again\n");
     1783        if (TARGET_IS_WIN7(tctx)) {
     1784                CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
     1785        } else {
     1786                CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
     1787        }
     1788
     1789        torture_comment(tctx, "and with full permissions again\n");
    15861790        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
    15871791        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    15881792        status = smb_raw_open(cli->tree, tctx, &io);
    1589         CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
     1793        if (TARGET_IS_WIN7(tctx)) {
     1794                CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
     1795        } else {
     1796                CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
     1797        }
    15901798
    15911799        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
     
    15961804        smbcli_close(cli->tree, fnum2);
    15971805
    1598         printf("put back original sd\n");
     1806        torture_comment(tctx, "put back original sd\n");
    15991807        set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
    16001808        set.set_secdesc.in.file.fnum = fnum;
     
    16081816        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    16091817        status = smb_raw_open(cli->tree, tctx, &io);
    1610         CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
     1818        if (TARGET_IS_WIN7(tctx)) {
     1819                CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
     1820        } else {
     1821                CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
     1822        }
    16111823
    16121824        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
     
    16171829        smbcli_close(cli->tree, fnum2);
    16181830
     1831done:
     1832        if (sd_orig != NULL) {
     1833                set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
     1834                set.set_secdesc.in.file.fnum = fnum;
     1835                set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
     1836                set.set_secdesc.in.sd = sd_orig;
     1837                status = smb_raw_setfileinfo(cli->tree, &set);
     1838        }
     1839
     1840        smbcli_close(cli->tree, fnum);
    16191841        smbcli_unlink(cli->tree, fname1);
    16201842        smbcli_rmdir(cli->tree, dname);
    1621 
    1622 done:
    1623         set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
    1624         set.set_secdesc.in.file.fnum = fnum;
    1625         set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
    1626         set.set_secdesc.in.sd = sd_orig;
    1627         status = smb_raw_setfileinfo(cli->tree, &set);
    1628 
    1629         smbcli_close(cli->tree, fnum);
     1843        smb_raw_exit(cli->session);
     1844        smbcli_deltree(cli->tree, BASEDIR);
    16301845        return ret;
    16311846}
    16321847
     1848static bool test_inheritance_flags(struct torture_context *tctx,
     1849    struct smbcli_state *cli)
     1850{
     1851        NTSTATUS status;
     1852        union smb_open io;
     1853        const char *dname = BASEDIR "\\inheritance";
     1854        const char *fname1 = BASEDIR "\\inheritance\\testfile";
     1855        bool ret = true;
     1856        int fnum=0, fnum2, i, j;
     1857        union smb_fileinfo q;
     1858        union smb_setfileinfo set;
     1859        struct security_descriptor *sd, *sd2, *sd_orig=NULL;
     1860        const char *owner_sid;
     1861        struct {
     1862                uint32_t parent_set_sd_type; /* 3 options */
     1863                uint32_t parent_set_ace_inherit; /* 1 option */
     1864                uint32_t parent_get_sd_type;
     1865                uint32_t parent_get_ace_inherit;
     1866                uint32_t child_get_sd_type;
     1867                uint32_t child_get_ace_inherit;
     1868        } tflags[16]; /* 2^4 */
     1869
     1870        for (i = 0; i < 15; i++) {
     1871                torture_comment(tctx, "i=%d:", i);
     1872
     1873                ZERO_STRUCT(tflags[i]);
     1874
     1875                if (i & 1) {
     1876                        tflags[i].parent_set_sd_type |=
     1877                            SEC_DESC_DACL_AUTO_INHERITED;
     1878                        torture_comment(tctx, "AUTO_INHERITED, ");
     1879                }
     1880                if (i & 2) {
     1881                        tflags[i].parent_set_sd_type |=
     1882                            SEC_DESC_DACL_AUTO_INHERIT_REQ;
     1883                        torture_comment(tctx, "AUTO_INHERIT_REQ, ");
     1884                }
     1885                if (i & 4) {
     1886                        tflags[i].parent_set_sd_type |=
     1887                            SEC_DESC_DACL_PROTECTED;
     1888                        tflags[i].parent_get_sd_type |=
     1889                            SEC_DESC_DACL_PROTECTED;
     1890                        torture_comment(tctx, "PROTECTED, ");
     1891                }
     1892                if (i & 8) {
     1893                        tflags[i].parent_set_ace_inherit |=
     1894                            SEC_ACE_FLAG_INHERITED_ACE;
     1895                        tflags[i].parent_get_ace_inherit |=
     1896                            SEC_ACE_FLAG_INHERITED_ACE;
     1897                        torture_comment(tctx, "INHERITED, ");
     1898                }
     1899
     1900                if ((tflags[i].parent_set_sd_type &
     1901                    (SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_DACL_AUTO_INHERIT_REQ)) ==
     1902                    (SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_DACL_AUTO_INHERIT_REQ)) {
     1903                        tflags[i].parent_get_sd_type |=
     1904                            SEC_DESC_DACL_AUTO_INHERITED;
     1905                        tflags[i].child_get_sd_type |=
     1906                            SEC_DESC_DACL_AUTO_INHERITED;
     1907                        tflags[i].child_get_ace_inherit |=
     1908                            SEC_ACE_FLAG_INHERITED_ACE;
     1909                        torture_comment(tctx, "  ... parent is AUTO INHERITED");
     1910                }
     1911
     1912                if (tflags[i].parent_set_ace_inherit &
     1913                    SEC_ACE_FLAG_INHERITED_ACE) {
     1914                        tflags[i].parent_get_ace_inherit =
     1915                            SEC_ACE_FLAG_INHERITED_ACE;
     1916                        torture_comment(tctx, "  ... parent ACE is INHERITED");
     1917                }
     1918
     1919                torture_comment(tctx, "\n");
     1920        }
     1921
     1922        if (!torture_setup_dir(cli, BASEDIR))
     1923                return false;
     1924
     1925        torture_comment(tctx, "TESTING ACL INHERITANCE FLAGS\n");
     1926
     1927        io.generic.level = RAW_OPEN_NTCREATEX;
     1928        io.ntcreatex.in.root_fid.fnum = 0;
     1929        io.ntcreatex.in.flags = 0;
     1930        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     1931        io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
     1932        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
     1933        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_MASK;
     1934        io.ntcreatex.in.alloc_size = 0;
     1935        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
     1936        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     1937        io.ntcreatex.in.security_flags = 0;
     1938        io.ntcreatex.in.fname = dname;
     1939
     1940        torture_comment(tctx, "creating initial directory %s\n", dname);
     1941        status = smb_raw_open(cli->tree, tctx, &io);
     1942        CHECK_STATUS(status, NT_STATUS_OK);
     1943        fnum = io.ntcreatex.out.file.fnum;
     1944
     1945        torture_comment(tctx, "getting original sd\n");
     1946        q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
     1947        q.query_secdesc.in.file.fnum = fnum;
     1948        q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
     1949        status = smb_raw_fileinfo(cli->tree, tctx, &q);
     1950        CHECK_STATUS(status, NT_STATUS_OK);
     1951        sd_orig = q.query_secdesc.out.sd;
     1952
     1953        owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
     1954        torture_comment(tctx, "owner_sid is %s\n", owner_sid);
     1955
     1956        for (i=0; i < ARRAY_SIZE(tflags); i++) {
     1957                torture_comment(tctx, "setting a new sd on directory, pass #%d\n", i);
     1958
     1959                sd = security_descriptor_dacl_create(tctx,
     1960                                                tflags[i].parent_set_sd_type,
     1961                                                NULL, NULL,
     1962                                                owner_sid,
     1963                                                SEC_ACE_TYPE_ACCESS_ALLOWED,
     1964                                                SEC_FILE_WRITE_DATA | SEC_STD_WRITE_DAC,
     1965                                                SEC_ACE_FLAG_OBJECT_INHERIT |
     1966                                                SEC_ACE_FLAG_CONTAINER_INHERIT |
     1967                                                tflags[i].parent_set_ace_inherit,
     1968                                                SID_WORLD,
     1969                                                SEC_ACE_TYPE_ACCESS_ALLOWED,
     1970                                                SEC_FILE_ALL | SEC_STD_ALL,
     1971                                                0,
     1972                                                NULL);
     1973                set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
     1974                set.set_secdesc.in.file.fnum = fnum;
     1975                set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
     1976                set.set_secdesc.in.sd = sd;
     1977                status = smb_raw_setfileinfo(cli->tree, &set);
     1978                CHECK_STATUS(status, NT_STATUS_OK);
     1979
     1980                /*
     1981                 * Check DACL we just set, except change the bits to what they
     1982                 * should be.
     1983                 */
     1984                torture_comment(tctx, "  checking new sd\n");
     1985
     1986                /* REQ bit should always be false. */
     1987                sd->type &= ~SEC_DESC_DACL_AUTO_INHERIT_REQ;
     1988
     1989                if ((tflags[i].parent_get_sd_type & SEC_DESC_DACL_AUTO_INHERITED) == 0)
     1990                        sd->type &= ~SEC_DESC_DACL_AUTO_INHERITED;
     1991
     1992                q.query_secdesc.in.file.fnum = fnum;
     1993                q.query_secdesc.in.secinfo_flags = SECINFO_DACL;
     1994                status = smb_raw_fileinfo(cli->tree, tctx, &q);
     1995                CHECK_STATUS(status, NT_STATUS_OK);
     1996                CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd);
     1997
     1998                /* Create file. */
     1999                torture_comment(tctx, "  creating file %s\n", fname1);
     2000                io.ntcreatex.in.fname = fname1;
     2001                io.ntcreatex.in.create_options = 0;
     2002                io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     2003                io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     2004                io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
     2005                status = smb_raw_open(cli->tree, tctx, &io);
     2006                CHECK_STATUS(status, NT_STATUS_OK);
     2007                fnum2 = io.ntcreatex.out.file.fnum;
     2008                CHECK_ACCESS_FLAGS(fnum2, SEC_RIGHTS_FILE_ALL);
     2009
     2010                q.query_secdesc.in.file.fnum = fnum2;
     2011                q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
     2012                status = smb_raw_fileinfo(cli->tree, tctx, &q);
     2013                CHECK_STATUS(status, NT_STATUS_OK);
     2014
     2015                torture_comment(tctx, "  checking sd on file %s\n", fname1);
     2016                sd2 = security_descriptor_dacl_create(tctx,
     2017                                                 tflags[i].child_get_sd_type,
     2018                                                 owner_sid, NULL,
     2019                                                 owner_sid,
     2020                                                 SEC_ACE_TYPE_ACCESS_ALLOWED,
     2021                                                 SEC_FILE_WRITE_DATA | SEC_STD_WRITE_DAC,
     2022                                                 tflags[i].child_get_ace_inherit,
     2023                                                 NULL);
     2024                CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
     2025
     2026                /*
     2027                 * Set new sd on file ... prove that the bits have nothing to
     2028                 * do with the parents bits when manually setting an ACL. The
     2029                 * _AUTO_INHERITED bit comes directly from the ACL set.
     2030                 */
     2031                for (j = 0; j < ARRAY_SIZE(tflags); j++) {
     2032                        torture_comment(tctx, "  setting new file sd, pass #%d\n", j);
     2033
     2034                        /* Change sd type. */
     2035                        sd2->type &= ~(SEC_DESC_DACL_AUTO_INHERITED |
     2036                            SEC_DESC_DACL_AUTO_INHERIT_REQ |
     2037                            SEC_DESC_DACL_PROTECTED);
     2038                        sd2->type |= tflags[j].parent_set_sd_type;
     2039
     2040                        sd2->dacl->aces[0].flags &=
     2041                            ~SEC_ACE_FLAG_INHERITED_ACE;
     2042                        sd2->dacl->aces[0].flags |=
     2043                            tflags[j].parent_set_ace_inherit;
     2044
     2045                        set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
     2046                        set.set_secdesc.in.file.fnum = fnum2;
     2047                        set.set_secdesc.in.secinfo_flags = SECINFO_DACL;
     2048                        set.set_secdesc.in.sd = sd2;
     2049                        status = smb_raw_setfileinfo(cli->tree, &set);
     2050                        CHECK_STATUS(status, NT_STATUS_OK);
     2051
     2052                        /* Check DACL we just set. */
     2053                        sd2->type &= ~SEC_DESC_DACL_AUTO_INHERIT_REQ;
     2054                        if ((tflags[j].parent_get_sd_type & SEC_DESC_DACL_AUTO_INHERITED) == 0)
     2055                                sd2->type &= ~SEC_DESC_DACL_AUTO_INHERITED;
     2056
     2057                        q.query_secdesc.in.file.fnum = fnum2;
     2058                        q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
     2059                        status = smb_raw_fileinfo(cli->tree, tctx, &q);
     2060                        CHECK_STATUS(status, NT_STATUS_OK);
     2061
     2062                        CHECK_SECURITY_DESCRIPTOR(q.query_secdesc.out.sd, sd2);
     2063                }
     2064
     2065                smbcli_close(cli->tree, fnum2);
     2066                smbcli_unlink(cli->tree, fname1);
     2067        }
     2068
     2069done:
     2070        smbcli_close(cli->tree, fnum);
     2071        smb_raw_exit(cli->session);
     2072        smbcli_deltree(cli->tree, BASEDIR);
     2073        return ret;
     2074}
    16332075
    16342076/*
    16352077  test dynamic acl inheritance
     2078  Test copied to smb2/acls.c for SMB2.
    16362079*/
    16372080static bool test_inheritance_dynamic(struct torture_context *tctx,
     
    16402083        NTSTATUS status;
    16412084        union smb_open io;
    1642         const char *dname = BASEDIR "\\inheritance";
    1643         const char *fname1 = BASEDIR "\\inheritance\\testfile";
     2085        const char *dname = BASEDIR "\\inheritance2";
     2086        const char *fname1 = BASEDIR "\\inheritance2\\testfile";
    16442087        bool ret = true;
    16452088        int fnum=0, fnum2;
     
    16492092        const char *owner_sid;
    16502093       
    1651         printf("TESTING DYNAMIC ACL INHERITANCE\n");
    1652 
    1653         if (!torture_setup_dir(cli, BASEDIR)) {
     2094        torture_comment(tctx, "TESTING DYNAMIC ACL INHERITANCE\n");
     2095
     2096        if (!torture_setup_dir(cli, BASEDIR))
    16542097                return false;
    1655         }
    16562098
    16572099        io.generic.level = RAW_OPEN_NTCREATEX;
    1658         io.ntcreatex.in.root_fid = 0;
     2100        io.ntcreatex.in.root_fid.fnum = 0;
    16592101        io.ntcreatex.in.flags = 0;
    16602102        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     
    16722114        fnum = io.ntcreatex.out.file.fnum;
    16732115
    1674         printf("get the original sd\n");
     2116        torture_comment(tctx, "get the original sd\n");
    16752117        q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
    16762118        q.query_secdesc.in.file.fnum = fnum;
     
    16822124        owner_sid = dom_sid_string(tctx, sd_orig->owner_sid);
    16832125
    1684         printf("owner_sid is %s\n", owner_sid);
     2126        torture_comment(tctx, "owner_sid is %s\n", owner_sid);
    16852127
    16862128        sd = security_descriptor_dacl_create(tctx,
     
    17002142        CHECK_STATUS(status, NT_STATUS_OK);
    17012143
    1702         printf("create a file with an inherited acl\n");
     2144        torture_comment(tctx, "create a file with an inherited acl\n");
    17032145        io.ntcreatex.in.fname = fname1;
    17042146        io.ntcreatex.in.create_options = 0;
     
    17102152        smbcli_close(cli->tree, fnum2);
    17112153
    1712         printf("try and access file with base rights - should be OK\n");
     2154        torture_comment(tctx, "try and access file with base rights - should be OK\n");
    17132155        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
    17142156        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
     
    17182160        smbcli_close(cli->tree, fnum2);
    17192161
    1720         printf("try and access file with extra rights - should be denied\n");
     2162        torture_comment(tctx, "try and access file with extra rights - should be denied\n");
    17212163        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA | SEC_FILE_EXECUTE;
    17222164        status = smb_raw_open(cli->tree, tctx, &io);
    17232165        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    17242166
    1725         printf("update parent sd\n");
     2167        torture_comment(tctx, "update parent sd\n");
    17262168        sd = security_descriptor_dacl_create(tctx,
    17272169                                        0, NULL, NULL,
     
    17372179        CHECK_STATUS(status, NT_STATUS_OK);
    17382180
    1739         printf("try and access file with base rights - should be OK\n");
     2181        torture_comment(tctx, "try and access file with base rights - should be OK\n");
    17402182        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
    17412183        status = smb_raw_open(cli->tree, tctx, &io);
     
    17452187
    17462188
    1747         printf("try and access now - should be OK if dynamic inheritance works\n");
     2189        torture_comment(tctx, "try and access now - should be OK if dynamic inheritance works\n");
    17482190        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA | SEC_FILE_EXECUTE;
    17492191        status = smb_raw_open(cli->tree, tctx, &io);
    17502192        if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
    1751                 printf("Server does not have dynamic inheritance\n");
     2193                torture_comment(tctx, "Server does not have dynamic inheritance\n");
    17522194        }
    17532195        if (NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
    1754                 printf("Server does have dynamic inheritance\n");
     2196                torture_comment(tctx, "Server does have dynamic inheritance\n");
    17552197        }
    17562198        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
     
    17592201
    17602202done:
    1761         printf("put back original sd\n");
     2203        torture_comment(tctx, "put back original sd\n");
    17622204        set.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
    17632205        set.set_secdesc.in.file.fnum = fnum;
     
    17682210        smbcli_close(cli->tree, fnum);
    17692211        smbcli_rmdir(cli->tree, dname);
     2212        smb_raw_exit(cli->session);
     2213        smbcli_deltree(cli->tree, BASEDIR);
    17702214
    17712215        return ret;
     
    17842228        if (NT_STATUS_IS_OK(status)) { \
    17852229                if (!(granted & access)) {\
    1786                         printf("(%s) %s but flags 0x%08X are not granted! granted[0x%08X] desired[0x%08X]\n", \
     2230                        ret = false; \
     2231                        torture_result(tctx, TORTURE_FAIL, "(%s) %s but flags 0x%08X are not granted! granted[0x%08X] desired[0x%08X]\n", \
    17872232                               __location__, nt_errstr(status), access, granted, desired); \
    1788                         ret = false; \
    17892233                        goto done; \
    17902234                } \
    17912235        } else { \
    17922236                if (granted & access) {\
    1793                         printf("(%s) %s but flags 0x%08X are granted! granted[0x%08X] desired[0x%08X]\n", \
     2237                        ret = false; \
     2238                        torture_result(tctx, TORTURE_FAIL, "(%s) %s but flags 0x%08X are granted! granted[0x%08X] desired[0x%08X]\n", \
    17942239                               __location__, nt_errstr(status), access, granted, desired); \
    1795                         ret = false; \
    17962240                        goto done; \
    17972241                } \
     
    18002244} while (0)
    18012245
    1802 /* test what access mask is needed for getting and setting security_descriptors */
     2246/* test what access mask is needed for getting and setting security_descriptors
     2247  Test copied to smb2/acls.c for SMB2. */
    18032248static bool test_sd_get_set(struct torture_context *tctx,
    18042249                                                        struct smbcli_state *cli)
     
    18362281        uint64_t set_sacl_bits  = SEC_FLAG_SYSTEM_SECURITY;
    18372282
    1838         printf("TESTING ACCESS MASKS FOR SD GET/SET\n");
     2283        if (!torture_setup_dir(cli, BASEDIR))
     2284                return false;
     2285
     2286        torture_comment(tctx, "TESTING ACCESS MASKS FOR SD GET/SET\n");
    18392287
    18402288        /* first create a file with full access for everyone */
     
    18492297        sd->sacl = NULL;
    18502298        io.ntcreatex.level = RAW_OPEN_NTTRANS_CREATE;
    1851         io.ntcreatex.in.root_fid = 0;
     2299        io.ntcreatex.in.root_fid.fnum = 0;
    18522300        io.ntcreatex.in.flags = 0;
    18532301        io.ntcreatex.in.access_mask = SEC_GENERIC_ALL;
     
    19792427        smbcli_close(cli->tree, fnum);
    19802428        smbcli_unlink(cli->tree, fname);
     2429        smb_raw_exit(cli->session);
     2430        smbcli_deltree(cli->tree, BASEDIR);
    19812431
    19822432        return ret;
     
    19872437   basic testing of security descriptor calls
    19882438*/
    1989 bool torture_raw_acls(struct torture_context *tctx, struct smbcli_state *cli)
     2439struct torture_suite *torture_raw_acls(TALLOC_CTX *mem_ctx)
    19902440{
    1991         bool ret = true;
    1992 
    1993         if (!torture_setup_dir(cli, BASEDIR)) {
    1994                 return false;
    1995         }
    1996 
    1997         ret &= test_sd(tctx, cli);
    1998         ret &= test_nttrans_create(tctx, cli);
    1999         ret &= test_nttrans_create_null_dacl(tctx, cli);
    2000         ret &= test_creator_sid(tctx, cli);
    2001         ret &= test_generic_bits(tctx, cli);
    2002         ret &= test_owner_bits(tctx, cli);
    2003         ret &= test_inheritance(tctx, cli);
    2004         ret &= test_inheritance_dynamic(tctx, cli);
    2005         ret &= test_sd_get_set(tctx, cli);
    2006 
    2007         smb_raw_exit(cli->session);
    2008         smbcli_deltree(cli->tree, BASEDIR);
    2009 
    2010         return ret;
     2441        struct torture_suite *suite = torture_suite_create(mem_ctx, "acls");
     2442
     2443        torture_suite_add_1smb_test(suite, "sd", test_sd);
     2444        torture_suite_add_1smb_test(suite, "create_file", test_nttrans_create_file);
     2445        torture_suite_add_1smb_test(suite, "create_dir", test_nttrans_create_dir);
     2446        torture_suite_add_1smb_test(suite, "nulldacl", test_nttrans_create_null_dacl);
     2447        torture_suite_add_1smb_test(suite, "creator", test_creator_sid);
     2448        torture_suite_add_1smb_test(suite, "generic", test_generic_bits);
     2449        torture_suite_add_1smb_test(suite, "owner", test_owner_bits);
     2450        torture_suite_add_1smb_test(suite, "inheritance", test_inheritance);
     2451
     2452        /* torture_suite_add_1smb_test(suite, "INHERITFLAGS", test_inheritance_flags); */
     2453        torture_suite_add_1smb_test(suite, "dynamic", test_inheritance_dynamic);
     2454        /* XXX This test does not work against XP or Vista.
     2455        torture_suite_add_1smb_test(suite, "GETSET", test_sd_get_set);
     2456        */
     2457
     2458        return suite;
    20112459}
  • trunk/server/source4/torture/raw/chkpath.c

    r414 r745  
    2020#include "includes.h"
    2121#include "system/locale.h"
    22 #include "torture/torture.h"
    2322#include "libcli/raw/libcliraw.h"
    24 #include "libcli/raw/raw_proto.h"
    2523#include "libcli/libcli.h"
    2624#include "torture/util.h"
     
    179177          give different NT status returns for chkpth and findfirst. */
    180178
    181         printf("testing findfirst on %s\n", "\\.\\\\\\\\\\\\.");
     179        printf("Testing findfirst on %s\n", "\\.\\\\\\\\\\\\.");
    182180        status = single_search(cli, tctx, "\\.\\\\\\\\\\\\.");
    183181        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID,NT_STATUS_DOS(ERRDOS,ERRinvalidname));
     
    186184
    187185        /* We expect this open to fail with the same error code as the chkpath below. */
    188         printf("testing Open on %s\n", "\\.\\\\\\\\\\\\.");
     186        printf("Testing Open on %s\n", "\\.\\\\\\\\\\\\.");
    189187        /* findfirst seems to fail with a different error. */
    190188        fnum1 = smbcli_nt_create_full(cli->tree, "\\.\\\\\\\\\\\\.",
     
    227225
    228226        /* We expect this open to fail with the same error code as the chkpath below. */
    229         printf("testing Open on %s\n", BASEDIR".\\.\\.\\.\\foo\\..\\.\\");
     227        printf("Testing Open on %s\n", BASEDIR".\\.\\.\\.\\foo\\..\\.\\");
    230228        /* findfirst seems to fail with a different error. */
    231229        fnum1 = smbcli_nt_create_full(cli->tree, BASEDIR".\\.\\.\\.\\foo\\..\\.\\",
     
    240238        CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_NOT_FOUND,NT_STATUS_DOS(ERRDOS,ERRbadpath));
    241239
    242         printf("testing findfirst on %s\n", BASEDIR".\\.\\.\\.\\foo\\..\\.\\");
     240        printf("Testing findfirst on %s\n", BASEDIR".\\.\\.\\.\\foo\\..\\.\\");
    243241        status = single_search(cli, tctx, BASEDIR".\\.\\.\\.\\foo\\..\\.\\");
    244242        CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_NOT_FOUND,NT_STATUS_DOS(ERRDOS,ERRbadpath));
     
    246244        /* We expect this open to fail with the same error code as the chkpath below. */
    247245        /* findfirst seems to fail with a different error. */
    248         printf("testing Open on %s\n", BASEDIR "\\nt\\V S\\VB98\\vb6.exe\\3");
     246        printf("Testing Open on %s\n", BASEDIR "\\nt\\V S\\VB98\\vb6.exe\\3");
    249247        fnum1 = smbcli_nt_create_full(cli->tree, BASEDIR "\\nt\\V S\\VB98\\vb6.exe\\3",
    250248                                      0, SEC_RIGHTS_FILE_ALL,
  • trunk/server/source4/torture/raw/close.c

    r414 r745  
    6868        CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
    6969       
    70         printf("testing close.in.write_time\n");
     70        printf("Testing close.in.write_time\n");
    7171
    7272        /* the file should have the write time set */
     
    8484        }
    8585
    86         printf("testing other times\n");
     86        printf("Testing other times\n");
    8787
    8888        /* none of the other times should be set to that time */
     
    134134        }
    135135
    136         printf("testing splclose\n");
     136        printf("Testing splclose\n");
    137137
    138138        /* check splclose on a file */
     
    143143        CHECK_STATUS(status, NT_STATUS_DOS(ERRSRV, ERRerror));
    144144
    145         printf("testing flush\n");
     145        printf("Testing flush\n");
    146146        smbcli_close(cli->tree, fnum);
    147147
  • trunk/server/source4/torture/raw/composite.c

    r414 r745  
    6666        io1.in.size  = len;
    6767
    68         printf("testing savefile\n");
     68        printf("Testing savefile\n");
    6969
    7070        status = smb_composite_savefile(cli->tree, &io1);
     
    7676        io2.in.fname = fname;
    7777
    78         printf("testing parallel loadfile with %d ops\n", num_ops);
     78        printf("Testing parallel loadfile with %d ops\n", num_ops);
    7979
    8080        c = talloc_array(tctx, struct composite_context *, num_ops);
     
    146146        io1.in.size  = len;
    147147
    148         printf("testing savefile\n");
     148        printf("Testing savefile\n");
    149149
    150150        status = smb_composite_savefile(cli->tree, &io1);
     
    155155
    156156        io2.in.dest_host = torture_setting_string(tctx, "host", NULL);
    157         io2.in.ports = lp_smb_ports(tctx->lp_ctx);
     157        io2.in.ports = lpcfg_smb_ports(tctx->lp_ctx);
    158158        io2.in.called_name = torture_setting_string(tctx, "host", NULL);
    159159        io2.in.service = torture_setting_string(tctx, "share", NULL);
     
    161161
    162162        io2.in.credentials = cmdline_credentials;
    163         io2.in.workgroup  = lp_workgroup(tctx->lp_ctx);
     163        io2.in.workgroup  = lpcfg_workgroup(tctx->lp_ctx);
    164164        io2.in.filename = fname;
    165         io2.in.resolve_ctx = lp_resolve_context(tctx->lp_ctx);
    166         io2.in.iconv_convenience = lp_iconv_convenience(tctx->lp_ctx);
    167         io2.in.gensec_settings = lp_gensec_settings(tctx, tctx->lp_ctx);
    168         lp_smbcli_options(tctx->lp_ctx, &io2.in.options);
    169         lp_smbcli_session_options(tctx->lp_ctx, &io2.in.session_options);
    170 
    171         printf("testing parallel fetchfile with %d ops\n", torture_numops);
     165        io2.in.resolve_ctx = lpcfg_resolve_context(tctx->lp_ctx);
     166        io2.in.gensec_settings = lpcfg_gensec_settings(tctx, tctx->lp_ctx);
     167        lpcfg_smbcli_options(tctx->lp_ctx, &io2.in.options);
     168        lpcfg_smbcli_session_options(tctx->lp_ctx, &io2.in.session_options);
     169
     170        printf("Testing parallel fetchfile with %d ops\n", torture_numops);
    172171
    173172        event_ctx = cli->transport->socket->event.ctx;
     
    285284        /* set parameters for appendacl async call */
    286285
    287         printf("testing parallel appendacl with %d ops\n", num_ops);
     286        printf("Testing parallel appendacl with %d ops\n", num_ops);
    288287
    289288        c = talloc_array(tctx, struct composite_context *, num_ops);
     
    348347
    349348        io1.in.dest_host = torture_setting_string(tctx, "host", NULL);
    350         io1.in.dest_ports = lp_smb_ports(tctx->lp_ctx);
    351         io1.in.socket_options = lp_socket_options(tctx->lp_ctx);
     349        io1.in.dest_ports = lpcfg_smb_ports(tctx->lp_ctx);
     350        io1.in.socket_options = lpcfg_socket_options(tctx->lp_ctx);
    352351        io1.in.called_name = torture_setting_string(tctx, "host", NULL);
    353352        io1.in.service = torture_setting_string(tctx, "share", NULL);
    354353        io1.in.service_type = "A:";
    355354        io1.in.credentials = cmdline_credentials;
    356         io1.in.workgroup = lp_workgroup(tctx->lp_ctx);
     355        io1.in.workgroup = lpcfg_workgroup(tctx->lp_ctx);
    357356        io1.in.level = RAW_QFS_OBJECTID_INFORMATION;
    358         io1.in.iconv_convenience = lp_iconv_convenience(tctx->lp_ctx);
    359         io1.in.gensec_settings = lp_gensec_settings(tctx, tctx->lp_ctx);
    360 
    361         printf("testing parallel queryfsinfo [Object ID] with %d ops\n", torture_numops);
     357        io1.in.gensec_settings = lpcfg_gensec_settings(tctx, tctx->lp_ctx);
     358
     359        printf("Testing parallel queryfsinfo [Object ID] with %d ops\n",
     360                  torture_numops);
    362361
    363362        event_ctx = tctx->ev;
     
    365364
    366365        for (i=0; i<torture_numops; i++) {
    367                 c[i] = smb_composite_fsinfo_send(cli->tree, &io1, lp_resolve_context(tctx->lp_ctx));
     366                c[i] = smb_composite_fsinfo_send(cli->tree, &io1, lpcfg_resolve_context(tctx->lp_ctx));
    368367                c[i]->async.fn = loadfile_complete;
    369368                c[i]->async.private_data = count;
  • trunk/server/source4/torture/raw/context.c

    r414 r745  
    1919
    2020#include "includes.h"
    21 #include "torture/torture.h"
    2221#include "libcli/raw/libcliraw.h"
    2322#include "libcli/raw/raw_proto.h"
    24 #include "libcli/composite/composite.h"
    2523#include "libcli/smb_composite/smb_composite.h"
    2624#include "lib/cmdline/popt_common.h"
    27 #include "lib/events/events.h"
    2825#include "libcli/libcli.h"
    2926#include "torture/util.h"
     
    9390        printf("create a second security context on the same transport\n");
    9491
    95         lp_smbcli_session_options(tctx->lp_ctx, &options);
    96         gensec_settings = lp_gensec_settings(tctx, tctx->lp_ctx);
     92        lpcfg_smbcli_session_options(tctx->lp_ctx, &options);
     93        gensec_settings = lpcfg_gensec_settings(tctx, tctx->lp_ctx);
    9794
    9895        session = smbcli_session_init(cli->transport, tctx, false, options);
     
    10097        setup.in.sesskey = cli->transport->negotiate.sesskey;
    10198        setup.in.capabilities = cli->transport->negotiate.capabilities; /* ignored in secondary session setup, except by our libs, which care about the extended security bit */
    102         setup.in.workgroup = lp_workgroup(tctx->lp_ctx);
     99        setup.in.workgroup = lpcfg_workgroup(tctx->lp_ctx);
    103100
    104101        setup.in.credentials = cmdline_credentials;
     
    116113        setup.in.sesskey = cli->transport->negotiate.sesskey;
    117114        setup.in.capabilities = cli->transport->negotiate.capabilities; /* ignored in secondary session setup, except by our libs, which care about the extended security bit */
    118         setup.in.workgroup = lp_workgroup(tctx->lp_ctx);
     115        setup.in.workgroup = lpcfg_workgroup(tctx->lp_ctx);
    119116
    120117        setup.in.credentials = cmdline_credentials;
     
    143140                setup.in.sesskey = cli->transport->negotiate.sesskey;
    144141                setup.in.capabilities &= ~CAP_EXTENDED_SECURITY; /* force a non extended security login (should fail) */
    145                 setup.in.workgroup = lp_workgroup(tctx->lp_ctx);
     142                setup.in.workgroup = lpcfg_workgroup(tctx->lp_ctx);
    146143       
    147144                setup.in.credentials = cmdline_credentials;
     
    156153                setup.in.sesskey = cli->transport->negotiate.sesskey;
    157154                setup.in.capabilities &= ~CAP_EXTENDED_SECURITY; /* force a non extended security login (should fail) */
    158                 setup.in.workgroup = lp_workgroup(tctx->lp_ctx);
     155                setup.in.workgroup = lpcfg_workgroup(tctx->lp_ctx);
    159156               
    160157                anon_creds = cli_credentials_init(tctx);
     
    176173        printf("create a file using the new vuid\n");
    177174        io.generic.level = RAW_OPEN_NTCREATEX;
    178         io.ntcreatex.in.root_fid = 0;
     175        io.ntcreatex.in.root_fid.fnum = 0;
    179176        io.ntcreatex.in.flags = 0;
    180177        io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    233230                setups[i].in.sesskey = cli->transport->negotiate.sesskey;
    234231                setups[i].in.capabilities = cli->transport->negotiate.capabilities; /* ignored in secondary session setup, except by our libs, which care about the extended security bit */
    235                 setups[i].in.workgroup = lp_workgroup(tctx->lp_ctx);
     232                setups[i].in.workgroup = lpcfg_workgroup(tctx->lp_ctx);
    236233               
    237234                setups[i].in.credentials = cmdline_credentials;
     
    312309        printf("create a file using the new tid\n");
    313310        io.generic.level = RAW_OPEN_NTCREATEX;
    314         io.ntcreatex.in.root_fid = 0;
     311        io.ntcreatex.in.root_fid.fnum = 0;
    315312        io.ntcreatex.in.flags = 0;
    316313        io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    398395        host  = torture_setting_string(tctx, "host", NULL);
    399396
    400         lp_smbcli_session_options(tctx->lp_ctx, &options);
     397        lpcfg_smbcli_session_options(tctx->lp_ctx, &options);
    401398
    402399        printf("create the first new sessions\n");
     
    404401        setup.in.sesskey = cli->transport->negotiate.sesskey;
    405402        setup.in.capabilities = cli->transport->negotiate.capabilities;
    406         setup.in.workgroup = lp_workgroup(tctx->lp_ctx);
     403        setup.in.workgroup = lpcfg_workgroup(tctx->lp_ctx);
    407404        setup.in.credentials = cmdline_credentials;
    408         setup.in.gensec_settings = lp_gensec_settings(tctx, tctx->lp_ctx);
     405        setup.in.gensec_settings = lpcfg_gensec_settings(tctx, tctx->lp_ctx);
    409406        status = smb_composite_sesssetup(session1, &setup);
    410407        CHECK_STATUS(status, NT_STATUS_OK);
     
    426423        printf("create a file using vuid1\n");
    427424        io.generic.level = RAW_OPEN_NTCREATEX;
    428         io.ntcreatex.in.root_fid = 0;
     425        io.ntcreatex.in.root_fid.fnum = 0;
    429426        io.ntcreatex.in.flags = 0;
    430427        io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    461458        setup.in.sesskey = cli->transport->negotiate.sesskey;
    462459        setup.in.capabilities = cli->transport->negotiate.capabilities;
    463         setup.in.workgroup = lp_workgroup(tctx->lp_ctx);
     460        setup.in.workgroup = lpcfg_workgroup(tctx->lp_ctx);
    464461        setup.in.credentials = cmdline_credentials;
    465         setup.in.gensec_settings = lp_gensec_settings(tctx, tctx->lp_ctx);
     462        setup.in.gensec_settings = lpcfg_gensec_settings(tctx, tctx->lp_ctx);
    466463        status = smb_composite_sesssetup(session2, &setup);
    467464        CHECK_STATUS(status, NT_STATUS_OK);
     
    474471        printf("create a file using vuid2\n");
    475472        io.generic.level = RAW_OPEN_NTCREATEX;
    476         io.ntcreatex.in.root_fid = 0;
     473        io.ntcreatex.in.root_fid.fnum = 0;
    477474        io.ntcreatex.in.flags = 0;
    478475        io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    552549        cli->session->pid = pid1;
    553550        io.generic.level = RAW_OPEN_NTCREATEX;
    554         io.ntcreatex.in.root_fid = 0;
     551        io.ntcreatex.in.root_fid.fnum = 0;
    555552        io.ntcreatex.in.flags = 0;
    556553        io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    655652        }
    656653
    657         lp_smbcli_session_options(tctx->lp_ctx, &options);
     654        lpcfg_smbcli_session_options(tctx->lp_ctx, &options);
    658655
    659656        printf("create a second security context on the same transport\n");
     
    662659        setup.in.sesskey = cli->transport->negotiate.sesskey;
    663660        setup.in.capabilities = cli->transport->negotiate.capabilities; /* ignored in secondary session setup, except by our libs, which care about the extended security bit */
    664         setup.in.workgroup = lp_workgroup(tctx->lp_ctx);
     661        setup.in.workgroup = lpcfg_workgroup(tctx->lp_ctx);
    665662        setup.in.credentials = cmdline_credentials;
    666         setup.in.gensec_settings = lp_gensec_settings(tctx, tctx->lp_ctx);
     663        setup.in.gensec_settings = lpcfg_gensec_settings(tctx, tctx->lp_ctx);
    667664
    668665        status = smb_composite_sesssetup(session, &setup);
     
    678675        cli->session->vuid = vuid1;
    679676        io.generic.level = RAW_OPEN_NTCREATEX;
    680         io.ntcreatex.in.root_fid = 0;
     677        io.ntcreatex.in.root_fid.fnum = 0;
    681678        io.ntcreatex.in.flags = 0;
    682679        io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    786783        cli->tree->tid = tid1;
    787784        io.generic.level = RAW_OPEN_NTCREATEX;
    788         io.ntcreatex.in.root_fid = 0;
     785        io.ntcreatex.in.root_fid.fnum = 0;
    789786        io.ntcreatex.in.flags = 0;
    790787        io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    817814        cli->tree->tid = tid2;
    818815        io.generic.level = RAW_OPEN_NTCREATEX;
    819         io.ntcreatex.in.root_fid = 0;
     816        io.ntcreatex.in.root_fid.fnum = 0;
    820817        io.ntcreatex.in.flags = 0;
    821818        io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    907904{
    908905        bool ret = true;
    909         if (lp_use_spnego(torture->lp_ctx)) {
     906        if (lpcfg_use_spnego(torture->lp_ctx)) {
    910907                ret &= torture_raw_context_int(torture, cli);
    911                 lp_set_cmdline(torture->lp_ctx, "use spnego", "False");
     908                lpcfg_set_cmdline(torture->lp_ctx, "use spnego", "False");
    912909        }
    913910
  • trunk/server/source4/torture/raw/eas.c

    r414 r745  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33
     
    66   Copyright (C) Andrew Tridgell 2004
    77   Copyright (C) Guenter Kukkukk 2005
    8    
     8
    99   This program is free software; you can redistribute it and/or modify
    1010   it under the terms of the GNU General Public License as published by
    1111   the Free Software Foundation; either version 3 of the License, or
    1212   (at your option) any later version.
    13    
     13
    1414   This program is distributed in the hope that it will be useful,
    1515   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1616   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1717   GNU General Public License for more details.
    18    
     18
    1919   You should have received a copy of the GNU General Public License
    2020   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    3030
    3131#define CHECK_STATUS(status, correct) do { \
    32         if (!NT_STATUS_EQUAL(status, correct)) { \
    33                 printf("(%s) Incorrect status %s - should be %s\n", \
    34                        __location__, nt_errstr(status), nt_errstr(correct)); \
    35                 ret = false; \
    36                 goto done; \
    37         }} while (0)
     32        torture_assert_ntstatus_equal_goto(tctx, status, correct, ret, done, "Incorrect status"); \
     33        } while (0)
    3834
    3935static  bool maxeadebug; /* need that here, to allow no file delete in debug case */
    4036
    41 static bool check_ea(struct smbcli_state *cli, 
     37static bool check_ea(struct smbcli_state *cli,
    4238                     const char *fname, const char *eaname, const char *value)
    4339{
     
    4642}
    4743
    48 static bool test_eas(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
     44static bool test_eas(struct smbcli_state *cli, struct torture_context *tctx)
    4945{
    5046        NTSTATUS status;
     
    5551        int fnum = -1;
    5652
    57         printf("TESTING SETFILEINFO EA_SET\n");
     53        torture_comment(tctx, "TESTING SETFILEINFO EA_SET\n");
    5854
    5955        io.generic.level = RAW_OPEN_NTCREATEX;
    60         io.ntcreatex.in.root_fid = 0;
     56        io.ntcreatex.in.root_fid.fnum = 0;
    6157        io.ntcreatex.in.flags = 0;
    6258        io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
    6359        io.ntcreatex.in.create_options = 0;
    6460        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
    65         io.ntcreatex.in.share_access = 
    66                 NTCREATEX_SHARE_ACCESS_READ | 
     61        io.ntcreatex.in.share_access =
     62                NTCREATEX_SHARE_ACCESS_READ |
    6763                NTCREATEX_SHARE_ACCESS_WRITE;
    6864        io.ntcreatex.in.alloc_size = 0;
     
    7167        io.ntcreatex.in.security_flags = 0;
    7268        io.ntcreatex.in.fname = fname;
    73         status = smb_raw_open(cli->tree, mem_ctx, &io);
     69        status = smb_raw_open(cli->tree, tctx, &io);
    7470        CHECK_STATUS(status, NT_STATUS_OK);
    7571        fnum = io.ntcreatex.out.file.fnum;
    76        
     72
    7773        ret &= check_ea(cli, fname, "EAONE", NULL);
    7874
    79         printf("Adding first two EAs\n");
     75        torture_comment(tctx, "Adding first two EAs\n");
    8076        setfile.generic.level = RAW_SFILEINFO_EA_SET;
    8177        setfile.generic.in.file.fnum = fnum;
    8278        setfile.ea_set.in.num_eas = 2;
    83         setfile.ea_set.in.eas = talloc_array(mem_ctx, struct ea_struct, 2);
     79        setfile.ea_set.in.eas = talloc_array(tctx, struct ea_struct, 2);
    8480        setfile.ea_set.in.eas[0].flags = 0;
    8581        setfile.ea_set.in.eas[0].name.s = "EAONE";
     
    9591        ret &= check_ea(cli, fname, "SECONDEA", "ValueTwo");
    9692
    97         printf("Modifying 2nd EA\n");
     93        torture_comment(tctx, "Modifying 2nd EA\n");
    9894        setfile.ea_set.in.num_eas = 1;
    9995        setfile.ea_set.in.eas[0].name.s = "SECONDEA";
     
    105101        ret &= check_ea(cli, fname, "SECONDEA", " Changed Value");
    106102
    107         printf("Setting a NULL EA\n");
     103        torture_comment(tctx, "Setting a NULL EA\n");
    108104        setfile.ea_set.in.eas[0].value = data_blob(NULL, 0);
    109105        setfile.ea_set.in.eas[0].name.s = "NULLEA";
     
    115111        ret &= check_ea(cli, fname, "NULLEA", NULL);
    116112
    117         printf("Deleting first EA\n");
     113        torture_comment(tctx, "Deleting first EA\n");
    118114        setfile.ea_set.in.eas[0].flags = 0;
    119115        setfile.ea_set.in.eas[0].name.s = "EAONE";
     
    125121        ret &= check_ea(cli, fname, "SECONDEA", " Changed Value");
    126122
    127         printf("Deleting second EA\n");
     123        torture_comment(tctx, "Deleting second EA\n");
    128124        setfile.ea_set.in.eas[0].flags = 0;
    129125        setfile.ea_set.in.eas[0].name.s = "SECONDEA";
     
    144140 * Helper function to retrieve the max. ea size for one ea name
    145141 */
    146 static int test_one_eamax(struct smbcli_state *cli, const int fnum,
    147                           const char *eaname, DATA_BLOB eablob,
    148                           const int eastart, const int eadebug)
     142static int test_one_eamax(struct torture_context *tctx,
     143                          struct smbcli_state *cli, const int fnum,
     144                          const char *eaname, DATA_BLOB eablob,
     145                          const int eastart, const int eadebug)
    149146{
    150147        NTSTATUS status;
     
    168165        do {
    169166                if (eadebug) {
    170                         printf ("Testing EA size: %d\n", i);
     167                        torture_comment(tctx, "Testing EA size: %d\n", i);
    171168                }
    172169                setfile.ea_set.in.eas->value.length = i;
     
    176173                if (NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
    177174                        if (eadebug) {
    178                                 printf ("[%s] EA size %d succeeded! "
    179                                         "(high=%d low=%d)\n", 
     175                                torture_comment(tctx, "[%s] EA size %d succeeded! "
     176                                        "(high=%d low=%d)\n",
    180177                                        eaname, i, high, low);
    181178                        }
    182179                        low = i;
    183180                        if (low == maxeasize) {
    184                                 printf ("Max. EA size for \"%s\"=%d "
    185                                         "[but could be possibly larger]\n", 
     181                                torture_comment(tctx, "Max. EA size for \"%s\"=%d "
     182                                        "[but could be possibly larger]\n",
    186183                                        eaname, low);
    187184                                break;
    188185                        }
    189186                        if (high - low == 1 && high != maxeasize) {
    190                                 printf ("Max. EA size for \"%s\"=%d\n",
     187                                torture_comment(tctx, "Max. EA size for \"%s\"=%d\n",
    191188                                        eaname, low);
    192189                                break;
     
    195192                } else {
    196193                        if (eadebug) {
    197                                 printf ("[%s] EA size %d failed!    "
    198                                         "(high=%d low=%d) [%s]\n", 
    199                                         eaname, i, high, low, 
     194                                torture_comment(tctx, "[%s] EA size %d failed!    "
     195                                        "(high=%d low=%d) [%s]\n",
     196                                        eaname, i, high, low,
    200197                                        nt_errstr(status));
    201198                        }
    202199                        high = i;
    203200                        if (high - low <= 1) {
    204                                 printf ("Max. EA size for \"%s\"=%d\n",
     201                                torture_comment(tctx, "Max. EA size for \"%s\"=%d\n",
    205202                                        eaname, low);
    206203                                break;
     
    245242        int       maxeastart;
    246243
    247         printf("TESTING SETFILEINFO MAX. EA_SET\n");
     244        torture_comment(tctx, "TESTING SETFILEINFO MAX. EA_SET\n");
    248245
    249246        maxeasize  = torture_setting_int(tctx, "maxeasize", 65536);
     
    254251        /* Do some sanity check on possibly passed parms */
    255252        if (maxeasize <= 0) {
    256                 printf("Invalid parameter 'maxeasize=%d'",maxeasize);
     253                torture_comment(tctx, "Invalid parameter 'maxeasize=%d'",maxeasize);
    257254                err = true;
    258255        }
    259256        if (maxeanames <= 0) {
    260                 printf("Invalid parameter 'maxeanames=%d'",maxeanames);
     257                torture_comment(tctx, "Invalid parameter 'maxeanames=%d'",maxeanames);
    261258                err = true;
    262259        }
    263260        if (maxeastart <= 0) {
    264                 printf("Invalid parameter 'maxeastart=%d'",maxeastart);
     261                torture_comment(tctx, "Invalid parameter 'maxeastart=%d'",maxeastart);
    265262                err = true;
    266263        }
    267264        if (maxeadebug < 0) {
    268                 printf("Invalid parameter 'maxeadebug=%d'",maxeadebug);
     265                torture_comment(tctx, "Invalid parameter 'maxeadebug=%d'",maxeadebug);
    269266                err = true;
    270267        }
    271268        if (err) {
    272           printf("\n\n");
     269          torture_comment(tctx, "\n\n");
    273270          goto done;
    274271        }
    275272        if (maxeastart > maxeasize) {
    276273                maxeastart = maxeasize;
    277                 printf ("'maxeastart' outside range - corrected to %d\n",
     274                torture_comment(tctx, "'maxeastart' outside range - corrected to %d\n",
    278275                        maxeastart);
    279276        }
    280         printf("MAXEA parms: maxeasize=%d maxeanames=%d maxeastart=%d"
    281                " maxeadebug=%d\n", maxeasize, maxeanames, maxeastart, 
     277        torture_comment(tctx, "MAXEA parms: maxeasize=%d maxeanames=%d maxeastart=%d"
     278               " maxeadebug=%d\n", maxeasize, maxeanames, maxeastart,
    282279               maxeadebug);
    283280
    284281        io.generic.level = RAW_OPEN_NTCREATEX;
    285         io.ntcreatex.in.root_fid = 0;
     282        io.ntcreatex.in.root_fid.fnum = 0;
    286283        io.ntcreatex.in.flags = 0;
    287284        io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
    288285        io.ntcreatex.in.create_options = 0;
    289286        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
    290         io.ntcreatex.in.share_access = 
    291                 NTCREATEX_SHARE_ACCESS_READ | 
     287        io.ntcreatex.in.share_access =
     288                NTCREATEX_SHARE_ACCESS_READ |
    292289                NTCREATEX_SHARE_ACCESS_WRITE;
    293290        io.ntcreatex.in.alloc_size = 0;
     
    299296        CHECK_STATUS(status, NT_STATUS_OK);
    300297        fnum = io.ntcreatex.out.file.fnum;
    301        
     298
    302299        eablob = data_blob_talloc(tctx, NULL, maxeasize);
    303300        if (eablob.data == NULL) {
    304301                goto done;
    305302        }
    306         /* 
    307          * Fill in some EA data - the offset could be easily checked 
     303        /*
     304         * Fill in some EA data - the offset could be easily checked
    308305         * during a hexdump.
    309306         */
     
    316313
    317314        i = eablob.length % 4;
    318         if (i-- > 0) { 
     315        if (i-- > 0) {
    319316                eablob.data[k] = k & 0xff;
    320                 if (i-- > 0) { 
     317                if (i-- > 0) {
    321318                        eablob.data[k+1] = (k >>  8) & 0xff;
    322                         if (i-- > 0) { 
     319                        if (i-- > 0) {
    323320                                eablob.data[k+2] = (k >> 16) & 0xff;
    324321                        }
     
    340337                        goto done;
    341338                }
    342                 j = test_one_eamax(cli, fnum, eaname, eablob, last, maxeadebug);
     339                j = test_one_eamax(tctx, cli, fnum, eaname, eablob, last, maxeadebug);
    343340                if (j <= 0) {
    344341                        break;
     
    348345        }
    349346
    350         printf("Total EA size:%d\n", total);
     347        torture_comment(tctx, "Total EA size:%d\n", total);
    351348        if (i == maxeanames) {
    352                 printf ("NOTE: More EAs could be available!\n");
    353         } 
     349                torture_comment(tctx, "NOTE: More EAs could be available!\n");
     350        }
    354351        if (total == 0) {
    355352                ret = false;
     
    363360  test using NTTRANS CREATE to create a file with an initial EA set
    364361*/
    365 static bool test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
     362static bool test_nttrans_create(struct smbcli_state *cli, struct torture_context *tctx)
    366363{
    367364        NTSTATUS status;
     
    373370        struct smb_ea_list ea_list;
    374371
    375         printf("TESTING NTTRANS CREATE WITH EAS\n");
     372        torture_comment(tctx, "TESTING NTTRANS CREATE WITH EAS\n");
    376373
    377374        io.generic.level = RAW_OPEN_NTTRANS_CREATE;
    378         io.ntcreatex.in.root_fid = 0;
     375        io.ntcreatex.in.root_fid.fnum = 0;
    379376        io.ntcreatex.in.flags = 0;
    380377        io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
    381378        io.ntcreatex.in.create_options = 0;
    382379        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
    383         io.ntcreatex.in.share_access = 
    384                 NTCREATEX_SHARE_ACCESS_READ | 
     380        io.ntcreatex.in.share_access =
     381                NTCREATEX_SHARE_ACCESS_READ |
    385382                NTCREATEX_SHARE_ACCESS_WRITE;
    386383        io.ntcreatex.in.alloc_size = 0;
     
    408405        io.ntcreatex.in.sec_desc = NULL;
    409406
    410         status = smb_raw_open(cli->tree, mem_ctx, &io);
     407        status = smb_raw_open(cli->tree, tctx, &io);
    411408        CHECK_STATUS(status, NT_STATUS_OK);
    412409        fnum = io.ntcreatex.out.file.fnum;
    413        
     410
    414411        ret &= check_ea(cli, fname, "EAONE", NULL);
    415412        ret &= check_ea(cli, fname, "1st EA", "Value One");
     
    419416        smbcli_close(cli->tree, fnum);
    420417
    421         printf("Trying to add EAs on non-create\n");
     418        torture_comment(tctx, "Trying to add EAs on non-create\n");
    422419        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
    423420        io.ntcreatex.in.fname = fname;
     
    428425        eas[0].value = data_blob_string_const("Value Four");
    429426
    430         status = smb_raw_open(cli->tree, mem_ctx, &io);
     427        status = smb_raw_open(cli->tree, tctx, &io);
    431428        CHECK_STATUS(status, NT_STATUS_OK);
    432429        fnum = io.ntcreatex.out.file.fnum;
    433        
     430
    434431        ret &= check_ea(cli, fname, "1st EA", "Value One");
    435432        ret &= check_ea(cli, fname, "2nd EA", "Second Value");
     
    442439}
    443440
    444 /* 
     441/*
    445442   basic testing of EA calls
    446443*/
     
    461458}
    462459
    463 /* 
     460/*
    464461   test max EA size
    465462*/
  • trunk/server/source4/torture/raw/ioctl.c

    r414 r745  
    2020
    2121#include "includes.h"
    22 #include "torture/torture.h"
    2322#include "libcli/raw/ioctl.h"
    2423#include "libcli/raw/libcliraw.h"
     
    10099        }
    101100
     101        printf("Trying FSCTL_FIND_FILES_BY_SID\n");
     102        nt.ioctl.level = RAW_IOCTL_NTIOCTL;
     103        nt.ntioctl.in.function = FSCTL_FIND_FILES_BY_SID;
     104        nt.ntioctl.in.file.fnum = fnum;
     105        nt.ntioctl.in.fsctl = true;
     106        nt.ntioctl.in.filter = 0;
     107        nt.ntioctl.in.max_data = 0;
     108        nt.ntioctl.in.blob = data_blob(NULL, 1024);
     109        /* definitely not a sid... */
     110        generate_random_buffer(nt.ntioctl.in.blob.data,
     111                               nt.ntioctl.in.blob.length);
     112        nt.ntioctl.in.blob.data[1] = 15+1;
     113        status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
     114        if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) &&
     115            !NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED) &&
     116            !NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
     117                printf("Got unexpected error code: %s\n",
     118                        nt_errstr(status));
     119                ret = false;
     120                goto done;
     121        }
     122
    102123        printf("trying sparse file\n");
    103124        nt.ioctl.level = RAW_IOCTL_NTIOCTL;
  • trunk/server/source4/torture/raw/lock.c

    r414 r745  
    7272#define TARGET_IS_W2K8(_tctx) (torture_setting_bool(_tctx, "w2k8", false))
    7373#define TARGET_IS_WIN7(_tctx) (torture_setting_bool(_tctx, "win7", false))
     74#define TARGET_IS_WINDOWS(_tctx) \
     75        ((torture_setting_bool(_tctx, "w2k3", false)) || \
     76         (torture_setting_bool(_tctx, "w2k8", false)) || \
     77         (torture_setting_bool(_tctx, "win7", false)))
    7478#define TARGET_IS_SAMBA3(_tctx) (torture_setting_bool(_tctx, "samba3", false))
    75 
     79#define TARGET_IS_SAMBA4(_tctx) (torture_setting_bool(_tctx, "samba4", false))
     80
     81#define TARGET_SUPPORTS_INVALID_LOCK_RANGE(_tctx) \
     82        (torture_setting_bool(_tctx, "invalid_lock_range_support", true))
     83#define TARGET_SUPPORTS_SMBEXIT(_tctx) \
     84    (torture_setting_bool(_tctx, "smbexit_pdu_support", true))
     85#define TARGET_SUPPORTS_SMBLOCK(_tctx) \
     86    (torture_setting_bool(_tctx, "smblock_pdu_support", true))
     87#define TARGET_SUPPORTS_OPENX_DENY_DOS(_tctx) \
     88    (torture_setting_bool(_tctx, "openx_deny_dos_support", true))
     89#define TARGET_RETURNS_RANGE_NOT_LOCKED(_tctx) \
     90    (torture_setting_bool(_tctx, "range_not_locked_on_file_close", true))
    7691/*
    7792  test SMBlock and SMBunlock ops
     
    8499        int fnum;
    85100        const char *fname = BASEDIR "\\test.txt";
     101
     102        if (!TARGET_SUPPORTS_SMBLOCK(tctx))
     103                torture_skip(tctx, "Target does not support the SMBlock PDU");
    86104
    87105        if (!torture_setup_dir(cli, BASEDIR)) {
     
    366384        lock[0].count = 2;
    367385        status = smb_raw_lock(cli->tree, &io);
    368         if (TARGET_IS_WIN7(tctx))
     386        if (TARGET_SUPPORTS_INVALID_LOCK_RANGE(tctx))
    369387                CHECK_STATUS(status, NT_STATUS_INVALID_LOCK_RANGE);
    370388        else
     
    489507        const char *fname = BASEDIR "\\test.txt";
    490508        time_t t;
    491         struct smbcli_request *req;
     509        struct smbcli_request *req, *req2;
    492510        struct smbcli_session_options options;
    493511
     
    496514        }
    497515
    498         lp_smbcli_session_options(tctx->lp_ctx, &options);
     516        lpcfg_smbcli_session_options(tctx->lp_ctx, &options);
    499517
    500518        torture_comment(tctx, "Testing LOCKING_ANDX_CANCEL_LOCK\n");
     
    515533        lock[0].offset = 100;
    516534        lock[0].count = 10;
     535        lock[1].pid = cli->session->pid;
     536        lock[1].offset = 110;
     537        lock[1].count = 10;
    517538        io.lockx.in.locks = &lock[0];
    518539        status = smb_raw_lock(cli->tree, &io);
    519540        CHECK_STATUS(status, NT_STATUS_OK);
    520541
    521         t = time(NULL);
    522 
    523         torture_comment(tctx, "testing cancel by CANCEL_LOCK\n");
     542        t = time_mono(NULL);
     543
     544        torture_comment(tctx, "Testing cancel by CANCEL_LOCK\n");
    524545
    525546        /* setup a timed lock */
     
    554575        CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
    555576
    556         torture_assert(tctx,!(time(NULL) > t+2), talloc_asprintf(tctx,
     577        torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
    557578                       "lock cancel was not immediate (%s)\n", __location__));
    558579
    559         torture_comment(tctx, "testing cancel by unlock\n");
     580        /* MS-CIFS (2.2.4.32.1) states that a cancel is honored if and only
     581         * if the lock vector contains one entry. When given mutliple cancel
     582         * requests in a single PDU we expect the server to return an
     583         * error. Samba4 handles this correctly. Windows servers seem to
     584         * accept the request but only cancel the first lock.  Samba3
     585         * now does what Windows does (JRA).
     586         */
     587        torture_comment(tctx, "Testing multiple cancel\n");
     588
     589        /* acquire second lock */
     590        io.lockx.in.timeout = 0;
    560591        io.lockx.in.ulock_cnt = 0;
    561592        io.lockx.in.lock_cnt = 1;
    562593        io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
    563         io.lockx.in.timeout = 0;
    564         status = smb_raw_lock(cli->tree, &io);
    565         CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
     594        io.lockx.in.locks = &lock[1];
     595        status = smb_raw_lock(cli->tree, &io);
     596        CHECK_STATUS(status, NT_STATUS_OK);
     597
     598        /* setup 2 timed locks */
     599        t = time_mono(NULL);
     600        io.lockx.in.timeout = 10000;
     601        io.lockx.in.lock_cnt = 1;
     602        io.lockx.in.locks = &lock[0];
     603        req = smb_raw_lock_send(cli->tree, &io);
     604        torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
     605                       "Failed to setup timed lock (%s)\n", __location__));
     606        io.lockx.in.locks = &lock[1];
     607        req2 = smb_raw_lock_send(cli->tree, &io);
     608        torture_assert(tctx,(req2 != NULL), talloc_asprintf(tctx,
     609                       "Failed to setup timed lock (%s)\n", __location__));
     610
     611        /* try to cancel both locks in the same packet */
     612        io.lockx.in.timeout = 0;
     613        io.lockx.in.lock_cnt = 2;
     614        io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK | LOCKING_ANDX_LARGE_FILES;
     615        io.lockx.in.locks = lock;
     616        status = smb_raw_lock(cli->tree, &io);
     617        CHECK_STATUS(status, NT_STATUS_OK);
     618
     619        torture_warning(tctx, "Target server accepted a lock cancel "
     620                              "request with multiple locks. This violates "
     621                              "MS-CIFS 2.2.4.32.1.\n");
     622
     623        /* receive the failed lock requests */
     624        status = smbcli_request_simple_recv(req);
     625        CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
     626
     627        torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
     628                       "first lock was not cancelled immediately (%s)\n",
     629                       __location__));
     630
     631        /* send cancel to second lock */
     632        io.lockx.in.timeout = 0;
     633        io.lockx.in.lock_cnt = 1;
     634        io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK |
     635                           LOCKING_ANDX_LARGE_FILES;
     636        io.lockx.in.locks = &lock[1];
     637        status = smb_raw_lock(cli->tree, &io);
     638        CHECK_STATUS(status, NT_STATUS_OK);
     639
     640        status = smbcli_request_simple_recv(req2);
     641        CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
     642
     643        torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
     644                       "second lock was not cancelled immediately (%s)\n",
     645                       __location__));
     646
     647        /* cleanup the second lock */
     648        io.lockx.in.ulock_cnt = 1;
     649        io.lockx.in.lock_cnt = 0;
     650        io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
     651        io.lockx.in.locks = &lock[1];
     652        status = smb_raw_lock(cli->tree, &io);
     653        CHECK_STATUS(status, NT_STATUS_OK);
     654
     655        /* If a lock request contained multiple ranges and we are cancelling
     656         * one while it's still pending, what happens? */
     657        torture_comment(tctx, "Testing cancel 1/2 lock request\n");
     658
     659        /* Send request with two ranges */
     660        io.lockx.in.timeout = -1;
     661        io.lockx.in.ulock_cnt = 0;
     662        io.lockx.in.lock_cnt = 2;
     663        io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
     664        io.lockx.in.locks = lock;
     665        req = smb_raw_lock_send(cli->tree, &io);
     666        torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
     667                       "Failed to setup pending lock (%s)\n", __location__));
     668
     669        /* Try to cancel the first lock range */
     670        io.lockx.in.timeout = 0;
     671        io.lockx.in.lock_cnt = 1;
     672        io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK | LOCKING_ANDX_LARGE_FILES;
     673        io.lockx.in.locks = &lock[0];
     674        status = smb_raw_lock(cli->tree, &io);
     675        CHECK_STATUS(status, NT_STATUS_OK);
     676
     677        /* Locking request should've failed and second range should be
     678         * unlocked */
     679        status = smbcli_request_simple_recv(req);
     680        CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
     681
     682        io.lockx.in.timeout = 0;
     683        io.lockx.in.ulock_cnt = 0;
     684        io.lockx.in.lock_cnt = 1;
     685        io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
     686        io.lockx.in.locks = &lock[1];
     687        status = smb_raw_lock(cli->tree, &io);
     688        CHECK_STATUS(status, NT_STATUS_OK);
     689
     690        /* Cleanup both locks */
     691        io.lockx.in.ulock_cnt = 2;
     692        io.lockx.in.lock_cnt = 0;
     693        io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
     694        io.lockx.in.locks = lock;
     695        status = smb_raw_lock(cli->tree, &io);
     696        CHECK_STATUS(status, NT_STATUS_OK);
     697
     698        torture_comment(tctx, "Testing cancel 2/2 lock request\n");
     699
     700        /* Lock second range so it contends */
     701        io.lockx.in.timeout = 0;
     702        io.lockx.in.ulock_cnt = 0;
     703        io.lockx.in.lock_cnt = 1;
     704        io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
     705        io.lockx.in.locks = &lock[1];
     706        status = smb_raw_lock(cli->tree, &io);
     707        CHECK_STATUS(status, NT_STATUS_OK);
     708
     709        /* Send request with two ranges */
     710        io.lockx.in.timeout = -1;
     711        io.lockx.in.ulock_cnt = 0;
     712        io.lockx.in.lock_cnt = 2;
     713        io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
     714        io.lockx.in.locks = lock;
     715        req = smb_raw_lock_send(cli->tree, &io);
     716        torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
     717                       "Failed to setup pending lock (%s)\n", __location__));
     718
     719        /* Try to cancel the second lock range */
     720        io.lockx.in.timeout = 0;
     721        io.lockx.in.lock_cnt = 1;
     722        io.lockx.in.mode = LOCKING_ANDX_CANCEL_LOCK | LOCKING_ANDX_LARGE_FILES;
     723        io.lockx.in.locks = &lock[1];
     724        status = smb_raw_lock(cli->tree, &io);
     725        CHECK_STATUS(status, NT_STATUS_OK);
     726
     727        /* Locking request should've failed and first range should be
     728         * unlocked */
     729        status = smbcli_request_simple_recv(req);
     730        CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
     731
     732        io.lockx.in.timeout = 0;
     733        io.lockx.in.ulock_cnt = 0;
     734        io.lockx.in.lock_cnt = 1;
     735        io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
     736        io.lockx.in.locks = &lock[0];
     737        status = smb_raw_lock(cli->tree, &io);
     738        CHECK_STATUS(status, NT_STATUS_OK);
     739
     740        /* Cleanup both locks */
     741        io.lockx.in.ulock_cnt = 2;
     742        io.lockx.in.lock_cnt = 0;
     743        io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
     744        io.lockx.in.locks = lock;
     745        status = smb_raw_lock(cli->tree, &io);
     746        CHECK_STATUS(status, NT_STATUS_OK);
     747
     748        torture_comment(tctx, "Testing cancel by unlock\n");
     749        io.lockx.in.ulock_cnt = 0;
     750        io.lockx.in.lock_cnt = 1;
     751        io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
     752        io.lockx.in.timeout = 0;
     753        io.lockx.in.locks = &lock[0];
     754        status = smb_raw_lock(cli->tree, &io);
     755        CHECK_STATUS(status, NT_STATUS_OK);
    566756
    567757        io.lockx.in.timeout = 5000;
     
    575765        CHECK_STATUS(status, NT_STATUS_OK);
    576766
    577         t = time(NULL);
     767        t = time_mono(NULL);
    578768        status = smbcli_request_simple_recv(req);
    579769        CHECK_STATUS(status, NT_STATUS_OK);
    580770
    581         torture_assert(tctx,!(time(NULL) > t+2), talloc_asprintf(tctx,
     771        torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
    582772                       "lock cancel by unlock was not immediate (%s) - took %d secs\n",
    583                        __location__, (int)(time(NULL)-t)));
    584 
    585         torture_comment(tctx, "testing cancel by close\n");
     773                       __location__, (int)(time_mono(NULL)-t)));
     774
     775        torture_comment(tctx, "Testing cancel by close\n");
    586776        io.lockx.in.ulock_cnt = 0;
    587777        io.lockx.in.lock_cnt = 1;
     
    589779        io.lockx.in.timeout = 0;
    590780        status = smb_raw_lock(cli->tree, &io);
    591         CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
    592 
    593         t = time(NULL);
     781        CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
     782
     783        t = time_mono(NULL);
    594784        io.lockx.in.timeout = 10000;
    595785        req = smb_raw_lock_send(cli->tree, &io);
     
    601791
    602792        status = smbcli_request_simple_recv(req);
    603         CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
    604 
    605         torture_assert(tctx,!(time(NULL) > t+2), talloc_asprintf(tctx,
     793        if (TARGET_RETURNS_RANGE_NOT_LOCKED(tctx))
     794                CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
     795        else
     796                CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
     797
     798        torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
    606799                       "lock cancel by close was not immediate (%s)\n", __location__));
    607800
     
    610803        setup.in.sesskey = cli->transport->negotiate.sesskey;
    611804        setup.in.capabilities = cli->transport->negotiate.capabilities;
    612         setup.in.workgroup = lp_workgroup(tctx->lp_ctx);
     805        setup.in.workgroup = lpcfg_workgroup(tctx->lp_ctx);
    613806        setup.in.credentials = cmdline_credentials;
    614         setup.in.gensec_settings = lp_gensec_settings(tctx, tctx->lp_ctx);
     807        setup.in.gensec_settings = lpcfg_gensec_settings(tctx, tctx->lp_ctx);
    615808        status = smb_composite_sesssetup(session, &setup);
    616809        CHECK_STATUS(status, NT_STATUS_OK);
     
    630823        tree->tid = tcon.tconx.out.tid;
    631824
    632         torture_comment(tctx, "testing cancel by exit\n");
    633         fname = BASEDIR "\\test_exit.txt";
     825        torture_comment(tctx, "Testing cancel by exit\n");
     826        if (TARGET_SUPPORTS_SMBEXIT(tctx)) {
     827                fname = BASEDIR "\\test_exit.txt";
     828                fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
     829                torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
     830                               "Failed to reopen %s - %s\n",
     831                               fname, smbcli_errstr(tree)));
     832
     833                io.lockx.level = RAW_LOCK_LOCKX;
     834                io.lockx.in.file.fnum = fnum;
     835                io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
     836                io.lockx.in.timeout = 0;
     837                io.lockx.in.ulock_cnt = 0;
     838                io.lockx.in.lock_cnt = 1;
     839                lock[0].pid = session->pid;
     840                lock[0].offset = 100;
     841                lock[0].count = 10;
     842                io.lockx.in.locks = &lock[0];
     843                status = smb_raw_lock(tree, &io);
     844                CHECK_STATUS(status, NT_STATUS_OK);
     845
     846                io.lockx.in.ulock_cnt = 0;
     847                io.lockx.in.lock_cnt = 1;
     848                io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
     849                io.lockx.in.timeout = 0;
     850                status = smb_raw_lock(tree, &io);
     851                CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
     852
     853                io.lockx.in.timeout = 10000;
     854                t = time_mono(NULL);
     855                req = smb_raw_lock_send(tree, &io);
     856                torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
     857                               "Failed to setup timed lock (%s)\n",
     858                               __location__));
     859
     860                status = smb_raw_exit(session);
     861                CHECK_STATUS(status, NT_STATUS_OK);
     862
     863                status = smbcli_request_simple_recv(req);
     864                if (TARGET_RETURNS_RANGE_NOT_LOCKED(tctx))
     865                        CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
     866                else
     867                        CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
     868
     869                torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
     870                               "lock cancel by exit was not immediate (%s)\n",
     871                               __location__));
     872        }
     873        else {
     874                torture_comment(tctx,
     875                                "  skipping test, SMBExit not supported\n");
     876        }
     877
     878        torture_comment(tctx, "Testing cancel by ulogoff\n");
     879        fname = BASEDIR "\\test_ulogoff.txt";
    634880        fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
    635881        torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
     
    658904
    659905        io.lockx.in.timeout = 10000;
    660         t = time(NULL);
     906        t = time_mono(NULL);
    661907        req = smb_raw_lock_send(tree, &io);
    662908        torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
    663909                       "Failed to setup timed lock (%s)\n", __location__));
    664910
    665         status = smb_raw_exit(session);
     911        status = smb_raw_ulogoff(session);
    666912        CHECK_STATUS(status, NT_STATUS_OK);
    667913
    668914        status = smbcli_request_simple_recv(req);
    669         CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
    670 
    671         torture_assert(tctx,!(time(NULL) > t+2), talloc_asprintf(tctx,
    672                        "lock cancel by exit was not immediate (%s)\n", __location__));
    673 
    674         torture_comment(tctx, "testing cancel by ulogoff\n");
    675         fname = BASEDIR "\\test_ulogoff.txt";
    676         fnum = smbcli_open(tree, fname, O_RDWR|O_CREAT, DENY_NONE);
    677         torture_assert(tctx,(fnum != -1), talloc_asprintf(tctx,
    678                        "Failed to reopen %s - %s\n",
    679                        fname, smbcli_errstr(tree)));
    680 
    681         io.lockx.level = RAW_LOCK_LOCKX;
    682         io.lockx.in.file.fnum = fnum;
    683         io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
    684         io.lockx.in.timeout = 0;
    685         io.lockx.in.ulock_cnt = 0;
    686         io.lockx.in.lock_cnt = 1;
    687         lock[0].pid = session->pid;
    688         lock[0].offset = 100;
    689         lock[0].count = 10;
    690         io.lockx.in.locks = &lock[0];
    691         status = smb_raw_lock(tree, &io);
    692         CHECK_STATUS(status, NT_STATUS_OK);
    693 
    694         io.lockx.in.ulock_cnt = 0;
    695         io.lockx.in.lock_cnt = 1;
    696         io.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
    697         io.lockx.in.timeout = 0;
    698         status = smb_raw_lock(tree, &io);
    699         CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
    700 
    701         io.lockx.in.timeout = 10000;
    702         t = time(NULL);
    703         req = smb_raw_lock_send(tree, &io);
    704         torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
    705                        "Failed to setup timed lock (%s)\n", __location__));
    706 
    707         status = smb_raw_ulogoff(session);
    708         CHECK_STATUS(status, NT_STATUS_OK);
    709 
    710         status = smbcli_request_simple_recv(req);
    711         if (NT_STATUS_EQUAL(NT_STATUS_FILE_LOCK_CONFLICT, status)) {
    712                 torture_result(tctx, TORTURE_FAIL,
    713                         "lock not canceled by ulogoff - %s (ignored because of vfs_vifs fails it)\n",
    714                         nt_errstr(status));
    715                 smb_tree_disconnect(tree);
    716                 smb_raw_exit(session);
    717                 goto done;
    718         }
    719         CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
    720 
    721         torture_assert(tctx,!(time(NULL) > t+2), talloc_asprintf(tctx,
     915        if (TARGET_RETURNS_RANGE_NOT_LOCKED(tctx)) {
     916                if (NT_STATUS_EQUAL(NT_STATUS_FILE_LOCK_CONFLICT, status)) {
     917                        torture_result(tctx, TORTURE_FAIL,
     918                                "lock not canceled by ulogoff - %s "
     919                                "(ignored because of vfs_vifs fails it)\n",
     920                                nt_errstr(status));
     921                        smb_tree_disconnect(tree);
     922                        smb_raw_exit(session);
     923                        goto done;
     924                }
     925                CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
     926        } else {
     927                CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
     928        }
     929
     930        torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
    722931                       "lock cancel by ulogoff was not immediate (%s)\n", __location__));
    723932
    724         torture_comment(tctx, "testing cancel by tdis\n");
     933        torture_comment(tctx, "Testing cancel by tdis\n");
    725934        tree->session = cli->session;
    726935
     
    748957
    749958        io.lockx.in.timeout = 10000;
    750         t = time(NULL);
     959        t = time_mono(NULL);
    751960        req = smb_raw_lock_send(tree, &io);
    752961        torture_assert(tctx,(req != NULL), talloc_asprintf(tctx,
     
    757966
    758967        status = smbcli_request_simple_recv(req);
    759         CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
    760 
    761         torture_assert(tctx,!(time(NULL) > t+2), talloc_asprintf(tctx,
     968        if (TARGET_RETURNS_RANGE_NOT_LOCKED(tctx))
     969                CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
     970        else
     971                CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
     972
     973        torture_assert(tctx,!(time_mono(NULL) > t+2), talloc_asprintf(tctx,
    762974                       "lock cancel by tdis was not immediate (%s)\n", __location__));
    763975
     
    785997        int t;
    786998        int delay;
     999        uint16_t deny_mode = 0;
    7871000
    7881001        if (!torture_setup_dir(cli, BASEDIR)) {
     
    7921005        torture_comment(tctx, "Testing LOCK_NOT_GRANTED vs. FILE_LOCK_CONFLICT\n");
    7931006
    794         torture_comment(tctx, "testing with timeout = 0\n");
     1007        torture_comment(tctx, "Testing with timeout = 0\n");
    7951008        fname = BASEDIR "\\test0.txt";
    7961009        t = 0;
     
    8011014         */
    8021015next_run:
    803         /*
    804          * use the DENY_DOS mode, that creates two fnum's of one low-level file handle,
    805          * this demonstrates that the cache is per fnum
     1016        /*
     1017         * use the DENY_DOS mode, that creates two fnum's of one low-level
     1018         * file handle, this demonstrates that the cache is per fnum, not
     1019         * per file handle
    8061020         */
     1021        if (TARGET_SUPPORTS_OPENX_DENY_DOS(tctx))
     1022            deny_mode = OPENX_MODE_DENY_DOS;
     1023        else
     1024            deny_mode = OPENX_MODE_DENY_NONE;
     1025
    8071026        op.openx.level = RAW_OPEN_OPENX;
    8081027        op.openx.in.fname = fname;
    8091028        op.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
    810         op.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_DOS;
     1029        op.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | deny_mode;
    8111030        op.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
    8121031        op.openx.in.search_attrs = 0;
     
    10591278         * demonstrate the a successful lock in a different range,
    10601279         * doesn't reset the cache, the failing lock on the 2nd handle
    1061          * resets the resets the cache
     1280         * resets the cache
    10621281         */
    10631282        lock[0].offset = 120;
     
    10891308                smb_raw_exit(cli->session);
    10901309                t = 1;
    1091                 torture_comment(tctx, "testing with timeout > 0 (=%d)\n",
     1310                torture_comment(tctx, "Testing with timeout > 0 (=%d)\n",
    10921311                                t);
    10931312                fname = BASEDIR "\\test1.txt";
     
    10961315
    10971316        t = 4000;
    1098         torture_comment(tctx, "testing special cases with timeout > 0 (=%d)\n",
     1317        torture_comment(tctx, "Testing special cases with timeout > 0 (=%d)\n",
    10991318                        t);
    11001319
     
    11051324         */
    11061325        smb_raw_exit(cli->session);
    1107         torture_comment(tctx, "testing a conflict while a lock is pending\n");
     1326        torture_comment(tctx, "Testing a conflict while a lock is pending\n");
    11081327        fname = BASEDIR "\\test2.txt";
    11091328        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
     
    11251344        CHECK_STATUS(status, NT_STATUS_OK);
    11261345
    1127         start = time(NULL);
     1346        start = time_mono(NULL);
    11281347        io.lockx.in.timeout = t;
    11291348        req = smb_raw_lock_send(cli->tree, &io);
     
    11451364        }
    11461365
    1147         torture_assert(tctx,!(time(NULL) < start+delay), talloc_asprintf(tctx,
     1366        torture_assert(tctx,!(time_mono(NULL) < start+delay), talloc_asprintf(tctx,
    11481367                       "lock comes back to early timeout[%d] delay[%d]"
    11491368                       "(%s)\n", t, delay, __location__));
     
    11721391        CHECK_STATUS(status, NT_STATUS_OK);
    11731392
    1174         start = time(NULL);
     1393        start = time_mono(NULL);
    11751394        io.lockx.in.timeout = t;
    11761395        req = smb_raw_lock_send(cli->tree, &io);
     
    11921411        }
    11931412
    1194         torture_assert(tctx,!(time(NULL) < start+delay), talloc_asprintf(tctx,
     1413        torture_assert(tctx,!(time_mono(NULL) < start+delay), talloc_asprintf(tctx,
    11951414                       "lock comes back to early timeout[%d] delay[%d]"
    11961415                       "(%s)\n", t, delay, __location__));
     
    12211440        CHECK_STATUS(status, NT_STATUS_OK);
    12221441
    1223         start = time(NULL);
     1442        start = time_mono(NULL);
    12241443        io.lockx.in.timeout = t;
    12251444        req = smb_raw_lock_send(cli->tree, &io);
     
    12391458        }
    12401459
    1241         torture_assert(tctx,!(time(NULL) < start+delay), talloc_asprintf(tctx,
     1460        torture_assert(tctx,!(time_mono(NULL) < start+delay), talloc_asprintf(tctx,
    12421461                       "lock comes back to early timeout[%d] delay[%d]"
    12431462                       "(%s)\n", t, delay, __location__));
     
    13271546 * Tests zero byte locks.
    13281547 */
    1329 static const struct double_lock_test zero_byte_tests[] = {
     1548static struct double_lock_test zero_byte_tests[] = {
    13301549        /* {pid, offset, count}, {pid, offset, count}, status */
    13311550
     
    13931612                torture_comment(tctx, "  ... {%d, %llu, %llu} + {%d, %llu, %llu} = %s\n",
    13941613                    zero_byte_tests[i].lock1.pid,
    1395                     zero_byte_tests[i].lock1.offset,
    1396                     zero_byte_tests[i].lock1.count,
     1614                    (unsigned long long) zero_byte_tests[i].lock1.offset,
     1615                    (unsigned long long) zero_byte_tests[i].lock1.count,
    13971616                    zero_byte_tests[i].lock2.pid,
    1398                     zero_byte_tests[i].lock2.offset,
    1399                     zero_byte_tests[i].lock2.count,
     1617                    (unsigned long long) zero_byte_tests[i].lock2.offset,
     1618                    (unsigned long long) zero_byte_tests[i].lock2.count,
    14001619                    nt_errstr(zero_byte_tests[i].exp_status));
    14011620
     
    14041623                io.lockx.in.lock_cnt = 1;
    14051624
    1406                 io.lockx.in.locks = &zero_byte_tests[i].lock1;
     1625                io.lockx.in.locks = discard_const_p(struct smb_lock_entry,
     1626                                                    &zero_byte_tests[i].lock1);
    14071627                status = smb_raw_lock(cli->tree, &io);
    14081628                CHECK_STATUS(status, NT_STATUS_OK);
    14091629
    1410                 io.lockx.in.locks = &zero_byte_tests[i].lock2;
     1630                io.lockx.in.locks = discard_const_p(struct smb_lock_entry,
     1631                                                    &zero_byte_tests[i].lock2);
    14111632                status = smb_raw_lock(cli->tree, &io);
    14121633
     
    14331654                }
    14341655
    1435                 io.lockx.in.locks = &zero_byte_tests[i].lock1;
     1656                io.lockx.in.locks = discard_const_p(struct smb_lock_entry,
     1657                                                    &zero_byte_tests[i].lock1);
    14361658                status = smb_raw_lock(cli->tree, &io);
    14371659                CHECK_STATUS(status, NT_STATUS_OK);
     
    17281950        io.lockx.in.lock_cnt = 0;
    17291951        io.lockx.in.locks = &lock1;
     1952        status = smb_raw_lock(cli->tree, &io);
     1953        CHECK_STATUS(status, NT_STATUS_OK);
     1954
     1955        /* Test3: Request 2 locks, second will contend.  What happens to the
     1956         * first? */
     1957        torture_comment(tctx, "  request 2 locks, second one will contend. "
     1958           "Expect both to fail.\n");
     1959
     1960        /* Lock the second range */
     1961        io.lockx.in.ulock_cnt = 0;
     1962        io.lockx.in.lock_cnt = 1;
     1963        io.lockx.in.locks = &lock2;
     1964        status = smb_raw_lock(cli->tree, &io);
     1965        CHECK_STATUS(status, NT_STATUS_OK);
     1966
     1967        /* Request both locks */
     1968        io.lockx.in.ulock_cnt = 0;
     1969        io.lockx.in.lock_cnt = 2;
     1970        io.lockx.in.locks = locks;
     1971
     1972        status = smb_raw_lock(cli->tree, &io);
     1973        CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
     1974
     1975        /* First lock should be unlocked. */
     1976        io.lockx.in.ulock_cnt = 0;
     1977        io.lockx.in.lock_cnt = 1;
     1978        io.lockx.in.locks = &lock1;
     1979        status = smb_raw_lock(cli->tree, &io);
     1980        CHECK_STATUS(status, NT_STATUS_OK);
     1981
     1982        /* cleanup */
     1983        io.lockx.in.ulock_cnt = 2;
     1984        io.lockx.in.lock_cnt = 0;
     1985        io.lockx.in.locks = locks;
     1986        status = smb_raw_lock(cli->tree, &io);
     1987        CHECK_STATUS(status, NT_STATUS_OK);
     1988
     1989        /* Test4: Request unlock and lock. The lock contends, is the unlock
     1990         * then re-locked? */
     1991        torture_comment(tctx, "  request unlock and lock, second one will "
     1992           "contend. Expect the unlock to succeed.\n");
     1993
     1994        /* Lock both ranges */
     1995        io.lockx.in.ulock_cnt = 0;
     1996        io.lockx.in.lock_cnt = 2;
     1997        io.lockx.in.locks = locks;
     1998        status = smb_raw_lock(cli->tree, &io);
     1999        CHECK_STATUS(status, NT_STATUS_OK);
     2000
     2001        /* Attempt to unlock the first range and lock the second */
     2002        io.lockx.in.ulock_cnt = 1;
     2003        io.lockx.in.lock_cnt = 1;
     2004        io.lockx.in.locks = locks;
     2005        status = smb_raw_lock(cli->tree, &io);
     2006        CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
     2007
     2008        /* The first lock should've been unlocked */
     2009        io.lockx.in.ulock_cnt = 0;
     2010        io.lockx.in.lock_cnt = 1;
     2011        io.lockx.in.locks = &lock1;
     2012        status = smb_raw_lock(cli->tree, &io);
     2013        CHECK_STATUS(status, NT_STATUS_OK);
     2014
     2015        /* cleanup */
     2016        io.lockx.in.ulock_cnt = 2;
     2017        io.lockx.in.lock_cnt = 0;
     2018        io.lockx.in.locks = locks;
    17302019        status = smb_raw_lock(cli->tree, &io);
    17312020        CHECK_STATUS(status, NT_STATUS_OK);
     
    18292118}
    18302119
    1831 /*
     2120/**
     2121 * Test how 0-byte read requests contend with byte range locks
     2122 */
     2123static bool test_zerobyteread(struct torture_context *tctx,
     2124                              struct smbcli_state *cli)
     2125{
     2126        union smb_lock io;
     2127        union smb_read rd;
     2128        NTSTATUS status;
     2129        bool ret = true;
     2130        int fnum1, fnum2;
     2131        const char *fname = BASEDIR "\\zerobyteread.txt";
     2132        struct smb_lock_entry lock1;
     2133        uint8_t c = 1;
     2134
     2135        if (!torture_setup_dir(cli, BASEDIR)) {
     2136                return false;
     2137        }
     2138
     2139        io.generic.level = RAW_LOCK_LOCKX;
     2140
     2141        fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
     2142        torture_assert(tctx,(fnum1 != -1), talloc_asprintf(tctx,
     2143                       "Failed to create %s - %s\n",
     2144                       fname, smbcli_errstr(cli->tree)));
     2145
     2146        fnum2 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
     2147        torture_assert(tctx,(fnum2 != -1), talloc_asprintf(tctx,
     2148                       "Failed to create %s - %s\n",
     2149                       fname, smbcli_errstr(cli->tree)));
     2150
     2151        /* Setup initial parameters */
     2152        io.lockx.level = RAW_LOCK_LOCKX;
     2153        io.lockx.in.timeout = 0;
     2154
     2155        lock1.pid = cli->session->pid;
     2156        lock1.offset = 0;
     2157        lock1.count = 10;
     2158
     2159        ZERO_STRUCT(rd);
     2160        rd.readx.level = RAW_READ_READX;
     2161
     2162        torture_comment(tctx, "Testing zero byte read on lock range:\n");
     2163
     2164        /* Take an exclusive lock */
     2165        torture_comment(tctx, "  taking exclusive lock.\n");
     2166        io.lockx.in.ulock_cnt = 0;
     2167        io.lockx.in.lock_cnt = 1;
     2168        io.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
     2169        io.lockx.in.file.fnum = fnum1;
     2170        io.lockx.in.locks = &lock1;
     2171        status = smb_raw_lock(cli->tree, &io);
     2172        CHECK_STATUS(status, NT_STATUS_OK);
     2173
     2174        /* Try a zero byte read */
     2175        torture_comment(tctx, "  reading 0 bytes.\n");
     2176        rd.readx.in.file.fnum = fnum2;
     2177        rd.readx.in.offset    = 5;
     2178        rd.readx.in.mincnt    = 0;
     2179        rd.readx.in.maxcnt    = 0;
     2180        rd.readx.in.remaining = 0;
     2181        rd.readx.in.read_for_execute = false;
     2182        rd.readx.out.data     = &c;
     2183        status = smb_raw_read(cli->tree, &rd);
     2184        torture_assert_int_equal_goto(tctx, rd.readx.out.nread, 0, ret, done,
     2185                                      "zero byte read did not return 0 bytes");
     2186        CHECK_STATUS(status, NT_STATUS_OK);
     2187
     2188        /* Unlock lock */
     2189        io.lockx.in.ulock_cnt = 1;
     2190        io.lockx.in.lock_cnt = 0;
     2191        io.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
     2192        io.lockx.in.file.fnum = fnum1;
     2193        io.lockx.in.locks = &lock1;
     2194        status = smb_raw_lock(cli->tree, &io);
     2195        CHECK_STATUS(status, NT_STATUS_OK);
     2196
     2197        torture_comment(tctx, "Testing zero byte read on zero byte lock "
     2198                              "range:\n");
     2199
     2200        /* Take an exclusive lock */
     2201        torture_comment(tctx, "  taking exclusive 0-byte lock.\n");
     2202        io.lockx.in.ulock_cnt = 0;
     2203        io.lockx.in.lock_cnt = 1;
     2204        io.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
     2205        io.lockx.in.file.fnum = fnum1;
     2206        io.lockx.in.locks = &lock1;
     2207        lock1.offset = 5;
     2208        lock1.count = 0;
     2209        status = smb_raw_lock(cli->tree, &io);
     2210        CHECK_STATUS(status, NT_STATUS_OK);
     2211
     2212        /* Try a zero byte read before the lock */
     2213        torture_comment(tctx, "  reading 0 bytes before the lock.\n");
     2214        rd.readx.in.file.fnum = fnum2;
     2215        rd.readx.in.offset    = 4;
     2216        rd.readx.in.mincnt    = 0;
     2217        rd.readx.in.maxcnt    = 0;
     2218        rd.readx.in.remaining = 0;
     2219        rd.readx.in.read_for_execute = false;
     2220        rd.readx.out.data     = &c;
     2221        status = smb_raw_read(cli->tree, &rd);
     2222        torture_assert_int_equal_goto(tctx, rd.readx.out.nread, 0, ret, done,
     2223                                      "zero byte read did not return 0 bytes");
     2224        CHECK_STATUS(status, NT_STATUS_OK);
     2225
     2226        /* Try a zero byte read on the lock */
     2227        torture_comment(tctx, "  reading 0 bytes on the lock.\n");
     2228        rd.readx.in.file.fnum = fnum2;
     2229        rd.readx.in.offset    = 5;
     2230        rd.readx.in.mincnt    = 0;
     2231        rd.readx.in.maxcnt    = 0;
     2232        rd.readx.in.remaining = 0;
     2233        rd.readx.in.read_for_execute = false;
     2234        rd.readx.out.data     = &c;
     2235        status = smb_raw_read(cli->tree, &rd);
     2236        torture_assert_int_equal_goto(tctx, rd.readx.out.nread, 0, ret, done,
     2237                                      "zero byte read did not return 0 bytes");
     2238        CHECK_STATUS(status, NT_STATUS_OK);
     2239
     2240        /* Try a zero byte read after the lock */
     2241        torture_comment(tctx, "  reading 0 bytes after the lock.\n");
     2242        rd.readx.in.file.fnum = fnum2;
     2243        rd.readx.in.offset    = 6;
     2244        rd.readx.in.mincnt    = 0;
     2245        rd.readx.in.maxcnt    = 0;
     2246        rd.readx.in.remaining = 0;
     2247        rd.readx.in.read_for_execute = false;
     2248        rd.readx.out.data     = &c;
     2249        status = smb_raw_read(cli->tree, &rd);
     2250        torture_assert_int_equal_goto(tctx, rd.readx.out.nread, 0, ret, done,
     2251                                      "zero byte read did not return 0 bytes");
     2252        CHECK_STATUS(status, NT_STATUS_OK);
     2253
     2254        /* Unlock lock */
     2255        io.lockx.in.ulock_cnt = 1;
     2256        io.lockx.in.lock_cnt = 0;
     2257        io.lockx.in.mode = LOCKING_ANDX_EXCLUSIVE_LOCK;
     2258        io.lockx.in.file.fnum = fnum1;
     2259        io.lockx.in.locks = &lock1;
     2260        status = smb_raw_lock(cli->tree, &io);
     2261        CHECK_STATUS(status, NT_STATUS_OK);
     2262
     2263done:
     2264        smbcli_close(cli->tree, fnum1);
     2265        smbcli_close(cli->tree, fnum2);
     2266        smb_raw_exit(cli->session);
     2267        smbcli_deltree(cli->tree, BASEDIR);
     2268        return ret;
     2269}
     2270
     2271/*
    18322272   basic testing of lock calls
    18332273*/
    18342274struct torture_suite *torture_raw_lock(TALLOC_CTX *mem_ctx)
    18352275{
    1836         struct torture_suite *suite = torture_suite_create(mem_ctx, "LOCK");
     2276        struct torture_suite *suite = torture_suite_create(mem_ctx, "lock");
    18372277
    18382278        torture_suite_add_1smb_test(suite, "lockx", test_lockx);
     
    18472287        torture_suite_add_1smb_test(suite, "multiple_unlock",
    18482288            test_multiple_unlock);
    1849         torture_suite_add_1smb_test(suite, "zerobytelocks",
    1850             test_zerobytelocks);
     2289        torture_suite_add_1smb_test(suite, "zerobytelocks", test_zerobytelocks);
     2290        torture_suite_add_1smb_test(suite, "zerobyteread", test_zerobyteread);
    18512291
    18522292        return suite;
  • trunk/server/source4/torture/raw/lockbench.c

    r414 r745  
    2121
    2222#include "includes.h"
    23 #include "torture/torture.h"
    2423#include "libcli/raw/libcliraw.h"
    2524#include "libcli/raw/raw_proto.h"
     
    189188        io->in.dest_host    = state->dest_host;
    190189        io->in.dest_ports   = state->dest_ports;
    191         io->in.gensec_settings = lp_gensec_settings(state->mem_ctx, state->tctx->lp_ctx);
    192         io->in.socket_options = lp_socket_options(state->tctx->lp_ctx);
     190        io->in.gensec_settings = lpcfg_gensec_settings(state->mem_ctx, state->tctx->lp_ctx);
     191        io->in.socket_options = lpcfg_socket_options(state->tctx->lp_ctx);
    193192        io->in.called_name  = state->called_name;
    194193        io->in.service      = share;
     
    196195        io->in.credentials  = cmdline_credentials;
    197196        io->in.fallback_to_anonymous = false;
    198         io->in.workgroup    = lp_workgroup(state->tctx->lp_ctx);
    199         io->in.iconv_convenience = lp_iconv_convenience(state->tctx->lp_ctx);
    200         lp_smbcli_options(state->tctx->lp_ctx, &io->in.options);
    201         lp_smbcli_session_options(state->tctx->lp_ctx, &io->in.session_options);
     197        io->in.workgroup    = lpcfg_workgroup(state->tctx->lp_ctx);
     198        lpcfg_smbcli_options(state->tctx->lp_ctx, &io->in.options);
     199        lpcfg_smbcli_session_options(state->tctx->lp_ctx, &io->in.session_options);
    202200
    203201        /* kill off the remnants of the old connection */
     
    206204
    207205        ctx = smb_composite_connect_send(io, state->mem_ctx,
    208                                          lp_resolve_context(state->tctx->lp_ctx),
     206                                         lpcfg_resolve_context(state->tctx->lp_ctx),
    209207                                         state->ev);
    210208        if (ctx == NULL) {
     
    228226        if (!NT_STATUS_IS_OK(status)) {
    229227                if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE) ||
    230                     NT_STATUS_EQUAL(status, NT_STATUS_LOCAL_DISCONNECT)) {
     228                    NT_STATUS_EQUAL(status, NT_STATUS_LOCAL_DISCONNECT) ||
     229                    NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET)) {
    231230                        talloc_free(state->tree);
    232231                        state->tree = NULL;
     
    266265        NTSTATUS status = smbcli_request_simple_recv(req);
    267266        if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE) ||
    268             NT_STATUS_EQUAL(status, NT_STATUS_LOCAL_DISCONNECT)) {
     267            NT_STATUS_EQUAL(status, NT_STATUS_LOCAL_DISCONNECT) ||
     268            NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET)) {
    269269                talloc_free(state->tree);
    270270                state->tree = NULL;
  • trunk/server/source4/torture/raw/lookuprate.c

    r414 r745  
    2121#include "system/filesys.h"
    2222#include "torture/smbtorture.h"
    23 #include "torture/basic/proto.h"
    2423#include "libcli/libcli.h"
    2524#include "torture/util.h"
    26 #include "lib/cmdline/popt_common.h"
    27 #include "auth/credentials/credentials.h"
    2825
    2926#define BASEDIR "\\lookuprate"
     
    9794
    9895                fnum = smbcli_open(tree, fname, O_RDONLY|O_CREAT,
    99                                 OPENX_MODE_DENY_NONE);
     96                                DENY_NONE);
    10097                if (fnum < 0) {
    10198                        talloc_free(fname);
     
    248245
    249246        for (i = 0; i < ARRAY_SIZE(records); ++i) {
    250                 printf("testing lookup rate with %u directory entries\n",
     247                printf("Testing lookup rate with %u directory entries\n",
    251248                                records[i].dirent_count);
    252249
  • trunk/server/source4/torture/raw/mkdir.c

    r414 r745  
    1919
    2020#include "includes.h"
    21 #include "torture/torture.h"
    2221#include "libcli/raw/libcliraw.h"
    23 #include "libcli/raw/raw_proto.h"
    2422#include "libcli/libcli.h"
    2523#include "torture/util.h"
     
    5957        CHECK_STATUS(status, NT_STATUS_OK);
    6058
    61         printf("testing mkdir collision\n");
     59        printf("Testing mkdir collision\n");
    6260
    6361        /* 2nd create */
     
    7371        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
    7472
    75         printf("testing mkdir collision with file\n");
     73        printf("Testing mkdir collision with file\n");
    7674
    7775        /* name collision with a file */
     
    8078        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
    8179
    82         printf("testing rmdir with file\n");
     80        printf("Testing rmdir with file\n");
    8381
    8482        /* delete a file with rmdir */
     
    8886        smbcli_unlink(cli->tree, path);
    8987
    90         printf("testing invalid dir\n");
     88        printf("Testing invalid dir\n");
    9189
    9290        /* create an invalid dir */
     
    9593        CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
    9694       
    97         printf("testing t2mkdir\n");
     95        printf("Testing t2mkdir\n");
    9896
    9997        /* try a t2mkdir - need to work out why this fails! */
     
    107105        CHECK_STATUS(status, NT_STATUS_OK);
    108106
    109         printf("testing t2mkdir bad path\n");
     107        printf("Testing t2mkdir bad path\n");
    110108        md.t2mkdir.in.path = talloc_asprintf(tctx, "%s\\bad_path\\bad_path",
    111109                                             BASEDIR);
     
    113111        CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_NOT_FOUND);
    114112
    115         printf("testing t2mkdir with EAs\n");
     113        printf("Testing t2mkdir with EAs\n");
    116114
    117115        /* with EAs */
  • trunk/server/source4/torture/raw/mux.c

    r414 r745  
    1919
    2020#include "includes.h"
    21 #include "torture/torture.h"
    2221#include "system/filesys.h"
    2322#include "libcli/raw/libcliraw.h"
     
    5049        double d;
    5150
    52         printf("testing multiplexed open/open/close\n");
     51        printf("Testing multiplexed open/open/close\n");
    5352
    5453        printf("send first open\n");
    5554        io.generic.level = RAW_OPEN_NTCREATEX;
    56         io.ntcreatex.in.root_fid = 0;
     55        io.ntcreatex.in.root_fid.fnum = 0;
    5756        io.ntcreatex.in.flags = 0;
    5857        io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
     
    151150        struct smbcli_request *req;
    152151
    153         printf("testing multiplexed lock/write/close\n");
     152        printf("Testing multiplexed lock/write/close\n");
    154153
    155154        fnum = smbcli_open(cli->tree, BASEDIR "\\write.dat", O_RDWR | O_CREAT, DENY_NONE);
  • trunk/server/source4/torture/raw/notify.c

    r414 r745  
    1919
    2020#include "includes.h"
    21 #include "torture/torture.h"
    2221#include "libcli/raw/libcliraw.h"
    2322#include "libcli/raw/raw_proto.h"
     
    5251        }} while (0)
    5352
     53#define CHECK_WSTR2(tctx, field, value, flags) \
     54do { \
     55        if (!field.s || strcmp(field.s, value) || \
     56            wire_bad_flags(&field, flags, cli->transport)) { \
     57                torture_result(tctx, TORTURE_FAIL, \
     58                    "(%d) %s [%s] != %s\n",  __LINE__, #field, field.s, value); \
     59        } \
     60} while (0)
    5461
    5562/*
     
    6875        extern int torture_numops;
    6976
    70         printf("TESTING CHANGE NOTIFY ON DIRECTRIES\n");
     77        printf("TESTING CHANGE NOTIFY ON DIRECTORIES\n");
    7178               
    7279        /*
     
    7481        */
    7582        io.generic.level = RAW_OPEN_NTCREATEX;
    76         io.ntcreatex.in.root_fid = 0;
     83        io.ntcreatex.in.root_fid.fnum = 0;
    7784        io.ntcreatex.in.flags = 0;
    7885        io.ntcreatex.in.access_mask = SEC_FILE_ALL;
     
    102109        notify.nttrans.in.recursive = true;
    103110
    104         printf("testing notify cancel\n");
     111        printf("Testing notify cancel\n");
    105112
    106113        req = smb_raw_changenotify_send(cli->tree, &notify);
     
    109116        CHECK_STATUS(status, NT_STATUS_CANCELLED);
    110117
    111         printf("testing notify mkdir\n");
     118        printf("Testing notify mkdir\n");
    112119
    113120        req = smb_raw_changenotify_send(cli->tree, &notify);
     
    121128        CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
    122129
    123         printf("testing notify rmdir\n");
     130        printf("Testing notify rmdir\n");
    124131
    125132        req = smb_raw_changenotify_send(cli->tree, &notify);
     
    132139        CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
    133140
    134         printf("testing notify mkdir - rmdir - mkdir - rmdir\n");
     141        printf("Testing notify mkdir - rmdir - mkdir - rmdir\n");
    135142
    136143        smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name");
     
    138145        smbcli_mkdir(cli2->tree, BASEDIR "\\subdir-name");
    139146        smbcli_rmdir(cli2->tree, BASEDIR "\\subdir-name");
    140         msleep(200);
     147        smb_msleep(200);
    141148        req = smb_raw_changenotify_send(cli->tree, &notify);
    142149        status = smb_raw_changenotify_recv(req, mem_ctx, &notify);
     
    153160
    154161        count = torture_numops;
    155         printf("testing buffered notify on create of %d files\n", count);
     162        printf("Testing buffered notify on create of %d files\n", count);
    156163        for (i=0;i<count;i++) {
    157164                char *fname = talloc_asprintf(cli, BASEDIR "\\test%d.txt", i);
     
    183190           this unlink is only seen by the 1st notify and
    184191           the 3rd notify (later) */
    185         printf("testing notify on unlink for the first file\n");
     192        printf("Testing notify on unlink for the first file\n");
    186193        status = smbcli_unlink(cli2->tree, BASEDIR "\\test0.txt");
    187194        CHECK_STATUS(status, NT_STATUS_OK);
     
    210217        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
    211218
    212         printf("testing notify on wildcard unlink for %d files\n", count-1);
     219        printf("Testing notify on wildcard unlink for %d files\n", count-1);
    213220        /* (2nd unlink) do a wildcard unlink */
    214221        status = smbcli_unlink(cli2->tree, BASEDIR "\\test*.txt");
     
    241248        }
    242249
    243         printf("testing if a close() on the dir handle triggers the notify reply\n");
     250        printf("Testing if a close() on the dir handle triggers the notify reply\n");
    244251
    245252        notify.nttrans.in.file.fnum = fnum;
     
    311318        */
    312319        io.generic.level = RAW_OPEN_NTCREATEX;
    313         io.ntcreatex.in.root_fid = 0;
     320        io.ntcreatex.in.root_fid.fnum = 0;
    314321        io.ntcreatex.in.flags = 0;
    315322        io.ntcreatex.in.access_mask = SEC_FILE_ALL;
     
    359366        notify.nttrans.in.completion_filter = 0;
    360367        notify.nttrans.in.recursive = true;
    361         msleep(200);
     368        smb_msleep(200);
    362369        req1 = smb_raw_changenotify_send(cli->tree, &notify);
    363370
     
    442449        */
    443450        io.generic.level = RAW_OPEN_NTCREATEX;
    444         io.ntcreatex.in.root_fid = 0;
     451        io.ntcreatex.in.root_fid.fnum = 0;
    445452        io.ntcreatex.in.flags = 0;
    446453        io.ntcreatex.in.access_mask = SEC_FILE_ALL;
     
    567574        */
    568575        io.generic.level = RAW_OPEN_NTCREATEX;
    569         io.ntcreatex.in.root_fid = 0;
     576        io.ntcreatex.in.root_fid.fnum = 0;
    570577        io.ntcreatex.in.flags = 0;
    571578        io.ntcreatex.in.access_mask = SEC_FILE_ALL;
     
    596603                req = smb_raw_changenotify_send(cli->tree, &notify); \
    597604                op \
    598                 msleep(200); smb_raw_ntcancel(req); \
     605                smb_msleep(200); smb_raw_ntcancel(req); \
    599606                status = smb_raw_changenotify_recv(req, tctx, &notify); \
    600607                cleanup \
     
    645652        } while (0);
    646653
    647         printf("testing mkdir\n");
    648         NOTIFY_MASK_TEST("testing mkdir",;,
     654        printf("Testing mkdir\n");
     655        NOTIFY_MASK_TEST("Testing mkdir",;,
    649656                         smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
    650657                         smbcli_rmdir(cli->tree, BASEDIR "\\tname1");,
     
    652659                         FILE_NOTIFY_CHANGE_DIR_NAME, 1);
    653660
    654         printf("testing create file\n");
    655         NOTIFY_MASK_TEST("testing create file",;,
     661        printf("Testing create file\n");
     662        NOTIFY_MASK_TEST("Testing create file",;,
    656663                         smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
    657664                         smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
     
    659666                         FILE_NOTIFY_CHANGE_FILE_NAME, 1);
    660667
    661         printf("testing unlink\n");
    662         NOTIFY_MASK_TEST("testing unlink",
     668        printf("Testing unlink\n");
     669        NOTIFY_MASK_TEST("Testing unlink",
    663670                         smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
    664671                         smbcli_unlink(cli->tree, BASEDIR "\\tname1");,
     
    667674                         FILE_NOTIFY_CHANGE_FILE_NAME, 1);
    668675
    669         printf("testing rmdir\n");
    670         NOTIFY_MASK_TEST("testing rmdir",
     676        printf("Testing rmdir\n");
     677        NOTIFY_MASK_TEST("Testing rmdir",
    671678                         smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
    672679                         smbcli_rmdir(cli->tree, BASEDIR "\\tname1");,
     
    675682                         FILE_NOTIFY_CHANGE_DIR_NAME, 1);
    676683
    677         printf("testing rename file\n");
    678         NOTIFY_MASK_TEST("testing rename file",
     684        printf("Testing rename file\n");
     685        NOTIFY_MASK_TEST("Testing rename file",
    679686                         smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
    680687                         smbcli_rename(cli->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,
     
    683690                         FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_ATTRIBUTES|FILE_NOTIFY_CHANGE_CREATION, 2);
    684691
    685         printf("testing rename dir\n");
    686         NOTIFY_MASK_TEST("testing rename dir",
     692        printf("Testing rename dir\n");
     693        NOTIFY_MASK_TEST("Testing rename dir",
    687694                smbcli_mkdir(cli->tree, BASEDIR "\\tname1");,
    688695                smbcli_rename(cli->tree, BASEDIR "\\tname1", BASEDIR "\\tname2");,
     
    691698                FILE_NOTIFY_CHANGE_DIR_NAME, 2);
    692699
    693         printf("testing set path attribute\n");
    694         NOTIFY_MASK_TEST("testing set path attribute",
     700        printf("Testing set path attribute\n");
     701        NOTIFY_MASK_TEST("Testing set path attribute",
    695702                smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
    696703                smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);,
     
    699706                FILE_NOTIFY_CHANGE_ATTRIBUTES, 1);
    700707
    701         printf("testing set path write time\n");
    702         NOTIFY_MASK_TEST("testing set path write time",
     708        printf("Testing set path write time\n");
     709        NOTIFY_MASK_TEST("Testing set path write time",
    703710                smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1", O_CREAT, 0));,
    704711                smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_NORMAL, 1000);,
     
    707714                FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
    708715
    709         printf("testing set file attribute\n");
    710         NOTIFY_MASK_TEST("testing set file attribute",
     716        printf("Testing set file attribute\n");
     717        NOTIFY_MASK_TEST("Testing set file attribute",
    711718                fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
    712719                smbcli_fsetatr(cli->tree, fnum2, FILE_ATTRIBUTE_HIDDEN, 0, 0, 0, 0);,
     
    720727        }
    721728        else {
    722                 printf("testing set file create time\n");
    723                 NOTIFY_MASK_TEST("testing set file create time",
     729                printf("Testing set file create time\n");
     730                NOTIFY_MASK_TEST("Testing set file create time",
    724731                        fnum2 = create_complex_file(cli, tctx,
    725732                                                    BASEDIR "\\tname1");,
     
    731738        }
    732739
    733         printf("testing set file access time\n");
    734         NOTIFY_MASK_TEST("testing set file access time",
     740        printf("Testing set file access time\n");
     741        NOTIFY_MASK_TEST("Testing set file access time",
    735742                fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
    736743                smbcli_fsetatr(cli->tree, fnum2, 0, 0, t, 0, 0);,
     
    739746                FILE_NOTIFY_CHANGE_LAST_ACCESS, 1);
    740747
    741         printf("testing set file write time\n");
    742         NOTIFY_MASK_TEST("testing set file write time",
     748        printf("Testing set file write time\n");
     749        NOTIFY_MASK_TEST("Testing set file write time",
    743750                fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
    744751                smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, t, 0);,
     
    747754                FILE_NOTIFY_CHANGE_LAST_WRITE, 1);
    748755
    749         printf("testing set file change time\n");
    750         NOTIFY_MASK_TEST("testing set file change time",
     756        printf("Testing set file change time\n");
     757        NOTIFY_MASK_TEST("Testing set file change time",
    751758                fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
    752759                smbcli_fsetatr(cli->tree, fnum2, 0, 0, 0, 0, t);,
     
    756763
    757764
    758         printf("testing write\n");
    759         NOTIFY_MASK_TEST("testing write",
     765        printf("Testing write\n");
     766        NOTIFY_MASK_TEST("Testing write",
    760767                fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
    761768                smbcli_write(cli->tree, fnum2, 1, &c, 10000, 1);,
     
    764771                0, 1);
    765772
    766         printf("testing truncate\n");
    767         NOTIFY_MASK_TEST("testing truncate",
     773        printf("Testing truncate\n");
     774        NOTIFY_MASK_TEST("Testing truncate",
    768775                fnum2 = create_complex_file(cli, tctx, BASEDIR "\\tname1");,
    769776                smbcli_ftruncate(cli->tree, fnum2, 10000);,
     
    794801
    795802        io.generic.level = RAW_OPEN_NTCREATEX;
    796         io.ntcreatex.in.root_fid = 0;
     803        io.ntcreatex.in.root_fid.fnum = 0;
    797804        io.ntcreatex.in.flags = 0;
    798805        io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    817824        notify.nttrans.in.recursive = false;
    818825
    819         printf("testing if notifies on file handles are invalid (should be)\n");
     826        printf("Testing if notifies on file handles are invalid (should be)\n");
    820827
    821828        req = smb_raw_changenotify_send(cli->tree, &notify);
     
    860867        */
    861868        io.generic.level = RAW_OPEN_NTCREATEX;
    862         io.ntcreatex.in.root_fid = 0;
     869        io.ntcreatex.in.root_fid.fnum = 0;
    863870        io.ntcreatex.in.flags = 0;
    864871        io.ntcreatex.in.access_mask = SEC_FILE_ALL;
     
    922929        */
    923930        io.generic.level = RAW_OPEN_NTCREATEX;
    924         io.ntcreatex.in.root_fid = 0;
     931        io.ntcreatex.in.root_fid.fnum = 0;
    925932        io.ntcreatex.in.flags = 0;
    926933        io.ntcreatex.in.access_mask = SEC_FILE_ALL;
     
    983990        */
    984991        io.generic.level = RAW_OPEN_NTCREATEX;
    985         io.ntcreatex.in.root_fid = 0;
     992        io.ntcreatex.in.root_fid.fnum = 0;
    986993        io.ntcreatex.in.flags = 0;
    987994        io.ntcreatex.in.access_mask = SEC_FILE_ALL;
     
    10511058        */
    10521059        io.generic.level = RAW_OPEN_NTCREATEX;
    1053         io.ntcreatex.in.root_fid = 0;
     1060        io.ntcreatex.in.root_fid.fnum = 0;
    10541061        io.ntcreatex.in.flags = 0;
    10551062        io.ntcreatex.in.access_mask = SEC_FILE_ALL;
     
    11051112        */
    11061113        io.generic.level = RAW_OPEN_NTCREATEX;
    1107         io.ntcreatex.in.root_fid = 0;
     1114        io.ntcreatex.in.root_fid.fnum = 0;
    11081115        io.ntcreatex.in.flags = 0;
    11091116        io.ntcreatex.in.access_mask = SEC_FILE_ALL;
     
    11981205
    11991206        io.generic.level = RAW_OPEN_NTCREATEX;
    1200         io.ntcreatex.in.root_fid = 0;
     1207        io.ntcreatex.in.root_fid.fnum = 0;
    12011208        io.ntcreatex.in.flags = 0;
    12021209        io.ntcreatex.in.access_mask = SEC_FILE_ALL;
     
    12941301        union smb_notify notify;
    12951302        union smb_open io;
    1296         int fnum, fnum2;
     1303        int fnum;
    12971304        int count = 100;
    12981305        struct smbcli_request *req1;
     
    13031310        /* get a handle on the directory */
    13041311        io.generic.level = RAW_OPEN_NTCREATEX;
    1305         io.ntcreatex.in.root_fid = 0;
     1312        io.ntcreatex.in.root_fid.fnum = 0;
    13061313        io.ntcreatex.in.flags = 0;
    13071314        io.ntcreatex.in.access_mask = SEC_FILE_ALL;
     
    13351342
    13361343        /* open a lot of files, filling up the server side notify buffer */
    1337         printf("testing overflowed buffer notify on create of %d files\n",
     1344        printf("Testing overflowed buffer notify on create of %d files\n",
    13381345               count);
    13391346        for (i=0;i<count;i++) {
     
    13721379        union smb_notify notify;
    13731380        union smb_open io;
    1374         int fnum, fnum2;
    1375         int count = 100;
     1381        int fnum;
    13761382        struct smbcli_request *req1;
    1377         int i;
    13781383
    13791384        printf("TESTING CHANGE NOTIFY BASEDIR EVENTS\n");
     
    13811386        /* get a handle on the directory */
    13821387        io.generic.level = RAW_OPEN_NTCREATEX;
    1383         io.ntcreatex.in.root_fid = 0;
     1388        io.ntcreatex.in.root_fid.fnum = 0;
    13841389        io.ntcreatex.in.flags = 0;
    13851390        io.ntcreatex.in.access_mask = SEC_FILE_ALL;
     
    14161421        /* set attribute on a file to assure we receive a notification */
    14171422        smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);
    1418         msleep(200);
     1423        smb_msleep(200);
    14191424
    14201425        /* check how many responses were given, expect only 1 for the file */
     
    14881493        */
    14891494        io.generic.level = RAW_OPEN_NTCREATEX;
    1490         io.ntcreatex.in.root_fid = 0;
     1495        io.ntcreatex.in.root_fid.fnum = 0;
    14911496        io.ntcreatex.in.flags = 0;
    14921497        io.ntcreatex.in.access_mask = SEC_FILE_ALL;
     
    15161521        notify.nttrans.in.recursive = true;
    15171522
    1518         printf("testing notify mkdir\n");
     1523        printf("Testing notify mkdir\n");
    15191524        req = smb_raw_changenotify_send(cli->tree, &notify);
    15201525        smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
     
    15271532        CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
    15281533
    1529         printf("testing notify rmdir\n");
     1534        printf("Testing notify rmdir\n");
    15301535        req = smb_raw_changenotify_send(cli->tree, &notify);
    15311536        smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
     
    15421547        tree = secondary_tcon(cli, torture);
    15431548
    1544         printf("testing notify mkdir\n");
     1549        printf("Testing notify mkdir\n");
    15451550        req = smb_raw_changenotify_send(cli->tree, &notify);
    15461551        smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
     
    15531558        CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
    15541559
    1555         printf("testing notify rmdir\n");
     1560        printf("Testing notify rmdir\n");
    15561561        req = smb_raw_changenotify_send(cli->tree, &notify);
    15571562        smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
     
    15701575        talloc_free(tree);
    15711576
    1572         printf("testing notify mkdir\n");
     1577        printf("Testing notify mkdir\n");
    15731578        req = smb_raw_changenotify_send(cli->tree, &notify);
    15741579        smbcli_mkdir(cli->tree, BASEDIR "\\subdir-name");
     
    15811586        CHECK_WSTR(notify.nttrans.out.changes[0].name, "subdir-name", STR_UNICODE);
    15821587
    1583         printf("testing notify rmdir\n");
     1588        printf("Testing notify rmdir\n");
    15841589        req = smb_raw_changenotify_send(cli->tree, &notify);
    15851590        smbcli_rmdir(cli->tree, BASEDIR "\\subdir-name");
     
    15981603
    15991604
    1600 /*
     1605/*
     1606   testing alignment of multiple change notify infos
     1607*/
     1608static bool test_notify_alignment(struct smbcli_state *cli,
     1609    struct torture_context *tctx)
     1610{
     1611        NTSTATUS status;
     1612        union smb_notify notify;
     1613        union smb_open io;
     1614        int i, fnum, fnum2;
     1615        struct smbcli_request *req;
     1616        const char *fname = BASEDIR "\\starter";
     1617        const char *fnames[] = { "a",
     1618                                 "ab",
     1619                                 "abc",
     1620                                 "abcd" };
     1621        int num_names = ARRAY_SIZE(fnames);
     1622        char *fpath = NULL;
     1623
     1624        torture_comment(tctx, "TESTING CHANGE NOTIFY REPLY ALIGNMENT\n");
     1625
     1626        /* get a handle on the directory */
     1627        io.generic.level = RAW_OPEN_NTCREATEX;
     1628        io.ntcreatex.in.root_fid.fnum = 0;
     1629        io.ntcreatex.in.flags = 0;
     1630        io.ntcreatex.in.access_mask = SEC_FILE_ALL;
     1631        io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
     1632        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     1633        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
     1634                                       NTCREATEX_SHARE_ACCESS_WRITE;
     1635        io.ntcreatex.in.alloc_size = 0;
     1636        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
     1637        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     1638        io.ntcreatex.in.security_flags = 0;
     1639        io.ntcreatex.in.fname = BASEDIR;
     1640
     1641        status = smb_raw_open(cli->tree, tctx, &io);
     1642        torture_assert_ntstatus_ok(tctx, status, "");
     1643        fnum = io.ntcreatex.out.file.fnum;
     1644
     1645        /* ask for a change notify, on file creation */
     1646        notify.nttrans.level = RAW_NOTIFY_NTTRANS;
     1647        notify.nttrans.in.buffer_size = 1000;
     1648        notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_FILE_NAME;
     1649        notify.nttrans.in.file.fnum = fnum;
     1650        notify.nttrans.in.recursive = false;
     1651
     1652        /* start change tracking */
     1653        req = smb_raw_changenotify_send(cli->tree, &notify);
     1654
     1655        fnum2 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
     1656        torture_assert(tctx, fnum2 != -1, smbcli_errstr(cli->tree));
     1657        smbcli_close(cli->tree, fnum2);
     1658
     1659        status = smb_raw_changenotify_recv(req, tctx, &notify);
     1660        torture_assert_ntstatus_ok(tctx, status, "");
     1661
     1662        /* create 4 files that will cause CHANGE_NOTIFY_INFO structures
     1663         * to be returned in the same packet with all possible 4-byte padding
     1664         * permutations.  As per MS-CIFS 2.2.7.4.2 these structures should be
     1665         * 4-byte aligned. */
     1666
     1667        for (i = 0; i < num_names; i++) {
     1668                fpath = talloc_asprintf(tctx, "%s\\%s", BASEDIR, fnames[i]);
     1669                fnum2 = smbcli_open(cli->tree, fpath,
     1670                    O_CREAT|O_RDWR, DENY_NONE);
     1671                torture_assert(tctx, fnum2 != -1, smbcli_errstr(cli->tree));
     1672                smbcli_close(cli->tree, fnum2);
     1673                talloc_free(fpath);
     1674        }
     1675
     1676        /* We send a notify packet, and let smb_raw_changenotify_recv() do
     1677         * the alignment checking for us. */
     1678        req = smb_raw_changenotify_send(cli->tree, &notify);
     1679        status = smb_raw_changenotify_recv(req, tctx, &notify);
     1680        torture_assert_ntstatus_ok(tctx, status, "");
     1681
     1682        /* Do basic checking for correctness. */
     1683        torture_assert(tctx, notify.nttrans.out.num_changes == num_names, "");
     1684        for (i = 0; i < num_names; i++) {
     1685                torture_assert(tctx, notify.nttrans.out.changes[i].action ==
     1686                    NOTIFY_ACTION_ADDED, "");
     1687                CHECK_WSTR2(tctx, notify.nttrans.out.changes[i].name, fnames[i],
     1688                    STR_UNICODE);
     1689        }
     1690
     1691        return true;
     1692}
     1693
     1694/*
    16011695   basic testing of change notify
    16021696*/
     
    16251719        ret &= test_notify_overflow(cli, torture);
    16261720        ret &= test_notify_basedir(cli, torture);
     1721        ret &= test_notify_alignment(cli, torture);
    16271722
    16281723        smb_raw_exit(cli->session);
  • trunk/server/source4/torture/raw/offline.c

    r414 r745  
    2323
    2424#include "includes.h"
    25 #include "torture/torture.h"
    26 #include "libcli/raw/libcliraw.h"
    2725#include "system/time.h"
    2826#include "system/filesys.h"
     
    3028#include "torture/util.h"
    3129#include "lib/events/events.h"
    32 #include "lib/cmdline/popt_common.h"
    3330#include "libcli/composite/composite.h"
    3431#include "libcli/smb_composite/smb_composite.h"
    35 #include "libcli/resolve/resolve.h"
    3632
    3733#define BASEDIR "\\testoffline"
     
    322318        NTSTATUS status = smbcli_request_simple_recv(req);
    323319        if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE) ||
    324             NT_STATUS_EQUAL(status, NT_STATUS_LOCAL_DISCONNECT)) {
     320            NT_STATUS_EQUAL(status, NT_STATUS_LOCAL_DISCONNECT) ||
     321            NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET)) {
    325322                talloc_free(state->tree);
    326323                state->tree = NULL;
  • trunk/server/source4/torture/raw/open.c

    r414 r745  
    1919
    2020#include "includes.h"
    21 #include "torture/torture.h"
    2221#include "libcli/raw/libcliraw.h"
    23 #include "libcli/raw/raw_proto.h"
    2422#include "system/time.h"
    2523#include "system/filesys.h"
    26 #include "librpc/gen_ndr/security.h"
    2724#include "lib/events/events.h"
    2825#include "libcli/libcli.h"
    2926#include "torture/util.h"
    30 #include "auth/credentials/credentials.h"
    31 #include "lib/cmdline/popt_common.h"
    3227
    3328/* enum for whether reads/writes are possible on a file */
     
    6661#define CHECK_STATUS(status, correct) do { \
    6762        if (!NT_STATUS_EQUAL(status, correct)) { \
    68                 printf("(%s) Incorrect status %s - should be %s\n", \
     63                torture_result(tctx, TORTURE_FAIL, \
     64                        "(%s) Incorrect status %s - should be %s\n", \
    6965                       __location__, nt_errstr(status), nt_errstr(correct)); \
    7066                ret = false; \
     
    7571        fnum = create_complex_file(cli, tctx, fname); \
    7672        if (fnum == -1) { \
    77                 printf("(%s) Failed to create %s - %s\n", __location__, fname, smbcli_errstr(cli->tree)); \
     73                torture_result(tctx, TORTURE_FAIL, \
     74                        "(%s) Failed to create %s - %s\n", \
     75                         __location__, fname, smbcli_errstr(cli->tree)); \
    7876                ret = false; \
    7977                goto done; \
     
    8381        enum rdwr_mode m = check_rdwr(cli->tree, fnum); \
    8482        if (m != correct) { \
    85                 printf("(%s) Incorrect readwrite mode %s - expected %s\n", \
     83                torture_result(tctx, TORTURE_FAIL, \
     84                       "(%s) Incorrect readwrite mode %s - expected %s\n", \
    8685                       __location__, rdwr_string(m), rdwr_string(correct)); \
    8786                ret = false; \
     
    9796        t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
    9897        if (abs(t1-t2) > 2) { \
    99                 printf("(%s) wrong time for field %s  %s - %s\n", \
     98                torture_result(tctx, TORTURE_FAIL, \
     99                       "(%s) wrong time for field %s  %s - %s\n", \
    100100                       __location__, #field, \
    101101                       timestring(tctx, t1), \
     
    113113        t2 = finfo.all_info.out.field; \
    114114        if (t != t2) { \
    115                 printf("(%s) wrong time for field %s  %s - %s\n", \
     115                torture_result(tctx, TORTURE_FAIL, \
     116                       "(%s) wrong time for field %s  %s - %s\n", \
    116117                       __location__, #field, \
    117118                       nt_time_string(tctx, t), \
     
    127128        CHECK_STATUS(status, NT_STATUS_OK); \
    128129        if ((v) != (finfo.all_info.out.field)) { \
    129                 printf("(%s) wrong value for field %s  0x%x - 0x%x\n", \
     130                torture_result(tctx, TORTURE_FAIL, \
     131                       "(%s) wrong value for field %s  0x%x - 0x%x\n", \
    130132                       __location__, #field, (int)v, (int)(finfo.all_info.out.field)); \
    131133                dump_all_info(tctx, &finfo); \
     
    135137#define CHECK_VAL(v, correct) do { \
    136138        if ((v) != (correct)) { \
    137                 printf("(%s) wrong value for %s  0x%x - should be 0x%x\n", \
     139                torture_result(tctx, TORTURE_FAIL, \
     140                       "(%s) wrong value for %s  0x%x - should be 0x%x\n", \
    138141                       __location__, #v, (int)(v), (int)correct); \
    139142                ret = false; \
     
    148151        status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
    149152        if (!NT_STATUS_IS_OK(status)) { \
    150                 printf("(%s) Failed to set attrib 0x%x on %s\n", \
     153                torture_warning(tctx, "(%s) Failed to set attrib 0x%x on %s\n", \
    151154                       __location__, sattrib, fname); \
    152155        }} while (0)
     
    155158  test RAW_OPEN_OPEN
    156159*/
    157 static bool test_open(struct smbcli_state *cli, struct torture_context *tctx)
     160static bool test_open(struct torture_context *tctx, struct smbcli_state *cli)
    158161{
    159162        union smb_open io;
     
    164167        bool ret = true;
    165168
    166         printf("Checking RAW_OPEN_OPEN\n");
     169        if (!torture_setup_dir(cli, BASEDIR)) {
     170                return false;
     171        }
    167172
    168173        io.openold.level = RAW_OPEN_OPEN;
     
    224229       
    225230        if (io.openold.in.open_mode != io.openold.out.rmode) {
    226                 printf("(%s) rmode should equal open_mode - 0x%x 0x%x\n",
     231                torture_warning(tctx, "(%s) rmode should equal open_mode - 0x%x 0x%x\n",
    227232                       __location__, io.openold.out.rmode, io.openold.in.open_mode);
    228233        }
     
    257262done:
    258263        smbcli_close(cli->tree, fnum);
    259         smbcli_unlink(cli->tree, fname);
     264        smbcli_deltree(cli->tree, BASEDIR);
    260265
    261266        return ret;
     
    266271  test RAW_OPEN_OPENX
    267272*/
    268 static bool test_openx(struct smbcli_state *cli, struct torture_context *tctx)
     273static bool test_openx(struct torture_context *tctx, struct smbcli_state *cli)
    269274{
    270275        union smb_open io;
     
    296301        };
    297302
    298         printf("Checking RAW_OPEN_OPENX\n");
    299         smbcli_unlink(cli->tree, fname);
     303        if (!torture_setup_dir(cli, BASEDIR)) {
     304                return false;
     305        }
    300306
    301307        io.openx.level = RAW_OPEN_OPENX;
     
    314320                        fnum = create_complex_file(cli, tctx, fname);
    315321                        if (fnum == -1) {
    316                                 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
     322                                torture_result(tctx, TORTURE_FAIL,
     323                                        "Failed to create file %s - %s\n",
     324                                        fname, smbcli_errstr(cli->tree));
    317325                                ret = false;
    318326                                goto done;
     
    323331                status = smb_raw_open(cli->tree, tctx, &io);
    324332                if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
    325                         printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
    326                                __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
    327                                i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
     333                        torture_result(tctx, TORTURE_FAIL,
     334                                "(%s) incorrect status %s should be %s "
     335                                "(i=%d with_file=%d open_func=0x%x)\n",
     336                                __location__, nt_errstr(status),
     337                                nt_errstr(open_funcs[i].correct_status),
     338                                i, (int)open_funcs[i].with_file,
     339                                (int)open_funcs[i].open_func);
    328340                        ret = false;
    329341                }
     
    425437        CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
    426438        if (timeval_elapsed(&tv) > 3.0) {
    427                 printf("(%s) Incorrect timing in openx with timeout - waited %.2f seconds\n",
    428                        __location__, timeval_elapsed(&tv));
     439                torture_result(tctx, TORTURE_FAIL,
     440                        "(%s) Incorrect timing in openx with timeout "
     441                        "- waited %.2f seconds\n",
     442                        __location__, timeval_elapsed(&tv));
    429443                ret = false;
    430444        }
     
    484498done:
    485499        smbcli_close(cli->tree, fnum);
    486         smbcli_unlink(cli->tree, fname_exe);
    487         smbcli_unlink(cli->tree, fname);
     500        smbcli_deltree(cli->tree, BASEDIR);
    488501
    489502        return ret;
     
    496509  many thanks to kukks for a sniff showing how this works with os2->w2k
    497510*/
    498 static bool test_t2open(struct smbcli_state *cli, struct torture_context *tctx)
     511static bool test_t2open(struct torture_context *tctx, struct smbcli_state *cli)
    499512{
    500513        union smb_open io;
     
    526539        };
    527540
     541        if (!torture_setup_dir(cli, BASEDIR)) {
     542                return false;
     543        }
     544
    528545        fnum = create_complex_file(cli, tctx, fname1);
    529546        if (fnum == -1) {
    530                 d_printf("Failed to create file %s - %s\n", fname1, smbcli_errstr(cli->tree));
     547                torture_result(tctx, TORTURE_FAIL,
     548                        "(%s): Failed to create file %s - %s\n",
     549                        __location__, fname1, smbcli_errstr(cli->tree));
    531550                ret = false;
    532551                goto done;
    533552        }
    534553        smbcli_close(cli->tree, fnum);
    535 
    536         printf("Checking RAW_OPEN_T2OPEN\n");
    537554
    538555        io.t2open.level = RAW_OPEN_T2OPEN;
     
    571588                    && NT_STATUS_EQUAL(status, NT_STATUS_EAS_NOT_SUPPORTED)
    572589                    && torture_setting_bool(tctx, "samba3", false)) {
    573                         printf("(%s) EAs not supported, not treating as fatal "
    574                                "in Samba3 test\n", __location__);
     590                        torture_warning(tctx, "(%s) EAs not supported, not "
     591                                "treating as fatal in Samba3 test\n",
     592                                __location__);
    575593                        io.t2open.in.num_eas = 0;
    576594                        goto again;
     
    578596
    579597                if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
    580                         printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
    581                                __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
    582                                i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
     598                        torture_result(tctx, TORTURE_FAIL,
     599                                "(%s) incorrect status %s should be %s "
     600                                "(i=%d with_file=%d open_func=0x%x)\n",
     601                                 __location__, nt_errstr(status),
     602                                nt_errstr(open_funcs[i].correct_status),
     603                                i, (int)open_funcs[i].with_file,
     604                                (int)open_funcs[i].open_func);
    583605                        ret = false;
    584606                }
     
    652674done:
    653675        smbcli_close(cli->tree, fnum);
    654         smbcli_unlink(cli->tree, fname);
     676        smbcli_deltree(cli->tree, BASEDIR);
    655677
    656678        return ret;
     
    661683  test RAW_OPEN_NTCREATEX
    662684*/
    663 static bool test_ntcreatex(struct smbcli_state *cli, struct torture_context *tctx)
     685static bool test_ntcreatex(struct torture_context *tctx, struct smbcli_state *cli)
    664686{
    665687        union smb_open io;
     
    692714        };
    693715
    694         printf("Checking RAW_OPEN_NTCREATEX\n");
     716        if (!torture_setup_dir(cli, BASEDIR)) {
     717                return false;
     718        }
    695719
    696720        /* reasonable default parameters */
    697721        io.generic.level = RAW_OPEN_NTCREATEX;
    698722        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
    699         io.ntcreatex.in.root_fid = 0;
     723        io.ntcreatex.in.root_fid.fnum = 0;
    700724        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    701725        io.ntcreatex.in.alloc_size = 1024*1024;
     
    713737                        fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
    714738                        if (fnum == -1) {
    715                                 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
     739                                torture_result(tctx, TORTURE_FAIL,
     740                                        "Failed to create file %s - %s\n",
     741                                        fname, smbcli_errstr(cli->tree));
    716742                                ret = false;
    717743                                goto done;
     
    722748                status = smb_raw_open(cli->tree, tctx, &io);
    723749                if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
    724                         printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n",
    725                                __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
    726                                i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
     750                        torture_result(tctx, TORTURE_FAIL,
     751                                "(%s) incorrect status %s should be %s "
     752                                "(i=%d with_file=%d open_disp=%d)\n",
     753                                __location__, nt_errstr(status),
     754                                nt_errstr(open_funcs[i].correct_status),
     755                                i, (int)open_funcs[i].with_file,
     756                                (int)open_funcs[i].open_disp);
    727757                        ret = false;
    728758                }
     
    825855done:
    826856        smbcli_close(cli->tree, fnum);
    827         smbcli_unlink(cli->tree, fname);
     857        smbcli_deltree(cli->tree, BASEDIR);
    828858
    829859        return ret;
     
    834864  test RAW_OPEN_NTTRANS_CREATE
    835865*/
    836 static bool test_nttrans_create(struct smbcli_state *cli, struct torture_context *tctx)
     866static bool test_nttrans_create(struct torture_context *tctx, struct smbcli_state *cli)
    837867{
    838868        union smb_open io;
     
    867897        };
    868898
    869         printf("Checking RAW_OPEN_NTTRANS_CREATE\n");
     899        if (!torture_setup_dir(cli, BASEDIR)) {
     900                return false;
     901        }
    870902
    871903        /* reasonable default parameters */
    872904        io.generic.level = RAW_OPEN_NTTRANS_CREATE;
    873905        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
    874         io.ntcreatex.in.root_fid = 0;
     906        io.ntcreatex.in.root_fid.fnum = 0;
    875907        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    876908        io.ntcreatex.in.alloc_size = 1024*1024;
     
    890922                        fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
    891923                        if (fnum == -1) {
    892                                 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
     924                                torture_result(tctx, TORTURE_FAIL,
     925                                        "Failed to create file %s - %s\n",
     926                                        fname, smbcli_errstr(cli->tree));
    893927                                ret = false;
    894928                                goto done;
     
    899933                status = smb_raw_open(cli->tree, tctx, &io);
    900934                if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
    901                         printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n",
    902                                __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
    903                                i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
     935                        torture_result(tctx, TORTURE_FAIL,
     936                                "(%s) incorrect status %s should be %s "
     937                                "(i=%d with_file=%d open_disp=%d)\n",
     938                                __location__, nt_errstr(status),
     939                                nt_errstr(open_funcs[i].correct_status),
     940                                i, (int)open_funcs[i].with_file,
     941                                (int)open_funcs[i].open_disp);
    904942                        ret = false;
    905943                }
     
    9851023                status = smb_raw_open(cli->tree, tctx, &io);
    9861024                if (!NT_STATUS_IS_OK(status)) {
    987                         printf("ntcreatex create option 0x%08x gave %s - should give NT_STATUS_OK\n",
    988                                create_option, nt_errstr(status));
     1025                        torture_warning(tctx, "ntcreatex create option 0x%08x "
     1026                                "gave %s - should give NT_STATUS_OK\n",
     1027                                create_option, nt_errstr(status));
    9891028                }
    9901029                CHECK_STATUS(status, NT_STATUS_OK);
     
    10331072                } else {
    10341073                        unexpected_mask |= 1<<i;
    1035                         printf("create option 0x%08x returned %s\n", create_option, nt_errstr(status));
     1074                        torture_comment(tctx, "create option 0x%08x returned %s\n",
     1075                                        create_option, nt_errstr(status));
    10361076                }
    10371077        }
     
    10891129done:
    10901130        smbcli_close(cli->tree, fnum);
    1091         smbcli_unlink(cli->tree, fname);
     1131        smbcli_deltree(cli->tree, BASEDIR);
    10921132
    10931133        return ret;
     
    11021142  second open.
    11031143*/
    1104 static bool test_ntcreatex_brlocked(struct smbcli_state *cli, struct torture_context *tctx)
     1144static bool test_ntcreatex_brlocked(struct torture_context *tctx, struct smbcli_state *cli)
    11051145{
    11061146        union smb_open io, io1;
     
    11111151        bool ret = true;
    11121152
    1113         printf("Testing ntcreatex with a byte range locked file\n");
     1153        if (!torture_setup_dir(cli, BASEDIR)) {
     1154                return false;
     1155        }
     1156
     1157        torture_comment(tctx, "Testing ntcreatex with a byte range locked file\n");
    11141158
    11151159        io.generic.level = RAW_OPEN_NTCREATEX;
    11161160        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
    1117         io.ntcreatex.in.root_fid = 0;
     1161        io.ntcreatex.in.root_fid.fnum = 0;
    11181162        io.ntcreatex.in.access_mask = 0x2019f;
    11191163        io.ntcreatex.in.alloc_size = 0;
     
    11461190        io1.generic.level = RAW_OPEN_NTCREATEX;
    11471191        io1.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
    1148         io1.ntcreatex.in.root_fid = 0;
     1192        io1.ntcreatex.in.root_fid.fnum = 0;
    11491193        io1.ntcreatex.in.access_mask = 0x20196;
    11501194        io1.ntcreatex.in.alloc_size = 0;
     
    11651209        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    11661210        smbcli_close(cli->tree, io1.ntcreatex.out.file.fnum);
    1167         smbcli_unlink(cli->tree, fname);
     1211        smbcli_deltree(cli->tree, BASEDIR);
    11681212        return ret;
    11691213}
     
    11721216  test RAW_OPEN_MKNEW
    11731217*/
    1174 static bool test_mknew(struct smbcli_state *cli, struct torture_context *tctx)
     1218static bool test_mknew(struct torture_context *tctx, struct smbcli_state *cli)
    11751219{
    11761220        union smb_open io;
     
    11821226        union smb_fileinfo finfo;
    11831227
    1184         printf("Checking RAW_OPEN_MKNEW\n");
     1228        if (!torture_setup_dir(cli, BASEDIR)) {
     1229                return false;
     1230        }
    11851231
    11861232        io.mknew.level = RAW_OPEN_MKNEW;
     
    12181264done:
    12191265        smbcli_close(cli->tree, fnum);
    1220         smbcli_unlink(cli->tree, fname);
     1266        smbcli_deltree(cli->tree, BASEDIR);
    12211267
    12221268        return ret;
     
    12271273  test RAW_OPEN_CREATE
    12281274*/
    1229 static bool test_create(struct smbcli_state *cli, struct torture_context *tctx)
     1275static bool test_create(struct torture_context *tctx, struct smbcli_state *cli)
    12301276{
    12311277        union smb_open io;
     
    12371283        union smb_fileinfo finfo;
    12381284
    1239         printf("Checking RAW_OPEN_CREATE\n");
     1285        if (!torture_setup_dir(cli, BASEDIR)) {
     1286                return false;
     1287        }
    12401288
    12411289        io.create.level = RAW_OPEN_CREATE;
     
    12741322done:
    12751323        smbcli_close(cli->tree, fnum);
    1276         smbcli_unlink(cli->tree, fname);
     1324        smbcli_deltree(cli->tree, BASEDIR);
    12771325
    12781326        return ret;
     
    12831331  test RAW_OPEN_CTEMP
    12841332*/
    1285 static bool test_ctemp(struct smbcli_state *cli, TALLOC_CTX *tctx)
     1333static bool test_ctemp(struct torture_context *tctx, struct smbcli_state *cli)
    12861334{
    12871335        union smb_open io;
     
    12931341        const char *name, *fname = NULL;
    12941342
    1295         printf("Checking RAW_OPEN_CTEMP\n");
     1343        if (!torture_setup_dir(cli, BASEDIR)) {
     1344                return false;
     1345        }
    12961346
    12971347        io.ctemp.level = RAW_OPEN_CTEMP;
     
    13111361
    13121362        fname = finfo.name_info.out.fname.s;
    1313         d_printf("ctemp name=%s  real name=%s\n", name, fname);
     1363        torture_comment(tctx, "ctemp name=%s  real name=%s\n", name, fname);
    13141364
    13151365done:
    13161366        smbcli_close(cli->tree, fnum);
    1317         if (fname) {
    1318                 smbcli_unlink(cli->tree, fname);
    1319         }
     1367        smbcli_deltree(cli->tree, BASEDIR);
    13201368
    13211369        return ret;
     
    13261374  test chained RAW_OPEN_OPENX_READX
    13271375*/
    1328 static bool test_chained(struct smbcli_state *cli, TALLOC_CTX *tctx)
     1376static bool test_chained(struct torture_context *tctx, struct smbcli_state *cli)
    13291377{
    13301378        union smb_open io;
     
    13361384        char buf2[4];
    13371385
    1338         printf("Checking RAW_OPEN_OPENX chained with READX\n");
    1339         smbcli_unlink(cli->tree, fname);
     1386        if (!torture_setup_dir(cli, BASEDIR)) {
     1387                return false;
     1388        }
    13401389
    13411390        fnum = create_complex_file(cli, tctx, fname);
     
    13671416
    13681417        if (memcmp(buf, buf2, sizeof(buf)) != 0) {
    1369                 d_printf("wrong data in reply buffer\n");
     1418                torture_result(tctx, TORTURE_FAIL,
     1419                        "wrong data in reply buffer\n");
    13701420                ret = false;
    13711421        }
     
    13731423done:
    13741424        smbcli_close(cli->tree, fnum);
    1375         smbcli_unlink(cli->tree, fname);
     1425        smbcli_deltree(cli->tree, BASEDIR);
    13761426
    13771427        return ret;
     
    13831433 
    13841434*/
    1385 static bool test_no_leading_slash(struct smbcli_state *cli, TALLOC_CTX *tctx)
     1435static bool test_no_leading_slash(struct torture_context *tctx, struct smbcli_state *cli)
    13861436{
    13871437        union smb_open io;
     
    13921442        const char *buf = "test";
    13931443
    1394         printf("Checking RAW_OPEN_OPENX without leading slash on path\n");
    1395         smbcli_unlink(cli->tree, fname);
    1396 
    1397         /* Create the file */
     1444        if (!torture_setup_dir(cli, BASEDIR)) {
     1445                return false;
     1446        }
     1447
     1448        smbcli_unlink(cli->tree, fname);
     1449
     1450        /* Create the file */
    13981451        fnum = create_complex_file(cli, tctx, fname);
    13991452        smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
    14001453        smbcli_close(cli->tree, fnum); 
    14011454
    1402         /* Prepare to open the file using path without leading slash */
     1455        /* Prepare to open the file using path without leading slash */
    14031456        io.openx.level = RAW_OPEN_OPENX;
    14041457        io.openx.in.fname = fname + 1;
     
    14181471done:
    14191472        smbcli_close(cli->tree, fnum);
    1420         smbcli_unlink(cli->tree, fname);
     1473        smbcli_deltree(cli->tree, BASEDIR);
    14211474
    14221475        return ret;
     
    14291482 
    14301483*/
    1431 static bool test_openx_over_dir(struct smbcli_state *cli, TALLOC_CTX *tctx)
     1484static bool test_openx_over_dir(struct torture_context *tctx, struct smbcli_state *cli)
    14321485{
    14331486        union smb_open io;
     
    14381491        bool ret = true;
    14391492
    1440         printf("Checking RAW_OPEN_OPENX over an existing directory\n");
    1441         smbcli_unlink(cli->tree, fname);
    1442 
    1443         /* Create the Directory */
     1493        if (!torture_setup_dir(cli, BASEDIR)) {
     1494                return false;
     1495        }
     1496
     1497        /* Create the Directory */
    14441498        status = create_directory_handle(cli->tree, fname, &d_fnum);
    14451499        smbcli_close(cli->tree, d_fnum);       
    14461500
    1447         /* Prepare to open the file over the directory. */
     1501        /* Prepare to open the file over the directory. */
    14481502        io.openx.level = RAW_OPEN_OPENX;
    14491503        io.openx.in.fname = fname;
     
    14631517done:
    14641518        smbcli_close(cli->tree, fnum);
    1465         smbcli_unlink(cli->tree, fname);
     1519        smbcli_deltree(cli->tree, BASEDIR);
    14661520
    14671521        return ret;
     
    14711525/* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
    14721526
    1473 static bool test_raw_open_multi(struct torture_context *tctx)
     1527static bool test_raw_open_multi(struct torture_context *tctx, struct smbcli_state *cli_ignored)
    14741528{
    14751529        struct smbcli_state *cli;
     
    14931547        if ((tctx->ev == NULL) || (clients == NULL) || (requests == NULL) ||
    14941548            (ios == NULL)) {
    1495                 DEBUG(0, ("talloc failed\n"));
     1549                torture_result(tctx, TORTURE_FAIL, "(%s): talloc failed\n",
     1550                                __location__);
    14961551                return false;
    14971552        }
     
    15061561                if (!torture_open_connection_share(mem_ctx, &(clients[i]),
    15071562                                                   tctx, host, share, tctx->ev)) {
    1508                         DEBUG(0, ("Could not open %d'th connection\n", i));
     1563                        torture_result(tctx, TORTURE_FAIL,
     1564                                       "(%s): Could not open %d'th connection\n",
     1565                                       __location__, i);
    15091566                        return false;
    15101567                }
     
    15191576        */
    15201577        io.generic.level = RAW_OPEN_NTCREATEX;
    1521         io.ntcreatex.in.root_fid = 0;
     1578        io.ntcreatex.in.root_fid.fnum = 0;
    15221579        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    15231580        io.ntcreatex.in.alloc_size = 0;
     
    15371594                requests[i] = smb_raw_open_send(clients[i]->tree, &ios[i]);
    15381595                if (requests[i] == NULL) {
    1539                         DEBUG(0, ("could not send %d'th request\n", i));
     1596                        torture_result(tctx, TORTURE_FAIL,
     1597                                "(%s): could not send %d'th request\n",
     1598                                __location__, i);
    15401599                        return false;
    15411600                }
    15421601        }
    15431602
    1544         DEBUG(10, ("waiting for replies\n"));
     1603        torture_comment(tctx, "waiting for replies\n");
    15451604        while (1) {
    15461605                bool unreplied = false;
     
    15561615                                                   &ios[i]);
    15571616
    1558                         DEBUG(0, ("File %d returned status %s\n", i,
    1559                                   nt_errstr(status)));
     1617                        torture_comment(tctx, "File %d returned status %s\n", i,
     1618                                  nt_errstr(status));
    15601619
    15611620                        if (NT_STATUS_IS_OK(status)) {
     
    15751634
    15761635                if (event_loop_once(tctx->ev) != 0) {
    1577                         DEBUG(0, ("event_loop_once failed\n"));
     1636                        torture_result(tctx, TORTURE_FAIL,
     1637                                "(%s): event_loop_once failed\n", __location__);
    15781638                        return false;
    15791639                }
     
    15941654  test opening for delete on a read-only attribute file.
    15951655*/
    1596 static bool test_open_for_delete(struct smbcli_state *cli, struct torture_context *tctx)
     1656static bool test_open_for_delete(struct torture_context *tctx, struct smbcli_state *cli)
    15971657{
    15981658        union smb_open io;
     
    16031663        bool ret = true;
    16041664
    1605         printf("Checking RAW_NTCREATEX for delete on a readonly file.\n");
     1665        if (!torture_setup_dir(cli, BASEDIR)) {
     1666                return false;
     1667        }
    16061668
    16071669        /* reasonable default parameters */
    16081670        io.generic.level = RAW_OPEN_NTCREATEX;
    16091671        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
    1610         io.ntcreatex.in.root_fid = 0;
     1672        io.ntcreatex.in.root_fid.fnum = 0;
    16111673        io.ntcreatex.in.alloc_size = 0;
    16121674        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     
    16431705done:
    16441706        smbcli_close(cli->tree, fnum);
    1645         smbcli_unlink(cli->tree, fname);
     1707        smbcli_deltree(cli->tree, BASEDIR);
    16461708
    16471709        return ret;
    16481710}
    16491711
    1650 
    1651 /* basic testing of all RAW_OPEN_* calls
     1712/*
     1713  test chained RAW_OPEN_NTCREATEX_READX
     1714  Send chained NTCREATEX_READX on a file that doesn't exist, then create
     1715  the file and try again.
    16521716*/
    1653 bool torture_raw_open(struct torture_context *torture, struct smbcli_state *cli)
     1717static bool test_chained_ntcreatex_readx(struct torture_context *tctx, struct smbcli_state *cli)
    16541718{
     1719        TALLOC_CTX *mem_ctx = talloc_new(tctx);
     1720        union smb_open io;
     1721        const char *fname = BASEDIR "\\torture_chained.txt";
     1722        NTSTATUS status;
     1723        int fnum = -1;
    16551724        bool ret = true;
     1725        const char *buf = "test";
     1726        char buf2[4];
    16561727
    16571728        if (!torture_setup_dir(cli, BASEDIR)) {
     
    16591730        }
    16601731
    1661         ret &= test_ntcreatex_brlocked(cli, torture);
    1662         ret &= test_open(cli, torture);
    1663         ret &= test_raw_open_multi(torture);
    1664         ret &= test_openx(cli, torture);
    1665         ret &= test_ntcreatex(cli, torture);
    1666         ret &= test_nttrans_create(cli, torture);
    1667         ret &= test_t2open(cli, torture);
    1668         ret &= test_mknew(cli, torture);
    1669         ret &= test_create(cli, torture);
    1670         ret &= test_ctemp(cli, torture);
    1671         ret &= test_chained(cli, torture);
    1672         ret &= test_no_leading_slash(cli, torture);
    1673         ret &= test_openx_over_dir(cli, torture);
    1674         ret &= test_open_for_delete(cli, torture);
    1675 
    1676         smb_raw_exit(cli->session);
     1732        torture_comment(tctx, "Checking RAW_NTCREATEX_READX chained on "
     1733                              "non-existant file \n");
     1734
     1735        /* ntcreatex parameters */
     1736        io.generic.level = RAW_OPEN_NTCREATEX_READX;
     1737        io.ntcreatexreadx.in.flags = 0;
     1738        io.ntcreatexreadx.in.root_fid.fnum = 0;
     1739        io.ntcreatexreadx.in.access_mask = SEC_FILE_READ_DATA;
     1740        io.ntcreatexreadx.in.alloc_size = 0;
     1741        io.ntcreatexreadx.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     1742        io.ntcreatexreadx.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
     1743                NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
     1744        io.ntcreatexreadx.in.open_disposition = NTCREATEX_DISP_OPEN;
     1745        io.ntcreatexreadx.in.create_options = 0;
     1746        io.ntcreatexreadx.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
     1747        io.ntcreatexreadx.in.security_flags = 0;
     1748        io.ntcreatexreadx.in.fname = fname;
     1749
     1750        /* readx parameters */
     1751        io.ntcreatexreadx.in.offset = 0;
     1752        io.ntcreatexreadx.in.mincnt = sizeof(buf);
     1753        io.ntcreatexreadx.in.maxcnt = sizeof(buf);
     1754        io.ntcreatexreadx.in.remaining = 0;
     1755        io.ntcreatexreadx.out.data = (uint8_t *)buf2;
     1756
     1757        /* try to open the non-existant file */
     1758        status = smb_raw_open(cli->tree, mem_ctx, &io);
     1759        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
     1760        fnum = io.ntcreatexreadx.out.file.fnum;
     1761
     1762        smbcli_close(cli->tree, fnum);
     1763        smbcli_unlink(cli->tree, fname);
     1764
     1765        torture_comment(tctx, "Checking RAW_NTCREATEX_READX chained on "
     1766                              "existing file \n");
     1767
     1768        fnum = create_complex_file(cli, mem_ctx, fname);
     1769        smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
     1770        smbcli_close(cli->tree, fnum);
     1771
     1772        status = smb_raw_open(cli->tree, mem_ctx, &io);
     1773        CHECK_STATUS(status, NT_STATUS_OK);
     1774        fnum = io.ntcreatexreadx.out.file.fnum;
     1775
     1776        if (memcmp(buf, buf2, sizeof(buf)) != 0) {
     1777                torture_result(tctx, TORTURE_FAIL,
     1778                        "(%s): wrong data in reply buffer\n", __location__);
     1779                ret = false;
     1780        }
     1781
     1782done:
     1783        smbcli_close(cli->tree, fnum);
    16771784        smbcli_deltree(cli->tree, BASEDIR);
     1785        talloc_free(mem_ctx);
    16781786
    16791787        return ret;
    16801788}
     1789
     1790static bool test_ntcreatex_opendisp_dir(struct torture_context *tctx,
     1791                                        struct smbcli_state *cli)
     1792{
     1793        const char *dname = BASEDIR "\\torture_ntcreatex_opendisp_dir";
     1794        NTSTATUS status;
     1795        bool ret = true;
     1796        int i;
     1797        struct {
     1798                uint32_t open_disp;
     1799                bool dir_exists;
     1800                NTSTATUS correct_status;
     1801        } open_funcs_dir[] = {
     1802                { NTCREATEX_DISP_SUPERSEDE,     true,  NT_STATUS_INVALID_PARAMETER },
     1803                { NTCREATEX_DISP_SUPERSEDE,     false, NT_STATUS_INVALID_PARAMETER },
     1804                { NTCREATEX_DISP_OPEN,          true,  NT_STATUS_OK },
     1805                { NTCREATEX_DISP_OPEN,          false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
     1806                { NTCREATEX_DISP_CREATE,        true,  NT_STATUS_OBJECT_NAME_COLLISION },
     1807                { NTCREATEX_DISP_CREATE,        false, NT_STATUS_OK },
     1808                { NTCREATEX_DISP_OPEN_IF,       true,  NT_STATUS_OK },
     1809                { NTCREATEX_DISP_OPEN_IF,       false, NT_STATUS_OK },
     1810                { NTCREATEX_DISP_OVERWRITE,     true,  NT_STATUS_INVALID_PARAMETER },
     1811                { NTCREATEX_DISP_OVERWRITE,     false, NT_STATUS_INVALID_PARAMETER },
     1812                { NTCREATEX_DISP_OVERWRITE_IF,  true,  NT_STATUS_INVALID_PARAMETER },
     1813                { NTCREATEX_DISP_OVERWRITE_IF,  false, NT_STATUS_INVALID_PARAMETER },
     1814                { 6,                            true,  NT_STATUS_INVALID_PARAMETER },
     1815                { 6,                            false, NT_STATUS_INVALID_PARAMETER },
     1816        };
     1817        union smb_open io;
     1818
     1819        ZERO_STRUCT(io);
     1820        io.generic.level = RAW_OPEN_NTCREATEX;
     1821        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
     1822        io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     1823        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
     1824        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
     1825        io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
     1826        io.ntcreatex.in.fname = dname;
     1827
     1828        if (!torture_setup_dir(cli, BASEDIR)) {
     1829                return false;
     1830        }
     1831
     1832        smbcli_rmdir(cli->tree, dname);
     1833        smbcli_unlink(cli->tree, dname);
     1834
     1835        /* test the open disposition for directories */
     1836        torture_comment(tctx, "Testing open dispositions for directories...\n");
     1837
     1838        for (i=0; i<ARRAY_SIZE(open_funcs_dir); i++) {
     1839                if (open_funcs_dir[i].dir_exists) {
     1840                        status = smbcli_mkdir(cli->tree, dname);
     1841                        if (!NT_STATUS_IS_OK(status)) {
     1842                                torture_result(tctx, TORTURE_FAIL,
     1843                                        "(%s): Failed to make directory "
     1844                                        "%s - %s\n", __location__, dname,
     1845                                        smbcli_errstr(cli->tree));
     1846                                ret = false;
     1847                                goto done;
     1848                        }
     1849                }
     1850
     1851                io.ntcreatex.in.open_disposition = open_funcs_dir[i].open_disp;
     1852                status = smb_raw_open(cli->tree, tctx, &io);
     1853                if (!NT_STATUS_EQUAL(status, open_funcs_dir[i].correct_status)) {
     1854                        torture_result(tctx, TORTURE_FAIL,
     1855                                "(%s) incorrect status %s should be %s "
     1856                                "(i=%d dir_exists=%d open_disp=%d)\n",
     1857                                __location__, nt_errstr(status),
     1858                                nt_errstr(open_funcs_dir[i].correct_status),
     1859                                i, (int)open_funcs_dir[i].dir_exists,
     1860                                (int)open_funcs_dir[i].open_disp);
     1861                        ret = false;
     1862                }
     1863                if (NT_STATUS_IS_OK(status) || open_funcs_dir[i].dir_exists) {
     1864                        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
     1865                        smbcli_rmdir(cli->tree, dname);
     1866                }
     1867        }
     1868
     1869done:
     1870        smbcli_deltree(cli->tree, BASEDIR);
     1871
     1872        return ret;
     1873}
     1874
     1875/**
     1876 * Test what happens when trying to open a file with directory parameters and
     1877 * vice-versa.  Also test that NTCREATEX_OPTIONS_DIRECTORY is treated as
     1878 * mandatory and FILE_ATTRIBUTE_DIRECTORY is advisory for directory
     1879 * creation/opening.
     1880 */
     1881static bool test_ntcreatexdir(struct torture_context *tctx,
     1882    struct smbcli_state *cli)
     1883{
     1884        union smb_open io;
     1885        const char *fname = BASEDIR "\\torture_ntcreatex.txt";
     1886        const char *dname = BASEDIR "\\torture_ntcreatex_dir";
     1887        NTSTATUS status;
     1888        int i;
     1889
     1890        struct {
     1891                uint32_t open_disp;
     1892                uint32_t file_attr;
     1893                uint32_t create_options;
     1894                NTSTATUS correct_status;
     1895        } open_funcs[] = {
     1896                { NTCREATEX_DISP_SUPERSEDE,     0, NTCREATEX_OPTIONS_DIRECTORY,
     1897                  NT_STATUS_INVALID_PARAMETER },
     1898                { NTCREATEX_DISP_OPEN,          0, NTCREATEX_OPTIONS_DIRECTORY,
     1899                  NT_STATUS_OBJECT_NAME_NOT_FOUND },
     1900                { NTCREATEX_DISP_CREATE,        0, NTCREATEX_OPTIONS_DIRECTORY,
     1901                  NT_STATUS_OK },
     1902                { NTCREATEX_DISP_OPEN_IF,       0, NTCREATEX_OPTIONS_DIRECTORY,
     1903                  NT_STATUS_OK },
     1904                { NTCREATEX_DISP_OVERWRITE,     0, NTCREATEX_OPTIONS_DIRECTORY,
     1905                  NT_STATUS_INVALID_PARAMETER },
     1906                { NTCREATEX_DISP_OVERWRITE_IF,  0, NTCREATEX_OPTIONS_DIRECTORY,
     1907                  NT_STATUS_INVALID_PARAMETER },
     1908                { NTCREATEX_DISP_SUPERSEDE,     FILE_ATTRIBUTE_DIRECTORY, 0,
     1909                  NT_STATUS_OK },
     1910                { NTCREATEX_DISP_OPEN,          FILE_ATTRIBUTE_DIRECTORY, 0,
     1911                  NT_STATUS_OBJECT_NAME_NOT_FOUND },
     1912                { NTCREATEX_DISP_CREATE,        FILE_ATTRIBUTE_DIRECTORY, 0,
     1913                  NT_STATUS_OK },
     1914                { NTCREATEX_DISP_OPEN_IF,       FILE_ATTRIBUTE_DIRECTORY, 0,
     1915                  NT_STATUS_OK },
     1916                { NTCREATEX_DISP_OVERWRITE,     FILE_ATTRIBUTE_DIRECTORY, 0,
     1917                  NT_STATUS_OBJECT_NAME_NOT_FOUND },
     1918                { NTCREATEX_DISP_OVERWRITE_IF,  FILE_ATTRIBUTE_DIRECTORY, 0,
     1919                  NT_STATUS_OK },
     1920
     1921        };
     1922
     1923        if (!torture_setup_dir(cli, BASEDIR)) {
     1924                return false;
     1925        }
     1926
     1927        /* setup some base params. */
     1928        io.generic.level = RAW_OPEN_NTCREATEX;
     1929        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
     1930        io.ntcreatex.in.root_fid.fnum = 0;
     1931        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     1932        io.ntcreatex.in.alloc_size = 0;
     1933        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
     1934        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     1935        io.ntcreatex.in.security_flags = 0;
     1936        io.ntcreatex.in.fname = fname;
     1937
     1938        /*
     1939         * Test the validity checking for create dispositions, which is done
     1940         * against the requested parameters rather than what's actually on
     1941         * disk.
     1942         */
     1943        for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
     1944                io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
     1945                io.ntcreatex.in.file_attr = open_funcs[i].file_attr;
     1946                io.ntcreatex.in.create_options = open_funcs[i].create_options;
     1947                status = smb_raw_open(cli->tree, tctx, &io);
     1948                if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
     1949                        torture_result(tctx, TORTURE_FAIL,
     1950                                "(%s) incorrect status %s should be %s "
     1951                                "(i=%d open_disp=%d)\n",
     1952                                __location__, nt_errstr(status),
     1953                                nt_errstr(open_funcs[i].correct_status),
     1954                                i, (int)open_funcs[i].open_disp);
     1955                        return false;
     1956                }
     1957                /* Close and delete the file. */
     1958                if (NT_STATUS_IS_OK(status)) {
     1959                        if (open_funcs[i].create_options != 0) {
     1960                                /* out attrib should be a directory. */
     1961                                torture_assert_int_equal(tctx,
     1962                                    io.ntcreatex.out.attrib,
     1963                                    FILE_ATTRIBUTE_DIRECTORY, "should have "
     1964                                    "created a directory");
     1965
     1966                                smbcli_close(cli->tree,
     1967                                    io.ntcreatex.out.file.fnum);
     1968
     1969                                /* Make sure unlink fails. */
     1970                                status = smbcli_unlink(cli->tree, fname);
     1971                                torture_assert_ntstatus_equal(tctx, status,
     1972                                    NT_STATUS_FILE_IS_A_DIRECTORY,
     1973                                    "unlink should fail for a directory");
     1974
     1975                                status = smbcli_rmdir(cli->tree, fname);
     1976                                torture_assert_ntstatus_ok(tctx, status,
     1977                                    "rmdir failed");
     1978                        } else {
     1979                                torture_assert_int_equal(tctx,
     1980                                    io.ntcreatex.out.attrib,
     1981                                    FILE_ATTRIBUTE_ARCHIVE, "should not have "
     1982                                    "created a directory");
     1983
     1984                                smbcli_close(cli->tree,
     1985                                    io.ntcreatex.out.file.fnum);
     1986
     1987                                /* Make sure rmdir fails. */
     1988                                status = smbcli_rmdir(cli->tree, fname);
     1989                                torture_assert_ntstatus_equal(tctx, status,
     1990                                    NT_STATUS_NOT_A_DIRECTORY,
     1991                                    "rmdir should fail for a file");
     1992
     1993                                status = smbcli_unlink(cli->tree, fname);
     1994                                torture_assert_ntstatus_ok(tctx, status,
     1995                                    "unlink failed");
     1996                        }
     1997                }
     1998        }
     1999
     2000        /* Create a file. */
     2001        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     2002        io.ntcreatex.in.create_options = 0;
     2003        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
     2004        status = smb_raw_open(cli->tree, tctx, &io);
     2005        torture_assert_ntstatus_ok(tctx, status, "Failed to create file.");
     2006        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
     2007
     2008        /* Try and open the file with file_attr_dir and check the error. */
     2009        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
     2010        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
     2011
     2012        status = smb_raw_open(cli->tree, tctx, &io);
     2013        torture_assert_ntstatus_ok(tctx, status, "FILE_ATTRIBUTE_DIRECTORY "
     2014            "doesn't produce a hard failure.");
     2015        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
     2016
     2017        /* Try and open file with createx_option_dir and check the error. */
     2018        io.ntcreatex.in.file_attr = 0;
     2019        io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
     2020
     2021        status = smb_raw_open(cli->tree, tctx, &io);
     2022        torture_assert_ntstatus_equal(tctx, status, NT_STATUS_NOT_A_DIRECTORY,
     2023            "NTCREATEX_OPTIONS_DIRECTORY will a file from being opened.");
     2024        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
     2025
     2026        /* Delete the file and move onto directory testing. */
     2027        smbcli_unlink(cli->tree, fname);
     2028
     2029        /* Now try some tests on a directory. */
     2030        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
     2031        io.ntcreatex.in.file_attr = 0;
     2032        io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
     2033        io.ntcreatex.in.fname = dname;
     2034
     2035        status = smb_raw_open(cli->tree, tctx, &io);
     2036        torture_assert_ntstatus_ok(tctx, status, "Failed to create dir.");
     2037
     2038        /* out attrib should be a directory. */
     2039        torture_assert_int_equal(tctx, io.ntcreatex.out.attrib,
     2040            FILE_ATTRIBUTE_DIRECTORY, "should have created a directory");
     2041
     2042        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
     2043
     2044        /* Try and open it with normal attr and check the error. */
     2045        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     2046        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
     2047
     2048        status = smb_raw_open(cli->tree, tctx, &io);
     2049        torture_assert_ntstatus_ok(tctx, status, "FILE_ATTRIBUTE_NORMAL "
     2050            "doesn't produce a hard failure.");
     2051        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
     2052
     2053        /* Try and open it with file create_options and check the error. */
     2054        io.ntcreatex.in.file_attr = 0;
     2055        io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
     2056
     2057        status = smb_raw_open(cli->tree, tctx, &io);
     2058        torture_assert_ntstatus_equal(tctx, status,
     2059            NT_STATUS_FILE_IS_A_DIRECTORY,
     2060            "NTCREATEX_OPTIONS_NON_DIRECTORY_FILE should be returned ");
     2061        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
     2062
     2063        smbcli_deltree(cli->tree, BASEDIR);
     2064
     2065        return true;
     2066}
     2067
     2068/* basic testing of all RAW_OPEN_* calls
     2069*/
     2070struct torture_suite *torture_raw_open(TALLOC_CTX *mem_ctx)
     2071{
     2072        struct torture_suite *suite = torture_suite_create(mem_ctx, "open");
     2073
     2074        torture_suite_add_1smb_test(suite, "brlocked", test_ntcreatex_brlocked);
     2075        torture_suite_add_1smb_test(suite, "open", test_open);
     2076        torture_suite_add_1smb_test(suite, "open-multi", test_raw_open_multi);
     2077        torture_suite_add_1smb_test(suite, "openx", test_openx);
     2078        torture_suite_add_1smb_test(suite, "ntcreatex", test_ntcreatex);
     2079        torture_suite_add_1smb_test(suite, "nttrans-create", test_nttrans_create);
     2080        torture_suite_add_1smb_test(suite, "t2open", test_t2open);
     2081        torture_suite_add_1smb_test(suite, "mknew", test_mknew);
     2082        torture_suite_add_1smb_test(suite, "create", test_create);
     2083        torture_suite_add_1smb_test(suite, "ctemp", test_ctemp);
     2084        torture_suite_add_1smb_test(suite, "chained-openx", test_chained);
     2085        torture_suite_add_1smb_test(suite, "chained-ntcreatex", test_chained_ntcreatex_readx);
     2086        torture_suite_add_1smb_test(suite, "no-leading-slash", test_no_leading_slash);
     2087        torture_suite_add_1smb_test(suite, "openx-over-dir", test_openx_over_dir);
     2088        torture_suite_add_1smb_test(suite, "open-for-delete", test_open_for_delete);
     2089        torture_suite_add_1smb_test(suite, "opendisp-dir", test_ntcreatex_opendisp_dir);
     2090        torture_suite_add_1smb_test(suite, "ntcreatedir", test_ntcreatexdir);
     2091
     2092        return suite;
     2093}
  • trunk/server/source4/torture/raw/openbench.c

    r414 r745  
    131131        io->in.dest_host    = state->dest_host;
    132132        io->in.dest_ports   = state->dest_ports;
    133         io->in.socket_options = lp_socket_options(state->tctx->lp_ctx);
     133        io->in.socket_options = lpcfg_socket_options(state->tctx->lp_ctx);
    134134        io->in.called_name  = state->called_name;
    135135        io->in.service      = share;
     
    137137        io->in.credentials  = cmdline_credentials;
    138138        io->in.fallback_to_anonymous = false;
    139         io->in.workgroup    = lp_workgroup(state->tctx->lp_ctx);
    140         io->in.gensec_settings = lp_gensec_settings(state->mem_ctx, state->tctx->lp_ctx);
    141         lp_smbcli_options(state->tctx->lp_ctx, &io->in.options);
    142         lp_smbcli_session_options(state->tctx->lp_ctx, &io->in.session_options);
     139        io->in.workgroup    = lpcfg_workgroup(state->tctx->lp_ctx);
     140        io->in.gensec_settings = lpcfg_gensec_settings(state->mem_ctx, state->tctx->lp_ctx);
     141        lpcfg_smbcli_options(state->tctx->lp_ctx, &io->in.options);
     142        lpcfg_smbcli_session_options(state->tctx->lp_ctx, &io->in.session_options);
    143143
    144144        /* kill off the remnants of the old connection */
     
    149149
    150150        ctx = smb_composite_connect_send(io, state->mem_ctx,
    151                                          lp_resolve_context(state->tctx->lp_ctx),
     151                                         lpcfg_resolve_context(state->tctx->lp_ctx),
    152152                                         state->ev);
    153153        if (ctx == NULL) {
     
    174174        state->open_parms.ntcreatex.level = RAW_OPEN_NTCREATEX;
    175175        state->open_parms.ntcreatex.in.flags = 0;
    176         state->open_parms.ntcreatex.in.root_fid = 0;
     176        state->open_parms.ntcreatex.in.root_fid.fnum = 0;
    177177        state->open_parms.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    178178        state->open_parms.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     
    223223
    224224        if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE) ||
    225             NT_STATUS_EQUAL(status, NT_STATUS_LOCAL_DISCONNECT)) {
     225            NT_STATUS_EQUAL(status, NT_STATUS_LOCAL_DISCONNECT) ||
     226            NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET)) {
    226227                talloc_free(state->tree);
    227228                talloc_free(state->cli);
     
    282283
    283284        if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE) ||
    284             NT_STATUS_EQUAL(status, NT_STATUS_LOCAL_DISCONNECT)) {
     285            NT_STATUS_EQUAL(status, NT_STATUS_LOCAL_DISCONNECT) ||
     286            NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET)) {
    285287                talloc_free(state->tree);
    286288                talloc_free(state->cli);
     
    316318        NTSTATUS status = smbcli_request_simple_recv(req);
    317319        if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE) ||
    318             NT_STATUS_EQUAL(status, NT_STATUS_LOCAL_DISCONNECT)) {
     320            NT_STATUS_EQUAL(status, NT_STATUS_LOCAL_DISCONNECT) ||
     321            NT_STATUS_EQUAL(status, NT_STATUS_CONNECTION_RESET)) {
    319322                talloc_free(state->tree);
    320323                state->tree = NULL;
  • trunk/server/source4/torture/raw/oplock.c

    r414 r745  
    1919
    2020#include "includes.h"
    21 #include "torture/torture.h"
    22 #include "torture/smbtorture.h"
    23 #include "librpc/gen_ndr/security.h"
    24 #include "librpc/gen_ndr/ndr_security.h"
    2521#include "libcli/raw/libcliraw.h"
    2622#include "libcli/raw/raw_proto.h"
    27 #include "libcli/security/security.h"
    2823#include "libcli/libcli.h"
    2924#include "torture/util.h"
     
    4035        }} while (0)
    4136
    42 #define CHECK_RANGE(v, min, max) do { \
    43         if ((v) < (min) || (v) > (max)) { \
    44                 torture_result(tctx, TORTURE_FAIL, "(%s): wrong value for %s got %d - should be between %d and %d\n", \
    45                                 __location__, #v, (int)v, (int)min, (int)max); \
    46                 ret = false; \
     37#define CHECK_RANGE(v, min, max) do {                                   \
     38        if ((v) < (min) || (v) > (max)) {                               \
     39                torture_warning(tctx, "(%s): wrong value for %s got "   \
     40                    "%d - should be between %d and %d\n",               \
     41                    __location__, #v, (int)v, (int)min, (int)max);      \
    4742        }} while (0)
    4843
     
    182177        struct smbcli_session_options session_options;
    183178
    184         lp_smbcli_options(tctx->lp_ctx, &options);
    185         lp_smbcli_session_options(tctx->lp_ctx, &session_options);
     179        lpcfg_smbcli_options(tctx->lp_ctx, &options);
     180        lpcfg_smbcli_session_options(tctx->lp_ctx, &session_options);
    186181
    187182        options.use_level2_oplocks = false;
     
    189184        status = smbcli_full_connection(tctx, c,
    190185                                        torture_setting_string(tctx, "host", NULL),
    191                                         lp_smb_ports(tctx->lp_ctx),
     186                                        lpcfg_smb_ports(tctx->lp_ctx),
    192187                                        torture_setting_string(tctx, "share", NULL),
    193                                         NULL, lp_socket_options(tctx->lp_ctx), cmdline_credentials,
    194                                         lp_resolve_context(tctx->lp_ctx),
     188                                        NULL, lpcfg_socket_options(tctx->lp_ctx), cmdline_credentials,
     189                                        lpcfg_resolve_context(tctx->lp_ctx),
    195190                                        tctx->ev, &options, &session_options,
    196                                         lp_iconv_convenience(tctx->lp_ctx),
    197                                         lp_gensec_settings(tctx, tctx->lp_ctx));
     191                                        lpcfg_gensec_settings(tctx, tctx->lp_ctx));
    198192        if (!NT_STATUS_IS_OK(status)) {
    199193                torture_comment(tctx, "Failed to open connection - %s\n",
     
    259253}
    260254
     255static uint8_t get_break_level1_to_none_count(struct torture_context *tctx)
     256{
     257        return torture_setting_bool(tctx, "2_step_break_to_none", false) ?
     258            2 : 1;
     259}
     260
    261261static bool test_raw_oplock_exclusive1(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
    262262{
     
    281281        */
    282282        io.generic.level = RAW_OPEN_NTCREATEX;
    283         io.ntcreatex.in.root_fid = 0;
     283        io.ntcreatex.in.root_fid.fnum = 0;
    284284        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    285285        io.ntcreatex.in.alloc_size = 0;
     
    348348        */
    349349        io.generic.level = RAW_OPEN_NTCREATEX;
    350         io.ntcreatex.in.root_fid = 0;
     350        io.ntcreatex.in.root_fid.fnum = 0;
    351351        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    352352        io.ntcreatex.in.alloc_size = 0;
     
    446446        */
    447447        io.generic.level = RAW_OPEN_NTCREATEX;
    448         io.ntcreatex.in.root_fid = 0;
     448        io.ntcreatex.in.root_fid.fnum = 0;
     449        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     450        io.ntcreatex.in.alloc_size = 0;
     451        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     452        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_WRITE;
     453        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
     454        io.ntcreatex.in.create_options = 0;
     455        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     456        io.ntcreatex.in.security_flags = 0;
     457        io.ntcreatex.in.fname = fname;
     458
     459        torture_comment(tctx, "EXCLUSIVE3: open a file with an exclusive oplock (share mode: none)\n");
     460
     461        ZERO_STRUCT(break_info);
     462        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | NTCREATEX_FLAGS_REQUEST_OPLOCK;
     463
     464        status = smb_raw_open(cli1->tree, tctx, &io);
     465        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     466        fnum = io.ntcreatex.out.file.fnum;
     467        CHECK_VAL(io.ntcreatex.out.oplock_level, EXCLUSIVE_OPLOCK_RETURN);
     468
     469        torture_comment(tctx, "setpathinfo EOF should trigger a break to none\n");
     470        ZERO_STRUCT(sfi);
     471        sfi.generic.level = RAW_SFILEINFO_END_OF_FILE_INFORMATION;
     472        sfi.generic.in.file.path = fname;
     473        sfi.end_of_file_info.in.size = 100;
     474
     475        status = smb_raw_setpathinfo(cli2->tree, &sfi);
     476
     477        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     478        torture_wait_for_oplock_break(tctx);
     479        CHECK_VAL(break_info.count, get_break_level1_to_none_count(tctx));
     480        CHECK_VAL(break_info.failures, 0);
     481        CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_NONE);
     482
     483        smbcli_close(cli1->tree, fnum);
     484
     485done:
     486        smb_raw_exit(cli1->session);
     487        smb_raw_exit(cli2->session);
     488        smbcli_deltree(cli1->tree, BASEDIR);
     489        return ret;
     490}
     491
     492static bool test_raw_oplock_exclusive4(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
     493{
     494        const char *fname = BASEDIR "\\test_exclusive4.dat";
     495        NTSTATUS status;
     496        bool ret = true;
     497        union smb_open io;
     498        uint16_t fnum=0, fnum2=0;
     499
     500        if (!torture_setup_dir(cli1, BASEDIR)) {
     501                return false;
     502        }
     503
     504        /* cleanup */
     505        smbcli_unlink(cli1->tree, fname);
     506
     507        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
     508
     509        /*
     510          base ntcreatex parms
     511        */
     512        io.generic.level = RAW_OPEN_NTCREATEX;
     513        io.ntcreatex.in.root_fid.fnum = 0;
    449514        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    450515        io.ntcreatex.in.alloc_size = 0;
     
    457522        io.ntcreatex.in.fname = fname;
    458523
    459         torture_comment(tctx, "EXCLUSIVE3: open a file with an exclusive oplock (share mode: none)\n");
    460 
    461         ZERO_STRUCT(break_info);
     524        torture_comment(tctx, "EXCLUSIVE4: open with exclusive oplock\n");
     525        ZERO_STRUCT(break_info);
     526        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
     527
    462528        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | NTCREATEX_FLAGS_REQUEST_OPLOCK;
    463 
    464529        status = smb_raw_open(cli1->tree, tctx, &io);
    465530        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     
    467532        CHECK_VAL(io.ntcreatex.out.oplock_level, EXCLUSIVE_OPLOCK_RETURN);
    468533
    469         torture_comment(tctx, "setpathinfo EOF should trigger a break to none\n");
    470         ZERO_STRUCT(sfi);
    471         sfi.generic.level = RAW_SFILEINFO_END_OF_FILE_INFORMATION;
    472         sfi.generic.in.file.path = fname;
    473         sfi.end_of_file_info.in.size = 100;
    474 
    475         status = smb_raw_setpathinfo(cli2->tree, &sfi);
    476 
    477         CHECK_STATUS(tctx, status, NT_STATUS_OK);
    478         torture_wait_for_oplock_break(tctx);
    479         CHECK_VAL(break_info.count, 1);
    480         CHECK_VAL(break_info.failures, 0);
    481         CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_NONE);
     534        ZERO_STRUCT(break_info);
     535        torture_comment(tctx, "second open with attributes only shouldn't cause oplock break\n");
     536
     537        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | NTCREATEX_FLAGS_REQUEST_OPLOCK;
     538        io.ntcreatex.in.access_mask = SEC_FILE_READ_ATTRIBUTE|SEC_FILE_WRITE_ATTRIBUTE|SEC_STD_SYNCHRONIZE;
     539        status = smb_raw_open(cli2->tree, tctx, &io);
     540        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     541        fnum2 = io.ntcreatex.out.file.fnum;
     542        CHECK_VAL(io.ntcreatex.out.oplock_level, NO_OPLOCK_RETURN);
     543        torture_wait_for_oplock_break(tctx);
     544        CHECK_VAL(break_info.count, 0);
     545        CHECK_VAL(break_info.failures, 0);
    482546
    483547        smbcli_close(cli1->tree, fnum);
     548        smbcli_close(cli2->tree, fnum2);
    484549
    485550done:
     
    490555}
    491556
    492 static bool test_raw_oplock_exclusive4(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
    493 {
    494         const char *fname = BASEDIR "\\test_exclusive4.dat";
     557static bool test_raw_oplock_exclusive5(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
     558{
     559        const char *fname = BASEDIR "\\test_exclusive5.dat";
    495560        NTSTATUS status;
    496561        bool ret = true;
     
    506571
    507572        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
     573        smbcli_oplock_handler(cli2->transport, oplock_handler_ack_to_given, cli1->tree);
    508574
    509575        /*
     
    511577        */
    512578        io.generic.level = RAW_OPEN_NTCREATEX;
    513         io.ntcreatex.in.root_fid = 0;
     579        io.ntcreatex.in.root_fid.fnum = 0;
    514580        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    515581        io.ntcreatex.in.alloc_size = 0;
     
    522588        io.ntcreatex.in.fname = fname;
    523589
    524         torture_comment(tctx, "EXCLUSIVE4: open with exclusive oplock\n");
     590        torture_comment(tctx, "EXCLUSIVE5: open with exclusive oplock\n");
    525591        ZERO_STRUCT(break_info);
    526592        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
    527593
     594
    528595        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | NTCREATEX_FLAGS_REQUEST_OPLOCK;
     596        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
     597                NTCREATEX_SHARE_ACCESS_WRITE|
     598                NTCREATEX_SHARE_ACCESS_DELETE;
    529599        status = smb_raw_open(cli1->tree, tctx, &io);
    530600        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     
    533603
    534604        ZERO_STRUCT(break_info);
    535         torture_comment(tctx, "second open with attributes only shouldn't cause oplock break\n");
     605
     606        torture_comment(tctx, "second open with attributes only and NTCREATEX_DISP_OVERWRITE_IF dispostion causes oplock break\n");
    536607
    537608        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | NTCREATEX_FLAGS_REQUEST_OPLOCK;
    538609        io.ntcreatex.in.access_mask = SEC_FILE_READ_ATTRIBUTE|SEC_FILE_WRITE_ATTRIBUTE|SEC_STD_SYNCHRONIZE;
     610        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
    539611        status = smb_raw_open(cli2->tree, tctx, &io);
    540612        CHECK_STATUS(tctx, status, NT_STATUS_OK);
    541613        fnum2 = io.ntcreatex.out.file.fnum;
    542         CHECK_VAL(io.ntcreatex.out.oplock_level, NO_OPLOCK_RETURN);
    543         torture_wait_for_oplock_break(tctx);
    544         CHECK_VAL(break_info.count, 0);
     614        CHECK_VAL(io.ntcreatex.out.oplock_level, LEVEL_II_OPLOCK_RETURN);
     615        torture_wait_for_oplock_break(tctx);
     616        CHECK_VAL(break_info.count, get_break_level1_to_none_count(tctx));
    545617        CHECK_VAL(break_info.failures, 0);
    546618
     
    555627}
    556628
    557 static bool test_raw_oplock_exclusive5(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
    558 {
    559         const char *fname = BASEDIR "\\test_exclusive5.dat";
     629static bool test_raw_oplock_exclusive6(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
     630{
     631        const char *fname1 = BASEDIR "\\test_exclusive6_1.dat";
     632        const char *fname2 = BASEDIR "\\test_exclusive6_2.dat";
    560633        NTSTATUS status;
    561634        bool ret = true;
    562635        union smb_open io;
    563         uint16_t fnum=0, fnum2=0;
     636        union smb_rename rn;
     637        uint16_t fnum=0;
     638
     639        if (!torture_setup_dir(cli1, BASEDIR)) {
     640                return false;
     641        }
     642
     643        /* cleanup */
     644        smbcli_unlink(cli1->tree, fname1);
     645        smbcli_unlink(cli1->tree, fname2);
     646
     647        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
     648
     649        /*
     650          base ntcreatex parms
     651        */
     652        io.generic.level = RAW_OPEN_NTCREATEX;
     653        io.ntcreatex.in.root_fid.fnum = 0;
     654        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     655        io.ntcreatex.in.alloc_size = 0;
     656        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     657        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
     658        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
     659        io.ntcreatex.in.create_options = 0;
     660        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     661        io.ntcreatex.in.security_flags = 0;
     662        io.ntcreatex.in.fname = fname1;
     663
     664        torture_comment(tctx, "EXCLUSIVE6: open a file with an exclusive "
     665                        "oplock (share mode: none)\n");
     666        ZERO_STRUCT(break_info);
     667        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | NTCREATEX_FLAGS_REQUEST_OPLOCK;
     668
     669        status = smb_raw_open(cli1->tree, tctx, &io);
     670        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     671        fnum = io.ntcreatex.out.file.fnum;
     672        CHECK_VAL(io.ntcreatex.out.oplock_level, EXCLUSIVE_OPLOCK_RETURN);
     673
     674        torture_comment(tctx, "rename should not generate a break but get a "
     675                        "sharing violation\n");
     676        ZERO_STRUCT(rn);
     677        rn.generic.level = RAW_RENAME_RENAME;
     678        rn.rename.in.pattern1 = fname1;
     679        rn.rename.in.pattern2 = fname2;
     680        rn.rename.in.attrib = 0;
     681
     682        torture_comment(tctx, "trying rename while first file open\n");
     683        status = smb_raw_rename(cli2->tree, &rn);
     684
     685        CHECK_STATUS(tctx, status, NT_STATUS_SHARING_VIOLATION);
     686        torture_wait_for_oplock_break(tctx);
     687        CHECK_VAL(break_info.count, 0);
     688        CHECK_VAL(break_info.failures, 0);
     689
     690        smbcli_close(cli1->tree, fnum);
     691
     692done:
     693        smb_raw_exit(cli1->session);
     694        smb_raw_exit(cli2->session);
     695        smbcli_deltree(cli1->tree, BASEDIR);
     696        return ret;
     697}
     698
     699/**
     700 * Exclusive version of batch19
     701 */
     702static bool test_raw_oplock_exclusive7(struct torture_context *tctx,
     703    struct smbcli_state *cli1, struct smbcli_state *cli2)
     704{
     705        const char *fname1 = BASEDIR "\\test_exclusiv6_1.dat";
     706        const char *fname2 = BASEDIR "\\test_exclusiv6_2.dat";
     707        const char *fname3 = BASEDIR "\\test_exclusiv6_3.dat";
     708        NTSTATUS status;
     709        bool ret = true;
     710        union smb_open io;
     711        union smb_fileinfo qfi;
     712        union smb_setfileinfo sfi;
     713        uint16_t fnum=0;
     714        uint16_t fnum2 = 0;
     715
     716        if (!torture_setup_dir(cli1, BASEDIR)) {
     717                return false;
     718        }
     719
     720        /* cleanup */
     721        smbcli_unlink(cli1->tree, fname1);
     722        smbcli_unlink(cli1->tree, fname2);
     723        smbcli_unlink(cli1->tree, fname3);
     724
     725        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given,
     726            cli1->tree);
     727
     728        /*
     729          base ntcreatex parms
     730        */
     731        io.generic.level = RAW_OPEN_NTCREATEX;
     732        io.ntcreatex.in.root_fid.fnum = 0;
     733        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     734        io.ntcreatex.in.alloc_size = 0;
     735        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     736        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
     737            NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
     738        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
     739        io.ntcreatex.in.create_options = 0;
     740        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     741        io.ntcreatex.in.security_flags = 0;
     742        io.ntcreatex.in.fname = fname1;
     743
     744        torture_comment(tctx, "open a file with an exclusive oplock (share "
     745            "mode: none)\n");
     746        ZERO_STRUCT(break_info);
     747        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
     748                NTCREATEX_FLAGS_REQUEST_OPLOCK;
     749        status = smb_raw_open(cli1->tree, tctx, &io);
     750        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     751        fnum = io.ntcreatex.out.file.fnum;
     752        CHECK_VAL(io.ntcreatex.out.oplock_level, EXCLUSIVE_OPLOCK_RETURN);
     753
     754        torture_comment(tctx, "setpathinfo rename info should trigger a break "
     755            "to none\n");
     756        ZERO_STRUCT(sfi);
     757        sfi.generic.level = RAW_SFILEINFO_RENAME_INFORMATION;
     758        sfi.generic.in.file.path = fname1;
     759        sfi.rename_information.in.overwrite     = 0;
     760        sfi.rename_information.in.root_fid      = 0;
     761        sfi.rename_information.in.new_name      = fname2+strlen(BASEDIR)+1;
     762
     763        status = smb_raw_setpathinfo(cli2->tree, &sfi);
     764        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     765
     766        torture_wait_for_oplock_break(tctx);
     767        CHECK_VAL(break_info.failures, 0);
     768
     769        if (TARGET_IS_WINXP(tctx)) {
     770                /* XP incorrectly breaks to level2. */
     771                CHECK_VAL(break_info.count, 1);
     772                CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
     773        } else {
     774                /* Exclusive oplocks should not be broken on rename. */
     775                CHECK_VAL(break_info.failures, 0);
     776                CHECK_VAL(break_info.count, 0);
     777        }
     778
     779        ZERO_STRUCT(qfi);
     780        qfi.generic.level = RAW_FILEINFO_ALL_INFORMATION;
     781        qfi.generic.in.file.fnum = fnum;
     782
     783        status = smb_raw_fileinfo(cli1->tree, tctx, &qfi);
     784        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     785        CHECK_STRMATCH(qfi.all_info.out.fname.s, fname2);
     786
     787        /* Try breaking to level2 and then see if rename breaks the level2.*/
     788        ZERO_STRUCT(break_info);
     789        io.ntcreatex.in.fname = fname2;
     790        status = smb_raw_open(cli2->tree, tctx, &io);
     791        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     792        fnum2 = io.ntcreatex.out.file.fnum;
     793        CHECK_VAL(io.ntcreatex.out.oplock_level, LEVEL_II_OPLOCK_RETURN);
     794
     795        torture_wait_for_oplock_break(tctx);
     796        CHECK_VAL(break_info.failures, 0);
     797
     798        if (TARGET_IS_WINXP(tctx)) {
     799                /* XP already broke to level2. */
     800                CHECK_VAL(break_info.failures, 0);
     801                CHECK_VAL(break_info.count, 0);
     802        } else {
     803                /* Break to level 2 expected. */
     804                CHECK_VAL(break_info.count, 1);
     805                CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
     806        }
     807
     808        ZERO_STRUCT(break_info);
     809        sfi.generic.in.file.path = fname2;
     810        sfi.rename_information.in.overwrite     = 0;
     811        sfi.rename_information.in.root_fid      = 0;
     812        sfi.rename_information.in.new_name      = fname1+strlen(BASEDIR)+1;
     813
     814        status = smb_raw_setpathinfo(cli2->tree, &sfi);
     815        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     816
     817        /* Level2 oplocks are not broken on rename. */
     818        torture_wait_for_oplock_break(tctx);
     819        CHECK_VAL(break_info.failures, 0);
     820        CHECK_VAL(break_info.count, 0);
     821
     822        /* Close and re-open file with oplock. */
     823        smbcli_close(cli1->tree, fnum);
     824        status = smb_raw_open(cli1->tree, tctx, &io);
     825        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     826        fnum = io.ntcreatex.out.file.fnum;
     827        CHECK_VAL(io.ntcreatex.out.oplock_level, EXCLUSIVE_OPLOCK_RETURN);
     828
     829        torture_comment(tctx, "setfileinfo rename info on a client's own fid "
     830            "should not trigger a break nor a violation\n");
     831        ZERO_STRUCT(break_info);
     832        ZERO_STRUCT(sfi);
     833        sfi.generic.level = RAW_SFILEINFO_RENAME_INFORMATION;
     834        sfi.generic.in.file.fnum = fnum;
     835        sfi.rename_information.in.overwrite     = 0;
     836        sfi.rename_information.in.root_fid      = 0;
     837        sfi.rename_information.in.new_name      = fname3+strlen(BASEDIR)+1;
     838
     839        status = smb_raw_setfileinfo(cli1->tree, &sfi);
     840        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     841
     842        torture_wait_for_oplock_break(tctx);
     843        if (TARGET_IS_WINXP(tctx)) {
     844                /* XP incorrectly breaks to level2. */
     845                CHECK_VAL(break_info.count, 1);
     846                CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
     847        } else {
     848                CHECK_VAL(break_info.count, 0);
     849        }
     850
     851        ZERO_STRUCT(qfi);
     852        qfi.generic.level = RAW_FILEINFO_ALL_INFORMATION;
     853        qfi.generic.in.file.fnum = fnum;
     854
     855        status = smb_raw_fileinfo(cli1->tree, tctx, &qfi);
     856        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     857        CHECK_STRMATCH(qfi.all_info.out.fname.s, fname3);
     858
     859done:
     860        smbcli_close(cli1->tree, fnum);
     861        smbcli_close(cli2->tree, fnum2);
     862
     863        smb_raw_exit(cli1->session);
     864        smb_raw_exit(cli2->session);
     865        smbcli_deltree(cli1->tree, BASEDIR);
     866        return ret;
     867}
     868
     869static bool test_raw_oplock_batch1(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
     870{
     871        const char *fname = BASEDIR "\\test_batch1.dat";
     872        NTSTATUS status;
     873        bool ret = true;
     874        union smb_open io;
     875        union smb_unlink unl;
     876        uint16_t fnum=0;
     877        char c = 0;
    564878
    565879        if (!torture_setup_dir(cli1, BASEDIR)) {
     
    571885
    572886        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
    573         smbcli_oplock_handler(cli2->transport, oplock_handler_ack_to_given, cli1->tree);
    574887
    575888        /*
     
    577890        */
    578891        io.generic.level = RAW_OPEN_NTCREATEX;
    579         io.ntcreatex.in.root_fid = 0;
     892        io.ntcreatex.in.root_fid.fnum = 0;
    580893        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    581894        io.ntcreatex.in.alloc_size = 0;
     
    588901        io.ntcreatex.in.fname = fname;
    589902
    590         torture_comment(tctx, "EXCLUSIVE5: open with exclusive oplock\n");
    591         ZERO_STRUCT(break_info);
    592         smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
    593 
    594 
    595         io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | NTCREATEX_FLAGS_REQUEST_OPLOCK;
    596         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
    597                 NTCREATEX_SHARE_ACCESS_WRITE|
    598                 NTCREATEX_SHARE_ACCESS_DELETE;
     903        /*
     904          with a batch oplock we get a break
     905        */
     906        torture_comment(tctx, "BATCH1: open with batch oplock\n");
     907        ZERO_STRUCT(break_info);
     908        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
     909                NTCREATEX_FLAGS_REQUEST_OPLOCK |
     910                NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
    599911        status = smb_raw_open(cli1->tree, tctx, &io);
    600912        CHECK_STATUS(tctx, status, NT_STATUS_OK);
    601913        fnum = io.ntcreatex.out.file.fnum;
    602         CHECK_VAL(io.ntcreatex.out.oplock_level, EXCLUSIVE_OPLOCK_RETURN);
    603 
    604         ZERO_STRUCT(break_info);
    605 
    606         torture_comment(tctx, "second open with attributes only and NTCREATEX_DISP_OVERWRITE_IF dispostion causes oplock break\n");
    607 
    608         io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | NTCREATEX_FLAGS_REQUEST_OPLOCK;
    609         io.ntcreatex.in.access_mask = SEC_FILE_READ_ATTRIBUTE|SEC_FILE_WRITE_ATTRIBUTE|SEC_STD_SYNCHRONIZE;
    610         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
    611         status = smb_raw_open(cli2->tree, tctx, &io);
    612         CHECK_STATUS(tctx, status, NT_STATUS_OK);
    613         fnum2 = io.ntcreatex.out.file.fnum;
    614         CHECK_VAL(io.ntcreatex.out.oplock_level, LEVEL_II_OPLOCK_RETURN);
     914        CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
     915
     916        torture_comment(tctx, "unlink should generate a break\n");
     917        unl.unlink.in.pattern = fname;
     918        unl.unlink.in.attrib = 0;
     919        status = smb_raw_unlink(cli2->tree, &unl);
     920        CHECK_STATUS(tctx, status, NT_STATUS_SHARING_VIOLATION);
     921
    615922        torture_wait_for_oplock_break(tctx);
    616923        CHECK_VAL(break_info.count, 1);
     924        CHECK_VAL(break_info.fnum, fnum);
     925        CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
     926        CHECK_VAL(break_info.failures, 0);
     927
     928        torture_comment(tctx, "2nd unlink should not generate a break\n");
     929        ZERO_STRUCT(break_info);
     930        status = smb_raw_unlink(cli2->tree, &unl);
     931        CHECK_STATUS(tctx, status, NT_STATUS_SHARING_VIOLATION);
     932
     933        torture_wait_for_oplock_break(tctx);
     934        CHECK_VAL(break_info.count, 0);
     935
     936        torture_comment(tctx, "writing should generate a self break to none\n");
     937        smbcli_write(cli1->tree, fnum, 0, &c, 0, 1);
     938
     939        torture_wait_for_oplock_break(tctx);
     940        torture_wait_for_oplock_break(tctx);
     941        CHECK_VAL(break_info.count, 1);
     942        CHECK_VAL(break_info.fnum, fnum);
     943        CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_NONE);
    617944        CHECK_VAL(break_info.failures, 0);
    618945
    619946        smbcli_close(cli1->tree, fnum);
    620         smbcli_close(cli2->tree, fnum2);
    621947
    622948done:
     
    627953}
    628954
    629 static bool test_raw_oplock_exclusive6(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
    630 {
    631         const char *fname1 = BASEDIR "\\test_exclusive6_1.dat";
    632         const char *fname2 = BASEDIR "\\test_exclusive6_2.dat";
    633         NTSTATUS status;
    634         bool ret = true;
    635         union smb_open io;
    636         union smb_rename rn;
    637         uint16_t fnum=0;
    638 
    639         if (!torture_setup_dir(cli1, BASEDIR)) {
    640                 return false;
    641         }
    642 
    643         /* cleanup */
    644         smbcli_unlink(cli1->tree, fname1);
    645         smbcli_unlink(cli1->tree, fname2);
    646 
    647         smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
    648 
    649         /*
    650           base ntcreatex parms
    651         */
    652         io.generic.level = RAW_OPEN_NTCREATEX;
    653         io.ntcreatex.in.root_fid = 0;
    654         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    655         io.ntcreatex.in.alloc_size = 0;
    656         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
    657         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
    658         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
    659         io.ntcreatex.in.create_options = 0;
    660         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
    661         io.ntcreatex.in.security_flags = 0;
    662         io.ntcreatex.in.fname = fname1;
    663 
    664         torture_comment(tctx, "EXCLUSIVE6: open a file with an exclusive "
    665                         "oplock (share mode: none)\n");
    666         ZERO_STRUCT(break_info);
    667         io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | NTCREATEX_FLAGS_REQUEST_OPLOCK;
    668 
    669         status = smb_raw_open(cli1->tree, tctx, &io);
    670         CHECK_STATUS(tctx, status, NT_STATUS_OK);
    671         fnum = io.ntcreatex.out.file.fnum;
    672         CHECK_VAL(io.ntcreatex.out.oplock_level, EXCLUSIVE_OPLOCK_RETURN);
    673 
    674         torture_comment(tctx, "rename should not generate a break but get a "
    675                         "sharing violation\n");
    676         ZERO_STRUCT(rn);
    677         rn.generic.level = RAW_RENAME_RENAME;
    678         rn.rename.in.pattern1 = fname1;
    679         rn.rename.in.pattern2 = fname2;
    680         rn.rename.in.attrib = 0;
    681 
    682         torture_comment(tctx, "trying rename while first file open\n");
    683         status = smb_raw_rename(cli2->tree, &rn);
    684 
    685         CHECK_STATUS(tctx, status, NT_STATUS_SHARING_VIOLATION);
    686         torture_wait_for_oplock_break(tctx);
    687         CHECK_VAL(break_info.count, 0);
    688         CHECK_VAL(break_info.failures, 0);
    689 
    690         smbcli_close(cli1->tree, fnum);
    691 
    692 done:
    693         smb_raw_exit(cli1->session);
    694         smb_raw_exit(cli2->session);
    695         smbcli_deltree(cli1->tree, BASEDIR);
    696         return ret;
    697 }
    698 
    699 static bool test_raw_oplock_batch1(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
    700 {
    701         const char *fname = BASEDIR "\\test_batch1.dat";
     955static bool test_raw_oplock_batch2(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
     956{
     957        const char *fname = BASEDIR "\\test_batch2.dat";
    702958        NTSTATUS status;
    703959        bool ret = true;
     
    720976        */
    721977        io.generic.level = RAW_OPEN_NTCREATEX;
    722         io.ntcreatex.in.root_fid = 0;
     978        io.ntcreatex.in.root_fid.fnum = 0;
    723979        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    724980        io.ntcreatex.in.alloc_size = 0;
     
    731987        io.ntcreatex.in.fname = fname;
    732988
    733         /*
    734           with a batch oplock we get a break
    735         */
    736         torture_comment(tctx, "BATCH1: open with batch oplock\n");
     989        torture_comment(tctx, "BATCH2: open with batch oplock\n");
    737990        ZERO_STRUCT(break_info);
    738991        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
     
    744997        CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
    745998
    746         torture_comment(tctx, "unlink should generate a break\n");
     999        torture_comment(tctx, "unlink should generate a break, which we ack as break to none\n");
     1000        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_none, cli1->tree);
    7471001        unl.unlink.in.pattern = fname;
    7481002        unl.unlink.in.attrib = 0;
     
    7641018        CHECK_VAL(break_info.count, 0);
    7651019
    766         torture_comment(tctx, "writing should generate a self break to none\n");
     1020        torture_comment(tctx, "writing should not generate a break\n");
    7671021        smbcli_write(cli1->tree, fnum, 0, &c, 0, 1);
    7681022
    7691023        torture_wait_for_oplock_break(tctx);
    770         torture_wait_for_oplock_break(tctx);
    771         CHECK_VAL(break_info.count, 1);
    772         CHECK_VAL(break_info.fnum, fnum);
    773         CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_NONE);
    774         CHECK_VAL(break_info.failures, 0);
     1024        CHECK_VAL(break_info.count, 0);
    7751025
    7761026        smbcli_close(cli1->tree, fnum);
     
    7831033}
    7841034
    785 static bool test_raw_oplock_batch2(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
    786 {
    787         const char *fname = BASEDIR "\\test_batch2.dat";
     1035static bool test_raw_oplock_batch3(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
     1036{
     1037        const char *fname = BASEDIR "\\test_batch3.dat";
    7881038        NTSTATUS status;
    7891039        bool ret = true;
     
    7911041        union smb_unlink unl;
    7921042        uint16_t fnum=0;
    793         char c = 0;
    7941043
    7951044        if (!torture_setup_dir(cli1, BASEDIR)) {
     
    8061055        */
    8071056        io.generic.level = RAW_OPEN_NTCREATEX;
    808         io.ntcreatex.in.root_fid = 0;
     1057        io.ntcreatex.in.root_fid.fnum = 0;
    8091058        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    8101059        io.ntcreatex.in.alloc_size = 0;
     
    8171066        io.ntcreatex.in.fname = fname;
    8181067
    819         torture_comment(tctx, "BATCH2: open with batch oplock\n");
    820         ZERO_STRUCT(break_info);
     1068        torture_comment(tctx, "BATCH3: if we close on break then the unlink can succeed\n");
     1069        ZERO_STRUCT(break_info);
     1070        smbcli_oplock_handler(cli1->transport, oplock_handler_close, cli1->tree);
    8211071        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
    8221072                NTCREATEX_FLAGS_REQUEST_OPLOCK |
     
    8271077        CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
    8281078
    829         torture_comment(tctx, "unlink should generate a break, which we ack as break to none\n");
    830         smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_none, cli1->tree);
    8311079        unl.unlink.in.pattern = fname;
    8321080        unl.unlink.in.attrib = 0;
     1081        ZERO_STRUCT(break_info);
    8331082        status = smb_raw_unlink(cli2->tree, &unl);
    834         CHECK_STATUS(tctx, status, NT_STATUS_SHARING_VIOLATION);
     1083        CHECK_STATUS(tctx, status, NT_STATUS_OK);
    8351084
    8361085        torture_wait_for_oplock_break(tctx);
    8371086        CHECK_VAL(break_info.count, 1);
    8381087        CHECK_VAL(break_info.fnum, fnum);
    839         CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
    840         CHECK_VAL(break_info.failures, 0);
    841 
    842         torture_comment(tctx, "2nd unlink should not generate a break\n");
    843         ZERO_STRUCT(break_info);
    844         status = smb_raw_unlink(cli2->tree, &unl);
    845         CHECK_STATUS(tctx, status, NT_STATUS_SHARING_VIOLATION);
    846 
    847         torture_wait_for_oplock_break(tctx);
    848         CHECK_VAL(break_info.count, 0);
    849 
    850         torture_comment(tctx, "writing should not generate a break\n");
    851         smbcli_write(cli1->tree, fnum, 0, &c, 0, 1);
    852 
    853         torture_wait_for_oplock_break(tctx);
    854         CHECK_VAL(break_info.count, 0);
     1088        CHECK_VAL(break_info.level, 1);
     1089        CHECK_VAL(break_info.failures, 0);
    8551090
    8561091        smbcli_close(cli1->tree, fnum);
     
    8631098}
    8641099
    865 static bool test_raw_oplock_batch3(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
    866 {
    867         const char *fname = BASEDIR "\\test_batch3.dat";
     1100static bool test_raw_oplock_batch4(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
     1101{
     1102        const char *fname = BASEDIR "\\test_batch4.dat";
    8681103        NTSTATUS status;
    8691104        bool ret = true;
    8701105        union smb_open io;
    871         union smb_unlink unl;
     1106        union smb_read rd;
    8721107        uint16_t fnum=0;
    8731108
     
    8851120        */
    8861121        io.generic.level = RAW_OPEN_NTCREATEX;
    887         io.ntcreatex.in.root_fid = 0;
     1122        io.ntcreatex.in.root_fid.fnum = 0;
    8881123        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    8891124        io.ntcreatex.in.alloc_size = 0;
     
    8961131        io.ntcreatex.in.fname = fname;
    8971132
    898         torture_comment(tctx, "BATCH3: if we close on break then the unlink can succeed\n");
    899         ZERO_STRUCT(break_info);
    900         smbcli_oplock_handler(cli1->transport, oplock_handler_close, cli1->tree);
     1133        torture_comment(tctx, "BATCH4: a self read should not cause a break\n");
     1134        ZERO_STRUCT(break_info);
     1135        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
     1136
    9011137        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
    9021138                NTCREATEX_FLAGS_REQUEST_OPLOCK |
     
    9071143        CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
    9081144
    909         unl.unlink.in.pattern = fname;
    910         unl.unlink.in.attrib = 0;
    911         ZERO_STRUCT(break_info);
    912         status = smb_raw_unlink(cli2->tree, &unl);
    913         CHECK_STATUS(tctx, status, NT_STATUS_OK);
    914 
    915         torture_wait_for_oplock_break(tctx);
    916         CHECK_VAL(break_info.count, 1);
    917         CHECK_VAL(break_info.fnum, fnum);
    918         CHECK_VAL(break_info.level, 1);
     1145        rd.readx.level = RAW_READ_READX;
     1146        rd.readx.in.file.fnum = fnum;
     1147        rd.readx.in.mincnt = 1;
     1148        rd.readx.in.maxcnt = 1;
     1149        rd.readx.in.offset = 0;
     1150        rd.readx.in.remaining = 0;
     1151        rd.readx.in.read_for_execute = false;
     1152        status = smb_raw_read(cli1->tree, &rd);
     1153        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     1154        torture_wait_for_oplock_break(tctx);
     1155        CHECK_VAL(break_info.count, 0);
    9191156        CHECK_VAL(break_info.failures, 0);
    9201157
     
    9281165}
    9291166
    930 static bool test_raw_oplock_batch4(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
    931 {
    932         const char *fname = BASEDIR "\\test_batch4.dat";
     1167static bool test_raw_oplock_batch5(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
     1168{
     1169        const char *fname = BASEDIR "\\test_batch5.dat";
    9331170        NTSTATUS status;
    9341171        bool ret = true;
    9351172        union smb_open io;
    936         union smb_read rd;
    9371173        uint16_t fnum=0;
    9381174
     
    9501186        */
    9511187        io.generic.level = RAW_OPEN_NTCREATEX;
    952         io.ntcreatex.in.root_fid = 0;
     1188        io.ntcreatex.in.root_fid.fnum = 0;
    9531189        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    9541190        io.ntcreatex.in.alloc_size = 0;
     
    9611197        io.ntcreatex.in.fname = fname;
    9621198
    963         torture_comment(tctx, "BATCH4: a self read should not cause a break\n");
     1199        torture_comment(tctx, "BATCH5: a 2nd open should give a break\n");
    9641200        ZERO_STRUCT(break_info);
    9651201        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
     
    9731209        CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
    9741210
    975         rd.read.level = RAW_READ_READ;
    976         rd.read.in.file.fnum = fnum;
    977         rd.read.in.count = 1;
    978         rd.read.in.offset = 0;
    979         rd.read.in.remaining = 0;
    980         status = smb_raw_read(cli1->tree, &rd);
    981         CHECK_STATUS(tctx, status, NT_STATUS_OK);
    982         torture_wait_for_oplock_break(tctx);
    983         CHECK_VAL(break_info.count, 0);
     1211        ZERO_STRUCT(break_info);
     1212
     1213        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
     1214        status = smb_raw_open(cli2->tree, tctx, &io);
     1215        CHECK_STATUS(tctx, status, NT_STATUS_SHARING_VIOLATION);
     1216
     1217        torture_wait_for_oplock_break(tctx);
     1218        CHECK_VAL(break_info.count, 1);
     1219        CHECK_VAL(break_info.fnum, fnum);
     1220        CHECK_VAL(break_info.level, 1);
    9841221        CHECK_VAL(break_info.failures, 0);
    9851222
     
    9931230}
    9941231
    995 static bool test_raw_oplock_batch5(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
    996 {
    997         const char *fname = BASEDIR "\\test_batch5.dat";
     1232static bool test_raw_oplock_batch6(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
     1233{
     1234        const char *fname = BASEDIR "\\test_batch6.dat";
    9981235        NTSTATUS status;
    9991236        bool ret = true;
    10001237        union smb_open io;
    1001         uint16_t fnum=0;
     1238        uint16_t fnum=0, fnum2=0;
     1239        char c = 0;
    10021240
    10031241        if (!torture_setup_dir(cli1, BASEDIR)) {
     
    10091247
    10101248        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
     1249        smbcli_oplock_handler(cli2->transport, oplock_handler_ack_to_given, cli2->tree);
    10111250
    10121251        /*
     
    10141253        */
    10151254        io.generic.level = RAW_OPEN_NTCREATEX;
    1016         io.ntcreatex.in.root_fid = 0;
     1255        io.ntcreatex.in.root_fid.fnum = 0;
    10171256        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    10181257        io.ntcreatex.in.alloc_size = 0;
     
    10251264        io.ntcreatex.in.fname = fname;
    10261265
    1027         torture_comment(tctx, "BATCH5: a 2nd open should give a break\n");
    1028         ZERO_STRUCT(break_info);
    1029         smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
    1030 
     1266        torture_comment(tctx, "BATCH6: a 2nd open should give a break to level II if the first open allowed shared read\n");
     1267        ZERO_STRUCT(break_info);
     1268
     1269        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_READ | SEC_RIGHTS_FILE_WRITE;
     1270        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
    10311271        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
    10321272                NTCREATEX_FLAGS_REQUEST_OPLOCK |
     
    10391279        ZERO_STRUCT(break_info);
    10401280
    1041         io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
    10421281        status = smb_raw_open(cli2->tree, tctx, &io);
    1043         CHECK_STATUS(tctx, status, NT_STATUS_SHARING_VIOLATION);
    1044 
    1045         torture_wait_for_oplock_break(tctx);
     1282        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     1283        fnum2 = io.ntcreatex.out.file.fnum;
     1284        CHECK_VAL(io.ntcreatex.out.oplock_level, LEVEL_II_OPLOCK_RETURN);
     1285
     1286        //torture_wait_for_oplock_break(tctx);
    10461287        CHECK_VAL(break_info.count, 1);
    10471288        CHECK_VAL(break_info.fnum, fnum);
    10481289        CHECK_VAL(break_info.level, 1);
    10491290        CHECK_VAL(break_info.failures, 0);
     1291        ZERO_STRUCT(break_info);
     1292
     1293        torture_comment(tctx, "write should trigger a break to none on both\n");
     1294        smbcli_write(cli1->tree, fnum, 0, &c, 0, 1);
     1295
     1296        /* We expect two breaks */
     1297        torture_wait_for_oplock_break(tctx);
     1298        torture_wait_for_oplock_break(tctx);
     1299
     1300        CHECK_VAL(break_info.count, 2);
     1301        CHECK_VAL(break_info.level, 0);
     1302        CHECK_VAL(break_info.failures, 0);
    10501303
    10511304        smbcli_close(cli1->tree, fnum);
     1305        smbcli_close(cli2->tree, fnum2);
    10521306
    10531307done:
     
    10581312}
    10591313
    1060 static bool test_raw_oplock_batch6(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
    1061 {
    1062         const char *fname = BASEDIR "\\test_batch6.dat";
     1314static bool test_raw_oplock_batch7(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
     1315{
     1316        const char *fname = BASEDIR "\\test_batch7.dat";
    10631317        NTSTATUS status;
    10641318        bool ret = true;
    10651319        union smb_open io;
    10661320        uint16_t fnum=0, fnum2=0;
    1067         char c = 0;
    10681321
    10691322        if (!torture_setup_dir(cli1, BASEDIR)) {
     
    10751328
    10761329        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
    1077         smbcli_oplock_handler(cli2->transport, oplock_handler_ack_to_given, cli2->tree);
    10781330
    10791331        /*
     
    10811333        */
    10821334        io.generic.level = RAW_OPEN_NTCREATEX;
    1083         io.ntcreatex.in.root_fid = 0;
     1335        io.ntcreatex.in.root_fid.fnum = 0;
    10841336        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    10851337        io.ntcreatex.in.alloc_size = 0;
     
    10921344        io.ntcreatex.in.fname = fname;
    10931345
    1094         torture_comment(tctx, "BATCH6: a 2nd open should give a break to level II if the first open allowed shared read\n");
    1095         ZERO_STRUCT(break_info);
    1096 
    1097         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_READ | SEC_RIGHTS_FILE_WRITE;
    1098         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
     1346        torture_comment(tctx, "BATCH7: a 2nd open should get an oplock when we close instead of ack\n");
     1347        ZERO_STRUCT(break_info);
     1348        smbcli_oplock_handler(cli1->transport, oplock_handler_close, cli1->tree);
     1349
     1350        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     1351        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
    10991352        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
    11001353                NTCREATEX_FLAGS_REQUEST_OPLOCK |
     
    11021355        status = smb_raw_open(cli1->tree, tctx, &io);
    11031356        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     1357        fnum2 = io.ntcreatex.out.file.fnum;
     1358        CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
     1359
     1360        ZERO_STRUCT(break_info);
     1361
     1362        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
     1363                NTCREATEX_FLAGS_REQUEST_OPLOCK |
     1364                NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
     1365        status = smb_raw_open(cli2->tree, tctx, &io);
     1366        CHECK_STATUS(tctx, status, NT_STATUS_OK);
    11041367        fnum = io.ntcreatex.out.file.fnum;
    11051368        CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
    11061369
    1107         ZERO_STRUCT(break_info);
    1108 
    1109         status = smb_raw_open(cli2->tree, tctx, &io);
    1110         CHECK_STATUS(tctx, status, NT_STATUS_OK);
    1111         fnum2 = io.ntcreatex.out.file.fnum;
    1112         CHECK_VAL(io.ntcreatex.out.oplock_level, LEVEL_II_OPLOCK_RETURN);
    1113 
    1114         //torture_wait_for_oplock_break(tctx);
     1370        torture_wait_for_oplock_break(tctx);
    11151371        CHECK_VAL(break_info.count, 1);
    1116         CHECK_VAL(break_info.fnum, fnum);
     1372        CHECK_VAL(break_info.fnum, fnum2);
    11171373        CHECK_VAL(break_info.level, 1);
    11181374        CHECK_VAL(break_info.failures, 0);
    1119         ZERO_STRUCT(break_info);
    1120 
    1121         torture_comment(tctx, "write should trigger a break to none on both\n");
    1122         smbcli_write(cli1->tree, fnum, 0, &c, 0, 1);
    1123 
    1124         /* We expect two breaks */
    1125         torture_wait_for_oplock_break(tctx);
    1126         torture_wait_for_oplock_break(tctx);
    1127 
    1128         CHECK_VAL(break_info.count, 2);
    1129         CHECK_VAL(break_info.level, 0);
    1130         CHECK_VAL(break_info.failures, 0);
    1131 
    1132         smbcli_close(cli1->tree, fnum);
    1133         smbcli_close(cli2->tree, fnum2);
     1375
     1376        smbcli_close(cli2->tree, fnum);
    11341377
    11351378done:
     
    11401383}
    11411384
    1142 static bool test_raw_oplock_batch7(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
    1143 {
    1144         const char *fname = BASEDIR "\\test_batch7.dat";
     1385static bool test_raw_oplock_batch8(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
     1386{
     1387        const char *fname = BASEDIR "\\test_batch8.dat";
    11451388        NTSTATUS status;
    11461389        bool ret = true;
     
    11611404        */
    11621405        io.generic.level = RAW_OPEN_NTCREATEX;
    1163         io.ntcreatex.in.root_fid = 0;
     1406        io.ntcreatex.in.root_fid.fnum = 0;
    11641407        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    11651408        io.ntcreatex.in.alloc_size = 0;
     
    11721415        io.ntcreatex.in.fname = fname;
    11731416
    1174         torture_comment(tctx, "BATCH7: a 2nd open should get an oplock when we close instead of ack\n");
    1175         ZERO_STRUCT(break_info);
    1176         smbcli_oplock_handler(cli1->transport, oplock_handler_close, cli1->tree);
    1177 
    1178         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    1179         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
     1417        torture_comment(tctx, "BATCH8: open with batch oplock\n");
     1418        ZERO_STRUCT(break_info);
     1419        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
     1420
    11801421        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
    11811422                NTCREATEX_FLAGS_REQUEST_OPLOCK |
     
    11831424        status = smb_raw_open(cli1->tree, tctx, &io);
    11841425        CHECK_STATUS(tctx, status, NT_STATUS_OK);
    1185         fnum2 = io.ntcreatex.out.file.fnum;
     1426        fnum = io.ntcreatex.out.file.fnum;
    11861427        CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
    11871428
    11881429        ZERO_STRUCT(break_info);
     1430        torture_comment(tctx, "second open with attributes only shouldn't cause oplock break\n");
    11891431
    11901432        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
    11911433                NTCREATEX_FLAGS_REQUEST_OPLOCK |
    11921434                NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
     1435        io.ntcreatex.in.access_mask = SEC_FILE_READ_ATTRIBUTE|SEC_FILE_WRITE_ATTRIBUTE|SEC_STD_SYNCHRONIZE;
    11931436        status = smb_raw_open(cli2->tree, tctx, &io);
    11941437        CHECK_STATUS(tctx, status, NT_STATUS_OK);
    1195         fnum = io.ntcreatex.out.file.fnum;
    1196         CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
    1197 
    1198         torture_wait_for_oplock_break(tctx);
    1199         CHECK_VAL(break_info.count, 1);
    1200         CHECK_VAL(break_info.fnum, fnum2);
    1201         CHECK_VAL(break_info.level, 1);
    1202         CHECK_VAL(break_info.failures, 0);
    1203 
    1204         smbcli_close(cli2->tree, fnum);
     1438        fnum2 = io.ntcreatex.out.file.fnum;
     1439        CHECK_VAL(io.ntcreatex.out.oplock_level, NO_OPLOCK_RETURN);
     1440        torture_wait_for_oplock_break(tctx);
     1441        CHECK_VAL(break_info.count, 0);
     1442        CHECK_VAL(break_info.failures, 0);
     1443
     1444        smbcli_close(cli1->tree, fnum);
     1445        smbcli_close(cli2->tree, fnum2);
    12051446
    12061447done:
     
    12111452}
    12121453
    1213 static bool test_raw_oplock_batch8(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
    1214 {
    1215         const char *fname = BASEDIR "\\test_batch8.dat";
     1454static bool test_raw_oplock_batch9(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
     1455{
     1456        const char *fname = BASEDIR "\\test_batch9.dat";
    12161457        NTSTATUS status;
    12171458        bool ret = true;
    12181459        union smb_open io;
    12191460        uint16_t fnum=0, fnum2=0;
     1461        char c = 0;
    12201462
    12211463        if (!torture_setup_dir(cli1, BASEDIR)) {
     
    12321474        */
    12331475        io.generic.level = RAW_OPEN_NTCREATEX;
    1234         io.ntcreatex.in.root_fid = 0;
     1476        io.ntcreatex.in.root_fid.fnum = 0;
    12351477        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    12361478        io.ntcreatex.in.alloc_size = 0;
     
    12431485        io.ntcreatex.in.fname = fname;
    12441486
    1245         torture_comment(tctx, "BATCH8: open with batch oplock\n");
    1246         ZERO_STRUCT(break_info);
    1247         smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
    1248 
    1249         io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
    1250                 NTCREATEX_FLAGS_REQUEST_OPLOCK |
    1251                 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
    1252         status = smb_raw_open(cli1->tree, tctx, &io);
    1253         CHECK_STATUS(tctx, status, NT_STATUS_OK);
    1254         fnum = io.ntcreatex.out.file.fnum;
    1255         CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
    1256 
    1257         ZERO_STRUCT(break_info);
    1258         torture_comment(tctx, "second open with attributes only shouldn't cause oplock break\n");
     1487        torture_comment(tctx, "BATCH9: open with attributes only can create file\n");
    12591488
    12601489        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
     
    12621491                NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
    12631492        io.ntcreatex.in.access_mask = SEC_FILE_READ_ATTRIBUTE|SEC_FILE_WRITE_ATTRIBUTE|SEC_STD_SYNCHRONIZE;
     1493        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
     1494        status = smb_raw_open(cli1->tree, tctx, &io);
     1495        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     1496        fnum = io.ntcreatex.out.file.fnum;
     1497        CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
     1498
     1499        torture_comment(tctx, "Subsequent normal open should break oplock on attribute only open to level II\n");
     1500
     1501        ZERO_STRUCT(break_info);
     1502        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
     1503
     1504        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
     1505                NTCREATEX_FLAGS_REQUEST_OPLOCK |
     1506                NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
     1507        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     1508        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
    12641509        status = smb_raw_open(cli2->tree, tctx, &io);
    12651510        CHECK_STATUS(tctx, status, NT_STATUS_OK);
    12661511        fnum2 = io.ntcreatex.out.file.fnum;
    1267         CHECK_VAL(io.ntcreatex.out.oplock_level, NO_OPLOCK_RETURN);
     1512        torture_wait_for_oplock_break(tctx);
     1513        CHECK_VAL(break_info.count, 1);
     1514        CHECK_VAL(break_info.fnum, fnum);
     1515        CHECK_VAL(break_info.failures, 0);
     1516        CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
     1517        CHECK_VAL(io.ntcreatex.out.oplock_level, LEVEL_II_OPLOCK_RETURN);
     1518        smbcli_close(cli2->tree, fnum2);
     1519
     1520        torture_comment(tctx, "third oplocked open should grant level2 without break\n");
     1521        ZERO_STRUCT(break_info);
     1522        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
     1523        smbcli_oplock_handler(cli2->transport, oplock_handler_ack_to_given, cli2->tree);
     1524        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
     1525                NTCREATEX_FLAGS_REQUEST_OPLOCK |
     1526                NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
     1527        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     1528        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
     1529        status = smb_raw_open(cli2->tree, tctx, &io);
     1530        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     1531        fnum2 = io.ntcreatex.out.file.fnum;
    12681532        torture_wait_for_oplock_break(tctx);
    12691533        CHECK_VAL(break_info.count, 0);
     1534        CHECK_VAL(break_info.failures, 0);
     1535        CHECK_VAL(io.ntcreatex.out.oplock_level, LEVEL_II_OPLOCK_RETURN);
     1536
     1537        ZERO_STRUCT(break_info);
     1538
     1539        torture_comment(tctx, "write should trigger a break to none on both\n");
     1540        smbcli_write(cli2->tree, fnum2, 0, &c, 0, 1);
     1541
     1542        /* We expect two breaks */
     1543        torture_wait_for_oplock_break(tctx);
     1544        torture_wait_for_oplock_break(tctx);
     1545
     1546        CHECK_VAL(break_info.count, 2);
     1547        CHECK_VAL(break_info.level, 0);
    12701548        CHECK_VAL(break_info.failures, 0);
    12711549
     
    12801558}
    12811559
    1282 static bool test_raw_oplock_batch9(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
    1283 {
    1284         const char *fname = BASEDIR "\\test_batch9.dat";
    1285         NTSTATUS status;
    1286         bool ret = true;
    1287         union smb_open io;
    1288         uint16_t fnum=0, fnum2=0;
    1289         char c = 0;
    1290 
    1291         if (!torture_setup_dir(cli1, BASEDIR)) {
    1292                 return false;
    1293         }
    1294 
    1295         /* cleanup */
    1296         smbcli_unlink(cli1->tree, fname);
    1297 
    1298         smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
    1299 
    1300         /*
    1301           base ntcreatex parms
    1302         */
    1303         io.generic.level = RAW_OPEN_NTCREATEX;
    1304         io.ntcreatex.in.root_fid = 0;
    1305         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    1306         io.ntcreatex.in.alloc_size = 0;
    1307         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
    1308         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
    1309         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
    1310         io.ntcreatex.in.create_options = 0;
    1311         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
    1312         io.ntcreatex.in.security_flags = 0;
    1313         io.ntcreatex.in.fname = fname;
    1314 
    1315         torture_comment(tctx, "BATCH9: open with attributes only can create file\n");
    1316 
    1317         io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
    1318                 NTCREATEX_FLAGS_REQUEST_OPLOCK |
    1319                 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
    1320         io.ntcreatex.in.access_mask = SEC_FILE_READ_ATTRIBUTE|SEC_FILE_WRITE_ATTRIBUTE|SEC_STD_SYNCHRONIZE;
    1321         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
    1322         status = smb_raw_open(cli1->tree, tctx, &io);
    1323         CHECK_STATUS(tctx, status, NT_STATUS_OK);
    1324         fnum = io.ntcreatex.out.file.fnum;
    1325         CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
    1326 
    1327         torture_comment(tctx, "Subsequent normal open should break oplock on attribute only open to level II\n");
    1328 
    1329         ZERO_STRUCT(break_info);
    1330         smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
    1331 
    1332         io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
    1333                 NTCREATEX_FLAGS_REQUEST_OPLOCK |
    1334                 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
    1335         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    1336         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
    1337         status = smb_raw_open(cli2->tree, tctx, &io);
    1338         CHECK_STATUS(tctx, status, NT_STATUS_OK);
    1339         fnum2 = io.ntcreatex.out.file.fnum;
    1340         torture_wait_for_oplock_break(tctx);
    1341         CHECK_VAL(break_info.count, 1);
    1342         CHECK_VAL(break_info.fnum, fnum);
    1343         CHECK_VAL(break_info.failures, 0);
    1344         CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
    1345         CHECK_VAL(io.ntcreatex.out.oplock_level, LEVEL_II_OPLOCK_RETURN);
    1346         smbcli_close(cli2->tree, fnum2);
    1347 
    1348         torture_comment(tctx, "third oplocked open should grant level2 without break\n");
    1349         ZERO_STRUCT(break_info);
    1350         smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
    1351         smbcli_oplock_handler(cli2->transport, oplock_handler_ack_to_given, cli2->tree);
    1352         io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
    1353                 NTCREATEX_FLAGS_REQUEST_OPLOCK |
    1354                 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
    1355         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    1356         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
    1357         status = smb_raw_open(cli2->tree, tctx, &io);
    1358         CHECK_STATUS(tctx, status, NT_STATUS_OK);
    1359         fnum2 = io.ntcreatex.out.file.fnum;
    1360         torture_wait_for_oplock_break(tctx);
    1361         CHECK_VAL(break_info.count, 0);
    1362         CHECK_VAL(break_info.failures, 0);
    1363         CHECK_VAL(io.ntcreatex.out.oplock_level, LEVEL_II_OPLOCK_RETURN);
    1364 
    1365         ZERO_STRUCT(break_info);
    1366 
    1367         torture_comment(tctx, "write should trigger a break to none on both\n");
    1368         smbcli_write(cli2->tree, fnum2, 0, &c, 0, 1);
    1369 
    1370         /* We expect two breaks */
    1371         torture_wait_for_oplock_break(tctx);
    1372         torture_wait_for_oplock_break(tctx);
    1373 
    1374         CHECK_VAL(break_info.count, 2);
    1375         CHECK_VAL(break_info.level, 0);
    1376         CHECK_VAL(break_info.failures, 0);
    1377 
    1378         smbcli_close(cli1->tree, fnum);
    1379         smbcli_close(cli2->tree, fnum2);
    1380 
    1381 done:
    1382         smb_raw_exit(cli1->session);
    1383         smb_raw_exit(cli2->session);
    1384         smbcli_deltree(cli1->tree, BASEDIR);
    1385         return ret;
    1386 }
    1387 
    13881560static bool test_raw_oplock_batch10(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
    13891561{
     
    14071579        */
    14081580        io.generic.level = RAW_OPEN_NTCREATEX;
    1409         io.ntcreatex.in.root_fid = 0;
     1581        io.ntcreatex.in.root_fid.fnum = 0;
    14101582        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    14111583        io.ntcreatex.in.alloc_size = 0;
     
    15031675        */
    15041676        io.generic.level = RAW_OPEN_NTCREATEX;
    1505         io.ntcreatex.in.root_fid = 0;
     1677        io.ntcreatex.in.root_fid.fnum = 0;
     1678        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     1679        io.ntcreatex.in.alloc_size = 0;
     1680        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     1681        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_WRITE;
     1682        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
     1683        io.ntcreatex.in.create_options = 0;
     1684        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     1685        io.ntcreatex.in.security_flags = 0;
     1686        io.ntcreatex.in.fname = fname;
     1687
     1688        /* Test if a set-eof on pathname breaks an exclusive oplock. */
     1689        torture_comment(tctx, "BATCH11: Test if setpathinfo set EOF breaks oplocks.\n");
     1690
     1691        ZERO_STRUCT(break_info);
     1692
     1693        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
     1694                NTCREATEX_FLAGS_REQUEST_OPLOCK |
     1695                NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
     1696        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     1697        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
     1698                NTCREATEX_SHARE_ACCESS_WRITE|
     1699                NTCREATEX_SHARE_ACCESS_DELETE;
     1700        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
     1701        status = smb_raw_open(cli1->tree, tctx, &io);
     1702        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     1703        fnum = io.ntcreatex.out.file.fnum;
     1704        torture_wait_for_oplock_break(tctx);
     1705        CHECK_VAL(break_info.count, 0);
     1706        CHECK_VAL(break_info.failures, 0);
     1707        CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
     1708
     1709        ZERO_STRUCT(sfi);
     1710        sfi.generic.level = RAW_SFILEINFO_END_OF_FILE_INFORMATION;
     1711        sfi.generic.in.file.path = fname;
     1712        sfi.end_of_file_info.in.size = 100;
     1713
     1714        status = smb_raw_setpathinfo(cli2->tree, &sfi);
     1715        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     1716
     1717        torture_wait_for_oplock_break(tctx);
     1718        CHECK_VAL(break_info.count, get_break_level1_to_none_count(tctx));
     1719        CHECK_VAL(break_info.failures, 0);
     1720        CHECK_VAL(break_info.level, 0);
     1721
     1722        smbcli_close(cli1->tree, fnum);
     1723
     1724done:
     1725        smb_raw_exit(cli1->session);
     1726        smb_raw_exit(cli2->session);
     1727        smbcli_deltree(cli1->tree, BASEDIR);
     1728        return ret;
     1729}
     1730
     1731static bool test_raw_oplock_batch12(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
     1732{
     1733        const char *fname = BASEDIR "\\test_batch12.dat";
     1734        NTSTATUS status;
     1735        bool ret = true;
     1736        union smb_open io;
     1737        union smb_setfileinfo sfi;
     1738        uint16_t fnum=0;
     1739
     1740        if (!torture_setup_dir(cli1, BASEDIR)) {
     1741                return false;
     1742        }
     1743
     1744        /* cleanup */
     1745        smbcli_unlink(cli1->tree, fname);
     1746
     1747        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
     1748
     1749        /*
     1750          base ntcreatex parms
     1751        */
     1752        io.generic.level = RAW_OPEN_NTCREATEX;
     1753        io.ntcreatex.in.root_fid.fnum = 0;
    15061754        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    15071755        io.ntcreatex.in.alloc_size = 0;
     
    15141762        io.ntcreatex.in.fname = fname;
    15151763
    1516         /* Test if a set-eof on pathname breaks an exclusive oplock. */
    1517         torture_comment(tctx, "BATCH11: Test if setpathinfo set EOF breaks oplocks.\n");
    1518 
    1519         ZERO_STRUCT(break_info);
     1764        /* Test if a set-allocation size on pathname breaks an exclusive oplock. */
     1765        torture_comment(tctx, "BATCH12: Test if setpathinfo allocation size breaks oplocks.\n");
     1766
     1767        ZERO_STRUCT(break_info);
     1768        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
    15201769
    15211770        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
     
    15361785
    15371786        ZERO_STRUCT(sfi);
    1538         sfi.generic.level = RAW_SFILEINFO_END_OF_FILE_INFORMATION;
     1787        sfi.generic.level = SMB_SFILEINFO_ALLOCATION_INFORMATION;
    15391788        sfi.generic.in.file.path = fname;
    1540         sfi.end_of_file_info.in.size = 100;
     1789        sfi.allocation_info.in.alloc_size = 65536 * 8;
    15411790
    15421791        status = smb_raw_setpathinfo(cli2->tree, &sfi);
     
    15441793
    15451794        torture_wait_for_oplock_break(tctx);
    1546         CHECK_VAL(break_info.count, 1);
     1795        CHECK_VAL(break_info.count, get_break_level1_to_none_count(tctx));
    15471796        CHECK_VAL(break_info.failures, 0);
    15481797        CHECK_VAL(break_info.level, 0);
     
    15571806}
    15581807
    1559 static bool test_raw_oplock_batch12(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
    1560 {
    1561         const char *fname = BASEDIR "\\test_batch12.dat";
    1562         NTSTATUS status;
    1563         bool ret = true;
    1564         union smb_open io;
    1565         union smb_setfileinfo sfi;
    1566         uint16_t fnum=0;
    1567 
    1568         if (!torture_setup_dir(cli1, BASEDIR)) {
    1569                 return false;
    1570         }
    1571 
    1572         /* cleanup */
    1573         smbcli_unlink(cli1->tree, fname);
    1574 
    1575         smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
    1576 
    1577         /*
    1578           base ntcreatex parms
    1579         */
    1580         io.generic.level = RAW_OPEN_NTCREATEX;
    1581         io.ntcreatex.in.root_fid = 0;
    1582         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    1583         io.ntcreatex.in.alloc_size = 0;
    1584         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
    1585         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
    1586         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
    1587         io.ntcreatex.in.create_options = 0;
    1588         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
    1589         io.ntcreatex.in.security_flags = 0;
    1590         io.ntcreatex.in.fname = fname;
    1591 
    1592         /* Test if a set-allocation size on pathname breaks an exclusive oplock. */
    1593         torture_comment(tctx, "BATCH12: Test if setpathinfo allocation size breaks oplocks.\n");
    1594 
    1595         ZERO_STRUCT(break_info);
    1596         smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
    1597 
    1598         io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
    1599                 NTCREATEX_FLAGS_REQUEST_OPLOCK |
    1600                 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
    1601         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    1602         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
    1603                 NTCREATEX_SHARE_ACCESS_WRITE|
    1604                 NTCREATEX_SHARE_ACCESS_DELETE;
    1605         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
    1606         status = smb_raw_open(cli1->tree, tctx, &io);
    1607         CHECK_STATUS(tctx, status, NT_STATUS_OK);
    1608         fnum = io.ntcreatex.out.file.fnum;
    1609         torture_wait_for_oplock_break(tctx);
    1610         CHECK_VAL(break_info.count, 0);
    1611         CHECK_VAL(break_info.failures, 0);
    1612         CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
    1613 
    1614         ZERO_STRUCT(sfi);
    1615         sfi.generic.level = SMB_SFILEINFO_ALLOCATION_INFORMATION;
    1616         sfi.generic.in.file.path = fname;
    1617         sfi.allocation_info.in.alloc_size = 65536 * 8;
    1618 
    1619         status = smb_raw_setpathinfo(cli2->tree, &sfi);
    1620         CHECK_STATUS(tctx, status, NT_STATUS_OK);
    1621 
    1622         torture_wait_for_oplock_break(tctx);
    1623         CHECK_VAL(break_info.count, 1);
    1624         CHECK_VAL(break_info.failures, 0);
    1625         CHECK_VAL(break_info.level, 0);
    1626 
    1627         smbcli_close(cli1->tree, fnum);
    1628 
    1629 done:
    1630         smb_raw_exit(cli1->session);
    1631         smb_raw_exit(cli2->session);
    1632         smbcli_deltree(cli1->tree, BASEDIR);
    1633         return ret;
    1634 }
    1635 
    16361808static bool test_raw_oplock_batch13(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
    16371809{
     
    16561828        */
    16571829        io.generic.level = RAW_OPEN_NTCREATEX;
    1658         io.ntcreatex.in.root_fid = 0;
     1830        io.ntcreatex.in.root_fid.fnum = 0;
    16591831        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    16601832        io.ntcreatex.in.alloc_size = 0;
     
    16981870        torture_wait_for_oplock_break(tctx);
    16991871        CHECK_VAL(io.ntcreatex.out.oplock_level, LEVEL_II_OPLOCK_RETURN);
    1700         CHECK_VAL(break_info.count, 1);
     1872        CHECK_VAL(break_info.count, get_break_level1_to_none_count(tctx));
    17011873        CHECK_VAL(break_info.failures, 0);
    17021874
     
    17321904        */
    17331905        io.generic.level = RAW_OPEN_NTCREATEX;
    1734         io.ntcreatex.in.root_fid = 0;
     1906        io.ntcreatex.in.root_fid.fnum = 0;
    17351907        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    17361908        io.ntcreatex.in.alloc_size = 0;
     
    17751947
    17761948        torture_wait_for_oplock_break(tctx);
    1777         CHECK_VAL(break_info.count, 1);
     1949        CHECK_VAL(break_info.count, get_break_level1_to_none_count(tctx));
    17781950        CHECK_VAL(break_info.failures, 0);
    17791951
     
    18091981        */
    18101982        io.generic.level = RAW_OPEN_NTCREATEX;
    1811         io.ntcreatex.in.root_fid = 0;
     1983        io.ntcreatex.in.root_fid.fnum = 0;
    18121984        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    18131985        io.ntcreatex.in.alloc_size = 0;
     
    18842056        */
    18852057        io.generic.level = RAW_OPEN_NTCREATEX;
    1886         io.ntcreatex.in.root_fid = 0;
     2058        io.ntcreatex.in.root_fid.fnum = 0;
    18872059        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    18882060        io.ntcreatex.in.alloc_size = 0;
     
    19272099
    19282100        torture_wait_for_oplock_break(tctx);
    1929         CHECK_VAL(break_info.count, 1);
     2101        CHECK_VAL(break_info.count, get_break_level1_to_none_count(tctx));
    19302102        CHECK_VAL(break_info.failures, 0);
    19312103
     
    19642136        */
    19652137        io.generic.level = RAW_OPEN_NTCREATEX;
    1966         io.ntcreatex.in.root_fid = 0;
     2138        io.ntcreatex.in.root_fid.fnum = 0;
    19672139        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    19682140        io.ntcreatex.in.alloc_size = 0;
     
    20362208        */
    20372209        io.generic.level = RAW_OPEN_NTCREATEX;
    2038         io.ntcreatex.in.root_fid = 0;
     2210        io.ntcreatex.in.root_fid.fnum = 0;
    20392211        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    20402212        io.ntcreatex.in.alloc_size = 0;
     
    21112283        */
    21122284        io.generic.level = RAW_OPEN_NTCREATEX;
    2113         io.ntcreatex.in.root_fid = 0;
     2285        io.ntcreatex.in.root_fid.fnum = 0;
    21142286        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    21152287        io.ntcreatex.in.alloc_size = 0;
    21162288        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
    2117         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
     2289        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
     2290            NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
    21182291        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
    21192292        io.ntcreatex.in.create_options = 0;
     
    21322305        CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
    21332306
    2134         torture_comment(tctx, "setpathinfo rename info should not trigger a break nor a violation\n");
     2307        torture_comment(tctx, "setpathinfo rename info should trigger a break "
     2308            "to none\n");
    21352309        ZERO_STRUCT(sfi);
    21362310        sfi.generic.level = RAW_SFILEINFO_RENAME_INFORMATION;
     
    21442318
    21452319        torture_wait_for_oplock_break(tctx);
    2146         CHECK_VAL(break_info.count, 0);
     2320
     2321        CHECK_VAL(break_info.failures, 0);
     2322
     2323        if (TARGET_IS_WINXP(tctx)) {
     2324                /* Win XP breaks to level2. */
     2325                CHECK_VAL(break_info.count, 1);
     2326                CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
     2327        } else if (TARGET_IS_W2K3(tctx) || TARGET_IS_W2K8(tctx) ||
     2328            TARGET_IS_SAMBA3(tctx) || TARGET_IS_SAMBA4(tctx)) {
     2329                /* Win2K3/2k8 incorrectly doesn't break at all. */
     2330                CHECK_VAL(break_info.count, 0);
     2331        } else {
     2332                /* win7/2k8r2 break to none. */
     2333                CHECK_VAL(break_info.count, 1);
     2334                CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_NONE);
     2335        }
    21472336
    21482337        ZERO_STRUCT(qfi);
     
    21542343        CHECK_STRMATCH(qfi.all_info.out.fname.s, fname2);
    21552344
    2156         torture_comment(tctx, "setfileinfo rename info should not trigger a break nor a violation\n");
     2345        /* Close and re-open file with oplock. */
     2346        smbcli_close(cli1->tree, fnum);
     2347        status = smb_raw_open(cli1->tree, tctx, &io);
     2348        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     2349        fnum = io.ntcreatex.out.file.fnum;
     2350        CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
     2351
     2352        torture_comment(tctx, "setfileinfo rename info on a client's own fid "
     2353            "should not trigger a break nor a violation\n");
     2354        ZERO_STRUCT(break_info);
    21572355        ZERO_STRUCT(sfi);
    21582356        sfi.generic.level = RAW_SFILEINFO_RENAME_INFORMATION;
     
    21662364
    21672365        torture_wait_for_oplock_break(tctx);
    2168         CHECK_VAL(break_info.count, 0);
     2366        if (TARGET_IS_WINXP(tctx)) {
     2367                /* XP incorrectly breaks to level2. */
     2368                CHECK_VAL(break_info.count, 1);
     2369                CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
     2370        } else {
     2371                CHECK_VAL(break_info.count, 0);
     2372        }
    21692373
    21702374        ZERO_STRUCT(qfi);
     
    21762380        CHECK_STRMATCH(qfi.all_info.out.fname.s, fname3);
    21772381
     2382done:
    21782383        smbcli_close(cli1->tree, fnum);
    2179 
    2180 done:
    21812384        smb_raw_exit(cli1->session);
    21822385        smb_raw_exit(cli2->session);
     
    22172420        */
    22182421        io.generic.level = RAW_OPEN_NTCREATEX;
    2219         io.ntcreatex.in.root_fid = 0;
     2422        io.ntcreatex.in.root_fid.fnum = 0;
    22202423        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    22212424        io.ntcreatex.in.alloc_size = 0;
    22222425        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
    2223         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
     2426        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
     2427            NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
    22242428        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
    22252429        io.ntcreatex.in.create_options = 0;
     
    22822486        CHECK_STRMATCH(qfi.all_info.out.fname.s, fname3);
    22832487
     2488done:
    22842489        smbcli_close(cli1->tree, fnum);
    2285 
    2286 done:
    22872490        smb_raw_exit(cli1->session);
    22882491        smb_raw_exit(cli2->session);
     
    23212524        */
    23222525        io.generic.level = RAW_OPEN_NTCREATEX;
    2323         io.ntcreatex.in.root_fid = 0;
     2526        io.ntcreatex.in.root_fid.fnum = 0;
    23242527        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    23252528        io.ntcreatex.in.alloc_size = 0;
     
    24432646        */
    24442647        io.generic.level = RAW_OPEN_NTCREATEX;
    2445         io.ntcreatex.in.root_fid = 0;
     2648        io.ntcreatex.in.root_fid.fnum = 0;
    24462649        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    24472650        io.ntcreatex.in.alloc_size = 0;
     
    24672670        CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
    24682671
    2469         torture_comment(tctx, "setpathinfo rename info should not trigger a break nor a violation\n");
    24702672        ZERO_STRUCT(sfi);
    24712673        sfi.generic.level = RAW_SFILEINFO_RENAME_INFORMATION;
     
    24792681
    24802682        torture_wait_for_oplock_break(tctx);
    2481         CHECK_VAL(break_info.count, 0);
     2683        CHECK_VAL(break_info.failures, 0);
     2684
     2685        if (TARGET_IS_WINXP(tctx)) {
     2686                /* Win XP breaks to level2. */
     2687                CHECK_VAL(break_info.count, 1);
     2688                CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
     2689        } else if (TARGET_IS_W2K3(tctx) || TARGET_IS_W2K8(tctx) ||
     2690            TARGET_IS_SAMBA3(tctx) || TARGET_IS_SAMBA4(tctx)) {
     2691                /* Win2K3/2k8 incorrectly doesn't break at all. */
     2692                CHECK_VAL(break_info.count, 0);
     2693        } else {
     2694                /* win7/2k8r2 break to none. */
     2695                CHECK_VAL(break_info.count, 1);
     2696                CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_NONE);
     2697        }
    24822698
    24832699        ZERO_STRUCT(qfi);
     
    25042720
    25052721        torture_wait_for_oplock_break(tctx);
    2506         CHECK_VAL(break_info.count, 1);
    2507         CHECK_VAL(break_info.failures, 0);
    2508         CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
    2509 
    2510         torture_comment(tctx, "setfileinfo rename info should not trigger a break nor a violation\n");
     2722
     2723        if (TARGET_IS_WINXP(tctx)) {
     2724                /* XP broke to level2, and doesn't break again. */
     2725                CHECK_VAL(break_info.count, 0);
     2726        } else if (TARGET_IS_W2K3(tctx) || TARGET_IS_W2K8(tctx) ||
     2727            TARGET_IS_SAMBA3(tctx) || TARGET_IS_SAMBA4(tctx)) {
     2728                /* Win2K3 incorrectly didn't break before so break now. */
     2729                CHECK_VAL(break_info.count, 1);
     2730                CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
     2731        } else {
     2732                /* win7/2k8r2 broke to none, and doesn't break again. */
     2733                CHECK_VAL(break_info.count, 0);
     2734        }
     2735
     2736        ZERO_STRUCT(break_info);
     2737
    25112738        ZERO_STRUCT(sfi);
    25122739        sfi.generic.level = RAW_SFILEINFO_RENAME_INFORMATION;
     
    25202747
    25212748        torture_wait_for_oplock_break(tctx);
    2522         CHECK_VAL(break_info.count, 1);
    2523         CHECK_VAL(break_info.failures, 0);
    2524         CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
     2749        CHECK_VAL(break_info.count, 0);
    25252750
    25262751        ZERO_STRUCT(qfi);
     
    25402765        CHECK_STRMATCH(qfi.all_info.out.fname.s, fname3);
    25412766
     2767
     2768done:
    25422769        smbcli_close(cli1->tree, fnum);
    2543 
    2544 done:
     2770        smbcli_close(cli2->tree, fnum2);
    25452771        smb_raw_exit(cli1->session);
    25462772        smb_raw_exit(cli2->session);
     
    25732799        */
    25742800        io.generic.level = RAW_OPEN_NTCREATEX;
    2575         io.ntcreatex.in.root_fid = 0;
     2801        io.ntcreatex.in.root_fid.fnum = 0;
    25762802        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    25772803        io.ntcreatex.in.alloc_size = 0;
     
    26252851        bool ret = true;
    26262852        union smb_open io;
    2627         uint16_t fnum=0, fnum2=0;
     2853        uint16_t fnum = 0, fnum2 = 0, fnum3 = 0;
    26282854        struct timeval tv;
    26292855        int timeout = torture_setting_int(tctx, "oplocktimeout", 30);
    26302856        int te;
    26312857
    2632         if (torture_setting_bool(tctx, "samba3", false)) {
    2633                 torture_skip(tctx, "BATCH22 disabled against samba3\n");
    2634         }
    2635 
    26362858        if (!torture_setup_dir(cli1, BASEDIR)) {
    26372859                return false;
     
    26422864
    26432865        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
    2644 
    26452866        /*
    26462867          base ntcreatex parms
    26472868        */
    26482869        io.generic.level = RAW_OPEN_NTCREATEX;
    2649         io.ntcreatex.in.root_fid = 0;
     2870        io.ntcreatex.in.root_fid.fnum = 0;
    26502871        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    26512872        io.ntcreatex.in.alloc_size = 0;
     
    26792900        smbcli_oplock_handler(cli1->transport, oplock_handler_timeout, cli1->tree);
    26802901        status = smb_raw_open(cli1->tree, tctx, &io);
    2681         CHECK_STATUS(tctx, status, NT_STATUS_SHARING_VIOLATION);
     2902
     2903        if (TARGET_IS_W2K3(tctx)) {
     2904                /* 2k3 has an issue here. xp/win7 are ok. */
     2905                CHECK_STATUS(tctx, status, NT_STATUS_SHARING_VIOLATION);
     2906        } else {
     2907                CHECK_STATUS(tctx, status, NT_STATUS_OK);
     2908        }
     2909
     2910        fnum2 = io.ntcreatex.out.file.fnum;
     2911
    26822912        torture_wait_for_oplock_break(tctx);
    26832913        te = (int)timeval_elapsed(&tv);
     2914
     2915        /*
     2916         * Some servers detect clients that let oplocks timeout, so this check
     2917         * only shows a warning message instead failing the test to eliminate
     2918         * failures from repeated runs of the test.  This isn't ideal, but
     2919         * it's better than not running the test at all.
     2920         */
    26842921        CHECK_RANGE(te, timeout - 1, timeout + 15);
    26852922
     
    26962933        status = smb_raw_open(cli1->tree, tctx, &io);
    26972934        CHECK_STATUS(tctx, status, NT_STATUS_OK);
    2698         CHECK_VAL(io.ntcreatex.out.oplock_level, LEVEL_II_OPLOCK_RETURN);
     2935#if 0
     2936        /* Samba 3.6.0 and above behave as Windows. */
     2937        if (TARGET_IS_SAMBA3(tctx)) {
     2938                /* samba3 doesn't grant additional oplocks to bad clients. */
     2939                CHECK_VAL(io.ntcreatex.out.oplock_level, NO_OPLOCK_RETURN);
     2940        } else {
     2941                CHECK_VAL(io.ntcreatex.out.oplock_level,
     2942                        LEVEL_II_OPLOCK_RETURN);
     2943        }
     2944#else
     2945        CHECK_VAL(io.ntcreatex.out.oplock_level,
     2946                  LEVEL_II_OPLOCK_RETURN);
     2947#endif
    26992948        torture_wait_for_oplock_break(tctx);
    27002949        te = (int)timeval_elapsed(&tv);
    27012950        /* it should come in without delay */
    27022951        CHECK_RANGE(te+1, 0, timeout);
    2703         fnum2 = io.ntcreatex.out.file.fnum;
     2952        fnum3 = io.ntcreatex.out.file.fnum;
    27042953
    27052954        CHECK_VAL(break_info.count, 0);
     
    27072956        smbcli_close(cli1->tree, fnum);
    27082957        smbcli_close(cli1->tree, fnum2);
     2958        smbcli_close(cli1->tree, fnum3);
    27092959
    27102960done:
     
    27422992        */
    27432993        io.generic.level = RAW_OPEN_NTCREATEX;
    2744         io.ntcreatex.in.root_fid = 0;
     2994        io.ntcreatex.in.root_fid.fnum = 0;
    27452995        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    27462996        io.ntcreatex.in.alloc_size = 0;
     
    28303080        */
    28313081        io.generic.level = RAW_OPEN_NTCREATEX;
    2832         io.ntcreatex.in.root_fid = 0;
     3082        io.ntcreatex.in.root_fid.fnum = 0;
    28333083        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    28343084        io.ntcreatex.in.alloc_size = 0;
     
    29033153        */
    29043154        io.generic.level = RAW_OPEN_NTCREATEX;
    2905         io.ntcreatex.in.root_fid = 0;
     3155        io.ntcreatex.in.root_fid.fnum = 0;
    29063156        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    29073157        io.ntcreatex.in.alloc_size = 0;
     
    29393189        torture_wait_for_oplock_break(tctx);
    29403190        CHECK_VAL(break_info.count, 0);
     3191
     3192        smbcli_close(cli1->tree, fnum);
     3193
     3194done:
     3195        smb_raw_exit(cli1->session);
     3196        smb_raw_exit(cli2->session);
     3197        smbcli_deltree(cli1->tree, BASEDIR);
     3198        return ret;
     3199}
     3200
     3201/**
     3202 * Similar to batch17/18, but test with open share mode rather than
     3203 * share_none.
     3204 */
     3205static bool test_raw_oplock_batch26(struct torture_context *tctx,
     3206    struct smbcli_state *cli1, struct smbcli_state *cli2)
     3207{
     3208        const char *fname1 = BASEDIR "\\test_batch26_1.dat";
     3209        const char *fname2 = BASEDIR "\\test_batch26_2.dat";
     3210        NTSTATUS status;
     3211        bool ret = true;
     3212        union smb_open io;
     3213        union smb_rename rn;
     3214        uint16_t fnum=0;
     3215
     3216        if (!torture_setup_dir(cli1, BASEDIR)) {
     3217                return false;
     3218        }
     3219
     3220        /* cleanup */
     3221        smbcli_unlink(cli1->tree, fname1);
     3222        smbcli_unlink(cli1->tree, fname2);
     3223
     3224        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given,
     3225            cli1->tree);
     3226
     3227        /*
     3228          base ntcreatex parms
     3229        */
     3230        io.generic.level = RAW_OPEN_NTCREATEX;
     3231        io.ntcreatex.in.root_fid.fnum = 0;
     3232        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     3233        io.ntcreatex.in.alloc_size = 0;
     3234        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     3235        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
     3236            NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
     3237        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
     3238        io.ntcreatex.in.create_options = 0;
     3239        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     3240        io.ntcreatex.in.security_flags = 0;
     3241        io.ntcreatex.in.fname = fname1;
     3242
     3243        torture_comment(tctx, "BATCH26: open a file with an batch oplock "
     3244            "(share mode: none)\n");
     3245
     3246        ZERO_STRUCT(break_info);
     3247        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
     3248                NTCREATEX_FLAGS_REQUEST_OPLOCK |
     3249                NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
     3250
     3251
     3252        status = smb_raw_open(cli1->tree, tctx, &io);
     3253        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     3254        fnum = io.ntcreatex.out.file.fnum;
     3255        CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
     3256
     3257        torture_comment(tctx, "rename should trigger a break\n");
     3258        ZERO_STRUCT(rn);
     3259        rn.generic.level = RAW_RENAME_RENAME;
     3260        rn.rename.in.pattern1 = fname1;
     3261        rn.rename.in.pattern2 = fname2;
     3262        rn.rename.in.attrib = 0;
     3263
     3264        torture_comment(tctx, "trying rename while first file open\n");
     3265        status = smb_raw_rename(cli2->tree, &rn);
     3266        CHECK_STATUS(tctx, status, NT_STATUS_SHARING_VIOLATION);
     3267
     3268        torture_wait_for_oplock_break(tctx);
     3269        CHECK_VAL(break_info.count, 1);
     3270        CHECK_VAL(break_info.failures, 0);
     3271        CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
     3272
     3273        /* Close and reopen with batch again. */
     3274        smbcli_close(cli1->tree, fnum);
     3275        ZERO_STRUCT(break_info);
     3276
     3277        status = smb_raw_open(cli1->tree, tctx, &io);
     3278        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     3279        fnum = io.ntcreatex.out.file.fnum;
     3280        CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
     3281
     3282        /* Now try ntrename. */
     3283        torture_comment(tctx, "ntrename should trigger a break\n");
     3284        ZERO_STRUCT(rn);
     3285        rn.generic.level = RAW_RENAME_NTRENAME;
     3286        rn.ntrename.in.attrib   = 0;
     3287        rn.ntrename.in.flags    = RENAME_FLAG_RENAME;
     3288        rn.ntrename.in.old_name = fname1;
     3289        rn.ntrename.in.new_name = fname2;
     3290        torture_comment(tctx, "trying rename while first file open\n");
     3291        status = smb_raw_rename(cli2->tree, &rn);
     3292        CHECK_STATUS(tctx, status, NT_STATUS_SHARING_VIOLATION);
     3293
     3294        torture_wait_for_oplock_break(tctx);
     3295        CHECK_VAL(break_info.count, 1);
     3296        CHECK_VAL(break_info.failures, 0);
     3297        CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
    29413298
    29423299        smbcli_close(cli1->tree, fnum);
     
    30113368        /* Setup generic open parameters. */
    30123369        io.generic.level = RAW_OPEN_NTCREATEX;
    3013         io.ntcreatex.in.root_fid = 0;
     3370        io.ntcreatex.in.root_fid.fnum = 0;
    30143371        io.ntcreatex.in.access_mask = (SEC_FILE_READ_DATA|SEC_FILE_WRITE_DATA|
    30153372            SEC_FILE_APPEND_DATA|SEC_STD_READ_CONTROL);
     
    30443401                if (open_base_file) {
    30453402                        torture_comment(tctx, "Opening base file: %s with "
    3046                             "%d\n", fname_base, oplock_req);
     3403                            "%d\n", fname_base, batch_req);
    30473404                        io.ntcreatex.in.fname = fname_base;
    30483405                        io.ntcreatex.in.flags = batch_req;
     
    31503507        */
    31513508        io.generic.level = RAW_OPEN_NTCREATEX;
    3152         io.ntcreatex.in.root_fid = 0;
     3509        io.ntcreatex.in.root_fid.fnum = 0;
    31533510        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    31543511        io.ntcreatex.in.alloc_size = 0;
     
    32133570        */
    32143571        io.generic.level = RAW_OPEN_NTCREATEX;
    3215         io.ntcreatex.in.root_fid = 0;
     3572        io.ntcreatex.in.root_fid.fnum = 0;
    32163573        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_READ |
    32173574                                      SEC_RIGHTS_FILE_WRITE;
     
    33243681        */
    33253682        io.generic.level = RAW_OPEN_NTCREATEX;
    3326         io.ntcreatex.in.root_fid = 0;
     3683        io.ntcreatex.in.root_fid.fnum = 0;
    33273684        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_READ |
    33283685                                      SEC_RIGHTS_FILE_WRITE;
     
    34173774        */
    34183775        io.generic.level = RAW_OPEN_NTCREATEX;
    3419         io.ntcreatex.in.root_fid = 0;
     3776        io.ntcreatex.in.root_fid.fnum = 0;
    34203777        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_READ |
    34213778                                      SEC_RIGHTS_FILE_WRITE;
     
    35003857
    35013858/*
     3859 * Open a file with an exclusive oplock from the 1st client and acquire a
     3860 * brl. Then open the same file from the 2nd client that should give oplock
     3861 * break with level2 to the 1st and return no oplock to the 2nd.
     3862 */
     3863static bool test_raw_oplock_brl4(struct torture_context *tctx,
     3864                                 struct smbcli_state *cli1,
     3865                                 struct smbcli_state *cli2)
     3866{
     3867        const char *fname = BASEDIR "\\test_batch_brl.dat";
     3868        bool ret = true;
     3869        uint8_t buf[1000];
     3870        bool correct = true;
     3871        union smb_open io;
     3872        NTSTATUS status;
     3873        uint16_t fnum = 0;
     3874        uint16_t fnum2 = 0;
     3875
     3876        if (!torture_setup_dir(cli1, BASEDIR)) {
     3877                return false;
     3878        }
     3879
     3880        /* cleanup */
     3881        smbcli_unlink(cli1->tree, fname);
     3882
     3883        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given,
     3884                              cli1->tree);
     3885
     3886        /*
     3887          base ntcreatex parms
     3888        */
     3889        io.generic.level = RAW_OPEN_NTCREATEX;
     3890        io.ntcreatex.in.root_fid.fnum = 0;
     3891        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_READ |
     3892                                      SEC_RIGHTS_FILE_WRITE;
     3893        io.ntcreatex.in.alloc_size = 0;
     3894        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     3895        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
     3896                                       NTCREATEX_SHARE_ACCESS_WRITE;
     3897        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
     3898        io.ntcreatex.in.create_options = 0;
     3899        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     3900        io.ntcreatex.in.security_flags = 0;
     3901        io.ntcreatex.in.fname = fname;
     3902
     3903        torture_comment(tctx, "open with exclusive oplock\n");
     3904        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
     3905                NTCREATEX_FLAGS_REQUEST_OPLOCK;
     3906
     3907        status = smb_raw_open(cli1->tree, tctx, &io);
     3908
     3909        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     3910        fnum = io.ntcreatex.out.file.fnum;
     3911        CHECK_VAL(io.ntcreatex.out.oplock_level, EXCLUSIVE_OPLOCK_RETURN);
     3912
     3913        /* create a file with bogus data */
     3914        memset(buf, 0, sizeof(buf));
     3915
     3916        if (smbcli_write(cli1->tree, fnum, 0, buf, 0, sizeof(buf)) !=
     3917                         sizeof(buf))
     3918        {
     3919                torture_comment(tctx, "Failed to create file\n");
     3920                correct = false;
     3921                goto done;
     3922        }
     3923
     3924        status = smbcli_lock(cli1->tree, fnum, 0, 1, 0, WRITE_LOCK);
     3925        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     3926
     3927        torture_comment(tctx, "a 2nd open should give a break to the 1st\n");
     3928        ZERO_STRUCT(break_info);
     3929
     3930        status = smb_raw_open(cli2->tree, tctx, &io);
     3931
     3932        CHECK_STATUS(tctx, status, NT_STATUS_OK);
     3933        CHECK_VAL(break_info.count, 1);
     3934        CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
     3935        CHECK_VAL(break_info.failures, 0);
     3936        CHECK_VAL(break_info.fnum, fnum);
     3937
     3938        torture_comment(tctx, "and return no oplock to the 2nd\n");
     3939        fnum2 = io.ntcreatex.out.file.fnum;
     3940        CHECK_VAL(io.ntcreatex.out.oplock_level, NO_OPLOCK_RETURN);
     3941
     3942        smbcli_close(cli1->tree, fnum);
     3943        smbcli_close(cli2->tree, fnum2);
     3944
     3945done:
     3946        smb_raw_exit(cli1->session);
     3947        smb_raw_exit(cli2->session);
     3948        smbcli_deltree(cli1->tree, BASEDIR);
     3949        return ret;
     3950}
     3951
     3952/*
    35023953   basic testing of oplocks
    35033954*/
    35043955struct torture_suite *torture_raw_oplock(TALLOC_CTX *mem_ctx)
    35053956{
    3506         struct torture_suite *suite = torture_suite_create(mem_ctx, "OPLOCK");
    3507 
    3508         torture_suite_add_2smb_test(suite, "EXCLUSIVE1", test_raw_oplock_exclusive1);
    3509         torture_suite_add_2smb_test(suite, "EXCLUSIVE2", test_raw_oplock_exclusive2);
    3510         torture_suite_add_2smb_test(suite, "EXCLUSIVE3", test_raw_oplock_exclusive3);
    3511         torture_suite_add_2smb_test(suite, "EXCLUSIVE4", test_raw_oplock_exclusive4);
    3512         torture_suite_add_2smb_test(suite, "EXCLUSIVE5", test_raw_oplock_exclusive5);
    3513         torture_suite_add_2smb_test(suite, "EXCLUSIVE6", test_raw_oplock_exclusive6);
    3514         torture_suite_add_2smb_test(suite, "BATCH1", test_raw_oplock_batch1);
    3515         torture_suite_add_2smb_test(suite, "BATCH2", test_raw_oplock_batch2);
    3516         torture_suite_add_2smb_test(suite, "BATCH3", test_raw_oplock_batch3);
    3517         torture_suite_add_2smb_test(suite, "BATCH4", test_raw_oplock_batch4);
    3518         torture_suite_add_2smb_test(suite, "BATCH5", test_raw_oplock_batch5);
    3519         torture_suite_add_2smb_test(suite, "BATCH6", test_raw_oplock_batch6);
    3520         torture_suite_add_2smb_test(suite, "BATCH7", test_raw_oplock_batch7);
    3521         torture_suite_add_2smb_test(suite, "BATCH8", test_raw_oplock_batch8);
    3522         torture_suite_add_2smb_test(suite, "BATCH9", test_raw_oplock_batch9);
    3523         torture_suite_add_2smb_test(suite, "BATCH10", test_raw_oplock_batch10);
    3524         torture_suite_add_2smb_test(suite, "BATCH11", test_raw_oplock_batch11);
    3525         torture_suite_add_2smb_test(suite, "BATCH12", test_raw_oplock_batch12);
    3526         torture_suite_add_2smb_test(suite, "BATCH13", test_raw_oplock_batch13);
    3527         torture_suite_add_2smb_test(suite, "BATCH14", test_raw_oplock_batch14);
    3528         torture_suite_add_2smb_test(suite, "BATCH15", test_raw_oplock_batch15);
    3529         torture_suite_add_2smb_test(suite, "BATCH16", test_raw_oplock_batch16);
    3530         torture_suite_add_2smb_test(suite, "BATCH17", test_raw_oplock_batch17);
    3531         torture_suite_add_2smb_test(suite, "BATCH18", test_raw_oplock_batch18);
    3532         torture_suite_add_2smb_test(suite, "BATCH19", test_raw_oplock_batch19);
    3533         torture_suite_add_2smb_test(suite, "BATCH20", test_raw_oplock_batch20);
    3534         torture_suite_add_2smb_test(suite, "BATCH21", test_raw_oplock_batch21);
    3535         torture_suite_add_2smb_test(suite, "BATCH22", test_raw_oplock_batch22);
    3536         torture_suite_add_2smb_test(suite, "BATCH23", test_raw_oplock_batch23);
    3537         torture_suite_add_2smb_test(suite, "BATCH24", test_raw_oplock_batch24);
    3538         torture_suite_add_2smb_test(suite, "BATCH25", test_raw_oplock_batch25);
    3539         torture_suite_add_2smb_test(suite, "STREAM1", test_raw_oplock_stream1);
    3540         torture_suite_add_1smb_test(suite, "DOC1", test_raw_oplock_doc);
    3541         torture_suite_add_2smb_test(suite, "BRL1", test_raw_oplock_brl1);
    3542         torture_suite_add_1smb_test(suite, "BRL2", test_raw_oplock_brl2);
    3543         torture_suite_add_1smb_test(suite, "BRL3", test_raw_oplock_brl3);
     3957        struct torture_suite *suite = torture_suite_create(mem_ctx, "oplock");
     3958
     3959        torture_suite_add_2smb_test(suite, "exclusive1", test_raw_oplock_exclusive1);
     3960        torture_suite_add_2smb_test(suite, "exclusive2", test_raw_oplock_exclusive2);
     3961        torture_suite_add_2smb_test(suite, "exclusive3", test_raw_oplock_exclusive3);
     3962        torture_suite_add_2smb_test(suite, "exclusive4", test_raw_oplock_exclusive4);
     3963        torture_suite_add_2smb_test(suite, "exclusive5", test_raw_oplock_exclusive5);
     3964        torture_suite_add_2smb_test(suite, "exclusive6", test_raw_oplock_exclusive6);
     3965        torture_suite_add_2smb_test(suite, "exclusive7", test_raw_oplock_exclusive7);
     3966        torture_suite_add_2smb_test(suite, "batch1", test_raw_oplock_batch1);
     3967        torture_suite_add_2smb_test(suite, "batch2", test_raw_oplock_batch2);
     3968        torture_suite_add_2smb_test(suite, "batch3", test_raw_oplock_batch3);
     3969        torture_suite_add_2smb_test(suite, "batch4", test_raw_oplock_batch4);
     3970        torture_suite_add_2smb_test(suite, "batch5", test_raw_oplock_batch5);
     3971        torture_suite_add_2smb_test(suite, "batch6", test_raw_oplock_batch6);
     3972        torture_suite_add_2smb_test(suite, "batch7", test_raw_oplock_batch7);
     3973        torture_suite_add_2smb_test(suite, "batch8", test_raw_oplock_batch8);
     3974        torture_suite_add_2smb_test(suite, "batch9", test_raw_oplock_batch9);
     3975        torture_suite_add_2smb_test(suite, "batch10", test_raw_oplock_batch10);
     3976        torture_suite_add_2smb_test(suite, "batch11", test_raw_oplock_batch11);
     3977        torture_suite_add_2smb_test(suite, "batch12", test_raw_oplock_batch12);
     3978        torture_suite_add_2smb_test(suite, "batch13", test_raw_oplock_batch13);
     3979        torture_suite_add_2smb_test(suite, "batch14", test_raw_oplock_batch14);
     3980        torture_suite_add_2smb_test(suite, "batch15", test_raw_oplock_batch15);
     3981        torture_suite_add_2smb_test(suite, "batch16", test_raw_oplock_batch16);
     3982        torture_suite_add_2smb_test(suite, "batch17", test_raw_oplock_batch17);
     3983        torture_suite_add_2smb_test(suite, "batch18", test_raw_oplock_batch18);
     3984        torture_suite_add_2smb_test(suite, "batch19", test_raw_oplock_batch19);
     3985        torture_suite_add_2smb_test(suite, "batch20", test_raw_oplock_batch20);
     3986        torture_suite_add_2smb_test(suite, "batch21", test_raw_oplock_batch21);
     3987        torture_suite_add_2smb_test(suite, "batch22", test_raw_oplock_batch22);
     3988        torture_suite_add_2smb_test(suite, "batch23", test_raw_oplock_batch23);
     3989        torture_suite_add_2smb_test(suite, "batch24", test_raw_oplock_batch24);
     3990        torture_suite_add_2smb_test(suite, "batch25", test_raw_oplock_batch25);
     3991        torture_suite_add_2smb_test(suite, "batch26", test_raw_oplock_batch26);
     3992        torture_suite_add_2smb_test(suite, "stream1", test_raw_oplock_stream1);
     3993        torture_suite_add_1smb_test(suite, "doc1", test_raw_oplock_doc);
     3994        torture_suite_add_2smb_test(suite, "brl1", test_raw_oplock_brl1);
     3995        torture_suite_add_1smb_test(suite, "brl2", test_raw_oplock_brl2);
     3996        torture_suite_add_1smb_test(suite, "brl3", test_raw_oplock_brl3);
     3997        torture_suite_add_2smb_test(suite, "brl4", test_raw_oplock_brl4);
    35443998
    35453999        return suite;
     
    35784032
    35794033        io.ntcreatex.level = RAW_OPEN_NTCREATEX;
    3580         io.ntcreatex.in.root_fid = 0;
     4034        io.ntcreatex.in.root_fid.fnum = 0;
    35814035        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    35824036        io.ntcreatex.in.alloc_size = 0;
     
    37044158
    37054159                io.generic.level = RAW_OPEN_NTCREATEX;
    3706                 io.ntcreatex.in.root_fid = 0;
     4160                io.ntcreatex.in.root_fid.fnum = 0;
    37074161                io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    37084162                io.ntcreatex.in.alloc_size = 0;
  • trunk/server/source4/torture/raw/pingpong.c

    r414 r745  
    4545*/
    4646#include "includes.h"
    47 #include "torture/torture.h"
    48 #include "libcli/raw/libcliraw.h"
    4947#include "system/time.h"
    5048#include "system/filesys.h"
     
    157155        }
    158156}       
    159 
    160 
    161 static struct timeval tp1, tp2;
    162 
    163 static void start_timer(void)
    164 {
    165         gettimeofday(&tp1, NULL);
    166 }
    167 
    168 static double end_timer(void)
    169 {
    170         gettimeofday(&tp2, NULL);
    171         return (tp2.tv_sec + (tp2.tv_usec*1.0e-6)) -
    172                 (tp1.tv_sec + (tp1.tv_usec*1.0e-6));
    173 }
    174157
    175158/*
     
    190173        uint8_t *val;
    191174        int count, loops;
     175        struct timeval start;
    192176
    193177        fn = torture_setting_string(torture, "filename", NULL);
     
    222206
    223207
    224         start_timer();
     208        start = timeval_current();
    225209        val = talloc_zero_array(mem_ctx, uint8_t, num_locks);
    226210        i = 0;
     
    251235                        fflush(stdout);
    252236                }
    253                 if (end_timer() > 1.0) {
     237                if (timeval_elapsed(&start) > 1.0) {
    254238                        printf("%8u locks/sec\r",
    255                                (unsigned)(2*count/end_timer()));
     239                               (unsigned)(2*count/timeval_elapsed(&start)));
    256240                        fflush(stdout);
    257                         start_timer();
     241                        start = timeval_current();
    258242                        count=0;
    259243                }
    260244                loops++;
    261245        }
    262 
    263         talloc_free(mem_ctx);
    264         return true;
    265246}
    266247
  • trunk/server/source4/torture/raw/qfileinfo.c

    r414 r745  
    2020
    2121#include "includes.h"
    22 #include "torture/torture.h"
    2322#include "libcli/raw/libcliraw.h"
    2423#include "libcli/raw/raw_proto.h"
    2524#include "libcli/libcli.h"
    2625#include "torture/util.h"
    27 #include "librpc/rpc/dcerpc.h"
    28 #include "torture/rpc/rpc.h"
    29 #include "torture/raw/proto.h"
     26#include "torture/rpc/torture_rpc.h"
    3027#include "param/param.h"
    3128
     
    3330        const char *name;
    3431        enum smb_fileinfo_level level;
    35         uint_t only_paths:1;
    36         uint_t only_handles:1;
     32        unsigned int only_paths:1;
     33        unsigned int only_handles:1;
    3734        uint32_t capability_mask;
    38         uint_t expected_ipc_access_denied:1;
     35        unsigned int expected_ipc_access_denied:1;
    3936        NTSTATUS expected_ipc_fnum_status;
    4037        NTSTATUS fnum_status, fname_status;
     
    144141        time_t t2 = nt_time_to_unix(nt);
    145142        if (abs(t2 - t) <= 2) return 0;
    146         return t2 - t;
     143        return t2 > t ? 1 : -1;
    147144}
    148145
     
    186183#define VAL_EQUAL(n1, v1, n2, v2) do {if (s1->n1.out.v1 != s2->n2.out.v2) { \
    187184        printf("%s/%s [%u] != %s/%s [%u] at %s(%d)\n", \
    188                #n1, #v1, (uint_t)s1->n1.out.v1, \
    189                #n2, #v2, (uint_t)s2->n2.out.v2, \
     185               #n1, #v1, (unsigned int)s1->n1.out.v1, \
     186               #n2, #v2, (unsigned int)s2->n2.out.v2, \
    190187               __FILE__, __LINE__); \
    191188        ret = false; \
     
    215212        printf("%s/%s non-zero unknown - %u (0x%x) at %s(%d)\n", \
    216213               #n1, #v1, \
    217                (uint_t)s1->n1.out.v1, \
    218                (uint_t)s1->n1.out.v1, \
     214               (unsigned int)s1->n1.out.v1, \
     215               (unsigned int)s1->n1.out.v1, \
    219216               __FILE__, __LINE__); \
    220217        ret = false; \
     
    269266                if (is_ipc) {
    270267                        if (levels[i].expected_ipc_access_denied && NT_STATUS_EQUAL(NT_STATUS_ACCESS_DENIED, levels[i].fname_status)) {
     268                        } else if (!levels[i].only_handles &&
     269                                   NT_STATUS_EQUAL(levels[i].fname_status,
     270                                   NT_STATUS_NOT_SUPPORTED)) {
     271                                torture_warning(torture, "fname level %s %s",
     272                                        levels[i].name,
     273                                        nt_errstr(levels[i].fname_status));
     274                                continue;
    271275                        } else if (!levels[i].only_handles && !NT_STATUS_EQUAL(NT_STATUS_INVALID_DEVICE_REQUEST, levels[i].fname_status)) {
    272276                                printf("ERROR: fname level %s failed, expected NT_STATUS_INVALID_DEVICE_REQUEST - %s\n",
    273277                                       levels[i].name, nt_errstr(levels[i].fname_status));
    274278                                count++;
     279                        }
     280                        if (!levels[i].only_paths &&
     281                           (NT_STATUS_EQUAL(levels[i].fnum_status,
     282                            NT_STATUS_NOT_SUPPORTED) ||
     283                            NT_STATUS_EQUAL(levels[i].fnum_status,
     284                            NT_STATUS_NOT_IMPLEMENTED))) {
     285                                torture_warning(torture, "fnum level %s %s",
     286                                        levels[i].name,
     287                                        nt_errstr(levels[i].fnum_status));
     288                                continue;
    275289                        }
    276290                        if (!levels[i].only_paths && !NT_STATUS_EQUAL(levels[i].expected_ipc_fnum_status, levels[i].fnum_status)) {
     
    281295                        }
    282296                } else {
     297                        if (!levels[i].only_paths &&
     298                           (NT_STATUS_EQUAL(levels[i].fnum_status,
     299                            NT_STATUS_NOT_SUPPORTED) ||
     300                            NT_STATUS_EQUAL(levels[i].fnum_status,
     301                            NT_STATUS_NOT_IMPLEMENTED))) {
     302                                torture_warning(torture, "fnum level %s %s",
     303                                        levels[i].name,
     304                                        nt_errstr(levels[i].fnum_status));
     305                                continue;
     306                        }
     307
     308                        if (!levels[i].only_handles &&
     309                           (NT_STATUS_EQUAL(levels[i].fname_status,
     310                            NT_STATUS_NOT_SUPPORTED) ||
     311                            NT_STATUS_EQUAL(levels[i].fname_status,
     312                            NT_STATUS_NOT_IMPLEMENTED))) {
     313                                torture_warning(torture, "fname level %s %s",
     314                                        levels[i].name,
     315                                        nt_errstr(levels[i].fname_status));
     316                                continue;
     317                        }
     318
    283319                        if (!levels[i].only_paths && !NT_STATUS_IS_OK(levels[i].fnum_status)) {
    284320                                printf("ERROR: fnum level %s failed - %s\n",
     
    500536        if (s1 && s1->stype.out.tfield != correct_size) { \
    501537                printf("(%d) handle %s/%s incorrect - %u should be %u\n", __LINE__, #stype, #tfield,  \
    502                        (uint_t)s1->stype.out.tfield, \
    503                        (uint_t)correct_size); \
     538                       (unsigned int)s1->stype.out.tfield, \
     539                       (unsigned int)correct_size); \
    504540                ret = false; \
    505541        } \
     
    507543        if (s1 && s1->stype.out.tfield != correct_size) { \
    508544                printf("(%d) path %s/%s incorrect - %u should be %u\n", __LINE__, #stype, #tfield,  \
    509                        (uint_t)s1->stype.out.tfield, \
    510                        (uint_t)correct_size); \
     545                       (unsigned int)s1->stype.out.tfield, \
     546                       (unsigned int)correct_size); \
    511547                ret = false; \
    512548        }} while (0)
     
    514550        s1 = fnum_find("STANDARD_INFO");
    515551        correct_size = s1->standard_info.out.size;
    516         torture_comment(torture, "size: %u\n", (uint_t)correct_size);
     552        torture_comment(torture, "size: %u\n", (unsigned int)correct_size);
    517553       
    518554        SIZE_CHECK("GETATTR",                  getattr,                  size);
     
    535571        s1 = fnum_find("STANDARD_INFO");
    536572        correct_size = s1->standard_info.out.alloc_size;
    537         torture_comment(torture, "alloc_size: %u\n", (uint_t)correct_size);
     573        torture_comment(torture, "alloc_size: %u\n", (unsigned int)correct_size);
    538574       
    539575        SIZE_CHECK("GETATTRE",                 getattre,                 alloc_size);
     
    554590        if (s1 && s1->stype.out.tfield != correct_attrib) { \
    555591                printf("(%d) handle %s/%s incorrect - 0x%x should be 0x%x\n", __LINE__, #stype, #tfield,  \
    556                        (uint_t)s1->stype.out.tfield, \
    557                        (uint_t)correct_attrib); \
     592                       (unsigned int)s1->stype.out.tfield, \
     593                       (unsigned int)correct_attrib); \
    558594                ret = false; \
    559595        } \
     
    561597        if (s1 && s1->stype.out.tfield != correct_attrib) { \
    562598                printf("(%d) path %s/%s incorrect - 0x%x should be 0x%x\n", __LINE__, #stype, #tfield,  \
    563                        (uint_t)s1->stype.out.tfield, \
    564                        (uint_t)correct_attrib); \
     599                       (unsigned int)s1->stype.out.tfield, \
     600                       (unsigned int)correct_attrib); \
    565601                ret = false; \
    566602        }} while (0)
     
    568604        s1 = fnum_find("BASIC_INFO");
    569605        correct_attrib = s1->basic_info.out.attrib;
    570         torture_comment(torture, "attrib: 0x%x\n", (uint_t)correct_attrib);
     606        torture_comment(torture, "attrib: 0x%x\n", (unsigned int)correct_attrib);
    571607       
    572608        ATTRIB_CHECK("GETATTR",                   getattr,                   attrib);
     
    632668        if (s1) {
    633669                correct_name = s1->alt_name_info.out.fname.s;
     670        }
     671
     672        if (!correct_name) {
     673                torture_comment(torture, "no alternate name information\n");
     674        } else {
    634675                torture_comment(torture, "alt_name: %s\n", correct_name);
    635676               
     
    796837                printf("(%d) handle %s/%s unknown != 0 (0x%x)\n", __LINE__, \
    797838                       #stype, #tfield, \
    798                        (uint_t)s1->stype.out.tfield); \
     839                       (unsigned int)s1->stype.out.tfield); \
    799840        } \
    800841        s1 = fname_find(is_ipc, sname); \
     
    802843                printf("(%d) path %s/%s unknown != 0 (0x%x)\n", __LINE__, \
    803844                       #stype, #tfield, \
    804                        (uint_t)s1->stype.out.tfield); \
     845                       (unsigned int)s1->stype.out.tfield); \
    805846        }} while (0)
    806847#endif
     
    848889        NTSTATUS status;
    849890
    850         if (!(p = dcerpc_pipe_init(torture, cli->tree->session->transport->socket->event.ctx,
    851                                    lp_iconv_convenience(torture->lp_ctx)))) {
     891        if (!(p = dcerpc_pipe_init(torture, cli->tree->session->transport->socket->event.ctx))) {
    852892                return false;
    853893        }
  • trunk/server/source4/torture/raw/qfsinfo.c

    r414 r745  
    1919
    2020#include "includes.h"
    21 #include "torture/torture.h"
    22 #include "libcli/raw/libcliraw.h"
    2321#include "libcli/libcli.h"
    2422#include "torture/util.h"
     
    7270#define VAL_EQUAL(n1, v1, n2, v2) do {if (s1->n1.out.v1 != s2->n2.out.v2) { \
    7371        printf("%s/%s [%u] != %s/%s [%u] at %s(%d)\n", \
    74                #n1, #v1, (uint_t)s1->n1.out.v1, \
    75                #n2, #v2, (uint_t)s2->n2.out.v2, \
     72               #n1, #v1, (unsigned int)s1->n1.out.v1, \
     73               #n2, #v2, (unsigned int)s2->n2.out.v2, \
    7674               __FILE__, __LINE__); \
    7775        ret = false; \
     
    8078#define VAL_APPROX_EQUAL(n1, v1, n2, v2) do {if (abs((int)(s1->n1.out.v1) - (int)(s2->n2.out.v2)) > 0.1*s1->n1.out.v1) { \
    8179        printf("%s/%s [%u] != %s/%s [%u] at %s(%d)\n", \
    82                #n1, #v1, (uint_t)s1->n1.out.v1, \
    83                #n2, #v2, (uint_t)s2->n2.out.v2, \
     80               #n1, #v1, (unsigned int)s1->n1.out.v1, \
     81               #n2, #v2, (unsigned int)s2->n2.out.v2, \
    8482               __FILE__, __LINE__); \
    8583        ret = false; \
     
    108106        printf("%s/%s non-zero unknown - %u (0x%x) at %s(%d)\n", \
    109107               #n1, #v1, \
    110                (uint_t)s1->n1.out.v1, \
    111                (uint_t)s1->n1.out.v1, \
     108               (unsigned int)s1->n1.out.v1, \
     109               (unsigned int)s1->n1.out.v1, \
    112110               __FILE__, __LINE__); \
    113111        ret = false; \
  • trunk/server/source4/torture/raw/raw.c

    r414 r745  
    2727{
    2828        struct torture_suite *suite = torture_suite_create(
    29                 talloc_autofree_context(),
    30                 "RAW");
     29                talloc_autofree_context(), "raw");
    3130        /* RAW smb tests */
    32         torture_suite_add_simple_test(suite, "BENCH-OPLOCK", torture_bench_oplock);
    33         torture_suite_add_simple_test(suite, "PING-PONG", torture_ping_pong);
    34         torture_suite_add_simple_test(suite, "BENCH-LOCK", torture_bench_lock);
    35         torture_suite_add_simple_test(suite, "BENCH-OPEN", torture_bench_open);
    36         torture_suite_add_simple_test(suite, "BENCH-LOOKUP",
     31        torture_suite_add_simple_test(suite, "bench-oplock", torture_bench_oplock);
     32        torture_suite_add_simple_test(suite, "ping-pong", torture_ping_pong);
     33        torture_suite_add_simple_test(suite, "bench-lock", torture_bench_lock);
     34        torture_suite_add_simple_test(suite, "bench-open", torture_bench_open);
     35        torture_suite_add_simple_test(suite, "bench-lookup",
    3736                torture_bench_lookup);
    38         torture_suite_add_simple_test(suite, "BENCH-TCON",
     37        torture_suite_add_simple_test(suite, "bench-tcon",
    3938                torture_bench_treeconnect);
    40         torture_suite_add_simple_test(suite, "OFFLINE", torture_test_offline);
    41         torture_suite_add_1smb_test(suite, "QFSINFO", torture_raw_qfsinfo);
    42         torture_suite_add_1smb_test(suite, "QFILEINFO", torture_raw_qfileinfo);
    43         torture_suite_add_1smb_test(suite, "QFILEINFO-IPC", torture_raw_qfileinfo_pipe);
    44         torture_suite_add_1smb_test(suite, "SFILEINFO", torture_raw_sfileinfo);
    45         torture_suite_add_1smb_test(suite, "SFILEINFO-BUG", torture_raw_sfileinfo_bug);
    46         torture_suite_add_1smb_test(suite, "SFILEINFO-RENAME",
    47                                       torture_raw_sfileinfo_rename);
     39        torture_suite_add_simple_test(suite, "offline", torture_test_offline);
     40        torture_suite_add_1smb_test(suite, "qfsinfo", torture_raw_qfsinfo);
     41        torture_suite_add_1smb_test(suite, "qfileinfo", torture_raw_qfileinfo);
     42        torture_suite_add_1smb_test(suite, "qfileinfo.ipc", torture_raw_qfileinfo_pipe);
     43        torture_suite_add_suite(suite, torture_raw_sfileinfo(suite));
    4844        torture_suite_add_suite(suite, torture_raw_search(suite));
    49         torture_suite_add_1smb_test(suite, "CLOSE", torture_raw_close);
    50         torture_suite_add_1smb_test(suite, "OPEN", torture_raw_open);
    51         torture_suite_add_1smb_test(suite, "MKDIR", torture_raw_mkdir);
     45        torture_suite_add_1smb_test(suite, "close", torture_raw_close);
     46        torture_suite_add_suite(suite, torture_raw_open(suite));
     47        torture_suite_add_1smb_test(suite, "mkdir", torture_raw_mkdir);
    5248        torture_suite_add_suite(suite, torture_raw_oplock(suite));
    53         torture_suite_add_1smb_test(suite, "HOLD-OPLOCK", torture_hold_oplock);
    54         torture_suite_add_2smb_test(suite, "NOTIFY", torture_raw_notify);
    55         torture_suite_add_1smb_test(suite, "MUX", torture_raw_mux);
    56         torture_suite_add_1smb_test(suite, "IOCTL", torture_raw_ioctl);
    57         torture_suite_add_1smb_test(suite, "CHKPATH", torture_raw_chkpath);
     49        torture_suite_add_1smb_test(suite, "hold-oplock", torture_hold_oplock);
     50        torture_suite_add_2smb_test(suite, "notify", torture_raw_notify);
     51        torture_suite_add_1smb_test(suite, "mux", torture_raw_mux);
     52        torture_suite_add_1smb_test(suite, "ioctl", torture_raw_ioctl);
     53        torture_suite_add_1smb_test(suite, "chkpath", torture_raw_chkpath);
    5854        torture_suite_add_suite(suite, torture_raw_unlink(suite));
    5955        torture_suite_add_suite(suite, torture_raw_read(suite));
    6056        torture_suite_add_suite(suite, torture_raw_write(suite));
    6157        torture_suite_add_suite(suite, torture_raw_lock(suite));
    62         torture_suite_add_1smb_test(suite, "CONTEXT", torture_raw_context);
     58        torture_suite_add_1smb_test(suite, "context", torture_raw_context);
    6359        torture_suite_add_suite(suite, torture_raw_rename(suite));
    64         torture_suite_add_1smb_test(suite, "SEEK", torture_raw_seek);
    65         torture_suite_add_1smb_test(suite, "EAS", torture_raw_eas);
    66         torture_suite_add_1smb_test(suite, "STREAMS", torture_raw_streams);
    67         torture_suite_add_1smb_test(suite, "ACLS", torture_raw_acls);
    68         torture_suite_add_1smb_test(suite, "COMPOSITE", torture_raw_composite);
    69         torture_suite_add_simple_test(suite, "SAMBA3HIDE", torture_samba3_hide);
    70         torture_suite_add_simple_test(suite, "SAMBA3CLOSEERR", torture_samba3_closeerr);
    71         torture_suite_add_simple_test(suite, "SAMBA3ROOTDIRFID",
     60        torture_suite_add_1smb_test(suite, "seek", torture_raw_seek);
     61        torture_suite_add_1smb_test(suite, "eas", torture_raw_eas);
     62        torture_suite_add_suite(suite, torture_raw_streams(suite));
     63        torture_suite_add_suite(suite, torture_raw_acls(suite));
     64        torture_suite_add_1smb_test(suite, "composite", torture_raw_composite);
     65        torture_suite_add_simple_test(suite, "samba3hide", torture_samba3_hide);
     66        torture_suite_add_simple_test(suite, "samba3closeerr", torture_samba3_closeerr);
     67        torture_suite_add_simple_test(suite, "samba3rootdirfid",
    7268                                      torture_samba3_rootdirfid);
    73         torture_suite_add_simple_test(suite, "SAMBA3CHECKFSP", torture_samba3_checkfsp);
    74         torture_suite_add_simple_test(suite, "SAMBA3OPLOCKLOGOFF", torture_samba3_oplock_logoff);
    75         torture_suite_add_simple_test(suite, "SAMBA3BADPATH", torture_samba3_badpath);
    76         torture_suite_add_simple_test(suite, "SAMBA3CASEINSENSITIVE",
     69        torture_suite_add_simple_test(suite, "samba3checkfsp", torture_samba3_checkfsp);
     70        torture_suite_add_simple_test(suite, "samba3oplocklogoff", torture_samba3_oplock_logoff);
     71        torture_suite_add_simple_test(suite, "samba3badpath", torture_samba3_badpath);
     72        torture_suite_add_simple_test(suite, "samba3caseinsensitive",
    7773                                      torture_samba3_caseinsensitive);
    78         torture_suite_add_simple_test(suite, "SAMBA3POSIXTIMEDLOCK",
     74        torture_suite_add_simple_test(suite, "samba3posixtimedlock",
    7975                                      torture_samba3_posixtimedlock);
    80         torture_suite_add_simple_test(suite, "SCAN-EAMAX", torture_max_eas);
     76        torture_suite_add_simple_test(suite, "scan-eamax", torture_max_eas);
    8177
    8278        suite->description = talloc_strdup(suite, "Tests for the raw SMB interface");
  • trunk/server/source4/torture/raw/read.c

    r414 r745  
    1919
    2020#include "includes.h"
    21 #include "torture/torture.h"
    2221#include "libcli/raw/libcliraw.h"
    23 #include "libcli/raw/raw_proto.h"
    2422#include "system/time.h"
    2523#include "system/filesys.h"
     
    5553  setup a random buffer based on a seed
    5654*/
    57 static void setup_buffer(uint8_t *buf, uint_t seed, int len)
     55static void setup_buffer(uint8_t *buf, unsigned int seed, int len)
    5856{
    5957        int i;
     
    6563  check a random buffer based on a seed
    6664*/
    67 static bool check_buffer(uint8_t *buf, uint_t seed, int len, int line)
     65static bool check_buffer(uint8_t *buf, unsigned int seed, int len, int line)
    6866{
    6967        int i;
     
    9391        const char *fname = BASEDIR "\\test.txt";
    9492        const char *test_data = "TEST DATA";
    95         uint_t seed = time(NULL);
     93        unsigned int seed = time(NULL);
    9694
    9795        buf = talloc_zero_array(tctx, uint8_t, maxsize);
     96
     97        if (!torture_setting_bool(tctx, "read_support", true)) {
     98                printf("server refuses to support READ\n");
     99                return true;
     100        }
    98101
    99102        if (!torture_setup_dir(cli, BASEDIR)) {
     
    103106        printf("Testing RAW_READ_READ\n");
    104107        io.generic.level = RAW_READ_READ;
    105        
     108
    106109        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
    107110        if (fnum == -1) {
     
    220223        const char *fname = BASEDIR "\\test.txt";
    221224        const char *test_data = "TEST DATA";
    222         uint_t seed = time(NULL);
     225        unsigned int seed = time(NULL);
     226
     227        if (!cli->transport->negotiate.lockread_supported) {
     228                printf("Server does not support lockread - skipping\n");
     229                return true;
     230        }
    223231
    224232        buf = talloc_zero_array(tctx, uint8_t, maxsize);
     
    365373        const char *fname = BASEDIR "\\test.txt";
    366374        const char *test_data = "TEST DATA";
    367         uint_t seed = time(NULL);
     375        unsigned int seed = time(NULL);
    368376
    369377        buf = talloc_zero_array(tctx, uint8_t, maxsize);
     
    481489        memset(buf, 0, maxsize);
    482490
    483         printf("Trying large read\n");
     491        printf("Trying page sized read\n");
     492        io.readx.in.offset = 0;
     493        io.readx.in.mincnt = 0x1000;
     494        io.readx.in.maxcnt = 0x1000;
     495        status = smb_raw_read(cli->tree, &io);
     496        CHECK_STATUS(status, NT_STATUS_OK);
     497        CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
     498        CHECK_VALUE(io.readx.out.compaction_mode, 0);
     499        CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt);
     500        CHECK_BUFFER(buf, seed, io.readx.out.nread);
     501
     502        printf("Trying page + 1 sized read (check alignment)\n");
     503        io.readx.in.offset = 0;
     504        io.readx.in.mincnt = 0x1001;
     505        io.readx.in.maxcnt = 0x1001;
     506        status = smb_raw_read(cli->tree, &io);
     507        CHECK_STATUS(status, NT_STATUS_OK);
     508        CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
     509        CHECK_VALUE(io.readx.out.compaction_mode, 0);
     510        CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt);
     511        CHECK_BUFFER(buf, seed, io.readx.out.nread);
     512
     513        printf("Trying large read (UINT16_MAX)\n");
    484514        io.readx.in.offset = 0;
    485515        io.readx.in.mincnt = 0xFFFF;
     
    626656        const char *fname = BASEDIR "\\test.txt";
    627657        const char *test_data = "TEST DATA";
    628         uint_t seed = time(NULL);
     658        unsigned int seed = time(NULL);
    629659
    630660        if (!cli->transport->negotiate.readbraw_supported) {
     
    816846
    817847        op.generic.level = RAW_OPEN_NTCREATEX;
    818         op.ntcreatex.in.root_fid = 0;
     848        op.ntcreatex.in.root_fid.fnum = 0;
    819849        op.ntcreatex.in.flags = 0;
    820850        op.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    847877        printf("open file with SEC_FILE_EXECUTE\n");
    848878        op.generic.level = RAW_OPEN_NTCREATEX;
    849         op.ntcreatex.in.root_fid = 0;
     879        op.ntcreatex.in.root_fid.fnum = 0;
    850880        op.ntcreatex.in.flags = 0;
    851881        op.ntcreatex.in.access_mask = SEC_FILE_EXECUTE;
     
    894924        printf("open file with SEC_FILE_READ_DATA\n");
    895925        op.generic.level = RAW_OPEN_NTCREATEX;
    896         op.ntcreatex.in.root_fid = 0;
     926        op.ntcreatex.in.root_fid.fnum = 0;
    897927        op.ntcreatex.in.flags = 0;
    898928        op.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
     
    951981struct torture_suite *torture_raw_read(TALLOC_CTX *mem_ctx)
    952982{
    953         struct torture_suite *suite = torture_suite_create(mem_ctx, "READ");
     983        struct torture_suite *suite = torture_suite_create(mem_ctx, "read");
    954984
    955985        torture_suite_add_1smb_test(suite, "read", test_read);
     
    958988        torture_suite_add_1smb_test(suite, "readbraw", test_readbraw);
    959989        torture_suite_add_1smb_test(suite, "read for execute",
    960                                                                 test_read_for_execute);
     990                test_read_for_execute);
    961991
    962992        return suite;
  • trunk/server/source4/torture/raw/rename.c

    r414 r745  
    1919
    2020#include "includes.h"
    21 #include "torture/torture.h"
    22 #include "libcli/raw/libcliraw.h"
    2321#include "libcli/libcli.h"
    2422#include "torture/util.h"
     
    6866
    6967        op.generic.level = RAW_OPEN_NTCREATEX;
    70         op.ntcreatex.in.root_fid = 0;
     68        op.ntcreatex.in.root_fid.fnum = 0;
    7169        op.ntcreatex.in.flags = 0;
    7270        op.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    209207        }
    210208        op.generic.level = RAW_OPEN_NTCREATEX;
    211         op.ntcreatex.in.root_fid = 0;
     209        op.ntcreatex.in.root_fid.fnum = 0;
    212210        op.ntcreatex.in.flags = 0;
    213211        op.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
     
    308306        CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
    309307       
    310         smb_raw_exit(cli->session);
     308        smbcli_close(cli->tree, fnum);
    311309        status = smb_raw_rename(cli->tree, &io);
    312310        CHECK_STATUS(status, NT_STATUS_OK);
     
    429427        io.ntrename.in.flags = 0;
    430428        status = smb_raw_rename(cli->tree, &io);
    431         CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
     429        if (TARGET_IS_WIN7(tctx)) {
     430                CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
     431        } else {
     432                CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
     433        }
    432434
    433435        io.ntrename.in.flags = 300;
    434436        status = smb_raw_rename(cli->tree, &io);
    435         CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
     437        if (TARGET_IS_WIN7(tctx)) {
     438                CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
     439        } else {
     440                CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
     441        }
    436442
    437443        io.ntrename.in.flags = 0x106;
    438444        status = smb_raw_rename(cli->tree, &io);
    439         CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
     445        if (TARGET_IS_WIN7(tctx)) {
     446                CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
     447        } else {
     448                CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
     449        }
    440450
    441451        torture_comment(tctx, "Checking unknown field\n");
     
    508518                io.ntrename.in.cluster_size = 0;
    509519                status = smb_raw_rename(cli->tree, &io);
    510                 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
    511                         torture_warning(tctx, "flags=0x%x status=%s\n", i, nt_errstr(status));
     520                if (TARGET_IS_WIN7(tctx)){
     521                        if (!NT_STATUS_EQUAL(status,
     522                                             NT_STATUS_INVALID_PARAMETER)) {
     523                                torture_warning(tctx, "flags=0x%x status=%s\n",
     524                                                i, nt_errstr(status));
     525                        }
     526                } else {
     527                        if (!NT_STATUS_EQUAL(status,
     528                                             NT_STATUS_ACCESS_DENIED)) {
     529                                torture_warning(tctx, "flags=0x%x status=%s\n",
     530                                                i, nt_errstr(status));
     531                        }
    512532                }
    513533        }
     
    578598        io.generic.level = RAW_OPEN_NTCREATEX;
    579599        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
    580         io.ntcreatex.in.root_fid = 0;
     600        io.ntcreatex.in.root_fid.fnum = 0;
    581601        io.ntcreatex.in.alloc_size = 0;
    582602        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     
    698718struct torture_suite *torture_raw_rename(TALLOC_CTX *mem_ctx)
    699719{
    700         struct torture_suite *suite = torture_suite_create(mem_ctx, "RENAME");
     720        struct torture_suite *suite = torture_suite_create(mem_ctx, "rename");
    701721
    702722        torture_suite_add_1smb_test(suite, "mv", test_mv);
  • trunk/server/source4/torture/raw/samba3hide.c

    r414 r745  
    1919
    2020#include "includes.h"
    21 #include "torture/torture.h"
    22 #include "libcli/raw/libcliraw.h"
    2321#include "system/time.h"
    2422#include "system/filesys.h"
     
    138136                    torture, &cli, torture, torture_setting_string(torture, "host", NULL),
    139137                    torture_setting_string(torture, "share", NULL), torture->ev)) {
    140                 d_printf("torture_open_connection_share failed\n");
    141                 return false;
     138                torture_fail(torture, "torture_open_connection_share failed\n");
    142139        }
    143140
    144141        status = torture_second_tcon(torture, cli->session, "hideunread",
    145142                                     &hideunread);
    146         if (!NT_STATUS_IS_OK(status)) {
    147                 d_printf("second_tcon(hideunread) failed: %s\n",
    148                          nt_errstr(status));
    149                 return false;
    150         }
     143        torture_assert_ntstatus_ok(torture, status, "second_tcon(hideunread) failed\n");
    151144
    152145        status = torture_second_tcon(torture, cli->session, "hideunwrite",
    153146                                     &hideunwrite);
    154         if (!NT_STATUS_IS_OK(status)) {
    155                 d_printf("second_tcon(hideunwrite) failed: %s\n",
    156                          nt_errstr(status));
    157                 return false;
    158         }
     147        torture_assert_ntstatus_ok(torture, status, "second_tcon(hideunwrite) failed\n");
    159148
    160149        status = smbcli_unlink(cli->tree, fname);
     
    166155        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
    167156        if (fnum == -1) {
    168                 d_printf("Failed to create %s - %s\n", fname,
    169                          smbcli_errstr(cli->tree));
    170                 return false;
     157                torture_fail(torture,
     158                        talloc_asprintf(torture, "Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree)));
    171159        }
    172160
     
    174162
    175163        if (!smbcli_file_exists(cli->tree, fname)) {
    176                 d_printf("%s does not exist\n", fname);
    177                 return false;
     164                torture_fail(torture, talloc_asprintf(torture, "%s does not exist\n", fname));
    178165        }
    179166
     
    181168
    182169        status = smbcli_chmod(cli->tree, fname, UNIX_R_USR|UNIX_W_USR);
    183         if (!NT_STATUS_IS_OK(status)) {
    184                 d_printf("smbcli_chmod failed: %s\n", nt_errstr(status));
    185                 return false;
    186         }
     170        torture_assert_ntstatus_ok(torture, status, "smbcli_chmod failed\n");
     171
    187172        if (!is_writeable(torture, cli->tree, fname)) {
    188                 d_printf("File not writable\n");
    189                 return false;
     173                torture_fail(torture, "File not writable\n");
    190174        }
    191175        if (!is_readable(cli->tree, fname)) {
    192                 d_printf("File not readable\n");
    193                 return false;
     176                torture_fail(torture, "File not readable\n");
    194177        }
    195178        if (!is_visible(cli->tree, fname)) {
    196                 d_printf("r/w file not visible via normal share\n");
    197                 return false;
     179                torture_fail(torture, "r/w file not visible via normal share\n");
    198180        }
    199181        if (!is_visible(hideunread, fname)) {
    200                 d_printf("r/w file not visible via hide unreadable\n");
    201                 return false;
     182                torture_fail(torture, "r/w file not visible via hide unreadable\n");
    202183        }
    203184        if (!is_visible(hideunwrite, fname)) {
    204                 d_printf("r/w file not visible via hide unwriteable\n");
    205                 return false;
     185                torture_fail(torture, "r/w file not visible via hide unwriteable\n");
    206186        }
    207187
     
    209189
    210190        status = smbcli_chmod(cli->tree, fname, UNIX_R_USR);
    211 
    212         if (!NT_STATUS_IS_OK(status)) {
    213                 d_printf("smbcli_chmod failed: %s\n", nt_errstr(status));
    214                 return false;
    215         }
     191        torture_assert_ntstatus_ok(torture, status, "smbcli_chmod failed\n");
     192
    216193        if (is_writeable(torture, cli->tree, fname)) {
    217                 d_printf("r/o is writable\n");
    218                 return false;
     194                torture_fail(torture, "r/o is writable\n");
    219195        }
    220196        if (!is_readable(cli->tree, fname)) {
    221                 d_printf("r/o not readable\n");
    222                 return false;
     197                torture_fail(torture, "r/o not readable\n");
    223198        }
    224199        if (!is_visible(cli->tree, fname)) {
    225                 d_printf("r/o file not visible via normal share\n");
    226                 return false;
     200                torture_fail(torture, "r/o file not visible via normal share\n");
    227201        }
    228202        if (!is_visible(hideunread, fname)) {
    229                 d_printf("r/o file not visible via hide unreadable\n");
    230                 return false;
     203                torture_fail(torture, "r/o file not visible via hide unreadable\n");
    231204        }
    232205        if (is_visible(hideunwrite, fname)) {
    233                 d_printf("r/o file visible via hide unwriteable\n");
    234                 return false;
     206                torture_fail(torture, "r/o file visible via hide unwriteable\n");
    235207        }
    236208
     
    238210
    239211        status = smbcli_chmod(cli->tree, fname, 0);
    240         if (!NT_STATUS_IS_OK(status)) {
    241                 d_printf("smbcli_chmod failed: %s\n", nt_errstr(status));
    242                 return false;
    243         }
     212        torture_assert_ntstatus_ok(torture, status, "smbcli_chmod failed\n");
     213
    244214        if (is_writeable(torture, cli->tree, fname)) {
    245                 d_printf("inaccessible file is writable\n");
    246                 return false;
     215                torture_fail(torture, "inaccessible file is writable\n");
    247216        }
    248217        if (is_readable(cli->tree, fname)) {
    249                 d_printf("inaccessible file is readable\n");
    250                 return false;
     218                torture_fail(torture, "inaccessible file is readable\n");
    251219        }
    252220        if (!is_visible(cli->tree, fname)) {
    253                 d_printf("inaccessible file not visible via normal share\n");
    254                 return false;
     221                torture_fail(torture, "inaccessible file not visible via normal share\n");
    255222        }
    256223        if (is_visible(hideunread, fname)) {
    257                 d_printf("inaccessible file visible via hide unreadable\n");
    258                 return false;
     224                torture_fail(torture, "inaccessible file visible via hide unreadable\n");
    259225        }
    260226        if (is_visible(hideunwrite, fname)) {
    261                 d_printf("inaccessible file visible via hide unwriteable\n");
    262                 return false;
     227                torture_fail(torture, "inaccessible file visible via hide unwriteable\n");
    263228        }
    264229
  • trunk/server/source4/torture/raw/samba3misc.c

    r414 r745  
    9191                io.generic.level = RAW_OPEN_NTCREATEX;
    9292                io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
    93                 io.ntcreatex.in.root_fid = 0;
     93                io.ntcreatex.in.root_fid.fnum = 0;
    9494                io.ntcreatex.in.security_flags = 0;
    9595                io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
     
    163163{
    164164        union smb_open open_parms;
    165         uint_t openfn=0;
    166         uint_t accessmode=0;
     165        unsigned int openfn=0;
     166        unsigned int accessmode=0;
    167167        TALLOC_CTX *mem_ctx;
    168168        NTSTATUS status;
     
    226226{
    227227        union smb_open io;
    228         uint_t openfn=0;
    229         uint_t accessmode=0;
     228        unsigned int openfn=0;
     229        unsigned int accessmode=0;
    230230        TALLOC_CTX *mem_ctx;
    231231        NTSTATUS status;
     
    305305        io.generic.level = RAW_OPEN_NTCREATEX;
    306306        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
    307         io.ntcreatex.in.root_fid = 0;
     307        io.ntcreatex.in.root_fid.fnum = 0;
    308308        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
    309309        io.ntcreatex.in.alloc_size = 0;
     
    347347        }
    348348
    349         nt_status_support = lp_nt_status_support(torture->lp_ctx);
    350 
    351         if (!lp_set_cmdline(torture->lp_ctx, "nt status support", "yes")) {
     349        nt_status_support = lpcfg_nt_status_support(torture->lp_ctx);
     350
     351        if (!lpcfg_set_cmdline(torture->lp_ctx, "nt status support", "yes")) {
    352352                printf("Could not set 'nt status support = yes'\n");
    353353                goto fail;
     
    358358        }
    359359
    360         if (!lp_set_cmdline(torture->lp_ctx, "nt status support", "no")) {
     360        if (!lpcfg_set_cmdline(torture->lp_ctx, "nt status support", "no")) {
    361361                printf("Could not set 'nt status support = yes'\n");
    362362                goto fail;
     
    367367        }
    368368
    369         if (!lp_set_cmdline(torture->lp_ctx, "nt status support",
     369        if (!lpcfg_set_cmdline(torture->lp_ctx, "nt status support",
    370370                            nt_status_support ? "yes":"no")) {
    371371                printf("Could not reset 'nt status support = yes'");
     
    622622        int fnum;
    623623        int counter = 0;
    624         bool ret = true;
     624        bool ret = false;
    625625
    626626        if (!(mem_ctx = talloc_init("torture_samba3_caseinsensitive"))) {
     
    636636
    637637        status = smbcli_mkdir(cli->tree, dirname);
     638        torture_assert_ntstatus_ok(torture, status, "smbcli_mkdir failed");
    638639        if (!NT_STATUS_IS_OK(status)) {
    639                 d_printf("smbcli_mkdir failed: %s\n", nt_errstr(status));
    640640                goto done;
    641641        }
     
    646646        fnum = smbcli_open(cli->tree, fpath, O_RDWR | O_CREAT, DENY_NONE);
    647647        if (fnum == -1) {
    648                 d_printf("Could not create file %s: %s\n", fpath,
     648                torture_result(torture, TORTURE_FAIL,
     649                        "Could not create file %s: %s", fpath,
    649650                         smbcli_errstr(cli->tree));
    650651                goto done;
     
    662663        }
    663664        else {
    664                 d_fprintf(stderr, "expected 3 entries, got %d\n", counter);
     665                torture_result(torture, TORTURE_FAIL,
     666                        "expected 3 entries, got %d", counter);
    665667                ret = false;
    666668        }
     
    888890        io.generic.level = RAW_OPEN_NTCREATEX;
    889891        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
    890         io.ntcreatex.in.root_fid = 0;
     892        io.ntcreatex.in.root_fid.fnum = 0;
    891893        io.ntcreatex.in.security_flags = 0;
    892894        io.ntcreatex.in.access_mask =
     
    913915                NTCREATEX_FLAGS_REQUEST_OPLOCK
    914916                | NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
    915         io.ntcreatex.in.root_fid = dnum;
     917        io.ntcreatex.in.root_fid.fnum = dnum;
    916918        io.ntcreatex.in.security_flags = 0;
    917919        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
     
    962964        io.generic.level = RAW_OPEN_NTCREATEX;
    963965        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
    964         io.ntcreatex.in.root_fid = 0;
     966        io.ntcreatex.in.root_fid.fnum = 0;
    965967        io.ntcreatex.in.security_flags = 0;
    966968        io.ntcreatex.in.access_mask =
     
    10081010        echo_req.in.repeat_count = 1;
    10091011        echo_req.in.size = 1;
    1010         echo_req.in.data = (uint8_t *)"";
     1012        echo_req.in.data = discard_const_p(uint8_t, "");
    10111013
    10121014        status = smb_raw_echo(cli->session->transport, &echo_req);
  • trunk/server/source4/torture/raw/search.c

    r414 r745  
    1919
    2020#include "includes.h"
    21 #include "torture/torture.h"
    2221#include "system/filesys.h"
    2322#include "libcli/raw/libcliraw.h"
     
    2524#include "libcli/libcli.h"
    2625#include "torture/util.h"
     26#include "lib/util/tsort.h"
    2727
    2828
    2929#define BASEDIR "\\testsearch"
     30
     31#define CHECK_STATUS_LEVEL(__tctx, __status, __level, __supp)           \
     32        do {                                                            \
     33                if (NT_STATUS_EQUAL(__status,                           \
     34                        NT_STATUS_NOT_SUPPORTED) ||                     \
     35                    NT_STATUS_EQUAL(__status,                           \
     36                        NT_STATUS_NOT_IMPLEMENTED)) {                   \
     37                        torture_warning(__tctx, "(%s) Info "            \
     38                            "level "#__level" is %s",                   \
     39                            __location__, nt_errstr(__status));         \
     40                        __supp = false;                                 \
     41                } else {                                                \
     42                        torture_assert_ntstatus_ok_goto(__tctx,         \
     43                            __status, ret, done, #__level" failed");    \
     44                        __supp = true;                                  \
     45                }                                                       \
     46        } while (0)
    3047
    3148/*
     
    243260        int i;
    244261        union smb_fileinfo all_info, alt_info, name_info, internal_info;
     262        bool all_info_supported, alt_info_supported, name_info_supported,
     263            internal_info_supported;
    245264        union smb_search_data *s;
    246265
     
    257276                uint32_t cap = cli->transport->negotiate.capabilities;
    258277
    259                 torture_comment(tctx, "testing %s\n", levels[i].name);
     278                torture_comment(tctx, "Testing %s\n", levels[i].name);
    260279
    261280                levels[i].status = torture_single_search(cli, tctx, fname,
     
    266285
    267286                /* see if this server claims to support this level */
    268                 if ((cap & levels[i].capability_mask) != levels[i].capability_mask) {
     287                if (((cap & levels[i].capability_mask) != levels[i].capability_mask)
     288                    || NT_STATUS_EQUAL(levels[i].status, NT_STATUS_NOT_SUPPORTED)) {
    269289                        printf("search level %s(%d) not supported by server\n",
    270290                               levels[i].name, (int)levels[i].level);
     
    305325        all_info.generic.in.file.path = fname;
    306326        status = smb_raw_pathinfo(cli->tree, tctx, &all_info);
    307         torture_assert_ntstatus_ok(tctx, status, "RAW_FILEINFO_ALL_INFO failed");
     327        CHECK_STATUS_LEVEL(tctx, status, "RAW_FILEINFO_ALL_INFO",
     328            all_info_supported);
    308329
    309330        alt_info.generic.level = RAW_FILEINFO_ALT_NAME_INFO;
    310331        alt_info.generic.in.file.path = fname;
    311332        status = smb_raw_pathinfo(cli->tree, tctx, &alt_info);
    312         torture_assert_ntstatus_ok(tctx, status, "RAW_FILEINFO_ALT_NAME_INFO failed");
     333        CHECK_STATUS_LEVEL(tctx, status, "RAW_FILEINFO_ALT_NAME_INFO",
     334            alt_info_supported);
    313335
    314336        internal_info.generic.level = RAW_FILEINFO_INTERNAL_INFORMATION;
    315337        internal_info.generic.in.file.path = fname;
    316338        status = smb_raw_pathinfo(cli->tree, tctx, &internal_info);
    317         torture_assert_ntstatus_ok(tctx, status, "RAW_FILEINFO_INTERNAL_INFORMATION failed");
     339        CHECK_STATUS_LEVEL(tctx, status, "RAW_FILEINFO_INTERNAL_INFORMATION",
     340            internal_info_supported);
    318341
    319342        name_info.generic.level = RAW_FILEINFO_NAME_INFO;
    320343        name_info.generic.in.file.path = fname;
    321344        status = smb_raw_pathinfo(cli->tree, tctx, &name_info);
    322         torture_assert_ntstatus_ok(tctx, status, "RAW_FILEINFO_NAME_INFO failed");
     345        CHECK_STATUS_LEVEL(tctx, status, "RAW_FILEINFO_NAME_INFO",
     346            name_info_supported);
    323347
    324348#define CHECK_VAL(name, sname1, field1, v, sname2, field2) do { \
     
    478502        CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info,           ea_size, all_info, all_info, ea_size);
    479503
    480         CHECK_STR("SEARCH", search, name, alt_info, alt_name_info, fname);
    481         CHECK_WSTR("BOTH_DIRECTORY_INFO", both_directory_info, short_name, alt_info, alt_name_info, fname, STR_UNICODE);
     504        if (alt_info_supported) {
     505                CHECK_STR("SEARCH", search, name, alt_info, alt_name_info,
     506                    fname);
     507                CHECK_WSTR("BOTH_DIRECTORY_INFO", both_directory_info,
     508                    short_name, alt_info, alt_name_info, fname, STR_UNICODE);
     509        }
    482510
    483511        CHECK_NAME("STANDARD",            standard,            name, fname+1, 0);
     
    485513        CHECK_NAME("DIRECTORY_INFO",      directory_info,      name, fname+1, STR_TERMINATE_ASCII);
    486514        CHECK_NAME("FULL_DIRECTORY_INFO", full_directory_info, name, fname+1, STR_TERMINATE_ASCII);
    487         CHECK_NAME("NAME_INFO",           name_info,           name, fname+1, STR_TERMINATE_ASCII);
     515
     516        if (name_info_supported) {
     517                CHECK_NAME("NAME_INFO", name_info, name, fname+1,
     518                    STR_TERMINATE_ASCII);
     519        }
     520
    488521        CHECK_NAME("BOTH_DIRECTORY_INFO", both_directory_info, name, fname+1, STR_TERMINATE_ASCII);
    489522        CHECK_NAME("ID_FULL_DIRECTORY_INFO", id_full_directory_info,           name, fname+1, STR_TERMINATE_ASCII);
     
    491524        CHECK_UNIX_NAME("UNIX_INFO",           unix_info,           name, fname+1, STR_TERMINATE_ASCII);
    492525
    493         CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info, file_id, internal_info, internal_information, file_id);
    494         CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info, file_id, internal_info, internal_information, file_id);
     526        if (internal_info_supported) {
     527                CHECK_VAL("ID_FULL_DIRECTORY_INFO", id_full_directory_info,
     528                    file_id, internal_info, internal_information, file_id);
     529                CHECK_VAL("ID_BOTH_DIRECTORY_INFO", id_both_directory_info,
     530                    file_id, internal_info, internal_information, file_id);
     531        }
    495532
    496533done:
     
    713750                if ((search_types[t].cont_type == CONT_RESUME_KEY) &&
    714751                    (search_types[t].data_level != RAW_SEARCH_DATA_SEARCH) &&
    715                     torture_setting_bool(tctx, "samba3", false)) {
     752                    !torture_setting_bool(tctx, "resume_key_support", true)) {
    716753                        torture_comment(tctx,
    717754                                        "SKIP: Continue %s via %s\n",
     
    729766                                         search_types[t].cont_type,
    730767                                         &result);
    731        
     768                if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
     769                        torture_warning(tctx, "search level %s not supported "
     770                                        "by server",
     771                                        search_types[t].name);
     772                        continue;
     773                }
    732774                torture_assert_ntstatus_ok(tctx, status, "search failed");
    733775                CHECK_VALUE(result.count, num_files);
     
    735777                compare_data_level = search_types[t].data_level;
    736778
    737                 qsort(result.list, result.count, sizeof(result.list[0]),
    738                       QSORT_CAST  search_compare);
     779                TYPESAFE_QSORT(result.list, result.count, search_compare);
    739780
    740781                for (i=0;i<result.count;i++) {
     
    9921033        union smb_search_data *file, *file2, *file3;
    9931034
     1035        if (!torture_setting_bool(tctx, "raw_search_search", true)) {
     1036                torture_comment(tctx, "Skipping these tests as the server "
     1037                        "doesn't support old style search calls\n");
     1038                return true;
     1039        }
    9941040        if (!torture_setup_dir(cli, BASEDIR)) {
    9951041                return false;
     
    11241170                }
    11251171
    1126                 if (strcmp(file3[i].search.name, file2[i].search.name) != 0) {
     1172                if (torture_setting_bool(tctx, "rewind_support", true) &&
     1173                    strcmp(file3[i].search.name, file2[i].search.name) != 0) {
    11271174                        printf("(%s) server did not rewind - got '%s' expected '%s'\n",
    11281175                               __location__, file3[i].search.name, file2[i].search.name);
     
    11601207        struct multiple_result result;
    11611208
     1209        if (!torture_setting_bool(tctx, "search_ea_size", true)){
     1210                torture_comment(tctx,
     1211                                "Server does not support RAW_SEARCH_EA_SIZE "
     1212                                "level. Skipping this test\n");
     1213                return true;
     1214        }
     1215
    11621216        if (!torture_setup_dir(cli, BASEDIR)) {
    11631217                return false;
     
    12741328
    12751329        printf("Testing RAW_SEARCH_EA_LIST level\n");
     1330
     1331        if (!torture_setting_bool(tctx, "search_ea_support", true) ||
     1332            !torture_setting_bool(tctx, "ea_support", true)) {
     1333                printf("..skipped per target configuration.\n");
     1334                return true;
     1335        }
    12761336
    12771337        fnum = smbcli_open(cli->tree, BASEDIR "\\file1.txt", O_CREAT|O_RDWR, DENY_NONE);
     
    13401400        /* we have to sort the result as different servers can return directories
    13411401           in different orders */
    1342         qsort(result.list, result.count, sizeof(result.list[0]),
    1343               (comparison_fn_t)ealist_cmp);
     1402        TYPESAFE_QSORT(result.list, result.count, ealist_cmp);
    13441403
    13451404        CHECK_VALUE(result.count, 3);
     
    13711430}
    13721431
    1373 
     1432/*
     1433 Test the behavior of max count parameter in TRANS2_FIND_FIRST2 and
     1434 TRANS2_FIND_NEXT2 queries
     1435*/
     1436static bool test_max_count(struct torture_context *tctx,
     1437                           struct smbcli_state *cli)
     1438{
     1439        const int num_files = 2;
     1440        int i, fnum;
     1441        char *fname;
     1442        bool ret = true;
     1443        NTSTATUS status;
     1444        struct multiple_result result;
     1445        union smb_search_first io;
     1446        union smb_search_next io2;
     1447
     1448        if (!torture_setup_dir(cli, BASEDIR)) {
     1449                return false;
     1450        }
     1451
     1452        torture_comment(tctx, "Creating %d files\n", num_files);
     1453
     1454        for (i=num_files-1;i>=0;i--) {
     1455                fname = talloc_asprintf(cli, BASEDIR "\\t%03d-%d.txt", i, i);
     1456                fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR, DENY_NONE);
     1457                if (fnum == -1) {
     1458                        torture_comment(tctx,
     1459                                "Failed to create %s - %s\n",
     1460                                fname, smbcli_errstr(cli->tree));
     1461                        ret = false;
     1462                        goto done;
     1463                }
     1464                talloc_free(fname);
     1465                smbcli_close(cli->tree, fnum);
     1466        }
     1467
     1468        torture_comment(tctx, "Set max_count parameter to 0. "
     1469                        "This should return 1 entry\n");
     1470        ZERO_STRUCT(result);
     1471        result.tctx = talloc_new(tctx);
     1472
     1473        io.t2ffirst.level = RAW_SEARCH_TRANS2;
     1474        io.t2ffirst.data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO;
     1475        io.t2ffirst.in.search_attrib = 0;
     1476        io.t2ffirst.in.max_count = 0;
     1477        io.t2ffirst.in.flags = 0;
     1478        io.t2ffirst.in.storage_type = 0;
     1479        io.t2ffirst.in.pattern = BASEDIR "\\*.*";
     1480
     1481        status = smb_raw_search_first(cli->tree, tctx,
     1482                                      &io, &result, multiple_search_callback);
     1483        CHECK_STATUS(status, NT_STATUS_OK);
     1484        CHECK_VALUE(result.count, 1);
     1485
     1486        torture_comment(tctx, "Set max_count to 1. This should also "
     1487                        "return 1 entry\n");
     1488        io2.t2fnext.level = RAW_SEARCH_TRANS2;
     1489        io2.t2fnext.data_level = RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO;
     1490        io2.t2fnext.in.handle = io.t2ffirst.out.handle;
     1491        io2.t2fnext.in.max_count = 1;
     1492        io2.t2fnext.in.resume_key = 0;
     1493        io2.t2fnext.in.flags = 0;
     1494        io2.t2fnext.in.last_name =
     1495                result.list[result.count-1].both_directory_info.name.s;
     1496
     1497        status = smb_raw_search_next(cli->tree, tctx,
     1498                                     &io2, &result, multiple_search_callback);
     1499        CHECK_STATUS(status, NT_STATUS_OK);
     1500        CHECK_VALUE(result.count, 2);
     1501done:
     1502        smb_raw_exit(cli->session);
     1503        smbcli_deltree(cli->tree, BASEDIR);
     1504
     1505        return ret;
     1506}
    13741507
    13751508/*
     
    13781511struct torture_suite *torture_raw_search(TALLOC_CTX *mem_ctx)
    13791512{
    1380         struct torture_suite *suite = torture_suite_create(mem_ctx, "SEARCH");
     1513        struct torture_suite *suite = torture_suite_create(mem_ctx, "search");
    13811514
    13821515        torture_suite_add_1smb_test(suite, "one file search", test_one_file);
     
    13871520        torture_suite_add_1smb_test(suite, "os2 delete", test_os2_delete);
    13881521        torture_suite_add_1smb_test(suite, "ea list", test_ea_list);
     1522        torture_suite_add_1smb_test(suite, "max count", test_max_count);
    13891523
    13901524        return suite;
  • trunk/server/source4/torture/raw/seek.c

    r414 r745  
    1919
    2020#include "includes.h"
    21 #include "torture/torture.h"
    2221#include "system/filesys.h"
    23 #include "libcli/raw/libcliraw.h"
    2422#include "libcli/libcli.h"
    2523#include "torture/util.h"
  • trunk/server/source4/torture/raw/setfileinfo.c

    r414 r745  
    1919
    2020#include "includes.h"
    21 #include "torture/torture.h"
    2221#include "system/time.h"
    2322#include "libcli/raw/libcliraw.h"
    24 #include "libcli/raw/raw_proto.h"
    2523#include "libcli/libcli.h"
    2624#include "torture/util.h"
    27 #include "torture/raw/proto.h"
    2825
    2926#define BASEDIR "\\testsfileinfo"
     
    3330   for consistency between the calls.
    3431*/
    35 bool torture_raw_sfileinfo(struct torture_context *torture,
    36                           struct smbcli_state *cli)
     32static bool
     33torture_raw_sfileinfo_base(struct torture_context *torture, struct smbcli_state *cli)
    3734{
    3835        bool ret = true;
     
    8380        sfinfo.generic.in.file.fnum = fnum; \
    8481        status = smb_raw_setfileinfo(cli->tree, &sfinfo); \
    85         if (!NT_STATUS_EQUAL(status, rightstatus)) { \
     82        if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) { \
     83                torture_warning(torture, \
     84                        "(%s) %s - %s", __location__, #call, \
     85                        nt_errstr(status)); \
     86        } else if (!NT_STATUS_EQUAL(status, rightstatus)) { \
    8687                printf("(%s) %s - %s (should be %s)\n", __location__, #call, \
    8788                        nt_errstr(status), nt_errstr(rightstatus)); \
     
    9192        finfo1.generic.in.file.fnum = fnum; \
    9293        status2 = smb_raw_fileinfo(cli->tree, torture, &finfo1); \
    93         if (!NT_STATUS_IS_OK(status2)) { \
     94        if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) { \
     95                torture_warning(torture, \
     96                        "(%s) %s - %s", __location__, #call, \
     97                        nt_errstr(status)); \
     98        } else if (!NT_STATUS_IS_OK(status2)) { \
    9499                printf("(%s) %s pathinfo - %s\n", __location__, #call, nt_errstr(status)); \
    95100                ret = false; \
     
    106111                status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
    107112        } \
    108         if (!NT_STATUS_EQUAL(status, rightstatus)) { \
     113        if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) { \
     114                torture_warning(torture, \
     115                        "(%s) %s - %s", __location__, #call, \
     116                        nt_errstr(status)); \
     117        } else if (!NT_STATUS_EQUAL(status, rightstatus)) { \
    109118                printf("(%s) %s - %s (should be %s)\n", __location__, #call, \
    110119                        nt_errstr(status), nt_errstr(rightstatus)); \
     
    118127                status2 = smb_raw_pathinfo(cli->tree, torture, &finfo1); \
    119128        } \
    120         if (!NT_STATUS_IS_OK(status2)) { \
     129        if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) { \
     130                torture_warning(torture, \
     131                        "(%s) %s - %s", __location__, #call, \
     132                        nt_errstr(status)); \
     133        } else if (!NT_STATUS_IS_OK(status2)) { \
    121134                printf("(%s) %s pathinfo - %s\n", __location__, #call, nt_errstr(status2)); \
    122135                ret = false; \
     
    148161                printf("(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
    149162                       call_name, #stype, #field, \
    150                        (uint_t)value, (uint_t)finfo2.stype.out.field); \
     163                       (unsigned int)value, (unsigned int)finfo2.stype.out.field); \
    151164                dump_all_info(torture, &finfo1); \
    152165                ret = false; \
     
    158171                printf("(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
    159172                        call_name, #stype, #field, \
    160                         (uint_t)value, \
    161                         (uint_t)nt_time_to_unix(finfo2.stype.out.field)); \
     173                        (unsigned int)value, \
     174                        (unsigned int)nt_time_to_unix(finfo2.stype.out.field)); \
    162175                printf("\t%s", timestring(torture, value)); \
    163176                printf("\t%s\n", nt_time_string(torture, finfo2.stype.out.field)); \
     
    186199
    187200       
    188         printf("test setattr\n");
     201        printf("Test setattr\n");
    189202        sfinfo.setattr.in.attrib = FILE_ATTRIBUTE_READONLY;
    190203        sfinfo.setattr.in.write_time = basetime;
     
    207220        CHECK_TIME (ALL_INFO, all_info, write_time, basetime);
    208221
    209         printf("test setattre\n");
     222        printf("Test setattre\n");
    210223        sfinfo.setattre.in.create_time = basetime + 20;
    211224        sfinfo.setattre.in.access_time = basetime + 30;
     
    224237        CHECK_TIME(ALL_INFO, all_info, write_time,  basetime + 40);
    225238
    226         printf("test standard level\n");
     239        printf("Test standard level\n");
    227240        sfinfo.standard.in.create_time = basetime + 100;
    228241        sfinfo.standard.in.access_time = basetime + 200;
     
    233246        CHECK_TIME(ALL_INFO, all_info, write_time,  basetime + 300);
    234247
    235         printf("test basic_info level\n");
     248        printf("Test basic_info level\n");
    236249        basetime += 86400;
    237250        unix_to_nt_time(&sfinfo.basic_info.in.create_time, basetime + 100);
     
    260273        CHECK_VALUE(ALL_INFO, all_info, attrib,     FILE_ATTRIBUTE_READONLY);
    261274
    262         printf("test basic_information level\n");
     275        printf("Test basic_information level\n");
    263276        basetime += 86400;
    264277        unix_to_nt_time(&sfinfo.basic_info.in.create_time, basetime + 100);
     
    281294        CHECK_VALUE(ALL_INFO, all_info, attrib,     FILE_ATTRIBUTE_NORMAL);
    282295
     296        torture_comment(torture, "try to change a file to a directory\n");
     297        sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
     298        CHECK_CALL_FNUM(BASIC_INFO, NT_STATUS_INVALID_PARAMETER);
     299
    283300        printf("a zero time means don't change\n");
    284301        unix_to_nt_time(&sfinfo.basic_info.in.create_time, 0);
     
    305322        CHECK_VALUE(ALL_INFO, all_info, attrib,     FILE_ATTRIBUTE_NORMAL);
    306323
    307         printf("test disposition_info level\n");
     324        printf("Test disposition_info level\n");
    308325        sfinfo.disposition_info.in.delete_on_close = 1;
    309326        CHECK_CALL_FNUM(DISPOSITION_INFO, NT_STATUS_OK);
     
    316333        CHECK_VALUE(ALL_INFO, all_info, nlink, 1);
    317334
    318         printf("test disposition_information level\n");
     335        printf("Test disposition_information level\n");
    319336        sfinfo.disposition_info.in.delete_on_close = 1;
    320337        CHECK_CALL_FNUM(DISPOSITION_INFORMATION, NT_STATUS_OK);
     
    338355        CHECK_VALUE(ALL_INFO, all_info, nlink, 1);
    339356
    340         printf("test allocation_info level\n");
     357        printf("Test allocation_info level\n");
    341358        sfinfo.allocation_info.in.alloc_size = 0;
    342359        CHECK_CALL_FNUM(ALLOCATION_INFO, NT_STATUS_OK);
     
    370387        CHECK_VALUE(ALL_INFO, all_info, size, 0);
    371388
    372         printf("test end_of_file_info level\n");
     389        printf("Test end_of_file_info level\n");
    373390        sfinfo.end_of_file_info.in.size = 37;
    374391        CHECK_CALL_FNUM(END_OF_FILE_INFO, NT_STATUS_OK);
     
    393410        CHECK_VALUE(ALL_INFO, all_info, size, 7);
    394411
    395         printf("test position_information level\n");
     412        printf("Test position_information level\n");
    396413        sfinfo.position_information.in.position = 123456;
    397414        CHECK_CALL_FNUM(POSITION_INFORMATION, NT_STATUS_OK);
     
    401418        CHECK_VALUE(POSITION_INFORMATION, position_information, position, 0);
    402419
    403         printf("test mode_information level\n");
     420        printf("Test mode_information level\n");
    404421        sfinfo.mode_information.in.mode = 2;
    405422        CHECK_CALL_FNUM(MODE_INFORMATION, NT_STATUS_OK);
     
    421438
    422439#if 0
    423         printf("test unix_basic level\n");
     440        printf("Test unix_basic level\n");
    424441        CHECK_CALL_FNUM(UNIX_BASIC, NT_STATUS_OK);
    425442        CHECK_CALL_PATH(UNIX_BASIC, NT_STATUS_OK);
    426443
    427         printf("test unix_link level\n");
     444        printf("Test unix_link level\n");
    428445        CHECK_CALL_FNUM(UNIX_LINK, NT_STATUS_OK);
    429446        CHECK_CALL_PATH(UNIX_LINK, NT_STATUS_OK);
     
    446463 * basic testing of all RAW_SFILEINFO_RENAME call
    447464 */
    448 bool torture_raw_sfileinfo_rename(struct torture_context *torture,
    449                                                                   struct smbcli_state *cli)
     465static bool
     466torture_raw_sfileinfo_rename(struct torture_context *torture,
     467    struct smbcli_state *cli)
    450468{
    451469        bool ret = true;
     
    673691   look for the w2k3 setpathinfo STANDARD bug
    674692*/
    675 bool torture_raw_sfileinfo_bug(struct torture_context *torture,
    676                                                            struct smbcli_state *cli)
     693static bool torture_raw_sfileinfo_bug(struct torture_context *torture,
     694    struct smbcli_state *cli)
    677695{
    678696        const char *fname = "\\bug3.txt";
     
    702720        return true;
    703721}
     722
     723/**
     724 * Test both the snia cifs RAW_SFILEINFO_END_OF_FILE_INFO and the undocumented
     725 * pass-through RAW_SFILEINFO_END_OF_FILE_INFORMATION in the context of
     726 * trans2setpathinfo.
     727 */
     728static bool
     729torture_raw_sfileinfo_eof(struct torture_context *tctx,
     730    struct smbcli_state *cli1, struct smbcli_state *cli2)
     731{
     732        const char *fname = BASEDIR "\\test_sfileinfo_end_of_file.dat";
     733        NTSTATUS status;
     734        bool ret = true;
     735        union smb_open io;
     736        union smb_setfileinfo sfi;
     737        union smb_fileinfo qfi;
     738        uint16_t fnum = 0;
     739
     740        if (!torture_setup_dir(cli1, BASEDIR)) {
     741                return false;
     742        }
     743
     744        /* cleanup */
     745        smbcli_unlink(cli1->tree, fname);
     746
     747        io.generic.level = RAW_OPEN_NTCREATEX;
     748        io.ntcreatex.in.root_fid.fnum = 0;
     749        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     750        io.ntcreatex.in.alloc_size = 0;
     751        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     752        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
     753        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
     754        io.ntcreatex.in.create_options = 0;
     755        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     756        io.ntcreatex.in.security_flags = 0;
     757        io.ntcreatex.in.fname = fname;
     758        io.ntcreatex.in.flags = 0;
     759
     760        /* Open the file sharing none. */
     761        status = smb_raw_open(cli1->tree, tctx, &io);
     762        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK, ret,
     763            done, "Status should be OK");
     764        fnum = io.ntcreatex.out.file.fnum;
     765
     766        /* Try to sfileinfo to extend the file. */
     767        ZERO_STRUCT(sfi);
     768        sfi.generic.level = RAW_SFILEINFO_END_OF_FILE_INFO;
     769        sfi.generic.in.file.path = fname;
     770        sfi.end_of_file_info.in.size = 100;
     771        status = smb_raw_setpathinfo(cli2->tree, &sfi);
     772
     773        /* There should be share mode contention in this case. */
     774        torture_assert_ntstatus_equal_goto(tctx, status,
     775            NT_STATUS_SHARING_VIOLATION, ret, done, "Status should be "
     776            "SHARING_VIOLATION");
     777
     778        /* Make sure the size is still 0. */
     779        ZERO_STRUCT(qfi);
     780        qfi.generic.level = RAW_FILEINFO_STANDARD_INFO;
     781        qfi.generic.in.file.path = fname;
     782        status = smb_raw_pathinfo(cli2->tree, tctx, &qfi);
     783        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK, ret,
     784            done, "Status should be OK");
     785
     786        torture_assert_u64_equal(tctx, qfi.standard_info.out.size, 0,
     787            "alloc_size should be 0 since the setpathinfo failed.");
     788
     789        /* Try again with the pass through instead of documented version. */
     790        ZERO_STRUCT(sfi);
     791        sfi.generic.level = RAW_SFILEINFO_END_OF_FILE_INFORMATION;
     792        sfi.generic.in.file.path = fname;
     793        sfi.end_of_file_info.in.size = 100;
     794        status = smb_raw_setpathinfo(cli2->tree, &sfi);
     795
     796        /*
     797         * Looks like a windows bug:
     798         * http://lists.samba.org/archive/cifs-protocol/2009-November/001130.html
     799         */
     800        if (TARGET_IS_W2K8(tctx) || TARGET_IS_WIN7(tctx)) {
     801                /* It succeeds! This is just weird! */
     802                torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK,
     803                    ret, done, "Status should be OK");
     804
     805                /* Verify that the file was actually extended to 100. */
     806                ZERO_STRUCT(qfi);
     807                qfi.generic.level = RAW_FILEINFO_STANDARD_INFO;
     808                qfi.generic.in.file.path = fname;
     809                status = smb_raw_pathinfo(cli2->tree, tctx, &qfi);
     810                torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK,
     811                    ret, done, "Status should be OK");
     812
     813                torture_assert_u64_equal(tctx, qfi.standard_info.out.size, 100,
     814                    "alloc_size should be 100 since the setpathinfo "
     815                    "succeeded.");
     816        } else {
     817                torture_assert_ntstatus_equal_goto(tctx, status,
     818                    NT_STATUS_SHARING_VIOLATION, ret, done, "Status should be "
     819                    "SHARING_VIOLATION");
     820        }
     821
     822        /* close the first file. */
     823        smbcli_close(cli1->tree, fnum);
     824        fnum = 0;
     825
     826        /* Try to sfileinfo to extend the file again (non-pass-through). */
     827        ZERO_STRUCT(sfi);
     828        sfi.generic.level = RAW_SFILEINFO_END_OF_FILE_INFO;
     829        sfi.generic.in.file.path = fname;
     830        sfi.end_of_file_info.in.size = 200;
     831        status = smb_raw_setpathinfo(cli2->tree, &sfi);
     832
     833        /* This should cause the client to retun invalid level. */
     834        if (TARGET_IS_W2K8(tctx) || TARGET_IS_WIN7(tctx)) {
     835                /*
     836                 * Windows sends back an invalid packet that smbclient sees
     837                 * and returns INTERNAL_ERROR.
     838                 */
     839                torture_assert_ntstatus_equal_goto(tctx, status,
     840                    NT_STATUS_INTERNAL_ERROR, ret, done, "Status should be "
     841                    "INTERNAL_ERROR");
     842        } else {
     843                torture_assert_ntstatus_equal_goto(tctx, status,
     844                    NT_STATUS_INVALID_LEVEL, ret, done, "Status should be "
     845                    "INVALID_LEVEL");
     846        }
     847
     848        /* Try to extend the file now with the passthrough level. */
     849        sfi.generic.level = RAW_SFILEINFO_END_OF_FILE_INFORMATION;
     850        status = smb_raw_setpathinfo(cli2->tree, &sfi);
     851        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK, ret,
     852            done, "Status should be OK");
     853
     854        /* Verify that the file was actually extended to 200. */
     855        ZERO_STRUCT(qfi);
     856        qfi.generic.level = RAW_FILEINFO_STANDARD_INFO;
     857        qfi.generic.in.file.path = fname;
     858        status = smb_raw_pathinfo(cli2->tree, tctx, &qfi);
     859
     860        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK, ret,
     861            done, "Status should be OK");
     862        torture_assert_u64_equal(tctx, qfi.standard_info.out.size, 200,
     863            "alloc_size should be 200 since the setpathinfo succeeded.");
     864
     865        /* Open the file so end of file can be set by handle. */
     866        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_WRITE;
     867        status = smb_raw_open(cli1->tree, tctx, &io);
     868        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK, ret,
     869            done, "Status should be OK");
     870        fnum = io.ntcreatex.out.file.fnum;
     871
     872        /* Try sfileinfo to extend the file by handle (non-pass-through). */
     873        ZERO_STRUCT(sfi);
     874        sfi.generic.level = RAW_SFILEINFO_END_OF_FILE_INFO;
     875        sfi.generic.in.file.fnum = fnum;
     876        sfi.end_of_file_info.in.size = 300;
     877        status = smb_raw_setfileinfo(cli1->tree, &sfi);
     878        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK, ret,
     879            done, "Status should be OK");
     880
     881        /* Verify that the file was actually extended to 300. */
     882        ZERO_STRUCT(qfi);
     883        qfi.generic.level = RAW_FILEINFO_STANDARD_INFO;
     884        qfi.generic.in.file.path = fname;
     885        status = smb_raw_pathinfo(cli1->tree, tctx, &qfi);
     886        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK, ret,
     887            done, "Status should be OK");
     888        torture_assert_u64_equal(tctx, qfi.standard_info.out.size, 300,
     889            "alloc_size should be 300 since the setpathinfo succeeded.");
     890
     891        /* Try sfileinfo to extend the file by handle (pass-through). */
     892        ZERO_STRUCT(sfi);
     893        sfi.generic.level = RAW_SFILEINFO_END_OF_FILE_INFORMATION;
     894        sfi.generic.in.file.fnum = fnum;
     895        sfi.end_of_file_info.in.size = 400;
     896        status = smb_raw_setfileinfo(cli1->tree, &sfi);
     897        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK, ret,
     898            done, "Status should be OK");
     899
     900        /* Verify that the file was actually extended to 300. */
     901        ZERO_STRUCT(qfi);
     902        qfi.generic.level = RAW_FILEINFO_STANDARD_INFO;
     903        qfi.generic.in.file.path = fname;
     904        status = smb_raw_pathinfo(cli1->tree, tctx, &qfi);
     905        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK, ret,
     906            done, "Status should be OK");
     907        torture_assert_u64_equal(tctx, qfi.standard_info.out.size, 400,
     908            "alloc_size should be 400 since the setpathinfo succeeded.");
     909 done:
     910        if (fnum > 0) {
     911                smbcli_close(cli1->tree, fnum);
     912                fnum = 0;
     913        }
     914
     915        smb_raw_exit(cli1->session);
     916        smb_raw_exit(cli2->session);
     917        smbcli_deltree(cli1->tree, BASEDIR);
     918        return ret;
     919}
     920
     921static bool
     922torture_raw_sfileinfo_eof_access(struct torture_context *tctx,
     923    struct smbcli_state *cli1, struct smbcli_state *cli2)
     924{
     925        const char *fname = BASEDIR "\\test_exclusive3.dat";
     926        NTSTATUS status, expected_status;
     927        bool ret = true;
     928        union smb_open io;
     929        union smb_setfileinfo sfi;
     930        uint16_t fnum=0;
     931        uint32_t access_mask = 0;
     932
     933        if (!torture_setup_dir(cli1, BASEDIR)) {
     934                return false;
     935        }
     936
     937        /* cleanup */
     938        smbcli_unlink(cli1->tree, fname);
     939
     940        /*
     941         * base ntcreatex parms
     942         */
     943        io.generic.level = RAW_OPEN_NTCREATEX;
     944        io.ntcreatex.in.root_fid.fnum = 0;
     945        io.ntcreatex.in.alloc_size = 0;
     946        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     947        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
     948        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
     949        io.ntcreatex.in.create_options = 0;
     950        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     951        io.ntcreatex.in.security_flags = 0;
     952        io.ntcreatex.in.fname = fname;
     953        io.ntcreatex.in.flags = 0;
     954
     955
     956        for (access_mask = 1; access_mask <= 0x00001FF; access_mask++) {
     957                io.ntcreatex.in.access_mask = access_mask;
     958
     959                status = smb_raw_open(cli1->tree, tctx, &io);
     960                if (!NT_STATUS_IS_OK(status)) {
     961                        continue;
     962                }
     963
     964                fnum = io.ntcreatex.out.file.fnum;
     965
     966                ZERO_STRUCT(sfi);
     967                sfi.generic.level = RAW_SFILEINFO_END_OF_FILE_INFO;
     968                sfi.generic.in.file.fnum = fnum;
     969                sfi.end_of_file_info.in.size = 100;
     970
     971                status = smb_raw_setfileinfo(cli1->tree, &sfi);
     972
     973                expected_status = (access_mask & SEC_FILE_WRITE_DATA) ?
     974                    NT_STATUS_OK : NT_STATUS_ACCESS_DENIED;
     975
     976                if (!NT_STATUS_EQUAL(expected_status, status)) {
     977                        torture_comment(tctx, "0x%x wrong\n", access_mask);
     978                }
     979
     980                torture_assert_ntstatus_equal_goto(tctx, status,
     981                    expected_status, ret, done, "Status Wrong");
     982
     983                smbcli_close(cli1->tree, fnum);
     984        }
     985
     986done:
     987        smb_raw_exit(cli1->session);
     988        smb_raw_exit(cli2->session);
     989        smbcli_deltree(cli1->tree, BASEDIR);
     990        return ret;
     991}
     992
     993static bool
     994torture_raw_sfileinfo_archive(struct torture_context *tctx,
     995    struct smbcli_state *cli)
     996{
     997        const char *fname = BASEDIR "\\test_archive.dat";
     998        NTSTATUS status;
     999        bool ret = true;
     1000        union smb_open io;
     1001        union smb_setfileinfo sfinfo;
     1002        union smb_fileinfo finfo;
     1003        uint16_t fnum=0;
     1004
     1005        if (!torture_setup_dir(cli, BASEDIR)) {
     1006                return false;
     1007        }
     1008
     1009        /* cleanup */
     1010        smbcli_unlink(cli->tree, fname);
     1011
     1012        /*
     1013         * create a normal file, verify archive bit
     1014         */
     1015        io.generic.level = RAW_OPEN_NTCREATEX;
     1016        io.ntcreatex.in.root_fid.fnum = 0;
     1017        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     1018        io.ntcreatex.in.alloc_size = 0;
     1019        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     1020        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
     1021        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
     1022        io.ntcreatex.in.create_options = 0;
     1023        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     1024        io.ntcreatex.in.security_flags = 0;
     1025        io.ntcreatex.in.fname = fname;
     1026        io.ntcreatex.in.flags = 0;
     1027        status = smb_raw_open(cli->tree, tctx, &io);
     1028        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK,
     1029            ret, done, "open failed");
     1030        fnum = io.ntcreatex.out.file.fnum;
     1031
     1032        torture_assert_int_equal(tctx,
     1033            io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
     1034            FILE_ATTRIBUTE_ARCHIVE,
     1035            "archive bit not set");
     1036
     1037        /*
     1038         * try to turn off archive bit
     1039         */
     1040        ZERO_STRUCT(sfinfo);
     1041        sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFO;
     1042        sfinfo.generic.in.file.fnum = fnum;
     1043        sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL;
     1044        status = smb_raw_setfileinfo(cli->tree, &sfinfo);
     1045        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK,
     1046            ret, done, "setfileinfo failed");
     1047
     1048        finfo.generic.level = RAW_FILEINFO_ALL_INFO;
     1049        finfo.generic.in.file.fnum = fnum;
     1050        status = smb_raw_fileinfo(cli->tree, tctx, &finfo);
     1051        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK,
     1052            ret, done, "fileinfo failed");
     1053
     1054        torture_assert_int_equal(tctx,
     1055            finfo.all_info.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
     1056            FILE_ATTRIBUTE_NORMAL,
     1057            "archive bit set");
     1058
     1059        status = smbcli_close(cli->tree, fnum);
     1060        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK,
     1061            ret, done, "close failed");
     1062
     1063        status = smbcli_unlink(cli->tree, fname);
     1064        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK,
     1065            ret, done, "unlink failed");
     1066
     1067        /*
     1068         * create a directory, verify no archive bit
     1069         */
     1070        io.generic.level = RAW_OPEN_NTCREATEX;
     1071        io.ntcreatex.in.root_fid.fnum = 0;
     1072        io.ntcreatex.in.access_mask = SEC_RIGHTS_DIR_ALL;
     1073        io.ntcreatex.in.alloc_size = 0;
     1074        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
     1075        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
     1076        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
     1077        io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
     1078        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     1079        io.ntcreatex.in.security_flags = 0;
     1080        io.ntcreatex.in.fname = fname;
     1081        io.ntcreatex.in.flags = 0;
     1082        status = smb_raw_open(cli->tree, tctx, &io);
     1083        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK,
     1084            ret, done, "directory open failed");
     1085        fnum = io.ntcreatex.out.file.fnum;
     1086
     1087        torture_assert_int_equal(tctx,
     1088            io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
     1089            FILE_ATTRIBUTE_DIRECTORY,
     1090            "archive bit set");
     1091
     1092        /*
     1093         * verify you can turn on archive bit
     1094         */
     1095        sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFO;
     1096        sfinfo.generic.in.file.fnum = fnum;
     1097        sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_ARCHIVE;
     1098        status = smb_raw_setfileinfo(cli->tree, &sfinfo);
     1099        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK,
     1100            ret, done, "setfileinfo failed");
     1101
     1102        finfo.generic.level = RAW_FILEINFO_ALL_INFO;
     1103        finfo.generic.in.file.fnum = fnum;
     1104        status = smb_raw_fileinfo(cli->tree, tctx, &finfo);
     1105        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK,
     1106            ret, done, "fileinfo failed");
     1107
     1108        torture_assert_int_equal(tctx,
     1109            finfo.all_info.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
     1110            FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_ARCHIVE,
     1111            "archive bit not set");
     1112
     1113        /*
     1114         * and try to turn it back off
     1115         */
     1116        sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFO;
     1117        sfinfo.generic.in.file.fnum = fnum;
     1118        sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_DIRECTORY;
     1119        status = smb_raw_setfileinfo(cli->tree, &sfinfo);
     1120        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK,
     1121            ret, done, "setfileinfo failed");
     1122
     1123        finfo.generic.level = RAW_FILEINFO_ALL_INFO;
     1124        finfo.generic.in.file.fnum = fnum;
     1125        status = smb_raw_fileinfo(cli->tree, tctx, &finfo);
     1126        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK,
     1127            ret, done, "fileinfo failed");
     1128
     1129        torture_assert_int_equal(tctx,
     1130            finfo.all_info.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
     1131            FILE_ATTRIBUTE_DIRECTORY,
     1132            "archive bit set");
     1133
     1134        status = smbcli_close(cli->tree, fnum);
     1135        torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_OK,
     1136            ret, done, "close failed");
     1137
     1138done:
     1139        smbcli_close(cli->tree, fnum);
     1140        smbcli_deltree(cli->tree, BASEDIR);
     1141        return ret;
     1142}
     1143
     1144struct torture_suite *torture_raw_sfileinfo(TALLOC_CTX *mem_ctx)
     1145{
     1146        struct torture_suite *suite = torture_suite_create(mem_ctx, "sfileinfo");
     1147
     1148        torture_suite_add_1smb_test(suite, "base", torture_raw_sfileinfo_base);
     1149        torture_suite_add_1smb_test(suite, "rename", torture_raw_sfileinfo_rename);
     1150        torture_suite_add_1smb_test(suite, "bug", torture_raw_sfileinfo_bug);
     1151        torture_suite_add_2smb_test(suite, "end-of-file",
     1152            torture_raw_sfileinfo_eof);
     1153        torture_suite_add_2smb_test(suite, "end-of-file-access",
     1154            torture_raw_sfileinfo_eof_access);
     1155        torture_suite_add_1smb_test(suite, "archive",
     1156                                                                torture_raw_sfileinfo_archive);
     1157
     1158        return suite;
     1159}
  • trunk/server/source4/torture/raw/streams.c

    r414 r745  
    2727#include "libcli/libcli.h"
    2828#include "torture/util.h"
     29#include "lib/util/tsort.h"
    2930
    3031#define BASEDIR "\\teststreams"
    3132
    32 #define CHECK_STATUS(status, correct) do { \
    33         if (!NT_STATUS_EQUAL(status, correct)) { \
    34                 printf("(%s) Incorrect status %s - should be %s\n", \
    35                        __location__, nt_errstr(status), nt_errstr(correct)); \
    36                 ret = false; \
    37                 goto done; \
    38         }} while (0)
    39 
    40 #define CHECK_VALUE(v, correct) do { \
    41         if ((v) != (correct)) { \
    42                 printf("(%s) Incorrect value %s=%d - should be %d\n", \
    43                        __location__, #v, (int)v, (int)correct); \
    44                 ret = false; \
    45         }} while (0)
    46 
    47 #define CHECK_NTTIME(v, correct) do { \
    48         if ((v) != (correct)) { \
    49                 printf("(%s) Incorrect value %s=%llu - should be %llu\n", \
    50                        __location__, #v, (unsigned long long)v, \
    51                        (unsigned long long)correct); \
    52                 ret = false; \
    53         }} while (0)
     33#define CHECK_STATUS(status, correct) \
     34        torture_assert_ntstatus_equal_goto(tctx,status,correct,ret,done,"CHECK_STATUS")
     35
     36#define CHECK_VALUE(v, correct) \
     37        torture_assert_int_equal(tctx,v,correct,"CHECK_VALUE")
     38
     39#define CHECK_NTTIME(v, correct) \
     40        torture_assert_u64_equal(tctx,v,correct,"CHECK_NTTIME")
    5441
    5542#define CHECK_STR(v, correct) do { \
     
    6653                ok = false; \
    6754        } \
    68         if (!ok) { \
    69                 printf("(%s) Incorrect value %s='%s' - should be '%s'\n", \
    70                        __location__, #v, (v)?(v):"NULL", \
    71                        (correct)?(correct):"NULL"); \
    72                 ret = false; \
    73         }} while (0)
     55        torture_assert(tctx,ok,\
     56                       talloc_asprintf(tctx, "got '%s', expected '%s'",\
     57                       (v)?(v):"NULL", (correct)?(correct):"NULL")); \
     58} while (0)
    7459
    7560/*
     
    123108}
    124109
    125 static int qsort_string(const void *v1, const void *v2)
     110static int qsort_string(char * const *s1, char * const *s2)
    126111{
    127         char * const *s1 = v1;
    128         char * const *s2 = v2;
    129112        return strcmp(*s1, *s2);
    130113}
    131114
    132 static int qsort_stream(const void *v1, const void *v2)
     115static int qsort_stream(const struct stream_struct *s1, const struct stream_struct *s2)
    133116{
    134         const struct stream_struct * s1 = v1;
    135         const struct stream_struct * s2 = v2;
    136117        return strcmp(s1->stream_name.s, s2->stream_name.s);
    137118}
    138119
    139 static bool check_stream_list(struct smbcli_state *cli, const char *fname,
     120static bool check_stream_list(struct torture_context *tctx,
     121                              struct smbcli_state *cli, const char *fname,
    140122                              int num_exp, const char **exp)
    141123{
     
    147129        struct stream_struct *stream_sort;
    148130        bool ret = false;
     131        int fail = -1;
    149132
    150133        finfo.generic.level = RAW_FILEINFO_STREAM_INFO;
     
    152135
    153136        status = smb_raw_pathinfo(cli->tree, tmp_ctx, &finfo);
    154         if (!NT_STATUS_IS_OK(status)) {
    155                 d_fprintf(stderr, "(%s) smb_raw_pathinfo failed: %s\n",
    156                           __location__, nt_errstr(status));
    157                 goto fail;
    158         }
    159 
    160         if (finfo.stream_info.out.num_streams != num_exp) {
    161                 d_fprintf(stderr, "(%s) expected %d streams, got %d\n",
    162                           __location__, num_exp,
    163                           finfo.stream_info.out.num_streams);
    164                 goto fail;
    165         }
     137        CHECK_STATUS(status, NT_STATUS_OK);
     138
     139        CHECK_VALUE(finfo.stream_info.out.num_streams, num_exp);
    166140
    167141        if (num_exp == 0) {
    168142                ret = true;
    169                 goto fail;
    170         }
    171 
    172         exp_sort = talloc_memdup(tmp_ctx, exp, num_exp * sizeof(*exp));
     143                goto done;
     144        }
     145
     146        exp_sort = (char **)talloc_memdup(tmp_ctx, exp, num_exp * sizeof(*exp));
    173147
    174148        if (exp_sort == NULL) {
    175                 goto fail;
    176         }
    177 
    178         qsort(exp_sort, num_exp, sizeof(*exp_sort), qsort_string);
    179 
    180         stream_sort = talloc_memdup(tmp_ctx, finfo.stream_info.out.streams,
    181                                     finfo.stream_info.out.num_streams *
    182                                     sizeof(*stream_sort));
     149                goto done;
     150        }
     151
     152        TYPESAFE_QSORT(exp_sort, num_exp, qsort_string);
     153
     154        stream_sort = (struct stream_struct *)talloc_memdup(tmp_ctx,
     155                                finfo.stream_info.out.streams,
     156                                finfo.stream_info.out.num_streams *
     157                                sizeof(*stream_sort));
    183158
    184159        if (stream_sort == NULL) {
    185                 goto fail;
    186         }
    187 
    188         qsort(stream_sort, finfo.stream_info.out.num_streams,
    189               sizeof(*stream_sort), qsort_stream);
     160                goto done;
     161        }
     162
     163        TYPESAFE_QSORT(stream_sort, finfo.stream_info.out.num_streams, qsort_stream);
    190164
    191165        for (i=0; i<num_exp; i++) {
    192166                if (strcmp(exp_sort[i], stream_sort[i].stream_name.s) != 0) {
    193                         d_fprintf(stderr, "(%s) expected stream name %s, got "
    194                                   "%s\n", __location__, exp_sort[i],
    195                                   stream_sort[i].stream_name.s);
    196                         goto fail;
     167                        fail = i;
     168                        goto show_streams;
    197169                }
    198170        }
    199171
    200172        ret = true;
    201  fail:
     173done:
     174        talloc_free(tmp_ctx);
     175        return ret;
     176
     177show_streams:
     178        for (i=0; i<num_exp; i++) {
     179                torture_comment(tctx, "stream names '%s' '%s'\n",
     180                                exp_sort[i], stream_sort[i].stream_name.s);
     181        }
     182        CHECK_STR(stream_sort[fail].stream_name.s, exp_sort[fail]);
    202183        talloc_free(tmp_ctx);
    203184        return ret;
     
    208189*/
    209190static bool test_stream_dir(struct torture_context *tctx,
    210                            struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
     191                           struct smbcli_state *cli)
    211192{
    212193        NTSTATUS status;
     
    217198        const char *basedir_data;
    218199
    219         basedir_data = talloc_asprintf(mem_ctx, "%s::$DATA", BASEDIR);
    220         sname1 = talloc_asprintf(mem_ctx, "%s:%s", fname, "Stream One");
     200        if (!torture_setup_dir(cli, BASEDIR)) {
     201                return false;
     202        }
     203
     204        basedir_data = talloc_asprintf(tctx, "%s::$DATA", BASEDIR);
     205        sname1 = talloc_asprintf(tctx, "%s:%s", fname, "Stream One");
    221206
    222207        printf("(%s) opening non-existant directory stream\n", __location__);
    223208        io.generic.level = RAW_OPEN_NTCREATEX;
    224         io.ntcreatex.in.root_fid = 0;
     209        io.ntcreatex.in.root_fid.fnum = 0;
    225210        io.ntcreatex.in.flags = 0;
    226211        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
     
    233218        io.ntcreatex.in.security_flags = 0;
    234219        io.ntcreatex.in.fname = sname1;
    235         status = smb_raw_open(cli->tree, mem_ctx, &io);
     220        status = smb_raw_open(cli->tree, tctx, &io);
    236221        CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY);
    237222
    238223        printf("(%s) opening basedir  stream\n", __location__);
    239224        io.generic.level = RAW_OPEN_NTCREATEX;
    240         io.ntcreatex.in.root_fid = 0;
     225        io.ntcreatex.in.root_fid.fnum = 0;
    241226        io.ntcreatex.in.flags = 0;
    242227        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
     
    249234        io.ntcreatex.in.security_flags = 0;
    250235        io.ntcreatex.in.fname = basedir_data;
    251         status = smb_raw_open(cli->tree, mem_ctx, &io);
     236        status = smb_raw_open(cli->tree, tctx, &io);
    252237        CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY);
    253238
    254239        printf("(%s) opening basedir ::$DATA stream\n", __location__);
    255240        io.generic.level = RAW_OPEN_NTCREATEX;
    256         io.ntcreatex.in.root_fid = 0;
     241        io.ntcreatex.in.root_fid.fnum = 0;
    257242        io.ntcreatex.in.flags = 0x10;
    258243        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
     
    265250        io.ntcreatex.in.security_flags = 0;
    266251        io.ntcreatex.in.fname = basedir_data;
    267         status = smb_raw_open(cli->tree, mem_ctx, &io);
     252        status = smb_raw_open(cli->tree, tctx, &io);
    268253        CHECK_STATUS(status, NT_STATUS_FILE_IS_A_DIRECTORY);
    269254
    270255        printf("(%s) list the streams on the basedir\n", __location__);
    271         ret &= check_stream_list(cli, BASEDIR, 0, NULL);
     256        ret &= check_stream_list(tctx, cli, BASEDIR, 0, NULL);
    272257done:
     258        smbcli_deltree(cli->tree, BASEDIR);
    273259        return ret;
    274260}
     
    278264*/
    279265static bool test_stream_io(struct torture_context *tctx,
    280                            struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
     266                           struct smbcli_state *cli)
    281267{
    282268        NTSTATUS status;
     
    293279                                ":Second Stream:$DATA" };
    294280
    295         sname1 = talloc_asprintf(mem_ctx, "%s:%s", fname, "Stream One");
    296         sname2 = talloc_asprintf(mem_ctx, "%s:%s:$DaTa", fname, "Second Stream");
     281        if (!torture_setup_dir(cli, BASEDIR)) {
     282                return false;
     283        }
     284
     285        sname1 = talloc_asprintf(tctx, "%s:%s", fname, "Stream One");
     286        sname2 = talloc_asprintf(tctx, "%s:%s:$DaTa", fname, "Second Stream");
    297287
    298288        printf("(%s) creating a stream on a non-existant file\n", __location__);
    299289        io.generic.level = RAW_OPEN_NTCREATEX;
    300         io.ntcreatex.in.root_fid = 0;
     290        io.ntcreatex.in.root_fid.fnum = 0;
    301291        io.ntcreatex.in.flags = 0;
    302292        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
     
    309299        io.ntcreatex.in.security_flags = 0;
    310300        io.ntcreatex.in.fname = sname1;
    311         status = smb_raw_open(cli->tree, mem_ctx, &io);
     301        status = smb_raw_open(cli->tree, tctx, &io);
    312302        CHECK_STATUS(status, NT_STATUS_OK);
    313303        fnum = io.ntcreatex.out.file.fnum;
    314304
    315         ret &= check_stream(cli, __location__, mem_ctx, fname, "Stream One", NULL);
     305        ret &= check_stream(cli, __location__, tctx, fname, "Stream One", NULL);
    316306
    317307        printf("(%s) check that open of base file is allowed\n", __location__);
    318308        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
    319309        io.ntcreatex.in.fname = fname;
    320         status = smb_raw_open(cli->tree, mem_ctx, &io);
     310        status = smb_raw_open(cli->tree, tctx, &io);
    321311        CHECK_STATUS(status, NT_STATUS_OK);
    322312        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
     
    328318        smbcli_close(cli->tree, fnum);
    329319
    330         ret &= check_stream(cli, __location__, mem_ctx, fname, "Stream One", "test data");
     320        ret &= check_stream(cli, __location__, tctx, fname, "Stream One", "test data");
    331321
    332322        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
    333323        io.ntcreatex.in.fname = sname1;
    334         status = smb_raw_open(cli->tree, mem_ctx, &io);
     324        status = smb_raw_open(cli->tree, tctx, &io);
    335325        CHECK_STATUS(status, NT_STATUS_OK);
    336326        fnum = io.ntcreatex.out.file.fnum;
     
    342332        smbcli_close(cli->tree, fnum);
    343333
    344         ret &= check_stream(cli, __location__, mem_ctx, fname, "Stream One:$FOO", NULL);
     334        ret &= check_stream(cli, __location__, tctx, fname, "Stream One:$FOO", NULL);
    345335
    346336        printf("(%s) creating a stream2 on a existing file\n", __location__);
    347337        io.ntcreatex.in.fname = sname2;
    348338        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
    349         status = smb_raw_open(cli->tree, mem_ctx, &io);
     339        status = smb_raw_open(cli->tree, tctx, &io);
    350340        CHECK_STATUS(status, NT_STATUS_OK);
    351341        fnum = io.ntcreatex.out.file.fnum;
     
    357347        smbcli_close(cli->tree, fnum);
    358348
    359         ret &= check_stream(cli, __location__, mem_ctx, fname, "Stream One", "test MORE DATA ");
    360         ret &= check_stream(cli, __location__, mem_ctx, fname, "Stream One:$DATA", "test MORE DATA ");
    361         ret &= check_stream(cli, __location__, mem_ctx, fname, "Stream One:", NULL);
    362         ret &= check_stream(cli, __location__, mem_ctx, fname, "Second Stream", "SECOND STREAM");
    363         if (!torture_setting_bool(tctx, "samba4", false)) {
    364                 ret &= check_stream(cli, __location__, mem_ctx, fname,
    365                                     "SECOND STREAM:$DATA", "SECOND STREAM");
    366         }
    367         ret &= check_stream(cli, __location__, mem_ctx, fname, "Second Stream:$DATA", "SECOND STREAM");
    368         ret &= check_stream(cli, __location__, mem_ctx, fname, "Second Stream:", NULL);
    369         ret &= check_stream(cli, __location__, mem_ctx, fname, "Second Stream:$FOO", NULL);
    370 
    371         check_stream_list(cli, fname, 3, three);
     349        ret &= check_stream(cli, __location__, tctx, fname, "Stream One", "test MORE DATA ");
     350        ret &= check_stream(cli, __location__, tctx, fname, "Stream One:$DATA", "test MORE DATA ");
     351        ret &= check_stream(cli, __location__, tctx, fname, "Stream One:", NULL);
     352        ret &= check_stream(cli, __location__, tctx, fname, "Second Stream", "SECOND STREAM");
     353        ret &= check_stream(cli, __location__, tctx, fname,
     354                            "SECOND STREAM:$DATA", "SECOND STREAM");
     355        ret &= check_stream(cli, __location__, tctx, fname, "Second Stream:$DATA", "SECOND STREAM");
     356        ret &= check_stream(cli, __location__, tctx, fname, "Second Stream:", NULL);
     357        ret &= check_stream(cli, __location__, tctx, fname, "Second Stream:$FOO", NULL);
     358
     359        check_stream_list(tctx, cli, fname, 3, three);
    372360
    373361        printf("(%s) deleting stream\n", __location__);
     
    375363        CHECK_STATUS(status, NT_STATUS_OK);
    376364
    377         check_stream_list(cli, fname, 2, two);
     365        check_stream_list(tctx, cli, fname, 2, two);
    378366
    379367        printf("(%s) delete a stream via delete-on-close\n", __location__);
     
    384372        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
    385373
    386         status = smb_raw_open(cli->tree, mem_ctx, &io);
     374        status = smb_raw_open(cli->tree, tctx, &io);
    387375        CHECK_STATUS(status, NT_STATUS_OK);
    388376        fnum = io.ntcreatex.out.file.fnum;
     
    392380        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
    393381
    394         check_stream_list(cli, fname, 1, one);
    395 
    396         if (!torture_setting_bool(tctx, "samba4", false)) {
    397                 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
    398                 io.ntcreatex.in.fname = sname1;
    399                 status = smb_raw_open(cli->tree, mem_ctx, &io);
    400                 CHECK_STATUS(status, NT_STATUS_OK);
    401                 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    402                 io.ntcreatex.in.fname = sname2;
    403                 status = smb_raw_open(cli->tree, mem_ctx, &io);
    404                 CHECK_STATUS(status, NT_STATUS_OK);
    405                 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    406         }
     382        check_stream_list(tctx, cli, fname, 1, one);
     383
     384        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
     385        io.ntcreatex.in.fname = sname1;
     386        status = smb_raw_open(cli->tree, tctx, &io);
     387        CHECK_STATUS(status, NT_STATUS_OK);
     388        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
     389        io.ntcreatex.in.fname = sname2;
     390        status = smb_raw_open(cli->tree, tctx, &io);
     391        CHECK_STATUS(status, NT_STATUS_OK);
     392        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    407393
    408394        printf("(%s) deleting file\n", __location__);
     
    412398done:
    413399        smbcli_close(cli->tree, fnum);
     400        smbcli_deltree(cli->tree, BASEDIR);
    414401        return ret;
    415402}
     
    419406*/
    420407static bool test_stream_sharemodes(struct torture_context *tctx,
    421                                    struct smbcli_state *cli,
    422                                    TALLOC_CTX *mem_ctx)
     408                                   struct smbcli_state *cli)
    423409{
    424410        NTSTATUS status;
     
    430416        int fnum2 = -1;
    431417
    432         sname1 = talloc_asprintf(mem_ctx, "%s:%s", fname, "Stream One");
    433         sname2 = talloc_asprintf(mem_ctx, "%s:%s:$DaTa", fname, "Second Stream");
     418        if (!torture_setup_dir(cli, BASEDIR)) {
     419                return false;
     420        }
     421
     422        sname1 = talloc_asprintf(tctx, "%s:%s", fname, "Stream One");
     423        sname2 = talloc_asprintf(tctx, "%s:%s:$DaTa", fname, "Second Stream");
    434424
    435425        printf("(%s) testing stream share mode conflicts\n", __location__);
    436426        io.generic.level = RAW_OPEN_NTCREATEX;
    437         io.ntcreatex.in.root_fid = 0;
     427        io.ntcreatex.in.root_fid.fnum = 0;
    438428        io.ntcreatex.in.flags = 0;
    439429        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
     
    447437        io.ntcreatex.in.fname = sname1;
    448438
    449         status = smb_raw_open(cli->tree, mem_ctx, &io);
     439        status = smb_raw_open(cli->tree, tctx, &io);
    450440        CHECK_STATUS(status, NT_STATUS_OK);
    451441        fnum1 = io.ntcreatex.out.file.fnum;
     
    456446
    457447        io.ntcreatex.in.fname = sname2;
    458         status = smb_raw_open(cli->tree, mem_ctx, &io);
     448        status = smb_raw_open(cli->tree, tctx, &io);
    459449        CHECK_STATUS(status, NT_STATUS_OK);
    460450        fnum2 = io.ntcreatex.out.file.fnum;
     
    467457        io.ntcreatex.in.fname = sname1;
    468458        io.ntcreatex.in.open_disposition = 0;
    469         status = smb_raw_open(cli->tree, mem_ctx, &io);
     459        status = smb_raw_open(cli->tree, tctx, &io);
    470460        CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
    471461
    472462        io.ntcreatex.in.fname = sname2;
    473         status = smb_raw_open(cli->tree, mem_ctx, &io);
     463        status = smb_raw_open(cli->tree, tctx, &io);
    474464        CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
    475465
     
    478468        if (fnum2 != -1) smbcli_close(cli->tree, fnum2);
    479469        status = smbcli_unlink(cli->tree, fname);
     470        smbcli_deltree(cli->tree, BASEDIR);
    480471        return ret;
    481472}
     
    508499
    509500static bool test_stream_delete(struct torture_context *tctx,
    510                                struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
     501                               struct smbcli_state *cli)
    511502{
    512503        NTSTATUS status;
     
    520511        union smb_fileinfo finfo;
    521512
    522         sname1 = talloc_asprintf(mem_ctx, "%s:%s", fname, "Stream One");
     513        if (!torture_setup_dir(cli, BASEDIR)) {
     514                return false;
     515        }
     516
     517        sname1 = talloc_asprintf(tctx, "%s:%s", fname, "Stream One");
    523518
    524519        printf("(%s) opening non-existant file stream\n", __location__);
    525520        io.generic.level = RAW_OPEN_NTCREATEX;
    526         io.ntcreatex.in.root_fid = 0;
     521        io.ntcreatex.in.root_fid.fnum = 0;
    527522        io.ntcreatex.in.flags = 0;
    528523        io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA|SEC_FILE_WRITE_DATA;
     
    536531        io.ntcreatex.in.fname = sname1;
    537532
    538         status = smb_raw_open(cli->tree, mem_ctx, &io);
     533        status = smb_raw_open(cli->tree, tctx, &io);
    539534        CHECK_STATUS(status, NT_STATUS_OK);
    540535        fnum = io.ntcreatex.out.file.fnum;
     
    554549        io.ntcreatex.in.fname = fname;
    555550        io.ntcreatex.in.access_mask = SEC_STD_DELETE;
    556         status = smb_raw_open(cli->tree, mem_ctx, &io);
     551        status = smb_raw_open(cli->tree, tctx, &io);
    557552        CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
    558553
     
    566561        io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA|SEC_FILE_WRITE_DATA;
    567562        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_DELETE;
    568         status = smb_raw_open(cli->tree, mem_ctx, &io);
     563        status = smb_raw_open(cli->tree, tctx, &io);
    569564        CHECK_STATUS(status, NT_STATUS_OK);
    570565        fnum = io.ntcreatex.out.file.fnum;
     
    588583         */
    589584
    590         status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
     585        status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
    591586        CHECK_STATUS(status, NT_STATUS_DELETE_PENDING);
    592587
     
    595590         */
    596591        finfo.generic.in.file.path = sname1;
    597         status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
     592        status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
    598593        CHECK_STATUS(status, NT_STATUS_DELETE_PENDING);
    599594
     
    607602        finfo.all_info.in.file.fnum = fnum;
    608603
    609         status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
    610         CHECK_STATUS(status, NT_STATUS_OK);
    611         /* w2k and w2k3 return 0 and w2k8 returns 1
    612         CHECK_VALUE(finfo.all_info.out.delete_pending, 0);
    613         */
     604        status = smb_raw_fileinfo(cli->tree, tctx, &finfo);
     605        CHECK_STATUS(status, NT_STATUS_OK);
     606
     607        /* w2k and w2k3 return 0 and w2k8 returns 1 */
     608        if (TARGET_IS_WINXP(tctx) || TARGET_IS_W2K3(tctx) ||
     609            TARGET_IS_SAMBA3(tctx)) {
     610                CHECK_VALUE(finfo.all_info.out.delete_pending, 0);
     611        } else {
     612                CHECK_VALUE(finfo.all_info.out.delete_pending, 1);
     613        }
    614614
    615615        smbcli_close(cli->tree, fnum);
     
    620620
    621621        finfo.generic.in.file.path = fname;
    622         status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
     622        status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
    623623        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
    624624
     
    627627        io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
    628628        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
    629         status = smb_raw_open(cli->tree, mem_ctx, &io);
     629        status = smb_raw_open(cli->tree, tctx, &io);
    630630        CHECK_STATUS(status, NT_STATUS_OK);
    631631        fnum = io.ntcreatex.out.file.fnum;
    632632
    633633        finfo.generic.in.file.path = fname;
    634         status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
     634        status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
    635635        CHECK_STATUS(status, NT_STATUS_OK);
    636636
    637637        smbcli_close(cli->tree, fnum);
    638638
    639         status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
     639        status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
    640640        CHECK_STATUS(status, NT_STATUS_OK);
    641641done:
    642642        smbcli_close(cli->tree, fnum);
    643643        smbcli_unlink(cli->tree, fname);
     644        smbcli_deltree(cli->tree, BASEDIR);
    644645        return ret;
    645646}
     
    649650*/
    650651static bool test_stream_names(struct torture_context *tctx,
    651                               struct smbcli_state *cli,
    652                               TALLOC_CTX *mem_ctx)
     652                              struct smbcli_state *cli)
    653653{
    654654        NTSTATUS status;
     
    687687        };
    688688
    689         sname1 = talloc_asprintf(mem_ctx, "%s:%s", fname, "\x05Stream\n One");
    690         sname1b = talloc_asprintf(mem_ctx, "%s:", sname1);
    691         sname1c = talloc_asprintf(mem_ctx, "%s:$FOO", sname1);
    692         sname1d = talloc_asprintf(mem_ctx, "%s:?D*a", sname1);
    693         sname2 = talloc_asprintf(mem_ctx, "%s:%s:$DaTa", fname, "MStream Two");
    694         snamew = talloc_asprintf(mem_ctx, "%s:%s:$DATA", fname, "?Stream*");
    695         snamew2 = talloc_asprintf(mem_ctx, "%s\\stream*:%s:$DATA", BASEDIR, "?Stream*");
    696         snamer1 = talloc_asprintf(mem_ctx, "%s:%s:$DATA", fname, "BeforeRename");
    697         snamer2 = talloc_asprintf(mem_ctx, "%s:%s:$DATA", fname, "AfterRename");
     689        if (!torture_setup_dir(cli, BASEDIR)) {
     690                return false;
     691        }
     692
     693        sname1 = talloc_asprintf(tctx, "%s:%s", fname, "\x05Stream\n One");
     694        sname1b = talloc_asprintf(tctx, "%s:", sname1);
     695        sname1c = talloc_asprintf(tctx, "%s:$FOO", sname1);
     696        sname1d = talloc_asprintf(tctx, "%s:?D*a", sname1);
     697        sname2 = talloc_asprintf(tctx, "%s:%s:$DaTa", fname, "MStream Two");
     698        snamew = talloc_asprintf(tctx, "%s:%s:$DATA", fname, "?Stream*");
     699        snamew2 = talloc_asprintf(tctx, "%s\\stream*:%s:$DATA", BASEDIR, "?Stream*");
     700        snamer1 = talloc_asprintf(tctx, "%s:%s:$DATA", fname, "BeforeRename");
     701        snamer2 = talloc_asprintf(tctx, "%s:%s:$DATA", fname, "AfterRename");
    698702
    699703        printf("(%s) testing stream names\n", __location__);
    700704        io.generic.level = RAW_OPEN_NTCREATEX;
    701         io.ntcreatex.in.root_fid = 0;
     705        io.ntcreatex.in.root_fid.fnum = 0;
     706        io.ntcreatex.in.flags = 0;
     707        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
     708        io.ntcreatex.in.create_options = 0;
     709        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     710        io.ntcreatex.in.share_access = 0;
     711        io.ntcreatex.in.alloc_size = 0;
     712        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
     713        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     714        io.ntcreatex.in.security_flags = 0;
     715        io.ntcreatex.in.fname = fname;
     716
     717        status = smb_raw_open(cli->tree, tctx, &io);
     718        CHECK_STATUS(status, NT_STATUS_OK);
     719        fnum1 = io.ntcreatex.out.file.fnum;
     720
     721        /*
     722         * Make sure the create time of the streams are different from the
     723         * base file.
     724         */
     725        sleep(2);
     726        smbcli_close(cli->tree, fnum1);
     727
     728        io.generic.level = RAW_OPEN_NTCREATEX;
     729        io.ntcreatex.in.root_fid.fnum = 0;
    702730        io.ntcreatex.in.flags = 0;
    703731        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
     
    711739        io.ntcreatex.in.fname = sname1;
    712740
    713         status = smb_raw_open(cli->tree, mem_ctx, &io);
     741        status = smb_raw_open(cli->tree, tctx, &io);
    714742        CHECK_STATUS(status, NT_STATUS_OK);
    715743        fnum1 = io.ntcreatex.out.file.fnum;
     
    720748
    721749        io.ntcreatex.in.fname = sname2;
    722         status = smb_raw_open(cli->tree, mem_ctx, &io);
     750        status = smb_raw_open(cli->tree, tctx, &io);
    723751        CHECK_STATUS(status, NT_STATUS_OK);
    724752        fnum2 = io.ntcreatex.out.file.fnum;
     
    731759        io.ntcreatex.in.fname = sname1;
    732760        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_SUPERSEDE;
    733         status = smb_raw_open(cli->tree, mem_ctx, &io);
     761        status = smb_raw_open(cli->tree, tctx, &io);
    734762        CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
    735763
    736764        io.ntcreatex.in.fname = sname1b;
    737         status = smb_raw_open(cli->tree, mem_ctx, &io);
     765        status = smb_raw_open(cli->tree, tctx, &io);
    738766        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID);
    739767
    740768        io.ntcreatex.in.fname = sname1c;
    741         status = smb_raw_open(cli->tree, mem_ctx, &io);
     769        status = smb_raw_open(cli->tree, tctx, &io);
    742770        if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
    743771                /* w2k returns INVALID_PARAMETER */
     
    748776
    749777        io.ntcreatex.in.fname = sname1d;
    750         status = smb_raw_open(cli->tree, mem_ctx, &io);
     778        status = smb_raw_open(cli->tree, tctx, &io);
    751779        if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
    752780                /* w2k returns INVALID_PARAMETER */
     
    757785
    758786        io.ntcreatex.in.fname = sname2;
    759         status = smb_raw_open(cli->tree, mem_ctx, &io);
     787        status = smb_raw_open(cli->tree, tctx, &io);
    760788        CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
    761789
    762790        io.ntcreatex.in.fname = snamew;
    763         status = smb_raw_open(cli->tree, mem_ctx, &io);
     791        status = smb_raw_open(cli->tree, tctx, &io);
    764792        CHECK_STATUS(status, NT_STATUS_OK);
    765793        fnum3 = io.ntcreatex.out.file.fnum;
    766794
    767795        io.ntcreatex.in.fname = snamew2;
    768         status = smb_raw_open(cli->tree, mem_ctx, &io);
     796        status = smb_raw_open(cli->tree, tctx, &io);
    769797        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID);
    770798
    771         ret &= check_stream_list(cli, fname, 4, four);
     799        ret &= check_stream_list(tctx, cli, fname, 4, four);
    772800
    773801        smbcli_close(cli->tree, fnum1);
     
    775803        smbcli_close(cli->tree, fnum3);
    776804
    777         if (torture_setting_bool(tctx, "samba4", true)) {
    778                 goto done;
    779         }
    780 
    781805        finfo.generic.level = RAW_FILEINFO_ALL_INFO;
    782806        finfo.generic.in.file.path = fname;
    783         status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
    784         CHECK_STATUS(status, NT_STATUS_OK);
    785 
    786         ret &= check_stream_list(cli, fname, 4, four);
     807        status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
     808        CHECK_STATUS(status, NT_STATUS_OK);
     809
     810        ret &= check_stream_list(tctx, cli, fname, 4, four);
    787811
    788812        for (i=0; i < 4; i++) {
     
    807831                                            SEC_RIGHTS_FILE_ALL;
    808832                io.ntcreatex.in.fname = path;
    809                 status = smb_raw_open(cli->tree, mem_ctx, &io);
     833                status = smb_raw_open(cli->tree, tctx, &io);
    810834                CHECK_STATUS(status, NT_STATUS_OK);
    811835                fnum1 = io.ntcreatex.out.file.fnum;
     
    813837                finfo.generic.level = RAW_FILEINFO_ALL_INFO;
    814838                finfo.generic.in.file.path = fname;
    815                 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
     839                status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
    816840                CHECK_STATUS(status, NT_STATUS_OK);
    817841
    818842                stinfo.generic.level = RAW_FILEINFO_ALL_INFO;
    819843                stinfo.generic.in.file.fnum = fnum1;
    820                 status = smb_raw_fileinfo(cli->tree, mem_ctx, &stinfo);
     844                status = smb_raw_fileinfo(cli->tree, tctx, &stinfo);
    821845                CHECK_STATUS(status, NT_STATUS_OK);
    822846                if (!torture_setting_bool(tctx, "samba3", false)) {
     
    843867                stinfo.generic.level = RAW_FILEINFO_NAME_INFO;
    844868                stinfo.generic.in.file.fnum = fnum1;
    845                 status = smb_raw_fileinfo(cli->tree, mem_ctx, &stinfo);
     869                status = smb_raw_fileinfo(cli->tree, tctx, &stinfo);
    846870                CHECK_STATUS(status, NT_STATUS_OK);
    847871                if (!torture_setting_bool(tctx, "samba3", false)) {
    848                         CHECK_STR(rpath, stinfo.name_info.out.fname.s);
     872                        CHECK_STR(stinfo.name_info.out.fname.s, rpath);
    849873                }
    850874
     
    873897                stinfo.generic.level = RAW_FILEINFO_ALL_INFO;
    874898                stinfo.generic.in.file.fnum = fnum1;
    875                 status = smb_raw_fileinfo(cli->tree, mem_ctx, &stinfo);
     899                status = smb_raw_fileinfo(cli->tree, tctx, &stinfo);
    876900                CHECK_STATUS(status, NT_STATUS_OK);
    877901                if (!torture_setting_bool(tctx, "samba3", false)) {
     
    890914                            finfo.all_info.out.ea_size);
    891915
    892                 ret &= check_stream_list(cli, fname, 4, four);
     916                ret &= check_stream_list(tctx, cli, fname, 4, four);
    893917
    894918                smbcli_close(cli->tree, fnum1);
     
    902926                                    SEC_RIGHTS_FILE_ALL;
    903927        io.ntcreatex.in.fname = snamer1;
    904         status = smb_raw_open(cli->tree, mem_ctx, &io);
     928        status = smb_raw_open(cli->tree, tctx, &io);
    905929        CHECK_STATUS(status, NT_STATUS_OK);
    906930        fnum1 = io.ntcreatex.out.file.fnum;
    907931
    908         ret &= check_stream_list(cli, fname, 5, five1);
     932        ret &= check_stream_list(tctx, cli, fname, 5, five1);
    909933
    910934        ZERO_STRUCT(sinfo);
     
    917941        CHECK_STATUS(status, NT_STATUS_OK);
    918942
    919         ret &= check_stream_list(cli, fname, 5, five2);
     943        ret &= check_stream_list(tctx, cli, fname, 5, five2);
    920944
    921945        ZERO_STRUCT(sinfo);
     
    928952        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
    929953
    930         ret &= check_stream_list(cli, fname, 5, five2);
     954        ret &= check_stream_list(tctx, cli, fname, 5, five2);
    931955
    932956        ZERO_STRUCT(sinfo);
     
    937961        sinfo.rename_information.in.new_name = ":MStream Two:$DATA";
    938962        status = smb_raw_setfileinfo(cli->tree, &sinfo);
    939         CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
    940 
    941         ret &= check_stream_list(cli, fname, 5, five2);
     963        if (torture_setting_bool(tctx, "samba4", false) ||
     964            torture_setting_bool(tctx, "samba3", false)) {
     965                /* why should this rename be considered invalid?? */
     966                CHECK_STATUS(status, NT_STATUS_OK);
     967                ret &= check_stream_list(tctx, cli, fname, 4, four);
     968        } else {
     969                CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
     970                ret &= check_stream_list(tctx, cli, fname, 5, five2);
     971        }
     972
    942973
    943974        /* TODO: we need to test more rename combinations */
     
    948979        if (fnum3 != -1) smbcli_close(cli->tree, fnum3);
    949980        status = smbcli_unlink(cli->tree, fname);
     981        smbcli_deltree(cli->tree, BASEDIR);
    950982        return ret;
    951983}
     
    955987*/
    956988static bool test_stream_names2(struct torture_context *tctx,
    957                                struct smbcli_state *cli,
    958                                TALLOC_CTX *mem_ctx)
     989                               struct smbcli_state *cli)
    959990{
    960991        NTSTATUS status;
     
    965996        uint8_t i;
    966997
     998        if (!torture_setup_dir(cli, BASEDIR)) {
     999                return false;
     1000        }
     1001
    9671002        printf("(%s) testing stream names\n", __location__);
    9681003        io.generic.level = RAW_OPEN_NTCREATEX;
    969         io.ntcreatex.in.root_fid = 0;
     1004        io.ntcreatex.in.root_fid.fnum = 0;
    9701005        io.ntcreatex.in.flags = 0;
    9711006        io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA;
     
    9781013        io.ntcreatex.in.security_flags = 0;
    9791014        io.ntcreatex.in.fname = fname;
    980         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1015        status = smb_raw_open(cli->tree, tctx, &io);
    9811016        CHECK_STATUS(status, NT_STATUS_OK);
    9821017        fnum1 = io.ntcreatex.out.file.fnum;
     
    10011036                io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
    10021037                io.ntcreatex.in.fname = path;
    1003                 status = smb_raw_open(cli->tree, mem_ctx, &io);
     1038                status = smb_raw_open(cli->tree, tctx, &io);
    10041039                if (!NT_STATUS_EQUAL(status, expected)) {
    10051040                        printf("(%s) %s:Stream%c0x%02X:$DATA%s => expected[%s]\n",
     
    10161051        if (fnum1 != -1) smbcli_close(cli->tree, fnum1);
    10171052        status = smbcli_unlink(cli->tree, fname);
     1053        smbcli_deltree(cli->tree, BASEDIR);
    10181054        return ret;
    10191055}
     
    10421078*/
    10431079static bool test_stream_rename(struct torture_context *tctx,
    1044                                    struct smbcli_state *cli,
    1045                                    TALLOC_CTX *mem_ctx)
     1080                                   struct smbcli_state *cli)
    10461081{
    10471082        NTSTATUS status, status2;
     
    10561091        const char *call_name;
    10571092
    1058         sname1 = talloc_asprintf(mem_ctx, "%s:%s", fname, "Stream One");
    1059         sname2 = talloc_asprintf(mem_ctx, "%s:%s:$DaTa", fname, "Second Stream");
     1093        if (!torture_setup_dir(cli, BASEDIR)) {
     1094                return false;
     1095        }
     1096
     1097        sname1 = talloc_asprintf(tctx, "%s:%s", fname, "Stream One");
     1098        sname2 = talloc_asprintf(tctx, "%s:%s:$DaTa", fname, "Second Stream");
    10601099
    10611100        printf("(%s) testing stream renames\n", __location__);
    10621101        io.generic.level = RAW_OPEN_NTCREATEX;
    1063         io.ntcreatex.in.root_fid = 0;
     1102        io.ntcreatex.in.root_fid.fnum = 0;
    10641103        io.ntcreatex.in.flags = 0;
    10651104        io.ntcreatex.in.access_mask = SEC_FILE_READ_ATTRIBUTE |
     
    10761115
    10771116        /* Create two streams. */
    1078         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1117        status = smb_raw_open(cli->tree, tctx, &io);
    10791118        CHECK_STATUS(status, NT_STATUS_OK);
    10801119        fnum = io.ntcreatex.out.file.fnum;
     
    10821121
    10831122        io.ntcreatex.in.fname = sname2;
    1084         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1123        status = smb_raw_open(cli->tree, tctx, &io);
    10851124        CHECK_STATUS(status, NT_STATUS_OK);
    10861125        fnum = io.ntcreatex.out.file.fnum;
     
    10941133        io.ntcreatex.in.access_mask = SEC_STD_DELETE;
    10951134        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
    1096         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1135        status = smb_raw_open(cli->tree, tctx, &io);
    10971136        CHECK_STATUS(status, NT_STATUS_OK);
    10981137        fnum = io.ntcreatex.out.file.fnum;
     
    11121151        if (fnum != -1) smbcli_close(cli->tree, fnum);
    11131152        status = smbcli_unlink(cli->tree, fname);
     1153        smbcli_deltree(cli->tree, BASEDIR);
    11141154        return ret;
    11151155}
    11161156
    11171157static bool test_stream_rename2(struct torture_context *tctx,
    1118                                struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
     1158                               struct smbcli_state *cli)
    11191159{
    11201160        NTSTATUS status;
     
    11321172        union smb_rename rio;
    11331173
    1134         sname1 = talloc_asprintf(mem_ctx, "%s:%s", fname1, "Stream One");
    1135         sname2 = talloc_asprintf(mem_ctx, "%s:%s", fname1, "Stream Two");
     1174        if (!torture_setup_dir(cli, BASEDIR)) {
     1175                return false;
     1176        }
     1177
     1178        sname1 = talloc_asprintf(tctx, "%s:%s", fname1, "Stream One");
     1179        sname2 = talloc_asprintf(tctx, "%s:%s", fname1, "Stream Two");
    11361180
    11371181        io.generic.level = RAW_OPEN_NTCREATEX;
    1138         io.ntcreatex.in.root_fid = 0;
     1182        io.ntcreatex.in.root_fid.fnum = 0;
    11391183        io.ntcreatex.in.flags = 0;
    11401184        io.ntcreatex.in.access_mask = (SEC_FILE_READ_DATA|SEC_FILE_WRITE_DATA|
     
    11521196
    11531197        /* Open/create new stream. */
    1154         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1198        status = smb_raw_open(cli->tree, tctx, &io);
    11551199        CHECK_STATUS(status, NT_STATUS_OK);
    11561200
     
    12071251        /* Create the file. */
    12081252        io.ntcreatex.in.fname = fname2;
    1209         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1253        status = smb_raw_open(cli->tree, tctx, &io);
    12101254        CHECK_STATUS(status, NT_STATUS_OK);
    12111255        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
     
    12221266        io.ntcreatex.in.fname = sname2;
    12231267        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
    1224         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1268        status = smb_raw_open(cli->tree, tctx, &io);
    12251269        CHECK_STATUS(status, NT_STATUS_OK);
    12261270        fnum = io.ntcreatex.out.file.fnum;
     
    12491293        io.ntcreatex.in.fname = sname2;
    12501294        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
    1251         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1295        status = smb_raw_open(cli->tree, tctx, &io);
    12521296        CHECK_STATUS(status, NT_STATUS_OK);
    12531297        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
     
    12661310        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
    12671311        io.ntcreatex.in.fname = sname2;
    1268         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1312        status = smb_raw_open(cli->tree, tctx, &io);
    12691313        CHECK_STATUS(status, NT_STATUS_OK);
    12701314        fnum = io.ntcreatex.out.file.fnum;
     
    13051349        status = smbcli_unlink(cli->tree, fname1);
    13061350        status = smbcli_unlink(cli->tree, fname2);
     1351        smbcli_deltree(cli->tree, BASEDIR);
    13071352        return ret;
    13081353}
    13091354
     1355/*
     1356  test stream renames
     1357*/
     1358static bool test_stream_rename3(struct torture_context *tctx,
     1359                                   struct smbcli_state *cli)
     1360{
     1361        NTSTATUS status, status2;
     1362        union smb_open io;
     1363        const char *fname = BASEDIR "\\stream_rename.txt";
     1364        const char *sname1, *sname2;
     1365        union smb_fileinfo finfo1;
     1366        union smb_setfileinfo sfinfo;
     1367        bool ret = true;
     1368        int fnum = -1;
     1369        int fnum2 = -1;
     1370        bool check_fnum;
     1371        const char *call_name;
     1372
     1373        if (!torture_setup_dir(cli, BASEDIR)) {
     1374                return false;
     1375        }
     1376
     1377        sname1 = talloc_asprintf(tctx, "%s:%s", fname, "MStream Two:$DATA");
     1378        sname2 = talloc_asprintf(tctx, "%s:%s:$DaTa", fname, "Second Stream");
     1379
     1380        printf("(%s) testing stream renames\n", __location__);
     1381        io.generic.level = RAW_OPEN_NTCREATEX;
     1382        io.ntcreatex.in.root_fid.fnum = 0;
     1383        io.ntcreatex.in.flags = 0;
     1384        io.ntcreatex.in.access_mask = SEC_FILE_READ_ATTRIBUTE |
     1385                                      SEC_FILE_WRITE_ATTRIBUTE |
     1386                                    SEC_RIGHTS_FILE_ALL;
     1387        io.ntcreatex.in.create_options = 0;
     1388        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     1389        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
     1390            NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
     1391        io.ntcreatex.in.alloc_size = 0;
     1392        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
     1393        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     1394        io.ntcreatex.in.security_flags = 0;
     1395        io.ntcreatex.in.fname = sname1;
     1396
     1397        /* Create two streams. */
     1398        status = smb_raw_open(cli->tree, tctx, &io);
     1399        CHECK_STATUS(status, NT_STATUS_OK);
     1400        fnum = io.ntcreatex.out.file.fnum;
     1401        if (fnum != -1) smbcli_close(cli->tree, fnum);
     1402
     1403        io.ntcreatex.in.fname = sname2;
     1404        status = smb_raw_open(cli->tree, tctx, &io);
     1405        CHECK_STATUS(status, NT_STATUS_OK);
     1406        fnum = io.ntcreatex.out.file.fnum;
     1407
     1408        if (fnum != -1) smbcli_close(cli->tree, fnum);
     1409
     1410        /* open the second stream. */
     1411        io.ntcreatex.in.access_mask = SEC_STD_DELETE;
     1412        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
     1413        status = smb_raw_open(cli->tree, tctx, &io);
     1414        CHECK_STATUS(status, NT_STATUS_OK);
     1415        fnum = io.ntcreatex.out.file.fnum;
     1416
     1417        /* Keep a handle to the first stream open. */
     1418        io.ntcreatex.in.fname = sname1;
     1419        io.ntcreatex.in.access_mask = SEC_STD_DELETE;
     1420        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
     1421        status = smb_raw_open(cli->tree, tctx, &io);
     1422        CHECK_STATUS(status, NT_STATUS_OK);
     1423        fnum2 = io.ntcreatex.out.file.fnum;
     1424
     1425        ZERO_STRUCT(sfinfo);
     1426        sfinfo.rename_information.in.overwrite = 1;
     1427        sfinfo.rename_information.in.root_fid  = 0;
     1428        sfinfo.rename_information.in.new_name  = ":MStream Two:$DATA";
     1429        if (torture_setting_bool(tctx, "samba4", false) ||
     1430            torture_setting_bool(tctx, "samba3", false)) {
     1431                CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
     1432        } else {
     1433                CHECK_CALL_FNUM(RENAME_INFORMATION,
     1434                    NT_STATUS_INVALID_PARAMETER);
     1435        }
     1436
     1437
     1438done:
     1439        if (fnum != -1) smbcli_close(cli->tree, fnum);
     1440        if (fnum2 != -1) smbcli_close(cli->tree, fnum2);
     1441        status = smbcli_unlink(cli->tree, fname);
     1442        smbcli_deltree(cli->tree, BASEDIR);
     1443        return ret;
     1444}
     1445
    13101446static bool create_file_with_stream(struct torture_context *tctx,
    13111447                                    struct smbcli_state *cli,
    1312                                     TALLOC_CTX *mem_ctx,
    13131448                                    const char *stream)
    13141449{
     
    13191454        /* Create a file with a stream */
    13201455        io.generic.level = RAW_OPEN_NTCREATEX;
    1321         io.ntcreatex.in.root_fid = 0;
     1456        io.ntcreatex.in.root_fid.fnum = 0;
    13221457        io.ntcreatex.in.flags = 0;
    13231458        io.ntcreatex.in.access_mask = (SEC_FILE_READ_DATA|SEC_FILE_WRITE_DATA|
     
    13321467        io.ntcreatex.in.fname = stream;
    13331468
    1334         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1469        status = smb_raw_open(cli->tree, tctx, &io);
    13351470        CHECK_STATUS(status, NT_STATUS_OK);
    13361471
     
    13421477/* Test how streams interact with create dispositions */
    13431478static bool test_stream_create_disposition(struct torture_context *tctx,
    1344                                            struct smbcli_state *cli,
    1345                                            TALLOC_CTX *mem_ctx)
     1479                                           struct smbcli_state *cli)
    13461480{
    13471481        NTSTATUS status;
     
    13521486        const char *default_stream_name = "::$DATA";
    13531487        const char *stream_list[2];
    1354         bool ret = true;
     1488        bool ret = false;
    13551489        int fnum = -1;
    13561490
    1357         fname_stream = talloc_asprintf(mem_ctx, "%s:%s", fname, stream);
    1358 
    1359         stream_list[0] = talloc_asprintf(mem_ctx, ":%s", stream);
     1491        if (!torture_setup_dir(cli, BASEDIR)) {
     1492                return false;
     1493        }
     1494
     1495        fname_stream = talloc_asprintf(tctx, "%s:%s", fname, stream);
     1496
     1497        stream_list[0] = talloc_asprintf(tctx, ":%s", stream);
    13601498        stream_list[1] = default_stream_name;
    13611499
    1362         if (!create_file_with_stream(tctx, cli, mem_ctx, fname_stream)) {
     1500        if (!create_file_with_stream(tctx, cli, fname_stream)) {
    13631501                goto done;
    13641502        }
     
    13661504        /* Open the base file with OPEN */
    13671505        io.generic.level = RAW_OPEN_NTCREATEX;
    1368         io.ntcreatex.in.root_fid = 0;
     1506        io.ntcreatex.in.root_fid.fnum = 0;
    13691507        io.ntcreatex.in.flags = 0;
    13701508        io.ntcreatex.in.access_mask = (SEC_FILE_READ_DATA|SEC_FILE_WRITE_DATA|
     
    13831521        printf("(%s) Checking ntcreatex disp: open\n", __location__);
    13841522        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
    1385         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1523        status = smb_raw_open(cli->tree, tctx, &io);
    13861524        CHECK_STATUS(status, NT_STATUS_OK);
    13871525        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    1388         if (!check_stream_list(cli, fname, 2, stream_list)) {
     1526        if (!check_stream_list(tctx, cli, fname, 2, stream_list)) {
    13891527                goto done;
    13901528        }
     
    13951533        printf("(%s) Checking ntcreatex disp: overwrite\n", __location__);
    13961534        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE;
    1397         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1535        status = smb_raw_open(cli->tree, tctx, &io);
    13981536        CHECK_STATUS(status, NT_STATUS_OK);
    13991537        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    1400         if (!check_stream_list(cli, fname, 1, &default_stream_name)) {
     1538        if (!check_stream_list(tctx, cli, fname, 1, &default_stream_name)) {
    14011539                goto done;
    14021540        }
     
    14071545        printf("(%s) Checking ntcreatex disp: overwrite_if\n", __location__);
    14081546        smbcli_unlink(cli->tree, fname);
    1409         if (!create_file_with_stream(tctx, cli, mem_ctx, fname_stream)) {
     1547        if (!create_file_with_stream(tctx, cli, fname_stream)) {
    14101548                goto done;
    14111549        }
    14121550
    14131551        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
    1414         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1552        status = smb_raw_open(cli->tree, tctx, &io);
    14151553        CHECK_STATUS(status, NT_STATUS_OK);
    14161554        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    1417         if (!check_stream_list(cli, fname, 1, &default_stream_name)) {
     1555        if (!check_stream_list(tctx, cli, fname, 1, &default_stream_name)) {
    14181556                goto done;
    14191557        }
     
    14241562        printf("(%s) Checking ntcreatex disp: supersede\n", __location__);
    14251563        smbcli_unlink(cli->tree, fname);
    1426         if (!create_file_with_stream(tctx, cli, mem_ctx, fname_stream)) {
     1564        if (!create_file_with_stream(tctx, cli, fname_stream)) {
    14271565                goto done;
    14281566        }
    14291567
    14301568        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_SUPERSEDE;
    1431         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1569        status = smb_raw_open(cli->tree, tctx, &io);
    14321570        CHECK_STATUS(status, NT_STATUS_OK);
    14331571        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    1434         if (!check_stream_list(cli, fname, 1, &default_stream_name)) {
     1572        if (!check_stream_list(tctx, cli, fname, 1, &default_stream_name)) {
    14351573                goto done;
    14361574        }
     
    14421580               __location__);
    14431581        smbcli_unlink(cli->tree, fname);
    1444         if (!create_file_with_stream(tctx, cli, mem_ctx, fname_stream)) {
     1582        if (!create_file_with_stream(tctx, cli, fname_stream)) {
    14451583                goto done;
    14461584        }
     
    14481586        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
    14491587        io.ntcreatex.in.fname = fname_stream;
    1450         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1588        status = smb_raw_open(cli->tree, tctx, &io);
    14511589        CHECK_STATUS(status, NT_STATUS_OK);
    14521590        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
    1453         if (!check_stream_list(cli, fname, 1, &default_stream_name)) {
     1591        if (!check_stream_list(tctx, cli, fname, 2, stream_list)) {
    14541592                goto done;
    14551593        }
     
    14601598        printf("(%s) Checking openx disp: overwrite_if\n", __location__);
    14611599        smbcli_unlink(cli->tree, fname);
    1462         if (!create_file_with_stream(tctx, cli, mem_ctx, fname_stream)) {
     1600        if (!create_file_with_stream(tctx, cli, fname_stream)) {
    14631601                goto done;
    14641602        }
     
    14661604        io.openx.level = RAW_OPEN_OPENX;
    14671605        io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
    1468         io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
     1606        io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPEN_FLAGS_DENY_NONE;
    14691607        io.openx.in.search_attrs = 0;
    14701608        io.openx.in.file_attrs = 0;
     
    14751613
    14761614        io.openx.in.open_func = OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE;
    1477         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1615        status = smb_raw_open(cli->tree, tctx, &io);
    14781616        CHECK_STATUS(status, NT_STATUS_OK);
    14791617        smbcli_close(cli->tree, io.openx.out.file.fnum);
    1480         if (!check_stream_list(cli, fname, 1, &default_stream_name)) {
    1481                 goto done;
    1482         }
     1618        if (!check_stream_list(tctx, cli, fname, 1, &default_stream_name)) {
     1619                goto done;
     1620        }
     1621
     1622        ret = true;
    14831623
    14841624 done:
    14851625        smbcli_close(cli->tree, fnum);
    14861626        smbcli_unlink(cli->tree, fname);
     1627        smbcli_deltree(cli->tree, BASEDIR);
    14871628        return ret;
    14881629}
     
    14901631/* Test streaminfo with enough streams on a file to fill up the buffer.  */
    14911632static bool test_stream_large_streaminfo(struct torture_context *tctx,
    1492                                          struct smbcli_state *cli,
    1493                                          TALLOC_CTX *mem_ctx)
     1633                                         struct smbcli_state *cli)
    14941634{
    14951635#define LONG_STREAM_SIZE 2
     
    15021642        union smb_fileinfo finfo;
    15031643
    1504         lstream_name = talloc_array(mem_ctx, char, LONG_STREAM_SIZE);
     1644        if (!torture_setup_dir(cli, BASEDIR)) {
     1645                return false;
     1646        }
     1647
     1648        lstream_name = talloc_array(tctx, char, LONG_STREAM_SIZE);
    15051649
    15061650        for (i = 0; i < LONG_STREAM_SIZE - 1; i++) {
     
    15091653        lstream_name[LONG_STREAM_SIZE - 1] = '\0';
    15101654
    1511         printf("(%s) Creating a file with a lot of streams\n", __location__);
     1655        torture_comment(tctx, "(%s) Creating a file with a lot of streams\n", __location__);
    15121656        for (i = 0; i < 10000; i++) {
    1513                 fname_stream = talloc_asprintf(mem_ctx, "%s:%s%d", fname,
     1657                fname_stream = talloc_asprintf(tctx, "%s:%s%d", fname,
    15141658                                               lstream_name, i);
    1515                 ret = create_file_with_stream(tctx, cli, mem_ctx,
    1516                                               fname_stream);
     1659                ret = create_file_with_stream(tctx, cli, fname_stream);
    15171660                if (!ret) {
    15181661                        goto done;
     
    15231666        finfo.generic.in.file.path = fname;
    15241667
    1525         status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
     1668        status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
    15261669        CHECK_STATUS(status, STATUS_BUFFER_OVERFLOW);
    15271670
    15281671 done:
    15291672        smbcli_unlink(cli->tree, fname);
     1673        smbcli_deltree(cli->tree, BASEDIR);
    15301674        return ret;
    15311675}
     
    15331677/* Test the effect of setting attributes on a stream. */
    15341678static bool test_stream_attributes(struct torture_context *tctx,
    1535                                          struct smbcli_state *cli,
    1536                                          TALLOC_CTX *mem_ctx)
     1679                                         struct smbcli_state *cli)
    15371680{
    15381681        bool ret = true;
     
    15471690        time_t basetime = (time(NULL) - 86400) & ~1;
    15481691
    1549         printf ("(%s) testing attribute setting on stream\n", __location__);
    1550 
    1551         fname_stream = talloc_asprintf(mem_ctx, "%s:%s", fname, stream);
     1692        if (!torture_setup_dir(cli, BASEDIR)) {
     1693                return false;
     1694        }
     1695
     1696        torture_comment(tctx, "(%s) testing attribute setting on stream\n", __location__);
     1697
     1698        fname_stream = talloc_asprintf(tctx, "%s:%s", fname, stream);
    15521699
    15531700        /* Create a file with a stream with attribute FILE_ATTRIBUTE_ARCHIVE. */
    1554         ret = create_file_with_stream(tctx, cli, mem_ctx, fname_stream);
     1701        ret = create_file_with_stream(tctx, cli, fname_stream);
    15551702        if (!ret) {
    15561703                goto done;
     
    15601707        finfo.generic.level = RAW_FILEINFO_BASIC_INFO;
    15611708        finfo.generic.in.file.path = fname;
    1562         status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
     1709        status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
    15631710        CHECK_STATUS(status, NT_STATUS_OK);
    15641711
     
    15741721
    15751722        io.generic.level = RAW_OPEN_NTCREATEX;
    1576         io.ntcreatex.in.root_fid = 0;
     1723        io.ntcreatex.in.root_fid.fnum = 0;
    15771724        io.ntcreatex.in.flags = 0;
    15781725        io.ntcreatex.in.access_mask = (SEC_FILE_READ_DATA|SEC_FILE_WRITE_DATA|
     
    15871734        io.ntcreatex.in.fname = fname_stream;
    15881735
    1589         status = smb_raw_open(cli->tree, mem_ctx, &io);
     1736        status = smb_raw_open(cli->tree, tctx, &io);
    15901737        CHECK_STATUS(status, NT_STATUS_OK);
    15911738
     
    16131760        finfo.generic.level = RAW_FILEINFO_ALL_INFO;
    16141761        finfo.generic.in.file.path = fname;
    1615         status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
     1762        status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
    16161763        if (!NT_STATUS_IS_OK(status)) {
    16171764                printf("(%s) %s pathinfo - %s\n", __location__, "SETATTRE", nt_errstr(status));
     
    16421789        }
    16431790        smbcli_unlink(cli->tree, fname);
     1791        smbcli_deltree(cli->tree, BASEDIR);
     1792        return ret;
     1793}
     1794
     1795/**
     1796 * A rough approximation of how a windows client creates the streams for use
     1797 * in the summary tab.
     1798 */
     1799static bool test_stream_summary_tab(struct torture_context *tctx,
     1800                                    struct smbcli_state *cli)
     1801{
     1802        bool ret = true;
     1803        NTSTATUS status;
     1804        union smb_open io;
     1805        const char *fname = BASEDIR "\\stream_summary.txt";
     1806        const char *stream = ":\005SummaryInformation:$DATA";
     1807        const char *fname_stream = NULL;
     1808        const char *tmp_stream = ":Updt_\005SummaryInformation:$DATA";
     1809        const char *fname_tmp_stream = NULL;
     1810        int fnum = -1;
     1811        union smb_fileinfo finfo;
     1812        union smb_rename rio;
     1813        ssize_t retsize;
     1814
     1815        if (!torture_setup_dir(cli, BASEDIR)) {
     1816                return false;
     1817        }
     1818
     1819        fname_stream = talloc_asprintf(tctx, "%s%s", fname, stream);
     1820        fname_tmp_stream = talloc_asprintf(tctx, "%s%s", fname,
     1821                                           tmp_stream);
     1822
     1823        /* Create summary info stream */
     1824        ret = create_file_with_stream(tctx, cli, fname_stream);
     1825        if (!ret) {
     1826                goto done;
     1827        }
     1828
     1829        /* Create summary info tmp update stream */
     1830        ret = create_file_with_stream(tctx, cli, fname_tmp_stream);
     1831        if (!ret) {
     1832                goto done;
     1833        }
     1834
     1835        /* Open tmp stream and write to it */
     1836        io.generic.level = RAW_OPEN_NTCREATEX;
     1837        io.ntcreatex.in.root_fid.fnum = 0;
     1838        io.ntcreatex.in.flags = 0;
     1839        io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA|SEC_FILE_WRITE_DATA;
     1840        io.ntcreatex.in.create_options = 0;
     1841        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     1842        io.ntcreatex.in.share_access = 0;
     1843        io.ntcreatex.in.alloc_size = 0;
     1844        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
     1845        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     1846        io.ntcreatex.in.security_flags = 0;
     1847        io.ntcreatex.in.fname = fname_tmp_stream;
     1848
     1849        status = smb_raw_open(cli->tree, tctx, &io);
     1850        CHECK_STATUS(status, NT_STATUS_OK);
     1851        fnum = io.ntcreatex.out.file.fnum;
     1852
     1853        retsize = smbcli_write(cli->tree, fnum, 0, "test data", 0, 9);
     1854        CHECK_VALUE(retsize, 9);
     1855
     1856        /* close the tmp stream. */
     1857        smbcli_close(cli->tree, fnum);
     1858        fnum = -1;
     1859
     1860        /* Delete the current stream */
     1861        smbcli_unlink(cli->tree, fname_stream);
     1862
     1863        /* Do the rename. */
     1864        rio.generic.level = RAW_RENAME_RENAME;
     1865        rio.rename.in.pattern1 = fname_tmp_stream;
     1866        rio.rename.in.pattern2 = stream;
     1867        rio.rename.in.attrib = FILE_ATTRIBUTE_SYSTEM |
     1868            FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY;
     1869        status = smb_raw_rename(cli->tree, &rio);
     1870        CHECK_STATUS(status, NT_STATUS_OK);
     1871
     1872        /* Try to open the tmp stream that we just renamed away. */
     1873        status = smb_raw_open(cli->tree, tctx, &io);
     1874        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
     1875
     1876        /* Query the base file to make sure it's still there.  */
     1877        finfo.generic.level = RAW_FILEINFO_BASIC_INFO;
     1878        finfo.generic.in.file.path = fname;
     1879
     1880        status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
     1881        CHECK_STATUS(status, NT_STATUS_OK);
     1882
     1883 done:
     1884
     1885        if (fnum != -1) {
     1886                smbcli_close(cli->tree, fnum);
     1887        }
     1888        smbcli_unlink(cli->tree, fname);
     1889
     1890        smbcli_deltree(cli->tree, BASEDIR);
    16441891        return ret;
    16451892}
     
    16481895   basic testing of streams calls
    16491896*/
    1650 bool torture_raw_streams(struct torture_context *torture,
    1651                          struct smbcli_state *cli)
     1897struct torture_suite *torture_raw_streams(TALLOC_CTX *tctx)
    16521898{
    1653         bool ret = true;
    1654 
    1655         if (!torture_setup_dir(cli, BASEDIR)) {
    1656                 return false;
    1657         }
    1658 
    1659         ret &= test_stream_dir(torture, cli, torture);
    1660         smb_raw_exit(cli->session);
    1661         ret &= test_stream_io(torture, cli, torture);
    1662         smb_raw_exit(cli->session);
    1663         ret &= test_stream_sharemodes(torture, cli, torture);
    1664         smb_raw_exit(cli->session);
    1665         if (!torture_setting_bool(torture, "samba4", false)) {
    1666                 ret &= test_stream_delete(torture, cli, torture);
    1667         }
    1668         ret &= test_stream_names(torture, cli, torture);
    1669         smb_raw_exit(cli->session);
    1670         ret &= test_stream_names2(torture, cli, torture);
    1671         smb_raw_exit(cli->session);
    1672         ret &= test_stream_rename(torture, cli, torture);
    1673         smb_raw_exit(cli->session);
    1674         ret &= test_stream_rename2(torture, cli, torture);
    1675         smb_raw_exit(cli->session);
    1676         ret &= test_stream_create_disposition(torture, cli, torture);
    1677         smb_raw_exit(cli->session);
    1678 
    1679         ret &= test_stream_attributes(torture, cli, torture);
    1680         smb_raw_exit(cli->session);
    1681 
    1682         /* ret &= test_stream_large_streaminfo(torture, cli, torture); */
    1683 /*      smb_raw_exit(cli->session); */
    1684 
    1685         smbcli_deltree(cli->tree, BASEDIR);
    1686 
    1687         return ret;
     1899        struct torture_suite *suite = torture_suite_create(tctx, "streams");
     1900
     1901        torture_suite_add_1smb_test(suite, "dir", test_stream_dir);
     1902        torture_suite_add_1smb_test(suite, "io", test_stream_io);
     1903        torture_suite_add_1smb_test(suite, "sharemodes", test_stream_sharemodes);
     1904        torture_suite_add_1smb_test(suite, "delete", test_stream_delete);
     1905        torture_suite_add_1smb_test(suite, "names", test_stream_names);
     1906        torture_suite_add_1smb_test(suite, "names2", test_stream_names2);
     1907        torture_suite_add_1smb_test(suite, "rename", test_stream_rename);
     1908        torture_suite_add_1smb_test(suite, "rename2", test_stream_rename2);
     1909        torture_suite_add_1smb_test(suite, "rename3", test_stream_rename3);
     1910        torture_suite_add_1smb_test(suite, "createdisp",
     1911            test_stream_create_disposition);
     1912        torture_suite_add_1smb_test(suite, "attr", test_stream_attributes);
     1913        torture_suite_add_1smb_test(suite, "sumtab", test_stream_summary_tab);
     1914
     1915        /* torture_suite_add_1smb_test(suite, "LARGESTREAMINFO", */
     1916        /*     test_stream_large_streaminfo); */
     1917
     1918        return suite;
    16881919}
  • trunk/server/source4/torture/raw/tconrate.c

    r414 r745  
    7171        struct smbcli_session_options session_options;
    7272
    73         lp_smbcli_options(tctx->lp_ctx, &options);
    74         lp_smbcli_session_options(tctx->lp_ctx, &session_options);
     73        lpcfg_smbcli_options(tctx->lp_ctx, &options);
     74        lpcfg_smbcli_session_options(tctx->lp_ctx, &session_options);
    7575
    7676        child = fork();
     
    9999
    100100                status = smbcli_full_connection(NULL, &cli,
    101                                 host, lp_smb_ports(tctx->lp_ctx), share,
    102                                 NULL, lp_socket_options(tctx->lp_ctx), cmdline_credentials,
    103                                 lp_resolve_context(tctx->lp_ctx),
     101                                host, lpcfg_smb_ports(tctx->lp_ctx), share,
     102                                NULL, lpcfg_socket_options(tctx->lp_ctx), cmdline_credentials,
     103                                lpcfg_resolve_context(tctx->lp_ctx),
    104104                                tctx->ev, &options, &session_options,
    105                                 lp_iconv_convenience(tctx->lp_ctx),
    106                                 lp_gensec_settings(tctx, tctx->lp_ctx));
     105                                lpcfg_gensec_settings(tctx, tctx->lp_ctx));
    107106
    108107                if (!NT_STATUS_IS_OK(status)) {
     
    125124static bool children_remain(void)
    126125{
     126        bool res;
     127
    127128        /* Reap as many children as possible. */
    128129        for (;;) {
     
    130131                if (ret == 0) {
    131132                        /* no children ready */
    132                         return true;
     133                        res = true;
     134                        break;
    133135                }
    134136                if (ret == -1) {
    135137                        /* no children left. maybe */
    136                         return errno == ECHILD ? false : true;
    137                 }
    138         }
    139 
    140         /* notreached */
    141         return false;
     138                        res = errno != ECHILD;
     139                        break;
     140                }
     141        }
     142        return res;
    142143}
    143144
  • trunk/server/source4/torture/raw/unlink.c

    r414 r745  
    328328
    329329        op.generic.level = RAW_OPEN_NTCREATEX;
    330         op.ntcreatex.in.root_fid = 0;
     330        op.ntcreatex.in.root_fid.fnum = 0;
    331331        op.ntcreatex.in.flags = 0;
    332332        op.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     
    360360
    361361        op.generic.level = RAW_OPEN_NTCREATEX;
    362         op.ntcreatex.in.root_fid = 0;
     362        op.ntcreatex.in.root_fid.fnum = 0;
    363363        op.ntcreatex.in.flags = 0;
    364364        op.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     
    395395
    396396        op.generic.level = RAW_OPEN_NTCREATEX;
    397         op.ntcreatex.in.root_fid = 0;
     397        op.ntcreatex.in.root_fid.fnum = 0;
    398398        op.ntcreatex.in.flags = 0;
    399399        op.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     
    436436
    437437
     438struct unlink_defer_cli_state {
     439        struct torture_context *tctx;
     440        struct smbcli_state *cli1;
     441};
     442
     443/*
     444 * A handler function for oplock break requests. Ack it as a break to none
     445 */
     446static bool oplock_handler_ack_to_none(struct smbcli_transport *transport,
     447                                       uint16_t tid, uint16_t fnum,
     448                                       uint8_t level, void *private_data)
     449{
     450        struct unlink_defer_cli_state *ud_cli_state =
     451            (struct unlink_defer_cli_state *)private_data;
     452        union smb_setfileinfo sfinfo;
     453        bool ret;
     454        struct smbcli_request *req = NULL;
     455
     456        torture_comment(ud_cli_state->tctx, "delete the file before sending "
     457                        "the ack.");
     458
     459        /* cli1: set delete on close */
     460        sfinfo.disposition_info.level = RAW_SFILEINFO_DISPOSITION_INFO;
     461        sfinfo.disposition_info.in.file.fnum = fnum;
     462        sfinfo.disposition_info.in.delete_on_close = 1;
     463        req = smb_raw_setfileinfo_send(ud_cli_state->cli1->tree, &sfinfo);
     464
     465        smbcli_close(ud_cli_state->cli1->tree, fnum);
     466
     467        torture_comment(ud_cli_state->tctx, "Acking the oplock to NONE\n");
     468
     469        ret = smbcli_oplock_ack(ud_cli_state->cli1->tree, fnum,
     470                                 OPLOCK_BREAK_TO_NONE);
     471
     472        return ret;
     473}
     474
     475static bool test_unlink_defer(struct torture_context *tctx,
     476                              struct smbcli_state *cli1,
     477                              struct smbcli_state *cli2)
     478{
     479        const char *fname = BASEDIR "\\test_unlink_defer.dat";
     480        NTSTATUS status;
     481        bool ret = true;
     482        union smb_open io;
     483        union smb_unlink unl;
     484        uint16_t fnum=0;
     485        struct unlink_defer_cli_state ud_cli_state = {};
     486
     487        if (!torture_setup_dir(cli1, BASEDIR)) {
     488                return false;
     489        }
     490
     491        /* cleanup */
     492        smbcli_unlink(cli1->tree, fname);
     493
     494        ud_cli_state.tctx = tctx;
     495        ud_cli_state.cli1 = cli1;
     496
     497        smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_none,
     498                              &ud_cli_state);
     499
     500        io.generic.level = RAW_OPEN_NTCREATEX;
     501        io.ntcreatex.in.root_fid.fnum = 0;
     502        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
     503        io.ntcreatex.in.alloc_size = 0;
     504        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
     505        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
     506            NTCREATEX_SHARE_ACCESS_WRITE |
     507            NTCREATEX_SHARE_ACCESS_DELETE;
     508        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
     509        io.ntcreatex.in.create_options = 0;
     510        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
     511        io.ntcreatex.in.security_flags = 0;
     512        io.ntcreatex.in.fname = fname;
     513
     514        /* cli1: open file with a batch oplock. */
     515        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
     516            NTCREATEX_FLAGS_REQUEST_OPLOCK |
     517            NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
     518
     519        status = smb_raw_open(cli1->tree, tctx, &io);
     520        CHECK_STATUS(status, NT_STATUS_OK);
     521        fnum = io.ntcreatex.out.file.fnum;
     522
     523        /* cli2: Try to unlink it, but block on the oplock */
     524        torture_comment(tctx, "Try an unlink (should defer the open\n");
     525        unl.unlink.in.pattern = fname;
     526        unl.unlink.in.attrib = 0;
     527        status = smb_raw_unlink(cli2->tree, &unl);
     528
     529done:
     530        smb_raw_exit(cli1->session);
     531        smb_raw_exit(cli2->session);
     532        smbcli_deltree(cli1->tree, BASEDIR);
     533        return ret;
     534}
     535
    438536/*
    439537   basic testing of unlink calls
     
    441539struct torture_suite *torture_raw_unlink(TALLOC_CTX *mem_ctx)
    442540{
    443         struct torture_suite *suite = torture_suite_create(mem_ctx, "UNLINK");
     541        struct torture_suite *suite = torture_suite_create(mem_ctx, "unlink");
    444542
    445543        torture_suite_add_1smb_test(suite, "unlink", test_unlink);
    446544        torture_suite_add_1smb_test(suite, "delete_on_close", test_delete_on_close);
     545        torture_suite_add_2smb_test(suite, "unlink-defer", test_unlink_defer);
    447546
    448547        return suite;
  • trunk/server/source4/torture/raw/write.c

    r414 r745  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   test suite for various write operations
    44
    55   Copyright (C) Andrew Tridgell 2003
    6    
     6
    77   This program is free software; you can redistribute it and/or modify
    88   it under the terms of the GNU General Public License as published by
    99   the Free Software Foundation; either version 3 of the License, or
    1010   (at your option) any later version.
    11    
     11
    1212   This program is distributed in the hope that it will be useful,
    1313   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1414   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1515   GNU General Public License for more details.
    16    
     16
    1717   You should have received a copy of the GNU General Public License
    1818   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2020
    2121#include "includes.h"
    22 #include "torture/torture.h"
    2322#include "libcli/raw/libcliraw.h"
    24 #include "libcli/raw/raw_proto.h"
    2523#include "system/time.h"
    2624#include "system/filesys.h"
     
    3028#define CHECK_STATUS(status, correct) do { \
    3129        if (!NT_STATUS_EQUAL(status, correct)) { \
    32                 printf("(%s) Incorrect status %s - should be %s\n", \
    33                        __location__, nt_errstr(status), nt_errstr(correct)); \
     30                torture_fail(tctx, talloc_asprintf(tctx, "(%s) Incorrect status %s - should be %s\n", \
     31                       __location__, nt_errstr(status), nt_errstr(correct))); \
    3432                ret = false; \
    3533                goto done; \
     
    3836#define CHECK_VALUE(v, correct) do { \
    3937        if ((v) != (correct)) { \
    40                 printf("(%s) Incorrect value %s=%d - should be %d\n", \
    41                        __location__, #v, v, correct); \
     38                torture_fail(tctx, talloc_asprintf(tctx, "(%s) Incorrect value %s=%d - should be %d\n", \
     39                       __location__, #v, v, correct)); \
    4240                ret = false; \
    4341                goto done; \
     
    4543
    4644#define CHECK_BUFFER(buf, seed, len) do { \
    47         if (!check_buffer(buf, seed, len, __location__)) { \
     45        if (!check_buffer(tctx, buf, seed, len, __location__)) { \
    4846                ret = false; \
    4947                goto done; \
     
    5654        CHECK_STATUS(status, NT_STATUS_OK); \
    5755        if ((v) != finfo.all_info.out.field) { \
    58                 printf("(%s) wrong value for field %s  %.0f - %.0f\n", \
     56                torture_comment(tctx, "(%s) wrong value for field %s  %.0f - %.0f\n", \
    5957                       __location__, #field, (double)v, (double)finfo.all_info.out.field); \
    6058                dump_all_info(tctx, &finfo); \
     
    6967  setup a random buffer based on a seed
    7068*/
    71 static void setup_buffer(uint8_t *buf, uint_t seed, int len)
     69static void setup_buffer(uint8_t *buf, unsigned int seed, int len)
    7270{
    7371        int i;
     
    7977  check a random buffer based on a seed
    8078*/
    81 static bool check_buffer(uint8_t *buf, uint_t seed, int len, const char *location)
     79static bool check_buffer(struct torture_context *tctx,
     80                         uint8_t *buf, unsigned int seed, int len, const char *location)
    8281{
    8382        int i;
     
    8685                uint8_t v = random();
    8786                if (buf[i] != v) {
    88                         printf("Buffer incorrect at %s! ofs=%d buf=0x%x correct=0x%x\n",
    89                                location, i, buf[i], v);
     87                        torture_fail(tctx, talloc_asprintf(tctx, "Buffer incorrect at %s! ofs=%d buf=0x%x correct=0x%x\n",
     88                               location, i, buf[i], v));
    9089                        return false;
    9190                }
     
    9796  test write ops
    9897*/
    99 static bool test_write(struct torture_context *tctx, 
    100                                            struct smbcli_state *cli)
     98static bool test_write(struct torture_context *tctx,
     99                       struct smbcli_state *cli)
    101100{
    102101        union smb_write io;
     
    107106        const int maxsize = 90000;
    108107        const char *fname = BASEDIR "\\test.txt";
    109         uint_t seed = time(NULL);
     108        unsigned int seed = time(NULL);
    110109        union smb_fileinfo finfo;
    111110
     
    113112
    114113        if (!torture_setup_dir(cli, BASEDIR)) {
    115                 return false;
    116         }
    117 
    118         printf("Testing RAW_WRITE_WRITE\n");
     114                torture_fail(tctx, "failed to setup basedir");
     115        }
     116
     117        torture_comment(tctx, "Testing RAW_WRITE_WRITE\n");
    119118        io.generic.level = RAW_WRITE_WRITE;
    120        
     119
    121120        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
    122121        if (fnum == -1) {
    123                 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
    124                 ret = false;
    125                 goto done;
    126         }
    127 
    128         printf("Trying zero write\n");
     122                ret = false;
     123                torture_fail_goto(tctx, done,
     124                        talloc_asprintf(tctx, "Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree)));
     125        }
     126
     127        torture_comment(tctx, "Trying zero write\n");
    129128        io.write.in.file.fnum = fnum;
    130129        io.write.in.count = 0;
     
    138137        setup_buffer(buf, seed, maxsize);
    139138
    140         printf("Trying small write\n");
     139        torture_comment(tctx, "Trying small write\n");
    141140        io.write.in.count = 9;
    142141        io.write.in.offset = 4;
     
    148147        memset(buf, 0, maxsize);
    149148        if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
    150                 printf("read failed at %s\n", __location__);
    151                 ret = false;
    152                 goto done;
     149                ret = false;
     150                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
    153151        }
    154152        CHECK_BUFFER(buf+4, seed, 9);
     
    157155        setup_buffer(buf, seed, maxsize);
    158156
    159         printf("Trying large write\n");
     157        torture_comment(tctx, "Trying large write\n");
    160158        io.write.in.count = 4000;
    161159        io.write.in.offset = 0;
     
    167165        memset(buf, 0, maxsize);
    168166        if (smbcli_read(cli->tree, fnum, buf, 0, 4000) != 4000) {
    169                 printf("read failed at %s\n", __location__);
    170                 ret = false;
    171                 goto done;
     167                ret = false;
     168                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
    172169        }
    173170        CHECK_BUFFER(buf, seed, 4000);
    174171
    175         printf("Trying bad fnum\n");
     172        torture_comment(tctx, "Trying bad fnum\n");
    176173        io.write.in.file.fnum = fnum+1;
    177174        io.write.in.count = 4000;
     
    181178        CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
    182179
    183         printf("Setting file as sparse\n");
     180        torture_comment(tctx, "Setting file as sparse\n");
    184181        status = torture_set_sparse(cli->tree, fnum);
    185182        CHECK_STATUS(status, NT_STATUS_OK);
    186183
    187184        if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
    188                 printf("skipping large file tests - CAP_LARGE_FILES not set\n");
     185                torture_comment(tctx, "skipping large file tests - CAP_LARGE_FILES not set\n");
    189186                goto done;
    190187        }
    191        
    192         if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
    193                 printf("skipping large file tests - CAP_LARGE_FILES not set\n");
    194                 goto done;
    195         }
    196 
    197         printf("Trying 2^32 offset\n");
     188
     189        torture_comment(tctx, "Trying 2^32 offset\n");
    198190        setup_buffer(buf, seed, maxsize);
    199191        io.write.in.file.fnum = fnum;
     
    205197        CHECK_VALUE(io.write.out.nwritten, 4000);
    206198        CHECK_ALL_INFO(io.write.in.count + (uint64_t)io.write.in.offset, size);
    207        
     199
    208200        memset(buf, 0, maxsize);
    209201        if (smbcli_read(cli->tree, fnum, buf, io.write.in.offset, 4000) != 4000) {
    210                 printf("read failed at %s\n", __location__);
    211                 ret = false;
    212                 goto done;
     202                ret = false;
     203                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
    213204        }
    214205        CHECK_BUFFER(buf, seed, 4000);
     
    225216  test writex ops
    226217*/
    227 static bool test_writex(struct torture_context *tctx, 
    228                                                 struct smbcli_state *cli)
     218static bool test_writex(struct torture_context *tctx,
     219                        struct smbcli_state *cli)
    229220{
    230221        union smb_write io;
     
    235226        const int maxsize = 90000;
    236227        const char *fname = BASEDIR "\\test.txt";
    237         uint_t seed = time(NULL);
     228        unsigned int seed = time(NULL);
    238229        union smb_fileinfo finfo;
    239230        int max_bits=63;
     
    246237        buf = talloc_zero_array(tctx, uint8_t, maxsize);
    247238
     239        if (!cli->transport->negotiate.lockread_supported) {
     240                torture_comment(tctx, "Server does not support writeunlock - skipping\n");
     241                return true;
     242        }
     243
    248244        if (!torture_setup_dir(cli, BASEDIR)) {
    249                 return false;
    250         }
    251 
    252         printf("Testing RAW_WRITE_WRITEX\n");
     245                torture_fail(tctx, "failed to setup basedir");
     246        }
     247
     248        torture_comment(tctx, "Testing RAW_WRITE_WRITEX\n");
    253249        io.generic.level = RAW_WRITE_WRITEX;
    254        
     250
    255251        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
    256252        if (fnum == -1) {
    257                 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
    258                 ret = false;
    259                 goto done;
    260         }
    261 
    262         printf("Trying zero write\n");
     253                ret = false;
     254                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree)));
     255        }
     256
     257        torture_comment(tctx, "Trying zero write\n");
    263258        io.writex.in.file.fnum = fnum;
    264259        io.writex.in.offset = 0;
     
    273268        setup_buffer(buf, seed, maxsize);
    274269
    275         printf("Trying small write\n");
     270        torture_comment(tctx, "Trying small write\n");
    276271        io.writex.in.count = 9;
    277272        io.writex.in.offset = 4;
     
    283278        memset(buf, 0, maxsize);
    284279        if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
    285                 printf("read failed at %s\n", __location__);
    286                 ret = false;
    287                 goto done;
     280                ret = false;
     281                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
    288282        }
    289283        CHECK_BUFFER(buf+4, seed, 9);
     
    292286        setup_buffer(buf, seed, maxsize);
    293287
    294         printf("Trying large write\n");
     288        torture_comment(tctx, "Trying large write\n");
    295289        io.writex.in.count = 4000;
    296290        io.writex.in.offset = 0;
     
    302296        memset(buf, 0, maxsize);
    303297        if (smbcli_read(cli->tree, fnum, buf, 0, 4000) != 4000) {
    304                 printf("read failed at %s\n", __location__);
    305                 ret = false;
    306                 goto done;
     298                ret = false;
     299                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
    307300        }
    308301        CHECK_BUFFER(buf, seed, 4000);
    309302
    310         printf("Trying bad fnum\n");
     303        torture_comment(tctx, "Trying bad fnum\n");
    311304        io.writex.in.file.fnum = fnum+1;
    312305        io.writex.in.count = 4000;
     
    316309        CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
    317310
    318         printf("Testing wmode\n");
     311        torture_comment(tctx, "Testing wmode\n");
    319312        io.writex.in.file.fnum = fnum;
    320313        io.writex.in.count = 1;
     
    332325
    333326
    334         printf("Trying locked region\n");
     327        torture_comment(tctx, "Trying locked region\n");
    335328        cli->session->pid++;
    336329        if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 3, 1, 0, WRITE_LOCK))) {
    337                 printf("Failed to lock file at %s\n", __location__);
    338                 ret = false;
    339                 goto done;
     330                ret = false;
     331                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "Failed to lock file at %s\n", __location__));
    340332        }
    341333        cli->session->pid--;
     
    346338        CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
    347339
    348         printf("Setting file as sparse\n");
     340        torture_comment(tctx, "Setting file as sparse\n");
    349341        status = torture_set_sparse(cli->tree, fnum);
    350342        CHECK_STATUS(status, NT_STATUS_OK);
    351        
     343
    352344        if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
    353                 printf("skipping large file tests - CAP_LARGE_FILES not set\n");
    354                 goto done;
    355         }
    356 
    357         printf("Trying 2^32 offset\n");
     345                torture_skip(tctx, "skipping large file tests - CAP_LARGE_FILES not set\n");
     346        }
     347
     348        torture_comment(tctx, "Trying 2^32 offset\n");
    358349        setup_buffer(buf, seed, maxsize);
    359350        io.writex.in.file.fnum = fnum;
     
    368359        memset(buf, 0, maxsize);
    369360        if (smbcli_read(cli->tree, fnum, buf, io.writex.in.offset, 4000) != 4000) {
    370                 printf("read failed at %s\n", __location__);
    371                 ret = false;
    372                 goto done;
     361                ret = false;
     362                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
    373363        }
    374364        CHECK_BUFFER(buf, seed, 4000);
    375365
    376366        for (i=33;i<max_bits;i++) {
    377                 printf("Trying 2^%d offset\n", i);
     367                torture_comment(tctx, "Trying 2^%d offset\n", i);
    378368                setup_buffer(buf, seed+1, maxsize);
    379369                io.writex.in.file.fnum = fnum;
     
    392382                memset(buf, 0, maxsize);
    393383                if (smbcli_read(cli->tree, fnum, buf, io.writex.in.offset, 4000) != 4000) {
    394                         printf("read failed at %s\n", __location__);
    395384                        ret = false;
    396                         goto done;
     385                        torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
    397386                }
    398387                CHECK_BUFFER(buf, seed+1, 4000);
    399388        }
    400         printf("limit is 2^%d\n", i);
     389        torture_comment(tctx, "limit is 2^%d\n", i);
    401390
    402391        setup_buffer(buf, seed, maxsize);
     
    413402  test write unlock ops
    414403*/
    415 static bool test_writeunlock(struct torture_context *tctx, 
    416                                                         struct smbcli_state *cli)
     404static bool test_writeunlock(struct torture_context *tctx,
     405                            struct smbcli_state *cli)
    417406{
    418407        union smb_write io;
     
    423412        const int maxsize = 90000;
    424413        const char *fname = BASEDIR "\\test.txt";
    425         uint_t seed = time(NULL);
     414        unsigned int seed = time(NULL);
    426415        union smb_fileinfo finfo;
    427416
    428417        buf = talloc_zero_array(tctx, uint8_t, maxsize);
    429418
     419        if (!cli->transport->negotiate.lockread_supported) {
     420                torture_skip(tctx, "Server does not support writeunlock - skipping\n");
     421        }
     422
    430423        if (!torture_setup_dir(cli, BASEDIR)) {
    431                 return false;
    432         }
    433 
    434         printf("Testing RAW_WRITE_WRITEUNLOCK\n");
     424                torture_fail(tctx, "failed to setup basedir");
     425        }
     426
     427        torture_comment(tctx, "Testing RAW_WRITE_WRITEUNLOCK\n");
    435428        io.generic.level = RAW_WRITE_WRITEUNLOCK;
    436        
     429
    437430        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
    438431        if (fnum == -1) {
    439                 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
    440                 ret = false;
    441                 goto done;
    442         }
    443 
    444         printf("Trying zero write\n");
     432                ret = false;
     433                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree)));
     434        }
     435
     436        torture_comment(tctx, "Trying zero write\n");
    445437        io.writeunlock.in.file.fnum = fnum;
    446438        io.writeunlock.in.count = 0;
     
    454446        setup_buffer(buf, seed, maxsize);
    455447
    456         printf("Trying small write\n");
     448        torture_comment(tctx, "Trying small write\n");
    457449        io.writeunlock.in.count = 9;
    458450        io.writeunlock.in.offset = 4;
     
    461453        CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
    462454        if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
    463                 printf("read failed at %s\n", __location__);
    464                 ret = false;
    465                 goto done;
     455                ret = false;
     456                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
    466457        }
    467458        CHECK_BUFFER(buf+4, seed, 9);
     
    469460
    470461        setup_buffer(buf, seed, maxsize);
    471         smbcli_lock(cli->tree, fnum, io.writeunlock.in.offset, io.writeunlock.in.count, 
     462        smbcli_lock(cli->tree, fnum, io.writeunlock.in.offset, io.writeunlock.in.count,
    472463                 0, WRITE_LOCK);
    473464        status = smb_raw_write(cli->tree, &io);
     
    477468        memset(buf, 0, maxsize);
    478469        if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
    479                 printf("read failed at %s\n", __location__);
    480                 ret = false;
    481                 goto done;
     470                ret = false;
     471                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
    482472        }
    483473        CHECK_BUFFER(buf+4, seed, 9);
     
    486476        setup_buffer(buf, seed, maxsize);
    487477
    488         printf("Trying large write\n");
     478        torture_comment(tctx, "Trying large write\n");
    489479        io.writeunlock.in.count = 4000;
    490480        io.writeunlock.in.offset = 0;
    491481        io.writeunlock.in.data = buf;
    492         smbcli_lock(cli->tree, fnum, io.writeunlock.in.offset, io.writeunlock.in.count, 
     482        smbcli_lock(cli->tree, fnum, io.writeunlock.in.offset, io.writeunlock.in.count,
    493483                 0, WRITE_LOCK);
    494484        status = smb_raw_write(cli->tree, &io);
     
    501491        memset(buf, 0, maxsize);
    502492        if (smbcli_read(cli->tree, fnum, buf, 0, 4000) != 4000) {
    503                 printf("read failed at %s\n", __location__);
    504                 ret = false;
    505                 goto done;
     493                ret = false;
     494                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
    506495        }
    507496        CHECK_BUFFER(buf, seed, 4000);
    508497
    509         printf("Trying bad fnum\n");
     498        torture_comment(tctx, "Trying bad fnum\n");
    510499        io.writeunlock.in.file.fnum = fnum+1;
    511500        io.writeunlock.in.count = 4000;
     
    515504        CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
    516505
    517         printf("Setting file as sparse\n");
     506        torture_comment(tctx, "Setting file as sparse\n");
    518507        status = torture_set_sparse(cli->tree, fnum);
    519508        CHECK_STATUS(status, NT_STATUS_OK);
    520        
     509
    521510        if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
    522                 printf("skipping large file tests - CAP_LARGE_FILES not set\n");
    523                 goto done;
    524         }
    525 
    526         printf("Trying 2^32 offset\n");
     511                torture_skip(tctx, "skipping large file tests - CAP_LARGE_FILES not set\n");
     512        }
     513
     514        torture_comment(tctx, "Trying 2^32 offset\n");
    527515        setup_buffer(buf, seed, maxsize);
    528516        io.writeunlock.in.file.fnum = fnum;
     
    530518        io.writeunlock.in.offset = 0xFFFFFFFF - 2000;
    531519        io.writeunlock.in.data = buf;
    532         smbcli_lock(cli->tree, fnum, io.writeunlock.in.offset, io.writeunlock.in.count, 
     520        smbcli_lock(cli->tree, fnum, io.writeunlock.in.offset, io.writeunlock.in.count,
    533521                 0, WRITE_LOCK);
    534522        status = smb_raw_write(cli->tree, &io);
     
    539527        memset(buf, 0, maxsize);
    540528        if (smbcli_read(cli->tree, fnum, buf, io.writeunlock.in.offset, 4000) != 4000) {
    541                 printf("read failed at %s\n", __location__);
    542                 ret = false;
    543                 goto done;
     529                ret = false;
     530                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
    544531        }
    545532        CHECK_BUFFER(buf, seed, 4000);
     
    556543  test write close ops
    557544*/
    558 static bool test_writeclose(struct torture_context *tctx, 
    559                                                         struct smbcli_state *cli)
     545static bool test_writeclose(struct torture_context *tctx,
     546                            struct smbcli_state *cli)
    560547{
    561548        union smb_write io;
     
    566553        const int maxsize = 90000;
    567554        const char *fname = BASEDIR "\\test.txt";
    568         uint_t seed = time(NULL);
     555        unsigned int seed = time(NULL);
    569556        union smb_fileinfo finfo;
    570557
    571558        buf = talloc_zero_array(tctx, uint8_t, maxsize);
    572559
     560        if (!torture_setting_bool(tctx, "writeclose_support", true)) {
     561                torture_skip(tctx, "Server does not support writeclose - skipping\n");
     562        }
     563
    573564        if (!torture_setup_dir(cli, BASEDIR)) {
    574                 return false;
    575         }
    576 
    577         printf("Testing RAW_WRITE_WRITECLOSE\n");
     565                torture_fail(tctx, "failed to setup basedir");
     566        }
     567
     568        torture_comment(tctx, "Testing RAW_WRITE_WRITECLOSE\n");
    578569        io.generic.level = RAW_WRITE_WRITECLOSE;
    579        
     570
    580571        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
    581572        if (fnum == -1) {
    582                 printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
    583                 ret = false;
    584                 goto done;
    585         }
    586 
    587         printf("Trying zero write\n");
     573                ret = false;
     574                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree)));
     575        }
     576
     577        torture_comment(tctx, "Trying zero write\n");
    588578        io.writeclose.in.file.fnum = fnum;
    589579        io.writeclose.in.count = 0;
     
    601591        setup_buffer(buf, seed, maxsize);
    602592
    603         printf("Trying small write\n");
     593        torture_comment(tctx, "Trying small write\n");
    604594        io.writeclose.in.count = 9;
    605595        io.writeclose.in.offset = 4;
     
    615605
    616606        if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
    617                 printf("read failed at %s\n", __location__);
    618                 ret = false;
    619                 goto done;
     607                ret = false;
     608                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
    620609        }
    621610        CHECK_BUFFER(buf+4, seed, 9);
     
    632621        memset(buf, 0, maxsize);
    633622        if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
    634                 printf("read failed at %s\n", __location__);
    635                 ret = false;
    636                 goto done;
     623                ret = false;
     624                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
    637625        }
    638626        CHECK_BUFFER(buf+4, seed, 9);
     
    641629        setup_buffer(buf, seed, maxsize);
    642630
    643         printf("Trying large write\n");
     631        torture_comment(tctx, "Trying large write\n");
    644632        io.writeclose.in.count = 4000;
    645633        io.writeclose.in.offset = 0;
     
    657645        memset(buf, 0, maxsize);
    658646        if (smbcli_read(cli->tree, fnum, buf, 0, 4000) != 4000) {
    659                 printf("read failed at %s\n", __location__);
    660                 ret = false;
    661                 goto done;
     647                ret = false;
     648                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
    662649        }
    663650        CHECK_BUFFER(buf, seed, 4000);
    664651
    665         printf("Trying bad fnum\n");
     652        torture_comment(tctx, "Trying bad fnum\n");
    666653        io.writeclose.in.file.fnum = fnum+1;
    667654        io.writeclose.in.count = 4000;
     
    671658        CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
    672659
    673         printf("Setting file as sparse\n");
     660        torture_comment(tctx, "Setting file as sparse\n");
    674661        status = torture_set_sparse(cli->tree, fnum);
    675662        CHECK_STATUS(status, NT_STATUS_OK);
    676        
     663
    677664        if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
    678                 printf("skipping large file tests - CAP_LARGE_FILES not set\n");
    679                 goto done;
    680         }
    681 
    682         printf("Trying 2^32 offset\n");
     665                torture_skip(tctx, "skipping large file tests - CAP_LARGE_FILES not set\n");
     666        }
     667
     668        torture_comment(tctx, "Trying 2^32 offset\n");
    683669        setup_buffer(buf, seed, maxsize);
    684670        io.writeclose.in.file.fnum = fnum;
     
    696682        memset(buf, 0, maxsize);
    697683        if (smbcli_read(cli->tree, fnum, buf, io.writeclose.in.offset, 4000) != 4000) {
    698                 printf("read failed at %s\n", __location__);
    699                 ret = false;
    700                 goto done;
     684                ret = false;
     685                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
    701686        }
    702687        CHECK_BUFFER(buf, seed, 4000);
     
    709694}
    710695
    711 /* 
     696/*
    712697   basic testing of write calls
    713698*/
    714699struct torture_suite *torture_raw_write(TALLOC_CTX *mem_ctx)
    715700{
    716         struct torture_suite *suite = torture_suite_create(mem_ctx, "WRITE");
     701        struct torture_suite *suite = torture_suite_create(mem_ctx, "write");
    717702
    718703        torture_suite_add_1smb_test(suite, "write", test_write);
Note: See TracChangeset for help on using the changeset viewer.