1 /* dn2id.c - routines to deal with the dn2id index */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
25 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
26 DB *db = bdb->bi_dn2id->bdi_db;
28 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_add( \"%s\", %ld )\n", dn, id, 0 );
32 key.size = strlen( dn ) + 2;
33 key.data = ch_malloc( key.size );
34 ((char *)key.data)[0] = DN_BASE_PREFIX;
35 AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
38 data.data = (char *) &id;
39 data.size = sizeof( id );
41 /* store it -- don't override */
42 rc = db->put( db, txn, &key, &data, DB_NOOVERWRITE );
44 Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_add: put failed: %s %d\n",
45 db_strerror(rc), rc, 0 );
50 char *pdn = dn_parent( NULL, dn );
51 ((char *)(key.data))[0] = DN_ONE_PREFIX;
54 key.size = strlen( pdn ) + 2;
55 AC_MEMCPY( &((char*)key.data)[1],
58 rc = bdb_idl_insert_key( be, db, txn, &key, id );
61 Debug( LDAP_DEBUG_ANY,
62 "=> bdb_dn2id_add: parent (%s) insert failed: %d\n",
72 char **subtree = dn_subtree( NULL, dn );
74 if( subtree != NULL ) {
76 ((char *)key.data)[0] = DN_SUBTREE_PREFIX;
77 for( i=0; subtree[i] != NULL; i++ ) {
78 key.size = strlen( subtree[i] ) + 2;
79 AC_MEMCPY( &((char *)key.data)[1],
80 subtree[i], key.size - 1 );
82 rc = bdb_idl_insert_key( be, db, txn, &key, id );
85 Debug( LDAP_DEBUG_ANY,
86 "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n",
88 charray_free( subtree );
93 charray_free( subtree );
99 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_add %d\n", rc, 0, 0 );
112 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
113 DB *db = bdb->bi_dn2id->bdi_db;
115 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_delete( \"%s\", %ld )\n", dn, id, 0 );
118 key.size = strlen( dn ) + 2;
119 key.data = ch_malloc( key.size );
120 ((char *)key.data)[0] = DN_BASE_PREFIX;
121 AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
123 /* store it -- don't override */
124 rc = db->del( db, txn, &key, 0 );
126 Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_delete: delete failed: %s %d\n",
127 db_strerror(rc), rc, 0 );
132 char *pdn = dn_parent( NULL, dn );
133 ((char *)(key.data))[0] = DN_ONE_PREFIX;
136 key.size = strlen( pdn ) + 2;
137 AC_MEMCPY( &((char*)key.data)[1],
140 rc = bdb_idl_delete_key( be, db, txn, &key, id );
143 Debug( LDAP_DEBUG_ANY,
144 "=> bdb_dn2id_delete: parent (%s) delete failed: %d\n",
154 char **subtree = dn_subtree( NULL, dn );
156 if( subtree != NULL ) {
158 ((char *)key.data)[0] = DN_SUBTREE_PREFIX;
159 for( i=0; subtree[i] != NULL; i++ ) {
160 key.size = strlen( subtree[i] ) + 2;
161 AC_MEMCPY( &((char *)key.data)[1],
162 subtree[i], key.size - 1 );
164 rc = bdb_idl_delete_key( be, db, txn, &key, id );
167 Debug( LDAP_DEBUG_ANY,
168 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
170 charray_free( subtree );
175 charray_free( subtree );
181 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_delete %d\n", rc, 0, 0 );
194 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
195 DB *db = bdb->bi_dn2id->bdi_db;
197 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id( \"%s\" )\n", dn, 0, 0 );
200 key.size = strlen( dn ) + 2;
201 key.data = ch_malloc( key.size );
202 ((char *)key.data)[0] = DN_BASE_PREFIX;
203 AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
208 data.ulen = sizeof(ID);
209 data.flags = DB_DBT_USERMEM;
212 rc = db->get( db, txn, &key, &data, 0 );
214 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: id=%ld: %s (%d)\n",
215 id, db_strerror( rc ), rc );
231 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
232 DB *db = bdb->bi_dn2id->bdi_db;
236 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_matched( \"%s\" )\n", dn, 0, 0 );
239 key.size = strlen( dn ) + 2;
240 key.data = ch_malloc( key.size );
241 ((char *)key.data)[0] = DN_BASE_PREFIX;
246 data.ulen = sizeof(ID);
247 data.flags = DB_DBT_USERMEM;
252 AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
255 rc = db->get( db, txn, &key, &data, 0 );
257 if( rc == DB_NOTFOUND ) {
258 char *pdn = dn_parent( be, dn );
262 if( pdn == NULL || *pdn == '\0' ) {
269 key.size = strlen( dn ) + 2;
271 } else if ( rc == 0 ) {
273 *matchedDN = (char *) dn;
275 Debug( LDAP_DEBUG_TRACE,
276 "<= bdb_dn2id_matched: id=%ld: %s\n",
298 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
299 DB *db = bdb->bi_dn2id->bdi_db;
302 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_children( %s )\n",
306 key.size = strlen( dn ) + 2;
307 key.data = ch_malloc( key.size );
308 ((char *)key.data)[0] = DN_ONE_PREFIX;
309 AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
311 /* we actually could do a empty get... */
314 data.ulen = sizeof(id);
315 data.flags = DB_DBT_USERMEM;
317 data.dlen = sizeof(id);
319 rc = db->get( db, txn, &key, &data, 0 );
321 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_children( %s ): %s (%d)\n",
323 rc == 0 ? "yes" : ( rc == DB_NOTFOUND ? "no" :
324 db_strerror(rc) ), rc );