/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2004-2007 The OpenLDAP Foundation.
+ * Copyright 2004-2008 The OpenLDAP Foundation.
* Portions Copyright 2004,2006-2007 Symas Corporation.
* All rights reserved.
*
uri->ndn,
NULL );
if ( rc != LDAP_SUCCESS ) {
- snprintf( c->msg, sizeof( c->msg ),
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
"<%s> invalid DN %d (%s)",
url_desc->lud_dn, rc, ldap_err2string( rc ));
rc = ARG_BAD_CONF;
}
if ( !dnIsSuffix ( uri->ndn, &be->be_nsuffix[0] ) ) {
- sprintf ( c->msg,
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
"dn <%s> is not a suffix of backend base dn <%s>",
uri->dn->bv_val,
be->be_nsuffix[0].bv_val );
attr->next = uri->attrs;
uri->attrs = attr;
} else {
- snprintf( c->msg, sizeof( c->msg ),
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
"unique: attribute: %s: %s",
attr_str[i], text );
rc = ARG_BAD_CONF;
uri->scope = url_desc->lud_scope;
if ( !uri->scope ) {
- snprintf( c->msg, sizeof( c->msg ),
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
"unique: uri with base scope will always be unique");
rc = ARG_BAD_CONF;
goto exit;
uri->filter = ber_str2bv( url_desc->lud_filter, 0, 1, NULL);
f = str2filter( uri->filter->bv_val );
if ( !f ) {
- snprintf( c->msg, sizeof( c->msg ),
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
"unique: bad filter");
rc = ARG_BAD_CONF;
goto exit;
*urip = uri;
if ( rc ) {
Debug ( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
- "%s: %s\n", c->log, c->msg, 0 );
+ "%s: %s\n", c->log, c->cr_msg, 0 );
unique_free_domain_uri ( uri );
*urip = NULL;
}
}
rc = ldap_url_parselist_ext ( &url_descs, uri_start, " ", 0 );
if ( rc ) {
- snprintf( c->msg, sizeof( c->msg ),
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
"<%s> invalid ldap urilist",
uri_start );
rc = ARG_BAD_CONF;
*domainp = domain;
if ( rc ) {
Debug ( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
- "%s: %s\n", c->log, c->msg, 0 );
+ "%s: %s\n", c->log, c->cr_msg, 0 );
unique_free_domain ( domain );
*domainp = NULL;
}
case LDAP_MOD_ADD:
case SLAP_CONFIG_ADD:
if ( domains ) {
- sprintf ( c->msg,
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
"cannot set legacy attrs when URIs are present" );
Debug ( LDAP_DEBUG_CONFIG, "unique config: %s\n",
- c->msg, NULL, NULL );
+ c->cr_msg, NULL, NULL );
rc = ARG_BAD_CONF;
break;
}
if ( !dnIsSuffix ( &c->value_ndn,
&be->be_nsuffix[0] ) ) {
- sprintf ( c->msg,
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
"dn is not a suffix of backend base" );
Debug ( LDAP_DEBUG_CONFIG, "unique config: %s\n",
- c->msg, NULL, NULL );
+ c->cr_msg, NULL, NULL );
rc = ARG_BAD_CONF;
break;
}
case LDAP_MOD_ADD:
case SLAP_CONFIG_ADD:
if ( domains ) {
- sprintf ( c->msg,
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
"cannot set legacy attrs when URIs are present" );
Debug ( LDAP_DEBUG_CONFIG, "unique config: %s\n",
- c->msg, NULL, NULL );
+ c->cr_msg, NULL, NULL );
rc = ARG_BAD_CONF;
break;
}
&& legacy->uri
&& legacy->uri->attrs
&& (c->type == UNIQUE_IGNORE) != legacy->ignore ) {
- sprintf ( c->msg,
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
"cannot set both attrs and ignore-attrs" );
Debug ( LDAP_DEBUG_CONFIG, "unique config: %s\n",
- c->msg, NULL, NULL );
+ c->cr_msg, NULL, NULL );
rc = ARG_BAD_CONF;
break;
}
attr->next = new_attrs;
new_attrs = attr;
} else {
- snprintf( c->msg, sizeof( c->msg ),
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
"unique: attribute: %s: %s",
c->argv[i], text );
for ( attr = new_attrs;
if ( rc ) {
Debug ( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
- "%s: %s\n", c->log, c->msg, 0 );
+ "%s: %s\n", c->log, c->cr_msg, 0 );
}
return rc;
}
case LDAP_MOD_ADD:
case SLAP_CONFIG_ADD:
if ( domains ) {
- sprintf ( c->msg,
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
"cannot set legacy attrs when URIs are present" );
Debug ( LDAP_DEBUG_CONFIG, "unique config: %s\n",
- c->msg, NULL, NULL );
+ c->cr_msg, NULL, NULL );
rc = ARG_BAD_CONF;
break;
}
* test024 Will hit this case in such a
* situation.
*/
- assert (*domainp);
+ assert (*domainp != NULL);
domain = *domainp;
*domainp = domain->next;
case SLAP_CONFIG_ADD: /* fallthrough */
case LDAP_MOD_ADD:
if ( legacy ) {
- sprintf ( c->msg,
+ snprintf( c->cr_msg, sizeof( c->cr_msg ),
"cannot set Uri when legacy attrs are present" );
Debug ( LDAP_DEBUG_CONFIG, "unique config: %s\n",
- c->msg, NULL, NULL );
+ c->cr_msg, NULL, NULL );
rc = ARG_BAD_CONF;
break;
}
static int
unique_db_init(
- BackendDB *be
+ BackendDB *be,
+ ConfigReply *cr
)
{
slap_overinst *on = (slap_overinst *)be->bd_info;
static int
unique_db_destroy(
- BackendDB *be
+ BackendDB *be,
+ ConfigReply *cr
)
{
slap_overinst *on = (slap_overinst *)be->bd_info;
static int
unique_open(
- BackendDB *be
+ BackendDB *be,
+ ConfigReply *cr
)
{
Debug(LDAP_DEBUG_TRACE, "unique_open: overlay initialized\n", 0, 0, 0);
static int
unique_close(
- BackendDB *be
+ BackendDB *be,
+ ConfigReply *cr
)
{
slap_overinst *on = (slap_overinst *) be->bd_info;
AttributeDescription *ad,
BerVarray b,
char *kp,
+ int ks,
void *ctx
)
{
if ( b && b[0].bv_val ) {
for ( i = 0; b[i].bv_val; i++ ) {
struct berval bv;
+ int len;
ldap_bv2escaped_filter_value_x( &b[i], &bv, 1, ctx );
- kp += sprintf( kp, "(%s=%s)", ad->ad_cname.bv_val, bv.bv_val );
+ len = snprintf( kp, ks, "(%s=%s)", ad->ad_cname.bv_val, bv.bv_val );
+ assert( len >= 0 && len < ks );
+ kp += len;
if ( bv.bv_val != b[i].bv_val ) {
ber_memfree_x( bv.bv_val, ctx );
}
}
} else if ( domain->strict ) {
- kp += sprintf( kp, "(%s=*)", ad->ad_cname.bv_val );
+ int len;
+ len = snprintf( kp, ks, "(%s=*)", ad->ad_cname.bv_val );
+ assert( len >= 0 && len < ks );
+ kp += len;
}
break;
}
for ( domain = legacy ? legacy : domains;
domain;
- domain = domain->next ) {
+ domain = domain->next )
+ {
unique_domain_uri *uri;
int ks = 0;
for ( uri = domain->uri;
uri;
- uri = uri->next ) {
+ uri = uri->next )
+ {
+ int len;
if ( uri->ndn
&& !dnIsSuffix( &op->o_req_ndn, uri->ndn ))
ks += uri->filter->bv_len + STRLENOF ("(&)");
kp = key = op->o_tmpalloc(ks, op->o_tmpmemctx);
- if ( uri->filter && uri->filter->bv_len )
- kp += sprintf (kp, "(&%s", uri->filter->bv_val);
- kp += sprintf(kp, "(|");
+ if ( uri->filter && uri->filter->bv_len ) {
+ len = snprintf (kp, ks, "(&%s", uri->filter->bv_val);
+ assert( len >= 0 && len < ks );
+ kp += len;
+ }
+ len = snprintf(kp, ks - (kp - key), "(|");
+ assert( len >= 0 && len < ks - (kp - key) );
+ kp += len;
for(a = op->ora_e->e_attrs; a; a = a->a_next)
kp = build_filter(domain,
a->a_desc,
a->a_vals,
kp,
+ ks - ( kp - key ),
op->o_tmpmemctx);
- kp += sprintf(kp, ")");
- if ( uri->filter && uri->filter->bv_len )
- kp += sprintf (kp, ")");
+ len = snprintf(kp, ks - (kp - key), ")");
+ assert( len >= 0 && len < ks - (kp - key) );
+ kp += len;
+ if ( uri->filter && uri->filter->bv_len ) {
+ len = snprintf(kp, ks - (kp - key), ")");
+ assert( len >= 0 && len < ks - (kp - key) );
+ kp += len;
+ }
rc = unique_search ( op,
&nop,
for ( domain = legacy ? legacy : domains;
domain;
- domain = domain->next ) {
+ domain = domain->next )
+ {
unique_domain_uri *uri;
int ks = 0;
for ( uri = domain->uri;
uri;
- uri = uri->next ) {
+ uri = uri->next )
+ {
+ int len;
if ( uri->ndn
&& !dnIsSuffix( &op->o_req_ndn, uri->ndn ))
if ( !ks ) continue;
if ( uri->filter && uri->filter->bv_len )
- ks += uri->filter->bv_len;
- key = op->o_tmpalloc(ks, op->o_tmpmemctx);
+ ks += uri->filter->bv_len + STRLENOF ("(&)");
+ kp = key = op->o_tmpalloc(ks, op->o_tmpmemctx);
- if ( uri->filter && uri->filter->bv_len )
- kp += sprintf ("(&(%s)", uri->filter->bv_val);
- kp = key + sprintf(key, "(|");
+ if ( uri->filter && uri->filter->bv_len ) {
+ len = snprintf(kp, ks, "(&%s", uri->filter->bv_val);
+ assert( len >= 0 && len < ks );
+ kp += len;
+ }
+ len = snprintf(kp, ks - (kp - key), "(|");
+ assert( len >= 0 && len < ks - (kp - key) );
+ kp += len;
for(m = op->orm_modlist; m; m = m->sml_next)
if ( (m->sml_op & LDAP_MOD_OP)
m->sml_desc,
m->sml_values,
kp,
+ ks - (kp - key),
op->o_tmpmemctx );
- kp += sprintf (kp, ")");
- if ( uri->filter && uri->filter->bv_len )
- kp += sprintf (kp, ")");
+ len = snprintf(kp, ks - (kp - key), ")");
+ assert( len >= 0 && len < ks - (kp - key) );
+ kp += len;
+ if ( uri->filter && uri->filter->bv_len ) {
+ len = snprintf (kp, ks - (kp - key), ")");
+ assert( len >= 0 && len < ks - (kp - key) );
+ kp += len;
+ }
rc = unique_search ( op,
&nop,
for ( domain = legacy ? legacy : domains;
domain;
- domain = domain->next ) {
+ domain = domain->next )
+ {
unique_domain_uri *uri;
int ks = 0;
for ( uri = domain->uri;
uri;
- uri = uri->next ) {
- int i;
+ uri = uri->next )
+ {
+ int i, len;
if ( uri->ndn
&& !dnIsSuffix( &op->o_req_ndn, uri->ndn )
if ( !ks ) continue;
if ( uri->filter && uri->filter->bv_len )
- ks += uri->filter->bv_len;
- key = op->o_tmpalloc(ks, op->o_tmpmemctx);
+ ks += uri->filter->bv_len + STRLENOF ("(&)");
+ kp = key = op->o_tmpalloc(ks, op->o_tmpmemctx);
- if ( uri->filter && uri->filter->bv_len )
- kp += sprintf ("(&(%s)", uri->filter->bv_val);
- kp = key + sprintf(key, "(|");
+ if ( uri->filter && uri->filter->bv_len ) {
+ len = snprintf(kp, ks, "(&%s", uri->filter->bv_val);
+ assert( len >= 0 && len < ks );
+ kp += len;
+ }
+ len = snprintf(kp, ks - (kp - key), "(|");
+ assert( len >= 0 && len < ks - (kp - key) );
+ kp += len;
for ( i=0; newrdn[i]; i++) {
bv[0] = newrdn[i]->la_value;
newrdn[i]->la_private,
bv,
kp,
+ ks - (kp - key ),
op->o_tmpmemctx);
}
- kp += sprintf(kp, ")");
- if ( uri->filter && uri->filter->bv_len )
- kp += sprintf (kp, ")");
+ len = snprintf(kp, ks - (kp - key), ")");
+ assert( len >= 0 && len < ks - (kp - key) );
+ kp += len;
+ if ( uri->filter && uri->filter->bv_len ) {
+ len = snprintf (kp, ks - (kp - key), ")");
+ assert( len >= 0 && len < ks - (kp - key) );
+ kp += len;
+ }
rc = unique_search ( op,
&nop,