1998-08-09 08:43:13 +08:00
|
|
|
/* acl.c - routines to parse and check acl's */
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/regex.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
1998-08-21 14:33:42 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "slap.h"
|
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
static int regex_matches(char *pat, char *str, char *buf, regmatch_t *matches);
|
|
|
|
static void string_expand(char *newbuf, int bufsiz, char *pattern,
|
|
|
|
char *match, regmatch_t *matches);
|
1998-08-21 14:33:42 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
/*
|
1999-01-19 13:10:50 +08:00
|
|
|
* access_allowed - check whether op->o_ndn is allowed the requested access
|
1998-08-09 08:43:13 +08:00
|
|
|
* to entry e, attribute attr, value val. if val is null, access to
|
|
|
|
* the whole attribute is assumed (all values). this routine finds
|
|
|
|
* the applicable acl and calls acl_access_allowed() to make the
|
|
|
|
* decision.
|
|
|
|
*
|
|
|
|
* returns 0 access NOT allowed
|
|
|
|
* 1 access allowed
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
access_allowed(
|
|
|
|
Backend *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
|
|
|
Entry *e,
|
|
|
|
char *attr,
|
|
|
|
struct berval *val,
|
|
|
|
int access
|
|
|
|
)
|
|
|
|
{
|
1998-08-21 14:33:42 +08:00
|
|
|
int rc;
|
|
|
|
struct acl *a;
|
|
|
|
char *edn;
|
|
|
|
|
|
|
|
regmatch_t matches[MAXREMATCHES];
|
|
|
|
int i;
|
|
|
|
int n;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
if ( be == NULL ) {
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
1999-01-19 13:10:50 +08:00
|
|
|
edn = e->e_ndn;
|
|
|
|
|
1998-08-21 14:33:42 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL, "\n=> access_allowed: entry (%s) attr (%s)\n",
|
|
|
|
e->e_dn, attr, 0 );
|
|
|
|
|
|
|
|
/* the lastmod attributes are ignored by ACL checking */
|
1999-07-08 02:51:39 +08:00
|
|
|
if ( oc_check_no_usermod_attr( attr ) ) {
|
1999-06-29 12:52:55 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL, "Operational attribute: %s access allowed\n",
|
1998-08-21 14:33:42 +08:00
|
|
|
attr, 0, 0 );
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(matches, 0, sizeof(matches));
|
|
|
|
|
1999-01-19 13:10:50 +08:00
|
|
|
a = acl_get_applicable( be, op, e, attr, MAXREMATCHES, matches );
|
1998-08-21 14:33:42 +08:00
|
|
|
|
|
|
|
if (a) {
|
|
|
|
for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
|
1998-11-23 12:33:53 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS, "=> match[%d]: %d %d ", i,
|
|
|
|
(int)matches[i].rm_so, (int)matches[i].rm_eo );
|
1998-08-21 14:33:42 +08:00
|
|
|
|
|
|
|
if( matches[i].rm_so <= matches[0].rm_eo ) {
|
|
|
|
for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
|
|
|
|
Debug( LDAP_DEBUG_ARGS, "%c", edn[n], 0, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Debug( LDAP_DEBUG_ARGS, "\n", 0, 0, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = acl_access_allowed( a, be, conn, e, val, op, access, edn, matches );
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ACL, "\n=> access_allowed: exit (%s) attr (%s)\n",
|
|
|
|
e->e_dn, attr, 0);
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acl_get_applicable - return the acl applicable to entry e, attribute
|
|
|
|
* attr. the acl returned is suitable for use in subsequent calls to
|
|
|
|
* acl_access_allowed().
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct acl *
|
|
|
|
acl_get_applicable(
|
|
|
|
Backend *be,
|
|
|
|
Operation *op,
|
|
|
|
Entry *e,
|
1998-08-21 14:33:42 +08:00
|
|
|
char *attr,
|
|
|
|
int nmatch,
|
|
|
|
regmatch_t *matches
|
1998-08-09 08:43:13 +08:00
|
|
|
)
|
|
|
|
{
|
1999-03-09 15:15:35 +08:00
|
|
|
int i;
|
1998-08-09 08:43:13 +08:00
|
|
|
struct acl *a;
|
1999-01-19 13:10:50 +08:00
|
|
|
char *edn;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-08-21 14:33:42 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL, "\n=> acl_get: entry (%s) attr (%s)\n",
|
|
|
|
e->e_dn, attr, 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-01-19 13:10:50 +08:00
|
|
|
if ( be_isroot( be, op->o_ndn ) ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"<= acl_get: no acl applicable to database root\n", 0, 0,
|
|
|
|
0 );
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
1999-01-19 13:10:50 +08:00
|
|
|
edn = e->e_ndn;
|
|
|
|
|
1998-08-21 14:33:42 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS, "=> acl_get: edn %s\n", edn, 0, 0 );
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/* check for a backend-specific acl that matches the entry */
|
|
|
|
for ( i = 1, a = be->be_acl; a != NULL; a = a->acl_next, i++ ) {
|
1998-08-21 14:33:42 +08:00
|
|
|
if (a->acl_dnpat != NULL) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "=> dnpat: [%d] %s nsub: %d\n",
|
1998-11-23 12:33:53 +08:00
|
|
|
i, a->acl_dnpat, (int) a->acl_dnre.re_nsub);
|
1998-08-21 14:33:42 +08:00
|
|
|
|
|
|
|
if (regexec(&a->acl_dnre, edn, nmatch, matches, 0))
|
1998-08-09 08:43:13 +08:00
|
|
|
continue;
|
1998-08-21 14:33:42 +08:00
|
|
|
else
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "=> acl_get:[%d] backend ACL match\n",
|
|
|
|
i, 0, 0);
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1998-08-21 14:33:42 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( a->acl_filter != NULL ) {
|
1998-08-21 14:33:42 +08:00
|
|
|
if ( test_filter( NULL, NULL, NULL, e, a->acl_filter ) != 0 ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
1998-08-21 14:33:42 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ARGS, "=> acl_get: [%d] check attr %s\n", i, attr, 0);
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( attr == NULL || a->acl_attrs == NULL ||
|
1998-08-21 14:33:42 +08:00
|
|
|
charray_inlist( a->acl_attrs, attr ) )
|
|
|
|
{
|
|
|
|
Debug( LDAP_DEBUG_ACL, "<= acl_get: [%d] backend acl %s attr: %s\n",
|
|
|
|
i, e->e_dn, attr );
|
1998-08-09 08:43:13 +08:00
|
|
|
return( a );
|
|
|
|
}
|
1998-08-21 14:33:42 +08:00
|
|
|
matches[0].rm_so = matches[0].rm_eo = -1;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check for a global acl that matches the entry */
|
|
|
|
for ( i = 1, a = global_acl; a != NULL; a = a->acl_next, i++ ) {
|
1998-08-21 14:33:42 +08:00
|
|
|
if (a->acl_dnpat != NULL) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "=> dnpat: [%d] %s nsub: %d\n",
|
1998-11-23 12:33:53 +08:00
|
|
|
i, a->acl_dnpat, (int) a->acl_dnre.re_nsub);
|
1998-08-21 14:33:42 +08:00
|
|
|
|
|
|
|
if (regexec(&a->acl_dnre, edn, nmatch, matches, 0)) {
|
1998-08-09 08:43:13 +08:00
|
|
|
continue;
|
1998-08-21 14:33:42 +08:00
|
|
|
} else {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "=> acl_get: [%d] global ACL match\n",
|
|
|
|
i, 0, 0);
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
1998-08-21 14:33:42 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( a->acl_filter != NULL ) {
|
1998-08-21 14:33:42 +08:00
|
|
|
if ( test_filter( NULL, NULL, NULL, e, a->acl_filter ) != 0 ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
1998-08-21 14:33:42 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ARGS, "=> acl_get: [%d] check attr\n", i, 0, 0);
|
|
|
|
|
|
|
|
if ( attr == NULL || a->acl_attrs == NULL ||
|
|
|
|
charray_inlist( a->acl_attrs, attr ) )
|
|
|
|
{
|
|
|
|
Debug( LDAP_DEBUG_ACL, "<= acl_get: [%d] global acl %s attr: %s\n",
|
|
|
|
i, e->e_dn, attr );
|
1998-08-09 08:43:13 +08:00
|
|
|
return( a );
|
|
|
|
}
|
1998-08-21 14:33:42 +08:00
|
|
|
|
|
|
|
matches[0].rm_so = matches[0].rm_eo = -1;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1998-08-21 14:33:42 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL, "<= acl_get: no match\n", 0, 0, 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acl_access_allowed - check whether the given acl allows dn the
|
|
|
|
* requested access to entry e, attribute attr, value val. if val
|
|
|
|
* is null, access to the whole attribute is assumed (all values).
|
|
|
|
*
|
|
|
|
* returns 0 access NOT allowed
|
|
|
|
* 1 access allowed
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
acl_access_allowed(
|
|
|
|
struct acl *a,
|
|
|
|
Backend *be,
|
|
|
|
Connection *conn,
|
|
|
|
Entry *e,
|
|
|
|
struct berval *val,
|
|
|
|
Operation *op,
|
1998-08-21 14:33:42 +08:00
|
|
|
int access,
|
|
|
|
char *edn,
|
|
|
|
regmatch_t *matches
|
1998-08-09 08:43:13 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct access *b;
|
|
|
|
Attribute *at;
|
|
|
|
struct berval bv;
|
|
|
|
int default_access;
|
|
|
|
|
1998-08-21 14:33:42 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"\n=> acl_access_allowed: %s access to entry \"%s\"\n",
|
|
|
|
access2str( access ), e->e_dn, 0 );
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"\n=> acl_access_allowed: %s access to value \"%s\" by \"%s\"\n",
|
|
|
|
access2str( access ),
|
|
|
|
val ? val->bv_val : "any",
|
1999-01-19 13:10:50 +08:00
|
|
|
op->o_ndn ? op->o_ndn : "" );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-01-19 13:10:50 +08:00
|
|
|
if ( be_isroot( be, op->o_ndn ) ) {
|
1998-08-21 14:33:42 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"<= acl_access_allowed: granted to database root\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
0, 0, 0 );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
|
1998-08-21 14:33:42 +08:00
|
|
|
default_access = be->be_dfltaccess ? be->be_dfltaccess : global_default_access;
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( a == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_ACL,
|
1998-08-21 14:33:42 +08:00
|
|
|
"<= acl_access_allowed: %s by default (no matching to)\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
default_access >= access ? "granted" : "denied", 0, 0 );
|
|
|
|
return( default_access >= access );
|
|
|
|
}
|
|
|
|
|
1999-07-08 02:51:39 +08:00
|
|
|
if ( op->o_ndn != NULL ) {
|
|
|
|
bv.bv_val = op->o_ndn;
|
|
|
|
bv.bv_len = strlen( bv.bv_val );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-01-19 13:10:50 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
for ( i = 1, b = a->acl_access; b != NULL; b = b->a_next, i++ ) {
|
|
|
|
if ( b->a_dnpat != NULL ) {
|
1998-08-21 14:33:42 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<= check a_dnpat: %s\n",
|
|
|
|
b->a_dnpat, 0, 0);
|
1998-08-09 08:43:13 +08:00
|
|
|
/*
|
|
|
|
* if access applies to the entry itself, and the
|
|
|
|
* user is bound as somebody in the same namespace as
|
|
|
|
* the entry, OR the given dn matches the dn pattern
|
|
|
|
*/
|
1999-07-05 03:53:00 +08:00
|
|
|
if ( strcasecmp( b->a_dnpat, "anonymous" ) == 0 &&
|
|
|
|
(op->o_ndn == NULL || *(op->o_ndn) == '\0' ) )
|
|
|
|
{
|
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"<= acl_access_allowed: matched by clause #%d access %s\n",
|
|
|
|
i, ACL_GRANT(b->a_access, access)
|
|
|
|
? "granted" : "denied", 0 );
|
|
|
|
|
|
|
|
return ACL_GRANT(b->a_access, access );
|
|
|
|
|
|
|
|
} else if ( strcasecmp( b->a_dnpat, "self" ) == 0 &&
|
1999-01-19 13:10:50 +08:00
|
|
|
op->o_ndn != NULL && *(op->o_ndn) && e->e_dn != NULL )
|
1998-08-21 14:33:42 +08:00
|
|
|
{
|
1999-01-20 11:05:35 +08:00
|
|
|
if ( strcmp( edn, op->o_ndn ) == 0 ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL,
|
1998-08-21 14:33:42 +08:00
|
|
|
"<= acl_access_allowed: matched by clause #%d access %s\n",
|
1999-07-05 02:46:24 +08:00
|
|
|
i, ACL_GRANT(b->a_access, access)
|
|
|
|
? "granted" : "denied", 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-07-05 02:46:24 +08:00
|
|
|
return ACL_GRANT(b->a_access, access );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
} else {
|
1999-07-08 02:51:39 +08:00
|
|
|
if ( regex_matches( b->a_dnpat, op->o_ndn, edn, matches ) ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL,
|
1998-08-21 14:33:42 +08:00
|
|
|
"<= acl_access_allowed: matched by clause #%d access %s\n",
|
1999-07-05 02:46:24 +08:00
|
|
|
i, ACL_GRANT(b->a_access, access)
|
|
|
|
? "granted" : "denied", 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-07-05 02:46:24 +08:00
|
|
|
return ACL_GRANT(b->a_access, access );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( b->a_addrpat != NULL ) {
|
1999-03-22 15:14:54 +08:00
|
|
|
if ( regex_matches( b->a_addrpat, conn->c_client_addr,
|
|
|
|
edn, matches ) )
|
|
|
|
{
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL,
|
1998-08-21 14:33:42 +08:00
|
|
|
"<= acl_access_allowed: matched by clause #%d access %s\n",
|
1999-07-05 02:46:24 +08:00
|
|
|
i, ACL_GRANT(b->a_access, access)
|
|
|
|
? "granted" : "denied", 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-07-05 02:46:24 +08:00
|
|
|
return ACL_GRANT(b->a_access, access );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( b->a_domainpat != NULL ) {
|
1998-08-21 14:33:42 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS, "<= check a_domainpath: %s\n",
|
|
|
|
b->a_domainpat, 0, 0 );
|
1999-03-22 15:14:54 +08:00
|
|
|
if ( regex_matches( b->a_domainpat, conn->c_client_name,
|
|
|
|
edn, matches ) )
|
1998-08-21 14:33:42 +08:00
|
|
|
{
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL,
|
1998-08-21 14:33:42 +08:00
|
|
|
"<= acl_access_allowed: matched by clause #%d access %s\n",
|
1999-07-05 02:46:24 +08:00
|
|
|
i, ACL_GRANT(b->a_access, access)
|
|
|
|
? "granted" : "denied", 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-07-05 02:46:24 +08:00
|
|
|
return ACL_GRANT(b->a_access, access );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
1999-01-19 13:10:50 +08:00
|
|
|
if ( b->a_dnattr != NULL && op->o_ndn != NULL ) {
|
1998-08-21 14:33:42 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS, "<= check a_dnattr: %s\n",
|
|
|
|
b->a_dnattr, 0, 0);
|
1998-08-09 08:43:13 +08:00
|
|
|
/* see if asker is listed in dnattr */
|
1998-08-21 14:33:42 +08:00
|
|
|
if ( (at = attr_find( e->e_attrs, b->a_dnattr )) != NULL &&
|
|
|
|
value_find( at->a_vals, &bv, at->a_syntax, 3 ) == 0 )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
1999-07-05 02:46:24 +08:00
|
|
|
if ( ACL_IS_SELF(b->a_access) &&
|
1998-08-21 14:33:42 +08:00
|
|
|
(val == NULL || value_cmp( &bv, val, at->a_syntax, 2 )) )
|
|
|
|
{
|
1998-08-09 08:43:13 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ACL,
|
1998-08-21 14:33:42 +08:00
|
|
|
"<= acl_acces_allowed: matched by clause #%d access %s\n",
|
1999-07-05 02:46:24 +08:00
|
|
|
i, ACL_GRANT(b->a_access, access)
|
|
|
|
? "granted" : "denied", 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-07-05 02:46:24 +08:00
|
|
|
return ACL_GRANT(b->a_access, access );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* asker not listed in dnattr - check for self access */
|
1999-07-05 02:46:24 +08:00
|
|
|
if ( ! ACL_IS_SELF(b->a_access) || val == NULL ||
|
1998-08-21 14:33:42 +08:00
|
|
|
value_cmp( &bv, val, at->a_syntax, 2 ) != 0 )
|
|
|
|
{
|
1998-08-09 08:43:13 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ACL,
|
1998-08-21 14:33:42 +08:00
|
|
|
"<= acl_access_allowed: matched by clause #%d (self) access %s\n",
|
1999-07-05 02:46:24 +08:00
|
|
|
i, ACL_GRANT(b->a_access, access)
|
|
|
|
? "granted" : "denied", 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-07-05 02:46:24 +08:00
|
|
|
return ACL_GRANT(b->a_access, access );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-07-05 14:26:26 +08:00
|
|
|
|
1999-01-19 13:10:50 +08:00
|
|
|
if ( b->a_group != NULL && op->o_ndn != NULL ) {
|
|
|
|
char buf[1024];
|
1998-08-21 14:33:42 +08:00
|
|
|
|
|
|
|
/* b->a_group is an unexpanded entry name, expanded it should be an
|
|
|
|
* entry with objectclass group* and we test to see if odn is one of
|
1998-10-24 10:33:17 +08:00
|
|
|
* the values in the attribute group
|
1998-08-21 14:33:42 +08:00
|
|
|
*/
|
|
|
|
/* see if asker is listed in dnattr */
|
|
|
|
string_expand(buf, sizeof(buf), b->a_group, edn, matches);
|
1999-01-19 13:10:50 +08:00
|
|
|
(void) dn_normalize_case(buf);
|
1998-08-21 14:33:42 +08:00
|
|
|
|
1999-07-08 02:51:39 +08:00
|
|
|
if (backend_group(be, e, buf, op->o_ndn,
|
1999-07-05 02:46:24 +08:00
|
|
|
b->a_group_oc, b->a_group_at) == 0)
|
1998-12-30 11:35:23 +08:00
|
|
|
{
|
1998-08-21 14:33:42 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"<= acl_access_allowed: matched by clause #%d (group) access granted\n",
|
|
|
|
i, 0, 0 );
|
1999-07-05 02:46:24 +08:00
|
|
|
return ACL_GRANT(b->a_access, access );
|
1998-08-21 14:33:42 +08:00
|
|
|
}
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1998-08-21 14:33:42 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL,
|
|
|
|
"<= acl_access_allowed: %s by default (no matching by)\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
default_access >= access ? "granted" : "denied", 0, 0 );
|
|
|
|
|
|
|
|
return( default_access >= access );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-12-21 08:21:58 +08:00
|
|
|
* acl_check_modlist - check access control on the given entry to see if
|
1998-08-09 08:43:13 +08:00
|
|
|
* it allows the given modifications by the user associated with op.
|
|
|
|
* returns LDAP_SUCCESS mods allowed ok
|
|
|
|
* anything else mods not allowed - return is an error
|
|
|
|
* code indicating the problem
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
1998-12-21 08:21:58 +08:00
|
|
|
acl_check_modlist(
|
1998-08-09 08:43:13 +08:00
|
|
|
Backend *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
|
|
|
Entry *e,
|
1998-12-21 08:21:58 +08:00
|
|
|
LDAPModList *mlist
|
1998-08-09 08:43:13 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct acl *a;
|
1999-01-19 13:10:50 +08:00
|
|
|
char *edn = e->e_ndn;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-12-21 08:21:58 +08:00
|
|
|
for ( ; mlist != NULL; mlist = mlist->ml_next ) {
|
1998-08-21 14:33:42 +08:00
|
|
|
regmatch_t matches[MAXREMATCHES];
|
|
|
|
|
|
|
|
/* the lastmod attributes are ignored by ACL checking */
|
1999-07-08 02:51:39 +08:00
|
|
|
if ( oc_check_no_usermod_attr( mlist->ml_type ) ) {
|
1999-06-29 12:52:55 +08:00
|
|
|
Debug( LDAP_DEBUG_ACL, "Operational attribute: %s access allowed\n",
|
1998-12-21 08:21:58 +08:00
|
|
|
mlist->ml_type, 0, 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-01-19 13:10:50 +08:00
|
|
|
a = acl_get_applicable( be, op, e, mlist->ml_type,
|
1998-08-21 14:33:42 +08:00
|
|
|
MAXREMATCHES, matches );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-12-21 08:21:58 +08:00
|
|
|
switch ( mlist->ml_op & ~LDAP_MOD_BVALUES ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
case LDAP_MOD_REPLACE:
|
|
|
|
case LDAP_MOD_ADD:
|
1998-12-21 08:21:58 +08:00
|
|
|
if ( mlist->ml_bvalues == NULL ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
break;
|
|
|
|
}
|
1998-12-21 08:21:58 +08:00
|
|
|
for ( i = 0; mlist->ml_bvalues[i] != NULL; i++ ) {
|
|
|
|
if ( ! acl_access_allowed( a, be, conn, e, mlist->ml_bvalues[i],
|
1998-08-21 14:33:42 +08:00
|
|
|
op, ACL_WRITE, edn, matches) )
|
|
|
|
{
|
1998-08-09 08:43:13 +08:00
|
|
|
return( LDAP_INSUFFICIENT_ACCESS );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_MOD_DELETE:
|
1998-12-21 08:21:58 +08:00
|
|
|
if ( mlist->ml_bvalues == NULL ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( ! acl_access_allowed( a, be, conn, e,
|
1998-08-21 14:33:42 +08:00
|
|
|
NULL, op, ACL_WRITE, edn, matches) )
|
|
|
|
{
|
1998-08-09 08:43:13 +08:00
|
|
|
return( LDAP_INSUFFICIENT_ACCESS );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1998-12-21 08:21:58 +08:00
|
|
|
for ( i = 0; mlist->ml_bvalues[i] != NULL; i++ ) {
|
|
|
|
if ( ! acl_access_allowed( a, be, conn, e, mlist->ml_bvalues[i],
|
1998-08-21 14:33:42 +08:00
|
|
|
op, ACL_WRITE, edn, matches) )
|
|
|
|
{
|
1998-08-09 08:43:13 +08:00
|
|
|
return( LDAP_INSUFFICIENT_ACCESS );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return( LDAP_SUCCESS );
|
|
|
|
}
|
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
static void
|
|
|
|
string_expand(
|
1998-08-21 14:33:42 +08:00
|
|
|
char *newbuf,
|
|
|
|
int bufsiz,
|
|
|
|
char *pat,
|
|
|
|
char *match,
|
|
|
|
regmatch_t *matches)
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
1998-08-21 14:33:42 +08:00
|
|
|
int size;
|
|
|
|
char *sp;
|
|
|
|
char *dp;
|
|
|
|
int flag;
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
newbuf[0] = '\0';
|
|
|
|
|
|
|
|
flag = 0;
|
1998-11-24 10:29:53 +08:00
|
|
|
for ( dp = newbuf, sp = pat; size < bufsiz && *sp ; sp++) {
|
1998-08-21 14:33:42 +08:00
|
|
|
/* did we previously see a $ */
|
|
|
|
if (flag) {
|
|
|
|
if (*sp == '$') {
|
|
|
|
*dp++ = '$';
|
|
|
|
size++;
|
|
|
|
} else if (*sp >= '0' && *sp <= '9' ) {
|
|
|
|
int n;
|
|
|
|
int i;
|
|
|
|
int l;
|
|
|
|
|
|
|
|
n = *sp - '0';
|
|
|
|
*dp = '\0';
|
|
|
|
i = matches[n].rm_so;
|
|
|
|
l = matches[n].rm_eo;
|
|
|
|
for ( ; size < 512 && i < l; size++, i++ ) {
|
|
|
|
*dp++ = match[i];
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
*dp = '\0';
|
|
|
|
}
|
|
|
|
flag = 0;
|
|
|
|
} else {
|
|
|
|
if (*sp == '$') {
|
|
|
|
flag = 1;
|
|
|
|
} else {
|
|
|
|
*dp++ = *sp;
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1998-08-21 14:33:42 +08:00
|
|
|
*dp = '\0';
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-08-21 14:33:42 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "=> string_expand: pattern: %s\n", pat, 0, 0 );
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "=> string_expand: expanded: %s\n", newbuf, 0, 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1998-08-21 14:33:42 +08:00
|
|
|
regex_matches(
|
|
|
|
char *pat, /* pattern to expand and match against */
|
|
|
|
char *str, /* string to match against pattern */
|
|
|
|
char *buf, /* buffer with $N expansion variables */
|
|
|
|
regmatch_t *matches /* offsets in buffer for $N expansion variables */
|
|
|
|
)
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
1998-08-21 14:33:42 +08:00
|
|
|
regex_t re;
|
|
|
|
char newbuf[512];
|
1998-08-09 08:43:13 +08:00
|
|
|
int rc;
|
|
|
|
|
1999-07-05 03:53:00 +08:00
|
|
|
if(str == NULL) str = "";
|
|
|
|
|
1998-08-21 14:33:42 +08:00
|
|
|
string_expand(newbuf, sizeof(newbuf), pat, buf, matches);
|
|
|
|
if (( rc = regcomp(&re, newbuf, REG_EXTENDED|REG_ICASE))) {
|
|
|
|
char error[512];
|
|
|
|
regerror(rc, &re, error, sizeof(error));
|
|
|
|
|
1998-09-21 04:22:46 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
1998-08-21 14:33:42 +08:00
|
|
|
"compile( \"%s\", \"%s\") failed %s\n",
|
|
|
|
pat, str, error );
|
1998-08-09 08:43:13 +08:00
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
1998-08-21 14:33:42 +08:00
|
|
|
rc = regexec(&re, str, 0, NULL, 0);
|
|
|
|
regfree( &re );
|
|
|
|
|
1998-09-12 12:33:13 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
1998-08-21 14:33:42 +08:00
|
|
|
"=> regex_matches: string: %s\n", str, 0, 0 );
|
1998-09-12 12:33:13 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
1998-08-21 14:33:42 +08:00
|
|
|
"=> regex_matches: rc: %d %s\n",
|
|
|
|
rc, !rc ? "matches" : "no matches", 0 );
|
|
|
|
return( !rc );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|