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",
92 charray_free( subtree );
98 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_add: %d\n", rc, 0, 0 );
111 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
112 DB *db = bdb->bi_dn2id->bdi_db;
114 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_delete( \"%s\", %ld )\n", dn, id, 0 );
117 key.size = strlen( dn ) + 2;
118 key.data = ch_malloc( key.size );
119 ((char *)key.data)[0] = DN_BASE_PREFIX;
120 AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
122 /* store it -- don't override */
123 rc = db->del( db, txn, &key, 0 );
125 Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_delete: delete failed: %s %d\n",
126 db_strerror(rc), rc, 0 );
131 char *pdn = dn_parent( NULL, dn );
132 ((char *)(key.data))[0] = DN_ONE_PREFIX;
135 key.size = strlen( pdn ) + 2;
136 AC_MEMCPY( &((char*)key.data)[1],
139 rc = bdb_idl_delete_key( be, db, txn, &key, id );
142 Debug( LDAP_DEBUG_ANY,
143 "=> bdb_dn2id_delete: parent (%s) delete failed: %d\n",
153 char **subtree = dn_subtree( NULL, dn );
155 if( subtree != NULL ) {
157 ((char *)key.data)[0] = DN_SUBTREE_PREFIX;
158 for( i=0; subtree[i] != NULL; i++ ) {
159 key.size = strlen( subtree[i] ) + 2;
160 AC_MEMCPY( &((char *)key.data)[1],
161 subtree[i], key.size - 1 );
163 rc = bdb_idl_delete_key( be, db, txn, &key, id );
166 Debug( LDAP_DEBUG_ANY,
167 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
169 charray_free( subtree );
174 charray_free( subtree );
180 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_delete %d\n", rc, 0, 0 );
193 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
194 DB *db = bdb->bi_dn2id->bdi_db;
196 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id( \"%s\" )\n", dn, 0, 0 );
199 key.size = strlen( dn ) + 2;
200 key.data = ch_malloc( key.size );
201 ((char *)key.data)[0] = DN_BASE_PREFIX;
202 AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
207 data.ulen = sizeof(ID);
208 data.flags = DB_DBT_USERMEM;
211 rc = db->get( db, txn, &key, &data, 0 );
213 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: id=%ld: %s (%d)\n",
214 id, db_strerror( rc ), rc );
230 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
231 DB *db = bdb->bi_dn2id->bdi_db;
235 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_matched( \"%s\" )\n", dn, 0, 0 );
238 key.size = strlen( dn ) + 2;
239 key.data = ch_malloc( key.size );
240 ((char *)key.data)[0] = DN_BASE_PREFIX;
245 data.ulen = sizeof(ID);
246 data.flags = DB_DBT_USERMEM;
251 AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
254 rc = db->get( db, txn, &key, &data, 0 );
256 if( rc == DB_NOTFOUND ) {
257 char *pdn = dn_parent( be, dn );
261 if( pdn == NULL || *pdn == '\0' ) {
268 key.size = strlen( dn ) + 2;
270 } else if ( rc == 0 ) {
272 *matchedDN = (char *) dn;
274 Debug( LDAP_DEBUG_TRACE,
275 "<= bdb_dn2id_matched: id=%ld: %s\n",
297 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
298 DB *db = bdb->bi_dn2id->bdi_db;
301 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_children( %s )\n",
305 key.size = strlen( dn ) + 2;
306 key.data = ch_malloc( key.size );
307 ((char *)key.data)[0] = DN_ONE_PREFIX;
308 AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
310 /* we actually could do a empty get... */
313 data.ulen = sizeof(id);
314 data.flags = DB_DBT_USERMEM;
316 data.dlen = sizeof(id);
318 rc = db->get( db, txn, &key, &data, 0 );
320 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_children( %s ): %s (%d)\n",
322 rc == 0 ? "yes" : ( rc == DB_NOTFOUND ? "no" :
323 db_strerror(rc) ), rc );