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 #define TEST_MACHINE_NAME "torturetest"
28 static BOOL test_DsBind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
29 struct policy_handle *bind_handle)
32 struct drsuapi_DsBind r;
35 r.in.server_guid = NULL;
36 r.in.bind_info = NULL;
37 r.out.bind_handle = bind_handle;
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("drsuapi_DsBind failed - %s\n", errstr);
52 static BOOL test_DsCrackNames(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
53 struct policy_handle *bind_handle)
56 struct drsuapi_DsCrackNames r;
57 struct drsuapi_DsNameString names[1];
59 const char *dns_domain;
60 const char *nt4_domain;
61 const char *FQDN_1779_domain;
62 const char *FQDN_1779_name;
65 r.in.bind_handle = bind_handle;
67 r.in.req.req1.unknown1 = 0x000004e4;
68 r.in.req.req1.unknown2 = 0x00000407;
69 r.in.req.req1.count = 1;
70 r.in.req.req1.names = names;
71 r.in.req.req1.format_flags = DRSUAPI_DS_NAME_FLAG_NO_FLAGS;
73 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_CANONICAL;
74 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
75 names[0].str = talloc_asprintf(mem_ctx, "%s/", lp_realm());
77 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
78 if (!NT_STATUS_IS_OK(status)) {
79 const char *errstr = nt_errstr(status);
80 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
81 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
83 printf("drsuapi_DsCrackNames failed - %s\n", errstr);
91 dns_domain = r.out.ctr.ctr1->array[0].dns_domain_name;
92 nt4_domain = r.out.ctr.ctr1->array[0].result_name;
94 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
95 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
96 names[0].str = nt4_domain;
98 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
99 if (!NT_STATUS_IS_OK(status)) {
100 const char *errstr = nt_errstr(status);
101 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
102 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
104 printf("drsuapi_DsCrackNames failed - %s\n", errstr);
112 FQDN_1779_domain = r.out.ctr.ctr1->array[0].result_name;
114 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
115 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
116 names[0].str = talloc_asprintf(mem_ctx, "%s%s$", nt4_domain, dcerpc_server_name(p));
118 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
119 if (!NT_STATUS_IS_OK(status)) {
120 const char *errstr = nt_errstr(status);
121 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
122 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
124 printf("drsuapi_DsCrackNames failed - %s\n", errstr);
132 FQDN_1779_name = r.out.ctr.ctr1->array[0].result_name;
134 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
135 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_CANONICAL;
136 names[0].str = FQDN_1779_name;
138 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
139 if (!NT_STATUS_IS_OK(status)) {
140 const char *errstr = nt_errstr(status);
141 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
142 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
144 printf("drsuapi_DsCrackNames failed - %s\n", errstr);
152 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_DISPLAY;
154 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
155 if (!NT_STATUS_IS_OK(status)) {
156 const char *errstr = nt_errstr(status);
157 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
158 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
160 printf("drsuapi_DsCrackNames failed - %s\n", errstr);
168 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_GUID;
170 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
171 if (!NT_STATUS_IS_OK(status)) {
172 const char *errstr = nt_errstr(status);
173 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
174 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
176 printf("drsuapi_DsCrackNames failed - %s\n", errstr);
184 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL;
186 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
187 if (!NT_STATUS_IS_OK(status)) {
188 const char *errstr = nt_errstr(status);
189 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
190 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
192 printf("drsuapi_DsCrackNames failed - %s\n", errstr);
200 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_SERVICE_PRINCIPAL;
202 status = dcerpc_drsuapi_DsCrackNames(p, mem_ctx, &r);
203 if (!NT_STATUS_IS_OK(status)) {
204 const char *errstr = nt_errstr(status);
205 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
206 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
208 printf("drsuapi_DsCrackNames failed - %s\n", errstr);
219 static BOOL test_DsUnbind(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
220 struct policy_handle *bind_handle)
223 struct drsuapi_DsUnbind r;
226 r.in.bind_handle = bind_handle;
227 r.out.bind_handle = bind_handle;
229 status = dcerpc_drsuapi_DsUnbind(p, mem_ctx, &r);
230 if (!NT_STATUS_IS_OK(status)) {
231 const char *errstr = nt_errstr(status);
232 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
233 errstr = dcerpc_errstr(mem_ctx, p->last_fault_code);
235 printf("drsuapi_DsUnbind failed - %s\n", errstr);
242 BOOL torture_rpc_drsuapi(int dummy)
245 struct dcerpc_pipe *p;
248 struct policy_handle bind_handle;
250 status = torture_rpc_connection(&p,
253 DCERPC_DRSUAPI_VERSION);
254 if (!NT_STATUS_IS_OK(status)) {
258 printf("Connected to DRAUAPI pipe\n");
260 mem_ctx = talloc_init("torture_rpc_drsuapi");
262 if (!test_DsBind(p, mem_ctx, &bind_handle)) {
266 if (!test_DsCrackNames(p, mem_ctx, &bind_handle)) {
270 if (!test_DsUnbind(p, mem_ctx, &bind_handle)) {
275 if (!test_scan(p, mem_ctx)) {
279 talloc_destroy(mem_ctx);
281 torture_rpc_close(p);