1 /* aclparse.c - routines to parse and check acl's */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2003 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that this notice is preserved and that due credit is given
21 * to the University of Michigan at Ann Arbor. The name of the University
22 * may not be used to endorse or promote products derived from this
23 * software without specific prior written permission. This software
24 * is provided ``as is'' without express or implied warranty.
33 #include <ac/socket.h>
34 #include <ac/string.h>
35 #include <ac/unistd.h>
41 static char *style_strings[] = { "regex",
42 "base", "one", "subtree", "children", NULL };
44 static void split(char *line, int splitchar, char **left, char **right);
45 static void access_append(Access **l, Access *a);
46 static void acl_usage(void) LDAP_GCCATTR((noreturn));
48 static void acl_regex_normalized_dn(const char *src, struct berval *pat);
51 static void print_acl(Backend *be, AccessControl *a);
52 static void print_access(Access *b);
56 regtest(const char *fname, int lineno, char *pat) {
72 for (size = 0, flag = 0; (size < sizeof(buf)) && *sp; sp++) {
74 if (*sp == '$'|| (*sp >= '0' && *sp <= '9')) {
91 if ( size >= (sizeof(buf)-1) ) {
93 "%s: line %d: regular expression \"%s\" too large\n",
98 if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
100 regerror(e, &re, error, sizeof(error));
102 "%s: line %d: regular expression \"%s\" bad because of %s\n",
103 fname, lineno, pat, error );
119 char *left, *right, *style;
127 for ( i = 1; i < argc; i++ ) {
128 /* to clause - select which entries are protected */
129 if ( strcasecmp( argv[i], "to" ) == 0 ) {
131 fprintf( stderr, "%s: line %d: "
132 "only one to clause allowed in access line\n",
136 a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
137 for ( ++i; i < argc; i++ ) {
138 if ( strcasecmp( argv[i], "by" ) == 0 ) {
143 if ( strcasecmp( argv[i], "*" ) == 0 ) {
144 if( a->acl_dn_pat.bv_len ||
145 ( a->acl_dn_style != ACL_STYLE_REGEX ) )
148 "%s: line %d: dn pattern"
149 " already specified in to clause.\n",
154 a->acl_dn_pat.bv_val = ch_strdup( "*" );
155 a->acl_dn_pat.bv_len = 1;
159 split( argv[i], '=', &left, &right );
160 split( left, '.', &left, &style );
162 if ( right == NULL ) {
163 fprintf( stderr, "%s: line %d: "
164 "missing \"=\" in \"%s\" in to clause\n",
165 fname, lineno, left );
169 if ( strcasecmp( left, "dn" ) == 0 ) {
170 if( a->acl_dn_pat.bv_len != 0 ||
171 ( a->acl_dn_style != ACL_STYLE_REGEX ) )
174 "%s: line %d: dn pattern"
175 " already specified in to clause.\n",
180 if ( style == NULL || *style == '\0' ||
181 ( strcasecmp( style, "base" ) == 0 ) ||
182 ( strcasecmp( style, "exact" ) == 0 ))
184 a->acl_dn_style = ACL_STYLE_BASE;
185 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
187 } else if ( strcasecmp( style, "one" ) == 0 ) {
188 a->acl_dn_style = ACL_STYLE_ONE;
189 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
191 } else if ( strcasecmp( style, "subtree" ) == 0
192 || strcasecmp( style, "sub" ) == 0 )
194 if( *right == '\0' ) {
195 a->acl_dn_pat.bv_val = ch_strdup( "*" );
196 a->acl_dn_pat.bv_len = 1;
199 a->acl_dn_style = ACL_STYLE_SUBTREE;
200 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
203 } else if ( strcasecmp( style, "children" ) == 0 ) {
204 a->acl_dn_style = ACL_STYLE_CHILDREN;
205 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
207 } else if ( strcasecmp( style, "regex" ) == 0 ) {
208 a->acl_dn_style = ACL_STYLE_REGEX;
210 if ( *right == '\0' ) {
211 /* empty regex should match empty DN */
212 a->acl_dn_style = ACL_STYLE_BASE;
213 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
215 } else if ( strcmp(right, "*") == 0
216 || strcmp(right, ".*") == 0
217 || strcmp(right, ".*$") == 0
218 || strcmp(right, "^.*") == 0
219 || strcmp(right, "^.*$") == 0
220 || strcmp(right, ".*$$") == 0
221 || strcmp(right, "^.*$$") == 0 )
223 a->acl_dn_pat.bv_val = ch_strdup( "*" );
224 a->acl_dn_pat.bv_len = sizeof("*")-1;
227 acl_regex_normalized_dn( right, &a->acl_dn_pat );
231 fprintf( stderr, "%s: line %d: "
232 "unknown dn style \"%s\" in to clause\n",
233 fname, lineno, style );
240 if ( strcasecmp( left, "filter" ) == 0 ) {
241 if ( (a->acl_filter = str2filter( right )) == NULL ) {
243 "%s: line %d: bad filter \"%s\" in to clause\n",
244 fname, lineno, right );
248 } else if ( strncasecmp( left, "attr", 4 ) == 0 ) {
249 a->acl_attrs = str2anlist( a->acl_attrs,
251 if ( a->acl_attrs == NULL ) {
253 "%s: line %d: unknown attr \"%s\" in to clause\n",
254 fname, lineno, right );
258 } else if ( strncasecmp( left, "val", 3 ) == 0 ) {
259 if ( a->acl_attrval.bv_len ) {
261 "%s: line %d: attr val already specified in to clause.\n",
265 if ( a->acl_attrs == NULL || a->acl_attrs[1].an_name.bv_val ) {
267 "%s: line %d: attr val requires a single attribute.\n",
271 ber_str2bv( right, 0, 1, &a->acl_attrval );
272 if ( style && strcasecmp( style, "regex" ) == 0 ) {
273 int e = regcomp( &a->acl_attrval_re, a->acl_attrval.bv_val,
274 REG_EXTENDED | REG_ICASE | REG_NOSUB );
277 regerror( e, &a->acl_attrval_re, buf, sizeof(buf) );
278 fprintf( stderr, "%s: line %d: "
279 "regular expression \"%s\" bad because of %s\n",
280 fname, lineno, right, buf );
283 a->acl_attrval_style = ACL_STYLE_REGEX;
285 /* FIXME: if the attribute has DN syntax,
286 * we might allow one, subtree and children styles as well */
287 if ( !strcasecmp( style, "exact" ) ) {
288 a->acl_attrval_style = ACL_STYLE_BASE;
290 } else if ( a->acl_attrs[0].an_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) {
291 if ( !strcasecmp( style, "base" ) ) {
292 a->acl_attrval_style = ACL_STYLE_BASE;
293 } else if ( !strcasecmp( style, "onelevel" ) || !strcasecmp( style, "one" ) ) {
294 a->acl_attrval_style = ACL_STYLE_ONE;
295 } else if ( !strcasecmp( style, "subtree" ) || !strcasecmp( style, "sub" ) ) {
296 a->acl_attrval_style = ACL_STYLE_SUBTREE;
297 } else if ( !strcasecmp( style, "children" ) ) {
298 a->acl_attrval_style = ACL_STYLE_CHILDREN;
301 "%s: line %d: unknown val.<style> \"%s\" "
302 "for attributeType \"%s\" with DN syntax; using \"base\"\n",
303 fname, lineno, style,
304 a->acl_attrs[0].an_desc->ad_cname.bv_val );
305 a->acl_attrval_style = ACL_STYLE_BASE;
310 "%s: line %d: unknown val.<style> \"%s\" "
311 "for attributeType \"%s\"; using \"exact\"\n",
312 fname, lineno, style,
313 a->acl_attrs[0].an_desc->ad_cname.bv_val );
314 a->acl_attrval_style = ACL_STYLE_BASE;
320 "%s: line %d: expecting <what> got \"%s\"\n",
321 fname, lineno, left );
326 if ( a->acl_dn_pat.bv_len != 0 &&
327 strcmp(a->acl_dn_pat.bv_val, "*") == 0 )
329 free( a->acl_dn_pat.bv_val );
330 a->acl_dn_pat.bv_val = NULL;
331 a->acl_dn_pat.bv_len = 0;
334 if( a->acl_dn_pat.bv_len != 0 ||
335 ( a->acl_dn_style != ACL_STYLE_REGEX ) )
337 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
339 rc = dnNormalize( 0, NULL, NULL, &a->acl_dn_pat, &bv, NULL);
340 if ( rc != LDAP_SUCCESS ) {
342 "%s: line %d: bad DN \"%s\" in to DN clause\n",
343 fname, lineno, a->acl_dn_pat.bv_val );
346 free( a->acl_dn_pat.bv_val );
349 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
350 REG_EXTENDED | REG_ICASE );
353 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
354 fprintf( stderr, "%s: line %d: "
355 "regular expression \"%s\" bad because of %s\n",
356 fname, lineno, right, buf );
362 /* by clause - select who has what access to entries */
363 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
365 fprintf( stderr, "%s: line %d: "
366 "to clause required before by clause in access line\n",
372 * by clause consists of <who> and <access>
375 b = (Access *) ch_calloc( 1, sizeof(Access) );
377 ACL_INVALIDATE( b->a_access_mask );
381 "%s: line %d: premature eol: expecting <who>\n",
387 for ( ; i < argc; i++ ) {
388 slap_style_t sty = ACL_STYLE_REGEX;
389 char *style_modifier = NULL;
392 split( argv[i], '=', &left, &right );
393 split( left, '.', &left, &style );
395 split( style, ',', &style, &style_modifier);
398 if ( style == NULL || *style == '\0' ||
399 strcasecmp( style, "exact" ) == 0 ||
400 strcasecmp( style, "base" ) == 0 )
402 sty = ACL_STYLE_BASE;
404 } else if ( strcasecmp( style, "one" ) == 0 ) {
407 } else if ( strcasecmp( style, "subtree" ) == 0 ||
408 strcasecmp( style, "sub" ) == 0 )
410 sty = ACL_STYLE_SUBTREE;
412 } else if ( strcasecmp( style, "children" ) == 0 ) {
413 sty = ACL_STYLE_CHILDREN;
415 } else if ( strcasecmp( style, "regex" ) == 0 ) {
416 sty = ACL_STYLE_REGEX;
420 "%s: line %d: unknown style \"%s\" in by clause\n",
421 fname, lineno, style );
425 if ( style_modifier &&
426 strcasecmp( style_modifier, "expand" ) == 0 )
431 if ( strcasecmp( argv[i], "*" ) == 0 ) {
432 bv.bv_val = ch_strdup( "*" );
434 sty = ACL_STYLE_REGEX;
436 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
437 ber_str2bv("anonymous", sizeof("anonymous")-1, 1, &bv);
438 sty = ACL_STYLE_REGEX;
440 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
441 ber_str2bv("self", sizeof("self")-1, 1, &bv);
442 sty = ACL_STYLE_REGEX;
444 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
445 ber_str2bv("users", sizeof("users")-1, 1, &bv);
446 sty = ACL_STYLE_REGEX;
448 } else if ( strcasecmp( left, "dn" ) == 0 ) {
449 if ( sty == ACL_STYLE_REGEX ) {
450 b->a_dn_style = ACL_STYLE_REGEX;
451 if( right == NULL ) {
456 } else if (*right == '\0' ) {
458 ber_str2bv("anonymous",
459 sizeof("anonymous")-1,
461 } else if ( strcmp( right, "*" ) == 0 ) {
463 /* any or users? users for now */
467 } else if ( strcmp( right, ".+" ) == 0
468 || strcmp( right, "^.+" ) == 0
469 || strcmp( right, ".+$" ) == 0
470 || strcmp( right, "^.+$" ) == 0
471 || strcmp( right, ".+$$" ) == 0
472 || strcmp( right, "^.+$$" ) == 0 )
477 } else if ( strcmp( right, ".*" ) == 0
478 || strcmp( right, "^.*" ) == 0
479 || strcmp( right, ".*$" ) == 0
480 || strcmp( right, "^.*$" ) == 0
481 || strcmp( right, ".*$$" ) == 0
482 || strcmp( right, "^.*$$" ) == 0 )
489 acl_regex_normalized_dn( right, &bv );
490 if ( !ber_bvccmp( &bv, '*' ) ) {
491 regtest(fname, lineno, bv.bv_val);
494 } else if ( right == NULL || *right == '\0' ) {
495 fprintf( stderr, "%s: line %d: "
496 "missing \"=\" in (or value after) \"%s\" "
498 fname, lineno, left );
502 ber_str2bv( right, 0, 1, &bv );
509 if( bv.bv_val != NULL ) {
510 if( b->a_dn_pat.bv_len != 0 ) {
512 "%s: line %d: dn pattern already specified.\n",
517 if ( sty != ACL_STYLE_REGEX && expand == 0 ) {
518 rc = dnNormalize(0, NULL, NULL,
519 &bv, &b->a_dn_pat, NULL);
520 if ( rc != LDAP_SUCCESS ) {
522 "%s: line %d: bad DN \"%s\" in by DN clause\n",
523 fname, lineno, bv.bv_val );
531 b->a_dn_expand = expand;
535 if ( strcasecmp( left, "dnattr" ) == 0 ) {
536 if ( right == NULL || right[ 0 ] == '\0' ) {
538 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
539 fname, lineno, left );
543 if( b->a_dn_at != NULL ) {
545 "%s: line %d: dnattr already specified.\n",
550 rc = slap_str2ad( right, &b->a_dn_at, &text );
552 if( rc != LDAP_SUCCESS ) {
554 "%s: line %d: dnattr \"%s\": %s\n",
555 fname, lineno, right, text );
560 if( !is_at_syntax( b->a_dn_at->ad_type,
562 !is_at_syntax( b->a_dn_at->ad_type,
563 SLAPD_NAMEUID_SYNTAX ))
566 "%s: line %d: dnattr \"%s\": "
567 "inappropriate syntax: %s\n",
568 fname, lineno, right,
569 b->a_dn_at->ad_type->sat_syntax_oid );
573 if( b->a_dn_at->ad_type->sat_equality == NULL ) {
575 "%s: line %d: dnattr \"%s\": "
576 "inappropriate matching (no EQUALITY)\n",
577 fname, lineno, right );
584 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
588 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
589 fprintf( stderr, "%s: line %d: "
590 "inappropriate style \"%s\" in by clause\n",
591 fname, lineno, style );
595 if ( right == NULL || right[ 0 ] == '\0' ) {
596 fprintf( stderr, "%s: line %d: "
597 "missing \"=\" in (or value after) \"%s\" "
599 fname, lineno, left );
603 if( b->a_group_pat.bv_len ) {
605 "%s: line %d: group pattern already specified.\n",
610 /* format of string is
611 "group/objectClassValue/groupAttrName" */
612 if ((value = strchr(left, '/')) != NULL) {
614 if (*value && (name = strchr(value, '/')) != NULL) {
619 b->a_group_style = sty;
620 if (sty == ACL_STYLE_REGEX) {
621 acl_regex_normalized_dn( right, &bv );
622 if ( !ber_bvccmp( &bv, '*' ) ) {
623 regtest(fname, lineno, bv.bv_val);
627 ber_str2bv( right, 0, 0, &bv );
628 rc = dnNormalize( 0, NULL, NULL, &bv,
629 &b->a_group_pat, NULL );
630 if ( rc != LDAP_SUCCESS ) {
632 "%s: line %d: bad DN \"%s\"\n",
633 fname, lineno, right );
638 if (value && *value) {
639 b->a_group_oc = oc_find( value );
642 if( b->a_group_oc == NULL ) {
644 "%s: line %d: group objectclass "
646 fname, lineno, value );
650 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
652 if( b->a_group_oc == NULL ) {
654 "%s: line %d: group default objectclass "
656 fname, lineno, SLAPD_GROUP_CLASS );
661 if( is_object_subclass( slap_schema.si_oc_referral,
665 "%s: line %d: group objectclass \"%s\" "
666 "is subclass of referral\n",
667 fname, lineno, value );
671 if( is_object_subclass( slap_schema.si_oc_alias,
675 "%s: line %d: group objectclass \"%s\" "
676 "is subclass of alias\n",
677 fname, lineno, value );
682 rc = slap_str2ad( name, &b->a_group_at, &text );
684 if( rc != LDAP_SUCCESS ) {
686 "%s: line %d: group \"%s\": %s\n",
687 fname, lineno, right, text );
692 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
694 if( rc != LDAP_SUCCESS ) {
696 "%s: line %d: group \"%s\": %s\n",
697 fname, lineno, SLAPD_GROUP_ATTR, text );
702 if( !is_at_syntax( b->a_group_at->ad_type,
704 !is_at_syntax( b->a_group_at->ad_type,
705 SLAPD_NAMEUID_SYNTAX ) &&
706 !is_at_subtype( b->a_group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ))
709 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
710 fname, lineno, right,
711 b->a_group_at->ad_type->sat_syntax_oid );
718 struct berval vals[2];
720 vals[0].bv_val = b->a_group_oc->soc_oid;
721 vals[0].bv_len = strlen(vals[0].bv_val);
722 vals[1].bv_val = NULL;
725 rc = oc_check_allowed( b->a_group_at->ad_type,
729 fprintf( stderr, "%s: line %d: "
730 "group: \"%s\" not allowed by \"%s\"\n",
732 b->a_group_at->ad_cname.bv_val,
733 b->a_group_oc->soc_oid );
740 if ( strcasecmp( left, "peername" ) == 0 ) {
741 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
742 fprintf( stderr, "%s: line %d: "
743 "inappropriate style \"%s\" in by clause\n",
744 fname, lineno, style );
748 if ( right == NULL || right[ 0 ] == '\0' ) {
749 fprintf( stderr, "%s: line %d: "
750 "missing \"=\" in (or value after) \"%s\" "
752 fname, lineno, left );
756 if( b->a_peername_pat.bv_len ) {
757 fprintf( stderr, "%s: line %d: "
758 "peername pattern already specified.\n",
763 b->a_peername_style = sty;
764 if (sty == ACL_STYLE_REGEX) {
765 acl_regex_normalized_dn( right, &bv );
766 if ( !ber_bvccmp( &bv, '*' ) ) {
767 regtest(fname, lineno, bv.bv_val);
769 b->a_peername_pat = bv;
771 ber_str2bv( right, 0, 1, &b->a_peername_pat );
776 if ( strcasecmp( left, "sockname" ) == 0 ) {
777 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
778 fprintf( stderr, "%s: line %d: "
779 "inappropriate style \"%s\" in by clause\n",
780 fname, lineno, style );
784 if ( right == NULL || right[ 0 ] == '\0' ) {
785 fprintf( stderr, "%s: line %d: "
786 "missing \"=\" in (or value after) \"%s\" "
788 fname, lineno, left );
792 if( b->a_sockname_pat.bv_len ) {
793 fprintf( stderr, "%s: line %d: "
794 "sockname pattern already specified.\n",
799 b->a_sockname_style = sty;
800 if (sty == ACL_STYLE_REGEX) {
801 acl_regex_normalized_dn( right, &bv );
802 if ( !ber_bvccmp( &bv, '*' ) ) {
803 regtest(fname, lineno, bv.bv_val);
805 b->a_sockname_pat = bv;
807 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
812 if ( strcasecmp( left, "domain" ) == 0 ) {
814 case ACL_STYLE_REGEX:
816 case ACL_STYLE_SUBTREE:
821 "%s: line %d: inappropriate style \"%s\" in by clause\n",
822 fname, lineno, style );
826 if ( right == NULL || right[ 0 ] == '\0' ) {
828 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
829 fname, lineno, left );
833 if( b->a_domain_pat.bv_len ) {
835 "%s: line %d: domain pattern already specified.\n",
840 b->a_domain_style = sty;
841 b->a_domain_expand = expand;
842 if (sty == ACL_STYLE_REGEX) {
843 acl_regex_normalized_dn( right, &bv );
844 if ( !ber_bvccmp( &bv, '*' ) ) {
845 regtest(fname, lineno, bv.bv_val);
847 b->a_domain_pat = bv;
849 ber_str2bv( right, 0, 1, &b->a_domain_pat );
854 if ( strcasecmp( left, "sockurl" ) == 0 ) {
855 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
857 "%s: line %d: inappropriate style \"%s\" in by clause\n",
858 fname, lineno, style );
862 if ( right == NULL || right[ 0 ] == '\0' ) {
864 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
865 fname, lineno, left );
869 if( b->a_sockurl_pat.bv_len ) {
871 "%s: line %d: sockurl pattern already specified.\n",
876 b->a_sockurl_style = sty;
877 if (sty == ACL_STYLE_REGEX) {
878 acl_regex_normalized_dn( right, &bv );
879 if ( !ber_bvccmp( &bv, '*' ) ) {
880 regtest(fname, lineno, bv.bv_val);
882 b->a_sockurl_pat = bv;
884 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
889 if ( strcasecmp( left, "set" ) == 0 ) {
890 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
892 "%s: line %d: inappropriate style \"%s\" in by clause\n",
893 fname, lineno, style );
897 if( b->a_set_pat.bv_len != 0 ) {
899 "%s: line %d: set attribute already specified.\n",
904 if ( right == NULL || *right == '\0' ) {
906 "%s: line %d: no set is defined\n",
911 b->a_set_style = sty;
912 ber_str2bv( right, 0, 1, &b->a_set_pat );
917 #ifdef SLAPD_ACI_ENABLED
918 if ( strcasecmp( left, "aci" ) == 0 ) {
919 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
921 "%s: line %d: inappropriate style \"%s\" in by clause\n",
922 fname, lineno, style );
926 if( b->a_aci_at != NULL ) {
928 "%s: line %d: aci attribute already specified.\n",
933 if ( right != NULL && *right != '\0' ) {
934 rc = slap_str2ad( right, &b->a_aci_at, &text );
936 if( rc != LDAP_SUCCESS ) {
938 "%s: line %d: aci \"%s\": %s\n",
939 fname, lineno, right, text );
944 b->a_aci_at = slap_schema.si_ad_aci;
947 if( !is_at_syntax( b->a_aci_at->ad_type,
951 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
952 fname, lineno, right,
953 b->a_aci_at->ad_type->sat_syntax_oid );
959 #endif /* SLAPD_ACI_ENABLED */
961 if ( strcasecmp( left, "ssf" ) == 0 ) {
962 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
964 "%s: line %d: inappropriate style \"%s\" in by clause\n",
965 fname, lineno, style );
969 if( b->a_authz.sai_ssf ) {
971 "%s: line %d: ssf attribute already specified.\n",
976 if ( right == NULL || *right == '\0' ) {
978 "%s: line %d: no ssf is defined\n",
983 b->a_authz.sai_ssf = atoi( right );
985 if( !b->a_authz.sai_ssf ) {
987 "%s: line %d: invalid ssf value (%s)\n",
988 fname, lineno, right );
994 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
995 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
997 "%s: line %d: inappropriate style \"%s\" in by clause\n",
998 fname, lineno, style );
1002 if( b->a_authz.sai_transport_ssf ) {
1004 "%s: line %d: transport_ssf attribute already specified.\n",
1009 if ( right == NULL || *right == '\0' ) {
1011 "%s: line %d: no transport_ssf is defined\n",
1016 b->a_authz.sai_transport_ssf = atoi( right );
1018 if( !b->a_authz.sai_transport_ssf ) {
1020 "%s: line %d: invalid transport_ssf value (%s)\n",
1021 fname, lineno, right );
1027 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
1028 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1030 "%s: line %d: inappropriate style \"%s\" in by clause\n",
1031 fname, lineno, style );
1035 if( b->a_authz.sai_tls_ssf ) {
1037 "%s: line %d: tls_ssf attribute already specified.\n",
1042 if ( right == NULL || *right == '\0' ) {
1044 "%s: line %d: no tls_ssf is defined\n",
1049 b->a_authz.sai_tls_ssf = atoi( right );
1051 if( !b->a_authz.sai_tls_ssf ) {
1053 "%s: line %d: invalid tls_ssf value (%s)\n",
1054 fname, lineno, right );
1060 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1061 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1063 "%s: line %d: inappropriate style \"%s\" in by clause\n",
1064 fname, lineno, style );
1068 if( b->a_authz.sai_sasl_ssf ) {
1070 "%s: line %d: sasl_ssf attribute already specified.\n",
1075 if ( right == NULL || *right == '\0' ) {
1077 "%s: line %d: no sasl_ssf is defined\n",
1082 b->a_authz.sai_sasl_ssf = atoi( right );
1084 if( !b->a_authz.sai_sasl_ssf ) {
1086 "%s: line %d: invalid sasl_ssf value (%s)\n",
1087 fname, lineno, right );
1093 if( right != NULL ) {
1100 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
1101 /* out of arguments or plain stop */
1103 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1104 b->a_type = ACL_STOP;
1106 access_append( &a->acl_access, b );
1110 if( strcasecmp( left, "continue" ) == 0 ) {
1111 /* plain continue */
1113 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1114 b->a_type = ACL_CONTINUE;
1116 access_append( &a->acl_access, b );
1120 if( strcasecmp( left, "break" ) == 0 ) {
1121 /* plain continue */
1123 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1124 b->a_type = ACL_BREAK;
1126 access_append( &a->acl_access, b );
1130 if ( strcasecmp( left, "by" ) == 0 ) {
1131 /* we've gone too far */
1133 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1134 b->a_type = ACL_STOP;
1136 access_append( &a->acl_access, b );
1141 if( strncasecmp( left, "self", 4 ) == 0 ) {
1143 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
1146 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1149 if( ACL_IS_INVALID( b->a_access_mask ) ) {
1151 "%s: line %d: expecting <access> got \"%s\"\n",
1152 fname, lineno, left );
1156 b->a_type = ACL_STOP;
1159 /* out of arguments or plain stop */
1160 access_append( &a->acl_access, b );
1164 if( strcasecmp( argv[i], "continue" ) == 0 ) {
1165 /* plain continue */
1166 b->a_type = ACL_CONTINUE;
1168 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
1169 /* plain continue */
1170 b->a_type = ACL_BREAK;
1172 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1177 access_append( &a->acl_access, b );
1181 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
1182 fname, lineno, argv[i] );
1187 /* if we have no real access clause, complain and do nothing */
1190 "%s: line %d: warning: no access clause(s) specified in access line\n",
1195 if (ldap_debug & LDAP_DEBUG_ACL)
1199 if ( a->acl_access == NULL ) {
1201 "%s: line %d: warning: no by clause(s) specified in access line\n",
1206 acl_append( &be->be_acl, a );
1208 acl_append( &global_acl, a );
1214 accessmask2str( slap_mask_t mask, char *buf )
1219 assert( buf != NULL );
1221 if ( ACL_IS_INVALID( mask ) ) {
1227 if ( ACL_IS_LEVEL( mask ) ) {
1228 if ( ACL_LVL_IS_NONE(mask) ) {
1229 ptr = lutil_strcopy( ptr, "none" );
1231 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1232 ptr = lutil_strcopy( ptr, "auth" );
1234 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1235 ptr = lutil_strcopy( ptr, "compare" );
1237 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1238 ptr = lutil_strcopy( ptr, "search" );
1240 } else if ( ACL_LVL_IS_READ(mask) ) {
1241 ptr = lutil_strcopy( ptr, "read" );
1243 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1244 ptr = lutil_strcopy( ptr, "write" );
1246 ptr = lutil_strcopy( ptr, "unknown" );
1252 if( ACL_IS_ADDITIVE( mask ) ) {
1255 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1262 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1267 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1272 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1277 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1282 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1287 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1296 if ( ACL_IS_LEVEL( mask ) ) {
1306 str2accessmask( const char *str )
1310 if( !ASCII_ALPHA(str[0]) ) {
1313 if ( str[0] == '=' ) {
1316 } else if( str[0] == '+' ) {
1317 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1319 } else if( str[0] == '-' ) {
1320 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1323 ACL_INVALIDATE(mask);
1327 for( i=1; str[i] != '\0'; i++ ) {
1328 if( TOLOWER((unsigned char) str[i]) == 'w' ) {
1329 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1331 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
1332 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1334 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
1335 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1337 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
1338 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1340 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
1341 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1343 } else if( str[i] != '0' ) {
1344 ACL_INVALIDATE(mask);
1352 if ( strcasecmp( str, "none" ) == 0 ) {
1353 ACL_LVL_ASSIGN_NONE(mask);
1355 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1356 ACL_LVL_ASSIGN_AUTH(mask);
1358 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1359 ACL_LVL_ASSIGN_COMPARE(mask);
1361 } else if ( strcasecmp( str, "search" ) == 0 ) {
1362 ACL_LVL_ASSIGN_SEARCH(mask);
1364 } else if ( strcasecmp( str, "read" ) == 0 ) {
1365 ACL_LVL_ASSIGN_READ(mask);
1367 } else if ( strcasecmp( str, "write" ) == 0 ) {
1368 ACL_LVL_ASSIGN_WRITE(mask);
1371 ACL_INVALIDATE( mask );
1380 fprintf( stderr, "%s%s\n",
1381 "<access clause> ::= access to <what> "
1382 "[ by <who> <access> [ <control> ] ]+ \n"
1383 "<what> ::= * | [dn[.<dnstyle>]=<DN>] [filter=<filter>] [attrs=<attrlist>]\n"
1384 "<attrlist> ::= <attr> [val[.<style>]=<value>] | <attr> , <attrlist>\n"
1385 "<attr> ::= <attrname> | entry | children\n"
1386 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
1387 "\t[dnattr=<attrname>]\n"
1388 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
1389 "\t[peername[.<style>]=<peer>] [sockname[.<style>]=<name>]\n",
1390 "\t[domain[.<style>]=<domain>] [sockurl[.<style>]=<url>]\n"
1391 #ifdef SLAPD_ACI_ENABLED
1392 "\t[aci=<attrname>]\n"
1394 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1395 "<dnstyle> ::= base | exact | one | subtree | children | regex\n"
1396 "<style> ::= regex | base | exact\n"
1397 "<access> ::= [self]{<level>|<priv>}\n"
1398 "<level> ::= none | auth | compare | search | read | write\n"
1399 "<priv> ::= {=|+|-}{w|r|s|c|x|0}+\n"
1400 "<control> ::= [ stop | continue | break ]\n"
1402 exit( EXIT_FAILURE );
1406 * Set pattern to a "normalized" DN from src.
1407 * At present it simply eats the (optional) space after
1408 * a RDN separator (,)
1409 * Eventually will evolve in a more complete normalization
1412 acl_regex_normalized_dn(
1414 struct berval *pattern
1420 str = ch_strdup( src );
1421 len = strlen( src );
1423 for ( p = str; p && p[ 0 ]; p++ ) {
1425 if ( p[ 0 ] == '\\' && p[ 1 ] ) {
1427 * if escaping a hex pair we should
1428 * increment p twice; however, in that
1429 * case the second hex number does
1435 if ( p[ 0 ] == ',' ) {
1436 if ( p[ 1 ] == ' ' ) {
1440 * too much space should be
1441 * an error if we are pedantic
1443 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1446 AC_MEMCPY( p+1, q, len-(q-str)+1);
1450 pattern->bv_val = str;
1451 pattern->bv_len = p-str;
1465 if ( (*right = strchr( line, splitchar )) != NULL ) {
1466 *((*right)++) = '\0';
1471 access_append( Access **l, Access *a )
1473 for ( ; *l != NULL; l = &(*l)->a_next )
1480 acl_append( AccessControl **l, AccessControl *a )
1482 for ( ; *l != NULL; l = &(*l)->acl_next )
1489 access_free( Access *a )
1491 if ( a->a_dn_pat.bv_val )
1492 free ( a->a_dn_pat.bv_val );
1493 if ( a->a_peername_pat.bv_val )
1494 free ( a->a_peername_pat.bv_val );
1495 if ( a->a_sockname_pat.bv_val )
1496 free ( a->a_sockname_pat.bv_val );
1497 if ( a->a_domain_pat.bv_val )
1498 free ( a->a_domain_pat.bv_val );
1499 if ( a->a_sockurl_pat.bv_val )
1500 free ( a->a_sockurl_pat.bv_val );
1501 if ( a->a_set_pat.bv_len )
1502 free ( a->a_set_pat.bv_val );
1503 if ( a->a_group_pat.bv_len )
1504 free ( a->a_group_pat.bv_val );
1509 acl_free( AccessControl *a )
1514 if ( a->acl_filter )
1515 filter_free( a->acl_filter );
1516 if ( a->acl_dn_pat.bv_len )
1517 free ( a->acl_dn_pat.bv_val );
1518 if ( a->acl_attrs ) {
1519 for ( an = a->acl_attrs; an->an_name.bv_val; an++ ) {
1520 free( an->an_name.bv_val );
1522 free( a->acl_attrs );
1524 for (; a->acl_access; a->acl_access = n) {
1525 n = a->acl_access->a_next;
1526 access_free( a->acl_access );
1531 /* Because backend_startup uses acl_append to tack on the global_acl to
1532 * the end of each backend's acl, we cannot just take one argument and
1533 * merrily free our way to the end of the list. backend_destroy calls us
1534 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1535 * point. config_destroy calls us with global_acl in arg1 and NULL in
1536 * arg2, so we then proceed to polish off the global_acl.
1539 acl_destroy( AccessControl *a, AccessControl *end )
1543 for (; a && a!= end; a=n) {
1550 access2str( slap_access_t access )
1552 if ( access == ACL_NONE ) {
1555 } else if ( access == ACL_AUTH ) {
1558 } else if ( access == ACL_COMPARE ) {
1561 } else if ( access == ACL_SEARCH ) {
1564 } else if ( access == ACL_READ ) {
1567 } else if ( access == ACL_WRITE ) {
1575 str2access( const char *str )
1577 if ( strcasecmp( str, "none" ) == 0 ) {
1580 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1583 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1586 } else if ( strcasecmp( str, "search" ) == 0 ) {
1589 } else if ( strcasecmp( str, "read" ) == 0 ) {
1592 } else if ( strcasecmp( str, "write" ) == 0 ) {
1596 return( ACL_INVALID_ACCESS );
1602 print_access( Access *b )
1604 char maskbuf[ACCESSMASK_MAXLEN];
1606 fprintf( stderr, "\tby" );
1608 if ( b->a_dn_pat.bv_len != 0 ) {
1609 if( strcmp(b->a_dn_pat.bv_val, "*") == 0
1610 || strcmp(b->a_dn_pat.bv_val, "users") == 0
1611 || strcmp(b->a_dn_pat.bv_val, "anonymous") == 0
1612 || strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1614 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1617 fprintf( stderr, " dn.%s=\"%s\"",
1618 style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1622 if ( b->a_dn_at != NULL ) {
1623 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1626 if ( b->a_group_pat.bv_len ) {
1627 fprintf( stderr, " group/%s/%s.%s=\"%s\"",
1628 b->a_group_oc ? b->a_group_oc->soc_cname.bv_val : "groupOfNames",
1629 b->a_group_at ? b->a_group_at->ad_cname.bv_val : "member",
1630 style_strings[b->a_group_style],
1631 b->a_group_pat.bv_val );
1634 if ( b->a_peername_pat.bv_len != 0 ) {
1635 fprintf( stderr, " peername=\"%s\"", b->a_peername_pat.bv_val );
1638 if ( b->a_sockname_pat.bv_len != 0 ) {
1639 fprintf( stderr, " sockname=\"%s\"", b->a_sockname_pat.bv_val );
1642 if ( b->a_domain_pat.bv_len != 0 ) {
1643 fprintf( stderr, " domain=%s", b->a_domain_pat.bv_val );
1646 if ( b->a_sockurl_pat.bv_len != 0 ) {
1647 fprintf( stderr, " sockurl=\"%s\"", b->a_sockurl_pat.bv_val );
1650 #ifdef SLAPD_ACI_ENABLED
1651 if ( b->a_aci_at != NULL ) {
1652 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1656 /* Security Strength Factors */
1657 if ( b->a_authz.sai_ssf ) {
1658 fprintf( stderr, " ssf=%u",
1659 b->a_authz.sai_ssf );
1661 if ( b->a_authz.sai_transport_ssf ) {
1662 fprintf( stderr, " transport_ssf=%u",
1663 b->a_authz.sai_transport_ssf );
1665 if ( b->a_authz.sai_tls_ssf ) {
1666 fprintf( stderr, " tls_ssf=%u",
1667 b->a_authz.sai_tls_ssf );
1669 if ( b->a_authz.sai_sasl_ssf ) {
1670 fprintf( stderr, " sasl_ssf=%u",
1671 b->a_authz.sai_sasl_ssf );
1674 fprintf( stderr, " %s%s",
1675 b->a_dn_self ? "self" : "",
1676 accessmask2str( b->a_access_mask, maskbuf ) );
1678 if( b->a_type == ACL_BREAK ) {
1679 fprintf( stderr, " break" );
1681 } else if( b->a_type == ACL_CONTINUE ) {
1682 fprintf( stderr, " continue" );
1684 } else if( b->a_type != ACL_STOP ) {
1685 fprintf( stderr, " unknown-control" );
1688 fprintf( stderr, "\n" );
1693 print_acl( Backend *be, AccessControl *a )
1698 fprintf( stderr, "%s ACL: access to",
1699 be == NULL ? "Global" : "Backend" );
1701 if ( a->acl_dn_pat.bv_len != 0 ) {
1703 fprintf( stderr, " dn.%s=\"%s\"\n",
1704 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
1707 if ( a->acl_filter != NULL ) {
1708 struct berval bv = { 0, NULL };
1710 filter2bv( a->acl_filter, &bv );
1711 fprintf( stderr, " filter=%s\n", bv.bv_val );
1712 ch_free( bv.bv_val );
1715 if ( a->acl_attrs != NULL ) {
1720 fprintf( stderr, " attrs=" );
1721 for ( an = a->acl_attrs; an && an->an_name.bv_val; an++ ) {
1723 fprintf( stderr, "," );
1726 fputc( an->an_oc_exclude ? '!' : '@', stderr);
1728 fputs( an->an_name.bv_val, stderr );
1731 fprintf( stderr, "\n" );
1734 if ( a->acl_attrval.bv_len != 0 ) {
1736 fprintf( stderr, " val.%s=\"%s\"\n",
1737 style_strings[a->acl_attrval_style], a->acl_attrval.bv_val );
1742 fprintf( stderr, " *\n" );
1745 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1749 fprintf( stderr, "\n" );
1752 #endif /* LDAP_DEBUG */