]> git.sur5r.net Git - openldap/commitdiff
set the berval length\! (ITS#4196)
authorPierangelo Masarati <ando@openldap.org>
Tue, 22 Nov 2005 12:13:07 +0000 (12:13 +0000)
committerPierangelo Masarati <ando@openldap.org>
Tue, 22 Nov 2005 12:13:07 +0000 (12:13 +0000)
servers/slapd/back-meta/config.c
servers/slapd/back-meta/dncache.c

index 035b5a21ec311fd26767e6acfaca0b60c4462bf0..e733fa7eb505ba3cecfbcd94119c8abe71885c83 100644 (file)
@@ -334,7 +334,15 @@ meta_back_db_config(
                } else if ( strcasecmp( argv[ 1 ], "disabled" ) == 0 ) {
                        mi->mi_cache.ttl = META_DNCACHE_DISABLED;
                } else {
-                       mi->mi_cache.ttl = atol( argv[ 1 ] );
+                       char            *next;
+
+                       mi->mi_cache.ttl = strtol( argv[ 1 ], &next, 10 );
+                       if ( next == argv[ 1 ] || next[ 0 ] != '\0' ) {
+                               fprintf( stderr,
+       "%s: line %d: unable to parse ttl \"%s\" in \"dncache-ttl <ttl>\" line\n",
+                                       fname, lineno, argv[ 1 ] );
+                               return 1;
+                       }
                }
 
        /* network timeout when connecting to ldap servers */
index ccaf446de6f8b098e86576a5b1fc080a1f0e0792..1257862ee8cb53ec6fe567c35e7b812290f50916 100644 (file)
@@ -94,7 +94,6 @@ meta_dncache_get_target(
 {
        metadncacheentry_t      tmp_entry,
                                *entry;
-       time_t                  curr_time;
        int                     target = META_TARGET_NONE;
 
        assert( cache != NULL );
@@ -116,13 +115,7 @@ meta_dncache_get_target(
                        target = entry->target;
 
                } else {
-
-                       /*
-                        * Need mutex?
-                        */     
-                       curr_time = time( NULL );
-
-                       if ( entry->lastupdated+cache->ttl > curr_time ) {
+                       if ( entry->lastupdated+cache->ttl > slap_get_time() ) {
                                target = entry->target;
                        }
                }
@@ -158,11 +151,7 @@ meta_dncache_update_entry(
         * else, cache is used with ttl
         */
        if ( cache->ttl > 0 ) {
-
-               /*
-                * Need mutex?
-                */
-               curr_time = time( NULL );
+               curr_time = slap_get_time();
        }
 
        tmp_entry.dn = *ndn;
@@ -178,18 +167,23 @@ meta_dncache_update_entry(
        } else {
                entry = ch_malloc( sizeof( metadncacheentry_t ) + ndn->bv_len + 1 );
                if ( entry == NULL ) {
-                       ldap_pvt_thread_mutex_unlock( &cache->mutex );
-                       return -1;
+                       err = -1;
+                       goto error_return;
                }
 
+               entry->dn.bv_len = ndn->bv_len;
                entry->dn.bv_val = (char *)&entry[ 1 ];
-               AC_MEMCPY( entry->dn.bv_val, ndn->bv_val, ndn->bv_len + 1 );
+               AC_MEMCPY( entry->dn.bv_val, ndn->bv_val, ndn->bv_len );
+               entry->dn.bv_val[ ndn->bv_len ] = '\0';
+
                entry->target = target;
                entry->lastupdated = curr_time;
 
                err = avl_insert( &cache->tree, ( caddr_t )entry,
                                meta_dncache_cmp, meta_dncache_dup );
        }
+
+error_return:;
        ldap_pvt_thread_mutex_unlock( &cache->mutex );
 
        return err;