]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/dncache.c
Fix prev commit, return generated passwd
[openldap] / servers / slapd / back-meta / dncache.c
index a37d1e7706e39956c8356ff9887f97b4a6abd0f9..895573171d70dddef3186b109b0619086c80e444 100644 (file)
@@ -1,7 +1,24 @@
-/*
- * Copyright 1998-2001 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1999-2003 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
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* ACKNOWLEDGEMENTS:
+ * This work was initially developed by the Howard Chu for inclusion
+ * in OpenLDAP Software and subsequently enhanced by Pierangelo
+ * Masarati.
+ */
+/* This is an altered version */
+/*
  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
  *
  * This work has been developed to fulfill the requirements
@@ -77,7 +94,7 @@
  */
 
 struct metadncacheentry {
-       struct berval   *dn;
+       struct berval   dn;
        int             target;
 
        time_t          lastupdated;
@@ -99,12 +116,10 @@ meta_dncache_cmp(
        struct metadncacheentry *cc1 = ( struct metadncacheentry * )c1;
        struct metadncacheentry *cc2 = ( struct metadncacheentry * )c2;
 
-       int                     d = cc1->dn->bv_len - cc2->dn->bv_len;
-       
        /*
         * case sensitive, because the dn MUST be normalized
         */
-       return d != 0 ? d : strcmp( cc1->dn->bv_val, cc2->dn->bv_val );
+       return ber_bvcmp( &cc1->dn, &cc2->dn);
 }
 
 /*
@@ -122,15 +137,10 @@ meta_dncache_dup(
        struct metadncacheentry *cc1 = ( struct metadncacheentry * )c1;
        struct metadncacheentry *cc2 = ( struct metadncacheentry * )c2;
        
-       int                     d = cc1->dn->bv_len - cc2->dn->bv_len;
-       int                     cmp;
-       
        /*
         * case sensitive, because the dn MUST be normalized
         */
-       cmp = d != 0 ? d : strcmp( cc1->dn->bv_val, cc2->dn->bv_val );
-
-       return ( cmp == 0 ) ? -1 : 0;
+       return ( ber_bvcmp( &cc1->dn, &cc2->dn ) == 0 ) ? -1 : 0;
 }
 
 /*
@@ -149,7 +159,10 @@ meta_dncache_get_target(
        time_t curr_time;
        int target = -1;
 
-       tmp_entry.dn = ndn;
+       assert( cache );
+       assert( ndn );
+
+       tmp_entry.dn = *ndn;
        ldap_pvt_thread_mutex_lock( &cache->mutex );
        entry = ( struct metadncacheentry * )avl_find( cache->tree,
                        ( caddr_t )&tmp_entry, meta_dncache_cmp );
@@ -197,6 +210,9 @@ meta_dncache_update_entry(
        time_t curr_time = 0L;
        int err = 0;
 
+       assert( cache );
+       assert( ndn );
+
        /*
         * if cache->ttl < 0, cache never expires;
         * if cache->ttl = 0 no cache is used; shouldn't get here
@@ -210,7 +226,7 @@ meta_dncache_update_entry(
                curr_time = time( NULL );
        }
 
-       tmp_entry.dn = ndn;
+       tmp_entry.dn = *ndn;
 
        ldap_pvt_thread_mutex_lock( &cache->mutex );
        entry = ( struct metadncacheentry * )avl_find( cache->tree,
@@ -226,8 +242,8 @@ meta_dncache_update_entry(
                        return -1;
                }
 
-               entry->dn = ber_bvdup( ndn );
-               if ( entry->dn == NULL ) {
+               ber_dupbv( &entry->dn, ndn );
+               if ( entry->dn.bv_val == NULL ) {
                        ldap_pvt_thread_mutex_unlock( &cache->mutex );
                        return -1;
                }
@@ -256,12 +272,15 @@ meta_dncache_delete_entry(
 {
        struct metadncacheentry *entry, tmp_entry;
 
-       tmp_entry.dn = ndn;
+       assert( cache );
+       assert( ndn );
+
+       tmp_entry.dn = *ndn;
 
        ldap_pvt_thread_mutex_lock( &cache->mutex );
        entry = avl_delete( &cache->tree, ( caddr_t )&tmp_entry,
                        meta_dncache_cmp );
-       ldap_pvt_thread_mutex_lock( &cache->mutex );
+       ldap_pvt_thread_mutex_unlock( &cache->mutex );
 
        if ( entry != NULL ) {
                meta_dncache_free( ( void * )entry );
@@ -283,6 +302,6 @@ meta_dncache_free(
 {
        struct metadncacheentry *entry = ( struct metadncacheentry * )e;
 
-       ber_bvfree( entry->dn );
+       free( entry->dn.bv_val );
 }