]> 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 febb96341491c3cd2c7bc643a5276c68a6299413..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
  */
 
 struct metadncacheentry {
-       char *dn;
-       int target;
+       struct berval   dn;
+       int             target;
 
-       time_t lastupdated;
+       time_t          lastupdated;
 };
 
 /*
@@ -98,11 +115,11 @@ meta_dncache_cmp(
 {
        struct metadncacheentry *cc1 = ( struct metadncacheentry * )c1;
        struct metadncacheentry *cc2 = ( struct metadncacheentry * )c2;
-       
+
        /*
         * case sensitive, because the dn MUST be normalized
         */
-       return strcmp( cc1->dn, cc2->dn );
+       return ber_bvcmp( &cc1->dn, &cc2->dn);
 }
 
 /*
@@ -123,7 +140,7 @@ meta_dncache_dup(
        /*
         * case sensitive, because the dn MUST be normalized
         */
-       return ( strcmp( cc1->dn, cc2->dn ) == 0 ) ? -1 : 0;
+       return ( ber_bvcmp( &cc1->dn, &cc2->dn ) == 0 ) ? -1 : 0;
 }
 
 /*
@@ -135,14 +152,17 @@ meta_dncache_dup(
 int
 meta_dncache_get_target(
                struct metadncache      *cache,
-               const char              *ndn
+               struct berval           *ndn
 )
 {
        struct metadncacheentry tmp_entry, *entry;
        time_t curr_time;
        int target = -1;
 
-       tmp_entry.dn = ( char * )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 );
@@ -182,7 +202,7 @@ meta_dncache_get_target(
 int
 meta_dncache_update_entry(
                struct metadncache      *cache,
-               const char              *ndn,
+               struct berval           *ndn,
                int                     target
 )
 {
@@ -190,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
@@ -203,7 +226,7 @@ meta_dncache_update_entry(
                curr_time = time( NULL );
        }
 
-       tmp_entry.dn = ( char * )ndn;
+       tmp_entry.dn = *ndn;
 
        ldap_pvt_thread_mutex_lock( &cache->mutex );
        entry = ( struct metadncacheentry * )avl_find( cache->tree,
@@ -219,8 +242,8 @@ meta_dncache_update_entry(
                        return -1;
                }
 
-               entry->dn = ch_strdup( 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;
                }
@@ -244,17 +267,20 @@ meta_dncache_update_entry(
 int
 meta_dncache_delete_entry(
                struct metadncache      *cache,
-               const char              *ndn
+               struct berval           *ndn
 )
 {
        struct metadncacheentry *entry, tmp_entry;
 
-       tmp_entry.dn = ( char * )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 );
@@ -276,6 +302,6 @@ meta_dncache_free(
 {
        struct metadncacheentry *entry = ( struct metadncacheentry * )e;
 
-       free( entry->dn );
+       free( entry->dn.bv_val );
 }