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