1 /* aclparse.c - routines to parse and check acl's */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that this notice is preserved and that due credit is given
21 * to the University of Michigan at Ann Arbor. The name of the University
22 * may not be used to endorse or promote products derived from this
23 * software without specific prior written permission. This software
24 * is provided ``as is'' without express or implied warranty.
33 #include <ac/socket.h>
34 #include <ac/string.h>
35 #include <ac/unistd.h>
41 static const char style_base[] = "base";
42 static char *style_strings[] = {
59 static void split(char *line, int splitchar, char **left, char **right);
60 static void access_append(Access **l, Access *a);
61 static void acl_usage(void) LDAP_GCCATTR((noreturn));
63 static void acl_regex_normalized_dn(const char *src, struct berval *pat);
66 static void print_acl(Backend *be, AccessControl *a);
69 static int check_scope( BackendDB *be, AccessControl *a );
73 slap_dynacl_config( const char *fname, int lineno, Access *b, const char *name, slap_style_t sty, const char *right )
75 slap_dynacl_t *da, *tmp;
78 for ( da = b->a_dynacl; da; da = da->da_next ) {
79 if ( strcasecmp( da->da_name, name ) == 0 ) {
81 "%s: line %d: dynacl \"%s\" already specified.\n",
82 fname, lineno, name );
87 da = slap_dynacl_get( name );
92 tmp = ch_malloc( sizeof( slap_dynacl_t ) );
95 if ( tmp->da_parse ) {
96 rc = ( *tmp->da_parse )( fname, lineno, sty, right, &tmp->da_private );
103 tmp->da_next = b->a_dynacl;
108 #endif /* SLAP_DYNACL */
111 regtest(const char *fname, int lineno, char *pat) {
127 for (size = 0, flag = 0; (size < sizeof(buf)) && *sp; sp++) {
129 if (*sp == '$'|| (*sp >= '0' && *sp <= '9')) {
146 if ( size >= (sizeof(buf) - 1) ) {
148 "%s: line %d: regular expression \"%s\" too large\n",
149 fname, lineno, pat );
153 if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
155 regerror(e, &re, error, sizeof(error));
157 "%s: line %d: regular expression \"%s\" bad because of %s\n",
158 fname, lineno, pat, error );
167 * Check if the pattern of an ACL, if any, matches the scope
168 * of the backend it is defined within.
170 #define ACL_SCOPE_UNKNOWN (-2)
171 #define ACL_SCOPE_ERR (-1)
172 #define ACL_SCOPE_OK (0)
173 #define ACL_SCOPE_PARTIAL (1)
174 #define ACL_SCOPE_WARN (2)
177 check_scope( BackendDB *be, AccessControl *a )
182 dn = be->be_nsuffix[0];
184 if ( BER_BVISEMPTY( &dn ) ) {
188 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
189 a->acl_dn_style != ACL_STYLE_REGEX )
191 slap_style_t style = a->acl_dn_style;
193 if ( style == ACL_STYLE_REGEX ) {
194 char dnbuf[SLAP_LDAPDN_MAXLEN + 2];
195 char rebuf[SLAP_LDAPDN_MAXLEN + 1];
200 /* add trailing '$' to database suffix to form
201 * a simple trial regex pattern "<suffix>$" */
202 AC_MEMCPY( dnbuf, be->be_nsuffix[0].bv_val,
203 be->be_nsuffix[0].bv_len );
204 dnbuf[be->be_nsuffix[0].bv_len] = '$';
205 dnbuf[be->be_nsuffix[0].bv_len + 1] = '\0';
207 if ( regcomp( &re, dnbuf, REG_EXTENDED|REG_ICASE ) ) {
208 return ACL_SCOPE_WARN;
211 /* remove trailing ')$', if any, from original
213 rebuflen = a->acl_dn_pat.bv_len;
214 AC_MEMCPY( rebuf, a->acl_dn_pat.bv_val, rebuflen + 1 );
215 if ( rebuf[rebuflen - 1] == '$' ) {
216 rebuf[--rebuflen] = '\0';
218 while ( rebuflen > be->be_nsuffix[0].bv_len && rebuf[rebuflen - 1] == ')' ) {
219 rebuf[--rebuflen] = '\0';
221 if ( rebuflen == be->be_nsuffix[0].bv_len ) {
226 /* not a clear indication of scoping error, though */
227 rc = regexec( &re, rebuf, 0, NULL, 0 )
228 ? ACL_SCOPE_WARN : ACL_SCOPE_OK;
235 patlen = a->acl_dn_pat.bv_len;
236 /* If backend suffix is longer than pattern,
237 * it is a potential mismatch (in the sense
238 * that a superior naming context could
240 if ( dn.bv_len > patlen ) {
241 /* base is blatantly wrong */
242 if ( style == ACL_STYLE_BASE ) return ACL_SCOPE_ERR;
244 /* a style of one can be wrong if there is
245 * more than one level between the suffix
247 if ( style == ACL_STYLE_ONE ) {
248 int rdnlen = -1, sep = 0;
251 if ( !DN_SEPARATOR( dn.bv_val[dn.bv_len - patlen - 1] )) {
252 return ACL_SCOPE_ERR;
257 rdnlen = dn_rdnlen( NULL, &dn );
258 if ( rdnlen != dn.bv_len - patlen - sep )
259 return ACL_SCOPE_ERR;
262 /* if the trailing part doesn't match,
263 * then it's an error */
264 if ( strcmp( a->acl_dn_pat.bv_val,
265 &dn.bv_val[dn.bv_len - patlen] ) != 0 )
267 return ACL_SCOPE_ERR;
270 return ACL_SCOPE_PARTIAL;
276 case ACL_STYLE_CHILDREN:
277 case ACL_STYLE_SUBTREE:
285 if ( dn.bv_len < patlen &&
286 !DN_SEPARATOR( a->acl_dn_pat.bv_val[patlen - dn.bv_len - 1] ))
288 return ACL_SCOPE_ERR;
291 if ( strcmp( &a->acl_dn_pat.bv_val[patlen - dn.bv_len], dn.bv_val )
294 return ACL_SCOPE_ERR;
300 return ACL_SCOPE_UNKNOWN;
313 char *left, *right, *style, *next;
321 for ( i = 1; i < argc; i++ ) {
322 /* to clause - select which entries are protected */
323 if ( strcasecmp( argv[i], "to" ) == 0 ) {
325 fprintf( stderr, "%s: line %d: "
326 "only one to clause allowed in access line\n",
330 a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
331 for ( ++i; i < argc; i++ ) {
332 if ( strcasecmp( argv[i], "by" ) == 0 ) {
337 if ( strcasecmp( argv[i], "*" ) == 0 ) {
338 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
339 a->acl_dn_style != ACL_STYLE_REGEX )
342 "%s: line %d: dn pattern"
343 " already specified in to clause.\n",
348 ber_str2bv( "*", STRLENOF( "*" ), 1, &a->acl_dn_pat );
352 split( argv[i], '=', &left, &right );
353 split( left, '.', &left, &style );
355 if ( right == NULL ) {
356 fprintf( stderr, "%s: line %d: "
357 "missing \"=\" in \"%s\" in to clause\n",
358 fname, lineno, left );
362 if ( strcasecmp( left, "dn" ) == 0 ) {
363 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
364 a->acl_dn_style != ACL_STYLE_REGEX )
367 "%s: line %d: dn pattern"
368 " already specified in to clause.\n",
373 if ( style == NULL || *style == '\0' ||
374 strcasecmp( style, "baseObject" ) == 0 ||
375 strcasecmp( style, "base" ) == 0 ||
376 strcasecmp( style, "exact" ) == 0 )
378 a->acl_dn_style = ACL_STYLE_BASE;
379 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
381 } else if ( strcasecmp( style, "oneLevel" ) == 0 ||
382 strcasecmp( style, "one" ) == 0 )
384 a->acl_dn_style = ACL_STYLE_ONE;
385 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
387 } else if ( strcasecmp( style, "subtree" ) == 0 ||
388 strcasecmp( style, "sub" ) == 0 )
390 if( *right == '\0' ) {
391 ber_str2bv( "*", STRLENOF( "*" ), 1, &a->acl_dn_pat );
394 a->acl_dn_style = ACL_STYLE_SUBTREE;
395 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
398 } else if ( strcasecmp( style, "children" ) == 0 ) {
399 a->acl_dn_style = ACL_STYLE_CHILDREN;
400 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
402 } else if ( strcasecmp( style, "regex" ) == 0 ) {
403 a->acl_dn_style = ACL_STYLE_REGEX;
405 if ( *right == '\0' ) {
406 /* empty regex should match empty DN */
407 a->acl_dn_style = ACL_STYLE_BASE;
408 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
410 } else if ( strcmp(right, "*") == 0
411 || strcmp(right, ".*") == 0
412 || strcmp(right, ".*$") == 0
413 || strcmp(right, "^.*") == 0
414 || strcmp(right, "^.*$") == 0
415 || strcmp(right, ".*$$") == 0
416 || strcmp(right, "^.*$$") == 0 )
418 ber_str2bv( "*", STRLENOF("*"), 1, &a->acl_dn_pat );
421 acl_regex_normalized_dn( right, &a->acl_dn_pat );
425 fprintf( stderr, "%s: line %d: "
426 "unknown dn style \"%s\" in to clause\n",
427 fname, lineno, style );
434 if ( strcasecmp( left, "filter" ) == 0 ) {
435 if ( (a->acl_filter = str2filter( right )) == NULL ) {
437 "%s: line %d: bad filter \"%s\" in to clause\n",
438 fname, lineno, right );
442 } else if ( strcasecmp( left, "attr" ) == 0 /* TOLERATED */
443 || strcasecmp( left, "attrs" ) == 0 ) /* DOCUMENTED */
445 a->acl_attrs = str2anlist( a->acl_attrs,
447 if ( a->acl_attrs == NULL ) {
449 "%s: line %d: unknown attr \"%s\" in to clause\n",
450 fname, lineno, right );
454 } else if ( strncasecmp( left, "val", 3 ) == 0 ) {
455 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
457 "%s: line %d: attr val already specified in to clause.\n",
461 if ( a->acl_attrs == NULL || !BER_BVISEMPTY( &a->acl_attrs[1].an_name ) )
464 "%s: line %d: attr val requires a single attribute.\n",
468 ber_str2bv( right, 0, 1, &a->acl_attrval );
469 a->acl_attrval_style = ACL_STYLE_BASE;
470 if ( style != NULL ) {
471 if ( strcasecmp( style, "regex" ) == 0 ) {
472 int e = regcomp( &a->acl_attrval_re, a->acl_attrval.bv_val,
473 REG_EXTENDED | REG_ICASE | REG_NOSUB );
476 regerror( e, &a->acl_attrval_re, buf, sizeof(buf) );
477 fprintf( stderr, "%s: line %d: "
478 "regular expression \"%s\" bad because of %s\n",
479 fname, lineno, right, buf );
482 a->acl_attrval_style = ACL_STYLE_REGEX;
485 /* FIXME: if the attribute has DN syntax, we might
486 * allow one, subtree and children styles as well */
487 if ( !strcasecmp( style, "base" ) ||
488 !strcasecmp( style, "exact" ) ) {
489 a->acl_attrval_style = ACL_STYLE_BASE;
491 } else if ( a->acl_attrs[0].an_desc->ad_type->
492 sat_syntax == slap_schema.si_syn_distinguishedName )
494 if ( !strcasecmp( style, "baseObject" ) ||
495 !strcasecmp( style, "base" ) )
497 a->acl_attrval_style = ACL_STYLE_BASE;
498 } else if ( !strcasecmp( style, "onelevel" ) ||
499 !strcasecmp( style, "one" ) )
501 a->acl_attrval_style = ACL_STYLE_ONE;
502 } else if ( !strcasecmp( style, "subtree" ) ||
503 !strcasecmp( style, "sub" ) )
505 a->acl_attrval_style = ACL_STYLE_SUBTREE;
506 } else if ( !strcasecmp( style, "children" ) ) {
507 a->acl_attrval_style = ACL_STYLE_CHILDREN;
510 "%s: line %d: unknown val.<style> \"%s\" "
511 "for attributeType \"%s\" with DN syntax; "
513 fname, lineno, style,
514 a->acl_attrs[0].an_desc->ad_cname.bv_val );
515 a->acl_attrval_style = ACL_STYLE_BASE;
520 "%s: line %d: unknown val.<style> \"%s\" "
521 "for attributeType \"%s\"; using \"exact\"\n",
522 fname, lineno, style,
523 a->acl_attrs[0].an_desc->ad_cname.bv_val );
524 a->acl_attrval_style = ACL_STYLE_BASE;
531 "%s: line %d: expecting <what> got \"%s\"\n",
532 fname, lineno, left );
537 if ( !BER_BVISNULL( &a->acl_dn_pat ) &&
538 ber_bvccmp( &a->acl_dn_pat, '*' ) )
540 free( a->acl_dn_pat.bv_val );
541 BER_BVZERO( &a->acl_dn_pat );
542 a->acl_dn_style = ACL_STYLE_REGEX;
545 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
546 a->acl_dn_style != ACL_STYLE_REGEX )
548 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
550 rc = dnNormalize( 0, NULL, NULL, &a->acl_dn_pat, &bv, NULL);
551 if ( rc != LDAP_SUCCESS ) {
553 "%s: line %d: bad DN \"%s\" in to DN clause\n",
554 fname, lineno, a->acl_dn_pat.bv_val );
557 free( a->acl_dn_pat.bv_val );
561 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
562 REG_EXTENDED | REG_ICASE );
565 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
566 fprintf( stderr, "%s: line %d: "
567 "regular expression \"%s\" bad because of %s\n",
568 fname, lineno, right, buf );
574 /* by clause - select who has what access to entries */
575 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
577 fprintf( stderr, "%s: line %d: "
578 "to clause required before by clause in access line\n",
584 * by clause consists of <who> and <access>
587 b = (Access *) ch_calloc( 1, sizeof(Access) );
589 ACL_INVALIDATE( b->a_access_mask );
593 "%s: line %d: premature eol: expecting <who>\n",
599 for ( ; i < argc; i++ ) {
600 slap_style_t sty = ACL_STYLE_REGEX;
601 char *style_modifier = NULL;
602 char *style_level = NULL;
605 slap_dn_access *bdn = &b->a_dn;
608 split( argv[i], '=', &left, &right );
609 split( left, '.', &left, &style );
611 split( style, ',', &style, &style_modifier );
613 if ( strncasecmp( style, "level", STRLENOF( "level" ) ) == 0 ) {
614 split( style, '{', &style, &style_level );
615 if ( style_level != NULL ) {
616 char *p = strchr( style_level, '}' );
619 "%s: line %d: premature eol: "
620 "expecting closing '}' in \"level{n}\"\n",
623 } else if ( p == style_level ) {
625 "%s: line %d: empty level "
635 if ( style == NULL || *style == '\0' ||
636 strcasecmp( style, "exact" ) == 0 ||
637 strcasecmp( style, "baseObject" ) == 0 ||
638 strcasecmp( style, "base" ) == 0 )
640 sty = ACL_STYLE_BASE;
642 } else if ( strcasecmp( style, "onelevel" ) == 0 ||
643 strcasecmp( style, "one" ) == 0 )
647 } else if ( strcasecmp( style, "subtree" ) == 0 ||
648 strcasecmp( style, "sub" ) == 0 )
650 sty = ACL_STYLE_SUBTREE;
652 } else if ( strcasecmp( style, "children" ) == 0 ) {
653 sty = ACL_STYLE_CHILDREN;
655 } else if ( strcasecmp( style, "level" ) == 0 )
659 level = strtol( style_level, &next, 10 );
660 if ( next[0] != '\0' ) {
662 "%s: line %d: unable to parse level "
668 sty = ACL_STYLE_LEVEL;
670 } else if ( strcasecmp( style, "regex" ) == 0 ) {
671 sty = ACL_STYLE_REGEX;
673 } else if ( strcasecmp( style, "expand" ) == 0 ) {
674 sty = ACL_STYLE_EXPAND;
676 } else if ( strcasecmp( style, "ip" ) == 0 ) {
679 } else if ( strcasecmp( style, "path" ) == 0 ) {
680 sty = ACL_STYLE_PATH;
681 #ifndef LDAP_PF_LOCAL
682 fprintf( stderr, "%s: line %d: "
683 "path style modifier is useless without local\n",
685 #endif /* LDAP_PF_LOCAL */
689 "%s: line %d: unknown style \"%s\" in by clause\n",
690 fname, lineno, style );
694 if ( style_modifier &&
695 strcasecmp( style_modifier, "expand" ) == 0 )
698 case ACL_STYLE_REGEX:
699 fprintf( stderr, "%s: line %d: "
700 "\"regex\" style implies "
701 "\"expand\" modifier"
702 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
704 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
706 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
709 case ACL_STYLE_EXPAND:
711 /* FIXME: now it's legal... */
712 fprintf( stderr, "%s: line %d: "
713 "\"expand\" style used "
714 "in conjunction with "
715 "\"expand\" modifier"
716 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
718 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
720 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
725 /* we'll see later if it's pertinent */
731 /* expand in <who> needs regex in <what> */
732 if ( ( sty == ACL_STYLE_EXPAND || expand )
733 && a->acl_dn_style != ACL_STYLE_REGEX )
735 fprintf( stderr, "%s: line %d: "
736 "\"expand\" style or modifier used "
737 "in conjunction with "
738 "a non-regex <what> clause\n",
742 if ( strncasecmp( left, "real", STRLENOF( "real" ) ) == 0 ) {
745 left += STRLENOF( "real" );
748 if ( strcasecmp( left, "*" ) == 0 ) {
753 ber_str2bv( "*", STRLENOF( "*" ), 1, &bv );
754 sty = ACL_STYLE_REGEX;
756 } else if ( strcasecmp( left, "anonymous" ) == 0 ) {
757 ber_str2bv("anonymous", STRLENOF( "anonymous" ), 1, &bv);
758 sty = ACL_STYLE_ANONYMOUS;
760 } else if ( strcasecmp( left, "users" ) == 0 ) {
761 ber_str2bv("users", STRLENOF( "users" ), 1, &bv);
762 sty = ACL_STYLE_USERS;
764 } else if ( strcasecmp( left, "self" ) == 0 ) {
765 ber_str2bv("self", STRLENOF( "self" ), 1, &bv);
766 sty = ACL_STYLE_SELF;
768 } else if ( strcasecmp( left, "dn" ) == 0 ) {
769 if ( sty == ACL_STYLE_REGEX ) {
770 bdn->a_style = ACL_STYLE_REGEX;
771 if ( right == NULL ) {
776 bdn->a_style = ACL_STYLE_USERS;
778 } else if (*right == '\0' ) {
780 ber_str2bv("anonymous",
781 STRLENOF( "anonymous" ),
783 bdn->a_style = ACL_STYLE_ANONYMOUS;
785 } else if ( strcmp( right, "*" ) == 0 ) {
787 /* any or users? users for now */
791 bdn->a_style = ACL_STYLE_USERS;
793 } else if ( strcmp( right, ".+" ) == 0
794 || strcmp( right, "^.+" ) == 0
795 || strcmp( right, ".+$" ) == 0
796 || strcmp( right, "^.+$" ) == 0
797 || strcmp( right, ".+$$" ) == 0
798 || strcmp( right, "^.+$$" ) == 0 )
803 bdn->a_style = ACL_STYLE_USERS;
805 } else if ( strcmp( right, ".*" ) == 0
806 || strcmp( right, "^.*" ) == 0
807 || strcmp( right, ".*$" ) == 0
808 || strcmp( right, "^.*$" ) == 0
809 || strcmp( right, ".*$$" ) == 0
810 || strcmp( right, "^.*$$" ) == 0 )
817 acl_regex_normalized_dn( right, &bv );
818 if ( !ber_bvccmp( &bv, '*' ) ) {
819 regtest( fname, lineno, bv.bv_val );
823 } else if ( right == NULL || *right == '\0' ) {
824 fprintf( stderr, "%s: line %d: "
825 "missing \"=\" in (or value after) \"%s\" "
827 fname, lineno, left );
831 ber_str2bv( right, 0, 1, &bv );
838 if ( !BER_BVISNULL( &bv ) ) {
839 if ( !BER_BVISEMPTY( &bdn->a_pat ) ) {
841 "%s: line %d: dn pattern already specified.\n",
846 if ( sty != ACL_STYLE_REGEX &&
847 sty != ACL_STYLE_ANONYMOUS &&
848 sty != ACL_STYLE_USERS &&
849 sty != ACL_STYLE_SELF &&
852 rc = dnNormalize(0, NULL, NULL,
853 &bv, &bdn->a_pat, NULL);
854 if ( rc != LDAP_SUCCESS ) {
856 "%s: line %d: bad DN \"%s\" in by DN clause\n",
857 fname, lineno, bv.bv_val );
870 for ( exp = strchr( bdn->a_pat.bv_val, '$' );
871 exp && exp - bdn->a_pat.bv_val < bdn->a_pat.bv_len;
872 exp = strchr( exp, '$' ) )
874 if ( isdigit( exp[ 1 ] ) ) {
881 bdn->a_expand = expand;
885 "%s: line %d: \"expand\" used "
886 "with no expansions in \"pattern\""
887 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
889 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
891 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
894 if ( sty == ACL_STYLE_SELF ) {
895 bdn->a_self_level = level;
900 "%s: line %d: bad negative level \"%d\" "
902 fname, lineno, level );
904 } else if ( level == 1 ) {
906 "%s: line %d: \"onelevel\" should be used "
907 "instead of \"level{1}\" in by DN clause\n",
909 } else if ( level == 0 && sty == ACL_STYLE_LEVEL ) {
911 "%s: line %d: \"base\" should be used "
912 "instead of \"level{0}\" in by DN clause\n",
916 bdn->a_level = level;
921 if ( strcasecmp( left, "dnattr" ) == 0 ) {
922 if ( right == NULL || right[0] == '\0' ) {
923 fprintf( stderr, "%s: line %d: "
924 "missing \"=\" in (or value after) \"%s\" "
926 fname, lineno, left );
930 if( bdn->a_at != NULL ) {
932 "%s: line %d: dnattr already specified.\n",
937 rc = slap_str2ad( right, &bdn->a_at, &text );
939 if( rc != LDAP_SUCCESS ) {
941 "%s: line %d: dnattr \"%s\": %s\n",
942 fname, lineno, right, text );
947 if( !is_at_syntax( bdn->a_at->ad_type,
949 !is_at_syntax( bdn->a_at->ad_type,
950 SLAPD_NAMEUID_SYNTAX ))
953 "%s: line %d: dnattr \"%s\": "
954 "inappropriate syntax: %s\n",
955 fname, lineno, right,
956 bdn->a_at->ad_type->sat_syntax_oid );
960 if( bdn->a_at->ad_type->sat_equality == NULL ) {
962 "%s: line %d: dnattr \"%s\": "
963 "inappropriate matching (no EQUALITY)\n",
964 fname, lineno, right );
971 if ( strncasecmp( left, "group", STRLENOF( "group" ) ) == 0 ) {
976 case ACL_STYLE_REGEX:
977 /* legacy, tolerated */
978 fprintf( stderr, "%s: line %d: "
979 "deprecated group style \"regex\"; "
980 "use \"expand\" instead\n",
981 fname, lineno, style );
982 sty = ACL_STYLE_EXPAND;
986 /* legal, traditional */
987 case ACL_STYLE_EXPAND:
988 /* legal, substring expansion; supersedes regex */
993 fprintf( stderr, "%s: line %d: "
994 "inappropriate style \"%s\" in by clause\n",
995 fname, lineno, style );
999 if ( right == NULL || right[0] == '\0' ) {
1000 fprintf( stderr, "%s: line %d: "
1001 "missing \"=\" in (or value after) \"%s\" "
1003 fname, lineno, left );
1007 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1009 "%s: line %d: group pattern already specified.\n",
1014 /* format of string is
1015 "group/objectClassValue/groupAttrName" */
1016 if ( ( value = strchr(left, '/') ) != NULL ) {
1018 if ( *value && ( name = strchr( value, '/' ) ) != NULL ) {
1023 b->a_group_style = sty;
1024 if ( sty == ACL_STYLE_EXPAND ) {
1025 acl_regex_normalized_dn( right, &bv );
1026 if ( !ber_bvccmp( &bv, '*' ) ) {
1027 regtest( fname, lineno, bv.bv_val );
1029 b->a_group_pat = bv;
1032 ber_str2bv( right, 0, 0, &bv );
1033 rc = dnNormalize( 0, NULL, NULL, &bv,
1034 &b->a_group_pat, NULL );
1035 if ( rc != LDAP_SUCCESS ) {
1037 "%s: line %d: bad DN \"%s\"\n",
1038 fname, lineno, right );
1043 if ( value && *value ) {
1044 b->a_group_oc = oc_find( value );
1047 if ( b->a_group_oc == NULL ) {
1049 "%s: line %d: group objectclass "
1051 fname, lineno, value );
1056 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
1058 if( b->a_group_oc == NULL ) {
1060 "%s: line %d: group default objectclass "
1062 fname, lineno, SLAPD_GROUP_CLASS );
1067 if ( is_object_subclass( slap_schema.si_oc_referral,
1071 "%s: line %d: group objectclass \"%s\" "
1072 "is subclass of referral\n",
1073 fname, lineno, value );
1077 if ( is_object_subclass( slap_schema.si_oc_alias,
1081 "%s: line %d: group objectclass \"%s\" "
1082 "is subclass of alias\n",
1083 fname, lineno, value );
1087 if ( name && *name ) {
1088 rc = slap_str2ad( name, &b->a_group_at, &text );
1090 if( rc != LDAP_SUCCESS ) {
1092 "%s: line %d: group \"%s\": %s\n",
1093 fname, lineno, right, text );
1099 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
1101 if ( rc != LDAP_SUCCESS ) {
1103 "%s: line %d: group \"%s\": %s\n",
1104 fname, lineno, SLAPD_GROUP_ATTR, text );
1109 if ( !is_at_syntax( b->a_group_at->ad_type,
1110 SLAPD_DN_SYNTAX ) &&
1111 !is_at_syntax( b->a_group_at->ad_type,
1112 SLAPD_NAMEUID_SYNTAX ) &&
1113 !is_at_subtype( b->a_group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ) )
1116 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
1117 fname, lineno, right,
1118 b->a_group_at->ad_type->sat_syntax_oid );
1125 struct berval vals[2];
1127 ber_str2bv( b->a_group_oc->soc_oid, 0, 0, &vals[0] );
1128 BER_BVZERO( &vals[1] );
1130 rc = oc_check_allowed( b->a_group_at->ad_type,
1134 fprintf( stderr, "%s: line %d: "
1135 "group: \"%s\" not allowed by \"%s\"\n",
1137 b->a_group_at->ad_cname.bv_val,
1138 b->a_group_oc->soc_oid );
1145 if ( strcasecmp( left, "peername" ) == 0 ) {
1147 case ACL_STYLE_REGEX:
1148 case ACL_STYLE_BASE:
1149 /* legal, traditional */
1150 case ACL_STYLE_EXPAND:
1151 /* cheap replacement to regex for simple expansion */
1153 case ACL_STYLE_PATH:
1154 /* legal, peername specific */
1158 fprintf( stderr, "%s: line %d: "
1159 "inappropriate style \"%s\" in by clause\n",
1160 fname, lineno, style );
1164 if ( right == NULL || right[0] == '\0' ) {
1165 fprintf( stderr, "%s: line %d: "
1166 "missing \"=\" in (or value after) \"%s\" "
1168 fname, lineno, left );
1172 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1173 fprintf( stderr, "%s: line %d: "
1174 "peername pattern already specified.\n",
1179 b->a_peername_style = sty;
1180 if ( sty == ACL_STYLE_REGEX ) {
1181 acl_regex_normalized_dn( right, &bv );
1182 if ( !ber_bvccmp( &bv, '*' ) ) {
1183 regtest( fname, lineno, bv.bv_val );
1185 b->a_peername_pat = bv;
1188 ber_str2bv( right, 0, 1, &b->a_peername_pat );
1190 if ( sty == ACL_STYLE_IP ) {
1195 split( right, '{', &addr, &port );
1196 split( addr, '%', &addr, &mask );
1198 b->a_peername_addr = inet_addr( addr );
1199 if ( b->a_peername_addr == (unsigned long)(-1) ) {
1200 /* illegal address */
1201 fprintf( stderr, "%s: line %d: "
1202 "illegal peername address \"%s\".\n",
1203 fname, lineno, addr );
1207 b->a_peername_mask = (unsigned long)(-1);
1208 if ( mask != NULL ) {
1209 b->a_peername_mask = inet_addr( mask );
1210 if ( b->a_peername_mask ==
1211 (unsigned long)(-1) )
1214 fprintf( stderr, "%s: line %d: "
1215 "illegal peername address mask "
1217 fname, lineno, mask );
1222 b->a_peername_port = -1;
1226 b->a_peername_port = strtol( port, &end, 10 );
1227 if ( end[0] != '}' ) {
1229 fprintf( stderr, "%s: line %d: "
1230 "illegal peername port specification "
1232 fname, lineno, port );
1241 if ( strcasecmp( left, "sockname" ) == 0 ) {
1243 case ACL_STYLE_REGEX:
1244 case ACL_STYLE_BASE:
1245 /* legal, traditional */
1246 case ACL_STYLE_EXPAND:
1247 /* cheap replacement to regex for simple expansion */
1252 fprintf( stderr, "%s: line %d: "
1253 "inappropriate style \"%s\" in by clause\n",
1254 fname, lineno, style );
1258 if ( right == NULL || right[0] == '\0' ) {
1259 fprintf( stderr, "%s: line %d: "
1260 "missing \"=\" in (or value after) \"%s\" "
1262 fname, lineno, left );
1266 if ( !BER_BVISNULL( &b->a_sockname_pat ) ) {
1267 fprintf( stderr, "%s: line %d: "
1268 "sockname pattern already specified.\n",
1273 b->a_sockname_style = sty;
1274 if ( sty == ACL_STYLE_REGEX ) {
1275 acl_regex_normalized_dn( right, &bv );
1276 if ( !ber_bvccmp( &bv, '*' ) ) {
1277 regtest( fname, lineno, bv.bv_val );
1279 b->a_sockname_pat = bv;
1282 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
1287 if ( strcasecmp( left, "domain" ) == 0 ) {
1289 case ACL_STYLE_REGEX:
1290 case ACL_STYLE_BASE:
1291 case ACL_STYLE_SUBTREE:
1292 /* legal, traditional */
1295 case ACL_STYLE_EXPAND:
1296 /* tolerated: means exact,expand */
1300 "\"expand\" modifier "
1301 "with \"expand\" style\n",
1304 sty = ACL_STYLE_BASE;
1310 fprintf( stderr, "%s: line %d: "
1311 "inappropriate style \"%s\" in by clause\n",
1312 fname, lineno, style );
1316 if ( right == NULL || right[0] == '\0' ) {
1317 fprintf( stderr, "%s: line %d: "
1318 "missing \"=\" in (or value after) \"%s\" "
1320 fname, lineno, left );
1324 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1326 "%s: line %d: domain pattern already specified.\n",
1331 b->a_domain_style = sty;
1332 b->a_domain_expand = expand;
1333 if ( sty == ACL_STYLE_REGEX ) {
1334 acl_regex_normalized_dn( right, &bv );
1335 if ( !ber_bvccmp( &bv, '*' ) ) {
1336 regtest( fname, lineno, bv.bv_val );
1338 b->a_domain_pat = bv;
1341 ber_str2bv( right, 0, 1, &b->a_domain_pat );
1346 if ( strcasecmp( left, "sockurl" ) == 0 ) {
1348 case ACL_STYLE_REGEX:
1349 case ACL_STYLE_BASE:
1350 /* legal, traditional */
1351 case ACL_STYLE_EXPAND:
1352 /* cheap replacement to regex for simple expansion */
1357 fprintf( stderr, "%s: line %d: "
1358 "inappropriate style \"%s\" in by clause\n",
1359 fname, lineno, style );
1363 if ( right == NULL || right[0] == '\0' ) {
1364 fprintf( stderr, "%s: line %d: "
1365 "missing \"=\" in (or value after) \"%s\" "
1367 fname, lineno, left );
1371 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1373 "%s: line %d: sockurl pattern already specified.\n",
1378 b->a_sockurl_style = sty;
1379 if ( sty == ACL_STYLE_REGEX ) {
1380 acl_regex_normalized_dn( right, &bv );
1381 if ( !ber_bvccmp( &bv, '*' ) ) {
1382 regtest( fname, lineno, bv.bv_val );
1384 b->a_sockurl_pat = bv;
1387 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
1392 if ( strcasecmp( left, "set" ) == 0 ) {
1395 case ACL_STYLE_REGEX:
1396 fprintf( stderr, "%s: line %d: "
1397 "deprecated set style "
1398 "\"regex\" in <by> clause; "
1399 "use \"expand\" instead\n",
1401 sty = ACL_STYLE_EXPAND;
1404 case ACL_STYLE_BASE:
1405 case ACL_STYLE_EXPAND:
1409 fprintf( stderr, "%s: line %d: "
1410 "inappropriate style \"%s\" in by clause\n",
1411 fname, lineno, style );
1415 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1417 "%s: line %d: set attribute already specified.\n",
1422 if ( right == NULL || *right == '\0' ) {
1424 "%s: line %d: no set is defined\n",
1429 b->a_set_style = sty;
1430 ber_str2bv( right, 0, 1, &b->a_set_pat );
1439 if ( strcasecmp( left, "aci" ) == 0 ) {
1442 } else if ( strncasecmp( left, "dynacl/", STRLENOF( "dynacl/" ) ) == 0 ) {
1443 name = &left[ STRLENOF( "dynacl/" ) ];
1447 if ( slap_dynacl_config( fname, lineno, b, name, sty, right ) ) {
1448 fprintf( stderr, "%s: line %d: "
1449 "unable to configure dynacl \"%s\"\n",
1450 fname, lineno, name );
1457 #else /* ! SLAP_DYNACL */
1459 #ifdef SLAPD_ACI_ENABLED
1460 if ( strcasecmp( left, "aci" ) == 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_aci_at != NULL ) {
1470 "%s: line %d: aci attribute already specified.\n",
1475 if ( right != NULL && *right != '\0' ) {
1476 rc = slap_str2ad( right, &b->a_aci_at, &text );
1478 if( rc != LDAP_SUCCESS ) {
1480 "%s: line %d: aci \"%s\": %s\n",
1481 fname, lineno, right, text );
1486 b->a_aci_at = slap_schema.si_ad_aci;
1489 if( !is_at_syntax( b->a_aci_at->ad_type,
1492 fprintf( stderr, "%s: line %d: "
1493 "aci \"%s\": inappropriate syntax: %s\n",
1494 fname, lineno, right,
1495 b->a_aci_at->ad_type->sat_syntax_oid );
1501 #endif /* SLAPD_ACI_ENABLED */
1502 #endif /* ! SLAP_DYNACL */
1504 if ( strcasecmp( left, "ssf" ) == 0 ) {
1505 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1506 fprintf( stderr, "%s: line %d: "
1507 "inappropriate style \"%s\" in by clause\n",
1508 fname, lineno, style );
1512 if ( b->a_authz.sai_ssf ) {
1514 "%s: line %d: ssf attribute already specified.\n",
1519 if ( right == NULL || *right == '\0' ) {
1521 "%s: line %d: no ssf is defined\n",
1526 b->a_authz.sai_ssf = strtol( right, &next, 10 );
1527 if ( next == NULL || next[0] != '\0' ) {
1529 "%s: line %d: unable to parse ssf value (%s)\n",
1530 fname, lineno, right );
1534 if ( !b->a_authz.sai_ssf ) {
1536 "%s: line %d: invalid ssf value (%s)\n",
1537 fname, lineno, right );
1543 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
1544 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1545 fprintf( stderr, "%s: line %d: "
1546 "inappropriate style \"%s\" in by clause\n",
1547 fname, lineno, style );
1551 if ( b->a_authz.sai_transport_ssf ) {
1552 fprintf( stderr, "%s: line %d: "
1553 "transport_ssf attribute already specified.\n",
1558 if ( right == NULL || *right == '\0' ) {
1560 "%s: line %d: no transport_ssf is defined\n",
1565 b->a_authz.sai_transport_ssf = strtol( right, &next, 10 );
1566 if ( next == NULL || next[0] != '\0' ) {
1567 fprintf( stderr, "%s: line %d: "
1568 "unable to parse transport_ssf value (%s)\n",
1569 fname, lineno, right );
1573 if ( !b->a_authz.sai_transport_ssf ) {
1575 "%s: line %d: invalid transport_ssf value (%s)\n",
1576 fname, lineno, right );
1582 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
1583 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1584 fprintf( stderr, "%s: line %d: "
1585 "inappropriate style \"%s\" in by clause\n",
1586 fname, lineno, style );
1590 if ( b->a_authz.sai_tls_ssf ) {
1591 fprintf( stderr, "%s: line %d: "
1592 "tls_ssf attribute already specified.\n",
1597 if ( right == NULL || *right == '\0' ) {
1599 "%s: line %d: no tls_ssf is defined\n",
1604 b->a_authz.sai_tls_ssf = strtol( right, &next, 10 );
1605 if ( next == NULL || next[0] != '\0' ) {
1606 fprintf( stderr, "%s: line %d: "
1607 "unable to parse tls_ssf value (%s)\n",
1608 fname, lineno, right );
1612 if ( !b->a_authz.sai_tls_ssf ) {
1614 "%s: line %d: invalid tls_ssf value (%s)\n",
1615 fname, lineno, right );
1621 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1622 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1623 fprintf( stderr, "%s: line %d: "
1624 "inappropriate style \"%s\" in by clause\n",
1625 fname, lineno, style );
1629 if ( b->a_authz.sai_sasl_ssf ) {
1630 fprintf( stderr, "%s: line %d: "
1631 "sasl_ssf attribute already specified.\n",
1636 if ( right == NULL || *right == '\0' ) {
1638 "%s: line %d: no sasl_ssf is defined\n",
1643 b->a_authz.sai_sasl_ssf = strtol( right, &next, 10 );
1644 if ( next == NULL || next[0] != '\0' ) {
1645 fprintf( stderr, "%s: line %d: "
1646 "unable to parse sasl_ssf value (%s)\n",
1647 fname, lineno, right );
1651 if ( !b->a_authz.sai_sasl_ssf ) {
1653 "%s: line %d: invalid sasl_ssf value (%s)\n",
1654 fname, lineno, right );
1660 if ( right != NULL ) {
1667 if ( i == argc || ( strcasecmp( left, "stop" ) == 0 ) ) {
1668 /* out of arguments or plain stop */
1670 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1671 b->a_type = ACL_STOP;
1673 access_append( &a->acl_access, b );
1677 if ( strcasecmp( left, "continue" ) == 0 ) {
1678 /* plain continue */
1680 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1681 b->a_type = ACL_CONTINUE;
1683 access_append( &a->acl_access, b );
1687 if ( strcasecmp( left, "break" ) == 0 ) {
1688 /* plain continue */
1690 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1691 b->a_type = ACL_BREAK;
1693 access_append( &a->acl_access, b );
1697 if ( strcasecmp( left, "by" ) == 0 ) {
1698 /* we've gone too far */
1700 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1701 b->a_type = ACL_STOP;
1703 access_append( &a->acl_access, b );
1708 if ( strncasecmp( left, "self", STRLENOF( "self" ) ) == 0 ) {
1710 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "self" ) ] ) );
1712 } else if ( strncasecmp( left, "realself", STRLENOF( "realself" ) ) == 0 ) {
1713 b->a_realdn_self = 1;
1714 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "realself" ) ] ) );
1717 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1720 if ( ACL_IS_INVALID( b->a_access_mask ) ) {
1722 "%s: line %d: expecting <access> got \"%s\"\n",
1723 fname, lineno, left );
1727 b->a_type = ACL_STOP;
1729 if ( ++i == argc ) {
1730 /* out of arguments or plain stop */
1731 access_append( &a->acl_access, b );
1735 if ( strcasecmp( argv[i], "continue" ) == 0 ) {
1736 /* plain continue */
1737 b->a_type = ACL_CONTINUE;
1739 } else if ( strcasecmp( argv[i], "break" ) == 0 ) {
1740 /* plain continue */
1741 b->a_type = ACL_BREAK;
1743 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1748 access_append( &a->acl_access, b );
1752 "%s: line %d: expecting \"to\" "
1753 "or \"by\" got \"%s\"\n",
1754 fname, lineno, argv[i] );
1759 /* if we have no real access clause, complain and do nothing */
1761 fprintf( stderr, "%s: line %d: "
1762 "warning: no access clause(s) specified in access line\n",
1767 if ( ldap_debug & LDAP_DEBUG_ACL ) {
1772 if ( a->acl_access == NULL ) {
1773 fprintf( stderr, "%s: line %d: "
1774 "warning: no by clause(s) specified in access line\n",
1779 if ( !BER_BVISNULL( &be->be_nsuffix[ 1 ] ) ) {
1780 fprintf( stderr, "%s: line %d: warning: "
1781 "scope checking only applies to single-valued "
1782 "suffix databases\n",
1784 /* go ahead, since checking is not authoritative */
1787 switch ( check_scope( be, a ) ) {
1788 case ACL_SCOPE_UNKNOWN:
1789 fprintf( stderr, "%s: line %d: warning: "
1790 "cannot assess the validity of the ACL scope within "
1791 "backend naming context\n",
1795 case ACL_SCOPE_WARN:
1796 fprintf( stderr, "%s: line %d: warning: "
1797 "ACL could be out of scope within backend naming context\n",
1801 case ACL_SCOPE_PARTIAL:
1802 fprintf( stderr, "%s: line %d: warning: "
1803 "ACL appears to be partially out of scope within "
1804 "backend naming context\n",
1809 fprintf( stderr, "%s: line %d: warning: "
1810 "ACL appears to be out of scope within "
1811 "backend naming context\n",
1818 acl_append( &be->be_acl, a, pos );
1821 acl_append( &frontendDB->be_acl, a, pos );
1827 accessmask2str( slap_mask_t mask, char *buf, int debug )
1832 assert( buf != NULL );
1834 if ( ACL_IS_INVALID( mask ) ) {
1840 if ( ACL_IS_LEVEL( mask ) ) {
1841 if ( ACL_LVL_IS_NONE(mask) ) {
1842 ptr = lutil_strcopy( ptr, "none" );
1844 } else if ( ACL_LVL_IS_DISCLOSE(mask) ) {
1845 ptr = lutil_strcopy( ptr, "disclose" );
1847 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1848 ptr = lutil_strcopy( ptr, "auth" );
1850 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1851 ptr = lutil_strcopy( ptr, "compare" );
1853 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1854 ptr = lutil_strcopy( ptr, "search" );
1856 } else if ( ACL_LVL_IS_READ(mask) ) {
1857 ptr = lutil_strcopy( ptr, "read" );
1859 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1860 ptr = lutil_strcopy( ptr, "write" );
1862 } else if ( ACL_LVL_IS_WADD(mask) ) {
1863 ptr = lutil_strcopy( ptr, "add" );
1865 } else if ( ACL_LVL_IS_WDEL(mask) ) {
1866 ptr = lutil_strcopy( ptr, "delete" );
1868 } else if ( ACL_LVL_IS_MANAGE(mask) ) {
1869 ptr = lutil_strcopy( ptr, "manage" );
1872 ptr = lutil_strcopy( ptr, "unknown" );
1882 if( ACL_IS_ADDITIVE( mask ) ) {
1885 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1892 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_MANAGE) ) {
1897 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1901 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WADD) ) {
1905 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WDEL) ) {
1910 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1915 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1920 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1925 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1930 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_DISCLOSE) ) {
1935 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1944 if ( ACL_IS_LEVEL( mask ) ) {
1954 str2accessmask( const char *str )
1958 if( !ASCII_ALPHA(str[0]) ) {
1961 if ( str[0] == '=' ) {
1964 } else if( str[0] == '+' ) {
1965 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1967 } else if( str[0] == '-' ) {
1968 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1971 ACL_INVALIDATE(mask);
1975 for( i=1; str[i] != '\0'; i++ ) {
1976 if( TOLOWER((unsigned char) str[i]) == 'm' ) {
1977 ACL_PRIV_SET(mask, ACL_PRIV_MANAGE);
1979 } else if( TOLOWER((unsigned char) str[i]) == 'w' ) {
1980 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1982 } else if( TOLOWER((unsigned char) str[i]) == 'a' ) {
1983 ACL_PRIV_SET(mask, ACL_PRIV_WADD);
1985 } else if( TOLOWER((unsigned char) str[i]) == 'z' ) {
1986 ACL_PRIV_SET(mask, ACL_PRIV_WDEL);
1988 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
1989 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1991 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
1992 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1994 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
1995 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1997 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
1998 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
2000 } else if( TOLOWER((unsigned char) str[i]) == 'd' ) {
2001 ACL_PRIV_SET(mask, ACL_PRIV_DISCLOSE);
2003 } else if( str[i] != '0' ) {
2004 ACL_INVALIDATE(mask);
2012 if ( strcasecmp( str, "none" ) == 0 ) {
2013 ACL_LVL_ASSIGN_NONE(mask);
2015 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2016 ACL_LVL_ASSIGN_DISCLOSE(mask);
2018 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2019 ACL_LVL_ASSIGN_AUTH(mask);
2021 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2022 ACL_LVL_ASSIGN_COMPARE(mask);
2024 } else if ( strcasecmp( str, "search" ) == 0 ) {
2025 ACL_LVL_ASSIGN_SEARCH(mask);
2027 } else if ( strcasecmp( str, "read" ) == 0 ) {
2028 ACL_LVL_ASSIGN_READ(mask);
2030 } else if ( strcasecmp( str, "add" ) == 0 ) {
2031 ACL_LVL_ASSIGN_WADD(mask);
2033 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2034 ACL_LVL_ASSIGN_WDEL(mask);
2036 } else if ( strcasecmp( str, "write" ) == 0 ) {
2037 ACL_LVL_ASSIGN_WRITE(mask);
2039 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2040 ACL_LVL_ASSIGN_MANAGE(mask);
2043 ACL_INVALIDATE( mask );
2052 fprintf( stderr, "%s%s%s\n",
2053 "<access clause> ::= access to <what> "
2054 "[ by <who> <access> [ <control> ] ]+ \n"
2055 "<what> ::= * | [dn[.<dnstyle>]=<DN>] [filter=<filter>] [attrs=<attrlist>]\n"
2056 "<attrlist> ::= <attr> [val[.<attrstyle>]=<value>] | <attr> , <attrlist>\n"
2057 "<attr> ::= <attrname> | entry | children\n",
2058 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
2059 "\t[ realanonymous | realusers | realself | realdn[.<dnstyle>]=<DN> ]\n"
2060 "\t[dnattr=<attrname>]\n"
2061 "\t[realdnattr=<attrname>]\n"
2062 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
2063 "\t[peername[.<peernamestyle>]=<peer>] [sockname[.<style>]=<name>]\n"
2064 "\t[domain[.<domainstyle>]=<domain>] [sockurl[.<style>]=<url>]\n"
2065 #ifdef SLAPD_ACI_ENABLED
2066 "\t[aci=[<attrname>]]\n"
2069 "\t[dynacl/<name>[.<dynstyle>][=<pattern>]]\n"
2070 #endif /* SLAP_DYNACL */
2071 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n",
2072 "<style> ::= exact | regex | base(Object)\n"
2073 "<dnstyle> ::= base(Object) | one(level) | sub(tree) | children | "
2075 "<attrstyle> ::= exact | regex | base(Object) | one(level) | "
2076 "sub(tree) | children\n"
2077 "<peernamestyle> ::= exact | regex | ip | path\n"
2078 "<domainstyle> ::= exact | regex | base(Object) | sub(tree)\n"
2079 "<access> ::= [[real]self]{<level>|<priv>}\n"
2080 "<level> ::= none|disclose|auth|compare|search|read|{write|add|delete}|manage\n"
2081 "<priv> ::= {=|+|-}{0|d|x|c|s|r|{w|a|z}|m}+\n"
2082 "<control> ::= [ stop | continue | break ]\n"
2084 exit( EXIT_FAILURE );
2088 * Set pattern to a "normalized" DN from src.
2089 * At present it simply eats the (optional) space after
2090 * a RDN separator (,)
2091 * Eventually will evolve in a more complete normalization
2094 acl_regex_normalized_dn(
2096 struct berval *pattern )
2101 str = ch_strdup( src );
2102 len = strlen( src );
2104 for ( p = str; p && p[0]; p++ ) {
2106 if ( p[0] == '\\' && p[1] ) {
2108 * if escaping a hex pair we should
2109 * increment p twice; however, in that
2110 * case the second hex number does
2116 if ( p[0] == ',' && p[1] == ' ' ) {
2120 * too much space should be an error if we are pedantic
2122 for ( q = &p[2]; q[0] == ' '; q++ ) {
2125 AC_MEMCPY( p+1, q, len-(q-str)+1);
2128 pattern->bv_val = str;
2129 pattern->bv_len = p - str;
2142 if ( (*right = strchr( line, splitchar )) != NULL ) {
2143 *((*right)++) = '\0';
2148 access_append( Access **l, Access *a )
2150 for ( ; *l != NULL; l = &(*l)->a_next ) {
2158 acl_append( AccessControl **l, AccessControl *a, int pos )
2162 for (i=0 ; i != pos && *l != NULL; l = &(*l)->acl_next, i++ ) {
2171 access_free( Access *a )
2173 if ( !BER_BVISNULL( &a->a_dn_pat ) ) {
2174 free( a->a_dn_pat.bv_val );
2176 if ( !BER_BVISNULL( &a->a_realdn_pat ) ) {
2177 free( a->a_realdn_pat.bv_val );
2179 if ( !BER_BVISNULL( &a->a_peername_pat ) ) {
2180 free( a->a_peername_pat.bv_val );
2182 if ( !BER_BVISNULL( &a->a_sockname_pat ) ) {
2183 free( a->a_sockname_pat.bv_val );
2185 if ( !BER_BVISNULL( &a->a_domain_pat ) ) {
2186 free( a->a_domain_pat.bv_val );
2188 if ( !BER_BVISNULL( &a->a_sockurl_pat ) ) {
2189 free( a->a_sockurl_pat.bv_val );
2191 if ( !BER_BVISNULL( &a->a_set_pat ) ) {
2192 free( a->a_set_pat.bv_val );
2194 if ( !BER_BVISNULL( &a->a_group_pat ) ) {
2195 free( a->a_group_pat.bv_val );
2201 acl_free( AccessControl *a )
2206 if ( a->acl_filter ) {
2207 filter_free( a->acl_filter );
2209 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2210 free ( a->acl_dn_pat.bv_val );
2212 if ( a->acl_attrs ) {
2213 for ( an = a->acl_attrs; !BER_BVISNULL( &an->an_name ); an++ ) {
2214 free( an->an_name.bv_val );
2216 free( a->acl_attrs );
2218 for ( ; a->acl_access; a->acl_access = n ) {
2219 n = a->acl_access->a_next;
2220 access_free( a->acl_access );
2225 /* Because backend_startup uses acl_append to tack on the global_acl to
2226 * the end of each backend's acl, we cannot just take one argument and
2227 * merrily free our way to the end of the list. backend_destroy calls us
2228 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
2229 * point. config_destroy calls us with global_acl in arg1 and NULL in
2230 * arg2, so we then proceed to polish off the global_acl.
2233 acl_destroy( AccessControl *a, AccessControl *end )
2237 for (; a && a!= end; a=n) {
2244 access2str( slap_access_t access )
2246 if ( access == ACL_NONE ) {
2249 } else if ( access == ACL_DISCLOSE ) {
2252 } else if ( access == ACL_AUTH ) {
2255 } else if ( access == ACL_COMPARE ) {
2258 } else if ( access == ACL_SEARCH ) {
2261 } else if ( access == ACL_READ ) {
2264 } else if ( access == ACL_WRITE ) {
2267 } else if ( access == ACL_WADD ) {
2270 } else if ( access == ACL_WDEL ) {
2273 } else if ( access == ACL_MANAGE ) {
2282 str2access( const char *str )
2284 if ( strcasecmp( str, "none" ) == 0 ) {
2287 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2288 #ifndef SLAP_ACL_HONOR_DISCLOSE
2289 fprintf( stderr, "str2access: warning, "
2290 "\"disclose\" privilege disabled.\n" );
2291 #endif /* SLAP_ACL_HONOR_DISCLOSE */
2292 return ACL_DISCLOSE;
2294 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2297 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2300 } else if ( strcasecmp( str, "search" ) == 0 ) {
2303 } else if ( strcasecmp( str, "read" ) == 0 ) {
2306 } else if ( strcasecmp( str, "write" ) == 0 ) {
2309 } else if ( strcasecmp( str, "add" ) == 0 ) {
2312 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2315 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2319 return( ACL_INVALID_ACCESS );
2322 #define ACLBUF_MAXLEN 8192
2324 static char aclbuf[ACLBUF_MAXLEN];
2327 dnaccess2text( slap_dn_access *bdn, char *ptr, int is_realdn )
2332 ptr = lutil_strcopy( ptr, "real" );
2335 if ( ber_bvccmp( &bdn->a_pat, '*' ) ||
2336 bdn->a_style == ACL_STYLE_ANONYMOUS ||
2337 bdn->a_style == ACL_STYLE_USERS ||
2338 bdn->a_style == ACL_STYLE_SELF )
2341 assert( ! ber_bvccmp( &bdn->a_pat, '*' ) );
2344 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2345 if ( bdn->a_style == ACL_STYLE_SELF && bdn->a_self_level != 0 ) {
2346 int n = sprintf( ptr, ".level{%d}", bdn->a_self_level );
2353 ptr = lutil_strcopy( ptr, "dn." );
2354 if ( bdn->a_style == ACL_STYLE_BASE )
2355 ptr = lutil_strcopy( ptr, style_base );
2357 ptr = lutil_strcopy( ptr, style_strings[bdn->a_style] );
2358 if ( bdn->a_style == ACL_STYLE_LEVEL ) {
2359 int n = sprintf( ptr, "{%d}", bdn->a_level );
2364 if ( bdn->a_expand ) {
2365 ptr = lutil_strcopy( ptr, ",expand" );
2369 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2376 access2text( Access *b, char *ptr )
2378 char maskbuf[ACCESSMASK_MAXLEN];
2380 ptr = lutil_strcopy( ptr, "\tby" );
2382 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
2383 ptr = dnaccess2text( &b->a_dn, ptr, 0 );
2386 ptr = lutil_strcopy( ptr, " dnattr=" );
2387 ptr = lutil_strcopy( ptr, b->a_dn_at->ad_cname.bv_val );
2390 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
2391 ptr = dnaccess2text( &b->a_realdn, ptr, 1 );
2393 if ( b->a_realdn_at ) {
2394 ptr = lutil_strcopy( ptr, " realdnattr=" );
2395 ptr = lutil_strcopy( ptr, b->a_realdn_at->ad_cname.bv_val );
2398 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
2399 ptr = lutil_strcopy( ptr, " group/" );
2400 ptr = lutil_strcopy( ptr, b->a_group_oc ?
2401 b->a_group_oc->soc_cname.bv_val : "groupOfNames" );
2403 ptr = lutil_strcopy( ptr, b->a_group_at ?
2404 b->a_group_at->ad_cname.bv_val : "member" );
2406 ptr = lutil_strcopy( ptr, style_strings[b->a_group_style] );
2409 ptr = lutil_strcopy( ptr, b->a_group_pat.bv_val );
2413 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
2414 ptr = lutil_strcopy( ptr, " peername" );
2416 ptr = lutil_strcopy( ptr, style_strings[b->a_peername_style] );
2419 ptr = lutil_strcopy( ptr, b->a_peername_pat.bv_val );
2423 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
2424 ptr = lutil_strcopy( ptr, " sockname" );
2426 ptr = lutil_strcopy( ptr, style_strings[b->a_sockname_style] );
2429 ptr = lutil_strcopy( ptr, b->a_sockname_pat.bv_val );
2433 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
2434 ptr = lutil_strcopy( ptr, " domain" );
2436 ptr = lutil_strcopy( ptr, style_strings[b->a_domain_style] );
2437 if ( b->a_domain_expand ) {
2438 ptr = lutil_strcopy( ptr, ",expand" );
2441 ptr = lutil_strcopy( ptr, b->a_domain_pat.bv_val );
2444 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
2445 ptr = lutil_strcopy( ptr, " sockurl" );
2447 ptr = lutil_strcopy( ptr, style_strings[b->a_sockurl_style] );
2450 ptr = lutil_strcopy( ptr, b->a_sockurl_pat.bv_val );
2454 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
2455 ptr = lutil_strcopy( ptr, " set" );
2457 ptr = lutil_strcopy( ptr, style_strings[b->a_set_style] );
2460 ptr = lutil_strcopy( ptr, b->a_set_pat.bv_val );
2465 if ( b->a_dynacl ) {
2468 for ( da = b->a_dynacl; da; da = da->da_next ) {
2469 if ( da->da_unparse ) {
2471 (void)( *da->da_unparse )( da->da_private, &bv );
2472 ptr = lutil_strcopy( ptr, bv.bv_val );
2473 ch_free( bv.bv_val );
2477 #else /* ! SLAP_DYNACL */
2478 #ifdef SLAPD_ACI_ENABLED
2479 if ( b->a_aci_at != NULL ) {
2480 ptr = lutil_strcopy( ptr, " aci=" );
2481 ptr = lutil_strcopy( ptr, b->a_aci_at->ad_cname.bv_val );
2484 #endif /* SLAP_DYNACL */
2486 /* Security Strength Factors */
2487 if ( b->a_authz.sai_ssf ) {
2488 ptr += sprintf( ptr, " ssf=%u",
2489 b->a_authz.sai_ssf );
2491 if ( b->a_authz.sai_transport_ssf ) {
2492 ptr += sprintf( ptr, " transport_ssf=%u",
2493 b->a_authz.sai_transport_ssf );
2495 if ( b->a_authz.sai_tls_ssf ) {
2496 ptr += sprintf( ptr, " tls_ssf=%u",
2497 b->a_authz.sai_tls_ssf );
2499 if ( b->a_authz.sai_sasl_ssf ) {
2500 ptr += sprintf( ptr, " sasl_ssf=%u",
2501 b->a_authz.sai_sasl_ssf );
2505 if ( b->a_dn_self ) {
2506 ptr = lutil_strcopy( ptr, "self" );
2507 } else if ( b->a_realdn_self ) {
2508 ptr = lutil_strcopy( ptr, "realself" );
2510 ptr = lutil_strcopy( ptr, accessmask2str( b->a_access_mask, maskbuf, 0 ));
2511 if ( !maskbuf[0] ) ptr--;
2513 if( b->a_type == ACL_BREAK ) {
2514 ptr = lutil_strcopy( ptr, " break" );
2516 } else if( b->a_type == ACL_CONTINUE ) {
2517 ptr = lutil_strcopy( ptr, " continue" );
2519 } else if( b->a_type != ACL_STOP ) {
2520 ptr = lutil_strcopy( ptr, " unknown-control" );
2522 if ( !maskbuf[0] ) ptr = lutil_strcopy( ptr, " stop" );
2530 acl_unparse( AccessControl *a, struct berval *bv )
2536 bv->bv_val = aclbuf;
2541 ptr = lutil_strcopy( ptr, "to" );
2542 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2544 ptr = lutil_strcopy( ptr, " dn." );
2545 if ( a->acl_dn_style == ACL_STYLE_BASE )
2546 ptr = lutil_strcopy( ptr, style_base );
2548 ptr = lutil_strcopy( ptr, style_strings[a->acl_dn_style] );
2551 ptr = lutil_strcopy( ptr, a->acl_dn_pat.bv_val );
2552 ptr = lutil_strcopy( ptr, "\"\n" );
2555 if ( a->acl_filter != NULL ) {
2556 struct berval bv = BER_BVNULL;
2559 filter2bv( a->acl_filter, &bv );
2560 ptr = lutil_strcopy( ptr, " filter=\"" );
2561 ptr = lutil_strcopy( ptr, bv.bv_val );
2564 ch_free( bv.bv_val );
2567 if ( a->acl_attrs != NULL ) {
2572 ptr = lutil_strcopy( ptr, " attrs=" );
2573 for ( an = a->acl_attrs; an && !BER_BVISNULL( &an->an_name ); an++ ) {
2574 if ( ! first ) *ptr++ = ',';
2576 *ptr++ = an->an_oc_exclude ? '!' : '@';
2577 ptr = lutil_strcopy( ptr, an->an_oc->soc_cname.bv_val );
2580 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2587 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
2589 ptr = lutil_strcopy( ptr, " val." );
2590 if ( a->acl_attrval_style == ACL_STYLE_BASE &&
2591 a->acl_attrs[0].an_desc->ad_type->sat_syntax ==
2592 slap_schema.si_syn_distinguishedName )
2593 ptr = lutil_strcopy( ptr, style_base );
2595 ptr = lutil_strcopy( ptr, style_strings[a->acl_attrval_style] );
2598 ptr = lutil_strcopy( ptr, a->acl_attrval.bv_val );
2604 ptr = lutil_strcopy( ptr, " *\n" );
2607 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
2608 ptr = access2text( b, ptr );
2611 bv->bv_len = ptr - bv->bv_val;
2617 print_acl( Backend *be, AccessControl *a )
2621 acl_unparse( a, &bv );
2622 fprintf( stderr, "%s ACL: access %s\n",
2623 be == NULL ? "Global" : "Backend", bv.bv_val );
2625 #endif /* LDAP_DEBUG */