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 );
57 char *supportedACIMechs[] = {
58 "1.3.6.1.4.1.4203.666.7.1", /* experimental IETF aci family */
59 "1.3.6.1.4.1.4203.666.7.2", /* experimental OpenLDAP aci family */
64 static int regex_matches(
65 char *pat, char *str, char *buf, regmatch_t *matches);
66 static void string_expand(
67 char *newbuf, int bufsiz, char *pattern,
68 char *match, regmatch_t *matches);
72 * access_allowed - check whether op->o_ndn is allowed the requested access
73 * to entry e, attribute attr, value val. if val is null, access to
74 * the whole attribute is assumed (all values).
76 * This routine loops through all access controls and calls
77 * acl_mask() on each applicable access control.
78 * The loop exits when a definitive answer is reached or
79 * or no more controls remain.
92 #ifdef SLAPD_SCHEMA_NOT_COMPAT
93 AttributeDescription *desc,
98 slap_access_t access )
103 char accessmaskbuf[ACCESSMASK_MAXLEN];
105 slap_access_mask_t mask;
106 slap_control_t control;
108 #ifdef SLAPD_SCHEMA_NOT_COMPAT
109 const char *attr = desc ? desc->ad_cname->bv_val : NULL;
111 const char *attr = desc;
114 regmatch_t matches[MAXREMATCHES];
116 Debug( LDAP_DEBUG_ACL,
117 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
118 access2str( access ),
121 assert( be != NULL );
123 assert( attr != NULL );
124 assert( access > ACL_NONE );
126 /* grant database root access */
127 if ( be != NULL && be_isroot( be, op->o_ndn ) ) {
128 Debug( LDAP_DEBUG_ACL,
129 "<= root access granted\n",
135 * no-user-modification operational attributes are ignored
136 * by ACL_WRITE checking as any found here are not provided
139 #ifdef SLAPD_SCHEMA_NOT_COMPAT
140 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type ) )
142 if ( access >= ACL_WRITE && oc_check_op_no_usermod_attr( attr ) )
145 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
146 " %s access granted\n",
151 /* use backend default access if no backend acls */
152 if( be != NULL && be->be_acl == NULL ) {
153 Debug( LDAP_DEBUG_ACL,
154 "=> access_allowed: backend default %s access %s to \"%s\"\n",
155 access2str( access ),
156 be->be_dfltaccess >= access ? "granted" : "denied", op->o_dn );
158 return be->be_dfltaccess >= access;
161 /* be is always non-NULL */
162 /* use global default access if no global acls */
163 } else if ( be == NULL && global_acl == NULL ) {
164 Debug( LDAP_DEBUG_ACL,
165 "=> access_allowed: global default %s access %s to \"%s\"\n",
166 access2str( access ),
167 global_default_access >= access ? "granted" : "denied", op->o_dn );
169 return global_default_access >= access;
174 memset(matches, 0, sizeof(matches));
180 while( a = acl_get( a, &count, be, op, e, desc, MAXREMATCHES, matches ) )
184 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
185 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
186 (int)matches[i].rm_so, (int)matches[i].rm_eo );
188 if( matches[i].rm_so <= matches[0].rm_eo ) {
190 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
191 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
194 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
197 control = acl_mask( a, &mask, be, conn, op,
198 e, desc, val, matches );
200 if ( control != ACL_BREAK ) {
204 memset(matches, 0, sizeof(matches));
207 if ( ACL_IS_INVALID( mask ) ) {
208 Debug( LDAP_DEBUG_ACL,
209 "=> access_allowed: \"%s\" (%s) invalid!\n",
213 } else if ( control == ACL_BREAK ) {
214 Debug( LDAP_DEBUG_ACL,
215 "=> access_allowed: no more rules\n", 0, 0, 0);
219 Debug( LDAP_DEBUG_ACL,
220 "=> access_allowed: %s access %s by %s\n",
221 access2str( access ),
222 ACL_GRANT(mask, access) ? "granted" : "denied",
223 accessmask2str( mask, accessmaskbuf ) );
225 return ACL_GRANT(mask, access);
229 * acl_get - return the acl applicable to entry e, attribute
230 * attr. the acl returned is suitable for use in subsequent calls to
231 * acl_access_allowed().
234 static AccessControl *
241 #ifdef SLAPD_SCHEMA_NOT_COMPAT
242 AttributeDescription *desc,
247 regmatch_t *matches )
251 assert( count != NULL );
253 #ifdef SLAPD_SCHEMA_NOT_COMPAT
254 attr = desc ? desc->ad_cname->bv_val : NULL;
272 for ( ; a != NULL; a = a->acl_next ) {
275 if (a->acl_dn_pat != NULL) {
276 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
277 *count, a->acl_dn_pat, (int) a->acl_dn_re.re_nsub );
279 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0)) {
283 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
288 if ( a->acl_filter != NULL ) {
289 ber_int_t rc = test_filter( NULL, NULL, NULL, e, a->acl_filter );
290 if ( rc != LDAP_COMPARE_TRUE ) {
295 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] check attr %s\n",
298 if ( attr == NULL || a->acl_attrs == NULL ||
299 ad_inlist( desc, a->acl_attrs ) )
301 Debug( LDAP_DEBUG_ACL,
302 "<= acl_get: [%d] acl %s attr: %s\n",
303 *count, e->e_dn, attr );
306 matches[0].rm_so = matches[0].rm_eo = -1;
309 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
315 * acl_mask - modifies mask based upon the given acl and the
316 * requested access to entry e, attribute attr, value val. if val
317 * is null, access to the whole attribute is assumed (all values).
319 * returns 0 access NOT allowed
323 static slap_control_t
326 slap_access_mask_t *mask,
331 #ifdef SLAPD_SCHEMA_NOT_COMPAT
332 AttributeDescription *desc,
343 char accessmaskbuf[ACCESSMASK_MAXLEN];
345 #ifdef SLAPD_SCHEMA_NOT_COMPAT
346 const char *attr = desc ? desc->ad_cname->bv_val : NULL;
348 const char *attr = desc;
352 assert( mask != NULL );
354 Debug( LDAP_DEBUG_ACL,
355 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
358 Debug( LDAP_DEBUG_ACL,
359 "=> acl_mask: to value \"%s\" by \"%s\", (%s) \n",
360 val ? val->bv_val : "*",
361 op->o_ndn ? op->o_ndn : "",
362 accessmask2str( *mask, accessmaskbuf ) );
364 for ( i = 1, b = a->acl_access; b != NULL; b = b->a_next, i++ ) {
365 slap_access_mask_t oldmask, modmask;
367 ACL_INVALIDATE( modmask );
369 /* AND <who> clauses */
370 if ( b->a_dn_pat != NULL ) {
371 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
374 * if access applies to the entry itself, and the
375 * user is bound as somebody in the same namespace as
376 * the entry, OR the given dn matches the dn pattern
378 if ( strcmp( b->a_dn_pat, "anonymous" ) == 0 ) {
379 if (op->o_ndn != NULL && op->o_ndn[0] != '\0' ) {
383 } else if ( strcmp( b->a_dn_pat, "users" ) == 0 ) {
384 if (op->o_ndn == NULL || op->o_ndn[0] == '\0' ) {
388 } else if ( strcmp( b->a_dn_pat, "self" ) == 0 ) {
389 if( op->o_ndn == NULL || op->o_ndn[0] == '\0' ) {
393 if ( e->e_dn == NULL || strcmp( e->e_ndn, op->o_ndn ) != 0 ) {
397 } else if ( strcmp( b->a_dn_pat, "*" ) != 0 ) {
398 int ret = regex_matches( b->a_dn_pat,
399 op->o_ndn, e->e_ndn, matches );
407 if ( b->a_sockurl_pat != NULL ) {
408 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
409 b->a_sockurl_pat, 0, 0 );
411 if ( strcmp( b->a_sockurl_pat, "*" ) != 0 &&
412 !regex_matches( b->a_sockurl_pat, conn->c_listener_url,
413 e->e_ndn, matches ) )
419 if ( b->a_domain_pat != NULL ) {
420 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
421 b->a_domain_pat, 0, 0 );
423 if ( strcmp( b->a_domain_pat, "*" ) != 0 &&
424 !regex_matches( b->a_domain_pat, conn->c_peer_domain,
425 e->e_ndn, matches ) )
431 if ( b->a_peername_pat != NULL ) {
432 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
433 b->a_peername_pat, 0, 0 );
435 if ( strcmp( b->a_peername_pat, "*" ) != 0 &&
436 !regex_matches( b->a_peername_pat, conn->c_peer_name,
437 e->e_ndn, matches ) )
443 if ( b->a_sockname_pat != NULL ) {
444 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
445 b->a_sockname_pat, 0, 0 );
447 if ( strcmp( b->a_sockname_pat, "*" ) != 0 &&
448 !regex_matches( b->a_sockname_pat, conn->c_sock_name,
449 e->e_ndn, matches ) )
455 if ( b->a_dn_at != NULL && op->o_ndn != NULL ) {
458 #ifdef SLAPD_SCHEMA_NOT_COMPAT
463 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
466 bv.bv_val = op->o_ndn;
467 bv.bv_len = strlen( bv.bv_val );
469 /* see if asker is listed in dnattr */
470 #ifdef SLAPD_SCHEMA_NOT_COMPAT
471 for( at = attrs_find( e->e_attrs, b->a_dn_at );
473 at = attrs_find( e->e_attrs->a_next, b->a_dn_at ) )
475 if( value_find( b->a_dn_at, at->a_vals, &bv ) == 0 ) {
483 if ( b->a_dn_self && (val == NULL
484 || value_match( &match, b->a_dn_at,
485 b->a_dn_at->ad_type->sat_equality, &bv, val, &text ) )
491 } else if ( ! b->a_dn_self || val == NULL
492 || value_match( &match, b->a_dn_at,
493 b->a_dn_at->ad_type->sat_equality, &bv, val, &text )
500 /* see if asker is listed in dnattr */
501 if ( (at = attr_find( e->e_attrs, b->a_dn_at )) != NULL &&
502 value_find( at->a_vals, &bv, at->a_syntax, 3 ) == 0 )
504 if ( b->a_dn_self && (val == NULL
505 || value_cmp( &bv, val, at->a_syntax, 2 ) ) )
510 /* asker not listed in dnattr - check for self access */
511 } else if ( ! b->a_dn_self || val == NULL
512 || value_cmp( &bv, val, at->a_syntax, 2 ) != 0 )
519 if ( b->a_group_pat != NULL && op->o_ndn != NULL ) {
522 /* b->a_group is an unexpanded entry name, expanded it should be an
523 * entry with objectclass group* and we test to see if odn is one of
524 * the values in the attribute group
526 /* see if asker is listed in dnattr */
527 string_expand(buf, sizeof(buf), b->a_group_pat, e->e_ndn, matches);
528 if ( dn_normalize(buf) == NULL ) {
529 /* did not expand to a valid dn */
533 if (backend_group(be, e, buf, op->o_ndn,
534 b->a_group_oc, b->a_group_at) != 0)
540 #ifdef SLAPD_ACI_ENABLED
541 if ( b->a_aci_at != NULL ) {
543 slap_access_t grant, deny, tgrant, tdeny;
545 /* this case works different from the others above.
546 * since aci's themselves give permissions, we need
547 * to first check b->a_mask, the ACL's access level.
550 if( op->o_ndn == NULL || op->o_ndn[0] == '\0' ) {
554 if ( e->e_dn == NULL ) {
558 /* first check if the right being requested
559 * is allowed by the ACL clause.
561 if ( ! ACL_GRANT( b->a_mask, *mask ) ) {
565 /* get the aci attribute */
566 at = attr_find( e->e_attrs, b->a_aci_at );
571 /* start out with nothing granted, nothing denied */
575 /* the aci is an multi-valued attribute. The
576 * rights are determined by OR'ing the individual
577 * rights given by the acis.
579 for ( i = 0; at->a_vals[i] != NULL; i++ ) {
580 if (aci_mask( be, op,
581 e, attr, val, at->a_vals[i],
582 matches, &grant, &deny ) != 0)
589 /* remove anything that the ACL clause does not allow */
590 tgrant &= b->a_mask & ACL_PRIV_MASK;
591 tdeny &= ACL_PRIV_MASK;
593 /* see if we have anything to contribute */
594 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
598 /* this could be improved by changing acl_mask so that it can deal with
599 * by clauses that return grant/deny pairs. Right now, it does either
600 * additive or subtractive rights, but not both at the same time. So,
601 * we need to combine the grant/deny pair into a single rights mask in
602 * a smart way: if either grant or deny is "empty", then we use the
603 * opposite as is, otherwise we remove any denied rights from the grant
604 * rights mask and construct an additive mask.
606 if (ACL_IS_INVALID(tdeny)) {
607 modmask = tgrant | ACL_PRIV_ADDITIVE;
609 } else if (ACL_IS_INVALID(tgrant)) {
610 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
613 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
623 Debug( LDAP_DEBUG_ACL,
624 "<= acl_mask: [%d] applying %s (%s)\n",
625 i, accessmask2str( modmask, accessmaskbuf ),
626 b->a_type == ACL_CONTINUE
628 : b->a_type == ACL_BREAK
635 if( ACL_IS_ADDITIVE(modmask) ) {
637 ACL_PRIV_SET( *mask, modmask );
640 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
642 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
643 /* substract privs */
644 ACL_PRIV_CLR( *mask, modmask );
647 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
654 Debug( LDAP_DEBUG_ACL,
655 "<= acl_mask: [%d] mask: %s\n",
656 i, accessmask2str(*mask, accessmaskbuf), 0 );
658 if( b->a_type == ACL_CONTINUE ) {
661 } else if ( b->a_type == ACL_BREAK ) {
669 Debug( LDAP_DEBUG_ACL,
670 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
671 accessmask2str(*mask, accessmaskbuf), 0, 0 );
676 * acl_check_modlist - check access control on the given entry to see if
677 * it allows the given modifications by the user associated with op.
678 * returns 1 if mods allowed ok
693 assert( be != NULL );
695 /* short circuit root database access */
696 if ( be_isroot( be, op->o_ndn ) ) {
697 Debug( LDAP_DEBUG_ACL,
698 "<= acl_access_allowed: granted to database root\n",
703 /* use backend default access if no backend acls */
704 if( be != NULL && be->be_acl == NULL ) {
705 Debug( LDAP_DEBUG_ACL,
706 "=> access_allowed: backend default %s access %s to \"%s\"\n",
707 access2str( ACL_WRITE ),
708 be->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn );
710 return be->be_dfltaccess >= ACL_WRITE;
713 /* be is always non-NULL */
714 /* use global default access if no global acls */
715 } else if ( be == NULL && global_acl == NULL ) {
716 Debug( LDAP_DEBUG_ACL,
717 "=> access_allowed: global default %s access %s to \"%s\"\n",
718 access2str( ACL_WRITE ),
719 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn );
721 return global_default_access >= ACL_WRITE;
725 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
727 * no-user-modification operational attributes are ignored
728 * by ACL_WRITE checking as any found here are not provided
731 #ifdef SLAPD_SCHEMA_NOT_COMPAT
732 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
733 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
734 " modify access granted\n",
735 mlist->sml_desc->ad_cname->bv_val, 0, 0 );
739 if ( oc_check_op_no_usermod_attr( mlist->sml_type ) ) {
740 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
741 " modify access granted\n",
742 mlist->sml_type, 0, 0 );
747 switch ( mlist->sml_op ) {
748 case LDAP_MOD_REPLACE:
750 if ( mlist->sml_bvalues == NULL ) {
753 for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) {
754 if ( ! access_allowed( be, conn, op, e,
755 mlist->sml_desc, mlist->sml_bvalues[i], ACL_WRITE ) )
762 case LDAP_MOD_DELETE:
763 if ( mlist->sml_bvalues == NULL ) {
764 if ( ! access_allowed( be, conn, op, e,
765 mlist->sml_desc, NULL, ACL_WRITE ) )
771 for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) {
772 if ( ! access_allowed( be, conn, op, e,
773 mlist->sml_desc, mlist->sml_bvalues[i], ACL_WRITE ) )
785 #ifdef SLAPD_ACI_ENABLED
787 aci_bvstrdup( struct berval *bv )
791 s = (char *)ch_malloc(bv->bv_len + 1);
793 memcpy(s, bv->bv_val, bv->bv_len);
806 res = strncasecmp( s, bv->bv_val, bv->bv_len );
810 if (len > (int)bv->bv_len)
812 if (len < (int)bv->bv_len)
833 while (len >= 0 && --ix >= 0) {
834 while (--len >= 0 && *p++ != sep) ;
836 while (len >= 0 && *p == ' ') {
847 while (--len >= 0 && *p != sep) {
851 while (bv->bv_len > 0 && *--p == ' ')
858 struct berval *list )
865 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
868 switch (*bv.bv_val) {
870 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
873 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
874 * the right 's' to mean "set", but in the examples states
875 * that the right 's' means "search". The latter definition
878 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
881 ACL_PRIV_SET(mask, ACL_PRIV_READ);
884 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
887 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
888 * define any equivalent to the AUTH right, so I've just used
891 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
907 struct berval bv, left, right;
910 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
911 if (aci_get_part(&bv, 0, '=', &left) < 0
912 || aci_get_part(&bv, 1, '=', &right) < 0)
914 if (aci_strbvcmp(attr, &bv) == 0)
916 } else if (val == NULL) {
917 if (aci_strbvcmp(attr, &left) == 0)
920 if (aci_strbvcmp(attr, &left) == 0) {
921 /* this is experimental code that implements a
922 * simple (prefix) match of the attribute value.
923 * the ACI draft does not provide for aci's that
924 * apply to specific values, but it would be
925 * nice to have. If the <attr> part of an aci's
926 * rights list is of the form <attr>=<value>,
927 * that means the aci applies only to attrs with
928 * the given value. Furthermore, if the attr is
929 * of the form <attr>=<value>*, then <value> is
930 * treated as a prefix, and the aci applies to
931 * any value with that prefix.
933 * Ideally, this would allow r.e. matches.
935 if (aci_get_part(&right, 0, '*', &left) < 0
936 || right.bv_len <= left.bv_len)
938 if (aci_strbvcmp(val->bv_val, &right) == 0)
940 } else if (val->bv_len >= left.bv_len) {
941 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
951 aci_list_get_attr_rights(
960 /* loop through each rights/attr pair, skip first part (action) */
962 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
963 if (aci_list_has_attr(&bv, attr, val) == 0)
965 if (aci_get_part(list, i, ';', &bv) < 0)
967 mask |= aci_list_map_rights(&bv);
977 slap_access_t *grant,
978 slap_access_t *deny )
980 struct berval perm, actn;
984 if (attr == NULL || *attr == 0 || strcasecmp(attr, "entry") == 0) {
991 /* loop through each permissions clause */
992 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
993 if (aci_get_part(&perm, 0, ';', &actn) < 0)
995 if (aci_strbvcmp( "grant", &actn ) == 0) {
997 } else if (aci_strbvcmp( "deny", &actn ) == 0) {
1004 *mask |= aci_list_get_attr_rights(&perm, attr, val);
1005 *mask |= aci_list_get_attr_rights(&perm, "[all]", NULL);
1012 struct berval *subj,
1013 const char *defgrpoc,
1014 const char *defgrpat,
1022 char *subjdn, *grpdn = NULL;
1025 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1026 ObjectClass *grp_oc = NULL;
1027 AttributeDescription *grp_ad = NULL;
1035 /* format of string is "group/objectClassValue/groupAttrName" */
1036 if (aci_get_part(subj, 0, '/', &bv) < 0) {
1040 subjdn = aci_bvstrdup(&bv);
1041 if (subjdn == NULL) {
1045 if (aci_get_part(subj, 1, '/', &bv) < 0) {
1046 grpoc = ch_strdup( defgrpoc );
1048 grpoc = aci_bvstrdup(&bv);
1051 if (aci_get_part(subj, 2, '/', &bv) < 0) {
1052 grpat = ch_strdup( defgrpat );
1054 grpat = aci_bvstrdup(&bv);
1057 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1058 rc = slap_str2ad( grpat, &grp_ad, &text );
1059 if( rc != LDAP_SUCCESS ) {
1068 grpdn = (char *)ch_malloc(1024);
1070 if (grp_oc != NULL && grp_ad != NULL && grpdn != NULL) {
1071 string_expand(grpdn, 1024, subjdn, e->e_ndn, matches);
1072 if ( dn_normalize(grpdn) != NULL ) {
1073 rc = (backend_group(be, e, grpdn, op->o_ndn, grp_oc, grp_ad) == 0);
1077 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1079 if( grp_ad != NULL ) ad_free( grp_ad, 1 );
1093 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1094 AttributeDescription *desc,
1100 regmatch_t *matches,
1101 slap_access_t *grant,
1105 struct berval bv, perms, sdn;
1108 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1112 /* parse an aci of the form:
1113 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1115 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1116 a full description of the format for this attribute.
1118 For now, this routine only supports scope=entry.
1121 /* check that the aci has all 5 components */
1122 if (aci_get_part(aci, 4, '#', NULL) < 0)
1125 /* check that the aci family is supported */
1126 if (aci_get_part(aci, 0, '#', &bv) < 0)
1128 for (i = 0; supportedACIMechs[i] != NULL; i++) {
1129 if (aci_strbvcmp( supportedACIMechs[i], &bv ) == 0)
1132 if (supportedACIMechs[i] == NULL)
1135 /* check that the scope is "entry" */
1136 if (aci_get_part(aci, 1, '#', &bv) < 0
1137 || aci_strbvcmp( "entry", &bv ) != 0)
1142 /* get the list of permissions clauses, bail if empty */
1143 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1146 /* check if any permissions allow desired access */
1147 if (aci_list_get_rights(&perms, attr, val, grant, deny) == 0)
1150 /* see if we have a DN match */
1151 if (aci_get_part(aci, 3, '#', &bv) < 0)
1154 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1157 if (aci_strbvcmp( "access-id", &bv ) == 0) {
1158 subjdn = aci_bvstrdup(&sdn);
1162 if ( dn_normalize(subjdn) != NULL )
1163 if (strcasecmp(op->o_ndn, subjdn) != 0)
1169 if (aci_strbvcmp( "self", &bv ) == 0) {
1170 if (strcasecmp(op->o_ndn, e->e_ndn) == 0)
1173 } else if (aci_strbvcmp( "dnattr", &bv ) == 0) {
1174 char *dnattr = aci_bvstrdup(&sdn);
1175 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1177 AttributeDescription *ad = NULL;
1180 rc = slap_str2ad( dnattr, &ad, &text );
1183 if( rc != LDAP_SUCCESS ) {
1189 bv.bv_val = op->o_ndn;
1190 bv.bv_len = strlen( bv.bv_val );
1192 for(at = attrs_find( e->e_attrs, ad );
1194 at = attrs_find( at->a_next, ad ) )
1196 if (value_find( ad, at->a_vals, &bv) == 0 ) {
1207 at = attr_find( e->e_attrs, dnattr );
1211 bv.bv_val = op->o_ndn;
1212 bv.bv_len = strlen( bv.bv_val );
1214 if (value_find( at->a_vals, &bv, at->a_syntax, 3 ) == 0 )
1219 } else if (aci_strbvcmp( "group", &bv ) == 0) {
1220 if (aci_group_member(&sdn, SLAPD_GROUP_CLASS, SLAPD_GROUP_ATTR, be, e, op, matches))
1223 } else if (aci_strbvcmp( "role", &bv ) == 0) {
1224 if (aci_group_member(&sdn, SLAPD_ROLE_CLASS, SLAPD_ROLE_ATTR, be, e, op, matches))
1232 get_supported_acimech(
1235 if (index < 0 || index >= (sizeof(supportedACIMechs) / sizeof(char *)))
1237 return(supportedACIMechs[index]);
1240 #endif /* SLAPD_ACI_ENABLED */
1248 regmatch_t *matches)
1257 bufsiz--; /* leave space for lone $ */
1260 for ( dp = newbuf, sp = pat; size < bufsiz && *sp ; sp++) {
1261 /* did we previously see a $ */
1266 } else if (*sp >= '0' && *sp <= '9' ) {
1273 i = matches[n].rm_so;
1274 l = matches[n].rm_eo;
1275 for ( ; size < 512 && i < l; size++, i++ ) {
1293 /* must have ended with a single $ */
1300 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %s\n", pat, 0, 0 );
1301 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", newbuf, 0, 0 );
1306 char *pat, /* pattern to expand and match against */
1307 char *str, /* string to match against pattern */
1308 char *buf, /* buffer with $N expansion variables */
1309 regmatch_t *matches /* offsets in buffer for $N expansion variables */
1316 if(str == NULL) str = "";
1318 string_expand(newbuf, sizeof(newbuf), pat, buf, matches);
1319 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
1321 regerror(rc, &re, error, sizeof(error));
1323 Debug( LDAP_DEBUG_TRACE,
1324 "compile( \"%s\", \"%s\") failed %s\n",
1329 rc = regexec(&re, str, 0, NULL, 0);
1332 Debug( LDAP_DEBUG_TRACE,
1333 "=> regex_matches: string: %s\n", str, 0, 0 );
1334 Debug( LDAP_DEBUG_TRACE,
1335 "=> regex_matches: rc: %d %s\n",
1336 rc, !rc ? "matches" : "no matches", 0 );