X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fdn.c;h=24bc185ff5376d1ab4aab97ddf3ff12948740920;hb=5631f25839a4a83521993639a96909267ea7bce6;hp=9b6edbcf680b5f82ae8ae6e0ec42732b186a4f14;hpb=741f9ea38386231960c7df2085ddcf7819dfab9b;p=openldap diff --git a/servers/slapd/dn.c b/servers/slapd/dn.c index 9b6edbcf68..24bc185ff5 100644 --- a/servers/slapd/dn.c +++ b/servers/slapd/dn.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2004 The OpenLDAP Foundation. + * Copyright 1998-2005 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,7 +34,6 @@ #include #include "slap.h" -#include "ldap_pvt.h" /* must be after slap.h, to get ldap_bv2dn_x() & co */ #include "lutil.h" /* @@ -60,14 +59,14 @@ LDAPRDN_validate( LDAPRDN rdn ) int iAVA; int rc; - assert( rdn ); + assert( rdn != NULL ); for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) { LDAPAVA *ava = rdn[ iAVA ]; AttributeDescription *ad; slap_syntax_validate_func *validate = NULL; - assert( ava ); + assert( ava != NULL ); if ( ( ad = AVA_PRIVATE( ava ) ) == NULL ) { const char *text = NULL; @@ -113,20 +112,20 @@ LDAPDN_validate( LDAPDN dn ) int iRDN; int rc; - assert( dn ); + assert( dn != NULL ); for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) { LDAPRDN rdn = dn[ iRDN ]; int iAVA; - assert( rdn ); + assert( rdn != NULL ); for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) { LDAPAVA *ava = rdn[ iAVA ]; AttributeDescription *ad; slap_syntax_validate_func *validate = NULL; - assert( ava ); + assert( ava != NULL ); if ( ( ad = AVA_PRIVATE( ava ) ) == NULL ) { const char *text = NULL; @@ -174,7 +173,7 @@ dnValidate( int rc; LDAPDN dn = NULL; - assert( in ); + assert( in != NULL ); if ( in->bv_len == 0 ) { return LDAP_SUCCESS; @@ -212,7 +211,7 @@ rdnValidate( LDAPRDN rdn; char* p; - assert( in ); + assert( in != NULL ); if ( in->bv_len == 0 ) { return LDAP_SUCCESS; @@ -262,14 +261,14 @@ AVA_Sort( LDAPRDN rdn, int iAVA ) int i; LDAPAVA *ava_in = rdn[ iAVA ]; - assert( rdn ); - assert( ava_in ); + assert( rdn != NULL ); + assert( ava_in != NULL ); for ( i = 0; i < iAVA; i++ ) { LDAPAVA *ava = rdn[ i ]; int a, j; - assert( ava ); + assert( ava != NULL ); a = strcmp( ava_in->la_attr.bv_val, ava->la_attr.bv_val ); @@ -338,7 +337,7 @@ LDAPRDN_rewrite( LDAPRDN rdn, unsigned flags, void *ctx ) struct berval bv = BER_BVNULL; int do_sort = 0; - assert( ava ); + assert( ava != NULL ); if ( ( ad = AVA_PRIVATE( ava ) ) == NULL ) { const char *text = NULL; @@ -445,13 +444,13 @@ LDAPDN_rewrite( LDAPDN dn, unsigned flags, void *ctx ) int iRDN; int rc; - assert( dn ); + assert( dn != NULL ); for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) { LDAPRDN rdn = dn[ iRDN ]; int iAVA; - assert( rdn ); + assert( rdn != NULL ); for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) { LDAPAVA *ava = rdn[ iAVA ]; @@ -463,7 +462,7 @@ LDAPDN_rewrite( LDAPDN dn, unsigned flags, void *ctx ) struct berval bv = BER_BVNULL; int do_sort = 0; - assert( ava ); + assert( ava != NULL ); if ( ( ad = AVA_PRIVATE( ava ) ) == NULL ) { const char *text = NULL; @@ -571,8 +570,8 @@ dnNormalize( struct berval *out, void *ctx) { - assert( val ); - assert( out ); + assert( val != NULL ); + assert( out != NULL ); Debug( LDAP_DEBUG_TRACE, ">>> dnNormalize: <%s>\n", val->bv_val, 0, 0 ); @@ -627,8 +626,8 @@ rdnNormalize( struct berval *out, void *ctx) { - assert( val ); - assert( out ); + assert( val != NULL ); + assert( out != NULL ); Debug( LDAP_DEBUG_TRACE, ">>> dnNormalize: <%s>\n", val->bv_val, 0, 0 ); if ( val->bv_len != 0 ) { @@ -683,8 +682,8 @@ dnPretty( struct berval *out, void *ctx) { - assert( val ); - assert( out ); + assert( val != NULL ); + assert( out != NULL ); Debug( LDAP_DEBUG_TRACE, ">>> dnPretty: <%s>\n", val->bv_val, 0, 0 ); @@ -740,8 +739,8 @@ rdnPretty( struct berval *out, void *ctx) { - assert( val ); - assert( out ); + assert( val != NULL ); + assert( out != NULL ); Debug( LDAP_DEBUG_TRACE, ">>> dnPretty: <%s>\n", val->bv_val, 0, 0 ); @@ -801,8 +800,8 @@ dnPrettyNormalDN( int flags, void *ctx ) { - assert( val ); - assert( dn ); + assert( val != NULL ); + assert( dn != NULL ); Debug( LDAP_DEBUG_TRACE, ">>> dn%sDN: <%s>\n", flags == SLAP_LDAPDN_PRETTY ? "Pretty" : "Normal", @@ -855,9 +854,9 @@ dnPrettyNormal( { Debug( LDAP_DEBUG_TRACE, ">>> dnPrettyNormal: <%s>\n", val->bv_val, 0, 0 ); - assert( val ); - assert( pretty ); - assert( normal ); + assert( val != NULL ); + assert( pretty != NULL ); + assert( normal != NULL ); if ( val->bv_len == 0 ) { ber_dupbv_x( pretty, val, ctx ); @@ -941,9 +940,9 @@ dnMatch( int match; struct berval *asserted = (struct berval *) assertedValue; - assert( matchp ); - assert( value ); - assert( assertedValue ); + assert( matchp != NULL ); + assert( value != NULL ); + assert( assertedValue != NULL ); assert( !BER_BVISNULL( value ) ); assert( !BER_BVISNULL( asserted ) ); @@ -976,9 +975,9 @@ dnRelativeMatch( int match; struct berval *asserted = (struct berval *) assertedValue; - assert( matchp ); - assert( value ); - assert( assertedValue ); + assert( matchp != NULL ); + assert( value != NULL ); + assert( assertedValue != NULL ); assert( !BER_BVISNULL( value ) ); assert( !BER_BVISNULL( asserted ) ); @@ -1005,6 +1004,61 @@ dnRelativeMatch( return LDAP_SUCCESS; } + if( mr == slap_schema.si_mr_dnSuperiorMatch ) { + asserted = value; + value = (struct berval *) assertedValue; + mr = slap_schema.si_mr_dnSubordinateMatch; + } + + if( mr == slap_schema.si_mr_dnSubordinateMatch ) { + if( asserted->bv_len >= value->bv_len ) { + match = -1; + } else { + if( DN_SEPARATOR( + value->bv_val[value->bv_len - asserted->bv_len - 1] )) + { + match = memcmp( + &value->bv_val[value->bv_len - asserted->bv_len], + asserted->bv_val, + asserted->bv_len ); + } else { + return 1; + } + } + + *matchp = match; + return LDAP_SUCCESS; + } + + if( mr == slap_schema.si_mr_dnOneLevelMatch ) { + if( asserted->bv_len >= value->bv_len ) { + match = -1; + } else { + if( DN_SEPARATOR( + value->bv_val[value->bv_len - asserted->bv_len - 1] )) + { + match = memcmp( + &value->bv_val[value->bv_len - asserted->bv_len], + asserted->bv_val, + asserted->bv_len ); + + if( !match ) { + struct berval rdn; + rdn.bv_val = value->bv_val; + rdn.bv_len = value->bv_len - asserted->bv_len - 1; + match = dnIsOneLevelRDN( &rdn ) ? 0 : 1; + } + } else { + return 1; + } + } + + *matchp = match; + return LDAP_SUCCESS; + } + + /* should not be reachable */ + assert( 0 ); return LDAP_OTHER; } @@ -1020,9 +1074,9 @@ rdnMatch( int match; struct berval *asserted = (struct berval *) assertedValue; - assert( matchp ); - assert( value ); - assert( assertedValue ); + assert( matchp != NULL ); + assert( value != NULL ); + assert( assertedValue != NULL ); match = value->bv_len - asserted->bv_len; @@ -1043,6 +1097,10 @@ rdnMatch( * dnParent - dn's parent, in-place * note: the incoming dn is assumed to be normalized/prettyfied, * so that escaped rdn/ava separators are in '\'+hexpair form + * + * note: "dn" and "pdn" can point to the same berval; + * beware that, in this case, the pointer to the original buffer + * will get lost. */ void dnParent( @@ -1064,8 +1122,35 @@ dnParent( p++; assert( ATTR_LEADCHAR( p[ 0 ] ) ); - pdn->bv_val = p; pdn->bv_len = dn->bv_len - (p - dn->bv_val); + pdn->bv_val = p; + + return; +} + +/* + * dnRdn - dn's rdn, in-place + * note: the incoming dn is assumed to be normalized/prettyfied, + * so that escaped rdn/ava separators are in '\'+hexpair form + */ +void +dnRdn( + struct berval *dn, + struct berval *rdn ) +{ + char *p; + + *rdn = *dn; + p = strchr( dn->bv_val, ',' ); + + /* one-level dn */ + if ( p == NULL ) { + return; + } + + assert( DN_SEPARATOR( p[ 0 ] ) ); + assert( ATTR_LEADCHAR( p[ 1 ] ) ); + rdn->bv_len = p - dn->bv_val; return; } @@ -1080,8 +1165,8 @@ dnExtractRdn( const char *p; int rc; - assert( dn ); - assert( rdn ); + assert( dn != NULL ); + assert( rdn != NULL ); if( dn->bv_len == 0 ) { return LDAP_OTHER; @@ -1109,7 +1194,7 @@ dn_rdnlen( { const char *p; - assert( dn_in ); + assert( dn_in != NULL ); if ( dn_in == NULL ) { return 0; @@ -1217,7 +1302,7 @@ build_new_dn( struct berval * new_dn, new_dn->bv_len = parent_dn->bv_len + newrdn->bv_len + 1; new_dn->bv_val = (char *) slap_sl_malloc( new_dn->bv_len + 1, memctx ); - ptr = lutil_strcopy( new_dn->bv_val, newrdn->bv_val ); + ptr = lutil_strncopy( new_dn->bv_val, newrdn->bv_val, newrdn->bv_len ); *ptr++ = ','; strcpy( ptr, parent_dn->bv_val ); } @@ -1234,8 +1319,8 @@ dnIsSuffix( { int d = dn->bv_len - suffix->bv_len; - assert( dn ); - assert( suffix ); + assert( dn != NULL ); + assert( suffix != NULL ); /* empty suffix matches any dn */ if ( suffix->bv_len == 0 ) { @@ -1274,6 +1359,22 @@ dnIsOneLevelRDN( struct berval *rdn ) return 1; } +#ifdef HAVE_TLS +static SLAP_CERT_MAP_FN *DNX509PeerNormalizeCertMap = NULL; +#endif + +int register_certificate_map_function(SLAP_CERT_MAP_FN *fn) +{ +#ifdef HAVE_TLS + if ( DNX509PeerNormalizeCertMap == NULL ) { + DNX509PeerNormalizeCertMap = fn; + return 0; + } +#endif + + return -1; +} + #ifdef HAVE_TLS /* * Convert an X.509 DN into a normalized LDAP DN @@ -1296,7 +1397,16 @@ dnX509normalize( void *x509_name, struct berval *out ) int dnX509peerNormalize( void *ssl, struct berval *dn ) { - return ldap_pvt_tls_get_peer_dn( ssl, dn, - (LDAPDN_rewrite_dummy *)LDAPDN_rewrite, 0 ); + int rc = LDAP_INVALID_CREDENTIALS; + + if ( DNX509PeerNormalizeCertMap != NULL ) + rc = (*DNX509PeerNormalizeCertMap)( ssl, dn ); + + if ( rc != LDAP_SUCCESS ) { + rc = ldap_pvt_tls_get_peer_dn( ssl, dn, + (LDAPDN_rewrite_dummy *)LDAPDN_rewrite, 0 ); + } + + return rc; } #endif