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 domain_guid;
30 struct GUID site_guid;
31 struct GUID computer_guid;
32 struct GUID server_guid;
33 struct GUID ntds_guid;
36 static BOOL test_DsBind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
37 struct DsPrivate *priv)
40 struct drsuapi_DsBind r;
43 r.in.server_guid = NULL;
44 r.in.bind_info = NULL;
45 r.out.bind_handle = &priv->bind_handle;
47 printf("testing DsBind\n");
49 status = dcerpc_drsuapi_DsBind(p, mem_ctx, &r);
50 if (!NT_STATUS_IS_OK(status)) {
51 const char *errstr = nt_errstr(status);
52 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
53 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
55 printf("dcerpc_drsuapi_DsBind failed - %s\n", errstr);
57 } else if (!W_ERROR_IS_OK(r.out.result)) {
58 printf("DsBind failed - %s\n", win_errstr(r.out.result));
65 static BOOL test_DsCrackNames(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
66 struct DsPrivate *priv)
69 struct drsuapi_DsCrackNames r;
70 struct drsuapi_DsNameString names[1];
72 const char *dns_domain;
73 const char *nt4_domain;
74 const char *FQDN_1779_domain;
75 const char *FQDN_1779_name;
78 r.in.bind_handle = &priv->bind_handle;
80 r.in.req.req1.unknown1 = 0x000004e4;
81 r.in.req.req1.unknown2 = 0x00000407;
82 r.in.req.req1.count = 1;
83 r.in.req.req1.names = names;
84 r.in.req.req1.format_flags = DRSUAPI_DS_NAME_FLAG_NO_FLAGS;
86 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_CANONICAL;
87 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
88 names[0].str = talloc_asprintf(mem_ctx, "%s/", lp_realm());
90 printf("testing DsCrackNames with name '%s' desired format:%d\n",
91 names[0].str, r.in.req.req1.format_desired);
93 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
94 if (!NT_STATUS_IS_OK(status)) {
95 const char *errstr = nt_errstr(status);
96 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
97 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
99 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
101 } else if (!W_ERROR_IS_OK(r.out.result)) {
102 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
110 dns_domain = r.out.ctr.ctr1->array[0].dns_domain_name;
111 nt4_domain = r.out.ctr.ctr1->array[0].result_name;
113 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
114 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
115 names[0].str = nt4_domain;
117 printf("testing DsCrackNames with name '%s' desired format:%d\n",
118 names[0].str, r.in.req.req1.format_desired);
120 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
121 if (!NT_STATUS_IS_OK(status)) {
122 const char *errstr = nt_errstr(status);
123 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
124 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
126 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
128 } else if (!W_ERROR_IS_OK(r.out.result)) {
129 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
137 FQDN_1779_domain = r.out.ctr.ctr1->array[0].result_name;
139 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
140 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
141 names[0].str = talloc_asprintf(mem_ctx, "%s%s$", nt4_domain, dcerpc_server_name(p));
143 printf("testing DsCrackNames with name '%s' desired format:%d\n",
144 names[0].str, r.in.req.req1.format_desired);
146 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
147 if (!NT_STATUS_IS_OK(status)) {
148 const char *errstr = nt_errstr(status);
149 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
150 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
152 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
154 } else if (!W_ERROR_IS_OK(r.out.result)) {
155 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
163 FQDN_1779_name = r.out.ctr.ctr1->array[0].result_name;
165 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
166 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_CANONICAL;
167 names[0].str = FQDN_1779_name;
169 printf("testing DsCrackNames with name '%s' desired format:%d\n",
170 names[0].str, r.in.req.req1.format_desired);
172 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
173 if (!NT_STATUS_IS_OK(status)) {
174 const char *errstr = nt_errstr(status);
175 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
176 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
178 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
180 } else if (!W_ERROR_IS_OK(r.out.result)) {
181 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
189 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_DISPLAY;
191 printf("testing DsCrackNames with name '%s' desired format:%d\n",
192 names[0].str, r.in.req.req1.format_desired);
194 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
195 if (!NT_STATUS_IS_OK(status)) {
196 const char *errstr = nt_errstr(status);
197 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
198 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
200 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
202 } else if (!W_ERROR_IS_OK(r.out.result)) {
203 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
211 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_GUID;
213 printf("testing DsCrackNames with name '%s' desired format:%d\n",
214 names[0].str, r.in.req.req1.format_desired);
216 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
217 if (!NT_STATUS_IS_OK(status)) {
218 const char *errstr = nt_errstr(status);
219 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
220 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
222 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
224 } else if (!W_ERROR_IS_OK(r.out.result)) {
225 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
233 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL;
235 printf("testing DsCrackNames with name '%s' desired format:%d\n",
236 names[0].str, r.in.req.req1.format_desired);
238 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
239 if (!NT_STATUS_IS_OK(status)) {
240 const char *errstr = nt_errstr(status);
241 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
242 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
244 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
246 } else if (!W_ERROR_IS_OK(r.out.result)) {
247 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
255 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL;
257 printf("testing DsCrackNames with name '%s' desired format:%d\n",
258 names[0].str, r.in.req.req1.format_desired);
260 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
261 if (!NT_STATUS_IS_OK(status)) {
262 const char *errstr = nt_errstr(status);
263 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
264 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
266 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
268 } else if (!W_ERROR_IS_OK(r.out.result)) {
269 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
277 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_GUID;
278 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
279 names[0].str = GUID_string2(mem_ctx, &priv->site_guid);
281 printf("testing DsCrackNames with Site GUID '%s' desired format:%d\n",
282 names[0].str, r.in.req.req1.format_desired);
284 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
285 if (!NT_STATUS_IS_OK(status)) {
286 const char *errstr = nt_errstr(status);
287 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
288 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
290 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
292 } else if (!W_ERROR_IS_OK(r.out.result)) {
293 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
301 names[0].str = GUID_string2(mem_ctx, &priv->computer_guid);
303 printf("testing DsCrackNames with Computer GUID '%s' desired format:%d\n",
304 names[0].str, r.in.req.req1.format_desired);
306 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
307 if (!NT_STATUS_IS_OK(status)) {
308 const char *errstr = nt_errstr(status);
309 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
310 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
312 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
314 } else if (!W_ERROR_IS_OK(r.out.result)) {
315 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
323 names[0].str = GUID_string2(mem_ctx, &priv->server_guid);
325 printf("testing DsCrackNames with Server GUID '%s' desired format:%d\n",
326 names[0].str, r.in.req.req1.format_desired);
328 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
329 if (!NT_STATUS_IS_OK(status)) {
330 const char *errstr = nt_errstr(status);
331 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
332 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
334 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
336 } else if (!W_ERROR_IS_OK(r.out.result)) {
337 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
345 names[0].str = GUID_string2(mem_ctx, &priv->ntds_guid);
347 printf("testing DsCrackNames with NTDS GUID '%s' desired format:%d\n",
348 names[0].str, r.in.req.req1.format_desired);
350 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
351 if (!NT_STATUS_IS_OK(status)) {
352 const char *errstr = nt_errstr(status);
353 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
354 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
356 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
358 } else if (!W_ERROR_IS_OK(r.out.result)) {
359 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
370 static BOOL test_DsGetDCInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
371 struct DsPrivate *priv)
374 struct drsuapi_DsGetDomainControllerInfo r;
377 r.in.bind_handle = &priv->bind_handle;
380 r.in.req.req1.domain_name = talloc_strdup(mem_ctx, lp_realm());
381 r.in.req.req1.level = 1;
383 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
384 r.in.req.req1.level, r.in.req.req1.domain_name);
386 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
387 if (!NT_STATUS_IS_OK(status)) {
388 const char *errstr = nt_errstr(status);
389 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
390 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
392 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
393 " with dns domain failed - %s\n",
394 r.in.req.req1.level, errstr);
396 } else if (!W_ERROR_IS_OK(r.out.result)) {
397 printf("DsGetDomainControllerInfo level %d\n"
398 " with dns domain failed - %s\n",
399 r.in.req.req1.level, win_errstr(r.out.result));
403 r.in.req.req1.level = 2;
405 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
406 r.in.req.req1.level, r.in.req.req1.domain_name);
408 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
409 if (!NT_STATUS_IS_OK(status)) {
410 const char *errstr = nt_errstr(status);
411 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
412 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
414 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
415 " with dns domain failed - %s\n",
416 r.in.req.req1.level, errstr);
418 } else if (!W_ERROR_IS_OK(r.out.result)) {
419 printf("DsGetDomainControllerInfo level %d\n"
420 " with dns domain failed - %s\n",
421 r.in.req.req1.level, win_errstr(r.out.result));
424 if (r.out.ctr.ctr2.count > 0) {
425 priv->site_guid = r.out.ctr.ctr2.array[0].site_guid;
426 priv->computer_guid = r.out.ctr.ctr2.array[0].computer_guid;
427 priv->server_guid = r.out.ctr.ctr2.array[0].server_guid;
428 priv->ntds_guid = r.out.ctr.ctr2.array[0].ntds_guid;
432 r.in.req.req1.level = -1;
434 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
435 r.in.req.req1.level, r.in.req.req1.domain_name);
437 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
438 if (!NT_STATUS_IS_OK(status)) {
439 const char *errstr = nt_errstr(status);
440 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
441 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
443 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
444 " with dns domain failed - %s\n",
445 r.in.req.req1.level, errstr);
447 } else if (!W_ERROR_IS_OK(r.out.result)) {
448 printf("DsGetDomainControllerInfo level %d\n"
449 " with dns domain failed - %s\n",
450 r.in.req.req1.level, win_errstr(r.out.result));
454 r.in.req.req1.domain_name = talloc_strdup(mem_ctx, lp_workgroup());
455 r.in.req.req1.level = 2;
457 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
458 r.in.req.req1.level, r.in.req.req1.domain_name);
460 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
461 if (!NT_STATUS_IS_OK(status)) {
462 const char *errstr = nt_errstr(status);
463 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
464 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
466 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
467 " with netbios domain failed - %s\n",
468 r.in.req.req1.level, errstr);
470 } else if (!W_ERROR_IS_OK(r.out.result)) {
471 printf("DsGetDomainControllerInfo level %d\n"
472 " with netbios domain failed - %s\n",
473 r.in.req.req1.level, win_errstr(r.out.result));
477 r.in.req.req1.domain_name = "__UNKNOWN_DOMAIN__";
478 r.in.req.req1.level = 2;
480 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
481 r.in.req.req1.level, r.in.req.req1.domain_name);
483 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
484 if (!NT_STATUS_IS_OK(status)) {
485 const char *errstr = nt_errstr(status);
486 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
487 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
489 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
490 " with invalid domain failed - %s\n",
491 r.in.req.req1.level, errstr);
493 } else if (!W_ERROR_EQUAL(r.out.result, WERR_DS_OBJ_NOT_FOUND)) {
494 printf("DsGetDomainControllerInfo level %d\n"
495 " with invalid domain not expected error (WERR_DS_OBJ_NOT_FOUND) - %s\n",
496 r.in.req.req1.level, win_errstr(r.out.result));
503 static BOOL test_DsUnbind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
504 struct DsPrivate *priv)
507 struct drsuapi_DsUnbind r;
510 r.in.bind_handle = &priv->bind_handle;
511 r.out.bind_handle = &priv->bind_handle;
513 printf("testing DsUnbind\n");
515 status = dcerpc_drsuapi_DsUnbind(p, mem_ctx, &r);
516 if (!NT_STATUS_IS_OK(status)) {
517 const char *errstr = nt_errstr(status);
518 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
519 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
521 printf("dcerpc_drsuapi_DsUnbind failed - %s\n", errstr);
523 } else if (!W_ERROR_IS_OK(r.out.result)) {
524 printf("DsBind failed - %s\n", win_errstr(r.out.result));
531 BOOL torture_rpc_drsuapi(void)
534 struct dcerpc_pipe *p;
537 struct DsPrivate priv;
539 status = torture_rpc_connection(&p,
542 DCERPC_DRSUAPI_VERSION);
543 if (!NT_STATUS_IS_OK(status)) {
547 printf("Connected to DRAUAPI pipe\n");
549 mem_ctx = talloc_init("torture_rpc_drsuapi");
551 if (!test_DsBind(p, mem_ctx, &priv)) {
555 if (!test_DsGetDCInfo(p, mem_ctx, &priv)) {
559 if (!test_DsCrackNames(p, mem_ctx, &priv)) {
563 if (!test_DsUnbind(p, mem_ctx, &priv)) {
568 if (!test_scan(p, mem_ctx)) {
572 talloc_destroy(mem_ctx);
574 torture_rpc_close(p);