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