root/source4/torture/basic/disconnect.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. test_disconnect_open
  2. test_disconnect_lock
  3. torture_disconnect

   1 /* 
   2    Unix SMB/CIFS implementation.
   3 
   4    test server handling of unexpected client disconnects
   5 
   6    Copyright (C) Andrew Tridgell 2004
   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 "torture/torture.h"
  24 #include "system/filesys.h"
  25 #include "libcli/raw/libcliraw.h"
  26 #include "libcli/raw/raw_proto.h"
  27 #include "libcli/libcli.h"
  28 #include "torture/util.h"
  29 
  30 #define BASEDIR "\\test_disconnect"
  31 
  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                 talloc_free(cli); \
  37                 return false; \
  38         }} while (0)
  39 
  40 /*
  41   test disconnect after async open
  42 */
  43 static bool test_disconnect_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
     /* [<][>][^][v][top][bottom][index][help] */
  44 {
  45         union smb_open io;
  46         NTSTATUS status;
  47         struct smbcli_request *req1, *req2;
  48 
  49         printf("trying open/disconnect\n");
  50 
  51         io.generic.level = RAW_OPEN_NTCREATEX;
  52         io.ntcreatex.in.root_fid = 0;
  53         io.ntcreatex.in.flags = 0;
  54         io.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
  55         io.ntcreatex.in.create_options = 0;
  56         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
  57         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ;
  58         io.ntcreatex.in.alloc_size = 0;
  59         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
  60         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
  61         io.ntcreatex.in.security_flags = 0;
  62         io.ntcreatex.in.fname = BASEDIR "\\open.dat";
  63         status = smb_raw_open(cli->tree, mem_ctx, &io);
  64         CHECK_STATUS(status, NT_STATUS_OK);
  65 
  66         io.ntcreatex.in.share_access = 0;
  67         req1 = smb_raw_open_send(cli->tree, &io);
  68         req2 = smb_raw_open_send(cli->tree, &io);
  69 
  70         status = smbcli_chkpath(cli->tree, "\\");
  71         CHECK_STATUS(status, NT_STATUS_OK);
  72         
  73         talloc_free(cli);
  74 
  75         return true;
  76 }
  77 
  78 
  79 /*
  80   test disconnect with timed lock
  81 */
  82 static bool test_disconnect_lock(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
     /* [<][>][^][v][top][bottom][index][help] */
  83 {
  84         union smb_lock io;
  85         NTSTATUS status;
  86         int fnum;
  87         struct smbcli_request *req;
  88         struct smb_lock_entry lock[1];
  89 
  90         printf("trying disconnect with async lock\n");
  91 
  92         fnum = smbcli_open(cli->tree, BASEDIR "\\write.dat", 
  93                            O_RDWR | O_CREAT, DENY_NONE);
  94         if (fnum == -1) {
  95                 printf("open failed in mux_write - %s\n", smbcli_errstr(cli->tree));
  96                 return false;
  97         }
  98 
  99         io.lockx.level = RAW_LOCK_LOCKX;
 100         io.lockx.in.file.fnum = fnum;
 101         io.lockx.in.mode = 0;
 102         io.lockx.in.timeout = 0;
 103         io.lockx.in.lock_cnt = 1;
 104         io.lockx.in.ulock_cnt = 0;
 105         lock[0].pid = 1;
 106         lock[0].offset = 0;
 107         lock[0].count = 4;
 108         io.lockx.in.locks = &lock[0];
 109 
 110         status = smb_raw_lock(cli->tree, &io);
 111         CHECK_STATUS(status, NT_STATUS_OK);
 112 
 113         lock[0].pid = 2;
 114         io.lockx.in.timeout = 3000;
 115         req = smb_raw_lock_send(cli->tree, &io);
 116 
 117         status = smbcli_chkpath(cli->tree, "\\");
 118         CHECK_STATUS(status, NT_STATUS_OK);
 119 
 120         talloc_free(cli);
 121 
 122         return true;
 123 }
 124 
 125 
 126 
 127 /* 
 128    basic testing of disconnects
 129 */
 130 bool torture_disconnect(struct torture_context *torture)
     /* [<][>][^][v][top][bottom][index][help] */
 131 {
 132         bool ret = true;
 133         TALLOC_CTX *mem_ctx;
 134         int i;
 135         extern int torture_numops;
 136         struct smbcli_state *cli;
 137 
 138         mem_ctx = talloc_init("torture_raw_mux");
 139 
 140         if (!torture_open_connection(&cli, torture, 0)) {
 141                 return false;
 142         }
 143 
 144         if (!torture_setup_dir(cli, BASEDIR)) {
 145                 return false;
 146         }
 147 
 148         for (i=0;i<torture_numops;i++) {
 149                 ret &= test_disconnect_lock(cli, mem_ctx);
 150                 if (!torture_open_connection(&cli, torture, 0)) {
 151                         return false;
 152                 }
 153 
 154                 ret &= test_disconnect_open(cli, mem_ctx);
 155                 if (!torture_open_connection(&cli, torture, 0)) {
 156                         return false;
 157                 }
 158 
 159                 if (torture_setting_bool(torture, "samba3", false)) {
 160                         /*
 161                          * In Samba3 it might happen that the old smbd from
 162                          * test_disconnect_lock is not scheduled before the
 163                          * new process comes in. Try to get rid of the random
 164                          * failures in the build farm.
 165                          */
 166                         msleep(200);
 167                 }
 168         }
 169 
 170         smb_raw_exit(cli->session);
 171         smbcli_deltree(cli->tree, BASEDIR);
 172         talloc_free(mem_ctx);
 173         return ret;
 174 }

/* [<][>][^][v][top][bottom][index][help] */