1 /* aclparse.c - routines to parse and check acl's */
4 * Copyright 1998-2000 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>
20 static void split(char *line, int splitchar, char **left, char **right);
21 static void access_append(Access **l, Access *a);
22 static void acl_usage(void) LDAP_GCCATTR((noreturn));
24 static char *acl_regex_normalized_dn(const char *pattern);
27 static void print_acl(Backend *be, AccessControl *a);
28 static void print_access(Access *b);
32 regtest(const char *fname, int lineno, char *pat) {
48 for (size = 0, flag = 0; (size < sizeof(buf)) && *sp; sp++) {
50 if (*sp == '$'|| (*sp >= '0' && *sp <= '9')) {
67 if ( size >= (sizeof(buf)-1) ) {
69 "%s: line %d: regular expression \"%s\" too large\n",
74 if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
76 regerror(e, &re, error, sizeof(error));
78 "%s: line %d: regular expression \"%s\" bad because of %s\n",
79 fname, lineno, pat, error );
97 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;
157 if ( strcmp(right, "*") == 0
158 || strcmp(right, ".*") == 0
159 || strcmp(right, ".*$") == 0
160 || strcmp(right, "^.*") == 0
161 || strcmp(right, "^.*$$") == 0
162 || strcmp(right, ".*$$") == 0
163 || strcmp(right, "^.*$$") == 0 )
165 a->acl_dn_pat.bv_val = ch_strdup( "*" );
166 a->acl_dn_pat.bv_len = 1;
169 a->acl_dn_pat.bv_val = acl_regex_normalized_dn( right );
170 a->acl_dn_pat.bv_len = strlen( a->acl_dn_pat.bv_val );
172 } else if ( strcasecmp( style, "base" ) == 0 ) {
173 a->acl_dn_style = ACL_STYLE_BASE;
174 a->acl_dn_pat.bv_val = ch_strdup( right );
175 a->acl_dn_pat.bv_len = strlen( right );
177 } else if ( strcasecmp( style, "one" ) == 0 ) {
178 a->acl_dn_style = ACL_STYLE_ONE;
179 a->acl_dn_pat.bv_val = ch_strdup( right );
180 a->acl_dn_pat.bv_len = strlen( right );
182 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
183 a->acl_dn_style = ACL_STYLE_SUBTREE;
184 a->acl_dn_pat.bv_val = ch_strdup( right );
185 a->acl_dn_pat.bv_len = strlen( right );
187 } else if ( strcasecmp( style, "children" ) == 0 ) {
188 a->acl_dn_style = ACL_STYLE_CHILDREN;
189 a->acl_dn_pat.bv_val = ch_strdup( right );
190 a->acl_dn_pat.bv_len = strlen( right );
194 "%s: line %d: unknown dn style \"%s\" in to clause\n",
195 fname, lineno, style );
202 if ( strcasecmp( left, "filter" ) == 0 ) {
203 if ( (a->acl_filter = str2filter(
206 "%s: line %d: bad filter \"%s\" in to clause\n",
207 fname, lineno, right );
211 } else if ( strncasecmp( left, "attr", 4 ) == 0 ) {
214 alist = str2charray( right, "," );
215 charray_merge( &a->acl_attrs, alist );
216 charray_free( alist );
220 "%s: line %d: expecting <what> got \"%s\"\n",
221 fname, lineno, left );
226 if ( a->acl_dn_pat.bv_len != 0 && strcmp(a->acl_dn_pat.bv_val, "*") == 0) {
227 free( a->acl_dn_pat.bv_val );
228 a->acl_dn_pat.bv_val = NULL;
229 a->acl_dn_pat.bv_len = 0;
232 if( a->acl_dn_pat.bv_len != 0 ) {
233 if ( a->acl_dn_style != ACL_STYLE_REGEX )
235 struct berval *bv = NULL;
236 dnNormalize( NULL, &a->acl_dn_pat, &bv);
237 free( a->acl_dn_pat.bv_val );
241 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
242 REG_EXTENDED | REG_ICASE );
245 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
247 "%s: line %d: regular expression \"%s\" bad because of %s\n",
248 fname, lineno, right, buf );
254 /* by clause - select who has what access to entries */
255 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
258 "%s: line %d: to clause required before by clause in access line\n",
264 * by clause consists of <who> and <access>
267 b = (Access *) ch_calloc( 1, sizeof(Access) );
269 ACL_INVALIDATE( b->a_access_mask );
273 "%s: line %d: premature eol: expecting <who>\n",
279 for ( ; i < argc; i++ ) {
281 slap_style_t sty = ACL_STYLE_REGEX;
283 split( argv[i], '=', &left, &right );
284 split( left, '.', &left, &style );
285 if ( style == NULL || *style == '\0'
286 || strcasecmp( style, "regex" ) == 0 )
288 sty = ACL_STYLE_REGEX;
289 } else if ( strcasecmp( style, "exact" ) == 0 ) {
290 sty = ACL_STYLE_EXACT;
291 } else if ( strcasecmp( style, "base" ) == 0 ) {
292 sty = ACL_STYLE_BASE;
293 } else if ( strcasecmp( style, "one" ) == 0 ) {
295 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
296 sty = ACL_STYLE_SUBTREE;
297 } else if ( strcasecmp( style, "children" ) == 0 ) {
298 sty = ACL_STYLE_CHILDREN;
301 "%s: line %d: unknown style \"%s\" in by clause\n",
302 fname, lineno, style );
306 if ( strcasecmp( argv[i], "*" ) == 0 ) {
307 pat = ch_strdup( "*" );
309 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
310 pat = ch_strdup( "anonymous" );
312 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
313 pat = ch_strdup( "self" );
315 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
316 pat = ch_strdup( "users" );
318 } else if ( strcasecmp( left, "dn" ) == 0 ) {
319 if ( sty == ACL_STYLE_REGEX ) {
320 b->a_dn_style = ACL_STYLE_REGEX;
321 if( right == NULL ) {
323 pat = ch_strdup( "users" );
325 } else if (*right == '\0' ) {
327 pat = ch_strdup( "anonymous" );
329 } else if ( strcmp( right, "*" ) == 0 ) {
331 /* any or users? users for now */
332 pat = ch_strdup( "users" );
334 } else if ( strcmp( right, ".+" ) == 0
335 || strcmp( right, "^.+" ) == 0
336 || strcmp( right, ".+$" ) == 0
337 || strcmp( right, "^.+$" ) == 0
338 || strcmp( right, ".+$$" ) == 0
339 || strcmp( right, "^.+$$" ) == 0 )
341 pat = ch_strdup( "users" );
343 } else if ( strcmp( right, ".*" ) == 0
344 || strcmp( right, "^.*" ) == 0
345 || strcmp( right, ".*$" ) == 0
346 || strcmp( right, "^.*$" ) == 0
347 || strcmp( right, ".*$$" ) == 0
348 || strcmp( right, "^.*$$" ) == 0 )
350 pat = ch_strdup( "*" );
353 pat = acl_regex_normalized_dn( right );
354 regtest(fname, lineno, pat);
356 } else if ( right == NULL || *right == '\0' ) {
358 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
359 fname, lineno, left );
363 pat = ch_strdup( right );
371 if( b->a_dn_pat.bv_len != 0 ) {
373 "%s: line %d: dn pattern already specified.\n",
378 b->a_dn_pat.bv_val = pat;
379 b->a_dn_pat.bv_len = strlen( pat );
381 if ( sty != ACL_STYLE_REGEX )
386 if ( strcasecmp( left, "dnattr" ) == 0 ) {
387 if ( right == NULL || right[ 0 ] == '\0' ) {
389 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
390 fname, lineno, left );
394 if( b->a_dn_at != NULL ) {
396 "%s: line %d: dnattr already specified.\n",
401 rc = slap_str2ad( right, &b->a_dn_at, &text );
403 if( rc != LDAP_SUCCESS ) {
405 "%s: line %d: dnattr \"%s\": %s\n",
406 fname, lineno, right, text );
411 if( !is_at_syntax( b->a_dn_at->ad_type,
413 !is_at_syntax( b->a_dn_at->ad_type,
414 SLAPD_NAMEUID_SYNTAX ))
417 "%s: line %d: dnattr \"%s\": "
418 "inappropriate syntax: %s\n",
419 fname, lineno, right,
420 b->a_dn_at->ad_type->sat_syntax_oid );
427 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
429 "%s: line %d: inappropriate style \"%s\" in by clause\n",
430 fname, lineno, style );
434 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
438 if ( right == NULL || right[ 0 ] == '\0' ) {
440 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
441 fname, lineno, left );
445 if( b->a_group_pat != NULL ) {
447 "%s: line %d: group pattern already specified.\n",
452 /* format of string is "group/objectClassValue/groupAttrName" */
453 if ((value = strchr(left, '/')) != NULL) {
456 && (name = strchr(value, '/')) != NULL)
462 b->a_group_style = sty;
463 if (sty == ACL_STYLE_REGEX) {
464 char *tmp = acl_regex_normalized_dn( right );
465 regtest(fname, lineno, tmp);
466 b->a_group_pat = tmp;
468 b->a_group_pat = ch_strdup( right );
469 dn_normalize(b->a_group_pat);
472 if (value && *value) {
473 b->a_group_oc = oc_find( value );
476 if( b->a_group_oc == NULL ) {
478 "%s: line %d: group objectclass "
480 fname, lineno, value );
484 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
486 if( b->a_group_oc == NULL ) {
488 "%s: line %d: group default objectclass "
490 fname, lineno, SLAPD_GROUP_CLASS );
495 if( is_object_subclass( b->a_group_oc,
496 slap_schema.si_oc_referral ) )
499 "%s: line %d: group objectclass \"%s\" "
500 "is subclass of referral\n",
501 fname, lineno, value );
505 if( is_object_subclass( b->a_group_oc,
506 slap_schema.si_oc_alias ) )
509 "%s: line %d: group objectclass \"%s\" "
510 "is subclass of alias\n",
511 fname, lineno, value );
516 rc = slap_str2ad( name, &b->a_group_at, &text );
518 if( rc != LDAP_SUCCESS ) {
520 "%s: line %d: group \"%s\": %s\n",
521 fname, lineno, right, text );
526 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
528 if( rc != LDAP_SUCCESS ) {
530 "%s: line %d: group \"%s\": %s\n",
531 fname, lineno, SLAPD_GROUP_ATTR, text );
536 if( !is_at_syntax( b->a_group_at->ad_type,
538 !is_at_syntax( b->a_group_at->ad_type,
539 SLAPD_NAMEUID_SYNTAX ) )
542 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
543 fname, lineno, right,
544 b->a_group_at->ad_type->sat_syntax_oid );
552 struct berval *vals[2];
554 val.bv_val = b->a_group_oc->soc_oid;
555 val.bv_len = strlen(val.bv_val);
560 rc = oc_check_allowed( b->a_group_at->ad_type, vals, NULL );
564 "%s: line %d: group: \"%s\" not allowed by \"%s\"\n",
566 b->a_group_at->ad_cname.bv_val,
567 b->a_group_oc->soc_oid );
574 if ( strcasecmp( left, "peername" ) == 0 ) {
575 if ( right == NULL || right[ 0 ] == '\0' ) {
577 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
578 fname, lineno, left );
582 if( b->a_peername_pat != NULL ) {
584 "%s: line %d: peername pattern already specified.\n",
589 b->a_peername_style = sty;
590 if (sty == ACL_STYLE_REGEX) {
591 char *tmp = acl_regex_normalized_dn( right );
592 regtest(fname, lineno, tmp);
593 b->a_peername_pat = tmp;
595 b->a_peername_pat = ch_strdup( right );
600 if ( strcasecmp( left, "sockname" ) == 0 ) {
601 if ( right == NULL || right[ 0 ] == '\0' ) {
603 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
604 fname, lineno, left );
608 if( b->a_sockname_pat != NULL ) {
610 "%s: line %d: sockname pattern already specified.\n",
615 b->a_sockname_style = sty;
616 if (sty == ACL_STYLE_REGEX) {
617 char *tmp = acl_regex_normalized_dn( right );
618 regtest(fname, lineno, tmp);
619 b->a_sockname_pat = tmp;
621 b->a_sockname_pat = ch_strdup( right );
626 if ( strcasecmp( left, "domain" ) == 0 ) {
627 if ( right == NULL || right[ 0 ] == '\0' ) {
629 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
630 fname, lineno, left );
634 if( b->a_domain_pat != NULL ) {
636 "%s: line %d: domain pattern already specified.\n",
641 b->a_domain_style = sty;
642 if (sty == ACL_STYLE_REGEX) {
643 char *tmp = acl_regex_normalized_dn( right );
644 regtest(fname, lineno, tmp);
645 b->a_domain_pat = tmp;
647 b->a_domain_pat = ch_strdup( right );
652 if ( strcasecmp( left, "sockurl" ) == 0 ) {
653 if ( right == NULL || right[ 0 ] == '\0' ) {
655 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
656 fname, lineno, left );
660 if( b->a_sockurl_pat != NULL ) {
662 "%s: line %d: sockurl pattern already specified.\n",
667 b->a_sockurl_style = sty;
668 if (sty == ACL_STYLE_REGEX) {
669 char *tmp = acl_regex_normalized_dn( right );
670 regtest(fname, lineno, tmp);
671 b->a_sockurl_pat = tmp;
673 b->a_sockurl_pat = ch_strdup( right );
678 if ( strcasecmp( left, "set" ) == 0 ) {
679 if( b->a_set_pat.bv_len != 0 ) {
681 "%s: line %d: set attribute already specified.\n",
686 if ( right == NULL || *right == '\0' ) {
688 "%s: line %d: no set is defined\n",
693 b->a_set_style = sty;
694 b->a_set_pat.bv_val = ch_strdup(right);
695 b->a_set_pat.bv_len = strlen(right);
700 #ifdef SLAPD_ACI_ENABLED
701 if ( strcasecmp( left, "aci" ) == 0 ) {
702 if( b->a_aci_at != NULL ) {
704 "%s: line %d: aci attribute already specified.\n",
709 if ( right != NULL && *right != '\0' ) {
710 rc = slap_str2ad( right, &b->a_aci_at, &text );
712 if( rc != LDAP_SUCCESS ) {
714 "%s: line %d: aci \"%s\": %s\n",
715 fname, lineno, right, text );
720 rc = slap_str2ad( SLAPD_ACI_ATTR, &b->a_aci_at, &text );
722 if( rc != LDAP_SUCCESS ) {
724 "%s: line %d: aci \"%s\": %s\n",
725 fname, lineno, SLAPD_ACI_ATTR, text );
730 if( !is_at_syntax( b->a_aci_at->ad_type,
734 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
735 fname, lineno, right,
736 b->a_aci_at->ad_type->sat_syntax_oid );
742 #endif /* SLAPD_ACI_ENABLED */
744 if ( strcasecmp( left, "ssf" ) == 0 ) {
745 if( b->a_authz.sai_ssf ) {
747 "%s: line %d: ssf attribute already specified.\n",
752 if ( right == NULL || *right == '\0' ) {
754 "%s: line %d: no ssf is defined\n",
759 b->a_authz.sai_ssf = atoi( right );
761 if( !b->a_authz.sai_ssf ) {
763 "%s: line %d: invalid ssf value (%s)\n",
764 fname, lineno, right );
770 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
771 if( b->a_authz.sai_transport_ssf ) {
773 "%s: line %d: transport_ssf attribute already specified.\n",
778 if ( right == NULL || *right == '\0' ) {
780 "%s: line %d: no transport_ssf is defined\n",
785 b->a_authz.sai_transport_ssf = atoi( right );
787 if( !b->a_authz.sai_transport_ssf ) {
789 "%s: line %d: invalid transport_ssf value (%s)\n",
790 fname, lineno, right );
796 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
797 if( b->a_authz.sai_tls_ssf ) {
799 "%s: line %d: tls_ssf attribute already specified.\n",
804 if ( right == NULL || *right == '\0' ) {
806 "%s: line %d: no tls_ssf is defined\n",
811 b->a_authz.sai_tls_ssf = atoi( right );
813 if( !b->a_authz.sai_tls_ssf ) {
815 "%s: line %d: invalid tls_ssf value (%s)\n",
816 fname, lineno, right );
822 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
823 if( b->a_authz.sai_sasl_ssf ) {
825 "%s: line %d: sasl_ssf attribute already specified.\n",
830 if ( right == NULL || *right == '\0' ) {
832 "%s: line %d: no sasl_ssf is defined\n",
837 b->a_authz.sai_sasl_ssf = atoi( right );
839 if( !b->a_authz.sai_sasl_ssf ) {
841 "%s: line %d: invalid sasl_ssf value (%s)\n",
842 fname, lineno, right );
848 if( right != NULL ) {
855 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
856 /* out of arguments or plain stop */
858 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
859 b->a_type = ACL_STOP;
861 access_append( &a->acl_access, b );
865 if( strcasecmp( left, "continue" ) == 0 ) {
868 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
869 b->a_type = ACL_CONTINUE;
871 access_append( &a->acl_access, b );
875 if( strcasecmp( left, "break" ) == 0 ) {
878 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
879 b->a_type = ACL_BREAK;
881 access_append( &a->acl_access, b );
885 if ( strcasecmp( left, "by" ) == 0 ) {
886 /* we've gone too far */
888 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
889 b->a_type = ACL_STOP;
891 access_append( &a->acl_access, b );
896 if( strncasecmp( left, "self", 4 ) == 0 ) {
898 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
901 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
904 if( ACL_IS_INVALID( b->a_access_mask ) ) {
906 "%s: line %d: expecting <access> got \"%s\"\n",
907 fname, lineno, left );
911 b->a_type = ACL_STOP;
914 /* out of arguments or plain stop */
915 access_append( &a->acl_access, b );
919 if( strcasecmp( argv[i], "continue" ) == 0 ) {
921 b->a_type = ACL_CONTINUE;
923 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
925 b->a_type = ACL_BREAK;
927 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
932 access_append( &a->acl_access, b );
936 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
937 fname, lineno, argv[i] );
942 /* if we have no real access clause, complain and do nothing */
945 "%s: line %d: warning: no access clause(s) specified in access line\n",
950 if (ldap_debug & LDAP_DEBUG_ACL)
954 if ( a->acl_access == NULL ) {
956 "%s: line %d: warning: no by clause(s) specified in access line\n",
961 acl_append( &be->be_acl, a );
963 acl_append( &global_acl, a );
969 accessmask2str( slap_mask_t mask, char *buf )
973 assert( buf != NULL );
975 if ( ACL_IS_INVALID( mask ) ) {
981 if ( ACL_IS_LEVEL( mask ) ) {
982 if ( ACL_LVL_IS_NONE(mask) ) {
983 strcat( buf, "none" );
985 } else if ( ACL_LVL_IS_AUTH(mask) ) {
986 strcat( buf, "auth" );
988 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
989 strcat( buf, "compare" );
991 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
992 strcat( buf, "search" );
994 } else if ( ACL_LVL_IS_READ(mask) ) {
995 strcat( buf, "read" );
997 } else if ( ACL_LVL_IS_WRITE(mask) ) {
998 strcat( buf, "write" );
1000 strcat( buf, "unknown" );
1006 if( ACL_IS_ADDITIVE( mask ) ) {
1009 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1016 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1021 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1026 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1031 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1036 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1041 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1050 if ( ACL_IS_LEVEL( mask ) ) {
1057 str2accessmask( const char *str )
1061 if( !ASCII_ALPHA(str[0]) ) {
1064 if ( str[0] == '=' ) {
1067 } else if( str[0] == '+' ) {
1068 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1070 } else if( str[0] == '-' ) {
1071 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1074 ACL_INVALIDATE(mask);
1078 for( i=1; str[i] != '\0'; i++ ) {
1079 if( TOLOWER(str[i]) == 'w' ) {
1080 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1082 } else if( TOLOWER(str[i]) == 'r' ) {
1083 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1085 } else if( TOLOWER(str[i]) == 's' ) {
1086 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1088 } else if( TOLOWER(str[i]) == 'c' ) {
1089 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1091 } else if( TOLOWER(str[i]) == 'x' ) {
1092 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1094 } else if( str[i] != '0' ) {
1095 ACL_INVALIDATE(mask);
1103 if ( strcasecmp( str, "none" ) == 0 ) {
1104 ACL_LVL_ASSIGN_NONE(mask);
1106 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1107 ACL_LVL_ASSIGN_AUTH(mask);
1109 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1110 ACL_LVL_ASSIGN_COMPARE(mask);
1112 } else if ( strcasecmp( str, "search" ) == 0 ) {
1113 ACL_LVL_ASSIGN_SEARCH(mask);
1115 } else if ( strcasecmp( str, "read" ) == 0 ) {
1116 ACL_LVL_ASSIGN_READ(mask);
1118 } else if ( strcasecmp( str, "write" ) == 0 ) {
1119 ACL_LVL_ASSIGN_WRITE(mask);
1122 ACL_INVALIDATE( mask );
1131 fprintf( stderr, "\n"
1132 "<access clause> ::= access to <what> "
1133 "[ by <who> <access> [ <control> ] ]+ \n"
1134 "<what> ::= * | [dn[.<dnstyle>]=<regex>] [filter=<ldapfilter>] [attrs=<attrlist>]\n"
1135 "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
1136 "<attr> ::= <attrname> | entry | children\n"
1137 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<regex> ]\n"
1138 "\t[dnattr=<attrname>]\n"
1139 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<regex>]\n"
1140 "\t[peername[.<style>]=<regex>] [sockname[.<style>]=<regex>]\n"
1141 "\t[domain[.<style>]=<regex>] [sockurl[.<style>]=<regex>]\n"
1142 #ifdef SLAPD_ACI_ENABLED
1143 "\t[aci=<attrname>]\n"
1145 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1146 "<dnstyle> ::= regex | base | exact (alias of base) | one | sub | children\n"
1147 "<style> ::= regex | base | exact (alias of base)\n"
1148 "<groupflags> ::= R\n"
1149 "<access> ::= [self]{<level>|<priv>}\n"
1150 "<level> ::= none | auth | compare | search | read | write\n"
1151 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
1152 "<control> ::= [ stop | continue | break ]\n"
1154 exit( EXIT_FAILURE );
1158 * At present it simply eats the (optional) space after
1159 * a RDN separator (,)
1160 * Eventually will evolve in a more complete normalization
1163 acl_regex_normalized_dn(
1169 str = ch_strdup( pattern );
1171 if ( str == NULL ) {
1175 for ( p = str; p[ 0 ]; p++ ) {
1177 if ( p[ 0 ] == '\\' ) {
1181 if ( p[ 0 ] == ',' ) {
1182 if ( p[ 1 ] == ' ' ) {
1185 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1188 AC_MEMCPY( &p[ 1 ], &q[ 0 ], strlen( q ) + 1 );
1205 if ( (*right = strchr( line, splitchar )) != NULL ) {
1206 *((*right)++) = '\0';
1211 access_append( Access **l, Access *a )
1213 for ( ; *l != NULL; l = &(*l)->a_next )
1220 acl_append( AccessControl **l, AccessControl *a )
1222 for ( ; *l != NULL; l = &(*l)->acl_next )
1229 access_free( Access *a )
1231 if ( a->a_dn_pat.bv_val )
1232 free ( a->a_dn_pat.bv_val );
1233 if ( a->a_peername_pat )
1234 free ( a->a_peername_pat );
1235 if ( a->a_sockname_pat )
1236 free ( a->a_sockname_pat );
1237 if ( a->a_domain_pat )
1238 free ( a->a_domain_pat );
1239 if ( a->a_sockurl_pat )
1240 free ( a->a_sockurl_pat );
1241 if ( a->a_set_pat.bv_len )
1242 free ( a->a_set_pat.bv_val );
1243 if ( a->a_group_pat )
1244 free ( a->a_group_pat );
1249 acl_free( AccessControl *a )
1253 if ( a->acl_filter )
1254 filter_free( a->acl_filter );
1255 if ( a->acl_dn_pat.bv_len )
1256 free ( a->acl_dn_pat.bv_val );
1258 charray_free( a->acl_attrs );
1259 for (; a->acl_access; a->acl_access = n) {
1260 n = a->acl_access->a_next;
1261 access_free( a->acl_access );
1266 /* Because backend_startup uses acl_append to tack on the global_acl to
1267 * the end of each backend's acl, we cannot just take one argument and
1268 * merrily free our way to the end of the list. backend_destroy calls us
1269 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1270 * point. config_destroy calls us with global_acl in arg1 and NULL in
1271 * arg2, so we then proceed to polish off the global_acl.
1274 acl_destroy( AccessControl *a, AccessControl *end )
1278 for (; a && a!= end; a=n) {
1285 access2str( slap_access_t access )
1287 if ( access == ACL_NONE ) {
1290 } else if ( access == ACL_AUTH ) {
1293 } else if ( access == ACL_COMPARE ) {
1296 } else if ( access == ACL_SEARCH ) {
1299 } else if ( access == ACL_READ ) {
1302 } else if ( access == ACL_WRITE ) {
1310 str2access( const char *str )
1312 if ( strcasecmp( str, "none" ) == 0 ) {
1315 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1318 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1321 } else if ( strcasecmp( str, "search" ) == 0 ) {
1324 } else if ( strcasecmp( str, "read" ) == 0 ) {
1327 } else if ( strcasecmp( str, "write" ) == 0 ) {
1331 return( ACL_INVALID_ACCESS );
1336 static char *style_strings[5] = {
1346 print_access( Access *b )
1348 char maskbuf[ACCESSMASK_MAXLEN];
1350 fprintf( stderr, "\tby" );
1352 if ( b->a_dn_pat.bv_len != 0 ) {
1353 if( strcmp(b->a_dn_pat.bv_val, "*") == 0
1354 || strcmp(b->a_dn_pat.bv_val, "users") == 0
1355 || strcmp(b->a_dn_pat.bv_val, "anonymous") == 0
1356 || strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1358 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1361 fprintf( stderr, " dn.%s=%s", style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1365 if ( b->a_dn_at != NULL ) {
1366 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1369 if ( b->a_group_pat != NULL ) {
1370 fprintf( stderr, " group=%s", b->a_group_pat );
1372 if ( b->a_group_oc ) {
1373 fprintf( stderr, " objectClass: %s",
1374 b->a_group_oc->soc_oclass.oc_oid );
1376 if ( b->a_group_at ) {
1377 fprintf( stderr, " attributeType: %s", b->a_group_at->ad_cname.bv_val );
1382 if ( b->a_peername_pat != NULL ) {
1383 fprintf( stderr, " peername=%s", b->a_peername_pat );
1386 if ( b->a_sockname_pat != NULL ) {
1387 fprintf( stderr, " sockname=%s", b->a_sockname_pat );
1390 if ( b->a_domain_pat != NULL ) {
1391 fprintf( stderr, " domain=%s", b->a_domain_pat );
1394 if ( b->a_sockurl_pat != NULL ) {
1395 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat );
1398 #ifdef SLAPD_ACI_ENABLED
1399 if ( b->a_aci_at != NULL ) {
1400 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1404 /* Security Strength Factors */
1405 if ( b->a_authz.sai_ssf ) {
1406 fprintf( stderr, " ssf=%u",
1407 b->a_authz.sai_ssf );
1409 if ( b->a_authz.sai_transport_ssf ) {
1410 fprintf( stderr, " transport_ssf=%u",
1411 b->a_authz.sai_transport_ssf );
1413 if ( b->a_authz.sai_tls_ssf ) {
1414 fprintf( stderr, " tls_ssf=%u",
1415 b->a_authz.sai_tls_ssf );
1417 if ( b->a_authz.sai_sasl_ssf ) {
1418 fprintf( stderr, " sasl_ssf=%u",
1419 b->a_authz.sai_sasl_ssf );
1422 fprintf( stderr, " %s%s",
1423 b->a_dn_self ? "self" : "",
1424 accessmask2str( b->a_access_mask, maskbuf ) );
1426 if( b->a_type == ACL_BREAK ) {
1427 fprintf( stderr, " break" );
1429 } else if( b->a_type == ACL_CONTINUE ) {
1430 fprintf( stderr, " continue" );
1432 } else if( b->a_type != ACL_STOP ) {
1433 fprintf( stderr, " unknown-control" );
1436 fprintf( stderr, "\n" );
1441 print_acl( Backend *be, AccessControl *a )
1446 fprintf( stderr, "%s ACL: access to",
1447 be == NULL ? "Global" : "Backend" );
1449 if ( a->acl_dn_pat.bv_len != 0 ) {
1451 fprintf( stderr, " dn.%s=%s\n",
1452 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
1455 if ( a->acl_filter != NULL ) {
1457 fprintf( stderr, " filter=" );
1458 filter_print( a->acl_filter );
1459 fprintf( stderr, "\n" );
1462 if ( a->acl_attrs != NULL ) {
1466 fprintf( stderr, " attrs=" );
1467 for ( i = 0; a->acl_attrs[i] != NULL; i++ ) {
1469 fprintf( stderr, "," );
1471 fprintf( stderr, a->acl_attrs[i] );
1474 fprintf( stderr, "\n" );
1478 fprintf( stderr, " *\n" );
1481 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1485 fprintf( stderr, "\n" );
1488 #endif /* LDAP_DEBUG */