]> git.sur5r.net Git - openldap/blob - servers/slapd/backend.c
ad58b26b633f2a8376cbbc24e5bc7d57333b2160
[openldap] / servers / slapd / backend.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /* backend.c - routines for dealing with back-end databases */
7
8
9 #include "portable.h"
10
11 #include <stdio.h>
12
13 #include <ac/string.h>
14 #include <ac/socket.h>
15 #include <sys/stat.h>
16
17 #include "slap.h"
18 #include "lutil.h"
19 #include "lber_pvt.h"
20
21 #include "ldap_rq.h"
22
23 #ifdef LDAP_SLAPI
24 #include "slapi.h"
25 #endif
26
27 /*
28  * If a module is configured as dynamic, its header should not
29  * get included into slapd. While this is a general rule and does
30  * not have much of an effect in UNIX, this rule should be adhered
31  * to for Windows, where dynamic object code should not be implicitly
32  * imported into slapd without appropriate __declspec(dllimport) directives.
33  */
34
35 #if defined(SLAPD_BDB) && !defined(SLAPD_BDB_DYNAMIC)
36 #include "back-bdb/external.h"
37 #endif
38 #if defined(SLAPD_DNSSRV) && !defined(SLAPD_DNSSRV_DYNAMIC)
39 #include "back-dnssrv/external.h"
40 #endif
41 #if defined(SLAPD_HDB) && !defined(SLAPD_HDB_DYNAMIC)
42 #include "back-hdb/external.h"
43 #endif
44 #if defined(SLAPD_LDAP) && !defined(SLAPD_LDAP_DYNAMIC)
45 #include "back-ldap/external.h"
46 #endif
47 #if defined(SLAPD_LDBM) && !defined(SLAPD_LDBM_DYNAMIC)
48 #include "back-ldbm/external.h"
49 #endif
50 #if defined(SLAPD_META) && !defined(SLAPD_META_DYNAMIC)
51 #include "back-meta/external.h"
52 #endif
53 #if defined(SLAPD_MONITOR) && !defined(SLAPD_MONITOR_DYNAMIC)
54 #include "back-monitor/external.h"
55 #endif
56 #if defined(SLAPD_NULL) && !defined(SLAPD_NULL_DYNAMIC)
57 #include "back-null/external.h"
58 #endif
59 #if defined(SLAPD_PASSWD) && !defined(SLAPD_PASSWD_DYNAMIC)
60 #include "back-passwd/external.h"
61 #endif
62 #if defined(SLAPD_PERL) && !defined(SLAPD_PERL_DYNAMIC)
63 #include "back-perl/external.h"
64 #endif
65 #if defined(SLAPD_SHELL) && !defined(SLAPD_SHELL_DYNAMIC)
66 #include "back-shell/external.h"
67 #endif
68 #if defined(SLAPD_TCL) && !defined(SLAPD_TCL_DYNAMIC)
69 #include "back-tcl/external.h"
70 #endif
71 #if defined(SLAPD_SQL) && !defined(SLAPD_SQL_DYNAMIC)
72 #include "back-sql/external.h"
73 #endif
74 #if defined(SLAPD_PRIVATE) && !defined(SLAPD_PRIVATE_DYNAMIC)
75 #include "private/external.h"
76 #endif
77
78 static BackendInfo binfo[] = {
79 #if defined(SLAPD_BDB) && !defined(SLAPD_BDB_DYNAMIC)
80         {"bdb", bdb_initialize},
81 #endif
82 #if defined(SLAPD_DNSSRV) && !defined(SLAPD_DNSSRV_DYNAMIC)
83         {"dnssrv",      dnssrv_back_initialize},
84 #endif
85 #if defined(SLAPD_HDB) && !defined(SLAPD_HDB_DYNAMIC)
86         {"hdb", hdb_initialize},
87 #endif
88 #if defined(SLAPD_LDAP) && !defined(SLAPD_LDAP_DYNAMIC)
89         {"ldap",        ldap_back_initialize},
90 #endif
91 #if defined(SLAPD_LDBM) && !defined(SLAPD_LDBM_DYNAMIC)
92         {"ldbm",        ldbm_back_initialize},
93 #endif
94 #if defined(SLAPD_META) && !defined(SLAPD_META_DYNAMIC)
95         {"meta",        meta_back_initialize},
96 #endif
97 #if defined(SLAPD_MONITOR) && !defined(SLAPD_MONITOR_DYNAMIC)
98         {"monitor",     monitor_back_initialize},
99 #endif
100 #if defined(SLAPD_NULL) && !defined(SLAPD_NULL_DYNAMIC)
101         {"null",        null_back_initialize},
102 #endif
103 #if defined(SLAPD_PASSWD) && !defined(SLAPD_PASSWD_DYNAMIC)
104         {"passwd",      passwd_back_initialize},
105 #endif
106 #if defined(SLAPD_PERL) && !defined(SLAPD_PERL_DYNAMIC)
107         {"perl",        perl_back_initialize},
108 #endif
109 #if defined(SLAPD_SHELL) && !defined(SLAPD_SHELL_DYNAMIC)
110         {"shell",       shell_back_initialize},
111 #endif
112 #if defined(SLAPD_TCL) && !defined(SLAPD_TCL_DYNAMIC)
113         {"tcl",         tcl_back_initialize},
114 #endif
115 #if defined(SLAPD_SQL) && !defined(SLAPD_SQL_DYNAMIC)
116         {"sql",         sql_back_initialize},
117 #endif
118         /* for any private backend */
119 #if defined(SLAPD_PRIVATE) && !defined(SLAPD_PRIVATE_DYNAMIC)
120         {"private",     private_back_initialize},
121 #endif
122         {NULL}
123 };
124
125 int                     nBackendInfo = 0;
126 BackendInfo     *backendInfo = NULL;
127
128 int                     nBackendDB = 0; 
129 BackendDB       *backendDB = NULL;
130
131 ldap_pvt_thread_pool_t  syncrepl_pool;
132 int                     syncrepl_pool_max = SLAP_MAX_SYNCREPL_THREADS;
133
134 int backend_init(void)
135 {
136         int rc = -1;
137
138         ldap_pvt_thread_pool_init( &syncrepl_pool, syncrepl_pool_max, 0 );
139
140         if((nBackendInfo != 0) || (backendInfo != NULL)) {
141                 /* already initialized */
142 #ifdef NEW_LOGGING
143                 LDAP_LOG( BACKEND, ERR, 
144                         "backend_init:  backend already initialized\n", 0, 0, 0 );
145 #else
146                 Debug( LDAP_DEBUG_ANY,
147                         "backend_init: already initialized.\n", 0, 0, 0 );
148 #endif
149                 return -1;
150         }
151
152         for( ;
153                 binfo[nBackendInfo].bi_type != NULL;
154                 nBackendInfo++ )
155         {
156                 rc = binfo[nBackendInfo].bi_init( &binfo[nBackendInfo] );
157
158                 if(rc != 0) {
159 #ifdef NEW_LOGGING
160                         LDAP_LOG( BACKEND, INFO, 
161                                 "backend_init:  initialized for type \"%s\"\n",
162                                 binfo[nBackendInfo].bi_type, 0, 0 );
163 #else
164                         Debug( LDAP_DEBUG_ANY,
165                                 "backend_init: initialized for type \"%s\"\n",
166                                 binfo[nBackendInfo].bi_type, 0, 0 );
167 #endif
168                         /* destroy those we've already inited */
169                         for( nBackendInfo--;
170                                 nBackendInfo >= 0 ;
171                                 nBackendInfo-- )
172                         { 
173                                 if ( binfo[nBackendInfo].bi_destroy ) {
174                                         binfo[nBackendInfo].bi_destroy(
175                                                 &binfo[nBackendInfo] );
176                                 }
177                         }
178                         return rc;
179                 }
180         }
181
182         if ( nBackendInfo > 0) {
183                 backendInfo = binfo;
184                 return 0;
185         }
186
187 #ifdef SLAPD_MODULES    
188         return 0;
189 #else
190
191 #ifdef NEW_LOGGING
192         LDAP_LOG( BACKEND, ERR, "backend_init: failed\n", 0, 0, 0 );
193 #else
194         Debug( LDAP_DEBUG_ANY,
195                 "backend_init: failed\n",
196                 0, 0, 0 );
197 #endif
198
199         return rc;
200 #endif /* SLAPD_MODULES */
201 }
202
203 int backend_add(BackendInfo *aBackendInfo)
204 {
205    int rc = 0;
206
207    if ((rc = aBackendInfo->bi_init(aBackendInfo)) != 0) {
208 #ifdef NEW_LOGGING
209         LDAP_LOG( BACKEND, ERR, 
210                   "backend_add:  initialization for type \"%s\" failed\n",
211                   aBackendInfo->bi_type, 0, 0 );
212 #else
213       Debug( LDAP_DEBUG_ANY,
214              "backend_add: initialization for type \"%s\" failed\n",
215              aBackendInfo->bi_type, 0, 0 );
216 #endif
217       return rc;
218    }
219
220    /* now add the backend type to the Backend Info List */
221    {
222       BackendInfo *newBackendInfo = 0;
223
224       /* if backendInfo == binfo no deallocation of old backendInfo */
225       if (backendInfo == binfo) {
226          newBackendInfo = ch_calloc(nBackendInfo + 1, sizeof(BackendInfo));
227          AC_MEMCPY(newBackendInfo, backendInfo, sizeof(BackendInfo) * 
228                 nBackendInfo);
229       } else {
230          newBackendInfo = ch_realloc(backendInfo, sizeof(BackendInfo) * 
231                                      (nBackendInfo + 1));
232       }
233       AC_MEMCPY(&newBackendInfo[nBackendInfo], aBackendInfo, 
234              sizeof(BackendInfo));
235       backendInfo = newBackendInfo;
236       nBackendInfo++;
237
238       return 0;
239    }        
240 }
241
242 int backend_startup(Backend *be)
243 {
244         int i;
245         int rc = 0;
246
247         if( ! ( nBackendDB > 0 ) ) {
248                 /* no databases */
249 #ifdef NEW_LOGGING
250                 LDAP_LOG( BACKEND, INFO, 
251                         "backend_startup: %d databases to startup. \n", nBackendDB, 0, 0 );
252 #else
253                 Debug( LDAP_DEBUG_ANY,
254                         "backend_startup: %d databases to startup.\n",
255                         nBackendDB, 0, 0 );
256 #endif
257                 return 1;
258         }
259
260         if(be != NULL) {
261                 /* startup a specific backend database */
262
263                 LDAP_TAILQ_INIT( &be->be_pending_csn_list );
264
265 #ifdef NEW_LOGGING
266                 LDAP_LOG( BACKEND, DETAIL1, "backend_startup:  starting \"%s\"\n",
267                            be->be_suffix[0].bv_val, 0, 0 );
268 #else
269                 Debug( LDAP_DEBUG_TRACE,
270                         "backend_startup: starting \"%s\"\n",
271                         be->be_suffix[0].bv_val, 0, 0 );
272 #endif
273
274                 if ( be->bd_info->bi_open ) {
275                         rc = be->bd_info->bi_open( be->bd_info );
276                         if ( rc != 0 ) {
277 #ifdef NEW_LOGGING
278                                 LDAP_LOG( BACKEND, CRIT, "backend_startup: bi_open failed!\n", 0, 0, 0 );
279 #else
280                                 Debug( LDAP_DEBUG_ANY,
281                                         "backend_startup: bi_open failed!\n",
282                                         0, 0, 0 );
283 #endif
284
285                                 return rc;
286                         }
287                 }
288
289                 if ( be->bd_info->bi_db_open ) {
290                         rc = be->bd_info->bi_db_open( be );
291                         if ( rc != 0 ) {
292 #ifdef NEW_LOGGING
293                                 LDAP_LOG( BACKEND, CRIT, 
294                                         "backend_startup: bi_db_open failed! (%d)\n", rc, 0, 0 );
295 #else
296                                 Debug( LDAP_DEBUG_ANY,
297                                         "backend_startup: bi_db_open failed! (%d)\n",
298                                         rc, 0, 0 );
299 #endif
300                                 return rc;
301                         }
302                 }
303
304                 return rc;
305         }
306
307         /* open each backend type */
308         for( i = 0; i < nBackendInfo; i++ ) {
309                 if( backendInfo[i].bi_nDB == 0) {
310                         /* no database of this type, don't open */
311                         continue;
312                 }
313
314                 if( backendInfo[i].bi_open ) {
315                         rc = backendInfo[i].bi_open(
316                                 &backendInfo[i] );
317                         if ( rc != 0 ) {
318 #ifdef NEW_LOGGING
319                                 LDAP_LOG( BACKEND, CRIT, 
320                                         "backend_startup: bi_open %d failed!\n", i, 0, 0 );
321 #else
322                                 Debug( LDAP_DEBUG_ANY,
323                                         "backend_startup: bi_open %d failed!\n",
324                                         i, 0, 0 );
325 #endif
326                                 return rc;
327                         }
328                 }
329         }
330
331         ldap_pvt_thread_mutex_init( &syncrepl_rq.rq_mutex );
332         LDAP_STAILQ_INIT( &syncrepl_rq.task_list );
333         LDAP_STAILQ_INIT( &syncrepl_rq.run_list );
334
335         /* open each backend database */
336         for( i = 0; i < nBackendDB; i++ ) {
337 #ifndef SLAPD_MULTIMASTER
338                 if ( backendDB[i].be_update_ndn.bv_val && (
339                         !backendDB[i].be_update_refs &&
340                         !backendDB[i].be_syncinfo &&
341                         !default_referral ) )
342                 {
343 #ifdef NEW_LOGGING
344                         LDAP_LOG( BACKEND, CRIT, 
345                                 "backend_startup: slave \"%s\" updateref missing\n",
346                                 backendDB[i].be_suffix[0].bv_val, 0, 0 );
347                                 
348 #else
349                         Debug( LDAP_DEBUG_ANY,
350                                 "backend_startup: slave \"%s\" updateref missing\n",
351                                 backendDB[i].be_suffix[0].bv_val, 0, 0 );
352 #endif
353                         return -1;
354                 }
355 #endif
356
357                 /* append global access controls */
358                 acl_append( &backendDB[i].be_acl, global_acl );
359
360                 LDAP_TAILQ_INIT( &backendDB[i].be_pending_csn_list );
361
362                 if ( backendDB[i].bd_info->bi_db_open ) {
363                         rc = backendDB[i].bd_info->bi_db_open(
364                                 &backendDB[i] );
365                         if ( rc != 0 ) {
366 #ifdef NEW_LOGGING
367                                 LDAP_LOG( BACKEND, CRIT, 
368                                         "backend_startup: bi_db_open(%d) failed! (%d)\n", i, rc, 0 );
369 #else
370                                 Debug( LDAP_DEBUG_ANY,
371                                         "backend_startup: bi_db_open(%d) failed! (%d)\n",
372                                         i, rc, 0 );
373 #endif
374                                 return rc;
375                         }
376                 }
377
378                 if ( backendDB[i].be_syncinfo != NULL ) {
379                         syncinfo_t *si = ( syncinfo_t * ) backendDB[i].be_syncinfo;
380                         si->si_be = &backendDB[i];
381                         init_syncrepl(si);
382                         ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
383                         ldap_pvt_runqueue_insert( &syncrepl_rq, si->si_interval,
384                                 do_syncrepl, (void *) backendDB[i].be_syncinfo );
385                         ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
386                 }
387         }
388
389         return rc;
390 }
391
392 int backend_num( Backend *be )
393 {
394         int i;
395
396         if( be == NULL ) return -1;
397
398         for( i = 0; i < nBackendDB; i++ ) {
399                 if( be == &backendDB[i] ) return i;
400         }
401         return -1;
402 }
403
404 int backend_shutdown( Backend *be )
405 {
406         int i;
407         int rc = 0;
408
409         if( be != NULL ) {
410                 /* shutdown a specific backend database */
411
412                 if ( be->bd_info->bi_nDB == 0 ) {
413                         /* no database of this type, we never opened it */
414                         return 0;
415                 }
416
417                 if ( be->bd_info->bi_db_close ) {
418                         be->bd_info->bi_db_close( be );
419                 }
420
421                 if( be->bd_info->bi_close ) {
422                         be->bd_info->bi_close( be->bd_info );
423                 }
424
425                 return 0;
426         }
427
428         /* close each backend database */
429         for( i = 0; i < nBackendDB; i++ ) {
430                 if ( backendDB[i].bd_info->bi_db_close ) {
431                         backendDB[i].bd_info->bi_db_close(
432                                 &backendDB[i] );
433                 }
434
435                 if(rc != 0) {
436 #ifdef NEW_LOGGING
437                         LDAP_LOG( BACKEND, NOTICE, 
438                                 "backend_shutdown: bi_close %s failed!\n",
439                                 backendDB[i].be_type, 0, 0 );
440 #else
441                         Debug( LDAP_DEBUG_ANY,
442                                 "backend_close: bi_close %s failed!\n",
443                                 backendDB[i].be_type, 0, 0 );
444 #endif
445                 }
446         }
447
448         /* close each backend type */
449         for( i = 0; i < nBackendInfo; i++ ) {
450                 if( backendInfo[i].bi_nDB == 0 ) {
451                         /* no database of this type */
452                         continue;
453                 }
454
455                 if( backendInfo[i].bi_close ) {
456                         backendInfo[i].bi_close(
457                                 &backendInfo[i] );
458                 }
459         }
460
461         return 0;
462 }
463
464 int backend_destroy(void)
465 {
466         int i;
467         BackendDB *bd;
468
469         ldap_pvt_thread_pool_destroy( &syncrepl_pool, 1 );
470
471         /* destroy each backend database */
472         for( i = 0, bd = backendDB; i < nBackendDB; i++, bd++ ) {
473                 if ( bd->bd_info->bi_db_destroy ) {
474                         bd->bd_info->bi_db_destroy( bd );
475                 }
476                 ber_bvarray_free( bd->be_suffix );
477                 ber_bvarray_free( bd->be_nsuffix );
478                 if ( bd->be_rootdn.bv_val ) free( bd->be_rootdn.bv_val );
479                 if ( bd->be_rootndn.bv_val ) free( bd->be_rootndn.bv_val );
480                 if ( bd->be_rootpw.bv_val ) free( bd->be_rootpw.bv_val );
481                 acl_destroy( bd->be_acl, global_acl );
482         }
483         free( backendDB );
484
485         /* destroy each backend type */
486         for( i = 0; i < nBackendInfo; i++ ) {
487                 if( backendInfo[i].bi_destroy ) {
488                         backendInfo[i].bi_destroy(
489                                 &backendInfo[i] );
490                 }
491         }
492
493 #ifdef SLAPD_MODULES
494         if (backendInfo != binfo) {
495            free(backendInfo);
496         }
497 #endif /* SLAPD_MODULES */
498
499         nBackendInfo = 0;
500         backendInfo = NULL;
501
502         return 0;
503 }
504
505 BackendInfo* backend_info(const char *type)
506 {
507         int i;
508
509         /* search for the backend type */
510         for( i = 0; i < nBackendInfo; i++ ) {
511                 if( strcasecmp(backendInfo[i].bi_type, type) == 0 ) {
512                         return &backendInfo[i];
513                 }
514         }
515
516         return NULL;
517 }
518
519
520 BackendDB *
521 backend_db_init(
522     const char  *type
523 )
524 {
525         Backend *be;
526         BackendInfo *bi = backend_info(type);
527         int     rc = 0;
528
529         if( bi == NULL ) {
530                 fprintf( stderr, "Unrecognized database type (%s)\n", type );
531                 return NULL;
532         }
533
534         backendDB = (BackendDB *) ch_realloc(
535                         (char *) backendDB,
536                     (nBackendDB + 1) * sizeof(Backend) );
537
538         memset( &backendDB[nbackends], '\0', sizeof(Backend) );
539
540         be = &backends[nbackends++];
541
542         be->bd_info = bi;
543         be->be_def_limit = deflimit;
544         be->be_dfltaccess = global_default_access;
545
546         be->be_restrictops = global_restrictops;
547         be->be_requires = global_requires;
548         be->be_ssf_set = global_ssf_set;
549
550         be->be_context_csn.bv_len = 0;
551         be->be_context_csn.bv_val = NULL;
552         ldap_pvt_thread_mutex_init( &be->be_pcl_mutex );
553         ldap_pvt_thread_mutex_init( &be->be_context_csn_mutex );
554
555         be->be_syncinfo = NULL;
556
557         /* assign a default depth limit for alias deref */
558         be->be_max_deref_depth = SLAPD_DEFAULT_MAXDEREFDEPTH; 
559
560         if(bi->bi_db_init) {
561                 rc = bi->bi_db_init( be );
562         }
563
564         if(rc != 0) {
565                 fprintf( stderr, "database init failed (%s)\n", type );
566                 nbackends--;
567                 return NULL;
568         }
569
570         bi->bi_nDB++;
571         return( be );
572 }
573
574 void
575 be_db_close( void )
576 {
577         int     i;
578
579         for ( i = 0; i < nbackends; i++ ) {
580                 if ( backends[i].bd_info->bi_db_close ) {
581                         (*backends[i].bd_info->bi_db_close)( &backends[i] );
582                 }
583         }
584 }
585
586 Backend *
587 select_backend(
588         struct berval * dn,
589         int manageDSAit,
590         int noSubs )
591 {
592         int     i, j;
593         ber_len_t len, dnlen = dn->bv_len;
594         Backend *be = NULL;
595
596         for ( i = 0; i < nbackends; i++ ) {
597                 for ( j = 0; backends[i].be_nsuffix != NULL &&
598                     backends[i].be_nsuffix[j].bv_val != NULL; j++ )
599                 {
600                         if ( ( SLAP_GLUE_SUBORDINATE( &backends[i] ) )
601                                 && noSubs )
602                         {
603                                 continue;
604                         }
605
606                         len = backends[i].be_nsuffix[j].bv_len;
607
608                         if ( len > dnlen ) {
609                                 /* suffix is longer than DN */
610                                 continue;
611                         }
612                         
613                         /*
614                          * input DN is normalized, so the separator check
615                          * need not look at escaping
616                          */
617                         if ( len && len < dnlen &&
618                                 !DN_SEPARATOR( dn->bv_val[(dnlen-len)-1] ))
619                         {
620                                 continue;
621                         }
622
623                         if ( strcmp( backends[i].be_nsuffix[j].bv_val,
624                                 &dn->bv_val[dnlen-len] ) == 0 )
625                         {
626                                 if( be == NULL ) {
627                                         be = &backends[i];
628
629                                         if( manageDSAit && len == dnlen &&
630                                                 !SLAP_GLUE_SUBORDINATE( be ) ) {
631                                                 continue;
632                                         }
633                                 } else {
634                                         be = &backends[i];
635                                 }
636                                 return be;
637                         }
638                 }
639         }
640
641         return be;
642 }
643
644 int
645 be_issuffix(
646     Backend     *be,
647     struct berval       *bvsuffix
648 )
649 {
650         int     i;
651
652         for ( i = 0; be->be_nsuffix != NULL && be->be_nsuffix[i].bv_val != NULL; i++ ) {
653                 if ( bvmatch( &be->be_nsuffix[i], bvsuffix ) ) {
654                         return( 1 );
655                 }
656         }
657
658         return( 0 );
659 }
660
661 int
662 be_isroot( Backend *be, struct berval *ndn )
663 {
664         if ( !ndn->bv_len ) {
665                 return( 0 );
666         }
667
668         if ( !be->be_rootndn.bv_len ) {
669                 return( 0 );
670         }
671
672         return dn_match( &be->be_rootndn, ndn );
673 }
674
675 int
676 be_isupdate( Backend *be, struct berval *ndn )
677 {
678         if ( !ndn->bv_len ) {
679                 return( 0 );
680         }
681
682         if ( !be->be_update_ndn.bv_len ) {
683                 return( 0 );
684         }
685
686         return dn_match( &be->be_update_ndn, ndn );
687 }
688
689 struct berval *
690 be_root_dn( Backend *be )
691 {
692         return &be->be_rootdn;
693 }
694
695 int
696 be_isroot_pw( Operation *op )
697 {
698         int result;
699         char *errmsg;
700
701         if ( ! be_isroot( op->o_bd, &op->o_req_ndn ) ) {
702                 return 0;
703         }
704
705         if( op->o_bd->be_rootpw.bv_len == 0 ) {
706                 return 0;
707         }
708
709 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
710         ldap_pvt_thread_mutex_lock( &passwd_mutex );
711 #ifdef SLAPD_SPASSWD
712         lutil_passwd_sasl_conn = op->o_conn->c_sasl_authctx;
713 #endif
714 #endif
715
716         result = lutil_passwd( &op->o_bd->be_rootpw, &op->orb_cred, NULL, NULL );
717
718 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
719 #ifdef SLAPD_SPASSWD
720         lutil_passwd_sasl_conn = NULL;
721 #endif
722         ldap_pvt_thread_mutex_unlock( &passwd_mutex );
723 #endif
724
725         return result == 0;
726 }
727
728 int
729 be_entry_release_rw(
730         Operation *op,
731         Entry *e,
732         int rw )
733 {
734         if ( op->o_bd->be_release ) {
735                 /* free and release entry from backend */
736                 return op->o_bd->be_release( op, e, rw );
737         } else {
738                 /* free entry */
739                 entry_free( e );
740                 return 0;
741         }
742 }
743
744 int
745 backend_unbind( Operation *op, SlapReply *rs )
746 {
747         int             i;
748 #if defined( LDAP_SLAPI )
749         Slapi_PBlock *pb = op->o_pb;
750
751         int     rc;
752         slapi_x_pblock_set_operation( pb, op );
753 #endif /* defined( LDAP_SLAPI ) */
754
755         for ( i = 0; i < nbackends; i++ ) {
756 #if defined( LDAP_SLAPI )
757                 slapi_pblock_set( pb, SLAPI_BACKEND, (void *)&backends[i] );
758                 rc = doPluginFNs( &backends[i], SLAPI_PLUGIN_PRE_UNBIND_FN,
759                                 (Slapi_PBlock *)pb );
760                 if ( rc < 0 ) {
761                         /*
762                          * A preoperation plugin failure will abort the
763                          * entire operation.
764                          */
765 #ifdef NEW_LOGGING
766                         LDAP_LOG( OPERATION, INFO, "do_bind: Unbind preoperation plugin "
767                                         "failed\n", 0, 0, 0);
768 #else
769                         Debug(LDAP_DEBUG_TRACE, "do_bind: Unbind preoperation plugin "
770                                         "failed.\n", 0, 0, 0);
771 #endif
772                         return 0;
773                 }
774 #endif /* defined( LDAP_SLAPI ) */
775
776                 if ( backends[i].be_unbind ) {
777                         op->o_bd = &backends[i];
778                         (*backends[i].be_unbind)( op, rs );
779                 }
780
781 #if defined( LDAP_SLAPI )
782                 if ( doPluginFNs( &backends[i], SLAPI_PLUGIN_POST_UNBIND_FN,
783                                 (Slapi_PBlock *)pb ) < 0 ) {
784 #ifdef NEW_LOGGING
785                         LDAP_LOG( OPERATION, INFO, "do_unbind: Unbind postoperation plugins "
786                                         "failed\n", 0, 0, 0);
787 #else
788                         Debug(LDAP_DEBUG_TRACE, "do_unbind: Unbind postoperation plugins "
789                                         "failed.\n", 0, 0, 0);
790 #endif
791                 }
792 #endif /* defined( LDAP_SLAPI ) */
793         }
794
795         return 0;
796 }
797
798 int
799 backend_connection_init(
800         Connection   *conn
801 )
802 {
803         int     i;
804
805         for ( i = 0; i < nbackends; i++ ) {
806                 if ( backends[i].be_connection_init ) {
807                         (*backends[i].be_connection_init)( &backends[i], conn);
808                 }
809         }
810
811         return 0;
812 }
813
814 int
815 backend_connection_destroy(
816         Connection   *conn
817 )
818 {
819         int     i;
820
821         for ( i = 0; i < nbackends; i++ ) {
822                 if ( backends[i].be_connection_destroy ) {
823                         (*backends[i].be_connection_destroy)( &backends[i], conn);
824                 }
825         }
826
827         return 0;
828 }
829
830 static int
831 backend_check_controls(
832         Operation *op,
833         SlapReply *rs )
834 {
835         LDAPControl **ctrls = op->o_ctrls;
836         rs->sr_err = LDAP_SUCCESS;
837
838         if( ctrls ) {
839                 for( ; *ctrls != NULL ; ctrls++ ) {
840                         if( (*ctrls)->ldctl_iscritical && !ldap_charray_inlist(
841                                 op->o_bd->be_controls, (*ctrls)->ldctl_oid ) )
842                         {
843                                 rs->sr_text = "control unavailable in context";
844                                 rs->sr_err = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
845                                 break;
846                         }
847                 }
848         }
849
850         return rs->sr_err;
851 }
852
853 int
854 backend_check_restrictions(
855         Operation *op,
856         SlapReply *rs,
857         struct berval *opdata )
858 {
859         slap_mask_t restrictops;
860         slap_mask_t requires;
861         slap_mask_t opflag;
862         slap_ssf_set_t *ssf;
863         int updateop = 0;
864         int starttls = 0;
865         int session = 0;
866
867         if( op->o_bd ) {
868                 if ( backend_check_controls( op, rs ) != LDAP_SUCCESS ) {
869                         return rs->sr_err;
870                 }
871
872                 restrictops = op->o_bd->be_restrictops;
873                 requires = op->o_bd->be_requires;
874                 ssf = &op->o_bd->be_ssf_set;
875
876         } else {
877                 restrictops = global_restrictops;
878                 requires = global_requires;
879                 ssf = &global_ssf_set;
880         }
881
882         switch( op->o_tag ) {
883         case LDAP_REQ_ADD:
884                 opflag = SLAP_RESTRICT_OP_ADD;
885                 updateop++;
886                 break;
887         case LDAP_REQ_BIND:
888                 opflag = SLAP_RESTRICT_OP_BIND;
889                 session++;
890                 break;
891         case LDAP_REQ_COMPARE:
892                 opflag = SLAP_RESTRICT_OP_COMPARE;
893                 break;
894         case LDAP_REQ_DELETE:
895                 updateop++;
896                 opflag = SLAP_RESTRICT_OP_DELETE;
897                 break;
898         case LDAP_REQ_EXTENDED:
899                 opflag = SLAP_RESTRICT_OP_EXTENDED;
900
901                 if( !opdata ) {
902                         /* treat unspecified as a modify */
903                         opflag = SLAP_RESTRICT_OP_MODIFY;
904                         updateop++;
905                         break;
906                 }
907
908                 {
909                         if( bvmatch( opdata, &slap_EXOP_START_TLS ) ) {
910                                 session++;
911                                 starttls++;
912                                 break;
913                         }
914                 }
915
916                 {
917                         if( bvmatch( opdata, &slap_EXOP_WHOAMI ) ) {
918                                 break;
919                         }
920                 }
921
922 #ifdef LDAP_EXOP_X_CANCEL
923                 {
924                         if ( bvmatch( opdata, &slap_EXOP_CANCEL ) ) {
925                                 break;
926                         }
927                 }
928 #endif
929
930                 /* treat everything else as a modify */
931                 opflag = SLAP_RESTRICT_OP_MODIFY;
932                 updateop++;
933                 break;
934
935         case LDAP_REQ_MODIFY:
936                 updateop++;
937                 opflag = SLAP_RESTRICT_OP_MODIFY;
938                 break;
939         case LDAP_REQ_RENAME:
940                 updateop++;
941                 opflag = SLAP_RESTRICT_OP_RENAME;
942                 break;
943         case LDAP_REQ_SEARCH:
944                 opflag = SLAP_RESTRICT_OP_SEARCH;
945                 break;
946         case LDAP_REQ_UNBIND:
947                 session++;
948                 opflag = 0;
949                 break;
950         default:
951                 rs->sr_text = "restrict operations internal error";
952                 rs->sr_err = LDAP_OTHER;
953                 return rs->sr_err;
954         }
955
956         if ( !starttls ) {
957                 /* these checks don't apply to StartTLS */
958
959                 rs->sr_err = LDAP_CONFIDENTIALITY_REQUIRED;
960                 if( op->o_transport_ssf < ssf->sss_transport ) {
961                         rs->sr_text = "transport confidentiality required";
962                         return rs->sr_err;
963                 }
964
965                 if( op->o_tls_ssf < ssf->sss_tls ) {
966                         rs->sr_text = "TLS confidentiality required";
967                         return rs->sr_err;
968                 }
969
970
971                 if( op->o_tag == LDAP_REQ_BIND && opdata == NULL ) {
972                         /* simple bind specific check */
973                         if( op->o_ssf < ssf->sss_simple_bind ) {
974                                 rs->sr_text = "confidentiality required";
975                                 return rs->sr_err;
976                         }
977                 }
978
979                 if( op->o_tag != LDAP_REQ_BIND || opdata == NULL ) {
980                         /* these checks don't apply to SASL bind */
981
982                         if( op->o_sasl_ssf < ssf->sss_sasl ) {
983                                 rs->sr_text = "SASL confidentiality required";
984                                 return rs->sr_err;
985                         }
986
987                         if( op->o_ssf < ssf->sss_ssf ) {
988                                 rs->sr_text = "confidentiality required";
989                                 return rs->sr_err;
990                         }
991                 }
992
993                 if( updateop ) {
994                         if( op->o_transport_ssf < ssf->sss_update_transport ) {
995                                 rs->sr_text = "transport update confidentiality required";
996                                 return rs->sr_err;
997                         }
998
999                         if( op->o_tls_ssf < ssf->sss_update_tls ) {
1000                                 rs->sr_text = "TLS update confidentiality required";
1001                                 return rs->sr_err;
1002                         }
1003
1004                         if( op->o_sasl_ssf < ssf->sss_update_sasl ) {
1005                                 rs->sr_text = "SASL update confidentiality required";
1006                                 return rs->sr_err;
1007                         }
1008
1009                         if( op->o_ssf < ssf->sss_update_ssf ) {
1010                                 rs->sr_text = "update confidentiality required";
1011                                 return rs->sr_err;
1012                         }
1013
1014                         if( !( global_allows & SLAP_ALLOW_UPDATE_ANON ) &&
1015                                 op->o_ndn.bv_len == 0 )
1016                         {
1017                                 rs->sr_text = "modifications require authentication";
1018                                 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1019                                 return rs->sr_err;
1020                         }
1021
1022 #ifdef SLAP_X_LISTENER_MOD
1023                         if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & ( op->o_ndn.bv_len > 0 ? S_IWUSR : S_IWOTH ) ) ) {
1024                                 /* no "w" mode means readonly */
1025                                 rs->sr_text = "modifications not allowed on this listener";
1026                                 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1027                                 return rs->sr_err;
1028                         }
1029 #endif /* SLAP_X_LISTENER_MOD */
1030                 }
1031         }
1032
1033         if ( !session ) {
1034                 /* these checks don't apply to Bind, StartTLS, or Unbind */
1035
1036                 if( requires & SLAP_REQUIRE_STRONG ) {
1037                         /* should check mechanism */
1038                         if( ( op->o_transport_ssf < ssf->sss_transport
1039                                 && op->o_authmech.bv_len == 0 ) || op->o_dn.bv_len == 0 )
1040                         {
1041                                 rs->sr_text = "strong authentication required";
1042                                 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1043                                 return rs->sr_err;
1044                         }
1045                 }
1046
1047                 if( requires & SLAP_REQUIRE_SASL ) {
1048                         if( op->o_authmech.bv_len == 0 || op->o_dn.bv_len == 0 ) {
1049                                 rs->sr_text = "SASL authentication required";
1050                                 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1051                                 return rs->sr_err;
1052                         }
1053                 }
1054                         
1055                 if( requires & SLAP_REQUIRE_AUTHC ) {
1056                         if( op->o_dn.bv_len == 0 ) {
1057                                 rs->sr_text = "authentication required";
1058                                 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1059                                 return rs->sr_err;
1060                         }
1061                 }
1062
1063                 if( requires & SLAP_REQUIRE_BIND ) {
1064                         int version;
1065                         ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1066                         version = op->o_conn->c_protocol;
1067                         ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1068
1069                         if( !version ) {
1070                                 /* no bind has occurred */
1071                                 rs->sr_text = "BIND required";
1072                                 rs->sr_err = LDAP_OPERATIONS_ERROR;
1073                                 return rs->sr_err;
1074                         }
1075                 }
1076
1077                 if( requires & SLAP_REQUIRE_LDAP_V3 ) {
1078                         if( op->o_protocol < LDAP_VERSION3 ) {
1079                                 /* no bind has occurred */
1080                                 rs->sr_text = "operation restricted to LDAPv3 clients";
1081                                 rs->sr_err = LDAP_OPERATIONS_ERROR;
1082                                 return rs->sr_err;
1083                         }
1084                 }
1085
1086 #ifdef SLAP_X_LISTENER_MOD
1087                 if ( !starttls && op->o_dn.bv_len == 0 ) {
1088                         if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & S_IXOTH ) ) {
1089                                 /* no "x" mode means bind required */
1090                                 rs->sr_text = "bind required on this listener";
1091                                 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1092                                 return rs->sr_err;
1093                         }
1094                 }
1095
1096                 if ( !starttls && !updateop ) {
1097                         if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & ( op->o_dn.bv_len > 0 ? S_IRUSR : S_IROTH ) ) ) {
1098                                 /* no "r" mode means no read */
1099                                 rs->sr_text = "read not allowed on this listener";
1100                                 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1101                                 return rs->sr_err;
1102                         }
1103                 }
1104 #endif /* SLAP_X_LISTENER_MOD */
1105
1106         }
1107
1108         if( restrictops & opflag ) {
1109                 if( restrictops == SLAP_RESTRICT_OP_READS ) {
1110                         rs->sr_text = "read operations restricted";
1111                 } else {
1112                         rs->sr_text = "operation restricted";
1113                 }
1114                 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1115                 return rs->sr_err;
1116         }
1117
1118         rs->sr_err = LDAP_SUCCESS;
1119         return rs->sr_err;
1120 }
1121
1122 int backend_check_referrals( Operation *op, SlapReply *rs )
1123 {
1124         rs->sr_err = LDAP_SUCCESS;
1125
1126         if( op->o_bd->be_chk_referrals ) {
1127                 rs->sr_err = op->o_bd->be_chk_referrals( op, rs );
1128
1129                 if( rs->sr_err != LDAP_SUCCESS && rs->sr_err != LDAP_REFERRAL ) {
1130                         send_ldap_result( op, rs );
1131                 }
1132         }
1133
1134         return rs->sr_err;
1135 }
1136
1137 int
1138 be_entry_get_rw(
1139         Operation *op,
1140         struct berval *ndn,
1141         ObjectClass *oc,
1142         AttributeDescription *at,
1143         int rw,
1144         Entry **e )
1145 {
1146         int rc;
1147
1148         *e = NULL;
1149
1150         if (op->o_bd == NULL) {
1151                 rc = LDAP_NO_SUCH_OBJECT;
1152         } else if ( op->o_bd->be_fetch ) {
1153                 rc = ( op->o_bd->be_fetch )( op, ndn,
1154                         oc, at, rw, e );
1155         } else {
1156                 rc = LDAP_UNWILLING_TO_PERFORM;
1157         }
1158         return rc;
1159 }
1160
1161 int 
1162 backend_group(
1163         Operation *op,
1164         Entry   *target,
1165         struct berval *gr_ndn,
1166         struct berval *op_ndn,
1167         ObjectClass *group_oc,
1168         AttributeDescription *group_at
1169 )
1170 {
1171         Entry *e;
1172         Attribute *a;
1173         int rc;
1174         GroupAssertion *g;
1175         Backend *be = op->o_bd;
1176
1177         if ( op->o_abandon ) return SLAPD_ABANDON;
1178
1179         op->o_bd = select_backend( gr_ndn, 0, 0 );
1180
1181         for (g = op->o_groups; g; g=g->ga_next) {
1182                 if (g->ga_be != op->o_bd || g->ga_oc != group_oc ||
1183                         g->ga_at != group_at || g->ga_len != gr_ndn->bv_len)
1184                         continue;
1185                 if (strcmp( g->ga_ndn, gr_ndn->bv_val ) == 0)
1186                         break;
1187         }
1188
1189         if (g) {
1190                 rc = g->ga_res;
1191                 goto done;
1192         }
1193
1194         if ( target && dn_match( &target->e_nname, gr_ndn ) ) {
1195                 e = target;
1196                 rc = 0;
1197         } else {
1198                 rc = be_entry_get_rw(op, gr_ndn, group_oc, group_at, 0, &e );
1199         }
1200         if ( e ) {
1201                 a = attr_find( e->e_attrs, group_at );
1202                 if ( a ) {
1203                         /* If the attribute is a subtype of labeledURI, treat this as
1204                          * a dynamic group ala groupOfURLs
1205                          */
1206                         if (is_at_subtype( group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1207                                 int i;
1208                                 LDAPURLDesc *ludp;
1209                                 struct berval bv, nbase;
1210                                 Filter *filter;
1211                                 Entry *user;
1212                                 Backend *b2 = op->o_bd;
1213
1214                                 if ( target && dn_match( &target->e_nname, op_ndn ) ) {
1215                                         user = target;
1216                                 } else {
1217                                         op->o_bd = select_backend( op_ndn, 0, 0 );
1218                                         rc = be_entry_get_rw(op, op_ndn, NULL, NULL, 0, &user );
1219                                 }
1220                                 
1221                                 if ( rc == 0 ) {
1222                                         rc = 1;
1223                                         for (i=0; a->a_vals[i].bv_val; i++) {
1224                                                 if ( ldap_url_parse( a->a_vals[i].bv_val, &ludp ) != LDAP_SUCCESS )
1225                                                         continue;
1226                                                 nbase.bv_val = NULL;
1227                                                 /* host part must be empty */
1228                                                 /* attrs and extensions parts must be empty */
1229                                                 if (( ludp->lud_host && *ludp->lud_host )
1230                                                         || ludp->lud_attrs || ludp->lud_exts )
1231                                                         goto loopit;
1232                                                 ber_str2bv( ludp->lud_dn, 0, 0, &bv );
1233                                                 if ( dnNormalize( 0, NULL, NULL, &bv, &nbase, op->o_tmpmemctx ) != LDAP_SUCCESS )
1234                                                         goto loopit;
1235                                                 switch(ludp->lud_scope) {
1236                                                 case LDAP_SCOPE_BASE:
1237                                                         if ( !dn_match(&nbase, op_ndn)) goto loopit;
1238                                                         break;
1239                                                 case LDAP_SCOPE_ONELEVEL:
1240                                                         dnParent(op_ndn, &bv );
1241                                                         if ( !dn_match(&nbase, &bv)) goto loopit;
1242                                                         break;
1243                                                 case LDAP_SCOPE_SUBTREE:
1244                                                         if ( !dnIsSuffix(op_ndn, &nbase)) goto loopit;
1245                                                         break;
1246                                                 }
1247                                                 filter = str2filter_x( op, ludp->lud_filter );
1248                                                 if ( filter ) {
1249                                                         if ( test_filter( NULL, user, filter ) == LDAP_COMPARE_TRUE )
1250                                                         {
1251                                                                 rc = 0;
1252                                                         }
1253                                                         filter_free_x( op, filter );
1254                                                 }
1255         loopit:
1256                                                 ldap_free_urldesc( ludp );
1257                                                 if ( nbase.bv_val ) {
1258                                                         op->o_tmpfree( nbase.bv_val, op->o_tmpmemctx );
1259                                                 }
1260                                                 if ( rc == 0 ) break;
1261                                         }
1262                                         if ( user != target ) {
1263                                                 be_entry_release_r( op, user );
1264                                         }
1265                                 }
1266                                 op->o_bd = b2;
1267                         } else {
1268                                 rc = value_find_ex( group_at,
1269                                 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1270                                 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1271                                 a->a_nvals, op_ndn, op->o_tmpmemctx );
1272                         }
1273                 } else {
1274                         rc = LDAP_NO_SUCH_ATTRIBUTE;
1275                 }
1276                 if (e != target ) {
1277                         be_entry_release_r( op, e );
1278                 }
1279         } else {
1280                 rc = LDAP_NO_SUCH_OBJECT;
1281         }
1282
1283         if ( op->o_tag != LDAP_REQ_BIND && !op->o_do_not_cache ) {
1284                 g = sl_malloc(sizeof(GroupAssertion) + gr_ndn->bv_len, op->o_tmpmemctx);
1285                 g->ga_be = op->o_bd;
1286                 g->ga_oc = group_oc;
1287                 g->ga_at = group_at;
1288                 g->ga_res = rc;
1289                 g->ga_len = gr_ndn->bv_len;
1290                 strcpy(g->ga_ndn, gr_ndn->bv_val);
1291                 g->ga_next = op->o_groups;
1292                 op->o_groups = g;
1293         }
1294 done:
1295         op->o_bd = be;
1296         return rc;
1297 }
1298
1299 int 
1300 backend_attribute(
1301         Operation *op,
1302         Entry   *target,
1303         struct berval   *edn,
1304         AttributeDescription *entry_at,
1305         BerVarray *vals
1306 )
1307 {
1308         Entry *e;
1309         Attribute *a;
1310         int i, j, rc = LDAP_SUCCESS;
1311         AccessControlState acl_state = ACL_STATE_INIT;
1312         Backend *be = op->o_bd;
1313
1314         op->o_bd = select_backend( edn, 0, 0 );
1315
1316         if ( target && dn_match( &target->e_nname, edn ) ) {
1317                 e = target;
1318         } else {
1319                 rc = be_entry_get_rw(op, edn, NULL, entry_at, 0, &e );
1320         } 
1321
1322         if ( e ) {
1323                 a = attr_find( e->e_attrs, entry_at );
1324                 if ( a ) {
1325                         BerVarray v;
1326
1327                         if ( op->o_conn && access_allowed( op,
1328                                 e, entry_at, NULL, ACL_AUTH,
1329                                 &acl_state ) == 0 ) {
1330                                 rc = LDAP_INSUFFICIENT_ACCESS;
1331                                 goto freeit;
1332                         }
1333
1334                         for ( i=0; a->a_vals[i].bv_val; i++ ) ;
1335                         
1336                         v = op->o_tmpalloc( sizeof(struct berval) * (i+1), op->o_tmpmemctx );
1337                         for ( i=0,j=0; a->a_vals[i].bv_val; i++ ) {
1338                                 if ( op->o_conn && access_allowed( op,
1339                                         e, entry_at,
1340                                         &a->a_nvals[i],
1341                                         ACL_AUTH, &acl_state ) == 0 ) {
1342                                         continue;
1343                                 }
1344                                 ber_dupbv_x( &v[j],
1345                                         &a->a_nvals[i], op->o_tmpmemctx );
1346                                 if (v[j].bv_val ) j++;
1347                         }
1348                         if (j == 0) {
1349                                 op->o_tmpfree( v, op->o_tmpmemctx );
1350                                 *vals = NULL;
1351                                 rc = LDAP_INSUFFICIENT_ACCESS;
1352                         } else {
1353                                 v[j].bv_val = NULL;
1354                                 v[j].bv_len = 0;
1355                                 *vals = v;
1356                                 rc = LDAP_SUCCESS;
1357                         }
1358                 }
1359 freeit:         if (e != target ) {
1360                         be_entry_release_r( op, e );
1361                 }
1362         }
1363
1364         op->o_bd = be;
1365         return rc;
1366 }
1367
1368 Attribute *backend_operational(
1369         Operation *op,
1370         SlapReply *rs,
1371         int opattrs     )
1372 {
1373         Attribute *a = NULL, **ap = &a;
1374
1375         /*
1376          * If operational attributes (allegedly) are required, 
1377          * and the backend supports specific operational attributes, 
1378          * add them to the attribute list
1379          */
1380         if ( opattrs || ( op->ors_attrs &&
1381                 ad_inlist( slap_schema.si_ad_subschemaSubentry, op->ors_attrs )) ) {
1382                 *ap = slap_operational_subschemaSubentry( op->o_bd );
1383                 ap = &(*ap)->a_next;
1384         }
1385
1386         if ( ( opattrs || op->ors_attrs ) && op->o_bd && op->o_bd->be_operational != NULL ) {
1387                 ( void )op->o_bd->be_operational( op, rs, opattrs, ap );
1388         }
1389
1390         return a;
1391 }
1392