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;
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 = str2anlist( 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 );
555 struct berval vals[2];
557 vals[0].bv_val = b->a_group_oc->soc_oid;
558 vals[0].bv_len = strlen(vals[0].bv_val);
559 vals[1].bv_val = NULL;
562 rc = oc_check_allowed( b->a_group_at->ad_type, vals, NULL );
566 "%s: line %d: group: \"%s\" not allowed by \"%s\"\n",
568 b->a_group_at->ad_cname.bv_val,
569 b->a_group_oc->soc_oid );
576 if ( strcasecmp( left, "peername" ) == 0 ) {
577 if ( right == NULL || right[ 0 ] == '\0' ) {
579 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
580 fname, lineno, left );
584 if( b->a_peername_pat != NULL ) {
586 "%s: line %d: peername pattern already specified.\n",
591 b->a_peername_style = sty;
592 if (sty == ACL_STYLE_REGEX) {
594 acl_regex_normalized_dn( &bv );
595 regtest(fname, lineno, bv.bv_val);
596 b->a_peername_pat = bv.bv_val;
598 b->a_peername_pat = ch_strdup( right );
603 if ( strcasecmp( left, "sockname" ) == 0 ) {
604 if ( right == NULL || right[ 0 ] == '\0' ) {
606 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
607 fname, lineno, left );
611 if( b->a_sockname_pat != NULL ) {
613 "%s: line %d: sockname pattern already specified.\n",
618 b->a_sockname_style = sty;
619 if (sty == ACL_STYLE_REGEX) {
621 acl_regex_normalized_dn( &bv );
622 regtest(fname, lineno, bv.bv_val);
623 b->a_sockname_pat = bv.bv_val;
625 b->a_sockname_pat = ch_strdup( right );
630 if ( strcasecmp( left, "domain" ) == 0 ) {
631 if ( right == NULL || right[ 0 ] == '\0' ) {
633 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
634 fname, lineno, left );
638 if( b->a_domain_pat != NULL ) {
640 "%s: line %d: domain pattern already specified.\n",
645 b->a_domain_style = sty;
646 if (sty == ACL_STYLE_REGEX) {
648 acl_regex_normalized_dn( &bv );
649 regtest(fname, lineno, bv.bv_val);
650 b->a_domain_pat = bv.bv_val;
652 b->a_domain_pat = ch_strdup( right );
657 if ( strcasecmp( left, "sockurl" ) == 0 ) {
658 if ( right == NULL || right[ 0 ] == '\0' ) {
660 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
661 fname, lineno, left );
665 if( b->a_sockurl_pat != NULL ) {
667 "%s: line %d: sockurl pattern already specified.\n",
672 b->a_sockurl_style = sty;
673 if (sty == ACL_STYLE_REGEX) {
675 acl_regex_normalized_dn( &bv );
676 regtest(fname, lineno, bv.bv_val);
677 b->a_sockurl_pat = bv.bv_val;
679 b->a_sockurl_pat = ch_strdup( right );
684 if ( strcasecmp( left, "set" ) == 0 ) {
685 if( b->a_set_pat.bv_len != 0 ) {
687 "%s: line %d: set attribute already specified.\n",
692 if ( right == NULL || *right == '\0' ) {
694 "%s: line %d: no set is defined\n",
699 b->a_set_style = sty;
700 ber_str2bv( right, 0, 1, &b->a_set_pat );
705 #ifdef SLAPD_ACI_ENABLED
706 if ( strcasecmp( left, "aci" ) == 0 ) {
707 if( b->a_aci_at != NULL ) {
709 "%s: line %d: aci attribute already specified.\n",
714 if ( right != NULL && *right != '\0' ) {
715 rc = slap_str2ad( right, &b->a_aci_at, &text );
717 if( rc != LDAP_SUCCESS ) {
719 "%s: line %d: aci \"%s\": %s\n",
720 fname, lineno, right, text );
725 rc = slap_str2ad( SLAPD_ACI_ATTR, &b->a_aci_at, &text );
727 if( rc != LDAP_SUCCESS ) {
729 "%s: line %d: aci \"%s\": %s\n",
730 fname, lineno, SLAPD_ACI_ATTR, text );
735 if( !is_at_syntax( b->a_aci_at->ad_type,
739 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
740 fname, lineno, right,
741 b->a_aci_at->ad_type->sat_syntax_oid );
747 #endif /* SLAPD_ACI_ENABLED */
749 if ( strcasecmp( left, "ssf" ) == 0 ) {
750 if( b->a_authz.sai_ssf ) {
752 "%s: line %d: ssf attribute already specified.\n",
757 if ( right == NULL || *right == '\0' ) {
759 "%s: line %d: no ssf is defined\n",
764 b->a_authz.sai_ssf = atoi( right );
766 if( !b->a_authz.sai_ssf ) {
768 "%s: line %d: invalid ssf value (%s)\n",
769 fname, lineno, right );
775 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
776 if( b->a_authz.sai_transport_ssf ) {
778 "%s: line %d: transport_ssf attribute already specified.\n",
783 if ( right == NULL || *right == '\0' ) {
785 "%s: line %d: no transport_ssf is defined\n",
790 b->a_authz.sai_transport_ssf = atoi( right );
792 if( !b->a_authz.sai_transport_ssf ) {
794 "%s: line %d: invalid transport_ssf value (%s)\n",
795 fname, lineno, right );
801 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
802 if( b->a_authz.sai_tls_ssf ) {
804 "%s: line %d: tls_ssf attribute already specified.\n",
809 if ( right == NULL || *right == '\0' ) {
811 "%s: line %d: no tls_ssf is defined\n",
816 b->a_authz.sai_tls_ssf = atoi( right );
818 if( !b->a_authz.sai_tls_ssf ) {
820 "%s: line %d: invalid tls_ssf value (%s)\n",
821 fname, lineno, right );
827 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
828 if( b->a_authz.sai_sasl_ssf ) {
830 "%s: line %d: sasl_ssf attribute already specified.\n",
835 if ( right == NULL || *right == '\0' ) {
837 "%s: line %d: no sasl_ssf is defined\n",
842 b->a_authz.sai_sasl_ssf = atoi( right );
844 if( !b->a_authz.sai_sasl_ssf ) {
846 "%s: line %d: invalid sasl_ssf value (%s)\n",
847 fname, lineno, right );
853 if( right != NULL ) {
860 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
861 /* out of arguments or plain stop */
863 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
864 b->a_type = ACL_STOP;
866 access_append( &a->acl_access, b );
870 if( strcasecmp( left, "continue" ) == 0 ) {
873 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
874 b->a_type = ACL_CONTINUE;
876 access_append( &a->acl_access, b );
880 if( strcasecmp( left, "break" ) == 0 ) {
883 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
884 b->a_type = ACL_BREAK;
886 access_append( &a->acl_access, b );
890 if ( strcasecmp( left, "by" ) == 0 ) {
891 /* we've gone too far */
893 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
894 b->a_type = ACL_STOP;
896 access_append( &a->acl_access, b );
901 if( strncasecmp( left, "self", 4 ) == 0 ) {
903 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
906 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
909 if( ACL_IS_INVALID( b->a_access_mask ) ) {
911 "%s: line %d: expecting <access> got \"%s\"\n",
912 fname, lineno, left );
916 b->a_type = ACL_STOP;
919 /* out of arguments or plain stop */
920 access_append( &a->acl_access, b );
924 if( strcasecmp( argv[i], "continue" ) == 0 ) {
926 b->a_type = ACL_CONTINUE;
928 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
930 b->a_type = ACL_BREAK;
932 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
937 access_append( &a->acl_access, b );
941 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
942 fname, lineno, argv[i] );
947 /* if we have no real access clause, complain and do nothing */
950 "%s: line %d: warning: no access clause(s) specified in access line\n",
955 if (ldap_debug & LDAP_DEBUG_ACL)
959 if ( a->acl_access == NULL ) {
961 "%s: line %d: warning: no by clause(s) specified in access line\n",
966 acl_append( &be->be_acl, a );
968 acl_append( &global_acl, a );
974 accessmask2str( slap_mask_t mask, char *buf )
979 assert( buf != NULL );
981 if ( ACL_IS_INVALID( mask ) ) {
987 if ( ACL_IS_LEVEL( mask ) ) {
988 if ( ACL_LVL_IS_NONE(mask) ) {
989 ptr = slap_strcopy( ptr, "none" );
991 } else if ( ACL_LVL_IS_AUTH(mask) ) {
992 ptr = slap_strcopy( ptr, "auth" );
994 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
995 ptr = slap_strcopy( ptr, "compare" );
997 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
998 ptr = slap_strcopy( ptr, "search" );
1000 } else if ( ACL_LVL_IS_READ(mask) ) {
1001 ptr = slap_strcopy( ptr, "read" );
1003 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1004 ptr = slap_strcopy( ptr, "write" );
1006 ptr = slap_strcopy( ptr, "unknown" );
1012 if( ACL_IS_ADDITIVE( mask ) ) {
1015 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1022 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1027 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1032 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1037 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1042 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1047 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1056 if ( ACL_IS_LEVEL( mask ) ) {
1066 str2accessmask( const char *str )
1070 if( !ASCII_ALPHA(str[0]) ) {
1073 if ( str[0] == '=' ) {
1076 } else if( str[0] == '+' ) {
1077 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1079 } else if( str[0] == '-' ) {
1080 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1083 ACL_INVALIDATE(mask);
1087 for( i=1; str[i] != '\0'; i++ ) {
1088 if( TOLOWER(str[i]) == 'w' ) {
1089 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1091 } else if( TOLOWER(str[i]) == 'r' ) {
1092 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1094 } else if( TOLOWER(str[i]) == 's' ) {
1095 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1097 } else if( TOLOWER(str[i]) == 'c' ) {
1098 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1100 } else if( TOLOWER(str[i]) == 'x' ) {
1101 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1103 } else if( str[i] != '0' ) {
1104 ACL_INVALIDATE(mask);
1112 if ( strcasecmp( str, "none" ) == 0 ) {
1113 ACL_LVL_ASSIGN_NONE(mask);
1115 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1116 ACL_LVL_ASSIGN_AUTH(mask);
1118 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1119 ACL_LVL_ASSIGN_COMPARE(mask);
1121 } else if ( strcasecmp( str, "search" ) == 0 ) {
1122 ACL_LVL_ASSIGN_SEARCH(mask);
1124 } else if ( strcasecmp( str, "read" ) == 0 ) {
1125 ACL_LVL_ASSIGN_READ(mask);
1127 } else if ( strcasecmp( str, "write" ) == 0 ) {
1128 ACL_LVL_ASSIGN_WRITE(mask);
1131 ACL_INVALIDATE( mask );
1140 fprintf( stderr, "\n"
1141 "<access clause> ::= access to <what> "
1142 "[ by <who> <access> [ <control> ] ]+ \n"
1143 "<what> ::= * | [dn[.<dnstyle>]=<regex>] [filter=<ldapfilter>] [attrs=<attrlist>]\n"
1144 "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
1145 "<attr> ::= <attrname> | entry | children\n"
1146 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<regex> ]\n"
1147 "\t[dnattr=<attrname>]\n"
1148 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<regex>]\n"
1149 "\t[peername[.<style>]=<regex>] [sockname[.<style>]=<regex>]\n"
1150 "\t[domain[.<style>]=<regex>] [sockurl[.<style>]=<regex>]\n"
1151 #ifdef SLAPD_ACI_ENABLED
1152 "\t[aci=<attrname>]\n"
1154 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1155 "<dnstyle> ::= regex | base | exact (alias of base) | one | sub | children\n"
1156 "<style> ::= regex | base | exact (alias of base)\n"
1157 "<groupflags> ::= R\n"
1158 "<access> ::= [self]{<level>|<priv>}\n"
1159 "<level> ::= none | auth | compare | search | read | write\n"
1160 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
1161 "<control> ::= [ stop | continue | break ]\n"
1163 exit( EXIT_FAILURE );
1167 * At present it simply eats the (optional) space after
1168 * a RDN separator (,)
1169 * Eventually will evolve in a more complete normalization
1171 * Note that the input berval only needs bv_val, it ignores
1172 * the input bv_len and sets it on return.
1175 acl_regex_normalized_dn(
1176 struct berval *pattern
1181 str = ch_strdup( pattern->bv_val );
1183 for ( p = str; p && p[ 0 ]; p++ ) {
1185 if ( p[ 0 ] == '\\' ) {
1187 * if escaping a hex pair we should
1188 * increment p twice; however, in that
1189 * case the second hex number does
1195 if ( p[ 0 ] == ',' ) {
1196 if ( p[ 1 ] == ' ' ) {
1200 * too much space should be
1201 * an error if we are pedantic
1203 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1206 AC_MEMCPY( p+1, q, pattern->bv_len-(q-str)+1);
1210 pattern->bv_val = str;
1211 pattern->bv_len = p-str;
1225 if ( (*right = strchr( line, splitchar )) != NULL ) {
1226 *((*right)++) = '\0';
1231 access_append( Access **l, Access *a )
1233 for ( ; *l != NULL; l = &(*l)->a_next )
1240 acl_append( AccessControl **l, AccessControl *a )
1242 for ( ; *l != NULL; l = &(*l)->acl_next )
1249 access_free( Access *a )
1251 if ( a->a_dn_pat.bv_val )
1252 free ( a->a_dn_pat.bv_val );
1253 if ( a->a_peername_pat )
1254 free ( a->a_peername_pat );
1255 if ( a->a_sockname_pat )
1256 free ( a->a_sockname_pat );
1257 if ( a->a_domain_pat )
1258 free ( a->a_domain_pat );
1259 if ( a->a_sockurl_pat )
1260 free ( a->a_sockurl_pat );
1261 if ( a->a_set_pat.bv_len )
1262 free ( a->a_set_pat.bv_val );
1263 if ( a->a_group_pat.bv_len )
1264 free ( a->a_group_pat.bv_val );
1269 acl_free( AccessControl *a )
1274 if ( a->acl_filter )
1275 filter_free( a->acl_filter );
1276 if ( a->acl_dn_pat.bv_len )
1277 free ( a->acl_dn_pat.bv_val );
1278 if ( a->acl_attrs ) {
1279 for ( an = a->acl_attrs; an->an_name.bv_val; an++ ) {
1280 free( an->an_name.bv_val );
1282 free( a->acl_attrs );
1284 for (; a->acl_access; a->acl_access = n) {
1285 n = a->acl_access->a_next;
1286 access_free( a->acl_access );
1291 /* Because backend_startup uses acl_append to tack on the global_acl to
1292 * the end of each backend's acl, we cannot just take one argument and
1293 * merrily free our way to the end of the list. backend_destroy calls us
1294 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1295 * point. config_destroy calls us with global_acl in arg1 and NULL in
1296 * arg2, so we then proceed to polish off the global_acl.
1299 acl_destroy( AccessControl *a, AccessControl *end )
1303 for (; a && a!= end; a=n) {
1310 access2str( slap_access_t access )
1312 if ( access == ACL_NONE ) {
1315 } else if ( access == ACL_AUTH ) {
1318 } else if ( access == ACL_COMPARE ) {
1321 } else if ( access == ACL_SEARCH ) {
1324 } else if ( access == ACL_READ ) {
1327 } else if ( access == ACL_WRITE ) {
1335 str2access( const char *str )
1337 if ( strcasecmp( str, "none" ) == 0 ) {
1340 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1343 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1346 } else if ( strcasecmp( str, "search" ) == 0 ) {
1349 } else if ( strcasecmp( str, "read" ) == 0 ) {
1352 } else if ( strcasecmp( str, "write" ) == 0 ) {
1356 return( ACL_INVALID_ACCESS );
1361 static char *style_strings[5] = {
1371 print_access( Access *b )
1373 char maskbuf[ACCESSMASK_MAXLEN];
1375 fprintf( stderr, "\tby" );
1377 if ( b->a_dn_pat.bv_len != 0 ) {
1378 if( strcmp(b->a_dn_pat.bv_val, "*") == 0
1379 || strcmp(b->a_dn_pat.bv_val, "users") == 0
1380 || strcmp(b->a_dn_pat.bv_val, "anonymous") == 0
1381 || strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1383 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1386 fprintf( stderr, " dn.%s=%s", style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1390 if ( b->a_dn_at != NULL ) {
1391 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1394 if ( b->a_group_pat.bv_len ) {
1395 fprintf( stderr, " group=%s", b->a_group_pat.bv_val );
1397 if ( b->a_group_oc ) {
1398 fprintf( stderr, " objectClass: %s",
1399 b->a_group_oc->soc_oclass.oc_oid );
1401 if ( b->a_group_at ) {
1402 fprintf( stderr, " attributeType: %s", b->a_group_at->ad_cname.bv_val );
1407 if ( b->a_peername_pat != NULL ) {
1408 fprintf( stderr, " peername=%s", b->a_peername_pat );
1411 if ( b->a_sockname_pat != NULL ) {
1412 fprintf( stderr, " sockname=%s", b->a_sockname_pat );
1415 if ( b->a_domain_pat != NULL ) {
1416 fprintf( stderr, " domain=%s", b->a_domain_pat );
1419 if ( b->a_sockurl_pat != NULL ) {
1420 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat );
1423 #ifdef SLAPD_ACI_ENABLED
1424 if ( b->a_aci_at != NULL ) {
1425 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1429 /* Security Strength Factors */
1430 if ( b->a_authz.sai_ssf ) {
1431 fprintf( stderr, " ssf=%u",
1432 b->a_authz.sai_ssf );
1434 if ( b->a_authz.sai_transport_ssf ) {
1435 fprintf( stderr, " transport_ssf=%u",
1436 b->a_authz.sai_transport_ssf );
1438 if ( b->a_authz.sai_tls_ssf ) {
1439 fprintf( stderr, " tls_ssf=%u",
1440 b->a_authz.sai_tls_ssf );
1442 if ( b->a_authz.sai_sasl_ssf ) {
1443 fprintf( stderr, " sasl_ssf=%u",
1444 b->a_authz.sai_sasl_ssf );
1447 fprintf( stderr, " %s%s",
1448 b->a_dn_self ? "self" : "",
1449 accessmask2str( b->a_access_mask, maskbuf ) );
1451 if( b->a_type == ACL_BREAK ) {
1452 fprintf( stderr, " break" );
1454 } else if( b->a_type == ACL_CONTINUE ) {
1455 fprintf( stderr, " continue" );
1457 } else if( b->a_type != ACL_STOP ) {
1458 fprintf( stderr, " unknown-control" );
1461 fprintf( stderr, "\n" );
1466 print_acl( Backend *be, AccessControl *a )
1471 fprintf( stderr, "%s ACL: access to",
1472 be == NULL ? "Global" : "Backend" );
1474 if ( a->acl_dn_pat.bv_len != 0 ) {
1476 fprintf( stderr, " dn.%s=%s\n",
1477 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
1480 if ( a->acl_filter != NULL ) {
1482 fprintf( stderr, " filter=" );
1483 filter_print( a->acl_filter );
1484 fprintf( stderr, "\n" );
1487 if ( a->acl_attrs != NULL ) {
1492 fprintf( stderr, " attrs=" );
1493 for ( an = a->acl_attrs; an && an->an_name.bv_val; an++ ) {
1495 fprintf( stderr, "," );
1497 fputs( an->an_name.bv_val, stderr );
1500 fprintf( stderr, "\n" );
1504 fprintf( stderr, " *\n" );
1507 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1511 fprintf( stderr, "\n" );
1514 #endif /* LDAP_DEBUG */