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 = sizeof("*")-1;
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 ( a->acl_dn_pat.bv_len != 0 &&
478 strcmp(a->acl_dn_pat.bv_val, "*") == 0 )
480 free( a->acl_dn_pat.bv_val );
481 a->acl_dn_pat.bv_val = NULL;
482 a->acl_dn_pat.bv_len = 0;
485 if( a->acl_dn_pat.bv_len != 0 ||
486 ( a->acl_dn_style != ACL_STYLE_REGEX ) )
488 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
490 rc = dnNormalize( 0, NULL, NULL, &a->acl_dn_pat, &bv, NULL);
491 if ( rc != LDAP_SUCCESS ) {
493 "%s: line %d: bad DN \"%s\" in to DN clause\n",
494 fname, lineno, a->acl_dn_pat.bv_val );
497 free( a->acl_dn_pat.bv_val );
500 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
501 REG_EXTENDED | REG_ICASE );
504 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
505 fprintf( stderr, "%s: line %d: "
506 "regular expression \"%s\" bad because of %s\n",
507 fname, lineno, right, buf );
513 /* by clause - select who has what access to entries */
514 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
516 fprintf( stderr, "%s: line %d: "
517 "to clause required before by clause in access line\n",
523 * by clause consists of <who> and <access>
526 b = (Access *) ch_calloc( 1, sizeof(Access) );
528 ACL_INVALIDATE( b->a_access_mask );
532 "%s: line %d: premature eol: expecting <who>\n",
538 for ( ; i < argc; i++ ) {
539 slap_style_t sty = ACL_STYLE_REGEX;
540 char *style_modifier = NULL;
543 split( argv[i], '=', &left, &right );
544 split( left, '.', &left, &style );
546 split( style, ',', &style, &style_modifier);
549 if ( style == NULL || *style == '\0' ||
550 strcasecmp( style, "exact" ) == 0 ||
551 strcasecmp( style, "baseObject" ) == 0 ||
552 strcasecmp( style, "base" ) == 0 )
554 sty = ACL_STYLE_BASE;
556 } else if ( strcasecmp( style, "onelevel" ) == 0 ||
557 strcasecmp( style, "one" ) == 0 )
561 } else if ( strcasecmp( style, "subtree" ) == 0 ||
562 strcasecmp( style, "sub" ) == 0 )
564 sty = ACL_STYLE_SUBTREE;
566 } else if ( strcasecmp( style, "children" ) == 0 ) {
567 sty = ACL_STYLE_CHILDREN;
569 } else if ( strcasecmp( style, "regex" ) == 0 ) {
570 sty = ACL_STYLE_REGEX;
572 } else if ( strcasecmp( style, "expand" ) == 0 ) {
573 sty = ACL_STYLE_EXPAND;
575 } else if ( strcasecmp( style, "ip" ) == 0 ) {
578 } else if ( strcasecmp( style, "path" ) == 0 ) {
579 sty = ACL_STYLE_PATH;
580 #ifndef LDAP_PF_LOCAL
581 fprintf( stderr, "%s: line %d: "
582 "path style modifier is useless without local\n",
584 #endif /* LDAP_PF_LOCAL */
588 "%s: line %d: unknown style \"%s\" in by clause\n",
589 fname, lineno, style );
593 if ( style_modifier &&
594 strcasecmp( style_modifier, "expand" ) == 0 )
597 case ACL_STYLE_REGEX:
598 fprintf( stderr, "%s: line %d: "
599 "\"regex\" style implies "
600 "\"expand\" modifier (ignored)\n",
604 case ACL_STYLE_EXPAND:
605 fprintf( stderr, "%s: line %d: "
606 "\"expand\" style used "
607 "in conjunction with "
608 "\"expand\" modifier (ignored)\n",
613 /* we'll see later if it's pertinent */
619 /* expand in <who> needs regex in <what> */
620 if ( ( sty == ACL_STYLE_EXPAND || expand )
621 && a->acl_dn_style != ACL_STYLE_REGEX )
623 fprintf( stderr, "%s: line %d: "
624 "\"expand\" style or modifier used "
625 "in conjunction with "
626 "a non-regex <what> clause\n",
631 if ( strcasecmp( argv[i], "*" ) == 0 ) {
632 bv.bv_val = ch_strdup( "*" );
634 sty = ACL_STYLE_REGEX;
636 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
637 ber_str2bv("anonymous", sizeof("anonymous")-1, 1, &bv);
638 sty = ACL_STYLE_REGEX;
640 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
641 ber_str2bv("self", sizeof("self")-1, 1, &bv);
642 sty = ACL_STYLE_REGEX;
644 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
645 ber_str2bv("users", sizeof("users")-1, 1, &bv);
646 sty = ACL_STYLE_REGEX;
648 } else if ( strcasecmp( left, "dn" ) == 0 ) {
649 if ( sty == ACL_STYLE_REGEX ) {
650 b->a_dn_style = ACL_STYLE_REGEX;
651 if( right == NULL ) {
656 } else if (*right == '\0' ) {
658 ber_str2bv("anonymous",
659 sizeof("anonymous")-1,
661 } else if ( strcmp( right, "*" ) == 0 ) {
663 /* any or users? users for now */
667 } else if ( strcmp( right, ".+" ) == 0
668 || strcmp( right, "^.+" ) == 0
669 || strcmp( right, ".+$" ) == 0
670 || strcmp( right, "^.+$" ) == 0
671 || strcmp( right, ".+$$" ) == 0
672 || strcmp( right, "^.+$$" ) == 0 )
677 } else if ( strcmp( right, ".*" ) == 0
678 || strcmp( right, "^.*" ) == 0
679 || strcmp( right, ".*$" ) == 0
680 || strcmp( right, "^.*$" ) == 0
681 || strcmp( right, ".*$$" ) == 0
682 || strcmp( right, "^.*$$" ) == 0 )
689 acl_regex_normalized_dn( right, &bv );
690 if ( !ber_bvccmp( &bv, '*' ) ) {
691 regtest(fname, lineno, bv.bv_val);
694 } else if ( right == NULL || *right == '\0' ) {
695 fprintf( stderr, "%s: line %d: "
696 "missing \"=\" in (or value after) \"%s\" "
698 fname, lineno, left );
702 ber_str2bv( right, 0, 1, &bv );
709 if( bv.bv_val != NULL ) {
710 if( b->a_dn_pat.bv_len != 0 ) {
712 "%s: line %d: dn pattern already specified.\n",
717 if ( sty != ACL_STYLE_REGEX && expand == 0 ) {
718 rc = dnNormalize(0, NULL, NULL,
719 &bv, &b->a_dn_pat, NULL);
720 if ( rc != LDAP_SUCCESS ) {
722 "%s: line %d: bad DN \"%s\" in by DN clause\n",
723 fname, lineno, bv.bv_val );
731 b->a_dn_expand = expand;
735 if ( strcasecmp( left, "dnattr" ) == 0 ) {
736 if ( right == NULL || right[0] == '\0' ) {
737 fprintf( stderr, "%s: line %d: "
738 "missing \"=\" in (or value after) \"%s\" "
740 fname, lineno, left );
744 if( b->a_dn_at != NULL ) {
746 "%s: line %d: dnattr already specified.\n",
751 rc = slap_str2ad( right, &b->a_dn_at, &text );
753 if( rc != LDAP_SUCCESS ) {
755 "%s: line %d: dnattr \"%s\": %s\n",
756 fname, lineno, right, text );
761 if( !is_at_syntax( b->a_dn_at->ad_type,
763 !is_at_syntax( b->a_dn_at->ad_type,
764 SLAPD_NAMEUID_SYNTAX ))
767 "%s: line %d: dnattr \"%s\": "
768 "inappropriate syntax: %s\n",
769 fname, lineno, right,
770 b->a_dn_at->ad_type->sat_syntax_oid );
774 if( b->a_dn_at->ad_type->sat_equality == NULL ) {
776 "%s: line %d: dnattr \"%s\": "
777 "inappropriate matching (no EQUALITY)\n",
778 fname, lineno, right );
785 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
790 case ACL_STYLE_REGEX:
791 /* legacy, tolerated */
792 fprintf( stderr, "%s: line %d: "
793 "deprecated group style \"regex\"; "
794 "use \"expand\" instead\n",
795 fname, lineno, style );
796 sty = ACL_STYLE_EXPAND;
800 /* legal, traditional */
801 case ACL_STYLE_EXPAND:
802 /* legal, substring expansion; supersedes regex */
807 fprintf( stderr, "%s: line %d: "
808 "inappropriate style \"%s\" in by clause\n",
809 fname, lineno, style );
813 if ( right == NULL || right[0] == '\0' ) {
814 fprintf( stderr, "%s: line %d: "
815 "missing \"=\" in (or value after) \"%s\" "
817 fname, lineno, left );
821 if( b->a_group_pat.bv_len ) {
823 "%s: line %d: group pattern already specified.\n",
828 /* format of string is
829 "group/objectClassValue/groupAttrName" */
830 if ((value = strchr(left, '/')) != NULL) {
832 if (*value && (name = strchr(value, '/')) != NULL) {
837 b->a_group_style = sty;
838 if (sty == ACL_STYLE_EXPAND) {
839 acl_regex_normalized_dn( right, &bv );
840 if ( !ber_bvccmp( &bv, '*' ) ) {
841 regtest(fname, lineno, bv.bv_val);
845 ber_str2bv( right, 0, 0, &bv );
846 rc = dnNormalize( 0, NULL, NULL, &bv,
847 &b->a_group_pat, NULL );
848 if ( rc != LDAP_SUCCESS ) {
850 "%s: line %d: bad DN \"%s\"\n",
851 fname, lineno, right );
856 if (value && *value) {
857 b->a_group_oc = oc_find( value );
860 if( b->a_group_oc == NULL ) {
862 "%s: line %d: group objectclass "
864 fname, lineno, value );
868 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
870 if( b->a_group_oc == NULL ) {
872 "%s: line %d: group default objectclass "
874 fname, lineno, SLAPD_GROUP_CLASS );
879 if( is_object_subclass( slap_schema.si_oc_referral,
883 "%s: line %d: group objectclass \"%s\" "
884 "is subclass of referral\n",
885 fname, lineno, value );
889 if( is_object_subclass( slap_schema.si_oc_alias,
893 "%s: line %d: group objectclass \"%s\" "
894 "is subclass of alias\n",
895 fname, lineno, value );
900 rc = slap_str2ad( name, &b->a_group_at, &text );
902 if( rc != LDAP_SUCCESS ) {
904 "%s: line %d: group \"%s\": %s\n",
905 fname, lineno, right, text );
910 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
912 if( rc != LDAP_SUCCESS ) {
914 "%s: line %d: group \"%s\": %s\n",
915 fname, lineno, SLAPD_GROUP_ATTR, text );
920 if( !is_at_syntax( b->a_group_at->ad_type,
922 !is_at_syntax( b->a_group_at->ad_type,
923 SLAPD_NAMEUID_SYNTAX ) &&
924 !is_at_subtype( b->a_group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ))
927 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
928 fname, lineno, right,
929 b->a_group_at->ad_type->sat_syntax_oid );
936 struct berval vals[2];
938 vals[0].bv_val = b->a_group_oc->soc_oid;
939 vals[0].bv_len = strlen(vals[0].bv_val);
940 vals[1].bv_val = NULL;
943 rc = oc_check_allowed( b->a_group_at->ad_type,
947 fprintf( stderr, "%s: line %d: "
948 "group: \"%s\" not allowed by \"%s\"\n",
950 b->a_group_at->ad_cname.bv_val,
951 b->a_group_oc->soc_oid );
958 if ( strcasecmp( left, "peername" ) == 0 ) {
960 case ACL_STYLE_REGEX:
962 /* legal, traditional */
963 case ACL_STYLE_EXPAND:
964 /* cheap replacement to regex for simple expansion */
967 /* legal, peername specific */
971 fprintf( stderr, "%s: line %d: "
972 "inappropriate style \"%s\" in by clause\n",
973 fname, lineno, style );
977 if ( right == NULL || right[0] == '\0' ) {
978 fprintf( stderr, "%s: line %d: "
979 "missing \"=\" in (or value after) \"%s\" "
981 fname, lineno, left );
985 if( b->a_peername_pat.bv_len ) {
986 fprintf( stderr, "%s: line %d: "
987 "peername pattern already specified.\n",
992 b->a_peername_style = sty;
993 if (sty == ACL_STYLE_REGEX) {
994 acl_regex_normalized_dn( right, &bv );
995 if ( !ber_bvccmp( &bv, '*' ) ) {
996 regtest(fname, lineno, bv.bv_val);
998 b->a_peername_pat = bv;
1001 ber_str2bv( right, 0, 1, &b->a_peername_pat );
1003 if ( sty == ACL_STYLE_IP ) {
1008 split( right, '{', &addr, &port );
1009 split( addr, '%', &addr, &mask );
1011 b->a_peername_addr = inet_addr( addr );
1012 if ( b->a_peername_addr == (unsigned long)(-1)) {
1013 /* illegal address */
1014 fprintf( stderr, "%s: line %d: "
1015 "illegal peername address \"%s\".\n",
1016 fname, lineno, addr );
1020 b->a_peername_mask = (unsigned long)(-1);
1021 if ( mask != NULL ) {
1022 b->a_peername_mask = inet_addr( mask );
1023 if ( b->a_peername_mask ==
1024 (unsigned long)(-1))
1027 fprintf( stderr, "%s: line %d: "
1028 "illegal peername address mask "
1030 fname, lineno, mask );
1035 b->a_peername_port = -1;
1039 b->a_peername_port = strtol( port, &end, 10 );
1040 if ( end[0] != '}' ) {
1042 fprintf( stderr, "%s: line %d: "
1043 "illegal peername port specification "
1045 fname, lineno, port );
1054 if ( strcasecmp( left, "sockname" ) == 0 ) {
1056 case ACL_STYLE_REGEX:
1057 case ACL_STYLE_BASE:
1058 /* legal, traditional */
1059 case ACL_STYLE_EXPAND:
1060 /* cheap replacement to regex for simple expansion */
1065 fprintf( stderr, "%s: line %d: "
1066 "inappropriate style \"%s\" in by clause\n",
1067 fname, lineno, style );
1071 if ( right == NULL || right[0] == '\0' ) {
1072 fprintf( stderr, "%s: line %d: "
1073 "missing \"=\" in (or value after) \"%s\" "
1075 fname, lineno, left );
1079 if( b->a_sockname_pat.bv_len ) {
1080 fprintf( stderr, "%s: line %d: "
1081 "sockname pattern already specified.\n",
1086 b->a_sockname_style = sty;
1087 if (sty == ACL_STYLE_REGEX) {
1088 acl_regex_normalized_dn( right, &bv );
1089 if ( !ber_bvccmp( &bv, '*' ) ) {
1090 regtest(fname, lineno, bv.bv_val);
1092 b->a_sockname_pat = bv;
1094 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
1099 if ( strcasecmp( left, "domain" ) == 0 ) {
1101 case ACL_STYLE_REGEX:
1102 case ACL_STYLE_BASE:
1103 case ACL_STYLE_SUBTREE:
1104 /* legal, traditional */
1107 case ACL_STYLE_EXPAND:
1108 /* tolerated: means exact,expand */
1112 "\"expand\" modifier with \"expand\" style\n",
1115 sty = ACL_STYLE_BASE;
1121 fprintf( stderr, "%s: line %d: "
1122 "inappropriate style \"%s\" in by clause\n",
1123 fname, lineno, style );
1127 if ( right == NULL || right[0] == '\0' ) {
1128 fprintf( stderr, "%s: line %d: "
1129 "missing \"=\" in (or value after) \"%s\" "
1131 fname, lineno, left );
1135 if( b->a_domain_pat.bv_len ) {
1137 "%s: line %d: domain pattern already specified.\n",
1142 b->a_domain_style = sty;
1143 b->a_domain_expand = expand;
1144 if (sty == ACL_STYLE_REGEX) {
1145 acl_regex_normalized_dn( right, &bv );
1146 if ( !ber_bvccmp( &bv, '*' ) ) {
1147 regtest(fname, lineno, bv.bv_val);
1149 b->a_domain_pat = bv;
1151 ber_str2bv( right, 0, 1, &b->a_domain_pat );
1156 if ( strcasecmp( left, "sockurl" ) == 0 ) {
1158 case ACL_STYLE_REGEX:
1159 case ACL_STYLE_BASE:
1160 /* legal, traditional */
1161 case ACL_STYLE_EXPAND:
1162 /* cheap replacement to regex for simple expansion */
1167 fprintf( stderr, "%s: line %d: "
1168 "inappropriate style \"%s\" in by clause\n",
1169 fname, lineno, style );
1173 if ( right == NULL || right[0] == '\0' ) {
1174 fprintf( stderr, "%s: line %d: "
1175 "missing \"=\" in (or value after) \"%s\" "
1177 fname, lineno, left );
1181 if( b->a_sockurl_pat.bv_len ) {
1183 "%s: line %d: sockurl pattern already specified.\n",
1188 b->a_sockurl_style = sty;
1189 if (sty == ACL_STYLE_REGEX) {
1190 acl_regex_normalized_dn( right, &bv );
1191 if ( !ber_bvccmp( &bv, '*' ) ) {
1192 regtest(fname, lineno, bv.bv_val);
1194 b->a_sockurl_pat = bv;
1196 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
1201 if ( strcasecmp( left, "set" ) == 0 ) {
1202 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1203 fprintf( stderr, "%s: line %d: "
1204 "inappropriate style \"%s\" in by clause\n",
1205 fname, lineno, style );
1209 if( b->a_set_pat.bv_len != 0 ) {
1211 "%s: line %d: set attribute already specified.\n",
1216 if ( right == NULL || *right == '\0' ) {
1218 "%s: line %d: no set is defined\n",
1223 b->a_set_style = sty;
1224 ber_str2bv( right, 0, 1, &b->a_set_pat );
1229 #ifdef SLAPD_ACI_ENABLED
1230 if ( strcasecmp( left, "aci" ) == 0 ) {
1231 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1232 fprintf( stderr, "%s: line %d: "
1233 "inappropriate style \"%s\" in by clause\n",
1234 fname, lineno, style );
1238 if( b->a_aci_at != NULL ) {
1240 "%s: line %d: aci attribute already specified.\n",
1245 if ( right != NULL && *right != '\0' ) {
1246 rc = slap_str2ad( right, &b->a_aci_at, &text );
1248 if( rc != LDAP_SUCCESS ) {
1250 "%s: line %d: aci \"%s\": %s\n",
1251 fname, lineno, right, text );
1256 b->a_aci_at = slap_schema.si_ad_aci;
1259 if( !is_at_syntax( b->a_aci_at->ad_type,
1262 fprintf( stderr, "%s: line %d: "
1263 "aci \"%s\": inappropriate syntax: %s\n",
1264 fname, lineno, right,
1265 b->a_aci_at->ad_type->sat_syntax_oid );
1271 #endif /* SLAPD_ACI_ENABLED */
1273 if ( strcasecmp( left, "ssf" ) == 0 ) {
1274 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1275 fprintf( stderr, "%s: line %d: "
1276 "inappropriate style \"%s\" in by clause\n",
1277 fname, lineno, style );
1281 if( b->a_authz.sai_ssf ) {
1283 "%s: line %d: ssf attribute already specified.\n",
1288 if ( right == NULL || *right == '\0' ) {
1290 "%s: line %d: no ssf is defined\n",
1295 b->a_authz.sai_ssf = strtol( right, &next, 10 );
1296 if ( next == NULL || next[0] != '\0' ) {
1298 "%s: line %d: unable to parse ssf value (%s)\n",
1299 fname, lineno, right );
1303 if( !b->a_authz.sai_ssf ) {
1305 "%s: line %d: invalid ssf value (%s)\n",
1306 fname, lineno, right );
1312 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
1313 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1314 fprintf( stderr, "%s: line %d: "
1315 "inappropriate style \"%s\" in by clause\n",
1316 fname, lineno, style );
1320 if( b->a_authz.sai_transport_ssf ) {
1321 fprintf( stderr, "%s: line %d: "
1322 "transport_ssf attribute already specified.\n",
1327 if ( right == NULL || *right == '\0' ) {
1329 "%s: line %d: no transport_ssf is defined\n",
1334 b->a_authz.sai_transport_ssf = strtol( right, &next, 10 );
1335 if ( next == NULL || next[0] != '\0' ) {
1336 fprintf( stderr, "%s: line %d: "
1337 "unable to parse transport_ssf value (%s)\n",
1338 fname, lineno, right );
1342 if( !b->a_authz.sai_transport_ssf ) {
1344 "%s: line %d: invalid transport_ssf value (%s)\n",
1345 fname, lineno, right );
1351 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
1352 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1353 fprintf( stderr, "%s: line %d: "
1354 "inappropriate style \"%s\" in by clause\n",
1355 fname, lineno, style );
1359 if( b->a_authz.sai_tls_ssf ) {
1360 fprintf( stderr, "%s: line %d: "
1361 "tls_ssf attribute already specified.\n",
1366 if ( right == NULL || *right == '\0' ) {
1368 "%s: line %d: no tls_ssf is defined\n",
1373 b->a_authz.sai_tls_ssf = strtol( right, &next, 10 );
1374 if ( next == NULL || next[0] != '\0' ) {
1375 fprintf( stderr, "%s: line %d: "
1376 "unable to parse tls_ssf value (%s)\n",
1377 fname, lineno, right );
1381 if( !b->a_authz.sai_tls_ssf ) {
1383 "%s: line %d: invalid tls_ssf value (%s)\n",
1384 fname, lineno, right );
1390 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1391 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1392 fprintf( stderr, "%s: line %d: "
1393 "inappropriate style \"%s\" in by clause\n",
1394 fname, lineno, style );
1398 if( b->a_authz.sai_sasl_ssf ) {
1399 fprintf( stderr, "%s: line %d: "
1400 "sasl_ssf attribute already specified.\n",
1405 if ( right == NULL || *right == '\0' ) {
1407 "%s: line %d: no sasl_ssf is defined\n",
1412 b->a_authz.sai_sasl_ssf = strtol( right, &next, 10 );
1413 if ( next == NULL || next[0] != '\0' ) {
1414 fprintf( stderr, "%s: line %d: "
1415 "unable to parse sasl_ssf value (%s)\n",
1416 fname, lineno, right );
1420 if( !b->a_authz.sai_sasl_ssf ) {
1422 "%s: line %d: invalid sasl_ssf value (%s)\n",
1423 fname, lineno, right );
1429 if( right != NULL ) {
1436 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
1437 /* out of arguments or plain stop */
1439 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1440 b->a_type = ACL_STOP;
1442 access_append( &a->acl_access, b );
1446 if( strcasecmp( left, "continue" ) == 0 ) {
1447 /* plain continue */
1449 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1450 b->a_type = ACL_CONTINUE;
1452 access_append( &a->acl_access, b );
1456 if( strcasecmp( left, "break" ) == 0 ) {
1457 /* plain continue */
1459 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1460 b->a_type = ACL_BREAK;
1462 access_append( &a->acl_access, b );
1466 if ( strcasecmp( left, "by" ) == 0 ) {
1467 /* we've gone too far */
1469 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1470 b->a_type = ACL_STOP;
1472 access_append( &a->acl_access, b );
1477 if( strncasecmp( left, "self", 4 ) == 0 ) {
1479 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
1482 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1485 if( ACL_IS_INVALID( b->a_access_mask ) ) {
1487 "%s: line %d: expecting <access> got \"%s\"\n",
1488 fname, lineno, left );
1492 b->a_type = ACL_STOP;
1495 /* out of arguments or plain stop */
1496 access_append( &a->acl_access, b );
1500 if( strcasecmp( argv[i], "continue" ) == 0 ) {
1501 /* plain continue */
1502 b->a_type = ACL_CONTINUE;
1504 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
1505 /* plain continue */
1506 b->a_type = ACL_BREAK;
1508 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1513 access_append( &a->acl_access, b );
1517 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
1518 fname, lineno, argv[i] );
1523 /* if we have no real access clause, complain and do nothing */
1525 fprintf( stderr, "%s: line %d: "
1526 "warning: no access clause(s) specified in access line\n",
1531 if (ldap_debug & LDAP_DEBUG_ACL) print_acl(be, a);
1534 if ( a->acl_access == NULL ) {
1535 fprintf( stderr, "%s: line %d: "
1536 "warning: no by clause(s) specified in access line\n",
1542 switch ( check_scope( be, a ) ) {
1543 case ACL_SCOPE_UNKNOWN:
1544 fprintf( stderr, "%s: line %d: warning: "
1545 "cannot assess the validity of the ACL scope within "
1546 "backend naming context\n",
1550 case ACL_SCOPE_WARN:
1551 fprintf( stderr, "%s: line %d: warning: "
1552 "ACL could be out of scope within backend naming context\n",
1556 case ACL_SCOPE_PARTIAL:
1557 fprintf( stderr, "%s: line %d: warning: "
1558 "ACL appears to be partially out of scope within "
1559 "backend naming context\n",
1564 fprintf( stderr, "%s: line %d: warning: "
1565 "ACL appears to be out of scope within "
1566 "backend naming context\n",
1573 #endif /* LDAP_DEVEL */
1574 acl_append( &be->be_acl, a );
1576 acl_append( &frontendDB->be_acl, a );
1582 accessmask2str( slap_mask_t mask, char *buf )
1587 assert( buf != NULL );
1589 if ( ACL_IS_INVALID( mask ) ) {
1595 if ( ACL_IS_LEVEL( mask ) ) {
1596 if ( ACL_LVL_IS_NONE(mask) ) {
1597 ptr = lutil_strcopy( ptr, "none" );
1599 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1600 ptr = lutil_strcopy( ptr, "auth" );
1602 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1603 ptr = lutil_strcopy( ptr, "compare" );
1605 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1606 ptr = lutil_strcopy( ptr, "search" );
1608 } else if ( ACL_LVL_IS_READ(mask) ) {
1609 ptr = lutil_strcopy( ptr, "read" );
1611 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1612 ptr = lutil_strcopy( ptr, "write" );
1614 ptr = lutil_strcopy( ptr, "unknown" );
1620 if( ACL_IS_ADDITIVE( mask ) ) {
1623 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1630 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1635 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1640 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1645 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1650 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1655 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1664 if ( ACL_IS_LEVEL( mask ) ) {
1674 str2accessmask( const char *str )
1678 if( !ASCII_ALPHA(str[0]) ) {
1681 if ( str[0] == '=' ) {
1684 } else if( str[0] == '+' ) {
1685 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1687 } else if( str[0] == '-' ) {
1688 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1691 ACL_INVALIDATE(mask);
1695 for( i=1; str[i] != '\0'; i++ ) {
1696 if( TOLOWER((unsigned char) str[i]) == 'w' ) {
1697 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1699 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
1700 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1702 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
1703 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1705 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
1706 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1708 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
1709 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1711 } else if( str[i] != '0' ) {
1712 ACL_INVALIDATE(mask);
1720 if ( strcasecmp( str, "none" ) == 0 ) {
1721 ACL_LVL_ASSIGN_NONE(mask);
1723 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1724 ACL_LVL_ASSIGN_AUTH(mask);
1726 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1727 ACL_LVL_ASSIGN_COMPARE(mask);
1729 } else if ( strcasecmp( str, "search" ) == 0 ) {
1730 ACL_LVL_ASSIGN_SEARCH(mask);
1732 } else if ( strcasecmp( str, "read" ) == 0 ) {
1733 ACL_LVL_ASSIGN_READ(mask);
1735 } else if ( strcasecmp( str, "write" ) == 0 ) {
1736 ACL_LVL_ASSIGN_WRITE(mask);
1739 ACL_INVALIDATE( mask );
1748 fprintf( stderr, "%s%s%s\n",
1749 "<access clause> ::= access to <what> "
1750 "[ by <who> <access> [ <control> ] ]+ \n"
1751 "<what> ::= * | [dn[.<dnstyle>]=<DN>] [filter=<filter>] [attrs=<attrlist>]\n"
1752 "<attrlist> ::= <attr> [val[.<style>]=<value>] | <attr> , <attrlist>\n"
1753 "<attr> ::= <attrname> | entry | children\n",
1754 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
1755 "\t[dnattr=<attrname>]\n"
1756 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
1757 "\t[peername[.<peernamestyle>]=<peer>] [sockname[.<style>]=<name>]\n"
1758 "\t[domain[.<domainstyle>]=<domain>] [sockurl[.<style>]=<url>]\n"
1759 #ifdef SLAPD_ACI_ENABLED
1760 "\t[aci=<attrname>]\n"
1762 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n",
1763 "<dnstyle> ::= base(Object) | one(level) | sub(tree) | children | "
1765 "<style> ::= exact | regex | base(Object)\n"
1766 "<peernamestyle> ::= exact | regex | ip | path\n"
1767 "<domainstyle> ::= exact | regex | base(Object) | sub(tree)\n"
1768 "<access> ::= [self]{<level>|<priv>}\n"
1769 "<level> ::= none | auth | compare | search | read | write\n"
1770 "<priv> ::= {=|+|-}{w|r|s|c|x|0}+\n"
1771 "<control> ::= [ stop | continue | break ]\n"
1773 exit( EXIT_FAILURE );
1777 * Set pattern to a "normalized" DN from src.
1778 * At present it simply eats the (optional) space after
1779 * a RDN separator (,)
1780 * Eventually will evolve in a more complete normalization
1783 acl_regex_normalized_dn(
1785 struct berval *pattern )
1790 str = ch_strdup( src );
1791 len = strlen( src );
1793 for ( p = str; p && p[0]; p++ ) {
1795 if ( p[0] == '\\' && p[1] ) {
1797 * if escaping a hex pair we should
1798 * increment p twice; however, in that
1799 * case the second hex number does
1805 if ( p[0] == ',' && p[1] == ' ' ) {
1809 * too much space should be an error if we are pedantic
1811 for ( q = &p[2]; q[0] == ' '; q++ ) {
1814 AC_MEMCPY( p+1, q, len-(q-str)+1);
1817 pattern->bv_val = str;
1818 pattern->bv_len = p-str;
1831 if ( (*right = strchr( line, splitchar )) != NULL ) {
1832 *((*right)++) = '\0';
1837 access_append( Access **l, Access *a )
1839 for ( ; *l != NULL; l = &(*l)->a_next ) {
1847 acl_append( AccessControl **l, AccessControl *a )
1849 for ( ; *l != NULL; l = &(*l)->acl_next ) {
1857 access_free( Access *a )
1859 if ( a->a_dn_pat.bv_val ) free ( a->a_dn_pat.bv_val );
1860 if ( a->a_peername_pat.bv_val ) free ( a->a_peername_pat.bv_val );
1861 if ( a->a_sockname_pat.bv_val ) free ( a->a_sockname_pat.bv_val );
1862 if ( a->a_domain_pat.bv_val ) free ( a->a_domain_pat.bv_val );
1863 if ( a->a_sockurl_pat.bv_val ) free ( a->a_sockurl_pat.bv_val );
1864 if ( a->a_set_pat.bv_len ) free ( a->a_set_pat.bv_val );
1865 if ( a->a_group_pat.bv_len ) free ( a->a_group_pat.bv_val );
1870 acl_free( AccessControl *a )
1875 if ( a->acl_filter ) filter_free( a->acl_filter );
1876 if ( a->acl_dn_pat.bv_len ) free ( a->acl_dn_pat.bv_val );
1877 if ( a->acl_attrs ) {
1878 for ( an = a->acl_attrs; an->an_name.bv_val; an++ ) {
1879 free( an->an_name.bv_val );
1881 free( a->acl_attrs );
1883 for (; a->acl_access; a->acl_access = n) {
1884 n = a->acl_access->a_next;
1885 access_free( a->acl_access );
1890 /* Because backend_startup uses acl_append to tack on the global_acl to
1891 * the end of each backend's acl, we cannot just take one argument and
1892 * merrily free our way to the end of the list. backend_destroy calls us
1893 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1894 * point. config_destroy calls us with global_acl in arg1 and NULL in
1895 * arg2, so we then proceed to polish off the global_acl.
1898 acl_destroy( AccessControl *a, AccessControl *end )
1902 for (; a && a!= end; a=n) {
1909 access2str( slap_access_t access )
1911 if ( access == ACL_NONE ) {
1914 } else if ( access == ACL_AUTH ) {
1917 } else if ( access == ACL_COMPARE ) {
1920 } else if ( access == ACL_SEARCH ) {
1923 } else if ( access == ACL_READ ) {
1926 } else if ( access == ACL_WRITE ) {
1934 str2access( const char *str )
1936 if ( strcasecmp( str, "none" ) == 0 ) {
1939 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1942 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1945 } else if ( strcasecmp( str, "search" ) == 0 ) {
1948 } else if ( strcasecmp( str, "read" ) == 0 ) {
1951 } else if ( strcasecmp( str, "write" ) == 0 ) {
1955 return( ACL_INVALID_ACCESS );
1961 print_access( Access *b )
1963 char maskbuf[ACCESSMASK_MAXLEN];
1965 fprintf( stderr, "\tby" );
1967 if ( b->a_dn_pat.bv_len != 0 ) {
1968 if( strcmp(b->a_dn_pat.bv_val, "*") == 0 ||
1969 strcmp(b->a_dn_pat.bv_val, "users") == 0 ||
1970 strcmp(b->a_dn_pat.bv_val, "anonymous") == 0 ||
1971 strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1973 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1976 fprintf( stderr, " dn.%s=\"%s\"",
1977 style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1981 if ( b->a_dn_at != NULL ) {
1982 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1985 if ( b->a_group_pat.bv_len ) {
1986 fprintf( stderr, " group/%s/%s.%s=\"%s\"",
1987 b->a_group_oc ? b->a_group_oc->soc_cname.bv_val : "groupOfNames",
1988 b->a_group_at ? b->a_group_at->ad_cname.bv_val : "member",
1989 style_strings[b->a_group_style],
1990 b->a_group_pat.bv_val );
1993 if ( b->a_peername_pat.bv_len != 0 ) {
1994 fprintf( stderr, " peername=\"%s\"", b->a_peername_pat.bv_val );
1997 if ( b->a_sockname_pat.bv_len != 0 ) {
1998 fprintf( stderr, " sockname=\"%s\"", b->a_sockname_pat.bv_val );
2001 if ( b->a_domain_pat.bv_len != 0 ) {
2002 fprintf( stderr, " domain=%s", b->a_domain_pat.bv_val );
2005 if ( b->a_sockurl_pat.bv_len != 0 ) {
2006 fprintf( stderr, " sockurl=\"%s\"", b->a_sockurl_pat.bv_val );
2009 if ( b->a_set_pat.bv_len != 0 ) {
2010 fprintf( stderr, " set=\"%s\"", b->a_set_pat.bv_val );
2013 #ifdef SLAPD_ACI_ENABLED
2014 if ( b->a_aci_at != NULL ) {
2015 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
2019 /* Security Strength Factors */
2020 if ( b->a_authz.sai_ssf ) {
2021 fprintf( stderr, " ssf=%u",
2022 b->a_authz.sai_ssf );
2024 if ( b->a_authz.sai_transport_ssf ) {
2025 fprintf( stderr, " transport_ssf=%u",
2026 b->a_authz.sai_transport_ssf );
2028 if ( b->a_authz.sai_tls_ssf ) {
2029 fprintf( stderr, " tls_ssf=%u",
2030 b->a_authz.sai_tls_ssf );
2032 if ( b->a_authz.sai_sasl_ssf ) {
2033 fprintf( stderr, " sasl_ssf=%u",
2034 b->a_authz.sai_sasl_ssf );
2037 fprintf( stderr, " %s%s",
2038 b->a_dn_self ? "self" : "",
2039 accessmask2str( b->a_access_mask, maskbuf ) );
2041 if( b->a_type == ACL_BREAK ) {
2042 fprintf( stderr, " break" );
2044 } else if( b->a_type == ACL_CONTINUE ) {
2045 fprintf( stderr, " continue" );
2047 } else if( b->a_type != ACL_STOP ) {
2048 fprintf( stderr, " unknown-control" );
2051 fprintf( stderr, "\n" );
2056 print_acl( Backend *be, AccessControl *a )
2061 fprintf( stderr, "%s ACL: access to",
2062 be == NULL ? "Global" : "Backend" );
2064 if ( a->acl_dn_pat.bv_len != 0 ) {
2066 fprintf( stderr, " dn.%s=\"%s\"\n",
2067 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
2070 if ( a->acl_filter != NULL ) {
2071 struct berval bv = BER_BVNULL;
2073 filter2bv( a->acl_filter, &bv );
2074 fprintf( stderr, " filter=%s\n", bv.bv_val );
2075 ch_free( bv.bv_val );
2078 if ( a->acl_attrs != NULL ) {
2083 fprintf( stderr, " attrs=" );
2084 for ( an = a->acl_attrs; an && an->an_name.bv_val; an++ ) {
2085 if ( ! first ) fprintf( stderr, "," );
2087 fputc( an->an_oc_exclude ? '!' : '@', stderr);
2089 fputs( an->an_name.bv_val, stderr );
2092 fprintf( stderr, "\n" );
2095 if ( a->acl_attrval.bv_len != 0 ) {
2097 fprintf( stderr, " val.%s=\"%s\"\n",
2098 style_strings[a->acl_attrval_style], a->acl_attrval.bv_val );
2102 if( !to ) fprintf( stderr, " *\n" );
2104 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
2108 fprintf( stderr, "\n" );
2110 #endif /* LDAP_DEBUG */