1 /* aclparse.c - routines to parse and check acl's */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2007 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that this notice is preserved and that due credit is given
21 * to the University of Michigan at Ann Arbor. The name of the University
22 * may not be used to endorse or promote products derived from this
23 * software without specific prior written permission. This software
24 * is provided ``as is'' without express or implied warranty.
33 #include <ac/socket.h>
34 #include <ac/string.h>
35 #include <ac/unistd.h>
41 static const char style_base[] = "base";
42 char *style_strings[] = {
60 static void split(char *line, int splitchar, char **left, char **right);
61 static void access_append(Access **l, Access *a);
62 static void access_free( Access *a );
63 static int acl_usage(void);
65 static void acl_regex_normalized_dn(const char *src, struct berval *pat);
68 static void print_acl(Backend *be, AccessControl *a);
71 static int check_scope( BackendDB *be, AccessControl *a );
84 slap_dynacl_t *da, *tmp;
87 for ( da = b->a_dynacl; da; da = da->da_next ) {
88 if ( strcasecmp( da->da_name, name ) == 0 ) {
89 Debug( LDAP_DEBUG_ANY,
90 "%s: line %d: dynacl \"%s\" already specified.\n",
91 fname, lineno, name );
96 da = slap_dynacl_get( name );
101 tmp = ch_malloc( sizeof( slap_dynacl_t ) );
104 if ( tmp->da_parse ) {
105 rc = ( *tmp->da_parse )( fname, lineno, opts, sty, right, &tmp->da_private );
112 tmp->da_next = b->a_dynacl;
117 #endif /* SLAP_DYNACL */
120 regtest(const char *fname, int lineno, char *pat) {
124 char buf[ SLAP_TEXT_BUFLEN ];
136 for (size = 0, flag = 0; (size < sizeof(buf)) && *sp; sp++) {
138 if (*sp == '$'|| (*sp >= '0' && *sp <= '9')) {
155 if ( size >= (sizeof(buf) - 1) ) {
156 Debug( LDAP_DEBUG_ANY,
157 "%s: line %d: regular expression \"%s\" too large\n",
158 fname, lineno, pat );
160 exit( EXIT_FAILURE );
163 if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
164 char error[ SLAP_TEXT_BUFLEN ];
166 regerror(e, &re, error, sizeof(error));
168 snprintf( buf, sizeof( buf ),
169 "regular expression \"%s\" bad because of %s",
171 Debug( LDAP_DEBUG_ANY,
173 fname, lineno, buf );
175 exit( EXIT_FAILURE );
183 * Check if the pattern of an ACL, if any, matches the scope
184 * of the backend it is defined within.
186 #define ACL_SCOPE_UNKNOWN (-2)
187 #define ACL_SCOPE_ERR (-1)
188 #define ACL_SCOPE_OK (0)
189 #define ACL_SCOPE_PARTIAL (1)
190 #define ACL_SCOPE_WARN (2)
193 check_scope( BackendDB *be, AccessControl *a )
198 dn = be->be_nsuffix[0];
200 if ( BER_BVISEMPTY( &dn ) ) {
204 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
205 a->acl_dn_style != ACL_STYLE_REGEX )
207 slap_style_t style = a->acl_dn_style;
209 if ( style == ACL_STYLE_REGEX ) {
210 char dnbuf[SLAP_LDAPDN_MAXLEN + 2];
211 char rebuf[SLAP_LDAPDN_MAXLEN + 1];
216 /* add trailing '$' to database suffix to form
217 * a simple trial regex pattern "<suffix>$" */
218 AC_MEMCPY( dnbuf, be->be_nsuffix[0].bv_val,
219 be->be_nsuffix[0].bv_len );
220 dnbuf[be->be_nsuffix[0].bv_len] = '$';
221 dnbuf[be->be_nsuffix[0].bv_len + 1] = '\0';
223 if ( regcomp( &re, dnbuf, REG_EXTENDED|REG_ICASE ) ) {
224 return ACL_SCOPE_WARN;
227 /* remove trailing ')$', if any, from original
229 rebuflen = a->acl_dn_pat.bv_len;
230 AC_MEMCPY( rebuf, a->acl_dn_pat.bv_val, rebuflen + 1 );
231 if ( rebuf[rebuflen - 1] == '$' ) {
232 rebuf[--rebuflen] = '\0';
234 while ( rebuflen > be->be_nsuffix[0].bv_len && rebuf[rebuflen - 1] == ')' ) {
235 rebuf[--rebuflen] = '\0';
237 if ( rebuflen == be->be_nsuffix[0].bv_len ) {
242 /* not a clear indication of scoping error, though */
243 rc = regexec( &re, rebuf, 0, NULL, 0 )
244 ? ACL_SCOPE_WARN : ACL_SCOPE_OK;
251 patlen = a->acl_dn_pat.bv_len;
252 /* If backend suffix is longer than pattern,
253 * it is a potential mismatch (in the sense
254 * that a superior naming context could
256 if ( dn.bv_len > patlen ) {
257 /* base is blatantly wrong */
258 if ( style == ACL_STYLE_BASE ) return ACL_SCOPE_ERR;
260 /* a style of one can be wrong if there is
261 * more than one level between the suffix
263 if ( style == ACL_STYLE_ONE ) {
264 ber_len_t rdnlen = 0;
268 if ( !DN_SEPARATOR( dn.bv_val[dn.bv_len - patlen - 1] )) {
269 return ACL_SCOPE_ERR;
274 rdnlen = dn_rdnlen( NULL, &dn );
275 if ( rdnlen != dn.bv_len - patlen - sep )
276 return ACL_SCOPE_ERR;
279 /* if the trailing part doesn't match,
280 * then it's an error */
281 if ( strcmp( a->acl_dn_pat.bv_val,
282 &dn.bv_val[dn.bv_len - patlen] ) != 0 )
284 return ACL_SCOPE_ERR;
287 return ACL_SCOPE_PARTIAL;
293 case ACL_STYLE_CHILDREN:
294 case ACL_STYLE_SUBTREE:
302 if ( dn.bv_len < patlen &&
303 !DN_SEPARATOR( a->acl_dn_pat.bv_val[patlen - dn.bv_len - 1] ))
305 return ACL_SCOPE_ERR;
308 if ( strcmp( &a->acl_dn_pat.bv_val[patlen - dn.bv_len], dn.bv_val )
311 return ACL_SCOPE_ERR;
317 return ACL_SCOPE_UNKNOWN;
330 char *left, *right, *style;
332 AccessControl *a = NULL;
337 for ( i = 1; i < argc; i++ ) {
338 /* to clause - select which entries are protected */
339 if ( strcasecmp( argv[i], "to" ) == 0 ) {
341 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
342 "only one to clause allowed in access line\n",
346 a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
347 for ( ++i; i < argc; i++ ) {
348 if ( strcasecmp( argv[i], "by" ) == 0 ) {
353 if ( strcasecmp( argv[i], "*" ) == 0 ) {
354 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
355 a->acl_dn_style != ACL_STYLE_REGEX )
357 Debug( LDAP_DEBUG_ANY,
358 "%s: line %d: dn pattern"
359 " already specified in to clause.\n",
364 ber_str2bv( "*", STRLENOF( "*" ), 1, &a->acl_dn_pat );
368 split( argv[i], '=', &left, &right );
369 split( left, '.', &left, &style );
371 if ( right == NULL ) {
372 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
373 "missing \"=\" in \"%s\" in to clause\n",
374 fname, lineno, left );
378 if ( strcasecmp( left, "dn" ) == 0 ) {
379 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
380 a->acl_dn_style != ACL_STYLE_REGEX )
382 Debug( LDAP_DEBUG_ANY,
383 "%s: line %d: dn pattern"
384 " already specified in to clause.\n",
389 if ( style == NULL || *style == '\0' ||
390 strcasecmp( style, "baseObject" ) == 0 ||
391 strcasecmp( style, "base" ) == 0 ||
392 strcasecmp( style, "exact" ) == 0 )
394 a->acl_dn_style = ACL_STYLE_BASE;
395 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
397 } else if ( strcasecmp( style, "oneLevel" ) == 0 ||
398 strcasecmp( style, "one" ) == 0 )
400 a->acl_dn_style = ACL_STYLE_ONE;
401 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
403 } else if ( strcasecmp( style, "subtree" ) == 0 ||
404 strcasecmp( style, "sub" ) == 0 )
406 if( *right == '\0' ) {
407 ber_str2bv( "*", STRLENOF( "*" ), 1, &a->acl_dn_pat );
410 a->acl_dn_style = ACL_STYLE_SUBTREE;
411 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
414 } else if ( strcasecmp( style, "children" ) == 0 ) {
415 a->acl_dn_style = ACL_STYLE_CHILDREN;
416 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
418 } else if ( strcasecmp( style, "regex" ) == 0 ) {
419 a->acl_dn_style = ACL_STYLE_REGEX;
421 if ( *right == '\0' ) {
422 /* empty regex should match empty DN */
423 a->acl_dn_style = ACL_STYLE_BASE;
424 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
426 } else if ( strcmp(right, "*") == 0
427 || strcmp(right, ".*") == 0
428 || strcmp(right, ".*$") == 0
429 || strcmp(right, "^.*") == 0
430 || strcmp(right, "^.*$") == 0
431 || strcmp(right, ".*$$") == 0
432 || strcmp(right, "^.*$$") == 0 )
434 ber_str2bv( "*", STRLENOF("*"), 1, &a->acl_dn_pat );
437 acl_regex_normalized_dn( right, &a->acl_dn_pat );
441 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
442 "unknown dn style \"%s\" in to clause\n",
443 fname, lineno, style );
450 if ( strcasecmp( left, "filter" ) == 0 ) {
451 if ( (a->acl_filter = str2filter( right )) == NULL ) {
452 Debug( LDAP_DEBUG_ANY,
453 "%s: line %d: bad filter \"%s\" in to clause\n",
454 fname, lineno, right );
458 } else if ( strcasecmp( left, "attr" ) == 0 /* TOLERATED */
459 || strcasecmp( left, "attrs" ) == 0 ) /* DOCUMENTED */
461 if ( strcasecmp( left, "attr" ) == 0 ) {
462 Debug( LDAP_DEBUG_ANY,
463 "%s: line %d: \"attr\" "
464 "is deprecated (and undocumented); "
465 "use \"attrs\" instead.\n",
469 a->acl_attrs = str2anlist( a->acl_attrs,
471 if ( a->acl_attrs == NULL ) {
472 Debug( LDAP_DEBUG_ANY,
473 "%s: line %d: unknown attr \"%s\" in to clause\n",
474 fname, lineno, right );
478 } else if ( strncasecmp( left, "val", 3 ) == 0 ) {
482 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
483 Debug( LDAP_DEBUG_ANY,
484 "%s: line %d: attr val already specified in to clause.\n",
488 if ( a->acl_attrs == NULL || !BER_BVISEMPTY( &a->acl_attrs[1].an_name ) )
490 Debug( LDAP_DEBUG_ANY,
491 "%s: line %d: attr val requires a single attribute.\n",
496 ber_str2bv( right, 0, 0, &bv );
497 a->acl_attrval_style = ACL_STYLE_BASE;
499 mr = strchr( left, '/' );
504 a->acl_attrval_mr = mr_find( mr );
505 if ( a->acl_attrval_mr == NULL ) {
506 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
507 "invalid matching rule \"%s\".\n",
512 if( !mr_usable_with_at( a->acl_attrval_mr, a->acl_attrs[ 0 ].an_desc->ad_type ) )
514 char buf[ SLAP_TEXT_BUFLEN ];
516 snprintf( buf, sizeof( buf ),
517 "matching rule \"%s\" use "
518 "with attr \"%s\" not appropriate.",
519 mr, a->acl_attrs[ 0 ].an_name.bv_val );
522 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
523 fname, lineno, buf );
528 if ( style != NULL ) {
529 if ( strcasecmp( style, "regex" ) == 0 ) {
530 int e = regcomp( &a->acl_attrval_re, bv.bv_val,
531 REG_EXTENDED | REG_ICASE | REG_NOSUB );
533 char err[SLAP_TEXT_BUFLEN],
534 buf[ SLAP_TEXT_BUFLEN ];
536 regerror( e, &a->acl_attrval_re, err, sizeof( err ) );
538 snprintf( buf, sizeof( buf ),
539 "regular expression \"%s\" bad because of %s",
542 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
543 fname, lineno, buf );
546 a->acl_attrval_style = ACL_STYLE_REGEX;
549 /* FIXME: if the attribute has DN syntax, we might
550 * allow one, subtree and children styles as well */
551 if ( !strcasecmp( style, "base" ) ||
552 !strcasecmp( style, "exact" ) ) {
553 a->acl_attrval_style = ACL_STYLE_BASE;
555 } else if ( a->acl_attrs[0].an_desc->ad_type->
556 sat_syntax == slap_schema.si_syn_distinguishedName )
558 if ( !strcasecmp( style, "baseObject" ) ||
559 !strcasecmp( style, "base" ) )
561 a->acl_attrval_style = ACL_STYLE_BASE;
562 } else if ( !strcasecmp( style, "onelevel" ) ||
563 !strcasecmp( style, "one" ) )
565 a->acl_attrval_style = ACL_STYLE_ONE;
566 } else if ( !strcasecmp( style, "subtree" ) ||
567 !strcasecmp( style, "sub" ) )
569 a->acl_attrval_style = ACL_STYLE_SUBTREE;
570 } else if ( !strcasecmp( style, "children" ) ) {
571 a->acl_attrval_style = ACL_STYLE_CHILDREN;
573 char buf[ SLAP_TEXT_BUFLEN ];
575 snprintf( buf, sizeof( buf ),
576 "unknown val.<style> \"%s\" for attributeType \"%s\" "
579 a->acl_attrs[0].an_desc->ad_cname.bv_val );
581 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
583 fname, lineno, buf );
587 rc = dnNormalize( 0, NULL, NULL, &bv, &a->acl_attrval, NULL );
588 if ( rc != LDAP_SUCCESS ) {
589 char buf[ SLAP_TEXT_BUFLEN ];
591 snprintf( buf, sizeof( buf ),
592 "unable to normalize DN \"%s\" "
593 "for attributeType \"%s\" (%d).",
595 a->acl_attrs[0].an_desc->ad_cname.bv_val,
597 Debug( LDAP_DEBUG_ANY,
599 fname, lineno, buf );
604 char buf[ SLAP_TEXT_BUFLEN ];
606 snprintf( buf, sizeof( buf ),
607 "unknown val.<style> \"%s\" for attributeType \"%s\".",
608 style, a->acl_attrs[0].an_desc->ad_cname.bv_val );
609 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
611 fname, lineno, buf );
617 /* Check for appropriate matching rule */
618 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
619 ber_dupbv( &a->acl_attrval, &bv );
621 } else if ( BER_BVISNULL( &a->acl_attrval ) ) {
625 if ( a->acl_attrval_mr == NULL ) {
626 a->acl_attrval_mr = a->acl_attrs[ 0 ].an_desc->ad_type->sat_equality;
629 if ( a->acl_attrval_mr == NULL ) {
630 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
631 "attr \"%s\" does not have an EQUALITY matching rule.\n",
632 fname, lineno, a->acl_attrs[ 0 ].an_name.bv_val );
636 rc = asserted_value_validate_normalize(
637 a->acl_attrs[ 0 ].an_desc,
639 SLAP_MR_EQUALITY|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
644 if ( rc != LDAP_SUCCESS ) {
645 char buf[ SLAP_TEXT_BUFLEN ];
647 snprintf( buf, sizeof( buf ), "%s: line %d: "
648 " attr \"%s\" normalization failed (%d: %s)",
650 a->acl_attrs[ 0 ].an_name.bv_val, rc, text );
651 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s.\n",
652 fname, lineno, buf );
658 Debug( LDAP_DEBUG_ANY,
659 "%s: line %d: expecting <what> got \"%s\"\n",
660 fname, lineno, left );
665 if ( !BER_BVISNULL( &a->acl_dn_pat ) &&
666 ber_bvccmp( &a->acl_dn_pat, '*' ) )
668 free( a->acl_dn_pat.bv_val );
669 BER_BVZERO( &a->acl_dn_pat );
670 a->acl_dn_style = ACL_STYLE_REGEX;
673 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
674 a->acl_dn_style != ACL_STYLE_REGEX )
676 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
678 rc = dnNormalize( 0, NULL, NULL, &a->acl_dn_pat, &bv, NULL);
679 if ( rc != LDAP_SUCCESS ) {
680 Debug( LDAP_DEBUG_ANY,
681 "%s: line %d: bad DN \"%s\" in to DN clause\n",
682 fname, lineno, a->acl_dn_pat.bv_val );
685 free( a->acl_dn_pat.bv_val );
689 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
690 REG_EXTENDED | REG_ICASE );
692 char err[ SLAP_TEXT_BUFLEN ],
693 buf[ SLAP_TEXT_BUFLEN ];
695 regerror( e, &a->acl_dn_re, err, sizeof( err ) );
696 snprintf( buf, sizeof( buf ),
697 "regular expression \"%s\" bad because of %s",
699 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
700 fname, lineno, buf );
706 /* by clause - select who has what access to entries */
707 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
709 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
710 "to clause required before by clause in access line\n",
716 * by clause consists of <who> and <access>
720 Debug( LDAP_DEBUG_ANY,
721 "%s: line %d: premature EOL: expecting <who>\n",
726 b = (Access *) ch_calloc( 1, sizeof(Access) );
728 ACL_INVALIDATE( b->a_access_mask );
731 for ( ; i < argc; i++ ) {
732 slap_style_t sty = ACL_STYLE_REGEX;
733 char *style_modifier = NULL;
734 char *style_level = NULL;
737 slap_dn_access *bdn = &b->a_dn;
740 split( argv[i], '=', &left, &right );
741 split( left, '.', &left, &style );
743 split( style, ',', &style, &style_modifier );
745 if ( strncasecmp( style, "level", STRLENOF( "level" ) ) == 0 ) {
746 split( style, '{', &style, &style_level );
747 if ( style_level != NULL ) {
748 char *p = strchr( style_level, '}' );
750 Debug( LDAP_DEBUG_ANY,
751 "%s: line %d: premature eol: "
752 "expecting closing '}' in \"level{n}\"\n",
755 } else if ( p == style_level ) {
756 Debug( LDAP_DEBUG_ANY,
757 "%s: line %d: empty level "
767 if ( style == NULL || *style == '\0' ||
768 strcasecmp( style, "exact" ) == 0 ||
769 strcasecmp( style, "baseObject" ) == 0 ||
770 strcasecmp( style, "base" ) == 0 )
772 sty = ACL_STYLE_BASE;
774 } else if ( strcasecmp( style, "onelevel" ) == 0 ||
775 strcasecmp( style, "one" ) == 0 )
779 } else if ( strcasecmp( style, "subtree" ) == 0 ||
780 strcasecmp( style, "sub" ) == 0 )
782 sty = ACL_STYLE_SUBTREE;
784 } else if ( strcasecmp( style, "children" ) == 0 ) {
785 sty = ACL_STYLE_CHILDREN;
787 } else if ( strcasecmp( style, "level" ) == 0 )
789 if ( lutil_atoi( &level, style_level ) != 0 ) {
790 Debug( LDAP_DEBUG_ANY,
791 "%s: line %d: unable to parse level "
797 sty = ACL_STYLE_LEVEL;
799 } else if ( strcasecmp( style, "regex" ) == 0 ) {
800 sty = ACL_STYLE_REGEX;
802 } else if ( strcasecmp( style, "expand" ) == 0 ) {
803 sty = ACL_STYLE_EXPAND;
805 } else if ( strcasecmp( style, "ip" ) == 0 ) {
808 } else if ( strcasecmp( style, "ipv6" ) == 0 ) {
809 #ifndef LDAP_PF_INET6
810 Debug( LDAP_DEBUG_ANY,
811 "%s: line %d: IPv6 not supported\n",
813 #endif /* ! LDAP_PF_INET6 */
814 sty = ACL_STYLE_IPV6;
816 } else if ( strcasecmp( style, "path" ) == 0 ) {
817 sty = ACL_STYLE_PATH;
818 #ifndef LDAP_PF_LOCAL
819 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
821 "\"path\" style modifier is useless without local.\n",
824 #endif /* LDAP_PF_LOCAL */
827 Debug( LDAP_DEBUG_ANY,
828 "%s: line %d: unknown style \"%s\" in by clause\n",
829 fname, lineno, style );
833 if ( style_modifier &&
834 strcasecmp( style_modifier, "expand" ) == 0 )
837 case ACL_STYLE_REGEX:
838 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
839 "\"regex\" style implies \"expand\" modifier.\n",
844 case ACL_STYLE_EXPAND:
848 /* we'll see later if it's pertinent */
854 /* expand in <who> needs regex in <what> */
855 if ( ( sty == ACL_STYLE_EXPAND || expand )
856 && a->acl_dn_style != ACL_STYLE_REGEX )
858 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL, "%s: line %d: \"expand\" style "
859 "or modifier used in conjunction with a non-regex <what> clause.\n",
864 if ( strncasecmp( left, "real", STRLENOF( "real" ) ) == 0 ) {
867 left += STRLENOF( "real" );
870 if ( strcasecmp( left, "*" ) == 0 ) {
875 ber_str2bv( "*", STRLENOF( "*" ), 1, &bv );
876 sty = ACL_STYLE_REGEX;
878 } else if ( strcasecmp( left, "anonymous" ) == 0 ) {
879 ber_str2bv("anonymous", STRLENOF( "anonymous" ), 1, &bv);
880 sty = ACL_STYLE_ANONYMOUS;
882 } else if ( strcasecmp( left, "users" ) == 0 ) {
883 ber_str2bv("users", STRLENOF( "users" ), 1, &bv);
884 sty = ACL_STYLE_USERS;
886 } else if ( strcasecmp( left, "self" ) == 0 ) {
887 ber_str2bv("self", STRLENOF( "self" ), 1, &bv);
888 sty = ACL_STYLE_SELF;
890 } else if ( strcasecmp( left, "dn" ) == 0 ) {
891 if ( sty == ACL_STYLE_REGEX ) {
892 bdn->a_style = ACL_STYLE_REGEX;
893 if ( right == NULL ) {
898 bdn->a_style = ACL_STYLE_USERS;
900 } else if (*right == '\0' ) {
902 ber_str2bv("anonymous",
903 STRLENOF( "anonymous" ),
905 bdn->a_style = ACL_STYLE_ANONYMOUS;
907 } else if ( strcmp( right, "*" ) == 0 ) {
909 /* any or users? users for now */
913 bdn->a_style = ACL_STYLE_USERS;
915 } else if ( strcmp( right, ".+" ) == 0
916 || strcmp( right, "^.+" ) == 0
917 || strcmp( right, ".+$" ) == 0
918 || strcmp( right, "^.+$" ) == 0
919 || strcmp( right, ".+$$" ) == 0
920 || strcmp( right, "^.+$$" ) == 0 )
925 bdn->a_style = ACL_STYLE_USERS;
927 } else if ( strcmp( right, ".*" ) == 0
928 || strcmp( right, "^.*" ) == 0
929 || strcmp( right, ".*$" ) == 0
930 || strcmp( right, "^.*$" ) == 0
931 || strcmp( right, ".*$$" ) == 0
932 || strcmp( right, "^.*$$" ) == 0 )
939 acl_regex_normalized_dn( right, &bv );
940 if ( !ber_bvccmp( &bv, '*' ) ) {
941 regtest( fname, lineno, bv.bv_val );
945 } else if ( right == NULL || *right == '\0' ) {
946 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
947 "missing \"=\" in (or value after) \"%s\" "
949 fname, lineno, left );
953 ber_str2bv( right, 0, 1, &bv );
960 if ( !BER_BVISNULL( &bv ) ) {
961 if ( !BER_BVISEMPTY( &bdn->a_pat ) ) {
962 Debug( LDAP_DEBUG_ANY,
963 "%s: line %d: dn pattern already specified.\n",
968 if ( sty != ACL_STYLE_REGEX &&
969 sty != ACL_STYLE_ANONYMOUS &&
970 sty != ACL_STYLE_USERS &&
971 sty != ACL_STYLE_SELF &&
974 rc = dnNormalize(0, NULL, NULL,
975 &bv, &bdn->a_pat, NULL);
976 if ( rc != LDAP_SUCCESS ) {
977 Debug( LDAP_DEBUG_ANY,
978 "%s: line %d: bad DN \"%s\" in by DN clause\n",
979 fname, lineno, bv.bv_val );
983 if ( sty == ACL_STYLE_BASE
985 && !BER_BVISNULL( &be->be_rootndn )
986 && dn_match( &bdn->a_pat, &be->be_rootndn ) )
988 Debug( LDAP_DEBUG_ANY,
989 "%s: line %d: rootdn is always granted "
990 "unlimited privileges.\n",
1002 for ( exp = strchr( bdn->a_pat.bv_val, '$' );
1003 exp && (ber_len_t)(exp - bdn->a_pat.bv_val)
1004 < bdn->a_pat.bv_len;
1005 exp = strchr( exp, '$' ) )
1007 if ( isdigit( (unsigned char) exp[ 1 ] ) ) {
1014 bdn->a_expand = expand;
1017 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1018 "\"expand\" used with no expansions in \"pattern\".\n",
1023 if ( sty == ACL_STYLE_SELF ) {
1024 bdn->a_self_level = level;
1028 Debug( LDAP_DEBUG_ANY,
1029 "%s: line %d: bad negative level \"%d\" "
1030 "in by DN clause\n",
1031 fname, lineno, level );
1033 } else if ( level == 1 ) {
1034 Debug( LDAP_DEBUG_ANY,
1035 "%s: line %d: \"onelevel\" should be used "
1036 "instead of \"level{1}\" in by DN clause\n",
1038 } else if ( level == 0 && sty == ACL_STYLE_LEVEL ) {
1039 Debug( LDAP_DEBUG_ANY,
1040 "%s: line %d: \"base\" should be used "
1041 "instead of \"level{0}\" in by DN clause\n",
1045 bdn->a_level = level;
1050 if ( strcasecmp( left, "dnattr" ) == 0 ) {
1051 if ( right == NULL || right[0] == '\0' ) {
1052 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1053 "missing \"=\" in (or value after) \"%s\" "
1055 fname, lineno, left );
1059 if( bdn->a_at != NULL ) {
1060 Debug( LDAP_DEBUG_ANY,
1061 "%s: line %d: dnattr already specified.\n",
1066 rc = slap_str2ad( right, &bdn->a_at, &text );
1068 if( rc != LDAP_SUCCESS ) {
1069 char buf[ SLAP_TEXT_BUFLEN ];
1071 snprintf( buf, sizeof( buf ),
1072 "dnattr \"%s\": %s",
1074 Debug( LDAP_DEBUG_ANY,
1075 "%s: line %d: %s\n",
1076 fname, lineno, buf );
1081 if( !is_at_syntax( bdn->a_at->ad_type,
1082 SLAPD_DN_SYNTAX ) &&
1083 !is_at_syntax( bdn->a_at->ad_type,
1084 SLAPD_NAMEUID_SYNTAX ))
1086 char buf[ SLAP_TEXT_BUFLEN ];
1088 snprintf( buf, sizeof( buf ),
1090 "inappropriate syntax: %s\n",
1092 bdn->a_at->ad_type->sat_syntax_oid );
1093 Debug( LDAP_DEBUG_ANY,
1094 "%s: line %d: %s\n",
1095 fname, lineno, buf );
1099 if( bdn->a_at->ad_type->sat_equality == NULL ) {
1100 Debug( LDAP_DEBUG_ANY,
1101 "%s: line %d: dnattr \"%s\": "
1102 "inappropriate matching (no EQUALITY)\n",
1103 fname, lineno, right );
1110 if ( strncasecmp( left, "group", STRLENOF( "group" ) ) == 0 ) {
1113 char *attr_name = SLAPD_GROUP_ATTR;
1116 case ACL_STYLE_REGEX:
1117 /* legacy, tolerated */
1118 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
1120 "deprecated group style \"regex\"; "
1121 "use \"expand\" instead.\n",
1123 sty = ACL_STYLE_EXPAND;
1126 case ACL_STYLE_BASE:
1127 /* legal, traditional */
1128 case ACL_STYLE_EXPAND:
1129 /* legal, substring expansion; supersedes regex */
1134 Debug( LDAP_DEBUG_ANY,
1136 "inappropriate style \"%s\" in by clause.\n",
1137 fname, lineno, style );
1141 if ( right == NULL || right[0] == '\0' ) {
1142 Debug( LDAP_DEBUG_ANY,
1144 "missing \"=\" in (or value after) \"%s\" "
1146 fname, lineno, left );
1150 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1151 Debug( LDAP_DEBUG_ANY,
1152 "%s: line %d: group pattern already specified.\n",
1157 /* format of string is
1158 "group/objectClassValue/groupAttrName" */
1159 if ( ( value = strchr(left, '/') ) != NULL ) {
1161 if ( *value && ( name = strchr( value, '/' ) ) != NULL ) {
1166 b->a_group_style = sty;
1167 if ( sty == ACL_STYLE_EXPAND ) {
1168 acl_regex_normalized_dn( right, &bv );
1169 if ( !ber_bvccmp( &bv, '*' ) ) {
1170 regtest( fname, lineno, bv.bv_val );
1172 b->a_group_pat = bv;
1175 ber_str2bv( right, 0, 0, &bv );
1176 rc = dnNormalize( 0, NULL, NULL, &bv,
1177 &b->a_group_pat, NULL );
1178 if ( rc != LDAP_SUCCESS ) {
1179 Debug( LDAP_DEBUG_ANY,
1180 "%s: line %d: bad DN \"%s\".\n",
1181 fname, lineno, right );
1186 if ( value && *value ) {
1187 b->a_group_oc = oc_find( value );
1190 if ( b->a_group_oc == NULL ) {
1191 Debug( LDAP_DEBUG_ANY,
1192 "%s: line %d: group objectclass "
1193 "\"%s\" unknown.\n",
1194 fname, lineno, value );
1199 b->a_group_oc = oc_find( SLAPD_GROUP_CLASS );
1201 if( b->a_group_oc == NULL ) {
1202 Debug( LDAP_DEBUG_ANY,
1203 "%s: line %d: group default objectclass "
1204 "\"%s\" unknown.\n",
1205 fname, lineno, SLAPD_GROUP_CLASS );
1210 if ( is_object_subclass( slap_schema.si_oc_referral,
1213 Debug( LDAP_DEBUG_ANY,
1214 "%s: line %d: group objectclass \"%s\" "
1215 "is subclass of referral.\n",
1216 fname, lineno, value );
1220 if ( is_object_subclass( slap_schema.si_oc_alias,
1223 Debug( LDAP_DEBUG_ANY,
1224 "%s: line %d: group objectclass \"%s\" "
1225 "is subclass of alias.\n",
1226 fname, lineno, value );
1230 if ( name && *name ) {
1236 rc = slap_str2ad( attr_name, &b->a_group_at, &text );
1237 if ( rc != LDAP_SUCCESS ) {
1238 char buf[ SLAP_TEXT_BUFLEN ];
1240 snprintf( buf, sizeof( buf ),
1241 "group \"%s\": %s.",
1243 Debug( LDAP_DEBUG_ANY,
1244 "%s: line %d: %s\n",
1245 fname, lineno, buf );
1249 if ( !is_at_syntax( b->a_group_at->ad_type,
1250 SLAPD_DN_SYNTAX ) /* e.g. "member" */
1251 && !is_at_syntax( b->a_group_at->ad_type,
1252 SLAPD_NAMEUID_SYNTAX ) /* e.g. memberUID */
1253 && !is_at_subtype( b->a_group_at->ad_type,
1254 slap_schema.si_ad_labeledURI->ad_type ) /* e.g. memberURL */ )
1256 char buf[ SLAP_TEXT_BUFLEN ];
1258 snprintf( buf, sizeof( buf ),
1259 "group \"%s\" attr \"%s\": inappropriate syntax: %s; "
1260 "must be " SLAPD_DN_SYNTAX " (DN), "
1261 SLAPD_NAMEUID_SYNTAX " (NameUID) "
1262 "or a subtype of labeledURI.",
1265 at_syntax( b->a_group_at->ad_type ) );
1266 Debug( LDAP_DEBUG_ANY,
1267 "%s: line %d: %s\n",
1268 fname, lineno, buf );
1275 ObjectClass *ocs[2];
1277 ocs[0] = b->a_group_oc;
1280 rc = oc_check_allowed( b->a_group_at->ad_type,
1284 char buf[ SLAP_TEXT_BUFLEN ];
1286 snprintf( buf, sizeof( buf ),
1287 "group: \"%s\" not allowed by \"%s\".",
1288 b->a_group_at->ad_cname.bv_val,
1289 b->a_group_oc->soc_oid );
1290 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
1291 fname, lineno, buf );
1298 if ( strcasecmp( left, "peername" ) == 0 ) {
1300 case ACL_STYLE_REGEX:
1301 case ACL_STYLE_BASE:
1302 /* legal, traditional */
1303 case ACL_STYLE_EXPAND:
1304 /* cheap replacement to regex for simple expansion */
1306 case ACL_STYLE_IPV6:
1307 case ACL_STYLE_PATH:
1308 /* legal, peername specific */
1312 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1313 "inappropriate style \"%s\" in by clause.\n",
1314 fname, lineno, style );
1318 if ( right == NULL || right[0] == '\0' ) {
1319 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1320 "missing \"=\" in (or value after) \"%s\" "
1322 fname, lineno, left );
1326 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1327 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1328 "peername pattern already specified.\n",
1333 b->a_peername_style = sty;
1334 if ( sty == ACL_STYLE_REGEX ) {
1335 acl_regex_normalized_dn( right, &bv );
1336 if ( !ber_bvccmp( &bv, '*' ) ) {
1337 regtest( fname, lineno, bv.bv_val );
1339 b->a_peername_pat = bv;
1342 ber_str2bv( right, 0, 1, &b->a_peername_pat );
1344 if ( sty == ACL_STYLE_IP ) {
1349 split( right, '{', &addr, &port );
1350 split( addr, '%', &addr, &mask );
1352 b->a_peername_addr = inet_addr( addr );
1353 if ( b->a_peername_addr == (unsigned long)(-1) ) {
1354 /* illegal address */
1355 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1356 "illegal peername address \"%s\".\n",
1357 fname, lineno, addr );
1361 b->a_peername_mask = (unsigned long)(-1);
1362 if ( mask != NULL ) {
1363 b->a_peername_mask = inet_addr( mask );
1364 if ( b->a_peername_mask ==
1365 (unsigned long)(-1) )
1368 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1369 "illegal peername address mask "
1371 fname, lineno, mask );
1376 b->a_peername_port = -1;
1380 b->a_peername_port = strtol( port, &end, 10 );
1381 if ( end == port || end[0] != '}' ) {
1383 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1384 "illegal peername port specification "
1386 fname, lineno, port );
1391 #ifdef LDAP_PF_INET6
1392 } else if ( sty == ACL_STYLE_IPV6 ) {
1397 split( right, '{', &addr, &port );
1398 split( addr, '%', &addr, &mask );
1400 if ( inet_pton( AF_INET6, addr, &b->a_peername_addr6 ) != 1 ) {
1401 /* illegal address */
1402 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1403 "illegal peername address \"%s\".\n",
1404 fname, lineno, addr );
1408 if ( mask == NULL ) {
1409 mask = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
1412 if ( inet_pton( AF_INET6, mask, &b->a_peername_mask6 ) != 1 ) {
1414 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1415 "illegal peername address mask "
1417 fname, lineno, mask );
1421 b->a_peername_port = -1;
1425 b->a_peername_port = strtol( port, &end, 10 );
1426 if ( end == port || end[0] != '}' ) {
1428 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1429 "illegal peername port specification "
1431 fname, lineno, port );
1435 #endif /* LDAP_PF_INET6 */
1441 if ( strcasecmp( left, "sockname" ) == 0 ) {
1443 case ACL_STYLE_REGEX:
1444 case ACL_STYLE_BASE:
1445 /* legal, traditional */
1446 case ACL_STYLE_EXPAND:
1447 /* cheap replacement to regex for simple expansion */
1452 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1453 "inappropriate style \"%s\" in by clause\n",
1454 fname, lineno, style );
1458 if ( right == NULL || right[0] == '\0' ) {
1459 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1460 "missing \"=\" in (or value after) \"%s\" "
1462 fname, lineno, left );
1466 if ( !BER_BVISNULL( &b->a_sockname_pat ) ) {
1467 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1468 "sockname pattern already specified.\n",
1473 b->a_sockname_style = sty;
1474 if ( sty == ACL_STYLE_REGEX ) {
1475 acl_regex_normalized_dn( right, &bv );
1476 if ( !ber_bvccmp( &bv, '*' ) ) {
1477 regtest( fname, lineno, bv.bv_val );
1479 b->a_sockname_pat = bv;
1482 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
1487 if ( strcasecmp( left, "domain" ) == 0 ) {
1489 case ACL_STYLE_REGEX:
1490 case ACL_STYLE_BASE:
1491 case ACL_STYLE_SUBTREE:
1492 /* legal, traditional */
1495 case ACL_STYLE_EXPAND:
1496 /* tolerated: means exact,expand */
1498 Debug( LDAP_DEBUG_ANY,
1500 "\"expand\" modifier "
1501 "with \"expand\" style.\n",
1504 sty = ACL_STYLE_BASE;
1510 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1511 "inappropriate style \"%s\" in by clause.\n",
1512 fname, lineno, style );
1516 if ( right == NULL || right[0] == '\0' ) {
1517 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1518 "missing \"=\" in (or value after) \"%s\" "
1520 fname, lineno, left );
1524 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1525 Debug( LDAP_DEBUG_ANY,
1526 "%s: line %d: domain pattern already specified.\n",
1531 b->a_domain_style = sty;
1532 b->a_domain_expand = expand;
1533 if ( sty == ACL_STYLE_REGEX ) {
1534 acl_regex_normalized_dn( right, &bv );
1535 if ( !ber_bvccmp( &bv, '*' ) ) {
1536 regtest( fname, lineno, bv.bv_val );
1538 b->a_domain_pat = bv;
1541 ber_str2bv( right, 0, 1, &b->a_domain_pat );
1546 if ( strcasecmp( left, "sockurl" ) == 0 ) {
1548 case ACL_STYLE_REGEX:
1549 case ACL_STYLE_BASE:
1550 /* legal, traditional */
1551 case ACL_STYLE_EXPAND:
1552 /* cheap replacement to regex for simple expansion */
1557 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1558 "inappropriate style \"%s\" in by clause.\n",
1559 fname, lineno, style );
1563 if ( right == NULL || right[0] == '\0' ) {
1564 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1565 "missing \"=\" in (or value after) \"%s\" "
1567 fname, lineno, left );
1571 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1572 Debug( LDAP_DEBUG_ANY,
1573 "%s: line %d: sockurl pattern already specified.\n",
1578 b->a_sockurl_style = sty;
1579 if ( sty == ACL_STYLE_REGEX ) {
1580 acl_regex_normalized_dn( right, &bv );
1581 if ( !ber_bvccmp( &bv, '*' ) ) {
1582 regtest( fname, lineno, bv.bv_val );
1584 b->a_sockurl_pat = bv;
1587 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
1592 if ( strcasecmp( left, "set" ) == 0 ) {
1595 case ACL_STYLE_REGEX:
1596 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
1598 "deprecated set style "
1599 "\"regex\" in <by> clause; "
1600 "use \"expand\" instead.\n",
1602 sty = ACL_STYLE_EXPAND;
1605 case ACL_STYLE_BASE:
1606 case ACL_STYLE_EXPAND:
1610 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1611 "inappropriate style \"%s\" in by clause.\n",
1612 fname, lineno, style );
1616 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1617 Debug( LDAP_DEBUG_ANY,
1618 "%s: line %d: set attribute already specified.\n",
1623 if ( right == NULL || *right == '\0' ) {
1624 Debug( LDAP_DEBUG_ANY,
1625 "%s: line %d: no set is defined.\n",
1630 b->a_set_style = sty;
1631 ber_str2bv( right, 0, 1, &b->a_set_pat );
1641 #if 1 /* tolerate legacy "aci" <who> */
1642 if ( strcasecmp( left, "aci" ) == 0 ) {
1643 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1644 "undocumented deprecated \"aci\" directive "
1645 "is superseded by \"dynacl/aci\".\n",
1650 #endif /* tolerate legacy "aci" <who> */
1651 if ( strncasecmp( left, "dynacl/", STRLENOF( "dynacl/" ) ) == 0 ) {
1652 name = &left[ STRLENOF( "dynacl/" ) ];
1653 opts = strchr( name, '/' );
1661 if ( slap_dynacl_config( fname, lineno, b, name, opts, sty, right ) ) {
1662 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1663 "unable to configure dynacl \"%s\".\n",
1664 fname, lineno, name );
1671 #endif /* SLAP_DYNACL */
1673 if ( strcasecmp( left, "ssf" ) == 0 ) {
1674 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1675 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1676 "inappropriate style \"%s\" in by clause.\n",
1677 fname, lineno, style );
1681 if ( b->a_authz.sai_ssf ) {
1682 Debug( LDAP_DEBUG_ANY,
1683 "%s: line %d: ssf attribute already specified.\n",
1688 if ( right == NULL || *right == '\0' ) {
1689 Debug( LDAP_DEBUG_ANY,
1690 "%s: line %d: no ssf is defined.\n",
1695 if ( lutil_atou( &b->a_authz.sai_ssf, right ) != 0 ) {
1696 Debug( LDAP_DEBUG_ANY,
1697 "%s: line %d: unable to parse ssf value (%s).\n",
1698 fname, lineno, right );
1702 if ( !b->a_authz.sai_ssf ) {
1703 Debug( LDAP_DEBUG_ANY,
1704 "%s: line %d: invalid ssf value (%s).\n",
1705 fname, lineno, right );
1711 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
1712 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1713 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1714 "inappropriate style \"%s\" in by clause.\n",
1715 fname, lineno, style );
1719 if ( b->a_authz.sai_transport_ssf ) {
1720 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1721 "transport_ssf attribute already specified.\n",
1726 if ( right == NULL || *right == '\0' ) {
1727 Debug( LDAP_DEBUG_ANY,
1728 "%s: line %d: no transport_ssf is defined.\n",
1733 if ( lutil_atou( &b->a_authz.sai_transport_ssf, right ) != 0 ) {
1734 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1735 "unable to parse transport_ssf value (%s).\n",
1736 fname, lineno, right );
1740 if ( !b->a_authz.sai_transport_ssf ) {
1741 Debug( LDAP_DEBUG_ANY,
1742 "%s: line %d: invalid transport_ssf value (%s).\n",
1743 fname, lineno, right );
1749 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
1750 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1751 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1752 "inappropriate style \"%s\" in by clause.\n",
1753 fname, lineno, style );
1757 if ( b->a_authz.sai_tls_ssf ) {
1758 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1759 "tls_ssf attribute already specified.\n",
1764 if ( right == NULL || *right == '\0' ) {
1765 Debug( LDAP_DEBUG_ANY,
1766 "%s: line %d: no tls_ssf is defined\n",
1771 if ( lutil_atou( &b->a_authz.sai_tls_ssf, right ) != 0 ) {
1772 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1773 "unable to parse tls_ssf value (%s).\n",
1774 fname, lineno, right );
1778 if ( !b->a_authz.sai_tls_ssf ) {
1779 Debug( LDAP_DEBUG_ANY,
1780 "%s: line %d: invalid tls_ssf value (%s).\n",
1781 fname, lineno, right );
1787 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1788 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1789 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1790 "inappropriate style \"%s\" in by clause.\n",
1791 fname, lineno, style );
1795 if ( b->a_authz.sai_sasl_ssf ) {
1796 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1797 "sasl_ssf attribute already specified.\n",
1802 if ( right == NULL || *right == '\0' ) {
1803 Debug( LDAP_DEBUG_ANY,
1804 "%s: line %d: no sasl_ssf is defined.\n",
1809 if ( lutil_atou( &b->a_authz.sai_sasl_ssf, right ) != 0 ) {
1810 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1811 "unable to parse sasl_ssf value (%s).\n",
1812 fname, lineno, right );
1816 if ( !b->a_authz.sai_sasl_ssf ) {
1817 Debug( LDAP_DEBUG_ANY,
1818 "%s: line %d: invalid sasl_ssf value (%s).\n",
1819 fname, lineno, right );
1825 if ( right != NULL ) {
1832 if ( i == argc || ( strcasecmp( left, "stop" ) == 0 ) ) {
1833 /* out of arguments or plain stop */
1835 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1836 ACL_PRIV_SET( b->a_access_mask, ACL_PRIV_NONE);
1837 b->a_type = ACL_STOP;
1839 access_append( &a->acl_access, b );
1843 if ( strcasecmp( left, "continue" ) == 0 ) {
1844 /* plain continue */
1846 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1847 ACL_PRIV_SET( b->a_access_mask, ACL_PRIV_NONE);
1848 b->a_type = ACL_CONTINUE;
1850 access_append( &a->acl_access, b );
1854 if ( strcasecmp( left, "break" ) == 0 ) {
1855 /* plain continue */
1857 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1858 ACL_PRIV_SET( b->a_access_mask, ACL_PRIV_NONE);
1859 b->a_type = ACL_BREAK;
1861 access_append( &a->acl_access, b );
1865 if ( strcasecmp( left, "by" ) == 0 ) {
1866 /* we've gone too far */
1868 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1869 ACL_PRIV_SET( b->a_access_mask, ACL_PRIV_NONE);
1870 b->a_type = ACL_STOP;
1872 access_append( &a->acl_access, b );
1880 if ( strncasecmp( left, "self", STRLENOF( "self" ) ) == 0 ) {
1882 lleft = &left[ STRLENOF( "self" ) ];
1884 } else if ( strncasecmp( left, "realself", STRLENOF( "realself" ) ) == 0 ) {
1885 b->a_realdn_self = 1;
1886 lleft = &left[ STRLENOF( "realself" ) ];
1889 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( lleft ) );
1892 if ( ACL_IS_INVALID( b->a_access_mask ) ) {
1893 Debug( LDAP_DEBUG_ANY,
1894 "%s: line %d: expecting <access> got \"%s\".\n",
1895 fname, lineno, left );
1899 b->a_type = ACL_STOP;
1901 if ( ++i == argc ) {
1902 /* out of arguments or plain stop */
1903 access_append( &a->acl_access, b );
1907 if ( strcasecmp( argv[i], "continue" ) == 0 ) {
1908 /* plain continue */
1909 b->a_type = ACL_CONTINUE;
1911 } else if ( strcasecmp( argv[i], "break" ) == 0 ) {
1912 /* plain continue */
1913 b->a_type = ACL_BREAK;
1915 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1920 access_append( &a->acl_access, b );
1924 Debug( LDAP_DEBUG_ANY,
1925 "%s: line %d: expecting \"to\" "
1926 "or \"by\" got \"%s\"\n",
1927 fname, lineno, argv[i] );
1932 /* if we have no real access clause, complain and do nothing */
1934 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1935 "warning: no access clause(s) specified in access line.\n",
1941 if ( slap_debug & LDAP_DEBUG_ACL ) {
1946 if ( a->acl_access == NULL ) {
1947 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1948 "warning: no by clause(s) specified in access line.\n",
1954 if ( be->be_nsuffix == NULL ) {
1955 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1956 "scope checking needs suffix before ACLs.\n",
1958 /* go ahead, since checking is not authoritative */
1959 } else if ( !BER_BVISNULL( &be->be_nsuffix[ 1 ] ) ) {
1960 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1961 "scope checking only applies to single-valued "
1962 "suffix databases\n",
1964 /* go ahead, since checking is not authoritative */
1966 switch ( check_scope( be, a ) ) {
1967 case ACL_SCOPE_UNKNOWN:
1968 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1969 "cannot assess the validity of the ACL scope within "
1970 "backend naming context\n",
1974 case ACL_SCOPE_WARN:
1975 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1976 "ACL could be out of scope within backend naming context\n",
1980 case ACL_SCOPE_PARTIAL:
1981 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1982 "ACL appears to be partially out of scope within "
1983 "backend naming context\n",
1988 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1989 "ACL appears to be out of scope within "
1990 "backend naming context\n",
1998 acl_append( &be->be_acl, a, pos );
2001 acl_append( &frontendDB->be_acl, a, pos );
2008 if ( b ) access_free( b );
2009 if ( a ) acl_free( a );
2014 accessmask2str( slap_mask_t mask, char *buf, int debug )
2019 assert( buf != NULL );
2021 if ( ACL_IS_INVALID( mask ) ) {
2027 if ( ACL_IS_LEVEL( mask ) ) {
2028 if ( ACL_LVL_IS_NONE(mask) ) {
2029 ptr = lutil_strcopy( ptr, "none" );
2031 } else if ( ACL_LVL_IS_DISCLOSE(mask) ) {
2032 ptr = lutil_strcopy( ptr, "disclose" );
2034 } else if ( ACL_LVL_IS_AUTH(mask) ) {
2035 ptr = lutil_strcopy( ptr, "auth" );
2037 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
2038 ptr = lutil_strcopy( ptr, "compare" );
2040 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
2041 ptr = lutil_strcopy( ptr, "search" );
2043 } else if ( ACL_LVL_IS_READ(mask) ) {
2044 ptr = lutil_strcopy( ptr, "read" );
2046 } else if ( ACL_LVL_IS_WRITE(mask) ) {
2047 ptr = lutil_strcopy( ptr, "write" );
2049 } else if ( ACL_LVL_IS_WADD(mask) ) {
2050 ptr = lutil_strcopy( ptr, "add" );
2052 } else if ( ACL_LVL_IS_WDEL(mask) ) {
2053 ptr = lutil_strcopy( ptr, "delete" );
2055 } else if ( ACL_LVL_IS_MANAGE(mask) ) {
2056 ptr = lutil_strcopy( ptr, "manage" );
2059 ptr = lutil_strcopy( ptr, "unknown" );
2069 if( ACL_IS_ADDITIVE( mask ) ) {
2072 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
2079 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_MANAGE) ) {
2084 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
2088 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WADD) ) {
2092 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WDEL) ) {
2097 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
2102 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
2107 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
2112 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
2117 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_DISCLOSE) ) {
2122 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
2131 if ( ACL_IS_LEVEL( mask ) ) {
2141 str2accessmask( const char *str )
2145 if( !ASCII_ALPHA(str[0]) ) {
2148 if ( str[0] == '=' ) {
2151 } else if( str[0] == '+' ) {
2152 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
2154 } else if( str[0] == '-' ) {
2155 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
2158 ACL_INVALIDATE(mask);
2162 for( i=1; str[i] != '\0'; i++ ) {
2163 if( TOLOWER((unsigned char) str[i]) == 'm' ) {
2164 ACL_PRIV_SET(mask, ACL_PRIV_MANAGE);
2166 } else if( TOLOWER((unsigned char) str[i]) == 'w' ) {
2167 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
2169 } else if( TOLOWER((unsigned char) str[i]) == 'a' ) {
2170 ACL_PRIV_SET(mask, ACL_PRIV_WADD);
2172 } else if( TOLOWER((unsigned char) str[i]) == 'z' ) {
2173 ACL_PRIV_SET(mask, ACL_PRIV_WDEL);
2175 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
2176 ACL_PRIV_SET(mask, ACL_PRIV_READ);
2178 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
2179 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
2181 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
2182 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
2184 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
2185 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
2187 } else if( TOLOWER((unsigned char) str[i]) == 'd' ) {
2188 ACL_PRIV_SET(mask, ACL_PRIV_DISCLOSE);
2190 } else if( str[i] == '0' ) {
2191 ACL_PRIV_SET(mask, ACL_PRIV_NONE);
2194 ACL_INVALIDATE(mask);
2202 if ( strcasecmp( str, "none" ) == 0 ) {
2203 ACL_LVL_ASSIGN_NONE(mask);
2205 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2206 ACL_LVL_ASSIGN_DISCLOSE(mask);
2208 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2209 ACL_LVL_ASSIGN_AUTH(mask);
2211 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2212 ACL_LVL_ASSIGN_COMPARE(mask);
2214 } else if ( strcasecmp( str, "search" ) == 0 ) {
2215 ACL_LVL_ASSIGN_SEARCH(mask);
2217 } else if ( strcasecmp( str, "read" ) == 0 ) {
2218 ACL_LVL_ASSIGN_READ(mask);
2220 } else if ( strcasecmp( str, "add" ) == 0 ) {
2221 ACL_LVL_ASSIGN_WADD(mask);
2223 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2224 ACL_LVL_ASSIGN_WDEL(mask);
2226 } else if ( strcasecmp( str, "write" ) == 0 ) {
2227 ACL_LVL_ASSIGN_WRITE(mask);
2229 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2230 ACL_LVL_ASSIGN_MANAGE(mask);
2233 ACL_INVALIDATE( mask );
2243 "<access clause> ::= access to <what> "
2244 "[ by <who> [ <access> ] [ <control> ] ]+ \n";
2246 "<what> ::= * | dn[.<dnstyle>=<DN>] [filter=<filter>] [attrs=<attrspec>]\n"
2247 "<attrspec> ::= <attrname> [val[/<matchingRule>][.<attrstyle>]=<value>] | <attrlist>\n"
2248 "<attrlist> ::= <attr> [ , <attrlist> ]\n"
2249 "<attr> ::= <attrname> | @<objectClass> | !<objectClass> | entry | children\n";
2252 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
2253 "\t[ realanonymous | realusers | realself | realdn[.<dnstyle>]=<DN> ]\n"
2254 "\t[dnattr=<attrname>]\n"
2255 "\t[realdnattr=<attrname>]\n"
2256 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
2257 "\t[peername[.<peernamestyle>]=<peer>] [sockname[.<style>]=<name>]\n"
2258 "\t[domain[.<domainstyle>]=<domain>] [sockurl[.<style>]=<url>]\n"
2260 "\t[dynacl/<name>[/<options>][.<dynstyle>][=<pattern>]]\n"
2261 #endif /* SLAP_DYNACL */
2262 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
2263 "<style> ::= exact | regex | base(Object)\n"
2264 "<dnstyle> ::= base(Object) | one(level) | sub(tree) | children | "
2266 "<attrstyle> ::= exact | regex | base(Object) | one(level) | "
2267 "sub(tree) | children\n"
2268 "<peernamestyle> ::= exact | regex | ip | ipv6 | path\n"
2269 "<domainstyle> ::= exact | regex | base(Object) | sub(tree)\n"
2270 "<access> ::= [[real]self]{<level>|<priv>}\n"
2271 "<level> ::= none|disclose|auth|compare|search|read|{write|add|delete}|manage\n"
2272 "<priv> ::= {=|+|-}{0|d|x|c|s|r|{w|a|z}|m}+\n"
2273 "<control> ::= [ stop | continue | break ]\n"
2275 #ifdef SLAPD_ACI_ENABLED
2277 "\t<name>=ACI\t<pattern>=<attrname>\n"
2278 #endif /* SLAPD_ACI_ENABLED */
2279 #endif /* ! SLAP_DYNACL */
2282 Debug( LDAP_DEBUG_ANY, "%s%s%s\n", access, what, who );
2288 * Set pattern to a "normalized" DN from src.
2289 * At present it simply eats the (optional) space after
2290 * a RDN separator (,)
2291 * Eventually will evolve in a more complete normalization
2294 acl_regex_normalized_dn(
2296 struct berval *pattern )
2301 str = ch_strdup( src );
2302 len = strlen( src );
2304 for ( p = str; p && p[0]; p++ ) {
2306 if ( p[0] == '\\' && p[1] ) {
2308 * if escaping a hex pair we should
2309 * increment p twice; however, in that
2310 * case the second hex number does
2316 if ( p[0] == ',' && p[1] == ' ' ) {
2320 * too much space should be an error if we are pedantic
2322 for ( q = &p[2]; q[0] == ' '; q++ ) {
2325 AC_MEMCPY( p+1, q, len-(q-str)+1);
2328 pattern->bv_val = str;
2329 pattern->bv_len = p - str;
2342 if ( (*right = strchr( line, splitchar )) != NULL ) {
2343 *((*right)++) = '\0';
2348 access_append( Access **l, Access *a )
2350 for ( ; *l != NULL; l = &(*l)->a_next ) {
2358 acl_append( AccessControl **l, AccessControl *a, int pos )
2362 for (i=0 ; i != pos && *l != NULL; l = &(*l)->acl_next, i++ ) {
2371 access_free( Access *a )
2373 if ( !BER_BVISNULL( &a->a_dn_pat ) ) {
2374 free( a->a_dn_pat.bv_val );
2376 if ( !BER_BVISNULL( &a->a_realdn_pat ) ) {
2377 free( a->a_realdn_pat.bv_val );
2379 if ( !BER_BVISNULL( &a->a_peername_pat ) ) {
2380 free( a->a_peername_pat.bv_val );
2382 if ( !BER_BVISNULL( &a->a_sockname_pat ) ) {
2383 free( a->a_sockname_pat.bv_val );
2385 if ( !BER_BVISNULL( &a->a_domain_pat ) ) {
2386 free( a->a_domain_pat.bv_val );
2388 if ( !BER_BVISNULL( &a->a_sockurl_pat ) ) {
2389 free( a->a_sockurl_pat.bv_val );
2391 if ( !BER_BVISNULL( &a->a_set_pat ) ) {
2392 free( a->a_set_pat.bv_val );
2394 if ( !BER_BVISNULL( &a->a_group_pat ) ) {
2395 free( a->a_group_pat.bv_val );
2398 if ( a->a_dynacl != NULL ) {
2400 for ( da = a->a_dynacl; da; ) {
2401 slap_dynacl_t *tmp = da;
2405 if ( tmp->da_destroy ) {
2406 tmp->da_destroy( tmp->da_private );
2412 #endif /* SLAP_DYNACL */
2417 acl_free( AccessControl *a )
2422 if ( a->acl_filter ) {
2423 filter_free( a->acl_filter );
2425 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2426 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
2427 regfree( &a->acl_dn_re );
2429 free ( a->acl_dn_pat.bv_val );
2431 if ( a->acl_attrs ) {
2432 for ( an = a->acl_attrs; !BER_BVISNULL( &an->an_name ); an++ ) {
2433 free( an->an_name.bv_val );
2435 free( a->acl_attrs );
2437 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
2438 regfree( &a->acl_attrval_re );
2441 if ( !BER_BVISNULL( &a->acl_attrval ) ) {
2442 ber_memfree( a->acl_attrval.bv_val );
2445 for ( ; a->acl_access; a->acl_access = n ) {
2446 n = a->acl_access->a_next;
2447 access_free( a->acl_access );
2452 /* Because backend_startup uses acl_append to tack on the global_acl to
2453 * the end of each backend's acl, we cannot just take one argument and
2454 * merrily free our way to the end of the list. backend_destroy calls us
2455 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
2456 * point. config_destroy calls us with global_acl in arg1 and NULL in
2457 * arg2, so we then proceed to polish off the global_acl.
2460 acl_destroy( AccessControl *a, AccessControl *end )
2464 for ( ; a && a != end; a = n ) {
2471 access2str( slap_access_t access )
2473 if ( access == ACL_NONE ) {
2476 } else if ( access == ACL_DISCLOSE ) {
2479 } else if ( access == ACL_AUTH ) {
2482 } else if ( access == ACL_COMPARE ) {
2485 } else if ( access == ACL_SEARCH ) {
2488 } else if ( access == ACL_READ ) {
2491 } else if ( access == ACL_WRITE ) {
2494 } else if ( access == ACL_WADD ) {
2497 } else if ( access == ACL_WDEL ) {
2500 } else if ( access == ACL_MANAGE ) {
2509 str2access( const char *str )
2511 if ( strcasecmp( str, "none" ) == 0 ) {
2514 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2515 return ACL_DISCLOSE;
2517 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2520 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2523 } else if ( strcasecmp( str, "search" ) == 0 ) {
2526 } else if ( strcasecmp( str, "read" ) == 0 ) {
2529 } else if ( strcasecmp( str, "write" ) == 0 ) {
2532 } else if ( strcasecmp( str, "add" ) == 0 ) {
2535 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2538 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2542 return( ACL_INVALID_ACCESS );
2545 #define ACLBUF_MAXLEN 8192
2547 static char aclbuf[ACLBUF_MAXLEN];
2550 dnaccess2text( slap_dn_access *bdn, char *ptr, int is_realdn )
2555 ptr = lutil_strcopy( ptr, "real" );
2558 if ( ber_bvccmp( &bdn->a_pat, '*' ) ||
2559 bdn->a_style == ACL_STYLE_ANONYMOUS ||
2560 bdn->a_style == ACL_STYLE_USERS ||
2561 bdn->a_style == ACL_STYLE_SELF )
2564 assert( ! ber_bvccmp( &bdn->a_pat, '*' ) );
2567 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2568 if ( bdn->a_style == ACL_STYLE_SELF && bdn->a_self_level != 0 ) {
2569 int n = sprintf( ptr, ".level{%d}", bdn->a_self_level );
2576 ptr = lutil_strcopy( ptr, "dn." );
2577 if ( bdn->a_style == ACL_STYLE_BASE )
2578 ptr = lutil_strcopy( ptr, style_base );
2580 ptr = lutil_strcopy( ptr, style_strings[bdn->a_style] );
2581 if ( bdn->a_style == ACL_STYLE_LEVEL ) {
2582 int n = sprintf( ptr, "{%d}", bdn->a_level );
2587 if ( bdn->a_expand ) {
2588 ptr = lutil_strcopy( ptr, ",expand" );
2592 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2599 access2text( Access *b, char *ptr )
2601 char maskbuf[ACCESSMASK_MAXLEN];
2603 ptr = lutil_strcopy( ptr, "\tby" );
2605 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
2606 ptr = dnaccess2text( &b->a_dn, ptr, 0 );
2609 ptr = lutil_strcopy( ptr, " dnattr=" );
2610 ptr = lutil_strcopy( ptr, b->a_dn_at->ad_cname.bv_val );
2613 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
2614 ptr = dnaccess2text( &b->a_realdn, ptr, 1 );
2616 if ( b->a_realdn_at ) {
2617 ptr = lutil_strcopy( ptr, " realdnattr=" );
2618 ptr = lutil_strcopy( ptr, b->a_realdn_at->ad_cname.bv_val );
2621 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
2622 ptr = lutil_strcopy( ptr, " group/" );
2623 ptr = lutil_strcopy( ptr, b->a_group_oc ?
2624 b->a_group_oc->soc_cname.bv_val : SLAPD_GROUP_CLASS );
2626 ptr = lutil_strcopy( ptr, b->a_group_at ?
2627 b->a_group_at->ad_cname.bv_val : SLAPD_GROUP_ATTR );
2629 ptr = lutil_strcopy( ptr, style_strings[b->a_group_style] );
2632 ptr = lutil_strcopy( ptr, b->a_group_pat.bv_val );
2636 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
2637 ptr = lutil_strcopy( ptr, " peername" );
2639 ptr = lutil_strcopy( ptr, style_strings[b->a_peername_style] );
2642 ptr = lutil_strcopy( ptr, b->a_peername_pat.bv_val );
2646 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
2647 ptr = lutil_strcopy( ptr, " sockname" );
2649 ptr = lutil_strcopy( ptr, style_strings[b->a_sockname_style] );
2652 ptr = lutil_strcopy( ptr, b->a_sockname_pat.bv_val );
2656 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
2657 ptr = lutil_strcopy( ptr, " domain" );
2659 ptr = lutil_strcopy( ptr, style_strings[b->a_domain_style] );
2660 if ( b->a_domain_expand ) {
2661 ptr = lutil_strcopy( ptr, ",expand" );
2664 ptr = lutil_strcopy( ptr, b->a_domain_pat.bv_val );
2667 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
2668 ptr = lutil_strcopy( ptr, " sockurl" );
2670 ptr = lutil_strcopy( ptr, style_strings[b->a_sockurl_style] );
2673 ptr = lutil_strcopy( ptr, b->a_sockurl_pat.bv_val );
2677 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
2678 ptr = lutil_strcopy( ptr, " set" );
2680 ptr = lutil_strcopy( ptr, style_strings[b->a_set_style] );
2683 ptr = lutil_strcopy( ptr, b->a_set_pat.bv_val );
2688 if ( b->a_dynacl ) {
2691 for ( da = b->a_dynacl; da; da = da->da_next ) {
2692 if ( da->da_unparse ) {
2693 struct berval bv = BER_BVNULL;
2694 (void)( *da->da_unparse )( da->da_private, &bv );
2695 assert( !BER_BVISNULL( &bv ) );
2696 ptr = lutil_strcopy( ptr, bv.bv_val );
2697 ch_free( bv.bv_val );
2701 #endif /* SLAP_DYNACL */
2703 /* Security Strength Factors */
2704 if ( b->a_authz.sai_ssf ) {
2705 ptr += sprintf( ptr, " ssf=%u",
2706 b->a_authz.sai_ssf );
2708 if ( b->a_authz.sai_transport_ssf ) {
2709 ptr += sprintf( ptr, " transport_ssf=%u",
2710 b->a_authz.sai_transport_ssf );
2712 if ( b->a_authz.sai_tls_ssf ) {
2713 ptr += sprintf( ptr, " tls_ssf=%u",
2714 b->a_authz.sai_tls_ssf );
2716 if ( b->a_authz.sai_sasl_ssf ) {
2717 ptr += sprintf( ptr, " sasl_ssf=%u",
2718 b->a_authz.sai_sasl_ssf );
2722 if ( b->a_dn_self ) {
2723 ptr = lutil_strcopy( ptr, "self" );
2724 } else if ( b->a_realdn_self ) {
2725 ptr = lutil_strcopy( ptr, "realself" );
2727 ptr = lutil_strcopy( ptr, accessmask2str( b->a_access_mask, maskbuf, 0 ));
2728 if ( !maskbuf[0] ) ptr--;
2730 if( b->a_type == ACL_BREAK ) {
2731 ptr = lutil_strcopy( ptr, " break" );
2733 } else if( b->a_type == ACL_CONTINUE ) {
2734 ptr = lutil_strcopy( ptr, " continue" );
2736 } else if( b->a_type != ACL_STOP ) {
2737 ptr = lutil_strcopy( ptr, " unknown-control" );
2739 if ( !maskbuf[0] ) ptr = lutil_strcopy( ptr, " stop" );
2747 acl_unparse( AccessControl *a, struct berval *bv )
2753 bv->bv_val = aclbuf;
2758 ptr = lutil_strcopy( ptr, "to" );
2759 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2761 ptr = lutil_strcopy( ptr, " dn." );
2762 if ( a->acl_dn_style == ACL_STYLE_BASE )
2763 ptr = lutil_strcopy( ptr, style_base );
2765 ptr = lutil_strcopy( ptr, style_strings[a->acl_dn_style] );
2768 ptr = lutil_strcopy( ptr, a->acl_dn_pat.bv_val );
2769 ptr = lutil_strcopy( ptr, "\"\n" );
2772 if ( a->acl_filter != NULL ) {
2773 struct berval bv = BER_BVNULL;
2776 filter2bv( a->acl_filter, &bv );
2777 ptr = lutil_strcopy( ptr, " filter=\"" );
2778 ptr = lutil_strcopy( ptr, bv.bv_val );
2781 ch_free( bv.bv_val );
2784 if ( a->acl_attrs != NULL ) {
2789 ptr = lutil_strcopy( ptr, " attrs=" );
2790 for ( an = a->acl_attrs; an && !BER_BVISNULL( &an->an_name ); an++ ) {
2791 if ( ! first ) *ptr++ = ',';
2793 *ptr++ = an->an_oc_exclude ? '!' : '@';
2794 ptr = lutil_strcopy( ptr, an->an_oc->soc_cname.bv_val );
2797 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2804 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
2806 ptr = lutil_strcopy( ptr, " val." );
2807 if ( a->acl_attrval_style == ACL_STYLE_BASE &&
2808 a->acl_attrs[0].an_desc->ad_type->sat_syntax ==
2809 slap_schema.si_syn_distinguishedName )
2810 ptr = lutil_strcopy( ptr, style_base );
2812 ptr = lutil_strcopy( ptr, style_strings[a->acl_attrval_style] );
2815 ptr = lutil_strcopy( ptr, a->acl_attrval.bv_val );
2821 ptr = lutil_strcopy( ptr, " *\n" );
2824 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
2825 ptr = access2text( b, ptr );
2828 bv->bv_len = ptr - bv->bv_val;
2833 print_acl( Backend *be, AccessControl *a )
2837 acl_unparse( a, &bv );
2838 fprintf( stderr, "%s ACL: access %s\n",
2839 be == NULL ? "Global" : "Backend", bv.bv_val );
2841 #endif /* LDAP_DEBUG */