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 #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 mlist->sml_desc, mlist->sml_bvalues[i], ACL_WRITE ) )
723 case LDAP_MOD_DELETE:
724 if ( mlist->sml_bvalues == NULL ) {
725 if ( ! access_allowed( be, conn, op, e,
726 mlist->sml_desc, NULL, ACL_WRITE ) )
732 for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) {
733 if ( ! access_allowed( be, conn, op, e,
734 mlist->sml_desc, mlist->sml_bvalues[i], ACL_WRITE ) )
746 #ifdef SLAPD_ACI_ENABLED
748 aci_bvstrdup( struct berval *bv )
752 s = (char *)ch_malloc(bv->bv_len + 1);
754 memcpy(s, bv->bv_val, bv->bv_len);
767 res = strncasecmp( s, bv->bv_val, bv->bv_len );
771 if (len > (int)bv->bv_len)
773 if (len < (int)bv->bv_len)
794 while (len >= 0 && --ix >= 0) {
795 while (--len >= 0 && *p++ != sep) ;
797 while (len >= 0 && *p == ' ') {
808 while (--len >= 0 && *p != sep) {
812 while (bv->bv_len > 0 && *--p == ' ')
819 struct berval *list )
826 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
829 switch (*bv.bv_val) {
831 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
834 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
835 * the right 's' to mean "set", but in the examples states
836 * that the right 's' means "search". The latter definition
839 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
842 ACL_PRIV_SET(mask, ACL_PRIV_READ);
845 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
848 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
849 * define any equivalent to the AUTH right, so I've just used
852 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
868 struct berval bv, left, right;
871 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
872 if (aci_get_part(&bv, 0, '=', &left) < 0
873 || aci_get_part(&bv, 1, '=', &right) < 0)
875 if (aci_strbvcmp(attr, &bv) == 0)
877 } else if (val == NULL) {
878 if (aci_strbvcmp(attr, &left) == 0)
881 if (aci_strbvcmp(attr, &left) == 0) {
882 /* this is experimental code that implements a
883 * simple (prefix) match of the attribute value.
884 * the ACI draft does not provide for aci's that
885 * apply to specific values, but it would be
886 * nice to have. If the <attr> part of an aci's
887 * rights list is of the form <attr>=<value>,
888 * that means the aci applies only to attrs with
889 * the given value. Furthermore, if the attr is
890 * of the form <attr>=<value>*, then <value> is
891 * treated as a prefix, and the aci applies to
892 * any value with that prefix.
894 * Ideally, this would allow r.e. matches.
896 if (aci_get_part(&right, 0, '*', &left) < 0
897 || right.bv_len <= left.bv_len)
899 if (aci_strbvcmp(val->bv_val, &right) == 0)
901 } else if (val->bv_len >= left.bv_len) {
902 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
912 aci_list_get_attr_rights(
921 /* loop through each rights/attr pair, skip first part (action) */
923 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
924 if (aci_list_has_attr(&bv, attr, val) == 0)
926 if (aci_get_part(list, i, ';', &bv) < 0)
928 mask |= aci_list_map_rights(&bv);
938 slap_access_t *grant,
939 slap_access_t *deny )
941 struct berval perm, actn;
945 if (attr == NULL || *attr == 0 || strcasecmp(attr, "entry") == 0) {
952 /* loop through each permissions clause */
953 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
954 if (aci_get_part(&perm, 0, ';', &actn) < 0)
956 if (aci_strbvcmp( "grant", &actn ) == 0) {
958 } else if (aci_strbvcmp( "deny", &actn ) == 0) {
965 *mask |= aci_list_get_attr_rights(&perm, attr, val);
966 *mask |= aci_list_get_attr_rights(&perm, "[all]", NULL);
974 const char *defgrpoc,
975 const char *defgrpat,
983 char *subjdn, *grpdn = NULL;
986 #ifdef SLAPD_SCHEMA_NOT_COMPAT
987 AttributeDescription *grpad;
994 /* format of string is "group/objectClassValue/groupAttrName" */
995 if (aci_get_part(subj, 0, '/', &bv) < 0) {
999 subjdn = aci_bvstrdup(&bv);
1000 if (subjdn == NULL) {
1004 if (aci_get_part(subj, 1, '/', &bv) < 0) {
1005 grpoc = ch_strdup( defgrpoc );
1007 grpoc = aci_bvstrdup(&bv);
1010 if (aci_get_part(subj, 2, '/', &bv) < 0) {
1011 grpat = ch_strdup( defgrpat );
1013 grpat = aci_bvstrdup(&bv);
1016 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1017 rc = slap_str2ad( grpat, &grpad, &text );
1018 if( rc != LDAP_SUCCESS ) {
1027 grpdn = (char *)ch_malloc(1024);
1029 if (grpoc != NULL && grpad != NULL && grpdn != NULL) {
1030 string_expand(grpdn, 1024, subjdn, e->e_ndn, matches);
1031 if ( dn_normalize(grpdn) != NULL ) {
1032 rc = (backend_group(be, e, grpdn, op->o_ndn, grpoc, grpad) == 0);
1037 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1038 if( grpad != NULL ) ad_free( grpad, 1 );
1052 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1053 AttributeDescription *desc,
1059 regmatch_t *matches,
1060 slap_access_t *grant,
1064 struct berval bv, perms, sdn;
1067 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1071 /* parse an aci of the form:
1072 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1074 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1075 a full description of the format for this attribute.
1077 For now, this routine only supports scope=entry.
1080 /* check that the aci has all 5 components */
1081 if (aci_get_part(aci, 4, '#', NULL) < 0)
1084 /* check that the aci family is supported */
1085 if (aci_get_part(aci, 0, '#', &bv) < 0)
1087 for (i = 0; supportedACIMechs[i] != NULL; i++) {
1088 if (aci_strbvcmp( supportedACIMechs[i], &bv ) == 0)
1091 if (supportedACIMechs[i] == NULL)
1094 /* check that the scope is "entry" */
1095 if (aci_get_part(aci, 1, '#', &bv) < 0
1096 || aci_strbvcmp( "entry", &bv ) != 0)
1101 /* get the list of permissions clauses, bail if empty */
1102 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1105 /* check if any permissions allow desired access */
1106 if (aci_list_get_rights(&perms, attr, val, grant, deny) == 0)
1109 /* see if we have a DN match */
1110 if (aci_get_part(aci, 3, '#', &bv) < 0)
1113 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1116 if (aci_strbvcmp( "access-id", &bv ) == 0) {
1117 subjdn = aci_bvstrdup(&sdn);
1121 if ( dn_normalize(subjdn) != NULL )
1122 if (strcasecmp(op->o_ndn, subjdn) != 0)
1128 if (aci_strbvcmp( "self", &bv ) == 0) {
1129 if (strcasecmp(op->o_ndn, e->e_ndn) == 0)
1132 } else if (aci_strbvcmp( "dnattr", &bv ) == 0) {
1134 char *dnattr = aci_bvstrdup(&sdn);
1135 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1136 AttributeDescription *dnad;
1138 rc = slap_str2ad( dnattr, &dnad, &text );
1141 if ( rc == LDAP_SUCCESS ) {
1143 char *dnad = dnattr;
1145 at = attr_find( e->e_attrs, dnad );
1146 #ifdef SLAPD_SCHEMA_NOT_COMAT
1152 bv.bv_val = op->o_ndn;
1153 bv.bv_len = strlen( bv.bv_val );
1155 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1156 /* not yet implemented */
1158 if (value_find( at->a_vals, &bv, at->a_syntax, 3 ) == 0 )
1162 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1168 } else if (aci_strbvcmp( "group", &bv ) == 0) {
1169 if (aci_group_member(&sdn, "groupOfNames", "member", be, e, op, matches))
1172 } else if (aci_strbvcmp( "role", &bv ) == 0) {
1173 if (aci_group_member(&sdn, "organizationalRole", "roleOccupant", be, e, op, matches))
1181 get_supported_acimech(
1184 if (index < 0 || index >= (sizeof(supportedACIMechs) / sizeof(char *)))
1186 return(supportedACIMechs[index]);
1189 #endif /* SLAPD_ACI_ENABLED */
1197 regmatch_t *matches)
1206 bufsiz--; /* leave space for lone $ */
1209 for ( dp = newbuf, sp = pat; size < bufsiz && *sp ; sp++) {
1210 /* did we previously see a $ */
1215 } else if (*sp >= '0' && *sp <= '9' ) {
1222 i = matches[n].rm_so;
1223 l = matches[n].rm_eo;
1224 for ( ; size < 512 && i < l; size++, i++ ) {
1242 /* must have ended with a single $ */
1249 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %s\n", pat, 0, 0 );
1250 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", newbuf, 0, 0 );
1255 char *pat, /* pattern to expand and match against */
1256 char *str, /* string to match against pattern */
1257 char *buf, /* buffer with $N expansion variables */
1258 regmatch_t *matches /* offsets in buffer for $N expansion variables */
1265 if(str == NULL) str = "";
1267 string_expand(newbuf, sizeof(newbuf), pat, buf, matches);
1268 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
1270 regerror(rc, &re, error, sizeof(error));
1272 Debug( LDAP_DEBUG_TRACE,
1273 "compile( \"%s\", \"%s\") failed %s\n",
1278 rc = regexec(&re, str, 0, NULL, 0);
1281 Debug( LDAP_DEBUG_TRACE,
1282 "=> regex_matches: string: %s\n", str, 0, 0 );
1283 Debug( LDAP_DEBUG_TRACE,
1284 "=> regex_matches: rc: %d %s\n",
1285 rc, !rc ? "matches" : "no matches", 0 );