summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2003-11-03 09:18:38 +0000
committerAndrew Tridgell <tridge@samba.org>2003-11-03 09:18:38 +0000
commit399fff106d268a5ea95fd2e60735d92b80bcecb1 (patch)
tree3b3409a7451b76f514cc200d12b7c4f510563878
parent87ef172531add2672185ec8935180104c3667894 (diff)
downloadsamba-399fff106d268a5ea95fd2e60735d92b80bcecb1.tar.gz
samba-399fff106d268a5ea95fd2e60735d92b80bcecb1.tar.bz2
samba-399fff106d268a5ea95fd2e60735d92b80bcecb1.zip
added rpcecho EchoData test
(This used to be commit 9c7e4db4712d1b2b7d8125e3ae535efd50b80f58)
-rw-r--r--source4/libcli/ndr/ndr_basic.c25
-rw-r--r--source4/libcli/ndr/ndr_echo.c24
-rw-r--r--source4/libcli/ndr/ndr_echo.h12
-rw-r--r--source4/libcli/rpc/rpc_echo.c31
-rw-r--r--source4/torture/rpc/echo.c42
5 files changed, 133 insertions, 1 deletions
diff --git a/source4/libcli/ndr/ndr_basic.c b/source4/libcli/ndr/ndr_basic.c
index 736ad0b762..d06eac3ca9 100644
--- a/source4/libcli/ndr/ndr_basic.c
+++ b/source4/libcli/ndr/ndr_basic.c
@@ -91,7 +91,19 @@ NTSTATUS ndr_pull_u32(struct ndr_pull *ndr, uint32 *v)
} else {
*v = IVAL(ndr->data, ndr->offset);
}
- ndr->offset += 2;
+ ndr->offset += 4;
+ return NT_STATUS_OK;
+}
+
+/*
+ parse a set of bytes
+*/
+NTSTATUS ndr_pull_bytes(struct ndr_pull *ndr, char **data, uint32 n)
+{
+ NDR_PULL_NEED_BYTES(ndr, n);
+ NDR_ALLOC_N(ndr, *data, n);
+ memcpy(*data, ndr->data + ndr->offset, n);
+ ndr->offset += n;
return NT_STATUS_OK;
}
@@ -138,3 +150,14 @@ NTSTATUS ndr_push_u32(struct ndr_push *ndr, uint32 v)
ndr->offset += 4;
return NT_STATUS_OK;
}
+
+/*
+ push some bytes
+*/
+NTSTATUS ndr_push_bytes(struct ndr_push *ndr, const char *data, uint32 n)
+{
+ NDR_PUSH_NEED_BYTES(ndr, n);
+ memcpy(ndr->data + ndr->offset, data, n);
+ ndr->offset += n;
+ return NT_STATUS_OK;
+}
diff --git a/source4/libcli/ndr/ndr_echo.c b/source4/libcli/ndr/ndr_echo.c
index da4f28f30c..456b254f3a 100644
--- a/source4/libcli/ndr/ndr_echo.c
+++ b/source4/libcli/ndr/ndr_echo.c
@@ -44,3 +44,27 @@ NTSTATUS ndr_push_rpcecho_addone(struct ndr_push *ndr,
NDR_CHECK(ndr_push_u32(ndr, r->in.data));
return NT_STATUS_OK;
}
+
+
+/*
+ parse a echodata
+*/
+NTSTATUS ndr_pull_rpcecho_echodata(struct ndr_pull *ndr,
+ struct rpcecho_echodata *r)
+{
+ NDR_CHECK(ndr_pull_u32(ndr, &r->out.len));
+ NDR_CHECK(ndr_pull_bytes(ndr, &r->out.data, r->out.len));
+ return NT_STATUS_OK;
+}
+
+/*
+ push a echodata
+*/
+NTSTATUS ndr_push_rpcecho_echodata(struct ndr_push *ndr,
+ struct rpcecho_echodata *r)
+{
+ NDR_CHECK(ndr_push_u32(ndr, r->in.len));
+ NDR_CHECK(ndr_push_u32(ndr, r->in.len));
+ NDR_CHECK(ndr_push_bytes(ndr, r->in.data, r->in.len));
+ return NT_STATUS_OK;
+}
diff --git a/source4/libcli/ndr/ndr_echo.h b/source4/libcli/ndr/ndr_echo.h
index 6144d3885b..4a8a4f5ab5 100644
--- a/source4/libcli/ndr/ndr_echo.h
+++ b/source4/libcli/ndr/ndr_echo.h
@@ -35,6 +35,18 @@ struct rpcecho_addone {
} out;
};
+/* EchoData interface */
+struct rpcecho_echodata {
+ struct {
+ int len;
+ const char *data;
+ } in;
+ struct {
+ int len;
+ char *data;
+ } out;
+};
+
/* define the command codes */
enum {
RPCECHO_CALL_ADDONE=0,
diff --git a/source4/libcli/rpc/rpc_echo.c b/source4/libcli/rpc/rpc_echo.c
index c3075ecedc..ab793a1ffa 100644
--- a/source4/libcli/rpc/rpc_echo.c
+++ b/source4/libcli/rpc/rpc_echo.c
@@ -52,3 +52,34 @@ NTSTATUS dcerpc_rpcecho_addone(struct dcerpc_pipe *p,
talloc_destroy(mem_ctx);
return status;
}
+
+
+/*
+ echodata interface
+*/
+NTSTATUS dcerpc_rpcecho_echodata(struct dcerpc_pipe *p,
+ TALLOC_CTX *mem_ctx,
+ int len,
+ const char *in_data,
+ int *out_len,
+ char **out_data)
+{
+ struct rpcecho_echodata r;
+ NTSTATUS status;
+
+ /* fill the .in side of the call */
+ r.in.len = len;
+ r.in.data = in_data;
+
+ /* make the call */
+ status = dcerpc_ndr_request(p, RPCECHO_CALL_ECHODATA, mem_ctx,
+ (ndr_push_fn_t) ndr_push_rpcecho_echodata,
+ (ndr_pull_fn_t) ndr_pull_rpcecho_echodata,
+ &r);
+
+ /* and extract the .out parameters */
+ *out_len = r.out.len;
+ *out_data = r.out.data;
+
+ return status;
+}
diff --git a/source4/torture/rpc/echo.c b/source4/torture/rpc/echo.c
index 5469854116..754d0c16d3 100644
--- a/source4/torture/rpc/echo.c
+++ b/source4/torture/rpc/echo.c
@@ -45,6 +45,44 @@ static BOOL test_addone(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
return True;
}
+/*
+ test the EchoData interface
+*/
+static BOOL test_echodata(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
+{
+ int i;
+ NTSTATUS status;
+ char *data_in, *data_out;
+ int len = 10;
+ int len_out;
+
+ printf("\nTesting EchoData\n");
+
+ data_in = talloc(mem_ctx, len);
+ for (i=0;i<len;i++) {
+ data_in[i] = i+1;
+ }
+
+ status = dcerpc_rpcecho_echodata(p, mem_ctx,
+ len,
+ data_in,
+ &len_out,
+ &data_out);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("EchoData(%d) failed\n", len);
+ return False;
+ }
+ printf("EchoData(%d) returned %d bytes\n", len, len_out);
+
+ if (memcmp(data_in, data_out, len) != 0) {
+ printf("Bad data returned!\n");
+ return False;
+ }
+
+
+ return True;
+}
+
BOOL torture_rpc_echo(int dummy)
{
NTSTATUS status;
@@ -63,6 +101,10 @@ BOOL torture_rpc_echo(int dummy)
ret = False;
}
+ if (!test_echodata(p, mem_ctx)) {
+ ret = False;
+ }
+
printf("\n");
torture_rpc_close(p);