r2971: fix DsBind idl
[ira/wip.git] / source4 / torture / rpc / drsuapi.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    DRSUapi tests
5
6    Copyright (C) Andrew Tridgell 2003
7    Copyright (C) Stefan (metze) Metzmacher 2004
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include "includes.h"
25
26 #define TEST_MACHINE_NAME "torturetest"
27
28 static BOOL test_DsBind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
29                       struct policy_handle *bind_handle)
30 {
31         NTSTATUS status;
32         struct drsuapi_DsBind r;
33         BOOL ret = True;
34
35         r.in.server_guid = NULL;
36         r.in.bind_info = NULL;
37         r.out.bind_handle = bind_handle;
38
39         status = dcerpc_drsuapi_DsBind(p, mem_ctx, &r);
40         if (!NT_STATUS_IS_OK(status)) {
41                 const char *errstr = nt_errstr(status);
42                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
43                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
44                 }
45                 printf("drsuapi_DsBind failed - %s\n", errstr);
46                 ret = False;
47         }
48
49         return ret;
50 }
51
52 static BOOL test_DsCrackNames(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
53                       struct policy_handle *bind_handle)
54 {
55         NTSTATUS status;
56         struct drsuapi_DsCrackNames r;
57         struct drsuapi_DsNameString names[1];
58         BOOL ret = True;
59         const char *dns_domain;
60         const char *nt4_domain;
61         const char *FQDN_1779_domain;
62         const char *FQDN_1779_name;
63
64         ZERO_STRUCT(r);
65         r.in.bind_handle                = bind_handle;
66         r.in.level                      = 1;
67         r.in.req.req1.unknown1          = 0x000004e4;
68         r.in.req.req1.unknown2          = 0x00000407;
69         r.in.req.req1.count             = 1;
70         r.in.req.req1.names             = names;
71         r.in.req.req1.format_flags      = DRSUAPI_DS_NAME_FLAG_NO_FLAGS;
72
73         r.in.req.req1.format_offered    = DRSUAPI_DS_NAME_FORMAT_CANONICAL;
74         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
75         names[0].str = talloc_asprintf(mem_ctx, "%s/", lp_realm());
76
77         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
78         if (!NT_STATUS_IS_OK(status)) {
79                 const char *errstr = nt_errstr(status);
80                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
81                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
82                 }
83                 printf("drsuapi_DsCrackNames failed - %s\n", errstr);
84                 ret = False;
85         }
86
87         if (!ret) {
88                 return ret;
89         }
90
91         dns_domain = r.out.ctr.ctr1->array[0].dns_domain_name;
92         nt4_domain = r.out.ctr.ctr1->array[0].result_name;
93
94         r.in.req.req1.format_offered    = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
95         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
96         names[0].str = nt4_domain;
97
98         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
99         if (!NT_STATUS_IS_OK(status)) {
100                 const char *errstr = nt_errstr(status);
101                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
102                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
103                 }
104                 printf("drsuapi_DsCrackNames failed - %s\n", errstr);
105                 ret = False;
106         }
107
108         if (!ret) {
109                 return ret;
110         }
111
112         FQDN_1779_domain = r.out.ctr.ctr1->array[0].result_name;
113
114         r.in.req.req1.format_offered    = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
115         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
116         names[0].str = talloc_asprintf(mem_ctx, "%s%s$", nt4_domain, dcerpc_server_name(p));
117
118         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
119         if (!NT_STATUS_IS_OK(status)) {
120                 const char *errstr = nt_errstr(status);
121                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
122                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
123                 }
124                 printf("drsuapi_DsCrackNames failed - %s\n", errstr);
125                 ret = False;
126         }
127
128         if (!ret) {
129                 return ret;
130         }
131
132         FQDN_1779_name = r.out.ctr.ctr1->array[0].result_name;
133
134         r.in.req.req1.format_offered    = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
135         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_CANONICAL;
136         names[0].str = FQDN_1779_name;
137
138         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
139         if (!NT_STATUS_IS_OK(status)) {
140                 const char *errstr = nt_errstr(status);
141                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
142                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
143                 }
144                 printf("drsuapi_DsCrackNames failed - %s\n", errstr);
145                 ret = False;
146         }
147
148         if (!ret) {
149                 return ret;
150         }
151
152         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_DISPLAY;
153
154         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
155         if (!NT_STATUS_IS_OK(status)) {
156                 const char *errstr = nt_errstr(status);
157                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
158                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
159                 }
160                 printf("drsuapi_DsCrackNames failed - %s\n", errstr);
161                 ret = False;
162         }
163
164         if (!ret) {
165                 return ret;
166         }
167
168         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_GUID;
169
170         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
171         if (!NT_STATUS_IS_OK(status)) {
172                 const char *errstr = nt_errstr(status);
173                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
174                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
175                 }
176                 printf("drsuapi_DsCrackNames failed - %s\n", errstr);
177                 ret = False;
178         }
179
180         if (!ret) {
181                 return ret;
182         }
183
184         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL;
185
186         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
187         if (!NT_STATUS_IS_OK(status)) {
188                 const char *errstr = nt_errstr(status);
189                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
190                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
191                 }
192                 printf("drsuapi_DsCrackNames failed - %s\n", errstr);
193                 ret = False;
194         }
195
196         if (!ret) {
197                 return ret;
198         }
199
200         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL;
201
202         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
203         if (!NT_STATUS_IS_OK(status)) {
204                 const char *errstr = nt_errstr(status);
205                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
206                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
207                 }
208                 printf("drsuapi_DsCrackNames failed - %s\n", errstr);
209                 ret = False;
210         }
211
212         if (!ret) {
213                 return ret;
214         }
215
216         return ret;
217 }
218
219 static BOOL test_DsUnbind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
220                         struct policy_handle *bind_handle)
221 {
222         NTSTATUS status;
223         struct drsuapi_DsUnbind r;
224         BOOL ret = True;
225
226         r.in.bind_handle = bind_handle;
227         r.out.bind_handle = bind_handle;
228
229         status = dcerpc_drsuapi_DsUnbind(p, mem_ctx, &r);
230         if (!NT_STATUS_IS_OK(status)) {
231                 const char *errstr = nt_errstr(status);
232                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
233                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
234                 }
235                 printf("drsuapi_DsUnbind failed - %s\n", errstr);
236                 ret = False;
237         }
238
239         return ret;
240 }
241
242 BOOL torture_rpc_drsuapi(int dummy)
243 {
244         NTSTATUS status;
245         struct dcerpc_pipe *p;
246         TALLOC_CTX *mem_ctx;
247         BOOL ret = True;
248         struct policy_handle bind_handle;
249
250         status = torture_rpc_connection(&p, 
251                                         DCERPC_DRSUAPI_NAME,
252                                         DCERPC_DRSUAPI_UUID,
253                                         DCERPC_DRSUAPI_VERSION);
254         if (!NT_STATUS_IS_OK(status)) {
255                 return False;
256         }
257
258         printf("Connected to DRAUAPI pipe\n");
259
260         mem_ctx = talloc_init("torture_rpc_drsuapi");
261
262         if (!test_DsBind(p, mem_ctx, &bind_handle)) {
263                 ret = False;
264         }
265
266         if (!test_DsCrackNames(p, mem_ctx, &bind_handle)) {
267                 ret = False;
268         }
269
270         if (!test_DsUnbind(p, mem_ctx, &bind_handle)) {
271                 ret = False;
272         }
273
274 #if 0
275         if (!test_scan(p, mem_ctx)) {
276                 ret = False;
277         }
278 #endif
279         talloc_destroy(mem_ctx);
280
281         torture_rpc_close(p);
282
283         return ret;
284 }