]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/id2children.c
If dn2id returns ID but id2entry returns NULL, log it.
[openldap] / servers / slapd / back-ldbm / 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-ldbm.h"
12
13 int
14 id2children_add(
15     Backend     *be,
16     Entry       *p,
17     Entry       *e
18 )
19 {
20         struct dbcache  *db;
21         Datum           key;
22         int             len, rc;
23         IDList          *idl;
24         char            buf[20];
25
26         ldbm_datum_init( key );
27
28         Debug( LDAP_DEBUG_TRACE, "=> id2children_add( %lu, %lu )\n",
29                p ? p->e_id : 0, e->e_id, 0 );
30
31         if ( (db = ldbm_cache_open( be, "id2children", LDBM_SUFFIX,
32             LDBM_WRCREAT )) == NULL ) {
33                 Debug( LDAP_DEBUG_ANY,
34                     "<= id2children_add -1 could not open \"id2children%s\"\n",
35                     LDBM_SUFFIX, 0, 0 );
36                 return( -1 );
37         }
38
39         sprintf( buf, "%c%ld", EQ_PREFIX, p ? p->e_id : 0 );
40         key.dptr = buf;
41         key.dsize = strlen( buf ) + 1;
42
43         if ( idl_insert_key( be, db, key, e->e_id ) != 0 ) {
44                 Debug( LDAP_DEBUG_TRACE, "<= id2children_add -1 (idl_insert)\n",
45                     0, 0, 0 );
46                 ldbm_cache_close( be, db );
47                 return( -1 );
48         }
49
50         ldbm_cache_close( be, db );
51
52         Debug( LDAP_DEBUG_TRACE, "<= id2children_add 0\n", 0, 0, 0 );
53         return( 0 );
54 }
55
56
57 int
58 id2children_remove(
59     Backend     *be,
60     Entry       *p,
61     Entry       *e
62 )
63 {
64         struct dbcache  *db;
65         Datum           key;
66         int             len, rc;
67         IDList          *idl;
68         char            buf[20];
69
70         Debug( LDAP_DEBUG_TRACE, "=> id2children_remove( %lu, %lu )\n", p ? p->e_id
71             : 0, e->e_id, 0 );
72
73         if ( (db = ldbm_cache_open( be, "id2children", LDBM_SUFFIX,
74             LDBM_WRCREAT )) == NULL ) {
75                 Debug( LDAP_DEBUG_ANY,
76                     "<= id2children_remove -1 could not open \"id2children%s\"\n",
77                     LDBM_SUFFIX, 0, 0 );
78                 return( -1 );
79         }
80
81         ldbm_datum_init( key );
82         sprintf( buf, "%c%ld", EQ_PREFIX, p ? p->e_id : 0 );
83         key.dptr = buf;
84         key.dsize = strlen( buf ) + 1;
85
86         if ( idl_delete_key( be, db, key, e->e_id ) != 0 ) {
87                 Debug( LDAP_DEBUG_TRACE, "<= id2children_remove -1 (idl_delete)\n",
88                     0, 0, 0 );
89                 ldbm_cache_close( be, db );
90                 return( -1 );
91         }
92
93         ldbm_cache_close( be, db );
94
95         Debug( LDAP_DEBUG_TRACE, "<= id2children_remove 0\n", 0, 0, 0 );
96         return( 0 );
97 }
98
99 int
100 has_children(
101     Backend     *be,
102     Entry       *p
103 )
104 {
105         struct dbcache  *db;
106         Datum           key;
107         int             rc;
108         IDList          *idl;
109         char            buf[20];
110
111         ldbm_datum_init( key );
112
113         Debug( LDAP_DEBUG_TRACE, "=> has_children( %lu )\n", p->e_id , 0, 0 );
114
115         if ( (db = ldbm_cache_open( be, "id2children", LDBM_SUFFIX,
116             LDBM_WRCREAT )) == NULL ) {
117                 Debug( LDAP_DEBUG_ANY,
118                     "<= has_children -1 could not open \"id2children%s\"\n",
119                     LDBM_SUFFIX, 0, 0 );
120                 return( 0 );
121         }
122
123         sprintf( buf, "%c%ld", EQ_PREFIX, p->e_id );
124         key.dptr = buf;
125         key.dsize = strlen( buf ) + 1;
126
127         idl = idl_fetch( be, db, key );
128
129         ldbm_cache_close( be, db );
130         rc = idl ? 1 : 0;
131         idl_free( idl );
132
133         Debug( LDAP_DEBUG_TRACE, "<= has_children %d\n", rc, 0, 0 );
134         return( rc );
135 }