LCOV - code coverage report
Current view: top level - source4/torture/smb2 - maxwrite.c (source / functions) Hit Total Coverage
Test: coverage report for master 6248eab5 Lines: 0 53 0.0 %
Date: 2021-08-25 13:27:56 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    test suite for SMB2 write operations
       5             : 
       6             :    Copyright (C) Andrew Tridgell 2006
       7             :    
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             :    
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             :    
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "librpc/gen_ndr/security.h"
      24             : #include "libcli/smb2/smb2.h"
      25             : #include "libcli/smb2/smb2_calls.h"
      26             : #include "torture/torture.h"
      27             : #include "torture/smb2/proto.h"
      28             : 
      29             : #define FNAME "testmaxwrite.dat"
      30             : 
      31             : /*
      32             :   test writing
      33             : */
      34           0 : static NTSTATUS torture_smb2_write(struct torture_context *tctx,
      35             :                                    struct smb2_tree *tree, 
      36             :                                    struct smb2_handle handle)
      37             : {
      38             :         struct smb2_write w;
      39             :         struct smb2_read r;
      40             :         NTSTATUS status;
      41             :         int i, len;
      42           0 :         int max = 80000000;
      43           0 :         int min = 1;
      44             : 
      45           0 :         while (max > min) {
      46           0 :                 TALLOC_CTX *tmp_ctx = talloc_new(tctx);
      47             : 
      48             : 
      49           0 :                 len = 1+(min+max)/2;
      50             : 
      51           0 :                 ZERO_STRUCT(w);
      52           0 :                 w.in.file.handle = handle;
      53           0 :                 w.in.offset      = 0;
      54           0 :                 w.in.data        = data_blob_talloc(tmp_ctx, NULL, len);
      55             : 
      56           0 :                 for (i=0;i<len;i++) {
      57           0 :                         w.in.data.data[i] = i % 256;
      58             :                 }
      59             : 
      60           0 :                 torture_comment(tctx, "trying to write %d bytes (min=%d max=%d)\n",
      61             :                        len, min, max);
      62             : 
      63           0 :                 status = smb2_write(tree, &w);
      64           0 :                 if (!NT_STATUS_IS_OK(status)) {
      65           0 :                         torture_comment(tctx, "write failed - %s\n", nt_errstr(status));
      66           0 :                         max = len-1;
      67           0 :                         status = smb2_util_close(tree, handle);
      68           0 :                         if (!NT_STATUS_IS_OK(status)) {
      69             :                                 /* vista bug */
      70           0 :                                 torture_comment(tctx, "coping with server disconnect\n");
      71           0 :                                 talloc_free(tree);
      72           0 :                                 if (!torture_smb2_connection(tctx, &tree)) {
      73           0 :                                         torture_comment(tctx, "failed to reconnect\n");
      74           0 :                                         return NT_STATUS_NET_WRITE_FAULT;
      75             :                                 }
      76             :                         }
      77           0 :                         status = torture_smb2_createfile(tctx, tree, FNAME, &handle);
      78           0 :                         if (!NT_STATUS_IS_OK(status)) {
      79           0 :                                 torture_comment(tctx, "failed to create file handle\n");
      80           0 :                                 talloc_free(tmp_ctx);
      81           0 :                                 return status;
      82             :                         }
      83           0 :                         continue;
      84             :                 } else {
      85           0 :                         min = len;
      86             :                 }
      87             : 
      88             :                 
      89           0 :                 ZERO_STRUCT(r);
      90           0 :                 r.in.file.handle = handle;
      91           0 :                 r.in.length      = len;
      92           0 :                 r.in.offset      = 0;
      93             :                 
      94           0 :                 torture_comment(tctx, "reading %d bytes\n", len);
      95             : 
      96           0 :                 status = smb2_read(tree, tmp_ctx, &r);
      97           0 :                 if (!NT_STATUS_IS_OK(status)) {
      98           0 :                         torture_comment(tctx, "read failed - %s\n", nt_errstr(status));
      99           0 :                 } else if (w.in.data.length != r.out.data.length ||
     100           0 :                     memcmp(w.in.data.data, r.out.data.data, len) != 0) {
     101           0 :                         torture_comment(tctx, "read data mismatch\n");
     102             :                 }
     103             : 
     104           0 :                 talloc_free(tmp_ctx);
     105             :         }
     106             : 
     107           0 :         torture_comment(tctx, "converged: len=%d\n", max);
     108           0 :         smb2_util_close(tree, handle);
     109           0 :         smb2_util_unlink(tree, FNAME);
     110             : 
     111           0 :         return NT_STATUS_OK;
     112             : }
     113             : 
     114             : 
     115             : 
     116             : /* 
     117             :    basic testing of SMB2 connection calls
     118             : */
     119           0 : bool torture_smb2_maxwrite(struct torture_context *tctx)
     120             : {
     121             :         struct smb2_tree *tree;
     122             :         struct smb2_handle h1;
     123             : 
     124           0 :         if (!torture_smb2_connection(tctx, &tree)) {
     125           0 :                 return false;
     126             :         }
     127             : 
     128           0 :         torture_assert_ntstatus_ok(tctx,
     129             :                 torture_smb2_createfile(tctx, tree, FNAME, &h1),
     130             :                 "failed to create file handle");
     131             : 
     132           0 :         torture_assert_ntstatus_ok(tctx,
     133             :                 torture_smb2_write(tctx, tree, h1),
     134             :                 "Write failed");
     135             : 
     136           0 :         return true;
     137             : }

Generated by: LCOV version 1.13