RPC-NAMEDPIPE01...
authorStefan Metzmacher <metze@samba.org>
Mon, 20 Apr 2009 12:24:41 +0000 (14:24 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 22 Apr 2013 09:19:22 +0000 (11:19 +0200)
source4/torture/raw/named_pipe_echo.c [new file with mode: 0644]
source4/torture/raw/raw.c

diff --git a/source4/torture/raw/named_pipe_echo.c b/source4/torture/raw/named_pipe_echo.c
new file mode 100644 (file)
index 0000000..ad508e3
--- /dev/null
@@ -0,0 +1,237 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   test suite for SMB2 oplocks
+
+   Copyright (C) Stefan Metzmacher 2008
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "torture/torture.h"
+#include "libcli/raw/libcliraw.h"
+#include "libcli/raw/raw_proto.h"
+#include "libcli/libcli.h"
+#include "torture/util.h"
+
+#define CHECK_VAL(v, correct) do { \
+       if ((v) != (correct)) { \
+               torture_result(tctx, TORTURE_FAIL, "(%s): wrong value for %s got 0x%x - should be 0x%x\n", \
+                               __location__, #v, (int)v, (int)correct); \
+               ret = false; \
+       }} while (0)
+
+#define CHECK_STATUS(status, correct) do { \
+       if (!NT_STATUS_EQUAL(status, correct)) { \
+               torture_result(tctx, TORTURE_FAIL, __location__": Incorrect status %s - should be %s", \
+                      nt_errstr(status), nt_errstr(correct)); \
+               ret = false; \
+               goto done; \
+       }} while (0)
+
+#define NP_ECHO_MESSAGE_FNAME "\\NPECHO_MESSAGE"
+
+bool torture_raw_np_echo01(struct torture_context *tctx,
+                          struct smbcli_state *cli)
+{
+       bool ret = true;
+       NTSTATUS status;
+       union smb_open op;
+       struct smb_trans2 tr;
+       union smb_write wr;
+       union smb_read rd;
+       union smb_close cl;
+       int fnum;
+       uint8_t cmd_buf[256*8];
+       uint16_t setup[2];
+       struct smbcli_request *reqs[4];
+       uint8_t zero20[20];
+       ZERO_STRUCT(zero20);
+
+       torture_comment(tctx, "open message mode named pipe\n");
+       ZERO_STRUCT(op);
+       op.ntcreatex.level = RAW_OPEN_NTCREATEX;
+       op.ntcreatex.in.fname = NP_ECHO_MESSAGE_FNAME;
+       op.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
+                               NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK |
+                               NTCREATEX_FLAGS_REQUEST_OPLOCK;
+       op.ntcreatex.in.root_fid = 0;
+       op.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
+       op.ntcreatex.in.alloc_size = 0;
+       op.ntcreatex.in.file_attr = 0;
+       op.ntcreatex.in.share_access = 0;
+       op.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
+       op.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
+       op.ntcreatex.in.security_flags = NTCREATEX_SECURITY_ALL |
+                                        NTCREATEX_SECURITY_DYNAMIC;
+       op.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
+
+       status = smb_raw_open(cli->tree, tctx, &op);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       fnum = op.ntcreatex.out.file.fnum;
+       CHECK_VAL(op.ntcreatex.out.attrib, FILE_ATTRIBUTE_NORMAL);
+       CHECK_VAL(op.ntcreatex.out.create_action, 1);
+       CHECK_VAL(op.ntcreatex.out.is_directory, 0);
+       CHECK_VAL(op.ntcreatex.out.size, 0);
+       //CHECK_VAL(op.ntcreatex.out.alloc_size, 0);
+       CHECK_VAL(op.ntcreatex.out.maximal_access, 0);
+       CHECK_VAL(op.ntcreatex.out.file_type, FILE_TYPE_MESSAGE_MODE_PIPE);
+       CHECK_VAL(op.ntcreatex.out.ipc_state, 0x5ff);
+
+       torture_comment(tctx, "select cmds\n");
+#define NPECHO_CMD_SLEEP 0
+#define NPECHO_CMD_READ 1
+#define NPECHO_CMD_WRITE 2
+
+#define NPECHO_BUF_CMD_SIZE 8
+
+#define NPECHO_BUF_SETUP_CMD(buf, idx, cmd, val) do { \
+       SIVAL(buf, (idx*NPECHO_BUF_CMD_SIZE)+0, cmd); \
+       SIVAL(buf, (idx*NPECHO_BUF_CMD_SIZE)+4, val); \
+       } while (0)
+
+       NPECHO_BUF_SETUP_CMD(cmd_buf, 0, NPECHO_CMD_SLEEP, 300);
+       NPECHO_BUF_SETUP_CMD(cmd_buf, 1, NPECHO_CMD_READ, 20);
+       NPECHO_BUF_SETUP_CMD(cmd_buf, 2, NPECHO_CMD_READ, 20);
+       NPECHO_BUF_SETUP_CMD(cmd_buf, 3, NPECHO_CMD_SLEEP, 300);
+       NPECHO_BUF_SETUP_CMD(cmd_buf, 4, NPECHO_CMD_WRITE, 20);
+       NPECHO_BUF_SETUP_CMD(cmd_buf, 5, NPECHO_CMD_WRITE, 20);
+       NPECHO_BUF_SETUP_CMD(cmd_buf, 6, NPECHO_CMD_SLEEP, 300);
+       NPECHO_BUF_SETUP_CMD(cmd_buf, 7, NPECHO_CMD_READ, 20);
+       NPECHO_BUF_SETUP_CMD(cmd_buf, 8, NPECHO_CMD_READ, 20);
+       NPECHO_BUF_SETUP_CMD(cmd_buf, 9, NPECHO_CMD_SLEEP, 300);
+       NPECHO_BUF_SETUP_CMD(cmd_buf,10, NPECHO_CMD_WRITE, 20);
+       NPECHO_BUF_SETUP_CMD(cmd_buf,11, NPECHO_CMD_WRITE, 20);
+       NPECHO_BUF_SETUP_CMD(cmd_buf,12, NPECHO_CMD_SLEEP, 300);
+       NPECHO_BUF_SETUP_CMD(cmd_buf,13, NPECHO_CMD_READ, 20);
+       NPECHO_BUF_SETUP_CMD(cmd_buf,14, NPECHO_CMD_READ, 20);
+       NPECHO_BUF_SETUP_CMD(cmd_buf,15, NPECHO_CMD_SLEEP, 300);
+       NPECHO_BUF_SETUP_CMD(cmd_buf,16, NPECHO_CMD_WRITE, 20);
+       NPECHO_BUF_SETUP_CMD(cmd_buf,17, NPECHO_CMD_WRITE, 20);
+       NPECHO_BUF_SETUP_CMD(cmd_buf,18, NPECHO_CMD_SLEEP, 300);
+       NPECHO_BUF_SETUP_CMD(cmd_buf,19, NPECHO_CMD_READ, 20);
+       NPECHO_BUF_SETUP_CMD(cmd_buf,20, NPECHO_CMD_SLEEP, 300);
+       NPECHO_BUF_SETUP_CMD(cmd_buf,21, NPECHO_CMD_WRITE, 20);
+       NPECHO_BUF_SETUP_CMD(cmd_buf,22, NPECHO_CMD_WRITE, 20);
+       NPECHO_BUF_SETUP_CMD(cmd_buf,23, NPECHO_CMD_SLEEP, 300);
+
+       setup[0] = TRANSACT_DCERPCCMD;
+       setup[1] = fnum;
+
+       ZERO_STRUCT(tr);
+       tr.in.flags = 0;
+       tr.in.timeout = 0;
+       tr.in.setup_count = 2;
+       tr.in.setup = setup;
+       tr.in.params = data_blob(NULL, 0);
+       tr.in.data = data_blob_const(cmd_buf, 24*NPECHO_BUF_CMD_SIZE);
+       tr.in.max_setup = 0;
+       tr.in.max_param = 0;
+       tr.in.max_data = 4;
+       status = smb_raw_trans(cli->tree, tctx, &tr);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       /* now do operations and send them all at the same time */
+       ZERO_STRUCT(wr);
+       wr.writex.level = RAW_WRITE_WRITEX;
+       wr.writex.in.file.fnum = fnum;
+       wr.writex.in.wmode = 0;
+       wr.writex.in.remaining = 0;
+       wr.writex.in.offset = 0;
+       wr.writex.in.count = sizeof(zero20);
+       wr.writex.in.data = zero20;
+
+       ZERO_STRUCT(rd);
+       rd.readx.level = RAW_READ_READX;
+       rd.readx.in.file.fnum = fnum;
+       rd.readx.in.maxcnt = sizeof(zero20);
+       rd.readx.in.mincnt = sizeof(zero20);
+       rd.readx.in.offset = 0;
+       rd.readx.in.read_for_execute = false;
+       rd.readx.in.remaining = 0;
+       rd.readx.out.data = zero20;
+
+       tr.in.data = data_blob_const(zero20, sizeof(zero20));
+       tr.in.max_data = sizeof(zero20);
+
+       torture_comment(tctx, "do write, write, read, read\n");
+       reqs[0] = smb_raw_write_send(cli->tree, &wr);
+       reqs[1] = smb_raw_write_send(cli->tree, &wr);
+       reqs[2] = smb_raw_read_send(cli->tree, &rd);
+       reqs[3] = smb_raw_read_send(cli->tree, &rd);
+
+       status = smb_raw_write_recv(reqs[0], &wr);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       status = smb_raw_write_recv(reqs[1], &wr);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       status = smb_raw_read_recv(reqs[2], &rd);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       status = smb_raw_read_recv(reqs[3], &rd);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       torture_comment(tctx, "do write, trans, read\n");
+       reqs[0] = smb_raw_write_send(cli->tree, &wr);
+       reqs[1] = smb_raw_trans_send(cli->tree, &tr);
+       reqs[2] = smb_raw_read_send(cli->tree, &rd);
+
+       status = smb_raw_write_recv(reqs[0], &wr);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       status = smb_raw_trans_recv(reqs[1], tctx, &tr);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       status = smb_raw_read_recv(reqs[2], &rd);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       torture_comment(tctx, "do write, trans, trans(pipe_busy), read\n");
+       reqs[0] = smb_raw_write_send(cli->tree, &wr);
+       reqs[1] = smb_raw_trans_send(cli->tree, &tr);
+       reqs[2] = smb_raw_trans_send(cli->tree, &tr);
+       reqs[3] = smb_raw_read_send(cli->tree, &rd);
+
+       status = smb_raw_write_recv(reqs[0], &wr);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       status = smb_raw_trans_recv(reqs[1], tctx, &tr);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       status = smb_raw_trans_recv(reqs[2], tctx, &tr);
+       CHECK_STATUS(status, NT_STATUS_PIPE_BUSY);
+       status = smb_raw_read_recv(reqs[3], &rd);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       torture_comment(tctx, "do write, read, trans(pipe_busy), read\n");
+       reqs[0] = smb_raw_write_send(cli->tree, &wr);
+       reqs[1] = smb_raw_read_send(cli->tree, &rd);
+       reqs[2] = smb_raw_trans_send(cli->tree, &tr);
+       reqs[3] = smb_raw_read_send(cli->tree, &rd);
+
+       status = smb_raw_write_recv(reqs[0], &wr);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       status = smb_raw_read_recv(reqs[1], &rd);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       status = smb_raw_trans_recv(reqs[2], tctx, &tr);
+       CHECK_STATUS(status, NT_STATUS_PIPE_BUSY);
+       status = smb_raw_read_recv(reqs[3], &rd);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       torture_comment(tctx, "close message mode named pipe\n");
+       ZERO_STRUCT(cl);
+       cl.close.level = RAW_CLOSE_CLOSE;
+       cl.close.in.file.fnum = fnum;
+       cl.close.in.write_time = 0;
+       status = smb_raw_close(cli->tree, &cl);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+done:
+       return ret;
+}
+
index bda463b8a7239e598b89e073cdd941d493178640..513cc6086a44490bea4e23bc863d9587a75d963b 100644 (file)
@@ -77,6 +77,8 @@ NTSTATUS torture_raw_init(void)
                                      torture_samba3_posixtimedlock);
        torture_suite_add_simple_test(suite, "scan-eamax", torture_max_eas);
 
+       torture_suite_add_1smb_test(suite, "NAMEDPIPE01", torture_raw_np_echo01);
+
        suite->description = talloc_strdup(suite, "Tests for the raw SMB interface");
 
        torture_register_suite(suite);