fix config emit (ITS#6986)

This commit is contained in:
Pierangelo Masarati 2011-07-07 08:14:14 +02:00
parent c02e681121
commit c0b669e14f

View file

@ -145,6 +145,8 @@ constraint_cf_gen( ConfigArgs *c )
char *tstr = NULL; char *tstr = NULL;
int quotes = 0; int quotes = 0;
int j; int j;
size_t val;
char val_buf[SLAP_TEXT_BUFLEN] = { '\0' };
bv.bv_len = STRLENOF(" "); bv.bv_len = STRLENOF(" ");
for (j = 0; cp->ap[j]; j++) { for (j = 0; cp->ap[j]; j++) {
@ -156,6 +158,7 @@ constraint_cf_gen( ConfigArgs *c )
if (cp->re) { if (cp->re) {
tstr = REGEX_STR; tstr = REGEX_STR;
quotes = 1;
} else if (cp->lud) { } else if (cp->lud) {
tstr = URI_STR; tstr = URI_STR;
quotes = 1; quotes = 1;
@ -164,8 +167,10 @@ constraint_cf_gen( ConfigArgs *c )
quotes = 1; quotes = 1;
} else if (cp->size) { } else if (cp->size) {
tstr = SIZE_STR; tstr = SIZE_STR;
val = cp->size;
} else if (cp->count) { } else if (cp->count) {
tstr = COUNT_STR; tstr = COUNT_STR;
val = cp->count;
} }
bv.bv_len += strlen(tstr); bv.bv_len += strlen(tstr);
@ -175,6 +180,15 @@ constraint_cf_gen( ConfigArgs *c )
bv.bv_len += cp->restrict_val.bv_len + STRLENOF(" restrict=\"\""); bv.bv_len += cp->restrict_val.bv_len + STRLENOF(" restrict=\"\"");
} }
if (cp->count || cp->size) {
int len = snprintf(val_buf, sizeof(val_buf), "%d", val);
if (len <= 0) {
/* error */
return -1;
}
bv.bv_len += len;
}
s = bv.bv_val = ch_malloc(bv.bv_len + 1); 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 ); s = lutil_strncopy( s, cp->ap[0]->ad_cname.bv_val, cp->ap[0]->ad_cname.bv_len );
@ -185,9 +199,13 @@ constraint_cf_gen( ConfigArgs *c )
*s++ = ' '; *s++ = ' ';
s = lutil_strcopy( s, tstr ); s = lutil_strcopy( s, tstr );
*s++ = ' '; *s++ = ' ';
if ( quotes ) *s++ = '"'; if (cp->count || cp->size) {
s = lutil_strncopy( s, cp->val.bv_val, cp->val.bv_len ); s = lutil_strcopy( s, val_buf );
if ( quotes ) *s++ = '"'; } else {
if ( quotes ) *s++ = '"';
s = lutil_strncopy( s, cp->val.bv_val, cp->val.bv_len );
if ( quotes ) *s++ = '"';
}
if (cp->restrict_lud != NULL) { if (cp->restrict_lud != NULL) {
s = lutil_strcopy( s, " restrict=\"" ); s = lutil_strcopy( s, " restrict=\"" );
s = lutil_strncopy( s, cp->restrict_val.bv_val, cp->restrict_val.bv_len ); s = lutil_strncopy( s, cp->restrict_val.bv_val, cp->restrict_val.bv_len );
@ -471,7 +489,7 @@ constraint_cf_gen( ConfigArgs *c )
} }
} }
ber_str2bv(c->argv[argidx], 0, 1, &ap.restrict_val); ber_str2bv(c->argv[argidx] + STRLENOF("restrict="), 0, 1, &ap.restrict_val);
} else { } else {
/* cleanup */ /* cleanup */