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