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>
43 #include "slapi/slapi.h"
45 static void init_group_pblock( Operation *op, Entry *target,
46 Entry *e, struct berval *op_ndn, AttributeDescription *group_at );
47 static int call_group_preop_plugins( Operation *op );
48 static void call_group_postop_plugins( Operation *op );
49 #endif /* LDAP_SLAPI */
52 * If a module is configured as dynamic, its header should not
53 * get included into slapd. While this is a general rule and does
54 * not have much of an effect in UNIX, this rule should be adhered
55 * to for Windows, where dynamic object code should not be implicitly
56 * imported into slapd without appropriate __declspec(dllimport) directives.
60 BackendInfo *backendInfo = NULL;
63 BackendDB *backendDB = NULL;
65 ldap_pvt_thread_pool_t syncrepl_pool;
66 int syncrepl_pool_max = SLAP_MAX_SYNCREPL_THREADS;
68 int backend_init(void)
72 ldap_pvt_thread_pool_init( &syncrepl_pool, syncrepl_pool_max, 0 );
74 if((nBackendInfo != 0) || (backendInfo != NULL)) {
75 /* already initialized */
76 Debug( LDAP_DEBUG_ANY,
77 "backend_init: already initialized.\n", 0, 0, 0 );
82 slap_binfo[nBackendInfo].bi_type != NULL;
85 assert( slap_binfo[nBackendInfo].bi_init );
87 rc = slap_binfo[nBackendInfo].bi_init( &slap_binfo[nBackendInfo] );
90 Debug( LDAP_DEBUG_ANY,
91 "backend_init: initialized for type \"%s\"\n",
92 slap_binfo[nBackendInfo].bi_type, 0, 0 );
93 /* destroy those we've already inited */
98 if ( slap_binfo[nBackendInfo].bi_destroy ) {
99 slap_binfo[nBackendInfo].bi_destroy(
100 &slap_binfo[nBackendInfo] );
107 if ( nBackendInfo > 0) {
108 backendInfo = slap_binfo;
116 Debug( LDAP_DEBUG_ANY,
117 "backend_init: failed\n",
121 #endif /* SLAPD_MODULES */
124 int backend_add(BackendInfo *aBackendInfo)
128 if ( aBackendInfo->bi_init == NULL ) {
129 Debug( LDAP_DEBUG_ANY, "backend_add: "
130 "backend type \"%s\" does not have the (mandatory)init function\n",
131 aBackendInfo->bi_type, 0, 0 );
135 if ((rc = aBackendInfo->bi_init(aBackendInfo)) != 0) {
136 Debug( LDAP_DEBUG_ANY,
137 "backend_add: initialization for type \"%s\" failed\n",
138 aBackendInfo->bi_type, 0, 0 );
142 /* now add the backend type to the Backend Info List */
144 BackendInfo *newBackendInfo = 0;
146 /* if backendInfo == slap_binfo no deallocation of old backendInfo */
147 if (backendInfo == slap_binfo) {
148 newBackendInfo = ch_calloc(nBackendInfo + 1, sizeof(BackendInfo));
149 AC_MEMCPY(newBackendInfo, backendInfo,
150 sizeof(BackendInfo) * nBackendInfo);
152 newBackendInfo = ch_realloc(backendInfo,
153 sizeof(BackendInfo) * (nBackendInfo + 1));
156 AC_MEMCPY(&newBackendInfo[nBackendInfo], aBackendInfo,
157 sizeof(BackendInfo));
158 backendInfo = newBackendInfo;
164 /* startup a specific backend database */
165 int backend_startup_one(Backend *be)
168 BackendInfo *bi = be->bd_info;
172 be->be_pending_csn_list = (struct be_pcl *)
173 ch_calloc( 1, sizeof( struct be_pcl ));
175 LDAP_TAILQ_INIT( be->be_pending_csn_list );
177 /* back-relay takes care of itself; so may do other */
178 if ( be->be_controls == NULL ) {
179 if ( overlay_is_over( be ) ) {
180 bi = ((slap_overinfo *)be->bd_info->bi_private)->oi_orig;
183 if ( bi->bi_controls ) {
184 be->be_controls = ldap_charray_dup( bi->bi_controls );
188 Debug( LDAP_DEBUG_TRACE,
189 "backend_startup: starting \"%s\"\n",
190 be->be_suffix ? be->be_suffix[0].bv_val : "(unknown)",
192 if ( be->bd_info->bi_db_open ) {
193 rc = be->bd_info->bi_db_open( be );
195 Debug( LDAP_DEBUG_ANY,
196 "backend_startup: bi_db_open failed! (%d)\n",
201 /* back-relay takes care of itself; so may do other */
203 if ( overlay_is_over( be ) ) {
204 bi = ((slap_overinfo *)be->bd_info->bi_private)->oi_orig;
207 if ( bi->bi_controls ) {
208 if ( be->be_controls == NULL ) {
209 be->be_controls = ldap_charray_dup( bi->bi_controls );
214 /* maybe not efficient, but it's startup and few dozens of controls... */
215 for ( i = 0; bi->bi_controls[ i ]; i++ ) {
216 if ( !ldap_charray_inlist( be->be_controls, bi->bi_controls[ i ] ) ) {
217 rc = ldap_charray_add( &be->be_controls, bi->bi_controls[ i ] );
229 int backend_startup(Backend *be)
234 if( ! ( nBackendDB > 0 ) ) {
236 Debug( LDAP_DEBUG_ANY,
237 "backend_startup: %d databases to startup.\n",
243 if ( be->bd_info->bi_open ) {
244 rc = be->bd_info->bi_open( be->bd_info );
246 Debug( LDAP_DEBUG_ANY,
247 "backend_startup: bi_open failed!\n",
254 return backend_startup_one( be );
257 /* open frontend, if required */
258 if ( frontendDB->bd_info->bi_db_open ) {
259 rc = frontendDB->bd_info->bi_db_open( frontendDB );
261 Debug( LDAP_DEBUG_ANY,
262 "backend_startup: bi_db_open(frontend) failed! (%d)\n",
268 /* open each backend type */
269 for( i = 0; i < nBackendInfo; i++ ) {
270 if( backendInfo[i].bi_nDB == 0) {
271 /* no database of this type, don't open */
275 if( backendInfo[i].bi_open ) {
276 rc = backendInfo[i].bi_open(
279 Debug( LDAP_DEBUG_ANY,
280 "backend_startup: bi_open %d failed!\n",
287 ldap_pvt_thread_mutex_init( &slapd_rq.rq_mutex );
288 LDAP_STAILQ_INIT( &slapd_rq.task_list );
289 LDAP_STAILQ_INIT( &slapd_rq.run_list );
291 /* open each backend database */
292 for( i = 0; i < nBackendDB; i++ ) {
293 if ( backendDB[i].be_suffix == NULL ) {
294 Debug( LDAP_DEBUG_ANY,
295 "backend_startup: warning, database %d (%s) "
297 i, backendDB[i].bd_info->bi_type, 0 );
299 /* append global access controls */
300 acl_append( &backendDB[i].be_acl, frontendDB->be_acl );
302 rc = backend_startup_one( &backendDB[i] );
307 if ( backendDB[i].be_syncinfo ) {
310 if ( !( backendDB[i].be_search && backendDB[i].be_add &&
311 backendDB[i].be_modify && backendDB[i].be_delete )) {
312 Debug( LDAP_DEBUG_ANY,
313 "backend_startup: database(%d) does not support "
314 "operations required for syncrepl", i, 0, 0 );
319 si = backendDB[i].be_syncinfo;
320 si->si_be = &backendDB[i];
322 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
323 ldap_pvt_runqueue_insert( &slapd_rq,
324 si->si_interval, do_syncrepl, (void *) si );
325 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
333 int backend_num( Backend *be )
337 if( be == NULL ) return -1;
339 for( i = 0; i < nBackendDB; i++ ) {
340 if( be == &backendDB[i] ) return i;
345 int backend_shutdown( Backend *be )
351 /* shutdown a specific backend database */
353 if ( be->bd_info->bi_nDB == 0 ) {
354 /* no database of this type, we never opened it */
358 if ( be->bd_info->bi_db_close ) {
359 be->bd_info->bi_db_close( be );
362 if( be->bd_info->bi_close ) {
363 be->bd_info->bi_close( be->bd_info );
369 /* close each backend database */
370 for( i = 0; i < nBackendDB; i++ ) {
371 if ( backendDB[i].bd_info->bi_db_close ) {
372 backendDB[i].bd_info->bi_db_close(
377 Debug( LDAP_DEBUG_ANY,
378 "backend_close: bi_db_close %s failed!\n",
379 backendDB[i].be_type, 0, 0 );
383 /* close each backend type */
384 for( i = 0; i < nBackendInfo; i++ ) {
385 if( backendInfo[i].bi_nDB == 0 ) {
386 /* no database of this type */
390 if( backendInfo[i].bi_close ) {
391 backendInfo[i].bi_close(
396 /* close frontend, if required */
397 if ( frontendDB->bd_info->bi_db_close ) {
398 rc = frontendDB->bd_info->bi_db_close ( frontendDB );
400 Debug( LDAP_DEBUG_ANY,
401 "backend_startup: bi_db_close(frontend) failed! (%d)\n",
409 int backend_destroy(void)
413 struct slap_csn_entry *csne;
415 ldap_pvt_thread_pool_destroy( &syncrepl_pool, 1 );
417 /* destroy each backend database */
418 for( i = 0, bd = backendDB; i < nBackendDB; i++, bd++ ) {
420 if ( bd->be_syncinfo ) {
421 syncinfo_free( bd->be_syncinfo );
424 if ( bd->be_pending_csn_list ) {
425 csne = LDAP_TAILQ_FIRST( bd->be_pending_csn_list );
427 struct slap_csn_entry *tmp_csne = csne;
429 LDAP_TAILQ_REMOVE( bd->be_pending_csn_list, csne, ce_csn_link );
430 ch_free( csne->ce_csn.bv_val );
431 csne = LDAP_TAILQ_NEXT( csne, ce_csn_link );
436 if ( bd->bd_info->bi_db_destroy ) {
437 bd->bd_info->bi_db_destroy( bd );
439 ber_bvarray_free( bd->be_suffix );
440 ber_bvarray_free( bd->be_nsuffix );
441 if ( !BER_BVISNULL( &bd->be_rootdn ) ) {
442 free( bd->be_rootdn.bv_val );
444 if ( !BER_BVISNULL( &bd->be_rootndn ) ) {
445 free( bd->be_rootndn.bv_val );
447 if ( !BER_BVISNULL( &bd->be_rootpw ) ) {
448 free( bd->be_rootpw.bv_val );
450 acl_destroy( bd->be_acl, frontendDB->be_acl );
451 if ( bd->be_controls ) {
452 ldap_charray_free( bd->be_controls );
457 /* destroy each backend type */
458 for( i = 0; i < nBackendInfo; i++ ) {
459 if( backendInfo[i].bi_destroy ) {
460 backendInfo[i].bi_destroy(
466 if (backendInfo != slap_binfo) {
469 #endif /* SLAPD_MODULES */
474 /* destroy frontend database */
477 if ( bd->bd_info->bi_db_destroy ) {
478 bd->bd_info->bi_db_destroy( bd );
480 ber_bvarray_free( bd->be_suffix );
481 ber_bvarray_free( bd->be_nsuffix );
482 if ( !BER_BVISNULL( &bd->be_rootdn ) ) {
483 free( bd->be_rootdn.bv_val );
485 if ( !BER_BVISNULL( &bd->be_rootndn ) ) {
486 free( bd->be_rootndn.bv_val );
488 if ( !BER_BVISNULL( &bd->be_rootpw ) ) {
489 free( bd->be_rootpw.bv_val );
491 acl_destroy( bd->be_acl, frontendDB->be_acl );
497 BackendInfo* backend_info(const char *type)
501 /* search for the backend type */
502 for( i = 0; i < nBackendInfo; i++ ) {
503 if( strcasecmp(backendInfo[i].bi_type, type) == 0 ) {
504 return &backendInfo[i];
517 BackendInfo *bi = backend_info(type);
521 fprintf( stderr, "Unrecognized database type (%s)\n", type );
527 backendDB = (BackendDB *) ch_realloc(
529 (nBackendDB + 1) * sizeof(Backend) );
531 memset( &backendDB[nbackends], '\0', sizeof(Backend) );
533 /* did realloc move our table? if so, fix up dependent pointers */
534 if ( be != backendDB ) {
536 for ( i=0, be=backendDB; i<nbackends; i++, be++ ) {
537 be->be_pcl_mutexp = &be->be_pcl_mutex;
541 be = &backends[nbackends++];
545 be->be_def_limit = frontendDB->be_def_limit;
546 be->be_dfltaccess = frontendDB->be_dfltaccess;
548 be->be_restrictops = frontendDB->be_restrictops;
549 be->be_requires = frontendDB->be_requires;
550 be->be_ssf_set = frontendDB->be_ssf_set;
552 be->be_pcl_mutexp = &be->be_pcl_mutex;
553 ldap_pvt_thread_mutex_init( be->be_pcl_mutexp );
555 /* assign a default depth limit for alias deref */
556 be->be_max_deref_depth = SLAPD_DEFAULT_MAXDEREFDEPTH;
559 rc = bi->bi_db_init( be );
563 fprintf( stderr, "database init failed (%s)\n", type );
577 for ( i = 0; i < nbackends; i++ ) {
578 if ( backends[i].bd_info->bi_db_close ) {
579 (*backends[i].bd_info->bi_db_close)( &backends[i] );
583 if ( frontendDB->bd_info->bi_db_close ) {
584 (*frontendDB->bd_info->bi_db_close)( frontendDB );
595 ber_len_t len, dnlen = dn->bv_len;
598 for ( i = 0; i < nbackends; i++ ) {
599 if ( backends[i].be_nsuffix == NULL ) {
603 for ( j = 0; !BER_BVISNULL( &backends[i].be_nsuffix[j] ); j++ )
605 if ( ( SLAP_GLUE_SUBORDINATE( &backends[i] ) )
611 len = backends[i].be_nsuffix[j].bv_len;
614 /* suffix is longer than DN */
619 * input DN is normalized, so the separator check
620 * need not look at escaping
622 if ( len && len < dnlen &&
623 !DN_SEPARATOR( dn->bv_val[(dnlen-len)-1] ))
628 if ( strcmp( backends[i].be_nsuffix[j].bv_val,
629 &dn->bv_val[dnlen-len] ) == 0 )
634 if( manageDSAit && len == dnlen &&
635 !SLAP_GLUE_SUBORDINATE( be ) ) {
652 struct berval *bvsuffix )
656 if ( be->be_nsuffix == NULL ) {
660 for ( i = 0; !BER_BVISNULL( &be->be_nsuffix[i] ); i++ ) {
661 if ( bvmatch( &be->be_nsuffix[i], bvsuffix ) ) {
670 be_isroot_dn( Backend *be, struct berval *ndn )
672 if ( BER_BVISEMPTY( ndn ) || BER_BVISEMPTY( &be->be_rootndn ) ) {
676 return dn_match( &be->be_rootndn, ndn );
680 be_slurp_update( Operation *op )
682 return ( SLAP_SLURP_SHADOW( op->o_bd ) &&
683 be_isupdate_dn( op->o_bd, &op->o_ndn ) );
687 be_shadow_update( Operation *op )
689 return ( SLAP_SYNC_SHADOW( op->o_bd ) ||
690 ( SLAP_SHADOW( op->o_bd ) && be_isupdate_dn( op->o_bd, &op->o_ndn ) ) );
694 be_isupdate_dn( Backend *be, struct berval *ndn )
696 if ( BER_BVISEMPTY( ndn ) || BER_BVISEMPTY( &be->be_update_ndn ) ) {
700 return dn_match( &be->be_update_ndn, ndn );
704 be_root_dn( Backend *be )
706 return &be->be_rootdn;
710 be_isroot( Operation *op )
712 return be_isroot_dn( op->o_bd, &op->o_ndn );
716 be_isroot_pw( Operation *op )
720 if ( ! be_isroot_dn( op->o_bd, &op->o_req_ndn ) ) {
724 if ( BER_BVISEMPTY( &op->o_bd->be_rootpw ) ) {
728 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
729 ldap_pvt_thread_mutex_lock( &passwd_mutex );
731 lutil_passwd_sasl_conn = op->o_conn->c_sasl_authctx;
735 result = lutil_passwd( &op->o_bd->be_rootpw, &op->orb_cred, NULL, NULL );
737 #if defined( SLAPD_CRYPT ) || defined( SLAPD_SPASSWD )
739 lutil_passwd_sasl_conn = NULL;
741 ldap_pvt_thread_mutex_unlock( &passwd_mutex );
753 if ( op->o_bd->be_release ) {
754 /* free and release entry from backend */
755 return op->o_bd->be_release( op, e, rw );
764 backend_unbind( Operation *op, SlapReply *rs )
768 for ( i = 0; i < nbackends; i++ ) {
769 #if defined( LDAP_SLAPI )
772 if ( i == 0 ) slapi_int_pblock_set_operation( op->o_pb, op );
773 slapi_pblock_set( op->o_pb, SLAPI_BACKEND, (void *)&backends[i] );
774 rc = slapi_int_call_plugins( &backends[i],
775 SLAPI_PLUGIN_PRE_UNBIND_FN, (Slapi_PBlock *)op->o_pb );
778 * A preoperation plugin failure will abort the
781 Debug(LDAP_DEBUG_TRACE,
782 "do_bind: Unbind preoperation plugin failed\n",
787 #endif /* defined( LDAP_SLAPI ) */
789 if ( backends[i].be_unbind ) {
790 op->o_bd = &backends[i];
791 (*backends[i].be_unbind)( op, rs );
794 #if defined( LDAP_SLAPI )
795 if ( op->o_pb != NULL && slapi_int_call_plugins( &backends[i],
796 SLAPI_PLUGIN_POST_UNBIND_FN, (Slapi_PBlock *)op->o_pb ) < 0 )
798 Debug(LDAP_DEBUG_TRACE,
799 "do_unbind: Unbind postoperation plugins failed\n",
802 #endif /* defined( LDAP_SLAPI ) */
809 backend_connection_init(
814 for ( i = 0; i < nbackends; i++ ) {
815 if ( backends[i].be_connection_init ) {
816 (*backends[i].be_connection_init)( &backends[i], conn);
824 backend_connection_destroy(
829 for ( i = 0; i < nbackends; i++ ) {
830 if ( backends[i].be_connection_destroy ) {
831 (*backends[i].be_connection_destroy)( &backends[i], conn);
839 backend_check_controls(
843 LDAPControl **ctrls = op->o_ctrls;
844 rs->sr_err = LDAP_SUCCESS;
847 for( ; *ctrls != NULL ; ctrls++ ) {
849 #ifdef SLAP_CONTROL_AVAILABILITY_KLUDGE
850 /* KLUDGE: ldctl_iscritical munged by controls.c:get_ctrls()
851 * to ensure this check is enabled/disabled appropriately.
853 (*ctrls)->ldctl_iscritical &&
855 !ldap_charray_inlist( op->o_bd->be_controls,
856 (*ctrls)->ldctl_oid ) )
858 /* Per RFC 2251 (and LDAPBIS discussions), if the control
859 * is recognized and appropriate for the operation (which
860 * we've already verified), then the server should make
861 * use of the control when performing the operation.
863 * Here we find that operation extended by the control
864 * is not unavailable in a particular context, hence the
865 * return of unwillingToPerform.
867 rs->sr_text = "control unavailable in context";
868 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
878 backend_check_restrictions(
881 struct berval *opdata )
883 slap_mask_t restrictops;
884 slap_mask_t requires;
886 slap_mask_t exopflag = 0;
893 if ( backend_check_controls( op, rs ) != LDAP_SUCCESS ) {
897 restrictops = op->o_bd->be_restrictops;
898 requires = op->o_bd->be_requires;
899 ssf = &op->o_bd->be_ssf_set;
902 restrictops = frontendDB->be_restrictops;
903 requires = frontendDB->be_requires;
904 ssf = &frontendDB->be_ssf_set;
907 switch( op->o_tag ) {
909 opflag = SLAP_RESTRICT_OP_ADD;
913 opflag = SLAP_RESTRICT_OP_BIND;
916 case LDAP_REQ_COMPARE:
917 opflag = SLAP_RESTRICT_OP_COMPARE;
919 case LDAP_REQ_DELETE:
921 opflag = SLAP_RESTRICT_OP_DELETE;
923 case LDAP_REQ_EXTENDED:
924 opflag = SLAP_RESTRICT_OP_EXTENDED;
927 /* treat unspecified as a modify */
928 opflag = SLAP_RESTRICT_OP_MODIFY;
933 if( bvmatch( opdata, &slap_EXOP_START_TLS ) ) {
936 exopflag = SLAP_RESTRICT_EXOP_START_TLS;
940 if( bvmatch( opdata, &slap_EXOP_WHOAMI ) ) {
941 exopflag = SLAP_RESTRICT_EXOP_WHOAMI;
945 if ( bvmatch( opdata, &slap_EXOP_CANCEL ) ) {
946 exopflag = SLAP_RESTRICT_EXOP_CANCEL;
950 if ( bvmatch( opdata, &slap_EXOP_MODIFY_PASSWD ) ) {
951 exopflag = SLAP_RESTRICT_EXOP_MODIFY_PASSWD;
956 /* treat everything else as a modify */
957 opflag = SLAP_RESTRICT_OP_MODIFY;
961 case LDAP_REQ_MODIFY:
963 opflag = SLAP_RESTRICT_OP_MODIFY;
965 case LDAP_REQ_RENAME:
967 opflag = SLAP_RESTRICT_OP_RENAME;
969 case LDAP_REQ_SEARCH:
970 opflag = SLAP_RESTRICT_OP_SEARCH;
972 case LDAP_REQ_UNBIND:
977 rs->sr_text = "restrict operations internal error";
978 rs->sr_err = LDAP_OTHER;
983 /* these checks don't apply to StartTLS */
985 rs->sr_err = LDAP_CONFIDENTIALITY_REQUIRED;
986 if( op->o_transport_ssf < ssf->sss_transport ) {
987 rs->sr_text = op->o_transport_ssf
988 ? "stronger transport confidentiality required"
989 : "transport confidentiality required";
993 if( op->o_tls_ssf < ssf->sss_tls ) {
994 rs->sr_text = op->o_tls_ssf
995 ? "stronger TLS confidentiality required"
996 : "TLS confidentiality required";
1001 if( op->o_tag == LDAP_REQ_BIND && opdata == NULL ) {
1002 /* simple bind specific check */
1003 if( op->o_ssf < ssf->sss_simple_bind ) {
1004 rs->sr_text = op->o_ssf
1005 ? "stronger confidentiality required"
1006 : "confidentiality required";
1011 if( op->o_tag != LDAP_REQ_BIND || opdata == NULL ) {
1012 /* these checks don't apply to SASL bind */
1014 if( op->o_sasl_ssf < ssf->sss_sasl ) {
1015 rs->sr_text = op->o_sasl_ssf
1016 ? "stronger SASL confidentiality required"
1017 : "SASL confidentiality required";
1021 if( op->o_ssf < ssf->sss_ssf ) {
1022 rs->sr_text = op->o_ssf
1023 ? "stronger confidentiality required"
1024 : "confidentiality required";
1030 if( op->o_transport_ssf < ssf->sss_update_transport ) {
1031 rs->sr_text = op->o_transport_ssf
1032 ? "stronger transport confidentiality required for update"
1033 : "transport confidentiality required for update";
1037 if( op->o_tls_ssf < ssf->sss_update_tls ) {
1038 rs->sr_text = op->o_tls_ssf
1039 ? "stronger TLS confidentiality required for update"
1040 : "TLS confidentiality required for update";
1044 if( op->o_sasl_ssf < ssf->sss_update_sasl ) {
1045 rs->sr_text = op->o_sasl_ssf
1046 ? "stronger SASL confidentiality required for update"
1047 : "SASL confidentiality required for update";
1051 if( op->o_ssf < ssf->sss_update_ssf ) {
1052 rs->sr_text = op->o_ssf
1053 ? "stronger confidentiality required for update"
1054 : "confidentiality required for update";
1058 if( !( global_allows & SLAP_ALLOW_UPDATE_ANON ) &&
1059 BER_BVISEMPTY( &op->o_ndn ) )
1061 rs->sr_text = "modifications require authentication";
1062 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1066 #ifdef SLAP_X_LISTENER_MOD
1067 if ( op->o_conn->c_listener && ! ( op->o_conn->c_listener->sl_perms & ( !BER_BVISEMPTY( &op->o_ndn ) ? S_IWUSR : S_IWOTH ) ) ) {
1068 /* no "w" mode means readonly */
1069 rs->sr_text = "modifications not allowed on this listener";
1070 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1073 #endif /* SLAP_X_LISTENER_MOD */
1078 /* these checks don't apply to Bind, StartTLS, or Unbind */
1080 if( requires & SLAP_REQUIRE_STRONG ) {
1081 /* should check mechanism */
1082 if( ( op->o_transport_ssf < ssf->sss_transport
1083 && op->o_authtype == LDAP_AUTH_SIMPLE )
1084 || BER_BVISEMPTY( &op->o_dn ) )
1086 rs->sr_text = "strong(er) authentication required";
1087 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1092 if( requires & SLAP_REQUIRE_SASL ) {
1093 if( op->o_authtype != LDAP_AUTH_SASL || BER_BVISEMPTY( &op->o_dn ) ) {
1094 rs->sr_text = "SASL authentication required";
1095 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1100 if( requires & SLAP_REQUIRE_AUTHC ) {
1101 if( BER_BVISEMPTY( &op->o_dn ) ) {
1102 rs->sr_text = "authentication required";
1103 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1108 if( requires & SLAP_REQUIRE_BIND ) {
1110 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
1111 version = op->o_conn->c_protocol;
1112 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
1115 /* no bind has occurred */
1116 rs->sr_text = "BIND required";
1117 rs->sr_err = LDAP_OPERATIONS_ERROR;
1122 if( requires & SLAP_REQUIRE_LDAP_V3 ) {
1123 if( op->o_protocol < LDAP_VERSION3 ) {
1124 /* no bind has occurred */
1125 rs->sr_text = "operation restricted to LDAPv3 clients";
1126 rs->sr_err = LDAP_OPERATIONS_ERROR;
1131 #ifdef SLAP_X_LISTENER_MOD
1132 if ( !starttls && BER_BVISEMPTY( &op->o_dn ) ) {
1133 if ( op->o_conn->c_listener &&
1134 !( op->o_conn->c_listener->sl_perms & S_IXOTH ))
1136 /* no "x" mode means bind required */
1137 rs->sr_text = "bind required on this listener";
1138 rs->sr_err = LDAP_STRONG_AUTH_REQUIRED;
1143 if ( !starttls && !updateop ) {
1144 if ( op->o_conn->c_listener &&
1145 !( op->o_conn->c_listener->sl_perms &
1146 ( !BER_BVISEMPTY( &op->o_dn ) ? S_IRUSR : S_IROTH )))
1148 /* no "r" mode means no read */
1149 rs->sr_text = "read not allowed on this listener";
1150 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1154 #endif /* SLAP_X_LISTENER_MOD */
1158 if( ( restrictops & opflag )
1159 || ( exopflag && ( restrictops & exopflag ) ) ) {
1160 if( ( restrictops & SLAP_RESTRICT_OP_MASK) == SLAP_RESTRICT_OP_READS ) {
1161 rs->sr_text = "read operations restricted";
1162 } else if ( restrictops & exopflag ) {
1163 rs->sr_text = "extended operation restricted";
1165 rs->sr_text = "operation restricted";
1167 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
1171 rs->sr_err = LDAP_SUCCESS;
1175 int backend_check_referrals( Operation *op, SlapReply *rs )
1177 rs->sr_err = LDAP_SUCCESS;
1179 if( op->o_bd->be_chk_referrals ) {
1180 rs->sr_err = op->o_bd->be_chk_referrals( op, rs );
1182 if( rs->sr_err != LDAP_SUCCESS && rs->sr_err != LDAP_REFERRAL ) {
1183 send_ldap_result( op, rs );
1195 AttributeDescription *at,
1203 if (op->o_bd == NULL) {
1204 rc = LDAP_NO_SUCH_OBJECT;
1205 } else if ( op->o_bd->be_fetch ) {
1206 rc = ( op->o_bd->be_fetch )( op, ndn,
1209 rc = LDAP_UNWILLING_TO_PERFORM;
1218 struct berval *gr_ndn,
1219 struct berval *op_ndn,
1220 ObjectClass *group_oc,
1221 AttributeDescription *group_at )
1227 Backend *be = op->o_bd;
1229 if ( op->o_abandon ) return SLAPD_ABANDON;
1231 op->o_bd = select_backend( gr_ndn, 0, 0 );
1233 for ( g = op->o_groups; g; g = g->ga_next ) {
1234 if ( g->ga_be != op->o_bd || g->ga_oc != group_oc ||
1235 g->ga_at != group_at || g->ga_len != gr_ndn->bv_len )
1239 if ( strcmp( g->ga_ndn, gr_ndn->bv_val ) == 0 ) {
1249 if ( target && dn_match( &target->e_nname, gr_ndn ) ) {
1253 rc = be_entry_get_rw( op, gr_ndn, group_oc, group_at, 0, &e );
1257 if ( op->o_pb != NULL ) {
1258 init_group_pblock( op, target, e, op_ndn, group_at );
1260 rc = call_group_preop_plugins( op );
1261 if ( rc == LDAP_SUCCESS ) {
1265 #endif /* LDAP_SLAPI */
1267 a = attr_find( e->e_attrs, group_at );
1269 /* If the attribute is a subtype of labeledURI, treat this as
1270 * a dynamic group ala groupOfURLs
1272 if (is_at_subtype( group_at->ad_type,
1273 slap_schema.si_ad_labeledURI->ad_type ) )
1277 struct berval bv, nbase;
1280 Backend *b2 = op->o_bd;
1282 if ( target && dn_match( &target->e_nname, op_ndn ) ) {
1285 op->o_bd = select_backend( op_ndn, 0, 0 );
1286 rc = be_entry_get_rw(op, op_ndn, NULL, NULL, 0, &user );
1291 for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) {
1292 if ( ldap_url_parse( a->a_vals[i].bv_val, &ludp ) !=
1297 BER_BVZERO( &nbase );
1298 /* host part must be empty */
1299 /* attrs and extensions parts must be empty */
1300 if ( ( ludp->lud_host && *ludp->lud_host ) ||
1301 ludp->lud_attrs || ludp->lud_exts )
1305 ber_str2bv( ludp->lud_dn, 0, 0, &bv );
1306 if ( dnNormalize( 0, NULL, NULL, &bv, &nbase,
1307 op->o_tmpmemctx ) != LDAP_SUCCESS )
1311 switch ( ludp->lud_scope ) {
1312 case LDAP_SCOPE_BASE:
1313 if ( !dn_match( &nbase, op_ndn ) ) {
1317 case LDAP_SCOPE_ONELEVEL:
1318 dnParent( op_ndn, &bv );
1319 if ( !dn_match( &nbase, &bv ) ) {
1323 case LDAP_SCOPE_SUBTREE:
1324 if ( !dnIsSuffix( op_ndn, &nbase ) ) {
1328 #ifdef LDAP_SCOPE_SUBORDINATE
1329 case LDAP_SCOPE_SUBORDINATE:
1330 if ( dn_match( &nbase, op_ndn ) ||
1331 !dnIsSuffix( op_ndn, &nbase ) )
1337 filter = str2filter_x( op, ludp->lud_filter );
1339 if ( test_filter( NULL, user, filter ) ==
1344 filter_free_x( op, filter );
1347 ldap_free_urldesc( ludp );
1348 if ( !BER_BVISNULL( &nbase ) ) {
1349 op->o_tmpfree( nbase.bv_val, op->o_tmpmemctx );
1351 if ( rc == 0 ) break;
1353 if ( user != target ) {
1354 be_entry_release_r( op, user );
1359 rc = value_find_ex( group_at,
1360 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1361 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1362 a->a_nvals, op_ndn, op->o_tmpmemctx );
1365 rc = LDAP_NO_SUCH_ATTRIBUTE;
1368 be_entry_release_r( op, e );
1371 rc = LDAP_NO_SUCH_OBJECT;
1375 if ( op->o_pb ) call_group_postop_plugins( op );
1376 #endif /* LDAP_SLAPI */
1378 if ( op->o_tag != LDAP_REQ_BIND && !op->o_do_not_cache ) {
1379 g = op->o_tmpalloc( sizeof( GroupAssertion ) + gr_ndn->bv_len,
1381 g->ga_be = op->o_bd;
1382 g->ga_oc = group_oc;
1383 g->ga_at = group_at;
1385 g->ga_len = gr_ndn->bv_len;
1386 strcpy( g->ga_ndn, gr_ndn->bv_val );
1387 g->ga_next = op->o_groups;
1396 static int backend_compute_output_attr(computed_attr_context *c, Slapi_Attr *a, Slapi_Entry *e)
1400 BerVarray *vals = (BerVarray *)c->cac_private;
1401 Operation *op = NULL;
1404 slapi_pblock_get( c->cac_pb, SLAPI_OPERATION, &op );
1409 if ( op->o_conn && access_allowed( op,
1410 e, a->a_desc, NULL, ACL_AUTH,
1411 &c->cac_acl_state ) == 0 ) {
1415 for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) ;
1417 v = op->o_tmpalloc( sizeof(struct berval) * (i+1),
1419 for ( i = 0, j = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) {
1420 if ( op->o_conn && access_allowed( op,
1423 ACL_AUTH, &c->cac_acl_state ) == 0 ) {
1427 &a->a_nvals[i], op->o_tmpmemctx );
1428 if ( !BER_BVISNULL( &v[j] ) ) {
1434 op->o_tmpfree( v, op->o_tmpmemctx );
1438 BER_BVZERO( &v[j] );
1445 #endif /* LDAP_SLAPI */
1452 AttributeDescription *entry_at,
1454 slap_access_t access )
1457 Attribute *a = NULL;
1458 int freeattr = 0, i, j, rc = LDAP_SUCCESS;
1459 AccessControlState acl_state = ACL_STATE_INIT;
1460 Backend *be = op->o_bd;
1462 op->o_bd = select_backend( edn, 0, 0 );
1464 if ( target && dn_match( &target->e_nname, edn ) ) {
1468 rc = be_entry_get_rw( op, edn, NULL, entry_at, 0, &e );
1472 a = attr_find( e->e_attrs, entry_at );
1474 SlapReply rs = { 0 };
1475 AttributeName anlist[ 2 ];
1477 anlist[ 0 ].an_name = entry_at->ad_cname;
1478 anlist[ 0 ].an_desc = entry_at;
1479 BER_BVZERO( &anlist[ 1 ].an_name );
1480 rs.sr_attrs = anlist;
1482 rs.sr_attr_flags = slap_attr_flags( rs.sr_attrs );
1484 rc = backend_operational( op, &rs );
1486 if ( rc == LDAP_SUCCESS && rs.sr_operational_attrs ) {
1488 a = rs.sr_operational_attrs;
1495 if ( op->o_conn && access > ACL_NONE && access_allowed( op,
1496 e, entry_at, NULL, access,
1497 &acl_state ) == 0 ) {
1498 rc = LDAP_INSUFFICIENT_ACCESS;
1502 for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ )
1505 v = op->o_tmpalloc( sizeof(struct berval) * ( i + 1 ),
1507 for ( i = 0,j = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ )
1509 if ( op->o_conn && access > ACL_NONE &&
1510 access_allowed( op, e,
1518 ber_dupbv_x( &v[j], &a->a_nvals[i],
1520 if ( !BER_BVISNULL( &v[j] ) ) {
1525 op->o_tmpfree( v, op->o_tmpmemctx );
1527 rc = LDAP_INSUFFICIENT_ACCESS;
1530 BER_BVZERO( &v[j] );
1536 else if ( op->o_pb ) {
1537 /* try any computed attributes */
1538 computed_attr_context ctx;
1540 slapi_int_pblock_set_operation( op->o_pb, op );
1542 ctx.cac_pb = op->o_pb;
1543 ctx.cac_attrs = NULL;
1544 ctx.cac_userattrs = 0;
1545 ctx.cac_opattrs = 0;
1546 ctx.cac_acl_state = acl_state;
1547 ctx.cac_private = (void *)vals;
1549 rc = compute_evaluator( &ctx, entry_at->ad_cname.bv_val, e, backend_compute_output_attr );
1551 rc = LDAP_INSUFFICIENT_ACCESS;
1557 #endif /* LDAP_SLAPI */
1558 freeit: if ( e != target ) {
1559 be_entry_release_r( op, e );
1570 int backend_operational(
1578 for ( ap = &rs->sr_operational_attrs; *ap; ap = &(*ap)->a_next )
1579 /* just count them */ ;
1582 * If operational attributes (allegedly) are required,
1583 * and the backend supports specific operational attributes,
1584 * add them to the attribute list
1586 if ( SLAP_OPATTRS( rs->sr_attr_flags ) || ( op->ors_attrs &&
1587 ad_inlist( slap_schema.si_ad_entryDN, op->ors_attrs )))
1589 *ap = slap_operational_entryDN( rs->sr_entry );
1590 ap = &(*ap)->a_next;
1593 if ( SLAP_OPATTRS( rs->sr_attr_flags ) || ( op->ors_attrs &&
1594 ad_inlist( slap_schema.si_ad_subschemaSubentry, op->ors_attrs )))
1596 *ap = slap_operational_subschemaSubentry( op->o_bd );
1597 ap = &(*ap)->a_next;
1600 /* Let the overlays have a chance at this */
1602 if ( SLAP_ISOVERLAY( be_orig ))
1603 op->o_bd = select_backend( be_orig->be_nsuffix, 0, 0 );
1605 if (( SLAP_OPATTRS( rs->sr_attr_flags ) || op->ors_attrs ) &&
1606 op->o_bd && op->o_bd->be_operational != NULL )
1610 a = rs->sr_operational_attrs;
1611 rs->sr_operational_attrs = NULL;
1612 rc = op->o_bd->be_operational( op, rs );
1613 *ap = rs->sr_operational_attrs;
1615 rs->sr_operational_attrs = a;
1618 for ( ; *ap; ap = &(*ap)->a_next )
1619 /* just count them */ ;
1627 static void init_group_pblock( Operation *op, Entry *target,
1628 Entry *e, struct berval *op_ndn, AttributeDescription *group_at )
1630 slapi_int_pblock_set_operation( op->o_pb, op );
1632 slapi_pblock_set( op->o_pb,
1633 SLAPI_X_GROUP_ENTRY, (void *)e );
1634 slapi_pblock_set( op->o_pb,
1635 SLAPI_X_GROUP_OPERATION_DN, (void *)op_ndn->bv_val );
1636 slapi_pblock_set( op->o_pb,
1637 SLAPI_X_GROUP_ATTRIBUTE, (void *)group_at->ad_cname.bv_val );
1638 slapi_pblock_set( op->o_pb,
1639 SLAPI_X_GROUP_TARGET_ENTRY, (void *)target );
1642 static int call_group_preop_plugins( Operation *op )
1646 rc = slapi_int_call_plugins( op->o_bd,
1647 SLAPI_X_PLUGIN_PRE_GROUP_FN, op->o_pb );
1649 if (( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE,
1650 (void *)&rc ) != 0 ) || rc == LDAP_SUCCESS )
1652 rc = LDAP_NO_SUCH_ATTRIBUTE;
1661 static void call_group_postop_plugins( Operation *op )
1663 (void) slapi_int_call_plugins( op->o_bd, SLAPI_X_PLUGIN_POST_GROUP_FN, op->o_pb );
1665 #endif /* LDAP_SLAPI */