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 int acl_usage(void);
63 static void acl_regex_normalized_dn(const char *src, struct berval *pat);
66 static void print_acl(Backend *be, AccessControl *a);
69 static int check_scope( BackendDB *be, AccessControl *a );
82 slap_dynacl_t *da, *tmp;
85 for ( da = b->a_dynacl; da; da = da->da_next ) {
86 if ( strcasecmp( da->da_name, name ) == 0 ) {
87 Debug( LDAP_DEBUG_ANY,
88 "%s: line %d: dynacl \"%s\" already specified.\n",
89 fname, lineno, name );
94 da = slap_dynacl_get( name );
99 tmp = ch_malloc( sizeof( slap_dynacl_t ) );
102 if ( tmp->da_parse ) {
103 rc = ( *tmp->da_parse )( fname, lineno, opts, sty, right, &tmp->da_private );
110 tmp->da_next = b->a_dynacl;
115 #endif /* SLAP_DYNACL */
118 regtest(const char *fname, int lineno, char *pat) {
122 char buf[ SLAP_TEXT_BUFLEN ];
134 for (size = 0, flag = 0; (size < sizeof(buf)) && *sp; sp++) {
136 if (*sp == '$'|| (*sp >= '0' && *sp <= '9')) {
153 if ( size >= (sizeof(buf) - 1) ) {
154 Debug( LDAP_DEBUG_ANY,
155 "%s: line %d: regular expression \"%s\" too large\n",
156 fname, lineno, pat );
158 exit( EXIT_FAILURE );
161 if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
162 char error[ SLAP_TEXT_BUFLEN ];
164 regerror(e, &re, error, sizeof(error));
166 snprintf( buf, sizeof( buf ),
167 "regular expression \"%s\" bad because of %s",
169 Debug( LDAP_DEBUG_ANY,
171 fname, lineno, buf );
173 exit( EXIT_FAILURE );
181 * Check if the pattern of an ACL, if any, matches the scope
182 * of the backend it is defined within.
184 #define ACL_SCOPE_UNKNOWN (-2)
185 #define ACL_SCOPE_ERR (-1)
186 #define ACL_SCOPE_OK (0)
187 #define ACL_SCOPE_PARTIAL (1)
188 #define ACL_SCOPE_WARN (2)
191 check_scope( BackendDB *be, AccessControl *a )
196 dn = be->be_nsuffix[0];
198 if ( BER_BVISEMPTY( &dn ) ) {
202 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
203 a->acl_dn_style != ACL_STYLE_REGEX )
205 slap_style_t style = a->acl_dn_style;
207 if ( style == ACL_STYLE_REGEX ) {
208 char dnbuf[SLAP_LDAPDN_MAXLEN + 2];
209 char rebuf[SLAP_LDAPDN_MAXLEN + 1];
214 /* add trailing '$' to database suffix to form
215 * a simple trial regex pattern "<suffix>$" */
216 AC_MEMCPY( dnbuf, be->be_nsuffix[0].bv_val,
217 be->be_nsuffix[0].bv_len );
218 dnbuf[be->be_nsuffix[0].bv_len] = '$';
219 dnbuf[be->be_nsuffix[0].bv_len + 1] = '\0';
221 if ( regcomp( &re, dnbuf, REG_EXTENDED|REG_ICASE ) ) {
222 return ACL_SCOPE_WARN;
225 /* remove trailing ')$', if any, from original
227 rebuflen = a->acl_dn_pat.bv_len;
228 AC_MEMCPY( rebuf, a->acl_dn_pat.bv_val, rebuflen + 1 );
229 if ( rebuf[rebuflen - 1] == '$' ) {
230 rebuf[--rebuflen] = '\0';
232 while ( rebuflen > be->be_nsuffix[0].bv_len && rebuf[rebuflen - 1] == ')' ) {
233 rebuf[--rebuflen] = '\0';
235 if ( rebuflen == be->be_nsuffix[0].bv_len ) {
240 /* not a clear indication of scoping error, though */
241 rc = regexec( &re, rebuf, 0, NULL, 0 )
242 ? ACL_SCOPE_WARN : ACL_SCOPE_OK;
249 patlen = a->acl_dn_pat.bv_len;
250 /* If backend suffix is longer than pattern,
251 * it is a potential mismatch (in the sense
252 * that a superior naming context could
254 if ( dn.bv_len > patlen ) {
255 /* base is blatantly wrong */
256 if ( style == ACL_STYLE_BASE ) return ACL_SCOPE_ERR;
258 /* a style of one can be wrong if there is
259 * more than one level between the suffix
261 if ( style == ACL_STYLE_ONE ) {
262 ber_len_t rdnlen = 0;
266 if ( !DN_SEPARATOR( dn.bv_val[dn.bv_len - patlen - 1] )) {
267 return ACL_SCOPE_ERR;
272 rdnlen = dn_rdnlen( NULL, &dn );
273 if ( rdnlen != dn.bv_len - patlen - sep )
274 return ACL_SCOPE_ERR;
277 /* if the trailing part doesn't match,
278 * then it's an error */
279 if ( strcmp( a->acl_dn_pat.bv_val,
280 &dn.bv_val[dn.bv_len - patlen] ) != 0 )
282 return ACL_SCOPE_ERR;
285 return ACL_SCOPE_PARTIAL;
291 case ACL_STYLE_CHILDREN:
292 case ACL_STYLE_SUBTREE:
300 if ( dn.bv_len < patlen &&
301 !DN_SEPARATOR( a->acl_dn_pat.bv_val[patlen - dn.bv_len - 1] ))
303 return ACL_SCOPE_ERR;
306 if ( strcmp( &a->acl_dn_pat.bv_val[patlen - dn.bv_len], dn.bv_val )
309 return ACL_SCOPE_ERR;
315 return ACL_SCOPE_UNKNOWN;
328 char *left, *right, *style;
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 /* FIXME: should be an error */
576 snprintf( buf, sizeof( buf ),
577 "unknown val.<style> \"%s\" for attributeType \"%s\" "
580 a->acl_attrs[0].an_desc->ad_cname.bv_val );
582 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
584 fname, lineno, buf );
586 a->acl_attrval_style = ACL_STYLE_BASE;
589 rc = dnNormalize( 0, NULL, NULL, &bv, &a->acl_attrval, NULL );
590 if ( rc != LDAP_SUCCESS ) {
591 char buf[ SLAP_TEXT_BUFLEN ];
593 snprintf( buf, sizeof( buf ),
594 "unable to normalize DN \"%s\" "
595 "for attributeType \"%s\" (%d).",
597 a->acl_attrs[0].an_desc->ad_cname.bv_val,
599 Debug( LDAP_DEBUG_ANY,
601 fname, lineno, buf );
606 char buf[ SLAP_TEXT_BUFLEN ];
608 /* FIXME: should be an error */
610 snprintf( buf, sizeof( buf ),
611 "unknown val.<style> \"%s\" for attributeType \"%s\".",
612 style, a->acl_attrs[0].an_desc->ad_cname.bv_val );
613 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
615 fname, lineno, buf );
617 a->acl_attrval_style = ACL_STYLE_BASE;
622 /* Check for appropriate matching rule */
623 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
624 ber_dupbv( &a->acl_attrval, &bv );
626 } else if ( BER_BVISNULL( &a->acl_attrval ) ) {
630 if ( a->acl_attrval_mr == NULL ) {
631 a->acl_attrval_mr = a->acl_attrs[ 0 ].an_desc->ad_type->sat_equality;
634 if ( a->acl_attrval_mr == NULL ) {
635 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
636 "attr \"%s\" does not have an EQUALITY matching rule.\n",
637 fname, lineno, a->acl_attrs[ 0 ].an_name.bv_val );
641 rc = asserted_value_validate_normalize(
642 a->acl_attrs[ 0 ].an_desc,
644 SLAP_MR_EQUALITY|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
649 if ( rc != LDAP_SUCCESS ) {
650 char buf[ SLAP_TEXT_BUFLEN ];
652 snprintf( buf, sizeof( buf ), "%s: line %d: "
653 " attr \"%s\" normalization failed (%d: %s)",
654 a->acl_attrs[ 0 ].an_name.bv_val, rc, text );
655 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s.\n",
656 fname, lineno, buf );
662 Debug( LDAP_DEBUG_ANY,
663 "%s: line %d: expecting <what> got \"%s\"\n",
664 fname, lineno, left );
669 if ( !BER_BVISNULL( &a->acl_dn_pat ) &&
670 ber_bvccmp( &a->acl_dn_pat, '*' ) )
672 free( a->acl_dn_pat.bv_val );
673 BER_BVZERO( &a->acl_dn_pat );
674 a->acl_dn_style = ACL_STYLE_REGEX;
677 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
678 a->acl_dn_style != ACL_STYLE_REGEX )
680 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
682 rc = dnNormalize( 0, NULL, NULL, &a->acl_dn_pat, &bv, NULL);
683 if ( rc != LDAP_SUCCESS ) {
684 Debug( LDAP_DEBUG_ANY,
685 "%s: line %d: bad DN \"%s\" in to DN clause\n",
686 fname, lineno, a->acl_dn_pat.bv_val );
689 free( a->acl_dn_pat.bv_val );
693 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
694 REG_EXTENDED | REG_ICASE );
696 char err[ SLAP_TEXT_BUFLEN ],
697 buf[ SLAP_TEXT_BUFLEN ];
699 regerror( e, &a->acl_dn_re, err, sizeof( err ) );
700 snprintf( buf, sizeof( buf ),
701 "regular expression \"%s\" bad because of %s",
703 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
704 fname, lineno, buf );
710 /* by clause - select who has what access to entries */
711 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
713 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
714 "to clause required before by clause in access line\n",
720 * by clause consists of <who> and <access>
723 b = (Access *) ch_calloc( 1, sizeof(Access) );
725 ACL_INVALIDATE( b->a_access_mask );
728 Debug( LDAP_DEBUG_ANY,
729 "%s: line %d: premature EOL: expecting <who>\n",
735 for ( ; i < argc; i++ ) {
736 slap_style_t sty = ACL_STYLE_REGEX;
737 char *style_modifier = NULL;
738 char *style_level = NULL;
741 slap_dn_access *bdn = &b->a_dn;
744 split( argv[i], '=', &left, &right );
745 split( left, '.', &left, &style );
747 split( style, ',', &style, &style_modifier );
749 if ( strncasecmp( style, "level", STRLENOF( "level" ) ) == 0 ) {
750 split( style, '{', &style, &style_level );
751 if ( style_level != NULL ) {
752 char *p = strchr( style_level, '}' );
754 Debug( LDAP_DEBUG_ANY,
755 "%s: line %d: premature eol: "
756 "expecting closing '}' in \"level{n}\"\n",
759 } else if ( p == style_level ) {
760 Debug( LDAP_DEBUG_ANY,
761 "%s: line %d: empty level "
771 if ( style == NULL || *style == '\0' ||
772 strcasecmp( style, "exact" ) == 0 ||
773 strcasecmp( style, "baseObject" ) == 0 ||
774 strcasecmp( style, "base" ) == 0 )
776 sty = ACL_STYLE_BASE;
778 } else if ( strcasecmp( style, "onelevel" ) == 0 ||
779 strcasecmp( style, "one" ) == 0 )
783 } else if ( strcasecmp( style, "subtree" ) == 0 ||
784 strcasecmp( style, "sub" ) == 0 )
786 sty = ACL_STYLE_SUBTREE;
788 } else if ( strcasecmp( style, "children" ) == 0 ) {
789 sty = ACL_STYLE_CHILDREN;
791 } else if ( strcasecmp( style, "level" ) == 0 )
793 if ( lutil_atoi( &level, style_level ) != 0 ) {
794 Debug( LDAP_DEBUG_ANY,
795 "%s: line %d: unable to parse level "
801 sty = ACL_STYLE_LEVEL;
803 } else if ( strcasecmp( style, "regex" ) == 0 ) {
804 sty = ACL_STYLE_REGEX;
806 } else if ( strcasecmp( style, "expand" ) == 0 ) {
807 sty = ACL_STYLE_EXPAND;
809 } else if ( strcasecmp( style, "ip" ) == 0 ) {
812 } else if ( strcasecmp( style, "path" ) == 0 ) {
813 sty = ACL_STYLE_PATH;
814 #ifndef LDAP_PF_LOCAL
815 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
817 "\"path\" style modifier is useless without local.\n",
820 #endif /* LDAP_PF_LOCAL */
823 Debug( LDAP_DEBUG_ANY,
824 "%s: line %d: unknown style \"%s\" in by clause\n",
825 fname, lineno, style );
829 if ( style_modifier &&
830 strcasecmp( style_modifier, "expand" ) == 0 )
833 case ACL_STYLE_REGEX:
834 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
835 "\"regex\" style implies \"expand\" modifier.\n",
840 case ACL_STYLE_EXPAND:
844 /* we'll see later if it's pertinent */
850 /* expand in <who> needs regex in <what> */
851 if ( ( sty == ACL_STYLE_EXPAND || expand )
852 && a->acl_dn_style != ACL_STYLE_REGEX )
854 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL, "%s: line %d: \"expand\" style "
855 "or modifier used in conjunction with a non-regex <what> clause.\n",
860 if ( strncasecmp( left, "real", STRLENOF( "real" ) ) == 0 ) {
863 left += STRLENOF( "real" );
866 if ( strcasecmp( left, "*" ) == 0 ) {
871 ber_str2bv( "*", STRLENOF( "*" ), 1, &bv );
872 sty = ACL_STYLE_REGEX;
874 } else if ( strcasecmp( left, "anonymous" ) == 0 ) {
875 ber_str2bv("anonymous", STRLENOF( "anonymous" ), 1, &bv);
876 sty = ACL_STYLE_ANONYMOUS;
878 } else if ( strcasecmp( left, "users" ) == 0 ) {
879 ber_str2bv("users", STRLENOF( "users" ), 1, &bv);
880 sty = ACL_STYLE_USERS;
882 } else if ( strcasecmp( left, "self" ) == 0 ) {
883 ber_str2bv("self", STRLENOF( "self" ), 1, &bv);
884 sty = ACL_STYLE_SELF;
886 } else if ( strcasecmp( left, "dn" ) == 0 ) {
887 if ( sty == ACL_STYLE_REGEX ) {
888 bdn->a_style = ACL_STYLE_REGEX;
889 if ( right == NULL ) {
894 bdn->a_style = ACL_STYLE_USERS;
896 } else if (*right == '\0' ) {
898 ber_str2bv("anonymous",
899 STRLENOF( "anonymous" ),
901 bdn->a_style = ACL_STYLE_ANONYMOUS;
903 } else if ( strcmp( right, "*" ) == 0 ) {
905 /* any or users? users for now */
909 bdn->a_style = ACL_STYLE_USERS;
911 } else if ( strcmp( right, ".+" ) == 0
912 || strcmp( right, "^.+" ) == 0
913 || strcmp( right, ".+$" ) == 0
914 || strcmp( right, "^.+$" ) == 0
915 || strcmp( right, ".+$$" ) == 0
916 || strcmp( right, "^.+$$" ) == 0 )
921 bdn->a_style = ACL_STYLE_USERS;
923 } else if ( strcmp( right, ".*" ) == 0
924 || strcmp( right, "^.*" ) == 0
925 || strcmp( right, ".*$" ) == 0
926 || strcmp( right, "^.*$" ) == 0
927 || strcmp( right, ".*$$" ) == 0
928 || strcmp( right, "^.*$$" ) == 0 )
935 acl_regex_normalized_dn( right, &bv );
936 if ( !ber_bvccmp( &bv, '*' ) ) {
937 regtest( fname, lineno, bv.bv_val );
941 } else if ( right == NULL || *right == '\0' ) {
942 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
943 "missing \"=\" in (or value after) \"%s\" "
945 fname, lineno, left );
949 ber_str2bv( right, 0, 1, &bv );
956 if ( !BER_BVISNULL( &bv ) ) {
957 if ( !BER_BVISEMPTY( &bdn->a_pat ) ) {
958 Debug( LDAP_DEBUG_ANY,
959 "%s: line %d: dn pattern already specified.\n",
964 if ( sty != ACL_STYLE_REGEX &&
965 sty != ACL_STYLE_ANONYMOUS &&
966 sty != ACL_STYLE_USERS &&
967 sty != ACL_STYLE_SELF &&
970 rc = dnNormalize(0, NULL, NULL,
971 &bv, &bdn->a_pat, NULL);
972 if ( rc != LDAP_SUCCESS ) {
973 Debug( LDAP_DEBUG_ANY,
974 "%s: line %d: bad DN \"%s\" in by DN clause\n",
975 fname, lineno, bv.bv_val );
979 if ( sty == ACL_STYLE_BASE
981 && !BER_BVISNULL( &be->be_rootndn )
982 && dn_match( &bdn->a_pat, &be->be_rootndn ) )
984 Debug( LDAP_DEBUG_ANY,
985 "%s: line %d: rootdn is always granted "
986 "unlimited privileges.\n",
998 for ( exp = strchr( bdn->a_pat.bv_val, '$' );
999 exp && (ber_len_t)(exp - bdn->a_pat.bv_val)
1000 < bdn->a_pat.bv_len;
1001 exp = strchr( exp, '$' ) )
1003 if ( isdigit( exp[ 1 ] ) ) {
1010 bdn->a_expand = expand;
1013 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1014 "\"expand\" used with no expansions in \"pattern\".\n",
1019 if ( sty == ACL_STYLE_SELF ) {
1020 bdn->a_self_level = level;
1024 Debug( LDAP_DEBUG_ANY,
1025 "%s: line %d: bad negative level \"%d\" "
1026 "in by DN clause\n",
1027 fname, lineno, level );
1029 } else if ( level == 1 ) {
1030 Debug( LDAP_DEBUG_ANY,
1031 "%s: line %d: \"onelevel\" should be used "
1032 "instead of \"level{1}\" in by DN clause\n",
1034 } else if ( level == 0 && sty == ACL_STYLE_LEVEL ) {
1035 Debug( LDAP_DEBUG_ANY,
1036 "%s: line %d: \"base\" should be used "
1037 "instead of \"level{0}\" in by DN clause\n",
1041 bdn->a_level = level;
1046 if ( strcasecmp( left, "dnattr" ) == 0 ) {
1047 if ( right == NULL || right[0] == '\0' ) {
1048 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1049 "missing \"=\" in (or value after) \"%s\" "
1051 fname, lineno, left );
1055 if( bdn->a_at != NULL ) {
1056 Debug( LDAP_DEBUG_ANY,
1057 "%s: line %d: dnattr already specified.\n",
1062 rc = slap_str2ad( right, &bdn->a_at, &text );
1064 if( rc != LDAP_SUCCESS ) {
1065 char buf[ SLAP_TEXT_BUFLEN ];
1067 snprintf( buf, sizeof( buf ),
1068 "dnattr \"%s\": %s",
1070 Debug( LDAP_DEBUG_ANY,
1071 "%s: line %d: %s\n",
1072 fname, lineno, buf );
1077 if( !is_at_syntax( bdn->a_at->ad_type,
1078 SLAPD_DN_SYNTAX ) &&
1079 !is_at_syntax( bdn->a_at->ad_type,
1080 SLAPD_NAMEUID_SYNTAX ))
1082 char buf[ SLAP_TEXT_BUFLEN ];
1084 snprintf( buf, sizeof( buf ),
1086 "inappropriate syntax: %s\n",
1088 bdn->a_at->ad_type->sat_syntax_oid );
1089 Debug( LDAP_DEBUG_ANY,
1090 "%s: line %d: %s\n",
1091 fname, lineno, buf );
1095 if( bdn->a_at->ad_type->sat_equality == NULL ) {
1096 Debug( LDAP_DEBUG_ANY,
1097 "%s: line %d: dnattr \"%s\": "
1098 "inappropriate matching (no EQUALITY)\n",
1099 fname, lineno, right );
1106 if ( strncasecmp( left, "group", STRLENOF( "group" ) ) == 0 ) {
1111 case ACL_STYLE_REGEX:
1112 /* legacy, tolerated */
1113 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
1115 "deprecated group style \"regex\"; "
1116 "use \"expand\" instead.\n",
1118 sty = ACL_STYLE_EXPAND;
1121 case ACL_STYLE_BASE:
1122 /* legal, traditional */
1123 case ACL_STYLE_EXPAND:
1124 /* legal, substring expansion; supersedes regex */
1129 Debug( LDAP_DEBUG_ANY,
1131 "inappropriate style \"%s\" in by clause.\n",
1132 fname, lineno, style );
1136 if ( right == NULL || right[0] == '\0' ) {
1137 Debug( LDAP_DEBUG_ANY,
1139 "missing \"=\" in (or value after) \"%s\" "
1141 fname, lineno, left );
1145 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1146 Debug( LDAP_DEBUG_ANY,
1147 "%s: line %d: group pattern already specified.\n",
1152 /* format of string is
1153 "group/objectClassValue/groupAttrName" */
1154 if ( ( value = strchr(left, '/') ) != NULL ) {
1156 if ( *value && ( name = strchr( value, '/' ) ) != NULL ) {
1161 b->a_group_style = sty;
1162 if ( sty == ACL_STYLE_EXPAND ) {
1163 acl_regex_normalized_dn( right, &bv );
1164 if ( !ber_bvccmp( &bv, '*' ) ) {
1165 regtest( fname, lineno, bv.bv_val );
1167 b->a_group_pat = bv;
1170 ber_str2bv( right, 0, 0, &bv );
1171 rc = dnNormalize( 0, NULL, NULL, &bv,
1172 &b->a_group_pat, NULL );
1173 if ( rc != LDAP_SUCCESS ) {
1174 Debug( LDAP_DEBUG_ANY,
1175 "%s: line %d: bad DN \"%s\".\n",
1176 fname, lineno, right );
1181 if ( value && *value ) {
1182 b->a_group_oc = oc_find( value );
1185 if ( b->a_group_oc == NULL ) {
1186 Debug( LDAP_DEBUG_ANY,
1187 "%s: line %d: group objectclass "
1188 "\"%s\" unknown.\n",
1189 fname, lineno, value );
1194 b->a_group_oc = oc_find( SLAPD_GROUP_CLASS );
1196 if( b->a_group_oc == NULL ) {
1197 Debug( LDAP_DEBUG_ANY,
1198 "%s: line %d: group default objectclass "
1199 "\"%s\" unknown.\n",
1200 fname, lineno, SLAPD_GROUP_CLASS );
1205 if ( is_object_subclass( slap_schema.si_oc_referral,
1208 Debug( LDAP_DEBUG_ANY,
1209 "%s: line %d: group objectclass \"%s\" "
1210 "is subclass of referral.\n",
1211 fname, lineno, value );
1215 if ( is_object_subclass( slap_schema.si_oc_alias,
1218 Debug( LDAP_DEBUG_ANY,
1219 "%s: line %d: group objectclass \"%s\" "
1220 "is subclass of alias.\n",
1221 fname, lineno, value );
1225 if ( name && *name ) {
1226 rc = slap_str2ad( name, &b->a_group_at, &text );
1228 if( rc != LDAP_SUCCESS ) {
1229 char buf[ SLAP_TEXT_BUFLEN ];
1231 snprintf( buf, sizeof( buf ),
1232 "group \"%s\": %s.",
1234 Debug( LDAP_DEBUG_ANY,
1235 "%s: line %d: %s\n",
1236 fname, lineno, buf );
1242 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
1244 if ( rc != LDAP_SUCCESS ) {
1245 char buf[ SLAP_TEXT_BUFLEN ];
1247 snprintf( buf, sizeof( buf ),
1248 "group \"%s\": %s.",
1249 SLAPD_GROUP_ATTR, text );
1250 Debug( LDAP_DEBUG_ANY,
1251 "%s: line %d: %s\n",
1252 fname, lineno, buf );
1257 if ( !is_at_syntax( b->a_group_at->ad_type,
1258 SLAPD_DN_SYNTAX ) &&
1259 !is_at_syntax( b->a_group_at->ad_type,
1260 SLAPD_NAMEUID_SYNTAX ) &&
1261 !is_at_subtype( b->a_group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ) )
1263 char buf[ SLAP_TEXT_BUFLEN ];
1265 snprintf( buf, sizeof( buf ),
1266 "group \"%s\": inappropriate syntax: %s.",
1268 b->a_group_at->ad_type->sat_syntax_oid );
1269 Debug( LDAP_DEBUG_ANY,
1270 "%s: line %d: %s\n",
1271 fname, lineno, buf );
1278 struct berval vals[2];
1280 ber_str2bv( b->a_group_oc->soc_oid, 0, 0, &vals[0] );
1281 BER_BVZERO( &vals[1] );
1283 rc = oc_check_allowed( b->a_group_at->ad_type,
1287 char buf[ SLAP_TEXT_BUFLEN ];
1289 snprintf( buf, sizeof( buf ),
1290 "group: \"%s\" not allowed by \"%s\".",
1291 b->a_group_at->ad_cname.bv_val,
1292 b->a_group_oc->soc_oid );
1293 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
1294 fname, lineno, buf );
1301 if ( strcasecmp( left, "peername" ) == 0 ) {
1303 case ACL_STYLE_REGEX:
1304 case ACL_STYLE_BASE:
1305 /* legal, traditional */
1306 case ACL_STYLE_EXPAND:
1307 /* cheap replacement to regex for simple expansion */
1309 case ACL_STYLE_PATH:
1310 /* legal, peername specific */
1314 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1315 "inappropriate style \"%s\" in by clause.\n",
1316 fname, lineno, style );
1320 if ( right == NULL || right[0] == '\0' ) {
1321 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1322 "missing \"=\" in (or value after) \"%s\" "
1324 fname, lineno, left );
1328 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1329 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1330 "peername pattern already specified.\n",
1335 b->a_peername_style = sty;
1336 if ( sty == ACL_STYLE_REGEX ) {
1337 acl_regex_normalized_dn( right, &bv );
1338 if ( !ber_bvccmp( &bv, '*' ) ) {
1339 regtest( fname, lineno, bv.bv_val );
1341 b->a_peername_pat = bv;
1344 ber_str2bv( right, 0, 1, &b->a_peername_pat );
1346 if ( sty == ACL_STYLE_IP ) {
1351 split( right, '{', &addr, &port );
1352 split( addr, '%', &addr, &mask );
1354 b->a_peername_addr = inet_addr( addr );
1355 if ( b->a_peername_addr == (unsigned long)(-1) ) {
1356 /* illegal address */
1357 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1358 "illegal peername address \"%s\".\n",
1359 fname, lineno, addr );
1363 b->a_peername_mask = (unsigned long)(-1);
1364 if ( mask != NULL ) {
1365 b->a_peername_mask = inet_addr( mask );
1366 if ( b->a_peername_mask ==
1367 (unsigned long)(-1) )
1370 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1371 "illegal peername address mask "
1373 fname, lineno, mask );
1378 b->a_peername_port = -1;
1382 b->a_peername_port = strtol( port, &end, 10 );
1383 if ( end == port || end[0] != '}' ) {
1385 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1386 "illegal peername port specification "
1388 fname, lineno, port );
1397 if ( strcasecmp( left, "sockname" ) == 0 ) {
1399 case ACL_STYLE_REGEX:
1400 case ACL_STYLE_BASE:
1401 /* legal, traditional */
1402 case ACL_STYLE_EXPAND:
1403 /* cheap replacement to regex for simple expansion */
1408 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1409 "inappropriate style \"%s\" in by clause\n",
1410 fname, lineno, style );
1414 if ( right == NULL || right[0] == '\0' ) {
1415 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1416 "missing \"=\" in (or value after) \"%s\" "
1418 fname, lineno, left );
1422 if ( !BER_BVISNULL( &b->a_sockname_pat ) ) {
1423 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1424 "sockname pattern already specified.\n",
1429 b->a_sockname_style = sty;
1430 if ( sty == ACL_STYLE_REGEX ) {
1431 acl_regex_normalized_dn( right, &bv );
1432 if ( !ber_bvccmp( &bv, '*' ) ) {
1433 regtest( fname, lineno, bv.bv_val );
1435 b->a_sockname_pat = bv;
1438 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
1443 if ( strcasecmp( left, "domain" ) == 0 ) {
1445 case ACL_STYLE_REGEX:
1446 case ACL_STYLE_BASE:
1447 case ACL_STYLE_SUBTREE:
1448 /* legal, traditional */
1451 case ACL_STYLE_EXPAND:
1452 /* tolerated: means exact,expand */
1454 Debug( LDAP_DEBUG_ANY,
1456 "\"expand\" modifier "
1457 "with \"expand\" style.\n",
1460 sty = ACL_STYLE_BASE;
1466 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1467 "inappropriate style \"%s\" in by clause.\n",
1468 fname, lineno, style );
1472 if ( right == NULL || right[0] == '\0' ) {
1473 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1474 "missing \"=\" in (or value after) \"%s\" "
1476 fname, lineno, left );
1480 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1481 Debug( LDAP_DEBUG_ANY,
1482 "%s: line %d: domain pattern already specified.\n",
1487 b->a_domain_style = sty;
1488 b->a_domain_expand = expand;
1489 if ( sty == ACL_STYLE_REGEX ) {
1490 acl_regex_normalized_dn( right, &bv );
1491 if ( !ber_bvccmp( &bv, '*' ) ) {
1492 regtest( fname, lineno, bv.bv_val );
1494 b->a_domain_pat = bv;
1497 ber_str2bv( right, 0, 1, &b->a_domain_pat );
1502 if ( strcasecmp( left, "sockurl" ) == 0 ) {
1504 case ACL_STYLE_REGEX:
1505 case ACL_STYLE_BASE:
1506 /* legal, traditional */
1507 case ACL_STYLE_EXPAND:
1508 /* cheap replacement to regex for simple expansion */
1513 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1514 "inappropriate style \"%s\" in by clause.\n",
1515 fname, lineno, style );
1519 if ( right == NULL || right[0] == '\0' ) {
1520 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1521 "missing \"=\" in (or value after) \"%s\" "
1523 fname, lineno, left );
1527 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1528 Debug( LDAP_DEBUG_ANY,
1529 "%s: line %d: sockurl pattern already specified.\n",
1534 b->a_sockurl_style = sty;
1535 if ( sty == ACL_STYLE_REGEX ) {
1536 acl_regex_normalized_dn( right, &bv );
1537 if ( !ber_bvccmp( &bv, '*' ) ) {
1538 regtest( fname, lineno, bv.bv_val );
1540 b->a_sockurl_pat = bv;
1543 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
1548 if ( strcasecmp( left, "set" ) == 0 ) {
1551 case ACL_STYLE_REGEX:
1552 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
1554 "deprecated set style "
1555 "\"regex\" in <by> clause; "
1556 "use \"expand\" instead.\n",
1558 sty = ACL_STYLE_EXPAND;
1561 case ACL_STYLE_BASE:
1562 case ACL_STYLE_EXPAND:
1566 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1567 "inappropriate style \"%s\" in by clause.\n",
1568 fname, lineno, style );
1572 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1573 Debug( LDAP_DEBUG_ANY,
1574 "%s: line %d: set attribute already specified.\n",
1579 if ( right == NULL || *right == '\0' ) {
1580 Debug( LDAP_DEBUG_ANY,
1581 "%s: line %d: no set is defined.\n",
1586 b->a_set_style = sty;
1587 ber_str2bv( right, 0, 1, &b->a_set_pat );
1597 #if 1 /* tolerate legacy "aci" <who> */
1598 if ( strcasecmp( left, "aci" ) == 0 ) {
1599 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1600 "undocumented deprecated \"aci\" directive "
1601 "is superseded by \"dynacl/aci\".\n",
1606 #endif /* tolerate legacy "aci" <who> */
1607 if ( strncasecmp( left, "dynacl/", STRLENOF( "dynacl/" ) ) == 0 ) {
1608 name = &left[ STRLENOF( "dynacl/" ) ];
1609 opts = strchr( name, '/' );
1617 if ( slap_dynacl_config( fname, lineno, b, name, opts, sty, right ) ) {
1618 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1619 "unable to configure dynacl \"%s\".\n",
1620 fname, lineno, name );
1627 #endif /* SLAP_DYNACL */
1629 if ( strcasecmp( left, "ssf" ) == 0 ) {
1630 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1631 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1632 "inappropriate style \"%s\" in by clause.\n",
1633 fname, lineno, style );
1637 if ( b->a_authz.sai_ssf ) {
1638 Debug( LDAP_DEBUG_ANY,
1639 "%s: line %d: ssf attribute already specified.\n",
1644 if ( right == NULL || *right == '\0' ) {
1645 Debug( LDAP_DEBUG_ANY,
1646 "%s: line %d: no ssf is defined.\n",
1651 if ( lutil_atou( &b->a_authz.sai_ssf, right ) != 0 ) {
1652 Debug( LDAP_DEBUG_ANY,
1653 "%s: line %d: unable to parse ssf value (%s).\n",
1654 fname, lineno, right );
1658 if ( !b->a_authz.sai_ssf ) {
1659 Debug( LDAP_DEBUG_ANY,
1660 "%s: line %d: invalid ssf value (%s).\n",
1661 fname, lineno, right );
1667 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
1668 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1669 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1670 "inappropriate style \"%s\" in by clause.\n",
1671 fname, lineno, style );
1675 if ( b->a_authz.sai_transport_ssf ) {
1676 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1677 "transport_ssf attribute already specified.\n",
1682 if ( right == NULL || *right == '\0' ) {
1683 Debug( LDAP_DEBUG_ANY,
1684 "%s: line %d: no transport_ssf is defined.\n",
1689 if ( lutil_atou( &b->a_authz.sai_transport_ssf, right ) != 0 ) {
1690 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1691 "unable to parse transport_ssf value (%s).\n",
1692 fname, lineno, right );
1696 if ( !b->a_authz.sai_transport_ssf ) {
1697 Debug( LDAP_DEBUG_ANY,
1698 "%s: line %d: invalid transport_ssf value (%s).\n",
1699 fname, lineno, right );
1705 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
1706 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1707 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1708 "inappropriate style \"%s\" in by clause.\n",
1709 fname, lineno, style );
1713 if ( b->a_authz.sai_tls_ssf ) {
1714 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1715 "tls_ssf attribute already specified.\n",
1720 if ( right == NULL || *right == '\0' ) {
1721 Debug( LDAP_DEBUG_ANY,
1722 "%s: line %d: no tls_ssf is defined\n",
1727 if ( lutil_atou( &b->a_authz.sai_tls_ssf, right ) != 0 ) {
1728 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1729 "unable to parse tls_ssf value (%s).\n",
1730 fname, lineno, right );
1734 if ( !b->a_authz.sai_tls_ssf ) {
1735 Debug( LDAP_DEBUG_ANY,
1736 "%s: line %d: invalid tls_ssf value (%s).\n",
1737 fname, lineno, right );
1743 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1744 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1745 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1746 "inappropriate style \"%s\" in by clause.\n",
1747 fname, lineno, style );
1751 if ( b->a_authz.sai_sasl_ssf ) {
1752 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1753 "sasl_ssf attribute already specified.\n",
1758 if ( right == NULL || *right == '\0' ) {
1759 Debug( LDAP_DEBUG_ANY,
1760 "%s: line %d: no sasl_ssf is defined.\n",
1765 if ( lutil_atou( &b->a_authz.sai_sasl_ssf, right ) != 0 ) {
1766 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1767 "unable to parse sasl_ssf value (%s).\n",
1768 fname, lineno, right );
1772 if ( !b->a_authz.sai_sasl_ssf ) {
1773 Debug( LDAP_DEBUG_ANY,
1774 "%s: line %d: invalid sasl_ssf value (%s).\n",
1775 fname, lineno, right );
1781 if ( right != NULL ) {
1788 if ( i == argc || ( strcasecmp( left, "stop" ) == 0 ) ) {
1789 /* out of arguments or plain stop */
1791 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1792 b->a_type = ACL_STOP;
1794 access_append( &a->acl_access, b );
1798 if ( strcasecmp( left, "continue" ) == 0 ) {
1799 /* plain continue */
1801 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1802 b->a_type = ACL_CONTINUE;
1804 access_append( &a->acl_access, b );
1808 if ( strcasecmp( left, "break" ) == 0 ) {
1809 /* plain continue */
1811 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1812 b->a_type = ACL_BREAK;
1814 access_append( &a->acl_access, b );
1818 if ( strcasecmp( left, "by" ) == 0 ) {
1819 /* we've gone too far */
1821 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1822 b->a_type = ACL_STOP;
1824 access_append( &a->acl_access, b );
1829 if ( strncasecmp( left, "self", STRLENOF( "self" ) ) == 0 ) {
1831 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "self" ) ] ) );
1833 } else if ( strncasecmp( left, "realself", STRLENOF( "realself" ) ) == 0 ) {
1834 b->a_realdn_self = 1;
1835 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "realself" ) ] ) );
1838 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1841 if ( ACL_IS_INVALID( b->a_access_mask ) ) {
1842 Debug( LDAP_DEBUG_ANY,
1843 "%s: line %d: expecting <access> got \"%s\".\n",
1844 fname, lineno, left );
1848 b->a_type = ACL_STOP;
1850 if ( ++i == argc ) {
1851 /* out of arguments or plain stop */
1852 access_append( &a->acl_access, b );
1856 if ( strcasecmp( argv[i], "continue" ) == 0 ) {
1857 /* plain continue */
1858 b->a_type = ACL_CONTINUE;
1860 } else if ( strcasecmp( argv[i], "break" ) == 0 ) {
1861 /* plain continue */
1862 b->a_type = ACL_BREAK;
1864 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1869 access_append( &a->acl_access, b );
1872 Debug( LDAP_DEBUG_ANY,
1873 "%s: line %d: expecting \"to\" "
1874 "or \"by\" got \"%s\"\n",
1875 fname, lineno, argv[i] );
1880 /* if we have no real access clause, complain and do nothing */
1882 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1883 "warning: no access clause(s) specified in access line.\n",
1889 if ( slap_debug & LDAP_DEBUG_ACL ) {
1894 if ( a->acl_access == NULL ) {
1895 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1896 "warning: no by clause(s) specified in access line.\n",
1902 if ( be->be_nsuffix == NULL ) {
1903 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1904 "scope checking needs suffix before ACLs.\n",
1906 /* go ahead, since checking is not authoritative */
1907 } else if ( !BER_BVISNULL( &be->be_nsuffix[ 1 ] ) ) {
1908 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1909 "scope checking only applies to single-valued "
1910 "suffix databases\n",
1912 /* go ahead, since checking is not authoritative */
1914 switch ( check_scope( be, a ) ) {
1915 case ACL_SCOPE_UNKNOWN:
1916 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1917 "cannot assess the validity of the ACL scope within "
1918 "backend naming context\n",
1922 case ACL_SCOPE_WARN:
1923 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1924 "ACL could be out of scope within backend naming context\n",
1928 case ACL_SCOPE_PARTIAL:
1929 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1930 "ACL appears to be partially out of scope within "
1931 "backend naming context\n",
1936 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1937 "ACL appears to be out of scope within "
1938 "backend naming context\n",
1946 acl_append( &be->be_acl, a, pos );
1949 acl_append( &frontendDB->be_acl, a, pos );
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 */