1 /* config.c - configuration file handling routines */
11 #include "ldapconfig.h"
15 extern Backend *new_backend();
16 extern char *default_referral;
17 extern int ldap_syslog;
18 extern int global_schemacheck;
21 * defaults for various global variables
23 int defsize = SLAPD_DEFAULT_SIZELIMIT;
24 int deftime = SLAPD_DEFAULT_TIMELIMIT;
25 struct acl *global_acl = NULL;
26 int global_default_access = ACL_READ;
29 char *ldap_srvtab = "";
31 static char *fp_getline();
32 static void fp_getline_init();
33 static void fp_parse_line();
35 static char *strtok_quote();
38 read_config( char *fname, Backend **bep, FILE *pfp )
41 char *line, *savefname, *dn;
42 int cargc, savelineno;
47 if ( (fp = pfp) == NULL && (fp = fopen( fname, "r" )) == NULL ) {
49 Debug( LDAP_DEBUG_ANY,
50 "could not open config file \"%s\" - absolute path?\n",
56 Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 );
58 fp_getline_init( &lineno );
59 while ( (line = fp_getline( fp, &lineno )) != NULL ) {
60 /* skip comments and blank lines */
61 if ( line[0] == '#' || line[0] == '\0' ) {
65 Debug( LDAP_DEBUG_CONFIG, "line %d (%s)\n", lineno, line, 0 );
67 fp_parse_line( line, &cargc, cargv );
70 Debug( LDAP_DEBUG_ANY,
71 "%s: line %d: bad config line (ignored)\n",
76 /* start of a new database definition */
77 if ( strcasecmp( cargv[0], "database" ) == 0 ) {
79 Debug( LDAP_DEBUG_ANY,
80 "%s: line %d: missing type in \"database <type>\" line\n",
84 *bep = new_backend( cargv[1] );
87 /* assign a default depth limit for alias deref */
88 be->be_maxDerefDepth = SLAPD_DEFAULT_MAXDEREFDEPTH;
91 } else if ( strcasecmp( cargv[0], "sizelimit" ) == 0 ) {
93 Debug( LDAP_DEBUG_ANY,
94 "%s: line %d: missing limit in \"sizelimit <limit>\" line\n",
99 defsize = atoi( cargv[1] );
101 be->be_sizelimit = atoi( cargv[1] );
105 } else if ( strcasecmp( cargv[0], "timelimit" ) == 0 ) {
107 Debug( LDAP_DEBUG_ANY,
108 "%s: line %d: missing limit in \"timelimit <limit>\" line\n",
113 deftime = atoi( cargv[1] );
115 be->be_timelimit = atoi( cargv[1] );
118 /* set database suffix */
119 } else if ( strcasecmp( cargv[0], "suffix" ) == 0 ) {
121 Debug( LDAP_DEBUG_ANY,
122 "%s: line %d: missing dn in \"suffix <dn>\" line\n",
125 } else if ( cargc > 2 ) {
126 Debug( LDAP_DEBUG_ANY,
127 "%s: line %d: extra cruft after <dn> in \"suffix %s\" line (ignored)\n",
128 fname, lineno, cargv[1] );
131 Debug( LDAP_DEBUG_ANY,
132 "%s: line %d: suffix line must appear inside a database definition (ignored)\n",
135 dn = strdup( cargv[1] );
136 (void) dn_normalize( dn );
137 charray_add( &be->be_suffix, dn );
140 /* set database suffixAlias */
141 } else if ( strcasecmp( cargv[0], "suffixAlias" ) == 0 ) {
143 Debug( LDAP_DEBUG_ANY,
144 "%s: line %d: missing alias and aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
147 } else if ( cargc < 3 ) {
148 Debug( LDAP_DEBUG_ANY,
149 "%s: line %d: missing aliased_dn in \"suffixAlias <alias> <aliased_dn>\" line\n",
152 } else if ( cargc > 3 ) {
153 Debug( LDAP_DEBUG_ANY,
154 "%s: line %d: extra cruft in suffixAlias line (ignored)\n",
158 Debug( LDAP_DEBUG_ANY,
159 "%s: line %d: suffixAlias line must appear inside a database definition (ignored)\n",
162 dn = strdup( cargv[1] );
163 (void) dn_normalize( dn );
164 charray_add( &be->be_suffixAlias, dn );
166 dn = strdup( cargv[2] );
167 (void) dn_normalize( dn );
168 charray_add( &be->be_suffixAlias, dn );
171 /* set max deref depth */
172 } else if ( strcasecmp( cargv[0], "maxDerefDepth" ) == 0 ) {
174 Debug( LDAP_DEBUG_ANY,
175 "%s: line %d: missing depth in \"maxDerefDepth <depth>\" line\n",
180 Debug( LDAP_DEBUG_ANY,
181 "%s: line %d: depth line must appear inside a database definition (ignored)\n",
184 be->be_maxDerefDepth = atoi (cargv[1]);
188 /* set magic "root" dn for this database */
189 } else if ( strcasecmp( cargv[0], "rootdn" ) == 0 ) {
191 Debug( LDAP_DEBUG_ANY,
192 "%s: line %d: missing dn in \"rootdn <dn>\" line\n",
197 Debug( LDAP_DEBUG_ANY,
198 "%s: line %d: rootdn line must appear inside a database definition (ignored)\n",
201 dn = strdup( cargv[1] );
202 (void) dn_normalize( dn );
206 /* set super-secret magic database password */
207 } else if ( strcasecmp( cargv[0], "rootpw" ) == 0 ) {
209 Debug( LDAP_DEBUG_ANY,
210 "%s: line %d: missing passwd in \"rootpw <passwd>\" line\n",
215 Debug( LDAP_DEBUG_ANY,
216 "%s: line %d: rootpw line must appear inside a database definition (ignored)\n",
219 be->be_rootpw = strdup( cargv[1] );
222 /* make this database read-only */
223 } else if ( strcasecmp( cargv[0], "readonly" ) == 0 ) {
225 Debug( LDAP_DEBUG_ANY,
226 "%s: line %d: missing on|off in \"readonly <on|off>\" line\n",
231 Debug( LDAP_DEBUG_ANY,
232 "%s: line %d: readonly line must appear inside a database definition (ignored)\n",
235 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
242 /* where to send clients when we don't hold it */
243 } else if ( strcasecmp( cargv[0], "referral" ) == 0 ) {
245 Debug( LDAP_DEBUG_ANY,
246 "%s: line %d: missing URL in \"referral <URL>\" line\n",
250 default_referral = (char *) malloc( strlen( cargv[1] )
251 + sizeof("Referral:\n") + 1 );
252 strcpy( default_referral, "Referral:\n" );
253 strcat( default_referral, cargv[1] );
255 /* specify an objectclass */
256 } else if ( strcasecmp( cargv[0], "objectclass" ) == 0 ) {
257 parse_oc( be, fname, lineno, cargc, cargv );
259 /* specify an attribute */
260 } else if ( strcasecmp( cargv[0], "attribute" ) == 0 ) {
261 attr_syntax_config( fname, lineno, cargc - 1,
264 /* turn on/off schema checking */
265 } else if ( strcasecmp( cargv[0], "schemacheck" ) == 0 ) {
267 Debug( LDAP_DEBUG_ANY,
268 "%s: line %d: missing on|off in \"schemacheck <on|off>\" line\n",
272 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
273 global_schemacheck = 1;
275 global_schemacheck = 0;
278 /* specify access control info */
279 } else if ( strcasecmp( cargv[0], "access" ) == 0 ) {
280 parse_acl( be, fname, lineno, cargc, cargv );
282 /* specify default access control info */
283 } else if ( strcasecmp( cargv[0], "defaultaccess" ) == 0 ) {
285 Debug( LDAP_DEBUG_ANY,
286 "%s: line %d: missing limit in \"defaultaccess <access>\" line\n",
291 if ( (global_default_access =
292 str2access( cargv[1] )) == -1 ) {
293 Debug( LDAP_DEBUG_ANY,
294 "%s: line %d: bad access \"%s\" expecting [self]{none|compare|read|write}\n",
295 fname, lineno, cargv[1] );
299 if ( (be->be_dfltaccess =
300 str2access( cargv[1] )) == -1 ) {
301 Debug( LDAP_DEBUG_ANY,
302 "%s: line %d: bad access \"%s\" expecting [self]{none|compare|read|write}\n",
303 fname, lineno, cargv[1] );
308 /* debug level to log things to syslog */
309 } else if ( strcasecmp( cargv[0], "loglevel" ) == 0 ) {
311 Debug( LDAP_DEBUG_ANY,
312 "%s: line %d: missing level in \"loglevel <level>\" line\n",
316 ldap_syslog = atoi( cargv[1] );
318 /* list of replicas of the data in this backend (master only) */
319 } else if ( strcasecmp( cargv[0], "replica" ) == 0 ) {
321 Debug( LDAP_DEBUG_ANY,
322 "%s: line %d: missing host in \"replica <host[:port]>\" line\n",
327 Debug( LDAP_DEBUG_ANY,
328 "%s: line %d: replica line must appear inside a database definition (ignored)\n",
331 for ( i = 1; i < cargc; i++ ) {
332 if ( strncasecmp( cargv[i], "host=", 5 )
334 charray_add( &be->be_replica,
335 strdup( cargv[i] + 5 ) );
340 Debug( LDAP_DEBUG_ANY,
341 "%s: line %d: missing host in \"replica\" line (ignored)\n",
346 /* dn of master entity allowed to write to replica */
347 } else if ( strcasecmp( cargv[0], "updatedn" ) == 0 ) {
349 Debug( LDAP_DEBUG_ANY,
350 "%s: line %d: missing dn in \"updatedn <dn>\" line\n",
355 Debug( LDAP_DEBUG_ANY,
356 "%s: line %d: updatedn line must appear inside a database definition (ignored)\n",
359 be->be_updatedn = strdup( cargv[1] );
360 (void) dn_normalize( be->be_updatedn );
363 /* replication log file to which changes are appended */
364 } else if ( strcasecmp( cargv[0], "replogfile" ) == 0 ) {
366 Debug( LDAP_DEBUG_ANY,
367 "%s: line %d: missing dn in \"replogfile <filename>\" line\n",
372 be->be_replogfile = strdup( cargv[1] );
374 replogfile = strdup( cargv[1] );
377 /* maintain lastmodified{by,time} attributes */
378 } else if ( strcasecmp( cargv[0], "lastmod" ) == 0 ) {
380 Debug( LDAP_DEBUG_ANY,
381 "%s: line %d: missing on|off in \"lastmod <on|off>\" line\n",
385 if ( strcasecmp( cargv[1], "on" ) == 0 ) {
392 be->be_lastmod = OFF;
394 global_lastmod = OFF;
397 /* include another config file */
398 } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
400 Debug( LDAP_DEBUG_ANY,
401 "%s: line %d: missing filename in \"include <filename>\" line\n",
405 savefname = strdup( cargv[1] );
407 read_config( savefname, bep, NULL );
410 lineno = savelineno - 1;
412 /* location of kerberos srvtab file */
413 } else if ( strcasecmp( cargv[0], "srvtab" ) == 0 ) {
415 Debug( LDAP_DEBUG_ANY,
416 "%s: line %d: missing filename in \"srvtab <filename>\" line\n",
420 ldap_srvtab = strdup( cargv[1] );
422 /* pass anything else to the current backend config routine */
425 Debug( LDAP_DEBUG_ANY,
426 "%s: line %d: unknown directive \"%s\" outside database definition (ignored)\n",
427 fname, lineno, cargv[0] );
428 } else if ( be->be_config == NULL ) {
429 Debug( LDAP_DEBUG_ANY,
430 "%s: line %d: unknown directive \"%s\" inside database definition (ignored)\n",
431 fname, lineno, cargv[0] );
433 (*be->be_config)( be, fname, lineno, cargc,
451 for ( token = strtok_quote( line, " \t" ); token != NULL;
452 token = strtok_quote( NULL, " \t" ) ) {
453 if ( *argcp == MAXARGS ) {
454 Debug( LDAP_DEBUG_ANY, "Too many tokens (max %d)\n",
458 argv[(*argcp)++] = token;
464 strtok_quote( char *line, char *sep )
470 if ( line != NULL ) {
473 while ( *next && strchr( sep, *next ) ) {
477 if ( *next == '\0' ) {
483 for ( inquote = 0; *next; ) {
491 strcpy( next, next + 1 );
495 strcpy( next, next + 1 );
500 if ( strchr( sep, *next ) != NULL ) {
513 static char buf[BUFSIZ];
515 static int lmax, lcur;
517 #define CATLINE( buf ) { \
519 len = strlen( buf ); \
520 while ( lcur + len + 1 > lmax ) { \
522 line = (char *) ch_realloc( line, lmax ); \
524 strcpy( line + lcur, buf ); \
529 fp_getline( FILE *fp, int *lineno )
537 /* hack attack - keeps us from having to keep a stack of bufs... */
538 if ( strncasecmp( line, "include", 7 ) == 0 ) {
543 while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
544 if ( (p = strchr( buf, '\n' )) != NULL ) {
547 if ( ! isspace( buf[0] ) ) {
556 return( line[0] ? line : NULL );
560 fp_getline_init( int *lineno )