1 /* aclparse.c - routines to parse and check acl's */
4 * Copyright 1998-2003 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 || strcasecmp( style, "sub" ) == 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 || strcasecmp( style, "sub" ) == 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 );
467 if( b->a_dn_at->ad_type->sat_equality == NULL )
470 "%s: line %d: dnattr \"%s\": "
471 "inappropriate matching (no EQUALITY)\n",
472 fname, lineno, right );
479 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
483 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
485 "%s: line %d: inappropriate style \"%s\" in by clause\n",
486 fname, lineno, style );
490 if ( right == NULL || right[ 0 ] == '\0' ) {
492 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
493 fname, lineno, left );
497 if( b->a_group_pat.bv_len ) {
499 "%s: line %d: group pattern already specified.\n",
504 /* format of string is "group/objectClassValue/groupAttrName" */
505 if ((value = strchr(left, '/')) != NULL) {
508 && (name = strchr(value, '/')) != NULL)
514 b->a_group_style = sty;
515 if (sty == ACL_STYLE_REGEX) {
516 acl_regex_normalized_dn( right, &bv );
517 if ( !ber_bvccmp( &bv, '*' ) ) {
518 regtest(fname, lineno, bv.bv_val);
522 ber_str2bv( right, 0, 0, &bv );
523 rc = dnNormalize2( NULL, &bv, &b->a_group_pat );
524 if ( rc != LDAP_SUCCESS ) {
526 "%s: line %d: bad DN \"%s\"\n",
527 fname, lineno, right );
532 if (value && *value) {
533 b->a_group_oc = oc_find( value );
536 if( b->a_group_oc == NULL ) {
538 "%s: line %d: group objectclass "
540 fname, lineno, value );
544 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
546 if( b->a_group_oc == NULL ) {
548 "%s: line %d: group default objectclass "
550 fname, lineno, SLAPD_GROUP_CLASS );
555 if( is_object_subclass( slap_schema.si_oc_referral,
559 "%s: line %d: group objectclass \"%s\" "
560 "is subclass of referral\n",
561 fname, lineno, value );
565 if( is_object_subclass( slap_schema.si_oc_alias,
569 "%s: line %d: group objectclass \"%s\" "
570 "is subclass of alias\n",
571 fname, lineno, value );
576 rc = slap_str2ad( name, &b->a_group_at, &text );
578 if( rc != LDAP_SUCCESS ) {
580 "%s: line %d: group \"%s\": %s\n",
581 fname, lineno, right, text );
586 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
588 if( rc != LDAP_SUCCESS ) {
590 "%s: line %d: group \"%s\": %s\n",
591 fname, lineno, SLAPD_GROUP_ATTR, text );
596 if( !is_at_syntax( b->a_group_at->ad_type,
598 !is_at_syntax( b->a_group_at->ad_type,
599 SLAPD_NAMEUID_SYNTAX ) )
602 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
603 fname, lineno, right,
604 b->a_group_at->ad_type->sat_syntax_oid );
611 struct berval vals[2];
613 vals[0].bv_val = b->a_group_oc->soc_oid;
614 vals[0].bv_len = strlen(vals[0].bv_val);
615 vals[1].bv_val = NULL;
618 rc = oc_check_allowed( b->a_group_at->ad_type, vals, NULL );
622 "%s: line %d: group: \"%s\" not allowed by \"%s\"\n",
624 b->a_group_at->ad_cname.bv_val,
625 b->a_group_oc->soc_oid );
632 if ( strcasecmp( left, "peername" ) == 0 ) {
633 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
635 "%s: line %d: inappropriate style \"%s\" in by clause\n",
636 fname, lineno, style );
640 if ( right == NULL || right[ 0 ] == '\0' ) {
642 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
643 fname, lineno, left );
647 if( b->a_peername_pat.bv_len ) {
649 "%s: line %d: peername pattern already specified.\n",
654 b->a_peername_style = sty;
655 if (sty == ACL_STYLE_REGEX) {
656 acl_regex_normalized_dn( right, &bv );
657 if ( !ber_bvccmp( &bv, '*' ) ) {
658 regtest(fname, lineno, bv.bv_val);
660 b->a_peername_pat = bv;
662 ber_str2bv( right, 0, 1, &b->a_peername_pat );
667 if ( strcasecmp( left, "sockname" ) == 0 ) {
668 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
670 "%s: line %d: inappropriate style \"%s\" in by clause\n",
671 fname, lineno, style );
675 if ( right == NULL || right[ 0 ] == '\0' ) {
677 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
678 fname, lineno, left );
682 if( b->a_sockname_pat.bv_len ) {
684 "%s: line %d: sockname pattern already specified.\n",
689 b->a_sockname_style = sty;
690 if (sty == ACL_STYLE_REGEX) {
691 acl_regex_normalized_dn( right, &bv );
692 if ( !ber_bvccmp( &bv, '*' ) ) {
693 regtest(fname, lineno, bv.bv_val);
695 b->a_sockname_pat = bv;
697 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
702 if ( strcasecmp( left, "domain" ) == 0 ) {
704 case ACL_STYLE_REGEX:
706 case ACL_STYLE_SUBTREE:
711 "%s: line %d: inappropriate style \"%s\" in by clause\n",
712 fname, lineno, style );
716 if ( right == NULL || right[ 0 ] == '\0' ) {
718 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
719 fname, lineno, left );
723 if( b->a_domain_pat.bv_len ) {
725 "%s: line %d: domain pattern already specified.\n",
730 b->a_domain_style = sty;
731 b->a_domain_expand = expand;
732 if (sty == ACL_STYLE_REGEX) {
733 acl_regex_normalized_dn( right, &bv );
734 if ( !ber_bvccmp( &bv, '*' ) ) {
735 regtest(fname, lineno, bv.bv_val);
737 b->a_domain_pat = bv;
739 ber_str2bv( right, 0, 1, &b->a_domain_pat );
744 if ( strcasecmp( left, "sockurl" ) == 0 ) {
745 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
747 "%s: line %d: inappropriate style \"%s\" in by clause\n",
748 fname, lineno, style );
752 if ( right == NULL || right[ 0 ] == '\0' ) {
754 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
755 fname, lineno, left );
759 if( b->a_sockurl_pat.bv_len ) {
761 "%s: line %d: sockurl pattern already specified.\n",
766 b->a_sockurl_style = sty;
767 if (sty == ACL_STYLE_REGEX) {
768 acl_regex_normalized_dn( right, &bv );
769 if ( !ber_bvccmp( &bv, '*' ) ) {
770 regtest(fname, lineno, bv.bv_val);
772 b->a_sockurl_pat = bv;
774 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
779 if ( strcasecmp( left, "set" ) == 0 ) {
780 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
782 "%s: line %d: inappropriate style \"%s\" in by clause\n",
783 fname, lineno, style );
787 if( b->a_set_pat.bv_len != 0 ) {
789 "%s: line %d: set attribute already specified.\n",
794 if ( right == NULL || *right == '\0' ) {
796 "%s: line %d: no set is defined\n",
801 b->a_set_style = sty;
802 ber_str2bv( right, 0, 1, &b->a_set_pat );
807 #ifdef SLAPD_ACI_ENABLED
808 if ( strcasecmp( left, "aci" ) == 0 ) {
809 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
811 "%s: line %d: inappropriate style \"%s\" in by clause\n",
812 fname, lineno, style );
816 if( b->a_aci_at != NULL ) {
818 "%s: line %d: aci attribute already specified.\n",
823 if ( right != NULL && *right != '\0' ) {
824 rc = slap_str2ad( right, &b->a_aci_at, &text );
826 if( rc != LDAP_SUCCESS ) {
828 "%s: line %d: aci \"%s\": %s\n",
829 fname, lineno, right, text );
834 b->a_aci_at = slap_schema.si_ad_aci;
837 if( !is_at_syntax( b->a_aci_at->ad_type,
841 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
842 fname, lineno, right,
843 b->a_aci_at->ad_type->sat_syntax_oid );
849 #endif /* SLAPD_ACI_ENABLED */
851 if ( strcasecmp( left, "ssf" ) == 0 ) {
852 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
854 "%s: line %d: inappropriate style \"%s\" in by clause\n",
855 fname, lineno, style );
859 if( b->a_authz.sai_ssf ) {
861 "%s: line %d: ssf attribute already specified.\n",
866 if ( right == NULL || *right == '\0' ) {
868 "%s: line %d: no ssf is defined\n",
873 b->a_authz.sai_ssf = atoi( right );
875 if( !b->a_authz.sai_ssf ) {
877 "%s: line %d: invalid ssf value (%s)\n",
878 fname, lineno, right );
884 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
885 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
887 "%s: line %d: inappropriate style \"%s\" in by clause\n",
888 fname, lineno, style );
892 if( b->a_authz.sai_transport_ssf ) {
894 "%s: line %d: transport_ssf attribute already specified.\n",
899 if ( right == NULL || *right == '\0' ) {
901 "%s: line %d: no transport_ssf is defined\n",
906 b->a_authz.sai_transport_ssf = atoi( right );
908 if( !b->a_authz.sai_transport_ssf ) {
910 "%s: line %d: invalid transport_ssf value (%s)\n",
911 fname, lineno, right );
917 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
918 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
920 "%s: line %d: inappropriate style \"%s\" in by clause\n",
921 fname, lineno, style );
925 if( b->a_authz.sai_tls_ssf ) {
927 "%s: line %d: tls_ssf attribute already specified.\n",
932 if ( right == NULL || *right == '\0' ) {
934 "%s: line %d: no tls_ssf is defined\n",
939 b->a_authz.sai_tls_ssf = atoi( right );
941 if( !b->a_authz.sai_tls_ssf ) {
943 "%s: line %d: invalid tls_ssf value (%s)\n",
944 fname, lineno, right );
950 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
951 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
953 "%s: line %d: inappropriate style \"%s\" in by clause\n",
954 fname, lineno, style );
958 if( b->a_authz.sai_sasl_ssf ) {
960 "%s: line %d: sasl_ssf attribute already specified.\n",
965 if ( right == NULL || *right == '\0' ) {
967 "%s: line %d: no sasl_ssf is defined\n",
972 b->a_authz.sai_sasl_ssf = atoi( right );
974 if( !b->a_authz.sai_sasl_ssf ) {
976 "%s: line %d: invalid sasl_ssf value (%s)\n",
977 fname, lineno, right );
983 if( right != NULL ) {
990 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
991 /* out of arguments or plain stop */
993 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
994 b->a_type = ACL_STOP;
996 access_append( &a->acl_access, b );
1000 if( strcasecmp( left, "continue" ) == 0 ) {
1001 /* plain continue */
1003 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1004 b->a_type = ACL_CONTINUE;
1006 access_append( &a->acl_access, b );
1010 if( strcasecmp( left, "break" ) == 0 ) {
1011 /* plain continue */
1013 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1014 b->a_type = ACL_BREAK;
1016 access_append( &a->acl_access, b );
1020 if ( strcasecmp( left, "by" ) == 0 ) {
1021 /* we've gone too far */
1023 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1024 b->a_type = ACL_STOP;
1026 access_append( &a->acl_access, b );
1031 if( strncasecmp( left, "self", 4 ) == 0 ) {
1033 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
1036 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1039 if( ACL_IS_INVALID( b->a_access_mask ) ) {
1041 "%s: line %d: expecting <access> got \"%s\"\n",
1042 fname, lineno, left );
1046 b->a_type = ACL_STOP;
1049 /* out of arguments or plain stop */
1050 access_append( &a->acl_access, b );
1054 if( strcasecmp( argv[i], "continue" ) == 0 ) {
1055 /* plain continue */
1056 b->a_type = ACL_CONTINUE;
1058 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
1059 /* plain continue */
1060 b->a_type = ACL_BREAK;
1062 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1067 access_append( &a->acl_access, b );
1071 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
1072 fname, lineno, argv[i] );
1077 /* if we have no real access clause, complain and do nothing */
1080 "%s: line %d: warning: no access clause(s) specified in access line\n",
1085 if (ldap_debug & LDAP_DEBUG_ACL)
1089 if ( a->acl_access == NULL ) {
1091 "%s: line %d: warning: no by clause(s) specified in access line\n",
1096 acl_append( &be->be_acl, a );
1098 acl_append( &global_acl, a );
1104 accessmask2str( slap_mask_t mask, char *buf )
1109 assert( buf != NULL );
1111 if ( ACL_IS_INVALID( mask ) ) {
1117 if ( ACL_IS_LEVEL( mask ) ) {
1118 if ( ACL_LVL_IS_NONE(mask) ) {
1119 ptr = lutil_strcopy( ptr, "none" );
1121 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1122 ptr = lutil_strcopy( ptr, "auth" );
1124 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1125 ptr = lutil_strcopy( ptr, "compare" );
1127 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1128 ptr = lutil_strcopy( ptr, "search" );
1130 } else if ( ACL_LVL_IS_READ(mask) ) {
1131 ptr = lutil_strcopy( ptr, "read" );
1133 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1134 ptr = lutil_strcopy( ptr, "write" );
1136 ptr = lutil_strcopy( ptr, "unknown" );
1142 if( ACL_IS_ADDITIVE( mask ) ) {
1145 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1152 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1157 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1162 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1167 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1172 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1177 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1186 if ( ACL_IS_LEVEL( mask ) ) {
1196 str2accessmask( const char *str )
1200 if( !ASCII_ALPHA(str[0]) ) {
1203 if ( str[0] == '=' ) {
1206 } else if( str[0] == '+' ) {
1207 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1209 } else if( str[0] == '-' ) {
1210 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1213 ACL_INVALIDATE(mask);
1217 for( i=1; str[i] != '\0'; i++ ) {
1218 if( TOLOWER((unsigned char) str[i]) == 'w' ) {
1219 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1221 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
1222 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1224 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
1225 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1227 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
1228 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1230 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
1231 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1233 } else if( str[i] != '0' ) {
1234 ACL_INVALIDATE(mask);
1242 if ( strcasecmp( str, "none" ) == 0 ) {
1243 ACL_LVL_ASSIGN_NONE(mask);
1245 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1246 ACL_LVL_ASSIGN_AUTH(mask);
1248 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1249 ACL_LVL_ASSIGN_COMPARE(mask);
1251 } else if ( strcasecmp( str, "search" ) == 0 ) {
1252 ACL_LVL_ASSIGN_SEARCH(mask);
1254 } else if ( strcasecmp( str, "read" ) == 0 ) {
1255 ACL_LVL_ASSIGN_READ(mask);
1257 } else if ( strcasecmp( str, "write" ) == 0 ) {
1258 ACL_LVL_ASSIGN_WRITE(mask);
1261 ACL_INVALIDATE( mask );
1270 fprintf( stderr, "\n"
1271 "<access clause> ::= access to <what> "
1272 "[ by <who> <access> [ <control> ] ]+ \n"
1273 "<what> ::= * | [dn[.<dnstyle>]=<regex>] [filter=<ldapfilter>] [attrs=<attrlist>]\n"
1274 "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
1275 "<attr> ::= <attrname> | entry | children\n"
1276 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<regex> ]\n"
1277 "\t[dnattr=<attrname>]\n"
1278 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<regex>]\n"
1279 "\t[peername[.<style>]=<regex>] [sockname[.<style>]=<regex>]\n"
1280 "\t[domain[.<style>]=<regex>] [sockurl[.<style>]=<regex>]\n"
1281 #ifdef SLAPD_ACI_ENABLED
1282 "\t[aci=<attrname>]\n"
1284 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1285 "<dnstyle> ::= regex | base | exact (alias of base) | one | subtree | children\n"
1286 "<style> ::= regex | base | exact (alias of base)\n"
1287 "<groupflags> ::= R\n"
1288 "<access> ::= [self]{<level>|<priv>}\n"
1289 "<level> ::= none | auth | compare | search | read | write\n"
1290 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
1291 "<control> ::= [ stop | continue | break ]\n"
1293 exit( EXIT_FAILURE );
1297 * Set pattern to a "normalized" DN from src.
1298 * At present it simply eats the (optional) space after
1299 * a RDN separator (,)
1300 * Eventually will evolve in a more complete normalization
1303 acl_regex_normalized_dn(
1305 struct berval *pattern
1311 str = ch_strdup( src );
1312 len = strlen( src );
1314 for ( p = str; p && p[ 0 ]; p++ ) {
1316 if ( p[ 0 ] == '\\' && p[ 1 ] ) {
1318 * if escaping a hex pair we should
1319 * increment p twice; however, in that
1320 * case the second hex number does
1326 if ( p[ 0 ] == ',' ) {
1327 if ( p[ 1 ] == ' ' ) {
1331 * too much space should be
1332 * an error if we are pedantic
1334 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1337 AC_MEMCPY( p+1, q, len-(q-str)+1);
1341 pattern->bv_val = str;
1342 pattern->bv_len = p-str;
1356 if ( (*right = strchr( line, splitchar )) != NULL ) {
1357 *((*right)++) = '\0';
1362 access_append( Access **l, Access *a )
1364 for ( ; *l != NULL; l = &(*l)->a_next )
1371 acl_append( AccessControl **l, AccessControl *a )
1373 for ( ; *l != NULL; l = &(*l)->acl_next )
1380 access_free( Access *a )
1382 if ( a->a_dn_pat.bv_val )
1383 free ( a->a_dn_pat.bv_val );
1384 if ( a->a_peername_pat.bv_val )
1385 free ( a->a_peername_pat.bv_val );
1386 if ( a->a_sockname_pat.bv_val )
1387 free ( a->a_sockname_pat.bv_val );
1388 if ( a->a_domain_pat.bv_val )
1389 free ( a->a_domain_pat.bv_val );
1390 if ( a->a_sockurl_pat.bv_val )
1391 free ( a->a_sockurl_pat.bv_val );
1392 if ( a->a_set_pat.bv_len )
1393 free ( a->a_set_pat.bv_val );
1394 if ( a->a_group_pat.bv_len )
1395 free ( a->a_group_pat.bv_val );
1400 acl_free( AccessControl *a )
1405 if ( a->acl_filter )
1406 filter_free( a->acl_filter );
1407 if ( a->acl_dn_pat.bv_len )
1408 free ( a->acl_dn_pat.bv_val );
1409 if ( a->acl_attrs ) {
1410 for ( an = a->acl_attrs; an->an_name.bv_val; an++ ) {
1411 free( an->an_name.bv_val );
1413 free( a->acl_attrs );
1415 for (; a->acl_access; a->acl_access = n) {
1416 n = a->acl_access->a_next;
1417 access_free( a->acl_access );
1422 /* Because backend_startup uses acl_append to tack on the global_acl to
1423 * the end of each backend's acl, we cannot just take one argument and
1424 * merrily free our way to the end of the list. backend_destroy calls us
1425 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1426 * point. config_destroy calls us with global_acl in arg1 and NULL in
1427 * arg2, so we then proceed to polish off the global_acl.
1430 acl_destroy( AccessControl *a, AccessControl *end )
1434 for (; a && a!= end; a=n) {
1441 access2str( slap_access_t access )
1443 if ( access == ACL_NONE ) {
1446 } else if ( access == ACL_AUTH ) {
1449 } else if ( access == ACL_COMPARE ) {
1452 } else if ( access == ACL_SEARCH ) {
1455 } else if ( access == ACL_READ ) {
1458 } else if ( access == ACL_WRITE ) {
1466 str2access( const char *str )
1468 if ( strcasecmp( str, "none" ) == 0 ) {
1471 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1474 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1477 } else if ( strcasecmp( str, "search" ) == 0 ) {
1480 } else if ( strcasecmp( str, "read" ) == 0 ) {
1483 } else if ( strcasecmp( str, "write" ) == 0 ) {
1487 return( ACL_INVALID_ACCESS );
1492 static char *style_strings[5] = {
1502 print_access( Access *b )
1504 char maskbuf[ACCESSMASK_MAXLEN];
1506 fprintf( stderr, "\tby" );
1508 if ( b->a_dn_pat.bv_len != 0 ) {
1509 if( strcmp(b->a_dn_pat.bv_val, "*") == 0
1510 || strcmp(b->a_dn_pat.bv_val, "users") == 0
1511 || strcmp(b->a_dn_pat.bv_val, "anonymous") == 0
1512 || strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1514 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1517 fprintf( stderr, " dn.%s=%s",
1518 style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1522 if ( b->a_dn_at != NULL ) {
1523 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1526 if ( b->a_group_pat.bv_len ) {
1527 fprintf( stderr, " group=%s", b->a_group_pat.bv_val );
1529 if ( b->a_group_oc ) {
1530 fprintf( stderr, " objectClass: %s",
1531 b->a_group_oc->soc_oclass.oc_oid );
1533 if ( b->a_group_at ) {
1534 fprintf( stderr, " attributeType: %s", b->a_group_at->ad_cname.bv_val );
1539 if ( b->a_peername_pat.bv_len != 0 ) {
1540 fprintf( stderr, " peername=%s", b->a_peername_pat.bv_val );
1543 if ( b->a_sockname_pat.bv_len != 0 ) {
1544 fprintf( stderr, " sockname=%s", b->a_sockname_pat.bv_val );
1547 if ( b->a_domain_pat.bv_len != 0 ) {
1548 fprintf( stderr, " domain=%s", b->a_domain_pat.bv_val );
1551 if ( b->a_sockurl_pat.bv_len != 0 ) {
1552 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat.bv_val );
1555 #ifdef SLAPD_ACI_ENABLED
1556 if ( b->a_aci_at != NULL ) {
1557 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1561 /* Security Strength Factors */
1562 if ( b->a_authz.sai_ssf ) {
1563 fprintf( stderr, " ssf=%u",
1564 b->a_authz.sai_ssf );
1566 if ( b->a_authz.sai_transport_ssf ) {
1567 fprintf( stderr, " transport_ssf=%u",
1568 b->a_authz.sai_transport_ssf );
1570 if ( b->a_authz.sai_tls_ssf ) {
1571 fprintf( stderr, " tls_ssf=%u",
1572 b->a_authz.sai_tls_ssf );
1574 if ( b->a_authz.sai_sasl_ssf ) {
1575 fprintf( stderr, " sasl_ssf=%u",
1576 b->a_authz.sai_sasl_ssf );
1579 fprintf( stderr, " %s%s",
1580 b->a_dn_self ? "self" : "",
1581 accessmask2str( b->a_access_mask, maskbuf ) );
1583 if( b->a_type == ACL_BREAK ) {
1584 fprintf( stderr, " break" );
1586 } else if( b->a_type == ACL_CONTINUE ) {
1587 fprintf( stderr, " continue" );
1589 } else if( b->a_type != ACL_STOP ) {
1590 fprintf( stderr, " unknown-control" );
1593 fprintf( stderr, "\n" );
1598 print_acl( Backend *be, AccessControl *a )
1603 fprintf( stderr, "%s ACL: access to",
1604 be == NULL ? "Global" : "Backend" );
1606 if ( a->acl_dn_pat.bv_len != 0 ) {
1608 fprintf( stderr, " dn.%s=%s\n",
1609 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
1612 if ( a->acl_filter != NULL ) {
1613 struct berval bv = { 0, NULL };
1615 filter2bv( a->acl_filter, &bv );
1616 fprintf( stderr, " filter=%s\n", bv.bv_val );
1617 ch_free( bv.bv_val );
1620 if ( a->acl_attrs != NULL ) {
1625 fprintf( stderr, " attrs=" );
1626 for ( an = a->acl_attrs; an && an->an_name.bv_val; an++ ) {
1628 fprintf( stderr, "," );
1630 fputs( an->an_name.bv_val, stderr );
1633 fprintf( stderr, "\n" );
1637 fprintf( stderr, " *\n" );
1640 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1644 fprintf( stderr, "\n" );
1647 #endif /* LDAP_DEBUG */