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));
25 static void print_acl(Backend *be, AccessControl *a);
26 static void print_access(Access *b);
30 regtest(const char *fname, int lineno, char *pat) {
46 for (size = 0, flag = 0; (size < sizeof(buf)) && *sp; sp++) {
48 if (*sp == '$'|| (*sp >= '0' && *sp <= '9')) {
65 if ( size >= (sizeof(buf)-1) ) {
67 "%s: line %d: regular expression \"%s\" too large\n",
72 if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
74 regerror(e, &re, error, sizeof(error));
76 "%s: line %d: regular expression \"%s\" bad because of %s\n",
77 fname, lineno, pat, error );
95 char *left, *right, *style;
102 for ( i = 1; i < argc; i++ ) {
103 /* to clause - select which entries are protected */
104 if ( strcasecmp( argv[i], "to" ) == 0 ) {
107 "%s: line %d: only one to clause allowed in access line\n",
111 a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
112 a->acl_filter = NULL;
113 a->acl_dn_pat = NULL;
115 a->acl_access = NULL;
117 for ( ++i; i < argc; i++ ) {
118 if ( strcasecmp( argv[i], "by" ) == 0 ) {
123 if ( strcasecmp( argv[i], "*" ) == 0 ) {
124 if( a->acl_dn_pat != NULL ) {
126 "%s: line %d: dn pattern"
127 " already specified in to clause.\n",
132 a->acl_dn_pat = ch_strdup( "*" );
136 split( argv[i], '=', &left, &right );
137 split( left, '.', &left, &style );
139 if ( right == NULL ) {
141 "%s: line %d: missing \"=\" in \"%s\" in to clause\n",
142 fname, lineno, left );
146 if ( strcasecmp( left, "dn" ) == 0 ) {
147 if( a->acl_dn_pat != NULL ) {
149 "%s: line %d: dn pattern"
150 " already specified in to clause.\n",
155 if ( style == NULL || *style == '\0'
156 || strcasecmp( style, "regex" ) == 0 )
158 a->acl_dn_style = ACL_STYLE_REGEX;
159 if ( strcmp(right, "*") == 0
160 || strcmp(right, ".*") == 0
161 || strcmp(right, ".*$") == 0
162 || strcmp(right, "^.*") == 0
163 || strcmp(right, "^.*$$") == 0
164 || strcmp(right, ".*$$") == 0
165 || strcmp(right, "^.*$$") == 0 )
167 a->acl_dn_pat = ch_strdup( "*" );
170 a->acl_dn_pat = ch_strdup( right );
172 } else if ( strcasecmp( style, "base" ) == 0 ) {
173 a->acl_dn_style = ACL_STYLE_BASE;
174 a->acl_dn_pat = ch_strdup( right );
176 } else if ( strcasecmp( style, "one" ) == 0 ) {
177 a->acl_dn_style = ACL_STYLE_ONE;
178 a->acl_dn_pat = ch_strdup( right );
180 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
181 a->acl_dn_style = ACL_STYLE_SUBTREE;
182 a->acl_dn_pat = ch_strdup( right );
184 } else if ( strcasecmp( style, "children" ) == 0 ) {
185 a->acl_dn_style = ACL_STYLE_CHILDREN;
186 a->acl_dn_pat = ch_strdup( right );
190 "%s: line %d: unknown dn style \"%s\" in to clause\n",
191 fname, lineno, style );
198 if ( strcasecmp( left, "filter" ) == 0 ) {
199 if ( (a->acl_filter = str2filter(
202 "%s: line %d: bad filter \"%s\" in to clause\n",
203 fname, lineno, right );
207 } else if ( strncasecmp( left, "attr", 4 ) == 0 ) {
210 alist = str2charray( right, "," );
211 charray_merge( &a->acl_attrs, alist );
212 charray_free( alist );
216 "%s: line %d: expecting <what> got \"%s\"\n",
217 fname, lineno, left );
222 if ( a->acl_dn_pat != NULL && strcmp(a->acl_dn_pat, "*") == 0) {
223 free( a->acl_dn_pat );
224 a->acl_dn_pat = NULL;
227 if( a->acl_dn_pat != NULL ) {
228 if ( a->acl_dn_style != ACL_STYLE_REGEX )
230 dn_normalize(a->acl_dn_pat);
233 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat,
234 REG_EXTENDED | REG_ICASE );
237 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
239 "%s: line %d: regular expression \"%s\" bad because of %s\n",
240 fname, lineno, right, buf );
246 /* by clause - select who has what access to entries */
247 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
250 "%s: line %d: to clause required before by clause in access line\n",
256 * by clause consists of <who> and <access>
259 b = (Access *) ch_calloc( 1, sizeof(Access) );
261 ACL_INVALIDATE( b->a_access_mask );
265 "%s: line %d: premature eol: expecting <who>\n",
271 for ( ; i < argc; i++ ) {
273 slap_style_t sty = ACL_STYLE_REGEX;
275 split( argv[i], '=', &left, &right );
276 split( left, '.', &left, &style );
277 if ( style == NULL || *style == '\0'
278 || strcasecmp( style, "regex" ) == 0 )
280 sty = ACL_STYLE_REGEX;
281 } else if ( strcasecmp( style, "exact" ) == 0 ) {
282 sty = ACL_STYLE_EXACT;
283 } else if ( strcasecmp( style, "base" ) == 0 ) {
284 sty = ACL_STYLE_BASE;
285 } else if ( strcasecmp( style, "one" ) == 0 ) {
287 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
288 sty = ACL_STYLE_SUBTREE;
289 } else if ( strcasecmp( style, "children" ) == 0 ) {
290 sty = ACL_STYLE_CHILDREN;
293 "%s: line %d: unknown style \"%s\" in by clause\n",
294 fname, lineno, style );
298 if ( strcasecmp( argv[i], "*" ) == 0 ) {
299 pat = ch_strdup( "*" );
301 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
302 pat = ch_strdup( "anonymous" );
304 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
305 pat = ch_strdup( "self" );
307 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
308 pat = ch_strdup( "users" );
310 } else if ( strcasecmp( left, "dn" ) == 0 ) {
311 if ( sty == ACL_STYLE_REGEX ) {
312 b->a_dn_style = ACL_STYLE_REGEX;
313 if( right == NULL ) {
315 pat = ch_strdup( "users" );
317 } else if (*right == '\0' ) {
319 pat = ch_strdup( "anonymous" );
321 } else if ( strcmp( right, "*" ) == 0 ) {
323 /* any or users? users for now */
324 pat = ch_strdup( "users" );
326 } else if ( strcmp( right, ".+" ) == 0
327 || strcmp( right, "^.+" ) == 0
328 || strcmp( right, ".+$" ) == 0
329 || strcmp( right, "^.+$" ) == 0
330 || strcmp( right, ".+$$" ) == 0
331 || strcmp( right, "^.+$$" ) == 0 )
333 pat = ch_strdup( "users" );
335 } else if ( strcmp( right, ".*" ) == 0
336 || strcmp( right, "^.*" ) == 0
337 || strcmp( right, ".*$" ) == 0
338 || strcmp( right, "^.*$" ) == 0
339 || strcmp( right, ".*$$" ) == 0
340 || strcmp( right, "^.*$$" ) == 0 )
342 pat = ch_strdup( "*" );
345 regtest(fname, lineno, right);
346 pat = ch_strdup( right );
348 } else if ( right == NULL || *right == '\0' ) {
350 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
351 fname, lineno, left );
355 pat = ch_strdup( right );
363 if( b->a_dn_pat != NULL ) {
365 "%s: line %d: dn pattern already specified.\n",
372 if ( sty != ACL_STYLE_REGEX )
377 if ( strcasecmp( left, "dnattr" ) == 0 ) {
378 if ( right == NULL || right[ 0 ] == '\0' ) {
380 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
381 fname, lineno, left );
385 if( b->a_dn_at != NULL ) {
387 "%s: line %d: dnattr already specified.\n",
392 rc = slap_str2ad( right, &b->a_dn_at, &text );
394 if( rc != LDAP_SUCCESS ) {
396 "%s: line %d: dnattr \"%s\": %s\n",
397 fname, lineno, right, text );
402 if( !is_at_syntax( b->a_dn_at->ad_type,
404 !is_at_syntax( b->a_dn_at->ad_type,
405 SLAPD_NAMEUID_SYNTAX ))
408 "%s: line %d: dnattr \"%s\": "
409 "inappropriate syntax: %s\n",
410 fname, lineno, right,
411 b->a_dn_at->ad_type->sat_syntax_oid );
418 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
420 "%s: line %d: inappropriate style \"%s\" in by clause\n",
421 fname, lineno, style );
425 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
429 if ( right == NULL || right[ 0 ] == '\0' ) {
431 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
432 fname, lineno, left );
436 if( b->a_group_pat != NULL ) {
438 "%s: line %d: group pattern already specified.\n",
443 /* format of string is "group/objectClassValue/groupAttrName" */
444 if ((value = strchr(left, '/')) != NULL) {
447 && (name = strchr(value, '/')) != NULL)
453 b->a_group_style = sty;
454 if (sty == ACL_STYLE_REGEX) {
455 regtest(fname, lineno, right);
456 b->a_group_pat = ch_strdup( right );
458 b->a_group_pat = ch_strdup( right );
459 dn_normalize(b->a_group_pat);
462 if (value && *value) {
463 b->a_group_oc = oc_find( value );
466 if( b->a_group_oc == NULL ) {
468 "%s: line %d: group objectclass "
470 fname, lineno, value );
474 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
476 if( b->a_group_oc == NULL ) {
478 "%s: line %d: group default objectclass "
480 fname, lineno, SLAPD_GROUP_CLASS );
485 if( is_object_subclass( b->a_group_oc,
486 slap_schema.si_oc_referral ) )
489 "%s: line %d: group objectclass \"%s\" "
490 "is subclass of referral\n",
491 fname, lineno, value );
495 if( is_object_subclass( b->a_group_oc,
496 slap_schema.si_oc_alias ) )
499 "%s: line %d: group objectclass \"%s\" "
500 "is subclass of alias\n",
501 fname, lineno, value );
506 rc = slap_str2ad( name, &b->a_group_at, &text );
508 if( rc != LDAP_SUCCESS ) {
510 "%s: line %d: group \"%s\": %s\n",
511 fname, lineno, right, text );
516 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
518 if( rc != LDAP_SUCCESS ) {
520 "%s: line %d: group \"%s\": %s\n",
521 fname, lineno, SLAPD_GROUP_ATTR, text );
526 if( !is_at_syntax( b->a_group_at->ad_type,
528 !is_at_syntax( b->a_group_at->ad_type,
529 SLAPD_NAMEUID_SYNTAX ) )
532 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
533 fname, lineno, right,
534 b->a_group_at->ad_type->sat_syntax_oid );
542 struct berval *vals[2];
544 val.bv_val = b->a_group_oc->soc_oid;
545 val.bv_len = strlen(val.bv_val);
550 rc = oc_check_allowed( b->a_group_at->ad_type, vals );
554 "%s: line %d: group: \"%s\" not allowed by \"%s\"\n",
556 b->a_group_at->ad_cname.bv_val,
557 b->a_group_oc->soc_oid );
564 if ( strcasecmp( left, "peername" ) == 0 ) {
565 if ( right == NULL || right[ 0 ] == '\0' ) {
567 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
568 fname, lineno, left );
572 if( b->a_peername_pat != NULL ) {
574 "%s: line %d: peername pattern already specified.\n",
579 b->a_peername_style = sty;
580 if (sty == ACL_STYLE_REGEX) {
581 regtest(fname, lineno, right);
583 b->a_peername_pat = ch_strdup( right );
587 if ( strcasecmp( left, "sockname" ) == 0 ) {
588 if ( right == NULL || right[ 0 ] == '\0' ) {
590 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
591 fname, lineno, left );
595 if( b->a_sockname_pat != NULL ) {
597 "%s: line %d: sockname pattern already specified.\n",
602 b->a_sockname_style = sty;
603 if (sty == ACL_STYLE_REGEX) {
604 regtest(fname, lineno, right);
606 b->a_sockname_pat = ch_strdup( right );
610 if ( strcasecmp( left, "domain" ) == 0 ) {
611 if ( right == NULL || right[ 0 ] == '\0' ) {
613 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
614 fname, lineno, left );
618 if( b->a_domain_pat != NULL ) {
620 "%s: line %d: domain pattern already specified.\n",
625 b->a_domain_style = sty;
626 if (sty == ACL_STYLE_REGEX) {
627 regtest(fname, lineno, right);
629 b->a_domain_pat = ch_strdup( right );
633 if ( strcasecmp( left, "sockurl" ) == 0 ) {
634 if ( right == NULL || right[ 0 ] == '\0' ) {
636 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
637 fname, lineno, left );
641 if( b->a_sockurl_pat != NULL ) {
643 "%s: line %d: sockurl pattern already specified.\n",
648 b->a_sockurl_style = sty;
649 if (sty == ACL_STYLE_REGEX) {
650 regtest(fname, lineno, right);
652 b->a_sockurl_pat = ch_strdup( right );
656 if ( strcasecmp( left, "set" ) == 0 ) {
657 if( b->a_set_pat != NULL ) {
659 "%s: line %d: set attribute already specified.\n",
664 if ( right == NULL || *right == '\0' ) {
666 "%s: line %d: no set is defined\n",
671 b->a_set_style = sty;
672 b->a_set_pat = ch_strdup(right);
677 #ifdef SLAPD_ACI_ENABLED
678 if ( strcasecmp( left, "aci" ) == 0 ) {
679 if( b->a_aci_at != NULL ) {
681 "%s: line %d: aci attribute already specified.\n",
686 if ( right != NULL && *right != '\0' ) {
687 rc = slap_str2ad( right, &b->a_aci_at, &text );
689 if( rc != LDAP_SUCCESS ) {
691 "%s: line %d: aci \"%s\": %s\n",
692 fname, lineno, right, text );
697 rc = slap_str2ad( SLAPD_ACI_ATTR, &b->a_aci_at, &text );
699 if( rc != LDAP_SUCCESS ) {
701 "%s: line %d: aci \"%s\": %s\n",
702 fname, lineno, SLAPD_ACI_ATTR, text );
707 if( !is_at_syntax( b->a_aci_at->ad_type,
711 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
712 fname, lineno, right,
713 b->a_aci_at->ad_type->sat_syntax_oid );
719 #endif /* SLAPD_ACI_ENABLED */
721 if ( strcasecmp( left, "ssf" ) == 0 ) {
722 if( b->a_authz.sai_ssf ) {
724 "%s: line %d: ssf attribute already specified.\n",
729 if ( right == NULL || *right == '\0' ) {
731 "%s: line %d: no ssf is defined\n",
736 b->a_authz.sai_ssf = atoi( right );
738 if( !b->a_authz.sai_ssf ) {
740 "%s: line %d: invalid ssf value (%s)\n",
741 fname, lineno, right );
747 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
748 if( b->a_authz.sai_transport_ssf ) {
750 "%s: line %d: transport_ssf attribute already specified.\n",
755 if ( right == NULL || *right == '\0' ) {
757 "%s: line %d: no transport_ssf is defined\n",
762 b->a_authz.sai_transport_ssf = atoi( right );
764 if( !b->a_authz.sai_transport_ssf ) {
766 "%s: line %d: invalid transport_ssf value (%s)\n",
767 fname, lineno, right );
773 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
774 if( b->a_authz.sai_tls_ssf ) {
776 "%s: line %d: tls_ssf attribute already specified.\n",
781 if ( right == NULL || *right == '\0' ) {
783 "%s: line %d: no tls_ssf is defined\n",
788 b->a_authz.sai_tls_ssf = atoi( right );
790 if( !b->a_authz.sai_tls_ssf ) {
792 "%s: line %d: invalid tls_ssf value (%s)\n",
793 fname, lineno, right );
799 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
800 if( b->a_authz.sai_sasl_ssf ) {
802 "%s: line %d: sasl_ssf attribute already specified.\n",
807 if ( right == NULL || *right == '\0' ) {
809 "%s: line %d: no sasl_ssf is defined\n",
814 b->a_authz.sai_sasl_ssf = atoi( right );
816 if( !b->a_authz.sai_sasl_ssf ) {
818 "%s: line %d: invalid sasl_ssf value (%s)\n",
819 fname, lineno, right );
825 if( right != NULL ) {
832 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
833 /* out of arguments or plain stop */
835 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
836 b->a_type = ACL_STOP;
838 access_append( &a->acl_access, b );
842 if( strcasecmp( left, "continue" ) == 0 ) {
845 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
846 b->a_type = ACL_CONTINUE;
848 access_append( &a->acl_access, b );
852 if( strcasecmp( left, "break" ) == 0 ) {
855 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
856 b->a_type = ACL_BREAK;
858 access_append( &a->acl_access, b );
862 if ( strcasecmp( left, "by" ) == 0 ) {
863 /* we've gone too far */
865 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
866 b->a_type = ACL_STOP;
868 access_append( &a->acl_access, b );
873 if( strncasecmp( left, "self", 4 ) == 0 ) {
875 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
878 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
881 if( ACL_IS_INVALID( b->a_access_mask ) ) {
883 "%s: line %d: expecting <access> got \"%s\"\n",
884 fname, lineno, left );
888 b->a_type = ACL_STOP;
891 /* out of arguments or plain stop */
892 access_append( &a->acl_access, b );
896 if( strcasecmp( argv[i], "continue" ) == 0 ) {
898 b->a_type = ACL_CONTINUE;
900 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
902 b->a_type = ACL_BREAK;
904 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
909 access_append( &a->acl_access, b );
913 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
914 fname, lineno, argv[i] );
919 /* if we have no real access clause, complain and do nothing */
922 "%s: line %d: warning: no access clause(s) specified in access line\n",
927 if (ldap_debug & LDAP_DEBUG_ACL)
931 if ( a->acl_access == NULL ) {
933 "%s: line %d: warning: no by clause(s) specified in access line\n",
938 acl_append( &be->be_acl, a );
940 acl_append( &global_acl, a );
946 accessmask2str( slap_mask_t mask, char *buf )
950 assert( buf != NULL );
952 if ( ACL_IS_INVALID( mask ) ) {
958 if ( ACL_IS_LEVEL( mask ) ) {
959 if ( ACL_LVL_IS_NONE(mask) ) {
960 strcat( buf, "none" );
962 } else if ( ACL_LVL_IS_AUTH(mask) ) {
963 strcat( buf, "auth" );
965 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
966 strcat( buf, "compare" );
968 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
969 strcat( buf, "search" );
971 } else if ( ACL_LVL_IS_READ(mask) ) {
972 strcat( buf, "read" );
974 } else if ( ACL_LVL_IS_WRITE(mask) ) {
975 strcat( buf, "write" );
977 strcat( buf, "unknown" );
983 if( ACL_IS_ADDITIVE( mask ) ) {
986 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
993 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
998 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1003 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1008 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1013 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1018 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1027 if ( ACL_IS_LEVEL( mask ) ) {
1034 str2accessmask( const char *str )
1038 if( !ASCII_ALPHA(str[0]) ) {
1041 if ( str[0] == '=' ) {
1044 } else if( str[0] == '+' ) {
1045 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1047 } else if( str[0] == '-' ) {
1048 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1051 ACL_INVALIDATE(mask);
1055 for( i=1; str[i] != '\0'; i++ ) {
1056 if( TOLOWER(str[i]) == 'w' ) {
1057 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1059 } else if( TOLOWER(str[i]) == 'r' ) {
1060 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1062 } else if( TOLOWER(str[i]) == 's' ) {
1063 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1065 } else if( TOLOWER(str[i]) == 'c' ) {
1066 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1068 } else if( TOLOWER(str[i]) == 'x' ) {
1069 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1071 } else if( str[i] != '0' ) {
1072 ACL_INVALIDATE(mask);
1080 if ( strcasecmp( str, "none" ) == 0 ) {
1081 ACL_LVL_ASSIGN_NONE(mask);
1083 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1084 ACL_LVL_ASSIGN_AUTH(mask);
1086 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1087 ACL_LVL_ASSIGN_COMPARE(mask);
1089 } else if ( strcasecmp( str, "search" ) == 0 ) {
1090 ACL_LVL_ASSIGN_SEARCH(mask);
1092 } else if ( strcasecmp( str, "read" ) == 0 ) {
1093 ACL_LVL_ASSIGN_READ(mask);
1095 } else if ( strcasecmp( str, "write" ) == 0 ) {
1096 ACL_LVL_ASSIGN_WRITE(mask);
1099 ACL_INVALIDATE( mask );
1108 fprintf( stderr, "\n"
1109 "<access clause> ::= access to <what> "
1110 "[ by <who> <access> [ <control> ] ]+ \n"
1111 "<what> ::= * | [dn[.<dnstyle>]=<regex>] [filter=<ldapfilter>] [attrs=<attrlist>]\n"
1112 "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
1113 "<attr> ::= <attrname> | entry | children\n"
1114 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<regex> ]\n"
1115 "\t[dnattr=<attrname>]\n"
1116 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<regex>]\n"
1117 "\t[peername[.<style>]=<regex>] [sockname[.<style>]=<regex>]\n"
1118 "\t[domain[.<style>]=<regex>] [sockurl[.<style>]=<regex>]\n"
1119 #ifdef SLAPD_ACI_ENABLED
1120 "\t[aci=<attrname>]\n"
1122 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1123 "<dnstyle> ::= regex | base | exact (alias of base) | one | sub | children\n"
1124 "<style> ::= regex | base | exact (alias of base)\n"
1125 "<groupflags> ::= R\n"
1126 "<access> ::= [self]{<level>|<priv>}\n"
1127 "<level> ::= none | auth | compare | search | read | write\n"
1128 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
1129 "<control> ::= [ stop | continue | break ]\n"
1131 exit( EXIT_FAILURE );
1143 if ( (*right = strchr( line, splitchar )) != NULL ) {
1144 *((*right)++) = '\0';
1149 access_append( Access **l, Access *a )
1151 for ( ; *l != NULL; l = &(*l)->a_next )
1158 acl_append( AccessControl **l, AccessControl *a )
1160 for ( ; *l != NULL; l = &(*l)->acl_next )
1167 access2str( slap_access_t access )
1169 if ( access == ACL_NONE ) {
1172 } else if ( access == ACL_AUTH ) {
1175 } else if ( access == ACL_COMPARE ) {
1178 } else if ( access == ACL_SEARCH ) {
1181 } else if ( access == ACL_READ ) {
1184 } else if ( access == ACL_WRITE ) {
1192 str2access( const char *str )
1194 if ( strcasecmp( str, "none" ) == 0 ) {
1197 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1200 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1203 } else if ( strcasecmp( str, "search" ) == 0 ) {
1206 } else if ( strcasecmp( str, "read" ) == 0 ) {
1209 } else if ( strcasecmp( str, "write" ) == 0 ) {
1213 return( ACL_INVALID_ACCESS );
1218 static char *style_strings[5] = {
1228 print_access( Access *b )
1230 char maskbuf[ACCESSMASK_MAXLEN];
1232 fprintf( stderr, "\tby" );
1234 if ( b->a_dn_pat != NULL ) {
1235 if( strcmp(b->a_dn_pat, "*") == 0
1236 || strcmp(b->a_dn_pat, "users") == 0
1237 || strcmp(b->a_dn_pat, "anonymous") == 0
1238 || strcmp(b->a_dn_pat, "self") == 0 )
1240 fprintf( stderr, " %s", b->a_dn_pat );
1243 fprintf( stderr, " dn.%s=%s", style_strings[b->a_dn_style], b->a_dn_pat );
1247 if ( b->a_dn_at != NULL ) {
1248 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1251 if ( b->a_group_pat != NULL ) {
1252 fprintf( stderr, " group=%s", b->a_group_pat );
1254 if ( b->a_group_oc ) {
1255 fprintf( stderr, " objectClass: %s",
1256 b->a_group_oc->soc_oclass.oc_oid );
1258 if ( b->a_group_at ) {
1259 fprintf( stderr, " attributeType: %s", b->a_group_at->ad_cname.bv_val );
1264 if ( b->a_peername_pat != NULL ) {
1265 fprintf( stderr, " peername=%s", b->a_peername_pat );
1268 if ( b->a_sockname_pat != NULL ) {
1269 fprintf( stderr, " sockname=%s", b->a_sockname_pat );
1272 if ( b->a_domain_pat != NULL ) {
1273 fprintf( stderr, " domain=%s", b->a_domain_pat );
1276 if ( b->a_sockurl_pat != NULL ) {
1277 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat );
1280 #ifdef SLAPD_ACI_ENABLED
1281 if ( b->a_aci_at != NULL ) {
1282 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1286 /* Security Strength Factors */
1287 if ( b->a_authz.sai_ssf ) {
1288 fprintf( stderr, " ssf=%u",
1289 b->a_authz.sai_ssf );
1291 if ( b->a_authz.sai_transport_ssf ) {
1292 fprintf( stderr, " transport_ssf=%u",
1293 b->a_authz.sai_transport_ssf );
1295 if ( b->a_authz.sai_tls_ssf ) {
1296 fprintf( stderr, " tls_ssf=%u",
1297 b->a_authz.sai_tls_ssf );
1299 if ( b->a_authz.sai_sasl_ssf ) {
1300 fprintf( stderr, " sasl_ssf=%u",
1301 b->a_authz.sai_sasl_ssf );
1304 fprintf( stderr, " %s%s",
1305 b->a_dn_self ? "self" : "",
1306 accessmask2str( b->a_access_mask, maskbuf ) );
1308 if( b->a_type == ACL_BREAK ) {
1309 fprintf( stderr, " break" );
1311 } else if( b->a_type == ACL_CONTINUE ) {
1312 fprintf( stderr, " continue" );
1314 } else if( b->a_type != ACL_STOP ) {
1315 fprintf( stderr, " unknown-control" );
1318 fprintf( stderr, "\n" );
1323 print_acl( Backend *be, AccessControl *a )
1328 fprintf( stderr, "%s ACL: access to",
1329 be == NULL ? "Global" : "Backend" );
1331 if ( a->acl_dn_pat != NULL ) {
1333 fprintf( stderr, " dn.%s=%s\n",
1334 style_strings[a->acl_dn_style], a->acl_dn_pat );
1337 if ( a->acl_filter != NULL ) {
1339 fprintf( stderr, " filter=" );
1340 filter_print( a->acl_filter );
1341 fprintf( stderr, "\n" );
1344 if ( a->acl_attrs != NULL ) {
1348 fprintf( stderr, " attrs=" );
1349 for ( i = 0; a->acl_attrs[i] != NULL; i++ ) {
1351 fprintf( stderr, "," );
1353 fprintf( stderr, a->acl_attrs[i] );
1356 fprintf( stderr, "\n" );
1360 fprintf( stderr, " *\n" );
1363 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1367 fprintf( stderr, "\n" );
1370 #endif /* LDAP_DEBUG */