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-2010 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 const char *style_strings[] = {
60 static void split(char *line, int splitchar, char **left, char **right);
61 static void access_append(Access **l, Access *a);
62 static void access_free( Access *a );
63 static int acl_usage(void);
65 static void acl_regex_normalized_dn(const char *src, struct berval *pat);
68 static void print_acl(Backend *be, AccessControl *a);
71 static int check_scope( BackendDB *be, AccessControl *a );
84 slap_dynacl_t *da, *tmp;
87 for ( da = b->a_dynacl; da; da = da->da_next ) {
88 if ( strcasecmp( da->da_name, name ) == 0 ) {
89 Debug( LDAP_DEBUG_ANY,
90 "%s: line %d: dynacl \"%s\" already specified.\n",
91 fname, lineno, name );
96 da = slap_dynacl_get( name );
101 tmp = ch_malloc( sizeof( slap_dynacl_t ) );
104 if ( tmp->da_parse ) {
105 rc = ( *tmp->da_parse )( fname, lineno, opts, sty, right, &tmp->da_private );
112 tmp->da_next = b->a_dynacl;
117 #endif /* SLAP_DYNACL */
120 regtest(const char *fname, int lineno, char *pat) {
124 char buf[ SLAP_TEXT_BUFLEN ];
136 for (size = 0, flag = 0; (size < sizeof(buf)) && *sp; sp++) {
138 if (*sp == '$'|| (*sp >= '0' && *sp <= '9')) {
155 if ( size >= (sizeof(buf) - 1) ) {
156 Debug( LDAP_DEBUG_ANY,
157 "%s: line %d: regular expression \"%s\" too large\n",
158 fname, lineno, pat );
160 exit( EXIT_FAILURE );
163 if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
164 char error[ SLAP_TEXT_BUFLEN ];
166 regerror(e, &re, error, sizeof(error));
168 snprintf( buf, sizeof( buf ),
169 "regular expression \"%s\" bad because of %s",
171 Debug( LDAP_DEBUG_ANY,
173 fname, lineno, buf );
175 exit( EXIT_FAILURE );
183 * Check if the pattern of an ACL, if any, matches the scope
184 * of the backend it is defined within.
186 #define ACL_SCOPE_UNKNOWN (-2)
187 #define ACL_SCOPE_ERR (-1)
188 #define ACL_SCOPE_OK (0)
189 #define ACL_SCOPE_PARTIAL (1)
190 #define ACL_SCOPE_WARN (2)
193 check_scope( BackendDB *be, AccessControl *a )
198 dn = be->be_nsuffix[0];
200 if ( BER_BVISEMPTY( &dn ) ) {
204 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
205 a->acl_dn_style != ACL_STYLE_REGEX )
207 slap_style_t style = a->acl_dn_style;
209 if ( style == ACL_STYLE_REGEX ) {
210 char dnbuf[SLAP_LDAPDN_MAXLEN + 2];
211 char rebuf[SLAP_LDAPDN_MAXLEN + 1];
216 /* add trailing '$' to database suffix to form
217 * a simple trial regex pattern "<suffix>$" */
218 AC_MEMCPY( dnbuf, be->be_nsuffix[0].bv_val,
219 be->be_nsuffix[0].bv_len );
220 dnbuf[be->be_nsuffix[0].bv_len] = '$';
221 dnbuf[be->be_nsuffix[0].bv_len + 1] = '\0';
223 if ( regcomp( &re, dnbuf, REG_EXTENDED|REG_ICASE ) ) {
224 return ACL_SCOPE_WARN;
227 /* remove trailing ')$', if any, from original
229 rebuflen = a->acl_dn_pat.bv_len;
230 AC_MEMCPY( rebuf, a->acl_dn_pat.bv_val, rebuflen + 1 );
231 if ( rebuf[rebuflen - 1] == '$' ) {
232 rebuf[--rebuflen] = '\0';
234 while ( rebuflen > be->be_nsuffix[0].bv_len && rebuf[rebuflen - 1] == ')' ) {
235 rebuf[--rebuflen] = '\0';
237 if ( rebuflen == be->be_nsuffix[0].bv_len ) {
242 /* not a clear indication of scoping error, though */
243 rc = regexec( &re, rebuf, 0, NULL, 0 )
244 ? ACL_SCOPE_WARN : ACL_SCOPE_OK;
251 patlen = a->acl_dn_pat.bv_len;
252 /* If backend suffix is longer than pattern,
253 * it is a potential mismatch (in the sense
254 * that a superior naming context could
256 if ( dn.bv_len > patlen ) {
257 /* base is blatantly wrong */
258 if ( style == ACL_STYLE_BASE ) return ACL_SCOPE_ERR;
260 /* a style of one can be wrong if there is
261 * more than one level between the suffix
263 if ( style == ACL_STYLE_ONE ) {
264 ber_len_t rdnlen = 0;
268 if ( !DN_SEPARATOR( dn.bv_val[dn.bv_len - patlen - 1] )) {
269 return ACL_SCOPE_ERR;
274 rdnlen = dn_rdnlen( NULL, &dn );
275 if ( rdnlen != dn.bv_len - patlen - sep )
276 return ACL_SCOPE_ERR;
279 /* if the trailing part doesn't match,
280 * then it's an error */
281 if ( strcmp( a->acl_dn_pat.bv_val,
282 &dn.bv_val[dn.bv_len - patlen] ) != 0 )
284 return ACL_SCOPE_ERR;
287 return ACL_SCOPE_PARTIAL;
293 case ACL_STYLE_CHILDREN:
294 case ACL_STYLE_SUBTREE:
302 if ( dn.bv_len < patlen &&
303 !DN_SEPARATOR( a->acl_dn_pat.bv_val[patlen - dn.bv_len - 1] ))
305 return ACL_SCOPE_ERR;
308 if ( strcmp( &a->acl_dn_pat.bv_val[patlen - dn.bv_len], dn.bv_val )
311 return ACL_SCOPE_ERR;
317 return ACL_SCOPE_UNKNOWN;
330 char *left, *right, *style;
332 AccessControl *a = NULL;
337 for ( i = 1; i < argc; i++ ) {
338 /* to clause - select which entries are protected */
339 if ( strcasecmp( argv[i], "to" ) == 0 ) {
341 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
342 "only one to clause allowed in access line\n",
346 a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
347 for ( ++i; i < argc; i++ ) {
348 if ( strcasecmp( argv[i], "by" ) == 0 ) {
353 if ( strcasecmp( argv[i], "*" ) == 0 ) {
354 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
355 a->acl_dn_style != ACL_STYLE_REGEX )
357 Debug( LDAP_DEBUG_ANY,
358 "%s: line %d: dn pattern"
359 " already specified in to clause.\n",
364 ber_str2bv( "*", STRLENOF( "*" ), 1, &a->acl_dn_pat );
368 split( argv[i], '=', &left, &right );
369 split( left, '.', &left, &style );
371 if ( right == NULL ) {
372 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
373 "missing \"=\" in \"%s\" in to clause\n",
374 fname, lineno, left );
378 if ( strcasecmp( left, "dn" ) == 0 ) {
379 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
380 a->acl_dn_style != ACL_STYLE_REGEX )
382 Debug( LDAP_DEBUG_ANY,
383 "%s: line %d: dn pattern"
384 " already specified in to clause.\n",
389 if ( style == NULL || *style == '\0' ||
390 strcasecmp( style, "baseObject" ) == 0 ||
391 strcasecmp( style, "base" ) == 0 ||
392 strcasecmp( style, "exact" ) == 0 )
394 a->acl_dn_style = ACL_STYLE_BASE;
395 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
397 } else if ( strcasecmp( style, "oneLevel" ) == 0 ||
398 strcasecmp( style, "one" ) == 0 )
400 a->acl_dn_style = ACL_STYLE_ONE;
401 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
403 } else if ( strcasecmp( style, "subtree" ) == 0 ||
404 strcasecmp( style, "sub" ) == 0 )
406 if( *right == '\0' ) {
407 ber_str2bv( "*", STRLENOF( "*" ), 1, &a->acl_dn_pat );
410 a->acl_dn_style = ACL_STYLE_SUBTREE;
411 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
414 } else if ( strcasecmp( style, "children" ) == 0 ) {
415 a->acl_dn_style = ACL_STYLE_CHILDREN;
416 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
418 } else if ( strcasecmp( style, "regex" ) == 0 ) {
419 a->acl_dn_style = ACL_STYLE_REGEX;
421 if ( *right == '\0' ) {
422 /* empty regex should match empty DN */
423 a->acl_dn_style = ACL_STYLE_BASE;
424 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
426 } else if ( strcmp(right, "*") == 0
427 || strcmp(right, ".*") == 0
428 || strcmp(right, ".*$") == 0
429 || strcmp(right, "^.*") == 0
430 || strcmp(right, "^.*$") == 0
431 || strcmp(right, ".*$$") == 0
432 || strcmp(right, "^.*$$") == 0 )
434 ber_str2bv( "*", STRLENOF("*"), 1, &a->acl_dn_pat );
437 acl_regex_normalized_dn( right, &a->acl_dn_pat );
441 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
442 "unknown dn style \"%s\" in to clause\n",
443 fname, lineno, style );
450 if ( strcasecmp( left, "filter" ) == 0 ) {
451 if ( (a->acl_filter = str2filter( right )) == NULL ) {
452 Debug( LDAP_DEBUG_ANY,
453 "%s: line %d: bad filter \"%s\" in to clause\n",
454 fname, lineno, right );
458 } else if ( strcasecmp( left, "attr" ) == 0 /* TOLERATED */
459 || strcasecmp( left, "attrs" ) == 0 ) /* DOCUMENTED */
461 if ( strcasecmp( left, "attr" ) == 0 ) {
462 Debug( LDAP_DEBUG_ANY,
463 "%s: line %d: \"attr\" "
464 "is deprecated (and undocumented); "
465 "use \"attrs\" instead.\n",
469 a->acl_attrs = str2anlist( a->acl_attrs,
471 if ( a->acl_attrs == NULL ) {
472 Debug( LDAP_DEBUG_ANY,
473 "%s: line %d: unknown attr \"%s\" in to clause\n",
474 fname, lineno, right );
478 } else if ( strncasecmp( left, "val", 3 ) == 0 ) {
482 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
483 Debug( LDAP_DEBUG_ANY,
484 "%s: line %d: attr val already specified in to clause.\n",
488 if ( a->acl_attrs == NULL || !BER_BVISEMPTY( &a->acl_attrs[1].an_name ) )
490 Debug( LDAP_DEBUG_ANY,
491 "%s: line %d: attr val requires a single attribute.\n",
496 ber_str2bv( right, 0, 0, &bv );
497 a->acl_attrval_style = ACL_STYLE_BASE;
499 mr = strchr( left, '/' );
504 a->acl_attrval_mr = mr_find( mr );
505 if ( a->acl_attrval_mr == NULL ) {
506 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
507 "invalid matching rule \"%s\".\n",
512 if( !mr_usable_with_at( a->acl_attrval_mr, a->acl_attrs[ 0 ].an_desc->ad_type ) )
514 char buf[ SLAP_TEXT_BUFLEN ];
516 snprintf( buf, sizeof( buf ),
517 "matching rule \"%s\" use "
518 "with attr \"%s\" not appropriate.",
519 mr, a->acl_attrs[ 0 ].an_name.bv_val );
522 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
523 fname, lineno, buf );
528 if ( style != NULL ) {
529 if ( strcasecmp( style, "regex" ) == 0 ) {
530 int e = regcomp( &a->acl_attrval_re, bv.bv_val,
531 REG_EXTENDED | REG_ICASE );
533 char err[SLAP_TEXT_BUFLEN],
534 buf[ SLAP_TEXT_BUFLEN ];
536 regerror( e, &a->acl_attrval_re, err, sizeof( err ) );
538 snprintf( buf, sizeof( buf ),
539 "regular expression \"%s\" bad because of %s",
542 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
543 fname, lineno, buf );
546 a->acl_attrval_style = ACL_STYLE_REGEX;
549 /* FIXME: if the attribute has DN syntax, we might
550 * allow one, subtree and children styles as well */
551 if ( !strcasecmp( style, "base" ) ||
552 !strcasecmp( style, "exact" ) ) {
553 a->acl_attrval_style = ACL_STYLE_BASE;
555 } else if ( a->acl_attrs[0].an_desc->ad_type->
556 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 snprintf( buf, sizeof( buf ),
576 "unknown val.<style> \"%s\" for attributeType \"%s\" "
579 a->acl_attrs[0].an_desc->ad_cname.bv_val );
581 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
583 fname, lineno, buf );
587 rc = dnNormalize( 0, NULL, NULL, &bv, &a->acl_attrval, NULL );
588 if ( rc != LDAP_SUCCESS ) {
589 char buf[ SLAP_TEXT_BUFLEN ];
591 snprintf( buf, sizeof( buf ),
592 "unable to normalize DN \"%s\" "
593 "for attributeType \"%s\" (%d).",
595 a->acl_attrs[0].an_desc->ad_cname.bv_val,
597 Debug( LDAP_DEBUG_ANY,
599 fname, lineno, buf );
604 char buf[ SLAP_TEXT_BUFLEN ];
606 snprintf( buf, sizeof( buf ),
607 "unknown val.<style> \"%s\" for attributeType \"%s\".",
608 style, a->acl_attrs[0].an_desc->ad_cname.bv_val );
609 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
611 fname, lineno, buf );
617 /* Check for appropriate matching rule */
618 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
619 ber_dupbv( &a->acl_attrval, &bv );
621 } else if ( BER_BVISNULL( &a->acl_attrval ) ) {
625 if ( a->acl_attrval_mr == NULL ) {
626 a->acl_attrval_mr = a->acl_attrs[ 0 ].an_desc->ad_type->sat_equality;
629 if ( a->acl_attrval_mr == NULL ) {
630 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
631 "attr \"%s\" does not have an EQUALITY matching rule.\n",
632 fname, lineno, a->acl_attrs[ 0 ].an_name.bv_val );
636 rc = asserted_value_validate_normalize(
637 a->acl_attrs[ 0 ].an_desc,
639 SLAP_MR_EQUALITY|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
644 if ( rc != LDAP_SUCCESS ) {
645 char buf[ SLAP_TEXT_BUFLEN ];
647 snprintf( buf, sizeof( buf ), "%s: line %d: "
648 " attr \"%s\" normalization failed (%d: %s)",
650 a->acl_attrs[ 0 ].an_name.bv_val, rc, text );
651 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s.\n",
652 fname, lineno, buf );
658 Debug( LDAP_DEBUG_ANY,
659 "%s: line %d: expecting <what> got \"%s\"\n",
660 fname, lineno, left );
665 if ( !BER_BVISNULL( &a->acl_dn_pat ) &&
666 ber_bvccmp( &a->acl_dn_pat, '*' ) )
668 free( a->acl_dn_pat.bv_val );
669 BER_BVZERO( &a->acl_dn_pat );
670 a->acl_dn_style = ACL_STYLE_REGEX;
673 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
674 a->acl_dn_style != ACL_STYLE_REGEX )
676 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
678 rc = dnNormalize( 0, NULL, NULL, &a->acl_dn_pat, &bv, NULL);
679 if ( rc != LDAP_SUCCESS ) {
680 Debug( LDAP_DEBUG_ANY,
681 "%s: line %d: bad DN \"%s\" in to DN clause\n",
682 fname, lineno, a->acl_dn_pat.bv_val );
685 free( a->acl_dn_pat.bv_val );
689 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
690 REG_EXTENDED | REG_ICASE );
692 char err[ SLAP_TEXT_BUFLEN ],
693 buf[ SLAP_TEXT_BUFLEN ];
695 regerror( e, &a->acl_dn_re, err, sizeof( err ) );
696 snprintf( buf, sizeof( buf ),
697 "regular expression \"%s\" bad because of %s",
699 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
700 fname, lineno, buf );
706 /* by clause - select who has what access to entries */
707 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
709 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
710 "to clause required before by clause in access line\n",
716 * by clause consists of <who> and <access>
720 Debug( LDAP_DEBUG_ANY,
721 "%s: line %d: premature EOL: expecting <who>\n",
726 b = (Access *) ch_calloc( 1, sizeof(Access) );
728 ACL_INVALIDATE( b->a_access_mask );
731 for ( ; i < argc; i++ ) {
732 slap_style_t sty = ACL_STYLE_REGEX;
733 char *style_modifier = NULL;
734 char *style_level = NULL;
737 slap_dn_access *bdn = &b->a_dn;
740 split( argv[i], '=', &left, &right );
741 split( left, '.', &left, &style );
743 split( style, ',', &style, &style_modifier );
745 if ( strncasecmp( style, "level", STRLENOF( "level" ) ) == 0 ) {
746 split( style, '{', &style, &style_level );
747 if ( style_level != NULL ) {
748 char *p = strchr( style_level, '}' );
750 Debug( LDAP_DEBUG_ANY,
751 "%s: line %d: premature eol: "
752 "expecting closing '}' in \"level{n}\"\n",
755 } else if ( p == style_level ) {
756 Debug( LDAP_DEBUG_ANY,
757 "%s: line %d: empty level "
767 if ( style == NULL || *style == '\0' ||
768 strcasecmp( style, "exact" ) == 0 ||
769 strcasecmp( style, "baseObject" ) == 0 ||
770 strcasecmp( style, "base" ) == 0 )
772 sty = ACL_STYLE_BASE;
774 } else if ( strcasecmp( style, "onelevel" ) == 0 ||
775 strcasecmp( style, "one" ) == 0 )
779 } else if ( strcasecmp( style, "subtree" ) == 0 ||
780 strcasecmp( style, "sub" ) == 0 )
782 sty = ACL_STYLE_SUBTREE;
784 } else if ( strcasecmp( style, "children" ) == 0 ) {
785 sty = ACL_STYLE_CHILDREN;
787 } else if ( strcasecmp( style, "level" ) == 0 )
789 if ( lutil_atoi( &level, style_level ) != 0 ) {
790 Debug( LDAP_DEBUG_ANY,
791 "%s: line %d: unable to parse level "
797 sty = ACL_STYLE_LEVEL;
799 } else if ( strcasecmp( style, "regex" ) == 0 ) {
800 sty = ACL_STYLE_REGEX;
802 } else if ( strcasecmp( style, "expand" ) == 0 ) {
803 sty = ACL_STYLE_EXPAND;
805 } else if ( strcasecmp( style, "ip" ) == 0 ) {
808 } else if ( strcasecmp( style, "ipv6" ) == 0 ) {
809 #ifndef LDAP_PF_INET6
810 Debug( LDAP_DEBUG_ANY,
811 "%s: line %d: IPv6 not supported\n",
813 #endif /* ! LDAP_PF_INET6 */
814 sty = ACL_STYLE_IPV6;
816 } else if ( strcasecmp( style, "path" ) == 0 ) {
817 sty = ACL_STYLE_PATH;
818 #ifndef LDAP_PF_LOCAL
819 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
821 "\"path\" style modifier is useless without local.\n",
824 #endif /* LDAP_PF_LOCAL */
827 Debug( LDAP_DEBUG_ANY,
828 "%s: line %d: unknown style \"%s\" in by clause\n",
829 fname, lineno, style );
833 if ( style_modifier &&
834 strcasecmp( style_modifier, "expand" ) == 0 )
837 case ACL_STYLE_REGEX:
838 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
839 "\"regex\" style implies \"expand\" modifier.\n",
844 case ACL_STYLE_EXPAND:
848 /* we'll see later if it's pertinent */
854 if ( strncasecmp( left, "real", STRLENOF( "real" ) ) == 0 ) {
857 left += STRLENOF( "real" );
860 if ( strcasecmp( left, "*" ) == 0 ) {
865 ber_str2bv( "*", STRLENOF( "*" ), 1, &bv );
866 sty = ACL_STYLE_REGEX;
868 } else if ( strcasecmp( left, "anonymous" ) == 0 ) {
869 ber_str2bv("anonymous", STRLENOF( "anonymous" ), 1, &bv);
870 sty = ACL_STYLE_ANONYMOUS;
872 } else if ( strcasecmp( left, "users" ) == 0 ) {
873 ber_str2bv("users", STRLENOF( "users" ), 1, &bv);
874 sty = ACL_STYLE_USERS;
876 } else if ( strcasecmp( left, "self" ) == 0 ) {
877 ber_str2bv("self", STRLENOF( "self" ), 1, &bv);
878 sty = ACL_STYLE_SELF;
880 } else if ( strcasecmp( left, "dn" ) == 0 ) {
881 if ( sty == ACL_STYLE_REGEX ) {
882 bdn->a_style = ACL_STYLE_REGEX;
883 if ( right == NULL ) {
888 bdn->a_style = ACL_STYLE_USERS;
890 } else if (*right == '\0' ) {
892 ber_str2bv("anonymous",
893 STRLENOF( "anonymous" ),
895 bdn->a_style = ACL_STYLE_ANONYMOUS;
897 } else if ( strcmp( right, "*" ) == 0 ) {
899 /* any or users? users for now */
903 bdn->a_style = ACL_STYLE_USERS;
905 } else if ( strcmp( right, ".+" ) == 0
906 || strcmp( right, "^.+" ) == 0
907 || strcmp( right, ".+$" ) == 0
908 || strcmp( right, "^.+$" ) == 0
909 || strcmp( right, ".+$$" ) == 0
910 || strcmp( right, "^.+$$" ) == 0 )
915 bdn->a_style = ACL_STYLE_USERS;
917 } else if ( strcmp( right, ".*" ) == 0
918 || strcmp( right, "^.*" ) == 0
919 || strcmp( right, ".*$" ) == 0
920 || strcmp( right, "^.*$" ) == 0
921 || strcmp( right, ".*$$" ) == 0
922 || strcmp( right, "^.*$$" ) == 0 )
929 acl_regex_normalized_dn( right, &bv );
930 if ( !ber_bvccmp( &bv, '*' ) ) {
931 regtest( fname, lineno, bv.bv_val );
935 } else if ( right == NULL || *right == '\0' ) {
936 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
937 "missing \"=\" in (or value after) \"%s\" "
939 fname, lineno, left );
943 ber_str2bv( right, 0, 1, &bv );
950 if ( !BER_BVISNULL( &bv ) ) {
951 if ( !BER_BVISEMPTY( &bdn->a_pat ) ) {
952 Debug( LDAP_DEBUG_ANY,
953 "%s: line %d: dn pattern already specified.\n",
958 if ( sty != ACL_STYLE_REGEX &&
959 sty != ACL_STYLE_ANONYMOUS &&
960 sty != ACL_STYLE_USERS &&
961 sty != ACL_STYLE_SELF &&
964 rc = dnNormalize(0, NULL, NULL,
965 &bv, &bdn->a_pat, NULL);
966 if ( rc != LDAP_SUCCESS ) {
967 Debug( LDAP_DEBUG_ANY,
968 "%s: line %d: bad DN \"%s\" in by DN clause\n",
969 fname, lineno, bv.bv_val );
973 if ( sty == ACL_STYLE_BASE
975 && !BER_BVISNULL( &be->be_rootndn )
976 && dn_match( &bdn->a_pat, &be->be_rootndn ) )
978 Debug( LDAP_DEBUG_ANY,
979 "%s: line %d: rootdn is always granted "
980 "unlimited privileges.\n",
992 for ( exp = strchr( bdn->a_pat.bv_val, '$' );
993 exp && (ber_len_t)(exp - bdn->a_pat.bv_val)
995 exp = strchr( exp, '$' ) )
997 if ( ( isdigit( (unsigned char) exp[ 1 ] ) ||
998 exp[ 1 ] == '{' ) ) {
1005 bdn->a_expand = expand;
1008 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1009 "\"expand\" used with no expansions in \"pattern\".\n",
1014 if ( sty == ACL_STYLE_SELF ) {
1015 bdn->a_self_level = level;
1019 Debug( LDAP_DEBUG_ANY,
1020 "%s: line %d: bad negative level \"%d\" "
1021 "in by DN clause\n",
1022 fname, lineno, level );
1024 } else if ( level == 1 ) {
1025 Debug( LDAP_DEBUG_ANY,
1026 "%s: line %d: \"onelevel\" should be used "
1027 "instead of \"level{1}\" in by DN clause\n",
1029 } else if ( level == 0 && sty == ACL_STYLE_LEVEL ) {
1030 Debug( LDAP_DEBUG_ANY,
1031 "%s: line %d: \"base\" should be used "
1032 "instead of \"level{0}\" in by DN clause\n",
1036 bdn->a_level = level;
1041 if ( strcasecmp( left, "dnattr" ) == 0 ) {
1042 if ( right == NULL || right[0] == '\0' ) {
1043 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1044 "missing \"=\" in (or value after) \"%s\" "
1046 fname, lineno, left );
1050 if( bdn->a_at != NULL ) {
1051 Debug( LDAP_DEBUG_ANY,
1052 "%s: line %d: dnattr already specified.\n",
1057 rc = slap_str2ad( right, &bdn->a_at, &text );
1059 if( rc != LDAP_SUCCESS ) {
1060 char buf[ SLAP_TEXT_BUFLEN ];
1062 snprintf( buf, sizeof( buf ),
1063 "dnattr \"%s\": %s",
1065 Debug( LDAP_DEBUG_ANY,
1066 "%s: line %d: %s\n",
1067 fname, lineno, buf );
1072 if( !is_at_syntax( bdn->a_at->ad_type,
1073 SLAPD_DN_SYNTAX ) &&
1074 !is_at_syntax( bdn->a_at->ad_type,
1075 SLAPD_NAMEUID_SYNTAX ))
1077 char buf[ SLAP_TEXT_BUFLEN ];
1079 snprintf( buf, sizeof( buf ),
1081 "inappropriate syntax: %s\n",
1083 bdn->a_at->ad_type->sat_syntax_oid );
1084 Debug( LDAP_DEBUG_ANY,
1085 "%s: line %d: %s\n",
1086 fname, lineno, buf );
1090 if( bdn->a_at->ad_type->sat_equality == NULL ) {
1091 Debug( LDAP_DEBUG_ANY,
1092 "%s: line %d: dnattr \"%s\": "
1093 "inappropriate matching (no EQUALITY)\n",
1094 fname, lineno, right );
1101 if ( strncasecmp( left, "group", STRLENOF( "group" ) ) == 0 ) {
1104 char *attr_name = SLAPD_GROUP_ATTR;
1107 case ACL_STYLE_REGEX:
1108 /* legacy, tolerated */
1109 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
1111 "deprecated group style \"regex\"; "
1112 "use \"expand\" instead.\n",
1114 sty = ACL_STYLE_EXPAND;
1117 case ACL_STYLE_BASE:
1118 /* legal, traditional */
1119 case ACL_STYLE_EXPAND:
1120 /* legal, substring expansion; supersedes regex */
1125 Debug( LDAP_DEBUG_ANY,
1127 "inappropriate style \"%s\" in by clause.\n",
1128 fname, lineno, style );
1132 if ( right == NULL || right[0] == '\0' ) {
1133 Debug( LDAP_DEBUG_ANY,
1135 "missing \"=\" in (or value after) \"%s\" "
1137 fname, lineno, left );
1141 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1142 Debug( LDAP_DEBUG_ANY,
1143 "%s: line %d: group pattern already specified.\n",
1148 /* format of string is
1149 "group/objectClassValue/groupAttrName" */
1150 if ( ( value = strchr(left, '/') ) != NULL ) {
1152 if ( *value && ( name = strchr( value, '/' ) ) != NULL ) {
1157 b->a_group_style = sty;
1158 if ( sty == ACL_STYLE_EXPAND ) {
1159 acl_regex_normalized_dn( right, &bv );
1160 if ( !ber_bvccmp( &bv, '*' ) ) {
1161 regtest( fname, lineno, bv.bv_val );
1163 b->a_group_pat = bv;
1166 ber_str2bv( right, 0, 0, &bv );
1167 rc = dnNormalize( 0, NULL, NULL, &bv,
1168 &b->a_group_pat, NULL );
1169 if ( rc != LDAP_SUCCESS ) {
1170 Debug( LDAP_DEBUG_ANY,
1171 "%s: line %d: bad DN \"%s\".\n",
1172 fname, lineno, right );
1177 if ( value && *value ) {
1178 b->a_group_oc = oc_find( value );
1181 if ( b->a_group_oc == NULL ) {
1182 Debug( LDAP_DEBUG_ANY,
1183 "%s: line %d: group objectclass "
1184 "\"%s\" unknown.\n",
1185 fname, lineno, value );
1190 b->a_group_oc = oc_find( SLAPD_GROUP_CLASS );
1192 if( b->a_group_oc == NULL ) {
1193 Debug( LDAP_DEBUG_ANY,
1194 "%s: line %d: group default objectclass "
1195 "\"%s\" unknown.\n",
1196 fname, lineno, SLAPD_GROUP_CLASS );
1201 if ( is_object_subclass( slap_schema.si_oc_referral,
1204 Debug( LDAP_DEBUG_ANY,
1205 "%s: line %d: group objectclass \"%s\" "
1206 "is subclass of referral.\n",
1207 fname, lineno, value );
1211 if ( is_object_subclass( slap_schema.si_oc_alias,
1214 Debug( LDAP_DEBUG_ANY,
1215 "%s: line %d: group objectclass \"%s\" "
1216 "is subclass of alias.\n",
1217 fname, lineno, value );
1221 if ( name && *name ) {
1227 rc = slap_str2ad( attr_name, &b->a_group_at, &text );
1228 if ( rc != LDAP_SUCCESS ) {
1229 char buf[ SLAP_TEXT_BUFLEN ];
1231 snprintf( buf, sizeof( buf ),
1232 "group \"%s\": %s.",
1234 Debug( LDAP_DEBUG_ANY,
1235 "%s: line %d: %s\n",
1236 fname, lineno, buf );
1240 if ( !is_at_syntax( b->a_group_at->ad_type,
1241 SLAPD_DN_SYNTAX ) /* e.g. "member" */
1242 && !is_at_syntax( b->a_group_at->ad_type,
1243 SLAPD_NAMEUID_SYNTAX ) /* e.g. memberUID */
1244 && !is_at_subtype( b->a_group_at->ad_type,
1245 slap_schema.si_ad_labeledURI->ad_type ) /* e.g. memberURL */ )
1247 char buf[ SLAP_TEXT_BUFLEN ];
1249 snprintf( buf, sizeof( buf ),
1250 "group \"%s\" attr \"%s\": inappropriate syntax: %s; "
1251 "must be " SLAPD_DN_SYNTAX " (DN), "
1252 SLAPD_NAMEUID_SYNTAX " (NameUID) "
1253 "or a subtype of labeledURI.",
1256 at_syntax( b->a_group_at->ad_type ) );
1257 Debug( LDAP_DEBUG_ANY,
1258 "%s: line %d: %s\n",
1259 fname, lineno, buf );
1266 ObjectClass *ocs[2];
1268 ocs[0] = b->a_group_oc;
1271 rc = oc_check_allowed( b->a_group_at->ad_type,
1275 char buf[ SLAP_TEXT_BUFLEN ];
1277 snprintf( buf, sizeof( buf ),
1278 "group: \"%s\" not allowed by \"%s\".",
1279 b->a_group_at->ad_cname.bv_val,
1280 b->a_group_oc->soc_oid );
1281 Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n",
1282 fname, lineno, buf );
1289 if ( strcasecmp( left, "peername" ) == 0 ) {
1291 case ACL_STYLE_REGEX:
1292 case ACL_STYLE_BASE:
1293 /* legal, traditional */
1294 case ACL_STYLE_EXPAND:
1295 /* cheap replacement to regex for simple expansion */
1297 case ACL_STYLE_IPV6:
1298 case ACL_STYLE_PATH:
1299 /* legal, peername specific */
1303 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1304 "inappropriate style \"%s\" in by clause.\n",
1305 fname, lineno, style );
1309 if ( right == NULL || right[0] == '\0' ) {
1310 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1311 "missing \"=\" in (or value after) \"%s\" "
1313 fname, lineno, left );
1317 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1318 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1319 "peername pattern already specified.\n",
1324 b->a_peername_style = sty;
1325 if ( sty == ACL_STYLE_REGEX ) {
1326 acl_regex_normalized_dn( right, &bv );
1327 if ( !ber_bvccmp( &bv, '*' ) ) {
1328 regtest( fname, lineno, bv.bv_val );
1330 b->a_peername_pat = bv;
1333 ber_str2bv( right, 0, 1, &b->a_peername_pat );
1335 if ( sty == ACL_STYLE_IP ) {
1340 split( right, '{', &addr, &port );
1341 split( addr, '%', &addr, &mask );
1343 b->a_peername_addr = inet_addr( addr );
1344 if ( b->a_peername_addr == (unsigned long)(-1) ) {
1345 /* illegal address */
1346 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1347 "illegal peername address \"%s\".\n",
1348 fname, lineno, addr );
1352 b->a_peername_mask = (unsigned long)(-1);
1353 if ( mask != NULL ) {
1354 b->a_peername_mask = inet_addr( mask );
1355 if ( b->a_peername_mask ==
1356 (unsigned long)(-1) )
1359 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1360 "illegal peername address mask "
1362 fname, lineno, mask );
1367 b->a_peername_port = -1;
1371 b->a_peername_port = strtol( port, &end, 10 );
1372 if ( end == port || end[0] != '}' ) {
1374 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1375 "illegal peername port specification "
1377 fname, lineno, port );
1382 #ifdef LDAP_PF_INET6
1383 } else if ( sty == ACL_STYLE_IPV6 ) {
1388 split( right, '{', &addr, &port );
1389 split( addr, '%', &addr, &mask );
1391 if ( inet_pton( AF_INET6, addr, &b->a_peername_addr6 ) != 1 ) {
1392 /* illegal address */
1393 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1394 "illegal peername address \"%s\".\n",
1395 fname, lineno, addr );
1399 if ( mask == NULL ) {
1400 mask = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
1403 if ( inet_pton( AF_INET6, mask, &b->a_peername_mask6 ) != 1 ) {
1405 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1406 "illegal peername address mask "
1408 fname, lineno, mask );
1412 b->a_peername_port = -1;
1416 b->a_peername_port = strtol( port, &end, 10 );
1417 if ( end == port || end[0] != '}' ) {
1419 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1420 "illegal peername port specification "
1422 fname, lineno, port );
1426 #endif /* LDAP_PF_INET6 */
1432 if ( strcasecmp( left, "sockname" ) == 0 ) {
1434 case ACL_STYLE_REGEX:
1435 case ACL_STYLE_BASE:
1436 /* legal, traditional */
1437 case ACL_STYLE_EXPAND:
1438 /* cheap replacement to regex for simple expansion */
1443 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1444 "inappropriate style \"%s\" in by clause\n",
1445 fname, lineno, style );
1449 if ( right == NULL || right[0] == '\0' ) {
1450 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1451 "missing \"=\" in (or value after) \"%s\" "
1453 fname, lineno, left );
1457 if ( !BER_BVISNULL( &b->a_sockname_pat ) ) {
1458 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1459 "sockname pattern already specified.\n",
1464 b->a_sockname_style = sty;
1465 if ( sty == ACL_STYLE_REGEX ) {
1466 acl_regex_normalized_dn( right, &bv );
1467 if ( !ber_bvccmp( &bv, '*' ) ) {
1468 regtest( fname, lineno, bv.bv_val );
1470 b->a_sockname_pat = bv;
1473 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
1478 if ( strcasecmp( left, "domain" ) == 0 ) {
1480 case ACL_STYLE_REGEX:
1481 case ACL_STYLE_BASE:
1482 case ACL_STYLE_SUBTREE:
1483 /* legal, traditional */
1486 case ACL_STYLE_EXPAND:
1487 /* tolerated: means exact,expand */
1489 Debug( LDAP_DEBUG_ANY,
1491 "\"expand\" modifier "
1492 "with \"expand\" style.\n",
1495 sty = ACL_STYLE_BASE;
1501 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1502 "inappropriate style \"%s\" in by clause.\n",
1503 fname, lineno, style );
1507 if ( right == NULL || right[0] == '\0' ) {
1508 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1509 "missing \"=\" in (or value after) \"%s\" "
1511 fname, lineno, left );
1515 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1516 Debug( LDAP_DEBUG_ANY,
1517 "%s: line %d: domain pattern already specified.\n",
1522 b->a_domain_style = sty;
1523 b->a_domain_expand = expand;
1524 if ( sty == ACL_STYLE_REGEX ) {
1525 acl_regex_normalized_dn( right, &bv );
1526 if ( !ber_bvccmp( &bv, '*' ) ) {
1527 regtest( fname, lineno, bv.bv_val );
1529 b->a_domain_pat = bv;
1532 ber_str2bv( right, 0, 1, &b->a_domain_pat );
1537 if ( strcasecmp( left, "sockurl" ) == 0 ) {
1539 case ACL_STYLE_REGEX:
1540 case ACL_STYLE_BASE:
1541 /* legal, traditional */
1542 case ACL_STYLE_EXPAND:
1543 /* cheap replacement to regex for simple expansion */
1548 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1549 "inappropriate style \"%s\" in by clause.\n",
1550 fname, lineno, style );
1554 if ( right == NULL || right[0] == '\0' ) {
1555 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1556 "missing \"=\" in (or value after) \"%s\" "
1558 fname, lineno, left );
1562 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1563 Debug( LDAP_DEBUG_ANY,
1564 "%s: line %d: sockurl pattern already specified.\n",
1569 b->a_sockurl_style = sty;
1570 if ( sty == ACL_STYLE_REGEX ) {
1571 acl_regex_normalized_dn( right, &bv );
1572 if ( !ber_bvccmp( &bv, '*' ) ) {
1573 regtest( fname, lineno, bv.bv_val );
1575 b->a_sockurl_pat = bv;
1578 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
1583 if ( strcasecmp( left, "set" ) == 0 ) {
1586 case ACL_STYLE_REGEX:
1587 Debug( LDAP_DEBUG_CONFIG | LDAP_DEBUG_ACL,
1589 "deprecated set style "
1590 "\"regex\" in <by> clause; "
1591 "use \"expand\" instead.\n",
1593 sty = ACL_STYLE_EXPAND;
1596 case ACL_STYLE_BASE:
1597 case ACL_STYLE_EXPAND:
1601 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1602 "inappropriate style \"%s\" in by clause.\n",
1603 fname, lineno, style );
1607 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1608 Debug( LDAP_DEBUG_ANY,
1609 "%s: line %d: set attribute already specified.\n",
1614 if ( right == NULL || *right == '\0' ) {
1615 Debug( LDAP_DEBUG_ANY,
1616 "%s: line %d: no set is defined.\n",
1621 b->a_set_style = sty;
1622 ber_str2bv( right, 0, 1, &b->a_set_pat );
1632 #if 1 /* tolerate legacy "aci" <who> */
1633 if ( strcasecmp( left, "aci" ) == 0 ) {
1634 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1635 "undocumented deprecated \"aci\" directive "
1636 "is superseded by \"dynacl/aci\".\n",
1641 #endif /* tolerate legacy "aci" <who> */
1642 if ( strncasecmp( left, "dynacl/", STRLENOF( "dynacl/" ) ) == 0 ) {
1643 name = &left[ STRLENOF( "dynacl/" ) ];
1644 opts = strchr( name, '/' );
1652 if ( slap_dynacl_config( fname, lineno, b, name, opts, sty, right ) ) {
1653 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1654 "unable to configure dynacl \"%s\".\n",
1655 fname, lineno, name );
1662 #endif /* SLAP_DYNACL */
1664 if ( strcasecmp( left, "ssf" ) == 0 ) {
1665 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1666 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1667 "inappropriate style \"%s\" in by clause.\n",
1668 fname, lineno, style );
1672 if ( b->a_authz.sai_ssf ) {
1673 Debug( LDAP_DEBUG_ANY,
1674 "%s: line %d: ssf attribute already specified.\n",
1679 if ( right == NULL || *right == '\0' ) {
1680 Debug( LDAP_DEBUG_ANY,
1681 "%s: line %d: no ssf is defined.\n",
1686 if ( lutil_atou( &b->a_authz.sai_ssf, right ) != 0 ) {
1687 Debug( LDAP_DEBUG_ANY,
1688 "%s: line %d: unable to parse ssf value (%s).\n",
1689 fname, lineno, right );
1693 if ( !b->a_authz.sai_ssf ) {
1694 Debug( LDAP_DEBUG_ANY,
1695 "%s: line %d: invalid ssf value (%s).\n",
1696 fname, lineno, right );
1702 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
1703 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1704 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1705 "inappropriate style \"%s\" in by clause.\n",
1706 fname, lineno, style );
1710 if ( b->a_authz.sai_transport_ssf ) {
1711 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1712 "transport_ssf attribute already specified.\n",
1717 if ( right == NULL || *right == '\0' ) {
1718 Debug( LDAP_DEBUG_ANY,
1719 "%s: line %d: no transport_ssf is defined.\n",
1724 if ( lutil_atou( &b->a_authz.sai_transport_ssf, right ) != 0 ) {
1725 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1726 "unable to parse transport_ssf value (%s).\n",
1727 fname, lineno, right );
1731 if ( !b->a_authz.sai_transport_ssf ) {
1732 Debug( LDAP_DEBUG_ANY,
1733 "%s: line %d: invalid transport_ssf value (%s).\n",
1734 fname, lineno, right );
1740 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
1741 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1742 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1743 "inappropriate style \"%s\" in by clause.\n",
1744 fname, lineno, style );
1748 if ( b->a_authz.sai_tls_ssf ) {
1749 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1750 "tls_ssf attribute already specified.\n",
1755 if ( right == NULL || *right == '\0' ) {
1756 Debug( LDAP_DEBUG_ANY,
1757 "%s: line %d: no tls_ssf is defined\n",
1762 if ( lutil_atou( &b->a_authz.sai_tls_ssf, right ) != 0 ) {
1763 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1764 "unable to parse tls_ssf value (%s).\n",
1765 fname, lineno, right );
1769 if ( !b->a_authz.sai_tls_ssf ) {
1770 Debug( LDAP_DEBUG_ANY,
1771 "%s: line %d: invalid tls_ssf value (%s).\n",
1772 fname, lineno, right );
1778 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1779 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1780 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1781 "inappropriate style \"%s\" in by clause.\n",
1782 fname, lineno, style );
1786 if ( b->a_authz.sai_sasl_ssf ) {
1787 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1788 "sasl_ssf attribute already specified.\n",
1793 if ( right == NULL || *right == '\0' ) {
1794 Debug( LDAP_DEBUG_ANY,
1795 "%s: line %d: no sasl_ssf is defined.\n",
1800 if ( lutil_atou( &b->a_authz.sai_sasl_ssf, right ) != 0 ) {
1801 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1802 "unable to parse sasl_ssf value (%s).\n",
1803 fname, lineno, right );
1807 if ( !b->a_authz.sai_sasl_ssf ) {
1808 Debug( LDAP_DEBUG_ANY,
1809 "%s: line %d: invalid sasl_ssf value (%s).\n",
1810 fname, lineno, right );
1816 if ( right != NULL ) {
1823 if ( i == argc || ( strcasecmp( left, "stop" ) == 0 ) ) {
1824 /* out of arguments or plain stop */
1826 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1827 ACL_PRIV_SET( b->a_access_mask, ACL_PRIV_NONE);
1828 b->a_type = ACL_STOP;
1830 access_append( &a->acl_access, b );
1834 if ( strcasecmp( left, "continue" ) == 0 ) {
1835 /* plain continue */
1837 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1838 ACL_PRIV_SET( b->a_access_mask, ACL_PRIV_NONE);
1839 b->a_type = ACL_CONTINUE;
1841 access_append( &a->acl_access, b );
1845 if ( strcasecmp( left, "break" ) == 0 ) {
1846 /* plain continue */
1848 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1849 ACL_PRIV_SET( b->a_access_mask, ACL_PRIV_NONE);
1850 b->a_type = ACL_BREAK;
1852 access_append( &a->acl_access, b );
1856 if ( strcasecmp( left, "by" ) == 0 ) {
1857 /* we've gone too far */
1859 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1860 ACL_PRIV_SET( b->a_access_mask, ACL_PRIV_NONE);
1861 b->a_type = ACL_STOP;
1863 access_append( &a->acl_access, b );
1871 if ( strncasecmp( left, "self", STRLENOF( "self" ) ) == 0 ) {
1873 lleft = &left[ STRLENOF( "self" ) ];
1875 } else if ( strncasecmp( left, "realself", STRLENOF( "realself" ) ) == 0 ) {
1876 b->a_realdn_self = 1;
1877 lleft = &left[ STRLENOF( "realself" ) ];
1880 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( lleft ) );
1883 if ( ACL_IS_INVALID( b->a_access_mask ) ) {
1884 Debug( LDAP_DEBUG_ANY,
1885 "%s: line %d: expecting <access> got \"%s\".\n",
1886 fname, lineno, left );
1890 b->a_type = ACL_STOP;
1892 if ( ++i == argc ) {
1893 /* out of arguments or plain stop */
1894 access_append( &a->acl_access, b );
1898 if ( strcasecmp( argv[i], "continue" ) == 0 ) {
1899 /* plain continue */
1900 b->a_type = ACL_CONTINUE;
1902 } else if ( strcasecmp( argv[i], "break" ) == 0 ) {
1903 /* plain continue */
1904 b->a_type = ACL_BREAK;
1906 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1911 access_append( &a->acl_access, b );
1915 Debug( LDAP_DEBUG_ANY,
1916 "%s: line %d: expecting \"to\" "
1917 "or \"by\" got \"%s\"\n",
1918 fname, lineno, argv[i] );
1923 /* if we have no real access clause, complain and do nothing */
1925 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1926 "warning: no access clause(s) specified in access line.\n",
1932 if ( slap_debug & LDAP_DEBUG_ACL ) {
1937 if ( a->acl_access == NULL ) {
1938 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1939 "warning: no by clause(s) specified in access line.\n",
1945 if ( be->be_nsuffix == NULL ) {
1946 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1947 "scope checking needs suffix before ACLs.\n",
1949 /* go ahead, since checking is not authoritative */
1950 } else if ( !BER_BVISNULL( &be->be_nsuffix[ 1 ] ) ) {
1951 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1952 "scope checking only applies to single-valued "
1953 "suffix databases\n",
1955 /* go ahead, since checking is not authoritative */
1957 switch ( check_scope( be, a ) ) {
1958 case ACL_SCOPE_UNKNOWN:
1959 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1960 "cannot assess the validity of the ACL scope within "
1961 "backend naming context\n",
1965 case ACL_SCOPE_WARN:
1966 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1967 "ACL could be out of scope within backend naming context\n",
1971 case ACL_SCOPE_PARTIAL:
1972 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1973 "ACL appears to be partially out of scope within "
1974 "backend naming context\n",
1979 Debug( LDAP_DEBUG_ACL, "%s: line %d: warning: "
1980 "ACL appears to be out of scope within "
1981 "backend naming context\n",
1989 acl_append( &be->be_acl, a, pos );
1992 acl_append( &frontendDB->be_acl, a, pos );
1999 if ( b ) access_free( b );
2000 if ( a ) acl_free( a );
2005 accessmask2str( slap_mask_t mask, char *buf, int debug )
2010 assert( buf != NULL );
2012 if ( ACL_IS_INVALID( mask ) ) {
2018 if ( ACL_IS_LEVEL( mask ) ) {
2019 if ( ACL_LVL_IS_NONE(mask) ) {
2020 ptr = lutil_strcopy( ptr, "none" );
2022 } else if ( ACL_LVL_IS_DISCLOSE(mask) ) {
2023 ptr = lutil_strcopy( ptr, "disclose" );
2025 } else if ( ACL_LVL_IS_AUTH(mask) ) {
2026 ptr = lutil_strcopy( ptr, "auth" );
2028 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
2029 ptr = lutil_strcopy( ptr, "compare" );
2031 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
2032 ptr = lutil_strcopy( ptr, "search" );
2034 } else if ( ACL_LVL_IS_READ(mask) ) {
2035 ptr = lutil_strcopy( ptr, "read" );
2037 } else if ( ACL_LVL_IS_WRITE(mask) ) {
2038 ptr = lutil_strcopy( ptr, "write" );
2040 } else if ( ACL_LVL_IS_WADD(mask) ) {
2041 ptr = lutil_strcopy( ptr, "add" );
2043 } else if ( ACL_LVL_IS_WDEL(mask) ) {
2044 ptr = lutil_strcopy( ptr, "delete" );
2046 } else if ( ACL_LVL_IS_MANAGE(mask) ) {
2047 ptr = lutil_strcopy( ptr, "manage" );
2050 ptr = lutil_strcopy( ptr, "unknown" );
2060 if( ACL_IS_ADDITIVE( mask ) ) {
2063 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
2070 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_MANAGE) ) {
2075 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
2079 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WADD) ) {
2083 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WDEL) ) {
2088 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
2093 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
2098 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
2103 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
2108 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_DISCLOSE) ) {
2113 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
2122 if ( ACL_IS_LEVEL( mask ) ) {
2132 str2accessmask( const char *str )
2136 if( !ASCII_ALPHA(str[0]) ) {
2139 if ( str[0] == '=' ) {
2142 } else if( str[0] == '+' ) {
2143 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
2145 } else if( str[0] == '-' ) {
2146 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
2149 ACL_INVALIDATE(mask);
2153 for( i=1; str[i] != '\0'; i++ ) {
2154 if( TOLOWER((unsigned char) str[i]) == 'm' ) {
2155 ACL_PRIV_SET(mask, ACL_PRIV_MANAGE);
2157 } else if( TOLOWER((unsigned char) str[i]) == 'w' ) {
2158 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
2160 } else if( TOLOWER((unsigned char) str[i]) == 'a' ) {
2161 ACL_PRIV_SET(mask, ACL_PRIV_WADD);
2163 } else if( TOLOWER((unsigned char) str[i]) == 'z' ) {
2164 ACL_PRIV_SET(mask, ACL_PRIV_WDEL);
2166 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
2167 ACL_PRIV_SET(mask, ACL_PRIV_READ);
2169 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
2170 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
2172 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
2173 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
2175 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
2176 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
2178 } else if( TOLOWER((unsigned char) str[i]) == 'd' ) {
2179 ACL_PRIV_SET(mask, ACL_PRIV_DISCLOSE);
2181 } else if( str[i] == '0' ) {
2182 ACL_PRIV_SET(mask, ACL_PRIV_NONE);
2185 ACL_INVALIDATE(mask);
2193 if ( strcasecmp( str, "none" ) == 0 ) {
2194 ACL_LVL_ASSIGN_NONE(mask);
2196 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2197 ACL_LVL_ASSIGN_DISCLOSE(mask);
2199 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2200 ACL_LVL_ASSIGN_AUTH(mask);
2202 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2203 ACL_LVL_ASSIGN_COMPARE(mask);
2205 } else if ( strcasecmp( str, "search" ) == 0 ) {
2206 ACL_LVL_ASSIGN_SEARCH(mask);
2208 } else if ( strcasecmp( str, "read" ) == 0 ) {
2209 ACL_LVL_ASSIGN_READ(mask);
2211 } else if ( strcasecmp( str, "add" ) == 0 ) {
2212 ACL_LVL_ASSIGN_WADD(mask);
2214 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2215 ACL_LVL_ASSIGN_WDEL(mask);
2217 } else if ( strcasecmp( str, "write" ) == 0 ) {
2218 ACL_LVL_ASSIGN_WRITE(mask);
2220 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2221 ACL_LVL_ASSIGN_MANAGE(mask);
2224 ACL_INVALIDATE( mask );
2234 "<access clause> ::= access to <what> "
2235 "[ by <who> [ <access> ] [ <control> ] ]+ \n";
2237 "<what> ::= * | dn[.<dnstyle>=<DN>] [filter=<filter>] [attrs=<attrspec>]\n"
2238 "<attrspec> ::= <attrname> [val[/<matchingRule>][.<attrstyle>]=<value>] | <attrlist>\n"
2239 "<attrlist> ::= <attr> [ , <attrlist> ]\n"
2240 "<attr> ::= <attrname> | @<objectClass> | !<objectClass> | entry | children\n";
2243 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
2244 "\t[ realanonymous | realusers | realself | realdn[.<dnstyle>]=<DN> ]\n"
2245 "\t[dnattr=<attrname>]\n"
2246 "\t[realdnattr=<attrname>]\n"
2247 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
2248 "\t[peername[.<peernamestyle>]=<peer>] [sockname[.<style>]=<name>]\n"
2249 "\t[domain[.<domainstyle>]=<domain>] [sockurl[.<style>]=<url>]\n"
2251 "\t[dynacl/<name>[/<options>][.<dynstyle>][=<pattern>]]\n"
2252 #endif /* SLAP_DYNACL */
2253 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
2254 "<style> ::= exact | regex | base(Object)\n"
2255 "<dnstyle> ::= base(Object) | one(level) | sub(tree) | children | "
2257 "<attrstyle> ::= exact | regex | base(Object) | one(level) | "
2258 "sub(tree) | children\n"
2259 "<peernamestyle> ::= exact | regex | ip | ipv6 | path\n"
2260 "<domainstyle> ::= exact | regex | base(Object) | sub(tree)\n"
2261 "<access> ::= [[real]self]{<level>|<priv>}\n"
2262 "<level> ::= none|disclose|auth|compare|search|read|{write|add|delete}|manage\n"
2263 "<priv> ::= {=|+|-}{0|d|x|c|s|r|{w|a|z}|m}+\n"
2264 "<control> ::= [ stop | continue | break ]\n"
2266 #ifdef SLAPD_ACI_ENABLED
2268 "\t<name>=ACI\t<pattern>=<attrname>\n"
2269 #endif /* SLAPD_ACI_ENABLED */
2270 #endif /* ! SLAP_DYNACL */
2273 Debug( LDAP_DEBUG_ANY, "%s%s%s\n", access, what, who );
2279 * Set pattern to a "normalized" DN from src.
2280 * At present it simply eats the (optional) space after
2281 * a RDN separator (,)
2282 * Eventually will evolve in a more complete normalization
2285 acl_regex_normalized_dn(
2287 struct berval *pattern )
2292 str = ch_strdup( src );
2293 len = strlen( src );
2295 for ( p = str; p && p[0]; p++ ) {
2297 if ( p[0] == '\\' && p[1] ) {
2299 * if escaping a hex pair we should
2300 * increment p twice; however, in that
2301 * case the second hex number does
2307 if ( p[0] == ',' && p[1] == ' ' ) {
2311 * too much space should be an error if we are pedantic
2313 for ( q = &p[2]; q[0] == ' '; q++ ) {
2316 AC_MEMCPY( p+1, q, len-(q-str)+1);
2319 pattern->bv_val = str;
2320 pattern->bv_len = p - str;
2333 if ( (*right = strchr( line, splitchar )) != NULL ) {
2334 *((*right)++) = '\0';
2339 access_append( Access **l, Access *a )
2341 for ( ; *l != NULL; l = &(*l)->a_next ) {
2349 acl_append( AccessControl **l, AccessControl *a, int pos )
2353 for (i=0 ; i != pos && *l != NULL; l = &(*l)->acl_next, i++ ) {
2362 access_free( Access *a )
2364 if ( !BER_BVISNULL( &a->a_dn_pat ) ) {
2365 free( a->a_dn_pat.bv_val );
2367 if ( !BER_BVISNULL( &a->a_realdn_pat ) ) {
2368 free( a->a_realdn_pat.bv_val );
2370 if ( !BER_BVISNULL( &a->a_peername_pat ) ) {
2371 free( a->a_peername_pat.bv_val );
2373 if ( !BER_BVISNULL( &a->a_sockname_pat ) ) {
2374 free( a->a_sockname_pat.bv_val );
2376 if ( !BER_BVISNULL( &a->a_domain_pat ) ) {
2377 free( a->a_domain_pat.bv_val );
2379 if ( !BER_BVISNULL( &a->a_sockurl_pat ) ) {
2380 free( a->a_sockurl_pat.bv_val );
2382 if ( !BER_BVISNULL( &a->a_set_pat ) ) {
2383 free( a->a_set_pat.bv_val );
2385 if ( !BER_BVISNULL( &a->a_group_pat ) ) {
2386 free( a->a_group_pat.bv_val );
2389 if ( a->a_dynacl != NULL ) {
2391 for ( da = a->a_dynacl; da; ) {
2392 slap_dynacl_t *tmp = da;
2396 if ( tmp->da_destroy ) {
2397 tmp->da_destroy( tmp->da_private );
2403 #endif /* SLAP_DYNACL */
2408 acl_free( AccessControl *a )
2413 if ( a->acl_filter ) {
2414 filter_free( a->acl_filter );
2416 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2417 if ( a->acl_dn_style == ACL_STYLE_REGEX ) {
2418 regfree( &a->acl_dn_re );
2420 free ( a->acl_dn_pat.bv_val );
2422 if ( a->acl_attrs ) {
2423 for ( an = a->acl_attrs; !BER_BVISNULL( &an->an_name ); an++ ) {
2424 free( an->an_name.bv_val );
2426 free( a->acl_attrs );
2428 if ( a->acl_attrval_style == ACL_STYLE_REGEX ) {
2429 regfree( &a->acl_attrval_re );
2432 if ( !BER_BVISNULL( &a->acl_attrval ) ) {
2433 ber_memfree( a->acl_attrval.bv_val );
2436 for ( ; a->acl_access; a->acl_access = n ) {
2437 n = a->acl_access->a_next;
2438 access_free( a->acl_access );
2444 acl_destroy( AccessControl *a )
2448 for ( ; a; a = n ) {
2455 access2str( slap_access_t access )
2457 if ( access == ACL_NONE ) {
2460 } else if ( access == ACL_DISCLOSE ) {
2463 } else if ( access == ACL_AUTH ) {
2466 } else if ( access == ACL_COMPARE ) {
2469 } else if ( access == ACL_SEARCH ) {
2472 } else if ( access == ACL_READ ) {
2475 } else if ( access == ACL_WRITE ) {
2478 } else if ( access == ACL_WADD ) {
2481 } else if ( access == ACL_WDEL ) {
2484 } else if ( access == ACL_MANAGE ) {
2493 str2access( const char *str )
2495 if ( strcasecmp( str, "none" ) == 0 ) {
2498 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2499 return ACL_DISCLOSE;
2501 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2504 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2507 } else if ( strcasecmp( str, "search" ) == 0 ) {
2510 } else if ( strcasecmp( str, "read" ) == 0 ) {
2513 } else if ( strcasecmp( str, "write" ) == 0 ) {
2516 } else if ( strcasecmp( str, "add" ) == 0 ) {
2519 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2522 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2526 return( ACL_INVALID_ACCESS );
2529 #define ACLBUF_MAXLEN 8192
2531 static char aclbuf[ACLBUF_MAXLEN];
2534 dnaccess2text( slap_dn_access *bdn, char *ptr, int is_realdn )
2539 ptr = lutil_strcopy( ptr, "real" );
2542 if ( ber_bvccmp( &bdn->a_pat, '*' ) ||
2543 bdn->a_style == ACL_STYLE_ANONYMOUS ||
2544 bdn->a_style == ACL_STYLE_USERS ||
2545 bdn->a_style == ACL_STYLE_SELF )
2548 assert( ! ber_bvccmp( &bdn->a_pat, '*' ) );
2551 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2552 if ( bdn->a_style == ACL_STYLE_SELF && bdn->a_self_level != 0 ) {
2553 int n = sprintf( ptr, ".level{%d}", bdn->a_self_level );
2560 ptr = lutil_strcopy( ptr, "dn." );
2561 if ( bdn->a_style == ACL_STYLE_BASE )
2562 ptr = lutil_strcopy( ptr, style_base );
2564 ptr = lutil_strcopy( ptr, style_strings[bdn->a_style] );
2565 if ( bdn->a_style == ACL_STYLE_LEVEL ) {
2566 int n = sprintf( ptr, "{%d}", bdn->a_level );
2571 if ( bdn->a_expand ) {
2572 ptr = lutil_strcopy( ptr, ",expand" );
2576 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2583 access2text( Access *b, char *ptr )
2585 char maskbuf[ACCESSMASK_MAXLEN];
2587 ptr = lutil_strcopy( ptr, "\tby" );
2589 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
2590 ptr = dnaccess2text( &b->a_dn, ptr, 0 );
2593 ptr = lutil_strcopy( ptr, " dnattr=" );
2594 ptr = lutil_strcopy( ptr, b->a_dn_at->ad_cname.bv_val );
2597 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
2598 ptr = dnaccess2text( &b->a_realdn, ptr, 1 );
2600 if ( b->a_realdn_at ) {
2601 ptr = lutil_strcopy( ptr, " realdnattr=" );
2602 ptr = lutil_strcopy( ptr, b->a_realdn_at->ad_cname.bv_val );
2605 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
2606 ptr = lutil_strcopy( ptr, " group/" );
2607 ptr = lutil_strcopy( ptr, b->a_group_oc ?
2608 b->a_group_oc->soc_cname.bv_val : SLAPD_GROUP_CLASS );
2610 ptr = lutil_strcopy( ptr, b->a_group_at ?
2611 b->a_group_at->ad_cname.bv_val : SLAPD_GROUP_ATTR );
2613 ptr = lutil_strcopy( ptr, style_strings[b->a_group_style] );
2616 ptr = lutil_strcopy( ptr, b->a_group_pat.bv_val );
2620 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
2621 ptr = lutil_strcopy( ptr, " peername" );
2623 ptr = lutil_strcopy( ptr, style_strings[b->a_peername_style] );
2626 ptr = lutil_strcopy( ptr, b->a_peername_pat.bv_val );
2630 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
2631 ptr = lutil_strcopy( ptr, " sockname" );
2633 ptr = lutil_strcopy( ptr, style_strings[b->a_sockname_style] );
2636 ptr = lutil_strcopy( ptr, b->a_sockname_pat.bv_val );
2640 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
2641 ptr = lutil_strcopy( ptr, " domain" );
2643 ptr = lutil_strcopy( ptr, style_strings[b->a_domain_style] );
2644 if ( b->a_domain_expand ) {
2645 ptr = lutil_strcopy( ptr, ",expand" );
2648 ptr = lutil_strcopy( ptr, b->a_domain_pat.bv_val );
2651 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
2652 ptr = lutil_strcopy( ptr, " sockurl" );
2654 ptr = lutil_strcopy( ptr, style_strings[b->a_sockurl_style] );
2657 ptr = lutil_strcopy( ptr, b->a_sockurl_pat.bv_val );
2661 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
2662 ptr = lutil_strcopy( ptr, " set" );
2664 ptr = lutil_strcopy( ptr, style_strings[b->a_set_style] );
2667 ptr = lutil_strcopy( ptr, b->a_set_pat.bv_val );
2672 if ( b->a_dynacl ) {
2675 for ( da = b->a_dynacl; da; da = da->da_next ) {
2676 if ( da->da_unparse ) {
2677 struct berval bv = BER_BVNULL;
2678 (void)( *da->da_unparse )( da->da_private, &bv );
2679 assert( !BER_BVISNULL( &bv ) );
2680 ptr = lutil_strcopy( ptr, bv.bv_val );
2681 ch_free( bv.bv_val );
2685 #endif /* SLAP_DYNACL */
2687 /* Security Strength Factors */
2688 if ( b->a_authz.sai_ssf ) {
2689 ptr += sprintf( ptr, " ssf=%u",
2690 b->a_authz.sai_ssf );
2692 if ( b->a_authz.sai_transport_ssf ) {
2693 ptr += sprintf( ptr, " transport_ssf=%u",
2694 b->a_authz.sai_transport_ssf );
2696 if ( b->a_authz.sai_tls_ssf ) {
2697 ptr += sprintf( ptr, " tls_ssf=%u",
2698 b->a_authz.sai_tls_ssf );
2700 if ( b->a_authz.sai_sasl_ssf ) {
2701 ptr += sprintf( ptr, " sasl_ssf=%u",
2702 b->a_authz.sai_sasl_ssf );
2706 if ( b->a_dn_self ) {
2707 ptr = lutil_strcopy( ptr, "self" );
2708 } else if ( b->a_realdn_self ) {
2709 ptr = lutil_strcopy( ptr, "realself" );
2711 ptr = lutil_strcopy( ptr, accessmask2str( b->a_access_mask, maskbuf, 0 ));
2712 if ( !maskbuf[0] ) ptr--;
2714 if( b->a_type == ACL_BREAK ) {
2715 ptr = lutil_strcopy( ptr, " break" );
2717 } else if( b->a_type == ACL_CONTINUE ) {
2718 ptr = lutil_strcopy( ptr, " continue" );
2720 } else if( b->a_type != ACL_STOP ) {
2721 ptr = lutil_strcopy( ptr, " unknown-control" );
2723 if ( !maskbuf[0] ) ptr = lutil_strcopy( ptr, " stop" );
2731 acl_unparse( AccessControl *a, struct berval *bv )
2737 bv->bv_val = aclbuf;
2742 ptr = lutil_strcopy( ptr, "to" );
2743 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2745 ptr = lutil_strcopy( ptr, " dn." );
2746 if ( a->acl_dn_style == ACL_STYLE_BASE )
2747 ptr = lutil_strcopy( ptr, style_base );
2749 ptr = lutil_strcopy( ptr, style_strings[a->acl_dn_style] );
2752 ptr = lutil_strcopy( ptr, a->acl_dn_pat.bv_val );
2753 ptr = lutil_strcopy( ptr, "\"\n" );
2756 if ( a->acl_filter != NULL ) {
2757 struct berval bv = BER_BVNULL;
2760 filter2bv( a->acl_filter, &bv );
2761 ptr = lutil_strcopy( ptr, " filter=\"" );
2762 ptr = lutil_strcopy( ptr, bv.bv_val );
2765 ch_free( bv.bv_val );
2768 if ( a->acl_attrs != NULL ) {
2773 ptr = lutil_strcopy( ptr, " attrs=" );
2774 for ( an = a->acl_attrs; an && !BER_BVISNULL( &an->an_name ); an++ ) {
2775 if ( ! first ) *ptr++ = ',';
2777 *ptr++ = ( an->an_flags & SLAP_AN_OCEXCLUDE ) ? '!' : '@';
2778 ptr = lutil_strcopy( ptr, an->an_oc->soc_cname.bv_val );
2781 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2788 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
2790 ptr = lutil_strcopy( ptr, " val." );
2791 if ( a->acl_attrval_style == ACL_STYLE_BASE &&
2792 a->acl_attrs[0].an_desc->ad_type->sat_syntax ==
2793 slap_schema.si_syn_distinguishedName )
2794 ptr = lutil_strcopy( ptr, style_base );
2796 ptr = lutil_strcopy( ptr, style_strings[a->acl_attrval_style] );
2799 ptr = lutil_strcopy( ptr, a->acl_attrval.bv_val );
2805 ptr = lutil_strcopy( ptr, " *\n" );
2808 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
2809 ptr = access2text( b, ptr );
2812 bv->bv_len = ptr - bv->bv_val;
2817 print_acl( Backend *be, AccessControl *a )
2821 acl_unparse( a, &bv );
2822 fprintf( stderr, "%s ACL: access %s\n",
2823 be == NULL ? "Global" : "Backend", bv.bv_val );
2825 #endif /* LDAP_DEBUG */