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-2006 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[] = {
59 static void split(char *line, int splitchar, char **left, char **right);
60 static void access_append(Access **l, Access *a);
61 static void access_free( Access *a );
62 static int acl_usage(void);
64 static void acl_regex_normalized_dn(const char *src, struct berval *pat);
67 static void print_acl(Backend *be, AccessControl *a);
70 static int check_scope( BackendDB *be, AccessControl *a );
83 slap_dynacl_t *da, *tmp;
86 for ( da = b->a_dynacl; da; da = da->da_next ) {
87 if ( strcasecmp( da->da_name, name ) == 0 ) {
88 Debug( LDAP_DEBUG_ANY,
89 "%s: line %d: dynacl \"%s\" already specified.\n",
90 fname, lineno, name );
95 da = slap_dynacl_get( name );
100 tmp = ch_malloc( sizeof( slap_dynacl_t ) );
103 if ( tmp->da_parse ) {
104 rc = ( *tmp->da_parse )( fname, lineno, opts, sty, right, &tmp->da_private );
111 tmp->da_next = b->a_dynacl;
116 #endif /* SLAP_DYNACL */
119 regtest(const char *fname, int lineno, char *pat) {
123 char buf[ SLAP_TEXT_BUFLEN ];
135 for (size = 0, flag = 0; (size < sizeof(buf)) && *sp; sp++) {
137 if (*sp == '$'|| (*sp >= '0' && *sp <= '9')) {
154 if ( size >= (sizeof(buf) - 1) ) {
155 Debug( LDAP_DEBUG_ANY,
156 "%s: line %d: regular expression \"%s\" too large\n",
157 fname, lineno, pat );
159 exit( EXIT_FAILURE );
162 if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
163 char error[ SLAP_TEXT_BUFLEN ];
165 regerror(e, &re, error, sizeof(error));
167 snprintf( buf, sizeof( buf ),
168 "regular expression \"%s\" bad because of %s",
170 Debug( LDAP_DEBUG_ANY,
172 fname, lineno, buf );
174 exit( EXIT_FAILURE );
182 * Check if the pattern of an ACL, if any, matches the scope
183 * of the backend it is defined within.
185 #define ACL_SCOPE_UNKNOWN (-2)
186 #define ACL_SCOPE_ERR (-1)
187 #define ACL_SCOPE_OK (0)
188 #define ACL_SCOPE_PARTIAL (1)
189 #define ACL_SCOPE_WARN (2)
192 check_scope( BackendDB *be, AccessControl *a )
197 dn = be->be_nsuffix[0];
199 if ( BER_BVISEMPTY( &dn ) ) {
203 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
204 a->acl_dn_style != ACL_STYLE_REGEX )
206 slap_style_t style = a->acl_dn_style;
208 if ( style == ACL_STYLE_REGEX ) {
209 char dnbuf[SLAP_LDAPDN_MAXLEN + 2];
210 char rebuf[SLAP_LDAPDN_MAXLEN + 1];
215 /* add trailing '$' to database suffix to form
216 * a simple trial regex pattern "<suffix>$" */
217 AC_MEMCPY( dnbuf, be->be_nsuffix[0].bv_val,
218 be->be_nsuffix[0].bv_len );
219 dnbuf[be->be_nsuffix[0].bv_len] = '$';
220 dnbuf[be->be_nsuffix[0].bv_len + 1] = '\0';
222 if ( regcomp( &re, dnbuf, REG_EXTENDED|REG_ICASE ) ) {
223 return ACL_SCOPE_WARN;
226 /* remove trailing ')$', if any, from original
228 rebuflen = a->acl_dn_pat.bv_len;
229 AC_MEMCPY( rebuf, a->acl_dn_pat.bv_val, rebuflen + 1 );
230 if ( rebuf[rebuflen - 1] == '$' ) {
231 rebuf[--rebuflen] = '\0';
233 while ( rebuflen > be->be_nsuffix[0].bv_len && rebuf[rebuflen - 1] == ')' ) {
234 rebuf[--rebuflen] = '\0';
236 if ( rebuflen == be->be_nsuffix[0].bv_len ) {
241 /* not a clear indication of scoping error, though */
242 rc = regexec( &re, rebuf, 0, NULL, 0 )
243 ? ACL_SCOPE_WARN : ACL_SCOPE_OK;
250 patlen = a->acl_dn_pat.bv_len;
251 /* If backend suffix is longer than pattern,
252 * it is a potential mismatch (in the sense
253 * that a superior naming context could
255 if ( dn.bv_len > patlen ) {
256 /* base is blatantly wrong */
257 if ( style == ACL_STYLE_BASE ) return ACL_SCOPE_ERR;
259 /* a style of one can be wrong if there is
260 * more than one level between the suffix
262 if ( style == ACL_STYLE_ONE ) {
263 ber_len_t rdnlen = 0;
267 if ( !DN_SEPARATOR( dn.bv_val[dn.bv_len - patlen - 1] )) {
268 return ACL_SCOPE_ERR;
273 rdnlen = dn_rdnlen( NULL, &dn );
274 if ( rdnlen != dn.bv_len - patlen - sep )
275 return ACL_SCOPE_ERR;
278 /* if the trailing part doesn't match,
279 * then it's an error */
280 if ( strcmp( a->acl_dn_pat.bv_val,
281 &dn.bv_val[dn.bv_len - patlen] ) != 0 )
283 return ACL_SCOPE_ERR;
286 return ACL_SCOPE_PARTIAL;
292 case ACL_STYLE_CHILDREN:
293 case ACL_STYLE_SUBTREE:
301 if ( dn.bv_len < patlen &&
302 !DN_SEPARATOR( a->acl_dn_pat.bv_val[patlen - dn.bv_len - 1] ))
304 return ACL_SCOPE_ERR;
307 if ( strcmp( &a->acl_dn_pat.bv_val[patlen - dn.bv_len], dn.bv_val )
310 return ACL_SCOPE_ERR;
316 return ACL_SCOPE_UNKNOWN;
329 char *left, *right, *style;
331 AccessControl *a = NULL;
336 for ( i = 1; i < argc; i++ ) {
337 /* to clause - select which entries are protected */
338 if ( strcasecmp( argv[i], "to" ) == 0 ) {
340 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
341 "only one to clause allowed in access line\n",
345 a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
346 for ( ++i; i < argc; i++ ) {
347 if ( strcasecmp( argv[i], "by" ) == 0 ) {
352 if ( strcasecmp( argv[i], "*" ) == 0 ) {
353 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
354 a->acl_dn_style != ACL_STYLE_REGEX )
356 Debug( LDAP_DEBUG_ANY,
357 "%s: line %d: dn pattern"
358 " already specified in to clause.\n",
363 ber_str2bv( "*", STRLENOF( "*" ), 1, &a->acl_dn_pat );
367 split( argv[i], '=', &left, &right );
368 split( left, '.', &left, &style );
370 if ( right == NULL ) {
371 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
372 "missing \"=\" in \"%s\" in to clause\n",
373 fname, lineno, left );
377 if ( strcasecmp( left, "dn" ) == 0 ) {
378 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
379 a->acl_dn_style != ACL_STYLE_REGEX )
381 Debug( LDAP_DEBUG_ANY,
382 "%s: line %d: dn pattern"
383 " already specified in to clause.\n",
388 if ( style == NULL || *style == '\0' ||
389 strcasecmp( style, "baseObject" ) == 0 ||
390 strcasecmp( style, "base" ) == 0 ||
391 strcasecmp( style, "exact" ) == 0 )
393 a->acl_dn_style = ACL_STYLE_BASE;
394 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
396 } else if ( strcasecmp( style, "oneLevel" ) == 0 ||
397 strcasecmp( style, "one" ) == 0 )
399 a->acl_dn_style = ACL_STYLE_ONE;
400 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
402 } else if ( strcasecmp( style, "subtree" ) == 0 ||
403 strcasecmp( style, "sub" ) == 0 )
405 if( *right == '\0' ) {
406 ber_str2bv( "*", STRLENOF( "*" ), 1, &a->acl_dn_pat );
409 a->acl_dn_style = ACL_STYLE_SUBTREE;
410 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
413 } else if ( strcasecmp( style, "children" ) == 0 ) {
414 a->acl_dn_style = ACL_STYLE_CHILDREN;
415 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
417 } else if ( strcasecmp( style, "regex" ) == 0 ) {
418 a->acl_dn_style = ACL_STYLE_REGEX;
420 if ( *right == '\0' ) {
421 /* empty regex should match empty DN */
422 a->acl_dn_style = ACL_STYLE_BASE;
423 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
425 } else if ( strcmp(right, "*") == 0
426 || strcmp(right, ".*") == 0
427 || strcmp(right, ".*$") == 0
428 || strcmp(right, "^.*") == 0
429 || strcmp(right, "^.*$") == 0
430 || strcmp(right, ".*$$") == 0
431 || strcmp(right, "^.*$$") == 0 )
433 ber_str2bv( "*", STRLENOF("*"), 1, &a->acl_dn_pat );
436 acl_regex_normalized_dn( right, &a->acl_dn_pat );
440 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
441 "unknown dn style \"%s\" in to clause\n",
442 fname, lineno, style );
449 if ( strcasecmp( left, "filter" ) == 0 ) {
450 if ( (a->acl_filter = str2filter( right )) == NULL ) {
451 Debug( LDAP_DEBUG_ANY,
452 "%s: line %d: bad filter \"%s\" in to clause\n",
453 fname, lineno, right );
457 } else if ( strcasecmp( left, "attr" ) == 0 /* TOLERATED */
458 || strcasecmp( left, "attrs" ) == 0 ) /* DOCUMENTED */
460 if ( strcasecmp( left, "attr" ) == 0 ) {
461 Debug( LDAP_DEBUG_ANY,
462 "%s: line %d: \"attr\" "
463 "is deprecated (and undocumented); "
464 "use \"attrs\" instead.\n",
468 a->acl_attrs = str2anlist( a->acl_attrs,
470 if ( a->acl_attrs == NULL ) {
471 Debug( LDAP_DEBUG_ANY,
472 "%s: line %d: unknown attr \"%s\" in to clause\n",
473 fname, lineno, right );
477 } else if ( strncasecmp( left, "val", 3 ) == 0 ) {
481 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
482 Debug( LDAP_DEBUG_ANY,
483 "%s: line %d: attr val already specified in to clause.\n",
487 if ( a->acl_attrs == NULL || !BER_BVISEMPTY( &a->acl_attrs[1].an_name ) )
489 Debug( LDAP_DEBUG_ANY,
490 "%s: line %d: attr val requires a single attribute.\n",
495 ber_str2bv( right, 0, 0, &bv );
496 a->acl_attrval_style = ACL_STYLE_BASE;
498 mr = strchr( left, '/' );
503 a->acl_attrval_mr = mr_find( mr );
504 if ( a->acl_attrval_mr == NULL ) {
505 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
506 "invalid matching rule \"%s\".\n",
511 if( !mr_usable_with_at( a->acl_attrval_mr, a->acl_attrs[ 0 ].an_desc->ad_type ) )
513 char buf[ SLAP_TEXT_BUFLEN ];
515 snprintf( buf, sizeof( buf ),
516 "matching rule \"%s\" use "
517 "with attr \"%s\" not appropriate.",
518 mr, a->acl_attrs[ 0 ].an_name.bv_val );
521 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
522 fname, lineno, buf );
527 if ( style != NULL ) {
528 if ( strcasecmp( style, "regex" ) == 0 ) {
529 int e = regcomp( &a->acl_attrval_re, bv.bv_val,
530 REG_EXTENDED | REG_ICASE | REG_NOSUB );
532 char err[SLAP_TEXT_BUFLEN],
533 buf[ SLAP_TEXT_BUFLEN ];
535 regerror( e, &a->acl_attrval_re, err, sizeof( err ) );
537 snprintf( buf, sizeof( buf ),
538 "regular expression \"%s\" bad because of %s",
541 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
542 fname, lineno, buf );
545 a->acl_attrval_style = ACL_STYLE_REGEX;
548 /* FIXME: if the attribute has DN syntax, we might
549 * allow one, subtree and children styles as well */
550 if ( !strcasecmp( style, "base" ) ||
551 !strcasecmp( style, "exact" ) ) {
552 a->acl_attrval_style = ACL_STYLE_BASE;
554 } else if ( a->acl_attrs[0].an_desc->ad_type->
555 sat_syntax == slap_schema.si_syn_distinguishedName )
557 if ( !strcasecmp( style, "baseObject" ) ||
558 !strcasecmp( style, "base" ) )
560 a->acl_attrval_style = ACL_STYLE_BASE;
561 } else if ( !strcasecmp( style, "onelevel" ) ||
562 !strcasecmp( style, "one" ) )
564 a->acl_attrval_style = ACL_STYLE_ONE;
565 } else if ( !strcasecmp( style, "subtree" ) ||
566 !strcasecmp( style, "sub" ) )
568 a->acl_attrval_style = ACL_STYLE_SUBTREE;
569 } else if ( !strcasecmp( style, "children" ) ) {
570 a->acl_attrval_style = ACL_STYLE_CHILDREN;
572 char buf[ SLAP_TEXT_BUFLEN ];
574 snprintf( buf, sizeof( buf ),
575 "unknown val.<style> \"%s\" for attributeType \"%s\" "
578 a->acl_attrs[0].an_desc->ad_cname.bv_val );
580 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
582 fname, lineno, buf );
586 rc = dnNormalize( 0, NULL, NULL, &bv, &a->acl_attrval, NULL );
587 if ( rc != LDAP_SUCCESS ) {
588 char buf[ SLAP_TEXT_BUFLEN ];
590 snprintf( buf, sizeof( buf ),
591 "unable to normalize DN \"%s\" "
592 "for attributeType \"%s\" (%d).",
594 a->acl_attrs[0].an_desc->ad_cname.bv_val,
596 Debug( LDAP_DEBUG_ANY,
598 fname, lineno, buf );
603 char buf[ SLAP_TEXT_BUFLEN ];
605 snprintf( buf, sizeof( buf ),
606 "unknown val.<style> \"%s\" for attributeType \"%s\".",
607 style, a->acl_attrs[0].an_desc->ad_cname.bv_val );
608 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
610 fname, lineno, buf );
616 /* Check for appropriate matching rule */
617 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
618 ber_dupbv( &a->acl_attrval, &bv );
620 } else if ( BER_BVISNULL( &a->acl_attrval ) ) {
624 if ( a->acl_attrval_mr == NULL ) {
625 a->acl_attrval_mr = a->acl_attrs[ 0 ].an_desc->ad_type->sat_equality;
628 if ( a->acl_attrval_mr == NULL ) {
629 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
630 "attr \"%s\" does not have an EQUALITY matching rule.\n",
631 fname, lineno, a->acl_attrs[ 0 ].an_name.bv_val );
635 rc = asserted_value_validate_normalize(
636 a->acl_attrs[ 0 ].an_desc,
638 SLAP_MR_EQUALITY|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
643 if ( rc != LDAP_SUCCESS ) {
644 char buf[ SLAP_TEXT_BUFLEN ];
646 snprintf( buf, sizeof( buf ), "%s: line %d: "
647 " attr \"%s\" normalization failed (%d: %s)",
648 a->acl_attrs[ 0 ].an_name.bv_val, rc, text );
649 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s.\n",
650 fname, lineno, buf );
656 Debug( LDAP_DEBUG_ANY,
657 "%s: line %d: expecting <what> got \"%s\"\n",
658 fname, lineno, left );
663 if ( !BER_BVISNULL( &a->acl_dn_pat ) &&
664 ber_bvccmp( &a->acl_dn_pat, '*' ) )
666 free( a->acl_dn_pat.bv_val );
667 BER_BVZERO( &a->acl_dn_pat );
668 a->acl_dn_style = ACL_STYLE_REGEX;
671 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
672 a->acl_dn_style != ACL_STYLE_REGEX )
674 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
676 rc = dnNormalize( 0, NULL, NULL, &a->acl_dn_pat, &bv, NULL);
677 if ( rc != LDAP_SUCCESS ) {
678 Debug( LDAP_DEBUG_ANY,
679 "%s: line %d: bad DN \"%s\" in to DN clause\n",
680 fname, lineno, a->acl_dn_pat.bv_val );
683 free( a->acl_dn_pat.bv_val );
687 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
688 REG_EXTENDED | REG_ICASE );
690 char err[ SLAP_TEXT_BUFLEN ],
691 buf[ SLAP_TEXT_BUFLEN ];
693 regerror( e, &a->acl_dn_re, err, sizeof( err ) );
694 snprintf( buf, sizeof( buf ),
695 "regular expression \"%s\" bad because of %s",
697 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
698 fname, lineno, buf );
704 /* by clause - select who has what access to entries */
705 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
707 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
708 "to clause required before by clause in access line\n",
714 * by clause consists of <who> and <access>
718 Debug( LDAP_DEBUG_ANY,
719 "%s: line %d: premature EOL: expecting <who>\n",
724 b = (Access *) ch_calloc( 1, sizeof(Access) );
726 ACL_INVALIDATE( b->a_access_mask );
729 for ( ; i < argc; i++ ) {
730 slap_style_t sty = ACL_STYLE_REGEX;
731 char *style_modifier = NULL;
732 char *style_level = NULL;
735 slap_dn_access *bdn = &b->a_dn;
738 split( argv[i], '=', &left, &right );
739 split( left, '.', &left, &style );
741 split( style, ',', &style, &style_modifier );
743 if ( strncasecmp( style, "level", STRLENOF( "level" ) ) == 0 ) {
744 split( style, '{', &style, &style_level );
745 if ( style_level != NULL ) {
746 char *p = strchr( style_level, '}' );
748 Debug( LDAP_DEBUG_ANY,
749 "%s: line %d: premature eol: "
750 "expecting closing '}' in \"level{n}\"\n",
753 } else if ( p == style_level ) {
754 Debug( LDAP_DEBUG_ANY,
755 "%s: line %d: empty level "
765 if ( style == NULL || *style == '\0' ||
766 strcasecmp( style, "exact" ) == 0 ||
767 strcasecmp( style, "baseObject" ) == 0 ||
768 strcasecmp( style, "base" ) == 0 )
770 sty = ACL_STYLE_BASE;
772 } else if ( strcasecmp( style, "onelevel" ) == 0 ||
773 strcasecmp( style, "one" ) == 0 )
777 } else if ( strcasecmp( style, "subtree" ) == 0 ||
778 strcasecmp( style, "sub" ) == 0 )
780 sty = ACL_STYLE_SUBTREE;
782 } else if ( strcasecmp( style, "children" ) == 0 ) {
783 sty = ACL_STYLE_CHILDREN;
785 } else if ( strcasecmp( style, "level" ) == 0 )
787 if ( lutil_atoi( &level, style_level ) != 0 ) {
788 Debug( LDAP_DEBUG_ANY,
789 "%s: line %d: unable to parse level "
795 sty = ACL_STYLE_LEVEL;
797 } else if ( strcasecmp( style, "regex" ) == 0 ) {
798 sty = ACL_STYLE_REGEX;
800 } else if ( strcasecmp( style, "expand" ) == 0 ) {
801 sty = ACL_STYLE_EXPAND;
803 } else if ( strcasecmp( style, "ip" ) == 0 ) {
806 } else if ( strcasecmp( style, "path" ) == 0 ) {
807 sty = ACL_STYLE_PATH;
808 #ifndef LDAP_PF_LOCAL
809 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
811 "\"path\" style modifier is useless without local.\n",
814 #endif /* LDAP_PF_LOCAL */
817 Debug( LDAP_DEBUG_ANY,
818 "%s: line %d: unknown style \"%s\" in by clause\n",
819 fname, lineno, style );
823 if ( style_modifier &&
824 strcasecmp( style_modifier, "expand" ) == 0 )
827 case ACL_STYLE_REGEX:
828 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
829 "\"regex\" style implies \"expand\" modifier.\n",
834 case ACL_STYLE_EXPAND:
838 /* we'll see later if it's pertinent */
844 /* expand in <who> needs regex in <what> */
845 if ( ( sty == ACL_STYLE_EXPAND || expand )
846 && a->acl_dn_style != ACL_STYLE_REGEX )
848 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL, "%s: line %d: \"expand\" style "
849 "or modifier used in conjunction with a non-regex <what> clause.\n",
854 if ( strncasecmp( left, "real", STRLENOF( "real" ) ) == 0 ) {
857 left += STRLENOF( "real" );
860 if ( strcasecmp( left, "*" ) == 0 ) {
865 ber_str2bv( "*", STRLENOF( "*" ), 1, &bv );
866 sty = ACL_STYLE_REGEX;
868 } else if ( strcasecmp( left, "anonymous" ) == 0 ) {
869 ber_str2bv("anonymous", STRLENOF( "anonymous" ), 1, &bv);
870 sty = ACL_STYLE_ANONYMOUS;
872 } else if ( strcasecmp( left, "users" ) == 0 ) {
873 ber_str2bv("users", STRLENOF( "users" ), 1, &bv);
874 sty = ACL_STYLE_USERS;
876 } else if ( strcasecmp( left, "self" ) == 0 ) {
877 ber_str2bv("self", STRLENOF( "self" ), 1, &bv);
878 sty = ACL_STYLE_SELF;
880 } else if ( strcasecmp( left, "dn" ) == 0 ) {
881 if ( sty == ACL_STYLE_REGEX ) {
882 bdn->a_style = ACL_STYLE_REGEX;
883 if ( right == NULL ) {
888 bdn->a_style = ACL_STYLE_USERS;
890 } else if (*right == '\0' ) {
892 ber_str2bv("anonymous",
893 STRLENOF( "anonymous" ),
895 bdn->a_style = ACL_STYLE_ANONYMOUS;
897 } else if ( strcmp( right, "*" ) == 0 ) {
899 /* any or users? users for now */
903 bdn->a_style = ACL_STYLE_USERS;
905 } else if ( strcmp( right, ".+" ) == 0
906 || strcmp( right, "^.+" ) == 0
907 || strcmp( right, ".+$" ) == 0
908 || strcmp( right, "^.+$" ) == 0
909 || strcmp( right, ".+$$" ) == 0
910 || strcmp( right, "^.+$$" ) == 0 )
915 bdn->a_style = ACL_STYLE_USERS;
917 } else if ( strcmp( right, ".*" ) == 0
918 || strcmp( right, "^.*" ) == 0
919 || strcmp( right, ".*$" ) == 0
920 || strcmp( right, "^.*$" ) == 0
921 || strcmp( right, ".*$$" ) == 0
922 || strcmp( right, "^.*$$" ) == 0 )
929 acl_regex_normalized_dn( right, &bv );
930 if ( !ber_bvccmp( &bv, '*' ) ) {
931 regtest( fname, lineno, bv.bv_val );
935 } else if ( right == NULL || *right == '\0' ) {
936 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
937 "missing \"=\" in (or value after) \"%s\" "
939 fname, lineno, left );
943 ber_str2bv( right, 0, 1, &bv );
950 if ( !BER_BVISNULL( &bv ) ) {
951 if ( !BER_BVISEMPTY( &bdn->a_pat ) ) {
952 Debug( LDAP_DEBUG_ANY,
953 "%s: line %d: dn pattern already specified.\n",
958 if ( sty != ACL_STYLE_REGEX &&
959 sty != ACL_STYLE_ANONYMOUS &&
960 sty != ACL_STYLE_USERS &&
961 sty != ACL_STYLE_SELF &&
964 rc = dnNormalize(0, NULL, NULL,
965 &bv, &bdn->a_pat, NULL);
966 if ( rc != LDAP_SUCCESS ) {
967 Debug( LDAP_DEBUG_ANY,
968 "%s: line %d: bad DN \"%s\" in by DN clause\n",
969 fname, lineno, bv.bv_val );
973 if ( sty == ACL_STYLE_BASE
975 && !BER_BVISNULL( &be->be_rootndn )
976 && dn_match( &bdn->a_pat, &be->be_rootndn ) )
978 Debug( LDAP_DEBUG_ANY,
979 "%s: line %d: rootdn is always granted "
980 "unlimited privileges.\n",
992 for ( exp = strchr( bdn->a_pat.bv_val, '$' );
993 exp && (ber_len_t)(exp - bdn->a_pat.bv_val)
995 exp = strchr( exp, '$' ) )
997 if ( isdigit( exp[ 1 ] ) ) {
1004 bdn->a_expand = expand;
1007 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1008 "\"expand\" used with no expansions in \"pattern\".\n",
1013 if ( sty == ACL_STYLE_SELF ) {
1014 bdn->a_self_level = level;
1018 Debug( LDAP_DEBUG_ANY,
1019 "%s: line %d: bad negative level \"%d\" "
1020 "in by DN clause\n",
1021 fname, lineno, level );
1023 } else if ( level == 1 ) {
1024 Debug( LDAP_DEBUG_ANY,
1025 "%s: line %d: \"onelevel\" should be used "
1026 "instead of \"level{1}\" in by DN clause\n",
1028 } else if ( level == 0 && sty == ACL_STYLE_LEVEL ) {
1029 Debug( LDAP_DEBUG_ANY,
1030 "%s: line %d: \"base\" should be used "
1031 "instead of \"level{0}\" in by DN clause\n",
1035 bdn->a_level = level;
1040 if ( strcasecmp( left, "dnattr" ) == 0 ) {
1041 if ( right == NULL || right[0] == '\0' ) {
1042 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1043 "missing \"=\" in (or value after) \"%s\" "
1045 fname, lineno, left );
1049 if( bdn->a_at != NULL ) {
1050 Debug( LDAP_DEBUG_ANY,
1051 "%s: line %d: dnattr already specified.\n",
1056 rc = slap_str2ad( right, &bdn->a_at, &text );
1058 if( rc != LDAP_SUCCESS ) {
1059 char buf[ SLAP_TEXT_BUFLEN ];
1061 snprintf( buf, sizeof( buf ),
1062 "dnattr \"%s\": %s",
1064 Debug( LDAP_DEBUG_ANY,
1065 "%s: line %d: %s\n",
1066 fname, lineno, buf );
1071 if( !is_at_syntax( bdn->a_at->ad_type,
1072 SLAPD_DN_SYNTAX ) &&
1073 !is_at_syntax( bdn->a_at->ad_type,
1074 SLAPD_NAMEUID_SYNTAX ))
1076 char buf[ SLAP_TEXT_BUFLEN ];
1078 snprintf( buf, sizeof( buf ),
1080 "inappropriate syntax: %s\n",
1082 bdn->a_at->ad_type->sat_syntax_oid );
1083 Debug( LDAP_DEBUG_ANY,
1084 "%s: line %d: %s\n",
1085 fname, lineno, buf );
1089 if( bdn->a_at->ad_type->sat_equality == NULL ) {
1090 Debug( LDAP_DEBUG_ANY,
1091 "%s: line %d: dnattr \"%s\": "
1092 "inappropriate matching (no EQUALITY)\n",
1093 fname, lineno, right );
1100 if ( strncasecmp( left, "group", STRLENOF( "group" ) ) == 0 ) {
1105 case ACL_STYLE_REGEX:
1106 /* legacy, tolerated */
1107 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
1109 "deprecated group style \"regex\"; "
1110 "use \"expand\" instead.\n",
1112 sty = ACL_STYLE_EXPAND;
1115 case ACL_STYLE_BASE:
1116 /* legal, traditional */
1117 case ACL_STYLE_EXPAND:
1118 /* legal, substring expansion; supersedes regex */
1123 Debug( LDAP_DEBUG_ANY,
1125 "inappropriate style \"%s\" in by clause.\n",
1126 fname, lineno, style );
1130 if ( right == NULL || right[0] == '\0' ) {
1131 Debug( LDAP_DEBUG_ANY,
1133 "missing \"=\" in (or value after) \"%s\" "
1135 fname, lineno, left );
1139 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1140 Debug( LDAP_DEBUG_ANY,
1141 "%s: line %d: group pattern already specified.\n",
1146 /* format of string is
1147 "group/objectClassValue/groupAttrName" */
1148 if ( ( value = strchr(left, '/') ) != NULL ) {
1150 if ( *value && ( name = strchr( value, '/' ) ) != NULL ) {
1155 b->a_group_style = sty;
1156 if ( sty == ACL_STYLE_EXPAND ) {
1157 acl_regex_normalized_dn( right, &bv );
1158 if ( !ber_bvccmp( &bv, '*' ) ) {
1159 regtest( fname, lineno, bv.bv_val );
1161 b->a_group_pat = bv;
1164 ber_str2bv( right, 0, 0, &bv );
1165 rc = dnNormalize( 0, NULL, NULL, &bv,
1166 &b->a_group_pat, NULL );
1167 if ( rc != LDAP_SUCCESS ) {
1168 Debug( LDAP_DEBUG_ANY,
1169 "%s: line %d: bad DN \"%s\".\n",
1170 fname, lineno, right );
1175 if ( value && *value ) {
1176 b->a_group_oc = oc_find( value );
1179 if ( b->a_group_oc == NULL ) {
1180 Debug( LDAP_DEBUG_ANY,
1181 "%s: line %d: group objectclass "
1182 "\"%s\" unknown.\n",
1183 fname, lineno, value );
1188 b->a_group_oc = oc_find( SLAPD_GROUP_CLASS );
1190 if( b->a_group_oc == NULL ) {
1191 Debug( LDAP_DEBUG_ANY,
1192 "%s: line %d: group default objectclass "
1193 "\"%s\" unknown.\n",
1194 fname, lineno, SLAPD_GROUP_CLASS );
1199 if ( is_object_subclass( slap_schema.si_oc_referral,
1202 Debug( LDAP_DEBUG_ANY,
1203 "%s: line %d: group objectclass \"%s\" "
1204 "is subclass of referral.\n",
1205 fname, lineno, value );
1209 if ( is_object_subclass( slap_schema.si_oc_alias,
1212 Debug( LDAP_DEBUG_ANY,
1213 "%s: line %d: group objectclass \"%s\" "
1214 "is subclass of alias.\n",
1215 fname, lineno, value );
1219 if ( name && *name ) {
1220 rc = slap_str2ad( name, &b->a_group_at, &text );
1222 if( rc != LDAP_SUCCESS ) {
1223 char buf[ SLAP_TEXT_BUFLEN ];
1225 snprintf( buf, sizeof( buf ),
1226 "group \"%s\": %s.",
1228 Debug( LDAP_DEBUG_ANY,
1229 "%s: line %d: %s\n",
1230 fname, lineno, buf );
1236 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
1238 if ( rc != LDAP_SUCCESS ) {
1239 char buf[ SLAP_TEXT_BUFLEN ];
1241 snprintf( buf, sizeof( buf ),
1242 "group \"%s\": %s.",
1243 SLAPD_GROUP_ATTR, text );
1244 Debug( LDAP_DEBUG_ANY,
1245 "%s: line %d: %s\n",
1246 fname, lineno, buf );
1251 if ( !is_at_syntax( b->a_group_at->ad_type,
1252 SLAPD_DN_SYNTAX ) &&
1253 !is_at_syntax( b->a_group_at->ad_type,
1254 SLAPD_NAMEUID_SYNTAX ) &&
1255 !is_at_subtype( b->a_group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ) )
1257 char buf[ SLAP_TEXT_BUFLEN ];
1259 snprintf( buf, sizeof( buf ),
1260 "group \"%s\": inappropriate syntax: %s.",
1262 b->a_group_at->ad_type->sat_syntax_oid );
1263 Debug( LDAP_DEBUG_ANY,
1264 "%s: line %d: %s\n",
1265 fname, lineno, buf );
1272 struct berval vals[2];
1274 ber_str2bv( b->a_group_oc->soc_oid, 0, 0, &vals[0] );
1275 BER_BVZERO( &vals[1] );
1277 rc = oc_check_allowed( b->a_group_at->ad_type,
1281 char buf[ SLAP_TEXT_BUFLEN ];
1283 snprintf( buf, sizeof( buf ),
1284 "group: \"%s\" not allowed by \"%s\".",
1285 b->a_group_at->ad_cname.bv_val,
1286 b->a_group_oc->soc_oid );
1287 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
1288 fname, lineno, buf );
1295 if ( strcasecmp( left, "peername" ) == 0 ) {
1297 case ACL_STYLE_REGEX:
1298 case ACL_STYLE_BASE:
1299 /* legal, traditional */
1300 case ACL_STYLE_EXPAND:
1301 /* cheap replacement to regex for simple expansion */
1303 case ACL_STYLE_PATH:
1304 /* legal, peername specific */
1308 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1309 "inappropriate style \"%s\" in by clause.\n",
1310 fname, lineno, style );
1314 if ( right == NULL || right[0] == '\0' ) {
1315 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1316 "missing \"=\" in (or value after) \"%s\" "
1318 fname, lineno, left );
1322 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1323 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1324 "peername pattern already specified.\n",
1329 b->a_peername_style = sty;
1330 if ( sty == ACL_STYLE_REGEX ) {
1331 acl_regex_normalized_dn( right, &bv );
1332 if ( !ber_bvccmp( &bv, '*' ) ) {
1333 regtest( fname, lineno, bv.bv_val );
1335 b->a_peername_pat = bv;
1338 ber_str2bv( right, 0, 1, &b->a_peername_pat );
1340 if ( sty == ACL_STYLE_IP ) {
1345 split( right, '{', &addr, &port );
1346 split( addr, '%', &addr, &mask );
1348 b->a_peername_addr = inet_addr( addr );
1349 if ( b->a_peername_addr == (unsigned long)(-1) ) {
1350 /* illegal address */
1351 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1352 "illegal peername address \"%s\".\n",
1353 fname, lineno, addr );
1357 b->a_peername_mask = (unsigned long)(-1);
1358 if ( mask != NULL ) {
1359 b->a_peername_mask = inet_addr( mask );
1360 if ( b->a_peername_mask ==
1361 (unsigned long)(-1) )
1364 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1365 "illegal peername address mask "
1367 fname, lineno, mask );
1372 b->a_peername_port = -1;
1376 b->a_peername_port = strtol( port, &end, 10 );
1377 if ( end == port || end[0] != '}' ) {
1379 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1380 "illegal peername port specification "
1382 fname, lineno, port );
1391 if ( strcasecmp( left, "sockname" ) == 0 ) {
1393 case ACL_STYLE_REGEX:
1394 case ACL_STYLE_BASE:
1395 /* legal, traditional */
1396 case ACL_STYLE_EXPAND:
1397 /* cheap replacement to regex for simple expansion */
1402 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1403 "inappropriate style \"%s\" in by clause\n",
1404 fname, lineno, style );
1408 if ( right == NULL || right[0] == '\0' ) {
1409 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1410 "missing \"=\" in (or value after) \"%s\" "
1412 fname, lineno, left );
1416 if ( !BER_BVISNULL( &b->a_sockname_pat ) ) {
1417 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1418 "sockname pattern already specified.\n",
1423 b->a_sockname_style = sty;
1424 if ( sty == ACL_STYLE_REGEX ) {
1425 acl_regex_normalized_dn( right, &bv );
1426 if ( !ber_bvccmp( &bv, '*' ) ) {
1427 regtest( fname, lineno, bv.bv_val );
1429 b->a_sockname_pat = bv;
1432 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
1437 if ( strcasecmp( left, "domain" ) == 0 ) {
1439 case ACL_STYLE_REGEX:
1440 case ACL_STYLE_BASE:
1441 case ACL_STYLE_SUBTREE:
1442 /* legal, traditional */
1445 case ACL_STYLE_EXPAND:
1446 /* tolerated: means exact,expand */
1448 Debug( LDAP_DEBUG_ANY,
1450 "\"expand\" modifier "
1451 "with \"expand\" style.\n",
1454 sty = ACL_STYLE_BASE;
1460 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1461 "inappropriate style \"%s\" in by clause.\n",
1462 fname, lineno, style );
1466 if ( right == NULL || right[0] == '\0' ) {
1467 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1468 "missing \"=\" in (or value after) \"%s\" "
1470 fname, lineno, left );
1474 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1475 Debug( LDAP_DEBUG_ANY,
1476 "%s: line %d: domain pattern already specified.\n",
1481 b->a_domain_style = sty;
1482 b->a_domain_expand = expand;
1483 if ( sty == ACL_STYLE_REGEX ) {
1484 acl_regex_normalized_dn( right, &bv );
1485 if ( !ber_bvccmp( &bv, '*' ) ) {
1486 regtest( fname, lineno, bv.bv_val );
1488 b->a_domain_pat = bv;
1491 ber_str2bv( right, 0, 1, &b->a_domain_pat );
1496 if ( strcasecmp( left, "sockurl" ) == 0 ) {
1498 case ACL_STYLE_REGEX:
1499 case ACL_STYLE_BASE:
1500 /* legal, traditional */
1501 case ACL_STYLE_EXPAND:
1502 /* cheap replacement to regex for simple expansion */
1507 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1508 "inappropriate style \"%s\" in by clause.\n",
1509 fname, lineno, style );
1513 if ( right == NULL || right[0] == '\0' ) {
1514 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1515 "missing \"=\" in (or value after) \"%s\" "
1517 fname, lineno, left );
1521 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1522 Debug( LDAP_DEBUG_ANY,
1523 "%s: line %d: sockurl pattern already specified.\n",
1528 b->a_sockurl_style = sty;
1529 if ( sty == ACL_STYLE_REGEX ) {
1530 acl_regex_normalized_dn( right, &bv );
1531 if ( !ber_bvccmp( &bv, '*' ) ) {
1532 regtest( fname, lineno, bv.bv_val );
1534 b->a_sockurl_pat = bv;
1537 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
1542 if ( strcasecmp( left, "set" ) == 0 ) {
1545 case ACL_STYLE_REGEX:
1546 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
1548 "deprecated set style "
1549 "\"regex\" in <by> clause; "
1550 "use \"expand\" instead.\n",
1552 sty = ACL_STYLE_EXPAND;
1555 case ACL_STYLE_BASE:
1556 case ACL_STYLE_EXPAND:
1560 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1561 "inappropriate style \"%s\" in by clause.\n",
1562 fname, lineno, style );
1566 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1567 Debug( LDAP_DEBUG_ANY,
1568 "%s: line %d: set attribute already specified.\n",
1573 if ( right == NULL || *right == '\0' ) {
1574 Debug( LDAP_DEBUG_ANY,
1575 "%s: line %d: no set is defined.\n",
1580 b->a_set_style = sty;
1581 ber_str2bv( right, 0, 1, &b->a_set_pat );
1591 #if 1 /* tolerate legacy "aci" <who> */
1592 if ( strcasecmp( left, "aci" ) == 0 ) {
1593 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1594 "undocumented deprecated \"aci\" directive "
1595 "is superseded by \"dynacl/aci\".\n",
1600 #endif /* tolerate legacy "aci" <who> */
1601 if ( strncasecmp( left, "dynacl/", STRLENOF( "dynacl/" ) ) == 0 ) {
1602 name = &left[ STRLENOF( "dynacl/" ) ];
1603 opts = strchr( name, '/' );
1611 if ( slap_dynacl_config( fname, lineno, b, name, opts, sty, right ) ) {
1612 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1613 "unable to configure dynacl \"%s\".\n",
1614 fname, lineno, name );
1621 #endif /* SLAP_DYNACL */
1623 if ( strcasecmp( left, "ssf" ) == 0 ) {
1624 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1625 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1626 "inappropriate style \"%s\" in by clause.\n",
1627 fname, lineno, style );
1631 if ( b->a_authz.sai_ssf ) {
1632 Debug( LDAP_DEBUG_ANY,
1633 "%s: line %d: ssf attribute already specified.\n",
1638 if ( right == NULL || *right == '\0' ) {
1639 Debug( LDAP_DEBUG_ANY,
1640 "%s: line %d: no ssf is defined.\n",
1645 if ( lutil_atou( &b->a_authz.sai_ssf, right ) != 0 ) {
1646 Debug( LDAP_DEBUG_ANY,
1647 "%s: line %d: unable to parse ssf value (%s).\n",
1648 fname, lineno, right );
1652 if ( !b->a_authz.sai_ssf ) {
1653 Debug( LDAP_DEBUG_ANY,
1654 "%s: line %d: invalid ssf value (%s).\n",
1655 fname, lineno, right );
1661 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
1662 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1663 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1664 "inappropriate style \"%s\" in by clause.\n",
1665 fname, lineno, style );
1669 if ( b->a_authz.sai_transport_ssf ) {
1670 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1671 "transport_ssf attribute already specified.\n",
1676 if ( right == NULL || *right == '\0' ) {
1677 Debug( LDAP_DEBUG_ANY,
1678 "%s: line %d: no transport_ssf is defined.\n",
1683 if ( lutil_atou( &b->a_authz.sai_transport_ssf, right ) != 0 ) {
1684 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1685 "unable to parse transport_ssf value (%s).\n",
1686 fname, lineno, right );
1690 if ( !b->a_authz.sai_transport_ssf ) {
1691 Debug( LDAP_DEBUG_ANY,
1692 "%s: line %d: invalid transport_ssf value (%s).\n",
1693 fname, lineno, right );
1699 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
1700 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1701 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1702 "inappropriate style \"%s\" in by clause.\n",
1703 fname, lineno, style );
1707 if ( b->a_authz.sai_tls_ssf ) {
1708 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1709 "tls_ssf attribute already specified.\n",
1714 if ( right == NULL || *right == '\0' ) {
1715 Debug( LDAP_DEBUG_ANY,
1716 "%s: line %d: no tls_ssf is defined\n",
1721 if ( lutil_atou( &b->a_authz.sai_tls_ssf, right ) != 0 ) {
1722 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1723 "unable to parse tls_ssf value (%s).\n",
1724 fname, lineno, right );
1728 if ( !b->a_authz.sai_tls_ssf ) {
1729 Debug( LDAP_DEBUG_ANY,
1730 "%s: line %d: invalid tls_ssf value (%s).\n",
1731 fname, lineno, right );
1737 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1738 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1739 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1740 "inappropriate style \"%s\" in by clause.\n",
1741 fname, lineno, style );
1745 if ( b->a_authz.sai_sasl_ssf ) {
1746 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1747 "sasl_ssf attribute already specified.\n",
1752 if ( right == NULL || *right == '\0' ) {
1753 Debug( LDAP_DEBUG_ANY,
1754 "%s: line %d: no sasl_ssf is defined.\n",
1759 if ( lutil_atou( &b->a_authz.sai_sasl_ssf, right ) != 0 ) {
1760 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1761 "unable to parse sasl_ssf value (%s).\n",
1762 fname, lineno, right );
1766 if ( !b->a_authz.sai_sasl_ssf ) {
1767 Debug( LDAP_DEBUG_ANY,
1768 "%s: line %d: invalid sasl_ssf value (%s).\n",
1769 fname, lineno, right );
1775 if ( right != NULL ) {
1782 if ( i == argc || ( strcasecmp( left, "stop" ) == 0 ) ) {
1783 /* out of arguments or plain stop */
1785 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1786 b->a_type = ACL_STOP;
1788 access_append( &a->acl_access, b );
1792 if ( strcasecmp( left, "continue" ) == 0 ) {
1793 /* plain continue */
1795 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1796 b->a_type = ACL_CONTINUE;
1798 access_append( &a->acl_access, b );
1802 if ( strcasecmp( left, "break" ) == 0 ) {
1803 /* plain continue */
1805 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1806 b->a_type = ACL_BREAK;
1808 access_append( &a->acl_access, b );
1812 if ( strcasecmp( left, "by" ) == 0 ) {
1813 /* we've gone too far */
1815 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1816 b->a_type = ACL_STOP;
1818 access_append( &a->acl_access, b );
1823 if ( strncasecmp( left, "self", STRLENOF( "self" ) ) == 0 ) {
1825 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "self" ) ] ) );
1827 } else if ( strncasecmp( left, "realself", STRLENOF( "realself" ) ) == 0 ) {
1828 b->a_realdn_self = 1;
1829 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "realself" ) ] ) );
1832 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1835 if ( ACL_IS_INVALID( b->a_access_mask ) ) {
1836 Debug( LDAP_DEBUG_ANY,
1837 "%s: line %d: expecting <access> got \"%s\".\n",
1838 fname, lineno, left );
1842 b->a_type = ACL_STOP;
1844 if ( ++i == argc ) {
1845 /* out of arguments or plain stop */
1846 access_append( &a->acl_access, b );
1850 if ( strcasecmp( argv[i], "continue" ) == 0 ) {
1851 /* plain continue */
1852 b->a_type = ACL_CONTINUE;
1854 } else if ( strcasecmp( argv[i], "break" ) == 0 ) {
1855 /* plain continue */
1856 b->a_type = ACL_BREAK;
1858 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1863 access_append( &a->acl_access, b );
1867 Debug( LDAP_DEBUG_ANY,
1868 "%s: line %d: expecting \"to\" "
1869 "or \"by\" got \"%s\"\n",
1870 fname, lineno, argv[i] );
1875 /* if we have no real access clause, complain and do nothing */
1877 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1878 "warning: no access clause(s) specified in access line.\n",
1884 if ( slap_debug & LDAP_DEBUG_ACL ) {
1889 if ( a->acl_access == NULL ) {
1890 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1891 "warning: no by clause(s) specified in access line.\n",
1897 if ( be->be_nsuffix == NULL ) {
1898 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1899 "scope checking needs suffix before ACLs.\n",
1901 /* go ahead, since checking is not authoritative */
1902 } else if ( !BER_BVISNULL( &be->be_nsuffix[ 1 ] ) ) {
1903 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1904 "scope checking only applies to single-valued "
1905 "suffix databases\n",
1907 /* go ahead, since checking is not authoritative */
1909 switch ( check_scope( be, a ) ) {
1910 case ACL_SCOPE_UNKNOWN:
1911 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1912 "cannot assess the validity of the ACL scope within "
1913 "backend naming context\n",
1917 case ACL_SCOPE_WARN:
1918 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1919 "ACL could be out of scope within backend naming context\n",
1923 case ACL_SCOPE_PARTIAL:
1924 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1925 "ACL appears to be partially out of scope within "
1926 "backend naming context\n",
1931 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1932 "ACL appears to be out of scope within "
1933 "backend naming context\n",
1941 acl_append( &be->be_acl, a, pos );
1944 acl_append( &frontendDB->be_acl, a, pos );
1951 if ( b ) access_free( b );
1952 if ( a ) acl_free( a );
1957 accessmask2str( slap_mask_t mask, char *buf, int debug )
1962 assert( buf != NULL );
1964 if ( ACL_IS_INVALID( mask ) ) {
1970 if ( ACL_IS_LEVEL( mask ) ) {
1971 if ( ACL_LVL_IS_NONE(mask) ) {
1972 ptr = lutil_strcopy( ptr, "none" );
1974 } else if ( ACL_LVL_IS_DISCLOSE(mask) ) {
1975 ptr = lutil_strcopy( ptr, "disclose" );
1977 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1978 ptr = lutil_strcopy( ptr, "auth" );
1980 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1981 ptr = lutil_strcopy( ptr, "compare" );
1983 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1984 ptr = lutil_strcopy( ptr, "search" );
1986 } else if ( ACL_LVL_IS_READ(mask) ) {
1987 ptr = lutil_strcopy( ptr, "read" );
1989 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1990 ptr = lutil_strcopy( ptr, "write" );
1992 } else if ( ACL_LVL_IS_WADD(mask) ) {
1993 ptr = lutil_strcopy( ptr, "add" );
1995 } else if ( ACL_LVL_IS_WDEL(mask) ) {
1996 ptr = lutil_strcopy( ptr, "delete" );
1998 } else if ( ACL_LVL_IS_MANAGE(mask) ) {
1999 ptr = lutil_strcopy( ptr, "manage" );
2002 ptr = lutil_strcopy( ptr, "unknown" );
2012 if( ACL_IS_ADDITIVE( mask ) ) {
2015 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
2022 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_MANAGE) ) {
2027 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
2031 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WADD) ) {
2035 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WDEL) ) {
2040 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
2045 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
2050 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
2055 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
2060 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_DISCLOSE) ) {
2065 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
2074 if ( ACL_IS_LEVEL( mask ) ) {
2084 str2accessmask( const char *str )
2088 if( !ASCII_ALPHA(str[0]) ) {
2091 if ( str[0] == '=' ) {
2094 } else if( str[0] == '+' ) {
2095 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
2097 } else if( str[0] == '-' ) {
2098 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
2101 ACL_INVALIDATE(mask);
2105 for( i=1; str[i] != '\0'; i++ ) {
2106 if( TOLOWER((unsigned char) str[i]) == 'm' ) {
2107 ACL_PRIV_SET(mask, ACL_PRIV_MANAGE);
2109 } else if( TOLOWER((unsigned char) str[i]) == 'w' ) {
2110 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
2112 } else if( TOLOWER((unsigned char) str[i]) == 'a' ) {
2113 ACL_PRIV_SET(mask, ACL_PRIV_WADD);
2115 } else if( TOLOWER((unsigned char) str[i]) == 'z' ) {
2116 ACL_PRIV_SET(mask, ACL_PRIV_WDEL);
2118 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
2119 ACL_PRIV_SET(mask, ACL_PRIV_READ);
2121 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
2122 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
2124 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
2125 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
2127 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
2128 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
2130 } else if( TOLOWER((unsigned char) str[i]) == 'd' ) {
2131 ACL_PRIV_SET(mask, ACL_PRIV_DISCLOSE);
2133 } else if( str[i] != '0' ) {
2134 ACL_INVALIDATE(mask);
2142 if ( strcasecmp( str, "none" ) == 0 ) {
2143 ACL_LVL_ASSIGN_NONE(mask);
2145 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2146 ACL_LVL_ASSIGN_DISCLOSE(mask);
2148 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2149 ACL_LVL_ASSIGN_AUTH(mask);
2151 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2152 ACL_LVL_ASSIGN_COMPARE(mask);
2154 } else if ( strcasecmp( str, "search" ) == 0 ) {
2155 ACL_LVL_ASSIGN_SEARCH(mask);
2157 } else if ( strcasecmp( str, "read" ) == 0 ) {
2158 ACL_LVL_ASSIGN_READ(mask);
2160 } else if ( strcasecmp( str, "add" ) == 0 ) {
2161 ACL_LVL_ASSIGN_WADD(mask);
2163 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2164 ACL_LVL_ASSIGN_WDEL(mask);
2166 } else if ( strcasecmp( str, "write" ) == 0 ) {
2167 ACL_LVL_ASSIGN_WRITE(mask);
2169 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2170 ACL_LVL_ASSIGN_MANAGE(mask);
2173 ACL_INVALIDATE( mask );
2183 "<access clause> ::= access to <what> "
2184 "[ by <who> <access> [ <control> ] ]+ \n";
2186 "<what> ::= * | [dn[.<dnstyle>]=<DN>] [filter=<filter>] [attrs=<attrspec>]\n"
2187 "<attrspec> ::= <attrname> [val[/<matchingRule>][.<attrstyle>]=<value>] | <attrlist>\n"
2188 "<attrlist> ::= <attr> [ , <attrlist> ]\n"
2189 "<attr> ::= <attrname> | @<objectClass> | !<objectClass> | entry | children\n";
2192 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
2193 "\t[ realanonymous | realusers | realself | realdn[.<dnstyle>]=<DN> ]\n"
2194 "\t[dnattr=<attrname>]\n"
2195 "\t[realdnattr=<attrname>]\n"
2196 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
2197 "\t[peername[.<peernamestyle>]=<peer>] [sockname[.<style>]=<name>]\n"
2198 "\t[domain[.<domainstyle>]=<domain>] [sockurl[.<style>]=<url>]\n"
2200 "\t[dynacl/<name>[/<options>][.<dynstyle>][=<pattern>]]\n"
2201 #endif /* SLAP_DYNACL */
2202 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
2203 "<style> ::= exact | regex | base(Object)\n"
2204 "<dnstyle> ::= base(Object) | one(level) | sub(tree) | children | "
2206 "<attrstyle> ::= exact | regex | base(Object) | one(level) | "
2207 "sub(tree) | children\n"
2208 "<peernamestyle> ::= exact | regex | ip | path\n"
2209 "<domainstyle> ::= exact | regex | base(Object) | sub(tree)\n"
2210 "<access> ::= [[real]self]{<level>|<priv>}\n"
2211 "<level> ::= none|disclose|auth|compare|search|read|{write|add|delete}|manage\n"
2212 "<priv> ::= {=|+|-}{0|d|x|c|s|r|{w|a|z}|m}+\n"
2213 "<control> ::= [ stop | continue | break ]\n"
2215 #ifdef SLAPD_ACI_ENABLED
2217 "\t<name>=ACI\t<pattern>=<attrname>\n"
2218 #endif /* SLAPD_ACI_ENABLED */
2219 #endif /* ! SLAP_DYNACL */
2222 Debug( LDAP_DEBUG_ANY, "%s%s%s\n", access, what, who );
2228 * Set pattern to a "normalized" DN from src.
2229 * At present it simply eats the (optional) space after
2230 * a RDN separator (,)
2231 * Eventually will evolve in a more complete normalization
2234 acl_regex_normalized_dn(
2236 struct berval *pattern )
2241 str = ch_strdup( src );
2242 len = strlen( src );
2244 for ( p = str; p && p[0]; p++ ) {
2246 if ( p[0] == '\\' && p[1] ) {
2248 * if escaping a hex pair we should
2249 * increment p twice; however, in that
2250 * case the second hex number does
2256 if ( p[0] == ',' && p[1] == ' ' ) {
2260 * too much space should be an error if we are pedantic
2262 for ( q = &p[2]; q[0] == ' '; q++ ) {
2265 AC_MEMCPY( p+1, q, len-(q-str)+1);
2268 pattern->bv_val = str;
2269 pattern->bv_len = p - str;
2282 if ( (*right = strchr( line, splitchar )) != NULL ) {
2283 *((*right)++) = '\0';
2288 access_append( Access **l, Access *a )
2290 for ( ; *l != NULL; l = &(*l)->a_next ) {
2298 acl_append( AccessControl **l, AccessControl *a, int pos )
2302 for (i=0 ; i != pos && *l != NULL; l = &(*l)->acl_next, i++ ) {
2311 access_free( Access *a )
2313 if ( !BER_BVISNULL( &a->a_dn_pat ) ) {
2314 free( a->a_dn_pat.bv_val );
2316 if ( !BER_BVISNULL( &a->a_realdn_pat ) ) {
2317 free( a->a_realdn_pat.bv_val );
2319 if ( !BER_BVISNULL( &a->a_peername_pat ) ) {
2320 free( a->a_peername_pat.bv_val );
2322 if ( !BER_BVISNULL( &a->a_sockname_pat ) ) {
2323 free( a->a_sockname_pat.bv_val );
2325 if ( !BER_BVISNULL( &a->a_domain_pat ) ) {
2326 free( a->a_domain_pat.bv_val );
2328 if ( !BER_BVISNULL( &a->a_sockurl_pat ) ) {
2329 free( a->a_sockurl_pat.bv_val );
2331 if ( !BER_BVISNULL( &a->a_set_pat ) ) {
2332 free( a->a_set_pat.bv_val );
2334 if ( !BER_BVISNULL( &a->a_group_pat ) ) {
2335 free( a->a_group_pat.bv_val );
2338 if ( a->a_dynacl != NULL ) {
2340 for ( da = a->a_dynacl; da; ) {
2341 slap_dynacl_t *tmp = da;
2345 if ( tmp->da_destroy ) {
2346 tmp->da_destroy( tmp->da_private );
2352 #endif /* SLAP_DYNACL */
2357 acl_free( AccessControl *a )
2362 if ( a->acl_filter ) {
2363 filter_free( a->acl_filter );
2365 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2366 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
2367 regfree( &a->acl_dn_re );
2369 free ( a->acl_dn_pat.bv_val );
2371 if ( a->acl_attrs ) {
2372 for ( an = a->acl_attrs; !BER_BVISNULL( &an->an_name ); an++ ) {
2373 free( an->an_name.bv_val );
2375 free( a->acl_attrs );
2377 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
2378 regfree( &a->acl_attrval_re );
2381 if ( !BER_BVISNULL( &a->acl_attrval ) ) {
2382 ber_memfree( a->acl_attrval.bv_val );
2385 for ( ; a->acl_access; a->acl_access = n ) {
2386 n = a->acl_access->a_next;
2387 access_free( a->acl_access );
2392 /* Because backend_startup uses acl_append to tack on the global_acl to
2393 * the end of each backend's acl, we cannot just take one argument and
2394 * merrily free our way to the end of the list. backend_destroy calls us
2395 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
2396 * point. config_destroy calls us with global_acl in arg1 and NULL in
2397 * arg2, so we then proceed to polish off the global_acl.
2400 acl_destroy( AccessControl *a, AccessControl *end )
2404 for ( ; a && a != end; a = n ) {
2411 access2str( slap_access_t access )
2413 if ( access == ACL_NONE ) {
2416 } else if ( access == ACL_DISCLOSE ) {
2419 } else if ( access == ACL_AUTH ) {
2422 } else if ( access == ACL_COMPARE ) {
2425 } else if ( access == ACL_SEARCH ) {
2428 } else if ( access == ACL_READ ) {
2431 } else if ( access == ACL_WRITE ) {
2434 } else if ( access == ACL_WADD ) {
2437 } else if ( access == ACL_WDEL ) {
2440 } else if ( access == ACL_MANAGE ) {
2449 str2access( const char *str )
2451 if ( strcasecmp( str, "none" ) == 0 ) {
2454 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2455 #ifndef SLAP_ACL_HONOR_DISCLOSE
2456 Debug( LDAP_DEBUG_ACL, "str2access: warning, "
2457 "\"disclose\" privilege disabled.\n",
2459 #endif /* SLAP_ACL_HONOR_DISCLOSE */
2460 return ACL_DISCLOSE;
2462 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2465 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2468 } else if ( strcasecmp( str, "search" ) == 0 ) {
2471 } else if ( strcasecmp( str, "read" ) == 0 ) {
2474 } else if ( strcasecmp( str, "write" ) == 0 ) {
2477 } else if ( strcasecmp( str, "add" ) == 0 ) {
2480 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2483 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2487 return( ACL_INVALID_ACCESS );
2490 #define ACLBUF_MAXLEN 8192
2492 static char aclbuf[ACLBUF_MAXLEN];
2495 dnaccess2text( slap_dn_access *bdn, char *ptr, int is_realdn )
2500 ptr = lutil_strcopy( ptr, "real" );
2503 if ( ber_bvccmp( &bdn->a_pat, '*' ) ||
2504 bdn->a_style == ACL_STYLE_ANONYMOUS ||
2505 bdn->a_style == ACL_STYLE_USERS ||
2506 bdn->a_style == ACL_STYLE_SELF )
2509 assert( ! ber_bvccmp( &bdn->a_pat, '*' ) );
2512 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2513 if ( bdn->a_style == ACL_STYLE_SELF && bdn->a_self_level != 0 ) {
2514 int n = sprintf( ptr, ".level{%d}", bdn->a_self_level );
2521 ptr = lutil_strcopy( ptr, "dn." );
2522 if ( bdn->a_style == ACL_STYLE_BASE )
2523 ptr = lutil_strcopy( ptr, style_base );
2525 ptr = lutil_strcopy( ptr, style_strings[bdn->a_style] );
2526 if ( bdn->a_style == ACL_STYLE_LEVEL ) {
2527 int n = sprintf( ptr, "{%d}", bdn->a_level );
2532 if ( bdn->a_expand ) {
2533 ptr = lutil_strcopy( ptr, ",expand" );
2537 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2544 access2text( Access *b, char *ptr )
2546 char maskbuf[ACCESSMASK_MAXLEN];
2548 ptr = lutil_strcopy( ptr, "\tby" );
2550 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
2551 ptr = dnaccess2text( &b->a_dn, ptr, 0 );
2554 ptr = lutil_strcopy( ptr, " dnattr=" );
2555 ptr = lutil_strcopy( ptr, b->a_dn_at->ad_cname.bv_val );
2558 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
2559 ptr = dnaccess2text( &b->a_realdn, ptr, 1 );
2561 if ( b->a_realdn_at ) {
2562 ptr = lutil_strcopy( ptr, " realdnattr=" );
2563 ptr = lutil_strcopy( ptr, b->a_realdn_at->ad_cname.bv_val );
2566 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
2567 ptr = lutil_strcopy( ptr, " group/" );
2568 ptr = lutil_strcopy( ptr, b->a_group_oc ?
2569 b->a_group_oc->soc_cname.bv_val : SLAPD_GROUP_CLASS );
2571 ptr = lutil_strcopy( ptr, b->a_group_at ?
2572 b->a_group_at->ad_cname.bv_val : SLAPD_GROUP_ATTR );
2574 ptr = lutil_strcopy( ptr, style_strings[b->a_group_style] );
2577 ptr = lutil_strcopy( ptr, b->a_group_pat.bv_val );
2581 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
2582 ptr = lutil_strcopy( ptr, " peername" );
2584 ptr = lutil_strcopy( ptr, style_strings[b->a_peername_style] );
2587 ptr = lutil_strcopy( ptr, b->a_peername_pat.bv_val );
2591 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
2592 ptr = lutil_strcopy( ptr, " sockname" );
2594 ptr = lutil_strcopy( ptr, style_strings[b->a_sockname_style] );
2597 ptr = lutil_strcopy( ptr, b->a_sockname_pat.bv_val );
2601 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
2602 ptr = lutil_strcopy( ptr, " domain" );
2604 ptr = lutil_strcopy( ptr, style_strings[b->a_domain_style] );
2605 if ( b->a_domain_expand ) {
2606 ptr = lutil_strcopy( ptr, ",expand" );
2609 ptr = lutil_strcopy( ptr, b->a_domain_pat.bv_val );
2612 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
2613 ptr = lutil_strcopy( ptr, " sockurl" );
2615 ptr = lutil_strcopy( ptr, style_strings[b->a_sockurl_style] );
2618 ptr = lutil_strcopy( ptr, b->a_sockurl_pat.bv_val );
2622 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
2623 ptr = lutil_strcopy( ptr, " set" );
2625 ptr = lutil_strcopy( ptr, style_strings[b->a_set_style] );
2628 ptr = lutil_strcopy( ptr, b->a_set_pat.bv_val );
2633 if ( b->a_dynacl ) {
2636 for ( da = b->a_dynacl; da; da = da->da_next ) {
2637 if ( da->da_unparse ) {
2638 struct berval bv = BER_BVNULL;
2639 (void)( *da->da_unparse )( da->da_private, &bv );
2640 assert( !BER_BVISNULL( &bv ) );
2641 ptr = lutil_strcopy( ptr, bv.bv_val );
2642 ch_free( bv.bv_val );
2646 #endif /* SLAP_DYNACL */
2648 /* Security Strength Factors */
2649 if ( b->a_authz.sai_ssf ) {
2650 ptr += sprintf( ptr, " ssf=%u",
2651 b->a_authz.sai_ssf );
2653 if ( b->a_authz.sai_transport_ssf ) {
2654 ptr += sprintf( ptr, " transport_ssf=%u",
2655 b->a_authz.sai_transport_ssf );
2657 if ( b->a_authz.sai_tls_ssf ) {
2658 ptr += sprintf( ptr, " tls_ssf=%u",
2659 b->a_authz.sai_tls_ssf );
2661 if ( b->a_authz.sai_sasl_ssf ) {
2662 ptr += sprintf( ptr, " sasl_ssf=%u",
2663 b->a_authz.sai_sasl_ssf );
2667 if ( b->a_dn_self ) {
2668 ptr = lutil_strcopy( ptr, "self" );
2669 } else if ( b->a_realdn_self ) {
2670 ptr = lutil_strcopy( ptr, "realself" );
2672 ptr = lutil_strcopy( ptr, accessmask2str( b->a_access_mask, maskbuf, 0 ));
2673 if ( !maskbuf[0] ) ptr--;
2675 if( b->a_type == ACL_BREAK ) {
2676 ptr = lutil_strcopy( ptr, " break" );
2678 } else if( b->a_type == ACL_CONTINUE ) {
2679 ptr = lutil_strcopy( ptr, " continue" );
2681 } else if( b->a_type != ACL_STOP ) {
2682 ptr = lutil_strcopy( ptr, " unknown-control" );
2684 if ( !maskbuf[0] ) ptr = lutil_strcopy( ptr, " stop" );
2692 acl_unparse( AccessControl *a, struct berval *bv )
2698 bv->bv_val = aclbuf;
2703 ptr = lutil_strcopy( ptr, "to" );
2704 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2706 ptr = lutil_strcopy( ptr, " dn." );
2707 if ( a->acl_dn_style == ACL_STYLE_BASE )
2708 ptr = lutil_strcopy( ptr, style_base );
2710 ptr = lutil_strcopy( ptr, style_strings[a->acl_dn_style] );
2713 ptr = lutil_strcopy( ptr, a->acl_dn_pat.bv_val );
2714 ptr = lutil_strcopy( ptr, "\"\n" );
2717 if ( a->acl_filter != NULL ) {
2718 struct berval bv = BER_BVNULL;
2721 filter2bv( a->acl_filter, &bv );
2722 ptr = lutil_strcopy( ptr, " filter=\"" );
2723 ptr = lutil_strcopy( ptr, bv.bv_val );
2726 ch_free( bv.bv_val );
2729 if ( a->acl_attrs != NULL ) {
2734 ptr = lutil_strcopy( ptr, " attrs=" );
2735 for ( an = a->acl_attrs; an && !BER_BVISNULL( &an->an_name ); an++ ) {
2736 if ( ! first ) *ptr++ = ',';
2738 *ptr++ = an->an_oc_exclude ? '!' : '@';
2739 ptr = lutil_strcopy( ptr, an->an_oc->soc_cname.bv_val );
2742 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2749 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
2751 ptr = lutil_strcopy( ptr, " val." );
2752 if ( a->acl_attrval_style == ACL_STYLE_BASE &&
2753 a->acl_attrs[0].an_desc->ad_type->sat_syntax ==
2754 slap_schema.si_syn_distinguishedName )
2755 ptr = lutil_strcopy( ptr, style_base );
2757 ptr = lutil_strcopy( ptr, style_strings[a->acl_attrval_style] );
2760 ptr = lutil_strcopy( ptr, a->acl_attrval.bv_val );
2766 ptr = lutil_strcopy( ptr, " *\n" );
2769 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
2770 ptr = access2text( b, ptr );
2773 bv->bv_len = ptr - bv->bv_val;
2778 print_acl( Backend *be, AccessControl *a )
2782 acl_unparse( a, &bv );
2783 fprintf( stderr, "%s ACL: access %s\n",
2784 be == NULL ? "Global" : "Backend", bv.bv_val );
2786 #endif /* LDAP_DEBUG */