Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : RPC pipe client
4 :
5 : Copyright (C) Guenther Deschner 2008
6 :
7 : This program is free software; you can redistribute it and/or modify
8 : it under the terms of the GNU General Public License as published by
9 : the Free Software Foundation; either version 3 of the License, or
10 : (at your option) any later version.
11 :
12 : This program is distributed in the hope that it will be useful,
13 : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : GNU General Public License for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with this program. If not, see <http://www.gnu.org/licenses/>.
19 : */
20 :
21 : #include "includes.h"
22 : #include "rpcclient.h"
23 : #include "../librpc/gen_ndr/ndr_drsuapi_c.h"
24 :
25 0 : static WERROR cracknames(struct rpc_pipe_client *cli,
26 : TALLOC_CTX *mem_ctx,
27 : struct policy_handle *bind_handle,
28 : enum drsuapi_DsNameFormat format_offered,
29 : enum drsuapi_DsNameFormat format_desired,
30 : int argc,
31 : const char **argv,
32 : union drsuapi_DsNameCtr *ctr)
33 : {
34 : NTSTATUS status;
35 : WERROR werr;
36 : int i;
37 0 : uint32_t level = 1;
38 : union drsuapi_DsNameRequest req;
39 : uint32_t level_out;
40 : struct drsuapi_DsNameString *names;
41 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
42 :
43 0 : names = talloc_zero_array(mem_ctx, struct drsuapi_DsNameString, argc);
44 0 : W_ERROR_HAVE_NO_MEMORY(names);
45 :
46 0 : for (i=0; i<argc; i++) {
47 0 : names[i].str = argv[i];
48 : }
49 :
50 0 : req.req1.codepage = 1252; /* german */
51 0 : req.req1.language = 0x00000407; /* german */
52 0 : req.req1.count = argc;
53 0 : req.req1.names = names;
54 0 : req.req1.format_flags = DRSUAPI_DS_NAME_FLAG_NO_FLAGS;
55 0 : req.req1.format_offered = format_offered;
56 0 : req.req1.format_desired = format_desired;
57 :
58 0 : status = dcerpc_drsuapi_DsCrackNames(b, mem_ctx,
59 : bind_handle,
60 : level,
61 : &req,
62 : &level_out,
63 : ctr,
64 : &werr);
65 0 : if (!NT_STATUS_IS_OK(status)) {
66 0 : return ntstatus_to_werror(status);
67 : }
68 :
69 0 : if (!W_ERROR_IS_OK(werr)) {
70 0 : return werr;
71 : }
72 :
73 0 : return WERR_OK;
74 : }
75 :
76 0 : static WERROR cmd_drsuapi_cracknames(struct rpc_pipe_client *cli,
77 : TALLOC_CTX *mem_ctx, int argc,
78 : const char **argv)
79 : {
80 : NTSTATUS status;
81 : WERROR werr;
82 : int i;
83 :
84 : struct GUID bind_guid;
85 : struct policy_handle bind_handle;
86 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
87 :
88 : union drsuapi_DsNameCtr ctr;
89 :
90 0 : if (argc < 2) {
91 0 : printf("usage: %s name\n", argv[0]);
92 0 : return WERR_OK;
93 : }
94 :
95 0 : GUID_from_string(DRSUAPI_DS_BIND_GUID, &bind_guid);
96 :
97 0 : status = dcerpc_drsuapi_DsBind(b, mem_ctx,
98 : &bind_guid,
99 : NULL,
100 : &bind_handle,
101 : &werr);
102 :
103 0 : if (!NT_STATUS_IS_OK(status)) {
104 0 : return ntstatus_to_werror(status);
105 : }
106 :
107 0 : if (!W_ERROR_IS_OK(werr)) {
108 0 : return werr;
109 : }
110 :
111 0 : werr = cracknames(cli, mem_ctx,
112 : &bind_handle,
113 : DRSUAPI_DS_NAME_FORMAT_UNKNOWN,
114 : DRSUAPI_DS_NAME_FORMAT_FQDN_1779,
115 : 1,
116 : argv+1,
117 : &ctr);
118 :
119 0 : if (!W_ERROR_IS_OK(werr)) {
120 0 : goto out;
121 : }
122 :
123 0 : for (i=0; i < ctr.ctr1->count; i++) {
124 0 : printf("status: %d\n",
125 0 : ctr.ctr1->array[i].status);
126 0 : printf("dns_domain_name: %s\n",
127 0 : ctr.ctr1->array[i].dns_domain_name);
128 0 : printf("result_name: %s\n",
129 0 : ctr.ctr1->array[i].result_name);
130 : }
131 :
132 0 : out:
133 0 : if (is_valid_policy_hnd(&bind_handle)) {
134 : WERROR _werr;
135 0 : dcerpc_drsuapi_DsUnbind(b, mem_ctx, &bind_handle, &_werr);
136 : }
137 :
138 0 : return werr;
139 : }
140 :
141 0 : static void display_domain_controller_info_01(struct drsuapi_DsGetDCConnection01 *r)
142 : {
143 0 : printf("client_ip_address:\t%s\n", r->client_ip_address);
144 0 : printf("unknown2:\t%d\n", r->unknown2);
145 0 : printf("connection_time:\t%d\n", r->connection_time);
146 0 : printf("unknown4:\t%d\n", r->unknown4);
147 0 : printf("unknown5:\t%d\n", r->unknown5);
148 0 : printf("unknown6:\t%d\n", r->unknown6);
149 0 : printf("client_account:\t%s\n", r->client_account);
150 0 : }
151 :
152 0 : static void display_domain_controller_info_1(struct drsuapi_DsGetDCInfo1 *r)
153 : {
154 0 : printf("netbios_name:\t%s\n", r->netbios_name);
155 0 : printf("dns_name:\t%s\n", r->dns_name);
156 0 : printf("site_name:\t%s\n", r->site_name);
157 0 : printf("computer_dn:\t%s\n", r->computer_dn);
158 0 : printf("server_dn:\t%s\n", r->server_dn);
159 0 : printf("is_pdc:\t\t%s\n", r->is_pdc ? "true" : "false");
160 0 : printf("is_enabled:\t%s\n", r->is_enabled ? "true" : "false");
161 0 : }
162 :
163 0 : static void display_domain_controller_info_2(struct drsuapi_DsGetDCInfo2 *r)
164 : {
165 0 : printf("netbios_name:\t%s\n", r->netbios_name);
166 0 : printf("dns_name:\t%s\n", r->dns_name);
167 0 : printf("site_name:\t%s\n", r->site_name);
168 0 : printf("site_dn:\t%s\n", r->site_dn);
169 0 : printf("computer_dn:\t%s\n", r->computer_dn);
170 0 : printf("server_dn:\t%s\n", r->server_dn);
171 0 : printf("ntds_dn:\t%s\n", r->ntds_dn);
172 0 : printf("is_pdc:\t\t%s\n", r->is_pdc ? "true" : "false");
173 0 : printf("is_enabled:\t%s\n", r->is_enabled ? "true" : "false");
174 0 : printf("is_gc:\t\t%s\n", r->is_gc ? "true" : "false");
175 0 : printf("site_guid:\t%s\n", GUID_string(talloc_tos(), &r->site_guid));
176 0 : printf("computer_guid:\t%s\n", GUID_string(talloc_tos(), &r->computer_guid));
177 0 : printf("server_guid:\t%s\n", GUID_string(talloc_tos(), &r->server_guid));
178 0 : printf("ntds_guid:\t%s\n", GUID_string(talloc_tos(), &r->ntds_guid));
179 0 : }
180 :
181 0 : static void display_domain_controller_info_3(struct drsuapi_DsGetDCInfo3 *r)
182 : {
183 0 : printf("netbios_name:\t%s\n", r->netbios_name);
184 0 : printf("dns_name:\t%s\n", r->dns_name);
185 0 : printf("site_name:\t%s\n", r->site_name);
186 0 : printf("site_dn:\t%s\n", r->site_dn);
187 0 : printf("computer_dn:\t%s\n", r->computer_dn);
188 0 : printf("server_dn:\t%s\n", r->server_dn);
189 0 : printf("ntds_dn:\t%s\n", r->ntds_dn);
190 0 : printf("is_pdc:\t\t%s\n", r->is_pdc ? "true" : "false");
191 0 : printf("is_enabled:\t%s\n", r->is_enabled ? "true" : "false");
192 0 : printf("is_gc:\t\t%s\n", r->is_gc ? "true" : "false");
193 0 : printf("is_rodc:\t%s\n", r->is_rodc ? "true" : "false");
194 0 : printf("site_guid:\t%s\n", GUID_string(talloc_tos(), &r->site_guid));
195 0 : printf("computer_guid:\t%s\n", GUID_string(talloc_tos(), &r->computer_guid));
196 0 : printf("server_guid:\t%s\n", GUID_string(talloc_tos(), &r->server_guid));
197 0 : printf("ntds_guid:\t%s\n", GUID_string(talloc_tos(), &r->ntds_guid));
198 0 : }
199 :
200 0 : static void display_domain_controller_info(int32_t level,
201 : union drsuapi_DsGetDCInfoCtr *ctr)
202 : {
203 : int i;
204 :
205 0 : switch (level) {
206 0 : case DRSUAPI_DC_CONNECTION_CTR_01:
207 0 : for (i=0; i<ctr->ctr01.count; i++) {
208 0 : printf("----------\n");
209 0 : display_domain_controller_info_01(&ctr->ctr01.array[i]);
210 : }
211 0 : break;
212 0 : case DRSUAPI_DC_INFO_CTR_1:
213 0 : for (i=0; i<ctr->ctr1.count; i++) {
214 0 : printf("----------\n");
215 0 : display_domain_controller_info_1(&ctr->ctr1.array[i]);
216 : }
217 0 : break;
218 0 : case DRSUAPI_DC_INFO_CTR_2:
219 0 : for (i=0; i<ctr->ctr2.count; i++) {
220 0 : printf("----------\n");
221 0 : display_domain_controller_info_2(&ctr->ctr2.array[i]);
222 : }
223 0 : break;
224 0 : case DRSUAPI_DC_INFO_CTR_3:
225 0 : for (i=0; i<ctr->ctr3.count; i++) {
226 0 : printf("----------\n");
227 0 : display_domain_controller_info_3(&ctr->ctr3.array[i]);
228 : }
229 0 : break;
230 0 : default:
231 0 : break;
232 : }
233 0 : }
234 :
235 0 : static WERROR cmd_drsuapi_getdcinfo(struct rpc_pipe_client *cli,
236 : TALLOC_CTX *mem_ctx, int argc,
237 : const char **argv)
238 : {
239 : NTSTATUS status;
240 : WERROR werr;
241 :
242 : struct GUID bind_guid;
243 : struct policy_handle bind_handle;
244 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
245 :
246 0 : const char *domain = NULL;
247 0 : int32_t level = 1;
248 : int32_t level_out;
249 : union drsuapi_DsGetDCInfoRequest req;
250 : union drsuapi_DsGetDCInfoCtr ctr;
251 :
252 0 : if (argc < 2) {
253 0 : printf("usage: %s domain [level]\n", argv[0]);
254 0 : return WERR_OK;
255 : }
256 :
257 0 : domain = argv[1];
258 0 : if (argc >= 3) {
259 0 : level = atoi(argv[2]);
260 : }
261 :
262 0 : GUID_from_string(DRSUAPI_DS_BIND_GUID, &bind_guid);
263 :
264 0 : status = dcerpc_drsuapi_DsBind(b, mem_ctx,
265 : &bind_guid,
266 : NULL,
267 : &bind_handle,
268 : &werr);
269 :
270 0 : if (!NT_STATUS_IS_OK(status)) {
271 0 : return ntstatus_to_werror(status);
272 : }
273 :
274 0 : if (!W_ERROR_IS_OK(werr)) {
275 0 : return werr;
276 : }
277 :
278 0 : req.req1.domain_name = domain;
279 0 : req.req1.level = level;
280 :
281 0 : status = dcerpc_drsuapi_DsGetDomainControllerInfo(b, mem_ctx,
282 : &bind_handle,
283 : 1,
284 : &req,
285 : &level_out,
286 : &ctr,
287 : &werr);
288 0 : if (!NT_STATUS_IS_OK(status)) {
289 0 : werr = ntstatus_to_werror(status);
290 0 : goto out;
291 : }
292 :
293 0 : if (!W_ERROR_IS_OK(werr)) {
294 0 : goto out;
295 : }
296 :
297 0 : display_domain_controller_info(level_out, &ctr);
298 0 : out:
299 0 : if (is_valid_policy_hnd(&bind_handle)) {
300 : WERROR _werr;
301 0 : dcerpc_drsuapi_DsUnbind(b, mem_ctx, &bind_handle, &_werr);
302 : }
303 :
304 0 : return werr;
305 : }
306 :
307 0 : static WERROR cmd_drsuapi_writeaccountspn(struct rpc_pipe_client *cli,
308 : TALLOC_CTX *mem_ctx, int argc,
309 : const char **argv)
310 : {
311 : NTSTATUS status;
312 : WERROR werr;
313 :
314 : struct GUID bind_guid;
315 : struct policy_handle bind_handle;
316 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
317 0 : struct drsuapi_DsNameString *spn_names = NULL;
318 :
319 0 : int i = 0;
320 : uint32_t level_out;
321 : union drsuapi_DsWriteAccountSpnRequest req;
322 : union drsuapi_DsWriteAccountSpnResult result;
323 :
324 0 : if (argc < 4) {
325 0 : printf("usage: %s [add|replace|delete] dn [spn_names]+\n", argv[0]);
326 0 : return WERR_OK;
327 : }
328 :
329 0 : req.req1.unknown1 = 0; /* Unused, must be 0 */
330 0 : req.req1.object_dn = argv[2];
331 0 : req.req1.count = argc - 3;
332 :
333 0 : if (strcmp(argv[1], "add") == 0) {
334 0 : req.req1.operation = DRSUAPI_DS_SPN_OPERATION_ADD;
335 0 : } else if (strcmp(argv[1], "replace") == 0) {
336 0 : req.req1.operation = DRSUAPI_DS_SPN_OPERATION_REPLACE;
337 0 : } else if (strcmp(argv[1], "delete") == 0) {
338 0 : req.req1.operation = DRSUAPI_DS_SPN_OPERATION_DELETE;
339 : } else {
340 0 : printf("usage: %s [add|replace|delete] dn [spn_names]+\n", argv[0]);
341 0 : return WERR_OK;
342 : }
343 :
344 0 : spn_names = talloc_zero_array(mem_ctx,
345 : struct drsuapi_DsNameString,
346 : req.req1.count);
347 0 : W_ERROR_HAVE_NO_MEMORY(spn_names);
348 :
349 0 : for (i=0; i<req.req1.count; i++) {
350 0 : spn_names[i].str = argv[i + 3];
351 : }
352 :
353 0 : req.req1.spn_names = spn_names;
354 :
355 0 : GUID_from_string(DRSUAPI_DS_BIND_GUID, &bind_guid);
356 :
357 0 : status = dcerpc_drsuapi_DsBind(b, mem_ctx,
358 : &bind_guid,
359 : NULL,
360 : &bind_handle,
361 : &werr);
362 :
363 0 : if (!NT_STATUS_IS_OK(status)) {
364 0 : return ntstatus_to_werror(status);
365 : }
366 :
367 0 : if (!W_ERROR_IS_OK(werr)) {
368 0 : return werr;
369 : }
370 :
371 0 : status = dcerpc_drsuapi_DsWriteAccountSpn(b, mem_ctx,
372 : &bind_handle,
373 : 1,
374 : &req,
375 : &level_out,
376 : &result,
377 : &werr);
378 :
379 0 : if (!NT_STATUS_IS_OK(status)) {
380 0 : werr = ntstatus_to_werror(status);
381 0 : goto out;
382 : }
383 :
384 0 : if (!W_ERROR_IS_OK(werr)) {
385 0 : goto out;
386 : }
387 :
388 0 : out:
389 0 : if (is_valid_policy_hnd(&bind_handle)) {
390 : WERROR _werr;
391 0 : dcerpc_drsuapi_DsUnbind(b, mem_ctx, &bind_handle, &_werr);
392 : }
393 :
394 0 : return werr;
395 : }
396 :
397 0 : static WERROR cmd_drsuapi_getncchanges(struct rpc_pipe_client *cli,
398 : TALLOC_CTX *mem_ctx, int argc,
399 : const char **argv)
400 : {
401 : NTSTATUS status;
402 : WERROR werr;
403 :
404 : struct policy_handle bind_handle;
405 0 : struct dcerpc_binding_handle *b = cli->binding_handle;
406 :
407 : struct GUID bind_guid;
408 : struct drsuapi_DsBindInfoCtr bind_info;
409 : struct drsuapi_DsBindInfo28 info28;
410 :
411 0 : const char *nc_dn = NULL;
412 :
413 : DATA_BLOB session_key;
414 :
415 0 : uint32_t level = 8;
416 0 : bool single = false;
417 0 : uint32_t level_out = 0;
418 : union drsuapi_DsGetNCChangesRequest req;
419 : union drsuapi_DsGetNCChangesCtr ctr;
420 : struct drsuapi_DsReplicaObjectIdentifier nc;
421 :
422 0 : struct drsuapi_DsGetNCChangesCtr1 *ctr1 = NULL;
423 0 : struct drsuapi_DsGetNCChangesCtr6 *ctr6 = NULL;
424 0 : uint32_t out_level = 0;
425 : int y;
426 :
427 0 : uint32_t supported_extensions = 0;
428 0 : uint32_t replica_flags = DRSUAPI_DRS_WRIT_REP |
429 : DRSUAPI_DRS_INIT_SYNC |
430 : DRSUAPI_DRS_PER_SYNC |
431 : DRSUAPI_DRS_GET_ANC |
432 : DRSUAPI_DRS_NEVER_SYNCED;
433 :
434 0 : if (argc > 3) {
435 0 : printf("usage: %s [naming_context_or_object_dn [single]]\n", argv[0]);
436 0 : return WERR_OK;
437 : }
438 :
439 0 : if (argc >= 2) {
440 0 : nc_dn = argv[1];
441 : }
442 :
443 0 : if (argc == 3) {
444 0 : if (strequal(argv[2], "single")) {
445 0 : single = true;
446 : } else {
447 0 : printf("warning: ignoring unknown argument '%s'\n",
448 0 : argv[2]);
449 : }
450 : }
451 :
452 0 : ZERO_STRUCT(info28);
453 :
454 0 : ZERO_STRUCT(req);
455 :
456 0 : GUID_from_string(DRSUAPI_DS_BIND_GUID, &bind_guid);
457 :
458 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_BASE;
459 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION;
460 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI;
461 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2;
462 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS;
463 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1;
464 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION;
465 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE;
466 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2;
467 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION;
468 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2;
469 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD;
470 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND;
471 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO;
472 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION;
473 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01;
474 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP;
475 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY;
476 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3;
477 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2;
478 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6;
479 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS;
480 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8;
481 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5;
482 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6;
483 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
484 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7;
485 0 : info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT;
486 0 : info28.site_guid = GUID_zero();
487 0 : info28.pid = 0;
488 0 : info28.repl_epoch = 0;
489 :
490 0 : bind_info.length = 28;
491 0 : bind_info.info.info28 = info28;
492 :
493 0 : status = dcerpc_drsuapi_DsBind(b, mem_ctx,
494 : &bind_guid,
495 : &bind_info,
496 : &bind_handle,
497 : &werr);
498 :
499 0 : if (!NT_STATUS_IS_OK(status)) {
500 0 : return ntstatus_to_werror(status);
501 : }
502 :
503 0 : if (!W_ERROR_IS_OK(werr)) {
504 0 : return werr;
505 : }
506 :
507 0 : if (bind_info.length == 24) {
508 0 : supported_extensions = bind_info.info.info24.supported_extensions;
509 0 : } else if (bind_info.length == 28) {
510 0 : supported_extensions = bind_info.info.info28.supported_extensions;
511 0 : } else if (bind_info.length == 32) {
512 0 : supported_extensions = bind_info.info.info32.supported_extensions;
513 0 : } else if (bind_info.length == 48) {
514 0 : supported_extensions = bind_info.info.info48.supported_extensions;
515 0 : } else if (bind_info.length == 52) {
516 0 : supported_extensions = bind_info.info.info52.supported_extensions;
517 : }
518 :
519 0 : if (!nc_dn) {
520 :
521 : union drsuapi_DsNameCtr crack_ctr;
522 : const char *name;
523 :
524 0 : name = talloc_asprintf(mem_ctx, "%s\\", lp_workgroup());
525 0 : W_ERROR_HAVE_NO_MEMORY(name);
526 :
527 0 : werr = cracknames(cli, mem_ctx,
528 : &bind_handle,
529 : DRSUAPI_DS_NAME_FORMAT_UNKNOWN,
530 : DRSUAPI_DS_NAME_FORMAT_FQDN_1779,
531 : 1,
532 : &name,
533 : &crack_ctr);
534 0 : if (!W_ERROR_IS_OK(werr)) {
535 0 : return werr;
536 : }
537 :
538 0 : if (crack_ctr.ctr1->count != 1) {
539 0 : return WERR_NO_SUCH_DOMAIN;
540 : }
541 :
542 0 : if (crack_ctr.ctr1->array[0].status != DRSUAPI_DS_NAME_STATUS_OK) {
543 0 : return WERR_NO_SUCH_DOMAIN;
544 : }
545 :
546 0 : nc_dn = talloc_strdup(mem_ctx, crack_ctr.ctr1->array[0].result_name);
547 0 : W_ERROR_HAVE_NO_MEMORY(nc_dn);
548 :
549 0 : printf("using: %s\n", nc_dn);
550 : }
551 :
552 0 : nc.dn = nc_dn;
553 0 : nc.guid = GUID_zero();
554 0 : nc.sid = (struct dom_sid) {0};
555 :
556 0 : if (supported_extensions & DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8) {
557 0 : level = 8;
558 0 : req.req8.naming_context = &nc;
559 0 : req.req8.replica_flags = replica_flags;
560 0 : req.req8.max_object_count = 402;
561 0 : req.req8.max_ndr_size = 402116;
562 0 : if (single) {
563 0 : req.req8.extended_op = DRSUAPI_EXOP_REPL_OBJ;
564 : }
565 : } else {
566 0 : level = 5;
567 0 : req.req5.naming_context = &nc;
568 0 : req.req5.replica_flags = replica_flags;
569 0 : req.req5.max_object_count = 402;
570 0 : req.req5.max_ndr_size = 402116;
571 0 : if (single) {
572 0 : req.req5.extended_op = DRSUAPI_EXOP_REPL_OBJ;
573 : }
574 : }
575 :
576 0 : for (y=0; ;y++) {
577 :
578 0 : if (level == 8) {
579 0 : DEBUG(1,("start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",y,
580 : (long long)req.req8.highwatermark.tmp_highest_usn,
581 : (long long)req.req8.highwatermark.highest_usn));
582 : }
583 :
584 0 : status = dcerpc_drsuapi_DsGetNCChanges(b, mem_ctx,
585 : &bind_handle,
586 : level,
587 : &req,
588 : &level_out,
589 : &ctr,
590 : &werr);
591 0 : if (!NT_STATUS_IS_OK(status)) {
592 0 : werr = ntstatus_to_werror(status);
593 0 : printf("Failed to get NC Changes: %s",
594 : get_friendly_nt_error_msg(status));
595 0 : goto out;
596 : }
597 :
598 0 : if (!W_ERROR_IS_OK(werr)) {
599 0 : printf("Failed to get NC Changes: %s",
600 : get_friendly_werror_msg(werr));
601 0 : goto out;
602 : }
603 :
604 0 : if (level_out == 1) {
605 0 : out_level = 1;
606 0 : ctr1 = &ctr.ctr1;
607 0 : } else if (level_out == 2 && ctr.ctr2.mszip1.ts) {
608 0 : out_level = 1;
609 0 : ctr1 = &ctr.ctr2.mszip1.ts->ctr1;
610 : }
611 :
612 0 : status = cli_get_session_key(mem_ctx, cli, &session_key);
613 0 : if (!NT_STATUS_IS_OK(status)) {
614 0 : printf("Failed to get Session Key: %s",
615 : nt_errstr(status));
616 0 : return ntstatus_to_werror(status);
617 : }
618 :
619 0 : if (out_level == 1) {
620 0 : DEBUG(1,("end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",y,
621 : (long long)ctr1->new_highwatermark.tmp_highest_usn,
622 : (long long)ctr1->new_highwatermark.highest_usn));
623 : #if 0
624 : libnet_dssync_decrypt_attributes(mem_ctx,
625 : &session_key,
626 : ctr1->first_object);
627 : #endif
628 0 : if (ctr1->more_data) {
629 0 : req.req5.highwatermark = ctr1->new_highwatermark;
630 0 : continue;
631 : }
632 : }
633 :
634 0 : if (level_out == 6) {
635 0 : out_level = 6;
636 0 : ctr6 = &ctr.ctr6;
637 0 : } else if (level_out == 7
638 0 : && ctr.ctr7.level == 6
639 0 : && ctr.ctr7.type == DRSUAPI_COMPRESSION_TYPE_MSZIP
640 0 : && ctr.ctr7.ctr.mszip6.ts) {
641 0 : out_level = 6;
642 0 : ctr6 = &ctr.ctr7.ctr.mszip6.ts->ctr6;
643 0 : } else if (level_out == 7
644 0 : && ctr.ctr7.level == 6
645 0 : && ctr.ctr7.type == DRSUAPI_COMPRESSION_TYPE_WIN2K3_LZ77_DIRECT2
646 0 : && ctr.ctr7.ctr.xpress6.ts) {
647 0 : out_level = 6;
648 0 : ctr6 = &ctr.ctr7.ctr.xpress6.ts->ctr6;
649 : }
650 :
651 0 : if (out_level == 6) {
652 0 : DEBUG(1,("end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",y,
653 : (long long)ctr6->new_highwatermark.tmp_highest_usn,
654 : (long long)ctr6->new_highwatermark.highest_usn));
655 : #if 0
656 : libnet_dssync_decrypt_attributes(mem_ctx,
657 : &session_key,
658 : ctr6->first_object);
659 : #endif
660 0 : if (ctr6->more_data) {
661 0 : req.req8.highwatermark = ctr6->new_highwatermark;
662 0 : continue;
663 : }
664 : }
665 :
666 0 : break;
667 : }
668 :
669 0 : out:
670 0 : return werr;
671 : }
672 :
673 : /* List of commands exported by this module */
674 :
675 : struct cmd_set drsuapi_commands[] = {
676 :
677 : {
678 : .name = "DRSUAPI",
679 : },
680 : {
681 : .name = "dscracknames",
682 : .returntype = RPC_RTYPE_WERROR,
683 : .ntfn = NULL,
684 : .wfn = cmd_drsuapi_cracknames,
685 : .table = &ndr_table_drsuapi,
686 : .rpc_pipe = NULL,
687 : .description = "Crack Name",
688 : .usage = "",
689 : },
690 : {
691 : .name = "dsgetdcinfo",
692 : .returntype = RPC_RTYPE_WERROR,
693 : .ntfn = NULL,
694 : .wfn = cmd_drsuapi_getdcinfo,
695 : .table = &ndr_table_drsuapi,
696 : .rpc_pipe = NULL,
697 : .description = "Get Domain Controller Info",
698 : .usage = "",
699 : },
700 : {
701 : .name = "dsgetncchanges",
702 : .returntype = RPC_RTYPE_WERROR,
703 : .ntfn = NULL,
704 : .wfn = cmd_drsuapi_getncchanges,
705 : .table = &ndr_table_drsuapi,
706 : .rpc_pipe = NULL,
707 : .description = "Get NC Changes",
708 : .usage = "",
709 : },
710 : {
711 : .name = "dswriteaccountspn",
712 : .returntype = RPC_RTYPE_WERROR,
713 : .ntfn = NULL,
714 : .wfn = cmd_drsuapi_writeaccountspn,
715 : .table = &ndr_table_drsuapi,
716 : .rpc_pipe = NULL,
717 : .description = "Write Account SPN",
718 : .usage = "",
719 : },
720 : {
721 : .name = NULL,
722 : },
723 : };
|