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 a->acl_filter = NULL;
115 a->acl_dn_pat = NULL;
117 a->acl_access = NULL;
119 for ( ++i; i < argc; i++ ) {
120 if ( strcasecmp( argv[i], "by" ) == 0 ) {
125 if ( strcasecmp( argv[i], "*" ) == 0 ) {
126 if( a->acl_dn_pat != NULL ) {
128 "%s: line %d: dn pattern"
129 " already specified in to clause.\n",
134 a->acl_dn_pat = ch_strdup( "*" );
138 split( argv[i], '=', &left, &right );
139 split( left, '.', &left, &style );
141 if ( right == NULL ) {
143 "%s: line %d: missing \"=\" in \"%s\" in to clause\n",
144 fname, lineno, left );
148 if ( strcasecmp( left, "dn" ) == 0 ) {
149 if( a->acl_dn_pat != NULL ) {
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;
161 if ( strcmp(right, "*") == 0
162 || strcmp(right, ".*") == 0
163 || strcmp(right, ".*$") == 0
164 || strcmp(right, "^.*") == 0
165 || strcmp(right, "^.*$$") == 0
166 || strcmp(right, ".*$$") == 0
167 || strcmp(right, "^.*$$") == 0 )
169 a->acl_dn_pat = ch_strdup( "*" );
172 a->acl_dn_pat = acl_regex_normalized_dn( right );
174 } else if ( strcasecmp( style, "base" ) == 0 ) {
175 a->acl_dn_style = ACL_STYLE_BASE;
176 a->acl_dn_pat = ch_strdup( right );
178 } else if ( strcasecmp( style, "one" ) == 0 ) {
179 a->acl_dn_style = ACL_STYLE_ONE;
180 a->acl_dn_pat = ch_strdup( right );
182 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
183 a->acl_dn_style = ACL_STYLE_SUBTREE;
184 a->acl_dn_pat = ch_strdup( right );
186 } else if ( strcasecmp( style, "children" ) == 0 ) {
187 a->acl_dn_style = ACL_STYLE_CHILDREN;
188 a->acl_dn_pat = ch_strdup( right );
192 "%s: line %d: unknown dn style \"%s\" in to clause\n",
193 fname, lineno, style );
200 if ( strcasecmp( left, "filter" ) == 0 ) {
201 if ( (a->acl_filter = str2filter(
204 "%s: line %d: bad filter \"%s\" in to clause\n",
205 fname, lineno, right );
209 } else if ( strncasecmp( left, "attr", 4 ) == 0 ) {
212 alist = str2charray( right, "," );
213 charray_merge( &a->acl_attrs, alist );
214 charray_free( alist );
218 "%s: line %d: expecting <what> got \"%s\"\n",
219 fname, lineno, left );
224 if ( a->acl_dn_pat != NULL && strcmp(a->acl_dn_pat, "*") == 0) {
225 free( a->acl_dn_pat );
226 a->acl_dn_pat = NULL;
229 if( a->acl_dn_pat != NULL ) {
230 if ( a->acl_dn_style != ACL_STYLE_REGEX )
232 dn_normalize(a->acl_dn_pat);
235 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat,
236 REG_EXTENDED | REG_ICASE );
239 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
241 "%s: line %d: regular expression \"%s\" bad because of %s\n",
242 fname, lineno, right, buf );
248 /* by clause - select who has what access to entries */
249 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
252 "%s: line %d: to clause required before by clause in access line\n",
258 * by clause consists of <who> and <access>
261 b = (Access *) ch_calloc( 1, sizeof(Access) );
263 ACL_INVALIDATE( b->a_access_mask );
267 "%s: line %d: premature eol: expecting <who>\n",
273 for ( ; i < argc; i++ ) {
275 slap_style_t sty = ACL_STYLE_REGEX;
277 split( argv[i], '=', &left, &right );
278 split( left, '.', &left, &style );
279 if ( style == NULL || *style == '\0'
280 || strcasecmp( style, "regex" ) == 0 )
282 sty = ACL_STYLE_REGEX;
283 } else if ( strcasecmp( style, "exact" ) == 0 ) {
284 sty = ACL_STYLE_EXACT;
285 } else if ( strcasecmp( style, "base" ) == 0 ) {
286 sty = ACL_STYLE_BASE;
287 } else if ( strcasecmp( style, "one" ) == 0 ) {
289 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
290 sty = ACL_STYLE_SUBTREE;
291 } else if ( strcasecmp( style, "children" ) == 0 ) {
292 sty = ACL_STYLE_CHILDREN;
295 "%s: line %d: unknown style \"%s\" in by clause\n",
296 fname, lineno, style );
300 if ( strcasecmp( argv[i], "*" ) == 0 ) {
301 pat = ch_strdup( "*" );
303 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
304 pat = ch_strdup( "anonymous" );
306 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
307 pat = ch_strdup( "self" );
309 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
310 pat = ch_strdup( "users" );
312 } else if ( strcasecmp( left, "dn" ) == 0 ) {
313 if ( sty == ACL_STYLE_REGEX ) {
314 b->a_dn_style = ACL_STYLE_REGEX;
315 if( right == NULL ) {
317 pat = ch_strdup( "users" );
319 } else if (*right == '\0' ) {
321 pat = ch_strdup( "anonymous" );
323 } else if ( strcmp( right, "*" ) == 0 ) {
325 /* any or users? users for now */
326 pat = ch_strdup( "users" );
328 } else if ( strcmp( right, ".+" ) == 0
329 || strcmp( right, "^.+" ) == 0
330 || strcmp( right, ".+$" ) == 0
331 || strcmp( right, "^.+$" ) == 0
332 || strcmp( right, ".+$$" ) == 0
333 || strcmp( right, "^.+$$" ) == 0 )
335 pat = ch_strdup( "users" );
337 } else if ( strcmp( right, ".*" ) == 0
338 || strcmp( right, "^.*" ) == 0
339 || strcmp( right, ".*$" ) == 0
340 || strcmp( right, "^.*$" ) == 0
341 || strcmp( right, ".*$$" ) == 0
342 || strcmp( right, "^.*$$" ) == 0 )
344 pat = ch_strdup( "*" );
347 pat = acl_regex_normalized_dn( right );
348 regtest(fname, lineno, pat);
350 } else if ( right == NULL || *right == '\0' ) {
352 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
353 fname, lineno, left );
357 pat = ch_strdup( right );
365 if( b->a_dn_pat != NULL ) {
367 "%s: line %d: dn pattern already specified.\n",
374 if ( sty != ACL_STYLE_REGEX )
379 if ( strcasecmp( left, "dnattr" ) == 0 ) {
380 if ( right == NULL || right[ 0 ] == '\0' ) {
382 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
383 fname, lineno, left );
387 if( b->a_dn_at != NULL ) {
389 "%s: line %d: dnattr already specified.\n",
394 rc = slap_str2ad( right, &b->a_dn_at, &text );
396 if( rc != LDAP_SUCCESS ) {
398 "%s: line %d: dnattr \"%s\": %s\n",
399 fname, lineno, right, text );
404 if( !is_at_syntax( b->a_dn_at->ad_type,
406 !is_at_syntax( b->a_dn_at->ad_type,
407 SLAPD_NAMEUID_SYNTAX ))
410 "%s: line %d: dnattr \"%s\": "
411 "inappropriate syntax: %s\n",
412 fname, lineno, right,
413 b->a_dn_at->ad_type->sat_syntax_oid );
420 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
422 "%s: line %d: inappropriate style \"%s\" in by clause\n",
423 fname, lineno, style );
427 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
431 if ( right == NULL || right[ 0 ] == '\0' ) {
433 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
434 fname, lineno, left );
438 if( b->a_group_pat != NULL ) {
440 "%s: line %d: group pattern already specified.\n",
445 /* format of string is "group/objectClassValue/groupAttrName" */
446 if ((value = strchr(left, '/')) != NULL) {
449 && (name = strchr(value, '/')) != NULL)
455 b->a_group_style = sty;
456 if (sty == ACL_STYLE_REGEX) {
457 char *tmp = acl_regex_normalized_dn( right );
458 regtest(fname, lineno, tmp);
459 b->a_group_pat = tmp;
461 b->a_group_pat = ch_strdup( right );
462 dn_normalize(b->a_group_pat);
465 if (value && *value) {
466 b->a_group_oc = oc_find( value );
469 if( b->a_group_oc == NULL ) {
471 "%s: line %d: group objectclass "
473 fname, lineno, value );
477 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
479 if( b->a_group_oc == NULL ) {
481 "%s: line %d: group default objectclass "
483 fname, lineno, SLAPD_GROUP_CLASS );
488 if( is_object_subclass( b->a_group_oc,
489 slap_schema.si_oc_referral ) )
492 "%s: line %d: group objectclass \"%s\" "
493 "is subclass of referral\n",
494 fname, lineno, value );
498 if( is_object_subclass( b->a_group_oc,
499 slap_schema.si_oc_alias ) )
502 "%s: line %d: group objectclass \"%s\" "
503 "is subclass of alias\n",
504 fname, lineno, value );
509 rc = slap_str2ad( name, &b->a_group_at, &text );
511 if( rc != LDAP_SUCCESS ) {
513 "%s: line %d: group \"%s\": %s\n",
514 fname, lineno, right, text );
519 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
521 if( rc != LDAP_SUCCESS ) {
523 "%s: line %d: group \"%s\": %s\n",
524 fname, lineno, SLAPD_GROUP_ATTR, text );
529 if( !is_at_syntax( b->a_group_at->ad_type,
531 !is_at_syntax( b->a_group_at->ad_type,
532 SLAPD_NAMEUID_SYNTAX ) )
535 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
536 fname, lineno, right,
537 b->a_group_at->ad_type->sat_syntax_oid );
545 struct berval *vals[2];
547 val.bv_val = b->a_group_oc->soc_oid;
548 val.bv_len = strlen(val.bv_val);
553 rc = oc_check_allowed( b->a_group_at->ad_type, vals );
557 "%s: line %d: group: \"%s\" not allowed by \"%s\"\n",
559 b->a_group_at->ad_cname.bv_val,
560 b->a_group_oc->soc_oid );
567 if ( strcasecmp( left, "peername" ) == 0 ) {
568 if ( right == NULL || right[ 0 ] == '\0' ) {
570 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
571 fname, lineno, left );
575 if( b->a_peername_pat != NULL ) {
577 "%s: line %d: peername pattern already specified.\n",
582 b->a_peername_style = sty;
583 if (sty == ACL_STYLE_REGEX) {
584 char *tmp = acl_regex_normalized_dn( right );
585 regtest(fname, lineno, tmp);
586 b->a_peername_pat = tmp;
588 b->a_peername_pat = ch_strdup( right );
593 if ( strcasecmp( left, "sockname" ) == 0 ) {
594 if ( right == NULL || right[ 0 ] == '\0' ) {
596 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
597 fname, lineno, left );
601 if( b->a_sockname_pat != NULL ) {
603 "%s: line %d: sockname pattern already specified.\n",
608 b->a_sockname_style = sty;
609 if (sty == ACL_STYLE_REGEX) {
610 char *tmp = acl_regex_normalized_dn( right );
611 regtest(fname, lineno, tmp);
612 b->a_sockname_pat = tmp;
614 b->a_sockname_pat = ch_strdup( right );
619 if ( strcasecmp( left, "domain" ) == 0 ) {
620 if ( right == NULL || right[ 0 ] == '\0' ) {
622 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
623 fname, lineno, left );
627 if( b->a_domain_pat != NULL ) {
629 "%s: line %d: domain pattern already specified.\n",
634 b->a_domain_style = sty;
635 if (sty == ACL_STYLE_REGEX) {
636 char *tmp = acl_regex_normalized_dn( right );
637 regtest(fname, lineno, tmp);
638 b->a_domain_pat = tmp;
640 b->a_domain_pat = ch_strdup( right );
645 if ( strcasecmp( left, "sockurl" ) == 0 ) {
646 if ( right == NULL || right[ 0 ] == '\0' ) {
648 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
649 fname, lineno, left );
653 if( b->a_sockurl_pat != NULL ) {
655 "%s: line %d: sockurl pattern already specified.\n",
660 b->a_sockurl_style = sty;
661 if (sty == ACL_STYLE_REGEX) {
662 char *tmp = acl_regex_normalized_dn( right );
663 regtest(fname, lineno, tmp);
664 b->a_sockurl_pat = tmp;
666 b->a_sockurl_pat = ch_strdup( right );
671 if ( strcasecmp( left, "set" ) == 0 ) {
672 if( b->a_set_pat != NULL ) {
674 "%s: line %d: set attribute already specified.\n",
679 if ( right == NULL || *right == '\0' ) {
681 "%s: line %d: no set is defined\n",
686 b->a_set_style = sty;
687 b->a_set_pat = ch_strdup(right);
692 #ifdef SLAPD_ACI_ENABLED
693 if ( strcasecmp( left, "aci" ) == 0 ) {
694 if( b->a_aci_at != NULL ) {
696 "%s: line %d: aci attribute already specified.\n",
701 if ( right != NULL && *right != '\0' ) {
702 rc = slap_str2ad( right, &b->a_aci_at, &text );
704 if( rc != LDAP_SUCCESS ) {
706 "%s: line %d: aci \"%s\": %s\n",
707 fname, lineno, right, text );
712 rc = slap_str2ad( SLAPD_ACI_ATTR, &b->a_aci_at, &text );
714 if( rc != LDAP_SUCCESS ) {
716 "%s: line %d: aci \"%s\": %s\n",
717 fname, lineno, SLAPD_ACI_ATTR, text );
722 if( !is_at_syntax( b->a_aci_at->ad_type,
726 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
727 fname, lineno, right,
728 b->a_aci_at->ad_type->sat_syntax_oid );
734 #endif /* SLAPD_ACI_ENABLED */
736 if ( strcasecmp( left, "ssf" ) == 0 ) {
737 if( b->a_authz.sai_ssf ) {
739 "%s: line %d: ssf attribute already specified.\n",
744 if ( right == NULL || *right == '\0' ) {
746 "%s: line %d: no ssf is defined\n",
751 b->a_authz.sai_ssf = atoi( right );
753 if( !b->a_authz.sai_ssf ) {
755 "%s: line %d: invalid ssf value (%s)\n",
756 fname, lineno, right );
762 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
763 if( b->a_authz.sai_transport_ssf ) {
765 "%s: line %d: transport_ssf attribute already specified.\n",
770 if ( right == NULL || *right == '\0' ) {
772 "%s: line %d: no transport_ssf is defined\n",
777 b->a_authz.sai_transport_ssf = atoi( right );
779 if( !b->a_authz.sai_transport_ssf ) {
781 "%s: line %d: invalid transport_ssf value (%s)\n",
782 fname, lineno, right );
788 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
789 if( b->a_authz.sai_tls_ssf ) {
791 "%s: line %d: tls_ssf attribute already specified.\n",
796 if ( right == NULL || *right == '\0' ) {
798 "%s: line %d: no tls_ssf is defined\n",
803 b->a_authz.sai_tls_ssf = atoi( right );
805 if( !b->a_authz.sai_tls_ssf ) {
807 "%s: line %d: invalid tls_ssf value (%s)\n",
808 fname, lineno, right );
814 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
815 if( b->a_authz.sai_sasl_ssf ) {
817 "%s: line %d: sasl_ssf attribute already specified.\n",
822 if ( right == NULL || *right == '\0' ) {
824 "%s: line %d: no sasl_ssf is defined\n",
829 b->a_authz.sai_sasl_ssf = atoi( right );
831 if( !b->a_authz.sai_sasl_ssf ) {
833 "%s: line %d: invalid sasl_ssf value (%s)\n",
834 fname, lineno, right );
840 if( right != NULL ) {
847 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
848 /* out of arguments or plain stop */
850 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
851 b->a_type = ACL_STOP;
853 access_append( &a->acl_access, b );
857 if( strcasecmp( left, "continue" ) == 0 ) {
860 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
861 b->a_type = ACL_CONTINUE;
863 access_append( &a->acl_access, b );
867 if( strcasecmp( left, "break" ) == 0 ) {
870 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
871 b->a_type = ACL_BREAK;
873 access_append( &a->acl_access, b );
877 if ( strcasecmp( left, "by" ) == 0 ) {
878 /* we've gone too far */
880 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
881 b->a_type = ACL_STOP;
883 access_append( &a->acl_access, b );
888 if( strncasecmp( left, "self", 4 ) == 0 ) {
890 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
893 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
896 if( ACL_IS_INVALID( b->a_access_mask ) ) {
898 "%s: line %d: expecting <access> got \"%s\"\n",
899 fname, lineno, left );
903 b->a_type = ACL_STOP;
906 /* out of arguments or plain stop */
907 access_append( &a->acl_access, b );
911 if( strcasecmp( argv[i], "continue" ) == 0 ) {
913 b->a_type = ACL_CONTINUE;
915 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
917 b->a_type = ACL_BREAK;
919 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
924 access_append( &a->acl_access, b );
928 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
929 fname, lineno, argv[i] );
934 /* if we have no real access clause, complain and do nothing */
937 "%s: line %d: warning: no access clause(s) specified in access line\n",
942 if (ldap_debug & LDAP_DEBUG_ACL)
946 if ( a->acl_access == NULL ) {
948 "%s: line %d: warning: no by clause(s) specified in access line\n",
953 acl_append( &be->be_acl, a );
955 acl_append( &global_acl, a );
961 accessmask2str( slap_mask_t mask, char *buf )
965 assert( buf != NULL );
967 if ( ACL_IS_INVALID( mask ) ) {
973 if ( ACL_IS_LEVEL( mask ) ) {
974 if ( ACL_LVL_IS_NONE(mask) ) {
975 strcat( buf, "none" );
977 } else if ( ACL_LVL_IS_AUTH(mask) ) {
978 strcat( buf, "auth" );
980 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
981 strcat( buf, "compare" );
983 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
984 strcat( buf, "search" );
986 } else if ( ACL_LVL_IS_READ(mask) ) {
987 strcat( buf, "read" );
989 } else if ( ACL_LVL_IS_WRITE(mask) ) {
990 strcat( buf, "write" );
992 strcat( buf, "unknown" );
998 if( ACL_IS_ADDITIVE( mask ) ) {
1001 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1008 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1013 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1018 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1023 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1028 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1033 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1042 if ( ACL_IS_LEVEL( mask ) ) {
1049 str2accessmask( const char *str )
1053 if( !ASCII_ALPHA(str[0]) ) {
1056 if ( str[0] == '=' ) {
1059 } else if( str[0] == '+' ) {
1060 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1062 } else if( str[0] == '-' ) {
1063 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1066 ACL_INVALIDATE(mask);
1070 for( i=1; str[i] != '\0'; i++ ) {
1071 if( TOLOWER(str[i]) == 'w' ) {
1072 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1074 } else if( TOLOWER(str[i]) == 'r' ) {
1075 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1077 } else if( TOLOWER(str[i]) == 's' ) {
1078 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1080 } else if( TOLOWER(str[i]) == 'c' ) {
1081 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1083 } else if( TOLOWER(str[i]) == 'x' ) {
1084 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1086 } else if( str[i] != '0' ) {
1087 ACL_INVALIDATE(mask);
1095 if ( strcasecmp( str, "none" ) == 0 ) {
1096 ACL_LVL_ASSIGN_NONE(mask);
1098 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1099 ACL_LVL_ASSIGN_AUTH(mask);
1101 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1102 ACL_LVL_ASSIGN_COMPARE(mask);
1104 } else if ( strcasecmp( str, "search" ) == 0 ) {
1105 ACL_LVL_ASSIGN_SEARCH(mask);
1107 } else if ( strcasecmp( str, "read" ) == 0 ) {
1108 ACL_LVL_ASSIGN_READ(mask);
1110 } else if ( strcasecmp( str, "write" ) == 0 ) {
1111 ACL_LVL_ASSIGN_WRITE(mask);
1114 ACL_INVALIDATE( mask );
1123 fprintf( stderr, "\n"
1124 "<access clause> ::= access to <what> "
1125 "[ by <who> <access> [ <control> ] ]+ \n"
1126 "<what> ::= * | [dn[.<dnstyle>]=<regex>] [filter=<ldapfilter>] [attrs=<attrlist>]\n"
1127 "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
1128 "<attr> ::= <attrname> | entry | children\n"
1129 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<regex> ]\n"
1130 "\t[dnattr=<attrname>]\n"
1131 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<regex>]\n"
1132 "\t[peername[.<style>]=<regex>] [sockname[.<style>]=<regex>]\n"
1133 "\t[domain[.<style>]=<regex>] [sockurl[.<style>]=<regex>]\n"
1134 #ifdef SLAPD_ACI_ENABLED
1135 "\t[aci=<attrname>]\n"
1137 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1138 "<dnstyle> ::= regex | base | exact (alias of base) | one | sub | children\n"
1139 "<style> ::= regex | base | exact (alias of base)\n"
1140 "<groupflags> ::= R\n"
1141 "<access> ::= [self]{<level>|<priv>}\n"
1142 "<level> ::= none | auth | compare | search | read | write\n"
1143 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
1144 "<control> ::= [ stop | continue | break ]\n"
1146 exit( EXIT_FAILURE );
1150 * At present it simply eats the (optional) space after
1151 * a RDN separator (,)
1152 * Eventually will evolve in a more complete normalization
1155 acl_regex_normalized_dn(
1161 str = ch_strdup( pattern );
1163 if ( str == NULL ) {
1167 for ( p = str; p[ 0 ]; p++ ) {
1169 if ( p[ 0 ] == '\\' ) {
1173 if ( p[ 0 ] == ',' ) {
1174 if ( p[ 1 ] == ' ' ) {
1177 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1180 AC_MEMCPY( &p[ 1 ], &q[ 0 ], strlen( q ) + 1 );
1197 if ( (*right = strchr( line, splitchar )) != NULL ) {
1198 *((*right)++) = '\0';
1203 access_append( Access **l, Access *a )
1205 for ( ; *l != NULL; l = &(*l)->a_next )
1212 acl_append( AccessControl **l, AccessControl *a )
1214 for ( ; *l != NULL; l = &(*l)->acl_next )
1221 access2str( slap_access_t access )
1223 if ( access == ACL_NONE ) {
1226 } else if ( access == ACL_AUTH ) {
1229 } else if ( access == ACL_COMPARE ) {
1232 } else if ( access == ACL_SEARCH ) {
1235 } else if ( access == ACL_READ ) {
1238 } else if ( access == ACL_WRITE ) {
1246 str2access( const char *str )
1248 if ( strcasecmp( str, "none" ) == 0 ) {
1251 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1254 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1257 } else if ( strcasecmp( str, "search" ) == 0 ) {
1260 } else if ( strcasecmp( str, "read" ) == 0 ) {
1263 } else if ( strcasecmp( str, "write" ) == 0 ) {
1267 return( ACL_INVALID_ACCESS );
1272 static char *style_strings[5] = {
1282 print_access( Access *b )
1284 char maskbuf[ACCESSMASK_MAXLEN];
1286 fprintf( stderr, "\tby" );
1288 if ( b->a_dn_pat != NULL ) {
1289 if( strcmp(b->a_dn_pat, "*") == 0
1290 || strcmp(b->a_dn_pat, "users") == 0
1291 || strcmp(b->a_dn_pat, "anonymous") == 0
1292 || strcmp(b->a_dn_pat, "self") == 0 )
1294 fprintf( stderr, " %s", b->a_dn_pat );
1297 fprintf( stderr, " dn.%s=%s", style_strings[b->a_dn_style], b->a_dn_pat );
1301 if ( b->a_dn_at != NULL ) {
1302 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1305 if ( b->a_group_pat != NULL ) {
1306 fprintf( stderr, " group=%s", b->a_group_pat );
1308 if ( b->a_group_oc ) {
1309 fprintf( stderr, " objectClass: %s",
1310 b->a_group_oc->soc_oclass.oc_oid );
1312 if ( b->a_group_at ) {
1313 fprintf( stderr, " attributeType: %s", b->a_group_at->ad_cname.bv_val );
1318 if ( b->a_peername_pat != NULL ) {
1319 fprintf( stderr, " peername=%s", b->a_peername_pat );
1322 if ( b->a_sockname_pat != NULL ) {
1323 fprintf( stderr, " sockname=%s", b->a_sockname_pat );
1326 if ( b->a_domain_pat != NULL ) {
1327 fprintf( stderr, " domain=%s", b->a_domain_pat );
1330 if ( b->a_sockurl_pat != NULL ) {
1331 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat );
1334 #ifdef SLAPD_ACI_ENABLED
1335 if ( b->a_aci_at != NULL ) {
1336 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1340 /* Security Strength Factors */
1341 if ( b->a_authz.sai_ssf ) {
1342 fprintf( stderr, " ssf=%u",
1343 b->a_authz.sai_ssf );
1345 if ( b->a_authz.sai_transport_ssf ) {
1346 fprintf( stderr, " transport_ssf=%u",
1347 b->a_authz.sai_transport_ssf );
1349 if ( b->a_authz.sai_tls_ssf ) {
1350 fprintf( stderr, " tls_ssf=%u",
1351 b->a_authz.sai_tls_ssf );
1353 if ( b->a_authz.sai_sasl_ssf ) {
1354 fprintf( stderr, " sasl_ssf=%u",
1355 b->a_authz.sai_sasl_ssf );
1358 fprintf( stderr, " %s%s",
1359 b->a_dn_self ? "self" : "",
1360 accessmask2str( b->a_access_mask, maskbuf ) );
1362 if( b->a_type == ACL_BREAK ) {
1363 fprintf( stderr, " break" );
1365 } else if( b->a_type == ACL_CONTINUE ) {
1366 fprintf( stderr, " continue" );
1368 } else if( b->a_type != ACL_STOP ) {
1369 fprintf( stderr, " unknown-control" );
1372 fprintf( stderr, "\n" );
1377 print_acl( Backend *be, AccessControl *a )
1382 fprintf( stderr, "%s ACL: access to",
1383 be == NULL ? "Global" : "Backend" );
1385 if ( a->acl_dn_pat != NULL ) {
1387 fprintf( stderr, " dn.%s=%s\n",
1388 style_strings[a->acl_dn_style], a->acl_dn_pat );
1391 if ( a->acl_filter != NULL ) {
1393 fprintf( stderr, " filter=" );
1394 filter_print( a->acl_filter );
1395 fprintf( stderr, "\n" );
1398 if ( a->acl_attrs != NULL ) {
1402 fprintf( stderr, " attrs=" );
1403 for ( i = 0; a->acl_attrs[i] != NULL; i++ ) {
1405 fprintf( stderr, "," );
1407 fprintf( stderr, a->acl_attrs[i] );
1410 fprintf( stderr, "\n" );
1414 fprintf( stderr, " *\n" );
1417 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1421 fprintf( stderr, "\n" );
1424 #endif /* LDAP_DEBUG */