]> git.sur5r.net Git - openldap/commitdiff
Changed be_issuffix and dnParent to struct bervals
authorHoward Chu <hyc@openldap.org>
Sat, 26 Jan 2002 06:52:59 +0000 (06:52 +0000)
committerHoward Chu <hyc@openldap.org>
Sat, 26 Jan 2002 06:52:59 +0000 (06:52 +0000)
servers/slapd/back-ldbm/add.c
servers/slapd/back-ldbm/delete.c
servers/slapd/back-ldbm/dn2id.c
servers/slapd/back-ldbm/modrdn.c
servers/slapd/back-ldbm/search.c
servers/slapd/back-monitor/cache.c
servers/slapd/back-passwd/search.c

index ec7d13f515b54cde50bb6dafd3f15b0c239f4410..d6e4b300eb73c85d577b4509492d7359396cd4f4 100644 (file)
@@ -80,11 +80,12 @@ ldbm_back_add(
         * add the entry.
         */
 
-       pdn.bv_val = dn_parent( be, e->e_ndn );
-       if (pdn.bv_val && pdn.bv_val[0])
-               pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_ndn);
-       else
-               pdn.bv_len = 0;
+       if ( be_issuffix( be, &e->e_nname ) ) {
+               pdn = slap_empty_bv;
+       } else {
+               rc = dnParent( &e->e_nname, &pdn );
+               /* dnParent always returns success */
+       }
 
        if( pdn.bv_len ) {
                Entry *matched = NULL;
@@ -206,7 +207,7 @@ ldbm_back_add(
 
                /* no parent, must be adding entry to root */
                if ( !be_isroot( be, &op->o_ndn ) ) {
-                       if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
+                       if ( be_issuffix( be, (struct berval *)&slap_empty_bv ) || be_isupdate( be, &op->o_ndn ) ) {
                                p = (Entry *)&slap_entry_root;
                                
                                rc = access_allowed( be, conn, op, p,
index bfe7a48eba3d8b239df4f7db30cc8a512d5858e2..adb1ff6b724bf5b4d7f1cd614507185ca94a3630 100644 (file)
@@ -115,8 +115,8 @@ ldbm_back_delete(
        }
 
        /* delete from parent's id2children entry */
-       if( (pdn.bv_val = dn_parent( be, e->e_ndn )) != NULL && pdn.bv_val[ 0 ] != '\0' ) {
-               pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_ndn);
+       if( !be_issuffix( be, &e->e_nname ) && dnParent( &e->e_nname, &pdn ) == LDAP_SUCCESS
+               && pdn.bv_len ) {
                if( (p = dn2entry_w( be, &pdn, NULL )) == NULL) {
 #ifdef NEW_LOGGING
                        LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
@@ -154,7 +154,7 @@ ldbm_back_delete(
        } else {
                /* no parent, must be root to delete */
                if( ! be_isroot( be, &op->o_ndn ) ) {
-                       if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
+                       if ( be_issuffix( be, (struct berval *)&slap_empty_bv ) || be_isupdate( be, &op->o_ndn ) ) {
                                p = (Entry *)&slap_entry_root;
                                
                                rc = access_allowed( be, conn, op, p,
index 83325ad275e554e14d3c719fc2e615d4324d34c8..64be1196bf6be0ef491e5c0b5d6295b89d1605b9 100644 (file)
@@ -26,7 +26,8 @@ dn2id_add(
        int             rc, flags;
        DBCache *db;
        Datum           key, data;
-       char            *buf, *ptr, *pdn;
+       char            *buf;
+       struct berval   ptr, pdn;
 
 #ifdef NEW_LOGGING
        LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
@@ -55,8 +56,9 @@ dn2id_add(
        buf = ch_malloc( key.dsize );
        key.dptr = buf;
        buf[0] = DN_BASE_PREFIX;
-       ptr = buf + 1;
-       strcpy( ptr, dn->bv_val );
+       ptr.bv_val = buf + 1;
+       ptr.bv_len = dn->bv_len;
+       strcpy( ptr.bv_val, dn->bv_val );
 
        ldbm_datum_init( data );
        data.dptr = (char *) &id;
@@ -65,41 +67,39 @@ dn2id_add(
        flags = LDBM_INSERT;
        rc = ldbm_cache_store( db, key, data, flags );
 
-       if ( rc != -1 && !be_issuffix( be, ptr )) {
+       if ( rc != -1 && !be_issuffix( be, &ptr )) {
                buf[0] = DN_SUBTREE_PREFIX;
                ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
                rc = idl_insert_key( be, db, key, id );
                ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
-       }
-
-       if ( rc != -1 ) {
-               pdn = dn_parent( be, ptr );
 
-               if( pdn != NULL ) {
-                       pdn[-1] = DN_ONE_PREFIX;
-                       key.dsize -= pdn - ptr;
-                       key.dptr = pdn - 1;
-                       ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
-                       rc = idl_insert_key( be, db, key, id );
-                       ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
+               if ( rc != -1 ) {
+                       rc = dnParent( &ptr, &pdn );
+
+                       if( rc == LDAP_SUCCESS ) {
+                               pdn.bv_val[-1] = DN_ONE_PREFIX;
+                               key.dsize = pdn.bv_len + 2;
+                               key.dptr = pdn.bv_val - 1;
+                               ptr = pdn;
+                               ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
+                               rc = idl_insert_key( be, db, key, id );
+                               ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
+                       }
                }
        }
 
-       while ( rc != -1 && pdn != NULL ) {
-               if ( be_issuffix( be, pdn ))
-                       break;
-
-               pdn[-1] = DN_SUBTREE_PREFIX;
+       while ( rc != -1 && !be_issuffix( be, &ptr )) {
+               ptr.bv_val[-1] = DN_SUBTREE_PREFIX;
 
                ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
                rc = idl_insert_key( be, db, key, id );
                ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
 
                if( rc != 0 ) break;
+               rc = dnParent( &ptr, &pdn );
+               key.dsize = pdn.bv_len + 2;
+               key.dptr = pdn.bv_val - 1;
                ptr = pdn;
-               pdn = dn_parent( be, pdn );
-               key.dsize -= pdn - ptr;
-               key.dptr = pdn - 1;
        }
 
        free( buf );
@@ -226,7 +226,7 @@ dn2idl(
        assert( idlp != NULL );
        *idlp = NULL;
 
-       if ( prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn->bv_val) ) {
+       if ( prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn) ) {
                *idlp = idl_allids( be );
                return 0;
        }
@@ -270,7 +270,8 @@ dn2id_delete(
        DBCache *db;
        Datum           key;
        int             rc;
-       char            *buf, *ptr, *pdn;
+       char            *buf;
+       struct berval   ptr, pdn;
 
 #ifdef NEW_LOGGING
        LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
@@ -301,44 +302,43 @@ dn2id_delete(
        buf = ch_malloc( key.dsize );
        key.dptr = buf;
        buf[0] = DN_BASE_PREFIX;
-       ptr = buf + 1;
-       strcpy( ptr, dn->bv_val );
+       ptr.bv_val = buf + 1;
+       ptr.bv_len = dn->bv_len;
+       strcpy( ptr.bv_val, dn->bv_val );
 
        rc = ldbm_cache_delete( db, key );
        
-       if( !be_issuffix( be, ptr )) {
+       if( !be_issuffix( be, &ptr )) {
                buf[0] = DN_SUBTREE_PREFIX;
                ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
                (void) idl_delete_key( be, db, key, id );
                ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
-       }
 
-       pdn = dn_parent( be, ptr );
+               rc = dnParent( &ptr, &pdn );
 
-       if( pdn != NULL ) {
-               pdn[-1] = DN_ONE_PREFIX;
-               key.dsize -= pdn - ptr;
-               key.dptr = pdn - 1;
+               if( rc == LDAP_SUCCESS ) {
+                       pdn.bv_val[-1] = DN_ONE_PREFIX;
+                       key.dsize = pdn.bv_len + 2;
+                       key.dptr = pdn.bv_val - 1;
+                       ptr = pdn;
 
-               ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
-               (void) idl_delete_key( be, db, key, id );
-               ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
+                       ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
+                       (void) idl_delete_key( be, db, key, id );
+                       ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
+               }
        }
 
-       while ( pdn != NULL ) {
-               if ( be_issuffix( be, pdn ))
-                       break;
-
-               pdn[-1] = DN_SUBTREE_PREFIX;
+       while ( rc != -1 && !be_issuffix( be, &ptr )) {
+               ptr.bv_val[-1] = DN_SUBTREE_PREFIX;
 
                ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
                (void) idl_delete_key( be, db, key, id );
                ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
 
+               rc = dnParent( &ptr, &pdn );
+               key.dsize = pdn.bv_len + 2;
+               key.dptr = pdn.bv_val - 1;
                ptr = pdn;
-               pdn = dn_parent( be, pdn );
-               key.dsize -= pdn - ptr;
-               key.dptr = pdn - 1;
        }
 
        free( buf );
@@ -415,9 +415,8 @@ dn2entry_rw(
        if( matched == NULL ) return NULL;
 
        /* entry does not exist - see how much of the dn does exist */
-       /* dn_parent checks returns NULL if dn is suffix */
-       if ( (pdn.bv_val = dn_parent( be, dn->bv_val )) != NULL && *pdn.bv_val ) {
-               pdn.bv_len = dn->bv_len - (pdn.bv_val - dn->bv_val);
+       if ( !be_issuffix( be, dn ) && dnParent( dn, &pdn ) == LDAP_SUCCESS
+               && pdn.bv_len ) {
                /* get entry with reader lock */
                if ( (e = dn2entry_r( be, &pdn, matched )) != NULL ) {
                        *matched = e;
index d8a80509a4c6b87baf843ada3bf4678b073dc3d5..195fa4d434f575c5e86171d73b6224481e492146 100644 (file)
@@ -148,11 +148,11 @@ ldbm_back_modrdn(
                goto return_results;
        }
 
-       p_ndn.bv_val = dn_parent( be, e->e_ndn );
-       if ( p_ndn.bv_val )
-               p_ndn.bv_len = e->e_nname.bv_len - (p_ndn.bv_val - e->e_ndn);
-       else
-               p_ndn.bv_len = 0;
+       if ( be_issuffix( be, &e->e_nname ) ) {
+               p_ndn = slap_empty_bv ;
+       } else {
+               dnParent( &e->e_nname, &p_ndn );
+       }
 
        if ( p_ndn.bv_len != 0 ) {
                /* Make sure parent entry exist and we can write its 
@@ -201,11 +201,11 @@ ldbm_back_modrdn(
                       p_ndn.bv_val, 0, 0 );
 #endif
 
-               p_dn.bv_val = dn_parent( be, e->e_dn );
-               if ( p_dn.bv_val )
-                       p_dn.bv_len = e->e_name.bv_len - (p_dn.bv_val - e->e_dn);
-               else
-                       p_dn.bv_len = 0;
+               if ( p_ndn.bv_val == slap_empty_bv.bv_val ) {
+                       p_dn = slap_empty_bv;
+               } else {
+                       dnParent( &e->e_name, &p_dn );
+               }
 
 #ifdef NEW_LOGGING
                LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
@@ -219,7 +219,7 @@ ldbm_back_modrdn(
                /* no parent, must be root to modify rdn */
                isroot = be_isroot( be, &op->o_ndn );
                if ( ! isroot ) {
-                       if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
+                       if ( be_issuffix( be, (struct berval *)&slap_empty_bv ) || be_isupdate( be, &op->o_ndn ) ) {
                                p = (Entry *)&slap_entry_root;
                                
                                rc = access_allowed( be, conn, op, p,
@@ -397,7 +397,7 @@ ldbm_back_modrdn(
                        }
 
                        if ( ! isroot ) {
-                               if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
+                               if ( be_issuffix( be, (struct berval *)&slap_empty_bv ) || be_isupdate( be, &op->o_ndn ) ) {
                                        np = (Entry *)&slap_entry_root;
                                
                                        rc = access_allowed( be, conn, op, np,
index c16404a3ac50bbeb89fffafb7d455169ca4b3c0c..c80359f8c6ecb6dcc141727faf659e340e6d1d7b 100644 (file)
@@ -343,11 +343,10 @@ searchit:
 
                        /* need to skip alias which deref into scope */
                        if( scope & LDAP_SCOPE_ONELEVEL ) {
-                               char *pdn = dn_parent( NULL, e->e_ndn );
-                               if ( pdn != NULL ) {
-                                       if( strcmp( pdn, realbase.bv_val ) ) {
-                                               goto loop_continue;
-                                       }
+                               struct berval pdn;
+                               dnParent( &e->e_nname, &pdn );
+                               if ( ber_bvcmp( &pdn, &realbase ) ) {
+                                       goto loop_continue;
                                }
 
                        } else if ( dnIsSuffix( &e->e_nname, &realbase ) ) {
@@ -375,14 +374,13 @@ searchit:
                if ( !manageDSAit && scope != LDAP_SCOPE_BASE &&
                        is_entry_referral( e ) )
                {
-                       char    *dn;
+                       struct berval   dn;
 
                        /* check scope */
                        if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
-                               if ( (dn = dn_parent( be, e->e_ndn )) != NULL ) {
-                                       scopeok = (dn == realbase.bv_val)
-                                               ? 1
-                                               : (strcmp( dn, realbase.bv_val ) ? 0 : 1 );
+                               if ( !be_issuffix( be, &e->e_nname ) ) {
+                                       dnParent( &e->e_nname, &dn );
+                                       scopeok = dn_match( &dn, &realbase );
                                } else {
                                        scopeok = (realbase.bv_len == 0);
                                }
@@ -425,14 +423,13 @@ searchit:
 
                /* if it matches the filter and scope, send it */
                if ( test_filter( be, conn, op, e, filter ) == LDAP_COMPARE_TRUE ) {
-                       char    *dn;
+                       struct berval   dn;
 
                        /* check scope */
                        if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
-                               if ( (dn = dn_parent( be, e->e_ndn )) != NULL ) {
-                                       scopeok = (dn == realbase.bv_val)
-                                               ? 1
-                                               : (strcmp( dn, realbase.bv_val ) ? 0 : 1 );
+                               if ( !be_issuffix( be, &e->e_nname ) ) {
+                                       dnParent( &e->e_nname, &dn );
+                                       scopeok = dn_match( &dn, &realbase );
                                } else {
                                        scopeok = (realbase.bv_len == 0);
                                }
index 70b7cdf2a0c009a1ecc1b0efcacb8a7b02fcbded..6572c2af2eb219cf34c88337aab589e133e5d4db 100644 (file)
@@ -206,7 +206,7 @@ monitor_cache_dn2entry(
 
        /* try with parent/ancestors */
        if ( ndn->bv_len ) {
-               p_ndn.bv_val = dn_parent( NULL, ndn->bv_val );
+               dnParent( ndn, &p_ndn );
        }
 
        if ( p_ndn.bv_val == NULL ) {
index 4366f32aa82d9ff80b4f6433881e4818754f4b8e..bad2c1776317487e1f3133a4a8e47d48454aaaaa 100644 (file)
@@ -47,7 +47,7 @@ passwd_back_search(
        int err = LDAP_SUCCESS;
 
        LDAPRDN *rdn = NULL;
-       char *parent = NULL;
+       struct berval parent = { 0, NULL };
        char *matched = NULL;
        const char *text = NULL;
 
@@ -68,7 +68,7 @@ passwd_back_search(
 #endif /* HAVE_SETPWFILE */
 
        /* Handle a query for the base of this backend */
-       if ( be_issuffix( be,  nbase->bv_val ) ) {
+       if ( be_issuffix( be, nbase ) ) {
                struct berval   vals[2];
 
                vals[1].bv_val = NULL;
@@ -174,12 +174,14 @@ passwd_back_search(
                }
 
        } else {
-               parent = dn_parent( be, nbase->bv_val );
+               if (! be_issuffix( be, nbase ) ) {
+                       dnParent( nbase, &parent );
+               }
 
                /* This backend is only one layer deep. Don't answer requests for
                 * anything deeper than that.
                 */
-               if( !be_issuffix( be, parent ) ) {
+               if( !be_issuffix( be, &parent ) ) {
                        int i;
                        for( i=0; be->be_nsuffix[i] != NULL; i++ ) {
                                if( dnIsSuffix( nbase, be->be_nsuffix[i] ) ) {
@@ -203,7 +205,7 @@ passwd_back_search(
                }
 
                if ( (pw = getpwnam( rdn[0][0]->la_value.bv_val )) == NULL ) {
-                       matched = parent;
+                       matched = parent.bv_val;
                        err = LDAP_NO_SUCH_OBJECT;
                        goto done;
                }