#define LDAP_DN_NEEDESCAPE_LEAD(c) \
( LDAP_DN_ASCII_SPACE(c) || LDAP_DN_OCTOTHORPE(c) || LDAP_DN_NE(c) )
#define LDAP_DN_NEEDESCAPE_TRAIL(c) \
- ( ( LDAP_DN_ASCII_SPACE(c) || LDAP_DN_NEEDESCAPE(c) )
+ ( LDAP_DN_ASCII_SPACE(c) || LDAP_DN_NEEDESCAPE(c) )
/* LDAPv2 */
#define LDAP_DN_VALUE_END_V2(c) \
if ( p[ 0 ] == '\0' ) {
return( 1 );
}
- if ( LDAP_DN_NEEDESCAPE( p[ 0 ] ) ) {
+ if ( ( p == startPos + 1 && LDAP_DN_NEEDESCAPE_LEAD( p[ 0 ] ) )
+ || ( LDAP_DN_VALUE_END( p[ 1 ] ) && LDAP_DN_NEEDESCAPE_TRAIL( p[ 0 ] ) )
+ || LDAP_DN_NEEDESCAPE( p[ 0 ] ) ) {
escapes++;
continue;
}
/*
* we assume the string is UTF-8
*/
- *retFlags = LDAP_AVA_UTF8STRING;
+ *retFlags = LDAP_AVA_PRINTABLE;
continue;
}
/* strip trailing (unescaped) spaces */
for ( endPos = p - 1;
endPos > startPos + 1 &&
- LDAP_DN_ASCII_SPACE( endPos[ -1 ] ) &&
- !LDAP_DN_ESCAPE( endPos[ -2 ] );
+ LDAP_DN_ASCII_SPACE( endPos[ 0 ] ) &&
+ !LDAP_DN_ESCAPE( endPos[ -1 ] );
endPos-- ) {
/* no op */
}
for ( s = 0, d = 0; d < len; ) {
if ( LDAP_DN_ESCAPE( startPos[ s ] ) ) {
s++;
- if ( LDAP_DN_NEEDESCAPE( startPos[ s ] ) ) {
+ if ( ( s == 0 && LDAP_DN_NEEDESCAPE_LEAD( startPos[ s ] ) )
+ || ( s == len - 1 && LDAP_DN_NEEDESCAPE_TRAIL( startPos[ s ] ) )
+ || LDAP_DN_NEEDESCAPE( startPos[ s ] ) ) {
( *val )->bv_val[ d++ ] =
startPos[ s++ ];
} else if ( LDAP_DN_HEXPAIR( &startPos[ s ] ) ) {
/* strip trailing (unescaped) spaces */
for ( endPos = p - 1;
endPos > startPos + 1 &&
- LDAP_DN_ASCII_SPACE( endPos[ -1 ] ) &&
- !LDAP_DN_ESCAPE( endPos[ -2 ] );
+ LDAP_DN_ASCII_SPACE( endPos[ 0 ] ) &&
+ !LDAP_DN_ESCAPE( endPos[ -1 ] );
endPos-- ) {
/* no op */
}
static int
hexstr2binval( const char *str, struct berval **val, const char **next, unsigned flags )
{
- const char *p, *startPos;
+ const char *p, *startPos, *endPos = NULL;
ber_len_t len;
ber_len_t s, d;
*next = NULL;
for ( startPos = p = str; p[ 0 ]; p += 2 ) {
- /*
- * FIXME: add test for spaces to allow trailing spaces
- */
if ( LDAP_DN_VALUE_END( p[ 0 ] ) ) {
break;
}
+
+ if ( LDAP_DN_ASCII_SPACE( p[ 0 ] ) ) {
+ if ( flags & LDAP_DN_PEDANTIC ) {
+ return( 1 );
+ }
+ endPos = p;
+
+ for ( ; p[ 0 ]; p++ ) {
+ if ( LDAP_DN_VALUE_END( p[ 0 ] ) ) {
+ break;
+ }
+ }
+ break;
+ }
if ( !LDAP_DN_HEXPAIR( p ) ) {
return( 1 );
}
}
- /* FIXME: no trailing spaces allowed? */
- len = ( p - startPos ) / 2;
- assert( 2 * len == p - startPos ); /* must be even! */
+ len = ( ( endPos ? endPos : p ) - startPos ) / 2;
+ /* must be even! */
+ assert( 2 * len == ( endPos ? endPos : p ) - startPos );
*val = LDAP_MALLOC( sizeof( struct berval ) );
if ( *val == NULL ) {
if ( cl > 1 ) {
/* need to escape it */
l += 3 * cl;
- } else if ( LDAP_DN_NEEDESCAPE( p[ 0 ] ) ) {
+ } else if ( ( p == val->bv_val && LDAP_DN_NEEDESCAPE_LEAD( p[ 0 ] ) )
+ || ( !p[ 1 ] && LDAP_DN_NEEDESCAPE_TRAIL( p[ 0 ] ) )
+ || LDAP_DN_NEEDESCAPE( p[ 0 ] ) ) {
l += 2;
} else {
l++;
}
}
- return l;
+ return( l );
}
/*
static int
strval2str( struct berval *val, char *str, unsigned flags, ber_len_t *len )
{
- ber_len_t s, d, cl;
+ ber_len_t s, d, cl, end;
assert( val );
assert( str );
* we assume the string has enough room for the hex encoding
* of the value
*/
-
- for ( s = 0, d = 0; s < val->bv_len; ) {
+ for ( s = 0, d = 0, end = val->bv_len - 1; s < val->bv_len; ) {
cl = ldap_utf8_charlen( &val->bv_val[ s ] );
if ( cl > 1 ) {
d += 2;
}
} else {
- if ( LDAP_DN_NEEDESCAPE( val->bv_val[ s ] ) ) {
+ if ( ( d == 0 && LDAP_DN_NEEDESCAPE_LEAD( val->bv_val[ s ] ) )
+ || ( s == end && LDAP_DN_NEEDESCAPE_TRAIL( val->bv_val[ s ] ) )
+ || LDAP_DN_NEEDESCAPE( val->bv_val[ s ] ) ) {
str[ d++ ] = '\\';
}
str[ d++ ] = val->bv_val[ s++ ];
return( 0 );
}
- if ( flags & LDAP_AVA_UTF8STRING ) {
+ if ( flags & LDAP_AVA_PRINTABLE ) {
/*
* FIXME: binary encoded BER
*/
} else {
for ( l = 0, p = val->bv_val; p[ 0 ]; p++ ) {
- if ( LDAP_DN_NEEDESCAPE( p[ 0 ] ) ) {
+ if ( ( p == val->bv_val && LDAP_DN_NEEDESCAPE_LEAD( p[ 0 ] ) )
+ || ( !p[ 1 ] && LDAP_DN_NEEDESCAPE_TRAIL( p[ 0 ] ) )
+ || LDAP_DN_NEEDESCAPE( p[ 0 ] ) ) {
l += 2;
} else {
l++;
static int
strval2IA5str( struct berval *val, char *str, unsigned flags, ber_len_t *len )
{
- ber_len_t s, d;
+ ber_len_t s, d, end;
assert( val );
assert( str );
return ( 0 );
}
- if ( flags & LDAP_AVA_UTF8STRING ) {
+ if ( flags & LDAP_AVA_PRINTABLE ) {
/*
* FIXME: binary encoded BER
*/
* of the value
*/
- for ( s = 0, d = 0; s < val->bv_len; ) {
- if ( LDAP_DN_NEEDESCAPE( val->bv_val[ s ] ) ) {
+ for ( s = 0, d = 0, end = val->bv_len - 1; s < val->bv_len; ) {
+ if ( ( s == 0 && LDAP_DN_NEEDESCAPE_LEAD( val->bv_val[ s ] ) )
+ || ( s == end && LDAP_DN_NEEDESCAPE_TRAIL( val->bv_val[ s ] ) )
+ || LDAP_DN_NEEDESCAPE( val->bv_val[ s ] ) ) {
str[ d++ ] = '\\';
}
str[ d++ ] = val->bv_val[ s++ ];
return ( 0 );
}
- if ( flags & LDAP_AVA_UTF8STRING ) {
+ if ( flags & LDAP_AVA_PRINTABLE ) {
/*
* FIXME: binary encoded BER
*/
return ( 0 );
}
- if ( flags & LDAP_AVA_UTF8STRING ) {
+ if ( flags & LDAP_AVA_PRINTABLE ) {
/*
* FIXME: binary encoded BER
*/
return ( 0 );
}
- if ( flags & LDAP_AVA_UTF8STRING ) {
+ if ( flags & LDAP_AVA_PRINTABLE ) {
/*
* FIXME: binary encoded BER
*/
return ( 0 );
}
- if ( flags & LDAP_AVA_UTF8STRING ) {
+ if ( flags & LDAP_AVA_PRINTABLE ) {
/*
* FIXME: binary encoded BER
*/
s2l = strval2IA5strlen;
s2s = strval2IA5str;
v2_v3:
-
+
/*
* FIXME: we're treating LDAPv3 and LDAPv2 the same way;
* is it correct? No. LDAPv2 need to use binary encode
rc = LDAP_NO_MEMORY;
break;
}
- ( *str )[ 0 ] = '\0';
for ( l = 0, iRDN = 0; dn[ iRDN ]; iRDN++ ) {
LDAPRDN *rdn = dn[ iRDN ][ 0 ];
rc = LDAP_NO_MEMORY;
break;
}
- ( *str )[ 0 ] = '\0';
for ( l = 0, iRDN = 0; dn[ iRDN ]; iRDN++ ) {
LDAPRDN *rdn = dn[ iRDN ][ 0 ];
rc = LDAP_NO_MEMORY;
break;
}
- ( *str )[ 0 ] = '\0';
for ( l = 0; iRDN--; ) {
LDAPRDN *rdn = dn[ iRDN ][ 0 ];
rc = LDAP_NO_MEMORY;
break;
}
- ( *str )[ 0 ] = '\0';
iRDN--;
if ( iRDN && dn2domain( dn, str, &iRDN ) ) {