]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/aclparse.c
When recreating a database from an ldif file created by ldbmcat,
[openldap] / servers / slapd / aclparse.c
index b2588e287d2eaac691180454c09f0eb7046cd4e6..6a291fd2b127bf6cd308c3bb6e8c8704e5627ba6 100644 (file)
 #include "slap.h"
 
 static void            split(char *line, int splitchar, char **left, char **right);
-static void            acl_append(struct acl **l, struct acl *a);
-static void            access_append(struct access **l, struct access *a);
+static void            acl_append(AccessControl **l, AccessControl *a);
+static void            access_append(Access **l, Access *a);
 static void            acl_usage(void);
 #ifdef LDAP_DEBUG
-static void            print_acl(struct acl *a);
-static void            print_access(struct access *b);
+static void            print_acl(AccessControl *a);
+static void            print_access(Access *b);
 #endif
 
 static int
@@ -88,8 +88,8 @@ parse_acl(
 {
        int             i;
        char            *left, *right;
-       struct acl      *a;
-       struct access   *b;
+       AccessControl   *a;
+       Access  *b;
 
        a = NULL;
        for ( i = 1; i < argc; i++ ) {
@@ -101,7 +101,7 @@ parse_acl(
                                    fname, lineno );
                                acl_usage();
                        }
-                       a = (struct acl *) ch_calloc( 1, sizeof(struct acl) );
+                       a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
                        for ( ++i; i < argc; i++ ) {
                                if ( strcasecmp( argv[i], "by" ) == 0 ) {
                                        i--;
@@ -109,18 +109,7 @@ parse_acl(
                                }
 
                                if ( strcasecmp( argv[i], "*" ) == 0 ) {
-                                       int e;
-                                       if ((e = regcomp( &a->acl_dnre, ".*",
-                                               REG_EXTENDED|REG_ICASE)))
-                                       {
-                                               char buf[512];
-                                               regerror(e, &a->acl_dnre, buf, sizeof(buf));
-                                               fprintf( stderr,
-                                                       "%s: line %d: regular expression \"%s\" bad because of %s\n",
-                                                       fname, lineno, right, buf );
-                                               acl_usage();
-                                       }
-                                       a->acl_dnpat = ch_strdup( ".*" );
+                                       a->acl_dn_pat = ch_strdup( ".*" );
                                        continue;
                                }
 
@@ -140,27 +129,30 @@ parse_acl(
                                                    fname, lineno, right );
                                                acl_usage();
                                        }
+
                                } else if ( strcasecmp( left, "dn" ) == 0 ) {
                                        int e;
-                                       if ((e = regcomp(&a->acl_dnre, right,
+
+                                       if ((e = regcomp(&a->acl_dn_re, right,
                                                REG_EXTENDED|REG_ICASE))) {
                                                char buf[512];
-                                               regerror(e, &a->acl_dnre, buf, sizeof(buf));
+                                               regerror(e, &a->acl_dn_re, buf, sizeof(buf));
                                                fprintf( stderr,
                                "%s: line %d: regular expression \"%s\" bad because of %s\n",
                                                        fname, lineno, right, buf );
                                                acl_usage();
 
                                        } else {
-                                               a->acl_dnpat = dn_upcase(ch_strdup( right ));
+                                               a->acl_dn_pat = ch_strdup( right );
                                        }
-                               } else if ( strncasecmp( left, "attr", 4 )
-                                   == 0 ) {
+
+                               } else if ( strncasecmp( left, "attr", 4 ) == 0 ) {
                                        char    **alist;
 
                                        alist = str2charray( right, "," );
                                        charray_merge( &a->acl_attrs, alist );
                                        charray_free( alist );
+
                                } else {
                                        fprintf( stderr,
                                                "%s: line %d: expecting <what> got \"%s\"\n",
@@ -181,7 +173,7 @@ parse_acl(
                         * by clause consists of <who> and <access>
                         */
 
-                       b = (struct access *) ch_calloc( 1, sizeof(struct access) );
+                       b = (Access *) ch_calloc( 1, sizeof(Access) );
 
                        if ( ++i == argc ) {
                                fprintf( stderr,
@@ -191,88 +183,150 @@ parse_acl(
                        }
 
                        /* get <who> */
-                       split( argv[i], '=', &left, &right );
-                       if ( strcasecmp( argv[i], "*" ) == 0 ) {
-                               b->a_dnpat = ch_strdup( ".*" );
-                       } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
-                               b->a_dnpat = ch_strdup( "anonymous" );
-                       } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
-                               b->a_dnpat = ch_strdup( "self" );
-                       } else if ( strcasecmp( left, "dn" ) == 0 ) {
-                               regtest(fname, lineno, right);
-                               b->a_dnpat = dn_upcase( ch_strdup( right ) );
-                       } else if ( strcasecmp( left, "dnattr" ) == 0 ) {
-                               b->a_dnattr = ch_strdup( right );
-
-#ifdef SLAPD_ACLGROUPS
-                       } else if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
-                                char *name = NULL;
-                                char *value = NULL;
-
-                                /* format of string is "group/objectClassValue/groupAttrName"
-                                 */
-                                if ((value = strchr(left, '/')) != NULL) {
-                                        *value++ = '\0';
-                                        if (value && *value && (name = strchr(value, '/')) != NULL) 
-                                            *name++ = '\0';
-                                }
-
-                               regtest(fname, lineno, right);
-                               b->a_group = dn_upcase(ch_strdup( right ));
-
-                                if (value && *value) {
-                                        b->a_group_oc = ch_strdup(value);
-                                        *--value = '/';
-                                }
-                                else
-                                        b->a_group_oc = ch_strdup("groupOfNames");
-
-                                if (name && *name) {
-                                        b->a_group_at = ch_strdup(name);
-                                        *--name = '/';
-                                }
-                                else
-                                        b->a_group_at = ch_strdup("member");
-
-
-
-#endif /* SLAPD_ACLGROUPS */
-                       } else if ( strcasecmp( left, "domain" ) == 0 ) {
-                               char    *s;
-                               regtest(fname, lineno, right);
-                               b->a_domainpat = ch_strdup( right );
-
-                               /* normalize the domain */
-                               for ( s = b->a_domainpat; *s; s++ ) {
-                                       *s = TOLOWER( (unsigned char) *s );
+                       for ( ; i < argc; i++ ) {
+                               char *pat;
+                               split( argv[i], '=', &left, &right );
+
+                               if ( strcasecmp( argv[i], "*" ) == 0 ) {
+                                       pat = ch_strdup( ".*" );
+                               } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
+                                       pat = ch_strdup( "anonymous" );
+                               } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
+                                       pat = ch_strdup( "self" );
+                               } else if ( strcasecmp( left, "dn" ) == 0 ) {
+                                       regtest(fname, lineno, right);
+                                       pat = ch_strdup( right );
+                               } else {
+                                       pat = NULL;
                                }
-                       } else if ( strcasecmp( left, "addr" ) == 0 ) {
-                               regtest(fname, lineno, right);
-                               b->a_addrpat = ch_strdup( right );
-                       } else {
-                               fprintf( stderr,
-                                   "%s: line %d: expecting <who> got \"%s\"\n",
-                                   fname, lineno, left );
-                               acl_usage();
-                       }
 
-                       if ( ++i == argc ) {
-                               fprintf( stderr,
-                           "%s: line %d: premature eol: expecting <access>\n",
-                                   fname, lineno );
-                               acl_usage();
-                       }
+                               if( pat != NULL ) {
+                                       if( b->a_dn_pat != NULL ) {
+                                               fprintf( stderr,
+                                                   "%s: line %d: dn pattern already specified.\n",
+                                                   fname, lineno );
+                                               acl_usage();
+                                       }
 
-                       /* get <access> */
-                       split( argv[i], '=', &left, &right );
-                       if ( ACL_IS_INVALID(ACL_SET(b->a_access,str2access( left ))) ) {
-                               fprintf( stderr,
-                           "%s: line %d: expecting <access> got \"%s\"\n",
-                                   fname, lineno, left );
-                               acl_usage();
-                       }
-                       access_append( &a->acl_access, b );
+                                       b->a_dn_pat = pat;
+                                       continue;
+                               }
+
+                               if ( strcasecmp( left, "dnattr" ) == 0 ) {
+                                       if( b->a_dn_pat != NULL ) {
+                                               fprintf( stderr,
+                                                       "%s: line %d: dnaddr already specified.\n",
+                                                       fname, lineno );
+                                               acl_usage();
+                                       }
+
+                                       b->a_dn_at = ch_strdup( right );
+                                       continue;
+                               }
+
+                               if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
+                                       char *name = NULL;
+                                       char *value = NULL;
+
+                                       if( b->a_group_pat != NULL ) {
+                                               fprintf( stderr,
+                                                       "%s: line %d: group pattern already specified.\n",
+                                                       fname, lineno );
+                                               acl_usage();
+                                       }
+
+                                       /* format of string is "group/objectClassValue/groupAttrName" */
+                                       if ((value = strchr(left, '/')) != NULL) {
+                                               *value++ = '\0';
+                                               if (value && *value
+                                                       && (name = strchr(value, '/')) != NULL)
+                                               {
+                                                       *name++ = '\0';
+                                               }
+                                       }
+
+                                       regtest(fname, lineno, right);
+                                       b->a_group_pat = ch_strdup( right );
+
+                                       if (value && *value) {
+                                               b->a_group_oc = ch_strdup(value);
+                                               *--value = '/';
+                                       } else {
+                                               b->a_group_oc = ch_strdup("groupOfNames");
+
+                                               if (name && *name) {
+                                                       b->a_group_at = ch_strdup(name);
+                                                       *--name = '/';
+
+                                               } else {
+                                                       b->a_group_at = ch_strdup("member");
+                                               }
+                                       }
+                                       continue;
+                               }
+
+                               if ( strcasecmp( left, "peername" ) == 0 ) {
+                                       if( b->a_peername_pat != NULL ) {
+                                               fprintf( stderr,
+                                                       "%s: line %d: peername pattern already specified.\n",
+                                                       fname, lineno );
+                                               acl_usage();
+                                       }
+
+                                       regtest(fname, lineno, right);
+                                       b->a_peername_pat = ch_strdup( right );
+                                       continue;
+                               }
+
+                               if ( strcasecmp( left, "sockname" ) == 0 ) {
+                                       if( b->a_sockname_pat != NULL ) {
+                                               fprintf( stderr,
+                                                       "%s: line %d: sockname pattern already specified.\n",
+                                                       fname, lineno );
+                                               acl_usage();
+                                       }
+
+                                       regtest(fname, lineno, right);
+                                       b->a_sockname_pat = ch_strdup( right );
+                                       continue;
+                               }
+
+                               if ( strcasecmp( left, "domain" ) == 0 ) {
+                                       if( b->a_domain_pat != NULL ) {
+                                               fprintf( stderr,
+                                                       "%s: line %d: domain pattern already specified.\n",
+                                                       fname, lineno );
+                                               acl_usage();
+                                       }
+
+                                       regtest(fname, lineno, right);
+                                       b->a_domain_pat = ch_strdup( right );
+                                       continue;
+                               }
+
+                               if ( strcasecmp( left, "sockurl" ) == 0 ) {
+                                       if( b->a_sockurl_pat != NULL ) {
+                                               fprintf( stderr,
+                                                       "%s: line %d: sockurl pattern already specified.\n",
+                                                       fname, lineno );
+                                               acl_usage();
+                                       }
 
+                                       regtest(fname, lineno, right);
+                                       b->a_sockurl_pat = ch_strdup( right );
+                                       continue;
+                               }
+
+                               /* get <access> */
+                               if ( ACL_IS_INVALID(ACL_SET(b->a_access, str2access( left ))) ) {
+                                       fprintf( stderr,
+                                       "%s: line %d: expecting <access> got \"%s\"\n",
+                                               fname, lineno, left );
+                                       acl_usage();
+                               }
+                               access_append( &a->acl_access, b );
+                               break;
+                       }
                } else {
                        fprintf( stderr,
                    "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
@@ -321,10 +375,8 @@ access2str( int access )
 
        if ( ACL_IS_NONE(access) ) {
                strcat( buf, "none" );
-#ifdef SLAPD_ACLAUTH
        } else if ( ACL_IS_AUTH(access) ) {
                strcat( buf, "auth" );
-#endif
        } else if ( ACL_IS_COMPARE(access) ) {
                strcat( buf, "compare" );
        } else if ( ACL_IS_SEARCH(access) ) {
@@ -333,6 +385,7 @@ access2str( int access )
                strcat( buf, "read" );
        } else if ( ACL_IS_WRITE(access) ) {
                strcat( buf, "write" );
+
        } else {
                strcat( buf, "unknown" );
        }
@@ -354,10 +407,8 @@ str2access( char *str )
 
        if ( strcasecmp( str, "none" ) == 0 ) {
                ACL_SET_NONE(access);
-#ifdef SLAPD_ACLAUTH
        } else if ( strcasecmp( str, "auth" ) == 0 ) {
                ACL_SET_AUTH(access);
-#endif
        } else if ( strcasecmp( str, "compare" ) == 0 ) {
                ACL_SET_COMPARE(access);
        } else if ( strcasecmp( str, "search" ) == 0 ) {
@@ -381,16 +432,12 @@ acl_usage( void )
                "<what> ::= * | [dn=<regex>] [filter=<ldapfilter>] [attrs=<attrlist>]\n"
                "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
                "<attr> ::= <attrname> | entry | children\n"
-               "<who> ::= * | anonymous | self | dn=<regex> | addr=<regex>\n"
-                       "\t| domain=<regex> | dnattr=<dnattrname>\n"
-#ifdef SLAPD_ACLGROUPS
-                       "\t| group[/<objectclass>[/<attrname>]]=<regex>\n"
-#endif
-#ifdef SLAPD_ACLAUTH
+               "<who> ::= [ * | anonymous | self | dn=<regex> ]\n"
+                       "\t[dnattr=<attrname>]\n"
+                       "\t[group[/<objectclass>[/<attrname>]]=<regex>]\n"
+                       "\t[peername=<regex>] [sockname=<regex>]\n"
+                       "\t[domain=<regex>] [sockurl=<regex>]\n"
                "<access> ::= [self]{none|auth|compare|search|read|write}\n"
-#else
-               "<access> ::= [self]{none|auth|compare|search|read|write}\n"
-#endif
                );
        exit( 1 );
 }
@@ -410,7 +457,7 @@ split(
 }
 
 static void
-access_append( struct access **l, struct access *a )
+access_append( Access **l, Access *a )
 {
        for ( ; *l != NULL; l = &(*l)->a_next )
                ;       /* NULL */
@@ -419,7 +466,7 @@ access_append( struct access **l, struct access *a )
 }
 
 static void
-acl_append( struct acl **l, struct acl *a )
+acl_append( AccessControl **l, AccessControl *a )
 {
        for ( ; *l != NULL; l = &(*l)->acl_next )
                ;       /* NULL */
@@ -430,42 +477,61 @@ acl_append( struct acl **l, struct acl *a )
 #ifdef LDAP_DEBUG
 
 static void
-print_access( struct access *b )
+print_access( Access *b )
 {
        fprintf( stderr, "\tby" );
 
-       if ( b->a_dnpat != NULL ) {
-               if( strcmp(b->a_dnpat, "anonymous") == 0 ) {
+       if ( b->a_dn_pat != NULL ) {
+               if( strcmp(b->a_dn_pat, "anonymous") == 0 ) {
                        fprintf( stderr, " anonymous" );
-               } else if( strcmp(b->a_dnpat, "self") == 0 ) {
+
+               } else if( strcmp(b->a_dn_pat, "self") == 0 ) {
                        fprintf( stderr, " self" );
+
                } else {
-                       fprintf( stderr, " dn=%s", b->a_dnpat );
+                       fprintf( stderr, " dn=%s", b->a_dn_pat );
                }
-       } else if ( b->a_addrpat != NULL ) {
-               fprintf( stderr, " addr=%s", b->a_addrpat );
-       } else if ( b->a_domainpat != NULL ) {
-               fprintf( stderr, " domain=%s", b->a_domainpat );
-       } else if ( b->a_dnattr != NULL ) {
-               fprintf( stderr, " dnattr=%s", b->a_dnattr );
        }
-#ifdef SLAPD_ACLGROUPS
-        else if ( b->a_group != NULL ) {
-                fprintf( stderr, " group: %s", b->a_group );
-                if ( b->a_group_oc )
-                        fprintf( stderr, " objectClass: %s", b->a_group_oc );
-                if ( b->a_group_at )
-                        fprintf( stderr, " attributeType: %s", b->a_group_at );
-        }
-#endif
+
+       if ( b->a_dn_at != NULL ) {
+               fprintf( stderr, " dnattr=%s", b->a_dn_at );
+       }
+
+       if ( b->a_group_pat != NULL ) {
+               fprintf( stderr, " group: %s", b->a_group_pat );
+
+               if ( b->a_group_oc ) {
+                       fprintf( stderr, " objectClass: %s", b->a_group_oc );
+
+                       if ( b->a_group_at ) {
+                               fprintf( stderr, " attributeType: %s", b->a_group_at );
+                       }
+               }
+    }
+
+       if ( b->a_peername_pat != NULL ) {
+               fprintf( stderr, " peername=%s", b->a_peername_pat );
+       }
+       if ( b->a_sockname_pat != NULL ) {
+               fprintf( stderr, " sockname=%s", b->a_sockname_pat );
+       }
+
+       if ( b->a_domain_pat != NULL ) {
+               fprintf( stderr, " domain=%s", b->a_domain_pat );
+       }
+
+       if ( b->a_sockurl_pat != NULL ) {
+               fprintf( stderr, " sockurl=%s", b->a_sockurl_pat );
+       }
+
        fprintf( stderr, "\n" );
 }
 
 static void
-print_acl( struct acl *a )
+print_acl( AccessControl *a )
 {
        int             i;
-       struct access   *b;
+       Access  *b;
 
        if ( a == NULL ) {
                fprintf( stderr, "NULL\n" );
@@ -475,9 +541,9 @@ print_acl( struct acl *a )
                fprintf(  stderr," filter=" );
                filter_print( a->acl_filter );
        }
-       if ( a->acl_dnpat != NULL ) {
+       if ( a->acl_dn_pat != NULL ) {
                fprintf( stderr, " dn=" );
-               fprintf( stderr, a->acl_dnpat );
+               fprintf( stderr, a->acl_dn_pat );
        }
        if ( a->acl_attrs != NULL ) {
                int     first = 1;