From e2c2de11c3617afc1cf0b1bb881ab8230cb6b209 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sat, 8 Dec 2001 10:37:42 +0000 Subject: [PATCH] Converted all use of dn_parent to the in-place version. (Fixed a pdn leak in back-sql along the way.) --- servers/slapd/back-bdb/add.c | 2 +- servers/slapd/back-bdb/delete.c | 2 +- servers/slapd/back-bdb/dn2id.c | 14 +++++++------- servers/slapd/back-bdb/modrdn.c | 4 ++-- servers/slapd/back-bdb/search.c | 4 ++-- servers/slapd/back-bdb/tools.c | 4 ++-- servers/slapd/back-ldbm/add.c | 4 ---- servers/slapd/back-ldbm/delete.c | 2 -- servers/slapd/back-ldbm/dn2id.c | 7 ++----- servers/slapd/back-ldbm/modrdn.c | 3 --- servers/slapd/back-ldbm/search.c | 7 ------- servers/slapd/back-monitor/cache.c | 1 - servers/slapd/back-passwd/search.c | 7 ++----- servers/slapd/back-sql/modify.c | 3 --- servers/slapd/dn.c | 22 +++------------------- servers/slapd/proto-slap.h | 1 - 16 files changed, 22 insertions(+), 65 deletions(-) diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index b098bb499c..8373f69349 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -93,7 +93,7 @@ retry: rc = txn_abort( ltid ); * If the parent does not exist, only allow the "root" user to * add the entry. */ - pdn = dn_parent1( be, e->e_ndn ); + pdn = dn_parent( be, e->e_ndn ); if( pdn != NULL && *pdn != '\0' ) { Entry *matched = NULL; diff --git a/servers/slapd/back-bdb/delete.c b/servers/slapd/back-bdb/delete.c index 47b9ca6708..9094411caf 100644 --- a/servers/slapd/back-bdb/delete.c +++ b/servers/slapd/back-bdb/delete.c @@ -116,7 +116,7 @@ retry: /* transaction retry */ goto done; } - pdn = dn_parent1( be, ndn ); + pdn = dn_parent( be, ndn ); if( pdn != NULL && *pdn != '\0' ) { /* get parent */ diff --git a/servers/slapd/back-bdb/dn2id.c b/servers/slapd/back-bdb/dn2id.c index 22695f4605..8606ea3889 100644 --- a/servers/slapd/back-bdb/dn2id.c +++ b/servers/slapd/back-bdb/dn2id.c @@ -60,7 +60,7 @@ bdb_dn2id_add( goto done; } - pdn = dn_parent1( be, ptr ); + pdn = dn_parent( be, ptr ); if( pdn != NULL ) { key.size -= pdn - ptr; @@ -86,7 +86,7 @@ bdb_dn2id_add( goto done; } ptr = pdn; - pdn = dn_parent1( be, pdn ); + pdn = dn_parent( be, pdn ); } while( pdn != NULL ) { @@ -106,7 +106,7 @@ bdb_dn2id_add( break; } ptr = pdn; - pdn = dn_parent1( be, pdn ); + pdn = dn_parent( be, pdn ); } done: @@ -157,7 +157,7 @@ bdb_dn2id_delete( goto done; } - pdn = dn_parent1( be, ptr ); + pdn = dn_parent( be, ptr ); if( pdn != NULL ) { key.size -= pdn - ptr; @@ -184,7 +184,7 @@ bdb_dn2id_delete( goto done; } ptr = pdn; - pdn = dn_parent1( be, pdn ); + pdn = dn_parent( be, pdn ); } while( pdn != NULL ) { @@ -203,7 +203,7 @@ bdb_dn2id_delete( goto done; } ptr = pdn; - pdn = dn_parent1( be, pdn ); + pdn = dn_parent( be, pdn ); } done: @@ -291,7 +291,7 @@ bdb_dn2id_matched( rc = db->get( db, txn, &key, &data, bdb->bi_db_opflags ); if( rc == DB_NOTFOUND ) { - char *pdn = dn_parent1( be, dn ); + char *pdn = dn_parent( be, dn ); if( pdn == NULL || *pdn == '\0' ) { Debug( LDAP_DEBUG_TRACE, diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index 7bf0378bf1..5e6d149561 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -160,7 +160,7 @@ retry: /* transaction retry */ goto done; } - p_ndn = dn_parent1( be, e->e_ndn ); + p_ndn = dn_parent( be, e->e_ndn ); np_ndn = p_ndn; if ( p_ndn != NULL && p_ndn[ 0 ] != '\0' ) { /* Make sure parent entry exist and we can write its @@ -204,7 +204,7 @@ retry: /* transaction retry */ "bdb_modrdn: wr to children of entry %s OK\n", p_ndn, 0, 0 ); - p_dn = dn_parent1( be, e->e_dn ); + p_dn = dn_parent( be, e->e_dn ); Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: parent dn=%s\n", diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index f578eca689..72f8154811 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -328,7 +328,7 @@ bdb_search( /* need to skip alias which deref into scope */ if( scope & LDAP_SCOPE_ONELEVEL ) { - char *pdn = dn_parent1( NULL, e->e_ndn ); + char *pdn = dn_parent( NULL, e->e_ndn ); if ( pdn != NULL ) { if( strcmp( pdn, realbase ) ) { goto loop_continue; @@ -377,7 +377,7 @@ bdb_search( /* check scope */ if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) { - if ( (dn = dn_parent1( be, e->e_ndn )) != NULL ) { + if ( (dn = dn_parent( be, e->e_ndn )) != NULL ) { scopeok = (dn == realbase) ? 1 : (strcmp( dn, realbase ) ? 0 : 1 ); diff --git a/servers/slapd/back-bdb/tools.c b/servers/slapd/back-bdb/tools.c index 8b68ddeb65..992fb7346b 100644 --- a/servers/slapd/back-bdb/tools.c +++ b/servers/slapd/back-bdb/tools.c @@ -145,7 +145,7 @@ ID bdb_tool_entry_put( } /* add dn2id indices */ - pdn = dn_parent1( be, e->e_ndn ); + pdn = dn_parent( be, e->e_ndn ); rc = bdb_dn2id_add( be, tid, pdn, e ); if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, @@ -237,7 +237,7 @@ int bdb_tool_entry_reindex( (long) id, e->e_dn, 0 ); /* add dn2id indices */ - pdn = dn_parent1( be, e->e_ndn ); + pdn = dn_parent( be, e->e_ndn ); rc = bdb_dn2id_add( be, tid, pdn, e ); if( rc != 0 && rc != DB_KEYEXIST ) { Debug( LDAP_DEBUG_ANY, diff --git a/servers/slapd/back-ldbm/add.c b/servers/slapd/back-ldbm/add.c index ab9b53dede..1a8424f53d 100644 --- a/servers/slapd/back-ldbm/add.c +++ b/servers/slapd/back-ldbm/add.c @@ -123,15 +123,12 @@ ldbm_back_add( ber_bvecfree( refs ); free( matched_dn ); - free( pdn ); return -1; } /* don't need the add lock anymore */ ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); - free(pdn); - if ( ! access_allowed( be, conn, op, p, children, NULL, ACL_WRITE ) ) { @@ -205,7 +202,6 @@ ldbm_back_add( } else { if(pdn != NULL) { assert( *pdn == '\0' ); - free(pdn); } /* no parent, must be adding entry to root */ diff --git a/servers/slapd/back-ldbm/delete.c b/servers/slapd/back-ldbm/delete.c index 7a09fd0fbf..4c17e6cccd 100644 --- a/servers/slapd/back-ldbm/delete.c +++ b/servers/slapd/back-ldbm/delete.c @@ -243,8 +243,6 @@ ldbm_back_delete( rc = 0; return_results:; - if ( pdn != NULL ) free(pdn); - if( p != NULL ) { /* free parent and writer lock */ cache_return_entry_w( &li->li_cache, p ); diff --git a/servers/slapd/back-ldbm/dn2id.c b/servers/slapd/back-ldbm/dn2id.c index f743046aa5..9743094340 100644 --- a/servers/slapd/back-ldbm/dn2id.c +++ b/servers/slapd/back-ldbm/dn2id.c @@ -64,7 +64,7 @@ dn2id_add( free( key.dptr ); if ( rc != -1 ) { - char *pdn = dn_parent( NULL, dn ); + char *pdn = dn_parent( be, dn ); if( pdn != NULL ) { ldbm_datum_init( key ); @@ -75,7 +75,6 @@ dn2id_add( rc = idl_insert_key( be, db, key, id ); ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex ); free( key.dptr ); - free( pdn ); } } @@ -297,7 +296,7 @@ dn2id_delete( { - char *pdn = dn_parent( NULL, dn ); + char *pdn = dn_parent( be, dn ); if( pdn != NULL ) { ldbm_datum_init( key ); @@ -310,7 +309,6 @@ dn2id_delete( ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex ); free( key.dptr ); - free( pdn ); } } @@ -425,7 +423,6 @@ dn2entry_rw( if ( (e = dn2entry_r( be, pdn, matched )) != NULL ) { *matched = e; } - free( pdn ); } return NULL; diff --git a/servers/slapd/back-ldbm/modrdn.c b/servers/slapd/back-ldbm/modrdn.c index 43ab2c557b..26a78a393d 100644 --- a/servers/slapd/back-ldbm/modrdn.c +++ b/servers/slapd/back-ldbm/modrdn.c @@ -790,9 +790,6 @@ return_results: if( new_dn != NULL ) free( new_dn ); if( new_ndn != NULL ) free( new_ndn ); - if( p_dn != NULL ) free( p_dn ); - if( p_ndn != NULL ) free( p_ndn ); - /* LDAP v2 supporting correct attribute handling. */ if( new_rdn_types != NULL ) charray_free( new_rdn_types ); if( new_rdn_vals != NULL ) charray_free( new_rdn_vals ); diff --git a/servers/slapd/back-ldbm/search.c b/servers/slapd/back-ldbm/search.c index 2f83a48288..f4484ecf60 100644 --- a/servers/slapd/back-ldbm/search.c +++ b/servers/slapd/back-ldbm/search.c @@ -346,7 +346,6 @@ searchit: free( pdn ); goto loop_continue; } - free(pdn); } } else if ( dn_issuffix( e->e_ndn, realbase ) ) { @@ -379,12 +378,9 @@ searchit: /* check scope */ if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) { if ( (dn = dn_parent( be, e->e_ndn )) != NULL ) { - (void) dn_normalize( dn ); scopeok = (dn == realbase) ? 1 : (strcmp( dn, realbase ) ? 0 : 1 ); - free( dn ); - } else { scopeok = (realbase == NULL || *realbase == '\0'); } @@ -433,12 +429,9 @@ searchit: /* check scope */ if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) { if ( (dn = dn_parent( be, e->e_ndn )) != NULL ) { - (void) dn_normalize( dn ); scopeok = (dn == realbase) ? 1 : (strcmp( dn, realbase ) ? 0 : 1 ); - free( dn ); - } else { scopeok = (realbase == NULL || *realbase == '\0'); } diff --git a/servers/slapd/back-monitor/cache.c b/servers/slapd/back-monitor/cache.c index f5d70f59e1..b794b40233 100644 --- a/servers/slapd/back-monitor/cache.c +++ b/servers/slapd/back-monitor/cache.c @@ -195,7 +195,6 @@ monitor_cache_dn2entry( /* try with parent/ancestors */ p_ndn = dn_parent( NULL, ndn ); rc = monitor_cache_dn2entry( mi, p_ndn, &e_parent ); - free( p_ndn ); if ( rc || e_parent == NULL) { return( -1 ); } diff --git a/servers/slapd/back-passwd/search.c b/servers/slapd/back-passwd/search.c index 1fd6991090..7143f90088 100644 --- a/servers/slapd/back-passwd/search.c +++ b/servers/slapd/back-passwd/search.c @@ -74,7 +74,7 @@ passwd_back_search( vals[0] = &val; vals[1] = NULL; - matched = ch_strdup( base ); + matched = base; if( scope != LDAP_SCOPE_ONELEVEL ) { char *type; @@ -191,7 +191,7 @@ passwd_back_search( int i; for( i=0; be->be_nsuffix[i] != NULL; i++ ) { if( dn_issuffix( nbase, be->be_nsuffix[i]->bv_val ) ) { - matched = ch_strdup( be->be_suffix[i] ); + matched = be->be_suffix[i]; break; } } @@ -212,7 +212,6 @@ passwd_back_search( if ( (pw = getpwnam( user )) == NULL ) { matched = parent; - parent = NULL; err = LDAP_NO_SUCH_OBJECT; goto done; } @@ -233,8 +232,6 @@ done: err, err == LDAP_NO_SUCH_OBJECT ? matched : NULL, NULL, NULL, NULL ); - if( matched != NULL ) free( matched ); - if( parent != NULL ) free( parent ); if( rdn != NULL ) free( rdn ); if( user != NULL ) free( user ); diff --git a/servers/slapd/back-sql/modify.c b/servers/slapd/back-sql/modify.c index bf4f0bb1ed..9514da0155 100644 --- a/servers/slapd/back-sql/modify.c +++ b/servers/slapd/back-sql/modify.c @@ -336,8 +336,6 @@ int backsql_modrdn(BackendDB *be,Connection *conn,Operation *op, send_ldap_result(conn,op,LDAP_SUCCESS,"",NULL,NULL,NULL); modrdn_return: SQLFreeStmt(sth,SQL_DROP); - if (p_dn) - ch_free(p_dn); if (newSuperior && new_pdn) ch_free(new_pdn); if (new_dn) @@ -462,7 +460,6 @@ int backsql_add(BackendDB *be,Connection *conn,Operation *op,Entry *e) send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL); return 1; } - free(pdn); backsql_BindParamStr(sth,1,e->e_dn,BACKSQL_MAX_DN_LEN); SQLBindParameter(sth,2,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,0,0,&oc->id,0,0); SQLBindParameter(sth,3,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,0,0,&parent_id.id,0,0); diff --git a/servers/slapd/dn.c b/servers/slapd/dn.c index c88eb3c49b..65e775060d 100644 --- a/servers/slapd/dn.c +++ b/servers/slapd/dn.c @@ -313,11 +313,11 @@ dn_match( const char *val, const char *asserted ) } /* - * dn_parent1 - return the dn's parent, in-place + * dn_parent - return the dn's parent, in-place */ char * -dn_parent1( +dn_parent( Backend *be, const char *dn ) { @@ -369,22 +369,6 @@ dn_parent1( return ""; } -/* - * dn_parent - return a copy of the dn of dn's parent - */ - -char * -dn_parent( - Backend *be, - const char *dn -) -{ - dn = dn_parent1( be, dn ); - if( dn != NULL ) - dn = ch_strdup( dn ); - return (char *)dn; -} - char * dn_rdn( Backend *be, const char *dn_in ) @@ -449,7 +433,7 @@ char **dn_subtree( do { charray_add( &subtree, dn ); - dn = dn_parent1( be, dn ); + dn = dn_parent( be, dn ); } while ( dn != NULL ); diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index c1342c65b1..8b3539f745 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -319,7 +319,6 @@ LDAP_SLAPD_F (char *) dn_validate LDAP_P(( char *dn )); LDAP_SLAPD_F (char *) dn_normalize LDAP_P(( char *dn )); LDAP_SLAPD_F (int) dn_match LDAP_P(( const char *val, const char *asserted )); LDAP_SLAPD_F (char *) dn_parent LDAP_P(( Backend *be, const char *dn )); -LDAP_SLAPD_F (char *) dn_parent1 LDAP_P(( Backend *be, const char *dn )); LDAP_SLAPD_F (char **) dn_subtree LDAP_P(( Backend *be, const char *dn )); LDAP_SLAPD_F (char *) dn_rdn LDAP_P(( Backend *be, const char *dn )); LDAP_SLAPD_F (int) dn_issuffix LDAP_P(( const char *dn, const char *suffix )); -- 2.39.5