From: Howard Chu Date: Tue, 27 Feb 2024 13:13:25 +0000 (+0000) Subject: ITS#10183 ldapmodify: add jump to lineno option X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=01a1c1293b129721aab432f164b276b07d3b0917;p=thirdparty%2Fopenldap.git ITS#10183 ldapmodify: add jump to lineno option --- diff --git a/clients/tools/ldapmodify.c b/clients/tools/ldapmodify.c index 53888d8727..f6e6b4d777 100644 --- a/clients/tools/ldapmodify.c +++ b/clients/tools/ldapmodify.c @@ -99,6 +99,7 @@ static struct timeval interval_tv; static int txn = 0; static int txnabort = 0; struct berval *txn_id = NULL; +static unsigned long jumpline; void usage( void ) @@ -116,6 +117,7 @@ usage( void ) " (! indicate s criticality)\n")); fprintf( stderr, _(" -f file read operations from `file'\n")); fprintf( stderr, _(" -i time wait `time' microseconds between operations\n")); + fprintf( stderr, _(" -j lineno jump to lineno before processing\n")); fprintf( stderr, _(" -M enable Manage DSA IT control (-MM to make critical)\n")); fprintf( stderr, _(" -P version protocol version (default: 3)\n")); fprintf( stderr, @@ -128,7 +130,7 @@ usage( void ) const char options[] = "aE:rS:" - "cd:D:e:f:H:i:IMnNO:o:P:QR:U:vVw:WxX:y:Y:Z"; + "cd:D:e:f:H:i:Ij:MnNO:o:P:QR:U:vVw:WxX:y:Y:Z"; int handle_private_option( int i ) @@ -203,6 +205,17 @@ handle_private_option( int i ) } break; + case 'j': /* jump */ + { + char *next; + jumpline = strtoul( optarg, &next, 10 ); + if ( !next || *next ) { + fprintf( stderr, "%s: unable to parse jump line number \"%s\"\n", prog, optarg); + exit(EXIT_FAILURE); + } + } + break; + case 'r': /* replace (obsolete) */ break; @@ -302,6 +315,9 @@ main( int argc, char **argv ) while (( rc == 0 || contoper ) && ( ldifrc = ldif_read_record( ldiffp, &nextline, &rbuf, &lmax )) > 0 ) { + if ( lineno < jumpline ) + goto next; + if ( rejfp ) { len = strlen( rbuf ); if (( rejbuf = (char *)ber_memalloc( len+1 )) == NULL ) { @@ -317,11 +333,10 @@ main( int argc, char **argv ) } rc = process_ldif_rec( rbuf, lineno ); - lineno = nextline+1; if ( rc ) retval = rc; if ( rc && rejfp ) { - fprintf(rejfp, _("# Error: %s (%d)"), ldap_err2string(rc), rc); + fprintf(rejfp, _("# Error: %s (%d) (line=%lu)"), ldap_err2string(rc), rc, lineno); matched_msg = NULL; ldap_get_option(ld, LDAP_OPT_MATCHED_DN, &matched_msg); @@ -344,6 +359,9 @@ main( int argc, char **argv ) } if (rejfp) ber_memfree( rejbuf ); + +next: + lineno = nextline+1; } ber_memfree( rbuf ); diff --git a/doc/man/man1/ldapmodify.1 b/doc/man/man1/ldapmodify.1 index 715ed8dcea..e012938461 100644 --- a/doc/man/man1/ldapmodify.1 +++ b/doc/man/man1/ldapmodify.1 @@ -23,6 +23,8 @@ ldapmodify, ldapadd \- LDAP modify entry and LDAP add entry tools [\c .BI \-i \ time\fR] [\c +.BI \-j \ lineno\fR] +[\c .BI \-S \ file\fR] [\c .BR \-M [ M ]] @@ -81,6 +83,8 @@ ldapmodify, ldapadd \- LDAP modify entry and LDAP add entry tools [\c .BI \-i \ time\fR] [\c +.BI \-j \ lineno\fR] +[\c .BI \-S \ file\fR] [\c .BR \-M [ M ]] @@ -178,6 +182,11 @@ standard input. .BI \-i \ time Wait \fItime\fP microseconds before issuing an operation. .TP +.BI \-j \ lineno +Jump to the specified line number in the LDIF file before processing any entries. +This allows a load that was aborted due to errors in the input LDIF to be resumed +after the errors are corrected. +.TP .BI \-S \ file Add or change records which were skipped due to an error are written to \fIfile\fP and the error message returned by the server is added as a comment. Most useful in