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,
55 slap_access_t *deny );
58 static int regex_matches(
59 char *pat, char *str, char *buf, regmatch_t *matches);
60 static void string_expand(
61 char *newbuf, int bufsiz, char *pattern,
62 char *match, regmatch_t *matches);
66 * access_allowed - check whether op->o_ndn is allowed the requested access
67 * to entry e, attribute attr, value val. if val is null, access to
68 * the whole attribute is assumed (all values).
70 * This routine loops through all access controls and calls
71 * acl_mask() on each applicable access control.
72 * The loop exits when a definitive answer is reached or
73 * or no more controls remain.
86 #ifdef SLAPD_SCHEMA_NOT_COMPAT
87 AttributeDescription *desc,
92 slap_access_t access )
97 char accessmaskbuf[ACCESSMASK_MAXLEN];
99 slap_access_mask_t mask;
100 slap_control_t control;
102 #ifdef SLAPD_SCHEMA_NOT_COMPAT
103 const char *attr = desc ? desc->ad_cname->bv_val : NULL;
105 const char *attr = desc;
108 regmatch_t matches[MAXREMATCHES];
110 Debug( LDAP_DEBUG_ACL,
111 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
112 access2str( access ),
115 assert( be != NULL );
117 assert( attr != NULL );
118 assert( access > ACL_NONE );
120 /* grant database root access */
121 if ( be != NULL && be_isroot( be, op->o_ndn ) ) {
122 Debug( LDAP_DEBUG_ACL,
123 "<= root access granted\n",
129 * no-user-modification operational attributes are ignored
130 * by ACL_WRITE checking as any found here are not provided
133 #ifdef SLAPD_SCHEMA_NOT_COMPAT
134 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type ) )
136 if ( access >= ACL_WRITE && oc_check_op_no_usermod_attr( attr ) )
139 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
140 " %s access granted\n",
145 /* use backend default access if no backend acls */
146 if( be != NULL && be->be_acl == NULL ) {
147 Debug( LDAP_DEBUG_ACL,
148 "=> access_allowed: backend default %s access %s to \"%s\"\n",
149 access2str( access ),
150 be->be_dfltaccess >= access ? "granted" : "denied", op->o_dn );
152 return be->be_dfltaccess >= access;
155 /* be is always non-NULL */
156 /* use global default access if no global acls */
157 } else if ( be == NULL && global_acl == NULL ) {
158 Debug( LDAP_DEBUG_ACL,
159 "=> access_allowed: global default %s access %s to \"%s\"\n",
160 access2str( access ),
161 global_default_access >= access ? "granted" : "denied", op->o_dn );
163 return global_default_access >= access;
168 memset(matches, 0, sizeof(matches));
174 while( a = acl_get( a, &count, be, op, e, desc, MAXREMATCHES, matches ) )
178 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
179 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
180 (int)matches[i].rm_so, (int)matches[i].rm_eo );
182 if( matches[i].rm_so <= matches[0].rm_eo ) {
184 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
185 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
188 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
191 control = acl_mask( a, &mask, be, conn, op,
192 e, desc, val, matches );
194 if ( control != ACL_BREAK ) {
198 memset(matches, 0, sizeof(matches));
201 if ( ACL_IS_INVALID( mask ) ) {
202 Debug( LDAP_DEBUG_ACL,
203 "=> access_allowed: \"%s\" (%s) invalid!\n",
207 } else if ( control == ACL_BREAK ) {
208 Debug( LDAP_DEBUG_ACL,
209 "=> access_allowed: no more rules\n", 0, 0, 0);
213 Debug( LDAP_DEBUG_ACL,
214 "=> access_allowed: %s access %s by %s\n",
215 access2str( access ),
216 ACL_GRANT(mask, access) ? "granted" : "denied",
217 accessmask2str( mask, accessmaskbuf ) );
219 return ACL_GRANT(mask, access);
223 * acl_get - return the acl applicable to entry e, attribute
224 * attr. the acl returned is suitable for use in subsequent calls to
225 * acl_access_allowed().
228 static AccessControl *
235 #ifdef SLAPD_SCHEMA_NOT_COMPAT
236 AttributeDescription *desc,
241 regmatch_t *matches )
245 assert( count != NULL );
247 #ifdef SLAPD_SCHEMA_NOT_COMPAT
248 attr = desc ? desc->ad_cname->bv_val : NULL;
266 for ( ; a != NULL; a = a->acl_next ) {
269 if (a->acl_dn_pat != NULL) {
270 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
271 *count, a->acl_dn_pat, (int) a->acl_dn_re.re_nsub );
273 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0)) {
277 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
282 if ( a->acl_filter != NULL ) {
283 ber_int_t rc = test_filter( NULL, NULL, NULL, e, a->acl_filter );
284 if ( rc != LDAP_COMPARE_TRUE ) {
289 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] check attr %s\n",
292 if ( attr == NULL || a->acl_attrs == NULL ||
293 ad_inlist( desc, a->acl_attrs ) )
295 Debug( LDAP_DEBUG_ACL,
296 "<= acl_get: [%d] acl %s attr: %s\n",
297 *count, e->e_dn, attr );
300 matches[0].rm_so = matches[0].rm_eo = -1;
303 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
309 * acl_mask - modifies mask based upon the given acl and the
310 * requested access to entry e, attribute attr, value val. if val
311 * is null, access to the whole attribute is assumed (all values).
313 * returns 0 access NOT allowed
317 static slap_control_t
320 slap_access_mask_t *mask,
325 #ifdef SLAPD_SCHEMA_NOT_COMPAT
326 AttributeDescription *desc,
337 char accessmaskbuf[ACCESSMASK_MAXLEN];
339 #ifdef SLAPD_SCHEMA_NOT_COMPAT
340 const char *attr = desc ? desc->ad_cname->bv_val : NULL;
342 const char *attr = desc;
346 assert( mask != NULL );
348 Debug( LDAP_DEBUG_ACL,
349 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
352 Debug( LDAP_DEBUG_ACL,
353 "=> acl_mask: to value \"%s\" by \"%s\", (%s) \n",
354 val ? val->bv_val : "*",
355 op->o_ndn ? op->o_ndn : "",
356 accessmask2str( *mask, accessmaskbuf ) );
358 for ( i = 1, b = a->acl_access; b != NULL; b = b->a_next, i++ ) {
359 slap_access_mask_t oldmask, modmask;
361 ACL_INVALIDATE( modmask );
363 /* AND <who> clauses */
364 if ( b->a_dn_pat != NULL ) {
365 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
368 * if access applies to the entry itself, and the
369 * user is bound as somebody in the same namespace as
370 * the entry, OR the given dn matches the dn pattern
372 if ( strcmp( b->a_dn_pat, "anonymous" ) == 0 ) {
373 if (op->o_ndn != NULL && op->o_ndn[0] != '\0' ) {
377 } else if ( strcmp( b->a_dn_pat, "users" ) == 0 ) {
378 if (op->o_ndn == NULL || op->o_ndn[0] == '\0' ) {
382 } else if ( strcmp( b->a_dn_pat, "self" ) == 0 ) {
383 if( op->o_ndn == NULL || op->o_ndn[0] == '\0' ) {
387 if ( e->e_dn == NULL || strcmp( e->e_ndn, op->o_ndn ) != 0 ) {
391 } else if ( strcmp( b->a_dn_pat, "*" ) != 0 ) {
392 int ret = regex_matches( b->a_dn_pat,
393 op->o_ndn, e->e_ndn, matches );
401 if ( b->a_sockurl_pat != NULL ) {
402 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
403 b->a_sockurl_pat, 0, 0 );
405 if ( strcmp( b->a_sockurl_pat, "*" ) != 0 &&
406 !regex_matches( b->a_sockurl_pat, conn->c_listener_url,
407 e->e_ndn, matches ) )
413 if ( b->a_domain_pat != NULL ) {
414 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
415 b->a_domain_pat, 0, 0 );
417 if ( strcmp( b->a_domain_pat, "*" ) != 0 &&
418 !regex_matches( b->a_domain_pat, conn->c_peer_domain,
419 e->e_ndn, matches ) )
425 if ( b->a_peername_pat != NULL ) {
426 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
427 b->a_peername_pat, 0, 0 );
429 if ( strcmp( b->a_peername_pat, "*" ) != 0 &&
430 !regex_matches( b->a_peername_pat, conn->c_peer_name,
431 e->e_ndn, matches ) )
437 if ( b->a_sockname_pat != NULL ) {
438 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
439 b->a_sockname_pat, 0, 0 );
441 if ( strcmp( b->a_sockname_pat, "*" ) != 0 &&
442 !regex_matches( b->a_sockname_pat, conn->c_sock_name,
443 e->e_ndn, matches ) )
449 if ( b->a_dn_at != NULL && op->o_ndn != NULL ) {
452 #ifdef SLAPD_SCHEMA_NOT_COMPAT
455 const char *desc = b->a_dn_at->ad_cname->bv_val;
457 const char *desc = b->a_dn_at;
460 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
463 bv.bv_val = op->o_ndn;
464 bv.bv_len = strlen( bv.bv_val );
466 /* see if asker is listed in dnattr */
467 #ifdef SLAPD_SCHEMA_NOT_COMPAT
468 for( at = attrs_find( e->e_attrs, b->a_dn_at );
470 at = attrs_find( e->e_attrs->a_next, b->a_dn_at ) )
472 if( value_find( b->a_dn_at, at->a_vals, &bv ) == 0 ) {
480 if ( b->a_dn_self && (val == NULL
481 || value_match( &match, b->a_dn_at,
482 b->a_dn_at->ad_type->sat_equality, val, &bv, &text ) )
488 } else if ( ! b->a_dn_self || val == NULL
489 || value_match( &match, b->a_dn_at,
490 b->a_dn_at->ad_type->sat_equality, val, &bv, &text )
497 /* see if asker is listed in dnattr */
498 if ( (at = attr_find( e->e_attrs, b->a_dn_at )) != NULL &&
499 value_find( at->a_vals, &bv, at->a_syntax, 3 ) == 0 )
501 if ( b->a_dn_self && (val == NULL
502 || value_cmp( &bv, val, at->a_syntax, 2 ) ) )
507 /* asker not listed in dnattr - check for self access */
508 } else if ( ! b->a_dn_self || val == NULL
509 || value_cmp( &bv, val, at->a_syntax, 2 ) != 0 )
516 if ( b->a_group_pat != NULL && op->o_ndn != NULL ) {
519 /* b->a_group is an unexpanded entry name, expanded it should be an
520 * entry with objectclass group* and we test to see if odn is one of
521 * the values in the attribute group
523 /* see if asker is listed in dnattr */
524 string_expand(buf, sizeof(buf), b->a_group_pat, e->e_ndn, matches);
525 if ( dn_normalize(buf) == NULL ) {
526 /* did not expand to a valid dn */
530 if (backend_group(be, e, buf, op->o_ndn,
531 b->a_group_oc, b->a_group_at) != 0)
537 #ifdef SLAPD_ACI_ENABLED
538 if ( b->a_aci_at != NULL ) {
540 slap_access_t grant, deny, tgrant, tdeny;
542 /* this case works different from the others above.
543 * since aci's themselves give permissions, we need
544 * to first check b->a_mask, the ACL's access level.
547 if( op->o_ndn == NULL || op->o_ndn[0] == '\0' ) {
551 if ( e->e_dn == NULL ) {
555 /* first check if the right being requested
556 * is allowed by the ACL clause.
558 if ( ! ACL_GRANT( b->a_mask, *mask ) ) {
562 /* get the aci attribute */
563 at = attr_find( e->e_attrs, b->a_aci_at );
568 /* start out with nothing granted, nothing denied */
572 /* the aci is an multi-valued attribute. The
573 * rights are determined by OR'ing the individual
574 * rights given by the acis.
576 for ( i = 0; at->a_vals[i] != NULL; i++ ) {
577 if (aci_mask( be, op,
578 e, desc, val, at->a_vals[i],
579 matches, &grant, &deny ) != 0)
586 /* remove anything that the ACL clause does not allow */
587 tgrant &= b->a_mask & ACL_PRIV_MASK;
588 tdeny &= ACL_PRIV_MASK;
590 /* see if we have anything to contribute */
591 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
595 /* this could be improved by changing acl_mask so that it can deal with
596 * by clauses that return grant/deny pairs. Right now, it does either
597 * additive or subtractive rights, but not both at the same time. So,
598 * we need to combine the grant/deny pair into a single rights mask in
599 * a smart way: if either grant or deny is "empty", then we use the
600 * opposite as is, otherwise we remove any denied rights from the grant
601 * rights mask and construct an additive mask.
603 if (ACL_IS_INVALID(tdeny)) {
604 modmask = tgrant | ACL_PRIV_ADDITIVE;
606 } else if (ACL_IS_INVALID(tgrant)) {
607 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
610 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
620 Debug( LDAP_DEBUG_ACL,
621 "<= acl_mask: [%d] applying %s (%s)\n",
622 i, accessmask2str( modmask, accessmaskbuf ),
623 b->a_type == ACL_CONTINUE
625 : b->a_type == ACL_BREAK
632 if( ACL_IS_ADDITIVE(modmask) ) {
634 ACL_PRIV_SET( *mask, modmask );
637 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
639 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
640 /* substract privs */
641 ACL_PRIV_CLR( *mask, modmask );
644 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
651 Debug( LDAP_DEBUG_ACL,
652 "<= acl_mask: [%d] mask: %s\n",
653 i, accessmask2str(*mask, accessmaskbuf), 0 );
655 if( b->a_type == ACL_CONTINUE ) {
658 } else if ( b->a_type == ACL_BREAK ) {
666 Debug( LDAP_DEBUG_ACL,
667 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
668 accessmask2str(*mask, accessmaskbuf), 0, 0 );
673 * acl_check_modlist - check access control on the given entry to see if
674 * it allows the given modifications by the user associated with op.
675 * returns 1 if mods allowed ok
690 assert( be != NULL );
692 /* short circuit root database access */
693 if ( be_isroot( be, op->o_ndn ) ) {
694 Debug( LDAP_DEBUG_ACL,
695 "<= acl_access_allowed: granted to database root\n",
700 /* use backend default access if no backend acls */
701 if( be != NULL && be->be_acl == NULL ) {
702 Debug( LDAP_DEBUG_ACL,
703 "=> access_allowed: backend default %s access %s to \"%s\"\n",
704 access2str( ACL_WRITE ),
705 be->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn );
707 return be->be_dfltaccess >= ACL_WRITE;
710 /* be is always non-NULL */
711 /* use global default access if no global acls */
712 } else if ( be == NULL && global_acl == NULL ) {
713 Debug( LDAP_DEBUG_ACL,
714 "=> access_allowed: global default %s access %s to \"%s\"\n",
715 access2str( ACL_WRITE ),
716 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn );
718 return global_default_access >= ACL_WRITE;
722 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
724 * no-user-modification operational attributes are ignored
725 * by ACL_WRITE checking as any found here are not provided
728 #ifdef SLAPD_SCHEMA_NOT_COMPAT
729 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
730 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
731 " modify access granted\n",
732 mlist->sml_desc->ad_cname->bv_val, 0, 0 );
736 if ( oc_check_op_no_usermod_attr( mlist->sml_type ) ) {
737 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
738 " modify access granted\n",
739 mlist->sml_type, 0, 0 );
744 switch ( mlist->sml_op ) {
745 case LDAP_MOD_REPLACE:
747 if ( mlist->sml_bvalues == NULL ) {
750 for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) {
751 if ( ! access_allowed( be, conn, op, e,
752 mlist->sml_desc, mlist->sml_bvalues[i], ACL_WRITE ) )
759 case LDAP_MOD_DELETE:
760 if ( mlist->sml_bvalues == NULL ) {
761 if ( ! access_allowed( be, conn, op, e,
762 mlist->sml_desc, NULL, ACL_WRITE ) )
768 for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) {
769 if ( ! access_allowed( be, conn, op, e,
770 mlist->sml_desc, mlist->sml_bvalues[i], ACL_WRITE ) )
782 #ifdef SLAPD_ACI_ENABLED
784 aci_bvstrdup( struct berval *bv )
788 s = (char *)ch_malloc(bv->bv_len + 1);
790 memcpy(s, bv->bv_val, bv->bv_len);
803 res = strncasecmp( s, bv->bv_val, bv->bv_len );
807 if (len > (int)bv->bv_len)
809 if (len < (int)bv->bv_len)
830 while (len >= 0 && --ix >= 0) {
831 while (--len >= 0 && *p++ != sep) ;
833 while (len >= 0 && *p == ' ') {
844 while (--len >= 0 && *p != sep) {
848 while (bv->bv_len > 0 && *--p == ' ')
855 struct berval *list )
862 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
865 switch (*bv.bv_val) {
867 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
870 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
871 * the right 's' to mean "set", but in the examples states
872 * that the right 's' means "search". The latter definition
875 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
878 ACL_PRIV_SET(mask, ACL_PRIV_READ);
881 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
884 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
885 * define any equivalent to the AUTH right, so I've just used
888 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
904 struct berval bv, left, right;
907 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
908 if (aci_get_part(&bv, 0, '=', &left) < 0
909 || aci_get_part(&bv, 1, '=', &right) < 0)
911 if (aci_strbvcmp(attr, &bv) == 0)
913 } else if (val == NULL) {
914 if (aci_strbvcmp(attr, &left) == 0)
917 if (aci_strbvcmp(attr, &left) == 0) {
918 /* this is experimental code that implements a
919 * simple (prefix) match of the attribute value.
920 * the ACI draft does not provide for aci's that
921 * apply to specific values, but it would be
922 * nice to have. If the <attr> part of an aci's
923 * rights list is of the form <attr>=<value>,
924 * that means the aci applies only to attrs with
925 * the given value. Furthermore, if the attr is
926 * of the form <attr>=<value>*, then <value> is
927 * treated as a prefix, and the aci applies to
928 * any value with that prefix.
930 * Ideally, this would allow r.e. matches.
932 if (aci_get_part(&right, 0, '*', &left) < 0
933 || right.bv_len <= left.bv_len)
935 if (aci_strbvcmp(val->bv_val, &right) == 0)
937 } else if (val->bv_len >= left.bv_len) {
938 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
948 aci_list_get_attr_rights(
957 /* loop through each rights/attr pair, skip first part (action) */
959 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
960 if (aci_list_has_attr(&bv, attr, val) == 0)
962 if (aci_get_part(list, i, ';', &bv) < 0)
964 mask |= aci_list_map_rights(&bv);
974 slap_access_t *grant,
975 slap_access_t *deny )
977 struct berval perm, actn;
981 if (attr == NULL || *attr == 0 || strcasecmp(attr, "entry") == 0) {
988 /* loop through each permissions clause */
989 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
990 if (aci_get_part(&perm, 0, ';', &actn) < 0)
992 if (aci_strbvcmp( "grant", &actn ) == 0) {
994 } else if (aci_strbvcmp( "deny", &actn ) == 0) {
1001 *mask |= aci_list_get_attr_rights(&perm, attr, val);
1002 *mask |= aci_list_get_attr_rights(&perm, "[all]", NULL);
1009 struct berval *subj,
1010 const char *defgrpoc,
1011 const char *defgrpat,
1019 char *subjdn, *grpdn = NULL;
1022 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1023 ObjectClass *grp_oc = NULL;
1024 AttributeDescription *grp_ad = NULL;
1032 /* format of string is "group/objectClassValue/groupAttrName" */
1033 if (aci_get_part(subj, 0, '/', &bv) < 0) {
1037 subjdn = aci_bvstrdup(&bv);
1038 if (subjdn == NULL) {
1042 if (aci_get_part(subj, 1, '/', &bv) < 0) {
1043 grpoc = ch_strdup( defgrpoc );
1045 grpoc = aci_bvstrdup(&bv);
1048 if (aci_get_part(subj, 2, '/', &bv) < 0) {
1049 grpat = ch_strdup( defgrpat );
1051 grpat = aci_bvstrdup(&bv);
1054 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1055 rc = slap_str2ad( grpat, &grp_ad, &text );
1056 if( rc != LDAP_SUCCESS ) {
1065 grpdn = (char *)ch_malloc(1024);
1067 if (grp_oc != NULL && grp_ad != NULL && grpdn != NULL) {
1068 string_expand(grpdn, 1024, subjdn, e->e_ndn, matches);
1069 if ( dn_normalize(grpdn) != NULL ) {
1070 rc = (backend_group(be, e, grpdn, op->o_ndn, grp_oc, grp_ad) == 0);
1074 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1076 if( grp_ad != NULL ) ad_free( grp_ad, 1 );
1090 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1091 AttributeDescription *desc,
1097 regmatch_t *matches,
1098 slap_access_t *grant,
1102 struct berval bv, perms, sdn;
1105 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1109 /* parse an aci of the form:
1110 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1112 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1113 a full description of the format for this attribute.
1115 For now, this routine only supports scope=entry.
1118 /* check that the aci has all 5 components */
1119 if (aci_get_part(aci, 4, '#', NULL) < 0)
1122 /* check that the aci family is supported */
1123 if (aci_get_part(aci, 0, '#', &bv) < 0)
1126 /* check that the scope is "entry" */
1127 if (aci_get_part(aci, 1, '#', &bv) < 0
1128 || aci_strbvcmp( "entry", &bv ) != 0)
1133 /* get the list of permissions clauses, bail if empty */
1134 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1137 /* check if any permissions allow desired access */
1138 if (aci_list_get_rights(&perms, attr, val, grant, deny) == 0)
1141 /* see if we have a DN match */
1142 if (aci_get_part(aci, 3, '#', &bv) < 0)
1145 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1148 if (aci_strbvcmp( "access-id", &bv ) == 0) {
1149 subjdn = aci_bvstrdup(&sdn);
1153 if ( dn_normalize(subjdn) != NULL )
1154 if (strcasecmp(op->o_ndn, subjdn) != 0)
1160 if (aci_strbvcmp( "self", &bv ) == 0) {
1161 if (strcasecmp(op->o_ndn, e->e_ndn) == 0)
1164 } else if (aci_strbvcmp( "dnattr", &bv ) == 0) {
1165 char *dnattr = aci_bvstrdup(&sdn);
1166 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1168 AttributeDescription *ad = NULL;
1171 rc = slap_str2ad( dnattr, &ad, &text );
1174 if( rc != LDAP_SUCCESS ) {
1180 bv.bv_val = op->o_ndn;
1181 bv.bv_len = strlen( bv.bv_val );
1183 for(at = attrs_find( e->e_attrs, ad );
1185 at = attrs_find( at->a_next, ad ) )
1187 if (value_find( ad, at->a_vals, &bv) == 0 ) {
1198 at = attr_find( e->e_attrs, dnattr );
1202 bv.bv_val = op->o_ndn;
1203 bv.bv_len = strlen( bv.bv_val );
1205 if (value_find( at->a_vals, &bv, at->a_syntax, 3 ) == 0 )
1210 } else if (aci_strbvcmp( "group", &bv ) == 0) {
1211 if (aci_group_member(&sdn, SLAPD_GROUP_CLASS, SLAPD_GROUP_ATTR, be, e, op, matches))
1214 } else if (aci_strbvcmp( "role", &bv ) == 0) {
1215 if (aci_group_member(&sdn, SLAPD_ROLE_CLASS, SLAPD_ROLE_ATTR, be, e, op, matches))
1222 #endif /* SLAPD_ACI_ENABLED */
1230 regmatch_t *matches)
1239 bufsiz--; /* leave space for lone $ */
1242 for ( dp = newbuf, sp = pat; size < bufsiz && *sp ; sp++) {
1243 /* did we previously see a $ */
1248 } else if (*sp >= '0' && *sp <= '9' ) {
1255 i = matches[n].rm_so;
1256 l = matches[n].rm_eo;
1257 for ( ; size < 512 && i < l; size++, i++ ) {
1275 /* must have ended with a single $ */
1282 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %s\n", pat, 0, 0 );
1283 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", newbuf, 0, 0 );
1288 char *pat, /* pattern to expand and match against */
1289 char *str, /* string to match against pattern */
1290 char *buf, /* buffer with $N expansion variables */
1291 regmatch_t *matches /* offsets in buffer for $N expansion variables */
1298 if(str == NULL) str = "";
1300 string_expand(newbuf, sizeof(newbuf), pat, buf, matches);
1301 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
1303 regerror(rc, &re, error, sizeof(error));
1305 Debug( LDAP_DEBUG_TRACE,
1306 "compile( \"%s\", \"%s\") failed %s\n",
1311 rc = regexec(&re, str, 0, NULL, 0);
1314 Debug( LDAP_DEBUG_TRACE,
1315 "=> regex_matches: string: %s\n", str, 0, 0 );
1316 Debug( LDAP_DEBUG_TRACE,
1317 "=> regex_matches: rc: %d %s\n",
1318 rc, !rc ? "matches" : "no matches", 0 );