r3915: a few updates to the DsCrackNames() torture test
[samba.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 #include "librpc/gen_ndr/ndr_drsuapi.h"
26
27 struct DsPrivate {
28         struct policy_handle bind_handle;
29         const char *domain_guid_str;
30         struct drsuapi_DsGetDCInfo2 dcinfo;
31 };
32
33 static BOOL test_DsBind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
34                       struct DsPrivate *priv)
35 {
36         NTSTATUS status;
37         struct drsuapi_DsBind r;
38         BOOL ret = True;
39
40         r.in.server_guid = NULL;
41         r.in.bind_info = NULL;
42         r.out.bind_handle = &priv->bind_handle;
43
44         printf("testing DsBind\n");
45
46         status = dcerpc_drsuapi_DsBind(p, mem_ctx, &r);
47         if (!NT_STATUS_IS_OK(status)) {
48                 const char *errstr = nt_errstr(status);
49                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
50                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
51                 }
52                 printf("dcerpc_drsuapi_DsBind failed - %s\n", errstr);
53                 ret = False;
54         } else if (!W_ERROR_IS_OK(r.out.result)) {
55                 printf("DsBind failed - %s\n", win_errstr(r.out.result));
56                 ret = False;
57         }
58
59         return ret;
60 }
61
62 static BOOL test_DsCrackNames(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
63                       struct DsPrivate *priv)
64 {
65         NTSTATUS status;
66         struct drsuapi_DsCrackNames r;
67         struct drsuapi_DsNameString names[1];
68         BOOL ret = True;
69         const char *dns_domain;
70         const char *nt4_domain;
71         const char *FQDN_1779_domain;
72         const char *FQDN_1779_name;
73
74         ZERO_STRUCT(r);
75         r.in.bind_handle                = &priv->bind_handle;
76         r.in.level                      = 1;
77         r.in.req.req1.unknown1          = 0x000004e4;
78         r.in.req.req1.unknown2          = 0x00000407;
79         r.in.req.req1.count             = 1;
80         r.in.req.req1.names             = names;
81         r.in.req.req1.format_flags      = DRSUAPI_DS_NAME_FLAG_NO_FLAGS;
82
83         r.in.req.req1.format_offered    = DRSUAPI_DS_NAME_FORMAT_CANONICAL;
84         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
85         names[0].str = talloc_asprintf(mem_ctx, "%s/", lp_realm());
86
87         printf("testing DsCrackNames with name '%s' desired format:%d\n",
88                         names[0].str, r.in.req.req1.format_desired);
89
90         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
91         if (!NT_STATUS_IS_OK(status)) {
92                 const char *errstr = nt_errstr(status);
93                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
94                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
95                 }
96                 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
97                 ret = False;
98         } else if (!W_ERROR_IS_OK(r.out.result)) {
99                 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
100                 ret = False;
101         }
102
103         if (!ret) {
104                 return ret;
105         }
106
107         dns_domain = r.out.ctr.ctr1->array[0].dns_domain_name;
108         nt4_domain = r.out.ctr.ctr1->array[0].result_name;
109
110         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_GUID;
111
112         printf("testing DsCrackNames with name '%s' desired format:%d\n",
113                         names[0].str, r.in.req.req1.format_desired);
114
115         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
116         if (!NT_STATUS_IS_OK(status)) {
117                 const char *errstr = nt_errstr(status);
118                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
119                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
120                 }
121                 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
122                 ret = False;
123         } else if (!W_ERROR_IS_OK(r.out.result)) {
124                 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
125                 ret = False;
126         }
127
128         if (!ret) {
129                 return ret;
130         }
131
132         priv->domain_guid_str = r.out.ctr.ctr1->array[0].result_name;
133
134         r.in.req.req1.format_offered    = DRSUAPI_DS_NAME_FORMAT_GUID;
135         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
136         names[0].str = priv->domain_guid_str;
137
138         printf("testing DsCrackNames with name '%s' desired format:%d\n",
139                         names[0].str, r.in.req.req1.format_desired);
140
141         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
142         if (!NT_STATUS_IS_OK(status)) {
143                 const char *errstr = nt_errstr(status);
144                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
145                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
146                 }
147                 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
148                 ret = False;
149         } else if (!W_ERROR_IS_OK(r.out.result)) {
150                 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
151                 ret = False;
152         }
153
154         if (!ret) {
155                 return ret;
156         }
157
158         r.in.req.req1.format_offered    = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
159         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
160         names[0].str = nt4_domain;
161
162         printf("testing DsCrackNames with name '%s' desired format:%d\n",
163                         names[0].str, r.in.req.req1.format_desired);
164
165         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
166         if (!NT_STATUS_IS_OK(status)) {
167                 const char *errstr = nt_errstr(status);
168                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
169                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
170                 }
171                 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
172                 ret = False;
173         } else if (!W_ERROR_IS_OK(r.out.result)) {
174                 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
175                 ret = False;
176         }
177
178         if (!ret) {
179                 return ret;
180         }
181
182         FQDN_1779_domain = r.out.ctr.ctr1->array[0].result_name;
183
184         r.in.req.req1.format_offered    = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
185         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
186         names[0].str = talloc_asprintf(mem_ctx, "%s%s$", nt4_domain, priv->dcinfo.netbios_name);
187
188         printf("testing DsCrackNames with name '%s' desired format:%d\n",
189                         names[0].str, r.in.req.req1.format_desired);
190
191         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
192         if (!NT_STATUS_IS_OK(status)) {
193                 const char *errstr = nt_errstr(status);
194                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
195                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
196                 }
197                 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
198                 ret = False;
199         } else if (!W_ERROR_IS_OK(r.out.result)) {
200                 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
201                 ret = False;
202         }
203
204         if (!ret) {
205                 return ret;
206         }
207
208         FQDN_1779_name = r.out.ctr.ctr1->array[0].result_name;
209
210         r.in.req.req1.format_offered    = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
211         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_CANONICAL;
212         names[0].str = FQDN_1779_name;
213
214         printf("testing DsCrackNames with name '%s' desired format:%d\n",
215                         names[0].str, r.in.req.req1.format_desired);
216
217         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
218         if (!NT_STATUS_IS_OK(status)) {
219                 const char *errstr = nt_errstr(status);
220                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
221                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
222                 }
223                 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
224                 ret = False;
225         } else if (!W_ERROR_IS_OK(r.out.result)) {
226                 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
227                 ret = False;
228         }
229
230         if (!ret) {
231                 return ret;
232         }
233
234         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_DISPLAY;
235
236         printf("testing DsCrackNames with name '%s' desired format:%d\n",
237                         names[0].str, r.in.req.req1.format_desired);
238
239         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
240         if (!NT_STATUS_IS_OK(status)) {
241                 const char *errstr = nt_errstr(status);
242                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
243                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
244                 }
245                 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
246                 ret = False;
247         } else if (!W_ERROR_IS_OK(r.out.result)) {
248                 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
249                 ret = False;
250         }
251
252         if (!ret) {
253                 return ret;
254         }
255
256         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_GUID;
257
258         printf("testing DsCrackNames with name '%s' desired format:%d\n",
259                         names[0].str, r.in.req.req1.format_desired);
260
261         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
262         if (!NT_STATUS_IS_OK(status)) {
263                 const char *errstr = nt_errstr(status);
264                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
265                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
266                 }
267                 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
268                 ret = False;
269         } else if (!W_ERROR_IS_OK(r.out.result)) {
270                 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
271                 ret = False;
272         }
273
274         if (!ret) {
275                 return ret;
276         }
277
278         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL;
279
280         printf("testing DsCrackNames with name '%s' desired format:%d\n",
281                         names[0].str, r.in.req.req1.format_desired);
282
283         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
284         if (!NT_STATUS_IS_OK(status)) {
285                 const char *errstr = nt_errstr(status);
286                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
287                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
288                 }
289                 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
290                 ret = False;
291         } else if (!W_ERROR_IS_OK(r.out.result)) {
292                 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
293                 ret = False;
294         }
295
296         if (!ret) {
297                 return ret;
298         }
299
300         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL;
301
302         printf("testing DsCrackNames with name '%s' desired format:%d\n",
303                         names[0].str, r.in.req.req1.format_desired);
304
305         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
306         if (!NT_STATUS_IS_OK(status)) {
307                 const char *errstr = nt_errstr(status);
308                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
309                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
310                 }
311                 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
312                 ret = False;
313         } else if (!W_ERROR_IS_OK(r.out.result)) {
314                 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
315                 ret = False;
316         }
317
318         if (!ret) {
319                 return ret;
320         }
321
322         r.in.req.req1.format_offered    = DRSUAPI_DS_NAME_FORMAT_GUID;
323         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
324         names[0].str = GUID_string2(mem_ctx, &priv->dcinfo.site_guid);
325
326         printf("testing DsCrackNames with Site GUID '%s' desired format:%d\n",
327                         names[0].str, r.in.req.req1.format_desired);
328
329         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
330         if (!NT_STATUS_IS_OK(status)) {
331                 const char *errstr = nt_errstr(status);
332                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
333                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
334                 }
335                 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
336                 ret = False;
337         } else if (!W_ERROR_IS_OK(r.out.result)) {
338                 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
339                 ret = False;
340         }
341
342         if (!ret) {
343                 return ret;
344         }
345
346         r.in.req.req1.format_desired    = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
347         names[0].str = GUID_string2(mem_ctx, &priv->dcinfo.computer_guid);
348
349         printf("testing DsCrackNames with Computer GUID '%s' desired format:%d\n",
350                         names[0].str, r.in.req.req1.format_desired);
351
352         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
353         if (!NT_STATUS_IS_OK(status)) {
354                 const char *errstr = nt_errstr(status);
355                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
356                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
357                 }
358                 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
359                 ret = False;
360         } else if (!W_ERROR_IS_OK(r.out.result)) {
361                 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
362                 ret = False;
363         }
364
365         if (!ret) {
366                 return ret;
367         }
368
369         names[0].str = GUID_string2(mem_ctx, &priv->dcinfo.server_guid);
370
371         printf("testing DsCrackNames with Server GUID '%s' desired format:%d\n",
372                         names[0].str, r.in.req.req1.format_desired);
373
374         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
375         if (!NT_STATUS_IS_OK(status)) {
376                 const char *errstr = nt_errstr(status);
377                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
378                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
379                 }
380                 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
381                 ret = False;
382         } else if (!W_ERROR_IS_OK(r.out.result)) {
383                 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
384                 ret = False;
385         }
386
387         if (!ret) {
388                 return ret;
389         }
390
391         names[0].str = GUID_string2(mem_ctx, &priv->dcinfo.ntds_guid);
392
393         printf("testing DsCrackNames with NTDS GUID '%s' desired format:%d\n",
394                         names[0].str, r.in.req.req1.format_desired);
395
396         status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
397         if (!NT_STATUS_IS_OK(status)) {
398                 const char *errstr = nt_errstr(status);
399                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
400                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
401                 }
402                 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
403                 ret = False;
404         } else if (!W_ERROR_IS_OK(r.out.result)) {
405                 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
406                 ret = False;
407         }
408
409         if (!ret) {
410                 return ret;
411         }
412
413         return ret;
414 }
415
416 static BOOL test_DsGetDCInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
417                       struct DsPrivate *priv)
418 {
419         NTSTATUS status;
420         struct drsuapi_DsGetDomainControllerInfo r;
421         BOOL ret = True;
422
423         r.in.bind_handle = &priv->bind_handle;
424         r.in.level = 1;
425
426         r.in.req.req1.domain_name = talloc_strdup(mem_ctx, lp_realm());
427         r.in.req.req1.level = 1;
428
429         printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
430                         r.in.req.req1.level, r.in.req.req1.domain_name);
431
432         status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
433         if (!NT_STATUS_IS_OK(status)) {
434                 const char *errstr = nt_errstr(status);
435                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
436                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
437                 }
438                 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
439                         "    with dns domain failed - %s\n",
440                         r.in.req.req1.level, errstr);
441                 ret = False;
442         } else if (!W_ERROR_IS_OK(r.out.result)) {
443                 printf("DsGetDomainControllerInfo level %d\n"
444                         "    with dns domain failed - %s\n",
445                         r.in.req.req1.level, win_errstr(r.out.result));
446                 ret = False;
447         }
448
449         r.in.req.req1.level = 2;
450
451         printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
452                         r.in.req.req1.level, r.in.req.req1.domain_name);
453
454         status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
455         if (!NT_STATUS_IS_OK(status)) {
456                 const char *errstr = nt_errstr(status);
457                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
458                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
459                 }
460                 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
461                         "    with dns domain failed - %s\n",
462                         r.in.req.req1.level, errstr);
463                 ret = False;
464         } else if (!W_ERROR_IS_OK(r.out.result)) {
465                 printf("DsGetDomainControllerInfo level %d\n"
466                         "    with dns domain failed - %s\n",
467                         r.in.req.req1.level, win_errstr(r.out.result));
468                 ret = False;
469         } else {
470                 if (r.out.ctr.ctr2.count > 0) {
471                         priv->dcinfo    = r.out.ctr.ctr2.array[0];
472                 }
473         }
474
475         r.in.req.req1.level = -1;
476
477         printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
478                         r.in.req.req1.level, r.in.req.req1.domain_name);
479
480         status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
481         if (!NT_STATUS_IS_OK(status)) {
482                 const char *errstr = nt_errstr(status);
483                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
484                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
485                 }
486                 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
487                         "    with dns domain failed - %s\n",
488                         r.in.req.req1.level, errstr);
489                 ret = False;
490         } else if (!W_ERROR_IS_OK(r.out.result)) {
491                 printf("DsGetDomainControllerInfo level %d\n"
492                         "    with dns domain failed - %s\n",
493                         r.in.req.req1.level, win_errstr(r.out.result));
494                 ret = False;
495         }
496
497         r.in.req.req1.domain_name = talloc_strdup(mem_ctx, lp_workgroup());
498         r.in.req.req1.level = 2;
499
500         printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
501                         r.in.req.req1.level, r.in.req.req1.domain_name);
502
503         status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
504         if (!NT_STATUS_IS_OK(status)) {
505                 const char *errstr = nt_errstr(status);
506                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
507                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
508                 }
509                 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
510                         "    with netbios domain failed - %s\n",
511                         r.in.req.req1.level, errstr);
512                 ret = False;
513         } else if (!W_ERROR_IS_OK(r.out.result)) {
514                 printf("DsGetDomainControllerInfo level %d\n"
515                         "    with netbios domain failed - %s\n",
516                         r.in.req.req1.level, win_errstr(r.out.result));
517                 ret = False;
518         }
519
520         r.in.req.req1.domain_name = "__UNKNOWN_DOMAIN__";
521         r.in.req.req1.level = 2;
522
523         printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
524                         r.in.req.req1.level, r.in.req.req1.domain_name);
525
526         status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
527         if (!NT_STATUS_IS_OK(status)) {
528                 const char *errstr = nt_errstr(status);
529                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
530                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
531                 }
532                 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
533                         "    with invalid domain failed - %s\n",
534                         r.in.req.req1.level, errstr);
535                 ret = False;
536         } else if (!W_ERROR_EQUAL(r.out.result, WERR_DS_OBJ_NOT_FOUND)) {
537                 printf("DsGetDomainControllerInfo level %d\n"
538                         "    with invalid domain not expected error (WERR_DS_OBJ_NOT_FOUND) - %s\n",
539                         r.in.req.req1.level, win_errstr(r.out.result));
540                 ret = False;
541         }
542
543         return ret;
544 }
545
546 static BOOL test_DsUnbind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
547                         struct DsPrivate *priv)
548 {
549         NTSTATUS status;
550         struct drsuapi_DsUnbind r;
551         BOOL ret = True;
552
553         r.in.bind_handle = &priv->bind_handle;
554         r.out.bind_handle = &priv->bind_handle;
555
556         printf("testing DsUnbind\n");
557
558         status = dcerpc_drsuapi_DsUnbind(p, mem_ctx, &r);
559         if (!NT_STATUS_IS_OK(status)) {
560                 const char *errstr = nt_errstr(status);
561                 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
562                         errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
563                 }
564                 printf("dcerpc_drsuapi_DsUnbind failed - %s\n", errstr);
565                 ret = False;
566         } else if (!W_ERROR_IS_OK(r.out.result)) {
567                 printf("DsBind failed - %s\n", win_errstr(r.out.result));
568                 ret = False;
569         }
570
571         return ret;
572 }
573
574 BOOL torture_rpc_drsuapi(void)
575 {
576         NTSTATUS status;
577         struct dcerpc_pipe *p;
578         TALLOC_CTX *mem_ctx;
579         BOOL ret = True;
580         struct DsPrivate priv;
581
582         status = torture_rpc_connection(&p, 
583                                         DCERPC_DRSUAPI_NAME,
584                                         DCERPC_DRSUAPI_UUID,
585                                         DCERPC_DRSUAPI_VERSION);
586         if (!NT_STATUS_IS_OK(status)) {
587                 return False;
588         }
589
590         printf("Connected to DRAUAPI pipe\n");
591
592         mem_ctx = talloc_init("torture_rpc_drsuapi");
593
594         ZERO_STRUCT(priv);
595
596         if (!test_DsBind(p, mem_ctx, &priv)) {
597                 ret = False;
598         }
599
600         if (!test_DsGetDCInfo(p, mem_ctx, &priv)) {
601                 ret = False;
602         }
603
604         if (!test_DsCrackNames(p, mem_ctx, &priv)) {
605                 ret = False;
606         }
607
608         if (!test_DsUnbind(p, mem_ctx, &priv)) {
609                 ret = False;
610         }
611
612         talloc_destroy(mem_ctx);
613
614         torture_rpc_close(p);
615
616         return ret;
617 }