return( values );
-error_return:
+error_return:;
LBER_VFREE( values );
ldapava_free_dn( tmpDN );
return( NULL );
/* States */
#define B4AVA 0x0000
-#define B4ATTRTYPE 0x0001
+/* #define B4ATTRTYPE 0x0001 */
#define B4OIDATTRTYPE 0x0002
#define B4STRINGATTRTYPE 0x0003
( 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) )
+#define LDAP_DN_WILLESCAPE(c) \
+ ( LDAP_DN_RDN_SEP(c) || LDAP_DN_AVA_SEP(c) )
/* LDAPv2 */
#define LDAP_DN_VALUE_END_V2(c) \
/* FIXME: no composite rdn or non-"dc" types, right?
* (what about "dc" in OID form?) */
/* FIXME: we do not allow binary values in domain, right? */
+/* NOTE: use this macro only when ABSOLUTELY SURE rdn IS VALID! */
#define LDAP_DN_IS_RDN_DC( rdn ) \
( ( rdn ) && ( rdn )[ 0 ][ 0 ] && !( rdn )[ 1 ] \
&& ( ( rdn )[ 0 ][ 0 ]->la_flags == LDAP_AVA_STRING ) \
if ( p[ 0 ] ) {
switch ( LDAP_DN_FORMAT( flags ) ) {
case LDAP_DN_FORMAT_LDAPV3:
- case LDAP_DN_FORMAT_LDAPV2:
if ( !LDAP_DN_RDN_SEP( p[ 0 ] ) ) {
rc = LDAP_OTHER;
goto parsing_error;
}
break;
+ case LDAP_DN_FORMAT_LDAPV2:
+ if ( !LDAP_DN_RDN_SEP_V2( p[ 0 ] ) ) {
+ rc = LDAP_OTHER;
+ goto parsing_error;
+ }
+ break;
+
case LDAP_DN_FORMAT_DCE:
if ( !LDAP_DN_RDN_SEP_DCE( p[ 0 ] ) ) {
rc = LDAP_OTHER;
}
}
- state = B4ATTRTYPE;
- break;
-
- case B4ATTRTYPE:
/* oid */
if ( LDAP_DN_OID_LEADCHAR( p[ 0 ] ) ) {
state = B4OIDATTRTYPE;
* "OID." or "oid."
*/
if ( flags & LDAP_DN_PEDANTIC ) {
- if ( !strncmp( p, "oid.", 4 )
- || !strncmp( p, "OID.", 4 ) ) {
+ if ( !strncmp( p, "OID.", 4 )
+ || !strncmp( p, "oid.", 4 ) ) {
p += 4;
state = B4OIDATTRTYPE;
break;
* the starting char has been found to be
* a LDAP_DN_DESC_LEADCHAR so we don't re-check it
* FIXME: DCE attr types seem to have a more
- * restrictive syntax
+ * restrictive syntax (no '-' ...)
*/
for ( startPos = p++; p[ 0 ]; p++ ) {
if ( LDAP_DN_DESC_CHAR( p[ 0 ] ) ) {
case B4STRINGVALUE:
switch ( LDAP_DN_FORMAT( flags ) ) {
case LDAP_DN_FORMAT_LDAPV3:
- if ( str2strval( p, &attrValue,
- &p, flags,
+ if ( str2strval( p, &attrValue, &p, flags,
&attrValueEncoding ) ) {
goto parsing_error;
}
break;
case LDAP_DN_FORMAT_DCE:
- /* FIXME: does DCE use UTF-8? */
- if ( DCE2strval( p, &attrValue,
- &p, flags ) ) {
+ if ( DCE2strval( p, &attrValue, &p, flags ) ) {
goto parsing_error;
}
break;
newRDN = rdn;
/*
- * if we got an AVA separator ('+', | ',' * for DCE )
+ * if we got an AVA separator ('+', or ',' for DCE )
* we expect a new AVA for this RDN; otherwise
* we add the RDN to the DN
*/
for ( startPos = p = str; p[ 0 ]; p += 2 ) {
switch ( LDAP_DN_FORMAT( flags ) ) {
case LDAP_DN_FORMAT_LDAPV3:
- case LDAP_DN_FORMAT_LDAPV2:
if ( LDAP_DN_VALUE_END( p[ 0 ] ) ) {
goto end_of_value;
}
break;
+ case LDAP_DN_FORMAT_LDAPV2:
+ if ( LDAP_DN_VALUE_END_V2( p[ 0 ] ) ) {
+ goto end_of_value;
+ }
+ break;
+
case LDAP_DN_FORMAT_DCE:
if ( LDAP_DN_VALUE_END_DCE( p[ 0 ] ) ) {
goto end_of_value;
for ( ; p[ 0 ]; p++ ) {
switch ( LDAP_DN_FORMAT( flags ) ) {
case LDAP_DN_FORMAT_LDAPV3:
- case LDAP_DN_FORMAT_LDAPV2:
if ( LDAP_DN_VALUE_END( p[ 0 ] ) ) {
goto end_of_value;
}
break;
+ case LDAP_DN_FORMAT_LDAPV2:
+ if ( LDAP_DN_VALUE_END_V2( p[ 0 ] ) ) {
+ goto end_of_value;
+ }
+ break;
+
case LDAP_DN_FORMAT_DCE:
if ( LDAP_DN_VALUE_END_DCE( p[ 0 ] ) ) {
goto end_of_value;
}
/* need to escape it */
l += 3 * cl;
+
+ /*
+ * there might be some chars we want to escape in form
+ * of a couple of hexdigits for optimization purposes
+ */
+ } else if ( LDAP_DN_WILLESCAPE( p[ 0 ] ) ) {
+ l += 3;
- } 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 ] ) ) {
+ } else if ( LDAP_DN_NEEDESCAPE( p[ 0 ] )
+ || ( p == val->bv_val && LDAP_DN_NEEDESCAPE_LEAD( p[ 0 ] ) )
+ || ( !p[ 1 ] && LDAP_DN_NEEDESCAPE_TRAIL( p[ 0 ] ) ) ) {
l += 2;
} else {
for ( s = 0, d = 0, end = val->bv_len - 1; s < val->bv_len; ) {
ber_len_t cl = ldap_utf8_charlen( &val->bv_val[ s ] );
- if ( cl > 1 ) {
+ /*
+ * there might be some chars we want to escape in form
+ * of a couple of hexdigits for optimization purposes
+ */
+ if ( cl > 1 || LDAP_DN_WILLESCAPE( val->bv_val[ s ] ) ) {
for ( ; cl--; ) {
str[ d++ ] = '\\';
byte2hexpair( &val->bv_val[ s ], &str[ d ] );
}
} else {
- 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 ] ) ) {
+ if ( LDAP_DN_NEEDESCAPE( val->bv_val[ s ] )
+ || ( d == 0 && LDAP_DN_NEEDESCAPE_LEAD( val->bv_val[ s ] ) )
+ || ( s == end && LDAP_DN_NEEDESCAPE_TRAIL( val->bv_val[ s ] ) ) ) {
str[ d++ ] = '\\';
}
str[ d++ ] = val->bv_val[ s++ ];
} else {
for ( l = 0, p = val->bv_val; p[ 0 ]; p++ ) {
- if ( ( p == val->bv_val && LDAP_DN_NEEDESCAPE_LEAD( p[ 0 ] ) )
- || ( !p[ 1 ] && LDAP_DN_NEEDESCAPE_TRAIL( p[ 0 ] ) )
- || LDAP_DN_NEEDESCAPE( p[ 0 ] ) ) {
+ if ( LDAP_DN_NEEDESCAPE( p[ 0 ] )
+ || ( p == val->bv_val && LDAP_DN_NEEDESCAPE_LEAD( p[ 0 ] ) )
+ || ( !p[ 1 ] && LDAP_DN_NEEDESCAPE_TRAIL( p[ 0 ] ) ) ) {
l += 2;
} else {
*/
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 ] ) ) {
+ if ( LDAP_DN_NEEDESCAPE( val->bv_val[ s ] )
+ || ( s == 0 && LDAP_DN_NEEDESCAPE_LEAD( val->bv_val[ s ] ) )
+ || ( s == end && LDAP_DN_NEEDESCAPE_TRAIL( val->bv_val[ s ] ) ) ) {
str[ d++ ] = '\\';
}
str[ d++ ] = val->bv_val[ s++ ];