]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/monitor.c
Plug mutex/rwlock leaks (destroy them)
[openldap] / servers / slapd / back-bdb / monitor.c
1 /* monitor.c - monitor bdb backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2000-2010 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20 #include <ac/string.h>
21 #include <ac/unistd.h>
22 #include <ac/stdlib.h>
23 #include <ac/errno.h>
24 #include <sys/stat.h>
25 #include "lutil.h"
26 #include "back-bdb.h"
27
28 #include "../back-monitor/back-monitor.h"
29
30 #include "config.h"
31
32 static ObjectClass              *oc_olmBDBDatabase;
33
34 static AttributeDescription     *ad_olmBDBEntryCache,
35         *ad_olmBDBDNCache, *ad_olmBDBIDLCache,
36         *ad_olmDbDirectory;
37
38 #ifdef BDB_MONITOR_IDX
39 static int
40 bdb_monitor_idx_entry_add(
41         struct bdb_info *bdb,
42         Entry           *e );
43
44 static AttributeDescription     *ad_olmBDBNotIndexed;
45 #endif /* BDB_MONITOR_IDX */
46
47 /*
48  * NOTE: there's some confusion in monitor OID arc;
49  * by now, let's consider:
50  * 
51  * Subsystems monitor attributes        1.3.6.1.4.1.4203.666.1.55.0
52  * Databases monitor attributes         1.3.6.1.4.1.4203.666.1.55.0.1
53  * BDB database monitor attributes      1.3.6.1.4.1.4203.666.1.55.0.1.1
54  *
55  * Subsystems monitor objectclasses     1.3.6.1.4.1.4203.666.3.16.0
56  * Databases monitor objectclasses      1.3.6.1.4.1.4203.666.3.16.0.1
57  * BDB database monitor objectclasses   1.3.6.1.4.1.4203.666.3.16.0.1.1
58  */
59
60 static struct {
61         char                    *name;
62         char                    *oid;
63 }               s_oid[] = {
64         { "olmBDBAttributes",                   "olmDatabaseAttributes:1" },
65         { "olmBDBObjectClasses",                "olmDatabaseObjectClasses:1" },
66
67         { NULL }
68 };
69
70 static struct {
71         char                    *desc;
72         AttributeDescription    **ad;
73 }               s_at[] = {
74         { "( olmBDBAttributes:1 "
75                 "NAME ( 'olmBDBEntryCache' ) "
76                 "DESC 'Number of items in Entry Cache' "
77                 "SUP monitorCounter "
78                 "NO-USER-MODIFICATION "
79                 "USAGE dSAOperation )",
80                 &ad_olmBDBEntryCache },
81
82         { "( olmBDBAttributes:2 "
83                 "NAME ( 'olmBDBDNCache' ) "
84                 "DESC 'Number of items in DN Cache' "
85                 "SUP monitorCounter "
86                 "NO-USER-MODIFICATION "
87                 "USAGE dSAOperation )",
88                 &ad_olmBDBDNCache },
89
90         { "( olmBDBAttributes:3 "
91                 "NAME ( 'olmBDBIDLCache' ) "
92                 "DESC 'Number of items in IDL Cache' "
93                 "SUP monitorCounter "
94                 "NO-USER-MODIFICATION "
95                 "USAGE dSAOperation )",
96                 &ad_olmBDBIDLCache },
97
98         { "( olmBDBAttributes:4 "
99                 "NAME ( 'olmDbDirectory' ) "
100                 "DESC 'Path name of the directory "
101                         "where the database environment resides' "
102                 "SUP monitoredInfo "
103                 "NO-USER-MODIFICATION "
104                 "USAGE dSAOperation )",
105                 &ad_olmDbDirectory },
106
107 #ifdef BDB_MONITOR_IDX
108         { "( olmBDBAttributes:5 "
109                 "NAME ( 'olmBDBNotIndexed' ) "
110                 "DESC 'Missing indexes resulting from candidate selection' "
111                 "SUP monitoredInfo "
112                 "NO-USER-MODIFICATION "
113                 "USAGE dSAOperation )",
114                 &ad_olmBDBNotIndexed },
115 #endif /* BDB_MONITOR_IDX */
116
117         { NULL }
118 };
119
120 static struct {
121         char            *desc;
122         ObjectClass     **oc;
123 }               s_oc[] = {
124         /* augments an existing object, so it must be AUXILIARY
125          * FIXME: derive from some ABSTRACT "monitoredEntity"? */
126         { "( olmBDBObjectClasses:1 "
127                 "NAME ( 'olmBDBDatabase' ) "
128                 "SUP top AUXILIARY "
129                 "MAY ( "
130                         "olmBDBEntryCache "
131                         "$ olmBDBDNCache "
132                         "$ olmBDBIDLCache "
133                         "$ olmDbDirectory "
134 #ifdef BDB_MONITOR_IDX
135                         "$ olmBDBNotIndexed "
136 #endif /* BDB_MONITOR_IDX */
137                         ") )",
138                 &oc_olmBDBDatabase },
139
140         { NULL }
141 };
142
143 static int
144 bdb_monitor_update(
145         Operation       *op,
146         SlapReply       *rs,
147         Entry           *e,
148         void            *priv )
149 {
150         struct bdb_info         *bdb = (struct bdb_info *) priv;
151         Attribute               *a;
152
153         char                    buf[ BUFSIZ ];
154         struct berval           bv;
155
156         assert( ad_olmBDBEntryCache != NULL );
157
158         a = attr_find( e->e_attrs, ad_olmBDBEntryCache );
159         assert( a != NULL );
160         bv.bv_val = buf;
161         bv.bv_len = snprintf( buf, sizeof( buf ), "%lu", bdb->bi_cache.c_cursize );
162         ber_bvreplace( &a->a_vals[ 0 ], &bv );
163
164         a = attr_find( e->e_attrs, ad_olmBDBDNCache );
165         assert( a != NULL );
166         bv.bv_len = snprintf( buf, sizeof( buf ), "%lu", bdb->bi_cache.c_eiused );
167         ber_bvreplace( &a->a_vals[ 0 ], &bv );
168
169         a = attr_find( e->e_attrs, ad_olmBDBIDLCache );
170         assert( a != NULL );
171         bv.bv_len = snprintf( buf, sizeof( buf ), "%lu", bdb->bi_idl_cache_size );
172         ber_bvreplace( &a->a_vals[ 0 ], &bv );
173         
174 #ifdef BDB_MONITOR_IDX
175         bdb_monitor_idx_entry_add( bdb, e );
176 #endif /* BDB_MONITOR_IDX */
177
178         return SLAP_CB_CONTINUE;
179 }
180
181 #if 0   /* uncomment if required */
182 static int
183 bdb_monitor_modify(
184         Operation       *op,
185         SlapReply       *rs,
186         Entry           *e,
187         void            *priv )
188 {
189         return SLAP_CB_CONTINUE;
190 }
191 #endif
192
193 static int
194 bdb_monitor_free(
195         Entry           *e,
196         void            **priv )
197 {
198         struct berval   values[ 2 ];
199         Modification    mod = { 0 };
200
201         const char      *text;
202         char            textbuf[ SLAP_TEXT_BUFLEN ];
203
204         int             i, rc;
205
206         /* NOTE: if slap_shutdown != 0, priv might have already been freed */
207         *priv = NULL;
208
209         /* Remove objectClass */
210         mod.sm_op = LDAP_MOD_DELETE;
211         mod.sm_desc = slap_schema.si_ad_objectClass;
212         mod.sm_values = values;
213         mod.sm_numvals = 1;
214         values[ 0 ] = oc_olmBDBDatabase->soc_cname;
215         BER_BVZERO( &values[ 1 ] );
216
217         rc = modify_delete_values( e, &mod, 1, &text,
218                 textbuf, sizeof( textbuf ) );
219         /* don't care too much about return code... */
220
221         /* remove attrs */
222         mod.sm_values = NULL;
223         mod.sm_numvals = 0;
224         for ( i = 0; s_at[ i ].desc != NULL; i++ ) {
225                 mod.sm_desc = *s_at[ i ].ad;
226                 rc = modify_delete_values( e, &mod, 1, &text,
227                         textbuf, sizeof( textbuf ) );
228                 /* don't care too much about return code... */
229         }
230         
231         return SLAP_CB_CONTINUE;
232 }
233
234 #define bdb_monitor_initialize  BDB_SYMBOL(monitor_initialize)
235
236 /*
237  * call from within bdb_initialize()
238  */
239 static int
240 bdb_monitor_initialize( void )
241 {
242         int             i, code;
243         ConfigArgs c;
244         char    *argv[ 3 ];
245
246         static int      bdb_monitor_initialized = 0;
247
248         if ( backend_info( "monitor" ) == NULL ) {
249                 return -1;
250         }
251
252         if ( bdb_monitor_initialized++ ) {
253                 return 0;
254         }
255
256         /* register schema here */
257
258         argv[ 0 ] = "back-bdb/back-hdb monitor";
259         c.argv = argv;
260         c.argc = 3;
261         c.fname = argv[0];
262
263         for ( i = 0; s_oid[ i ].name; i++ ) {
264                 c.lineno = i;
265                 argv[ 1 ] = s_oid[ i ].name;
266                 argv[ 2 ] = s_oid[ i ].oid;
267
268                 if ( parse_oidm( &c, 0, NULL ) != 0 ) {
269                         Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_monitor_initialize)
270                                 ": unable to add "
271                                 "objectIdentifier \"%s=%s\"\n",
272                                 s_oid[ i ].name, s_oid[ i ].oid, 0 );
273                         return 1;
274                 }
275         }
276
277         for ( i = 0; s_at[ i ].desc != NULL; i++ ) {
278                 code = register_at( s_at[ i ].desc, s_at[ i ].ad, 1 );
279                 if ( code != LDAP_SUCCESS ) {
280                         Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_monitor_initialize)
281                                 ": register_at failed\n",
282                                 0, 0, 0 );
283                 } else {
284                         (*s_at[ i ].ad)->ad_type->sat_flags |= SLAP_AT_HIDE;
285                 }
286         }
287
288         for ( i = 0; s_oc[ i ].desc != NULL; i++ ) {
289                 code = register_oc( s_oc[ i ].desc, s_oc[ i ].oc, 1 );
290                 if ( code != LDAP_SUCCESS ) {
291                         Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_monitor_initialize)
292                                 ": register_oc failed\n",
293                                 0, 0, 0 );
294                 } else {
295                         (*s_oc[ i ].oc)->soc_flags |= SLAP_OC_HIDE;
296                 }
297         }
298
299         return 0;
300 }
301
302 /*
303  * call from within bdb_db_init()
304  */
305 int
306 bdb_monitor_db_init( BackendDB *be )
307 {
308         struct bdb_info         *bdb = (struct bdb_info *) be->be_private;
309
310         if ( bdb_monitor_initialize() == LDAP_SUCCESS ) {
311                 /* monitoring in back-bdb is on by default */
312                 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_MONITORING;
313         }
314
315 #ifdef BDB_MONITOR_IDX
316         bdb->bi_idx = NULL;
317         ldap_pvt_thread_mutex_init( &bdb->bi_idx_mutex );
318 #endif /* BDB_MONITOR_IDX */
319
320         return 0;
321 }
322
323 /*
324  * call from within bdb_db_open()
325  */
326 int
327 bdb_monitor_db_open( BackendDB *be )
328 {
329         struct bdb_info         *bdb = (struct bdb_info *) be->be_private;
330         Attribute               *a, *next;
331         monitor_callback_t      *cb = NULL;
332         int                     rc = 0;
333         BackendInfo             *mi;
334         monitor_extra_t         *mbe;
335         struct berval dummy = BER_BVC("");
336
337         if ( !SLAP_DBMONITORING( be ) ) {
338                 return 0;
339         }
340
341         mi = backend_info( "monitor" );
342         if ( !mi || !mi->bi_extra ) {
343                 SLAP_DBFLAGS( be ) ^= SLAP_DBFLAG_MONITORING;
344                 return 0;
345         }
346         mbe = mi->bi_extra;
347
348         /* don't bother if monitor is not configured */
349         if ( !mbe->is_configured() ) {
350                 static int warning = 0;
351
352                 if ( warning++ == 0 ) {
353                         Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_monitor_db_open)
354                                 ": monitoring disabled; "
355                                 "configure monitor database to enable\n",
356                                 0, 0, 0 );
357                 }
358
359                 return 0;
360         }
361
362         /* alloc as many as required (plus 1 for objectClass) */
363         a = attrs_alloc( 1 + 4 );
364         if ( a == NULL ) {
365                 rc = 1;
366                 goto cleanup;
367         }
368
369         a->a_desc = slap_schema.si_ad_objectClass;
370         attr_valadd( a, &oc_olmBDBDatabase->soc_cname, NULL, 1 );
371         next = a->a_next;
372
373         {
374                 struct berval   bv = BER_BVC( "0" );
375
376                 next->a_desc = ad_olmBDBEntryCache;
377                 attr_valadd( next, &bv, NULL, 1 );
378                 next = next->a_next;
379
380                 next->a_desc = ad_olmBDBDNCache;
381                 attr_valadd( next, &bv, NULL, 1 );
382                 next = next->a_next;
383
384                 next->a_desc = ad_olmBDBIDLCache;
385                 attr_valadd( next, &bv, NULL, 1 );
386                 next = next->a_next;
387         }
388
389         {
390                 struct berval   bv, nbv;
391                 ber_len_t       pathlen = 0, len = 0;
392                 char            path[ MAXPATHLEN ] = { '\0' };
393                 char            *fname = bdb->bi_dbenv_home,
394                                 *ptr;
395
396                 len = strlen( fname );
397                 if ( fname[ 0 ] != '/' ) {
398                         /* get full path name */
399                         getcwd( path, sizeof( path ) );
400                         pathlen = strlen( path );
401
402                         if ( fname[ 0 ] == '.' && fname[ 1 ] == '/' ) {
403                                 fname += 2;
404                                 len -= 2;
405                         }
406                 }
407
408                 bv.bv_len = pathlen + STRLENOF( "/" ) + len;
409                 ptr = bv.bv_val = ch_malloc( bv.bv_len + STRLENOF( "/" ) + 1 );
410                 if ( pathlen ) {
411                         ptr = lutil_strncopy( ptr, path, pathlen );
412                         ptr[ 0 ] = '/';
413                         ptr++;
414                 }
415                 ptr = lutil_strncopy( ptr, fname, len );
416                 if ( ptr[ -1 ] != '/' ) {
417                         ptr[ 0 ] = '/';
418                         ptr++;
419                 }
420                 ptr[ 0 ] = '\0';
421                 
422                 attr_normalize_one( ad_olmDbDirectory, &bv, &nbv, NULL );
423
424                 next->a_desc = ad_olmDbDirectory;
425                 next->a_vals = ch_calloc( sizeof( struct berval ), 2 );
426                 next->a_vals[ 0 ] = bv;
427                 next->a_numvals = 1;
428
429                 if ( BER_BVISNULL( &nbv ) ) {
430                         next->a_nvals = next->a_vals;
431
432                 } else {
433                         next->a_nvals = ch_calloc( sizeof( struct berval ), 2 );
434                         next->a_nvals[ 0 ] = nbv;
435                 }
436
437                 next = next->a_next;
438         }
439
440         cb = ch_calloc( sizeof( monitor_callback_t ), 1 );
441         cb->mc_update = bdb_monitor_update;
442 #if 0   /* uncomment if required */
443         cb->mc_modify = bdb_monitor_modify;
444 #endif
445         cb->mc_free = bdb_monitor_free;
446         cb->mc_private = (void *)bdb;
447
448         /* make sure the database is registered; then add monitor attributes */
449         rc = mbe->register_database( be, &bdb->bi_monitor.bdm_ndn );
450         if ( rc == 0 ) {
451                 rc = mbe->register_entry_attrs( &bdb->bi_monitor.bdm_ndn, a, cb,
452                         &dummy, 0, &dummy );
453         }
454
455 cleanup:;
456         if ( rc != 0 ) {
457                 if ( cb != NULL ) {
458                         ch_free( cb );
459                         cb = NULL;
460                 }
461
462                 if ( a != NULL ) {
463                         attrs_free( a );
464                         a = NULL;
465                 }
466         }
467
468         /* store for cleanup */
469         bdb->bi_monitor.bdm_cb = (void *)cb;
470
471         /* we don't need to keep track of the attributes, because
472          * bdb_monitor_free() takes care of everything */
473         if ( a != NULL ) {
474                 attrs_free( a );
475         }
476
477         return rc;
478 }
479
480 /*
481  * call from within bdb_db_close()
482  */
483 int
484 bdb_monitor_db_close( BackendDB *be )
485 {
486         struct bdb_info         *bdb = (struct bdb_info *) be->be_private;
487
488         if ( !BER_BVISNULL( &bdb->bi_monitor.bdm_ndn ) ) {
489                 BackendInfo             *mi = backend_info( "monitor" );
490                 monitor_extra_t         *mbe;
491
492                 if ( mi && &mi->bi_extra ) {
493                         mbe = mi->bi_extra;
494                         mbe->unregister_entry_callback( &bdb->bi_monitor.bdm_ndn,
495                                 (monitor_callback_t *)bdb->bi_monitor.bdm_cb,
496                                 NULL, 0, NULL );
497                 }
498
499                 memset( &bdb->bi_monitor, 0, sizeof( bdb->bi_monitor ) );
500         }
501
502         return 0;
503 }
504
505 /*
506  * call from within bdb_db_destroy()
507  */
508 int
509 bdb_monitor_db_destroy( BackendDB *be )
510 {
511 #ifdef BDB_MONITOR_IDX
512         struct bdb_info         *bdb = (struct bdb_info *) be->be_private;
513
514         /* TODO: free tree */
515         ldap_pvt_thread_mutex_destroy( &bdb->bi_idx_mutex );
516         avl_free( bdb->bi_idx, ch_free );
517 #endif /* BDB_MONITOR_IDX */
518
519         return 0;
520 }
521
522 #ifdef BDB_MONITOR_IDX
523
524 #define BDB_MONITOR_IDX_TYPES   (4)
525
526 typedef struct monitor_idx_t monitor_idx_t;
527
528 struct monitor_idx_t {
529         AttributeDescription    *idx_ad;
530         unsigned long           idx_count[BDB_MONITOR_IDX_TYPES];
531 };
532
533 static int
534 bdb_monitor_bitmask2key( slap_mask_t bitmask )
535 {
536         int     key;
537
538         for ( key = 0; key < 8 * (int)sizeof(slap_mask_t) && !( bitmask & 0x1U );
539                         key++ )
540                 bitmask >>= 1;
541
542         return key;
543 }
544
545 static struct berval idxbv[] = {
546         BER_BVC( "present=" ),
547         BER_BVC( "equality=" ),
548         BER_BVC( "approx=" ),
549         BER_BVC( "substr=" ),
550         BER_BVNULL
551 };
552
553 static ber_len_t
554 bdb_monitor_idx2len( monitor_idx_t *idx )
555 {
556         int             i;
557         ber_len_t       len = 0;
558
559         for ( i = 0; i < BDB_MONITOR_IDX_TYPES; i++ ) {
560                 if ( idx->idx_count[ i ] != 0 ) {
561                         len += idxbv[i].bv_len;
562                 }
563         }
564
565         return len;
566 }
567
568 static int
569 monitor_idx_cmp( const void *p1, const void *p2 )
570 {
571         const monitor_idx_t     *idx1 = (const monitor_idx_t *)p1;
572         const monitor_idx_t     *idx2 = (const monitor_idx_t *)p2;
573
574         return SLAP_PTRCMP( idx1->idx_ad, idx2->idx_ad );
575 }
576
577 static int
578 monitor_idx_dup( void *p1, void *p2 )
579 {
580         monitor_idx_t   *idx1 = (monitor_idx_t *)p1;
581         monitor_idx_t   *idx2 = (monitor_idx_t *)p2;
582
583         return SLAP_PTRCMP( idx1->idx_ad, idx2->idx_ad ) == 0 ? -1 : 0;
584 }
585
586 int
587 bdb_monitor_idx_add(
588         struct bdb_info         *bdb,
589         AttributeDescription    *desc,
590         slap_mask_t             type )
591 {
592         monitor_idx_t           idx_dummy = { 0 },
593                                 *idx;
594         int                     rc = 0, key;
595
596         idx_dummy.idx_ad = desc;
597         key = bdb_monitor_bitmask2key( type ) - 1;
598         if ( key >= BDB_MONITOR_IDX_TYPES ) {
599                 /* invalid index type */
600                 return -1;
601         }
602
603         ldap_pvt_thread_mutex_lock( &bdb->bi_idx_mutex );
604
605         idx = (monitor_idx_t *)avl_find( bdb->bi_idx,
606                 (caddr_t)&idx_dummy, monitor_idx_cmp );
607         if ( idx == NULL ) {
608                 idx = (monitor_idx_t *)ch_calloc( sizeof( monitor_idx_t ), 1 );
609                 idx->idx_ad = desc;
610                 idx->idx_count[ key ] = 1;
611
612                 switch ( avl_insert( &bdb->bi_idx, (caddr_t)idx, 
613                         monitor_idx_cmp, monitor_idx_dup ) )
614                 {
615                 case 0:
616                         break;
617
618                 default:
619                         ch_free( idx );
620                         rc = -1;
621                 }
622
623         } else {
624                 idx->idx_count[ key ]++;
625         }
626
627         ldap_pvt_thread_mutex_unlock( &bdb->bi_idx_mutex );
628
629         return rc;
630 }
631
632 static int
633 bdb_monitor_idx_apply( void *v_idx, void *v_valp )
634 {
635         monitor_idx_t   *idx = (monitor_idx_t *)v_idx;
636         BerVarray       *valp = (BerVarray *)v_valp;
637
638         struct berval   bv;
639         char            *ptr;
640         char            count_buf[ BDB_MONITOR_IDX_TYPES ][ SLAP_TEXT_BUFLEN ];
641         ber_len_t       count_len[ BDB_MONITOR_IDX_TYPES ],
642                         idx_len;
643         int             i, num = 0;
644
645         idx_len = bdb_monitor_idx2len( idx );
646
647         bv.bv_len = 0;
648         for ( i = 0; i < BDB_MONITOR_IDX_TYPES; i++ ) {
649                 if ( idx->idx_count[ i ] == 0 ) {
650                         continue;
651                 }
652
653                 count_len[ i ] = snprintf( count_buf[ i ],
654                         sizeof( count_buf[ i ] ), "%lu", idx->idx_count[ i ] );
655                 bv.bv_len += count_len[ i ];
656                 num++;
657         }
658
659         bv.bv_len += idx->idx_ad->ad_cname.bv_len
660                 + num
661                 + idx_len;
662         ptr = bv.bv_val = ch_malloc( bv.bv_len + 1 );
663         ptr = lutil_strcopy( ptr, idx->idx_ad->ad_cname.bv_val );
664         for ( i = 0; i < BDB_MONITOR_IDX_TYPES; i++ ) {
665                 if ( idx->idx_count[ i ] == 0 ) {
666                         continue;
667                 }
668
669                 ptr[ 0 ] = '#';
670                 ++ptr;
671                 ptr = lutil_strcopy( ptr, idxbv[ i ].bv_val );
672                 ptr = lutil_strcopy( ptr, count_buf[ i ] );
673         }
674
675         ber_bvarray_add( valp, &bv );
676
677         return 0;
678 }
679
680 static int
681 bdb_monitor_idx_entry_add(
682         struct bdb_info *bdb,
683         Entry           *e )
684 {
685         BerVarray       vals = NULL;
686         Attribute       *a;
687
688         a = attr_find( e->e_attrs, ad_olmBDBNotIndexed );
689
690         ldap_pvt_thread_mutex_lock( &bdb->bi_idx_mutex );
691
692         avl_apply( bdb->bi_idx, bdb_monitor_idx_apply,
693                 &vals, -1, AVL_INORDER );
694
695         ldap_pvt_thread_mutex_unlock( &bdb->bi_idx_mutex );
696
697         if ( vals != NULL ) {
698                 if ( a != NULL ) {
699                         assert( a->a_nvals == a->a_vals );
700
701                         ber_bvarray_free( a->a_vals );
702
703                 } else {
704                         Attribute       **ap;
705
706                         for ( ap = &e->e_attrs; *ap != NULL; ap = &(*ap)->a_next )
707                                 ;
708                         *ap = attr_alloc( ad_olmBDBNotIndexed );
709                         a = *ap;
710                 }
711                 a->a_vals = vals;
712                 a->a_nvals = a->a_vals;
713         }
714
715         return 0;
716 }
717
718 #endif /* BDB_MONITOR_IDX */