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