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(const char *src, struct berval *pat);
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 );
96 char *left, *right, *style;
104 for ( i = 1; i < argc; i++ ) {
105 /* to clause - select which entries are protected */
106 if ( strcasecmp( argv[i], "to" ) == 0 ) {
109 "%s: line %d: only one to clause allowed in access line\n",
113 a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
114 for ( ++i; i < argc; i++ ) {
115 if ( strcasecmp( argv[i], "by" ) == 0 ) {
120 if ( strcasecmp( argv[i], "*" ) == 0 ) {
121 if( a->acl_dn_pat.bv_len != 0 ) {
123 "%s: line %d: dn pattern"
124 " already specified in to clause.\n",
129 a->acl_dn_pat.bv_val = ch_strdup( "*" );
130 a->acl_dn_pat.bv_len = 1;
134 split( argv[i], '=', &left, &right );
135 split( left, '.', &left, &style );
137 if ( right == NULL ) {
139 "%s: line %d: missing \"=\" in \"%s\" in to clause\n",
140 fname, lineno, left );
144 if ( strcasecmp( left, "dn" ) == 0 ) {
145 if( a->acl_dn_pat.bv_len != 0 ) {
147 "%s: line %d: dn pattern"
148 " already specified in to clause.\n",
153 if ( style == NULL || *style == '\0'
154 || strcasecmp( style, "regex" ) == 0 )
156 a->acl_dn_style = ACL_STYLE_REGEX;
158 if ( *right == '\0' ) {
159 /* empty regex should match empty DN */
160 a->acl_dn_style = ACL_STYLE_BASE;
161 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
163 } else if ( strcmp(right, "*") == 0
164 || strcmp(right, ".*") == 0
165 || strcmp(right, ".*$") == 0
166 || strcmp(right, "^.*") == 0
167 || strcmp(right, "^.*$") == 0
168 || strcmp(right, ".*$$") == 0
169 || strcmp(right, "^.*$$") == 0 )
171 a->acl_dn_pat.bv_val = ch_strdup( "*" );
172 a->acl_dn_pat.bv_len = sizeof("*")-1;
175 acl_regex_normalized_dn( right, &a->acl_dn_pat );
177 } else if ( strcasecmp( style, "base" ) == 0 ) {
178 a->acl_dn_style = ACL_STYLE_BASE;
179 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
180 } else if ( strcasecmp( style, "one" ) == 0 ) {
181 a->acl_dn_style = ACL_STYLE_ONE;
182 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
183 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
184 a->acl_dn_style = ACL_STYLE_SUBTREE;
185 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
186 } else if ( strcasecmp( style, "children" ) == 0 ) {
187 a->acl_dn_style = ACL_STYLE_CHILDREN;
188 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
191 "%s: line %d: unknown dn style \"%s\" in to clause\n",
192 fname, lineno, style );
199 if ( strcasecmp( left, "filter" ) == 0 ) {
200 if ( (a->acl_filter = str2filter(
203 "%s: line %d: bad filter \"%s\" in to clause\n",
204 fname, lineno, right );
208 } else if ( strncasecmp( left, "attr", 4 ) == 0 ) {
209 a->acl_attrs = str2anlist( a->acl_attrs,
211 if ( a->acl_attrs == NULL ) {
213 "%s: line %d: unknown attr \"%s\" in to clause\n",
214 fname, lineno, right );
219 "%s: line %d: expecting <what> got \"%s\"\n",
220 fname, lineno, left );
225 if ( a->acl_dn_pat.bv_len != 0 &&
226 strcmp(a->acl_dn_pat.bv_val, "*") == 0)
228 free( a->acl_dn_pat.bv_val );
229 a->acl_dn_pat.bv_val = NULL;
230 a->acl_dn_pat.bv_len = 0;
233 if( a->acl_dn_pat.bv_len != 0 ) {
234 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
236 rc = dnNormalize2( NULL, &a->acl_dn_pat, &bv);
237 if ( rc != LDAP_SUCCESS ) {
239 "%s: line %d: bad DN \"%s\"\n",
240 fname, lineno, a->acl_dn_pat.bv_val );
243 free( a->acl_dn_pat.bv_val );
246 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
247 REG_EXTENDED | REG_ICASE );
250 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
251 fprintf( stderr, "%s: line %d: "
252 "regular expression \"%s\" bad because of %s\n",
253 fname, lineno, right, buf );
259 /* by clause - select who has what access to entries */
260 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
263 "%s: line %d: to clause required before by clause in access line\n",
269 * by clause consists of <who> and <access>
272 b = (Access *) ch_calloc( 1, sizeof(Access) );
274 ACL_INVALIDATE( b->a_access_mask );
278 "%s: line %d: premature eol: expecting <who>\n",
284 for ( ; i < argc; i++ ) {
285 slap_style_t sty = ACL_STYLE_REGEX;
286 char *style_modifier = NULL;
289 split( argv[i], '=', &left, &right );
290 split( left, '.', &left, &style );
292 split( style, ',', &style, &style_modifier);
294 if ( style == NULL || *style == '\0'
295 || strcasecmp( style, "regex" ) == 0 )
297 sty = ACL_STYLE_REGEX;
298 } else if ( strcasecmp( style, "exact" ) == 0 ) {
299 sty = ACL_STYLE_EXACT;
300 } else if ( strcasecmp( style, "base" ) == 0 ) {
301 sty = ACL_STYLE_BASE;
302 } else if ( strcasecmp( style, "one" ) == 0 ) {
304 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
305 sty = ACL_STYLE_SUBTREE;
306 } else if ( strcasecmp( style, "children" ) == 0 ) {
307 sty = ACL_STYLE_CHILDREN;
310 "%s: line %d: unknown style \"%s\" in by clause\n",
311 fname, lineno, style );
315 if ( style_modifier && strcasecmp( style_modifier, "expand" ) == 0 ) {
319 if ( strcasecmp( argv[i], "*" ) == 0 ) {
320 bv.bv_val = ch_strdup( "*" );
323 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
324 ber_str2bv("anonymous",
325 sizeof("anonymous")-1,
328 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
333 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
338 } else if ( strcasecmp( left, "dn" ) == 0 ) {
339 if ( sty == ACL_STYLE_REGEX ) {
340 b->a_dn_style = ACL_STYLE_REGEX;
341 if( right == NULL ) {
346 } else if (*right == '\0' ) {
348 ber_str2bv("anonymous",
349 sizeof("anonymous")-1,
351 } else if ( strcmp( right, "*" ) == 0 ) {
353 /* any or users? users for now */
357 } else if ( strcmp( right, ".+" ) == 0
358 || strcmp( right, "^.+" ) == 0
359 || strcmp( right, ".+$" ) == 0
360 || strcmp( right, "^.+$" ) == 0
361 || strcmp( right, ".+$$" ) == 0
362 || strcmp( right, "^.+$$" ) == 0 )
367 } else if ( strcmp( right, ".*" ) == 0
368 || strcmp( right, "^.*" ) == 0
369 || strcmp( right, ".*$" ) == 0
370 || strcmp( right, "^.*$" ) == 0
371 || strcmp( right, ".*$$" ) == 0
372 || strcmp( right, "^.*$$" ) == 0 )
379 acl_regex_normalized_dn( right, &bv );
380 if ( !ber_bvccmp( &bv, '*' ) ) {
381 regtest(fname, lineno, bv.bv_val);
384 } else if ( right == NULL || *right == '\0' ) {
386 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
387 fname, lineno, left );
391 ber_str2bv( right, 0, 1, &bv );
398 if( bv.bv_val != NULL ) {
399 if( b->a_dn_pat.bv_len != 0 ) {
401 "%s: line %d: dn pattern already specified.\n",
406 if ( sty != ACL_STYLE_REGEX && expand == 0 ) {
407 rc = dnNormalize2(NULL, &bv, &b->a_dn_pat);
408 if ( rc != LDAP_SUCCESS ) {
410 "%s: line %d: bad DN \"%s\"\n",
411 fname, lineno, bv.bv_val );
419 b->a_dn_expand = expand;
423 if ( strcasecmp( left, "dnattr" ) == 0 ) {
424 if ( right == NULL || right[ 0 ] == '\0' ) {
426 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
427 fname, lineno, left );
431 if( b->a_dn_at != NULL ) {
433 "%s: line %d: dnattr already specified.\n",
438 rc = slap_str2ad( right, &b->a_dn_at, &text );
440 if( rc != LDAP_SUCCESS ) {
442 "%s: line %d: dnattr \"%s\": %s\n",
443 fname, lineno, right, text );
448 if( !is_at_syntax( b->a_dn_at->ad_type,
450 !is_at_syntax( b->a_dn_at->ad_type,
451 SLAPD_NAMEUID_SYNTAX ))
454 "%s: line %d: dnattr \"%s\": "
455 "inappropriate syntax: %s\n",
456 fname, lineno, right,
457 b->a_dn_at->ad_type->sat_syntax_oid );
464 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
468 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
470 "%s: line %d: inappropriate style \"%s\" in by clause\n",
471 fname, lineno, style );
475 if ( right == NULL || right[ 0 ] == '\0' ) {
477 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
478 fname, lineno, left );
482 if( b->a_group_pat.bv_len ) {
484 "%s: line %d: group pattern already specified.\n",
489 /* format of string is "group/objectClassValue/groupAttrName" */
490 if ((value = strchr(left, '/')) != NULL) {
493 && (name = strchr(value, '/')) != NULL)
499 b->a_group_style = sty;
500 if (sty == ACL_STYLE_REGEX) {
501 acl_regex_normalized_dn( right, &bv );
502 if ( !ber_bvccmp( &bv, '*' ) ) {
503 regtest(fname, lineno, bv.bv_val);
507 ber_str2bv( right, 0, 0, &bv );
508 rc = dnNormalize2( NULL, &bv, &b->a_group_pat );
509 if ( rc != LDAP_SUCCESS ) {
511 "%s: line %d: bad DN \"%s\"\n",
512 fname, lineno, right );
517 if (value && *value) {
518 b->a_group_oc = oc_find( value );
521 if( b->a_group_oc == NULL ) {
523 "%s: line %d: group objectclass "
525 fname, lineno, value );
529 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
531 if( b->a_group_oc == NULL ) {
533 "%s: line %d: group default objectclass "
535 fname, lineno, SLAPD_GROUP_CLASS );
540 if( is_object_subclass( slap_schema.si_oc_referral,
544 "%s: line %d: group objectclass \"%s\" "
545 "is subclass of referral\n",
546 fname, lineno, value );
550 if( is_object_subclass( slap_schema.si_oc_alias,
554 "%s: line %d: group objectclass \"%s\" "
555 "is subclass of alias\n",
556 fname, lineno, value );
561 rc = slap_str2ad( name, &b->a_group_at, &text );
563 if( rc != LDAP_SUCCESS ) {
565 "%s: line %d: group \"%s\": %s\n",
566 fname, lineno, right, text );
571 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
573 if( rc != LDAP_SUCCESS ) {
575 "%s: line %d: group \"%s\": %s\n",
576 fname, lineno, SLAPD_GROUP_ATTR, text );
581 if( !is_at_syntax( b->a_group_at->ad_type,
583 !is_at_syntax( b->a_group_at->ad_type,
584 SLAPD_NAMEUID_SYNTAX ) )
587 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
588 fname, lineno, right,
589 b->a_group_at->ad_type->sat_syntax_oid );
596 struct berval vals[2];
598 vals[0].bv_val = b->a_group_oc->soc_oid;
599 vals[0].bv_len = strlen(vals[0].bv_val);
600 vals[1].bv_val = NULL;
603 rc = oc_check_allowed( b->a_group_at->ad_type, vals, NULL );
607 "%s: line %d: group: \"%s\" not allowed by \"%s\"\n",
609 b->a_group_at->ad_cname.bv_val,
610 b->a_group_oc->soc_oid );
617 if ( strcasecmp( left, "peername" ) == 0 ) {
618 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
620 "%s: line %d: inappropriate style \"%s\" in by clause\n",
621 fname, lineno, style );
625 if ( right == NULL || right[ 0 ] == '\0' ) {
627 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
628 fname, lineno, left );
632 if( b->a_peername_pat.bv_len ) {
634 "%s: line %d: peername pattern already specified.\n",
639 b->a_peername_style = sty;
640 if (sty == ACL_STYLE_REGEX) {
641 acl_regex_normalized_dn( right, &bv );
642 if ( !ber_bvccmp( &bv, '*' ) ) {
643 regtest(fname, lineno, bv.bv_val);
645 b->a_peername_pat = bv;
647 ber_str2bv( right, 0, 1, &b->a_peername_pat );
652 if ( strcasecmp( left, "sockname" ) == 0 ) {
653 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
655 "%s: line %d: inappropriate style \"%s\" in by clause\n",
656 fname, lineno, style );
660 if ( right == NULL || right[ 0 ] == '\0' ) {
662 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
663 fname, lineno, left );
667 if( b->a_sockname_pat.bv_len ) {
669 "%s: line %d: sockname pattern already specified.\n",
674 b->a_sockname_style = sty;
675 if (sty == ACL_STYLE_REGEX) {
676 acl_regex_normalized_dn( right, &bv );
677 if ( !ber_bvccmp( &bv, '*' ) ) {
678 regtest(fname, lineno, bv.bv_val);
680 b->a_sockname_pat = bv;
682 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
687 if ( strcasecmp( left, "domain" ) == 0 ) {
689 case ACL_STYLE_REGEX:
691 case ACL_STYLE_SUBTREE:
696 "%s: line %d: inappropriate style \"%s\" in by clause\n",
697 fname, lineno, style );
701 if ( right == NULL || right[ 0 ] == '\0' ) {
703 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
704 fname, lineno, left );
708 if( b->a_domain_pat.bv_len ) {
710 "%s: line %d: domain pattern already specified.\n",
715 b->a_domain_style = sty;
716 b->a_domain_expand = expand;
717 if (sty == ACL_STYLE_REGEX) {
718 acl_regex_normalized_dn( right, &bv );
719 if ( !ber_bvccmp( &bv, '*' ) ) {
720 regtest(fname, lineno, bv.bv_val);
722 b->a_domain_pat = bv;
724 ber_str2bv( right, 0, 1, &b->a_domain_pat );
729 if ( strcasecmp( left, "sockurl" ) == 0 ) {
730 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
732 "%s: line %d: inappropriate style \"%s\" in by clause\n",
733 fname, lineno, style );
737 if ( right == NULL || right[ 0 ] == '\0' ) {
739 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
740 fname, lineno, left );
744 if( b->a_sockurl_pat.bv_len ) {
746 "%s: line %d: sockurl pattern already specified.\n",
751 b->a_sockurl_style = sty;
752 if (sty == ACL_STYLE_REGEX) {
753 acl_regex_normalized_dn( right, &bv );
754 if ( !ber_bvccmp( &bv, '*' ) ) {
755 regtest(fname, lineno, bv.bv_val);
757 b->a_sockurl_pat = bv;
759 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
764 if ( strcasecmp( left, "set" ) == 0 ) {
765 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
767 "%s: line %d: inappropriate style \"%s\" in by clause\n",
768 fname, lineno, style );
772 if( b->a_set_pat.bv_len != 0 ) {
774 "%s: line %d: set attribute already specified.\n",
779 if ( right == NULL || *right == '\0' ) {
781 "%s: line %d: no set is defined\n",
786 b->a_set_style = sty;
787 ber_str2bv( right, 0, 1, &b->a_set_pat );
792 #ifdef SLAPD_ACI_ENABLED
793 if ( strcasecmp( left, "aci" ) == 0 ) {
794 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
796 "%s: line %d: inappropriate style \"%s\" in by clause\n",
797 fname, lineno, style );
801 if( b->a_aci_at != NULL ) {
803 "%s: line %d: aci attribute already specified.\n",
808 if ( right != NULL && *right != '\0' ) {
809 rc = slap_str2ad( right, &b->a_aci_at, &text );
811 if( rc != LDAP_SUCCESS ) {
813 "%s: line %d: aci \"%s\": %s\n",
814 fname, lineno, right, text );
819 b->a_aci_at = slap_schema.si_ad_aci;
822 if( !is_at_syntax( b->a_aci_at->ad_type,
826 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
827 fname, lineno, right,
828 b->a_aci_at->ad_type->sat_syntax_oid );
834 #endif /* SLAPD_ACI_ENABLED */
836 if ( strcasecmp( left, "ssf" ) == 0 ) {
837 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
839 "%s: line %d: inappropriate style \"%s\" in by clause\n",
840 fname, lineno, style );
844 if( b->a_authz.sai_ssf ) {
846 "%s: line %d: ssf attribute already specified.\n",
851 if ( right == NULL || *right == '\0' ) {
853 "%s: line %d: no ssf is defined\n",
858 b->a_authz.sai_ssf = atoi( right );
860 if( !b->a_authz.sai_ssf ) {
862 "%s: line %d: invalid ssf value (%s)\n",
863 fname, lineno, right );
869 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
870 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
872 "%s: line %d: inappropriate style \"%s\" in by clause\n",
873 fname, lineno, style );
877 if( b->a_authz.sai_transport_ssf ) {
879 "%s: line %d: transport_ssf attribute already specified.\n",
884 if ( right == NULL || *right == '\0' ) {
886 "%s: line %d: no transport_ssf is defined\n",
891 b->a_authz.sai_transport_ssf = atoi( right );
893 if( !b->a_authz.sai_transport_ssf ) {
895 "%s: line %d: invalid transport_ssf value (%s)\n",
896 fname, lineno, right );
902 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
903 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
905 "%s: line %d: inappropriate style \"%s\" in by clause\n",
906 fname, lineno, style );
910 if( b->a_authz.sai_tls_ssf ) {
912 "%s: line %d: tls_ssf attribute already specified.\n",
917 if ( right == NULL || *right == '\0' ) {
919 "%s: line %d: no tls_ssf is defined\n",
924 b->a_authz.sai_tls_ssf = atoi( right );
926 if( !b->a_authz.sai_tls_ssf ) {
928 "%s: line %d: invalid tls_ssf value (%s)\n",
929 fname, lineno, right );
935 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
936 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
938 "%s: line %d: inappropriate style \"%s\" in by clause\n",
939 fname, lineno, style );
943 if( b->a_authz.sai_sasl_ssf ) {
945 "%s: line %d: sasl_ssf attribute already specified.\n",
950 if ( right == NULL || *right == '\0' ) {
952 "%s: line %d: no sasl_ssf is defined\n",
957 b->a_authz.sai_sasl_ssf = atoi( right );
959 if( !b->a_authz.sai_sasl_ssf ) {
961 "%s: line %d: invalid sasl_ssf value (%s)\n",
962 fname, lineno, right );
968 if( right != NULL ) {
975 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
976 /* out of arguments or plain stop */
978 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
979 b->a_type = ACL_STOP;
981 access_append( &a->acl_access, b );
985 if( strcasecmp( left, "continue" ) == 0 ) {
988 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
989 b->a_type = ACL_CONTINUE;
991 access_append( &a->acl_access, b );
995 if( strcasecmp( left, "break" ) == 0 ) {
998 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
999 b->a_type = ACL_BREAK;
1001 access_append( &a->acl_access, b );
1005 if ( strcasecmp( left, "by" ) == 0 ) {
1006 /* we've gone too far */
1008 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1009 b->a_type = ACL_STOP;
1011 access_append( &a->acl_access, b );
1016 if( strncasecmp( left, "self", 4 ) == 0 ) {
1018 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
1021 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1024 if( ACL_IS_INVALID( b->a_access_mask ) ) {
1026 "%s: line %d: expecting <access> got \"%s\"\n",
1027 fname, lineno, left );
1031 b->a_type = ACL_STOP;
1034 /* out of arguments or plain stop */
1035 access_append( &a->acl_access, b );
1039 if( strcasecmp( argv[i], "continue" ) == 0 ) {
1040 /* plain continue */
1041 b->a_type = ACL_CONTINUE;
1043 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
1044 /* plain continue */
1045 b->a_type = ACL_BREAK;
1047 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1052 access_append( &a->acl_access, b );
1056 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
1057 fname, lineno, argv[i] );
1062 /* if we have no real access clause, complain and do nothing */
1065 "%s: line %d: warning: no access clause(s) specified in access line\n",
1070 if (ldap_debug & LDAP_DEBUG_ACL)
1074 if ( a->acl_access == NULL ) {
1076 "%s: line %d: warning: no by clause(s) specified in access line\n",
1081 acl_append( &be->be_acl, a );
1083 acl_append( &global_acl, a );
1089 accessmask2str( slap_mask_t mask, char *buf )
1094 assert( buf != NULL );
1096 if ( ACL_IS_INVALID( mask ) ) {
1102 if ( ACL_IS_LEVEL( mask ) ) {
1103 if ( ACL_LVL_IS_NONE(mask) ) {
1104 ptr = slap_strcopy( ptr, "none" );
1106 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1107 ptr = slap_strcopy( ptr, "auth" );
1109 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1110 ptr = slap_strcopy( ptr, "compare" );
1112 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1113 ptr = slap_strcopy( ptr, "search" );
1115 } else if ( ACL_LVL_IS_READ(mask) ) {
1116 ptr = slap_strcopy( ptr, "read" );
1118 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1119 ptr = slap_strcopy( ptr, "write" );
1121 ptr = slap_strcopy( ptr, "unknown" );
1127 if( ACL_IS_ADDITIVE( mask ) ) {
1130 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1137 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1142 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1147 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1152 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1157 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1162 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1171 if ( ACL_IS_LEVEL( mask ) ) {
1181 str2accessmask( const char *str )
1185 if( !ASCII_ALPHA(str[0]) ) {
1188 if ( str[0] == '=' ) {
1191 } else if( str[0] == '+' ) {
1192 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1194 } else if( str[0] == '-' ) {
1195 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1198 ACL_INVALIDATE(mask);
1202 for( i=1; str[i] != '\0'; i++ ) {
1203 if( TOLOWER((unsigned char) str[i]) == 'w' ) {
1204 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1206 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
1207 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1209 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
1210 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1212 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
1213 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1215 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
1216 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1218 } else if( str[i] != '0' ) {
1219 ACL_INVALIDATE(mask);
1227 if ( strcasecmp( str, "none" ) == 0 ) {
1228 ACL_LVL_ASSIGN_NONE(mask);
1230 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1231 ACL_LVL_ASSIGN_AUTH(mask);
1233 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1234 ACL_LVL_ASSIGN_COMPARE(mask);
1236 } else if ( strcasecmp( str, "search" ) == 0 ) {
1237 ACL_LVL_ASSIGN_SEARCH(mask);
1239 } else if ( strcasecmp( str, "read" ) == 0 ) {
1240 ACL_LVL_ASSIGN_READ(mask);
1242 } else if ( strcasecmp( str, "write" ) == 0 ) {
1243 ACL_LVL_ASSIGN_WRITE(mask);
1246 ACL_INVALIDATE( mask );
1255 fprintf( stderr, "\n"
1256 "<access clause> ::= access to <what> "
1257 "[ by <who> <access> [ <control> ] ]+ \n"
1258 "<what> ::= * | [dn[.<dnstyle>]=<regex>] [filter=<ldapfilter>] [attrs=<attrlist>]\n"
1259 "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
1260 "<attr> ::= <attrname> | entry | children\n"
1261 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<regex> ]\n"
1262 "\t[dnattr=<attrname>]\n"
1263 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<regex>]\n"
1264 "\t[peername[.<style>]=<regex>] [sockname[.<style>]=<regex>]\n"
1265 "\t[domain[.<style>]=<regex>] [sockurl[.<style>]=<regex>]\n"
1266 #ifdef SLAPD_ACI_ENABLED
1267 "\t[aci=<attrname>]\n"
1269 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1270 "<dnstyle> ::= regex | base | exact (alias of base) | one | sub | children\n"
1271 "<style> ::= regex | base | exact (alias of base)\n"
1272 "<groupflags> ::= R\n"
1273 "<access> ::= [self]{<level>|<priv>}\n"
1274 "<level> ::= none | auth | compare | search | read | write\n"
1275 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
1276 "<control> ::= [ stop | continue | break ]\n"
1278 exit( EXIT_FAILURE );
1282 * Set pattern to a "normalized" DN from src.
1283 * At present it simply eats the (optional) space after
1284 * a RDN separator (,)
1285 * Eventually will evolve in a more complete normalization
1288 acl_regex_normalized_dn(
1290 struct berval *pattern
1296 str = ch_strdup( src );
1297 len = strlen( src );
1299 for ( p = str; p && p[ 0 ]; p++ ) {
1301 if ( p[ 0 ] == '\\' && p[ 1 ] ) {
1303 * if escaping a hex pair we should
1304 * increment p twice; however, in that
1305 * case the second hex number does
1311 if ( p[ 0 ] == ',' ) {
1312 if ( p[ 1 ] == ' ' ) {
1316 * too much space should be
1317 * an error if we are pedantic
1319 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1322 AC_MEMCPY( p+1, q, len-(q-str)+1);
1326 pattern->bv_val = str;
1327 pattern->bv_len = p-str;
1341 if ( (*right = strchr( line, splitchar )) != NULL ) {
1342 *((*right)++) = '\0';
1347 access_append( Access **l, Access *a )
1349 for ( ; *l != NULL; l = &(*l)->a_next )
1356 acl_append( AccessControl **l, AccessControl *a )
1358 for ( ; *l != NULL; l = &(*l)->acl_next )
1365 access_free( Access *a )
1367 if ( a->a_dn_pat.bv_val )
1368 free ( a->a_dn_pat.bv_val );
1369 if ( a->a_peername_pat.bv_val )
1370 free ( a->a_peername_pat.bv_val );
1371 if ( a->a_sockname_pat.bv_val )
1372 free ( a->a_sockname_pat.bv_val );
1373 if ( a->a_domain_pat.bv_val )
1374 free ( a->a_domain_pat.bv_val );
1375 if ( a->a_sockurl_pat.bv_val )
1376 free ( a->a_sockurl_pat.bv_val );
1377 if ( a->a_set_pat.bv_len )
1378 free ( a->a_set_pat.bv_val );
1379 if ( a->a_group_pat.bv_len )
1380 free ( a->a_group_pat.bv_val );
1385 acl_free( AccessControl *a )
1390 if ( a->acl_filter )
1391 filter_free( a->acl_filter );
1392 if ( a->acl_dn_pat.bv_len )
1393 free ( a->acl_dn_pat.bv_val );
1394 if ( a->acl_attrs ) {
1395 for ( an = a->acl_attrs; an->an_name.bv_val; an++ ) {
1396 free( an->an_name.bv_val );
1398 free( a->acl_attrs );
1400 for (; a->acl_access; a->acl_access = n) {
1401 n = a->acl_access->a_next;
1402 access_free( a->acl_access );
1407 /* Because backend_startup uses acl_append to tack on the global_acl to
1408 * the end of each backend's acl, we cannot just take one argument and
1409 * merrily free our way to the end of the list. backend_destroy calls us
1410 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1411 * point. config_destroy calls us with global_acl in arg1 and NULL in
1412 * arg2, so we then proceed to polish off the global_acl.
1415 acl_destroy( AccessControl *a, AccessControl *end )
1419 for (; a && a!= end; a=n) {
1426 access2str( slap_access_t access )
1428 if ( access == ACL_NONE ) {
1431 } else if ( access == ACL_AUTH ) {
1434 } else if ( access == ACL_COMPARE ) {
1437 } else if ( access == ACL_SEARCH ) {
1440 } else if ( access == ACL_READ ) {
1443 } else if ( access == ACL_WRITE ) {
1451 str2access( const char *str )
1453 if ( strcasecmp( str, "none" ) == 0 ) {
1456 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1459 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1462 } else if ( strcasecmp( str, "search" ) == 0 ) {
1465 } else if ( strcasecmp( str, "read" ) == 0 ) {
1468 } else if ( strcasecmp( str, "write" ) == 0 ) {
1472 return( ACL_INVALID_ACCESS );
1477 static char *style_strings[5] = {
1487 print_access( Access *b )
1489 char maskbuf[ACCESSMASK_MAXLEN];
1491 fprintf( stderr, "\tby" );
1493 if ( b->a_dn_pat.bv_len != 0 ) {
1494 if( strcmp(b->a_dn_pat.bv_val, "*") == 0
1495 || strcmp(b->a_dn_pat.bv_val, "users") == 0
1496 || strcmp(b->a_dn_pat.bv_val, "anonymous") == 0
1497 || strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1499 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1502 fprintf( stderr, " dn.%s=%s",
1503 style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1507 if ( b->a_dn_at != NULL ) {
1508 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1511 if ( b->a_group_pat.bv_len ) {
1512 fprintf( stderr, " group=%s", b->a_group_pat.bv_val );
1514 if ( b->a_group_oc ) {
1515 fprintf( stderr, " objectClass: %s",
1516 b->a_group_oc->soc_oclass.oc_oid );
1518 if ( b->a_group_at ) {
1519 fprintf( stderr, " attributeType: %s", b->a_group_at->ad_cname.bv_val );
1524 if ( b->a_peername_pat.bv_len != 0 ) {
1525 fprintf( stderr, " peername=%s", b->a_peername_pat.bv_val );
1528 if ( b->a_sockname_pat.bv_len != 0 ) {
1529 fprintf( stderr, " sockname=%s", b->a_sockname_pat.bv_val );
1532 if ( b->a_domain_pat.bv_len != 0 ) {
1533 fprintf( stderr, " domain=%s", b->a_domain_pat.bv_val );
1536 if ( b->a_sockurl_pat.bv_len != 0 ) {
1537 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat.bv_val );
1540 #ifdef SLAPD_ACI_ENABLED
1541 if ( b->a_aci_at != NULL ) {
1542 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1546 /* Security Strength Factors */
1547 if ( b->a_authz.sai_ssf ) {
1548 fprintf( stderr, " ssf=%u",
1549 b->a_authz.sai_ssf );
1551 if ( b->a_authz.sai_transport_ssf ) {
1552 fprintf( stderr, " transport_ssf=%u",
1553 b->a_authz.sai_transport_ssf );
1555 if ( b->a_authz.sai_tls_ssf ) {
1556 fprintf( stderr, " tls_ssf=%u",
1557 b->a_authz.sai_tls_ssf );
1559 if ( b->a_authz.sai_sasl_ssf ) {
1560 fprintf( stderr, " sasl_ssf=%u",
1561 b->a_authz.sai_sasl_ssf );
1564 fprintf( stderr, " %s%s",
1565 b->a_dn_self ? "self" : "",
1566 accessmask2str( b->a_access_mask, maskbuf ) );
1568 if( b->a_type == ACL_BREAK ) {
1569 fprintf( stderr, " break" );
1571 } else if( b->a_type == ACL_CONTINUE ) {
1572 fprintf( stderr, " continue" );
1574 } else if( b->a_type != ACL_STOP ) {
1575 fprintf( stderr, " unknown-control" );
1578 fprintf( stderr, "\n" );
1583 print_acl( Backend *be, AccessControl *a )
1588 fprintf( stderr, "%s ACL: access to",
1589 be == NULL ? "Global" : "Backend" );
1591 if ( a->acl_dn_pat.bv_len != 0 ) {
1593 fprintf( stderr, " dn.%s=%s\n",
1594 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
1597 if ( a->acl_filter != NULL ) {
1598 struct berval bv = { 0, NULL };
1600 filter2bv( a->acl_filter, &bv );
1601 fprintf( stderr, " filter=%s\n", bv.bv_val );
1602 ch_free( bv.bv_val );
1605 if ( a->acl_attrs != NULL ) {
1610 fprintf( stderr, " attrs=" );
1611 for ( an = a->acl_attrs; an && an->an_name.bv_val; an++ ) {
1613 fprintf( stderr, "," );
1615 fputs( an->an_name.bv_val, stderr );
1618 fprintf( stderr, "\n" );
1622 fprintf( stderr, " *\n" );
1625 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1629 fprintf( stderr, "\n" );
1632 #endif /* LDAP_DEBUG */