From 7731832751ab9f3c6ddeb66f186d3d7fa1934a6d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 13:11:40 +0200 Subject: Adding upstream version 2.4.57+dfsg. Signed-off-by: Daniel Baumann --- servers/slapd/back-mdb/dn2entry.c | 79 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 servers/slapd/back-mdb/dn2entry.c (limited to 'servers/slapd/back-mdb/dn2entry.c') diff --git a/servers/slapd/back-mdb/dn2entry.c b/servers/slapd/back-mdb/dn2entry.c new file mode 100644 index 0000000..e2377f5 --- /dev/null +++ b/servers/slapd/back-mdb/dn2entry.c @@ -0,0 +1,79 @@ +/* dn2entry.c - routines to deal with the dn2id / id2entry glue */ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 2000-2021 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ + +#include "portable.h" + +#include +#include + +#include "back-mdb.h" + +/* + * dn2entry - look up dn in the cache/indexes and return the corresponding + * entry. If the requested DN is not found and matched is TRUE, return info + * for the closest ancestor of the DN. Otherwise e is NULL. + */ + +int +mdb_dn2entry( + Operation *op, + MDB_txn *tid, + MDB_cursor *m2, + struct berval *dn, + Entry **e, + ID *nsubs, + int matched ) +{ + struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private; + int rc, rc2; + ID id = NOID; + struct berval mbv, nmbv; + MDB_cursor *mc; + + Debug(LDAP_DEBUG_TRACE, "mdb_dn2entry(\"%s\")\n", + dn->bv_val ? dn->bv_val : "", 0, 0 ); + + *e = NULL; + + rc = mdb_dn2id( op, tid, m2, dn, &id, nsubs, &mbv, &nmbv ); + if ( rc ) { + if ( matched ) { + rc2 = mdb_cursor_open( tid, mdb->mi_id2entry, &mc ); + if ( rc2 == MDB_SUCCESS ) { + rc2 = mdb_id2entry( op, mc, id, e ); + mdb_cursor_close( mc ); + } + } + + } else { + rc = mdb_cursor_open( tid, mdb->mi_id2entry, &mc ); + if ( rc == MDB_SUCCESS ) { + rc = mdb_id2entry( op, mc, id, e ); + mdb_cursor_close(mc); + } + } + if ( *e ) { + (*e)->e_name = mbv; + if ( rc == MDB_SUCCESS ) + ber_dupbv_x( &(*e)->e_nname, dn, op->o_tmpmemctx ); + else + ber_dupbv_x( &(*e)->e_nname, &nmbv, op->o_tmpmemctx ); + } else { + op->o_tmpfree( mbv.bv_val, op->o_tmpmemctx ); + } + + return rc; +} -- cgit v1.2.3