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