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, 1, &a->acl_dn_pat );
176 } else if ( strcasecmp( style, "one" ) == 0 ) {
177 a->acl_dn_style = ACL_STYLE_ONE;
178 ber_str2bv( right, 1, &a->acl_dn_pat );
179 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
180 a->acl_dn_style = ACL_STYLE_SUBTREE;
181 ber_str2bv( right, 1, &a->acl_dn_pat );
182 } else if ( strcasecmp( style, "children" ) == 0 ) {
183 a->acl_dn_style = ACL_STYLE_CHILDREN;
184 ber_str2bv( right, 1, &a->acl_dn_pat );
187 "%s: line %d: unknown dn style \"%s\" in to clause\n",
188 fname, lineno, style );
195 if ( strcasecmp( left, "filter" ) == 0 ) {
196 if ( (a->acl_filter = str2filter(
199 "%s: line %d: bad filter \"%s\" in to clause\n",
200 fname, lineno, right );
204 } else if ( strncasecmp( left, "attr", 4 ) == 0 ) {
205 a->acl_attrs = str2bvec( a->acl_attrs,
209 "%s: line %d: expecting <what> got \"%s\"\n",
210 fname, lineno, left );
215 if ( a->acl_dn_pat.bv_len != 0 && strcmp(a->acl_dn_pat.bv_val, "*") == 0) {
216 free( a->acl_dn_pat.bv_val );
217 a->acl_dn_pat.bv_val = NULL;
218 a->acl_dn_pat.bv_len = 0;
221 if( a->acl_dn_pat.bv_len != 0 ) {
222 if ( a->acl_dn_style != ACL_STYLE_REGEX )
224 struct berval *bv = NULL;
225 dnNormalize( NULL, &a->acl_dn_pat, &bv);
226 free( a->acl_dn_pat.bv_val );
230 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
231 REG_EXTENDED | REG_ICASE );
234 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
236 "%s: line %d: regular expression \"%s\" bad because of %s\n",
237 fname, lineno, right, buf );
243 /* by clause - select who has what access to entries */
244 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
247 "%s: line %d: to clause required before by clause in access line\n",
253 * by clause consists of <who> and <access>
256 b = (Access *) ch_calloc( 1, sizeof(Access) );
258 ACL_INVALIDATE( b->a_access_mask );
262 "%s: line %d: premature eol: expecting <who>\n",
268 for ( ; i < argc; i++ ) {
269 slap_style_t sty = ACL_STYLE_REGEX;
271 split( argv[i], '=', &left, &right );
272 split( left, '.', &left, &style );
273 if ( style == NULL || *style == '\0'
274 || strcasecmp( style, "regex" ) == 0 )
276 sty = ACL_STYLE_REGEX;
277 } else if ( strcasecmp( style, "exact" ) == 0 ) {
278 sty = ACL_STYLE_EXACT;
279 } else if ( strcasecmp( style, "base" ) == 0 ) {
280 sty = ACL_STYLE_BASE;
281 } else if ( strcasecmp( style, "one" ) == 0 ) {
283 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
284 sty = ACL_STYLE_SUBTREE;
285 } else if ( strcasecmp( style, "children" ) == 0 ) {
286 sty = ACL_STYLE_CHILDREN;
289 "%s: line %d: unknown style \"%s\" in by clause\n",
290 fname, lineno, style );
294 if ( strcasecmp( argv[i], "*" ) == 0 ) {
295 bv.bv_val = ch_strdup( "*" );
298 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
299 bv.bv_val = ch_strdup( "anonymous" );
300 bv.bv_len = sizeof("anonymous")-1;
302 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
303 bv.bv_val = ch_strdup( "self" );
304 bv.bv_len = sizeof("self")-1;
306 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
307 bv.bv_val = ch_strdup( "users" );
308 bv.bv_len = sizeof("users")-1;
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 bv.bv_val = ch_strdup( "users" );
316 bv.bv_len = sizeof("users")-1;
318 } else if (*right == '\0' ) {
320 bv.bv_val = ch_strdup( "anonymous" );
321 bv.bv_len = sizeof("anonymous")-1;
323 } else if ( strcmp( right, "*" ) == 0 ) {
325 /* any or users? users for now */
326 bv.bv_val = ch_strdup( "users" );
327 bv.bv_len = sizeof("users")-1;
329 } else if ( strcmp( right, ".+" ) == 0
330 || strcmp( right, "^.+" ) == 0
331 || strcmp( right, ".+$" ) == 0
332 || strcmp( right, "^.+$" ) == 0
333 || strcmp( right, ".+$$" ) == 0
334 || strcmp( right, "^.+$$" ) == 0 )
336 bv.bv_val = ch_strdup( "users" );
337 bv.bv_len = sizeof("users")-1;
339 } else if ( strcmp( right, ".*" ) == 0
340 || strcmp( right, "^.*" ) == 0
341 || strcmp( right, ".*$" ) == 0
342 || strcmp( right, "^.*$" ) == 0
343 || strcmp( right, ".*$$" ) == 0
344 || strcmp( right, "^.*$$" ) == 0 )
346 bv.bv_val = ch_strdup( "*" );
351 acl_regex_normalized_dn( &bv );
352 regtest(fname, lineno, bv.bv_val);
354 } else if ( right == NULL || *right == '\0' ) {
356 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
357 fname, lineno, left );
361 ber_str2bv( right, 1, &bv );
368 if( bv.bv_val != NULL ) {
369 if( b->a_dn_pat.bv_len != 0 ) {
371 "%s: line %d: dn pattern already specified.\n",
376 if ( sty != ACL_STYLE_REGEX ) {
377 struct berval *ndn = NULL;
378 dnNormalize(NULL, &bv, &ndn);
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 struct berval *ndn = NULL;
473 ber_str2bv( right, 0, &bv );
474 dnNormalize( NULL, &bv, &ndn );
475 b->a_group_pat = *ndn;
479 if (value && *value) {
480 b->a_group_oc = oc_find( value );
483 if( b->a_group_oc == NULL ) {
485 "%s: line %d: group objectclass "
487 fname, lineno, value );
491 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
493 if( b->a_group_oc == NULL ) {
495 "%s: line %d: group default objectclass "
497 fname, lineno, SLAPD_GROUP_CLASS );
502 if( is_object_subclass( b->a_group_oc,
503 slap_schema.si_oc_referral ) )
506 "%s: line %d: group objectclass \"%s\" "
507 "is subclass of referral\n",
508 fname, lineno, value );
512 if( is_object_subclass( b->a_group_oc,
513 slap_schema.si_oc_alias ) )
516 "%s: line %d: group objectclass \"%s\" "
517 "is subclass of alias\n",
518 fname, lineno, value );
523 rc = slap_str2ad( name, &b->a_group_at, &text );
525 if( rc != LDAP_SUCCESS ) {
527 "%s: line %d: group \"%s\": %s\n",
528 fname, lineno, right, text );
533 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
535 if( rc != LDAP_SUCCESS ) {
537 "%s: line %d: group \"%s\": %s\n",
538 fname, lineno, SLAPD_GROUP_ATTR, text );
543 if( !is_at_syntax( b->a_group_at->ad_type,
545 !is_at_syntax( b->a_group_at->ad_type,
546 SLAPD_NAMEUID_SYNTAX ) )
549 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
550 fname, lineno, right,
551 b->a_group_at->ad_type->sat_syntax_oid );
559 struct berval *vals[2];
561 val.bv_val = b->a_group_oc->soc_oid;
562 val.bv_len = strlen(val.bv_val);
567 rc = oc_check_allowed( b->a_group_at->ad_type, vals, NULL );
571 "%s: line %d: group: \"%s\" not allowed by \"%s\"\n",
573 b->a_group_at->ad_cname.bv_val,
574 b->a_group_oc->soc_oid );
581 if ( strcasecmp( left, "peername" ) == 0 ) {
582 if ( right == NULL || right[ 0 ] == '\0' ) {
584 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
585 fname, lineno, left );
589 if( b->a_peername_pat != NULL ) {
591 "%s: line %d: peername pattern already specified.\n",
596 b->a_peername_style = sty;
597 if (sty == ACL_STYLE_REGEX) {
599 acl_regex_normalized_dn( &bv );
600 regtest(fname, lineno, bv.bv_val);
601 b->a_peername_pat = bv.bv_val;
603 b->a_peername_pat = ch_strdup( right );
608 if ( strcasecmp( left, "sockname" ) == 0 ) {
609 if ( right == NULL || right[ 0 ] == '\0' ) {
611 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
612 fname, lineno, left );
616 if( b->a_sockname_pat != NULL ) {
618 "%s: line %d: sockname pattern already specified.\n",
623 b->a_sockname_style = sty;
624 if (sty == ACL_STYLE_REGEX) {
626 acl_regex_normalized_dn( &bv );
627 regtest(fname, lineno, bv.bv_val);
628 b->a_sockname_pat = bv.bv_val;
630 b->a_sockname_pat = ch_strdup( right );
635 if ( strcasecmp( left, "domain" ) == 0 ) {
636 if ( right == NULL || right[ 0 ] == '\0' ) {
638 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
639 fname, lineno, left );
643 if( b->a_domain_pat != NULL ) {
645 "%s: line %d: domain pattern already specified.\n",
650 b->a_domain_style = sty;
651 if (sty == ACL_STYLE_REGEX) {
653 acl_regex_normalized_dn( &bv );
654 regtest(fname, lineno, bv.bv_val);
655 b->a_domain_pat = bv.bv_val;
657 b->a_domain_pat = ch_strdup( right );
662 if ( strcasecmp( left, "sockurl" ) == 0 ) {
663 if ( right == NULL || right[ 0 ] == '\0' ) {
665 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
666 fname, lineno, left );
670 if( b->a_sockurl_pat != NULL ) {
672 "%s: line %d: sockurl pattern already specified.\n",
677 b->a_sockurl_style = sty;
678 if (sty == ACL_STYLE_REGEX) {
680 acl_regex_normalized_dn( &bv );
681 regtest(fname, lineno, bv.bv_val);
682 b->a_sockurl_pat = bv.bv_val;
684 b->a_sockurl_pat = ch_strdup( right );
689 if ( strcasecmp( left, "set" ) == 0 ) {
690 if( b->a_set_pat.bv_len != 0 ) {
692 "%s: line %d: set attribute already specified.\n",
697 if ( right == NULL || *right == '\0' ) {
699 "%s: line %d: no set is defined\n",
704 b->a_set_style = sty;
705 ber_str2bv( right, 1, &b->a_set_pat );
710 #ifdef SLAPD_ACI_ENABLED
711 if ( strcasecmp( left, "aci" ) == 0 ) {
712 if( b->a_aci_at != NULL ) {
714 "%s: line %d: aci attribute already specified.\n",
719 if ( right != NULL && *right != '\0' ) {
720 rc = slap_str2ad( right, &b->a_aci_at, &text );
722 if( rc != LDAP_SUCCESS ) {
724 "%s: line %d: aci \"%s\": %s\n",
725 fname, lineno, right, text );
730 rc = slap_str2ad( SLAPD_ACI_ATTR, &b->a_aci_at, &text );
732 if( rc != LDAP_SUCCESS ) {
734 "%s: line %d: aci \"%s\": %s\n",
735 fname, lineno, SLAPD_ACI_ATTR, text );
740 if( !is_at_syntax( b->a_aci_at->ad_type,
744 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
745 fname, lineno, right,
746 b->a_aci_at->ad_type->sat_syntax_oid );
752 #endif /* SLAPD_ACI_ENABLED */
754 if ( strcasecmp( left, "ssf" ) == 0 ) {
755 if( b->a_authz.sai_ssf ) {
757 "%s: line %d: ssf attribute already specified.\n",
762 if ( right == NULL || *right == '\0' ) {
764 "%s: line %d: no ssf is defined\n",
769 b->a_authz.sai_ssf = atoi( right );
771 if( !b->a_authz.sai_ssf ) {
773 "%s: line %d: invalid ssf value (%s)\n",
774 fname, lineno, right );
780 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
781 if( b->a_authz.sai_transport_ssf ) {
783 "%s: line %d: transport_ssf attribute already specified.\n",
788 if ( right == NULL || *right == '\0' ) {
790 "%s: line %d: no transport_ssf is defined\n",
795 b->a_authz.sai_transport_ssf = atoi( right );
797 if( !b->a_authz.sai_transport_ssf ) {
799 "%s: line %d: invalid transport_ssf value (%s)\n",
800 fname, lineno, right );
806 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
807 if( b->a_authz.sai_tls_ssf ) {
809 "%s: line %d: tls_ssf attribute already specified.\n",
814 if ( right == NULL || *right == '\0' ) {
816 "%s: line %d: no tls_ssf is defined\n",
821 b->a_authz.sai_tls_ssf = atoi( right );
823 if( !b->a_authz.sai_tls_ssf ) {
825 "%s: line %d: invalid tls_ssf value (%s)\n",
826 fname, lineno, right );
832 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
833 if( b->a_authz.sai_sasl_ssf ) {
835 "%s: line %d: sasl_ssf attribute already specified.\n",
840 if ( right == NULL || *right == '\0' ) {
842 "%s: line %d: no sasl_ssf is defined\n",
847 b->a_authz.sai_sasl_ssf = atoi( right );
849 if( !b->a_authz.sai_sasl_ssf ) {
851 "%s: line %d: invalid sasl_ssf value (%s)\n",
852 fname, lineno, right );
858 if( right != NULL ) {
865 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
866 /* out of arguments or plain stop */
868 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
869 b->a_type = ACL_STOP;
871 access_append( &a->acl_access, b );
875 if( strcasecmp( left, "continue" ) == 0 ) {
878 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
879 b->a_type = ACL_CONTINUE;
881 access_append( &a->acl_access, b );
885 if( strcasecmp( left, "break" ) == 0 ) {
888 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
889 b->a_type = ACL_BREAK;
891 access_append( &a->acl_access, b );
895 if ( strcasecmp( left, "by" ) == 0 ) {
896 /* we've gone too far */
898 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
899 b->a_type = ACL_STOP;
901 access_append( &a->acl_access, b );
906 if( strncasecmp( left, "self", 4 ) == 0 ) {
908 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
911 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
914 if( ACL_IS_INVALID( b->a_access_mask ) ) {
916 "%s: line %d: expecting <access> got \"%s\"\n",
917 fname, lineno, left );
921 b->a_type = ACL_STOP;
924 /* out of arguments or plain stop */
925 access_append( &a->acl_access, b );
929 if( strcasecmp( argv[i], "continue" ) == 0 ) {
931 b->a_type = ACL_CONTINUE;
933 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
935 b->a_type = ACL_BREAK;
937 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
942 access_append( &a->acl_access, b );
946 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
947 fname, lineno, argv[i] );
952 /* if we have no real access clause, complain and do nothing */
955 "%s: line %d: warning: no access clause(s) specified in access line\n",
960 if (ldap_debug & LDAP_DEBUG_ACL)
964 if ( a->acl_access == NULL ) {
966 "%s: line %d: warning: no by clause(s) specified in access line\n",
971 acl_append( &be->be_acl, a );
973 acl_append( &global_acl, a );
979 accessmask2str( slap_mask_t mask, char *buf )
983 assert( buf != NULL );
985 if ( ACL_IS_INVALID( mask ) ) {
991 if ( ACL_IS_LEVEL( mask ) ) {
992 if ( ACL_LVL_IS_NONE(mask) ) {
993 strcat( buf, "none" );
995 } else if ( ACL_LVL_IS_AUTH(mask) ) {
996 strcat( buf, "auth" );
998 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
999 strcat( buf, "compare" );
1001 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1002 strcat( buf, "search" );
1004 } else if ( ACL_LVL_IS_READ(mask) ) {
1005 strcat( buf, "read" );
1007 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1008 strcat( buf, "write" );
1010 strcat( buf, "unknown" );
1016 if( ACL_IS_ADDITIVE( mask ) ) {
1019 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1026 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1031 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1036 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1041 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1046 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1051 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1060 if ( ACL_IS_LEVEL( mask ) ) {
1067 str2accessmask( const char *str )
1071 if( !ASCII_ALPHA(str[0]) ) {
1074 if ( str[0] == '=' ) {
1077 } else if( str[0] == '+' ) {
1078 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1080 } else if( str[0] == '-' ) {
1081 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1084 ACL_INVALIDATE(mask);
1088 for( i=1; str[i] != '\0'; i++ ) {
1089 if( TOLOWER(str[i]) == 'w' ) {
1090 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1092 } else if( TOLOWER(str[i]) == 'r' ) {
1093 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1095 } else if( TOLOWER(str[i]) == 's' ) {
1096 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1098 } else if( TOLOWER(str[i]) == 'c' ) {
1099 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1101 } else if( TOLOWER(str[i]) == 'x' ) {
1102 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1104 } else if( str[i] != '0' ) {
1105 ACL_INVALIDATE(mask);
1113 if ( strcasecmp( str, "none" ) == 0 ) {
1114 ACL_LVL_ASSIGN_NONE(mask);
1116 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1117 ACL_LVL_ASSIGN_AUTH(mask);
1119 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1120 ACL_LVL_ASSIGN_COMPARE(mask);
1122 } else if ( strcasecmp( str, "search" ) == 0 ) {
1123 ACL_LVL_ASSIGN_SEARCH(mask);
1125 } else if ( strcasecmp( str, "read" ) == 0 ) {
1126 ACL_LVL_ASSIGN_READ(mask);
1128 } else if ( strcasecmp( str, "write" ) == 0 ) {
1129 ACL_LVL_ASSIGN_WRITE(mask);
1132 ACL_INVALIDATE( mask );
1141 fprintf( stderr, "\n"
1142 "<access clause> ::= access to <what> "
1143 "[ by <who> <access> [ <control> ] ]+ \n"
1144 "<what> ::= * | [dn[.<dnstyle>]=<regex>] [filter=<ldapfilter>] [attrs=<attrlist>]\n"
1145 "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
1146 "<attr> ::= <attrname> | entry | children\n"
1147 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<regex> ]\n"
1148 "\t[dnattr=<attrname>]\n"
1149 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<regex>]\n"
1150 "\t[peername[.<style>]=<regex>] [sockname[.<style>]=<regex>]\n"
1151 "\t[domain[.<style>]=<regex>] [sockurl[.<style>]=<regex>]\n"
1152 #ifdef SLAPD_ACI_ENABLED
1153 "\t[aci=<attrname>]\n"
1155 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1156 "<dnstyle> ::= regex | base | exact (alias of base) | one | sub | children\n"
1157 "<style> ::= regex | base | exact (alias of base)\n"
1158 "<groupflags> ::= R\n"
1159 "<access> ::= [self]{<level>|<priv>}\n"
1160 "<level> ::= none | auth | compare | search | read | write\n"
1161 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
1162 "<control> ::= [ stop | continue | break ]\n"
1164 exit( EXIT_FAILURE );
1168 * At present it simply eats the (optional) space after
1169 * a RDN separator (,)
1170 * Eventually will evolve in a more complete normalization
1172 * Note that the input berval only needs bv_val, it ignores
1173 * the input bv_len and sets it on return.
1176 acl_regex_normalized_dn(
1177 struct berval *pattern
1182 str = ch_strdup( pattern->bv_val );
1184 for ( p = str; p && p[ 0 ]; p++ ) {
1186 if ( p[ 0 ] == '\\' ) {
1190 if ( p[ 0 ] == ',' ) {
1191 if ( p[ 1 ] == ' ' ) {
1194 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1197 AC_MEMCPY( p+1, q, pattern->bv_len-(q-str)+1);
1201 pattern->bv_val = str;
1202 pattern->bv_len = p-str;
1216 if ( (*right = strchr( line, splitchar )) != NULL ) {
1217 *((*right)++) = '\0';
1222 access_append( Access **l, Access *a )
1224 for ( ; *l != NULL; l = &(*l)->a_next )
1231 acl_append( AccessControl **l, AccessControl *a )
1233 for ( ; *l != NULL; l = &(*l)->acl_next )
1240 access_free( Access *a )
1242 if ( a->a_dn_pat.bv_val )
1243 free ( a->a_dn_pat.bv_val );
1244 if ( a->a_peername_pat )
1245 free ( a->a_peername_pat );
1246 if ( a->a_sockname_pat )
1247 free ( a->a_sockname_pat );
1248 if ( a->a_domain_pat )
1249 free ( a->a_domain_pat );
1250 if ( a->a_sockurl_pat )
1251 free ( a->a_sockurl_pat );
1252 if ( a->a_set_pat.bv_len )
1253 free ( a->a_set_pat.bv_val );
1254 if ( a->a_group_pat.bv_len )
1255 free ( a->a_group_pat.bv_val );
1260 acl_free( AccessControl *a )
1264 if ( a->acl_filter )
1265 filter_free( a->acl_filter );
1266 if ( a->acl_dn_pat.bv_len )
1267 free ( a->acl_dn_pat.bv_val );
1269 ber_bvecfree( a->acl_attrs );
1270 for (; a->acl_access; a->acl_access = n) {
1271 n = a->acl_access->a_next;
1272 access_free( a->acl_access );
1277 /* Because backend_startup uses acl_append to tack on the global_acl to
1278 * the end of each backend's acl, we cannot just take one argument and
1279 * merrily free our way to the end of the list. backend_destroy calls us
1280 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1281 * point. config_destroy calls us with global_acl in arg1 and NULL in
1282 * arg2, so we then proceed to polish off the global_acl.
1285 acl_destroy( AccessControl *a, AccessControl *end )
1289 for (; a && a!= end; a=n) {
1296 access2str( slap_access_t access )
1298 if ( access == ACL_NONE ) {
1301 } else if ( access == ACL_AUTH ) {
1304 } else if ( access == ACL_COMPARE ) {
1307 } else if ( access == ACL_SEARCH ) {
1310 } else if ( access == ACL_READ ) {
1313 } else if ( access == ACL_WRITE ) {
1321 str2access( const char *str )
1323 if ( strcasecmp( str, "none" ) == 0 ) {
1326 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1329 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1332 } else if ( strcasecmp( str, "search" ) == 0 ) {
1335 } else if ( strcasecmp( str, "read" ) == 0 ) {
1338 } else if ( strcasecmp( str, "write" ) == 0 ) {
1342 return( ACL_INVALID_ACCESS );
1347 static char *style_strings[5] = {
1357 print_access( Access *b )
1359 char maskbuf[ACCESSMASK_MAXLEN];
1361 fprintf( stderr, "\tby" );
1363 if ( b->a_dn_pat.bv_len != 0 ) {
1364 if( strcmp(b->a_dn_pat.bv_val, "*") == 0
1365 || strcmp(b->a_dn_pat.bv_val, "users") == 0
1366 || strcmp(b->a_dn_pat.bv_val, "anonymous") == 0
1367 || strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1369 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1372 fprintf( stderr, " dn.%s=%s", style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1376 if ( b->a_dn_at != NULL ) {
1377 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1380 if ( b->a_group_pat.bv_len ) {
1381 fprintf( stderr, " group=%s", b->a_group_pat.bv_val );
1383 if ( b->a_group_oc ) {
1384 fprintf( stderr, " objectClass: %s",
1385 b->a_group_oc->soc_oclass.oc_oid );
1387 if ( b->a_group_at ) {
1388 fprintf( stderr, " attributeType: %s", b->a_group_at->ad_cname.bv_val );
1393 if ( b->a_peername_pat != NULL ) {
1394 fprintf( stderr, " peername=%s", b->a_peername_pat );
1397 if ( b->a_sockname_pat != NULL ) {
1398 fprintf( stderr, " sockname=%s", b->a_sockname_pat );
1401 if ( b->a_domain_pat != NULL ) {
1402 fprintf( stderr, " domain=%s", b->a_domain_pat );
1405 if ( b->a_sockurl_pat != NULL ) {
1406 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat );
1409 #ifdef SLAPD_ACI_ENABLED
1410 if ( b->a_aci_at != NULL ) {
1411 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1415 /* Security Strength Factors */
1416 if ( b->a_authz.sai_ssf ) {
1417 fprintf( stderr, " ssf=%u",
1418 b->a_authz.sai_ssf );
1420 if ( b->a_authz.sai_transport_ssf ) {
1421 fprintf( stderr, " transport_ssf=%u",
1422 b->a_authz.sai_transport_ssf );
1424 if ( b->a_authz.sai_tls_ssf ) {
1425 fprintf( stderr, " tls_ssf=%u",
1426 b->a_authz.sai_tls_ssf );
1428 if ( b->a_authz.sai_sasl_ssf ) {
1429 fprintf( stderr, " sasl_ssf=%u",
1430 b->a_authz.sai_sasl_ssf );
1433 fprintf( stderr, " %s%s",
1434 b->a_dn_self ? "self" : "",
1435 accessmask2str( b->a_access_mask, maskbuf ) );
1437 if( b->a_type == ACL_BREAK ) {
1438 fprintf( stderr, " break" );
1440 } else if( b->a_type == ACL_CONTINUE ) {
1441 fprintf( stderr, " continue" );
1443 } else if( b->a_type != ACL_STOP ) {
1444 fprintf( stderr, " unknown-control" );
1447 fprintf( stderr, "\n" );
1452 print_acl( Backend *be, AccessControl *a )
1457 fprintf( stderr, "%s ACL: access to",
1458 be == NULL ? "Global" : "Backend" );
1460 if ( a->acl_dn_pat.bv_len != 0 ) {
1462 fprintf( stderr, " dn.%s=%s\n",
1463 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
1466 if ( a->acl_filter != NULL ) {
1468 fprintf( stderr, " filter=" );
1469 filter_print( a->acl_filter );
1470 fprintf( stderr, "\n" );
1473 if ( a->acl_attrs != NULL ) {
1477 fprintf( stderr, " attrs=" );
1478 for ( i = 0; a->acl_attrs[i] != NULL; i++ ) {
1480 fprintf( stderr, "," );
1482 fputs( a->acl_attrs[i]->bv_val, stderr );
1485 fprintf( stderr, "\n" );
1489 fprintf( stderr, " *\n" );
1492 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1496 fprintf( stderr, "\n" );
1499 #endif /* LDAP_DEBUG */