~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source4/torture/raw/write.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
 
1
/*
2
2
   Unix SMB/CIFS implementation.
3
3
   test suite for various write operations
4
4
 
5
5
   Copyright (C) Andrew Tridgell 2003
6
 
   
 
6
 
7
7
   This program is free software; you can redistribute it and/or modify
8
8
   it under the terms of the GNU General Public License as published by
9
9
   the Free Software Foundation; either version 3 of the License, or
10
10
   (at your option) any later version.
11
 
   
 
11
 
12
12
   This program is distributed in the hope that it will be useful,
13
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
15
   GNU General Public License for more details.
16
 
   
 
16
 
17
17
   You should have received a copy of the GNU General Public License
18
18
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
19
*/
20
20
 
21
21
#include "includes.h"
22
 
#include "torture/torture.h"
23
22
#include "libcli/raw/libcliraw.h"
24
 
#include "libcli/raw/raw_proto.h"
25
23
#include "system/time.h"
26
24
#include "system/filesys.h"
27
25
#include "libcli/libcli.h"
29
27
 
30
28
#define CHECK_STATUS(status, correct) do { \
31
29
        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))); \
34
32
                ret = false; \
35
33
                goto done; \
36
34
        }} while (0)
37
35
 
38
36
#define CHECK_VALUE(v, correct) do { \
39
37
        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)); \
42
40
                ret = false; \
43
41
                goto done; \
44
42
        }} while (0)
45
43
 
46
44
#define CHECK_BUFFER(buf, seed, len) do { \
47
 
        if (!check_buffer(buf, seed, len, __location__)) { \
 
45
        if (!check_buffer(tctx, buf, seed, len, __location__)) { \
48
46
                ret = false; \
49
47
                goto done; \
50
48
        }} while (0)
55
53
        status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
56
54
        CHECK_STATUS(status, NT_STATUS_OK); \
57
55
        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", \
59
57
                       __location__, #field, (double)v, (double)finfo.all_info.out.field); \
60
58
                dump_all_info(tctx, &finfo); \
61
59
                ret = false; \
68
66
/*
69
67
  setup a random buffer based on a seed
70
68
*/
71
 
static void setup_buffer(uint8_t *buf, uint_t seed, int len)
 
69
static void setup_buffer(uint8_t *buf, unsigned int seed, int len)
72
70
{
73
71
        int i;
74
72
        srandom(seed);
78
76
/*
79
77
  check a random buffer based on a seed
80
78
*/
81
 
static bool check_buffer(uint8_t *buf, uint_t seed, int len, const char *location)
 
79
static bool check_buffer(struct torture_context *tctx,
 
80
                         uint8_t *buf, unsigned int seed, int len, const char *location)
82
81
{
83
82
        int i;
84
83
        srandom(seed);
85
84
        for (i=0;i<len;i++) {
86
85
                uint8_t v = random();
87
86
                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));
90
89
                        return false;
91
90
                }
92
91
        }
96
95
/*
97
96
  test write ops
98
97
*/
99
 
static bool test_write(struct torture_context *tctx, 
100
 
                                           struct smbcli_state *cli)
 
98
static bool test_write(struct torture_context *tctx,
 
99
                       struct smbcli_state *cli)
101
100
{
102
101
        union smb_write io;
103
102
        NTSTATUS status;
106
105
        uint8_t *buf;
107
106
        const int maxsize = 90000;
108
107
        const char *fname = BASEDIR "\\test.txt";
109
 
        uint_t seed = time(NULL);
 
108
        unsigned int seed = time(NULL);
110
109
        union smb_fileinfo finfo;
111
110
 
112
111
        buf = talloc_zero_array(tctx, uint8_t, maxsize);
113
112
 
114
113
        if (!torture_setup_dir(cli, BASEDIR)) {
115
 
                return false;
 
114
                torture_fail(tctx, "failed to setup basedir");
116
115
        }
117
116
 
118
 
        printf("Testing RAW_WRITE_WRITE\n");
 
117
        torture_comment(tctx, "Testing RAW_WRITE_WRITE\n");
119
118
        io.generic.level = RAW_WRITE_WRITE;
120
 
        
 
119
 
121
120
        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
122
121
        if (fnum == -1) {
123
 
                printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
124
122
                ret = false;
125
 
                goto done;
 
123
                torture_fail_goto(tctx, done,
 
124
                        talloc_asprintf(tctx, "Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree)));
126
125
        }
127
126
 
128
 
        printf("Trying zero write\n");
 
127
        torture_comment(tctx, "Trying zero write\n");
129
128
        io.write.in.file.fnum = fnum;
130
129
        io.write.in.count = 0;
131
130
        io.write.in.offset = 0;
137
136
 
138
137
        setup_buffer(buf, seed, maxsize);
139
138
 
140
 
        printf("Trying small write\n");
 
139
        torture_comment(tctx, "Trying small write\n");
141
140
        io.write.in.count = 9;
142
141
        io.write.in.offset = 4;
143
142
        io.write.in.data = buf;
147
146
 
148
147
        memset(buf, 0, maxsize);
149
148
        if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
150
 
                printf("read failed at %s\n", __location__);
151
149
                ret = false;
152
 
                goto done;
 
150
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
153
151
        }
154
152
        CHECK_BUFFER(buf+4, seed, 9);
155
153
        CHECK_VALUE(IVAL(buf,0), 0);
156
154
 
157
155
        setup_buffer(buf, seed, maxsize);
158
156
 
159
 
        printf("Trying large write\n");
 
157
        torture_comment(tctx, "Trying large write\n");
160
158
        io.write.in.count = 4000;
161
159
        io.write.in.offset = 0;
162
160
        io.write.in.data = buf;
166
164
 
167
165
        memset(buf, 0, maxsize);
168
166
        if (smbcli_read(cli->tree, fnum, buf, 0, 4000) != 4000) {
169
 
                printf("read failed at %s\n", __location__);
170
167
                ret = false;
171
 
                goto done;
 
168
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
172
169
        }
173
170
        CHECK_BUFFER(buf, seed, 4000);
174
171
 
175
 
        printf("Trying bad fnum\n");
 
172
        torture_comment(tctx, "Trying bad fnum\n");
176
173
        io.write.in.file.fnum = fnum+1;
177
174
        io.write.in.count = 4000;
178
175
        io.write.in.offset = 0;
180
177
        status = smb_raw_write(cli->tree, &io);
181
178
        CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
182
179
 
183
 
        printf("Setting file as sparse\n");
 
180
        torture_comment(tctx, "Setting file as sparse\n");
184
181
        status = torture_set_sparse(cli->tree, fnum);
185
182
        CHECK_STATUS(status, NT_STATUS_OK);
186
183
 
187
184
        if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
188
 
                printf("skipping large file tests - CAP_LARGE_FILES not set\n");
189
 
                goto done;
190
 
        }
191
 
        
192
 
        if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
193
 
                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");
194
186
                goto done;
195
187
        }
196
188
 
197
 
        printf("Trying 2^32 offset\n");
 
189
        torture_comment(tctx, "Trying 2^32 offset\n");
198
190
        setup_buffer(buf, seed, maxsize);
199
191
        io.write.in.file.fnum = fnum;
200
192
        io.write.in.count = 4000;
204
196
        CHECK_STATUS(status, NT_STATUS_OK);
205
197
        CHECK_VALUE(io.write.out.nwritten, 4000);
206
198
        CHECK_ALL_INFO(io.write.in.count + (uint64_t)io.write.in.offset, size);
207
 
        
 
199
 
208
200
        memset(buf, 0, maxsize);
209
201
        if (smbcli_read(cli->tree, fnum, buf, io.write.in.offset, 4000) != 4000) {
210
 
                printf("read failed at %s\n", __location__);
211
202
                ret = false;
212
 
                goto done;
 
203
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
213
204
        }
214
205
        CHECK_BUFFER(buf, seed, 4000);
215
206
 
224
215
/*
225
216
  test writex ops
226
217
*/
227
 
static bool test_writex(struct torture_context *tctx, 
228
 
                                                struct smbcli_state *cli)
 
218
static bool test_writex(struct torture_context *tctx,
 
219
                        struct smbcli_state *cli)
229
220
{
230
221
        union smb_write io;
231
222
        NTSTATUS status;
234
225
        uint8_t *buf;
235
226
        const int maxsize = 90000;
236
227
        const char *fname = BASEDIR "\\test.txt";
237
 
        uint_t seed = time(NULL);
 
228
        unsigned int seed = time(NULL);
238
229
        union smb_fileinfo finfo;
239
230
        int max_bits=63;
240
231
 
245
236
 
246
237
        buf = talloc_zero_array(tctx, uint8_t, maxsize);
247
238
 
 
239
        if (!cli->transport->negotiate.lockread_supported) {
 
240
                torture_comment(tctx, "Server does not support writeunlock - skipping\n");
 
241
                return true;
 
242
        }
 
243
 
248
244
        if (!torture_setup_dir(cli, BASEDIR)) {
249
 
                return false;
 
245
                torture_fail(tctx, "failed to setup basedir");
250
246
        }
251
247
 
252
 
        printf("Testing RAW_WRITE_WRITEX\n");
 
248
        torture_comment(tctx, "Testing RAW_WRITE_WRITEX\n");
253
249
        io.generic.level = RAW_WRITE_WRITEX;
254
 
        
 
250
 
255
251
        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
256
252
        if (fnum == -1) {
257
 
                printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
258
253
                ret = false;
259
 
                goto done;
 
254
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree)));
260
255
        }
261
256
 
262
 
        printf("Trying zero write\n");
 
257
        torture_comment(tctx, "Trying zero write\n");
263
258
        io.writex.in.file.fnum = fnum;
264
259
        io.writex.in.offset = 0;
265
260
        io.writex.in.wmode = 0;
272
267
 
273
268
        setup_buffer(buf, seed, maxsize);
274
269
 
275
 
        printf("Trying small write\n");
 
270
        torture_comment(tctx, "Trying small write\n");
276
271
        io.writex.in.count = 9;
277
272
        io.writex.in.offset = 4;
278
273
        io.writex.in.data = buf;
282
277
 
283
278
        memset(buf, 0, maxsize);
284
279
        if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
285
 
                printf("read failed at %s\n", __location__);
286
280
                ret = false;
287
 
                goto done;
 
281
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
288
282
        }
289
283
        CHECK_BUFFER(buf+4, seed, 9);
290
284
        CHECK_VALUE(IVAL(buf,0), 0);
291
285
 
292
286
        setup_buffer(buf, seed, maxsize);
293
287
 
294
 
        printf("Trying large write\n");
 
288
        torture_comment(tctx, "Trying large write\n");
295
289
        io.writex.in.count = 4000;
296
290
        io.writex.in.offset = 0;
297
291
        io.writex.in.data = buf;
301
295
 
302
296
        memset(buf, 0, maxsize);
303
297
        if (smbcli_read(cli->tree, fnum, buf, 0, 4000) != 4000) {
304
 
                printf("read failed at %s\n", __location__);
305
298
                ret = false;
306
 
                goto done;
 
299
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
307
300
        }
308
301
        CHECK_BUFFER(buf, seed, 4000);
309
302
 
310
 
        printf("Trying bad fnum\n");
 
303
        torture_comment(tctx, "Trying bad fnum\n");
311
304
        io.writex.in.file.fnum = fnum+1;
312
305
        io.writex.in.count = 4000;
313
306
        io.writex.in.offset = 0;
315
308
        status = smb_raw_write(cli->tree, &io);
316
309
        CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
317
310
 
318
 
        printf("Testing wmode\n");
 
311
        torture_comment(tctx, "Testing wmode\n");
319
312
        io.writex.in.file.fnum = fnum;
320
313
        io.writex.in.count = 1;
321
314
        io.writex.in.offset = 0;
331
324
        CHECK_VALUE(io.writex.out.nwritten, io.writex.in.count);
332
325
 
333
326
 
334
 
        printf("Trying locked region\n");
 
327
        torture_comment(tctx, "Trying locked region\n");
335
328
        cli->session->pid++;
336
329
        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
330
                ret = false;
339
 
                goto done;
 
331
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "Failed to lock file at %s\n", __location__));
340
332
        }
341
333
        cli->session->pid--;
342
334
        io.writex.in.wmode = 0;
345
337
        status = smb_raw_write(cli->tree, &io);
346
338
        CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);
347
339
 
348
 
        printf("Setting file as sparse\n");
 
340
        torture_comment(tctx, "Setting file as sparse\n");
349
341
        status = torture_set_sparse(cli->tree, fnum);
350
342
        CHECK_STATUS(status, NT_STATUS_OK);
351
 
        
 
343
 
352
344
        if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
353
 
                printf("skipping large file tests - CAP_LARGE_FILES not set\n");
354
 
                goto done;
 
345
                torture_skip(tctx, "skipping large file tests - CAP_LARGE_FILES not set\n");
355
346
        }
356
347
 
357
 
        printf("Trying 2^32 offset\n");
 
348
        torture_comment(tctx, "Trying 2^32 offset\n");
358
349
        setup_buffer(buf, seed, maxsize);
359
350
        io.writex.in.file.fnum = fnum;
360
351
        io.writex.in.count = 4000;
367
358
 
368
359
        memset(buf, 0, maxsize);
369
360
        if (smbcli_read(cli->tree, fnum, buf, io.writex.in.offset, 4000) != 4000) {
370
 
                printf("read failed at %s\n", __location__);
371
361
                ret = false;
372
 
                goto done;
 
362
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
373
363
        }
374
364
        CHECK_BUFFER(buf, seed, 4000);
375
365
 
376
366
        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);
378
368
                setup_buffer(buf, seed+1, maxsize);
379
369
                io.writex.in.file.fnum = fnum;
380
370
                io.writex.in.count = 4000;
391
381
 
392
382
                memset(buf, 0, maxsize);
393
383
                if (smbcli_read(cli->tree, fnum, buf, io.writex.in.offset, 4000) != 4000) {
394
 
                        printf("read failed at %s\n", __location__);
395
384
                        ret = false;
396
 
                        goto done;
 
385
                        torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
397
386
                }
398
387
                CHECK_BUFFER(buf, seed+1, 4000);
399
388
        }
400
 
        printf("limit is 2^%d\n", i);
 
389
        torture_comment(tctx, "limit is 2^%d\n", i);
401
390
 
402
391
        setup_buffer(buf, seed, maxsize);
403
392
 
412
401
/*
413
402
  test write unlock ops
414
403
*/
415
 
static bool test_writeunlock(struct torture_context *tctx, 
416
 
                                                         struct smbcli_state *cli)
 
404
static bool test_writeunlock(struct torture_context *tctx,
 
405
                             struct smbcli_state *cli)
417
406
{
418
407
        union smb_write io;
419
408
        NTSTATUS status;
422
411
        uint8_t *buf;
423
412
        const int maxsize = 90000;
424
413
        const char *fname = BASEDIR "\\test.txt";
425
 
        uint_t seed = time(NULL);
 
414
        unsigned int seed = time(NULL);
426
415
        union smb_fileinfo finfo;
427
416
 
428
417
        buf = talloc_zero_array(tctx, uint8_t, maxsize);
429
418
 
 
419
        if (!cli->transport->negotiate.lockread_supported) {
 
420
                torture_skip(tctx, "Server does not support writeunlock - skipping\n");
 
421
        }
 
422
 
430
423
        if (!torture_setup_dir(cli, BASEDIR)) {
431
 
                return false;
 
424
                torture_fail(tctx, "failed to setup basedir");
432
425
        }
433
426
 
434
 
        printf("Testing RAW_WRITE_WRITEUNLOCK\n");
 
427
        torture_comment(tctx, "Testing RAW_WRITE_WRITEUNLOCK\n");
435
428
        io.generic.level = RAW_WRITE_WRITEUNLOCK;
436
 
        
 
429
 
437
430
        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
438
431
        if (fnum == -1) {
439
 
                printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
440
432
                ret = false;
441
 
                goto done;
 
433
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree)));
442
434
        }
443
435
 
444
 
        printf("Trying zero write\n");
 
436
        torture_comment(tctx, "Trying zero write\n");
445
437
        io.writeunlock.in.file.fnum = fnum;
446
438
        io.writeunlock.in.count = 0;
447
439
        io.writeunlock.in.offset = 0;
453
445
 
454
446
        setup_buffer(buf, seed, maxsize);
455
447
 
456
 
        printf("Trying small write\n");
 
448
        torture_comment(tctx, "Trying small write\n");
457
449
        io.writeunlock.in.count = 9;
458
450
        io.writeunlock.in.offset = 4;
459
451
        io.writeunlock.in.data = buf;
460
452
        status = smb_raw_write(cli->tree, &io);
461
453
        CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
462
454
        if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
463
 
                printf("read failed at %s\n", __location__);
464
455
                ret = false;
465
 
                goto done;
 
456
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
466
457
        }
467
458
        CHECK_BUFFER(buf+4, seed, 9);
468
459
        CHECK_VALUE(IVAL(buf,0), 0);
469
460
 
470
461
        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,
472
463
                 0, WRITE_LOCK);
473
464
        status = smb_raw_write(cli->tree, &io);
474
465
        CHECK_STATUS(status, NT_STATUS_OK);
476
467
 
477
468
        memset(buf, 0, maxsize);
478
469
        if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
479
 
                printf("read failed at %s\n", __location__);
480
470
                ret = false;
481
 
                goto done;
 
471
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
482
472
        }
483
473
        CHECK_BUFFER(buf+4, seed, 9);
484
474
        CHECK_VALUE(IVAL(buf,0), 0);
485
475
 
486
476
        setup_buffer(buf, seed, maxsize);
487
477
 
488
 
        printf("Trying large write\n");
 
478
        torture_comment(tctx, "Trying large write\n");
489
479
        io.writeunlock.in.count = 4000;
490
480
        io.writeunlock.in.offset = 0;
491
481
        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,
493
483
                 0, WRITE_LOCK);
494
484
        status = smb_raw_write(cli->tree, &io);
495
485
        CHECK_STATUS(status, NT_STATUS_OK);
500
490
 
501
491
        memset(buf, 0, maxsize);
502
492
        if (smbcli_read(cli->tree, fnum, buf, 0, 4000) != 4000) {
503
 
                printf("read failed at %s\n", __location__);
504
493
                ret = false;
505
 
                goto done;
 
494
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
506
495
        }
507
496
        CHECK_BUFFER(buf, seed, 4000);
508
497
 
509
 
        printf("Trying bad fnum\n");
 
498
        torture_comment(tctx, "Trying bad fnum\n");
510
499
        io.writeunlock.in.file.fnum = fnum+1;
511
500
        io.writeunlock.in.count = 4000;
512
501
        io.writeunlock.in.offset = 0;
514
503
        status = smb_raw_write(cli->tree, &io);
515
504
        CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
516
505
 
517
 
        printf("Setting file as sparse\n");
 
506
        torture_comment(tctx, "Setting file as sparse\n");
518
507
        status = torture_set_sparse(cli->tree, fnum);
519
508
        CHECK_STATUS(status, NT_STATUS_OK);
520
 
        
 
509
 
521
510
        if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
522
 
                printf("skipping large file tests - CAP_LARGE_FILES not set\n");
523
 
                goto done;
 
511
                torture_skip(tctx, "skipping large file tests - CAP_LARGE_FILES not set\n");
524
512
        }
525
513
 
526
 
        printf("Trying 2^32 offset\n");
 
514
        torture_comment(tctx, "Trying 2^32 offset\n");
527
515
        setup_buffer(buf, seed, maxsize);
528
516
        io.writeunlock.in.file.fnum = fnum;
529
517
        io.writeunlock.in.count = 4000;
530
518
        io.writeunlock.in.offset = 0xFFFFFFFF - 2000;
531
519
        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,
533
521
                 0, WRITE_LOCK);
534
522
        status = smb_raw_write(cli->tree, &io);
535
523
        CHECK_STATUS(status, NT_STATUS_OK);
538
526
 
539
527
        memset(buf, 0, maxsize);
540
528
        if (smbcli_read(cli->tree, fnum, buf, io.writeunlock.in.offset, 4000) != 4000) {
541
 
                printf("read failed at %s\n", __location__);
542
529
                ret = false;
543
 
                goto done;
 
530
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
544
531
        }
545
532
        CHECK_BUFFER(buf, seed, 4000);
546
533
 
555
542
/*
556
543
  test write close ops
557
544
*/
558
 
static bool test_writeclose(struct torture_context *tctx, 
559
 
                                                        struct smbcli_state *cli)
 
545
static bool test_writeclose(struct torture_context *tctx,
 
546
                            struct smbcli_state *cli)
560
547
{
561
548
        union smb_write io;
562
549
        NTSTATUS status;
565
552
        uint8_t *buf;
566
553
        const int maxsize = 90000;
567
554
        const char *fname = BASEDIR "\\test.txt";
568
 
        uint_t seed = time(NULL);
 
555
        unsigned int seed = time(NULL);
569
556
        union smb_fileinfo finfo;
570
557
 
571
558
        buf = talloc_zero_array(tctx, uint8_t, maxsize);
572
559
 
 
560
        if (!torture_setting_bool(tctx, "writeclose_support", true)) {
 
561
                torture_skip(tctx, "Server does not support writeclose - skipping\n");
 
562
        }
 
563
 
573
564
        if (!torture_setup_dir(cli, BASEDIR)) {
574
 
                return false;
 
565
                torture_fail(tctx, "failed to setup basedir");
575
566
        }
576
567
 
577
 
        printf("Testing RAW_WRITE_WRITECLOSE\n");
 
568
        torture_comment(tctx, "Testing RAW_WRITE_WRITECLOSE\n");
578
569
        io.generic.level = RAW_WRITE_WRITECLOSE;
579
 
        
 
570
 
580
571
        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
581
572
        if (fnum == -1) {
582
 
                printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
583
573
                ret = false;
584
 
                goto done;
 
574
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree)));
585
575
        }
586
576
 
587
 
        printf("Trying zero write\n");
 
577
        torture_comment(tctx, "Trying zero write\n");
588
578
        io.writeclose.in.file.fnum = fnum;
589
579
        io.writeclose.in.count = 0;
590
580
        io.writeclose.in.offset = 0;
600
590
 
601
591
        setup_buffer(buf, seed, maxsize);
602
592
 
603
 
        printf("Trying small write\n");
 
593
        torture_comment(tctx, "Trying small write\n");
604
594
        io.writeclose.in.count = 9;
605
595
        io.writeclose.in.offset = 4;
606
596
        io.writeclose.in.data = buf;
614
604
        io.writeclose.in.file.fnum = fnum;
615
605
 
616
606
        if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
617
 
                printf("read failed at %s\n", __location__);
618
607
                ret = false;
619
 
                goto done;
 
608
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
620
609
        }
621
610
        CHECK_BUFFER(buf+4, seed, 9);
622
611
        CHECK_VALUE(IVAL(buf,0), 0);
631
620
 
632
621
        memset(buf, 0, maxsize);
633
622
        if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
634
 
                printf("read failed at %s\n", __location__);
635
623
                ret = false;
636
 
                goto done;
 
624
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
637
625
        }
638
626
        CHECK_BUFFER(buf+4, seed, 9);
639
627
        CHECK_VALUE(IVAL(buf,0), 0);
640
628
 
641
629
        setup_buffer(buf, seed, maxsize);
642
630
 
643
 
        printf("Trying large write\n");
 
631
        torture_comment(tctx, "Trying large write\n");
644
632
        io.writeclose.in.count = 4000;
645
633
        io.writeclose.in.offset = 0;
646
634
        io.writeclose.in.data = buf;
656
644
 
657
645
        memset(buf, 0, maxsize);
658
646
        if (smbcli_read(cli->tree, fnum, buf, 0, 4000) != 4000) {
659
 
                printf("read failed at %s\n", __location__);
660
647
                ret = false;
661
 
                goto done;
 
648
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
662
649
        }
663
650
        CHECK_BUFFER(buf, seed, 4000);
664
651
 
665
 
        printf("Trying bad fnum\n");
 
652
        torture_comment(tctx, "Trying bad fnum\n");
666
653
        io.writeclose.in.file.fnum = fnum+1;
667
654
        io.writeclose.in.count = 4000;
668
655
        io.writeclose.in.offset = 0;
670
657
        status = smb_raw_write(cli->tree, &io);
671
658
        CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
672
659
 
673
 
        printf("Setting file as sparse\n");
 
660
        torture_comment(tctx, "Setting file as sparse\n");
674
661
        status = torture_set_sparse(cli->tree, fnum);
675
662
        CHECK_STATUS(status, NT_STATUS_OK);
676
 
        
 
663
 
677
664
        if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
678
 
                printf("skipping large file tests - CAP_LARGE_FILES not set\n");
679
 
                goto done;
 
665
                torture_skip(tctx, "skipping large file tests - CAP_LARGE_FILES not set\n");
680
666
        }
681
667
 
682
 
        printf("Trying 2^32 offset\n");
 
668
        torture_comment(tctx, "Trying 2^32 offset\n");
683
669
        setup_buffer(buf, seed, maxsize);
684
670
        io.writeclose.in.file.fnum = fnum;
685
671
        io.writeclose.in.count = 4000;
695
681
 
696
682
        memset(buf, 0, maxsize);
697
683
        if (smbcli_read(cli->tree, fnum, buf, io.writeclose.in.offset, 4000) != 4000) {
698
 
                printf("read failed at %s\n", __location__);
699
684
                ret = false;
700
 
                goto done;
 
685
                torture_fail_goto(tctx, done, talloc_asprintf(tctx, "read failed at %s\n", __location__));
701
686
        }
702
687
        CHECK_BUFFER(buf, seed, 4000);
703
688
 
708
693
        return ret;
709
694
}
710
695
 
711
 
/* 
 
696
/*
712
697
   basic testing of write calls
713
698
*/
714
699
struct torture_suite *torture_raw_write(TALLOC_CTX *mem_ctx)
715
700
{
716
 
        struct torture_suite *suite = torture_suite_create(mem_ctx, "WRITE");
 
701
        struct torture_suite *suite = torture_suite_create(mem_ctx, "write");
717
702
 
718
703
        torture_suite_add_1smb_test(suite, "write", test_write);
719
704
        torture_suite_add_1smb_test(suite, "write unlock", test_writeunlock);