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 ) )
656 "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
657 fname, lineno, right,
658 b->a_group_at->ad_type->sat_syntax_oid );
665 struct berval vals[2];
667 vals[0].bv_val = b->a_group_oc->soc_oid;
668 vals[0].bv_len = strlen(vals[0].bv_val);
669 vals[1].bv_val = NULL;
672 rc = oc_check_allowed( b->a_group_at->ad_type,
676 fprintf( stderr, "%s: line %d: "
677 "group: \"%s\" not allowed by \"%s\"\n",
679 b->a_group_at->ad_cname.bv_val,
680 b->a_group_oc->soc_oid );
687 if ( strcasecmp( left, "peername" ) == 0 ) {
688 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
689 fprintf( stderr, "%s: line %d: "
690 "inappropriate style \"%s\" in by clause\n",
691 fname, lineno, style );
695 if ( right == NULL || right[ 0 ] == '\0' ) {
696 fprintf( stderr, "%s: line %d: "
697 "missing \"=\" in (or value after) \"%s\" "
699 fname, lineno, left );
703 if( b->a_peername_pat.bv_len ) {
704 fprintf( stderr, "%s: line %d: "
705 "peername pattern already specified.\n",
710 b->a_peername_style = sty;
711 if (sty == ACL_STYLE_REGEX) {
712 acl_regex_normalized_dn( right, &bv );
713 if ( !ber_bvccmp( &bv, '*' ) ) {
714 regtest(fname, lineno, bv.bv_val);
716 b->a_peername_pat = bv;
718 ber_str2bv( right, 0, 1, &b->a_peername_pat );
723 if ( strcasecmp( left, "sockname" ) == 0 ) {
724 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
725 fprintf( stderr, "%s: line %d: "
726 "inappropriate style \"%s\" in by clause\n",
727 fname, lineno, style );
731 if ( right == NULL || right[ 0 ] == '\0' ) {
732 fprintf( stderr, "%s: line %d: "
733 "missing \"=\" in (or value after) \"%s\" "
735 fname, lineno, left );
739 if( b->a_sockname_pat.bv_len ) {
740 fprintf( stderr, "%s: line %d: "
741 "sockname pattern already specified.\n",
746 b->a_sockname_style = sty;
747 if (sty == ACL_STYLE_REGEX) {
748 acl_regex_normalized_dn( right, &bv );
749 if ( !ber_bvccmp( &bv, '*' ) ) {
750 regtest(fname, lineno, bv.bv_val);
752 b->a_sockname_pat = bv;
754 ber_str2bv( right, 0, 1, &b->a_sockname_pat );
759 if ( strcasecmp( left, "domain" ) == 0 ) {
761 case ACL_STYLE_REGEX:
763 case ACL_STYLE_SUBTREE:
768 "%s: line %d: inappropriate style \"%s\" in by clause\n",
769 fname, lineno, style );
773 if ( right == NULL || right[ 0 ] == '\0' ) {
775 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
776 fname, lineno, left );
780 if( b->a_domain_pat.bv_len ) {
782 "%s: line %d: domain pattern already specified.\n",
787 b->a_domain_style = sty;
788 b->a_domain_expand = expand;
789 if (sty == ACL_STYLE_REGEX) {
790 acl_regex_normalized_dn( right, &bv );
791 if ( !ber_bvccmp( &bv, '*' ) ) {
792 regtest(fname, lineno, bv.bv_val);
794 b->a_domain_pat = bv;
796 ber_str2bv( right, 0, 1, &b->a_domain_pat );
801 if ( strcasecmp( left, "sockurl" ) == 0 ) {
802 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
804 "%s: line %d: inappropriate style \"%s\" in by clause\n",
805 fname, lineno, style );
809 if ( right == NULL || right[ 0 ] == '\0' ) {
811 "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
812 fname, lineno, left );
816 if( b->a_sockurl_pat.bv_len ) {
818 "%s: line %d: sockurl pattern already specified.\n",
823 b->a_sockurl_style = sty;
824 if (sty == ACL_STYLE_REGEX) {
825 acl_regex_normalized_dn( right, &bv );
826 if ( !ber_bvccmp( &bv, '*' ) ) {
827 regtest(fname, lineno, bv.bv_val);
829 b->a_sockurl_pat = bv;
831 ber_str2bv( right, 0, 1, &b->a_sockurl_pat );
836 if ( strcasecmp( left, "set" ) == 0 ) {
837 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
839 "%s: line %d: inappropriate style \"%s\" in by clause\n",
840 fname, lineno, style );
844 if( b->a_set_pat.bv_len != 0 ) {
846 "%s: line %d: set attribute already specified.\n",
851 if ( right == NULL || *right == '\0' ) {
853 "%s: line %d: no set is defined\n",
858 b->a_set_style = sty;
859 ber_str2bv( right, 0, 1, &b->a_set_pat );
864 #ifdef SLAPD_ACI_ENABLED
865 if ( strcasecmp( left, "aci" ) == 0 ) {
866 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
868 "%s: line %d: inappropriate style \"%s\" in by clause\n",
869 fname, lineno, style );
873 if( b->a_aci_at != NULL ) {
875 "%s: line %d: aci attribute already specified.\n",
880 if ( right != NULL && *right != '\0' ) {
881 rc = slap_str2ad( right, &b->a_aci_at, &text );
883 if( rc != LDAP_SUCCESS ) {
885 "%s: line %d: aci \"%s\": %s\n",
886 fname, lineno, right, text );
891 b->a_aci_at = slap_schema.si_ad_aci;
894 if( !is_at_syntax( b->a_aci_at->ad_type,
898 "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
899 fname, lineno, right,
900 b->a_aci_at->ad_type->sat_syntax_oid );
906 #endif /* SLAPD_ACI_ENABLED */
908 if ( strcasecmp( left, "ssf" ) == 0 ) {
909 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
911 "%s: line %d: inappropriate style \"%s\" in by clause\n",
912 fname, lineno, style );
916 if( b->a_authz.sai_ssf ) {
918 "%s: line %d: ssf attribute already specified.\n",
923 if ( right == NULL || *right == '\0' ) {
925 "%s: line %d: no ssf is defined\n",
930 b->a_authz.sai_ssf = atoi( right );
932 if( !b->a_authz.sai_ssf ) {
934 "%s: line %d: invalid ssf value (%s)\n",
935 fname, lineno, right );
941 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
942 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
944 "%s: line %d: inappropriate style \"%s\" in by clause\n",
945 fname, lineno, style );
949 if( b->a_authz.sai_transport_ssf ) {
951 "%s: line %d: transport_ssf attribute already specified.\n",
956 if ( right == NULL || *right == '\0' ) {
958 "%s: line %d: no transport_ssf is defined\n",
963 b->a_authz.sai_transport_ssf = atoi( right );
965 if( !b->a_authz.sai_transport_ssf ) {
967 "%s: line %d: invalid transport_ssf value (%s)\n",
968 fname, lineno, right );
974 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
975 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
977 "%s: line %d: inappropriate style \"%s\" in by clause\n",
978 fname, lineno, style );
982 if( b->a_authz.sai_tls_ssf ) {
984 "%s: line %d: tls_ssf attribute already specified.\n",
989 if ( right == NULL || *right == '\0' ) {
991 "%s: line %d: no tls_ssf is defined\n",
996 b->a_authz.sai_tls_ssf = atoi( right );
998 if( !b->a_authz.sai_tls_ssf ) {
1000 "%s: line %d: invalid tls_ssf value (%s)\n",
1001 fname, lineno, right );
1007 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
1008 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
1010 "%s: line %d: inappropriate style \"%s\" in by clause\n",
1011 fname, lineno, style );
1015 if( b->a_authz.sai_sasl_ssf ) {
1017 "%s: line %d: sasl_ssf attribute already specified.\n",
1022 if ( right == NULL || *right == '\0' ) {
1024 "%s: line %d: no sasl_ssf is defined\n",
1029 b->a_authz.sai_sasl_ssf = atoi( right );
1031 if( !b->a_authz.sai_sasl_ssf ) {
1033 "%s: line %d: invalid sasl_ssf value (%s)\n",
1034 fname, lineno, right );
1040 if( right != NULL ) {
1047 if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) {
1048 /* out of arguments or plain stop */
1050 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1051 b->a_type = ACL_STOP;
1053 access_append( &a->acl_access, b );
1057 if( strcasecmp( left, "continue" ) == 0 ) {
1058 /* plain continue */
1060 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1061 b->a_type = ACL_CONTINUE;
1063 access_append( &a->acl_access, b );
1067 if( strcasecmp( left, "break" ) == 0 ) {
1068 /* plain continue */
1070 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1071 b->a_type = ACL_BREAK;
1073 access_append( &a->acl_access, b );
1077 if ( strcasecmp( left, "by" ) == 0 ) {
1078 /* we've gone too far */
1080 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
1081 b->a_type = ACL_STOP;
1083 access_append( &a->acl_access, b );
1088 if( strncasecmp( left, "self", 4 ) == 0 ) {
1090 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
1093 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
1096 if( ACL_IS_INVALID( b->a_access_mask ) ) {
1098 "%s: line %d: expecting <access> got \"%s\"\n",
1099 fname, lineno, left );
1103 b->a_type = ACL_STOP;
1106 /* out of arguments or plain stop */
1107 access_append( &a->acl_access, b );
1111 if( strcasecmp( argv[i], "continue" ) == 0 ) {
1112 /* plain continue */
1113 b->a_type = ACL_CONTINUE;
1115 } else if( strcasecmp( argv[i], "break" ) == 0 ) {
1116 /* plain continue */
1117 b->a_type = ACL_BREAK;
1119 } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
1124 access_append( &a->acl_access, b );
1128 "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
1129 fname, lineno, argv[i] );
1134 /* if we have no real access clause, complain and do nothing */
1137 "%s: line %d: warning: no access clause(s) specified in access line\n",
1142 if (ldap_debug & LDAP_DEBUG_ACL)
1146 if ( a->acl_access == NULL ) {
1148 "%s: line %d: warning: no by clause(s) specified in access line\n",
1153 acl_append( &be->be_acl, a );
1155 acl_append( &global_acl, a );
1161 accessmask2str( slap_mask_t mask, char *buf )
1166 assert( buf != NULL );
1168 if ( ACL_IS_INVALID( mask ) ) {
1174 if ( ACL_IS_LEVEL( mask ) ) {
1175 if ( ACL_LVL_IS_NONE(mask) ) {
1176 ptr = lutil_strcopy( ptr, "none" );
1178 } else if ( ACL_LVL_IS_AUTH(mask) ) {
1179 ptr = lutil_strcopy( ptr, "auth" );
1181 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
1182 ptr = lutil_strcopy( ptr, "compare" );
1184 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
1185 ptr = lutil_strcopy( ptr, "search" );
1187 } else if ( ACL_LVL_IS_READ(mask) ) {
1188 ptr = lutil_strcopy( ptr, "read" );
1190 } else if ( ACL_LVL_IS_WRITE(mask) ) {
1191 ptr = lutil_strcopy( ptr, "write" );
1193 ptr = lutil_strcopy( ptr, "unknown" );
1199 if( ACL_IS_ADDITIVE( mask ) ) {
1202 } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1209 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1214 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1219 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1224 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1229 if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1234 if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1243 if ( ACL_IS_LEVEL( mask ) ) {
1253 str2accessmask( const char *str )
1257 if( !ASCII_ALPHA(str[0]) ) {
1260 if ( str[0] == '=' ) {
1263 } else if( str[0] == '+' ) {
1264 ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1266 } else if( str[0] == '-' ) {
1267 ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1270 ACL_INVALIDATE(mask);
1274 for( i=1; str[i] != '\0'; i++ ) {
1275 if( TOLOWER((unsigned char) str[i]) == 'w' ) {
1276 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1278 } else if( TOLOWER((unsigned char) str[i]) == 'r' ) {
1279 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1281 } else if( TOLOWER((unsigned char) str[i]) == 's' ) {
1282 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1284 } else if( TOLOWER((unsigned char) str[i]) == 'c' ) {
1285 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1287 } else if( TOLOWER((unsigned char) str[i]) == 'x' ) {
1288 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1290 } else if( str[i] != '0' ) {
1291 ACL_INVALIDATE(mask);
1299 if ( strcasecmp( str, "none" ) == 0 ) {
1300 ACL_LVL_ASSIGN_NONE(mask);
1302 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1303 ACL_LVL_ASSIGN_AUTH(mask);
1305 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1306 ACL_LVL_ASSIGN_COMPARE(mask);
1308 } else if ( strcasecmp( str, "search" ) == 0 ) {
1309 ACL_LVL_ASSIGN_SEARCH(mask);
1311 } else if ( strcasecmp( str, "read" ) == 0 ) {
1312 ACL_LVL_ASSIGN_READ(mask);
1314 } else if ( strcasecmp( str, "write" ) == 0 ) {
1315 ACL_LVL_ASSIGN_WRITE(mask);
1318 ACL_INVALIDATE( mask );
1327 fprintf( stderr, "%s%s\n",
1328 "<access clause> ::= access to <what> "
1329 "[ by <who> <access> [ <control> ] ]+ \n"
1330 "<what> ::= * | [dn[.<dnstyle>]=<DN>] [filter=<filter>] [attrs=<attrlist>]\n"
1331 "<attrlist> ::= <attr> [val[.<style>]=<value>] | <attr> , <attrlist>\n"
1332 "<attr> ::= <attrname> | entry | children\n"
1333 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
1334 "\t[dnattr=<attrname>]\n"
1335 "\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
1336 "\t[peername[.<style>]=<peer>] [sockname[.<style>]=<name>]\n",
1337 "\t[domain[.<style>]=<domain>] [sockurl[.<style>]=<url>]\n"
1338 #ifdef SLAPD_ACI_ENABLED
1339 "\t[aci=<attrname>]\n"
1341 "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1342 "<dnstyle> ::= base | exact | one | subtree | children | regex\n"
1343 "<style> ::= regex | base | exact\n"
1344 "<access> ::= [self]{<level>|<priv>}\n"
1345 "<level> ::= none | auth | compare | search | read | write\n"
1346 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
1347 "<control> ::= [ stop | continue | break ]\n"
1349 exit( EXIT_FAILURE );
1353 * Set pattern to a "normalized" DN from src.
1354 * At present it simply eats the (optional) space after
1355 * a RDN separator (,)
1356 * Eventually will evolve in a more complete normalization
1359 acl_regex_normalized_dn(
1361 struct berval *pattern
1367 str = ch_strdup( src );
1368 len = strlen( src );
1370 for ( p = str; p && p[ 0 ]; p++ ) {
1372 if ( p[ 0 ] == '\\' && p[ 1 ] ) {
1374 * if escaping a hex pair we should
1375 * increment p twice; however, in that
1376 * case the second hex number does
1382 if ( p[ 0 ] == ',' ) {
1383 if ( p[ 1 ] == ' ' ) {
1387 * too much space should be
1388 * an error if we are pedantic
1390 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1393 AC_MEMCPY( p+1, q, len-(q-str)+1);
1397 pattern->bv_val = str;
1398 pattern->bv_len = p-str;
1412 if ( (*right = strchr( line, splitchar )) != NULL ) {
1413 *((*right)++) = '\0';
1418 access_append( Access **l, Access *a )
1420 for ( ; *l != NULL; l = &(*l)->a_next )
1427 acl_append( AccessControl **l, AccessControl *a )
1429 for ( ; *l != NULL; l = &(*l)->acl_next )
1436 access_free( Access *a )
1438 if ( a->a_dn_pat.bv_val )
1439 free ( a->a_dn_pat.bv_val );
1440 if ( a->a_peername_pat.bv_val )
1441 free ( a->a_peername_pat.bv_val );
1442 if ( a->a_sockname_pat.bv_val )
1443 free ( a->a_sockname_pat.bv_val );
1444 if ( a->a_domain_pat.bv_val )
1445 free ( a->a_domain_pat.bv_val );
1446 if ( a->a_sockurl_pat.bv_val )
1447 free ( a->a_sockurl_pat.bv_val );
1448 if ( a->a_set_pat.bv_len )
1449 free ( a->a_set_pat.bv_val );
1450 if ( a->a_group_pat.bv_len )
1451 free ( a->a_group_pat.bv_val );
1456 acl_free( AccessControl *a )
1461 if ( a->acl_filter )
1462 filter_free( a->acl_filter );
1463 if ( a->acl_dn_pat.bv_len )
1464 free ( a->acl_dn_pat.bv_val );
1465 if ( a->acl_attrs ) {
1466 for ( an = a->acl_attrs; an->an_name.bv_val; an++ ) {
1467 free( an->an_name.bv_val );
1469 free( a->acl_attrs );
1471 for (; a->acl_access; a->acl_access = n) {
1472 n = a->acl_access->a_next;
1473 access_free( a->acl_access );
1478 /* Because backend_startup uses acl_append to tack on the global_acl to
1479 * the end of each backend's acl, we cannot just take one argument and
1480 * merrily free our way to the end of the list. backend_destroy calls us
1481 * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1482 * point. config_destroy calls us with global_acl in arg1 and NULL in
1483 * arg2, so we then proceed to polish off the global_acl.
1486 acl_destroy( AccessControl *a, AccessControl *end )
1490 for (; a && a!= end; a=n) {
1497 access2str( slap_access_t access )
1499 if ( access == ACL_NONE ) {
1502 } else if ( access == ACL_AUTH ) {
1505 } else if ( access == ACL_COMPARE ) {
1508 } else if ( access == ACL_SEARCH ) {
1511 } else if ( access == ACL_READ ) {
1514 } else if ( access == ACL_WRITE ) {
1522 str2access( const char *str )
1524 if ( strcasecmp( str, "none" ) == 0 ) {
1527 } else if ( strcasecmp( str, "auth" ) == 0 ) {
1530 } else if ( strcasecmp( str, "compare" ) == 0 ) {
1533 } else if ( strcasecmp( str, "search" ) == 0 ) {
1536 } else if ( strcasecmp( str, "read" ) == 0 ) {
1539 } else if ( strcasecmp( str, "write" ) == 0 ) {
1543 return( ACL_INVALID_ACCESS );
1548 static char *style_strings[5] = { "regex",
1549 "base", "one", "subtree", "children" };
1552 print_access( Access *b )
1554 char maskbuf[ACCESSMASK_MAXLEN];
1556 fprintf( stderr, "\tby" );
1558 if ( b->a_dn_pat.bv_len != 0 ) {
1559 if( strcmp(b->a_dn_pat.bv_val, "*") == 0
1560 || strcmp(b->a_dn_pat.bv_val, "users") == 0
1561 || strcmp(b->a_dn_pat.bv_val, "anonymous") == 0
1562 || strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1564 fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1567 fprintf( stderr, " dn.%s=%s",
1568 style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1572 if ( b->a_dn_at != NULL ) {
1573 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1576 if ( b->a_group_pat.bv_len ) {
1577 fprintf( stderr, " group=%s", b->a_group_pat.bv_val );
1579 if ( b->a_group_oc ) {
1580 fprintf( stderr, " objectClass: %s",
1581 b->a_group_oc->soc_oclass.oc_oid );
1583 if ( b->a_group_at ) {
1584 fprintf( stderr, " attributeType: %s",
1585 b->a_group_at->ad_cname.bv_val );
1590 if ( b->a_peername_pat.bv_len != 0 ) {
1591 fprintf( stderr, " peername=%s", b->a_peername_pat.bv_val );
1594 if ( b->a_sockname_pat.bv_len != 0 ) {
1595 fprintf( stderr, " sockname=%s", b->a_sockname_pat.bv_val );
1598 if ( b->a_domain_pat.bv_len != 0 ) {
1599 fprintf( stderr, " domain=%s", b->a_domain_pat.bv_val );
1602 if ( b->a_sockurl_pat.bv_len != 0 ) {
1603 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat.bv_val );
1606 #ifdef SLAPD_ACI_ENABLED
1607 if ( b->a_aci_at != NULL ) {
1608 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1612 /* Security Strength Factors */
1613 if ( b->a_authz.sai_ssf ) {
1614 fprintf( stderr, " ssf=%u",
1615 b->a_authz.sai_ssf );
1617 if ( b->a_authz.sai_transport_ssf ) {
1618 fprintf( stderr, " transport_ssf=%u",
1619 b->a_authz.sai_transport_ssf );
1621 if ( b->a_authz.sai_tls_ssf ) {
1622 fprintf( stderr, " tls_ssf=%u",
1623 b->a_authz.sai_tls_ssf );
1625 if ( b->a_authz.sai_sasl_ssf ) {
1626 fprintf( stderr, " sasl_ssf=%u",
1627 b->a_authz.sai_sasl_ssf );
1630 fprintf( stderr, " %s%s",
1631 b->a_dn_self ? "self" : "",
1632 accessmask2str( b->a_access_mask, maskbuf ) );
1634 if( b->a_type == ACL_BREAK ) {
1635 fprintf( stderr, " break" );
1637 } else if( b->a_type == ACL_CONTINUE ) {
1638 fprintf( stderr, " continue" );
1640 } else if( b->a_type != ACL_STOP ) {
1641 fprintf( stderr, " unknown-control" );
1644 fprintf( stderr, "\n" );
1649 print_acl( Backend *be, AccessControl *a )
1654 fprintf( stderr, "%s ACL: access to",
1655 be == NULL ? "Global" : "Backend" );
1657 if ( a->acl_dn_pat.bv_len != 0 ) {
1659 fprintf( stderr, " dn.%s=%s\n",
1660 style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
1663 if ( a->acl_filter != NULL ) {
1664 struct berval bv = { 0, NULL };
1666 filter2bv( a->acl_filter, &bv );
1667 fprintf( stderr, " filter=%s\n", bv.bv_val );
1668 ch_free( bv.bv_val );
1671 if ( a->acl_attrs != NULL ) {
1676 fprintf( stderr, " attrs=" );
1677 for ( an = a->acl_attrs; an && an->an_name.bv_val; an++ ) {
1679 fprintf( stderr, "," );
1681 fputs( an->an_name.bv_val, stderr );
1684 fprintf( stderr, "\n" );
1687 if ( a->acl_attrval.bv_len != 0 ) {
1689 fprintf( stderr, " val.%s=%s\n",
1690 style_strings[a->acl_attrval_style], a->acl_attrval.bv_val );
1695 fprintf( stderr, " *\n" );
1698 for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1702 fprintf( stderr, "\n" );
1705 #endif /* LDAP_DEBUG */