/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1998-2011 The OpenLDAP Foundation.
+ * Copyright 1998-2014 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
return 0;
}
-/* compatibility with U-Mich off by one bug */
-#define LDIF_KLUDGE 1
+/* compatibility with U-Mich off by two bug */
+#define LDIF_KLUDGE 2
/* NOTE: only preserved for binary compatibility */
void
LDAP_CONST char *val,
ber_len_t vlen )
{
- ldif_sput_wrap( out, type, name, val, vlen, LDIF_LINE_WIDTH );
+ ldif_sput_wrap( out, type, name, val, vlen, LDIF_LINE_WIDTH+LDIF_KLUDGE );
}
void
ber_len_t len=0;
ber_len_t i;
- wrap = LDIF_LINE_WIDTH_WRAP( wrap );
+ if ( !wrap )
+ wrap = LDIF_LINE_WIDTH+LDIF_KLUDGE;
/* prefix */
switch( type ) {
b64 = 1;
break;
}
- if ( len - LDIF_KLUDGE > wrap ) {
+ if ( len >= wrap ) {
*(*out)++ = '\n';
*(*out)++ = ' ';
len = 1;
bits |= (byte[2] & 0xff);
for ( i = 0; i < 4; i++, len++, bits <<= 6 ) {
- if ( len - LDIF_KLUDGE > wrap ) {
+ if ( len >= wrap ) {
*(*out)++ = '\n';
*(*out)++ = ' ';
len = 1;
bits |= (byte[2] & 0xff);
for ( i = 0; i < 4; i++, len++, bits <<= 6 ) {
- if ( len - LDIF_KLUDGE > wrap ) {
+ if ( len >= wrap ) {
*(*out)++ = '\n';
*(*out)++ = ' ';
len = 1;
int
ldif_read_record(
LDIFFP *lfp,
- int *lno, /* ptr to line number counter */
+ unsigned long *lno, /* ptr to line number counter */
char **bufp, /* ptr to malloced output buffer */
int *buflenp ) /* ptr to length of *bufp */
{
break;
}
}
- if ( stop )
- break;
+ if ( !stop ) {
+ if ( fgets( line, sizeof( line ), lfp->fp ) == NULL ) {
+ stop = 1;
+ len = 0;
+ } else {
+ len = strlen( line );
+ }
+ }
- if ( fgets( line, sizeof( line ), lfp->fp ) == NULL ) {
- stop = 1;
+ if ( stop ) {
/* Add \n in case the file does not end with newline */
- line[0] = '\n';
- line[1] = '\0';
+ if (last_ch != '\n') {
+ len = 1;
+ line[0] = '\n';
+ line[1] = '\0';
+ goto last;
+ }
+ break;
+ }
+
+ /* Squash \r\n to \n */
+ if ( len > 1 && line[len-2] == '\r' ) {
+ len--;
+ line[len-1] = '\n';
}
- len = strlen( line );
if ( last_ch == '\n' ) {
(*lno)++;
- if ( line[0] == '\n' ||
- ( line[0] == '\r' && line[1] == '\n' )) {
+ if ( line[0] == '\n' ) {
if ( !found_entry ) {
lcur = 0;
top_comment = 0;
len--;
line[len] = '\0';
}
- if ( line[len-1] == '\r' ) {
- len--;
- line[len] = '\0';
- }
ptr = line + STRLENOF("include:");
while (isspace((unsigned char) *ptr)) ptr++;
}
}
}
- }
+ }
}
+last:
if ( *buflenp - lcur <= len ) {
*buflenp += len + LDIF_MAXLINE;
nbufp = ber_memrealloc( *bufp, *buflenp );