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 );
544 if ( !BER_BVISEMPTY( &a->acl_dn_pat ) ||
545 a->acl_dn_style != ACL_STYLE_REGEX )
547 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
549 rc = dnNormalize( 0, NULL, NULL, &a->acl_dn_pat, &bv, NULL);
550 if ( rc != LDAP_SUCCESS ) {
552 "%s: line %d: bad DN \"%s\" in to DN clause\n",
553 fname, lineno, a->acl_dn_pat.bv_val );
556 free( a->acl_dn_pat.bv_val );
560 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
561 REG_EXTENDED | REG_ICASE );
564 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
565 fprintf( stderr, "%s: line %d: "
566 "regular expression \"%s\" bad because of %s\n",
567 fname, lineno, right, buf );
573 /* by clause - select who has what access to entries */
574 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
576 fprintf( stderr, "%s: line %d: "
577 "to clause required before by clause in access line\n",
583 * by clause consists of <who> and <access>
586 b = (Access *) ch_calloc( 1, sizeof(Access) );
588 ACL_INVALIDATE( b->a_access_mask );
592 "%s: line %d: premature eol: expecting <who>\n",
598 for ( ; i < argc; i++ ) {
599 slap_style_t sty = ACL_STYLE_REGEX;
600 char *style_modifier = NULL;
601 char *style_level = NULL;
604 slap_dn_access *bdn = &b->a_dn;
607 split( argv[i], '=', &left, &right );
608 split( left, '.', &left, &style );
610 split( style, ',', &style, &style_modifier );
612 if ( strncasecmp( style, "level", STRLENOF( "level" ) ) == 0 ) {
613 split( style, '{', &style, &style_level );
614 if ( style_level != NULL ) {
615 char *p = strchr( style_level, '}' );
618 "%s: line %d: premature eol: "
619 "expecting closing '}' in \"level{n}\"\n",
622 } else if ( p == style_level ) {
624 "%s: line %d: empty level "
634 if ( style == NULL || *style == '\0' ||
635 strcasecmp( style, "exact" ) == 0 ||
636 strcasecmp( style, "baseObject" ) == 0 ||
637 strcasecmp( style, "base" ) == 0 )
639 sty = ACL_STYLE_BASE;
641 } else if ( strcasecmp( style, "onelevel" ) == 0 ||
642 strcasecmp( style, "one" ) == 0 )
646 } else if ( strcasecmp( style, "subtree" ) == 0 ||
647 strcasecmp( style, "sub" ) == 0 )
649 sty = ACL_STYLE_SUBTREE;
651 } else if ( strcasecmp( style, "children" ) == 0 ) {
652 sty = ACL_STYLE_CHILDREN;
654 } else if ( strcasecmp( style, "level" ) == 0 )
658 level = strtol( style_level, &next, 10 );
659 if ( next[0] != '\0' ) {
661 "%s: line %d: unable to parse level "
667 sty = ACL_STYLE_LEVEL;
669 } else if ( strcasecmp( style, "regex" ) == 0 ) {
670 sty = ACL_STYLE_REGEX;
672 } else if ( strcasecmp( style, "expand" ) == 0 ) {
673 sty = ACL_STYLE_EXPAND;
675 } else if ( strcasecmp( style, "ip" ) == 0 ) {
678 } else if ( strcasecmp( style, "path" ) == 0 ) {
679 sty = ACL_STYLE_PATH;
680 #ifndef LDAP_PF_LOCAL
681 fprintf( stderr, "%s: line %d: "
682 "path style modifier is useless without local\n",
684 #endif /* LDAP_PF_LOCAL */
688 "%s: line %d: unknown style \"%s\" in by clause\n",
689 fname, lineno, style );
693 if ( style_modifier &&
694 strcasecmp( style_modifier, "expand" ) == 0 )
697 case ACL_STYLE_REGEX:
698 fprintf( stderr, "%s: line %d: "
699 "\"regex\" style implies "
700 "\"expand\" modifier"
701 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
703 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
705 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
708 case ACL_STYLE_EXPAND:
710 /* FIXME: now it's legal... */
711 fprintf( stderr, "%s: line %d: "
712 "\"expand\" style used "
713 "in conjunction with "
714 "\"expand\" modifier"
715 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
717 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
719 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
724 /* we'll see later if it's pertinent */
730 /* expand in <who> needs regex in <what> */
731 if ( ( sty == ACL_STYLE_EXPAND || expand )
732 && a->acl_dn_style != ACL_STYLE_REGEX )
734 fprintf( stderr, "%s: line %d: "
735 "\"expand\" style or modifier used "
736 "in conjunction with "
737 "a non-regex <what> clause\n",
741 if ( strncasecmp( left, "real", STRLENOF( "real" ) ) == 0 ) {
744 left += STRLENOF( "real" );
747 if ( strcasecmp( left, "*" ) == 0 ) {
752 ber_str2bv( "*", STRLENOF( "*" ), 1, &bv );
753 sty = ACL_STYLE_REGEX;
755 } else if ( strcasecmp( left, "anonymous" ) == 0 ) {
756 ber_str2bv("anonymous", STRLENOF( "anonymous" ), 1, &bv);
757 sty = ACL_STYLE_ANONYMOUS;
759 } else if ( strcasecmp( left, "users" ) == 0 ) {
760 ber_str2bv("users", STRLENOF( "users" ), 1, &bv);
761 sty = ACL_STYLE_USERS;
763 } else if ( strcasecmp( left, "self" ) == 0 ) {
764 ber_str2bv("self", STRLENOF( "self" ), 1, &bv);
765 sty = ACL_STYLE_SELF;
767 } else if ( strcasecmp( left, "dn" ) == 0 ) {
768 if ( sty == ACL_STYLE_REGEX ) {
769 bdn->a_style = ACL_STYLE_REGEX;
770 if ( right == NULL ) {
775 bdn->a_style = ACL_STYLE_USERS;
777 } else if (*right == '\0' ) {
779 ber_str2bv("anonymous",
780 STRLENOF( "anonymous" ),
782 bdn->a_style = ACL_STYLE_ANONYMOUS;
784 } else if ( strcmp( right, "*" ) == 0 ) {
786 /* any or users? users for now */
790 bdn->a_style = ACL_STYLE_USERS;
792 } else if ( strcmp( right, ".+" ) == 0
793 || strcmp( right, "^.+" ) == 0
794 || strcmp( right, ".+$" ) == 0
795 || strcmp( right, "^.+$" ) == 0
796 || strcmp( right, ".+$$" ) == 0
797 || strcmp( right, "^.+$$" ) == 0 )
802 bdn->a_style = ACL_STYLE_USERS;
804 } else if ( strcmp( right, ".*" ) == 0
805 || strcmp( right, "^.*" ) == 0
806 || strcmp( right, ".*$" ) == 0
807 || strcmp( right, "^.*$" ) == 0
808 || strcmp( right, ".*$$" ) == 0
809 || strcmp( right, "^.*$$" ) == 0 )
816 acl_regex_normalized_dn( right, &bv );
817 if ( !ber_bvccmp( &bv, '*' ) ) {
818 regtest( fname, lineno, bv.bv_val );
822 } else if ( right == NULL || *right == '\0' ) {
823 fprintf( stderr, "%s: line %d: "
824 "missing \"=\" in (or value after) \"%s\" "
826 fname, lineno, left );
830 ber_str2bv( right, 0, 1, &bv );
837 if ( !BER_BVISNULL( &bv ) ) {
838 if ( !BER_BVISEMPTY( &bdn->a_pat ) ) {
840 "%s: line %d: dn pattern already specified.\n",
845 if ( sty != ACL_STYLE_REGEX &&
846 sty != ACL_STYLE_ANONYMOUS &&
847 sty != ACL_STYLE_USERS &&
848 sty != ACL_STYLE_SELF &&
851 rc = dnNormalize(0, NULL, NULL,
852 &bv, &bdn->a_pat, NULL);
853 if ( rc != LDAP_SUCCESS ) {
855 "%s: line %d: bad DN \"%s\" in by DN clause\n",
856 fname, lineno, bv.bv_val );
869 for ( exp = strchr( bdn->a_pat.bv_val, '$' );
870 exp && exp - bdn->a_pat.bv_val < bdn->a_pat.bv_len;
871 exp = strchr( exp, '$' ) )
873 if ( isdigit( exp[ 1 ] ) ) {
880 bdn->a_expand = expand;
884 "%s: line %d: \"expand\" used "
885 "with no expansions in \"pattern\""
886 SLAPD_CONF_UNKNOWN_IGNORED ".\n",
888 #ifdef SLAPD_CONF_UNKNOWN_BAILOUT
890 #endif /* SLAPD_CONF_UNKNOWN_BAILOUT */
893 if ( sty == ACL_STYLE_SELF ) {
894 bdn->a_self_level = level;
899 "%s: line %d: bad negative level \"%d\" "
901 fname, lineno, level );
903 } else if ( level == 1 ) {
905 "%s: line %d: \"onelevel\" should be used "
906 "instead of \"level{1}\" in by DN clause\n",
908 } else if ( level == 0 && sty == ACL_STYLE_LEVEL ) {
910 "%s: line %d: \"base\" should be used "
911 "instead of \"level{0}\" in by DN clause\n",
915 bdn->a_level = level;
920 if ( strcasecmp( left, "dnattr" ) == 0 ) {
921 if ( right == NULL || right[0] == '\0' ) {
922 fprintf( stderr, "%s: line %d: "
923 "missing \"=\" in (or value after) \"%s\" "
925 fname, lineno, left );
929 if( bdn->a_at != NULL ) {
931 "%s: line %d: dnattr already specified.\n",
936 rc = slap_str2ad( right, &bdn->a_at, &text );
938 if( rc != LDAP_SUCCESS ) {
940 "%s: line %d: dnattr \"%s\": %s\n",
941 fname, lineno, right, text );
946 if( !is_at_syntax( bdn->a_at->ad_type,
948 !is_at_syntax( bdn->a_at->ad_type,
949 SLAPD_NAMEUID_SYNTAX ))
952 "%s: line %d: dnattr \"%s\": "
953 "inappropriate syntax: %s\n",
954 fname, lineno, right,
955 bdn->a_at->ad_type->sat_syntax_oid );
959 if( bdn->a_at->ad_type->sat_equality == NULL ) {
961 "%s: line %d: dnattr \"%s\": "
962 "inappropriate matching (no EQUALITY)\n",
963 fname, lineno, right );
970 if ( strncasecmp( left, "group", STRLENOF( "group" ) ) == 0 ) {
975 case ACL_STYLE_REGEX:
976 /* legacy, tolerated */
977 fprintf( stderr, "%s: line %d: "
978 "deprecated group style \"regex\"; "
979 "use \"expand\" instead\n",
980 fname, lineno, style );
981 sty = ACL_STYLE_EXPAND;
985 /* legal, traditional */
986 case ACL_STYLE_EXPAND:
987 /* legal, substring expansion; supersedes regex */
992 fprintf( stderr, "%s: line %d: "
993 "inappropriate style \"%s\" in by clause\n",
994 fname, lineno, style );
998 if ( right == NULL || right[0] == '\0' ) {
999 fprintf( stderr, "%s: line %d: "
1000 "missing \"=\" in (or value after) \"%s\" "
1002 fname, lineno, left );
1006 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
1008 "%s: line %d: group pattern already specified.\n",
1013 /* format of string is
1014 "group/objectClassValue/groupAttrName" */
1015 if ( ( value = strchr(left, '/') ) != NULL ) {
1017 if ( *value && ( name = strchr( value, '/' ) ) != NULL ) {
1022 b->a_group_style = sty;
1023 if ( sty == ACL_STYLE_EXPAND ) {
1024 acl_regex_normalized_dn( right, &bv );
1025 if ( !ber_bvccmp( &bv, '*' ) ) {
1026 regtest( fname, lineno, bv.bv_val );
1028 b->a_group_pat = bv;
1031 ber_str2bv( right, 0, 0, &bv );
1032 rc = dnNormalize( 0, NULL, NULL, &bv,
1033 &b->a_group_pat, NULL );
1034 if ( rc != LDAP_SUCCESS ) {
1036 "%s: line %d: bad DN \"%s\"\n",
1037 fname, lineno, right );
1042 if ( value && *value ) {
1043 b->a_group_oc = oc_find( value );
1046 if ( b->a_group_oc == NULL ) {
1048 "%s: line %d: group objectclass "
1050 fname, lineno, value );
1055 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
1057 if( b->a_group_oc == NULL ) {
1059 "%s: line %d: group default objectclass "
1061 fname, lineno, SLAPD_GROUP_CLASS );
1066 if ( is_object_subclass( slap_schema.si_oc_referral,
1070 "%s: line %d: group objectclass \"%s\" "
1071 "is subclass of referral\n",
1072 fname, lineno, value );
1076 if ( is_object_subclass( slap_schema.si_oc_alias,
1080 "%s: line %d: group objectclass \"%s\" "
1081 "is subclass of alias\n",
1082 fname, lineno, value );
1086 if ( name && *name ) {
1087 rc = slap_str2ad( name, &b->a_group_at, &text );
1089 if( rc != LDAP_SUCCESS ) {
1091 "%s: line %d: group \"%s\": %s\n",
1092 fname, lineno, right, text );
1098 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
1100 if ( rc != LDAP_SUCCESS ) {
1102 "%s: line %d: group \"%s\": %s\n",
1103 fname, lineno, SLAPD_GROUP_ATTR, text );
1108 if ( !is_at_syntax( b->a_group_at->ad_type,
1109 SLAPD_DN_SYNTAX ) &&
1110 !is_at_syntax( b->a_group_at->ad_type,
1111 SLAPD_NAMEUID_SYNTAX ) &&
1112 !is_at_subtype( b->a_group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ) )
1115 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
1116 fname, lineno, right,
1117 b->a_group_at->ad_type->sat_syntax_oid );
1124 struct berval vals[2];
1126 ber_str2bv( b->a_group_oc->soc_oid, 0, 0, &vals[0] );
1127 BER_BVZERO( &vals[1] );
1129 rc = oc_check_allowed( b->a_group_at->ad_type,
1133 fprintf( stderr, "%s: line %d: "
1134 "group: \"%s\" not allowed by \"%s\"\n",
1136 b->a_group_at->ad_cname.bv_val,
1137 b->a_group_oc->soc_oid );
1144 if ( strcasecmp( left, "peername" ) == 0 ) {
1146 case ACL_STYLE_REGEX:
1147 case ACL_STYLE_BASE:
1148 /* legal, traditional */
1149 case ACL_STYLE_EXPAND:
1150 /* cheap replacement to regex for simple expansion */
1152 case ACL_STYLE_PATH:
1153 /* legal, peername specific */
1157 fprintf( stderr, "%s: line %d: "
1158 "inappropriate style \"%s\" in by clause\n",
1159 fname, lineno, style );
1163 if ( right == NULL || right[0] == '\0' ) {
1164 fprintf( stderr, "%s: line %d: "
1165 "missing \"=\" in (or value after) \"%s\" "
1167 fname, lineno, left );
1171 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
1172 fprintf( stderr, "%s: line %d: "
1173 "peername pattern already specified.\n",
1178 b->a_peername_style = sty;
1179 if ( sty == ACL_STYLE_REGEX ) {
1180 acl_regex_normalized_dn( right, &bv );
1181 if ( !ber_bvccmp( &bv, '*' ) ) {
1182 regtest( fname, lineno, bv.bv_val );
1184 b->a_peername_pat = bv;
1187 ber_str2bv( right, 0, 1, &b->a_peername_pat );
1189 if ( sty == ACL_STYLE_IP ) {
1194 split( right, '{', &addr, &port );
1195 split( addr, '%', &addr, &mask );
1197 b->a_peername_addr = inet_addr( addr );
1198 if ( b->a_peername_addr == (unsigned long)(-1) ) {
1199 /* illegal address */
1200 fprintf( stderr, "%s: line %d: "
1201 "illegal peername address \"%s\".\n",
1202 fname, lineno, addr );
1206 b->a_peername_mask = (unsigned long)(-1);
1207 if ( mask != NULL ) {
1208 b->a_peername_mask = inet_addr( mask );
1209 if ( b->a_peername_mask ==
1210 (unsigned long)(-1) )
1213 fprintf( stderr, "%s: line %d: "
1214 "illegal peername address mask "
1216 fname, lineno, mask );
1221 b->a_peername_port = -1;
1225 b->a_peername_port = strtol( port, &end, 10 );
1226 if ( end[0] != '}' ) {
1228 fprintf( stderr, "%s: line %d: "
1229 "illegal peername port specification "
1231 fname, lineno, port );
1240 if ( strcasecmp( left, "sockname" ) == 0 ) {
1242 case ACL_STYLE_REGEX:
1243 case ACL_STYLE_BASE:
1244 /* legal, traditional */
1245 case ACL_STYLE_EXPAND:
1246 /* cheap replacement to regex for simple expansion */
1251 fprintf( stderr, "%s: line %d: "
1252 "inappropriate style \"%s\" in by clause\n",
1253 fname, lineno, style );
1257 if ( right == NULL || right[0] == '\0' ) {
1258 fprintf( stderr, "%s: line %d: "
1259 "missing \"=\" in (or value after) \"%s\" "
1261 fname, lineno, left );
1265 if ( !BER_BVISNULL( &b->a_sockname_pat ) ) {
1266 fprintf( stderr, "%s: line %d: "
1267 "sockname pattern already specified.\n",
1272 b->a_sockname_style = sty;
1273 if ( sty == ACL_STYLE_REGEX ) {
1274 acl_regex_normalized_dn( right, &bv );
1275 if ( !ber_bvccmp( &bv, '*' ) ) {
1276 regtest( fname, lineno, bv.bv_val );
1278 b->a_sockname_pat = bv;
1281 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
1286 if ( strcasecmp( left, "domain" ) == 0 ) {
1288 case ACL_STYLE_REGEX:
1289 case ACL_STYLE_BASE:
1290 case ACL_STYLE_SUBTREE:
1291 /* legal, traditional */
1294 case ACL_STYLE_EXPAND:
1295 /* tolerated: means exact,expand */
1299 "\"expand\" modifier "
1300 "with \"expand\" style\n",
1303 sty = ACL_STYLE_BASE;
1309 fprintf( stderr, "%s: line %d: "
1310 "inappropriate style \"%s\" in by clause\n",
1311 fname, lineno, style );
1315 if ( right == NULL || right[0] == '\0' ) {
1316 fprintf( stderr, "%s: line %d: "
1317 "missing \"=\" in (or value after) \"%s\" "
1319 fname, lineno, left );
1323 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
1325 "%s: line %d: domain pattern already specified.\n",
1330 b->a_domain_style = sty;
1331 b->a_domain_expand = expand;
1332 if ( sty == ACL_STYLE_REGEX ) {
1333 acl_regex_normalized_dn( right, &bv );
1334 if ( !ber_bvccmp( &bv, '*' ) ) {
1335 regtest( fname, lineno, bv.bv_val );
1337 b->a_domain_pat = bv;
1340 ber_str2bv( right, 0, 1, &b->a_domain_pat );
1345 if ( strcasecmp( left, "sockurl" ) == 0 ) {
1347 case ACL_STYLE_REGEX:
1348 case ACL_STYLE_BASE:
1349 /* legal, traditional */
1350 case ACL_STYLE_EXPAND:
1351 /* cheap replacement to regex for simple expansion */
1356 fprintf( stderr, "%s: line %d: "
1357 "inappropriate style \"%s\" in by clause\n",
1358 fname, lineno, style );
1362 if ( right == NULL || right[0] == '\0' ) {
1363 fprintf( stderr, "%s: line %d: "
1364 "missing \"=\" in (or value after) \"%s\" "
1366 fname, lineno, left );
1370 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
1372 "%s: line %d: sockurl pattern already specified.\n",
1377 b->a_sockurl_style = sty;
1378 if ( sty == ACL_STYLE_REGEX ) {
1379 acl_regex_normalized_dn( right, &bv );
1380 if ( !ber_bvccmp( &bv, '*' ) ) {
1381 regtest( fname, lineno, bv.bv_val );
1383 b->a_sockurl_pat = bv;
1386 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
1391 if ( strcasecmp( left, "set" ) == 0 ) {
1394 case ACL_STYLE_REGEX:
1395 fprintf( stderr, "%s: line %d: "
1396 "deprecated set style "
1397 "\"regex\" in <by> clause; "
1398 "use \"expand\" instead\n",
1400 sty = ACL_STYLE_EXPAND;
1403 case ACL_STYLE_BASE:
1404 case ACL_STYLE_EXPAND:
1408 fprintf( stderr, "%s: line %d: "
1409 "inappropriate style \"%s\" in by clause\n",
1410 fname, lineno, style );
1414 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
1416 "%s: line %d: set attribute already specified.\n",
1421 if ( right == NULL || *right == '\0' ) {
1423 "%s: line %d: no set is defined\n",
1428 b->a_set_style = sty;
1429 ber_str2bv( right, 0, 1, &b->a_set_pat );
1438 if ( strcasecmp( left, "aci" ) == 0 ) {
1441 } else if ( strncasecmp( left, "dynacl/", STRLENOF( "dynacl/" ) ) == 0 ) {
1442 name = &left[ STRLENOF( "dynacl/" ) ];
1446 if ( slap_dynacl_config( fname, lineno, b, name, sty, right ) ) {
1447 fprintf( stderr, "%s: line %d: "
1448 "unable to configure dynacl \"%s\"\n",
1449 fname, lineno, name );
1456 #else /* ! SLAP_DYNACL */
1458 #ifdef SLAPD_ACI_ENABLED
1459 if ( strcasecmp( left, "aci" ) == 0 ) {
1460 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1461 fprintf( stderr, "%s: line %d: "
1462 "inappropriate style \"%s\" in by clause\n",
1463 fname, lineno, style );
1467 if( b->a_aci_at != NULL ) {
1469 "%s: line %d: aci attribute already specified.\n",
1474 if ( right != NULL && *right != '\0' ) {
1475 rc = slap_str2ad( right, &b->a_aci_at, &text );
1477 if( rc != LDAP_SUCCESS ) {
1479 "%s: line %d: aci \"%s\": %s\n",
1480 fname, lineno, right, text );
1485 b->a_aci_at = slap_schema.si_ad_aci;
1488 if( !is_at_syntax( b->a_aci_at->ad_type,
1491 fprintf( stderr, "%s: line %d: "
1492 "aci \"%s\": inappropriate syntax: %s\n",
1493 fname, lineno, right,
1494 b->a_aci_at->ad_type->sat_syntax_oid );
1500 #endif /* SLAPD_ACI_ENABLED */
1501 #endif /* ! SLAP_DYNACL */
1503 if ( strcasecmp( left, "ssf" ) == 0 ) {
1504 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1505 fprintf( stderr, "%s: line %d: "
1506 "inappropriate style \"%s\" in by clause\n",
1507 fname, lineno, style );
1511 if ( b->a_authz.sai_ssf ) {
1513 "%s: line %d: ssf attribute already specified.\n",
1518 if ( right == NULL || *right == '\0' ) {
1520 "%s: line %d: no ssf is defined\n",
1525 b->a_authz.sai_ssf = strtol( right, &next, 10 );
1526 if ( next == NULL || next[0] != '\0' ) {
1528 "%s: line %d: unable to parse ssf value (%s)\n",
1529 fname, lineno, right );
1533 if ( !b->a_authz.sai_ssf ) {
1535 "%s: line %d: invalid ssf value (%s)\n",
1536 fname, lineno, right );
1542 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
1543 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1544 fprintf( stderr, "%s: line %d: "
1545 "inappropriate style \"%s\" in by clause\n",
1546 fname, lineno, style );
1550 if ( b->a_authz.sai_transport_ssf ) {
1551 fprintf( stderr, "%s: line %d: "
1552 "transport_ssf attribute already specified.\n",
1557 if ( right == NULL || *right == '\0' ) {
1559 "%s: line %d: no transport_ssf is defined\n",
1564 b->a_authz.sai_transport_ssf = strtol( right, &next, 10 );
1565 if ( next == NULL || next[0] != '\0' ) {
1566 fprintf( stderr, "%s: line %d: "
1567 "unable to parse transport_ssf value (%s)\n",
1568 fname, lineno, right );
1572 if ( !b->a_authz.sai_transport_ssf ) {
1574 "%s: line %d: invalid transport_ssf value (%s)\n",
1575 fname, lineno, right );
1581 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
1582 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1583 fprintf( stderr, "%s: line %d: "
1584 "inappropriate style \"%s\" in by clause\n",
1585 fname, lineno, style );
1589 if ( b->a_authz.sai_tls_ssf ) {
1590 fprintf( stderr, "%s: line %d: "
1591 "tls_ssf attribute already specified.\n",
1596 if ( right == NULL || *right == '\0' ) {
1598 "%s: line %d: no tls_ssf is defined\n",
1603 b->a_authz.sai_tls_ssf = strtol( right, &next, 10 );
1604 if ( next == NULL || next[0] != '\0' ) {
1605 fprintf( stderr, "%s: line %d: "
1606 "unable to parse tls_ssf value (%s)\n",
1607 fname, lineno, right );
1611 if ( !b->a_authz.sai_tls_ssf ) {
1613 "%s: line %d: invalid tls_ssf value (%s)\n",
1614 fname, lineno, right );
1620 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1621 if ( sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE ) {
1622 fprintf( stderr, "%s: line %d: "
1623 "inappropriate style \"%s\" in by clause\n",
1624 fname, lineno, style );
1628 if ( b->a_authz.sai_sasl_ssf ) {
1629 fprintf( stderr, "%s: line %d: "
1630 "sasl_ssf attribute already specified.\n",
1635 if ( right == NULL || *right == '\0' ) {
1637 "%s: line %d: no sasl_ssf is defined\n",
1642 b->a_authz.sai_sasl_ssf = strtol( right, &next, 10 );
1643 if ( next == NULL || next[0] != '\0' ) {
1644 fprintf( stderr, "%s: line %d: "
1645 "unable to parse sasl_ssf value (%s)\n",
1646 fname, lineno, right );
1650 if ( !b->a_authz.sai_sasl_ssf ) {
1652 "%s: line %d: invalid sasl_ssf value (%s)\n",
1653 fname, lineno, right );
1659 if ( right != NULL ) {
1666 if ( i == argc || ( strcasecmp( left, "stop" ) == 0 ) ) {
1667 /* out of arguments or plain stop */
1669 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1670 b->a_type = ACL_STOP;
1672 access_append( &a->acl_access, b );
1676 if ( strcasecmp( left, "continue" ) == 0 ) {
1677 /* plain continue */
1679 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1680 b->a_type = ACL_CONTINUE;
1682 access_append( &a->acl_access, b );
1686 if ( strcasecmp( left, "break" ) == 0 ) {
1687 /* plain continue */
1689 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1690 b->a_type = ACL_BREAK;
1692 access_append( &a->acl_access, b );
1696 if ( strcasecmp( left, "by" ) == 0 ) {
1697 /* we've gone too far */
1699 ACL_PRIV_ASSIGN( b->a_access_mask, ACL_PRIV_ADDITIVE );
1700 b->a_type = ACL_STOP;
1702 access_append( &a->acl_access, b );
1707 if ( strncasecmp( left, "self", STRLENOF( "self" ) ) == 0 ) {
1709 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "self" ) ] ) );
1711 } else if ( strncasecmp( left, "realself", STRLENOF( "realself" ) ) == 0 ) {
1712 b->a_realdn_self = 1;
1713 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[ STRLENOF( "realself" ) ] ) );
1716 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1719 if ( ACL_IS_INVALID( b->a_access_mask ) ) {
1721 "%s: line %d: expecting <access> got \"%s\"\n",
1722 fname, lineno, left );
1726 b->a_type = ACL_STOP;
1728 if ( ++i == argc ) {
1729 /* out of arguments or plain stop */
1730 access_append( &a->acl_access, b );
1734 if ( strcasecmp( argv[i], "continue" ) == 0 ) {
1735 /* plain continue */
1736 b->a_type = ACL_CONTINUE;
1738 } else if ( strcasecmp( argv[i], "break" ) == 0 ) {
1739 /* plain continue */
1740 b->a_type = ACL_BREAK;
1742 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1747 access_append( &a->acl_access, b );
1751 "%s: line %d: expecting \"to\" "
1752 "or \"by\" got \"%s\"\n",
1753 fname, lineno, argv[i] );
1758 /* if we have no real access clause, complain and do nothing */
1760 fprintf( stderr, "%s: line %d: "
1761 "warning: no access clause(s) specified in access line\n",
1766 if ( ldap_debug & LDAP_DEBUG_ACL ) {
1771 if ( a->acl_access == NULL ) {
1772 fprintf( stderr, "%s: line %d: "
1773 "warning: no by clause(s) specified in access line\n",
1778 if ( !BER_BVISNULL( &be->be_nsuffix[ 1 ] ) ) {
1779 fprintf( stderr, "%s: line %d: warning: "
1780 "scope checking only applies to single-valued "
1781 "suffix databases\n",
1783 /* go ahead, since checking is not authoritative */
1786 switch ( check_scope( be, a ) ) {
1787 case ACL_SCOPE_UNKNOWN:
1788 fprintf( stderr, "%s: line %d: warning: "
1789 "cannot assess the validity of the ACL scope within "
1790 "backend naming context\n",
1794 case ACL_SCOPE_WARN:
1795 fprintf( stderr, "%s: line %d: warning: "
1796 "ACL could be out of scope within backend naming context\n",
1800 case ACL_SCOPE_PARTIAL:
1801 fprintf( stderr, "%s: line %d: warning: "
1802 "ACL appears to be partially out of scope within "
1803 "backend naming context\n",
1808 fprintf( stderr, "%s: line %d: warning: "
1809 "ACL appears to be out of scope within "
1810 "backend naming context\n",
1817 acl_append( &be->be_acl, a, pos );
1820 acl_append( &frontendDB->be_acl, a, pos );
1826 accessmask2str( slap_mask_t mask, char *buf, int debug )
1831 assert( buf != NULL );
1833 if ( ACL_IS_INVALID( mask ) ) {
1839 if ( ACL_IS_LEVEL( mask ) ) {
1840 if ( ACL_LVL_IS_NONE(mask) ) {
1841 ptr = lutil_strcopy( ptr, "none" );
1843 } else if ( ACL_LVL_IS_DISCLOSE(mask) ) {
1844 ptr = lutil_strcopy( ptr, "disclose" );
1846 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1847 ptr = lutil_strcopy( ptr, "auth" );
1849 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1850 ptr = lutil_strcopy( ptr, "compare" );
1852 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1853 ptr = lutil_strcopy( ptr, "search" );
1855 } else if ( ACL_LVL_IS_READ(mask) ) {
1856 ptr = lutil_strcopy( ptr, "read" );
1858 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1859 ptr = lutil_strcopy( ptr, "write" );
1861 } else if ( ACL_LVL_IS_WADD(mask) ) {
1862 ptr = lutil_strcopy( ptr, "add" );
1864 } else if ( ACL_LVL_IS_WDEL(mask) ) {
1865 ptr = lutil_strcopy( ptr, "delete" );
1867 } else if ( ACL_LVL_IS_MANAGE(mask) ) {
1868 ptr = lutil_strcopy( ptr, "manage" );
1871 ptr = lutil_strcopy( ptr, "unknown" );
1881 if( ACL_IS_ADDITIVE( mask ) ) {
1884 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1891 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_MANAGE) ) {
1896 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1900 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WADD) ) {
1904 } else if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WDEL) ) {
1909 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1914 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1919 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1924 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1929 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_DISCLOSE) ) {
1934 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1943 if ( ACL_IS_LEVEL( mask ) ) {
1953 str2accessmask( const char *str )
1957 if( !ASCII_ALPHA(str[0]) ) {
1960 if ( str[0] == '=' ) {
1963 } else if( str[0] == '+' ) {
1964 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1966 } else if( str[0] == '-' ) {
1967 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1970 ACL_INVALIDATE(mask);
1974 for( i=1; str[i] != '\0'; i++ ) {
1975 if( TOLOWER((unsigned char) str[i]) == 'm' ) {
1976 ACL_PRIV_SET(mask, ACL_PRIV_MANAGE);
1978 } else if( TOLOWER((unsigned char) str[i]) == 'w' ) {
1979 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1981 } else if( TOLOWER((unsigned char) str[i]) == 'a' ) {
1982 ACL_PRIV_SET(mask, ACL_PRIV_WADD);
1984 } else if( TOLOWER((unsigned char) str[i]) == 'z' ) {
1985 ACL_PRIV_SET(mask, ACL_PRIV_WDEL);
1987 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
1988 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1990 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
1991 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1993 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
1994 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1996 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
1997 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1999 } else if( TOLOWER((unsigned char) str[i]) == 'd' ) {
2000 ACL_PRIV_SET(mask, ACL_PRIV_DISCLOSE);
2002 } else if( str[i] != '0' ) {
2003 ACL_INVALIDATE(mask);
2011 if ( strcasecmp( str, "none" ) == 0 ) {
2012 ACL_LVL_ASSIGN_NONE(mask);
2014 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2015 ACL_LVL_ASSIGN_DISCLOSE(mask);
2017 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2018 ACL_LVL_ASSIGN_AUTH(mask);
2020 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2021 ACL_LVL_ASSIGN_COMPARE(mask);
2023 } else if ( strcasecmp( str, "search" ) == 0 ) {
2024 ACL_LVL_ASSIGN_SEARCH(mask);
2026 } else if ( strcasecmp( str, "read" ) == 0 ) {
2027 ACL_LVL_ASSIGN_READ(mask);
2029 } else if ( strcasecmp( str, "add" ) == 0 ) {
2030 ACL_LVL_ASSIGN_WADD(mask);
2032 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2033 ACL_LVL_ASSIGN_WDEL(mask);
2035 } else if ( strcasecmp( str, "write" ) == 0 ) {
2036 ACL_LVL_ASSIGN_WRITE(mask);
2038 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2039 ACL_LVL_ASSIGN_MANAGE(mask);
2042 ACL_INVALIDATE( mask );
2051 fprintf( stderr, "%s%s%s\n",
2052 "<access clause> ::= access to <what> "
2053 "[ by <who> <access> [ <control> ] ]+ \n"
2054 "<what> ::= * | [dn[.<dnstyle>]=<DN>] [filter=<filter>] [attrs=<attrlist>]\n"
2055 "<attrlist> ::= <attr> [val[.<attrstyle>]=<value>] | <attr> , <attrlist>\n"
2056 "<attr> ::= <attrname> | entry | children\n",
2057 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
2058 "\t[ realanonymous | realusers | realself | realdn[.<dnstyle>]=<DN> ]\n"
2059 "\t[dnattr=<attrname>]\n"
2060 "\t[realdnattr=<attrname>]\n"
2061 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
2062 "\t[peername[.<peernamestyle>]=<peer>] [sockname[.<style>]=<name>]\n"
2063 "\t[domain[.<domainstyle>]=<domain>] [sockurl[.<style>]=<url>]\n"
2064 #ifdef SLAPD_ACI_ENABLED
2065 "\t[aci=[<attrname>]]\n"
2068 "\t[dynacl/<name>[.<dynstyle>][=<pattern>]]\n"
2069 #endif /* SLAP_DYNACL */
2070 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n",
2071 "<style> ::= exact | regex | base(Object)\n"
2072 "<dnstyle> ::= base(Object) | one(level) | sub(tree) | children | "
2074 "<attrstyle> ::= exact | regex | base(Object) | one(level) | "
2075 "sub(tree) | children\n"
2076 "<peernamestyle> ::= exact | regex | ip | path\n"
2077 "<domainstyle> ::= exact | regex | base(Object) | sub(tree)\n"
2078 "<access> ::= [[real]self]{<level>|<priv>}\n"
2079 "<level> ::= none|disclose|auth|compare|search|read|{write|add|delete}|manage\n"
2080 "<priv> ::= {=|+|-}{0|d|x|c|s|r|{w|a|z}|m}+\n"
2081 "<control> ::= [ stop | continue | break ]\n"
2083 exit( EXIT_FAILURE );
2087 * Set pattern to a "normalized" DN from src.
2088 * At present it simply eats the (optional) space after
2089 * a RDN separator (,)
2090 * Eventually will evolve in a more complete normalization
2093 acl_regex_normalized_dn(
2095 struct berval *pattern )
2100 str = ch_strdup( src );
2101 len = strlen( src );
2103 for ( p = str; p && p[0]; p++ ) {
2105 if ( p[0] == '\\' && p[1] ) {
2107 * if escaping a hex pair we should
2108 * increment p twice; however, in that
2109 * case the second hex number does
2115 if ( p[0] == ',' && p[1] == ' ' ) {
2119 * too much space should be an error if we are pedantic
2121 for ( q = &p[2]; q[0] == ' '; q++ ) {
2124 AC_MEMCPY( p+1, q, len-(q-str)+1);
2127 pattern->bv_val = str;
2128 pattern->bv_len = p - str;
2141 if ( (*right = strchr( line, splitchar )) != NULL ) {
2142 *((*right)++) = '\0';
2147 access_append( Access **l, Access *a )
2149 for ( ; *l != NULL; l = &(*l)->a_next ) {
2157 acl_append( AccessControl **l, AccessControl *a, int pos )
2161 for (i=0 ; i != pos && *l != NULL; l = &(*l)->acl_next, i++ ) {
2170 access_free( Access *a )
2172 if ( !BER_BVISNULL( &a->a_dn_pat ) ) {
2173 free( a->a_dn_pat.bv_val );
2175 if ( !BER_BVISNULL( &a->a_realdn_pat ) ) {
2176 free( a->a_realdn_pat.bv_val );
2178 if ( !BER_BVISNULL( &a->a_peername_pat ) ) {
2179 free( a->a_peername_pat.bv_val );
2181 if ( !BER_BVISNULL( &a->a_sockname_pat ) ) {
2182 free( a->a_sockname_pat.bv_val );
2184 if ( !BER_BVISNULL( &a->a_domain_pat ) ) {
2185 free( a->a_domain_pat.bv_val );
2187 if ( !BER_BVISNULL( &a->a_sockurl_pat ) ) {
2188 free( a->a_sockurl_pat.bv_val );
2190 if ( !BER_BVISNULL( &a->a_set_pat ) ) {
2191 free( a->a_set_pat.bv_val );
2193 if ( !BER_BVISNULL( &a->a_group_pat ) ) {
2194 free( a->a_group_pat.bv_val );
2200 acl_free( AccessControl *a )
2205 if ( a->acl_filter ) {
2206 filter_free( a->acl_filter );
2208 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2209 free ( a->acl_dn_pat.bv_val );
2211 if ( a->acl_attrs ) {
2212 for ( an = a->acl_attrs; !BER_BVISNULL( &an->an_name ); an++ ) {
2213 free( an->an_name.bv_val );
2215 free( a->acl_attrs );
2217 for ( ; a->acl_access; a->acl_access = n ) {
2218 n = a->acl_access->a_next;
2219 access_free( a->acl_access );
2224 /* Because backend_startup uses acl_append to tack on the global_acl to
2225 * the end of each backend's acl, we cannot just take one argument and
2226 * merrily free our way to the end of the list. backend_destroy calls us
2227 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
2228 * point. config_destroy calls us with global_acl in arg1 and NULL in
2229 * arg2, so we then proceed to polish off the global_acl.
2232 acl_destroy( AccessControl *a, AccessControl *end )
2236 for (; a && a!= end; a=n) {
2243 access2str( slap_access_t access )
2245 if ( access == ACL_NONE ) {
2248 } else if ( access == ACL_DISCLOSE ) {
2251 } else if ( access == ACL_AUTH ) {
2254 } else if ( access == ACL_COMPARE ) {
2257 } else if ( access == ACL_SEARCH ) {
2260 } else if ( access == ACL_READ ) {
2263 } else if ( access == ACL_WRITE ) {
2266 } else if ( access == ACL_WADD ) {
2269 } else if ( access == ACL_WDEL ) {
2272 } else if ( access == ACL_MANAGE ) {
2281 str2access( const char *str )
2283 if ( strcasecmp( str, "none" ) == 0 ) {
2286 } else if ( strcasecmp( str, "disclose" ) == 0 ) {
2287 #ifndef SLAP_ACL_HONOR_DISCLOSE
2288 fprintf( stderr, "str2access: warning, "
2289 "\"disclose\" privilege disabled.\n" );
2290 #endif /* SLAP_ACL_HONOR_DISCLOSE */
2291 return ACL_DISCLOSE;
2293 } else if ( strcasecmp( str, "auth" ) == 0 ) {
2296 } else if ( strcasecmp( str, "compare" ) == 0 ) {
2299 } else if ( strcasecmp( str, "search" ) == 0 ) {
2302 } else if ( strcasecmp( str, "read" ) == 0 ) {
2305 } else if ( strcasecmp( str, "write" ) == 0 ) {
2308 } else if ( strcasecmp( str, "add" ) == 0 ) {
2311 } else if ( strcasecmp( str, "delete" ) == 0 ) {
2314 } else if ( strcasecmp( str, "manage" ) == 0 ) {
2318 return( ACL_INVALID_ACCESS );
2321 #define ACLBUF_MAXLEN 8192
2323 static char aclbuf[ACLBUF_MAXLEN];
2326 dnaccess2text( slap_dn_access *bdn, char *ptr, int is_realdn )
2331 ptr = lutil_strcopy( ptr, "real" );
2334 if ( ber_bvccmp( &bdn->a_pat, '*' ) ||
2335 bdn->a_style == ACL_STYLE_ANONYMOUS ||
2336 bdn->a_style == ACL_STYLE_USERS ||
2337 bdn->a_style == ACL_STYLE_SELF )
2340 assert( ! ber_bvccmp( &bdn->a_pat, '*' ) );
2343 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2344 if ( bdn->a_style == ACL_STYLE_SELF && bdn->a_self_level != 0 ) {
2345 int n = sprintf( ptr, ".level{%d}", bdn->a_self_level );
2352 ptr = lutil_strcopy( ptr, "dn." );
2353 if ( bdn->a_style == ACL_STYLE_BASE )
2354 ptr = lutil_strcopy( ptr, style_base );
2356 ptr = lutil_strcopy( ptr, style_strings[bdn->a_style] );
2357 if ( bdn->a_style == ACL_STYLE_LEVEL ) {
2358 int n = sprintf( ptr, "{%d}", bdn->a_level );
2363 if ( bdn->a_expand ) {
2364 ptr = lutil_strcopy( ptr, ",expand" );
2368 ptr = lutil_strcopy( ptr, bdn->a_pat.bv_val );
2375 access2text( Access *b, char *ptr )
2377 char maskbuf[ACCESSMASK_MAXLEN];
2379 ptr = lutil_strcopy( ptr, "\tby" );
2381 if ( !BER_BVISEMPTY( &b->a_dn_pat ) ) {
2382 ptr = dnaccess2text( &b->a_dn, ptr, 0 );
2385 ptr = lutil_strcopy( ptr, " dnattr=" );
2386 ptr = lutil_strcopy( ptr, b->a_dn_at->ad_cname.bv_val );
2389 if ( !BER_BVISEMPTY( &b->a_realdn_pat ) ) {
2390 ptr = dnaccess2text( &b->a_realdn, ptr, 1 );
2392 if ( b->a_realdn_at ) {
2393 ptr = lutil_strcopy( ptr, " realdnattr=" );
2394 ptr = lutil_strcopy( ptr, b->a_realdn_at->ad_cname.bv_val );
2397 if ( !BER_BVISEMPTY( &b->a_group_pat ) ) {
2398 ptr = lutil_strcopy( ptr, " group/" );
2399 ptr = lutil_strcopy( ptr, b->a_group_oc ?
2400 b->a_group_oc->soc_cname.bv_val : "groupOfNames" );
2402 ptr = lutil_strcopy( ptr, b->a_group_at ?
2403 b->a_group_at->ad_cname.bv_val : "member" );
2405 ptr = lutil_strcopy( ptr, style_strings[b->a_group_style] );
2408 ptr = lutil_strcopy( ptr, b->a_group_pat.bv_val );
2412 if ( !BER_BVISEMPTY( &b->a_peername_pat ) ) {
2413 ptr = lutil_strcopy( ptr, " peername" );
2415 ptr = lutil_strcopy( ptr, style_strings[b->a_peername_style] );
2418 ptr = lutil_strcopy( ptr, b->a_peername_pat.bv_val );
2422 if ( !BER_BVISEMPTY( &b->a_sockname_pat ) ) {
2423 ptr = lutil_strcopy( ptr, " sockname" );
2425 ptr = lutil_strcopy( ptr, style_strings[b->a_sockname_style] );
2428 ptr = lutil_strcopy( ptr, b->a_sockname_pat.bv_val );
2432 if ( !BER_BVISEMPTY( &b->a_domain_pat ) ) {
2433 ptr = lutil_strcopy( ptr, " domain" );
2435 ptr = lutil_strcopy( ptr, style_strings[b->a_domain_style] );
2436 if ( b->a_domain_expand ) {
2437 ptr = lutil_strcopy( ptr, ",expand" );
2440 ptr = lutil_strcopy( ptr, b->a_domain_pat.bv_val );
2443 if ( !BER_BVISEMPTY( &b->a_sockurl_pat ) ) {
2444 ptr = lutil_strcopy( ptr, " sockurl" );
2446 ptr = lutil_strcopy( ptr, style_strings[b->a_sockurl_style] );
2449 ptr = lutil_strcopy( ptr, b->a_sockurl_pat.bv_val );
2453 if ( !BER_BVISEMPTY( &b->a_set_pat ) ) {
2454 ptr = lutil_strcopy( ptr, " set" );
2456 ptr = lutil_strcopy( ptr, style_strings[b->a_set_style] );
2459 ptr = lutil_strcopy( ptr, b->a_set_pat.bv_val );
2464 if ( b->a_dynacl ) {
2467 for ( da = b->a_dynacl; da; da = da->da_next ) {
2468 if ( da->da_unparse ) {
2470 (void)( *da->da_unparse )( da->da_private, &bv );
2471 ptr = lutil_strcopy( ptr, bv.bv_val );
2472 ch_free( bv.bv_val );
2476 #else /* ! SLAP_DYNACL */
2477 #ifdef SLAPD_ACI_ENABLED
2478 if ( b->a_aci_at != NULL ) {
2479 ptr = lutil_strcopy( ptr, " aci=" );
2480 ptr = lutil_strcopy( ptr, b->a_aci_at->ad_cname.bv_val );
2483 #endif /* SLAP_DYNACL */
2485 /* Security Strength Factors */
2486 if ( b->a_authz.sai_ssf ) {
2487 ptr += sprintf( ptr, " ssf=%u",
2488 b->a_authz.sai_ssf );
2490 if ( b->a_authz.sai_transport_ssf ) {
2491 ptr += sprintf( ptr, " transport_ssf=%u",
2492 b->a_authz.sai_transport_ssf );
2494 if ( b->a_authz.sai_tls_ssf ) {
2495 ptr += sprintf( ptr, " tls_ssf=%u",
2496 b->a_authz.sai_tls_ssf );
2498 if ( b->a_authz.sai_sasl_ssf ) {
2499 ptr += sprintf( ptr, " sasl_ssf=%u",
2500 b->a_authz.sai_sasl_ssf );
2504 if ( b->a_dn_self ) {
2505 ptr = lutil_strcopy( ptr, "self" );
2506 } else if ( b->a_realdn_self ) {
2507 ptr = lutil_strcopy( ptr, "realself" );
2509 ptr = lutil_strcopy( ptr, accessmask2str( b->a_access_mask, maskbuf, 0 ));
2510 if ( !maskbuf[0] ) ptr--;
2512 if( b->a_type == ACL_BREAK ) {
2513 ptr = lutil_strcopy( ptr, " break" );
2515 } else if( b->a_type == ACL_CONTINUE ) {
2516 ptr = lutil_strcopy( ptr, " continue" );
2518 } else if( b->a_type != ACL_STOP ) {
2519 ptr = lutil_strcopy( ptr, " unknown-control" );
2521 if ( !maskbuf[0] ) ptr = lutil_strcopy( ptr, " stop" );
2529 acl_unparse( AccessControl *a, struct berval *bv )
2535 bv->bv_val = aclbuf;
2540 ptr = lutil_strcopy( ptr, "to" );
2541 if ( !BER_BVISNULL( &a->acl_dn_pat ) ) {
2543 ptr = lutil_strcopy( ptr, " dn." );
2544 if ( a->acl_dn_style == ACL_STYLE_BASE )
2545 ptr = lutil_strcopy( ptr, style_base );
2547 ptr = lutil_strcopy( ptr, style_strings[a->acl_dn_style] );
2550 ptr = lutil_strcopy( ptr, a->acl_dn_pat.bv_val );
2551 ptr = lutil_strcopy( ptr, "\"\n" );
2554 if ( a->acl_filter != NULL ) {
2555 struct berval bv = BER_BVNULL;
2558 filter2bv( a->acl_filter, &bv );
2559 ptr = lutil_strcopy( ptr, " filter=\"" );
2560 ptr = lutil_strcopy( ptr, bv.bv_val );
2563 ch_free( bv.bv_val );
2566 if ( a->acl_attrs != NULL ) {
2571 ptr = lutil_strcopy( ptr, " attrs=" );
2572 for ( an = a->acl_attrs; an && !BER_BVISNULL( &an->an_name ); an++ ) {
2573 if ( ! first ) *ptr++ = ',';
2575 *ptr++ = an->an_oc_exclude ? '!' : '@';
2576 ptr = lutil_strcopy( ptr, an->an_oc->soc_cname.bv_val );
2579 ptr = lutil_strcopy( ptr, an->an_name.bv_val );
2586 if ( !BER_BVISEMPTY( &a->acl_attrval ) ) {
2588 ptr = lutil_strcopy( ptr, " val." );
2589 if ( a->acl_attrval_style == ACL_STYLE_BASE &&
2590 a->acl_attrs[0].an_desc->ad_type->sat_syntax ==
2591 slap_schema.si_syn_distinguishedName )
2592 ptr = lutil_strcopy( ptr, style_base );
2594 ptr = lutil_strcopy( ptr, style_strings[a->acl_attrval_style] );
2597 ptr = lutil_strcopy( ptr, a->acl_attrval.bv_val );
2603 ptr = lutil_strcopy( ptr, " *\n" );
2606 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
2607 ptr = access2text( b, ptr );
2610 bv->bv_len = ptr - bv->bv_val;
2616 print_acl( Backend *be, AccessControl *a )
2620 acl_unparse( a, &bv );
2621 fprintf( stderr, "%s ACL: access %s\n",
2622 be == NULL ? "Global" : "Backend", bv.bv_val );
2624 #endif /* LDAP_DEBUG */