]> git.sur5r.net Git - openldap/commitdiff
add in-scope helper
authorQuanah Gibson-Mount <quanah@openldap.org>
Thu, 13 Aug 2009 01:38:56 +0000 (01:38 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Thu, 13 Aug 2009 01:38:56 +0000 (01:38 +0000)
servers/slapd/dn.c
servers/slapd/proto-slap.h

index 331035b9cc318cec02aff565bf7a7d27c221af37..35051299e6792272665f81ee669cfb5b1a6df6e3 100644 (file)
@@ -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 )
 {
index 5d77594cfa42815833b8664796101f88245a1e7f..6e962d2ebb3cd6cebe388cfd48ab9948ffa71dc2 100644 (file)
@@ -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((