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