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 #ifndef SLAPD_MULTIMASTER
318 if ( backendDB[i].be_update_ndn.bv_val && (
319 !backendDB[i].be_update_refs &&
320 !default_referral ) ) {
322 LDAP_LOG( BACKEND, CRIT,
323 "backend_startup: slave \"%s\" updateref missing\n",
324 backendDB[i].be_suffix[0].bv_val, 0, 0 );
327 Debug( LDAP_DEBUG_ANY,
328 "backend_startup: slave \"%s\" updateref missing\n",
329 backendDB[i].be_suffix[0].bv_val, 0, 0 );
335 /* append global access controls */
336 acl_append( &backendDB[i].be_acl, global_acl );
338 if ( backendDB[i].bd_info->bi_db_open ) {
339 rc = backendDB[i].bd_info->bi_db_open(
343 LDAP_LOG( BACKEND, CRIT,
344 "backend_startup: bi_db_open(%d) failed! (%d)\n", i, rc, 0 );
346 Debug( LDAP_DEBUG_ANY,
347 "backend_startup: bi_db_open(%d) failed! (%d)\n",
358 int backend_num( Backend *be )
362 if( be == NULL ) return -1;
364 for( i = 0; i < nBackendDB; i++ ) {
365 if( be == &backendDB[i] ) return i;
370 int backend_shutdown( Backend *be )
376 /* shutdown a specific backend database */
378 if ( be->bd_info->bi_nDB == 0 ) {
379 /* no database of this type, we never opened it */
383 if ( be->bd_info->bi_db_close ) {
384 be->bd_info->bi_db_close( be );
387 if( be->bd_info->bi_close ) {
388 be->bd_info->bi_close( be->bd_info );
394 /* close each backend database */
395 for( i = 0; i < nBackendDB; i++ ) {
396 if ( backendDB[i].bd_info->bi_db_close ) {
397 backendDB[i].bd_info->bi_db_close(
403 LDAP_LOG( BACKEND, NOTICE,
404 "backend_shutdown: bi_close %s failed!\n",
405 backendDB[i].be_type, 0, 0 );
407 Debug( LDAP_DEBUG_ANY,
408 "backend_close: bi_close %s failed!\n",
409 backendDB[i].be_type, 0, 0 );
414 /* close each backend type */
415 for( i = 0; i < nBackendInfo; i++ ) {
416 if( backendInfo[i].bi_nDB == 0 ) {
417 /* no database of this type */
421 if( backendInfo[i].bi_close ) {
422 backendInfo[i].bi_close(
430 int backend_destroy(void)
435 /* destroy each backend database */
436 for( i = 0, bd = backendDB; i < nBackendDB; i++, bd++ ) {
437 if ( bd->bd_info->bi_db_destroy ) {
438 bd->bd_info->bi_db_destroy( bd );
440 ber_bvarray_free( bd->be_suffix );
441 ber_bvarray_free( bd->be_nsuffix );
442 if ( bd->be_rootdn.bv_val ) free( bd->be_rootdn.bv_val );
443 if ( bd->be_rootndn.bv_val ) free( bd->be_rootndn.bv_val );
444 if ( bd->be_rootpw.bv_val ) free( bd->be_rootpw.bv_val );
445 acl_destroy( bd->be_acl, global_acl );
449 /* destroy each backend type */
450 for( i = 0; i < nBackendInfo; i++ ) {
451 if( backendInfo[i].bi_destroy ) {
452 backendInfo[i].bi_destroy(
458 if (backendInfo != binfo) {
461 #endif /* SLAPD_MODULES */
469 BackendInfo* backend_info(const char *type)
473 /* search for the backend type */
474 for( i = 0; i < nBackendInfo; i++ ) {
475 if( strcasecmp(backendInfo[i].bi_type, type) == 0 ) {
476 return &backendInfo[i];
490 BackendInfo *bi = backend_info(type);
494 fprintf( stderr, "Unrecognized database type (%s)\n", type );
498 backendDB = (BackendDB *) ch_realloc(
500 (nBackendDB + 1) * sizeof(Backend) );
502 memset( &backendDB[nbackends], '\0', sizeof(Backend) );
504 be = &backends[nbackends++];
507 be->be_def_limit = deflimit;
508 be->be_dfltaccess = global_default_access;
510 be->be_restrictops = global_restrictops;
511 be->be_requires = global_requires;
512 be->be_ssf_set = global_ssf_set;
514 /* assign a default depth limit for alias deref */
515 be->be_max_deref_depth = SLAPD_DEFAULT_MAXDEREFDEPTH;
518 rc = bi->bi_db_init( be );
522 fprintf( stderr, "database init failed (%s)\n", type );
536 for ( i = 0; i < nbackends; i++ ) {
537 if ( backends[i].bd_info->bi_db_close ) {
538 (*backends[i].bd_info->bi_db_close)( &backends[i] );
550 ber_len_t len, dnlen = dn->bv_len;
553 for ( i = 0; i < nbackends; i++ ) {
554 for ( j = 0; backends[i].be_nsuffix != NULL &&
555 backends[i].be_nsuffix[j].bv_val != NULL; j++ )
557 if ( ( SLAP_GLUE_SUBORDINATE( &backends[i] ) )
563 len = backends[i].be_nsuffix[j].bv_len;
566 /* suffix is longer than DN */
571 * input DN is normalized, so the separator check
572 * need not look at escaping
574 if ( len && len < dnlen &&
575 !DN_SEPARATOR( dn->bv_val[(dnlen-len)-1] ))
580 if ( strcmp( backends[i].be_nsuffix[j].bv_val,
581 &dn->bv_val[dnlen-len] ) == 0 )
586 if( manageDSAit && len == dnlen &&
587 !SLAP_GLUE_SUBORDINATE( be ) ) {
604 struct berval *bvsuffix
609 for ( i = 0; be->be_nsuffix != NULL && be->be_nsuffix[i].bv_val != NULL; i++ ) {
610 if ( bvmatch( &be->be_nsuffix[i], bvsuffix ) ) {
619 be_isroot( Backend *be, struct berval *ndn )
621 if ( !ndn->bv_len ) {
625 if ( !be->be_rootndn.bv_len ) {
629 return dn_match( &be->be_rootndn, ndn );
633 be_isupdate( Backend *be, struct berval *ndn )
635 if ( !ndn->bv_len ) {
639 if ( !be->be_update_ndn.bv_len ) {
643 return dn_match( &be->be_update_ndn, ndn );
647 be_root_dn( Backend *be )
649 return &be->be_rootdn;
653 be_isroot_pw( Backend *be,
656 struct berval *cred )
661 if ( ! be_isroot( be, ndn ) ) {
665 if( be->be_rootpw.bv_len == 0 ) {
669 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
670 ldap_pvt_thread_mutex_lock( &passwd_mutex );
672 lutil_passwd_sasl_conn = conn->c_sasl_context;
676 result = lutil_passwd( &be->be_rootpw, cred, NULL, NULL );
678 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
680 lutil_passwd_sasl_conn = NULL;
682 ldap_pvt_thread_mutex_unlock( &passwd_mutex );
696 if ( be->be_release ) {
697 /* free and release entry from backend */
698 return be->be_release( be, conn, op, e, rw );
713 #if defined( LDAP_SLAPI )
714 Slapi_PBlock *pb = op->o_pb;
717 slapi_x_connection_set_pb( pb, conn );
718 slapi_x_operation_set_pb( pb, op );
719 #endif /* defined( LDAP_SLAPI ) */
721 for ( i = 0; i < nbackends; i++ ) {
722 #if defined( LDAP_SLAPI )
723 slapi_pblock_set( pb, SLAPI_BACKEND, (void *)&backends[i] );
724 rc = doPluginFNs( &backends[i], SLAPI_PLUGIN_PRE_UNBIND_FN,
725 (Slapi_PBlock *)pb );
728 * A preoperation plugin failure will abort the
732 LDAP_LOG( OPERATION, INFO, "do_bind: Unbind preoperation plugin "
733 "failed\n", 0, 0, 0);
735 Debug(LDAP_DEBUG_TRACE, "do_bind: Unbind preoperation plugin "
736 "failed.\n", 0, 0, 0);
740 #endif /* defined( LDAP_SLAPI ) */
742 if ( backends[i].be_unbind ) {
743 (*backends[i].be_unbind)( &backends[i], conn, op );
746 #if defined( LDAP_SLAPI )
747 if ( doPluginFNs( &backends[i], SLAPI_PLUGIN_POST_UNBIND_FN,
748 (Slapi_PBlock *)pb ) != 0 ) {
750 LDAP_LOG( OPERATION, INFO, "do_unbind: Unbind postoperation plugins "
751 "failed\n", 0, 0, 0);
753 Debug(LDAP_DEBUG_TRACE, "do_unbind: Unbind postoperation plugins "
754 "failed.\n", 0, 0, 0);
757 #endif /* defined( LDAP_SLAPI ) */
764 backend_connection_init(
770 for ( i = 0; i < nbackends; i++ ) {
771 if ( backends[i].be_connection_init ) {
772 (*backends[i].be_connection_init)( &backends[i], conn);
780 backend_connection_destroy(
786 for ( i = 0; i < nbackends; i++ ) {
787 if ( backends[i].be_connection_destroy ) {
788 (*backends[i].be_connection_destroy)( &backends[i], conn);
796 backend_check_controls(
802 LDAPControl **ctrls = op->o_ctrls;
804 if( ctrls == NULL ) return LDAP_SUCCESS;
806 for( ; *ctrls != NULL ; ctrls++ ) {
807 if( (*ctrls)->ldctl_iscritical &&
808 !ldap_charray_inlist( be->be_controls, (*ctrls)->ldctl_oid ) )
810 *text = "control unavailable in context";
811 return LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
819 backend_check_restrictions(
823 struct berval *opdata,
827 slap_mask_t restrictops;
828 slap_mask_t requires;
836 rc = backend_check_controls( be, conn, op, text );
838 if( rc != LDAP_SUCCESS ) {
842 restrictops = be->be_restrictops;
843 requires = be->be_requires;
844 ssf = &be->be_ssf_set;
847 restrictops = global_restrictops;
848 requires = global_requires;
849 ssf = &global_ssf_set;
852 switch( op->o_tag ) {
854 opflag = SLAP_RESTRICT_OP_ADD;
858 opflag = SLAP_RESTRICT_OP_BIND;
861 case LDAP_REQ_COMPARE:
862 opflag = SLAP_RESTRICT_OP_COMPARE;
864 case LDAP_REQ_DELETE:
866 opflag = SLAP_RESTRICT_OP_DELETE;
868 case LDAP_REQ_EXTENDED:
869 opflag = SLAP_RESTRICT_OP_EXTENDED;
872 /* treat unspecified as a modify */
873 opflag = SLAP_RESTRICT_OP_MODIFY;
879 struct berval bv = BER_BVC( LDAP_EXOP_START_TLS );
880 if( bvmatch( opdata, &bv ) ) {
888 struct berval bv = BER_BVC( LDAP_EXOP_X_WHO_AM_I );
889 if( bvmatch( opdata, &bv ) ) {
894 #ifdef LDAP_EXOP_X_CANCEL
896 struct berval bv = BER_BVC( LDAP_EXOP_X_CANCEL );
897 if ( bvmatch( opdata, &bv ) ) {
903 /* treat everything else as a modify */
904 opflag = SLAP_RESTRICT_OP_MODIFY;
908 case LDAP_REQ_MODIFY:
910 opflag = SLAP_RESTRICT_OP_MODIFY;
912 case LDAP_REQ_RENAME:
914 opflag = SLAP_RESTRICT_OP_RENAME;
916 case LDAP_REQ_SEARCH:
917 opflag = SLAP_RESTRICT_OP_SEARCH;
919 case LDAP_REQ_UNBIND:
924 *text = "restrict operations internal error";
929 /* these checks don't apply to StartTLS */
931 if( op->o_transport_ssf < ssf->sss_transport ) {
932 *text = "transport confidentiality required";
933 return LDAP_CONFIDENTIALITY_REQUIRED;
936 if( op->o_tls_ssf < ssf->sss_tls ) {
937 *text = "TLS confidentiality required";
938 return LDAP_CONFIDENTIALITY_REQUIRED;
942 if( op->o_tag == LDAP_REQ_BIND && opdata == NULL ) {
943 /* simple bind specific check */
944 if( op->o_ssf < ssf->sss_simple_bind ) {
945 *text = "confidentiality required";
946 return LDAP_CONFIDENTIALITY_REQUIRED;
950 if( op->o_tag != LDAP_REQ_BIND || opdata == NULL ) {
951 /* these checks don't apply to SASL bind */
953 if( op->o_sasl_ssf < ssf->sss_sasl ) {
954 *text = "SASL confidentiality required";
955 return LDAP_CONFIDENTIALITY_REQUIRED;
958 if( op->o_ssf < ssf->sss_ssf ) {
959 *text = "confidentiality required";
960 return LDAP_CONFIDENTIALITY_REQUIRED;
965 if( op->o_transport_ssf < ssf->sss_update_transport ) {
966 *text = "transport update confidentiality required";
967 return LDAP_CONFIDENTIALITY_REQUIRED;
970 if( op->o_tls_ssf < ssf->sss_update_tls ) {
971 *text = "TLS update confidentiality required";
972 return LDAP_CONFIDENTIALITY_REQUIRED;
975 if( op->o_sasl_ssf < ssf->sss_update_sasl ) {
976 *text = "SASL update confidentiality required";
977 return LDAP_CONFIDENTIALITY_REQUIRED;
980 if( op->o_ssf < ssf->sss_update_ssf ) {
981 *text = "update confidentiality required";
982 return LDAP_CONFIDENTIALITY_REQUIRED;
985 if( !( global_allows & SLAP_ALLOW_UPDATE_ANON ) &&
986 op->o_ndn.bv_len == 0 )
988 *text = "modifications require authentication";
989 return LDAP_STRONG_AUTH_REQUIRED;
992 #ifdef SLAP_X_LISTENER_MOD
993 if ( ! ( conn->c_listener->sl_perms & S_IWUSR ) ) {
994 /* no "w" mode means readonly */
995 *text = "modifications not allowed on this listener";
996 return LDAP_UNWILLING_TO_PERFORM;
998 #endif /* SLAP_X_LISTENER_MOD */
1003 /* these checks don't apply to Bind, StartTLS, or Unbind */
1005 if( requires & SLAP_REQUIRE_STRONG ) {
1006 /* should check mechanism */
1007 if( ( op->o_transport_ssf < ssf->sss_transport
1008 && op->o_authmech.bv_len == 0 ) || op->o_dn.bv_len == 0 )
1010 *text = "strong authentication required";
1011 return LDAP_STRONG_AUTH_REQUIRED;
1015 if( requires & SLAP_REQUIRE_SASL ) {
1016 if( op->o_authmech.bv_len == 0 || op->o_dn.bv_len == 0 ) {
1017 *text = "SASL authentication required";
1018 return LDAP_STRONG_AUTH_REQUIRED;
1022 if( requires & SLAP_REQUIRE_AUTHC ) {
1023 if( op->o_dn.bv_len == 0 ) {
1024 *text = "authentication required";
1025 return LDAP_UNWILLING_TO_PERFORM;
1029 if( requires & SLAP_REQUIRE_BIND ) {
1031 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1032 version = conn->c_protocol;
1033 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1036 /* no bind has occurred */
1037 *text = "BIND required";
1038 return LDAP_OPERATIONS_ERROR;
1042 if( requires & SLAP_REQUIRE_LDAP_V3 ) {
1043 if( op->o_protocol < LDAP_VERSION3 ) {
1044 /* no bind has occurred */
1045 *text = "operation restricted to LDAPv3 clients";
1046 return LDAP_OPERATIONS_ERROR;
1050 #ifdef SLAP_X_LISTENER_MOD
1051 if ( !starttls && op->o_dn.bv_len == 0 ) {
1052 if ( ! ( conn->c_listener->sl_perms & S_IXUSR ) ) {
1053 /* no "x" mode means bind required */
1054 *text = "bind required on this listener";
1055 return LDAP_STRONG_AUTH_REQUIRED;
1059 if ( !starttls && !updateop ) {
1060 if ( ! ( conn->c_listener->sl_perms & S_IRUSR ) ) {
1061 /* no "r" mode means no read */
1062 *text = "read not allowed on this listener";
1063 return LDAP_UNWILLING_TO_PERFORM;
1066 #endif /* SLAP_X_LISTENER_MOD */
1070 if( restrictops & opflag ) {
1071 if( restrictops == SLAP_RESTRICT_OP_READS ) {
1072 *text = "read operations restricted";
1074 *text = "operation restricted";
1076 return LDAP_UNWILLING_TO_PERFORM;
1079 return LDAP_SUCCESS;
1082 int backend_check_referrals(
1087 struct berval *ndn )
1089 int rc = LDAP_SUCCESS;
1091 if( be->be_chk_referrals ) {
1094 rc = be->be_chk_referrals( be,
1095 conn, op, dn, ndn, &text );
1097 if( rc != LDAP_SUCCESS && rc != LDAP_REFERRAL ) {
1098 send_ldap_result( conn, op, rc,
1099 NULL, text, NULL, NULL );
1112 struct berval *gr_ndn,
1113 struct berval *op_ndn,
1114 ObjectClass *group_oc,
1115 AttributeDescription *group_at
1120 if ( op->o_abandon ) return SLAPD_ABANDON;
1122 if ( !dn_match( &target->e_nname, gr_ndn ) ) {
1123 /* we won't attempt to send it to a different backend */
1125 be = select_backend( gr_ndn, 0, 0 );
1128 return LDAP_NO_SUCH_OBJECT;
1132 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1134 for (g = conn->c_groups; g; g=g->ga_next) {
1135 if (g->ga_be != be || g->ga_oc != group_oc ||
1136 g->ga_at != group_at || g->ga_len != gr_ndn->bv_len)
1138 if (strcmp( g->ga_ndn, gr_ndn->bv_val ) == 0)
1142 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1148 if( be->be_group ) {
1149 int res = be->be_group( be, conn, op,
1150 target, gr_ndn, op_ndn,
1151 group_oc, group_at );
1153 if ( op->o_tag != LDAP_REQ_BIND && !op->o_do_not_cache ) {
1154 g = ch_malloc(sizeof(GroupAssertion) + gr_ndn->bv_len);
1156 g->ga_oc = group_oc;
1157 g->ga_at = group_at;
1159 g->ga_len = gr_ndn->bv_len;
1160 strcpy(g->ga_ndn, gr_ndn->bv_val);
1161 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1162 g->ga_next = conn->c_groups;
1164 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1170 return LDAP_UNWILLING_TO_PERFORM;
1180 AttributeDescription *entry_at,
1184 if ( target == NULL || !dn_match( &target->e_nname, edn ) ) {
1185 /* we won't attempt to send it to a different backend */
1187 be = select_backend( edn, 0, 0 );
1190 return LDAP_NO_SUCH_OBJECT;
1194 if( be->be_attribute ) {
1195 return be->be_attribute( be, conn, op, target, edn,
1199 return LDAP_UNWILLING_TO_PERFORM;
1202 Attribute *backend_operational(
1207 AttributeName *attrs,
1210 Attribute *a = NULL, **ap = &a;
1213 * If operational attributes (allegedly) are required,
1214 * and the backend supports specific operational attributes,
1215 * add them to the attribute list
1217 if ( opattrs || ( attrs &&
1218 ad_inlist( slap_schema.si_ad_subschemaSubentry, attrs )) ) {
1219 *ap = slap_operational_subschemaSubentry( be );
1220 ap = &(*ap)->a_next;
1223 if ( ( opattrs || attrs ) && be && be->be_operational != NULL ) {
1224 ( void )be->be_operational( be, conn, op, e, attrs, opattrs, ap );