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;
311 char *left, *right, *style, *next;
319 for ( i = 1; i < argc; i++ ) {
320 /* to clause - select which entries are protected */
321 if ( strcasecmp( argv[i], "to" ) == 0 ) {
323 fprintf( stderr, "%s: line %d: "
324 "only one to clause allowed in access line\n",
328 a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
329 for ( ++i; i < argc; i++ ) {
330 if ( strcasecmp( argv[i], "by" ) == 0 ) {
335 if ( strcasecmp( argv[i], "*" ) == 0 ) {
336 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
337 a->acl_dn_style != ACL_STYLE_REGEX )
340 "%s: line %d: dn pattern"
341 " already specified in to clause.\n",
346 ber_str2bv( "*", STRLENOF( "*" ), 1, &a->acl_dn_pat );
350 split( argv[i], '=', &left, &right );
351 split( left, '.', &left, &style );
353 if ( right == NULL ) {
354 fprintf( stderr, "%s: line %d: "
355 "missing \"=\" in \"%s\" in to clause\n",
356 fname, lineno, left );
360 if ( strcasecmp( left, "dn" ) == 0 ) {
361 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
362 a->acl_dn_style != ACL_STYLE_REGEX )
365 "%s: line %d: dn pattern"
366 " already specified in to clause.\n",
371 if ( style == NULL || *style == '\0' ||
372 strcasecmp( style, "baseObject" ) == 0 ||
373 strcasecmp( style, "base" ) == 0 ||
374 strcasecmp( style, "exact" ) == 0 )
376 a->acl_dn_style = ACL_STYLE_BASE;
377 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
379 } else if ( strcasecmp( style, "oneLevel" ) == 0 ||
380 strcasecmp( style, "one" ) == 0 )
382 a->acl_dn_style = ACL_STYLE_ONE;
383 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
385 } else if ( strcasecmp( style, "subtree" ) == 0 ||
386 strcasecmp( style, "sub" ) == 0 )
388 if( *right == '\0' ) {
389 ber_str2bv( "*", STRLENOF( "*" ), 1, &a->acl_dn_pat );
392 a->acl_dn_style = ACL_STYLE_SUBTREE;
393 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
396 } else if ( strcasecmp( style, "children" ) == 0 ) {
397 a->acl_dn_style = ACL_STYLE_CHILDREN;
398 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
400 } else if ( strcasecmp( style, "regex" ) == 0 ) {
401 a->acl_dn_style = ACL_STYLE_REGEX;
403 if ( *right == '\0' ) {
404 /* empty regex should match empty DN */
405 a->acl_dn_style = ACL_STYLE_BASE;
406 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
408 } else if ( strcmp(right, "*") == 0
409 || strcmp(right, ".*") == 0
410 || strcmp(right, ".*$") == 0
411 || strcmp(right, "^.*") == 0
412 || strcmp(right, "^.*$") == 0
413 || strcmp(right, ".*$$") == 0
414 || strcmp(right, "^.*$$") == 0 )
416 ber_str2bv( "*", STRLENOF("*"), 1, &a->acl_dn_pat );
419 acl_regex_normalized_dn( right, &a->acl_dn_pat );
423 fprintf( stderr, "%s: line %d: "
424 "unknown dn style \"%s\" in to clause\n",
425 fname, lineno, style );
432 if ( strcasecmp( left, "filter" ) == 0 ) {
433 if ( (a->acl_filter = str2filter( right )) == NULL ) {
435 "%s: line %d: bad filter \"%s\" in to clause\n",
436 fname, lineno, right );
440 } else if ( strcasecmp( left, "attr" ) == 0
441 || strcasecmp( left, "attrs" ) == 0 ) {
442 a->acl_attrs = str2anlist( a->acl_attrs,
444 if ( a->acl_attrs == NULL ) {
446 "%s: line %d: unknown attr \"%s\" in to clause\n",
447 fname, lineno, right );
451 } else if ( strncasecmp( left, "val", 3 ) == 0 ) {
452 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
454 "%s: line %d: attr val already specified in to clause.\n",
458 if ( a->acl_attrs == NULL || !BER_BVISEMPTY( &a->acl_attrs[1].an_name ) )
461 "%s: line %d: attr val requires a single attribute.\n",
465 ber_str2bv( right, 0, 1, &a->acl_attrval );
466 if ( style && strcasecmp( style, "regex" ) == 0 ) {
467 int e = regcomp( &a->acl_attrval_re, a->acl_attrval.bv_val,
468 REG_EXTENDED | REG_ICASE | REG_NOSUB );
471 regerror( e, &a->acl_attrval_re, buf, sizeof(buf) );
472 fprintf( stderr, "%s: line %d: "
473 "regular expression \"%s\" bad because of %s\n",
474 fname, lineno, right, buf );
477 a->acl_attrval_style = ACL_STYLE_REGEX;
479 /* FIXME: if the attribute has DN syntax, we might
480 * allow one, subtree and children styles as well */
481 if ( !strcasecmp( style, "exact" ) ) {
482 a->acl_attrval_style = ACL_STYLE_BASE;
484 } else if ( a->acl_attrs[0].an_desc->ad_type->
485 sat_syntax == slap_schema.si_syn_distinguishedName )
487 if ( !strcasecmp( style, "baseObject" ) ||
488 !strcasecmp( style, "base" ) )
490 a->acl_attrval_style = ACL_STYLE_BASE;
491 } else if ( !strcasecmp( style, "onelevel" ) ||
492 !strcasecmp( style, "one" ) )
494 a->acl_attrval_style = ACL_STYLE_ONE;
495 } else if ( !strcasecmp( style, "subtree" ) ||
496 !strcasecmp( style, "sub" ) )
498 a->acl_attrval_style = ACL_STYLE_SUBTREE;
499 } else if ( !strcasecmp( style, "children" ) ) {
500 a->acl_attrval_style = ACL_STYLE_CHILDREN;
503 "%s: line %d: unknown val.<style> \"%s\" "
504 "for attributeType \"%s\" with DN syntax; "
506 fname, lineno, style,
507 a->acl_attrs[0].an_desc->ad_cname.bv_val );
508 a->acl_attrval_style = ACL_STYLE_BASE;
513 "%s: line %d: unknown val.<style> \"%s\" "
514 "for attributeType \"%s\"; using \"exact\"\n",
515 fname, lineno, style,
516 a->acl_attrs[0].an_desc->ad_cname.bv_val );
517 a->acl_attrval_style = ACL_STYLE_BASE;
523 "%s: line %d: expecting <what> got \"%s\"\n",
524 fname, lineno, left );
529 if ( !BER_BVISNULL( &a->acl_dn_pat ) &&
530 ber_bvccmp( &a->acl_dn_pat, '*' ) )
532 free( a->acl_dn_pat.bv_val );
533 BER_BVZERO( &a->acl_dn_pat );
536 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
537 a->acl_dn_style != ACL_STYLE_REGEX )
539 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
541 rc = dnNormalize( 0, NULL, NULL, &a->acl_dn_pat, &bv, NULL);
542 if ( rc != LDAP_SUCCESS ) {
544 "%s: line %d: bad DN \"%s\" in to DN clause\n",
545 fname, lineno, a->acl_dn_pat.bv_val );
548 free( a->acl_dn_pat.bv_val );
552 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
553 REG_EXTENDED | REG_ICASE );
556 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
557 fprintf( stderr, "%s: line %d: "
558 "regular expression \"%s\" bad because of %s\n",
559 fname, lineno, right, buf );
565 /* by clause - select who has what access to entries */
566 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
568 fprintf( stderr, "%s: line %d: "
569 "to clause required before by clause in access line\n",
575 * by clause consists of <who> and <access>
578 b = (Access *) ch_calloc( 1, sizeof(Access) );
580 ACL_INVALIDATE( b->a_access_mask );
584 "%s: line %d: premature eol: expecting <who>\n",
590 for ( ; i < argc; i++ ) {
591 slap_style_t sty = ACL_STYLE_REGEX;
592 char *style_modifier = NULL;
593 char *style_level = NULL;
596 slap_dn_access *bdn = &b->a_dn;
599 split( argv[i], '=', &left, &right );
600 split( left, '.', &left, &style );
602 split( style, ',', &style, &style_modifier );
604 if ( strncasecmp( style, "level", STRLENOF( "level" ) ) == 0 ) {
605 split( style, '{', &style, &style_level );
606 if ( style_level != NULL ) {
607 char *p = strchr( style_level, '}' );
610 "%s: line %d: premature eol: "
611 "expecting closing '}' in \"level{n}\"\n",
614 } else if ( p == style_level ) {
616 "%s: line %d: empty level "
626 if ( style == NULL || *style == '\0' ||
627 strcasecmp( style, "exact" ) == 0 ||
628 strcasecmp( style, "baseObject" ) == 0 ||
629 strcasecmp( style, "base" ) == 0 )
631 sty = ACL_STYLE_BASE;
633 } else if ( strcasecmp( style, "onelevel" ) == 0 ||
634 strcasecmp( style, "one" ) == 0 )
638 } else if ( strcasecmp( style, "subtree" ) == 0 ||
639 strcasecmp( style, "sub" ) == 0 )
641 sty = ACL_STYLE_SUBTREE;
643 } else if ( strcasecmp( style, "children" ) == 0 ) {
644 sty = ACL_STYLE_CHILDREN;
646 } else if ( strcasecmp( style, "level" ) == 0 )
650 level = strtol( style_level, &next, 10 );
651 if ( next[0] != '\0' ) {
653 "%s: line %d: unable to parse level "
659 sty = ACL_STYLE_LEVEL;
661 } else if ( strcasecmp( style, "regex" ) == 0 ) {
662 sty = ACL_STYLE_REGEX;
664 } else if ( strcasecmp( style, "expand" ) == 0 ) {
665 sty = ACL_STYLE_EXPAND;
667 } else if ( strcasecmp( style, "ip" ) == 0 ) {
670 } else if ( strcasecmp( style, "path" ) == 0 ) {
671 sty = ACL_STYLE_PATH;
672 #ifndef LDAP_PF_LOCAL
673 fprintf( stderr, "%s: line %d: "
674 "path style modifier is useless without local\n",
676 #endif /* LDAP_PF_LOCAL */
680 "%s: line %d: unknown style \"%s\" in by clause\n",
681 fname, lineno, style );
685 if ( style_modifier &&
686 strcasecmp( style_modifier, "expand" ) == 0 )
689 case ACL_STYLE_REGEX:
690 fprintf( stderr, "%s: line %d: "
691 "\"regex\" style implies "
692 "\"expand\" modifier (ignored)\n",
696 case ACL_STYLE_EXPAND:
698 /* FIXME: now it's legal... */
699 fprintf( stderr, "%s: line %d: "
700 "\"expand\" style used "
701 "in conjunction with "
702 "\"expand\" modifier (ignored)\n",
708 /* we'll see later if it's pertinent */
714 /* expand in <who> needs regex in <what> */
715 if ( ( sty == ACL_STYLE_EXPAND || expand )
716 && a->acl_dn_style != ACL_STYLE_REGEX )
718 fprintf( stderr, "%s: line %d: "
719 "\"expand\" style or modifier used "
720 "in conjunction with "
721 "a non-regex <what> clause\n",
725 if ( strncasecmp( left, "real", STRLENOF( "real" ) ) == 0 ) {
728 left += STRLENOF( "real" );
731 if ( strcasecmp( left, "*" ) == 0 ) {
736 ber_str2bv( "*", STRLENOF( "*" ), 1, &bv );
737 sty = ACL_STYLE_REGEX;
739 } else if ( strcasecmp( left, "anonymous" ) == 0 ) {
740 ber_str2bv("anonymous", STRLENOF( "anonymous" ), 1, &bv);
741 sty = ACL_STYLE_ANONYMOUS;
743 } else if ( strcasecmp( left, "users" ) == 0 ) {
744 ber_str2bv("users", STRLENOF( "users" ), 1, &bv);
745 sty = ACL_STYLE_USERS;
747 } else if ( strcasecmp( left, "self" ) == 0 ) {
748 ber_str2bv("self", STRLENOF( "self" ), 1, &bv);
749 sty = ACL_STYLE_SELF;
751 } else if ( strcasecmp( left, "dn" ) == 0 ) {
752 if ( sty == ACL_STYLE_REGEX ) {
753 bdn->a_style = ACL_STYLE_REGEX;
754 if ( right == NULL ) {
759 bdn->a_style = ACL_STYLE_USERS;
761 } else if (*right == '\0' ) {
763 ber_str2bv("anonymous",
764 STRLENOF( "anonymous" ),
766 bdn->a_style = ACL_STYLE_ANONYMOUS;
768 } else if ( strcmp( right, "*" ) == 0 ) {
770 /* any or users? users for now */
774 bdn->a_style = ACL_STYLE_USERS;
776 } else if ( strcmp( right, ".+" ) == 0
777 || strcmp( right, "^.+" ) == 0
778 || strcmp( right, ".+$" ) == 0
779 || strcmp( right, "^.+$" ) == 0
780 || strcmp( right, ".+$$" ) == 0
781 || strcmp( right, "^.+$$" ) == 0 )
786 bdn->a_style = ACL_STYLE_USERS;
788 } else if ( strcmp( right, ".*" ) == 0
789 || strcmp( right, "^.*" ) == 0
790 || strcmp( right, ".*$" ) == 0
791 || strcmp( right, "^.*$" ) == 0
792 || strcmp( right, ".*$$" ) == 0
793 || strcmp( right, "^.*$$" ) == 0 )
800 acl_regex_normalized_dn( right, &bv );
801 if ( !ber_bvccmp( &bv, '*' ) ) {
802 regtest( fname, lineno, bv.bv_val );
806 } else if ( right == NULL || *right == '\0' ) {
807 fprintf( stderr, "%s: line %d: "
808 "missing \"=\" in (or value after) \"%s\" "
810 fname, lineno, left );
814 ber_str2bv( right, 0, 1, &bv );
821 if ( !BER_BVISNULL( &bv ) ) {
822 if ( !BER_BVISEMPTY( &bdn->a_pat ) ) {
824 "%s: line %d: dn pattern already specified.\n",
829 if ( sty != ACL_STYLE_REGEX &&
830 sty != ACL_STYLE_ANONYMOUS &&
831 sty != ACL_STYLE_USERS &&
832 sty != ACL_STYLE_SELF &&
835 rc = dnNormalize(0, NULL, NULL,
836 &bv, &bdn->a_pat, NULL);
837 if ( rc != LDAP_SUCCESS ) {
839 "%s: line %d: bad DN \"%s\" in by DN clause\n",
840 fname, lineno, bv.bv_val );
849 bdn->a_expand = expand;
850 if ( sty == ACL_STYLE_SELF ) {
851 bdn->a_self_level = level;
856 "%s: line %d: bad negative level \"%d\" "
858 fname, lineno, level );
860 } else if ( level == 1 ) {
862 "%s: line %d: \"onelevel\" should be used "
863 "instead of \"level{1}\" in by DN clause\n",
865 } else if ( level == 0 && sty == ACL_STYLE_LEVEL ) {
867 "%s: line %d: \"base\" should be used "
868 "instead of \"level{0}\" in by DN clause\n",
872 bdn->a_level = level;
877 if ( strcasecmp( left, "dnattr" ) == 0 ) {
878 if ( right == NULL || right[0] == '\0' ) {
879 fprintf( stderr, "%s: line %d: "
880 "missing \"=\" in (or value after) \"%s\" "
882 fname, lineno, left );
886 if( bdn->a_at != NULL ) {
888 "%s: line %d: dnattr already specified.\n",
893 rc = slap_str2ad( right, &bdn->a_at, &text );
895 if( rc != LDAP_SUCCESS ) {
897 "%s: line %d: dnattr \"%s\": %s\n",
898 fname, lineno, right, text );
903 if( !is_at_syntax( bdn->a_at->ad_type,
905 !is_at_syntax( bdn->a_at->ad_type,
906 SLAPD_NAMEUID_SYNTAX ))
909 "%s: line %d: dnattr \"%s\": "
910 "inappropriate syntax: %s\n",
911 fname, lineno, right,
912 bdn->a_at->ad_type->sat_syntax_oid );
916 if( bdn->a_at->ad_type->sat_equality == NULL ) {
918 "%s: line %d: dnattr \"%s\": "
919 "inappropriate matching (no EQUALITY)\n",
920 fname, lineno, right );
927 if ( strncasecmp( left, "group", STRLENOF( "group" ) ) == 0 ) {
932 case ACL_STYLE_REGEX:
933 /* legacy, tolerated */
934 fprintf( stderr, "%s: line %d: "
935 "deprecated group style \"regex\"; "
936 "use \"expand\" instead\n",
937 fname, lineno, style );
938 sty = ACL_STYLE_EXPAND;
942 /* legal, traditional */
943 case ACL_STYLE_EXPAND:
944 /* legal, substring expansion; supersedes regex */
949 fprintf( stderr, "%s: line %d: "
950 "inappropriate style \"%s\" in by clause\n",
951 fname, lineno, style );
955 if ( right == NULL || right[0] == '\0' ) {
956 fprintf( stderr, "%s: line %d: "
957 "missing \"=\" in (or value after) \"%s\" "
959 fname, lineno, left );
963 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
965 "%s: line %d: group pattern already specified.\n",
970 /* format of string is
971 "group/objectClassValue/groupAttrName" */
972 if ( ( value = strchr(left, '/') ) != NULL ) {
974 if ( *value && ( name = strchr( value, '/' ) ) != NULL ) {
979 b->a_group_style = sty;
980 if ( sty == ACL_STYLE_EXPAND ) {
981 acl_regex_normalized_dn( right, &bv );
982 if ( !ber_bvccmp( &bv, '*' ) ) {
983 regtest( fname, lineno, bv.bv_val );
988 ber_str2bv( right, 0, 0, &bv );
989 rc = dnNormalize( 0, NULL, NULL, &bv,
990 &b->a_group_pat, NULL );
991 if ( rc != LDAP_SUCCESS ) {
993 "%s: line %d: bad DN \"%s\"\n",
994 fname, lineno, right );
999 if ( value && *value ) {
1000 b->a_group_oc = oc_find( value );
1003 if ( b->a_group_oc == NULL ) {
1005 "%s: line %d: group objectclass "
1007 fname, lineno, value );
1012 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
1014 if( b->a_group_oc == NULL ) {
1016 "%s: line %d: group default objectclass "
1018 fname, lineno, SLAPD_GROUP_CLASS );
1023 if ( is_object_subclass( slap_schema.si_oc_referral,
1027 "%s: line %d: group objectclass \"%s\" "
1028 "is subclass of referral\n",
1029 fname, lineno, value );
1033 if ( is_object_subclass( slap_schema.si_oc_alias,
1037 "%s: line %d: group objectclass \"%s\" "
1038 "is subclass of alias\n",
1039 fname, lineno, value );
1043 if ( name && *name ) {
1044 rc = slap_str2ad( name, &b->a_group_at, &text );
1046 if( rc != LDAP_SUCCESS ) {
1048 "%s: line %d: group \"%s\": %s\n",
1049 fname, lineno, right, text );
1055 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
1057 if ( rc != LDAP_SUCCESS ) {
1059 "%s: line %d: group \"%s\": %s\n",
1060 fname, lineno, SLAPD_GROUP_ATTR, text );
1065 if ( !is_at_syntax( b->a_group_at->ad_type,
1066 SLAPD_DN_SYNTAX ) &&
1067 !is_at_syntax( b->a_group_at->ad_type,
1068 SLAPD_NAMEUID_SYNTAX ) &&
1069 !is_at_subtype( b->a_group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ) )
1072 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
1073 fname, lineno, right,
1074 b->a_group_at->ad_type->sat_syntax_oid );
1081 struct berval vals[2];
1083 ber_str2bv( b->a_group_oc->soc_oid, 0, 0, &vals[0] );
1084 BER_BVZERO( &vals[1] );
1086 rc = oc_check_allowed( b->a_group_at->ad_type,
1090 fprintf( stderr, "%s: line %d: "
1091 "group: \"%s\" not allowed by \"%s\"\n",
1093 b->a_group_at->ad_cname.bv_val,
1094 b->a_group_oc->soc_oid );
1101 if ( strcasecmp( left, "peername" ) == 0 ) {
1103 case ACL_STYLE_REGEX:
1104 case ACL_STYLE_BASE:
1105 /* legal, traditional */
1106 case ACL_STYLE_EXPAND:
1107 /* cheap replacement to regex for simple expansion */
1109 case ACL_STYLE_PATH:
1110 /* legal, peername specific */
1114 fprintf( stderr, "%s: line %d: "
1115 "inappropriate style \"%s\" in by clause\n",
1116 fname, lineno, style );
1120 if ( right == NULL || right[0] == '\0' ) {
1121 fprintf( stderr, "%s: line %d: "
1122 "missing \"=\" in (or value after) \"%s\" "
1124 fname, lineno, left );
1128 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1129 fprintf( stderr, "%s: line %d: "
1130 "peername pattern already specified.\n",
1135 b->a_peername_style = sty;
1136 if ( sty == ACL_STYLE_REGEX ) {
1137 acl_regex_normalized_dn( right, &bv );
1138 if ( !ber_bvccmp( &bv, '*' ) ) {
1139 regtest( fname, lineno, bv.bv_val );
1141 b->a_peername_pat = bv;
1144 ber_str2bv( right, 0, 1, &b->a_peername_pat );
1146 if ( sty == ACL_STYLE_IP ) {
1151 split( right, '{', &addr, &port );
1152 split( addr, '%', &addr, &mask );
1154 b->a_peername_addr = inet_addr( addr );
1155 if ( b->a_peername_addr == (unsigned long)(-1) ) {
1156 /* illegal address */
1157 fprintf( stderr, "%s: line %d: "
1158 "illegal peername address \"%s\".\n",
1159 fname, lineno, addr );
1163 b->a_peername_mask = (unsigned long)(-1);
1164 if ( mask != NULL ) {
1165 b->a_peername_mask = inet_addr( mask );
1166 if ( b->a_peername_mask ==
1167 (unsigned long)(-1) )
1170 fprintf( stderr, "%s: line %d: "
1171 "illegal peername address mask "
1173 fname, lineno, mask );
1178 b->a_peername_port = -1;
1182 b->a_peername_port = strtol( port, &end, 10 );
1183 if ( end[0] != '}' ) {
1185 fprintf( stderr, "%s: line %d: "
1186 "illegal peername port specification "
1188 fname, lineno, port );
1197 if ( strcasecmp( left, "sockname" ) == 0 ) {
1199 case ACL_STYLE_REGEX:
1200 case ACL_STYLE_BASE:
1201 /* legal, traditional */
1202 case ACL_STYLE_EXPAND:
1203 /* cheap replacement to regex for simple expansion */
1208 fprintf( stderr, "%s: line %d: "
1209 "inappropriate style \"%s\" in by clause\n",
1210 fname, lineno, style );
1214 if ( right == NULL || right[0] == '\0' ) {
1215 fprintf( stderr, "%s: line %d: "
1216 "missing \"=\" in (or value after) \"%s\" "
1218 fname, lineno, left );
1222 if ( !BER_BVISNULL( &b->a_sockname_pat ) ) {
1223 fprintf( stderr, "%s: line %d: "
1224 "sockname pattern already specified.\n",
1229 b->a_sockname_style = sty;
1230 if ( sty == ACL_STYLE_REGEX ) {
1231 acl_regex_normalized_dn( right, &bv );
1232 if ( !ber_bvccmp( &bv, '*' ) ) {
1233 regtest( fname, lineno, bv.bv_val );
1235 b->a_sockname_pat = bv;
1238 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
1243 if ( strcasecmp( left, "domain" ) == 0 ) {
1245 case ACL_STYLE_REGEX:
1246 case ACL_STYLE_BASE:
1247 case ACL_STYLE_SUBTREE:
1248 /* legal, traditional */
1251 case ACL_STYLE_EXPAND:
1252 /* tolerated: means exact,expand */
1256 "\"expand\" modifier "
1257 "with \"expand\" style\n",
1260 sty = ACL_STYLE_BASE;
1266 fprintf( stderr, "%s: line %d: "
1267 "inappropriate style \"%s\" in by clause\n",
1268 fname, lineno, style );
1272 if ( right == NULL || right[0] == '\0' ) {
1273 fprintf( stderr, "%s: line %d: "
1274 "missing \"=\" in (or value after) \"%s\" "
1276 fname, lineno, left );
1280 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1282 "%s: line %d: domain pattern already specified.\n",
1287 b->a_domain_style = sty;
1288 b->a_domain_expand = expand;
1289 if ( sty == ACL_STYLE_REGEX ) {
1290 acl_regex_normalized_dn( right, &bv );
1291 if ( !ber_bvccmp( &bv, '*' ) ) {
1292 regtest( fname, lineno, bv.bv_val );
1294 b->a_domain_pat = bv;
1297 ber_str2bv( right, 0, 1, &b->a_domain_pat );
1302 if ( strcasecmp( left, "sockurl" ) == 0 ) {
1304 case ACL_STYLE_REGEX:
1305 case ACL_STYLE_BASE:
1306 /* legal, traditional */
1307 case ACL_STYLE_EXPAND:
1308 /* cheap replacement to regex for simple expansion */
1313 fprintf( stderr, "%s: line %d: "
1314 "inappropriate style \"%s\" in by clause\n",
1315 fname, lineno, style );
1319 if ( right == NULL || right[0] == '\0' ) {
1320 fprintf( stderr, "%s: line %d: "
1321 "missing \"=\" in (or value after) \"%s\" "
1323 fname, lineno, left );
1327 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1329 "%s: line %d: sockurl pattern already specified.\n",
1334 b->a_sockurl_style = sty;
1335 if ( sty == ACL_STYLE_REGEX ) {
1336 acl_regex_normalized_dn( right, &bv );
1337 if ( !ber_bvccmp( &bv, '*' ) ) {
1338 regtest( fname, lineno, bv.bv_val );
1340 b->a_sockurl_pat = bv;
1343 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
1348 if ( strcasecmp( left, "set" ) == 0 ) {
1351 case ACL_STYLE_REGEX:
1352 fprintf( stderr, "%s: line %d: "
1353 "deprecated set style "
1354 "\"regex\" in <by> clause; "
1355 "use \"expand\" instead\n",
1357 sty = ACL_STYLE_EXPAND;
1360 case ACL_STYLE_BASE:
1361 case ACL_STYLE_EXPAND:
1365 fprintf( stderr, "%s: line %d: "
1366 "inappropriate style \"%s\" in by clause\n",
1367 fname, lineno, style );
1371 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1373 "%s: line %d: set attribute already specified.\n",
1378 if ( right == NULL || *right == '\0' ) {
1380 "%s: line %d: no set is defined\n",
1385 b->a_set_style = sty;
1386 ber_str2bv( right, 0, 1, &b->a_set_pat );
1395 if ( strcasecmp( left, "aci" ) == 0 ) {
1398 } else if ( strncasecmp( left, "dynacl/", STRLENOF( "dynacl/" ) ) == 0 ) {
1399 name = &left[ STRLENOF( "dynacl/" ) ];
1403 if ( slap_dynacl_config( fname, lineno, b, name, sty, right ) ) {
1404 fprintf( stderr, "%s: line %d: "
1405 "unable to configure dynacl \"%s\"\n",
1406 fname, lineno, name );
1413 #else /* ! SLAP_DYNACL */
1415 #ifdef SLAPD_ACI_ENABLED
1416 if ( strcasecmp( left, "aci" ) == 0 ) {
1417 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1418 fprintf( stderr, "%s: line %d: "
1419 "inappropriate style \"%s\" in by clause\n",
1420 fname, lineno, style );
1424 if( b->a_aci_at != NULL ) {
1426 "%s: line %d: aci attribute already specified.\n",
1431 if ( right != NULL && *right != '\0' ) {
1432 rc = slap_str2ad( right, &b->a_aci_at, &text );
1434 if( rc != LDAP_SUCCESS ) {
1436 "%s: line %d: aci \"%s\": %s\n",
1437 fname, lineno, right, text );
1442 b->a_aci_at = slap_schema.si_ad_aci;
1445 if( !is_at_syntax( b->a_aci_at->ad_type,
1448 fprintf( stderr, "%s: line %d: "
1449 "aci \"%s\": inappropriate syntax: %s\n",
1450 fname, lineno, right,
1451 b->a_aci_at->ad_type->sat_syntax_oid );
1457 #endif /* SLAPD_ACI_ENABLED */
1458 #endif /* ! SLAP_DYNACL */
1460 if ( strcasecmp( left, "ssf" ) == 0 ) {
1461 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1462 fprintf( stderr, "%s: line %d: "
1463 "inappropriate style \"%s\" in by clause\n",
1464 fname, lineno, style );
1468 if ( b->a_authz.sai_ssf ) {
1470 "%s: line %d: ssf attribute already specified.\n",
1475 if ( right == NULL || *right == '\0' ) {
1477 "%s: line %d: no ssf is defined\n",
1482 b->a_authz.sai_ssf = strtol( right, &next, 10 );
1483 if ( next == NULL || next[0] != '\0' ) {
1485 "%s: line %d: unable to parse ssf value (%s)\n",
1486 fname, lineno, right );
1490 if ( !b->a_authz.sai_ssf ) {
1492 "%s: line %d: invalid ssf value (%s)\n",
1493 fname, lineno, right );
1499 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
1500 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1501 fprintf( stderr, "%s: line %d: "
1502 "inappropriate style \"%s\" in by clause\n",
1503 fname, lineno, style );
1507 if ( b->a_authz.sai_transport_ssf ) {
1508 fprintf( stderr, "%s: line %d: "
1509 "transport_ssf attribute already specified.\n",
1514 if ( right == NULL || *right == '\0' ) {
1516 "%s: line %d: no transport_ssf is defined\n",
1521 b->a_authz.sai_transport_ssf = strtol( right, &next, 10 );
1522 if ( next == NULL || next[0] != '\0' ) {
1523 fprintf( stderr, "%s: line %d: "
1524 "unable to parse transport_ssf value (%s)\n",
1525 fname, lineno, right );
1529 if ( !b->a_authz.sai_transport_ssf ) {
1531 "%s: line %d: invalid transport_ssf value (%s)\n",
1532 fname, lineno, right );
1538 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
1539 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1540 fprintf( stderr, "%s: line %d: "
1541 "inappropriate style \"%s\" in by clause\n",
1542 fname, lineno, style );
1546 if ( b->a_authz.sai_tls_ssf ) {
1547 fprintf( stderr, "%s: line %d: "
1548 "tls_ssf attribute already specified.\n",
1553 if ( right == NULL || *right == '\0' ) {
1555 "%s: line %d: no tls_ssf is defined\n",
1560 b->a_authz.sai_tls_ssf = strtol( right, &next, 10 );
1561 if ( next == NULL || next[0] != '\0' ) {
1562 fprintf( stderr, "%s: line %d: "
1563 "unable to parse tls_ssf value (%s)\n",
1564 fname, lineno, right );
1568 if ( !b->a_authz.sai_tls_ssf ) {
1570 "%s: line %d: invalid tls_ssf value (%s)\n",
1571 fname, lineno, right );
1577 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1578 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1579 fprintf( stderr, "%s: line %d: "
1580 "inappropriate style \"%s\" in by clause\n",
1581 fname, lineno, style );
1585 if ( b->a_authz.sai_sasl_ssf ) {
1586 fprintf( stderr, "%s: line %d: "
1587 "sasl_ssf attribute already specified.\n",
1592 if ( right == NULL || *right == '\0' ) {
1594 "%s: line %d: no sasl_ssf is defined\n",
1599 b->a_authz.sai_sasl_ssf = strtol( right, &next, 10 );
1600 if ( next == NULL || next[0] != '\0' ) {
1601 fprintf( stderr, "%s: line %d: "
1602 "unable to parse sasl_ssf value (%s)\n",
1603 fname, lineno, right );
1607 if ( !b->a_authz.sai_sasl_ssf ) {
1609 "%s: line %d: invalid sasl_ssf value (%s)\n",
1610 fname, lineno, right );
1616 if ( right != NULL ) {
1623 if ( i == argc || ( strcasecmp( left, "stop" ) == 0 ) ) {
1624 /* out of arguments or plain stop */
1626 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1627 b->a_type = ACL_STOP;
1629 access_append( &a->acl_access, b );
1633 if ( strcasecmp( left, "continue" ) == 0 ) {
1634 /* plain continue */
1636 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1637 b->a_type = ACL_CONTINUE;
1639 access_append( &a->acl_access, b );
1643 if ( strcasecmp( left, "break" ) == 0 ) {
1644 /* plain continue */
1646 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1647 b->a_type = ACL_BREAK;
1649 access_append( &a->acl_access, b );
1653 if ( strcasecmp( left, "by" ) == 0 ) {
1654 /* we've gone too far */
1656 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1657 b->a_type = ACL_STOP;
1659 access_append( &a->acl_access, b );
1664 if ( strncasecmp( left, "self", STRLENOF( "self" ) ) == 0 ) {
1666 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "self" ) ] ) );
1668 } else if ( strncasecmp( left, "realself", STRLENOF( "realself" ) ) == 0 ) {
1669 b->a_realdn_self = 1;
1670 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "realself" ) ] ) );
1673 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1676 if ( ACL_IS_INVALID( b->a_access_mask ) ) {
1678 "%s: line %d: expecting <access> got \"%s\"\n",
1679 fname, lineno, left );
1683 b->a_type = ACL_STOP;
1685 if ( ++i == argc ) {
1686 /* out of arguments or plain stop */
1687 access_append( &a->acl_access, b );
1691 if ( strcasecmp( argv[i], "continue" ) == 0 ) {
1692 /* plain continue */
1693 b->a_type = ACL_CONTINUE;
1695 } else if ( strcasecmp( argv[i], "break" ) == 0 ) {
1696 /* plain continue */
1697 b->a_type = ACL_BREAK;
1699 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1704 access_append( &a->acl_access, b );
1708 "%s: line %d: expecting \"to\" "
1709 "or \"by\" got \"%s\"\n",
1710 fname, lineno, argv[i] );
1715 /* if we have no real access clause, complain and do nothing */
1717 fprintf( stderr, "%s: line %d: "
1718 "warning: no access clause(s) specified in access line\n",
1723 if ( ldap_debug & LDAP_DEBUG_ACL ) {
1728 if ( a->acl_access == NULL ) {
1729 fprintf( stderr, "%s: line %d: "
1730 "warning: no by clause(s) specified in access line\n",
1735 if ( !BER_BVISNULL( &be->be_nsuffix[ 1 ] ) ) {
1736 fprintf( stderr, "%s: line %d: warning: "
1737 "scope checking only applies to single-valued "
1738 "suffix databases\n",
1740 /* go ahead, since checking is not authoritative */
1743 switch ( check_scope( be, a ) ) {
1744 case ACL_SCOPE_UNKNOWN:
1745 fprintf( stderr, "%s: line %d: warning: "
1746 "cannot assess the validity of the ACL scope within "
1747 "backend naming context\n",
1751 case ACL_SCOPE_WARN:
1752 fprintf( stderr, "%s: line %d: warning: "
1753 "ACL could be out of scope within backend naming context\n",
1757 case ACL_SCOPE_PARTIAL:
1758 fprintf( stderr, "%s: line %d: warning: "
1759 "ACL appears to be partially out of scope within "
1760 "backend naming context\n",
1765 fprintf( stderr, "%s: line %d: warning: "
1766 "ACL appears to be out of scope within "
1767 "backend naming context\n",
1774 acl_append( &be->be_acl, a );
1777 acl_append( &frontendDB->be_acl, a );
1783 accessmask2str( slap_mask_t mask, char *buf, int debug )
1788 assert( buf != NULL );
1790 if ( ACL_IS_INVALID( mask ) ) {
1796 if ( ACL_IS_LEVEL( mask ) ) {
1797 if ( ACL_LVL_IS_NONE(mask) ) {
1798 ptr = lutil_strcopy( ptr, "none" );
1800 } else if ( ACL_LVL_IS_DISCLOSE(mask) ) {
1801 ptr = lutil_strcopy( ptr, "disclose" );
1803 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1804 ptr = lutil_strcopy( ptr, "auth" );
1806 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1807 ptr = lutil_strcopy( ptr, "compare" );
1809 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1810 ptr = lutil_strcopy( ptr, "search" );
1812 } else if ( ACL_LVL_IS_READ(mask) ) {
1813 ptr = lutil_strcopy( ptr, "read" );
1815 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1816 ptr = lutil_strcopy( ptr, "write" );
1818 } else if ( ACL_LVL_IS_WADD(mask) ) {
1819 ptr = lutil_strcopy( ptr, "add" );
1821 } else if ( ACL_LVL_IS_WDEL(mask) ) {
1822 ptr = lutil_strcopy( ptr, "delete" );
1824 } else if ( ACL_LVL_IS_MANAGE(mask) ) {
1825 ptr = lutil_strcopy( ptr, "manage" );
1828 ptr = lutil_strcopy( ptr, "unknown" );
1838 if( ACL_IS_ADDITIVE( mask ) ) {
1841 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1848 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_MANAGE) ) {
1853 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1857 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WADD) ) {
1861 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WDEL) ) {
1866 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1871 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1876 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1881 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1886 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_DISCLOSE) ) {
1891 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1900 if ( ACL_IS_LEVEL( mask ) ) {
1910 str2accessmask( const char *str )
1914 if( !ASCII_ALPHA(str[0]) ) {
1917 if ( str[0] == '=' ) {
1920 } else if( str[0] == '+' ) {
1921 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1923 } else if( str[0] == '-' ) {
1924 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1927 ACL_INVALIDATE(mask);
1931 for( i=1; str[i] != '\0'; i++ ) {
1932 if( TOLOWER((unsigned char) str[i]) == 'm' ) {
1933 ACL_PRIV_SET(mask, ACL_PRIV_MANAGE);
1935 } else if( TOLOWER((unsigned char) str[i]) == 'w' ) {
1936 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1938 } else if( TOLOWER((unsigned char) str[i]) == 'a' ) {
1939 ACL_PRIV_SET(mask, ACL_PRIV_WADD);
1941 } else if( TOLOWER((unsigned char) str[i]) == 'z' ) {
1942 ACL_PRIV_SET(mask, ACL_PRIV_WDEL);
1944 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
1945 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1947 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
1948 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1950 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
1951 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1953 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
1954 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1956 } else if( TOLOWER((unsigned char) str[i]) == 'd' ) {
1957 ACL_PRIV_SET(mask, ACL_PRIV_DISCLOSE);
1959 } else if( str[i] != '0' ) {
1960 ACL_INVALIDATE(mask);
1968 if ( strcasecmp( str, "none" ) == 0 ) {
1969 ACL_LVL_ASSIGN_NONE(mask);
1971 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
1972 ACL_LVL_ASSIGN_DISCLOSE(mask);
1974 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1975 ACL_LVL_ASSIGN_AUTH(mask);
1977 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1978 ACL_LVL_ASSIGN_COMPARE(mask);
1980 } else if ( strcasecmp( str, "search" ) == 0 ) {
1981 ACL_LVL_ASSIGN_SEARCH(mask);
1983 } else if ( strcasecmp( str, "read" ) == 0 ) {
1984 ACL_LVL_ASSIGN_READ(mask);
1986 } else if ( strcasecmp( str, "add" ) == 0 ) {
1987 ACL_LVL_ASSIGN_WADD(mask);
1989 } else if ( strcasecmp( str, "delete" ) == 0 ) {
1990 ACL_LVL_ASSIGN_WDEL(mask);
1992 } else if ( strcasecmp( str, "write" ) == 0 ) {
1993 ACL_LVL_ASSIGN_WRITE(mask);
1995 } else if ( strcasecmp( str, "manage" ) == 0 ) {
1996 ACL_LVL_ASSIGN_MANAGE(mask);
1999 ACL_INVALIDATE( mask );
2008 fprintf( stderr, "%s%s%s\n",
2009 "<access clause> ::= access to <what> "
2010 "[ by <who> <access> [ <control> ] ]+ \n"
2011 "<what> ::= * | [dn[.<dnstyle>]=<DN>] [filter=<filter>] [attrs=<attrlist>]\n"
2012 "<attrlist> ::= <attr> [val[.<attrstyle>]=<value>] | <attr> , <attrlist>\n"
2013 "<attr> ::= <attrname> | entry | children\n",
2014 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
2015 "\t[ realanonymous | realusers | realself | realdn[.<dnstyle>]=<DN> ]\n"
2016 "\t[dnattr=<attrname>]\n"
2017 "\t[realdnattr=<attrname>]\n"
2018 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
2019 "\t[peername[.<peernamestyle>]=<peer>] [sockname[.<style>]=<name>]\n"
2020 "\t[domain[.<domainstyle>]=<domain>] [sockurl[.<style>]=<url>]\n"
2021 #ifdef SLAPD_ACI_ENABLED
2022 "\t[aci=[<attrname>]]\n"
2025 "\t[dynacl/<name>[.<dynstyle>][=<pattern>]]\n"
2026 #endif /* SLAP_DYNACL */
2027 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n",
2028 "<style> ::= exact | regex | base(Object)\n"
2029 "<dnstyle> ::= base(Object) | one(level) | sub(tree) | children | "
2031 "<attrstyle> ::= exact | regex | base(Object) | one(level) | "
2032 "sub(tree) | children\n"
2033 "<peernamestyle> ::= exact | regex | ip | path\n"
2034 "<domainstyle> ::= exact | regex | base(Object) | sub(tree)\n"
2035 "<access> ::= [[real]self]{<level>|<priv>}\n"
2036 "<level> ::= none|disclose|auth|compare|search|read|{write|add|delete}|manage\n"
2037 "<priv> ::= {=|+|-}{0|d|x|c|s|r|{w|a|z}|m}+\n"
2038 "<control> ::= [ stop | continue | break ]\n"
2040 exit( EXIT_FAILURE );
2044 * Set pattern to a "normalized" DN from src.
2045 * At present it simply eats the (optional) space after
2046 * a RDN separator (,)
2047 * Eventually will evolve in a more complete normalization
2050 acl_regex_normalized_dn(
2052 struct berval *pattern )
2057 str = ch_strdup( src );
2058 len = strlen( src );
2060 for ( p = str; p && p[0]; p++ ) {
2062 if ( p[0] == '\\' && p[1] ) {
2064 * if escaping a hex pair we should
2065 * increment p twice; however, in that
2066 * case the second hex number does
2072 if ( p[0] == ',' && p[1] == ' ' ) {
2076 * too much space should be an error if we are pedantic
2078 for ( q = &p[2]; q[0] == ' '; q++ ) {
2081 AC_MEMCPY( p+1, q, len-(q-str)+1);
2084 pattern->bv_val = str;
2085 pattern->bv_len = p - str;
2098 if ( (*right = strchr( line, splitchar )) != NULL ) {
2099 *((*right)++) = '\0';
2104 access_append( Access **l, Access *a )
2106 for ( ; *l != NULL; l = &(*l)->a_next ) {
2114 acl_append( AccessControl **l, AccessControl *a )
2116 for ( ; *l != NULL; l = &(*l)->acl_next ) {
2124 access_free( Access *a )
2126 if ( !BER_BVISNULL( &a->a_dn_pat ) ) {
2127 free( a->a_dn_pat.bv_val );
2129 if ( !BER_BVISNULL( &a->a_realdn_pat ) ) {
2130 free( a->a_realdn_pat.bv_val );
2132 if ( !BER_BVISNULL( &a->a_peername_pat ) ) {
2133 free( a->a_peername_pat.bv_val );
2135 if ( !BER_BVISNULL( &a->a_sockname_pat ) ) {
2136 free( a->a_sockname_pat.bv_val );
2138 if ( !BER_BVISNULL( &a->a_domain_pat ) ) {
2139 free( a->a_domain_pat.bv_val );
2141 if ( !BER_BVISNULL( &a->a_sockurl_pat ) ) {
2142 free( a->a_sockurl_pat.bv_val );
2144 if ( !BER_BVISNULL( &a->a_set_pat ) ) {
2145 free( a->a_set_pat.bv_val );
2147 if ( !BER_BVISNULL( &a->a_group_pat ) ) {
2148 free( a->a_group_pat.bv_val );
2154 acl_free( AccessControl *a )
2159 if ( a->acl_filter ) {
2160 filter_free( a->acl_filter );
2162 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2163 free ( a->acl_dn_pat.bv_val );
2165 if ( a->acl_attrs ) {
2166 for ( an = a->acl_attrs; !BER_BVISNULL( &an->an_name ); an++ ) {
2167 free( an->an_name.bv_val );
2169 free( a->acl_attrs );
2171 for ( ; a->acl_access; a->acl_access = n ) {
2172 n = a->acl_access->a_next;
2173 access_free( a->acl_access );
2178 /* Because backend_startup uses acl_append to tack on the global_acl to
2179 * the end of each backend's acl, we cannot just take one argument and
2180 * merrily free our way to the end of the list. backend_destroy calls us
2181 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
2182 * point. config_destroy calls us with global_acl in arg1 and NULL in
2183 * arg2, so we then proceed to polish off the global_acl.
2186 acl_destroy( AccessControl *a, AccessControl *end )
2190 for (; a && a!= end; a=n) {
2197 access2str( slap_access_t access )
2199 if ( access == ACL_NONE ) {
2202 } else if ( access == ACL_DISCLOSE ) {
2205 } else if ( access == ACL_AUTH ) {
2208 } else if ( access == ACL_COMPARE ) {
2211 } else if ( access == ACL_SEARCH ) {
2214 } else if ( access == ACL_READ ) {
2217 } else if ( access == ACL_WRITE ) {
2220 } else if ( access == ACL_WADD ) {
2223 } else if ( access == ACL_WDEL ) {
2226 } else if ( access == ACL_MANAGE ) {
2235 str2access( const char *str )
2237 if ( strcasecmp( str, "none" ) == 0 ) {
2240 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2241 #ifndef SLAP_ACL_HONOR_DISCLOSE
2242 fprintf( stderr, "str2access: warning, "
2243 "\"disclose\" privilege disabled.\n" );
2244 #endif /* SLAP_ACL_HONOR_DISCLOSE */
2245 return ACL_DISCLOSE;
2247 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2250 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2253 } else if ( strcasecmp( str, "search" ) == 0 ) {
2256 } else if ( strcasecmp( str, "read" ) == 0 ) {
2259 } else if ( strcasecmp( str, "write" ) == 0 ) {
2262 } else if ( strcasecmp( str, "add" ) == 0 ) {
2265 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2268 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2272 return( ACL_INVALID_ACCESS );
2275 #define ACLBUF_MAXLEN 8192
2277 static char aclbuf[ACLBUF_MAXLEN];
2280 dnaccess2text( slap_dn_access *bdn, char *ptr, int is_realdn )
2285 ptr = lutil_strcopy( ptr, "real" );
2288 if ( ber_bvccmp( &bdn->a_pat, '*' ) ||
2289 bdn->a_style == ACL_STYLE_ANONYMOUS ||
2290 bdn->a_style == ACL_STYLE_USERS ||
2291 bdn->a_style == ACL_STYLE_SELF )
2294 assert( ! ber_bvccmp( &bdn->a_pat, '*' ) );
2297 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2298 if ( bdn->a_style == ACL_STYLE_SELF && bdn->a_self_level != 0 ) {
2299 int n = sprintf( ptr, ".level{%d}", bdn->a_self_level );
2306 ptr = lutil_strcopy( ptr, "dn." );
2307 ptr = lutil_strcopy( ptr, style_strings[bdn->a_style] );
2308 if ( bdn->a_style == ACL_STYLE_LEVEL ) {
2309 int n = sprintf( ptr, "{%d}", bdn->a_level );
2314 if ( bdn->a_expand ) {
2315 ptr = lutil_strcopy( ptr, ",expand" );
2319 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2323 if ( bdn->a_at != NULL ) {
2326 ptr = lutil_strcopy( ptr, "real" );
2328 ptr = lutil_strcopy( ptr, "dnattr=" );
2329 ptr = lutil_strcopy( ptr, bdn->a_at->ad_cname.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 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
2347 ptr = dnaccess2text( &b->a_realdn, ptr, 1 );
2350 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
2351 ptr = lutil_strcopy( ptr, " group/" );
2352 ptr = lutil_strcopy( ptr, b->a_group_oc ?
2353 b->a_group_oc->soc_cname.bv_val : "groupOfNames" );
2355 ptr = lutil_strcopy( ptr, b->a_group_at ?
2356 b->a_group_at->ad_cname.bv_val : "member" );
2358 ptr = lutil_strcopy( ptr, style_strings[b->a_group_style] );
2361 ptr = lutil_strcopy( ptr, b->a_group_pat.bv_val );
2365 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
2366 ptr = lutil_strcopy( ptr, " peername=\"" );
2367 ptr = lutil_strcopy( ptr, b->a_peername_pat.bv_val );
2371 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
2372 ptr = lutil_strcopy( ptr, " sockname=\"" );
2373 ptr = lutil_strcopy( ptr, b->a_sockname_pat.bv_val );
2377 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
2378 ptr = lutil_strcopy( ptr, " domain=" );
2379 ptr = lutil_strcopy( ptr, b->a_domain_pat.bv_val );
2382 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
2383 ptr = lutil_strcopy( ptr, " sockurl=\"" );
2384 ptr = lutil_strcopy( ptr, b->a_sockurl_pat.bv_val );
2388 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
2389 ptr = lutil_strcopy( ptr, " set=\"" );
2390 ptr = lutil_strcopy( ptr, b->a_set_pat.bv_val );
2395 if ( b->a_dynacl ) {
2398 for ( da = b->a_dynacl; da; da = da->da_next ) {
2399 if ( da->da_unparse ) {
2401 (void)( *da->da_unparse )( da->da_private, &bv );
2402 ptr = lutil_strcopy( ptr, bv.bv_val );
2403 ch_free( bv.bv_val );
2407 #else /* ! SLAP_DYNACL */
2408 #ifdef SLAPD_ACI_ENABLED
2409 if ( b->a_aci_at != NULL ) {
2410 ptr = lutil_strcopy( ptr, " aci=" );
2411 ptr = lutil_strcopy( ptr, b->a_aci_at->ad_cname.bv_val );
2414 #endif /* SLAP_DYNACL */
2416 /* Security Strength Factors */
2417 if ( b->a_authz.sai_ssf ) {
2418 ptr += sprintf( ptr, " ssf=%u",
2419 b->a_authz.sai_ssf );
2421 if ( b->a_authz.sai_transport_ssf ) {
2422 ptr += sprintf( ptr, " transport_ssf=%u",
2423 b->a_authz.sai_transport_ssf );
2425 if ( b->a_authz.sai_tls_ssf ) {
2426 ptr += sprintf( ptr, " tls_ssf=%u",
2427 b->a_authz.sai_tls_ssf );
2429 if ( b->a_authz.sai_sasl_ssf ) {
2430 ptr += sprintf( ptr, " sasl_ssf=%u",
2431 b->a_authz.sai_sasl_ssf );
2435 if ( b->a_dn_self ) {
2436 ptr = lutil_strcopy( ptr, "self" );
2437 } else if ( b->a_realdn_self ) {
2438 ptr = lutil_strcopy( ptr, "realself" );
2440 ptr = lutil_strcopy( ptr, accessmask2str( b->a_access_mask, maskbuf, 0 ));
2441 if ( !maskbuf[0] ) ptr--;
2443 if( b->a_type == ACL_BREAK ) {
2444 ptr = lutil_strcopy( ptr, " break" );
2446 } else if( b->a_type == ACL_CONTINUE ) {
2447 ptr = lutil_strcopy( ptr, " continue" );
2449 } else if( b->a_type != ACL_STOP ) {
2450 ptr = lutil_strcopy( ptr, " unknown-control" );
2452 if ( !maskbuf[0] ) ptr = lutil_strcopy( ptr, " stop" );
2460 acl_unparse( AccessControl *a, struct berval *bv )
2466 bv->bv_val = aclbuf;
2471 ptr = lutil_strcopy( ptr, "to" );
2472 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2474 ptr = lutil_strcopy( ptr, " dn." );
2475 ptr = lutil_strcopy( ptr, style_strings[a->acl_dn_style] );
2478 ptr = lutil_strcopy( ptr, a->acl_dn_pat.bv_val );
2479 ptr = lutil_strcopy( ptr, "\"\n" );
2482 if ( a->acl_filter != NULL ) {
2483 struct berval bv = BER_BVNULL;
2486 filter2bv( a->acl_filter, &bv );
2487 ptr = lutil_strcopy( ptr, " filter=\"" );
2488 ptr = lutil_strcopy( ptr, bv.bv_val );
2491 ch_free( bv.bv_val );
2494 if ( a->acl_attrs != NULL ) {
2499 ptr = lutil_strcopy( ptr, " attrs=" );
2500 for ( an = a->acl_attrs; an && !BER_BVISNULL( &an->an_name ); an++ ) {
2501 if ( ! first ) *ptr++ = ',';
2503 *ptr++ = an->an_oc_exclude ? '!' : '@';
2504 ptr = lutil_strcopy( ptr, an->an_oc->soc_cname.bv_val );
2507 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2514 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
2516 ptr = lutil_strcopy( ptr, " val." );
2517 ptr = lutil_strcopy( ptr, style_strings[a->acl_attrval_style] );
2520 ptr = lutil_strcopy( ptr, a->acl_attrval.bv_val );
2526 ptr = lutil_strcopy( ptr, " *\n" );
2529 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
2530 ptr = access2text( b, ptr );
2533 bv->bv_len = ptr - bv->bv_val;
2539 print_acl( Backend *be, AccessControl *a )
2543 acl_unparse( a, &bv );
2544 fprintf( stderr, "%s ACL: access %s\n",
2545 be == NULL ? "Global" : "Backend", bv.bv_val );
2547 #endif /* LDAP_DEBUG */