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-2005 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 acl_usage(void) LDAP_GCCATTR((noreturn));
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 );
160 if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
161 char error[ SLAP_TEXT_BUFLEN ];
163 regerror(e, &re, error, sizeof(error));
165 snprintf( buf, sizeof( buf ),
166 "regular expression \"%s\" bad because of %s",
168 Debug( LDAP_DEBUG_ANY,
170 fname, lineno, buf );
179 * Check if the pattern of an ACL, if any, matches the scope
180 * of the backend it is defined within.
182 #define ACL_SCOPE_UNKNOWN (-2)
183 #define ACL_SCOPE_ERR (-1)
184 #define ACL_SCOPE_OK (0)
185 #define ACL_SCOPE_PARTIAL (1)
186 #define ACL_SCOPE_WARN (2)
189 check_scope( BackendDB *be, AccessControl *a )
194 dn = be->be_nsuffix[0];
196 if ( BER_BVISEMPTY( &dn ) ) {
200 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
201 a->acl_dn_style != ACL_STYLE_REGEX )
203 slap_style_t style = a->acl_dn_style;
205 if ( style == ACL_STYLE_REGEX ) {
206 char dnbuf[SLAP_LDAPDN_MAXLEN + 2];
207 char rebuf[SLAP_LDAPDN_MAXLEN + 1];
212 /* add trailing '$' to database suffix to form
213 * a simple trial regex pattern "<suffix>$" */
214 AC_MEMCPY( dnbuf, be->be_nsuffix[0].bv_val,
215 be->be_nsuffix[0].bv_len );
216 dnbuf[be->be_nsuffix[0].bv_len] = '$';
217 dnbuf[be->be_nsuffix[0].bv_len + 1] = '\0';
219 if ( regcomp( &re, dnbuf, REG_EXTENDED|REG_ICASE ) ) {
220 return ACL_SCOPE_WARN;
223 /* remove trailing ')$', if any, from original
225 rebuflen = a->acl_dn_pat.bv_len;
226 AC_MEMCPY( rebuf, a->acl_dn_pat.bv_val, rebuflen + 1 );
227 if ( rebuf[rebuflen - 1] == '$' ) {
228 rebuf[--rebuflen] = '\0';
230 while ( rebuflen > be->be_nsuffix[0].bv_len && rebuf[rebuflen - 1] == ')' ) {
231 rebuf[--rebuflen] = '\0';
233 if ( rebuflen == be->be_nsuffix[0].bv_len ) {
238 /* not a clear indication of scoping error, though */
239 rc = regexec( &re, rebuf, 0, NULL, 0 )
240 ? ACL_SCOPE_WARN : ACL_SCOPE_OK;
247 patlen = a->acl_dn_pat.bv_len;
248 /* If backend suffix is longer than pattern,
249 * it is a potential mismatch (in the sense
250 * that a superior naming context could
252 if ( dn.bv_len > patlen ) {
253 /* base is blatantly wrong */
254 if ( style == ACL_STYLE_BASE ) return ACL_SCOPE_ERR;
256 /* a style of one can be wrong if there is
257 * more than one level between the suffix
259 if ( style == ACL_STYLE_ONE ) {
260 ber_len_t rdnlen = 0;
264 if ( !DN_SEPARATOR( dn.bv_val[dn.bv_len - patlen - 1] )) {
265 return ACL_SCOPE_ERR;
270 rdnlen = dn_rdnlen( NULL, &dn );
271 if ( rdnlen != dn.bv_len - patlen - sep )
272 return ACL_SCOPE_ERR;
275 /* if the trailing part doesn't match,
276 * then it's an error */
277 if ( strcmp( a->acl_dn_pat.bv_val,
278 &dn.bv_val[dn.bv_len - patlen] ) != 0 )
280 return ACL_SCOPE_ERR;
283 return ACL_SCOPE_PARTIAL;
289 case ACL_STYLE_CHILDREN:
290 case ACL_STYLE_SUBTREE:
298 if ( dn.bv_len < patlen &&
299 !DN_SEPARATOR( a->acl_dn_pat.bv_val[patlen - dn.bv_len - 1] ))
301 return ACL_SCOPE_ERR;
304 if ( strcmp( &a->acl_dn_pat.bv_val[patlen - dn.bv_len], dn.bv_val )
307 return ACL_SCOPE_ERR;
313 return ACL_SCOPE_UNKNOWN;
326 char *left, *right, *style, *next;
334 for ( i = 1; i < argc; i++ ) {
335 /* to clause - select which entries are protected */
336 if ( strcasecmp( argv[i], "to" ) == 0 ) {
338 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
339 "only one to clause allowed in access line\n",
343 a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
344 for ( ++i; i < argc; i++ ) {
345 if ( strcasecmp( argv[i], "by" ) == 0 ) {
350 if ( strcasecmp( argv[i], "*" ) == 0 ) {
351 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
352 a->acl_dn_style != ACL_STYLE_REGEX )
354 Debug( LDAP_DEBUG_ANY,
355 "%s: line %d: dn pattern"
356 " already specified in to clause.\n",
361 ber_str2bv( "*", STRLENOF( "*" ), 1, &a->acl_dn_pat );
365 split( argv[i], '=', &left, &right );
366 split( left, '.', &left, &style );
368 if ( right == NULL ) {
369 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
370 "missing \"=\" in \"%s\" in to clause\n",
371 fname, lineno, left );
375 if ( strcasecmp( left, "dn" ) == 0 ) {
376 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
377 a->acl_dn_style != ACL_STYLE_REGEX )
379 Debug( LDAP_DEBUG_ANY,
380 "%s: line %d: dn pattern"
381 " already specified in to clause.\n",
386 if ( style == NULL || *style == '\0' ||
387 strcasecmp( style, "baseObject" ) == 0 ||
388 strcasecmp( style, "base" ) == 0 ||
389 strcasecmp( style, "exact" ) == 0 )
391 a->acl_dn_style = ACL_STYLE_BASE;
392 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
394 } else if ( strcasecmp( style, "oneLevel" ) == 0 ||
395 strcasecmp( style, "one" ) == 0 )
397 a->acl_dn_style = ACL_STYLE_ONE;
398 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
400 } else if ( strcasecmp( style, "subtree" ) == 0 ||
401 strcasecmp( style, "sub" ) == 0 )
403 if( *right == '\0' ) {
404 ber_str2bv( "*", STRLENOF( "*" ), 1, &a->acl_dn_pat );
407 a->acl_dn_style = ACL_STYLE_SUBTREE;
408 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
411 } else if ( strcasecmp( style, "children" ) == 0 ) {
412 a->acl_dn_style = ACL_STYLE_CHILDREN;
413 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
415 } else if ( strcasecmp( style, "regex" ) == 0 ) {
416 a->acl_dn_style = ACL_STYLE_REGEX;
418 if ( *right == '\0' ) {
419 /* empty regex should match empty DN */
420 a->acl_dn_style = ACL_STYLE_BASE;
421 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
423 } else if ( strcmp(right, "*") == 0
424 || strcmp(right, ".*") == 0
425 || strcmp(right, ".*$") == 0
426 || strcmp(right, "^.*") == 0
427 || strcmp(right, "^.*$") == 0
428 || strcmp(right, ".*$$") == 0
429 || strcmp(right, "^.*$$") == 0 )
431 ber_str2bv( "*", STRLENOF("*"), 1, &a->acl_dn_pat );
434 acl_regex_normalized_dn( right, &a->acl_dn_pat );
438 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
439 "unknown dn style \"%s\" in to clause\n",
440 fname, lineno, style );
447 if ( strcasecmp( left, "filter" ) == 0 ) {
448 if ( (a->acl_filter = str2filter( right )) == NULL ) {
449 Debug( LDAP_DEBUG_ANY,
450 "%s: line %d: bad filter \"%s\" in to clause\n",
451 fname, lineno, right );
455 } else if ( strcasecmp( left, "attr" ) == 0 /* TOLERATED */
456 || strcasecmp( left, "attrs" ) == 0 ) /* DOCUMENTED */
458 if ( strcasecmp( left, "attr" ) == 0 ) {
459 Debug( LDAP_DEBUG_ANY,
460 "%s: line %d: \"attr\" "
461 "is deprecated (and undocumented); "
462 "use \"attrs\" instead.\n",
466 a->acl_attrs = str2anlist( a->acl_attrs,
468 if ( a->acl_attrs == NULL ) {
469 Debug( LDAP_DEBUG_ANY,
470 "%s: line %d: unknown attr \"%s\" in to clause\n",
471 fname, lineno, right );
475 } else if ( strncasecmp( left, "val", 3 ) == 0 ) {
478 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
479 Debug( LDAP_DEBUG_ANY,
480 "%s: line %d: attr val already specified in to clause.\n",
484 if ( a->acl_attrs == NULL || !BER_BVISEMPTY( &a->acl_attrs[1].an_name ) )
486 Debug( LDAP_DEBUG_ANY,
487 "%s: line %d: attr val requires a single attribute.\n",
492 ber_str2bv( right, 0, 1, &a->acl_attrval );
493 a->acl_attrval_style = ACL_STYLE_BASE;
495 mr = strchr( left, '/' );
500 a->acl_attrval_mr = mr_find( mr );
501 if ( a->acl_attrval_mr == NULL ) {
502 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
503 "invalid matching rule \"%s\".\n",
508 if( !mr_usable_with_at( a->acl_attrval_mr, a->acl_attrs[ 0 ].an_desc->ad_type ) )
510 char buf[ SLAP_TEXT_BUFLEN ];
512 snprintf( buf, sizeof( buf ),
513 "matching rule \"%s\" use "
514 "with attr \"%s\" not appropriate.",
515 mr, a->acl_attrs[ 0 ].an_name.bv_val );
518 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
519 fname, lineno, buf );
524 if ( style != NULL ) {
525 if ( strcasecmp( style, "regex" ) == 0 ) {
526 int e = regcomp( &a->acl_attrval_re, a->acl_attrval.bv_val,
527 REG_EXTENDED | REG_ICASE | REG_NOSUB );
529 char err[SLAP_TEXT_BUFLEN],
530 buf[ SLAP_TEXT_BUFLEN ];
532 regerror( e, &a->acl_attrval_re, err, sizeof( err ) );
534 snprintf( buf, sizeof( buf ),
535 "regular expression \"%s\" bad because of %s",
538 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
539 fname, lineno, buf );
542 a->acl_attrval_style = ACL_STYLE_REGEX;
545 /* FIXME: if the attribute has DN syntax, we might
546 * allow one, subtree and children styles as well */
547 if ( !strcasecmp( style, "base" ) ||
548 !strcasecmp( style, "exact" ) ) {
549 a->acl_attrval_style = ACL_STYLE_BASE;
551 } else if ( a->acl_attrs[0].an_desc->ad_type->
552 sat_syntax == slap_schema.si_syn_distinguishedName )
556 if ( !strcasecmp( style, "baseObject" ) ||
557 !strcasecmp( style, "base" ) )
559 a->acl_attrval_style = ACL_STYLE_BASE;
560 } else if ( !strcasecmp( style, "onelevel" ) ||
561 !strcasecmp( style, "one" ) )
563 a->acl_attrval_style = ACL_STYLE_ONE;
564 } else if ( !strcasecmp( style, "subtree" ) ||
565 !strcasecmp( style, "sub" ) )
567 a->acl_attrval_style = ACL_STYLE_SUBTREE;
568 } else if ( !strcasecmp( style, "children" ) ) {
569 a->acl_attrval_style = ACL_STYLE_CHILDREN;
571 char buf[ SLAP_TEXT_BUFLEN ];
573 /* FIXME: should be an error */
575 snprintf( buf, sizeof( buf ),
576 "unknown val.<style> \"%s\" "
577 "for attributeType \"%s\" with DN syntax; "
579 SLAPD_CONF_UNKNOWN_IGNORED ".",
581 a->acl_attrs[0].an_desc->ad_cname.bv_val );
583 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
585 fname, lineno, buf );
586 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
588 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
589 a->acl_attrval_style = ACL_STYLE_BASE;
593 rc = dnNormalize( 0, NULL, NULL, &bv, &a->acl_attrval, NULL );
594 if ( rc != LDAP_SUCCESS ) {
595 char buf[ SLAP_TEXT_BUFLEN ];
597 snprintf( buf, sizeof( buf ),
598 "unable to normalize DN \"%s\" "
599 "for attributeType \"%s\" (%d).",
601 a->acl_attrs[0].an_desc->ad_cname.bv_val,
603 Debug( LDAP_DEBUG_ANY,
605 fname, lineno, buf );
608 ber_memfree( bv.bv_val );
611 char buf[ SLAP_TEXT_BUFLEN ];
613 /* FIXME: should be an error */
615 snprintf( buf, sizeof( buf ),
616 "unknown val.<style> \"%s\" "
617 "for attributeType \"%s\"; using \"exact\""
618 SLAPD_CONF_UNKNOWN_IGNORED ".",
619 style, a->acl_attrs[0].an_desc->ad_cname.bv_val );
620 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
622 fname, lineno, buf );
623 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
625 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
626 a->acl_attrval_style = ACL_STYLE_BASE;
631 /* Check for appropriate matching rule */
632 if ( a->acl_attrval_style != ACL_STYLE_REGEX ) {
633 if ( a->acl_attrval_mr == NULL ) {
634 a->acl_attrval_mr = a->acl_attrs[ 0 ].an_desc->ad_type->sat_equality;
637 if ( a->acl_attrval_mr == NULL ) {
638 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
639 "attr \"%s\" must have an EQUALITY matching rule.\n",
640 fname, lineno, a->acl_attrs[ 0 ].an_name.bv_val );
646 Debug( LDAP_DEBUG_ANY,
647 "%s: line %d: expecting <what> got \"%s\"\n",
648 fname, lineno, left );
653 if ( !BER_BVISNULL( &a->acl_dn_pat ) &&
654 ber_bvccmp( &a->acl_dn_pat, '*' ) )
656 free( a->acl_dn_pat.bv_val );
657 BER_BVZERO( &a->acl_dn_pat );
658 a->acl_dn_style = ACL_STYLE_REGEX;
661 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
662 a->acl_dn_style != ACL_STYLE_REGEX )
664 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
666 rc = dnNormalize( 0, NULL, NULL, &a->acl_dn_pat, &bv, NULL);
667 if ( rc != LDAP_SUCCESS ) {
668 Debug( LDAP_DEBUG_ANY,
669 "%s: line %d: bad DN \"%s\" in to DN clause\n",
670 fname, lineno, a->acl_dn_pat.bv_val );
673 free( a->acl_dn_pat.bv_val );
677 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
678 REG_EXTENDED | REG_ICASE );
680 char err[ SLAP_TEXT_BUFLEN ],
681 buf[ SLAP_TEXT_BUFLEN ];
683 regerror( e, &a->acl_dn_re, err, sizeof( err ) );
684 snprintf( buf, sizeof( buf ),
685 "regular expression \"%s\" bad because of %s",
687 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
688 fname, lineno, buf );
694 /* by clause - select who has what access to entries */
695 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
697 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
698 "to clause required before by clause in access line\n",
704 * by clause consists of <who> and <access>
707 b = (Access *) ch_calloc( 1, sizeof(Access) );
709 ACL_INVALIDATE( b->a_access_mask );
712 Debug( LDAP_DEBUG_ANY,
713 "%s: line %d: premature EOL: expecting <who>\n",
719 for ( ; i < argc; i++ ) {
720 slap_style_t sty = ACL_STYLE_REGEX;
721 char *style_modifier = NULL;
722 char *style_level = NULL;
725 slap_dn_access *bdn = &b->a_dn;
728 split( argv[i], '=', &left, &right );
729 split( left, '.', &left, &style );
731 split( style, ',', &style, &style_modifier );
733 if ( strncasecmp( style, "level", STRLENOF( "level" ) ) == 0 ) {
734 split( style, '{', &style, &style_level );
735 if ( style_level != NULL ) {
736 char *p = strchr( style_level, '}' );
738 Debug( LDAP_DEBUG_ANY,
739 "%s: line %d: premature eol: "
740 "expecting closing '}' in \"level{n}\"\n",
743 } else if ( p == style_level ) {
744 Debug( LDAP_DEBUG_ANY,
745 "%s: line %d: empty level "
755 if ( style == NULL || *style == '\0' ||
756 strcasecmp( style, "exact" ) == 0 ||
757 strcasecmp( style, "baseObject" ) == 0 ||
758 strcasecmp( style, "base" ) == 0 )
760 sty = ACL_STYLE_BASE;
762 } else if ( strcasecmp( style, "onelevel" ) == 0 ||
763 strcasecmp( style, "one" ) == 0 )
767 } else if ( strcasecmp( style, "subtree" ) == 0 ||
768 strcasecmp( style, "sub" ) == 0 )
770 sty = ACL_STYLE_SUBTREE;
772 } else if ( strcasecmp( style, "children" ) == 0 ) {
773 sty = ACL_STYLE_CHILDREN;
775 } else if ( strcasecmp( style, "level" ) == 0 )
779 level = strtol( style_level, &next, 10 );
780 if ( next[0] != '\0' ) {
781 Debug( LDAP_DEBUG_ANY,
782 "%s: line %d: unable to parse level "
788 sty = ACL_STYLE_LEVEL;
790 } else if ( strcasecmp( style, "regex" ) == 0 ) {
791 sty = ACL_STYLE_REGEX;
793 } else if ( strcasecmp( style, "expand" ) == 0 ) {
794 sty = ACL_STYLE_EXPAND;
796 } else if ( strcasecmp( style, "ip" ) == 0 ) {
799 } else if ( strcasecmp( style, "path" ) == 0 ) {
800 sty = ACL_STYLE_PATH;
801 #ifndef LDAP_PF_LOCAL
802 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
804 "\"path\" style modifier is useless without local"
805 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
807 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
809 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
810 #endif /* LDAP_PF_LOCAL */
813 Debug( LDAP_DEBUG_ANY,
814 "%s: line %d: unknown style \"%s\" in by clause\n",
815 fname, lineno, style );
819 if ( style_modifier &&
820 strcasecmp( style_modifier, "expand" ) == 0 )
823 case ACL_STYLE_REGEX:
824 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
825 "\"regex\" style implies "
826 "\"expand\" modifier"
827 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
829 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
831 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
834 case ACL_STYLE_EXPAND:
838 /* we'll see later if it's pertinent */
844 /* expand in <who> needs regex in <what> */
845 if ( ( sty == ACL_STYLE_EXPAND || expand )
846 && a->acl_dn_style != ACL_STYLE_REGEX )
848 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL, "%s: line %d: "
849 "\"expand\" style or modifier used "
850 "in conjunction with "
851 "a non-regex <what> clause"
852 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
854 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
856 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
859 if ( strncasecmp( left, "real", STRLENOF( "real" ) ) == 0 ) {
862 left += STRLENOF( "real" );
865 if ( strcasecmp( left, "*" ) == 0 ) {
870 ber_str2bv( "*", STRLENOF( "*" ), 1, &bv );
871 sty = ACL_STYLE_REGEX;
873 } else if ( strcasecmp( left, "anonymous" ) == 0 ) {
874 ber_str2bv("anonymous", STRLENOF( "anonymous" ), 1, &bv);
875 sty = ACL_STYLE_ANONYMOUS;
877 } else if ( strcasecmp( left, "users" ) == 0 ) {
878 ber_str2bv("users", STRLENOF( "users" ), 1, &bv);
879 sty = ACL_STYLE_USERS;
881 } else if ( strcasecmp( left, "self" ) == 0 ) {
882 ber_str2bv("self", STRLENOF( "self" ), 1, &bv);
883 sty = ACL_STYLE_SELF;
885 } else if ( strcasecmp( left, "dn" ) == 0 ) {
886 if ( sty == ACL_STYLE_REGEX ) {
887 bdn->a_style = ACL_STYLE_REGEX;
888 if ( right == NULL ) {
893 bdn->a_style = ACL_STYLE_USERS;
895 } else if (*right == '\0' ) {
897 ber_str2bv("anonymous",
898 STRLENOF( "anonymous" ),
900 bdn->a_style = ACL_STYLE_ANONYMOUS;
902 } else if ( strcmp( right, "*" ) == 0 ) {
904 /* any or users? users for now */
908 bdn->a_style = ACL_STYLE_USERS;
910 } else if ( strcmp( right, ".+" ) == 0
911 || strcmp( right, "^.+" ) == 0
912 || strcmp( right, ".+$" ) == 0
913 || strcmp( right, "^.+$" ) == 0
914 || strcmp( right, ".+$$" ) == 0
915 || strcmp( right, "^.+$$" ) == 0 )
920 bdn->a_style = ACL_STYLE_USERS;
922 } else if ( strcmp( right, ".*" ) == 0
923 || strcmp( right, "^.*" ) == 0
924 || strcmp( right, ".*$" ) == 0
925 || strcmp( right, "^.*$" ) == 0
926 || strcmp( right, ".*$$" ) == 0
927 || strcmp( right, "^.*$$" ) == 0 )
934 acl_regex_normalized_dn( right, &bv );
935 if ( !ber_bvccmp( &bv, '*' ) ) {
936 regtest( fname, lineno, bv.bv_val );
940 } else if ( right == NULL || *right == '\0' ) {
941 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
942 "missing \"=\" in (or value after) \"%s\" "
944 fname, lineno, left );
948 ber_str2bv( right, 0, 1, &bv );
955 if ( !BER_BVISNULL( &bv ) ) {
956 if ( !BER_BVISEMPTY( &bdn->a_pat ) ) {
957 Debug( LDAP_DEBUG_ANY,
958 "%s: line %d: dn pattern already specified.\n",
963 if ( sty != ACL_STYLE_REGEX &&
964 sty != ACL_STYLE_ANONYMOUS &&
965 sty != ACL_STYLE_USERS &&
966 sty != ACL_STYLE_SELF &&
969 rc = dnNormalize(0, NULL, NULL,
970 &bv, &bdn->a_pat, NULL);
971 if ( rc != LDAP_SUCCESS ) {
972 Debug( LDAP_DEBUG_ANY,
973 "%s: line %d: bad DN \"%s\" in by DN clause\n",
974 fname, lineno, bv.bv_val );
978 if ( sty == ACL_STYLE_BASE
980 && !BER_BVISNULL( &be->be_rootndn )
981 && dn_match( &bdn->a_pat, &be->be_rootndn ) )
983 Debug( LDAP_DEBUG_ANY,
984 "%s: line %d: rootdn is always granted "
985 "unlimited privileges.\n",
997 for ( exp = strchr( bdn->a_pat.bv_val, '$' );
998 exp && (ber_len_t)(exp - bdn->a_pat.bv_val)
1000 exp = strchr( exp, '$' ) )
1002 if ( isdigit( exp[ 1 ] ) ) {
1009 bdn->a_expand = expand;
1012 Debug( LDAP_DEBUG_ANY,
1013 "%s: line %d: \"expand\" used "
1014 "with no expansions in \"pattern\""
1015 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1017 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1019 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1022 if ( sty == ACL_STYLE_SELF ) {
1023 bdn->a_self_level = level;
1027 Debug( LDAP_DEBUG_ANY,
1028 "%s: line %d: bad negative level \"%d\" "
1029 "in by DN clause\n",
1030 fname, lineno, level );
1032 } else if ( level == 1 ) {
1033 Debug( LDAP_DEBUG_ANY,
1034 "%s: line %d: \"onelevel\" should be used "
1035 "instead of \"level{1}\" in by DN clause\n",
1037 } else if ( level == 0 && sty == ACL_STYLE_LEVEL ) {
1038 Debug( LDAP_DEBUG_ANY,
1039 "%s: line %d: \"base\" should be used "
1040 "instead of \"level{0}\" in by DN clause\n",
1044 bdn->a_level = level;
1049 if ( strcasecmp( left, "dnattr" ) == 0 ) {
1050 if ( right == NULL || right[0] == '\0' ) {
1051 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1052 "missing \"=\" in (or value after) \"%s\" "
1054 fname, lineno, left );
1058 if( bdn->a_at != NULL ) {
1059 Debug( LDAP_DEBUG_ANY,
1060 "%s: line %d: dnattr already specified.\n",
1065 rc = slap_str2ad( right, &bdn->a_at, &text );
1067 if( rc != LDAP_SUCCESS ) {
1068 char buf[ SLAP_TEXT_BUFLEN ];
1070 snprintf( buf, sizeof( buf ),
1071 "dnattr \"%s\": %s",
1073 Debug( LDAP_DEBUG_ANY,
1074 "%s: line %d: %s\n",
1075 fname, lineno, buf );
1080 if( !is_at_syntax( bdn->a_at->ad_type,
1081 SLAPD_DN_SYNTAX ) &&
1082 !is_at_syntax( bdn->a_at->ad_type,
1083 SLAPD_NAMEUID_SYNTAX ))
1085 char buf[ SLAP_TEXT_BUFLEN ];
1087 snprintf( buf, sizeof( buf ),
1089 "inappropriate syntax: %s\n",
1091 bdn->a_at->ad_type->sat_syntax_oid );
1092 Debug( LDAP_DEBUG_ANY,
1093 "%s: line %d: %s\n",
1094 fname, lineno, buf );
1098 if( bdn->a_at->ad_type->sat_equality == NULL ) {
1099 Debug( LDAP_DEBUG_ANY,
1100 "%s: line %d: dnattr \"%s\": "
1101 "inappropriate matching (no EQUALITY)\n",
1102 fname, lineno, right );
1109 if ( strncasecmp( left, "group", STRLENOF( "group" ) ) == 0 ) {
1114 case ACL_STYLE_REGEX:
1115 /* legacy, tolerated */
1116 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
1118 "deprecated group style \"regex\"; "
1119 "use \"expand\" instead.\n",
1121 sty = ACL_STYLE_EXPAND;
1124 case ACL_STYLE_BASE:
1125 /* legal, traditional */
1126 case ACL_STYLE_EXPAND:
1127 /* legal, substring expansion; supersedes regex */
1132 Debug( LDAP_DEBUG_ANY,
1134 "inappropriate style \"%s\" in by clause.\n",
1135 fname, lineno, style );
1139 if ( right == NULL || right[0] == '\0' ) {
1140 Debug( LDAP_DEBUG_ANY,
1142 "missing \"=\" in (or value after) \"%s\" "
1144 fname, lineno, left );
1148 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1149 Debug( LDAP_DEBUG_ANY,
1150 "%s: line %d: group pattern already specified.\n",
1155 /* format of string is
1156 "group/objectClassValue/groupAttrName" */
1157 if ( ( value = strchr(left, '/') ) != NULL ) {
1159 if ( *value && ( name = strchr( value, '/' ) ) != NULL ) {
1164 b->a_group_style = sty;
1165 if ( sty == ACL_STYLE_EXPAND ) {
1166 acl_regex_normalized_dn( right, &bv );
1167 if ( !ber_bvccmp( &bv, '*' ) ) {
1168 regtest( fname, lineno, bv.bv_val );
1170 b->a_group_pat = bv;
1173 ber_str2bv( right, 0, 0, &bv );
1174 rc = dnNormalize( 0, NULL, NULL, &bv,
1175 &b->a_group_pat, NULL );
1176 if ( rc != LDAP_SUCCESS ) {
1177 Debug( LDAP_DEBUG_ANY,
1178 "%s: line %d: bad DN \"%s\".\n",
1179 fname, lineno, right );
1184 if ( value && *value ) {
1185 b->a_group_oc = oc_find( value );
1188 if ( b->a_group_oc == NULL ) {
1189 Debug( LDAP_DEBUG_ANY,
1190 "%s: line %d: group objectclass "
1191 "\"%s\" unknown.\n",
1192 fname, lineno, value );
1197 b->a_group_oc = oc_find( SLAPD_GROUP_CLASS );
1199 if( b->a_group_oc == NULL ) {
1200 Debug( LDAP_DEBUG_ANY,
1201 "%s: line %d: group default objectclass "
1202 "\"%s\" unknown.\n",
1203 fname, lineno, SLAPD_GROUP_CLASS );
1208 if ( is_object_subclass( slap_schema.si_oc_referral,
1211 Debug( LDAP_DEBUG_ANY,
1212 "%s: line %d: group objectclass \"%s\" "
1213 "is subclass of referral.\n",
1214 fname, lineno, value );
1218 if ( is_object_subclass( slap_schema.si_oc_alias,
1221 Debug( LDAP_DEBUG_ANY,
1222 "%s: line %d: group objectclass \"%s\" "
1223 "is subclass of alias.\n",
1224 fname, lineno, value );
1228 if ( name && *name ) {
1229 rc = slap_str2ad( name, &b->a_group_at, &text );
1231 if( rc != LDAP_SUCCESS ) {
1232 char buf[ SLAP_TEXT_BUFLEN ];
1234 snprintf( buf, sizeof( buf ),
1235 "group \"%s\": %s.",
1237 Debug( LDAP_DEBUG_ANY,
1238 "%s: line %d: %s\n",
1239 fname, lineno, buf );
1245 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
1247 if ( rc != LDAP_SUCCESS ) {
1248 char buf[ SLAP_TEXT_BUFLEN ];
1250 snprintf( buf, sizeof( buf ),
1251 "group \"%s\": %s.",
1252 SLAPD_GROUP_ATTR, text );
1253 Debug( LDAP_DEBUG_ANY,
1254 "%s: line %d: %s\n",
1255 fname, lineno, buf );
1260 if ( !is_at_syntax( b->a_group_at->ad_type,
1261 SLAPD_DN_SYNTAX ) &&
1262 !is_at_syntax( b->a_group_at->ad_type,
1263 SLAPD_NAMEUID_SYNTAX ) &&
1264 !is_at_subtype( b->a_group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ) )
1266 char buf[ SLAP_TEXT_BUFLEN ];
1268 snprintf( buf, sizeof( buf ),
1269 "group \"%s\": inappropriate syntax: %s.",
1271 b->a_group_at->ad_type->sat_syntax_oid );
1272 Debug( LDAP_DEBUG_ANY,
1273 "%s: line %d: %s\n",
1274 fname, lineno, buf );
1281 struct berval vals[2];
1283 ber_str2bv( b->a_group_oc->soc_oid, 0, 0, &vals[0] );
1284 BER_BVZERO( &vals[1] );
1286 rc = oc_check_allowed( b->a_group_at->ad_type,
1290 char buf[ SLAP_TEXT_BUFLEN ];
1292 snprintf( buf, sizeof( buf ),
1293 "group: \"%s\" not allowed by \"%s\".",
1294 b->a_group_at->ad_cname.bv_val,
1295 b->a_group_oc->soc_oid );
1296 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
1297 fname, lineno, buf );
1304 if ( strcasecmp( left, "peername" ) == 0 ) {
1306 case ACL_STYLE_REGEX:
1307 case ACL_STYLE_BASE:
1308 /* legal, traditional */
1309 case ACL_STYLE_EXPAND:
1310 /* cheap replacement to regex for simple expansion */
1312 case ACL_STYLE_PATH:
1313 /* legal, peername specific */
1317 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1318 "inappropriate style \"%s\" in by clause.\n",
1319 fname, lineno, style );
1323 if ( right == NULL || right[0] == '\0' ) {
1324 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1325 "missing \"=\" in (or value after) \"%s\" "
1327 fname, lineno, left );
1331 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1332 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1333 "peername pattern already specified.\n",
1338 b->a_peername_style = sty;
1339 if ( sty == ACL_STYLE_REGEX ) {
1340 acl_regex_normalized_dn( right, &bv );
1341 if ( !ber_bvccmp( &bv, '*' ) ) {
1342 regtest( fname, lineno, bv.bv_val );
1344 b->a_peername_pat = bv;
1347 ber_str2bv( right, 0, 1, &b->a_peername_pat );
1349 if ( sty == ACL_STYLE_IP ) {
1354 split( right, '{', &addr, &port );
1355 split( addr, '%', &addr, &mask );
1357 b->a_peername_addr = inet_addr( addr );
1358 if ( b->a_peername_addr == (unsigned long)(-1) ) {
1359 /* illegal address */
1360 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1361 "illegal peername address \"%s\".\n",
1362 fname, lineno, addr );
1366 b->a_peername_mask = (unsigned long)(-1);
1367 if ( mask != NULL ) {
1368 b->a_peername_mask = inet_addr( mask );
1369 if ( b->a_peername_mask ==
1370 (unsigned long)(-1) )
1373 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1374 "illegal peername address mask "
1376 fname, lineno, mask );
1381 b->a_peername_port = -1;
1385 b->a_peername_port = strtol( port, &end, 10 );
1386 if ( end[0] != '}' ) {
1388 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1389 "illegal peername port specification "
1391 fname, lineno, port );
1400 if ( strcasecmp( left, "sockname" ) == 0 ) {
1402 case ACL_STYLE_REGEX:
1403 case ACL_STYLE_BASE:
1404 /* legal, traditional */
1405 case ACL_STYLE_EXPAND:
1406 /* cheap replacement to regex for simple expansion */
1411 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1412 "inappropriate style \"%s\" in by clause\n",
1413 fname, lineno, style );
1417 if ( right == NULL || right[0] == '\0' ) {
1418 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1419 "missing \"=\" in (or value after) \"%s\" "
1421 fname, lineno, left );
1425 if ( !BER_BVISNULL( &b->a_sockname_pat ) ) {
1426 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1427 "sockname pattern already specified.\n",
1432 b->a_sockname_style = sty;
1433 if ( sty == ACL_STYLE_REGEX ) {
1434 acl_regex_normalized_dn( right, &bv );
1435 if ( !ber_bvccmp( &bv, '*' ) ) {
1436 regtest( fname, lineno, bv.bv_val );
1438 b->a_sockname_pat = bv;
1441 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
1446 if ( strcasecmp( left, "domain" ) == 0 ) {
1448 case ACL_STYLE_REGEX:
1449 case ACL_STYLE_BASE:
1450 case ACL_STYLE_SUBTREE:
1451 /* legal, traditional */
1454 case ACL_STYLE_EXPAND:
1455 /* tolerated: means exact,expand */
1457 Debug( LDAP_DEBUG_ANY,
1459 "\"expand\" modifier "
1460 "with \"expand\" style.\n",
1463 sty = ACL_STYLE_BASE;
1469 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1470 "inappropriate style \"%s\" in by clause.\n",
1471 fname, lineno, style );
1475 if ( right == NULL || right[0] == '\0' ) {
1476 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1477 "missing \"=\" in (or value after) \"%s\" "
1479 fname, lineno, left );
1483 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1484 Debug( LDAP_DEBUG_ANY,
1485 "%s: line %d: domain pattern already specified.\n",
1490 b->a_domain_style = sty;
1491 b->a_domain_expand = expand;
1492 if ( sty == ACL_STYLE_REGEX ) {
1493 acl_regex_normalized_dn( right, &bv );
1494 if ( !ber_bvccmp( &bv, '*' ) ) {
1495 regtest( fname, lineno, bv.bv_val );
1497 b->a_domain_pat = bv;
1500 ber_str2bv( right, 0, 1, &b->a_domain_pat );
1505 if ( strcasecmp( left, "sockurl" ) == 0 ) {
1507 case ACL_STYLE_REGEX:
1508 case ACL_STYLE_BASE:
1509 /* legal, traditional */
1510 case ACL_STYLE_EXPAND:
1511 /* cheap replacement to regex for simple expansion */
1516 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1517 "inappropriate style \"%s\" in by clause.\n",
1518 fname, lineno, style );
1522 if ( right == NULL || right[0] == '\0' ) {
1523 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1524 "missing \"=\" in (or value after) \"%s\" "
1526 fname, lineno, left );
1530 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1531 Debug( LDAP_DEBUG_ANY,
1532 "%s: line %d: sockurl pattern already specified.\n",
1537 b->a_sockurl_style = sty;
1538 if ( sty == ACL_STYLE_REGEX ) {
1539 acl_regex_normalized_dn( right, &bv );
1540 if ( !ber_bvccmp( &bv, '*' ) ) {
1541 regtest( fname, lineno, bv.bv_val );
1543 b->a_sockurl_pat = bv;
1546 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
1551 if ( strcasecmp( left, "set" ) == 0 ) {
1554 case ACL_STYLE_REGEX:
1555 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
1557 "deprecated set style "
1558 "\"regex\" in <by> clause; "
1559 "use \"expand\" instead.\n",
1561 sty = ACL_STYLE_EXPAND;
1564 case ACL_STYLE_BASE:
1565 case ACL_STYLE_EXPAND:
1569 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1570 "inappropriate style \"%s\" in by clause.\n",
1571 fname, lineno, style );
1575 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1576 Debug( LDAP_DEBUG_ANY,
1577 "%s: line %d: set attribute already specified.\n",
1582 if ( right == NULL || *right == '\0' ) {
1583 Debug( LDAP_DEBUG_ANY,
1584 "%s: line %d: no set is defined.\n",
1589 b->a_set_style = sty;
1590 ber_str2bv( right, 0, 1, &b->a_set_pat );
1600 if ( strcasecmp( left, "aci" ) == 0 ) {
1603 } else if ( strncasecmp( left, "dynacl/", STRLENOF( "dynacl/" ) ) == 0 ) {
1604 name = &left[ STRLENOF( "dynacl/" ) ];
1605 opts = strchr( name, '/' );
1613 if ( slap_dynacl_config( fname, lineno, b, name, opts, sty, right ) ) {
1614 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1615 "unable to configure dynacl \"%s\".\n",
1616 fname, lineno, name );
1623 #else /* ! SLAP_DYNACL */
1625 #ifdef SLAPD_ACI_ENABLED
1626 if ( strcasecmp( left, "aci" ) == 0 ) {
1627 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1628 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1629 "inappropriate style \"%s\" in by clause.\n",
1630 fname, lineno, style );
1634 if( b->a_aci_at != NULL ) {
1635 Debug( LDAP_DEBUG_ANY,
1636 "%s: line %d: ACI attribute already specified.\n",
1641 if ( right != NULL && *right != '\0' ) {
1642 rc = slap_str2ad( right, &b->a_aci_at, &text );
1644 if( rc != LDAP_SUCCESS ) {
1645 char buf[ SLAP_TEXT_BUFLEN ];
1647 snprintf( buf, sizeof( buf ),
1650 Debug( LDAP_DEBUG_ANY,
1651 "%s: line %d: %s\n",
1652 fname, lineno, buf );
1657 b->a_aci_at = slap_ad_aci;
1660 if( !is_at_syntax( b->a_aci_at->ad_type,
1663 char buf[ SLAP_TEXT_BUFLEN ];
1665 snprintf( buf, sizeof( buf ),
1666 "ACI \"%s\": inappropriate syntax: %s.",
1668 b->a_aci_at->ad_type->sat_syntax_oid );
1669 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
1670 fname, lineno, buf );
1676 #endif /* SLAPD_ACI_ENABLED */
1677 #endif /* ! SLAP_DYNACL */
1679 if ( strcasecmp( left, "ssf" ) == 0 ) {
1680 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1681 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1682 "inappropriate style \"%s\" in by clause.\n",
1683 fname, lineno, style );
1687 if ( b->a_authz.sai_ssf ) {
1688 Debug( LDAP_DEBUG_ANY,
1689 "%s: line %d: ssf attribute already specified.\n",
1694 if ( right == NULL || *right == '\0' ) {
1695 Debug( LDAP_DEBUG_ANY,
1696 "%s: line %d: no ssf is defined.\n",
1701 b->a_authz.sai_ssf = strtol( right, &next, 10 );
1702 if ( next == NULL || next[0] != '\0' ) {
1703 Debug( LDAP_DEBUG_ANY,
1704 "%s: line %d: unable to parse ssf value (%s).\n",
1705 fname, lineno, right );
1709 if ( !b->a_authz.sai_ssf ) {
1710 Debug( LDAP_DEBUG_ANY,
1711 "%s: line %d: invalid ssf value (%s).\n",
1712 fname, lineno, right );
1718 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
1719 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1720 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1721 "inappropriate style \"%s\" in by clause.\n",
1722 fname, lineno, style );
1726 if ( b->a_authz.sai_transport_ssf ) {
1727 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1728 "transport_ssf attribute already specified.\n",
1733 if ( right == NULL || *right == '\0' ) {
1734 Debug( LDAP_DEBUG_ANY,
1735 "%s: line %d: no transport_ssf is defined.\n",
1740 b->a_authz.sai_transport_ssf = strtol( right, &next, 10 );
1741 if ( next == NULL || next[0] != '\0' ) {
1742 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1743 "unable to parse transport_ssf value (%s).\n",
1744 fname, lineno, right );
1748 if ( !b->a_authz.sai_transport_ssf ) {
1749 Debug( LDAP_DEBUG_ANY,
1750 "%s: line %d: invalid transport_ssf value (%s).\n",
1751 fname, lineno, right );
1757 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
1758 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1759 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1760 "inappropriate style \"%s\" in by clause.\n",
1761 fname, lineno, style );
1765 if ( b->a_authz.sai_tls_ssf ) {
1766 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1767 "tls_ssf attribute already specified.\n",
1772 if ( right == NULL || *right == '\0' ) {
1773 Debug( LDAP_DEBUG_ANY,
1774 "%s: line %d: no tls_ssf is defined\n",
1779 b->a_authz.sai_tls_ssf = strtol( right, &next, 10 );
1780 if ( next == NULL || next[0] != '\0' ) {
1781 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1782 "unable to parse tls_ssf value (%s).\n",
1783 fname, lineno, right );
1787 if ( !b->a_authz.sai_tls_ssf ) {
1788 Debug( LDAP_DEBUG_ANY,
1789 "%s: line %d: invalid tls_ssf value (%s).\n",
1790 fname, lineno, right );
1796 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1797 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1798 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1799 "inappropriate style \"%s\" in by clause.\n",
1800 fname, lineno, style );
1804 if ( b->a_authz.sai_sasl_ssf ) {
1805 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1806 "sasl_ssf attribute already specified.\n",
1811 if ( right == NULL || *right == '\0' ) {
1812 Debug( LDAP_DEBUG_ANY,
1813 "%s: line %d: no sasl_ssf is defined.\n",
1818 b->a_authz.sai_sasl_ssf = strtol( right, &next, 10 );
1819 if ( next == NULL || next[0] != '\0' ) {
1820 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1821 "unable to parse sasl_ssf value (%s).\n",
1822 fname, lineno, right );
1826 if ( !b->a_authz.sai_sasl_ssf ) {
1827 Debug( LDAP_DEBUG_ANY,
1828 "%s: line %d: invalid sasl_ssf value (%s).\n",
1829 fname, lineno, right );
1835 if ( right != NULL ) {
1842 if ( i == argc || ( strcasecmp( left, "stop" ) == 0 ) ) {
1843 /* out of arguments or plain stop */
1845 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1846 b->a_type = ACL_STOP;
1848 access_append( &a->acl_access, b );
1852 if ( strcasecmp( left, "continue" ) == 0 ) {
1853 /* plain continue */
1855 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1856 b->a_type = ACL_CONTINUE;
1858 access_append( &a->acl_access, b );
1862 if ( strcasecmp( left, "break" ) == 0 ) {
1863 /* plain continue */
1865 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1866 b->a_type = ACL_BREAK;
1868 access_append( &a->acl_access, b );
1872 if ( strcasecmp( left, "by" ) == 0 ) {
1873 /* we've gone too far */
1875 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1876 b->a_type = ACL_STOP;
1878 access_append( &a->acl_access, b );
1883 if ( strncasecmp( left, "self", STRLENOF( "self" ) ) == 0 ) {
1885 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "self" ) ] ) );
1887 } else if ( strncasecmp( left, "realself", STRLENOF( "realself" ) ) == 0 ) {
1888 b->a_realdn_self = 1;
1889 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "realself" ) ] ) );
1892 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1895 if ( ACL_IS_INVALID( b->a_access_mask ) ) {
1896 Debug( LDAP_DEBUG_ANY,
1897 "%s: line %d: expecting <access> got \"%s\".\n",
1898 fname, lineno, left );
1902 b->a_type = ACL_STOP;
1904 if ( ++i == argc ) {
1905 /* out of arguments or plain stop */
1906 access_append( &a->acl_access, b );
1910 if ( strcasecmp( argv[i], "continue" ) == 0 ) {
1911 /* plain continue */
1912 b->a_type = ACL_CONTINUE;
1914 } else if ( strcasecmp( argv[i], "break" ) == 0 ) {
1915 /* plain continue */
1916 b->a_type = ACL_BREAK;
1918 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1923 access_append( &a->acl_access, b );
1926 Debug( LDAP_DEBUG_ANY,
1927 "%s: line %d: expecting \"to\" "
1928 "or \"by\" got \"%s\"\n",
1929 fname, lineno, argv[i] );
1934 /* if we have no real access clause, complain and do nothing */
1936 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1937 "warning: no access clause(s) "
1938 "specified in access line"
1939 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1941 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1943 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1947 if ( ldap_debug & LDAP_DEBUG_ACL ) {
1952 if ( a->acl_access == NULL ) {
1953 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1954 "warning: no by clause(s) "
1955 "specified in access line"
1956 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1958 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1960 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1964 if ( !BER_BVISNULL( &be->be_nsuffix[ 1 ] ) ) {
1965 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1966 "scope checking only applies to single-valued "
1967 "suffix databases\n",
1969 /* go ahead, since checking is not authoritative */
1972 switch ( check_scope( be, a ) ) {
1973 case ACL_SCOPE_UNKNOWN:
1974 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1975 "cannot assess the validity of the ACL scope within "
1976 "backend naming context\n",
1980 case ACL_SCOPE_WARN:
1981 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1982 "ACL could be out of scope within backend naming context\n",
1986 case ACL_SCOPE_PARTIAL:
1987 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1988 "ACL appears to be partially out of scope within "
1989 "backend naming context\n",
1994 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1995 "ACL appears to be out of scope within "
1996 "backend naming context\n",
2003 acl_append( &be->be_acl, a, pos );
2006 acl_append( &frontendDB->be_acl, a, pos );
2012 accessmask2str( slap_mask_t mask, char *buf, int debug )
2017 assert( buf != NULL );
2019 if ( ACL_IS_INVALID( mask ) ) {
2025 if ( ACL_IS_LEVEL( mask ) ) {
2026 if ( ACL_LVL_IS_NONE(mask) ) {
2027 ptr = lutil_strcopy( ptr, "none" );
2029 } else if ( ACL_LVL_IS_DISCLOSE(mask) ) {
2030 ptr = lutil_strcopy( ptr, "disclose" );
2032 } else if ( ACL_LVL_IS_AUTH(mask) ) {
2033 ptr = lutil_strcopy( ptr, "auth" );
2035 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
2036 ptr = lutil_strcopy( ptr, "compare" );
2038 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
2039 ptr = lutil_strcopy( ptr, "search" );
2041 } else if ( ACL_LVL_IS_READ(mask) ) {
2042 ptr = lutil_strcopy( ptr, "read" );
2044 } else if ( ACL_LVL_IS_WRITE(mask) ) {
2045 ptr = lutil_strcopy( ptr, "write" );
2047 } else if ( ACL_LVL_IS_WADD(mask) ) {
2048 ptr = lutil_strcopy( ptr, "add" );
2050 } else if ( ACL_LVL_IS_WDEL(mask) ) {
2051 ptr = lutil_strcopy( ptr, "delete" );
2053 } else if ( ACL_LVL_IS_MANAGE(mask) ) {
2054 ptr = lutil_strcopy( ptr, "manage" );
2057 ptr = lutil_strcopy( ptr, "unknown" );
2067 if( ACL_IS_ADDITIVE( mask ) ) {
2070 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
2077 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_MANAGE) ) {
2082 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
2086 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WADD) ) {
2090 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WDEL) ) {
2095 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
2100 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
2105 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
2110 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
2115 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_DISCLOSE) ) {
2120 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
2129 if ( ACL_IS_LEVEL( mask ) ) {
2139 str2accessmask( const char *str )
2143 if( !ASCII_ALPHA(str[0]) ) {
2146 if ( str[0] == '=' ) {
2149 } else if( str[0] == '+' ) {
2150 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
2152 } else if( str[0] == '-' ) {
2153 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
2156 ACL_INVALIDATE(mask);
2160 for( i=1; str[i] != '\0'; i++ ) {
2161 if( TOLOWER((unsigned char) str[i]) == 'm' ) {
2162 ACL_PRIV_SET(mask, ACL_PRIV_MANAGE);
2164 } else if( TOLOWER((unsigned char) str[i]) == 'w' ) {
2165 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
2167 } else if( TOLOWER((unsigned char) str[i]) == 'a' ) {
2168 ACL_PRIV_SET(mask, ACL_PRIV_WADD);
2170 } else if( TOLOWER((unsigned char) str[i]) == 'z' ) {
2171 ACL_PRIV_SET(mask, ACL_PRIV_WDEL);
2173 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
2174 ACL_PRIV_SET(mask, ACL_PRIV_READ);
2176 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
2177 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
2179 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
2180 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
2182 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
2183 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
2185 } else if( TOLOWER((unsigned char) str[i]) == 'd' ) {
2186 ACL_PRIV_SET(mask, ACL_PRIV_DISCLOSE);
2188 } else if( str[i] != '0' ) {
2189 ACL_INVALIDATE(mask);
2197 if ( strcasecmp( str, "none" ) == 0 ) {
2198 ACL_LVL_ASSIGN_NONE(mask);
2200 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2201 ACL_LVL_ASSIGN_DISCLOSE(mask);
2203 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2204 ACL_LVL_ASSIGN_AUTH(mask);
2206 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2207 ACL_LVL_ASSIGN_COMPARE(mask);
2209 } else if ( strcasecmp( str, "search" ) == 0 ) {
2210 ACL_LVL_ASSIGN_SEARCH(mask);
2212 } else if ( strcasecmp( str, "read" ) == 0 ) {
2213 ACL_LVL_ASSIGN_READ(mask);
2215 } else if ( strcasecmp( str, "add" ) == 0 ) {
2216 ACL_LVL_ASSIGN_WADD(mask);
2218 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2219 ACL_LVL_ASSIGN_WDEL(mask);
2221 } else if ( strcasecmp( str, "write" ) == 0 ) {
2222 ACL_LVL_ASSIGN_WRITE(mask);
2224 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2225 ACL_LVL_ASSIGN_MANAGE(mask);
2228 ACL_INVALIDATE( mask );
2238 "<access clause> ::= access to <what> "
2239 "[ by <who> <access> [ <control> ] ]+ \n";
2242 "<what> ::= * | [dn[.<dnstyle>]=<DN>] [filter=<filter>] [attrs=<attrlist>]\n"
2243 "<attrlist> ::= <attr> [val[/matchingRule][.<attrstyle>]=<value>] | <attr> , <attrlist>\n"
2244 "<attr> ::= <attrname> | entry | children\n";
2247 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
2248 "\t[ realanonymous | realusers | realself | realdn[.<dnstyle>]=<DN> ]\n"
2249 "\t[dnattr=<attrname>]\n"
2250 "\t[realdnattr=<attrname>]\n"
2251 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
2252 "\t[peername[.<peernamestyle>]=<peer>] [sockname[.<style>]=<name>]\n"
2253 "\t[domain[.<domainstyle>]=<domain>] [sockurl[.<style>]=<url>]\n"
2255 "\t[dynacl/<name>[/<options>][.<dynstyle>][=<pattern>]]\n"
2256 #else /* ! SLAP_DYNACL */
2257 #ifdef SLAPD_ACI_ENABLED
2258 "\t[aci[=<attrname>]]\n"
2259 #endif /* SLAPD_ACI_ENABLED */
2260 #endif /* ! SLAP_DYNACL */
2261 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
2262 "<style> ::= exact | regex | base(Object)\n"
2263 "<dnstyle> ::= base(Object) | one(level) | sub(tree) | children | "
2265 "<attrstyle> ::= exact | regex | base(Object) | one(level) | "
2266 "sub(tree) | children\n"
2267 "<peernamestyle> ::= exact | regex | ip | path\n"
2268 "<domainstyle> ::= exact | regex | base(Object) | sub(tree)\n"
2269 "<access> ::= [[real]self]{<level>|<priv>}\n"
2270 "<level> ::= none|disclose|auth|compare|search|read|{write|add|delete}|manage\n"
2271 "<priv> ::= {=|+|-}{0|d|x|c|s|r|{w|a|z}|m}+\n"
2272 "<control> ::= [ stop | continue | break ]\n"
2274 #ifdef SLAPD_ACI_ENABLED
2276 "\t<name>=ACI\t<pattern>=<attrname>\n"
2277 #endif /* SLAPD_ACI_ENABLED */
2278 #endif /* ! SLAP_DYNACL */
2281 Debug( LDAP_DEBUG_ANY, "%s%s%s\n", access, who, what );
2282 exit( EXIT_FAILURE );
2286 * Set pattern to a "normalized" DN from src.
2287 * At present it simply eats the (optional) space after
2288 * a RDN separator (,)
2289 * Eventually will evolve in a more complete normalization
2292 acl_regex_normalized_dn(
2294 struct berval *pattern )
2299 str = ch_strdup( src );
2300 len = strlen( src );
2302 for ( p = str; p && p[0]; p++ ) {
2304 if ( p[0] == '\\' && p[1] ) {
2306 * if escaping a hex pair we should
2307 * increment p twice; however, in that
2308 * case the second hex number does
2314 if ( p[0] == ',' && p[1] == ' ' ) {
2318 * too much space should be an error if we are pedantic
2320 for ( q = &p[2]; q[0] == ' '; q++ ) {
2323 AC_MEMCPY( p+1, q, len-(q-str)+1);
2326 pattern->bv_val = str;
2327 pattern->bv_len = p - str;
2340 if ( (*right = strchr( line, splitchar )) != NULL ) {
2341 *((*right)++) = '\0';
2346 access_append( Access **l, Access *a )
2348 for ( ; *l != NULL; l = &(*l)->a_next ) {
2356 acl_append( AccessControl **l, AccessControl *a, int pos )
2360 for (i=0 ; i != pos && *l != NULL; l = &(*l)->acl_next, i++ ) {
2369 access_free( Access *a )
2371 if ( !BER_BVISNULL( &a->a_dn_pat ) ) {
2372 free( a->a_dn_pat.bv_val );
2374 if ( !BER_BVISNULL( &a->a_realdn_pat ) ) {
2375 free( a->a_realdn_pat.bv_val );
2377 if ( !BER_BVISNULL( &a->a_peername_pat ) ) {
2378 free( a->a_peername_pat.bv_val );
2380 if ( !BER_BVISNULL( &a->a_sockname_pat ) ) {
2381 free( a->a_sockname_pat.bv_val );
2383 if ( !BER_BVISNULL( &a->a_domain_pat ) ) {
2384 free( a->a_domain_pat.bv_val );
2386 if ( !BER_BVISNULL( &a->a_sockurl_pat ) ) {
2387 free( a->a_sockurl_pat.bv_val );
2389 if ( !BER_BVISNULL( &a->a_set_pat ) ) {
2390 free( a->a_set_pat.bv_val );
2392 if ( !BER_BVISNULL( &a->a_group_pat ) ) {
2393 free( a->a_group_pat.bv_val );
2396 if ( a->a_dynacl != NULL ) {
2398 for ( da = a->a_dynacl; da; ) {
2399 slap_dynacl_t *tmp = da;
2403 if ( tmp->da_destroy ) {
2404 tmp->da_destroy( tmp->da_private );
2410 #endif /* SLAP_DYNACL */
2415 acl_free( AccessControl *a )
2420 if ( a->acl_filter ) {
2421 filter_free( a->acl_filter );
2423 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2424 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
2425 regfree( &a->acl_dn_re );
2427 free ( a->acl_dn_pat.bv_val );
2429 if ( a->acl_attrs ) {
2430 for ( an = a->acl_attrs; !BER_BVISNULL( &an->an_name ); an++ ) {
2431 free( an->an_name.bv_val );
2433 free( a->acl_attrs );
2435 for ( ; a->acl_access; a->acl_access = n ) {
2436 n = a->acl_access->a_next;
2437 access_free( a->acl_access );
2442 /* Because backend_startup uses acl_append to tack on the global_acl to
2443 * the end of each backend's acl, we cannot just take one argument and
2444 * merrily free our way to the end of the list. backend_destroy calls us
2445 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
2446 * point. config_destroy calls us with global_acl in arg1 and NULL in
2447 * arg2, so we then proceed to polish off the global_acl.
2450 acl_destroy( AccessControl *a, AccessControl *end )
2454 for ( ; a && a != end; a = n ) {
2461 access2str( slap_access_t access )
2463 if ( access == ACL_NONE ) {
2466 } else if ( access == ACL_DISCLOSE ) {
2469 } else if ( access == ACL_AUTH ) {
2472 } else if ( access == ACL_COMPARE ) {
2475 } else if ( access == ACL_SEARCH ) {
2478 } else if ( access == ACL_READ ) {
2481 } else if ( access == ACL_WRITE ) {
2484 } else if ( access == ACL_WADD ) {
2487 } else if ( access == ACL_WDEL ) {
2490 } else if ( access == ACL_MANAGE ) {
2499 str2access( const char *str )
2501 if ( strcasecmp( str, "none" ) == 0 ) {
2504 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2505 #ifndef SLAP_ACL_HONOR_DISCLOSE
2506 Debug( LDAP_DEBUG_ACL, "str2access: warning, "
2507 "\"disclose\" privilege disabled.\n",
2509 #endif /* SLAP_ACL_HONOR_DISCLOSE */
2510 return ACL_DISCLOSE;
2512 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2515 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2518 } else if ( strcasecmp( str, "search" ) == 0 ) {
2521 } else if ( strcasecmp( str, "read" ) == 0 ) {
2524 } else if ( strcasecmp( str, "write" ) == 0 ) {
2527 } else if ( strcasecmp( str, "add" ) == 0 ) {
2530 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2533 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2537 return( ACL_INVALID_ACCESS );
2540 #define ACLBUF_MAXLEN 8192
2542 static char aclbuf[ACLBUF_MAXLEN];
2545 dnaccess2text( slap_dn_access *bdn, char *ptr, int is_realdn )
2550 ptr = lutil_strcopy( ptr, "real" );
2553 if ( ber_bvccmp( &bdn->a_pat, '*' ) ||
2554 bdn->a_style == ACL_STYLE_ANONYMOUS ||
2555 bdn->a_style == ACL_STYLE_USERS ||
2556 bdn->a_style == ACL_STYLE_SELF )
2559 assert( ! ber_bvccmp( &bdn->a_pat, '*' ) );
2562 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2563 if ( bdn->a_style == ACL_STYLE_SELF && bdn->a_self_level != 0 ) {
2564 int n = sprintf( ptr, ".level{%d}", bdn->a_self_level );
2571 ptr = lutil_strcopy( ptr, "dn." );
2572 if ( bdn->a_style == ACL_STYLE_BASE )
2573 ptr = lutil_strcopy( ptr, style_base );
2575 ptr = lutil_strcopy( ptr, style_strings[bdn->a_style] );
2576 if ( bdn->a_style == ACL_STYLE_LEVEL ) {
2577 int n = sprintf( ptr, "{%d}", bdn->a_level );
2582 if ( bdn->a_expand ) {
2583 ptr = lutil_strcopy( ptr, ",expand" );
2587 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2594 access2text( Access *b, char *ptr )
2596 char maskbuf[ACCESSMASK_MAXLEN];
2598 ptr = lutil_strcopy( ptr, "\tby" );
2600 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
2601 ptr = dnaccess2text( &b->a_dn, ptr, 0 );
2604 ptr = lutil_strcopy( ptr, " dnattr=" );
2605 ptr = lutil_strcopy( ptr, b->a_dn_at->ad_cname.bv_val );
2608 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
2609 ptr = dnaccess2text( &b->a_realdn, ptr, 1 );
2611 if ( b->a_realdn_at ) {
2612 ptr = lutil_strcopy( ptr, " realdnattr=" );
2613 ptr = lutil_strcopy( ptr, b->a_realdn_at->ad_cname.bv_val );
2616 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
2617 ptr = lutil_strcopy( ptr, " group/" );
2618 ptr = lutil_strcopy( ptr, b->a_group_oc ?
2619 b->a_group_oc->soc_cname.bv_val : SLAPD_GROUP_CLASS );
2621 ptr = lutil_strcopy( ptr, b->a_group_at ?
2622 b->a_group_at->ad_cname.bv_val : SLAPD_GROUP_ATTR );
2624 ptr = lutil_strcopy( ptr, style_strings[b->a_group_style] );
2627 ptr = lutil_strcopy( ptr, b->a_group_pat.bv_val );
2631 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
2632 ptr = lutil_strcopy( ptr, " peername" );
2634 ptr = lutil_strcopy( ptr, style_strings[b->a_peername_style] );
2637 ptr = lutil_strcopy( ptr, b->a_peername_pat.bv_val );
2641 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
2642 ptr = lutil_strcopy( ptr, " sockname" );
2644 ptr = lutil_strcopy( ptr, style_strings[b->a_sockname_style] );
2647 ptr = lutil_strcopy( ptr, b->a_sockname_pat.bv_val );
2651 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
2652 ptr = lutil_strcopy( ptr, " domain" );
2654 ptr = lutil_strcopy( ptr, style_strings[b->a_domain_style] );
2655 if ( b->a_domain_expand ) {
2656 ptr = lutil_strcopy( ptr, ",expand" );
2659 ptr = lutil_strcopy( ptr, b->a_domain_pat.bv_val );
2662 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
2663 ptr = lutil_strcopy( ptr, " sockurl" );
2665 ptr = lutil_strcopy( ptr, style_strings[b->a_sockurl_style] );
2668 ptr = lutil_strcopy( ptr, b->a_sockurl_pat.bv_val );
2672 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
2673 ptr = lutil_strcopy( ptr, " set" );
2675 ptr = lutil_strcopy( ptr, style_strings[b->a_set_style] );
2678 ptr = lutil_strcopy( ptr, b->a_set_pat.bv_val );
2683 if ( b->a_dynacl ) {
2686 for ( da = b->a_dynacl; da; da = da->da_next ) {
2687 if ( da->da_unparse ) {
2688 struct berval bv = BER_BVNULL;
2689 (void)( *da->da_unparse )( da->da_private, &bv );
2690 assert( !BER_BVISNULL( &bv ) );
2691 ptr = lutil_strcopy( ptr, bv.bv_val );
2692 ch_free( bv.bv_val );
2696 #else /* ! SLAP_DYNACL */
2697 #ifdef SLAPD_ACI_ENABLED
2698 if ( b->a_aci_at != NULL ) {
2699 ptr = lutil_strcopy( ptr, " aci=" );
2700 ptr = lutil_strcopy( ptr, b->a_aci_at->ad_cname.bv_val );
2703 #endif /* SLAP_DYNACL */
2705 /* Security Strength Factors */
2706 if ( b->a_authz.sai_ssf ) {
2707 ptr += sprintf( ptr, " ssf=%u",
2708 b->a_authz.sai_ssf );
2710 if ( b->a_authz.sai_transport_ssf ) {
2711 ptr += sprintf( ptr, " transport_ssf=%u",
2712 b->a_authz.sai_transport_ssf );
2714 if ( b->a_authz.sai_tls_ssf ) {
2715 ptr += sprintf( ptr, " tls_ssf=%u",
2716 b->a_authz.sai_tls_ssf );
2718 if ( b->a_authz.sai_sasl_ssf ) {
2719 ptr += sprintf( ptr, " sasl_ssf=%u",
2720 b->a_authz.sai_sasl_ssf );
2724 if ( b->a_dn_self ) {
2725 ptr = lutil_strcopy( ptr, "self" );
2726 } else if ( b->a_realdn_self ) {
2727 ptr = lutil_strcopy( ptr, "realself" );
2729 ptr = lutil_strcopy( ptr, accessmask2str( b->a_access_mask, maskbuf, 0 ));
2730 if ( !maskbuf[0] ) ptr--;
2732 if( b->a_type == ACL_BREAK ) {
2733 ptr = lutil_strcopy( ptr, " break" );
2735 } else if( b->a_type == ACL_CONTINUE ) {
2736 ptr = lutil_strcopy( ptr, " continue" );
2738 } else if( b->a_type != ACL_STOP ) {
2739 ptr = lutil_strcopy( ptr, " unknown-control" );
2741 if ( !maskbuf[0] ) ptr = lutil_strcopy( ptr, " stop" );
2749 acl_unparse( AccessControl *a, struct berval *bv )
2755 bv->bv_val = aclbuf;
2760 ptr = lutil_strcopy( ptr, "to" );
2761 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2763 ptr = lutil_strcopy( ptr, " dn." );
2764 if ( a->acl_dn_style == ACL_STYLE_BASE )
2765 ptr = lutil_strcopy( ptr, style_base );
2767 ptr = lutil_strcopy( ptr, style_strings[a->acl_dn_style] );
2770 ptr = lutil_strcopy( ptr, a->acl_dn_pat.bv_val );
2771 ptr = lutil_strcopy( ptr, "\"\n" );
2774 if ( a->acl_filter != NULL ) {
2775 struct berval bv = BER_BVNULL;
2778 filter2bv( a->acl_filter, &bv );
2779 ptr = lutil_strcopy( ptr, " filter=\"" );
2780 ptr = lutil_strcopy( ptr, bv.bv_val );
2783 ch_free( bv.bv_val );
2786 if ( a->acl_attrs != NULL ) {
2791 ptr = lutil_strcopy( ptr, " attrs=" );
2792 for ( an = a->acl_attrs; an && !BER_BVISNULL( &an->an_name ); an++ ) {
2793 if ( ! first ) *ptr++ = ',';
2795 *ptr++ = an->an_oc_exclude ? '!' : '@';
2796 ptr = lutil_strcopy( ptr, an->an_oc->soc_cname.bv_val );
2799 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2806 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
2808 ptr = lutil_strcopy( ptr, " val." );
2809 if ( a->acl_attrval_style == ACL_STYLE_BASE &&
2810 a->acl_attrs[0].an_desc->ad_type->sat_syntax ==
2811 slap_schema.si_syn_distinguishedName )
2812 ptr = lutil_strcopy( ptr, style_base );
2814 ptr = lutil_strcopy( ptr, style_strings[a->acl_attrval_style] );
2817 ptr = lutil_strcopy( ptr, a->acl_attrval.bv_val );
2823 ptr = lutil_strcopy( ptr, " *\n" );
2826 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
2827 ptr = access2text( b, ptr );
2830 bv->bv_len = ptr - bv->bv_val;
2835 print_acl( Backend *be, AccessControl *a )
2839 acl_unparse( a, &bv );
2840 fprintf( stderr, "%s ACL: access %s\n",
2841 be == NULL ? "Global" : "Backend", bv.bv_val );
2843 #endif /* LDAP_DEBUG */