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-2004 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 #include "slapi/slapi.h"
41 #endif /* LDAPI_SLAPI */
43 #define ACL_BUF_SIZE 1024 /* use most appropriate size */
49 aci_bv_entry = BER_BVC("entry"),
50 aci_bv_children = BER_BVC("children"),
51 aci_bv_subtree = BER_BVC("subtree"),
52 aci_bv_br_entry = BER_BVC("[entry]"),
53 aci_bv_br_all = BER_BVC("[all]"),
54 aci_bv_access_id = BER_BVC("access-id"),
55 aci_bv_anonymous = BER_BVC("anonymous"),
56 aci_bv_public = BER_BVC("public"),
57 aci_bv_users = BER_BVC("users"),
58 aci_bv_self = BER_BVC("self"),
59 aci_bv_dnattr = BER_BVC("dnattr"),
60 aci_bv_group = BER_BVC("group"),
61 aci_bv_role = BER_BVC("role"),
62 aci_bv_set = BER_BVC("set"),
63 aci_bv_set_ref = BER_BVC("set-ref"),
64 aci_bv_grant = BER_BVC("grant"),
65 aci_bv_deny = BER_BVC("deny"),
67 aci_bv_ip_eq = BER_BVC("IP="),
69 aci_bv_path_eq = BER_BVC("PATH="),
70 aci_bv_dirsep = BER_BVC(LDAP_DIRSEP),
71 #endif /* LDAP_PF_LOCAL */
73 aci_bv_group_class = BER_BVC(SLAPD_GROUP_CLASS),
74 aci_bv_group_attr = BER_BVC(SLAPD_GROUP_ATTR),
75 aci_bv_role_class = BER_BVC(SLAPD_ROLE_CLASS),
76 aci_bv_role_attr = BER_BVC(SLAPD_ROLE_ATTR),
77 aci_bv_set_attr = BER_BVC(SLAPD_ACI_SET_ATTR);
79 typedef enum slap_aci_scope_t {
80 SLAP_ACI_SCOPE_ENTRY = 0x1,
81 SLAP_ACI_SCOPE_CHILDREN = 0x2,
82 SLAP_ACI_SCOPE_SUBTREE = ( SLAP_ACI_SCOPE_ENTRY | SLAP_ACI_SCOPE_CHILDREN )
85 static AccessControl * acl_get(
86 AccessControl *ac, int *count,
87 Operation *op, Entry *e,
88 AttributeDescription *desc,
90 int nmatch, regmatch_t *matches,
91 AccessControlState *state );
93 static slap_control_t acl_mask(
94 AccessControl *ac, slap_mask_t *mask,
95 Operation *op, Entry *e,
96 AttributeDescription *desc,
101 AccessControlState *state );
103 #ifdef SLAPD_ACI_ENABLED
105 Operation *op, Entry *e,
106 AttributeDescription *desc,
111 slap_access_t *grant,
113 slap_aci_scope_t scope);
116 static int regex_matches(
117 struct berval *pat, char *str, char *buf,
118 int nmatch, regmatch_t *matches);
119 static int string_expand(
120 struct berval *newbuf, struct berval *pattern,
121 char *match, int nmatch, regmatch_t *matches);
123 typedef struct AciSetCookie {
128 SLAP_SET_GATHER aci_set_gather;
129 SLAP_SET_GATHER aci_set_gather2;
130 static int aci_match_set ( struct berval *subj, Operation *op,
131 Entry *e, int setref );
134 * access_allowed - check whether op->o_ndn is allowed the requested access
135 * to entry e, attribute attr, value val. if val is null, access to
136 * the whole attribute is assumed (all values).
138 * This routine loops through all access controls and calls
139 * acl_mask() on each applicable access control.
140 * The loop exits when a definitive answer is reached or
141 * or no more controls remain.
148 * - can be legally called with op == NULL
149 * - can be legally called with op->o_bd == NULL
156 AttributeDescription *desc,
158 slap_access_t access,
159 AccessControlState *state,
164 AccessControl *a = NULL;
169 char accessmaskbuf[ACCESSMASK_MAXLEN];
172 slap_control_t control;
174 regmatch_t matches[MAXREMATCHES];
175 int st_same_attr = 0;
176 static AccessControlState state_init = ACL_STATE_INIT;
179 assert( desc != NULL );
180 assert( access > ACL_NONE );
181 if ( maskp ) ACL_INVALIDATE( *maskp );
183 attr = desc->ad_cname.bv_val;
185 assert( attr != NULL );
187 if( op && op->o_is_auth_check &&
188 ( access == ACL_SEARCH || access == ACL_READ ))
194 if ( state->as_vd_ad==desc) {
195 if ( state->as_recorded ) {
196 if( state->as_recorded & ACL_STATE_RECORDED_NV &&
199 return state->as_result;
200 } else if ( state->as_recorded & ACL_STATE_RECORDED_VD &&
201 val != NULL && state->as_vd_acl == NULL )
203 return state->as_result;
211 state->as_vd_ad=desc;
214 Debug( LDAP_DEBUG_ACL,
215 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
216 access2str( access ), e->e_dn, attr );
229 * FIXME: experimental; use first backend rules
230 * iff there is no global_acl (ITS#3100) */
231 if ( frontendDB->be_acl == NULL )
237 assert( be != NULL );
240 if ( op->o_pb != NULL ) {
241 ret = slapi_int_access_allowed( op, e, desc, val, access, state );
243 /* ACL plugin denied access */
247 #endif /* LDAP_SLAPI */
249 /* grant database root access */
250 if ( be != NULL && be_isroot( op ) ) {
251 Debug( LDAP_DEBUG_ACL,
252 "<= root access granted\n",
255 mask = ACL_LVL_WRITE;
262 * no-user-modification operational attributes are ignored
263 * by ACL_WRITE checking as any found here are not provided
266 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type )
267 && desc != slap_schema.si_ad_entry
268 && desc != slap_schema.si_ad_children )
270 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
271 " %s access granted\n",
276 /* use backend default access if no backend acls */
277 if( be != NULL && be->be_acl == NULL ) {
278 Debug( LDAP_DEBUG_ACL,
279 "=> access_allowed: backend default %s access %s to \"%s\"\n",
280 access2str( access ),
281 be->be_dfltaccess >= access ? "granted" : "denied",
282 op->o_dn.bv_val ? op->o_dn.bv_val : "(anonymous)" );
283 ret = be->be_dfltaccess >= access;
288 mask = ACL_PRIV_LEVEL;
289 for ( i = ACL_NONE; i <= be->be_dfltaccess; i++ ) {
290 mask |= ACL_ACCESS2PRIV( i );
297 /* be is always non-NULL */
298 /* use global default access if no global acls */
299 } else if ( be == NULL && frontendDB->be_acl == NULL ) {
300 Debug( LDAP_DEBUG_ACL,
301 "=> access_allowed: global default %s access %s to \"%s\"\n",
302 access2str( access ),
303 frontendDB->be_dfltaccess >= access ? "granted" : "denied", op->o_dn.bv_val );
304 ret = frontendDB->be_dfltaccess >= access;
309 mask = ACL_PRIV_LEVEL;
310 for ( i = ACL_NONE; i <= global_default_access; i++ ) {
311 mask |= ACL_ACCESS2PRIV( i );
323 assert( state->as_vd_acl != NULL );
325 a = state->as_vd_acl;
326 count = state->as_vd_acl_count;
327 if ( !ACL_IS_INVALID( state->as_vd_acl_mask )) {
328 mask = state->as_vd_acl_mask;
329 AC_MEMCPY( matches, state->as_vd_acl_matches, sizeof(matches) );
334 if ( state ) state->as_vi_acl = NULL;
338 memset(matches, '\0', sizeof(matches));
341 while((a = acl_get( a, &count, op, e, desc, val,
342 MAXREMATCHES, matches, state )) != NULL)
346 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
347 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
348 (int)matches[i].rm_so, (int)matches[i].rm_eo );
349 if( matches[i].rm_so <= matches[0].rm_eo ) {
351 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
352 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
355 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
359 if (state->as_vi_acl == a && (state->as_recorded & ACL_STATE_RECORDED_NV)) {
360 Debug( LDAP_DEBUG_ACL, "access_allowed: result from state (%s)\n", attr, 0, 0 );
361 ret = state->as_result;
364 Debug( LDAP_DEBUG_ACL, "access_allowed: no res from state (%s)\n", attr, 0, 0);
369 control = acl_mask( a, &mask, op,
370 e, desc, val, MAXREMATCHES, matches, count, state );
372 if ( control != ACL_BREAK ) {
376 memset(matches, '\0', sizeof(matches));
379 if ( ACL_IS_INVALID( mask ) ) {
380 Debug( LDAP_DEBUG_ACL,
381 "=> access_allowed: \"%s\" (%s) invalid!\n",
385 } else if ( control == ACL_BREAK ) {
386 Debug( LDAP_DEBUG_ACL,
387 "=> access_allowed: no more rules\n", 0, 0, 0);
392 Debug( LDAP_DEBUG_ACL,
393 "=> access_allowed: %s access %s by %s\n",
394 access2str( access ),
395 ACL_GRANT(mask, access) ? "granted" : "denied",
396 accessmask2str( mask, accessmaskbuf ) );
398 ret = ACL_GRANT(mask, access);
401 if( state != NULL ) {
402 /* If not value-dependent, save ACL in case of more attrs */
403 if ( !(state->as_recorded & ACL_STATE_RECORDED_VD) ) {
404 state->as_vi_acl = a;
405 state->as_result = ret;
407 state->as_recorded |= ACL_STATE_RECORDED;
409 if (be_null) op->o_bd = NULL;
410 if ( maskp ) *maskp = mask;
416 * acl_get - return the acl applicable to entry e, attribute
417 * attr. the acl returned is suitable for use in subsequent calls to
418 * acl_access_allowed().
421 static AccessControl *
427 AttributeDescription *desc,
431 AccessControlState *state )
438 assert( count != NULL );
439 assert( desc != NULL );
441 attr = desc->ad_cname.bv_val;
443 assert( attr != NULL );
446 if( op->o_bd == NULL ) {
447 a = frontendDB->be_acl;
449 a = op->o_bd->be_acl;
460 dnlen = e->e_nname.bv_len;
462 for ( ; a != NULL; a = a->acl_next ) {
465 if ( a->acl_dn_pat.bv_len || ( a->acl_dn_style != ACL_STYLE_REGEX )) {
466 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
467 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
468 *count, a->acl_dn_pat.bv_val, (int) a->acl_dn_re.re_nsub );
469 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
473 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
474 *count, a->acl_dn_pat.bv_val, 0 );
475 patlen = a->acl_dn_pat.bv_len;
476 if ( dnlen < patlen )
479 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
480 /* base dn -- entire object DN must match */
481 if ( dnlen != patlen )
484 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
485 int rdnlen = -1, sep = 0;
487 if ( dnlen <= patlen )
491 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
496 rdnlen = dn_rdnlen( NULL, &e->e_nname );
497 if ( rdnlen != dnlen - patlen - sep )
500 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
501 if ( dnlen > patlen && !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
504 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
505 if ( dnlen <= patlen )
507 if ( !DN_SEPARATOR( e->e_ndn[dnlen - patlen - 1] ) )
511 if ( strcmp( a->acl_dn_pat.bv_val, e->e_ndn + dnlen - patlen ) != 0 )
515 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
519 if ( a->acl_attrs && !ad_inlist( desc, a->acl_attrs ) ) {
520 matches[0].rm_so = matches[0].rm_eo = -1;
524 /* Is this ACL only for a specific value? */
525 if ( a->acl_attrval.bv_len ) {
530 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) {
531 state->as_recorded |= ACL_STATE_RECORDED_VD;
532 state->as_vd_acl = prev;
533 state->as_vd_acl_count = *count;
534 state->as_vd_access = a->acl_access;
535 state->as_vd_access_count = 1;
536 ACL_INVALIDATE( state->as_vd_acl_mask );
539 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
540 Debug( LDAP_DEBUG_ACL,
541 "acl_get: valpat %s\n",
542 a->acl_attrval.bv_val, 0, 0 );
543 if (regexec(&a->acl_attrval_re, val->bv_val, 0, NULL, 0))
548 Debug( LDAP_DEBUG_ACL,
550 a->acl_attrval.bv_val, 0, 0 );
552 if ( a->acl_attrs[0].an_desc->ad_type->sat_syntax != slap_schema.si_syn_distinguishedName ) {
553 if (value_match( &match, desc,
554 desc->ad_type->sat_equality, 0,
555 val, &a->acl_attrval, &text ) != LDAP_SUCCESS ||
562 patlen = a->acl_attrval.bv_len;
563 vdnlen = val->bv_len;
565 if ( vdnlen < patlen )
568 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
569 if ( vdnlen > patlen )
572 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
575 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
578 rdnlen = dn_rdnlen( NULL, val );
579 if ( rdnlen != vdnlen - patlen - 1 )
582 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
583 if ( vdnlen > patlen && !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
586 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
587 if ( vdnlen <= patlen )
590 if ( !DN_SEPARATOR( val->bv_val[vdnlen - patlen - 1] ) )
594 if ( strcmp( a->acl_attrval.bv_val, val->bv_val + vdnlen - patlen ))
600 if ( a->acl_filter != NULL ) {
601 ber_int_t rc = test_filter( NULL, e, a->acl_filter );
602 if ( rc != LDAP_COMPARE_TRUE ) {
607 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] attr %s\n",
612 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
617 * Record value-dependent access control state
619 #define ACL_RECORD_VALUE_STATE do { \
620 if( state && !( state->as_recorded & ACL_STATE_RECORDED_VD )) { \
621 state->as_recorded |= ACL_STATE_RECORDED_VD; \
622 state->as_vd_acl = a; \
623 AC_MEMCPY( state->as_vd_acl_matches, matches, \
624 sizeof( state->as_vd_acl_matches )) ; \
625 state->as_vd_acl_count = count; \
626 state->as_vd_access = b; \
627 state->as_vd_access_count = i; \
632 * acl_mask - modifies mask based upon the given acl and the
633 * requested access to entry e, attribute attr, value val. if val
634 * is null, access to the whole attribute is assumed (all values).
636 * returns 0 access NOT allowed
640 static slap_control_t
646 AttributeDescription *desc,
651 AccessControlState *state )
653 int i, odnlen, patlen;
656 char accessmaskbuf[ACCESSMASK_MAXLEN];
657 char accessmaskbuf1[ACCESSMASK_MAXLEN];
662 assert( mask != NULL );
663 assert( desc != NULL );
665 attr = desc->ad_cname.bv_val;
667 assert( attr != NULL );
669 Debug( LDAP_DEBUG_ACL,
670 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
673 Debug( LDAP_DEBUG_ACL,
674 "=> acl_mask: to %s by \"%s\", (%s) \n",
675 val ? "value" : "all values",
676 op->o_ndn.bv_val ? op->o_ndn.bv_val : "",
677 accessmask2str( *mask, accessmaskbuf ) );
680 if( state && ( state->as_recorded & ACL_STATE_RECORDED_VD )
681 && state->as_vd_acl == a )
683 b = state->as_vd_access;
684 i = state->as_vd_access_count;
691 for ( ; b != NULL; b = b->a_next, i++ ) {
692 slap_mask_t oldmask, modmask;
694 ACL_INVALIDATE( modmask );
696 /* AND <who> clauses */
697 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
698 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
699 b->a_dn_pat.bv_val, 0, 0);
701 * if access applies to the entry itself, and the
702 * user is bound as somebody in the same namespace as
703 * the entry, OR the given dn matches the dn pattern
706 * NOTE: styles "anonymous", "users" and "self"
707 * have been moved to an enumeration, * whose value
708 * is set in a_dn_style; however, the string
709 * is maintaned in a_dn_pat.
711 if ( b->a_dn_style == ACL_STYLE_ANONYMOUS /* bvmatch( &b->a_dn_pat, &aci_bv_anonymous ) */ ) {
712 if ( op->o_ndn.bv_len != 0 ) {
716 } else if ( b->a_dn_style == ACL_STYLE_USERS /* bvmatch( &b->a_dn_pat, &aci_bv_users ) */ ) {
717 if ( op->o_ndn.bv_len == 0 ) {
721 } else if ( b->a_dn_style == ACL_STYLE_SELF /* bvmatch( &b->a_dn_pat, &aci_bv_self ) */ ) {
722 if ( op->o_ndn.bv_len == 0 ) {
726 if ( e->e_dn == NULL || !dn_match( &e->e_nname, &op->o_ndn ) ) {
730 } else if ( b->a_dn_style == ACL_STYLE_REGEX ) {
731 if ( !ber_bvccmp( &b->a_dn_pat, '*' ) ) {
733 regmatch_t tmp_matches[2],
734 *tmp_matchesp = tmp_matches;
738 switch ( a->acl_dn_style ) {
739 case ACL_STYLE_REGEX:
740 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
741 tmp_matchesp = matches;
745 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
748 tmp_matches[0].rm_so = 0;
749 tmp_matches[0].rm_eo = e->e_nname.bv_len;
754 case ACL_STYLE_SUBTREE:
755 case ACL_STYLE_CHILDREN:
756 tmp_matches[0].rm_so = 0;
757 tmp_matches[0].rm_eo = e->e_nname.bv_len;
758 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
759 tmp_matches[1].rm_eo = e->e_nname.bv_len;
773 if ( !regex_matches( &b->a_dn_pat,
774 op->o_ndn.bv_val, e->e_ndn,
775 tmp_nmatch, tmp_matchesp ) )
785 if ( e->e_dn == NULL )
788 if ( b->a_dn_expand ) {
790 char buf[ACL_BUF_SIZE];
793 regmatch_t tmp_matches[2],
794 *tmp_matchesp = tmp_matches;
798 bv.bv_len = sizeof( buf ) - 1;
801 switch ( a->acl_dn_style ) {
802 case ACL_STYLE_REGEX:
803 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
804 tmp_matchesp = matches;
808 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
811 tmp_matches[0].rm_so = 0;
812 tmp_matches[0].rm_eo = e->e_nname.bv_len;
817 case ACL_STYLE_SUBTREE:
818 case ACL_STYLE_CHILDREN:
819 tmp_matches[0].rm_so = 0;
820 tmp_matches[0].rm_eo = e->e_nname.bv_len;
821 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
822 tmp_matches[1].rm_eo = e->e_nname.bv_len;
836 if ( string_expand( &bv, &b->a_dn_pat,
838 tmp_nmatch, tmp_matchesp ) )
843 if ( dnNormalize(0, NULL, NULL, &bv,
844 &pat, op->o_tmpmemctx )
847 /* did not expand to a valid dn */
856 odnlen = op->o_ndn.bv_len;
857 if ( odnlen < patlen ) {
858 goto dn_match_cleanup;
862 if ( b->a_dn_style == ACL_STYLE_BASE ) {
863 /* base dn -- entire object DN must match */
864 if ( odnlen != patlen ) {
865 goto dn_match_cleanup;
868 } else if ( b->a_dn_style == ACL_STYLE_ONE ) {
871 if ( odnlen <= patlen ) {
872 goto dn_match_cleanup;
875 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
876 goto dn_match_cleanup;
879 rdnlen = dn_rdnlen( NULL, &op->o_ndn );
880 if ( rdnlen != odnlen - patlen - 1 ) {
881 goto dn_match_cleanup;
884 } else if ( b->a_dn_style == ACL_STYLE_SUBTREE ) {
885 if ( odnlen > patlen && !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
886 goto dn_match_cleanup;
889 } else if ( b->a_dn_style == ACL_STYLE_CHILDREN ) {
890 if ( odnlen <= patlen ) {
891 goto dn_match_cleanup;
894 if ( !DN_SEPARATOR( op->o_ndn.bv_val[odnlen - patlen - 1] ) ) {
895 goto dn_match_cleanup;
899 got_match = !strcmp( pat.bv_val, op->o_ndn.bv_val + odnlen - patlen );
902 if ( pat.bv_val != b->a_dn_pat.bv_val ) {
903 slap_sl_free( pat.bv_val, op->o_tmpmemctx );
912 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
913 if ( ! op->o_conn->c_listener ) {
916 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
917 b->a_sockurl_pat.bv_val, 0, 0 );
919 if ( !ber_bvccmp( &b->a_sockurl_pat, '*' ) ) {
920 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
921 if (!regex_matches( &b->a_sockurl_pat, op->o_conn->c_listener_url.bv_val,
922 e->e_ndn, nmatch, matches ) )
927 } else if ( b->a_sockurl_style == ACL_STYLE_EXPAND ) {
929 char buf[ACL_BUF_SIZE];
931 bv.bv_len = sizeof( buf ) - 1;
933 if ( string_expand( &bv, &b->a_sockurl_pat,
934 e->e_ndn, nmatch, matches ) )
939 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_listener_url ) != 0 )
945 if ( ber_bvstrcasecmp( &b->a_sockurl_pat, &op->o_conn->c_listener_url ) != 0 )
953 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
954 if ( !op->o_conn->c_peer_domain.bv_val ) {
957 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
958 b->a_domain_pat.bv_val, 0, 0 );
959 if ( !ber_bvccmp( &b->a_domain_pat, '*' ) ) {
960 if ( b->a_domain_style == ACL_STYLE_REGEX) {
961 if (!regex_matches( &b->a_domain_pat, op->o_conn->c_peer_domain.bv_val,
962 e->e_ndn, nmatch, matches ) )
967 char buf[ACL_BUF_SIZE];
969 struct berval cmp = op->o_conn->c_peer_domain;
970 struct berval pat = b->a_domain_pat;
972 if ( b->a_domain_expand ) {
975 bv.bv_len = sizeof(buf) - 1;
978 if ( string_expand(&bv, &b->a_domain_pat,
979 e->e_ndn, nmatch, matches) )
986 if ( b->a_domain_style == ACL_STYLE_SUBTREE ) {
987 int offset = cmp.bv_len - pat.bv_len;
992 if ( offset == 1 || ( offset > 1 && cmp.bv_val[ offset - 1 ] != '.' ) ) {
996 /* trim the domain */
997 cmp.bv_val = &cmp.bv_val[ offset ];
998 cmp.bv_len -= offset;
1001 if ( ber_bvstrcasecmp( &pat, &cmp ) != 0 ) {
1008 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1009 if ( !op->o_conn->c_peer_name.bv_val ) {
1012 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
1013 b->a_peername_pat.bv_val, 0, 0 );
1014 if ( !ber_bvccmp( &b->a_peername_pat, '*' ) ) {
1015 if ( b->a_peername_style == ACL_STYLE_REGEX ) {
1016 if (!regex_matches( &b->a_peername_pat, op->o_conn->c_peer_name.bv_val,
1017 e->e_ndn, nmatch, matches ) )
1023 /* try exact match */
1024 if ( b->a_peername_style == ACL_STYLE_BASE ) {
1025 if ( ber_bvstrcasecmp( &b->a_peername_pat, &op->o_conn->c_peer_name ) != 0 ) {
1029 } else if ( b->a_peername_style == ACL_STYLE_EXPAND ) {
1031 char buf[ACL_BUF_SIZE];
1033 bv.bv_len = sizeof( buf ) - 1;
1035 if ( string_expand( &bv, &b->a_peername_pat,
1036 e->e_ndn, nmatch, matches ) )
1041 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_peer_name ) != 0 ) {
1045 /* extract IP and try exact match */
1046 } else if ( b->a_peername_style == ACL_STYLE_IP ) {
1048 char buf[] = "255.255.255.255";
1051 int port_number = -1;
1053 if ( strncasecmp( op->o_conn->c_peer_name.bv_val,
1054 aci_bv_ip_eq.bv_val, aci_bv_ip_eq.bv_len ) != 0 )
1057 ip.bv_val = op->o_conn->c_peer_name.bv_val + aci_bv_ip_eq.bv_len;
1058 ip.bv_len = op->o_conn->c_peer_name.bv_len - aci_bv_ip_eq.bv_len;
1060 port = strrchr( ip.bv_val, ':' );
1064 ip.bv_len = port - ip.bv_val;
1066 port_number = strtol( port, &next, 10 );
1067 if ( next[0] != '\0' )
1071 /* the port check can be anticipated here */
1072 if ( b->a_peername_port != -1 && port_number != b->a_peername_port )
1075 /* address longer than expected? */
1076 if ( ip.bv_len >= sizeof(buf) )
1079 AC_MEMCPY( buf, ip.bv_val, ip.bv_len );
1080 buf[ ip.bv_len ] = '\0';
1082 addr = inet_addr( buf );
1084 /* unable to convert? */
1085 if ( addr == (unsigned long)(-1) )
1088 if ( (addr & b->a_peername_mask) != b->a_peername_addr )
1091 #ifdef LDAP_PF_LOCAL
1092 /* extract path and try exact match */
1093 } else if ( b->a_peername_style == ACL_STYLE_PATH ) {
1096 if ( strncmp( op->o_conn->c_peer_name.bv_val,
1097 aci_bv_path_eq.bv_val, aci_bv_path_eq.bv_len ) != 0 )
1100 path.bv_val = op->o_conn->c_peer_name.bv_val + aci_bv_path_eq.bv_len;
1101 path.bv_len = op->o_conn->c_peer_name.bv_len - aci_bv_path_eq.bv_len;
1103 if ( ber_bvcmp( &b->a_peername_pat, &path ) != 0 )
1106 #endif /* LDAP_PF_LOCAL */
1108 /* exact match (very unlikely...) */
1109 } else if ( ber_bvcmp( &op->o_conn->c_peer_name, &b->a_peername_pat ) != 0 ) {
1116 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
1117 if ( BER_BVISNULL( &op->o_conn->c_sock_name ) ) {
1120 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
1121 b->a_sockname_pat.bv_val, 0, 0 );
1122 if ( !ber_bvccmp( &b->a_sockname_pat, '*' ) ) {
1123 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
1124 if (!regex_matches( &b->a_sockname_pat, op->o_conn->c_sock_name.bv_val,
1125 e->e_ndn, nmatch, matches ) )
1130 } else if ( b->a_sockname_style == ACL_STYLE_EXPAND ) {
1132 char buf[ACL_BUF_SIZE];
1134 bv.bv_len = sizeof( buf ) - 1;
1136 if ( string_expand( &bv, &b->a_sockname_pat,
1137 e->e_ndn, nmatch, matches ) )
1142 if ( ber_bvstrcasecmp( &bv, &op->o_conn->c_sock_name ) != 0 ) {
1147 if ( ber_bvstrcasecmp( &b->a_sockname_pat, &op->o_conn->c_sock_name ) != 0 ) {
1154 if ( b->a_dn_at != NULL ) {
1159 const char *attr = b->a_dn_at->ad_cname.bv_val;
1161 assert( attr != NULL );
1163 if ( op->o_ndn.bv_len == 0 ) {
1167 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
1171 /* see if asker is listed in dnattr */
1172 for( at = attrs_find( e->e_attrs, b->a_dn_at );
1174 at = attrs_find( at->a_next, b->a_dn_at ) )
1176 if( value_find_ex( b->a_dn_at,
1177 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
1178 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
1180 &bv, op->o_tmpmemctx ) == 0 )
1189 /* have a dnattr match. if this is a self clause then
1190 * the target must also match the op dn.
1192 if ( b->a_dn_self ) {
1193 /* check if the target is an attribute. */
1194 if ( val == NULL ) continue;
1196 /* target is attribute, check if the attribute value
1199 rc = value_match( &match, b->a_dn_at,
1200 b->a_dn_at->ad_type->sat_equality, 0,
1202 /* on match error or no match, fail the ACL clause */
1203 if (rc != LDAP_SUCCESS || match != 0 )
1207 /* no dnattr match, check if this is a self clause */
1208 if ( ! b->a_dn_self )
1211 ACL_RECORD_VALUE_STATE;
1213 /* this is a self clause, check if the target is an
1219 /* target is attribute, check if the attribute value
1222 rc = value_match( &match, b->a_dn_at,
1223 b->a_dn_at->ad_type->sat_equality, 0,
1226 /* on match error or no match, fail the ACL clause */
1227 if (rc != LDAP_SUCCESS || match != 0 )
1232 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1234 struct berval ndn = BER_BVNULL;
1237 if ( op->o_ndn.bv_len == 0 ) {
1241 /* b->a_group is an unexpanded entry name, expanded it should be an
1242 * entry with objectclass group* and we test to see if odn is one of
1243 * the values in the attribute group
1245 /* see if asker is listed in dnattr */
1246 if ( b->a_group_style == ACL_STYLE_EXPAND ) {
1247 char buf[ACL_BUF_SIZE];
1249 regmatch_t tmp_matches[2],
1250 *tmp_matchesp = tmp_matches;
1252 bv.bv_len = sizeof(buf) - 1;
1257 switch ( a->acl_dn_style ) {
1258 case ACL_STYLE_REGEX:
1259 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1260 tmp_matchesp = matches;
1261 tmp_nmatch = nmatch;
1265 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1266 case ACL_STYLE_BASE:
1267 tmp_matches[0].rm_so = 0;
1268 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1273 case ACL_STYLE_SUBTREE:
1274 case ACL_STYLE_CHILDREN:
1275 tmp_matches[0].rm_so = 0;
1276 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1277 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1278 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1292 if ( string_expand( &bv, &b->a_group_pat,
1294 tmp_nmatch, tmp_matchesp ) )
1299 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn,
1300 op->o_tmpmemctx ) != LDAP_SUCCESS )
1302 /* did not expand to a valid dn */
1309 bv = b->a_group_pat;
1312 rc = backend_group( op, e, &bv, &op->o_ndn,
1313 b->a_group_oc, b->a_group_at );
1316 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
1324 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1326 char buf[ACL_BUF_SIZE];
1328 if ( b->a_set_style == ACL_STYLE_EXPAND ) {
1330 regmatch_t tmp_matches[2],
1331 *tmp_matchesp = tmp_matches;
1334 bv.bv_len = sizeof( buf ) - 1;
1339 switch ( a->acl_dn_style ) {
1340 case ACL_STYLE_REGEX:
1341 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
1342 tmp_matchesp = matches;
1343 tmp_nmatch = nmatch;
1347 /* FALLTHRU: applies also to ACL_STYLE_REGEX when pattern is "*" */
1348 case ACL_STYLE_BASE:
1349 tmp_matches[0].rm_so = 0;
1350 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1355 case ACL_STYLE_SUBTREE:
1356 case ACL_STYLE_CHILDREN:
1357 tmp_matches[0].rm_so = 0;
1358 tmp_matches[0].rm_eo = e->e_nname.bv_len;
1359 tmp_matches[1].rm_so = e->e_nname.bv_len - a->acl_dn_pat.bv_len;
1360 tmp_matches[1].rm_eo = e->e_nname.bv_len;
1374 if ( string_expand( &bv, &b->a_set_pat,
1376 tmp_nmatch, tmp_matchesp ) )
1385 if ( aci_match_set( &bv, op, e, 0 ) == 0 ) {
1390 if ( b->a_authz.sai_ssf ) {
1391 Debug( LDAP_DEBUG_ACL, "<= check a_authz.sai_ssf: ACL %u > OP %u\n",
1392 b->a_authz.sai_ssf, op->o_ssf, 0 );
1393 if ( b->a_authz.sai_ssf > op->o_ssf ) {
1398 if ( b->a_authz.sai_transport_ssf ) {
1399 Debug( LDAP_DEBUG_ACL,
1400 "<= check a_authz.sai_transport_ssf: ACL %u > OP %u\n",
1401 b->a_authz.sai_transport_ssf, op->o_transport_ssf, 0 );
1402 if ( b->a_authz.sai_transport_ssf > op->o_transport_ssf ) {
1407 if ( b->a_authz.sai_tls_ssf ) {
1408 Debug( LDAP_DEBUG_ACL,
1409 "<= check a_authz.sai_tls_ssf: ACL %u > OP %u\n",
1410 b->a_authz.sai_tls_ssf, op->o_tls_ssf, 0 );
1411 if ( b->a_authz.sai_tls_ssf > op->o_tls_ssf ) {
1416 if ( b->a_authz.sai_sasl_ssf ) {
1417 Debug( LDAP_DEBUG_ACL,
1418 "<= check a_authz.sai_sasl_ssf: ACL %u > OP %u\n",
1419 b->a_authz.sai_sasl_ssf, op->o_sasl_ssf, 0 );
1420 if ( b->a_authz.sai_sasl_ssf > op->o_sasl_ssf ) {
1426 if ( b->a_dynacl ) {
1428 slap_access_t tgrant, tdeny;
1430 /* this case works different from the others above.
1431 * since aci's themselves give permissions, we need
1432 * to first check b->a_access_mask, the ACL's access level.
1434 if ( BER_BVISEMPTY( &e->e_nname ) ) {
1435 /* no ACIs in the root DSE */
1439 /* first check if the right being requested
1440 * is allowed by the ACL clause.
1442 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1446 /* start out with nothing granted, nothing denied */
1450 for ( da = b->a_dynacl; da; da = da->da_next ) {
1451 slap_access_t grant, deny;
1453 (void)( *da->da_mask )( da->da_private, op, e, desc, val, nmatch, matches, &grant, &deny );
1459 /* remove anything that the ACL clause does not allow */
1460 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1461 tdeny &= ACL_PRIV_MASK;
1463 /* see if we have anything to contribute */
1464 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1468 /* this could be improved by changing acl_mask so that it can deal with
1469 * by clauses that return grant/deny pairs. Right now, it does either
1470 * additive or subtractive rights, but not both at the same time. So,
1471 * we need to combine the grant/deny pair into a single rights mask in
1472 * a smart way: if either grant or deny is "empty", then we use the
1473 * opposite as is, otherwise we remove any denied rights from the grant
1474 * rights mask and construct an additive mask.
1476 if (ACL_IS_INVALID(tdeny)) {
1477 modmask = tgrant | ACL_PRIV_ADDITIVE;
1479 } else if (ACL_IS_INVALID(tgrant)) {
1480 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1483 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1487 #else /* !SLAP_DYNACL */
1489 #ifdef SLAPD_ACI_ENABLED
1490 if ( b->a_aci_at != NULL ) {
1492 slap_access_t grant, deny, tgrant, tdeny;
1493 struct berval parent_ndn,
1494 old_parent_ndn = BER_BVNULL;
1495 BerVarray bvals = NULL;
1498 /* this case works different from the others above.
1499 * since aci's themselves give permissions, we need
1500 * to first check b->a_access_mask, the ACL's access level.
1503 if ( BER_BVISEMPTY( &e->e_nname ) ) {
1504 /* no ACIs in the root DSE */
1508 /* first check if the right being requested
1509 * is allowed by the ACL clause.
1511 if ( ! ACL_GRANT( b->a_access_mask, *mask ) ) {
1514 /* start out with nothing granted, nothing denied */
1518 /* get the aci attribute */
1519 at = attr_find( e->e_attrs, b->a_aci_at );
1522 /* FIXME: this breaks acl caching;
1523 * see also ACL_RECORD_VALUE_STATE below */
1524 ACL_RECORD_VALUE_STATE;
1526 /* the aci is an multi-valued attribute. The
1527 * rights are determined by OR'ing the individual
1528 * rights given by the acis.
1530 for ( i = 0; !BER_BVISNULL( &at->a_nvals[i] ); i++ ) {
1535 &grant, &deny, SLAP_ACI_SCOPE_ENTRY ) != 0)
1541 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
1542 accessmask2str(tgrant,accessmaskbuf),
1543 accessmask2str(tdeny, accessmaskbuf1), 0);
1546 /* If the entry level aci didn't contain anything valid for the
1547 * current operation, climb up the tree and evaluate the
1548 * acis with scope set to subtree
1550 if ( (tgrant == ACL_PRIV_NONE) && (tdeny == ACL_PRIV_NONE) ) {
1551 dnParent(&(e->e_nname), &parent_ndn);
1552 while ( parent_ndn.bv_val != old_parent_ndn.bv_val ) {
1553 old_parent_ndn = parent_ndn;
1554 Debug(LDAP_DEBUG_ACL, "checking ACI of %s\n", parent_ndn.bv_val, 0, 0);
1555 ret = backend_attribute(op, NULL, &parent_ndn, b->a_aci_at, &bvals, ACL_AUTH);
1563 for( i = 0; bvals[i].bv_val != NULL; i++){
1565 /* FIXME: this breaks acl caching;
1566 * see also ACL_RECORD_VALUE_STATE above */
1567 ACL_RECORD_VALUE_STATE;
1569 if (aci_mask(op, e, desc, val, &bvals[i],
1571 &grant, &deny, SLAP_ACI_SCOPE_CHILDREN ) != 0 )
1575 /* evaluation stops as soon as either a "deny" or a
1576 * "grant" directive matches.
1578 if( (tgrant != ACL_PRIV_NONE) || (tdeny != ACL_PRIV_NONE) ){
1582 Debug(LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
1583 accessmask2str(tgrant,accessmaskbuf),
1584 accessmask2str(tdeny, accessmaskbuf1), 0);
1588 case LDAP_NO_SUCH_ATTRIBUTE:
1589 /* just go on if the aci-Attribute is not present in
1592 Debug(LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0);
1596 case LDAP_NO_SUCH_OBJECT:
1597 /* We have reached the base object */
1598 Debug(LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0);
1609 dnParent(&old_parent_ndn, &parent_ndn);
1614 /* remove anything that the ACL clause does not allow */
1615 tgrant &= b->a_access_mask & ACL_PRIV_MASK;
1616 tdeny &= ACL_PRIV_MASK;
1618 /* see if we have anything to contribute */
1619 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
1623 /* this could be improved by changing acl_mask so that it can deal with
1624 * by clauses that return grant/deny pairs. Right now, it does either
1625 * additive or subtractive rights, but not both at the same time. So,
1626 * we need to combine the grant/deny pair into a single rights mask in
1627 * a smart way: if either grant or deny is "empty", then we use the
1628 * opposite as is, otherwise we remove any denied rights from the grant
1629 * rights mask and construct an additive mask.
1631 if (ACL_IS_INVALID(tdeny)) {
1632 modmask = tgrant | ACL_PRIV_ADDITIVE;
1634 } else if (ACL_IS_INVALID(tgrant)) {
1635 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
1638 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
1642 #endif /* SLAPD_ACI_ENABLED */
1643 #endif /* !SLAP_DYNACL */
1645 modmask = b->a_access_mask;
1648 Debug( LDAP_DEBUG_ACL,
1649 "<= acl_mask: [%d] applying %s (%s)\n",
1650 i, accessmask2str( modmask, accessmaskbuf ),
1651 b->a_type == ACL_CONTINUE
1653 : b->a_type == ACL_BREAK
1659 if( ACL_IS_ADDITIVE(modmask) ) {
1661 ACL_PRIV_SET( *mask, modmask );
1664 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1666 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
1667 /* substract privs */
1668 ACL_PRIV_CLR( *mask, modmask );
1671 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
1678 Debug( LDAP_DEBUG_ACL,
1679 "<= acl_mask: [%d] mask: %s\n",
1680 i, accessmask2str(*mask, accessmaskbuf), 0 );
1682 if( b->a_type == ACL_CONTINUE ) {
1685 } else if ( b->a_type == ACL_BREAK ) {
1693 /* implicit "by * none" clause */
1696 Debug( LDAP_DEBUG_ACL,
1697 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
1698 accessmask2str(*mask, accessmaskbuf), 0, 0 );
1703 * acl_check_modlist - check access control on the given entry to see if
1704 * it allows the given modifications by the user associated with op.
1705 * returns 1 if mods allowed ok
1706 * 0 mods not allowed
1713 Modifications *mlist
1717 AccessControlState state = ACL_STATE_INIT;
1720 int ret = 1; /* default is access allowed */
1728 assert( be != NULL );
1730 /* short circuit root database access */
1731 if ( be_isroot( op ) ) {
1732 Debug( LDAP_DEBUG_ACL,
1733 "<= acl_access_allowed: granted to database root\n",
1738 /* use backend default access if no backend acls */
1739 if( op->o_bd != NULL && op->o_bd->be_acl == NULL ) {
1740 Debug( LDAP_DEBUG_ACL,
1741 "=> access_allowed: backend default %s access %s to \"%s\"\n",
1742 access2str( ACL_WRITE ),
1743 op->o_bd->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn.bv_val );
1744 ret = (op->o_bd->be_dfltaccess >= ACL_WRITE);
1748 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
1750 * no-user-modification operational attributes are ignored
1751 * by ACL_WRITE checking as any found here are not provided
1754 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
1755 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
1756 " modify access granted\n",
1757 mlist->sml_desc->ad_cname.bv_val, 0, 0 );
1761 switch ( mlist->sml_op ) {
1762 case LDAP_MOD_REPLACE:
1764 * We must check both permission to delete the whole
1765 * attribute and permission to add the specific attributes.
1766 * This prevents abuse from selfwriters.
1768 if ( ! access_allowed( op, e,
1769 mlist->sml_desc, NULL, ACL_WRITE, &state ) )
1775 if ( mlist->sml_values == NULL ) break;
1777 /* fall thru to check value to add */
1780 assert( mlist->sml_values != NULL );
1782 for ( bv = mlist->sml_nvalues
1783 ? mlist->sml_nvalues : mlist->sml_values;
1784 bv->bv_val != NULL; bv++ )
1786 if ( ! access_allowed( op, e,
1787 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1795 case LDAP_MOD_DELETE:
1796 if ( mlist->sml_values == NULL ) {
1797 if ( ! access_allowed( op, e,
1798 mlist->sml_desc, NULL, ACL_WRITE, NULL ) )
1805 for ( bv = mlist->sml_nvalues
1806 ? mlist->sml_nvalues : mlist->sml_values;
1807 bv->bv_val != NULL; bv++ )
1809 if ( ! access_allowed( op, e,
1810 mlist->sml_desc, bv, ACL_WRITE, &state ) )
1818 case SLAP_MOD_SOFTADD:
1819 /* allow adding attribute via modrdn thru */
1831 if (be_null) op->o_bd = NULL;
1837 struct berval *list,
1850 while ( len >= 0 && --ix >= 0 ) {
1851 while ( --len >= 0 && *p++ != sep )
1854 while ( len >= 0 && *p == ' ' ) {
1867 while ( --len >= 0 && *p != sep ) {
1871 while ( bv->bv_len > 0 && *--p == ' ' ) {
1878 typedef struct aci_set_gather_t {
1884 aci_set_cb_gather( Operation *op, SlapReply *rs )
1886 aci_set_gather_t *p = (aci_set_gather_t *)op->o_callback->sc_private;
1888 if ( rs->sr_type == REP_SEARCH ) {
1889 BerValue bvals[ 2 ];
1890 BerVarray bvalsp = NULL;
1893 for ( j = 0; !BER_BVISNULL( &rs->sr_attrs[ j ].an_name ); j++ ) {
1894 AttributeDescription *desc = rs->sr_attrs[ j ].an_desc;
1896 if ( desc == slap_schema.si_ad_entryDN ) {
1898 bvals[ 0 ] = rs->sr_entry->e_nname;
1899 BER_BVZERO( &bvals[ 1 ] );
1904 a = attr_find( rs->sr_entry->e_attrs, desc );
1908 for ( i = 0; !BER_BVISNULL( &a->a_nvals[ i ] ); i++ )
1911 bvalsp = a->a_nvals;
1917 p->bvals = slap_set_join( p->cookie, p->bvals,
1918 ( '|' | SLAP_SET_RREF ), bvalsp );
1922 assert( rs->sr_type == REP_RESULT );
1929 aci_set_gather( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
1931 AciSetCookie *cp = (AciSetCookie *)cookie;
1933 LDAPURLDesc *ludp = NULL;
1934 Operation op2 = { 0 };
1935 SlapReply rs = {REP_RESULT};
1936 AttributeName anlist[ 2 ], *anlistp = NULL;
1938 slap_callback cb = { NULL, aci_set_cb_gather, NULL, NULL };
1939 aci_set_gather_t p = { 0 };
1940 const char *text = NULL;
1941 static struct berval defaultFilter_bv = BER_BVC( "(objectClass=*)" );
1943 /* this routine needs to return the bervals instead of
1944 * plain strings, since syntax is not known. It should
1945 * also return the syntax or some "comparison cookie".
1947 if ( strncasecmp( name->bv_val, "ldap:///", STRLENOF( "ldap:///" ) ) != 0 ) {
1948 return aci_set_gather2( cookie, name, desc );
1951 rc = ldap_url_parse( name->bv_val, &ludp );
1952 if ( rc != LDAP_URL_SUCCESS ) {
1953 rc = LDAP_PROTOCOL_ERROR;
1957 if ( ( ludp->lud_host && ludp->lud_host[0] ) || ludp->lud_exts )
1959 /* host part must be empty */
1960 /* extensions parts must be empty */
1961 rc = LDAP_PROTOCOL_ERROR;
1965 /* Grab the searchbase and see if an appropriate database can be found */
1966 ber_str2bv( ludp->lud_dn, 0, 0, &op2.o_req_dn );
1967 rc = dnNormalize( 0, NULL, NULL, &op2.o_req_dn,
1968 &op2.o_req_ndn, cp->op->o_tmpmemctx );
1969 BER_BVZERO( &op2.o_req_dn );
1970 if ( rc != LDAP_SUCCESS ) {
1974 op2.o_bd = select_backend( &op2.o_req_ndn, 0, 1 );
1975 if ( ( op2.o_bd == NULL ) || ( op2.o_bd->be_search == NULL ) ) {
1976 rc = LDAP_NO_SUCH_OBJECT;
1980 /* Grab the filter */
1981 if ( ludp->lud_filter ) {
1982 ber_str2bv_x( ludp->lud_filter, 0, 0, &op2.ors_filterstr,
1983 cp->op->o_tmpmemctx );
1986 op2.ors_filterstr = defaultFilter_bv;
1989 op2.ors_filter = str2filter_x( cp->op, op2.ors_filterstr.bv_val );
1990 if ( op2.ors_filter == NULL ) {
1991 rc = LDAP_PROTOCOL_ERROR;
1995 /* Grab the scope */
1996 op2.ors_scope = ludp->lud_scope;
1998 /* Grap the attributes */
1999 if ( ludp->lud_attrs ) {
2000 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ )
2003 anlistp = slap_sl_malloc( sizeof( AttributeName ) * ( nattrs + 2 ),
2004 cp->op->o_tmpmemctx );
2006 for ( ; ludp->lud_attrs[ nattrs ]; nattrs++ ) {
2007 ber_str2bv( ludp->lud_attrs[ nattrs ], 0, 0, &anlistp[ nattrs ].an_name );
2008 anlistp[ nattrs ].an_desc = NULL;
2009 rc = slap_bv2ad( &anlistp[ nattrs ].an_name,
2010 &anlistp[ nattrs ].an_desc, &text );
2011 if ( rc != LDAP_SUCCESS ) {
2020 anlistp[ nattrs ].an_name = desc->ad_cname;
2021 anlistp[ nattrs ].an_desc = desc;
2023 BER_BVZERO( &anlistp[ nattrs + 1 ].an_name );
2027 op2.o_tag = LDAP_REQ_SEARCH;
2028 op2.o_protocol = LDAP_VERSION3;
2029 op2.o_ndn = op2.o_bd->be_rootndn;
2030 op2.o_callback = &cb;
2031 op2.o_time = slap_get_time();
2032 op2.o_do_not_cache = 1;
2033 op2.o_is_auth_check = 0;
2034 op2.o_threadctx = cp->op->o_threadctx;
2035 op2.o_tmpmemctx = cp->op->o_tmpmemctx;
2036 op2.o_tmpmfuncs = cp->op->o_tmpmfuncs;
2038 op2.o_pb = cp->op->o_pb;
2040 op2.o_conn = cp->op->o_conn;
2041 op2.o_connid = cp->op->o_connid;
2042 ber_dupbv_x( &op2.o_req_dn, &op2.o_req_ndn, cp->op->o_tmpmemctx );
2043 op2.ors_slimit = SLAP_NO_LIMIT;
2044 op2.ors_tlimit = SLAP_NO_LIMIT;
2045 op2.ors_attrs = anlistp;
2046 op2.ors_attrsonly = 0;
2047 op2.o_sync_slog_size = -1;
2051 rc = op2.o_bd->be_search( &op2, &rs );
2057 if ( op2.ors_filter ) {
2058 filter_free_x( cp->op, op2.ors_filter );
2060 if ( !BER_BVISNULL( &op2.o_req_ndn ) ) {
2061 slap_sl_free( op2.o_req_ndn.bv_val, cp->op->o_tmpmemctx );
2063 if ( !BER_BVISNULL( &op2.o_req_dn ) ) {
2064 slap_sl_free( op2.o_req_dn.bv_val, cp->op->o_tmpmemctx );
2067 ldap_free_urldesc( ludp );
2069 if ( anlistp && anlistp != anlist ) {
2070 slap_sl_free( anlistp, cp->op->o_tmpmemctx );
2077 aci_set_gather2( SetCookie *cookie, struct berval *name, AttributeDescription *desc )
2079 AciSetCookie *cp = (AciSetCookie *)cookie;
2080 BerVarray bvals = NULL;
2084 /* this routine needs to return the bervals instead of
2085 * plain strings, since syntax is not known. It should
2086 * also return the syntax or some "comparison cookie".
2088 rc = dnNormalize( 0, NULL, NULL, name, &ndn, cp->op->o_tmpmemctx );
2089 if ( rc == LDAP_SUCCESS ) {
2090 if ( desc == slap_schema.si_ad_entryDN ) {
2091 bvals = (BerVarray)slap_sl_malloc( sizeof( BerValue ) * 2,
2092 cp->op->o_tmpmemctx );
2094 BER_BVZERO( &bvals[ 1 ] );
2098 backend_attribute( cp->op,
2099 cp->e, &ndn, desc, &bvals, ACL_NONE );
2102 if ( !BER_BVISNULL( &ndn ) ) {
2103 slap_sl_free( ndn.bv_val, cp->op->o_tmpmemctx );
2112 struct berval *subj,
2118 struct berval set = BER_BVNULL;
2120 AciSetCookie cookie;
2123 ber_dupbv_x( &set, subj, op->o_tmpmemctx );
2125 struct berval subjdn, ndn = BER_BVNULL;
2126 struct berval setat;
2129 AttributeDescription *desc = NULL;
2131 /* format of string is "entry/setAttrName" */
2132 if ( aci_get_part( subj, 0, '/', &subjdn ) < 0 ) {
2136 if ( aci_get_part( subj, 1, '/', &setat ) < 0 ) {
2137 setat = aci_bv_set_attr;
2141 * NOTE: dnNormalize honors the ber_len field
2142 * as the length of the dn to be normalized
2144 if ( slap_bv2ad( &setat, &desc, &text ) == LDAP_SUCCESS ) {
2145 if ( dnNormalize( 0, NULL, NULL, &subjdn, &ndn, op->o_tmpmemctx ) == LDAP_SUCCESS )
2147 backend_attribute( op, e, &ndn, desc, &bvals, ACL_NONE );
2148 if ( bvals != NULL && !BER_BVISNULL( &bvals[0] ) ) {
2152 BER_BVZERO( &bvals[0] );
2153 for ( i = 1; !BER_BVISNULL( &bvals[i] ); i++ )
2155 bvals[0].bv_val = bvals[i-1].bv_val;
2156 BER_BVZERO( &bvals[i-1] );
2158 ber_bvarray_free_x( bvals, op->o_tmpmemctx );
2159 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2164 if ( !BER_BVISNULL( &set ) ) {
2167 rc = ( slap_set_filter( aci_set_gather, (SetCookie *)&cookie, &set,
2168 &op->o_ndn, &e->e_nname, NULL ) > 0 );
2169 slap_sl_free( set.bv_val, op->o_tmpmemctx );
2175 #ifdef SLAPD_ACI_ENABLED
2177 aci_list_map_rights(
2178 struct berval *list )
2185 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
2188 switch (*bv.bv_val) {
2190 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
2193 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
2194 * the right 's' to mean "set", but in the examples states
2195 * that the right 's' means "search". The latter definition
2198 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
2201 ACL_PRIV_SET(mask, ACL_PRIV_READ);
2204 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
2207 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
2208 * define any equivalent to the AUTH right, so I've just used
2211 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
2223 struct berval *list,
2224 const struct berval *attr,
2225 struct berval *val )
2227 struct berval bv, left, right;
2230 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
2231 if (aci_get_part(&bv, 0, '=', &left) < 0
2232 || aci_get_part(&bv, 1, '=', &right) < 0)
2234 if (ber_bvstrcasecmp(attr, &bv) == 0)
2236 } else if (val == NULL) {
2237 if (ber_bvstrcasecmp(attr, &left) == 0)
2240 if (ber_bvstrcasecmp(attr, &left) == 0) {
2241 /* this is experimental code that implements a
2242 * simple (prefix) match of the attribute value.
2243 * the ACI draft does not provide for aci's that
2244 * apply to specific values, but it would be
2245 * nice to have. If the <attr> part of an aci's
2246 * rights list is of the form <attr>=<value>,
2247 * that means the aci applies only to attrs with
2248 * the given value. Furthermore, if the attr is
2249 * of the form <attr>=<value>*, then <value> is
2250 * treated as a prefix, and the aci applies to
2251 * any value with that prefix.
2253 * Ideally, this would allow r.e. matches.
2255 if (aci_get_part(&right, 0, '*', &left) < 0
2256 || right.bv_len <= left.bv_len)
2258 if (ber_bvstrcasecmp(val, &right) == 0)
2260 } else if (val->bv_len >= left.bv_len) {
2261 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
2270 static slap_access_t
2271 aci_list_get_attr_rights(
2272 struct berval *list,
2273 const struct berval *attr,
2274 struct berval *val )
2280 /* loop through each rights/attr pair, skip first part (action) */
2282 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
2283 if (aci_list_has_attr(&bv, attr, val) == 0)
2285 if (aci_get_part(list, i, ';', &bv) < 0)
2287 mask |= aci_list_map_rights(&bv);
2293 aci_list_get_rights(
2294 struct berval *list,
2295 const struct berval *attr,
2297 slap_access_t *grant,
2298 slap_access_t *deny )
2300 struct berval perm, actn;
2301 slap_access_t *mask;
2304 if (attr == NULL || attr->bv_len == 0
2305 || ber_bvstrcasecmp( attr, &aci_bv_entry ) == 0) {
2306 attr = &aci_bv_br_entry;
2312 /* loop through each permissions clause */
2313 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
2314 if (aci_get_part(&perm, 0, ';', &actn) < 0)
2316 if (ber_bvstrcasecmp( &aci_bv_grant, &actn ) == 0) {
2318 } else if (ber_bvstrcasecmp( &aci_bv_deny, &actn ) == 0) {
2325 *mask |= aci_list_get_attr_rights(&perm, attr, val);
2326 *mask |= aci_list_get_attr_rights(&perm, &aci_bv_br_all, NULL);
2333 struct berval *subj,
2334 struct berval *defgrpoc,
2335 struct berval *defgrpat,
2342 struct berval subjdn;
2343 struct berval grpoc;
2344 struct berval grpat;
2345 ObjectClass *grp_oc = NULL;
2346 AttributeDescription *grp_ad = NULL;
2350 /* format of string is "group/objectClassValue/groupAttrName" */
2351 if (aci_get_part(subj, 0, '/', &subjdn) < 0) {
2355 if (aci_get_part(subj, 1, '/', &grpoc) < 0) {
2359 if (aci_get_part(subj, 2, '/', &grpat) < 0) {
2363 rc = slap_bv2ad( &grpat, &grp_ad, &text );
2364 if( rc != LDAP_SUCCESS ) {
2370 grp_oc = oc_bvfind( &grpoc );
2372 if (grp_oc != NULL && grp_ad != NULL ) {
2373 char buf[ACL_BUF_SIZE];
2374 struct berval bv, ndn;
2375 bv.bv_len = sizeof( buf ) - 1;
2376 bv.bv_val = (char *)&buf;
2377 if ( string_expand(&bv, &subjdn,
2378 e->e_ndn, nmatch, matches) )
2383 if ( dnNormalize( 0, NULL, NULL, &bv, &ndn, op->o_tmpmemctx ) == LDAP_SUCCESS ) {
2384 rc = ( backend_group( op, e, &ndn, &op->o_ndn,
2385 grp_oc, grp_ad ) == 0 );
2386 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2398 AttributeDescription *desc,
2402 regmatch_t *matches,
2403 slap_access_t *grant,
2404 slap_access_t *deny,
2405 slap_aci_scope_t asserted_scope
2408 struct berval bv, scope, perms, type, sdn;
2412 assert( !BER_BVISNULL( &desc->ad_cname ) );
2414 /* parse an aci of the form:
2415 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
2417 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
2418 a full description of the format for this attribute.
2419 Differences: "this" in the draft is "self" here, and
2420 "self" and "public" is in the position of dnType.
2422 For now, this routine only supports scope=entry.
2424 /* check that the aci has all 5 components */
2425 if ( aci_get_part( aci, 4, '#', NULL ) < 0 ) {
2429 /* check that the aci family is supported */
2430 if ( aci_get_part( aci, 0, '#', &bv ) < 0 ) {
2434 /* check that the scope matches */
2435 if ( aci_get_part( aci, 1, '#', &scope ) < 0 ) {
2439 /* note: scope can be either ENTRY or CHILDREN;
2440 * they respectively match "entry" and "children" in bv
2441 * both match "subtree" */
2442 switch ( asserted_scope ) {
2443 case SLAP_ACI_SCOPE_ENTRY:
2444 if ( ber_bvstrcasecmp( &scope, &aci_bv_entry ) != 0
2445 && ber_bvstrcasecmp( &scope, &aci_bv_subtree ) != 0 )
2451 case SLAP_ACI_SCOPE_CHILDREN:
2452 if ( ber_bvstrcasecmp( &scope, &aci_bv_children ) != 0
2453 && ber_bvstrcasecmp( &scope, &aci_bv_subtree ) != 0 )
2463 /* get the list of permissions clauses, bail if empty */
2464 if ( aci_get_part( aci, 2, '#', &perms ) <= 0 ) {
2468 /* check if any permissions allow desired access */
2469 if ( aci_list_get_rights( &perms, &desc->ad_cname, val, grant, deny ) == 0 ) {
2473 /* see if we have a DN match */
2474 if ( aci_get_part( aci, 3, '#', &type ) < 0 ) {
2478 if ( aci_get_part( aci, 4, '#', &sdn ) < 0 ) {
2482 if ( ber_bvstrcasecmp( &aci_bv_access_id, &type ) == 0 ) {
2486 if ( dnNormalize( 0, NULL, NULL, &sdn, &ndn, op->o_tmpmemctx ) == LDAP_SUCCESS )
2488 if ( dn_match( &op->o_ndn, &ndn ) ) {
2491 slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
2495 } else if ( ber_bvstrcasecmp( &aci_bv_public, &type ) == 0 ) {
2498 } else if ( ber_bvstrcasecmp( &aci_bv_self, &type ) == 0 ) {
2499 if ( dn_match( &op->o_ndn, &e->e_nname ) ) {
2503 } else if ( ber_bvstrcasecmp( &aci_bv_dnattr, &type ) == 0 ) {
2505 AttributeDescription *ad = NULL;
2508 rc = slap_bv2ad( &sdn, &ad, &text );
2510 if( rc != LDAP_SUCCESS ) {
2518 for ( at = attrs_find( e->e_attrs, ad );
2520 at = attrs_find( at->a_next, ad ) )
2522 if ( value_find_ex( ad,
2523 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
2524 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
2526 &bv, op->o_tmpmemctx ) == 0 )
2536 } else if ( ber_bvstrcasecmp( &aci_bv_group, &type ) == 0 ) {
2537 if ( aci_group_member( &sdn, &aci_bv_group_class,
2538 &aci_bv_group_attr, op, e, nmatch, matches ) )
2543 } else if ( ber_bvstrcasecmp( &aci_bv_role, &type ) == 0 ) {
2544 if ( aci_group_member( &sdn, &aci_bv_role_class,
2545 &aci_bv_role_attr, op, e, nmatch, matches ) )
2550 } else if ( ber_bvstrcasecmp( &aci_bv_set, &type ) == 0 ) {
2551 if ( aci_match_set( &sdn, op, e, 0 ) ) {
2555 } else if ( ber_bvstrcasecmp( &aci_bv_set_ref, &type ) == 0 ) {
2556 if ( aci_match_set( &sdn, op, e, 1 ) ) {
2564 #endif /* SLAPD_ACI_ENABLED */
2568 dynacl_aci_parse( const char *fname, int lineno, slap_style_t sty, const char *right, void **privp )
2570 AttributeDescription *ad = NULL;
2571 const char *text = NULL;
2573 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
2574 fprintf( stderr, "%s: line %d: "
2575 "inappropriate style \"%s\" in \"aci\" by clause\n",
2576 fname, lineno, sty );
2580 if ( right != NULL && *right != '\0' ) {
2581 if ( slap_str2ad( right, &ad, &text ) != LDAP_SUCCESS ) {
2583 "%s: line %d: aci \"%s\": %s\n",
2584 fname, lineno, right, text );
2589 ad = slap_schema.si_ad_aci;
2592 if ( !is_at_syntax( ad->ad_type, SLAPD_ACI_SYNTAX) ) {
2593 fprintf( stderr, "%s: line %d: "
2594 "aci \"%s\": inappropriate syntax: %s\n",
2595 fname, lineno, right,
2596 ad->ad_type->sat_syntax_oid );
2600 *privp = (void *)ad;
2606 dynacl_aci_print( void *priv )
2608 AttributeDescription *ad = ( AttributeDescription * )priv;
2612 fprintf( stderr, " aci=%s", ad->ad_cname.bv_val );
2623 AttributeDescription *desc,
2626 regmatch_t *matches,
2627 slap_access_t *grantp,
2628 slap_access_t *denyp )
2630 AttributeDescription *ad = ( AttributeDescription * )priv;
2632 slap_access_t tgrant, tdeny, grant, deny;
2634 char accessmaskbuf[ACCESSMASK_MAXLEN];
2635 char accessmaskbuf1[ACCESSMASK_MAXLEN];
2636 #endif /* LDAP_DEBUG */
2638 /* start out with nothing granted, nothing denied */
2642 /* get the aci attribute */
2643 at = attr_find( e->e_attrs, ad );
2647 /* the aci is an multi-valued attribute. The
2648 * rights are determined by OR'ing the individual
2649 * rights given by the acis.
2651 for ( i = 0; !BER_BVISNULL( &at->a_nvals[i] ); i++ ) {
2652 if ( aci_mask( op, e, desc, val, &at->a_nvals[i],
2653 nmatch, matches, &grant, &deny,
2654 SLAP_ACI_SCOPE_ENTRY ) != 0 )
2661 Debug( LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2662 accessmask2str( tgrant, accessmaskbuf ),
2663 accessmask2str( tdeny, accessmaskbuf1 ), 0 );
2666 /* If the entry level aci didn't contain anything valid for the
2667 * current operation, climb up the tree and evaluate the
2668 * acis with scope set to subtree
2670 if ( tgrant == ACL_PRIV_NONE && tdeny == ACL_PRIV_NONE ) {
2671 struct berval parent_ndn;
2672 struct berval old_parent_ndn = BER_BVNULL;
2674 dnParent( &e->e_nname, &parent_ndn );
2675 while ( parent_ndn.bv_val != old_parent_ndn.bv_val ){
2677 BerVarray bvals = NULL;
2680 old_parent_ndn = parent_ndn;
2681 Debug( LDAP_DEBUG_ACL, "checking ACI of \"%s\"\n", parent_ndn.bv_val, 0, 0 );
2682 ret = backend_attribute( op, NULL, &parent_ndn, ad, &bvals, ACL_AUTH );
2691 for ( i = 0; !BER_BVISNULL( &bvals[i] ); i++) {
2692 if ( aci_mask( op, e, desc, val,
2696 SLAP_ACI_SCOPE_CHILDREN ) != 0 )
2700 /* evaluation stops as soon as either a "deny" or a
2701 * "grant" directive matches.
2703 if ( tgrant != ACL_PRIV_NONE || tdeny != ACL_PRIV_NONE ) {
2707 Debug( LDAP_DEBUG_ACL, "<= aci_mask grant %s deny %s\n",
2708 accessmask2str( tgrant, accessmaskbuf ),
2709 accessmask2str( tdeny, accessmaskbuf1 ), 0 );
2713 case LDAP_NO_SUCH_ATTRIBUTE:
2714 /* just go on if the aci-Attribute is not present in
2717 Debug( LDAP_DEBUG_ACL, "no such attribute\n", 0, 0, 0 );
2721 case LDAP_NO_SUCH_OBJECT:
2722 /* We have reached the base object */
2723 Debug( LDAP_DEBUG_ACL, "no such object\n", 0, 0, 0 );
2735 dnParent( &old_parent_ndn, &parent_ndn );
2745 /* need to register this at some point */
2746 static slap_dynacl_t dynacl_aci = {
2759 return slap_dynacl_register( &dynacl_aci );
2763 * dynamic ACL infrastructure
2765 static slap_dynacl_t *da_list = NULL;
2768 slap_dynacl_register( slap_dynacl_t *da )
2772 for ( tmp = da_list; tmp; tmp = tmp->da_next ) {
2773 if ( strcasecmp( da->da_name, tmp->da_name ) == 0 ) {
2778 if ( tmp != NULL ) {
2782 if ( da->da_mask == NULL ) {
2786 da->da_private = NULL;
2787 da->da_next = da_list;
2793 static slap_dynacl_t *
2794 slap_dynacl_next( slap_dynacl_t *da )
2803 slap_dynacl_get( const char *name )
2807 for ( da = slap_dynacl_next( NULL ); da; da = slap_dynacl_next( da ) ) {
2808 if ( strcasecmp( da->da_name, name ) == 0 ) {
2815 #endif /* SLAP_DYNACL */
2825 #ifdef SLAPD_ACI_ENABLED
2830 #endif /* SLAPD_ACI_ENABLED */
2831 #endif /* SLAP_DYNACL */
2843 regmatch_t *matches)
2851 bv->bv_val[0] = '\0';
2852 bv->bv_len--; /* leave space for lone $ */
2855 for ( dp = bv->bv_val, sp = pat->bv_val; size < bv->bv_len &&
2856 sp < pat->bv_val + pat->bv_len ; sp++ )
2858 /* did we previously see a $ */
2860 if ( flag == 1 && *sp == '$' ) {
2865 } else if ( flag == 1 && *sp == '{' /*'}'*/) {
2868 } else if ( *sp >= '0' && *sp <= '9' ) {
2876 for ( sp++; *sp != '\0' && *sp != /*'{'*/ '}'; sp++ ) {
2877 if ( *sp >= '0' && *sp <= '9' ) {
2878 n = 10*n + ( *sp - '0' );
2882 if ( *sp != /*'{'*/ '}' ) {
2888 if ( n >= nmatch ) {
2894 i = matches[n].rm_so;
2895 l = matches[n].rm_eo;
2896 for ( ; size < bv->bv_len && i < l; size++, i++ ) {
2914 /* must have ended with a single $ */
2922 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %.*s\n", (int)pat->bv_len, pat->bv_val, 0 );
2923 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", bv->bv_val, 0, 0 );
2930 struct berval *pat, /* pattern to expand and match against */
2931 char *str, /* string to match against pattern */
2932 char *buf, /* buffer with $N expansion variables */
2933 int nmatch, /* size of the matches array */
2934 regmatch_t *matches /* offsets in buffer for $N expansion variables */
2938 char newbuf[ACL_BUF_SIZE];
2942 bv.bv_len = sizeof( newbuf ) - 1;
2949 string_expand( &bv, pat, buf, nmatch, matches );
2950 rc = regcomp( &re, newbuf, REG_EXTENDED|REG_ICASE );
2952 char error[ACL_BUF_SIZE];
2953 regerror( rc, &re, error, sizeof( error ) );
2955 Debug( LDAP_DEBUG_TRACE,
2956 "compile( \"%s\", \"%s\") failed %s\n",
2957 pat->bv_val, str, error );
2961 rc = regexec( &re, str, 0, NULL, 0 );
2964 Debug( LDAP_DEBUG_TRACE,
2965 "=> regex_matches: string: %s\n", str, 0, 0 );
2966 Debug( LDAP_DEBUG_TRACE,
2967 "=> regex_matches: rc: %d %s\n",
2968 rc, !rc ? "matches" : "no matches", 0 );