3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 /* ldapmodify.c - generic program to modify or add entries using LDAP */
12 #include <ac/stdlib.h>
15 #include <ac/signal.h>
16 #include <ac/string.h>
17 #include <ac/unistd.h>
19 #ifdef HAVE_SYS_STAT_H
23 #ifdef HAVE_SYS_FILE_H
32 #include "lutil_ldap.h"
34 #include "ldap_defaults.h"
37 static char *binddn = NULL;
38 static struct berval passwd = { 0, NULL };
39 static char *ldaphost = NULL;
40 static int ldapport = 0;
41 #ifdef HAVE_CYRUS_SASL
42 static char *sasl_authc_id = NULL;
43 static char *sasl_authz_id = NULL;
44 static char *sasl_mech = NULL;
45 static char *sasl_secprops = NULL;
47 static int use_tls = 0;
48 static int ldapadd, replace, not, verbose, contoper, force;
51 #define LDAPMOD_MAXLINE 4096
53 /* strings found in replog/LDIF entries (mostly lifted from slurpd/slurp.h) */
54 #define T_VERSION_STR "version"
55 #define T_REPLICA_STR "replica"
57 #define T_CHANGETYPESTR "changetype"
58 #define T_ADDCTSTR "add"
59 #define T_MODIFYCTSTR "modify"
60 #define T_DELETECTSTR "delete"
61 #define T_MODRDNCTSTR "modrdn"
62 #define T_MODDNCTSTR "moddn"
63 #define T_RENAMECTSTR "rename"
64 #define T_MODOPADDSTR "add"
65 #define T_MODOPREPLACESTR "replace"
66 #define T_MODOPDELETESTR "delete"
67 #define T_MODSEPSTR "-"
68 #define T_NEWRDNSTR "newrdn"
69 #define T_DELETEOLDRDNSTR "deleteoldrdn"
70 #define T_NEWSUPSTR "newsuperior"
73 static void usage LDAP_P(( const char *prog )) LDAP_GCCATTR((noreturn));
74 static int process_ldif_rec LDAP_P(( char *rbuf, int count ));
75 static void addmodifyop LDAP_P((
76 LDAPMod ***pmodsp, int modop,
78 struct berval *value ));
79 static int domodify LDAP_P((
83 static int dodelete LDAP_P((
85 static int dorename LDAP_P((
90 static char *read_one_record LDAP_P(( FILE *fp ));
93 usage( const char *prog )
96 "Add or modify entries from an LDAP server\n\n"
97 "usage: %s [options]\n"
98 " The list of desired operations are read from stdin or from the file\n"
99 " specified by \"-f file\".\n"
100 "Add or modify options:\n"
101 " -a\t\tadd values (default%s)\n"
102 " -r\t\treplace values\n"
103 " -F\t\tforce all changes records to be used\n"
106 " -c\t\tcontinuous operation (ignore errors)\n"
107 " -C\t\tchase referrals\n"
108 " -d level\tset LDAP debugging level to `level'\n"
109 " -D dn\t\tbind DN\n"
110 " -f file\t\tread operations from `file'\n"
111 " -h host\t\tLDAP server\n"
112 " -k\t\tuse Kerberos authentication\n"
113 " -K\t\tlike -k, but do only step 1 of the Kerberos bind\n"
114 " -M\t\tenable Manage DSA IT control (-MM to make it critical)\n"
115 " -n\t\tprint changes, don't actually do them\n"
116 " -O secprops\tSASL security properties\n"
117 " -p port\t\tport on LDAP server\n"
118 " -U user\t\tSASL authentication identity (username)\n"
119 " -v\t\tverbose mode\n"
120 " -w passwd\tbind password (for Simple authentication)\n"
121 " -X id\t\tSASL authorization identity (\"dn:<dn>\" or \"u:<user>\")\n"
122 " -Y mech\t\tSASL mechanism\n"
123 " -Z\t\tissue Start TLS request (-ZZ to require successful response)\n"
124 , prog, (strcmp( prog, "ldapadd" ) ? " is to replace" : "") );
126 exit( EXIT_FAILURE );
131 main( int argc, char **argv )
133 char *infile, *rbuf, *start;
135 int rc, i, authmethod, version, want_bindpw, debug, manageDSAit, referrals;
138 if (( prog = strrchr( argv[ 0 ], *LDAP_DIRSEP )) == NULL ) {
144 /* Print usage when no parameters */
145 if( argc < 2 ) usage( prog );
147 ldapadd = ( strcmp( prog, "ldapadd" ) == 0 );
150 not = verbose = want_bindpw = debug = manageDSAit = referrals = 0;
154 while (( i = getopt( argc, argv, "acrf:F" "Cd:D:h:kKMnO:p:P:U:vw:WxX:Y:Z" )) != EOF ) {
160 case 'c': /* continuous operation */
163 case 'f': /* read from file */
164 infile = strdup( optarg );
166 case 'F': /* force all changes records to be used */
169 case 'r': /* default is to replace rather than add values */
178 debug |= atoi( optarg );
180 case 'D': /* bind DN */
181 binddn = strdup( optarg );
183 case 'h': /* ldap host */
184 ldaphost = strdup( optarg );
186 case 'k': /* kerberos bind */
187 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
188 if( version > LDAP_VERSION2 ) {
189 fprintf( stderr, "%s: -k incompatible with LDAPv%d\n",
194 if( authmethod != -1 ) {
195 fprintf( stderr, "%s: -k incompatible with previous "
196 "authentication choice\n", prog );
200 authmethod = LDAP_AUTH_KRBV4;
202 fprintf( stderr, "%s: not compiled with Kerberos support\n", prog );
206 case 'K': /* kerberos bind, part one only */
207 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
208 if( version > LDAP_VERSION2 ) {
209 fprintf( stderr, "%s: -k incompatible with LDAPv%d\n",
213 if( authmethod != -1 ) {
214 fprintf( stderr, "%s: incompatible with previous "
215 "authentication choice\n", prog );
219 authmethod = LDAP_AUTH_KRBV41;
221 fprintf( stderr, "%s: not compiled with Kerberos support\n", prog );
222 return( EXIT_FAILURE );
226 /* enable Manage DSA IT */
227 if( version == LDAP_VERSION2 ) {
228 fprintf( stderr, "%s: -M incompatible with LDAPv%d\n",
233 version = LDAP_VERSION3;
235 case 'n': /* print deletes, don't actually do them */
239 #ifdef HAVE_CYRUS_SASL
240 if( version == LDAP_VERSION2 ) {
241 fprintf( stderr, "%s -O incompatible with LDAPv%d\n",
245 if( authmethod != -1 && authmethod != LDAP_AUTH_SASL ) {
246 fprintf( stderr, "%s: incompatible previous "
247 "authentication choice\n", prog );
250 sasl_secprops = strdup( optarg );
251 authmethod = LDAP_AUTH_SASL;
252 version = LDAP_VERSION3;
254 fprintf( stderr, "%s: not compiled with SASL support\n",
256 return( EXIT_FAILURE );
260 ldapport = atoi( optarg );
263 switch( atoi(optarg) ) {
265 if( version == LDAP_VERSION3 ) {
266 fprintf( stderr, "%s: -P 2 incompatible with version %d\n",
270 version = LDAP_VERSION2;
273 if( version == LDAP_VERSION2 ) {
274 fprintf( stderr, "%s: -P 2 incompatible with version %d\n",
278 version = LDAP_VERSION3;
281 fprintf( stderr, "%s: protocol version should be 2 or 3\n",
284 return( EXIT_FAILURE );
287 #ifdef HAVE_CYRUS_SASL
288 if( version == LDAP_VERSION2 ) {
289 fprintf( stderr, "%s: -U incompatible with version %d\n",
293 if( authmethod != -1 && authmethod != LDAP_AUTH_SASL ) {
294 fprintf( stderr, "%s: incompatible previous "
295 "authentication choice\n",
299 authmethod = LDAP_AUTH_SASL;
300 version = LDAP_VERSION3;
302 sasl_authc_id = strdup( optarg );
303 authmethod = LDAP_AUTH_SASL;
305 fprintf( stderr, "%s: was not compiled with SASL support\n",
307 return( EXIT_FAILURE );
310 case 'v': /* verbose mode */
313 case 'w': /* password */
314 passwd.bv_val = strdup( optarg );
318 for( p = optarg; *p == '\0'; p++ ) {
322 passwd.bv_len = strlen( passwd.bv_val );
328 #ifdef HAVE_CYRUS_SASL
329 if( version == LDAP_VERSION2 ) {
330 fprintf( stderr, "%s: -Y incompatible with version %d\n",
334 if( authmethod != -1 && authmethod != LDAP_AUTH_SASL ) {
335 fprintf( stderr, "%s: incompatible with authentication choice\n", prog );
339 authmethod = LDAP_AUTH_SASL;
340 version = LDAP_VERSION3;
342 fprintf( stderr, "%s: was not compiled with SASL support\n",
344 return( EXIT_FAILURE );
348 if( authmethod != -1 && authmethod != LDAP_AUTH_SIMPLE ) {
349 fprintf( stderr, "%s: incompatible with previous "
350 "authentication choice\n", prog );
353 authmethod = LDAP_AUTH_SIMPLE;
356 #ifdef HAVE_CYRUS_SASL
357 if( version == LDAP_VERSION2 ) {
358 fprintf( stderr, "%s: -X incompatible with LDAPv%d\n",
362 if( authmethod != -1 && authmethod != LDAP_AUTH_SASL ) {
363 fprintf( stderr, "%s: -X incompatible with "
364 "authentication choice\n", prog );
367 authmethod = LDAP_AUTH_SASL;
368 version = LDAP_VERSION3;
370 sasl_authz_id = strdup( optarg );
371 authmethod = LDAP_AUTH_SASL;
373 fprintf( stderr, "%s: not compiled with SASL support\n",
375 return( EXIT_FAILURE );
380 if( version == LDAP_VERSION2 ) {
381 fprintf( stderr, "%s -Z incompatible with version %d\n",
385 version = LDAP_VERSION3;
388 fprintf( stderr, "%s: not compiled with TLS support\n",
390 return( EXIT_FAILURE );
394 fprintf( stderr, "%s: unrecongized option -%c\n",
401 version = LDAP_VERSION3;
403 if (authmethod == -1 && version > LDAP_VERSION2) {
404 #ifdef HAVE_CYRUS_SASL
405 authmethod = LDAP_AUTH_SASL;
407 authmethod = LDAP_AUTH_SIMPLE;
411 if ( argc != optind )
414 if ( infile != NULL ) {
415 if (( fp = fopen( infile, "r" )) == NULL ) {
417 return( EXIT_FAILURE );
424 if( ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &debug ) != LBER_OPT_SUCCESS ) {
425 fprintf( stderr, "Could not set LBER_OPT_DEBUG_LEVEL %d\n", debug );
427 if( ldap_set_option( NULL, LDAP_OPT_DEBUG_LEVEL, &debug ) != LDAP_OPT_SUCCESS ) {
428 fprintf( stderr, "Could not set LDAP_OPT_DEBUG_LEVEL %d\n", debug );
434 (void) SIGNAL( SIGPIPE, SIG_IGN );
438 if (( ld = ldap_init( ldaphost, ldapport )) == NULL ) {
439 perror( "ldap_init" );
440 return( EXIT_FAILURE );
444 if( ldap_set_option( ld, LDAP_OPT_REFERRALS,
445 referrals ? LDAP_OPT_ON : LDAP_OPT_OFF ) != LDAP_OPT_SUCCESS )
447 fprintf( stderr, "Could not set LDAP_OPT_REFERRALS %s\n",
448 referrals ? "on" : "off" );
453 if (version == -1 ) {
457 if( ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version )
458 != LDAP_OPT_SUCCESS )
460 fprintf( stderr, "Could not set LDAP_OPT_PROTOCOL_VERSION %d\n",
465 if ( use_tls && ldap_start_tls_s( ld, NULL, NULL ) != LDAP_SUCCESS ) {
467 ldap_perror( ld, "ldap_start_tls" );
468 return( EXIT_FAILURE );
470 fprintf( stderr, "WARNING: could not start TLS\n" );
474 passwd.bv_val = getpassphrase("Enter LDAP Password: ");
475 passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
478 if ( authmethod == LDAP_AUTH_SASL ) {
479 #ifdef HAVE_CYRUS_SASL
480 if( sasl_secprops != NULL ) {
481 rc = ldap_set_option( ld, LDAP_OPT_X_SASL_SECPROPS,
482 (void *) sasl_secprops );
484 if( rc != LDAP_OPT_SUCCESS ) {
486 "Could not set LDAP_OPT_X_SASL_SECPROPS: %s\n",
488 return( EXIT_FAILURE );
492 rc = ldap_sasl_interactive_bind_s( ld, binddn,
493 sasl_mech, NULL, NULL, lutil_sasl_interact );
495 if( rc != LDAP_SUCCESS ) {
496 ldap_perror( ld, "ldap_sasl_interactive_bind_s" );
497 return( EXIT_FAILURE );
500 fprintf( stderr, "%s was not compiled with SASL support\n",
502 return( EXIT_FAILURE );
506 if ( ldap_bind_s( ld, binddn, passwd.bv_val, authmethod )
508 ldap_perror( ld, "ldap_bind" );
509 return( EXIT_FAILURE );
520 LDAPControl *ctrls[2];
524 c.ldctl_oid = LDAP_CONTROL_MANAGEDSAIT;
525 c.ldctl_value.bv_val = NULL;
526 c.ldctl_value.bv_len = 0;
527 c.ldctl_iscritical = manageDSAit > 1;
529 err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, &ctrls );
531 if( err != LDAP_OPT_SUCCESS ) {
532 fprintf( stderr, "Could not set ManageDSAit %scontrol\n",
533 c.ldctl_iscritical ? "critical " : "" );
534 if( c.ldctl_iscritical ) {
535 exit( EXIT_FAILURE );
541 while (( rc == 0 || contoper ) &&
542 ( rbuf = read_one_record( fp )) != NULL ) {
547 rc = process_ldif_rec( start, count );
550 fprintf( stderr, "ldif_record() = %d\n", rc );
563 process_ldif_rec( char *rbuf, int count )
565 char *line, *dn, *type, *newrdn, *newsup, *p;
566 int rc, linenum, modop, replicaport;
567 int expect_modop, expect_sep, expect_ct, expect_newrdn, expect_newsup;
568 int expect_deleteoldrdn, deleteoldrdn;
569 int saw_replica, use_record, new_entry, delete_entry, got_all;
576 rc = got_all = saw_replica = delete_entry = modop = expect_modop = 0;
577 expect_deleteoldrdn = expect_newrdn = expect_newsup = 0;
578 expect_sep = expect_ct = 0;
584 dn = newrdn = newsup = NULL;
586 while ( rc == 0 && ( line = ldif_getline( &rbuf )) != NULL ) {
589 if ( expect_sep && strcasecmp( line, T_MODSEPSTR ) == 0 ) {
595 if ( ldif_parse_line( line, &type, &val.bv_val, &val.bv_len ) < 0 ) {
596 fprintf( stderr, "%s: invalid format (line %d) entry: \"%s\"\n",
597 prog, linenum, dn == NULL ? "" : dn );
598 rc = LDAP_PARAM_ERROR;
603 if ( !use_record && strcasecmp( type, T_REPLICA_STR ) == 0 ) {
605 if (( p = strchr( val.bv_val, ':' )) == NULL ) {
609 replicaport = atoi( p );
611 if ( ldaphost != NULL && strcasecmp( val.bv_val, ldaphost ) == 0 &&
612 replicaport == ldapport ) {
615 } else if ( count == 1 && linenum == 1 &&
616 strcasecmp( type, T_VERSION_STR ) == 0 )
618 if( val.bv_len == 0 || atoi(val.bv_val) != 1 ) {
619 fprintf( stderr, "%s: invalid version %s, line %d (ignored)\n",
620 prog, val.bv_val == NULL ? "(null)" : val.bv_val, linenum );
624 } else if ( strcasecmp( type, T_DN_STR ) == 0 ) {
625 if (( dn = strdup( val.bv_val ? val.bv_val : "" )) == NULL ) {
627 exit( EXIT_FAILURE );
631 goto end_line; /* skip all lines until we see "dn:" */
636 if ( !use_record && saw_replica ) {
637 printf( "%s: skipping change record for entry: %s\n"
638 "\t(LDAP host/port does not match replica: lines)\n",
642 ber_memfree( val.bv_val );
646 if ( strcasecmp( type, T_CHANGETYPESTR ) == 0 ) {
647 if ( strcasecmp( val.bv_val, T_MODIFYCTSTR ) == 0 ) {
650 } else if ( strcasecmp( val.bv_val, T_ADDCTSTR ) == 0 ) {
652 } else if ( strcasecmp( val.bv_val, T_MODRDNCTSTR ) == 0
653 || strcasecmp( val.bv_val, T_MODDNCTSTR ) == 0
654 || strcasecmp( val.bv_val, T_RENAMECTSTR ) == 0)
657 } else if ( strcasecmp( val.bv_val, T_DELETECTSTR ) == 0 ) {
658 got_all = delete_entry = 1;
661 "%s: unknown %s \"%s\" (line %d of entry \"%s\")\n",
662 prog, T_CHANGETYPESTR, val.bv_val, linenum, dn );
663 rc = LDAP_PARAM_ERROR;
666 } else if ( ldapadd ) { /* missing changetype => add */
668 modop = LDAP_MOD_ADD;
670 expect_modop = 1; /* missing changetype => modify */
674 if ( expect_modop ) {
677 if ( strcasecmp( type, T_MODOPADDSTR ) == 0 ) {
678 modop = LDAP_MOD_ADD;
680 } else if ( strcasecmp( type, T_MODOPREPLACESTR ) == 0 ) {
681 modop = LDAP_MOD_REPLACE;
682 addmodifyop( &pmods, modop, val.bv_val, NULL );
684 } else if ( strcasecmp( type, T_MODOPDELETESTR ) == 0 ) {
685 modop = LDAP_MOD_DELETE;
686 addmodifyop( &pmods, modop, val.bv_val, NULL );
688 } else { /* no modify op: use default */
689 modop = replace ? LDAP_MOD_REPLACE : LDAP_MOD_ADD;
693 if ( expect_newrdn ) {
694 if ( strcasecmp( type, T_NEWRDNSTR ) == 0 ) {
695 if (( newrdn = strdup( val.bv_val ? val.bv_val : "" )) == NULL ) {
697 exit( EXIT_FAILURE );
699 expect_deleteoldrdn = 1;
702 fprintf( stderr, "%s: expecting \"%s:\" but saw \"%s:\" (line %d of entry \"%s\")\n",
703 prog, T_NEWRDNSTR, type, linenum, dn );
704 rc = LDAP_PARAM_ERROR;
706 } else if ( expect_deleteoldrdn ) {
707 if ( strcasecmp( type, T_DELETEOLDRDNSTR ) == 0 ) {
708 deleteoldrdn = ( *val.bv_val == '0' ) ? 0 : 1;
709 expect_deleteoldrdn = 0;
713 fprintf( stderr, "%s: expecting \"%s:\" but saw \"%s:\" (line %d of entry \"%s\")\n",
714 prog, T_DELETEOLDRDNSTR, type, linenum, dn );
715 rc = LDAP_PARAM_ERROR;
717 } else if ( expect_newsup ) {
718 if ( strcasecmp( type, T_NEWSUPSTR ) == 0 ) {
719 if (( newsup = strdup( val.bv_val ? val.bv_val : "" )) == NULL ) {
721 exit( EXIT_FAILURE );
725 fprintf( stderr, "%s: expecting \"%s:\" but saw \"%s:\" (line %d of entry \"%s\")\n",
726 prog, T_NEWSUPSTR, type, linenum, dn );
727 rc = LDAP_PARAM_ERROR;
729 } else if ( got_all ) {
731 "%s: extra lines at end (line %d of entry \"%s\")\n",
733 rc = LDAP_PARAM_ERROR;
735 addmodifyop( &pmods, modop, type, val.bv_val == NULL ? NULL : &val );
740 ber_memfree( val.bv_val );
747 if( version && linenum == 1 ) {
752 if ( delete_entry ) {
754 } else if ( newrdn != NULL ) {
755 rc = dorename( dn, newrdn, newsup, deleteoldrdn );
757 rc = domodify( dn, pmods, new_entry );
760 if ( rc == LDAP_SUCCESS ) {
768 if ( newrdn != NULL ) {
771 if ( pmods != NULL ) {
772 ldap_mods_free( pmods, 1 );
790 modop |= LDAP_MOD_BVALUES;
793 if ( pmods != NULL ) {
794 for ( ; pmods[ i ] != NULL; ++i ) {
795 if ( strcasecmp( pmods[ i ]->mod_type, attr ) == 0 &&
796 pmods[ i ]->mod_op == modop )
803 if ( pmods == NULL || pmods[ i ] == NULL ) {
804 if (( pmods = (LDAPMod **)ber_memrealloc( pmods, (i + 2) *
805 sizeof( LDAPMod * ))) == NULL )
808 exit( EXIT_FAILURE );
812 pmods[ i + 1 ] = NULL;
814 pmods[ i ] = (LDAPMod *)ber_memcalloc( 1, sizeof( LDAPMod ));
815 if ( pmods[ i ] == NULL ) {
817 exit( EXIT_FAILURE );
820 pmods[ i ]->mod_op = modop;
821 pmods[ i ]->mod_type = ber_strdup( attr );
822 if ( pmods[ i ]->mod_type == NULL ) {
824 exit( EXIT_FAILURE );
830 if ( pmods[ i ]->mod_bvalues != NULL ) {
831 for ( ; pmods[ i ]->mod_bvalues[ j ] != NULL; ++j ) {
836 pmods[ i ]->mod_bvalues = (struct berval **) ber_memrealloc(
837 pmods[ i ]->mod_bvalues, (j + 2) * sizeof( struct berval * ));
838 if ( pmods[ i ]->mod_bvalues == NULL ) {
839 perror( "ber_realloc" );
840 exit( EXIT_FAILURE );
843 pmods[ i ]->mod_bvalues[ j + 1 ] = NULL;
844 pmods[ i ]->mod_bvalues[ j ] = ber_bvdup( val );
845 if ( pmods[ i ]->mod_bvalues[ j ] == NULL ) {
846 perror( "ber_bvdup" );
847 exit( EXIT_FAILURE );
859 int i, j, k, notascii, op;
862 if ( pmods == NULL ) {
863 fprintf( stderr, "%s: no attributes to change or add (entry=\"%s\")\n",
865 return( LDAP_PARAM_ERROR );
869 for ( i = 0; pmods[ i ] != NULL; ++i ) {
870 op = pmods[ i ]->mod_op & ~LDAP_MOD_BVALUES;
871 printf( "%s %s:\n", op == LDAP_MOD_REPLACE ?
872 "replace" : op == LDAP_MOD_ADD ?
873 "add" : "delete", pmods[ i ]->mod_type );
874 if ( pmods[ i ]->mod_bvalues != NULL ) {
875 for ( j = 0; pmods[ i ]->mod_bvalues[ j ] != NULL; ++j ) {
876 bvp = pmods[ i ]->mod_bvalues[ j ];
878 for ( k = 0; (unsigned long) k < bvp->bv_len; ++k ) {
879 if ( !isascii( bvp->bv_val[ k ] )) {
885 printf( "\tNOT ASCII (%ld bytes)\n", bvp->bv_len );
887 printf( "\t%s\n", bvp->bv_val );
895 printf( "%sadding new entry \"%s\"\n", not ? "!" : "", dn );
897 printf( "%smodifying entry \"%s\"\n", not ? "!" : "", dn );
902 i = ldap_add_s( ld, dn, pmods );
904 i = ldap_modify_s( ld, dn, pmods );
906 if ( i != LDAP_SUCCESS ) {
907 ldap_perror( ld, newentry ? "ldap_add" : "ldap_modify" );
908 } else if ( verbose ) {
909 printf( "modify complete\n" );
927 printf( "%sdeleting entry \"%s\"\n", not ? "!" : "", dn );
929 if (( rc = ldap_delete_s( ld, dn )) != LDAP_SUCCESS ) {
930 ldap_perror( ld, "ldap_delete" );
931 } else if ( verbose ) {
932 printf( "delete complete" );
954 printf( "%smodifying rdn of entry \"%s\"\n", not ? "!" : "", dn );
956 printf( "\tnew RDN: \"%s\" (%skeep existing values)\n",
957 newrdn, deleteoldrdn ? "do not " : "" );
960 if (( rc = ldap_rename2_s( ld, dn, newrdn, newsup, deleteoldrdn ))
962 ldap_perror( ld, "ldap_modrdn" );
964 printf( "modrdn completed\n" );
977 read_one_record( FILE *fp )
979 char *buf, line[ LDAPMOD_MAXLINE ];
985 while ( fgets( line, sizeof(line), fp ) != NULL ) {
986 int len = strlen( line );
996 if ( lcur + len + 1 > lmax ) {
997 lmax = LDAPMOD_MAXLINE
998 * (( lcur + len + 1 ) / LDAPMOD_MAXLINE + 1 );
1000 if (( buf = (char *)realloc( buf, lmax )) == NULL ) {
1001 perror( "realloc" );
1002 exit( EXIT_FAILURE );
1006 strcpy( buf + lcur, line );