Skip to content
Snippets Groups Projects
Commit 13c1e77a authored by Quanah Gibson-Mount's avatar Quanah Gibson-Mount
Browse files

add in-scope helper

parent bc13ead2
No related branches found
No related tags found
No related merge requests found
......@@ -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 )
{
......
......@@ -922,6 +922,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((
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment