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
461 const char *desc = b->a_dn_at->ad_cname->bv_val;
463 const char *desc = b->a_dn_at;
466 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
469 bv.bv_val = op->o_ndn;
470 bv.bv_len = strlen( bv.bv_val );
472 /* see if asker is listed in dnattr */
473 #ifdef SLAPD_SCHEMA_NOT_COMPAT
474 for( at = attrs_find( e->e_attrs, b->a_dn_at );
476 at = attrs_find( e->e_attrs->a_next, b->a_dn_at ) )
478 if( value_find( b->a_dn_at, at->a_vals, &bv ) == 0 ) {
486 if ( b->a_dn_self && (val == NULL
487 || value_match( &match, b->a_dn_at,
488 b->a_dn_at->ad_type->sat_equality, val, &bv, &text ) )
494 } else if ( ! b->a_dn_self || val == NULL
495 || value_match( &match, b->a_dn_at,
496 b->a_dn_at->ad_type->sat_equality, val, &bv, &text )
503 /* see if asker is listed in dnattr */
504 if ( (at = attr_find( e->e_attrs, b->a_dn_at )) != NULL &&
505 value_find( at->a_vals, &bv, at->a_syntax, 3 ) == 0 )
507 if ( b->a_dn_self && (val == NULL
508 || value_cmp( &bv, val, at->a_syntax, 2 ) ) )
513 /* asker not listed in dnattr - check for self access */
514 } else if ( ! b->a_dn_self || val == NULL
515 || value_cmp( &bv, val, at->a_syntax, 2 ) != 0 )
522 if ( b->a_group_pat != NULL && op->o_ndn != NULL ) {
525 /* b->a_group is an unexpanded entry name, expanded it should be an
526 * entry with objectclass group* and we test to see if odn is one of
527 * the values in the attribute group
529 /* see if asker is listed in dnattr */
530 string_expand(buf, sizeof(buf), b->a_group_pat, e->e_ndn, matches);
531 if ( dn_normalize(buf) == NULL ) {
532 /* did not expand to a valid dn */
536 if (backend_group(be, e, buf, op->o_ndn,
537 b->a_group_oc, b->a_group_at) != 0)
543 #ifdef SLAPD_ACI_ENABLED
544 if ( b->a_aci_at != NULL ) {
546 slap_access_t grant, deny, tgrant, tdeny;
548 /* this case works different from the others above.
549 * since aci's themselves give permissions, we need
550 * to first check b->a_mask, the ACL's access level.
553 if( op->o_ndn == NULL || op->o_ndn[0] == '\0' ) {
557 if ( e->e_dn == NULL ) {
561 /* first check if the right being requested
562 * is allowed by the ACL clause.
564 if ( ! ACL_GRANT( b->a_mask, *mask ) ) {
568 /* get the aci attribute */
569 at = attr_find( e->e_attrs, b->a_aci_at );
574 /* start out with nothing granted, nothing denied */
578 /* the aci is an multi-valued attribute. The
579 * rights are determined by OR'ing the individual
580 * rights given by the acis.
582 for ( i = 0; at->a_vals[i] != NULL; i++ ) {
583 if (aci_mask( be, op,
584 e, desc, val, at->a_vals[i],
585 matches, &grant, &deny ) != 0)
592 /* remove anything that the ACL clause does not allow */
593 tgrant &= b->a_mask & ACL_PRIV_MASK;
594 tdeny &= ACL_PRIV_MASK;
596 /* see if we have anything to contribute */
597 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
601 /* this could be improved by changing acl_mask so that it can deal with
602 * by clauses that return grant/deny pairs. Right now, it does either
603 * additive or subtractive rights, but not both at the same time. So,
604 * we need to combine the grant/deny pair into a single rights mask in
605 * a smart way: if either grant or deny is "empty", then we use the
606 * opposite as is, otherwise we remove any denied rights from the grant
607 * rights mask and construct an additive mask.
609 if (ACL_IS_INVALID(tdeny)) {
610 modmask = tgrant | ACL_PRIV_ADDITIVE;
612 } else if (ACL_IS_INVALID(tgrant)) {
613 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
616 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
626 Debug( LDAP_DEBUG_ACL,
627 "<= acl_mask: [%d] applying %s (%s)\n",
628 i, accessmask2str( modmask, accessmaskbuf ),
629 b->a_type == ACL_CONTINUE
631 : b->a_type == ACL_BREAK
638 if( ACL_IS_ADDITIVE(modmask) ) {
640 ACL_PRIV_SET( *mask, modmask );
643 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
645 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
646 /* substract privs */
647 ACL_PRIV_CLR( *mask, modmask );
650 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
657 Debug( LDAP_DEBUG_ACL,
658 "<= acl_mask: [%d] mask: %s\n",
659 i, accessmask2str(*mask, accessmaskbuf), 0 );
661 if( b->a_type == ACL_CONTINUE ) {
664 } else if ( b->a_type == ACL_BREAK ) {
672 Debug( LDAP_DEBUG_ACL,
673 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
674 accessmask2str(*mask, accessmaskbuf), 0, 0 );
679 * acl_check_modlist - check access control on the given entry to see if
680 * it allows the given modifications by the user associated with op.
681 * returns 1 if mods allowed ok
696 assert( be != NULL );
698 /* short circuit root database access */
699 if ( be_isroot( be, op->o_ndn ) ) {
700 Debug( LDAP_DEBUG_ACL,
701 "<= acl_access_allowed: granted to database root\n",
706 /* use backend default access if no backend acls */
707 if( be != NULL && be->be_acl == NULL ) {
708 Debug( LDAP_DEBUG_ACL,
709 "=> access_allowed: backend default %s access %s to \"%s\"\n",
710 access2str( ACL_WRITE ),
711 be->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn );
713 return be->be_dfltaccess >= ACL_WRITE;
716 /* be is always non-NULL */
717 /* use global default access if no global acls */
718 } else if ( be == NULL && global_acl == NULL ) {
719 Debug( LDAP_DEBUG_ACL,
720 "=> access_allowed: global default %s access %s to \"%s\"\n",
721 access2str( ACL_WRITE ),
722 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn );
724 return global_default_access >= ACL_WRITE;
728 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
730 * no-user-modification operational attributes are ignored
731 * by ACL_WRITE checking as any found here are not provided
734 #ifdef SLAPD_SCHEMA_NOT_COMPAT
735 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
736 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
737 " modify access granted\n",
738 mlist->sml_desc->ad_cname->bv_val, 0, 0 );
742 if ( oc_check_op_no_usermod_attr( mlist->sml_type ) ) {
743 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
744 " modify access granted\n",
745 mlist->sml_type, 0, 0 );
750 switch ( mlist->sml_op ) {
751 case LDAP_MOD_REPLACE:
753 if ( mlist->sml_bvalues == NULL ) {
756 for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) {
757 if ( ! access_allowed( be, conn, op, e,
758 mlist->sml_desc, mlist->sml_bvalues[i], ACL_WRITE ) )
765 case LDAP_MOD_DELETE:
766 if ( mlist->sml_bvalues == NULL ) {
767 if ( ! access_allowed( be, conn, op, e,
768 mlist->sml_desc, NULL, ACL_WRITE ) )
774 for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) {
775 if ( ! access_allowed( be, conn, op, e,
776 mlist->sml_desc, mlist->sml_bvalues[i], ACL_WRITE ) )
788 #ifdef SLAPD_ACI_ENABLED
790 aci_bvstrdup( struct berval *bv )
794 s = (char *)ch_malloc(bv->bv_len + 1);
796 memcpy(s, bv->bv_val, bv->bv_len);
809 res = strncasecmp( s, bv->bv_val, bv->bv_len );
813 if (len > (int)bv->bv_len)
815 if (len < (int)bv->bv_len)
836 while (len >= 0 && --ix >= 0) {
837 while (--len >= 0 && *p++ != sep) ;
839 while (len >= 0 && *p == ' ') {
850 while (--len >= 0 && *p != sep) {
854 while (bv->bv_len > 0 && *--p == ' ')
861 struct berval *list )
868 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
871 switch (*bv.bv_val) {
873 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
876 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
877 * the right 's' to mean "set", but in the examples states
878 * that the right 's' means "search". The latter definition
881 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
884 ACL_PRIV_SET(mask, ACL_PRIV_READ);
887 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
890 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
891 * define any equivalent to the AUTH right, so I've just used
894 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
910 struct berval bv, left, right;
913 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
914 if (aci_get_part(&bv, 0, '=', &left) < 0
915 || aci_get_part(&bv, 1, '=', &right) < 0)
917 if (aci_strbvcmp(attr, &bv) == 0)
919 } else if (val == NULL) {
920 if (aci_strbvcmp(attr, &left) == 0)
923 if (aci_strbvcmp(attr, &left) == 0) {
924 /* this is experimental code that implements a
925 * simple (prefix) match of the attribute value.
926 * the ACI draft does not provide for aci's that
927 * apply to specific values, but it would be
928 * nice to have. If the <attr> part of an aci's
929 * rights list is of the form <attr>=<value>,
930 * that means the aci applies only to attrs with
931 * the given value. Furthermore, if the attr is
932 * of the form <attr>=<value>*, then <value> is
933 * treated as a prefix, and the aci applies to
934 * any value with that prefix.
936 * Ideally, this would allow r.e. matches.
938 if (aci_get_part(&right, 0, '*', &left) < 0
939 || right.bv_len <= left.bv_len)
941 if (aci_strbvcmp(val->bv_val, &right) == 0)
943 } else if (val->bv_len >= left.bv_len) {
944 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
954 aci_list_get_attr_rights(
963 /* loop through each rights/attr pair, skip first part (action) */
965 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
966 if (aci_list_has_attr(&bv, attr, val) == 0)
968 if (aci_get_part(list, i, ';', &bv) < 0)
970 mask |= aci_list_map_rights(&bv);
980 slap_access_t *grant,
981 slap_access_t *deny )
983 struct berval perm, actn;
987 if (attr == NULL || *attr == 0 || strcasecmp(attr, "entry") == 0) {
994 /* loop through each permissions clause */
995 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
996 if (aci_get_part(&perm, 0, ';', &actn) < 0)
998 if (aci_strbvcmp( "grant", &actn ) == 0) {
1000 } else if (aci_strbvcmp( "deny", &actn ) == 0) {
1007 *mask |= aci_list_get_attr_rights(&perm, attr, val);
1008 *mask |= aci_list_get_attr_rights(&perm, "[all]", NULL);
1015 struct berval *subj,
1016 const char *defgrpoc,
1017 const char *defgrpat,
1025 char *subjdn, *grpdn = NULL;
1028 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1029 ObjectClass *grp_oc = NULL;
1030 AttributeDescription *grp_ad = NULL;
1038 /* format of string is "group/objectClassValue/groupAttrName" */
1039 if (aci_get_part(subj, 0, '/', &bv) < 0) {
1043 subjdn = aci_bvstrdup(&bv);
1044 if (subjdn == NULL) {
1048 if (aci_get_part(subj, 1, '/', &bv) < 0) {
1049 grpoc = ch_strdup( defgrpoc );
1051 grpoc = aci_bvstrdup(&bv);
1054 if (aci_get_part(subj, 2, '/', &bv) < 0) {
1055 grpat = ch_strdup( defgrpat );
1057 grpat = aci_bvstrdup(&bv);
1060 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1061 rc = slap_str2ad( grpat, &grp_ad, &text );
1062 if( rc != LDAP_SUCCESS ) {
1071 grpdn = (char *)ch_malloc(1024);
1073 if (grp_oc != NULL && grp_ad != NULL && grpdn != NULL) {
1074 string_expand(grpdn, 1024, subjdn, e->e_ndn, matches);
1075 if ( dn_normalize(grpdn) != NULL ) {
1076 rc = (backend_group(be, e, grpdn, op->o_ndn, grp_oc, grp_ad) == 0);
1080 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1082 if( grp_ad != NULL ) ad_free( grp_ad, 1 );
1096 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1097 AttributeDescription *desc,
1103 regmatch_t *matches,
1104 slap_access_t *grant,
1108 struct berval bv, perms, sdn;
1111 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1115 /* parse an aci of the form:
1116 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1118 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1119 a full description of the format for this attribute.
1121 For now, this routine only supports scope=entry.
1124 /* check that the aci has all 5 components */
1125 if (aci_get_part(aci, 4, '#', NULL) < 0)
1128 /* check that the aci family is supported */
1129 if (aci_get_part(aci, 0, '#', &bv) < 0)
1131 for (i = 0; supportedACIMechs[i] != NULL; i++) {
1132 if (aci_strbvcmp( supportedACIMechs[i], &bv ) == 0)
1135 if (supportedACIMechs[i] == NULL)
1138 /* check that the scope is "entry" */
1139 if (aci_get_part(aci, 1, '#', &bv) < 0
1140 || aci_strbvcmp( "entry", &bv ) != 0)
1145 /* get the list of permissions clauses, bail if empty */
1146 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1149 /* check if any permissions allow desired access */
1150 if (aci_list_get_rights(&perms, attr, val, grant, deny) == 0)
1153 /* see if we have a DN match */
1154 if (aci_get_part(aci, 3, '#', &bv) < 0)
1157 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1160 if (aci_strbvcmp( "access-id", &bv ) == 0) {
1161 subjdn = aci_bvstrdup(&sdn);
1165 if ( dn_normalize(subjdn) != NULL )
1166 if (strcasecmp(op->o_ndn, subjdn) != 0)
1172 if (aci_strbvcmp( "self", &bv ) == 0) {
1173 if (strcasecmp(op->o_ndn, e->e_ndn) == 0)
1176 } else if (aci_strbvcmp( "dnattr", &bv ) == 0) {
1177 char *dnattr = aci_bvstrdup(&sdn);
1178 #ifdef SLAPD_SCHEMA_NOT_COMPAT
1180 AttributeDescription *ad = NULL;
1183 rc = slap_str2ad( dnattr, &ad, &text );
1186 if( rc != LDAP_SUCCESS ) {
1192 bv.bv_val = op->o_ndn;
1193 bv.bv_len = strlen( bv.bv_val );
1195 for(at = attrs_find( e->e_attrs, ad );
1197 at = attrs_find( at->a_next, ad ) )
1199 if (value_find( ad, at->a_vals, &bv) == 0 ) {
1210 at = attr_find( e->e_attrs, dnattr );
1214 bv.bv_val = op->o_ndn;
1215 bv.bv_len = strlen( bv.bv_val );
1217 if (value_find( at->a_vals, &bv, at->a_syntax, 3 ) == 0 )
1222 } else if (aci_strbvcmp( "group", &bv ) == 0) {
1223 if (aci_group_member(&sdn, SLAPD_GROUP_CLASS, SLAPD_GROUP_ATTR, be, e, op, matches))
1226 } else if (aci_strbvcmp( "role", &bv ) == 0) {
1227 if (aci_group_member(&sdn, SLAPD_ROLE_CLASS, SLAPD_ROLE_ATTR, be, e, op, matches))
1235 get_supported_acimech(
1238 if (index < 0 || index >= (sizeof(supportedACIMechs) / sizeof(char *)))
1240 return(supportedACIMechs[index]);
1243 #endif /* SLAPD_ACI_ENABLED */
1251 regmatch_t *matches)
1260 bufsiz--; /* leave space for lone $ */
1263 for ( dp = newbuf, sp = pat; size < bufsiz && *sp ; sp++) {
1264 /* did we previously see a $ */
1269 } else if (*sp >= '0' && *sp <= '9' ) {
1276 i = matches[n].rm_so;
1277 l = matches[n].rm_eo;
1278 for ( ; size < 512 && i < l; size++, i++ ) {
1296 /* must have ended with a single $ */
1303 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %s\n", pat, 0, 0 );
1304 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", newbuf, 0, 0 );
1309 char *pat, /* pattern to expand and match against */
1310 char *str, /* string to match against pattern */
1311 char *buf, /* buffer with $N expansion variables */
1312 regmatch_t *matches /* offsets in buffer for $N expansion variables */
1319 if(str == NULL) str = "";
1321 string_expand(newbuf, sizeof(newbuf), pat, buf, matches);
1322 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
1324 regerror(rc, &re, error, sizeof(error));
1326 Debug( LDAP_DEBUG_TRACE,
1327 "compile( \"%s\", \"%s\") failed %s\n",
1332 rc = regexec(&re, str, 0, NULL, 0);
1335 Debug( LDAP_DEBUG_TRACE,
1336 "=> regex_matches: string: %s\n", str, 0, 0 );
1337 Debug( LDAP_DEBUG_TRACE,
1338 "=> regex_matches: rc: %d %s\n",
1339 rc, !rc ? "matches" : "no matches", 0 );