]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/id2children.c
ITS#2368 - fix deleting key from range IDL
[openldap] / servers / slapd / back-ldbm / id2children.c
1 /* id2children.c - routines to deal with the id2children index */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11 #include <ac/string.h>
12
13 #include <ac/socket.h>
14
15 #include "slap.h"
16 #include "back-ldbm.h"
17
18 int
19 has_children(
20     Backend     *be,
21     Entry       *p
22 )
23 {
24         DBCache *db;
25         Datum           key;
26         int             rc = 0;
27         ID_BLOCK                *idl;
28
29         ldbm_datum_init( key );
30
31 #ifdef NEW_LOGGING
32         LDAP_LOG( INDEX, ENTRY, "has_children: enter %ld\n", p->e_id, 0, 0 );
33 #else
34         Debug( LDAP_DEBUG_TRACE, "=> has_children( %ld )\n", p->e_id , 0, 0 );
35 #endif
36
37
38         if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX,
39             LDBM_WRCREAT )) == NULL ) {
40 #ifdef NEW_LOGGING
41                 LDAP_LOG( INDEX, ERR, 
42                         "has_children: could not open \"dn2id%s\"\n", LDBM_SUFFIX, 0, 0 );
43 #else
44                 Debug( LDAP_DEBUG_ANY,
45                     "<= has_children -1 could not open \"dn2id%s\"\n",
46                     LDBM_SUFFIX, 0, 0 );
47 #endif
48
49                 return( 0 );
50         }
51
52         key.dsize = strlen( p->e_ndn ) + 2;
53         key.dptr = ch_malloc( key.dsize );
54         sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, p->e_ndn );
55
56         idl = idl_fetch( be, db, key );
57
58         free( key.dptr );
59
60         ldbm_cache_close( be, db );
61
62         if( idl != NULL ) {
63                 idl_free( idl );
64                 rc = 1;
65         }
66
67 #ifdef NEW_LOGGING
68         LDAP_LOG( INDEX, ENTRY, 
69                    "has_children: id (%ld) %s children.\n",
70                    p->e_id, rc ? "has" : "doesn't have", 0 );
71 #else
72         Debug( LDAP_DEBUG_TRACE, "<= has_children( %ld ): %s\n",
73                 p->e_id, rc ? "yes" : "no", 0 );
74 #endif
75
76         return( rc );
77 }