main( int argc, char *argv[] )
{
int rc, i, debug = 0, f2 = 0;
- unsigned flags[ 2 ] = { 0U, 0U };
+ unsigned flags[ 2 ] = { 0U, LDAP_DN_FORMAT_LDAPV3 };
char *strin, *str, *str2, buf[ 1024 ];
LDAPDN *dn, *dn2 = NULL;
if ( argc < 2 ) {
fprintf( stderr, "usage: dntest <dn> [flags-in[,...]] [flags-out[,...]]\n\n" );
- fprintf( stderr, "\tflags-in: V3,V2,DCE,<pedantic>\n" );
- fprintf( stderr, "\tflags-out: V3,V2,UFN,DCE,AD,<pedantic>\n\n" );
- fprintf( stderr, "\t<pedantic>: PEDANTIC,NOSPACES,NOONESPACE\n\n" );
+ fprintf( stderr, "\tflags-in: V3,V2,DCE,<flags>\n" );
+ fprintf( stderr, "\tflags-out: V3,V2,UFN,DCE,AD,<flags>\n\n" );
+ fprintf( stderr, "\t<flags>: PRETTY,PEDANTIC,NOSPACES,NOONESPACE\n\n" );
return( 0 );
}
}
}
- f2 = argc > 3 ? 1 : 0;
+ f2 = 1;
rc = ldap_str2dn( strin, &dn, flags[ 0 ] );
#else /* USE_LDAP_DN_PARSING */
Debug( LDAP_DEBUG_TRACE, "ldap_dn2ufn\n", 0, 0, 0 );
- return dn2dn( dn, LDAP_DN_FORMAT_LDAPV3, LDAP_DN_FORMAT_UFN );
+ return dn2dn( dn, LDAP_DN_FORMAT_LDAP, LDAP_DN_FORMAT_UFN );
#endif /* USE_LDAP_DN_PARSING */
}
Debug( LDAP_DEBUG_TRACE, "ldap_explode_dn\n", 0, 0, 0 );
- if ( ldap_str2dn( dn, &tmpDN, LDAP_DN_FORMAT_LDAPV3 )
+ if ( ldap_str2dn( dn, &tmpDN, LDAP_DN_FORMAT_LDAP )
!= LDAP_SUCCESS ) {
return( NULL );
}
/*
* we assume this dn is made of one rdn only
*/
- if ( ldap_str2dn( rdn, &tmpDN, LDAP_DN_FORMAT_LDAPV3 )
+ if ( ldap_str2dn( rdn, &tmpDN, LDAP_DN_FORMAT_LDAP )
!= LDAP_SUCCESS ) {
return( NULL );
}
#else /* USE_LDAP_DN_PARSING */
Debug( LDAP_DEBUG_TRACE, "ldap_dn2dcedn\n", 0, 0, 0 );
- return dn2dn( dn, LDAP_DN_FORMAT_LDAPV3, LDAP_DN_FORMAT_DCE );
+ return dn2dn( dn, LDAP_DN_FORMAT_LDAP, LDAP_DN_FORMAT_DCE );
#endif /* USE_LDAP_DN_PARSING */
}
{
Debug( LDAP_DEBUG_TRACE, "ldap_dn2ad_canonical\n", 0, 0, 0 );
- return dn2dn( dn, LDAP_DN_FORMAT_LDAPV3, LDAP_DN_FORMAT_AD_CANONICAL );
+ return dn2dn( dn, LDAP_DN_FORMAT_LDAP, LDAP_DN_FORMAT_AD_CANONICAL );
}
#ifndef USE_LDAP_DN_PARSING /* deprecated */
* from ( fin & LDAP_DN_FORMAT_MASK ) to ( fout & LDAP_DN_FORMAT_MASK )
*
* fin can be one of:
+ * LDAP_DN_FORMAT_LDAP (rfc 2253 and ldapbis liberal,
+ * plus some rfc 1779)
* LDAP_DN_FORMAT_LDAPV3 (rfc 2253 and ldapbis)
* LDAP_DN_FORMAT_LDAPV2 (rfc 1779)
* LDAP_DN_FORMAT_DCE (?)
*
- * fout can be any of the above plus:
+ * fout can be any of the above except
+ * LDAP_DN_FORMAT_LDAP
+ * plus:
* LDAP_DN_FORMAT_UFN (rfc 1781, partial and with extensions)
* LDAP_DN_FORMAT_AD_CANONICAL (?)
*/
/* Composite rules */
#define LDAP_DN_ALLOW_ONE_SPACE(f) \
- ( ( (f) & LDAP_DN_FORMAT_LDAPV2 ) \
+ ( LDAP_DN_LDAPV2(f) \
|| !( (f) & LDAP_DN_P_NOSPACEAFTERRDN ) )
#define LDAP_DN_ALLOW_SPACES(f) \
- ( ( (f) & LDAP_DN_FORMAT_LDAPV2 ) \
+ ( LDAP_DN_LDAPV2(f) \
|| !( (f) & ( LDAP_DN_P_NOLEADTRAILSPACES | LDAP_DN_P_NOSPACEAFTERRDN ) ) )
+#define LDAP_DN_LDAP(f) \
+ ( ( (f) & LDAP_DN_FORMAT_MASK ) == LDAP_DN_FORMAT_LDAP )
#define LDAP_DN_LDAPV3(f) \
( ( (f) & LDAP_DN_FORMAT_MASK ) == LDAP_DN_FORMAT_LDAPV3 )
#define LDAP_DN_LDAPV2(f) \
/*
* Converts a string representation of a DN (in LDAPv3, LDAPv2 or DCE)
- * into a structured representation of the DN, by separating attribute
+ * into a structural representation of the DN, by separating attribute
* types and values encoded in the more appropriate form, which is
* string or OID for attribute types and binary form of the BER encoded
* value or Unicode string. Formats different from LDAPv3 are parsed
*dn = NULL;
switch ( LDAP_DN_FORMAT( flags ) ) {
+ case LDAP_DN_FORMAT_LDAP:
case LDAP_DN_FORMAT_LDAPV3:
case LDAP_DN_FORMAT_LDAPV2:
case LDAP_DN_FORMAT_DCE:
goto parsing_error;
}
p++;
+
+ } else if ( LDAP_DN_LDAP( flags ) ) {
+ /*
+ * if dn starts with '/' let's make it a DCE dn
+ */
+ if ( LDAP_DN_RDN_SEP_DCE( p[ 0 ] ) ) {
+ flags |= LDAP_DN_FORMAT_DCE;
+ p++;
+ }
}
for ( ; p[ 0 ]; p++ ) {
}
break;
+ case LDAP_DN_FORMAT_LDAP:
case LDAP_DN_FORMAT_LDAPV2:
if ( !LDAP_DN_RDN_SEP_V2( p[ 0 ] ) ) {
rc = LDAP_OTHER;
*n = NULL;
switch ( LDAP_DN_FORMAT( flags ) ) {
+ case LDAP_DN_FORMAT_LDAP:
case LDAP_DN_FORMAT_LDAPV3:
case LDAP_DN_FORMAT_LDAPV2:
case LDAP_DN_FORMAT_DCE:
* LDAPv2 allows the attribute value to be quoted;
* also, IA5 values are expected, in principle
*/
- if ( LDAP_DN_LDAPV2( flags ) ) {
+ if ( LDAP_DN_LDAPV2( flags ) || LDAP_DN_LDAP( flags ) ) {
if ( LDAP_DN_QUOTES( p[ 0 ] ) ) {
p++;
state = B4IA5VALUEQUOTED;
break;
}
- state = B4IA5VALUE;
- break;
+ if ( LDAP_DN_LDAPV2( flags ) ) {
+ state = B4IA5VALUE;
+ break;
+ }
}
/*
case B4STRINGVALUE:
switch ( LDAP_DN_FORMAT( flags ) ) {
+ case LDAP_DN_FORMAT_LDAP:
case LDAP_DN_FORMAT_LDAPV3:
if ( str2strval( p, &attrValue, &p, flags,
&attrValueEncoding ) ) {
* we add the RDN to the DN
*/
switch ( LDAP_DN_FORMAT( flags ) ) {
+ case LDAP_DN_FORMAT_LDAP:
case LDAP_DN_FORMAT_LDAPV3:
case LDAP_DN_FORMAT_LDAPV2:
if ( !LDAP_DN_AVA_SEP( p[ 0 ] ) ) {
if ( newRDN ) {
ldapava_free_rdn( newRDN );
+ newRDN = NULL;
}
return_result:;
*/
unescapes++;
- } else if ( LDAP_DN_VALUE_END( p[ 0 ] ) ) {
+ } else if ( ( LDAP_DN_LDAP( flags ) && LDAP_DN_VALUE_END_V2( p[ 0 ] ) )
+ || ( LDAP_DN_LDAPV3( flags ) && LDAP_DN_VALUE_END( p[ 0 ] ) ) ) {
break;
} else if ( LDAP_DN_NEEDESCAPE( p[ 0 ] ) ) {
}
break;
+ case LDAP_DN_FORMAT_LDAP:
case LDAP_DN_FORMAT_LDAPV2:
if ( LDAP_DN_VALUE_END_V2( p[ 0 ] ) ) {
goto end_of_value;
}
break;
+ case LDAP_DN_FORMAT_LDAP:
case LDAP_DN_FORMAT_LDAPV2:
if ( LDAP_DN_VALUE_END_V2( p[ 0 ] ) ) {
goto end_of_value;
break;
default:
- return( LDAP_OTHER );
+ return( LDAP_INVALID_DN_SYNTAX );
}
*str = LDAP_MALLOC( l + 1 );
}
default:
- assert( 0 );
+ return( LDAP_INVALID_DN_SYNTAX );
}
return( LDAP_SUCCESS );
}
- rc = ldap_str2dn( in->bv_val, &dn, LDAP_DN_FORMAT_LDAPV3 );
+ rc = ldap_str2dn( in->bv_val, &dn, LDAP_DN_FORMAT_LDAP );
+
+ /*
+ * Fixme: should we also validate each DN component?
+ */
ldapava_free_dn( dn );
if ( rc != LDAP_SUCCESS ) {
/*
* Go to structural representation
*/
- rc = ldap_str2dn( val->bv_val, &dn, LDAP_DN_FORMAT_LDAPV3 );
+ rc = ldap_str2dn( val->bv_val, &dn, LDAP_DN_FORMAT_LDAP );
if ( rc != LDAP_SUCCESS ) {
return LDAP_INVALID_SYNTAX;
}
int rc;
/* FIXME: should be liberal in what we accept */
- rc = ldap_str2dn( val->bv_val, &dn, LDAP_DN_FORMAT_LDAPV3 );
+ rc = ldap_str2dn( val->bv_val, &dn, LDAP_DN_FORMAT_LDAP );
if ( rc != LDAP_SUCCESS ) {
return LDAP_INVALID_SYNTAX;
}
match = value->bv_len - asserted->bv_len;
if ( match == 0 ) {
-#ifdef USE_DN_NORMALIZE
match = strcmp( value->bv_val, asserted->bv_val );
- fprintf(stderr, "USE_DN_NORMALIZE :(\n");
-#else
- match = strcasecmp( value->bv_val, asserted->bv_val );
- fprintf(stderr, "!USE_DN_NORMALIZE :)\n");
-#endif
}
#ifdef NEW_LOGGING