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 level = strtol( style_level, &next, 10 );
782 if ( next[0] != '\0' ) {
783 Debug( LDAP_DEBUG_ANY,
784 "%s: line %d: unable to parse level "
790 sty = ACL_STYLE_LEVEL;
792 } else if ( strcasecmp( style, "regex" ) == 0 ) {
793 sty = ACL_STYLE_REGEX;
795 } else if ( strcasecmp( style, "expand" ) == 0 ) {
796 sty = ACL_STYLE_EXPAND;
798 } else if ( strcasecmp( style, "ip" ) == 0 ) {
801 } else if ( strcasecmp( style, "path" ) == 0 ) {
802 sty = ACL_STYLE_PATH;
803 #ifndef LDAP_PF_LOCAL
804 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
806 "\"path\" style modifier is useless without local"
807 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
809 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
811 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
812 #endif /* LDAP_PF_LOCAL */
815 Debug( LDAP_DEBUG_ANY,
816 "%s: line %d: unknown style \"%s\" in by clause\n",
817 fname, lineno, style );
821 if ( style_modifier &&
822 strcasecmp( style_modifier, "expand" ) == 0 )
825 case ACL_STYLE_REGEX:
826 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
827 "\"regex\" style implies "
828 "\"expand\" modifier"
829 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
831 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
833 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
836 case ACL_STYLE_EXPAND:
840 /* we'll see later if it's pertinent */
846 /* expand in <who> needs regex in <what> */
847 if ( ( sty == ACL_STYLE_EXPAND || expand )
848 && a->acl_dn_style != ACL_STYLE_REGEX )
850 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL, "%s: line %d: "
851 "\"expand\" style or modifier used "
852 "in conjunction with "
853 "a non-regex <what> clause"
854 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
856 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
858 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
861 if ( strncasecmp( left, "real", STRLENOF( "real" ) ) == 0 ) {
864 left += STRLENOF( "real" );
867 if ( strcasecmp( left, "*" ) == 0 ) {
872 ber_str2bv( "*", STRLENOF( "*" ), 1, &bv );
873 sty = ACL_STYLE_REGEX;
875 } else if ( strcasecmp( left, "anonymous" ) == 0 ) {
876 ber_str2bv("anonymous", STRLENOF( "anonymous" ), 1, &bv);
877 sty = ACL_STYLE_ANONYMOUS;
879 } else if ( strcasecmp( left, "users" ) == 0 ) {
880 ber_str2bv("users", STRLENOF( "users" ), 1, &bv);
881 sty = ACL_STYLE_USERS;
883 } else if ( strcasecmp( left, "self" ) == 0 ) {
884 ber_str2bv("self", STRLENOF( "self" ), 1, &bv);
885 sty = ACL_STYLE_SELF;
887 } else if ( strcasecmp( left, "dn" ) == 0 ) {
888 if ( sty == ACL_STYLE_REGEX ) {
889 bdn->a_style = ACL_STYLE_REGEX;
890 if ( right == NULL ) {
895 bdn->a_style = ACL_STYLE_USERS;
897 } else if (*right == '\0' ) {
899 ber_str2bv("anonymous",
900 STRLENOF( "anonymous" ),
902 bdn->a_style = ACL_STYLE_ANONYMOUS;
904 } else if ( strcmp( right, "*" ) == 0 ) {
906 /* any or users? users for now */
910 bdn->a_style = ACL_STYLE_USERS;
912 } else if ( strcmp( right, ".+" ) == 0
913 || strcmp( right, "^.+" ) == 0
914 || strcmp( right, ".+$" ) == 0
915 || strcmp( right, "^.+$" ) == 0
916 || strcmp( right, ".+$$" ) == 0
917 || strcmp( right, "^.+$$" ) == 0 )
922 bdn->a_style = ACL_STYLE_USERS;
924 } else if ( strcmp( right, ".*" ) == 0
925 || strcmp( right, "^.*" ) == 0
926 || strcmp( right, ".*$" ) == 0
927 || strcmp( right, "^.*$" ) == 0
928 || strcmp( right, ".*$$" ) == 0
929 || strcmp( right, "^.*$$" ) == 0 )
936 acl_regex_normalized_dn( right, &bv );
937 if ( !ber_bvccmp( &bv, '*' ) ) {
938 regtest( fname, lineno, bv.bv_val );
942 } else if ( right == NULL || *right == '\0' ) {
943 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
944 "missing \"=\" in (or value after) \"%s\" "
946 fname, lineno, left );
950 ber_str2bv( right, 0, 1, &bv );
957 if ( !BER_BVISNULL( &bv ) ) {
958 if ( !BER_BVISEMPTY( &bdn->a_pat ) ) {
959 Debug( LDAP_DEBUG_ANY,
960 "%s: line %d: dn pattern already specified.\n",
965 if ( sty != ACL_STYLE_REGEX &&
966 sty != ACL_STYLE_ANONYMOUS &&
967 sty != ACL_STYLE_USERS &&
968 sty != ACL_STYLE_SELF &&
971 rc = dnNormalize(0, NULL, NULL,
972 &bv, &bdn->a_pat, NULL);
973 if ( rc != LDAP_SUCCESS ) {
974 Debug( LDAP_DEBUG_ANY,
975 "%s: line %d: bad DN \"%s\" in by DN clause\n",
976 fname, lineno, bv.bv_val );
980 if ( sty == ACL_STYLE_BASE
982 && !BER_BVISNULL( &be->be_rootndn )
983 && dn_match( &bdn->a_pat, &be->be_rootndn ) )
985 Debug( LDAP_DEBUG_ANY,
986 "%s: line %d: rootdn is always granted "
987 "unlimited privileges.\n",
999 for ( exp = strchr( bdn->a_pat.bv_val, '$' );
1000 exp && (ber_len_t)(exp - bdn->a_pat.bv_val)
1001 < bdn->a_pat.bv_len;
1002 exp = strchr( exp, '$' ) )
1004 if ( isdigit( exp[ 1 ] ) ) {
1011 bdn->a_expand = expand;
1014 Debug( LDAP_DEBUG_ANY,
1015 "%s: line %d: \"expand\" used "
1016 "with no expansions in \"pattern\""
1017 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1019 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1021 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1024 if ( sty == ACL_STYLE_SELF ) {
1025 bdn->a_self_level = level;
1029 Debug( LDAP_DEBUG_ANY,
1030 "%s: line %d: bad negative level \"%d\" "
1031 "in by DN clause\n",
1032 fname, lineno, level );
1034 } else if ( level == 1 ) {
1035 Debug( LDAP_DEBUG_ANY,
1036 "%s: line %d: \"onelevel\" should be used "
1037 "instead of \"level{1}\" in by DN clause\n",
1039 } else if ( level == 0 && sty == ACL_STYLE_LEVEL ) {
1040 Debug( LDAP_DEBUG_ANY,
1041 "%s: line %d: \"base\" should be used "
1042 "instead of \"level{0}\" in by DN clause\n",
1046 bdn->a_level = level;
1051 if ( strcasecmp( left, "dnattr" ) == 0 ) {
1052 if ( right == NULL || right[0] == '\0' ) {
1053 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1054 "missing \"=\" in (or value after) \"%s\" "
1056 fname, lineno, left );
1060 if( bdn->a_at != NULL ) {
1061 Debug( LDAP_DEBUG_ANY,
1062 "%s: line %d: dnattr already specified.\n",
1067 rc = slap_str2ad( right, &bdn->a_at, &text );
1069 if( rc != LDAP_SUCCESS ) {
1070 char buf[ SLAP_TEXT_BUFLEN ];
1072 snprintf( buf, sizeof( buf ),
1073 "dnattr \"%s\": %s",
1075 Debug( LDAP_DEBUG_ANY,
1076 "%s: line %d: %s\n",
1077 fname, lineno, buf );
1082 if( !is_at_syntax( bdn->a_at->ad_type,
1083 SLAPD_DN_SYNTAX ) &&
1084 !is_at_syntax( bdn->a_at->ad_type,
1085 SLAPD_NAMEUID_SYNTAX ))
1087 char buf[ SLAP_TEXT_BUFLEN ];
1089 snprintf( buf, sizeof( buf ),
1091 "inappropriate syntax: %s\n",
1093 bdn->a_at->ad_type->sat_syntax_oid );
1094 Debug( LDAP_DEBUG_ANY,
1095 "%s: line %d: %s\n",
1096 fname, lineno, buf );
1100 if( bdn->a_at->ad_type->sat_equality == NULL ) {
1101 Debug( LDAP_DEBUG_ANY,
1102 "%s: line %d: dnattr \"%s\": "
1103 "inappropriate matching (no EQUALITY)\n",
1104 fname, lineno, right );
1111 if ( strncasecmp( left, "group", STRLENOF( "group" ) ) == 0 ) {
1116 case ACL_STYLE_REGEX:
1117 /* legacy, tolerated */
1118 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
1120 "deprecated group style \"regex\"; "
1121 "use \"expand\" instead.\n",
1123 sty = ACL_STYLE_EXPAND;
1126 case ACL_STYLE_BASE:
1127 /* legal, traditional */
1128 case ACL_STYLE_EXPAND:
1129 /* legal, substring expansion; supersedes regex */
1134 Debug( LDAP_DEBUG_ANY,
1136 "inappropriate style \"%s\" in by clause.\n",
1137 fname, lineno, style );
1141 if ( right == NULL || right[0] == '\0' ) {
1142 Debug( LDAP_DEBUG_ANY,
1144 "missing \"=\" in (or value after) \"%s\" "
1146 fname, lineno, left );
1150 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1151 Debug( LDAP_DEBUG_ANY,
1152 "%s: line %d: group pattern already specified.\n",
1157 /* format of string is
1158 "group/objectClassValue/groupAttrName" */
1159 if ( ( value = strchr(left, '/') ) != NULL ) {
1161 if ( *value && ( name = strchr( value, '/' ) ) != NULL ) {
1166 b->a_group_style = sty;
1167 if ( sty == ACL_STYLE_EXPAND ) {
1168 acl_regex_normalized_dn( right, &bv );
1169 if ( !ber_bvccmp( &bv, '*' ) ) {
1170 regtest( fname, lineno, bv.bv_val );
1172 b->a_group_pat = bv;
1175 ber_str2bv( right, 0, 0, &bv );
1176 rc = dnNormalize( 0, NULL, NULL, &bv,
1177 &b->a_group_pat, NULL );
1178 if ( rc != LDAP_SUCCESS ) {
1179 Debug( LDAP_DEBUG_ANY,
1180 "%s: line %d: bad DN \"%s\".\n",
1181 fname, lineno, right );
1186 if ( value && *value ) {
1187 b->a_group_oc = oc_find( value );
1190 if ( b->a_group_oc == NULL ) {
1191 Debug( LDAP_DEBUG_ANY,
1192 "%s: line %d: group objectclass "
1193 "\"%s\" unknown.\n",
1194 fname, lineno, value );
1199 b->a_group_oc = oc_find( SLAPD_GROUP_CLASS );
1201 if( b->a_group_oc == NULL ) {
1202 Debug( LDAP_DEBUG_ANY,
1203 "%s: line %d: group default objectclass "
1204 "\"%s\" unknown.\n",
1205 fname, lineno, SLAPD_GROUP_CLASS );
1210 if ( is_object_subclass( slap_schema.si_oc_referral,
1213 Debug( LDAP_DEBUG_ANY,
1214 "%s: line %d: group objectclass \"%s\" "
1215 "is subclass of referral.\n",
1216 fname, lineno, value );
1220 if ( is_object_subclass( slap_schema.si_oc_alias,
1223 Debug( LDAP_DEBUG_ANY,
1224 "%s: line %d: group objectclass \"%s\" "
1225 "is subclass of alias.\n",
1226 fname, lineno, value );
1230 if ( name && *name ) {
1231 rc = slap_str2ad( name, &b->a_group_at, &text );
1233 if( rc != LDAP_SUCCESS ) {
1234 char buf[ SLAP_TEXT_BUFLEN ];
1236 snprintf( buf, sizeof( buf ),
1237 "group \"%s\": %s.",
1239 Debug( LDAP_DEBUG_ANY,
1240 "%s: line %d: %s\n",
1241 fname, lineno, buf );
1247 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
1249 if ( rc != LDAP_SUCCESS ) {
1250 char buf[ SLAP_TEXT_BUFLEN ];
1252 snprintf( buf, sizeof( buf ),
1253 "group \"%s\": %s.",
1254 SLAPD_GROUP_ATTR, text );
1255 Debug( LDAP_DEBUG_ANY,
1256 "%s: line %d: %s\n",
1257 fname, lineno, buf );
1262 if ( !is_at_syntax( b->a_group_at->ad_type,
1263 SLAPD_DN_SYNTAX ) &&
1264 !is_at_syntax( b->a_group_at->ad_type,
1265 SLAPD_NAMEUID_SYNTAX ) &&
1266 !is_at_subtype( b->a_group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ) )
1268 char buf[ SLAP_TEXT_BUFLEN ];
1270 snprintf( buf, sizeof( buf ),
1271 "group \"%s\": inappropriate syntax: %s.",
1273 b->a_group_at->ad_type->sat_syntax_oid );
1274 Debug( LDAP_DEBUG_ANY,
1275 "%s: line %d: %s\n",
1276 fname, lineno, buf );
1283 struct berval vals[2];
1285 ber_str2bv( b->a_group_oc->soc_oid, 0, 0, &vals[0] );
1286 BER_BVZERO( &vals[1] );
1288 rc = oc_check_allowed( b->a_group_at->ad_type,
1292 char buf[ SLAP_TEXT_BUFLEN ];
1294 snprintf( buf, sizeof( buf ),
1295 "group: \"%s\" not allowed by \"%s\".",
1296 b->a_group_at->ad_cname.bv_val,
1297 b->a_group_oc->soc_oid );
1298 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
1299 fname, lineno, buf );
1306 if ( strcasecmp( left, "peername" ) == 0 ) {
1308 case ACL_STYLE_REGEX:
1309 case ACL_STYLE_BASE:
1310 /* legal, traditional */
1311 case ACL_STYLE_EXPAND:
1312 /* cheap replacement to regex for simple expansion */
1314 case ACL_STYLE_PATH:
1315 /* legal, peername specific */
1319 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1320 "inappropriate style \"%s\" in by clause.\n",
1321 fname, lineno, style );
1325 if ( right == NULL || right[0] == '\0' ) {
1326 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1327 "missing \"=\" in (or value after) \"%s\" "
1329 fname, lineno, left );
1333 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1334 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1335 "peername pattern already specified.\n",
1340 b->a_peername_style = sty;
1341 if ( sty == ACL_STYLE_REGEX ) {
1342 acl_regex_normalized_dn( right, &bv );
1343 if ( !ber_bvccmp( &bv, '*' ) ) {
1344 regtest( fname, lineno, bv.bv_val );
1346 b->a_peername_pat = bv;
1349 ber_str2bv( right, 0, 1, &b->a_peername_pat );
1351 if ( sty == ACL_STYLE_IP ) {
1356 split( right, '{', &addr, &port );
1357 split( addr, '%', &addr, &mask );
1359 b->a_peername_addr = inet_addr( addr );
1360 if ( b->a_peername_addr == (unsigned long)(-1) ) {
1361 /* illegal address */
1362 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1363 "illegal peername address \"%s\".\n",
1364 fname, lineno, addr );
1368 b->a_peername_mask = (unsigned long)(-1);
1369 if ( mask != NULL ) {
1370 b->a_peername_mask = inet_addr( mask );
1371 if ( b->a_peername_mask ==
1372 (unsigned long)(-1) )
1375 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1376 "illegal peername address mask "
1378 fname, lineno, mask );
1383 b->a_peername_port = -1;
1387 b->a_peername_port = strtol( port, &end, 10 );
1388 if ( end[0] != '}' ) {
1390 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1391 "illegal peername port specification "
1393 fname, lineno, port );
1402 if ( strcasecmp( left, "sockname" ) == 0 ) {
1404 case ACL_STYLE_REGEX:
1405 case ACL_STYLE_BASE:
1406 /* legal, traditional */
1407 case ACL_STYLE_EXPAND:
1408 /* cheap replacement to regex for simple expansion */
1413 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1414 "inappropriate style \"%s\" in by clause\n",
1415 fname, lineno, style );
1419 if ( right == NULL || right[0] == '\0' ) {
1420 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1421 "missing \"=\" in (or value after) \"%s\" "
1423 fname, lineno, left );
1427 if ( !BER_BVISNULL( &b->a_sockname_pat ) ) {
1428 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1429 "sockname pattern already specified.\n",
1434 b->a_sockname_style = sty;
1435 if ( sty == ACL_STYLE_REGEX ) {
1436 acl_regex_normalized_dn( right, &bv );
1437 if ( !ber_bvccmp( &bv, '*' ) ) {
1438 regtest( fname, lineno, bv.bv_val );
1440 b->a_sockname_pat = bv;
1443 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
1448 if ( strcasecmp( left, "domain" ) == 0 ) {
1450 case ACL_STYLE_REGEX:
1451 case ACL_STYLE_BASE:
1452 case ACL_STYLE_SUBTREE:
1453 /* legal, traditional */
1456 case ACL_STYLE_EXPAND:
1457 /* tolerated: means exact,expand */
1459 Debug( LDAP_DEBUG_ANY,
1461 "\"expand\" modifier "
1462 "with \"expand\" style.\n",
1465 sty = ACL_STYLE_BASE;
1471 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1472 "inappropriate style \"%s\" in by clause.\n",
1473 fname, lineno, style );
1477 if ( right == NULL || right[0] == '\0' ) {
1478 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1479 "missing \"=\" in (or value after) \"%s\" "
1481 fname, lineno, left );
1485 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1486 Debug( LDAP_DEBUG_ANY,
1487 "%s: line %d: domain pattern already specified.\n",
1492 b->a_domain_style = sty;
1493 b->a_domain_expand = expand;
1494 if ( sty == ACL_STYLE_REGEX ) {
1495 acl_regex_normalized_dn( right, &bv );
1496 if ( !ber_bvccmp( &bv, '*' ) ) {
1497 regtest( fname, lineno, bv.bv_val );
1499 b->a_domain_pat = bv;
1502 ber_str2bv( right, 0, 1, &b->a_domain_pat );
1507 if ( strcasecmp( left, "sockurl" ) == 0 ) {
1509 case ACL_STYLE_REGEX:
1510 case ACL_STYLE_BASE:
1511 /* legal, traditional */
1512 case ACL_STYLE_EXPAND:
1513 /* cheap replacement to regex for simple expansion */
1518 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1519 "inappropriate style \"%s\" in by clause.\n",
1520 fname, lineno, style );
1524 if ( right == NULL || right[0] == '\0' ) {
1525 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1526 "missing \"=\" in (or value after) \"%s\" "
1528 fname, lineno, left );
1532 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1533 Debug( LDAP_DEBUG_ANY,
1534 "%s: line %d: sockurl pattern already specified.\n",
1539 b->a_sockurl_style = sty;
1540 if ( sty == ACL_STYLE_REGEX ) {
1541 acl_regex_normalized_dn( right, &bv );
1542 if ( !ber_bvccmp( &bv, '*' ) ) {
1543 regtest( fname, lineno, bv.bv_val );
1545 b->a_sockurl_pat = bv;
1548 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
1553 if ( strcasecmp( left, "set" ) == 0 ) {
1556 case ACL_STYLE_REGEX:
1557 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
1559 "deprecated set style "
1560 "\"regex\" in <by> clause; "
1561 "use \"expand\" instead.\n",
1563 sty = ACL_STYLE_EXPAND;
1566 case ACL_STYLE_BASE:
1567 case ACL_STYLE_EXPAND:
1571 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1572 "inappropriate style \"%s\" in by clause.\n",
1573 fname, lineno, style );
1577 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1578 Debug( LDAP_DEBUG_ANY,
1579 "%s: line %d: set attribute already specified.\n",
1584 if ( right == NULL || *right == '\0' ) {
1585 Debug( LDAP_DEBUG_ANY,
1586 "%s: line %d: no set is defined.\n",
1591 b->a_set_style = sty;
1592 ber_str2bv( right, 0, 1, &b->a_set_pat );
1602 if ( strcasecmp( left, "aci" ) == 0 ) {
1605 } else if ( strncasecmp( left, "dynacl/", STRLENOF( "dynacl/" ) ) == 0 ) {
1606 name = &left[ STRLENOF( "dynacl/" ) ];
1607 opts = strchr( name, '/' );
1615 if ( slap_dynacl_config( fname, lineno, b, name, opts, sty, right ) ) {
1616 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1617 "unable to configure dynacl \"%s\".\n",
1618 fname, lineno, name );
1625 #else /* ! SLAP_DYNACL */
1627 #ifdef SLAPD_ACI_ENABLED
1628 if ( strcasecmp( left, "aci" ) == 0 ) {
1629 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1630 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1631 "inappropriate style \"%s\" in by clause.\n",
1632 fname, lineno, style );
1636 if( b->a_aci_at != NULL ) {
1637 Debug( LDAP_DEBUG_ANY,
1638 "%s: line %d: ACI attribute already specified.\n",
1643 if ( right != NULL && *right != '\0' ) {
1644 rc = slap_str2ad( right, &b->a_aci_at, &text );
1646 if( rc != LDAP_SUCCESS ) {
1647 char buf[ SLAP_TEXT_BUFLEN ];
1649 snprintf( buf, sizeof( buf ),
1652 Debug( LDAP_DEBUG_ANY,
1653 "%s: line %d: %s\n",
1654 fname, lineno, buf );
1659 b->a_aci_at = slap_ad_aci;
1662 if( !is_at_syntax( b->a_aci_at->ad_type,
1665 char buf[ SLAP_TEXT_BUFLEN ];
1667 snprintf( buf, sizeof( buf ),
1668 "ACI \"%s\": inappropriate syntax: %s.",
1670 b->a_aci_at->ad_type->sat_syntax_oid );
1671 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
1672 fname, lineno, buf );
1678 #endif /* SLAPD_ACI_ENABLED */
1679 #endif /* ! SLAP_DYNACL */
1681 if ( strcasecmp( left, "ssf" ) == 0 ) {
1682 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1683 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1684 "inappropriate style \"%s\" in by clause.\n",
1685 fname, lineno, style );
1689 if ( b->a_authz.sai_ssf ) {
1690 Debug( LDAP_DEBUG_ANY,
1691 "%s: line %d: ssf attribute already specified.\n",
1696 if ( right == NULL || *right == '\0' ) {
1697 Debug( LDAP_DEBUG_ANY,
1698 "%s: line %d: no ssf is defined.\n",
1703 b->a_authz.sai_ssf = strtol( right, &next, 10 );
1704 if ( next == NULL || next[0] != '\0' ) {
1705 Debug( LDAP_DEBUG_ANY,
1706 "%s: line %d: unable to parse ssf value (%s).\n",
1707 fname, lineno, right );
1711 if ( !b->a_authz.sai_ssf ) {
1712 Debug( LDAP_DEBUG_ANY,
1713 "%s: line %d: invalid ssf value (%s).\n",
1714 fname, lineno, right );
1720 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
1721 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1722 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1723 "inappropriate style \"%s\" in by clause.\n",
1724 fname, lineno, style );
1728 if ( b->a_authz.sai_transport_ssf ) {
1729 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1730 "transport_ssf attribute already specified.\n",
1735 if ( right == NULL || *right == '\0' ) {
1736 Debug( LDAP_DEBUG_ANY,
1737 "%s: line %d: no transport_ssf is defined.\n",
1742 b->a_authz.sai_transport_ssf = strtol( right, &next, 10 );
1743 if ( next == NULL || next[0] != '\0' ) {
1744 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1745 "unable to parse transport_ssf value (%s).\n",
1746 fname, lineno, right );
1750 if ( !b->a_authz.sai_transport_ssf ) {
1751 Debug( LDAP_DEBUG_ANY,
1752 "%s: line %d: invalid transport_ssf value (%s).\n",
1753 fname, lineno, right );
1759 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
1760 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1761 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1762 "inappropriate style \"%s\" in by clause.\n",
1763 fname, lineno, style );
1767 if ( b->a_authz.sai_tls_ssf ) {
1768 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1769 "tls_ssf attribute already specified.\n",
1774 if ( right == NULL || *right == '\0' ) {
1775 Debug( LDAP_DEBUG_ANY,
1776 "%s: line %d: no tls_ssf is defined\n",
1781 b->a_authz.sai_tls_ssf = strtol( right, &next, 10 );
1782 if ( next == NULL || next[0] != '\0' ) {
1783 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1784 "unable to parse tls_ssf value (%s).\n",
1785 fname, lineno, right );
1789 if ( !b->a_authz.sai_tls_ssf ) {
1790 Debug( LDAP_DEBUG_ANY,
1791 "%s: line %d: invalid tls_ssf value (%s).\n",
1792 fname, lineno, right );
1798 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1799 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1800 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1801 "inappropriate style \"%s\" in by clause.\n",
1802 fname, lineno, style );
1806 if ( b->a_authz.sai_sasl_ssf ) {
1807 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1808 "sasl_ssf attribute already specified.\n",
1813 if ( right == NULL || *right == '\0' ) {
1814 Debug( LDAP_DEBUG_ANY,
1815 "%s: line %d: no sasl_ssf is defined.\n",
1820 b->a_authz.sai_sasl_ssf = strtol( right, &next, 10 );
1821 if ( next == NULL || next[0] != '\0' ) {
1822 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1823 "unable to parse sasl_ssf value (%s).\n",
1824 fname, lineno, right );
1828 if ( !b->a_authz.sai_sasl_ssf ) {
1829 Debug( LDAP_DEBUG_ANY,
1830 "%s: line %d: invalid sasl_ssf value (%s).\n",
1831 fname, lineno, right );
1837 if ( right != NULL ) {
1844 if ( i == argc || ( strcasecmp( left, "stop" ) == 0 ) ) {
1845 /* out of arguments or plain stop */
1847 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1848 b->a_type = ACL_STOP;
1850 access_append( &a->acl_access, b );
1854 if ( strcasecmp( left, "continue" ) == 0 ) {
1855 /* plain continue */
1857 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1858 b->a_type = ACL_CONTINUE;
1860 access_append( &a->acl_access, b );
1864 if ( strcasecmp( left, "break" ) == 0 ) {
1865 /* plain continue */
1867 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1868 b->a_type = ACL_BREAK;
1870 access_append( &a->acl_access, b );
1874 if ( strcasecmp( left, "by" ) == 0 ) {
1875 /* we've gone too far */
1877 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1878 b->a_type = ACL_STOP;
1880 access_append( &a->acl_access, b );
1885 if ( strncasecmp( left, "self", STRLENOF( "self" ) ) == 0 ) {
1887 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "self" ) ] ) );
1889 } else if ( strncasecmp( left, "realself", STRLENOF( "realself" ) ) == 0 ) {
1890 b->a_realdn_self = 1;
1891 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "realself" ) ] ) );
1894 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1897 if ( ACL_IS_INVALID( b->a_access_mask ) ) {
1898 Debug( LDAP_DEBUG_ANY,
1899 "%s: line %d: expecting <access> got \"%s\".\n",
1900 fname, lineno, left );
1904 b->a_type = ACL_STOP;
1906 if ( ++i == argc ) {
1907 /* out of arguments or plain stop */
1908 access_append( &a->acl_access, b );
1912 if ( strcasecmp( argv[i], "continue" ) == 0 ) {
1913 /* plain continue */
1914 b->a_type = ACL_CONTINUE;
1916 } else if ( strcasecmp( argv[i], "break" ) == 0 ) {
1917 /* plain continue */
1918 b->a_type = ACL_BREAK;
1920 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1925 access_append( &a->acl_access, b );
1928 Debug( LDAP_DEBUG_ANY,
1929 "%s: line %d: expecting \"to\" "
1930 "or \"by\" got \"%s\"\n",
1931 fname, lineno, argv[i] );
1936 /* if we have no real access clause, complain and do nothing */
1938 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1939 "warning: no access clause(s) "
1940 "specified in access line"
1941 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1943 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1945 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1949 if ( ldap_debug & LDAP_DEBUG_ACL ) {
1954 if ( a->acl_access == NULL ) {
1955 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1956 "warning: no by clause(s) "
1957 "specified in access line"
1958 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1960 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
1962 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
1966 if ( !BER_BVISNULL( &be->be_nsuffix[ 1 ] ) ) {
1967 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1968 "scope checking only applies to single-valued "
1969 "suffix databases\n",
1971 /* go ahead, since checking is not authoritative */
1974 switch ( check_scope( be, a ) ) {
1975 case ACL_SCOPE_UNKNOWN:
1976 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1977 "cannot assess the validity of the ACL scope within "
1978 "backend naming context\n",
1982 case ACL_SCOPE_WARN:
1983 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1984 "ACL could be out of scope within backend naming context\n",
1988 case ACL_SCOPE_PARTIAL:
1989 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1990 "ACL appears to be partially out of scope within "
1991 "backend naming context\n",
1996 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1997 "ACL appears to be out of scope within "
1998 "backend naming context\n",
2005 acl_append( &be->be_acl, a, pos );
2008 acl_append( &frontendDB->be_acl, a, pos );
2016 accessmask2str( slap_mask_t mask, char *buf, int debug )
2021 assert( buf != NULL );
2023 if ( ACL_IS_INVALID( mask ) ) {
2029 if ( ACL_IS_LEVEL( mask ) ) {
2030 if ( ACL_LVL_IS_NONE(mask) ) {
2031 ptr = lutil_strcopy( ptr, "none" );
2033 } else if ( ACL_LVL_IS_DISCLOSE(mask) ) {
2034 ptr = lutil_strcopy( ptr, "disclose" );
2036 } else if ( ACL_LVL_IS_AUTH(mask) ) {
2037 ptr = lutil_strcopy( ptr, "auth" );
2039 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
2040 ptr = lutil_strcopy( ptr, "compare" );
2042 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
2043 ptr = lutil_strcopy( ptr, "search" );
2045 } else if ( ACL_LVL_IS_READ(mask) ) {
2046 ptr = lutil_strcopy( ptr, "read" );
2048 } else if ( ACL_LVL_IS_WRITE(mask) ) {
2049 ptr = lutil_strcopy( ptr, "write" );
2051 } else if ( ACL_LVL_IS_WADD(mask) ) {
2052 ptr = lutil_strcopy( ptr, "add" );
2054 } else if ( ACL_LVL_IS_WDEL(mask) ) {
2055 ptr = lutil_strcopy( ptr, "delete" );
2057 } else if ( ACL_LVL_IS_MANAGE(mask) ) {
2058 ptr = lutil_strcopy( ptr, "manage" );
2061 ptr = lutil_strcopy( ptr, "unknown" );
2071 if( ACL_IS_ADDITIVE( mask ) ) {
2074 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
2081 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_MANAGE) ) {
2086 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
2090 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WADD) ) {
2094 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WDEL) ) {
2099 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
2104 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
2109 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
2114 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
2119 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_DISCLOSE) ) {
2124 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
2133 if ( ACL_IS_LEVEL( mask ) ) {
2143 str2accessmask( const char *str )
2147 if( !ASCII_ALPHA(str[0]) ) {
2150 if ( str[0] == '=' ) {
2153 } else if( str[0] == '+' ) {
2154 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
2156 } else if( str[0] == '-' ) {
2157 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
2160 ACL_INVALIDATE(mask);
2164 for( i=1; str[i] != '\0'; i++ ) {
2165 if( TOLOWER((unsigned char) str[i]) == 'm' ) {
2166 ACL_PRIV_SET(mask, ACL_PRIV_MANAGE);
2168 } else if( TOLOWER((unsigned char) str[i]) == 'w' ) {
2169 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
2171 } else if( TOLOWER((unsigned char) str[i]) == 'a' ) {
2172 ACL_PRIV_SET(mask, ACL_PRIV_WADD);
2174 } else if( TOLOWER((unsigned char) str[i]) == 'z' ) {
2175 ACL_PRIV_SET(mask, ACL_PRIV_WDEL);
2177 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
2178 ACL_PRIV_SET(mask, ACL_PRIV_READ);
2180 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
2181 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
2183 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
2184 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
2186 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
2187 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
2189 } else if( TOLOWER((unsigned char) str[i]) == 'd' ) {
2190 ACL_PRIV_SET(mask, ACL_PRIV_DISCLOSE);
2192 } else if( str[i] != '0' ) {
2193 ACL_INVALIDATE(mask);
2201 if ( strcasecmp( str, "none" ) == 0 ) {
2202 ACL_LVL_ASSIGN_NONE(mask);
2204 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2205 ACL_LVL_ASSIGN_DISCLOSE(mask);
2207 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2208 ACL_LVL_ASSIGN_AUTH(mask);
2210 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2211 ACL_LVL_ASSIGN_COMPARE(mask);
2213 } else if ( strcasecmp( str, "search" ) == 0 ) {
2214 ACL_LVL_ASSIGN_SEARCH(mask);
2216 } else if ( strcasecmp( str, "read" ) == 0 ) {
2217 ACL_LVL_ASSIGN_READ(mask);
2219 } else if ( strcasecmp( str, "add" ) == 0 ) {
2220 ACL_LVL_ASSIGN_WADD(mask);
2222 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2223 ACL_LVL_ASSIGN_WDEL(mask);
2225 } else if ( strcasecmp( str, "write" ) == 0 ) {
2226 ACL_LVL_ASSIGN_WRITE(mask);
2228 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2229 ACL_LVL_ASSIGN_MANAGE(mask);
2232 ACL_INVALIDATE( mask );
2242 "<access clause> ::= access to <what> "
2243 "[ by <who> <access> [ <control> ] ]+ \n";
2245 "<what> ::= * | [dn[.<dnstyle>]=<DN>] [filter=<filter>] [attrs=<attrspec>]\n"
2246 "<attrspec> ::= <attrname> [val[/<matchingRule>][.<attrstyle>]=<value>] | <attrlist>\n"
2247 "<attrlist> ::= <attr> [ , <attrlist> ]\n"
2248 "<attr> ::= <attrname> | @<objectClass> | !<objectClass> | entry | children\n";
2251 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
2252 "\t[ realanonymous | realusers | realself | realdn[.<dnstyle>]=<DN> ]\n"
2253 "\t[dnattr=<attrname>]\n"
2254 "\t[realdnattr=<attrname>]\n"
2255 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
2256 "\t[peername[.<peernamestyle>]=<peer>] [sockname[.<style>]=<name>]\n"
2257 "\t[domain[.<domainstyle>]=<domain>] [sockurl[.<style>]=<url>]\n"
2259 "\t[dynacl/<name>[/<options>][.<dynstyle>][=<pattern>]]\n"
2260 #else /* ! SLAP_DYNACL */
2261 #ifdef SLAPD_ACI_ENABLED
2262 "\t[aci[=<attrname>]]\n"
2263 #endif /* SLAPD_ACI_ENABLED */
2264 #endif /* ! SLAP_DYNACL */
2265 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
2266 "<style> ::= exact | regex | base(Object)\n"
2267 "<dnstyle> ::= base(Object) | one(level) | sub(tree) | children | "
2269 "<attrstyle> ::= exact | regex | base(Object) | one(level) | "
2270 "sub(tree) | children\n"
2271 "<peernamestyle> ::= exact | regex | ip | path\n"
2272 "<domainstyle> ::= exact | regex | base(Object) | sub(tree)\n"
2273 "<access> ::= [[real]self]{<level>|<priv>}\n"
2274 "<level> ::= none|disclose|auth|compare|search|read|{write|add|delete}|manage\n"
2275 "<priv> ::= {=|+|-}{0|d|x|c|s|r|{w|a|z}|m}+\n"
2276 "<control> ::= [ stop | continue | break ]\n"
2278 #ifdef SLAPD_ACI_ENABLED
2280 "\t<name>=ACI\t<pattern>=<attrname>\n"
2281 #endif /* SLAPD_ACI_ENABLED */
2282 #endif /* ! SLAP_DYNACL */
2285 Debug( LDAP_DEBUG_ANY, "%s%s%s\n", access, what, who );
2291 * Set pattern to a "normalized" DN from src.
2292 * At present it simply eats the (optional) space after
2293 * a RDN separator (,)
2294 * Eventually will evolve in a more complete normalization
2297 acl_regex_normalized_dn(
2299 struct berval *pattern )
2304 str = ch_strdup( src );
2305 len = strlen( src );
2307 for ( p = str; p && p[0]; p++ ) {
2309 if ( p[0] == '\\' && p[1] ) {
2311 * if escaping a hex pair we should
2312 * increment p twice; however, in that
2313 * case the second hex number does
2319 if ( p[0] == ',' && p[1] == ' ' ) {
2323 * too much space should be an error if we are pedantic
2325 for ( q = &p[2]; q[0] == ' '; q++ ) {
2328 AC_MEMCPY( p+1, q, len-(q-str)+1);
2331 pattern->bv_val = str;
2332 pattern->bv_len = p - str;
2345 if ( (*right = strchr( line, splitchar )) != NULL ) {
2346 *((*right)++) = '\0';
2351 access_append( Access **l, Access *a )
2353 for ( ; *l != NULL; l = &(*l)->a_next ) {
2361 acl_append( AccessControl **l, AccessControl *a, int pos )
2365 for (i=0 ; i != pos && *l != NULL; l = &(*l)->acl_next, i++ ) {
2374 access_free( Access *a )
2376 if ( !BER_BVISNULL( &a->a_dn_pat ) ) {
2377 free( a->a_dn_pat.bv_val );
2379 if ( !BER_BVISNULL( &a->a_realdn_pat ) ) {
2380 free( a->a_realdn_pat.bv_val );
2382 if ( !BER_BVISNULL( &a->a_peername_pat ) ) {
2383 free( a->a_peername_pat.bv_val );
2385 if ( !BER_BVISNULL( &a->a_sockname_pat ) ) {
2386 free( a->a_sockname_pat.bv_val );
2388 if ( !BER_BVISNULL( &a->a_domain_pat ) ) {
2389 free( a->a_domain_pat.bv_val );
2391 if ( !BER_BVISNULL( &a->a_sockurl_pat ) ) {
2392 free( a->a_sockurl_pat.bv_val );
2394 if ( !BER_BVISNULL( &a->a_set_pat ) ) {
2395 free( a->a_set_pat.bv_val );
2397 if ( !BER_BVISNULL( &a->a_group_pat ) ) {
2398 free( a->a_group_pat.bv_val );
2401 if ( a->a_dynacl != NULL ) {
2403 for ( da = a->a_dynacl; da; ) {
2404 slap_dynacl_t *tmp = da;
2408 if ( tmp->da_destroy ) {
2409 tmp->da_destroy( tmp->da_private );
2415 #endif /* SLAP_DYNACL */
2420 acl_free( AccessControl *a )
2425 if ( a->acl_filter ) {
2426 filter_free( a->acl_filter );
2428 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2429 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
2430 regfree( &a->acl_dn_re );
2432 free ( a->acl_dn_pat.bv_val );
2434 if ( a->acl_attrs ) {
2435 for ( an = a->acl_attrs; !BER_BVISNULL( &an->an_name ); an++ ) {
2436 free( an->an_name.bv_val );
2438 free( a->acl_attrs );
2440 for ( ; a->acl_access; a->acl_access = n ) {
2441 n = a->acl_access->a_next;
2442 access_free( a->acl_access );
2447 /* Because backend_startup uses acl_append to tack on the global_acl to
2448 * the end of each backend's acl, we cannot just take one argument and
2449 * merrily free our way to the end of the list. backend_destroy calls us
2450 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
2451 * point. config_destroy calls us with global_acl in arg1 and NULL in
2452 * arg2, so we then proceed to polish off the global_acl.
2455 acl_destroy( AccessControl *a, AccessControl *end )
2459 for ( ; a && a != end; a = n ) {
2466 access2str( slap_access_t access )
2468 if ( access == ACL_NONE ) {
2471 } else if ( access == ACL_DISCLOSE ) {
2474 } else if ( access == ACL_AUTH ) {
2477 } else if ( access == ACL_COMPARE ) {
2480 } else if ( access == ACL_SEARCH ) {
2483 } else if ( access == ACL_READ ) {
2486 } else if ( access == ACL_WRITE ) {
2489 } else if ( access == ACL_WADD ) {
2492 } else if ( access == ACL_WDEL ) {
2495 } else if ( access == ACL_MANAGE ) {
2504 str2access( const char *str )
2506 if ( strcasecmp( str, "none" ) == 0 ) {
2509 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2510 #ifndef SLAP_ACL_HONOR_DISCLOSE
2511 Debug( LDAP_DEBUG_ACL, "str2access: warning, "
2512 "\"disclose\" privilege disabled.\n",
2514 #endif /* SLAP_ACL_HONOR_DISCLOSE */
2515 return ACL_DISCLOSE;
2517 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2520 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2523 } else if ( strcasecmp( str, "search" ) == 0 ) {
2526 } else if ( strcasecmp( str, "read" ) == 0 ) {
2529 } else if ( strcasecmp( str, "write" ) == 0 ) {
2532 } else if ( strcasecmp( str, "add" ) == 0 ) {
2535 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2538 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2542 return( ACL_INVALID_ACCESS );
2545 #define ACLBUF_MAXLEN 8192
2547 static char aclbuf[ACLBUF_MAXLEN];
2550 dnaccess2text( slap_dn_access *bdn, char *ptr, int is_realdn )
2555 ptr = lutil_strcopy( ptr, "real" );
2558 if ( ber_bvccmp( &bdn->a_pat, '*' ) ||
2559 bdn->a_style == ACL_STYLE_ANONYMOUS ||
2560 bdn->a_style == ACL_STYLE_USERS ||
2561 bdn->a_style == ACL_STYLE_SELF )
2564 assert( ! ber_bvccmp( &bdn->a_pat, '*' ) );
2567 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2568 if ( bdn->a_style == ACL_STYLE_SELF && bdn->a_self_level != 0 ) {
2569 int n = sprintf( ptr, ".level{%d}", bdn->a_self_level );
2576 ptr = lutil_strcopy( ptr, "dn." );
2577 if ( bdn->a_style == ACL_STYLE_BASE )
2578 ptr = lutil_strcopy( ptr, style_base );
2580 ptr = lutil_strcopy( ptr, style_strings[bdn->a_style] );
2581 if ( bdn->a_style == ACL_STYLE_LEVEL ) {
2582 int n = sprintf( ptr, "{%d}", bdn->a_level );
2587 if ( bdn->a_expand ) {
2588 ptr = lutil_strcopy( ptr, ",expand" );
2592 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2599 access2text( Access *b, char *ptr )
2601 char maskbuf[ACCESSMASK_MAXLEN];
2603 ptr = lutil_strcopy( ptr, "\tby" );
2605 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
2606 ptr = dnaccess2text( &b->a_dn, ptr, 0 );
2609 ptr = lutil_strcopy( ptr, " dnattr=" );
2610 ptr = lutil_strcopy( ptr, b->a_dn_at->ad_cname.bv_val );
2613 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
2614 ptr = dnaccess2text( &b->a_realdn, ptr, 1 );
2616 if ( b->a_realdn_at ) {
2617 ptr = lutil_strcopy( ptr, " realdnattr=" );
2618 ptr = lutil_strcopy( ptr, b->a_realdn_at->ad_cname.bv_val );
2621 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
2622 ptr = lutil_strcopy( ptr, " group/" );
2623 ptr = lutil_strcopy( ptr, b->a_group_oc ?
2624 b->a_group_oc->soc_cname.bv_val : SLAPD_GROUP_CLASS );
2626 ptr = lutil_strcopy( ptr, b->a_group_at ?
2627 b->a_group_at->ad_cname.bv_val : SLAPD_GROUP_ATTR );
2629 ptr = lutil_strcopy( ptr, style_strings[b->a_group_style] );
2632 ptr = lutil_strcopy( ptr, b->a_group_pat.bv_val );
2636 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
2637 ptr = lutil_strcopy( ptr, " peername" );
2639 ptr = lutil_strcopy( ptr, style_strings[b->a_peername_style] );
2642 ptr = lutil_strcopy( ptr, b->a_peername_pat.bv_val );
2646 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
2647 ptr = lutil_strcopy( ptr, " sockname" );
2649 ptr = lutil_strcopy( ptr, style_strings[b->a_sockname_style] );
2652 ptr = lutil_strcopy( ptr, b->a_sockname_pat.bv_val );
2656 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
2657 ptr = lutil_strcopy( ptr, " domain" );
2659 ptr = lutil_strcopy( ptr, style_strings[b->a_domain_style] );
2660 if ( b->a_domain_expand ) {
2661 ptr = lutil_strcopy( ptr, ",expand" );
2664 ptr = lutil_strcopy( ptr, b->a_domain_pat.bv_val );
2667 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
2668 ptr = lutil_strcopy( ptr, " sockurl" );
2670 ptr = lutil_strcopy( ptr, style_strings[b->a_sockurl_style] );
2673 ptr = lutil_strcopy( ptr, b->a_sockurl_pat.bv_val );
2677 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
2678 ptr = lutil_strcopy( ptr, " set" );
2680 ptr = lutil_strcopy( ptr, style_strings[b->a_set_style] );
2683 ptr = lutil_strcopy( ptr, b->a_set_pat.bv_val );
2688 if ( b->a_dynacl ) {
2691 for ( da = b->a_dynacl; da; da = da->da_next ) {
2692 if ( da->da_unparse ) {
2693 struct berval bv = BER_BVNULL;
2694 (void)( *da->da_unparse )( da->da_private, &bv );
2695 assert( !BER_BVISNULL( &bv ) );
2696 ptr = lutil_strcopy( ptr, bv.bv_val );
2697 ch_free( bv.bv_val );
2701 #else /* ! SLAP_DYNACL */
2702 #ifdef SLAPD_ACI_ENABLED
2703 if ( b->a_aci_at != NULL ) {
2704 ptr = lutil_strcopy( ptr, " aci=" );
2705 ptr = lutil_strcopy( ptr, b->a_aci_at->ad_cname.bv_val );
2708 #endif /* SLAP_DYNACL */
2710 /* Security Strength Factors */
2711 if ( b->a_authz.sai_ssf ) {
2712 ptr += sprintf( ptr, " ssf=%u",
2713 b->a_authz.sai_ssf );
2715 if ( b->a_authz.sai_transport_ssf ) {
2716 ptr += sprintf( ptr, " transport_ssf=%u",
2717 b->a_authz.sai_transport_ssf );
2719 if ( b->a_authz.sai_tls_ssf ) {
2720 ptr += sprintf( ptr, " tls_ssf=%u",
2721 b->a_authz.sai_tls_ssf );
2723 if ( b->a_authz.sai_sasl_ssf ) {
2724 ptr += sprintf( ptr, " sasl_ssf=%u",
2725 b->a_authz.sai_sasl_ssf );
2729 if ( b->a_dn_self ) {
2730 ptr = lutil_strcopy( ptr, "self" );
2731 } else if ( b->a_realdn_self ) {
2732 ptr = lutil_strcopy( ptr, "realself" );
2734 ptr = lutil_strcopy( ptr, accessmask2str( b->a_access_mask, maskbuf, 0 ));
2735 if ( !maskbuf[0] ) ptr--;
2737 if( b->a_type == ACL_BREAK ) {
2738 ptr = lutil_strcopy( ptr, " break" );
2740 } else if( b->a_type == ACL_CONTINUE ) {
2741 ptr = lutil_strcopy( ptr, " continue" );
2743 } else if( b->a_type != ACL_STOP ) {
2744 ptr = lutil_strcopy( ptr, " unknown-control" );
2746 if ( !maskbuf[0] ) ptr = lutil_strcopy( ptr, " stop" );
2754 acl_unparse( AccessControl *a, struct berval *bv )
2760 bv->bv_val = aclbuf;
2765 ptr = lutil_strcopy( ptr, "to" );
2766 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2768 ptr = lutil_strcopy( ptr, " dn." );
2769 if ( a->acl_dn_style == ACL_STYLE_BASE )
2770 ptr = lutil_strcopy( ptr, style_base );
2772 ptr = lutil_strcopy( ptr, style_strings[a->acl_dn_style] );
2775 ptr = lutil_strcopy( ptr, a->acl_dn_pat.bv_val );
2776 ptr = lutil_strcopy( ptr, "\"\n" );
2779 if ( a->acl_filter != NULL ) {
2780 struct berval bv = BER_BVNULL;
2783 filter2bv( a->acl_filter, &bv );
2784 ptr = lutil_strcopy( ptr, " filter=\"" );
2785 ptr = lutil_strcopy( ptr, bv.bv_val );
2788 ch_free( bv.bv_val );
2791 if ( a->acl_attrs != NULL ) {
2796 ptr = lutil_strcopy( ptr, " attrs=" );
2797 for ( an = a->acl_attrs; an && !BER_BVISNULL( &an->an_name ); an++ ) {
2798 if ( ! first ) *ptr++ = ',';
2800 *ptr++ = an->an_oc_exclude ? '!' : '@';
2801 ptr = lutil_strcopy( ptr, an->an_oc->soc_cname.bv_val );
2804 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2811 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
2813 ptr = lutil_strcopy( ptr, " val." );
2814 if ( a->acl_attrval_style == ACL_STYLE_BASE &&
2815 a->acl_attrs[0].an_desc->ad_type->sat_syntax ==
2816 slap_schema.si_syn_distinguishedName )
2817 ptr = lutil_strcopy( ptr, style_base );
2819 ptr = lutil_strcopy( ptr, style_strings[a->acl_attrval_style] );
2822 ptr = lutil_strcopy( ptr, a->acl_attrval.bv_val );
2828 ptr = lutil_strcopy( ptr, " *\n" );
2831 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
2832 ptr = access2text( b, ptr );
2835 bv->bv_len = ptr - bv->bv_val;
2840 print_acl( Backend *be, AccessControl *a )
2844 acl_unparse( a, &bv );
2845 fprintf( stderr, "%s ACL: access %s\n",
2846 be == NULL ? "Global" : "Backend", bv.bv_val );
2848 #endif /* LDAP_DEBUG */