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-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that this notice is preserved and that due credit is given
21 * to the University of Michigan at Ann Arbor. The name of the University
22 * may not be used to endorse or promote products derived from this
23 * software without specific prior written permission. This software
24 * is provided ``as is'' without express or implied warranty.
33 #include <ac/socket.h>
34 #include <ac/string.h>
35 #include <ac/unistd.h>
41 static char *style_strings[] = {
54 static void split(char *line, int splitchar, char **left, char **right);
55 static void access_append(Access **l, Access *a);
56 static void acl_usage(void) LDAP_GCCATTR((noreturn));
58 static void acl_regex_normalized_dn(const char *src, struct berval *pat);
61 static void print_acl(Backend *be, AccessControl *a);
62 static void print_access(Access *b);
67 check_scope( BackendDB *be, AccessControl *a );
68 #endif /* LDAP_DEVEL */
71 regtest(const char *fname, int lineno, char *pat) {
87 for (size = 0, flag = 0; (size < sizeof(buf)) && *sp; sp++) {
89 if (*sp == '$'|| (*sp >= '0' && *sp <= '9')) {
106 if ( size >= (sizeof(buf) - 1) ) {
108 "%s: line %d: regular expression \"%s\" too large\n",
109 fname, lineno, pat );
113 if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
115 regerror(e, &re, error, sizeof(error));
117 "%s: line %d: regular expression \"%s\" bad because of %s\n",
118 fname, lineno, pat, error );
128 * Check if the pattern of an ACL, if any, matches the scope
129 * of the backend it is defined within.
131 #define ACL_SCOPE_UNKNOWN (-2)
132 #define ACL_SCOPE_ERR (-1)
133 #define ACL_SCOPE_OK (0)
134 #define ACL_SCOPE_PARTIAL (1)
135 #define ACL_SCOPE_WARN (2)
138 check_scope( BackendDB *be, AccessControl *a )
143 dn = be->be_nsuffix[0];
145 if ( a->acl_dn_pat.bv_len || a->acl_dn_style != ACL_STYLE_REGEX ) {
146 slap_style_t style = a->acl_dn_style;
148 if ( style == ACL_STYLE_REGEX ) {
149 char dnbuf[SLAP_LDAPDN_MAXLEN + 2];
150 char rebuf[SLAP_LDAPDN_MAXLEN + 1];
154 /* add trailing '$' */
155 AC_MEMCPY( dnbuf, be->be_nsuffix[0].bv_val,
156 be->be_nsuffix[0].bv_len );
157 dnbuf[be->be_nsuffix[0].bv_len] = '$';
158 dnbuf[be->be_nsuffix[0].bv_len + 1] = '\0';
160 if ( regcomp( &re, dnbuf, REG_EXTENDED|REG_ICASE ) ) {
161 return ACL_SCOPE_WARN;
164 /* remove trailing '$' */
165 AC_MEMCPY( rebuf, a->acl_dn_pat.bv_val,
166 a->acl_dn_pat.bv_len + 1 );
167 if ( a->acl_dn_pat.bv_val[a->acl_dn_pat.bv_len - 1] == '$' ) {
168 rebuf[a->acl_dn_pat.bv_len - 1] = '\0';
171 /* not a clear indication of scoping error, though */
172 rc = regexec( &re, rebuf, 0, NULL, 0 )
173 ? ACL_SCOPE_WARN : ACL_SCOPE_OK;
179 patlen = a->acl_dn_pat.bv_len;
180 /* If backend suffix is longer than pattern,
181 * it is a potential mismatch (in the sense
182 * that a superior naming context could
184 if ( dn.bv_len > patlen ) {
185 /* base is blatantly wrong */
186 if ( style == ACL_STYLE_BASE ) return ACL_SCOPE_ERR;
188 /* one can be wrong if there is more
189 * than one level between the suffix
191 if ( style == ACL_STYLE_ONE ) {
192 int rdnlen = -1, sep = 0;
195 if ( !DN_SEPARATOR( dn.bv_val[dn.bv_len - patlen - 1] )) {
196 return ACL_SCOPE_ERR;
201 rdnlen = dn_rdnlen( NULL, &dn );
202 if ( rdnlen != dn.bv_len - patlen - sep )
203 return ACL_SCOPE_ERR;
206 /* if the trailing part doesn't match,
207 * then it's an error */
208 if ( strcmp( a->acl_dn_pat.bv_val,
209 &dn.bv_val[dn.bv_len - patlen] ) != 0 )
211 return ACL_SCOPE_ERR;
214 return ACL_SCOPE_PARTIAL;
220 case ACL_STYLE_CHILDREN:
221 case ACL_STYLE_SUBTREE:
229 if ( dn.bv_len < patlen &&
230 !DN_SEPARATOR( a->acl_dn_pat.bv_val[patlen -dn.bv_len - 1] )) {
231 return ACL_SCOPE_ERR;
234 if ( strcmp( &a->acl_dn_pat.bv_val[patlen - dn.bv_len], dn.bv_val )
237 return ACL_SCOPE_ERR;
243 return ACL_SCOPE_UNKNOWN;
245 #endif /* LDAP_DEVEL */
257 char *left, *right, *style, *next;
265 for ( i = 1; i < argc; i++ ) {
266 /* to clause - select which entries are protected */
267 if ( strcasecmp( argv[i], "to" ) == 0 ) {
269 fprintf( stderr, "%s: line %d: "
270 "only one to clause allowed in access line\n",
274 a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
275 for ( ++i; i < argc; i++ ) {
276 if ( strcasecmp( argv[i], "by" ) == 0 ) {
281 if ( strcasecmp( argv[i], "*" ) == 0 ) {
282 if( a->acl_dn_pat.bv_len ||
283 ( a->acl_dn_style != ACL_STYLE_REGEX ) )
286 "%s: line %d: dn pattern"
287 " already specified in to clause.\n",
292 a->acl_dn_pat.bv_val = ch_strdup( "*" );
293 a->acl_dn_pat.bv_len = 1;
297 split( argv[i], '=', &left, &right );
298 split( left, '.', &left, &style );
300 if ( right == NULL ) {
301 fprintf( stderr, "%s: line %d: "
302 "missing \"=\" in \"%s\" in to clause\n",
303 fname, lineno, left );
307 if ( strcasecmp( left, "dn" ) == 0 ) {
308 if( a->acl_dn_pat.bv_len != 0 ||
309 ( a->acl_dn_style != ACL_STYLE_REGEX ) )
312 "%s: line %d: dn pattern"
313 " already specified in to clause.\n",
318 if ( style == NULL || *style == '\0' ||
319 strcasecmp( style, "baseObject" ) == 0 ||
320 strcasecmp( style, "base" ) == 0 ||
321 strcasecmp( style, "exact" ) == 0 )
323 a->acl_dn_style = ACL_STYLE_BASE;
324 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
326 } else if ( strcasecmp( style, "oneLevel" ) == 0 ||
327 strcasecmp( style, "one" ) == 0 )
329 a->acl_dn_style = ACL_STYLE_ONE;
330 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
332 } else if ( strcasecmp( style, "subtree" ) == 0 ||
333 strcasecmp( style, "sub" ) == 0 )
335 if( *right == '\0' ) {
336 a->acl_dn_pat.bv_val = ch_strdup( "*" );
337 a->acl_dn_pat.bv_len = 1;
340 a->acl_dn_style = ACL_STYLE_SUBTREE;
341 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
344 } else if ( strcasecmp( style, "children" ) == 0 ) {
345 a->acl_dn_style = ACL_STYLE_CHILDREN;
346 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
348 } else if ( strcasecmp( style, "regex" ) == 0 ) {
349 a->acl_dn_style = ACL_STYLE_REGEX;
351 if ( *right == '\0' ) {
352 /* empty regex should match empty DN */
353 a->acl_dn_style = ACL_STYLE_BASE;
354 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
356 } else if ( strcmp(right, "*") == 0
357 || strcmp(right, ".*") == 0
358 || strcmp(right, ".*$") == 0
359 || strcmp(right, "^.*") == 0
360 || strcmp(right, "^.*$") == 0
361 || strcmp(right, ".*$$") == 0
362 || strcmp(right, "^.*$$") == 0 )
364 a->acl_dn_pat.bv_val = ch_strdup( "*" );
365 a->acl_dn_pat.bv_len = STRLENOF("*");
368 acl_regex_normalized_dn( right, &a->acl_dn_pat );
372 fprintf( stderr, "%s: line %d: "
373 "unknown dn style \"%s\" in to clause\n",
374 fname, lineno, style );
381 if ( strcasecmp( left, "filter" ) == 0 ) {
382 if ( (a->acl_filter = str2filter( right )) == NULL ) {
384 "%s: line %d: bad filter \"%s\" in to clause\n",
385 fname, lineno, right );
389 } else if ( strcasecmp( left, "attr" ) == 0
390 || strcasecmp( left, "attrs" ) == 0 ) {
391 a->acl_attrs = str2anlist( a->acl_attrs,
393 if ( a->acl_attrs == NULL ) {
395 "%s: line %d: unknown attr \"%s\" in to clause\n",
396 fname, lineno, right );
400 } else if ( strncasecmp( left, "val", 3 ) == 0 ) {
401 if ( a->acl_attrval.bv_len ) {
403 "%s: line %d: attr val already specified in to clause.\n",
407 if ( a->acl_attrs == NULL || a->acl_attrs[1].an_name.bv_val ) {
409 "%s: line %d: attr val requires a single attribute.\n",
413 ber_str2bv( right, 0, 1, &a->acl_attrval );
414 if ( style && strcasecmp( style, "regex" ) == 0 ) {
415 int e = regcomp( &a->acl_attrval_re, a->acl_attrval.bv_val,
416 REG_EXTENDED | REG_ICASE | REG_NOSUB );
419 regerror( e, &a->acl_attrval_re, buf, sizeof(buf) );
420 fprintf( stderr, "%s: line %d: "
421 "regular expression \"%s\" bad because of %s\n",
422 fname, lineno, right, buf );
425 a->acl_attrval_style = ACL_STYLE_REGEX;
427 /* FIXME: if the attribute has DN syntax, we might
428 * allow one, subtree and children styles as well */
429 if ( !strcasecmp( style, "exact" ) ) {
430 a->acl_attrval_style = ACL_STYLE_BASE;
432 } else if ( a->acl_attrs[0].an_desc->ad_type->
433 sat_syntax == slap_schema.si_syn_distinguishedName )
435 if ( !strcasecmp( style, "baseObject" ) ||
436 !strcasecmp( style, "base" ) )
438 a->acl_attrval_style = ACL_STYLE_BASE;
439 } else if ( !strcasecmp( style, "onelevel" ) ||
440 !strcasecmp( style, "one" ) )
442 a->acl_attrval_style = ACL_STYLE_ONE;
443 } else if ( !strcasecmp( style, "subtree" ) ||
444 !strcasecmp( style, "sub" ) )
446 a->acl_attrval_style = ACL_STYLE_SUBTREE;
447 } else if ( !strcasecmp( style, "children" ) ) {
448 a->acl_attrval_style = ACL_STYLE_CHILDREN;
451 "%s: line %d: unknown val.<style> \"%s\" "
452 "for attributeType \"%s\" with DN syntax; "
454 fname, lineno, style,
455 a->acl_attrs[0].an_desc->ad_cname.bv_val );
456 a->acl_attrval_style = ACL_STYLE_BASE;
461 "%s: line %d: unknown val.<style> \"%s\" "
462 "for attributeType \"%s\"; using \"exact\"\n",
463 fname, lineno, style,
464 a->acl_attrs[0].an_desc->ad_cname.bv_val );
465 a->acl_attrval_style = ACL_STYLE_BASE;
471 "%s: line %d: expecting <what> got \"%s\"\n",
472 fname, lineno, left );
477 if ( !BER_BVISNULL( &a->acl_dn_pat ) &&
478 ber_bvccmp( &a->acl_dn_pat, '*' ) )
480 free( a->acl_dn_pat.bv_val );
481 BER_BVZERO( &a->acl_dn_pat );
484 if( a->acl_dn_pat.bv_len != 0 ||
485 ( a->acl_dn_style != ACL_STYLE_REGEX ) )
487 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
489 rc = dnNormalize( 0, NULL, NULL, &a->acl_dn_pat, &bv, NULL);
490 if ( rc != LDAP_SUCCESS ) {
492 "%s: line %d: bad DN \"%s\" in to DN clause\n",
493 fname, lineno, a->acl_dn_pat.bv_val );
496 free( a->acl_dn_pat.bv_val );
499 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
500 REG_EXTENDED | REG_ICASE );
503 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
504 fprintf( stderr, "%s: line %d: "
505 "regular expression \"%s\" bad because of %s\n",
506 fname, lineno, right, buf );
512 /* by clause - select who has what access to entries */
513 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
515 fprintf( stderr, "%s: line %d: "
516 "to clause required before by clause in access line\n",
522 * by clause consists of <who> and <access>
525 b = (Access *) ch_calloc( 1, sizeof(Access) );
527 ACL_INVALIDATE( b->a_access_mask );
531 "%s: line %d: premature eol: expecting <who>\n",
537 for ( ; i < argc; i++ ) {
538 slap_style_t sty = ACL_STYLE_REGEX;
539 char *style_modifier = NULL;
542 split( argv[i], '=', &left, &right );
543 split( left, '.', &left, &style );
545 split( style, ',', &style, &style_modifier);
548 if ( style == NULL || *style == '\0' ||
549 strcasecmp( style, "exact" ) == 0 ||
550 strcasecmp( style, "baseObject" ) == 0 ||
551 strcasecmp( style, "base" ) == 0 )
553 sty = ACL_STYLE_BASE;
555 } else if ( strcasecmp( style, "onelevel" ) == 0 ||
556 strcasecmp( style, "one" ) == 0 )
560 } else if ( strcasecmp( style, "subtree" ) == 0 ||
561 strcasecmp( style, "sub" ) == 0 )
563 sty = ACL_STYLE_SUBTREE;
565 } else if ( strcasecmp( style, "children" ) == 0 ) {
566 sty = ACL_STYLE_CHILDREN;
568 } else if ( strcasecmp( style, "regex" ) == 0 ) {
569 sty = ACL_STYLE_REGEX;
571 } else if ( strcasecmp( style, "expand" ) == 0 ) {
572 sty = ACL_STYLE_EXPAND;
574 } else if ( strcasecmp( style, "ip" ) == 0 ) {
577 } else if ( strcasecmp( style, "path" ) == 0 ) {
578 sty = ACL_STYLE_PATH;
579 #ifndef LDAP_PF_LOCAL
580 fprintf( stderr, "%s: line %d: "
581 "path style modifier is useless without local\n",
583 #endif /* LDAP_PF_LOCAL */
587 "%s: line %d: unknown style \"%s\" in by clause\n",
588 fname, lineno, style );
592 if ( style_modifier &&
593 strcasecmp( style_modifier, "expand" ) == 0 )
596 case ACL_STYLE_REGEX:
597 fprintf( stderr, "%s: line %d: "
598 "\"regex\" style implies "
599 "\"expand\" modifier (ignored)\n",
603 case ACL_STYLE_EXPAND:
604 fprintf( stderr, "%s: line %d: "
605 "\"expand\" style used "
606 "in conjunction with "
607 "\"expand\" modifier (ignored)\n",
612 /* we'll see later if it's pertinent */
618 /* expand in <who> needs regex in <what> */
619 if ( ( sty == ACL_STYLE_EXPAND || expand )
620 && a->acl_dn_style != ACL_STYLE_REGEX )
622 fprintf( stderr, "%s: line %d: "
623 "\"expand\" style or modifier used "
624 "in conjunction with "
625 "a non-regex <what> clause\n",
630 if ( strcasecmp( argv[i], "*" ) == 0 ) {
631 bv.bv_val = ch_strdup( "*" );
633 sty = ACL_STYLE_REGEX;
635 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
636 ber_str2bv("anonymous", STRLENOF( "anonymous" ), 1, &bv);
637 sty = ACL_STYLE_REGEX;
639 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
640 ber_str2bv("self", STRLENOF( "self" ), 1, &bv);
641 sty = ACL_STYLE_REGEX;
643 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
644 ber_str2bv("users", STRLENOF( "users" ), 1, &bv);
645 sty = ACL_STYLE_REGEX;
647 } else if ( strcasecmp( left, "dn" ) == 0 ) {
648 if ( sty == ACL_STYLE_REGEX ) {
649 b->a_dn_style = ACL_STYLE_REGEX;
650 if( right == NULL ) {
655 } else if (*right == '\0' ) {
657 ber_str2bv("anonymous",
658 STRLENOF( "anonymous" ),
660 } else if ( strcmp( right, "*" ) == 0 ) {
662 /* any or users? users for now */
666 } else if ( strcmp( right, ".+" ) == 0
667 || strcmp( right, "^.+" ) == 0
668 || strcmp( right, ".+$" ) == 0
669 || strcmp( right, "^.+$" ) == 0
670 || strcmp( right, ".+$$" ) == 0
671 || strcmp( right, "^.+$$" ) == 0 )
676 } else if ( strcmp( right, ".*" ) == 0
677 || strcmp( right, "^.*" ) == 0
678 || strcmp( right, ".*$" ) == 0
679 || strcmp( right, "^.*$" ) == 0
680 || strcmp( right, ".*$$" ) == 0
681 || strcmp( right, "^.*$$" ) == 0 )
688 acl_regex_normalized_dn( right, &bv );
689 if ( !ber_bvccmp( &bv, '*' ) ) {
690 regtest(fname, lineno, bv.bv_val);
693 } else if ( right == NULL || *right == '\0' ) {
694 fprintf( stderr, "%s: line %d: "
695 "missing \"=\" in (or value after) \"%s\" "
697 fname, lineno, left );
701 ber_str2bv( right, 0, 1, &bv );
708 if( bv.bv_val != NULL ) {
709 if( b->a_dn_pat.bv_len != 0 ) {
711 "%s: line %d: dn pattern already specified.\n",
716 if ( sty != ACL_STYLE_REGEX && expand == 0 ) {
717 rc = dnNormalize(0, NULL, NULL,
718 &bv, &b->a_dn_pat, NULL);
719 if ( rc != LDAP_SUCCESS ) {
721 "%s: line %d: bad DN \"%s\" in by DN clause\n",
722 fname, lineno, bv.bv_val );
730 b->a_dn_expand = expand;
734 if ( strcasecmp( left, "dnattr" ) == 0 ) {
735 if ( right == NULL || right[0] == '\0' ) {
736 fprintf( stderr, "%s: line %d: "
737 "missing \"=\" in (or value after) \"%s\" "
739 fname, lineno, left );
743 if( b->a_dn_at != NULL ) {
745 "%s: line %d: dnattr already specified.\n",
750 rc = slap_str2ad( right, &b->a_dn_at, &text );
752 if( rc != LDAP_SUCCESS ) {
754 "%s: line %d: dnattr \"%s\": %s\n",
755 fname, lineno, right, text );
760 if( !is_at_syntax( b->a_dn_at->ad_type,
762 !is_at_syntax( b->a_dn_at->ad_type,
763 SLAPD_NAMEUID_SYNTAX ))
766 "%s: line %d: dnattr \"%s\": "
767 "inappropriate syntax: %s\n",
768 fname, lineno, right,
769 b->a_dn_at->ad_type->sat_syntax_oid );
773 if( b->a_dn_at->ad_type->sat_equality == NULL ) {
775 "%s: line %d: dnattr \"%s\": "
776 "inappropriate matching (no EQUALITY)\n",
777 fname, lineno, right );
784 if ( strncasecmp( left, "group", STRLENOF( "group" ) ) == 0 ) {
789 case ACL_STYLE_REGEX:
790 /* legacy, tolerated */
791 fprintf( stderr, "%s: line %d: "
792 "deprecated group style \"regex\"; "
793 "use \"expand\" instead\n",
794 fname, lineno, style );
795 sty = ACL_STYLE_EXPAND;
799 /* legal, traditional */
800 case ACL_STYLE_EXPAND:
801 /* legal, substring expansion; supersedes regex */
806 fprintf( stderr, "%s: line %d: "
807 "inappropriate style \"%s\" in by clause\n",
808 fname, lineno, style );
812 if ( right == NULL || right[0] == '\0' ) {
813 fprintf( stderr, "%s: line %d: "
814 "missing \"=\" in (or value after) \"%s\" "
816 fname, lineno, left );
820 if( b->a_group_pat.bv_len ) {
822 "%s: line %d: group pattern already specified.\n",
827 /* format of string is
828 "group/objectClassValue/groupAttrName" */
829 if ((value = strchr(left, '/')) != NULL) {
831 if (*value && (name = strchr(value, '/')) != NULL) {
836 b->a_group_style = sty;
837 if (sty == ACL_STYLE_EXPAND) {
838 acl_regex_normalized_dn( right, &bv );
839 if ( !ber_bvccmp( &bv, '*' ) ) {
840 regtest(fname, lineno, bv.bv_val);
844 ber_str2bv( right, 0, 0, &bv );
845 rc = dnNormalize( 0, NULL, NULL, &bv,
846 &b->a_group_pat, NULL );
847 if ( rc != LDAP_SUCCESS ) {
849 "%s: line %d: bad DN \"%s\"\n",
850 fname, lineno, right );
855 if (value && *value) {
856 b->a_group_oc = oc_find( value );
859 if( b->a_group_oc == NULL ) {
861 "%s: line %d: group objectclass "
863 fname, lineno, value );
867 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
869 if( b->a_group_oc == NULL ) {
871 "%s: line %d: group default objectclass "
873 fname, lineno, SLAPD_GROUP_CLASS );
878 if( is_object_subclass( slap_schema.si_oc_referral,
882 "%s: line %d: group objectclass \"%s\" "
883 "is subclass of referral\n",
884 fname, lineno, value );
888 if( is_object_subclass( slap_schema.si_oc_alias,
892 "%s: line %d: group objectclass \"%s\" "
893 "is subclass of alias\n",
894 fname, lineno, value );
899 rc = slap_str2ad( name, &b->a_group_at, &text );
901 if( rc != LDAP_SUCCESS ) {
903 "%s: line %d: group \"%s\": %s\n",
904 fname, lineno, right, text );
909 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
911 if( rc != LDAP_SUCCESS ) {
913 "%s: line %d: group \"%s\": %s\n",
914 fname, lineno, SLAPD_GROUP_ATTR, text );
919 if( !is_at_syntax( b->a_group_at->ad_type,
921 !is_at_syntax( b->a_group_at->ad_type,
922 SLAPD_NAMEUID_SYNTAX ) &&
923 !is_at_subtype( b->a_group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ))
926 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
927 fname, lineno, right,
928 b->a_group_at->ad_type->sat_syntax_oid );
935 struct berval vals[2];
937 vals[0].bv_val = b->a_group_oc->soc_oid;
938 vals[0].bv_len = strlen(vals[0].bv_val);
939 vals[1].bv_val = NULL;
942 rc = oc_check_allowed( b->a_group_at->ad_type,
946 fprintf( stderr, "%s: line %d: "
947 "group: \"%s\" not allowed by \"%s\"\n",
949 b->a_group_at->ad_cname.bv_val,
950 b->a_group_oc->soc_oid );
957 if ( strcasecmp( left, "peername" ) == 0 ) {
959 case ACL_STYLE_REGEX:
961 /* legal, traditional */
962 case ACL_STYLE_EXPAND:
963 /* cheap replacement to regex for simple expansion */
966 /* legal, peername specific */
970 fprintf( stderr, "%s: line %d: "
971 "inappropriate style \"%s\" in by clause\n",
972 fname, lineno, style );
976 if ( right == NULL || right[0] == '\0' ) {
977 fprintf( stderr, "%s: line %d: "
978 "missing \"=\" in (or value after) \"%s\" "
980 fname, lineno, left );
984 if( b->a_peername_pat.bv_len ) {
985 fprintf( stderr, "%s: line %d: "
986 "peername pattern already specified.\n",
991 b->a_peername_style = sty;
992 if (sty == ACL_STYLE_REGEX) {
993 acl_regex_normalized_dn( right, &bv );
994 if ( !ber_bvccmp( &bv, '*' ) ) {
995 regtest(fname, lineno, bv.bv_val);
997 b->a_peername_pat = bv;
1000 ber_str2bv( right, 0, 1, &b->a_peername_pat );
1002 if ( sty == ACL_STYLE_IP ) {
1007 split( right, '{', &addr, &port );
1008 split( addr, '%', &addr, &mask );
1010 b->a_peername_addr = inet_addr( addr );
1011 if ( b->a_peername_addr == (unsigned long)(-1)) {
1012 /* illegal address */
1013 fprintf( stderr, "%s: line %d: "
1014 "illegal peername address \"%s\".\n",
1015 fname, lineno, addr );
1019 b->a_peername_mask = (unsigned long)(-1);
1020 if ( mask != NULL ) {
1021 b->a_peername_mask = inet_addr( mask );
1022 if ( b->a_peername_mask ==
1023 (unsigned long)(-1))
1026 fprintf( stderr, "%s: line %d: "
1027 "illegal peername address mask "
1029 fname, lineno, mask );
1034 b->a_peername_port = -1;
1038 b->a_peername_port = strtol( port, &end, 10 );
1039 if ( end[0] != '}' ) {
1041 fprintf( stderr, "%s: line %d: "
1042 "illegal peername port specification "
1044 fname, lineno, port );
1053 if ( strcasecmp( left, "sockname" ) == 0 ) {
1055 case ACL_STYLE_REGEX:
1056 case ACL_STYLE_BASE:
1057 /* legal, traditional */
1058 case ACL_STYLE_EXPAND:
1059 /* cheap replacement to regex for simple expansion */
1064 fprintf( stderr, "%s: line %d: "
1065 "inappropriate style \"%s\" in by clause\n",
1066 fname, lineno, style );
1070 if ( right == NULL || right[0] == '\0' ) {
1071 fprintf( stderr, "%s: line %d: "
1072 "missing \"=\" in (or value after) \"%s\" "
1074 fname, lineno, left );
1078 if( b->a_sockname_pat.bv_len ) {
1079 fprintf( stderr, "%s: line %d: "
1080 "sockname pattern already specified.\n",
1085 b->a_sockname_style = sty;
1086 if (sty == ACL_STYLE_REGEX) {
1087 acl_regex_normalized_dn( right, &bv );
1088 if ( !ber_bvccmp( &bv, '*' ) ) {
1089 regtest(fname, lineno, bv.bv_val);
1091 b->a_sockname_pat = bv;
1093 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
1098 if ( strcasecmp( left, "domain" ) == 0 ) {
1100 case ACL_STYLE_REGEX:
1101 case ACL_STYLE_BASE:
1102 case ACL_STYLE_SUBTREE:
1103 /* legal, traditional */
1106 case ACL_STYLE_EXPAND:
1107 /* tolerated: means exact,expand */
1111 "\"expand\" modifier with \"expand\" style\n",
1114 sty = ACL_STYLE_BASE;
1120 fprintf( stderr, "%s: line %d: "
1121 "inappropriate style \"%s\" in by clause\n",
1122 fname, lineno, style );
1126 if ( right == NULL || right[0] == '\0' ) {
1127 fprintf( stderr, "%s: line %d: "
1128 "missing \"=\" in (or value after) \"%s\" "
1130 fname, lineno, left );
1134 if( b->a_domain_pat.bv_len ) {
1136 "%s: line %d: domain pattern already specified.\n",
1141 b->a_domain_style = sty;
1142 b->a_domain_expand = expand;
1143 if (sty == ACL_STYLE_REGEX) {
1144 acl_regex_normalized_dn( right, &bv );
1145 if ( !ber_bvccmp( &bv, '*' ) ) {
1146 regtest(fname, lineno, bv.bv_val);
1148 b->a_domain_pat = bv;
1150 ber_str2bv( right, 0, 1, &b->a_domain_pat );
1155 if ( strcasecmp( left, "sockurl" ) == 0 ) {
1157 case ACL_STYLE_REGEX:
1158 case ACL_STYLE_BASE:
1159 /* legal, traditional */
1160 case ACL_STYLE_EXPAND:
1161 /* cheap replacement to regex for simple expansion */
1166 fprintf( stderr, "%s: line %d: "
1167 "inappropriate style \"%s\" in by clause\n",
1168 fname, lineno, style );
1172 if ( right == NULL || right[0] == '\0' ) {
1173 fprintf( stderr, "%s: line %d: "
1174 "missing \"=\" in (or value after) \"%s\" "
1176 fname, lineno, left );
1180 if( b->a_sockurl_pat.bv_len ) {
1182 "%s: line %d: sockurl pattern already specified.\n",
1187 b->a_sockurl_style = sty;
1188 if (sty == ACL_STYLE_REGEX) {
1189 acl_regex_normalized_dn( right, &bv );
1190 if ( !ber_bvccmp( &bv, '*' ) ) {
1191 regtest(fname, lineno, bv.bv_val);
1193 b->a_sockurl_pat = bv;
1195 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
1200 if ( strcasecmp( left, "set" ) == 0 ) {
1201 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1202 fprintf( stderr, "%s: line %d: "
1203 "inappropriate style \"%s\" in by clause\n",
1204 fname, lineno, style );
1208 if( b->a_set_pat.bv_len != 0 ) {
1210 "%s: line %d: set attribute already specified.\n",
1215 if ( right == NULL || *right == '\0' ) {
1217 "%s: line %d: no set is defined\n",
1222 b->a_set_style = sty;
1223 ber_str2bv( right, 0, 1, &b->a_set_pat );
1228 #ifdef SLAPD_ACI_ENABLED
1229 if ( strcasecmp( left, "aci" ) == 0 ) {
1230 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1231 fprintf( stderr, "%s: line %d: "
1232 "inappropriate style \"%s\" in by clause\n",
1233 fname, lineno, style );
1237 if( b->a_aci_at != NULL ) {
1239 "%s: line %d: aci attribute already specified.\n",
1244 if ( right != NULL && *right != '\0' ) {
1245 rc = slap_str2ad( right, &b->a_aci_at, &text );
1247 if( rc != LDAP_SUCCESS ) {
1249 "%s: line %d: aci \"%s\": %s\n",
1250 fname, lineno, right, text );
1255 b->a_aci_at = slap_schema.si_ad_aci;
1258 if( !is_at_syntax( b->a_aci_at->ad_type,
1261 fprintf( stderr, "%s: line %d: "
1262 "aci \"%s\": inappropriate syntax: %s\n",
1263 fname, lineno, right,
1264 b->a_aci_at->ad_type->sat_syntax_oid );
1270 #endif /* SLAPD_ACI_ENABLED */
1272 if ( strcasecmp( left, "ssf" ) == 0 ) {
1273 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1274 fprintf( stderr, "%s: line %d: "
1275 "inappropriate style \"%s\" in by clause\n",
1276 fname, lineno, style );
1280 if( b->a_authz.sai_ssf ) {
1282 "%s: line %d: ssf attribute already specified.\n",
1287 if ( right == NULL || *right == '\0' ) {
1289 "%s: line %d: no ssf is defined\n",
1294 b->a_authz.sai_ssf = strtol( right, &next, 10 );
1295 if ( next == NULL || next[0] != '\0' ) {
1297 "%s: line %d: unable to parse ssf value (%s)\n",
1298 fname, lineno, right );
1302 if( !b->a_authz.sai_ssf ) {
1304 "%s: line %d: invalid ssf value (%s)\n",
1305 fname, lineno, right );
1311 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
1312 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1313 fprintf( stderr, "%s: line %d: "
1314 "inappropriate style \"%s\" in by clause\n",
1315 fname, lineno, style );
1319 if( b->a_authz.sai_transport_ssf ) {
1320 fprintf( stderr, "%s: line %d: "
1321 "transport_ssf attribute already specified.\n",
1326 if ( right == NULL || *right == '\0' ) {
1328 "%s: line %d: no transport_ssf is defined\n",
1333 b->a_authz.sai_transport_ssf = strtol( right, &next, 10 );
1334 if ( next == NULL || next[0] != '\0' ) {
1335 fprintf( stderr, "%s: line %d: "
1336 "unable to parse transport_ssf value (%s)\n",
1337 fname, lineno, right );
1341 if( !b->a_authz.sai_transport_ssf ) {
1343 "%s: line %d: invalid transport_ssf value (%s)\n",
1344 fname, lineno, right );
1350 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
1351 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1352 fprintf( stderr, "%s: line %d: "
1353 "inappropriate style \"%s\" in by clause\n",
1354 fname, lineno, style );
1358 if( b->a_authz.sai_tls_ssf ) {
1359 fprintf( stderr, "%s: line %d: "
1360 "tls_ssf attribute already specified.\n",
1365 if ( right == NULL || *right == '\0' ) {
1367 "%s: line %d: no tls_ssf is defined\n",
1372 b->a_authz.sai_tls_ssf = strtol( right, &next, 10 );
1373 if ( next == NULL || next[0] != '\0' ) {
1374 fprintf( stderr, "%s: line %d: "
1375 "unable to parse tls_ssf value (%s)\n",
1376 fname, lineno, right );
1380 if( !b->a_authz.sai_tls_ssf ) {
1382 "%s: line %d: invalid tls_ssf value (%s)\n",
1383 fname, lineno, right );
1389 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1390 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1391 fprintf( stderr, "%s: line %d: "
1392 "inappropriate style \"%s\" in by clause\n",
1393 fname, lineno, style );
1397 if( b->a_authz.sai_sasl_ssf ) {
1398 fprintf( stderr, "%s: line %d: "
1399 "sasl_ssf attribute already specified.\n",
1404 if ( right == NULL || *right == '\0' ) {
1406 "%s: line %d: no sasl_ssf is defined\n",
1411 b->a_authz.sai_sasl_ssf = strtol( right, &next, 10 );
1412 if ( next == NULL || next[0] != '\0' ) {
1413 fprintf( stderr, "%s: line %d: "
1414 "unable to parse sasl_ssf value (%s)\n",
1415 fname, lineno, right );
1419 if( !b->a_authz.sai_sasl_ssf ) {
1421 "%s: line %d: invalid sasl_ssf value (%s)\n",
1422 fname, lineno, right );
1428 if( right != NULL ) {
1435 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
1436 /* out of arguments or plain stop */
1438 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1439 b->a_type = ACL_STOP;
1441 access_append( &a->acl_access, b );
1445 if( strcasecmp( left, "continue" ) == 0 ) {
1446 /* plain continue */
1448 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1449 b->a_type = ACL_CONTINUE;
1451 access_append( &a->acl_access, b );
1455 if( strcasecmp( left, "break" ) == 0 ) {
1456 /* plain continue */
1458 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1459 b->a_type = ACL_BREAK;
1461 access_append( &a->acl_access, b );
1465 if ( strcasecmp( left, "by" ) == 0 ) {
1466 /* we've gone too far */
1468 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1469 b->a_type = ACL_STOP;
1471 access_append( &a->acl_access, b );
1476 if( strncasecmp( left, "self", 4 ) == 0 ) {
1478 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
1481 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1484 if( ACL_IS_INVALID( b->a_access_mask ) ) {
1486 "%s: line %d: expecting <access> got \"%s\"\n",
1487 fname, lineno, left );
1491 b->a_type = ACL_STOP;
1494 /* out of arguments or plain stop */
1495 access_append( &a->acl_access, b );
1499 if( strcasecmp( argv[i], "continue" ) == 0 ) {
1500 /* plain continue */
1501 b->a_type = ACL_CONTINUE;
1503 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
1504 /* plain continue */
1505 b->a_type = ACL_BREAK;
1507 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1512 access_append( &a->acl_access, b );
1516 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
1517 fname, lineno, argv[i] );
1522 /* if we have no real access clause, complain and do nothing */
1524 fprintf( stderr, "%s: line %d: "
1525 "warning: no access clause(s) specified in access line\n",
1530 if (ldap_debug & LDAP_DEBUG_ACL) print_acl(be, a);
1533 if ( a->acl_access == NULL ) {
1534 fprintf( stderr, "%s: line %d: "
1535 "warning: no by clause(s) specified in access line\n",
1541 switch ( check_scope( be, a ) ) {
1542 case ACL_SCOPE_UNKNOWN:
1543 fprintf( stderr, "%s: line %d: warning: "
1544 "cannot assess the validity of the ACL scope within "
1545 "backend naming context\n",
1549 case ACL_SCOPE_WARN:
1550 fprintf( stderr, "%s: line %d: warning: "
1551 "ACL could be out of scope within backend naming context\n",
1555 case ACL_SCOPE_PARTIAL:
1556 fprintf( stderr, "%s: line %d: warning: "
1557 "ACL appears to be partially out of scope within "
1558 "backend naming context\n",
1563 fprintf( stderr, "%s: line %d: warning: "
1564 "ACL appears to be out of scope within "
1565 "backend naming context\n",
1572 #endif /* LDAP_DEVEL */
1573 acl_append( &be->be_acl, a );
1575 acl_append( &frontendDB->be_acl, a );
1581 accessmask2str( slap_mask_t mask, char *buf )
1586 assert( buf != NULL );
1588 if ( ACL_IS_INVALID( mask ) ) {
1594 if ( ACL_IS_LEVEL( mask ) ) {
1595 if ( ACL_LVL_IS_NONE(mask) ) {
1596 ptr = lutil_strcopy( ptr, "none" );
1598 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1599 ptr = lutil_strcopy( ptr, "auth" );
1601 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1602 ptr = lutil_strcopy( ptr, "compare" );
1604 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1605 ptr = lutil_strcopy( ptr, "search" );
1607 } else if ( ACL_LVL_IS_READ(mask) ) {
1608 ptr = lutil_strcopy( ptr, "read" );
1610 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1611 ptr = lutil_strcopy( ptr, "write" );
1613 ptr = lutil_strcopy( ptr, "unknown" );
1619 if( ACL_IS_ADDITIVE( mask ) ) {
1622 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1629 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1634 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1639 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1644 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1649 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1654 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1663 if ( ACL_IS_LEVEL( mask ) ) {
1673 str2accessmask( const char *str )
1677 if( !ASCII_ALPHA(str[0]) ) {
1680 if ( str[0] == '=' ) {
1683 } else if( str[0] == '+' ) {
1684 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1686 } else if( str[0] == '-' ) {
1687 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1690 ACL_INVALIDATE(mask);
1694 for( i=1; str[i] != '\0'; i++ ) {
1695 if( TOLOWER((unsigned char) str[i]) == 'w' ) {
1696 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1698 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
1699 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1701 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
1702 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1704 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
1705 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1707 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
1708 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1710 } else if( str[i] != '0' ) {
1711 ACL_INVALIDATE(mask);
1719 if ( strcasecmp( str, "none" ) == 0 ) {
1720 ACL_LVL_ASSIGN_NONE(mask);
1722 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1723 ACL_LVL_ASSIGN_AUTH(mask);
1725 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1726 ACL_LVL_ASSIGN_COMPARE(mask);
1728 } else if ( strcasecmp( str, "search" ) == 0 ) {
1729 ACL_LVL_ASSIGN_SEARCH(mask);
1731 } else if ( strcasecmp( str, "read" ) == 0 ) {
1732 ACL_LVL_ASSIGN_READ(mask);
1734 } else if ( strcasecmp( str, "write" ) == 0 ) {
1735 ACL_LVL_ASSIGN_WRITE(mask);
1738 ACL_INVALIDATE( mask );
1747 fprintf( stderr, "%s%s%s\n",
1748 "<access clause> ::= access to <what> "
1749 "[ by <who> <access> [ <control> ] ]+ \n"
1750 "<what> ::= * | [dn[.<dnstyle>]=<DN>] [filter=<filter>] [attrs=<attrlist>]\n"
1751 "<attrlist> ::= <attr> [val[.<style>]=<value>] | <attr> , <attrlist>\n"
1752 "<attr> ::= <attrname> | entry | children\n",
1753 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
1754 "\t[dnattr=<attrname>]\n"
1755 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
1756 "\t[peername[.<peernamestyle>]=<peer>] [sockname[.<style>]=<name>]\n"
1757 "\t[domain[.<domainstyle>]=<domain>] [sockurl[.<style>]=<url>]\n"
1758 #ifdef SLAPD_ACI_ENABLED
1759 "\t[aci=<attrname>]\n"
1761 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n",
1762 "<dnstyle> ::= base(Object) | one(level) | sub(tree) | children | "
1764 "<style> ::= exact | regex | base(Object)\n"
1765 "<peernamestyle> ::= exact | regex | ip | path\n"
1766 "<domainstyle> ::= exact | regex | base(Object) | sub(tree)\n"
1767 "<access> ::= [self]{<level>|<priv>}\n"
1768 "<level> ::= none | auth | compare | search | read | write\n"
1769 "<priv> ::= {=|+|-}{w|r|s|c|x|0}+\n"
1770 "<control> ::= [ stop | continue | break ]\n"
1772 exit( EXIT_FAILURE );
1776 * Set pattern to a "normalized" DN from src.
1777 * At present it simply eats the (optional) space after
1778 * a RDN separator (,)
1779 * Eventually will evolve in a more complete normalization
1782 acl_regex_normalized_dn(
1784 struct berval *pattern )
1789 str = ch_strdup( src );
1790 len = strlen( src );
1792 for ( p = str; p && p[0]; p++ ) {
1794 if ( p[0] == '\\' && p[1] ) {
1796 * if escaping a hex pair we should
1797 * increment p twice; however, in that
1798 * case the second hex number does
1804 if ( p[0] == ',' && p[1] == ' ' ) {
1808 * too much space should be an error if we are pedantic
1810 for ( q = &p[2]; q[0] == ' '; q++ ) {
1813 AC_MEMCPY( p+1, q, len-(q-str)+1);
1816 pattern->bv_val = str;
1817 pattern->bv_len = p-str;
1830 if ( (*right = strchr( line, splitchar )) != NULL ) {
1831 *((*right)++) = '\0';
1836 access_append( Access **l, Access *a )
1838 for ( ; *l != NULL; l = &(*l)->a_next ) {
1846 acl_append( AccessControl **l, AccessControl *a )
1848 for ( ; *l != NULL; l = &(*l)->acl_next ) {
1856 access_free( Access *a )
1858 if ( a->a_dn_pat.bv_val ) free ( a->a_dn_pat.bv_val );
1859 if ( a->a_peername_pat.bv_val ) free ( a->a_peername_pat.bv_val );
1860 if ( a->a_sockname_pat.bv_val ) free ( a->a_sockname_pat.bv_val );
1861 if ( a->a_domain_pat.bv_val ) free ( a->a_domain_pat.bv_val );
1862 if ( a->a_sockurl_pat.bv_val ) free ( a->a_sockurl_pat.bv_val );
1863 if ( a->a_set_pat.bv_len ) free ( a->a_set_pat.bv_val );
1864 if ( a->a_group_pat.bv_len ) free ( a->a_group_pat.bv_val );
1869 acl_free( AccessControl *a )
1874 if ( a->acl_filter ) filter_free( a->acl_filter );
1875 if ( a->acl_dn_pat.bv_len ) free ( a->acl_dn_pat.bv_val );
1876 if ( a->acl_attrs ) {
1877 for ( an = a->acl_attrs; an->an_name.bv_val; an++ ) {
1878 free( an->an_name.bv_val );
1880 free( a->acl_attrs );
1882 for (; a->acl_access; a->acl_access = n) {
1883 n = a->acl_access->a_next;
1884 access_free( a->acl_access );
1889 /* Because backend_startup uses acl_append to tack on the global_acl to
1890 * the end of each backend's acl, we cannot just take one argument and
1891 * merrily free our way to the end of the list. backend_destroy calls us
1892 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1893 * point. config_destroy calls us with global_acl in arg1 and NULL in
1894 * arg2, so we then proceed to polish off the global_acl.
1897 acl_destroy( AccessControl *a, AccessControl *end )
1901 for (; a && a!= end; a=n) {
1908 access2str( slap_access_t access )
1910 if ( access == ACL_NONE ) {
1913 } else if ( access == ACL_AUTH ) {
1916 } else if ( access == ACL_COMPARE ) {
1919 } else if ( access == ACL_SEARCH ) {
1922 } else if ( access == ACL_READ ) {
1925 } else if ( access == ACL_WRITE ) {
1933 str2access( const char *str )
1935 if ( strcasecmp( str, "none" ) == 0 ) {
1938 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1941 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1944 } else if ( strcasecmp( str, "search" ) == 0 ) {
1947 } else if ( strcasecmp( str, "read" ) == 0 ) {
1950 } else if ( strcasecmp( str, "write" ) == 0 ) {
1954 return( ACL_INVALID_ACCESS );
1960 print_access( Access *b )
1962 char maskbuf[ACCESSMASK_MAXLEN];
1964 fprintf( stderr, "\tby" );
1966 if ( b->a_dn_pat.bv_len != 0 ) {
1967 if ( ber_bvccmp( &b->a_dn_pat, '*' ) ||
1968 strcmp(b->a_dn_pat.bv_val, "users") == 0 ||
1969 strcmp(b->a_dn_pat.bv_val, "anonymous") == 0 ||
1970 strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1972 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1975 fprintf( stderr, " dn.%s=\"%s\"",
1976 style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1980 if ( b->a_dn_at != NULL ) {
1981 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1984 if ( b->a_group_pat.bv_len ) {
1985 fprintf( stderr, " group/%s/%s.%s=\"%s\"",
1986 b->a_group_oc ? b->a_group_oc->soc_cname.bv_val : "groupOfNames",
1987 b->a_group_at ? b->a_group_at->ad_cname.bv_val : "member",
1988 style_strings[b->a_group_style],
1989 b->a_group_pat.bv_val );
1992 if ( b->a_peername_pat.bv_len != 0 ) {
1993 fprintf( stderr, " peername=\"%s\"", b->a_peername_pat.bv_val );
1996 if ( b->a_sockname_pat.bv_len != 0 ) {
1997 fprintf( stderr, " sockname=\"%s\"", b->a_sockname_pat.bv_val );
2000 if ( b->a_domain_pat.bv_len != 0 ) {
2001 fprintf( stderr, " domain=%s", b->a_domain_pat.bv_val );
2004 if ( b->a_sockurl_pat.bv_len != 0 ) {
2005 fprintf( stderr, " sockurl=\"%s\"", b->a_sockurl_pat.bv_val );
2008 if ( b->a_set_pat.bv_len != 0 ) {
2009 fprintf( stderr, " set=\"%s\"", b->a_set_pat.bv_val );
2012 #ifdef SLAPD_ACI_ENABLED
2013 if ( b->a_aci_at != NULL ) {
2014 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
2018 /* Security Strength Factors */
2019 if ( b->a_authz.sai_ssf ) {
2020 fprintf( stderr, " ssf=%u",
2021 b->a_authz.sai_ssf );
2023 if ( b->a_authz.sai_transport_ssf ) {
2024 fprintf( stderr, " transport_ssf=%u",
2025 b->a_authz.sai_transport_ssf );
2027 if ( b->a_authz.sai_tls_ssf ) {
2028 fprintf( stderr, " tls_ssf=%u",
2029 b->a_authz.sai_tls_ssf );
2031 if ( b->a_authz.sai_sasl_ssf ) {
2032 fprintf( stderr, " sasl_ssf=%u",
2033 b->a_authz.sai_sasl_ssf );
2036 fprintf( stderr, " %s%s",
2037 b->a_dn_self ? "self" : "",
2038 accessmask2str( b->a_access_mask, maskbuf ) );
2040 if( b->a_type == ACL_BREAK ) {
2041 fprintf( stderr, " break" );
2043 } else if( b->a_type == ACL_CONTINUE ) {
2044 fprintf( stderr, " continue" );
2046 } else if( b->a_type != ACL_STOP ) {
2047 fprintf( stderr, " unknown-control" );
2050 fprintf( stderr, "\n" );
2055 print_acl( Backend *be, AccessControl *a )
2060 fprintf( stderr, "%s ACL: access to",
2061 be == NULL ? "Global" : "Backend" );
2063 if ( a->acl_dn_pat.bv_len != 0 ) {
2065 fprintf( stderr, " dn.%s=\"%s\"\n",
2066 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
2069 if ( a->acl_filter != NULL ) {
2070 struct berval bv = BER_BVNULL;
2072 filter2bv( a->acl_filter, &bv );
2073 fprintf( stderr, " filter=%s\n", bv.bv_val );
2074 ch_free( bv.bv_val );
2077 if ( a->acl_attrs != NULL ) {
2082 fprintf( stderr, " attrs=" );
2083 for ( an = a->acl_attrs; an && an->an_name.bv_val; an++ ) {
2084 if ( ! first ) fprintf( stderr, "," );
2086 fputc( an->an_oc_exclude ? '!' : '@', stderr);
2088 fputs( an->an_name.bv_val, stderr );
2091 fprintf( stderr, "\n" );
2094 if ( a->acl_attrval.bv_len != 0 ) {
2096 fprintf( stderr, " val.%s=\"%s\"\n",
2097 style_strings[a->acl_attrval_style], a->acl_attrval.bv_val );
2101 if( !to ) fprintf( stderr, " *\n" );
2103 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
2107 fprintf( stderr, "\n" );
2109 #endif /* LDAP_DEBUG */