~ttx/openldap/lucid-gssapi-495418

« back to all changes in this revision

Viewing changes to servers/slapd/back-bdb/dn2entry.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2008-07-10 14:45:49 UTC
  • Revision ID: james.westby@ubuntu.com-20080710144549-wck73med0e72gfyo
Tags: upstream-2.4.10
ImportĀ upstreamĀ versionĀ 2.4.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* dn2entry.c - routines to deal with the dn2id / id2entry glue */
 
2
/* $OpenLDAP: pkg/ldap/servers/slapd/back-bdb/dn2entry.c,v 1.28.2.7 2008/02/11 23:26:45 kurt Exp $ */
 
3
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
 
4
 *
 
5
 * Copyright 2000-2008 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
        BDB_LOCKER locker,
 
38
        DB_LOCK *lock )
 
39
{
 
40
        EntryInfo *ei = NULL;
 
41
        int rc, rc2;
 
42
 
 
43
        Debug(LDAP_DEBUG_TRACE, "bdb_dn2entry(\"%s\")\n",
 
44
                dn->bv_val, 0, 0 );
 
45
 
 
46
        *e = NULL;
 
47
 
 
48
        rc = bdb_cache_find_ndn( op, locker, dn, &ei );
 
49
        if ( rc ) {
 
50
                if ( matched && rc == DB_NOTFOUND ) {
 
51
                        /* Set the return value, whether we have its entry
 
52
                         * or not.
 
53
                         */
 
54
                        *e = ei;
 
55
                        if ( ei && ei->bei_id ) {
 
56
                                rc2 = bdb_cache_find_id( op, tid, ei->bei_id,
 
57
                                        &ei, ID_LOCKED, locker, lock );
 
58
                                if ( rc2 ) rc = rc2;
 
59
                        } else if ( ei ) {
 
60
                                bdb_cache_entryinfo_unlock( ei );
 
61
                                memset( lock, 0, sizeof( *lock ));
 
62
                                lock->mode = DB_LOCK_NG;
 
63
                        }
 
64
                } else if ( ei ) {
 
65
                        bdb_cache_entryinfo_unlock( ei );
 
66
                }
 
67
        } else {
 
68
                rc = bdb_cache_find_id( op, tid, ei->bei_id, &ei, ID_LOCKED,
 
69
                        locker, lock );
 
70
                if ( rc == 0 ) {
 
71
                        *e = ei;
 
72
                } else if ( matched && rc == DB_NOTFOUND ) {
 
73
                        /* always return EntryInfo */
 
74
                        if ( ei->bei_parent ) {
 
75
                                ei = ei->bei_parent;
 
76
                                rc2 = bdb_cache_find_id( op, tid, ei->bei_id, &ei, 0,
 
77
                                        locker, lock );
 
78
                                if ( rc2 ) rc = rc2;
 
79
                        }
 
80
                        *e = ei;
 
81
                }
 
82
        }
 
83
 
 
84
        return rc;
 
85
}