]> git.sur5r.net Git - openldap/blob - clients/tools/ldapsearch.c
Fix broken MSVC builds. The previous round of Mingw32 patches changed some
[openldap] / clients / tools / ldapsearch.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 #include "portable.h"
7
8 #include <stdio.h>
9
10 #include <ac/stdlib.h>
11
12 #include <ac/ctype.h>
13 #include <ac/signal.h>
14 #include <ac/string.h>
15 #include <ac/unistd.h>
16
17 #ifdef HAVE_IO_H
18 #include <io.h>
19 #endif
20
21 #include <ldap.h>
22
23 #include "ldif.h"
24 #include "ldap_defaults.h"
25
26 #define DEFSEP          "="
27
28 static void
29 usage( const char *s )
30 {
31         fprintf( stderr,
32 "usage: %s [options] filter [attributes...]\nwhere:\n"
33 "       filter\tRFC-1558 compliant LDAP search filter\n"
34 "       attributes\twhitespace-separated list of attributes to retrieve\n"
35 "\t\t1.1                -- no attributes\n"
36 "\t\t*            -- all user attributes\n"
37 "\t\t+            -- all operational attributes\n"
38 "\t\tempty list -- all non-operational attributes\n"
39 "options:\n"
40 "       -n\t\tshow what would be done but don't actually search\n"
41 "       -v\t\trun in verbose mode (diagnostics to standard output)\n"
42 "       -t\t\twrite binary values to files in TMPDIR\n"
43 "       -tt\t\twrite all values to files in TMPDIR\n"
44 "       -T path\twrite files to directory specified by path (default: \"/tmp\")\n"
45 "       -V prefix\tURL prefix for files (default: \"file://tmp/\"\n"
46 "       -u\t\tinclude User Friendly entry names in the output\n"
47 "       -A\t\tretrieve attribute names only (no values)\n"
48 "       -B\t\tdo not suppress printing of binary values\n"
49 "       -F sep\tprint `sep' instead of `=' between attribute names and values\n"
50 "       -L\t\tprint entries in LDIF format (implies -B)\n"
51 "       -LL\t\tprint entries in LDIF format without comments\n"
52 "       -LLL\t\tprint entries in LDIF format without comments and version\n"
53 "       -M\t\tenable Manage DSA IT control (-MM to make critical)\n"
54 "       -R\t\tdo not automatically follow referrals\n"
55 "       -S attr\tsort the results by attribute `attr'\n"
56 "       -d level\tset LDAP debugging level to `level'\n"
57 "       -f file\tperform sequence of searches listed in `file'\n"
58 "       -b basedn\tbase dn for search\n"
59 "       -s scope\tone of base, one, or sub (search scope)\n"
60 "       -a deref\tone of never, always, search, or find (alias dereferencing)\n"
61 "       -l limit\ttime limit (in seconds) for search\n"
62 "       -z limit\tsize limit (in entries) for search\n"
63 "       -D binddn\tbind dn\n"
64 "       -w passwd\tbind passwd (for simple authentication)\n"
65 "       -W\t\tprompt for bind passwd\n"
66 #ifdef HAVE_KERBEROS
67 "       -k\t\tuse Kerberos instead of Simple Password authentication\n"
68 #endif
69 "       -h host\tldap server\n"
70 "       -p port\tport on ldap server\n"
71 "       -P version\tprocotol version (2 or 3)\n"
72 ,               s );
73
74         exit( EXIT_FAILURE );
75 }
76
77 static void print_entry LDAP_P((
78         LDAP    *ld,
79         LDAPMessage     *entry,
80         int             attrsonly));
81
82 static int write_ldif LDAP_P((
83         int type,
84         char *name,
85         char *value,
86         ber_len_t vallen ));
87
88 static int dosearch LDAP_P((
89         LDAP    *ld,
90         char    *base,
91         int             scope,
92         char    **attrs,
93         int             attrsonly,
94         char    *filtpatt,
95         char    *value));
96
97 #define TMPDIR "/tmp"
98 #define URLPRE "file:/tmp/"
99
100 static char *tmpdir = NULL;
101 static char *urlpre = NULL;
102
103 static char     *binddn = NULL;
104 static char     *passwd = NULL;
105 static char     *base = NULL;
106 static char     *ldaphost = NULL;
107 static int      ldapport = 0;
108 static char     *sep = DEFSEP;
109 static char     *sortattr = NULL;
110 static int      skipsortattr = 0;
111 static int      verbose, not, includeufn, binary, vals2tmp, ldif;
112
113 int
114 main( int argc, char **argv )
115 {
116         char            *infile, *filtpattern, **attrs, line[ BUFSIZ ];
117         FILE            *fp;
118         int                     rc, i, first, scope, deref, attrsonly, manageDSAit;
119         int                     referrals, timelimit, sizelimit, debug;
120         int             authmethod, version, want_bindpw;
121         LDAP            *ld;
122
123         infile = NULL;
124         debug = verbose = binary = not = vals2tmp =
125                 attrsonly = manageDSAit = ldif = want_bindpw = 0;
126
127         deref = referrals = sizelimit = timelimit = version = -1;
128
129         scope = LDAP_SCOPE_SUBTREE;
130         authmethod = LDAP_AUTH_SIMPLE;
131
132         while (( i = getopt( argc, argv,
133                 "WKknuvtMRABLD:s:f:h:b:d:P:p:F:a:w:l:z:S:T:V:")) != EOF )
134         {
135         switch( i ) {
136         case 'n':       /* do Not do any searches */
137                 ++not;
138                 break;
139         case 'v':       /* verbose mode */
140                 ++verbose;
141                 break;
142         case 'd':
143                 debug |= atoi( optarg );
144                 break;
145         case 'k':       /* use kerberos bind */
146 #ifdef HAVE_KERBEROS
147                 authmethod = LDAP_AUTH_KRBV4;
148 #else
149                 fprintf (stderr, "%s was not compiled with Kerberos support\n", argv[0]);
150 #endif
151                 break;
152         case 'K':       /* use kerberos bind, 1st part only */
153 #ifdef HAVE_KERBEROS
154                 authmethod = LDAP_AUTH_KRBV41;
155 #else
156                 fprintf (stderr, "%s was not compiled with Kerberos support\n", argv[0]);
157 #endif
158                 break;
159         case 'u':       /* include UFN */
160                 ++includeufn;
161                 break;
162         case 't':       /* write attribute values to /tmp files */
163                 ++vals2tmp;
164                 break;
165         case 'M':
166                 /* enable Manage DSA IT */
167                 manageDSAit++;
168                 break;
169         case 'R':       /* don't automatically chase referrals */
170                 referrals = (int) LDAP_OPT_OFF;
171                 break;
172         case 'A':       /* retrieve attribute names only -- no values */
173                 ++attrsonly;
174                 break;
175         case 'L':       /* print entries in LDIF format */
176                 ++ldif;
177                 /* fall through -- always allow binary when outputting LDIF */
178         case 'B':       /* allow binary values to be printed */
179                 ++binary;
180                 break;
181         case 's':       /* search scope */
182                 if ( strcasecmp( optarg, "base" ) == 0 ) {
183                 scope = LDAP_SCOPE_BASE;
184                 } else if ( strcasecmp( optarg, "one" ) == 0 ) {
185                 scope = LDAP_SCOPE_ONELEVEL;
186                 } else if ( strcasecmp( optarg, "sub" ) == 0 ) {
187                 scope = LDAP_SCOPE_SUBTREE;
188                 } else {
189                 fprintf( stderr, "scope should be base, one, or sub\n" );
190                 usage( argv[ 0 ] );
191                 }
192                 break;
193
194         case 'a':       /* set alias deref option */
195                 if ( strcasecmp( optarg, "never" ) == 0 ) {
196                 deref = LDAP_DEREF_NEVER;
197                 } else if ( strcasecmp( optarg, "search" ) == 0 ) {
198                 deref = LDAP_DEREF_SEARCHING;
199                 } else if ( strcasecmp( optarg, "find" ) == 0 ) {
200                 deref = LDAP_DEREF_FINDING;
201                 } else if ( strcasecmp( optarg, "always" ) == 0 ) {
202                 deref = LDAP_DEREF_ALWAYS;
203                 } else {
204                 fprintf( stderr, "alias deref should be never, search, find, or always\n" );
205                 usage( argv[ 0 ] );
206                 }
207                 break;
208                 
209         case 'T':       /* field separator */
210                 if( tmpdir ) free( tmpdir );
211                 tmpdir = strdup( optarg );
212                 break;
213         case 'V':       /* field separator */
214                 if( urlpre ) free( urlpre );
215                 urlpre = strdup( optarg );
216                 break;
217         case 'F':       /* field separator */
218                 sep = strdup( optarg );
219                 break;
220         case 'f':       /* input file */
221                 infile = strdup( optarg );
222                 break;
223         case 'h':       /* ldap host */
224                 ldaphost = strdup( optarg );
225                 break;
226         case 'b':       /* searchbase */
227                 base = strdup( optarg );
228                 break;
229         case 'D':       /* bind DN */
230                 binddn = strdup( optarg );
231                 break;
232         case 'p':       /* ldap port */
233                 ldapport = atoi( optarg );
234                 break;
235         case 'w':       /* bind password */
236                 passwd = strdup( optarg );
237                 {
238                         char* p;
239
240                         for( p = optarg; *p == '\0'; p++ ) {
241                                 *p = '*';
242                         }
243                 }
244                 break;
245         case 'l':       /* time limit */
246                 timelimit = atoi( optarg );
247                 break;
248         case 'z':       /* size limit */
249                 sizelimit = atoi( optarg );
250                 break;
251         case 'S':       /* sort attribute */
252                 sortattr = strdup( optarg );
253                 break;
254         case 'W':
255                 want_bindpw++;
256                 break;
257         case 'P':
258                 switch( atoi( optarg ) )
259                 {
260                 case 2:
261                         version = LDAP_VERSION2;
262                         break;
263                 case 3:
264                         version = LDAP_VERSION3;
265                         break;
266                 default:
267                         fprintf( stderr, "protocol version should be 2 or 3\n" );
268                         usage( argv[0] );
269                 }
270                 break;
271         default:
272                 usage( argv[0] );
273         }
274         }
275
276         if ( argc - optind < 1 ) {
277                 usage( argv[ 0 ] );
278         }
279
280         filtpattern = strdup( argv[ optind ] );
281
282         if ( argv[ optind + 1 ] == NULL ) {
283                 attrs = NULL;
284         } else if ( sortattr == NULL || *sortattr == '\0' ) {
285                 attrs = &argv[ optind + 1 ];
286         } else {
287                 for ( i = optind + 1; i < argc; i++ ) {
288                         if ( strcasecmp( argv[ i ], sortattr ) == 0 ) {
289                                 break;
290                         }
291                 }
292                 if ( i == argc ) {
293                         skipsortattr = 1;
294                         argv[ optind ] = sortattr;
295                 } else {
296                         optind++;
297                 }
298                 attrs = &argv[ optind ];
299         }
300
301         if ( infile != NULL ) {
302                 if ( infile[0] == '-' && infile[1] == '\0' ) {
303                         fp = stdin;
304                 } else if (( fp = fopen( infile, "r" )) == NULL ) {
305                         perror( infile );
306                         return EXIT_FAILURE;
307                 }
308         }
309
310         if( tmpdir == NULL
311                 && (tmpdir = getenv("TMPDIR")) == NULL
312                 && (tmpdir = getenv("TMP")) == NULL
313                 && (tmpdir = getenv("TEMP")) == NULL )
314         {
315                 tmpdir = "/tmp";
316         }
317
318         if( urlpre == NULL ) {
319                 urlpre = malloc( sizeof("file:///") + strlen(tmpdir) );
320
321                 if( urlpre == NULL ) {
322                         perror( "malloc" );
323                         return EXIT_FAILURE;
324                 }
325
326                 sprintf( urlpre, "file:///%s/",
327                         tmpdir[0] == '/' ? &tmpdir[1] : tmpdir );
328
329                 /* urlpre should be URLized.... */
330         }
331
332         if ( debug ) {
333                 if( ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &debug ) != LBER_OPT_SUCCESS ) {
334                         fprintf( stderr, "Could not set LBER_OPT_DEBUG_LEVEL %d\n", debug );
335                 }
336                 if( ldap_set_option( NULL, LDAP_OPT_DEBUG_LEVEL, &debug ) != LDAP_OPT_SUCCESS ) {
337                         fprintf( stderr, "Could not set LDAP_OPT_DEBUG_LEVEL %d\n", debug );
338                 }
339                 ldif_debug = debug;
340         }
341
342 #ifdef SIGPIPE
343         (void) SIGNAL( SIGPIPE, SIG_IGN );
344 #endif
345
346         if ( verbose ) {
347                 fprintf( stderr,
348                         (ldapport ? "ldap_init( %s, %d )\n" : "ldap_init( %s, <DEFAULT> )\n"),
349                         (ldaphost != NULL) ? ldaphost : "<DEFAULT>",
350                         ldapport );
351         }
352
353         if (( ld = ldap_init( ldaphost, ldapport )) == NULL ) {
354                 perror( "ldap_init" );
355                 return( EXIT_FAILURE );
356         }
357
358         if (deref != -1 &&
359                 ldap_set_option( ld, LDAP_OPT_DEREF, (void *) &deref ) != LDAP_OPT_SUCCESS )
360         {
361                 fprintf( stderr, "Could not set LDAP_OPT_DEREF %d\n", deref );
362         }
363         if (timelimit != -1 &&
364                 ldap_set_option( ld, LDAP_OPT_TIMELIMIT, (void *) &timelimit ) != LDAP_OPT_SUCCESS )
365         {
366                 fprintf( stderr, "Could not set LDAP_OPT_TIMELIMIT %d\n", timelimit );
367         }
368         if (sizelimit != -1 &&
369                 ldap_set_option( ld, LDAP_OPT_SIZELIMIT, (void *) &sizelimit ) != LDAP_OPT_SUCCESS )
370         {
371                 fprintf( stderr, "Could not set LDAP_OPT_SIZELIMIT %d\n", sizelimit );
372         }
373         if (referrals != -1 &&
374                 ldap_set_option( ld, LDAP_OPT_REFERRALS,
375                                  (referrals ? LDAP_OPT_ON : LDAP_OPT_OFF) ) != LDAP_OPT_SUCCESS )
376         {
377                 fprintf( stderr, "Could not set LDAP_OPT_REFERRALS %s\n",
378                         referrals ? "on" : "off" );
379         }
380
381         if (version != -1 &&
382                 ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version ) != LDAP_OPT_SUCCESS )
383         {
384                 fprintf( stderr, "Could not set LDAP_OPT_PROTOCOL_VERSION %d\n", version );
385         }
386
387         if (want_bindpw) {
388                 passwd = getpass("Enter LDAP Password: ");
389         }
390
391         if ( ldap_bind_s( ld, binddn, passwd, authmethod ) != LDAP_SUCCESS ) {
392                 ldap_perror( ld, "ldap_bind" );
393                 return( EXIT_FAILURE );
394         }
395
396         if ( manageDSAit ) {
397                 int err;
398                 LDAPControl c;
399                 LDAPControl *ctrls[2];
400                 ctrls[0] = &c;
401                 ctrls[1] = NULL;
402
403                 c.ldctl_oid = LDAP_CONTROL_MANAGEDSAIT;
404                 c.ldctl_value.bv_val = NULL;
405                 c.ldctl_value.bv_len = 0;
406                 c.ldctl_iscritical = manageDSAit > 1;
407
408                 err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, &ctrls );
409
410                 if( err != LDAP_OPT_SUCCESS ) {
411                         fprintf( stderr, "Could not set Manage DSA IT Control\n" );
412                         if( c.ldctl_iscritical ) {
413                                 exit( EXIT_FAILURE );
414                         }
415                 }
416         }
417
418         if ( verbose ) {
419                 fprintf( stderr, "filter%s: %s\nreturning: ",
420                         infile != NULL ? " pattern" : "",
421                         filtpattern );
422
423                 if ( attrs == NULL ) {
424                         fprintf( stderr, "ALL" );
425                 } else {
426                         for ( i = 0; attrs[ i ] != NULL; ++i ) {
427                                 fprintf( stderr, "%s ", attrs[ i ] );
428                         }
429                 }
430                 fprintf( stderr, "\n" );
431         }
432
433         if ( ldif ) {
434                 if (ldif < 3 ) {
435                         printf( "version: 1\n\n");
436                 }
437
438                 if (ldif < 2 ) {
439                         printf( "#\n# filter%s: %s\n# returning: ",
440                                 infile != NULL ? " pattern" : "",
441                                 filtpattern );
442
443                         if ( attrs == NULL ) {
444                                 printf( "ALL" );
445                         } else {
446                                 for ( i = 0; attrs[ i ] != NULL; ++i ) {
447                                         printf( "%s ", attrs[ i ] );
448                                 }
449                         }
450                         printf( "\n#\n\n" );
451                 }
452         }
453
454         if ( infile == NULL ) {
455                 rc = dosearch( ld, base, scope, attrs, attrsonly, NULL, filtpattern );
456
457         } else {
458                 rc = 0;
459                 first = 1;
460                 while ( rc == 0 && fgets( line, sizeof( line ), fp ) != NULL ) {
461                         line[ strlen( line ) - 1 ] = '\0';
462                         if ( !first ) {
463                                 putchar( '\n' );
464                         } else {
465                                 first = 0;
466                         }
467                         rc = dosearch( ld, base, scope, attrs, attrsonly,
468                                 filtpattern, line );
469                 }
470                 if ( fp != stdin ) {
471                         fclose( fp );
472                 }
473         }
474
475         ldap_unbind( ld );
476         return( rc );
477 }
478
479
480 static int dosearch(
481         LDAP    *ld,
482         char    *base,
483         int             scope,
484         char    **attrs,
485         int             attrsonly,
486         char    *filtpatt,
487         char    *value)
488 {
489         char            filter[ BUFSIZ ];
490         int                     rc, first, matches;
491         LDAPMessage             *res, *e;
492
493         if( filtpatt != NULL ) {
494                 sprintf( filter, filtpatt, value );
495
496                 if ( verbose ) {
497                         fprintf( stderr, "filter is: (%s)\n", filter );
498                 }
499
500                 if( ldif == 1 ) {
501                         printf( "#\n# filter: %s\n#\n", filter );
502                 }
503
504         } else {
505                 sprintf( filter, "%s", value );
506         }
507
508         if ( not ) {
509                 return( LDAP_SUCCESS );
510         }
511
512         if ( ldap_search( ld, base, scope, filter, attrs, attrsonly ) == -1 ) {
513                 int ld_errno;
514                 ldap_perror( ld, "ldap_search" );
515
516                 ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &ld_errno);
517                 return( ld_errno );
518         }
519
520         matches = 0;
521         first = 1;
522         res = NULL;
523         while ( (rc = ldap_result( ld, LDAP_RES_ANY, sortattr ? 1 : 0, NULL, &res ))
524                 == LDAP_RES_SEARCH_ENTRY ) {
525         matches++;
526         e = ldap_first_entry( ld, res );
527         if ( !first ) {
528                 putchar( '\n' );
529         } else {
530                 first = 0;
531         }
532         print_entry( ld, e, attrsonly );
533         ldap_msgfree( res );
534         res = NULL;
535         }
536         if ( rc == -1 ) {
537         ldap_perror( ld, "ldap_result" );
538         return( rc );
539         }
540         if (( rc = ldap_result2error( ld, res, 0 )) != LDAP_SUCCESS ) {
541                 ldap_perror( ld, "ldap_search" );
542         }
543         if ( sortattr != NULL ) {
544                 (void) ldap_sort_entries( ld, &res,
545                         ( *sortattr == '\0' ) ? NULL : sortattr, strcasecmp );
546                 matches = 0;
547                 first = 1;
548                 for ( e = ldap_first_entry( ld, res ); e != NULL;
549                         e = ldap_next_entry( ld, e ) ) {
550                 matches++;
551                 if ( !first ) {
552                         putchar( '\n' );
553                 } else {
554                         first = 0;
555                 }
556                 print_entry( ld, e, attrsonly );
557                 }
558         }
559
560         if ( verbose ) {
561                 printf( "%d matches\n", matches );
562         }
563
564         ldap_msgfree( res );
565         return( rc );
566 }
567
568
569 static void
570 print_entry(
571         LDAP    *ld,
572         LDAPMessage     *entry,
573         int             attrsonly)
574 {
575         char            *a, *dn, *ufn;
576         char    tmpfname[ 256 ];
577         char    url[ 256 ];
578         int                     i;
579         BerElement              *ber = NULL;
580         struct berval   **bvals;
581         FILE            *tmpfp;
582
583         dn = ldap_get_dn( ld, entry );
584         ufn = NULL;
585
586         if ( ldif == 1 ) {
587                 ufn = ldap_dn2ufn( dn );
588                 write_ldif( LDIF_PUT_COMMENT, NULL, ufn, strlen( ufn ));
589         }
590         if ( ldif ) {
591                 write_ldif( LDIF_PUT_VALUE, "dn", dn, strlen( dn ));
592         } else {
593                 printf( "%s\n", dn );
594         }
595
596         if ( includeufn ) {
597                 if( ufn == NULL ) {
598                         ufn = ldap_dn2ufn( dn );
599                 }
600                 if ( ldif ) {
601                         write_ldif( LDIF_PUT_VALUE, "ufn", ufn, strlen( ufn ));
602                 } else {
603                         printf( "%s\n", ufn );
604                 }
605         }
606
607         if( ufn != NULL ) ldap_memfree( ufn );
608         ldap_memfree( dn );
609
610         for ( a = ldap_first_attribute( ld, entry, &ber ); a != NULL;
611                 a = ldap_next_attribute( ld, entry, ber ) )
612         {
613                 if ( skipsortattr && strcasecmp( a, sortattr ) == 0 ) {
614                         continue;
615                 }
616
617                 if ( attrsonly ) {
618                         if ( ldif ) {
619                                 write_ldif( LDIF_PUT_NOVALUE, a, NULL, 0 );
620                         } else {
621                                 printf( "%s\n", a );
622                         }
623
624                 } else if (( bvals = ldap_get_values_len( ld, entry, a )) != NULL ) {
625                         for ( i = 0; bvals[i] != NULL; i++ ) {
626                                 if ( vals2tmp > 1 || ( vals2tmp
627                                         && ldif_is_not_printable( bvals[i]->bv_val, bvals[i]->bv_len ) ))
628                                 {
629                                         /* write value to file */
630                                         sprintf( tmpfname, "%s" LDAP_DIRSEP "ldapsearch-%s-XXXXXX",
631                                                 tmpdir, a );
632                                         tmpfp = NULL;
633
634                                         if ( mktemp( tmpfname ) == NULL ) {
635                                                 perror( tmpfname );
636                                                 continue;
637                                         }
638
639                                         if (( tmpfp = fopen( tmpfname, "w")) == NULL ) {
640                                                 perror( tmpfname );
641                                                 continue;
642                                         }
643
644                                         if ( fwrite( bvals[ i ]->bv_val,
645                                                 bvals[ i ]->bv_len, 1, tmpfp ) == 0 )
646                                         {
647                                                 perror( tmpfname );
648                                                 fclose( tmpfp );
649                                                 continue;
650                                         }
651
652                                         fclose( tmpfp );
653
654                                         sprintf( url, "%s%s", urlpre,
655                                                 &tmpfname[strlen(tmpdir) + sizeof(LDAP_DIRSEP) - 1] );
656
657                                         if ( ldif ) {
658                                                 write_ldif( LDIF_PUT_URL, a, url, strlen( url ));
659                                         } else {
660                                                 printf( "%s%s%s\n", a, sep, url );
661                                         }
662
663
664                                 } else {
665                                         if ( ldif ) {
666                                                 write_ldif( LDIF_PUT_VALUE, a,
667                                                         bvals[ i ]->bv_val, bvals[ i ]->bv_len );
668
669                                         } else {
670                                                 int notprint = !binary && !vals2tmp
671                                                         && ldif_is_not_printable( bvals[i]->bv_val,
672                                                                 bvals[i]->bv_len ); 
673                                                 printf( "%s%s", a, sep );
674                                                 puts( notprint ? "NOT PRINTABLE" : bvals[ i ]->bv_val );
675                                         }
676                                 }
677                         }
678                         ber_bvecfree( bvals );
679                 }
680         }
681
682         if( ber != NULL ) {
683                 ber_free( ber, 0 );
684         }
685 }
686
687
688 static int
689 write_ldif( int type, char *name, char *value, ber_len_t vallen )
690 {
691         char    *ldif;
692
693         if (( ldif = ldif_put( type, name, value, vallen )) == NULL ) {
694                 return( -1 );
695         }
696
697         fputs( ldif, stdout );
698         ber_memfree( ldif );
699
700         return( 0 );
701 }