1 /* ldapsearch -- a tool for searching LDAP directories */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2011 The OpenLDAP Foundation.
6 * Portions Copyright 1998-2003 Kurt D. Zeilenga.
7 * Portions Copyright 1998-2001 Net Boolean Incorporated.
8 * Portions Copyright 2001-2003 IBM Corporation.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted only as authorized by the OpenLDAP
15 * A copy of this license is available in the file LICENSE in the
16 * top-level directory of the distribution or, alternatively, at
17 * <http://www.OpenLDAP.org/license.html>.
19 /* Portions Copyright (c) 1992-1996 Regents of the University of Michigan.
20 * All rights reserved.
22 * Redistribution and use in source and binary forms are permitted
23 * provided that this notice is preserved and that due credit is given
24 * to the University of Michigan at Ann Arbor. The name of the
25 * University may not be used to endorse or promote products derived
26 * from this software without specific prior written permission. This
27 * software is provided ``as is'' without express or implied warranty.
30 * This work was originally developed by the University of Michigan
31 * (as part of U-MICH LDAP). Additional significant contributors
43 #include <ac/stdlib.h>
46 #include <ac/string.h>
47 #include <ac/unistd.h>
51 #include <ac/signal.h>
56 #ifdef HAVE_SYS_TYPES_H
57 #include <sys/types.h>
67 #include "lutil_ldap.h"
68 #include "ldap_defaults.h"
75 * NOTE: we use this deprecated function only because
76 * we want ldapsearch to provide some client-side sorting
80 typedef int (LDAP_SORT_AD_CMP_PROC) LDAP_P(( /* deprecated */
81 LDAP_CONST char *left,
82 LDAP_CONST char *right ));
84 LDAP_F( int ) /* deprecated */
85 ldap_sort_entries LDAP_P(( LDAP *ld,
87 LDAP_CONST char *attr,
88 LDAP_SORT_AD_CMP_PROC *cmp ));
91 static int scope = LDAP_SCOPE_SUBTREE;
92 static int deref = -1;
94 static int timelimit = -1;
95 static int sizelimit = -1;
99 static char *def_tmpdir;
100 static char *def_urlpre;
102 #if defined(__CYGWIN__) || defined(__MINGW32__)
103 /* Turn off commandline globbing, otherwise you cannot search for
112 fprintf( stderr, _("usage: %s [options] [filter [attributes...]]\nwhere:\n"), prog);
113 fprintf( stderr, _(" filter\tRFC 4515 compliant LDAP search filter\n"));
114 fprintf( stderr, _(" attributes\twhitespace-separated list of attribute descriptions\n"));
115 fprintf( stderr, _(" which may include:\n"));
116 fprintf( stderr, _(" 1.1 no attributes\n"));
117 fprintf( stderr, _(" * all user attributes\n"));
118 fprintf( stderr, _(" + all operational attributes\n"));
121 fprintf( stderr, _("Search options:\n"));
122 fprintf( stderr, _(" -a deref one of never (default), always, search, or find\n"));
123 fprintf( stderr, _(" -A retrieve attribute names only (no values)\n"));
124 fprintf( stderr, _(" -b basedn base dn for search\n"));
125 fprintf( stderr, _(" -c continuous operation mode (do not stop on errors)\n"));
126 fprintf( stderr, _(" -E [!]<ext>[=<extparam>] search extensions (! indicates criticality)\n"));
127 fprintf( stderr, _(" [!]domainScope (domain scope)\n"));
128 fprintf( stderr, _(" !dontUseCopy (Don't Use Copy)\n"));
129 fprintf( stderr, _(" [!]mv=<filter> (RFC 3876 matched values filter)\n"));
130 fprintf( stderr, _(" [!]pr=<size>[/prompt|noprompt] (RFC 2696 paged results/prompt)\n"));
131 fprintf( stderr, _(" [!]sss=[-]<attr[:OID]>[/[-]<attr[:OID]>...]\n"));
132 fprintf( stderr, _(" (RFC 2891 server side sorting)\n"));
133 fprintf( stderr, _(" [!]subentries[=true|false] (RFC 3672 subentries)\n"));
134 fprintf( stderr, _(" [!]sync=ro[/<cookie>] (RFC 4533 LDAP Sync refreshOnly)\n"));
135 fprintf( stderr, _(" rp[/<cookie>][/<slimit>] (refreshAndPersist)\n"));
136 fprintf( stderr, _(" [!]vlv=<before>/<after>(/<offset>/<count>|:<value>)\n"));
137 fprintf( stderr, _(" (ldapv3-vlv-09 virtual list views)\n"));
138 #ifdef LDAP_CONTROL_X_DEREF
139 fprintf( stderr, _(" [!]deref=derefAttr:attr[,...][;derefAttr:attr[,...][;...]]\n"));
141 fprintf( stderr, _(" [!]<oid>[=:<b64value>] (generic control; no response handling)\n"));
142 fprintf( stderr, _(" -f file read operations from `file'\n"));
143 fprintf( stderr, _(" -F prefix URL prefix for files (default: %s)\n"), def_urlpre);
144 fprintf( stderr, _(" -l limit time limit (in seconds, or \"none\" or \"max\") for search\n"));
145 fprintf( stderr, _(" -L print responses in LDIFv1 format\n"));
146 fprintf( stderr, _(" -LL print responses in LDIF format without comments\n"));
147 fprintf( stderr, _(" -LLL print responses in LDIF format without comments\n"));
148 fprintf( stderr, _(" and version\n"));
149 fprintf( stderr, _(" -M enable Manage DSA IT control (-MM to make critical)\n"));
150 fprintf( stderr, _(" -P version protocol version (default: 3)\n"));
151 fprintf( stderr, _(" -s scope one of base, one, sub or children (search scope)\n"));
152 fprintf( stderr, _(" -S attr sort the results by attribute `attr'\n"));
153 fprintf( stderr, _(" -t write binary values to files in temporary directory\n"));
154 fprintf( stderr, _(" -tt write all values to files in temporary directory\n"));
155 fprintf( stderr, _(" -T path write files to directory specified by path (default: %s)\n"), def_tmpdir);
156 fprintf( stderr, _(" -u include User Friendly entry names in the output\n"));
157 fprintf( stderr, _(" -z limit size limit (in entries, or \"none\" or \"max\") for search\n"));
159 exit( EXIT_FAILURE );
162 static void print_entry LDAP_P((
167 static void print_reference(
169 LDAPMessage *reference );
171 static void print_extended(
173 LDAPMessage *extended );
175 static void print_partial(
177 LDAPMessage *partial );
179 static int print_result(
184 static int dosearch LDAP_P((
192 LDAPControl **sctrls,
193 LDAPControl **cctrls,
194 struct timeval *timeout,
197 static char *tmpdir = NULL;
198 static char *urlpre = NULL;
199 static char *base = NULL;
200 static char *sortattr = NULL;
201 static int includeufn, vals2tmp = 0;
203 static int subentries = 0, valuesReturnFilter = 0;
204 static char *vrFilter = NULL;
206 #ifdef LDAP_CONTROL_DONTUSECOPY
207 static int dontUseCopy = 0;
210 static int domainScope = 0;
213 static LDAPSortKey **sss_keys = NULL;
216 static LDAPVLVInfo vlvInfo;
217 static struct berval vlvValue;
219 static int ldapsync = 0;
220 static struct berval sync_cookie = { 0, NULL };
221 static int sync_slimit = -1;
223 /* cookie and morePagedResults moved to common.c */
224 static int pagedResults = 0;
225 static int pagePrompt = 1;
226 static ber_int_t pageSize = 0;
227 static ber_int_t entriesLeft = 0;
228 static int npagedresponses;
229 static int npagedentries;
230 static int npagedreferences;
231 static int npagedextended;
232 static int npagedpartial;
234 static LDAPControl *c = NULL;
235 static int nctrls = 0;
236 static int save_nctrls = 0;
238 #ifdef LDAP_CONTROL_X_DEREF
239 static int derefcrit;
240 static LDAPDerefSpec *ds;
241 static struct berval derefval;
250 tmpc = realloc( c, sizeof( LDAPControl ) * nctrls );
251 if ( tmpc == NULL ) {
254 _("unable to make room for control; out of memory?\n"));
267 if (*LDAP_DIRSEP != '/') {
268 for (p = url; *p; p++) {
269 if (*p == *LDAP_DIRSEP)
276 parse_vlv(char *cvalue)
282 if ( sscanf( keyp, "%d/%d", &num1, &num2 ) != 2 ) {
284 _("VLV control value \"%s\" invalid\n"),
288 vlvInfo.ldvlv_before_count = num1;
289 vlvInfo.ldvlv_after_count = num2;
290 keyp = strchr( keyp, '/' ) + 1;
291 key2 = strchr( keyp, '/' );
294 if ( sscanf( keyp, "%d/%d", &num1, &num2 ) != 2 ) {
296 _("VLV control value \"%s\" invalid\n"),
300 vlvInfo.ldvlv_offset = num1;
301 vlvInfo.ldvlv_count = num2;
302 vlvInfo.ldvlv_attrvalue = NULL;
304 key2 = strchr( keyp, ':' );
307 _("VLV control value \"%s\" invalid\n"),
311 ber_str2bv( key2+1, 0, 0, &vlvValue );
312 vlvInfo.ldvlv_attrvalue = &vlvValue;
317 const char options[] = "a:Ab:cE:F:l:Ls:S:tT:uz:"
318 "Cd:D:e:f:h:H:IMnNO:o:p:P:QR:U:vVw:WxX:y:Y:Z";
321 handle_private_option( int i )
326 case 'a': /* set alias deref option */
327 if ( strcasecmp( optarg, "never" ) == 0 ) {
328 deref = LDAP_DEREF_NEVER;
329 } else if ( strncasecmp( optarg, "search", sizeof("search")-1 ) == 0 ) {
330 deref = LDAP_DEREF_SEARCHING;
331 } else if ( strncasecmp( optarg, "find", sizeof("find")-1 ) == 0 ) {
332 deref = LDAP_DEREF_FINDING;
333 } else if ( strcasecmp( optarg, "always" ) == 0 ) {
334 deref = LDAP_DEREF_ALWAYS;
337 _("alias deref should be never, search, find, or always\n") );
341 case 'A': /* retrieve attribute names only -- no values */
344 case 'b': /* search base */
345 base = ber_strdup( optarg );
347 case 'E': /* search extensions */
348 if( protocol == LDAP_VERSION2 ) {
349 fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"),
351 exit( EXIT_FAILURE );
354 /* should be extended to support comma separated list of
355 * [!]key[=value] parameters, e.g. -E !foo,bar=567
360 while ( optarg[0] == '!' ) {
365 control = ber_strdup( optarg );
366 if ( (cvalue = strchr( control, '=' )) != NULL ) {
370 if ( strcasecmp( control, "mv" ) == 0 ) {
371 /* ValuesReturnFilter control */
372 if( valuesReturnFilter ) {
374 _("ValuesReturnFilter previously specified\n"));
375 exit( EXIT_FAILURE );
377 valuesReturnFilter= 1 + crit;
379 if ( cvalue == NULL ) {
381 _("missing filter in ValuesReturnFilter control\n"));
382 exit( EXIT_FAILURE );
386 protocol = LDAP_VERSION3;
388 } else if ( strcasecmp( control, "pr" ) == 0 ) {
390 /* PagedResults control */
391 if ( pagedResults != 0 ) {
393 _("PagedResultsControl previously specified\n") );
394 exit( EXIT_FAILURE );
398 _("PagedResultsControl incompatible with VLV\n") );
399 exit( EXIT_FAILURE );
402 if( cvalue != NULL ) {
405 promptp = strchr( cvalue, '/' );
406 if ( promptp != NULL ) {
408 if ( strcasecmp( promptp, "prompt" ) == 0 ) {
410 } else if ( strcasecmp( promptp, "noprompt" ) == 0) {
414 _("Invalid value for PagedResultsControl,"
415 " %s/%s.\n"), cvalue, promptp );
416 exit( EXIT_FAILURE );
419 num = sscanf( cvalue, "%d", &tmp );
422 _("Invalid value for PagedResultsControl, %s.\n"),
424 exit( EXIT_FAILURE );
427 fprintf(stderr, _("Invalid value for PagedResultsControl.\n"));
428 exit( EXIT_FAILURE );
430 pageSize = (ber_int_t) tmp;
431 pagedResults = 1 + crit;
433 #ifdef LDAP_CONTROL_DONTUSECOPY
434 } else if ( strcasecmp( control, "dontUseCopy" ) == 0 ) {
437 _("dontUseCopy control previously specified\n"));
438 exit( EXIT_FAILURE );
440 if( cvalue != NULL ) {
442 _("dontUseCopy: no control value expected\n") );
447 _("dontUseCopy: critical flag required\n") );
451 dontUseCopy = 1 + crit;
453 } else if ( strcasecmp( control, "domainScope" ) == 0 ) {
456 _("domainScope control previously specified\n"));
457 exit( EXIT_FAILURE );
459 if( cvalue != NULL ) {
461 _("domainScope: no control value expected\n") );
465 domainScope = 1 + crit;
467 } else if ( strcasecmp( control, "sss" ) == 0 ) {
471 _("server side sorting control previously specified\n"));
472 exit( EXIT_FAILURE );
474 if( cvalue == NULL ) {
476 _("missing specification of sss control\n") );
477 exit( EXIT_FAILURE );
480 while ( ( keyp = strchr(keyp, '/') ) != NULL ) {
483 if ( ldap_create_sort_keylist( &sss_keys, cvalue )) {
485 _("server side sorting control value \"%s\" invalid\n"),
487 exit( EXIT_FAILURE );
492 } else if ( strcasecmp( control, "subentries" ) == 0 ) {
495 _("subentries control previously specified\n"));
496 exit( EXIT_FAILURE );
498 if( cvalue == NULL || strcasecmp( cvalue, "true") == 0 ) {
500 } else if ( strcasecmp( cvalue, "false") == 0 ) {
504 _("subentries control value \"%s\" invalid\n"),
506 exit( EXIT_FAILURE );
508 if( crit ) subentries *= -1;
510 } else if ( strcasecmp( control, "sync" ) == 0 ) {
514 fprintf( stderr, _("sync control previously specified\n") );
515 exit( EXIT_FAILURE );
517 if ( cvalue == NULL ) {
518 fprintf( stderr, _("missing specification of sync control\n"));
519 exit( EXIT_FAILURE );
521 if ( strncasecmp( cvalue, "ro", 2 ) == 0 ) {
522 ldapsync = LDAP_SYNC_REFRESH_ONLY;
523 cookiep = strchr( cvalue, '/' );
524 if ( cookiep != NULL ) {
526 if ( *cookiep != '\0' ) {
527 ber_str2bv( cookiep, 0, 0, &sync_cookie );
530 } else if ( strncasecmp( cvalue, "rp", 2 ) == 0 ) {
531 ldapsync = LDAP_SYNC_REFRESH_AND_PERSIST;
532 cookiep = strchr( cvalue, '/' );
533 if ( cookiep != NULL ) {
537 slimitp = strchr( cvalue, '/' );
538 if ( slimitp != NULL ) {
541 if ( cookiep != NULL && *cookiep != '\0' )
542 ber_str2bv( cookiep, 0, 0, &sync_cookie );
543 if ( slimitp != NULL && *slimitp != '\0' ) {
544 ival = strtol( slimitp, &next, 10 );
545 if ( next == NULL || next[0] != '\0' ) {
546 fprintf( stderr, _("Unable to parse sync control value \"%s\"\n"), slimitp );
547 exit( EXIT_FAILURE );
552 fprintf( stderr, _("sync control value \"%s\" invalid\n"),
554 exit( EXIT_FAILURE );
556 if ( crit ) ldapsync *= -1;
558 } else if ( strcasecmp( control, "vlv" ) == 0 ) {
561 _("virtual list view control previously specified\n"));
562 exit( EXIT_FAILURE );
564 if ( pagedResults != 0 ) {
566 _("PagedResultsControl incompatible with VLV\n") );
567 exit( EXIT_FAILURE );
569 if( cvalue == NULL ) {
571 _("missing specification of vlv control\n") );
572 exit( EXIT_FAILURE );
574 if ( parse_vlv( cvalue ))
575 exit( EXIT_FAILURE );
579 #ifdef LDAP_CONTROL_X_DEREF
580 } else if ( strcasecmp( control, "deref" ) == 0 ) {
584 /* cvalue is something like
586 * derefAttr:attr[,attr[...]][;derefAttr:attr[,attr[...]]]"
589 specs = ldap_str2charray( cvalue, ";" );
590 if ( specs == NULL ) {
591 fprintf( stderr, _("deref specs \"%s\" invalid\n"),
593 exit( EXIT_FAILURE );
595 for ( ispecs = 0; specs[ ispecs ] != NULL; ispecs++ )
598 ds = ldap_memcalloc( ispecs + 1, sizeof( LDAPDerefSpec ) );
601 exit( EXIT_FAILURE );
604 for ( ispecs = 0; specs[ ispecs ] != NULL; ispecs++ ) {
607 ptr = strchr( specs[ ispecs ], ':' );
609 fprintf( stderr, _("deref specs \"%s\" invalid\n"),
611 exit( EXIT_FAILURE );
614 ds[ ispecs ].derefAttr = specs[ ispecs ];
616 ds[ ispecs ].attributes = ldap_str2charray( ptr, "," );
619 derefcrit = 1 + crit;
621 ldap_memfree( specs );
622 #endif /* LDAP_CONTROL_X_DEREF */
624 } else if ( tool_is_oid( control ) ) {
627 for ( i = 0; i < nctrls; i++ ) {
628 if ( strcmp( control, c[ i ].ldctl_oid ) == 0 ) {
629 fprintf( stderr, "%s control previously specified\n", control );
630 exit( EXIT_FAILURE );
636 exit( EXIT_FAILURE );
640 c[ nctrls - 1 ].ldctl_oid = control;
643 if ( cvalue == NULL ) {
644 c[ nctrls - 1 ].ldctl_value.bv_val = NULL;
645 c[ nctrls - 1 ].ldctl_value.bv_len = 0;
647 } else if ( cvalue[ 0 ] == ':' ) {
656 * to use ldif_parse_line2() */
657 save_c = cvalue[ -2 ];
659 ldif_parse_line2( &cvalue[ -2 ], &type,
661 cvalue[ -2 ] = save_c;
664 c[ nctrls - 1 ].ldctl_value = value;
667 ber_dupbv( &c[ nctrls - 1 ].ldctl_value, &value );
671 fprintf( stderr, "unable to parse %s control value\n", control );
672 exit( EXIT_FAILURE );
677 c[ nctrls - 1 ].ldctl_iscritical = crit;
680 fprintf( stderr, _("Invalid search extension name: %s\n"),
685 case 'F': /* uri prefix */
686 if( urlpre ) free( urlpre );
687 urlpre = strdup( optarg );
689 case 'l': /* time limit */
690 if ( strcasecmp( optarg, "none" ) == 0 ) {
693 } else if ( strcasecmp( optarg, "max" ) == 0 ) {
694 timelimit = LDAP_MAXINT;
697 ival = strtol( optarg, &next, 10 );
698 if ( next == NULL || next[0] != '\0' ) {
700 _("Unable to parse time limit \"%s\"\n"), optarg );
701 exit( EXIT_FAILURE );
705 if( timelimit < 0 || timelimit > LDAP_MAXINT ) {
706 fprintf( stderr, _("%s: invalid timelimit (%d) specified\n"),
708 exit( EXIT_FAILURE );
711 case 'L': /* print entries in LDIF format */
714 case 's': /* search scope */
715 if ( strncasecmp( optarg, "base", sizeof("base")-1 ) == 0 ) {
716 scope = LDAP_SCOPE_BASE;
717 } else if ( strncasecmp( optarg, "one", sizeof("one")-1 ) == 0 ) {
718 scope = LDAP_SCOPE_ONELEVEL;
719 } else if (( strcasecmp( optarg, "subordinate" ) == 0 )
720 || ( strcasecmp( optarg, "children" ) == 0 ))
722 scope = LDAP_SCOPE_SUBORDINATE;
723 } else if ( strncasecmp( optarg, "sub", sizeof("sub")-1 ) == 0 ) {
724 scope = LDAP_SCOPE_SUBTREE;
726 fprintf( stderr, _("scope should be base, one, or sub\n") );
730 case 'S': /* sort attribute */
731 sortattr = strdup( optarg );
733 case 't': /* write attribute values to TMPDIR files */
736 case 'T': /* tmpdir */
737 if( tmpdir ) free( tmpdir );
738 tmpdir = strdup( optarg );
740 case 'u': /* include UFN */
743 case 'z': /* size limit */
744 if ( strcasecmp( optarg, "none" ) == 0 ) {
747 } else if ( strcasecmp( optarg, "max" ) == 0 ) {
748 sizelimit = LDAP_MAXINT;
751 ival = strtol( optarg, &next, 10 );
752 if ( next == NULL || next[0] != '\0' ) {
754 _("Unable to parse size limit \"%s\"\n"), optarg );
755 exit( EXIT_FAILURE );
759 if( sizelimit < 0 || sizelimit > LDAP_MAXINT ) {
760 fprintf( stderr, _("%s: invalid sizelimit (%d) specified\n"),
762 exit( EXIT_FAILURE );
773 private_conn_setup( LDAP *ld )
776 ldap_set_option( ld, LDAP_OPT_DEREF, (void *) &deref )
777 != LDAP_OPT_SUCCESS )
779 fprintf( stderr, _("Could not set LDAP_OPT_DEREF %d\n"), deref );
780 exit( EXIT_FAILURE );
783 ldap_set_option( ld, LDAP_OPT_TIMELIMIT, (void *) &timelimit )
784 != LDAP_OPT_SUCCESS )
787 _("Could not set LDAP_OPT_TIMELIMIT %d\n"), timelimit );
788 exit( EXIT_FAILURE );
791 ldap_set_option( ld, LDAP_OPT_SIZELIMIT, (void *) &sizelimit )
792 != LDAP_OPT_SUCCESS )
795 _("Could not set LDAP_OPT_SIZELIMIT %d\n"), sizelimit );
796 exit( EXIT_FAILURE );
801 main( int argc, char **argv )
803 char *filtpattern, **attrs = NULL, line[BUFSIZ];
805 int rc, rc1, i, first;
807 BerElement *seber = NULL, *vrber = NULL;
809 BerElement *syncber = NULL;
810 struct berval *syncbvalp = NULL;
813 tool_init( TOOL_SEARCH );
815 npagedresponses = npagedentries = npagedreferences =
816 npagedextended = npagedpartial = 0;
818 prog = lutil_progname( "ldapsearch", argc, argv );
820 if((def_tmpdir = getenv("TMPDIR")) == NULL &&
821 (def_tmpdir = getenv("TMP")) == NULL &&
822 (def_tmpdir = getenv("TEMP")) == NULL )
824 def_tmpdir = LDAP_TMPDIR;
828 def_tmpdir = LDAP_TMPDIR;
830 def_urlpre = malloc( sizeof("file:////") + strlen(def_tmpdir) );
832 if( def_urlpre == NULL ) {
837 sprintf( def_urlpre, "file:///%s/",
838 def_tmpdir[0] == *LDAP_DIRSEP ? &def_tmpdir[1] : def_tmpdir );
840 urlize( def_urlpre );
842 tool_args( argc, argv );
846 _("VLV control requires server side sort control\n" ));
850 if (( argc - optind < 1 ) ||
851 ( *argv[optind] != '(' /*')'*/ &&
852 ( strchr( argv[optind], '=' ) == NULL ) ) )
854 filtpattern = "(objectclass=*)";
856 filtpattern = argv[optind++];
859 if ( argv[optind] != NULL ) {
860 attrs = &argv[optind];
863 if ( infile != NULL ) {
866 if ( infile[0] == '-' && infile[1] == '\0' ) {
868 } else if (( fp = fopen( infile, "r" )) == NULL ) {
873 for( i=0 ; filtpattern[i] ; i++ ) {
874 if( filtpattern[i] == '%' ) {
876 fprintf( stderr, _("Bad filter pattern \"%s\"\n"),
883 if( filtpattern[i+1] != 's' ) {
884 fprintf( stderr, _("Bad filter pattern \"%s\"\n"),
892 if ( tmpdir == NULL ) {
895 if ( urlpre == NULL )
899 if( urlpre == NULL ) {
900 urlpre = malloc( sizeof("file:////") + strlen(tmpdir) );
902 if( urlpre == NULL ) {
907 sprintf( urlpre, "file:///%s/",
908 tmpdir[0] == *LDAP_DIRSEP ? &tmpdir[1] : tmpdir );
916 ld = tool_conn_setup( 0, &private_conn_setup );
921 /* fp may have been closed, need to reopen if code jumps
922 * back here to getNextPage.
924 if ( !fp && infile ) {
925 if (( fp = fopen( infile, "r" )) == NULL ) {
930 save_nctrls = nctrls;
933 #ifdef LDAP_CONTROL_DONTUSECOPY
936 #ifdef LDAP_CONTROL_X_DEREF
944 || valuesReturnFilter
948 #ifdef LDAP_CONTROL_DONTUSECOPY
954 c[i].ldctl_oid = LDAP_CONTROL_DONTUSECOPY;
955 c[i].ldctl_value.bv_val = NULL;
956 c[i].ldctl_value.bv_len = 0;
957 c[i].ldctl_iscritical = dontUseCopy == 2;
967 c[i].ldctl_oid = LDAP_CONTROL_X_DOMAIN_SCOPE;
968 c[i].ldctl_value.bv_val = NULL;
969 c[i].ldctl_value.bv_len = 0;
970 c[i].ldctl_iscritical = domainScope > 1;
979 if (( seber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
983 err = ber_printf( seber, "b", abs(subentries) == 1 ? 0 : 1 );
985 ber_free( seber, 1 );
986 fprintf( stderr, _("Subentries control encoding error!\n") );
990 if ( ber_flatten2( seber, &c[i].ldctl_value, 0 ) == -1 ) {
994 c[i].ldctl_oid = LDAP_CONTROL_SUBENTRIES;
995 c[i].ldctl_iscritical = subentries < 1;
1001 return EXIT_FAILURE;
1004 if (( syncber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
1005 return EXIT_FAILURE;
1008 if ( sync_cookie.bv_len == 0 ) {
1009 err = ber_printf( syncber, "{e}", abs(ldapsync) );
1011 err = ber_printf( syncber, "{eO}", abs(ldapsync),
1016 ber_free( syncber, 1 );
1017 fprintf( stderr, _("ldap sync control encoding error!\n") );
1018 return EXIT_FAILURE;
1021 if ( ber_flatten( syncber, &syncbvalp ) == -1 ) {
1022 return EXIT_FAILURE;
1025 c[i].ldctl_oid = LDAP_CONTROL_SYNC;
1026 c[i].ldctl_value = (*syncbvalp);
1027 c[i].ldctl_iscritical = ldapsync < 0;
1031 if ( valuesReturnFilter ) {
1033 return EXIT_FAILURE;
1036 if (( vrber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
1037 return EXIT_FAILURE;
1040 if ( ( err = ldap_put_vrFilter( vrber, vrFilter ) ) == -1 ) {
1041 ber_free( vrber, 1 );
1042 fprintf( stderr, _("Bad ValuesReturnFilter: %s\n"), vrFilter );
1043 return EXIT_FAILURE;
1046 if ( ber_flatten2( vrber, &c[i].ldctl_value, 0 ) == -1 ) {
1047 return EXIT_FAILURE;
1050 c[i].ldctl_oid = LDAP_CONTROL_VALUESRETURNFILTER;
1051 c[i].ldctl_iscritical = valuesReturnFilter > 1;
1055 if ( pagedResults ) {
1057 return EXIT_FAILURE;
1060 if ( ldap_create_page_control_value( ld,
1061 pageSize, &pr_cookie, &c[i].ldctl_value ) )
1063 return EXIT_FAILURE;
1066 if ( pr_cookie.bv_val != NULL ) {
1067 ber_memfree( pr_cookie.bv_val );
1068 pr_cookie.bv_val = NULL;
1069 pr_cookie.bv_len = 0;
1072 c[i].ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
1073 c[i].ldctl_iscritical = pagedResults > 1;
1079 return EXIT_FAILURE;
1082 if ( ldap_create_sort_control_value( ld,
1083 sss_keys, &c[i].ldctl_value ) )
1085 return EXIT_FAILURE;
1088 c[i].ldctl_oid = LDAP_CONTROL_SORTREQUEST;
1089 c[i].ldctl_iscritical = sss > 1;
1095 return EXIT_FAILURE;
1098 if ( ldap_create_vlv_control_value( ld,
1099 &vlvInfo, &c[i].ldctl_value ) )
1101 return EXIT_FAILURE;
1104 c[i].ldctl_oid = LDAP_CONTROL_VLVREQUEST;
1105 c[i].ldctl_iscritical = sss > 1;
1108 #ifdef LDAP_CONTROL_X_DEREF
1110 if ( derefval.bv_val == NULL ) {
1113 assert( ds != NULL );
1115 if ( ldap_create_deref_control_value( ld, ds, &derefval ) != LDAP_SUCCESS ) {
1116 return EXIT_FAILURE;
1119 for ( i = 0; ds[ i ].derefAttr != NULL; i++ ) {
1120 ldap_memfree( ds[ i ].derefAttr );
1121 ldap_charray_free( ds[ i ].attributes );
1128 exit( EXIT_FAILURE );
1131 c[ i ].ldctl_iscritical = derefcrit > 1;
1132 c[ i ].ldctl_oid = LDAP_CONTROL_X_DEREF;
1133 c[ i ].ldctl_value = derefval;
1136 #endif /* LDAP_CONTROL_X_DEREF */
1139 tool_server_controls( ld, c, i );
1141 if ( seber ) ber_free( seber, 1 );
1142 if ( vrber ) ber_free( vrber, 1 );
1144 /* step back to the original number of controls, so that
1145 * those set while parsing args are preserved */
1146 nctrls = save_nctrls;
1149 fprintf( stderr, _("filter%s: %s\nrequesting: "),
1150 infile != NULL ? _(" pattern") : "",
1153 if ( attrs == NULL ) {
1154 fprintf( stderr, _("All userApplication attributes") );
1156 for ( i = 0; attrs[ i ] != NULL; ++i ) {
1157 fprintf( stderr, "%s ", attrs[ i ] );
1160 fprintf( stderr, "\n" );
1164 printf( _("# extended LDIF\n") );
1165 } else if ( ldif < 3 ) {
1166 printf( _("version: %d\n\n"), 1 );
1170 char *realbase = base;
1172 if ( realbase == NULL ) {
1173 ldap_get_option( ld, LDAP_OPT_DEFBASE, (void **)(char *)&realbase );
1177 printf(_("# LDAPv%d\n"), protocol);
1178 printf(_("# base <%s>%s with scope %s\n"),
1179 realbase ? realbase : "",
1180 ( realbase == NULL || realbase != base ) ? " (default)" : "",
1181 ((scope == LDAP_SCOPE_BASE) ? "baseObject"
1182 : ((scope == LDAP_SCOPE_ONELEVEL) ? "oneLevel"
1183 : ((scope == LDAP_SCOPE_SUBORDINATE) ? "children"
1185 printf(_("# filter%s: %s\n"), infile != NULL ? _(" pattern") : "",
1187 printf(_("# requesting: "));
1189 if ( attrs == NULL ) {
1192 for ( i = 0; attrs[ i ] != NULL; ++i ) {
1193 printf( "%s ", attrs[ i ] );
1197 if ( manageDSAit ) {
1198 printf(_("\n# with manageDSAit %scontrol"),
1199 manageDSAit > 1 ? _("critical ") : "" );
1202 printf(_("\n# with noop %scontrol"),
1203 noop > 1 ? _("critical ") : "" );
1206 printf(_("\n# with subentries %scontrol: %s"),
1207 subentries < 0 ? _("critical ") : "",
1208 abs(subentries) == 1 ? "false" : "true" );
1210 if ( valuesReturnFilter ) {
1211 printf(_("\n# with valuesReturnFilter %scontrol: %s"),
1212 valuesReturnFilter > 1 ? _("critical ") : "", vrFilter );
1214 if ( pagedResults ) {
1215 printf(_("\n# with pagedResults %scontrol: size=%d"),
1216 (pagedResults > 1) ? _("critical ") : "",
1220 printf(_("\n# with server side sorting %scontrol"),
1221 sss > 1 ? _("critical ") : "" );
1224 printf(_("\n# with virtual list view %scontrol: %d/%d"),
1225 vlv > 1 ? _("critical ") : "",
1226 vlvInfo.ldvlv_before_count, vlvInfo.ldvlv_after_count);
1227 if ( vlvInfo.ldvlv_attrvalue )
1228 printf(":%s", vlvInfo.ldvlv_attrvalue->bv_val );
1230 printf("/%d/%d", vlvInfo.ldvlv_offset, vlvInfo.ldvlv_count );
1232 #ifdef LDAP_CONTROL_X_DEREF
1234 printf(_("\n# with dereference %scontrol"),
1235 derefcrit > 1 ? _("critical ") : "" );
1239 printf( _("\n#\n\n") );
1241 if ( realbase && realbase != base ) {
1242 ldap_memfree( realbase );
1246 if ( infile == NULL ) {
1247 rc = dosearch( ld, base, scope, NULL, filtpattern,
1248 attrs, attrsonly, NULL, NULL, NULL, -1 );
1253 while ( fgets( line, sizeof( line ), fp ) != NULL ) {
1254 line[ strlen( line ) - 1 ] = '\0';
1260 rc1 = dosearch( ld, base, scope, filtpattern, line,
1261 attrs, attrsonly, NULL, NULL, NULL, -1 );
1269 if ( fp != stdin ) {
1275 if (( rc == LDAP_SUCCESS ) && pageSize && pr_morePagedResults ) {
1277 int i, moreEntries, tmpSize;
1279 /* Loop to get the next pages when
1280 * enter is pressed on the terminal.
1282 if ( pagePrompt != 0 ) {
1283 if ( entriesLeft > 0 ) {
1284 printf( _("Estimate entries: %d\n"), entriesLeft );
1286 printf( _("Press [size] Enter for the next {%d|size} entries.\n"),
1289 moreEntries = getchar();
1290 while ( moreEntries != EOF && moreEntries != '\n' ) {
1291 if ( i < (int)sizeof(buf) - 1 ) {
1292 buf[i] = moreEntries;
1295 moreEntries = getchar();
1299 if ( i > 0 && isdigit( (unsigned char)buf[0] ) ) {
1300 int num = sscanf( buf, "%d", &tmpSize );
1303 _("Invalid value for PagedResultsControl, %s.\n"), buf);
1304 return EXIT_FAILURE;
1307 pageSize = (ber_int_t)tmpSize;
1314 if (( rc == LDAP_SUCCESS ) && vlv ) {
1318 /* Loop to get the next window when
1319 * enter is pressed on the terminal.
1321 printf( _("Press [before/after(/offset/count|:value)] Enter for the next window.\n"));
1323 moreEntries = getchar();
1324 while ( moreEntries != EOF && moreEntries != '\n' ) {
1325 if ( i < (int)sizeof(buf) - 1 ) {
1326 buf[i] = moreEntries;
1329 moreEntries = getchar();
1333 i = parse_vlv( strdup( buf ));
1335 return EXIT_FAILURE;
1337 vlvInfo.ldvlv_attrvalue = NULL;
1338 vlvInfo.ldvlv_count = vlvCount;
1339 vlvInfo.ldvlv_offset += vlvInfo.ldvlv_after_count;
1342 if ( vlvInfo.ldvlv_context )
1343 ber_bvfree( vlvInfo.ldvlv_context );
1344 vlvInfo.ldvlv_context = vlvContext;
1351 if ( base != NULL ) {
1352 ber_memfree( base );
1354 if ( control != NULL ) {
1355 ber_memfree( control );
1357 if ( sss_keys != NULL ) {
1358 ldap_free_sort_keylist( sss_keys );
1360 if ( derefval.bv_val != NULL ) {
1361 ldap_memfree( derefval.bv_val );
1363 if ( urlpre != NULL ) {
1364 if ( def_urlpre != urlpre )
1370 for ( ; save_nctrls-- > 0; ) {
1371 ber_memfree( c[ save_nctrls ].ldctl_value.bv_val );
1381 static int dosearch(
1389 LDAPControl **sctrls,
1390 LDAPControl **cctrls,
1391 struct timeval *timeout,
1401 LDAPMessage *res, *msg;
1403 char *retoid = NULL;
1404 struct berval *retdata = NULL;
1405 int nresponses_psearch = -1;
1406 int cancel_msgid = -1;
1408 if( filtpatt != NULL ) {
1409 size_t max_fsize = strlen( filtpatt ) + strlen( value ) + 1, outlen;
1410 filter = malloc( max_fsize );
1411 if( filter == NULL ) {
1413 return EXIT_FAILURE;
1416 outlen = snprintf( filter, max_fsize, filtpatt, value );
1417 if( outlen >= max_fsize ) {
1418 fprintf( stderr, "Bad filter pattern: \"%s\"\n", filtpatt );
1420 return EXIT_FAILURE;
1424 fprintf( stderr, _("filter: %s\n"), filter );
1428 printf( _("#\n# filter: %s\n#\n"), filter );
1436 if ( filtpatt != NULL ) {
1439 return LDAP_SUCCESS;
1442 rc = ldap_search_ext( ld, base, scope, filter, attrs, attrsonly,
1443 sctrls, cctrls, timeout, sizelimit, &msgid );
1445 if ( filtpatt != NULL ) {
1449 if( rc != LDAP_SUCCESS ) {
1450 fprintf( stderr, _("%s: ldap_search_ext: %s (%d)\n"),
1451 prog, ldap_err2string( rc ), rc );
1455 nresponses = nentries = nreferences = nextended = npartial = 0;
1459 while ((rc = ldap_result( ld, LDAP_RES_ANY,
1460 sortattr ? LDAP_MSG_ALL : LDAP_MSG_ONE,
1463 rc = tool_check_abandon( ld, msgid );
1469 (void) ldap_sort_entries( ld, &res,
1470 ( *sortattr == '\0' ) ? NULL : sortattr, strcasecmp );
1473 for ( msg = ldap_first_message( ld, res );
1475 msg = ldap_next_message( ld, msg ) )
1477 if ( nresponses++ ) putchar('\n');
1478 if ( nresponses_psearch >= 0 )
1479 nresponses_psearch++;
1481 switch( ldap_msgtype( msg ) ) {
1482 case LDAP_RES_SEARCH_ENTRY:
1484 print_entry( ld, msg, attrsonly );
1487 case LDAP_RES_SEARCH_REFERENCE:
1489 print_reference( ld, msg );
1492 case LDAP_RES_EXTENDED:
1494 print_extended( ld, msg );
1496 if ( ldap_msgid( msg ) == 0 ) {
1497 /* unsolicited extended operation */
1501 if ( cancel_msgid != -1 &&
1502 cancel_msgid == ldap_msgid( msg ) ) {
1503 printf(_("Cancelled \n"));
1504 printf(_("cancel_msgid = %d\n"), cancel_msgid);
1509 case LDAP_RES_SEARCH_RESULT:
1510 /* pagedResults stuff is dealt with
1511 * in tool_print_ctrls(), called by
1512 * print_results(). */
1513 rc = print_result( ld, msg, 1 );
1514 if ( ldapsync == LDAP_SYNC_REFRESH_AND_PERSIST ) {
1520 case LDAP_RES_INTERMEDIATE:
1522 ldap_parse_intermediate( ld, msg,
1523 &retoid, &retdata, NULL, 0 );
1525 nresponses_psearch = 0;
1527 if ( strcmp( retoid, LDAP_SYNC_INFO ) == 0 ) {
1528 printf(_("SyncInfo Received\n"));
1529 ldap_memfree( retoid );
1530 ber_bvfree( retdata );
1534 print_partial( ld, msg );
1535 ldap_memfree( retoid );
1536 ber_bvfree( retdata );
1540 if ( ldapsync && sync_slimit != -1 &&
1541 nresponses_psearch >= sync_slimit ) {
1542 BerElement *msgidber = NULL;
1543 struct berval *msgidvalp = NULL;
1544 msgidber = ber_alloc_t(LBER_USE_DER);
1545 ber_printf(msgidber, "{i}", msgid);
1546 ber_flatten(msgidber, &msgidvalp);
1547 ldap_extended_operation(ld, LDAP_EXOP_CANCEL,
1548 msgidvalp, NULL, NULL, &cancel_msgid);
1549 nresponses_psearch = -1;
1553 ldap_msgfree( res );
1558 tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
1562 ldap_msgfree( res );
1564 if ( pagedResults ) {
1565 npagedresponses += nresponses;
1566 npagedentries += nentries;
1567 npagedextended += nextended;
1568 npagedpartial += npartial;
1569 npagedreferences += nreferences;
1570 if ( ( pr_morePagedResults == 0 ) && ( ldif < 2 ) ) {
1571 printf( _("\n# numResponses: %d\n"), npagedresponses );
1572 if( npagedentries ) {
1573 printf( _("# numEntries: %d\n"), npagedentries );
1575 if( npagedextended ) {
1576 printf( _("# numExtended: %d\n"), npagedextended );
1578 if( npagedpartial ) {
1579 printf( _("# numPartial: %d\n"), npagedpartial );
1581 if( npagedreferences ) {
1582 printf( _("# numReferences: %d\n"), npagedreferences );
1585 } else if ( ldif < 2 ) {
1586 printf( _("\n# numResponses: %d\n"), nresponses );
1587 if( nentries ) printf( _("# numEntries: %d\n"), nentries );
1588 if( nextended ) printf( _("# numExtended: %d\n"), nextended );
1589 if( npartial ) printf( _("# numPartial: %d\n"), npartial );
1590 if( nreferences ) printf( _("# numReferences: %d\n"), nreferences );
1596 /* This is the proposed new way of doing things.
1597 * It is more efficient, but the API is non-standard.
1606 char tmpfname[ 256 ];
1609 BerElement *ber = NULL;
1610 struct berval bv, *bvals, **bvp = &bvals;
1611 LDAPControl **ctrls = NULL;
1614 rc = ldap_get_dn_ber( ld, entry, &ber, &bv );
1617 ufn = ldap_dn2ufn( bv.bv_val );
1618 tool_write_ldif( LDIF_PUT_COMMENT, NULL, ufn, ufn ? strlen( ufn ) : 0 );
1620 tool_write_ldif( LDIF_PUT_VALUE, "dn", bv.bv_val, bv.bv_len );
1622 rc = ldap_get_entry_controls( ld, entry, &ctrls );
1623 if( rc != LDAP_SUCCESS ) {
1624 fprintf(stderr, _("print_entry: %d\n"), rc );
1625 tool_perror( "ldap_get_entry_controls", rc, NULL, NULL, NULL, NULL );
1626 exit( EXIT_FAILURE );
1630 tool_print_ctrls( ld, ctrls );
1631 ldap_controls_free( ctrls );
1636 ufn = ldap_dn2ufn( bv.bv_val );
1638 tool_write_ldif( LDIF_PUT_VALUE, "ufn", ufn, ufn ? strlen( ufn ) : 0 );
1641 if( ufn != NULL ) ldap_memfree( ufn );
1643 if ( attrsonly ) bvp = NULL;
1645 for ( rc = ldap_get_attribute_ber( ld, entry, ber, &bv, bvp );
1647 rc = ldap_get_attribute_ber( ld, entry, ber, &bv, bvp ) )
1649 if (bv.bv_val == NULL) break;
1652 tool_write_ldif( LDIF_PUT_NOVALUE, bv.bv_val, NULL, 0 );
1654 } else if ( bvals ) {
1655 for ( i = 0; bvals[i].bv_val != NULL; i++ ) {
1656 if ( vals2tmp > 1 || ( vals2tmp &&
1657 ldif_is_not_printable( bvals[i].bv_val, bvals[i].bv_len )))
1660 /* write value to file */
1661 snprintf( tmpfname, sizeof tmpfname,
1662 "%s" LDAP_DIRSEP "ldapsearch-%s-XXXXXX",
1663 tmpdir, bv.bv_val );
1666 tmpfd = mkstemp( tmpfname );
1673 if (( tmpfp = fdopen( tmpfd, "w")) == NULL ) {
1678 if ( fwrite( bvals[ i ].bv_val,
1679 bvals[ i ].bv_len, 1, tmpfp ) == 0 )
1688 snprintf( url, sizeof url, "%s%s", urlpre,
1689 &tmpfname[strlen(tmpdir) + sizeof(LDAP_DIRSEP) - 1] );
1692 tool_write_ldif( LDIF_PUT_URL, bv.bv_val, url, strlen( url ));
1695 tool_write_ldif( LDIF_PUT_VALUE, bv.bv_val,
1696 bvals[ i ].bv_val, bvals[ i ].bv_len );
1699 ber_memfree( bvals );
1708 static void print_reference(
1710 LDAPMessage *reference )
1714 LDAPControl **ctrls;
1717 printf(_("# search reference\n"));
1720 rc = ldap_parse_reference( ld, reference, &refs, &ctrls, 0 );
1722 if( rc != LDAP_SUCCESS ) {
1723 tool_perror( "ldap_parse_reference", rc, NULL, NULL, NULL, NULL );
1724 exit( EXIT_FAILURE );
1729 for( i=0; refs[i] != NULL; i++ ) {
1730 tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
1731 "ref", refs[i], strlen(refs[i]) );
1733 ber_memvfree( (void **) refs );
1737 tool_print_ctrls( ld, ctrls );
1738 ldap_controls_free( ctrls );
1742 static void print_extended(
1744 LDAPMessage *extended )
1747 char *retoid = NULL;
1748 struct berval *retdata = NULL;
1751 printf(_("# extended result response\n"));
1754 rc = ldap_parse_extended_result( ld, extended,
1755 &retoid, &retdata, 0 );
1757 if( rc != LDAP_SUCCESS ) {
1758 tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL );
1759 exit( EXIT_FAILURE );
1763 tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
1764 "extended", retoid, retoid ? strlen(retoid) : 0 );
1766 ber_memfree( retoid );
1770 tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_BINARY,
1771 "data", retdata->bv_val, retdata->bv_len );
1773 ber_bvfree( retdata );
1776 print_result( ld, extended, 0 );
1779 static void print_partial(
1781 LDAPMessage *partial )
1784 char *retoid = NULL;
1785 struct berval *retdata = NULL;
1786 LDAPControl **ctrls = NULL;
1789 printf(_("# extended partial response\n"));
1792 rc = ldap_parse_intermediate( ld, partial,
1793 &retoid, &retdata, &ctrls, 0 );
1795 if( rc != LDAP_SUCCESS ) {
1796 tool_perror( "ldap_parse_intermediate", rc, NULL, NULL, NULL, NULL );
1797 exit( EXIT_FAILURE );
1801 tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
1802 "partial", retoid, retoid ? strlen(retoid) : 0 );
1805 ber_memfree( retoid );
1809 tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_BINARY,
1810 "data", retdata->bv_val, retdata->bv_len );
1813 ber_bvfree( retdata );
1817 tool_print_ctrls( ld, ctrls );
1818 ldap_controls_free( ctrls );
1822 static int print_result(
1824 LDAPMessage *result, int search )
1828 char *matcheddn = NULL;
1831 LDAPControl **ctrls = NULL;
1835 printf(_("# search result\n"));
1838 printf("%s: %d\n", _("search"), ldap_msgid(result) );
1842 rc = ldap_parse_result( ld, result,
1843 &err, &matcheddn, &text, &refs, &ctrls, 0 );
1845 if( rc != LDAP_SUCCESS ) {
1846 tool_perror( "ldap_parse_result", rc, NULL, NULL, NULL, NULL );
1847 exit( EXIT_FAILURE );
1852 printf( _("result: %d %s\n"), err, ldap_err2string(err) );
1854 } else if ( err != LDAP_SUCCESS ) {
1855 fprintf( stderr, "%s (%d)\n", ldap_err2string(err), err );
1861 tool_write_ldif( LDIF_PUT_VALUE,
1862 "matchedDN", matcheddn, strlen(matcheddn) );
1864 fprintf( stderr, _("Matched DN: %s\n"), matcheddn );
1868 ber_memfree( matcheddn );
1874 if ( err == LDAP_PARTIAL_RESULTS ) {
1877 for ( line = text; line != NULL; ) {
1878 char *next = strchr( line, '\n' );
1880 tool_write_ldif( LDIF_PUT_TEXT,
1882 next ? (size_t) (next - line) : strlen( line ));
1884 line = next ? next + 1 : NULL;
1888 tool_write_ldif( LDIF_PUT_TEXT, "text",
1889 text, strlen(text) );
1892 fprintf( stderr, _("Additional information: %s\n"), text );
1896 ber_memfree( text );
1901 for( i=0; refs[i] != NULL; i++ ) {
1903 tool_write_ldif( LDIF_PUT_VALUE, "ref", refs[i], strlen(refs[i]) );
1905 fprintf( stderr, _("Referral: %s\n"), refs[i] );
1909 ber_memvfree( (void **) refs );
1912 pr_morePagedResults = 0;
1915 tool_print_ctrls( ld, ctrls );
1916 ldap_controls_free( ctrls );