#include <ac/socket.h>
#include <ac/errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
#include "slap.h"
#ifdef LDAP_SLAPI
#include "slapi/slapi.h"
static char *strtok_quote(char *line, char *sep, char **quote_ptr);
-int read_config_file(const char *fname, int depth, ConfigArgs *cf,
- ConfigTable *cft );
-
ConfigArgs *
new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
{
c->argc = argc;
c->argv = argv;
c->lineno = lineno;
- snprintf( c->log, sizeof( c->log ), "%s: line %lu", fname, lineno );
+ snprintf( c->log, sizeof( c->log ), "%s: line %d", fname, lineno );
return(c);
}
int config_set_vals(ConfigTable *Conf, ConfigArgs *c) {
int rc, arg_type;
- void *ptr;
+ void *ptr = NULL;
arg_type = Conf->arg_type;
if(arg_type & ARG_MAGIC) {
const char *err;
for (i=0; ct[i].name; i++ ) {
+ int freeit = 0;
+
if ( !ct[i].attribute ) continue;
at = ldap_str2attributetype( ct[i].attribute,
&code, &err, LDAP_SCHEMA_ALLOW_ALL );
ct[i].attribute, ldap_scherr2str(code), err );
return code;
}
+
code = at_add( at, 0, NULL, &err );
- if ( code && code != SLAP_SCHERR_ATTR_DUP ) {
- fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
- ct[i].attribute, scherr2str(code), err );
- return code;
+ if ( code ) {
+ if ( code == SLAP_SCHERR_ATTR_DUP ) {
+ freeit = 1;
+
+ } else {
+ fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s, %s\n",
+ ct[i].attribute, scherr2str(code), err );
+ return code;
+ }
}
code = slap_str2ad( at->at_names[0], &ct[i].ad, &err );
+ if ( freeit ) {
+ ldap_attributetype_free( at );
+ } else {
+ ldap_memfree( at );
+ }
if ( code ) {
fprintf( stderr, "init_config_attrs: AttributeType \"%s\": %s\n",
ct[i].attribute, err );
return code;
}
- ldap_memfree( at );
}
return 0;
int
config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx)
{
- int rc = 0;
+ int rc = 0;
+ char *saveline = NULL;
snprintf( c->log, sizeof( c->log ), "%s: value #%d",
ct->ad->ad_cname.bv_val, valx );
c->argc = 1;
c->argv[0] = ct->ad->ad_cname.bv_val;
+
+ if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
+ ber_len_t len;
+
+ saveline = c->line;
+ len = strlen( c->line );
+ c->line = ch_malloc( len + STRLENOF( "\"\"" ) + 1 );
+ sprintf( c->line, "\"%s\"", saveline );
+ }
+
if ( fp_parse_line( c ) ) {
rc = 1;
} else {
rc = config_check_vals( ct, c, 1 );
}
+
+ if ( saveline ) {
+ ch_free( c->line );
+ c->line = saveline;
+ }
+
if ( rc )
rc = LDAP_CONSTRAINT_VIOLATION;
int
config_parse_add(ConfigTable *ct, ConfigArgs *c)
{
- int rc = 0;
+ int rc = 0;
+ char *saveline = NULL;
snprintf( c->log, sizeof( c->log ), "%s: value #%d",
ct->ad->ad_cname.bv_val, c->valx );
c->argc = 1;
c->argv[0] = ct->ad->ad_cname.bv_val;
+
+ if ( ( ct->arg_type & ARG_QUOTE ) && c->line[ 0 ] != '"' ) {
+ ber_len_t len;
+
+ saveline = c->line;
+ len = strlen( c->line );
+
+ c->line = ch_malloc( len + STRLENOF( "\"\"" ) + 1 );
+ sprintf( c->line, "\"%s\"", saveline );
+ }
+
if ( fp_parse_line( c ) ) {
rc = 1;
} else {
rc = config_add_vals( ct, c );
}
+ if ( saveline ) {
+ ch_free( c->line );
+ c->line = saveline;
+ }
+
ch_free( c->tline );
return rc;
}
ConfigTable *ct;
ConfigArgs *c;
int rc;
+ struct stat s;
c = ch_calloc( 1, sizeof( ConfigArgs ) );
if ( c == NULL ) {
c->fname = fname;
init_config_argv( c );
+ if ( stat( fname, &s ) != 0 ) {
+ ldap_syslog = 1;
+ Debug(LDAP_DEBUG_ANY,
+ "could not stat config file \"%s\": %s (%d)\n",
+ fname, strerror(errno), errno);
+ return(1);
+ }
+
+ if ( !S_ISREG( s.st_mode ) ) {
+ ldap_syslog = 1;
+ Debug(LDAP_DEBUG_ANY,
+ "regular file expected, got \"%s\"\n",
+ fname, 0, 0 );
+ return(1);
+ }
+
fp = fopen( fname, "r" );
if ( fp == NULL ) {
ldap_syslog = 1;
continue;
}
- snprintf( c->log, sizeof( c->log ), "%s: line %lu",
+ snprintf( c->log, sizeof( c->log ), "%s: line %d",
c->fname, c->lineno );
c->argc = 0;
}
}
- if ( BER_BVISNULL( &frontendDB->be_schemadn ) ) {
- ber_str2bv( SLAPD_SCHEMA_DN, STRLENOF( SLAPD_SCHEMA_DN ), 1,
- &frontendDB->be_schemadn );
- rc = dnNormalize( 0, NULL, NULL, &frontendDB->be_schemadn, &frontendDB->be_schemandn, NULL );
- if ( rc != LDAP_SUCCESS ) {
- Debug(LDAP_DEBUG_ANY, "%s: "
- "unable to normalize default schema DN \"%s\"\n",
- c->log, frontendDB->be_schemadn.bv_val, 0 );
- /* must not happen */
- assert( 0 );
- }
- }
rc = 0;
leave:
return(0);
}
+/* Mask keywords that represent multiple bits should occur before single
+ * bit keywords in the verbmasks array.
+ */
int
mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) {
int 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;
}
}
return 0;
}
+int
+slap_verbmasks_init( slap_verbmasks **vp, slap_verbmasks *v )
+{
+ int i;
+
+ assert( *vp == NULL );
+
+ for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ )
+ ;
+
+ *vp = ch_calloc( i + 1, sizeof( slap_verbmasks ) );
+
+ for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
+ ber_dupbv( &(*vp)[ i ].word, &v[ i ].word );
+ *((slap_mask_t *)&(*vp)[ i ].mask) = v[ i ].mask;
+ }
+
+ BER_BVZERO( &(*vp)[ i ].word );
+
+ return 0;
+}
+
+int
+slap_verbmasks_destroy( slap_verbmasks *v )
+{
+ int i;
+
+ assert( v != NULL );
+
+ for ( i = 0; !BER_BVISNULL( &v[ i ].word ); i++ ) {
+ ch_free( v[ i ].word.bv_val );
+ }
+
+ ch_free( v );
+
+ return 0;
+}
+
+int
+slap_verbmasks_append(
+ slap_verbmasks **vp,
+ slap_mask_t m,
+ struct berval *v,
+ slap_mask_t *ignore )
+{
+ int i;
+
+ if ( !m ) {
+ return 1;
+ }
+
+ for ( i = 0; !BER_BVISNULL( &(*vp)[ i ].word ); i++ ) {
+ if ( !(*vp)[ i ].mask ) continue;
+
+ if ( ignore != NULL ) {
+ int j;
+
+ for ( j = 0; ignore[ j ] != 0; j++ ) {
+ if ( (*vp)[ i ].mask == ignore[ j ] ) {
+ goto check_next;
+ }
+ }
+ }
+
+ if ( ( m & (*vp)[ i ].mask ) == (*vp)[ i ].mask ) {
+ if ( ber_bvstrcasecmp( v, &(*vp)[ i ].word ) == 0 ) {
+ /* already set; ignore */
+ return 0;
+ }
+ /* conflicts */
+ return 1;
+ }
+
+ if ( m & (*vp)[ i ].mask ) {
+ /* conflicts */
+ return 1;
+ }
+check_next:;
+ }
+
+ *vp = ch_realloc( *vp, sizeof( slap_verbmasks ) * ( i + 2 ) );
+ ber_dupbv( &(*vp)[ i ].word, v );
+ *((slap_mask_t *)&(*vp)[ i ].mask) = m;
+ BER_BVZERO( &(*vp)[ i + 1 ].word );
+
+ return 0;
+}
+
int
enum_to_verb(slap_verbmasks *v, slap_mask_t m, struct berval *bv) {
int i;
break;
case 'd':
- assert( tab->aux );
+ assert( tab->aux != NULL );
iptr = (int *)((char *)bc + tab->off);
rc = 1;
break;
case 'd':
- assert( tab->aux );
+ assert( tab->aux != NULL );
iptr = (int *)((char *)bc + tab->off);
for ( i = 0; !BER_BVISNULL( &tab->aux[i].word ); i++ ) {
fp_parse_line(ConfigArgs *c)
{
char *token;
- char *hide[] = { "rootpw", "replica", "bindpw", "pseudorootpw", "dbpasswd", '\0' };
+ static char *const hide[] = {
+ "rootpw", "replica", "syncrepl", /* in slapd */
+ "acl-bind", "acl-method", "idassert-bind", /* in back-ldap */
+ "acl-passwd", "bindpw", /* in back-<ldap/meta> */
+ "pseudorootpw", /* in back-meta */
+ "dbpasswd", /* in back-sql */
+ NULL
+ };
char *quote_ptr;
- int i;
+ int i = (int)(sizeof(hide)/sizeof(hide[0])) - 1;
c->tline = ch_strdup(c->line);
token = strtok_quote(c->tline, " \t", "e_ptr);
if(token) for(i = 0; hide[i]; i++) if(!strcasecmp(token, hide[i])) break;
if(quote_ptr) *quote_ptr = ' ';
- Debug(LDAP_DEBUG_CONFIG, "line %lu (%s%s)\n", c->lineno,
+ Debug(LDAP_DEBUG_CONFIG, "line %d (%s%s)\n", c->lineno,
hide[i] ? hide[i] : c->line, hide[i] ? " ***" : "");
if(quote_ptr) *quote_ptr = '\0';
- for(; token; token = strtok_quote(NULL, " \t", "e_ptr)) {
- if(c->argc == c->argv_size - 1) {
+ for(;; token = strtok_quote(NULL, " \t", "e_ptr)) {
+ if(c->argc >= c->argv_size) {
char **tmp;
tmp = ch_realloc(c->argv, (c->argv_size + ARGS_STEP) * sizeof(*c->argv));
if(!tmp) {
- Debug(LDAP_DEBUG_ANY, "line %lu: out of memory\n", c->lineno, 0, 0);
+ Debug(LDAP_DEBUG_ANY, "line %d: out of memory\n", c->lineno, 0, 0);
return -1;
}
c->argv = tmp;
c->argv_size += ARGS_STEP;
}
+ if(token == NULL)
+ break;
c->argv[c->argc++] = token;
}
c->argv[c->argc] = NULL;
c.argc = argc;
c.argv = argv;
c.valx = -1;
- sprintf( c.log, "%s: line %lu", fname, lineno );
+ sprintf( c.log, "%s: line %d", fname, lineno );
rc = SLAP_CONF_UNKNOWN;
ct = config_find_keyword( be->be_cf_ocs->co_table, &c );