]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/id2children.c
add referral check to functions elaborated by overlays
[openldap] / servers / slapd / back-ldbm / id2children.c
1 /* id2children.c - routines to deal with the id2children index */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2004 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20 #include <ac/string.h>
21
22 #include <ac/socket.h>
23
24 #include "slap.h"
25 #include "back-ldbm.h"
26
27 int
28 has_children(
29     Backend     *be,
30     Entry       *p
31 )
32 {
33         DBCache *db;
34         Datum           key;
35         int             rc = 0;
36         ID_BLOCK                *idl;
37
38         ldbm_datum_init( key );
39
40 #ifdef NEW_LOGGING
41         LDAP_LOG( INDEX, ENTRY, "has_children: enter %ld\n", p->e_id, 0, 0 );
42 #else
43         Debug( LDAP_DEBUG_TRACE, "=> has_children( %ld )\n", p->e_id , 0, 0 );
44 #endif
45
46
47         if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX,
48             LDBM_WRCREAT )) == NULL ) {
49 #ifdef NEW_LOGGING
50                 LDAP_LOG( INDEX, ERR, 
51                         "has_children: could not open \"dn2id%s\"\n", LDBM_SUFFIX, 0, 0 );
52 #else
53                 Debug( LDAP_DEBUG_ANY,
54                     "<= has_children -1 could not open \"dn2id%s\"\n",
55                     LDBM_SUFFIX, 0, 0 );
56 #endif
57
58                 return( 0 );
59         }
60
61         key.dsize = strlen( p->e_ndn ) + 2;
62         key.dptr = ch_malloc( key.dsize );
63         sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, p->e_ndn );
64
65         idl = idl_fetch( be, db, key );
66
67         free( key.dptr );
68
69         ldbm_cache_close( be, db );
70
71         if( idl != NULL ) {
72                 idl_free( idl );
73                 rc = 1;
74         }
75
76 #ifdef NEW_LOGGING
77         LDAP_LOG( INDEX, ENTRY, 
78                    "has_children: id (%ld) %s children.\n",
79                    p->e_id, rc ? "has" : "doesn't have", 0 );
80 #else
81         Debug( LDAP_DEBUG_TRACE, "<= has_children( %ld ): %s\n",
82                 p->e_id, rc ? "yes" : "no", 0 );
83 #endif
84
85         return( rc );
86 }