mirror of
https://git.openldap.org/openldap/openldap.git
synced 2026-01-17 04:13:55 -05:00
format error message as LDIF (do not assume the error messages do not contain fancy chars; ITS#4382)
This commit is contained in:
parent
e8886621ab
commit
9fd59d812d
1 changed files with 41 additions and 4 deletions
|
|
@ -39,6 +39,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include <ac/stdlib.h>
|
||||
#include <ac/string.h>
|
||||
#include <ac/errno.h>
|
||||
#include <ac/unistd.h>
|
||||
|
||||
|
|
@ -48,6 +49,9 @@
|
|||
#include "slurp.h"
|
||||
#include "globals.h"
|
||||
|
||||
#include "lber_pvt.h"
|
||||
#include "lutil.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define PORTSEP ","
|
||||
#else
|
||||
|
|
@ -96,12 +100,45 @@ write_reject(
|
|||
Debug( LDAP_DEBUG_ANY, "Error: cannot open reject file \"%s\"\n",
|
||||
rejfile, 0, 0 );
|
||||
} else {
|
||||
fseek( rfp, 0, 2 );
|
||||
fprintf( rfp, "%s: %s", ERROR_STR, ldap_err2string( lderr ));
|
||||
struct berval bv = BER_BVNULL,
|
||||
errstrbv,
|
||||
errmsgbv = BER_BVNULL;
|
||||
char *ptr;
|
||||
|
||||
ber_str2bv( ldap_err2string( lderr ), 0, 0, &errstrbv );
|
||||
if ( errmsg && *errmsg ) {
|
||||
fprintf( rfp, ": %s", errmsg );
|
||||
ber_str2bv( errmsg, 0, 0, &errmsgbv );
|
||||
bv.bv_len = errstrbv.bv_len
|
||||
+ STRLENOF( ": " ) + errmsgbv.bv_len;
|
||||
|
||||
ptr = bv.bv_val = ber_memalloc( bv.bv_len + 1 );
|
||||
ptr = lutil_strcopy( ptr, errstrbv.bv_val );
|
||||
ptr = lutil_strcopy( ptr, ": " );
|
||||
ptr = lutil_strcopy( ptr, errmsgbv.bv_val );
|
||||
|
||||
} else {
|
||||
bv = errstrbv;
|
||||
}
|
||||
fprintf( rfp, "\n" );
|
||||
|
||||
fseek( rfp, 0, 2 );
|
||||
|
||||
ptr = ldif_put( LDIF_PUT_VALUE, ERROR_STR, bv.bv_val, bv.bv_len );
|
||||
if ( bv.bv_val != errstrbv.bv_val ) {
|
||||
ber_memfree( bv.bv_val );
|
||||
}
|
||||
if ( ptr == NULL ) {
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"Error: cannot convert error message(s) \"%s%s%s\" "
|
||||
"into LDIF format\n",
|
||||
errstrbv.bv_val,
|
||||
BER_BVISNULL( &errmsgbv ) ? "" : ": ",
|
||||
BER_BVISNULL( &errmsgbv ) ? "" : errmsgbv.bv_val );
|
||||
return;
|
||||
}
|
||||
|
||||
fputs( ptr, rfp );
|
||||
ber_memfree( ptr );
|
||||
|
||||
if ((rc = re->re_write( ri, re, rfp )) < 0 ) {
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"Error: cannot write reject file \"%s\"\n",
|
||||
|
|
|
|||
Loading…
Reference in a new issue