]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/dn2entry.c
Fix AVL comparisons
[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         BackendDB       *be,
25         DB_TXN *tid,
26         struct berval *dn,
27         EntryInfo **e,
28         int matched,
29         u_int32_t locker,
30         DB_LOCK *lock,
31         void *ctx )
32 {
33         EntryInfo *ei = NULL;
34         int rc;
35
36 #ifdef NEW_LOGGING
37         LDAP_LOG ( CACHE, ARGS, "bdb_dn2entry(\"%s\")\n", dn->bv_val, 0, 0 );
38 #else
39         Debug(LDAP_DEBUG_TRACE, "bdb_dn2entry(\"%s\")\n",
40                 dn->bv_val, 0, 0 );
41 #endif
42
43         *e = NULL;
44
45         rc = bdb_cache_find_entry_ndn2id( be, tid, dn, &ei, locker, ctx );
46         if ( rc ) {
47                 if ( matched && rc == DB_NOTFOUND ) {
48                         /* Set the return value, whether we have its entry
49                          * or not.
50                          */
51                         *e = ei;
52                         if ( ei && ei->bei_id )
53                                 bdb_cache_find_entry_id( be, tid, ei->bei_id,
54                                         &ei, 1, locker, lock, ctx );
55                         else if ( ei )
56                                 bdb_cache_entryinfo_unlock( ei );
57                 } else if ( ei ) {
58                         bdb_cache_entryinfo_unlock( ei );
59                 }
60         } else {
61                 rc = bdb_cache_find_entry_id( be, tid, ei->bei_id, &ei, 1,
62                         locker, lock, ctx );
63                 if ( rc == 0 ) {
64                         *e = ei;
65                 } else if ( matched && rc == DB_NOTFOUND ) {
66                         /* always return EntryInfo */
67                         ei = ei->bei_parent;
68                         bdb_cache_find_entry_id( be, tid, ei->bei_id, &ei, 1,
69                                 locker, lock, ctx );
70                         *e = ei;
71                 }
72         }
73
74         return rc;
75 }