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 char *style_strings[] = {
58 static void split(char *line, int splitchar, char **left, char **right);
59 static void access_append(Access **l, Access *a);
60 static void acl_usage(void) LDAP_GCCATTR((noreturn));
62 static void acl_regex_normalized_dn(const char *src, struct berval *pat);
65 static void print_acl(Backend *be, AccessControl *a);
68 static int check_scope( BackendDB *be, AccessControl *a );
72 slap_dynacl_config( const char *fname, int lineno, Access *b, const char *name, slap_style_t sty, const char *right )
74 slap_dynacl_t *da, *tmp;
77 for ( da = b->a_dynacl; da; da = da->da_next ) {
78 if ( strcasecmp( da->da_name, name ) == 0 ) {
80 "%s: line %d: dynacl \"%s\" already specified.\n",
81 fname, lineno, name );
86 da = slap_dynacl_get( name );
91 tmp = ch_malloc( sizeof( slap_dynacl_t ) );
94 if ( tmp->da_parse ) {
95 rc = ( *tmp->da_parse )( fname, lineno, sty, right, &tmp->da_private );
102 tmp->da_next = b->a_dynacl;
107 #endif /* SLAP_DYNACL */
110 regtest(const char *fname, int lineno, char *pat) {
126 for (size = 0, flag = 0; (size < sizeof(buf)) && *sp; sp++) {
128 if (*sp == '$'|| (*sp >= '0' && *sp <= '9')) {
145 if ( size >= (sizeof(buf) - 1) ) {
147 "%s: line %d: regular expression \"%s\" too large\n",
148 fname, lineno, pat );
152 if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
154 regerror(e, &re, error, sizeof(error));
156 "%s: line %d: regular expression \"%s\" bad because of %s\n",
157 fname, lineno, pat, error );
166 * Check if the pattern of an ACL, if any, matches the scope
167 * of the backend it is defined within.
169 #define ACL_SCOPE_UNKNOWN (-2)
170 #define ACL_SCOPE_ERR (-1)
171 #define ACL_SCOPE_OK (0)
172 #define ACL_SCOPE_PARTIAL (1)
173 #define ACL_SCOPE_WARN (2)
176 check_scope( BackendDB *be, AccessControl *a )
181 dn = be->be_nsuffix[0];
183 if ( BER_BVISEMPTY( &dn ) ) {
187 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
188 a->acl_dn_style != ACL_STYLE_REGEX )
190 slap_style_t style = a->acl_dn_style;
192 if ( style == ACL_STYLE_REGEX ) {
193 char dnbuf[SLAP_LDAPDN_MAXLEN + 2];
194 char rebuf[SLAP_LDAPDN_MAXLEN + 1];
199 /* add trailing '$' to database suffix to form
200 * a simple trial regex pattern "<suffix>$" */
201 AC_MEMCPY( dnbuf, be->be_nsuffix[0].bv_val,
202 be->be_nsuffix[0].bv_len );
203 dnbuf[be->be_nsuffix[0].bv_len] = '$';
204 dnbuf[be->be_nsuffix[0].bv_len + 1] = '\0';
206 if ( regcomp( &re, dnbuf, REG_EXTENDED|REG_ICASE ) ) {
207 return ACL_SCOPE_WARN;
210 /* remove trailing ')$', if any, from original
212 rebuflen = a->acl_dn_pat.bv_len;
213 AC_MEMCPY( rebuf, a->acl_dn_pat.bv_val, rebuflen + 1 );
214 if ( rebuf[rebuflen - 1] == '$' ) {
215 rebuf[--rebuflen] = '\0';
217 while ( rebuflen > be->be_nsuffix[0].bv_len && rebuf[rebuflen - 1] == ')' ) {
218 rebuf[--rebuflen] = '\0';
220 if ( rebuflen == be->be_nsuffix[0].bv_len ) {
225 /* not a clear indication of scoping error, though */
226 rc = regexec( &re, rebuf, 0, NULL, 0 )
227 ? ACL_SCOPE_WARN : ACL_SCOPE_OK;
234 patlen = a->acl_dn_pat.bv_len;
235 /* If backend suffix is longer than pattern,
236 * it is a potential mismatch (in the sense
237 * that a superior naming context could
239 if ( dn.bv_len > patlen ) {
240 /* base is blatantly wrong */
241 if ( style == ACL_STYLE_BASE ) return ACL_SCOPE_ERR;
243 /* a style of one can be wrong if there is
244 * more than one level between the suffix
246 if ( style == ACL_STYLE_ONE ) {
247 int rdnlen = -1, sep = 0;
250 if ( !DN_SEPARATOR( dn.bv_val[dn.bv_len - patlen - 1] )) {
251 return ACL_SCOPE_ERR;
256 rdnlen = dn_rdnlen( NULL, &dn );
257 if ( rdnlen != dn.bv_len - patlen - sep )
258 return ACL_SCOPE_ERR;
261 /* if the trailing part doesn't match,
262 * then it's an error */
263 if ( strcmp( a->acl_dn_pat.bv_val,
264 &dn.bv_val[dn.bv_len - patlen] ) != 0 )
266 return ACL_SCOPE_ERR;
269 return ACL_SCOPE_PARTIAL;
275 case ACL_STYLE_CHILDREN:
276 case ACL_STYLE_SUBTREE:
284 if ( dn.bv_len < patlen &&
285 !DN_SEPARATOR( a->acl_dn_pat.bv_val[patlen - dn.bv_len - 1] ))
287 return ACL_SCOPE_ERR;
290 if ( strcmp( &a->acl_dn_pat.bv_val[patlen - dn.bv_len], dn.bv_val )
293 return ACL_SCOPE_ERR;
299 return ACL_SCOPE_UNKNOWN;
312 char *left, *right, *style, *next;
320 for ( i = 1; i < argc; i++ ) {
321 /* to clause - select which entries are protected */
322 if ( strcasecmp( argv[i], "to" ) == 0 ) {
324 fprintf( stderr, "%s: line %d: "
325 "only one to clause allowed in access line\n",
329 a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
330 for ( ++i; i < argc; i++ ) {
331 if ( strcasecmp( argv[i], "by" ) == 0 ) {
336 if ( strcasecmp( argv[i], "*" ) == 0 ) {
337 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
338 a->acl_dn_style != ACL_STYLE_REGEX )
341 "%s: line %d: dn pattern"
342 " already specified in to clause.\n",
347 ber_str2bv( "*", STRLENOF( "*" ), 1, &a->acl_dn_pat );
351 split( argv[i], '=', &left, &right );
352 split( left, '.', &left, &style );
354 if ( right == NULL ) {
355 fprintf( stderr, "%s: line %d: "
356 "missing \"=\" in \"%s\" in to clause\n",
357 fname, lineno, left );
361 if ( strcasecmp( left, "dn" ) == 0 ) {
362 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
363 a->acl_dn_style != ACL_STYLE_REGEX )
366 "%s: line %d: dn pattern"
367 " already specified in to clause.\n",
372 if ( style == NULL || *style == '\0' ||
373 strcasecmp( style, "baseObject" ) == 0 ||
374 strcasecmp( style, "base" ) == 0 ||
375 strcasecmp( style, "exact" ) == 0 )
377 a->acl_dn_style = ACL_STYLE_BASE;
378 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
380 } else if ( strcasecmp( style, "oneLevel" ) == 0 ||
381 strcasecmp( style, "one" ) == 0 )
383 a->acl_dn_style = ACL_STYLE_ONE;
384 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
386 } else if ( strcasecmp( style, "subtree" ) == 0 ||
387 strcasecmp( style, "sub" ) == 0 )
389 if( *right == '\0' ) {
390 ber_str2bv( "*", STRLENOF( "*" ), 1, &a->acl_dn_pat );
393 a->acl_dn_style = ACL_STYLE_SUBTREE;
394 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
397 } else if ( strcasecmp( style, "children" ) == 0 ) {
398 a->acl_dn_style = ACL_STYLE_CHILDREN;
399 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
401 } else if ( strcasecmp( style, "regex" ) == 0 ) {
402 a->acl_dn_style = ACL_STYLE_REGEX;
404 if ( *right == '\0' ) {
405 /* empty regex should match empty DN */
406 a->acl_dn_style = ACL_STYLE_BASE;
407 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
409 } else if ( strcmp(right, "*") == 0
410 || strcmp(right, ".*") == 0
411 || strcmp(right, ".*$") == 0
412 || strcmp(right, "^.*") == 0
413 || strcmp(right, "^.*$") == 0
414 || strcmp(right, ".*$$") == 0
415 || strcmp(right, "^.*$$") == 0 )
417 ber_str2bv( "*", STRLENOF("*"), 1, &a->acl_dn_pat );
420 acl_regex_normalized_dn( right, &a->acl_dn_pat );
424 fprintf( stderr, "%s: line %d: "
425 "unknown dn style \"%s\" in to clause\n",
426 fname, lineno, style );
433 if ( strcasecmp( left, "filter" ) == 0 ) {
434 if ( (a->acl_filter = str2filter( right )) == NULL ) {
436 "%s: line %d: bad filter \"%s\" in to clause\n",
437 fname, lineno, right );
441 } else if ( strcasecmp( left, "attr" ) == 0 /* TOLERATED */
442 || strcasecmp( left, "attrs" ) == 0 ) /* DOCUMENTED */
444 a->acl_attrs = str2anlist( a->acl_attrs,
446 if ( a->acl_attrs == NULL ) {
448 "%s: line %d: unknown attr \"%s\" in to clause\n",
449 fname, lineno, right );
453 } else if ( strncasecmp( left, "val", 3 ) == 0 ) {
454 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
456 "%s: line %d: attr val already specified in to clause.\n",
460 if ( a->acl_attrs == NULL || !BER_BVISEMPTY( &a->acl_attrs[1].an_name ) )
463 "%s: line %d: attr val requires a single attribute.\n",
467 ber_str2bv( right, 0, 1, &a->acl_attrval );
468 a->acl_attrval_style = ACL_STYLE_BASE;
469 if ( style != NULL ) {
470 if ( strcasecmp( style, "regex" ) == 0 ) {
471 int e = regcomp( &a->acl_attrval_re, a->acl_attrval.bv_val,
472 REG_EXTENDED | REG_ICASE | REG_NOSUB );
475 regerror( e, &a->acl_attrval_re, buf, sizeof(buf) );
476 fprintf( stderr, "%s: line %d: "
477 "regular expression \"%s\" bad because of %s\n",
478 fname, lineno, right, buf );
481 a->acl_attrval_style = ACL_STYLE_REGEX;
484 /* FIXME: if the attribute has DN syntax, we might
485 * allow one, subtree and children styles as well */
486 if ( !strcasecmp( style, "base" ) ||
487 !strcasecmp( style, "exact" ) ) {
488 a->acl_attrval_style = ACL_STYLE_BASE;
490 } else if ( a->acl_attrs[0].an_desc->ad_type->
491 sat_syntax == slap_schema.si_syn_distinguishedName )
493 if ( !strcasecmp( style, "baseObject" ) ||
494 !strcasecmp( style, "base" ) )
496 a->acl_attrval_style = ACL_STYLE_BASE;
497 } else if ( !strcasecmp( style, "onelevel" ) ||
498 !strcasecmp( style, "one" ) )
500 a->acl_attrval_style = ACL_STYLE_ONE;
501 } else if ( !strcasecmp( style, "subtree" ) ||
502 !strcasecmp( style, "sub" ) )
504 a->acl_attrval_style = ACL_STYLE_SUBTREE;
505 } else if ( !strcasecmp( style, "children" ) ) {
506 a->acl_attrval_style = ACL_STYLE_CHILDREN;
509 "%s: line %d: unknown val.<style> \"%s\" "
510 "for attributeType \"%s\" with DN syntax; "
512 fname, lineno, style,
513 a->acl_attrs[0].an_desc->ad_cname.bv_val );
514 a->acl_attrval_style = ACL_STYLE_BASE;
519 "%s: line %d: unknown val.<style> \"%s\" "
520 "for attributeType \"%s\"; using \"exact\"\n",
521 fname, lineno, style,
522 a->acl_attrs[0].an_desc->ad_cname.bv_val );
523 a->acl_attrval_style = ACL_STYLE_BASE;
530 "%s: line %d: expecting <what> got \"%s\"\n",
531 fname, lineno, left );
536 if ( !BER_BVISNULL( &a->acl_dn_pat ) &&
537 ber_bvccmp( &a->acl_dn_pat, '*' ) )
539 free( a->acl_dn_pat.bv_val );
540 BER_BVZERO( &a->acl_dn_pat );
543 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
544 a->acl_dn_style != ACL_STYLE_REGEX )
546 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
548 rc = dnNormalize( 0, NULL, NULL, &a->acl_dn_pat, &bv, NULL);
549 if ( rc != LDAP_SUCCESS ) {
551 "%s: line %d: bad DN \"%s\" in to DN clause\n",
552 fname, lineno, a->acl_dn_pat.bv_val );
555 free( a->acl_dn_pat.bv_val );
559 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
560 REG_EXTENDED | REG_ICASE );
563 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
564 fprintf( stderr, "%s: line %d: "
565 "regular expression \"%s\" bad because of %s\n",
566 fname, lineno, right, buf );
572 /* by clause - select who has what access to entries */
573 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
575 fprintf( stderr, "%s: line %d: "
576 "to clause required before by clause in access line\n",
582 * by clause consists of <who> and <access>
585 b = (Access *) ch_calloc( 1, sizeof(Access) );
587 ACL_INVALIDATE( b->a_access_mask );
591 "%s: line %d: premature eol: expecting <who>\n",
597 for ( ; i < argc; i++ ) {
598 slap_style_t sty = ACL_STYLE_REGEX;
599 char *style_modifier = NULL;
600 char *style_level = NULL;
603 slap_dn_access *bdn = &b->a_dn;
606 split( argv[i], '=', &left, &right );
607 split( left, '.', &left, &style );
609 split( style, ',', &style, &style_modifier );
611 if ( strncasecmp( style, "level", STRLENOF( "level" ) ) == 0 ) {
612 split( style, '{', &style, &style_level );
613 if ( style_level != NULL ) {
614 char *p = strchr( style_level, '}' );
617 "%s: line %d: premature eol: "
618 "expecting closing '}' in \"level{n}\"\n",
621 } else if ( p == style_level ) {
623 "%s: line %d: empty level "
633 if ( style == NULL || *style == '\0' ||
634 strcasecmp( style, "exact" ) == 0 ||
635 strcasecmp( style, "baseObject" ) == 0 ||
636 strcasecmp( style, "base" ) == 0 )
638 sty = ACL_STYLE_BASE;
640 } else if ( strcasecmp( style, "onelevel" ) == 0 ||
641 strcasecmp( style, "one" ) == 0 )
645 } else if ( strcasecmp( style, "subtree" ) == 0 ||
646 strcasecmp( style, "sub" ) == 0 )
648 sty = ACL_STYLE_SUBTREE;
650 } else if ( strcasecmp( style, "children" ) == 0 ) {
651 sty = ACL_STYLE_CHILDREN;
653 } else if ( strcasecmp( style, "level" ) == 0 )
657 level = strtol( style_level, &next, 10 );
658 if ( next[0] != '\0' ) {
660 "%s: line %d: unable to parse level "
666 sty = ACL_STYLE_LEVEL;
668 } else if ( strcasecmp( style, "regex" ) == 0 ) {
669 sty = ACL_STYLE_REGEX;
671 } else if ( strcasecmp( style, "expand" ) == 0 ) {
672 sty = ACL_STYLE_EXPAND;
674 } else if ( strcasecmp( style, "ip" ) == 0 ) {
677 } else if ( strcasecmp( style, "path" ) == 0 ) {
678 sty = ACL_STYLE_PATH;
679 #ifndef LDAP_PF_LOCAL
680 fprintf( stderr, "%s: line %d: "
681 "path style modifier is useless without local\n",
683 #endif /* LDAP_PF_LOCAL */
687 "%s: line %d: unknown style \"%s\" in by clause\n",
688 fname, lineno, style );
692 if ( style_modifier &&
693 strcasecmp( style_modifier, "expand" ) == 0 )
696 case ACL_STYLE_REGEX:
697 fprintf( stderr, "%s: line %d: "
698 "\"regex\" style implies "
699 "\"expand\" modifier (ignored)\n",
703 case ACL_STYLE_EXPAND:
705 /* FIXME: now it's legal... */
706 fprintf( stderr, "%s: line %d: "
707 "\"expand\" style used "
708 "in conjunction with "
709 "\"expand\" modifier (ignored)\n",
715 /* we'll see later if it's pertinent */
721 /* expand in <who> needs regex in <what> */
722 if ( ( sty == ACL_STYLE_EXPAND || expand )
723 && a->acl_dn_style != ACL_STYLE_REGEX )
725 fprintf( stderr, "%s: line %d: "
726 "\"expand\" style or modifier used "
727 "in conjunction with "
728 "a non-regex <what> clause\n",
732 if ( strncasecmp( left, "real", STRLENOF( "real" ) ) == 0 ) {
735 left += STRLENOF( "real" );
738 if ( strcasecmp( left, "*" ) == 0 ) {
743 ber_str2bv( "*", STRLENOF( "*" ), 1, &bv );
744 sty = ACL_STYLE_REGEX;
746 } else if ( strcasecmp( left, "anonymous" ) == 0 ) {
747 ber_str2bv("anonymous", STRLENOF( "anonymous" ), 1, &bv);
748 sty = ACL_STYLE_ANONYMOUS;
750 } else if ( strcasecmp( left, "users" ) == 0 ) {
751 ber_str2bv("users", STRLENOF( "users" ), 1, &bv);
752 sty = ACL_STYLE_USERS;
754 } else if ( strcasecmp( left, "self" ) == 0 ) {
755 ber_str2bv("self", STRLENOF( "self" ), 1, &bv);
756 sty = ACL_STYLE_SELF;
758 } else if ( strcasecmp( left, "dn" ) == 0 ) {
759 if ( sty == ACL_STYLE_REGEX ) {
760 bdn->a_style = ACL_STYLE_REGEX;
761 if ( right == NULL ) {
766 bdn->a_style = ACL_STYLE_USERS;
768 } else if (*right == '\0' ) {
770 ber_str2bv("anonymous",
771 STRLENOF( "anonymous" ),
773 bdn->a_style = ACL_STYLE_ANONYMOUS;
775 } else if ( strcmp( right, "*" ) == 0 ) {
777 /* any or users? users for now */
781 bdn->a_style = ACL_STYLE_USERS;
783 } else if ( strcmp( right, ".+" ) == 0
784 || strcmp( right, "^.+" ) == 0
785 || strcmp( right, ".+$" ) == 0
786 || strcmp( right, "^.+$" ) == 0
787 || strcmp( right, ".+$$" ) == 0
788 || strcmp( right, "^.+$$" ) == 0 )
793 bdn->a_style = ACL_STYLE_USERS;
795 } else if ( strcmp( right, ".*" ) == 0
796 || strcmp( right, "^.*" ) == 0
797 || strcmp( right, ".*$" ) == 0
798 || strcmp( right, "^.*$" ) == 0
799 || strcmp( right, ".*$$" ) == 0
800 || strcmp( right, "^.*$$" ) == 0 )
807 acl_regex_normalized_dn( right, &bv );
808 if ( !ber_bvccmp( &bv, '*' ) ) {
809 regtest( fname, lineno, bv.bv_val );
813 } else if ( right == NULL || *right == '\0' ) {
814 fprintf( stderr, "%s: line %d: "
815 "missing \"=\" in (or value after) \"%s\" "
817 fname, lineno, left );
821 ber_str2bv( right, 0, 1, &bv );
828 if ( !BER_BVISNULL( &bv ) ) {
829 if ( !BER_BVISEMPTY( &bdn->a_pat ) ) {
831 "%s: line %d: dn pattern already specified.\n",
836 if ( sty != ACL_STYLE_REGEX &&
837 sty != ACL_STYLE_ANONYMOUS &&
838 sty != ACL_STYLE_USERS &&
839 sty != ACL_STYLE_SELF &&
842 rc = dnNormalize(0, NULL, NULL,
843 &bv, &bdn->a_pat, NULL);
844 if ( rc != LDAP_SUCCESS ) {
846 "%s: line %d: bad DN \"%s\" in by DN clause\n",
847 fname, lineno, bv.bv_val );
856 bdn->a_expand = expand;
857 if ( sty == ACL_STYLE_SELF ) {
858 bdn->a_self_level = level;
863 "%s: line %d: bad negative level \"%d\" "
865 fname, lineno, level );
867 } else if ( level == 1 ) {
869 "%s: line %d: \"onelevel\" should be used "
870 "instead of \"level{1}\" in by DN clause\n",
872 } else if ( level == 0 && sty == ACL_STYLE_LEVEL ) {
874 "%s: line %d: \"base\" should be used "
875 "instead of \"level{0}\" in by DN clause\n",
879 bdn->a_level = level;
884 if ( strcasecmp( left, "dnattr" ) == 0 ) {
885 if ( right == NULL || right[0] == '\0' ) {
886 fprintf( stderr, "%s: line %d: "
887 "missing \"=\" in (or value after) \"%s\" "
889 fname, lineno, left );
893 if( bdn->a_at != NULL ) {
895 "%s: line %d: dnattr already specified.\n",
900 rc = slap_str2ad( right, &bdn->a_at, &text );
902 if( rc != LDAP_SUCCESS ) {
904 "%s: line %d: dnattr \"%s\": %s\n",
905 fname, lineno, right, text );
910 if( !is_at_syntax( bdn->a_at->ad_type,
912 !is_at_syntax( bdn->a_at->ad_type,
913 SLAPD_NAMEUID_SYNTAX ))
916 "%s: line %d: dnattr \"%s\": "
917 "inappropriate syntax: %s\n",
918 fname, lineno, right,
919 bdn->a_at->ad_type->sat_syntax_oid );
923 if( bdn->a_at->ad_type->sat_equality == NULL ) {
925 "%s: line %d: dnattr \"%s\": "
926 "inappropriate matching (no EQUALITY)\n",
927 fname, lineno, right );
934 if ( strncasecmp( left, "group", STRLENOF( "group" ) ) == 0 ) {
939 case ACL_STYLE_REGEX:
940 /* legacy, tolerated */
941 fprintf( stderr, "%s: line %d: "
942 "deprecated group style \"regex\"; "
943 "use \"expand\" instead\n",
944 fname, lineno, style );
945 sty = ACL_STYLE_EXPAND;
949 /* legal, traditional */
950 case ACL_STYLE_EXPAND:
951 /* legal, substring expansion; supersedes regex */
956 fprintf( stderr, "%s: line %d: "
957 "inappropriate style \"%s\" in by clause\n",
958 fname, lineno, style );
962 if ( right == NULL || right[0] == '\0' ) {
963 fprintf( stderr, "%s: line %d: "
964 "missing \"=\" in (or value after) \"%s\" "
966 fname, lineno, left );
970 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
972 "%s: line %d: group pattern already specified.\n",
977 /* format of string is
978 "group/objectClassValue/groupAttrName" */
979 if ( ( value = strchr(left, '/') ) != NULL ) {
981 if ( *value && ( name = strchr( value, '/' ) ) != NULL ) {
986 b->a_group_style = sty;
987 if ( sty == ACL_STYLE_EXPAND ) {
988 acl_regex_normalized_dn( right, &bv );
989 if ( !ber_bvccmp( &bv, '*' ) ) {
990 regtest( fname, lineno, bv.bv_val );
995 ber_str2bv( right, 0, 0, &bv );
996 rc = dnNormalize( 0, NULL, NULL, &bv,
997 &b->a_group_pat, NULL );
998 if ( rc != LDAP_SUCCESS ) {
1000 "%s: line %d: bad DN \"%s\"\n",
1001 fname, lineno, right );
1006 if ( value && *value ) {
1007 b->a_group_oc = oc_find( value );
1010 if ( b->a_group_oc == NULL ) {
1012 "%s: line %d: group objectclass "
1014 fname, lineno, value );
1019 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
1021 if( b->a_group_oc == NULL ) {
1023 "%s: line %d: group default objectclass "
1025 fname, lineno, SLAPD_GROUP_CLASS );
1030 if ( is_object_subclass( slap_schema.si_oc_referral,
1034 "%s: line %d: group objectclass \"%s\" "
1035 "is subclass of referral\n",
1036 fname, lineno, value );
1040 if ( is_object_subclass( slap_schema.si_oc_alias,
1044 "%s: line %d: group objectclass \"%s\" "
1045 "is subclass of alias\n",
1046 fname, lineno, value );
1050 if ( name && *name ) {
1051 rc = slap_str2ad( name, &b->a_group_at, &text );
1053 if( rc != LDAP_SUCCESS ) {
1055 "%s: line %d: group \"%s\": %s\n",
1056 fname, lineno, right, text );
1062 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
1064 if ( rc != LDAP_SUCCESS ) {
1066 "%s: line %d: group \"%s\": %s\n",
1067 fname, lineno, SLAPD_GROUP_ATTR, text );
1072 if ( !is_at_syntax( b->a_group_at->ad_type,
1073 SLAPD_DN_SYNTAX ) &&
1074 !is_at_syntax( b->a_group_at->ad_type,
1075 SLAPD_NAMEUID_SYNTAX ) &&
1076 !is_at_subtype( b->a_group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ) )
1079 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
1080 fname, lineno, right,
1081 b->a_group_at->ad_type->sat_syntax_oid );
1088 struct berval vals[2];
1090 ber_str2bv( b->a_group_oc->soc_oid, 0, 0, &vals[0] );
1091 BER_BVZERO( &vals[1] );
1093 rc = oc_check_allowed( b->a_group_at->ad_type,
1097 fprintf( stderr, "%s: line %d: "
1098 "group: \"%s\" not allowed by \"%s\"\n",
1100 b->a_group_at->ad_cname.bv_val,
1101 b->a_group_oc->soc_oid );
1108 if ( strcasecmp( left, "peername" ) == 0 ) {
1110 case ACL_STYLE_REGEX:
1111 case ACL_STYLE_BASE:
1112 /* legal, traditional */
1113 case ACL_STYLE_EXPAND:
1114 /* cheap replacement to regex for simple expansion */
1116 case ACL_STYLE_PATH:
1117 /* legal, peername specific */
1121 fprintf( stderr, "%s: line %d: "
1122 "inappropriate style \"%s\" in by clause\n",
1123 fname, lineno, style );
1127 if ( right == NULL || right[0] == '\0' ) {
1128 fprintf( stderr, "%s: line %d: "
1129 "missing \"=\" in (or value after) \"%s\" "
1131 fname, lineno, left );
1135 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1136 fprintf( stderr, "%s: line %d: "
1137 "peername pattern already specified.\n",
1142 b->a_peername_style = sty;
1143 if ( sty == ACL_STYLE_REGEX ) {
1144 acl_regex_normalized_dn( right, &bv );
1145 if ( !ber_bvccmp( &bv, '*' ) ) {
1146 regtest( fname, lineno, bv.bv_val );
1148 b->a_peername_pat = bv;
1151 ber_str2bv( right, 0, 1, &b->a_peername_pat );
1153 if ( sty == ACL_STYLE_IP ) {
1158 split( right, '{', &addr, &port );
1159 split( addr, '%', &addr, &mask );
1161 b->a_peername_addr = inet_addr( addr );
1162 if ( b->a_peername_addr == (unsigned long)(-1) ) {
1163 /* illegal address */
1164 fprintf( stderr, "%s: line %d: "
1165 "illegal peername address \"%s\".\n",
1166 fname, lineno, addr );
1170 b->a_peername_mask = (unsigned long)(-1);
1171 if ( mask != NULL ) {
1172 b->a_peername_mask = inet_addr( mask );
1173 if ( b->a_peername_mask ==
1174 (unsigned long)(-1) )
1177 fprintf( stderr, "%s: line %d: "
1178 "illegal peername address mask "
1180 fname, lineno, mask );
1185 b->a_peername_port = -1;
1189 b->a_peername_port = strtol( port, &end, 10 );
1190 if ( end[0] != '}' ) {
1192 fprintf( stderr, "%s: line %d: "
1193 "illegal peername port specification "
1195 fname, lineno, port );
1204 if ( strcasecmp( left, "sockname" ) == 0 ) {
1206 case ACL_STYLE_REGEX:
1207 case ACL_STYLE_BASE:
1208 /* legal, traditional */
1209 case ACL_STYLE_EXPAND:
1210 /* cheap replacement to regex for simple expansion */
1215 fprintf( stderr, "%s: line %d: "
1216 "inappropriate style \"%s\" in by clause\n",
1217 fname, lineno, style );
1221 if ( right == NULL || right[0] == '\0' ) {
1222 fprintf( stderr, "%s: line %d: "
1223 "missing \"=\" in (or value after) \"%s\" "
1225 fname, lineno, left );
1229 if ( !BER_BVISNULL( &b->a_sockname_pat ) ) {
1230 fprintf( stderr, "%s: line %d: "
1231 "sockname pattern already specified.\n",
1236 b->a_sockname_style = sty;
1237 if ( sty == ACL_STYLE_REGEX ) {
1238 acl_regex_normalized_dn( right, &bv );
1239 if ( !ber_bvccmp( &bv, '*' ) ) {
1240 regtest( fname, lineno, bv.bv_val );
1242 b->a_sockname_pat = bv;
1245 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
1250 if ( strcasecmp( left, "domain" ) == 0 ) {
1252 case ACL_STYLE_REGEX:
1253 case ACL_STYLE_BASE:
1254 case ACL_STYLE_SUBTREE:
1255 /* legal, traditional */
1258 case ACL_STYLE_EXPAND:
1259 /* tolerated: means exact,expand */
1263 "\"expand\" modifier "
1264 "with \"expand\" style\n",
1267 sty = ACL_STYLE_BASE;
1273 fprintf( stderr, "%s: line %d: "
1274 "inappropriate style \"%s\" in by clause\n",
1275 fname, lineno, style );
1279 if ( right == NULL || right[0] == '\0' ) {
1280 fprintf( stderr, "%s: line %d: "
1281 "missing \"=\" in (or value after) \"%s\" "
1283 fname, lineno, left );
1287 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1289 "%s: line %d: domain pattern already specified.\n",
1294 b->a_domain_style = sty;
1295 b->a_domain_expand = expand;
1296 if ( sty == ACL_STYLE_REGEX ) {
1297 acl_regex_normalized_dn( right, &bv );
1298 if ( !ber_bvccmp( &bv, '*' ) ) {
1299 regtest( fname, lineno, bv.bv_val );
1301 b->a_domain_pat = bv;
1304 ber_str2bv( right, 0, 1, &b->a_domain_pat );
1309 if ( strcasecmp( left, "sockurl" ) == 0 ) {
1311 case ACL_STYLE_REGEX:
1312 case ACL_STYLE_BASE:
1313 /* legal, traditional */
1314 case ACL_STYLE_EXPAND:
1315 /* cheap replacement to regex for simple expansion */
1320 fprintf( stderr, "%s: line %d: "
1321 "inappropriate style \"%s\" in by clause\n",
1322 fname, lineno, style );
1326 if ( right == NULL || right[0] == '\0' ) {
1327 fprintf( stderr, "%s: line %d: "
1328 "missing \"=\" in (or value after) \"%s\" "
1330 fname, lineno, left );
1334 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1336 "%s: line %d: sockurl pattern already specified.\n",
1341 b->a_sockurl_style = sty;
1342 if ( sty == ACL_STYLE_REGEX ) {
1343 acl_regex_normalized_dn( right, &bv );
1344 if ( !ber_bvccmp( &bv, '*' ) ) {
1345 regtest( fname, lineno, bv.bv_val );
1347 b->a_sockurl_pat = bv;
1350 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
1355 if ( strcasecmp( left, "set" ) == 0 ) {
1358 case ACL_STYLE_REGEX:
1359 fprintf( stderr, "%s: line %d: "
1360 "deprecated set style "
1361 "\"regex\" in <by> clause; "
1362 "use \"expand\" instead\n",
1364 sty = ACL_STYLE_EXPAND;
1367 case ACL_STYLE_BASE:
1368 case ACL_STYLE_EXPAND:
1372 fprintf( stderr, "%s: line %d: "
1373 "inappropriate style \"%s\" in by clause\n",
1374 fname, lineno, style );
1378 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1380 "%s: line %d: set attribute already specified.\n",
1385 if ( right == NULL || *right == '\0' ) {
1387 "%s: line %d: no set is defined\n",
1392 b->a_set_style = sty;
1393 ber_str2bv( right, 0, 1, &b->a_set_pat );
1402 if ( strcasecmp( left, "aci" ) == 0 ) {
1405 } else if ( strncasecmp( left, "dynacl/", STRLENOF( "dynacl/" ) ) == 0 ) {
1406 name = &left[ STRLENOF( "dynacl/" ) ];
1410 if ( slap_dynacl_config( fname, lineno, b, name, sty, right ) ) {
1411 fprintf( stderr, "%s: line %d: "
1412 "unable to configure dynacl \"%s\"\n",
1413 fname, lineno, name );
1420 #else /* ! SLAP_DYNACL */
1422 #ifdef SLAPD_ACI_ENABLED
1423 if ( strcasecmp( left, "aci" ) == 0 ) {
1424 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1425 fprintf( stderr, "%s: line %d: "
1426 "inappropriate style \"%s\" in by clause\n",
1427 fname, lineno, style );
1431 if( b->a_aci_at != NULL ) {
1433 "%s: line %d: aci attribute already specified.\n",
1438 if ( right != NULL && *right != '\0' ) {
1439 rc = slap_str2ad( right, &b->a_aci_at, &text );
1441 if( rc != LDAP_SUCCESS ) {
1443 "%s: line %d: aci \"%s\": %s\n",
1444 fname, lineno, right, text );
1449 b->a_aci_at = slap_schema.si_ad_aci;
1452 if( !is_at_syntax( b->a_aci_at->ad_type,
1455 fprintf( stderr, "%s: line %d: "
1456 "aci \"%s\": inappropriate syntax: %s\n",
1457 fname, lineno, right,
1458 b->a_aci_at->ad_type->sat_syntax_oid );
1464 #endif /* SLAPD_ACI_ENABLED */
1465 #endif /* ! SLAP_DYNACL */
1467 if ( strcasecmp( left, "ssf" ) == 0 ) {
1468 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1469 fprintf( stderr, "%s: line %d: "
1470 "inappropriate style \"%s\" in by clause\n",
1471 fname, lineno, style );
1475 if ( b->a_authz.sai_ssf ) {
1477 "%s: line %d: ssf attribute already specified.\n",
1482 if ( right == NULL || *right == '\0' ) {
1484 "%s: line %d: no ssf is defined\n",
1489 b->a_authz.sai_ssf = strtol( right, &next, 10 );
1490 if ( next == NULL || next[0] != '\0' ) {
1492 "%s: line %d: unable to parse ssf value (%s)\n",
1493 fname, lineno, right );
1497 if ( !b->a_authz.sai_ssf ) {
1499 "%s: line %d: invalid ssf value (%s)\n",
1500 fname, lineno, right );
1506 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
1507 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1508 fprintf( stderr, "%s: line %d: "
1509 "inappropriate style \"%s\" in by clause\n",
1510 fname, lineno, style );
1514 if ( b->a_authz.sai_transport_ssf ) {
1515 fprintf( stderr, "%s: line %d: "
1516 "transport_ssf attribute already specified.\n",
1521 if ( right == NULL || *right == '\0' ) {
1523 "%s: line %d: no transport_ssf is defined\n",
1528 b->a_authz.sai_transport_ssf = strtol( right, &next, 10 );
1529 if ( next == NULL || next[0] != '\0' ) {
1530 fprintf( stderr, "%s: line %d: "
1531 "unable to parse transport_ssf value (%s)\n",
1532 fname, lineno, right );
1536 if ( !b->a_authz.sai_transport_ssf ) {
1538 "%s: line %d: invalid transport_ssf value (%s)\n",
1539 fname, lineno, right );
1545 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
1546 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1547 fprintf( stderr, "%s: line %d: "
1548 "inappropriate style \"%s\" in by clause\n",
1549 fname, lineno, style );
1553 if ( b->a_authz.sai_tls_ssf ) {
1554 fprintf( stderr, "%s: line %d: "
1555 "tls_ssf attribute already specified.\n",
1560 if ( right == NULL || *right == '\0' ) {
1562 "%s: line %d: no tls_ssf is defined\n",
1567 b->a_authz.sai_tls_ssf = strtol( right, &next, 10 );
1568 if ( next == NULL || next[0] != '\0' ) {
1569 fprintf( stderr, "%s: line %d: "
1570 "unable to parse tls_ssf value (%s)\n",
1571 fname, lineno, right );
1575 if ( !b->a_authz.sai_tls_ssf ) {
1577 "%s: line %d: invalid tls_ssf value (%s)\n",
1578 fname, lineno, right );
1584 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1585 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1586 fprintf( stderr, "%s: line %d: "
1587 "inappropriate style \"%s\" in by clause\n",
1588 fname, lineno, style );
1592 if ( b->a_authz.sai_sasl_ssf ) {
1593 fprintf( stderr, "%s: line %d: "
1594 "sasl_ssf attribute already specified.\n",
1599 if ( right == NULL || *right == '\0' ) {
1601 "%s: line %d: no sasl_ssf is defined\n",
1606 b->a_authz.sai_sasl_ssf = strtol( right, &next, 10 );
1607 if ( next == NULL || next[0] != '\0' ) {
1608 fprintf( stderr, "%s: line %d: "
1609 "unable to parse sasl_ssf value (%s)\n",
1610 fname, lineno, right );
1614 if ( !b->a_authz.sai_sasl_ssf ) {
1616 "%s: line %d: invalid sasl_ssf value (%s)\n",
1617 fname, lineno, right );
1623 if ( right != NULL ) {
1630 if ( i == argc || ( strcasecmp( left, "stop" ) == 0 ) ) {
1631 /* out of arguments or plain stop */
1633 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1634 b->a_type = ACL_STOP;
1636 access_append( &a->acl_access, b );
1640 if ( strcasecmp( left, "continue" ) == 0 ) {
1641 /* plain continue */
1643 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1644 b->a_type = ACL_CONTINUE;
1646 access_append( &a->acl_access, b );
1650 if ( strcasecmp( left, "break" ) == 0 ) {
1651 /* plain continue */
1653 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1654 b->a_type = ACL_BREAK;
1656 access_append( &a->acl_access, b );
1660 if ( strcasecmp( left, "by" ) == 0 ) {
1661 /* we've gone too far */
1663 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1664 b->a_type = ACL_STOP;
1666 access_append( &a->acl_access, b );
1671 if ( strncasecmp( left, "self", STRLENOF( "self" ) ) == 0 ) {
1673 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "self" ) ] ) );
1675 } else if ( strncasecmp( left, "realself", STRLENOF( "realself" ) ) == 0 ) {
1676 b->a_realdn_self = 1;
1677 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "realself" ) ] ) );
1680 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1683 if ( ACL_IS_INVALID( b->a_access_mask ) ) {
1685 "%s: line %d: expecting <access> got \"%s\"\n",
1686 fname, lineno, left );
1690 b->a_type = ACL_STOP;
1692 if ( ++i == argc ) {
1693 /* out of arguments or plain stop */
1694 access_append( &a->acl_access, b );
1698 if ( strcasecmp( argv[i], "continue" ) == 0 ) {
1699 /* plain continue */
1700 b->a_type = ACL_CONTINUE;
1702 } else if ( strcasecmp( argv[i], "break" ) == 0 ) {
1703 /* plain continue */
1704 b->a_type = ACL_BREAK;
1706 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1711 access_append( &a->acl_access, b );
1715 "%s: line %d: expecting \"to\" "
1716 "or \"by\" got \"%s\"\n",
1717 fname, lineno, argv[i] );
1722 /* if we have no real access clause, complain and do nothing */
1724 fprintf( stderr, "%s: line %d: "
1725 "warning: no access clause(s) specified in access line\n",
1730 if ( ldap_debug & LDAP_DEBUG_ACL ) {
1735 if ( a->acl_access == NULL ) {
1736 fprintf( stderr, "%s: line %d: "
1737 "warning: no by clause(s) specified in access line\n",
1742 if ( !BER_BVISNULL( &be->be_nsuffix[ 1 ] ) ) {
1743 fprintf( stderr, "%s: line %d: warning: "
1744 "scope checking only applies to single-valued "
1745 "suffix databases\n",
1747 /* go ahead, since checking is not authoritative */
1750 switch ( check_scope( be, a ) ) {
1751 case ACL_SCOPE_UNKNOWN:
1752 fprintf( stderr, "%s: line %d: warning: "
1753 "cannot assess the validity of the ACL scope within "
1754 "backend naming context\n",
1758 case ACL_SCOPE_WARN:
1759 fprintf( stderr, "%s: line %d: warning: "
1760 "ACL could be out of scope within backend naming context\n",
1764 case ACL_SCOPE_PARTIAL:
1765 fprintf( stderr, "%s: line %d: warning: "
1766 "ACL appears to be partially out of scope within "
1767 "backend naming context\n",
1772 fprintf( stderr, "%s: line %d: warning: "
1773 "ACL appears to be out of scope within "
1774 "backend naming context\n",
1781 acl_append( &be->be_acl, a, pos );
1784 acl_append( &frontendDB->be_acl, a, pos );
1790 accessmask2str( slap_mask_t mask, char *buf, int debug )
1795 assert( buf != NULL );
1797 if ( ACL_IS_INVALID( mask ) ) {
1803 if ( ACL_IS_LEVEL( mask ) ) {
1804 if ( ACL_LVL_IS_NONE(mask) ) {
1805 ptr = lutil_strcopy( ptr, "none" );
1807 } else if ( ACL_LVL_IS_DISCLOSE(mask) ) {
1808 ptr = lutil_strcopy( ptr, "disclose" );
1810 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1811 ptr = lutil_strcopy( ptr, "auth" );
1813 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1814 ptr = lutil_strcopy( ptr, "compare" );
1816 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1817 ptr = lutil_strcopy( ptr, "search" );
1819 } else if ( ACL_LVL_IS_READ(mask) ) {
1820 ptr = lutil_strcopy( ptr, "read" );
1822 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1823 ptr = lutil_strcopy( ptr, "write" );
1825 } else if ( ACL_LVL_IS_WADD(mask) ) {
1826 ptr = lutil_strcopy( ptr, "add" );
1828 } else if ( ACL_LVL_IS_WDEL(mask) ) {
1829 ptr = lutil_strcopy( ptr, "delete" );
1831 } else if ( ACL_LVL_IS_MANAGE(mask) ) {
1832 ptr = lutil_strcopy( ptr, "manage" );
1835 ptr = lutil_strcopy( ptr, "unknown" );
1845 if( ACL_IS_ADDITIVE( mask ) ) {
1848 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1855 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_MANAGE) ) {
1860 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1864 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WADD) ) {
1868 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WDEL) ) {
1873 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1878 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1883 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1888 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1893 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_DISCLOSE) ) {
1898 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1907 if ( ACL_IS_LEVEL( mask ) ) {
1917 str2accessmask( const char *str )
1921 if( !ASCII_ALPHA(str[0]) ) {
1924 if ( str[0] == '=' ) {
1927 } else if( str[0] == '+' ) {
1928 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1930 } else if( str[0] == '-' ) {
1931 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1934 ACL_INVALIDATE(mask);
1938 for( i=1; str[i] != '\0'; i++ ) {
1939 if( TOLOWER((unsigned char) str[i]) == 'm' ) {
1940 ACL_PRIV_SET(mask, ACL_PRIV_MANAGE);
1942 } else if( TOLOWER((unsigned char) str[i]) == 'w' ) {
1943 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1945 } else if( TOLOWER((unsigned char) str[i]) == 'a' ) {
1946 ACL_PRIV_SET(mask, ACL_PRIV_WADD);
1948 } else if( TOLOWER((unsigned char) str[i]) == 'z' ) {
1949 ACL_PRIV_SET(mask, ACL_PRIV_WDEL);
1951 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
1952 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1954 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
1955 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1957 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
1958 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1960 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
1961 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1963 } else if( TOLOWER((unsigned char) str[i]) == 'd' ) {
1964 ACL_PRIV_SET(mask, ACL_PRIV_DISCLOSE);
1966 } else if( str[i] != '0' ) {
1967 ACL_INVALIDATE(mask);
1975 if ( strcasecmp( str, "none" ) == 0 ) {
1976 ACL_LVL_ASSIGN_NONE(mask);
1978 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
1979 ACL_LVL_ASSIGN_DISCLOSE(mask);
1981 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1982 ACL_LVL_ASSIGN_AUTH(mask);
1984 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1985 ACL_LVL_ASSIGN_COMPARE(mask);
1987 } else if ( strcasecmp( str, "search" ) == 0 ) {
1988 ACL_LVL_ASSIGN_SEARCH(mask);
1990 } else if ( strcasecmp( str, "read" ) == 0 ) {
1991 ACL_LVL_ASSIGN_READ(mask);
1993 } else if ( strcasecmp( str, "add" ) == 0 ) {
1994 ACL_LVL_ASSIGN_WADD(mask);
1996 } else if ( strcasecmp( str, "delete" ) == 0 ) {
1997 ACL_LVL_ASSIGN_WDEL(mask);
1999 } else if ( strcasecmp( str, "write" ) == 0 ) {
2000 ACL_LVL_ASSIGN_WRITE(mask);
2002 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2003 ACL_LVL_ASSIGN_MANAGE(mask);
2006 ACL_INVALIDATE( mask );
2015 fprintf( stderr, "%s%s%s\n",
2016 "<access clause> ::= access to <what> "
2017 "[ by <who> <access> [ <control> ] ]+ \n"
2018 "<what> ::= * | [dn[.<dnstyle>]=<DN>] [filter=<filter>] [attrs=<attrlist>]\n"
2019 "<attrlist> ::= <attr> [val[.<attrstyle>]=<value>] | <attr> , <attrlist>\n"
2020 "<attr> ::= <attrname> | entry | children\n",
2021 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
2022 "\t[ realanonymous | realusers | realself | realdn[.<dnstyle>]=<DN> ]\n"
2023 "\t[dnattr=<attrname>]\n"
2024 "\t[realdnattr=<attrname>]\n"
2025 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
2026 "\t[peername[.<peernamestyle>]=<peer>] [sockname[.<style>]=<name>]\n"
2027 "\t[domain[.<domainstyle>]=<domain>] [sockurl[.<style>]=<url>]\n"
2028 #ifdef SLAPD_ACI_ENABLED
2029 "\t[aci=[<attrname>]]\n"
2032 "\t[dynacl/<name>[.<dynstyle>][=<pattern>]]\n"
2033 #endif /* SLAP_DYNACL */
2034 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n",
2035 "<style> ::= exact | regex | base(Object)\n"
2036 "<dnstyle> ::= base(Object) | one(level) | sub(tree) | children | "
2038 "<attrstyle> ::= exact | regex | base(Object) | one(level) | "
2039 "sub(tree) | children\n"
2040 "<peernamestyle> ::= exact | regex | ip | path\n"
2041 "<domainstyle> ::= exact | regex | base(Object) | sub(tree)\n"
2042 "<access> ::= [[real]self]{<level>|<priv>}\n"
2043 "<level> ::= none|disclose|auth|compare|search|read|{write|add|delete}|manage\n"
2044 "<priv> ::= {=|+|-}{0|d|x|c|s|r|{w|a|z}|m}+\n"
2045 "<control> ::= [ stop | continue | break ]\n"
2047 exit( EXIT_FAILURE );
2051 * Set pattern to a "normalized" DN from src.
2052 * At present it simply eats the (optional) space after
2053 * a RDN separator (,)
2054 * Eventually will evolve in a more complete normalization
2057 acl_regex_normalized_dn(
2059 struct berval *pattern )
2064 str = ch_strdup( src );
2065 len = strlen( src );
2067 for ( p = str; p && p[0]; p++ ) {
2069 if ( p[0] == '\\' && p[1] ) {
2071 * if escaping a hex pair we should
2072 * increment p twice; however, in that
2073 * case the second hex number does
2079 if ( p[0] == ',' && p[1] == ' ' ) {
2083 * too much space should be an error if we are pedantic
2085 for ( q = &p[2]; q[0] == ' '; q++ ) {
2088 AC_MEMCPY( p+1, q, len-(q-str)+1);
2091 pattern->bv_val = str;
2092 pattern->bv_len = p - str;
2105 if ( (*right = strchr( line, splitchar )) != NULL ) {
2106 *((*right)++) = '\0';
2111 access_append( Access **l, Access *a )
2113 for ( ; *l != NULL; l = &(*l)->a_next ) {
2121 acl_append( AccessControl **l, AccessControl *a, int pos )
2125 for (i=0 ; i != pos && *l != NULL; l = &(*l)->acl_next, i++ ) {
2134 access_free( Access *a )
2136 if ( !BER_BVISNULL( &a->a_dn_pat ) ) {
2137 free( a->a_dn_pat.bv_val );
2139 if ( !BER_BVISNULL( &a->a_realdn_pat ) ) {
2140 free( a->a_realdn_pat.bv_val );
2142 if ( !BER_BVISNULL( &a->a_peername_pat ) ) {
2143 free( a->a_peername_pat.bv_val );
2145 if ( !BER_BVISNULL( &a->a_sockname_pat ) ) {
2146 free( a->a_sockname_pat.bv_val );
2148 if ( !BER_BVISNULL( &a->a_domain_pat ) ) {
2149 free( a->a_domain_pat.bv_val );
2151 if ( !BER_BVISNULL( &a->a_sockurl_pat ) ) {
2152 free( a->a_sockurl_pat.bv_val );
2154 if ( !BER_BVISNULL( &a->a_set_pat ) ) {
2155 free( a->a_set_pat.bv_val );
2157 if ( !BER_BVISNULL( &a->a_group_pat ) ) {
2158 free( a->a_group_pat.bv_val );
2164 acl_free( AccessControl *a )
2169 if ( a->acl_filter ) {
2170 filter_free( a->acl_filter );
2172 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2173 free ( a->acl_dn_pat.bv_val );
2175 if ( a->acl_attrs ) {
2176 for ( an = a->acl_attrs; !BER_BVISNULL( &an->an_name ); an++ ) {
2177 free( an->an_name.bv_val );
2179 free( a->acl_attrs );
2181 for ( ; a->acl_access; a->acl_access = n ) {
2182 n = a->acl_access->a_next;
2183 access_free( a->acl_access );
2188 /* Because backend_startup uses acl_append to tack on the global_acl to
2189 * the end of each backend's acl, we cannot just take one argument and
2190 * merrily free our way to the end of the list. backend_destroy calls us
2191 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
2192 * point. config_destroy calls us with global_acl in arg1 and NULL in
2193 * arg2, so we then proceed to polish off the global_acl.
2196 acl_destroy( AccessControl *a, AccessControl *end )
2200 for (; a && a!= end; a=n) {
2207 access2str( slap_access_t access )
2209 if ( access == ACL_NONE ) {
2212 } else if ( access == ACL_DISCLOSE ) {
2215 } else if ( access == ACL_AUTH ) {
2218 } else if ( access == ACL_COMPARE ) {
2221 } else if ( access == ACL_SEARCH ) {
2224 } else if ( access == ACL_READ ) {
2227 } else if ( access == ACL_WRITE ) {
2230 } else if ( access == ACL_WADD ) {
2233 } else if ( access == ACL_WDEL ) {
2236 } else if ( access == ACL_MANAGE ) {
2245 str2access( const char *str )
2247 if ( strcasecmp( str, "none" ) == 0 ) {
2250 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2251 #ifndef SLAP_ACL_HONOR_DISCLOSE
2252 fprintf( stderr, "str2access: warning, "
2253 "\"disclose\" privilege disabled.\n" );
2254 #endif /* SLAP_ACL_HONOR_DISCLOSE */
2255 return ACL_DISCLOSE;
2257 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2260 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2263 } else if ( strcasecmp( str, "search" ) == 0 ) {
2266 } else if ( strcasecmp( str, "read" ) == 0 ) {
2269 } else if ( strcasecmp( str, "write" ) == 0 ) {
2272 } else if ( strcasecmp( str, "add" ) == 0 ) {
2275 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2278 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2282 return( ACL_INVALID_ACCESS );
2285 #define ACLBUF_MAXLEN 8192
2287 static char aclbuf[ACLBUF_MAXLEN];
2290 dnaccess2text( slap_dn_access *bdn, char *ptr, int is_realdn )
2295 ptr = lutil_strcopy( ptr, "real" );
2298 if ( ber_bvccmp( &bdn->a_pat, '*' ) ||
2299 bdn->a_style == ACL_STYLE_ANONYMOUS ||
2300 bdn->a_style == ACL_STYLE_USERS ||
2301 bdn->a_style == ACL_STYLE_SELF )
2304 assert( ! ber_bvccmp( &bdn->a_pat, '*' ) );
2307 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2308 if ( bdn->a_style == ACL_STYLE_SELF && bdn->a_self_level != 0 ) {
2309 int n = sprintf( ptr, ".level{%d}", bdn->a_self_level );
2316 ptr = lutil_strcopy( ptr, "dn." );
2317 ptr = lutil_strcopy( ptr, style_strings[bdn->a_style] );
2318 if ( bdn->a_style == ACL_STYLE_LEVEL ) {
2319 int n = sprintf( ptr, "{%d}", bdn->a_level );
2324 if ( bdn->a_expand ) {
2325 ptr = lutil_strcopy( ptr, ",expand" );
2329 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2336 access2text( Access *b, char *ptr )
2338 char maskbuf[ACCESSMASK_MAXLEN];
2340 ptr = lutil_strcopy( ptr, "\tby" );
2342 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
2343 ptr = dnaccess2text( &b->a_dn, ptr, 0 );
2346 ptr = lutil_strcopy( ptr, " dnattr=" );
2347 ptr = lutil_strcopy( ptr, b->a_dn_at->ad_cname.bv_val );
2350 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
2351 ptr = dnaccess2text( &b->a_realdn, ptr, 1 );
2353 if ( b->a_realdn_at ) {
2354 ptr = lutil_strcopy( ptr, " realdnattr=" );
2355 ptr = lutil_strcopy( ptr, b->a_realdn_at->ad_cname.bv_val );
2358 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
2359 ptr = lutil_strcopy( ptr, " group/" );
2360 ptr = lutil_strcopy( ptr, b->a_group_oc ?
2361 b->a_group_oc->soc_cname.bv_val : "groupOfNames" );
2363 ptr = lutil_strcopy( ptr, b->a_group_at ?
2364 b->a_group_at->ad_cname.bv_val : "member" );
2366 ptr = lutil_strcopy( ptr, style_strings[b->a_group_style] );
2369 ptr = lutil_strcopy( ptr, b->a_group_pat.bv_val );
2373 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
2374 ptr = lutil_strcopy( ptr, " peername=\"" );
2375 ptr = lutil_strcopy( ptr, b->a_peername_pat.bv_val );
2379 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
2380 ptr = lutil_strcopy( ptr, " sockname=\"" );
2381 ptr = lutil_strcopy( ptr, b->a_sockname_pat.bv_val );
2385 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
2386 ptr = lutil_strcopy( ptr, " domain=" );
2387 ptr = lutil_strcopy( ptr, b->a_domain_pat.bv_val );
2390 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
2391 ptr = lutil_strcopy( ptr, " sockurl=\"" );
2392 ptr = lutil_strcopy( ptr, b->a_sockurl_pat.bv_val );
2396 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
2397 ptr = lutil_strcopy( ptr, " set=\"" );
2398 ptr = lutil_strcopy( ptr, b->a_set_pat.bv_val );
2403 if ( b->a_dynacl ) {
2406 for ( da = b->a_dynacl; da; da = da->da_next ) {
2407 if ( da->da_unparse ) {
2409 (void)( *da->da_unparse )( da->da_private, &bv );
2410 ptr = lutil_strcopy( ptr, bv.bv_val );
2411 ch_free( bv.bv_val );
2415 #else /* ! SLAP_DYNACL */
2416 #ifdef SLAPD_ACI_ENABLED
2417 if ( b->a_aci_at != NULL ) {
2418 ptr = lutil_strcopy( ptr, " aci=" );
2419 ptr = lutil_strcopy( ptr, b->a_aci_at->ad_cname.bv_val );
2422 #endif /* SLAP_DYNACL */
2424 /* Security Strength Factors */
2425 if ( b->a_authz.sai_ssf ) {
2426 ptr += sprintf( ptr, " ssf=%u",
2427 b->a_authz.sai_ssf );
2429 if ( b->a_authz.sai_transport_ssf ) {
2430 ptr += sprintf( ptr, " transport_ssf=%u",
2431 b->a_authz.sai_transport_ssf );
2433 if ( b->a_authz.sai_tls_ssf ) {
2434 ptr += sprintf( ptr, " tls_ssf=%u",
2435 b->a_authz.sai_tls_ssf );
2437 if ( b->a_authz.sai_sasl_ssf ) {
2438 ptr += sprintf( ptr, " sasl_ssf=%u",
2439 b->a_authz.sai_sasl_ssf );
2443 if ( b->a_dn_self ) {
2444 ptr = lutil_strcopy( ptr, "self" );
2445 } else if ( b->a_realdn_self ) {
2446 ptr = lutil_strcopy( ptr, "realself" );
2448 ptr = lutil_strcopy( ptr, accessmask2str( b->a_access_mask, maskbuf, 0 ));
2449 if ( !maskbuf[0] ) ptr--;
2451 if( b->a_type == ACL_BREAK ) {
2452 ptr = lutil_strcopy( ptr, " break" );
2454 } else if( b->a_type == ACL_CONTINUE ) {
2455 ptr = lutil_strcopy( ptr, " continue" );
2457 } else if( b->a_type != ACL_STOP ) {
2458 ptr = lutil_strcopy( ptr, " unknown-control" );
2460 if ( !maskbuf[0] ) ptr = lutil_strcopy( ptr, " stop" );
2468 acl_unparse( AccessControl *a, struct berval *bv )
2474 bv->bv_val = aclbuf;
2479 ptr = lutil_strcopy( ptr, "to" );
2480 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2482 ptr = lutil_strcopy( ptr, " dn." );
2483 ptr = lutil_strcopy( ptr, style_strings[a->acl_dn_style] );
2486 ptr = lutil_strcopy( ptr, a->acl_dn_pat.bv_val );
2487 ptr = lutil_strcopy( ptr, "\"\n" );
2490 if ( a->acl_filter != NULL ) {
2491 struct berval bv = BER_BVNULL;
2494 filter2bv( a->acl_filter, &bv );
2495 ptr = lutil_strcopy( ptr, " filter=\"" );
2496 ptr = lutil_strcopy( ptr, bv.bv_val );
2499 ch_free( bv.bv_val );
2502 if ( a->acl_attrs != NULL ) {
2507 ptr = lutil_strcopy( ptr, " attrs=" );
2508 for ( an = a->acl_attrs; an && !BER_BVISNULL( &an->an_name ); an++ ) {
2509 if ( ! first ) *ptr++ = ',';
2511 *ptr++ = an->an_oc_exclude ? '!' : '@';
2512 ptr = lutil_strcopy( ptr, an->an_oc->soc_cname.bv_val );
2515 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2522 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
2524 ptr = lutil_strcopy( ptr, " val." );
2525 ptr = lutil_strcopy( ptr, style_strings[a->acl_attrval_style] );
2528 ptr = lutil_strcopy( ptr, a->acl_attrval.bv_val );
2534 ptr = lutil_strcopy( ptr, " *\n" );
2537 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
2538 ptr = access2text( b, ptr );
2541 bv->bv_len = ptr - bv->bv_val;
2547 print_acl( Backend *be, AccessControl *a )
2551 acl_unparse( a, &bv );
2552 fprintf( stderr, "%s ACL: access %s\n",
2553 be == NULL ? "Global" : "Backend", bv.bv_val );
2555 #endif /* LDAP_DEBUG */