| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
RAW_MKDIR_* and RAW_RMDIR_* individual test suite |
| 4 |
Copyright (C) Andrew Tridgell 2003 |
| 5 |
Copyright (C) David Mulder 2020 |
| 6 |
|
| 7 |
This program is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 3 of the License, or |
| 10 |
(at your option) any later version. |
| 11 |
|
| 12 |
This program is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "includes.h" |
| 22 |
#include "libcli/smb2/smb2.h" |
| 23 |
#include "libcli/smb2/smb2_calls.h" |
| 24 |
#include "torture/util.h" |
| 25 |
#include "torture/smb2/proto.h" |
| 26 |
#include "libcli/smb_composite/smb_composite.h" |
| 27 |
|
| 28 |
#define BASEDIR "mkdirtest" |
| 29 |
|
| 30 |
/* |
| 31 |
test mkdir ops |
| 32 |
*/ |
| 33 |
bool torture_smb2_mkdir(struct torture_context *tctx, struct smb2_tree *tree) |
| 34 |
{ |
| 35 |
struct smb2_handle h = {{0}}; |
| 36 |
const char *path = BASEDIR "\\mkdir.dir"; |
| 37 |
NTSTATUS status; |
| 38 |
bool ret = true; |
| 39 |
|
| 40 |
ret = smb2_util_setup_dir(tctx, tree, BASEDIR); |
| 41 |
torture_assert(tctx, ret, "Failed to setup up test directory: " BASEDIR); |
| 42 |
|
| 43 |
/* |
| 44 |
basic mkdir |
| 45 |
*/ |
| 46 |
status = smb2_util_mkdir(tree, path); |
| 47 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 48 |
"Incorrect status"); |
| 49 |
|
| 50 |
torture_comment(tctx, "Testing mkdir collision\n"); |
| 51 |
|
| 52 |
/* 2nd create */ |
| 53 |
status = smb2_util_mkdir(tree, path); |
| 54 |
torture_assert_ntstatus_equal_goto(tctx, status, |
| 55 |
NT_STATUS_OBJECT_NAME_COLLISION, |
| 56 |
ret, done, "Incorrect status"); |
| 57 |
|
| 58 |
/* basic rmdir */ |
| 59 |
status = smb2_util_rmdir(tree, path); |
| 60 |
torture_assert_ntstatus_ok_goto(tctx, status, ret, done, |
| 61 |
"Incorrect status"); |
| 62 |
|
| 63 |
status = smb2_util_rmdir(tree, path); |
| 64 |
torture_assert_ntstatus_equal_goto(tctx, status, |
| 65 |
NT_STATUS_OBJECT_NAME_NOT_FOUND, |
| 66 |
ret, done, "Incorrect status"); |
| 67 |
|
| 68 |
torture_comment(tctx, "Testing mkdir collision with file\n"); |
| 69 |
|
| 70 |
/* name collision with a file */ |
| 71 |
smb2_create_complex_file(tctx, tree, path, &h); |
| 72 |
smb2_util_close(tree, h); |
| 73 |
status = smb2_util_mkdir(tree, path); |
| 74 |
torture_assert_ntstatus_equal_goto(tctx, status, |
| 75 |
NT_STATUS_OBJECT_NAME_COLLISION, |
| 76 |
ret, done, "Incorrect status"); |
| 77 |
|
| 78 |
torture_comment(tctx, "Testing rmdir with file\n"); |
| 79 |
|
| 80 |
/* delete a file with rmdir */ |
| 81 |
status = smb2_util_rmdir(tree, path); |
| 82 |
torture_assert_ntstatus_equal_goto(tctx, status, |
| 83 |
NT_STATUS_NOT_A_DIRECTORY, |
| 84 |
ret, done, "Incorrect status"); |
| 85 |
|
| 86 |
smb2_util_unlink(tree, path); |
| 87 |
|
| 88 |
torture_comment(tctx, "Testing invalid dir\n"); |
| 89 |
|
| 90 |
/* create an invalid dir */ |
| 91 |
status = smb2_util_mkdir(tree, "..\\..\\.."); |
| 92 |
torture_assert_ntstatus_equal_goto(tctx, status, |
| 93 |
NT_STATUS_OBJECT_PATH_SYNTAX_BAD, |
| 94 |
ret, done, "Incorrect status"); |
| 95 |
|
| 96 |
torture_comment(tctx, "Testing t2mkdir bad path\n"); |
| 97 |
status = smb2_util_mkdir(tree, BASEDIR "\\bad_path\\bad_path"); |
| 98 |
torture_assert_ntstatus_equal_goto(tctx, status, |
| 99 |
NT_STATUS_OBJECT_PATH_NOT_FOUND, |
| 100 |
ret, done, "Incorrect status"); |
| 101 |
|
| 102 |
done: |
| 103 |
smb2_deltree(tree, BASEDIR); |
| 104 |
return ret; |
| 105 |
} |