2 Unix SMB/CIFS implementation.
3 run the "simple" example DCOM program
5 Copyright (C) Jelmer Vernooij 2004
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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "librpc/gen_ndr/ndr_dcom.h"
24 #include "librpc/gen_ndr/ndr_oxidresolver.h"
26 #define CLSID_SIMPLE "5e9ddec7-5767-11cf-beab-00aa006c3606"
27 #define DEFAULT_TRANS 4096
29 static BOOL test_readwrite(TALLOC_CTX *mem_ctx, const char *host)
32 struct dcerpc_pipe *p = NULL;
37 struct dcom_interface_p **interfaces;
41 struct dcom_context *ctx;
44 extern NTSTATUS dcom_IUnknown_init(void);
45 extern NTSTATUS dcom_IStream_init(void);
47 torture_dcom_init(&ctx);
49 GUID_from_string(DCERPC_ISTREAM_UUID, &IID[0]);
50 GUID_from_string(DCERPC_IUNKNOWN_UUID, &IID[1]);
51 GUID_from_string(CLSID_SIMPLE, &clsid);
52 error = dcom_create_object(ctx, &clsid,
57 if (!W_ERROR_IS_OK(error)) {
58 printf("dcom_create_object failed - %s\n", win_errstr(error));
62 if (!W_ERROR_IS_OK(results[0])) {
63 printf("dcom_create_object didn't return IStream interface - %s\n", win_errstr(results[0]));
68 r_read.in.num_requested = 20; /* Give me 20 0xFF bytes... */
69 status = dcom_IStream_Read(interfaces[0], mem_ctx, &r_read);
70 if (NT_STATUS_IS_ERR(status)) {
71 printf("IStream::Read() failed - %s\n", nt_errstr(status));
73 } else if (!W_ERROR_IS_OK(r_read.out.result)) {
74 printf("IStream::Read() failed - %s\n", win_errstr(r_read.out.result));
78 for (i = 0; i < 5; i++) {
81 r_write.in.num_requested = 5;
82 r_write.in.data = (uint8_t *)&test_data;
83 status = dcom_IStream_Write(interfaces[0], mem_ctx, &r_write);
84 if (NT_STATUS_IS_ERR(status)) {
85 printf("IStream::Write() failed - %s\n", nt_errstr(status));
87 } else if (!W_ERROR_IS_OK(r_write.out.result)) {
88 printf("IStream::Write() failed - %s\n", win_errstr(r_write.out.result));
92 status = dcom_IUnknown_Release(interfaces[1], mem_ctx, NULL);
93 if (NT_STATUS_IS_ERR(status)) {
94 printf("IUnknown::Release() failed - %s\n", nt_errstr(status));
98 talloc_destroy(mem_ctx);
100 torture_rpc_close(p);
105 BOOL torture_dcom_simple(void)
108 TALLOC_CTX *mem_ctx = talloc_init("torture_dcom_simple");
110 ret &= test_readwrite(mem_ctx, NULL);
111 ret &= test_readwrite(mem_ctx, lp_parm_string(-1, "torture", "dcomhost"));