r14379: Build torture/rpc/ as a seperate smbtorture module. Move helper
[tprouty/samba.git] / source4 / torture / rpc / remact.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for remoteactivation operations
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 "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_remact.h"
25 #include "librpc/gen_ndr/ndr_epmapper.h"
26 #include "torture/rpc/rpc.h"
27
28 #define CLSID_IMAGEDOC "02B01C80-E03D-101A-B294-00DD010F2BF9"
29
30 static int test_RemoteActivation(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
31 {
32         struct RemoteActivation r;
33         NTSTATUS status;
34         struct GUID iids[1];
35         uint16_t protseq[3] = { EPM_PROTOCOL_TCP, EPM_PROTOCOL_NCALRPC, EPM_PROTOCOL_UUID };
36
37         ZERO_STRUCT(r.in);
38         r.in.this.version.MajorVersion = 5;
39         r.in.this.version.MinorVersion = 1;
40         r.in.this.cid = GUID_random();
41         GUID_from_string(CLSID_IMAGEDOC, &r.in.Clsid);
42         r.in.ClientImpLevel = RPC_C_IMP_LEVEL_IDENTIFY;
43         r.in.num_protseqs = 3;
44         r.in.protseq = protseq;
45         r.in.Interfaces = 1;
46         GUID_from_string(DCERPC_IUNKNOWN_UUID, &iids[0]);
47         r.in.pIIDs = iids;
48
49         status = dcerpc_RemoteActivation(p, mem_ctx, &r);
50         if(NT_STATUS_IS_ERR(status)) {
51                 printf("RemoteActivation: %s\n", nt_errstr(status));
52                 return 0;
53         }
54
55         if(!W_ERROR_IS_OK(r.out.result)) {
56                 printf("RemoteActivation: %s\n", win_errstr(r.out.result));
57                 return 0;
58         }
59
60         if(!W_ERROR_IS_OK(r.out.hr)) {
61                 printf("RemoteActivation: %s\n", win_errstr(r.out.hr));
62                 return 0;
63         }
64
65         if(!W_ERROR_IS_OK(r.out.results[0])) {
66                 printf("RemoteActivation: %s\n", win_errstr(r.out.results[0]));
67                 return 0;
68         }
69
70         GUID_from_string(DCERPC_ICLASSFACTORY_UUID, &iids[0]);
71         r.in.Interfaces = 1;
72         r.in.Mode = MODE_GET_CLASS_OBJECT;
73
74         status = dcerpc_RemoteActivation(p, mem_ctx, &r);
75         if(NT_STATUS_IS_ERR(status)) {
76                 printf("RemoteActivation(GetClassObject): %s\n", nt_errstr(status));
77                 return 0;
78         }
79
80         if(!W_ERROR_IS_OK(r.out.result)) {
81                 printf("RemoteActivation(GetClassObject): %s\n", win_errstr(r.out.result));
82                 return 0;
83         }
84
85         if(!W_ERROR_IS_OK(r.out.hr)) {
86                 printf("RemoteActivation(GetClassObject): %s\n", win_errstr(r.out.hr));
87                 return 0;
88         }
89
90         if(!W_ERROR_IS_OK(r.out.results[0])) {
91                 printf("RemoteActivation(GetClassObject): %s\n", win_errstr(r.out.results[0]));
92                 return 0;
93         }
94
95         return 1;
96 }
97
98 BOOL torture_rpc_remact(void)
99 {
100         NTSTATUS status;
101         struct dcerpc_pipe *p;
102         TALLOC_CTX *mem_ctx;
103         BOOL ret = True;
104
105         mem_ctx = talloc_init("torture_rpc_remact");
106
107         status = torture_rpc_connection(mem_ctx,
108                                         &p, 
109                                         &dcerpc_table_IRemoteActivation);
110
111         if (!NT_STATUS_IS_OK(status)) {
112                 talloc_free(mem_ctx);
113                 return False;
114         }
115
116         if(!test_RemoteActivation(p, mem_ctx))
117                 ret = False;
118
119         talloc_free(mem_ctx);
120
121         return ret;
122 }