]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/id2children.c
903418daa6be04b03adfb04a992983357cfe060d
[openldap] / servers / slapd / back-bdb2 / id2children.c
1 /* id2children.c - routines to deal with the id2children index */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6 #include <ac/string.h>
7
8 #include <ac/socket.h>
9
10 #include "slap.h"
11 #include "back-bdb2.h"
12
13 int
14 bdb2i_has_children(
15     BackendDB   *be,
16     Entry       *p
17 )
18 {
19         struct dbcache  *db;
20         Datum           key;
21         int             rc = 0;
22         ID_BLOCK                *idl;
23
24         ldbm_datum_init( key );
25
26         Debug( LDAP_DEBUG_TRACE, "=> bdb2i_has_children( %ld )\n", p->e_id , 0, 0 );
27
28         if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX,
29             LDBM_WRCREAT )) == NULL ) {
30                 Debug( LDAP_DEBUG_ANY,
31                     "<= bdb2i_has_children: could not open \"dn2id" BDB2_SUFFIX "\"\n",
32                     0, 0, 0 );
33                 return( 0 );
34         }
35
36         key.dsize = strlen( p->e_ndn ) + 2;
37         key.dptr = ch_malloc( key.dsize );
38         sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, p->e_ndn );
39
40         idl = bdb2i_idl_fetch( be, db, key );
41
42         free( key.dptr );
43
44         bdb2i_cache_close( be, db );
45
46         if( idl != NULL ) {
47                 bdb2i_idl_free( idl );
48                 rc = 1;
49         }
50
51         Debug( LDAP_DEBUG_TRACE, "<= bdb2i_has_children( %ld ): %s\n",
52                                         p->e_id, rc ? "yes" : "no", 0 );
53         return( rc );
54 }