]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/id2children.c
Happy New Year!
[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-2005 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         Debug( LDAP_DEBUG_TRACE, "=> has_children( %ld )\n", p->e_id , 0, 0 );
41
42
43         if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX,
44             LDBM_WRCREAT )) == NULL ) {
45                 Debug( LDAP_DEBUG_ANY,
46                     "<= has_children -1 could not open \"dn2id%s\"\n",
47                     LDBM_SUFFIX, 0, 0 );
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         Debug( LDAP_DEBUG_TRACE, "<= has_children( %ld ): %s\n",
68                 p->e_id, rc ? "yes" : "no", 0 );
69
70         return( rc );
71 }