/* aclparse.c - routines to parse and check acl's */
/* $OpenLDAP$ */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2003 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* Portions Copyright (c) 1995 Regents of the University of Michigan.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to the University of Michigan at Ann Arbor. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission. This software
+ * is provided ``as is'' without express or implied warranty.
*/
#include "portable.h"
#include "lber_pvt.h"
#include "lutil.h"
+static char *style_strings[] = { "regex",
+ "base", "one", "subtree", "children", NULL };
+
static void split(char *line, int splitchar, char **left, char **right);
static void access_append(Access **l, Access *a);
static void acl_usage(void) LDAP_GCCATTR((noreturn));
} else if ( strcasecmp( style, "subtree" ) == 0
|| strcasecmp( style, "sub" ) == 0 )
{
- a->acl_dn_style = ACL_STYLE_SUBTREE;
- ber_str2bv( right, 0, 1, &a->acl_dn_pat );
+ if( *right == '\0' ) {
+ a->acl_dn_pat.bv_val = ch_strdup( "*" );
+ a->acl_dn_pat.bv_len = 1;
+
+ } else {
+ a->acl_dn_style = ACL_STYLE_SUBTREE;
+ ber_str2bv( right, 0, 1, &a->acl_dn_pat );
+ }
} else if ( strcasecmp( style, "children" ) == 0 ) {
a->acl_dn_style = ACL_STYLE_CHILDREN;
acl_usage();
}
+ } else if ( strncasecmp( left, "val", 3 ) == 0 ) {
+ if ( a->acl_attrval.bv_len ) {
+ fprintf( stderr,
+ "%s: line %d: attr val already specified in to clause.\n",
+ fname, lineno );
+ acl_usage();
+ }
+ if ( a->acl_attrs == NULL || a->acl_attrs[1].an_name.bv_val ) {
+ fprintf( stderr,
+ "%s: line %d: attr val requires a single attribute.\n",
+ fname, lineno );
+ acl_usage();
+ }
+ ber_str2bv( right, 0, 1, &a->acl_attrval );
+ if ( style && strcasecmp( style, "regex" ) == 0 ) {
+ int e = regcomp( &a->acl_attrval_re, a->acl_attrval.bv_val,
+ REG_EXTENDED | REG_ICASE | REG_NOSUB );
+ if ( e ) {
+ char buf[512];
+ regerror( e, &a->acl_attrval_re, buf, sizeof(buf) );
+ fprintf( stderr, "%s: line %d: "
+ "regular expression \"%s\" bad because of %s\n",
+ fname, lineno, right, buf );
+ acl_usage();
+ }
+ a->acl_attrval_style = ACL_STYLE_REGEX;
+ } else {
+ /* FIXME: if the attribute has DN syntax,
+ * we might allow one, subtree and children styles as well */
+ if ( !strcasecmp( style, "exact" ) ) {
+ a->acl_attrval_style = ACL_STYLE_BASE;
+
+ } else if ( a->acl_attrs[0].an_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) {
+ if ( !strcasecmp( style, "base" ) ) {
+ a->acl_attrval_style = ACL_STYLE_BASE;
+ } else if ( !strcasecmp( style, "onelevel" ) || !strcasecmp( style, "one" ) ) {
+ a->acl_attrval_style = ACL_STYLE_ONE;
+ } else if ( !strcasecmp( style, "subtree" ) || !strcasecmp( style, "sub" ) ) {
+ a->acl_attrval_style = ACL_STYLE_SUBTREE;
+ } else if ( !strcasecmp( style, "children" ) ) {
+ a->acl_attrval_style = ACL_STYLE_CHILDREN;
+ } else {
+ fprintf( stderr,
+ "%s: line %d: unknown val.<style> \"%s\" "
+ "for attributeType \"%s\" with DN syntax; using \"base\"\n",
+ fname, lineno, style,
+ a->acl_attrs[0].an_desc->ad_cname.bv_val );
+ a->acl_attrval_style = ACL_STYLE_BASE;
+ }
+
+ } else {
+ fprintf( stderr,
+ "%s: line %d: unknown val.<style> \"%s\" "
+ "for attributeType \"%s\"; using \"exact\"\n",
+ fname, lineno, style,
+ a->acl_attrs[0].an_desc->ad_cname.bv_val );
+ a->acl_attrval_style = ACL_STYLE_BASE;
+ }
+ }
+
} else {
fprintf( stderr,
"%s: line %d: expecting <what> got \"%s\"\n",
if( !is_at_syntax( b->a_group_at->ad_type,
SLAPD_DN_SYNTAX ) &&
!is_at_syntax( b->a_group_at->ad_type,
- SLAPD_NAMEUID_SYNTAX ) )
+ SLAPD_NAMEUID_SYNTAX ) &&
+ !is_at_subtype( b->a_group_at->ad_type, slap_schema.si_ad_labeledURI->ad_type ))
{
fprintf( stderr,
"%s: line %d: group \"%s\": inappropriate syntax: %s\n",
static void
acl_usage( void )
{
- fprintf( stderr, "\n"
+ fprintf( stderr, "%s%s\n",
"<access clause> ::= access to <what> "
"[ by <who> <access> [ <control> ] ]+ \n"
"<what> ::= * | [dn[.<dnstyle>]=<DN>] [filter=<filter>] [attrs=<attrlist>]\n"
- "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
+ "<attrlist> ::= <attr> [val[.<style>]=<value>] | <attr> , <attrlist>\n"
"<attr> ::= <attrname> | entry | children\n"
"<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<DN> ]\n"
"\t[dnattr=<attrname>]\n"
"\t[group[/<objectclass>[/<attrname>]][.<style>]=<group>]\n"
- "\t[peername[.<style>]=<peer>] [sockname[.<style>]=<name>]\n"
+ "\t[peername[.<style>]=<peer>] [sockname[.<style>]=<name>]\n",
"\t[domain[.<style>]=<domain>] [sockurl[.<style>]=<url>]\n"
#ifdef SLAPD_ACI_ENABLED
"\t[aci=<attrname>]\n"
#ifdef LDAP_DEBUG
-static char *style_strings[5] = { "regex",
- "base", "one", "subtree", "children" };
-
static void
print_access( Access *b )
{
fprintf( stderr, " %s", b->a_dn_pat.bv_val );
} else {
- fprintf( stderr, " dn.%s=%s",
+ fprintf( stderr, " dn.%s=\"%s\"",
style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
}
}
}
if ( b->a_group_pat.bv_len ) {
- fprintf( stderr, " group=%s", b->a_group_pat.bv_val );
-
- if ( b->a_group_oc ) {
- fprintf( stderr, " objectClass: %s",
- b->a_group_oc->soc_oclass.oc_oid );
-
- if ( b->a_group_at ) {
- fprintf( stderr, " attributeType: %s",
- b->a_group_at->ad_cname.bv_val );
- }
- }
+ fprintf( stderr, " group/%s/%s.%s=\"%s\"",
+ b->a_group_oc ? b->a_group_oc->soc_cname.bv_val : "groupOfNames",
+ b->a_group_at ? b->a_group_at->ad_cname.bv_val : "member",
+ style_strings[b->a_group_style],
+ b->a_group_pat.bv_val );
}
if ( b->a_peername_pat.bv_len != 0 ) {
- fprintf( stderr, " peername=%s", b->a_peername_pat.bv_val );
+ fprintf( stderr, " peername=\"%s\"", b->a_peername_pat.bv_val );
}
if ( b->a_sockname_pat.bv_len != 0 ) {
- fprintf( stderr, " sockname=%s", b->a_sockname_pat.bv_val );
+ fprintf( stderr, " sockname=\"%s\"", b->a_sockname_pat.bv_val );
}
if ( b->a_domain_pat.bv_len != 0 ) {
}
if ( b->a_sockurl_pat.bv_len != 0 ) {
- fprintf( stderr, " sockurl=%s", b->a_sockurl_pat.bv_val );
+ fprintf( stderr, " sockurl=\"%s\"", b->a_sockurl_pat.bv_val );
}
#ifdef SLAPD_ACI_ENABLED
if ( a->acl_dn_pat.bv_len != 0 ) {
to++;
- fprintf( stderr, " dn.%s=%s\n",
+ fprintf( stderr, " dn.%s=\"%s\"\n",
style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
}
if ( ! first ) {
fprintf( stderr, "," );
}
+ if (an->an_oc) {
+ fputc( an->an_oc_exclude ? '!' : '@', stderr);
+ }
fputs( an->an_name.bv_val, stderr );
first = 0;
}
fprintf( stderr, "\n" );
}
+ if ( a->acl_attrval.bv_len != 0 ) {
+ to++;
+ fprintf( stderr, " val.%s=\"%s\"\n",
+ style_strings[a->acl_attrval_style], a->acl_attrval.bv_val );
+
+ }
+
if( !to ) {
fprintf( stderr, " *\n" );
}