X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Faclparse.c;h=051e4a6fb4ace6f12a3614915d89552ae188d208;hb=298d439d596b198a3e96e4885dc80a9aba5e64be;hp=bca6db91c2db94ede075ce1c2f829d9b68af1446;hpb=3356017b936e0947cfc5dbd7a108ecd9c1c145a1;p=openldap diff --git a/servers/slapd/aclparse.c b/servers/slapd/aclparse.c index bca6db91c2..051e4a6fb4 100644 --- a/servers/slapd/aclparse.c +++ b/servers/slapd/aclparse.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2005 The OpenLDAP Foundation. + * Copyright 1998-2006 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -52,13 +52,15 @@ char *style_strings[] = { "users", "self", "ip", + "ipv6", "path", 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)); +static void access_free( Access *a ); +static int acl_usage(void); static void acl_regex_normalized_dn(const char *src, struct berval *pat); @@ -70,17 +72,24 @@ static int check_scope( BackendDB *be, AccessControl *a ); #ifdef SLAP_DYNACL static int -slap_dynacl_config( const char *fname, int lineno, Access *b, const char *name, slap_style_t sty, const char *right ) +slap_dynacl_config( + const char *fname, + int lineno, + Access *b, + const char *name, + const char *opts, + slap_style_t sty, + const char *right ) { slap_dynacl_t *da, *tmp; int rc = 0; for ( da = b->a_dynacl; da; da = da->da_next ) { if ( strcasecmp( da->da_name, name ) == 0 ) { - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "%s: line %d: dynacl \"%s\" already specified.\n", fname, lineno, name ); - acl_usage(); + return acl_usage(); } } @@ -93,7 +102,7 @@ slap_dynacl_config( const char *fname, int lineno, Access *b, const char *name, *tmp = *da; if ( tmp->da_parse ) { - rc = ( *tmp->da_parse )( fname, lineno, sty, right, &tmp->da_private ); + rc = ( *tmp->da_parse )( fname, lineno, opts, sty, right, &tmp->da_private ); if ( rc ) { ch_free( tmp ); return rc; @@ -112,8 +121,8 @@ regtest(const char *fname, int lineno, char *pat) { int e; regex_t re; - char buf[512]; - unsigned size; + char buf[ SLAP_TEXT_BUFLEN ]; + unsigned size; char *sp; char *dp; @@ -144,19 +153,26 @@ regtest(const char *fname, int lineno, char *pat) { *dp = '\0'; if ( size >= (sizeof(buf) - 1) ) { - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "%s: line %d: regular expression \"%s\" too large\n", fname, lineno, pat ); - acl_usage(); + (void)acl_usage(); + exit( EXIT_FAILURE ); } if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) { - char error[512]; + char error[ SLAP_TEXT_BUFLEN ]; + regerror(e, &re, error, sizeof(error)); - fprintf( stderr, - "%s: line %d: regular expression \"%s\" bad because of %s\n", - fname, lineno, pat, error ); + + snprintf( buf, sizeof( buf ), + "regular expression \"%s\" bad because of %s", + pat, error ); + Debug( LDAP_DEBUG_ANY, + "%s: line %d: %s\n", + fname, lineno, buf ); acl_usage(); + exit( EXIT_FAILURE ); } regfree(&re); } @@ -176,7 +192,7 @@ regtest(const char *fname, int lineno, char *pat) { static int check_scope( BackendDB *be, AccessControl *a ) { - int patlen; + ber_len_t patlen; struct berval dn; dn = be->be_nsuffix[0]; @@ -245,7 +261,8 @@ regex_done:; * more than one level between the suffix * and the pattern */ if ( style == ACL_STYLE_ONE ) { - int rdnlen = -1, sep = 0; + ber_len_t rdnlen = 0; + int sep = 0; if ( patlen > 0 ) { if ( !DN_SEPARATOR( dn.bv_val[dn.bv_len - patlen - 1] )) { @@ -300,32 +317,31 @@ regex_done:; return ACL_SCOPE_UNKNOWN; } -void +int parse_acl( - Backend *be, - const char *fname, - int lineno, - int argc, - char **argv, + Backend *be, + const char *fname, + int lineno, + int argc, + char **argv, int pos ) { int i; - char *left, *right, *style, *next; + char *left, *right, *style; struct berval bv; - AccessControl *a; - Access *b; + AccessControl *a = NULL; + Access *b = NULL; int rc; const char *text; - a = NULL; for ( i = 1; i < argc; i++ ) { /* to clause - select which entries are protected */ if ( strcasecmp( argv[i], "to" ) == 0 ) { if ( a != NULL ) { - fprintf( stderr, "%s: line %d: " + Debug( LDAP_DEBUG_ANY, "%s: line %d: " "only one to clause allowed in access line\n", - fname, lineno ); - acl_usage(); + fname, lineno, 0 ); + goto fail; } a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) ); for ( ++i; i < argc; i++ ) { @@ -338,11 +354,11 @@ parse_acl( if ( !BER_BVISEMPTY( &a->acl_dn_pat ) || a->acl_dn_style != ACL_STYLE_REGEX ) { - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "%s: line %d: dn pattern" " already specified in to clause.\n", - fname, lineno ); - acl_usage(); + fname, lineno, 0 ); + goto fail; } ber_str2bv( "*", STRLENOF( "*" ), 1, &a->acl_dn_pat ); @@ -353,21 +369,21 @@ parse_acl( split( left, '.', &left, &style ); if ( right == NULL ) { - fprintf( stderr, "%s: line %d: " + Debug( LDAP_DEBUG_ANY, "%s: line %d: " "missing \"=\" in \"%s\" in to clause\n", fname, lineno, left ); - acl_usage(); + goto fail; } if ( strcasecmp( left, "dn" ) == 0 ) { if ( !BER_BVISEMPTY( &a->acl_dn_pat ) || a->acl_dn_style != ACL_STYLE_REGEX ) { - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "%s: line %d: dn pattern" " already specified in to clause.\n", - fname, lineno ); - acl_usage(); + fname, lineno, 0 ); + goto fail; } if ( style == NULL || *style == '\0' || @@ -422,10 +438,10 @@ parse_acl( } } else { - fprintf( stderr, "%s: line %d: " + Debug( LDAP_DEBUG_ANY, "%s: line %d: " "unknown dn style \"%s\" in to clause\n", fname, lineno, style ); - acl_usage(); + goto fail; } continue; @@ -433,42 +449,51 @@ parse_acl( if ( strcasecmp( left, "filter" ) == 0 ) { if ( (a->acl_filter = str2filter( right )) == NULL ) { - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "%s: line %d: bad filter \"%s\" in to clause\n", fname, lineno, right ); - acl_usage(); + goto fail; } } else if ( strcasecmp( left, "attr" ) == 0 /* TOLERATED */ || strcasecmp( left, "attrs" ) == 0 ) /* DOCUMENTED */ { + if ( strcasecmp( left, "attr" ) == 0 ) { + Debug( LDAP_DEBUG_ANY, + "%s: line %d: \"attr\" " + "is deprecated (and undocumented); " + "use \"attrs\" instead.\n", + fname, lineno, 0 ); + } + a->acl_attrs = str2anlist( a->acl_attrs, right, "," ); if ( a->acl_attrs == NULL ) { - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "%s: line %d: unknown attr \"%s\" in to clause\n", fname, lineno, right ); - acl_usage(); + goto fail; } } else if ( strncasecmp( left, "val", 3 ) == 0 ) { - char *mr; + struct berval bv; + char *mr; if ( !BER_BVISEMPTY( &a->acl_attrval ) ) { - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "%s: line %d: attr val already specified in to clause.\n", - fname, lineno ); - acl_usage(); + fname, lineno, 0 ); + goto fail; } if ( a->acl_attrs == NULL || !BER_BVISEMPTY( &a->acl_attrs[1].an_name ) ) { - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "%s: line %d: attr val requires a single attribute.\n", - fname, lineno ); - acl_usage(); + fname, lineno, 0 ); + goto fail; } - ber_str2bv( right, 0, 1, &a->acl_attrval ); + ber_str2bv( right, 0, 0, &bv ); a->acl_attrval_style = ACL_STYLE_BASE; mr = strchr( left, '/' ); @@ -478,34 +503,45 @@ parse_acl( a->acl_attrval_mr = mr_find( mr ); if ( a->acl_attrval_mr == NULL ) { - fprintf( stderr, "%s: line %d: " + Debug( LDAP_DEBUG_ANY, "%s: line %d: " "invalid matching rule \"%s\".\n", fname, lineno, mr ); - acl_usage(); + goto fail; } if( !mr_usable_with_at( a->acl_attrval_mr, a->acl_attrs[ 0 ].an_desc->ad_type ) ) { - fprintf( stderr, "%s: line %d: " + char buf[ SLAP_TEXT_BUFLEN ]; + + snprintf( buf, sizeof( buf ), "matching rule \"%s\" use " - "with attr \"%s\" not appropriate.\n", - fname, lineno, mr, - a->acl_attrs[ 0 ].an_name.bv_val ); - acl_usage(); + "with attr \"%s\" not appropriate.", + mr, a->acl_attrs[ 0 ].an_name.bv_val ); + + + Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n", + fname, lineno, buf ); + goto fail; } } if ( style != NULL ) { if ( strcasecmp( style, "regex" ) == 0 ) { - int e = regcomp( &a->acl_attrval_re, a->acl_attrval.bv_val, + int e = regcomp( &a->acl_attrval_re, bv.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(); + char err[SLAP_TEXT_BUFLEN], + buf[ SLAP_TEXT_BUFLEN ]; + + regerror( e, &a->acl_attrval_re, err, sizeof( err ) ); + + snprintf( buf, sizeof( buf ), + "regular expression \"%s\" bad because of %s", + right, err ); + + Debug( LDAP_DEBUG_ANY, "%s: line %d: %s\n", + fname, lineno, buf ); + goto fail; } a->acl_attrval_style = ACL_STYLE_REGEX; @@ -519,8 +555,6 @@ parse_acl( } else if ( a->acl_attrs[0].an_desc->ad_type-> sat_syntax == slap_schema.si_syn_distinguishedName ) { - struct berval bv; - if ( !strcasecmp( style, "baseObject" ) || !strcasecmp( style, "base" ) ) { @@ -536,57 +570,95 @@ parse_acl( } else if ( !strcasecmp( style, "children" ) ) { a->acl_attrval_style = ACL_STYLE_CHILDREN; } else { - fprintf( stderr, - "%s: line %d: unknown val.