b52733e1f6f2884727272a4d9fc4abfd7c49bad3
[sfrench/samba-autobuild/.git] / source4 / torture / dcom / simple.c
1 /* 
2    Unix SMB/CIFS implementation.
3    run the "simple" example DCOM program 
4
5    Copyright (C) Jelmer Vernooij 2004
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 2 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, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "librpc/gen_ndr/ndr_dcom.h"
24 #include "librpc/gen_ndr/ndr_oxidresolver.h"
25
26 #define CLSID_SIMPLE "5e9ddec7-5767-11cf-beab-00aa006c3606"
27 #define DEFAULT_TRANS 4096
28
29 BOOL torture_dcom_simple(void)
30 {
31         NTSTATUS status;
32         struct dcerpc_pipe *p;
33         TALLOC_CTX *mem_ctx;
34         BOOL ret = True;
35         struct GUID IID[2];
36         struct GUID clsid;
37         WERROR error;
38         char pv[DEFAULT_TRANS];
39         struct dcom_interface *interfaces;
40         struct IStream_Read r_read;
41         struct IStream_Write r_write;
42
43         mem_ctx = talloc_init("torture_dcom_simple");
44
45         GUID_from_string(DCERPC_ISTREAM_UUID, &IID[0]);
46         GUID_from_string(DCERPC_IUNKNOWN_UUID, &IID[1]);
47         GUID_from_string(CLSID_SIMPLE, &clsid);
48         error = dcom_create_object(mem_ctx, &clsid, "192.168.4.28", 2, IID, &interfaces);
49
50         if (!W_ERROR_IS_OK(error)) {
51                 printf("dcom_create_object failed - %s\n", win_errstr(error));
52                 return False;
53         }
54         
55         ZERO_STRUCT(r_read);
56         status = dcerpc_IStream_Read(interfaces[0].pipe, &interfaces[0].ipid, mem_ctx, &r_read);
57         if (NT_STATUS_IS_ERR(error)) {
58                 printf("IStream::Read() failed - %s\n", win_errstr(error));
59                 return False;
60         }
61
62         
63         status = dcerpc_IStream_Write(interfaces[0].pipe, &interfaces[0].ipid, mem_ctx, &r_write);
64         if (NT_STATUS_IS_ERR(error)) {
65                 printf("IStream::Write() failed - %s\n", win_errstr(error));
66                 return False;
67         }
68
69         /*FIXME: dcerpc_IUnknown_Release();*/
70
71         talloc_destroy(mem_ctx);
72
73         torture_rpc_close(p);
74         return ret;
75 }