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>
22 static void split(char *line, int splitchar, char **left, char **right);
23 static void access_append(Access **l, Access *a);
24 static void acl_usage(void) LDAP_GCCATTR((noreturn));
26 static void acl_regex_normalized_dn(const char *src, struct berval *pat);
29 static void print_acl(Backend *be, AccessControl *a);
30 static void print_access(Access *b);
34 regtest(const char *fname, int lineno, char *pat) {
50 for (size = 0, flag = 0; (size < sizeof(buf)) && *sp; sp++) {
52 if (*sp == '$'|| (*sp >= '0' && *sp <= '9')) {
69 if ( size >= (sizeof(buf)-1) ) {
71 "%s: line %d: regular expression \"%s\" too large\n",
76 if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
78 regerror(e, &re, error, sizeof(error));
80 "%s: line %d: regular expression \"%s\" bad because of %s\n",
81 fname, lineno, pat, error );
97 char *left, *right, *style;
105 for ( i = 1; i < argc; i++ ) {
106 /* to clause - select which entries are protected */
107 if ( strcasecmp( argv[i], "to" ) == 0 ) {
110 "%s: line %d: only one to clause allowed in access line\n",
114 a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
115 for ( ++i; i < argc; i++ ) {
116 if ( strcasecmp( argv[i], "by" ) == 0 ) {
121 if ( strcasecmp( argv[i], "*" ) == 0 ) {
122 if( a->acl_dn_pat.bv_len ||
123 ( a->acl_dn_style != ACL_STYLE_REGEX ) )
126 "%s: line %d: dn pattern"
127 " already specified in to clause.\n",
132 a->acl_dn_pat.bv_val = ch_strdup( "*" );
133 a->acl_dn_pat.bv_len = 1;
137 split( argv[i], '=', &left, &right );
138 split( left, '.', &left, &style );
140 if ( right == NULL ) {
142 "%s: line %d: missing \"=\" in \"%s\" in to clause\n",
143 fname, lineno, left );
147 if ( strcasecmp( left, "dn" ) == 0 ) {
148 if( a->acl_dn_pat.bv_len != 0 ||
149 ( a->acl_dn_style != ACL_STYLE_REGEX ) )
152 "%s: line %d: dn pattern"
153 " already specified in to clause.\n",
158 if ( style == NULL || *style == '\0'
159 || strcasecmp( style, "regex" ) == 0 )
161 a->acl_dn_style = ACL_STYLE_REGEX;
163 if ( *right == '\0' ) {
164 /* empty regex should match empty DN */
165 a->acl_dn_style = ACL_STYLE_BASE;
166 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
168 } else if ( strcmp(right, "*") == 0
169 || strcmp(right, ".*") == 0
170 || strcmp(right, ".*$") == 0
171 || strcmp(right, "^.*") == 0
172 || strcmp(right, "^.*$") == 0
173 || strcmp(right, ".*$$") == 0
174 || strcmp(right, "^.*$$") == 0 )
176 a->acl_dn_pat.bv_val = ch_strdup( "*" );
177 a->acl_dn_pat.bv_len = sizeof("*")-1;
180 acl_regex_normalized_dn( right, &a->acl_dn_pat );
182 } else if ( strcasecmp( style, "base" ) == 0 ) {
183 a->acl_dn_style = ACL_STYLE_BASE;
184 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
185 } else if ( strcasecmp( style, "one" ) == 0 ) {
186 a->acl_dn_style = ACL_STYLE_ONE;
187 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
188 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
189 a->acl_dn_style = ACL_STYLE_SUBTREE;
190 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
191 } else if ( strcasecmp( style, "children" ) == 0 ) {
192 a->acl_dn_style = ACL_STYLE_CHILDREN;
193 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
196 "%s: line %d: unknown dn style \"%s\" in to clause\n",
197 fname, lineno, style );
204 if ( strcasecmp( left, "filter" ) == 0 ) {
205 if ( (a->acl_filter = str2filter( right )) == NULL ) {
207 "%s: line %d: bad filter \"%s\" in to clause\n",
208 fname, lineno, right );
212 } else if ( strncasecmp( left, "attr", 4 ) == 0 ) {
213 a->acl_attrs = str2anlist( a->acl_attrs,
215 if ( a->acl_attrs == NULL ) {
217 "%s: line %d: unknown attr \"%s\" in to clause\n",
218 fname, lineno, right );
223 "%s: line %d: expecting <what> got \"%s\"\n",
224 fname, lineno, left );
229 if ( a->acl_dn_pat.bv_len != 0 &&
230 strcmp(a->acl_dn_pat.bv_val, "*") == 0 )
232 free( a->acl_dn_pat.bv_val );
233 a->acl_dn_pat.bv_val = NULL;
234 a->acl_dn_pat.bv_len = 0;
237 if( a->acl_dn_pat.bv_len != 0 ||
238 ( a->acl_dn_style != ACL_STYLE_REGEX ) )
240 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
242 rc = dnNormalize2( NULL, &a->acl_dn_pat, &bv);
243 if ( rc != LDAP_SUCCESS ) {
245 "%s: line %d: bad DN \"%s\"\n",
246 fname, lineno, a->acl_dn_pat.bv_val );
249 free( a->acl_dn_pat.bv_val );
252 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
253 REG_EXTENDED | REG_ICASE );
256 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
257 fprintf( stderr, "%s: line %d: "
258 "regular expression \"%s\" bad because of %s\n",
259 fname, lineno, right, buf );
265 /* by clause - select who has what access to entries */
266 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
269 "%s: line %d: to clause required before by clause in access line\n",
275 * by clause consists of <who> and <access>
278 b = (Access *) ch_calloc( 1, sizeof(Access) );
280 ACL_INVALIDATE( b->a_access_mask );
284 "%s: line %d: premature eol: expecting <who>\n",
290 for ( ; i < argc; i++ ) {
291 slap_style_t sty = ACL_STYLE_REGEX;
292 char *style_modifier = NULL;
295 split( argv[i], '=', &left, &right );
296 split( left, '.', &left, &style );
298 split( style, ',', &style, &style_modifier);
300 if ( style == NULL || *style == '\0'
301 || strcasecmp( style, "regex" ) == 0 )
303 sty = ACL_STYLE_REGEX;
304 } else if ( strcasecmp( style, "exact" ) == 0 ) {
305 sty = ACL_STYLE_EXACT;
306 } else if ( strcasecmp( style, "base" ) == 0 ) {
307 sty = ACL_STYLE_BASE;
308 } else if ( strcasecmp( style, "one" ) == 0 ) {
310 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
311 sty = ACL_STYLE_SUBTREE;
312 } else if ( strcasecmp( style, "children" ) == 0 ) {
313 sty = ACL_STYLE_CHILDREN;
316 "%s: line %d: unknown style \"%s\" in by clause\n",
317 fname, lineno, style );
321 if ( style_modifier && strcasecmp( style_modifier, "expand" ) == 0 ) {
325 if ( strcasecmp( argv[i], "*" ) == 0 ) {
326 bv.bv_val = ch_strdup( "*" );
329 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
330 ber_str2bv("anonymous",
331 sizeof("anonymous")-1,
334 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
339 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
344 } else if ( strcasecmp( left, "dn" ) == 0 ) {
345 if ( sty == ACL_STYLE_REGEX ) {
346 b->a_dn_style = ACL_STYLE_REGEX;
347 if( right == NULL ) {
352 } else if (*right == '\0' ) {
354 ber_str2bv("anonymous",
355 sizeof("anonymous")-1,
357 } else if ( strcmp( right, "*" ) == 0 ) {
359 /* any or users? users for now */
363 } else if ( strcmp( right, ".+" ) == 0
364 || strcmp( right, "^.+" ) == 0
365 || strcmp( right, ".+$" ) == 0
366 || strcmp( right, "^.+$" ) == 0
367 || strcmp( right, ".+$$" ) == 0
368 || strcmp( right, "^.+$$" ) == 0 )
373 } else if ( strcmp( right, ".*" ) == 0
374 || strcmp( right, "^.*" ) == 0
375 || strcmp( right, ".*$" ) == 0
376 || strcmp( right, "^.*$" ) == 0
377 || strcmp( right, ".*$$" ) == 0
378 || strcmp( right, "^.*$$" ) == 0 )
385 acl_regex_normalized_dn( right, &bv );
386 if ( !ber_bvccmp( &bv, '*' ) ) {
387 regtest(fname, lineno, bv.bv_val);
390 } else if ( right == NULL || *right == '\0' ) {
392 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
393 fname, lineno, left );
397 ber_str2bv( right, 0, 1, &bv );
404 if( bv.bv_val != NULL ) {
405 if( b->a_dn_pat.bv_len != 0 ) {
407 "%s: line %d: dn pattern already specified.\n",
412 if ( sty != ACL_STYLE_REGEX && expand == 0 ) {
413 rc = dnNormalize2(NULL, &bv, &b->a_dn_pat);
414 if ( rc != LDAP_SUCCESS ) {
416 "%s: line %d: bad DN \"%s\"\n",
417 fname, lineno, bv.bv_val );
425 b->a_dn_expand = expand;
429 if ( strcasecmp( left, "dnattr" ) == 0 ) {
430 if ( right == NULL || right[ 0 ] == '\0' ) {
432 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
433 fname, lineno, left );
437 if( b->a_dn_at != NULL ) {
439 "%s: line %d: dnattr already specified.\n",
444 rc = slap_str2ad( right, &b->a_dn_at, &text );
446 if( rc != LDAP_SUCCESS ) {
448 "%s: line %d: dnattr \"%s\": %s\n",
449 fname, lineno, right, text );
454 if( !is_at_syntax( b->a_dn_at->ad_type,
456 !is_at_syntax( b->a_dn_at->ad_type,
457 SLAPD_NAMEUID_SYNTAX ))
460 "%s: line %d: dnattr \"%s\": "
461 "inappropriate syntax: %s\n",
462 fname, lineno, right,
463 b->a_dn_at->ad_type->sat_syntax_oid );
470 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
474 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
476 "%s: line %d: inappropriate style \"%s\" in by clause\n",
477 fname, lineno, style );
481 if ( right == NULL || right[ 0 ] == '\0' ) {
483 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
484 fname, lineno, left );
488 if( b->a_group_pat.bv_len ) {
490 "%s: line %d: group pattern already specified.\n",
495 /* format of string is "group/objectClassValue/groupAttrName" */
496 if ((value = strchr(left, '/')) != NULL) {
499 && (name = strchr(value, '/')) != NULL)
505 b->a_group_style = sty;
506 if (sty == ACL_STYLE_REGEX) {
507 acl_regex_normalized_dn( right, &bv );
508 if ( !ber_bvccmp( &bv, '*' ) ) {
509 regtest(fname, lineno, bv.bv_val);
513 ber_str2bv( right, 0, 0, &bv );
514 rc = dnNormalize2( NULL, &bv, &b->a_group_pat );
515 if ( rc != LDAP_SUCCESS ) {
517 "%s: line %d: bad DN \"%s\"\n",
518 fname, lineno, right );
523 if (value && *value) {
524 b->a_group_oc = oc_find( value );
527 if( b->a_group_oc == NULL ) {
529 "%s: line %d: group objectclass "
531 fname, lineno, value );
535 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
537 if( b->a_group_oc == NULL ) {
539 "%s: line %d: group default objectclass "
541 fname, lineno, SLAPD_GROUP_CLASS );
546 if( is_object_subclass( slap_schema.si_oc_referral,
550 "%s: line %d: group objectclass \"%s\" "
551 "is subclass of referral\n",
552 fname, lineno, value );
556 if( is_object_subclass( slap_schema.si_oc_alias,
560 "%s: line %d: group objectclass \"%s\" "
561 "is subclass of alias\n",
562 fname, lineno, value );
567 rc = slap_str2ad( name, &b->a_group_at, &text );
569 if( rc != LDAP_SUCCESS ) {
571 "%s: line %d: group \"%s\": %s\n",
572 fname, lineno, right, text );
577 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
579 if( rc != LDAP_SUCCESS ) {
581 "%s: line %d: group \"%s\": %s\n",
582 fname, lineno, SLAPD_GROUP_ATTR, text );
587 if( !is_at_syntax( b->a_group_at->ad_type,
589 !is_at_syntax( b->a_group_at->ad_type,
590 SLAPD_NAMEUID_SYNTAX ) )
593 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
594 fname, lineno, right,
595 b->a_group_at->ad_type->sat_syntax_oid );
602 struct berval vals[2];
604 vals[0].bv_val = b->a_group_oc->soc_oid;
605 vals[0].bv_len = strlen(vals[0].bv_val);
606 vals[1].bv_val = NULL;
609 rc = oc_check_allowed( b->a_group_at->ad_type, vals, NULL );
613 "%s: line %d: group: \"%s\" not allowed by \"%s\"\n",
615 b->a_group_at->ad_cname.bv_val,
616 b->a_group_oc->soc_oid );
623 if ( strcasecmp( left, "peername" ) == 0 ) {
624 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
626 "%s: line %d: inappropriate style \"%s\" in by clause\n",
627 fname, lineno, style );
631 if ( right == NULL || right[ 0 ] == '\0' ) {
633 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
634 fname, lineno, left );
638 if( b->a_peername_pat.bv_len ) {
640 "%s: line %d: peername pattern already specified.\n",
645 b->a_peername_style = sty;
646 if (sty == ACL_STYLE_REGEX) {
647 acl_regex_normalized_dn( right, &bv );
648 if ( !ber_bvccmp( &bv, '*' ) ) {
649 regtest(fname, lineno, bv.bv_val);
651 b->a_peername_pat = bv;
653 ber_str2bv( right, 0, 1, &b->a_peername_pat );
658 if ( strcasecmp( left, "sockname" ) == 0 ) {
659 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
661 "%s: line %d: inappropriate style \"%s\" in by clause\n",
662 fname, lineno, style );
666 if ( right == NULL || right[ 0 ] == '\0' ) {
668 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
669 fname, lineno, left );
673 if( b->a_sockname_pat.bv_len ) {
675 "%s: line %d: sockname pattern already specified.\n",
680 b->a_sockname_style = sty;
681 if (sty == ACL_STYLE_REGEX) {
682 acl_regex_normalized_dn( right, &bv );
683 if ( !ber_bvccmp( &bv, '*' ) ) {
684 regtest(fname, lineno, bv.bv_val);
686 b->a_sockname_pat = bv;
688 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
693 if ( strcasecmp( left, "domain" ) == 0 ) {
695 case ACL_STYLE_REGEX:
697 case ACL_STYLE_SUBTREE:
702 "%s: line %d: inappropriate style \"%s\" in by clause\n",
703 fname, lineno, style );
707 if ( right == NULL || right[ 0 ] == '\0' ) {
709 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
710 fname, lineno, left );
714 if( b->a_domain_pat.bv_len ) {
716 "%s: line %d: domain pattern already specified.\n",
721 b->a_domain_style = sty;
722 b->a_domain_expand = expand;
723 if (sty == ACL_STYLE_REGEX) {
724 acl_regex_normalized_dn( right, &bv );
725 if ( !ber_bvccmp( &bv, '*' ) ) {
726 regtest(fname, lineno, bv.bv_val);
728 b->a_domain_pat = bv;
730 ber_str2bv( right, 0, 1, &b->a_domain_pat );
735 if ( strcasecmp( left, "sockurl" ) == 0 ) {
736 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
738 "%s: line %d: inappropriate style \"%s\" in by clause\n",
739 fname, lineno, style );
743 if ( right == NULL || right[ 0 ] == '\0' ) {
745 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
746 fname, lineno, left );
750 if( b->a_sockurl_pat.bv_len ) {
752 "%s: line %d: sockurl pattern already specified.\n",
757 b->a_sockurl_style = sty;
758 if (sty == ACL_STYLE_REGEX) {
759 acl_regex_normalized_dn( right, &bv );
760 if ( !ber_bvccmp( &bv, '*' ) ) {
761 regtest(fname, lineno, bv.bv_val);
763 b->a_sockurl_pat = bv;
765 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
770 if ( strcasecmp( left, "set" ) == 0 ) {
771 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
773 "%s: line %d: inappropriate style \"%s\" in by clause\n",
774 fname, lineno, style );
778 if( b->a_set_pat.bv_len != 0 ) {
780 "%s: line %d: set attribute already specified.\n",
785 if ( right == NULL || *right == '\0' ) {
787 "%s: line %d: no set is defined\n",
792 b->a_set_style = sty;
793 ber_str2bv( right, 0, 1, &b->a_set_pat );
798 #ifdef SLAPD_ACI_ENABLED
799 if ( strcasecmp( left, "aci" ) == 0 ) {
800 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
802 "%s: line %d: inappropriate style \"%s\" in by clause\n",
803 fname, lineno, style );
807 if( b->a_aci_at != NULL ) {
809 "%s: line %d: aci attribute already specified.\n",
814 if ( right != NULL && *right != '\0' ) {
815 rc = slap_str2ad( right, &b->a_aci_at, &text );
817 if( rc != LDAP_SUCCESS ) {
819 "%s: line %d: aci \"%s\": %s\n",
820 fname, lineno, right, text );
825 b->a_aci_at = slap_schema.si_ad_aci;
828 if( !is_at_syntax( b->a_aci_at->ad_type,
832 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
833 fname, lineno, right,
834 b->a_aci_at->ad_type->sat_syntax_oid );
840 #endif /* SLAPD_ACI_ENABLED */
842 if ( strcasecmp( left, "ssf" ) == 0 ) {
843 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
845 "%s: line %d: inappropriate style \"%s\" in by clause\n",
846 fname, lineno, style );
850 if( b->a_authz.sai_ssf ) {
852 "%s: line %d: ssf attribute already specified.\n",
857 if ( right == NULL || *right == '\0' ) {
859 "%s: line %d: no ssf is defined\n",
864 b->a_authz.sai_ssf = atoi( right );
866 if( !b->a_authz.sai_ssf ) {
868 "%s: line %d: invalid ssf value (%s)\n",
869 fname, lineno, right );
875 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
876 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
878 "%s: line %d: inappropriate style \"%s\" in by clause\n",
879 fname, lineno, style );
883 if( b->a_authz.sai_transport_ssf ) {
885 "%s: line %d: transport_ssf attribute already specified.\n",
890 if ( right == NULL || *right == '\0' ) {
892 "%s: line %d: no transport_ssf is defined\n",
897 b->a_authz.sai_transport_ssf = atoi( right );
899 if( !b->a_authz.sai_transport_ssf ) {
901 "%s: line %d: invalid transport_ssf value (%s)\n",
902 fname, lineno, right );
908 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
909 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
911 "%s: line %d: inappropriate style \"%s\" in by clause\n",
912 fname, lineno, style );
916 if( b->a_authz.sai_tls_ssf ) {
918 "%s: line %d: tls_ssf attribute already specified.\n",
923 if ( right == NULL || *right == '\0' ) {
925 "%s: line %d: no tls_ssf is defined\n",
930 b->a_authz.sai_tls_ssf = atoi( right );
932 if( !b->a_authz.sai_tls_ssf ) {
934 "%s: line %d: invalid tls_ssf value (%s)\n",
935 fname, lineno, right );
941 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
942 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
944 "%s: line %d: inappropriate style \"%s\" in by clause\n",
945 fname, lineno, style );
949 if( b->a_authz.sai_sasl_ssf ) {
951 "%s: line %d: sasl_ssf attribute already specified.\n",
956 if ( right == NULL || *right == '\0' ) {
958 "%s: line %d: no sasl_ssf is defined\n",
963 b->a_authz.sai_sasl_ssf = atoi( right );
965 if( !b->a_authz.sai_sasl_ssf ) {
967 "%s: line %d: invalid sasl_ssf value (%s)\n",
968 fname, lineno, right );
974 if( right != NULL ) {
981 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
982 /* out of arguments or plain stop */
984 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
985 b->a_type = ACL_STOP;
987 access_append( &a->acl_access, b );
991 if( strcasecmp( left, "continue" ) == 0 ) {
994 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
995 b->a_type = ACL_CONTINUE;
997 access_append( &a->acl_access, b );
1001 if( strcasecmp( left, "break" ) == 0 ) {
1002 /* plain continue */
1004 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1005 b->a_type = ACL_BREAK;
1007 access_append( &a->acl_access, b );
1011 if ( strcasecmp( left, "by" ) == 0 ) {
1012 /* we've gone too far */
1014 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1015 b->a_type = ACL_STOP;
1017 access_append( &a->acl_access, b );
1022 if( strncasecmp( left, "self", 4 ) == 0 ) {
1024 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
1027 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1030 if( ACL_IS_INVALID( b->a_access_mask ) ) {
1032 "%s: line %d: expecting <access> got \"%s\"\n",
1033 fname, lineno, left );
1037 b->a_type = ACL_STOP;
1040 /* out of arguments or plain stop */
1041 access_append( &a->acl_access, b );
1045 if( strcasecmp( argv[i], "continue" ) == 0 ) {
1046 /* plain continue */
1047 b->a_type = ACL_CONTINUE;
1049 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
1050 /* plain continue */
1051 b->a_type = ACL_BREAK;
1053 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1058 access_append( &a->acl_access, b );
1062 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
1063 fname, lineno, argv[i] );
1068 /* if we have no real access clause, complain and do nothing */
1071 "%s: line %d: warning: no access clause(s) specified in access line\n",
1076 if (ldap_debug & LDAP_DEBUG_ACL)
1080 if ( a->acl_access == NULL ) {
1082 "%s: line %d: warning: no by clause(s) specified in access line\n",
1087 acl_append( &be->be_acl, a );
1089 acl_append( &global_acl, a );
1095 accessmask2str( slap_mask_t mask, char *buf )
1100 assert( buf != NULL );
1102 if ( ACL_IS_INVALID( mask ) ) {
1108 if ( ACL_IS_LEVEL( mask ) ) {
1109 if ( ACL_LVL_IS_NONE(mask) ) {
1110 ptr = lutil_strcopy( ptr, "none" );
1112 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1113 ptr = lutil_strcopy( ptr, "auth" );
1115 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1116 ptr = lutil_strcopy( ptr, "compare" );
1118 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1119 ptr = lutil_strcopy( ptr, "search" );
1121 } else if ( ACL_LVL_IS_READ(mask) ) {
1122 ptr = lutil_strcopy( ptr, "read" );
1124 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1125 ptr = lutil_strcopy( ptr, "write" );
1127 ptr = lutil_strcopy( ptr, "unknown" );
1133 if( ACL_IS_ADDITIVE( mask ) ) {
1136 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1143 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1148 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1153 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1158 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1163 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1168 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1177 if ( ACL_IS_LEVEL( mask ) ) {
1187 str2accessmask( const char *str )
1191 if( !ASCII_ALPHA(str[0]) ) {
1194 if ( str[0] == '=' ) {
1197 } else if( str[0] == '+' ) {
1198 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1200 } else if( str[0] == '-' ) {
1201 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1204 ACL_INVALIDATE(mask);
1208 for( i=1; str[i] != '\0'; i++ ) {
1209 if( TOLOWER((unsigned char) str[i]) == 'w' ) {
1210 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1212 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
1213 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1215 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
1216 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1218 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
1219 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1221 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
1222 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1224 } else if( str[i] != '0' ) {
1225 ACL_INVALIDATE(mask);
1233 if ( strcasecmp( str, "none" ) == 0 ) {
1234 ACL_LVL_ASSIGN_NONE(mask);
1236 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1237 ACL_LVL_ASSIGN_AUTH(mask);
1239 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1240 ACL_LVL_ASSIGN_COMPARE(mask);
1242 } else if ( strcasecmp( str, "search" ) == 0 ) {
1243 ACL_LVL_ASSIGN_SEARCH(mask);
1245 } else if ( strcasecmp( str, "read" ) == 0 ) {
1246 ACL_LVL_ASSIGN_READ(mask);
1248 } else if ( strcasecmp( str, "write" ) == 0 ) {
1249 ACL_LVL_ASSIGN_WRITE(mask);
1252 ACL_INVALIDATE( mask );
1261 fprintf( stderr, "\n"
1262 "<access clause> ::= access to <what> "
1263 "[ by <who> <access> [ <control> ] ]+ \n"
1264 "<what> ::= * | [dn[.<dnstyle>]=<regex>] [filter=<ldapfilter>] [attrs=<attrlist>]\n"
1265 "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
1266 "<attr> ::= <attrname> | entry | children\n"
1267 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<regex> ]\n"
1268 "\t[dnattr=<attrname>]\n"
1269 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<regex>]\n"
1270 "\t[peername[.<style>]=<regex>] [sockname[.<style>]=<regex>]\n"
1271 "\t[domain[.<style>]=<regex>] [sockurl[.<style>]=<regex>]\n"
1272 #ifdef SLAPD_ACI_ENABLED
1273 "\t[aci=<attrname>]\n"
1275 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1276 "<dnstyle> ::= regex | base | exact (alias of base) | one | sub | children\n"
1277 "<style> ::= regex | base | exact (alias of base)\n"
1278 "<groupflags> ::= R\n"
1279 "<access> ::= [self]{<level>|<priv>}\n"
1280 "<level> ::= none | auth | compare | search | read | write\n"
1281 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
1282 "<control> ::= [ stop | continue | break ]\n"
1284 exit( EXIT_FAILURE );
1288 * Set pattern to a "normalized" DN from src.
1289 * At present it simply eats the (optional) space after
1290 * a RDN separator (,)
1291 * Eventually will evolve in a more complete normalization
1294 acl_regex_normalized_dn(
1296 struct berval *pattern
1302 str = ch_strdup( src );
1303 len = strlen( src );
1305 for ( p = str; p && p[ 0 ]; p++ ) {
1307 if ( p[ 0 ] == '\\' && p[ 1 ] ) {
1309 * if escaping a hex pair we should
1310 * increment p twice; however, in that
1311 * case the second hex number does
1317 if ( p[ 0 ] == ',' ) {
1318 if ( p[ 1 ] == ' ' ) {
1322 * too much space should be
1323 * an error if we are pedantic
1325 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1328 AC_MEMCPY( p+1, q, len-(q-str)+1);
1332 pattern->bv_val = str;
1333 pattern->bv_len = p-str;
1347 if ( (*right = strchr( line, splitchar )) != NULL ) {
1348 *((*right)++) = '\0';
1353 access_append( Access **l, Access *a )
1355 for ( ; *l != NULL; l = &(*l)->a_next )
1362 acl_append( AccessControl **l, AccessControl *a )
1364 for ( ; *l != NULL; l = &(*l)->acl_next )
1371 access_free( Access *a )
1373 if ( a->a_dn_pat.bv_val )
1374 free ( a->a_dn_pat.bv_val );
1375 if ( a->a_peername_pat.bv_val )
1376 free ( a->a_peername_pat.bv_val );
1377 if ( a->a_sockname_pat.bv_val )
1378 free ( a->a_sockname_pat.bv_val );
1379 if ( a->a_domain_pat.bv_val )
1380 free ( a->a_domain_pat.bv_val );
1381 if ( a->a_sockurl_pat.bv_val )
1382 free ( a->a_sockurl_pat.bv_val );
1383 if ( a->a_set_pat.bv_len )
1384 free ( a->a_set_pat.bv_val );
1385 if ( a->a_group_pat.bv_len )
1386 free ( a->a_group_pat.bv_val );
1391 acl_free( AccessControl *a )
1396 if ( a->acl_filter )
1397 filter_free( a->acl_filter );
1398 if ( a->acl_dn_pat.bv_len )
1399 free ( a->acl_dn_pat.bv_val );
1400 if ( a->acl_attrs ) {
1401 for ( an = a->acl_attrs; an->an_name.bv_val; an++ ) {
1402 free( an->an_name.bv_val );
1404 free( a->acl_attrs );
1406 for (; a->acl_access; a->acl_access = n) {
1407 n = a->acl_access->a_next;
1408 access_free( a->acl_access );
1413 /* Because backend_startup uses acl_append to tack on the global_acl to
1414 * the end of each backend's acl, we cannot just take one argument and
1415 * merrily free our way to the end of the list. backend_destroy calls us
1416 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1417 * point. config_destroy calls us with global_acl in arg1 and NULL in
1418 * arg2, so we then proceed to polish off the global_acl.
1421 acl_destroy( AccessControl *a, AccessControl *end )
1425 for (; a && a!= end; a=n) {
1432 access2str( slap_access_t access )
1434 if ( access == ACL_NONE ) {
1437 } else if ( access == ACL_AUTH ) {
1440 } else if ( access == ACL_COMPARE ) {
1443 } else if ( access == ACL_SEARCH ) {
1446 } else if ( access == ACL_READ ) {
1449 } else if ( access == ACL_WRITE ) {
1457 str2access( const char *str )
1459 if ( strcasecmp( str, "none" ) == 0 ) {
1462 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1465 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1468 } else if ( strcasecmp( str, "search" ) == 0 ) {
1471 } else if ( strcasecmp( str, "read" ) == 0 ) {
1474 } else if ( strcasecmp( str, "write" ) == 0 ) {
1478 return( ACL_INVALID_ACCESS );
1483 static char *style_strings[5] = {
1493 print_access( Access *b )
1495 char maskbuf[ACCESSMASK_MAXLEN];
1497 fprintf( stderr, "\tby" );
1499 if ( b->a_dn_pat.bv_len != 0 ) {
1500 if( strcmp(b->a_dn_pat.bv_val, "*") == 0
1501 || strcmp(b->a_dn_pat.bv_val, "users") == 0
1502 || strcmp(b->a_dn_pat.bv_val, "anonymous") == 0
1503 || strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1505 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1508 fprintf( stderr, " dn.%s=%s",
1509 style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1513 if ( b->a_dn_at != NULL ) {
1514 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1517 if ( b->a_group_pat.bv_len ) {
1518 fprintf( stderr, " group=%s", b->a_group_pat.bv_val );
1520 if ( b->a_group_oc ) {
1521 fprintf( stderr, " objectClass: %s",
1522 b->a_group_oc->soc_oclass.oc_oid );
1524 if ( b->a_group_at ) {
1525 fprintf( stderr, " attributeType: %s", b->a_group_at->ad_cname.bv_val );
1530 if ( b->a_peername_pat.bv_len != 0 ) {
1531 fprintf( stderr, " peername=%s", b->a_peername_pat.bv_val );
1534 if ( b->a_sockname_pat.bv_len != 0 ) {
1535 fprintf( stderr, " sockname=%s", b->a_sockname_pat.bv_val );
1538 if ( b->a_domain_pat.bv_len != 0 ) {
1539 fprintf( stderr, " domain=%s", b->a_domain_pat.bv_val );
1542 if ( b->a_sockurl_pat.bv_len != 0 ) {
1543 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat.bv_val );
1546 #ifdef SLAPD_ACI_ENABLED
1547 if ( b->a_aci_at != NULL ) {
1548 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1552 /* Security Strength Factors */
1553 if ( b->a_authz.sai_ssf ) {
1554 fprintf( stderr, " ssf=%u",
1555 b->a_authz.sai_ssf );
1557 if ( b->a_authz.sai_transport_ssf ) {
1558 fprintf( stderr, " transport_ssf=%u",
1559 b->a_authz.sai_transport_ssf );
1561 if ( b->a_authz.sai_tls_ssf ) {
1562 fprintf( stderr, " tls_ssf=%u",
1563 b->a_authz.sai_tls_ssf );
1565 if ( b->a_authz.sai_sasl_ssf ) {
1566 fprintf( stderr, " sasl_ssf=%u",
1567 b->a_authz.sai_sasl_ssf );
1570 fprintf( stderr, " %s%s",
1571 b->a_dn_self ? "self" : "",
1572 accessmask2str( b->a_access_mask, maskbuf ) );
1574 if( b->a_type == ACL_BREAK ) {
1575 fprintf( stderr, " break" );
1577 } else if( b->a_type == ACL_CONTINUE ) {
1578 fprintf( stderr, " continue" );
1580 } else if( b->a_type != ACL_STOP ) {
1581 fprintf( stderr, " unknown-control" );
1584 fprintf( stderr, "\n" );
1589 print_acl( Backend *be, AccessControl *a )
1594 fprintf( stderr, "%s ACL: access to",
1595 be == NULL ? "Global" : "Backend" );
1597 if ( a->acl_dn_pat.bv_len != 0 ) {
1599 fprintf( stderr, " dn.%s=%s\n",
1600 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
1603 if ( a->acl_filter != NULL ) {
1604 struct berval bv = { 0, NULL };
1606 filter2bv( a->acl_filter, &bv );
1607 fprintf( stderr, " filter=%s\n", bv.bv_val );
1608 ch_free( bv.bv_val );
1611 if ( a->acl_attrs != NULL ) {
1616 fprintf( stderr, " attrs=" );
1617 for ( an = a->acl_attrs; an && an->an_name.bv_val; an++ ) {
1619 fprintf( stderr, "," );
1621 fputs( an->an_name.bv_val, stderr );
1624 fprintf( stderr, "\n" );
1628 fprintf( stderr, " *\n" );
1631 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1635 fprintf( stderr, "\n" );
1638 #endif /* LDAP_DEBUG */