From: Howard Chu Date: Sat, 26 Jan 2002 06:40:56 +0000 (+0000) Subject: Changed be_issuffix and dnParent to struct bervals X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~25 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7f54a89f32c34ec0e109ef3ca41c36545fe42b7c;p=openldap Changed be_issuffix and dnParent to struct bervals --- diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index 56b902f1f8..af4f37a46a 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -104,16 +104,14 @@ retry: /* transaction retry */ * If the parent does not exist, only allow the "root" user to * add the entry. */ - if ( be_issuffix( be, e->e_nname.bv_val ) ) { - pdn.bv_len = 0; - pdn.bv_val = ""; + if ( be_issuffix( be, &e->e_nname ) ) { + pdn = slap_empty_bv; } else { - rc = dnParent( e->e_nname.bv_val, (const char **)&pdn.bv_val ); + rc = dnParent( &e->e_nname, &pdn ); if ( rc != LDAP_SUCCESS ) { text = "internal error"; goto return_results; } - pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_nname.bv_val); } if( pdn.bv_len != 0 ) { @@ -244,7 +242,8 @@ retry: /* transaction retry */ * must be adding entry at suffix or with parent "" */ 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; /* check parent for "children" acl */ diff --git a/servers/slapd/back-bdb/delete.c b/servers/slapd/back-bdb/delete.c index 5c1588ae16..7658c84fc1 100644 --- a/servers/slapd/back-bdb/delete.c +++ b/servers/slapd/back-bdb/delete.c @@ -81,15 +81,12 @@ retry: /* transaction retry */ opinfo.boi_err = 0; op->o_private = &opinfo; - if ( !be_issuffix( be, ndn->bv_val ) ) { - rc = dnParent( ndn->bv_val, &pdn.bv_val ); + if ( !be_issuffix( be, ndn ) ) { + rc = dnParent( ndn, &pdn ); if ( rc != LDAP_SUCCESS ) { text = "internal error"; goto return_results; } - if (pdn.bv_val && pdn.bv_val[0]) { - pdn.bv_len = ndn->bv_len - (pdn.bv_val - ndn->bv_val); - } } if( pdn.bv_len != 0 ) { @@ -151,7 +148,8 @@ retry: /* transaction retry */ } 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; /* check parent for "children" acl */ diff --git a/servers/slapd/back-bdb/dn2id.c b/servers/slapd/back-bdb/dn2id.c index 1be0a4bbfd..33fb362256 100644 --- a/servers/slapd/back-bdb/dn2id.c +++ b/servers/slapd/back-bdb/dn2id.c @@ -25,7 +25,8 @@ bdb_dn2id_add( DB *db = bdb->bi_dn2id->bdi_db; int rc; DBT key, data; - char *buf, *ptr, *pdn; + char *buf; + struct berval ptr, pdn; Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_add( \"%s\", 0x%08lx )\n", e->e_ndn, (long) e->e_id, 0 ); @@ -36,8 +37,10 @@ bdb_dn2id_add( buf = ch_malloc( key.size ); key.data = buf; buf[0] = DN_BASE_PREFIX; - ptr = buf + 1; - AC_MEMCPY( ptr, e->e_ndn, key.size - 1 ); + ptr.bv_val = buf + 1; + ptr.bv_len = e->e_nname.bv_len; + AC_MEMCPY( ptr.bv_val, e->e_nname.bv_val, e->e_nname.bv_len ); + ptr.bv_val[ptr.bv_len] = '\0'; DBTzero( &data ); data.data = (char *) &e->e_id; @@ -51,27 +54,27 @@ bdb_dn2id_add( goto done; } - if( !be_issuffix( be, ptr )) { + if( !be_issuffix( be, &ptr )) { buf[0] = DN_SUBTREE_PREFIX; rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id ); if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n", - ptr, rc, 0 ); + ptr.bv_val, rc, 0 ); goto done; } - rc = dnParent( ptr, (const char **)&pdn ); + rc = dnParent( &ptr, &pdn ); if ( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_add: dnParent(\"%s\") failed\n", - ptr, 0, 0 ); + ptr.bv_val, 0, 0 ); goto done; } - key.size -= pdn - ptr; - pdn[-1] = DN_ONE_PREFIX; - key.data = pdn - 1; + key.size = pdn.bv_len + 2; + pdn.bv_val[-1] = DN_ONE_PREFIX; + key.data = pdn.bv_val-1; ptr = pdn; rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id ); @@ -79,32 +82,32 @@ bdb_dn2id_add( if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_add: parent (%s) insert failed: %d\n", - ptr, rc, 0 ); + ptr.bv_val, rc, 0 ); goto done; } } - while( !be_issuffix( be, ptr )) { - ptr[-1] = DN_SUBTREE_PREFIX; + while( !be_issuffix( be, &ptr )) { + ptr.bv_val[-1] = DN_SUBTREE_PREFIX; rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id ); if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n", - ptr, rc, 0 ); + ptr.bv_val, rc, 0 ); break; } - rc = dnParent( ptr, &pdn ); + rc = dnParent( &ptr, &pdn ); if ( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_add: dnParent(\"%s\") failed\n", - ptr, 0, 0 ); + ptr.bv_val, 0, 0 ); goto done; } - key.size -= pdn - ptr; - key.data = pdn - 1; + key.size = pdn.bv_len + 2; + key.data = pdn.bv_val - 1; ptr = pdn; } @@ -118,14 +121,15 @@ int bdb_dn2id_delete( BackendDB *be, DB_TXN *txn, - char *pdn, + char *pdnc, Entry *e ) { struct bdb_info *bdb = (struct bdb_info *) be->be_private; DB *db = bdb->bi_dn2id->bdi_db; int rc; DBT key; - char *buf, *ptr; + char *buf; + struct berval pdn, ptr; Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_delete( \"%s\", 0x%08lx )\n", e->e_ndn, e->e_id, 0 ); @@ -136,8 +140,10 @@ bdb_dn2id_delete( key.data = buf; key.flags = DB_DBT_USERMEM; buf[0] = DN_BASE_PREFIX; - ptr = buf+1; - AC_MEMCPY( ptr, e->e_ndn, key.size - 1 ); + ptr.bv_val = buf+1; + ptr.bv_len = e->e_nname.bv_len; + AC_MEMCPY( ptr.bv_val, e->e_nname.bv_val, e->e_nname.bv_len ); + ptr.bv_val[ptr.bv_len] = '\0'; /* delete it */ rc = db->del( db, txn, &key, 0 ); @@ -147,27 +153,27 @@ bdb_dn2id_delete( goto done; } - if( !be_issuffix( be, ptr )) { + if( !be_issuffix( be, &ptr )) { buf[0] = DN_SUBTREE_PREFIX; rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id ); if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n", - ptr, rc, 0 ); + ptr.bv_val, rc, 0 ); goto done; } - rc = dnParent( ptr, &pdn ); + rc = dnParent( &ptr, &pdn ); if ( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_delete: dnParent(\"%s\") failed\n", - ptr, 0, 0 ); + ptr.bv_val, 0, 0 ); goto done; } - key.size -= pdn - ptr; - pdn[-1] = DN_ONE_PREFIX; - key.data = pdn - 1; + key.size = pdn.bv_len + 2; + pdn.bv_val[-1] = DN_ONE_PREFIX; + key.data = pdn.bv_val - 1; ptr = pdn; rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id ); @@ -175,31 +181,31 @@ bdb_dn2id_delete( if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_delete: parent (%s) delete failed: %d\n", - ptr, rc, 0 ); + ptr.bv_val, rc, 0 ); goto done; } } - while( !be_issuffix( be, ptr )) { - ptr[-1] = DN_SUBTREE_PREFIX; + while( !be_issuffix( be, &ptr )) { + ptr.bv_val[-1] = DN_SUBTREE_PREFIX; rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id ); if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n", - ptr, rc, 0 ); + ptr.bv_val, rc, 0 ); goto done; } - rc = dnParent( ptr, &pdn ); + rc = dnParent( &ptr, &pdn ); if ( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_delete: dnParent(\"%s\") failed\n", - ptr, 0, 0 ); + ptr.bv_val, 0, 0 ); goto done; } - key.size -= pdn - ptr; - key.data = pdn - 1; + key.size = pdn.bv_len + 2; + key.data = pdn.bv_val - 1; ptr = pdn; } @@ -310,29 +316,26 @@ bdb_dn2id_matched( } if( rc == DB_NOTFOUND ) { - char *pdn = NULL; + struct berval pdn; - if ( ! be_issuffix( be, dn.bv_val ) ) { - rc = dnParent( dn.bv_val, &pdn ); + if ( ! be_issuffix( be, &dn ) ) { + rc = dnParent( &dn, &pdn ); if ( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_matched: dnParent(\"%s\") failed\n", - dn, 0, 0 ); + dn.bv_val, 0, 0 ); break; } - } - - if( pdn == NULL || *pdn == '\0' ) { + } else { Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_matched: no match\n", 0, 0, 0 ); break; } - key.size -= pdn - dn.bv_val; - dn.bv_val = pdn; - dn.bv_len = key.size - 2; - key.data = pdn - 1; + key.size = pdn.bv_len + 2; + dn = pdn; + key.data = pdn.bv_val - 1; } else if ( rc == 0 ) { if( data.size != sizeof( ID ) ) { @@ -417,7 +420,7 @@ bdb_dn2idl( Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl( \"%s\" )\n", dn->bv_val, 0, 0 ); - if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn->bv_val)) + if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn)) { BDB_IDL_ALL(bdb, ids); return 0; @@ -808,7 +811,7 @@ bdb_dn2id_matched( return DB_NOTFOUND; p = bdb->bi_troot; - if (be_issuffix(be, in->bv_val)) { + if (be_issuffix(be, in)) { *id = p->i_id; return 0; } @@ -917,7 +920,7 @@ bdb_dn2idl( ID id; idNode *n; - if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn->bv_val)) { + if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn)) { BDB_IDL_ALL(bdb, ids); return 0; } diff --git a/servers/slapd/back-bdb/idl.c b/servers/slapd/back-bdb/idl.c index a4b010b5f9..f98dc3aee7 100644 --- a/servers/slapd/back-bdb/idl.c +++ b/servers/slapd/back-bdb/idl.c @@ -232,7 +232,7 @@ bdb_idl_fetch_key( { DBC *cursor; ID buf[BDB_IDL_UM_SIZE]; - ID *i, *j; + ID *i; void *ptr; size_t len; int rc2; @@ -254,6 +254,8 @@ bdb_idl_fetch_key( if (rc == 0) { i = ids; while (rc == 0) { + u_int8_t *j; + DB_MULTIPLE_INIT( ptr, &data ); while (ptr) { DB_MULTIPLE_NEXT(ptr, &data, j, len); diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index e3f3e44a4d..45f25b557f 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -170,16 +170,14 @@ retry: /* transaction retry */ goto done; } - if ( be_issuffix( be, e->e_nname.bv_val ) ) { - p_ndn.bv_len = 0; - p_ndn.bv_val = ""; + if ( be_issuffix( be, &e->e_nname ) ) { + p_ndn = slap_empty_bv; } else { - rc = dnParent( e->e_nname.bv_val, (const char **)&p_ndn.bv_val ); + rc = dnParent( &e->e_nname, &p_ndn ); if ( rc != LDAP_SUCCESS ) { text = "internal error"; goto return_results; } - p_ndn.bv_len = e->e_nname.bv_len - (p_ndn.bv_val - e->e_nname.bv_val); } np_ndn = &p_ndn; if ( p_ndn.bv_len != 0 ) { @@ -223,16 +221,14 @@ retry: /* transaction retry */ "bdb_modrdn: wr to children of entry %s OK\n", p_ndn.bv_val, 0, 0 ); - if ( be_issuffix( be, e->e_name.bv_val ) ) { - p_dn.bv_len = 0; - p_dn.bv_val = ""; + if ( p_ndn.bv_val == slap_empty_bv.bv_val ) { + p_dn = slap_empty_bv; } else { - rc = dnParent( e->e_name.bv_val, &p_dn.bv_val ); + rc = dnParent( &e->e_name, &p_dn ); if ( rc != LDAP_SUCCESS ) { text = "internal error"; goto return_results; } - p_dn.bv_len = e->e_name.bv_len - (p_dn.bv_val - e->e_name.bv_val); } Debug( LDAP_DEBUG_TRACE, @@ -243,7 +239,8 @@ retry: /* transaction retry */ /* no parent, modrdn entry directly under root */ 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; @@ -364,7 +361,8 @@ retry: /* transaction retry */ /* no parent, modrdn entry directly under root */ 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; /* check parent for "children" acl */ diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index 7645674c15..239a70de7f 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -352,12 +352,10 @@ bdb_search( /* need to skip alias which deref into scope */ if( scope & LDAP_SCOPE_ONELEVEL ) { - char *pdn; - ber_len_t plen; + struct berval pdn; - if ( dnParent( e->e_nname.bv_val, &pdn ) == LDAP_SUCCESS ) { - plen = e->e_nname.bv_len - ( pdn - e->e_nname.bv_val ); - if ( plen != realbase.bv_len || strcmp( pdn, realbase.bv_val ) ) { + if ( dnParent( &e->e_nname, &pdn ) == LDAP_SUCCESS ) { + if ( ber_bvcmp( pdn, &realbase ) ) { goto loop_continue; } } @@ -401,17 +399,15 @@ bdb_search( /* if it matches the filter and scope, send it */ rc = test_filter( be, conn, op, e, filter ); if ( rc == LDAP_COMPARE_TRUE ) { - char *dn; + struct berval dn; /* check scope */ if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) { - if ( be_issuffix( be, e->e_nname.bv_val ) ) { + if ( be_issuffix( be, &e->e_nname ) ) { scopeok = (realbase.bv_len == 0); } else { - dnParent( e->e_nname.bv_val, (const char **)&dn ); - scopeok = (dn == realbase.bv_val) - ? 1 - : (strcmp( dn, realbase.bv_val ) ? 0 : 1 ); + dnParent( &e->e_nname, &dn ); + scopeok = dn_match( &dn, &realbase ); } } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) { diff --git a/servers/slapd/back-bdb/tools.c b/servers/slapd/back-bdb/tools.c index ef9219e22d..1612db3b31 100644 --- a/servers/slapd/back-bdb/tools.c +++ b/servers/slapd/back-bdb/tools.c @@ -155,11 +155,10 @@ ID bdb_tool_entry_put( } /* add dn2id indices */ - if ( be_issuffix( be, e->e_nname.bv_val ) ) { - pdn.bv_len = 0; - pdn.bv_val = ""; + if ( be_issuffix( be, &e->e_nname ) ) { + pdn = slap_empty_bv; } else { - rc = dnParent( e->e_nname.bv_val, &pdn.bv_val ); + rc = dnParent( &e->e_nname, &pdn ); if ( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_ANY, "=> bdb_tool_entry_put: " "dnParent(\"%s\") failed\n", @@ -167,7 +166,6 @@ ID bdb_tool_entry_put( goto done; } - pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_nname.bv_val); } rc = bdb_dn2id_add( be, tid, &pdn, e ); if( rc != 0 ) { @@ -272,18 +270,16 @@ int bdb_tool_entry_reindex( (long) id, e->e_dn, 0 ); /* add dn2id indices */ - if ( be_issuffix( be, e->e_nname.bv_val ) ) { - pdn.bv_len = 0; - pdn.bv_val = ""; + if ( be_issuffix( be, &e->e_nname ) ) { + pdn = slap_empty_bv; } else { - rc = dnParent( e->e_nname.bv_val, &pdn.bv_val ); + rc = dnParent( &e->e_nname, &pdn ); if ( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_ANY, "=> bdb_tool_entry_reindex: " "dnParent(\"%s\") failed\n", e->e_nname.bv_val, 0, 0 ); goto done; } - pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_nname.bv_val); } rc = bdb_dn2id_add( be, tid, &pdn, e ); if( rc != 0 && rc != DB_KEYEXIST ) {