#include "portable.h"
#include <stdio.h>
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
#include <ac/string.h>
#include <ac/ctype.h>
int global_lastmod;
char *ldap_srvtab = "";
+char *slapd_pid_file = NULL;
+char *slapd_args_file = NULL;
+
static char *fp_getline(FILE *fp, int *lineno);
static void fp_getline_init(int *lineno);
-static void fp_parse_line(char *line, int *argcp, char **argv);
+static int fp_parse_line(char *line, int *argcp, char **argv);
static char *strtok_quote(char *line, char *sep);
-void
-read_config( char *fname, Backend **bep, FILE *pfp )
+int
+read_config( char *fname )
{
FILE *fp;
char *line, *savefname;
int cargc, savelineno;
char *cargv[MAXARGS];
int lineno, i;
- Backend *be;
- if ( (fp = pfp) == NULL && (fp = fopen( fname, "r" )) == NULL ) {
+ static BackendInfo *bi = NULL;
+ static BackendDB *be = NULL;
+
+ if ( (fp = fopen( fname, "r" )) == NULL ) {
ldap_syslog = 1;
Debug( LDAP_DEBUG_ANY,
"could not open config file \"%s\" - absolute path?\n",
fname, 0, 0 );
perror( fname );
- exit( 1 );
+ return 1;
}
Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
- be = *bep;
+
fp_getline_init( &lineno );
+
while ( (line = fp_getline( fp, &lineno )) != NULL ) {
/* skip comments and blank lines */
if ( line[0] == '#' || line[0] == '\0' ) {
Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, line, 0 );
- fp_parse_line( line, &cargc, cargv );
+ if ( fp_parse_line( line, &cargc, cargv ) != 0 ) {
+ return( 1 );
+ }
if ( cargc < 1 ) {
Debug( LDAP_DEBUG_ANY,
continue;
}
+ if ( strcasecmp( cargv[0], "backend" ) == 0 ) {
+ if ( cargc < 2 ) {
+ Debug( LDAP_DEBUG_ANY,
+ "%s: line %d: missing type in \"backend <type>\" line\n",
+ fname, lineno, 0 );
+ return( 1 );
+ }
+
+ if( be != NULL ) {
+ Debug( LDAP_DEBUG_ANY,
+"%s: line %d: backend line must appear before any database definition\n",
+ fname, lineno, 0 );
+ return( 1 );
+ }
+
+ bi = backend_info( cargv[1] );
+
/* start of a new database definition */
- if ( strcasecmp( cargv[0], "database" ) == 0 ) {
+ } else if ( strcasecmp( cargv[0], "database" ) == 0 ) {
if ( cargc < 2 ) {
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing type in \"database <type>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
- *bep = new_backend( cargv[1] );
- be = *bep;
+ bi = NULL;
+ be = backend_db_init( cargv[1] );
/* assign a default depth limit for alias deref */
be->be_maxDerefDepth = SLAPD_DEFAULT_MAXDEREFDEPTH;
+ /* get pid file name */
+ } else if ( strcasecmp( cargv[0], "pidfile" ) == 0 ) {
+ if ( cargc < 2 ) {
+ Debug( LDAP_DEBUG_ANY,
+ "%s: line %d: missing file name in \"pidfile <file>\" line\n",
+ fname, lineno, 0 );
+ return( 1 );
+ }
+
+ slapd_pid_file = ch_strdup( cargv[1] );
+
+ /* get args file name */
+ } else if ( strcasecmp( cargv[0], "argsfile" ) == 0 ) {
+ if ( cargc < 2 ) {
+ Debug( LDAP_DEBUG_ANY,
+ "%s: line %d: missing file name in \"argsfile <file>\" line\n",
+ fname, lineno, 0 );
+ return( 1 );
+ }
+
+ slapd_args_file = ch_strdup( cargv[1] );
+
/* set size limit */
} else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
if ( cargc < 2 ) {
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
if ( be == NULL ) {
defsize = atoi( cargv[1] );
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing limit in \"timelimit <limit>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
if ( be == NULL ) {
deftime = atoi( cargv[1] );
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing dn in \"suffix <dn>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
} else if ( cargc > 2 ) {
Debug( LDAP_DEBUG_ANY,
"%s: line %d: extra cruft after <dn> in \"suffix %s\" line (ignored)\n",
fname, lineno, 0 );
} else {
char *dn = ch_strdup( cargv[1] );
- (void) dn_normalize( dn );
+ (void) dn_normalize_case( dn );
charray_add( &be->be_suffix, dn );
}
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing alias and aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
} else if ( cargc < 3 ) {
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
} else if ( cargc > 3 ) {
Debug( LDAP_DEBUG_ANY,
"%s: line %d: extra cruft in suffixAlias line (ignored)\n",
(void) dn_normalize( aliased_dn );
- if ( strcasecmp( alias, aliased_dn) ) {
+ if ( strcasecmp( alias, aliased_dn) == 0 ) {
Debug( LDAP_DEBUG_ANY,
"%s: line %d: suffixAlias %s is not different from aliased dn (ignored)\n",
fname, lineno, alias );
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
if ( be == NULL ) {
Debug( LDAP_DEBUG_ANY,
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing dn in \"rootdn <dn>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
if ( be == NULL ) {
Debug( LDAP_DEBUG_ANY,
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing passwd in \"rootpw <passwd>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
if ( be == NULL ) {
Debug( LDAP_DEBUG_ANY,
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
if ( be == NULL ) {
Debug( LDAP_DEBUG_ANY,
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing URL in \"referral <URL>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
- default_referral = (char *) malloc( strlen( cargv[1] )
+ default_referral = (char *) ch_malloc( strlen( cargv[1] )
+ sizeof("Referral:\n") + 1 );
strcpy( default_referral, "Referral:\n" );
strcat( default_referral, cargv[1] );
+ /* specify locale */
+ } else if ( strcasecmp( cargv[0], "locale" ) == 0 ) {
+#ifdef HAVE_LOCALE_H
+ char *locale;
+ if ( cargc < 2 ) {
+ Debug( LDAP_DEBUG_ANY,
+ "%s: line %d: missing locale in \"locale <name | on | off>\" line\n",
+ fname, lineno, 0 );
+ return( 1 );
+ }
+
+ locale = (strcasecmp( cargv[1], "on" ) == 0 ? ""
+ : strcasecmp( cargv[1], "off" ) == 0 ? "C"
+ : ch_strdup( cargv[1] ) );
+
+ if ( setlocale( LC_CTYPE, locale ) == 0 ) {
+ Debug( LDAP_DEBUG_ANY,
+ (*locale
+ ? "%s: line %d: bad locale \"%s\"\n"
+ : "%s: line %d: bad locale\n"),
+ fname, lineno, locale );
+ return( 1 );
+ }
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "%s: line %d: \"locale\" unsupported\n",
+ fname, lineno, 0 );
+ return( 1 );
+#endif
/* specify an objectclass */
} else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
parse_oc( be, fname, lineno, cargc, cargv );
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
if ( strcasecmp( cargv[1], "on" ) == 0 ) {
global_schemacheck = 1;
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing limit in \"defaultaccess <access>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
if ( be == NULL ) {
if ( (global_default_access =
Debug( LDAP_DEBUG_ANY,
"%s: line %d: bad access \"%s\" expecting [self]{none|compare|read|write}\n",
fname, lineno, cargv[1] );
- exit( 1 );
+ return( 1 );
}
} else {
if ( (be->be_dfltaccess =
Debug( LDAP_DEBUG_ANY,
"%s: line %d: bad access \"%s\" expecting [self]{none|compare|read|write}\n",
fname, lineno, cargv[1] );
- exit( 1 );
+ return( 1 );
}
}
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing level in \"loglevel <level>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
ldap_syslog = atoi( cargv[1] );
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing host in \"replica <host[:port]>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
if ( be == NULL ) {
Debug( LDAP_DEBUG_ANY,
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing dn in \"updatedn <dn>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
if ( be == NULL ) {
Debug( LDAP_DEBUG_ANY,
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing dn in \"replogfile <filename>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
if ( be ) {
be->be_replogfile = ch_strdup( cargv[1] );
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
if ( strcasecmp( cargv[1], "on" ) == 0 ) {
if ( be )
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing filename in \"include <filename>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
savefname = ch_strdup( cargv[1] );
savelineno = lineno;
- read_config( savefname, bep, NULL );
- be = *bep;
+
+ if ( read_config( savefname ) != 0 ) {
+ return( 1 );
+ }
+
free( savefname );
lineno = savelineno - 1;
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing filename in \"srvtab <filename>\" line\n",
fname, lineno, 0 );
- exit( 1 );
+ return( 1 );
}
ldap_srvtab = ch_strdup( cargv[1] );
- /* pass anything else to the current backend config routine */
+ /* pass anything else to the current backend info/db config routine */
} else {
- if ( be == NULL ) {
- Debug( LDAP_DEBUG_ANY,
-"%s: line %d: unknown directive \"%s\" outside database definition (ignored)\n",
- fname, lineno, cargv[0] );
- } else if ( be->be_config == NULL ) {
+ if ( bi != NULL ) {
+ if ( bi->bi_config == 0 ) {
+ Debug( LDAP_DEBUG_ANY,
+"%s: line %d: unknown directive \"%s\" inside backend info definition (ignored)\n",
+ fname, lineno, cargv[0] );
+ } else {
+ if ( (*bi->bi_config)( bi, fname, lineno, cargc, cargv )
+ != 0 )
+ {
+ return( 1 );
+ }
+ }
+ } else if ( be != NULL ) {
+ if ( be->be_config == 0 ) {
+ Debug( LDAP_DEBUG_ANY,
+"%s: line %d: unknown directive \"%s\" inside backend database definition (ignored)\n",
+ fname, lineno, cargv[0] );
+ } else {
+ if ( (*be->be_config)( be, fname, lineno, cargc, cargv )
+ != 0 )
+ {
+ return( 1 );
+ }
+ }
+ } else {
Debug( LDAP_DEBUG_ANY,
-"%s: line %d: unknown directive \"%s\" inside database definition (ignored)\n",
+"%s: line %d: unknown directive \"%s\" outside backend info and database definitions (ignored)\n",
fname, lineno, cargv[0] );
- } else {
- (*be->be_config)( be, fname, lineno, cargc,
- cargv );
}
}
}
fclose( fp );
+ return( 0 );
}
-static void
+static int
fp_parse_line(
char *line,
int *argcp,
if ( *argcp == MAXARGS ) {
Debug( LDAP_DEBUG_ANY, "Too many tokens (max %d)\n",
MAXARGS, 0, 0 );
- exit( 1 );
+ return( 1 );
}
argv[(*argcp)++] = token;
}
argv[*argcp] = NULL;
+ return 0;
}
static char *
break;
case '\\':
- SAFEMEMCPY( next, next + 1, strlen( next + 1 ) + 1 );
+ if ( next[1] )
+ SAFEMEMCPY( next,
+ next + 1, strlen( next + 1 ) + 1 );
+ next++; /* dont parse the escaped character */
break;
default:
if ( (p = strchr( buf, '\n' )) != NULL ) {
*p = '\0';
}
- if ( ! isspace( buf[0] ) ) {
+ if ( ! isspace( (unsigned char) buf[0] ) ) {
return( line );
}