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 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, *next;
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 ) {
480 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
481 Debug( LDAP_DEBUG_ANY,
482 "%s: line %d: attr val already specified in to clause.\n",
486 if ( a->acl_attrs == NULL || !BER_BVISEMPTY( &a->acl_attrs[1].an_name ) )
488 Debug( LDAP_DEBUG_ANY,
489 "%s: line %d: attr val requires a single attribute.\n",
494 ber_str2bv( right, 0, 1, &a->acl_attrval );
495 a->acl_attrval_style = ACL_STYLE_BASE;
497 mr = strchr( left, '/' );
502 a->acl_attrval_mr = mr_find( mr );
503 if ( a->acl_attrval_mr == NULL ) {
504 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
505 "invalid matching rule \"%s\".\n",
510 if( !mr_usable_with_at( a->acl_attrval_mr, a->acl_attrs[ 0 ].an_desc->ad_type ) )
512 char buf[ SLAP_TEXT_BUFLEN ];
514 snprintf( buf, sizeof( buf ),
515 "matching rule \"%s\" use "
516 "with attr \"%s\" not appropriate.",
517 mr, a->acl_attrs[ 0 ].an_name.bv_val );
520 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
521 fname, lineno, buf );
526 if ( style != NULL ) {
527 if ( strcasecmp( style, "regex" ) == 0 ) {
528 int e = regcomp( &a->acl_attrval_re, a->acl_attrval.bv_val,
529 REG_EXTENDED | REG_ICASE | REG_NOSUB );
531 char err[SLAP_TEXT_BUFLEN],
532 buf[ SLAP_TEXT_BUFLEN ];
534 regerror( e, &a->acl_attrval_re, err, sizeof( err ) );
536 snprintf( buf, sizeof( buf ),
537 "regular expression \"%s\" bad because of %s",
540 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
541 fname, lineno, buf );
544 a->acl_attrval_style = ACL_STYLE_REGEX;
547 /* FIXME: if the attribute has DN syntax, we might
548 * allow one, subtree and children styles as well */
549 if ( !strcasecmp( style, "base" ) ||
550 !strcasecmp( style, "exact" ) ) {
551 a->acl_attrval_style = ACL_STYLE_BASE;
553 } else if ( a->acl_attrs[0].an_desc->ad_type->
554 sat_syntax == slap_schema.si_syn_distinguishedName )
558 if ( !strcasecmp( style, "baseObject" ) ||
559 !strcasecmp( style, "base" ) )
561 a->acl_attrval_style = ACL_STYLE_BASE;
562 } else if ( !strcasecmp( style, "onelevel" ) ||
563 !strcasecmp( style, "one" ) )
565 a->acl_attrval_style = ACL_STYLE_ONE;
566 } else if ( !strcasecmp( style, "subtree" ) ||
567 !strcasecmp( style, "sub" ) )
569 a->acl_attrval_style = ACL_STYLE_SUBTREE;
570 } else if ( !strcasecmp( style, "children" ) ) {
571 a->acl_attrval_style = ACL_STYLE_CHILDREN;
573 char buf[ SLAP_TEXT_BUFLEN ];
575 /* FIXME: should be an error */
577 snprintf( buf, sizeof( buf ),
578 "unknown val.<style> \"%s\" "
579 "for attributeType \"%s\" with DN syntax; "
581 SLAPD_CONF_UNKNOWN_IGNORED ".",
583 a->acl_attrs[0].an_desc->ad_cname.bv_val );
585 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
587 fname, lineno, buf );
588 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
590 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
591 a->acl_attrval_style = ACL_STYLE_BASE;
595 rc = dnNormalize( 0, NULL, NULL, &bv, &a->acl_attrval, NULL );
596 if ( rc != LDAP_SUCCESS ) {
597 char buf[ SLAP_TEXT_BUFLEN ];
599 snprintf( buf, sizeof( buf ),
600 "unable to normalize DN \"%s\" "
601 "for attributeType \"%s\" (%d).",
603 a->acl_attrs[0].an_desc->ad_cname.bv_val,
605 Debug( LDAP_DEBUG_ANY,
607 fname, lineno, buf );
610 ber_memfree( bv.bv_val );
613 char buf[ SLAP_TEXT_BUFLEN ];
615 /* FIXME: should be an error */
617 snprintf( buf, sizeof( buf ),
618 "unknown val.<style> \"%s\" "
619 "for attributeType \"%s\"; using \"exact\""
620 SLAPD_CONF_UNKNOWN_IGNORED ".",
621 style, a->acl_attrs[0].an_desc->ad_cname.bv_val );
622 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
624 fname, lineno, buf );
625 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
627 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
628 a->acl_attrval_style = ACL_STYLE_BASE;
633 /* Check for appropriate matching rule */
634 if ( a->acl_attrval_style != ACL_STYLE_REGEX ) {
635 if ( a->acl_attrval_mr == NULL ) {
636 a->acl_attrval_mr = a->acl_attrs[ 0 ].an_desc->ad_type->sat_equality;
639 if ( a->acl_attrval_mr == NULL ) {
640 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
641 "attr \"%s\" must have an EQUALITY matching rule.\n",
642 fname, lineno, a->acl_attrs[ 0 ].an_name.bv_val );
648 Debug( LDAP_DEBUG_ANY,
649 "%s: line %d: expecting <what> got \"%s\"\n",
650 fname, lineno, left );
655 if ( !BER_BVISNULL( &a->acl_dn_pat ) &&
656 ber_bvccmp( &a->acl_dn_pat, '*' ) )
658 free( a->acl_dn_pat.bv_val );
659 BER_BVZERO( &a->acl_dn_pat );
660 a->acl_dn_style = ACL_STYLE_REGEX;
663 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
664 a->acl_dn_style != ACL_STYLE_REGEX )
666 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
668 rc = dnNormalize( 0, NULL, NULL, &a->acl_dn_pat, &bv, NULL);
669 if ( rc != LDAP_SUCCESS ) {
670 Debug( LDAP_DEBUG_ANY,
671 "%s: line %d: bad DN \"%s\" in to DN clause\n",
672 fname, lineno, a->acl_dn_pat.bv_val );
675 free( a->acl_dn_pat.bv_val );
679 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
680 REG_EXTENDED | REG_ICASE );
682 char err[ SLAP_TEXT_BUFLEN ],
683 buf[ SLAP_TEXT_BUFLEN ];
685 regerror( e, &a->acl_dn_re, err, sizeof( err ) );
686 snprintf( buf, sizeof( buf ),
687 "regular expression \"%s\" bad because of %s",
689 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
690 fname, lineno, buf );
696 /* by clause - select who has what access to entries */
697 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
699 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
700 "to clause required before by clause in access line\n",
706 * by clause consists of <who> and <access>
709 b = (Access *) ch_calloc( 1, sizeof(Access) );
711 ACL_INVALIDATE( b->a_access_mask );
714 Debug( LDAP_DEBUG_ANY,
715 "%s: line %d: premature EOL: expecting <who>\n",
721 for ( ; i < argc; i++ ) {
722 slap_style_t sty = ACL_STYLE_REGEX;
723 char *style_modifier = NULL;
724 char *style_level = NULL;
727 slap_dn_access *bdn = &b->a_dn;
730 split( argv[i], '=', &left, &right );
731 split( left, '.', &left, &style );
733 split( style, ',', &style, &style_modifier );
735 if ( strncasecmp( style, "level", STRLENOF( "level" ) ) == 0 ) {
736 split( style, '{', &style, &style_level );
737 if ( style_level != NULL ) {
738 char *p = strchr( style_level, '}' );
740 Debug( LDAP_DEBUG_ANY,
741 "%s: line %d: premature eol: "
742 "expecting closing '}' in \"level{n}\"\n",
745 } else if ( p == style_level ) {
746 Debug( LDAP_DEBUG_ANY,
747 "%s: line %d: empty level "
757 if ( style == NULL || *style == '\0' ||
758 strcasecmp( style, "exact" ) == 0 ||
759 strcasecmp( style, "baseObject" ) == 0 ||
760 strcasecmp( style, "base" ) == 0 )
762 sty = ACL_STYLE_BASE;
764 } else if ( strcasecmp( style, "onelevel" ) == 0 ||
765 strcasecmp( style, "one" ) == 0 )
769 } else if ( strcasecmp( style, "subtree" ) == 0 ||
770 strcasecmp( style, "sub" ) == 0 )
772 sty = ACL_STYLE_SUBTREE;
774 } else if ( strcasecmp( style, "children" ) == 0 ) {
775 sty = ACL_STYLE_CHILDREN;
777 } else if ( strcasecmp( style, "level" ) == 0 )
781 if ( lutil_atoi( &level, style_level ) != 0 ) {
782 Debug( LDAP_DEBUG_ANY,
783 "%s: line %d: unable to parse level "
789 sty = ACL_STYLE_LEVEL;
791 } else if ( strcasecmp( style, "regex" ) == 0 ) {
792 sty = ACL_STYLE_REGEX;
794 } else if ( strcasecmp( style, "expand" ) == 0 ) {
795 sty = ACL_STYLE_EXPAND;
797 } else if ( strcasecmp( style, "ip" ) == 0 ) {
800 } else if ( strcasecmp( style, "path" ) == 0 ) {
801 sty = ACL_STYLE_PATH;
802 #ifndef LDAP_PF_LOCAL
803 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
805 "\"path\" style modifier is useless without local"
806 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
808 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
810 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
811 #endif /* LDAP_PF_LOCAL */
814 Debug( LDAP_DEBUG_ANY,
815 "%s: line %d: unknown style \"%s\" in by clause\n",
816 fname, lineno, style );
820 if ( style_modifier &&
821 strcasecmp( style_modifier, "expand" ) == 0 )
824 case ACL_STYLE_REGEX:
825 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
826 "\"regex\" style implies "
827 "\"expand\" modifier"
828 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
830 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
832 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
835 case ACL_STYLE_EXPAND:
839 /* we'll see later if it's pertinent */
845 /* expand in <who> needs regex in <what> */
846 if ( ( sty == ACL_STYLE_EXPAND || expand )
847 && a->acl_dn_style != ACL_STYLE_REGEX )
849 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL, "%s: line %d: "
850 "\"expand\" style or modifier used "
851 "in conjunction with "
852 "a non-regex <what> clause"
853 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
855 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
857 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
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,
1014 "%s: line %d: \"expand\" used "
1015 "with no expansions in \"pattern\""
1016 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1018 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1020 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1023 if ( sty == ACL_STYLE_SELF ) {
1024 bdn->a_self_level = level;
1028 Debug( LDAP_DEBUG_ANY,
1029 "%s: line %d: bad negative level \"%d\" "
1030 "in by DN clause\n",
1031 fname, lineno, level );
1033 } else if ( level == 1 ) {
1034 Debug( LDAP_DEBUG_ANY,
1035 "%s: line %d: \"onelevel\" should be used "
1036 "instead of \"level{1}\" in by DN clause\n",
1038 } else if ( level == 0 && sty == ACL_STYLE_LEVEL ) {
1039 Debug( LDAP_DEBUG_ANY,
1040 "%s: line %d: \"base\" should be used "
1041 "instead of \"level{0}\" in by DN clause\n",
1045 bdn->a_level = level;
1050 if ( strcasecmp( left, "dnattr" ) == 0 ) {
1051 if ( right == NULL || right[0] == '\0' ) {
1052 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1053 "missing \"=\" in (or value after) \"%s\" "
1055 fname, lineno, left );
1059 if( bdn->a_at != NULL ) {
1060 Debug( LDAP_DEBUG_ANY,
1061 "%s: line %d: dnattr already specified.\n",
1066 rc = slap_str2ad( right, &bdn->a_at, &text );
1068 if( rc != LDAP_SUCCESS ) {
1069 char buf[ SLAP_TEXT_BUFLEN ];
1071 snprintf( buf, sizeof( buf ),
1072 "dnattr \"%s\": %s",
1074 Debug( LDAP_DEBUG_ANY,
1075 "%s: line %d: %s\n",
1076 fname, lineno, buf );
1081 if( !is_at_syntax( bdn->a_at->ad_type,
1082 SLAPD_DN_SYNTAX ) &&
1083 !is_at_syntax( bdn->a_at->ad_type,
1084 SLAPD_NAMEUID_SYNTAX ))
1086 char buf[ SLAP_TEXT_BUFLEN ];
1088 snprintf( buf, sizeof( buf ),
1090 "inappropriate syntax: %s\n",
1092 bdn->a_at->ad_type->sat_syntax_oid );
1093 Debug( LDAP_DEBUG_ANY,
1094 "%s: line %d: %s\n",
1095 fname, lineno, buf );
1099 if( bdn->a_at->ad_type->sat_equality == NULL ) {
1100 Debug( LDAP_DEBUG_ANY,
1101 "%s: line %d: dnattr \"%s\": "
1102 "inappropriate matching (no EQUALITY)\n",
1103 fname, lineno, right );
1110 if ( strncasecmp( left, "group", STRLENOF( "group" ) ) == 0 ) {
1115 case ACL_STYLE_REGEX:
1116 /* legacy, tolerated */
1117 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
1119 "deprecated group style \"regex\"; "
1120 "use \"expand\" instead.\n",
1122 sty = ACL_STYLE_EXPAND;
1125 case ACL_STYLE_BASE:
1126 /* legal, traditional */
1127 case ACL_STYLE_EXPAND:
1128 /* legal, substring expansion; supersedes regex */
1133 Debug( LDAP_DEBUG_ANY,
1135 "inappropriate style \"%s\" in by clause.\n",
1136 fname, lineno, style );
1140 if ( right == NULL || right[0] == '\0' ) {
1141 Debug( LDAP_DEBUG_ANY,
1143 "missing \"=\" in (or value after) \"%s\" "
1145 fname, lineno, left );
1149 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1150 Debug( LDAP_DEBUG_ANY,
1151 "%s: line %d: group pattern already specified.\n",
1156 /* format of string is
1157 "group/objectClassValue/groupAttrName" */
1158 if ( ( value = strchr(left, '/') ) != NULL ) {
1160 if ( *value && ( name = strchr( value, '/' ) ) != NULL ) {
1165 b->a_group_style = sty;
1166 if ( sty == ACL_STYLE_EXPAND ) {
1167 acl_regex_normalized_dn( right, &bv );
1168 if ( !ber_bvccmp( &bv, '*' ) ) {
1169 regtest( fname, lineno, bv.bv_val );
1171 b->a_group_pat = bv;
1174 ber_str2bv( right, 0, 0, &bv );
1175 rc = dnNormalize( 0, NULL, NULL, &bv,
1176 &b->a_group_pat, NULL );
1177 if ( rc != LDAP_SUCCESS ) {
1178 Debug( LDAP_DEBUG_ANY,
1179 "%s: line %d: bad DN \"%s\".\n",
1180 fname, lineno, right );
1185 if ( value && *value ) {
1186 b->a_group_oc = oc_find( value );
1189 if ( b->a_group_oc == NULL ) {
1190 Debug( LDAP_DEBUG_ANY,
1191 "%s: line %d: group objectclass "
1192 "\"%s\" unknown.\n",
1193 fname, lineno, value );
1198 b->a_group_oc = oc_find( SLAPD_GROUP_CLASS );
1200 if( b->a_group_oc == NULL ) {
1201 Debug( LDAP_DEBUG_ANY,
1202 "%s: line %d: group default objectclass "
1203 "\"%s\" unknown.\n",
1204 fname, lineno, SLAPD_GROUP_CLASS );
1209 if ( is_object_subclass( slap_schema.si_oc_referral,
1212 Debug( LDAP_DEBUG_ANY,
1213 "%s: line %d: group objectclass \"%s\" "
1214 "is subclass of referral.\n",
1215 fname, lineno, value );
1219 if ( is_object_subclass( slap_schema.si_oc_alias,
1222 Debug( LDAP_DEBUG_ANY,
1223 "%s: line %d: group objectclass \"%s\" "
1224 "is subclass of alias.\n",
1225 fname, lineno, value );
1229 if ( name && *name ) {
1230 rc = slap_str2ad( name, &b->a_group_at, &text );
1232 if( rc != LDAP_SUCCESS ) {
1233 char buf[ SLAP_TEXT_BUFLEN ];
1235 snprintf( buf, sizeof( buf ),
1236 "group \"%s\": %s.",
1238 Debug( LDAP_DEBUG_ANY,
1239 "%s: line %d: %s\n",
1240 fname, lineno, buf );
1246 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
1248 if ( rc != LDAP_SUCCESS ) {
1249 char buf[ SLAP_TEXT_BUFLEN ];
1251 snprintf( buf, sizeof( buf ),
1252 "group \"%s\": %s.",
1253 SLAPD_GROUP_ATTR, text );
1254 Debug( LDAP_DEBUG_ANY,
1255 "%s: line %d: %s\n",
1256 fname, lineno, buf );
1261 if ( !is_at_syntax( b->a_group_at->ad_type,
1262 SLAPD_DN_SYNTAX ) &&
1263 !is_at_syntax( b->a_group_at->ad_type,
1264 SLAPD_NAMEUID_SYNTAX ) &&
1265 !is_at_subtype( b->a_group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ) )
1267 char buf[ SLAP_TEXT_BUFLEN ];
1269 snprintf( buf, sizeof( buf ),
1270 "group \"%s\": inappropriate syntax: %s.",
1272 b->a_group_at->ad_type->sat_syntax_oid );
1273 Debug( LDAP_DEBUG_ANY,
1274 "%s: line %d: %s\n",
1275 fname, lineno, buf );
1282 struct berval vals[2];
1284 ber_str2bv( b->a_group_oc->soc_oid, 0, 0, &vals[0] );
1285 BER_BVZERO( &vals[1] );
1287 rc = oc_check_allowed( b->a_group_at->ad_type,
1291 char buf[ SLAP_TEXT_BUFLEN ];
1293 snprintf( buf, sizeof( buf ),
1294 "group: \"%s\" not allowed by \"%s\".",
1295 b->a_group_at->ad_cname.bv_val,
1296 b->a_group_oc->soc_oid );
1297 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
1298 fname, lineno, buf );
1305 if ( strcasecmp( left, "peername" ) == 0 ) {
1307 case ACL_STYLE_REGEX:
1308 case ACL_STYLE_BASE:
1309 /* legal, traditional */
1310 case ACL_STYLE_EXPAND:
1311 /* cheap replacement to regex for simple expansion */
1313 case ACL_STYLE_PATH:
1314 /* legal, peername specific */
1318 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1319 "inappropriate style \"%s\" in by clause.\n",
1320 fname, lineno, style );
1324 if ( right == NULL || right[0] == '\0' ) {
1325 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1326 "missing \"=\" in (or value after) \"%s\" "
1328 fname, lineno, left );
1332 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1333 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1334 "peername pattern already specified.\n",
1339 b->a_peername_style = sty;
1340 if ( sty == ACL_STYLE_REGEX ) {
1341 acl_regex_normalized_dn( right, &bv );
1342 if ( !ber_bvccmp( &bv, '*' ) ) {
1343 regtest( fname, lineno, bv.bv_val );
1345 b->a_peername_pat = bv;
1348 ber_str2bv( right, 0, 1, &b->a_peername_pat );
1350 if ( sty == ACL_STYLE_IP ) {
1355 split( right, '{', &addr, &port );
1356 split( addr, '%', &addr, &mask );
1358 b->a_peername_addr = inet_addr( addr );
1359 if ( b->a_peername_addr == (unsigned long)(-1) ) {
1360 /* illegal address */
1361 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1362 "illegal peername address \"%s\".\n",
1363 fname, lineno, addr );
1367 b->a_peername_mask = (unsigned long)(-1);
1368 if ( mask != NULL ) {
1369 b->a_peername_mask = inet_addr( mask );
1370 if ( b->a_peername_mask ==
1371 (unsigned long)(-1) )
1374 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1375 "illegal peername address mask "
1377 fname, lineno, mask );
1382 b->a_peername_port = -1;
1386 b->a_peername_port = strtol( port, &end, 10 );
1387 if ( end == port || end[0] != '}' ) {
1389 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1390 "illegal peername port specification "
1392 fname, lineno, port );
1401 if ( strcasecmp( left, "sockname" ) == 0 ) {
1403 case ACL_STYLE_REGEX:
1404 case ACL_STYLE_BASE:
1405 /* legal, traditional */
1406 case ACL_STYLE_EXPAND:
1407 /* cheap replacement to regex for simple expansion */
1412 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1413 "inappropriate style \"%s\" in by clause\n",
1414 fname, lineno, style );
1418 if ( right == NULL || right[0] == '\0' ) {
1419 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1420 "missing \"=\" in (or value after) \"%s\" "
1422 fname, lineno, left );
1426 if ( !BER_BVISNULL( &b->a_sockname_pat ) ) {
1427 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1428 "sockname pattern already specified.\n",
1433 b->a_sockname_style = sty;
1434 if ( sty == ACL_STYLE_REGEX ) {
1435 acl_regex_normalized_dn( right, &bv );
1436 if ( !ber_bvccmp( &bv, '*' ) ) {
1437 regtest( fname, lineno, bv.bv_val );
1439 b->a_sockname_pat = bv;
1442 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
1447 if ( strcasecmp( left, "domain" ) == 0 ) {
1449 case ACL_STYLE_REGEX:
1450 case ACL_STYLE_BASE:
1451 case ACL_STYLE_SUBTREE:
1452 /* legal, traditional */
1455 case ACL_STYLE_EXPAND:
1456 /* tolerated: means exact,expand */
1458 Debug( LDAP_DEBUG_ANY,
1460 "\"expand\" modifier "
1461 "with \"expand\" style.\n",
1464 sty = ACL_STYLE_BASE;
1470 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1471 "inappropriate style \"%s\" in by clause.\n",
1472 fname, lineno, style );
1476 if ( right == NULL || right[0] == '\0' ) {
1477 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1478 "missing \"=\" in (or value after) \"%s\" "
1480 fname, lineno, left );
1484 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1485 Debug( LDAP_DEBUG_ANY,
1486 "%s: line %d: domain pattern already specified.\n",
1491 b->a_domain_style = sty;
1492 b->a_domain_expand = expand;
1493 if ( sty == ACL_STYLE_REGEX ) {
1494 acl_regex_normalized_dn( right, &bv );
1495 if ( !ber_bvccmp( &bv, '*' ) ) {
1496 regtest( fname, lineno, bv.bv_val );
1498 b->a_domain_pat = bv;
1501 ber_str2bv( right, 0, 1, &b->a_domain_pat );
1506 if ( strcasecmp( left, "sockurl" ) == 0 ) {
1508 case ACL_STYLE_REGEX:
1509 case ACL_STYLE_BASE:
1510 /* legal, traditional */
1511 case ACL_STYLE_EXPAND:
1512 /* cheap replacement to regex for simple expansion */
1517 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1518 "inappropriate style \"%s\" in by clause.\n",
1519 fname, lineno, style );
1523 if ( right == NULL || right[0] == '\0' ) {
1524 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1525 "missing \"=\" in (or value after) \"%s\" "
1527 fname, lineno, left );
1531 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1532 Debug( LDAP_DEBUG_ANY,
1533 "%s: line %d: sockurl pattern already specified.\n",
1538 b->a_sockurl_style = sty;
1539 if ( sty == ACL_STYLE_REGEX ) {
1540 acl_regex_normalized_dn( right, &bv );
1541 if ( !ber_bvccmp( &bv, '*' ) ) {
1542 regtest( fname, lineno, bv.bv_val );
1544 b->a_sockurl_pat = bv;
1547 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
1552 if ( strcasecmp( left, "set" ) == 0 ) {
1555 case ACL_STYLE_REGEX:
1556 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
1558 "deprecated set style "
1559 "\"regex\" in <by> clause; "
1560 "use \"expand\" instead.\n",
1562 sty = ACL_STYLE_EXPAND;
1565 case ACL_STYLE_BASE:
1566 case ACL_STYLE_EXPAND:
1570 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1571 "inappropriate style \"%s\" in by clause.\n",
1572 fname, lineno, style );
1576 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1577 Debug( LDAP_DEBUG_ANY,
1578 "%s: line %d: set attribute already specified.\n",
1583 if ( right == NULL || *right == '\0' ) {
1584 Debug( LDAP_DEBUG_ANY,
1585 "%s: line %d: no set is defined.\n",
1590 b->a_set_style = sty;
1591 ber_str2bv( right, 0, 1, &b->a_set_pat );
1601 if ( strcasecmp( left, "aci" ) == 0 ) {
1604 } else if ( strncasecmp( left, "dynacl/", STRLENOF( "dynacl/" ) ) == 0 ) {
1605 name = &left[ STRLENOF( "dynacl/" ) ];
1606 opts = strchr( name, '/' );
1614 if ( slap_dynacl_config( fname, lineno, b, name, opts, sty, right ) ) {
1615 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1616 "unable to configure dynacl \"%s\".\n",
1617 fname, lineno, name );
1624 #else /* ! SLAP_DYNACL */
1626 #ifdef SLAPD_ACI_ENABLED
1627 if ( strcasecmp( left, "aci" ) == 0 ) {
1628 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1629 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1630 "inappropriate style \"%s\" in by clause.\n",
1631 fname, lineno, style );
1635 if( b->a_aci_at != NULL ) {
1636 Debug( LDAP_DEBUG_ANY,
1637 "%s: line %d: ACI attribute already specified.\n",
1642 if ( right != NULL && *right != '\0' ) {
1643 rc = slap_str2ad( right, &b->a_aci_at, &text );
1645 if( rc != LDAP_SUCCESS ) {
1646 char buf[ SLAP_TEXT_BUFLEN ];
1648 snprintf( buf, sizeof( buf ),
1651 Debug( LDAP_DEBUG_ANY,
1652 "%s: line %d: %s\n",
1653 fname, lineno, buf );
1658 b->a_aci_at = slap_ad_aci;
1661 if( !is_at_syntax( b->a_aci_at->ad_type,
1664 char buf[ SLAP_TEXT_BUFLEN ];
1666 snprintf( buf, sizeof( buf ),
1667 "ACI \"%s\": inappropriate syntax: %s.",
1669 b->a_aci_at->ad_type->sat_syntax_oid );
1670 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
1671 fname, lineno, buf );
1677 #endif /* SLAPD_ACI_ENABLED */
1678 #endif /* ! SLAP_DYNACL */
1680 if ( strcasecmp( left, "ssf" ) == 0 ) {
1681 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1682 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1683 "inappropriate style \"%s\" in by clause.\n",
1684 fname, lineno, style );
1688 if ( b->a_authz.sai_ssf ) {
1689 Debug( LDAP_DEBUG_ANY,
1690 "%s: line %d: ssf attribute already specified.\n",
1695 if ( right == NULL || *right == '\0' ) {
1696 Debug( LDAP_DEBUG_ANY,
1697 "%s: line %d: no ssf is defined.\n",
1702 if ( lutil_atou( &b->a_authz.sai_ssf, right ) != 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 if ( lutil_atou( &b->a_authz.sai_transport_ssf, right ) != 0 ) {
1741 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1742 "unable to parse transport_ssf value (%s).\n",
1743 fname, lineno, right );
1747 if ( !b->a_authz.sai_transport_ssf ) {
1748 Debug( LDAP_DEBUG_ANY,
1749 "%s: line %d: invalid transport_ssf value (%s).\n",
1750 fname, lineno, right );
1756 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
1757 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1758 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1759 "inappropriate style \"%s\" in by clause.\n",
1760 fname, lineno, style );
1764 if ( b->a_authz.sai_tls_ssf ) {
1765 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1766 "tls_ssf attribute already specified.\n",
1771 if ( right == NULL || *right == '\0' ) {
1772 Debug( LDAP_DEBUG_ANY,
1773 "%s: line %d: no tls_ssf is defined\n",
1778 if ( lutil_atou( &b->a_authz.sai_tls_ssf, right ) != 0 ) {
1779 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1780 "unable to parse tls_ssf value (%s).\n",
1781 fname, lineno, right );
1785 if ( !b->a_authz.sai_tls_ssf ) {
1786 Debug( LDAP_DEBUG_ANY,
1787 "%s: line %d: invalid tls_ssf value (%s).\n",
1788 fname, lineno, right );
1794 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1795 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1796 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1797 "inappropriate style \"%s\" in by clause.\n",
1798 fname, lineno, style );
1802 if ( b->a_authz.sai_sasl_ssf ) {
1803 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1804 "sasl_ssf attribute already specified.\n",
1809 if ( right == NULL || *right == '\0' ) {
1810 Debug( LDAP_DEBUG_ANY,
1811 "%s: line %d: no sasl_ssf is defined.\n",
1816 if ( lutil_atou( &b->a_authz.sai_sasl_ssf, right ) != 0 ) {
1817 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1818 "unable to parse sasl_ssf value (%s).\n",
1819 fname, lineno, right );
1823 if ( !b->a_authz.sai_sasl_ssf ) {
1824 Debug( LDAP_DEBUG_ANY,
1825 "%s: line %d: invalid sasl_ssf value (%s).\n",
1826 fname, lineno, right );
1832 if ( right != NULL ) {
1839 if ( i == argc || ( strcasecmp( left, "stop" ) == 0 ) ) {
1840 /* out of arguments or plain stop */
1842 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1843 b->a_type = ACL_STOP;
1845 access_append( &a->acl_access, b );
1849 if ( strcasecmp( left, "continue" ) == 0 ) {
1850 /* plain continue */
1852 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1853 b->a_type = ACL_CONTINUE;
1855 access_append( &a->acl_access, b );
1859 if ( strcasecmp( left, "break" ) == 0 ) {
1860 /* plain continue */
1862 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1863 b->a_type = ACL_BREAK;
1865 access_append( &a->acl_access, b );
1869 if ( strcasecmp( left, "by" ) == 0 ) {
1870 /* we've gone too far */
1872 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1873 b->a_type = ACL_STOP;
1875 access_append( &a->acl_access, b );
1880 if ( strncasecmp( left, "self", STRLENOF( "self" ) ) == 0 ) {
1882 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "self" ) ] ) );
1884 } else if ( strncasecmp( left, "realself", STRLENOF( "realself" ) ) == 0 ) {
1885 b->a_realdn_self = 1;
1886 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "realself" ) ] ) );
1889 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1892 if ( ACL_IS_INVALID( b->a_access_mask ) ) {
1893 Debug( LDAP_DEBUG_ANY,
1894 "%s: line %d: expecting <access> got \"%s\".\n",
1895 fname, lineno, left );
1899 b->a_type = ACL_STOP;
1901 if ( ++i == argc ) {
1902 /* out of arguments or plain stop */
1903 access_append( &a->acl_access, b );
1907 if ( strcasecmp( argv[i], "continue" ) == 0 ) {
1908 /* plain continue */
1909 b->a_type = ACL_CONTINUE;
1911 } else if ( strcasecmp( argv[i], "break" ) == 0 ) {
1912 /* plain continue */
1913 b->a_type = ACL_BREAK;
1915 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1920 access_append( &a->acl_access, b );
1923 Debug( LDAP_DEBUG_ANY,
1924 "%s: line %d: expecting \"to\" "
1925 "or \"by\" got \"%s\"\n",
1926 fname, lineno, argv[i] );
1931 /* if we have no real access clause, complain and do nothing */
1933 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1934 "warning: no access clause(s) "
1935 "specified in access line"
1936 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1938 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1940 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1944 if ( ldap_debug & LDAP_DEBUG_ACL ) {
1949 if ( a->acl_access == NULL ) {
1950 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1951 "warning: no by clause(s) "
1952 "specified in access line"
1953 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1955 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1957 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1961 if ( !BER_BVISNULL( &be->be_nsuffix[ 1 ] ) ) {
1962 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1963 "scope checking only applies to single-valued "
1964 "suffix databases\n",
1966 /* go ahead, since checking is not authoritative */
1969 switch ( check_scope( be, a ) ) {
1970 case ACL_SCOPE_UNKNOWN:
1971 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1972 "cannot assess the validity of the ACL scope within "
1973 "backend naming context\n",
1977 case ACL_SCOPE_WARN:
1978 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1979 "ACL could be out of scope within backend naming context\n",
1983 case ACL_SCOPE_PARTIAL:
1984 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1985 "ACL appears to be partially out of scope within "
1986 "backend naming context\n",
1991 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1992 "ACL appears to be out of scope within "
1993 "backend naming context\n",
2000 acl_append( &be->be_acl, a, pos );
2003 acl_append( &frontendDB->be_acl, a, pos );
2011 accessmask2str( slap_mask_t mask, char *buf, int debug )
2016 assert( buf != NULL );
2018 if ( ACL_IS_INVALID( mask ) ) {
2024 if ( ACL_IS_LEVEL( mask ) ) {
2025 if ( ACL_LVL_IS_NONE(mask) ) {
2026 ptr = lutil_strcopy( ptr, "none" );
2028 } else if ( ACL_LVL_IS_DISCLOSE(mask) ) {
2029 ptr = lutil_strcopy( ptr, "disclose" );
2031 } else if ( ACL_LVL_IS_AUTH(mask) ) {
2032 ptr = lutil_strcopy( ptr, "auth" );
2034 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
2035 ptr = lutil_strcopy( ptr, "compare" );
2037 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
2038 ptr = lutil_strcopy( ptr, "search" );
2040 } else if ( ACL_LVL_IS_READ(mask) ) {
2041 ptr = lutil_strcopy( ptr, "read" );
2043 } else if ( ACL_LVL_IS_WRITE(mask) ) {
2044 ptr = lutil_strcopy( ptr, "write" );
2046 } else if ( ACL_LVL_IS_WADD(mask) ) {
2047 ptr = lutil_strcopy( ptr, "add" );
2049 } else if ( ACL_LVL_IS_WDEL(mask) ) {
2050 ptr = lutil_strcopy( ptr, "delete" );
2052 } else if ( ACL_LVL_IS_MANAGE(mask) ) {
2053 ptr = lutil_strcopy( ptr, "manage" );
2056 ptr = lutil_strcopy( ptr, "unknown" );
2066 if( ACL_IS_ADDITIVE( mask ) ) {
2069 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
2076 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_MANAGE) ) {
2081 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
2085 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WADD) ) {
2089 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WDEL) ) {
2094 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
2099 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
2104 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
2109 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
2114 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_DISCLOSE) ) {
2119 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
2128 if ( ACL_IS_LEVEL( mask ) ) {
2138 str2accessmask( const char *str )
2142 if( !ASCII_ALPHA(str[0]) ) {
2145 if ( str[0] == '=' ) {
2148 } else if( str[0] == '+' ) {
2149 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
2151 } else if( str[0] == '-' ) {
2152 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
2155 ACL_INVALIDATE(mask);
2159 for( i=1; str[i] != '\0'; i++ ) {
2160 if( TOLOWER((unsigned char) str[i]) == 'm' ) {
2161 ACL_PRIV_SET(mask, ACL_PRIV_MANAGE);
2163 } else if( TOLOWER((unsigned char) str[i]) == 'w' ) {
2164 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
2166 } else if( TOLOWER((unsigned char) str[i]) == 'a' ) {
2167 ACL_PRIV_SET(mask, ACL_PRIV_WADD);
2169 } else if( TOLOWER((unsigned char) str[i]) == 'z' ) {
2170 ACL_PRIV_SET(mask, ACL_PRIV_WDEL);
2172 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
2173 ACL_PRIV_SET(mask, ACL_PRIV_READ);
2175 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
2176 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
2178 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
2179 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
2181 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
2182 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
2184 } else if( TOLOWER((unsigned char) str[i]) == 'd' ) {
2185 ACL_PRIV_SET(mask, ACL_PRIV_DISCLOSE);
2187 } else if( str[i] != '0' ) {
2188 ACL_INVALIDATE(mask);
2196 if ( strcasecmp( str, "none" ) == 0 ) {
2197 ACL_LVL_ASSIGN_NONE(mask);
2199 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2200 ACL_LVL_ASSIGN_DISCLOSE(mask);
2202 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2203 ACL_LVL_ASSIGN_AUTH(mask);
2205 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2206 ACL_LVL_ASSIGN_COMPARE(mask);
2208 } else if ( strcasecmp( str, "search" ) == 0 ) {
2209 ACL_LVL_ASSIGN_SEARCH(mask);
2211 } else if ( strcasecmp( str, "read" ) == 0 ) {
2212 ACL_LVL_ASSIGN_READ(mask);
2214 } else if ( strcasecmp( str, "add" ) == 0 ) {
2215 ACL_LVL_ASSIGN_WADD(mask);
2217 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2218 ACL_LVL_ASSIGN_WDEL(mask);
2220 } else if ( strcasecmp( str, "write" ) == 0 ) {
2221 ACL_LVL_ASSIGN_WRITE(mask);
2223 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2224 ACL_LVL_ASSIGN_MANAGE(mask);
2227 ACL_INVALIDATE( mask );
2237 "<access clause> ::= access to <what> "
2238 "[ by <who> <access> [ <control> ] ]+ \n";
2240 "<what> ::= * | [dn[.<dnstyle>]=<DN>] [filter=<filter>] [attrs=<attrspec>]\n"
2241 "<attrspec> ::= <attrname> [val[/<matchingRule>][.<attrstyle>]=<value>] | <attrlist>\n"
2242 "<attrlist> ::= <attr> [ , <attrlist> ]\n"
2243 "<attr> ::= <attrname> | @<objectClass> | !<objectClass> | entry | children\n";
2246 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
2247 "\t[ realanonymous | realusers | realself | realdn[.<dnstyle>]=<DN> ]\n"
2248 "\t[dnattr=<attrname>]\n"
2249 "\t[realdnattr=<attrname>]\n"
2250 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
2251 "\t[peername[.<peernamestyle>]=<peer>] [sockname[.<style>]=<name>]\n"
2252 "\t[domain[.<domainstyle>]=<domain>] [sockurl[.<style>]=<url>]\n"
2254 "\t[dynacl/<name>[/<options>][.<dynstyle>][=<pattern>]]\n"
2255 #else /* ! SLAP_DYNACL */
2256 #ifdef SLAPD_ACI_ENABLED
2257 "\t[aci[=<attrname>]]\n"
2258 #endif /* SLAPD_ACI_ENABLED */
2259 #endif /* ! SLAP_DYNACL */
2260 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
2261 "<style> ::= exact | regex | base(Object)\n"
2262 "<dnstyle> ::= base(Object) | one(level) | sub(tree) | children | "
2264 "<attrstyle> ::= exact | regex | base(Object) | one(level) | "
2265 "sub(tree) | children\n"
2266 "<peernamestyle> ::= exact | regex | ip | path\n"
2267 "<domainstyle> ::= exact | regex | base(Object) | sub(tree)\n"
2268 "<access> ::= [[real]self]{<level>|<priv>}\n"
2269 "<level> ::= none|disclose|auth|compare|search|read|{write|add|delete}|manage\n"
2270 "<priv> ::= {=|+|-}{0|d|x|c|s|r|{w|a|z}|m}+\n"
2271 "<control> ::= [ stop | continue | break ]\n"
2273 #ifdef SLAPD_ACI_ENABLED
2275 "\t<name>=ACI\t<pattern>=<attrname>\n"
2276 #endif /* SLAPD_ACI_ENABLED */
2277 #endif /* ! SLAP_DYNACL */
2280 Debug( LDAP_DEBUG_ANY, "%s%s%s\n", access, what, who );
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 */