1 /* $NetBSD: dn2entry.c,v 1.1.1.1 2014/05/28 09:58:49 tron Exp $ */ 2 3 /* dn2entry.c - routines to deal with the dn2id / id2entry glue */ 4 /* $OpenLDAP$ */ 5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 6 * 7 * Copyright 2000-2014 The OpenLDAP Foundation. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted only as authorized by the OpenLDAP 12 * Public License. 13 * 14 * A copy of this license is available in the file LICENSE in the 15 * top-level directory of the distribution or, alternatively, at 16 * <http://www.OpenLDAP.org/license.html>. 17 */ 18 19 #include "portable.h" 20 21 #include <stdio.h> 22 #include <ac/string.h> 23 24 #include "back-mdb.h" 25 26 /* 27 * dn2entry - look up dn in the cache/indexes and return the corresponding 28 * entry. If the requested DN is not found and matched is TRUE, return info 29 * for the closest ancestor of the DN. Otherwise e is NULL. 30 */ 31 32 int 33 mdb_dn2entry( 34 Operation *op, 35 MDB_txn *tid, 36 MDB_cursor *m2, 37 struct berval *dn, 38 Entry **e, 39 ID *nsubs, 40 int matched ) 41 { 42 struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private; 43 int rc, rc2; 44 ID id = NOID; 45 struct berval mbv, nmbv; 46 MDB_cursor *mc; 47 48 Debug(LDAP_DEBUG_TRACE, "mdb_dn2entry(\"%s\")\n", 49 dn->bv_val ? dn->bv_val : "", 0, 0 ); 50 51 *e = NULL; 52 53 rc = mdb_dn2id( op, tid, m2, dn, &id, nsubs, &mbv, &nmbv ); 54 if ( rc ) { 55 if ( matched ) { 56 rc2 = mdb_cursor_open( tid, mdb->mi_id2entry, &mc ); 57 if ( rc2 == MDB_SUCCESS ) { 58 rc2 = mdb_id2entry( op, mc, id, e ); 59 mdb_cursor_close( mc ); 60 } 61 } 62 63 } else { 64 rc = mdb_cursor_open( tid, mdb->mi_id2entry, &mc ); 65 if ( rc == MDB_SUCCESS ) { 66 rc = mdb_id2entry( op, mc, id, e ); 67 mdb_cursor_close(mc); 68 } 69 } 70 if ( *e ) { 71 (*e)->e_name = mbv; 72 if ( rc == MDB_SUCCESS ) 73 ber_dupbv_x( &(*e)->e_nname, dn, op->o_tmpmemctx ); 74 else 75 ber_dupbv_x( &(*e)->e_nname, &nmbv, op->o_tmpmemctx ); 76 } 77 78 return rc; 79 } 80