Back to index

openldap  2.4.31
Functions
dn2id.c File Reference
#include "portable.h"
#include <stdio.h>
#include <ac/string.h>
#include "back-bdb.h"
#include "idl.h"
#include "lutil.h"

Go to the source code of this file.

Functions

int bdb_dn2id_add (Operation *op, DB_TXN *txn, EntryInfo *eip, Entry *e)
int bdb_dn2id_delete (Operation *op, DB_TXN *txn, EntryInfo *eip, Entry *e)
int bdb_dn2id (Operation *op, struct berval *dn, EntryInfo *ei, DB_TXN *txn, DBC **cursor)
int bdb_dn2id_children (Operation *op, DB_TXN *txn, Entry *e)
int bdb_dn2idl (Operation *op, DB_TXN *txn, struct berval *ndn, EntryInfo *ei, ID *ids, ID *stack)

Function Documentation

int bdb_dn2id ( Operation op,
struct berval dn,
EntryInfo ei,
DB_TXN *  txn,
DBC **  cursor 
)

Definition at line 248 of file dn2id.c.

{
       struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
       DB *db = bdb->bi_dn2id->bdi_db;
       int           rc;
       DBT           key, data;
       ID            nid;

       Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id(\"%s\")\n", dn->bv_val, 0, 0 );

       DBTzero( &key );
       key.size = dn->bv_len + 2;
       key.data = op->o_tmpalloc( key.size, op->o_tmpmemctx );
       ((char *)key.data)[0] = DN_BASE_PREFIX;
       AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );

       /* store the ID */
       DBTzero( &data );
       data.data = &nid;
       data.ulen = sizeof(ID);
       data.flags = DB_DBT_USERMEM;

       rc = db->cursor( db, txn, cursor, bdb->bi_db_opflags );

       /* fetch it */
       if ( !rc )
              rc = (*cursor)->c_get( *cursor, &key, &data, DB_SET );

       if( rc != 0 ) {
              Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: get failed: %s (%d)\n",
                     db_strerror( rc ), rc, 0 );
       } else {
              BDB_DISK2ID( &nid, &ei->bei_id );
              Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: got id=0x%lx\n",
                     ei->bei_id, 0, 0 );
       }
       op->o_tmpfree( key.data, op->o_tmpmemctx );
       return rc;
}
int bdb_dn2id_add ( Operation op,
DB_TXN *  txn,
EntryInfo eip,
Entry e 
)

Definition at line 28 of file dn2id.c.

{
       struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
       DB *db = bdb->bi_dn2id->bdi_db;
       int           rc;
       DBT           key, data;
       ID            nid;
       char          *buf;
       struct berval ptr, pdn;

       Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_add 0x%lx: \"%s\"\n",
              e->e_id, e->e_ndn, 0 );
       assert( e->e_id != NOID );

       DBTzero( &key );
       key.size = e->e_nname.bv_len + 2;
       key.ulen = key.size;
       key.flags = DB_DBT_USERMEM;
       buf = op->o_tmpalloc( key.size, op->o_tmpmemctx );
       key.data = buf;
       buf[0] = DN_BASE_PREFIX;
       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 = &nid;
       data.size = sizeof( nid );
       BDB_ID2DISK( e->e_id, &nid );

       /* store it -- don't override */
       rc = db->put( db, txn, &key, &data, DB_NOOVERWRITE );
       if( rc != 0 ) {
              char buf[ SLAP_TEXT_BUFLEN ];
              snprintf( buf, sizeof( buf ), "%s => bdb_dn2id_add dn=\"%s\" ID=0x%lx",
                     op->o_log_prefix, e->e_name.bv_val, e->e_id );
              Debug( LDAP_DEBUG_ANY, "%s: put failed: %s %d\n",
                     buf, db_strerror(rc), rc );
              goto done;
       }

#ifndef BDB_MULTIPLE_SUFFIXES
       if( !be_issuffix( op->o_bd, &ptr ))
#endif
       {
              buf[0] = DN_SUBTREE_PREFIX;
              rc = db->put( db, txn, &key, &data, DB_NOOVERWRITE );
              if( rc != 0 ) {
                     Debug( LDAP_DEBUG_ANY,
                     "=> bdb_dn2id_add 0x%lx: subtree (%s) put failed: %d\n",
                     e->e_id, ptr.bv_val, rc );
                     goto done;
              }
              
#ifdef BDB_MULTIPLE_SUFFIXES
       if( !be_issuffix( op->o_bd, &ptr ))
#endif
       {
              dnParent( &ptr, &pdn );
       
              key.size = pdn.bv_len + 2;
              key.ulen = key.size;
              pdn.bv_val[-1] = DN_ONE_PREFIX;
              key.data = pdn.bv_val-1;
              ptr = pdn;

              rc = bdb_idl_insert_key( op->o_bd, db, txn, &key, e->e_id );

              if( rc != 0 ) {
                     Debug( LDAP_DEBUG_ANY,
                            "=> bdb_dn2id_add 0x%lx: parent (%s) insert failed: %d\n",
                                   e->e_id, ptr.bv_val, rc );
                     goto done;
              }
       }

#ifndef BDB_MULTIPLE_SUFFIXES
       while( !be_issuffix( op->o_bd, &ptr ))
#else
       for (;;)
#endif
       {
              ptr.bv_val[-1] = DN_SUBTREE_PREFIX;

              rc = bdb_idl_insert_key( op->o_bd, db, txn, &key, e->e_id );

              if( rc != 0 ) {
                     Debug( LDAP_DEBUG_ANY,
                            "=> bdb_dn2id_add 0x%lx: subtree (%s) insert failed: %d\n",
                                   e->e_id, ptr.bv_val, rc );
                     break;
              }
#ifdef BDB_MULTIPLE_SUFFIXES
              if( be_issuffix( op->o_bd, &ptr )) break;
#endif
              dnParent( &ptr, &pdn );

              key.size = pdn.bv_len + 2;
              key.ulen = key.size;
              key.data = pdn.bv_val - 1;
              ptr = pdn;
       }
       }

done:
       op->o_tmpfree( buf, op->o_tmpmemctx );
       Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_add 0x%lx: %d\n", e->e_id, rc, 0 );
       return rc;
}

Here is the call graph for this function:

int bdb_dn2id_children ( Operation op,
DB_TXN *  txn,
Entry e 
)

Definition at line 294 of file dn2id.c.

{
       DBT           key, data;
       struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
       DB *db = bdb->bi_dn2id->bdi_db;
       ID            id;
       int           rc;

       Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_children(\"%s\")\n",
              e->e_nname.bv_val, 0, 0 );
       DBTzero( &key );
       key.size = e->e_nname.bv_len + 2;
       key.data = op->o_tmpalloc( key.size, op->o_tmpmemctx );
       ((char *)key.data)[0] = DN_ONE_PREFIX;
       AC_MEMCPY( &((char *)key.data)[1], e->e_nname.bv_val, key.size - 1 );

       if ( bdb->bi_idl_cache_size ) {
              rc = bdb_idl_cache_get( bdb, db, &key, NULL );
              if ( rc != LDAP_NO_SUCH_OBJECT ) {
                     op->o_tmpfree( key.data, op->o_tmpmemctx );
                     return rc;
              }
       }
       /* we actually could do a empty get... */
       DBTzero( &data );
       data.data = &id;
       data.ulen = sizeof(id);
       data.flags = DB_DBT_USERMEM;
       data.doff = 0;
       data.dlen = sizeof(id);

       rc = db->get( db, txn, &key, &data, bdb->bi_db_opflags );
       op->o_tmpfree( key.data, op->o_tmpmemctx );

       Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_children(\"%s\"): %s (%d)\n",
              e->e_nname.bv_val,
              rc == 0 ? "" : ( rc == DB_NOTFOUND ? "no " :
                     db_strerror(rc) ), rc );

       return rc;
}
int bdb_dn2id_delete ( Operation op,
DB_TXN *  txn,
EntryInfo eip,
Entry e 
)

Definition at line 144 of file dn2id.c.

{
       struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
       DB *db = bdb->bi_dn2id->bdi_db;
       char          *buf;
       DBT           key;
       struct berval pdn, ptr;
       int           rc;

       Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_delete 0x%lx: \"%s\"\n",
              e->e_id, e->e_ndn, 0 );

       DBTzero( &key );
       key.size = e->e_nname.bv_len + 2;
       buf = op->o_tmpalloc( key.size, op->o_tmpmemctx );
       key.data = buf;
       key.flags = DB_DBT_USERMEM;
       buf[0] = DN_BASE_PREFIX;
       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 );
       if( rc != 0 ) {
              Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_delete 0x%lx: delete failed: %s %d\n",
                     e->e_id, db_strerror(rc), rc );
              goto done;
       }

#ifndef BDB_MULTIPLE_SUFFIXES
       if( !be_issuffix( op->o_bd, &ptr ))
#endif
       {
              buf[0] = DN_SUBTREE_PREFIX;
              rc = bdb_idl_delete_key( op->o_bd, db, txn, &key, e->e_id );
              if( rc != 0 ) {
                     Debug( LDAP_DEBUG_ANY,
                     "=> bdb_dn2id_delete 0x%lx: subtree (%s) delete failed: %d\n",
                     e->e_id, ptr.bv_val, rc );
                     goto done;
              }

#ifdef BDB_MULTIPLE_SUFFIXES
       if( !be_issuffix( op->o_bd, &ptr ))
#endif
       {
              dnParent( &ptr, &pdn );

              key.size = pdn.bv_len + 2;
              key.ulen = key.size;
              pdn.bv_val[-1] = DN_ONE_PREFIX;
              key.data = pdn.bv_val - 1;
              ptr = pdn;

              rc = bdb_idl_delete_key( op->o_bd, db, txn, &key, e->e_id );

              if( rc != 0 ) {
                     Debug( LDAP_DEBUG_ANY,
                            "=> bdb_dn2id_delete 0x%lx: parent (%s) delete failed: %d\n",
                            e->e_id, ptr.bv_val, rc );
                     goto done;
              }
       }

#ifndef BDB_MULTIPLE_SUFFIXES
       while( !be_issuffix( op->o_bd, &ptr ))
#else
       for (;;)
#endif
       {
              ptr.bv_val[-1] = DN_SUBTREE_PREFIX;

              rc = bdb_idl_delete_key( op->o_bd, db, txn, &key, e->e_id );
              if( rc != 0 ) {
                     Debug( LDAP_DEBUG_ANY,
                            "=> bdb_dn2id_delete 0x%lx: subtree (%s) delete failed: %d\n",
                            e->e_id, ptr.bv_val, rc );
                     goto done;
              }
#ifdef BDB_MULTIPLE_SUFFIXES
              if( be_issuffix( op->o_bd, &ptr )) break;
#endif
              dnParent( &ptr, &pdn );

              key.size = pdn.bv_len + 2;
              key.ulen = key.size;
              key.data = pdn.bv_val - 1;
              ptr = pdn;
       }
       }

done:
       op->o_tmpfree( buf, op->o_tmpmemctx );
       Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_delete 0x%lx: %d\n", e->e_id, rc, 0 );
       return rc;
}

Here is the call graph for this function:

int bdb_dn2idl ( Operation op,
DB_TXN *  txn,
struct berval ndn,
EntryInfo ei,
ID ids,
ID stack 
)

Definition at line 340 of file dn2id.c.

{
       int           rc;
       DBT           key;
       struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
       DB *db = bdb->bi_dn2id->bdi_db;
       int prefix = ( op->ors_scope == LDAP_SCOPE_ONELEVEL )
              ? DN_ONE_PREFIX : DN_SUBTREE_PREFIX;

       Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl(\"%s\")\n",
              ndn->bv_val, 0, 0 );

#ifndef       BDB_MULTIPLE_SUFFIXES
       if ( prefix == DN_SUBTREE_PREFIX
              && ( ei->bei_id == 0 ||
              ( ei->bei_parent->bei_id == 0 && op->o_bd->be_suffix[0].bv_len ))) {
              BDB_IDL_ALL(bdb, ids);
              return 0;
       }
#endif

       DBTzero( &key );
       key.size = ndn->bv_len + 2;
       key.ulen = key.size;
       key.flags = DB_DBT_USERMEM;
       key.data = op->o_tmpalloc( key.size, op->o_tmpmemctx );
       ((char *)key.data)[0] = prefix;
       AC_MEMCPY( &((char *)key.data)[1], ndn->bv_val, key.size - 1 );

       BDB_IDL_ZERO( ids );
       rc = bdb_idl_fetch_key( op->o_bd, db, txn, &key, ids, NULL, 0 );

       if( rc != 0 ) {
              Debug( LDAP_DEBUG_TRACE,
                     "<= bdb_dn2idl: get failed: %s (%d)\n",
                     db_strerror( rc ), rc, 0 );

       } else {
              Debug( LDAP_DEBUG_TRACE,
                     "<= bdb_dn2idl: id=%ld first=%ld last=%ld\n",
                     (long) ids[0],
                     (long) BDB_IDL_FIRST( ids ), (long) BDB_IDL_LAST( ids ) );
       }

       op->o_tmpfree( key.data, op->o_tmpmemctx );
       return rc;
}