1 /* acl.c - routines to parse and check acl's */
4 * Copyright 1998-1999 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 #ifdef SLAPD_SCHEMA_NOT_COMPAT
23 AttributeDescription *desc,
27 int nmatches, regmatch_t *matches );
29 static slap_control_t acl_mask(
30 AccessControl *ac, slap_access_mask_t *mask,
31 Backend *be, Connection *conn, Operation *op,
33 #ifdef SLAPD_SCHEMA_NOT_COMPAT
34 AttributeDescription *desc,
39 regmatch_t *matches );
41 #ifdef SLAPD_ACI_ENABLED
46 #ifdef SLAPD_SCHEMA_NOT_COMPAT
47 AttributeDescription *desc,
51 struct berval *val, struct berval *aci,
52 regmatch_t *matches, slap_access_t *grant, slap_access_t *deny );
54 char *supportedACIMechs[] = {
55 "1.3.6.1.4.1.4203.666.7.1", /* experimental IETF aci family */
56 "1.3.6.1.4.1.4203.666.7.2", /* experimental OpenLDAP aci family */
61 static int regex_matches(
62 char *pat, char *str, char *buf, regmatch_t *matches);
63 static void string_expand(
64 char *newbuf, int bufsiz, char *pattern,
65 char *match, regmatch_t *matches);
69 * access_allowed - check whether op->o_ndn is allowed the requested access
70 * to entry e, attribute attr, value val. if val is null, access to
71 * the whole attribute is assumed (all values).
73 * This routine loops through all access controls and calls
74 * acl_mask() on each applicable access control.
75 * The loop exits when a definitive answer is reached or
76 * or no more controls remain.
89 #ifdef SLAPD_SCHEMA_NOT_COMPAT
90 AttributeDescription *attr,
95 slap_access_t access )
100 char accessmaskbuf[ACCESSMASK_MAXLEN];
102 slap_access_mask_t mask;
103 slap_control_t control;
105 regmatch_t matches[MAXREMATCHES];
107 Debug( LDAP_DEBUG_ACL,
108 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
109 access2str( access ),
112 assert( be != NULL );
114 assert( attr != NULL );
115 assert( access > ACL_NONE );
117 /* grant database root access */
118 if ( be != NULL && be_isroot( be, op->o_ndn ) ) {
119 Debug( LDAP_DEBUG_ACL,
120 "<= root access granted\n",
126 * no-user-modification operational attributes are ignored
127 * by ACL_WRITE checking as any found here are not provided
130 #ifdef SLAPD_SCHEMA_NOT_COMPAT
131 if ( access >= ACL_WRITE && is_at_no_user_mod( attr->ad_type ) )
133 if ( access >= ACL_WRITE && oc_check_op_no_usermod_attr( attr ) )
136 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
137 " %s access granted\n",
142 /* use backend default access if no backend acls */
143 if( be != NULL && be->be_acl == NULL ) {
144 Debug( LDAP_DEBUG_ACL,
145 "=> access_allowed: backend default %s access %s to \"%s\"\n",
146 access2str( access ),
147 be->be_dfltaccess >= access ? "granted" : "denied", op->o_dn );
149 return be->be_dfltaccess >= access;
152 /* be is always non-NULL */
153 /* use global default access if no global acls */
154 } else if ( be == NULL && global_acl == NULL ) {
155 Debug( LDAP_DEBUG_ACL,
156 "=> access_allowed: global default %s access %s to \"%s\"\n",
157 access2str( access ),
158 global_default_access >= access ? "granted" : "denied", op->o_dn );
160 return global_default_access >= access;
165 memset(matches, 0, sizeof(matches));
171 while( a = acl_get( a, &count, be, op, e, attr, MAXREMATCHES, matches ) )
175 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
176 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
177 (int)matches[i].rm_so, (int)matches[i].rm_eo );
179 if( matches[i].rm_so <= matches[0].rm_eo ) {
181 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
182 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
185 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
188 control = acl_mask( a, &mask, be, conn, op,
189 e, attr, val, matches );
191 if ( control != ACL_BREAK ) {
195 memset(matches, 0, sizeof(matches));
198 if ( ACL_IS_INVALID( mask ) ) {
199 Debug( LDAP_DEBUG_ACL,
200 "=> access_allowed: \"%s\" (%s) invalid!\n",
204 } else if ( control == ACL_BREAK ) {
205 Debug( LDAP_DEBUG_ACL,
206 "=> access_allowed: no more rules\n", 0, 0, 0);
210 Debug( LDAP_DEBUG_ACL,
211 "=> access_allowed: %s access %s by %s\n",
212 access2str( access ),
213 ACL_GRANT(mask, access) ? "granted" : "denied",
214 accessmask2str( mask, accessmaskbuf ) );
216 return ACL_GRANT(mask, access);
220 * acl_get - return the acl applicable to entry e, attribute
221 * attr. the acl returned is suitable for use in subsequent calls to
222 * acl_access_allowed().
225 static AccessControl *
232 #ifdef SLAPD_SCHEMA_NOT_COMPAT
233 AttributeDescription *desc,
238 regmatch_t *matches )
242 assert( count != NULL );
257 #ifdef SLAPD_SCHEMA_NOT_COMPAT
258 attr = desc->ad_cname->bv_val;
263 for ( ; a != NULL; a = a->acl_next ) {
266 if (a->acl_dn_pat != NULL) {
267 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
268 *count, a->acl_dn_pat, (int) a->acl_dn_re.re_nsub );
270 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0)) {
274 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
279 if ( a->acl_filter != NULL ) {
280 ber_int_t rc = test_filter( NULL, NULL, NULL, e, a->acl_filter );
281 if ( rc != LDAP_COMPARE_TRUE ) {
286 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] check attr %s\n",
289 if ( attr == NULL || a->acl_attrs == NULL ||
290 ad_inlist( desc, a->acl_attrs ) )
292 Debug( LDAP_DEBUG_ACL,
293 "<= acl_get: [%d] acl %s attr: %s\n",
294 *count, e->e_dn, attr );
297 matches[0].rm_so = matches[0].rm_eo = -1;
300 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
306 * acl_mask - modifies mask based upon the given acl and the
307 * requested access to entry e, attribute attr, value val. if val
308 * is null, access to the whole attribute is assumed (all values).
310 * returns 0 access NOT allowed
314 static slap_control_t
317 slap_access_mask_t *mask,
322 #ifdef SLAPD_SCHEMA_NOT_COMPAT
323 AttributeDescription *attr,
334 char accessmaskbuf[ACCESSMASK_MAXLEN];
338 assert( mask != NULL );
340 Debug( LDAP_DEBUG_ACL,
341 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
344 Debug( LDAP_DEBUG_ACL,
345 "=> acl_mask: to value \"%s\" by \"%s\", (%s) \n",
346 val ? val->bv_val : "*",
347 op->o_ndn ? op->o_ndn : "",
348 accessmask2str( *mask, accessmaskbuf ) );
350 for ( i = 1, b = a->acl_access; b != NULL; b = b->a_next, i++ ) {
351 slap_access_mask_t oldmask, modmask;
353 ACL_INVALIDATE( modmask );
355 /* AND <who> clauses */
356 if ( b->a_dn_pat != NULL ) {
357 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
360 * if access applies to the entry itself, and the
361 * user is bound as somebody in the same namespace as
362 * the entry, OR the given dn matches the dn pattern
364 if ( strcmp( b->a_dn_pat, "anonymous" ) == 0 ) {
365 if (op->o_ndn != NULL && op->o_ndn[0] != '\0' ) {
369 } else if ( strcmp( b->a_dn_pat, "users" ) == 0 ) {
370 if (op->o_ndn == NULL || op->o_ndn[0] == '\0' ) {
374 } else if ( strcmp( b->a_dn_pat, "self" ) == 0 ) {
375 if( op->o_ndn == NULL || op->o_ndn[0] == '\0' ) {
379 if ( e->e_dn == NULL || strcmp( e->e_ndn, op->o_ndn ) != 0 ) {
383 } else if ( strcmp( b->a_dn_pat, "*" ) != 0 ) {
384 int ret = regex_matches( b->a_dn_pat,
385 op->o_ndn, e->e_ndn, matches );
393 if ( b->a_sockurl_pat != NULL ) {
394 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
395 b->a_sockurl_pat, 0, 0 );
397 if ( strcmp( b->a_sockurl_pat, "*" ) != 0 &&
398 !regex_matches( b->a_sockurl_pat, conn->c_listener_url,
399 e->e_ndn, matches ) )
405 if ( b->a_domain_pat != NULL ) {
406 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
407 b->a_domain_pat, 0, 0 );
409 if ( strcmp( b->a_domain_pat, "*" ) != 0 &&
410 !regex_matches( b->a_domain_pat, conn->c_peer_domain,
411 e->e_ndn, matches ) )
417 if ( b->a_peername_pat != NULL ) {
418 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
419 b->a_peername_pat, 0, 0 );
421 if ( strcmp( b->a_peername_pat, "*" ) != 0 &&
422 !regex_matches( b->a_peername_pat, conn->c_peer_name,
423 e->e_ndn, matches ) )
429 if ( b->a_sockname_pat != NULL ) {
430 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
431 b->a_sockname_pat, 0, 0 );
433 if ( strcmp( b->a_sockname_pat, "*" ) != 0 &&
434 !regex_matches( b->a_sockname_pat, conn->c_sock_name,
435 e->e_ndn, matches ) )
441 if ( b->a_dn_at != NULL && op->o_ndn != NULL ) {
445 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
448 bv.bv_val = op->o_ndn;
449 bv.bv_len = strlen( bv.bv_val );
451 /* see if asker is listed in dnattr */
452 if ( (at = attr_find( e->e_attrs, b->a_dn_at )) != NULL
453 #ifdef SLAPD_SCHEMA_NOT_COMPAT
454 /* not yet implemented */
456 && value_find( at->a_vals, &bv, at->a_syntax, 3 ) == 0
462 #ifdef SLAPD_SCHEMA_NOT_COMPAT
463 /* not yet implemented */
465 || value_cmp( &bv, val, at->a_syntax, 2 )
472 /* asker not listed in dnattr - check for self access */
473 } else if ( ! b->a_dn_self || val == NULL
474 #ifdef SLAPD_SCHEMA_NOT_COMPAT
475 /* not yet implemented */
477 || value_cmp( &bv, val, at->a_syntax, 2 ) != 0
485 if ( b->a_group_pat != NULL && op->o_ndn != NULL ) {
488 /* b->a_group is an unexpanded entry name, expanded it should be an
489 * entry with objectclass group* and we test to see if odn is one of
490 * the values in the attribute group
492 /* see if asker is listed in dnattr */
493 string_expand(buf, sizeof(buf), b->a_group_pat, e->e_ndn, matches);
494 if ( dn_normalize(buf) == NULL ) {
495 /* did not expand to a valid dn */
499 if (backend_group(be, e, buf, op->o_ndn,
500 b->a_group_oc, b->a_group_at) != 0)
506 #ifdef SLAPD_ACI_ENABLED
507 if ( b->a_aci_at != NULL ) {
509 slap_access_t grant, deny, tgrant, tdeny;
511 /* this case works different from the others above.
512 * since aci's themselves give permissions, we need
513 * to first check b->a_mask, the ACL's access level.
516 if( op->o_ndn == NULL || op->o_ndn[0] == '\0' ) {
520 if ( e->e_dn == NULL ) {
524 /* first check if the right being requested
525 * is allowed by the ACL clause.
527 if ( ! ACL_GRANT( b->a_mask, *mask ) ) {
531 /* get the aci attribute */
532 at = attr_find( e->e_attrs, b->a_aci_at );
537 /* start out with nothing granted, nothing denied */
541 /* the aci is an multi-valued attribute. The
542 * rights are determined by OR'ing the individual
543 * rights given by the acis.
545 for ( i = 0; at->a_vals[i] != NULL; i++ ) {
546 if (aci_mask( be, op,
547 e, attr, val, at->a_vals[i],
548 matches, &grant, &deny ) != 0)
555 /* remove anything that the ACL clause does not allow */
556 tgrant &= b->a_mask & ACL_PRIV_MASK;
557 tdeny &= ACL_PRIV_MASK;
559 /* see if we have anything to contribute */
560 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
564 /* this could be improved by changing acl_mask so that it can deal with
565 * by clauses that return grant/deny pairs. Right now, it does either
566 * additive or subtractive rights, but not both at the same time. So,
567 * we need to combine the grant/deny pair into a single rights mask in
568 * a smart way: if either grant or deny is "empty", then we use the
569 * opposite as is, otherwise we remove any denied rights from the grant
570 * rights mask and construct an additive mask.
572 if (ACL_IS_INVALID(tdeny)) {
573 modmask = tgrant | ACL_PRIV_ADDITIVE;
575 } else if (ACL_IS_INVALID(tgrant)) {
576 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
579 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
589 Debug( LDAP_DEBUG_ACL,
590 "<= acl_mask: [%d] applying %s (%s)\n",
591 i, accessmask2str( modmask, accessmaskbuf ),
592 b->a_type == ACL_CONTINUE
594 : b->a_type == ACL_BREAK
601 if( ACL_IS_ADDITIVE(modmask) ) {
603 ACL_PRIV_SET( *mask, modmask );
606 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
608 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
609 /* substract privs */
610 ACL_PRIV_CLR( *mask, modmask );
613 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
620 Debug( LDAP_DEBUG_ACL,
621 "<= acl_mask: [%d] mask: %s\n",
622 i, accessmask2str(*mask, accessmaskbuf), 0 );
624 if( b->a_type == ACL_CONTINUE ) {
627 } else if ( b->a_type == ACL_BREAK ) {
635 Debug( LDAP_DEBUG_ACL,
636 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
637 accessmask2str(*mask, accessmaskbuf), 0, 0 );
642 * acl_check_modlist - check access control on the given entry to see if
643 * it allows the given modifications by the user associated with op.
644 * returns 1 if mods allowed ok
659 assert( be != NULL );
661 /* short circuit root database access */
662 if ( be_isroot( be, op->o_ndn ) ) {
663 Debug( LDAP_DEBUG_ACL,
664 "<= acl_access_allowed: granted to database root\n",
669 /* use backend default access if no backend acls */
670 if( be != NULL && be->be_acl == NULL ) {
671 Debug( LDAP_DEBUG_ACL,
672 "=> access_allowed: backend default %s access %s to \"%s\"\n",
673 access2str( ACL_WRITE ),
674 be->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn );
676 return be->be_dfltaccess >= ACL_WRITE;
679 /* be is always non-NULL */
680 /* use global default access if no global acls */
681 } else if ( be == NULL && global_acl == NULL ) {
682 Debug( LDAP_DEBUG_ACL,
683 "=> access_allowed: global default %s access %s to \"%s\"\n",
684 access2str( ACL_WRITE ),
685 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn );
687 return global_default_access >= ACL_WRITE;
691 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
693 * no-user-modification operational attributes are ignored
694 * by ACL_WRITE checking as any found here are not provided
697 #ifdef SLAPD_SCHEMA_NOT_COMPAT
698 /* not yet implemented */
700 if ( oc_check_op_no_usermod_attr( mlist->sml_type ) ) {
701 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
702 " modify access granted\n",
703 mlist->sml_type, 0, 0 );
708 switch ( mlist->sml_op ) {
709 case LDAP_MOD_REPLACE:
711 if ( mlist->sml_bvalues == NULL ) {
714 for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) {
715 if ( ! access_allowed( be, conn, op, e,
716 #ifdef SLAPD_SCHEMA_NOT_COMPAT
721 mlist->sml_bvalues[i], ACL_WRITE ) )
728 case LDAP_MOD_DELETE:
729 if ( mlist->sml_bvalues == NULL ) {
730 if ( ! access_allowed( be, conn, op, e,
731 #ifdef SLAPD_SCHEMA_NOT_COMPAT
742 for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) {
743 if ( ! access_allowed( be, conn, op, e,
744 #ifdef SLAPD_SCHEMA_NOT_COMPAT
749 mlist->sml_bvalues[i], ACL_WRITE ) )
761 #ifdef SLAPD_ACI_ENABLED
763 aci_bvstrdup( struct berval *bv )
767 s = (char *)ch_malloc(bv->bv_len + 1);
769 memcpy(s, bv->bv_val, bv->bv_len);
782 res = strncasecmp( s, bv->bv_val, bv->bv_len );
786 if (len > (int)bv->bv_len)
788 if (len < (int)bv->bv_len)
809 while (len >= 0 && --ix >= 0) {
810 while (--len >= 0 && *p++ != sep) ;
812 while (len >= 0 && *p == ' ') {
823 while (--len >= 0 && *p != sep) {
827 while (bv->bv_len > 0 && *--p == ' ')
834 struct berval *list )
841 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
844 switch (*bv.bv_val) {
846 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
849 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
850 * the right 's' to mean "set", but in the examples states
851 * that the right 's' means "search". The latter definition
854 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
857 ACL_PRIV_SET(mask, ACL_PRIV_READ);
860 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
863 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
864 * define any equivalent to the AUTH right, so I've just used
867 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
883 struct berval bv, left, right;
886 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
887 if (aci_get_part(&bv, 0, '=', &left) < 0
888 || aci_get_part(&bv, 1, '=', &right) < 0)
890 if (aci_strbvcmp(attr, &bv) == 0)
892 } else if (val == NULL) {
893 if (aci_strbvcmp(attr, &left) == 0)
896 if (aci_strbvcmp(attr, &left) == 0) {
897 /* this is experimental code that implements a
898 * simple (prefix) match of the attribute value.
899 * the ACI draft does not provide for aci's that
900 * apply to specific values, but it would be
901 * nice to have. If the <attr> part of an aci's
902 * rights list is of the form <attr>=<value>,
903 * that means the aci applies only to attrs with
904 * the given value. Furthermore, if the attr is
905 * of the form <attr>=<value>*, then <value> is
906 * treated as a prefix, and the aci applies to
907 * any value with that prefix.
909 * Ideally, this would allow r.e. matches.
911 if (aci_get_part(&right, 0, '*', &left) < 0
912 || right.bv_len <= left.bv_len)
914 if (aci_strbvcmp(val->bv_val, &right) == 0)
916 } else if (val->bv_len >= left.bv_len) {
917 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
927 aci_list_get_attr_rights(
936 /* loop through each rights/attr pair, skip first part (action) */
938 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
939 if (aci_list_has_attr(&bv, attr, val) == 0)
941 if (aci_get_part(list, i, ';', &bv) < 0)
943 mask |= aci_list_map_rights(&bv);
953 slap_access_t *grant,
954 slap_access_t *deny )
956 struct berval perm, actn;
960 if (attr == NULL || *attr == 0 || strcasecmp(attr, "entry") == 0) {
967 /* loop through each permissions clause */
968 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
969 if (aci_get_part(&perm, 0, ';', &actn) < 0)
971 if (aci_strbvcmp( "grant", &actn ) == 0) {
973 } else if (aci_strbvcmp( "deny", &actn ) == 0) {
980 *mask |= aci_list_get_attr_rights(&perm, attr, val);
981 *mask |= aci_list_get_attr_rights(&perm, "[all]", NULL);
998 char *subjdn, *grpdn;
1001 /* format of string is "group/objectClassValue/groupAttrName" */
1002 if (aci_get_part(subj, 0, '/', &bv) < 0)
1004 subjdn = aci_bvstrdup(&bv);
1008 if (aci_get_part(subj, 1, '/', &bv) < 0)
1009 grpoc = ch_strdup(grpoc);
1011 grpoc = aci_bvstrdup(&bv);
1013 if (aci_get_part(subj, 2, '/', &bv) < 0)
1014 grpat = ch_strdup(grpat);
1016 grpat = aci_bvstrdup(&bv);
1018 grpdn = (char *)ch_malloc(1024);
1019 if (grpoc != NULL && grpat != NULL && grpdn != NULL) {
1020 string_expand(grpdn, 1024, subjdn, e->e_ndn, matches);
1021 if ( dn_normalize(grpdn) != NULL ) {
1022 rc = (backend_group(be, e, grpdn, op->o_ndn, grpoc, grpat) == 0);
1039 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1040 AttributeDescription *desc,
1046 regmatch_t *matches,
1047 slap_access_t *grant,
1051 struct berval bv, perms, sdn;
1055 /* parse an aci of the form:
1056 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1058 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1059 a full description of the format for this attribute.
1061 For now, this routine only supports scope=entry.
1064 /* check that the aci has all 5 components */
1065 if (aci_get_part(aci, 4, '#', NULL) < 0)
1068 /* check that the aci family is supported */
1069 if (aci_get_part(aci, 0, '#', &bv) < 0)
1071 for (i = 0; supportedACIMechs[i] != NULL; i++) {
1072 if (aci_strbvcmp( supportedACIMechs[i], &bv ) == 0)
1075 if (supportedACIMechs[i] == NULL)
1078 /* check that the scope is "entry" */
1079 if (aci_get_part(aci, 1, '#', &bv) < 0
1080 || aci_strbvcmp( "entry", &bv ) != 0)
1085 /* get the list of permissions clauses, bail if empty */
1086 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1089 /* check if any permissions allow desired access */
1090 if (aci_list_get_rights(&perms, attr, val, grant, deny) == 0)
1093 /* see if we have a DN match */
1094 if (aci_get_part(aci, 3, '#', &bv) < 0)
1097 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1100 if (aci_strbvcmp( "access-id", &bv ) == 0) {
1101 subjdn = aci_bvstrdup(&sdn);
1105 if ( dn_normalize(subjdn) != NULL )
1106 if (strcasecmp(op->o_ndn, subjdn) != 0)
1112 if (aci_strbvcmp( "self", &bv ) == 0) {
1113 if (strcasecmp(op->o_ndn, e->e_ndn) == 0)
1116 } else if (aci_strbvcmp( "dnattr", &bv ) == 0) {
1118 char *attrname = aci_bvstrdup(&sdn);
1119 at = attr_find(e->e_attrs, attrname);
1123 bv.bv_val = op->o_ndn;
1124 bv.bv_len = strlen( bv.bv_val );
1126 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1127 /* not yet implemented */
1129 if (value_find( at->a_vals, &bv, at->a_syntax, 3 ) == 0 )
1134 } else if (aci_strbvcmp( "group", &bv ) == 0) {
1135 if (aci_group_member(&sdn, "groupOfNames", "member", be, e, op, matches))
1138 } else if (aci_strbvcmp( "role", &bv ) == 0) {
1139 if (aci_group_member(&sdn, "organizationalRole", "roleOccupant", be, e, op, matches))
1147 get_supported_acimech(
1150 if (index < 0 || index >= (sizeof(supportedACIMechs) / sizeof(char *)))
1152 return(supportedACIMechs[index]);
1155 #endif /* SLAPD_ACI_ENABLED */
1163 regmatch_t *matches)
1172 bufsiz--; /* leave space for lone $ */
1175 for ( dp = newbuf, sp = pat; size < bufsiz && *sp ; sp++) {
1176 /* did we previously see a $ */
1181 } else if (*sp >= '0' && *sp <= '9' ) {
1188 i = matches[n].rm_so;
1189 l = matches[n].rm_eo;
1190 for ( ; size < 512 && i < l; size++, i++ ) {
1208 /* must have ended with a single $ */
1215 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %s\n", pat, 0, 0 );
1216 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", newbuf, 0, 0 );
1221 char *pat, /* pattern to expand and match against */
1222 char *str, /* string to match against pattern */
1223 char *buf, /* buffer with $N expansion variables */
1224 regmatch_t *matches /* offsets in buffer for $N expansion variables */
1231 if(str == NULL) str = "";
1233 string_expand(newbuf, sizeof(newbuf), pat, buf, matches);
1234 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
1236 regerror(rc, &re, error, sizeof(error));
1238 Debug( LDAP_DEBUG_TRACE,
1239 "compile( \"%s\", \"%s\") failed %s\n",
1244 rc = regexec(&re, str, 0, NULL, 0);
1247 Debug( LDAP_DEBUG_TRACE,
1248 "=> regex_matches: string: %s\n", str, 0, 0 );
1249 Debug( LDAP_DEBUG_TRACE,
1250 "=> regex_matches: rc: %d %s\n",
1251 rc, !rc ? "matches" : "no matches", 0 );