]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/database.c
rework subsystem initialization (can be added dynamically...)
[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( struct monitorinfo *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( struct monitorinfo *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         monitorsubsys   *ms
101 )
102 {
103         struct monitorinfo      *mi;
104         Entry                   *e_database, **ep;
105         int                     i;
106         struct monitorentrypriv *mp;
107         monitorsubsys           *ms_backend,
108                                 *ms_overlay;
109
110         assert( be != NULL );
111
112         mi = ( struct monitorinfo * )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 = ( struct monitorentrypriv * )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 ( strcmp( be->bd_info->bi_type, "over" ) == 0 ) {
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
222                         for ( ; on; on = on->on_next ) {
223                                 struct berval           bv;
224                                 slap_overinst           *on2;
225                                 
226                                 bv.bv_val = on->on_bi.bi_type;
227                                 bv.bv_len = strlen( bv.bv_val );
228                                 attr_merge_normalize_one( e, mi->mi_ad_monitorOverlay,
229                                                 &bv, NULL );
230
231                                 for ( on2 = overlay_next( NULL ), j = 0; on2; on2 = overlay_next( on2 ), j++ ) {
232                                         if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
233                                                 break;
234                                         }
235                                 }
236                                 assert( on2 );
237
238                                 snprintf( buf, sizeof( buf ), 
239                                         "cn=Overlay %d,%s", 
240                                         j, ms_overlay->mss_dn.bv_val );
241                                 bv.bv_val = buf;
242                                 bv.bv_len = strlen( buf );
243                                 attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
244                                                 &bv, NULL );
245                         }
246                 }
247
248 #if defined(SLAPD_LDAP) 
249                 if ( strcmp( bi->bi_type, "ldap" ) == 0 ) {
250                         struct ldapinfo         *li = (struct ldapinfo *)be->be_private;
251                         struct berval           bv;
252
253                         bv.bv_val = li->url;
254                         bv.bv_len = strlen( bv.bv_val );
255                         attr_merge_normalize_one( e, mi->mi_ad_labeledURI,
256                                         &bv, NULL );
257                 }
258 #endif /* defined(SLAPD_LDAP) */
259
260                 for ( j = 0; j < nBackendInfo; j++ ) {
261                         if ( backendInfo[ j ].bi_type == bi->bi_type ) {
262                                 struct berval           bv;
263
264                                 snprintf( buf, sizeof( buf ), 
265                                         "cn=Backend %d,%s", 
266                                         j, ms_backend->mss_dn.bv_val );
267                                 bv.bv_val = buf;
268                                 bv.bv_len = strlen( buf );
269                                 attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
270                                                 &bv, NULL );
271                                 break;
272                         }
273                 }
274                 /* we must find it! */
275                 assert( j >= 0 );
276
277                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
278                 e->e_private = ( void * )mp;
279                 mp->mp_next = NULL;
280                 mp->mp_children = NULL;
281                 mp->mp_info = ms;
282                 mp->mp_flags = ms->mss_flags
283                         | MONITOR_F_SUB;
284
285                 if ( monitor_cache_add( mi, e ) ) {
286                         Debug( LDAP_DEBUG_ANY,
287                                 "monitor_subsys_database_init: "
288                                 "unable to add entry \"cn=Database %d,%s\"\n",
289                                 i, ms->mss_ndn.bv_val, 0 );
290                         return( -1 );
291                 }
292
293 #if defined(LDAP_SLAPI)
294                 monitor_back_add_plugin( be, e );
295 #endif /* defined(LDAP_SLAPI) */
296
297                 *ep = e;
298                 ep = &mp->mp_next;
299         }
300         
301         monitor_cache_release( mi, e_database );
302
303         return( 0 );
304 }
305
306 /*
307  * v: array of values
308  * cur: must not contain the tags corresponding to the values in v
309  * delta: will contain the tags corresponding to the values in v
310  */
311 static int
312 value_mask( BerVarray v, slap_mask_t cur, slap_mask_t *delta )
313 {
314         for ( ; !BER_BVISNULL( v ); v++ ) {
315                 struct restricted_ops_t         *rops;
316                 int                             i;
317
318                 if ( OID_LEADCHAR( v->bv_val[ 0 ] ) ) {
319                         rops = restricted_exops;
320
321                 } else {
322                         rops = restricted_ops;
323                 }
324
325                 for ( i = 0; !BER_BVISNULL( &rops[ i ].op ); i++ ) {
326                         if ( ber_bvstrcasecmp( v, &rops[ i ].op ) != 0 ) {
327                                 continue;
328                         }
329
330                         if ( rops[ i ].tag & *delta ) {
331                                 return LDAP_OTHER;
332                         }
333
334                         if ( rops[ i ].tag & cur ) {
335                                 return LDAP_OTHER;
336                         }
337
338                         cur |= rops[ i ].tag;
339                         *delta |= rops[ i ].tag;
340
341                         break;
342                 }
343
344                 if ( BER_BVISNULL( &rops[ i ].op ) ) {
345                         return LDAP_INVALID_SYNTAX;
346                 }
347         }
348
349         return LDAP_SUCCESS;
350 }
351
352 int
353 monitor_subsys_database_modify(
354         Operation       *op,
355         Entry           *e
356 )
357 {
358         struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
359         int rc = LDAP_OTHER;
360         Attribute *save_attrs, *a;
361         Modifications *modlist = op->oq_modify.rs_modlist;
362         Modifications *ml;
363         Backend *be;
364         int ro_gotval = 1, i, n;
365         slap_mask_t     rp_add = 0, rp_delete = 0, rp_cur;
366         struct berval *tf;
367         
368         i = sscanf( e->e_nname.bv_val, "cn=database %d,", &n );
369         if ( i != 1 )
370                 return LDAP_UNWILLING_TO_PERFORM;
371
372         if ( n < 0 || n >= nBackendDB )
373                 return LDAP_NO_SUCH_OBJECT;
374
375         /* do not allow some changes on back-monitor (needs work)... */
376         be = &backendDB[n];
377         if ( SLAP_MONITOR( be ) )
378                 return LDAP_UNWILLING_TO_PERFORM;
379                 
380         rp_cur = be->be_restrictops;
381
382         save_attrs = e->e_attrs;
383         e->e_attrs = attrs_dup( e->e_attrs );
384
385         for ( ml=modlist; ml; ml=ml->sml_next ) {
386                 Modification *mod = &ml->sml_mod;
387
388                 if ( mod->sm_desc == mi->mi_ad_readOnly ) {
389                         int     val = -1;
390
391                         if ( mod->sm_values ) {
392                                 if ( !BER_BVISNULL( &mod->sm_values[ 1 ] ) ) {
393                                         rc = LDAP_CONSTRAINT_VIOLATION;
394                                         goto done;
395                                 }
396
397                                 if ( bvmatch( &slap_true_bv, mod->sm_values )) {
398                                         val = 1;
399
400                                 } else if ( bvmatch( &slap_false_bv, mod->sm_values )) {
401                                         val = 0;
402
403                                 } else {
404                                         rc = LDAP_INVALID_SYNTAX;
405                                         goto done;
406                                 }
407                         }
408
409                         switch ( mod->sm_op ) {
410                         case LDAP_MOD_DELETE:
411                                 if ( ro_gotval < 1 ) {
412                                         rc = LDAP_CONSTRAINT_VIOLATION;
413                                         goto done;
414                                 }
415                                 ro_gotval--;
416
417                                 if ( val == 0 && ( rp_cur & SLAP_RESTRICT_OP_WRITES ) == SLAP_RESTRICT_OP_WRITES ) {
418                                         rc = LDAP_NO_SUCH_ATTRIBUTE;
419                                         goto done;
420                                 }
421                                 
422                                 if ( val == 1 && ( rp_cur & SLAP_RESTRICT_OP_WRITES ) != SLAP_RESTRICT_OP_WRITES ) {
423                                         rc = LDAP_NO_SUCH_ATTRIBUTE;
424                                         goto done;
425                                 }
426                                 
427                                 break;
428
429                         case LDAP_MOD_REPLACE:
430                                 ro_gotval = 0;
431                                 /* fall thru */
432
433                         case LDAP_MOD_ADD:
434                                 if ( ro_gotval > 0 ) {
435                                         rc = LDAP_CONSTRAINT_VIOLATION;
436                                         goto done;
437                                 }
438                                 ro_gotval++;
439
440                                 if ( val == 1 ) {
441                                         rp_add |= (~rp_cur) & SLAP_RESTRICT_OP_WRITES;
442                                         rp_cur |= SLAP_RESTRICT_OP_WRITES;
443                                         rp_delete &= ~SLAP_RESTRICT_OP_WRITES;
444                                         
445                                 } else if ( val == 0 ) {
446                                         rp_delete |= rp_cur & SLAP_RESTRICT_OP_WRITES;
447                                         rp_cur &= ~SLAP_RESTRICT_OP_WRITES;
448                                         rp_add &= ~SLAP_RESTRICT_OP_WRITES;
449                                 }
450                                 break;
451
452                         default:
453                                 rc = LDAP_OTHER;
454                                 goto done;
455                         }
456
457                 } else if ( mod->sm_desc == mi->mi_ad_restrictedOperation ) {
458                         slap_mask_t     mask = 0;
459
460                         switch ( mod->sm_op ) {
461                         case LDAP_MOD_DELETE:
462                                 if ( mod->sm_values == NULL ) {
463                                         rp_delete = rp_cur;
464                                         rp_cur = 0;
465                                         rp_add = 0;
466                                         break;
467                                 }
468                                 rc = value_mask( mod->sm_values, ~rp_cur, &mask );
469                                 if ( rc == LDAP_SUCCESS ) {
470                                         rp_delete |= mask;
471                                         rp_add &= ~mask;
472                                         rp_cur &= ~mask;
473
474                                 } else if ( rc == LDAP_OTHER ) {
475                                         rc = LDAP_NO_SUCH_ATTRIBUTE;
476                                 }
477                                 break;
478
479                         case LDAP_MOD_REPLACE:
480                                 rp_delete = rp_cur;
481                                 rp_cur = 0;
482                                 rp_add = 0;
483                                 /* fall thru */
484
485                         case LDAP_MOD_ADD:
486                                 rc = value_mask( mod->sm_values, rp_cur, &mask );
487                                 if ( rc == LDAP_SUCCESS ) {
488                                         rp_add |= mask;
489                                         rp_cur |= mask;
490                                         rp_delete &= ~mask;
491
492                                 } else if ( rc == LDAP_OTHER ) {
493                                         rc = LDAP_TYPE_OR_VALUE_EXISTS;
494                                 }
495                                 break;
496
497                         default:
498                                 rc = LDAP_OTHER;
499                                 break;
500                         }
501
502                         if ( rc != LDAP_SUCCESS ) {
503                                 goto done;
504                         }
505
506                 } else if ( is_at_operational( mod->sm_desc->ad_type )) {
507                 /* accept all operational attributes */
508                         attr_delete( &e->e_attrs, mod->sm_desc );
509                         rc = attr_merge( e, mod->sm_desc, mod->sm_values,
510                                 mod->sm_nvalues );
511                         if ( rc ) {
512                                 rc = LDAP_OTHER;
513                                 break;
514                         }
515
516                 } else {
517                         rc = LDAP_UNWILLING_TO_PERFORM;
518                         break;
519                 }
520         }
521
522         /* sanity checks: */
523         if ( ro_gotval < 1 ) {
524                 rc = LDAP_CONSTRAINT_VIOLATION;
525                 goto done;
526         }
527
528         if ( ( rp_cur & SLAP_RESTRICT_OP_EXTENDED ) && ( rp_cur & SLAP_RESTRICT_EXOP_MASK ) ) {
529                 rc = LDAP_CONSTRAINT_VIOLATION;
530                 goto done;
531         }
532
533         if ( rp_delete & rp_add ) {
534                 rc = LDAP_OTHER;
535                 goto done;
536         }
537
538         /* check current value of readOnly */
539         if ( ( rp_cur & SLAP_RESTRICT_OP_WRITES ) == SLAP_RESTRICT_OP_WRITES ) {
540                 tf = (struct berval *)&slap_true_bv;
541
542         } else {
543                 tf = (struct berval *)&slap_false_bv;
544         }
545
546         a = attr_find( e->e_attrs, mi->mi_ad_readOnly );
547         if ( a == NULL ) {
548                 rc = LDAP_OTHER;
549                 goto done;
550         }
551
552         if ( !bvmatch( &a->a_vals[0], tf ) ) {
553                 attr_delete( &e->e_attrs, mi->mi_ad_readOnly );
554                 rc = attr_merge_one( e, mi->mi_ad_readOnly, tf, NULL );
555         }
556
557         if ( rc == LDAP_SUCCESS ) {
558                 if ( rp_delete ) {
559                         if ( rp_delete == be->be_restrictops ) {
560                                 attr_delete( &e->e_attrs, mi->mi_ad_restrictedOperation );
561
562                         } else {
563                                 a = attr_find( e->e_attrs, mi->mi_ad_restrictedOperation );
564                                 if ( a == NULL ) {
565                                         rc = LDAP_OTHER;
566                                         goto done;
567                                 }
568
569                                 for ( i = 0; !BER_BVISNULL( &restricted_ops[ i ].op ); i++ ) {
570                                         if ( rp_delete & restricted_ops[ i ].tag ) {
571                                                 int     j;
572                                         
573                                                 for ( j = 0; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ ) {
574                                                         int             k;
575
576                                                         if ( !bvmatch( &a->a_nvals[ j ], &restricted_ops[ i ].op ) ) {
577                                                                 continue;
578                                                         }
579
580                                                         ch_free( a->a_vals[ j ].bv_val );
581                                                         ch_free( a->a_nvals[ j ].bv_val );
582
583                                                         for ( k = j + 1; !BER_BVISNULL( &a->a_nvals[ k ] ); k++ ) {
584                                                                 a->a_vals[ k - 1 ] = a->a_vals[ k ];
585                                                                 a->a_nvals[ k - 1 ] = a->a_nvals[ k ];
586                                                         }
587         
588                                                         BER_BVZERO( &a->a_vals[ k - 1 ] );
589                                                         BER_BVZERO( &a->a_nvals[ k - 1 ] );
590                                                 }
591                                         }
592                                 }
593                                 
594                                 for ( i = 0; !BER_BVISNULL( &restricted_exops[ i ].op ); i++ ) {
595                                         if ( rp_delete & restricted_exops[ i ].tag ) {
596                                                 int     j;
597                                         
598                                                 for ( j = 0; !BER_BVISNULL( &a->a_nvals[ j ] ); j++ ) {
599                                                         int             k;
600
601                                                         if ( !bvmatch( &a->a_nvals[ j ], &restricted_exops[ i ].op ) ) {
602                                                                 continue;
603                                                         }
604
605                                                         ch_free( a->a_vals[ j ].bv_val );
606                                                         ch_free( a->a_nvals[ j ].bv_val );
607
608                                                         for ( k = j + 1; !BER_BVISNULL( &a->a_nvals[ k ] ); k++ ) {
609                                                                 a->a_vals[ k - 1 ] = a->a_vals[ k ];
610                                                                 a->a_nvals[ k - 1 ] = a->a_nvals[ k ];
611                                                         }
612         
613                                                         BER_BVZERO( &a->a_vals[ k - 1 ] );
614                                                         BER_BVZERO( &a->a_nvals[ k - 1 ] );
615                                                 }
616                                         }
617                                 }
618                         }
619                 }
620
621                 if ( rp_add ) {
622                         for ( i = 0; !BER_BVISNULL( &restricted_ops[ i ].op ); i++ ) {
623                                 if ( rp_add & restricted_ops[ i ].tag ) {
624                                         attr_merge_one( e, mi->mi_ad_restrictedOperation,
625                                                         &restricted_ops[ i ].op, NULL );
626                                 }
627                         }
628
629                         for ( i = 0; !BER_BVISNULL( &restricted_exops[ i ].op ); i++ ) {
630                                 if ( rp_add & restricted_exops[ i ].tag ) {
631                                         attr_merge_one( e, mi->mi_ad_restrictedOperation,
632                                                         &restricted_exops[ i ].op, NULL );
633                                 }
634                         }
635                 }
636         }
637
638         be->be_restrictops = rp_cur;
639
640 done:;
641         if ( rc == LDAP_SUCCESS ) {
642                 attrs_free( save_attrs );
643
644         } else {
645                 Attribute *tmp = e->e_attrs;
646                 e->e_attrs = save_attrs;
647                 attrs_free( tmp );
648         }
649         return rc;
650 }
651
652 #if defined(LDAP_SLAPI)
653 static int
654 monitor_back_add_plugin( Backend *be, Entry *e_database )
655 {
656         Slapi_PBlock            *pCurrentPB; 
657         int                     i, rc = LDAP_SUCCESS;
658         struct monitorinfo      *mi = ( struct monitorinfo * )be->be_private;
659
660         if ( slapi_int_pblock_get_first( be, &pCurrentPB ) != LDAP_SUCCESS ) {
661                 /*
662                  * LDAP_OTHER is returned if no plugins are installed
663                  */
664                 rc = LDAP_OTHER;
665                 goto done;
666         }
667
668         i = 0;
669         do {
670                 Slapi_PluginDesc        *srchdesc;
671                 char                    buf[ BACKMONITOR_BUFSIZE ];
672                 struct berval           bv;
673
674                 rc = slapi_pblock_get( pCurrentPB, SLAPI_PLUGIN_DESCRIPTION,
675                                 &srchdesc );
676                 if ( rc != LDAP_SUCCESS ) {
677                         goto done;
678                 }
679
680                 snprintf( buf, sizeof(buf),
681                                 "plugin %d name: %s; "
682                                 "vendor: %s; "
683                                 "version: %s; "
684                                 "description: %s", 
685                                 i,
686                                 srchdesc->spd_id,
687                                 srchdesc->spd_vendor,
688                                 srchdesc->spd_version,
689                                 srchdesc->spd_description );
690
691                 bv.bv_val = buf;
692                 bv.bv_len = strlen( buf );
693                 attr_merge_normalize_one( e_database,
694                                 mi->mi_ad_monitoredInfo, &bv, NULL );
695
696                 i++;
697
698         } while ( ( slapi_int_pblock_get_next( &pCurrentPB ) == LDAP_SUCCESS )
699                         && ( pCurrentPB != NULL ) );
700
701 done:
702         return rc;
703 }
704 #endif /* defined(LDAP_SLAPI) */