Backend *be,
DB_TXN *txn,
const char *dn,
- ID id
-)
+ ID id )
{
int rc;
DBT key;
DB *db = bdb->bi_dn2id->bdi_db;
Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_delete( \"%s\", %ld )\n", dn, id, 0 );
- assert( id != NOID );
DBTzero( &key );
key.size = strlen( dn ) + 2;
}
int
-bdb_dn2id_children(
+bdb_dn2id(
Backend *be,
DB_TXN *txn,
- const char *dn
-)
+ const char *dn,
+ ID *id )
{
int rc;
DBT key, data;
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
DB *db = bdb->bi_dn2id->bdi_db;
- ID id;
- Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_children( %s )\n",
- dn, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id( \"%s\" )\n", dn, 0, 0 );
DBTzero( &key );
key.size = strlen( dn ) + 2;
key.data = ch_malloc( key.size );
- ((char *)key.data)[0] = DN_ONE_PREFIX;
+ ((char *)key.data)[0] = DN_BASE_PREFIX;
AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
- /* we actually could do a empty get... */
+ /* store the ID */
DBTzero( &data );
- data.data = &id;
- data.ulen = sizeof(id);
+ data.data = id;
+ data.ulen = sizeof(ID);
data.flags = DB_DBT_USERMEM;
- data.doff = 0;
- data.dlen = sizeof(id);
+ /* fetch it */
rc = db->get( db, txn, &key, &data, 0 );
- Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_children( %s ): %s (%d)\n",
- dn,
- rc == 0 ? "yes" : ( rc == DB_NOTFOUND ? "no" :
- db_strerror(rc) ), rc );
+ Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: id=%ld: %s (%d)\n",
+ id, db_strerror( rc ), rc );
+ ch_free( key.data );
return rc;
}
-#if 0
-ID
-dn2id(
+int
+bdb_dn2id_matched(
Backend *be,
- const char *dn
-)
+ DB_TXN *txn,
+ const char *in,
+ ID *id,
+ char **matchedDN )
{
- struct ldbminfo *li = (struct ldbminfo *) be->be_private;
- DBCache *db;
- ID id;
- Datum key, data;
-
- Debug( LDAP_DEBUG_TRACE, "=> dn2id( \"%s\" )\n", dn, 0, 0 );
-
- /* first check the cache */
- if ( (id = cache_find_entry_dn2id( be, &li->li_cache, dn )) != NOID ) {
- Debug( LDAP_DEBUG_TRACE, "<= dn2id %ld (in cache)\n", id,
- 0, 0 );
- return( id );
- }
-
- if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT ))
- == NULL ) {
- Debug( LDAP_DEBUG_ANY, "<= dn2id could not open dn2id%s\n",
- LDBM_SUFFIX, 0, 0 );
- return( NOID );
- }
-
- ldbm_datum_init( key );
-
- key.dsize = strlen( dn ) + 2;
- key.dptr = ch_malloc( key.dsize );
- sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn );
-
- data = ldbm_cache_fetch( db, key );
+ int rc;
+ 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 *tmp = NULL;
- ldbm_cache_close( be, db );
+ Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_matched( \"%s\" )\n", dn, 0, 0 );
- free( key.dptr );
+ DBTzero( &key );
+ key.size = strlen( dn ) + 2;
+ key.data = ch_malloc( key.size );
+ ((char *)key.data)[0] = DN_BASE_PREFIX;
- if ( data.dptr == NULL ) {
- Debug( LDAP_DEBUG_TRACE, "<= dn2id NOID\n", 0, 0, 0 );
- return( NOID );
- }
+ /* store the ID */
+ DBTzero( &data );
+ data.data = id;
+ data.ulen = sizeof(ID);
+ data.flags = DB_DBT_USERMEM;
- AC_MEMCPY( (char *) &id, data.dptr, sizeof(ID) );
+ *matchedDN = NULL;
- assert( id != NOID );
+ while(1) {
+ AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
- ldbm_datum_free( db->dbc_db, data );
+ /* fetch it */
+ rc = db->get( db, txn, &key, &data, 0 );
- Debug( LDAP_DEBUG_TRACE, "<= dn2id %ld\n", id, 0, 0 );
- return( id );
-}
+ if( rc == DB_NOTFOUND ) {
+ char *pdn = dn_parent( be, dn );
+ ch_free( tmp );
+ tmp = NULL;
-ID_BLOCK *
-dn2idl(
- Backend *be,
- const char *dn,
- int prefix
-)
-{
- DBCache *db;
- Datum key;
- ID_BLOCK *idl;
+ if( pdn == NULL || *pdn == '\0' ) {
+ ch_free( pdn );
+ break;
+ }
- Debug( LDAP_DEBUG_TRACE, "=> dn2idl( \"%c%s\" )\n", prefix, dn, 0 );
+ dn = pdn;
+ tmp = pdn;
+ key.size = strlen( dn ) + 2;
- if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT ))
- == NULL ) {
- Debug( LDAP_DEBUG_ANY, "<= dn2idl could not open dn2id%s\n",
- LDBM_SUFFIX, 0, 0 );
- return NULL;
+ } else if ( rc == 0 ) {
+ if( in != dn ) {
+ *matchedDN = (char *) dn;
+ }
+ Debug( LDAP_DEBUG_TRACE,
+ "<= bdb_dn2id_matched: id=%ld: %s\n",
+ id, dn, 0 );
+ break;
+
+ } else {
+ ch_free( tmp );
+ break;
+ }
}
- ldbm_datum_init( key );
-
- key.dsize = strlen( dn ) + 2;
- key.dptr = ch_malloc( key.dsize );
- sprintf( key.dptr, "%c%s", prefix, dn );
-
- idl = idl_fetch( be, db, key );
-
- ldbm_cache_close( be, db );
-
- free( key.dptr );
-
- return( idl );
+ ch_free( key.data );
+ return rc;
}
-
-/*
- * dn2entry - look up dn in the cache/indexes and return the corresponding
- * entry.
- */
-
-Entry *
-dn2entry_rw(
+int
+bdb_dn2id_children(
Backend *be,
- const char *dn,
- Entry **matched,
- int rw
-)
+ DB_TXN *txn,
+ const char *dn )
{
+ int rc;
+ DBT key, data;
+ struct bdb_info *bdb = (struct bdb_info *) be->be_private;
+ DB *db = bdb->bi_dn2id->bdi_db;
ID id;
- Entry *e = NULL;
- char *pdn;
-
- Debug(LDAP_DEBUG_TRACE, "dn2entry_%s: dn: \"%s\"\n",
- rw ? "w" : "r", dn, 0);
- if( matched != NULL ) {
- /* caller cares about match */
- *matched = NULL;
- }
+ Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_children( %s )\n",
+ dn, 0, 0 );
- if ( (id = dn2id( be, dn )) != NOID &&
- (e = id2entry_rw( be, id, rw )) != NULL )
- {
- return( e );
- }
+ DBTzero( &key );
+ key.size = strlen( dn ) + 2;
+ key.data = ch_malloc( key.size );
+ ((char *)key.data)[0] = DN_ONE_PREFIX;
+ AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
- if ( id != NOID ) {
- Debug(LDAP_DEBUG_ANY,
- "dn2entry_%s: no entry for valid id (%ld), dn \"%s\"\n",
- rw ? "w" : "r", id, dn);
- /* must have been deleted from underneath us */
- /* treat as if NOID was found */
- }
+ /* 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);
- /* caller doesn't care about match */
- if( matched == NULL ) return NULL;
+ rc = db->get( db, txn, &key, &data, 0 );
- /* entry does not exist - see how much of the dn does exist */
- /* dn_parent checks returns NULL if dn is suffix */
- if ( (pdn = dn_parent( be, dn )) != NULL ) {
- /* get entry with reader lock */
- if ( (e = dn2entry_r( be, pdn, matched )) != NULL ) {
- *matched = e;
- }
- free( pdn );
- }
+ Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_children( %s ): %s (%d)\n",
+ dn,
+ rc == 0 ? "yes" : ( rc == DB_NOTFOUND ? "no" :
+ db_strerror(rc) ), rc );
- return NULL;
+ return rc;
}
-#endif
\ No newline at end of file
extern int bdb_initialize LDAP_P(( BackendInfo *bi ));
+extern int bdb_add LDAP_P(( BackendDB *bd,
+ Connection *conn, Operation *op, Entry *e ));
+
+extern int bdb_bind LDAP_P(( BackendDB *bd,
+ Connection *conn, Operation *op,
+ const char *dn, const char *ndn, int method,
+ struct berval *cred, char** edn ));
+
+extern int bdb_compare LDAP_P(( BackendDB *bd,
+ Connection *conn, Operation *op,
+ const char *dn, const char *ndn,
+ AttributeAssertion *ava ));
+
+extern int bdb_delete LDAP_P(( BackendDB *bd,
+ Connection *conn, Operation *op,
+ const char *dn, const char *ndn ));
+
+extern int bdb_abandon LDAP_P(( BackendDB *bd,
+ Connection *conn, Operation *op, ber_int_t msgid ));
+
+extern int bdb_modify LDAP_P(( BackendDB *bd,
+ Connection *conn, Operation *op,
+ const char *dn, const char *ndn, Modifications *ml ));
+
+extern int bdb_modrdn LDAP_P(( BackendDB *bd,
+ Connection *conn, Operation *op,
+ const char *dn, const char *ndn,
+ const char* newrdn, int deleteoldrdn,
+ const char *newSuperior ));
+
+extern int bdb_search LDAP_P(( BackendDB *bd,
+ Connection *conn, Operation *op,
+ const char *base, const char *nbase,
+ int scope, int deref, int sizelimit, int timelimit,
+ Filter *filter, const char *filterstr,
+ char **attrs, int attrsonly ));
+
+extern int bdb_unbind LDAP_P(( BackendDB *bd,
+ Connection *conn, Operation *op ));
+
LDAP_END_DECL
#endif /* _BDB_EXTERNAL_H */
#define deref_dn_r( be, dn, err, matched, text ) \
bdb_deref_internal_r( be, NULL, dn, err, matched, text)
+/*
+ * dn2entry.c
+ */
+int bdb_dn2entry LDAP_P(( Backend *be, DB_TXN *tid,
+ const char *dn, Entry **e, Entry **matched, int flags ));
+
+#define dn2entry_r(be, tid, dn, p, m) \
+ bdb_dn2entry((be), (tid), (dn), (p), (m), 0 )
+
+#define dn2entry_w(be, tid, dn, p, m) \
+ bdb_dn2entry((be), (tid), (dn), (p), (m), DB_RMW )
+
/*
* dn2id.c
*/
+int bdb_dn2id(
+ BackendDB *be,
+ DB_TXN *tid,
+ const char *dn,
+ ID *id );
+
+int bdb_dn2id_matched(
+ BackendDB *be,
+ DB_TXN *tid,
+ const char *dn,
+ ID *id,
+ char **matchedDN );
+
int bdb_dn2id_add(
BackendDB *be,
DB_TXN *tid,
DB_TXN *tid,
const char *dn );
-int bdb_dn2entry_rw LDAP_P(( Backend *be, DB_TXN *tid,
- const char *dn, Entry **e, Entry **matched, int rw ));
-
-#define dn2entry_r(be, tid, dn, p, m) bdb_dn2entry_rw((be), (tid), (dn), (p), (m), 0)
-#define dn2entry_w(be, tid, dn, p, m) bdb_dn2entry_rw((be), (tid), (dn), (p), (m), 1)
-
/*
* entry.c
*/
DB_TXN *tid,
ID id );
+int bdb_id2entry(
+ Backend *be,
+ DB_TXN *tid,
+ ID id,
+ Entry **e );
+
/*
* idl.c
*/