3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 /* backend.c - routines for dealing with back-end databases */
13 #include <ac/string.h>
14 #include <ac/socket.h>
26 * If a module is configured as dynamic, its header should not
27 * get included into slapd. While this is a general rule and does
28 * not have much of an effect in UNIX, this rule should be adhered
29 * to for Windows, where dynamic object code should not be implicitly
30 * imported into slapd without appropriate __declspec(dllimport) directives.
33 #if defined(SLAPD_BDB) && !defined(SLAPD_BDB_DYNAMIC)
34 #include "back-bdb/external.h"
36 #if defined(SLAPD_DNSSRV) && !defined(SLAPD_DNSSRV_DYNAMIC)
37 #include "back-dnssrv/external.h"
39 #if defined(SLAPD_LDAP) && !defined(SLAPD_LDAP_DYNAMIC)
40 #include "back-ldap/external.h"
42 #if defined(SLAPD_LDBM) && !defined(SLAPD_LDBM_DYNAMIC)
43 #include "back-ldbm/external.h"
45 #if defined(SLAPD_META) && !defined(SLAPD_META_DYNAMIC)
46 #include "back-meta/external.h"
48 #if defined(SLAPD_MONITOR) && !defined(SLAPD_MONITOR_DYNAMIC)
49 #include "back-monitor/external.h"
51 #if defined(SLAPD_NULL) && !defined(SLAPD_NULL_DYNAMIC)
52 #include "back-null/external.h"
54 #if defined(SLAPD_PASSWD) && !defined(SLAPD_PASSWD_DYNAMIC)
55 #include "back-passwd/external.h"
57 #if defined(SLAPD_PERL) && !defined(SLAPD_PERL_DYNAMIC)
58 #include "back-perl/external.h"
60 #if defined(SLAPD_SHELL) && !defined(SLAPD_SHELL_DYNAMIC)
61 #include "back-shell/external.h"
63 #if defined(SLAPD_TCL) && !defined(SLAPD_TCL_DYNAMIC)
64 #include "back-tcl/external.h"
66 #if defined(SLAPD_SQL) && !defined(SLAPD_SQL_DYNAMIC)
67 #include "back-sql/external.h"
69 #if defined(SLAPD_PRIVATE) && !defined(SLAPD_PRIVATE_DYNAMIC)
70 #include "private/external.h"
73 static BackendInfo binfo[] = {
74 #if defined(SLAPD_BDB) && !defined(SLAPD_BDB_DYNAMIC)
75 {"bdb", bdb_initialize},
77 #if defined(SLAPD_DNSSRV) && !defined(SLAPD_DNSSRV_DYNAMIC)
78 {"dnssrv", dnssrv_back_initialize},
80 #if defined(SLAPD_LDAP) && !defined(SLAPD_LDAP_DYNAMIC)
81 {"ldap", ldap_back_initialize},
83 #if defined(SLAPD_LDBM) && !defined(SLAPD_LDBM_DYNAMIC)
84 {"ldbm", ldbm_back_initialize},
86 #if defined(SLAPD_META) && !defined(SLAPD_META_DYNAMIC)
87 {"meta", meta_back_initialize},
89 #if defined(SLAPD_MONITOR) && !defined(SLAPD_MONITOR_DYNAMIC)
90 {"monitor", monitor_back_initialize},
92 #if defined(SLAPD_NULL) && !defined(SLAPD_NULL_DYNAMIC)
93 {"null", null_back_initialize},
95 #if defined(SLAPD_PASSWD) && !defined(SLAPD_PASSWD_DYNAMIC)
96 {"passwd", passwd_back_initialize},
98 #if defined(SLAPD_PERL) && !defined(SLAPD_PERL_DYNAMIC)
99 {"perl", perl_back_initialize},
101 #if defined(SLAPD_SHELL) && !defined(SLAPD_SHELL_DYNAMIC)
102 {"shell", shell_back_initialize},
104 #if defined(SLAPD_TCL) && !defined(SLAPD_TCL_DYNAMIC)
105 {"tcl", tcl_back_initialize},
107 #if defined(SLAPD_SQL) && !defined(SLAPD_SQL_DYNAMIC)
108 {"sql", sql_back_initialize},
110 /* for any private backend */
111 #if defined(SLAPD_PRIVATE) && !defined(SLAPD_PRIVATE_DYNAMIC)
112 {"private", private_back_initialize},
117 int nBackendInfo = 0;
118 BackendInfo *backendInfo = NULL;
121 BackendDB *backendDB = NULL;
123 int backend_init(void)
127 if((nBackendInfo != 0) || (backendInfo != NULL)) {
128 /* already initialized */
130 LDAP_LOG( BACKEND, ERR,
131 "backend_init: backend already initialized\n", 0, 0, 0 );
133 Debug( LDAP_DEBUG_ANY,
134 "backend_init: already initialized.\n", 0, 0, 0 );
140 binfo[nBackendInfo].bi_type != NULL;
143 rc = binfo[nBackendInfo].bi_init( &binfo[nBackendInfo] );
147 LDAP_LOG( BACKEND, INFO,
148 "backend_init: initialized for type \"%s\"\n",
149 binfo[nBackendInfo].bi_type, 0, 0 );
151 Debug( LDAP_DEBUG_ANY,
152 "backend_init: initialized for type \"%s\"\n",
153 binfo[nBackendInfo].bi_type, 0, 0 );
155 /* destroy those we've already inited */
160 if ( binfo[nBackendInfo].bi_destroy ) {
161 binfo[nBackendInfo].bi_destroy(
162 &binfo[nBackendInfo] );
169 if ( nBackendInfo > 0) {
179 LDAP_LOG( BACKEND, ERR, "backend_init: failed\n", 0, 0, 0 );
181 Debug( LDAP_DEBUG_ANY,
182 "backend_init: failed\n",
187 #endif /* SLAPD_MODULES */
190 int backend_add(BackendInfo *aBackendInfo)
194 if ((rc = aBackendInfo->bi_init(aBackendInfo)) != 0) {
196 LDAP_LOG( BACKEND, ERR,
197 "backend_add: initialization for type \"%s\" failed\n",
198 aBackendInfo->bi_type, 0, 0 );
200 Debug( LDAP_DEBUG_ANY,
201 "backend_add: initialization for type \"%s\" failed\n",
202 aBackendInfo->bi_type, 0, 0 );
207 /* now add the backend type to the Backend Info List */
209 BackendInfo *newBackendInfo = 0;
211 /* if backendInfo == binfo no deallocation of old backendInfo */
212 if (backendInfo == binfo) {
213 newBackendInfo = ch_calloc(nBackendInfo + 1, sizeof(BackendInfo));
214 AC_MEMCPY(newBackendInfo, backendInfo, sizeof(BackendInfo) *
217 newBackendInfo = ch_realloc(backendInfo, sizeof(BackendInfo) *
220 AC_MEMCPY(&newBackendInfo[nBackendInfo], aBackendInfo,
221 sizeof(BackendInfo));
222 backendInfo = newBackendInfo;
229 int backend_startup(Backend *be)
234 if( ! ( nBackendDB > 0 ) ) {
237 LDAP_LOG( BACKEND, INFO,
238 "backend_startup: %d databases to startup. \n", nBackendDB, 0, 0 );
240 Debug( LDAP_DEBUG_ANY,
241 "backend_startup: %d databases to startup.\n",
248 /* startup a specific backend database */
250 LDAP_LOG( BACKEND, DETAIL1, "backend_startup: starting \"%s\"\n",
251 be->be_suffix[0].bv_val, 0, 0 );
253 Debug( LDAP_DEBUG_TRACE,
254 "backend_startup: starting \"%s\"\n",
255 be->be_suffix[0].bv_val, 0, 0 );
258 if ( be->bd_info->bi_open ) {
259 rc = be->bd_info->bi_open( be->bd_info );
262 LDAP_LOG( BACKEND, CRIT, "backend_startup: bi_open failed!\n", 0, 0, 0 );
264 Debug( LDAP_DEBUG_ANY,
265 "backend_startup: bi_open failed!\n",
273 if ( be->bd_info->bi_db_open ) {
274 rc = be->bd_info->bi_db_open( be );
277 LDAP_LOG( BACKEND, CRIT,
278 "backend_startup: bi_db_open failed! (%d)\n", rc, 0, 0 );
280 Debug( LDAP_DEBUG_ANY,
281 "backend_startup: bi_db_open failed! (%d)\n",
291 /* open each backend type */
292 for( i = 0; i < nBackendInfo; i++ ) {
293 if( backendInfo[i].bi_nDB == 0) {
294 /* no database of this type, don't open */
298 if( backendInfo[i].bi_open ) {
299 rc = backendInfo[i].bi_open(
303 LDAP_LOG( BACKEND, CRIT,
304 "backend_startup: bi_open %d failed!\n", i, 0, 0 );
306 Debug( LDAP_DEBUG_ANY,
307 "backend_startup: bi_open %d failed!\n",
315 /* open each backend database */
316 for( i = 0; i < nBackendDB; i++ ) {
317 /* append global access controls */
318 acl_append( &backendDB[i].be_acl, global_acl );
320 if ( backendDB[i].bd_info->bi_db_open ) {
321 rc = backendDB[i].bd_info->bi_db_open(
325 LDAP_LOG( BACKEND, CRIT,
326 "backend_startup: bi_db_open(%d) failed! (%d)\n", i, rc, 0 );
328 Debug( LDAP_DEBUG_ANY,
329 "backend_startup: bi_db_open(%d) failed! (%d)\n",
340 int backend_num( Backend *be )
344 if( be == NULL ) return -1;
346 for( i = 0; i < nBackendDB; i++ ) {
347 if( be == &backendDB[i] ) return i;
352 int backend_shutdown( Backend *be )
358 /* shutdown a specific backend database */
360 if ( be->bd_info->bi_nDB == 0 ) {
361 /* no database of this type, we never opened it */
365 if ( be->bd_info->bi_db_close ) {
366 be->bd_info->bi_db_close( be );
369 if( be->bd_info->bi_close ) {
370 be->bd_info->bi_close( be->bd_info );
376 /* close each backend database */
377 for( i = 0; i < nBackendDB; i++ ) {
378 if ( backendDB[i].bd_info->bi_db_close ) {
379 backendDB[i].bd_info->bi_db_close(
385 LDAP_LOG( BACKEND, NOTICE,
386 "backend_shutdown: bi_close %s failed!\n",
387 backendDB[i].be_type, 0, 0 );
389 Debug( LDAP_DEBUG_ANY,
390 "backend_close: bi_close %s failed!\n",
391 backendDB[i].be_type, 0, 0 );
396 /* close each backend type */
397 for( i = 0; i < nBackendInfo; i++ ) {
398 if( backendInfo[i].bi_nDB == 0 ) {
399 /* no database of this type */
403 if( backendInfo[i].bi_close ) {
404 backendInfo[i].bi_close(
412 int backend_destroy(void)
417 /* destroy each backend database */
418 for( i = 0, bd = backendDB; i < nBackendDB; i++, bd++ ) {
419 if ( bd->bd_info->bi_db_destroy ) {
420 bd->bd_info->bi_db_destroy( bd );
422 ber_bvarray_free( bd->be_suffix );
423 ber_bvarray_free( bd->be_nsuffix );
424 if ( bd->be_rootdn.bv_val ) free( bd->be_rootdn.bv_val );
425 if ( bd->be_rootndn.bv_val ) free( bd->be_rootndn.bv_val );
426 if ( bd->be_rootpw.bv_val ) free( bd->be_rootpw.bv_val );
427 acl_destroy( bd->be_acl, global_acl );
431 /* destroy each backend type */
432 for( i = 0; i < nBackendInfo; i++ ) {
433 if( backendInfo[i].bi_destroy ) {
434 backendInfo[i].bi_destroy(
440 if (backendInfo != binfo) {
443 #endif /* SLAPD_MODULES */
451 BackendInfo* backend_info(const char *type)
455 /* search for the backend type */
456 for( i = 0; i < nBackendInfo; i++ ) {
457 if( strcasecmp(backendInfo[i].bi_type, type) == 0 ) {
458 return &backendInfo[i];
472 BackendInfo *bi = backend_info(type);
476 fprintf( stderr, "Unrecognized database type (%s)\n", type );
480 backendDB = (BackendDB *) ch_realloc(
482 (nBackendDB + 1) * sizeof(Backend) );
484 memset( &backendDB[nbackends], '\0', sizeof(Backend) );
486 be = &backends[nbackends++];
489 be->be_def_limit = deflimit;
490 be->be_dfltaccess = global_default_access;
492 be->be_restrictops = global_restrictops;
493 be->be_requires = global_requires;
494 be->be_ssf_set = global_ssf_set;
496 /* assign a default depth limit for alias deref */
497 be->be_max_deref_depth = SLAPD_DEFAULT_MAXDEREFDEPTH;
500 rc = bi->bi_db_init( be );
504 fprintf( stderr, "database init failed (%s)\n", type );
518 for ( i = 0; i < nbackends; i++ ) {
519 if ( backends[i].bd_info->bi_db_close ) {
520 (*backends[i].bd_info->bi_db_close)( &backends[i] );
532 ber_len_t len, dnlen = dn->bv_len;
535 for ( i = 0; i < nbackends; i++ ) {
536 for ( j = 0; backends[i].be_nsuffix != NULL &&
537 backends[i].be_nsuffix[j].bv_val != NULL; j++ )
539 if ( ( SLAP_GLUE_SUBORDINATE( &backends[i] ) )
545 len = backends[i].be_nsuffix[j].bv_len;
548 /* suffix is longer than DN */
553 * input DN is normalized, so the separator check
554 * need not look at escaping
556 if ( len && len < dnlen &&
557 !DN_SEPARATOR( dn->bv_val[(dnlen-len)-1] ))
562 if ( strcmp( backends[i].be_nsuffix[j].bv_val,
563 &dn->bv_val[dnlen-len] ) == 0 )
568 if( manageDSAit && len == dnlen ) {
585 struct berval *bvsuffix
590 for ( i = 0; be->be_nsuffix != NULL && be->be_nsuffix[i].bv_val != NULL; i++ ) {
591 if ( bvmatch( &be->be_nsuffix[i], bvsuffix ) ) {
600 be_isroot( Backend *be, struct berval *ndn )
602 if ( !ndn->bv_len ) {
606 if ( !be->be_rootndn.bv_len ) {
610 return dn_match( &be->be_rootndn, ndn );
614 be_isupdate( Backend *be, struct berval *ndn )
616 if ( !ndn->bv_len ) {
620 if ( !be->be_update_ndn.bv_len ) {
624 return dn_match( &be->be_update_ndn, ndn );
628 be_root_dn( Backend *be )
630 return &be->be_rootdn;
634 be_isroot_pw( Backend *be,
637 struct berval *cred )
641 if ( ! be_isroot( be, ndn ) ) {
645 if( be->be_rootpw.bv_len == 0 ) {
649 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
650 ldap_pvt_thread_mutex_lock( &passwd_mutex );
652 lutil_passwd_sasl_conn = conn->c_sasl_context;
656 result = lutil_passwd( &be->be_rootpw, cred, NULL );
658 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
660 lutil_passwd_sasl_conn = NULL;
662 ldap_pvt_thread_mutex_unlock( &passwd_mutex );
676 if ( be->be_release ) {
677 /* free and release entry from backend */
678 return be->be_release( be, conn, op, e, rw );
693 #if defined( LDAP_SLAPI )
694 Slapi_PBlock *pb = op->o_pb;
697 slapi_x_connection_set_pb( pb, conn );
698 slapi_x_operation_set_pb( pb, op );
699 #endif /* defined( LDAP_SLAPI ) */
701 for ( i = 0; i < nbackends; i++ ) {
702 #if defined( LDAP_SLAPI )
703 slapi_pblock_set( pb, SLAPI_BACKEND, (void *)&backends[i] );
704 rc = doPluginFNs( &backends[i], SLAPI_PLUGIN_PRE_UNBIND_FN,
705 (Slapi_PBlock *)pb );
708 * A preoperation plugin failure will abort the
712 LDAP_LOG( OPERATION, INFO, "do_bind: Unbind preoperation plugin "
713 "failed\n", 0, 0, 0);
715 Debug(LDAP_DEBUG_TRACE, "do_bind: Unbind preoperation plugin "
716 "failed.\n", 0, 0, 0);
720 #endif /* defined( LDAP_SLAPI ) */
722 if ( backends[i].be_unbind ) {
723 (*backends[i].be_unbind)( &backends[i], conn, op );
726 #if defined( LDAP_SLAPI )
727 if ( doPluginFNs( &backends[i], SLAPI_PLUGIN_POST_UNBIND_FN,
728 (Slapi_PBlock *)pb ) != 0 ) {
730 LDAP_LOG( OPERATION, INFO, "do_unbind: Unbind postoperation plugins "
731 "failed\n", 0, 0, 0);
733 Debug(LDAP_DEBUG_TRACE, "do_unbind: Unbind postoperation plugins "
734 "failed.\n", 0, 0, 0);
737 #endif /* defined( LDAP_SLAPI ) */
744 backend_connection_init(
750 for ( i = 0; i < nbackends; i++ ) {
751 if ( backends[i].be_connection_init ) {
752 (*backends[i].be_connection_init)( &backends[i], conn);
760 backend_connection_destroy(
766 for ( i = 0; i < nbackends; i++ ) {
767 if ( backends[i].be_connection_destroy ) {
768 (*backends[i].be_connection_destroy)( &backends[i], conn);
776 backend_check_controls(
782 LDAPControl **ctrls = op->o_ctrls;
784 if( ctrls == NULL ) return LDAP_SUCCESS;
786 for( ; *ctrls != NULL ; ctrls++ ) {
787 if( (*ctrls)->ldctl_iscritical &&
788 !ldap_charray_inlist( be->be_controls, (*ctrls)->ldctl_oid ) )
790 *text = "control unavailable in context";
791 return LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
799 backend_check_restrictions(
803 struct berval *opdata,
807 slap_mask_t restrictops;
808 slap_mask_t requires;
816 rc = backend_check_controls( be, conn, op, text );
818 if( rc != LDAP_SUCCESS ) {
822 restrictops = be->be_restrictops;
823 requires = be->be_requires;
824 ssf = &be->be_ssf_set;
827 restrictops = global_restrictops;
828 requires = global_requires;
829 ssf = &global_ssf_set;
832 switch( op->o_tag ) {
834 opflag = SLAP_RESTRICT_OP_ADD;
838 opflag = SLAP_RESTRICT_OP_BIND;
841 case LDAP_REQ_COMPARE:
842 opflag = SLAP_RESTRICT_OP_COMPARE;
844 case LDAP_REQ_DELETE:
846 opflag = SLAP_RESTRICT_OP_DELETE;
848 case LDAP_REQ_EXTENDED:
849 opflag = SLAP_RESTRICT_OP_EXTENDED;
852 /* treat unspecified as a modify */
853 opflag = SLAP_RESTRICT_OP_MODIFY;
859 if( bvmatch( opdata, &slap_EXOP_START_TLS ) ) {
867 if( bvmatch( opdata, &slap_EXOP_WHOAMI ) ) {
872 #ifdef LDAP_EXOP_X_CANCEL
874 if ( bvmatch( opdata, &slap_EXOP_CANCEL ) ) {
880 /* treat everything else as a modify */
881 opflag = SLAP_RESTRICT_OP_MODIFY;
885 case LDAP_REQ_MODIFY:
887 opflag = SLAP_RESTRICT_OP_MODIFY;
889 case LDAP_REQ_RENAME:
891 opflag = SLAP_RESTRICT_OP_RENAME;
893 case LDAP_REQ_SEARCH:
894 opflag = SLAP_RESTRICT_OP_SEARCH;
896 case LDAP_REQ_UNBIND:
901 *text = "restrict operations internal error";
906 /* these checks don't apply to StartTLS */
908 if( op->o_transport_ssf < ssf->sss_transport ) {
909 *text = "transport confidentiality required";
910 return LDAP_CONFIDENTIALITY_REQUIRED;
913 if( op->o_tls_ssf < ssf->sss_tls ) {
914 *text = "TLS confidentiality required";
915 return LDAP_CONFIDENTIALITY_REQUIRED;
919 if( op->o_tag == LDAP_REQ_BIND && opdata == NULL ) {
920 /* simple bind specific check */
921 if( op->o_ssf < ssf->sss_simple_bind ) {
922 *text = "confidentiality required";
923 return LDAP_CONFIDENTIALITY_REQUIRED;
927 if( op->o_tag != LDAP_REQ_BIND || opdata == NULL ) {
928 /* these checks don't apply to SASL bind */
930 if( op->o_sasl_ssf < ssf->sss_sasl ) {
931 *text = "SASL confidentiality required";
932 return LDAP_CONFIDENTIALITY_REQUIRED;
935 if( op->o_ssf < ssf->sss_ssf ) {
936 *text = "confidentiality required";
937 return LDAP_CONFIDENTIALITY_REQUIRED;
942 if( op->o_transport_ssf < ssf->sss_update_transport ) {
943 *text = "transport update confidentiality required";
944 return LDAP_CONFIDENTIALITY_REQUIRED;
947 if( op->o_tls_ssf < ssf->sss_update_tls ) {
948 *text = "TLS update confidentiality required";
949 return LDAP_CONFIDENTIALITY_REQUIRED;
952 if( op->o_sasl_ssf < ssf->sss_update_sasl ) {
953 *text = "SASL update confidentiality required";
954 return LDAP_CONFIDENTIALITY_REQUIRED;
957 if( op->o_ssf < ssf->sss_update_ssf ) {
958 *text = "update confidentiality required";
959 return LDAP_CONFIDENTIALITY_REQUIRED;
962 if( !( global_allows & SLAP_ALLOW_UPDATE_ANON ) &&
963 op->o_ndn.bv_len == 0 )
965 *text = "modifications require authentication";
966 return LDAP_STRONG_AUTH_REQUIRED;
969 #ifdef SLAP_X_LISTENER_MOD
970 if ( conn->c_listener && ! ( conn->c_listener->sl_perms & S_IWUSR ) ) {
971 /* no "w" mode means readonly */
972 *text = "modifications not allowed on this listener";
973 return LDAP_UNWILLING_TO_PERFORM;
975 #endif /* SLAP_X_LISTENER_MOD */
980 /* these checks don't apply to Bind, StartTLS, or Unbind */
982 if( requires & SLAP_REQUIRE_STRONG ) {
983 /* should check mechanism */
984 if( ( op->o_transport_ssf < ssf->sss_transport
985 && op->o_authmech.bv_len == 0 ) || op->o_dn.bv_len == 0 )
987 *text = "strong authentication required";
988 return LDAP_STRONG_AUTH_REQUIRED;
992 if( requires & SLAP_REQUIRE_SASL ) {
993 if( op->o_authmech.bv_len == 0 || op->o_dn.bv_len == 0 ) {
994 *text = "SASL authentication required";
995 return LDAP_STRONG_AUTH_REQUIRED;
999 if( requires & SLAP_REQUIRE_AUTHC ) {
1000 if( op->o_dn.bv_len == 0 ) {
1001 *text = "authentication required";
1002 return LDAP_UNWILLING_TO_PERFORM;
1006 if( requires & SLAP_REQUIRE_BIND ) {
1008 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1009 version = conn->c_protocol;
1010 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1013 /* no bind has occurred */
1014 *text = "BIND required";
1015 return LDAP_OPERATIONS_ERROR;
1019 if( requires & SLAP_REQUIRE_LDAP_V3 ) {
1020 if( op->o_protocol < LDAP_VERSION3 ) {
1021 /* no bind has occurred */
1022 *text = "operation restricted to LDAPv3 clients";
1023 return LDAP_OPERATIONS_ERROR;
1027 #ifdef SLAP_X_LISTENER_MOD
1028 if ( !starttls && op->o_dn.bv_len == 0 ) {
1029 if ( conn->c_listener && ! ( conn->c_listener->sl_perms & S_IXUSR ) ) {
1030 /* no "x" mode means bind required */
1031 *text = "bind required on this listener";
1032 return LDAP_STRONG_AUTH_REQUIRED;
1036 if ( !starttls && !updateop ) {
1037 if ( conn->c_listener && ! ( conn->c_listener->sl_perms & S_IRUSR ) ) {
1038 /* no "r" mode means no read */
1039 *text = "read not allowed on this listener";
1040 return LDAP_UNWILLING_TO_PERFORM;
1043 #endif /* SLAP_X_LISTENER_MOD */
1047 if( restrictops & opflag ) {
1048 if( restrictops == SLAP_RESTRICT_OP_READS ) {
1049 *text = "read operations restricted";
1051 *text = "operation restricted";
1053 return LDAP_UNWILLING_TO_PERFORM;
1056 return LDAP_SUCCESS;
1059 int backend_check_referrals(
1064 struct berval *ndn )
1066 int rc = LDAP_SUCCESS;
1068 if( be->be_chk_referrals ) {
1071 rc = be->be_chk_referrals( be,
1072 conn, op, dn, ndn, &text );
1074 if( rc != LDAP_SUCCESS && rc != LDAP_REFERRAL ) {
1075 send_ldap_result( conn, op, rc,
1076 NULL, text, NULL, NULL );
1089 struct berval *gr_ndn,
1090 struct berval *op_ndn,
1091 ObjectClass *group_oc,
1092 AttributeDescription *group_at
1097 if ( op->o_abandon ) return SLAPD_ABANDON;
1099 if ( !dn_match( &target->e_nname, gr_ndn ) ) {
1100 /* we won't attempt to send it to a different backend */
1102 be = select_backend( gr_ndn, 0, 0 );
1105 return LDAP_NO_SUCH_OBJECT;
1109 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1111 for (g = conn->c_groups; g; g=g->ga_next) {
1112 if (g->ga_be != be || g->ga_oc != group_oc ||
1113 g->ga_at != group_at || g->ga_len != gr_ndn->bv_len)
1115 if (strcmp( g->ga_ndn, gr_ndn->bv_val ) == 0)
1119 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1125 if( be->be_group ) {
1126 int res = be->be_group( be, conn, op,
1127 target, gr_ndn, op_ndn,
1128 group_oc, group_at );
1130 if ( op->o_tag != LDAP_REQ_BIND && !op->o_do_not_cache ) {
1131 g = ch_malloc(sizeof(GroupAssertion) + gr_ndn->bv_len);
1133 g->ga_oc = group_oc;
1134 g->ga_at = group_at;
1136 g->ga_len = gr_ndn->bv_len;
1137 strcpy(g->ga_ndn, gr_ndn->bv_val);
1138 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1139 g->ga_next = conn->c_groups;
1141 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1147 return LDAP_UNWILLING_TO_PERFORM;
1157 AttributeDescription *entry_at,
1161 if ( target == NULL || !dn_match( &target->e_nname, edn ) ) {
1162 /* we won't attempt to send it to a different backend */
1164 be = select_backend( edn, 0, 0 );
1167 return LDAP_NO_SUCH_OBJECT;
1171 if( be->be_attribute ) {
1172 return be->be_attribute( be, conn, op, target, edn,
1176 return LDAP_UNWILLING_TO_PERFORM;
1179 Attribute *backend_operational(
1184 AttributeName *attrs,
1187 Attribute *a = NULL, **ap = &a;
1190 * If operational attributes (allegedly) are required,
1191 * and the backend supports specific operational attributes,
1192 * add them to the attribute list
1194 if ( opattrs || ( attrs &&
1195 ad_inlist( slap_schema.si_ad_subschemaSubentry, attrs )) ) {
1196 *ap = slap_operational_subschemaSubentry( be );
1197 ap = &(*ap)->a_next;
1200 if ( ( opattrs || attrs ) && be && be->be_operational != NULL ) {
1201 ( void )be->be_operational( be, conn, op, e, attrs, opattrs, ap );