1 /* aclparse.c - routines to parse and check acl's */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
14 #include <ac/socket.h>
15 #include <ac/string.h>
16 #include <ac/unistd.h>
21 static void split(char *line, int splitchar, char **left, char **right);
22 static void access_append(Access **l, Access *a);
23 static void acl_usage(void) LDAP_GCCATTR((noreturn));
25 static void acl_regex_normalized_dn(struct berval *pattern);
28 static void print_acl(Backend *be, AccessControl *a);
29 static void print_access(Access *b);
33 regtest(const char *fname, int lineno, char *pat) {
49 for (size = 0, flag = 0; (size < sizeof(buf)) && *sp; sp++) {
51 if (*sp == '$'|| (*sp >= '0' && *sp <= '9')) {
68 if ( size >= (sizeof(buf)-1) ) {
70 "%s: line %d: regular expression \"%s\" too large\n",
75 if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
77 regerror(e, &re, error, sizeof(error));
79 "%s: line %d: regular expression \"%s\" bad because of %s\n",
80 fname, lineno, pat, error );
98 char *left, *right, *style;
106 for ( i = 1; i < argc; i++ ) {
107 /* to clause - select which entries are protected */
108 if ( strcasecmp( argv[i], "to" ) == 0 ) {
111 "%s: line %d: only one to clause allowed in access line\n",
115 a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
116 for ( ++i; i < argc; i++ ) {
117 if ( strcasecmp( argv[i], "by" ) == 0 ) {
122 if ( strcasecmp( argv[i], "*" ) == 0 ) {
123 if( a->acl_dn_pat.bv_len != 0 ) {
125 "%s: line %d: dn pattern"
126 " already specified in to clause.\n",
131 a->acl_dn_pat.bv_val = ch_strdup( "*" );
132 a->acl_dn_pat.bv_len = 1;
136 split( argv[i], '=', &left, &right );
137 split( left, '.', &left, &style );
139 if ( right == NULL ) {
141 "%s: line %d: missing \"=\" in \"%s\" in to clause\n",
142 fname, lineno, left );
146 if ( strcasecmp( left, "dn" ) == 0 ) {
147 if( a->acl_dn_pat.bv_len != 0 ) {
149 "%s: line %d: dn pattern"
150 " already specified in to clause.\n",
155 if ( style == NULL || *style == '\0'
156 || strcasecmp( style, "regex" ) == 0 )
158 a->acl_dn_style = ACL_STYLE_REGEX;
160 if ( *right == '\0' ) {
161 /* empty regex should match empty DN */
162 a->acl_dn_style = ACL_STYLE_BASE;
163 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
165 } else if ( strcmp(right, "*") == 0
166 || strcmp(right, ".*") == 0
167 || strcmp(right, ".*$") == 0
168 || strcmp(right, "^.*") == 0
169 || strcmp(right, "^.*$$") == 0
170 || strcmp(right, ".*$$") == 0
171 || strcmp(right, "^.*$$") == 0 )
173 a->acl_dn_pat.bv_val = ch_strdup( "*" );
174 a->acl_dn_pat.bv_len = sizeof("*")-1;
177 a->acl_dn_pat.bv_val = right;
178 acl_regex_normalized_dn( &a->acl_dn_pat );
180 } else if ( strcasecmp( style, "base" ) == 0 ) {
181 a->acl_dn_style = ACL_STYLE_BASE;
182 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
183 } else if ( strcasecmp( style, "one" ) == 0 ) {
184 a->acl_dn_style = ACL_STYLE_ONE;
185 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
186 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
187 a->acl_dn_style = ACL_STYLE_SUBTREE;
188 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
189 } else if ( strcasecmp( style, "children" ) == 0 ) {
190 a->acl_dn_style = ACL_STYLE_CHILDREN;
191 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
194 "%s: line %d: unknown dn style \"%s\" in to clause\n",
195 fname, lineno, style );
202 if ( strcasecmp( left, "filter" ) == 0 ) {
203 if ( (a->acl_filter = str2filter(
206 "%s: line %d: bad filter \"%s\" in to clause\n",
207 fname, lineno, right );
211 } else if ( strncasecmp( left, "attr", 4 ) == 0 ) {
212 a->acl_attrs = str2anlist( a->acl_attrs,
214 if ( a->acl_attrs == NULL ) {
216 "%s: line %d: unknown attr \"%s\" in to clause\n",
217 fname, lineno, right );
222 "%s: line %d: expecting <what> got \"%s\"\n",
223 fname, lineno, left );
228 if ( a->acl_dn_pat.bv_len != 0 &&
229 strcmp(a->acl_dn_pat.bv_val, "*") == 0)
231 free( a->acl_dn_pat.bv_val );
232 a->acl_dn_pat.bv_val = NULL;
233 a->acl_dn_pat.bv_len = 0;
236 if( a->acl_dn_pat.bv_len != 0 ) {
237 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
239 dnNormalize2( NULL, &a->acl_dn_pat, &bv);
240 free( a->acl_dn_pat.bv_val );
243 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
244 REG_EXTENDED | REG_ICASE );
247 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
248 fprintf( stderr, "%s: line %d: "
249 "regular expression \"%s\" bad because of %s\n",
250 fname, lineno, right, buf );
256 /* by clause - select who has what access to entries */
257 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
260 "%s: line %d: to clause required before by clause in access line\n",
266 * by clause consists of <who> and <access>
269 b = (Access *) ch_calloc( 1, sizeof(Access) );
271 ACL_INVALIDATE( b->a_access_mask );
275 "%s: line %d: premature eol: expecting <who>\n",
281 for ( ; i < argc; i++ ) {
282 slap_style_t sty = ACL_STYLE_REGEX;
283 char *style_modifier = NULL;
286 split( argv[i], '=', &left, &right );
287 split( left, '.', &left, &style );
289 split( style, ',', &style, &style_modifier);
291 if ( style == NULL || *style == '\0'
292 || strcasecmp( style, "regex" ) == 0 )
294 sty = ACL_STYLE_REGEX;
295 } else if ( strcasecmp( style, "exact" ) == 0 ) {
296 sty = ACL_STYLE_EXACT;
297 } else if ( strcasecmp( style, "base" ) == 0 ) {
298 sty = ACL_STYLE_BASE;
299 } else if ( strcasecmp( style, "one" ) == 0 ) {
301 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
302 sty = ACL_STYLE_SUBTREE;
303 } else if ( strcasecmp( style, "children" ) == 0 ) {
304 sty = ACL_STYLE_CHILDREN;
307 "%s: line %d: unknown style \"%s\" in by clause\n",
308 fname, lineno, style );
312 if ( style_modifier && strcasecmp( style_modifier, "expand" ) == 0 ) {
316 if ( strcasecmp( argv[i], "*" ) == 0 ) {
317 bv.bv_val = ch_strdup( "*" );
320 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
321 ber_str2bv("anonymous",
322 sizeof("anonymous")-1,
325 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
330 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
335 } else if ( strcasecmp( left, "dn" ) == 0 ) {
336 if ( sty == ACL_STYLE_REGEX ) {
337 b->a_dn_style = ACL_STYLE_REGEX;
338 if( right == NULL ) {
343 } else if (*right == '\0' ) {
345 ber_str2bv("anonymous",
346 sizeof("anonymous")-1,
348 } else if ( strcmp( right, "*" ) == 0 ) {
350 /* any or users? users for now */
354 } else if ( strcmp( right, ".+" ) == 0
355 || strcmp( right, "^.+" ) == 0
356 || strcmp( right, ".+$" ) == 0
357 || strcmp( right, "^.+$" ) == 0
358 || strcmp( right, ".+$$" ) == 0
359 || strcmp( right, "^.+$$" ) == 0 )
364 } else if ( strcmp( right, ".*" ) == 0
365 || strcmp( right, "^.*" ) == 0
366 || strcmp( right, ".*$" ) == 0
367 || strcmp( right, "^.*$" ) == 0
368 || strcmp( right, ".*$$" ) == 0
369 || strcmp( right, "^.*$$" ) == 0 )
377 acl_regex_normalized_dn( &bv );
378 if ( !ber_bvccmp( &bv, '*' ) ) {
379 regtest(fname, lineno, bv.bv_val);
382 } else if ( right == NULL || *right == '\0' ) {
384 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
385 fname, lineno, left );
389 ber_str2bv( right, 0, 1, &bv );
396 if( bv.bv_val != NULL ) {
397 if( b->a_dn_pat.bv_len != 0 ) {
399 "%s: line %d: dn pattern already specified.\n",
404 if ( sty != ACL_STYLE_REGEX && expand == 0 ) {
405 dnNormalize2(NULL, &bv, &b->a_dn_pat);
411 b->a_dn_expand = expand;
415 if ( strcasecmp( left, "dnattr" ) == 0 ) {
416 if ( right == NULL || right[ 0 ] == '\0' ) {
418 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
419 fname, lineno, left );
423 if( b->a_dn_at != NULL ) {
425 "%s: line %d: dnattr already specified.\n",
430 rc = slap_str2ad( right, &b->a_dn_at, &text );
432 if( rc != LDAP_SUCCESS ) {
434 "%s: line %d: dnattr \"%s\": %s\n",
435 fname, lineno, right, text );
440 if( !is_at_syntax( b->a_dn_at->ad_type,
442 !is_at_syntax( b->a_dn_at->ad_type,
443 SLAPD_NAMEUID_SYNTAX ))
446 "%s: line %d: dnattr \"%s\": "
447 "inappropriate syntax: %s\n",
448 fname, lineno, right,
449 b->a_dn_at->ad_type->sat_syntax_oid );
456 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
460 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
462 "%s: line %d: inappropriate style \"%s\" in by clause\n",
463 fname, lineno, style );
467 if ( right == NULL || right[ 0 ] == '\0' ) {
469 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
470 fname, lineno, left );
474 if( b->a_group_pat.bv_len ) {
476 "%s: line %d: group pattern already specified.\n",
481 /* format of string is "group/objectClassValue/groupAttrName" */
482 if ((value = strchr(left, '/')) != NULL) {
485 && (name = strchr(value, '/')) != NULL)
491 b->a_group_style = sty;
492 if (sty == ACL_STYLE_REGEX) {
494 acl_regex_normalized_dn( &bv );
495 if ( !ber_bvccmp( &bv, '*' ) ) {
496 regtest(fname, lineno, bv.bv_val);
500 ber_str2bv( right, 0, 0, &bv );
501 dnNormalize2( NULL, &bv, &b->a_group_pat );
504 if (value && *value) {
505 b->a_group_oc = oc_find( value );
508 if( b->a_group_oc == NULL ) {
510 "%s: line %d: group objectclass "
512 fname, lineno, value );
516 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
518 if( b->a_group_oc == NULL ) {
520 "%s: line %d: group default objectclass "
522 fname, lineno, SLAPD_GROUP_CLASS );
527 if( is_object_subclass( slap_schema.si_oc_referral,
531 "%s: line %d: group objectclass \"%s\" "
532 "is subclass of referral\n",
533 fname, lineno, value );
537 if( is_object_subclass( slap_schema.si_oc_alias,
541 "%s: line %d: group objectclass \"%s\" "
542 "is subclass of alias\n",
543 fname, lineno, value );
548 rc = slap_str2ad( name, &b->a_group_at, &text );
550 if( rc != LDAP_SUCCESS ) {
552 "%s: line %d: group \"%s\": %s\n",
553 fname, lineno, right, text );
558 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
560 if( rc != LDAP_SUCCESS ) {
562 "%s: line %d: group \"%s\": %s\n",
563 fname, lineno, SLAPD_GROUP_ATTR, text );
568 if( !is_at_syntax( b->a_group_at->ad_type,
570 !is_at_syntax( b->a_group_at->ad_type,
571 SLAPD_NAMEUID_SYNTAX ) )
574 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
575 fname, lineno, right,
576 b->a_group_at->ad_type->sat_syntax_oid );
583 struct berval vals[2];
585 vals[0].bv_val = b->a_group_oc->soc_oid;
586 vals[0].bv_len = strlen(vals[0].bv_val);
587 vals[1].bv_val = NULL;
590 rc = oc_check_allowed( b->a_group_at->ad_type, vals, NULL );
594 "%s: line %d: group: \"%s\" not allowed by \"%s\"\n",
596 b->a_group_at->ad_cname.bv_val,
597 b->a_group_oc->soc_oid );
604 if ( strcasecmp( left, "peername" ) == 0 ) {
605 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
607 "%s: line %d: inappropriate style \"%s\" in by clause\n",
608 fname, lineno, style );
612 if ( right == NULL || right[ 0 ] == '\0' ) {
614 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
615 fname, lineno, left );
619 if( b->a_peername_pat.bv_len ) {
621 "%s: line %d: peername pattern already specified.\n",
626 b->a_peername_style = sty;
627 if (sty == ACL_STYLE_REGEX) {
629 acl_regex_normalized_dn( &bv );
630 if ( !ber_bvccmp( &bv, '*' ) ) {
631 regtest(fname, lineno, bv.bv_val);
633 b->a_peername_pat = bv;
635 ber_str2bv( right, 0, 1, &b->a_peername_pat );
640 if ( strcasecmp( left, "sockname" ) == 0 ) {
641 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
643 "%s: line %d: inappropriate style \"%s\" in by clause\n",
644 fname, lineno, style );
648 if ( right == NULL || right[ 0 ] == '\0' ) {
650 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
651 fname, lineno, left );
655 if( b->a_sockname_pat.bv_len ) {
657 "%s: line %d: sockname pattern already specified.\n",
662 b->a_sockname_style = sty;
663 if (sty == ACL_STYLE_REGEX) {
665 acl_regex_normalized_dn( &bv );
666 if ( !ber_bvccmp( &bv, '*' ) ) {
667 regtest(fname, lineno, bv.bv_val);
669 b->a_sockname_pat = bv;
671 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
676 if ( strcasecmp( left, "domain" ) == 0 ) {
678 case ACL_STYLE_REGEX:
680 case ACL_STYLE_SUBTREE:
685 "%s: line %d: inappropriate style \"%s\" in by clause\n",
686 fname, lineno, style );
690 if ( right == NULL || right[ 0 ] == '\0' ) {
692 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
693 fname, lineno, left );
697 if( b->a_domain_pat.bv_len ) {
699 "%s: line %d: domain pattern already specified.\n",
704 b->a_domain_style = sty;
705 b->a_domain_expand = expand;
706 if (sty == ACL_STYLE_REGEX) {
708 acl_regex_normalized_dn( &bv );
709 if ( !ber_bvccmp( &bv, '*' ) ) {
710 regtest(fname, lineno, bv.bv_val);
712 b->a_domain_pat = bv;
714 ber_str2bv( right, 0, 1, &b->a_domain_pat );
719 if ( strcasecmp( left, "sockurl" ) == 0 ) {
720 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
722 "%s: line %d: inappropriate style \"%s\" in by clause\n",
723 fname, lineno, style );
727 if ( right == NULL || right[ 0 ] == '\0' ) {
729 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
730 fname, lineno, left );
734 if( b->a_sockurl_pat.bv_len ) {
736 "%s: line %d: sockurl pattern already specified.\n",
741 b->a_sockurl_style = sty;
742 if (sty == ACL_STYLE_REGEX) {
744 acl_regex_normalized_dn( &bv );
745 if ( !ber_bvccmp( &bv, '*' ) ) {
746 regtest(fname, lineno, bv.bv_val);
748 b->a_sockurl_pat = bv;
750 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
755 if ( strcasecmp( left, "set" ) == 0 ) {
756 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
758 "%s: line %d: inappropriate style \"%s\" in by clause\n",
759 fname, lineno, style );
763 if( b->a_set_pat.bv_len != 0 ) {
765 "%s: line %d: set attribute already specified.\n",
770 if ( right == NULL || *right == '\0' ) {
772 "%s: line %d: no set is defined\n",
777 b->a_set_style = sty;
778 ber_str2bv( right, 0, 1, &b->a_set_pat );
783 #ifdef SLAPD_ACI_ENABLED
784 if ( strcasecmp( left, "aci" ) == 0 ) {
785 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
787 "%s: line %d: inappropriate style \"%s\" in by clause\n",
788 fname, lineno, style );
792 if( b->a_aci_at != NULL ) {
794 "%s: line %d: aci attribute already specified.\n",
799 if ( right != NULL && *right != '\0' ) {
800 rc = slap_str2ad( right, &b->a_aci_at, &text );
802 if( rc != LDAP_SUCCESS ) {
804 "%s: line %d: aci \"%s\": %s\n",
805 fname, lineno, right, text );
810 b->a_aci_at = slap_schema.si_ad_aci;
813 if( !is_at_syntax( b->a_aci_at->ad_type,
817 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
818 fname, lineno, right,
819 b->a_aci_at->ad_type->sat_syntax_oid );
825 #endif /* SLAPD_ACI_ENABLED */
827 if ( strcasecmp( left, "ssf" ) == 0 ) {
828 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
830 "%s: line %d: inappropriate style \"%s\" in by clause\n",
831 fname, lineno, style );
835 if( b->a_authz.sai_ssf ) {
837 "%s: line %d: ssf attribute already specified.\n",
842 if ( right == NULL || *right == '\0' ) {
844 "%s: line %d: no ssf is defined\n",
849 b->a_authz.sai_ssf = atoi( right );
851 if( !b->a_authz.sai_ssf ) {
853 "%s: line %d: invalid ssf value (%s)\n",
854 fname, lineno, right );
860 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
861 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
863 "%s: line %d: inappropriate style \"%s\" in by clause\n",
864 fname, lineno, style );
868 if( b->a_authz.sai_transport_ssf ) {
870 "%s: line %d: transport_ssf attribute already specified.\n",
875 if ( right == NULL || *right == '\0' ) {
877 "%s: line %d: no transport_ssf is defined\n",
882 b->a_authz.sai_transport_ssf = atoi( right );
884 if( !b->a_authz.sai_transport_ssf ) {
886 "%s: line %d: invalid transport_ssf value (%s)\n",
887 fname, lineno, right );
893 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
894 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
896 "%s: line %d: inappropriate style \"%s\" in by clause\n",
897 fname, lineno, style );
901 if( b->a_authz.sai_tls_ssf ) {
903 "%s: line %d: tls_ssf attribute already specified.\n",
908 if ( right == NULL || *right == '\0' ) {
910 "%s: line %d: no tls_ssf is defined\n",
915 b->a_authz.sai_tls_ssf = atoi( right );
917 if( !b->a_authz.sai_tls_ssf ) {
919 "%s: line %d: invalid tls_ssf value (%s)\n",
920 fname, lineno, right );
926 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
927 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
929 "%s: line %d: inappropriate style \"%s\" in by clause\n",
930 fname, lineno, style );
934 if( b->a_authz.sai_sasl_ssf ) {
936 "%s: line %d: sasl_ssf attribute already specified.\n",
941 if ( right == NULL || *right == '\0' ) {
943 "%s: line %d: no sasl_ssf is defined\n",
948 b->a_authz.sai_sasl_ssf = atoi( right );
950 if( !b->a_authz.sai_sasl_ssf ) {
952 "%s: line %d: invalid sasl_ssf value (%s)\n",
953 fname, lineno, right );
959 if( right != NULL ) {
966 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
967 /* out of arguments or plain stop */
969 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
970 b->a_type = ACL_STOP;
972 access_append( &a->acl_access, b );
976 if( strcasecmp( left, "continue" ) == 0 ) {
979 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
980 b->a_type = ACL_CONTINUE;
982 access_append( &a->acl_access, b );
986 if( strcasecmp( left, "break" ) == 0 ) {
989 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
990 b->a_type = ACL_BREAK;
992 access_append( &a->acl_access, b );
996 if ( strcasecmp( left, "by" ) == 0 ) {
997 /* we've gone too far */
999 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1000 b->a_type = ACL_STOP;
1002 access_append( &a->acl_access, b );
1007 if( strncasecmp( left, "self", 4 ) == 0 ) {
1009 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
1012 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1015 if( ACL_IS_INVALID( b->a_access_mask ) ) {
1017 "%s: line %d: expecting <access> got \"%s\"\n",
1018 fname, lineno, left );
1022 b->a_type = ACL_STOP;
1025 /* out of arguments or plain stop */
1026 access_append( &a->acl_access, b );
1030 if( strcasecmp( argv[i], "continue" ) == 0 ) {
1031 /* plain continue */
1032 b->a_type = ACL_CONTINUE;
1034 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
1035 /* plain continue */
1036 b->a_type = ACL_BREAK;
1038 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1043 access_append( &a->acl_access, b );
1047 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
1048 fname, lineno, argv[i] );
1053 /* if we have no real access clause, complain and do nothing */
1056 "%s: line %d: warning: no access clause(s) specified in access line\n",
1061 if (ldap_debug & LDAP_DEBUG_ACL)
1065 if ( a->acl_access == NULL ) {
1067 "%s: line %d: warning: no by clause(s) specified in access line\n",
1072 acl_append( &be->be_acl, a );
1074 acl_append( &global_acl, a );
1080 accessmask2str( slap_mask_t mask, char *buf )
1085 assert( buf != NULL );
1087 if ( ACL_IS_INVALID( mask ) ) {
1093 if ( ACL_IS_LEVEL( mask ) ) {
1094 if ( ACL_LVL_IS_NONE(mask) ) {
1095 ptr = slap_strcopy( ptr, "none" );
1097 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1098 ptr = slap_strcopy( ptr, "auth" );
1100 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1101 ptr = slap_strcopy( ptr, "compare" );
1103 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1104 ptr = slap_strcopy( ptr, "search" );
1106 } else if ( ACL_LVL_IS_READ(mask) ) {
1107 ptr = slap_strcopy( ptr, "read" );
1109 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1110 ptr = slap_strcopy( ptr, "write" );
1112 ptr = slap_strcopy( ptr, "unknown" );
1118 if( ACL_IS_ADDITIVE( mask ) ) {
1121 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1128 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1133 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1138 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1143 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1148 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1153 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1162 if ( ACL_IS_LEVEL( mask ) ) {
1172 str2accessmask( const char *str )
1176 if( !ASCII_ALPHA(str[0]) ) {
1179 if ( str[0] == '=' ) {
1182 } else if( str[0] == '+' ) {
1183 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1185 } else if( str[0] == '-' ) {
1186 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1189 ACL_INVALIDATE(mask);
1193 for( i=1; str[i] != '\0'; i++ ) {
1194 if( TOLOWER(str[i]) == 'w' ) {
1195 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1197 } else if( TOLOWER(str[i]) == 'r' ) {
1198 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1200 } else if( TOLOWER(str[i]) == 's' ) {
1201 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1203 } else if( TOLOWER(str[i]) == 'c' ) {
1204 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1206 } else if( TOLOWER(str[i]) == 'x' ) {
1207 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1209 } else if( str[i] != '0' ) {
1210 ACL_INVALIDATE(mask);
1218 if ( strcasecmp( str, "none" ) == 0 ) {
1219 ACL_LVL_ASSIGN_NONE(mask);
1221 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1222 ACL_LVL_ASSIGN_AUTH(mask);
1224 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1225 ACL_LVL_ASSIGN_COMPARE(mask);
1227 } else if ( strcasecmp( str, "search" ) == 0 ) {
1228 ACL_LVL_ASSIGN_SEARCH(mask);
1230 } else if ( strcasecmp( str, "read" ) == 0 ) {
1231 ACL_LVL_ASSIGN_READ(mask);
1233 } else if ( strcasecmp( str, "write" ) == 0 ) {
1234 ACL_LVL_ASSIGN_WRITE(mask);
1237 ACL_INVALIDATE( mask );
1246 fprintf( stderr, "\n"
1247 "<access clause> ::= access to <what> "
1248 "[ by <who> <access> [ <control> ] ]+ \n"
1249 "<what> ::= * | [dn[.<dnstyle>]=<regex>] [filter=<ldapfilter>] [attrs=<attrlist>]\n"
1250 "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
1251 "<attr> ::= <attrname> | entry | children\n"
1252 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<regex> ]\n"
1253 "\t[dnattr=<attrname>]\n"
1254 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<regex>]\n"
1255 "\t[peername[.<style>]=<regex>] [sockname[.<style>]=<regex>]\n"
1256 "\t[domain[.<style>]=<regex>] [sockurl[.<style>]=<regex>]\n"
1257 #ifdef SLAPD_ACI_ENABLED
1258 "\t[aci=<attrname>]\n"
1260 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1261 "<dnstyle> ::= regex | base | exact (alias of base) | one | sub | children\n"
1262 "<style> ::= regex | base | exact (alias of base)\n"
1263 "<groupflags> ::= R\n"
1264 "<access> ::= [self]{<level>|<priv>}\n"
1265 "<level> ::= none | auth | compare | search | read | write\n"
1266 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
1267 "<control> ::= [ stop | continue | break ]\n"
1269 exit( EXIT_FAILURE );
1273 * At present it simply eats the (optional) space after
1274 * a RDN separator (,)
1275 * Eventually will evolve in a more complete normalization
1277 * Note that the input berval only needs bv_val, it ignores
1278 * the input bv_len and sets it on return.
1281 acl_regex_normalized_dn(
1282 struct berval *pattern
1287 str = ch_strdup( pattern->bv_val );
1289 for ( p = str; p && p[ 0 ]; p++ ) {
1291 if ( p[ 0 ] == '\\' ) {
1293 * if escaping a hex pair we should
1294 * increment p twice; however, in that
1295 * case the second hex number does
1301 if ( p[ 0 ] == ',' ) {
1302 if ( p[ 1 ] == ' ' ) {
1306 * too much space should be
1307 * an error if we are pedantic
1309 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1312 AC_MEMCPY( p+1, q, pattern->bv_len-(q-str)+1);
1316 pattern->bv_val = str;
1317 pattern->bv_len = p-str;
1331 if ( (*right = strchr( line, splitchar )) != NULL ) {
1332 *((*right)++) = '\0';
1337 access_append( Access **l, Access *a )
1339 for ( ; *l != NULL; l = &(*l)->a_next )
1346 acl_append( AccessControl **l, AccessControl *a )
1348 for ( ; *l != NULL; l = &(*l)->acl_next )
1355 access_free( Access *a )
1357 if ( a->a_dn_pat.bv_val )
1358 free ( a->a_dn_pat.bv_val );
1359 if ( a->a_peername_pat.bv_val )
1360 free ( a->a_peername_pat.bv_val );
1361 if ( a->a_sockname_pat.bv_val )
1362 free ( a->a_sockname_pat.bv_val );
1363 if ( a->a_domain_pat.bv_val )
1364 free ( a->a_domain_pat.bv_val );
1365 if ( a->a_sockurl_pat.bv_val )
1366 free ( a->a_sockurl_pat.bv_val );
1367 if ( a->a_set_pat.bv_len )
1368 free ( a->a_set_pat.bv_val );
1369 if ( a->a_group_pat.bv_len )
1370 free ( a->a_group_pat.bv_val );
1375 acl_free( AccessControl *a )
1380 if ( a->acl_filter )
1381 filter_free( a->acl_filter );
1382 if ( a->acl_dn_pat.bv_len )
1383 free ( a->acl_dn_pat.bv_val );
1384 if ( a->acl_attrs ) {
1385 for ( an = a->acl_attrs; an->an_name.bv_val; an++ ) {
1386 free( an->an_name.bv_val );
1388 free( a->acl_attrs );
1390 for (; a->acl_access; a->acl_access = n) {
1391 n = a->acl_access->a_next;
1392 access_free( a->acl_access );
1397 /* Because backend_startup uses acl_append to tack on the global_acl to
1398 * the end of each backend's acl, we cannot just take one argument and
1399 * merrily free our way to the end of the list. backend_destroy calls us
1400 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1401 * point. config_destroy calls us with global_acl in arg1 and NULL in
1402 * arg2, so we then proceed to polish off the global_acl.
1405 acl_destroy( AccessControl *a, AccessControl *end )
1409 for (; a && a!= end; a=n) {
1416 access2str( slap_access_t access )
1418 if ( access == ACL_NONE ) {
1421 } else if ( access == ACL_AUTH ) {
1424 } else if ( access == ACL_COMPARE ) {
1427 } else if ( access == ACL_SEARCH ) {
1430 } else if ( access == ACL_READ ) {
1433 } else if ( access == ACL_WRITE ) {
1441 str2access( const char *str )
1443 if ( strcasecmp( str, "none" ) == 0 ) {
1446 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1449 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1452 } else if ( strcasecmp( str, "search" ) == 0 ) {
1455 } else if ( strcasecmp( str, "read" ) == 0 ) {
1458 } else if ( strcasecmp( str, "write" ) == 0 ) {
1462 return( ACL_INVALID_ACCESS );
1467 static char *style_strings[5] = {
1477 print_access( Access *b )
1479 char maskbuf[ACCESSMASK_MAXLEN];
1481 fprintf( stderr, "\tby" );
1483 if ( b->a_dn_pat.bv_len != 0 ) {
1484 if( strcmp(b->a_dn_pat.bv_val, "*") == 0
1485 || strcmp(b->a_dn_pat.bv_val, "users") == 0
1486 || strcmp(b->a_dn_pat.bv_val, "anonymous") == 0
1487 || strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1489 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1492 fprintf( stderr, " dn.%s=%s",
1493 style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1497 if ( b->a_dn_at != NULL ) {
1498 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1501 if ( b->a_group_pat.bv_len ) {
1502 fprintf( stderr, " group=%s", b->a_group_pat.bv_val );
1504 if ( b->a_group_oc ) {
1505 fprintf( stderr, " objectClass: %s",
1506 b->a_group_oc->soc_oclass.oc_oid );
1508 if ( b->a_group_at ) {
1509 fprintf( stderr, " attributeType: %s", b->a_group_at->ad_cname.bv_val );
1514 if ( b->a_peername_pat.bv_len != 0 ) {
1515 fprintf( stderr, " peername=%s", b->a_peername_pat.bv_val );
1518 if ( b->a_sockname_pat.bv_len != 0 ) {
1519 fprintf( stderr, " sockname=%s", b->a_sockname_pat.bv_val );
1522 if ( b->a_domain_pat.bv_len != 0 ) {
1523 fprintf( stderr, " domain=%s", b->a_domain_pat.bv_val );
1526 if ( b->a_sockurl_pat.bv_len != 0 ) {
1527 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat.bv_val );
1530 #ifdef SLAPD_ACI_ENABLED
1531 if ( b->a_aci_at != NULL ) {
1532 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1536 /* Security Strength Factors */
1537 if ( b->a_authz.sai_ssf ) {
1538 fprintf( stderr, " ssf=%u",
1539 b->a_authz.sai_ssf );
1541 if ( b->a_authz.sai_transport_ssf ) {
1542 fprintf( stderr, " transport_ssf=%u",
1543 b->a_authz.sai_transport_ssf );
1545 if ( b->a_authz.sai_tls_ssf ) {
1546 fprintf( stderr, " tls_ssf=%u",
1547 b->a_authz.sai_tls_ssf );
1549 if ( b->a_authz.sai_sasl_ssf ) {
1550 fprintf( stderr, " sasl_ssf=%u",
1551 b->a_authz.sai_sasl_ssf );
1554 fprintf( stderr, " %s%s",
1555 b->a_dn_self ? "self" : "",
1556 accessmask2str( b->a_access_mask, maskbuf ) );
1558 if( b->a_type == ACL_BREAK ) {
1559 fprintf( stderr, " break" );
1561 } else if( b->a_type == ACL_CONTINUE ) {
1562 fprintf( stderr, " continue" );
1564 } else if( b->a_type != ACL_STOP ) {
1565 fprintf( stderr, " unknown-control" );
1568 fprintf( stderr, "\n" );
1573 print_acl( Backend *be, AccessControl *a )
1578 fprintf( stderr, "%s ACL: access to",
1579 be == NULL ? "Global" : "Backend" );
1581 if ( a->acl_dn_pat.bv_len != 0 ) {
1583 fprintf( stderr, " dn.%s=%s\n",
1584 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
1587 if ( a->acl_filter != NULL ) {
1588 struct berval bv = { 0, NULL };
1590 filter2bv( a->acl_filter, &bv );
1591 fprintf( stderr, " filter=%s\n", bv.bv_val );
1592 ch_free( bv.bv_val );
1595 if ( a->acl_attrs != NULL ) {
1600 fprintf( stderr, " attrs=" );
1601 for ( an = a->acl_attrs; an && an->an_name.bv_val; an++ ) {
1603 fprintf( stderr, "," );
1605 fputs( an->an_name.bv_val, stderr );
1608 fprintf( stderr, "\n" );
1612 fprintf( stderr, " *\n" );
1615 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1619 fprintf( stderr, "\n" );
1622 #endif /* LDAP_DEBUG */