| 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 "torture/torture.h"
|
|---|
| 22 | #include "libcli/raw/libcliraw.h"
|
|---|
| 23 | #include "libcli/raw/raw_proto.h"
|
|---|
| 24 | #include "libcli/libcli.h"
|
|---|
| 25 | #include "torture/util.h"
|
|---|
| 26 |
|
|---|
| 27 | #define BASEDIR "\\mkdirtest"
|
|---|
| 28 |
|
|---|
| 29 | #define CHECK_STATUS(status, correct) do { \
|
|---|
| 30 | if (!NT_STATUS_EQUAL(status, correct)) { \
|
|---|
| 31 | printf("(%s) Incorrect status %s - should be %s\n", \
|
|---|
| 32 | __location__, nt_errstr(status), nt_errstr(correct)); \
|
|---|
| 33 | ret = false; \
|
|---|
| 34 | goto done; \
|
|---|
| 35 | }} while (0)
|
|---|
| 36 |
|
|---|
| 37 | /*
|
|---|
| 38 | test mkdir ops
|
|---|
| 39 | */
|
|---|
| 40 | static bool test_mkdir(struct smbcli_state *cli, struct torture_context *tctx)
|
|---|
| 41 | {
|
|---|
| 42 | union smb_mkdir md;
|
|---|
| 43 | struct smb_rmdir rd;
|
|---|
| 44 | const char *path = BASEDIR "\\mkdir.dir";
|
|---|
| 45 | NTSTATUS status;
|
|---|
| 46 | bool ret = true;
|
|---|
| 47 |
|
|---|
| 48 | if (!torture_setup_dir(cli, BASEDIR)) {
|
|---|
| 49 | return false;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | /*
|
|---|
| 53 | basic mkdir
|
|---|
| 54 | */
|
|---|
| 55 | md.mkdir.level = RAW_MKDIR_MKDIR;
|
|---|
| 56 | md.mkdir.in.path = path;
|
|---|
| 57 |
|
|---|
| 58 | status = smb_raw_mkdir(cli->tree, &md);
|
|---|
| 59 | CHECK_STATUS(status, NT_STATUS_OK);
|
|---|
| 60 |
|
|---|
| 61 | printf("testing mkdir collision\n");
|
|---|
| 62 |
|
|---|
| 63 | /* 2nd create */
|
|---|
| 64 | status = smb_raw_mkdir(cli->tree, &md);
|
|---|
| 65 | CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
|
|---|
| 66 |
|
|---|
| 67 | /* basic rmdir */
|
|---|
| 68 | rd.in.path = path;
|
|---|
| 69 | status = smb_raw_rmdir(cli->tree, &rd);
|
|---|
| 70 | CHECK_STATUS(status, NT_STATUS_OK);
|
|---|
| 71 |
|
|---|
| 72 | status = smb_raw_rmdir(cli->tree, &rd);
|
|---|
| 73 | CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
|
|---|
| 74 |
|
|---|
| 75 | printf("testing mkdir collision with file\n");
|
|---|
| 76 |
|
|---|
| 77 | /* name collision with a file */
|
|---|
| 78 | smbcli_close(cli->tree, create_complex_file(cli, tctx, path));
|
|---|
| 79 | status = smb_raw_mkdir(cli->tree, &md);
|
|---|
| 80 | CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
|
|---|
| 81 |
|
|---|
| 82 | printf("testing rmdir with file\n");
|
|---|
| 83 |
|
|---|
| 84 | /* delete a file with rmdir */
|
|---|
| 85 | status = smb_raw_rmdir(cli->tree, &rd);
|
|---|
| 86 | CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY);
|
|---|
| 87 |
|
|---|
| 88 | smbcli_unlink(cli->tree, path);
|
|---|
| 89 |
|
|---|
| 90 | printf("testing invalid dir\n");
|
|---|
| 91 |
|
|---|
| 92 | /* create an invalid dir */
|
|---|
| 93 | md.mkdir.in.path = "..\\..\\..";
|
|---|
| 94 | status = smb_raw_mkdir(cli->tree, &md);
|
|---|
| 95 | CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
|
|---|
| 96 |
|
|---|
| 97 | printf("testing t2mkdir\n");
|
|---|
| 98 |
|
|---|
| 99 | /* try a t2mkdir - need to work out why this fails! */
|
|---|
| 100 | md.t2mkdir.level = RAW_MKDIR_T2MKDIR;
|
|---|
| 101 | md.t2mkdir.in.path = path;
|
|---|
| 102 | md.t2mkdir.in.num_eas = 0;
|
|---|
| 103 | status = smb_raw_mkdir(cli->tree, &md);
|
|---|
| 104 | CHECK_STATUS(status, NT_STATUS_OK);
|
|---|
| 105 |
|
|---|
| 106 | status = smb_raw_rmdir(cli->tree, &rd);
|
|---|
| 107 | CHECK_STATUS(status, NT_STATUS_OK);
|
|---|
| 108 |
|
|---|
| 109 | printf("testing t2mkdir bad path\n");
|
|---|
| 110 | md.t2mkdir.in.path = talloc_asprintf(tctx, "%s\\bad_path\\bad_path",
|
|---|
| 111 | BASEDIR);
|
|---|
| 112 | status = smb_raw_mkdir(cli->tree, &md);
|
|---|
| 113 | CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_NOT_FOUND);
|
|---|
| 114 |
|
|---|
| 115 | printf("testing t2mkdir with EAs\n");
|
|---|
| 116 |
|
|---|
| 117 | /* with EAs */
|
|---|
| 118 | md.t2mkdir.level = RAW_MKDIR_T2MKDIR;
|
|---|
| 119 | md.t2mkdir.in.path = path;
|
|---|
| 120 | md.t2mkdir.in.num_eas = 3;
|
|---|
| 121 | md.t2mkdir.in.eas = talloc_array(tctx, struct ea_struct, md.t2mkdir.in.num_eas);
|
|---|
| 122 | md.t2mkdir.in.eas[0].flags = 0;
|
|---|
| 123 | md.t2mkdir.in.eas[0].name.s = "EAONE";
|
|---|
| 124 | md.t2mkdir.in.eas[0].value = data_blob_talloc(tctx, "blah", 4);
|
|---|
| 125 | md.t2mkdir.in.eas[1].flags = 0;
|
|---|
| 126 | md.t2mkdir.in.eas[1].name.s = "EA TWO";
|
|---|
| 127 | md.t2mkdir.in.eas[1].value = data_blob_talloc(tctx, "foo bar", 7);
|
|---|
| 128 | md.t2mkdir.in.eas[2].flags = 0;
|
|---|
| 129 | md.t2mkdir.in.eas[2].name.s = "EATHREE";
|
|---|
| 130 | md.t2mkdir.in.eas[2].value = data_blob_talloc(tctx, "xx1", 3);
|
|---|
| 131 | status = smb_raw_mkdir(cli->tree, &md);
|
|---|
| 132 |
|
|---|
| 133 | if (torture_setting_bool(tctx, "samba3", false)
|
|---|
| 134 | && NT_STATUS_EQUAL(status, NT_STATUS_EAS_NOT_SUPPORTED)) {
|
|---|
| 135 | d_printf("EAS not supported -- not treating as fatal\n");
|
|---|
| 136 | }
|
|---|
| 137 | else {
|
|---|
| 138 | /*
|
|---|
| 139 | * In Samba3, don't see this error as fatal
|
|---|
| 140 | */
|
|---|
| 141 | CHECK_STATUS(status, NT_STATUS_OK);
|
|---|
| 142 |
|
|---|
| 143 | status = torture_check_ea(cli, path, "EAONE", "blah");
|
|---|
| 144 | CHECK_STATUS(status, NT_STATUS_OK);
|
|---|
| 145 | status = torture_check_ea(cli, path, "EA TWO", "foo bar");
|
|---|
| 146 | CHECK_STATUS(status, NT_STATUS_OK);
|
|---|
| 147 | status = torture_check_ea(cli, path, "EATHREE", "xx1");
|
|---|
| 148 | CHECK_STATUS(status, NT_STATUS_OK);
|
|---|
| 149 |
|
|---|
| 150 | status = smb_raw_rmdir(cli->tree, &rd);
|
|---|
| 151 | CHECK_STATUS(status, NT_STATUS_OK);
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | done:
|
|---|
| 155 | smb_raw_exit(cli->session);
|
|---|
| 156 | smbcli_deltree(cli->tree, BASEDIR);
|
|---|
| 157 | return ret;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 | /*
|
|---|
| 162 | basic testing of all RAW_MKDIR_* calls
|
|---|
| 163 | */
|
|---|
| 164 | bool torture_raw_mkdir(struct torture_context *torture,
|
|---|
| 165 | struct smbcli_state *cli)
|
|---|
| 166 | {
|
|---|
| 167 | bool ret = true;
|
|---|
| 168 |
|
|---|
| 169 | if (!test_mkdir(cli, torture)) {
|
|---|
| 170 | ret = false;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | return ret;
|
|---|
| 174 | }
|
|---|