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 const char *domain_guid_str;
30 struct drsuapi_DsGetDCInfo2 dcinfo;
33 static BOOL test_DsBind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
34 struct DsPrivate *priv)
37 struct drsuapi_DsBind r;
40 r.in.server_guid = NULL;
41 r.in.bind_info = NULL;
42 r.out.bind_handle = &priv->bind_handle;
44 printf("testing DsBind\n");
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);
52 printf("dcerpc_drsuapi_DsBind failed - %s\n", errstr);
54 } else if (!W_ERROR_IS_OK(r.out.result)) {
55 printf("DsBind failed - %s\n", win_errstr(r.out.result));
62 static BOOL test_DsCrackNames(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
63 struct DsPrivate *priv)
66 struct drsuapi_DsCrackNames r;
67 struct drsuapi_DsNameString names[1];
69 const char *dns_domain;
70 const char *nt4_domain;
71 const char *FQDN_1779_domain;
72 const char *FQDN_1779_name;
75 r.in.bind_handle = &priv->bind_handle;
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;
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());
87 printf("testing DsCrackNames with name '%s' desired format:%d\n",
88 names[0].str, r.in.req.req1.format_desired);
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);
96 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
98 } else if (!W_ERROR_IS_OK(r.out.result)) {
99 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
107 dns_domain = r.out.ctr.ctr1->array[0].dns_domain_name;
108 nt4_domain = r.out.ctr.ctr1->array[0].result_name;
110 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_GUID;
112 printf("testing DsCrackNames with name '%s' desired format:%d\n",
113 names[0].str, r.in.req.req1.format_desired);
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);
121 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
123 } else if (!W_ERROR_IS_OK(r.out.result)) {
124 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
132 priv->domain_guid_str = r.out.ctr.ctr1->array[0].result_name;
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;
138 printf("testing DsCrackNames with name '%s' desired format:%d\n",
139 names[0].str, r.in.req.req1.format_desired);
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);
147 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
149 } else if (!W_ERROR_IS_OK(r.out.result)) {
150 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
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;
162 printf("testing DsCrackNames with name '%s' desired format:%d\n",
163 names[0].str, r.in.req.req1.format_desired);
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);
171 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
173 } else if (!W_ERROR_IS_OK(r.out.result)) {
174 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
182 FQDN_1779_domain = r.out.ctr.ctr1->array[0].result_name;
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);
188 printf("testing DsCrackNames with name '%s' desired format:%d\n",
189 names[0].str, r.in.req.req1.format_desired);
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);
197 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
199 } else if (!W_ERROR_IS_OK(r.out.result)) {
200 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
208 FQDN_1779_name = r.out.ctr.ctr1->array[0].result_name;
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;
214 printf("testing DsCrackNames with name '%s' desired format:%d\n",
215 names[0].str, r.in.req.req1.format_desired);
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);
223 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
225 } else if (!W_ERROR_IS_OK(r.out.result)) {
226 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
234 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_DISPLAY;
236 printf("testing DsCrackNames with name '%s' desired format:%d\n",
237 names[0].str, r.in.req.req1.format_desired);
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);
245 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
247 } else if (!W_ERROR_IS_OK(r.out.result)) {
248 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
256 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_GUID;
258 printf("testing DsCrackNames with name '%s' desired format:%d\n",
259 names[0].str, r.in.req.req1.format_desired);
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);
267 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
269 } else if (!W_ERROR_IS_OK(r.out.result)) {
270 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
278 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL;
280 printf("testing DsCrackNames with name '%s' desired format:%d\n",
281 names[0].str, r.in.req.req1.format_desired);
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);
289 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
291 } else if (!W_ERROR_IS_OK(r.out.result)) {
292 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
300 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL;
302 printf("testing DsCrackNames with name '%s' desired format:%d\n",
303 names[0].str, r.in.req.req1.format_desired);
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);
311 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
313 } else if (!W_ERROR_IS_OK(r.out.result)) {
314 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
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);
326 printf("testing DsCrackNames with Site GUID '%s' desired format:%d\n",
327 names[0].str, r.in.req.req1.format_desired);
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);
335 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
337 } else if (!W_ERROR_IS_OK(r.out.result)) {
338 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
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);
349 printf("testing DsCrackNames with Computer GUID '%s' desired format:%d\n",
350 names[0].str, r.in.req.req1.format_desired);
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);
358 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
360 } else if (!W_ERROR_IS_OK(r.out.result)) {
361 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
369 names[0].str = GUID_string2(mem_ctx, &priv->dcinfo.server_guid);
371 printf("testing DsCrackNames with Server GUID '%s' desired format:%d\n",
372 names[0].str, r.in.req.req1.format_desired);
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);
380 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
382 } else if (!W_ERROR_IS_OK(r.out.result)) {
383 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
391 names[0].str = GUID_string2(mem_ctx, &priv->dcinfo.ntds_guid);
393 printf("testing DsCrackNames with NTDS GUID '%s' desired format:%d\n",
394 names[0].str, r.in.req.req1.format_desired);
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);
402 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
404 } else if (!W_ERROR_IS_OK(r.out.result)) {
405 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
416 static BOOL test_DsGetDCInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
417 struct DsPrivate *priv)
420 struct drsuapi_DsGetDomainControllerInfo r;
423 r.in.bind_handle = &priv->bind_handle;
426 r.in.req.req1.domain_name = talloc_strdup(mem_ctx, lp_realm());
427 r.in.req.req1.level = 1;
429 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
430 r.in.req.req1.level, r.in.req.req1.domain_name);
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);
438 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
439 " with dns domain failed - %s\n",
440 r.in.req.req1.level, errstr);
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));
449 r.in.req.req1.level = 2;
451 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
452 r.in.req.req1.level, r.in.req.req1.domain_name);
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);
460 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
461 " with dns domain failed - %s\n",
462 r.in.req.req1.level, errstr);
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));
470 if (r.out.ctr.ctr2.count > 0) {
471 priv->dcinfo = r.out.ctr.ctr2.array[0];
475 r.in.req.req1.level = -1;
477 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
478 r.in.req.req1.level, r.in.req.req1.domain_name);
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);
486 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
487 " with dns domain failed - %s\n",
488 r.in.req.req1.level, errstr);
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));
497 r.in.req.req1.domain_name = talloc_strdup(mem_ctx, lp_workgroup());
498 r.in.req.req1.level = 2;
500 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
501 r.in.req.req1.level, r.in.req.req1.domain_name);
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);
509 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
510 " with netbios domain failed - %s\n",
511 r.in.req.req1.level, errstr);
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));
520 r.in.req.req1.domain_name = "__UNKNOWN_DOMAIN__";
521 r.in.req.req1.level = 2;
523 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
524 r.in.req.req1.level, r.in.req.req1.domain_name);
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);
532 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
533 " with invalid domain failed - %s\n",
534 r.in.req.req1.level, errstr);
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));
546 static BOOL test_DsUnbind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
547 struct DsPrivate *priv)
550 struct drsuapi_DsUnbind r;
553 r.in.bind_handle = &priv->bind_handle;
554 r.out.bind_handle = &priv->bind_handle;
556 printf("testing DsUnbind\n");
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);
564 printf("dcerpc_drsuapi_DsUnbind failed - %s\n", errstr);
566 } else if (!W_ERROR_IS_OK(r.out.result)) {
567 printf("DsBind failed - %s\n", win_errstr(r.out.result));
574 BOOL torture_rpc_drsuapi(void)
577 struct dcerpc_pipe *p;
580 struct DsPrivate priv;
582 status = torture_rpc_connection(&p,
585 DCERPC_DRSUAPI_VERSION);
586 if (!NT_STATUS_IS_OK(status)) {
590 printf("Connected to DRAUAPI pipe\n");
592 mem_ctx = talloc_init("torture_rpc_drsuapi");
596 if (!test_DsBind(p, mem_ctx, &priv)) {
600 if (!test_DsGetDCInfo(p, mem_ctx, &priv)) {
604 if (!test_DsCrackNames(p, mem_ctx, &priv)) {
608 if (!test_DsUnbind(p, mem_ctx, &priv)) {
612 talloc_destroy(mem_ctx);
614 torture_rpc_close(p);