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>
21 static void split(char *line, int splitchar, char **left, char **right);
22 static void access_append(Access **l, Access *a);
23 static void acl_usage(void) LDAP_GCCATTR((noreturn));
25 static void acl_regex_normalized_dn(struct berval *pattern);
28 static void print_acl(Backend *be, AccessControl *a);
29 static void print_access(Access *b);
33 regtest(const char *fname, int lineno, char *pat) {
49 for (size = 0, flag = 0; (size < sizeof(buf)) && *sp; sp++) {
51 if (*sp == '$'|| (*sp >= '0' && *sp <= '9')) {
68 if ( size >= (sizeof(buf)-1) ) {
70 "%s: line %d: regular expression \"%s\" too large\n",
75 if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
77 regerror(e, &re, error, sizeof(error));
79 "%s: line %d: regular expression \"%s\" bad because of %s\n",
80 fname, lineno, pat, error );
98 char *left, *right, *style;
106 for ( i = 1; i < argc; i++ ) {
107 /* to clause - select which entries are protected */
108 if ( strcasecmp( argv[i], "to" ) == 0 ) {
111 "%s: line %d: only one to clause allowed in access line\n",
115 a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
116 for ( ++i; i < argc; i++ ) {
117 if ( strcasecmp( argv[i], "by" ) == 0 ) {
122 if ( strcasecmp( argv[i], "*" ) == 0 ) {
123 if( a->acl_dn_pat.bv_len != 0 ) {
125 "%s: line %d: dn pattern"
126 " already specified in to clause.\n",
131 a->acl_dn_pat.bv_val = ch_strdup( "*" );
132 a->acl_dn_pat.bv_len = 1;
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.bv_len != 0 ) {
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;
160 if ( *right == '\0' ) {
161 /* empty regex should match empty DN */
162 a->acl_dn_style = ACL_STYLE_BASE;
163 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
165 } else if ( strcmp(right, "*") == 0
166 || strcmp(right, ".*") == 0
167 || strcmp(right, ".*$") == 0
168 || strcmp(right, "^.*") == 0
169 || strcmp(right, "^.*$$") == 0
170 || strcmp(right, ".*$$") == 0
171 || strcmp(right, "^.*$$") == 0 )
173 a->acl_dn_pat.bv_val = ch_strdup( "*" );
174 a->acl_dn_pat.bv_len = sizeof("*")-1;
177 a->acl_dn_pat.bv_val = right;
178 acl_regex_normalized_dn( &a->acl_dn_pat );
180 } else if ( strcasecmp( style, "base" ) == 0 ) {
181 a->acl_dn_style = ACL_STYLE_BASE;
182 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
183 } else if ( strcasecmp( style, "one" ) == 0 ) {
184 a->acl_dn_style = ACL_STYLE_ONE;
185 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
186 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
187 a->acl_dn_style = ACL_STYLE_SUBTREE;
188 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
189 } else if ( strcasecmp( style, "children" ) == 0 ) {
190 a->acl_dn_style = ACL_STYLE_CHILDREN;
191 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
194 "%s: line %d: unknown dn style \"%s\" in to clause\n",
195 fname, lineno, style );
202 if ( strcasecmp( left, "filter" ) == 0 ) {
203 if ( (a->acl_filter = str2filter(
206 "%s: line %d: bad filter \"%s\" in to clause\n",
207 fname, lineno, right );
211 } else if ( strncasecmp( left, "attr", 4 ) == 0 ) {
212 a->acl_attrs = str2anlist( a->acl_attrs,
214 if ( a->acl_attrs == NULL ) {
216 "%s: line %d: unknown attr \"%s\" in to clause\n",
217 fname, lineno, right );
222 "%s: line %d: expecting <what> got \"%s\"\n",
223 fname, lineno, left );
228 if ( a->acl_dn_pat.bv_len != 0 &&
229 strcmp(a->acl_dn_pat.bv_val, "*") == 0)
231 free( a->acl_dn_pat.bv_val );
232 a->acl_dn_pat.bv_val = NULL;
233 a->acl_dn_pat.bv_len = 0;
236 if( a->acl_dn_pat.bv_len != 0 ) {
237 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
239 dnNormalize2( NULL, &a->acl_dn_pat, &bv);
240 free( a->acl_dn_pat.bv_val );
243 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
244 REG_EXTENDED | REG_ICASE );
247 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
248 fprintf( stderr, "%s: line %d: "
249 "regular expression \"%s\" bad because of %s\n",
250 fname, lineno, right, buf );
256 /* by clause - select who has what access to entries */
257 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
260 "%s: line %d: to clause required before by clause in access line\n",
266 * by clause consists of <who> and <access>
269 b = (Access *) ch_calloc( 1, sizeof(Access) );
271 ACL_INVALIDATE( b->a_access_mask );
275 "%s: line %d: premature eol: expecting <who>\n",
281 for ( ; i < argc; i++ ) {
282 slap_style_t sty = ACL_STYLE_REGEX;
284 split( argv[i], '=', &left, &right );
285 split( left, '.', &left, &style );
286 if ( style == NULL || *style == '\0'
287 || strcasecmp( style, "regex" ) == 0 )
289 sty = ACL_STYLE_REGEX;
290 } else if ( strcasecmp( style, "exact" ) == 0 ) {
291 sty = ACL_STYLE_EXACT;
292 } else if ( strcasecmp( style, "base" ) == 0 ) {
293 sty = ACL_STYLE_BASE;
294 } else if ( strcasecmp( style, "one" ) == 0 ) {
296 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
297 sty = ACL_STYLE_SUBTREE;
298 } else if ( strcasecmp( style, "children" ) == 0 ) {
299 sty = ACL_STYLE_CHILDREN;
302 "%s: line %d: unknown style \"%s\" in by clause\n",
303 fname, lineno, style );
307 if ( strcasecmp( argv[i], "*" ) == 0 ) {
308 bv.bv_val = ch_strdup( "*" );
311 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
312 ber_str2bv("anonymous",
313 sizeof("anonymous")-1,
316 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
321 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
326 } else if ( strcasecmp( left, "dn" ) == 0 ) {
327 if ( sty == ACL_STYLE_REGEX ) {
328 b->a_dn_style = ACL_STYLE_REGEX;
329 if( right == NULL ) {
334 } else if (*right == '\0' ) {
336 ber_str2bv("anonymous",
337 sizeof("anonymous")-1,
339 } else if ( strcmp( right, "*" ) == 0 ) {
341 /* any or users? users for now */
345 } else if ( strcmp( right, ".+" ) == 0
346 || strcmp( right, "^.+" ) == 0
347 || strcmp( right, ".+$" ) == 0
348 || strcmp( right, "^.+$" ) == 0
349 || strcmp( right, ".+$$" ) == 0
350 || strcmp( right, "^.+$$" ) == 0 )
355 } else if ( strcmp( right, ".*" ) == 0
356 || strcmp( right, "^.*" ) == 0
357 || strcmp( right, ".*$" ) == 0
358 || strcmp( right, "^.*$" ) == 0
359 || strcmp( right, ".*$$" ) == 0
360 || strcmp( right, "^.*$$" ) == 0 )
368 acl_regex_normalized_dn( &bv );
369 if ( !ber_bvccmp( &bv, '*' ) ) {
370 regtest(fname, lineno, bv.bv_val);
373 } else if ( right == NULL || *right == '\0' ) {
375 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
376 fname, lineno, left );
380 ber_str2bv( right, 0, 1, &bv );
387 if( bv.bv_val != NULL ) {
388 if( b->a_dn_pat.bv_len != 0 ) {
390 "%s: line %d: dn pattern already specified.\n",
395 if ( sty != ACL_STYLE_REGEX ) {
396 dnNormalize2(NULL, &bv, &b->a_dn_pat);
405 if ( strcasecmp( left, "dnattr" ) == 0 ) {
406 if ( right == NULL || right[ 0 ] == '\0' ) {
408 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
409 fname, lineno, left );
413 if( b->a_dn_at != NULL ) {
415 "%s: line %d: dnattr already specified.\n",
420 rc = slap_str2ad( right, &b->a_dn_at, &text );
422 if( rc != LDAP_SUCCESS ) {
424 "%s: line %d: dnattr \"%s\": %s\n",
425 fname, lineno, right, text );
430 if( !is_at_syntax( b->a_dn_at->ad_type,
432 !is_at_syntax( b->a_dn_at->ad_type,
433 SLAPD_NAMEUID_SYNTAX ))
436 "%s: line %d: dnattr \"%s\": "
437 "inappropriate syntax: %s\n",
438 fname, lineno, right,
439 b->a_dn_at->ad_type->sat_syntax_oid );
446 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
448 "%s: line %d: inappropriate style \"%s\" in by clause\n",
449 fname, lineno, style );
453 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
457 if ( right == NULL || right[ 0 ] == '\0' ) {
459 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
460 fname, lineno, left );
464 if( b->a_group_pat.bv_len ) {
466 "%s: line %d: group pattern already specified.\n",
471 /* format of string is "group/objectClassValue/groupAttrName" */
472 if ((value = strchr(left, '/')) != NULL) {
475 && (name = strchr(value, '/')) != NULL)
481 b->a_group_style = sty;
482 if (sty == ACL_STYLE_REGEX) {
484 acl_regex_normalized_dn( &bv );
485 if ( !ber_bvccmp( &bv, '*' ) ) {
486 regtest(fname, lineno, bv.bv_val);
490 ber_str2bv( right, 0, 0, &bv );
491 dnNormalize2( NULL, &bv, &b->a_group_pat );
494 if (value && *value) {
495 b->a_group_oc = oc_find( value );
498 if( b->a_group_oc == NULL ) {
500 "%s: line %d: group objectclass "
502 fname, lineno, value );
506 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
508 if( b->a_group_oc == NULL ) {
510 "%s: line %d: group default objectclass "
512 fname, lineno, SLAPD_GROUP_CLASS );
517 if( is_object_subclass( slap_schema.si_oc_referral,
521 "%s: line %d: group objectclass \"%s\" "
522 "is subclass of referral\n",
523 fname, lineno, value );
527 if( is_object_subclass( slap_schema.si_oc_alias,
531 "%s: line %d: group objectclass \"%s\" "
532 "is subclass of alias\n",
533 fname, lineno, value );
538 rc = slap_str2ad( name, &b->a_group_at, &text );
540 if( rc != LDAP_SUCCESS ) {
542 "%s: line %d: group \"%s\": %s\n",
543 fname, lineno, right, text );
548 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
550 if( rc != LDAP_SUCCESS ) {
552 "%s: line %d: group \"%s\": %s\n",
553 fname, lineno, SLAPD_GROUP_ATTR, text );
558 if( !is_at_syntax( b->a_group_at->ad_type,
560 !is_at_syntax( b->a_group_at->ad_type,
561 SLAPD_NAMEUID_SYNTAX ) )
564 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
565 fname, lineno, right,
566 b->a_group_at->ad_type->sat_syntax_oid );
573 struct berval vals[2];
575 vals[0].bv_val = b->a_group_oc->soc_oid;
576 vals[0].bv_len = strlen(vals[0].bv_val);
577 vals[1].bv_val = NULL;
580 rc = oc_check_allowed( b->a_group_at->ad_type, vals, NULL );
584 "%s: line %d: group: \"%s\" not allowed by \"%s\"\n",
586 b->a_group_at->ad_cname.bv_val,
587 b->a_group_oc->soc_oid );
594 if ( strcasecmp( left, "peername" ) == 0 ) {
595 if ( right == NULL || right[ 0 ] == '\0' ) {
597 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
598 fname, lineno, left );
602 if( b->a_peername_pat.bv_len ) {
604 "%s: line %d: peername pattern already specified.\n",
609 b->a_peername_style = sty;
610 if (sty == ACL_STYLE_REGEX) {
612 acl_regex_normalized_dn( &bv );
613 if ( !ber_bvccmp( &bv, '*' ) ) {
614 regtest(fname, lineno, bv.bv_val);
616 b->a_peername_pat = bv;
618 ber_str2bv( right, 0, 1, &b->a_peername_pat );
623 if ( strcasecmp( left, "sockname" ) == 0 ) {
624 if ( right == NULL || right[ 0 ] == '\0' ) {
626 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
627 fname, lineno, left );
631 if( b->a_sockname_pat.bv_len ) {
633 "%s: line %d: sockname pattern already specified.\n",
638 b->a_sockname_style = sty;
639 if (sty == ACL_STYLE_REGEX) {
641 acl_regex_normalized_dn( &bv );
642 if ( !ber_bvccmp( &bv, '*' ) ) {
643 regtest(fname, lineno, bv.bv_val);
645 b->a_sockname_pat = bv;
647 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
652 if ( strcasecmp( left, "domain" ) == 0 ) {
653 if ( right == NULL || right[ 0 ] == '\0' ) {
655 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
656 fname, lineno, left );
660 if( b->a_domain_pat.bv_len ) {
662 "%s: line %d: domain pattern already specified.\n",
667 b->a_domain_style = sty;
668 if (sty == ACL_STYLE_REGEX) {
670 acl_regex_normalized_dn( &bv );
671 if ( !ber_bvccmp( &bv, '*' ) ) {
672 regtest(fname, lineno, bv.bv_val);
674 b->a_domain_pat = bv;
676 ber_str2bv( right, 0, 1, &b->a_domain_pat );
681 if ( strcasecmp( left, "sockurl" ) == 0 ) {
682 if ( right == NULL || right[ 0 ] == '\0' ) {
684 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
685 fname, lineno, left );
689 if( b->a_sockurl_pat.bv_len ) {
691 "%s: line %d: sockurl pattern already specified.\n",
696 b->a_sockurl_style = sty;
697 if (sty == ACL_STYLE_REGEX) {
699 acl_regex_normalized_dn( &bv );
700 if ( !ber_bvccmp( &bv, '*' ) ) {
701 regtest(fname, lineno, bv.bv_val);
703 b->a_sockurl_pat = bv;
705 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
710 if ( strcasecmp( left, "set" ) == 0 ) {
711 if( b->a_set_pat.bv_len != 0 ) {
713 "%s: line %d: set attribute already specified.\n",
718 if ( right == NULL || *right == '\0' ) {
720 "%s: line %d: no set is defined\n",
725 b->a_set_style = sty;
726 ber_str2bv( right, 0, 1, &b->a_set_pat );
731 #ifdef SLAPD_ACI_ENABLED
732 if ( strcasecmp( left, "aci" ) == 0 ) {
733 if( b->a_aci_at != NULL ) {
735 "%s: line %d: aci attribute already specified.\n",
740 if ( right != NULL && *right != '\0' ) {
741 rc = slap_str2ad( right, &b->a_aci_at, &text );
743 if( rc != LDAP_SUCCESS ) {
745 "%s: line %d: aci \"%s\": %s\n",
746 fname, lineno, right, text );
751 b->a_aci_at = slap_schema.si_ad_aci;
754 if( !is_at_syntax( b->a_aci_at->ad_type,
758 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
759 fname, lineno, right,
760 b->a_aci_at->ad_type->sat_syntax_oid );
766 #endif /* SLAPD_ACI_ENABLED */
768 if ( strcasecmp( left, "ssf" ) == 0 ) {
769 if( b->a_authz.sai_ssf ) {
771 "%s: line %d: ssf attribute already specified.\n",
776 if ( right == NULL || *right == '\0' ) {
778 "%s: line %d: no ssf is defined\n",
783 b->a_authz.sai_ssf = atoi( right );
785 if( !b->a_authz.sai_ssf ) {
787 "%s: line %d: invalid ssf value (%s)\n",
788 fname, lineno, right );
794 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
795 if( b->a_authz.sai_transport_ssf ) {
797 "%s: line %d: transport_ssf attribute already specified.\n",
802 if ( right == NULL || *right == '\0' ) {
804 "%s: line %d: no transport_ssf is defined\n",
809 b->a_authz.sai_transport_ssf = atoi( right );
811 if( !b->a_authz.sai_transport_ssf ) {
813 "%s: line %d: invalid transport_ssf value (%s)\n",
814 fname, lineno, right );
820 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
821 if( b->a_authz.sai_tls_ssf ) {
823 "%s: line %d: tls_ssf attribute already specified.\n",
828 if ( right == NULL || *right == '\0' ) {
830 "%s: line %d: no tls_ssf is defined\n",
835 b->a_authz.sai_tls_ssf = atoi( right );
837 if( !b->a_authz.sai_tls_ssf ) {
839 "%s: line %d: invalid tls_ssf value (%s)\n",
840 fname, lineno, right );
846 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
847 if( b->a_authz.sai_sasl_ssf ) {
849 "%s: line %d: sasl_ssf attribute already specified.\n",
854 if ( right == NULL || *right == '\0' ) {
856 "%s: line %d: no sasl_ssf is defined\n",
861 b->a_authz.sai_sasl_ssf = atoi( right );
863 if( !b->a_authz.sai_sasl_ssf ) {
865 "%s: line %d: invalid sasl_ssf value (%s)\n",
866 fname, lineno, right );
872 if( right != NULL ) {
879 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
880 /* out of arguments or plain stop */
882 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
883 b->a_type = ACL_STOP;
885 access_append( &a->acl_access, b );
889 if( strcasecmp( left, "continue" ) == 0 ) {
892 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
893 b->a_type = ACL_CONTINUE;
895 access_append( &a->acl_access, b );
899 if( strcasecmp( left, "break" ) == 0 ) {
902 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
903 b->a_type = ACL_BREAK;
905 access_append( &a->acl_access, b );
909 if ( strcasecmp( left, "by" ) == 0 ) {
910 /* we've gone too far */
912 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
913 b->a_type = ACL_STOP;
915 access_append( &a->acl_access, b );
920 if( strncasecmp( left, "self", 4 ) == 0 ) {
922 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
925 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
928 if( ACL_IS_INVALID( b->a_access_mask ) ) {
930 "%s: line %d: expecting <access> got \"%s\"\n",
931 fname, lineno, left );
935 b->a_type = ACL_STOP;
938 /* out of arguments or plain stop */
939 access_append( &a->acl_access, b );
943 if( strcasecmp( argv[i], "continue" ) == 0 ) {
945 b->a_type = ACL_CONTINUE;
947 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
949 b->a_type = ACL_BREAK;
951 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
956 access_append( &a->acl_access, b );
960 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
961 fname, lineno, argv[i] );
966 /* if we have no real access clause, complain and do nothing */
969 "%s: line %d: warning: no access clause(s) specified in access line\n",
974 if (ldap_debug & LDAP_DEBUG_ACL)
978 if ( a->acl_access == NULL ) {
980 "%s: line %d: warning: no by clause(s) specified in access line\n",
985 acl_append( &be->be_acl, a );
987 acl_append( &global_acl, a );
993 accessmask2str( slap_mask_t mask, char *buf )
998 assert( buf != NULL );
1000 if ( ACL_IS_INVALID( mask ) ) {
1006 if ( ACL_IS_LEVEL( mask ) ) {
1007 if ( ACL_LVL_IS_NONE(mask) ) {
1008 ptr = slap_strcopy( ptr, "none" );
1010 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1011 ptr = slap_strcopy( ptr, "auth" );
1013 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1014 ptr = slap_strcopy( ptr, "compare" );
1016 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1017 ptr = slap_strcopy( ptr, "search" );
1019 } else if ( ACL_LVL_IS_READ(mask) ) {
1020 ptr = slap_strcopy( ptr, "read" );
1022 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1023 ptr = slap_strcopy( ptr, "write" );
1025 ptr = slap_strcopy( ptr, "unknown" );
1031 if( ACL_IS_ADDITIVE( mask ) ) {
1034 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1041 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1046 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1051 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1056 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1061 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1066 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1075 if ( ACL_IS_LEVEL( mask ) ) {
1085 str2accessmask( const char *str )
1089 if( !ASCII_ALPHA(str[0]) ) {
1092 if ( str[0] == '=' ) {
1095 } else if( str[0] == '+' ) {
1096 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1098 } else if( str[0] == '-' ) {
1099 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1102 ACL_INVALIDATE(mask);
1106 for( i=1; str[i] != '\0'; i++ ) {
1107 if( TOLOWER(str[i]) == 'w' ) {
1108 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1110 } else if( TOLOWER(str[i]) == 'r' ) {
1111 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1113 } else if( TOLOWER(str[i]) == 's' ) {
1114 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1116 } else if( TOLOWER(str[i]) == 'c' ) {
1117 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1119 } else if( TOLOWER(str[i]) == 'x' ) {
1120 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1122 } else if( str[i] != '0' ) {
1123 ACL_INVALIDATE(mask);
1131 if ( strcasecmp( str, "none" ) == 0 ) {
1132 ACL_LVL_ASSIGN_NONE(mask);
1134 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1135 ACL_LVL_ASSIGN_AUTH(mask);
1137 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1138 ACL_LVL_ASSIGN_COMPARE(mask);
1140 } else if ( strcasecmp( str, "search" ) == 0 ) {
1141 ACL_LVL_ASSIGN_SEARCH(mask);
1143 } else if ( strcasecmp( str, "read" ) == 0 ) {
1144 ACL_LVL_ASSIGN_READ(mask);
1146 } else if ( strcasecmp( str, "write" ) == 0 ) {
1147 ACL_LVL_ASSIGN_WRITE(mask);
1150 ACL_INVALIDATE( mask );
1159 fprintf( stderr, "\n"
1160 "<access clause> ::= access to <what> "
1161 "[ by <who> <access> [ <control> ] ]+ \n"
1162 "<what> ::= * | [dn[.<dnstyle>]=<regex>] [filter=<ldapfilter>] [attrs=<attrlist>]\n"
1163 "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
1164 "<attr> ::= <attrname> | entry | children\n"
1165 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<regex> ]\n"
1166 "\t[dnattr=<attrname>]\n"
1167 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<regex>]\n"
1168 "\t[peername[.<style>]=<regex>] [sockname[.<style>]=<regex>]\n"
1169 "\t[domain[.<style>]=<regex>] [sockurl[.<style>]=<regex>]\n"
1170 #ifdef SLAPD_ACI_ENABLED
1171 "\t[aci=<attrname>]\n"
1173 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1174 "<dnstyle> ::= regex | base | exact (alias of base) | one | sub | children\n"
1175 "<style> ::= regex | base | exact (alias of base)\n"
1176 "<groupflags> ::= R\n"
1177 "<access> ::= [self]{<level>|<priv>}\n"
1178 "<level> ::= none | auth | compare | search | read | write\n"
1179 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
1180 "<control> ::= [ stop | continue | break ]\n"
1182 exit( EXIT_FAILURE );
1186 * At present it simply eats the (optional) space after
1187 * a RDN separator (,)
1188 * Eventually will evolve in a more complete normalization
1190 * Note that the input berval only needs bv_val, it ignores
1191 * the input bv_len and sets it on return.
1194 acl_regex_normalized_dn(
1195 struct berval *pattern
1200 str = ch_strdup( pattern->bv_val );
1202 for ( p = str; p && p[ 0 ]; p++ ) {
1204 if ( p[ 0 ] == '\\' ) {
1206 * if escaping a hex pair we should
1207 * increment p twice; however, in that
1208 * case the second hex number does
1214 if ( p[ 0 ] == ',' ) {
1215 if ( p[ 1 ] == ' ' ) {
1219 * too much space should be
1220 * an error if we are pedantic
1222 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1225 AC_MEMCPY( p+1, q, pattern->bv_len-(q-str)+1);
1229 pattern->bv_val = str;
1230 pattern->bv_len = p-str;
1244 if ( (*right = strchr( line, splitchar )) != NULL ) {
1245 *((*right)++) = '\0';
1250 access_append( Access **l, Access *a )
1252 for ( ; *l != NULL; l = &(*l)->a_next )
1259 acl_append( AccessControl **l, AccessControl *a )
1261 for ( ; *l != NULL; l = &(*l)->acl_next )
1268 access_free( Access *a )
1270 if ( a->a_dn_pat.bv_val )
1271 free ( a->a_dn_pat.bv_val );
1272 if ( a->a_peername_pat.bv_val )
1273 free ( a->a_peername_pat.bv_val );
1274 if ( a->a_sockname_pat.bv_val )
1275 free ( a->a_sockname_pat.bv_val );
1276 if ( a->a_domain_pat.bv_val )
1277 free ( a->a_domain_pat.bv_val );
1278 if ( a->a_sockurl_pat.bv_val )
1279 free ( a->a_sockurl_pat.bv_val );
1280 if ( a->a_set_pat.bv_len )
1281 free ( a->a_set_pat.bv_val );
1282 if ( a->a_group_pat.bv_len )
1283 free ( a->a_group_pat.bv_val );
1288 acl_free( AccessControl *a )
1293 if ( a->acl_filter )
1294 filter_free( a->acl_filter );
1295 if ( a->acl_dn_pat.bv_len )
1296 free ( a->acl_dn_pat.bv_val );
1297 if ( a->acl_attrs ) {
1298 for ( an = a->acl_attrs; an->an_name.bv_val; an++ ) {
1299 free( an->an_name.bv_val );
1301 free( a->acl_attrs );
1303 for (; a->acl_access; a->acl_access = n) {
1304 n = a->acl_access->a_next;
1305 access_free( a->acl_access );
1310 /* Because backend_startup uses acl_append to tack on the global_acl to
1311 * the end of each backend's acl, we cannot just take one argument and
1312 * merrily free our way to the end of the list. backend_destroy calls us
1313 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1314 * point. config_destroy calls us with global_acl in arg1 and NULL in
1315 * arg2, so we then proceed to polish off the global_acl.
1318 acl_destroy( AccessControl *a, AccessControl *end )
1322 for (; a && a!= end; a=n) {
1329 access2str( slap_access_t access )
1331 if ( access == ACL_NONE ) {
1334 } else if ( access == ACL_AUTH ) {
1337 } else if ( access == ACL_COMPARE ) {
1340 } else if ( access == ACL_SEARCH ) {
1343 } else if ( access == ACL_READ ) {
1346 } else if ( access == ACL_WRITE ) {
1354 str2access( const char *str )
1356 if ( strcasecmp( str, "none" ) == 0 ) {
1359 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1362 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1365 } else if ( strcasecmp( str, "search" ) == 0 ) {
1368 } else if ( strcasecmp( str, "read" ) == 0 ) {
1371 } else if ( strcasecmp( str, "write" ) == 0 ) {
1375 return( ACL_INVALID_ACCESS );
1380 static char *style_strings[5] = {
1390 print_access( Access *b )
1392 char maskbuf[ACCESSMASK_MAXLEN];
1394 fprintf( stderr, "\tby" );
1396 if ( b->a_dn_pat.bv_len != 0 ) {
1397 if( strcmp(b->a_dn_pat.bv_val, "*") == 0
1398 || strcmp(b->a_dn_pat.bv_val, "users") == 0
1399 || strcmp(b->a_dn_pat.bv_val, "anonymous") == 0
1400 || strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1402 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1405 fprintf( stderr, " dn.%s=%s",
1406 style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1410 if ( b->a_dn_at != NULL ) {
1411 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1414 if ( b->a_group_pat.bv_len ) {
1415 fprintf( stderr, " group=%s", b->a_group_pat.bv_val );
1417 if ( b->a_group_oc ) {
1418 fprintf( stderr, " objectClass: %s",
1419 b->a_group_oc->soc_oclass.oc_oid );
1421 if ( b->a_group_at ) {
1422 fprintf( stderr, " attributeType: %s", b->a_group_at->ad_cname.bv_val );
1427 if ( b->a_peername_pat.bv_len != 0 ) {
1428 fprintf( stderr, " peername=%s", b->a_peername_pat.bv_val );
1431 if ( b->a_sockname_pat.bv_len != 0 ) {
1432 fprintf( stderr, " sockname=%s", b->a_sockname_pat.bv_val );
1435 if ( b->a_domain_pat.bv_len != 0 ) {
1436 fprintf( stderr, " domain=%s", b->a_domain_pat.bv_val );
1439 if ( b->a_sockurl_pat.bv_len != 0 ) {
1440 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat.bv_val );
1443 #ifdef SLAPD_ACI_ENABLED
1444 if ( b->a_aci_at != NULL ) {
1445 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1449 /* Security Strength Factors */
1450 if ( b->a_authz.sai_ssf ) {
1451 fprintf( stderr, " ssf=%u",
1452 b->a_authz.sai_ssf );
1454 if ( b->a_authz.sai_transport_ssf ) {
1455 fprintf( stderr, " transport_ssf=%u",
1456 b->a_authz.sai_transport_ssf );
1458 if ( b->a_authz.sai_tls_ssf ) {
1459 fprintf( stderr, " tls_ssf=%u",
1460 b->a_authz.sai_tls_ssf );
1462 if ( b->a_authz.sai_sasl_ssf ) {
1463 fprintf( stderr, " sasl_ssf=%u",
1464 b->a_authz.sai_sasl_ssf );
1467 fprintf( stderr, " %s%s",
1468 b->a_dn_self ? "self" : "",
1469 accessmask2str( b->a_access_mask, maskbuf ) );
1471 if( b->a_type == ACL_BREAK ) {
1472 fprintf( stderr, " break" );
1474 } else if( b->a_type == ACL_CONTINUE ) {
1475 fprintf( stderr, " continue" );
1477 } else if( b->a_type != ACL_STOP ) {
1478 fprintf( stderr, " unknown-control" );
1481 fprintf( stderr, "\n" );
1486 print_acl( Backend *be, AccessControl *a )
1491 fprintf( stderr, "%s ACL: access to",
1492 be == NULL ? "Global" : "Backend" );
1494 if ( a->acl_dn_pat.bv_len != 0 ) {
1496 fprintf( stderr, " dn.%s=%s\n",
1497 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
1500 if ( a->acl_filter != NULL ) {
1501 struct berval bv = { 0, NULL };
1503 filter2bv( a->acl_filter, &bv );
1504 fprintf( stderr, " filter=%s\n", bv.bv_val );
1505 ch_free( bv.bv_val );
1508 if ( a->acl_attrs != NULL ) {
1513 fprintf( stderr, " attrs=" );
1514 for ( an = a->acl_attrs; an && an->an_name.bv_val; an++ ) {
1516 fprintf( stderr, "," );
1518 fputs( an->an_name.bv_val, stderr );
1521 fprintf( stderr, "\n" );
1525 fprintf( stderr, " *\n" );
1528 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1532 fprintf( stderr, "\n" );
1535 #endif /* LDAP_DEBUG */