]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/database.c
451ddc8572f0cf3f60f4361d505d86b22cd003c8
[openldap] / servers / slapd / back-monitor / database.c
1 /* database.c - deals with database subsystem */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2001-2004 The OpenLDAP Foundation.
6  * Portions Copyright 2001-2003 Pierangelo Masarati.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Pierangelo Masarati for inclusion
19  * in OpenLDAP Software.
20  */
21
22 #include "portable.h"
23
24 #include <stdio.h>
25 #include <ac/string.h>
26
27 #include "slap.h"
28 #include "back-monitor.h"
29
30 #if defined(LDAP_SLAPI)
31 #include "slapi.h"
32 static int monitor_back_add_plugin( Backend *be, Entry *e );
33 #endif /* defined(LDAP_SLAPI) */
34
35 #if defined(SLAPD_LDAP) 
36 #include "../back-ldap/back-ldap.h"
37 #endif /* defined(SLAPD_LDAP) */
38
39 static struct restricted_ops_t {
40         struct berval   op;
41         unsigned int    tag;
42 } restricted_ops[] = {
43         { BER_BVC( "add" ),                     SLAP_RESTRICT_OP_ADD },
44         { BER_BVC( "bind" ),                    SLAP_RESTRICT_OP_BIND },
45         { BER_BVC( "compare" ),                 SLAP_RESTRICT_OP_COMPARE },
46         { BER_BVC( "delete" ),                  SLAP_RESTRICT_OP_DELETE },
47         { BER_BVC( "extended" ),                SLAP_RESTRICT_OP_EXTENDED },
48         { BER_BVC( "modify" ),                  SLAP_RESTRICT_OP_MODIFY },
49         { BER_BVC( "rename" ),                  SLAP_RESTRICT_OP_RENAME },
50         { BER_BVC( "search" ),                  SLAP_RESTRICT_OP_SEARCH },
51         { BER_BVNULL,                           0 }
52 }, restricted_exops[] = {
53         { BER_BVC( LDAP_EXOP_START_TLS ),       SLAP_RESTRICT_EXOP_START_TLS },
54         { BER_BVC( LDAP_EXOP_MODIFY_PASSWD ),   SLAP_RESTRICT_EXOP_MODIFY_PASSWD },
55         { BER_BVC( LDAP_EXOP_X_WHO_AM_I ),      SLAP_RESTRICT_EXOP_WHOAMI },
56         { BER_BVC( LDAP_EXOP_X_CANCEL ),        SLAP_RESTRICT_EXOP_CANCEL },
57         { BER_BVNULL,                           0 }
58 };
59
60 static int
61 init_readOnly( monitor_info_t *mi, Entry *e, slap_mask_t restrictops )
62 {
63         struct berval   *tf = ( ( restrictops & SLAP_RESTRICT_OP_MASK ) == SLAP_RESTRICT_OP_WRITES ) ?
64                 (struct berval *)&slap_true_bv : (struct berval *)&slap_false_bv;
65
66         return attr_merge_one( e, mi->mi_ad_readOnly, tf, NULL );
67 }
68
69 static int
70 init_restrictedOperation( monitor_info_t *mi, Entry *e, slap_mask_t restrictops )
71 {
72         int     i, rc;
73
74         for ( i = 0; restricted_ops[ i ].op.bv_val; i++ ) {
75                 if ( restrictops & restricted_ops[ i ].tag ) {
76                         rc = attr_merge_one( e, mi->mi_ad_restrictedOperation,
77                                         &restricted_ops[ i ].op, NULL );
78                         if ( rc ) {
79                                 return rc;
80                         }
81                 }
82         }
83
84         for ( i = 0; restricted_exops[ i ].op.bv_val; i++ ) {
85                 if ( restrictops & restricted_exops[ i ].tag ) {
86                         rc = attr_merge_one( e, mi->mi_ad_restrictedOperation,
87                                         &restricted_exops[ i ].op, NULL );
88                         if ( rc ) {
89                                 return rc;
90                         }
91                 }
92         }
93
94         return LDAP_SUCCESS;
95 }
96
97 int
98 monitor_subsys_database_init(
99         BackendDB               *be,
100         monitor_subsys_t        *ms
101 )
102 {
103         monitor_info_t          *mi;
104         Entry                   *e_database, **ep;
105         int                     i;
106         monitor_entry_t         *mp;
107         monitor_subsys_t        *ms_backend,
108                                 *ms_overlay;
109
110         assert( be != NULL );
111
112         mi = ( monitor_info_t * )be->be_private;
113
114         ms_backend = monitor_back_get_subsys( SLAPD_MONITOR_BACKEND_NAME );
115         if ( ms_backend == NULL ) {
116                 Debug( LDAP_DEBUG_ANY,
117                         "monitor_subsys_database_init: "
118                         "unable to get "
119                         "\"" SLAPD_MONITOR_BACKEND_NAME "\" "
120                         "subsystem\n",
121                         0, 0, 0 );
122                 return -1;
123         }
124
125         ms_overlay = monitor_back_get_subsys( SLAPD_MONITOR_OVERLAY_NAME );
126         if ( ms_overlay == NULL ) {
127                 Debug( LDAP_DEBUG_ANY,
128                         "monitor_subsys_database_init: "
129                         "unable to get "
130                         "\"" SLAPD_MONITOR_OVERLAY_NAME "\" "
131                         "subsystem\n",
132                         0, 0, 0 );
133                 return -1;
134         }
135
136         if ( monitor_cache_get( mi, &ms->mss_ndn, &e_database ) ) {
137                 Debug( LDAP_DEBUG_ANY,
138                         "monitor_subsys_database_init: "
139                         "unable to get entry \"%s\"\n",
140                         ms->mss_ndn.bv_val, 0, 0 );
141                 return( -1 );
142         }
143
144         (void)init_readOnly( mi, e_database, frontendDB->be_restrictops );
145         (void)init_restrictedOperation( mi, e_database, frontendDB->be_restrictops );
146
147         mp = ( monitor_entry_t * )e_database->e_private;
148         mp->mp_children = NULL;
149         ep = &mp->mp_children;
150
151         for ( i = 0; i < nBackendDB; i++ ) {
152                 char            buf[ BACKMONITOR_BUFSIZE ];
153                 int             j;
154                 slap_overinfo   *oi = NULL;
155                 BackendInfo     *bi;
156                 Entry           *e;
157
158                 be = &backendDB[ i ];
159
160                 bi = be->bd_info;
161
162                 if ( overlay_is_over( be ) ) {
163                         oi = (slap_overinfo *)be->bd_info->bi_private;
164                         bi = oi->oi_orig;
165                 }
166
167                 /* Subordinates are not exposed as their own naming context */
168                 if ( SLAP_GLUE_SUBORDINATE( be ) ) {
169                         continue;
170                 }
171
172                 snprintf( buf, sizeof( buf ),
173                                 "dn: cn=Database %d,%s\n"
174                                 "objectClass: %s\n"
175                                 "structuralObjectClass: %s\n"
176                                 "cn: Database %d\n"
177                                 "description: This object contains the type of the database.\n"
178                                 "%s: %s\n"
179                                 "creatorsName: %s\n"
180                                 "modifiersName: %s\n"
181                                 "createTimestamp: %s\n"
182                                 "modifyTimestamp: %s\n",
183                                 i,
184                                 ms->mss_dn.bv_val,
185                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
186                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
187                                 i,
188                                 mi->mi_ad_monitoredInfo->ad_cname.bv_val,
189                                 bi->bi_type,
190                                 mi->mi_creatorsName.bv_val,
191                                 mi->mi_creatorsName.bv_val,
192                                 mi->mi_startTime.bv_val,
193                                 mi->mi_startTime.bv_val );
194                 
195                 e = str2entry( buf );
196                 if ( e == NULL ) {
197                         Debug( LDAP_DEBUG_ANY,
198                                 "monitor_subsys_database_init: "
199                                 "unable to create entry \"cn=Database %d,%s\"\n",
200                                 i, ms->mss_ndn.bv_val, 0 );
201                         return( -1 );
202                 }
203                 
204                 if ( SLAP_MONITOR(be) ) {
205                         attr_merge( e, slap_schema.si_ad_monitorContext,
206                                         be->be_suffix, be->be_nsuffix );
207                         attr_merge( e_database, slap_schema.si_ad_monitorContext,
208                                         be->be_suffix, be->be_nsuffix );
209                 } else {
210                         attr_merge( e, slap_schema.si_ad_namingContexts,
211                                         be->be_suffix, be->be_nsuffix );
212                         attr_merge( e_database, slap_schema.si_ad_namingContexts,
213                                         be->be_suffix, be->be_nsuffix );
214                 }
215
216                 (void)init_readOnly( mi, e, be->be_restrictops );
217                 (void)init_restrictedOperation( mi, e, be->be_restrictops );
218
219                 if ( oi != NULL ) {
220                         slap_overinst   *on = oi->oi_list,
221                                         *on1 = on;
222
223                         for ( ; on; on = on->on_next ) {
224                                 struct berval           bv;
225                                 slap_overinst           *on2;
226
227                                 for ( on2 = on1; on2 != on; on2 = on2->on_next ) {
228                                         if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
229                                                 break;
230                                         }
231                                 }
232
233                                 if ( on2 != on ) {
234                                         break;
235                                 }
236                                 
237                                 bv.bv_val = on->on_bi.bi_type;
238                                 bv.bv_len = strlen( bv.bv_val );
239                                 attr_merge_normalize_one( e, mi->mi_ad_monitorOverlay,
240                                                 &bv, NULL );
241
242                                 /* find the overlay number, j */
243                                 for ( on2 = overlay_next( NULL ), j = 0; on2; on2 = overlay_next( on2 ), j++ ) {
244                                         if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
245                                                 break;
246                                         }
247                                 }
248                                 assert( on2 );
249
250                                 snprintf( buf, sizeof( buf ), 
251                                         "cn=Overlay %d,%s", 
252                                         j, ms_overlay->mss_dn.bv_val );
253                                 bv.bv_val = buf;
254                                 bv.bv_len = strlen( buf );
255                                 attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
256                                                 &bv, NULL );
257                         }
258                 }
259
260 #if defined(SLAPD_LDAP) 
261                 if ( strcmp( bi->bi_type, "ldap" ) == 0 ) {
262                         struct ldapinfo         *li = (struct ldapinfo *)be->be_private;
263                         struct berval           bv;
264
265                         bv.bv_val = li->url;
266                         bv.bv_len = strlen( bv.bv_val );
267                         attr_merge_normalize_one( e, slap_schema.si_ad_labeledURI,
268                                         &bv, NULL );
269                 }
270 #endif /* defined(SLAPD_LDAP) */
271
272                 for ( j = 0; j < nBackendInfo; j++ ) {
273                         if ( backendInfo[ j ].bi_type == bi->bi_type ) {
274                                 struct berval           bv;
275
276                                 snprintf( buf, sizeof( buf ), 
277                                         "cn=Backend %d,%s", 
278                                         j, ms_backend->mss_dn.bv_val );
279                                 bv.bv_val = buf;
280                                 bv.bv_len = strlen( buf );
281                                 attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
282                                                 &bv, NULL );
283                                 break;
284                         }
285                 }
286                 /* we must find it! */
287                 assert( j >= 0 );
288
289                 mp = monitor_entrypriv_create();
290                 if ( mp == NULL ) {
291                         return -1;
292                 }
293                 e->e_private = ( void * )mp;
294                 mp->mp_info = ms;
295                 mp->mp_flags = ms->mss_flags
296                         | MONITOR_F_SUB;
297
298                 if ( monitor_cache_add( mi, e ) ) {
299                         Debug( LDAP_DEBUG_ANY,
300                                 "monitor_subsys_database_init: "
301                                 "unable to add entry \"cn=Database %d,%s\"\n",
302                                 i, ms->mss_ndn.bv_val, 0 );
303                         return( -1 );
304                 }
305
306 #if defined(LDAP_SLAPI)
307                 monitor_back_add_plugin( be, e );
308 #endif /* defined(LDAP_SLAPI) */
309
310                 *ep = e;
311                 ep = &mp->mp_next;
312         }
313         
314         monitor_cache_release( mi, e_database );
315
316         return( 0 );
317 }
318
319 /*
320  * v: array of values
321  * cur: must not contain the tags corresponding to the values in v
322  * delta: will contain the tags corresponding to the values in v
323  */
324 static int
325 value_mask( BerVarray v, slap_mask_t cur, slap_mask_t *delta )
326 {
327         for ( ; !BER_BVISNULL( v ); v++ ) {
328                 struct restricted_ops_t         *rops;
329                 int                             i;
330
331                 if ( OID_LEADCHAR( v->bv_val[ 0 ] ) ) {
332                         rops = restricted_exops;
333
334                 } else {
335                         rops = restricted_ops;
336                 }
337
338                 for ( i = 0; !BER_BVISNULL( &rops[ i ].op ); i++ ) {
339                         if ( ber_bvstrcasecmp( v, &rops[ i ].op ) != 0 ) {
340                                 continue;
341                         }
342
343                         if ( rops[ i ].tag & *delta ) {
344                                 return LDAP_OTHER;
345                         }
346
347                         if ( rops[ i ].tag & cur ) {
348                                 return LDAP_OTHER;
349                         }
350
351                         cur |= rops[ i ].tag;
352                         *delta |= rops[ i ].tag;
353
354                         break;
355                 }
356
357                 if ( BER_BVISNULL( &rops[ i ].op ) ) {
358                         return LDAP_INVALID_SYNTAX;
359                 }
360         }
361
362         return LDAP_SUCCESS;
363 }
364
365 int
366 monitor_subsys_database_modify(
367         Operation       *op,
368         Entry           *e
369 )
370 {
371         monitor_info_t  *mi = (monitor_info_t *)op->o_bd->be_private;
372         int             rc = LDAP_OTHER;
373         Attribute       *save_attrs, *a;
374         Modifications   *modlist = op->oq_modify.rs_modlist;
375         Modifications   *ml;
376         Backend         *be;
377         int             ro_gotval = 1, i, n;
378         slap_mask_t     rp_add = 0, rp_delete = 0, rp_cur;
379         struct berval   *tf;
380         
381         i = sscanf( e->e_nname.bv_val, "cn=database %d,", &n );
382         if ( i != 1 )
383                 return LDAP_UNWILLING_TO_PERFORM;
384
385         if ( n < 0 || n >= nBackendDB )
386                 return LDAP_NO_SUCH_OBJECT;
387
388         /* do not allow some changes on back-monitor (needs work)... */
389         be = &backendDB[ n ];
390         if ( SLAP_MONITOR( be ) )
391                 return LDAP_UNWILLING_TO_PERFORM;
392                 
393         rp_cur = be->be_restrictops;
394
395         save_attrs = e->e_attrs;
396         e->e_attrs = attrs_dup( e->e_attrs );
397
398         for ( ml=modlist; ml; ml=ml->sml_next ) {
399                 Modification *mod = &ml->sml_mod;
400
401                 if ( mod->sm_desc == mi->mi_ad_readOnly ) {
402                         int     val = -1;
403
404                         if ( mod->sm_values ) {
405                                 if ( !BER_BVISNULL( &mod->sm_values[ 1 ] ) ) {
406                                         rc = LDAP_CONSTRAINT_VIOLATION;
407                                         goto done;
408                                 }
409
410                                 if ( bvmatch( &slap_true_bv, mod->sm_values )) {
411                                         val = 1;
412
413                                 } else if ( bvmatch( &slap_false_bv, mod->sm_values )) {
414                                         val = 0;
415
416                                 } else {
417                                         rc = LDAP_INVALID_SYNTAX;
418                                         goto done;
419                                 }
420                         }
421
422                         switch ( mod->sm_op ) {
423                         case LDAP_MOD_DELETE:
424                                 if ( ro_gotval < 1 ) {
425                                         rc = LDAP_CONSTRAINT_VIOLATION;
426                                         goto done;
427                                 }
428                                 ro_gotval--;
429
430                                 if ( val == 0 && ( rp_cur & SLAP_RESTRICT_OP_WRITES ) == SLAP_RESTRICT_OP_WRITES ) {
431                                         rc = LDAP_NO_SUCH_ATTRIBUTE;
432                                         goto done;
433                                 }
434                                 
435                                 if ( val == 1 && ( rp_cur & SLAP_RESTRICT_OP_WRITES ) != SLAP_RESTRICT_OP_WRITES ) {
436                                         rc = LDAP_NO_SUCH_ATTRIBUTE;
437                                         goto done;
438                                 }
439                                 
440                                 break;
441
442                         case LDAP_MOD_REPLACE:
443                                 ro_gotval = 0;
444                                 /* fall thru */
445
446                         case LDAP_MOD_ADD:
447                                 if ( ro_gotval > 0 ) {
448                                         rc = LDAP_CONSTRAINT_VIOLATION;
449                                         goto done;
450                                 }
451                                 ro_gotval++;
452
453                                 if ( val == 1 ) {
454                                         rp_add |= (~rp_cur) & SLAP_RESTRICT_OP_WRITES;
455                                         rp_cur |= SLAP_RESTRICT_OP_WRITES;
456                                         rp_delete &= ~SLAP_RESTRICT_OP_WRITES;
457                                         
458                                 } else if ( val == 0 ) {
459                                         rp_delete |= rp_cur & SLAP_RESTRICT_OP_WRITES;
460                                         rp_cur &= ~SLAP_RESTRICT_OP_WRITES;
461                                         rp_add &= ~SLAP_RESTRICT_OP_WRITES;
462                                 }
463                                 break;
464
465                         default:
466                                 rc = LDAP_OTHER;
467                                 goto done;
468                         }
469
470                 } else if ( mod->sm_desc == mi->mi_ad_restrictedOperation ) {
471                         slap_mask_t     mask = 0;
472
473                         switch ( mod->sm_op ) {
474                         case LDAP_MOD_DELETE:
475                                 if ( mod->sm_values == NULL ) {
476                                         rp_delete = rp_cur;
477                                         rp_cur = 0;
478                                         rp_add = 0;
479                                         break;
480                                 }
481                                 rc = value_mask( mod->sm_values, ~rp_cur, &mask );
482                                 if ( rc == LDAP_SUCCESS ) {
483                                         rp_delete |= mask;
484                                         rp_add &= ~mask;
485                                         rp_cur &= ~mask;
486
487                                 } else if ( rc == LDAP_OTHER ) {
488                                         rc = LDAP_NO_SUCH_ATTRIBUTE;
489                                 }
490                                 break;
491
492                         case LDAP_MOD_REPLACE:
493                                 rp_delete = rp_cur;
494                                 rp_cur = 0;
495                                 rp_add = 0;
496                                 /* fall thru */
497
498                         case LDAP_MOD_ADD:
499                                 rc = value_mask( mod->sm_values, rp_cur, &mask );
500                                 if ( rc == LDAP_SUCCESS ) {
501                                         rp_add |= mask;
502                                         rp_cur |= mask;
503                                         rp_delete &= ~mask;
504
505                                 } else if ( rc == LDAP_OTHER ) {
506                                         rc = LDAP_TYPE_OR_VALUE_EXISTS;
507                                 }
508                                 break;
509
510                         default:
511                                 rc = LDAP_OTHER;
512                                 break;
513                         }
514
515                         if ( rc != LDAP_SUCCESS ) {
516                                 goto done;
517                         }
518
519                 } else if ( is_at_operational( mod->sm_desc->ad_type )) {
520                 /* accept all operational attributes */
521                         attr_delete( &e->e_attrs, mod->sm_desc );
522                         rc = attr_merge( e, mod->sm_desc, mod->sm_values,
523                                 mod->sm_nvalues );
524                         if ( rc ) {
525                                 rc = LDAP_OTHER;
526                                 break;
527                         }
528
529                 } else {
530                         rc = LDAP_UNWILLING_TO_PERFORM;
531                         break;
532                 }
533         }
534
535         /* sanity checks: */
536         if ( ro_gotval < 1 ) {
537                 rc = LDAP_CONSTRAINT_VIOLATION;
538                 goto done;
539         }
540
541         if ( ( rp_cur & SLAP_RESTRICT_OP_EXTENDED ) && ( rp_cur & SLAP_RESTRICT_EXOP_MASK ) ) {
542                 rc = LDAP_CONSTRAINT_VIOLATION;
543                 goto done;
544         }
545
546         if ( rp_delete & rp_add ) {
547                 rc = LDAP_OTHER;
548                 goto done;
549         }
550
551         /* check current value of readOnly */
552         if ( ( rp_cur & SLAP_RESTRICT_OP_WRITES ) == SLAP_RESTRICT_OP_WRITES ) {
553                 tf = (struct berval *)&slap_true_bv;
554
555         } else {
556                 tf = (struct berval *)&slap_false_bv;
557         }
558
559         a = attr_find( e->e_attrs, mi->mi_ad_readOnly );
560         if ( a == NULL ) {
561                 rc = LDAP_OTHER;
562                 goto done;
563         }
564
565         if ( !bvmatch( &a->a_vals[ 0 ], tf ) ) {
566                 attr_delete( &e->e_attrs, mi->mi_ad_readOnly );
567                 rc = attr_merge_one( e, mi->mi_ad_readOnly, tf, NULL );
568         }
569
570         if ( rc == LDAP_SUCCESS ) {
571                 if ( rp_delete ) {
572                         if ( rp_delete == be->be_restrictops ) {
573                                 attr_delete( &e->e_attrs, mi->mi_ad_restrictedOperation );
574
575                         } else {
576                                 a = attr_find( e->e_attrs, mi->mi_ad_restrictedOperation );
577                                 if ( a == NULL ) {
578                                         rc = LDAP_OTHER;
579                                         goto done;
580                                 }
581
582                                 for ( i = 0; !BER_BVISNULL( &restricted_ops[ i ].op ); i++ ) {
583                                         if ( rp_delete & restricted_ops[ i ].tag ) {
584                                                 int     j;
585                                         
586                                                 for ( j = 0; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ ) {
587                                                         int             k;
588
589                                                         if ( !bvmatch( &a->a_nvals[ j ], &restricted_ops[ i ].op ) ) {
590                                                                 continue;
591                                                         }
592
593                                                         ch_free( a->a_vals[ j ].bv_val );
594                                                         ch_free( a->a_nvals[ j ].bv_val );
595
596                                                         for ( k = j + 1; !BER_BVISNULL( &a->a_nvals[ k ] ); k++ ) {
597                                                                 a->a_vals[ k - 1 ] = a->a_vals[ k ];
598                                                                 a->a_nvals[ k - 1 ] = a->a_nvals[ k ];
599                                                         }
600         
601                                                         BER_BVZERO( &a->a_vals[ k - 1 ] );
602                                                         BER_BVZERO( &a->a_nvals[ k - 1 ] );
603                                                 }
604                                         }
605                                 }
606                                 
607                                 for ( i = 0; !BER_BVISNULL( &restricted_exops[ i ].op ); i++ ) {
608                                         if ( rp_delete & restricted_exops[ i ].tag ) {
609                                                 int     j;
610                                         
611                                                 for ( j = 0; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ ) {
612                                                         int             k;
613
614                                                         if ( !bvmatch( &a->a_nvals[ j ], &restricted_exops[ i ].op ) ) {
615                                                                 continue;
616                                                         }
617
618                                                         ch_free( a->a_vals[ j ].bv_val );
619                                                         ch_free( a->a_nvals[ j ].bv_val );
620
621                                                         for ( k = j + 1; !BER_BVISNULL( &a->a_nvals[ k ] ); k++ ) {
622                                                                 a->a_vals[ k - 1 ] = a->a_vals[ k ];
623                                                                 a->a_nvals[ k - 1 ] = a->a_nvals[ k ];
624                                                         }
625         
626                                                         BER_BVZERO( &a->a_vals[ k - 1 ] );
627                                                         BER_BVZERO( &a->a_nvals[ k - 1 ] );
628                                                 }
629                                         }
630                                 }
631                         }
632                 }
633
634                 if ( rp_add ) {
635                         for ( i = 0; !BER_BVISNULL( &restricted_ops[ i ].op ); i++ ) {
636                                 if ( rp_add & restricted_ops[ i ].tag ) {
637                                         attr_merge_one( e, mi->mi_ad_restrictedOperation,
638                                                         &restricted_ops[ i ].op, NULL );
639                                 }
640                         }
641
642                         for ( i = 0; !BER_BVISNULL( &restricted_exops[ i ].op ); i++ ) {
643                                 if ( rp_add & restricted_exops[ i ].tag ) {
644                                         attr_merge_one( e, mi->mi_ad_restrictedOperation,
645                                                         &restricted_exops[ i ].op, NULL );
646                                 }
647                         }
648                 }
649         }
650
651         be->be_restrictops = rp_cur;
652
653 done:;
654         if ( rc == LDAP_SUCCESS ) {
655                 attrs_free( save_attrs );
656
657         } else {
658                 Attribute *tmp = e->e_attrs;
659                 e->e_attrs = save_attrs;
660                 attrs_free( tmp );
661         }
662         return rc;
663 }
664
665 #if defined(LDAP_SLAPI)
666 static int
667 monitor_back_add_plugin( Backend *be, Entry *e_database )
668 {
669         Slapi_PBlock    *pCurrentPB; 
670         int             i, rc = LDAP_SUCCESS;
671         monitor_info_t  *mi = ( monitor_info_t * )be->be_private;
672
673         if ( slapi_int_pblock_get_first( be, &pCurrentPB ) != LDAP_SUCCESS ) {
674                 /*
675                  * LDAP_OTHER is returned if no plugins are installed
676                  */
677                 rc = LDAP_OTHER;
678                 goto done;
679         }
680
681         i = 0;
682         do {
683                 Slapi_PluginDesc        *srchdesc;
684                 char                    buf[ BACKMONITOR_BUFSIZE ];
685                 struct berval           bv;
686
687                 rc = slapi_pblock_get( pCurrentPB, SLAPI_PLUGIN_DESCRIPTION,
688                                 &srchdesc );
689                 if ( rc != LDAP_SUCCESS ) {
690                         goto done;
691                 }
692
693                 snprintf( buf, sizeof(buf),
694                                 "plugin %d name: %s; "
695                                 "vendor: %s; "
696                                 "version: %s; "
697                                 "description: %s", 
698                                 i,
699                                 srchdesc->spd_id,
700                                 srchdesc->spd_vendor,
701                                 srchdesc->spd_version,
702                                 srchdesc->spd_description );
703
704                 bv.bv_val = buf;
705                 bv.bv_len = strlen( buf );
706                 attr_merge_normalize_one( e_database,
707                                 mi->mi_ad_monitoredInfo, &bv, NULL );
708
709                 i++;
710
711         } while ( ( slapi_int_pblock_get_next( &pCurrentPB ) == LDAP_SUCCESS )
712                         && ( pCurrentPB != NULL ) );
713
714 done:
715         return rc;
716 }
717 #endif /* defined(LDAP_SLAPI) */