]> git.sur5r.net Git - openldap/blob - servers/slapd/backend.c
55f9228c860cb1088d94348d41204439b96fe6bb
[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         init_syncrepl();
248
249         if( ! ( nBackendDB > 0 ) ) {
250                 /* no databases */
251 #ifdef NEW_LOGGING
252                 LDAP_LOG( BACKEND, INFO, 
253                         "backend_startup: %d databases to startup. \n", nBackendDB, 0, 0 );
254 #else
255                 Debug( LDAP_DEBUG_ANY,
256                         "backend_startup: %d databases to startup.\n",
257                         nBackendDB, 0, 0 );
258 #endif
259                 return 1;
260         }
261
262         if(be != NULL) {
263                 /* startup a specific backend database */
264
265                 LDAP_TAILQ_INIT( &be->be_pending_csn_list );
266
267 #ifdef NEW_LOGGING
268                 LDAP_LOG( BACKEND, DETAIL1, "backend_startup:  starting \"%s\"\n",
269                            be->be_suffix[0].bv_val, 0, 0 );
270 #else
271                 Debug( LDAP_DEBUG_TRACE,
272                         "backend_startup: starting \"%s\"\n",
273                         be->be_suffix[0].bv_val, 0, 0 );
274 #endif
275
276                 if ( be->bd_info->bi_open ) {
277                         rc = be->bd_info->bi_open( be->bd_info );
278                         if ( rc != 0 ) {
279 #ifdef NEW_LOGGING
280                                 LDAP_LOG( BACKEND, CRIT, "backend_startup: bi_open failed!\n", 0, 0, 0 );
281 #else
282                                 Debug( LDAP_DEBUG_ANY,
283                                         "backend_startup: bi_open failed!\n",
284                                         0, 0, 0 );
285 #endif
286
287                                 return rc;
288                         }
289                 }
290
291                 if ( be->bd_info->bi_db_open ) {
292                         rc = be->bd_info->bi_db_open( be );
293                         if ( rc != 0 ) {
294 #ifdef NEW_LOGGING
295                                 LDAP_LOG( BACKEND, CRIT, 
296                                         "backend_startup: bi_db_open failed! (%d)\n", rc, 0, 0 );
297 #else
298                                 Debug( LDAP_DEBUG_ANY,
299                                         "backend_startup: bi_db_open failed! (%d)\n",
300                                         rc, 0, 0 );
301 #endif
302                                 return rc;
303                         }
304                 }
305
306                 return rc;
307         }
308
309         /* open each backend type */
310         for( i = 0; i < nBackendInfo; i++ ) {
311                 if( backendInfo[i].bi_nDB == 0) {
312                         /* no database of this type, don't open */
313                         continue;
314                 }
315
316                 if( backendInfo[i].bi_open ) {
317                         rc = backendInfo[i].bi_open(
318                                 &backendInfo[i] );
319                         if ( rc != 0 ) {
320 #ifdef NEW_LOGGING
321                                 LDAP_LOG( BACKEND, CRIT, 
322                                         "backend_startup: bi_open %d failed!\n", i, 0, 0 );
323 #else
324                                 Debug( LDAP_DEBUG_ANY,
325                                         "backend_startup: bi_open %d failed!\n",
326                                         i, 0, 0 );
327 #endif
328                                 return rc;
329                         }
330                 }
331         }
332
333         ldap_pvt_thread_mutex_init( &syncrepl_rq.rq_mutex );
334         LDAP_STAILQ_INIT( &syncrepl_rq.task_list );
335         LDAP_STAILQ_INIT( &syncrepl_rq.run_list );
336
337         /* open each backend database */
338         for( i = 0; i < nBackendDB; i++ ) {
339                 if ( backendDB[i].be_update_ndn.bv_val && (
340                         !backendDB[i].be_update_refs &&
341                         !backendDB[i].syncinfo &&
342                         !default_referral ) ) {
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
356                 /* append global access controls */
357                 acl_append( &backendDB[i].be_acl, global_acl );
358
359                 LDAP_TAILQ_INIT( &backendDB[i].be_pending_csn_list );
360
361                 if ( backendDB[i].bd_info->bi_db_open ) {
362                         rc = backendDB[i].bd_info->bi_db_open(
363                                 &backendDB[i] );
364                         if ( rc != 0 ) {
365 #ifdef NEW_LOGGING
366                                 LDAP_LOG( BACKEND, CRIT, 
367                                         "backend_startup: bi_db_open(%d) failed! (%d)\n", i, rc, 0 );
368 #else
369                                 Debug( LDAP_DEBUG_ANY,
370                                         "backend_startup: bi_db_open(%d) failed! (%d)\n",
371                                         i, rc, 0 );
372 #endif
373                                 return rc;
374                         }
375                 }
376
377                 if ( backendDB[i].syncinfo != NULL ) {
378                         syncinfo_t *si = ( syncinfo_t * ) backendDB[i].syncinfo;
379                         si->be = &backendDB[i];
380                         ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
381                         ldap_pvt_runqueue_insert( &syncrepl_rq, si->interval,
382                                                         do_syncrepl, (void *) backendDB[i].syncinfo );
383                         ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
384                 }
385         }
386
387         return rc;
388 }
389
390 int backend_num( Backend *be )
391 {
392         int i;
393
394         if( be == NULL ) return -1;
395
396         for( i = 0; i < nBackendDB; i++ ) {
397                 if( be == &backendDB[i] ) return i;
398         }
399         return -1;
400 }
401
402 int backend_shutdown( Backend *be )
403 {
404         int i;
405         int rc = 0;
406
407         if( be != NULL ) {
408                 /* shutdown a specific backend database */
409
410                 if ( be->bd_info->bi_nDB == 0 ) {
411                         /* no database of this type, we never opened it */
412                         return 0;
413                 }
414
415                 if ( be->bd_info->bi_db_close ) {
416                         be->bd_info->bi_db_close( be );
417                 }
418
419                 if( be->bd_info->bi_close ) {
420                         be->bd_info->bi_close( be->bd_info );
421                 }
422
423                 return 0;
424         }
425
426         /* close each backend database */
427         for( i = 0; i < nBackendDB; i++ ) {
428                 if ( backendDB[i].bd_info->bi_db_close ) {
429                         backendDB[i].bd_info->bi_db_close(
430                                 &backendDB[i] );
431                 }
432
433                 if(rc != 0) {
434 #ifdef NEW_LOGGING
435                         LDAP_LOG( BACKEND, NOTICE, 
436                                 "backend_shutdown: bi_close %s failed!\n",
437                                 backendDB[i].be_type, 0, 0 );
438 #else
439                         Debug( LDAP_DEBUG_ANY,
440                                 "backend_close: bi_close %s failed!\n",
441                                 backendDB[i].be_type, 0, 0 );
442 #endif
443                 }
444         }
445
446         /* close each backend type */
447         for( i = 0; i < nBackendInfo; i++ ) {
448                 if( backendInfo[i].bi_nDB == 0 ) {
449                         /* no database of this type */
450                         continue;
451                 }
452
453                 if( backendInfo[i].bi_close ) {
454                         backendInfo[i].bi_close(
455                                 &backendInfo[i] );
456                 }
457         }
458
459         return 0;
460 }
461
462 int backend_destroy(void)
463 {
464         int i;
465         BackendDB *bd;
466
467         ldap_pvt_thread_pool_destroy( &syncrepl_pool, 1 );
468
469         /* destroy each backend database */
470         for( i = 0, bd = backendDB; i < nBackendDB; i++, bd++ ) {
471                 if ( bd->bd_info->bi_db_destroy ) {
472                         bd->bd_info->bi_db_destroy( bd );
473                 }
474                 ber_bvarray_free( bd->be_suffix );
475                 ber_bvarray_free( bd->be_nsuffix );
476                 if ( bd->be_rootdn.bv_val ) free( bd->be_rootdn.bv_val );
477                 if ( bd->be_rootndn.bv_val ) free( bd->be_rootndn.bv_val );
478                 if ( bd->be_rootpw.bv_val ) free( bd->be_rootpw.bv_val );
479                 acl_destroy( bd->be_acl, global_acl );
480         }
481         free( backendDB );
482
483         /* destroy each backend type */
484         for( i = 0; i < nBackendInfo; i++ ) {
485                 if( backendInfo[i].bi_destroy ) {
486                         backendInfo[i].bi_destroy(
487                                 &backendInfo[i] );
488                 }
489         }
490
491 #ifdef SLAPD_MODULES
492         if (backendInfo != binfo) {
493            free(backendInfo);
494         }
495 #endif /* SLAPD_MODULES */
496
497         nBackendInfo = 0;
498         backendInfo = NULL;
499
500         return 0;
501 }
502
503 BackendInfo* backend_info(const char *type)
504 {
505         int i;
506
507         /* search for the backend type */
508         for( i = 0; i < nBackendInfo; i++ ) {
509                 if( strcasecmp(backendInfo[i].bi_type, type) == 0 ) {
510                         return &backendInfo[i];
511                 }
512         }
513
514         return NULL;
515 }
516
517
518 BackendDB *
519 backend_db_init(
520     const char  *type
521 )
522 {
523         Backend *be;
524         BackendInfo *bi = backend_info(type);
525         int     rc = 0;
526
527         if( bi == NULL ) {
528                 fprintf( stderr, "Unrecognized database type (%s)\n", type );
529                 return NULL;
530         }
531
532         backendDB = (BackendDB *) ch_realloc(
533                         (char *) backendDB,
534                     (nBackendDB + 1) * sizeof(Backend) );
535
536         memset( &backendDB[nbackends], '\0', sizeof(Backend) );
537
538         be = &backends[nbackends++];
539
540         be->bd_info = bi;
541         be->be_def_limit = deflimit;
542         be->be_dfltaccess = global_default_access;
543
544         be->be_restrictops = global_restrictops;
545         be->be_requires = global_requires;
546         be->be_ssf_set = global_ssf_set;
547
548         be->be_context_csn.bv_len = 0;
549         be->be_context_csn.bv_val = NULL;
550         ldap_pvt_thread_mutex_init( &be->be_pcl_mutex );
551         ldap_pvt_thread_mutex_init( &be->be_context_csn_mutex );
552
553         be->syncinfo = NULL;
554
555         /* assign a default depth limit for alias deref */
556         be->be_max_deref_depth = SLAPD_DEFAULT_MAXDEREFDEPTH; 
557
558         if(bi->bi_db_init) {
559                 rc = bi->bi_db_init( be );
560         }
561
562         if(rc != 0) {
563                 fprintf( stderr, "database init failed (%s)\n", type );
564                 nbackends--;
565                 return NULL;
566         }
567
568         bi->bi_nDB++;
569         return( be );
570 }
571
572 void
573 be_db_close( void )
574 {
575         int     i;
576
577         for ( i = 0; i < nbackends; i++ ) {
578                 if ( backends[i].bd_info->bi_db_close ) {
579                         (*backends[i].bd_info->bi_db_close)( &backends[i] );
580                 }
581         }
582 }
583
584 Backend *
585 select_backend(
586         struct berval * dn,
587         int manageDSAit,
588         int noSubs )
589 {
590         int     i, j;
591         ber_len_t len, dnlen = dn->bv_len;
592         Backend *be = NULL;
593
594         for ( i = 0; i < nbackends; i++ ) {
595                 for ( j = 0; backends[i].be_nsuffix != NULL &&
596                     backends[i].be_nsuffix[j].bv_val != NULL; j++ )
597                 {
598                         if ( ( SLAP_GLUE_SUBORDINATE( &backends[i] ) )
599                                 && noSubs )
600                         {
601                                 continue;
602                         }
603
604                         len = backends[i].be_nsuffix[j].bv_len;
605
606                         if ( len > dnlen ) {
607                                 /* suffix is longer than DN */
608                                 continue;
609                         }
610                         
611                         /*
612                          * input DN is normalized, so the separator check
613                          * need not look at escaping
614                          */
615                         if ( len && len < dnlen &&
616                                 !DN_SEPARATOR( dn->bv_val[(dnlen-len)-1] ))
617                         {
618                                 continue;
619                         }
620
621                         if ( strcmp( backends[i].be_nsuffix[j].bv_val,
622                                 &dn->bv_val[dnlen-len] ) == 0 )
623                         {
624                                 if( be == NULL ) {
625                                         be = &backends[i];
626
627                                         if( manageDSAit && len == dnlen ) {
628                                                 continue;
629                                         }
630                                 } else {
631                                         be = &backends[i];
632                                 }
633                                 return be;
634                         }
635                 }
636         }
637
638         return be;
639 }
640
641 int
642 be_issuffix(
643     Backend     *be,
644     struct berval       *bvsuffix
645 )
646 {
647         int     i;
648
649         for ( i = 0; be->be_nsuffix != NULL && be->be_nsuffix[i].bv_val != NULL; i++ ) {
650                 if ( bvmatch( &be->be_nsuffix[i], bvsuffix ) ) {
651                         return( 1 );
652                 }
653         }
654
655         return( 0 );
656 }
657
658 int
659 be_isroot( Backend *be, struct berval *ndn )
660 {
661         if ( !ndn->bv_len ) {
662                 return( 0 );
663         }
664
665         if ( !be->be_rootndn.bv_len ) {
666                 return( 0 );
667         }
668
669         return dn_match( &be->be_rootndn, ndn );
670 }
671
672 int
673 be_isupdate( Backend *be, struct berval *ndn )
674 {
675         if ( !ndn->bv_len ) {
676                 return( 0 );
677         }
678
679         if ( !be->be_update_ndn.bv_len ) {
680                 return( 0 );
681         }
682
683         return dn_match( &be->be_update_ndn, ndn );
684 }
685
686 struct berval *
687 be_root_dn( Backend *be )
688 {
689         return &be->be_rootdn;
690 }
691
692 int
693 be_isroot_pw( Operation *op )
694 {
695         int result;
696         char *errmsg;
697
698         if ( ! be_isroot( op->o_bd, &op->o_req_ndn ) ) {
699                 return 0;
700         }
701
702         if( op->o_bd->be_rootpw.bv_len == 0 ) {
703                 return 0;
704         }
705
706 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
707         ldap_pvt_thread_mutex_lock( &passwd_mutex );
708 #ifdef SLAPD_SPASSWD
709         lutil_passwd_sasl_conn = op->o_conn->c_sasl_authctx;
710 #endif
711 #endif
712
713         result = lutil_passwd( &op->o_bd->be_rootpw, &op->orb_cred, NULL, NULL );
714
715 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
716 #ifdef SLAPD_SPASSWD
717         lutil_passwd_sasl_conn = NULL;
718 #endif
719         ldap_pvt_thread_mutex_unlock( &passwd_mutex );
720 #endif
721
722         return result == 0;
723 }
724
725 int
726 be_entry_release_rw(
727         Operation *op,
728         Entry *e,
729         int rw )
730 {
731         if ( op->o_bd->be_release ) {
732                 /* free and release entry from backend */
733                 return op->o_bd->be_release( op, e, rw );
734         } else {
735                 /* free entry */
736                 entry_free( e );
737                 return 0;
738         }
739 }
740
741 int
742 backend_unbind( Operation *op, SlapReply *rs )
743 {
744         int             i;
745 #if defined( LDAP_SLAPI )
746         Slapi_PBlock *pb = op->o_pb;
747
748         int     rc;
749         slapi_x_pblock_set_operation( pb, op );
750 #endif /* defined( LDAP_SLAPI ) */
751
752         for ( i = 0; i < nbackends; i++ ) {
753 #if defined( LDAP_SLAPI )
754                 slapi_pblock_set( pb, SLAPI_BACKEND, (void *)&backends[i] );
755                 rc = doPluginFNs( &backends[i], SLAPI_PLUGIN_PRE_UNBIND_FN,
756                                 (Slapi_PBlock *)pb );
757                 if ( rc < 0 ) {
758                         /*
759                          * A preoperation plugin failure will abort the
760                          * entire operation.
761                          */
762 #ifdef NEW_LOGGING
763                         LDAP_LOG( OPERATION, INFO, "do_bind: Unbind preoperation plugin "
764                                         "failed\n", 0, 0, 0);
765 #else
766                         Debug(LDAP_DEBUG_TRACE, "do_bind: Unbind preoperation plugin "
767                                         "failed.\n", 0, 0, 0);
768 #endif
769                         return 0;
770                 }
771 #endif /* defined( LDAP_SLAPI ) */
772
773                 if ( backends[i].be_unbind ) {
774                         op->o_bd = &backends[i];
775                         (*backends[i].be_unbind)( op, rs );
776                 }
777
778 #if defined( LDAP_SLAPI )
779                 if ( doPluginFNs( &backends[i], SLAPI_PLUGIN_POST_UNBIND_FN,
780                                 (Slapi_PBlock *)pb ) < 0 ) {
781 #ifdef NEW_LOGGING
782                         LDAP_LOG( OPERATION, INFO, "do_unbind: Unbind postoperation plugins "
783                                         "failed\n", 0, 0, 0);
784 #else
785                         Debug(LDAP_DEBUG_TRACE, "do_unbind: Unbind postoperation plugins "
786                                         "failed.\n", 0, 0, 0);
787 #endif
788                 }
789 #endif /* defined( LDAP_SLAPI ) */
790         }
791
792         return 0;
793 }
794
795 int
796 backend_connection_init(
797         Connection   *conn
798 )
799 {
800         int     i;
801
802         for ( i = 0; i < nbackends; i++ ) {
803                 if ( backends[i].be_connection_init ) {
804                         (*backends[i].be_connection_init)( &backends[i], conn);
805                 }
806         }
807
808         return 0;
809 }
810
811 int
812 backend_connection_destroy(
813         Connection   *conn
814 )
815 {
816         int     i;
817
818         for ( i = 0; i < nbackends; i++ ) {
819                 if ( backends[i].be_connection_destroy ) {
820                         (*backends[i].be_connection_destroy)( &backends[i], conn);
821                 }
822         }
823
824         return 0;
825 }
826
827 static int
828 backend_check_controls(
829         Operation *op,
830         SlapReply *rs )
831 {
832         LDAPControl **ctrls = op->o_ctrls;
833         rs->sr_err = LDAP_SUCCESS;
834
835         if( ctrls ) {
836                 for( ; *ctrls != NULL ; ctrls++ ) {
837                         if( (*ctrls)->ldctl_iscritical && !ldap_charray_inlist(
838                                 op->o_bd->be_controls, (*ctrls)->ldctl_oid ) )
839                         {
840                                 rs->sr_text = "control unavailable in context";
841                                 rs->sr_err = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
842                                 break;
843                         }
844                 }
845         }
846
847         return rs->sr_err;
848 }
849
850 int
851 backend_check_restrictions(
852         Operation *op,
853         SlapReply *rs,
854         struct berval *opdata )
855 {
856         slap_mask_t restrictops;
857         slap_mask_t requires;
858         slap_mask_t opflag;
859         slap_ssf_set_t *ssf;
860         int updateop = 0;
861         int starttls = 0;
862         int session = 0;
863
864         if( op->o_bd ) {
865                 if ( backend_check_controls( op, rs ) != LDAP_SUCCESS ) {
866                         return rs->sr_err;
867                 }
868
869                 restrictops = op->o_bd->be_restrictops;
870                 requires = op->o_bd->be_requires;
871                 ssf = &op->o_bd->be_ssf_set;
872
873         } else {
874                 restrictops = global_restrictops;
875                 requires = global_requires;
876                 ssf = &global_ssf_set;
877         }
878
879         switch( op->o_tag ) {
880         case LDAP_REQ_ADD:
881                 opflag = SLAP_RESTRICT_OP_ADD;
882                 updateop++;
883                 break;
884         case LDAP_REQ_BIND:
885                 opflag = SLAP_RESTRICT_OP_BIND;
886                 session++;
887                 break;
888         case LDAP_REQ_COMPARE:
889                 opflag = SLAP_RESTRICT_OP_COMPARE;
890                 break;
891         case LDAP_REQ_DELETE:
892                 updateop++;
893                 opflag = SLAP_RESTRICT_OP_DELETE;
894                 break;
895         case LDAP_REQ_EXTENDED:
896                 opflag = SLAP_RESTRICT_OP_EXTENDED;
897
898                 if( !opdata ) {
899                         /* treat unspecified as a modify */
900                         opflag = SLAP_RESTRICT_OP_MODIFY;
901                         updateop++;
902                         break;
903                 }
904
905                 {
906                         if( bvmatch( opdata, &slap_EXOP_START_TLS ) ) {
907                                 session++;
908                                 starttls++;
909                                 break;
910                         }
911                 }
912
913                 {
914                         if( bvmatch( opdata, &slap_EXOP_WHOAMI ) ) {
915                                 break;
916                         }
917                 }
918
919 #ifdef LDAP_EXOP_X_CANCEL
920                 {
921                         if ( bvmatch( opdata, &slap_EXOP_CANCEL ) ) {
922                                 break;
923                         }
924                 }
925 #endif
926
927                 /* treat everything else as a modify */
928                 opflag = SLAP_RESTRICT_OP_MODIFY;
929                 updateop++;
930                 break;
931
932         case LDAP_REQ_MODIFY:
933                 updateop++;
934                 opflag = SLAP_RESTRICT_OP_MODIFY;
935                 break;
936         case LDAP_REQ_RENAME:
937                 updateop++;
938                 opflag = SLAP_RESTRICT_OP_RENAME;
939                 break;
940         case LDAP_REQ_SEARCH:
941                 opflag = SLAP_RESTRICT_OP_SEARCH;
942                 break;
943         case LDAP_REQ_UNBIND:
944                 session++;
945                 opflag = 0;
946                 break;
947         default:
948                 rs->sr_text = "restrict operations internal error";
949                 rs->sr_err = LDAP_OTHER;
950                 return rs->sr_err;
951         }
952
953         if ( !starttls ) {
954                 /* these checks don't apply to StartTLS */
955
956                 rs->sr_err = LDAP_CONFIDENTIALITY_REQUIRED;
957                 if( op->o_transport_ssf < ssf->sss_transport ) {
958                         rs->sr_text = "transport confidentiality required";
959                         return rs->sr_err;
960                 }
961
962                 if( op->o_tls_ssf < ssf->sss_tls ) {
963                         rs->sr_text = "TLS confidentiality required";
964                         return rs->sr_err;
965                 }
966
967
968                 if( op->o_tag == LDAP_REQ_BIND && opdata == NULL ) {
969                         /* simple bind specific check */
970                         if( op->o_ssf < ssf->sss_simple_bind ) {
971                                 rs->sr_text = "confidentiality required";
972                                 return rs->sr_err;
973                         }
974                 }
975
976                 if( op->o_tag != LDAP_REQ_BIND || opdata == NULL ) {
977                         /* these checks don't apply to SASL bind */
978
979                         if( op->o_sasl_ssf < ssf->sss_sasl ) {
980                                 rs->sr_text = "SASL confidentiality required";
981                                 return rs->sr_err;
982                         }
983
984                         if( op->o_ssf < ssf->sss_ssf ) {
985                                 rs->sr_text = "confidentiality required";
986                                 return rs->sr_err;
987                         }
988                 }
989
990                 if( updateop ) {
991                         if( op->o_transport_ssf < ssf->sss_update_transport ) {
992                                 rs->sr_text = "transport update confidentiality required";
993                                 return rs->sr_err;
994                         }
995
996                         if( op->o_tls_ssf < ssf->sss_update_tls ) {
997                                 rs->sr_text = "TLS update confidentiality required";
998                                 return rs->sr_err;
999                         }
1000
1001                         if( op->o_sasl_ssf < ssf->sss_update_sasl ) {
1002                                 rs->sr_text = "SASL update confidentiality required";
1003                                 return rs->sr_err;
1004                         }
1005
1006                         if( op->o_ssf < ssf->sss_update_ssf ) {
1007                                 rs->sr_text = "update confidentiality required";
1008                                 return rs->sr_err;
1009                         }
1010
1011                         if( !( global_allows & SLAP_ALLOW_UPDATE_ANON ) &&
1012                                 op->o_ndn.bv_len == 0 )
1013                         {
1014                                 rs->sr_text = "modifications require authentication";
1015                                 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1016                                 return rs->sr_err;
1017                         }
1018
1019 #ifdef SLAP_X_LISTENER_MOD
1020                         if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & ( op->o_ndn.bv_len > 0 ? S_IWUSR : S_IWOTH ) ) ) {
1021                                 /* no "w" mode means readonly */
1022                                 rs->sr_text = "modifications not allowed on this listener";
1023                                 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1024                                 return rs->sr_err;
1025                         }
1026 #endif /* SLAP_X_LISTENER_MOD */
1027                 }
1028         }
1029
1030         if ( !session ) {
1031                 /* these checks don't apply to Bind, StartTLS, or Unbind */
1032
1033                 if( requires & SLAP_REQUIRE_STRONG ) {
1034                         /* should check mechanism */
1035                         if( ( op->o_transport_ssf < ssf->sss_transport
1036                                 && op->o_authmech.bv_len == 0 ) || op->o_dn.bv_len == 0 )
1037                         {
1038                                 rs->sr_text = "strong authentication required";
1039                                 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1040                                 return rs->sr_err;
1041                         }
1042                 }
1043
1044                 if( requires & SLAP_REQUIRE_SASL ) {
1045                         if( op->o_authmech.bv_len == 0 || op->o_dn.bv_len == 0 ) {
1046                                 rs->sr_text = "SASL authentication required";
1047                                 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1048                                 return rs->sr_err;
1049                         }
1050                 }
1051                         
1052                 if( requires & SLAP_REQUIRE_AUTHC ) {
1053                         if( op->o_dn.bv_len == 0 ) {
1054                                 rs->sr_text = "authentication required";
1055                                 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1056                                 return rs->sr_err;
1057                         }
1058                 }
1059
1060                 if( requires & SLAP_REQUIRE_BIND ) {
1061                         int version;
1062                         ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1063                         version = op->o_conn->c_protocol;
1064                         ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1065
1066                         if( !version ) {
1067                                 /* no bind has occurred */
1068                                 rs->sr_text = "BIND required";
1069                                 rs->sr_err = LDAP_OPERATIONS_ERROR;
1070                                 return rs->sr_err;
1071                         }
1072                 }
1073
1074                 if( requires & SLAP_REQUIRE_LDAP_V3 ) {
1075                         if( op->o_protocol < LDAP_VERSION3 ) {
1076                                 /* no bind has occurred */
1077                                 rs->sr_text = "operation restricted to LDAPv3 clients";
1078                                 rs->sr_err = LDAP_OPERATIONS_ERROR;
1079                                 return rs->sr_err;
1080                         }
1081                 }
1082
1083 #ifdef SLAP_X_LISTENER_MOD
1084                 if ( !starttls && op->o_dn.bv_len == 0 ) {
1085                         if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & S_IXOTH ) ) {
1086                                 /* no "x" mode means bind required */
1087                                 rs->sr_text = "bind required on this listener";
1088                                 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1089                                 return rs->sr_err;
1090                         }
1091                 }
1092
1093                 if ( !starttls && !updateop ) {
1094                         if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & ( op->o_dn.bv_len > 0 ? S_IRUSR : S_IROTH ) ) ) {
1095                                 /* no "r" mode means no read */
1096                                 rs->sr_text = "read not allowed on this listener";
1097                                 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1098                                 return rs->sr_err;
1099                         }
1100                 }
1101 #endif /* SLAP_X_LISTENER_MOD */
1102
1103         }
1104
1105         if( restrictops & opflag ) {
1106                 if( restrictops == SLAP_RESTRICT_OP_READS ) {
1107                         rs->sr_text = "read operations restricted";
1108                 } else {
1109                         rs->sr_text = "operation restricted";
1110                 }
1111                 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1112                 return rs->sr_err;
1113         }
1114
1115         rs->sr_err = LDAP_SUCCESS;
1116         return rs->sr_err;
1117 }
1118
1119 int backend_check_referrals( Operation *op, SlapReply *rs )
1120 {
1121         rs->sr_err = LDAP_SUCCESS;
1122
1123         if( op->o_bd->be_chk_referrals ) {
1124                 rs->sr_err = op->o_bd->be_chk_referrals( op, rs );
1125
1126                 if( rs->sr_err != LDAP_SUCCESS && rs->sr_err != LDAP_REFERRAL ) {
1127                         send_ldap_result( op, rs );
1128                 }
1129         }
1130
1131         return rs->sr_err;
1132 }
1133
1134 int
1135 be_entry_get_rw(
1136         Operation *op,
1137         struct berval *ndn,
1138         ObjectClass *oc,
1139         AttributeDescription *at,
1140         int rw,
1141         Entry **e )
1142 {
1143         int rc;
1144
1145         *e = NULL;
1146
1147         if (op->o_bd == NULL) {
1148                 rc = LDAP_NO_SUCH_OBJECT;
1149         } else if ( op->o_bd->be_fetch ) {
1150                 rc = ( op->o_bd->be_fetch )( op, ndn,
1151                         oc, at, rw, e );
1152         } else {
1153                 rc = LDAP_UNWILLING_TO_PERFORM;
1154         }
1155         return rc;
1156 }
1157
1158 int 
1159 backend_group(
1160         Operation *op,
1161         Entry   *target,
1162         struct berval *gr_ndn,
1163         struct berval *op_ndn,
1164         ObjectClass *group_oc,
1165         AttributeDescription *group_at
1166 )
1167 {
1168         Entry *e;
1169         Attribute *a;
1170         int rc;
1171         GroupAssertion *g;
1172         Backend *be = op->o_bd;
1173
1174         if ( op->o_abandon ) return SLAPD_ABANDON;
1175
1176         op->o_bd = select_backend( gr_ndn, 0, 0 );
1177
1178         ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1179
1180         for (g = op->o_conn->c_groups; g; g=g->ga_next) {
1181                 if (g->ga_be != op->o_bd || g->ga_oc != group_oc ||
1182                         g->ga_at != group_at || g->ga_len != gr_ndn->bv_len)
1183                         continue;
1184                 if (strcmp( g->ga_ndn, gr_ndn->bv_val ) == 0)
1185                         break;
1186         }
1187
1188         ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1189
1190         if (g) {
1191                 rc = g->ga_res;
1192                 goto done;
1193         }
1194
1195         if ( target && dn_match( &target->e_nname, gr_ndn ) ) {
1196                 e = target;
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 = ch_malloc(sizeof(GroupAssertion) + gr_ndn->bv_len);
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                 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1292                 g->ga_next = op->o_conn->c_groups;
1293                 op->o_conn->c_groups = g;
1294                 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1295         }
1296 done:
1297         op->o_bd = be;
1298         return rc;
1299 }
1300
1301 int 
1302 backend_attribute(
1303         Operation *op,
1304         Entry   *target,
1305         struct berval   *edn,
1306         AttributeDescription *entry_at,
1307         BerVarray *vals
1308 )
1309 {
1310         Entry *e;
1311         Attribute *a;
1312         int i, j, rc = LDAP_SUCCESS;
1313         AccessControlState acl_state = ACL_STATE_INIT;
1314         Backend *be = op->o_bd;
1315
1316         op->o_bd = select_backend( edn, 0, 0 );
1317
1318         if ( target && dn_match( &target->e_nname, edn ) ) {
1319                 e = target;
1320         } else {
1321                 rc = be_entry_get_rw(op, edn, NULL, entry_at, 0, &e );
1322         } 
1323
1324         if ( e ) {
1325                 a = attr_find( e->e_attrs, entry_at );
1326                 if ( a ) {
1327                         BerVarray v;
1328
1329                         if ( op->o_conn && access_allowed( op,
1330                                 e, entry_at, NULL, ACL_AUTH,
1331                                 &acl_state ) == 0 ) {
1332                                 rc = LDAP_INSUFFICIENT_ACCESS;
1333                                 goto freeit;
1334                         }
1335
1336                         for ( i=0; a->a_vals[i].bv_val; i++ ) ;
1337                         
1338                         v = op->o_tmpalloc( sizeof(struct berval) * (i+1), op->o_tmpmemctx );
1339                         for ( i=0,j=0; a->a_vals[i].bv_val; i++ ) {
1340                                 if ( op->o_conn && access_allowed( op,
1341                                         e, entry_at,
1342                                         &a->a_nvals[i],
1343                                         ACL_AUTH, &acl_state ) == 0 ) {
1344                                         continue;
1345                                 }
1346                                 ber_dupbv_x( &v[j],
1347                                         &a->a_nvals[i], op->o_tmpmemctx );
1348                                 if (v[j].bv_val ) j++;
1349                         }
1350                         if (j == 0) {
1351                                 op->o_tmpfree( v, op->o_tmpmemctx );
1352                                 *vals = NULL;
1353                                 rc = LDAP_INSUFFICIENT_ACCESS;
1354                         } else {
1355                                 v[j].bv_val = NULL;
1356                                 v[j].bv_len = 0;
1357                                 *vals = v;
1358                                 rc = LDAP_SUCCESS;
1359                         }
1360                 }
1361 freeit:         if (e != target ) {
1362                         be_entry_release_r( op, e );
1363                 }
1364         }
1365
1366         op->o_bd = be;
1367         return rc;
1368 }
1369
1370 Attribute *backend_operational(
1371         Operation *op,
1372         SlapReply *rs,
1373         int opattrs     )
1374 {
1375         Attribute *a = NULL, **ap = &a;
1376
1377         /*
1378          * If operational attributes (allegedly) are required, 
1379          * and the backend supports specific operational attributes, 
1380          * add them to the attribute list
1381          */
1382         if ( opattrs || ( op->ors_attrs &&
1383                 ad_inlist( slap_schema.si_ad_subschemaSubentry, op->ors_attrs )) ) {
1384                 *ap = slap_operational_subschemaSubentry( op->o_bd );
1385                 ap = &(*ap)->a_next;
1386         }
1387
1388         if ( ( opattrs || op->ors_attrs ) && op->o_bd && op->o_bd->be_operational != NULL ) {
1389                 ( void )op->o_bd->be_operational( op, rs, opattrs, ap );
1390         }
1391
1392         return a;
1393 }
1394