static int fp_parse_line(ConfigArgs *c);
static char *strtok_quote(char *line, char *sep, char **quote_ptr);
+static char *strtok_quote_ldif(char **line);
ConfigArgs *
new_config_args( BackendDB *be, const char *fname, int lineno, int argc, char **argv )
return(ARG_BAD_CONF);
}
if(Conf->max_args && (c->argc > Conf->max_args)) {
- sprintf( c->msg, "<%s> extra cruft after <%s> ignored",
+ char *ignored = " ignored";
+
+ sprintf( c->msg, "<%s> extra cruft after <%s>",
c->argv[0], Conf->what );
- Debug(LDAP_DEBUG_CONFIG, "%s: %s\n", c->log, c->msg, 0 );
+
+#ifdef LDAP_DEVEL
+ ignored = "";
+#endif /* LDAP_DEVEL */
+ Debug(LDAP_DEBUG_CONFIG, "%s: %s%s.\n",
+ c->log, c->msg, ignored );
+#ifdef LDAP_DEVEL
+ return(ARG_BAD_CONF);
+#endif /* LDAP_DEVEL */
}
if((arg_type & ARG_DB) && !c->be) {
sprintf( c->msg, "<%s> only allowed within database declaration",
int j;
iarg = 0; larg = 0; barg = 0;
switch(arg_type & ARGS_NUMERIC) {
- case ARG_INT: iarg = atoi(c->argv[1]); break;
+ case ARG_INT: iarg = strtol(c->argv[1], NULL, 0); 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_ON_OFF:
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;
}
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;
return 0;
}
+/* Split an LDIF line into space-separated tokens. Words may be grouped
+ * by quotes. A quoted string may begin in the middle of a word, but must
+ * end at the end of the word (be followed by whitespace or EOS). Any other
+ * quotes are passed through unchanged. All other characters are passed
+ * through unchanged.
+ */
+static char *
+strtok_quote_ldif( char **line )
+{
+ char *beg, *ptr, *quote=NULL;
+ int inquote=0;
+
+ ptr = *line;
+
+ if ( !ptr || !*ptr )
+ return NULL;
+
+ while( isspace( *ptr )) ptr++;
+
+ if ( *ptr == '"' ) {
+ inquote = 1;
+ ptr++;
+ }
+
+ beg = ptr;
+
+ for (;*ptr;ptr++) {
+ if ( *ptr == '"' ) {
+ if ( inquote && ( !ptr[1] || isspace(ptr[1]))) {
+ *ptr++ = '\0';
+ break;
+ }
+ inquote = 1;
+ quote = ptr;
+ continue;
+ }
+ if ( inquote )
+ continue;
+ if ( isspace( *ptr )) {
+ *ptr++ = '\0';
+ break;
+ }
+ }
+ if ( quote ) {
+ while ( quote < ptr ) {
+ *quote = quote[1];
+ quote++;
+ }
+ }
+ if ( !*ptr ) {
+ *line = NULL;
+ } else {
+ while ( isspace( *ptr )) ptr++;
+ *line = ptr;
+ }
+ return beg;
+}
+
+static void
+config_parse_ldif( ConfigArgs *c )
+{
+ char *next;
+ c->tline = ch_strdup(c->line);
+ next = c->tline;
+
+ while ((c->argv[c->argc] = strtok_quote_ldif( &next )) != NULL) {
+ c->argc++;
+ if ( c->argc >= c->argv_size ) {
+ char **tmp = ch_realloc( c->argv, (c->argv_size + ARGS_STEP) *
+ sizeof( *c->argv ));
+ c->argv = tmp;
+ c->argv_size += ARGS_STEP;
+ }
+ }
+ c->argv[c->argc] = NULL;
+}
+
int
config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx)
{
int rc = 0;
- char *saveline = NULL;
snprintf( c->log, sizeof( c->log ), "%s: value #%d",
ct->ad->ad_cname.bv_val, valx );
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;
+ c->argv[c->argc] = c->line;
+ c->argc++;
+ c->argv[c->argc] = NULL;
+ c->tline = NULL;
} else {
- rc = config_check_vals( ct, c, 1 );
- }
-
- if ( saveline ) {
- ch_free( c->line );
- c->line = saveline;
+ config_parse_ldif( c );
}
+ rc = config_check_vals( ct, c, 1 );
+ ch_free( c->tline );
if ( rc )
rc = LDAP_CONSTRAINT_VIOLATION;
- ch_free( c->tline );
return rc;
}
config_parse_add(ConfigTable *ct, ConfigArgs *c)
{
int rc = 0;
- char *saveline = NULL;
snprintf( c->log, sizeof( c->log ), "%s: value #%d",
ct->ad->ad_cname.bv_val, c->valx );
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;
+ c->argv[c->argc] = c->line;
+ c->argc++;
+ c->argv[c->argc] = NULL;
+ c->tline = NULL;
} else {
- c->op = LDAP_MOD_ADD;
- rc = config_add_vals( ct, c );
+ config_parse_ldif( c );
}
-
- if ( saveline ) {
- ch_free( c->line );
- c->line = saveline;
- }
-
+ c->op = LDAP_MOD_ADD;
+ rc = config_add_vals( ct, c );
ch_free( c->tline );
+
return rc;
}
ch_free( c->tline );
if ( fp_parse_line( c ) ) {
rc = 1;
- goto leave;
+ goto done;
}
if ( c->argc < 1 ) {
c->log, 0, 0);
#ifdef SLAPD_CONF_UNKNOWN_BAILOUT
rc = 1;
- goto leave;
+ goto done;
#else /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
continue;
#endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
Debug(LDAP_DEBUG_CONFIG, "%s: unknown user type <%s>\n",
c->log, c->argv[0], 0);
rc = 1;
- goto leave;
+ goto done;
} else if ( rc == ARG_BAD_CONF ) {
rc = 1;
- goto leave;
+ goto done;
}
} else if ( c->bi && !c->be ) {
#endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
default:
rc = 1;
- goto leave;
+ goto done;
}
}
#endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
default:
rc = 1;
- goto leave;
+ goto done;
}
}
#endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
default:
rc = 1;
- goto leave;
+ goto done;
}
}
c->log, *c->argv, 0);
#ifdef SLAPD_CONF_UNKNOWN_BAILOUT
rc = 1;
- goto leave;
+ goto done;
#else /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
continue;
#endif /* ! SLAPD_CONF_UNKNOWN_BAILOUT */
rc = 0;
-leave:
+done:
ch_free(c->tline);
fclose(fp);
ch_free(c->argv);
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 LDAP_OPERATIONS_ERROR;
+ }
+
+ 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 LDAP_SUCCESS;
+ }
+ /* conflicts */
+ return LDAP_TYPE_OR_VALUE_EXISTS;
+ }
+
+ if ( m & (*vp)[ i ].mask ) {
+ /* conflicts */
+ return LDAP_CONSTRAINT_VIOLATION;
+ }
+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 LDAP_SUCCESS;
+}
+
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++ ) {