1 /* backend.c - routines for dealing with back-end databases */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that this notice is preserved and that due credit is given
21 * to the University of Michigan at Ann Arbor. The name of the University
22 * may not be used to endorse or promote products derived from this
23 * software without specific prior written permission. This software
24 * is provided ``as is'' without express or implied warranty.
32 #include <ac/string.h>
33 #include <ac/socket.h>
41 #include "slapi/slapi.h"
43 static void init_group_pblock( Operation *op, Entry *target,
44 Entry *e, struct berval *op_ndn, AttributeDescription *group_at );
45 static int call_group_preop_plugins( Operation *op );
46 static void call_group_postop_plugins( Operation *op );
47 #endif /* LDAP_SLAPI */
50 * If a module is configured as dynamic, its header should not
51 * get included into slapd. While this is a general rule and does
52 * not have much of an effect in UNIX, this rule should be adhered
53 * to for Windows, where dynamic object code should not be implicitly
54 * imported into slapd without appropriate __declspec(dllimport) directives.
58 slap_bi_head backendInfo = LDAP_STAILQ_HEAD_INITIALIZER(backendInfo);
61 slap_be_head backendDB = LDAP_STAILQ_HEAD_INITIALIZER(backendDB);
64 backend_init_controls( BackendInfo *bi )
66 if ( bi->bi_controls ) {
69 for ( i = 0; bi->bi_controls[ i ]; i++ ) {
72 if ( slap_find_control_id( bi->bi_controls[ i ], &cid )
73 == LDAP_CONTROL_NOT_FOUND )
75 if ( !( slapMode & SLAP_TOOL_MODE ) ) {
82 bi->bi_ctrls[ cid ] = 1;
89 int backend_init(void)
94 if((nBackendInfo != 0) || !LDAP_STAILQ_EMPTY(&backendInfo)) {
95 /* already initialized */
96 Debug( LDAP_DEBUG_ANY,
97 "backend_init: already initialized\n", 0, 0, 0 );
101 for( bi=slap_binfo; bi->bi_type != NULL; bi++,nBackendInfo++ )
103 assert( bi->bi_init );
105 rc = bi->bi_init( bi );
108 Debug( LDAP_DEBUG_ANY,
109 "backend_init: initialized for type \"%s\"\n",
111 /* destroy those we've already inited */
116 if ( slap_binfo[nBackendInfo].bi_destroy ) {
117 slap_binfo[nBackendInfo].bi_destroy(
118 &slap_binfo[nBackendInfo] );
124 LDAP_STAILQ_INSERT_TAIL(&backendInfo, bi, bi_next);
127 if ( nBackendInfo > 0) {
135 Debug( LDAP_DEBUG_ANY,
136 "backend_init: failed\n",
140 #endif /* SLAPD_MODULES */
143 int backend_add(BackendInfo *aBackendInfo)
147 if ( aBackendInfo->bi_init == NULL ) {
148 Debug( LDAP_DEBUG_ANY, "backend_add: "
149 "backend type \"%s\" does not have the (mandatory)init function\n",
150 aBackendInfo->bi_type, 0, 0 );
154 rc = aBackendInfo->bi_init(aBackendInfo);
156 Debug( LDAP_DEBUG_ANY,
157 "backend_add: initialization for type \"%s\" failed\n",
158 aBackendInfo->bi_type, 0, 0 );
162 (void)backend_init_controls( aBackendInfo );
164 /* now add the backend type to the Backend Info List */
165 LDAP_STAILQ_INSERT_TAIL( &backendInfo, aBackendInfo, bi_next );
171 backend_set_controls( BackendDB *be )
173 BackendInfo *bi = be->bd_info;
175 /* back-relay takes care of itself; so may do other */
176 if ( overlay_is_over( be ) ) {
177 bi = ((slap_overinfo *)be->bd_info->bi_private)->oi_orig;
180 if ( bi->bi_controls ) {
181 if ( be->be_ctrls[ SLAP_MAX_CIDS ] == 0 ) {
182 AC_MEMCPY( be->be_ctrls, bi->bi_ctrls,
183 sizeof( be->be_ctrls ) );
184 be->be_ctrls[ SLAP_MAX_CIDS ] = 1;
189 for ( i = 0; i < SLAP_MAX_CIDS; i++ ) {
190 if ( bi->bi_ctrls[ i ] ) {
191 be->be_ctrls[ i ] = bi->bi_ctrls[ i ];
201 /* startup a specific backend database */
202 int backend_startup_one(Backend *be)
208 be->be_pending_csn_list = (struct be_pcl *)
209 ch_calloc( 1, sizeof( struct be_pcl ));
211 LDAP_TAILQ_INIT( be->be_pending_csn_list );
213 Debug( LDAP_DEBUG_TRACE,
214 "backend_startup_one: starting \"%s\"\n",
215 be->be_suffix ? be->be_suffix[0].bv_val : "(unknown)",
218 /* set database controls */
219 (void)backend_set_controls( be );
221 if ( be->bd_info->bi_db_open ) {
222 rc = be->bd_info->bi_db_open( be );
224 (void)backend_set_controls( be );
227 Debug( LDAP_DEBUG_ANY,
228 "backend_startup_one: bi_db_open failed! (%d)\n",
236 int backend_startup(Backend *be)
242 if( ! ( nBackendDB > 0 ) ) {
244 Debug( LDAP_DEBUG_ANY,
245 "backend_startup: %d databases to startup.\n",
251 if ( be->bd_info->bi_open ) {
252 rc = be->bd_info->bi_open( be->bd_info );
254 Debug( LDAP_DEBUG_ANY,
255 "backend_startup: bi_open failed!\n",
262 return backend_startup_one( be );
265 /* open frontend, if required */
266 if ( frontendDB->bd_info->bi_db_open ) {
267 rc = frontendDB->bd_info->bi_db_open( frontendDB );
269 Debug( LDAP_DEBUG_ANY,
270 "backend_startup: bi_db_open(frontend) failed! (%d)\n",
276 /* open each backend type */
278 LDAP_STAILQ_FOREACH(bi, &backendInfo, bi_next) {
280 if( bi->bi_nDB == 0) {
281 /* no database of this type, don't open */
286 rc = bi->bi_open( bi );
288 Debug( LDAP_DEBUG_ANY,
289 "backend_startup: bi_open %d (%s) failed!\n",
295 (void)backend_init_controls( bi );
298 /* open each backend database */
300 LDAP_STAILQ_FOREACH(be, &backendDB, be_next) {
302 if ( be->be_suffix == NULL ) {
303 Debug( LDAP_DEBUG_ANY,
304 "backend_startup: warning, database %d (%s) "
306 i, be->bd_info->bi_type, 0 );
308 /* append global access controls */
309 acl_append( &be->be_acl, frontendDB->be_acl, -1 );
311 rc = backend_startup_one( be );
319 int backend_num( Backend *be )
324 if( be == NULL ) return -1;
326 LDAP_STAILQ_FOREACH( b2, &backendDB, be_next ) {
327 if( be == b2 ) return i;
333 int backend_shutdown( Backend *be )
340 /* shutdown a specific backend database */
342 if ( be->bd_info->bi_nDB == 0 ) {
343 /* no database of this type, we never opened it */
347 if ( be->bd_info->bi_db_close ) {
348 be->bd_info->bi_db_close( be );
351 if( be->bd_info->bi_close ) {
352 be->bd_info->bi_close( be->bd_info );
358 /* close each backend database */
359 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
360 if ( be->bd_info->bi_db_close ) {
361 be->bd_info->bi_db_close( be );
365 Debug( LDAP_DEBUG_ANY,
366 "backend_close: bi_db_close %s failed!\n",
371 /* close each backend type */
372 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next ) {
373 if( bi->bi_nDB == 0 ) {
374 /* no database of this type */
383 /* close frontend, if required */
384 if ( frontendDB->bd_info->bi_db_close ) {
385 rc = frontendDB->bd_info->bi_db_close ( frontendDB );
387 Debug( LDAP_DEBUG_ANY,
388 "backend_startup: bi_db_close(frontend) failed! (%d)\n",
396 int backend_destroy(void)
401 struct slap_csn_entry *csne;
403 /* destroy each backend database */
404 while (( bd = LDAP_STAILQ_FIRST(&backendDB))) {
405 LDAP_STAILQ_REMOVE_HEAD(&backendDB, be_next);
407 if ( bd->be_syncinfo ) {
408 syncinfo_free( bd->be_syncinfo );
411 if ( bd->be_pending_csn_list ) {
412 csne = LDAP_TAILQ_FIRST( bd->be_pending_csn_list );
414 struct slap_csn_entry *tmp_csne = csne;
416 LDAP_TAILQ_REMOVE( bd->be_pending_csn_list, csne, ce_csn_link );
417 ch_free( csne->ce_csn.bv_val );
418 csne = LDAP_TAILQ_NEXT( csne, ce_csn_link );
423 if ( bd->bd_info->bi_db_destroy ) {
424 bd->bd_info->bi_db_destroy( bd );
426 ber_bvarray_free( bd->be_suffix );
427 ber_bvarray_free( bd->be_nsuffix );
428 if ( !BER_BVISNULL( &bd->be_rootdn ) ) {
429 free( bd->be_rootdn.bv_val );
431 if ( !BER_BVISNULL( &bd->be_rootndn ) ) {
432 free( bd->be_rootndn.bv_val );
434 if ( !BER_BVISNULL( &bd->be_rootpw ) ) {
435 free( bd->be_rootpw.bv_val );
437 acl_destroy( bd->be_acl, frontendDB->be_acl );
441 /* destroy each backend type */
442 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next ) {
443 if( bi->bi_destroy ) {
444 bi->bi_destroy( bi );
449 LDAP_STAILQ_INIT(&backendInfo);
451 /* destroy frontend database */
454 if ( bd->bd_info->bi_db_destroy ) {
455 bd->bd_info->bi_db_destroy( bd );
457 ber_bvarray_free( bd->be_suffix );
458 ber_bvarray_free( bd->be_nsuffix );
459 if ( !BER_BVISNULL( &bd->be_rootdn ) ) {
460 free( bd->be_rootdn.bv_val );
462 if ( !BER_BVISNULL( &bd->be_rootndn ) ) {
463 free( bd->be_rootndn.bv_val );
465 if ( !BER_BVISNULL( &bd->be_rootpw ) ) {
466 free( bd->be_rootpw.bv_val );
468 acl_destroy( bd->be_acl, frontendDB->be_acl );
474 BackendInfo* backend_info(const char *type)
478 /* search for the backend type */
479 LDAP_STAILQ_FOREACH(bi,&backendInfo,bi_next) {
480 if( strcasecmp(bi->bi_type, type) == 0 ) {
494 BackendInfo *bi = backend_info(type);
498 fprintf( stderr, "Unrecognized database type (%s)\n", type );
502 be = ch_calloc( 1, sizeof(Backend) );
504 LDAP_STAILQ_INSERT_TAIL(&backendDB, be, be_next);
508 be->be_def_limit = frontendDB->be_def_limit;
509 be->be_dfltaccess = frontendDB->be_dfltaccess;
511 be->be_restrictops = frontendDB->be_restrictops;
512 be->be_requires = frontendDB->be_requires;
513 be->be_ssf_set = frontendDB->be_ssf_set;
515 be->be_pcl_mutexp = &be->be_pcl_mutex;
516 ldap_pvt_thread_mutex_init( be->be_pcl_mutexp );
518 /* assign a default depth limit for alias deref */
519 be->be_max_deref_depth = SLAPD_DEFAULT_MAXDEREFDEPTH;
521 if ( bi->bi_db_init ) {
522 rc = bi->bi_db_init( be );
526 fprintf( stderr, "database init failed (%s)\n", type );
541 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
542 if ( be->bd_info->bi_db_close ) {
543 be->bd_info->bi_db_close( be );
547 if ( frontendDB->bd_info->bi_db_close ) {
548 (*frontendDB->bd_info->bi_db_close)( frontendDB );
560 ber_len_t len, dnlen = dn->bv_len;
561 Backend *be, *b2 = NULL;
563 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
564 if ( be->be_nsuffix == NULL ) {
568 for ( j = 0; !BER_BVISNULL( &be->be_nsuffix[j] ); j++ )
570 if ( ( SLAP_GLUE_SUBORDINATE( be ) ) && noSubs )
575 len = be->be_nsuffix[j].bv_len;
578 /* suffix is longer than DN */
583 * input DN is normalized, so the separator check
584 * need not look at escaping
586 if ( len && len < dnlen &&
587 !DN_SEPARATOR( dn->bv_val[(dnlen-len)-1] ))
592 if ( strcmp( be->be_nsuffix[j].bv_val,
593 &dn->bv_val[dnlen-len] ) == 0 )
598 if( manageDSAit && len == dnlen &&
599 !SLAP_GLUE_SUBORDINATE( be ) ) {
616 struct berval *bvsuffix )
620 if ( be->be_nsuffix == NULL ) {
624 for ( i = 0; !BER_BVISNULL( &be->be_nsuffix[i] ); i++ ) {
625 if ( bvmatch( &be->be_nsuffix[i], bvsuffix ) ) {
634 be_isroot_dn( Backend *be, struct berval *ndn )
636 if ( BER_BVISEMPTY( ndn ) || BER_BVISEMPTY( &be->be_rootndn ) ) {
640 return dn_match( &be->be_rootndn, ndn );
644 be_slurp_update( Operation *op )
646 return ( SLAP_SLURP_SHADOW( op->o_bd ) &&
647 be_isupdate_dn( op->o_bd, &op->o_ndn ) );
651 be_shadow_update( Operation *op )
653 return ( SLAP_SYNC_SHADOW( op->o_bd ) ||
654 ( SLAP_SHADOW( op->o_bd ) && be_isupdate_dn( op->o_bd, &op->o_ndn ) ) );
658 be_isupdate_dn( Backend *be, struct berval *ndn )
660 if ( BER_BVISEMPTY( ndn ) || BER_BVISEMPTY( &be->be_update_ndn ) ) {
664 return dn_match( &be->be_update_ndn, ndn );
668 be_root_dn( Backend *be )
670 return &be->be_rootdn;
674 be_isroot( Operation *op )
676 return be_isroot_dn( op->o_bd, &op->o_ndn );
680 be_isroot_pw( Operation *op )
684 if ( ! be_isroot_dn( op->o_bd, &op->o_req_ndn ) ) {
688 if ( BER_BVISEMPTY( &op->o_bd->be_rootpw ) ) {
693 ldap_pvt_thread_pool_setkey( op->o_threadctx, slap_sasl_bind,
694 op->o_conn->c_sasl_authctx, NULL );
697 result = lutil_passwd( &op->o_bd->be_rootpw, &op->orb_cred, NULL, NULL );
700 ldap_pvt_thread_pool_setkey( op->o_threadctx, slap_sasl_bind, NULL, NULL );
712 if ( op->o_bd->be_release ) {
713 /* free and release entry from backend */
714 return op->o_bd->be_release( op, e, rw );
723 backend_unbind( Operation *op, SlapReply *rs )
728 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
729 #if defined( LDAP_SLAPI )
732 if ( i == 0 ) slapi_int_pblock_set_operation( op->o_pb, op );
733 slapi_pblock_set( op->o_pb, SLAPI_BACKEND, (void *)be );
734 rc = slapi_int_call_plugins( be,
735 SLAPI_PLUGIN_PRE_UNBIND_FN, (Slapi_PBlock *)op->o_pb );
738 * A preoperation plugin failure will abort the
741 Debug(LDAP_DEBUG_TRACE,
742 "do_bind: Unbind preoperation plugin failed\n",
747 #endif /* defined( LDAP_SLAPI ) */
749 if ( be->be_unbind ) {
751 be->be_unbind( op, rs );
754 #if defined( LDAP_SLAPI )
755 if ( op->o_pb != NULL && slapi_int_call_plugins( be,
756 SLAPI_PLUGIN_POST_UNBIND_FN, (Slapi_PBlock *)op->o_pb ) < 0 )
758 Debug(LDAP_DEBUG_TRACE,
759 "do_unbind: Unbind postoperation plugins failed\n",
762 #endif /* defined( LDAP_SLAPI ) */
770 backend_connection_init(
775 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
776 if ( be->be_connection_init ) {
777 be->be_connection_init( be, conn);
785 backend_connection_destroy(
790 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
791 if ( be->be_connection_destroy ) {
792 be->be_connection_destroy( be, conn);
800 backend_check_controls(
804 LDAPControl **ctrls = op->o_ctrls;
805 rs->sr_err = LDAP_SUCCESS;
808 for( ; *ctrls != NULL ; ctrls++ ) {
811 switch ( slap_global_control( op, (*ctrls)->ldctl_oid, &cid ) ) {
812 case LDAP_CONTROL_NOT_FOUND:
813 /* unrecognized control */
814 if ( (*ctrls)->ldctl_iscritical ) {
815 /* should not be reachable */
816 Debug( LDAP_DEBUG_ANY,
817 "backend_check_controls: unrecognized control: %s\n",
818 (*ctrls)->ldctl_oid, 0, 0 );
823 case LDAP_COMPARE_FALSE:
824 if ( !op->o_bd->be_ctrls[ cid ] && (*ctrls)->ldctl_iscritical )
826 /* Per RFC 2251 (and LDAPBIS discussions), if the control
827 * is recognized and appropriate for the operation (which
828 * we've already verified), then the server should make
829 * use of the control when performing the operation.
831 * Here we find that operation extended by the control
832 * is unavailable in a particular context, and the control
833 * is marked Critical, hence the return of
834 * unwillingToPerform.
836 rs->sr_text = "critical control unavailable in context";
837 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
842 case LDAP_COMPARE_TRUE:
847 rs->sr_text = "unable to check control";
848 rs->sr_err = LDAP_OTHER;
859 backend_check_restrictions(
862 struct berval *opdata )
864 slap_mask_t restrictops;
865 slap_mask_t requires;
867 slap_mask_t exopflag = 0;
874 int rc = SLAP_CB_CONTINUE;
876 if ( op->o_bd->be_chk_controls ) {
877 rc = ( *op->o_bd->be_chk_controls )( op, rs );
880 if ( rc == SLAP_CB_CONTINUE ) {
881 rc = backend_check_controls( op, rs );
884 if ( rc != LDAP_SUCCESS ) {
888 restrictops = op->o_bd->be_restrictops;
889 requires = op->o_bd->be_requires;
890 ssf = &op->o_bd->be_ssf_set;
893 restrictops = frontendDB->be_restrictops;
894 requires = frontendDB->be_requires;
895 ssf = &frontendDB->be_ssf_set;
898 switch( op->o_tag ) {
900 opflag = SLAP_RESTRICT_OP_ADD;
904 opflag = SLAP_RESTRICT_OP_BIND;
907 case LDAP_REQ_COMPARE:
908 opflag = SLAP_RESTRICT_OP_COMPARE;
910 case LDAP_REQ_DELETE:
912 opflag = SLAP_RESTRICT_OP_DELETE;
914 case LDAP_REQ_EXTENDED:
915 opflag = SLAP_RESTRICT_OP_EXTENDED;
918 /* treat unspecified as a modify */
919 opflag = SLAP_RESTRICT_OP_MODIFY;
924 if( bvmatch( opdata, &slap_EXOP_START_TLS ) ) {
927 exopflag = SLAP_RESTRICT_EXOP_START_TLS;
931 if( bvmatch( opdata, &slap_EXOP_WHOAMI ) ) {
932 exopflag = SLAP_RESTRICT_EXOP_WHOAMI;
936 if ( bvmatch( opdata, &slap_EXOP_CANCEL ) ) {
937 exopflag = SLAP_RESTRICT_EXOP_CANCEL;
941 if ( bvmatch( opdata, &slap_EXOP_MODIFY_PASSWD ) ) {
942 exopflag = SLAP_RESTRICT_EXOP_MODIFY_PASSWD;
947 /* treat everything else as a modify */
948 opflag = SLAP_RESTRICT_OP_MODIFY;
952 case LDAP_REQ_MODIFY:
954 opflag = SLAP_RESTRICT_OP_MODIFY;
956 case LDAP_REQ_RENAME:
958 opflag = SLAP_RESTRICT_OP_RENAME;
960 case LDAP_REQ_SEARCH:
961 opflag = SLAP_RESTRICT_OP_SEARCH;
963 case LDAP_REQ_UNBIND:
968 rs->sr_text = "restrict operations internal error";
969 rs->sr_err = LDAP_OTHER;
974 /* these checks don't apply to StartTLS */
976 rs->sr_err = LDAP_CONFIDENTIALITY_REQUIRED;
977 if( op->o_transport_ssf < ssf->sss_transport ) {
978 rs->sr_text = op->o_transport_ssf
979 ? "stronger transport confidentiality required"
980 : "transport confidentiality required";
984 if( op->o_tls_ssf < ssf->sss_tls ) {
985 rs->sr_text = op->o_tls_ssf
986 ? "stronger TLS confidentiality required"
987 : "TLS confidentiality required";
992 if( op->o_tag == LDAP_REQ_BIND && opdata == NULL ) {
993 /* simple bind specific check */
994 if( op->o_ssf < ssf->sss_simple_bind ) {
995 rs->sr_text = op->o_ssf
996 ? "stronger confidentiality required"
997 : "confidentiality required";
1002 if( op->o_tag != LDAP_REQ_BIND || opdata == NULL ) {
1003 /* these checks don't apply to SASL bind */
1005 if( op->o_sasl_ssf < ssf->sss_sasl ) {
1006 rs->sr_text = op->o_sasl_ssf
1007 ? "stronger SASL confidentiality required"
1008 : "SASL confidentiality required";
1012 if( op->o_ssf < ssf->sss_ssf ) {
1013 rs->sr_text = op->o_ssf
1014 ? "stronger confidentiality required"
1015 : "confidentiality required";
1021 if( op->o_transport_ssf < ssf->sss_update_transport ) {
1022 rs->sr_text = op->o_transport_ssf
1023 ? "stronger transport confidentiality required for update"
1024 : "transport confidentiality required for update";
1028 if( op->o_tls_ssf < ssf->sss_update_tls ) {
1029 rs->sr_text = op->o_tls_ssf
1030 ? "stronger TLS confidentiality required for update"
1031 : "TLS confidentiality required for update";
1035 if( op->o_sasl_ssf < ssf->sss_update_sasl ) {
1036 rs->sr_text = op->o_sasl_ssf
1037 ? "stronger SASL confidentiality required for update"
1038 : "SASL confidentiality required for update";
1042 if( op->o_ssf < ssf->sss_update_ssf ) {
1043 rs->sr_text = op->o_ssf
1044 ? "stronger confidentiality required for update"
1045 : "confidentiality required for update";
1049 if( !( global_allows & SLAP_ALLOW_UPDATE_ANON ) &&
1050 BER_BVISEMPTY( &op->o_ndn ) )
1052 rs->sr_text = "modifications require authentication";
1053 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1057 #ifdef SLAP_X_LISTENER_MOD
1058 if ( op->o_conn->c_listener &&
1059 ! ( op->o_conn->c_listener->sl_perms & ( !BER_BVISEMPTY( &op->o_ndn )
1060 ? (S_IWUSR|S_IWOTH) : S_IWOTH ) ) )
1062 /* no "w" mode means readonly */
1063 rs->sr_text = "modifications not allowed on this listener";
1064 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1067 #endif /* SLAP_X_LISTENER_MOD */
1072 /* these checks don't apply to Bind, StartTLS, or Unbind */
1074 if( requires & SLAP_REQUIRE_STRONG ) {
1075 /* should check mechanism */
1076 if( ( op->o_transport_ssf < ssf->sss_transport
1077 && op->o_authtype == LDAP_AUTH_SIMPLE )
1078 || BER_BVISEMPTY( &op->o_dn ) )
1080 rs->sr_text = "strong(er) authentication required";
1081 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1086 if( requires & SLAP_REQUIRE_SASL ) {
1087 if( op->o_authtype != LDAP_AUTH_SASL || BER_BVISEMPTY( &op->o_dn ) ) {
1088 rs->sr_text = "SASL authentication required";
1089 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1094 if( requires & SLAP_REQUIRE_AUTHC ) {
1095 if( BER_BVISEMPTY( &op->o_dn ) ) {
1096 rs->sr_text = "authentication required";
1097 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1102 if( requires & SLAP_REQUIRE_BIND ) {
1104 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1105 version = op->o_conn->c_protocol;
1106 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1109 /* no bind has occurred */
1110 rs->sr_text = "BIND required";
1111 rs->sr_err = LDAP_OPERATIONS_ERROR;
1116 if( requires & SLAP_REQUIRE_LDAP_V3 ) {
1117 if( op->o_protocol < LDAP_VERSION3 ) {
1118 /* no bind has occurred */
1119 rs->sr_text = "operation restricted to LDAPv3 clients";
1120 rs->sr_err = LDAP_OPERATIONS_ERROR;
1125 #ifdef SLAP_X_LISTENER_MOD
1126 if ( !starttls && BER_BVISEMPTY( &op->o_dn ) ) {
1127 if ( op->o_conn->c_listener &&
1128 !( op->o_conn->c_listener->sl_perms & S_IXOTH ))
1130 /* no "x" mode means bind required */
1131 rs->sr_text = "bind required on this listener";
1132 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1137 if ( !starttls && !updateop ) {
1138 if ( op->o_conn->c_listener &&
1139 !( op->o_conn->c_listener->sl_perms &
1140 ( !BER_BVISEMPTY( &op->o_dn )
1141 ? (S_IRUSR|S_IROTH) : S_IROTH )))
1143 /* no "r" mode means no read */
1144 rs->sr_text = "read not allowed on this listener";
1145 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1149 #endif /* SLAP_X_LISTENER_MOD */
1153 if( ( restrictops & opflag )
1154 || ( exopflag && ( restrictops & exopflag ) ) ) {
1155 if( ( restrictops & SLAP_RESTRICT_OP_MASK) == SLAP_RESTRICT_OP_READS ) {
1156 rs->sr_text = "read operations restricted";
1157 } else if ( restrictops & exopflag ) {
1158 rs->sr_text = "extended operation restricted";
1160 rs->sr_text = "operation restricted";
1162 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1166 rs->sr_err = LDAP_SUCCESS;
1170 int backend_check_referrals( Operation *op, SlapReply *rs )
1172 rs->sr_err = LDAP_SUCCESS;
1174 if( op->o_bd->be_chk_referrals ) {
1175 rs->sr_err = op->o_bd->be_chk_referrals( op, rs );
1177 if( rs->sr_err != LDAP_SUCCESS && rs->sr_err != LDAP_REFERRAL ) {
1178 send_ldap_result( op, rs );
1190 AttributeDescription *at,
1198 if (op->o_bd == NULL) {
1199 rc = LDAP_NO_SUCH_OBJECT;
1200 } else if ( op->o_bd->be_fetch ) {
1201 rc = ( op->o_bd->be_fetch )( op, ndn,
1204 rc = LDAP_UNWILLING_TO_PERFORM;
1213 struct berval *gr_ndn,
1214 struct berval *op_ndn,
1215 ObjectClass *group_oc,
1216 AttributeDescription *group_at )
1222 Backend *be = op->o_bd;
1224 if ( op->o_abandon ) return SLAPD_ABANDON;
1226 op->o_bd = select_backend( gr_ndn, 0, 0 );
1228 for ( g = op->o_groups; g; g = g->ga_next ) {
1229 if ( g->ga_be != op->o_bd || g->ga_oc != group_oc ||
1230 g->ga_at != group_at || g->ga_len != gr_ndn->bv_len )
1234 if ( strcmp( g->ga_ndn, gr_ndn->bv_val ) == 0 ) {
1244 if ( target && dn_match( &target->e_nname, gr_ndn ) ) {
1248 rc = be_entry_get_rw( op, gr_ndn, group_oc, group_at, 0, &e );
1252 if ( op->o_pb != NULL ) {
1253 init_group_pblock( op, target, e, op_ndn, group_at );
1255 rc = call_group_preop_plugins( op );
1256 if ( rc == LDAP_SUCCESS ) {
1260 #endif /* LDAP_SLAPI */
1262 a = attr_find( e->e_attrs, group_at );
1264 /* If the attribute is a subtype of labeledURI, treat this as
1265 * a dynamic group ala groupOfURLs
1267 if (is_at_subtype( group_at->ad_type,
1268 slap_schema.si_ad_labeledURI->ad_type ) )
1272 struct berval bv, nbase;
1275 Backend *b2 = op->o_bd;
1277 if ( target && dn_match( &target->e_nname, op_ndn ) ) {
1280 op->o_bd = select_backend( op_ndn, 0, 0 );
1281 rc = be_entry_get_rw(op, op_ndn, NULL, NULL, 0, &user );
1285 rc = LDAP_COMPARE_FALSE;
1286 for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) {
1287 if ( ldap_url_parse( a->a_vals[i].bv_val, &ludp ) !=
1292 BER_BVZERO( &nbase );
1293 /* host part must be empty */
1294 /* attrs and extensions parts must be empty */
1295 if ( ( ludp->lud_host && *ludp->lud_host ) ||
1296 ludp->lud_attrs || ludp->lud_exts )
1300 ber_str2bv( ludp->lud_dn, 0, 0, &bv );
1301 if ( dnNormalize( 0, NULL, NULL, &bv, &nbase,
1302 op->o_tmpmemctx ) != LDAP_SUCCESS )
1306 switch ( ludp->lud_scope ) {
1307 case LDAP_SCOPE_BASE:
1308 if ( !dn_match( &nbase, op_ndn ) ) {
1312 case LDAP_SCOPE_ONELEVEL:
1313 dnParent( op_ndn, &bv );
1314 if ( !dn_match( &nbase, &bv ) ) {
1318 case LDAP_SCOPE_SUBTREE:
1319 if ( !dnIsSuffix( op_ndn, &nbase ) ) {
1323 #ifdef LDAP_SCOPE_SUBORDINATE
1324 case LDAP_SCOPE_SUBORDINATE:
1325 if ( dn_match( &nbase, op_ndn ) ||
1326 !dnIsSuffix( op_ndn, &nbase ) )
1332 filter = str2filter_x( op, ludp->lud_filter );
1334 if ( test_filter( NULL, user, filter ) ==
1339 filter_free_x( op, filter );
1342 ldap_free_urldesc( ludp );
1343 if ( !BER_BVISNULL( &nbase ) ) {
1344 op->o_tmpfree( nbase.bv_val, op->o_tmpmemctx );
1346 if ( rc == 0 ) break;
1348 if ( user != target ) {
1349 be_entry_release_r( op, user );
1354 rc = value_find_ex( group_at,
1355 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1356 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1357 a->a_nvals, op_ndn, op->o_tmpmemctx );
1358 if ( rc == LDAP_NO_SUCH_ATTRIBUTE )
1359 rc = LDAP_COMPARE_FALSE;
1362 rc = LDAP_NO_SUCH_ATTRIBUTE;
1365 be_entry_release_r( op, e );
1368 rc = LDAP_NO_SUCH_OBJECT;
1372 if ( op->o_pb ) call_group_postop_plugins( op );
1373 #endif /* LDAP_SLAPI */
1375 if ( op->o_tag != LDAP_REQ_BIND && !op->o_do_not_cache ) {
1376 g = op->o_tmpalloc( sizeof( GroupAssertion ) + gr_ndn->bv_len,
1378 g->ga_be = op->o_bd;
1379 g->ga_oc = group_oc;
1380 g->ga_at = group_at;
1382 g->ga_len = gr_ndn->bv_len;
1383 strcpy( g->ga_ndn, gr_ndn->bv_val );
1384 g->ga_next = op->o_groups;
1393 static int backend_compute_output_attr(computed_attr_context *c, Slapi_Attr *a, Slapi_Entry *e)
1397 BerVarray *vals = (BerVarray *)c->cac_private;
1398 Operation *op = NULL;
1401 slapi_pblock_get( c->cac_pb, SLAPI_OPERATION, &op );
1406 if ( op->o_conn && access_allowed( op,
1407 e, a->a_desc, NULL, ACL_AUTH,
1408 &c->cac_acl_state ) == 0 ) {
1412 for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) ;
1414 v = op->o_tmpalloc( sizeof(struct berval) * (i+1),
1416 for ( i = 0, j = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) {
1417 if ( op->o_conn && access_allowed( op,
1420 ACL_AUTH, &c->cac_acl_state ) == 0 ) {
1424 &a->a_nvals[i], op->o_tmpmemctx );
1425 if ( !BER_BVISNULL( &v[j] ) ) {
1431 op->o_tmpfree( v, op->o_tmpmemctx );
1435 BER_BVZERO( &v[j] );
1442 #endif /* LDAP_SLAPI */
1449 AttributeDescription *entry_at,
1451 slap_access_t access )
1454 Attribute *a = NULL;
1455 int freeattr = 0, i, j, rc = LDAP_SUCCESS;
1456 AccessControlState acl_state = ACL_STATE_INIT;
1457 Backend *be = op->o_bd;
1459 op->o_bd = select_backend( edn, 0, 0 );
1461 if ( target && dn_match( &target->e_nname, edn ) ) {
1465 rc = be_entry_get_rw( op, edn, NULL, entry_at, 0, &e );
1469 a = attr_find( e->e_attrs, entry_at );
1471 SlapReply rs = { 0 };
1472 AttributeName anlist[ 2 ];
1474 anlist[ 0 ].an_name = entry_at->ad_cname;
1475 anlist[ 0 ].an_desc = entry_at;
1476 BER_BVZERO( &anlist[ 1 ].an_name );
1477 rs.sr_attrs = anlist;
1479 /* NOTE: backend_operational() is also called
1480 * when returning results, so it's supposed
1481 * to do no harm to entries */
1483 rc = backend_operational( op, &rs );
1486 if ( rc == LDAP_SUCCESS ) {
1487 if ( rs.sr_operational_attrs ) {
1489 a = rs.sr_operational_attrs;
1492 rc = LDAP_NO_SUCH_ATTRIBUTE;
1500 if ( op->o_conn && access > ACL_NONE &&
1501 access_allowed( op, e, entry_at, NULL,
1502 access, &acl_state ) == 0 )
1504 rc = LDAP_INSUFFICIENT_ACCESS;
1508 for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ )
1511 v = op->o_tmpalloc( sizeof(struct berval) * ( i + 1 ),
1513 for ( i = 0, j = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ )
1515 if ( op->o_conn && access > ACL_NONE &&
1516 access_allowed( op, e, entry_at,
1523 ber_dupbv_x( &v[j], &a->a_nvals[i],
1525 if ( !BER_BVISNULL( &v[j] ) ) {
1530 op->o_tmpfree( v, op->o_tmpmemctx );
1532 rc = LDAP_INSUFFICIENT_ACCESS;
1535 BER_BVZERO( &v[j] );
1541 else if ( op->o_pb ) {
1542 /* try any computed attributes */
1543 computed_attr_context ctx;
1545 slapi_int_pblock_set_operation( op->o_pb, op );
1547 ctx.cac_pb = op->o_pb;
1548 ctx.cac_attrs = NULL;
1549 ctx.cac_userattrs = 0;
1550 ctx.cac_opattrs = 0;
1551 ctx.cac_acl_state = acl_state;
1552 ctx.cac_private = (void *)vals;
1554 rc = compute_evaluator( &ctx, entry_at->ad_cname.bv_val, e, backend_compute_output_attr );
1556 rc = LDAP_INSUFFICIENT_ACCESS;
1562 #endif /* LDAP_SLAPI */
1563 freeit: if ( e != target ) {
1564 be_entry_release_r( op, e );
1576 static int backend_compute_output_attr_access(computed_attr_context *c, Slapi_Attr *a, Slapi_Entry *e)
1578 struct berval *nval = (struct berval *)c->cac_private;
1579 Operation *op = NULL;
1581 slapi_pblock_get( c->cac_pb, SLAPI_OPERATION, &op );
1586 return access_allowed( op, e, a->a_desc, nval, ACL_AUTH, NULL ) == 0;
1588 #endif /* LDAP_SLAPI */
1595 AttributeDescription *entry_at,
1596 struct berval *nval,
1597 slap_access_t access,
1601 int rc = LDAP_INSUFFICIENT_ACCESS;
1602 Backend *be = op->o_bd;
1606 assert( op->o_conn );
1608 assert( access > ACL_NONE );
1610 op->o_bd = select_backend( edn, 0, 0 );
1612 if ( target && dn_match( &target->e_nname, edn ) ) {
1616 rc = be_entry_get_rw( op, edn, NULL, entry_at, 0, &e );
1620 Attribute *a = NULL;
1623 if ( entry_at == NULL ) {
1624 entry_at = slap_schema.si_ad_entry;
1627 if ( entry_at == slap_schema.si_ad_entry || entry_at == slap_schema.si_ad_children )
1629 if ( access_allowed_mask( op, e, entry_at,
1630 NULL, access, NULL, mask ) == 0 )
1632 rc = LDAP_INSUFFICIENT_ACCESS;
1639 a = attr_find( e->e_attrs, entry_at );
1641 SlapReply rs = { 0 };
1642 AttributeName anlist[ 2 ];
1644 anlist[ 0 ].an_name = entry_at->ad_cname;
1645 anlist[ 0 ].an_desc = entry_at;
1646 BER_BVZERO( &anlist[ 1 ].an_name );
1647 rs.sr_attrs = anlist;
1649 rs.sr_attr_flags = slap_attr_flags( rs.sr_attrs );
1651 /* NOTE: backend_operational() is also called
1652 * when returning results, so it's supposed
1653 * to do no harm to entries */
1655 rc = backend_operational( op, &rs );
1658 if ( rc == LDAP_SUCCESS ) {
1659 if ( rs.sr_operational_attrs ) {
1661 a = rs.sr_operational_attrs;
1664 rc = LDAP_NO_SUCH_OBJECT;
1670 if ( access_allowed_mask( op, e, entry_at,
1671 nval, access, NULL, mask ) == 0 )
1673 rc = LDAP_INSUFFICIENT_ACCESS;
1679 else if ( op->o_pb ) {
1680 /* try any computed attributes */
1681 computed_attr_context ctx;
1683 slapi_int_pblock_set_operation( op->o_pb, op );
1685 ctx.cac_pb = op->o_pb;
1686 ctx.cac_attrs = NULL;
1687 ctx.cac_userattrs = 0;
1688 ctx.cac_opattrs = 0;
1689 ctx.cac_private = (void *)nval;
1691 rc = compute_evaluator( &ctx, entry_at->ad_cname.bv_val, e, backend_compute_output_attr_access );
1693 rc = LDAP_INSUFFICIENT_ACCESS;
1699 #endif /* LDAP_SLAPI */
1701 freeit: if ( e != target ) {
1702 be_entry_release_r( op, e );
1713 int backend_operational(
1721 for ( ap = &rs->sr_operational_attrs; *ap; ap = &(*ap)->a_next )
1722 /* just count them */ ;
1725 * If operational attributes (allegedly) are required,
1726 * and the backend supports specific operational attributes,
1727 * add them to the attribute list
1729 if ( SLAP_OPATTRS( rs->sr_attr_flags ) || ( rs->sr_attrs &&
1730 ad_inlist( slap_schema.si_ad_entryDN, rs->sr_attrs ) ) )
1732 *ap = slap_operational_entryDN( rs->sr_entry );
1733 ap = &(*ap)->a_next;
1736 if ( SLAP_OPATTRS( rs->sr_attr_flags ) || ( rs->sr_attrs &&
1737 ad_inlist( slap_schema.si_ad_subschemaSubentry, rs->sr_attrs ) ) )
1739 *ap = slap_operational_subschemaSubentry( op->o_bd );
1740 ap = &(*ap)->a_next;
1743 /* Let the overlays have a chance at this */
1745 if ( SLAP_ISOVERLAY( be_orig ) )
1746 op->o_bd = select_backend( be_orig->be_nsuffix, 0, 0 );
1748 if ( ( SLAP_OPATTRS( rs->sr_attr_flags ) || rs->sr_attrs ) &&
1749 op->o_bd && op->o_bd->be_operational != NULL )
1751 rc = op->o_bd->be_operational( op, rs );
1759 static void init_group_pblock( Operation *op, Entry *target,
1760 Entry *e, struct berval *op_ndn, AttributeDescription *group_at )
1762 slapi_int_pblock_set_operation( op->o_pb, op );
1764 slapi_pblock_set( op->o_pb,
1765 SLAPI_X_GROUP_ENTRY, (void *)e );
1766 slapi_pblock_set( op->o_pb,
1767 SLAPI_X_GROUP_OPERATION_DN, (void *)op_ndn->bv_val );
1768 slapi_pblock_set( op->o_pb,
1769 SLAPI_X_GROUP_ATTRIBUTE, (void *)group_at->ad_cname.bv_val );
1770 slapi_pblock_set( op->o_pb,
1771 SLAPI_X_GROUP_TARGET_ENTRY, (void *)target );
1774 static int call_group_preop_plugins( Operation *op )
1778 rc = slapi_int_call_plugins( op->o_bd,
1779 SLAPI_X_PLUGIN_PRE_GROUP_FN, op->o_pb );
1781 if (( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE,
1782 (void *)&rc ) != 0 ) || rc == LDAP_SUCCESS )
1784 rc = LDAP_NO_SUCH_ATTRIBUTE;
1793 static void call_group_postop_plugins( Operation *op )
1795 (void) slapi_int_call_plugins( op->o_bd, SLAPI_X_PLUGIN_POST_GROUP_FN, op->o_pb );
1797 #endif /* LDAP_SLAPI */