]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/id2children.c
Added bdb_attribute and bdb_group ACL support routines
[openldap] / servers / slapd / back-ldbm / id2children.c
1 /* id2children.c - routines to deal with the id2children index */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 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
19 int
20 has_children(
21     Backend     *be,
22     Entry       *p
23 )
24 {
25         DBCache *db;
26         Datum           key;
27         int             rc = 0;
28         ID_BLOCK                *idl;
29
30         ldbm_datum_init( key );
31
32 #ifdef NEW_LOGGING
33         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
34                    "has_children: enter %ld\n", p->e_id ));
35 #else
36         Debug( LDAP_DEBUG_TRACE, "=> has_children( %ld )\n", p->e_id , 0, 0 );
37 #endif
38
39
40         if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX,
41             LDBM_WRCREAT )) == NULL ) {
42 #ifdef NEW_LOGGING
43                 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
44                            "has_children: could not open \"dn2id%s\"\n",
45                            LDBM_SUFFIX ));
46 #else
47                 Debug( LDAP_DEBUG_ANY,
48                     "<= has_children -1 could not open \"dn2id%s\"\n",
49                     LDBM_SUFFIX, 0, 0 );
50 #endif
51
52                 return( 0 );
53         }
54
55         key.dsize = strlen( p->e_ndn ) + 2;
56         key.dptr = ch_malloc( key.dsize );
57         sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, p->e_ndn );
58
59         idl = idl_fetch( be, db, key );
60
61         free( key.dptr );
62
63         ldbm_cache_close( be, db );
64
65         if( idl != NULL ) {
66                 idl_free( idl );
67                 rc = 1;
68         }
69
70 #ifdef NEW_LOGGING
71         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
72                    "has_children: id (%ld) %s children.\n",
73                    p->e_id, rc ? "has" : "doesn't have" ));
74 #else
75         Debug( LDAP_DEBUG_TRACE, "<= has_children( %ld ): %s\n",
76                 p->e_id, rc ? "yes" : "no", 0 );
77 #endif
78
79         return( rc );
80 }