From: Pierangelo Masarati Date: Mon, 4 May 2009 10:57:50 +0000 (+0000) Subject: add in-scope helper X-Git-Tag: ACLCHECK_0~577 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=5c2b116798fb6860b21edaebb7588e790966acba;p=openldap add in-scope helper --- diff --git a/servers/slapd/dn.c b/servers/slapd/dn.c index 331035b9cc..35051299e6 100644 --- a/servers/slapd/dn.c +++ b/servers/slapd/dn.c @@ -1197,6 +1197,70 @@ dnIsSuffix( return( strcmp( dn->bv_val + d, suffix->bv_val ) == 0 ); } +/* + * In place; assumes: + * - ndn is normalized + * - nbase is normalized + * - dnIsSuffix( ndn, nbase ) == TRUE + * - LDAP_SCOPE_DEFAULT == LDAP_SCOPE_SUBTREE + */ +int +dnIsWithinScope( struct berval *ndn, struct berval *nbase, int scope ) +{ + assert( ndn != NULL ); + assert( nbase != NULL ); + assert( !BER_BVISNULL( ndn ) ); + assert( !BER_BVISNULL( nbase ) ); + + switch ( scope ) { + case LDAP_SCOPE_DEFAULT: + case LDAP_SCOPE_SUBTREE: + break; + + case LDAP_SCOPE_BASE: + if ( ndn->bv_len != nbase->bv_len ) { + return 0; + } + break; + + case LDAP_SCOPE_ONELEVEL: { + struct berval pndn; + dnParent( ndn, &pndn ); + if ( pndn.bv_len != nbase->bv_len ) { + return 0; + } + } break; + + case LDAP_SCOPE_SUBORDINATE: + if ( ndn->bv_len == nbase->bv_len ) { + return 0; + } + break; + + /* unknown scope */ + default: + return -1; + } + + return 1; +} + +/* + * In place; assumes: + * - ndn is normalized + * - nbase is normalized + * - LDAP_SCOPE_DEFAULT == LDAP_SCOPE_SUBTREE + */ +int +dnIsSuffixScope( struct berval *ndn, struct berval *nbase, int scope ) +{ + if ( !dnIsSuffix( ndn, nbase ) ) { + return 0; + } + + return dnIsWithinScope( ndn, nbase, scope ); +} + int dnIsOneLevelRDN( struct berval *rdn ) { diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index abf6593396..0b86092a38 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -923,6 +923,12 @@ LDAP_SLAPD_F (int) rdnMatch LDAP_P(( LDAP_SLAPD_F (int) dnIsSuffix LDAP_P(( const struct berval *dn, const struct berval *suffix )); +LDAP_SLAPD_F (int) dnIsWithinScope LDAP_P(( + struct berval *ndn, struct berval *nbase, int scope )); + +LDAP_SLAPD_F (int) dnIsSuffixScope LDAP_P(( + struct berval *ndn, struct berval *nbase, int scope )); + LDAP_SLAPD_F (int) dnIsOneLevelRDN LDAP_P(( struct berval *rdn )); LDAP_SLAPD_F (int) dnExtractRdn LDAP_P((