1 /* aclparse.c - routines to parse and check acl's */
4 * Copyright 1998-2003 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>
22 static void split(char *line, int splitchar, char **left, char **right);
23 static void access_append(Access **l, Access *a);
24 static void acl_usage(void) LDAP_GCCATTR((noreturn));
26 static void acl_regex_normalized_dn(const char *src, struct berval *pat);
29 static void print_acl(Backend *be, AccessControl *a);
30 static void print_access(Access *b);
34 regtest(const char *fname, int lineno, char *pat) {
50 for (size = 0, flag = 0; (size < sizeof(buf)) && *sp; sp++) {
52 if (*sp == '$'|| (*sp >= '0' && *sp <= '9')) {
69 if ( size >= (sizeof(buf)-1) ) {
71 "%s: line %d: regular expression \"%s\" too large\n",
76 if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
78 regerror(e, &re, error, sizeof(error));
80 "%s: line %d: regular expression \"%s\" bad because of %s\n",
81 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 ) {
109 fprintf( stderr, "%s: line %d: "
110 "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 ||
123 ( a->acl_dn_style != ACL_STYLE_REGEX ) )
126 "%s: line %d: dn pattern"
127 " already specified in to clause.\n",
132 a->acl_dn_pat.bv_val = ch_strdup( "*" );
133 a->acl_dn_pat.bv_len = 1;
137 split( argv[i], '=', &left, &right );
138 split( left, '.', &left, &style );
140 if ( right == NULL ) {
141 fprintf( stderr, "%s: line %d: "
142 "missing \"=\" in \"%s\" in to clause\n",
143 fname, lineno, left );
147 if ( strcasecmp( left, "dn" ) == 0 ) {
148 if( a->acl_dn_pat.bv_len != 0 ||
149 ( a->acl_dn_style != ACL_STYLE_REGEX ) )
152 "%s: line %d: dn pattern"
153 " already specified in to clause.\n",
158 if ( style == NULL || *style == '\0' ||
159 ( strcasecmp( style, "base" ) == 0 ) ||
160 ( strcasecmp( style, "exact" ) == 0 ))
162 a->acl_dn_style = ACL_STYLE_BASE;
163 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
165 } else if ( strcasecmp( style, "one" ) == 0 ) {
166 a->acl_dn_style = ACL_STYLE_ONE;
167 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
169 } else if ( strcasecmp( style, "subtree" ) == 0
170 || strcasecmp( style, "sub" ) == 0 )
172 if( *right == '\0' ) {
173 a->acl_dn_pat.bv_val = ch_strdup( "*" );
174 a->acl_dn_pat.bv_len = 1;
177 a->acl_dn_style = ACL_STYLE_SUBTREE;
178 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
181 } else if ( strcasecmp( style, "children" ) == 0 ) {
182 a->acl_dn_style = ACL_STYLE_CHILDREN;
183 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
185 } else if ( strcasecmp( style, "regex" ) == 0 ) {
186 a->acl_dn_style = ACL_STYLE_REGEX;
188 if ( *right == '\0' ) {
189 /* empty regex should match empty DN */
190 a->acl_dn_style = ACL_STYLE_BASE;
191 ber_str2bv( right, 0, 1, &a->acl_dn_pat );
193 } else if ( strcmp(right, "*") == 0
194 || strcmp(right, ".*") == 0
195 || strcmp(right, ".*$") == 0
196 || strcmp(right, "^.*") == 0
197 || strcmp(right, "^.*$") == 0
198 || strcmp(right, ".*$$") == 0
199 || strcmp(right, "^.*$$") == 0 )
201 a->acl_dn_pat.bv_val = ch_strdup( "*" );
202 a->acl_dn_pat.bv_len = sizeof("*")-1;
205 acl_regex_normalized_dn( right, &a->acl_dn_pat );
209 fprintf( stderr, "%s: line %d: "
210 "unknown dn style \"%s\" in to clause\n",
211 fname, lineno, style );
218 if ( strcasecmp( left, "filter" ) == 0 ) {
219 if ( (a->acl_filter = str2filter( right )) == NULL ) {
221 "%s: line %d: bad filter \"%s\" in to clause\n",
222 fname, lineno, right );
226 } else if ( strncasecmp( left, "attr", 4 ) == 0 ) {
227 a->acl_attrs = str2anlist( a->acl_attrs,
229 if ( a->acl_attrs == NULL ) {
231 "%s: line %d: unknown attr \"%s\" in to clause\n",
232 fname, lineno, right );
236 } else if ( strncasecmp( left, "val", 3 ) == 0 ) {
237 if ( a->acl_attrval.bv_len ) {
239 "%s: line %d: attr val already specified in to clause.\n",
243 if ( a->acl_attrs == NULL || a->acl_attrs[1].an_name.bv_val ) {
245 "%s: line %d: attr val requires a single attribute.\n",
249 ber_str2bv( right, 0, 1, &a->acl_attrval );
250 if ( style && strcasecmp( style, "regex" ) == 0 ) {
251 int e = regcomp( &a->acl_attrval_re, a->acl_attrval.bv_val,
252 REG_EXTENDED | REG_ICASE | REG_NOSUB );
255 regerror( e, &a->acl_attrval_re, buf, sizeof(buf) );
256 fprintf( stderr, "%s: line %d: "
257 "regular expression \"%s\" bad because of %s\n",
258 fname, lineno, right, buf );
261 a->acl_attrval_style = ACL_STYLE_REGEX;
263 a->acl_attrval_style = ACL_STYLE_BASE;
268 "%s: line %d: expecting <what> got \"%s\"\n",
269 fname, lineno, left );
274 if ( a->acl_dn_pat.bv_len != 0 &&
275 strcmp(a->acl_dn_pat.bv_val, "*") == 0 )
277 free( a->acl_dn_pat.bv_val );
278 a->acl_dn_pat.bv_val = NULL;
279 a->acl_dn_pat.bv_len = 0;
282 if( a->acl_dn_pat.bv_len != 0 ||
283 ( a->acl_dn_style != ACL_STYLE_REGEX ) )
285 if ( a->acl_dn_style != ACL_STYLE_REGEX ) {
287 rc = dnNormalize( 0, NULL, NULL, &a->acl_dn_pat, &bv, NULL);
288 if ( rc != LDAP_SUCCESS ) {
290 "%s: line %d: bad DN \"%s\" in to DN clause\n",
291 fname, lineno, a->acl_dn_pat.bv_val );
294 free( a->acl_dn_pat.bv_val );
297 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
298 REG_EXTENDED | REG_ICASE );
301 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
302 fprintf( stderr, "%s: line %d: "
303 "regular expression \"%s\" bad because of %s\n",
304 fname, lineno, right, buf );
310 /* by clause - select who has what access to entries */
311 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
313 fprintf( stderr, "%s: line %d: "
314 "to clause required before by clause in access line\n",
320 * by clause consists of <who> and <access>
323 b = (Access *) ch_calloc( 1, sizeof(Access) );
325 ACL_INVALIDATE( b->a_access_mask );
329 "%s: line %d: premature eol: expecting <who>\n",
335 for ( ; i < argc; i++ ) {
336 slap_style_t sty = ACL_STYLE_REGEX;
337 char *style_modifier = NULL;
340 split( argv[i], '=', &left, &right );
341 split( left, '.', &left, &style );
343 split( style, ',', &style, &style_modifier);
346 if ( style == NULL || *style == '\0' ||
347 strcasecmp( style, "exact" ) == 0 ||
348 strcasecmp( style, "base" ) == 0 )
350 sty = ACL_STYLE_BASE;
352 } else if ( strcasecmp( style, "one" ) == 0 ) {
355 } else if ( strcasecmp( style, "subtree" ) == 0 ||
356 strcasecmp( style, "sub" ) == 0 )
358 sty = ACL_STYLE_SUBTREE;
360 } else if ( strcasecmp( style, "children" ) == 0 ) {
361 sty = ACL_STYLE_CHILDREN;
363 } else if ( strcasecmp( style, "regex" ) == 0 ) {
364 sty = ACL_STYLE_REGEX;
368 "%s: line %d: unknown style \"%s\" in by clause\n",
369 fname, lineno, style );
373 if ( style_modifier &&
374 strcasecmp( style_modifier, "expand" ) == 0 )
379 if ( strcasecmp( argv[i], "*" ) == 0 ) {
380 bv.bv_val = ch_strdup( "*" );
382 sty = ACL_STYLE_REGEX;
384 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
385 ber_str2bv("anonymous", sizeof("anonymous")-1, 1, &bv);
386 sty = ACL_STYLE_REGEX;
388 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
389 ber_str2bv("self", sizeof("self")-1, 1, &bv);
390 sty = ACL_STYLE_REGEX;
392 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
393 ber_str2bv("users", sizeof("users")-1, 1, &bv);
394 sty = ACL_STYLE_REGEX;
396 } else if ( strcasecmp( left, "dn" ) == 0 ) {
397 if ( sty == ACL_STYLE_REGEX ) {
398 b->a_dn_style = ACL_STYLE_REGEX;
399 if( right == NULL ) {
404 } else if (*right == '\0' ) {
406 ber_str2bv("anonymous",
407 sizeof("anonymous")-1,
409 } else if ( strcmp( right, "*" ) == 0 ) {
411 /* any or users? users for now */
415 } else if ( strcmp( right, ".+" ) == 0
416 || strcmp( right, "^.+" ) == 0
417 || strcmp( right, ".+$" ) == 0
418 || strcmp( right, "^.+$" ) == 0
419 || strcmp( right, ".+$$" ) == 0
420 || strcmp( right, "^.+$$" ) == 0 )
425 } else if ( strcmp( right, ".*" ) == 0
426 || strcmp( right, "^.*" ) == 0
427 || strcmp( right, ".*$" ) == 0
428 || strcmp( right, "^.*$" ) == 0
429 || strcmp( right, ".*$$" ) == 0
430 || strcmp( right, "^.*$$" ) == 0 )
437 acl_regex_normalized_dn( right, &bv );
438 if ( !ber_bvccmp( &bv, '*' ) ) {
439 regtest(fname, lineno, bv.bv_val);
442 } else if ( right == NULL || *right == '\0' ) {
443 fprintf( stderr, "%s: line %d: "
444 "missing \"=\" in (or value after) \"%s\" "
446 fname, lineno, left );
450 ber_str2bv( right, 0, 1, &bv );
457 if( bv.bv_val != NULL ) {
458 if( b->a_dn_pat.bv_len != 0 ) {
460 "%s: line %d: dn pattern already specified.\n",
465 if ( sty != ACL_STYLE_REGEX && expand == 0 ) {
466 rc = dnNormalize(0, NULL, NULL,
467 &bv, &b->a_dn_pat, NULL);
468 if ( rc != LDAP_SUCCESS ) {
470 "%s: line %d: bad DN \"%s\" in by DN clause\n",
471 fname, lineno, bv.bv_val );
479 b->a_dn_expand = expand;
483 if ( strcasecmp( left, "dnattr" ) == 0 ) {
484 if ( right == NULL || right[ 0 ] == '\0' ) {
486 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
487 fname, lineno, left );
491 if( b->a_dn_at != NULL ) {
493 "%s: line %d: dnattr already specified.\n",
498 rc = slap_str2ad( right, &b->a_dn_at, &text );
500 if( rc != LDAP_SUCCESS ) {
502 "%s: line %d: dnattr \"%s\": %s\n",
503 fname, lineno, right, text );
508 if( !is_at_syntax( b->a_dn_at->ad_type,
510 !is_at_syntax( b->a_dn_at->ad_type,
511 SLAPD_NAMEUID_SYNTAX ))
514 "%s: line %d: dnattr \"%s\": "
515 "inappropriate syntax: %s\n",
516 fname, lineno, right,
517 b->a_dn_at->ad_type->sat_syntax_oid );
521 if( b->a_dn_at->ad_type->sat_equality == NULL ) {
523 "%s: line %d: dnattr \"%s\": "
524 "inappropriate matching (no EQUALITY)\n",
525 fname, lineno, right );
532 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
536 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
537 fprintf( stderr, "%s: line %d: "
538 "inappropriate style \"%s\" in by clause\n",
539 fname, lineno, style );
543 if ( right == NULL || right[ 0 ] == '\0' ) {
544 fprintf( stderr, "%s: line %d: "
545 "missing \"=\" in (or value after) \"%s\" "
547 fname, lineno, left );
551 if( b->a_group_pat.bv_len ) {
553 "%s: line %d: group pattern already specified.\n",
558 /* format of string is
559 "group/objectClassValue/groupAttrName" */
560 if ((value = strchr(left, '/')) != NULL) {
562 if (*value && (name = strchr(value, '/')) != NULL) {
567 b->a_group_style = sty;
568 if (sty == ACL_STYLE_REGEX) {
569 acl_regex_normalized_dn( right, &bv );
570 if ( !ber_bvccmp( &bv, '*' ) ) {
571 regtest(fname, lineno, bv.bv_val);
575 ber_str2bv( right, 0, 0, &bv );
576 rc = dnNormalize( 0, NULL, NULL, &bv,
577 &b->a_group_pat, NULL );
578 if ( rc != LDAP_SUCCESS ) {
580 "%s: line %d: bad DN \"%s\"\n",
581 fname, lineno, right );
586 if (value && *value) {
587 b->a_group_oc = oc_find( value );
590 if( b->a_group_oc == NULL ) {
592 "%s: line %d: group objectclass "
594 fname, lineno, value );
598 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
600 if( b->a_group_oc == NULL ) {
602 "%s: line %d: group default objectclass "
604 fname, lineno, SLAPD_GROUP_CLASS );
609 if( is_object_subclass( slap_schema.si_oc_referral,
613 "%s: line %d: group objectclass \"%s\" "
614 "is subclass of referral\n",
615 fname, lineno, value );
619 if( is_object_subclass( slap_schema.si_oc_alias,
623 "%s: line %d: group objectclass \"%s\" "
624 "is subclass of alias\n",
625 fname, lineno, value );
630 rc = slap_str2ad( name, &b->a_group_at, &text );
632 if( rc != LDAP_SUCCESS ) {
634 "%s: line %d: group \"%s\": %s\n",
635 fname, lineno, right, text );
640 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
642 if( rc != LDAP_SUCCESS ) {
644 "%s: line %d: group \"%s\": %s\n",
645 fname, lineno, SLAPD_GROUP_ATTR, text );
650 if( !is_at_syntax( b->a_group_at->ad_type,
652 !is_at_syntax( b->a_group_at->ad_type,
653 SLAPD_NAMEUID_SYNTAX ) &&
654 !is_at_subtype( b->a_group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ))
657 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
658 fname, lineno, right,
659 b->a_group_at->ad_type->sat_syntax_oid );
666 struct berval vals[2];
668 vals[0].bv_val = b->a_group_oc->soc_oid;
669 vals[0].bv_len = strlen(vals[0].bv_val);
670 vals[1].bv_val = NULL;
673 rc = oc_check_allowed( b->a_group_at->ad_type,
677 fprintf( stderr, "%s: line %d: "
678 "group: \"%s\" not allowed by \"%s\"\n",
680 b->a_group_at->ad_cname.bv_val,
681 b->a_group_oc->soc_oid );
688 if ( strcasecmp( left, "peername" ) == 0 ) {
689 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
690 fprintf( stderr, "%s: line %d: "
691 "inappropriate style \"%s\" in by clause\n",
692 fname, lineno, style );
696 if ( right == NULL || right[ 0 ] == '\0' ) {
697 fprintf( stderr, "%s: line %d: "
698 "missing \"=\" in (or value after) \"%s\" "
700 fname, lineno, left );
704 if( b->a_peername_pat.bv_len ) {
705 fprintf( stderr, "%s: line %d: "
706 "peername pattern already specified.\n",
711 b->a_peername_style = sty;
712 if (sty == ACL_STYLE_REGEX) {
713 acl_regex_normalized_dn( right, &bv );
714 if ( !ber_bvccmp( &bv, '*' ) ) {
715 regtest(fname, lineno, bv.bv_val);
717 b->a_peername_pat = bv;
719 ber_str2bv( right, 0, 1, &b->a_peername_pat );
724 if ( strcasecmp( left, "sockname" ) == 0 ) {
725 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
726 fprintf( stderr, "%s: line %d: "
727 "inappropriate style \"%s\" in by clause\n",
728 fname, lineno, style );
732 if ( right == NULL || right[ 0 ] == '\0' ) {
733 fprintf( stderr, "%s: line %d: "
734 "missing \"=\" in (or value after) \"%s\" "
736 fname, lineno, left );
740 if( b->a_sockname_pat.bv_len ) {
741 fprintf( stderr, "%s: line %d: "
742 "sockname pattern already specified.\n",
747 b->a_sockname_style = sty;
748 if (sty == ACL_STYLE_REGEX) {
749 acl_regex_normalized_dn( right, &bv );
750 if ( !ber_bvccmp( &bv, '*' ) ) {
751 regtest(fname, lineno, bv.bv_val);
753 b->a_sockname_pat = bv;
755 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
760 if ( strcasecmp( left, "domain" ) == 0 ) {
762 case ACL_STYLE_REGEX:
764 case ACL_STYLE_SUBTREE:
769 "%s: line %d: inappropriate style \"%s\" in by clause\n",
770 fname, lineno, style );
774 if ( right == NULL || right[ 0 ] == '\0' ) {
776 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
777 fname, lineno, left );
781 if( b->a_domain_pat.bv_len ) {
783 "%s: line %d: domain pattern already specified.\n",
788 b->a_domain_style = sty;
789 b->a_domain_expand = expand;
790 if (sty == ACL_STYLE_REGEX) {
791 acl_regex_normalized_dn( right, &bv );
792 if ( !ber_bvccmp( &bv, '*' ) ) {
793 regtest(fname, lineno, bv.bv_val);
795 b->a_domain_pat = bv;
797 ber_str2bv( right, 0, 1, &b->a_domain_pat );
802 if ( strcasecmp( left, "sockurl" ) == 0 ) {
803 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
805 "%s: line %d: inappropriate style \"%s\" in by clause\n",
806 fname, lineno, style );
810 if ( right == NULL || right[ 0 ] == '\0' ) {
812 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
813 fname, lineno, left );
817 if( b->a_sockurl_pat.bv_len ) {
819 "%s: line %d: sockurl pattern already specified.\n",
824 b->a_sockurl_style = sty;
825 if (sty == ACL_STYLE_REGEX) {
826 acl_regex_normalized_dn( right, &bv );
827 if ( !ber_bvccmp( &bv, '*' ) ) {
828 regtest(fname, lineno, bv.bv_val);
830 b->a_sockurl_pat = bv;
832 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
837 if ( strcasecmp( left, "set" ) == 0 ) {
838 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
840 "%s: line %d: inappropriate style \"%s\" in by clause\n",
841 fname, lineno, style );
845 if( b->a_set_pat.bv_len != 0 ) {
847 "%s: line %d: set attribute already specified.\n",
852 if ( right == NULL || *right == '\0' ) {
854 "%s: line %d: no set is defined\n",
859 b->a_set_style = sty;
860 ber_str2bv( right, 0, 1, &b->a_set_pat );
865 #ifdef SLAPD_ACI_ENABLED
866 if ( strcasecmp( left, "aci" ) == 0 ) {
867 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
869 "%s: line %d: inappropriate style \"%s\" in by clause\n",
870 fname, lineno, style );
874 if( b->a_aci_at != NULL ) {
876 "%s: line %d: aci attribute already specified.\n",
881 if ( right != NULL && *right != '\0' ) {
882 rc = slap_str2ad( right, &b->a_aci_at, &text );
884 if( rc != LDAP_SUCCESS ) {
886 "%s: line %d: aci \"%s\": %s\n",
887 fname, lineno, right, text );
892 b->a_aci_at = slap_schema.si_ad_aci;
895 if( !is_at_syntax( b->a_aci_at->ad_type,
899 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
900 fname, lineno, right,
901 b->a_aci_at->ad_type->sat_syntax_oid );
907 #endif /* SLAPD_ACI_ENABLED */
909 if ( strcasecmp( left, "ssf" ) == 0 ) {
910 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
912 "%s: line %d: inappropriate style \"%s\" in by clause\n",
913 fname, lineno, style );
917 if( b->a_authz.sai_ssf ) {
919 "%s: line %d: ssf attribute already specified.\n",
924 if ( right == NULL || *right == '\0' ) {
926 "%s: line %d: no ssf is defined\n",
931 b->a_authz.sai_ssf = atoi( right );
933 if( !b->a_authz.sai_ssf ) {
935 "%s: line %d: invalid ssf value (%s)\n",
936 fname, lineno, right );
942 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
943 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
945 "%s: line %d: inappropriate style \"%s\" in by clause\n",
946 fname, lineno, style );
950 if( b->a_authz.sai_transport_ssf ) {
952 "%s: line %d: transport_ssf attribute already specified.\n",
957 if ( right == NULL || *right == '\0' ) {
959 "%s: line %d: no transport_ssf is defined\n",
964 b->a_authz.sai_transport_ssf = atoi( right );
966 if( !b->a_authz.sai_transport_ssf ) {
968 "%s: line %d: invalid transport_ssf value (%s)\n",
969 fname, lineno, right );
975 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
976 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
978 "%s: line %d: inappropriate style \"%s\" in by clause\n",
979 fname, lineno, style );
983 if( b->a_authz.sai_tls_ssf ) {
985 "%s: line %d: tls_ssf attribute already specified.\n",
990 if ( right == NULL || *right == '\0' ) {
992 "%s: line %d: no tls_ssf is defined\n",
997 b->a_authz.sai_tls_ssf = atoi( right );
999 if( !b->a_authz.sai_tls_ssf ) {
1001 "%s: line %d: invalid tls_ssf value (%s)\n",
1002 fname, lineno, right );
1008 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1009 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1011 "%s: line %d: inappropriate style \"%s\" in by clause\n",
1012 fname, lineno, style );
1016 if( b->a_authz.sai_sasl_ssf ) {
1018 "%s: line %d: sasl_ssf attribute already specified.\n",
1023 if ( right == NULL || *right == '\0' ) {
1025 "%s: line %d: no sasl_ssf is defined\n",
1030 b->a_authz.sai_sasl_ssf = atoi( right );
1032 if( !b->a_authz.sai_sasl_ssf ) {
1034 "%s: line %d: invalid sasl_ssf value (%s)\n",
1035 fname, lineno, right );
1041 if( right != NULL ) {
1048 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
1049 /* out of arguments or plain stop */
1051 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1052 b->a_type = ACL_STOP;
1054 access_append( &a->acl_access, b );
1058 if( strcasecmp( left, "continue" ) == 0 ) {
1059 /* plain continue */
1061 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1062 b->a_type = ACL_CONTINUE;
1064 access_append( &a->acl_access, b );
1068 if( strcasecmp( left, "break" ) == 0 ) {
1069 /* plain continue */
1071 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1072 b->a_type = ACL_BREAK;
1074 access_append( &a->acl_access, b );
1078 if ( strcasecmp( left, "by" ) == 0 ) {
1079 /* we've gone too far */
1081 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1082 b->a_type = ACL_STOP;
1084 access_append( &a->acl_access, b );
1089 if( strncasecmp( left, "self", 4 ) == 0 ) {
1091 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
1094 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1097 if( ACL_IS_INVALID( b->a_access_mask ) ) {
1099 "%s: line %d: expecting <access> got \"%s\"\n",
1100 fname, lineno, left );
1104 b->a_type = ACL_STOP;
1107 /* out of arguments or plain stop */
1108 access_append( &a->acl_access, b );
1112 if( strcasecmp( argv[i], "continue" ) == 0 ) {
1113 /* plain continue */
1114 b->a_type = ACL_CONTINUE;
1116 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
1117 /* plain continue */
1118 b->a_type = ACL_BREAK;
1120 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1125 access_append( &a->acl_access, b );
1129 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
1130 fname, lineno, argv[i] );
1135 /* if we have no real access clause, complain and do nothing */
1138 "%s: line %d: warning: no access clause(s) specified in access line\n",
1143 if (ldap_debug & LDAP_DEBUG_ACL)
1147 if ( a->acl_access == NULL ) {
1149 "%s: line %d: warning: no by clause(s) specified in access line\n",
1154 acl_append( &be->be_acl, a );
1156 acl_append( &global_acl, a );
1162 accessmask2str( slap_mask_t mask, char *buf )
1167 assert( buf != NULL );
1169 if ( ACL_IS_INVALID( mask ) ) {
1175 if ( ACL_IS_LEVEL( mask ) ) {
1176 if ( ACL_LVL_IS_NONE(mask) ) {
1177 ptr = lutil_strcopy( ptr, "none" );
1179 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1180 ptr = lutil_strcopy( ptr, "auth" );
1182 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1183 ptr = lutil_strcopy( ptr, "compare" );
1185 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1186 ptr = lutil_strcopy( ptr, "search" );
1188 } else if ( ACL_LVL_IS_READ(mask) ) {
1189 ptr = lutil_strcopy( ptr, "read" );
1191 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1192 ptr = lutil_strcopy( ptr, "write" );
1194 ptr = lutil_strcopy( ptr, "unknown" );
1200 if( ACL_IS_ADDITIVE( mask ) ) {
1203 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1210 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1215 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1220 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1225 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1230 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1235 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1244 if ( ACL_IS_LEVEL( mask ) ) {
1254 str2accessmask( const char *str )
1258 if( !ASCII_ALPHA(str[0]) ) {
1261 if ( str[0] == '=' ) {
1264 } else if( str[0] == '+' ) {
1265 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1267 } else if( str[0] == '-' ) {
1268 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1271 ACL_INVALIDATE(mask);
1275 for( i=1; str[i] != '\0'; i++ ) {
1276 if( TOLOWER((unsigned char) str[i]) == 'w' ) {
1277 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1279 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
1280 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1282 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
1283 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1285 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
1286 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1288 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
1289 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1291 } else if( str[i] != '0' ) {
1292 ACL_INVALIDATE(mask);
1300 if ( strcasecmp( str, "none" ) == 0 ) {
1301 ACL_LVL_ASSIGN_NONE(mask);
1303 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1304 ACL_LVL_ASSIGN_AUTH(mask);
1306 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1307 ACL_LVL_ASSIGN_COMPARE(mask);
1309 } else if ( strcasecmp( str, "search" ) == 0 ) {
1310 ACL_LVL_ASSIGN_SEARCH(mask);
1312 } else if ( strcasecmp( str, "read" ) == 0 ) {
1313 ACL_LVL_ASSIGN_READ(mask);
1315 } else if ( strcasecmp( str, "write" ) == 0 ) {
1316 ACL_LVL_ASSIGN_WRITE(mask);
1319 ACL_INVALIDATE( mask );
1328 fprintf( stderr, "%s%s\n",
1329 "<access clause> ::= access to <what> "
1330 "[ by <who> <access> [ <control> ] ]+ \n"
1331 "<what> ::= * | [dn[.<dnstyle>]=<DN>] [filter=<filter>] [attrs=<attrlist>]\n"
1332 "<attrlist> ::= <attr> [val[.<style>]=<value>] | <attr> , <attrlist>\n"
1333 "<attr> ::= <attrname> | entry | children\n"
1334 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
1335 "\t[dnattr=<attrname>]\n"
1336 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
1337 "\t[peername[.<style>]=<peer>] [sockname[.<style>]=<name>]\n",
1338 "\t[domain[.<style>]=<domain>] [sockurl[.<style>]=<url>]\n"
1339 #ifdef SLAPD_ACI_ENABLED
1340 "\t[aci=<attrname>]\n"
1342 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1343 "<dnstyle> ::= base | exact | one | subtree | children | regex\n"
1344 "<style> ::= regex | base | exact\n"
1345 "<access> ::= [self]{<level>|<priv>}\n"
1346 "<level> ::= none | auth | compare | search | read | write\n"
1347 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
1348 "<control> ::= [ stop | continue | break ]\n"
1350 exit( EXIT_FAILURE );
1354 * Set pattern to a "normalized" DN from src.
1355 * At present it simply eats the (optional) space after
1356 * a RDN separator (,)
1357 * Eventually will evolve in a more complete normalization
1360 acl_regex_normalized_dn(
1362 struct berval *pattern
1368 str = ch_strdup( src );
1369 len = strlen( src );
1371 for ( p = str; p && p[ 0 ]; p++ ) {
1373 if ( p[ 0 ] == '\\' && p[ 1 ] ) {
1375 * if escaping a hex pair we should
1376 * increment p twice; however, in that
1377 * case the second hex number does
1383 if ( p[ 0 ] == ',' ) {
1384 if ( p[ 1 ] == ' ' ) {
1388 * too much space should be
1389 * an error if we are pedantic
1391 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1394 AC_MEMCPY( p+1, q, len-(q-str)+1);
1398 pattern->bv_val = str;
1399 pattern->bv_len = p-str;
1413 if ( (*right = strchr( line, splitchar )) != NULL ) {
1414 *((*right)++) = '\0';
1419 access_append( Access **l, Access *a )
1421 for ( ; *l != NULL; l = &(*l)->a_next )
1428 acl_append( AccessControl **l, AccessControl *a )
1430 for ( ; *l != NULL; l = &(*l)->acl_next )
1437 access_free( Access *a )
1439 if ( a->a_dn_pat.bv_val )
1440 free ( a->a_dn_pat.bv_val );
1441 if ( a->a_peername_pat.bv_val )
1442 free ( a->a_peername_pat.bv_val );
1443 if ( a->a_sockname_pat.bv_val )
1444 free ( a->a_sockname_pat.bv_val );
1445 if ( a->a_domain_pat.bv_val )
1446 free ( a->a_domain_pat.bv_val );
1447 if ( a->a_sockurl_pat.bv_val )
1448 free ( a->a_sockurl_pat.bv_val );
1449 if ( a->a_set_pat.bv_len )
1450 free ( a->a_set_pat.bv_val );
1451 if ( a->a_group_pat.bv_len )
1452 free ( a->a_group_pat.bv_val );
1457 acl_free( AccessControl *a )
1462 if ( a->acl_filter )
1463 filter_free( a->acl_filter );
1464 if ( a->acl_dn_pat.bv_len )
1465 free ( a->acl_dn_pat.bv_val );
1466 if ( a->acl_attrs ) {
1467 for ( an = a->acl_attrs; an->an_name.bv_val; an++ ) {
1468 free( an->an_name.bv_val );
1470 free( a->acl_attrs );
1472 for (; a->acl_access; a->acl_access = n) {
1473 n = a->acl_access->a_next;
1474 access_free( a->acl_access );
1479 /* Because backend_startup uses acl_append to tack on the global_acl to
1480 * the end of each backend's acl, we cannot just take one argument and
1481 * merrily free our way to the end of the list. backend_destroy calls us
1482 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1483 * point. config_destroy calls us with global_acl in arg1 and NULL in
1484 * arg2, so we then proceed to polish off the global_acl.
1487 acl_destroy( AccessControl *a, AccessControl *end )
1491 for (; a && a!= end; a=n) {
1498 access2str( slap_access_t access )
1500 if ( access == ACL_NONE ) {
1503 } else if ( access == ACL_AUTH ) {
1506 } else if ( access == ACL_COMPARE ) {
1509 } else if ( access == ACL_SEARCH ) {
1512 } else if ( access == ACL_READ ) {
1515 } else if ( access == ACL_WRITE ) {
1523 str2access( const char *str )
1525 if ( strcasecmp( str, "none" ) == 0 ) {
1528 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1531 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1534 } else if ( strcasecmp( str, "search" ) == 0 ) {
1537 } else if ( strcasecmp( str, "read" ) == 0 ) {
1540 } else if ( strcasecmp( str, "write" ) == 0 ) {
1544 return( ACL_INVALID_ACCESS );
1549 static char *style_strings[5] = { "regex",
1550 "base", "one", "subtree", "children" };
1553 print_access( Access *b )
1555 char maskbuf[ACCESSMASK_MAXLEN];
1557 fprintf( stderr, "\tby" );
1559 if ( b->a_dn_pat.bv_len != 0 ) {
1560 if( strcmp(b->a_dn_pat.bv_val, "*") == 0
1561 || strcmp(b->a_dn_pat.bv_val, "users") == 0
1562 || strcmp(b->a_dn_pat.bv_val, "anonymous") == 0
1563 || strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1565 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1568 fprintf( stderr, " dn.%s=\"%s\"",
1569 style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1573 if ( b->a_dn_at != NULL ) {
1574 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1577 if ( b->a_group_pat.bv_len ) {
1578 fprintf( stderr, " group/%s/%s.%s=\"%s\"",
1579 b->a_group_oc ? b->a_group_oc->soc_cname.bv_val : "groupOfNames",
1580 b->a_group_at ? b->a_group_at->ad_cname.bv_val : "member",
1581 style_strings[b->a_group_style],
1582 b->a_group_pat.bv_val );
1585 if ( b->a_peername_pat.bv_len != 0 ) {
1586 fprintf( stderr, " peername=\"%s\"", b->a_peername_pat.bv_val );
1589 if ( b->a_sockname_pat.bv_len != 0 ) {
1590 fprintf( stderr, " sockname=\"%s\"", b->a_sockname_pat.bv_val );
1593 if ( b->a_domain_pat.bv_len != 0 ) {
1594 fprintf( stderr, " domain=%s", b->a_domain_pat.bv_val );
1597 if ( b->a_sockurl_pat.bv_len != 0 ) {
1598 fprintf( stderr, " sockurl=\"%s\"", b->a_sockurl_pat.bv_val );
1601 #ifdef SLAPD_ACI_ENABLED
1602 if ( b->a_aci_at != NULL ) {
1603 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1607 /* Security Strength Factors */
1608 if ( b->a_authz.sai_ssf ) {
1609 fprintf( stderr, " ssf=%u",
1610 b->a_authz.sai_ssf );
1612 if ( b->a_authz.sai_transport_ssf ) {
1613 fprintf( stderr, " transport_ssf=%u",
1614 b->a_authz.sai_transport_ssf );
1616 if ( b->a_authz.sai_tls_ssf ) {
1617 fprintf( stderr, " tls_ssf=%u",
1618 b->a_authz.sai_tls_ssf );
1620 if ( b->a_authz.sai_sasl_ssf ) {
1621 fprintf( stderr, " sasl_ssf=%u",
1622 b->a_authz.sai_sasl_ssf );
1625 fprintf( stderr, " %s%s",
1626 b->a_dn_self ? "self" : "",
1627 accessmask2str( b->a_access_mask, maskbuf ) );
1629 if( b->a_type == ACL_BREAK ) {
1630 fprintf( stderr, " break" );
1632 } else if( b->a_type == ACL_CONTINUE ) {
1633 fprintf( stderr, " continue" );
1635 } else if( b->a_type != ACL_STOP ) {
1636 fprintf( stderr, " unknown-control" );
1639 fprintf( stderr, "\n" );
1644 print_acl( Backend *be, AccessControl *a )
1649 fprintf( stderr, "%s ACL: access to",
1650 be == NULL ? "Global" : "Backend" );
1652 if ( a->acl_dn_pat.bv_len != 0 ) {
1654 fprintf( stderr, " dn.%s=\"%s\"\n",
1655 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
1658 if ( a->acl_filter != NULL ) {
1659 struct berval bv = { 0, NULL };
1661 filter2bv( a->acl_filter, &bv );
1662 fprintf( stderr, " filter=%s\n", bv.bv_val );
1663 ch_free( bv.bv_val );
1666 if ( a->acl_attrs != NULL ) {
1671 fprintf( stderr, " attrs=" );
1672 for ( an = a->acl_attrs; an && an->an_name.bv_val; an++ ) {
1674 fprintf( stderr, "," );
1676 fputs( an->an_name.bv_val, stderr );
1679 fprintf( stderr, "\n" );
1682 if ( a->acl_attrval.bv_len != 0 ) {
1684 fprintf( stderr, " val.%s=\"%s\"\n",
1685 style_strings[a->acl_attrval_style], a->acl_attrval.bv_val );
1690 fprintf( stderr, " *\n" );
1693 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1697 fprintf( stderr, "\n" );
1700 #endif /* LDAP_DEBUG */