]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/dn2entry.c
Restructured to avoid direct use of sl_malloc functions. Minimizes impact
[openldap] / servers / slapd / back-bdb / dn2entry.c
1 /* dn2entry.c - routines to deal with the dn2id / id2entry glue */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 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 "back-bdb.h"
14
15
16 /*
17  * dn2entry - look up dn in the cache/indexes and return the corresponding
18  * entry. If the requested DN is not found and matched is TRUE, return info
19  * for the closest ancestor of the DN. Otherwise e is NULL.
20  */
21
22 int
23 bdb_dn2entry(
24         Operation *op,
25         DB_TXN *tid,
26         struct berval *dn,
27         EntryInfo **e,
28         int matched,
29         u_int32_t locker,
30         DB_LOCK *lock )
31 {
32         EntryInfo *ei = NULL;
33         int rc;
34
35 #ifdef NEW_LOGGING
36         LDAP_LOG ( CACHE, ARGS, "bdb_dn2entry(\"%s\")\n", dn->bv_val, 0, 0 );
37 #else
38         Debug(LDAP_DEBUG_TRACE, "bdb_dn2entry(\"%s\")\n",
39                 dn->bv_val, 0, 0 );
40 #endif
41
42         *e = NULL;
43
44         rc = bdb_cache_find_ndn( op, tid, dn, &ei, locker );
45         if ( rc ) {
46                 if ( matched && rc == DB_NOTFOUND ) {
47                         /* Set the return value, whether we have its entry
48                          * or not.
49                          */
50                         *e = ei;
51                         if ( ei && ei->bei_id )
52                                 bdb_cache_find_id( op, tid, ei->bei_id,
53                                         &ei, 1, locker, lock );
54                         else if ( ei )
55                                 bdb_cache_entryinfo_unlock( ei );
56                 } else if ( ei ) {
57                         bdb_cache_entryinfo_unlock( ei );
58                 }
59         } else {
60                 rc = bdb_cache_find_id( op, tid, ei->bei_id, &ei, 1,
61                         locker, lock );
62                 if ( rc == 0 ) {
63                         *e = ei;
64                 } else if ( matched && rc == DB_NOTFOUND ) {
65                         /* always return EntryInfo */
66                         ei = ei->bei_parent;
67                         bdb_cache_find_id( op, tid, ei->bei_id, &ei, 1,
68                                 locker, lock );
69                         *e = ei;
70                 }
71         }
72
73         return rc;
74 }