#include "ldap_pvt.h"
#include "slap.h"
-#define MAXARGS 500
+#define ARGS_STEP 512
/*
* defaults for various global variables
char *global_realm = NULL;
char *ldap_srvtab = "";
char *default_passwd_hash = NULL;
+int cargc = 0, cargv_size = 0;
+char **cargv;
struct berval default_search_base = { 0, NULL };
struct berval default_search_nbase = { 0, NULL };
unsigned num_subordinates = 0;
static char *fp_getline(FILE *fp, int *lineno);
static void fp_getline_init(int *lineno);
-static int fp_parse_line(int lineno, char *line, int *argcp, char **argv);
+static int fp_parse_line(int lineno, char *line);
static char *strtok_quote(char *line, char *sep);
static int load_ucdata(char *path);
{
FILE *fp;
char *line, *savefname, *saveline;
- int cargc, savelineno;
- char *cargv[MAXARGS+1];
+ int savelineno;
int lineno, i;
int rc;
struct berval vals[2];
vals[1].bv_val = NULL;
+ cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) );
+ cargv_size = ARGS_STEP + 1;
+
if ( (fp = fopen( fname, "r" )) == NULL ) {
ldap_syslog = 1;
#ifdef NEW_LOGGING
/* fp_parse_line is destructive, we save a copy */
saveline = ch_strdup( line );
- if ( fp_parse_line( lineno, line, &cargc, cargv ) != 0 ) {
+ if ( fp_parse_line( lineno, line ) != 0 ) {
return( 1 );
}
static int
fp_parse_line(
int lineno,
- char *line,
- int *argcp,
- char **argv
+ char *line
)
{
char * token;
char * logline;
char logbuf[sizeof("pseudorootpw ***")];
- *argcp = 0;
+ cargc = 0;
token = strtok_quote( line, " \t" );
logline = line;
*strtok_quote_ptr = '\0';
for ( ; token != NULL; token = strtok_quote( NULL, " \t" ) ) {
- if ( *argcp == MAXARGS ) {
+ if ( cargc == cargv_size - 1 ) {
+ char **tmp;
+ tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
+ sizeof(*cargv) );
+ if ( tmp == NULL ) {
#ifdef NEW_LOGGING
- LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
- "fp_parse_line: too many tokens (%d max).\n",
- MAXARGS ));
+ LDAP_LOG(( "config", LDAP_LEVEL_ERR,
+ "line %d: out of memory\n",
+ lineno ));
#else
- Debug( LDAP_DEBUG_ANY, "Too many tokens (max %d)\n",
- MAXARGS, 0, 0 );
+ Debug( LDAP_DEBUG_ANY,
+ "line %d: out of memory\n",
+ lineno, 0, 0 );
#endif
-
- return( 1 );
+ return -1;
+ }
+ cargv = tmp;
+ cargv_size += ARGS_STEP;
}
- argv[(*argcp)++] = token;
+ cargv[cargc++] = token;
}
- argv[*argcp] = NULL;
+ cargv[cargc] = NULL;
return 0;
}
#include "slurp.h"
#include "globals.h"
-#define MAXARGS 500
+#define ARGS_STEP 512
/* Forward declarations */
static void add_replica LDAP_P(( char **, int ));
static int parse_replica_line LDAP_P(( char **, int, Ri *));
-static void parse_line LDAP_P(( char *, int *, char ** ));
+static void parse_line LDAP_P(( char * ));
static char *getline LDAP_P(( FILE * ));
static char *strtok_quote LDAP_P(( char *, char * ));
+int cargc = 0, cargv_size = 0;
+char **cargv;
/* current config file line # */
static int lineno;
{
FILE *fp;
char *line;
- int cargc;
- char *cargv[MAXARGS];
+
+ cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) );
+ cargv_size = ARGS_STEP + 1;
#ifdef NEW_LOGGING
LDAP_LOG (( "config", LDAP_LEVEL_ARGS,
Debug( LDAP_DEBUG_CONFIG, "Config: (%s)\n", line, 0, 0 );
#endif
- parse_line( line, &cargc, cargv );
+ parse_line( line );
if ( cargc < 1 ) {
fprintf( stderr, "line %d: bad config line (ignored)\n", lineno );
*/
static void
parse_line(
- char *line,
- int *argcp,
- char **argv
+ char *line
)
{
char * token;
- *argcp = 0;
+ cargc = 0;
for ( token = strtok_quote( line, " \t" ); token != NULL;
- token = strtok_quote( NULL, " \t" ) ) {
- argv[(*argcp)++] = token;
+ token = strtok_quote( NULL, " \t" ) )
+ {
+ if ( cargc == cargv_size - 1 ) {
+ char **tmp;
+ tmp = ch_realloc( cargv, (cargv_size + ARGS_STEP) *
+ sizeof(*cargv) );
+ if (tmp == NULL) {
+ cargc = 0;
+ return;
+ }
+ cargv = tmp;
+ cargv_size += ARGS_STEP;
+ }
+
+ cargv[cargc++] = token;
}
- argv[*argcp] = NULL;
+ cargv[cargc] = NULL;
}