From 91088eaa84923ec77c6cf14140d4d63cd3092bf2 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Thu, 6 Jun 2002 00:31:09 +0000 Subject: [PATCH] Full_Name: Norbert Klasen Version: head OS: SuSE Linux 7.3 URL: ftp://ftp.openldap.org/incoming/norbert.klasen.rejects.20020605.patch Submission from: (NULL) (62.104.216.66) This patch adds an '-S' option to ldapmodify. If a filename is specified with this option, records which could not successfully be added/modified/deleted from the LDAP server will be written to the specified file. Most useful in conjunction with '-c' option. --- clients/tools/ldapmodify.c | 62 +++++++++++++++++++++++++++++++++----- doc/devel/args | 2 +- doc/man/man1/ldapmodify.1 | 9 ++++++ 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/clients/tools/ldapmodify.c b/clients/tools/ldapmodify.c index f55cb80aa1..427952c5fa 100644 --- a/clients/tools/ldapmodify.c +++ b/clients/tools/ldapmodify.c @@ -103,12 +103,14 @@ usage( const char *prog ) " specified by \"-f file\".\n" "Add or modify options:\n" " -a add values (default%s)\n" +" -c continuous operation mode (do not stop on errors)\n" +" -f file read operations from `file'\n" " -F force all changes records to be used\n" +" -S file write skipped modifications to `file'\n" "Common options:\n" " -d level set LDAP debugging level to `level'\n" " -D binddn bind DN\n" -" -f file read operations from `file'\n" " -h host LDAP server\n" " -H URI LDAP Uniform Resource Indentifier(s)\n" " -I use SASL Interactive mode\n" @@ -138,10 +140,11 @@ usage( const char *prog ) int main( int argc, char **argv ) { - char *infile, *rbuf, *start; - FILE *fp; + char *infile, *rejfile, *rbuf, *start, *rejbuf; + FILE *fp, *rejfp; + char *matched_msg = NULL, *error_msg = NULL; int rc, i, authmethod, version, want_bindpw, debug, manageDSAit, referrals; - int count; + int count, len; if (( prog = strrchr( argv[ 0 ], *LDAP_DIRSEP )) == NULL ) { prog = argv[ 0 ]; @@ -156,12 +159,13 @@ main( int argc, char **argv ) ldapadd = ( strncmp( prog, "ldapadd", sizeof("ldapadd")-1 ) == 0 ); infile = NULL; + rejfile = NULL; not = verbose = want_bindpw = debug = manageDSAit = referrals = 0; authmethod = -1; version = -1; while (( i = getopt( argc, argv, "acrf:F" - "Cd:D:h:H:IkKMnO:p:P:QR:U:vw:WxX:Y:Z" )) != EOF ) + "Cd:D:h:H:IkKMnO:p:P:QR:S:U:vw:WxX:Y:Z" )) != EOF ) { switch( i ) { /* Modify Options */ @@ -403,6 +407,13 @@ main( int argc, char **argv ) return( EXIT_FAILURE ); #endif break; + case 'S': /* skipped modifications to file */ + if( rejfile != NULL ) { + fprintf( stderr, "%s: -S previously specified\n", prog ); + return EXIT_FAILURE; + } + rejfile = strdup( optarg ); + break; case 'U': #ifdef HAVE_CYRUS_SASL if( sasl_authc_id != NULL ) { @@ -539,6 +550,15 @@ main( int argc, char **argv ) if ( argc != optind ) usage( prog ); + if ( rejfile != NULL ) { + if (( rejfp = fopen( rejfile, "w" )) == NULL ) { + perror( rejfile ); + return( EXIT_FAILURE ); + } + } else { + rejfp = NULL; + } + if ( infile != NULL ) { if (( fp = fopen( infile, "r" )) == NULL ) { perror( infile ); @@ -671,6 +691,7 @@ main( int argc, char **argv ) ldap_perror( ld, "ldap_bind" ); return( EXIT_FAILURE ); } + } } @@ -707,10 +728,33 @@ main( int argc, char **argv ) start = rbuf; + if ( rejfp ) { + len = strlen( rbuf ); + if (( rejbuf = (char *)malloc( len+1 )) == NULL ) { + perror( "realloc" ); + exit( EXIT_FAILURE ); + } + memcpy( rejbuf, rbuf, len+1 ); + } + rc = process_ldif_rec( start, count ); - if( rc ) - fprintf( stderr, "ldif_record() = %d\n", rc ); + if ( rc && rejfp ) { + fprintf(rejfp, "# Error: %s (%d)", ldap_err2string(rc), rc); + + ldap_get_option(ld, LDAP_OPT_MATCHED_DN, &matched_msg); + if ( matched_msg != NULL && *matched_msg != '\0' ) { + fprintf( rejfp, ", matched DN: %s", matched_msg ); + } + + ldap_get_option(ld, LDAP_OPT_ERROR_STRING, &error_msg); + if ( error_msg != NULL && *error_msg != '\0' ) { + fprintf( rejfp, ", additional info: %s", error_msg ); + } + fprintf( rejfp, "\n%s\n", rejbuf ); + } + if (rejfp) + free( rejbuf ); free( rbuf ); } @@ -718,6 +762,10 @@ main( int argc, char **argv ) ldap_unbind( ld ); } + if ( rejfp != NULL ) { + fclose( rejfp ); + } + return( rc ); } diff --git a/doc/devel/args b/doc/devel/args index ea02cfa4f4..e000234440 100644 --- a/doc/devel/args +++ b/doc/devel/args @@ -1,6 +1,6 @@ Tools ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ldapdelete *CDE *HI*K M*OPQR U*WXYZ cdef*h**k *n*p* vwx* -ldapmodify *CDEF*HI*K M*OPQR U*WXYZabcdef*h**k *n*p*r t vwx* +ldapmodify *CDEF*HI*K M*OPQRS U*WXYZabcdef*h**k *n*p*r t vwx* ldapmodrdn *CDE *HI*K M*OPQR U*WXYZ cdef*h**k *n*p*rs vwx* ldappasswd A*CDE *HI* *O QRS U*WXYZa de *h** * * * s vwx* ldapsearch A*CDE *HI*KLM*OPQRSTU*WXYZab*def*h**kl*n*p* stuvwx*z diff --git a/doc/man/man1/ldapmodify.1 b/doc/man/man1/ldapmodify.1 index ab36e166c0..1397533632 100644 --- a/doc/man/man1/ldapmodify.1 +++ b/doc/man/man1/ldapmodify.1 @@ -11,6 +11,8 @@ ldapmodify, ldapadd \- LDAP modify entry and LDAP add entry tools [\c .BR \-c ] [\c +.BI \-S \ file\fR] +.[\c .BR \-C ] [\c .BR \-n ] @@ -61,6 +63,8 @@ ldapmodify, ldapadd \- LDAP modify entry and LDAP add entry tools [\c .BR \-c ] [\c +.BI \-S \ file\fR] +[\c .BR \-C ] [\c .BR \-n ] @@ -138,6 +142,11 @@ Continuous operation mode. Errors are reported, but will continue with modifications. The default is to exit after reporting an error. .TP +.BI \-S \ file +Add or change records which where 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 +conjunction with -c. +.TP .B \-n Show what would be done, but don't actually modify entries. Useful for debugging in conjunction with -v. -- 2.39.5