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 AttributeDescription *desc,
23 int nmatches, regmatch_t *matches );
25 static slap_control_t acl_mask(
26 AccessControl *ac, slap_access_mask_t *mask,
27 Backend *be, Connection *conn, Operation *op,
29 AttributeDescription *desc,
31 regmatch_t *matches );
33 #ifdef SLAPD_ACI_ENABLED
38 AttributeDescription *desc,
43 slap_access_t *deny );
46 static int regex_matches(
47 char *pat, char *str, char *buf, regmatch_t *matches);
48 static void string_expand(
49 char *newbuf, int bufsiz, char *pattern,
50 char *match, regmatch_t *matches);
54 * access_allowed - check whether op->o_ndn is allowed the requested access
55 * to entry e, attribute attr, value val. if val is null, access to
56 * the whole attribute is assumed (all values).
58 * This routine loops through all access controls and calls
59 * acl_mask() on each applicable access control.
60 * The loop exits when a definitive answer is reached or
61 * or no more controls remain.
74 AttributeDescription *desc,
76 slap_access_t access )
81 char accessmaskbuf[ACCESSMASK_MAXLEN];
83 slap_access_mask_t mask;
84 slap_control_t control;
86 const char *attr = desc ? desc->ad_cname->bv_val : NULL;
88 regmatch_t matches[MAXREMATCHES];
90 Debug( LDAP_DEBUG_ACL,
91 "=> access_allowed: %s access to \"%s\" \"%s\" requested\n",
97 assert( attr != NULL );
98 assert( access > ACL_NONE );
100 /* grant database root access */
101 if ( be != NULL && be_isroot( be, op->o_ndn ) ) {
102 Debug( LDAP_DEBUG_ACL,
103 "<= root access granted\n",
109 * no-user-modification operational attributes are ignored
110 * by ACL_WRITE checking as any found here are not provided
113 if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type ) )
115 Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
116 " %s access granted\n",
121 /* use backend default access if no backend acls */
122 if( be != NULL && be->be_acl == NULL ) {
123 Debug( LDAP_DEBUG_ACL,
124 "=> access_allowed: backend default %s access %s to \"%s\"\n",
125 access2str( access ),
126 be->be_dfltaccess >= access ? "granted" : "denied", op->o_dn );
128 return be->be_dfltaccess >= access;
131 /* be is always non-NULL */
132 /* use global default access if no global acls */
133 } else if ( be == NULL && global_acl == NULL ) {
134 Debug( LDAP_DEBUG_ACL,
135 "=> access_allowed: global default %s access %s to \"%s\"\n",
136 access2str( access ),
137 global_default_access >= access ? "granted" : "denied", op->o_dn );
139 return global_default_access >= access;
144 memset(matches, 0, sizeof(matches));
150 while( a = acl_get( a, &count, be, op, e, desc, MAXREMATCHES, matches ) )
154 for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
155 Debug( LDAP_DEBUG_ACL, "=> match[%d]: %d %d ", i,
156 (int)matches[i].rm_so, (int)matches[i].rm_eo );
158 if( matches[i].rm_so <= matches[0].rm_eo ) {
160 for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
161 Debug( LDAP_DEBUG_ACL, "%c", e->e_ndn[n], 0, 0 );
164 Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
167 control = acl_mask( a, &mask, be, conn, op,
168 e, desc, val, matches );
170 if ( control != ACL_BREAK ) {
174 memset(matches, 0, sizeof(matches));
177 if ( ACL_IS_INVALID( mask ) ) {
178 Debug( LDAP_DEBUG_ACL,
179 "=> access_allowed: \"%s\" (%s) invalid!\n",
183 } else if ( control == ACL_BREAK ) {
184 Debug( LDAP_DEBUG_ACL,
185 "=> access_allowed: no more rules\n", 0, 0, 0);
189 Debug( LDAP_DEBUG_ACL,
190 "=> access_allowed: %s access %s by %s\n",
191 access2str( access ),
192 ACL_GRANT(mask, access) ? "granted" : "denied",
193 accessmask2str( mask, accessmaskbuf ) );
195 return ACL_GRANT(mask, access);
199 * acl_get - return the acl applicable to entry e, attribute
200 * attr. the acl returned is suitable for use in subsequent calls to
201 * acl_access_allowed().
204 static AccessControl *
211 AttributeDescription *desc,
213 regmatch_t *matches )
217 assert( count != NULL );
219 attr = desc ? desc->ad_cname->bv_val : NULL;
234 for ( ; a != NULL; a = a->acl_next ) {
237 if (a->acl_dn_pat != NULL) {
238 Debug( LDAP_DEBUG_ACL, "=> dnpat: [%d] %s nsub: %d\n",
239 *count, a->acl_dn_pat, (int) a->acl_dn_re.re_nsub );
241 if (regexec(&a->acl_dn_re, e->e_ndn, nmatch, matches, 0)) {
245 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] matched\n",
250 if ( a->acl_filter != NULL ) {
251 ber_int_t rc = test_filter( NULL, NULL, NULL, e, a->acl_filter );
252 if ( rc != LDAP_COMPARE_TRUE ) {
257 Debug( LDAP_DEBUG_ACL, "=> acl_get: [%d] check attr %s\n",
260 if ( attr == NULL || a->acl_attrs == NULL ||
261 ad_inlist( desc, a->acl_attrs ) )
263 Debug( LDAP_DEBUG_ACL,
264 "<= acl_get: [%d] acl %s attr: %s\n",
265 *count, e->e_dn, attr );
268 matches[0].rm_so = matches[0].rm_eo = -1;
271 Debug( LDAP_DEBUG_ACL, "<= acl_get: done.\n", 0, 0, 0 );
277 * acl_mask - modifies mask based upon the given acl and the
278 * requested access to entry e, attribute attr, value val. if val
279 * is null, access to the whole attribute is assumed (all values).
281 * returns 0 access NOT allowed
285 static slap_control_t
288 slap_access_mask_t *mask,
293 AttributeDescription *desc,
301 char accessmaskbuf[ACCESSMASK_MAXLEN];
303 const char *attr = desc ? desc->ad_cname->bv_val : NULL;
306 assert( mask != NULL );
308 Debug( LDAP_DEBUG_ACL,
309 "=> acl_mask: access to entry \"%s\", attr \"%s\" requested\n",
312 Debug( LDAP_DEBUG_ACL,
313 "=> acl_mask: to value \"%s\" by \"%s\", (%s) \n",
314 val ? val->bv_val : "*",
315 op->o_ndn ? op->o_ndn : "",
316 accessmask2str( *mask, accessmaskbuf ) );
318 for ( i = 1, b = a->acl_access; b != NULL; b = b->a_next, i++ ) {
319 slap_access_mask_t oldmask, modmask;
321 ACL_INVALIDATE( modmask );
323 /* AND <who> clauses */
324 if ( b->a_dn_pat != NULL ) {
325 Debug( LDAP_DEBUG_ACL, "<= check a_dn_pat: %s\n",
328 * if access applies to the entry itself, and the
329 * user is bound as somebody in the same namespace as
330 * the entry, OR the given dn matches the dn pattern
332 if ( strcmp( b->a_dn_pat, "anonymous" ) == 0 ) {
333 if (op->o_ndn != NULL && op->o_ndn[0] != '\0' ) {
337 } else if ( strcmp( b->a_dn_pat, "users" ) == 0 ) {
338 if (op->o_ndn == NULL || op->o_ndn[0] == '\0' ) {
342 } else if ( strcmp( b->a_dn_pat, "self" ) == 0 ) {
343 if( op->o_ndn == NULL || op->o_ndn[0] == '\0' ) {
347 if ( e->e_dn == NULL || strcmp( e->e_ndn, op->o_ndn ) != 0 ) {
351 } else if ( strcmp( b->a_dn_pat, "*" ) != 0 ) {
352 int ret = regex_matches( b->a_dn_pat,
353 op->o_ndn, e->e_ndn, matches );
361 if ( b->a_sockurl_pat != NULL ) {
362 Debug( LDAP_DEBUG_ACL, "<= check a_sockurl_pat: %s\n",
363 b->a_sockurl_pat, 0, 0 );
365 if ( strcmp( b->a_sockurl_pat, "*" ) != 0 &&
366 !regex_matches( b->a_sockurl_pat, conn->c_listener_url,
367 e->e_ndn, matches ) )
373 if ( b->a_domain_pat != NULL ) {
374 Debug( LDAP_DEBUG_ACL, "<= check a_domain_pat: %s\n",
375 b->a_domain_pat, 0, 0 );
377 if ( strcmp( b->a_domain_pat, "*" ) != 0 &&
378 !regex_matches( b->a_domain_pat, conn->c_peer_domain,
379 e->e_ndn, matches ) )
385 if ( b->a_peername_pat != NULL ) {
386 Debug( LDAP_DEBUG_ACL, "<= check a_peername_path: %s\n",
387 b->a_peername_pat, 0, 0 );
389 if ( strcmp( b->a_peername_pat, "*" ) != 0 &&
390 !regex_matches( b->a_peername_pat, conn->c_peer_name,
391 e->e_ndn, matches ) )
397 if ( b->a_sockname_pat != NULL ) {
398 Debug( LDAP_DEBUG_ACL, "<= check a_sockname_path: %s\n",
399 b->a_sockname_pat, 0, 0 );
401 if ( strcmp( b->a_sockname_pat, "*" ) != 0 &&
402 !regex_matches( b->a_sockname_pat, conn->c_sock_name,
403 e->e_ndn, matches ) )
409 if ( b->a_dn_at != NULL && op->o_ndn != NULL ) {
414 const char *desc = b->a_dn_at->ad_cname->bv_val;
416 Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
419 bv.bv_val = op->o_ndn;
420 bv.bv_len = strlen( bv.bv_val );
422 /* see if asker is listed in dnattr */
423 for( at = attrs_find( e->e_attrs, b->a_dn_at );
425 at = attrs_find( e->e_attrs->a_next, b->a_dn_at ) )
427 if( value_find( b->a_dn_at, at->a_vals, &bv ) == 0 ) {
435 if ( b->a_dn_self && (val == NULL
436 || value_match( &match, b->a_dn_at,
437 b->a_dn_at->ad_type->sat_equality, val, &bv, &text ) )
443 } else if ( ! b->a_dn_self || val == NULL
444 || value_match( &match, b->a_dn_at,
445 b->a_dn_at->ad_type->sat_equality, val, &bv, &text )
453 if ( b->a_group_pat != NULL && op->o_ndn != NULL ) {
456 /* b->a_group is an unexpanded entry name, expanded it should be an
457 * entry with objectclass group* and we test to see if odn is one of
458 * the values in the attribute group
460 /* see if asker is listed in dnattr */
461 string_expand(buf, sizeof(buf), b->a_group_pat, e->e_ndn, matches);
462 if ( dn_normalize(buf) == NULL ) {
463 /* did not expand to a valid dn */
467 if (backend_group(be, e, buf, op->o_ndn,
468 b->a_group_oc, b->a_group_at) != 0)
474 #ifdef SLAPD_ACI_ENABLED
475 if ( b->a_aci_at != NULL ) {
477 slap_access_t grant, deny, tgrant, tdeny;
479 /* this case works different from the others above.
480 * since aci's themselves give permissions, we need
481 * to first check b->a_mask, the ACL's access level.
484 if( op->o_ndn == NULL || op->o_ndn[0] == '\0' ) {
488 if ( e->e_dn == NULL ) {
492 /* first check if the right being requested
493 * is allowed by the ACL clause.
495 if ( ! ACL_GRANT( b->a_mask, *mask ) ) {
499 /* get the aci attribute */
500 at = attr_find( e->e_attrs, b->a_aci_at );
505 /* start out with nothing granted, nothing denied */
509 /* the aci is an multi-valued attribute. The
510 * rights are determined by OR'ing the individual
511 * rights given by the acis.
513 for ( i = 0; at->a_vals[i] != NULL; i++ ) {
514 if (aci_mask( be, op,
515 e, desc, val, at->a_vals[i],
516 matches, &grant, &deny ) != 0)
523 /* remove anything that the ACL clause does not allow */
524 tgrant &= b->a_mask & ACL_PRIV_MASK;
525 tdeny &= ACL_PRIV_MASK;
527 /* see if we have anything to contribute */
528 if( ACL_IS_INVALID(tgrant) && ACL_IS_INVALID(tdeny) ) {
532 /* this could be improved by changing acl_mask so that it can deal with
533 * by clauses that return grant/deny pairs. Right now, it does either
534 * additive or subtractive rights, but not both at the same time. So,
535 * we need to combine the grant/deny pair into a single rights mask in
536 * a smart way: if either grant or deny is "empty", then we use the
537 * opposite as is, otherwise we remove any denied rights from the grant
538 * rights mask and construct an additive mask.
540 if (ACL_IS_INVALID(tdeny)) {
541 modmask = tgrant | ACL_PRIV_ADDITIVE;
543 } else if (ACL_IS_INVALID(tgrant)) {
544 modmask = tdeny | ACL_PRIV_SUBSTRACTIVE;
547 modmask = (tgrant & ~tdeny) | ACL_PRIV_ADDITIVE;
557 Debug( LDAP_DEBUG_ACL,
558 "<= acl_mask: [%d] applying %s (%s)\n",
559 i, accessmask2str( modmask, accessmaskbuf ),
560 b->a_type == ACL_CONTINUE
562 : b->a_type == ACL_BREAK
569 if( ACL_IS_ADDITIVE(modmask) ) {
571 ACL_PRIV_SET( *mask, modmask );
574 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
576 } else if( ACL_IS_SUBTRACTIVE(modmask) ) {
577 /* substract privs */
578 ACL_PRIV_CLR( *mask, modmask );
581 ACL_PRIV_CLR( *mask, ~ACL_PRIV_MASK );
588 Debug( LDAP_DEBUG_ACL,
589 "<= acl_mask: [%d] mask: %s\n",
590 i, accessmask2str(*mask, accessmaskbuf), 0 );
592 if( b->a_type == ACL_CONTINUE ) {
595 } else if ( b->a_type == ACL_BREAK ) {
603 Debug( LDAP_DEBUG_ACL,
604 "<= acl_mask: no more <who> clauses, returning %s (stop)\n",
605 accessmask2str(*mask, accessmaskbuf), 0, 0 );
610 * acl_check_modlist - check access control on the given entry to see if
611 * it allows the given modifications by the user associated with op.
612 * returns 1 if mods allowed ok
627 assert( be != NULL );
629 /* short circuit root database access */
630 if ( be_isroot( be, op->o_ndn ) ) {
631 Debug( LDAP_DEBUG_ACL,
632 "<= acl_access_allowed: granted to database root\n",
637 /* use backend default access if no backend acls */
638 if( be != NULL && be->be_acl == NULL ) {
639 Debug( LDAP_DEBUG_ACL,
640 "=> access_allowed: backend default %s access %s to \"%s\"\n",
641 access2str( ACL_WRITE ),
642 be->be_dfltaccess >= ACL_WRITE ? "granted" : "denied", op->o_dn );
644 return be->be_dfltaccess >= ACL_WRITE;
647 /* be is always non-NULL */
648 /* use global default access if no global acls */
649 } else if ( be == NULL && global_acl == NULL ) {
650 Debug( LDAP_DEBUG_ACL,
651 "=> access_allowed: global default %s access %s to \"%s\"\n",
652 access2str( ACL_WRITE ),
653 global_default_access >= ACL_WRITE ? "granted" : "denied", op->o_dn );
655 return global_default_access >= ACL_WRITE;
659 for ( ; mlist != NULL; mlist = mlist->sml_next ) {
661 * no-user-modification operational attributes are ignored
662 * by ACL_WRITE checking as any found here are not provided
665 if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
666 Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
667 " modify access granted\n",
668 mlist->sml_desc->ad_cname->bv_val, 0, 0 );
672 switch ( mlist->sml_op ) {
673 case LDAP_MOD_REPLACE:
675 if ( mlist->sml_bvalues == NULL ) {
678 for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) {
679 if ( ! access_allowed( be, conn, op, e,
680 mlist->sml_desc, mlist->sml_bvalues[i], ACL_WRITE ) )
687 case LDAP_MOD_DELETE:
688 if ( mlist->sml_bvalues == NULL ) {
689 if ( ! access_allowed( be, conn, op, e,
690 mlist->sml_desc, NULL, ACL_WRITE ) )
696 for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) {
697 if ( ! access_allowed( be, conn, op, e,
698 mlist->sml_desc, mlist->sml_bvalues[i], ACL_WRITE ) )
710 #ifdef SLAPD_ACI_ENABLED
712 aci_bvstrdup( struct berval *bv )
716 s = (char *)ch_malloc(bv->bv_len + 1);
718 memcpy(s, bv->bv_val, bv->bv_len);
731 res = strncasecmp( s, bv->bv_val, bv->bv_len );
735 if (len > (int)bv->bv_len)
737 if (len < (int)bv->bv_len)
758 while (len >= 0 && --ix >= 0) {
759 while (--len >= 0 && *p++ != sep) ;
761 while (len >= 0 && *p == ' ') {
772 while (--len >= 0 && *p != sep) {
776 while (bv->bv_len > 0 && *--p == ' ')
783 struct berval *list )
790 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
793 switch (*bv.bv_val) {
795 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
798 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt defines
799 * the right 's' to mean "set", but in the examples states
800 * that the right 's' means "search". The latter definition
803 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
806 ACL_PRIV_SET(mask, ACL_PRIV_READ);
809 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
812 /* **** NOTE: draft-ietf-ldapext-aci-model-0.3.txt does not
813 * define any equivalent to the AUTH right, so I've just used
816 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
832 struct berval bv, left, right;
835 for (i = 0; aci_get_part(list, i, ',', &bv) >= 0; i++) {
836 if (aci_get_part(&bv, 0, '=', &left) < 0
837 || aci_get_part(&bv, 1, '=', &right) < 0)
839 if (aci_strbvcmp(attr, &bv) == 0)
841 } else if (val == NULL) {
842 if (aci_strbvcmp(attr, &left) == 0)
845 if (aci_strbvcmp(attr, &left) == 0) {
846 /* this is experimental code that implements a
847 * simple (prefix) match of the attribute value.
848 * the ACI draft does not provide for aci's that
849 * apply to specific values, but it would be
850 * nice to have. If the <attr> part of an aci's
851 * rights list is of the form <attr>=<value>,
852 * that means the aci applies only to attrs with
853 * the given value. Furthermore, if the attr is
854 * of the form <attr>=<value>*, then <value> is
855 * treated as a prefix, and the aci applies to
856 * any value with that prefix.
858 * Ideally, this would allow r.e. matches.
860 if (aci_get_part(&right, 0, '*', &left) < 0
861 || right.bv_len <= left.bv_len)
863 if (aci_strbvcmp(val->bv_val, &right) == 0)
865 } else if (val->bv_len >= left.bv_len) {
866 if (strncasecmp( val->bv_val, left.bv_val, left.bv_len ) == 0)
876 aci_list_get_attr_rights(
885 /* loop through each rights/attr pair, skip first part (action) */
887 for (i = 1; aci_get_part(list, i + 1, ';', &bv) >= 0; i += 2) {
888 if (aci_list_has_attr(&bv, attr, val) == 0)
890 if (aci_get_part(list, i, ';', &bv) < 0)
892 mask |= aci_list_map_rights(&bv);
902 slap_access_t *grant,
903 slap_access_t *deny )
905 struct berval perm, actn;
909 if (attr == NULL || *attr == 0 || strcasecmp(attr, "entry") == 0) {
916 /* loop through each permissions clause */
917 for (i = 0; aci_get_part(list, i, '$', &perm) >= 0; i++) {
918 if (aci_get_part(&perm, 0, ';', &actn) < 0)
920 if (aci_strbvcmp( "grant", &actn ) == 0) {
922 } else if (aci_strbvcmp( "deny", &actn ) == 0) {
929 *mask |= aci_list_get_attr_rights(&perm, attr, val);
930 *mask |= aci_list_get_attr_rights(&perm, "[all]", NULL);
938 const char *defgrpoc,
939 const char *defgrpat,
947 char *subjdn, *grpdn = NULL;
950 ObjectClass *grp_oc = NULL;
951 AttributeDescription *grp_ad = NULL;
955 /* format of string is "group/objectClassValue/groupAttrName" */
956 if (aci_get_part(subj, 0, '/', &bv) < 0) {
960 subjdn = aci_bvstrdup(&bv);
961 if (subjdn == NULL) {
965 if (aci_get_part(subj, 1, '/', &bv) < 0) {
966 grpoc = ch_strdup( defgrpoc );
968 grpoc = aci_bvstrdup(&bv);
971 if (aci_get_part(subj, 2, '/', &bv) < 0) {
972 grpat = ch_strdup( defgrpat );
974 grpat = aci_bvstrdup(&bv);
977 rc = slap_str2ad( grpat, &grp_ad, &text );
978 if( rc != LDAP_SUCCESS ) {
984 grpdn = (char *)ch_malloc(1024);
986 if (grp_oc != NULL && grp_ad != NULL && grpdn != NULL) {
987 string_expand(grpdn, 1024, subjdn, e->e_ndn, matches);
988 if ( dn_normalize(grpdn) != NULL ) {
989 rc = (backend_group(be, e, grpdn, op->o_ndn, grp_oc, grp_ad) == 0);
994 if( grp_ad != NULL ) ad_free( grp_ad, 1 );
1007 AttributeDescription *desc,
1010 regmatch_t *matches,
1011 slap_access_t *grant,
1015 struct berval bv, perms, sdn;
1020 /* parse an aci of the form:
1021 oid#scope#action;rights;attr;rights;attr$action;rights;attr;rights;attr#dnType#subjectDN
1023 See draft-ietf-ldapext-aci-model-04.txt section 9.1 for
1024 a full description of the format for this attribute.
1026 For now, this routine only supports scope=entry.
1029 /* check that the aci has all 5 components */
1030 if (aci_get_part(aci, 4, '#', NULL) < 0)
1033 /* check that the aci family is supported */
1034 if (aci_get_part(aci, 0, '#', &bv) < 0)
1037 /* check that the scope is "entry" */
1038 if (aci_get_part(aci, 1, '#', &bv) < 0
1039 || aci_strbvcmp( "entry", &bv ) != 0)
1044 /* get the list of permissions clauses, bail if empty */
1045 if (aci_get_part(aci, 2, '#', &perms) <= 0)
1048 /* check if any permissions allow desired access */
1049 if (aci_list_get_rights(&perms, attr, val, grant, deny) == 0)
1052 /* see if we have a DN match */
1053 if (aci_get_part(aci, 3, '#', &bv) < 0)
1056 if (aci_get_part(aci, 4, '#', &sdn) < 0)
1059 if (aci_strbvcmp( "access-id", &bv ) == 0) {
1060 subjdn = aci_bvstrdup(&sdn);
1064 if ( dn_normalize(subjdn) != NULL )
1065 if (strcasecmp(op->o_ndn, subjdn) != 0)
1071 if (aci_strbvcmp( "self", &bv ) == 0) {
1072 if (strcasecmp(op->o_ndn, e->e_ndn) == 0)
1075 } else if (aci_strbvcmp( "dnattr", &bv ) == 0) {
1076 char *dnattr = aci_bvstrdup(&sdn);
1078 AttributeDescription *ad = NULL;
1081 rc = slap_str2ad( dnattr, &ad, &text );
1084 if( rc != LDAP_SUCCESS ) {
1090 bv.bv_val = op->o_ndn;
1091 bv.bv_len = strlen( bv.bv_val );
1093 for(at = attrs_find( e->e_attrs, ad );
1095 at = attrs_find( at->a_next, ad ) )
1097 if (value_find( ad, at->a_vals, &bv) == 0 ) {
1107 } else if (aci_strbvcmp( "group", &bv ) == 0) {
1108 if (aci_group_member(&sdn, SLAPD_GROUP_CLASS, SLAPD_GROUP_ATTR, be, e, op, matches))
1111 } else if (aci_strbvcmp( "role", &bv ) == 0) {
1112 if (aci_group_member(&sdn, SLAPD_ROLE_CLASS, SLAPD_ROLE_ATTR, be, e, op, matches))
1119 #endif /* SLAPD_ACI_ENABLED */
1127 regmatch_t *matches)
1136 bufsiz--; /* leave space for lone $ */
1139 for ( dp = newbuf, sp = pat; size < bufsiz && *sp ; sp++) {
1140 /* did we previously see a $ */
1145 } else if (*sp >= '0' && *sp <= '9' ) {
1152 i = matches[n].rm_so;
1153 l = matches[n].rm_eo;
1154 for ( ; size < 512 && i < l; size++, i++ ) {
1172 /* must have ended with a single $ */
1179 Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %s\n", pat, 0, 0 );
1180 Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", newbuf, 0, 0 );
1185 char *pat, /* pattern to expand and match against */
1186 char *str, /* string to match against pattern */
1187 char *buf, /* buffer with $N expansion variables */
1188 regmatch_t *matches /* offsets in buffer for $N expansion variables */
1195 if(str == NULL) str = "";
1197 string_expand(newbuf, sizeof(newbuf), pat, buf, matches);
1198 if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
1200 regerror(rc, &re, error, sizeof(error));
1202 Debug( LDAP_DEBUG_TRACE,
1203 "compile( \"%s\", \"%s\") failed %s\n",
1208 rc = regexec(&re, str, 0, NULL, 0);
1211 Debug( LDAP_DEBUG_TRACE,
1212 "=> regex_matches: string: %s\n", str, 0, 0 );
1213 Debug( LDAP_DEBUG_TRACE,
1214 "=> regex_matches: rc: %d %s\n",
1215 rc, !rc ? "matches" : "no matches", 0 );