]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/aclparse.c
ITS#2884 silence warning. We don't dereference this pointer, we just use
[openldap] / servers / slapd / aclparse.c
index 6ea473f434b3d2c24a72b11e7c5fd9e6903aacd4..67081a149ff3d122280cea8f8029020f678803d6 100644 (file)
@@ -1,8 +1,27 @@
 /* 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"
@@ -19,6 +38,9 @@
 #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));
@@ -169,8 +191,14 @@ parse_acl(
                                        } 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;
@@ -227,6 +255,66 @@ parse_acl(
                                                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",
@@ -614,7 +702,8 @@ parse_acl(
                                        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",
@@ -1288,16 +1377,16 @@ str2accessmask( const char *str )
 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"
@@ -1509,9 +1598,6 @@ str2access( const char *str )
 
 #ifdef LDAP_DEBUG
 
-static char *style_strings[5] = { "regex",
-       "base", "one", "subtree", "children" };
-
 static void
 print_access( Access *b )
 {
@@ -1528,7 +1614,7 @@ 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 );
                }
        }
@@ -1538,25 +1624,19 @@ print_access( Access *b )
        }
 
        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 ) {
@@ -1564,7 +1644,7 @@ print_access( Access *b )
        }
 
        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
@@ -1620,7 +1700,7 @@ print_acl( Backend *be, AccessControl *a )
 
        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 );
        }
 
@@ -1642,12 +1722,22 @@ print_acl( Backend *be, AccessControl *a )
                        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" );
        }