]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#10183 ldapmodify: add jump to lineno option
authorHoward Chu <hyc@openldap.org>
Tue, 27 Feb 2024 13:13:25 +0000 (13:13 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Tue, 7 May 2024 16:30:19 +0000 (16:30 +0000)
clients/tools/ldapmodify.c
doc/man/man1/ldapmodify.1

index c218ccad48d31a02fd869db5cffd32339a2f3d49..032e4e1479c48d872444ffc6f7006a68637f5d93 100644 (file)
@@ -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 );
 
index 2649060298f695cf35b5e940aff355f4625d9634..cf63609fb642c80c519bdeb61157b1e9abf2a3de 100644 (file)
@@ -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