| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 | ioctl individual test suite
|
|---|
| 4 | Copyright (C) Andrew Tridgell 2003
|
|---|
| 5 | Copyright (C) James J Myers 2003 <myersjj@samba.org>
|
|---|
| 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 "torture/torture.h"
|
|---|
| 23 | #include "libcli/raw/ioctl.h"
|
|---|
| 24 | #include "libcli/raw/libcliraw.h"
|
|---|
| 25 | #include "libcli/raw/raw_proto.h"
|
|---|
| 26 | #include "libcli/libcli.h"
|
|---|
| 27 | #include "torture/util.h"
|
|---|
| 28 |
|
|---|
| 29 | #define BASEDIR "\\rawioctl"
|
|---|
| 30 |
|
|---|
| 31 | #define CHECK_STATUS(status, correct) do { \
|
|---|
| 32 | if (!NT_STATUS_EQUAL(status, correct)) { \
|
|---|
| 33 | printf("(%d) Incorrect status %s - should be %s\n", \
|
|---|
| 34 | __LINE__, nt_errstr(status), nt_errstr(correct)); \
|
|---|
| 35 | ret = false; \
|
|---|
| 36 | goto done; \
|
|---|
| 37 | }} while (0)
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | /* test some ioctls */
|
|---|
| 41 | static bool test_ioctl(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
|
|---|
| 42 | {
|
|---|
| 43 | union smb_ioctl ctl;
|
|---|
| 44 | int fnum;
|
|---|
| 45 | NTSTATUS status;
|
|---|
| 46 | bool ret = true;
|
|---|
| 47 | const char *fname = BASEDIR "\\test.dat";
|
|---|
| 48 |
|
|---|
| 49 | printf("TESTING IOCTL FUNCTIONS\n");
|
|---|
| 50 |
|
|---|
| 51 | fnum = create_complex_file(cli, mem_ctx, fname);
|
|---|
| 52 | if (fnum == -1) {
|
|---|
| 53 | printf("Failed to create test.dat - %s\n", smbcli_errstr(cli->tree));
|
|---|
| 54 | ret = false;
|
|---|
| 55 | goto done;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | printf("Trying 0xFFFF\n");
|
|---|
| 59 | ctl.ioctl.level = RAW_IOCTL_IOCTL;
|
|---|
| 60 | ctl.ioctl.in.file.fnum = fnum;
|
|---|
| 61 | ctl.ioctl.in.request = 0xFFFF;
|
|---|
| 62 |
|
|---|
| 63 | status = smb_raw_ioctl(cli->tree, mem_ctx, &ctl);
|
|---|
| 64 | CHECK_STATUS(status, NT_STATUS_DOS(ERRSRV, ERRerror));
|
|---|
| 65 |
|
|---|
| 66 | printf("Trying QUERY_JOB_INFO\n");
|
|---|
| 67 | ctl.ioctl.level = RAW_IOCTL_IOCTL;
|
|---|
| 68 | ctl.ioctl.in.file.fnum = fnum;
|
|---|
| 69 | ctl.ioctl.in.request = IOCTL_QUERY_JOB_INFO;
|
|---|
| 70 |
|
|---|
| 71 | status = smb_raw_ioctl(cli->tree, mem_ctx, &ctl);
|
|---|
| 72 | CHECK_STATUS(status, NT_STATUS_DOS(ERRSRV, ERRerror));
|
|---|
| 73 |
|
|---|
| 74 | printf("Trying bad handle\n");
|
|---|
| 75 | ctl.ioctl.in.file.fnum = fnum+1;
|
|---|
| 76 | status = smb_raw_ioctl(cli->tree, mem_ctx, &ctl);
|
|---|
| 77 | CHECK_STATUS(status, NT_STATUS_DOS(ERRSRV, ERRerror));
|
|---|
| 78 |
|
|---|
| 79 | done:
|
|---|
| 80 | smbcli_close(cli->tree, fnum);
|
|---|
| 81 | return ret;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | /* test some filesystem control functions */
|
|---|
| 85 | static bool test_fsctl(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
|
|---|
| 86 | {
|
|---|
| 87 | int fnum;
|
|---|
| 88 | NTSTATUS status;
|
|---|
| 89 | bool ret = true;
|
|---|
| 90 | const char *fname = BASEDIR "\\test.dat";
|
|---|
| 91 | union smb_ioctl nt;
|
|---|
| 92 |
|
|---|
| 93 | printf("\nTESTING FSCTL FUNCTIONS\n");
|
|---|
| 94 |
|
|---|
| 95 | fnum = create_complex_file(cli, mem_ctx, fname);
|
|---|
| 96 | if (fnum == -1) {
|
|---|
| 97 | printf("Failed to create test.dat - %s\n", smbcli_errstr(cli->tree));
|
|---|
| 98 | ret = false;
|
|---|
| 99 | goto done;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | printf("trying sparse file\n");
|
|---|
| 103 | nt.ioctl.level = RAW_IOCTL_NTIOCTL;
|
|---|
| 104 | nt.ntioctl.in.function = FSCTL_SET_SPARSE;
|
|---|
| 105 | nt.ntioctl.in.file.fnum = fnum;
|
|---|
| 106 | nt.ntioctl.in.fsctl = true;
|
|---|
| 107 | nt.ntioctl.in.filter = 0;
|
|---|
| 108 | nt.ntioctl.in.max_data = 0;
|
|---|
| 109 | nt.ntioctl.in.blob = data_blob(NULL, 0);
|
|---|
| 110 |
|
|---|
| 111 | status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
|
|---|
| 112 | CHECK_STATUS(status, NT_STATUS_OK);
|
|---|
| 113 |
|
|---|
| 114 | printf("trying batch oplock\n");
|
|---|
| 115 | nt.ioctl.level = RAW_IOCTL_NTIOCTL;
|
|---|
| 116 | nt.ntioctl.in.function = FSCTL_REQUEST_BATCH_OPLOCK;
|
|---|
| 117 | nt.ntioctl.in.file.fnum = fnum;
|
|---|
| 118 | nt.ntioctl.in.fsctl = true;
|
|---|
| 119 | nt.ntioctl.in.filter = 0;
|
|---|
| 120 | nt.ntioctl.in.max_data = 0;
|
|---|
| 121 | nt.ntioctl.in.blob = data_blob(NULL, 0);
|
|---|
| 122 |
|
|---|
| 123 | status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
|
|---|
| 124 | if (NT_STATUS_IS_OK(status)) {
|
|---|
| 125 | printf("Server supports batch oplock upgrades on open files\n");
|
|---|
| 126 | } else {
|
|---|
| 127 | printf("Server does not support batch oplock upgrades on open files\n");
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | printf("Trying bad handle\n");
|
|---|
| 131 | nt.ntioctl.in.file.fnum = fnum+1;
|
|---|
| 132 | status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
|
|---|
| 133 | CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
|
|---|
| 134 |
|
|---|
| 135 | #if 0
|
|---|
| 136 | nt.ntioctl.in.file.fnum = fnum;
|
|---|
| 137 | for (i=0;i<100;i++) {
|
|---|
| 138 | nt.ntioctl.in.function = FSCTL_FILESYSTEM + (i<<2);
|
|---|
| 139 | status = smb_raw_ioctl(cli->tree, mem_ctx, &nt);
|
|---|
| 140 | if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
|
|---|
| 141 | printf("filesystem fsctl 0x%x - %s\n",
|
|---|
| 142 | i, nt_errstr(status));
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 | #endif
|
|---|
| 146 |
|
|---|
| 147 | done:
|
|---|
| 148 | smbcli_close(cli->tree, fnum);
|
|---|
| 149 | return ret;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | /*
|
|---|
| 153 | basic testing of some ioctl calls
|
|---|
| 154 | */
|
|---|
| 155 | bool torture_raw_ioctl(struct torture_context *torture,
|
|---|
| 156 | struct smbcli_state *cli)
|
|---|
| 157 | {
|
|---|
| 158 | bool ret = true;
|
|---|
| 159 |
|
|---|
| 160 | if (!torture_setup_dir(cli, BASEDIR)) {
|
|---|
| 161 | return false;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | ret &= test_ioctl(cli, torture);
|
|---|
| 165 | ret &= test_fsctl(cli, torture);
|
|---|
| 166 |
|
|---|
| 167 | smb_raw_exit(cli->session);
|
|---|
| 168 | smbcli_deltree(cli->tree, BASEDIR);
|
|---|
| 169 |
|
|---|
| 170 | return ret;
|
|---|
| 171 | }
|
|---|