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>
28 * If a module is configured as dynamic, its header should not
29 * get included into slapd. While this is a general rule and does
30 * not have much of an effect in UNIX, this rule should be adhered
31 * to for Windows, where dynamic object code should not be implicitly
32 * imported into slapd without appropriate __declspec(dllimport) directives.
35 #if defined(SLAPD_BDB) && !defined(SLAPD_BDB_DYNAMIC)
36 #include "back-bdb/external.h"
38 #if defined(SLAPD_DNSSRV) && !defined(SLAPD_DNSSRV_DYNAMIC)
39 #include "back-dnssrv/external.h"
41 #if defined(SLAPD_HDB) && !defined(SLAPD_HDB_DYNAMIC)
42 #include "back-hdb/external.h"
44 #if defined(SLAPD_LDAP) && !defined(SLAPD_LDAP_DYNAMIC)
45 #include "back-ldap/external.h"
47 #if defined(SLAPD_LDBM) && !defined(SLAPD_LDBM_DYNAMIC)
48 #include "back-ldbm/external.h"
50 #if defined(SLAPD_META) && !defined(SLAPD_META_DYNAMIC)
51 #include "back-meta/external.h"
53 #if defined(SLAPD_MONITOR) && !defined(SLAPD_MONITOR_DYNAMIC)
54 #include "back-monitor/external.h"
56 #if defined(SLAPD_NULL) && !defined(SLAPD_NULL_DYNAMIC)
57 #include "back-null/external.h"
59 #if defined(SLAPD_PASSWD) && !defined(SLAPD_PASSWD_DYNAMIC)
60 #include "back-passwd/external.h"
62 #if defined(SLAPD_PERL) && !defined(SLAPD_PERL_DYNAMIC)
63 #include "back-perl/external.h"
65 #if defined(SLAPD_SHELL) && !defined(SLAPD_SHELL_DYNAMIC)
66 #include "back-shell/external.h"
68 #if defined(SLAPD_TCL) && !defined(SLAPD_TCL_DYNAMIC)
69 #include "back-tcl/external.h"
71 #if defined(SLAPD_SQL) && !defined(SLAPD_SQL_DYNAMIC)
72 #include "back-sql/external.h"
74 #if defined(SLAPD_PRIVATE) && !defined(SLAPD_PRIVATE_DYNAMIC)
75 #include "private/external.h"
78 static BackendInfo binfo[] = {
79 #if defined(SLAPD_BDB) && !defined(SLAPD_BDB_DYNAMIC)
80 {"bdb", bdb_initialize},
82 #if defined(SLAPD_DNSSRV) && !defined(SLAPD_DNSSRV_DYNAMIC)
83 {"dnssrv", dnssrv_back_initialize},
85 #if defined(SLAPD_HDB) && !defined(SLAPD_HDB_DYNAMIC)
86 {"hdb", hdb_initialize},
88 #if defined(SLAPD_LDAP) && !defined(SLAPD_LDAP_DYNAMIC)
89 {"ldap", ldap_back_initialize},
91 #if defined(SLAPD_LDBM) && !defined(SLAPD_LDBM_DYNAMIC)
92 {"ldbm", ldbm_back_initialize},
94 #if defined(SLAPD_META) && !defined(SLAPD_META_DYNAMIC)
95 {"meta", meta_back_initialize},
97 #if defined(SLAPD_MONITOR) && !defined(SLAPD_MONITOR_DYNAMIC)
98 {"monitor", monitor_back_initialize},
100 #if defined(SLAPD_NULL) && !defined(SLAPD_NULL_DYNAMIC)
101 {"null", null_back_initialize},
103 #if defined(SLAPD_PASSWD) && !defined(SLAPD_PASSWD_DYNAMIC)
104 {"passwd", passwd_back_initialize},
106 #if defined(SLAPD_PERL) && !defined(SLAPD_PERL_DYNAMIC)
107 {"perl", perl_back_initialize},
109 #if defined(SLAPD_SHELL) && !defined(SLAPD_SHELL_DYNAMIC)
110 {"shell", shell_back_initialize},
112 #if defined(SLAPD_TCL) && !defined(SLAPD_TCL_DYNAMIC)
113 {"tcl", tcl_back_initialize},
115 #if defined(SLAPD_SQL) && !defined(SLAPD_SQL_DYNAMIC)
116 {"sql", sql_back_initialize},
118 /* for any private backend */
119 #if defined(SLAPD_PRIVATE) && !defined(SLAPD_PRIVATE_DYNAMIC)
120 {"private", private_back_initialize},
125 int nBackendInfo = 0;
126 BackendInfo *backendInfo = NULL;
129 BackendDB *backendDB = NULL;
131 ldap_pvt_thread_pool_t syncrepl_pool;
132 int syncrepl_pool_max = SLAP_MAX_SYNCREPL_THREADS;
134 int backend_init(void)
138 ldap_pvt_thread_pool_init( &syncrepl_pool, syncrepl_pool_max, 0 );
140 if((nBackendInfo != 0) || (backendInfo != NULL)) {
141 /* already initialized */
143 LDAP_LOG( BACKEND, ERR,
144 "backend_init: backend already initialized\n", 0, 0, 0 );
146 Debug( LDAP_DEBUG_ANY,
147 "backend_init: already initialized.\n", 0, 0, 0 );
153 binfo[nBackendInfo].bi_type != NULL;
156 rc = binfo[nBackendInfo].bi_init( &binfo[nBackendInfo] );
160 LDAP_LOG( BACKEND, INFO,
161 "backend_init: initialized for type \"%s\"\n",
162 binfo[nBackendInfo].bi_type, 0, 0 );
164 Debug( LDAP_DEBUG_ANY,
165 "backend_init: initialized for type \"%s\"\n",
166 binfo[nBackendInfo].bi_type, 0, 0 );
168 /* destroy those we've already inited */
173 if ( binfo[nBackendInfo].bi_destroy ) {
174 binfo[nBackendInfo].bi_destroy(
175 &binfo[nBackendInfo] );
182 if ( nBackendInfo > 0) {
192 LDAP_LOG( BACKEND, ERR, "backend_init: failed\n", 0, 0, 0 );
194 Debug( LDAP_DEBUG_ANY,
195 "backend_init: failed\n",
200 #endif /* SLAPD_MODULES */
203 int backend_add(BackendInfo *aBackendInfo)
207 if ((rc = aBackendInfo->bi_init(aBackendInfo)) != 0) {
209 LDAP_LOG( BACKEND, ERR,
210 "backend_add: initialization for type \"%s\" failed\n",
211 aBackendInfo->bi_type, 0, 0 );
213 Debug( LDAP_DEBUG_ANY,
214 "backend_add: initialization for type \"%s\" failed\n",
215 aBackendInfo->bi_type, 0, 0 );
220 /* now add the backend type to the Backend Info List */
222 BackendInfo *newBackendInfo = 0;
224 /* if backendInfo == binfo no deallocation of old backendInfo */
225 if (backendInfo == binfo) {
226 newBackendInfo = ch_calloc(nBackendInfo + 1, sizeof(BackendInfo));
227 AC_MEMCPY(newBackendInfo, backendInfo, sizeof(BackendInfo) *
230 newBackendInfo = ch_realloc(backendInfo, sizeof(BackendInfo) *
233 AC_MEMCPY(&newBackendInfo[nBackendInfo], aBackendInfo,
234 sizeof(BackendInfo));
235 backendInfo = newBackendInfo;
242 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_TAILQ_INIT( &be->be_pending_csn_list );
266 LDAP_LOG( BACKEND, DETAIL1, "backend_startup: starting \"%s\"\n",
267 be->be_suffix[0].bv_val, 0, 0 );
269 Debug( LDAP_DEBUG_TRACE,
270 "backend_startup: starting \"%s\"\n",
271 be->be_suffix[0].bv_val, 0, 0 );
274 if ( be->bd_info->bi_open ) {
275 rc = be->bd_info->bi_open( be->bd_info );
278 LDAP_LOG( BACKEND, CRIT, "backend_startup: bi_open failed!\n", 0, 0, 0 );
280 Debug( LDAP_DEBUG_ANY,
281 "backend_startup: bi_open failed!\n",
289 if ( be->bd_info->bi_db_open ) {
290 rc = be->bd_info->bi_db_open( be );
293 LDAP_LOG( BACKEND, CRIT,
294 "backend_startup: bi_db_open failed! (%d)\n", rc, 0, 0 );
296 Debug( LDAP_DEBUG_ANY,
297 "backend_startup: bi_db_open failed! (%d)\n",
307 /* open each backend type */
308 for( i = 0; i < nBackendInfo; i++ ) {
309 if( backendInfo[i].bi_nDB == 0) {
310 /* no database of this type, don't open */
314 if( backendInfo[i].bi_open ) {
315 rc = backendInfo[i].bi_open(
319 LDAP_LOG( BACKEND, CRIT,
320 "backend_startup: bi_open %d failed!\n", i, 0, 0 );
322 Debug( LDAP_DEBUG_ANY,
323 "backend_startup: bi_open %d failed!\n",
331 ldap_pvt_thread_mutex_init( &syncrepl_rq.rq_mutex );
332 LDAP_STAILQ_INIT( &syncrepl_rq.task_list );
333 LDAP_STAILQ_INIT( &syncrepl_rq.run_list );
335 /* open each backend database */
336 for( i = 0; i < nBackendDB; i++ ) {
337 #ifndef SLAPD_MULTIMASTER
338 if ( backendDB[i].be_update_ndn.bv_val && (
339 !backendDB[i].be_update_refs &&
340 !backendDB[i].be_syncinfo &&
341 !default_referral ) )
344 LDAP_LOG( BACKEND, CRIT,
345 "backend_startup: slave \"%s\" updateref missing\n",
346 backendDB[i].be_suffix[0].bv_val, 0, 0 );
349 Debug( LDAP_DEBUG_ANY,
350 "backend_startup: slave \"%s\" updateref missing\n",
351 backendDB[i].be_suffix[0].bv_val, 0, 0 );
357 /* append global access controls */
358 acl_append( &backendDB[i].be_acl, global_acl );
360 LDAP_TAILQ_INIT( &backendDB[i].be_pending_csn_list );
362 if ( backendDB[i].bd_info->bi_db_open ) {
363 rc = backendDB[i].bd_info->bi_db_open(
367 LDAP_LOG( BACKEND, CRIT,
368 "backend_startup: bi_db_open(%d) failed! (%d)\n", i, rc, 0 );
370 Debug( LDAP_DEBUG_ANY,
371 "backend_startup: bi_db_open(%d) failed! (%d)\n",
378 if ( backendDB[i].be_syncinfo != NULL ) {
379 syncinfo_t *si = ( syncinfo_t * ) backendDB[i].be_syncinfo;
380 si->si_be = &backendDB[i];
382 ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
383 ldap_pvt_runqueue_insert( &syncrepl_rq, si->si_interval,
384 do_syncrepl, (void *) backendDB[i].be_syncinfo );
385 ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
392 int backend_num( Backend *be )
396 if( be == NULL ) return -1;
398 for( i = 0; i < nBackendDB; i++ ) {
399 if( be == &backendDB[i] ) return i;
404 int backend_shutdown( Backend *be )
410 /* shutdown a specific backend database */
412 if ( be->bd_info->bi_nDB == 0 ) {
413 /* no database of this type, we never opened it */
417 if ( be->bd_info->bi_db_close ) {
418 be->bd_info->bi_db_close( be );
421 if( be->bd_info->bi_close ) {
422 be->bd_info->bi_close( be->bd_info );
428 /* close each backend database */
429 for( i = 0; i < nBackendDB; i++ ) {
430 if ( backendDB[i].bd_info->bi_db_close ) {
431 backendDB[i].bd_info->bi_db_close(
437 LDAP_LOG( BACKEND, NOTICE,
438 "backend_shutdown: bi_close %s failed!\n",
439 backendDB[i].be_type, 0, 0 );
441 Debug( LDAP_DEBUG_ANY,
442 "backend_close: bi_close %s failed!\n",
443 backendDB[i].be_type, 0, 0 );
448 /* close each backend type */
449 for( i = 0; i < nBackendInfo; i++ ) {
450 if( backendInfo[i].bi_nDB == 0 ) {
451 /* no database of this type */
455 if( backendInfo[i].bi_close ) {
456 backendInfo[i].bi_close(
464 int backend_destroy(void)
469 ldap_pvt_thread_pool_destroy( &syncrepl_pool, 1 );
471 /* destroy each backend database */
472 for( i = 0, bd = backendDB; i < nBackendDB; i++, bd++ ) {
473 if ( bd->bd_info->bi_db_destroy ) {
474 bd->bd_info->bi_db_destroy( bd );
476 ber_bvarray_free( bd->be_suffix );
477 ber_bvarray_free( bd->be_nsuffix );
478 if ( bd->be_rootdn.bv_val ) free( bd->be_rootdn.bv_val );
479 if ( bd->be_rootndn.bv_val ) free( bd->be_rootndn.bv_val );
480 if ( bd->be_rootpw.bv_val ) free( bd->be_rootpw.bv_val );
481 acl_destroy( bd->be_acl, global_acl );
485 /* destroy each backend type */
486 for( i = 0; i < nBackendInfo; i++ ) {
487 if( backendInfo[i].bi_destroy ) {
488 backendInfo[i].bi_destroy(
494 if (backendInfo != binfo) {
497 #endif /* SLAPD_MODULES */
505 BackendInfo* backend_info(const char *type)
509 /* search for the backend type */
510 for( i = 0; i < nBackendInfo; i++ ) {
511 if( strcasecmp(backendInfo[i].bi_type, type) == 0 ) {
512 return &backendInfo[i];
526 BackendInfo *bi = backend_info(type);
530 fprintf( stderr, "Unrecognized database type (%s)\n", type );
534 backendDB = (BackendDB *) ch_realloc(
536 (nBackendDB + 1) * sizeof(Backend) );
538 memset( &backendDB[nbackends], '\0', sizeof(Backend) );
540 be = &backends[nbackends++];
543 be->be_def_limit = deflimit;
544 be->be_dfltaccess = global_default_access;
546 be->be_restrictops = global_restrictops;
547 be->be_requires = global_requires;
548 be->be_ssf_set = global_ssf_set;
550 be->be_context_csn.bv_len = 0;
551 be->be_context_csn.bv_val = NULL;
552 ldap_pvt_thread_mutex_init( &be->be_pcl_mutex );
553 ldap_pvt_thread_mutex_init( &be->be_context_csn_mutex );
555 be->be_syncinfo = NULL;
557 /* assign a default depth limit for alias deref */
558 be->be_max_deref_depth = SLAPD_DEFAULT_MAXDEREFDEPTH;
561 rc = bi->bi_db_init( be );
565 fprintf( stderr, "database init failed (%s)\n", type );
579 for ( i = 0; i < nbackends; i++ ) {
580 if ( backends[i].bd_info->bi_db_close ) {
581 (*backends[i].bd_info->bi_db_close)( &backends[i] );
593 ber_len_t len, dnlen = dn->bv_len;
596 for ( i = 0; i < nbackends; i++ ) {
597 for ( j = 0; backends[i].be_nsuffix != NULL &&
598 backends[i].be_nsuffix[j].bv_val != NULL; j++ )
600 if ( ( SLAP_GLUE_SUBORDINATE( &backends[i] ) )
606 len = backends[i].be_nsuffix[j].bv_len;
609 /* suffix is longer than DN */
614 * input DN is normalized, so the separator check
615 * need not look at escaping
617 if ( len && len < dnlen &&
618 !DN_SEPARATOR( dn->bv_val[(dnlen-len)-1] ))
623 if ( strcmp( backends[i].be_nsuffix[j].bv_val,
624 &dn->bv_val[dnlen-len] ) == 0 )
629 if( manageDSAit && len == dnlen &&
630 !SLAP_GLUE_SUBORDINATE( be ) ) {
647 struct berval *bvsuffix
652 for ( i = 0; be->be_nsuffix != NULL && be->be_nsuffix[i].bv_val != NULL; i++ ) {
653 if ( bvmatch( &be->be_nsuffix[i], bvsuffix ) ) {
662 be_isroot( Backend *be, struct berval *ndn )
664 if ( !ndn->bv_len ) {
668 if ( !be->be_rootndn.bv_len ) {
672 return dn_match( &be->be_rootndn, ndn );
676 be_isupdate( Backend *be, struct berval *ndn )
678 if ( !ndn->bv_len ) {
682 if ( !be->be_update_ndn.bv_len ) {
686 return dn_match( &be->be_update_ndn, ndn );
690 be_root_dn( Backend *be )
692 return &be->be_rootdn;
696 be_isroot_pw( Operation *op )
701 if ( ! be_isroot( op->o_bd, &op->o_req_ndn ) ) {
705 if( op->o_bd->be_rootpw.bv_len == 0 ) {
709 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
710 ldap_pvt_thread_mutex_lock( &passwd_mutex );
712 lutil_passwd_sasl_conn = op->o_conn->c_sasl_authctx;
716 result = lutil_passwd( &op->o_bd->be_rootpw, &op->orb_cred, NULL, NULL );
718 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
720 lutil_passwd_sasl_conn = NULL;
722 ldap_pvt_thread_mutex_unlock( &passwd_mutex );
734 if ( op->o_bd->be_release ) {
735 /* free and release entry from backend */
736 return op->o_bd->be_release( op, e, rw );
745 backend_unbind( Operation *op, SlapReply *rs )
749 for ( i = 0; i < nbackends; i++ ) {
750 #if defined( LDAP_SLAPI )
753 if ( i == 0 ) slapi_x_pblock_set_operation( op->o_pb, op );
754 slapi_pblock_set( op->o_pb, SLAPI_BACKEND, (void *)&backends[i] );
755 rc = doPluginFNs( &backends[i], SLAPI_PLUGIN_PRE_UNBIND_FN,
756 (Slapi_PBlock *)op->o_pb );
759 * A preoperation plugin failure will abort the
763 LDAP_LOG( OPERATION, INFO, "do_bind: Unbind preoperation plugin "
764 "failed\n", 0, 0, 0);
766 Debug(LDAP_DEBUG_TRACE, "do_bind: Unbind preoperation plugin "
767 "failed.\n", 0, 0, 0);
772 #endif /* defined( LDAP_SLAPI ) */
774 if ( backends[i].be_unbind ) {
775 op->o_bd = &backends[i];
776 (*backends[i].be_unbind)( op, rs );
779 #if defined( LDAP_SLAPI )
780 if ( op->o_pb && doPluginFNs( &backends[i], SLAPI_PLUGIN_POST_UNBIND_FN,
781 (Slapi_PBlock *)op->o_pb ) < 0 ) {
783 LDAP_LOG( OPERATION, INFO, "do_unbind: Unbind postoperation plugins "
784 "failed\n", 0, 0, 0);
786 Debug(LDAP_DEBUG_TRACE, "do_unbind: Unbind postoperation plugins "
787 "failed.\n", 0, 0, 0);
790 #endif /* defined( LDAP_SLAPI ) */
797 backend_connection_init(
803 for ( i = 0; i < nbackends; i++ ) {
804 if ( backends[i].be_connection_init ) {
805 (*backends[i].be_connection_init)( &backends[i], conn);
813 backend_connection_destroy(
819 for ( i = 0; i < nbackends; i++ ) {
820 if ( backends[i].be_connection_destroy ) {
821 (*backends[i].be_connection_destroy)( &backends[i], conn);
829 backend_check_controls(
833 LDAPControl **ctrls = op->o_ctrls;
834 rs->sr_err = LDAP_SUCCESS;
837 for( ; *ctrls != NULL ; ctrls++ ) {
838 if( (*ctrls)->ldctl_iscritical && !ldap_charray_inlist(
839 op->o_bd->be_controls, (*ctrls)->ldctl_oid ) )
841 rs->sr_text = "control unavailable in context";
842 rs->sr_err = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
852 backend_check_restrictions(
855 struct berval *opdata )
857 slap_mask_t restrictops;
858 slap_mask_t requires;
866 if ( backend_check_controls( op, rs ) != LDAP_SUCCESS ) {
870 restrictops = op->o_bd->be_restrictops;
871 requires = op->o_bd->be_requires;
872 ssf = &op->o_bd->be_ssf_set;
875 restrictops = global_restrictops;
876 requires = global_requires;
877 ssf = &global_ssf_set;
880 switch( op->o_tag ) {
882 opflag = SLAP_RESTRICT_OP_ADD;
886 opflag = SLAP_RESTRICT_OP_BIND;
889 case LDAP_REQ_COMPARE:
890 opflag = SLAP_RESTRICT_OP_COMPARE;
892 case LDAP_REQ_DELETE:
894 opflag = SLAP_RESTRICT_OP_DELETE;
896 case LDAP_REQ_EXTENDED:
897 opflag = SLAP_RESTRICT_OP_EXTENDED;
900 /* treat unspecified as a modify */
901 opflag = SLAP_RESTRICT_OP_MODIFY;
907 if( bvmatch( opdata, &slap_EXOP_START_TLS ) ) {
915 if( bvmatch( opdata, &slap_EXOP_WHOAMI ) ) {
920 #ifdef LDAP_EXOP_X_CANCEL
922 if ( bvmatch( opdata, &slap_EXOP_CANCEL ) ) {
928 /* treat everything else as a modify */
929 opflag = SLAP_RESTRICT_OP_MODIFY;
933 case LDAP_REQ_MODIFY:
935 opflag = SLAP_RESTRICT_OP_MODIFY;
937 case LDAP_REQ_RENAME:
939 opflag = SLAP_RESTRICT_OP_RENAME;
941 case LDAP_REQ_SEARCH:
942 opflag = SLAP_RESTRICT_OP_SEARCH;
944 case LDAP_REQ_UNBIND:
949 rs->sr_text = "restrict operations internal error";
950 rs->sr_err = LDAP_OTHER;
955 /* these checks don't apply to StartTLS */
957 rs->sr_err = LDAP_CONFIDENTIALITY_REQUIRED;
958 if( op->o_transport_ssf < ssf->sss_transport ) {
959 rs->sr_text = "transport confidentiality required";
963 if( op->o_tls_ssf < ssf->sss_tls ) {
964 rs->sr_text = "TLS confidentiality required";
969 if( op->o_tag == LDAP_REQ_BIND && opdata == NULL ) {
970 /* simple bind specific check */
971 if( op->o_ssf < ssf->sss_simple_bind ) {
972 rs->sr_text = "confidentiality required";
977 if( op->o_tag != LDAP_REQ_BIND || opdata == NULL ) {
978 /* these checks don't apply to SASL bind */
980 if( op->o_sasl_ssf < ssf->sss_sasl ) {
981 rs->sr_text = "SASL confidentiality required";
985 if( op->o_ssf < ssf->sss_ssf ) {
986 rs->sr_text = "confidentiality required";
992 if( op->o_transport_ssf < ssf->sss_update_transport ) {
993 rs->sr_text = "transport update confidentiality required";
997 if( op->o_tls_ssf < ssf->sss_update_tls ) {
998 rs->sr_text = "TLS update confidentiality required";
1002 if( op->o_sasl_ssf < ssf->sss_update_sasl ) {
1003 rs->sr_text = "SASL update confidentiality required";
1007 if( op->o_ssf < ssf->sss_update_ssf ) {
1008 rs->sr_text = "update confidentiality required";
1012 if( !( global_allows & SLAP_ALLOW_UPDATE_ANON ) &&
1013 op->o_ndn.bv_len == 0 )
1015 rs->sr_text = "modifications require authentication";
1016 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1020 #ifdef SLAP_X_LISTENER_MOD
1021 if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & ( op->o_ndn.bv_len > 0 ? S_IWUSR : S_IWOTH ) ) ) {
1022 /* no "w" mode means readonly */
1023 rs->sr_text = "modifications not allowed on this listener";
1024 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1027 #endif /* SLAP_X_LISTENER_MOD */
1032 /* these checks don't apply to Bind, StartTLS, or Unbind */
1034 if( requires & SLAP_REQUIRE_STRONG ) {
1035 /* should check mechanism */
1036 if( ( op->o_transport_ssf < ssf->sss_transport
1037 && op->o_authmech.bv_len == 0 ) || op->o_dn.bv_len == 0 )
1039 rs->sr_text = "strong authentication required";
1040 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1045 if( requires & SLAP_REQUIRE_SASL ) {
1046 if( op->o_authmech.bv_len == 0 || op->o_dn.bv_len == 0 ) {
1047 rs->sr_text = "SASL authentication required";
1048 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1053 if( requires & SLAP_REQUIRE_AUTHC ) {
1054 if( op->o_dn.bv_len == 0 ) {
1055 rs->sr_text = "authentication required";
1056 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1061 if( requires & SLAP_REQUIRE_BIND ) {
1063 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1064 version = op->o_conn->c_protocol;
1065 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1068 /* no bind has occurred */
1069 rs->sr_text = "BIND required";
1070 rs->sr_err = LDAP_OPERATIONS_ERROR;
1075 if( requires & SLAP_REQUIRE_LDAP_V3 ) {
1076 if( op->o_protocol < LDAP_VERSION3 ) {
1077 /* no bind has occurred */
1078 rs->sr_text = "operation restricted to LDAPv3 clients";
1079 rs->sr_err = LDAP_OPERATIONS_ERROR;
1084 #ifdef SLAP_X_LISTENER_MOD
1085 if ( !starttls && op->o_dn.bv_len == 0 ) {
1086 if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & S_IXOTH ) ) {
1087 /* no "x" mode means bind required */
1088 rs->sr_text = "bind required on this listener";
1089 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1094 if ( !starttls && !updateop ) {
1095 if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & ( op->o_dn.bv_len > 0 ? S_IRUSR : S_IROTH ) ) ) {
1096 /* no "r" mode means no read */
1097 rs->sr_text = "read not allowed on this listener";
1098 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1102 #endif /* SLAP_X_LISTENER_MOD */
1106 if( restrictops & opflag ) {
1107 if( restrictops == SLAP_RESTRICT_OP_READS ) {
1108 rs->sr_text = "read operations restricted";
1110 rs->sr_text = "operation restricted";
1112 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1116 rs->sr_err = LDAP_SUCCESS;
1120 int backend_check_referrals( Operation *op, SlapReply *rs )
1122 rs->sr_err = LDAP_SUCCESS;
1124 if( op->o_bd->be_chk_referrals ) {
1125 rs->sr_err = op->o_bd->be_chk_referrals( op, rs );
1127 if( rs->sr_err != LDAP_SUCCESS && rs->sr_err != LDAP_REFERRAL ) {
1128 send_ldap_result( op, rs );
1140 AttributeDescription *at,
1148 if (op->o_bd == NULL) {
1149 rc = LDAP_NO_SUCH_OBJECT;
1150 } else if ( op->o_bd->be_fetch ) {
1151 rc = ( op->o_bd->be_fetch )( op, ndn,
1154 rc = LDAP_UNWILLING_TO_PERFORM;
1163 struct berval *gr_ndn,
1164 struct berval *op_ndn,
1165 ObjectClass *group_oc,
1166 AttributeDescription *group_at
1173 Backend *be = op->o_bd;
1175 if ( op->o_abandon ) return SLAPD_ABANDON;
1177 op->o_bd = select_backend( gr_ndn, 0, 0 );
1179 for (g = op->o_groups; g; g=g->ga_next) {
1180 if (g->ga_be != op->o_bd || g->ga_oc != group_oc ||
1181 g->ga_at != group_at || g->ga_len != gr_ndn->bv_len)
1183 if (strcmp( g->ga_ndn, gr_ndn->bv_val ) == 0)
1192 if ( target && dn_match( &target->e_nname, gr_ndn ) ) {
1196 rc = be_entry_get_rw(op, gr_ndn, group_oc, group_at, 0, &e );
1199 a = attr_find( e->e_attrs, group_at );
1201 /* If the attribute is a subtype of labeledURI, treat this as
1202 * a dynamic group ala groupOfURLs
1204 if (is_at_subtype( group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ) ) {
1207 struct berval bv, nbase;
1210 Backend *b2 = op->o_bd;
1212 if ( target && dn_match( &target->e_nname, op_ndn ) ) {
1215 op->o_bd = select_backend( op_ndn, 0, 0 );
1216 rc = be_entry_get_rw(op, op_ndn, NULL, NULL, 0, &user );
1221 for (i=0; a->a_vals[i].bv_val; i++) {
1222 if ( ldap_url_parse( a->a_vals[i].bv_val, &ludp ) != LDAP_SUCCESS )
1224 nbase.bv_val = NULL;
1225 /* host part must be empty */
1226 /* attrs and extensions parts must be empty */
1227 if (( ludp->lud_host && *ludp->lud_host )
1228 || ludp->lud_attrs || ludp->lud_exts )
1230 ber_str2bv( ludp->lud_dn, 0, 0, &bv );
1231 if ( dnNormalize( 0, NULL, NULL, &bv, &nbase, op->o_tmpmemctx ) != LDAP_SUCCESS )
1233 switch(ludp->lud_scope) {
1234 case LDAP_SCOPE_BASE:
1235 if ( !dn_match(&nbase, op_ndn)) goto loopit;
1237 case LDAP_SCOPE_ONELEVEL:
1238 dnParent(op_ndn, &bv );
1239 if ( !dn_match(&nbase, &bv)) goto loopit;
1241 case LDAP_SCOPE_SUBTREE:
1242 if ( !dnIsSuffix(op_ndn, &nbase)) goto loopit;
1245 filter = str2filter_x( op, ludp->lud_filter );
1247 if ( test_filter( NULL, user, filter ) == LDAP_COMPARE_TRUE )
1251 filter_free_x( op, filter );
1254 ldap_free_urldesc( ludp );
1255 if ( nbase.bv_val ) {
1256 op->o_tmpfree( nbase.bv_val, op->o_tmpmemctx );
1258 if ( rc == 0 ) break;
1260 if ( user != target ) {
1261 be_entry_release_r( op, user );
1266 rc = value_find_ex( group_at,
1267 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1268 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1269 a->a_nvals, op_ndn, op->o_tmpmemctx );
1272 rc = LDAP_NO_SUCH_ATTRIBUTE;
1275 be_entry_release_r( op, e );
1278 rc = LDAP_NO_SUCH_OBJECT;
1281 if ( op->o_tag != LDAP_REQ_BIND && !op->o_do_not_cache ) {
1282 g = sl_malloc(sizeof(GroupAssertion) + gr_ndn->bv_len, op->o_tmpmemctx);
1283 g->ga_be = op->o_bd;
1284 g->ga_oc = group_oc;
1285 g->ga_at = group_at;
1287 g->ga_len = gr_ndn->bv_len;
1288 strcpy(g->ga_ndn, gr_ndn->bv_val);
1289 g->ga_next = op->o_groups;
1302 AttributeDescription *entry_at,
1308 int i, j, rc = LDAP_SUCCESS;
1309 AccessControlState acl_state = ACL_STATE_INIT;
1310 Backend *be = op->o_bd;
1312 op->o_bd = select_backend( edn, 0, 0 );
1314 if ( target && dn_match( &target->e_nname, edn ) ) {
1317 rc = be_entry_get_rw(op, edn, NULL, entry_at, 0, &e );
1321 a = attr_find( e->e_attrs, entry_at );
1325 if ( op->o_conn && access_allowed( op,
1326 e, entry_at, NULL, ACL_AUTH,
1327 &acl_state ) == 0 ) {
1328 rc = LDAP_INSUFFICIENT_ACCESS;
1332 for ( i=0; a->a_vals[i].bv_val; i++ ) ;
1334 v = op->o_tmpalloc( sizeof(struct berval) * (i+1), op->o_tmpmemctx );
1335 for ( i=0,j=0; a->a_vals[i].bv_val; i++ ) {
1336 if ( op->o_conn && access_allowed( op,
1339 ACL_AUTH, &acl_state ) == 0 ) {
1343 &a->a_nvals[i], op->o_tmpmemctx );
1344 if (v[j].bv_val ) j++;
1347 op->o_tmpfree( v, op->o_tmpmemctx );
1349 rc = LDAP_INSUFFICIENT_ACCESS;
1357 freeit: if (e != target ) {
1358 be_entry_release_r( op, e );
1366 Attribute *backend_operational(
1371 Attribute *a = NULL, **ap = &a;
1374 * If operational attributes (allegedly) are required,
1375 * and the backend supports specific operational attributes,
1376 * add them to the attribute list
1378 if ( opattrs || ( op->ors_attrs &&
1379 ad_inlist( slap_schema.si_ad_subschemaSubentry, op->ors_attrs )) ) {
1380 *ap = slap_operational_subschemaSubentry( op->o_bd );
1381 ap = &(*ap)->a_next;
1384 if ( ( opattrs || op->ors_attrs ) && op->o_bd && op->o_bd->be_operational != NULL ) {
1385 ( void )op->o_bd->be_operational( op, rs, opattrs, ap );