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