/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * 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
c->argv[1] = "";
}
if(Conf->min_args && (c->argc < Conf->min_args)) {
- sprintf( c->msg, "<%s> missing <%s> argument",
+ snprintf( c->msg, sizeof( c->msg ), "<%s> missing <%s> argument",
c->argv[0], Conf->what );
Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n", c->log, c->msg, 0 );
return(ARG_BAD_CONF);
if(Conf->max_args && (c->argc > Conf->max_args)) {
char *ignored = " ignored";
- sprintf( c->msg, "<%s> extra cruft after <%s>",
+ snprintf( c->msg, sizeof( c->msg ), "<%s> extra cruft after <%s>",
c->argv[0], Conf->what );
#ifdef LDAP_DEVEL
#endif /* LDAP_DEVEL */
}
if((arg_type & ARG_DB) && !c->be) {
- sprintf( c->msg, "<%s> only allowed within database declaration",
+ snprintf( c->msg, sizeof( c->msg ), "<%s> only allowed within database declaration",
c->argv[0] );
Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
c->log, c->msg, 0);
return(ARG_BAD_CONF);
}
if((arg_type & ARG_PRE_BI) && c->bi) {
- sprintf( c->msg, "<%s> must occur before any backend %sdeclaration",
+ snprintf( c->msg, sizeof( c->msg ), "<%s> must occur before any backend %sdeclaration",
c->argv[0], (arg_type & ARG_PRE_DB) ? "or database " : "" );
Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
c->log, c->msg, 0 );
return(ARG_BAD_CONF);
}
if((arg_type & ARG_PRE_DB) && c->be && c->be != frontendDB) {
- sprintf( c->msg, "<%s> must occur before any database declaration",
+ snprintf( c->msg, sizeof( c->msg ), "<%s> must occur before any database declaration",
c->argv[0] );
Debug(LDAP_DEBUG_CONFIG, "%s: keyword %s\n",
c->log, c->msg, 0);
return(ARG_BAD_CONF);
}
if((arg_type & ARG_PAREN) && *c->argv[1] != '(' /*')'*/) {
- sprintf( c->msg, "<%s> old format not supported", c->argv[0] );
+ snprintf( c->msg, sizeof( c->msg ), "<%s> old format not supported", c->argv[0] );
Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
c->log, c->msg, 0);
return(ARG_BAD_CONF);
}
if((arg_type & ARGS_POINTER) && !Conf->arg_item && !(arg_type & ARG_OFFSET)) {
- sprintf( c->msg, "<%s> invalid config_table, arg_item is NULL",
+ snprintf( c->msg, sizeof( c->msg ), "<%s> invalid config_table, arg_item is NULL",
c->argv[0] );
Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
c->log, c->msg, 0);
int j;
iarg = 0; larg = 0; barg = 0;
switch(arg_type & ARGS_NUMERIC) {
- case ARG_INT: iarg = atoi(c->argv[1]); break;
- case ARG_LONG: larg = strtol(c->argv[1], NULL, 0); break;
- case ARG_BER_LEN_T: barg = (ber_len_t)atol(c->argv[1]); break;
+ case ARG_INT:
+ if ( lutil_atoix( &iarg, c->argv[1], 0 ) != 0 ) {
+ snprintf( c->msg, sizeof( c->msg ),
+ "<%s> unable to parse \"%s\" as int",
+ c->argv[0], c->argv[1] );
+ Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
+ c->log, c->msg, 0);
+ return(ARG_BAD_CONF);
+ }
+ break;
+ case ARG_LONG:
+ if ( lutil_atolx( &larg, c->argv[1], 0 ) != 0 ) {
+ snprintf( c->msg, sizeof( c->msg ),
+ "<%s> unable to parse \"%s\" as long",
+ c->argv[0], c->argv[1] );
+ Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
+ c->log, c->msg, 0);
+ return(ARG_BAD_CONF);
+ }
+ break;
+ case ARG_BER_LEN_T: {
+ unsigned long l;
+ if ( lutil_atoulx( &l, c->argv[1], 0 ) != 0 ) {
+ snprintf( c->msg, sizeof( c->msg ),
+ "<%s> unable to parse \"%s\" as ber_len_t",
+ c->argv[0], c->argv[1] );
+ Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
+ c->log, c->msg, 0);
+ return(ARG_BAD_CONF);
+ }
+ barg = (ber_len_t)l;
+ } break;
case ARG_ON_OFF:
- if(c->argc == 1) {
+ if (c->argc == 1) {
iarg = 1;
- } else if(!strcasecmp(c->argv[1], "on") ||
- !strcasecmp(c->argv[1], "true")) {
+ } else if ( !strcasecmp(c->argv[1], "on") ||
+ !strcasecmp(c->argv[1], "true") ||
+ !strcasecmp(c->argv[1], "yes") )
+ {
iarg = 1;
- } else if(!strcasecmp(c->argv[1], "off") ||
- !strcasecmp(c->argv[1], "false")) {
+ } else if ( !strcasecmp(c->argv[1], "off") ||
+ !strcasecmp(c->argv[1], "false") ||
+ !strcasecmp(c->argv[1], "no") )
+ {
iarg = 0;
} else {
- sprintf( c->msg, "<%s> invalid value, ignored",
+ snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value",
c->argv[0] );
- Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
+ Debug(LDAP_DEBUG_ANY, "%s: %s\n",
c->log, c->msg, 0 );
- return(0);
+ return(ARG_BAD_CONF);
}
break;
}
j = (arg_type & ARG_NONZERO) ? 1 : 0;
if(iarg < j && larg < j && barg < j ) {
larg = larg ? larg : (barg ? barg : iarg);
- sprintf( c->msg, "<%s> invalid value, ignored",
+ snprintf( c->msg, sizeof( c->msg ), "<%s> invalid value",
c->argv[0] );
- Debug(LDAP_DEBUG_CONFIG, "%s: %s\n",
+ Debug(LDAP_DEBUG_ANY, "%s: %s\n",
c->log, c->msg, 0 );
return(ARG_BAD_CONF);
}
ber_str2bv( c->argv[1], 0, 0, &bv );
rc = dnPrettyNormal( NULL, &bv, &c->value_dn, &c->value_ndn, NULL );
if ( rc != LDAP_SUCCESS ) {
- sprintf( c->msg, "<%s> invalid DN %d (%s)",
+ snprintf( c->msg, sizeof( c->msg ), "<%s> invalid DN %d (%s)",
c->argv[0], rc, ldap_err2string( rc ));
Debug(LDAP_DEBUG_CONFIG, "%s: %s\n" , c->log, c->msg, 0);
return(ARG_BAD_CONF);
#endif
if(rc) {
if ( !c->msg[0] ) {
- sprintf( c->msg, "<%s> handler exited with %d",
+ snprintf( c->msg, sizeof( c->msg ), "<%s> handler exited with %d",
c->argv[0], rc );
Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
c->log, c->msg, 0 );
else if (c->bi)
ptr = c->bi->bi_private;
else {
- sprintf( c->msg, "<%s> offset is missing base pointer",
+ snprintf( c->msg, sizeof( c->msg ), "<%s> offset is missing base pointer",
c->argv[0] );
Debug(LDAP_DEBUG_CONFIG, "%s: %s!\n",
c->log, c->msg, 0);
return(ARG_BAD_CONF);
}
- ptr = (void *)((char *)ptr + (int)Conf->arg_item);
+ ptr = (void *)((char *)ptr + (long)Conf->arg_item);
} else if (arg_type & ARGS_POINTER) {
ptr = Conf->arg_item;
}
ptr = c->bi->bi_private;
else
return 1;
- ptr = (void *)((char *)ptr + (int)cf->arg_item);
+ ptr = (void *)((char *)ptr + (long)cf->arg_item);
} else {
ptr = cf->arg_item;
}
if ( cf->arg_type & ARGS_POINTER) {
bv.bv_val = c->log;
switch(cf->arg_type & ARGS_POINTER) {
- case ARG_INT: bv.bv_len = sprintf(bv.bv_val, "%d", c->value_int); break;
- case ARG_LONG: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_long); break;
- case ARG_BER_LEN_T: bv.bv_len = sprintf(bv.bv_val, "%ld", c->value_ber_t); break;
- case ARG_ON_OFF: bv.bv_len = sprintf(bv.bv_val, "%s",
+ case ARG_INT: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%d", c->value_int); break;
+ case ARG_LONG: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%ld", c->value_long); break;
+ case ARG_BER_LEN_T: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%ld", c->value_ber_t); break;
+ case ARG_ON_OFF: bv.bv_len = snprintf(bv.bv_val, sizeof( c->log ), "%s",
c->value_int ? "TRUE" : "FALSE"); break;
case ARG_STRING:
if ( c->value_string && c->value_string[0]) {
}
break;
}
+ if (bv.bv_val == c->log && bv.bv_len >= sizeof( c->log ) ) {
+ return 1;
+ }
if (( cf->arg_type & ARGS_POINTER ) == ARG_STRING )
ber_bvarray_add(&c->rvalue_vals, &bv);
else
freeit = 1;
} else {
+ ldap_attributetype_free( at );
fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
ct[i].attribute, scherr2str(code), err );
return code;
}
rc = config_check_vals( ct, c, 1 );
ch_free( c->tline );
+ c->tline = NULL;
if ( rc )
rc = LDAP_CONSTRAINT_VIOLATION;
}
if ( c->argc < 1 ) {
- Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: bad config line"
- SLAPD_CONF_UNKNOWN_IGNORED ".\n",
+ Debug( LDAP_DEBUG_ANY, "%s: bad config line.\n",
c->log, 0, 0);
-#ifdef SLAPD_CONF_UNKNOWN_BAILOUT
rc = 1;
goto done;
-#else /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
- continue;
-#endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
}
c->op = SLAP_CONFIG_ADD;
if ( rc ) {
switch(rc) {
case SLAP_CONF_UNKNOWN:
- Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
- "unknown directive <%s> inside backend info definition"
- SLAPD_CONF_UNKNOWN_IGNORED ".\n",
+ Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
+ "<%s> inside backend info definition.\n",
c->log, *c->argv, 0);
-#ifndef SLAPD_CONF_UNKNOWN_BAILOUT
- continue;
-#endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
default:
rc = 1;
goto done;
}
}
- } else if ( c->be ) {
+ } else if ( c->be && c->be != frontendDB ) {
rc = SLAP_CONF_UNKNOWN;
if ( c->be->be_cf_ocs ) {
ct = config_find_keyword( c->be->be_cf_ocs->co_table, c );
rc = (*c->be->be_config)(c->be, c->fname, c->lineno,
c->argc, c->argv);
}
- if ( rc ) {
- switch(rc) {
- case SLAP_CONF_UNKNOWN:
- Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
- "unknown directive <%s> inside backend database "
- "definition" SLAPD_CONF_UNKNOWN_IGNORED ".\n",
- c->log, *c->argv, 0);
-#ifndef SLAPD_CONF_UNKNOWN_BAILOUT
- continue;
-#endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
- default:
- rc = 1;
- goto done;
- }
+ if ( rc == SLAP_CONF_UNKNOWN && SLAP_ISGLOBALOVERLAY( frontendDB ) )
+ {
+ /* global overlays may need
+ * definitions inside other databases...
+ */
+ rc = (*frontendDB->be_config)( frontendDB,
+ c->fname, (int)c->lineno, c->argc, c->argv );
+ }
+
+ switch ( rc ) {
+ case 0:
+ break;
+
+ case SLAP_CONF_UNKNOWN:
+ Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
+ "<%s> inside backend database definition.\n",
+ c->log, *c->argv, 0);
+
+ default:
+ rc = 1;
+ goto done;
}
} else if ( frontendDB->be_config ) {
- rc = (*frontendDB->be_config)(frontendDB, c->fname, (int)c->lineno, c->argc, c->argv);
+ rc = (*frontendDB->be_config)( frontendDB,
+ c->fname, (int)c->lineno, c->argc, c->argv);
if ( rc ) {
switch(rc) {
case SLAP_CONF_UNKNOWN:
- Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
- "unknown directive <%s> inside global database definition"
- SLAPD_CONF_UNKNOWN_IGNORED ".\n",
+ Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
+ "<%s> inside global database definition.\n",
c->log, *c->argv, 0);
-#ifndef SLAPD_CONF_UNKNOWN_BAILOUT
- continue;
-#endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
+
default:
rc = 1;
goto done;
}
} else {
- Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: "
- "unknown directive <%s> outside backend info and database definitions"
- SLAPD_CONF_UNKNOWN_IGNORED ".\n",
+ Debug( LDAP_DEBUG_ANY, "%s: unknown directive "
+ "<%s> outside backend info and database definitions.\n",
c->log, *c->argv, 0);
-#ifdef SLAPD_CONF_UNKNOWN_BAILOUT
rc = 1;
goto done;
-#else /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
- continue;
-#endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
}
}
int
verb_to_mask(const char *word, slap_verbmasks *v) {
int i;
- for(i = 0; !BER_BVISNULL(&v[i].word); i++)
- if(!strcasecmp(word, v[i].word.bv_val))
- break;
+ for(i = 0; !BER_BVISNULL(&v[i].word); i++) {
+ if(!strcasecmp(word, v[i].word.bv_val)) break;
+ }
return(i);
}
int i, j;
for(i = 1; i < argc; i++) {
j = verb_to_mask(argv[i], v);
- if(BER_BVISNULL(&v[j].word)) return(1);
+ if(BER_BVISNULL(&v[j].word)) return i;
while (!v[j].mask) j--;
*m |= v[j].mask;
}
*/
int
mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
- int i;
-
- if (!m) return 1;
- for (i=0; !BER_BVISNULL(&v[i].word); i++) {
- if (!v[i].mask) continue;
- if (( m & v[i].mask ) == v[i].mask ) {
- value_add_one( bva, &v[i].word );
- m ^= v[i].mask;
- if ( !m ) break;
+ int i, rc = 1;
+
+ if (m) {
+ for (i=0; !BER_BVISNULL(&v[i].word); i++) {
+ if (!v[i].mask) continue;
+ if (( m & v[i].mask ) == v[i].mask ) {
+ value_add_one( bva, &v[i].word );
+ rc = 0;
+ m ^= v[i].mask;
+ if ( !m ) break;
+ }
}
}
- return 0;
+ return rc;
}
int
assert( *vp == NULL );
- for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ )
- ;
+ for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) /* EMPTY */;
*vp = ch_calloc( i + 1, sizeof( slap_verbmasks ) );
{ BER_BVNULL, 0 }
};
-typedef struct cf_aux_table {
- struct berval key;
- int off;
- char type;
- char quote;
- slap_verbmasks *aux;
-} cf_aux_table;
-
-static cf_aux_table bindkey[] = {
+static slap_cf_aux_table bindkey[] = {
+ { BER_BVC("uri="), offsetof(slap_bindconf, sb_uri), 'b', 1, NULL },
{ BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'd', 0, tlskey },
{ BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'd', 0, methkey },
{ BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, NULL },
{ BER_BVNULL, 0, 0, 0, NULL }
};
-int bindconf_parse( const char *word, slap_bindconf *bc ) {
+int
+slap_cf_aux_table_parse( const char *word, void *dst, slap_cf_aux_table *tab0, LDAP_CONST char *tabmsg )
+{
int rc = 0;
- cf_aux_table *tab;
+ slap_cf_aux_table *tab;
- for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
+ for (tab = tab0; !BER_BVISNULL(&tab->key); tab++ ) {
if ( !strncasecmp( word, tab->key.bv_val, tab->key.bv_len )) {
char **cptr;
int *iptr, j;
+ unsigned *uptr;
+ long *lptr;
+ unsigned long *ulptr;
struct berval *bptr;
const char *val = word + tab->key.bv_len;
switch ( tab->type ) {
case 's':
- cptr = (char **)((char *)bc + tab->off);
+ cptr = (char **)((char *)dst + tab->off);
*cptr = ch_strdup( val );
break;
case 'b':
- bptr = (struct berval *)((char *)bc + tab->off);
+ bptr = (struct berval *)((char *)dst + tab->off);
ber_str2bv( val, 0, 1, bptr );
break;
case 'd':
assert( tab->aux != NULL );
- iptr = (int *)((char *)bc + tab->off);
+ iptr = (int *)((char *)dst + tab->off);
rc = 1;
for ( j = 0; !BER_BVISNULL( &tab->aux[j].word ); j++ ) {
}
}
break;
+
+ case 'i':
+ iptr = (int *)((char *)dst + tab->off);
+
+ rc = lutil_atoix( iptr, val, 0 );
+ break;
+
+ case 'u':
+ uptr = (unsigned *)((char *)dst + tab->off);
+
+ rc = lutil_atoux( uptr, val, 0 );
+ break;
+
+ case 'I':
+ lptr = (long *)((char *)dst + tab->off);
+
+ rc = lutil_atolx( lptr, val, 0 );
+ break;
+
+ case 'U':
+ ulptr = (unsigned long *)((char *)dst + tab->off);
+
+ rc = lutil_atoulx( ulptr, val, 0 );
+ break;
}
if ( rc ) {
- Debug( LDAP_DEBUG_ANY, "invalid bind config value %s\n",
- word, 0, 0 );
+ Debug( LDAP_DEBUG_ANY, "invalid %s value %s\n",
+ tabmsg, word, 0 );
}
return rc;
return rc;
}
-int bindconf_unparse( slap_bindconf *bc, struct berval *bv ) {
+int
+slap_cf_aux_table_unparse( void *src, struct berval *bv, slap_cf_aux_table *tab0 )
+{
char buf[BUFSIZ], *ptr;
- cf_aux_table *tab;
+ slap_cf_aux_table *tab;
struct berval tmp;
ptr = buf;
- for (tab = bindkey; !BER_BVISNULL(&tab->key); tab++) {
+ for (tab = tab0; !BER_BVISNULL(&tab->key); tab++ ) {
char **cptr;
int *iptr, i;
+ unsigned *uptr;
+ long *lptr;
+ unsigned long *ulptr;
struct berval *bptr;
- cptr = (char **)((char *)bc + tab->off);
+ cptr = (char **)((char *)src + tab->off);
switch ( tab->type ) {
case 'b':
- bptr = (struct berval *)((char *)bc + tab->off);
+ bptr = (struct berval *)((char *)src + tab->off);
cptr = &bptr->bv_val;
case 's':
if ( *cptr ) {
case 'd':
assert( tab->aux != NULL );
- iptr = (int *)((char *)bc + tab->off);
+ iptr = (int *)((char *)src + tab->off);
for ( i = 0; !BER_BVISNULL( &tab->aux[i].word ); i++ ) {
if ( *iptr == tab->aux[i].mask ) {
}
}
break;
+
+ case 'i':
+ iptr = (int *)((char *)src + tab->off);
+ *ptr++ = ' ';
+ ptr = lutil_strcopy( ptr, tab->key.bv_val );
+ ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%d", *iptr );
+ break;
+
+ case 'u':
+ uptr = (unsigned *)((char *)src + tab->off);
+ *ptr++ = ' ';
+ ptr = lutil_strcopy( ptr, tab->key.bv_val );
+ ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%u", *uptr );
+ break;
+
+ case 'I':
+ lptr = (long *)((char *)src + tab->off);
+ *ptr++ = ' ';
+ ptr = lutil_strcopy( ptr, tab->key.bv_val );
+ ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%ld", *lptr );
+ break;
+
+ case 'U':
+ ulptr = (unsigned long *)((char *)src + tab->off);
+ *ptr++ = ' ';
+ ptr = lutil_strcopy( ptr, tab->key.bv_val );
+ ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ), "%lu", *ulptr );
+ break;
+
+ default:
+ assert( 0 );
}
}
tmp.bv_val = buf;
return 0;
}
+int
+bindconf_parse( const char *word, slap_bindconf *bc )
+{
+ return slap_cf_aux_table_parse( word, bc, bindkey, "bind config" );
+}
+
+int
+bindconf_unparse( slap_bindconf *bc, struct berval *bv )
+{
+ return slap_cf_aux_table_unparse( bc, bv, bindkey );
+}
+
void bindconf_free( slap_bindconf *bc ) {
+ if ( !BER_BVISNULL( &bc->sb_uri ) ) {
+ ch_free( bc->sb_uri.bv_val );
+ BER_BVZERO( &bc->sb_uri );
+ }
if ( !BER_BVISNULL( &bc->sb_binddn ) ) {
ch_free( bc->sb_binddn.bv_val );
BER_BVZERO( &bc->sb_binddn );
c.argc = argc;
c.argv = argv;
c.valx = -1;
- sprintf( c.log, "%s: line %d", fname, lineno );
+ snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
rc = SLAP_CONF_UNKNOWN;
ct = config_find_keyword( be->be_cf_ocs->co_table, &c );