From: Howard Chu Date: Wed, 26 Dec 2001 23:26:17 +0000 (+0000) Subject: Some more (incomplete) struct berval conversion X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~477 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=66dc664930cc9f9dd3eb5c12669895fa33c32ccc;p=openldap Some more (incomplete) struct berval conversion --- diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index 33a2e2f08e..47d9be2fa2 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -93,13 +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_ndn ); + pdn = dn_parent( be, e->e_nname.bv_val ); if( pdn != NULL && *pdn != '\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, pdn, &p, &matched, 0 ); + rc = bdb_dn2entry( be, ltid, &pbv, &p, &matched, 0 ); switch( rc ) { case 0: diff --git a/servers/slapd/back-bdb/bind.c b/servers/slapd/back-bdb/bind.c index 04be2e37e4..fb43f683fc 100644 --- a/servers/slapd/back-bdb/bind.c +++ b/servers/slapd/back-bdb/bind.c @@ -43,7 +43,7 @@ bdb_bind( Debug( LDAP_DEBUG_ARGS, "==> bdb_bind: dn: %s\n", dn->bv_val, 0, 0); /* get entry */ - rc = bdb_dn2entry( be, NULL, ndn->bv_val, &e, &matched, 0 ); + rc = bdb_dn2entry( be, NULL, ndn, &e, &matched, 0 ); switch(rc) { case DB_NOTFOUND: diff --git a/servers/slapd/back-bdb/compare.c b/servers/slapd/back-bdb/compare.c index ce394d387b..b339141ac6 100644 --- a/servers/slapd/back-bdb/compare.c +++ b/servers/slapd/back-bdb/compare.c @@ -32,7 +32,7 @@ bdb_compare( int manageDSAit = get_manageDSAit( op ); /* get entry */ - rc = bdb_dn2entry( be, NULL, ndn->bv_val, &e, &matched, 0 ); + rc = bdb_dn2entry( be, NULL, ndn, &e, &matched, 0 ); switch( rc ) { case DB_NOTFOUND: diff --git a/servers/slapd/back-bdb/delete.c b/servers/slapd/back-bdb/delete.c index 442a992a69..0d93ff95a0 100644 --- a/servers/slapd/back-bdb/delete.c +++ b/servers/slapd/back-bdb/delete.c @@ -71,7 +71,7 @@ retry: /* transaction retry */ op->o_private = &opinfo; /* get entry for read/modify/write */ - rc = bdb_dn2entry( be, ltid, ndn->bv_val, &e, &matched, DB_RMW ); + rc = bdb_dn2entry( be, ltid, ndn, &e, &matched, DB_RMW ); switch( rc ) { case 0: @@ -120,8 +120,12 @@ retry: /* transaction retry */ pdn = dn_parent( be, ndn->bv_val ); if( pdn != NULL && *pdn != '\0' ) { + struct berval pbv; + + pbv.bv_len = ndn->bv_len - (pdn - ndn->bv_val); + pbv.bv_val = pdn; /* get parent */ - rc = bdb_dn2entry( be, ltid, pdn, &p, NULL, 0 ); + rc = bdb_dn2entry( be, ltid, &pbv, &p, NULL, 0 ); switch( rc ) { case 0: @@ -208,7 +212,7 @@ retry: /* transaction retry */ goto done; } - rc = bdb_dn2id_children( be, ltid, e->e_ndn ); + rc = bdb_dn2id_children( be, ltid, &e->e_nname ); if( rc != DB_NOTFOUND ) { switch( rc ) { case DB_LOCK_DEADLOCK: diff --git a/servers/slapd/back-bdb/dn2entry.c b/servers/slapd/back-bdb/dn2entry.c index 5ad00ac209..b95ae4ea6a 100644 --- a/servers/slapd/back-bdb/dn2entry.c +++ b/servers/slapd/back-bdb/dn2entry.c @@ -21,7 +21,7 @@ int bdb_dn2entry( BackendDB *be, DB_TXN *tid, - const char *dn, + struct berval *dn, Entry **e, Entry **matched, int flags ) @@ -31,7 +31,7 @@ bdb_dn2entry( char *matchedDN = NULL; Debug(LDAP_DEBUG_TRACE, "bdb_dn2entry(\"%s\")\n", - dn, 0, 0 ); + dn->bv_val, 0, 0 ); *e = NULL; diff --git a/servers/slapd/back-bdb/dn2id.c b/servers/slapd/back-bdb/dn2id.c index a2d6883929..c764d5f3fe 100644 --- a/servers/slapd/back-bdb/dn2id.c +++ b/servers/slapd/back-bdb/dn2id.c @@ -194,7 +194,7 @@ int bdb_dn2id( BackendDB *be, DB_TXN *txn, - const char *dn, + struct berval *dn, ID *id ) { int rc; @@ -202,13 +202,13 @@ bdb_dn2id( struct bdb_info *bdb = (struct bdb_info *) be->be_private; DB *db = bdb->bi_dn2id->bdi_db; - Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id( \"%s\" )\n", dn, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id( \"%s\" )\n", dn->bv_val, 0, 0 ); DBTzero( &key ); - key.size = strlen( dn ) + 2; + key.size = dn->bv_len + 2; key.data = ch_malloc( key.size ); ((char *)key.data)[0] = DN_BASE_PREFIX; - AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 ); + AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 ); /* store the ID */ DBTzero( &data ); @@ -235,7 +235,7 @@ int bdb_dn2id_matched( BackendDB *be, DB_TXN *txn, - const char *in, + struct berval *in, ID *id, char **matchedDN ) { @@ -243,14 +243,16 @@ bdb_dn2id_matched( DBT key, data; struct bdb_info *bdb = (struct bdb_info *) be->be_private; DB *db = bdb->bi_dn2id->bdi_db; - const char *dn = in; + char *buf, *dn; - Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_matched( \"%s\" )\n", dn, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_matched( \"%s\" )\n", in->bv_val, 0, 0 ); DBTzero( &key ); - key.size = strlen( dn ) + 2; - key.data = ch_malloc( key.size ); - ((char *)key.data)[0] = DN_BASE_PREFIX; + key.size = in->bv_len + 2; + buf = ch_malloc( key.size ); + key.data = buf; + dn = buf+1; + AC_MEMCPY( dn, in->bv_val, key.size - 1 ); /* store the ID */ DBTzero( &data ); @@ -261,7 +263,7 @@ bdb_dn2id_matched( *matchedDN = NULL; while(1) { - AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 ); + dn[-1] = DN_BASE_PREFIX; *id = NOID; @@ -278,8 +280,9 @@ bdb_dn2id_matched( break; } + key.size -= pdn - dn; dn = pdn; - key.size = strlen( dn ) + 2; + key.data = pdn - 1; } else if ( rc == 0 ) { if( data.size != sizeof( ID ) ) { @@ -289,7 +292,7 @@ bdb_dn2id_matched( (long) sizeof(ID), (long) data.size, 0 ); } - if( in != dn ) { + if( dn != buf+1 ) { *matchedDN = (char *) dn; } @@ -306,7 +309,7 @@ bdb_dn2id_matched( } } - ch_free( key.data ); + ch_free( buf ); return rc; } @@ -314,7 +317,7 @@ int bdb_dn2id_children( BackendDB *be, DB_TXN *txn, - const char *dn ) + struct berval *dn ) { int rc; DBT key, data; @@ -323,13 +326,13 @@ bdb_dn2id_children( ID id; Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_children( %s )\n", - dn, 0, 0 ); + dn->bv_val, 0, 0 ); DBTzero( &key ); - key.size = strlen( dn ) + 2; + key.size = dn->bv_len + 2; key.data = ch_malloc( key.size ); ((char *)key.data)[0] = DN_ONE_PREFIX; - AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 ); + AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 ); /* we actually could do a empty get... */ DBTzero( &data ); @@ -352,7 +355,7 @@ bdb_dn2id_children( int bdb_dn2idl( BackendDB *be, - const char *dn, + struct berval *dn, int prefix, ID *ids ) { @@ -361,19 +364,19 @@ bdb_dn2idl( struct bdb_info *bdb = (struct bdb_info *) be->be_private; DB *db = bdb->bi_dn2id->bdi_db; - Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl( \"%s\" )\n", dn, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl( \"%s\" )\n", dn->bv_val, 0, 0 ); - if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn)) + if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn->bv_val)) { BDB_IDL_ALL(bdb, ids); return 0; } DBTzero( &key ); - key.size = strlen( dn ) + 2; + key.size = dn->bv_len + 2; key.data = ch_malloc( key.size ); ((char *)key.data)[0] = prefix; - AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 ); + AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 ); rc = bdb_idl_fetch_key( be, db, NULL, &key, ids ); @@ -562,8 +565,6 @@ int bdb_build_tree( * Note that this code always uses be_suffix[0], so defining * multiple suffixes for a single backend won't work! */ - bdb->bi_sufflen = be->be_suffix[0]->bv_len; - rdns = ldap_explode_dn(be->be_nsuffix[0]->bv_val, 0); for (i=0; rdns[i]; i++); bdb->bi_nrdns = i; @@ -603,16 +604,18 @@ int bdb_fix_dn( ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr); o = bdb_find_id_node(id, bdb->bi_tree); - rlen = bdb->bi_sufflen + 1; + rlen = be->be_suffix[0]->bv_len + 1; nrlen = be->be_nsuffix[0]->bv_len + 1; for (n = o; n; n=n->i_parent) { rlen += n->i_rdn->rdn.bv_len + 1; nrlen += n->i_rdn->nrdn.bv_len + 1; } - e->e_dn = ch_malloc(rlen + nrlen); - e->e_ndn = e->e_dn + rlen; - ptr = e->e_dn; - nptr = e->e_ndn; + e->e_name.bv_len = rlen - 1; + e->e_nname.bv_len = nrlen - 1; + e->e_name.bv_val = ch_malloc(rlen + nrlen); + e->e_nname.bv_val = e->e_name.bv_val + rlen; + ptr = e->e_name.bv_val; + nptr = e->e_nname.bv_val; for (n = o; n; n=n->i_parent) { ptr = slap_strcopy(ptr, n->i_rdn->rdn.bv_val); *ptr++ = ','; @@ -739,7 +742,7 @@ int bdb_dn2id_matched( BackendDB *be, DB_TXN *txn, - const char *in, + struct berval *in, ID *id, char **matchedDN ) { @@ -752,12 +755,12 @@ bdb_dn2id_matched( return DB_NOTFOUND; p = bdb->bi_troot; - if (be_issuffix(be, in)) { + if (be_issuffix(be, in->bv_val)) { *id = p->i_id; return 0; } - rdns = ldap_explode_dn(in, 0); + rdns = ldap_explode_dn(in->bv_val, 0); for (i=0; rdns[i]; i++); i -= bdb->bi_nrdns; if (i < 0) @@ -796,7 +799,7 @@ int bdb_dn2id( BackendDB *be, DB_TXN *txn, - const char *dn, + struct berval *dn, ID *id ) { return bdb_dn2id_matched(be, txn, dn, id, NULL); @@ -806,7 +809,7 @@ int bdb_dn2id_children( BackendDB *be, DB_TXN *txn, - const char *dn ) + struct berval *dn ) { int rc; struct bdb_info *bdb = (struct bdb_info *) be->be_private; @@ -860,7 +863,7 @@ insert_sub( int bdb_dn2idl( BackendDB *be, - const char *dn, + struct berval *dn, int prefix, ID *ids ) { @@ -869,7 +872,7 @@ bdb_dn2idl( ID id; idNode *n; - if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn)) { + if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn->bv_val)) { BDB_IDL_ALL(bdb, ids); return 0; } diff --git a/servers/slapd/back-bdb/modify.c b/servers/slapd/back-bdb/modify.c index 47ee9f247e..a22713c755 100644 --- a/servers/slapd/back-bdb/modify.c +++ b/servers/slapd/back-bdb/modify.c @@ -208,7 +208,7 @@ retry: /* transaction retry */ op->o_private = &opinfo; /* get entry */ - rc = bdb_dn2entry( be, ltid, ndn->bv_val, &e, &matched, 0 ); + rc = bdb_dn2entry( be, ltid, ndn, &e, &matched, 0 ); if ( rc != 0 ) { Debug( LDAP_DEBUG_TRACE, diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index 91b6a00cb3..a30440f536 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -105,7 +105,7 @@ retry: /* transaction retry */ op->o_private = &opinfo; /* get entry */ - rc = bdb_dn2entry( be, ltid, ndn->bv_val, &e, &matched, 0 ); + rc = bdb_dn2entry( be, ltid, ndn, &e, &matched, 0 ); switch( rc ) { case 0: diff --git a/servers/slapd/back-bdb/passwd.c b/servers/slapd/back-bdb/passwd.c index 450a7d3273..7da1adc28e 100644 --- a/servers/slapd/back-bdb/passwd.c +++ b/servers/slapd/back-bdb/passwd.c @@ -38,7 +38,7 @@ bdb_exop_passwd( struct berval *id = NULL; struct berval *new = NULL; - char *dn; + struct berval *dn; assert( reqoid != NULL ); assert( strcmp( LDAP_EXOP_X_MODIFY_PASSWD, reqoid ) == 0 ); @@ -73,12 +73,12 @@ bdb_exop_passwd( goto done; } - dn = id ? id->bv_val : op->o_dn.bv_val; + dn = id ? id : &op->o_dn; Debug( LDAP_DEBUG_TRACE, "bdb_exop_passwd: \"%s\"%s\n", - dn, id ? " (proxy)" : "", 0 ); + dn->bv_val, id ? " (proxy)" : "", 0 ); - if( dn == NULL || dn[0] == '\0' ) { + if( dn->bv_len == 0 ) { *text = "No password is associated with the Root DSE"; rc = LDAP_OPERATIONS_ERROR; goto done; diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index 5323b643b9..5861142f89 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -58,7 +58,7 @@ bdb_db_cache( * dn2entry.c */ int bdb_dn2entry LDAP_P(( BackendDB *be, DB_TXN *tid, - const char *dn, Entry **e, Entry **matched, int flags )); + struct berval *dn, Entry **e, Entry **matched, int flags )); /* * dn2id.c @@ -66,13 +66,13 @@ int bdb_dn2entry LDAP_P(( BackendDB *be, DB_TXN *tid, int bdb_dn2id( BackendDB *be, DB_TXN *tid, - const char *dn, + struct berval *dn, ID *id ); int bdb_dn2id_matched( BackendDB *be, DB_TXN *tid, - const char *dn, + struct berval *dn, ID *id, char **matchedDN ); @@ -91,12 +91,12 @@ int bdb_dn2id_delete( int bdb_dn2id_children( BackendDB *be, DB_TXN *tid, - const char *dn ); + struct berval *dn ); int bdb_dn2idl( BackendDB *be, - const char *dn, + struct berval *dn, int prefix, ID *ids ); diff --git a/servers/slapd/back-bdb/referral.c b/servers/slapd/back-bdb/referral.c index 7a827ed2b6..941a34d042 100644 --- a/servers/slapd/back-bdb/referral.c +++ b/servers/slapd/back-bdb/referral.c @@ -36,7 +36,7 @@ bdb_referrals( } /* get entry */ - rc = bdb_dn2entry( be, NULL, ndn->bv_val, &e, &matched, 0 ); + rc = bdb_dn2entry( be, NULL, ndn, &e, &matched, 0 ); switch(rc) { case DB_NOTFOUND: diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index d930f9d09c..66772e42a4 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -78,7 +78,7 @@ bdb_search( } else #endif { - rc = bdb_dn2entry( be, NULL, nbase->bv_val, &e, &matched, 0 ); + rc = bdb_dn2entry( be, NULL, nbase, &e, &matched, 0 ); } switch(rc) {