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)",
649 a->acl_attrs[ 0 ].an_name.bv_val, rc, text );
650 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s.\n",
651 fname, lineno, buf );
657 Debug( LDAP_DEBUG_ANY,
658 "%s: line %d: expecting <what> got \"%s\"\n",
659 fname, lineno, left );
664 if ( !BER_BVISNULL( &a->acl_dn_pat ) &&
665 ber_bvccmp( &a->acl_dn_pat, '*' ) )
667 free( a->acl_dn_pat.bv_val );
668 BER_BVZERO( &a->acl_dn_pat );
669 a->acl_dn_style = ACL_STYLE_REGEX;
672 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
673 a->acl_dn_style != ACL_STYLE_REGEX )
675 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
677 rc = dnNormalize( 0, NULL, NULL, &a->acl_dn_pat, &bv, NULL);
678 if ( rc != LDAP_SUCCESS ) {
679 Debug( LDAP_DEBUG_ANY,
680 "%s: line %d: bad DN \"%s\" in to DN clause\n",
681 fname, lineno, a->acl_dn_pat.bv_val );
684 free( a->acl_dn_pat.bv_val );
688 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
689 REG_EXTENDED | REG_ICASE );
691 char err[ SLAP_TEXT_BUFLEN ],
692 buf[ SLAP_TEXT_BUFLEN ];
694 regerror( e, &a->acl_dn_re, err, sizeof( err ) );
695 snprintf( buf, sizeof( buf ),
696 "regular expression \"%s\" bad because of %s",
698 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
699 fname, lineno, buf );
705 /* by clause - select who has what access to entries */
706 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
708 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
709 "to clause required before by clause in access line\n",
715 * by clause consists of <who> and <access>
719 Debug( LDAP_DEBUG_ANY,
720 "%s: line %d: premature EOL: expecting <who>\n",
725 b = (Access *) ch_calloc( 1, sizeof(Access) );
727 ACL_INVALIDATE( b->a_access_mask );
730 for ( ; i < argc; i++ ) {
731 slap_style_t sty = ACL_STYLE_REGEX;
732 char *style_modifier = NULL;
733 char *style_level = NULL;
736 slap_dn_access *bdn = &b->a_dn;
739 split( argv[i], '=', &left, &right );
740 split( left, '.', &left, &style );
742 split( style, ',', &style, &style_modifier );
744 if ( strncasecmp( style, "level", STRLENOF( "level" ) ) == 0 ) {
745 split( style, '{', &style, &style_level );
746 if ( style_level != NULL ) {
747 char *p = strchr( style_level, '}' );
749 Debug( LDAP_DEBUG_ANY,
750 "%s: line %d: premature eol: "
751 "expecting closing '}' in \"level{n}\"\n",
754 } else if ( p == style_level ) {
755 Debug( LDAP_DEBUG_ANY,
756 "%s: line %d: empty level "
766 if ( style == NULL || *style == '\0' ||
767 strcasecmp( style, "exact" ) == 0 ||
768 strcasecmp( style, "baseObject" ) == 0 ||
769 strcasecmp( style, "base" ) == 0 )
771 sty = ACL_STYLE_BASE;
773 } else if ( strcasecmp( style, "onelevel" ) == 0 ||
774 strcasecmp( style, "one" ) == 0 )
778 } else if ( strcasecmp( style, "subtree" ) == 0 ||
779 strcasecmp( style, "sub" ) == 0 )
781 sty = ACL_STYLE_SUBTREE;
783 } else if ( strcasecmp( style, "children" ) == 0 ) {
784 sty = ACL_STYLE_CHILDREN;
786 } else if ( strcasecmp( style, "level" ) == 0 )
788 if ( lutil_atoi( &level, style_level ) != 0 ) {
789 Debug( LDAP_DEBUG_ANY,
790 "%s: line %d: unable to parse level "
796 sty = ACL_STYLE_LEVEL;
798 } else if ( strcasecmp( style, "regex" ) == 0 ) {
799 sty = ACL_STYLE_REGEX;
801 } else if ( strcasecmp( style, "expand" ) == 0 ) {
802 sty = ACL_STYLE_EXPAND;
804 } else if ( strcasecmp( style, "ip" ) == 0 ) {
807 } else if ( strcasecmp( style, "path" ) == 0 ) {
808 sty = ACL_STYLE_PATH;
809 #ifndef LDAP_PF_LOCAL
810 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
812 "\"path\" style modifier is useless without local.\n",
815 #endif /* LDAP_PF_LOCAL */
818 Debug( LDAP_DEBUG_ANY,
819 "%s: line %d: unknown style \"%s\" in by clause\n",
820 fname, lineno, style );
824 if ( style_modifier &&
825 strcasecmp( style_modifier, "expand" ) == 0 )
828 case ACL_STYLE_REGEX:
829 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
830 "\"regex\" style implies \"expand\" modifier.\n",
835 case ACL_STYLE_EXPAND:
839 /* we'll see later if it's pertinent */
845 /* expand in <who> needs regex in <what> */
846 if ( ( sty == ACL_STYLE_EXPAND || expand )
847 && a->acl_dn_style != ACL_STYLE_REGEX )
849 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL, "%s: line %d: \"expand\" style "
850 "or modifier used in conjunction with a non-regex <what> clause.\n",
855 if ( strncasecmp( left, "real", STRLENOF( "real" ) ) == 0 ) {
858 left += STRLENOF( "real" );
861 if ( strcasecmp( left, "*" ) == 0 ) {
866 ber_str2bv( "*", STRLENOF( "*" ), 1, &bv );
867 sty = ACL_STYLE_REGEX;
869 } else if ( strcasecmp( left, "anonymous" ) == 0 ) {
870 ber_str2bv("anonymous", STRLENOF( "anonymous" ), 1, &bv);
871 sty = ACL_STYLE_ANONYMOUS;
873 } else if ( strcasecmp( left, "users" ) == 0 ) {
874 ber_str2bv("users", STRLENOF( "users" ), 1, &bv);
875 sty = ACL_STYLE_USERS;
877 } else if ( strcasecmp( left, "self" ) == 0 ) {
878 ber_str2bv("self", STRLENOF( "self" ), 1, &bv);
879 sty = ACL_STYLE_SELF;
881 } else if ( strcasecmp( left, "dn" ) == 0 ) {
882 if ( sty == ACL_STYLE_REGEX ) {
883 bdn->a_style = ACL_STYLE_REGEX;
884 if ( right == NULL ) {
889 bdn->a_style = ACL_STYLE_USERS;
891 } else if (*right == '\0' ) {
893 ber_str2bv("anonymous",
894 STRLENOF( "anonymous" ),
896 bdn->a_style = ACL_STYLE_ANONYMOUS;
898 } else if ( strcmp( right, "*" ) == 0 ) {
900 /* any or users? users for now */
904 bdn->a_style = ACL_STYLE_USERS;
906 } else if ( strcmp( right, ".+" ) == 0
907 || strcmp( right, "^.+" ) == 0
908 || strcmp( right, ".+$" ) == 0
909 || strcmp( right, "^.+$" ) == 0
910 || strcmp( right, ".+$$" ) == 0
911 || strcmp( right, "^.+$$" ) == 0 )
916 bdn->a_style = ACL_STYLE_USERS;
918 } else if ( strcmp( right, ".*" ) == 0
919 || strcmp( right, "^.*" ) == 0
920 || strcmp( right, ".*$" ) == 0
921 || strcmp( right, "^.*$" ) == 0
922 || strcmp( right, ".*$$" ) == 0
923 || strcmp( right, "^.*$$" ) == 0 )
930 acl_regex_normalized_dn( right, &bv );
931 if ( !ber_bvccmp( &bv, '*' ) ) {
932 regtest( fname, lineno, bv.bv_val );
936 } else if ( right == NULL || *right == '\0' ) {
937 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
938 "missing \"=\" in (or value after) \"%s\" "
940 fname, lineno, left );
944 ber_str2bv( right, 0, 1, &bv );
951 if ( !BER_BVISNULL( &bv ) ) {
952 if ( !BER_BVISEMPTY( &bdn->a_pat ) ) {
953 Debug( LDAP_DEBUG_ANY,
954 "%s: line %d: dn pattern already specified.\n",
959 if ( sty != ACL_STYLE_REGEX &&
960 sty != ACL_STYLE_ANONYMOUS &&
961 sty != ACL_STYLE_USERS &&
962 sty != ACL_STYLE_SELF &&
965 rc = dnNormalize(0, NULL, NULL,
966 &bv, &bdn->a_pat, NULL);
967 if ( rc != LDAP_SUCCESS ) {
968 Debug( LDAP_DEBUG_ANY,
969 "%s: line %d: bad DN \"%s\" in by DN clause\n",
970 fname, lineno, bv.bv_val );
974 if ( sty == ACL_STYLE_BASE
976 && !BER_BVISNULL( &be->be_rootndn )
977 && dn_match( &bdn->a_pat, &be->be_rootndn ) )
979 Debug( LDAP_DEBUG_ANY,
980 "%s: line %d: rootdn is always granted "
981 "unlimited privileges.\n",
993 for ( exp = strchr( bdn->a_pat.bv_val, '$' );
994 exp && (ber_len_t)(exp - bdn->a_pat.bv_val)
996 exp = strchr( exp, '$' ) )
998 if ( isdigit( (unsigned char) exp[ 1 ] ) ) {
1005 bdn->a_expand = expand;
1008 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1009 "\"expand\" used with no expansions in \"pattern\".\n",
1014 if ( sty == ACL_STYLE_SELF ) {
1015 bdn->a_self_level = level;
1019 Debug( LDAP_DEBUG_ANY,
1020 "%s: line %d: bad negative level \"%d\" "
1021 "in by DN clause\n",
1022 fname, lineno, level );
1024 } else if ( level == 1 ) {
1025 Debug( LDAP_DEBUG_ANY,
1026 "%s: line %d: \"onelevel\" should be used "
1027 "instead of \"level{1}\" in by DN clause\n",
1029 } else if ( level == 0 && sty == ACL_STYLE_LEVEL ) {
1030 Debug( LDAP_DEBUG_ANY,
1031 "%s: line %d: \"base\" should be used "
1032 "instead of \"level{0}\" in by DN clause\n",
1036 bdn->a_level = level;
1041 if ( strcasecmp( left, "dnattr" ) == 0 ) {
1042 if ( right == NULL || right[0] == '\0' ) {
1043 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1044 "missing \"=\" in (or value after) \"%s\" "
1046 fname, lineno, left );
1050 if( bdn->a_at != NULL ) {
1051 Debug( LDAP_DEBUG_ANY,
1052 "%s: line %d: dnattr already specified.\n",
1057 rc = slap_str2ad( right, &bdn->a_at, &text );
1059 if( rc != LDAP_SUCCESS ) {
1060 char buf[ SLAP_TEXT_BUFLEN ];
1062 snprintf( buf, sizeof( buf ),
1063 "dnattr \"%s\": %s",
1065 Debug( LDAP_DEBUG_ANY,
1066 "%s: line %d: %s\n",
1067 fname, lineno, buf );
1072 if( !is_at_syntax( bdn->a_at->ad_type,
1073 SLAPD_DN_SYNTAX ) &&
1074 !is_at_syntax( bdn->a_at->ad_type,
1075 SLAPD_NAMEUID_SYNTAX ))
1077 char buf[ SLAP_TEXT_BUFLEN ];
1079 snprintf( buf, sizeof( buf ),
1081 "inappropriate syntax: %s\n",
1083 bdn->a_at->ad_type->sat_syntax_oid );
1084 Debug( LDAP_DEBUG_ANY,
1085 "%s: line %d: %s\n",
1086 fname, lineno, buf );
1090 if( bdn->a_at->ad_type->sat_equality == NULL ) {
1091 Debug( LDAP_DEBUG_ANY,
1092 "%s: line %d: dnattr \"%s\": "
1093 "inappropriate matching (no EQUALITY)\n",
1094 fname, lineno, right );
1101 if ( strncasecmp( left, "group", STRLENOF( "group" ) ) == 0 ) {
1106 case ACL_STYLE_REGEX:
1107 /* legacy, tolerated */
1108 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
1110 "deprecated group style \"regex\"; "
1111 "use \"expand\" instead.\n",
1113 sty = ACL_STYLE_EXPAND;
1116 case ACL_STYLE_BASE:
1117 /* legal, traditional */
1118 case ACL_STYLE_EXPAND:
1119 /* legal, substring expansion; supersedes regex */
1124 Debug( LDAP_DEBUG_ANY,
1126 "inappropriate style \"%s\" in by clause.\n",
1127 fname, lineno, style );
1131 if ( right == NULL || right[0] == '\0' ) {
1132 Debug( LDAP_DEBUG_ANY,
1134 "missing \"=\" in (or value after) \"%s\" "
1136 fname, lineno, left );
1140 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1141 Debug( LDAP_DEBUG_ANY,
1142 "%s: line %d: group pattern already specified.\n",
1147 /* format of string is
1148 "group/objectClassValue/groupAttrName" */
1149 if ( ( value = strchr(left, '/') ) != NULL ) {
1151 if ( *value && ( name = strchr( value, '/' ) ) != NULL ) {
1156 b->a_group_style = sty;
1157 if ( sty == ACL_STYLE_EXPAND ) {
1158 acl_regex_normalized_dn( right, &bv );
1159 if ( !ber_bvccmp( &bv, '*' ) ) {
1160 regtest( fname, lineno, bv.bv_val );
1162 b->a_group_pat = bv;
1165 ber_str2bv( right, 0, 0, &bv );
1166 rc = dnNormalize( 0, NULL, NULL, &bv,
1167 &b->a_group_pat, NULL );
1168 if ( rc != LDAP_SUCCESS ) {
1169 Debug( LDAP_DEBUG_ANY,
1170 "%s: line %d: bad DN \"%s\".\n",
1171 fname, lineno, right );
1176 if ( value && *value ) {
1177 b->a_group_oc = oc_find( value );
1180 if ( b->a_group_oc == NULL ) {
1181 Debug( LDAP_DEBUG_ANY,
1182 "%s: line %d: group objectclass "
1183 "\"%s\" unknown.\n",
1184 fname, lineno, value );
1189 b->a_group_oc = oc_find( SLAPD_GROUP_CLASS );
1191 if( b->a_group_oc == NULL ) {
1192 Debug( LDAP_DEBUG_ANY,
1193 "%s: line %d: group default objectclass "
1194 "\"%s\" unknown.\n",
1195 fname, lineno, SLAPD_GROUP_CLASS );
1200 if ( is_object_subclass( slap_schema.si_oc_referral,
1203 Debug( LDAP_DEBUG_ANY,
1204 "%s: line %d: group objectclass \"%s\" "
1205 "is subclass of referral.\n",
1206 fname, lineno, value );
1210 if ( is_object_subclass( slap_schema.si_oc_alias,
1213 Debug( LDAP_DEBUG_ANY,
1214 "%s: line %d: group objectclass \"%s\" "
1215 "is subclass of alias.\n",
1216 fname, lineno, value );
1220 if ( name && *name ) {
1221 rc = slap_str2ad( name, &b->a_group_at, &text );
1223 if( rc != LDAP_SUCCESS ) {
1224 char buf[ SLAP_TEXT_BUFLEN ];
1226 snprintf( buf, sizeof( buf ),
1227 "group \"%s\": %s.",
1229 Debug( LDAP_DEBUG_ANY,
1230 "%s: line %d: %s\n",
1231 fname, lineno, buf );
1237 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
1239 if ( rc != LDAP_SUCCESS ) {
1240 char buf[ SLAP_TEXT_BUFLEN ];
1242 snprintf( buf, sizeof( buf ),
1243 "group \"%s\": %s.",
1244 SLAPD_GROUP_ATTR, text );
1245 Debug( LDAP_DEBUG_ANY,
1246 "%s: line %d: %s\n",
1247 fname, lineno, buf );
1252 if ( !is_at_syntax( b->a_group_at->ad_type,
1253 SLAPD_DN_SYNTAX ) &&
1254 !is_at_syntax( b->a_group_at->ad_type,
1255 SLAPD_NAMEUID_SYNTAX ) &&
1256 !is_at_subtype( b->a_group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ) )
1258 char buf[ SLAP_TEXT_BUFLEN ];
1260 snprintf( buf, sizeof( buf ),
1261 "group \"%s\": inappropriate syntax: %s.",
1263 b->a_group_at->ad_type->sat_syntax_oid );
1264 Debug( LDAP_DEBUG_ANY,
1265 "%s: line %d: %s\n",
1266 fname, lineno, buf );
1273 ObjectClass *ocs[2];
1275 ocs[0] = b->a_group_oc;
1278 rc = oc_check_allowed( b->a_group_at->ad_type,
1282 char buf[ SLAP_TEXT_BUFLEN ];
1284 snprintf( buf, sizeof( buf ),
1285 "group: \"%s\" not allowed by \"%s\".",
1286 b->a_group_at->ad_cname.bv_val,
1287 b->a_group_oc->soc_oid );
1288 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
1289 fname, lineno, buf );
1296 if ( strcasecmp( left, "peername" ) == 0 ) {
1298 case ACL_STYLE_REGEX:
1299 case ACL_STYLE_BASE:
1300 /* legal, traditional */
1301 case ACL_STYLE_EXPAND:
1302 /* cheap replacement to regex for simple expansion */
1304 case ACL_STYLE_PATH:
1305 /* legal, peername specific */
1309 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1310 "inappropriate style \"%s\" in by clause.\n",
1311 fname, lineno, style );
1315 if ( right == NULL || right[0] == '\0' ) {
1316 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1317 "missing \"=\" in (or value after) \"%s\" "
1319 fname, lineno, left );
1323 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1324 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1325 "peername pattern already specified.\n",
1330 b->a_peername_style = sty;
1331 if ( sty == ACL_STYLE_REGEX ) {
1332 acl_regex_normalized_dn( right, &bv );
1333 if ( !ber_bvccmp( &bv, '*' ) ) {
1334 regtest( fname, lineno, bv.bv_val );
1336 b->a_peername_pat = bv;
1339 ber_str2bv( right, 0, 1, &b->a_peername_pat );
1341 if ( sty == ACL_STYLE_IP ) {
1346 split( right, '{', &addr, &port );
1347 split( addr, '%', &addr, &mask );
1349 b->a_peername_addr = inet_addr( addr );
1350 if ( b->a_peername_addr == (unsigned long)(-1) ) {
1351 /* illegal address */
1352 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1353 "illegal peername address \"%s\".\n",
1354 fname, lineno, addr );
1358 b->a_peername_mask = (unsigned long)(-1);
1359 if ( mask != NULL ) {
1360 b->a_peername_mask = inet_addr( mask );
1361 if ( b->a_peername_mask ==
1362 (unsigned long)(-1) )
1365 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1366 "illegal peername address mask "
1368 fname, lineno, mask );
1373 b->a_peername_port = -1;
1377 b->a_peername_port = strtol( port, &end, 10 );
1378 if ( end == port || end[0] != '}' ) {
1380 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1381 "illegal peername port specification "
1383 fname, lineno, port );
1392 if ( strcasecmp( left, "sockname" ) == 0 ) {
1394 case ACL_STYLE_REGEX:
1395 case ACL_STYLE_BASE:
1396 /* legal, traditional */
1397 case ACL_STYLE_EXPAND:
1398 /* cheap replacement to regex for simple expansion */
1403 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1404 "inappropriate style \"%s\" in by clause\n",
1405 fname, lineno, style );
1409 if ( right == NULL || right[0] == '\0' ) {
1410 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1411 "missing \"=\" in (or value after) \"%s\" "
1413 fname, lineno, left );
1417 if ( !BER_BVISNULL( &b->a_sockname_pat ) ) {
1418 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1419 "sockname pattern already specified.\n",
1424 b->a_sockname_style = sty;
1425 if ( sty == ACL_STYLE_REGEX ) {
1426 acl_regex_normalized_dn( right, &bv );
1427 if ( !ber_bvccmp( &bv, '*' ) ) {
1428 regtest( fname, lineno, bv.bv_val );
1430 b->a_sockname_pat = bv;
1433 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
1438 if ( strcasecmp( left, "domain" ) == 0 ) {
1440 case ACL_STYLE_REGEX:
1441 case ACL_STYLE_BASE:
1442 case ACL_STYLE_SUBTREE:
1443 /* legal, traditional */
1446 case ACL_STYLE_EXPAND:
1447 /* tolerated: means exact,expand */
1449 Debug( LDAP_DEBUG_ANY,
1451 "\"expand\" modifier "
1452 "with \"expand\" style.\n",
1455 sty = ACL_STYLE_BASE;
1461 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1462 "inappropriate style \"%s\" in by clause.\n",
1463 fname, lineno, style );
1467 if ( right == NULL || right[0] == '\0' ) {
1468 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1469 "missing \"=\" in (or value after) \"%s\" "
1471 fname, lineno, left );
1475 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1476 Debug( LDAP_DEBUG_ANY,
1477 "%s: line %d: domain pattern already specified.\n",
1482 b->a_domain_style = sty;
1483 b->a_domain_expand = expand;
1484 if ( sty == ACL_STYLE_REGEX ) {
1485 acl_regex_normalized_dn( right, &bv );
1486 if ( !ber_bvccmp( &bv, '*' ) ) {
1487 regtest( fname, lineno, bv.bv_val );
1489 b->a_domain_pat = bv;
1492 ber_str2bv( right, 0, 1, &b->a_domain_pat );
1497 if ( strcasecmp( left, "sockurl" ) == 0 ) {
1499 case ACL_STYLE_REGEX:
1500 case ACL_STYLE_BASE:
1501 /* legal, traditional */
1502 case ACL_STYLE_EXPAND:
1503 /* cheap replacement to regex for simple expansion */
1508 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1509 "inappropriate style \"%s\" in by clause.\n",
1510 fname, lineno, style );
1514 if ( right == NULL || right[0] == '\0' ) {
1515 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1516 "missing \"=\" in (or value after) \"%s\" "
1518 fname, lineno, left );
1522 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1523 Debug( LDAP_DEBUG_ANY,
1524 "%s: line %d: sockurl pattern already specified.\n",
1529 b->a_sockurl_style = sty;
1530 if ( sty == ACL_STYLE_REGEX ) {
1531 acl_regex_normalized_dn( right, &bv );
1532 if ( !ber_bvccmp( &bv, '*' ) ) {
1533 regtest( fname, lineno, bv.bv_val );
1535 b->a_sockurl_pat = bv;
1538 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
1543 if ( strcasecmp( left, "set" ) == 0 ) {
1546 case ACL_STYLE_REGEX:
1547 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
1549 "deprecated set style "
1550 "\"regex\" in <by> clause; "
1551 "use \"expand\" instead.\n",
1553 sty = ACL_STYLE_EXPAND;
1556 case ACL_STYLE_BASE:
1557 case ACL_STYLE_EXPAND:
1561 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1562 "inappropriate style \"%s\" in by clause.\n",
1563 fname, lineno, style );
1567 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1568 Debug( LDAP_DEBUG_ANY,
1569 "%s: line %d: set attribute already specified.\n",
1574 if ( right == NULL || *right == '\0' ) {
1575 Debug( LDAP_DEBUG_ANY,
1576 "%s: line %d: no set is defined.\n",
1581 b->a_set_style = sty;
1582 ber_str2bv( right, 0, 1, &b->a_set_pat );
1592 #if 1 /* tolerate legacy "aci" <who> */
1593 if ( strcasecmp( left, "aci" ) == 0 ) {
1594 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1595 "undocumented deprecated \"aci\" directive "
1596 "is superseded by \"dynacl/aci\".\n",
1601 #endif /* tolerate legacy "aci" <who> */
1602 if ( strncasecmp( left, "dynacl/", STRLENOF( "dynacl/" ) ) == 0 ) {
1603 name = &left[ STRLENOF( "dynacl/" ) ];
1604 opts = strchr( name, '/' );
1612 if ( slap_dynacl_config( fname, lineno, b, name, opts, sty, right ) ) {
1613 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1614 "unable to configure dynacl \"%s\".\n",
1615 fname, lineno, name );
1622 #endif /* SLAP_DYNACL */
1624 if ( strcasecmp( left, "ssf" ) == 0 ) {
1625 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1626 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1627 "inappropriate style \"%s\" in by clause.\n",
1628 fname, lineno, style );
1632 if ( b->a_authz.sai_ssf ) {
1633 Debug( LDAP_DEBUG_ANY,
1634 "%s: line %d: ssf attribute already specified.\n",
1639 if ( right == NULL || *right == '\0' ) {
1640 Debug( LDAP_DEBUG_ANY,
1641 "%s: line %d: no ssf is defined.\n",
1646 if ( lutil_atou( &b->a_authz.sai_ssf, right ) != 0 ) {
1647 Debug( LDAP_DEBUG_ANY,
1648 "%s: line %d: unable to parse ssf value (%s).\n",
1649 fname, lineno, right );
1653 if ( !b->a_authz.sai_ssf ) {
1654 Debug( LDAP_DEBUG_ANY,
1655 "%s: line %d: invalid ssf value (%s).\n",
1656 fname, lineno, right );
1662 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
1663 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1664 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1665 "inappropriate style \"%s\" in by clause.\n",
1666 fname, lineno, style );
1670 if ( b->a_authz.sai_transport_ssf ) {
1671 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1672 "transport_ssf attribute already specified.\n",
1677 if ( right == NULL || *right == '\0' ) {
1678 Debug( LDAP_DEBUG_ANY,
1679 "%s: line %d: no transport_ssf is defined.\n",
1684 if ( lutil_atou( &b->a_authz.sai_transport_ssf, right ) != 0 ) {
1685 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1686 "unable to parse transport_ssf value (%s).\n",
1687 fname, lineno, right );
1691 if ( !b->a_authz.sai_transport_ssf ) {
1692 Debug( LDAP_DEBUG_ANY,
1693 "%s: line %d: invalid transport_ssf value (%s).\n",
1694 fname, lineno, right );
1700 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
1701 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1702 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1703 "inappropriate style \"%s\" in by clause.\n",
1704 fname, lineno, style );
1708 if ( b->a_authz.sai_tls_ssf ) {
1709 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1710 "tls_ssf attribute already specified.\n",
1715 if ( right == NULL || *right == '\0' ) {
1716 Debug( LDAP_DEBUG_ANY,
1717 "%s: line %d: no tls_ssf is defined\n",
1722 if ( lutil_atou( &b->a_authz.sai_tls_ssf, right ) != 0 ) {
1723 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1724 "unable to parse tls_ssf value (%s).\n",
1725 fname, lineno, right );
1729 if ( !b->a_authz.sai_tls_ssf ) {
1730 Debug( LDAP_DEBUG_ANY,
1731 "%s: line %d: invalid tls_ssf value (%s).\n",
1732 fname, lineno, right );
1738 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1739 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1740 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1741 "inappropriate style \"%s\" in by clause.\n",
1742 fname, lineno, style );
1746 if ( b->a_authz.sai_sasl_ssf ) {
1747 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1748 "sasl_ssf attribute already specified.\n",
1753 if ( right == NULL || *right == '\0' ) {
1754 Debug( LDAP_DEBUG_ANY,
1755 "%s: line %d: no sasl_ssf is defined.\n",
1760 if ( lutil_atou( &b->a_authz.sai_sasl_ssf, right ) != 0 ) {
1761 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1762 "unable to parse sasl_ssf value (%s).\n",
1763 fname, lineno, right );
1767 if ( !b->a_authz.sai_sasl_ssf ) {
1768 Debug( LDAP_DEBUG_ANY,
1769 "%s: line %d: invalid sasl_ssf value (%s).\n",
1770 fname, lineno, right );
1776 if ( right != NULL ) {
1783 if ( i == argc || ( strcasecmp( left, "stop" ) == 0 ) ) {
1784 /* out of arguments or plain stop */
1786 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1787 ACL_PRIV_SET( b->a_access_mask, ACL_PRIV_NONE);
1788 b->a_type = ACL_STOP;
1790 access_append( &a->acl_access, b );
1794 if ( strcasecmp( left, "continue" ) == 0 ) {
1795 /* plain continue */
1797 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1798 ACL_PRIV_SET( b->a_access_mask, ACL_PRIV_NONE);
1799 b->a_type = ACL_CONTINUE;
1801 access_append( &a->acl_access, b );
1805 if ( strcasecmp( left, "break" ) == 0 ) {
1806 /* plain continue */
1808 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1809 ACL_PRIV_SET( b->a_access_mask, ACL_PRIV_NONE);
1810 b->a_type = ACL_BREAK;
1812 access_append( &a->acl_access, b );
1816 if ( strcasecmp( left, "by" ) == 0 ) {
1817 /* we've gone too far */
1819 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1820 ACL_PRIV_SET( b->a_access_mask, ACL_PRIV_NONE);
1821 b->a_type = ACL_STOP;
1823 access_append( &a->acl_access, b );
1831 if ( strncasecmp( left, "self", STRLENOF( "self" ) ) == 0 ) {
1833 lleft = &left[ STRLENOF( "self" ) ];
1835 } else if ( strncasecmp( left, "realself", STRLENOF( "realself" ) ) == 0 ) {
1836 b->a_realdn_self = 1;
1837 lleft = &left[ STRLENOF( "realself" ) ];
1840 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( lleft ) );
1843 if ( ACL_IS_INVALID( b->a_access_mask ) ) {
1844 Debug( LDAP_DEBUG_ANY,
1845 "%s: line %d: expecting <access> got \"%s\".\n",
1846 fname, lineno, left );
1850 b->a_type = ACL_STOP;
1852 if ( ++i == argc ) {
1853 /* out of arguments or plain stop */
1854 access_append( &a->acl_access, b );
1858 if ( strcasecmp( argv[i], "continue" ) == 0 ) {
1859 /* plain continue */
1860 b->a_type = ACL_CONTINUE;
1862 } else if ( strcasecmp( argv[i], "break" ) == 0 ) {
1863 /* plain continue */
1864 b->a_type = ACL_BREAK;
1866 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1871 access_append( &a->acl_access, b );
1875 Debug( LDAP_DEBUG_ANY,
1876 "%s: line %d: expecting \"to\" "
1877 "or \"by\" got \"%s\"\n",
1878 fname, lineno, argv[i] );
1883 /* if we have no real access clause, complain and do nothing */
1885 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1886 "warning: no access clause(s) specified in access line.\n",
1892 if ( slap_debug & LDAP_DEBUG_ACL ) {
1897 if ( a->acl_access == NULL ) {
1898 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1899 "warning: no by clause(s) specified in access line.\n",
1905 if ( be->be_nsuffix == NULL ) {
1906 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1907 "scope checking needs suffix before ACLs.\n",
1909 /* go ahead, since checking is not authoritative */
1910 } else if ( !BER_BVISNULL( &be->be_nsuffix[ 1 ] ) ) {
1911 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1912 "scope checking only applies to single-valued "
1913 "suffix databases\n",
1915 /* go ahead, since checking is not authoritative */
1917 switch ( check_scope( be, a ) ) {
1918 case ACL_SCOPE_UNKNOWN:
1919 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1920 "cannot assess the validity of the ACL scope within "
1921 "backend naming context\n",
1925 case ACL_SCOPE_WARN:
1926 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1927 "ACL could be out of scope within backend naming context\n",
1931 case ACL_SCOPE_PARTIAL:
1932 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1933 "ACL appears to be partially out of scope within "
1934 "backend naming context\n",
1939 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1940 "ACL appears to be out of scope within "
1941 "backend naming context\n",
1949 acl_append( &be->be_acl, a, pos );
1952 acl_append( &frontendDB->be_acl, a, pos );
1959 if ( b ) access_free( b );
1960 if ( a ) acl_free( a );
1965 accessmask2str( slap_mask_t mask, char *buf, int debug )
1970 assert( buf != NULL );
1972 if ( ACL_IS_INVALID( mask ) ) {
1978 if ( ACL_IS_LEVEL( mask ) ) {
1979 if ( ACL_LVL_IS_NONE(mask) ) {
1980 ptr = lutil_strcopy( ptr, "none" );
1982 } else if ( ACL_LVL_IS_DISCLOSE(mask) ) {
1983 ptr = lutil_strcopy( ptr, "disclose" );
1985 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1986 ptr = lutil_strcopy( ptr, "auth" );
1988 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1989 ptr = lutil_strcopy( ptr, "compare" );
1991 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1992 ptr = lutil_strcopy( ptr, "search" );
1994 } else if ( ACL_LVL_IS_READ(mask) ) {
1995 ptr = lutil_strcopy( ptr, "read" );
1997 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1998 ptr = lutil_strcopy( ptr, "write" );
2000 } else if ( ACL_LVL_IS_WADD(mask) ) {
2001 ptr = lutil_strcopy( ptr, "add" );
2003 } else if ( ACL_LVL_IS_WDEL(mask) ) {
2004 ptr = lutil_strcopy( ptr, "delete" );
2006 } else if ( ACL_LVL_IS_MANAGE(mask) ) {
2007 ptr = lutil_strcopy( ptr, "manage" );
2010 ptr = lutil_strcopy( ptr, "unknown" );
2020 if( ACL_IS_ADDITIVE( mask ) ) {
2023 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
2030 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_MANAGE) ) {
2035 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
2039 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WADD) ) {
2043 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WDEL) ) {
2048 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
2053 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
2058 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
2063 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
2068 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_DISCLOSE) ) {
2073 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
2082 if ( ACL_IS_LEVEL( mask ) ) {
2092 str2accessmask( const char *str )
2096 if( !ASCII_ALPHA(str[0]) ) {
2099 if ( str[0] == '=' ) {
2102 } else if( str[0] == '+' ) {
2103 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
2105 } else if( str[0] == '-' ) {
2106 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
2109 ACL_INVALIDATE(mask);
2113 for( i=1; str[i] != '\0'; i++ ) {
2114 if( TOLOWER((unsigned char) str[i]) == 'm' ) {
2115 ACL_PRIV_SET(mask, ACL_PRIV_MANAGE);
2117 } else if( TOLOWER((unsigned char) str[i]) == 'w' ) {
2118 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
2120 } else if( TOLOWER((unsigned char) str[i]) == 'a' ) {
2121 ACL_PRIV_SET(mask, ACL_PRIV_WADD);
2123 } else if( TOLOWER((unsigned char) str[i]) == 'z' ) {
2124 ACL_PRIV_SET(mask, ACL_PRIV_WDEL);
2126 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
2127 ACL_PRIV_SET(mask, ACL_PRIV_READ);
2129 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
2130 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
2132 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
2133 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
2135 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
2136 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
2138 } else if( TOLOWER((unsigned char) str[i]) == 'd' ) {
2139 ACL_PRIV_SET(mask, ACL_PRIV_DISCLOSE);
2141 } else if( str[i] == '0' ) {
2142 ACL_PRIV_SET(mask, ACL_PRIV_NONE);
2145 ACL_INVALIDATE(mask);
2153 if ( strcasecmp( str, "none" ) == 0 ) {
2154 ACL_LVL_ASSIGN_NONE(mask);
2156 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2157 ACL_LVL_ASSIGN_DISCLOSE(mask);
2159 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2160 ACL_LVL_ASSIGN_AUTH(mask);
2162 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2163 ACL_LVL_ASSIGN_COMPARE(mask);
2165 } else if ( strcasecmp( str, "search" ) == 0 ) {
2166 ACL_LVL_ASSIGN_SEARCH(mask);
2168 } else if ( strcasecmp( str, "read" ) == 0 ) {
2169 ACL_LVL_ASSIGN_READ(mask);
2171 } else if ( strcasecmp( str, "add" ) == 0 ) {
2172 ACL_LVL_ASSIGN_WADD(mask);
2174 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2175 ACL_LVL_ASSIGN_WDEL(mask);
2177 } else if ( strcasecmp( str, "write" ) == 0 ) {
2178 ACL_LVL_ASSIGN_WRITE(mask);
2180 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2181 ACL_LVL_ASSIGN_MANAGE(mask);
2184 ACL_INVALIDATE( mask );
2194 "<access clause> ::= access to <what> "
2195 "[ by <who> [ <access> ] [ <control> ] ]+ \n";
2197 "<what> ::= * | dn[.<dnstyle>=<DN>] [filter=<filter>] [attrs=<attrspec>]\n"
2198 "<attrspec> ::= <attrname> [val[/<matchingRule>][.<attrstyle>]=<value>] | <attrlist>\n"
2199 "<attrlist> ::= <attr> [ , <attrlist> ]\n"
2200 "<attr> ::= <attrname> | @<objectClass> | !<objectClass> | entry | children\n";
2203 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
2204 "\t[ realanonymous | realusers | realself | realdn[.<dnstyle>]=<DN> ]\n"
2205 "\t[dnattr=<attrname>]\n"
2206 "\t[realdnattr=<attrname>]\n"
2207 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
2208 "\t[peername[.<peernamestyle>]=<peer>] [sockname[.<style>]=<name>]\n"
2209 "\t[domain[.<domainstyle>]=<domain>] [sockurl[.<style>]=<url>]\n"
2211 "\t[dynacl/<name>[/<options>][.<dynstyle>][=<pattern>]]\n"
2212 #endif /* SLAP_DYNACL */
2213 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
2214 "<style> ::= exact | regex | base(Object)\n"
2215 "<dnstyle> ::= base(Object) | one(level) | sub(tree) | children | "
2217 "<attrstyle> ::= exact | regex | base(Object) | one(level) | "
2218 "sub(tree) | children\n"
2219 "<peernamestyle> ::= exact | regex | ip | path\n"
2220 "<domainstyle> ::= exact | regex | base(Object) | sub(tree)\n"
2221 "<access> ::= [[real]self]{<level>|<priv>}\n"
2222 "<level> ::= none|disclose|auth|compare|search|read|{write|add|delete}|manage\n"
2223 "<priv> ::= {=|+|-}{0|d|x|c|s|r|{w|a|z}|m}+\n"
2224 "<control> ::= [ stop | continue | break ]\n"
2226 #ifdef SLAPD_ACI_ENABLED
2228 "\t<name>=ACI\t<pattern>=<attrname>\n"
2229 #endif /* SLAPD_ACI_ENABLED */
2230 #endif /* ! SLAP_DYNACL */
2233 Debug( LDAP_DEBUG_ANY, "%s%s%s\n", access, what, who );
2239 * Set pattern to a "normalized" DN from src.
2240 * At present it simply eats the (optional) space after
2241 * a RDN separator (,)
2242 * Eventually will evolve in a more complete normalization
2245 acl_regex_normalized_dn(
2247 struct berval *pattern )
2252 str = ch_strdup( src );
2253 len = strlen( src );
2255 for ( p = str; p && p[0]; p++ ) {
2257 if ( p[0] == '\\' && p[1] ) {
2259 * if escaping a hex pair we should
2260 * increment p twice; however, in that
2261 * case the second hex number does
2267 if ( p[0] == ',' && p[1] == ' ' ) {
2271 * too much space should be an error if we are pedantic
2273 for ( q = &p[2]; q[0] == ' '; q++ ) {
2276 AC_MEMCPY( p+1, q, len-(q-str)+1);
2279 pattern->bv_val = str;
2280 pattern->bv_len = p - str;
2293 if ( (*right = strchr( line, splitchar )) != NULL ) {
2294 *((*right)++) = '\0';
2299 access_append( Access **l, Access *a )
2301 for ( ; *l != NULL; l = &(*l)->a_next ) {
2309 acl_append( AccessControl **l, AccessControl *a, int pos )
2313 for (i=0 ; i != pos && *l != NULL; l = &(*l)->acl_next, i++ ) {
2322 access_free( Access *a )
2324 if ( !BER_BVISNULL( &a->a_dn_pat ) ) {
2325 free( a->a_dn_pat.bv_val );
2327 if ( !BER_BVISNULL( &a->a_realdn_pat ) ) {
2328 free( a->a_realdn_pat.bv_val );
2330 if ( !BER_BVISNULL( &a->a_peername_pat ) ) {
2331 free( a->a_peername_pat.bv_val );
2333 if ( !BER_BVISNULL( &a->a_sockname_pat ) ) {
2334 free( a->a_sockname_pat.bv_val );
2336 if ( !BER_BVISNULL( &a->a_domain_pat ) ) {
2337 free( a->a_domain_pat.bv_val );
2339 if ( !BER_BVISNULL( &a->a_sockurl_pat ) ) {
2340 free( a->a_sockurl_pat.bv_val );
2342 if ( !BER_BVISNULL( &a->a_set_pat ) ) {
2343 free( a->a_set_pat.bv_val );
2345 if ( !BER_BVISNULL( &a->a_group_pat ) ) {
2346 free( a->a_group_pat.bv_val );
2349 if ( a->a_dynacl != NULL ) {
2351 for ( da = a->a_dynacl; da; ) {
2352 slap_dynacl_t *tmp = da;
2356 if ( tmp->da_destroy ) {
2357 tmp->da_destroy( tmp->da_private );
2363 #endif /* SLAP_DYNACL */
2368 acl_free( AccessControl *a )
2373 if ( a->acl_filter ) {
2374 filter_free( a->acl_filter );
2376 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2377 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
2378 regfree( &a->acl_dn_re );
2380 free ( a->acl_dn_pat.bv_val );
2382 if ( a->acl_attrs ) {
2383 for ( an = a->acl_attrs; !BER_BVISNULL( &an->an_name ); an++ ) {
2384 free( an->an_name.bv_val );
2386 free( a->acl_attrs );
2388 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
2389 regfree( &a->acl_attrval_re );
2392 if ( !BER_BVISNULL( &a->acl_attrval ) ) {
2393 ber_memfree( a->acl_attrval.bv_val );
2396 for ( ; a->acl_access; a->acl_access = n ) {
2397 n = a->acl_access->a_next;
2398 access_free( a->acl_access );
2403 /* Because backend_startup uses acl_append to tack on the global_acl to
2404 * the end of each backend's acl, we cannot just take one argument and
2405 * merrily free our way to the end of the list. backend_destroy calls us
2406 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
2407 * point. config_destroy calls us with global_acl in arg1 and NULL in
2408 * arg2, so we then proceed to polish off the global_acl.
2411 acl_destroy( AccessControl *a, AccessControl *end )
2415 for ( ; a && a != end; a = n ) {
2422 access2str( slap_access_t access )
2424 if ( access == ACL_NONE ) {
2427 } else if ( access == ACL_DISCLOSE ) {
2430 } else if ( access == ACL_AUTH ) {
2433 } else if ( access == ACL_COMPARE ) {
2436 } else if ( access == ACL_SEARCH ) {
2439 } else if ( access == ACL_READ ) {
2442 } else if ( access == ACL_WRITE ) {
2445 } else if ( access == ACL_WADD ) {
2448 } else if ( access == ACL_WDEL ) {
2451 } else if ( access == ACL_MANAGE ) {
2460 str2access( const char *str )
2462 if ( strcasecmp( str, "none" ) == 0 ) {
2465 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2466 return ACL_DISCLOSE;
2468 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2471 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2474 } else if ( strcasecmp( str, "search" ) == 0 ) {
2477 } else if ( strcasecmp( str, "read" ) == 0 ) {
2480 } else if ( strcasecmp( str, "write" ) == 0 ) {
2483 } else if ( strcasecmp( str, "add" ) == 0 ) {
2486 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2489 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2493 return( ACL_INVALID_ACCESS );
2496 #define ACLBUF_MAXLEN 8192
2498 static char aclbuf[ACLBUF_MAXLEN];
2501 dnaccess2text( slap_dn_access *bdn, char *ptr, int is_realdn )
2506 ptr = lutil_strcopy( ptr, "real" );
2509 if ( ber_bvccmp( &bdn->a_pat, '*' ) ||
2510 bdn->a_style == ACL_STYLE_ANONYMOUS ||
2511 bdn->a_style == ACL_STYLE_USERS ||
2512 bdn->a_style == ACL_STYLE_SELF )
2515 assert( ! ber_bvccmp( &bdn->a_pat, '*' ) );
2518 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2519 if ( bdn->a_style == ACL_STYLE_SELF && bdn->a_self_level != 0 ) {
2520 int n = sprintf( ptr, ".level{%d}", bdn->a_self_level );
2527 ptr = lutil_strcopy( ptr, "dn." );
2528 if ( bdn->a_style == ACL_STYLE_BASE )
2529 ptr = lutil_strcopy( ptr, style_base );
2531 ptr = lutil_strcopy( ptr, style_strings[bdn->a_style] );
2532 if ( bdn->a_style == ACL_STYLE_LEVEL ) {
2533 int n = sprintf( ptr, "{%d}", bdn->a_level );
2538 if ( bdn->a_expand ) {
2539 ptr = lutil_strcopy( ptr, ",expand" );
2543 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2550 access2text( Access *b, char *ptr )
2552 char maskbuf[ACCESSMASK_MAXLEN];
2554 ptr = lutil_strcopy( ptr, "\tby" );
2556 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
2557 ptr = dnaccess2text( &b->a_dn, ptr, 0 );
2560 ptr = lutil_strcopy( ptr, " dnattr=" );
2561 ptr = lutil_strcopy( ptr, b->a_dn_at->ad_cname.bv_val );
2564 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
2565 ptr = dnaccess2text( &b->a_realdn, ptr, 1 );
2567 if ( b->a_realdn_at ) {
2568 ptr = lutil_strcopy( ptr, " realdnattr=" );
2569 ptr = lutil_strcopy( ptr, b->a_realdn_at->ad_cname.bv_val );
2572 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
2573 ptr = lutil_strcopy( ptr, " group/" );
2574 ptr = lutil_strcopy( ptr, b->a_group_oc ?
2575 b->a_group_oc->soc_cname.bv_val : SLAPD_GROUP_CLASS );
2577 ptr = lutil_strcopy( ptr, b->a_group_at ?
2578 b->a_group_at->ad_cname.bv_val : SLAPD_GROUP_ATTR );
2580 ptr = lutil_strcopy( ptr, style_strings[b->a_group_style] );
2583 ptr = lutil_strcopy( ptr, b->a_group_pat.bv_val );
2587 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
2588 ptr = lutil_strcopy( ptr, " peername" );
2590 ptr = lutil_strcopy( ptr, style_strings[b->a_peername_style] );
2593 ptr = lutil_strcopy( ptr, b->a_peername_pat.bv_val );
2597 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
2598 ptr = lutil_strcopy( ptr, " sockname" );
2600 ptr = lutil_strcopy( ptr, style_strings[b->a_sockname_style] );
2603 ptr = lutil_strcopy( ptr, b->a_sockname_pat.bv_val );
2607 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
2608 ptr = lutil_strcopy( ptr, " domain" );
2610 ptr = lutil_strcopy( ptr, style_strings[b->a_domain_style] );
2611 if ( b->a_domain_expand ) {
2612 ptr = lutil_strcopy( ptr, ",expand" );
2615 ptr = lutil_strcopy( ptr, b->a_domain_pat.bv_val );
2618 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
2619 ptr = lutil_strcopy( ptr, " sockurl" );
2621 ptr = lutil_strcopy( ptr, style_strings[b->a_sockurl_style] );
2624 ptr = lutil_strcopy( ptr, b->a_sockurl_pat.bv_val );
2628 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
2629 ptr = lutil_strcopy( ptr, " set" );
2631 ptr = lutil_strcopy( ptr, style_strings[b->a_set_style] );
2634 ptr = lutil_strcopy( ptr, b->a_set_pat.bv_val );
2639 if ( b->a_dynacl ) {
2642 for ( da = b->a_dynacl; da; da = da->da_next ) {
2643 if ( da->da_unparse ) {
2644 struct berval bv = BER_BVNULL;
2645 (void)( *da->da_unparse )( da->da_private, &bv );
2646 assert( !BER_BVISNULL( &bv ) );
2647 ptr = lutil_strcopy( ptr, bv.bv_val );
2648 ch_free( bv.bv_val );
2652 #endif /* SLAP_DYNACL */
2654 /* Security Strength Factors */
2655 if ( b->a_authz.sai_ssf ) {
2656 ptr += sprintf( ptr, " ssf=%u",
2657 b->a_authz.sai_ssf );
2659 if ( b->a_authz.sai_transport_ssf ) {
2660 ptr += sprintf( ptr, " transport_ssf=%u",
2661 b->a_authz.sai_transport_ssf );
2663 if ( b->a_authz.sai_tls_ssf ) {
2664 ptr += sprintf( ptr, " tls_ssf=%u",
2665 b->a_authz.sai_tls_ssf );
2667 if ( b->a_authz.sai_sasl_ssf ) {
2668 ptr += sprintf( ptr, " sasl_ssf=%u",
2669 b->a_authz.sai_sasl_ssf );
2673 if ( b->a_dn_self ) {
2674 ptr = lutil_strcopy( ptr, "self" );
2675 } else if ( b->a_realdn_self ) {
2676 ptr = lutil_strcopy( ptr, "realself" );
2678 ptr = lutil_strcopy( ptr, accessmask2str( b->a_access_mask, maskbuf, 0 ));
2679 if ( !maskbuf[0] ) ptr--;
2681 if( b->a_type == ACL_BREAK ) {
2682 ptr = lutil_strcopy( ptr, " break" );
2684 } else if( b->a_type == ACL_CONTINUE ) {
2685 ptr = lutil_strcopy( ptr, " continue" );
2687 } else if( b->a_type != ACL_STOP ) {
2688 ptr = lutil_strcopy( ptr, " unknown-control" );
2690 if ( !maskbuf[0] ) ptr = lutil_strcopy( ptr, " stop" );
2698 acl_unparse( AccessControl *a, struct berval *bv )
2704 bv->bv_val = aclbuf;
2709 ptr = lutil_strcopy( ptr, "to" );
2710 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2712 ptr = lutil_strcopy( ptr, " dn." );
2713 if ( a->acl_dn_style == ACL_STYLE_BASE )
2714 ptr = lutil_strcopy( ptr, style_base );
2716 ptr = lutil_strcopy( ptr, style_strings[a->acl_dn_style] );
2719 ptr = lutil_strcopy( ptr, a->acl_dn_pat.bv_val );
2720 ptr = lutil_strcopy( ptr, "\"\n" );
2723 if ( a->acl_filter != NULL ) {
2724 struct berval bv = BER_BVNULL;
2727 filter2bv( a->acl_filter, &bv );
2728 ptr = lutil_strcopy( ptr, " filter=\"" );
2729 ptr = lutil_strcopy( ptr, bv.bv_val );
2732 ch_free( bv.bv_val );
2735 if ( a->acl_attrs != NULL ) {
2740 ptr = lutil_strcopy( ptr, " attrs=" );
2741 for ( an = a->acl_attrs; an && !BER_BVISNULL( &an->an_name ); an++ ) {
2742 if ( ! first ) *ptr++ = ',';
2744 *ptr++ = an->an_oc_exclude ? '!' : '@';
2745 ptr = lutil_strcopy( ptr, an->an_oc->soc_cname.bv_val );
2748 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2755 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
2757 ptr = lutil_strcopy( ptr, " val." );
2758 if ( a->acl_attrval_style == ACL_STYLE_BASE &&
2759 a->acl_attrs[0].an_desc->ad_type->sat_syntax ==
2760 slap_schema.si_syn_distinguishedName )
2761 ptr = lutil_strcopy( ptr, style_base );
2763 ptr = lutil_strcopy( ptr, style_strings[a->acl_attrval_style] );
2766 ptr = lutil_strcopy( ptr, a->acl_attrval.bv_val );
2772 ptr = lutil_strcopy( ptr, " *\n" );
2775 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
2776 ptr = access2text( b, ptr );
2779 bv->bv_len = ptr - bv->bv_val;
2784 print_acl( Backend *be, AccessControl *a )
2788 acl_unparse( a, &bv );
2789 fprintf( stderr, "%s ACL: access %s\n",
2790 be == NULL ? "Global" : "Backend", bv.bv_val );
2792 #endif /* LDAP_DEBUG */