2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2003
7 Copyright (C) Stefan (metze) Metzmacher 2004
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.
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.
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.
25 #include "librpc/gen_ndr/ndr_drsuapi.h"
28 struct policy_handle bind_handle;
29 struct GUID bind_guid;
30 const char *domain_obj_dn;
31 const char *domain_guid_str;
32 struct GUID domain_guid;
33 struct drsuapi_DsGetDCInfo2 dcinfo;
36 static BOOL test_DsBind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
37 struct DsPrivate *priv)
40 struct drsuapi_DsBind r;
43 GUID_from_string(DRSUAPI_DS_BIND_GUID, &priv->bind_guid);
45 r.in.bind_guid = &priv->bind_guid;
46 r.in.bind_info = NULL;
47 r.out.bind_handle = &priv->bind_handle;
49 printf("testing DsBind\n");
51 status = dcerpc_drsuapi_DsBind(p, mem_ctx, &r);
52 if (!NT_STATUS_IS_OK(status)) {
53 const char *errstr = nt_errstr(status);
54 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
55 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
57 printf("dcerpc_drsuapi_DsBind failed - %s\n", errstr);
59 } else if (!W_ERROR_IS_OK(r.out.result)) {
60 printf("DsBind failed - %s\n", win_errstr(r.out.result));
67 static BOOL test_DsCrackNames(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
68 struct DsPrivate *priv)
71 struct drsuapi_DsCrackNames r;
72 struct drsuapi_DsNameString names[1];
74 const char *dns_domain;
75 const char *nt4_domain;
76 const char *FQDN_1779_name;
79 r.in.bind_handle = &priv->bind_handle;
81 r.in.req.req1.unknown1 = 0x000004e4;
82 r.in.req.req1.unknown2 = 0x00000407;
83 r.in.req.req1.count = 1;
84 r.in.req.req1.names = names;
85 r.in.req.req1.format_flags = DRSUAPI_DS_NAME_FLAG_NO_FLAGS;
87 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_CANONICAL;
88 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
89 names[0].str = talloc_asprintf(mem_ctx, "%s/", lp_realm());
91 printf("testing DsCrackNames with name '%s' desired format:%d\n",
92 names[0].str, r.in.req.req1.format_desired);
94 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
95 if (!NT_STATUS_IS_OK(status)) {
96 const char *errstr = nt_errstr(status);
97 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
98 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
100 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
102 } else if (!W_ERROR_IS_OK(r.out.result)) {
103 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
111 dns_domain = r.out.ctr.ctr1->array[0].dns_domain_name;
112 nt4_domain = r.out.ctr.ctr1->array[0].result_name;
114 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_GUID;
116 printf("testing DsCrackNames with name '%s' desired format:%d\n",
117 names[0].str, r.in.req.req1.format_desired);
119 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
120 if (!NT_STATUS_IS_OK(status)) {
121 const char *errstr = nt_errstr(status);
122 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
123 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
125 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
127 } else if (!W_ERROR_IS_OK(r.out.result)) {
128 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
136 priv->domain_guid_str = r.out.ctr.ctr1->array[0].result_name;
137 GUID_from_string(priv->domain_guid_str, &priv->domain_guid);
140 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_GUID;
141 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
142 names[0].str = priv->domain_guid_str;
144 printf("testing DsCrackNames with name '%s' desired format:%d\n",
145 names[0].str, r.in.req.req1.format_desired);
147 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
148 if (!NT_STATUS_IS_OK(status)) {
149 const char *errstr = nt_errstr(status);
150 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
151 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
153 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
155 } else if (!W_ERROR_IS_OK(r.out.result)) {
156 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
164 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
165 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
166 names[0].str = nt4_domain;
168 printf("testing DsCrackNames with name '%s' desired format:%d\n",
169 names[0].str, r.in.req.req1.format_desired);
171 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
172 if (!NT_STATUS_IS_OK(status)) {
173 const char *errstr = nt_errstr(status);
174 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
175 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
177 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
179 } else if (!W_ERROR_IS_OK(r.out.result)) {
180 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
188 priv->domain_obj_dn = r.out.ctr.ctr1->array[0].result_name;
190 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
191 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
192 names[0].str = talloc_asprintf(mem_ctx, "%s%s$", nt4_domain, priv->dcinfo.netbios_name);
194 printf("testing DsCrackNames with name '%s' desired format:%d\n",
195 names[0].str, r.in.req.req1.format_desired);
197 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
198 if (!NT_STATUS_IS_OK(status)) {
199 const char *errstr = nt_errstr(status);
200 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
201 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
203 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
205 } else if (!W_ERROR_IS_OK(r.out.result)) {
206 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
214 FQDN_1779_name = r.out.ctr.ctr1->array[0].result_name;
216 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
217 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_CANONICAL;
218 names[0].str = FQDN_1779_name;
220 printf("testing DsCrackNames with name '%s' desired format:%d\n",
221 names[0].str, r.in.req.req1.format_desired);
223 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
224 if (!NT_STATUS_IS_OK(status)) {
225 const char *errstr = nt_errstr(status);
226 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
227 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
229 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
231 } else if (!W_ERROR_IS_OK(r.out.result)) {
232 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
240 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_DISPLAY;
242 printf("testing DsCrackNames with name '%s' desired format:%d\n",
243 names[0].str, r.in.req.req1.format_desired);
245 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
246 if (!NT_STATUS_IS_OK(status)) {
247 const char *errstr = nt_errstr(status);
248 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
249 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
251 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
253 } else if (!W_ERROR_IS_OK(r.out.result)) {
254 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
262 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_GUID;
264 printf("testing DsCrackNames with name '%s' desired format:%d\n",
265 names[0].str, r.in.req.req1.format_desired);
267 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
268 if (!NT_STATUS_IS_OK(status)) {
269 const char *errstr = nt_errstr(status);
270 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
271 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
273 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
275 } else if (!W_ERROR_IS_OK(r.out.result)) {
276 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
284 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL;
286 printf("testing DsCrackNames with name '%s' desired format:%d\n",
287 names[0].str, r.in.req.req1.format_desired);
289 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
290 if (!NT_STATUS_IS_OK(status)) {
291 const char *errstr = nt_errstr(status);
292 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
293 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
295 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
297 } else if (!W_ERROR_IS_OK(r.out.result)) {
298 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
306 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL;
308 printf("testing DsCrackNames with name '%s' desired format:%d\n",
309 names[0].str, r.in.req.req1.format_desired);
311 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
312 if (!NT_STATUS_IS_OK(status)) {
313 const char *errstr = nt_errstr(status);
314 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
315 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
317 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
319 } else if (!W_ERROR_IS_OK(r.out.result)) {
320 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
328 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_GUID;
329 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
330 names[0].str = GUID_string2(mem_ctx, &priv->dcinfo.site_guid);
332 printf("testing DsCrackNames with Site GUID '%s' desired format:%d\n",
333 names[0].str, r.in.req.req1.format_desired);
335 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
336 if (!NT_STATUS_IS_OK(status)) {
337 const char *errstr = nt_errstr(status);
338 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
339 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
341 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
343 } else if (!W_ERROR_IS_OK(r.out.result)) {
344 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
352 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
353 names[0].str = GUID_string2(mem_ctx, &priv->dcinfo.computer_guid);
355 printf("testing DsCrackNames with Computer GUID '%s' desired format:%d\n",
356 names[0].str, r.in.req.req1.format_desired);
358 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
359 if (!NT_STATUS_IS_OK(status)) {
360 const char *errstr = nt_errstr(status);
361 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
362 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
364 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
366 } else if (!W_ERROR_IS_OK(r.out.result)) {
367 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
375 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_GUID;
376 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
377 names[0].str = GUID_string2(mem_ctx, &priv->dcinfo.server_guid);
379 printf("testing DsCrackNames with Server GUID '%s' desired format:%d\n",
380 names[0].str, r.in.req.req1.format_desired);
382 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
383 if (!NT_STATUS_IS_OK(status)) {
384 const char *errstr = nt_errstr(status);
385 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
386 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
388 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
390 } else if (!W_ERROR_IS_OK(r.out.result)) {
391 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
399 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_GUID;
400 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
401 names[0].str = GUID_string2(mem_ctx, &priv->dcinfo.ntds_guid);
403 printf("testing DsCrackNames with NTDS GUID '%s' desired format:%d\n",
404 names[0].str, r.in.req.req1.format_desired);
406 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
407 if (!NT_STATUS_IS_OK(status)) {
408 const char *errstr = nt_errstr(status);
409 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
410 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
412 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
414 } else if (!W_ERROR_IS_OK(r.out.result)) {
415 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
423 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_GUID;
424 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
425 names[0].str = GUID_string2(mem_ctx, &priv->bind_guid);
427 printf("testing DsCrackNames with BIND GUID '%s' desired format:%d\n",
428 names[0].str, r.in.req.req1.format_desired);
430 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
431 if (!NT_STATUS_IS_OK(status)) {
432 const char *errstr = nt_errstr(status);
433 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
434 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
436 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
438 } else if (!W_ERROR_IS_OK(r.out.result)) {
439 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
450 static BOOL test_DsGetDCInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
451 struct DsPrivate *priv)
454 struct drsuapi_DsGetDomainControllerInfo r;
457 r.in.bind_handle = &priv->bind_handle;
460 r.in.req.req1.domain_name = talloc_strdup(mem_ctx, lp_realm());
461 r.in.req.req1.level = 1;
463 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
464 r.in.req.req1.level, r.in.req.req1.domain_name);
466 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
467 if (!NT_STATUS_IS_OK(status)) {
468 const char *errstr = nt_errstr(status);
469 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
470 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
472 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
473 " with dns domain failed - %s\n",
474 r.in.req.req1.level, errstr);
476 } else if (!W_ERROR_IS_OK(r.out.result)) {
477 printf("DsGetDomainControllerInfo level %d\n"
478 " with dns domain failed - %s\n",
479 r.in.req.req1.level, win_errstr(r.out.result));
483 r.in.req.req1.level = 2;
485 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
486 r.in.req.req1.level, r.in.req.req1.domain_name);
488 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
489 if (!NT_STATUS_IS_OK(status)) {
490 const char *errstr = nt_errstr(status);
491 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
492 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
494 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
495 " with dns domain failed - %s\n",
496 r.in.req.req1.level, errstr);
498 } else if (!W_ERROR_IS_OK(r.out.result)) {
499 printf("DsGetDomainControllerInfo level %d\n"
500 " with dns domain failed - %s\n",
501 r.in.req.req1.level, win_errstr(r.out.result));
504 if (r.out.ctr.ctr2.count > 0) {
505 priv->dcinfo = r.out.ctr.ctr2.array[0];
509 r.in.req.req1.level = -1;
511 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
512 r.in.req.req1.level, r.in.req.req1.domain_name);
514 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
515 if (!NT_STATUS_IS_OK(status)) {
516 const char *errstr = nt_errstr(status);
517 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
518 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
520 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
521 " with dns domain failed - %s\n",
522 r.in.req.req1.level, errstr);
524 } else if (!W_ERROR_IS_OK(r.out.result)) {
525 printf("DsGetDomainControllerInfo level %d\n"
526 " with dns domain failed - %s\n",
527 r.in.req.req1.level, win_errstr(r.out.result));
531 r.in.req.req1.domain_name = talloc_strdup(mem_ctx, lp_workgroup());
532 r.in.req.req1.level = 2;
534 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
535 r.in.req.req1.level, r.in.req.req1.domain_name);
537 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
538 if (!NT_STATUS_IS_OK(status)) {
539 const char *errstr = nt_errstr(status);
540 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
541 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
543 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
544 " with netbios domain failed - %s\n",
545 r.in.req.req1.level, errstr);
547 } else if (!W_ERROR_IS_OK(r.out.result)) {
548 printf("DsGetDomainControllerInfo level %d\n"
549 " with netbios domain failed - %s\n",
550 r.in.req.req1.level, win_errstr(r.out.result));
554 r.in.req.req1.domain_name = "__UNKNOWN_DOMAIN__";
555 r.in.req.req1.level = 2;
557 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
558 r.in.req.req1.level, r.in.req.req1.domain_name);
560 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
561 if (!NT_STATUS_IS_OK(status)) {
562 const char *errstr = nt_errstr(status);
563 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
564 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
566 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
567 " with invalid domain failed - %s\n",
568 r.in.req.req1.level, errstr);
570 } else if (!W_ERROR_EQUAL(r.out.result, WERR_DS_OBJ_NOT_FOUND)) {
571 printf("DsGetDomainControllerInfo level %d\n"
572 " with invalid domain not expected error (WERR_DS_OBJ_NOT_FOUND) - %s\n",
573 r.in.req.req1.level, win_errstr(r.out.result));
580 static BOOL test_DsWriteAccountSpn(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
581 struct DsPrivate *priv)
584 struct drsuapi_DsWriteAccountSpn r;
585 struct drsuapi_DsNameString names[2];
588 r.in.bind_handle = &priv->bind_handle;
591 printf("testing DsWriteAccountSpn\n");
593 r.in.req.req1.operation = DRSUAPI_DS_SPN_OPERATION_ADD;
594 r.in.req.req1.unknown1 = 0;
595 r.in.req.req1.object_dn = priv->dcinfo.computer_dn;
596 r.in.req.req1.count = 2;
597 r.in.req.req1.spn_names = names;
598 names[0].str = talloc_asprintf(mem_ctx, "smbtortureSPN/%s",priv->dcinfo.netbios_name);
599 names[1].str = talloc_asprintf(mem_ctx, "smbtortureSPN/%s",priv->dcinfo.dns_name);
601 status = dcerpc_drsuapi_DsWriteAccountSpn(p, mem_ctx, &r);
602 if (!NT_STATUS_IS_OK(status)) {
603 const char *errstr = nt_errstr(status);
604 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
605 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
607 printf("dcerpc_drsuapi_DsWriteAccountSpn failed - %s\n", errstr);
609 } else if (!W_ERROR_IS_OK(r.out.result)) {
610 printf("DsWriteAccountSpn failed - %s\n", win_errstr(r.out.result));
614 r.in.req.req1.operation = DRSUAPI_DS_SPN_OPERATION_DELETE;
615 r.in.req.req1.unknown1 = 0;
617 status = dcerpc_drsuapi_DsWriteAccountSpn(p, mem_ctx, &r);
618 if (!NT_STATUS_IS_OK(status)) {
619 const char *errstr = nt_errstr(status);
620 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
621 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
623 printf("dcerpc_drsuapi_DsWriteAccountSpn failed - %s\n", errstr);
625 } else if (!W_ERROR_IS_OK(r.out.result)) {
626 printf("DsWriteAccountSpn failed - %s\n", win_errstr(r.out.result));
633 static BOOL test_DsReplicaGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
634 struct DsPrivate *priv)
637 struct drsuapi_DsReplicaGetInfo r;
646 DRSUAPI_DS_REPLICA_GET_INFO,
647 DRSUAPI_DS_REPLICA_INFO_NEIGHBORS,
650 DRSUAPI_DS_REPLICA_GET_INFO,
651 DRSUAPI_DS_REPLICA_INFO_CURSORS,
654 DRSUAPI_DS_REPLICA_GET_INFO,
655 DRSUAPI_DS_REPLICA_INFO_OBJ_METADATA,
658 DRSUAPI_DS_REPLICA_GET_INFO,
659 DRSUAPI_DS_REPLICA_INFO_KCC_DSA_CONNECT_FAILURES,
662 DRSUAPI_DS_REPLICA_GET_INFO,
663 DRSUAPI_DS_REPLICA_INFO_KCC_DSA_LINK_FAILURES,
666 DRSUAPI_DS_REPLICA_GET_INFO,
667 DRSUAPI_DS_REPLICA_INFO_PENDING_OPS,
670 DRSUAPI_DS_REPLICA_GET_INFO2,
671 DRSUAPI_DS_REPLICA_INFO_ATTRIBUTE_VALUE_METADATA,
674 DRSUAPI_DS_REPLICA_GET_INFO2,
675 DRSUAPI_DS_REPLICA_INFO_CURSORS2,
678 DRSUAPI_DS_REPLICA_GET_INFO2,
679 DRSUAPI_DS_REPLICA_INFO_CURSORS3,
682 DRSUAPI_DS_REPLICA_GET_INFO2,
683 DRSUAPI_DS_REPLICA_INFO_OBJ_METADATA2,
686 DRSUAPI_DS_REPLICA_GET_INFO2,
687 DRSUAPI_DS_REPLICA_INFO_ATTRIBUTE_VALUE_METADATA2,
690 DRSUAPI_DS_REPLICA_GET_INFO2,
691 DRSUAPI_DS_REPLICA_INFO_NEIGHBORS02,
694 DRSUAPI_DS_REPLICA_GET_INFO2,
695 DRSUAPI_DS_REPLICA_INFO_CONNECTIONS04,
698 DRSUAPI_DS_REPLICA_GET_INFO2,
699 DRSUAPI_DS_REPLICA_INFO_CURSURS05,
702 DRSUAPI_DS_REPLICA_GET_INFO2,
703 DRSUAPI_DS_REPLICA_INFO_06,
708 r.in.bind_handle = &priv->bind_handle;
710 for (i=0; i < ARRAY_SIZE(array); i++) {
711 const char *object_dn;
713 printf("testing DsReplicaGetInfo level %d infotype %d\n",
714 array[i].level, array[i].infotype);
716 object_dn = (array[i].obj_dn ? array[i].obj_dn : priv->domain_obj_dn);
718 r.in.level = array[i].level;
720 case DRSUAPI_DS_REPLICA_GET_INFO:
721 r.in.req.req1.info_type = array[i].infotype;
722 r.in.req.req1.object_dn = object_dn;
723 ZERO_STRUCT(r.in.req.req1.guid1);
725 case DRSUAPI_DS_REPLICA_GET_INFO2:
726 r.in.req.req2.info_type = array[i].infotype;
727 r.in.req.req2.object_dn = object_dn;
728 ZERO_STRUCT(r.in.req.req1.guid1);
729 r.in.req.req2.unknown1 = 0;
730 r.in.req.req2.string1 = NULL;
731 r.in.req.req2.string2 = NULL;
732 r.in.req.req2.unknown2 = 0;
736 status = dcerpc_drsuapi_DsReplicaGetInfo(p, mem_ctx, &r);
737 if (!NT_STATUS_IS_OK(status)) {
738 const char *errstr = nt_errstr(status);
739 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
740 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
742 if (p->last_fault_code != DCERPC_FAULT_INVALID_TAG) {
743 printf("dcerpc_drsuapi_DsReplicaGetInfo failed - %s\n", errstr);
746 printf("DsReplicaGetInfo level %d and/or infotype %d not supported by server\n",
747 array[i].level, array[i].infotype);
749 } else if (!W_ERROR_IS_OK(r.out.result)) {
750 printf("DsReplicaGetInfo failed - %s\n", win_errstr(r.out.result));
758 static BOOL test_DsReplicaSync(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
759 struct DsPrivate *priv)
764 struct drsuapi_DsReplicaSync r;
765 struct drsuapi_DsReplicaSyncRequest1Info info1;
775 r.in.bind_handle = &priv->bind_handle;
777 for (i=0; i < ARRAY_SIZE(array); i++) {
778 printf("testing DsReplicaGetInfo level %d\n",
781 r.in.level = array[i].level;
784 r.in.req.req1.info = &info1;
785 r.in.req.req1.info->unknown1 = 32;
786 r.in.req.req1.info->unknown2 = 120;
787 ZERO_STRUCT(r.in.req.req1.info->guid1);
788 ZERO_ARRAY(r.in.req.req1.info->unknown3);
789 r.in.req.req1.info->nc_dn = priv->domain_obj_dn;
790 r.in.req.req1.guid1 = priv->dcinfo.ntds_guid;
791 r.in.req.req1.string1 = NULL;
792 r.in.req.req1.unknown1 = 16;
796 status = dcerpc_drsuapi_DsReplicaSync(p, mem_ctx, &r);
797 if (!NT_STATUS_IS_OK(status)) {
798 const char *errstr = nt_errstr(status);
799 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
800 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
802 printf("dcerpc_drsuapi_DsReplicaSync failed - %s\n", errstr);
804 } else if (!W_ERROR_IS_OK(r.out.result)) {
805 printf("DsReplicaSync failed - %s\n", win_errstr(r.out.result));
813 static BOOL test_DsUnbind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
814 struct DsPrivate *priv)
817 struct drsuapi_DsUnbind r;
820 r.in.bind_handle = &priv->bind_handle;
821 r.out.bind_handle = &priv->bind_handle;
823 printf("testing DsUnbind\n");
825 status = dcerpc_drsuapi_DsUnbind(p, mem_ctx, &r);
826 if (!NT_STATUS_IS_OK(status)) {
827 const char *errstr = nt_errstr(status);
828 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
829 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
831 printf("dcerpc_drsuapi_DsUnbind failed - %s\n", errstr);
833 } else if (!W_ERROR_IS_OK(r.out.result)) {
834 printf("DsBind failed - %s\n", win_errstr(r.out.result));
841 BOOL torture_rpc_drsuapi(void)
844 struct dcerpc_pipe *p;
847 struct DsPrivate priv;
849 status = torture_rpc_connection(&p,
852 DCERPC_DRSUAPI_VERSION);
853 if (!NT_STATUS_IS_OK(status)) {
857 printf("Connected to DRAUAPI pipe\n");
859 mem_ctx = talloc_init("torture_rpc_drsuapi");
863 ret &= test_DsBind(p, mem_ctx, &priv);
865 ret &= test_DsGetDCInfo(p, mem_ctx, &priv);
867 ret &= test_DsCrackNames(p, mem_ctx, &priv);
869 ret &= test_DsWriteAccountSpn(p, mem_ctx, &priv);
871 ret &= test_DsReplicaGetInfo(p, mem_ctx, &priv);
873 if (lp_parm_int(-1, "torture", "dangerous") == 1) {
874 ret &= test_DsReplicaSync(p, mem_ctx, &priv);
876 printf("DsReplicaSync disabled - enable dangerous tests to use\n");
879 ret &= test_DsUnbind(p, mem_ctx, &priv);
881 talloc_destroy(mem_ctx);
883 torture_rpc_close(p);