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;
124 ldap_pvt_thread_pool_t syncrepl_pool;
125 int syncrepl_pool_max = SLAP_MAX_SYNCREPL_THREADS;
128 int backend_init(void)
133 ldap_pvt_thread_pool_init( &syncrepl_pool, syncrepl_pool_max, 0 );
136 if((nBackendInfo != 0) || (backendInfo != NULL)) {
137 /* already initialized */
139 LDAP_LOG( BACKEND, ERR,
140 "backend_init: backend already initialized\n", 0, 0, 0 );
142 Debug( LDAP_DEBUG_ANY,
143 "backend_init: already initialized.\n", 0, 0, 0 );
149 binfo[nBackendInfo].bi_type != NULL;
152 rc = binfo[nBackendInfo].bi_init( &binfo[nBackendInfo] );
156 LDAP_LOG( BACKEND, INFO,
157 "backend_init: initialized for type \"%s\"\n",
158 binfo[nBackendInfo].bi_type, 0, 0 );
160 Debug( LDAP_DEBUG_ANY,
161 "backend_init: initialized for type \"%s\"\n",
162 binfo[nBackendInfo].bi_type, 0, 0 );
164 /* destroy those we've already inited */
169 if ( binfo[nBackendInfo].bi_destroy ) {
170 binfo[nBackendInfo].bi_destroy(
171 &binfo[nBackendInfo] );
178 if ( nBackendInfo > 0) {
188 LDAP_LOG( BACKEND, ERR, "backend_init: failed\n", 0, 0, 0 );
190 Debug( LDAP_DEBUG_ANY,
191 "backend_init: failed\n",
196 #endif /* SLAPD_MODULES */
199 int backend_add(BackendInfo *aBackendInfo)
203 if ((rc = aBackendInfo->bi_init(aBackendInfo)) != 0) {
205 LDAP_LOG( BACKEND, ERR,
206 "backend_add: initialization for type \"%s\" failed\n",
207 aBackendInfo->bi_type, 0, 0 );
209 Debug( LDAP_DEBUG_ANY,
210 "backend_add: initialization for type \"%s\" failed\n",
211 aBackendInfo->bi_type, 0, 0 );
216 /* now add the backend type to the Backend Info List */
218 BackendInfo *newBackendInfo = 0;
220 /* if backendInfo == binfo no deallocation of old backendInfo */
221 if (backendInfo == binfo) {
222 newBackendInfo = ch_calloc(nBackendInfo + 1, sizeof(BackendInfo));
223 AC_MEMCPY(newBackendInfo, backendInfo, sizeof(BackendInfo) *
226 newBackendInfo = ch_realloc(backendInfo, sizeof(BackendInfo) *
229 AC_MEMCPY(&newBackendInfo[nBackendInfo], aBackendInfo,
230 sizeof(BackendInfo));
231 backendInfo = newBackendInfo;
238 int backend_startup(Backend *be)
247 if( ! ( nBackendDB > 0 ) ) {
250 LDAP_LOG( BACKEND, INFO,
251 "backend_startup: %d databases to startup. \n", nBackendDB, 0, 0 );
253 Debug( LDAP_DEBUG_ANY,
254 "backend_startup: %d databases to startup.\n",
261 /* startup a specific backend database */
263 LDAP_LOG( BACKEND, DETAIL1, "backend_startup: starting \"%s\"\n",
264 be->be_suffix[0].bv_val, 0, 0 );
266 Debug( LDAP_DEBUG_TRACE,
267 "backend_startup: starting \"%s\"\n",
268 be->be_suffix[0].bv_val, 0, 0 );
271 if ( be->bd_info->bi_open ) {
272 rc = be->bd_info->bi_open( be->bd_info );
275 LDAP_LOG( BACKEND, CRIT, "backend_startup: bi_open failed!\n", 0, 0, 0 );
277 Debug( LDAP_DEBUG_ANY,
278 "backend_startup: bi_open failed!\n",
286 if ( be->bd_info->bi_db_open ) {
287 rc = be->bd_info->bi_db_open( be );
290 LDAP_LOG( BACKEND, CRIT,
291 "backend_startup: bi_db_open failed! (%d)\n", rc, 0, 0 );
293 Debug( LDAP_DEBUG_ANY,
294 "backend_startup: bi_db_open failed! (%d)\n",
304 /* open each backend type */
305 for( i = 0; i < nBackendInfo; i++ ) {
306 if( backendInfo[i].bi_nDB == 0) {
307 /* no database of this type, don't open */
311 if( backendInfo[i].bi_open ) {
312 rc = backendInfo[i].bi_open(
316 LDAP_LOG( BACKEND, CRIT,
317 "backend_startup: bi_open %d failed!\n", i, 0, 0 );
319 Debug( LDAP_DEBUG_ANY,
320 "backend_startup: bi_open %d failed!\n",
328 /* open each backend database */
329 for( i = 0; i < nBackendDB; i++ ) {
330 /* append global access controls */
331 acl_append( &backendDB[i].be_acl, global_acl );
333 if ( backendDB[i].bd_info->bi_db_open ) {
334 rc = backendDB[i].bd_info->bi_db_open(
338 LDAP_LOG( BACKEND, CRIT,
339 "backend_startup: bi_db_open(%d) failed! (%d)\n", i, rc, 0 );
341 Debug( LDAP_DEBUG_ANY,
342 "backend_startup: bi_db_open(%d) failed! (%d)\n",
350 if ( backendDB[i].syncinfo != NULL ) {
352 ret = ldap_pvt_thread_pool_submit( &syncrepl_pool,
353 do_syncrepl, (void *) &backendDB[i] );
356 LDAP_LOG( BACKEND, CRIT,
357 "syncrepl thread pool submit failed (%d)\n",
360 Debug( LDAP_DEBUG_ANY,
361 "ldap_pvt_thread_pool_submit failed (%d) \n",
372 int backend_num( Backend *be )
376 if( be == NULL ) return -1;
378 for( i = 0; i < nBackendDB; i++ ) {
379 if( be == &backendDB[i] ) return i;
384 int backend_shutdown( Backend *be )
390 /* shutdown a specific backend database */
392 if ( be->bd_info->bi_nDB == 0 ) {
393 /* no database of this type, we never opened it */
397 if ( be->bd_info->bi_db_close ) {
398 be->bd_info->bi_db_close( be );
401 if( be->bd_info->bi_close ) {
402 be->bd_info->bi_close( be->bd_info );
408 /* close each backend database */
409 for( i = 0; i < nBackendDB; i++ ) {
410 if ( backendDB[i].bd_info->bi_db_close ) {
411 backendDB[i].bd_info->bi_db_close(
417 LDAP_LOG( BACKEND, NOTICE,
418 "backend_shutdown: bi_close %s failed!\n",
419 backendDB[i].be_type, 0, 0 );
421 Debug( LDAP_DEBUG_ANY,
422 "backend_close: bi_close %s failed!\n",
423 backendDB[i].be_type, 0, 0 );
428 /* close each backend type */
429 for( i = 0; i < nBackendInfo; i++ ) {
430 if( backendInfo[i].bi_nDB == 0 ) {
431 /* no database of this type */
435 if( backendInfo[i].bi_close ) {
436 backendInfo[i].bi_close(
444 int backend_destroy(void)
450 ldap_pvt_thread_pool_destroy( &syncrepl_pool, 1 );
453 /* destroy each backend database */
454 for( i = 0, bd = backendDB; i < nBackendDB; i++, bd++ ) {
455 if ( bd->bd_info->bi_db_destroy ) {
456 bd->bd_info->bi_db_destroy( bd );
458 ber_bvarray_free( bd->be_suffix );
459 ber_bvarray_free( bd->be_nsuffix );
460 if ( bd->be_rootdn.bv_val ) free( bd->be_rootdn.bv_val );
461 if ( bd->be_rootndn.bv_val ) free( bd->be_rootndn.bv_val );
462 if ( bd->be_rootpw.bv_val ) free( bd->be_rootpw.bv_val );
463 acl_destroy( bd->be_acl, global_acl );
467 /* destroy each backend type */
468 for( i = 0; i < nBackendInfo; i++ ) {
469 if( backendInfo[i].bi_destroy ) {
470 backendInfo[i].bi_destroy(
476 if (backendInfo != binfo) {
479 #endif /* SLAPD_MODULES */
487 BackendInfo* backend_info(const char *type)
491 /* search for the backend type */
492 for( i = 0; i < nBackendInfo; i++ ) {
493 if( strcasecmp(backendInfo[i].bi_type, type) == 0 ) {
494 return &backendInfo[i];
508 BackendInfo *bi = backend_info(type);
512 fprintf( stderr, "Unrecognized database type (%s)\n", type );
516 backendDB = (BackendDB *) ch_realloc(
518 (nBackendDB + 1) * sizeof(Backend) );
520 memset( &backendDB[nbackends], '\0', sizeof(Backend) );
522 be = &backends[nbackends++];
525 be->be_def_limit = deflimit;
526 be->be_dfltaccess = global_default_access;
528 be->be_restrictops = global_restrictops;
529 be->be_requires = global_requires;
530 be->be_ssf_set = global_ssf_set;
536 /* assign a default depth limit for alias deref */
537 be->be_max_deref_depth = SLAPD_DEFAULT_MAXDEREFDEPTH;
540 rc = bi->bi_db_init( be );
544 fprintf( stderr, "database init failed (%s)\n", type );
558 for ( i = 0; i < nbackends; i++ ) {
559 if ( backends[i].bd_info->bi_db_close ) {
560 (*backends[i].bd_info->bi_db_close)( &backends[i] );
572 ber_len_t len, dnlen = dn->bv_len;
575 for ( i = 0; i < nbackends; i++ ) {
576 for ( j = 0; backends[i].be_nsuffix != NULL &&
577 backends[i].be_nsuffix[j].bv_val != NULL; j++ )
579 if ( ( SLAP_GLUE_SUBORDINATE( &backends[i] ) )
585 len = backends[i].be_nsuffix[j].bv_len;
588 /* suffix is longer than DN */
593 * input DN is normalized, so the separator check
594 * need not look at escaping
596 if ( len && len < dnlen &&
597 !DN_SEPARATOR( dn->bv_val[(dnlen-len)-1] ))
602 if ( strcmp( backends[i].be_nsuffix[j].bv_val,
603 &dn->bv_val[dnlen-len] ) == 0 )
608 if( manageDSAit && len == dnlen ) {
625 struct berval *bvsuffix
630 for ( i = 0; be->be_nsuffix != NULL && be->be_nsuffix[i].bv_val != NULL; i++ ) {
631 if ( bvmatch( &be->be_nsuffix[i], bvsuffix ) ) {
640 be_isroot( Backend *be, struct berval *ndn )
642 if ( !ndn->bv_len ) {
646 if ( !be->be_rootndn.bv_len ) {
650 return dn_match( &be->be_rootndn, ndn );
654 be_isupdate( Backend *be, struct berval *ndn )
656 if ( !ndn->bv_len ) {
660 if ( !be->be_update_ndn.bv_len ) {
664 return dn_match( &be->be_update_ndn, ndn );
668 be_root_dn( Backend *be )
670 return &be->be_rootdn;
674 be_isroot_pw( Operation *op )
678 if ( ! be_isroot( op->o_bd, &op->o_req_ndn ) ) {
682 if( op->o_bd->be_rootpw.bv_len == 0 ) {
686 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
687 ldap_pvt_thread_mutex_lock( &passwd_mutex );
689 lutil_passwd_sasl_conn = op->o_conn->c_sasl_context;
693 result = lutil_passwd( &op->o_bd->be_rootpw, &op->orb_cred, NULL );
695 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
697 lutil_passwd_sasl_conn = NULL;
699 ldap_pvt_thread_mutex_unlock( &passwd_mutex );
711 if ( op->o_bd->be_release ) {
712 /* free and release entry from backend */
713 return op->o_bd->be_release( op, e, rw );
722 backend_unbind( Operation *op, SlapReply *rs )
725 #if defined( LDAP_SLAPI )
726 Slapi_PBlock *pb = op->o_pb;
729 slapi_x_pblock_set_operation( pb, op );
730 #endif /* defined( LDAP_SLAPI ) */
732 for ( i = 0; i < nbackends; i++ ) {
733 #if defined( LDAP_SLAPI )
734 slapi_pblock_set( pb, SLAPI_BACKEND, (void *)&backends[i] );
735 rc = doPluginFNs( &backends[i], SLAPI_PLUGIN_PRE_UNBIND_FN,
736 (Slapi_PBlock *)pb );
739 * A preoperation plugin failure will abort the
743 LDAP_LOG( OPERATION, INFO, "do_bind: Unbind preoperation plugin "
744 "failed\n", 0, 0, 0);
746 Debug(LDAP_DEBUG_TRACE, "do_bind: Unbind preoperation plugin "
747 "failed.\n", 0, 0, 0);
751 #endif /* defined( LDAP_SLAPI ) */
753 if ( backends[i].be_unbind ) {
754 op->o_bd = &backends[i];
755 (*backends[i].be_unbind)( op, rs );
758 #if defined( LDAP_SLAPI )
759 if ( doPluginFNs( &backends[i], SLAPI_PLUGIN_POST_UNBIND_FN,
760 (Slapi_PBlock *)pb ) < 0 ) {
762 LDAP_LOG( OPERATION, INFO, "do_unbind: Unbind postoperation plugins "
763 "failed\n", 0, 0, 0);
765 Debug(LDAP_DEBUG_TRACE, "do_unbind: Unbind postoperation plugins "
766 "failed.\n", 0, 0, 0);
769 #endif /* defined( LDAP_SLAPI ) */
776 backend_connection_init(
782 for ( i = 0; i < nbackends; i++ ) {
783 if ( backends[i].be_connection_init ) {
784 (*backends[i].be_connection_init)( &backends[i], conn);
792 backend_connection_destroy(
798 for ( i = 0; i < nbackends; i++ ) {
799 if ( backends[i].be_connection_destroy ) {
800 (*backends[i].be_connection_destroy)( &backends[i], conn);
808 backend_check_controls(
812 LDAPControl **ctrls = op->o_ctrls;
813 rs->sr_err = LDAP_SUCCESS;
816 for( ; *ctrls != NULL ; ctrls++ ) {
817 if( (*ctrls)->ldctl_iscritical &&
818 !ldap_charray_inlist( op->o_bd->be_controls, (*ctrls)->ldctl_oid ) )
820 rs->sr_text = "control unavailable in context";
821 rs->sr_err = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
831 backend_check_restrictions(
834 struct berval *opdata )
836 slap_mask_t restrictops;
837 slap_mask_t requires;
845 if ( backend_check_controls( op, rs ) != LDAP_SUCCESS ) {
849 restrictops = op->o_bd->be_restrictops;
850 requires = op->o_bd->be_requires;
851 ssf = &op->o_bd->be_ssf_set;
854 restrictops = global_restrictops;
855 requires = global_requires;
856 ssf = &global_ssf_set;
859 switch( op->o_tag ) {
861 opflag = SLAP_RESTRICT_OP_ADD;
865 opflag = SLAP_RESTRICT_OP_BIND;
868 case LDAP_REQ_COMPARE:
869 opflag = SLAP_RESTRICT_OP_COMPARE;
871 case LDAP_REQ_DELETE:
873 opflag = SLAP_RESTRICT_OP_DELETE;
875 case LDAP_REQ_EXTENDED:
876 opflag = SLAP_RESTRICT_OP_EXTENDED;
879 /* treat unspecified as a modify */
880 opflag = SLAP_RESTRICT_OP_MODIFY;
886 if( bvmatch( opdata, &slap_EXOP_START_TLS ) ) {
894 if( bvmatch( opdata, &slap_EXOP_WHOAMI ) ) {
899 #ifdef LDAP_EXOP_X_CANCEL
901 if ( bvmatch( opdata, &slap_EXOP_CANCEL ) ) {
907 /* treat everything else as a modify */
908 opflag = SLAP_RESTRICT_OP_MODIFY;
912 case LDAP_REQ_MODIFY:
914 opflag = SLAP_RESTRICT_OP_MODIFY;
916 case LDAP_REQ_RENAME:
918 opflag = SLAP_RESTRICT_OP_RENAME;
920 case LDAP_REQ_SEARCH:
921 opflag = SLAP_RESTRICT_OP_SEARCH;
923 case LDAP_REQ_UNBIND:
928 rs->sr_text = "restrict operations internal error";
929 rs->sr_err = LDAP_OTHER;
934 /* these checks don't apply to StartTLS */
936 rs->sr_err = LDAP_CONFIDENTIALITY_REQUIRED;
937 if( op->o_transport_ssf < ssf->sss_transport ) {
938 rs->sr_text = "transport confidentiality required";
942 if( op->o_tls_ssf < ssf->sss_tls ) {
943 rs->sr_text = "TLS confidentiality required";
948 if( op->o_tag == LDAP_REQ_BIND && opdata == NULL ) {
949 /* simple bind specific check */
950 if( op->o_ssf < ssf->sss_simple_bind ) {
951 rs->sr_text = "confidentiality required";
956 if( op->o_tag != LDAP_REQ_BIND || opdata == NULL ) {
957 /* these checks don't apply to SASL bind */
959 if( op->o_sasl_ssf < ssf->sss_sasl ) {
960 rs->sr_text = "SASL confidentiality required";
964 if( op->o_ssf < ssf->sss_ssf ) {
965 rs->sr_text = "confidentiality required";
971 if( op->o_transport_ssf < ssf->sss_update_transport ) {
972 rs->sr_text = "transport update confidentiality required";
976 if( op->o_tls_ssf < ssf->sss_update_tls ) {
977 rs->sr_text = "TLS update confidentiality required";
981 if( op->o_sasl_ssf < ssf->sss_update_sasl ) {
982 rs->sr_text = "SASL update confidentiality required";
986 if( op->o_ssf < ssf->sss_update_ssf ) {
987 rs->sr_text = "update confidentiality required";
991 if( !( global_allows & SLAP_ALLOW_UPDATE_ANON ) &&
992 op->o_ndn.bv_len == 0 )
994 rs->sr_text = "modifications require authentication";
995 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
999 #ifdef SLAP_X_LISTENER_MOD
1000 if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & ( op->o_ndn.bv_len > 0 ? S_IWUSR : S_IWOTH ) ) ) {
1001 /* no "w" mode means readonly */
1002 rs->sr_text = "modifications not allowed on this listener";
1003 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1006 #endif /* SLAP_X_LISTENER_MOD */
1011 /* these checks don't apply to Bind, StartTLS, or Unbind */
1013 if( requires & SLAP_REQUIRE_STRONG ) {
1014 /* should check mechanism */
1015 if( ( op->o_transport_ssf < ssf->sss_transport
1016 && op->o_authmech.bv_len == 0 ) || op->o_dn.bv_len == 0 )
1018 rs->sr_text = "strong authentication required";
1019 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1024 if( requires & SLAP_REQUIRE_SASL ) {
1025 if( op->o_authmech.bv_len == 0 || op->o_dn.bv_len == 0 ) {
1026 rs->sr_text = "SASL authentication required";
1027 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1032 if( requires & SLAP_REQUIRE_AUTHC ) {
1033 if( op->o_dn.bv_len == 0 ) {
1034 rs->sr_text = "authentication required";
1035 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1040 if( requires & SLAP_REQUIRE_BIND ) {
1042 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1043 version = op->o_conn->c_protocol;
1044 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1047 /* no bind has occurred */
1048 rs->sr_text = "BIND required";
1049 rs->sr_err = LDAP_OPERATIONS_ERROR;
1054 if( requires & SLAP_REQUIRE_LDAP_V3 ) {
1055 if( op->o_protocol < LDAP_VERSION3 ) {
1056 /* no bind has occurred */
1057 rs->sr_text = "operation restricted to LDAPv3 clients";
1058 rs->sr_err = LDAP_OPERATIONS_ERROR;
1063 #ifdef SLAP_X_LISTENER_MOD
1064 if ( !starttls && op->o_dn.bv_len == 0 ) {
1065 if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & S_IXOTH ) ) {
1066 /* no "x" mode means bind required */
1067 rs->sr_text = "bind required on this listener";
1068 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1073 if ( !starttls && !updateop ) {
1074 if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & ( op->o_dn.bv_len > 0 ? S_IRUSR : S_IROTH ) ) ) {
1075 /* no "r" mode means no read */
1076 rs->sr_text = "read not allowed on this listener";
1077 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1081 #endif /* SLAP_X_LISTENER_MOD */
1085 if( restrictops & opflag ) {
1086 if( restrictops == SLAP_RESTRICT_OP_READS ) {
1087 rs->sr_text = "read operations restricted";
1089 rs->sr_text = "operation restricted";
1091 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1095 rs->sr_err = LDAP_SUCCESS;
1099 int backend_check_referrals( Operation *op, SlapReply *rs )
1101 rs->sr_err = LDAP_SUCCESS;
1103 if( op->o_bd->be_chk_referrals ) {
1104 rs->sr_err = op->o_bd->be_chk_referrals( op, rs );
1106 if( rs->sr_err != LDAP_SUCCESS && rs->sr_err != LDAP_REFERRAL ) {
1107 send_ldap_result( op, rs );
1119 AttributeDescription *at,
1123 Backend *be = op->o_bd;
1128 op->o_bd = select_backend( ndn, 0, 0 );
1130 if (op->o_bd == NULL) {
1131 rc = LDAP_NO_SUCH_OBJECT;
1132 } else if ( op->o_bd->be_fetch ) {
1133 rc = ( op->o_bd->be_fetch )( op, ndn,
1136 rc = LDAP_UNWILLING_TO_PERFORM;
1146 struct berval *gr_ndn,
1147 struct berval *op_ndn,
1148 ObjectClass *group_oc,
1149 AttributeDescription *group_at
1157 if ( op->o_abandon ) return SLAPD_ABANDON;
1159 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1161 for (g = op->o_conn->c_groups; g; g=g->ga_next) {
1162 if (g->ga_be != op->o_bd || g->ga_oc != group_oc ||
1163 g->ga_at != group_at || g->ga_len != gr_ndn->bv_len)
1165 if (strcmp( g->ga_ndn, gr_ndn->bv_val ) == 0)
1169 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1175 if ( target && dn_match( &target->e_nname, gr_ndn ) ) {
1178 rc = be_entry_get_rw(op, gr_ndn, group_oc, group_at, 0, &e );
1181 a = attr_find( e->e_attrs, group_at );
1183 rc = value_find_ex( group_at,
1184 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1185 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1186 a->a_nvals, op_ndn, op->o_tmpmemctx );
1188 rc = LDAP_NO_SUCH_ATTRIBUTE;
1191 be_entry_release_r( op, e );
1194 rc = LDAP_NO_SUCH_OBJECT;
1197 if ( op->o_tag != LDAP_REQ_BIND && !op->o_do_not_cache ) {
1198 g = ch_malloc(sizeof(GroupAssertion) + gr_ndn->bv_len);
1199 g->ga_be = op->o_bd;
1200 g->ga_oc = group_oc;
1201 g->ga_at = group_at;
1203 g->ga_len = gr_ndn->bv_len;
1204 strcpy(g->ga_ndn, gr_ndn->bv_val);
1205 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1206 g->ga_next = op->o_conn->c_groups;
1207 op->o_conn->c_groups = g;
1208 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1219 AttributeDescription *entry_at,
1225 int i, j, rc = LDAP_SUCCESS;
1226 AccessControlState acl_state = ACL_STATE_INIT;
1228 if ( target && dn_match( &target->e_nname, edn ) ) {
1231 rc = be_entry_get_rw(op, edn, NULL, entry_at, 0, &e );
1232 if ( rc != LDAP_SUCCESS ) return rc;
1236 a = attr_find( e->e_attrs, entry_at );
1240 if ( op->o_conn && access_allowed( op,
1241 e, entry_at, NULL, ACL_AUTH,
1242 &acl_state ) == 0 ) {
1243 rc = LDAP_INSUFFICIENT_ACCESS;
1247 for ( i=0; a->a_vals[i].bv_val; i++ ) ;
1249 v = op->o_tmpalloc( sizeof(struct berval) * (i+1), op->o_tmpmemctx );
1250 for ( i=0,j=0; a->a_vals[i].bv_val; i++ ) {
1251 if ( op->o_conn && access_allowed( op,
1254 ACL_AUTH, &acl_state ) == 0 ) {
1258 &a->a_nvals[i], op->o_tmpmemctx );
1259 if (v[j].bv_val ) j++;
1262 op->o_tmpfree( v, op->o_tmpmemctx );
1264 rc = LDAP_INSUFFICIENT_ACCESS;
1272 freeit: if (e != target ) {
1273 be_entry_release_r( op, e );
1280 Attribute *backend_operational(
1285 Attribute *a = NULL, **ap = &a;
1288 * If operational attributes (allegedly) are required,
1289 * and the backend supports specific operational attributes,
1290 * add them to the attribute list
1292 if ( opattrs || ( op->ors_attrs &&
1293 ad_inlist( slap_schema.si_ad_subschemaSubentry, op->ors_attrs )) ) {
1294 *ap = slap_operational_subschemaSubentry( op->o_bd );
1295 ap = &(*ap)->a_next;
1298 if ( ( opattrs || op->ors_attrs ) && op->o_bd && op->o_bd->be_operational != NULL ) {
1299 ( void )op->o_bd->be_operational( op, rs, opattrs, ap );