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 void acl_regex_normalized_dn(struct berval *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;
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 != 0 ) {
124 "%s: line %d: dn pattern"
125 " already specified in to clause.\n",
130 a->acl_dn_pat.bv_val = ch_strdup( "*" );
131 a->acl_dn_pat.bv_len = 1;
135 split( argv[i], '=', &left, &right );
136 split( left, '.', &left, &style );
138 if ( right == NULL ) {
140 "%s: line %d: missing \"=\" in \"%s\" in to clause\n",
141 fname, lineno, left );
145 if ( strcasecmp( left, "dn" ) == 0 ) {
146 if( a->acl_dn_pat.bv_len != 0 ) {
148 "%s: line %d: dn pattern"
149 " already specified in to clause.\n",
154 if ( style == NULL || *style == '\0'
155 || strcasecmp( style, "regex" ) == 0 )
157 a->acl_dn_style = ACL_STYLE_REGEX;
158 if ( strcmp(right, "*") == 0
159 || strcmp(right, ".*") == 0
160 || strcmp(right, ".*$") == 0
161 || strcmp(right, "^.*") == 0
162 || strcmp(right, "^.*$$") == 0
163 || strcmp(right, ".*$$") == 0
164 || strcmp(right, "^.*$$") == 0 )
166 a->acl_dn_pat.bv_val = ch_strdup( "*" );
167 a->acl_dn_pat.bv_len = 1;
170 a->acl_dn_pat.bv_val = right;
171 acl_regex_normalized_dn( &a->acl_dn_pat );
173 } else if ( strcasecmp( style, "base" ) == 0 ) {
174 a->acl_dn_style = ACL_STYLE_BASE;
175 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
176 } else if ( strcasecmp( style, "one" ) == 0 ) {
177 a->acl_dn_style = ACL_STYLE_ONE;
178 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
179 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
180 a->acl_dn_style = ACL_STYLE_SUBTREE;
181 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
182 } else if ( strcasecmp( style, "children" ) == 0 ) {
183 a->acl_dn_style = ACL_STYLE_CHILDREN;
184 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
187 "%s: line %d: unknown dn style \"%s\" in to clause\n",
188 fname, lineno, style );
195 if ( strcasecmp( left, "filter" ) == 0 ) {
196 if ( (a->acl_filter = str2filter(
199 "%s: line %d: bad filter \"%s\" in to clause\n",
200 fname, lineno, right );
204 } else if ( strncasecmp( left, "attr", 4 ) == 0 ) {
205 a->acl_attrs = str2bvec( a->acl_attrs,
209 "%s: line %d: expecting <what> got \"%s\"\n",
210 fname, lineno, left );
215 if ( a->acl_dn_pat.bv_len != 0 && strcmp(a->acl_dn_pat.bv_val, "*") == 0) {
216 free( a->acl_dn_pat.bv_val );
217 a->acl_dn_pat.bv_val = NULL;
218 a->acl_dn_pat.bv_len = 0;
221 if( a->acl_dn_pat.bv_len != 0 ) {
222 if ( a->acl_dn_style != ACL_STYLE_REGEX )
224 struct berval *bv = NULL;
225 dnNormalize( NULL, &a->acl_dn_pat, &bv);
226 free( a->acl_dn_pat.bv_val );
230 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
231 REG_EXTENDED | REG_ICASE );
234 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
236 "%s: line %d: regular expression \"%s\" bad because of %s\n",
237 fname, lineno, right, buf );
243 /* by clause - select who has what access to entries */
244 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
247 "%s: line %d: to clause required before by clause in access line\n",
253 * by clause consists of <who> and <access>
256 b = (Access *) ch_calloc( 1, sizeof(Access) );
258 ACL_INVALIDATE( b->a_access_mask );
262 "%s: line %d: premature eol: expecting <who>\n",
268 for ( ; i < argc; i++ ) {
269 slap_style_t sty = ACL_STYLE_REGEX;
271 split( argv[i], '=', &left, &right );
272 split( left, '.', &left, &style );
273 if ( style == NULL || *style == '\0'
274 || strcasecmp( style, "regex" ) == 0 )
276 sty = ACL_STYLE_REGEX;
277 } else if ( strcasecmp( style, "exact" ) == 0 ) {
278 sty = ACL_STYLE_EXACT;
279 } else if ( strcasecmp( style, "base" ) == 0 ) {
280 sty = ACL_STYLE_BASE;
281 } else if ( strcasecmp( style, "one" ) == 0 ) {
283 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
284 sty = ACL_STYLE_SUBTREE;
285 } else if ( strcasecmp( style, "children" ) == 0 ) {
286 sty = ACL_STYLE_CHILDREN;
289 "%s: line %d: unknown style \"%s\" in by clause\n",
290 fname, lineno, style );
294 if ( strcasecmp( argv[i], "*" ) == 0 ) {
295 bv.bv_val = ch_strdup( "*" );
298 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
299 ber_str2bv("anonymous",
300 sizeof("anonymous")-1,
303 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
308 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
313 } else if ( strcasecmp( left, "dn" ) == 0 ) {
314 if ( sty == ACL_STYLE_REGEX ) {
315 b->a_dn_style = ACL_STYLE_REGEX;
316 if( right == NULL ) {
321 } else if (*right == '\0' ) {
323 ber_str2bv("anonymous",
324 sizeof("anonymous")-1,
326 } else if ( strcmp( right, "*" ) == 0 ) {
328 /* any or users? users for now */
332 } else if ( strcmp( right, ".+" ) == 0
333 || strcmp( right, "^.+" ) == 0
334 || strcmp( right, ".+$" ) == 0
335 || strcmp( right, "^.+$" ) == 0
336 || strcmp( right, ".+$$" ) == 0
337 || strcmp( right, "^.+$$" ) == 0 )
342 } else if ( strcmp( right, ".*" ) == 0
343 || strcmp( right, "^.*" ) == 0
344 || strcmp( right, ".*$" ) == 0
345 || strcmp( right, "^.*$" ) == 0
346 || strcmp( right, ".*$$" ) == 0
347 || strcmp( right, "^.*$$" ) == 0 )
355 acl_regex_normalized_dn( &bv );
356 regtest(fname, lineno, bv.bv_val);
358 } else if ( right == NULL || *right == '\0' ) {
360 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
361 fname, lineno, left );
365 ber_str2bv( right, 0, 1, &bv );
372 if( bv.bv_val != NULL ) {
373 if( b->a_dn_pat.bv_len != 0 ) {
375 "%s: line %d: dn pattern already specified.\n",
380 if ( sty != ACL_STYLE_REGEX ) {
381 struct berval *ndn = NULL;
382 dnNormalize(NULL, &bv, &ndn);
393 if ( strcasecmp( left, "dnattr" ) == 0 ) {
394 if ( right == NULL || right[ 0 ] == '\0' ) {
396 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
397 fname, lineno, left );
401 if( b->a_dn_at != NULL ) {
403 "%s: line %d: dnattr already specified.\n",
408 rc = slap_str2ad( right, &b->a_dn_at, &text );
410 if( rc != LDAP_SUCCESS ) {
412 "%s: line %d: dnattr \"%s\": %s\n",
413 fname, lineno, right, text );
418 if( !is_at_syntax( b->a_dn_at->ad_type,
420 !is_at_syntax( b->a_dn_at->ad_type,
421 SLAPD_NAMEUID_SYNTAX ))
424 "%s: line %d: dnattr \"%s\": "
425 "inappropriate syntax: %s\n",
426 fname, lineno, right,
427 b->a_dn_at->ad_type->sat_syntax_oid );
434 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
436 "%s: line %d: inappropriate style \"%s\" in by clause\n",
437 fname, lineno, style );
441 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
445 if ( right == NULL || right[ 0 ] == '\0' ) {
447 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
448 fname, lineno, left );
452 if( b->a_group_pat.bv_len ) {
454 "%s: line %d: group pattern already specified.\n",
459 /* format of string is "group/objectClassValue/groupAttrName" */
460 if ((value = strchr(left, '/')) != NULL) {
463 && (name = strchr(value, '/')) != NULL)
469 b->a_group_style = sty;
470 if (sty == ACL_STYLE_REGEX) {
472 acl_regex_normalized_dn( &bv );
473 regtest(fname, lineno, bv.bv_val);
476 struct berval *ndn = NULL;
477 ber_str2bv( right, 0, 0, &bv );
478 dnNormalize( NULL, &bv, &ndn );
479 b->a_group_pat = *ndn;
483 if (value && *value) {
484 b->a_group_oc = oc_find( value );
487 if( b->a_group_oc == NULL ) {
489 "%s: line %d: group objectclass "
491 fname, lineno, value );
495 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
497 if( b->a_group_oc == NULL ) {
499 "%s: line %d: group default objectclass "
501 fname, lineno, SLAPD_GROUP_CLASS );
506 if( is_object_subclass( b->a_group_oc,
507 slap_schema.si_oc_referral ) )
510 "%s: line %d: group objectclass \"%s\" "
511 "is subclass of referral\n",
512 fname, lineno, value );
516 if( is_object_subclass( b->a_group_oc,
517 slap_schema.si_oc_alias ) )
520 "%s: line %d: group objectclass \"%s\" "
521 "is subclass of alias\n",
522 fname, lineno, value );
527 rc = slap_str2ad( name, &b->a_group_at, &text );
529 if( rc != LDAP_SUCCESS ) {
531 "%s: line %d: group \"%s\": %s\n",
532 fname, lineno, right, text );
537 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
539 if( rc != LDAP_SUCCESS ) {
541 "%s: line %d: group \"%s\": %s\n",
542 fname, lineno, SLAPD_GROUP_ATTR, text );
547 if( !is_at_syntax( b->a_group_at->ad_type,
549 !is_at_syntax( b->a_group_at->ad_type,
550 SLAPD_NAMEUID_SYNTAX ) )
553 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
554 fname, lineno, right,
555 b->a_group_at->ad_type->sat_syntax_oid );
563 struct berval *vals[2];
565 val.bv_val = b->a_group_oc->soc_oid;
566 val.bv_len = strlen(val.bv_val);
571 rc = oc_check_allowed( b->a_group_at->ad_type, vals, NULL );
575 "%s: line %d: group: \"%s\" not allowed by \"%s\"\n",
577 b->a_group_at->ad_cname.bv_val,
578 b->a_group_oc->soc_oid );
585 if ( strcasecmp( left, "peername" ) == 0 ) {
586 if ( right == NULL || right[ 0 ] == '\0' ) {
588 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
589 fname, lineno, left );
593 if( b->a_peername_pat != NULL ) {
595 "%s: line %d: peername pattern already specified.\n",
600 b->a_peername_style = sty;
601 if (sty == ACL_STYLE_REGEX) {
603 acl_regex_normalized_dn( &bv );
604 regtest(fname, lineno, bv.bv_val);
605 b->a_peername_pat = bv.bv_val;
607 b->a_peername_pat = ch_strdup( right );
612 if ( strcasecmp( left, "sockname" ) == 0 ) {
613 if ( right == NULL || right[ 0 ] == '\0' ) {
615 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
616 fname, lineno, left );
620 if( b->a_sockname_pat != NULL ) {
622 "%s: line %d: sockname pattern already specified.\n",
627 b->a_sockname_style = sty;
628 if (sty == ACL_STYLE_REGEX) {
630 acl_regex_normalized_dn( &bv );
631 regtest(fname, lineno, bv.bv_val);
632 b->a_sockname_pat = bv.bv_val;
634 b->a_sockname_pat = ch_strdup( right );
639 if ( strcasecmp( left, "domain" ) == 0 ) {
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_domain_pat != NULL ) {
649 "%s: line %d: domain pattern already specified.\n",
654 b->a_domain_style = sty;
655 if (sty == ACL_STYLE_REGEX) {
657 acl_regex_normalized_dn( &bv );
658 regtest(fname, lineno, bv.bv_val);
659 b->a_domain_pat = bv.bv_val;
661 b->a_domain_pat = ch_strdup( right );
666 if ( strcasecmp( left, "sockurl" ) == 0 ) {
667 if ( right == NULL || right[ 0 ] == '\0' ) {
669 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
670 fname, lineno, left );
674 if( b->a_sockurl_pat != NULL ) {
676 "%s: line %d: sockurl pattern already specified.\n",
681 b->a_sockurl_style = sty;
682 if (sty == ACL_STYLE_REGEX) {
684 acl_regex_normalized_dn( &bv );
685 regtest(fname, lineno, bv.bv_val);
686 b->a_sockurl_pat = bv.bv_val;
688 b->a_sockurl_pat = ch_strdup( right );
693 if ( strcasecmp( left, "set" ) == 0 ) {
694 if( b->a_set_pat.bv_len != 0 ) {
696 "%s: line %d: set attribute already specified.\n",
701 if ( right == NULL || *right == '\0' ) {
703 "%s: line %d: no set is defined\n",
708 b->a_set_style = sty;
709 ber_str2bv( right, 0, 1, &b->a_set_pat );
714 #ifdef SLAPD_ACI_ENABLED
715 if ( strcasecmp( left, "aci" ) == 0 ) {
716 if( b->a_aci_at != NULL ) {
718 "%s: line %d: aci attribute already specified.\n",
723 if ( right != NULL && *right != '\0' ) {
724 rc = slap_str2ad( right, &b->a_aci_at, &text );
726 if( rc != LDAP_SUCCESS ) {
728 "%s: line %d: aci \"%s\": %s\n",
729 fname, lineno, right, text );
734 rc = slap_str2ad( SLAPD_ACI_ATTR, &b->a_aci_at, &text );
736 if( rc != LDAP_SUCCESS ) {
738 "%s: line %d: aci \"%s\": %s\n",
739 fname, lineno, SLAPD_ACI_ATTR, text );
744 if( !is_at_syntax( b->a_aci_at->ad_type,
748 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
749 fname, lineno, right,
750 b->a_aci_at->ad_type->sat_syntax_oid );
756 #endif /* SLAPD_ACI_ENABLED */
758 if ( strcasecmp( left, "ssf" ) == 0 ) {
759 if( b->a_authz.sai_ssf ) {
761 "%s: line %d: ssf attribute already specified.\n",
766 if ( right == NULL || *right == '\0' ) {
768 "%s: line %d: no ssf is defined\n",
773 b->a_authz.sai_ssf = atoi( right );
775 if( !b->a_authz.sai_ssf ) {
777 "%s: line %d: invalid ssf value (%s)\n",
778 fname, lineno, right );
784 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
785 if( b->a_authz.sai_transport_ssf ) {
787 "%s: line %d: transport_ssf attribute already specified.\n",
792 if ( right == NULL || *right == '\0' ) {
794 "%s: line %d: no transport_ssf is defined\n",
799 b->a_authz.sai_transport_ssf = atoi( right );
801 if( !b->a_authz.sai_transport_ssf ) {
803 "%s: line %d: invalid transport_ssf value (%s)\n",
804 fname, lineno, right );
810 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
811 if( b->a_authz.sai_tls_ssf ) {
813 "%s: line %d: tls_ssf attribute already specified.\n",
818 if ( right == NULL || *right == '\0' ) {
820 "%s: line %d: no tls_ssf is defined\n",
825 b->a_authz.sai_tls_ssf = atoi( right );
827 if( !b->a_authz.sai_tls_ssf ) {
829 "%s: line %d: invalid tls_ssf value (%s)\n",
830 fname, lineno, right );
836 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
837 if( b->a_authz.sai_sasl_ssf ) {
839 "%s: line %d: sasl_ssf attribute already specified.\n",
844 if ( right == NULL || *right == '\0' ) {
846 "%s: line %d: no sasl_ssf is defined\n",
851 b->a_authz.sai_sasl_ssf = atoi( right );
853 if( !b->a_authz.sai_sasl_ssf ) {
855 "%s: line %d: invalid sasl_ssf value (%s)\n",
856 fname, lineno, right );
862 if( right != NULL ) {
869 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
870 /* out of arguments or plain stop */
872 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
873 b->a_type = ACL_STOP;
875 access_append( &a->acl_access, b );
879 if( strcasecmp( left, "continue" ) == 0 ) {
882 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
883 b->a_type = ACL_CONTINUE;
885 access_append( &a->acl_access, b );
889 if( strcasecmp( left, "break" ) == 0 ) {
892 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
893 b->a_type = ACL_BREAK;
895 access_append( &a->acl_access, b );
899 if ( strcasecmp( left, "by" ) == 0 ) {
900 /* we've gone too far */
902 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
903 b->a_type = ACL_STOP;
905 access_append( &a->acl_access, b );
910 if( strncasecmp( left, "self", 4 ) == 0 ) {
912 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
915 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
918 if( ACL_IS_INVALID( b->a_access_mask ) ) {
920 "%s: line %d: expecting <access> got \"%s\"\n",
921 fname, lineno, left );
925 b->a_type = ACL_STOP;
928 /* out of arguments or plain stop */
929 access_append( &a->acl_access, b );
933 if( strcasecmp( argv[i], "continue" ) == 0 ) {
935 b->a_type = ACL_CONTINUE;
937 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
939 b->a_type = ACL_BREAK;
941 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
946 access_append( &a->acl_access, b );
950 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
951 fname, lineno, argv[i] );
956 /* if we have no real access clause, complain and do nothing */
959 "%s: line %d: warning: no access clause(s) specified in access line\n",
964 if (ldap_debug & LDAP_DEBUG_ACL)
968 if ( a->acl_access == NULL ) {
970 "%s: line %d: warning: no by clause(s) specified in access line\n",
975 acl_append( &be->be_acl, a );
977 acl_append( &global_acl, a );
983 accessmask2str( slap_mask_t mask, char *buf )
988 assert( buf != NULL );
990 if ( ACL_IS_INVALID( mask ) ) {
996 if ( ACL_IS_LEVEL( mask ) ) {
997 if ( ACL_LVL_IS_NONE(mask) ) {
998 ptr = slap_strcopy( ptr, "none" );
1000 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1001 ptr = slap_strcopy( ptr, "auth" );
1003 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1004 ptr = slap_strcopy( ptr, "compare" );
1006 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1007 ptr = slap_strcopy( ptr, "search" );
1009 } else if ( ACL_LVL_IS_READ(mask) ) {
1010 ptr = slap_strcopy( ptr, "read" );
1012 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1013 ptr = slap_strcopy( ptr, "write" );
1015 ptr = slap_strcopy( ptr, "unknown" );
1021 if( ACL_IS_ADDITIVE( mask ) ) {
1024 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1031 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1036 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1041 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1046 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1051 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1056 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1065 if ( ACL_IS_LEVEL( mask ) ) {
1072 str2accessmask( const char *str )
1076 if( !ASCII_ALPHA(str[0]) ) {
1079 if ( str[0] == '=' ) {
1082 } else if( str[0] == '+' ) {
1083 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1085 } else if( str[0] == '-' ) {
1086 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1089 ACL_INVALIDATE(mask);
1093 for( i=1; str[i] != '\0'; i++ ) {
1094 if( TOLOWER(str[i]) == 'w' ) {
1095 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1097 } else if( TOLOWER(str[i]) == 'r' ) {
1098 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1100 } else if( TOLOWER(str[i]) == 's' ) {
1101 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1103 } else if( TOLOWER(str[i]) == 'c' ) {
1104 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1106 } else if( TOLOWER(str[i]) == 'x' ) {
1107 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1109 } else if( str[i] != '0' ) {
1110 ACL_INVALIDATE(mask);
1118 if ( strcasecmp( str, "none" ) == 0 ) {
1119 ACL_LVL_ASSIGN_NONE(mask);
1121 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1122 ACL_LVL_ASSIGN_AUTH(mask);
1124 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1125 ACL_LVL_ASSIGN_COMPARE(mask);
1127 } else if ( strcasecmp( str, "search" ) == 0 ) {
1128 ACL_LVL_ASSIGN_SEARCH(mask);
1130 } else if ( strcasecmp( str, "read" ) == 0 ) {
1131 ACL_LVL_ASSIGN_READ(mask);
1133 } else if ( strcasecmp( str, "write" ) == 0 ) {
1134 ACL_LVL_ASSIGN_WRITE(mask);
1137 ACL_INVALIDATE( mask );
1146 fprintf( stderr, "\n"
1147 "<access clause> ::= access to <what> "
1148 "[ by <who> <access> [ <control> ] ]+ \n"
1149 "<what> ::= * | [dn[.<dnstyle>]=<regex>] [filter=<ldapfilter>] [attrs=<attrlist>]\n"
1150 "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
1151 "<attr> ::= <attrname> | entry | children\n"
1152 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<regex> ]\n"
1153 "\t[dnattr=<attrname>]\n"
1154 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<regex>]\n"
1155 "\t[peername[.<style>]=<regex>] [sockname[.<style>]=<regex>]\n"
1156 "\t[domain[.<style>]=<regex>] [sockurl[.<style>]=<regex>]\n"
1157 #ifdef SLAPD_ACI_ENABLED
1158 "\t[aci=<attrname>]\n"
1160 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1161 "<dnstyle> ::= regex | base | exact (alias of base) | one | sub | children\n"
1162 "<style> ::= regex | base | exact (alias of base)\n"
1163 "<groupflags> ::= R\n"
1164 "<access> ::= [self]{<level>|<priv>}\n"
1165 "<level> ::= none | auth | compare | search | read | write\n"
1166 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
1167 "<control> ::= [ stop | continue | break ]\n"
1169 exit( EXIT_FAILURE );
1173 * At present it simply eats the (optional) space after
1174 * a RDN separator (,)
1175 * Eventually will evolve in a more complete normalization
1177 * Note that the input berval only needs bv_val, it ignores
1178 * the input bv_len and sets it on return.
1181 acl_regex_normalized_dn(
1182 struct berval *pattern
1187 str = ch_strdup( pattern->bv_val );
1189 for ( p = str; p && p[ 0 ]; p++ ) {
1191 if ( p[ 0 ] == '\\' ) {
1195 if ( p[ 0 ] == ',' ) {
1196 if ( p[ 1 ] == ' ' ) {
1199 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1202 AC_MEMCPY( p+1, q, pattern->bv_len-(q-str)+1);
1206 pattern->bv_val = str;
1207 pattern->bv_len = p-str;
1221 if ( (*right = strchr( line, splitchar )) != NULL ) {
1222 *((*right)++) = '\0';
1227 access_append( Access **l, Access *a )
1229 for ( ; *l != NULL; l = &(*l)->a_next )
1236 acl_append( AccessControl **l, AccessControl *a )
1238 for ( ; *l != NULL; l = &(*l)->acl_next )
1245 access_free( Access *a )
1247 if ( a->a_dn_pat.bv_val )
1248 free ( a->a_dn_pat.bv_val );
1249 if ( a->a_peername_pat )
1250 free ( a->a_peername_pat );
1251 if ( a->a_sockname_pat )
1252 free ( a->a_sockname_pat );
1253 if ( a->a_domain_pat )
1254 free ( a->a_domain_pat );
1255 if ( a->a_sockurl_pat )
1256 free ( a->a_sockurl_pat );
1257 if ( a->a_set_pat.bv_len )
1258 free ( a->a_set_pat.bv_val );
1259 if ( a->a_group_pat.bv_len )
1260 free ( a->a_group_pat.bv_val );
1265 acl_free( AccessControl *a )
1269 if ( a->acl_filter )
1270 filter_free( a->acl_filter );
1271 if ( a->acl_dn_pat.bv_len )
1272 free ( a->acl_dn_pat.bv_val );
1274 ber_bvecfree( a->acl_attrs );
1275 for (; a->acl_access; a->acl_access = n) {
1276 n = a->acl_access->a_next;
1277 access_free( a->acl_access );
1282 /* Because backend_startup uses acl_append to tack on the global_acl to
1283 * the end of each backend's acl, we cannot just take one argument and
1284 * merrily free our way to the end of the list. backend_destroy calls us
1285 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1286 * point. config_destroy calls us with global_acl in arg1 and NULL in
1287 * arg2, so we then proceed to polish off the global_acl.
1290 acl_destroy( AccessControl *a, AccessControl *end )
1294 for (; a && a!= end; a=n) {
1301 access2str( slap_access_t access )
1303 if ( access == ACL_NONE ) {
1306 } else if ( access == ACL_AUTH ) {
1309 } else if ( access == ACL_COMPARE ) {
1312 } else if ( access == ACL_SEARCH ) {
1315 } else if ( access == ACL_READ ) {
1318 } else if ( access == ACL_WRITE ) {
1326 str2access( const char *str )
1328 if ( strcasecmp( str, "none" ) == 0 ) {
1331 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1334 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1337 } else if ( strcasecmp( str, "search" ) == 0 ) {
1340 } else if ( strcasecmp( str, "read" ) == 0 ) {
1343 } else if ( strcasecmp( str, "write" ) == 0 ) {
1347 return( ACL_INVALID_ACCESS );
1352 static char *style_strings[5] = {
1362 print_access( Access *b )
1364 char maskbuf[ACCESSMASK_MAXLEN];
1366 fprintf( stderr, "\tby" );
1368 if ( b->a_dn_pat.bv_len != 0 ) {
1369 if( strcmp(b->a_dn_pat.bv_val, "*") == 0
1370 || strcmp(b->a_dn_pat.bv_val, "users") == 0
1371 || strcmp(b->a_dn_pat.bv_val, "anonymous") == 0
1372 || strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1374 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1377 fprintf( stderr, " dn.%s=%s", style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1381 if ( b->a_dn_at != NULL ) {
1382 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1385 if ( b->a_group_pat.bv_len ) {
1386 fprintf( stderr, " group=%s", b->a_group_pat.bv_val );
1388 if ( b->a_group_oc ) {
1389 fprintf( stderr, " objectClass: %s",
1390 b->a_group_oc->soc_oclass.oc_oid );
1392 if ( b->a_group_at ) {
1393 fprintf( stderr, " attributeType: %s", b->a_group_at->ad_cname.bv_val );
1398 if ( b->a_peername_pat != NULL ) {
1399 fprintf( stderr, " peername=%s", b->a_peername_pat );
1402 if ( b->a_sockname_pat != NULL ) {
1403 fprintf( stderr, " sockname=%s", b->a_sockname_pat );
1406 if ( b->a_domain_pat != NULL ) {
1407 fprintf( stderr, " domain=%s", b->a_domain_pat );
1410 if ( b->a_sockurl_pat != NULL ) {
1411 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat );
1414 #ifdef SLAPD_ACI_ENABLED
1415 if ( b->a_aci_at != NULL ) {
1416 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1420 /* Security Strength Factors */
1421 if ( b->a_authz.sai_ssf ) {
1422 fprintf( stderr, " ssf=%u",
1423 b->a_authz.sai_ssf );
1425 if ( b->a_authz.sai_transport_ssf ) {
1426 fprintf( stderr, " transport_ssf=%u",
1427 b->a_authz.sai_transport_ssf );
1429 if ( b->a_authz.sai_tls_ssf ) {
1430 fprintf( stderr, " tls_ssf=%u",
1431 b->a_authz.sai_tls_ssf );
1433 if ( b->a_authz.sai_sasl_ssf ) {
1434 fprintf( stderr, " sasl_ssf=%u",
1435 b->a_authz.sai_sasl_ssf );
1438 fprintf( stderr, " %s%s",
1439 b->a_dn_self ? "self" : "",
1440 accessmask2str( b->a_access_mask, maskbuf ) );
1442 if( b->a_type == ACL_BREAK ) {
1443 fprintf( stderr, " break" );
1445 } else if( b->a_type == ACL_CONTINUE ) {
1446 fprintf( stderr, " continue" );
1448 } else if( b->a_type != ACL_STOP ) {
1449 fprintf( stderr, " unknown-control" );
1452 fprintf( stderr, "\n" );
1457 print_acl( Backend *be, AccessControl *a )
1462 fprintf( stderr, "%s ACL: access to",
1463 be == NULL ? "Global" : "Backend" );
1465 if ( a->acl_dn_pat.bv_len != 0 ) {
1467 fprintf( stderr, " dn.%s=%s\n",
1468 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
1471 if ( a->acl_filter != NULL ) {
1473 fprintf( stderr, " filter=" );
1474 filter_print( a->acl_filter );
1475 fprintf( stderr, "\n" );
1478 if ( a->acl_attrs != NULL ) {
1482 fprintf( stderr, " attrs=" );
1483 for ( i = 0; a->acl_attrs[i] != NULL; i++ ) {
1485 fprintf( stderr, "," );
1487 fputs( a->acl_attrs[i]->bv_val, stderr );
1490 fprintf( stderr, "\n" );
1494 fprintf( stderr, " *\n" );
1497 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1501 fprintf( stderr, "\n" );
1504 #endif /* LDAP_DEBUG */