1 /* acl.c - routines to parse and check acl's */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/socket.h>
14 #include <ac/string.h>
18 static AccessControl * acl_get(
19 AccessControl *ac, int *count,
20 Backend *be, Operation *op,
22 AttributeDescription *desc,
23 int nmatches, regmatch_t *matches );
25 static slap_control_t acl_mask(
26 AccessControl *ac, slap_access_mask_t *mask,
27 Backend *be, Connection *conn, Operation *op,
29 AttributeDescription *desc,
31 regmatch_t *matches );
33 #ifdef SLAPD_ACI_ENABLED
39 AttributeDescription *desc,
44 slap_access_t *deny );
47 static int regex_matches(
48 char *pat, char *str, char *buf, regmatch_t *matches);
49 static void string_expand(
50 char *newbuf, int bufsiz, char *pattern,
51 char *match, regmatch_t *matches);
55 * access_allowed - check whether op->o_ndn is allowed the requested access
56 * to entry e, attribute attr, value val. if val is null, access to
57 * the whole attribute is assumed (all values).
59 * This routine loops through all access controls and calls
60 * acl_mask() on each applicable access control.
61 * The loop exits when a definitive answer is reached or
62 * or no more controls remain.
75 AttributeDescription *desc,
77 slap_access_t access )
82 char accessmaskbuf[ACCESSMASK_MAXLEN];
84 slap_access_mask_t mask;
85 slap_control_t control;
87 const char *attr = desc ? desc->ad_cname->bv_val : NULL;
89 regmatch_t matches[MAXREMATCHES];
91 Debug( LDAP_DEBUG_ACL,
92 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
98 assert( attr != NULL );
99 assert( access > ACL_NONE );
101 /* grant database root access */
102 if ( be != NULL && be_isroot( be, op->o_ndn ) ) {
103 Debug( LDAP_DEBUG_ACL,
104 "<= root access granted\n",
110 * no-user-modification operational attributes are ignored
111 * by ACL_WRITE checking as any found here are not provided
114 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type ) )
116 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
117 " %s access granted\n",
122 /* use backend default access if no backend acls */
123 if( be != NULL && be->be_acl == NULL ) {
124 Debug( LDAP_DEBUG_ACL,
125 "=> access_allowed: backend default %s access %s to \"%s\"\n",
126 access2str( access ),
127 be->be_dfltaccess >= access ? "granted" : "denied", op->o_dn );
129 return be->be_dfltaccess >= access;
132 /* be is always non-NULL */
133 /* use global default access if no global acls */
134 } else if ( be == NULL && global_acl == NULL ) {
135 Debug( LDAP_DEBUG_ACL,
136 "=> access_allowed: global default %s access %s to \"%s\"\n",
137 access2str( access ),
138 global_default_access >= access ? "granted" : "denied", op->o_dn );
140 return global_default_access >= access;
145 memset(matches, '\0', sizeof(matches));
151 while( a = acl_get( a, &count, be, op, e, desc, MAXREMATCHES, matches ) )
155 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
156 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
157 (int)matches[i].rm_so, (int)matches[i].rm_eo );
159 if( matches[i].rm_so <= matches[0].rm_eo ) {
161 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
162 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
165 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
168 control = acl_mask( a, &mask, be, conn, op,
169 e, desc, val, matches );
171 if ( control != ACL_BREAK ) {
175 memset(matches, '\0', sizeof(matches));
178 if ( ACL_IS_INVALID( mask ) ) {
179 Debug( LDAP_DEBUG_ACL,
180 "=> access_allowed: \"%s\" (%s) invalid!\n",
184 } else if ( control == ACL_BREAK ) {
185 Debug( LDAP_DEBUG_ACL,
186 "=> access_allowed: no more rules\n", 0, 0, 0);
190 Debug( LDAP_DEBUG_ACL,
191 "=> access_allowed: %s access %s by %s\n",
192 access2str( access ),
193 ACL_GRANT(mask, access) ? "granted" : "denied",
194 accessmask2str( mask, accessmaskbuf ) );
196 return ACL_GRANT(mask, access);
200 * acl_get - return the acl applicable to entry e, attribute
201 * attr. the acl returned is suitable for use in subsequent calls to
202 * acl_access_allowed().
205 static AccessControl *
212 AttributeDescription *desc,
214 regmatch_t *matches )
220 assert( count != NULL );
222 attr = desc ? desc->ad_cname->bv_val : NULL;
237 dnlen = strlen(e->e_ndn);
239 for ( ; a != NULL; a = a->acl_next ) {
242 if (a->acl_dn_pat != NULL) {
243 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
244 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
245 *count, a->acl_dn_pat, (int) a->acl_dn_re.re_nsub );
247 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0))
251 Debug( LDAP_DEBUG_ACL, "=> dn: [%d] %s\n",
252 *count, a->acl_dn_pat, 0 );
254 patlen = strlen( a->acl_dn_pat );
255 if ( dnlen < patlen )
258 if ( a->acl_dn_style == ACL_STYLE_BASE ) {
259 /* base dn -- entire object DN must match */
260 if ( dnlen != patlen )
263 } else if ( a->acl_dn_style == ACL_STYLE_ONE ) {
267 if ( dnlen <= patlen )
270 if ( e->e_ndn[dnlen - patlen - 1] != ',' )
273 rdn = dn_rdn( NULL, e->e_ndn );
275 rdnlen = strlen( rdn );
278 if ( rdnlen != dnlen - patlen - 1 )
281 } else if ( a->acl_dn_style == ACL_STYLE_SUBTREE ) {
282 if ( dnlen > patlen && e->e_ndn[dnlen - patlen - 1] != ',' )
285 } else if ( a->acl_dn_style == ACL_STYLE_CHILDREN ) {
286 if ( dnlen <= patlen )
288 if ( e->e_ndn[dnlen - patlen - 1] != ',' )
292 if ( strcmp( a->acl_dn_pat, e->e_ndn + dnlen - patlen ) != 0 )
296 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
300 if ( a->acl_filter != NULL ) {
301 ber_int_t rc = test_filter( NULL, NULL, NULL, e, a->acl_filter );
302 if ( rc != LDAP_COMPARE_TRUE ) {
307 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] check attr %s\n",
310 if ( attr == NULL || a->acl_attrs == NULL ||
311 ad_inlist( desc, a->acl_attrs ) )
313 Debug( LDAP_DEBUG_ACL,
314 "<= acl_get: [%d] acl %s attr: %s\n",
315 *count, e->e_dn, attr );
318 matches[0].rm_so = matches[0].rm_eo = -1;
321 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
327 * acl_mask - modifies mask based upon the given acl and the
328 * requested access to entry e, attribute attr, value val. if val
329 * is null, access to the whole attribute is assumed (all values).
331 * returns 0 access NOT allowed
335 static slap_control_t
338 slap_access_mask_t *mask,
343 AttributeDescription *desc,
348 int i, odnlen, patlen;
351 char accessmaskbuf[ACCESSMASK_MAXLEN];
353 const char *attr = desc ? desc->ad_cname->bv_val : NULL;
356 assert( mask != NULL );
358 Debug( LDAP_DEBUG_ACL,
359 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
362 Debug( LDAP_DEBUG_ACL,
363 "=> acl_mask: to value \"%s\" by \"%s\", (%s) \n",
364 val ? val->bv_val : "*",
365 op->o_ndn ? op->o_ndn : "",
366 accessmask2str( *mask, accessmaskbuf ) );
368 for ( i = 1, b = a->acl_access; b != NULL; b = b->a_next, i++ ) {
369 slap_access_mask_t oldmask, modmask;
371 ACL_INVALIDATE( modmask );
373 /* AND <who> clauses */
374 if ( b->a_dn_pat != NULL ) {
375 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
378 * if access applies to the entry itself, and the
379 * user is bound as somebody in the same namespace as
380 * the entry, OR the given dn matches the dn pattern
382 if ( strcmp( b->a_dn_pat, "anonymous" ) == 0 ) {
383 if (op->o_ndn != NULL && op->o_ndn[0] != '\0' ) {
387 } else if ( strcmp( b->a_dn_pat, "users" ) == 0 ) {
388 if (op->o_ndn == NULL || op->o_ndn[0] == '\0' ) {
392 } else if ( strcmp( b->a_dn_pat, "self" ) == 0 ) {
393 if( op->o_ndn == NULL || op->o_ndn[0] == '\0' ) {
397 if ( e->e_dn == NULL || strcmp( e->e_ndn, op->o_ndn ) != 0 ) {
401 } else if ( b->a_dn_style == ACL_STYLE_REGEX ) {
402 if ( strcmp( b->a_dn_pat, "*" ) != 0 ) {
403 int ret = regex_matches( b->a_dn_pat,
404 op->o_ndn, e->e_ndn, matches );
412 if ( e->e_dn == NULL )
415 patlen = strlen( b->a_dn_pat );
416 odnlen = strlen( op->o_ndn );
417 if ( odnlen < patlen )
420 if ( b->a_dn_style == ACL_STYLE_BASE ) {
421 /* base dn -- entire object DN must match */
422 if ( odnlen != patlen )
425 } else if ( b->a_dn_style == ACL_STYLE_ONE ) {
429 if ( odnlen <= patlen )
432 if ( op->o_ndn[odnlen - patlen - 1] != ',' )
435 rdn = dn_rdn( NULL, op->o_ndn );
437 rdnlen = strlen( rdn );
440 if ( rdnlen != odnlen - patlen - 1 )
443 } else if ( b->a_dn_style == ACL_STYLE_SUBTREE ) {
444 if ( odnlen > patlen && op->o_ndn[odnlen - patlen - 1] != ',' )
447 } else if ( b->a_dn_style == ACL_STYLE_CHILDREN ) {
448 if ( odnlen <= patlen )
450 if ( op->o_ndn[odnlen - patlen - 1] != ',' )
454 if ( strcmp( b->a_dn_pat, op->o_ndn + odnlen - patlen ) != 0 )
460 if ( b->a_sockurl_pat != NULL ) {
461 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
462 b->a_sockurl_pat, 0, 0 );
464 if ( strcmp( b->a_sockurl_pat, "*" ) != 0) {
465 if ( b->a_sockurl_style == ACL_STYLE_REGEX) {
466 if (!regex_matches( b->a_sockurl_pat, conn->c_listener_url,
467 e->e_ndn, matches ) )
472 if ( strcasecmp( b->a_sockurl_pat, conn->c_listener_url ) == 0 )
478 if ( b->a_domain_pat != NULL ) {
479 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
480 b->a_domain_pat, 0, 0 );
482 if ( strcmp( b->a_domain_pat, "*" ) != 0) {
483 if ( b->a_domain_style == ACL_STYLE_REGEX) {
484 if (!regex_matches( b->a_domain_pat, conn->c_peer_domain,
485 e->e_ndn, matches ) )
490 if ( strcasecmp( b->a_domain_pat, conn->c_peer_domain ) == 0 )
496 if ( b->a_peername_pat != NULL ) {
497 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
498 b->a_peername_pat, 0, 0 );
500 if ( strcmp( b->a_peername_pat, "*" ) != 0) {
501 if ( b->a_peername_style == ACL_STYLE_REGEX) {
502 if (!regex_matches( b->a_peername_pat, conn->c_peer_name,
503 e->e_ndn, matches ) )
508 if ( strcasecmp( b->a_peername_pat, conn->c_peer_name ) == 0 )
514 if ( b->a_sockname_pat != NULL ) {
515 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
516 b->a_sockname_pat, 0, 0 );
518 if ( strcmp( b->a_sockname_pat, "*" ) != 0) {
519 if ( b->a_sockname_style == ACL_STYLE_REGEX) {
520 if (!regex_matches( b->a_sockname_pat, conn->c_sock_name,
521 e->e_ndn, matches ) )
526 if ( strcasecmp( b->a_sockname_pat, conn->c_sock_name ) == 0 )
532 if ( b->a_dn_at != NULL && op->o_ndn != NULL ) {
537 const char *desc = b->a_dn_at->ad_cname->bv_val;
539 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
542 bv.bv_val = op->o_ndn;
543 bv.bv_len = strlen( bv.bv_val );
545 /* see if asker is listed in dnattr */
546 for( at = attrs_find( e->e_attrs, b->a_dn_at );
548 at = attrs_find( e->e_attrs->a_next, b->a_dn_at ) )
550 if( value_find( b->a_dn_at, at->a_vals, &bv ) == 0 ) {
558 if ( b->a_dn_self && (val == NULL
559 || value_match( &match, b->a_dn_at,
560 b->a_dn_at->ad_type->sat_equality, val, &bv, &text ) )
566 } else if ( ! b->a_dn_self || val == NULL
567 || value_match( &match, b->a_dn_at,
568 b->a_dn_at->ad_type->sat_equality, val, &bv, &text )
576 if ( b->a_group_pat != NULL && op->o_ndn != NULL ) {
579 /* b->a_group is an unexpanded entry name, expanded it should be an
580 * entry with objectclass group* and we test to see if odn is one of
581 * the values in the attribute group
583 /* see if asker is listed in dnattr */
584 if ( b->a_group_style != ACL_STYLE_REGEX ) {
585 string_expand(buf, sizeof(buf), b->a_group_pat, e->e_ndn, matches);
586 if ( dn_normalize(buf) == NULL ) {
587 /* did not expand to a valid dn */
591 strncpy( buf, b->a_group_pat, sizeof(buf) - 1 );
592 buf[sizeof(buf) - 1] = 0;
595 if (backend_group(be, e, buf, op->o_ndn,
596 b->a_group_oc, b->a_group_at) != 0)
602 #ifdef SLAPD_ACI_ENABLED
603 if ( b->a_aci_at != NULL ) {
605 slap_access_t grant, deny, tgrant, tdeny;
607 /* this case works different from the others above.
608 * since aci's themselves give permissions, we need
609 * to first check b->a_mask, the ACL's access level.
612 if( op->o_ndn == NULL || op->o_ndn[0] == '\0' ) {
616 if ( e->e_dn == NULL ) {
620 /* first check if the right being requested
621 * is allowed by the ACL clause.
623 if ( ! ACL_GRANT( b->a_mask, *mask ) ) {
627 /* get the aci attribute */
628 at = attr_find( e->e_attrs, b->a_aci_at );
633 /* start out with nothing granted, nothing denied */
637 /* the aci is an multi-valued attribute. The
638 * rights are determined by OR'ing the individual
639 * rights given by the acis.
641 for ( i = 0; at->a_vals[i] != NULL; i++ ) {
642 if (aci_mask( be, conn, op,
643 e, desc, val, at->a_vals[i],
644 matches, &grant, &deny ) != 0)
651 /* remove anything that the ACL clause does not allow */
652 tgrant &= b->a_mask & ACL_PRIV_MASK;
653 tdeny &= ACL_PRIV_MASK;
655 /* see if we have anything to contribute */
656 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
660 /* this could be improved by changing acl_mask so that it can deal with
661 * by clauses that return grant/deny pairs. Right now, it does either
662 * additive or subtractive rights, but not both at the same time. So,
663 * we need to combine the grant/deny pair into a single rights mask in
664 * a smart way: if either grant or deny is "empty", then we use the
665 * opposite as is, otherwise we remove any denied rights from the grant
666 * rights mask and construct an additive mask.
668 if (ACL_IS_INVALID(tdeny)) {
669 modmask = tgrant | ACL_PRIV_ADDITIVE;
671 } else if (ACL_IS_INVALID(tgrant)) {
672 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
675 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
685 Debug( LDAP_DEBUG_ACL,
686 "<= acl_mask: [%d] applying %s (%s)\n",
687 i, accessmask2str( modmask, accessmaskbuf ),
688 b->a_type == ACL_CONTINUE
690 : b->a_type == ACL_BREAK
697 if( ACL_IS_ADDITIVE(modmask) ) {
699 ACL_PRIV_SET( *mask, modmask );
702 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
704 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
705 /* substract privs */
706 ACL_PRIV_CLR( *mask, modmask );
709 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
716 Debug( LDAP_DEBUG_ACL,
717 "<= acl_mask: [%d] mask: %s\n",
718 i, accessmask2str(*mask, accessmaskbuf), 0 );
720 if( b->a_type == ACL_CONTINUE ) {
723 } else if ( b->a_type == ACL_BREAK ) {
731 Debug( LDAP_DEBUG_ACL,
732 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
733 accessmask2str(*mask, accessmaskbuf), 0, 0 );
738 * acl_check_modlist - check access control on the given entry to see if
739 * it allows the given modifications by the user associated with op.
740 * returns 1 if mods allowed ok
755 assert( be != NULL );
757 /* short circuit root database access */
758 if ( be_isroot( be, op->o_ndn ) ) {
759 Debug( LDAP_DEBUG_ACL,
760 "<= acl_access_allowed: granted to database root\n",
765 /* use backend default access if no backend acls */
766 if( be != NULL && be->be_acl == NULL ) {
767 Debug( LDAP_DEBUG_ACL,
768 "=> access_allowed: backend default %s access %s to \"%s\"\n",
769 access2str( ACL_WRITE ),
770 be->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn );
772 return be->be_dfltaccess >= ACL_WRITE;
775 /* be is always non-NULL */
776 /* use global default access if no global acls */
777 } else if ( be == NULL && global_acl == NULL ) {
778 Debug( LDAP_DEBUG_ACL,
779 "=> access_allowed: global default %s access %s to \"%s\"\n",
780 access2str( ACL_WRITE ),
781 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn );
783 return global_default_access >= ACL_WRITE;
787 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
789 * no-user-modification operational attributes are ignored
790 * by ACL_WRITE checking as any found here are not provided
793 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
794 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
795 " modify access granted\n",
796 mlist->sml_desc->ad_cname->bv_val, 0, 0 );
800 switch ( mlist->sml_op ) {
801 case LDAP_MOD_REPLACE:
803 if ( mlist->sml_bvalues == NULL ) {
806 for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) {
807 if ( ! access_allowed( be, conn, op, e,
808 mlist->sml_desc, mlist->sml_bvalues[i], ACL_WRITE ) )
815 case LDAP_MOD_DELETE:
816 if ( mlist->sml_bvalues == NULL ) {
817 if ( ! access_allowed( be, conn, op, e,
818 mlist->sml_desc, NULL, ACL_WRITE ) )
824 for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) {
825 if ( ! access_allowed( be, conn, op, e,
826 mlist->sml_desc, mlist->sml_bvalues[i], ACL_WRITE ) )
838 #ifdef SLAPD_ACI_ENABLED
840 aci_bvstrdup( struct berval *bv )
844 s = (char *)ch_malloc(bv->bv_len + 1);
846 memcpy(s, bv->bv_val, bv->bv_len);
859 res = strncasecmp( s, bv->bv_val, bv->bv_len );
863 if (len > (int)bv->bv_len)
865 if (len < (int)bv->bv_len)
886 while (len >= 0 && --ix >= 0) {
887 while (--len >= 0 && *p++ != sep) ;
889 while (len >= 0 && *p == ' ') {
900 while (--len >= 0 && *p != sep) {
904 while (bv->bv_len > 0 && *--p == ' ')
911 struct berval *list )
918 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
921 switch (*bv.bv_val) {
923 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
926 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
927 * the right 's' to mean "set", but in the examples states
928 * that the right 's' means "search". The latter definition
931 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
934 ACL_PRIV_SET(mask, ACL_PRIV_READ);
937 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
940 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
941 * define any equivalent to the AUTH right, so I've just used
944 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
960 struct berval bv, left, right;
963 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
964 if (aci_get_part(&bv, 0, '=', &left) < 0
965 || aci_get_part(&bv, 1, '=', &right) < 0)
967 if (aci_strbvcmp(attr, &bv) == 0)
969 } else if (val == NULL) {
970 if (aci_strbvcmp(attr, &left) == 0)
973 if (aci_strbvcmp(attr, &left) == 0) {
974 /* this is experimental code that implements a
975 * simple (prefix) match of the attribute value.
976 * the ACI draft does not provide for aci's that
977 * apply to specific values, but it would be
978 * nice to have. If the <attr> part of an aci's
979 * rights list is of the form <attr>=<value>,
980 * that means the aci applies only to attrs with
981 * the given value. Furthermore, if the attr is
982 * of the form <attr>=<value>*, then <value> is
983 * treated as a prefix, and the aci applies to
984 * any value with that prefix.
986 * Ideally, this would allow r.e. matches.
988 if (aci_get_part(&right, 0, '*', &left) < 0
989 || right.bv_len <= left.bv_len)
991 if (aci_strbvcmp(val->bv_val, &right) == 0)
993 } else if (val->bv_len >= left.bv_len) {
994 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
1003 static slap_access_t
1004 aci_list_get_attr_rights(
1005 struct berval *list,
1007 struct berval *val )
1013 /* loop through each rights/attr pair, skip first part (action) */
1015 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
1016 if (aci_list_has_attr(&bv, attr, val) == 0)
1018 if (aci_get_part(list, i, ';', &bv) < 0)
1020 mask |= aci_list_map_rights(&bv);
1026 aci_list_get_rights(
1027 struct berval *list,
1030 slap_access_t *grant,
1031 slap_access_t *deny )
1033 struct berval perm, actn;
1034 slap_access_t *mask;
1037 if (attr == NULL || *attr == 0 || strcasecmp(attr, "entry") == 0) {
1044 /* loop through each permissions clause */
1045 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
1046 if (aci_get_part(&perm, 0, ';', &actn) < 0)
1048 if (aci_strbvcmp( "grant", &actn ) == 0) {
1050 } else if (aci_strbvcmp( "deny", &actn ) == 0) {
1057 *mask |= aci_list_get_attr_rights(&perm, attr, val);
1058 *mask |= aci_list_get_attr_rights(&perm, "[all]", NULL);
1065 struct berval *subj,
1066 const char *defgrpoc,
1067 const char *defgrpat,
1075 char *subjdn, *grpdn = NULL;
1078 ObjectClass *grp_oc = NULL;
1079 AttributeDescription *grp_ad = NULL;
1083 /* format of string is "group/objectClassValue/groupAttrName" */
1084 if (aci_get_part(subj, 0, '/', &bv) < 0) {
1088 subjdn = aci_bvstrdup(&bv);
1089 if (subjdn == NULL) {
1093 if (aci_get_part(subj, 1, '/', &bv) < 0) {
1094 grpoc = ch_strdup( defgrpoc );
1096 grpoc = aci_bvstrdup(&bv);
1099 if (aci_get_part(subj, 2, '/', &bv) < 0) {
1100 grpat = ch_strdup( defgrpat );
1102 grpat = aci_bvstrdup(&bv);
1105 rc = slap_str2ad( grpat, &grp_ad, &text );
1106 if( rc != LDAP_SUCCESS ) {
1112 grpdn = (char *)ch_malloc(1024);
1114 if (grp_oc != NULL && grp_ad != NULL && grpdn != NULL) {
1115 string_expand(grpdn, 1024, subjdn, e->e_ndn, matches);
1116 if ( dn_normalize(grpdn) != NULL ) {
1117 rc = (backend_group(be, e, grpdn, op->o_ndn, grp_oc, grp_ad) == 0);
1122 if( grp_ad != NULL ) ad_free( grp_ad, 1 );
1136 AttributeDescription *desc,
1139 regmatch_t *matches,
1140 slap_access_t *grant,
1144 struct berval bv, perms, sdn;
1147 char *attr = desc->ad_cname->bv_val;
1149 /* parse an aci of the form:
1150 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1152 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1153 a full description of the format for this attribute.
1155 For now, this routine only supports scope=entry.
1158 /* check that the aci has all 5 components */
1159 if (aci_get_part(aci, 4, '#', NULL) < 0)
1162 /* check that the aci family is supported */
1163 if (aci_get_part(aci, 0, '#', &bv) < 0)
1166 /* check that the scope is "entry" */
1167 if (aci_get_part(aci, 1, '#', &bv) < 0
1168 || aci_strbvcmp( "entry", &bv ) != 0)
1173 /* get the list of permissions clauses, bail if empty */
1174 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1177 /* check if any permissions allow desired access */
1178 if (aci_list_get_rights(&perms, attr, val, grant, deny) == 0)
1181 /* see if we have a DN match */
1182 if (aci_get_part(aci, 3, '#', &bv) < 0)
1185 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1188 if (aci_strbvcmp( "access-id", &bv ) == 0) {
1189 subjdn = aci_bvstrdup(&sdn);
1193 if ( dn_normalize(subjdn) != NULL )
1194 if (strcasecmp(op->o_ndn, subjdn) != 0)
1200 if (aci_strbvcmp( "self", &bv ) == 0) {
1201 if (strcasecmp(op->o_ndn, e->e_ndn) == 0)
1204 } else if (aci_strbvcmp( "dnattr", &bv ) == 0) {
1205 char *dnattr = aci_bvstrdup(&sdn);
1207 AttributeDescription *ad = NULL;
1210 rc = slap_str2ad( dnattr, &ad, &text );
1213 if( rc != LDAP_SUCCESS ) {
1219 bv.bv_val = op->o_ndn;
1220 bv.bv_len = strlen( bv.bv_val );
1222 for(at = attrs_find( e->e_attrs, ad );
1224 at = attrs_find( at->a_next, ad ) )
1226 if (value_find( ad, at->a_vals, &bv) == 0 ) {
1236 } else if (aci_strbvcmp( "group", &bv ) == 0) {
1237 if (aci_group_member(&sdn, SLAPD_GROUP_CLASS, SLAPD_GROUP_ATTR, be, e, op, matches))
1240 } else if (aci_strbvcmp( "role", &bv ) == 0) {
1241 if (aci_group_member(&sdn, SLAPD_ROLE_CLASS, SLAPD_ROLE_ATTR, be, e, op, matches))
1248 #endif /* SLAPD_ACI_ENABLED */
1256 regmatch_t *matches)
1265 bufsiz--; /* leave space for lone $ */
1268 for ( dp = newbuf, sp = pat; size < bufsiz && *sp ; sp++) {
1269 /* did we previously see a $ */
1274 } else if (*sp >= '0' && *sp <= '9' ) {
1281 i = matches[n].rm_so;
1282 l = matches[n].rm_eo;
1283 for ( ; size < 512 && i < l; size++, i++ ) {
1301 /* must have ended with a single $ */
1308 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %s\n", pat, 0, 0 );
1309 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", newbuf, 0, 0 );
1314 char *pat, /* pattern to expand and match against */
1315 char *str, /* string to match against pattern */
1316 char *buf, /* buffer with $N expansion variables */
1317 regmatch_t *matches /* offsets in buffer for $N expansion variables */
1324 if(str == NULL) str = "";
1326 string_expand(newbuf, sizeof(newbuf), pat, buf, matches);
1327 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
1329 regerror(rc, &re, error, sizeof(error));
1331 Debug( LDAP_DEBUG_TRACE,
1332 "compile( \"%s\", \"%s\") failed %s\n",
1337 rc = regexec(&re, str, 0, NULL, 0);
1340 Debug( LDAP_DEBUG_TRACE,
1341 "=> regex_matches: string: %s\n", str, 0, 0 );
1342 Debug( LDAP_DEBUG_TRACE,
1343 "=> regex_matches: rc: %d %s\n",
1344 rc, !rc ? "matches" : "no matches", 0 );