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( Operation *op )
638 if ( ! be_isroot( op->o_bd, &op->o_req_ndn ) ) {
642 if( op->o_bd->be_rootpw.bv_len == 0 ) {
646 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
647 ldap_pvt_thread_mutex_lock( &passwd_mutex );
649 lutil_passwd_sasl_conn = op->o_conn->c_sasl_context;
653 result = lutil_passwd( &op->o_bd->be_rootpw, &op->orb_cred, NULL );
655 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
657 lutil_passwd_sasl_conn = NULL;
659 ldap_pvt_thread_mutex_unlock( &passwd_mutex );
671 if ( op->o_bd->be_release ) {
672 /* free and release entry from backend */
673 return op->o_bd->be_release( op, e, rw );
682 backend_unbind( Operation *op, SlapReply *rs )
685 #if defined( LDAP_SLAPI )
686 Slapi_PBlock *pb = op->o_pb;
689 slapi_x_pblock_set_operation( pb, op );
690 #endif /* defined( LDAP_SLAPI ) */
692 for ( i = 0; i < nbackends; i++ ) {
693 #if defined( LDAP_SLAPI )
694 slapi_pblock_set( pb, SLAPI_BACKEND, (void *)&backends[i] );
695 rc = doPluginFNs( &backends[i], SLAPI_PLUGIN_PRE_UNBIND_FN,
696 (Slapi_PBlock *)pb );
699 * A preoperation plugin failure will abort the
703 LDAP_LOG( OPERATION, INFO, "do_bind: Unbind preoperation plugin "
704 "failed\n", 0, 0, 0);
706 Debug(LDAP_DEBUG_TRACE, "do_bind: Unbind preoperation plugin "
707 "failed.\n", 0, 0, 0);
711 #endif /* defined( LDAP_SLAPI ) */
713 if ( backends[i].be_unbind ) {
714 op->o_bd = &backends[i];
715 (*backends[i].be_unbind)( op, rs );
718 #if defined( LDAP_SLAPI )
719 if ( doPluginFNs( &backends[i], SLAPI_PLUGIN_POST_UNBIND_FN,
720 (Slapi_PBlock *)pb ) != 0 ) {
722 LDAP_LOG( OPERATION, INFO, "do_unbind: Unbind postoperation plugins "
723 "failed\n", 0, 0, 0);
725 Debug(LDAP_DEBUG_TRACE, "do_unbind: Unbind postoperation plugins "
726 "failed.\n", 0, 0, 0);
729 #endif /* defined( LDAP_SLAPI ) */
736 backend_connection_init(
742 for ( i = 0; i < nbackends; i++ ) {
743 if ( backends[i].be_connection_init ) {
744 (*backends[i].be_connection_init)( &backends[i], conn);
752 backend_connection_destroy(
758 for ( i = 0; i < nbackends; i++ ) {
759 if ( backends[i].be_connection_destroy ) {
760 (*backends[i].be_connection_destroy)( &backends[i], conn);
768 backend_check_controls(
772 LDAPControl **ctrls = op->o_ctrls;
773 rs->sr_err = LDAP_SUCCESS;
776 for( ; *ctrls != NULL ; ctrls++ ) {
777 if( (*ctrls)->ldctl_iscritical &&
778 !ldap_charray_inlist( op->o_bd->be_controls, (*ctrls)->ldctl_oid ) )
780 rs->sr_text = "control unavailable in context";
781 rs->sr_err = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
791 backend_check_restrictions(
794 struct berval *opdata )
796 slap_mask_t restrictops;
797 slap_mask_t requires;
805 if ( backend_check_controls( op, rs ) != LDAP_SUCCESS ) {
809 restrictops = op->o_bd->be_restrictops;
810 requires = op->o_bd->be_requires;
811 ssf = &op->o_bd->be_ssf_set;
814 restrictops = global_restrictops;
815 requires = global_requires;
816 ssf = &global_ssf_set;
819 switch( op->o_tag ) {
821 opflag = SLAP_RESTRICT_OP_ADD;
825 opflag = SLAP_RESTRICT_OP_BIND;
828 case LDAP_REQ_COMPARE:
829 opflag = SLAP_RESTRICT_OP_COMPARE;
831 case LDAP_REQ_DELETE:
833 opflag = SLAP_RESTRICT_OP_DELETE;
835 case LDAP_REQ_EXTENDED:
836 opflag = SLAP_RESTRICT_OP_EXTENDED;
839 /* treat unspecified as a modify */
840 opflag = SLAP_RESTRICT_OP_MODIFY;
846 if( bvmatch( opdata, &slap_EXOP_START_TLS ) ) {
854 if( bvmatch( opdata, &slap_EXOP_WHOAMI ) ) {
859 #ifdef LDAP_EXOP_X_CANCEL
861 if ( bvmatch( opdata, &slap_EXOP_CANCEL ) ) {
867 /* treat everything else as a modify */
868 opflag = SLAP_RESTRICT_OP_MODIFY;
872 case LDAP_REQ_MODIFY:
874 opflag = SLAP_RESTRICT_OP_MODIFY;
876 case LDAP_REQ_RENAME:
878 opflag = SLAP_RESTRICT_OP_RENAME;
880 case LDAP_REQ_SEARCH:
881 opflag = SLAP_RESTRICT_OP_SEARCH;
883 case LDAP_REQ_UNBIND:
888 rs->sr_text = "restrict operations internal error";
889 rs->sr_err = LDAP_OTHER;
894 /* these checks don't apply to StartTLS */
896 rs->sr_err = LDAP_CONFIDENTIALITY_REQUIRED;
897 if( op->o_transport_ssf < ssf->sss_transport ) {
898 rs->sr_text = "transport confidentiality required";
902 if( op->o_tls_ssf < ssf->sss_tls ) {
903 rs->sr_text = "TLS confidentiality required";
908 if( op->o_tag == LDAP_REQ_BIND && opdata == NULL ) {
909 /* simple bind specific check */
910 if( op->o_ssf < ssf->sss_simple_bind ) {
911 rs->sr_text = "confidentiality required";
916 if( op->o_tag != LDAP_REQ_BIND || opdata == NULL ) {
917 /* these checks don't apply to SASL bind */
919 if( op->o_sasl_ssf < ssf->sss_sasl ) {
920 rs->sr_text = "SASL confidentiality required";
924 if( op->o_ssf < ssf->sss_ssf ) {
925 rs->sr_text = "confidentiality required";
931 if( op->o_transport_ssf < ssf->sss_update_transport ) {
932 rs->sr_text = "transport update confidentiality required";
936 if( op->o_tls_ssf < ssf->sss_update_tls ) {
937 rs->sr_text = "TLS update confidentiality required";
941 if( op->o_sasl_ssf < ssf->sss_update_sasl ) {
942 rs->sr_text = "SASL update confidentiality required";
946 if( op->o_ssf < ssf->sss_update_ssf ) {
947 rs->sr_text = "update confidentiality required";
951 if( !( global_allows & SLAP_ALLOW_UPDATE_ANON ) &&
952 op->o_ndn.bv_len == 0 )
954 rs->sr_text = "modifications require authentication";
955 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
959 #ifdef SLAP_X_LISTENER_MOD
960 if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & ( op->o_ndn.bv_len > 0 ? S_IWUSR : S_IWOTH ) ) ) {
961 /* no "w" mode means readonly */
962 rs->sr_text = "modifications not allowed on this listener";
963 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
966 #endif /* SLAP_X_LISTENER_MOD */
971 /* these checks don't apply to Bind, StartTLS, or Unbind */
973 if( requires & SLAP_REQUIRE_STRONG ) {
974 /* should check mechanism */
975 if( ( op->o_transport_ssf < ssf->sss_transport
976 && op->o_authmech.bv_len == 0 ) || op->o_dn.bv_len == 0 )
978 rs->sr_text = "strong authentication required";
979 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
984 if( requires & SLAP_REQUIRE_SASL ) {
985 if( op->o_authmech.bv_len == 0 || op->o_dn.bv_len == 0 ) {
986 rs->sr_text = "SASL authentication required";
987 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
992 if( requires & SLAP_REQUIRE_AUTHC ) {
993 if( op->o_dn.bv_len == 0 ) {
994 rs->sr_text = "authentication required";
995 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1000 if( requires & SLAP_REQUIRE_BIND ) {
1002 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1003 version = op->o_conn->c_protocol;
1004 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1007 /* no bind has occurred */
1008 rs->sr_text = "BIND required";
1009 rs->sr_err = LDAP_OPERATIONS_ERROR;
1014 if( requires & SLAP_REQUIRE_LDAP_V3 ) {
1015 if( op->o_protocol < LDAP_VERSION3 ) {
1016 /* no bind has occurred */
1017 rs->sr_text = "operation restricted to LDAPv3 clients";
1018 rs->sr_err = LDAP_OPERATIONS_ERROR;
1023 #ifdef SLAP_X_LISTENER_MOD
1024 if ( !starttls && op->o_dn.bv_len == 0 ) {
1025 if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & S_IXOTH ) ) {
1026 /* no "x" mode means bind required */
1027 rs->sr_text = "bind required on this listener";
1028 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1033 if ( !starttls && !updateop ) {
1034 if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & ( op->o_dn.bv_len > 0 ? S_IRUSR : S_IROTH ) ) ) {
1035 /* no "r" mode means no read */
1036 rs->sr_text = "read not allowed on this listener";
1037 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1041 #endif /* SLAP_X_LISTENER_MOD */
1045 if( restrictops & opflag ) {
1046 if( restrictops == SLAP_RESTRICT_OP_READS ) {
1047 rs->sr_text = "read operations restricted";
1049 rs->sr_text = "operation restricted";
1051 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1055 rs->sr_err = LDAP_SUCCESS;
1059 int backend_check_referrals( Operation *op, SlapReply *rs )
1061 rs->sr_err = LDAP_SUCCESS;
1063 if( op->o_bd->be_chk_referrals ) {
1064 rs->sr_err = op->o_bd->be_chk_referrals( op, rs );
1066 if( rs->sr_err != LDAP_SUCCESS && rs->sr_err != LDAP_REFERRAL ) {
1067 send_ldap_result( op, rs );
1079 AttributeDescription *at,
1083 Backend *be = op->o_bd;
1086 op->o_bd = select_backend( ndn, 0, 0 );
1088 if (op->o_bd == NULL) {
1089 rc = LDAP_NO_SUCH_OBJECT;
1090 } else if ( op->o_bd->be_fetch ) {
1091 rc = ( op->o_bd->be_fetch )( op, ndn,
1094 rc = LDAP_UNWILLING_TO_PERFORM;
1104 struct berval *gr_ndn,
1105 struct berval *op_ndn,
1106 ObjectClass *group_oc,
1107 AttributeDescription *group_at
1115 if ( op->o_abandon ) return SLAPD_ABANDON;
1117 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1119 for (g = op->o_conn->c_groups; g; g=g->ga_next) {
1120 if (g->ga_be != op->o_bd || g->ga_oc != group_oc ||
1121 g->ga_at != group_at || g->ga_len != gr_ndn->bv_len)
1123 if (strcmp( g->ga_ndn, gr_ndn->bv_val ) == 0)
1127 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1133 if ( target && dn_match( &target->e_nname, gr_ndn ) ) {
1136 rc = be_entry_get_rw(op, gr_ndn, group_oc, group_at, 0, &e );
1139 a = attr_find( e->e_attrs, group_at );
1142 rc = value_find_ex( group_at,
1143 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1144 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1145 a->a_nvals, op_ndn );
1147 rc = value_find_ex( group_at, 0, a->a_vals, op_ndn );
1150 rc = LDAP_NO_SUCH_ATTRIBUTE;
1153 be_entry_release_r( op, e );
1156 rc = LDAP_NO_SUCH_OBJECT;
1159 if ( op->o_tag != LDAP_REQ_BIND && !op->o_do_not_cache ) {
1160 g = ch_malloc(sizeof(GroupAssertion) + gr_ndn->bv_len);
1161 g->ga_be = op->o_bd;
1162 g->ga_oc = group_oc;
1163 g->ga_at = group_at;
1165 g->ga_len = gr_ndn->bv_len;
1166 strcpy(g->ga_ndn, gr_ndn->bv_val);
1167 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1168 g->ga_next = op->o_conn->c_groups;
1169 op->o_conn->c_groups = g;
1170 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1181 AttributeDescription *entry_at,
1187 int i, j, rc = LDAP_SUCCESS;
1188 AccessControlState acl_state = ACL_STATE_INIT;
1190 if ( target && dn_match( &target->e_nname, edn ) ) {
1193 rc = be_entry_get_rw(op, edn, NULL, entry_at, 0, &e );
1194 if ( rc != LDAP_SUCCESS ) return rc;
1198 a = attr_find( e->e_attrs, entry_at );
1202 if ( op->o_conn && access_allowed( op,
1203 e, entry_at, NULL, ACL_AUTH,
1204 &acl_state ) == 0 ) {
1205 rc = LDAP_INSUFFICIENT_ACCESS;
1209 for ( i=0; a->a_vals[i].bv_val; i++ ) ;
1211 v = ch_malloc( sizeof(struct berval) * (i+1) );
1212 for ( i=0,j=0; a->a_vals[i].bv_val; i++ ) {
1213 if ( op->o_conn && access_allowed( op,
1220 ACL_AUTH, &acl_state ) == 0 ) {
1230 if (v[j].bv_val ) j++;
1235 rc = LDAP_INSUFFICIENT_ACCESS;
1243 freeit: if (e != target ) {
1244 be_entry_release_r( op, e );
1251 Attribute *backend_operational(
1256 Attribute *a = NULL, **ap = &a;
1259 * If operational attributes (allegedly) are required,
1260 * and the backend supports specific operational attributes,
1261 * add them to the attribute list
1263 if ( opattrs || ( op->ors_attrs &&
1264 ad_inlist( slap_schema.si_ad_subschemaSubentry, op->ors_attrs )) ) {
1265 *ap = slap_operational_subschemaSubentry( op->o_bd );
1266 ap = &(*ap)->a_next;
1269 if ( ( opattrs || op->ors_attrs ) && op->o_bd && op->o_bd->be_operational != NULL ) {
1270 ( void )op->o_bd->be_operational( op, rs, opattrs, ap );