1 /* acl.c - routines to parse and check acl's */
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/socket.h>
33 #include <ac/string.h>
40 #define ACL_BUF_SIZE 1024 /* use most appropriate size */
45 const struct berval aci_bv[] = {
73 #endif /* LDAP_PF_LOCAL */
75 BER_BVC(SLAPD_GROUP_CLASS),
76 BER_BVC(SLAPD_GROUP_ATTR),
77 BER_BVC(SLAPD_ROLE_CLASS),
78 BER_BVC(SLAPD_ROLE_ATTR),
80 BER_BVC(SLAPD_ACI_SET_ATTR)
83 static AccessControl * slap_acl_get(
84 AccessControl *ac, int *count,
85 Operation *op, Entry *e,
86 AttributeDescription *desc,
88 int nmatch, regmatch_t *matches,
89 AccessControlState *state );
91 static slap_control_t slap_acl_mask(
92 AccessControl *ac, slap_mask_t *mask,
93 Operation *op, Entry *e,
94 AttributeDescription *desc,
99 AccessControlState *state );
101 static int regex_matches(
102 struct berval *pat, char *str, char *buf,
103 int nmatch, regmatch_t *matches);
105 typedef struct AclSetCookie {
110 SLAP_SET_GATHER acl_set_gather;
111 SLAP_SET_GATHER acl_set_gather2;
114 * access_allowed - check whether op->o_ndn is allowed the requested access
115 * to entry e, attribute attr, value val. if val is null, access to
116 * the whole attribute is assumed (all values).
118 * This routine loops through all access controls and calls
119 * slap_acl_mask() on each applicable access control.
120 * The loop exits when a definitive answer is reached or
121 * or no more controls remain.
128 * - can be legally called with op == NULL
129 * - can be legally called with op->o_bd == NULL
132 #ifdef SLAP_OVERLAY_ACCESS
134 slap_access_always_allowed(
137 AttributeDescription *desc,
139 slap_access_t access,
140 AccessControlState *state,
143 assert( maskp != NULL );
145 ACL_PRIV_SET( *maskp, ACL_ACCESS2PRIV( access ) );
154 AttributeDescription *desc,
156 slap_access_t access,
157 AccessControlState *state,
162 AccessControl *a = NULL;
165 char accessmaskbuf[ACCESSMASK_MAXLEN];
168 slap_control_t control;
169 slap_access_t access_level;
171 regmatch_t matches[MAXREMATCHES];
172 int st_same_attr = 0;
174 assert( op != NULL );
176 assert( desc != NULL );
177 assert( maskp != NULL );
179 access_level = ACL_LEVEL( access );
180 attr = desc->ad_cname.bv_val;
182 assert( attr != NULL );
184 /* grant database root access */
185 if ( be_isroot( op ) ) {
186 Debug( LDAP_DEBUG_ACL, "<= root access granted\n", 0, 0, 0 );
187 mask = ACL_LVL_MANAGE;
192 * no-user-modification operational attributes are ignored
193 * by ACL_WRITE checking as any found here are not provided
196 if ( access_level >= ACL_WRITE && is_at_no_user_mod( desc->ad_type )
197 && desc != slap_schema.si_ad_entry
198 && desc != slap_schema.si_ad_children )
200 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
201 " %s access granted\n",
206 /* use backend default access if no backend acls */
207 if ( op->o_bd->be_acl == NULL ) {
210 Debug( LDAP_DEBUG_ACL,
211 "=> slap_access_allowed: backend default %s "
212 "access %s to \"%s\"\n",
213 access2str( access ),
214 op->o_bd->be_dfltaccess >= access_level ? "granted" : "denied",
215 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
216 ret = op->o_bd->be_dfltaccess >= access_level;
218 mask = ACL_PRIV_LEVEL;
219 for ( i = ACL_NONE; i <= op->o_bd->be_dfltaccess; i++ ) {
220 ACL_PRIV_SET( mask, ACL_ACCESS2PRIV( i ) );
229 if ( st_same_attr ) {
230 assert( state->as_vd_acl != NULL );
232 a = state->as_vd_acl;
233 count = state->as_vd_acl_count;
234 if ( !ACL_IS_INVALID( state->as_vd_acl_mask ) ) {
235 mask = state->as_vd_acl_mask;
236 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
241 if ( state ) state->as_vi_acl = NULL;
243 ACL_PRIV_ASSIGN( mask, *maskp );
245 memset( matches, '\0', sizeof( matches ) );
248 while ( ( a = slap_acl_get( a, &count, op, e, desc, val,
249 MAXREMATCHES, matches, state ) ) != NULL )
253 for ( i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++ ) {
254 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
255 (int)matches[i].rm_so, (int)matches[i].rm_eo );
256 if ( matches[i].rm_so <= matches[0].rm_eo ) {
258 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++ ) {
259 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
262 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
266 if ( state->as_vi_acl == a &&
267 ( state->as_recorded & ACL_STATE_RECORDED_NV ) )
269 Debug( LDAP_DEBUG_ACL,
270 "=> slap_access_allowed: result from state (%s)\n",
272 ret = state->as_result;
275 Debug( LDAP_DEBUG_ACL,
276 "=> slap_access_allowed: no res from state (%s)\n",
282 control = slap_acl_mask( a, &mask, op,
283 e, desc, val, MAXREMATCHES, matches, count, state );
285 if ( control != ACL_BREAK ) {
289 memset( matches, '\0', sizeof( matches ) );
292 if ( ACL_IS_INVALID( mask ) ) {
293 Debug( LDAP_DEBUG_ACL,
294 "=> slap_access_allowed: \"%s\" (%s) invalid!\n",
296 ACL_PRIV_ASSIGN( mask, *maskp );
298 } else if ( control == ACL_BREAK ) {
299 Debug( LDAP_DEBUG_ACL,
300 "=> slap_access_allowed: no more rules\n", 0, 0, 0 );
305 ret = ACL_GRANT( mask, access );
307 Debug( LDAP_DEBUG_ACL,
308 "=> slap_access_allowed: %s access %s by %s\n",
309 access2str( access ), ret ? "granted" : "denied",
310 accessmask2str( mask, accessmaskbuf, 1 ) );
313 ACL_PRIV_ASSIGN( *maskp, mask );
321 AttributeDescription *desc,
323 slap_access_t access,
324 AccessControlState *state,
331 * NOTE: control gets here if FIXME
332 * if an appropriate backend cannot be selected for the operation,
333 * we assume that the frontend should handle this
334 * FIXME: should select_backend() take care of this,
335 * and return frontendDB instead of NULL? maybe for some value
340 op->o_bd = select_backend( &op->o_req_ndn, 0, 0 );
341 if ( op->o_bd == NULL ) {
342 op->o_bd = frontendDB;
344 rc = slap_access_allowed( op, e, desc, val, access, state, maskp );
354 AttributeDescription *desc,
356 slap_access_t access,
357 AccessControlState *state,
361 AccessControl *a = NULL;
365 char accessmaskbuf[ACCESSMASK_MAXLEN];
368 slap_access_t access_level;
370 int st_same_attr = 0;
371 static AccessControlState state_init = ACL_STATE_INIT;
374 assert( desc != NULL );
376 access_level = ACL_LEVEL( access );
378 assert( access_level > ACL_NONE );
381 if ( maskp ) ACL_INVALIDATE( *maskp );
383 attr = desc->ad_cname.bv_val;
385 assert( attr != NULL );
387 if ( op && op->o_is_auth_check &&
388 ( access_level == ACL_SEARCH || access_level == ACL_READ ) )
394 if ( state->as_vd_ad == desc ) {
395 if ( state->as_recorded ) {
396 if ( ( state->as_recorded & ACL_STATE_RECORDED_NV ) &&
399 return state->as_result;
401 } else if ( ( state->as_recorded & ACL_STATE_RECORDED_VD ) &&
402 val != NULL && state->as_vd_acl == NULL )
404 return state->as_result;
412 state->as_vd_ad = desc;
415 Debug( LDAP_DEBUG_ACL,
416 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
417 access2str( access ), e->e_dn, attr );
424 if ( op->o_bd == NULL ) {
425 op->o_bd = LDAP_STAILQ_FIRST( &backendDB );
430 * FIXME: experimental; use first backend rules
431 * iff there is no global_acl (ITS#3100) */
432 if ( frontendDB->be_acl != NULL ) {
433 op->o_bd = frontendDB;
435 #endif /* LDAP_DEVEL */
437 assert( op->o_bd != NULL );
439 /* this is enforced in backend_add() */
440 if ( op->o_bd->bd_info->bi_access_allowed ) {
441 /* delegate to backend */
442 ret = op->o_bd->bd_info->bi_access_allowed( op, e,
443 desc, val, access, state, &mask );
446 BackendDB *be_orig = op->o_bd;
448 /* use default (but pass through frontend
449 * for global ACL overlays) */
450 op->o_bd = frontendDB;
451 ret = frontendDB->bd_info->bi_access_allowed( op, e,
452 desc, val, access, state, &mask );
457 if ( ACL_IS_INVALID( mask ) ) {
458 Debug( LDAP_DEBUG_ACL,
459 "=> access_allowed: \"%s\" (%s) invalid!\n",
464 Debug( LDAP_DEBUG_ACL,
465 "=> access_allowed: no more rules\n", 0, 0, 0 );
471 Debug( LDAP_DEBUG_ACL,
472 "=> access_allowed: %s access %s by %s\n",
473 access2str( access ), ret ? "granted" : "denied",
474 accessmask2str( mask, accessmaskbuf, 1 ) );
477 if ( state != NULL ) {
478 /* If not value-dependent, save ACL in case of more attrs */
479 if ( !( state->as_recorded & ACL_STATE_RECORDED_VD ) ) {
480 state->as_vi_acl = a;
481 state->as_result = ret;
483 state->as_recorded |= ACL_STATE_RECORDED;
485 if ( be_null ) op->o_bd = NULL;
486 if ( maskp ) ACL_PRIV_ASSIGN( *maskp, mask );
490 #else /* !SLAP_OVERLAY_ACCESS */
496 AttributeDescription *desc,
498 slap_access_t access,
499 AccessControlState *state,
504 AccessControl *a = NULL;
509 char accessmaskbuf[ACCESSMASK_MAXLEN];
512 slap_control_t control;
513 slap_access_t access_level;
515 regmatch_t matches[MAXREMATCHES];
516 int st_same_attr = 0;
517 static AccessControlState state_init = ACL_STATE_INIT;
520 assert( desc != NULL );
522 access_level = ACL_LEVEL( access );
524 assert( access_level > ACL_NONE );
525 if ( maskp ) ACL_INVALIDATE( *maskp );
527 attr = desc->ad_cname.bv_val;
529 assert( attr != NULL );
531 if ( op && op->o_is_auth_check &&
532 ( access_level == ACL_SEARCH || access_level == ACL_READ ) )
538 if ( state->as_vd_ad == desc ) {
539 if ( state->as_recorded ) {
540 if ( ( state->as_recorded & ACL_STATE_RECORDED_NV ) &&
543 return state->as_result;
545 } else if ( ( state->as_recorded & ACL_STATE_RECORDED_VD ) &&
546 val != NULL && state->as_vd_acl == NULL )
548 return state->as_result;
556 state->as_vd_ad=desc;
559 Debug( LDAP_DEBUG_ACL,
560 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
561 access2str( access ), e->e_dn, attr );
570 be = LDAP_STAILQ_FIRST(&backendDB);
574 * FIXME: experimental; use first backend rules
575 * iff there is no global_acl (ITS#3100) */
576 if ( frontendDB->be_acl == NULL )
582 assert( be != NULL );
584 /* grant database root access */
585 if ( be_isroot( op ) ) {
586 Debug( LDAP_DEBUG_ACL, "<= root access granted\n", 0, 0, 0 );
588 mask = ACL_LVL_MANAGE;
595 * no-user-modification operational attributes are ignored
596 * by ACL_WRITE checking as any found here are not provided
599 if ( access_level >= ACL_WRITE && is_at_no_user_mod( desc->ad_type )
600 && desc != slap_schema.si_ad_entry
601 && desc != slap_schema.si_ad_children )
603 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
604 " %s access granted\n",
609 /* use backend default access if no backend acls */
610 if ( be->be_acl == NULL ) {
611 Debug( LDAP_DEBUG_ACL,
612 "=> access_allowed: backend default %s "
613 "access %s to \"%s\"\n",
614 access2str( access ),
615 be->be_dfltaccess >= access_level ? "granted" : "denied",
616 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
617 ret = be->be_dfltaccess >= access_level;
622 mask = ACL_PRIV_LEVEL;
623 for ( i = ACL_NONE; i <= be->be_dfltaccess; i++ ) {
624 mask |= ACL_ACCESS2PRIV( i );
631 /* be is always non-NULL */
632 /* use global default access if no global acls */
633 } else if ( be == NULL && frontendDB->be_acl == NULL ) {
634 Debug( LDAP_DEBUG_ACL,
635 "=> access_allowed: global default %s access %s to \"%s\"\n",
636 access2str( access ),
637 frontendDB->be_dfltaccess >= access_level ?
638 "granted" : "denied", op->o_dn.bv_val );
639 ret = frontendDB->be_dfltaccess >= access_level;
644 mask = ACL_PRIV_LEVEL;
645 for ( i = ACL_NONE; i <= global_default_access; i++ ) {
646 mask |= ACL_ACCESS2PRIV( i );
657 if ( st_same_attr ) {
658 assert( state->as_vd_acl != NULL );
660 a = state->as_vd_acl;
661 count = state->as_vd_acl_count;
662 if ( !ACL_IS_INVALID( state->as_vd_acl_mask ) ) {
663 mask = state->as_vd_acl_mask;
664 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
669 if ( state ) state->as_vi_acl = NULL;
673 memset( matches, '\0', sizeof(matches) );
676 while ( ( a = slap_acl_get( a, &count, op, e, desc, val,
677 MAXREMATCHES, matches, state ) ) != NULL )
681 for ( i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++ ) {
682 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
683 (int)matches[i].rm_so, (int)matches[i].rm_eo );
684 if ( matches[i].rm_so <= matches[0].rm_eo ) {
686 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++ ) {
687 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
690 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
694 if ( state->as_vi_acl == a &&
695 ( state->as_recorded & ACL_STATE_RECORDED_NV ) )
697 Debug( LDAP_DEBUG_ACL,
698 "access_allowed: result from state (%s)\n",
700 ret = state->as_result;
703 Debug( LDAP_DEBUG_ACL,
704 "access_allowed: no res from state (%s)\n",
710 control = slap_acl_mask( a, &mask, op,
711 e, desc, val, MAXREMATCHES, matches, count, state );
713 if ( control != ACL_BREAK ) {
717 memset( matches, '\0', sizeof(matches) );
720 if ( ACL_IS_INVALID( mask ) ) {
721 Debug( LDAP_DEBUG_ACL,
722 "=> access_allowed: \"%s\" (%s) invalid!\n",
726 } else if ( control == ACL_BREAK ) {
727 Debug( LDAP_DEBUG_ACL,
728 "=> access_allowed: no more rules\n", 0, 0, 0 );
733 Debug( LDAP_DEBUG_ACL,
734 "=> access_allowed: %s access %s by %s\n",
735 access2str( access ),
736 ACL_GRANT(mask, access) ? "granted" : "denied",
737 accessmask2str( mask, accessmaskbuf, 1 ) );
739 ret = ACL_GRANT(mask, access);
742 if ( state != NULL ) {
743 /* If not value-dependent, save ACL in case of more attrs */
744 if ( !( state->as_recorded & ACL_STATE_RECORDED_VD ) ) {
745 state->as_vi_acl = a;
746 state->as_result = ret;
748 state->as_recorded |= ACL_STATE_RECORDED;
750 if ( be_null ) op->o_bd = NULL;
751 if ( maskp ) *maskp = mask;
755 #endif /* SLAP_OVERLAY_ACCESS */
758 * slap_acl_get - return the acl applicable to entry e, attribute
759 * attr. the acl returned is suitable for use in subsequent calls to
760 * acl_access_allowed().
763 static AccessControl *
769 AttributeDescription *desc,
773 AccessControlState *state )
780 assert( count != NULL );
781 assert( desc != NULL );
783 attr = desc->ad_cname.bv_val;
785 assert( attr != NULL );
788 if( op->o_bd == NULL ) {
789 a = frontendDB->be_acl;
791 a = op->o_bd->be_acl;
802 dnlen = e->e_nname.bv_len;
804 for ( ; a != NULL; a = a->acl_next ) {
807 if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
808 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
809 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
810 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
811 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
815 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
816 *count, a->acl_dn_pat.bv_val, 0 );
817 patlen = a->acl_dn_pat.bv_len;
818 if ( dnlen < patlen )
821 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
822 /* base dn -- entire object DN must match */
823 if ( dnlen != patlen )
826 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
827 int rdnlen = -1, sep = 0;
829 if ( dnlen <= patlen )
833 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
838 rdnlen = dn_rdnlen( NULL, &e->e_nname );
839 if ( rdnlen != dnlen - patlen - sep )
842 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
843 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
846 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
847 if ( dnlen <= patlen )
849 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
853 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
857 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
861 if ( a->acl_attrs && !ad_inlist( desc, a->acl_attrs ) ) {
862 matches[0].rm_so = matches[0].rm_eo = -1;
866 /* Is this ACL only for a specific value? */
867 if ( a->acl_attrval.bv_len ) {
872 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) {
873 state->as_recorded |= ACL_STATE_RECORDED_VD;
874 state->as_vd_acl = a;
875 state->as_vd_acl_count = *count;
876 state->as_vd_access = a->acl_access;
877 state->as_vd_access_count = 1;
878 ACL_INVALIDATE( state->as_vd_acl_mask );
881 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
882 Debug( LDAP_DEBUG_ACL,
883 "acl_get: valpat %s\n",
884 a->acl_attrval.bv_val, 0, 0 );
885 if ( regexec( &a->acl_attrval_re, val->bv_val, 0, NULL, 0 ) )
893 Debug( LDAP_DEBUG_ACL,
895 a->acl_attrval.bv_val, 0, 0 );
897 if ( a->acl_attrs[0].an_desc->ad_type->sat_syntax != slap_schema.si_syn_distinguishedName ) {
898 if (value_match( &match, desc,
899 /* desc->ad_type->sat_equality */ a->acl_attrval_mr, 0,
900 val, &a->acl_attrval, &text ) != LDAP_SUCCESS ||
907 patlen = a->acl_attrval.bv_len;
908 vdnlen = val->bv_len;
910 if ( vdnlen < patlen )
913 if ( a->acl_attrval_style == ACL_STYLE_BASE ) {
914 if ( vdnlen > patlen )
917 } else if ( a->acl_attrval_style == ACL_STYLE_ONE ) {
920 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
923 rdnlen = dn_rdnlen( NULL, val );
924 if ( rdnlen != vdnlen - patlen - 1 )
927 } else if ( a->acl_attrval_style == ACL_STYLE_SUBTREE ) {
928 if ( vdnlen > patlen && !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
931 } else if ( a->acl_attrval_style == ACL_STYLE_CHILDREN ) {
932 if ( vdnlen <= patlen )
935 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
939 if ( strcmp( a->acl_attrval.bv_val, val->bv_val + vdnlen - patlen ))
945 if ( a->acl_filter != NULL ) {
946 ber_int_t rc = test_filter( NULL, e, a->acl_filter );
947 if ( rc != LDAP_COMPARE_TRUE ) {
952 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] attr %s\n",
957 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
969 struct berval *opndn )
972 * if access applies to the entry itself, and the
973 * user is bound as somebody in the same namespace as
974 * the entry, OR the given dn matches the dn pattern
977 * NOTE: styles "anonymous", "users" and "self"
978 * have been moved to enum slap_style_t, whose
979 * value is set in a_dn_style; however, the string
980 * is maintaned in a_dn_pat.
982 if ( b->a_style == ACL_STYLE_ANONYMOUS ) {
983 if ( !BER_BVISEMPTY( opndn ) ) {
987 } else if ( b->a_style == ACL_STYLE_USERS ) {
988 if ( BER_BVISEMPTY( opndn ) ) {
992 } else if ( b->a_style == ACL_STYLE_SELF ) {
993 struct berval ndn, selfndn;
996 if ( BER_BVISEMPTY( opndn ) || BER_BVISNULL( &e->e_nname ) ) {
1000 level = b->a_self_level;
1008 selfndn = e->e_nname;
1011 for ( ; level > 0; level-- ) {
1012 if ( BER_BVISEMPTY( &ndn ) ) {
1015 dnParent( &ndn, &ndn );
1018 if ( BER_BVISEMPTY( &ndn ) || !dn_match( &ndn, &selfndn ) )
1023 } else if ( b->a_style == ACL_STYLE_REGEX ) {
1024 if ( !ber_bvccmp( &b->a_pat, '*' ) ) {
1026 regmatch_t tmp_matches[2],
1027 *tmp_matchesp = tmp_matches;
1031 switch ( a->acl_dn_style ) {
1032 case ACL_STYLE_REGEX:
1033 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1034 tmp_matchesp = matches;
1035 tmp_nmatch = nmatch;
1038 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1040 case ACL_STYLE_BASE:
1041 tmp_matches[0].rm_so = 0;
1042 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1047 case ACL_STYLE_SUBTREE:
1048 case ACL_STYLE_CHILDREN:
1049 tmp_matches[0].rm_so = 0;
1050 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1051 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1052 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1066 if ( !regex_matches( &b->a_pat, opndn->bv_val,
1067 e->e_ndn, tmp_nmatch, tmp_matchesp ) )
1075 ber_len_t patlen, odnlen;
1078 if ( e->e_dn == NULL )
1081 if ( b->a_expand ) {
1083 char buf[ACL_BUF_SIZE];
1086 regmatch_t tmp_matches[2],
1087 *tmp_matchesp = tmp_matches;
1091 bv.bv_len = sizeof( buf ) - 1;
1094 switch ( a->acl_dn_style ) {
1095 case ACL_STYLE_REGEX:
1096 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1097 tmp_matchesp = matches;
1098 tmp_nmatch = nmatch;
1101 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1103 case ACL_STYLE_BASE:
1104 tmp_matches[0].rm_so = 0;
1105 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1110 case ACL_STYLE_SUBTREE:
1111 case ACL_STYLE_CHILDREN:
1112 tmp_matches[0].rm_so = 0;
1113 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1114 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1115 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1129 if ( acl_string_expand( &bv, &b->a_pat,
1131 tmp_nmatch, tmp_matchesp ) )
1136 if ( dnNormalize(0, NULL, NULL, &bv,
1137 &pat, op->o_tmpmemctx )
1140 /* did not expand to a valid dn */
1148 patlen = pat.bv_len;
1149 odnlen = opndn->bv_len;
1150 if ( odnlen < patlen ) {
1151 goto dn_match_cleanup;
1155 if ( b->a_style == ACL_STYLE_BASE ) {
1156 /* base dn -- entire object DN must match */
1157 if ( odnlen != patlen ) {
1158 goto dn_match_cleanup;
1161 } else if ( b->a_style == ACL_STYLE_ONE ) {
1164 if ( odnlen <= patlen ) {
1165 goto dn_match_cleanup;
1168 if ( !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1169 goto dn_match_cleanup;
1172 rdnlen = dn_rdnlen( NULL, opndn );
1173 if ( rdnlen != odnlen - patlen - 1 ) {
1174 goto dn_match_cleanup;
1177 } else if ( b->a_style == ACL_STYLE_SUBTREE ) {
1178 if ( odnlen > patlen && !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1179 goto dn_match_cleanup;
1182 } else if ( b->a_style == ACL_STYLE_CHILDREN ) {
1183 if ( odnlen <= patlen ) {
1184 goto dn_match_cleanup;
1187 if ( !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) ) {
1188 goto dn_match_cleanup;
1191 } else if ( b->a_style == ACL_STYLE_LEVEL ) {
1195 if ( odnlen <= patlen ) {
1196 goto dn_match_cleanup;
1199 if ( level > 0 && !DN_SEPARATOR( opndn->bv_val[odnlen - patlen - 1] ) )
1201 goto dn_match_cleanup;
1206 for ( ; level > 0; level-- ) {
1207 if ( BER_BVISEMPTY( &ndn ) ) {
1208 goto dn_match_cleanup;
1210 dnParent( &ndn, &ndn );
1211 if ( ndn.bv_len < patlen ) {
1212 goto dn_match_cleanup;
1216 if ( ndn.bv_len != patlen ) {
1217 goto dn_match_cleanup;
1221 got_match = !strcmp( pat.bv_val, &opndn->bv_val[ odnlen - patlen ] );
1224 if ( pat.bv_val != b->a_pat.bv_val ) {
1225 slap_sl_free( pat.bv_val, op->o_tmpmemctx );
1237 * Record value-dependent access control state
1239 #define ACL_RECORD_VALUE_STATE do { \
1240 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
1241 state->as_recorded |= ACL_STATE_RECORDED_VD; \
1242 state->as_vd_acl = a; \
1243 AC_MEMCPY( state->as_vd_acl_matches, matches, \
1244 sizeof( state->as_vd_acl_matches )) ; \
1245 state->as_vd_acl_count = count; \
1246 state->as_vd_access = b; \
1247 state->as_vd_access_count = i; \
1259 regmatch_t *matches,
1261 AccessControlState *state,
1262 slap_dn_access *bdn,
1263 struct berval *opndn )
1269 const char *attr = bdn->a_at->ad_cname.bv_val;
1271 assert( attr != NULL );
1273 if ( BER_BVISEMPTY( opndn ) ) {
1277 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n", attr, 0, 0 );
1280 /* see if asker is listed in dnattr */
1281 for ( at = attrs_find( e->e_attrs, bdn->a_at );
1283 at = attrs_find( at->a_next, bdn->a_at ) )
1285 if ( value_find_ex( bdn->a_at,
1286 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1287 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1289 &bv, op->o_tmpmemctx ) == 0 )
1298 /* have a dnattr match. if this is a self clause then
1299 * the target must also match the op dn.
1301 if ( bdn->a_self ) {
1302 /* check if the target is an attribute. */
1303 if ( val == NULL ) return 1;
1305 /* target is attribute, check if the attribute value
1308 rc = value_match( &match, bdn->a_at,
1309 bdn->a_at->ad_type->sat_equality, 0,
1311 /* on match error or no match, fail the ACL clause */
1312 if ( rc != LDAP_SUCCESS || match != 0 )
1317 /* no dnattr match, check if this is a self clause */
1318 if ( ! bdn->a_self )
1321 ACL_RECORD_VALUE_STATE;
1323 /* this is a self clause, check if the target is an
1329 /* target is attribute, check if the attribute value
1332 rc = value_match( &match, bdn->a_at,
1333 bdn->a_at->ad_type->sat_equality, 0,
1336 /* on match error or no match, fail the ACL clause */
1337 if ( rc != LDAP_SUCCESS || match != 0 )
1346 * slap_acl_mask - modifies mask based upon the given acl and the
1347 * requested access to entry e, attribute attr, value val. if val
1348 * is null, access to the whole attribute is assumed (all values).
1350 * returns 0 access NOT allowed
1354 static slap_control_t
1360 AttributeDescription *desc,
1363 regmatch_t *matches,
1365 AccessControlState *state )
1370 char accessmaskbuf[ACCESSMASK_MAXLEN];
1371 #if !defined( SLAP_DYNACL ) && defined( SLAPD_ACI_ENABLED )
1372 char accessmaskbuf1[ACCESSMASK_MAXLEN];
1373 #endif /* !SLAP_DYNACL && SLAPD_ACI_ENABLED */
1376 slap_mask_t a2pmask = ACL_ACCESS2PRIV( *mask );
1378 assert( a != NULL );
1379 assert( mask != NULL );
1380 assert( desc != NULL );
1382 attr = desc->ad_cname.bv_val;
1384 assert( attr != NULL );
1386 Debug( LDAP_DEBUG_ACL,
1387 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
1390 Debug( LDAP_DEBUG_ACL,
1391 "=> acl_mask: to %s by \"%s\", (%s) \n",
1392 val ? "value" : "all values",
1393 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
1394 accessmask2str( *mask, accessmaskbuf, 1 ) );
1397 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
1398 && state->as_vd_acl == a )
1400 b = state->as_vd_access;
1401 i = state->as_vd_access_count;
1408 for ( ; b != NULL; b = b->a_next, i++ ) {
1409 slap_mask_t oldmask, modmask;
1411 ACL_INVALIDATE( modmask );
1413 /* AND <who> clauses */
1414 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
1415 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
1416 b->a_dn_pat.bv_val, 0, 0);
1418 * if access applies to the entry itself, and the
1419 * user is bound as somebody in the same namespace as
1420 * the entry, OR the given dn matches the dn pattern
1423 * NOTE: styles "anonymous", "users" and "self"
1424 * have been moved to enum slap_style_t, whose
1425 * value is set in a_dn_style; however, the string
1426 * is maintaned in a_dn_pat.
1429 if ( acl_mask_dn( op, e, a, nmatch, matches,
1430 &b->a_dn, &op->o_ndn ) )
1436 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
1439 Debug( LDAP_DEBUG_ACL, "<= check a_realdn_pat: %s\n",
1440 b->a_realdn_pat.bv_val, 0, 0);
1442 * if access applies to the entry itself, and the
1443 * user is bound as somebody in the same namespace as
1444 * the entry, OR the given dn matches the dn pattern
1447 * NOTE: styles "anonymous", "users" and "self"
1448 * have been moved to enum slap_style_t, whose
1449 * value is set in a_dn_style; however, the string
1450 * is maintaned in a_dn_pat.
1453 if ( op->o_conn && !BER_BVISNULL( &op->o_conn->c_ndn ) )
1455 ndn = op->o_conn->c_ndn;
1460 if ( acl_mask_dn( op, e, a, nmatch, matches,
1461 &b->a_realdn, &ndn ) )
1467 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1468 if ( ! op->o_conn->c_listener ) {
1471 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
1472 b->a_sockurl_pat.bv_val, 0, 0 );
1474 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
1475 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
1476 if (!regex_matches( &b->a_sockurl_pat, op->o_conn->c_listener_url.bv_val,
1477 e->e_ndn, nmatch, matches ) )
1482 } else if ( b->a_sockurl_style == ACL_STYLE_EXPAND ) {
1484 char buf[ACL_BUF_SIZE];
1486 bv.bv_len = sizeof( buf ) - 1;
1488 if ( acl_string_expand( &bv, &b->a_sockurl_pat,
1489 e->e_ndn, nmatch, matches ) )
1494 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_listener_url ) != 0 )
1500 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &op->o_conn->c_listener_url ) != 0 )
1508 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1509 if ( !op->o_conn->c_peer_domain.bv_val ) {
1512 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
1513 b->a_domain_pat.bv_val, 0, 0 );
1514 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
1515 if ( b->a_domain_style == ACL_STYLE_REGEX) {
1516 if (!regex_matches( &b->a_domain_pat, op->o_conn->c_peer_domain.bv_val,
1517 e->e_ndn, nmatch, matches ) )
1522 char buf[ACL_BUF_SIZE];
1524 struct berval cmp = op->o_conn->c_peer_domain;
1525 struct berval pat = b->a_domain_pat;
1527 if ( b->a_domain_expand ) {
1530 bv.bv_len = sizeof(buf) - 1;
1533 if ( acl_string_expand(&bv, &b->a_domain_pat,
1534 e->e_ndn, nmatch, matches) )
1541 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
1542 int offset = cmp.bv_len - pat.bv_len;
1547 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
1551 /* trim the domain */
1552 cmp.bv_val = &cmp.bv_val[ offset ];
1553 cmp.bv_len -= offset;
1556 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
1563 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1564 if ( !op->o_conn->c_peer_name.bv_val ) {
1567 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
1568 b->a_peername_pat.bv_val, 0, 0 );
1569 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
1570 if ( b->a_peername_style == ACL_STYLE_REGEX ) {
1571 if (!regex_matches( &b->a_peername_pat, op->o_conn->c_peer_name.bv_val,
1572 e->e_ndn, nmatch, matches ) )
1578 /* try exact match */
1579 if ( b->a_peername_style == ACL_STYLE_BASE ) {
1580 if ( ber_bvstrcasecmp( &b->a_peername_pat, &op->o_conn->c_peer_name ) != 0 ) {
1584 } else if ( b->a_peername_style == ACL_STYLE_EXPAND ) {
1586 char buf[ACL_BUF_SIZE];
1588 bv.bv_len = sizeof( buf ) - 1;
1590 if ( acl_string_expand( &bv, &b->a_peername_pat,
1591 e->e_ndn, nmatch, matches ) )
1596 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_peer_name ) != 0 ) {
1600 /* extract IP and try exact match */
1601 } else if ( b->a_peername_style == ACL_STYLE_IP ) {
1603 char buf[] = "255.255.255.255";
1606 int port_number = -1;
1608 if ( strncasecmp( op->o_conn->c_peer_name.bv_val,
1609 aci_bv[ ACI_BV_IP_EQ ].bv_val,
1610 aci_bv[ ACI_BV_IP_EQ ].bv_len ) != 0 )
1613 ip.bv_val = op->o_conn->c_peer_name.bv_val + aci_bv[ ACI_BV_IP_EQ ].bv_len;
1614 ip.bv_len = op->o_conn->c_peer_name.bv_len - aci_bv[ ACI_BV_IP_EQ ].bv_len;
1616 port = strrchr( ip.bv_val, ':' );
1620 ip.bv_len = port - ip.bv_val;
1622 port_number = strtol( port, &next, 10 );
1623 if ( next[0] != '\0' )
1627 /* the port check can be anticipated here */
1628 if ( b->a_peername_port != -1 && port_number != b->a_peername_port )
1631 /* address longer than expected? */
1632 if ( ip.bv_len >= sizeof(buf) )
1635 AC_MEMCPY( buf, ip.bv_val, ip.bv_len );
1636 buf[ ip.bv_len ] = '\0';
1638 addr = inet_addr( buf );
1640 /* unable to convert? */
1641 if ( addr == (unsigned long)(-1) )
1644 if ( (addr & b->a_peername_mask) != b->a_peername_addr )
1647 #ifdef LDAP_PF_LOCAL
1648 /* extract path and try exact match */
1649 } else if ( b->a_peername_style == ACL_STYLE_PATH ) {
1652 if ( strncmp( op->o_conn->c_peer_name.bv_val,
1653 aci_bv[ ACI_BV_PATH_EQ ].bv_val,
1654 aci_bv[ ACI_BV_PATH_EQ ].bv_len ) != 0 )
1657 path.bv_val = op->o_conn->c_peer_name.bv_val
1658 + aci_bv[ ACI_BV_PATH_EQ ].bv_len;
1659 path.bv_len = op->o_conn->c_peer_name.bv_len
1660 - aci_bv[ ACI_BV_PATH_EQ ].bv_len;
1662 if ( ber_bvcmp( &b->a_peername_pat, &path ) != 0 )
1665 #endif /* LDAP_PF_LOCAL */
1667 /* exact match (very unlikely...) */
1668 } else if ( ber_bvcmp( &op->o_conn->c_peer_name, &b->a_peername_pat ) != 0 ) {
1675 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
1676 if ( BER_BVISNULL( &op->o_conn->c_sock_name ) ) {
1679 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
1680 b->a_sockname_pat.bv_val, 0, 0 );
1681 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
1682 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
1683 if (!regex_matches( &b->a_sockname_pat, op->o_conn->c_sock_name.bv_val,
1684 e->e_ndn, nmatch, matches ) )
1689 } else if ( b->a_sockname_style == ACL_STYLE_EXPAND ) {
1691 char buf[ACL_BUF_SIZE];
1693 bv.bv_len = sizeof( buf ) - 1;
1695 if ( acl_string_expand( &bv, &b->a_sockname_pat,
1696 e->e_ndn, nmatch, matches ) )
1701 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_sock_name ) != 0 ) {
1706 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &op->o_conn->c_sock_name ) != 0 ) {
1713 if ( b->a_dn_at != NULL ) {
1714 if ( acl_mask_dnattr( op, e, val, a, b, i,
1715 matches, count, state,
1716 &b->a_dn, &op->o_ndn ) )
1722 if ( b->a_realdn_at != NULL ) {
1725 if ( op->o_conn && !BER_BVISNULL( &op->o_conn->c_ndn ) )
1727 ndn = op->o_conn->c_ndn;
1732 if ( acl_mask_dnattr( op, e, val, a, b, i,
1733 matches, count, state,
1734 &b->a_realdn, &ndn ) )
1740 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1742 struct berval ndn = BER_BVNULL;
1745 if ( op->o_ndn.bv_len == 0 ) {
1749 Debug( LDAP_DEBUG_ACL, "<= check a_group_pat: %s\n",
1750 b->a_group_pat.bv_val, 0, 0 );
1752 /* b->a_group is an unexpanded entry name, expanded it should be an
1753 * entry with objectclass group* and we test to see if odn is one of
1754 * the values in the attribute group
1756 /* see if asker is listed in dnattr */
1757 if ( b->a_group_style == ACL_STYLE_EXPAND ) {
1758 char buf[ACL_BUF_SIZE];
1760 regmatch_t tmp_matches[2],
1761 *tmp_matchesp = tmp_matches;
1763 bv.bv_len = sizeof(buf) - 1;
1768 switch ( a->acl_dn_style ) {
1769 case ACL_STYLE_REGEX:
1770 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1771 tmp_matchesp = matches;
1772 tmp_nmatch = nmatch;
1776 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1777 case ACL_STYLE_BASE:
1778 tmp_matches[0].rm_so = 0;
1779 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1784 case ACL_STYLE_SUBTREE:
1785 case ACL_STYLE_CHILDREN:
1786 tmp_matches[0].rm_so = 0;
1787 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1788 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1789 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1803 if ( acl_string_expand( &bv, &b->a_group_pat,
1805 tmp_nmatch, tmp_matchesp ) )
1810 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn,
1811 op->o_tmpmemctx ) != LDAP_SUCCESS )
1813 /* did not expand to a valid dn */
1820 bv = b->a_group_pat;
1823 rc = backend_group( op, e, &bv, &op->o_ndn,
1824 b->a_group_oc, b->a_group_at );
1827 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1835 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1837 char buf[ACL_BUF_SIZE];
1839 Debug( LDAP_DEBUG_ACL, "<= check a_set_pat: %s\n",
1840 b->a_set_pat.bv_val, 0, 0 );
1842 if ( b->a_set_style == ACL_STYLE_EXPAND ) {
1844 regmatch_t tmp_matches[2],
1845 *tmp_matchesp = tmp_matches;
1848 bv.bv_len = sizeof( buf ) - 1;
1853 switch ( a->acl_dn_style ) {
1854 case ACL_STYLE_REGEX:
1855 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1856 tmp_matchesp = matches;
1857 tmp_nmatch = nmatch;
1861 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1862 case ACL_STYLE_BASE:
1863 tmp_matches[0].rm_so = 0;
1864 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1869 case ACL_STYLE_SUBTREE:
1870 case ACL_STYLE_CHILDREN:
1871 tmp_matches[0].rm_so = 0;
1872 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1873 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1874 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1888 if ( acl_string_expand( &bv, &b->a_set_pat,
1890 tmp_nmatch, tmp_matchesp ) )
1899 if ( acl_match_set( &bv, op, e, 0 ) == 0 ) {
1904 if ( b->a_authz.sai_ssf ) {
1905 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1906 b->a_authz.sai_ssf, op->o_ssf, 0 );
1907 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1912 if ( b->a_authz.sai_transport_ssf ) {
1913 Debug( LDAP_DEBUG_ACL,
1914 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1915 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1916 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1921 if ( b->a_authz.sai_tls_ssf ) {
1922 Debug( LDAP_DEBUG_ACL,
1923 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1924 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1925 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1930 if ( b->a_authz.sai_sasl_ssf ) {
1931 Debug( LDAP_DEBUG_ACL,
1932 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1933 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1934 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1940 if ( b->a_dynacl ) {
1942 slap_access_t tgrant, tdeny;
1944 Debug( LDAP_DEBUG_ACL, "<= check a_dynacl\n",
1947 /* this case works different from the others above.
1948 * since aci's themselves give permissions, we need
1949 * to first check b->a_access_mask, the ACL's access level.
1951 if ( BER_BVISEMPTY( &e->e_nname ) ) {
1952 /* no ACIs in the root DSE */
1956 /* first check if the right being requested
1957 * is allowed by the ACL clause.
1959 if ( ! ACL_PRIV_ISSET( b->a_access_mask, a2pmask ) ) {
1963 /* start out with nothing granted, nothing denied */
1967 for ( da = b->a_dynacl; da; da = da->da_next ) {
1968 slap_access_t grant,
1974 Debug( LDAP_DEBUG_ACL, " <= check a_dynacl: %s\n",
1975 da->da_name, 0, 0 );
1977 (void)( *da->da_mask )( da->da_private, op, e, desc, val, nmatch, matches, &grant, &deny );
1983 /* remove anything that the ACL clause does not allow */
1984 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1985 tdeny &= ACL_PRIV_MASK;
1987 /* see if we have anything to contribute */
1988 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1992 /* this could be improved by changing slap_acl_mask so that it can deal with
1993 * by clauses that return grant/deny pairs. Right now, it does either
1994 * additive or subtractive rights, but not both at the same time. So,
1995 * we need to combine the grant/deny pair into a single rights mask in
1996 * a smart way: if either grant or deny is "empty", then we use the
1997 * opposite as is, otherwise we remove any denied rights from the grant
1998 * rights mask and construct an additive mask.
2000 if (ACL_IS_INVALID(tdeny)) {
2001 modmask = tgrant | ACL_PRIV_ADDITIVE;
2003 } else if (ACL_IS_INVALID(tgrant)) {
2004 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
2007 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
2011 #else /* !SLAP_DYNACL */
2013 #ifdef SLAPD_ACI_ENABLED
2014 if ( b->a_aci_at != NULL ) {
2016 slap_access_t grant, deny, tgrant, tdeny;
2017 struct berval parent_ndn;
2018 BerVarray bvals = NULL;
2021 Debug( LDAP_DEBUG_ACL, " <= check a_aci_at: %s\n",
2022 b->a_aci_at->ad_cname.bv_val, 0, 0 );
2024 /* this case works different from the others above.
2025 * since aci's themselves give permissions, we need
2026 * to first check b->a_access_mask, the ACL's access level.
2029 if ( BER_BVISEMPTY( &e->e_nname ) ) {
2030 /* no ACIs in the root DSE */
2034 /* first check if the right being requested
2035 * is allowed by the ACL clause.
2037 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
2040 /* start out with nothing granted, nothing denied */
2044 /* get the aci attribute */
2045 at = attr_find( e->e_attrs, b->a_aci_at );
2048 /* FIXME: this breaks acl caching;
2049 * see also ACL_RECORD_VALUE_STATE below */
2050 ACL_RECORD_VALUE_STATE;
2052 /* the aci is an multi-valued attribute. The
2053 * rights are determined by OR'ing the individual
2054 * rights given by the acis.
2056 for ( i = 0; !BER_BVISNULL( &at->a_nvals[i] ); i++ ) {
2061 &grant, &deny, SLAP_ACI_SCOPE_ENTRY ) != 0 )
2067 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2068 accessmask2str(tgrant, accessmaskbuf, 1),
2069 accessmask2str(tdeny, accessmaskbuf1, 1), 0);
2072 /* If the entry level aci didn't contain anything valid for the
2073 * current operation, climb up the tree and evaluate the
2074 * acis with scope set to subtree
2076 if ( (tgrant == ACL_PRIV_NONE) && (tdeny == ACL_PRIV_NONE) ) {
2077 dnParent( &e->e_nname, &parent_ndn );
2078 while ( !BER_BVISEMPTY( &parent_ndn ) ) {
2079 Debug(LDAP_DEBUG_ACL, "checking ACI of %s\n", parent_ndn.bv_val, 0, 0);
2080 ret = backend_attribute(op, NULL, &parent_ndn, b->a_aci_at, &bvals, ACL_AUTH);
2088 for ( i = 0; !BER_BVISNULL( &bvals[i] ); i++ ) {
2090 /* FIXME: this breaks acl caching;
2091 * see also ACL_RECORD_VALUE_STATE above */
2092 ACL_RECORD_VALUE_STATE;
2094 if ( aci_mask( op, e, desc, val, &bvals[i],
2096 &grant, &deny, SLAP_ACI_SCOPE_CHILDREN ) != 0 )
2100 /* evaluation stops as soon as either a "deny" or a
2101 * "grant" directive matches.
2103 if( (tgrant != ACL_PRIV_NONE) || (tdeny != ACL_PRIV_NONE) ){
2107 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2108 accessmask2str(tgrant, accessmaskbuf, 1),
2109 accessmask2str(tdeny, accessmaskbuf1, 1), 0);
2113 case LDAP_NO_SUCH_ATTRIBUTE:
2114 /* just go on if the aci-Attribute is not present in
2117 Debug(LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0);
2121 case LDAP_NO_SUCH_OBJECT:
2122 /* We have reached the base object */
2123 Debug(LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0);
2134 dnParent( &parent_ndn, &parent_ndn );
2139 /* remove anything that the ACL clause does not allow */
2140 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
2141 tdeny &= ACL_PRIV_MASK;
2143 /* see if we have anything to contribute */
2144 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
2148 /* this could be improved by changing slap_acl_mask so that it can deal with
2149 * by clauses that return grant/deny pairs. Right now, it does either
2150 * additive or subtractive rights, but not both at the same time. So,
2151 * we need to combine the grant/deny pair into a single rights mask in
2152 * a smart way: if either grant or deny is "empty", then we use the
2153 * opposite as is, otherwise we remove any denied rights from the grant
2154 * rights mask and construct an additive mask.
2156 if (ACL_IS_INVALID(tdeny)) {
2157 modmask = tgrant | ACL_PRIV_ADDITIVE;
2159 } else if (ACL_IS_INVALID(tgrant)) {
2160 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
2163 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
2167 #endif /* SLAPD_ACI_ENABLED */
2168 #endif /* !SLAP_DYNACL */
2170 modmask = b->a_access_mask;
2173 Debug( LDAP_DEBUG_ACL,
2174 "<= acl_mask: [%d] applying %s (%s)\n",
2175 i, accessmask2str( modmask, accessmaskbuf, 1 ),
2176 b->a_type == ACL_CONTINUE
2178 : b->a_type == ACL_BREAK
2184 if( ACL_IS_ADDITIVE(modmask) ) {
2186 ACL_PRIV_SET( *mask, modmask );
2189 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
2191 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
2192 /* substract privs */
2193 ACL_PRIV_CLR( *mask, modmask );
2196 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
2205 Debug( LDAP_DEBUG_ACL,
2206 "<= acl_mask: [%d] mask: %s\n",
2207 i, accessmask2str(*mask, accessmaskbuf, 1), 0 );
2209 if( b->a_type == ACL_CONTINUE ) {
2212 } else if ( b->a_type == ACL_BREAK ) {
2220 /* implicit "by * none" clause */
2223 Debug( LDAP_DEBUG_ACL,
2224 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
2225 accessmask2str(*mask, accessmaskbuf, 1), 0, 0 );
2230 * acl_check_modlist - check access control on the given entry to see if
2231 * it allows the given modifications by the user associated with op.
2232 * returns 1 if mods allowed ok
2233 * 0 mods not allowed
2240 Modifications *mlist
2244 AccessControlState state = ACL_STATE_INIT;
2247 int ret = 1; /* default is access allowed */
2251 be = LDAP_STAILQ_FIRST(&backendDB);
2255 assert( be != NULL );
2257 /* short circuit root database access */
2258 if ( be_isroot( op ) ) {
2259 Debug( LDAP_DEBUG_ACL,
2260 "<= acl_access_allowed: granted to database root\n",
2265 /* use backend default access if no backend acls */
2266 if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
2267 Debug( LDAP_DEBUG_ACL,
2268 "=> access_allowed: backend default %s access %s to \"%s\"\n",
2269 access2str( ACL_WRITE ),
2270 op->o_bd->be_dfltaccess >= ACL_WRITE
2271 ? "granted" : "denied",
2273 ret = (op->o_bd->be_dfltaccess >= ACL_WRITE);
2277 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
2279 * Internal mods are ignored by ACL_WRITE checking
2281 if ( mlist->sml_flags & SLAP_MOD_INTERNAL ) {
2282 Debug( LDAP_DEBUG_ACL, "acl: internal mod %s:"
2283 " modify access granted\n",
2284 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
2289 * no-user-modification operational attributes are ignored
2290 * by ACL_WRITE checking as any found here are not provided
2293 if ( is_at_no_user_mod( mlist->sml_desc->ad_type )
2294 && !mlist->sml_managing )
2296 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
2297 " modify access granted\n",
2298 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
2302 switch ( mlist->sml_op ) {
2303 case LDAP_MOD_REPLACE:
2305 * We must check both permission to delete the whole
2306 * attribute and permission to add the specific attributes.
2307 * This prevents abuse from selfwriters.
2309 if ( ! access_allowed( op, e,
2310 mlist->sml_desc, NULL, ACL_WDEL, &state ) )
2316 if ( mlist->sml_values == NULL ) break;
2318 /* fall thru to check value to add */
2321 assert( mlist->sml_values != NULL );
2323 for ( bv = mlist->sml_nvalues
2324 ? mlist->sml_nvalues : mlist->sml_values;
2325 bv->bv_val != NULL; bv++ )
2327 if ( ! access_allowed( op, e,
2328 mlist->sml_desc, bv, ACL_WADD, &state ) )
2336 case LDAP_MOD_DELETE:
2337 if ( mlist->sml_values == NULL ) {
2338 if ( ! access_allowed( op, e,
2339 mlist->sml_desc, NULL, ACL_WDEL, NULL ) )
2346 for ( bv = mlist->sml_nvalues
2347 ? mlist->sml_nvalues : mlist->sml_values;
2348 bv->bv_val != NULL; bv++ )
2350 if ( ! access_allowed( op, e,
2351 mlist->sml_desc, bv, ACL_WDEL, &state ) )
2359 case SLAP_MOD_SOFTADD:
2360 /* allow adding attribute via modrdn thru */
2372 if (be_null) op->o_bd = NULL;
2378 struct berval *list,
2391 while ( len >= 0 && --ix >= 0 ) {
2392 while ( --len >= 0 && *p++ != sep )
2395 while ( len >= 0 && *p == ' ' ) {
2408 while ( --len >= 0 && *p != sep ) {
2412 while ( bv->bv_len > 0 && *--p == ' ' ) {
2419 typedef struct acl_set_gather_t {
2425 acl_set_cb_gather( Operation *op, SlapReply *rs )
2427 acl_set_gather_t *p = (acl_set_gather_t *)op->o_callback->sc_private;
2429 if ( rs->sr_type == REP_SEARCH ) {
2430 BerValue bvals[ 2 ];
2431 BerVarray bvalsp = NULL;
2434 for ( j = 0; !BER_BVISNULL( &rs->sr_attrs[ j ].an_name ); j++ ) {
2435 AttributeDescription *desc = rs->sr_attrs[ j ].an_desc;
2437 if ( desc == slap_schema.si_ad_entryDN ) {
2439 bvals[ 0 ] = rs->sr_entry->e_nname;
2440 BER_BVZERO( &bvals[ 1 ] );
2445 a = attr_find( rs->sr_entry->e_attrs, desc );
2449 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ )
2452 bvalsp = a->a_nvals;
2458 p->bvals = slap_set_join( p->cookie, p->bvals,
2459 ( '|' | SLAP_SET_RREF ), bvalsp );
2463 assert( rs->sr_type == REP_RESULT );
2470 acl_set_gather( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
2472 AclSetCookie *cp = (AclSetCookie *)cookie;
2474 LDAPURLDesc *ludp = NULL;
2475 Operation op2 = { 0 };
2476 SlapReply rs = {REP_RESULT};
2477 AttributeName anlist[ 2 ], *anlistp = NULL;
2479 slap_callback cb = { NULL, acl_set_cb_gather, NULL, NULL };
2480 acl_set_gather_t p = { 0 };
2481 const char *text = NULL;
2482 static struct berval defaultFilter_bv = BER_BVC( "(objectClass=*)" );
2484 /* this routine needs to return the bervals instead of
2485 * plain strings, since syntax is not known. It should
2486 * also return the syntax or some "comparison cookie".
2488 if ( strncasecmp( name->bv_val, "ldap:///", STRLENOF( "ldap:///" ) ) != 0 ) {
2489 return acl_set_gather2( cookie, name, desc );
2492 rc = ldap_url_parse( name->bv_val, &ludp );
2493 if ( rc != LDAP_URL_SUCCESS ) {
2494 rc = LDAP_PROTOCOL_ERROR;
2498 if ( ( ludp->lud_host && ludp->lud_host[0] ) || ludp->lud_exts )
2500 /* host part must be empty */
2501 /* extensions parts must be empty */
2502 rc = LDAP_PROTOCOL_ERROR;
2506 /* Grab the searchbase and see if an appropriate database can be found */
2507 ber_str2bv( ludp->lud_dn, 0, 0, &op2.o_req_dn );
2508 rc = dnNormalize( 0, NULL, NULL, &op2.o_req_dn,
2509 &op2.o_req_ndn, cp->op->o_tmpmemctx );
2510 BER_BVZERO( &op2.o_req_dn );
2511 if ( rc != LDAP_SUCCESS ) {
2515 op2.o_bd = select_backend( &op2.o_req_ndn, 0, 1 );
2516 if ( ( op2.o_bd == NULL ) || ( op2.o_bd->be_search == NULL ) ) {
2517 rc = LDAP_NO_SUCH_OBJECT;
2521 /* Grab the filter */
2522 if ( ludp->lud_filter ) {
2523 ber_str2bv_x( ludp->lud_filter, 0, 0, &op2.ors_filterstr,
2524 cp->op->o_tmpmemctx );
2527 op2.ors_filterstr = defaultFilter_bv;
2530 op2.ors_filter = str2filter_x( cp->op, op2.ors_filterstr.bv_val );
2531 if ( op2.ors_filter == NULL ) {
2532 rc = LDAP_PROTOCOL_ERROR;
2536 /* Grab the scope */
2537 op2.ors_scope = ludp->lud_scope;
2539 /* Grap the attributes */
2540 if ( ludp->lud_attrs ) {
2541 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ )
2544 anlistp = slap_sl_malloc( sizeof( AttributeName ) * ( nattrs + 2 ),
2545 cp->op->o_tmpmemctx );
2547 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ ) {
2548 ber_str2bv( ludp->lud_attrs[ nattrs ], 0, 0, &anlistp[ nattrs ].an_name );
2549 anlistp[ nattrs ].an_desc = NULL;
2550 rc = slap_bv2ad( &anlistp[ nattrs ].an_name,
2551 &anlistp[ nattrs ].an_desc, &text );
2552 if ( rc != LDAP_SUCCESS ) {
2561 anlistp[ nattrs ].an_name = desc->ad_cname;
2562 anlistp[ nattrs ].an_desc = desc;
2564 BER_BVZERO( &anlistp[ nattrs + 1 ].an_name );
2568 op2.o_hdr = cp->op->o_hdr;
2569 op2.o_tag = LDAP_REQ_SEARCH;
2570 op2.o_ndn = op2.o_bd->be_rootndn;
2571 op2.o_callback = &cb;
2572 op2.o_time = slap_get_time();
2573 op2.o_do_not_cache = 1;
2574 op2.o_is_auth_check = 0;
2575 ber_dupbv_x( &op2.o_req_dn, &op2.o_req_ndn, cp->op->o_tmpmemctx );
2576 op2.ors_slimit = SLAP_NO_LIMIT;
2577 op2.ors_tlimit = SLAP_NO_LIMIT;
2578 op2.ors_attrs = anlistp;
2579 op2.ors_attrsonly = 0;
2580 op2.o_private = cp->op->o_private;
2584 rc = op2.o_bd->be_search( &op2, &rs );
2590 if ( op2.ors_filter ) {
2591 filter_free_x( cp->op, op2.ors_filter );
2593 if ( !BER_BVISNULL( &op2.o_req_ndn ) ) {
2594 slap_sl_free( op2.o_req_ndn.bv_val, cp->op->o_tmpmemctx );
2596 if ( !BER_BVISNULL( &op2.o_req_dn ) ) {
2597 slap_sl_free( op2.o_req_dn.bv_val, cp->op->o_tmpmemctx );
2600 ldap_free_urldesc( ludp );
2602 if ( anlistp && anlistp != anlist ) {
2603 slap_sl_free( anlistp, cp->op->o_tmpmemctx );
2610 acl_set_gather2( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
2612 AclSetCookie *cp = (AclSetCookie *)cookie;
2613 BerVarray bvals = NULL;
2617 /* this routine needs to return the bervals instead of
2618 * plain strings, since syntax is not known. It should
2619 * also return the syntax or some "comparison cookie".
2621 rc = dnNormalize( 0, NULL, NULL, name, &ndn, cp->op->o_tmpmemctx );
2622 if ( rc == LDAP_SUCCESS ) {
2623 if ( desc == slap_schema.si_ad_entryDN ) {
2624 bvals = (BerVarray)slap_sl_malloc( sizeof( BerValue ) * 2,
2625 cp->op->o_tmpmemctx );
2627 BER_BVZERO( &bvals[ 1 ] );
2631 backend_attribute( cp->op,
2632 cp->e, &ndn, desc, &bvals, ACL_NONE );
2635 if ( !BER_BVISNULL( &ndn ) ) {
2636 slap_sl_free( ndn.bv_val, cp->op->o_tmpmemctx );
2645 struct berval *subj,
2650 struct berval set = BER_BVNULL;
2652 AclSetCookie cookie;
2654 if ( setref == 0 ) {
2655 ber_dupbv_x( &set, subj, op->o_tmpmemctx );
2658 struct berval subjdn, ndn = BER_BVNULL;
2659 struct berval setat;
2662 AttributeDescription *desc = NULL;
2664 /* format of string is "entry/setAttrName" */
2665 if ( acl_get_part( subj, 0, '/', &subjdn ) < 0 ) {
2669 if ( acl_get_part( subj, 1, '/', &setat ) < 0 ) {
2670 setat = aci_bv[ ACI_BV_SET_ATTR ];
2674 * NOTE: dnNormalize honors the ber_len field
2675 * as the length of the dn to be normalized
2677 if ( slap_bv2ad( &setat, &desc, &text ) == LDAP_SUCCESS ) {
2678 if ( dnNormalize( 0, NULL, NULL, &subjdn, &ndn, op->o_tmpmemctx ) == LDAP_SUCCESS )
2680 backend_attribute( op, e, &ndn, desc, &bvals, ACL_NONE );
2681 if ( bvals != NULL && !BER_BVISNULL( &bvals[0] ) ) {
2685 BER_BVZERO( &bvals[0] );
2686 for ( i = 1; !BER_BVISNULL( &bvals[i] ); i++ )
2688 bvals[0].bv_val = bvals[i-1].bv_val;
2689 BER_BVZERO( &bvals[i-1] );
2691 ber_bvarray_free_x( bvals, op->o_tmpmemctx );
2692 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2697 if ( !BER_BVISNULL( &set ) ) {
2700 rc = ( slap_set_filter( acl_set_gather, (SetCookie *)&cookie, &set,
2701 &op->o_ndn, &e->e_nname, NULL ) > 0 );
2702 slap_sl_free( set.bv_val, op->o_tmpmemctx );
2711 * dynamic ACL infrastructure
2713 static slap_dynacl_t *da_list = NULL;
2716 slap_dynacl_register( slap_dynacl_t *da )
2720 for ( tmp = da_list; tmp; tmp = tmp->da_next ) {
2721 if ( strcasecmp( da->da_name, tmp->da_name ) == 0 ) {
2726 if ( tmp != NULL ) {
2730 if ( da->da_mask == NULL ) {
2734 da->da_private = NULL;
2735 da->da_next = da_list;
2741 static slap_dynacl_t *
2742 slap_dynacl_next( slap_dynacl_t *da )
2751 slap_dynacl_get( const char *name )
2755 for ( da = slap_dynacl_next( NULL ); da; da = slap_dynacl_next( da ) ) {
2756 if ( strcasecmp( da->da_name, name ) == 0 ) {
2763 #endif /* SLAP_DYNACL */
2771 #ifdef SLAPD_ACI_ENABLED
2772 rc = dynacl_aci_init();
2776 #endif /* SLAPD_ACI_ENABLED */
2778 #endif /* SLAP_DYNACL */
2789 regmatch_t *matches)
2797 bv->bv_val[0] = '\0';
2798 bv->bv_len--; /* leave space for lone $ */
2801 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
2802 sp < pat->bv_val + pat->bv_len ; sp++ )
2804 /* did we previously see a $ */
2806 if ( flag == 1 && *sp == '$' ) {
2811 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
2814 } else if ( *sp >= '0' && *sp <= '9' ) {
2822 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
2823 if ( *sp >= '0' && *sp <= '9' ) {
2824 n = 10*n + ( *sp - '0' );
2828 if ( *sp != /*'{'*/ '}' ) {
2834 if ( n >= nmatch ) {
2840 i = matches[n].rm_so;
2841 l = matches[n].rm_eo;
2842 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
2860 /* must have ended with a single $ */
2868 Debug( LDAP_DEBUG_TRACE, "=> acl_string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
2869 Debug( LDAP_DEBUG_TRACE, "=> acl_string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
2876 struct berval *pat, /* pattern to expand and match against */
2877 char *str, /* string to match against pattern */
2878 char *buf, /* buffer with $N expansion variables */
2879 int nmatch, /* size of the matches array */
2880 regmatch_t *matches /* offsets in buffer for $N expansion variables */
2884 char newbuf[ACL_BUF_SIZE];
2888 bv.bv_len = sizeof( newbuf ) - 1;
2895 acl_string_expand( &bv, pat, buf, nmatch, matches );
2896 rc = regcomp( &re, newbuf, REG_EXTENDED|REG_ICASE );
2898 char error[ACL_BUF_SIZE];
2899 regerror( rc, &re, error, sizeof( error ) );
2901 Debug( LDAP_DEBUG_TRACE,
2902 "compile( \"%s\", \"%s\") failed %s\n",
2903 pat->bv_val, str, error );
2907 rc = regexec( &re, str, 0, NULL, 0 );
2910 Debug( LDAP_DEBUG_TRACE,
2911 "=> regex_matches: string: %s\n", str, 0, 0 );
2912 Debug( LDAP_DEBUG_TRACE,
2913 "=> regex_matches: rc: %d %s\n",
2914 rc, !rc ? "matches" : "no matches", 0 );