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 &&
569 !SLAP_GLUE_SUBORDINATE( be ) ) {
586 struct berval *bvsuffix
591 for ( i = 0; be->be_nsuffix != NULL && be->be_nsuffix[i].bv_val != NULL; i++ ) {
592 if ( bvmatch( &be->be_nsuffix[i], bvsuffix ) ) {
601 be_isroot( Backend *be, struct berval *ndn )
603 if ( !ndn->bv_len ) {
607 if ( !be->be_rootndn.bv_len ) {
611 return dn_match( &be->be_rootndn, ndn );
615 be_isupdate( Backend *be, struct berval *ndn )
617 if ( !ndn->bv_len ) {
621 if ( !be->be_update_ndn.bv_len ) {
625 return dn_match( &be->be_update_ndn, ndn );
629 be_root_dn( Backend *be )
631 return &be->be_rootdn;
635 be_isroot_pw( Backend *be,
638 struct berval *cred )
643 if ( ! be_isroot( be, ndn ) ) {
647 if( be->be_rootpw.bv_len == 0 ) {
651 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
652 ldap_pvt_thread_mutex_lock( &passwd_mutex );
654 lutil_passwd_sasl_conn = conn->c_sasl_context;
658 result = lutil_passwd( &be->be_rootpw, cred, NULL, NULL );
660 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
662 lutil_passwd_sasl_conn = NULL;
664 ldap_pvt_thread_mutex_unlock( &passwd_mutex );
678 if ( be->be_release ) {
679 /* free and release entry from backend */
680 return be->be_release( be, conn, op, e, rw );
695 #if defined( LDAP_SLAPI )
696 Slapi_PBlock *pb = op->o_pb;
699 slapi_x_connection_set_pb( pb, conn );
700 slapi_x_operation_set_pb( pb, op );
701 #endif /* defined( LDAP_SLAPI ) */
703 for ( i = 0; i < nbackends; i++ ) {
704 #if defined( LDAP_SLAPI )
705 slapi_pblock_set( pb, SLAPI_BACKEND, (void *)&backends[i] );
706 rc = doPluginFNs( &backends[i], SLAPI_PLUGIN_PRE_UNBIND_FN,
707 (Slapi_PBlock *)pb );
710 * A preoperation plugin failure will abort the
714 LDAP_LOG( OPERATION, INFO, "do_bind: Unbind preoperation plugin "
715 "failed\n", 0, 0, 0);
717 Debug(LDAP_DEBUG_TRACE, "do_bind: Unbind preoperation plugin "
718 "failed.\n", 0, 0, 0);
722 #endif /* defined( LDAP_SLAPI ) */
724 if ( backends[i].be_unbind ) {
725 (*backends[i].be_unbind)( &backends[i], conn, op );
728 #if defined( LDAP_SLAPI )
729 if ( doPluginFNs( &backends[i], SLAPI_PLUGIN_POST_UNBIND_FN,
730 (Slapi_PBlock *)pb ) != 0 ) {
732 LDAP_LOG( OPERATION, INFO, "do_unbind: Unbind postoperation plugins "
733 "failed\n", 0, 0, 0);
735 Debug(LDAP_DEBUG_TRACE, "do_unbind: Unbind postoperation plugins "
736 "failed.\n", 0, 0, 0);
739 #endif /* defined( LDAP_SLAPI ) */
746 backend_connection_init(
752 for ( i = 0; i < nbackends; i++ ) {
753 if ( backends[i].be_connection_init ) {
754 (*backends[i].be_connection_init)( &backends[i], conn);
762 backend_connection_destroy(
768 for ( i = 0; i < nbackends; i++ ) {
769 if ( backends[i].be_connection_destroy ) {
770 (*backends[i].be_connection_destroy)( &backends[i], conn);
778 backend_check_controls(
784 LDAPControl **ctrls = op->o_ctrls;
786 if( ctrls == NULL ) return LDAP_SUCCESS;
788 for( ; *ctrls != NULL ; ctrls++ ) {
789 if( (*ctrls)->ldctl_iscritical &&
790 !ldap_charray_inlist( be->be_controls, (*ctrls)->ldctl_oid ) )
792 *text = "control unavailable in context";
793 return LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
801 backend_check_restrictions(
805 struct berval *opdata,
809 slap_mask_t restrictops;
810 slap_mask_t requires;
818 rc = backend_check_controls( be, conn, op, text );
820 if( rc != LDAP_SUCCESS ) {
824 restrictops = be->be_restrictops;
825 requires = be->be_requires;
826 ssf = &be->be_ssf_set;
829 restrictops = global_restrictops;
830 requires = global_requires;
831 ssf = &global_ssf_set;
834 switch( op->o_tag ) {
836 opflag = SLAP_RESTRICT_OP_ADD;
840 opflag = SLAP_RESTRICT_OP_BIND;
843 case LDAP_REQ_COMPARE:
844 opflag = SLAP_RESTRICT_OP_COMPARE;
846 case LDAP_REQ_DELETE:
848 opflag = SLAP_RESTRICT_OP_DELETE;
850 case LDAP_REQ_EXTENDED:
851 opflag = SLAP_RESTRICT_OP_EXTENDED;
854 /* treat unspecified as a modify */
855 opflag = SLAP_RESTRICT_OP_MODIFY;
861 struct berval bv = BER_BVC( LDAP_EXOP_START_TLS );
862 if( bvmatch( opdata, &bv ) ) {
870 struct berval bv = BER_BVC( LDAP_EXOP_X_WHO_AM_I );
871 if( bvmatch( opdata, &bv ) ) {
876 #ifdef LDAP_EXOP_X_CANCEL
878 struct berval bv = BER_BVC( LDAP_EXOP_X_CANCEL );
879 if ( bvmatch( opdata, &bv ) ) {
885 /* treat everything else as a modify */
886 opflag = SLAP_RESTRICT_OP_MODIFY;
890 case LDAP_REQ_MODIFY:
892 opflag = SLAP_RESTRICT_OP_MODIFY;
894 case LDAP_REQ_RENAME:
896 opflag = SLAP_RESTRICT_OP_RENAME;
898 case LDAP_REQ_SEARCH:
899 opflag = SLAP_RESTRICT_OP_SEARCH;
901 case LDAP_REQ_UNBIND:
906 *text = "restrict operations internal error";
911 /* these checks don't apply to StartTLS */
913 if( op->o_transport_ssf < ssf->sss_transport ) {
914 *text = "transport confidentiality required";
915 return LDAP_CONFIDENTIALITY_REQUIRED;
918 if( op->o_tls_ssf < ssf->sss_tls ) {
919 *text = "TLS confidentiality required";
920 return LDAP_CONFIDENTIALITY_REQUIRED;
924 if( op->o_tag == LDAP_REQ_BIND && opdata == NULL ) {
925 /* simple bind specific check */
926 if( op->o_ssf < ssf->sss_simple_bind ) {
927 *text = "confidentiality required";
928 return LDAP_CONFIDENTIALITY_REQUIRED;
932 if( op->o_tag != LDAP_REQ_BIND || opdata == NULL ) {
933 /* these checks don't apply to SASL bind */
935 if( op->o_sasl_ssf < ssf->sss_sasl ) {
936 *text = "SASL confidentiality required";
937 return LDAP_CONFIDENTIALITY_REQUIRED;
940 if( op->o_ssf < ssf->sss_ssf ) {
941 *text = "confidentiality required";
942 return LDAP_CONFIDENTIALITY_REQUIRED;
947 if( op->o_transport_ssf < ssf->sss_update_transport ) {
948 *text = "transport update confidentiality required";
949 return LDAP_CONFIDENTIALITY_REQUIRED;
952 if( op->o_tls_ssf < ssf->sss_update_tls ) {
953 *text = "TLS update confidentiality required";
954 return LDAP_CONFIDENTIALITY_REQUIRED;
957 if( op->o_sasl_ssf < ssf->sss_update_sasl ) {
958 *text = "SASL update confidentiality required";
959 return LDAP_CONFIDENTIALITY_REQUIRED;
962 if( op->o_ssf < ssf->sss_update_ssf ) {
963 *text = "update confidentiality required";
964 return LDAP_CONFIDENTIALITY_REQUIRED;
967 if( !( global_allows & SLAP_ALLOW_UPDATE_ANON ) &&
968 op->o_ndn.bv_len == 0 )
970 *text = "modifications require authentication";
971 return LDAP_STRONG_AUTH_REQUIRED;
974 #ifdef SLAP_X_LISTENER_MOD
975 if ( ! ( conn->c_listener->sl_perms & S_IWUSR ) ) {
976 /* no "w" mode means readonly */
977 *text = "modifications not allowed on this listener";
978 return LDAP_UNWILLING_TO_PERFORM;
980 #endif /* SLAP_X_LISTENER_MOD */
985 /* these checks don't apply to Bind, StartTLS, or Unbind */
987 if( requires & SLAP_REQUIRE_STRONG ) {
988 /* should check mechanism */
989 if( ( op->o_transport_ssf < ssf->sss_transport
990 && op->o_authtype == LDAP_AUTH_SIMPLE ) || op->o_dn.bv_len == 0 )
992 *text = "strong authentication required";
993 return LDAP_STRONG_AUTH_REQUIRED;
997 if( requires & SLAP_REQUIRE_SASL ) {
998 if( op->o_authtype != LDAP_AUTH_SASL || op->o_dn.bv_len == 0 ) {
999 *text = "SASL authentication required";
1000 return LDAP_STRONG_AUTH_REQUIRED;
1004 if( requires & SLAP_REQUIRE_AUTHC ) {
1005 if( op->o_dn.bv_len == 0 ) {
1006 *text = "authentication required";
1007 return LDAP_UNWILLING_TO_PERFORM;
1011 if( requires & SLAP_REQUIRE_BIND ) {
1013 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1014 version = conn->c_protocol;
1015 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1018 /* no bind has occurred */
1019 *text = "BIND required";
1020 return LDAP_OPERATIONS_ERROR;
1024 if( requires & SLAP_REQUIRE_LDAP_V3 ) {
1025 if( op->o_protocol < LDAP_VERSION3 ) {
1026 /* no bind has occurred */
1027 *text = "operation restricted to LDAPv3 clients";
1028 return LDAP_OPERATIONS_ERROR;
1032 #ifdef SLAP_X_LISTENER_MOD
1033 if ( !starttls && op->o_dn.bv_len == 0 ) {
1034 if ( ! ( conn->c_listener->sl_perms & S_IXUSR ) ) {
1035 /* no "x" mode means bind required */
1036 *text = "bind required on this listener";
1037 return LDAP_STRONG_AUTH_REQUIRED;
1041 if ( !starttls && !updateop ) {
1042 if ( ! ( conn->c_listener->sl_perms & S_IRUSR ) ) {
1043 /* no "r" mode means no read */
1044 *text = "read not allowed on this listener";
1045 return LDAP_UNWILLING_TO_PERFORM;
1048 #endif /* SLAP_X_LISTENER_MOD */
1052 if( restrictops & opflag ) {
1053 if( restrictops == SLAP_RESTRICT_OP_READS ) {
1054 *text = "read operations restricted";
1056 *text = "operation restricted";
1058 return LDAP_UNWILLING_TO_PERFORM;
1061 return LDAP_SUCCESS;
1064 int backend_check_referrals(
1069 struct berval *ndn )
1071 int rc = LDAP_SUCCESS;
1073 if( be->be_chk_referrals ) {
1076 rc = be->be_chk_referrals( be,
1077 conn, op, dn, ndn, &text );
1079 if( rc != LDAP_SUCCESS && rc != LDAP_REFERRAL ) {
1080 send_ldap_result( conn, op, rc,
1081 NULL, text, NULL, NULL );
1094 struct berval *gr_ndn,
1095 struct berval *op_ndn,
1096 ObjectClass *group_oc,
1097 AttributeDescription *group_at
1102 if ( op->o_abandon ) return SLAPD_ABANDON;
1104 if ( !dn_match( &target->e_nname, gr_ndn ) ) {
1105 /* we won't attempt to send it to a different backend */
1107 be = select_backend( gr_ndn, 0, 0 );
1110 return LDAP_NO_SUCH_OBJECT;
1114 for (g = op->o_groups; g; g=g->ga_next) {
1115 if (g->ga_be != be || g->ga_oc != group_oc ||
1116 g->ga_at != group_at || g->ga_len != gr_ndn->bv_len)
1118 if (strcmp( g->ga_ndn, gr_ndn->bv_val ) == 0)
1126 if( be->be_group ) {
1127 int res = be->be_group( be, conn, op,
1128 target, gr_ndn, op_ndn,
1129 group_oc, group_at );
1131 if ( op->o_tag != LDAP_REQ_BIND && !op->o_do_not_cache ) {
1132 g = ch_malloc(sizeof(GroupAssertion) + gr_ndn->bv_len);
1134 g->ga_oc = group_oc;
1135 g->ga_at = group_at;
1137 g->ga_len = gr_ndn->bv_len;
1138 strcpy(g->ga_ndn, gr_ndn->bv_val);
1139 g->ga_next = op->o_groups;
1146 return LDAP_UNWILLING_TO_PERFORM;
1156 AttributeDescription *entry_at,
1160 if ( target == NULL || !dn_match( &target->e_nname, edn ) ) {
1161 /* we won't attempt to send it to a different backend */
1163 be = select_backend( edn, 0, 0 );
1166 return LDAP_NO_SUCH_OBJECT;
1170 if( be->be_attribute ) {
1171 return be->be_attribute( be, conn, op, target, edn,
1175 return LDAP_UNWILLING_TO_PERFORM;
1178 Attribute *backend_operational(
1183 AttributeName *attrs,
1186 Attribute *a = NULL, **ap = &a;
1189 * If operational attributes (allegedly) are required,
1190 * and the backend supports specific operational attributes,
1191 * add them to the attribute list
1193 if ( opattrs || ( attrs &&
1194 ad_inlist( slap_schema.si_ad_subschemaSubentry, attrs )) ) {
1195 *ap = slap_operational_subschemaSubentry( be );
1196 ap = &(*ap)->a_next;
1199 if ( ( opattrs || attrs ) && be && be->be_operational != NULL ) {
1200 ( void )be->be_operational( be, conn, op, e, attrs, opattrs, ap );