2007-12-15 19:12:56 +08:00
|
|
|
/* $OpenLDAP$ */
|
2006-04-29 18:03:36 +08:00
|
|
|
/* constraint.c - Overlay to constrain attributes to certain values */
|
|
|
|
/*
|
|
|
|
* Copyright 2003-2004 Hewlett-Packard Company
|
2007-12-15 19:12:56 +08:00
|
|
|
* Copyright 2007 Emmanuel Dreyfus
|
2006-04-29 18:03:36 +08:00
|
|
|
* 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>.
|
|
|
|
*/
|
|
|
|
/*
|
2007-12-15 19:12:56 +08:00
|
|
|
* Authors: Neil Dunbar <neil.dunbar@hp.com>
|
|
|
|
* Emmannuel Dreyfus <manu@netbsd.org>
|
2006-04-29 18:03:36 +08:00
|
|
|
*/
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#ifdef SLAPD_OVER_CONSTRAINT
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/regex.h>
|
|
|
|
|
2007-12-15 19:12:56 +08:00
|
|
|
#include "lutil.h"
|
2006-04-29 18:03:36 +08:00
|
|
|
#include "slap.h"
|
2006-07-12 10:14:22 +08:00
|
|
|
#include "config.h"
|
2006-04-29 18:03:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This overlay limits the values which can be placed into an
|
|
|
|
* attribute, over and above the limits placed by the schema.
|
|
|
|
*
|
|
|
|
* It traps only LDAP adds and modify commands (and only seeks to
|
|
|
|
* control the add and modify value mods of a modify)
|
|
|
|
*/
|
|
|
|
|
2006-07-12 10:14:22 +08:00
|
|
|
#define REGEX_STR "regex"
|
2007-12-15 19:12:56 +08:00
|
|
|
#define URI_STR "uri"
|
2008-09-17 08:40:18 +08:00
|
|
|
#define SET_STR "set"
|
2008-05-09 20:59:16 +08:00
|
|
|
#define SIZE_STR "size"
|
|
|
|
#define COUNT_STR "count"
|
2006-07-12 10:14:22 +08:00
|
|
|
|
2006-04-29 18:03:36 +08:00
|
|
|
/*
|
|
|
|
* Linked list of attribute constraints which we should enforce.
|
|
|
|
* This is probably a sub optimal structure - some form of sorted
|
|
|
|
* array would be better if the number of attributes contrained is
|
|
|
|
* likely to be much bigger than 4 or 5. We stick with a list for
|
|
|
|
* the moment.
|
|
|
|
*/
|
2006-07-12 10:14:22 +08:00
|
|
|
|
2006-04-29 18:03:36 +08:00
|
|
|
typedef struct constraint {
|
2007-12-15 19:12:56 +08:00
|
|
|
struct constraint *ap_next;
|
2008-09-17 08:40:18 +08:00
|
|
|
AttributeDescription **ap;
|
2007-12-15 19:12:56 +08:00
|
|
|
regex_t *re;
|
|
|
|
LDAPURLDesc *lud;
|
2008-09-17 08:40:18 +08:00
|
|
|
int set;
|
2008-05-09 20:59:16 +08:00
|
|
|
size_t size;
|
|
|
|
size_t count;
|
2007-12-15 19:12:56 +08:00
|
|
|
AttributeDescription **attrs;
|
|
|
|
struct berval val; /* constraint value */
|
|
|
|
struct berval dn;
|
|
|
|
struct berval filter;
|
2006-04-29 18:03:36 +08:00
|
|
|
} constraint;
|
|
|
|
|
2006-07-12 10:14:22 +08:00
|
|
|
enum {
|
2007-12-15 19:12:56 +08:00
|
|
|
CONSTRAINT_ATTRIBUTE = 1
|
2006-07-12 10:14:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static ConfigDriver constraint_cf_gen;
|
|
|
|
|
|
|
|
static ConfigTable constraintcfg[] = {
|
2007-12-15 19:12:56 +08:00
|
|
|
{ "constraint_attribute", "attribute> (regex|uri) <value",
|
|
|
|
4, 4, 0, ARG_MAGIC | CONSTRAINT_ATTRIBUTE, constraint_cf_gen,
|
|
|
|
"( OLcfgOvAt:13.1 NAME 'olcConstraintAttribute' "
|
|
|
|
"DESC 'regular expression constraint for attribute' "
|
2006-11-12 10:15:49 +08:00
|
|
|
"EQUALITY caseIgnoreMatch "
|
2007-12-15 19:12:56 +08:00
|
|
|
"SYNTAX OMsDirectoryString )", NULL, NULL },
|
|
|
|
{ NULL, NULL, 0, 0, 0, ARG_IGNORED }
|
2006-07-12 10:14:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static ConfigOCs constraintocs[] = {
|
2007-12-15 19:12:56 +08:00
|
|
|
{ "( OLcfgOvOc:13.1 "
|
|
|
|
"NAME 'olcConstraintConfig' "
|
|
|
|
"DESC 'Constraint overlay configuration' "
|
|
|
|
"SUP olcOverlayConfig "
|
|
|
|
"MAY ( olcConstraintAttribute ) )",
|
|
|
|
Cft_Overlay, constraintcfg },
|
|
|
|
{ NULL, 0, NULL }
|
2006-07-12 10:14:22 +08:00
|
|
|
};
|
|
|
|
|
2007-12-15 19:12:56 +08:00
|
|
|
static void
|
|
|
|
constraint_free( constraint *cp )
|
|
|
|
{
|
|
|
|
if (cp->re) {
|
|
|
|
regfree(cp->re);
|
|
|
|
ch_free(cp->re);
|
|
|
|
}
|
|
|
|
if (!BER_BVISNULL(&cp->val))
|
|
|
|
ch_free(cp->val.bv_val);
|
|
|
|
if (cp->lud)
|
|
|
|
ldap_free_urldesc(cp->lud);
|
|
|
|
if (cp->attrs)
|
|
|
|
ch_free(cp->attrs);
|
2008-09-17 08:40:18 +08:00
|
|
|
if (cp->ap)
|
|
|
|
ch_free(cp->ap);
|
2007-12-15 19:12:56 +08:00
|
|
|
ch_free(cp);
|
|
|
|
}
|
|
|
|
|
2006-07-12 10:14:22 +08:00
|
|
|
static int
|
|
|
|
constraint_cf_gen( ConfigArgs *c )
|
|
|
|
{
|
2007-12-15 19:12:56 +08:00
|
|
|
slap_overinst *on = (slap_overinst *)(c->bi);
|
|
|
|
constraint *cn = on->on_bi.bi_private, *cp;
|
|
|
|
struct berval bv;
|
|
|
|
int i, rc = 0;
|
|
|
|
constraint ap = { NULL, NULL, NULL }, *a2 = NULL;
|
|
|
|
const char *text = NULL;
|
|
|
|
|
|
|
|
switch ( c->op ) {
|
|
|
|
case SLAP_CONFIG_EMIT:
|
|
|
|
switch (c->type) {
|
|
|
|
case CONSTRAINT_ATTRIBUTE:
|
|
|
|
for (cp=cn; cp; cp=cp->ap_next) {
|
|
|
|
char *s;
|
|
|
|
char *tstr = NULL;
|
2008-09-17 08:40:18 +08:00
|
|
|
int quotes = 0;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
bv.bv_len = STRLENOF(" ");
|
|
|
|
for (j = 0; cp->ap[j]; j++) {
|
|
|
|
bv.bv_len += cp->ap[j]->ad_cname.bv_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* room for commas */
|
|
|
|
bv.bv_len += j - 1;
|
2007-12-15 19:12:56 +08:00
|
|
|
|
|
|
|
if (cp->re) {
|
|
|
|
tstr = REGEX_STR;
|
|
|
|
} else if (cp->lud) {
|
|
|
|
tstr = URI_STR;
|
2008-09-17 08:40:18 +08:00
|
|
|
} else if (cp->set) {
|
|
|
|
tstr = SET_STR;
|
|
|
|
quotes = 1;
|
2008-05-09 20:59:16 +08:00
|
|
|
} else if (cp->size) {
|
|
|
|
tstr = SIZE_STR;
|
|
|
|
} else if (cp->count) {
|
|
|
|
tstr = COUNT_STR;
|
2007-12-15 19:12:56 +08:00
|
|
|
}
|
|
|
|
|
2008-09-17 08:40:18 +08:00
|
|
|
bv.bv_len += strlen(tstr);
|
|
|
|
bv.bv_len += cp->val.bv_len + 2*quotes;
|
|
|
|
|
|
|
|
s = bv.bv_val = ch_malloc(bv.bv_len + 1);
|
|
|
|
|
|
|
|
s = lutil_strncopy( s, cp->ap[0]->ad_cname.bv_val, cp->ap[0]->ad_cname.bv_len );
|
|
|
|
for (j = 1; cp->ap[j]; j++) {
|
|
|
|
*s++ = ',';
|
|
|
|
s = lutil_strncopy( s, cp->ap[j]->ad_cname.bv_val, cp->ap[j]->ad_cname.bv_len );
|
|
|
|
}
|
|
|
|
*s++ = ' ';
|
|
|
|
s = lutil_strcopy( s, tstr );
|
|
|
|
*s++ = ' ';
|
|
|
|
if ( quotes ) *s++ = '"';
|
|
|
|
s = lutil_strncopy( s, cp->val.bv_val, cp->val.bv_len );
|
|
|
|
if ( quotes ) *s++ = '"';
|
|
|
|
*s = '\0';
|
2007-12-15 19:12:56 +08:00
|
|
|
|
|
|
|
rc = value_add_one( &c->rvalue_vals, &bv );
|
2008-09-17 08:40:18 +08:00
|
|
|
if (rc == LDAP_SUCCESS)
|
|
|
|
rc = value_add_one( &c->rvalue_nvals, &bv );
|
|
|
|
ch_free(bv.bv_val);
|
2007-12-15 19:12:56 +08:00
|
|
|
if (rc) return rc;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LDAP_MOD_DELETE:
|
|
|
|
switch (c->type) {
|
|
|
|
case CONSTRAINT_ATTRIBUTE:
|
|
|
|
if (!cn) break; /* nothing to do */
|
|
|
|
|
|
|
|
if (c->valx < 0) {
|
|
|
|
/* zap all constraints */
|
|
|
|
while (cn) {
|
|
|
|
cp = cn->ap_next;
|
|
|
|
constraint_free( cn );
|
|
|
|
cn = cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
on->on_bi.bi_private = NULL;
|
|
|
|
} else {
|
|
|
|
constraint **cpp;
|
|
|
|
|
|
|
|
/* zap constraint numbered 'valx' */
|
|
|
|
for(i=0, cp = cn, cpp = &cn;
|
|
|
|
(cp) && (i<c->valx);
|
|
|
|
i++, cpp = &cp->ap_next, cp = *cpp);
|
|
|
|
|
|
|
|
if (cp) {
|
|
|
|
/* zap cp, and join cpp to cp->ap_next */
|
|
|
|
*cpp = cp->ap_next;
|
|
|
|
constraint_free( cp );
|
|
|
|
}
|
|
|
|
on->on_bi.bi_private = cn;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SLAP_CONFIG_ADD:
|
|
|
|
case LDAP_MOD_ADD:
|
|
|
|
switch (c->type) {
|
2008-09-17 08:40:18 +08:00
|
|
|
case CONSTRAINT_ATTRIBUTE: {
|
|
|
|
int j;
|
|
|
|
char **attrs = ldap_str2charray( c->argv[1], "," );
|
|
|
|
|
|
|
|
for ( j = 0; attrs[j]; j++)
|
|
|
|
/* just count */ ;
|
|
|
|
ap.ap = ch_calloc( sizeof(AttributeDescription*), j + 1 );
|
|
|
|
for ( j = 0; attrs[j]; j++) {
|
|
|
|
if ( slap_str2ad( attrs[j], &ap.ap[j], &text ) ) {
|
|
|
|
snprintf( c->cr_msg, sizeof( c->cr_msg ),
|
|
|
|
"%s <%s>: %s\n", c->argv[0], attrs[j], text );
|
|
|
|
Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
|
|
|
|
"%s: %s\n", c->log, c->cr_msg, 0 );
|
|
|
|
ldap_memvfree((void**)attrs);
|
|
|
|
return( ARG_BAD_CONF );
|
|
|
|
}
|
2007-12-15 19:12:56 +08:00
|
|
|
}
|
2008-09-17 08:40:18 +08:00
|
|
|
ldap_memvfree((void**)attrs);
|
2007-12-15 19:12:56 +08:00
|
|
|
|
|
|
|
if ( strcasecmp( c->argv[2], REGEX_STR ) == 0) {
|
|
|
|
int err;
|
|
|
|
|
|
|
|
ap.re = ch_malloc( sizeof(regex_t) );
|
|
|
|
if ((err = regcomp( ap.re,
|
|
|
|
c->argv[3], REG_EXTENDED )) != 0) {
|
|
|
|
char errmsg[1024];
|
|
|
|
|
|
|
|
regerror( err, ap.re, errmsg, sizeof(errmsg) );
|
|
|
|
ch_free(ap.re);
|
|
|
|
snprintf( c->cr_msg, sizeof( c->cr_msg ),
|
|
|
|
"%s %s: Illegal regular expression \"%s\": Error %s",
|
|
|
|
c->argv[0], c->argv[1], c->argv[3], errmsg);
|
|
|
|
Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
|
|
|
|
"%s: %s\n", c->log, c->cr_msg, 0 );
|
|
|
|
ap.re = NULL;
|
|
|
|
return( ARG_BAD_CONF );
|
|
|
|
}
|
|
|
|
ber_str2bv( c->argv[3], 0, 1, &ap.val );
|
2008-05-09 20:59:16 +08:00
|
|
|
} else if ( strcasecmp( c->argv[2], SIZE_STR ) == 0 ) {
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
if ( ( size = atoi(c->argv[3]) ) != 0 )
|
|
|
|
ap.size = size;
|
|
|
|
} else if ( strcasecmp( c->argv[2], COUNT_STR ) == 0 ) {
|
|
|
|
size_t count;
|
|
|
|
|
|
|
|
if ( ( count = atoi(c->argv[3]) ) != 0 )
|
|
|
|
ap.count = count;
|
|
|
|
} else if ( strcasecmp( c->argv[2], URI_STR ) == 0 ) {
|
2007-12-15 19:12:56 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = ldap_url_parse(c->argv[3], &ap.lud);
|
|
|
|
if ( err != LDAP_URL_SUCCESS ) {
|
|
|
|
snprintf( c->cr_msg, sizeof( c->cr_msg ),
|
|
|
|
"%s %s: Invalid URI \"%s\"",
|
|
|
|
c->argv[0], c->argv[1], c->argv[3]);
|
|
|
|
Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
|
|
|
|
"%s: %s\n", c->log, c->cr_msg, 0 );
|
|
|
|
return( ARG_BAD_CONF );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ap.lud->lud_host != NULL) {
|
|
|
|
snprintf( c->cr_msg, sizeof( c->cr_msg ),
|
|
|
|
"%s %s: unsupported hostname in URI \"%s\"",
|
|
|
|
c->argv[0], c->argv[1], c->argv[3]);
|
|
|
|
Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
|
|
|
|
"%s: %s\n", c->log, c->cr_msg, 0 );
|
|
|
|
|
|
|
|
ldap_free_urldesc(ap.lud);
|
|
|
|
|
|
|
|
return( ARG_BAD_CONF );
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i=0; ap.lud->lud_attrs[i]; i++);
|
|
|
|
/* FIXME: This is worthless without at least one attr */
|
|
|
|
if ( i ) {
|
|
|
|
ap.attrs = ch_malloc( (i+1)*sizeof(AttributeDescription *));
|
|
|
|
for ( i=0; ap.lud->lud_attrs[i]; i++) {
|
|
|
|
ap.attrs[i] = NULL;
|
|
|
|
if ( slap_str2ad( ap.lud->lud_attrs[i], &ap.attrs[i], &text ) ) {
|
|
|
|
ch_free( ap.attrs );
|
2007-08-03 20:02:07 +08:00
|
|
|
snprintf( c->cr_msg, sizeof( c->cr_msg ),
|
2007-12-15 19:12:56 +08:00
|
|
|
"%s <%s>: %s\n", c->argv[0], ap.lud->lud_attrs[i], text );
|
|
|
|
Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
|
|
|
|
"%s: %s\n", c->log, c->cr_msg, 0 );
|
|
|
|
return( ARG_BAD_CONF );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ap.attrs[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ap.lud->lud_dn == NULL)
|
|
|
|
ap.lud->lud_dn = ch_strdup("");
|
|
|
|
|
2008-07-13 00:03:31 +08:00
|
|
|
if (ap.lud->lud_filter == NULL) {
|
2007-12-15 19:12:56 +08:00
|
|
|
ap.lud->lud_filter = ch_strdup("objectClass=*");
|
2008-07-13 00:03:31 +08:00
|
|
|
} else if ( ap.lud->lud_filter[0] == '(' ) {
|
|
|
|
ber_len_t len = strlen( ap.lud->lud_filter );
|
|
|
|
if ( ap.lud->lud_filter[len - 1] != ')' ) {
|
|
|
|
return( ARG_BAD_CONF );
|
|
|
|
}
|
|
|
|
AC_MEMCPY( &ap.lud->lud_filter[0], &ap.lud->lud_filter[1], len - 2 );
|
|
|
|
ap.lud->lud_filter[len - 2] = '\0';
|
|
|
|
}
|
2007-12-15 19:12:56 +08:00
|
|
|
|
|
|
|
ber_str2bv( c->argv[3], 0, 1, &ap.val );
|
2008-09-17 08:40:18 +08:00
|
|
|
|
|
|
|
} else if ( strcasecmp( c->argv[2], SET_STR ) == 0 ) {
|
|
|
|
ap.set = 1;
|
|
|
|
ber_str2bv( c->argv[3], 0, 1, &ap.val );
|
|
|
|
|
2007-12-15 19:12:56 +08:00
|
|
|
} else {
|
|
|
|
snprintf( c->cr_msg, sizeof( c->cr_msg ),
|
|
|
|
"%s %s: Unknown constraint type: %s",
|
|
|
|
c->argv[0], c->argv[1], c->argv[2] );
|
|
|
|
Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
|
|
|
|
"%s: %s\n", c->log, c->cr_msg, 0 );
|
|
|
|
return ( ARG_BAD_CONF );
|
|
|
|
}
|
|
|
|
|
2008-01-16 04:32:35 +08:00
|
|
|
a2 = ch_calloc( sizeof(constraint), 1 );
|
2007-12-15 19:12:56 +08:00
|
|
|
a2->ap_next = on->on_bi.bi_private;
|
|
|
|
a2->ap = ap.ap;
|
|
|
|
a2->re = ap.re;
|
|
|
|
a2->val = ap.val;
|
|
|
|
a2->lud = ap.lud;
|
2008-09-17 08:40:18 +08:00
|
|
|
a2->set = ap.set;
|
2008-05-09 20:59:16 +08:00
|
|
|
a2->size = ap.size;
|
|
|
|
a2->count = ap.count;
|
2008-01-16 04:32:35 +08:00
|
|
|
if ( a2->lud ) {
|
|
|
|
ber_str2bv(a2->lud->lud_dn, 0, 0, &a2->dn);
|
|
|
|
ber_str2bv(a2->lud->lud_filter, 0, 0, &a2->filter);
|
|
|
|
}
|
2007-12-15 19:12:56 +08:00
|
|
|
a2->attrs = ap.attrs;
|
|
|
|
on->on_bi.bi_private = a2;
|
2008-09-17 08:40:18 +08:00
|
|
|
} break;
|
2007-12-15 19:12:56 +08:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
constraint_uri_cb( Operation *op, SlapReply *rs )
|
|
|
|
{
|
|
|
|
if(rs->sr_type == REP_SEARCH) {
|
|
|
|
int *foundp = op->o_callback->sc_private;
|
|
|
|
|
|
|
|
*foundp = 1;
|
|
|
|
|
|
|
|
Debug(LDAP_DEBUG_TRACE, "==> constraint_uri_cb <%s>\n",
|
|
|
|
rs->sr_entry ? rs->sr_entry->e_name.bv_val : "UNKNOWN_DN", 0, 0);
|
|
|
|
}
|
|
|
|
return 0;
|
2006-07-12 10:14:22 +08:00
|
|
|
}
|
|
|
|
|
2006-04-29 18:03:36 +08:00
|
|
|
static int
|
2007-12-15 19:12:56 +08:00
|
|
|
constraint_violation( constraint *c, struct berval *bv, Operation *op, SlapReply *rs)
|
2006-04-29 18:03:36 +08:00
|
|
|
{
|
2008-07-13 01:58:11 +08:00
|
|
|
if ((!c) || (!bv)) return LDAP_SUCCESS;
|
2007-12-15 19:12:56 +08:00
|
|
|
|
|
|
|
if ((c->re) &&
|
|
|
|
(regexec(c->re, bv->bv_val, 0, NULL, 0) == REG_NOMATCH))
|
2008-07-13 01:58:11 +08:00
|
|
|
return LDAP_CONSTRAINT_VIOLATION; /* regular expression violation */
|
2007-12-15 19:12:56 +08:00
|
|
|
|
2008-05-09 20:59:16 +08:00
|
|
|
if ((c->size) && (bv->bv_len > c->size))
|
2008-07-13 01:58:11 +08:00
|
|
|
return LDAP_CONSTRAINT_VIOLATION; /* size violation */
|
2008-05-09 20:59:16 +08:00
|
|
|
|
2007-12-15 19:12:56 +08:00
|
|
|
if (c->lud) {
|
|
|
|
Operation nop = *op;
|
|
|
|
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
|
|
|
|
slap_callback cb;
|
|
|
|
SlapReply nrs = { REP_RESULT };
|
|
|
|
int i;
|
|
|
|
int found;
|
|
|
|
int rc;
|
|
|
|
size_t len;
|
|
|
|
struct berval filterstr;
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
found = 0;
|
|
|
|
|
|
|
|
nrs.sr_entry = NULL;
|
|
|
|
nrs.sr_nentries = 0;
|
|
|
|
|
|
|
|
cb.sc_next = NULL;
|
|
|
|
cb.sc_response = constraint_uri_cb;
|
|
|
|
cb.sc_cleanup = NULL;
|
|
|
|
cb.sc_private = &found;
|
|
|
|
|
|
|
|
nop.o_protocol = LDAP_VERSION3;
|
|
|
|
nop.o_tag = LDAP_REQ_SEARCH;
|
|
|
|
nop.o_time = slap_get_time();
|
|
|
|
if (c->lud->lud_dn) {
|
|
|
|
struct berval dn;
|
|
|
|
|
|
|
|
ber_str2bv(c->lud->lud_dn, 0, 0, &dn);
|
|
|
|
nop.o_req_dn = dn;
|
|
|
|
nop.o_req_ndn = dn;
|
|
|
|
nop.o_bd = select_backend(&nop.o_req_ndn, 1 );
|
2008-07-13 01:58:11 +08:00
|
|
|
if (!nop.o_bd) {
|
|
|
|
return LDAP_NO_SUCH_OBJECT; /* unexpected error */
|
|
|
|
}
|
|
|
|
if (!nop.o_bd->be_search) {
|
|
|
|
return LDAP_OTHER; /* unexpected error */
|
2007-12-15 19:12:56 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nop.o_req_dn = nop.o_bd->be_nsuffix[0];
|
|
|
|
nop.o_req_ndn = nop.o_bd->be_nsuffix[0];
|
|
|
|
nop.o_bd = on->on_info->oi_origdb;
|
|
|
|
}
|
|
|
|
nop.o_do_not_cache = 1;
|
|
|
|
nop.o_callback = &cb;
|
|
|
|
|
|
|
|
nop.ors_scope = c->lud->lud_scope;
|
|
|
|
nop.ors_deref = LDAP_DEREF_NEVER;
|
|
|
|
nop.ors_slimit = SLAP_NO_LIMIT;
|
|
|
|
nop.ors_tlimit = SLAP_NO_LIMIT;
|
|
|
|
nop.ors_limit = NULL;
|
|
|
|
|
|
|
|
nop.ors_attrsonly = 0;
|
|
|
|
nop.ors_attrs = slap_anlist_no_attrs;
|
|
|
|
|
|
|
|
len = STRLENOF("(&(") +
|
|
|
|
c->filter.bv_len +
|
|
|
|
STRLENOF(")(|");
|
|
|
|
|
|
|
|
for (i = 0; c->attrs[i]; i++) {
|
|
|
|
len += STRLENOF("(") +
|
|
|
|
c->attrs[i]->ad_cname.bv_len +
|
|
|
|
STRLENOF("=") +
|
|
|
|
bv->bv_len +
|
|
|
|
STRLENOF(")");
|
|
|
|
}
|
|
|
|
|
|
|
|
len += STRLENOF("))");
|
|
|
|
filterstr.bv_len = len;
|
|
|
|
filterstr.bv_val = op->o_tmpalloc(len + 1, op->o_tmpmemctx);
|
|
|
|
|
|
|
|
ptr = filterstr.bv_val +
|
|
|
|
snprintf(filterstr.bv_val, len, "(&(%s)(|", c->lud->lud_filter);
|
|
|
|
for (i = 0; c->attrs[i]; i++) {
|
|
|
|
*ptr++ = '(';
|
|
|
|
ptr = lutil_strcopy( ptr, c->attrs[i]->ad_cname.bv_val );
|
|
|
|
*ptr++ = '=';
|
|
|
|
ptr = lutil_strcopy( ptr, bv->bv_val );
|
|
|
|
*ptr++ = ')';
|
|
|
|
}
|
|
|
|
*ptr++ = ')';
|
|
|
|
*ptr++ = ')';
|
2008-07-13 00:03:31 +08:00
|
|
|
*ptr++ = '\0';
|
2007-12-15 19:12:56 +08:00
|
|
|
|
|
|
|
nop.ors_filterstr = filterstr;
|
|
|
|
nop.ors_filter = str2filter_x(&nop, filterstr.bv_val);
|
2008-07-13 01:58:11 +08:00
|
|
|
if ( nop.ors_filter == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"%s constraint_violation uri filter=\"%s\" invalid\n",
|
|
|
|
op->o_log_prefix, filterstr.bv_val, 0 );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
|
|
|
"==> constraint_violation uri filter = %s\n",
|
|
|
|
filterstr.bv_val, 0, 0);
|
2007-12-15 19:12:56 +08:00
|
|
|
|
2008-07-13 01:58:11 +08:00
|
|
|
rc = nop.o_bd->be_search( &nop, &nrs );
|
2007-12-15 19:12:56 +08:00
|
|
|
|
2008-07-13 01:58:11 +08:00
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
|
|
|
"==> constraint_violation uri rc = %d, found = %d\n",
|
|
|
|
rc, found, 0);
|
|
|
|
}
|
2007-12-15 19:12:56 +08:00
|
|
|
op->o_tmpfree(filterstr.bv_val, op->o_tmpmemctx);
|
|
|
|
|
|
|
|
if((rc != LDAP_SUCCESS) && (rc != LDAP_NO_SUCH_OBJECT)) {
|
2008-07-13 01:58:11 +08:00
|
|
|
return rc; /* unexpected error */
|
2007-12-15 19:12:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
2008-07-13 01:58:11 +08:00
|
|
|
return LDAP_CONSTRAINT_VIOLATION; /* constraint violation */
|
2007-12-15 19:12:56 +08:00
|
|
|
|
|
|
|
}
|
2008-09-17 08:40:18 +08:00
|
|
|
|
2008-07-13 01:58:11 +08:00
|
|
|
return LDAP_SUCCESS;
|
2006-04-29 18:03:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2007-12-15 19:12:56 +08:00
|
|
|
print_message( struct berval *errtext, AttributeDescription *a )
|
2006-04-29 18:03:36 +08:00
|
|
|
{
|
2007-12-15 19:12:56 +08:00
|
|
|
char *ret;
|
|
|
|
int sz;
|
|
|
|
|
|
|
|
sz = errtext->bv_len + sizeof(" on ") + a->ad_cname.bv_len;
|
|
|
|
ret = ch_malloc(sz);
|
|
|
|
snprintf( ret, sz, "%s on %s", errtext->bv_val, a->ad_cname.bv_val );
|
|
|
|
return ret;
|
2006-04-29 18:03:36 +08:00
|
|
|
}
|
|
|
|
|
2008-05-09 20:59:16 +08:00
|
|
|
static unsigned
|
|
|
|
constraint_count_attr(Entry *e, AttributeDescription *ad)
|
|
|
|
{
|
|
|
|
struct Attribute *a;
|
|
|
|
|
|
|
|
if ((a = attr_find(e->e_attrs, ad)) != NULL)
|
|
|
|
return a->a_numvals;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-29 18:03:36 +08:00
|
|
|
static int
|
|
|
|
constraint_add( Operation *op, SlapReply *rs )
|
|
|
|
{
|
2007-12-15 19:12:56 +08:00
|
|
|
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
|
|
|
|
Attribute *a;
|
|
|
|
constraint *c = on->on_bi.bi_private, *cp;
|
|
|
|
BerVarray b = NULL;
|
|
|
|
int i;
|
|
|
|
struct berval rsv = BER_BVC("add breaks constraint");
|
2008-07-13 01:58:11 +08:00
|
|
|
int rc;
|
|
|
|
char *msg = NULL;
|
2007-12-15 19:12:56 +08:00
|
|
|
|
|
|
|
if ((a = op->ora_e->e_attrs) == NULL) {
|
|
|
|
op->o_bd->bd_info = (BackendInfo *)(on->on_info);
|
|
|
|
send_ldap_error(op, rs, LDAP_INVALID_SYNTAX,
|
2008-07-13 01:58:11 +08:00
|
|
|
"constraint_add: no attrs");
|
2007-12-15 19:12:56 +08:00
|
|
|
return(rs->sr_err);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(; a; a = a->a_next ) {
|
|
|
|
/* we don't constrain operational attributes */
|
|
|
|
if (is_at_operational(a->a_desc->ad_type)) continue;
|
|
|
|
|
|
|
|
for(cp = c; cp; cp = cp->ap_next) {
|
2008-09-17 08:40:18 +08:00
|
|
|
int j;
|
|
|
|
for (j = 0; cp->ap[j]; j++) {
|
|
|
|
if (cp->ap[j] == a->a_desc) break;
|
|
|
|
}
|
|
|
|
if (cp->ap[j] == NULL) continue;
|
2007-12-15 19:12:56 +08:00
|
|
|
if ((b = a->a_vals) == NULL) continue;
|
|
|
|
|
2008-05-09 20:59:16 +08:00
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
|
|
|
"==> constraint_add, "
|
|
|
|
"a->a_numvals = %d, cp->count = %d\n",
|
|
|
|
a->a_numvals, cp->count, 0);
|
|
|
|
|
2008-07-13 01:58:11 +08:00
|
|
|
if ((cp->count != 0) && (a->a_numvals > cp->count)) {
|
|
|
|
rc = LDAP_CONSTRAINT_VIOLATION;
|
2008-05-09 20:59:16 +08:00
|
|
|
goto add_violation;
|
2008-07-13 01:58:11 +08:00
|
|
|
}
|
2008-05-09 20:59:16 +08:00
|
|
|
|
2008-07-13 01:58:11 +08:00
|
|
|
for ( i = 0; b[i].bv_val; i++ ) {
|
|
|
|
rc = constraint_violation( cp, &b[i], op, rs );
|
|
|
|
if ( rc ) {
|
2008-05-09 20:59:16 +08:00
|
|
|
goto add_violation;
|
2008-07-13 01:58:11 +08:00
|
|
|
}
|
|
|
|
}
|
2008-09-17 08:40:18 +08:00
|
|
|
|
|
|
|
if (cp->set && acl_match_set(&cp->val, op, op->ora_e, NULL) == 0) {
|
|
|
|
rc = LDAP_CONSTRAINT_VIOLATION;
|
|
|
|
goto add_violation; /* constraint violation */
|
|
|
|
}
|
|
|
|
|
2007-12-15 19:12:56 +08:00
|
|
|
}
|
|
|
|
}
|
2008-09-17 08:40:18 +08:00
|
|
|
|
2006-04-29 18:03:36 +08:00
|
|
|
/* Default is to just fall through to the normal processing */
|
2007-12-15 19:12:56 +08:00
|
|
|
return SLAP_CB_CONTINUE;
|
2008-05-09 20:59:16 +08:00
|
|
|
|
|
|
|
add_violation:
|
|
|
|
op->o_bd->bd_info = (BackendInfo *)(on->on_info);
|
2008-07-13 01:58:11 +08:00
|
|
|
if (rc == LDAP_CONSTRAINT_VIOLATION ) {
|
|
|
|
msg = print_message( &rsv, a->a_desc );
|
|
|
|
}
|
|
|
|
send_ldap_error(op, rs, rc, msg );
|
2008-05-09 20:59:16 +08:00
|
|
|
ch_free(msg);
|
|
|
|
return (rs->sr_err);
|
2006-04-29 18:03:36 +08:00
|
|
|
}
|
|
|
|
|
2008-05-09 20:59:16 +08:00
|
|
|
|
2006-04-29 18:03:36 +08:00
|
|
|
static int
|
|
|
|
constraint_modify( Operation *op, SlapReply *rs )
|
|
|
|
{
|
2007-12-15 19:12:56 +08:00
|
|
|
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
|
2008-05-09 20:59:16 +08:00
|
|
|
Backend *be = op->o_bd;
|
2007-12-15 19:12:56 +08:00
|
|
|
constraint *c = on->on_bi.bi_private, *cp;
|
2008-09-17 08:40:18 +08:00
|
|
|
Entry *target_entry = NULL, *target_entry_copy = NULL;
|
2007-12-15 19:12:56 +08:00
|
|
|
Modifications *m;
|
|
|
|
BerVarray b = NULL;
|
|
|
|
int i;
|
|
|
|
struct berval rsv = BER_BVC("modify breaks constraint");
|
2008-07-13 01:58:11 +08:00
|
|
|
int rc;
|
|
|
|
char *msg = NULL;
|
2007-12-15 19:12:56 +08:00
|
|
|
|
2008-09-17 08:40:18 +08:00
|
|
|
Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE, "constraint_modify()\n", 0,0,0);
|
2007-12-15 19:12:56 +08:00
|
|
|
if ((m = op->orm_modlist) == NULL) {
|
|
|
|
op->o_bd->bd_info = (BackendInfo *)(on->on_info);
|
|
|
|
send_ldap_error(op, rs, LDAP_INVALID_SYNTAX,
|
|
|
|
"constraint_modify() got null orm_modlist");
|
|
|
|
return(rs->sr_err);
|
|
|
|
}
|
|
|
|
|
2008-05-09 20:59:16 +08:00
|
|
|
/* Do we need to count attributes? */
|
|
|
|
for(cp = c; cp; cp = cp->ap_next) {
|
2008-09-17 08:40:18 +08:00
|
|
|
if (cp->count != 0 || cp->set) {
|
2008-05-09 20:59:16 +08:00
|
|
|
op->o_bd = on->on_info->oi_origdb;
|
|
|
|
rc = be_entry_get_rw( op, &op->o_req_ndn, NULL, NULL, 0, &target_entry );
|
|
|
|
op->o_bd = be;
|
|
|
|
|
|
|
|
if (rc != 0 || target_entry == NULL) {
|
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
2008-07-13 01:58:11 +08:00
|
|
|
"==> constraint_modify rc = %d DN=\"%s\"%s\n",
|
|
|
|
rc, op->o_req_ndn.bv_val,
|
|
|
|
target_entry ? "" : " not found" );
|
|
|
|
if ( rc == 0 )
|
|
|
|
rc = LDAP_CONSTRAINT_VIOLATION;
|
2008-05-09 20:59:16 +08:00
|
|
|
goto mod_violation;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-07-13 01:58:11 +08:00
|
|
|
|
|
|
|
rc = LDAP_CONSTRAINT_VIOLATION;
|
2007-12-15 19:12:56 +08:00
|
|
|
for(;m; m = m->sml_next) {
|
2008-05-09 20:59:16 +08:00
|
|
|
int ce = 0;
|
|
|
|
|
2007-12-15 19:12:56 +08:00
|
|
|
if (is_at_operational( m->sml_desc->ad_type )) continue;
|
2008-09-17 08:40:18 +08:00
|
|
|
|
2007-12-15 19:12:56 +08:00
|
|
|
if ((( m->sml_op & LDAP_MOD_OP ) != LDAP_MOD_ADD) &&
|
2008-05-09 20:59:16 +08:00
|
|
|
(( m->sml_op & LDAP_MOD_OP ) != LDAP_MOD_REPLACE) &&
|
|
|
|
(( m->sml_op & LDAP_MOD_OP ) != LDAP_MOD_DELETE))
|
2007-12-15 19:12:56 +08:00
|
|
|
continue;
|
|
|
|
/* we only care about ADD and REPLACE modifications */
|
2008-05-09 20:59:16 +08:00
|
|
|
/* and DELETE are used to track attribute count */
|
2007-12-15 19:12:56 +08:00
|
|
|
if ((( b = m->sml_values ) == NULL ) || (b[0].bv_val == NULL))
|
|
|
|
continue;
|
|
|
|
|
2008-09-17 08:40:18 +08:00
|
|
|
/* Get this attribute count, if needed */
|
|
|
|
if (target_entry)
|
|
|
|
ce = constraint_count_attr(target_entry, m->sml_desc);
|
|
|
|
|
2007-12-15 19:12:56 +08:00
|
|
|
for(cp = c; cp; cp = cp->ap_next) {
|
2008-09-17 08:40:18 +08:00
|
|
|
int j;
|
|
|
|
for (j = 0; cp->ap[j]; j++) {
|
|
|
|
if (cp->ap[j] == m->sml_desc) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cp->ap[j] == NULL) continue;
|
2007-12-15 19:12:56 +08:00
|
|
|
|
2008-05-09 20:59:16 +08:00
|
|
|
if (cp->count != 0) {
|
|
|
|
int ca;
|
|
|
|
|
|
|
|
if (m->sml_op == LDAP_MOD_DELETE)
|
|
|
|
ce = 0;
|
|
|
|
|
|
|
|
for (ca = 0; b[ca].bv_val; ++ca);
|
|
|
|
|
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
|
|
|
"==> constraint_modify ce = %d, "
|
|
|
|
"ca = %d, cp->count = %d\n",
|
2008-05-10 05:49:47 +08:00
|
|
|
ce, ca, cp->count);
|
2008-05-09 20:59:16 +08:00
|
|
|
|
2008-07-13 01:58:11 +08:00
|
|
|
if (m->sml_op == LDAP_MOD_ADD) {
|
|
|
|
if (ca + ce > cp->count) {
|
|
|
|
rc = LDAP_CONSTRAINT_VIOLATION;
|
2008-05-09 20:59:16 +08:00
|
|
|
goto mod_violation;
|
2008-07-13 01:58:11 +08:00
|
|
|
}
|
|
|
|
}
|
2008-05-10 05:49:47 +08:00
|
|
|
if (m->sml_op == LDAP_MOD_REPLACE) {
|
2008-07-13 01:58:11 +08:00
|
|
|
if (ca > cp->count) {
|
|
|
|
rc = LDAP_CONSTRAINT_VIOLATION;
|
2008-05-09 20:59:16 +08:00
|
|
|
goto mod_violation;
|
2008-07-13 01:58:11 +08:00
|
|
|
}
|
2008-05-10 05:49:47 +08:00
|
|
|
ce = ca;
|
|
|
|
}
|
2008-05-09 20:59:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DELETE are to be ignored beyond this point */
|
|
|
|
if (( m->sml_op & LDAP_MOD_OP ) == LDAP_MOD_DELETE)
|
|
|
|
continue;
|
|
|
|
|
2008-07-13 01:58:11 +08:00
|
|
|
for ( i = 0; b[i].bv_val; i++ ) {
|
|
|
|
rc = constraint_violation( cp, &b[i], op, rs );
|
|
|
|
if ( rc ) {
|
2008-05-09 20:59:16 +08:00
|
|
|
goto mod_violation;
|
2008-07-13 01:58:11 +08:00
|
|
|
}
|
|
|
|
}
|
2008-09-17 08:40:18 +08:00
|
|
|
|
|
|
|
if (cp->set && target_entry) {
|
|
|
|
if (target_entry_copy == NULL) {
|
|
|
|
Modifications *ml;
|
|
|
|
|
|
|
|
target_entry_copy = entry_dup(target_entry);
|
|
|
|
|
|
|
|
/* apply modifications, in an attempt
|
|
|
|
* to estimate what the entry would
|
|
|
|
* look like in case all modifications
|
|
|
|
* pass */
|
|
|
|
for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
|
|
|
|
Modification *mod = &ml->sml_mod;
|
|
|
|
const char *text;
|
|
|
|
char textbuf[SLAP_TEXT_BUFLEN];
|
|
|
|
size_t textlen = sizeof(textbuf);
|
|
|
|
int err;
|
|
|
|
|
|
|
|
switch ( mod->sm_op ) {
|
|
|
|
case LDAP_MOD_ADD:
|
|
|
|
err = modify_add_values( target_entry_copy,
|
|
|
|
mod, get_permissiveModify(op),
|
|
|
|
&text, textbuf, textlen );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_MOD_DELETE:
|
|
|
|
err = modify_delete_values( target_entry_copy,
|
|
|
|
mod, get_permissiveModify(op),
|
|
|
|
&text, textbuf, textlen );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_MOD_REPLACE:
|
|
|
|
err = modify_replace_values( target_entry_copy,
|
|
|
|
mod, get_permissiveModify(op),
|
|
|
|
&text, textbuf, textlen );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_MOD_INCREMENT:
|
|
|
|
err = modify_increment_values( target_entry_copy,
|
|
|
|
mod, get_permissiveModify(op),
|
|
|
|
&text, textbuf, textlen );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SLAP_MOD_SOFTADD:
|
|
|
|
mod->sm_op = LDAP_MOD_ADD;
|
|
|
|
err = modify_add_values( target_entry_copy,
|
|
|
|
mod, get_permissiveModify(op),
|
|
|
|
&text, textbuf, textlen );
|
|
|
|
mod->sm_op = SLAP_MOD_SOFTADD;
|
|
|
|
if ( err == LDAP_TYPE_OR_VALUE_EXISTS ) {
|
|
|
|
err = LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
err = LDAP_OTHER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( err != LDAP_SUCCESS ) {
|
|
|
|
rc = err;
|
|
|
|
goto mod_violation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( acl_match_set(&cp->val, op, target_entry_copy, NULL) == 0) {
|
|
|
|
rc = LDAP_CONSTRAINT_VIOLATION;
|
|
|
|
goto mod_violation;
|
|
|
|
}
|
|
|
|
}
|
2007-12-15 19:12:56 +08:00
|
|
|
}
|
|
|
|
}
|
2008-09-17 08:40:18 +08:00
|
|
|
|
2008-05-09 20:59:16 +08:00
|
|
|
if (target_entry) {
|
|
|
|
op->o_bd = on->on_info->oi_origdb;
|
|
|
|
be_entry_release_r(op, target_entry);
|
|
|
|
op->o_bd = be;
|
|
|
|
}
|
2008-09-17 08:40:18 +08:00
|
|
|
|
|
|
|
if (target_entry_copy) {
|
|
|
|
entry_free(target_entry_copy);
|
|
|
|
}
|
|
|
|
|
2007-12-15 19:12:56 +08:00
|
|
|
return SLAP_CB_CONTINUE;
|
2008-07-13 01:58:11 +08:00
|
|
|
|
2008-05-09 20:59:16 +08:00
|
|
|
mod_violation:
|
|
|
|
/* violation */
|
|
|
|
if (target_entry) {
|
|
|
|
op->o_bd = on->on_info->oi_origdb;
|
|
|
|
be_entry_release_r(op, target_entry);
|
|
|
|
op->o_bd = be;
|
|
|
|
}
|
2008-09-17 08:40:18 +08:00
|
|
|
|
|
|
|
if (target_entry_copy) {
|
|
|
|
entry_free(target_entry_copy);
|
|
|
|
}
|
|
|
|
|
2008-05-09 20:59:16 +08:00
|
|
|
op->o_bd->bd_info = (BackendInfo *)(on->on_info);
|
2008-07-13 01:58:11 +08:00
|
|
|
if ( rc == LDAP_CONSTRAINT_VIOLATION ) {
|
|
|
|
msg = print_message( &rsv, m->sml_desc );
|
|
|
|
}
|
|
|
|
send_ldap_error( op, rs, LDAP_CONSTRAINT_VIOLATION, msg );
|
2008-05-09 20:59:16 +08:00
|
|
|
ch_free(msg);
|
|
|
|
return (rs->sr_err);
|
2006-04-29 18:03:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
constraint_close(
|
2007-07-26 01:21:05 +08:00
|
|
|
BackendDB *be,
|
2007-08-03 20:02:07 +08:00
|
|
|
ConfigReply *cr )
|
2006-04-29 18:03:36 +08:00
|
|
|
{
|
2007-12-15 19:12:56 +08:00
|
|
|
slap_overinst *on = (slap_overinst *) be->bd_info;
|
|
|
|
constraint *ap, *a2;
|
|
|
|
|
|
|
|
for ( ap = on->on_bi.bi_private; ap; ap = a2 ) {
|
|
|
|
a2 = ap->ap_next;
|
|
|
|
constraint_free( ap );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2006-04-29 18:03:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static slap_overinst constraint_ovl;
|
|
|
|
|
2006-05-01 22:53:19 +08:00
|
|
|
#if SLAPD_OVER_CONSTRAINT == SLAPD_MOD_DYNAMIC
|
|
|
|
static
|
|
|
|
#endif
|
|
|
|
int
|
|
|
|
constraint_initialize( void ) {
|
2007-12-15 19:12:56 +08:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
constraint_ovl.on_bi.bi_type = "constraint";
|
|
|
|
constraint_ovl.on_bi.bi_db_close = constraint_close;
|
|
|
|
constraint_ovl.on_bi.bi_op_add = constraint_add;
|
|
|
|
constraint_ovl.on_bi.bi_op_modify = constraint_modify;
|
|
|
|
|
|
|
|
constraint_ovl.on_bi.bi_private = NULL;
|
|
|
|
|
|
|
|
constraint_ovl.on_bi.bi_cf_ocs = constraintocs;
|
|
|
|
rc = config_register_schema( constraintcfg, constraintocs );
|
|
|
|
if (rc) return rc;
|
|
|
|
|
|
|
|
return overlay_register( &constraint_ovl );
|
2006-04-29 18:03:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#if SLAPD_OVER_CONSTRAINT == SLAPD_MOD_DYNAMIC
|
|
|
|
int init_module(int argc, char *argv[]) {
|
2007-12-15 19:12:56 +08:00
|
|
|
return constraint_initialize();
|
2006-04-29 18:03:36 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* defined(SLAPD_OVER_CONSTRAINT) */
|
|
|
|
|