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;
132 ldap_pvt_thread_pool_t syncrepl_pool;
133 int syncrepl_pool_max = SLAP_MAX_SYNCREPL_THREADS;
136 int backend_init(void)
141 ldap_pvt_thread_pool_init( &syncrepl_pool, syncrepl_pool_max, 0 );
144 if((nBackendInfo != 0) || (backendInfo != NULL)) {
145 /* already initialized */
147 LDAP_LOG( BACKEND, ERR,
148 "backend_init: backend already initialized\n", 0, 0, 0 );
150 Debug( LDAP_DEBUG_ANY,
151 "backend_init: already initialized.\n", 0, 0, 0 );
157 binfo[nBackendInfo].bi_type != NULL;
160 rc = binfo[nBackendInfo].bi_init( &binfo[nBackendInfo] );
164 LDAP_LOG( BACKEND, INFO,
165 "backend_init: initialized for type \"%s\"\n",
166 binfo[nBackendInfo].bi_type, 0, 0 );
168 Debug( LDAP_DEBUG_ANY,
169 "backend_init: initialized for type \"%s\"\n",
170 binfo[nBackendInfo].bi_type, 0, 0 );
172 /* destroy those we've already inited */
177 if ( binfo[nBackendInfo].bi_destroy ) {
178 binfo[nBackendInfo].bi_destroy(
179 &binfo[nBackendInfo] );
186 if ( nBackendInfo > 0) {
196 LDAP_LOG( BACKEND, ERR, "backend_init: failed\n", 0, 0, 0 );
198 Debug( LDAP_DEBUG_ANY,
199 "backend_init: failed\n",
204 #endif /* SLAPD_MODULES */
207 int backend_add(BackendInfo *aBackendInfo)
211 if ((rc = aBackendInfo->bi_init(aBackendInfo)) != 0) {
213 LDAP_LOG( BACKEND, ERR,
214 "backend_add: initialization for type \"%s\" failed\n",
215 aBackendInfo->bi_type, 0, 0 );
217 Debug( LDAP_DEBUG_ANY,
218 "backend_add: initialization for type \"%s\" failed\n",
219 aBackendInfo->bi_type, 0, 0 );
224 /* now add the backend type to the Backend Info List */
226 BackendInfo *newBackendInfo = 0;
228 /* if backendInfo == binfo no deallocation of old backendInfo */
229 if (backendInfo == binfo) {
230 newBackendInfo = ch_calloc(nBackendInfo + 1, sizeof(BackendInfo));
231 AC_MEMCPY(newBackendInfo, backendInfo, sizeof(BackendInfo) *
234 newBackendInfo = ch_realloc(backendInfo, sizeof(BackendInfo) *
237 AC_MEMCPY(&newBackendInfo[nBackendInfo], aBackendInfo,
238 sizeof(BackendInfo));
239 backendInfo = newBackendInfo;
246 int backend_startup(Backend *be)
255 if( ! ( nBackendDB > 0 ) ) {
258 LDAP_LOG( BACKEND, INFO,
259 "backend_startup: %d databases to startup. \n", nBackendDB, 0, 0 );
261 Debug( LDAP_DEBUG_ANY,
262 "backend_startup: %d databases to startup.\n",
269 /* startup a specific backend database */
271 LDAP_LOG( BACKEND, DETAIL1, "backend_startup: starting \"%s\"\n",
272 be->be_suffix[0].bv_val, 0, 0 );
274 Debug( LDAP_DEBUG_TRACE,
275 "backend_startup: starting \"%s\"\n",
276 be->be_suffix[0].bv_val, 0, 0 );
279 if ( be->bd_info->bi_open ) {
280 rc = be->bd_info->bi_open( be->bd_info );
283 LDAP_LOG( BACKEND, CRIT, "backend_startup: bi_open failed!\n", 0, 0, 0 );
285 Debug( LDAP_DEBUG_ANY,
286 "backend_startup: bi_open failed!\n",
294 if ( be->bd_info->bi_db_open ) {
295 rc = be->bd_info->bi_db_open( be );
298 LDAP_LOG( BACKEND, CRIT,
299 "backend_startup: bi_db_open failed! (%d)\n", rc, 0, 0 );
301 Debug( LDAP_DEBUG_ANY,
302 "backend_startup: bi_db_open failed! (%d)\n",
312 /* open each backend type */
313 for( i = 0; i < nBackendInfo; i++ ) {
314 if( backendInfo[i].bi_nDB == 0) {
315 /* no database of this type, don't open */
319 if( backendInfo[i].bi_open ) {
320 rc = backendInfo[i].bi_open(
324 LDAP_LOG( BACKEND, CRIT,
325 "backend_startup: bi_open %d failed!\n", i, 0, 0 );
327 Debug( LDAP_DEBUG_ANY,
328 "backend_startup: bi_open %d failed!\n",
337 ldap_pvt_thread_mutex_init( &syncrepl_rq.rq_mutex );
338 LDAP_STAILQ_INIT( &syncrepl_rq.task_list );
339 LDAP_STAILQ_INIT( &syncrepl_rq.run_list );
342 /* open each backend database */
343 for( i = 0; i < nBackendDB; i++ ) {
344 /* append global access controls */
345 acl_append( &backendDB[i].be_acl, global_acl );
347 if ( backendDB[i].bd_info->bi_db_open ) {
348 rc = backendDB[i].bd_info->bi_db_open(
352 LDAP_LOG( BACKEND, CRIT,
353 "backend_startup: bi_db_open(%d) failed! (%d)\n", i, rc, 0 );
355 Debug( LDAP_DEBUG_ANY,
356 "backend_startup: bi_db_open(%d) failed! (%d)\n",
364 if ( backendDB[i].syncinfo != NULL ) {
365 syncinfo_t *si = ( syncinfo_t * ) backendDB[i].syncinfo;
366 ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
367 ldap_pvt_runqueue_insert( &syncrepl_rq, si->interval,
368 do_syncrepl, (void *) &backendDB[i] );
369 ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
377 int backend_num( Backend *be )
381 if( be == NULL ) return -1;
383 for( i = 0; i < nBackendDB; i++ ) {
384 if( be == &backendDB[i] ) return i;
389 int backend_shutdown( Backend *be )
395 /* shutdown a specific backend database */
397 if ( be->bd_info->bi_nDB == 0 ) {
398 /* no database of this type, we never opened it */
402 if ( be->bd_info->bi_db_close ) {
403 be->bd_info->bi_db_close( be );
406 if( be->bd_info->bi_close ) {
407 be->bd_info->bi_close( be->bd_info );
413 /* close each backend database */
414 for( i = 0; i < nBackendDB; i++ ) {
415 if ( backendDB[i].bd_info->bi_db_close ) {
416 backendDB[i].bd_info->bi_db_close(
422 LDAP_LOG( BACKEND, NOTICE,
423 "backend_shutdown: bi_close %s failed!\n",
424 backendDB[i].be_type, 0, 0 );
426 Debug( LDAP_DEBUG_ANY,
427 "backend_close: bi_close %s failed!\n",
428 backendDB[i].be_type, 0, 0 );
433 /* close each backend type */
434 for( i = 0; i < nBackendInfo; i++ ) {
435 if( backendInfo[i].bi_nDB == 0 ) {
436 /* no database of this type */
440 if( backendInfo[i].bi_close ) {
441 backendInfo[i].bi_close(
449 int backend_destroy(void)
455 ldap_pvt_thread_pool_destroy( &syncrepl_pool, 1 );
458 /* destroy each backend database */
459 for( i = 0, bd = backendDB; i < nBackendDB; i++, bd++ ) {
460 if ( bd->bd_info->bi_db_destroy ) {
461 bd->bd_info->bi_db_destroy( bd );
463 ber_bvarray_free( bd->be_suffix );
464 ber_bvarray_free( bd->be_nsuffix );
465 if ( bd->be_rootdn.bv_val ) free( bd->be_rootdn.bv_val );
466 if ( bd->be_rootndn.bv_val ) free( bd->be_rootndn.bv_val );
467 if ( bd->be_rootpw.bv_val ) free( bd->be_rootpw.bv_val );
468 acl_destroy( bd->be_acl, global_acl );
472 /* destroy each backend type */
473 for( i = 0; i < nBackendInfo; i++ ) {
474 if( backendInfo[i].bi_destroy ) {
475 backendInfo[i].bi_destroy(
481 if (backendInfo != binfo) {
484 #endif /* SLAPD_MODULES */
492 BackendInfo* backend_info(const char *type)
496 /* search for the backend type */
497 for( i = 0; i < nBackendInfo; i++ ) {
498 if( strcasecmp(backendInfo[i].bi_type, type) == 0 ) {
499 return &backendInfo[i];
513 BackendInfo *bi = backend_info(type);
517 fprintf( stderr, "Unrecognized database type (%s)\n", type );
521 backendDB = (BackendDB *) ch_realloc(
523 (nBackendDB + 1) * sizeof(Backend) );
525 memset( &backendDB[nbackends], '\0', sizeof(Backend) );
527 be = &backends[nbackends++];
530 be->be_def_limit = deflimit;
531 be->be_dfltaccess = global_default_access;
533 be->be_restrictops = global_restrictops;
534 be->be_requires = global_requires;
535 be->be_ssf_set = global_ssf_set;
541 /* assign a default depth limit for alias deref */
542 be->be_max_deref_depth = SLAPD_DEFAULT_MAXDEREFDEPTH;
545 rc = bi->bi_db_init( be );
549 fprintf( stderr, "database init failed (%s)\n", type );
563 for ( i = 0; i < nbackends; i++ ) {
564 if ( backends[i].bd_info->bi_db_close ) {
565 (*backends[i].bd_info->bi_db_close)( &backends[i] );
577 ber_len_t len, dnlen = dn->bv_len;
580 for ( i = 0; i < nbackends; i++ ) {
581 for ( j = 0; backends[i].be_nsuffix != NULL &&
582 backends[i].be_nsuffix[j].bv_val != NULL; j++ )
584 if ( ( SLAP_GLUE_SUBORDINATE( &backends[i] ) )
590 len = backends[i].be_nsuffix[j].bv_len;
593 /* suffix is longer than DN */
598 * input DN is normalized, so the separator check
599 * need not look at escaping
601 if ( len && len < dnlen &&
602 !DN_SEPARATOR( dn->bv_val[(dnlen-len)-1] ))
607 if ( strcmp( backends[i].be_nsuffix[j].bv_val,
608 &dn->bv_val[dnlen-len] ) == 0 )
613 if( manageDSAit && len == dnlen ) {
630 struct berval *bvsuffix
635 for ( i = 0; be->be_nsuffix != NULL && be->be_nsuffix[i].bv_val != NULL; i++ ) {
636 if ( bvmatch( &be->be_nsuffix[i], bvsuffix ) ) {
645 be_isroot( Backend *be, struct berval *ndn )
647 if ( !ndn->bv_len ) {
651 if ( !be->be_rootndn.bv_len ) {
655 return dn_match( &be->be_rootndn, ndn );
659 be_isupdate( Backend *be, struct berval *ndn )
661 if ( !ndn->bv_len ) {
665 if ( !be->be_update_ndn.bv_len ) {
669 return dn_match( &be->be_update_ndn, ndn );
673 be_root_dn( Backend *be )
675 return &be->be_rootdn;
679 be_isroot_pw( Operation *op )
684 if ( ! be_isroot( op->o_bd, &op->o_req_ndn ) ) {
688 if( op->o_bd->be_rootpw.bv_len == 0 ) {
692 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
693 ldap_pvt_thread_mutex_lock( &passwd_mutex );
695 lutil_passwd_sasl_conn = op->o_conn->c_sasl_authctx;
699 result = lutil_passwd( &op->o_bd->be_rootpw, &op->orb_cred, NULL, NULL );
701 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
703 lutil_passwd_sasl_conn = NULL;
705 ldap_pvt_thread_mutex_unlock( &passwd_mutex );
717 if ( op->o_bd->be_release ) {
718 /* free and release entry from backend */
719 return op->o_bd->be_release( op, e, rw );
728 backend_unbind( Operation *op, SlapReply *rs )
731 #if defined( LDAP_SLAPI )
732 Slapi_PBlock *pb = op->o_pb;
735 slapi_x_pblock_set_operation( pb, op );
736 #endif /* defined( LDAP_SLAPI ) */
738 for ( i = 0; i < nbackends; i++ ) {
739 #if defined( LDAP_SLAPI )
740 slapi_pblock_set( pb, SLAPI_BACKEND, (void *)&backends[i] );
741 rc = doPluginFNs( &backends[i], SLAPI_PLUGIN_PRE_UNBIND_FN,
742 (Slapi_PBlock *)pb );
745 * A preoperation plugin failure will abort the
749 LDAP_LOG( OPERATION, INFO, "do_bind: Unbind preoperation plugin "
750 "failed\n", 0, 0, 0);
752 Debug(LDAP_DEBUG_TRACE, "do_bind: Unbind preoperation plugin "
753 "failed.\n", 0, 0, 0);
757 #endif /* defined( LDAP_SLAPI ) */
759 if ( backends[i].be_unbind ) {
760 op->o_bd = &backends[i];
761 (*backends[i].be_unbind)( op, rs );
764 #if defined( LDAP_SLAPI )
765 if ( doPluginFNs( &backends[i], SLAPI_PLUGIN_POST_UNBIND_FN,
766 (Slapi_PBlock *)pb ) < 0 ) {
768 LDAP_LOG( OPERATION, INFO, "do_unbind: Unbind postoperation plugins "
769 "failed\n", 0, 0, 0);
771 Debug(LDAP_DEBUG_TRACE, "do_unbind: Unbind postoperation plugins "
772 "failed.\n", 0, 0, 0);
775 #endif /* defined( LDAP_SLAPI ) */
782 backend_connection_init(
788 for ( i = 0; i < nbackends; i++ ) {
789 if ( backends[i].be_connection_init ) {
790 (*backends[i].be_connection_init)( &backends[i], conn);
798 backend_connection_destroy(
804 for ( i = 0; i < nbackends; i++ ) {
805 if ( backends[i].be_connection_destroy ) {
806 (*backends[i].be_connection_destroy)( &backends[i], conn);
814 backend_check_controls(
818 LDAPControl **ctrls = op->o_ctrls;
819 rs->sr_err = LDAP_SUCCESS;
822 for( ; *ctrls != NULL ; ctrls++ ) {
823 if( (*ctrls)->ldctl_iscritical &&
824 !ldap_charray_inlist( op->o_bd->be_controls, (*ctrls)->ldctl_oid ) )
826 rs->sr_text = "control unavailable in context";
827 rs->sr_err = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
837 backend_check_restrictions(
840 struct berval *opdata )
842 slap_mask_t restrictops;
843 slap_mask_t requires;
851 if ( backend_check_controls( op, rs ) != LDAP_SUCCESS ) {
855 restrictops = op->o_bd->be_restrictops;
856 requires = op->o_bd->be_requires;
857 ssf = &op->o_bd->be_ssf_set;
860 restrictops = global_restrictops;
861 requires = global_requires;
862 ssf = &global_ssf_set;
865 switch( op->o_tag ) {
867 opflag = SLAP_RESTRICT_OP_ADD;
871 opflag = SLAP_RESTRICT_OP_BIND;
874 case LDAP_REQ_COMPARE:
875 opflag = SLAP_RESTRICT_OP_COMPARE;
877 case LDAP_REQ_DELETE:
879 opflag = SLAP_RESTRICT_OP_DELETE;
881 case LDAP_REQ_EXTENDED:
882 opflag = SLAP_RESTRICT_OP_EXTENDED;
885 /* treat unspecified as a modify */
886 opflag = SLAP_RESTRICT_OP_MODIFY;
892 if( bvmatch( opdata, &slap_EXOP_START_TLS ) ) {
900 if( bvmatch( opdata, &slap_EXOP_WHOAMI ) ) {
905 #ifdef LDAP_EXOP_X_CANCEL
907 if ( bvmatch( opdata, &slap_EXOP_CANCEL ) ) {
913 /* treat everything else as a modify */
914 opflag = SLAP_RESTRICT_OP_MODIFY;
918 case LDAP_REQ_MODIFY:
920 opflag = SLAP_RESTRICT_OP_MODIFY;
922 case LDAP_REQ_RENAME:
924 opflag = SLAP_RESTRICT_OP_RENAME;
926 case LDAP_REQ_SEARCH:
927 opflag = SLAP_RESTRICT_OP_SEARCH;
929 case LDAP_REQ_UNBIND:
934 rs->sr_text = "restrict operations internal error";
935 rs->sr_err = LDAP_OTHER;
940 /* these checks don't apply to StartTLS */
942 rs->sr_err = LDAP_CONFIDENTIALITY_REQUIRED;
943 if( op->o_transport_ssf < ssf->sss_transport ) {
944 rs->sr_text = "transport confidentiality required";
948 if( op->o_tls_ssf < ssf->sss_tls ) {
949 rs->sr_text = "TLS confidentiality required";
954 if( op->o_tag == LDAP_REQ_BIND && opdata == NULL ) {
955 /* simple bind specific check */
956 if( op->o_ssf < ssf->sss_simple_bind ) {
957 rs->sr_text = "confidentiality required";
962 if( op->o_tag != LDAP_REQ_BIND || opdata == NULL ) {
963 /* these checks don't apply to SASL bind */
965 if( op->o_sasl_ssf < ssf->sss_sasl ) {
966 rs->sr_text = "SASL confidentiality required";
970 if( op->o_ssf < ssf->sss_ssf ) {
971 rs->sr_text = "confidentiality required";
977 if( op->o_transport_ssf < ssf->sss_update_transport ) {
978 rs->sr_text = "transport update confidentiality required";
982 if( op->o_tls_ssf < ssf->sss_update_tls ) {
983 rs->sr_text = "TLS update confidentiality required";
987 if( op->o_sasl_ssf < ssf->sss_update_sasl ) {
988 rs->sr_text = "SASL update confidentiality required";
992 if( op->o_ssf < ssf->sss_update_ssf ) {
993 rs->sr_text = "update confidentiality required";
997 if( !( global_allows & SLAP_ALLOW_UPDATE_ANON ) &&
998 op->o_ndn.bv_len == 0 )
1000 rs->sr_text = "modifications require authentication";
1001 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1005 #ifdef SLAP_X_LISTENER_MOD
1006 if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & ( op->o_ndn.bv_len > 0 ? S_IWUSR : S_IWOTH ) ) ) {
1007 /* no "w" mode means readonly */
1008 rs->sr_text = "modifications not allowed on this listener";
1009 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1012 #endif /* SLAP_X_LISTENER_MOD */
1017 /* these checks don't apply to Bind, StartTLS, or Unbind */
1019 if( requires & SLAP_REQUIRE_STRONG ) {
1020 /* should check mechanism */
1021 if( ( op->o_transport_ssf < ssf->sss_transport
1022 && op->o_authmech.bv_len == 0 ) || op->o_dn.bv_len == 0 )
1024 rs->sr_text = "strong authentication required";
1025 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1030 if( requires & SLAP_REQUIRE_SASL ) {
1031 if( op->o_authmech.bv_len == 0 || op->o_dn.bv_len == 0 ) {
1032 rs->sr_text = "SASL authentication required";
1033 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1038 if( requires & SLAP_REQUIRE_AUTHC ) {
1039 if( op->o_dn.bv_len == 0 ) {
1040 rs->sr_text = "authentication required";
1041 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1046 if( requires & SLAP_REQUIRE_BIND ) {
1048 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1049 version = op->o_conn->c_protocol;
1050 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1053 /* no bind has occurred */
1054 rs->sr_text = "BIND required";
1055 rs->sr_err = LDAP_OPERATIONS_ERROR;
1060 if( requires & SLAP_REQUIRE_LDAP_V3 ) {
1061 if( op->o_protocol < LDAP_VERSION3 ) {
1062 /* no bind has occurred */
1063 rs->sr_text = "operation restricted to LDAPv3 clients";
1064 rs->sr_err = LDAP_OPERATIONS_ERROR;
1069 #ifdef SLAP_X_LISTENER_MOD
1070 if ( !starttls && op->o_dn.bv_len == 0 ) {
1071 if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & S_IXOTH ) ) {
1072 /* no "x" mode means bind required */
1073 rs->sr_text = "bind required on this listener";
1074 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1079 if ( !starttls && !updateop ) {
1080 if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & ( op->o_dn.bv_len > 0 ? S_IRUSR : S_IROTH ) ) ) {
1081 /* no "r" mode means no read */
1082 rs->sr_text = "read not allowed on this listener";
1083 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1087 #endif /* SLAP_X_LISTENER_MOD */
1091 if( restrictops & opflag ) {
1092 if( restrictops == SLAP_RESTRICT_OP_READS ) {
1093 rs->sr_text = "read operations restricted";
1095 rs->sr_text = "operation restricted";
1097 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1101 rs->sr_err = LDAP_SUCCESS;
1105 int backend_check_referrals( Operation *op, SlapReply *rs )
1107 rs->sr_err = LDAP_SUCCESS;
1109 if( op->o_bd->be_chk_referrals ) {
1110 rs->sr_err = op->o_bd->be_chk_referrals( op, rs );
1112 if( rs->sr_err != LDAP_SUCCESS && rs->sr_err != LDAP_REFERRAL ) {
1113 send_ldap_result( op, rs );
1125 AttributeDescription *at,
1129 Backend *be = op->o_bd;
1134 op->o_bd = select_backend( ndn, 0, 0 );
1136 if (op->o_bd == NULL) {
1137 rc = LDAP_NO_SUCH_OBJECT;
1138 } else if ( op->o_bd->be_fetch ) {
1139 rc = ( op->o_bd->be_fetch )( op, ndn,
1142 rc = LDAP_UNWILLING_TO_PERFORM;
1152 struct berval *gr_ndn,
1153 struct berval *op_ndn,
1154 ObjectClass *group_oc,
1155 AttributeDescription *group_at
1163 if ( op->o_abandon ) return SLAPD_ABANDON;
1165 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1167 for (g = op->o_conn->c_groups; g; g=g->ga_next) {
1168 if (g->ga_be != op->o_bd || g->ga_oc != group_oc ||
1169 g->ga_at != group_at || g->ga_len != gr_ndn->bv_len)
1171 if (strcmp( g->ga_ndn, gr_ndn->bv_val ) == 0)
1175 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1181 if ( target && dn_match( &target->e_nname, gr_ndn ) ) {
1184 rc = be_entry_get_rw(op, gr_ndn, group_oc, group_at, 0, &e );
1187 a = attr_find( e->e_attrs, group_at );
1189 rc = value_find_ex( group_at,
1190 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1191 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1192 a->a_nvals, op_ndn, op->o_tmpmemctx );
1194 rc = LDAP_NO_SUCH_ATTRIBUTE;
1197 be_entry_release_r( op, e );
1200 rc = LDAP_NO_SUCH_OBJECT;
1203 if ( op->o_tag != LDAP_REQ_BIND && !op->o_do_not_cache ) {
1204 g = ch_malloc(sizeof(GroupAssertion) + gr_ndn->bv_len);
1205 g->ga_be = op->o_bd;
1206 g->ga_oc = group_oc;
1207 g->ga_at = group_at;
1209 g->ga_len = gr_ndn->bv_len;
1210 strcpy(g->ga_ndn, gr_ndn->bv_val);
1211 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1212 g->ga_next = op->o_conn->c_groups;
1213 op->o_conn->c_groups = g;
1214 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1225 AttributeDescription *entry_at,
1231 int i, j, rc = LDAP_SUCCESS;
1232 AccessControlState acl_state = ACL_STATE_INIT;
1234 if ( target && dn_match( &target->e_nname, edn ) ) {
1237 rc = be_entry_get_rw(op, edn, NULL, entry_at, 0, &e );
1238 if ( rc != LDAP_SUCCESS ) return rc;
1242 a = attr_find( e->e_attrs, entry_at );
1246 if ( op->o_conn && access_allowed( op,
1247 e, entry_at, NULL, ACL_AUTH,
1248 &acl_state ) == 0 ) {
1249 rc = LDAP_INSUFFICIENT_ACCESS;
1253 for ( i=0; a->a_vals[i].bv_val; i++ ) ;
1255 v = op->o_tmpalloc( sizeof(struct berval) * (i+1), op->o_tmpmemctx );
1256 for ( i=0,j=0; a->a_vals[i].bv_val; i++ ) {
1257 if ( op->o_conn && access_allowed( op,
1260 ACL_AUTH, &acl_state ) == 0 ) {
1264 &a->a_nvals[i], op->o_tmpmemctx );
1265 if (v[j].bv_val ) j++;
1268 op->o_tmpfree( v, op->o_tmpmemctx );
1270 rc = LDAP_INSUFFICIENT_ACCESS;
1278 freeit: if (e != target ) {
1279 be_entry_release_r( op, e );
1286 Attribute *backend_operational(
1291 Attribute *a = NULL, **ap = &a;
1294 * If operational attributes (allegedly) are required,
1295 * and the backend supports specific operational attributes,
1296 * add them to the attribute list
1298 if ( opattrs || ( op->ors_attrs &&
1299 ad_inlist( slap_schema.si_ad_subschemaSubentry, op->ors_attrs )) ) {
1300 *ap = slap_operational_subschemaSubentry( op->o_bd );
1301 ap = &(*ap)->a_next;
1304 if ( ( opattrs || op->ors_attrs ) && op->o_bd && op->o_bd->be_operational != NULL ) {
1305 ( void )op->o_bd->be_operational( op, rs, opattrs, ap );