VERSION: Disable GIT_SNAPSHOT for the Samba 4.18.0rc1 release.
[Samba.git] / source4 / torture / smb2 / mkdir.c
blobf797b5cef6f7c3bb847c2f58659fc3bf107dce7d
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
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.
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.
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/>.
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"
28 #define BASEDIR "mkdirtest"
31 test mkdir ops
33 bool torture_smb2_mkdir(struct torture_context *tctx, struct smb2_tree *tree)
35 struct smb2_handle h = {{0}};
36 const char *path = BASEDIR "\\mkdir.dir";
37 NTSTATUS status;
38 bool ret = true;
40 ret = smb2_util_setup_dir(tctx, tree, BASEDIR);
41 torture_assert(tctx, ret, "Failed to setup up test directory: " BASEDIR);
44 basic mkdir
46 status = smb2_util_mkdir(tree, path);
47 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
48 "Incorrect status");
50 torture_comment(tctx, "Testing mkdir collision\n");
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");
58 /* basic rmdir */
59 status = smb2_util_rmdir(tree, path);
60 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
61 "Incorrect status");
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");
68 torture_comment(tctx, "Testing mkdir collision with file\n");
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");
78 torture_comment(tctx, "Testing rmdir with file\n");
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");
86 smb2_util_unlink(tree, path);
88 torture_comment(tctx, "Testing invalid dir\n");
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");
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");
102 done:
103 smb2_deltree(tree, BASEDIR);
104 return ret;