Debian Codegraph @

servers/slapd/back-mdb/dn2entry.c

raw
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-2024 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-mdb.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 mdb_dn2entry(
32 Operation *op,
33 MDB_txn *tid,
34 MDB_cursor *m2,
35 struct berval *dn,
36 Entry **e,
37 ID *nsubs,
38 int matched )
39 {
40 struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
41 int rc, rc2;
42 ID id = NOID;
43 struct berval mbv, nmbv;
44 MDB_cursor *mc;
45
46 Debug(LDAP_DEBUG_TRACE, "mdb_dn2entry(\"%s\")\n",
47 dn->bv_val ? dn->bv_val : "" );
48
49 *e = NULL;
50
51 rc = mdb_dn2id( op, tid, m2, dn, &id, nsubs, &mbv, &nmbv );
52 if ( rc ) {
53 if ( matched ) {
54 rc2 = mdb_cursor_open( tid, mdb->mi_id2entry, &mc );
55 if ( rc2 == MDB_SUCCESS ) {
56 rc2 = mdb_id2entry( op, mc, id, e );
57 mdb_cursor_close( mc );
58 }
59 }
60
61 } else {
62 rc = mdb_cursor_open( tid, mdb->mi_id2entry, &mc );
63 if ( rc == MDB_SUCCESS ) {
64 rc = mdb_id2entry( op, mc, id, e );
65 mdb_cursor_close(mc);
66 }
67 }
68 if ( *e ) {
69 (*e)->e_name = mbv;
70 if ( rc == MDB_SUCCESS )
71 ber_dupbv_x( &(*e)->e_nname, dn, op->o_tmpmemctx );
72 else
73 ber_dupbv_x( &(*e)->e_nname, &nmbv, op->o_tmpmemctx );
74 } else {
75 op->o_tmpfree( mbv.bv_val, op->o_tmpmemctx );
76 }
77
78 return rc;
79 }