1 /* aclparse.c - routines to parse and check acl's */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
14 #include <ac/socket.h>
15 #include <ac/string.h>
16 #include <ac/unistd.h>
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;
159 if ( *right == '\0' ) {
160 /* empty regex should match empty DN */
161 a->acl_dn_style = ACL_STYLE_BASE;
162 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
164 } else if ( strcmp(right, "*") == 0
165 || strcmp(right, ".*") == 0
166 || strcmp(right, ".*$") == 0
167 || strcmp(right, "^.*") == 0
168 || strcmp(right, "^.*$$") == 0
169 || strcmp(right, ".*$$") == 0
170 || strcmp(right, "^.*$$") == 0 )
172 a->acl_dn_pat.bv_val = ch_strdup( "*" );
173 a->acl_dn_pat.bv_len = sizeof("*")-1;
176 a->acl_dn_pat.bv_val = right;
177 acl_regex_normalized_dn( &a->acl_dn_pat );
179 } else if ( strcasecmp( style, "base" ) == 0 ) {
180 a->acl_dn_style = ACL_STYLE_BASE;
181 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
182 } else if ( strcasecmp( style, "one" ) == 0 ) {
183 a->acl_dn_style = ACL_STYLE_ONE;
184 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
185 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
186 a->acl_dn_style = ACL_STYLE_SUBTREE;
187 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
188 } else if ( strcasecmp( style, "children" ) == 0 ) {
189 a->acl_dn_style = ACL_STYLE_CHILDREN;
190 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
193 "%s: line %d: unknown dn style \"%s\" in to clause\n",
194 fname, lineno, style );
201 if ( strcasecmp( left, "filter" ) == 0 ) {
202 if ( (a->acl_filter = str2filter(
205 "%s: line %d: bad filter \"%s\" in to clause\n",
206 fname, lineno, right );
210 } else if ( strncasecmp( left, "attr", 4 ) == 0 ) {
211 a->acl_attrs = str2anlist( a->acl_attrs,
213 if ( a->acl_attrs == NULL ) {
215 "%s: line %d: unknown attr \"%s\" in to clause\n",
216 fname, lineno, right );
221 "%s: line %d: expecting <what> got \"%s\"\n",
222 fname, lineno, left );
227 if ( a->acl_dn_pat.bv_len != 0 &&
228 strcmp(a->acl_dn_pat.bv_val, "*") == 0)
230 free( a->acl_dn_pat.bv_val );
231 a->acl_dn_pat.bv_val = NULL;
232 a->acl_dn_pat.bv_len = 0;
235 if( a->acl_dn_pat.bv_len != 0 ) {
236 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
238 dnNormalize2( NULL, &a->acl_dn_pat, &bv);
239 free( a->acl_dn_pat.bv_val );
242 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
243 REG_EXTENDED | REG_ICASE );
246 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
247 fprintf( stderr, "%s: line %d: "
248 "regular expression \"%s\" bad because of %s\n",
249 fname, lineno, right, buf );
255 /* by clause - select who has what access to entries */
256 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
259 "%s: line %d: to clause required before by clause in access line\n",
265 * by clause consists of <who> and <access>
268 b = (Access *) ch_calloc( 1, sizeof(Access) );
270 ACL_INVALIDATE( b->a_access_mask );
274 "%s: line %d: premature eol: expecting <who>\n",
280 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 bv.bv_val = ch_strdup( "*" );
310 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
311 ber_str2bv("anonymous",
312 sizeof("anonymous")-1,
315 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
320 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
325 } else if ( strcasecmp( left, "dn" ) == 0 ) {
326 if ( sty == ACL_STYLE_REGEX ) {
327 b->a_dn_style = ACL_STYLE_REGEX;
328 if( right == NULL ) {
333 } else if (*right == '\0' ) {
335 ber_str2bv("anonymous",
336 sizeof("anonymous")-1,
338 } else if ( strcmp( right, "*" ) == 0 ) {
340 /* any or users? users for now */
344 } else if ( strcmp( right, ".+" ) == 0
345 || strcmp( right, "^.+" ) == 0
346 || strcmp( right, ".+$" ) == 0
347 || strcmp( right, "^.+$" ) == 0
348 || strcmp( right, ".+$$" ) == 0
349 || strcmp( right, "^.+$$" ) == 0 )
354 } else if ( strcmp( right, ".*" ) == 0
355 || strcmp( right, "^.*" ) == 0
356 || strcmp( right, ".*$" ) == 0
357 || strcmp( right, "^.*$" ) == 0
358 || strcmp( right, ".*$$" ) == 0
359 || strcmp( right, "^.*$$" ) == 0 )
367 acl_regex_normalized_dn( &bv );
368 regtest(fname, lineno, bv.bv_val);
370 } else if ( right == NULL || *right == '\0' ) {
372 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
373 fname, lineno, left );
377 ber_str2bv( right, 0, 1, &bv );
384 if( bv.bv_val != NULL ) {
385 if( b->a_dn_pat.bv_len != 0 ) {
387 "%s: line %d: dn pattern already specified.\n",
392 if ( sty != ACL_STYLE_REGEX ) {
393 dnNormalize2(NULL, &bv, &b->a_dn_pat);
402 if ( strcasecmp( left, "dnattr" ) == 0 ) {
403 if ( right == NULL || right[ 0 ] == '\0' ) {
405 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
406 fname, lineno, left );
410 if( b->a_dn_at != NULL ) {
412 "%s: line %d: dnattr already specified.\n",
417 rc = slap_str2ad( right, &b->a_dn_at, &text );
419 if( rc != LDAP_SUCCESS ) {
421 "%s: line %d: dnattr \"%s\": %s\n",
422 fname, lineno, right, text );
427 if( !is_at_syntax( b->a_dn_at->ad_type,
429 !is_at_syntax( b->a_dn_at->ad_type,
430 SLAPD_NAMEUID_SYNTAX ))
433 "%s: line %d: dnattr \"%s\": "
434 "inappropriate syntax: %s\n",
435 fname, lineno, right,
436 b->a_dn_at->ad_type->sat_syntax_oid );
443 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
445 "%s: line %d: inappropriate style \"%s\" in by clause\n",
446 fname, lineno, style );
450 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
454 if ( right == NULL || right[ 0 ] == '\0' ) {
456 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
457 fname, lineno, left );
461 if( b->a_group_pat.bv_len ) {
463 "%s: line %d: group pattern already specified.\n",
468 /* format of string is "group/objectClassValue/groupAttrName" */
469 if ((value = strchr(left, '/')) != NULL) {
472 && (name = strchr(value, '/')) != NULL)
478 b->a_group_style = sty;
479 if (sty == ACL_STYLE_REGEX) {
481 acl_regex_normalized_dn( &bv );
482 regtest(fname, lineno, bv.bv_val);
485 ber_str2bv( right, 0, 0, &bv );
486 dnNormalize2( NULL, &bv, &b->a_group_pat );
489 if (value && *value) {
490 b->a_group_oc = oc_find( value );
493 if( b->a_group_oc == NULL ) {
495 "%s: line %d: group objectclass "
497 fname, lineno, value );
501 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
503 if( b->a_group_oc == NULL ) {
505 "%s: line %d: group default objectclass "
507 fname, lineno, SLAPD_GROUP_CLASS );
512 if( is_object_subclass( slap_schema.si_oc_referral,
516 "%s: line %d: group objectclass \"%s\" "
517 "is subclass of referral\n",
518 fname, lineno, value );
522 if( is_object_subclass( slap_schema.si_oc_alias,
526 "%s: line %d: group objectclass \"%s\" "
527 "is subclass of alias\n",
528 fname, lineno, value );
533 rc = slap_str2ad( name, &b->a_group_at, &text );
535 if( rc != LDAP_SUCCESS ) {
537 "%s: line %d: group \"%s\": %s\n",
538 fname, lineno, right, text );
543 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
545 if( rc != LDAP_SUCCESS ) {
547 "%s: line %d: group \"%s\": %s\n",
548 fname, lineno, SLAPD_GROUP_ATTR, text );
553 if( !is_at_syntax( b->a_group_at->ad_type,
555 !is_at_syntax( b->a_group_at->ad_type,
556 SLAPD_NAMEUID_SYNTAX ) )
559 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
560 fname, lineno, right,
561 b->a_group_at->ad_type->sat_syntax_oid );
568 struct berval vals[2];
570 vals[0].bv_val = b->a_group_oc->soc_oid;
571 vals[0].bv_len = strlen(vals[0].bv_val);
572 vals[1].bv_val = NULL;
575 rc = oc_check_allowed( b->a_group_at->ad_type, vals, NULL );
579 "%s: line %d: group: \"%s\" not allowed by \"%s\"\n",
581 b->a_group_at->ad_cname.bv_val,
582 b->a_group_oc->soc_oid );
589 if ( strcasecmp( left, "peername" ) == 0 ) {
590 if ( right == NULL || right[ 0 ] == '\0' ) {
592 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
593 fname, lineno, left );
597 if( b->a_peername_pat.bv_len ) {
599 "%s: line %d: peername pattern already specified.\n",
604 b->a_peername_style = sty;
605 if (sty == ACL_STYLE_REGEX) {
607 acl_regex_normalized_dn( &bv );
608 regtest(fname, lineno, bv.bv_val);
609 b->a_peername_pat = bv;
611 ber_str2bv( right, 0, 1, &b->a_peername_pat );
616 if ( strcasecmp( left, "sockname" ) == 0 ) {
617 if ( right == NULL || right[ 0 ] == '\0' ) {
619 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
620 fname, lineno, left );
624 if( b->a_sockname_pat.bv_len ) {
626 "%s: line %d: sockname pattern already specified.\n",
631 b->a_sockname_style = sty;
632 if (sty == ACL_STYLE_REGEX) {
634 acl_regex_normalized_dn( &bv );
635 regtest(fname, lineno, bv.bv_val);
636 b->a_sockname_pat = bv;
638 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
643 if ( strcasecmp( left, "domain" ) == 0 ) {
644 if ( right == NULL || right[ 0 ] == '\0' ) {
646 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
647 fname, lineno, left );
651 if( b->a_domain_pat.bv_len ) {
653 "%s: line %d: domain pattern already specified.\n",
658 b->a_domain_style = sty;
659 if (sty == ACL_STYLE_REGEX) {
661 acl_regex_normalized_dn( &bv );
662 regtest(fname, lineno, bv.bv_val);
663 b->a_domain_pat = bv;
665 ber_str2bv( right, 0, 1, &b->a_domain_pat );
670 if ( strcasecmp( left, "sockurl" ) == 0 ) {
671 if ( right == NULL || right[ 0 ] == '\0' ) {
673 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
674 fname, lineno, left );
678 if( b->a_sockurl_pat.bv_len ) {
680 "%s: line %d: sockurl pattern already specified.\n",
685 b->a_sockurl_style = sty;
686 if (sty == ACL_STYLE_REGEX) {
688 acl_regex_normalized_dn( &bv );
689 regtest(fname, lineno, bv.bv_val);
690 b->a_sockurl_pat = bv;
692 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
697 if ( strcasecmp( left, "set" ) == 0 ) {
698 if( b->a_set_pat.bv_len != 0 ) {
700 "%s: line %d: set attribute already specified.\n",
705 if ( right == NULL || *right == '\0' ) {
707 "%s: line %d: no set is defined\n",
712 b->a_set_style = sty;
713 ber_str2bv( right, 0, 1, &b->a_set_pat );
718 #ifdef SLAPD_ACI_ENABLED
719 if ( strcasecmp( left, "aci" ) == 0 ) {
720 if( b->a_aci_at != NULL ) {
722 "%s: line %d: aci attribute already specified.\n",
727 if ( right != NULL && *right != '\0' ) {
728 rc = slap_str2ad( right, &b->a_aci_at, &text );
730 if( rc != LDAP_SUCCESS ) {
732 "%s: line %d: aci \"%s\": %s\n",
733 fname, lineno, right, text );
738 b->a_aci_at = slap_schema.si_ad_aci;
741 if( !is_at_syntax( b->a_aci_at->ad_type,
745 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
746 fname, lineno, right,
747 b->a_aci_at->ad_type->sat_syntax_oid );
753 #endif /* SLAPD_ACI_ENABLED */
755 if ( strcasecmp( left, "ssf" ) == 0 ) {
756 if( b->a_authz.sai_ssf ) {
758 "%s: line %d: ssf attribute already specified.\n",
763 if ( right == NULL || *right == '\0' ) {
765 "%s: line %d: no ssf is defined\n",
770 b->a_authz.sai_ssf = atoi( right );
772 if( !b->a_authz.sai_ssf ) {
774 "%s: line %d: invalid ssf value (%s)\n",
775 fname, lineno, right );
781 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
782 if( b->a_authz.sai_transport_ssf ) {
784 "%s: line %d: transport_ssf attribute already specified.\n",
789 if ( right == NULL || *right == '\0' ) {
791 "%s: line %d: no transport_ssf is defined\n",
796 b->a_authz.sai_transport_ssf = atoi( right );
798 if( !b->a_authz.sai_transport_ssf ) {
800 "%s: line %d: invalid transport_ssf value (%s)\n",
801 fname, lineno, right );
807 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
808 if( b->a_authz.sai_tls_ssf ) {
810 "%s: line %d: tls_ssf attribute already specified.\n",
815 if ( right == NULL || *right == '\0' ) {
817 "%s: line %d: no tls_ssf is defined\n",
822 b->a_authz.sai_tls_ssf = atoi( right );
824 if( !b->a_authz.sai_tls_ssf ) {
826 "%s: line %d: invalid tls_ssf value (%s)\n",
827 fname, lineno, right );
833 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
834 if( b->a_authz.sai_sasl_ssf ) {
836 "%s: line %d: sasl_ssf attribute already specified.\n",
841 if ( right == NULL || *right == '\0' ) {
843 "%s: line %d: no sasl_ssf is defined\n",
848 b->a_authz.sai_sasl_ssf = atoi( right );
850 if( !b->a_authz.sai_sasl_ssf ) {
852 "%s: line %d: invalid sasl_ssf value (%s)\n",
853 fname, lineno, right );
859 if( right != NULL ) {
866 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
867 /* out of arguments or plain stop */
869 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
870 b->a_type = ACL_STOP;
872 access_append( &a->acl_access, b );
876 if( strcasecmp( left, "continue" ) == 0 ) {
879 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
880 b->a_type = ACL_CONTINUE;
882 access_append( &a->acl_access, b );
886 if( strcasecmp( left, "break" ) == 0 ) {
889 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
890 b->a_type = ACL_BREAK;
892 access_append( &a->acl_access, b );
896 if ( strcasecmp( left, "by" ) == 0 ) {
897 /* we've gone too far */
899 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
900 b->a_type = ACL_STOP;
902 access_append( &a->acl_access, b );
907 if( strncasecmp( left, "self", 4 ) == 0 ) {
909 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
912 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
915 if( ACL_IS_INVALID( b->a_access_mask ) ) {
917 "%s: line %d: expecting <access> got \"%s\"\n",
918 fname, lineno, left );
922 b->a_type = ACL_STOP;
925 /* out of arguments or plain stop */
926 access_append( &a->acl_access, b );
930 if( strcasecmp( argv[i], "continue" ) == 0 ) {
932 b->a_type = ACL_CONTINUE;
934 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
936 b->a_type = ACL_BREAK;
938 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
943 access_append( &a->acl_access, b );
947 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
948 fname, lineno, argv[i] );
953 /* if we have no real access clause, complain and do nothing */
956 "%s: line %d: warning: no access clause(s) specified in access line\n",
961 if (ldap_debug & LDAP_DEBUG_ACL)
965 if ( a->acl_access == NULL ) {
967 "%s: line %d: warning: no by clause(s) specified in access line\n",
972 acl_append( &be->be_acl, a );
974 acl_append( &global_acl, a );
980 accessmask2str( slap_mask_t mask, char *buf )
985 assert( buf != NULL );
987 if ( ACL_IS_INVALID( mask ) ) {
993 if ( ACL_IS_LEVEL( mask ) ) {
994 if ( ACL_LVL_IS_NONE(mask) ) {
995 ptr = slap_strcopy( ptr, "none" );
997 } else if ( ACL_LVL_IS_AUTH(mask) ) {
998 ptr = slap_strcopy( ptr, "auth" );
1000 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1001 ptr = slap_strcopy( ptr, "compare" );
1003 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1004 ptr = slap_strcopy( ptr, "search" );
1006 } else if ( ACL_LVL_IS_READ(mask) ) {
1007 ptr = slap_strcopy( ptr, "read" );
1009 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1010 ptr = slap_strcopy( ptr, "write" );
1012 ptr = slap_strcopy( ptr, "unknown" );
1018 if( ACL_IS_ADDITIVE( mask ) ) {
1021 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1028 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1033 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1038 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1043 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1048 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1053 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1062 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 ] == '\\' ) {
1193 * if escaping a hex pair we should
1194 * increment p twice; however, in that
1195 * case the second hex number does
1201 if ( p[ 0 ] == ',' ) {
1202 if ( p[ 1 ] == ' ' ) {
1206 * too much space should be
1207 * an error if we are pedantic
1209 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1212 AC_MEMCPY( p+1, q, pattern->bv_len-(q-str)+1);
1216 pattern->bv_val = str;
1217 pattern->bv_len = p-str;
1231 if ( (*right = strchr( line, splitchar )) != NULL ) {
1232 *((*right)++) = '\0';
1237 access_append( Access **l, Access *a )
1239 for ( ; *l != NULL; l = &(*l)->a_next )
1246 acl_append( AccessControl **l, AccessControl *a )
1248 for ( ; *l != NULL; l = &(*l)->acl_next )
1255 access_free( Access *a )
1257 if ( a->a_dn_pat.bv_val )
1258 free ( a->a_dn_pat.bv_val );
1259 if ( a->a_peername_pat.bv_val )
1260 free ( a->a_peername_pat.bv_val );
1261 if ( a->a_sockname_pat.bv_val )
1262 free ( a->a_sockname_pat.bv_val );
1263 if ( a->a_domain_pat.bv_val )
1264 free ( a->a_domain_pat.bv_val );
1265 if ( a->a_sockurl_pat.bv_val )
1266 free ( a->a_sockurl_pat.bv_val );
1267 if ( a->a_set_pat.bv_len )
1268 free ( a->a_set_pat.bv_val );
1269 if ( a->a_group_pat.bv_len )
1270 free ( a->a_group_pat.bv_val );
1275 acl_free( AccessControl *a )
1280 if ( a->acl_filter )
1281 filter_free( a->acl_filter );
1282 if ( a->acl_dn_pat.bv_len )
1283 free ( a->acl_dn_pat.bv_val );
1284 if ( a->acl_attrs ) {
1285 for ( an = a->acl_attrs; an->an_name.bv_val; an++ ) {
1286 free( an->an_name.bv_val );
1288 free( a->acl_attrs );
1290 for (; a->acl_access; a->acl_access = n) {
1291 n = a->acl_access->a_next;
1292 access_free( a->acl_access );
1297 /* Because backend_startup uses acl_append to tack on the global_acl to
1298 * the end of each backend's acl, we cannot just take one argument and
1299 * merrily free our way to the end of the list. backend_destroy calls us
1300 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1301 * point. config_destroy calls us with global_acl in arg1 and NULL in
1302 * arg2, so we then proceed to polish off the global_acl.
1305 acl_destroy( AccessControl *a, AccessControl *end )
1309 for (; a && a!= end; a=n) {
1316 access2str( slap_access_t access )
1318 if ( access == ACL_NONE ) {
1321 } else if ( access == ACL_AUTH ) {
1324 } else if ( access == ACL_COMPARE ) {
1327 } else if ( access == ACL_SEARCH ) {
1330 } else if ( access == ACL_READ ) {
1333 } else if ( access == ACL_WRITE ) {
1341 str2access( const char *str )
1343 if ( strcasecmp( str, "none" ) == 0 ) {
1346 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1349 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1352 } else if ( strcasecmp( str, "search" ) == 0 ) {
1355 } else if ( strcasecmp( str, "read" ) == 0 ) {
1358 } else if ( strcasecmp( str, "write" ) == 0 ) {
1362 return( ACL_INVALID_ACCESS );
1367 static char *style_strings[5] = {
1377 print_access( Access *b )
1379 char maskbuf[ACCESSMASK_MAXLEN];
1381 fprintf( stderr, "\tby" );
1383 if ( b->a_dn_pat.bv_len != 0 ) {
1384 if( strcmp(b->a_dn_pat.bv_val, "*") == 0
1385 || strcmp(b->a_dn_pat.bv_val, "users") == 0
1386 || strcmp(b->a_dn_pat.bv_val, "anonymous") == 0
1387 || strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1389 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1392 fprintf( stderr, " dn.%s=%s",
1393 style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1397 if ( b->a_dn_at != NULL ) {
1398 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1401 if ( b->a_group_pat.bv_len ) {
1402 fprintf( stderr, " group=%s", b->a_group_pat.bv_val );
1404 if ( b->a_group_oc ) {
1405 fprintf( stderr, " objectClass: %s",
1406 b->a_group_oc->soc_oclass.oc_oid );
1408 if ( b->a_group_at ) {
1409 fprintf( stderr, " attributeType: %s", b->a_group_at->ad_cname.bv_val );
1414 if ( b->a_peername_pat.bv_len != 0 ) {
1415 fprintf( stderr, " peername=%s", b->a_peername_pat.bv_val );
1418 if ( b->a_sockname_pat.bv_len != 0 ) {
1419 fprintf( stderr, " sockname=%s", b->a_sockname_pat.bv_val );
1422 if ( b->a_domain_pat.bv_len != 0 ) {
1423 fprintf( stderr, " domain=%s", b->a_domain_pat.bv_val );
1426 if ( b->a_sockurl_pat.bv_len != 0 ) {
1427 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat.bv_val );
1430 #ifdef SLAPD_ACI_ENABLED
1431 if ( b->a_aci_at != NULL ) {
1432 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1436 /* Security Strength Factors */
1437 if ( b->a_authz.sai_ssf ) {
1438 fprintf( stderr, " ssf=%u",
1439 b->a_authz.sai_ssf );
1441 if ( b->a_authz.sai_transport_ssf ) {
1442 fprintf( stderr, " transport_ssf=%u",
1443 b->a_authz.sai_transport_ssf );
1445 if ( b->a_authz.sai_tls_ssf ) {
1446 fprintf( stderr, " tls_ssf=%u",
1447 b->a_authz.sai_tls_ssf );
1449 if ( b->a_authz.sai_sasl_ssf ) {
1450 fprintf( stderr, " sasl_ssf=%u",
1451 b->a_authz.sai_sasl_ssf );
1454 fprintf( stderr, " %s%s",
1455 b->a_dn_self ? "self" : "",
1456 accessmask2str( b->a_access_mask, maskbuf ) );
1458 if( b->a_type == ACL_BREAK ) {
1459 fprintf( stderr, " break" );
1461 } else if( b->a_type == ACL_CONTINUE ) {
1462 fprintf( stderr, " continue" );
1464 } else if( b->a_type != ACL_STOP ) {
1465 fprintf( stderr, " unknown-control" );
1468 fprintf( stderr, "\n" );
1473 print_acl( Backend *be, AccessControl *a )
1478 fprintf( stderr, "%s ACL: access to",
1479 be == NULL ? "Global" : "Backend" );
1481 if ( a->acl_dn_pat.bv_len != 0 ) {
1483 fprintf( stderr, " dn.%s=%s\n",
1484 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
1487 if ( a->acl_filter != NULL ) {
1489 fprintf( stderr, " filter=" );
1490 filter_print( a->acl_filter );
1491 fprintf( stderr, "\n" );
1494 if ( a->acl_attrs != NULL ) {
1499 fprintf( stderr, " attrs=" );
1500 for ( an = a->acl_attrs; an && an->an_name.bv_val; an++ ) {
1502 fprintf( stderr, "," );
1504 fputs( an->an_name.bv_val, stderr );
1507 fprintf( stderr, "\n" );
1511 fprintf( stderr, " *\n" );
1514 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1518 fprintf( stderr, "\n" );
1521 #endif /* LDAP_DEBUG */