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, "exact" ) ) {
487 a->acl_attrval_style = ACL_STYLE_BASE;
489 } else if ( a->acl_attrs[0].an_desc->ad_type->
490 sat_syntax == slap_schema.si_syn_distinguishedName )
492 if ( !strcasecmp( style, "baseObject" ) ||
493 !strcasecmp( style, "base" ) )
495 a->acl_attrval_style = ACL_STYLE_BASE;
496 } else if ( !strcasecmp( style, "onelevel" ) ||
497 !strcasecmp( style, "one" ) )
499 a->acl_attrval_style = ACL_STYLE_ONE;
500 } else if ( !strcasecmp( style, "subtree" ) ||
501 !strcasecmp( style, "sub" ) )
503 a->acl_attrval_style = ACL_STYLE_SUBTREE;
504 } else if ( !strcasecmp( style, "children" ) ) {
505 a->acl_attrval_style = ACL_STYLE_CHILDREN;
508 "%s: line %d: unknown val.<style> \"%s\" "
509 "for attributeType \"%s\" with DN syntax; "
511 fname, lineno, style,
512 a->acl_attrs[0].an_desc->ad_cname.bv_val );
513 a->acl_attrval_style = ACL_STYLE_BASE;
518 "%s: line %d: unknown val.<style> \"%s\" "
519 "for attributeType \"%s\"; using \"exact\"\n",
520 fname, lineno, style,
521 a->acl_attrs[0].an_desc->ad_cname.bv_val );
522 a->acl_attrval_style = ACL_STYLE_BASE;
529 "%s: line %d: expecting <what> got \"%s\"\n",
530 fname, lineno, left );
535 if ( !BER_BVISNULL( &a->acl_dn_pat ) &&
536 ber_bvccmp( &a->acl_dn_pat, '*' ) )
538 free( a->acl_dn_pat.bv_val );
539 BER_BVZERO( &a->acl_dn_pat );
542 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
543 a->acl_dn_style != ACL_STYLE_REGEX )
545 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
547 rc = dnNormalize( 0, NULL, NULL, &a->acl_dn_pat, &bv, NULL);
548 if ( rc != LDAP_SUCCESS ) {
550 "%s: line %d: bad DN \"%s\" in to DN clause\n",
551 fname, lineno, a->acl_dn_pat.bv_val );
554 free( a->acl_dn_pat.bv_val );
558 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
559 REG_EXTENDED | REG_ICASE );
562 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
563 fprintf( stderr, "%s: line %d: "
564 "regular expression \"%s\" bad because of %s\n",
565 fname, lineno, right, buf );
571 /* by clause - select who has what access to entries */
572 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
574 fprintf( stderr, "%s: line %d: "
575 "to clause required before by clause in access line\n",
581 * by clause consists of <who> and <access>
584 b = (Access *) ch_calloc( 1, sizeof(Access) );
586 ACL_INVALIDATE( b->a_access_mask );
590 "%s: line %d: premature eol: expecting <who>\n",
596 for ( ; i < argc; i++ ) {
597 slap_style_t sty = ACL_STYLE_REGEX;
598 char *style_modifier = NULL;
599 char *style_level = NULL;
602 slap_dn_access *bdn = &b->a_dn;
605 split( argv[i], '=', &left, &right );
606 split( left, '.', &left, &style );
608 split( style, ',', &style, &style_modifier );
610 if ( strncasecmp( style, "level", STRLENOF( "level" ) ) == 0 ) {
611 split( style, '{', &style, &style_level );
612 if ( style_level != NULL ) {
613 char *p = strchr( style_level, '}' );
616 "%s: line %d: premature eol: "
617 "expecting closing '}' in \"level{n}\"\n",
620 } else if ( p == style_level ) {
622 "%s: line %d: empty level "
632 if ( style == NULL || *style == '\0' ||
633 strcasecmp( style, "exact" ) == 0 ||
634 strcasecmp( style, "baseObject" ) == 0 ||
635 strcasecmp( style, "base" ) == 0 )
637 sty = ACL_STYLE_BASE;
639 } else if ( strcasecmp( style, "onelevel" ) == 0 ||
640 strcasecmp( style, "one" ) == 0 )
644 } else if ( strcasecmp( style, "subtree" ) == 0 ||
645 strcasecmp( style, "sub" ) == 0 )
647 sty = ACL_STYLE_SUBTREE;
649 } else if ( strcasecmp( style, "children" ) == 0 ) {
650 sty = ACL_STYLE_CHILDREN;
652 } else if ( strcasecmp( style, "level" ) == 0 )
656 level = strtol( style_level, &next, 10 );
657 if ( next[0] != '\0' ) {
659 "%s: line %d: unable to parse level "
665 sty = ACL_STYLE_LEVEL;
667 } else if ( strcasecmp( style, "regex" ) == 0 ) {
668 sty = ACL_STYLE_REGEX;
670 } else if ( strcasecmp( style, "expand" ) == 0 ) {
671 sty = ACL_STYLE_EXPAND;
673 } else if ( strcasecmp( style, "ip" ) == 0 ) {
676 } else if ( strcasecmp( style, "path" ) == 0 ) {
677 sty = ACL_STYLE_PATH;
678 #ifndef LDAP_PF_LOCAL
679 fprintf( stderr, "%s: line %d: "
680 "path style modifier is useless without local\n",
682 #endif /* LDAP_PF_LOCAL */
686 "%s: line %d: unknown style \"%s\" in by clause\n",
687 fname, lineno, style );
691 if ( style_modifier &&
692 strcasecmp( style_modifier, "expand" ) == 0 )
695 case ACL_STYLE_REGEX:
696 fprintf( stderr, "%s: line %d: "
697 "\"regex\" style implies "
698 "\"expand\" modifier (ignored)\n",
702 case ACL_STYLE_EXPAND:
704 /* FIXME: now it's legal... */
705 fprintf( stderr, "%s: line %d: "
706 "\"expand\" style used "
707 "in conjunction with "
708 "\"expand\" modifier (ignored)\n",
714 /* we'll see later if it's pertinent */
720 /* expand in <who> needs regex in <what> */
721 if ( ( sty == ACL_STYLE_EXPAND || expand )
722 && a->acl_dn_style != ACL_STYLE_REGEX )
724 fprintf( stderr, "%s: line %d: "
725 "\"expand\" style or modifier used "
726 "in conjunction with "
727 "a non-regex <what> clause\n",
731 if ( strncasecmp( left, "real", STRLENOF( "real" ) ) == 0 ) {
734 left += STRLENOF( "real" );
737 if ( strcasecmp( left, "*" ) == 0 ) {
742 ber_str2bv( "*", STRLENOF( "*" ), 1, &bv );
743 sty = ACL_STYLE_REGEX;
745 } else if ( strcasecmp( left, "anonymous" ) == 0 ) {
746 ber_str2bv("anonymous", STRLENOF( "anonymous" ), 1, &bv);
747 sty = ACL_STYLE_ANONYMOUS;
749 } else if ( strcasecmp( left, "users" ) == 0 ) {
750 ber_str2bv("users", STRLENOF( "users" ), 1, &bv);
751 sty = ACL_STYLE_USERS;
753 } else if ( strcasecmp( left, "self" ) == 0 ) {
754 ber_str2bv("self", STRLENOF( "self" ), 1, &bv);
755 sty = ACL_STYLE_SELF;
757 } else if ( strcasecmp( left, "dn" ) == 0 ) {
758 if ( sty == ACL_STYLE_REGEX ) {
759 bdn->a_style = ACL_STYLE_REGEX;
760 if ( right == NULL ) {
765 bdn->a_style = ACL_STYLE_USERS;
767 } else if (*right == '\0' ) {
769 ber_str2bv("anonymous",
770 STRLENOF( "anonymous" ),
772 bdn->a_style = ACL_STYLE_ANONYMOUS;
774 } else if ( strcmp( right, "*" ) == 0 ) {
776 /* any or users? users for now */
780 bdn->a_style = ACL_STYLE_USERS;
782 } else if ( strcmp( right, ".+" ) == 0
783 || strcmp( right, "^.+" ) == 0
784 || strcmp( right, ".+$" ) == 0
785 || strcmp( right, "^.+$" ) == 0
786 || strcmp( right, ".+$$" ) == 0
787 || strcmp( right, "^.+$$" ) == 0 )
792 bdn->a_style = ACL_STYLE_USERS;
794 } else if ( strcmp( right, ".*" ) == 0
795 || strcmp( right, "^.*" ) == 0
796 || strcmp( right, ".*$" ) == 0
797 || strcmp( right, "^.*$" ) == 0
798 || strcmp( right, ".*$$" ) == 0
799 || strcmp( right, "^.*$$" ) == 0 )
806 acl_regex_normalized_dn( right, &bv );
807 if ( !ber_bvccmp( &bv, '*' ) ) {
808 regtest( fname, lineno, bv.bv_val );
812 } else if ( right == NULL || *right == '\0' ) {
813 fprintf( stderr, "%s: line %d: "
814 "missing \"=\" in (or value after) \"%s\" "
816 fname, lineno, left );
820 ber_str2bv( right, 0, 1, &bv );
827 if ( !BER_BVISNULL( &bv ) ) {
828 if ( !BER_BVISEMPTY( &bdn->a_pat ) ) {
830 "%s: line %d: dn pattern already specified.\n",
835 if ( sty != ACL_STYLE_REGEX &&
836 sty != ACL_STYLE_ANONYMOUS &&
837 sty != ACL_STYLE_USERS &&
838 sty != ACL_STYLE_SELF &&
841 rc = dnNormalize(0, NULL, NULL,
842 &bv, &bdn->a_pat, NULL);
843 if ( rc != LDAP_SUCCESS ) {
845 "%s: line %d: bad DN \"%s\" in by DN clause\n",
846 fname, lineno, bv.bv_val );
855 bdn->a_expand = expand;
856 if ( sty == ACL_STYLE_SELF ) {
857 bdn->a_self_level = level;
862 "%s: line %d: bad negative level \"%d\" "
864 fname, lineno, level );
866 } else if ( level == 1 ) {
868 "%s: line %d: \"onelevel\" should be used "
869 "instead of \"level{1}\" in by DN clause\n",
871 } else if ( level == 0 && sty == ACL_STYLE_LEVEL ) {
873 "%s: line %d: \"base\" should be used "
874 "instead of \"level{0}\" in by DN clause\n",
878 bdn->a_level = level;
883 if ( strcasecmp( left, "dnattr" ) == 0 ) {
884 if ( right == NULL || right[0] == '\0' ) {
885 fprintf( stderr, "%s: line %d: "
886 "missing \"=\" in (or value after) \"%s\" "
888 fname, lineno, left );
892 if( bdn->a_at != NULL ) {
894 "%s: line %d: dnattr already specified.\n",
899 rc = slap_str2ad( right, &bdn->a_at, &text );
901 if( rc != LDAP_SUCCESS ) {
903 "%s: line %d: dnattr \"%s\": %s\n",
904 fname, lineno, right, text );
909 if( !is_at_syntax( bdn->a_at->ad_type,
911 !is_at_syntax( bdn->a_at->ad_type,
912 SLAPD_NAMEUID_SYNTAX ))
915 "%s: line %d: dnattr \"%s\": "
916 "inappropriate syntax: %s\n",
917 fname, lineno, right,
918 bdn->a_at->ad_type->sat_syntax_oid );
922 if( bdn->a_at->ad_type->sat_equality == NULL ) {
924 "%s: line %d: dnattr \"%s\": "
925 "inappropriate matching (no EQUALITY)\n",
926 fname, lineno, right );
933 if ( strncasecmp( left, "group", STRLENOF( "group" ) ) == 0 ) {
938 case ACL_STYLE_REGEX:
939 /* legacy, tolerated */
940 fprintf( stderr, "%s: line %d: "
941 "deprecated group style \"regex\"; "
942 "use \"expand\" instead\n",
943 fname, lineno, style );
944 sty = ACL_STYLE_EXPAND;
948 /* legal, traditional */
949 case ACL_STYLE_EXPAND:
950 /* legal, substring expansion; supersedes regex */
955 fprintf( stderr, "%s: line %d: "
956 "inappropriate style \"%s\" in by clause\n",
957 fname, lineno, style );
961 if ( right == NULL || right[0] == '\0' ) {
962 fprintf( stderr, "%s: line %d: "
963 "missing \"=\" in (or value after) \"%s\" "
965 fname, lineno, left );
969 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
971 "%s: line %d: group pattern already specified.\n",
976 /* format of string is
977 "group/objectClassValue/groupAttrName" */
978 if ( ( value = strchr(left, '/') ) != NULL ) {
980 if ( *value && ( name = strchr( value, '/' ) ) != NULL ) {
985 b->a_group_style = sty;
986 if ( sty == ACL_STYLE_EXPAND ) {
987 acl_regex_normalized_dn( right, &bv );
988 if ( !ber_bvccmp( &bv, '*' ) ) {
989 regtest( fname, lineno, bv.bv_val );
994 ber_str2bv( right, 0, 0, &bv );
995 rc = dnNormalize( 0, NULL, NULL, &bv,
996 &b->a_group_pat, NULL );
997 if ( rc != LDAP_SUCCESS ) {
999 "%s: line %d: bad DN \"%s\"\n",
1000 fname, lineno, right );
1005 if ( value && *value ) {
1006 b->a_group_oc = oc_find( value );
1009 if ( b->a_group_oc == NULL ) {
1011 "%s: line %d: group objectclass "
1013 fname, lineno, value );
1018 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
1020 if( b->a_group_oc == NULL ) {
1022 "%s: line %d: group default objectclass "
1024 fname, lineno, SLAPD_GROUP_CLASS );
1029 if ( is_object_subclass( slap_schema.si_oc_referral,
1033 "%s: line %d: group objectclass \"%s\" "
1034 "is subclass of referral\n",
1035 fname, lineno, value );
1039 if ( is_object_subclass( slap_schema.si_oc_alias,
1043 "%s: line %d: group objectclass \"%s\" "
1044 "is subclass of alias\n",
1045 fname, lineno, value );
1049 if ( name && *name ) {
1050 rc = slap_str2ad( name, &b->a_group_at, &text );
1052 if( rc != LDAP_SUCCESS ) {
1054 "%s: line %d: group \"%s\": %s\n",
1055 fname, lineno, right, text );
1061 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
1063 if ( rc != LDAP_SUCCESS ) {
1065 "%s: line %d: group \"%s\": %s\n",
1066 fname, lineno, SLAPD_GROUP_ATTR, text );
1071 if ( !is_at_syntax( b->a_group_at->ad_type,
1072 SLAPD_DN_SYNTAX ) &&
1073 !is_at_syntax( b->a_group_at->ad_type,
1074 SLAPD_NAMEUID_SYNTAX ) &&
1075 !is_at_subtype( b->a_group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ) )
1078 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
1079 fname, lineno, right,
1080 b->a_group_at->ad_type->sat_syntax_oid );
1087 struct berval vals[2];
1089 ber_str2bv( b->a_group_oc->soc_oid, 0, 0, &vals[0] );
1090 BER_BVZERO( &vals[1] );
1092 rc = oc_check_allowed( b->a_group_at->ad_type,
1096 fprintf( stderr, "%s: line %d: "
1097 "group: \"%s\" not allowed by \"%s\"\n",
1099 b->a_group_at->ad_cname.bv_val,
1100 b->a_group_oc->soc_oid );
1107 if ( strcasecmp( left, "peername" ) == 0 ) {
1109 case ACL_STYLE_REGEX:
1110 case ACL_STYLE_BASE:
1111 /* legal, traditional */
1112 case ACL_STYLE_EXPAND:
1113 /* cheap replacement to regex for simple expansion */
1115 case ACL_STYLE_PATH:
1116 /* legal, peername specific */
1120 fprintf( stderr, "%s: line %d: "
1121 "inappropriate style \"%s\" in by clause\n",
1122 fname, lineno, style );
1126 if ( right == NULL || right[0] == '\0' ) {
1127 fprintf( stderr, "%s: line %d: "
1128 "missing \"=\" in (or value after) \"%s\" "
1130 fname, lineno, left );
1134 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1135 fprintf( stderr, "%s: line %d: "
1136 "peername pattern already specified.\n",
1141 b->a_peername_style = sty;
1142 if ( sty == ACL_STYLE_REGEX ) {
1143 acl_regex_normalized_dn( right, &bv );
1144 if ( !ber_bvccmp( &bv, '*' ) ) {
1145 regtest( fname, lineno, bv.bv_val );
1147 b->a_peername_pat = bv;
1150 ber_str2bv( right, 0, 1, &b->a_peername_pat );
1152 if ( sty == ACL_STYLE_IP ) {
1157 split( right, '{', &addr, &port );
1158 split( addr, '%', &addr, &mask );
1160 b->a_peername_addr = inet_addr( addr );
1161 if ( b->a_peername_addr == (unsigned long)(-1) ) {
1162 /* illegal address */
1163 fprintf( stderr, "%s: line %d: "
1164 "illegal peername address \"%s\".\n",
1165 fname, lineno, addr );
1169 b->a_peername_mask = (unsigned long)(-1);
1170 if ( mask != NULL ) {
1171 b->a_peername_mask = inet_addr( mask );
1172 if ( b->a_peername_mask ==
1173 (unsigned long)(-1) )
1176 fprintf( stderr, "%s: line %d: "
1177 "illegal peername address mask "
1179 fname, lineno, mask );
1184 b->a_peername_port = -1;
1188 b->a_peername_port = strtol( port, &end, 10 );
1189 if ( end[0] != '}' ) {
1191 fprintf( stderr, "%s: line %d: "
1192 "illegal peername port specification "
1194 fname, lineno, port );
1203 if ( strcasecmp( left, "sockname" ) == 0 ) {
1205 case ACL_STYLE_REGEX:
1206 case ACL_STYLE_BASE:
1207 /* legal, traditional */
1208 case ACL_STYLE_EXPAND:
1209 /* cheap replacement to regex for simple expansion */
1214 fprintf( stderr, "%s: line %d: "
1215 "inappropriate style \"%s\" in by clause\n",
1216 fname, lineno, style );
1220 if ( right == NULL || right[0] == '\0' ) {
1221 fprintf( stderr, "%s: line %d: "
1222 "missing \"=\" in (or value after) \"%s\" "
1224 fname, lineno, left );
1228 if ( !BER_BVISNULL( &b->a_sockname_pat ) ) {
1229 fprintf( stderr, "%s: line %d: "
1230 "sockname pattern already specified.\n",
1235 b->a_sockname_style = sty;
1236 if ( sty == ACL_STYLE_REGEX ) {
1237 acl_regex_normalized_dn( right, &bv );
1238 if ( !ber_bvccmp( &bv, '*' ) ) {
1239 regtest( fname, lineno, bv.bv_val );
1241 b->a_sockname_pat = bv;
1244 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
1249 if ( strcasecmp( left, "domain" ) == 0 ) {
1251 case ACL_STYLE_REGEX:
1252 case ACL_STYLE_BASE:
1253 case ACL_STYLE_SUBTREE:
1254 /* legal, traditional */
1257 case ACL_STYLE_EXPAND:
1258 /* tolerated: means exact,expand */
1262 "\"expand\" modifier "
1263 "with \"expand\" style\n",
1266 sty = ACL_STYLE_BASE;
1272 fprintf( stderr, "%s: line %d: "
1273 "inappropriate style \"%s\" in by clause\n",
1274 fname, lineno, style );
1278 if ( right == NULL || right[0] == '\0' ) {
1279 fprintf( stderr, "%s: line %d: "
1280 "missing \"=\" in (or value after) \"%s\" "
1282 fname, lineno, left );
1286 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1288 "%s: line %d: domain pattern already specified.\n",
1293 b->a_domain_style = sty;
1294 b->a_domain_expand = expand;
1295 if ( sty == ACL_STYLE_REGEX ) {
1296 acl_regex_normalized_dn( right, &bv );
1297 if ( !ber_bvccmp( &bv, '*' ) ) {
1298 regtest( fname, lineno, bv.bv_val );
1300 b->a_domain_pat = bv;
1303 ber_str2bv( right, 0, 1, &b->a_domain_pat );
1308 if ( strcasecmp( left, "sockurl" ) == 0 ) {
1310 case ACL_STYLE_REGEX:
1311 case ACL_STYLE_BASE:
1312 /* legal, traditional */
1313 case ACL_STYLE_EXPAND:
1314 /* cheap replacement to regex for simple expansion */
1319 fprintf( stderr, "%s: line %d: "
1320 "inappropriate style \"%s\" in by clause\n",
1321 fname, lineno, style );
1325 if ( right == NULL || right[0] == '\0' ) {
1326 fprintf( stderr, "%s: line %d: "
1327 "missing \"=\" in (or value after) \"%s\" "
1329 fname, lineno, left );
1333 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1335 "%s: line %d: sockurl pattern already specified.\n",
1340 b->a_sockurl_style = sty;
1341 if ( sty == ACL_STYLE_REGEX ) {
1342 acl_regex_normalized_dn( right, &bv );
1343 if ( !ber_bvccmp( &bv, '*' ) ) {
1344 regtest( fname, lineno, bv.bv_val );
1346 b->a_sockurl_pat = bv;
1349 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
1354 if ( strcasecmp( left, "set" ) == 0 ) {
1357 case ACL_STYLE_REGEX:
1358 fprintf( stderr, "%s: line %d: "
1359 "deprecated set style "
1360 "\"regex\" in <by> clause; "
1361 "use \"expand\" instead\n",
1363 sty = ACL_STYLE_EXPAND;
1366 case ACL_STYLE_BASE:
1367 case ACL_STYLE_EXPAND:
1371 fprintf( stderr, "%s: line %d: "
1372 "inappropriate style \"%s\" in by clause\n",
1373 fname, lineno, style );
1377 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1379 "%s: line %d: set attribute already specified.\n",
1384 if ( right == NULL || *right == '\0' ) {
1386 "%s: line %d: no set is defined\n",
1391 b->a_set_style = sty;
1392 ber_str2bv( right, 0, 1, &b->a_set_pat );
1401 if ( strcasecmp( left, "aci" ) == 0 ) {
1404 } else if ( strncasecmp( left, "dynacl/", STRLENOF( "dynacl/" ) ) == 0 ) {
1405 name = &left[ STRLENOF( "dynacl/" ) ];
1409 if ( slap_dynacl_config( fname, lineno, b, name, sty, right ) ) {
1410 fprintf( stderr, "%s: line %d: "
1411 "unable to configure dynacl \"%s\"\n",
1412 fname, lineno, name );
1419 #else /* ! SLAP_DYNACL */
1421 #ifdef SLAPD_ACI_ENABLED
1422 if ( strcasecmp( left, "aci" ) == 0 ) {
1423 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1424 fprintf( stderr, "%s: line %d: "
1425 "inappropriate style \"%s\" in by clause\n",
1426 fname, lineno, style );
1430 if( b->a_aci_at != NULL ) {
1432 "%s: line %d: aci attribute already specified.\n",
1437 if ( right != NULL && *right != '\0' ) {
1438 rc = slap_str2ad( right, &b->a_aci_at, &text );
1440 if( rc != LDAP_SUCCESS ) {
1442 "%s: line %d: aci \"%s\": %s\n",
1443 fname, lineno, right, text );
1448 b->a_aci_at = slap_schema.si_ad_aci;
1451 if( !is_at_syntax( b->a_aci_at->ad_type,
1454 fprintf( stderr, "%s: line %d: "
1455 "aci \"%s\": inappropriate syntax: %s\n",
1456 fname, lineno, right,
1457 b->a_aci_at->ad_type->sat_syntax_oid );
1463 #endif /* SLAPD_ACI_ENABLED */
1464 #endif /* ! SLAP_DYNACL */
1466 if ( strcasecmp( left, "ssf" ) == 0 ) {
1467 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1468 fprintf( stderr, "%s: line %d: "
1469 "inappropriate style \"%s\" in by clause\n",
1470 fname, lineno, style );
1474 if ( b->a_authz.sai_ssf ) {
1476 "%s: line %d: ssf attribute already specified.\n",
1481 if ( right == NULL || *right == '\0' ) {
1483 "%s: line %d: no ssf is defined\n",
1488 b->a_authz.sai_ssf = strtol( right, &next, 10 );
1489 if ( next == NULL || next[0] != '\0' ) {
1491 "%s: line %d: unable to parse ssf value (%s)\n",
1492 fname, lineno, right );
1496 if ( !b->a_authz.sai_ssf ) {
1498 "%s: line %d: invalid ssf value (%s)\n",
1499 fname, lineno, right );
1505 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
1506 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1507 fprintf( stderr, "%s: line %d: "
1508 "inappropriate style \"%s\" in by clause\n",
1509 fname, lineno, style );
1513 if ( b->a_authz.sai_transport_ssf ) {
1514 fprintf( stderr, "%s: line %d: "
1515 "transport_ssf attribute already specified.\n",
1520 if ( right == NULL || *right == '\0' ) {
1522 "%s: line %d: no transport_ssf is defined\n",
1527 b->a_authz.sai_transport_ssf = strtol( right, &next, 10 );
1528 if ( next == NULL || next[0] != '\0' ) {
1529 fprintf( stderr, "%s: line %d: "
1530 "unable to parse transport_ssf value (%s)\n",
1531 fname, lineno, right );
1535 if ( !b->a_authz.sai_transport_ssf ) {
1537 "%s: line %d: invalid transport_ssf value (%s)\n",
1538 fname, lineno, right );
1544 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
1545 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1546 fprintf( stderr, "%s: line %d: "
1547 "inappropriate style \"%s\" in by clause\n",
1548 fname, lineno, style );
1552 if ( b->a_authz.sai_tls_ssf ) {
1553 fprintf( stderr, "%s: line %d: "
1554 "tls_ssf attribute already specified.\n",
1559 if ( right == NULL || *right == '\0' ) {
1561 "%s: line %d: no tls_ssf is defined\n",
1566 b->a_authz.sai_tls_ssf = strtol( right, &next, 10 );
1567 if ( next == NULL || next[0] != '\0' ) {
1568 fprintf( stderr, "%s: line %d: "
1569 "unable to parse tls_ssf value (%s)\n",
1570 fname, lineno, right );
1574 if ( !b->a_authz.sai_tls_ssf ) {
1576 "%s: line %d: invalid tls_ssf value (%s)\n",
1577 fname, lineno, right );
1583 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1584 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1585 fprintf( stderr, "%s: line %d: "
1586 "inappropriate style \"%s\" in by clause\n",
1587 fname, lineno, style );
1591 if ( b->a_authz.sai_sasl_ssf ) {
1592 fprintf( stderr, "%s: line %d: "
1593 "sasl_ssf attribute already specified.\n",
1598 if ( right == NULL || *right == '\0' ) {
1600 "%s: line %d: no sasl_ssf is defined\n",
1605 b->a_authz.sai_sasl_ssf = strtol( right, &next, 10 );
1606 if ( next == NULL || next[0] != '\0' ) {
1607 fprintf( stderr, "%s: line %d: "
1608 "unable to parse sasl_ssf value (%s)\n",
1609 fname, lineno, right );
1613 if ( !b->a_authz.sai_sasl_ssf ) {
1615 "%s: line %d: invalid sasl_ssf value (%s)\n",
1616 fname, lineno, right );
1622 if ( right != NULL ) {
1629 if ( i == argc || ( strcasecmp( left, "stop" ) == 0 ) ) {
1630 /* out of arguments or plain stop */
1632 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1633 b->a_type = ACL_STOP;
1635 access_append( &a->acl_access, b );
1639 if ( strcasecmp( left, "continue" ) == 0 ) {
1640 /* plain continue */
1642 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1643 b->a_type = ACL_CONTINUE;
1645 access_append( &a->acl_access, b );
1649 if ( strcasecmp( left, "break" ) == 0 ) {
1650 /* plain continue */
1652 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1653 b->a_type = ACL_BREAK;
1655 access_append( &a->acl_access, b );
1659 if ( strcasecmp( left, "by" ) == 0 ) {
1660 /* we've gone too far */
1662 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1663 b->a_type = ACL_STOP;
1665 access_append( &a->acl_access, b );
1670 if ( strncasecmp( left, "self", STRLENOF( "self" ) ) == 0 ) {
1672 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "self" ) ] ) );
1674 } else if ( strncasecmp( left, "realself", STRLENOF( "realself" ) ) == 0 ) {
1675 b->a_realdn_self = 1;
1676 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "realself" ) ] ) );
1679 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1682 if ( ACL_IS_INVALID( b->a_access_mask ) ) {
1684 "%s: line %d: expecting <access> got \"%s\"\n",
1685 fname, lineno, left );
1689 b->a_type = ACL_STOP;
1691 if ( ++i == argc ) {
1692 /* out of arguments or plain stop */
1693 access_append( &a->acl_access, b );
1697 if ( strcasecmp( argv[i], "continue" ) == 0 ) {
1698 /* plain continue */
1699 b->a_type = ACL_CONTINUE;
1701 } else if ( strcasecmp( argv[i], "break" ) == 0 ) {
1702 /* plain continue */
1703 b->a_type = ACL_BREAK;
1705 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1710 access_append( &a->acl_access, b );
1714 "%s: line %d: expecting \"to\" "
1715 "or \"by\" got \"%s\"\n",
1716 fname, lineno, argv[i] );
1721 /* if we have no real access clause, complain and do nothing */
1723 fprintf( stderr, "%s: line %d: "
1724 "warning: no access clause(s) specified in access line\n",
1729 if ( ldap_debug & LDAP_DEBUG_ACL ) {
1734 if ( a->acl_access == NULL ) {
1735 fprintf( stderr, "%s: line %d: "
1736 "warning: no by clause(s) specified in access line\n",
1741 if ( !BER_BVISNULL( &be->be_nsuffix[ 1 ] ) ) {
1742 fprintf( stderr, "%s: line %d: warning: "
1743 "scope checking only applies to single-valued "
1744 "suffix databases\n",
1746 /* go ahead, since checking is not authoritative */
1749 switch ( check_scope( be, a ) ) {
1750 case ACL_SCOPE_UNKNOWN:
1751 fprintf( stderr, "%s: line %d: warning: "
1752 "cannot assess the validity of the ACL scope within "
1753 "backend naming context\n",
1757 case ACL_SCOPE_WARN:
1758 fprintf( stderr, "%s: line %d: warning: "
1759 "ACL could be out of scope within backend naming context\n",
1763 case ACL_SCOPE_PARTIAL:
1764 fprintf( stderr, "%s: line %d: warning: "
1765 "ACL appears to be partially out of scope within "
1766 "backend naming context\n",
1771 fprintf( stderr, "%s: line %d: warning: "
1772 "ACL appears to be out of scope within "
1773 "backend naming context\n",
1780 acl_append( &be->be_acl, a, pos );
1783 acl_append( &frontendDB->be_acl, a, pos );
1789 accessmask2str( slap_mask_t mask, char *buf, int debug )
1794 assert( buf != NULL );
1796 if ( ACL_IS_INVALID( mask ) ) {
1802 if ( ACL_IS_LEVEL( mask ) ) {
1803 if ( ACL_LVL_IS_NONE(mask) ) {
1804 ptr = lutil_strcopy( ptr, "none" );
1806 } else if ( ACL_LVL_IS_DISCLOSE(mask) ) {
1807 ptr = lutil_strcopy( ptr, "disclose" );
1809 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1810 ptr = lutil_strcopy( ptr, "auth" );
1812 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1813 ptr = lutil_strcopy( ptr, "compare" );
1815 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1816 ptr = lutil_strcopy( ptr, "search" );
1818 } else if ( ACL_LVL_IS_READ(mask) ) {
1819 ptr = lutil_strcopy( ptr, "read" );
1821 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1822 ptr = lutil_strcopy( ptr, "write" );
1824 } else if ( ACL_LVL_IS_WADD(mask) ) {
1825 ptr = lutil_strcopy( ptr, "add" );
1827 } else if ( ACL_LVL_IS_WDEL(mask) ) {
1828 ptr = lutil_strcopy( ptr, "delete" );
1830 } else if ( ACL_LVL_IS_MANAGE(mask) ) {
1831 ptr = lutil_strcopy( ptr, "manage" );
1834 ptr = lutil_strcopy( ptr, "unknown" );
1844 if( ACL_IS_ADDITIVE( mask ) ) {
1847 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1854 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_MANAGE) ) {
1859 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1863 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WADD) ) {
1867 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WDEL) ) {
1872 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1877 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1882 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1887 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1892 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_DISCLOSE) ) {
1897 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1906 if ( ACL_IS_LEVEL( mask ) ) {
1916 str2accessmask( const char *str )
1920 if( !ASCII_ALPHA(str[0]) ) {
1923 if ( str[0] == '=' ) {
1926 } else if( str[0] == '+' ) {
1927 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1929 } else if( str[0] == '-' ) {
1930 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1933 ACL_INVALIDATE(mask);
1937 for( i=1; str[i] != '\0'; i++ ) {
1938 if( TOLOWER((unsigned char) str[i]) == 'm' ) {
1939 ACL_PRIV_SET(mask, ACL_PRIV_MANAGE);
1941 } else if( TOLOWER((unsigned char) str[i]) == 'w' ) {
1942 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1944 } else if( TOLOWER((unsigned char) str[i]) == 'a' ) {
1945 ACL_PRIV_SET(mask, ACL_PRIV_WADD);
1947 } else if( TOLOWER((unsigned char) str[i]) == 'z' ) {
1948 ACL_PRIV_SET(mask, ACL_PRIV_WDEL);
1950 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
1951 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1953 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
1954 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1956 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
1957 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1959 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
1960 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1962 } else if( TOLOWER((unsigned char) str[i]) == 'd' ) {
1963 ACL_PRIV_SET(mask, ACL_PRIV_DISCLOSE);
1965 } else if( str[i] != '0' ) {
1966 ACL_INVALIDATE(mask);
1974 if ( strcasecmp( str, "none" ) == 0 ) {
1975 ACL_LVL_ASSIGN_NONE(mask);
1977 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
1978 ACL_LVL_ASSIGN_DISCLOSE(mask);
1980 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1981 ACL_LVL_ASSIGN_AUTH(mask);
1983 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1984 ACL_LVL_ASSIGN_COMPARE(mask);
1986 } else if ( strcasecmp( str, "search" ) == 0 ) {
1987 ACL_LVL_ASSIGN_SEARCH(mask);
1989 } else if ( strcasecmp( str, "read" ) == 0 ) {
1990 ACL_LVL_ASSIGN_READ(mask);
1992 } else if ( strcasecmp( str, "add" ) == 0 ) {
1993 ACL_LVL_ASSIGN_WADD(mask);
1995 } else if ( strcasecmp( str, "delete" ) == 0 ) {
1996 ACL_LVL_ASSIGN_WDEL(mask);
1998 } else if ( strcasecmp( str, "write" ) == 0 ) {
1999 ACL_LVL_ASSIGN_WRITE(mask);
2001 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2002 ACL_LVL_ASSIGN_MANAGE(mask);
2005 ACL_INVALIDATE( mask );
2014 fprintf( stderr, "%s%s%s\n",
2015 "<access clause> ::= access to <what> "
2016 "[ by <who> <access> [ <control> ] ]+ \n"
2017 "<what> ::= * | [dn[.<dnstyle>]=<DN>] [filter=<filter>] [attrs=<attrlist>]\n"
2018 "<attrlist> ::= <attr> [val[.<attrstyle>]=<value>] | <attr> , <attrlist>\n"
2019 "<attr> ::= <attrname> | entry | children\n",
2020 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
2021 "\t[ realanonymous | realusers | realself | realdn[.<dnstyle>]=<DN> ]\n"
2022 "\t[dnattr=<attrname>]\n"
2023 "\t[realdnattr=<attrname>]\n"
2024 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
2025 "\t[peername[.<peernamestyle>]=<peer>] [sockname[.<style>]=<name>]\n"
2026 "\t[domain[.<domainstyle>]=<domain>] [sockurl[.<style>]=<url>]\n"
2027 #ifdef SLAPD_ACI_ENABLED
2028 "\t[aci=[<attrname>]]\n"
2031 "\t[dynacl/<name>[.<dynstyle>][=<pattern>]]\n"
2032 #endif /* SLAP_DYNACL */
2033 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n",
2034 "<style> ::= exact | regex | base(Object)\n"
2035 "<dnstyle> ::= base(Object) | one(level) | sub(tree) | children | "
2037 "<attrstyle> ::= exact | regex | base(Object) | one(level) | "
2038 "sub(tree) | children\n"
2039 "<peernamestyle> ::= exact | regex | ip | path\n"
2040 "<domainstyle> ::= exact | regex | base(Object) | sub(tree)\n"
2041 "<access> ::= [[real]self]{<level>|<priv>}\n"
2042 "<level> ::= none|disclose|auth|compare|search|read|{write|add|delete}|manage\n"
2043 "<priv> ::= {=|+|-}{0|d|x|c|s|r|{w|a|z}|m}+\n"
2044 "<control> ::= [ stop | continue | break ]\n"
2046 exit( EXIT_FAILURE );
2050 * Set pattern to a "normalized" DN from src.
2051 * At present it simply eats the (optional) space after
2052 * a RDN separator (,)
2053 * Eventually will evolve in a more complete normalization
2056 acl_regex_normalized_dn(
2058 struct berval *pattern )
2063 str = ch_strdup( src );
2064 len = strlen( src );
2066 for ( p = str; p && p[0]; p++ ) {
2068 if ( p[0] == '\\' && p[1] ) {
2070 * if escaping a hex pair we should
2071 * increment p twice; however, in that
2072 * case the second hex number does
2078 if ( p[0] == ',' && p[1] == ' ' ) {
2082 * too much space should be an error if we are pedantic
2084 for ( q = &p[2]; q[0] == ' '; q++ ) {
2087 AC_MEMCPY( p+1, q, len-(q-str)+1);
2090 pattern->bv_val = str;
2091 pattern->bv_len = p - str;
2104 if ( (*right = strchr( line, splitchar )) != NULL ) {
2105 *((*right)++) = '\0';
2110 access_append( Access **l, Access *a )
2112 for ( ; *l != NULL; l = &(*l)->a_next ) {
2120 acl_append( AccessControl **l, AccessControl *a, int pos )
2124 for (i=0 ; i != pos && *l != NULL; l = &(*l)->acl_next, i++ ) {
2133 access_free( Access *a )
2135 if ( !BER_BVISNULL( &a->a_dn_pat ) ) {
2136 free( a->a_dn_pat.bv_val );
2138 if ( !BER_BVISNULL( &a->a_realdn_pat ) ) {
2139 free( a->a_realdn_pat.bv_val );
2141 if ( !BER_BVISNULL( &a->a_peername_pat ) ) {
2142 free( a->a_peername_pat.bv_val );
2144 if ( !BER_BVISNULL( &a->a_sockname_pat ) ) {
2145 free( a->a_sockname_pat.bv_val );
2147 if ( !BER_BVISNULL( &a->a_domain_pat ) ) {
2148 free( a->a_domain_pat.bv_val );
2150 if ( !BER_BVISNULL( &a->a_sockurl_pat ) ) {
2151 free( a->a_sockurl_pat.bv_val );
2153 if ( !BER_BVISNULL( &a->a_set_pat ) ) {
2154 free( a->a_set_pat.bv_val );
2156 if ( !BER_BVISNULL( &a->a_group_pat ) ) {
2157 free( a->a_group_pat.bv_val );
2163 acl_free( AccessControl *a )
2168 if ( a->acl_filter ) {
2169 filter_free( a->acl_filter );
2171 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2172 free ( a->acl_dn_pat.bv_val );
2174 if ( a->acl_attrs ) {
2175 for ( an = a->acl_attrs; !BER_BVISNULL( &an->an_name ); an++ ) {
2176 free( an->an_name.bv_val );
2178 free( a->acl_attrs );
2180 for ( ; a->acl_access; a->acl_access = n ) {
2181 n = a->acl_access->a_next;
2182 access_free( a->acl_access );
2187 /* Because backend_startup uses acl_append to tack on the global_acl to
2188 * the end of each backend's acl, we cannot just take one argument and
2189 * merrily free our way to the end of the list. backend_destroy calls us
2190 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
2191 * point. config_destroy calls us with global_acl in arg1 and NULL in
2192 * arg2, so we then proceed to polish off the global_acl.
2195 acl_destroy( AccessControl *a, AccessControl *end )
2199 for (; a && a!= end; a=n) {
2206 access2str( slap_access_t access )
2208 if ( access == ACL_NONE ) {
2211 } else if ( access == ACL_DISCLOSE ) {
2214 } else if ( access == ACL_AUTH ) {
2217 } else if ( access == ACL_COMPARE ) {
2220 } else if ( access == ACL_SEARCH ) {
2223 } else if ( access == ACL_READ ) {
2226 } else if ( access == ACL_WRITE ) {
2229 } else if ( access == ACL_WADD ) {
2232 } else if ( access == ACL_WDEL ) {
2235 } else if ( access == ACL_MANAGE ) {
2244 str2access( const char *str )
2246 if ( strcasecmp( str, "none" ) == 0 ) {
2249 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2250 #ifndef SLAP_ACL_HONOR_DISCLOSE
2251 fprintf( stderr, "str2access: warning, "
2252 "\"disclose\" privilege disabled.\n" );
2253 #endif /* SLAP_ACL_HONOR_DISCLOSE */
2254 return ACL_DISCLOSE;
2256 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2259 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2262 } else if ( strcasecmp( str, "search" ) == 0 ) {
2265 } else if ( strcasecmp( str, "read" ) == 0 ) {
2268 } else if ( strcasecmp( str, "write" ) == 0 ) {
2271 } else if ( strcasecmp( str, "add" ) == 0 ) {
2274 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2277 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2281 return( ACL_INVALID_ACCESS );
2284 #define ACLBUF_MAXLEN 8192
2286 static char aclbuf[ACLBUF_MAXLEN];
2289 dnaccess2text( slap_dn_access *bdn, char *ptr, int is_realdn )
2294 ptr = lutil_strcopy( ptr, "real" );
2297 if ( ber_bvccmp( &bdn->a_pat, '*' ) ||
2298 bdn->a_style == ACL_STYLE_ANONYMOUS ||
2299 bdn->a_style == ACL_STYLE_USERS ||
2300 bdn->a_style == ACL_STYLE_SELF )
2303 assert( ! ber_bvccmp( &bdn->a_pat, '*' ) );
2306 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2307 if ( bdn->a_style == ACL_STYLE_SELF && bdn->a_self_level != 0 ) {
2308 int n = sprintf( ptr, ".level{%d}", bdn->a_self_level );
2315 ptr = lutil_strcopy( ptr, "dn." );
2316 ptr = lutil_strcopy( ptr, style_strings[bdn->a_style] );
2317 if ( bdn->a_style == ACL_STYLE_LEVEL ) {
2318 int n = sprintf( ptr, "{%d}", bdn->a_level );
2323 if ( bdn->a_expand ) {
2324 ptr = lutil_strcopy( ptr, ",expand" );
2328 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2335 access2text( Access *b, char *ptr )
2337 char maskbuf[ACCESSMASK_MAXLEN];
2339 ptr = lutil_strcopy( ptr, "\tby" );
2341 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
2342 ptr = dnaccess2text( &b->a_dn, ptr, 0 );
2345 ptr = lutil_strcopy( ptr, " dnattr=" );
2346 ptr = lutil_strcopy( ptr, b->a_dn_at->ad_cname.bv_val );
2349 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
2350 ptr = dnaccess2text( &b->a_realdn, ptr, 1 );
2352 if ( b->a_realdn_at ) {
2353 ptr = lutil_strcopy( ptr, " realdnattr=" );
2354 ptr = lutil_strcopy( ptr, b->a_realdn_at->ad_cname.bv_val );
2357 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
2358 ptr = lutil_strcopy( ptr, " group/" );
2359 ptr = lutil_strcopy( ptr, b->a_group_oc ?
2360 b->a_group_oc->soc_cname.bv_val : "groupOfNames" );
2362 ptr = lutil_strcopy( ptr, b->a_group_at ?
2363 b->a_group_at->ad_cname.bv_val : "member" );
2365 ptr = lutil_strcopy( ptr, style_strings[b->a_group_style] );
2368 ptr = lutil_strcopy( ptr, b->a_group_pat.bv_val );
2372 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
2373 ptr = lutil_strcopy( ptr, " peername=\"" );
2374 ptr = lutil_strcopy( ptr, b->a_peername_pat.bv_val );
2378 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
2379 ptr = lutil_strcopy( ptr, " sockname=\"" );
2380 ptr = lutil_strcopy( ptr, b->a_sockname_pat.bv_val );
2384 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
2385 ptr = lutil_strcopy( ptr, " domain=" );
2386 ptr = lutil_strcopy( ptr, b->a_domain_pat.bv_val );
2389 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
2390 ptr = lutil_strcopy( ptr, " sockurl=\"" );
2391 ptr = lutil_strcopy( ptr, b->a_sockurl_pat.bv_val );
2395 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
2396 ptr = lutil_strcopy( ptr, " set=\"" );
2397 ptr = lutil_strcopy( ptr, b->a_set_pat.bv_val );
2402 if ( b->a_dynacl ) {
2405 for ( da = b->a_dynacl; da; da = da->da_next ) {
2406 if ( da->da_unparse ) {
2408 (void)( *da->da_unparse )( da->da_private, &bv );
2409 ptr = lutil_strcopy( ptr, bv.bv_val );
2410 ch_free( bv.bv_val );
2414 #else /* ! SLAP_DYNACL */
2415 #ifdef SLAPD_ACI_ENABLED
2416 if ( b->a_aci_at != NULL ) {
2417 ptr = lutil_strcopy( ptr, " aci=" );
2418 ptr = lutil_strcopy( ptr, b->a_aci_at->ad_cname.bv_val );
2421 #endif /* SLAP_DYNACL */
2423 /* Security Strength Factors */
2424 if ( b->a_authz.sai_ssf ) {
2425 ptr += sprintf( ptr, " ssf=%u",
2426 b->a_authz.sai_ssf );
2428 if ( b->a_authz.sai_transport_ssf ) {
2429 ptr += sprintf( ptr, " transport_ssf=%u",
2430 b->a_authz.sai_transport_ssf );
2432 if ( b->a_authz.sai_tls_ssf ) {
2433 ptr += sprintf( ptr, " tls_ssf=%u",
2434 b->a_authz.sai_tls_ssf );
2436 if ( b->a_authz.sai_sasl_ssf ) {
2437 ptr += sprintf( ptr, " sasl_ssf=%u",
2438 b->a_authz.sai_sasl_ssf );
2442 if ( b->a_dn_self ) {
2443 ptr = lutil_strcopy( ptr, "self" );
2444 } else if ( b->a_realdn_self ) {
2445 ptr = lutil_strcopy( ptr, "realself" );
2447 ptr = lutil_strcopy( ptr, accessmask2str( b->a_access_mask, maskbuf, 0 ));
2448 if ( !maskbuf[0] ) ptr--;
2450 if( b->a_type == ACL_BREAK ) {
2451 ptr = lutil_strcopy( ptr, " break" );
2453 } else if( b->a_type == ACL_CONTINUE ) {
2454 ptr = lutil_strcopy( ptr, " continue" );
2456 } else if( b->a_type != ACL_STOP ) {
2457 ptr = lutil_strcopy( ptr, " unknown-control" );
2459 if ( !maskbuf[0] ) ptr = lutil_strcopy( ptr, " stop" );
2467 acl_unparse( AccessControl *a, struct berval *bv )
2473 bv->bv_val = aclbuf;
2478 ptr = lutil_strcopy( ptr, "to" );
2479 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2481 ptr = lutil_strcopy( ptr, " dn." );
2482 ptr = lutil_strcopy( ptr, style_strings[a->acl_dn_style] );
2485 ptr = lutil_strcopy( ptr, a->acl_dn_pat.bv_val );
2486 ptr = lutil_strcopy( ptr, "\"\n" );
2489 if ( a->acl_filter != NULL ) {
2490 struct berval bv = BER_BVNULL;
2493 filter2bv( a->acl_filter, &bv );
2494 ptr = lutil_strcopy( ptr, " filter=\"" );
2495 ptr = lutil_strcopy( ptr, bv.bv_val );
2498 ch_free( bv.bv_val );
2501 if ( a->acl_attrs != NULL ) {
2506 ptr = lutil_strcopy( ptr, " attrs=" );
2507 for ( an = a->acl_attrs; an && !BER_BVISNULL( &an->an_name ); an++ ) {
2508 if ( ! first ) *ptr++ = ',';
2510 *ptr++ = an->an_oc_exclude ? '!' : '@';
2511 ptr = lutil_strcopy( ptr, an->an_oc->soc_cname.bv_val );
2514 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2521 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
2523 ptr = lutil_strcopy( ptr, " val." );
2524 ptr = lutil_strcopy( ptr, style_strings[a->acl_attrval_style] );
2527 ptr = lutil_strcopy( ptr, a->acl_attrval.bv_val );
2533 ptr = lutil_strcopy( ptr, " *\n" );
2536 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
2537 ptr = access2text( b, ptr );
2540 bv->bv_len = ptr - bv->bv_val;
2546 print_acl( Backend *be, AccessControl *a )
2550 acl_unparse( a, &bv );
2551 fprintf( stderr, "%s ACL: access %s\n",
2552 be == NULL ? "Global" : "Backend", bv.bv_val );
2554 #endif /* LDAP_DEBUG */