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 ||
122 ( a->acl_dn_style != ACL_STYLE_REGEX ) )
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 ||
148 ( a->acl_dn_style != ACL_STYLE_REGEX ) )
151 "%s: line %d: dn pattern"
152 " already specified in to clause.\n",
157 if ( style == NULL || *style == '\0'
158 || strcasecmp( style, "regex" ) == 0 )
160 a->acl_dn_style = ACL_STYLE_REGEX;
162 if ( *right == '\0' ) {
163 /* empty regex should match empty DN */
164 a->acl_dn_style = ACL_STYLE_BASE;
165 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
167 } else if ( strcmp(right, "*") == 0
168 || strcmp(right, ".*") == 0
169 || strcmp(right, ".*$") == 0
170 || strcmp(right, "^.*") == 0
171 || strcmp(right, "^.*$") == 0
172 || strcmp(right, ".*$$") == 0
173 || strcmp(right, "^.*$$") == 0 )
175 a->acl_dn_pat.bv_val = ch_strdup( "*" );
176 a->acl_dn_pat.bv_len = sizeof("*")-1;
179 acl_regex_normalized_dn( right, &a->acl_dn_pat );
181 } else if ( strcasecmp( style, "base" ) == 0 ) {
182 a->acl_dn_style = ACL_STYLE_BASE;
183 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
184 } else if ( strcasecmp( style, "one" ) == 0 ) {
185 a->acl_dn_style = ACL_STYLE_ONE;
186 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
187 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
188 a->acl_dn_style = ACL_STYLE_SUBTREE;
189 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
190 } else if ( strcasecmp( style, "children" ) == 0 ) {
191 a->acl_dn_style = ACL_STYLE_CHILDREN;
192 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
195 "%s: line %d: unknown dn style \"%s\" in to clause\n",
196 fname, lineno, style );
203 if ( strcasecmp( left, "filter" ) == 0 ) {
204 if ( (a->acl_filter = str2filter( right )) == NULL ) {
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 ( a->acl_dn_style != ACL_STYLE_REGEX ) )
239 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
241 rc = dnNormalize2( NULL, &a->acl_dn_pat, &bv);
242 if ( rc != LDAP_SUCCESS ) {
244 "%s: line %d: bad DN \"%s\"\n",
245 fname, lineno, a->acl_dn_pat.bv_val );
248 free( a->acl_dn_pat.bv_val );
251 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
252 REG_EXTENDED | REG_ICASE );
255 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
256 fprintf( stderr, "%s: line %d: "
257 "regular expression \"%s\" bad because of %s\n",
258 fname, lineno, right, buf );
264 /* by clause - select who has what access to entries */
265 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
268 "%s: line %d: to clause required before by clause in access line\n",
274 * by clause consists of <who> and <access>
277 b = (Access *) ch_calloc( 1, sizeof(Access) );
279 ACL_INVALIDATE( b->a_access_mask );
283 "%s: line %d: premature eol: expecting <who>\n",
289 for ( ; i < argc; i++ ) {
290 slap_style_t sty = ACL_STYLE_REGEX;
291 char *style_modifier = NULL;
294 split( argv[i], '=', &left, &right );
295 split( left, '.', &left, &style );
297 split( style, ',', &style, &style_modifier);
299 if ( style == NULL || *style == '\0'
300 || strcasecmp( style, "regex" ) == 0 )
302 sty = ACL_STYLE_REGEX;
303 } else if ( strcasecmp( style, "exact" ) == 0 ) {
304 sty = ACL_STYLE_EXACT;
305 } else if ( strcasecmp( style, "base" ) == 0 ) {
306 sty = ACL_STYLE_BASE;
307 } else if ( strcasecmp( style, "one" ) == 0 ) {
309 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
310 sty = ACL_STYLE_SUBTREE;
311 } else if ( strcasecmp( style, "children" ) == 0 ) {
312 sty = ACL_STYLE_CHILDREN;
315 "%s: line %d: unknown style \"%s\" in by clause\n",
316 fname, lineno, style );
320 if ( style_modifier && strcasecmp( style_modifier, "expand" ) == 0 ) {
324 if ( strcasecmp( argv[i], "*" ) == 0 ) {
325 bv.bv_val = ch_strdup( "*" );
328 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
329 ber_str2bv("anonymous",
330 sizeof("anonymous")-1,
333 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
338 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
343 } else if ( strcasecmp( left, "dn" ) == 0 ) {
344 if ( sty == ACL_STYLE_REGEX ) {
345 b->a_dn_style = ACL_STYLE_REGEX;
346 if( right == NULL ) {
351 } else if (*right == '\0' ) {
353 ber_str2bv("anonymous",
354 sizeof("anonymous")-1,
356 } else if ( strcmp( right, "*" ) == 0 ) {
358 /* any or users? users for now */
362 } else if ( strcmp( right, ".+" ) == 0
363 || strcmp( right, "^.+" ) == 0
364 || strcmp( right, ".+$" ) == 0
365 || strcmp( right, "^.+$" ) == 0
366 || strcmp( right, ".+$$" ) == 0
367 || strcmp( right, "^.+$$" ) == 0 )
372 } else if ( strcmp( right, ".*" ) == 0
373 || strcmp( right, "^.*" ) == 0
374 || strcmp( right, ".*$" ) == 0
375 || strcmp( right, "^.*$" ) == 0
376 || strcmp( right, ".*$$" ) == 0
377 || strcmp( right, "^.*$$" ) == 0 )
384 acl_regex_normalized_dn( right, &bv );
385 if ( !ber_bvccmp( &bv, '*' ) ) {
386 regtest(fname, lineno, bv.bv_val);
389 } else if ( right == NULL || *right == '\0' ) {
391 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
392 fname, lineno, left );
396 ber_str2bv( right, 0, 1, &bv );
403 if( bv.bv_val != NULL ) {
404 if( b->a_dn_pat.bv_len != 0 ) {
406 "%s: line %d: dn pattern already specified.\n",
411 if ( sty != ACL_STYLE_REGEX && expand == 0 ) {
412 rc = dnNormalize2(NULL, &bv, &b->a_dn_pat);
413 if ( rc != LDAP_SUCCESS ) {
415 "%s: line %d: bad DN \"%s\"\n",
416 fname, lineno, bv.bv_val );
424 b->a_dn_expand = expand;
428 if ( strcasecmp( left, "dnattr" ) == 0 ) {
429 if ( right == NULL || right[ 0 ] == '\0' ) {
431 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
432 fname, lineno, left );
436 if( b->a_dn_at != NULL ) {
438 "%s: line %d: dnattr already specified.\n",
443 rc = slap_str2ad( right, &b->a_dn_at, &text );
445 if( rc != LDAP_SUCCESS ) {
447 "%s: line %d: dnattr \"%s\": %s\n",
448 fname, lineno, right, text );
453 if( !is_at_syntax( b->a_dn_at->ad_type,
455 !is_at_syntax( b->a_dn_at->ad_type,
456 SLAPD_NAMEUID_SYNTAX ))
459 "%s: line %d: dnattr \"%s\": "
460 "inappropriate syntax: %s\n",
461 fname, lineno, right,
462 b->a_dn_at->ad_type->sat_syntax_oid );
469 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
473 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
475 "%s: line %d: inappropriate style \"%s\" in by clause\n",
476 fname, lineno, style );
480 if ( right == NULL || right[ 0 ] == '\0' ) {
482 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
483 fname, lineno, left );
487 if( b->a_group_pat.bv_len ) {
489 "%s: line %d: group pattern already specified.\n",
494 /* format of string is "group/objectClassValue/groupAttrName" */
495 if ((value = strchr(left, '/')) != NULL) {
498 && (name = strchr(value, '/')) != NULL)
504 b->a_group_style = sty;
505 if (sty == ACL_STYLE_REGEX) {
506 acl_regex_normalized_dn( right, &bv );
507 if ( !ber_bvccmp( &bv, '*' ) ) {
508 regtest(fname, lineno, bv.bv_val);
512 ber_str2bv( right, 0, 0, &bv );
513 rc = dnNormalize2( NULL, &bv, &b->a_group_pat );
514 if ( rc != LDAP_SUCCESS ) {
516 "%s: line %d: bad DN \"%s\"\n",
517 fname, lineno, right );
522 if (value && *value) {
523 b->a_group_oc = oc_find( value );
526 if( b->a_group_oc == NULL ) {
528 "%s: line %d: group objectclass "
530 fname, lineno, value );
534 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
536 if( b->a_group_oc == NULL ) {
538 "%s: line %d: group default objectclass "
540 fname, lineno, SLAPD_GROUP_CLASS );
545 if( is_object_subclass( slap_schema.si_oc_referral,
549 "%s: line %d: group objectclass \"%s\" "
550 "is subclass of referral\n",
551 fname, lineno, value );
555 if( is_object_subclass( slap_schema.si_oc_alias,
559 "%s: line %d: group objectclass \"%s\" "
560 "is subclass of alias\n",
561 fname, lineno, value );
566 rc = slap_str2ad( name, &b->a_group_at, &text );
568 if( rc != LDAP_SUCCESS ) {
570 "%s: line %d: group \"%s\": %s\n",
571 fname, lineno, right, text );
576 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
578 if( rc != LDAP_SUCCESS ) {
580 "%s: line %d: group \"%s\": %s\n",
581 fname, lineno, SLAPD_GROUP_ATTR, text );
586 if( !is_at_syntax( b->a_group_at->ad_type,
588 !is_at_syntax( b->a_group_at->ad_type,
589 SLAPD_NAMEUID_SYNTAX ) )
592 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
593 fname, lineno, right,
594 b->a_group_at->ad_type->sat_syntax_oid );
601 struct berval vals[2];
603 vals[0].bv_val = b->a_group_oc->soc_oid;
604 vals[0].bv_len = strlen(vals[0].bv_val);
605 vals[1].bv_val = NULL;
608 rc = oc_check_allowed( b->a_group_at->ad_type, vals, NULL );
612 "%s: line %d: group: \"%s\" not allowed by \"%s\"\n",
614 b->a_group_at->ad_cname.bv_val,
615 b->a_group_oc->soc_oid );
622 if ( strcasecmp( left, "peername" ) == 0 ) {
623 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
625 "%s: line %d: inappropriate style \"%s\" in by clause\n",
626 fname, lineno, style );
630 if ( right == NULL || right[ 0 ] == '\0' ) {
632 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
633 fname, lineno, left );
637 if( b->a_peername_pat.bv_len ) {
639 "%s: line %d: peername pattern already specified.\n",
644 b->a_peername_style = sty;
645 if (sty == ACL_STYLE_REGEX) {
646 acl_regex_normalized_dn( right, &bv );
647 if ( !ber_bvccmp( &bv, '*' ) ) {
648 regtest(fname, lineno, bv.bv_val);
650 b->a_peername_pat = bv;
652 ber_str2bv( right, 0, 1, &b->a_peername_pat );
657 if ( strcasecmp( left, "sockname" ) == 0 ) {
658 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
660 "%s: line %d: inappropriate style \"%s\" in by clause\n",
661 fname, lineno, style );
665 if ( right == NULL || right[ 0 ] == '\0' ) {
667 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
668 fname, lineno, left );
672 if( b->a_sockname_pat.bv_len ) {
674 "%s: line %d: sockname pattern already specified.\n",
679 b->a_sockname_style = sty;
680 if (sty == ACL_STYLE_REGEX) {
681 acl_regex_normalized_dn( right, &bv );
682 if ( !ber_bvccmp( &bv, '*' ) ) {
683 regtest(fname, lineno, bv.bv_val);
685 b->a_sockname_pat = bv;
687 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
692 if ( strcasecmp( left, "domain" ) == 0 ) {
694 case ACL_STYLE_REGEX:
696 case ACL_STYLE_SUBTREE:
701 "%s: line %d: inappropriate style \"%s\" in by clause\n",
702 fname, lineno, style );
706 if ( right == NULL || right[ 0 ] == '\0' ) {
708 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
709 fname, lineno, left );
713 if( b->a_domain_pat.bv_len ) {
715 "%s: line %d: domain pattern already specified.\n",
720 b->a_domain_style = sty;
721 b->a_domain_expand = expand;
722 if (sty == ACL_STYLE_REGEX) {
723 acl_regex_normalized_dn( right, &bv );
724 if ( !ber_bvccmp( &bv, '*' ) ) {
725 regtest(fname, lineno, bv.bv_val);
727 b->a_domain_pat = bv;
729 ber_str2bv( right, 0, 1, &b->a_domain_pat );
734 if ( strcasecmp( left, "sockurl" ) == 0 ) {
735 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
737 "%s: line %d: inappropriate style \"%s\" in by clause\n",
738 fname, lineno, style );
742 if ( right == NULL || right[ 0 ] == '\0' ) {
744 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
745 fname, lineno, left );
749 if( b->a_sockurl_pat.bv_len ) {
751 "%s: line %d: sockurl pattern already specified.\n",
756 b->a_sockurl_style = sty;
757 if (sty == ACL_STYLE_REGEX) {
758 acl_regex_normalized_dn( right, &bv );
759 if ( !ber_bvccmp( &bv, '*' ) ) {
760 regtest(fname, lineno, bv.bv_val);
762 b->a_sockurl_pat = bv;
764 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
769 if ( strcasecmp( left, "set" ) == 0 ) {
770 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
772 "%s: line %d: inappropriate style \"%s\" in by clause\n",
773 fname, lineno, style );
777 if( b->a_set_pat.bv_len != 0 ) {
779 "%s: line %d: set attribute already specified.\n",
784 if ( right == NULL || *right == '\0' ) {
786 "%s: line %d: no set is defined\n",
791 b->a_set_style = sty;
792 ber_str2bv( right, 0, 1, &b->a_set_pat );
797 #ifdef SLAPD_ACI_ENABLED
798 if ( strcasecmp( left, "aci" ) == 0 ) {
799 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
801 "%s: line %d: inappropriate style \"%s\" in by clause\n",
802 fname, lineno, style );
806 if( b->a_aci_at != NULL ) {
808 "%s: line %d: aci attribute already specified.\n",
813 if ( right != NULL && *right != '\0' ) {
814 rc = slap_str2ad( right, &b->a_aci_at, &text );
816 if( rc != LDAP_SUCCESS ) {
818 "%s: line %d: aci \"%s\": %s\n",
819 fname, lineno, right, text );
824 b->a_aci_at = slap_schema.si_ad_aci;
827 if( !is_at_syntax( b->a_aci_at->ad_type,
831 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
832 fname, lineno, right,
833 b->a_aci_at->ad_type->sat_syntax_oid );
839 #endif /* SLAPD_ACI_ENABLED */
841 if ( strcasecmp( left, "ssf" ) == 0 ) {
842 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
844 "%s: line %d: inappropriate style \"%s\" in by clause\n",
845 fname, lineno, style );
849 if( b->a_authz.sai_ssf ) {
851 "%s: line %d: ssf attribute already specified.\n",
856 if ( right == NULL || *right == '\0' ) {
858 "%s: line %d: no ssf is defined\n",
863 b->a_authz.sai_ssf = atoi( right );
865 if( !b->a_authz.sai_ssf ) {
867 "%s: line %d: invalid ssf value (%s)\n",
868 fname, lineno, right );
874 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
875 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
877 "%s: line %d: inappropriate style \"%s\" in by clause\n",
878 fname, lineno, style );
882 if( b->a_authz.sai_transport_ssf ) {
884 "%s: line %d: transport_ssf attribute already specified.\n",
889 if ( right == NULL || *right == '\0' ) {
891 "%s: line %d: no transport_ssf is defined\n",
896 b->a_authz.sai_transport_ssf = atoi( right );
898 if( !b->a_authz.sai_transport_ssf ) {
900 "%s: line %d: invalid transport_ssf value (%s)\n",
901 fname, lineno, right );
907 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
908 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
910 "%s: line %d: inappropriate style \"%s\" in by clause\n",
911 fname, lineno, style );
915 if( b->a_authz.sai_tls_ssf ) {
917 "%s: line %d: tls_ssf attribute already specified.\n",
922 if ( right == NULL || *right == '\0' ) {
924 "%s: line %d: no tls_ssf is defined\n",
929 b->a_authz.sai_tls_ssf = atoi( right );
931 if( !b->a_authz.sai_tls_ssf ) {
933 "%s: line %d: invalid tls_ssf value (%s)\n",
934 fname, lineno, right );
940 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
941 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
943 "%s: line %d: inappropriate style \"%s\" in by clause\n",
944 fname, lineno, style );
948 if( b->a_authz.sai_sasl_ssf ) {
950 "%s: line %d: sasl_ssf attribute already specified.\n",
955 if ( right == NULL || *right == '\0' ) {
957 "%s: line %d: no sasl_ssf is defined\n",
962 b->a_authz.sai_sasl_ssf = atoi( right );
964 if( !b->a_authz.sai_sasl_ssf ) {
966 "%s: line %d: invalid sasl_ssf value (%s)\n",
967 fname, lineno, right );
973 if( right != NULL ) {
980 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
981 /* out of arguments or plain stop */
983 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
984 b->a_type = ACL_STOP;
986 access_append( &a->acl_access, b );
990 if( strcasecmp( left, "continue" ) == 0 ) {
993 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
994 b->a_type = ACL_CONTINUE;
996 access_append( &a->acl_access, b );
1000 if( strcasecmp( left, "break" ) == 0 ) {
1001 /* plain continue */
1003 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1004 b->a_type = ACL_BREAK;
1006 access_append( &a->acl_access, b );
1010 if ( strcasecmp( left, "by" ) == 0 ) {
1011 /* we've gone too far */
1013 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1014 b->a_type = ACL_STOP;
1016 access_append( &a->acl_access, b );
1021 if( strncasecmp( left, "self", 4 ) == 0 ) {
1023 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
1026 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1029 if( ACL_IS_INVALID( b->a_access_mask ) ) {
1031 "%s: line %d: expecting <access> got \"%s\"\n",
1032 fname, lineno, left );
1036 b->a_type = ACL_STOP;
1039 /* out of arguments or plain stop */
1040 access_append( &a->acl_access, b );
1044 if( strcasecmp( argv[i], "continue" ) == 0 ) {
1045 /* plain continue */
1046 b->a_type = ACL_CONTINUE;
1048 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
1049 /* plain continue */
1050 b->a_type = ACL_BREAK;
1052 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1057 access_append( &a->acl_access, b );
1061 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
1062 fname, lineno, argv[i] );
1067 /* if we have no real access clause, complain and do nothing */
1070 "%s: line %d: warning: no access clause(s) specified in access line\n",
1075 if (ldap_debug & LDAP_DEBUG_ACL)
1079 if ( a->acl_access == NULL ) {
1081 "%s: line %d: warning: no by clause(s) specified in access line\n",
1086 acl_append( &be->be_acl, a );
1088 acl_append( &global_acl, a );
1094 accessmask2str( slap_mask_t mask, char *buf )
1099 assert( buf != NULL );
1101 if ( ACL_IS_INVALID( mask ) ) {
1107 if ( ACL_IS_LEVEL( mask ) ) {
1108 if ( ACL_LVL_IS_NONE(mask) ) {
1109 ptr = lutil_strcopy( ptr, "none" );
1111 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1112 ptr = lutil_strcopy( ptr, "auth" );
1114 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1115 ptr = lutil_strcopy( ptr, "compare" );
1117 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1118 ptr = lutil_strcopy( ptr, "search" );
1120 } else if ( ACL_LVL_IS_READ(mask) ) {
1121 ptr = lutil_strcopy( ptr, "read" );
1123 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1124 ptr = lutil_strcopy( ptr, "write" );
1126 ptr = lutil_strcopy( ptr, "unknown" );
1132 if( ACL_IS_ADDITIVE( mask ) ) {
1135 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1142 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1147 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1152 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1157 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1162 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1167 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1176 if ( ACL_IS_LEVEL( mask ) ) {
1186 str2accessmask( const char *str )
1190 if( !ASCII_ALPHA(str[0]) ) {
1193 if ( str[0] == '=' ) {
1196 } else if( str[0] == '+' ) {
1197 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1199 } else if( str[0] == '-' ) {
1200 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1203 ACL_INVALIDATE(mask);
1207 for( i=1; str[i] != '\0'; i++ ) {
1208 if( TOLOWER((unsigned char) str[i]) == 'w' ) {
1209 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1211 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
1212 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1214 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
1215 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1217 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
1218 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1220 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
1221 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1223 } else if( str[i] != '0' ) {
1224 ACL_INVALIDATE(mask);
1232 if ( strcasecmp( str, "none" ) == 0 ) {
1233 ACL_LVL_ASSIGN_NONE(mask);
1235 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1236 ACL_LVL_ASSIGN_AUTH(mask);
1238 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1239 ACL_LVL_ASSIGN_COMPARE(mask);
1241 } else if ( strcasecmp( str, "search" ) == 0 ) {
1242 ACL_LVL_ASSIGN_SEARCH(mask);
1244 } else if ( strcasecmp( str, "read" ) == 0 ) {
1245 ACL_LVL_ASSIGN_READ(mask);
1247 } else if ( strcasecmp( str, "write" ) == 0 ) {
1248 ACL_LVL_ASSIGN_WRITE(mask);
1251 ACL_INVALIDATE( mask );
1260 fprintf( stderr, "\n"
1261 "<access clause> ::= access to <what> "
1262 "[ by <who> <access> [ <control> ] ]+ \n"
1263 "<what> ::= * | [dn[.<dnstyle>]=<regex>] [filter=<ldapfilter>] [attrs=<attrlist>]\n"
1264 "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
1265 "<attr> ::= <attrname> | entry | children\n"
1266 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<regex> ]\n"
1267 "\t[dnattr=<attrname>]\n"
1268 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<regex>]\n"
1269 "\t[peername[.<style>]=<regex>] [sockname[.<style>]=<regex>]\n"
1270 "\t[domain[.<style>]=<regex>] [sockurl[.<style>]=<regex>]\n"
1271 #ifdef SLAPD_ACI_ENABLED
1272 "\t[aci=<attrname>]\n"
1274 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1275 "<dnstyle> ::= regex | base | exact (alias of base) | one | sub | children\n"
1276 "<style> ::= regex | base | exact (alias of base)\n"
1277 "<groupflags> ::= R\n"
1278 "<access> ::= [self]{<level>|<priv>}\n"
1279 "<level> ::= none | auth | compare | search | read | write\n"
1280 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
1281 "<control> ::= [ stop | continue | break ]\n"
1283 exit( EXIT_FAILURE );
1287 * Set pattern to a "normalized" DN from src.
1288 * At present it simply eats the (optional) space after
1289 * a RDN separator (,)
1290 * Eventually will evolve in a more complete normalization
1293 acl_regex_normalized_dn(
1295 struct berval *pattern
1301 str = ch_strdup( src );
1302 len = strlen( src );
1304 for ( p = str; p && p[ 0 ]; p++ ) {
1306 if ( p[ 0 ] == '\\' && p[ 1 ] ) {
1308 * if escaping a hex pair we should
1309 * increment p twice; however, in that
1310 * case the second hex number does
1316 if ( p[ 0 ] == ',' ) {
1317 if ( p[ 1 ] == ' ' ) {
1321 * too much space should be
1322 * an error if we are pedantic
1324 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1327 AC_MEMCPY( p+1, q, len-(q-str)+1);
1331 pattern->bv_val = str;
1332 pattern->bv_len = p-str;
1346 if ( (*right = strchr( line, splitchar )) != NULL ) {
1347 *((*right)++) = '\0';
1352 access_append( Access **l, Access *a )
1354 for ( ; *l != NULL; l = &(*l)->a_next )
1361 acl_append( AccessControl **l, AccessControl *a )
1363 for ( ; *l != NULL; l = &(*l)->acl_next )
1370 access_free( Access *a )
1372 if ( a->a_dn_pat.bv_val )
1373 free ( a->a_dn_pat.bv_val );
1374 if ( a->a_peername_pat.bv_val )
1375 free ( a->a_peername_pat.bv_val );
1376 if ( a->a_sockname_pat.bv_val )
1377 free ( a->a_sockname_pat.bv_val );
1378 if ( a->a_domain_pat.bv_val )
1379 free ( a->a_domain_pat.bv_val );
1380 if ( a->a_sockurl_pat.bv_val )
1381 free ( a->a_sockurl_pat.bv_val );
1382 if ( a->a_set_pat.bv_len )
1383 free ( a->a_set_pat.bv_val );
1384 if ( a->a_group_pat.bv_len )
1385 free ( a->a_group_pat.bv_val );
1390 acl_free( AccessControl *a )
1395 if ( a->acl_filter )
1396 filter_free( a->acl_filter );
1397 if ( a->acl_dn_pat.bv_len )
1398 free ( a->acl_dn_pat.bv_val );
1399 if ( a->acl_attrs ) {
1400 for ( an = a->acl_attrs; an->an_name.bv_val; an++ ) {
1401 free( an->an_name.bv_val );
1403 free( a->acl_attrs );
1405 for (; a->acl_access; a->acl_access = n) {
1406 n = a->acl_access->a_next;
1407 access_free( a->acl_access );
1412 /* Because backend_startup uses acl_append to tack on the global_acl to
1413 * the end of each backend's acl, we cannot just take one argument and
1414 * merrily free our way to the end of the list. backend_destroy calls us
1415 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1416 * point. config_destroy calls us with global_acl in arg1 and NULL in
1417 * arg2, so we then proceed to polish off the global_acl.
1420 acl_destroy( AccessControl *a, AccessControl *end )
1424 for (; a && a!= end; a=n) {
1431 access2str( slap_access_t access )
1433 if ( access == ACL_NONE ) {
1436 } else if ( access == ACL_AUTH ) {
1439 } else if ( access == ACL_COMPARE ) {
1442 } else if ( access == ACL_SEARCH ) {
1445 } else if ( access == ACL_READ ) {
1448 } else if ( access == ACL_WRITE ) {
1456 str2access( const char *str )
1458 if ( strcasecmp( str, "none" ) == 0 ) {
1461 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1464 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1467 } else if ( strcasecmp( str, "search" ) == 0 ) {
1470 } else if ( strcasecmp( str, "read" ) == 0 ) {
1473 } else if ( strcasecmp( str, "write" ) == 0 ) {
1477 return( ACL_INVALID_ACCESS );
1482 static char *style_strings[5] = {
1492 print_access( Access *b )
1494 char maskbuf[ACCESSMASK_MAXLEN];
1496 fprintf( stderr, "\tby" );
1498 if ( b->a_dn_pat.bv_len != 0 ) {
1499 if( strcmp(b->a_dn_pat.bv_val, "*") == 0
1500 || strcmp(b->a_dn_pat.bv_val, "users") == 0
1501 || strcmp(b->a_dn_pat.bv_val, "anonymous") == 0
1502 || strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1504 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1507 fprintf( stderr, " dn.%s=%s",
1508 style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1512 if ( b->a_dn_at != NULL ) {
1513 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1516 if ( b->a_group_pat.bv_len ) {
1517 fprintf( stderr, " group=%s", b->a_group_pat.bv_val );
1519 if ( b->a_group_oc ) {
1520 fprintf( stderr, " objectClass: %s",
1521 b->a_group_oc->soc_oclass.oc_oid );
1523 if ( b->a_group_at ) {
1524 fprintf( stderr, " attributeType: %s", b->a_group_at->ad_cname.bv_val );
1529 if ( b->a_peername_pat.bv_len != 0 ) {
1530 fprintf( stderr, " peername=%s", b->a_peername_pat.bv_val );
1533 if ( b->a_sockname_pat.bv_len != 0 ) {
1534 fprintf( stderr, " sockname=%s", b->a_sockname_pat.bv_val );
1537 if ( b->a_domain_pat.bv_len != 0 ) {
1538 fprintf( stderr, " domain=%s", b->a_domain_pat.bv_val );
1541 if ( b->a_sockurl_pat.bv_len != 0 ) {
1542 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat.bv_val );
1545 #ifdef SLAPD_ACI_ENABLED
1546 if ( b->a_aci_at != NULL ) {
1547 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1551 /* Security Strength Factors */
1552 if ( b->a_authz.sai_ssf ) {
1553 fprintf( stderr, " ssf=%u",
1554 b->a_authz.sai_ssf );
1556 if ( b->a_authz.sai_transport_ssf ) {
1557 fprintf( stderr, " transport_ssf=%u",
1558 b->a_authz.sai_transport_ssf );
1560 if ( b->a_authz.sai_tls_ssf ) {
1561 fprintf( stderr, " tls_ssf=%u",
1562 b->a_authz.sai_tls_ssf );
1564 if ( b->a_authz.sai_sasl_ssf ) {
1565 fprintf( stderr, " sasl_ssf=%u",
1566 b->a_authz.sai_sasl_ssf );
1569 fprintf( stderr, " %s%s",
1570 b->a_dn_self ? "self" : "",
1571 accessmask2str( b->a_access_mask, maskbuf ) );
1573 if( b->a_type == ACL_BREAK ) {
1574 fprintf( stderr, " break" );
1576 } else if( b->a_type == ACL_CONTINUE ) {
1577 fprintf( stderr, " continue" );
1579 } else if( b->a_type != ACL_STOP ) {
1580 fprintf( stderr, " unknown-control" );
1583 fprintf( stderr, "\n" );
1588 print_acl( Backend *be, AccessControl *a )
1593 fprintf( stderr, "%s ACL: access to",
1594 be == NULL ? "Global" : "Backend" );
1596 if ( a->acl_dn_pat.bv_len != 0 ) {
1598 fprintf( stderr, " dn.%s=%s\n",
1599 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
1602 if ( a->acl_filter != NULL ) {
1603 struct berval bv = { 0, NULL };
1605 filter2bv( a->acl_filter, &bv );
1606 fprintf( stderr, " filter=%s\n", bv.bv_val );
1607 ch_free( bv.bv_val );
1610 if ( a->acl_attrs != NULL ) {
1615 fprintf( stderr, " attrs=" );
1616 for ( an = a->acl_attrs; an && an->an_name.bv_val; an++ ) {
1618 fprintf( stderr, "," );
1620 fputs( an->an_name.bv_val, stderr );
1623 fprintf( stderr, "\n" );
1627 fprintf( stderr, " *\n" );
1630 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1634 fprintf( stderr, "\n" );
1637 #endif /* LDAP_DEBUG */