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 )
225 dnNormalize2( NULL, &a->acl_dn_pat, &bv);
226 free( a->acl_dn_pat.bv_val );
229 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
230 REG_EXTENDED | REG_ICASE );
233 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
235 "%s: line %d: regular expression \"%s\" bad because of %s\n",
236 fname, lineno, right, buf );
242 /* by clause - select who has what access to entries */
243 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
246 "%s: line %d: to clause required before by clause in access line\n",
252 * by clause consists of <who> and <access>
255 b = (Access *) ch_calloc( 1, sizeof(Access) );
257 ACL_INVALIDATE( b->a_access_mask );
261 "%s: line %d: premature eol: expecting <who>\n",
267 for ( ; i < argc; i++ ) {
268 slap_style_t sty = ACL_STYLE_REGEX;
270 split( argv[i], '=', &left, &right );
271 split( left, '.', &left, &style );
272 if ( style == NULL || *style == '\0'
273 || strcasecmp( style, "regex" ) == 0 )
275 sty = ACL_STYLE_REGEX;
276 } else if ( strcasecmp( style, "exact" ) == 0 ) {
277 sty = ACL_STYLE_EXACT;
278 } else if ( strcasecmp( style, "base" ) == 0 ) {
279 sty = ACL_STYLE_BASE;
280 } else if ( strcasecmp( style, "one" ) == 0 ) {
282 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
283 sty = ACL_STYLE_SUBTREE;
284 } else if ( strcasecmp( style, "children" ) == 0 ) {
285 sty = ACL_STYLE_CHILDREN;
288 "%s: line %d: unknown style \"%s\" in by clause\n",
289 fname, lineno, style );
293 if ( strcasecmp( argv[i], "*" ) == 0 ) {
294 bv.bv_val = ch_strdup( "*" );
297 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
298 ber_str2bv("anonymous",
299 sizeof("anonymous")-1,
302 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
307 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
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 ) {
320 } else if (*right == '\0' ) {
322 ber_str2bv("anonymous",
323 sizeof("anonymous")-1,
325 } else if ( strcmp( right, "*" ) == 0 ) {
327 /* any or users? users for now */
331 } else if ( strcmp( right, ".+" ) == 0
332 || strcmp( right, "^.+" ) == 0
333 || strcmp( right, ".+$" ) == 0
334 || strcmp( right, "^.+$" ) == 0
335 || strcmp( right, ".+$$" ) == 0
336 || strcmp( right, "^.+$$" ) == 0 )
341 } else if ( strcmp( right, ".*" ) == 0
342 || strcmp( right, "^.*" ) == 0
343 || strcmp( right, ".*$" ) == 0
344 || strcmp( right, "^.*$" ) == 0
345 || strcmp( right, ".*$$" ) == 0
346 || strcmp( right, "^.*$$" ) == 0 )
354 acl_regex_normalized_dn( &bv );
355 regtest(fname, lineno, bv.bv_val);
357 } else if ( right == NULL || *right == '\0' ) {
359 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
360 fname, lineno, left );
364 ber_str2bv( right, 0, 1, &bv );
371 if( bv.bv_val != NULL ) {
372 if( b->a_dn_pat.bv_len != 0 ) {
374 "%s: line %d: dn pattern already specified.\n",
379 if ( sty != ACL_STYLE_REGEX ) {
380 dnNormalize2(NULL, &bv, &b->a_dn_pat);
389 if ( strcasecmp( left, "dnattr" ) == 0 ) {
390 if ( right == NULL || right[ 0 ] == '\0' ) {
392 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
393 fname, lineno, left );
397 if( b->a_dn_at != NULL ) {
399 "%s: line %d: dnattr already specified.\n",
404 rc = slap_str2ad( right, &b->a_dn_at, &text );
406 if( rc != LDAP_SUCCESS ) {
408 "%s: line %d: dnattr \"%s\": %s\n",
409 fname, lineno, right, text );
414 if( !is_at_syntax( b->a_dn_at->ad_type,
416 !is_at_syntax( b->a_dn_at->ad_type,
417 SLAPD_NAMEUID_SYNTAX ))
420 "%s: line %d: dnattr \"%s\": "
421 "inappropriate syntax: %s\n",
422 fname, lineno, right,
423 b->a_dn_at->ad_type->sat_syntax_oid );
430 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
432 "%s: line %d: inappropriate style \"%s\" in by clause\n",
433 fname, lineno, style );
437 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
441 if ( right == NULL || right[ 0 ] == '\0' ) {
443 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
444 fname, lineno, left );
448 if( b->a_group_pat.bv_len ) {
450 "%s: line %d: group pattern already specified.\n",
455 /* format of string is "group/objectClassValue/groupAttrName" */
456 if ((value = strchr(left, '/')) != NULL) {
459 && (name = strchr(value, '/')) != NULL)
465 b->a_group_style = sty;
466 if (sty == ACL_STYLE_REGEX) {
468 acl_regex_normalized_dn( &bv );
469 regtest(fname, lineno, bv.bv_val);
472 ber_str2bv( right, 0, 0, &bv );
473 dnNormalize2( NULL, &bv, &b->a_group_pat );
476 if (value && *value) {
477 b->a_group_oc = oc_find( value );
480 if( b->a_group_oc == NULL ) {
482 "%s: line %d: group objectclass "
484 fname, lineno, value );
488 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
490 if( b->a_group_oc == NULL ) {
492 "%s: line %d: group default objectclass "
494 fname, lineno, SLAPD_GROUP_CLASS );
499 if( is_object_subclass( b->a_group_oc,
500 slap_schema.si_oc_referral ) )
503 "%s: line %d: group objectclass \"%s\" "
504 "is subclass of referral\n",
505 fname, lineno, value );
509 if( is_object_subclass( b->a_group_oc,
510 slap_schema.si_oc_alias ) )
513 "%s: line %d: group objectclass \"%s\" "
514 "is subclass of alias\n",
515 fname, lineno, value );
520 rc = slap_str2ad( name, &b->a_group_at, &text );
522 if( rc != LDAP_SUCCESS ) {
524 "%s: line %d: group \"%s\": %s\n",
525 fname, lineno, right, text );
530 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
532 if( rc != LDAP_SUCCESS ) {
534 "%s: line %d: group \"%s\": %s\n",
535 fname, lineno, SLAPD_GROUP_ATTR, text );
540 if( !is_at_syntax( b->a_group_at->ad_type,
542 !is_at_syntax( b->a_group_at->ad_type,
543 SLAPD_NAMEUID_SYNTAX ) )
546 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
547 fname, lineno, right,
548 b->a_group_at->ad_type->sat_syntax_oid );
556 struct berval *vals[2];
558 val.bv_val = b->a_group_oc->soc_oid;
559 val.bv_len = strlen(val.bv_val);
564 rc = oc_check_allowed( b->a_group_at->ad_type, vals, NULL );
568 "%s: line %d: group: \"%s\" not allowed by \"%s\"\n",
570 b->a_group_at->ad_cname.bv_val,
571 b->a_group_oc->soc_oid );
578 if ( strcasecmp( left, "peername" ) == 0 ) {
579 if ( right == NULL || right[ 0 ] == '\0' ) {
581 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
582 fname, lineno, left );
586 if( b->a_peername_pat != NULL ) {
588 "%s: line %d: peername pattern already specified.\n",
593 b->a_peername_style = sty;
594 if (sty == ACL_STYLE_REGEX) {
596 acl_regex_normalized_dn( &bv );
597 regtest(fname, lineno, bv.bv_val);
598 b->a_peername_pat = bv.bv_val;
600 b->a_peername_pat = ch_strdup( right );
605 if ( strcasecmp( left, "sockname" ) == 0 ) {
606 if ( right == NULL || right[ 0 ] == '\0' ) {
608 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
609 fname, lineno, left );
613 if( b->a_sockname_pat != NULL ) {
615 "%s: line %d: sockname pattern already specified.\n",
620 b->a_sockname_style = sty;
621 if (sty == ACL_STYLE_REGEX) {
623 acl_regex_normalized_dn( &bv );
624 regtest(fname, lineno, bv.bv_val);
625 b->a_sockname_pat = bv.bv_val;
627 b->a_sockname_pat = ch_strdup( right );
632 if ( strcasecmp( left, "domain" ) == 0 ) {
633 if ( right == NULL || right[ 0 ] == '\0' ) {
635 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
636 fname, lineno, left );
640 if( b->a_domain_pat != NULL ) {
642 "%s: line %d: domain pattern already specified.\n",
647 b->a_domain_style = sty;
648 if (sty == ACL_STYLE_REGEX) {
650 acl_regex_normalized_dn( &bv );
651 regtest(fname, lineno, bv.bv_val);
652 b->a_domain_pat = bv.bv_val;
654 b->a_domain_pat = ch_strdup( right );
659 if ( strcasecmp( left, "sockurl" ) == 0 ) {
660 if ( right == NULL || right[ 0 ] == '\0' ) {
662 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
663 fname, lineno, left );
667 if( b->a_sockurl_pat != NULL ) {
669 "%s: line %d: sockurl pattern already specified.\n",
674 b->a_sockurl_style = sty;
675 if (sty == ACL_STYLE_REGEX) {
677 acl_regex_normalized_dn( &bv );
678 regtest(fname, lineno, bv.bv_val);
679 b->a_sockurl_pat = bv.bv_val;
681 b->a_sockurl_pat = ch_strdup( right );
686 if ( strcasecmp( left, "set" ) == 0 ) {
687 if( b->a_set_pat.bv_len != 0 ) {
689 "%s: line %d: set attribute already specified.\n",
694 if ( right == NULL || *right == '\0' ) {
696 "%s: line %d: no set is defined\n",
701 b->a_set_style = sty;
702 ber_str2bv( right, 0, 1, &b->a_set_pat );
707 #ifdef SLAPD_ACI_ENABLED
708 if ( strcasecmp( left, "aci" ) == 0 ) {
709 if( b->a_aci_at != NULL ) {
711 "%s: line %d: aci attribute already specified.\n",
716 if ( right != NULL && *right != '\0' ) {
717 rc = slap_str2ad( right, &b->a_aci_at, &text );
719 if( rc != LDAP_SUCCESS ) {
721 "%s: line %d: aci \"%s\": %s\n",
722 fname, lineno, right, text );
727 rc = slap_str2ad( SLAPD_ACI_ATTR, &b->a_aci_at, &text );
729 if( rc != LDAP_SUCCESS ) {
731 "%s: line %d: aci \"%s\": %s\n",
732 fname, lineno, SLAPD_ACI_ATTR, text );
737 if( !is_at_syntax( b->a_aci_at->ad_type,
741 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
742 fname, lineno, right,
743 b->a_aci_at->ad_type->sat_syntax_oid );
749 #endif /* SLAPD_ACI_ENABLED */
751 if ( strcasecmp( left, "ssf" ) == 0 ) {
752 if( b->a_authz.sai_ssf ) {
754 "%s: line %d: ssf attribute already specified.\n",
759 if ( right == NULL || *right == '\0' ) {
761 "%s: line %d: no ssf is defined\n",
766 b->a_authz.sai_ssf = atoi( right );
768 if( !b->a_authz.sai_ssf ) {
770 "%s: line %d: invalid ssf value (%s)\n",
771 fname, lineno, right );
777 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
778 if( b->a_authz.sai_transport_ssf ) {
780 "%s: line %d: transport_ssf attribute already specified.\n",
785 if ( right == NULL || *right == '\0' ) {
787 "%s: line %d: no transport_ssf is defined\n",
792 b->a_authz.sai_transport_ssf = atoi( right );
794 if( !b->a_authz.sai_transport_ssf ) {
796 "%s: line %d: invalid transport_ssf value (%s)\n",
797 fname, lineno, right );
803 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
804 if( b->a_authz.sai_tls_ssf ) {
806 "%s: line %d: tls_ssf attribute already specified.\n",
811 if ( right == NULL || *right == '\0' ) {
813 "%s: line %d: no tls_ssf is defined\n",
818 b->a_authz.sai_tls_ssf = atoi( right );
820 if( !b->a_authz.sai_tls_ssf ) {
822 "%s: line %d: invalid tls_ssf value (%s)\n",
823 fname, lineno, right );
829 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
830 if( b->a_authz.sai_sasl_ssf ) {
832 "%s: line %d: sasl_ssf attribute already specified.\n",
837 if ( right == NULL || *right == '\0' ) {
839 "%s: line %d: no sasl_ssf is defined\n",
844 b->a_authz.sai_sasl_ssf = atoi( right );
846 if( !b->a_authz.sai_sasl_ssf ) {
848 "%s: line %d: invalid sasl_ssf value (%s)\n",
849 fname, lineno, right );
855 if( right != NULL ) {
862 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
863 /* out of arguments or plain stop */
865 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
866 b->a_type = ACL_STOP;
868 access_append( &a->acl_access, b );
872 if( strcasecmp( left, "continue" ) == 0 ) {
875 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
876 b->a_type = ACL_CONTINUE;
878 access_append( &a->acl_access, b );
882 if( strcasecmp( left, "break" ) == 0 ) {
885 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
886 b->a_type = ACL_BREAK;
888 access_append( &a->acl_access, b );
892 if ( strcasecmp( left, "by" ) == 0 ) {
893 /* we've gone too far */
895 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
896 b->a_type = ACL_STOP;
898 access_append( &a->acl_access, b );
903 if( strncasecmp( left, "self", 4 ) == 0 ) {
905 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
908 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
911 if( ACL_IS_INVALID( b->a_access_mask ) ) {
913 "%s: line %d: expecting <access> got \"%s\"\n",
914 fname, lineno, left );
918 b->a_type = ACL_STOP;
921 /* out of arguments or plain stop */
922 access_append( &a->acl_access, b );
926 if( strcasecmp( argv[i], "continue" ) == 0 ) {
928 b->a_type = ACL_CONTINUE;
930 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
932 b->a_type = ACL_BREAK;
934 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
939 access_append( &a->acl_access, b );
943 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
944 fname, lineno, argv[i] );
949 /* if we have no real access clause, complain and do nothing */
952 "%s: line %d: warning: no access clause(s) specified in access line\n",
957 if (ldap_debug & LDAP_DEBUG_ACL)
961 if ( a->acl_access == NULL ) {
963 "%s: line %d: warning: no by clause(s) specified in access line\n",
968 acl_append( &be->be_acl, a );
970 acl_append( &global_acl, a );
976 accessmask2str( slap_mask_t mask, char *buf )
981 assert( buf != NULL );
983 if ( ACL_IS_INVALID( mask ) ) {
989 if ( ACL_IS_LEVEL( mask ) ) {
990 if ( ACL_LVL_IS_NONE(mask) ) {
991 ptr = slap_strcopy( ptr, "none" );
993 } else if ( ACL_LVL_IS_AUTH(mask) ) {
994 ptr = slap_strcopy( ptr, "auth" );
996 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
997 ptr = slap_strcopy( ptr, "compare" );
999 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1000 ptr = slap_strcopy( ptr, "search" );
1002 } else if ( ACL_LVL_IS_READ(mask) ) {
1003 ptr = slap_strcopy( ptr, "read" );
1005 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1006 ptr = slap_strcopy( ptr, "write" );
1008 ptr = slap_strcopy( ptr, "unknown" );
1014 if( ACL_IS_ADDITIVE( mask ) ) {
1017 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1024 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1029 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1034 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1039 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1044 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1049 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1058 if ( ACL_IS_LEVEL( mask ) ) {
1068 str2accessmask( const char *str )
1072 if( !ASCII_ALPHA(str[0]) ) {
1075 if ( str[0] == '=' ) {
1078 } else if( str[0] == '+' ) {
1079 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1081 } else if( str[0] == '-' ) {
1082 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1085 ACL_INVALIDATE(mask);
1089 for( i=1; str[i] != '\0'; i++ ) {
1090 if( TOLOWER(str[i]) == 'w' ) {
1091 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1093 } else if( TOLOWER(str[i]) == 'r' ) {
1094 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1096 } else if( TOLOWER(str[i]) == 's' ) {
1097 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1099 } else if( TOLOWER(str[i]) == 'c' ) {
1100 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1102 } else if( TOLOWER(str[i]) == 'x' ) {
1103 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1105 } else if( str[i] != '0' ) {
1106 ACL_INVALIDATE(mask);
1114 if ( strcasecmp( str, "none" ) == 0 ) {
1115 ACL_LVL_ASSIGN_NONE(mask);
1117 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1118 ACL_LVL_ASSIGN_AUTH(mask);
1120 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1121 ACL_LVL_ASSIGN_COMPARE(mask);
1123 } else if ( strcasecmp( str, "search" ) == 0 ) {
1124 ACL_LVL_ASSIGN_SEARCH(mask);
1126 } else if ( strcasecmp( str, "read" ) == 0 ) {
1127 ACL_LVL_ASSIGN_READ(mask);
1129 } else if ( strcasecmp( str, "write" ) == 0 ) {
1130 ACL_LVL_ASSIGN_WRITE(mask);
1133 ACL_INVALIDATE( mask );
1142 fprintf( stderr, "\n"
1143 "<access clause> ::= access to <what> "
1144 "[ by <who> <access> [ <control> ] ]+ \n"
1145 "<what> ::= * | [dn[.<dnstyle>]=<regex>] [filter=<ldapfilter>] [attrs=<attrlist>]\n"
1146 "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
1147 "<attr> ::= <attrname> | entry | children\n"
1148 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<regex> ]\n"
1149 "\t[dnattr=<attrname>]\n"
1150 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<regex>]\n"
1151 "\t[peername[.<style>]=<regex>] [sockname[.<style>]=<regex>]\n"
1152 "\t[domain[.<style>]=<regex>] [sockurl[.<style>]=<regex>]\n"
1153 #ifdef SLAPD_ACI_ENABLED
1154 "\t[aci=<attrname>]\n"
1156 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1157 "<dnstyle> ::= regex | base | exact (alias of base) | one | sub | children\n"
1158 "<style> ::= regex | base | exact (alias of base)\n"
1159 "<groupflags> ::= R\n"
1160 "<access> ::= [self]{<level>|<priv>}\n"
1161 "<level> ::= none | auth | compare | search | read | write\n"
1162 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
1163 "<control> ::= [ stop | continue | break ]\n"
1165 exit( EXIT_FAILURE );
1169 * At present it simply eats the (optional) space after
1170 * a RDN separator (,)
1171 * Eventually will evolve in a more complete normalization
1173 * Note that the input berval only needs bv_val, it ignores
1174 * the input bv_len and sets it on return.
1177 acl_regex_normalized_dn(
1178 struct berval *pattern
1183 str = ch_strdup( pattern->bv_val );
1185 for ( p = str; p && p[ 0 ]; p++ ) {
1187 if ( p[ 0 ] == '\\' ) {
1189 * if escaping a hex pair we should
1190 * increment p twice; however, in that
1191 * case the second hex number does
1197 if ( p[ 0 ] == ',' ) {
1198 if ( p[ 1 ] == ' ' ) {
1202 * too much space should be
1203 * an error if we are pedantic
1205 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1208 AC_MEMCPY( p+1, q, pattern->bv_len-(q-str)+1);
1212 pattern->bv_val = str;
1213 pattern->bv_len = p-str;
1227 if ( (*right = strchr( line, splitchar )) != NULL ) {
1228 *((*right)++) = '\0';
1233 access_append( Access **l, Access *a )
1235 for ( ; *l != NULL; l = &(*l)->a_next )
1242 acl_append( AccessControl **l, AccessControl *a )
1244 for ( ; *l != NULL; l = &(*l)->acl_next )
1251 access_free( Access *a )
1253 if ( a->a_dn_pat.bv_val )
1254 free ( a->a_dn_pat.bv_val );
1255 if ( a->a_peername_pat )
1256 free ( a->a_peername_pat );
1257 if ( a->a_sockname_pat )
1258 free ( a->a_sockname_pat );
1259 if ( a->a_domain_pat )
1260 free ( a->a_domain_pat );
1261 if ( a->a_sockurl_pat )
1262 free ( a->a_sockurl_pat );
1263 if ( a->a_set_pat.bv_len )
1264 free ( a->a_set_pat.bv_val );
1265 if ( a->a_group_pat.bv_len )
1266 free ( a->a_group_pat.bv_val );
1271 acl_free( AccessControl *a )
1275 if ( a->acl_filter )
1276 filter_free( a->acl_filter );
1277 if ( a->acl_dn_pat.bv_len )
1278 free ( a->acl_dn_pat.bv_val );
1280 ber_bvecfree( a->acl_attrs );
1281 for (; a->acl_access; a->acl_access = n) {
1282 n = a->acl_access->a_next;
1283 access_free( a->acl_access );
1288 /* Because backend_startup uses acl_append to tack on the global_acl to
1289 * the end of each backend's acl, we cannot just take one argument and
1290 * merrily free our way to the end of the list. backend_destroy calls us
1291 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1292 * point. config_destroy calls us with global_acl in arg1 and NULL in
1293 * arg2, so we then proceed to polish off the global_acl.
1296 acl_destroy( AccessControl *a, AccessControl *end )
1300 for (; a && a!= end; a=n) {
1307 access2str( slap_access_t access )
1309 if ( access == ACL_NONE ) {
1312 } else if ( access == ACL_AUTH ) {
1315 } else if ( access == ACL_COMPARE ) {
1318 } else if ( access == ACL_SEARCH ) {
1321 } else if ( access == ACL_READ ) {
1324 } else if ( access == ACL_WRITE ) {
1332 str2access( const char *str )
1334 if ( strcasecmp( str, "none" ) == 0 ) {
1337 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1340 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1343 } else if ( strcasecmp( str, "search" ) == 0 ) {
1346 } else if ( strcasecmp( str, "read" ) == 0 ) {
1349 } else if ( strcasecmp( str, "write" ) == 0 ) {
1353 return( ACL_INVALID_ACCESS );
1358 static char *style_strings[5] = {
1368 print_access( Access *b )
1370 char maskbuf[ACCESSMASK_MAXLEN];
1372 fprintf( stderr, "\tby" );
1374 if ( b->a_dn_pat.bv_len != 0 ) {
1375 if( strcmp(b->a_dn_pat.bv_val, "*") == 0
1376 || strcmp(b->a_dn_pat.bv_val, "users") == 0
1377 || strcmp(b->a_dn_pat.bv_val, "anonymous") == 0
1378 || strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1380 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1383 fprintf( stderr, " dn.%s=%s", style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1387 if ( b->a_dn_at != NULL ) {
1388 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1391 if ( b->a_group_pat.bv_len ) {
1392 fprintf( stderr, " group=%s", b->a_group_pat.bv_val );
1394 if ( b->a_group_oc ) {
1395 fprintf( stderr, " objectClass: %s",
1396 b->a_group_oc->soc_oclass.oc_oid );
1398 if ( b->a_group_at ) {
1399 fprintf( stderr, " attributeType: %s", b->a_group_at->ad_cname.bv_val );
1404 if ( b->a_peername_pat != NULL ) {
1405 fprintf( stderr, " peername=%s", b->a_peername_pat );
1408 if ( b->a_sockname_pat != NULL ) {
1409 fprintf( stderr, " sockname=%s", b->a_sockname_pat );
1412 if ( b->a_domain_pat != NULL ) {
1413 fprintf( stderr, " domain=%s", b->a_domain_pat );
1416 if ( b->a_sockurl_pat != NULL ) {
1417 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat );
1420 #ifdef SLAPD_ACI_ENABLED
1421 if ( b->a_aci_at != NULL ) {
1422 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1426 /* Security Strength Factors */
1427 if ( b->a_authz.sai_ssf ) {
1428 fprintf( stderr, " ssf=%u",
1429 b->a_authz.sai_ssf );
1431 if ( b->a_authz.sai_transport_ssf ) {
1432 fprintf( stderr, " transport_ssf=%u",
1433 b->a_authz.sai_transport_ssf );
1435 if ( b->a_authz.sai_tls_ssf ) {
1436 fprintf( stderr, " tls_ssf=%u",
1437 b->a_authz.sai_tls_ssf );
1439 if ( b->a_authz.sai_sasl_ssf ) {
1440 fprintf( stderr, " sasl_ssf=%u",
1441 b->a_authz.sai_sasl_ssf );
1444 fprintf( stderr, " %s%s",
1445 b->a_dn_self ? "self" : "",
1446 accessmask2str( b->a_access_mask, maskbuf ) );
1448 if( b->a_type == ACL_BREAK ) {
1449 fprintf( stderr, " break" );
1451 } else if( b->a_type == ACL_CONTINUE ) {
1452 fprintf( stderr, " continue" );
1454 } else if( b->a_type != ACL_STOP ) {
1455 fprintf( stderr, " unknown-control" );
1458 fprintf( stderr, "\n" );
1463 print_acl( Backend *be, AccessControl *a )
1468 fprintf( stderr, "%s ACL: access to",
1469 be == NULL ? "Global" : "Backend" );
1471 if ( a->acl_dn_pat.bv_len != 0 ) {
1473 fprintf( stderr, " dn.%s=%s\n",
1474 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
1477 if ( a->acl_filter != NULL ) {
1479 fprintf( stderr, " filter=" );
1480 filter_print( a->acl_filter );
1481 fprintf( stderr, "\n" );
1484 if ( a->acl_attrs != NULL ) {
1488 fprintf( stderr, " attrs=" );
1489 for ( i = 0; a->acl_attrs[i] != NULL; i++ ) {
1491 fprintf( stderr, "," );
1493 fputs( a->acl_attrs[i]->bv_val, stderr );
1496 fprintf( stderr, "\n" );
1500 fprintf( stderr, " *\n" );
1503 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1507 fprintf( stderr, "\n" );
1510 #endif /* LDAP_DEBUG */