From: Howard Chu Date: Tue, 27 Feb 2024 13:13:25 +0000 (+0000) Subject: ITS#10183 ldapmodify: add jump to lineno option X-Git-Tag: OPENLDAP_REL_ENG_2_6_8~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6eb993c57f9317a25874b477099000edf6aa3553;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 c218ccad48..032e4e1479 100644 --- a/clients/tools/ldapmodify.c +++ b/clients/tools/ldapmodify.c @@ -97,6 +97,7 @@ static int process_response( static int txn = 0; static int txnabort = 0; struct berval *txn_id = NULL; +static unsigned long jumpline; void usage( void ) @@ -113,6 +114,7 @@ usage( void ) fprintf( stderr, _(" -E [!]ext=extparam modify extensions" " (! indicate s criticality)\n")); fprintf( stderr, _(" -f file read operations from `file'\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, @@ -125,7 +127,7 @@ usage( void ) const char options[] = "aE:rS:" - "cd:D:e:f:H:IMnNO:o:P:QR:U:vVw:WxX:y:Y:Z"; + "cd:D:e:f:H:Ij:MnNO:o:P:QR:U:vVw:WxX:y:Y:Z"; int handle_private_option( int i ) @@ -187,6 +189,17 @@ handle_private_option( int i ) ldapadd = 1; 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; @@ -286,6 +299,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 ) { @@ -297,11 +313,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); @@ -324,6 +339,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 2649060298..cf63609fb6 100644 --- a/doc/man/man1/ldapmodify.1 +++ b/doc/man/man1/ldapmodify.1 @@ -21,6 +21,8 @@ ldapmodify, ldapadd \- LDAP modify entry and LDAP add entry tools [\c .BI \-f \ file\fR] [\c +.BI \-j \ lineno\fR] +[\c .BI \-S \ file\fR] [\c .BR \-M [ M ]] @@ -77,6 +79,8 @@ ldapmodify, ldapadd \- LDAP modify entry and LDAP add entry tools [\c .BI \-f \ file\fR] [\c +.BI \-j \ lineno\fR] +[\c .BI \-S \ file\fR] [\c .BR \-M [ M ]] @@ -171,6 +175,11 @@ reporting an error. Read the entry modification information from \fIfile\fP instead of from standard input. .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