2 ldb database library - command line handling for ldb tools
4 Copyright (C) Andrew Tridgell 2005
6 ** NOTE! The following LGPL license applies to the ldb
7 ** library. This does NOT imply that all of Samba is released
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "ldb/include/includes.h"
27 #include "ldb/tools/cmdline.h"
29 #if (_SAMBA_BUILD_ >= 4)
30 #include "lib/cmdline/popt_common.h"
31 #include "lib/ldb/samba/ldif_handlers.h"
32 #include "auth/gensec/gensec.h"
33 #include "auth/auth.h"
40 process command line options
42 struct ldb_cmdline
*ldb_cmdline_process(struct ldb_context
*ldb
, int argc
, const char **argv
,
45 static struct ldb_cmdline options
; /* needs to be static for older compilers */
46 struct ldb_cmdline
*ret
=NULL
;
48 #if (_SAMBA_BUILD_ >= 4)
55 struct poptOption popt_options
[] = {
57 { "url", 'H', POPT_ARG_STRING
, &options
.url
, 0, "database URL", "URL" },
58 { "basedn", 'b', POPT_ARG_STRING
, &options
.basedn
, 0, "base DN", "DN" },
59 { "editor", 'e', POPT_ARG_STRING
, &options
.editor
, 0, "external editor", "PROGRAM" },
60 { "scope", 's', POPT_ARG_STRING
, NULL
, 's', "search scope", "SCOPE" },
61 { "verbose", 'v', POPT_ARG_NONE
, NULL
, 'v', "increase verbosity", NULL
},
62 { "interactive", 'i', POPT_ARG_NONE
, &options
.interactive
, 0, "input from stdin", NULL
},
63 { "recursive", 'r', POPT_ARG_NONE
, &options
.recursive
, 0, "recursive delete", NULL
},
64 { "num-searches", 0, POPT_ARG_INT
, &options
.num_searches
, 0, "number of test searches", NULL
},
65 { "num-records", 0, POPT_ARG_INT
, &options
.num_records
, 0, "number of test records", NULL
},
66 { "all", 'a', POPT_ARG_NONE
, &options
.all_records
, 0, "(|(objectClass=*)(distinguishedName=*))", NULL
},
67 { "nosync", 0, POPT_ARG_NONE
, &options
.nosync
, 0, "non-synchronous transactions", NULL
},
68 { "sorted", 'S', POPT_ARG_NONE
, &options
.sorted
, 0, "sort attributes", NULL
},
69 { "sasl-mechanism", 0, POPT_ARG_STRING
, &options
.sasl_mechanism
, 0, "choose SASL mechanism", "MECHANISM" },
70 { "input", 'I', POPT_ARG_STRING
, &options
.input
, 0, "Input File", "Input" },
71 { "output", 'O', POPT_ARG_STRING
, &options
.output
, 0, "Output File", "Output" },
72 { NULL
, 'o', POPT_ARG_STRING
, NULL
, 'o', "ldb_connect option", "OPTION" },
73 { "controls", 0, POPT_ARG_STRING
, NULL
, 'c', "controls", NULL
},
74 #if (_SAMBA_BUILD_ >= 4)
76 POPT_COMMON_CREDENTIALS
84 #if (_SAMBA_BUILD_ >= 4)
85 r
= ldb_register_samba_handlers(ldb
);
92 ret
= talloc_zero(ldb
, struct ldb_cmdline
);
101 options
.url
= getenv("LDB_URL");
103 /* and editor (used by ldbedit) */
104 options
.editor
= getenv("VISUAL");
105 if (!options
.editor
) {
106 options
.editor
= getenv("EDITOR");
108 if (!options
.editor
) {
109 options
.editor
= "vi";
112 options
.scope
= LDB_SCOPE_DEFAULT
;
114 pc
= poptGetContext(argv
[0], argc
, argv
, popt_options
,
115 POPT_CONTEXT_KEEP_FIRST
);
117 while((opt
= poptGetNextOpt(pc
)) != -1) {
120 const char *arg
= poptGetOptArg(pc
);
121 if (strcmp(arg
, "base") == 0) {
122 options
.scope
= LDB_SCOPE_BASE
;
123 } else if (strcmp(arg
, "sub") == 0) {
124 options
.scope
= LDB_SCOPE_SUBTREE
;
125 } else if (strcmp(arg
, "one") == 0) {
126 options
.scope
= LDB_SCOPE_ONELEVEL
;
128 fprintf(stderr
, "Invalid scope '%s'\n", arg
);
139 options
.options
= talloc_realloc(ret
, options
.options
,
140 const char *, num_options
+3);
141 if (options
.options
== NULL
) {
145 options
.options
[num_options
] = poptGetOptArg(pc
);
146 options
.options
[num_options
+1] = NULL
;
151 const char *cs
= poptGetOptArg(pc
);
155 for (p
= cs
, cc
= 1; (q
= strchr(p
, ',')); cc
++, p
= q
+ 1) ;
157 options
.controls
= talloc_array(ret
, char *, cc
+ 1);
158 if (options
.controls
== NULL
) {
162 for (p
= cs
, cc
= 0; p
!= NULL
; cc
++) {
167 options
.controls
[cc
] = talloc_strdup(options
.controls
, p
);
170 options
.controls
[cc
] = talloc_strndup(options
.controls
, p
, t
-p
);
174 options
.controls
[cc
] = NULL
;
179 fprintf(stderr
, "Invalid option %s: %s\n",
180 poptBadOption(pc
, 0), poptStrerror(opt
));
186 /* setup the remaining options for the main program to use */
187 options
.argv
= poptGetArgs(pc
);
190 while (options
.argv
[options
.argc
]) options
.argc
++;
195 /* all utils need some option */
196 if (ret
->url
== NULL
) {
197 fprintf(stderr
, "You must supply a url with -H or with $LDB_URL\n");
202 if (strcmp(ret
->url
, "NONE") == 0) {
206 if (options
.nosync
) {
207 flags
|= LDB_FLG_NOSYNC
;
210 #if (_SAMBA_BUILD_ >= 4)
211 /* Must be after we have processed command line options */
214 if (ldb_set_opaque(ldb
, "sessionInfo", system_session(ldb
))) {
217 if (ldb_set_opaque(ldb
, "credentials", cmdline_credentials
)) {
220 ldb_set_utf8_fns(ldb
, NULL
, wrap_casefold
);
223 /* now connect to the ldb */
224 if (ldb_connect(ldb
, ret
->url
, flags
, ret
->options
) != 0) {
225 fprintf(stderr
, "Failed to connect to %s - %s\n",
226 ret
->url
, ldb_errstring(ldb
));
238 struct ldb_control
**parse_controls(void *mem_ctx
, char **control_strings
)
241 struct ldb_control
**ctrl
;
243 if (control_strings
== NULL
|| control_strings
[0] == NULL
)
246 for (i
= 0; control_strings
[i
]; i
++);
248 ctrl
= talloc_array(mem_ctx
, struct ldb_control
*, i
+ 1);
250 for (i
= 0; control_strings
[i
]; i
++) {
251 if (strncmp(control_strings
[i
], "vlv:", 4) == 0) {
252 struct ldb_vlv_req_control
*control
;
256 int crit
, bc
, ac
, os
, cc
, ret
;
260 p
= &(control_strings
[i
][4]);
261 ret
= sscanf(p
, "%d:%d:%d:%d:%d:%1023[^$]", &crit
, &bc
, &ac
, &os
, &cc
, ctxid
);
263 ret
= sscanf(p
, "%d:%d:%d:%1023[^:]:%1023[^$]", &crit
, &bc
, &ac
, attr
, ctxid
);
266 if ((ret
< 4) || (crit
< 0) || (crit
> 1)) {
267 fprintf(stderr
, "invalid server_sort control syntax\n");
268 fprintf(stderr
, " syntax: crit(b):bc(n):ac(n):<os(n):cc(n)|attr(s)>[:ctxid(o)]\n");
269 fprintf(stderr
, " note: b = boolean, n = number, s = string, o = b64 binary blob\n");
272 ctrl
[i
] = talloc(ctrl
, struct ldb_control
);
273 ctrl
[i
]->oid
= LDB_CONTROL_VLV_REQ_OID
;
274 ctrl
[i
]->critical
= crit
;
275 control
= talloc(ctrl
[i
], struct ldb_vlv_req_control
);
276 control
->beforeCount
= bc
;
277 control
->afterCount
= ac
;
280 control
->match
.gtOrEq
.value
= talloc_strdup(control
, attr
);
281 control
->match
.gtOrEq
.value_len
= strlen(attr
);
284 control
->match
.byOffset
.offset
= os
;
285 control
->match
.byOffset
.contentCount
= cc
;
288 control
->ctxid_len
= ldb_base64_decode(ctxid
);
289 control
->contextId
= (char *)talloc_memdup(control
, ctxid
, control
->ctxid_len
);
291 control
->ctxid_len
= 0;
292 control
->contextId
= NULL
;
294 ctrl
[i
]->data
= control
;
299 if (strncmp(control_strings
[i
], "dirsync:", 8) == 0) {
300 struct ldb_dirsync_control
*control
;
303 int crit
, flags
, max_attrs
, ret
;
306 p
= &(control_strings
[i
][8]);
307 ret
= sscanf(p
, "%d:%d:%d:%1023[^$]", &crit
, &flags
, &max_attrs
, cookie
);
309 if ((ret
< 3) || (crit
< 0) || (crit
> 1) || (flags
< 0) || (max_attrs
< 0)) {
310 fprintf(stderr
, "invalid dirsync control syntax\n");
311 fprintf(stderr
, " syntax: crit(b):flags(n):max_attrs(n)[:cookie(o)]\n");
312 fprintf(stderr
, " note: b = boolean, n = number, o = b64 binary blob\n");
316 /* w2k3 seems to ignore the parameter,
317 * but w2k sends a wrong cookie when this value is to small
318 * this would cause looping forever, while getting
319 * the same data and same cookie forever
321 if (max_attrs
== 0) max_attrs
= 0x0FFFFFFF;
323 ctrl
[i
] = talloc(ctrl
, struct ldb_control
);
324 ctrl
[i
]->oid
= LDB_CONTROL_DIRSYNC_OID
;
325 ctrl
[i
]->critical
= crit
;
326 control
= talloc(ctrl
[i
], struct ldb_dirsync_control
);
327 control
->flags
= flags
;
328 control
->max_attributes
= max_attrs
;
330 control
->cookie_len
= ldb_base64_decode(cookie
);
331 control
->cookie
= (char *)talloc_memdup(control
, cookie
, control
->cookie_len
);
333 control
->cookie
= NULL
;
334 control
->cookie_len
= 0;
336 ctrl
[i
]->data
= control
;
341 if (strncmp(control_strings
[i
], "asq:", 4) == 0) {
342 struct ldb_asq_control
*control
;
348 p
= &(control_strings
[i
][4]);
349 ret
= sscanf(p
, "%d:%255[^$]", &crit
, attr
);
350 if ((ret
!= 2) || (crit
< 0) || (crit
> 1) || (attr
[0] == '\0')) {
351 fprintf(stderr
, "invalid asq control syntax\n");
352 fprintf(stderr
, " syntax: crit(b):attr(s)\n");
353 fprintf(stderr
, " note: b = boolean, s = string\n");
357 ctrl
[i
] = talloc(ctrl
, struct ldb_control
);
358 ctrl
[i
]->oid
= LDB_CONTROL_ASQ_OID
;
359 ctrl
[i
]->critical
= crit
;
360 control
= talloc(ctrl
[i
], struct ldb_asq_control
);
361 control
->request
= 1;
362 control
->source_attribute
= talloc_strdup(control
, attr
);
363 control
->src_attr_len
= strlen(attr
);
364 ctrl
[i
]->data
= control
;
369 if (strncmp(control_strings
[i
], "extended_dn:", 12) == 0) {
370 struct ldb_extended_dn_control
*control
;
374 p
= &(control_strings
[i
][12]);
375 ret
= sscanf(p
, "%d:%d", &crit
, &type
);
376 if ((ret
!= 2) || (crit
< 0) || (crit
> 1) || (type
< 0) || (type
> 1)) {
377 fprintf(stderr
, "invalid extended_dn control syntax\n");
378 fprintf(stderr
, " syntax: crit(b):type(b)\n");
379 fprintf(stderr
, " note: b = boolean\n");
383 ctrl
[i
] = talloc(ctrl
, struct ldb_control
);
384 ctrl
[i
]->oid
= LDB_CONTROL_EXTENDED_DN_OID
;
385 ctrl
[i
]->critical
= crit
;
386 control
= talloc(ctrl
[i
], struct ldb_extended_dn_control
);
387 control
->type
= type
;
388 ctrl
[i
]->data
= control
;
393 if (strncmp(control_strings
[i
], "sd_flags:", 9) == 0) {
394 struct ldb_sd_flags_control
*control
;
397 unsigned secinfo_flags
;
399 p
= &(control_strings
[i
][9]);
400 ret
= sscanf(p
, "%d:%u", &crit
, &secinfo_flags
);
401 if ((ret
!= 2) || (crit
< 0) || (crit
> 1) || (secinfo_flags
< 0) || (secinfo_flags
> 0xF)) {
402 fprintf(stderr
, "invalid sd_flags control syntax\n");
403 fprintf(stderr
, " syntax: crit(b):secinfo_flags(n)\n");
404 fprintf(stderr
, " note: b = boolean, n = number\n");
408 ctrl
[i
] = talloc(ctrl
, struct ldb_control
);
409 ctrl
[i
]->oid
= LDB_CONTROL_SD_FLAGS_OID
;
410 ctrl
[i
]->critical
= crit
;
411 control
= talloc(ctrl
[i
], struct ldb_sd_flags_control
);
412 control
->secinfo_flags
= secinfo_flags
;
413 ctrl
[i
]->data
= control
;
418 if (strncmp(control_strings
[i
], "search_options:", 15) == 0) {
419 struct ldb_search_options_control
*control
;
422 unsigned search_options
;
424 p
= &(control_strings
[i
][15]);
425 ret
= sscanf(p
, "%d:%u", &crit
, &search_options
);
426 if ((ret
!= 2) || (crit
< 0) || (crit
> 1) || (search_options
< 0) || (search_options
> 0xF)) {
427 fprintf(stderr
, "invalid search_options control syntax\n");
428 fprintf(stderr
, " syntax: crit(b):search_options(n)\n");
429 fprintf(stderr
, " note: b = boolean, n = number\n");
433 ctrl
[i
] = talloc(ctrl
, struct ldb_control
);
434 ctrl
[i
]->oid
= LDB_CONTROL_SEARCH_OPTIONS_OID
;
435 ctrl
[i
]->critical
= crit
;
436 control
= talloc(ctrl
[i
], struct ldb_search_options_control
);
437 control
->search_options
= search_options
;
438 ctrl
[i
]->data
= control
;
443 if (strncmp(control_strings
[i
], "domain_scope:", 13) == 0) {
447 p
= &(control_strings
[i
][13]);
448 ret
= sscanf(p
, "%d", &crit
);
449 if ((ret
!= 1) || (crit
< 0) || (crit
> 1)) {
450 fprintf(stderr
, "invalid domain_scope control syntax\n");
451 fprintf(stderr
, " syntax: crit(b)\n");
452 fprintf(stderr
, " note: b = boolean\n");
456 ctrl
[i
] = talloc(ctrl
, struct ldb_control
);
457 ctrl
[i
]->oid
= LDB_CONTROL_DOMAIN_SCOPE_OID
;
458 ctrl
[i
]->critical
= crit
;
459 ctrl
[i
]->data
= NULL
;
464 if (strncmp(control_strings
[i
], "paged_results:", 14) == 0) {
465 struct ldb_paged_control
*control
;
469 p
= &(control_strings
[i
][14]);
470 ret
= sscanf(p
, "%d:%d", &crit
, &size
);
472 if ((ret
!= 2) || (crit
< 0) || (crit
> 1) || (size
< 0)) {
473 fprintf(stderr
, "invalid paged_results control syntax\n");
474 fprintf(stderr
, " syntax: crit(b):size(n)\n");
475 fprintf(stderr
, " note: b = boolean, n = number\n");
479 ctrl
[i
] = talloc(ctrl
, struct ldb_control
);
480 ctrl
[i
]->oid
= LDB_CONTROL_PAGED_RESULTS_OID
;
481 ctrl
[i
]->critical
= crit
;
482 control
= talloc(ctrl
[i
], struct ldb_paged_control
);
483 control
->size
= size
;
484 control
->cookie
= NULL
;
485 control
->cookie_len
= 0;
486 ctrl
[i
]->data
= control
;
491 if (strncmp(control_strings
[i
], "server_sort:", 12) == 0) {
492 struct ldb_server_sort_control
**control
;
500 p
= &(control_strings
[i
][12]);
501 ret
= sscanf(p
, "%d:%d:%255[^:]:%127[^:]", &crit
, &rev
, attr
, rule
);
502 if ((ret
< 3) || (crit
< 0) || (crit
> 1) || (rev
< 0 ) || (rev
> 1) ||attr
[0] == '\0') {
503 fprintf(stderr
, "invalid server_sort control syntax\n");
504 fprintf(stderr
, " syntax: crit(b):rev(b):attr(s)[:rule(s)]\n");
505 fprintf(stderr
, " note: b = boolean, s = string\n");
508 ctrl
[i
] = talloc(ctrl
, struct ldb_control
);
509 ctrl
[i
]->oid
= LDB_CONTROL_SERVER_SORT_OID
;
510 ctrl
[i
]->critical
= crit
;
511 control
= talloc_array(ctrl
[i
], struct ldb_server_sort_control
*, 2);
512 control
[0] = talloc(control
, struct ldb_server_sort_control
);
513 control
[0]->attributeName
= talloc_strdup(control
, attr
);
515 control
[0]->orderingRule
= talloc_strdup(control
, rule
);
517 control
[0]->orderingRule
= NULL
;
518 control
[0]->reverse
= rev
;
520 ctrl
[i
]->data
= control
;
525 if (strncmp(control_strings
[i
], "notification:", 13) == 0) {
529 p
= &(control_strings
[i
][13]);
530 ret
= sscanf(p
, "%d", &crit
);
531 if ((ret
!= 1) || (crit
< 0) || (crit
> 1)) {
532 fprintf(stderr
, "invalid notification control syntax\n");
533 fprintf(stderr
, " syntax: crit(b)\n");
534 fprintf(stderr
, " note: b = boolean\n");
538 ctrl
[i
] = talloc(ctrl
, struct ldb_control
);
539 ctrl
[i
]->oid
= LDB_CONTROL_NOTIFICATION_OID
;
540 ctrl
[i
]->critical
= crit
;
541 ctrl
[i
]->data
= NULL
;
546 if (strncmp(control_strings
[i
], "show_deleted:", 13) == 0) {
550 p
= &(control_strings
[i
][13]);
551 ret
= sscanf(p
, "%d", &crit
);
552 if ((ret
!= 1) || (crit
< 0) || (crit
> 1)) {
553 fprintf(stderr
, "invalid show_deleted control syntax\n");
554 fprintf(stderr
, " syntax: crit(b)\n");
555 fprintf(stderr
, " note: b = boolean\n");
559 ctrl
[i
] = talloc(ctrl
, struct ldb_control
);
560 ctrl
[i
]->oid
= LDB_CONTROL_SHOW_DELETED_OID
;
561 ctrl
[i
]->critical
= crit
;
562 ctrl
[i
]->data
= NULL
;
567 if (strncmp(control_strings
[i
], "permissive_modify:", 18) == 0) {
571 p
= &(control_strings
[i
][18]);
572 ret
= sscanf(p
, "%d", &crit
);
573 if ((ret
!= 1) || (crit
< 0) || (crit
> 1)) {
574 fprintf(stderr
, "invalid permissive_modify control syntax\n");
575 fprintf(stderr
, " syntax: crit(b)\n");
576 fprintf(stderr
, " note: b = boolean\n");
580 ctrl
[i
] = talloc(ctrl
, struct ldb_control
);
581 ctrl
[i
]->oid
= LDB_CONTROL_PERMISSIVE_MODIFY_OID
;
582 ctrl
[i
]->critical
= crit
;
583 ctrl
[i
]->data
= NULL
;
588 /* no controls matched, throw an error */
589 fprintf(stderr
, "Invalid control name: '%s'\n", control_strings
[i
]);
599 /* this function check controls reply and determines if more
600 * processing is needed setting up the request controls correctly
605 * 1 all ok, more processing required
607 int handle_controls_reply(struct ldb_control
**reply
, struct ldb_control
**request
)
612 if (reply
== NULL
|| request
== NULL
) return -1;
614 for (i
= 0; reply
[i
]; i
++) {
615 if (strcmp(LDB_CONTROL_VLV_RESP_OID
, reply
[i
]->oid
) == 0) {
616 struct ldb_vlv_resp_control
*rep_control
;
618 rep_control
= talloc_get_type(reply
[i
]->data
, struct ldb_vlv_resp_control
);
620 /* check we have a matching control in the request */
621 for (j
= 0; request
[j
]; j
++) {
622 if (strcmp(LDB_CONTROL_VLV_REQ_OID
, request
[j
]->oid
) == 0)
626 fprintf(stderr
, "Warning VLV reply received but no request have been made\n");
630 /* check the result */
631 if (rep_control
->vlv_result
!= 0) {
632 fprintf(stderr
, "Warning: VLV not performed with error: %d\n", rep_control
->vlv_result
);
634 fprintf(stderr
, "VLV Info: target position = %d, content count = %d\n", rep_control
->targetPosition
, rep_control
->contentCount
);
640 if (strcmp(LDB_CONTROL_ASQ_OID
, reply
[i
]->oid
) == 0) {
641 struct ldb_asq_control
*rep_control
;
643 rep_control
= talloc_get_type(reply
[i
]->data
, struct ldb_asq_control
);
645 /* check the result */
646 if (rep_control
->result
!= 0) {
647 fprintf(stderr
, "Warning: ASQ not performed with error: %d\n", rep_control
->result
);
653 if (strcmp(LDB_CONTROL_PAGED_RESULTS_OID
, reply
[i
]->oid
) == 0) {
654 struct ldb_paged_control
*rep_control
, *req_control
;
656 rep_control
= talloc_get_type(reply
[i
]->data
, struct ldb_paged_control
);
657 if (rep_control
->cookie_len
== 0) /* we are done */
660 /* more processing required */
661 /* let's fill in the request control with the new cookie */
663 for (j
= 0; request
[j
]; j
++) {
664 if (strcmp(LDB_CONTROL_PAGED_RESULTS_OID
, request
[j
]->oid
) == 0)
667 /* if there's a reply control we must find a request
668 * control matching it */
669 if (! request
[j
]) return -1;
671 req_control
= talloc_get_type(request
[j
]->data
, struct ldb_paged_control
);
673 if (req_control
->cookie
)
674 talloc_free(req_control
->cookie
);
675 req_control
->cookie
= (char *)talloc_memdup(
676 req_control
, rep_control
->cookie
,
677 rep_control
->cookie_len
);
678 req_control
->cookie_len
= rep_control
->cookie_len
;
685 if (strcmp(LDB_CONTROL_SORT_RESP_OID
, reply
[i
]->oid
) == 0) {
686 struct ldb_sort_resp_control
*rep_control
;
688 rep_control
= talloc_get_type(reply
[i
]->data
, struct ldb_sort_resp_control
);
690 /* check we have a matching control in the request */
691 for (j
= 0; request
[j
]; j
++) {
692 if (strcmp(LDB_CONTROL_SERVER_SORT_OID
, request
[j
]->oid
) == 0)
696 fprintf(stderr
, "Warning Server Sort reply received but no request found\n");
700 /* check the result */
701 if (rep_control
->result
!= 0) {
702 fprintf(stderr
, "Warning: Sorting not performed with error: %d\n", rep_control
->result
);
708 if (strcmp(LDB_CONTROL_DIRSYNC_OID
, reply
[i
]->oid
) == 0) {
709 struct ldb_dirsync_control
*rep_control
, *req_control
;
712 rep_control
= talloc_get_type(reply
[i
]->data
, struct ldb_dirsync_control
);
713 if (rep_control
->cookie_len
== 0) /* we are done */
716 /* more processing required */
717 /* let's fill in the request control with the new cookie */
719 for (j
= 0; request
[j
]; j
++) {
720 if (strcmp(LDB_CONTROL_DIRSYNC_OID
, request
[j
]->oid
) == 0)
723 /* if there's a reply control we must find a request
724 * control matching it */
725 if (! request
[j
]) return -1;
727 req_control
= talloc_get_type(request
[j
]->data
, struct ldb_dirsync_control
);
729 if (req_control
->cookie
)
730 talloc_free(req_control
->cookie
);
731 req_control
->cookie
= (char *)talloc_memdup(
732 req_control
, rep_control
->cookie
,
733 rep_control
->cookie_len
);
734 req_control
->cookie_len
= rep_control
->cookie_len
;
736 cookie
= ldb_base64_encode(req_control
, rep_control
->cookie
, rep_control
->cookie_len
);
737 printf("# DIRSYNC cookie returned was:\n# %s\n", cookie
);
742 /* no controls matched, throw a warning */
743 fprintf(stderr
, "Unknown reply control oid: %s\n", reply
[i
]->oid
);