3 * Copyright 1998-2003 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>
14 #include <ac/string.h>
15 #include <ac/unistd.h>
17 #ifdef HAVE_SYS_STAT_H
21 #ifdef HAVE_SYS_FILE_H
31 #include "lutil_ldap.h"
33 #include "ldap_defaults.h"
40 static int ldapadd, force = 0;
41 static char *rejfile = NULL;
42 static LDAP *ld = NULL;
44 #define LDAPMOD_MAXLINE 4096
46 /* strings found in replog/LDIF entries (mostly lifted from slurpd/slurp.h) */
47 #define T_VERSION_STR "version"
48 #define T_REPLICA_STR "replica"
50 #define T_CONTROL_STR "control"
51 #define T_CHANGETYPESTR "changetype"
52 #define T_ADDCTSTR "add"
53 #define T_MODIFYCTSTR "modify"
54 #define T_DELETECTSTR "delete"
55 #define T_MODRDNCTSTR "modrdn"
56 #define T_MODDNCTSTR "moddn"
57 #define T_RENAMECTSTR "rename"
58 #define T_MODOPADDSTR "add"
59 #define T_MODOPREPLACESTR "replace"
60 #define T_MODOPDELETESTR "delete"
61 #define T_MODOPINCREMENTSTR "increment"
62 #define T_MODSEPSTR "-"
63 #define T_NEWRDNSTR "newrdn"
64 #define T_DELETEOLDRDNSTR "deleteoldrdn"
65 #define T_NEWSUPSTR "newsuperior"
68 static int process_ldif_rec LDAP_P(( char *rbuf, int count ));
69 static int parse_ldif_control LDAP_P(( char *line, LDAPControl ***pctrls ));
70 static void addmodifyop LDAP_P((
71 LDAPMod ***pmodsp, int modop,
73 struct berval *value ));
74 static int domodify LDAP_P((
79 static int dodelete LDAP_P((
81 LDAPControl **pctrls ));
82 static int dorename LDAP_P((
87 LDAPControl **pctrls ));
88 static char *read_one_record LDAP_P(( FILE *fp ));
93 fprintf( stderr, _("Add or modify entries from an LDAP server\n\n"));
94 fprintf( stderr, _("usage: %s [options]\n"), prog);
95 fprintf( stderr, _(" The list of desired operations are read from stdin or from the file\n"));
96 fprintf( stderr, _(" specified by \"-f file\".\n"));
97 fprintf( stderr, _("Add or modify options:\n"));
98 fprintf( stderr, _(" -a add values (%s)\n"),
99 (ldapadd ? _("default") : _("default is to replace")));
100 fprintf( stderr, _(" -F force all changes records to be used\n"));
101 fprintf( stderr, _(" -S file write skipped modifications to `file'\n"));
103 exit( EXIT_FAILURE );
107 const char options[] = "aFrS:"
108 "cCd:D:e:f:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z";
111 handle_private_option( int i )
115 char *control, *cvalue;
117 case 'E': /* modify controls */
118 if( protocol == LDAP_VERSION2 ) {
119 fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"),
121 exit( EXIT_FAILURE );
124 /* should be extended to support comma separated list of
125 * [!]key[=value] parameters, e.g. -E !foo,bar=567
130 if( optarg[0] == '!' ) {
135 control = ber_strdup( optarg );
136 if ( (cvalue = strchr( control, '=' )) != NULL ) {
139 fprintf( stderr, _("Invalid modify control name: %s\n"), control );
147 case 'F': /* force all changes records to be used */
151 case 'r': /* replace (obsolete) */
154 case 'S': /* skipped modifications to file */
155 if( rejfile != NULL ) {
156 fprintf( stderr, _("%s: -S previously specified\n"), prog );
157 exit( EXIT_FAILURE );
159 rejfile = ber_strdup( optarg );
170 main( int argc, char **argv )
172 char *rbuf, *start, *rejbuf = NULL;
174 char *matched_msg, *error_msg;
179 prog = lutil_progname( "ldapmodify", argc, argv );
181 /* strncmp instead of strcmp since NT binaries carry .exe extension */
182 ldapadd = ( strncasecmp( prog, "ldapadd", sizeof("ldapadd")-1 ) == 0 );
184 /* Print usage when no parameters */
185 if( argc < 2 ) usage();
187 tool_args( argc, argv );
189 if ( argc != optind ) usage();
191 if ( rejfile != NULL ) {
192 if (( rejfp = fopen( rejfile, "w" )) == NULL ) {
194 return( EXIT_FAILURE );
200 if ( infile != NULL ) {
201 if (( fp = fopen( infile, "r" )) == NULL ) {
203 return( EXIT_FAILURE );
209 if ( debug ) ldif_debug = debug;
211 ld = tool_conn_setup( not, 0 );
214 if ( pw_file || want_bindpw ) {
216 rc = lutil_get_filed_password( pw_file, &passwd );
217 if( rc ) return EXIT_FAILURE;
219 passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
220 passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
228 if ( assertion || authzid || manageDSAit || noop || preread || postread ) {
229 tool_server_controls( ld, NULL, 0 );
234 while (( rc == 0 || contoper ) &&
235 ( rbuf = read_one_record( fp )) != NULL )
242 len = strlen( rbuf );
243 if (( rejbuf = (char *)ber_memalloc( len+1 )) == NULL ) {
245 exit( EXIT_FAILURE );
247 memcpy( rejbuf, rbuf, len+1 );
250 rc = process_ldif_rec( start, count );
252 if ( rc ) retval = rc;
254 fprintf(rejfp, _("# Error: %s (%d)"), ldap_err2string(rc), rc);
257 ldap_get_option(ld, LDAP_OPT_MATCHED_DN, &matched_msg);
258 if ( matched_msg != NULL ) {
259 if ( *matched_msg != '\0' ) {
260 fprintf( rejfp, _(", matched DN: %s"), matched_msg );
262 ldap_memfree( matched_msg );
266 ldap_get_option(ld, LDAP_OPT_ERROR_STRING, &error_msg);
267 if ( error_msg != NULL ) {
268 if ( *error_msg != '\0' ) {
269 fprintf( rejfp, _(", additional info: %s"), error_msg );
271 ldap_memfree( error_msg );
273 fprintf( rejfp, "\n%s\n", rejbuf );
276 if (rejfp) free( rejbuf );
284 if ( rejfp != NULL ) {
293 process_ldif_rec( char *rbuf, int count )
295 char *line, *dn, *type, *newrdn, *newsup, *p;
296 int rc, linenum, modop, replicaport;
297 int expect_modop, expect_sep, expect_ct, expect_newrdn, expect_newsup;
298 int expect_deleteoldrdn, deleteoldrdn;
299 int saw_replica, use_record, new_entry, delete_entry, got_all;
303 LDAPControl **pctrls;
307 rc = got_all = saw_replica = delete_entry = modop = expect_modop = 0;
308 expect_deleteoldrdn = expect_newrdn = expect_newsup = 0;
309 expect_sep = expect_ct = 0;
316 dn = newrdn = newsup = NULL;
318 while ( rc == 0 && ( line = ldif_getline( &rbuf )) != NULL ) {
321 if ( expect_sep && strcasecmp( line, T_MODSEPSTR ) == 0 ) {
327 if ( ldif_parse_line( line, &type, &val.bv_val, &val.bv_len ) < 0 ) {
328 fprintf( stderr, _("%s: invalid format (line %d) entry: \"%s\"\n"),
329 prog, linenum, dn == NULL ? "" : dn );
330 rc = LDAP_PARAM_ERROR;
335 if ( !use_record && strcasecmp( type, T_REPLICA_STR ) == 0 ) {
337 if (( p = strchr( val.bv_val, ':' )) == NULL ) {
341 replicaport = atoi( p );
343 if ( ldaphost != NULL && strcasecmp( val.bv_val, ldaphost ) == 0 &&
344 replicaport == ldapport ) {
347 } else if ( count == 1 && linenum == 1 &&
348 strcasecmp( type, T_VERSION_STR ) == 0 )
350 if( val.bv_len == 0 || atoi(val.bv_val) != 1 ) {
351 fprintf( stderr, _("%s: invalid version %s, line %d (ignored)\n"),
352 prog, val.bv_val, linenum );
356 } else if ( strcasecmp( type, T_DN_STR ) == 0 ) {
357 if (( dn = ber_strdup( val.bv_val )) == NULL ) {
359 exit( EXIT_FAILURE );
363 goto end_line; /* skip all lines until we see "dn:" */
368 /* Check for "control" tag after dn and before changetype. */
369 if (strcasecmp(type, T_CONTROL_STR) == 0) {
370 /* Parse and add it to the list of controls */
371 rc = parse_ldif_control( line, &pctrls );
373 fprintf( stderr, _("%s: Error processing %s line, line %d: %s\n"),
374 prog, T_CONTROL_STR, linenum, ldap_err2string(rc) );
380 if ( !use_record && saw_replica ) {
381 printf(_("%s: skipping change record for entry: %s\n"), prog, dn);
382 printf(_("\t(LDAP host/port does not match replica: lines)\n"));
385 ber_memfree( val.bv_val );
389 if ( strcasecmp( type, T_CHANGETYPESTR ) == 0 ) {
390 #ifdef LIBERAL_CHANGETYPE_MODOP
391 /* trim trailing spaces (and log warning ...) */
394 for ( icnt = val.bv_len; --icnt > 0; ) {
395 if ( !isspace( (unsigned char) val.bv_val[icnt] ) ) {
400 if ( ++icnt != val.bv_len ) {
401 fprintf( stderr, _("%s: illegal trailing space after \"%s: %s\" trimmed (line %d of entry \"%s\")\n"),
402 prog, T_CHANGETYPESTR, val.bv_val, linenum, dn );
403 val.bv_val[icnt] = '\0';
405 #endif /* LIBERAL_CHANGETYPE_MODOP */
407 if ( strcasecmp( val.bv_val, T_MODIFYCTSTR ) == 0 ) {
410 } else if ( strcasecmp( val.bv_val, T_ADDCTSTR ) == 0 ) {
412 } else if ( strcasecmp( val.bv_val, T_MODRDNCTSTR ) == 0
413 || strcasecmp( val.bv_val, T_MODDNCTSTR ) == 0
414 || strcasecmp( val.bv_val, T_RENAMECTSTR ) == 0)
417 } else if ( strcasecmp( val.bv_val, T_DELETECTSTR ) == 0 ) {
418 got_all = delete_entry = 1;
421 _("%s: unknown %s \"%s\" (line %d of entry \"%s\")\n"),
422 prog, T_CHANGETYPESTR, val.bv_val, linenum, dn );
423 rc = LDAP_PARAM_ERROR;
426 } else if ( ldapadd ) { /* missing changetype => add */
428 modop = LDAP_MOD_ADD;
430 expect_modop = 1; /* missing changetype => modify */
434 if ( expect_modop ) {
435 #ifdef LIBERAL_CHANGETYPE_MODOP
436 /* trim trailing spaces (and log warning ...) */
439 for ( icnt = val.bv_len; --icnt > 0; ) {
440 if ( !isspace( (unsigned char) val.bv_val[icnt] ) ) {
445 if ( ++icnt != val.bv_len ) {
446 fprintf( stderr, _("%s: illegal trailing space after \"%s: %s\" trimmed (line %d of entry \"%s\")\n"),
447 prog, type, val.bv_val, linenum, dn );
448 val.bv_val[icnt] = '\0';
450 #endif /* LIBERAL_CHANGETYPE_MODOP */
454 if ( strcasecmp( type, T_MODOPADDSTR ) == 0 ) {
455 modop = LDAP_MOD_ADD;
457 } else if ( strcasecmp( type, T_MODOPREPLACESTR ) == 0 ) {
458 modop = LDAP_MOD_REPLACE;
459 addmodifyop( &pmods, modop, val.bv_val, NULL );
461 } else if ( strcasecmp( type, T_MODOPDELETESTR ) == 0 ) {
462 modop = LDAP_MOD_DELETE;
463 addmodifyop( &pmods, modop, val.bv_val, NULL );
465 } else if ( strcasecmp( type, T_MODOPINCREMENTSTR ) == 0 ) {
466 modop = LDAP_MOD_INCREMENT;
467 addmodifyop( &pmods, modop, val.bv_val, NULL );
469 } else { /* no modify op: use default */
470 modop = ldapadd ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
474 if ( expect_newrdn ) {
475 if ( strcasecmp( type, T_NEWRDNSTR ) == 0 ) {
476 if (( newrdn = ber_strdup( val.bv_val )) == NULL ) {
478 exit( EXIT_FAILURE );
480 expect_deleteoldrdn = 1;
483 fprintf( stderr, _("%s: expecting \"%s:\" but saw \"%s:\" (line %d of entry \"%s\")\n"),
484 prog, T_NEWRDNSTR, type, linenum, dn );
485 rc = LDAP_PARAM_ERROR;
487 } else if ( expect_deleteoldrdn ) {
488 if ( strcasecmp( type, T_DELETEOLDRDNSTR ) == 0 ) {
489 deleteoldrdn = ( *val.bv_val == '0' ) ? 0 : 1;
490 expect_deleteoldrdn = 0;
494 fprintf( stderr, _("%s: expecting \"%s:\" but saw \"%s:\" (line %d of entry \"%s\")\n"),
495 prog, T_DELETEOLDRDNSTR, type, linenum, dn );
496 rc = LDAP_PARAM_ERROR;
498 } else if ( expect_newsup ) {
499 if ( strcasecmp( type, T_NEWSUPSTR ) == 0 ) {
500 if (( newsup = ber_strdup( val.bv_val )) == NULL ) {
502 exit( EXIT_FAILURE );
506 fprintf( stderr, _("%s: expecting \"%s:\" but saw \"%s:\" (line %d of entry \"%s\")\n"),
507 prog, T_NEWSUPSTR, type, linenum, dn );
508 rc = LDAP_PARAM_ERROR;
510 } else if ( got_all ) {
512 _("%s: extra lines at end (line %d of entry \"%s\")\n"),
514 rc = LDAP_PARAM_ERROR;
516 addmodifyop( &pmods, modop, type, &val );
521 ber_memfree( val.bv_val );
528 if( version && linenum == 1 ) {
532 /* If default controls are set (as with -M option) and controls are
533 specified in the LDIF file, we must add the default controls to
534 the list of controls sent with the ldap operation.
538 LDAPControl **defctrls = NULL; /* Default server controls */
539 LDAPControl **newctrls = NULL;
540 ldap_get_option(ld, LDAP_OPT_SERVER_CONTROLS, &defctrls);
542 int npc=0; /* Number of LDIF controls */
543 int ndefc=0; /* Number of default controls */
544 while (pctrls[npc]) /* Count LDIF controls */
546 while (defctrls[ndefc]) /* Count default controls */
548 newctrls = ber_memrealloc(pctrls, (npc+ndefc+1)*sizeof(LDAPControl*));
549 if (newctrls == NULL)
554 for (i=npc; i<npc+ndefc; i++) {
555 pctrls[i] = ldap_control_dup(defctrls[i-npc]);
556 if (pctrls[i] == NULL) {
561 pctrls[npc+ndefc] = NULL;
563 ldap_controls_free(defctrls); /* Must be freed by library */
570 if ( delete_entry ) {
571 rc = dodelete( dn, pctrls );
572 } else if ( newrdn != NULL ) {
573 rc = dorename( dn, newrdn, newsup, deleteoldrdn, pctrls );
575 rc = domodify( dn, pmods, pctrls, new_entry );
578 if ( rc == LDAP_SUCCESS ) {
586 if ( newrdn != NULL ) {
589 if ( pmods != NULL ) {
590 ldap_mods_free( pmods, 1 );
593 if (pctrls != NULL) {
594 ldap_controls_free( pctrls );
600 /* Parse an LDIF control line of the form
601 control: oid [true/false] [: value] or
602 control: oid [true/false] [:: base64-value] or
603 control: oid [true/false] [:< url]
604 The control is added to the list of controls in *ppctrls.
607 parse_ldif_control( char *line,
608 LDAPControl ***ppctrls )
611 int criticality = 0; /* Default is false if not present */
614 ber_len_t value_len = 0;
616 char *s, *oidStart, *pcolon;
617 LDAPControl *newctrl = NULL;
618 LDAPControl **pctrls = NULL;
623 s = line + strlen(T_CONTROL_STR); /* Skip over "control" */
624 pcolon = s; /* Save this position for later */
625 if (*s++ != ':') /* Make sure colon follows */
626 return ( LDAP_PARAM_ERROR );
627 while (*s && isspace((unsigned char)*s))
628 s++; /* Skip white space before OID */
630 /* OID should come next. Validate and extract it. */
632 return ( LDAP_PARAM_ERROR );
634 while (isdigit((unsigned char)*s) || *s == '.')
635 s++; /* OID should be digits or . */
637 return ( LDAP_PARAM_ERROR ); /* OID was not present */
638 if (*s) { /* End of OID should be space or NULL */
639 if (!isspace((unsigned char)*s))
640 return ( LDAP_PARAM_ERROR ); /* else OID contained invalid chars */
641 *s++ = 0; /* Replace space with null to terminate */
645 oid = ber_strdup(oidStart);
647 return ( LDAP_NO_MEMORY );
649 /* Optional Criticality field is next. */
650 while (*s && isspace((unsigned char)*s))
651 s++; /* Skip white space before criticality */
652 if (strncasecmp(s, "true", 4) == 0) {
656 else if (strncasecmp(s, "false", 5) == 0) {
661 /* Optional value field is next */
662 while (*s && isspace((unsigned char)*s))
663 s++; /* Skip white space before value */
665 if (*s != ':') { /* If value is present, must start with : */
666 rc = LDAP_PARAM_ERROR;
670 /* Shift value down over OID and criticality so it's in the form
672 control:: base64-value
674 Then we can use ldif_parse_line to extract and decode the value
676 while ( (*pcolon++ = *s++) != 0) /* Shift value */
678 rc = ldif_parse_line(line, &type, &val, &value_len);
679 if (type) ber_memfree(type); /* Don't need this field*/
681 rc = LDAP_PARAM_ERROR;
686 /* Create a new LDAPControl structure. */
687 newctrl = (LDAPControl *)ber_memalloc(sizeof(LDAPControl));
688 if ( newctrl == NULL ) {
692 newctrl->ldctl_oid = oid;
694 newctrl->ldctl_iscritical = criticality;
695 newctrl->ldctl_value.bv_len = value_len;
696 newctrl->ldctl_value.bv_val = val;
699 /* Add the new control to the passed-in list of controls. */
702 while ( pctrls[i] ) /* Count the # of controls passed in */
705 /* Allocate 1 more slot for the new control and 1 for the NULL. */
706 pctrls = (LDAPControl **)ber_memrealloc(pctrls, (i+2)*(sizeof(LDAPControl *)));
707 if (pctrls == NULL) {
718 if (newctrl->ldctl_oid)
719 ber_memfree(newctrl->ldctl_oid);
720 if (newctrl->ldctl_value.bv_val)
721 ber_memfree(newctrl->ldctl_value.bv_val);
722 ber_memfree(newctrl);
744 modop |= LDAP_MOD_BVALUES;
747 if ( pmods != NULL ) {
748 for ( ; pmods[ i ] != NULL; ++i ) {
749 if ( strcasecmp( pmods[ i ]->mod_type, attr ) == 0 &&
750 pmods[ i ]->mod_op == modop )
757 if ( pmods == NULL || pmods[ i ] == NULL ) {
758 if (( pmods = (LDAPMod **)ber_memrealloc( pmods, (i + 2) *
759 sizeof( LDAPMod * ))) == NULL )
762 exit( EXIT_FAILURE );
766 pmods[ i + 1 ] = NULL;
768 pmods[ i ] = (LDAPMod *)ber_memcalloc( 1, sizeof( LDAPMod ));
769 if ( pmods[ i ] == NULL ) {
771 exit( EXIT_FAILURE );
774 pmods[ i ]->mod_op = modop;
775 pmods[ i ]->mod_type = ber_strdup( attr );
776 if ( pmods[ i ]->mod_type == NULL ) {
778 exit( EXIT_FAILURE );
784 if ( pmods[ i ]->mod_bvalues != NULL ) {
785 for ( ; pmods[ i ]->mod_bvalues[ j ] != NULL; ++j ) {
790 pmods[ i ]->mod_bvalues = (struct berval **) ber_memrealloc(
791 pmods[ i ]->mod_bvalues, (j + 2) * sizeof( struct berval * ));
792 if ( pmods[ i ]->mod_bvalues == NULL ) {
793 perror( "ber_realloc" );
794 exit( EXIT_FAILURE );
797 pmods[ i ]->mod_bvalues[ j + 1 ] = NULL;
798 pmods[ i ]->mod_bvalues[ j ] = ber_bvdup( val );
799 if ( pmods[ i ]->mod_bvalues[ j ] == NULL ) {
800 perror( "ber_bvdup" );
801 exit( EXIT_FAILURE );
811 LDAPControl **pctrls,
814 int i, j, k, notascii, op;
818 fprintf( stderr, _("%s: no DN specified\n"), prog );
819 return( LDAP_PARAM_ERROR );
822 if ( pmods == NULL ) {
823 fprintf( stderr, _("%s: no attributes to change or add (entry=\"%s\")\n"),
825 return( LDAP_PARAM_ERROR );
828 for ( i = 0; pmods[ i ] != NULL; ++i ) {
829 op = pmods[ i ]->mod_op & ~LDAP_MOD_BVALUES;
830 if( op == LDAP_MOD_ADD && ( pmods[i]->mod_bvalues == NULL )) {
832 _("%s: attribute \"%s\" has no values (entry=\"%s\")\n"),
833 prog, pmods[i]->mod_type, dn );
834 return LDAP_PARAM_ERROR;
839 for ( i = 0; pmods[ i ] != NULL; ++i ) {
840 op = pmods[ i ]->mod_op & ~LDAP_MOD_BVALUES;
842 op == LDAP_MOD_REPLACE ? _("replace") :
843 op == LDAP_MOD_ADD ? _("add") :
844 op == LDAP_MOD_INCREMENT ? _("increment") :
845 op == LDAP_MOD_DELETE ? _("delete") :
847 pmods[ i ]->mod_type );
848 if ( pmods[ i ]->mod_bvalues != NULL ) {
849 for ( j = 0; pmods[ i ]->mod_bvalues[ j ] != NULL; ++j ) {
850 bvp = pmods[ i ]->mod_bvalues[ j ];
852 for ( k = 0; (unsigned long) k < bvp->bv_len; ++k ) {
853 if ( !isascii( bvp->bv_val[ k ] )) {
859 printf( _("\tNOT ASCII (%ld bytes)\n"), bvp->bv_len );
861 printf( "\t%s\n", bvp->bv_val );
869 printf( "%sadding new entry \"%s\"\n", not ? "!" : "", dn );
871 printf( "%smodifying entry \"%s\"\n", not ? "!" : "", dn );
876 i = ldap_add_ext_s( ld, dn, pmods, pctrls, NULL );
878 i = ldap_modify_ext_s( ld, dn, pmods, pctrls, NULL );
880 if ( i != LDAP_SUCCESS ) {
881 /* print error message about failed update including DN */
882 fprintf( stderr, _("%s: update failed: %s\n"), prog, dn );
883 ldap_perror( ld, newentry ? "ldap_add" : "ldap_modify" );
884 } else if ( verbose ) {
885 printf( _("modify complete\n") );
900 LDAPControl **pctrls )
904 printf( _("%sdeleting entry \"%s\"\n"), not ? "!" : "", dn );
906 if (( rc = ldap_delete_ext_s( ld, dn, pctrls, NULL )) != LDAP_SUCCESS ) {
907 fprintf( stderr, _("%s: delete failed: %s\n"), prog, dn );
908 ldap_perror( ld, "ldap_delete" );
909 } else if ( verbose ) {
910 printf( _("delete complete") );
928 LDAPControl **pctrls )
933 printf( _("%smodifying rdn of entry \"%s\"\n"), not ? "!" : "", dn );
935 printf( _("\tnew RDN: \"%s\" (%skeep existing values)\n"),
936 newrdn, deleteoldrdn ? _("do not ") : "" );
939 if (( rc = ldap_rename_s( ld, dn, newrdn, newsup, deleteoldrdn, pctrls, NULL ))
941 fprintf( stderr, _("%s: rename failed: %s\n"), prog, dn );
942 ldap_perror( ld, "ldap_modrdn" );
944 printf( _("modrdn completed\n") );
957 read_one_record( FILE *fp )
959 char *buf, line[ LDAPMOD_MAXLINE ];
965 while ( fgets( line, sizeof(line), fp ) != NULL ) {
966 int len = strlen( line );
968 if( len < 2 || ( len == 2 && *line == '\r' )) {
976 if ( lcur + len + 1 > lmax ) {
977 lmax = LDAPMOD_MAXLINE
978 * (( lcur + len + 1 ) / LDAPMOD_MAXLINE + 1 );
980 if (( buf = (char *)ber_memrealloc( buf, lmax )) == NULL ) {
982 exit( EXIT_FAILURE );
986 strcpy( buf + lcur, line );