| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
RAW_MKDIR_* and RAW_RMDIR_* individual test suite |
| 4 |
Copyright (C) Andrew Tridgell 2003 |
| 5 |
|
| 6 |
This program is free software; you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 3 of the License, or |
| 9 |
(at your option) any later version. |
| 10 |
|
| 11 |
This program is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "includes.h" |
| 21 |
#include "libcli/raw/libcliraw.h" |
| 22 |
#include "libcli/libcli.h" |
| 23 |
#include "torture/util.h" |
| 24 |
#include "torture/raw/proto.h" |
| 25 |
|
| 26 |
#define BASEDIR "\\mkdirtest" |
| 27 |
|
| 28 |
#define CHECK_STATUS(status, correct) do { \ |
| 29 |
if (!NT_STATUS_EQUAL(status, correct)) { \ |
| 30 |
printf("(%s) Incorrect status %s - should be %s\n", \ |
| 31 |
__location__, nt_errstr(status), nt_errstr(correct)); \ |
| 32 |
ret = false; \ |
| 33 |
goto done; \ |
| 34 |
}} while (0) |
| 35 |
|
| 36 |
/* |
| 37 |
test mkdir ops |
| 38 |
*/ |
| 39 |
static bool test_mkdir(struct smbcli_state *cli, struct torture_context *tctx) |
| 40 |
{ |
| 41 |
union smb_mkdir md; |
| 42 |
struct smb_rmdir rd; |
| 43 |
const char *path = BASEDIR "\\mkdir.dir"; |
| 44 |
NTSTATUS status; |
| 45 |
bool ret = true; |
| 46 |
|
| 47 |
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR); |
| 48 |
|
| 49 |
/* |
| 50 |
basic mkdir |
| 51 |
*/ |
| 52 |
md.mkdir.level = RAW_MKDIR_MKDIR; |
| 53 |
md.mkdir.in.path = path; |
| 54 |
|
| 55 |
status = smb_raw_mkdir(cli->tree, &md); |
| 56 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 57 |
|
| 58 |
printf("Testing mkdir collision\n"); |
| 59 |
|
| 60 |
/* 2nd create */ |
| 61 |
status = smb_raw_mkdir(cli->tree, &md); |
| 62 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION); |
| 63 |
|
| 64 |
/* basic rmdir */ |
| 65 |
rd.in.path = path; |
| 66 |
status = smb_raw_rmdir(cli->tree, &rd); |
| 67 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 68 |
|
| 69 |
status = smb_raw_rmdir(cli->tree, &rd); |
| 70 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 71 |
|
| 72 |
printf("Testing mkdir collision with file\n"); |
| 73 |
|
| 74 |
/* name collision with a file */ |
| 75 |
smbcli_close(cli->tree, create_complex_file(cli, tctx, path)); |
| 76 |
status = smb_raw_mkdir(cli->tree, &md); |
| 77 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION); |
| 78 |
|
| 79 |
printf("Testing rmdir with file\n"); |
| 80 |
|
| 81 |
/* delete a file with rmdir */ |
| 82 |
status = smb_raw_rmdir(cli->tree, &rd); |
| 83 |
CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY); |
| 84 |
|
| 85 |
smbcli_unlink(cli->tree, path); |
| 86 |
|
| 87 |
printf("Testing invalid dir\n"); |
| 88 |
|
| 89 |
/* create an invalid dir */ |
| 90 |
md.mkdir.in.path = "..\\..\\.."; |
| 91 |
status = smb_raw_mkdir(cli->tree, &md); |
| 92 |
CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD); |
| 93 |
|
| 94 |
printf("Testing t2mkdir\n"); |
| 95 |
|
| 96 |
/* try a t2mkdir - need to work out why this fails! */ |
| 97 |
md.t2mkdir.level = RAW_MKDIR_T2MKDIR; |
| 98 |
md.t2mkdir.in.path = path; |
| 99 |
md.t2mkdir.in.num_eas = 0; |
| 100 |
status = smb_raw_mkdir(cli->tree, &md); |
| 101 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 102 |
|
| 103 |
status = smb_raw_rmdir(cli->tree, &rd); |
| 104 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 105 |
|
| 106 |
printf("Testing t2mkdir bad path\n"); |
| 107 |
md.t2mkdir.in.path = talloc_asprintf(tctx, "%s\\bad_path\\bad_path", |
| 108 |
BASEDIR); |
| 109 |
status = smb_raw_mkdir(cli->tree, &md); |
| 110 |
CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_NOT_FOUND); |
| 111 |
|
| 112 |
printf("Testing t2mkdir with EAs\n"); |
| 113 |
|
| 114 |
/* with EAs */ |
| 115 |
md.t2mkdir.level = RAW_MKDIR_T2MKDIR; |
| 116 |
md.t2mkdir.in.path = path; |
| 117 |
md.t2mkdir.in.num_eas = 3; |
| 118 |
md.t2mkdir.in.eas = talloc_array(tctx, struct ea_struct, md.t2mkdir.in.num_eas); |
| 119 |
md.t2mkdir.in.eas[0].flags = 0; |
| 120 |
md.t2mkdir.in.eas[0].name.s = "EAONE"; |
| 121 |
md.t2mkdir.in.eas[0].value = data_blob_talloc(tctx, "blah", 4); |
| 122 |
md.t2mkdir.in.eas[1].flags = 0; |
| 123 |
md.t2mkdir.in.eas[1].name.s = "EA TWO"; |
| 124 |
md.t2mkdir.in.eas[1].value = data_blob_talloc(tctx, "foo bar", 7); |
| 125 |
md.t2mkdir.in.eas[2].flags = 0; |
| 126 |
md.t2mkdir.in.eas[2].name.s = "EATHREE"; |
| 127 |
md.t2mkdir.in.eas[2].value = data_blob_talloc(tctx, "xx1", 3); |
| 128 |
status = smb_raw_mkdir(cli->tree, &md); |
| 129 |
|
| 130 |
if (torture_setting_bool(tctx, "samba3", false) |
| 131 |
&& NT_STATUS_EQUAL(status, NT_STATUS_EAS_NOT_SUPPORTED)) { |
| 132 |
d_printf("EAS not supported -- not treating as fatal\n"); |
| 133 |
} |
| 134 |
else { |
| 135 |
/* |
| 136 |
* In Samba3, don't see this error as fatal |
| 137 |
*/ |
| 138 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 139 |
|
| 140 |
status = torture_check_ea(cli, path, "EAONE", "blah"); |
| 141 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 142 |
status = torture_check_ea(cli, path, "EA TWO", "foo bar"); |
| 143 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 144 |
status = torture_check_ea(cli, path, "EATHREE", "xx1"); |
| 145 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 146 |
|
| 147 |
status = smb_raw_rmdir(cli->tree, &rd); |
| 148 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 149 |
} |
| 150 |
|
| 151 |
done: |
| 152 |
smb_raw_exit(cli->session); |
| 153 |
smbcli_deltree(cli->tree, BASEDIR); |
| 154 |
return ret; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
/* |
| 159 |
basic testing of all RAW_MKDIR_* calls |
| 160 |
*/ |
| 161 |
bool torture_raw_mkdir(struct torture_context *torture, |
| 162 |
struct smbcli_state *cli) |
| 163 |
{ |
| 164 |
bool ret = true; |
| 165 |
|
| 166 |
if (!test_mkdir(cli, torture)) { |
| 167 |
ret = false; |
| 168 |
} |
| 169 |
|
| 170 |
return ret; |
| 171 |
} |