]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/dn2entry.c
ITS#3556: 64-bit portability
[openldap] / servers / slapd / back-bdb / dn2entry.c
1 /* dn2entry.c - routines to deal with the dn2id / id2entry glue */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2000-2005 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20 #include <ac/string.h>
21
22 #include "back-bdb.h"
23
24 /*
25  * dn2entry - look up dn in the cache/indexes and return the corresponding
26  * entry. If the requested DN is not found and matched is TRUE, return info
27  * for the closest ancestor of the DN. Otherwise e is NULL.
28  */
29
30 int
31 bdb_dn2entry(
32         Operation *op,
33         DB_TXN *tid,
34         struct berval *dn,
35         EntryInfo **e,
36         int matched,
37         u_int32_t locker,
38         DB_LOCK *lock )
39 {
40         EntryInfo *ei = NULL;
41         int rc, rc2;
42
43 #ifdef NEW_LOGGING
44         LDAP_LOG ( CACHE, ARGS, "bdb_dn2entry(\"%s\")\n", dn->bv_val, 0, 0 );
45 #else
46         Debug(LDAP_DEBUG_TRACE, "bdb_dn2entry(\"%s\")\n",
47                 dn->bv_val, 0, 0 );
48 #endif
49
50         *e = NULL;
51
52         rc = bdb_cache_find_ndn( op, tid, dn, &ei );
53         if ( rc ) {
54                 if ( matched && rc == DB_NOTFOUND ) {
55                         /* Set the return value, whether we have its entry
56                          * or not.
57                          */
58                         *e = ei;
59                         if ( ei && ei->bei_id ) {
60                                 rc2 = bdb_cache_find_id( op, tid, ei->bei_id,
61                                         &ei, 1, locker, lock );
62                                 if ( rc2 ) rc = rc2;
63                         } else if ( ei )
64                                 bdb_cache_entryinfo_unlock( ei );
65                 } else if ( ei ) {
66                         bdb_cache_entryinfo_unlock( ei );
67                 }
68         } else {
69                 rc = bdb_cache_find_id( op, tid, ei->bei_id, &ei, 1,
70                         locker, lock );
71                 if ( rc == 0 ) {
72                         *e = ei;
73                 } else if ( matched && rc == DB_NOTFOUND ) {
74                         /* always return EntryInfo */
75                         ei = ei->bei_parent;
76                         rc2 = bdb_cache_find_id( op, tid, ei->bei_id, &ei, 1,
77                                 locker, lock );
78                         if ( rc2 ) rc = rc2;
79                         *e = ei;
80                 }
81         }
82
83         return rc;
84 }