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 */
12 #include <ac/string.h>
13 #include <ac/socket.h>
22 * If a module is configured as dynamic, its header should not
23 * get included into slapd. While this is a general rule and does
24 * not have much of an effect in UNIX, this rule should be adhered
25 * to for Windows, where dynamic object code should not be implicitly
26 * imported into slapd without appropriate __declspec(dllimport) directives.
29 #if defined(SLAPD_BDB) && !defined(SLAPD_BDB_DYNAMIC)
30 #include "back-bdb/external.h"
32 #if defined(SLAPD_DNSSRV) && !defined(SLAPD_DNSSRV_DYNAMIC)
33 #include "back-dnssrv/external.h"
35 #if defined(SLAPD_LDAP) && !defined(SLAPD_LDAP_DYNAMIC)
36 #include "back-ldap/external.h"
38 #if defined(SLAPD_LDBM) && !defined(SLAPD_LDBM_DYNAMIC)
39 #include "back-ldbm/external.h"
41 #if defined(SLAPD_META) && !defined(SLAPD_META_DYNAMIC)
42 #include "back-meta/external.h"
44 #if defined(SLAPD_MONITOR) && !defined(SLAPD_MONITOR_DYNAMIC)
45 #include "back-monitor/external.h"
47 #if defined(SLAPD_NULL) && !defined(SLAPD_NULL_DYNAMIC)
48 #include "back-null/external.h"
50 #if defined(SLAPD_PASSWD) && !defined(SLAPD_PASSWD_DYNAMIC)
51 #include "back-passwd/external.h"
53 #if defined(SLAPD_PERL) && !defined(SLAPD_PERL_DYNAMIC)
54 #include "back-perl/external.h"
56 #if defined(SLAPD_SHELL) && !defined(SLAPD_SHELL_DYNAMIC)
57 #include "back-shell/external.h"
59 #if defined(SLAPD_TCL) && !defined(SLAPD_TCL_DYNAMIC)
60 #include "back-tcl/external.h"
62 #if defined(SLAPD_SQL) && !defined(SLAPD_SQL_DYNAMIC)
63 #include "back-sql/external.h"
65 #if defined(SLAPD_PRIVATE) && !defined(SLAPD_PRIVATE_DYNAMIC)
66 #include "private/external.h"
69 static BackendInfo binfo[] = {
70 #if defined(SLAPD_BDB) && !defined(SLAPD_BDB_DYNAMIC)
71 {"bdb", bdb_initialize},
73 #if defined(SLAPD_DNSSRV) && !defined(SLAPD_DNSSRV_DYNAMIC)
74 {"dnssrv", dnssrv_back_initialize},
76 #if defined(SLAPD_LDAP) && !defined(SLAPD_LDAP_DYNAMIC)
77 {"ldap", ldap_back_initialize},
79 #if defined(SLAPD_LDBM) && !defined(SLAPD_LDBM_DYNAMIC)
80 {"ldbm", ldbm_back_initialize},
82 #if defined(SLAPD_META) && !defined(SLAPD_META_DYNAMIC)
83 {"meta", meta_back_initialize},
85 #if defined(SLAPD_MONITOR) && !defined(SLAPD_MONITOR_DYNAMIC)
86 {"monitor", monitor_back_initialize},
88 #if defined(SLAPD_NULL) && !defined(SLAPD_NULL_DYNAMIC)
89 {"null", null_back_initialize},
91 #if defined(SLAPD_PASSWD) && !defined(SLAPD_PASSWD_DYNAMIC)
92 {"passwd", passwd_back_initialize},
94 #if defined(SLAPD_PERL) && !defined(SLAPD_PERL_DYNAMIC)
95 {"perl", perl_back_initialize},
97 #if defined(SLAPD_SHELL) && !defined(SLAPD_SHELL_DYNAMIC)
98 {"shell", shell_back_initialize},
100 #if defined(SLAPD_TCL) && !defined(SLAPD_TCL_DYNAMIC)
101 {"tcl", tcl_back_initialize},
103 #if defined(SLAPD_SQL) && !defined(SLAPD_SQL_DYNAMIC)
104 {"sql", sql_back_initialize},
106 /* for any private backend */
107 #if defined(SLAPD_PRIVATE) && !defined(SLAPD_PRIVATE_DYNAMIC)
108 {"private", private_back_initialize},
113 int nBackendInfo = 0;
114 BackendInfo *backendInfo = NULL;
117 BackendDB *backendDB = NULL;
119 int backend_init(void)
123 if((nBackendInfo != 0) || (backendInfo != NULL)) {
124 /* already initialized */
126 LDAP_LOG( BACKEND, ERR,
127 "backend_init: backend already initialized\n", 0, 0, 0 );
129 Debug( LDAP_DEBUG_ANY,
130 "backend_init: already initialized.\n", 0, 0, 0 );
136 binfo[nBackendInfo].bi_type != NULL;
139 rc = binfo[nBackendInfo].bi_init( &binfo[nBackendInfo] );
143 LDAP_LOG( BACKEND, INFO,
144 "backend_init: initialized for type \"%s\"\n",
145 binfo[nBackendInfo].bi_type, 0, 0 );
147 Debug( LDAP_DEBUG_ANY,
148 "backend_init: initialized for type \"%s\"\n",
149 binfo[nBackendInfo].bi_type, 0, 0 );
151 /* destroy those we've already inited */
156 if ( binfo[nBackendInfo].bi_destroy ) {
157 binfo[nBackendInfo].bi_destroy(
158 &binfo[nBackendInfo] );
165 if ( nBackendInfo > 0) {
175 LDAP_LOG( BACKEND, ERR, "backend_init: failed\n", 0, 0, 0 );
177 Debug( LDAP_DEBUG_ANY,
178 "backend_init: failed\n",
183 #endif /* SLAPD_MODULES */
186 int backend_add(BackendInfo *aBackendInfo)
190 if ((rc = aBackendInfo->bi_init(aBackendInfo)) != 0) {
192 LDAP_LOG( BACKEND, ERR,
193 "backend_add: initialization for type \"%s\" failed\n",
194 aBackendInfo->bi_type, 0, 0 );
196 Debug( LDAP_DEBUG_ANY,
197 "backend_add: initialization for type \"%s\" failed\n",
198 aBackendInfo->bi_type, 0, 0 );
203 /* now add the backend type to the Backend Info List */
205 BackendInfo *newBackendInfo = 0;
207 /* if backendInfo == binfo no deallocation of old backendInfo */
208 if (backendInfo == binfo) {
209 newBackendInfo = ch_calloc(nBackendInfo + 1, sizeof(BackendInfo));
210 AC_MEMCPY(newBackendInfo, backendInfo, sizeof(BackendInfo) *
213 newBackendInfo = ch_realloc(backendInfo, sizeof(BackendInfo) *
216 AC_MEMCPY(&newBackendInfo[nBackendInfo], aBackendInfo,
217 sizeof(BackendInfo));
218 backendInfo = newBackendInfo;
225 int backend_startup(Backend *be)
230 if( ! ( nBackendDB > 0 ) ) {
233 LDAP_LOG( BACKEND, INFO,
234 "backend_startup: %d databases to startup. \n", nBackendDB, 0, 0 );
236 Debug( LDAP_DEBUG_ANY,
237 "backend_startup: %d databases to startup.\n",
244 /* startup a specific backend database */
246 LDAP_LOG( BACKEND, DETAIL1, "backend_startup: starting \"%s\"\n",
247 be->be_suffix[0].bv_val, 0, 0 );
249 Debug( LDAP_DEBUG_TRACE,
250 "backend_startup: starting \"%s\"\n",
251 be->be_suffix[0].bv_val, 0, 0 );
254 if ( be->bd_info->bi_open ) {
255 rc = be->bd_info->bi_open( be->bd_info );
258 LDAP_LOG( BACKEND, CRIT, "backend_startup: bi_open failed!\n", 0, 0, 0 );
260 Debug( LDAP_DEBUG_ANY,
261 "backend_startup: bi_open failed!\n",
269 if ( be->bd_info->bi_db_open ) {
270 rc = be->bd_info->bi_db_open( be );
273 LDAP_LOG( BACKEND, CRIT,
274 "backend_startup: bi_db_open failed! (%d)\n", rc, 0, 0 );
276 Debug( LDAP_DEBUG_ANY,
277 "backend_startup: bi_db_open failed! (%d)\n",
287 /* open each backend type */
288 for( i = 0; i < nBackendInfo; i++ ) {
289 if( backendInfo[i].bi_nDB == 0) {
290 /* no database of this type, don't open */
294 if( backendInfo[i].bi_open ) {
295 rc = backendInfo[i].bi_open(
299 LDAP_LOG( BACKEND, CRIT,
300 "backend_startup: bi_open %d failed!\n", i, 0, 0 );
302 Debug( LDAP_DEBUG_ANY,
303 "backend_startup: bi_open %d failed!\n",
311 /* open each backend database */
312 for( i = 0; i < nBackendDB; i++ ) {
313 /* append global access controls */
314 acl_append( &backendDB[i].be_acl, global_acl );
316 if ( backendDB[i].bd_info->bi_db_open ) {
317 rc = backendDB[i].bd_info->bi_db_open(
321 LDAP_LOG( BACKEND, CRIT,
322 "backend_startup: bi_db_open(%d) failed! (%d)\n", i, rc, 0 );
324 Debug( LDAP_DEBUG_ANY,
325 "backend_startup: bi_db_open(%d) failed! (%d)\n",
336 int backend_num( Backend *be )
340 if( be == NULL ) return -1;
342 for( i = 0; i < nBackendDB; i++ ) {
343 if( be == &backendDB[i] ) return i;
348 int backend_shutdown( Backend *be )
354 /* shutdown a specific backend database */
356 if ( be->bd_info->bi_nDB == 0 ) {
357 /* no database of this type, we never opened it */
361 if ( be->bd_info->bi_db_close ) {
362 be->bd_info->bi_db_close( be );
365 if( be->bd_info->bi_close ) {
366 be->bd_info->bi_close( be->bd_info );
372 /* close each backend database */
373 for( i = 0; i < nBackendDB; i++ ) {
374 if ( backendDB[i].bd_info->bi_db_close ) {
375 backendDB[i].bd_info->bi_db_close(
381 LDAP_LOG( BACKEND, NOTICE,
382 "backend_shutdown: bi_close %s failed!\n",
383 backendDB[i].be_type, 0, 0 );
385 Debug( LDAP_DEBUG_ANY,
386 "backend_close: bi_close %s failed!\n",
387 backendDB[i].be_type, 0, 0 );
392 /* close each backend type */
393 for( i = 0; i < nBackendInfo; i++ ) {
394 if( backendInfo[i].bi_nDB == 0 ) {
395 /* no database of this type */
399 if( backendInfo[i].bi_close ) {
400 backendInfo[i].bi_close(
408 int backend_destroy(void)
413 /* destroy each backend database */
414 for( i = 0, bd = backendDB; i < nBackendDB; i++, bd++ ) {
415 if ( bd->bd_info->bi_db_destroy ) {
416 bd->bd_info->bi_db_destroy( bd );
418 ber_bvarray_free( bd->be_suffix );
419 ber_bvarray_free( bd->be_nsuffix );
420 if ( bd->be_rootdn.bv_val ) free( bd->be_rootdn.bv_val );
421 if ( bd->be_rootndn.bv_val ) free( bd->be_rootndn.bv_val );
422 if ( bd->be_rootpw.bv_val ) free( bd->be_rootpw.bv_val );
423 acl_destroy( bd->be_acl, global_acl );
427 /* destroy each backend type */
428 for( i = 0; i < nBackendInfo; i++ ) {
429 if( backendInfo[i].bi_destroy ) {
430 backendInfo[i].bi_destroy(
436 if (backendInfo != binfo) {
439 #endif /* SLAPD_MODULES */
447 BackendInfo* backend_info(const char *type)
451 /* search for the backend type */
452 for( i = 0; i < nBackendInfo; i++ ) {
453 if( strcasecmp(backendInfo[i].bi_type, type) == 0 ) {
454 return &backendInfo[i];
468 BackendInfo *bi = backend_info(type);
472 fprintf( stderr, "Unrecognized database type (%s)\n", type );
476 backendDB = (BackendDB *) ch_realloc(
478 (nBackendDB + 1) * sizeof(Backend) );
480 memset( &backendDB[nbackends], '\0', sizeof(Backend) );
482 be = &backends[nbackends++];
485 be->be_def_limit = deflimit;
486 be->be_dfltaccess = global_default_access;
488 be->be_restrictops = global_restrictops;
489 be->be_requires = global_requires;
490 be->be_ssf_set = global_ssf_set;
492 /* assign a default depth limit for alias deref */
493 be->be_max_deref_depth = SLAPD_DEFAULT_MAXDEREFDEPTH;
496 rc = bi->bi_db_init( be );
500 fprintf( stderr, "database init failed (%s)\n", type );
514 for ( i = 0; i < nbackends; i++ ) {
515 if ( backends[i].bd_info->bi_db_close ) {
516 (*backends[i].bd_info->bi_db_close)( &backends[i] );
528 ber_len_t len, dnlen = dn->bv_len;
531 for ( i = 0; i < nbackends; i++ ) {
532 for ( j = 0; backends[i].be_nsuffix != NULL &&
533 backends[i].be_nsuffix[j].bv_val != NULL; j++ )
535 if (( backends[i].be_flags & SLAP_BFLAG_GLUE_SUBORDINATE )
541 len = backends[i].be_nsuffix[j].bv_len;
544 /* suffix is longer than DN */
549 * input DN is normalized, so the separator check
550 * need not look at escaping
552 if ( len && len < dnlen &&
553 !DN_SEPARATOR( dn->bv_val[(dnlen-len)-1] ))
558 if ( strcmp( backends[i].be_nsuffix[j].bv_val,
559 &dn->bv_val[dnlen-len] ) == 0 )
564 if( manageDSAit && len == dnlen ) {
581 struct berval *bvsuffix
586 for ( i = 0; be->be_nsuffix != NULL && be->be_nsuffix[i].bv_val != NULL; i++ ) {
587 if ( bvmatch( &be->be_nsuffix[i], bvsuffix ) ) {
596 be_isroot( Backend *be, struct berval *ndn )
598 if ( !ndn->bv_len ) {
602 if ( !be->be_rootndn.bv_len ) {
606 return dn_match( &be->be_rootndn, ndn );
610 be_isupdate( Backend *be, struct berval *ndn )
612 if ( !ndn->bv_len ) {
616 if ( !be->be_update_ndn.bv_len ) {
620 return dn_match( &be->be_update_ndn, ndn );
624 be_root_dn( Backend *be )
626 return &be->be_rootdn;
630 be_isroot_pw( Backend *be,
633 struct berval *cred )
637 if ( ! be_isroot( be, ndn ) ) {
641 if( be->be_rootpw.bv_len == 0 ) {
645 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
646 ldap_pvt_thread_mutex_lock( &passwd_mutex );
648 lutil_passwd_sasl_conn = conn->c_sasl_context;
652 result = lutil_passwd( &be->be_rootpw, cred, NULL );
654 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
656 lutil_passwd_sasl_conn = NULL;
658 ldap_pvt_thread_mutex_unlock( &passwd_mutex );
672 if ( be->be_release ) {
673 /* free and release entry from backend */
674 return be->be_release( be, conn, op, e, rw );
689 Slapi_PBlock *pb = op->o_pb;
691 #if defined( LDAP_SLAPI )
693 slapi_x_connection_set_pb( pb, conn );
694 slapi_x_operation_set_pb( pb, op );
695 #endif /* defined( LDAP_SLAPI ) */
697 for ( i = 0; i < nbackends; i++ ) {
698 #if defined( LDAP_SLAPI )
699 slapi_pblock_set( pb, SLAPI_BACKEND, (void *)&backends[i] );
700 rc = doPluginFNs( &backends[i], SLAPI_PLUGIN_PRE_UNBIND_FN,
701 (Slapi_PBlock *)pb );
704 * A preoperation plugin failure will abort the
708 LDAP_LOG( OPERATION, INFO, "do_bind: Unbind preoperation plugin "
709 "failed\n", 0, 0, 0);
711 Debug(LDAP_DEBUG_TRACE, "do_bind: Unbind preoperation plugin "
712 "failed.\n", 0, 0, 0);
716 #endif /* defined( LDAP_SLAPI ) */
718 if ( backends[i].be_unbind ) {
719 (*backends[i].be_unbind)( &backends[i], conn, op );
722 #if defined( LDAP_SLAPI )
723 if ( doPluginFNs( &backends[i], SLAPI_PLUGIN_POST_UNBIND_FN,
724 (Slapi_PBlock *)pb ) != 0 ) {
726 LDAP_LOG( OPERATION, INFO, "do_unbind: Unbind postoperation plugins "
727 "failed\n", 0, 0, 0);
729 Debug(LDAP_DEBUG_TRACE, "do_unbind: Unbind postoperation plugins "
730 "failed.\n", 0, 0, 0);
733 #endif /* defined( LDAP_SLAPI ) */
740 backend_connection_init(
746 for ( i = 0; i < nbackends; i++ ) {
747 if ( backends[i].be_connection_init ) {
748 (*backends[i].be_connection_init)( &backends[i], conn);
756 backend_connection_destroy(
762 for ( i = 0; i < nbackends; i++ ) {
763 if ( backends[i].be_connection_destroy ) {
764 (*backends[i].be_connection_destroy)( &backends[i], conn);
772 backend_check_controls(
778 LDAPControl **ctrls = op->o_ctrls;
780 if( ctrls == NULL ) return LDAP_SUCCESS;
782 for( ; *ctrls != NULL ; ctrls++ ) {
783 if( (*ctrls)->ldctl_iscritical &&
784 !ldap_charray_inlist( be->be_controls, (*ctrls)->ldctl_oid ) )
786 *text = "control unavailable in context";
787 return LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
795 backend_check_restrictions(
799 struct berval *opdata,
803 slap_mask_t restrictops;
804 slap_mask_t requires;
812 rc = backend_check_controls( be, conn, op, text );
814 if( rc != LDAP_SUCCESS ) {
818 restrictops = be->be_restrictops;
819 requires = be->be_requires;
820 ssf = &be->be_ssf_set;
823 restrictops = global_restrictops;
824 requires = global_requires;
825 ssf = &global_ssf_set;
828 switch( op->o_tag ) {
830 opflag = SLAP_RESTRICT_OP_ADD;
834 opflag = SLAP_RESTRICT_OP_BIND;
837 case LDAP_REQ_COMPARE:
838 opflag = SLAP_RESTRICT_OP_COMPARE;
840 case LDAP_REQ_DELETE:
842 opflag = SLAP_RESTRICT_OP_DELETE;
844 case LDAP_REQ_EXTENDED:
845 opflag = SLAP_RESTRICT_OP_EXTENDED;
848 /* treat unspecified as a modify */
849 opflag = SLAP_RESTRICT_OP_MODIFY;
855 struct berval bv = BER_BVC( LDAP_EXOP_START_TLS );
856 if( bvmatch( opdata, &bv ) ) {
864 struct berval bv = BER_BVC( LDAP_EXOP_X_WHO_AM_I );
865 if( bvmatch( opdata, &bv ) ) {
871 struct berval bv = BER_BVC( LDAP_EXOP_X_CANCEL );
872 if ( bvmatch( opdata, &bv ) ) {
877 /* treat everything else as a modify */
878 opflag = SLAP_RESTRICT_OP_MODIFY;
882 case LDAP_REQ_MODIFY:
884 opflag = SLAP_RESTRICT_OP_MODIFY;
886 case LDAP_REQ_RENAME:
888 opflag = SLAP_RESTRICT_OP_RENAME;
890 case LDAP_REQ_SEARCH:
891 opflag = SLAP_RESTRICT_OP_SEARCH;
893 case LDAP_REQ_UNBIND:
898 *text = "restrict operations internal error";
903 /* these checks don't apply to StartTLS */
905 if( op->o_transport_ssf < ssf->sss_transport ) {
906 *text = "transport confidentiality required";
907 return LDAP_CONFIDENTIALITY_REQUIRED;
910 if( op->o_tls_ssf < ssf->sss_tls ) {
911 *text = "TLS confidentiality required";
912 return LDAP_CONFIDENTIALITY_REQUIRED;
916 if( op->o_tag == LDAP_REQ_BIND && opdata == NULL ) {
917 /* simple bind specific check */
918 if( op->o_ssf < ssf->sss_simple_bind ) {
919 *text = "confidentiality required";
920 return LDAP_CONFIDENTIALITY_REQUIRED;
924 if( op->o_tag != LDAP_REQ_BIND || opdata == NULL ) {
925 /* these checks don't apply to SASL bind */
927 if( op->o_sasl_ssf < ssf->sss_sasl ) {
928 *text = "SASL confidentiality required";
929 return LDAP_CONFIDENTIALITY_REQUIRED;
932 if( op->o_ssf < ssf->sss_ssf ) {
933 *text = "confidentiality required";
934 return LDAP_CONFIDENTIALITY_REQUIRED;
939 if( op->o_transport_ssf < ssf->sss_update_transport ) {
940 *text = "transport update confidentiality required";
941 return LDAP_CONFIDENTIALITY_REQUIRED;
944 if( op->o_tls_ssf < ssf->sss_update_tls ) {
945 *text = "TLS update confidentiality required";
946 return LDAP_CONFIDENTIALITY_REQUIRED;
949 if( op->o_sasl_ssf < ssf->sss_update_sasl ) {
950 *text = "SASL update confidentiality required";
951 return LDAP_CONFIDENTIALITY_REQUIRED;
954 if( op->o_ssf < ssf->sss_update_ssf ) {
955 *text = "update confidentiality required";
956 return LDAP_CONFIDENTIALITY_REQUIRED;
959 if( !( global_allows & SLAP_ALLOW_UPDATE_ANON ) &&
960 op->o_ndn.bv_len == 0 )
962 *text = "modifications require authentication";
963 return LDAP_STRONG_AUTH_REQUIRED;
966 #ifdef SLAP_X_LISTENER_MOD
967 if ( ! ( conn->c_listener->sl_perms & S_IWUSR ) ) {
968 /* no "w" mode means readonly */
969 *text = "modifications not allowed on this listener";
970 return LDAP_UNWILLING_TO_PERFORM;
972 #endif /* SLAP_X_LISTENER_MOD */
977 /* these checks don't apply to Bind, StartTLS, or Unbind */
979 if( requires & SLAP_REQUIRE_STRONG ) {
980 /* should check mechanism */
981 if( ( op->o_transport_ssf < ssf->sss_transport
982 && op->o_authmech.bv_len == 0 ) || op->o_dn.bv_len == 0 )
984 *text = "strong authentication required";
985 return LDAP_STRONG_AUTH_REQUIRED;
989 if( requires & SLAP_REQUIRE_SASL ) {
990 if( op->o_authmech.bv_len == 0 || op->o_dn.bv_len == 0 ) {
991 *text = "SASL authentication required";
992 return LDAP_STRONG_AUTH_REQUIRED;
996 if( requires & SLAP_REQUIRE_AUTHC ) {
997 if( op->o_dn.bv_len == 0 ) {
998 *text = "authentication required";
999 return LDAP_UNWILLING_TO_PERFORM;
1003 if( requires & SLAP_REQUIRE_BIND ) {
1005 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1006 version = conn->c_protocol;
1007 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1010 /* no bind has occurred */
1011 *text = "BIND required";
1012 return LDAP_OPERATIONS_ERROR;
1016 if( requires & SLAP_REQUIRE_LDAP_V3 ) {
1017 if( op->o_protocol < LDAP_VERSION3 ) {
1018 /* no bind has occurred */
1019 *text = "operation restricted to LDAPv3 clients";
1020 return LDAP_OPERATIONS_ERROR;
1024 #ifdef SLAP_X_LISTENER_MOD
1025 if ( !starttls && op->o_dn.bv_len == 0 ) {
1026 if ( ! ( conn->c_listener->sl_perms & S_IXUSR ) ) {
1027 /* no "x" mode means bind required */
1028 *text = "bind required on this listener";
1029 return LDAP_STRONG_AUTH_REQUIRED;
1033 if ( !starttls && !updateop ) {
1034 if ( ! ( conn->c_listener->sl_perms & S_IRUSR ) ) {
1035 /* no "r" mode means no read */
1036 *text = "read not allowed on this listener";
1037 return LDAP_UNWILLING_TO_PERFORM;
1040 #endif /* SLAP_X_LISTENER_MOD */
1044 if( restrictops & opflag ) {
1045 if( restrictops == SLAP_RESTRICT_OP_READS ) {
1046 *text = "read operations restricted";
1048 *text = "operation restricted";
1050 return LDAP_UNWILLING_TO_PERFORM;
1053 return LDAP_SUCCESS;
1056 int backend_check_referrals(
1061 struct berval *ndn )
1063 int rc = LDAP_SUCCESS;
1065 if( be->be_chk_referrals ) {
1068 rc = be->be_chk_referrals( be,
1069 conn, op, dn, ndn, &text );
1071 if( rc != LDAP_SUCCESS && rc != LDAP_REFERRAL ) {
1072 send_ldap_result( conn, op, rc,
1073 NULL, text, NULL, NULL );
1086 struct berval *gr_ndn,
1087 struct berval *op_ndn,
1088 ObjectClass *group_oc,
1089 AttributeDescription *group_at
1094 if ( op->o_abandon ) return SLAPD_ABANDON;
1096 if ( !dn_match( &target->e_nname, gr_ndn ) ) {
1097 /* we won't attempt to send it to a different backend */
1099 be = select_backend( gr_ndn, 0, 0 );
1102 return LDAP_NO_SUCH_OBJECT;
1106 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1108 for (g = conn->c_groups; g; g=g->ga_next) {
1109 if (g->ga_be != be || g->ga_oc != group_oc ||
1110 g->ga_at != group_at || g->ga_len != gr_ndn->bv_len)
1112 if (strcmp( g->ga_ndn, gr_ndn->bv_val ) == 0)
1116 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1122 if( be->be_group ) {
1123 int res = be->be_group( be, conn, op,
1124 target, gr_ndn, op_ndn,
1125 group_oc, group_at );
1127 if ( op->o_tag != LDAP_REQ_BIND && !op->o_do_not_cache ) {
1128 g = ch_malloc(sizeof(GroupAssertion) + gr_ndn->bv_len);
1130 g->ga_oc = group_oc;
1131 g->ga_at = group_at;
1133 g->ga_len = gr_ndn->bv_len;
1134 strcpy(g->ga_ndn, gr_ndn->bv_val);
1135 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1136 g->ga_next = conn->c_groups;
1138 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1144 return LDAP_UNWILLING_TO_PERFORM;
1154 AttributeDescription *entry_at,
1158 if ( target == NULL || !dn_match( &target->e_nname, edn ) ) {
1159 /* we won't attempt to send it to a different backend */
1161 be = select_backend( edn, 0, 0 );
1164 return LDAP_NO_SUCH_OBJECT;
1168 if( be->be_attribute ) {
1169 return be->be_attribute( be, conn, op, target, edn,
1173 return LDAP_UNWILLING_TO_PERFORM;
1176 Attribute *backend_operational(
1181 AttributeName *attrs,
1184 Attribute *a = NULL, **ap = &a;
1187 * If operational attributes (allegedly) are required,
1188 * and the backend supports specific operational attributes,
1189 * add them to the attribute list
1191 if ( opattrs || ( attrs &&
1192 ad_inlist( slap_schema.si_ad_subschemaSubentry, attrs )) ) {
1193 *ap = slap_operational_subschemaSubentry( be );
1194 ap = &(*ap)->a_next;
1197 if ( ( opattrs || attrs ) && be && be->be_operational != NULL ) {
1198 ( void )be->be_operational( be, conn, op, e, attrs, opattrs, ap );