Back to index

openldap  2.4.31
dn2entry.c
Go to the documentation of this file.
00001 /* dn2entry.c - routines to deal with the dn2id / id2entry glue */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2000-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 
00017 #include "portable.h"
00018 
00019 #include <stdio.h>
00020 #include <ac/string.h>
00021 
00022 #include "back-mdb.h"
00023 
00024 /*
00025  * dn2entry - look up dn in the cache/indexes and return the corresponding
00026  * entry. If the requested DN is not found and matched is TRUE, return info
00027  * for the closest ancestor of the DN. Otherwise e is NULL.
00028  */
00029 
00030 int
00031 mdb_dn2entry(
00032        Operation *op,
00033        MDB_txn *tid,
00034        MDB_cursor *m2,
00035        struct berval *dn,
00036        Entry **e,
00037        int matched )
00038 {
00039        struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
00040        int rc, rc2;
00041        ID id = NOID;
00042        struct berval mbv, nmbv;
00043        MDB_cursor *mc;
00044 
00045        Debug(LDAP_DEBUG_TRACE, "mdb_dn2entry(\"%s\")\n",
00046               dn->bv_val ? dn->bv_val : "", 0, 0 );
00047 
00048        *e = NULL;
00049 
00050        rc = mdb_dn2id( op, tid, m2, dn, &id, &mbv, &nmbv );
00051        if ( rc ) {
00052               if ( matched ) {
00053                      rc2 = mdb_cursor_open( tid, mdb->mi_id2entry, &mc );
00054                      if ( rc2 == MDB_SUCCESS ) {
00055                             rc2 = mdb_id2entry( op, mc, id, e );
00056                             mdb_cursor_close( mc );
00057                      }
00058               }
00059 
00060        } else {
00061               rc = mdb_cursor_open( tid, mdb->mi_id2entry, &mc );
00062               if ( rc == MDB_SUCCESS ) {
00063                      rc = mdb_id2entry( op, mc, id, e );
00064                      mdb_cursor_close(mc);
00065               }
00066        }
00067        if ( *e ) {
00068               (*e)->e_name = mbv;
00069               if ( rc == MDB_SUCCESS )
00070                      ber_dupbv_x( &(*e)->e_nname, dn, op->o_tmpmemctx );
00071               else
00072                      ber_dupbv_x( &(*e)->e_nname, &nmbv, op->o_tmpmemctx );
00073        }
00074 
00075        return rc;
00076 }