From: Howard Chu Date: Thu, 27 Dec 2001 01:38:15 +0000 (+0000) Subject: More struct berval fixes X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~461 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ef31250591144910405471748e66ec2118100151;p=openldap More struct berval fixes --- diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index 47d9be2fa2..9ff3295b2e 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -21,7 +21,7 @@ bdb_add( Entry *e ) { struct bdb_info *bdb = (struct bdb_info *) be->be_private; - char *pdn = NULL; + struct berval pdn; Entry *p = NULL; int rc; const char *text; @@ -93,17 +93,17 @@ retry: rc = txn_abort( ltid ); * If the parent does not exist, only allow the "root" user to * add the entry. */ - pdn = dn_parent( be, e->e_nname.bv_val ); + pdn.bv_val = dn_parent( be, e->e_nname.bv_val ); + if (pdn.bv_val == NULL) + pdn.bv_len = 0; + else + pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_nname.bv_val); - if( pdn != NULL && *pdn != '\0' ) { + if( pdn.bv_len != 0 ) { Entry *matched = NULL; - struct berval pbv; - - pbv.bv_val = pdn; - pbv.bv_len = e->e_nname.bv_len - (pdn - e->e_nname.bv_val); /* get parent */ - rc = bdb_dn2entry( be, ltid, &pbv, &p, &matched, 0 ); + rc = bdb_dn2entry( be, ltid, &pdn, &p, &matched, 0 ); switch( rc ) { case 0: @@ -214,7 +214,7 @@ retry: rc = txn_abort( ltid ); } else { Debug( LDAP_DEBUG_TRACE, "bdb_add: %s denied\n", - pdn == NULL ? "suffix" : "entry at root", + pdn.bv_len == 0 ? "suffix" : "entry at root", 0, 0 ); rc = LDAP_INSUFFICIENT_ACCESS; goto return_results; @@ -223,7 +223,7 @@ retry: rc = txn_abort( ltid ); } /* dn2id index */ - rc = bdb_dn2id_add( be, ltid, pdn, e ); + rc = bdb_dn2id_add( be, ltid, &pdn, e ); if ( rc != 0 ) { Debug( LDAP_DEBUG_TRACE, "bdb_add: dn2id_add failed: %s (%d)\n", db_strerror(rc), rc, 0 ); diff --git a/servers/slapd/back-bdb/dn2id.c b/servers/slapd/back-bdb/dn2id.c index c764d5f3fe..b5a8bc91ef 100644 --- a/servers/slapd/back-bdb/dn2id.c +++ b/servers/slapd/back-bdb/dn2id.c @@ -18,14 +18,14 @@ int bdb_dn2id_add( BackendDB *be, DB_TXN *txn, - char *pdn, + struct berval *pbv, Entry *e ) { struct bdb_info *bdb = (struct bdb_info *) be->be_private; DB *db = bdb->bi_dn2id->bdi_db; int rc; DBT key, data; - char *buf, *ptr; + char *buf, *ptr, *pdn; Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_add( \"%s\", 0x%08lx )\n", e->e_ndn, (long) e->e_id, 0 ); @@ -636,7 +636,7 @@ int bdb_dn2id_add( BackendDB *be, DB_TXN *txn, - char *pdn, + struct berval *pdn, Entry *e ) { struct bdb_info *bdb = (struct bdb_info *) be->be_private; diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index f9058b080b..ded56dad70 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -163,7 +163,10 @@ retry: /* transaction retry */ } p_ndn.bv_val = dn_parent( be, e->e_ndn ); - p_ndn.bv_len = e->e_nname.bv_len - (p_ndn.bv_val - 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; np_ndn = &p_ndn; if ( p_ndn.bv_len != 0 ) { /* Make sure parent entry exist and we can write its @@ -207,7 +210,10 @@ retry: /* transaction retry */ p_ndn.bv_val, 0, 0 ); p_dn.bv_val = dn_parent( be, e->e_dn ); - p_dn.bv_len = e->e_name.bv_len - (p_dn.bv_val - 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; Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: parent dn=%s\n", @@ -572,7 +578,7 @@ retry: /* transaction retry */ e->e_nname = *new_ndn; /* add new one */ - rc = bdb_dn2id_add( be, ltid, np_ndn->bv_val, e ); + rc = bdb_dn2id_add( be, ltid, np_ndn, e ); if ( rc != 0 ) { switch( rc ) { case DB_LOCK_DEADLOCK: diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index 30d7509f5c..802a81361d 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -79,7 +79,7 @@ int bdb_dn2id_matched( int bdb_dn2id_add( BackendDB *be, DB_TXN *tid, - char *pdn, + struct berval *pdn, Entry *e ); int bdb_dn2id_delete( diff --git a/servers/slapd/back-bdb/tools.c b/servers/slapd/back-bdb/tools.c index 992fb7346b..2e102ae0ae 100644 --- a/servers/slapd/back-bdb/tools.c +++ b/servers/slapd/back-bdb/tools.c @@ -117,7 +117,7 @@ ID bdb_tool_entry_put( int rc; struct bdb_info *bdb = (struct bdb_info *) be->be_private; DB_TXN *tid = NULL; - char *pdn; + struct berval pdn; assert( be != NULL ); assert( slapMode & SLAP_TOOL_MODE ); @@ -145,8 +145,12 @@ ID bdb_tool_entry_put( } /* add dn2id indices */ - pdn = dn_parent( be, e->e_ndn ); - rc = bdb_dn2id_add( be, tid, pdn, e ); + pdn.bv_val = dn_parent( be, e->e_ndn ); + if (pdn.bv_val) + pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_ndn); + else + pdn.bv_len = 0; + rc = bdb_dn2id_add( be, tid, &pdn, e ); if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, "=> bdb_tool_entry_put: dn2id_add failed: %s (%d)\n", @@ -202,7 +206,7 @@ int bdb_tool_entry_reindex( int rc; Entry *e; DB_TXN *tid = NULL; - char *pdn; + struct berval pdn; Debug( LDAP_DEBUG_ARGS, "=> bdb_tool_entry_reindex( %ld )\n", (long) id, 0, 0 ); @@ -237,8 +241,12 @@ int bdb_tool_entry_reindex( (long) id, e->e_dn, 0 ); /* add dn2id indices */ - pdn = dn_parent( be, e->e_ndn ); - rc = bdb_dn2id_add( be, tid, pdn, e ); + pdn.bv_val = dn_parent( be, e->e_ndn ); + if (pdn.bv_val) + pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_ndn); + else + pdn.bv_len = 0; + rc = bdb_dn2id_add( be, tid, &pdn, e ); if( rc != 0 && rc != DB_KEYEXIST ) { Debug( LDAP_DEBUG_ANY, "=> bdb_tool_entry_reindex: dn2id_add failed: %s (%d)\n", diff --git a/servers/slapd/back-ldbm/modrdn.c b/servers/slapd/back-ldbm/modrdn.c index 3dab57dbb2..f6a9d9be87 100644 --- a/servers/slapd/back-ldbm/modrdn.c +++ b/servers/slapd/back-ldbm/modrdn.c @@ -153,7 +153,10 @@ ldbm_back_modrdn( } p_ndn.bv_val = dn_parent( be, e->e_ndn ); - p_ndn.bv_len = e->e_nname.bv_len - (p_ndn.bv_val - 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 ( p_ndn.bv_len != 0 ) { /* Make sure parent entry exist and we can write its @@ -203,7 +206,10 @@ ldbm_back_modrdn( #endif p_dn.bv_val = dn_parent( be, e->e_dn ); - p_dn.bv_len = e->e_name.bv_len - (p_dn.bv_val - 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; #ifdef NEW_LOGGING LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,