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.
26 static BOOL test_DsBind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
27 struct policy_handle *bind_handle)
30 struct drsuapi_DsBind r;
33 r.in.server_guid = NULL;
34 r.in.bind_info = NULL;
35 r.out.bind_handle = bind_handle;
37 printf("testing DsBind\n");
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);
45 printf("dcerpc_drsuapi_DsBind failed - %s\n", errstr);
47 } else if (!W_ERROR_IS_OK(r.out.result)) {
48 printf("DsBind failed - %s\n", win_errstr(r.out.result));
55 static BOOL test_DsCrackNames(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
56 struct policy_handle *bind_handle)
59 struct drsuapi_DsCrackNames r;
60 struct drsuapi_DsNameString names[1];
62 const char *dns_domain;
63 const char *nt4_domain;
64 const char *FQDN_1779_domain;
65 const char *FQDN_1779_name;
68 r.in.bind_handle = bind_handle;
70 r.in.req.req1.unknown1 = 0x000004e4;
71 r.in.req.req1.unknown2 = 0x00000407;
72 r.in.req.req1.count = 1;
73 r.in.req.req1.names = names;
74 r.in.req.req1.format_flags = DRSUAPI_DS_NAME_FLAG_NO_FLAGS;
76 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_CANONICAL;
77 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
78 names[0].str = talloc_asprintf(mem_ctx, "%s/", lp_realm());
80 printf("testing DsCrackNames with name '%s' desired format:%d\n",
81 names[0].str, r.in.req.req1.format_desired);
83 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
84 if (!NT_STATUS_IS_OK(status)) {
85 const char *errstr = nt_errstr(status);
86 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
87 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
89 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
91 } else if (!W_ERROR_IS_OK(r.out.result)) {
92 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
100 dns_domain = r.out.ctr.ctr1->array[0].dns_domain_name;
101 nt4_domain = r.out.ctr.ctr1->array[0].result_name;
103 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
104 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
105 names[0].str = nt4_domain;
107 printf("testing DsCrackNames with name '%s' desired format:%d\n",
108 names[0].str, r.in.req.req1.format_desired);
110 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
111 if (!NT_STATUS_IS_OK(status)) {
112 const char *errstr = nt_errstr(status);
113 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
114 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
116 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
118 } else if (!W_ERROR_IS_OK(r.out.result)) {
119 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
127 FQDN_1779_domain = r.out.ctr.ctr1->array[0].result_name;
129 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
130 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
131 names[0].str = talloc_asprintf(mem_ctx, "%s%s$", nt4_domain, dcerpc_server_name(p));
133 printf("testing DsCrackNames with name '%s' desired format:%d\n",
134 names[0].str, r.in.req.req1.format_desired);
136 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
137 if (!NT_STATUS_IS_OK(status)) {
138 const char *errstr = nt_errstr(status);
139 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
140 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
142 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
144 } else if (!W_ERROR_IS_OK(r.out.result)) {
145 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
153 FQDN_1779_name = r.out.ctr.ctr1->array[0].result_name;
155 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
156 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_CANONICAL;
157 names[0].str = FQDN_1779_name;
159 printf("testing DsCrackNames with name '%s' desired format:%d\n",
160 names[0].str, r.in.req.req1.format_desired);
162 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
163 if (!NT_STATUS_IS_OK(status)) {
164 const char *errstr = nt_errstr(status);
165 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
166 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
168 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
170 } else if (!W_ERROR_IS_OK(r.out.result)) {
171 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
179 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_DISPLAY;
181 printf("testing DsCrackNames with name '%s' desired format:%d\n",
182 names[0].str, r.in.req.req1.format_desired);
184 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
185 if (!NT_STATUS_IS_OK(status)) {
186 const char *errstr = nt_errstr(status);
187 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
188 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
190 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
192 } else if (!W_ERROR_IS_OK(r.out.result)) {
193 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
201 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_GUID;
203 printf("testing DsCrackNames with name '%s' desired format:%d\n",
204 names[0].str, r.in.req.req1.format_desired);
206 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
207 if (!NT_STATUS_IS_OK(status)) {
208 const char *errstr = nt_errstr(status);
209 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
210 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
212 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
214 } else if (!W_ERROR_IS_OK(r.out.result)) {
215 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
223 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL;
225 printf("testing DsCrackNames with name '%s' desired format:%d\n",
226 names[0].str, r.in.req.req1.format_desired);
228 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
229 if (!NT_STATUS_IS_OK(status)) {
230 const char *errstr = nt_errstr(status);
231 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
232 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
234 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
236 } else if (!W_ERROR_IS_OK(r.out.result)) {
237 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
245 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL;
247 printf("testing DsCrackNames with name '%s' desired format:%d\n",
248 names[0].str, r.in.req.req1.format_desired);
250 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
251 if (!NT_STATUS_IS_OK(status)) {
252 const char *errstr = nt_errstr(status);
253 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
254 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
256 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
258 } else if (!W_ERROR_IS_OK(r.out.result)) {
259 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
270 static BOOL test_DsGetDCInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
271 struct policy_handle *bind_handle)
274 struct drsuapi_DsGetDomainControllerInfo r;
277 r.in.bind_handle = bind_handle;
280 r.in.req.req1.domain_name = talloc_strdup(mem_ctx, lp_realm());
281 r.in.req.req1.level = 1;
283 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
284 r.in.req.req1.level, r.in.req.req1.domain_name);
286 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
287 if (!NT_STATUS_IS_OK(status)) {
288 const char *errstr = nt_errstr(status);
289 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
290 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
292 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
293 " with dns domain failed - %s\n",
294 r.in.req.req1.level, errstr);
296 } else if (!W_ERROR_IS_OK(r.out.result)) {
297 printf("DsGetDomainControllerInfo level %d\n"
298 " with dns domain failed - %s\n",
299 r.in.req.req1.level, win_errstr(r.out.result));
303 r.in.req.req1.level = 2;
305 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
306 r.in.req.req1.level, r.in.req.req1.domain_name);
308 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
309 if (!NT_STATUS_IS_OK(status)) {
310 const char *errstr = nt_errstr(status);
311 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
312 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
314 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
315 " with dns domain failed - %s\n",
316 r.in.req.req1.level, errstr);
318 } else if (!W_ERROR_IS_OK(r.out.result)) {
319 printf("DsGetDomainControllerInfo level %d\n"
320 " with dns domain failed - %s\n",
321 r.in.req.req1.level, win_errstr(r.out.result));
325 r.in.req.req1.level = -1;
327 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
328 r.in.req.req1.level, r.in.req.req1.domain_name);
330 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
331 if (!NT_STATUS_IS_OK(status)) {
332 const char *errstr = nt_errstr(status);
333 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
334 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
336 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
337 " with dns domain failed - %s\n",
338 r.in.req.req1.level, errstr);
340 } else if (!W_ERROR_IS_OK(r.out.result)) {
341 printf("DsGetDomainControllerInfo level %d\n"
342 " with dns domain failed - %s\n",
343 r.in.req.req1.level, win_errstr(r.out.result));
347 r.in.req.req1.domain_name = talloc_strdup(mem_ctx, lp_workgroup());
348 r.in.req.req1.level = 2;
350 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
351 r.in.req.req1.level, r.in.req.req1.domain_name);
353 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
354 if (!NT_STATUS_IS_OK(status)) {
355 const char *errstr = nt_errstr(status);
356 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
357 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
359 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
360 " with netbios domain failed - %s\n",
361 r.in.req.req1.level, errstr);
363 } else if (!W_ERROR_IS_OK(r.out.result)) {
364 printf("DsGetDomainControllerInfo level %d\n"
365 " with netbios domain failed - %s\n",
366 r.in.req.req1.level, win_errstr(r.out.result));
370 r.in.req.req1.domain_name = "__UNKNOWN_DOMAIN__";
371 r.in.req.req1.level = 2;
373 printf("testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
374 r.in.req.req1.level, r.in.req.req1.domain_name);
376 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, mem_ctx, &r);
377 if (!NT_STATUS_IS_OK(status)) {
378 const char *errstr = nt_errstr(status);
379 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
380 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
382 printf("dcerpc_drsuapi_DsGetDomainControllerInfo level %d\n"
383 " with invalid domain failed - %s\n",
384 r.in.req.req1.level, errstr);
386 } else if (!W_ERROR_EQUAL(r.out.result, WERR_DS_OBJ_NOT_FOUND)) {
387 printf("DsGetDomainControllerInfo level %d\n"
388 " with invalid domain not expected error (WERR_DS_OBJ_NOT_FOUND) - %s\n",
389 r.in.req.req1.level, win_errstr(r.out.result));
396 static BOOL test_DsUnbind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
397 struct policy_handle *bind_handle)
400 struct drsuapi_DsUnbind r;
403 r.in.bind_handle = bind_handle;
404 r.out.bind_handle = bind_handle;
406 printf("testing DsUnbind\n");
408 status = dcerpc_drsuapi_DsUnbind(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_DsUnbind failed - %s\n", errstr);
416 } else if (!W_ERROR_IS_OK(r.out.result)) {
417 printf("DsBind failed - %s\n", win_errstr(r.out.result));
424 BOOL torture_rpc_drsuapi(void)
427 struct dcerpc_pipe *p;
430 struct policy_handle bind_handle;
432 status = torture_rpc_connection(&p,
435 DCERPC_DRSUAPI_VERSION);
436 if (!NT_STATUS_IS_OK(status)) {
440 printf("Connected to DRAUAPI pipe\n");
442 mem_ctx = talloc_init("torture_rpc_drsuapi");
444 if (!test_DsBind(p, mem_ctx, &bind_handle)) {
448 if (!test_DsGetDCInfo(p, mem_ctx, &bind_handle)) {
452 if (!test_DsCrackNames(p, mem_ctx, &bind_handle)) {
456 if (!test_DsUnbind(p, mem_ctx, &bind_handle)) {
461 if (!test_scan(p, mem_ctx)) {
465 talloc_destroy(mem_ctx);
467 torture_rpc_close(p);