server-config.c 20.9 KB
Newer Older
Linus Tolke's avatar
Linus Tolke committed
1
/*
2
 * $Id: server-config.c,v 0.86 2003/07/12 21:43:41 ceder Exp $
Per Cederqvist's avatar
Per Cederqvist committed
3
 * Copyright (C) 1991-1999, 2001-2002  Lysator Academic Computer Association.
Linus Tolke's avatar
Linus Tolke committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * This file is part of the LysKOM server.
 * 
 * LysKOM is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 1, or (at your option) 
 * any later version.
 * 
 * LysKOM is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with LysKOM; see the file COPYING.  If not, write to
 * Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
 * or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
 * MA 02139, USA.
 *
 * Please mail bug reports to bug-lyskom@lysator.liu.se. 
 */
Per Cederqvist's avatar
Per Cederqvist committed
25
/*
26
 *  server-config.c
Per Cederqvist's avatar
Per Cederqvist committed
27
28
 *
 *  This is in a .c file to make it possible to change a value without having
29
 *  to recompile the entire server (or, in fact, anything!)
30
31
 *
 *  Compile with -DDEFAULT_PREFIX='"/usr/lyskom"' or something similar.
Per Cederqvist's avatar
Per Cederqvist committed
32
33
 */

David Byers's avatar
David Byers committed
34
35
36
37
38

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

Per Cederqvist's avatar
Per Cederqvist committed
39
#include <limits.h>
40
41
#include <stdio.h>
#include <sys/types.h>
42
43
44
#ifdef HAVE_STRING_H
#  include <string.h>
#endif
45
#include <time.h>
46
#include <assert.h>
David Byers's avatar
Server    
David Byers committed
47
#include <setjmp.h>
Per Cederqvist's avatar
Per Cederqvist committed
48

49
#include "server/smalloc.h"
David Byers's avatar
David Byers committed
50
#include "kom-config.h"
David Byers's avatar
Server    
David Byers committed
51
52
53
54
#include "kom-types.h"
#include "com.h"
#include "async.h"
#include "connections.h"
55
#include "kom-errno.h"
David Byers's avatar
Server    
David Byers committed
56
#include "manipulate.h"
57
58
59
60
61
62
63
64
65
#include "server-config.h"
#include "misc-types.h"
#include "s-string.h"
#include "kom-types.h"
#include "param.h"
#include "conf-file.h"
#include "admin.h"
#include "log.h"
#include "lyskomd.h"
66
#include "unused.h"
67

68
struct kom_par param;
69
char *read_config_file;
70

71
72
static Success log_param(const char *val, const struct parameter *par);
static Success jubel(const char *val, const struct parameter *par);
Per Cederqvist's avatar
Per Cederqvist committed
73
static Success ident_param(const char *val, const struct parameter *par);
74

75
76
77
/* See lyskomd.texi for more info about the parameters.
   Please remember to update lyskomd.texi if you add more parameters!
   Try to keep this list and the list in lyskomd.texi in the same order. */
78
static const struct parameter parameters[] = {
79

80
    /* "Normal" configuration */
81

82
    {"Locale",
83
84
	 assign_string,  unassign_string,  0, 1, NULL, &param.use_locale,
         NULL},
85
    {"Force ISO 8859-1",
86
87
         assign_bool,    NULL,             0, 1, "no", &param.force_iso_8859_1,
         NULL},
88
    {"Prefix",
89
90
91
	 assign_string,  unassign_string,  0, 1, DEFAULT_PREFIX,
         &param.dbase_dir,
         NULL},
92
    {"Send async",
93
94
95
  	 assign_bool,    NULL,             0, 1, "1",
         &param.send_async_messages,
         NULL},
96
    {"Client host",
97
98
	 assign_string,  unassign_string,  0, 1, NULL, &param.ip_client_host,
         NULL},
99
    {"Client port",
100
101
	 assign_string,  unassign_string,  1, 1, NULL, &param.ip_client_port,
         NULL},
102
    {"Presentation of conferences",
103
104
	 assign_conf_no, NULL,             0, 1, "1", &kom_info.conf_pres_conf,
         NULL},
105
    {"Presentation of persons",
106
107
	 assign_conf_no, NULL,             0, 1, "2", &kom_info.pers_pres_conf,
         NULL},
108
    {"Motd-conference",
109
110
	 assign_conf_no, NULL,             0, 1, "3", &kom_info.motd_conf,
         NULL},
111
    {"News-conference", 
112
113
	 assign_conf_no, NULL,             0, 1, "4", &kom_info.kom_news_conf,
         NULL},
114
    {"Message of the day",
115
116
	 assign_text_no, NULL,             0, 1, "0", &kom_info.motd_of_lyskom,
         NULL},
117
    {"Garb",
118
119
	 assign_bool,    NULL,             0, 1, "on", &param.garb_enable,
         NULL},
120
    {"Never save",
121
122
	 assign_bool,    NULL,             0, 1, "no", &param.never_save,
         NULL},
123
124
#ifdef LOGACCESSES
    {"Log accesses", 
David Byers's avatar
David Byers committed
125
	 assign_string,  unassign_string,  0, 1, NULL,
126
127
         &param.logaccess_file,
         NULL},
128
#endif
129

130
    /* The database files. */
131

132
    {"Data file",
David Byers's avatar
David Byers committed
133
	 assign_string,  unassign_string,  0, 1, "db/lyskomd-data",
134
135
         &param.datafile_name,
         NULL},
136
    {"Backup file",
David Byers's avatar
David Byers committed
137
	 assign_string,  unassign_string,  0, 1, "db/lyskomd-backup",
138
139
         &param.backupfile_name,
         NULL},
140
    {"Backup file 2",
David Byers's avatar
David Byers committed
141
	 assign_string,  unassign_string,  0, 1, "db/lyskomd-backup-prev",
142
143
         &param.backupfile_name_2,
         NULL},
144
    {"Lock file",
David Byers's avatar
David Byers committed
145
	 assign_string,  unassign_string,  0, 1, "db/lyskomd-lock",
146
147
         &param.lockfile_name,
         NULL},
148
    {"Text file",
David Byers's avatar
David Byers committed
149
	 assign_string,  unassign_string,  0, 1, "db/lyskomd-texts",
150
151
         &param.textfile_name,
         NULL},
152
153
    {"Number file",
	 assign_string,  unassign_string,  0, 1, "db/number.txt",
154
155
         &param.numberfile_name,
         NULL},
156
157
    {"Number temp file",
	 assign_string,  unassign_string,  0, 1, "db/number.tmp",
158
159
         &param.numberfile_tmp_name,
         NULL},
160
    {"Text backup file",
David Byers's avatar
David Byers committed
161
	 assign_string,  unassign_string,  0, 1, "db/lyskomd-texts-backup",
162
163
         &param.textbackupfile_name,
         NULL},
164
165
    {"Backup export directory",
	 assign_string,  unassign_string,  0, 1, "exportdb",
166
167
         &param.backup_dir,
         NULL},
168

169
    /* Various log files */
170

171
    {"Log file",
David Byers's avatar
David Byers committed
172
	 assign_string,  unassign_string, 0, 1, "etc/server-log",
173
174
         &param.logfile_name,
         NULL},
175
    {"Log statistics",
David Byers's avatar
David Byers committed
176
	 assign_string,  unassign_string,  0, 1, "etc/lyskomd-log",
177
178
         &param.statistic_name,
         NULL},
179
    {"Pid file",
David Byers's avatar
David Byers committed
180
	 assign_string,  unassign_string,  0, 1, "etc/pid",
181
182
         &param.pid_name,
         NULL},
183
    {"Memory usage file",
David Byers's avatar
David Byers committed
184
	 assign_string,  unassign_string,  0, 1, "etc/memory-usage",
185
186
         &param.memuse_name,
         NULL},
187

188
    /* Other files. */
189

190
    {"Aux-item definition file",
David Byers's avatar
David Byers committed
191
	 assign_string,  unassign_string,  0, 1, "etc/aux-items.conf",
192
193
         &param.aux_def_file,
         NULL},
194
    {"Status file",
David Byers's avatar
David Byers committed
195
         assign_string,  unassign_string,  0, 1, "etc/status",
196
197
         &param.status_file,
         NULL},
198

199
200
    {"Connection status file",
         assign_string,  unassign_string,  0, 1, "etc/connections.txt",
201
202
         &param.connection_status_file,
         NULL},
203
204
205

    {"Connection status temp file",
         assign_string,  unassign_string,  0, 1, "etc/connections.tmp",
206
207
         &param.connection_status_file_tmp,
         NULL},
208

209
    /* Where to dump core. */
210

211
    {"Core directory",
David Byers's avatar
David Byers committed
212
	 assign_string,  unassign_string,  0, 1, "cores",
213
214
         &param.core_dir,
         NULL},
David Byers's avatar
David Byers committed
215
    {"Nologin file",
David Byers's avatar
David Byers committed
216
         assign_string,  unassign_string,  0, 1, "/etc/nologin",
217
218
         &param.nologin_file,
         NULL},
219

220
    /* Performance tuning parameters (milliseconds) */
221

Per Cederqvist's avatar
Per Cederqvist committed
222
    {"Garb busy postponement",
223
224
	 assign_timeval, NULL,             0, 1, "20",
         &param.garb_busy_postponement, "milliseconds"},
Per Cederqvist's avatar
Per Cederqvist committed
225

226
    {"Garb timeout",
227
228
	 assign_timeval, NULL,             0, 1, "100", &param.garbtimeout,
         "milliseconds"},
229
    {"Sync timeout",
230
231
	 assign_timeval, NULL,             0, 1, "0", &param.synctimeout,
         "milliseconds"},
232

233
    /* Performance tuning parameters (minutes) */
234

235
    {"Garb interval",
236
237
	 assign_timeval, NULL,             0, 1, "1440", &param.garb_interval,
         "minutes"},
238
    {"Permissive sync",
239
240
         assign_bool,    NULL,             0, 1, "off", &param.permissive_sync,
         NULL},
241
    {"Sync interval",
242
243
	 assign_timeval, NULL,             0, 1, "5", &param.sync_interval,
         "minutes"},
244
    
245
    {"Sync retry interval",
246
247
248
	 assign_timeval, NULL,             0, 1, "1",
         &param.sync_retry_interval,
         "minutes"},
249
250
251

    {"Saved items per call",
         assign_int,     NULL,             0, 1, "5",
252
253
         &param.saved_items_per_call,
         NULL},
254

Per Cederqvist's avatar
Per Cederqvist committed
255
256
    {"Penalty per call",
         assign_uint,    NULL,             0, 1, "10",
257
258
         &param.penalty_per_call,
         NULL},
Per Cederqvist's avatar
Per Cederqvist committed
259
260
261

    {"Penalty per read",
         assign_uint,    NULL,             0, 1, "1",
262
263
         &param.penalty_per_read,
         NULL},
Per Cederqvist's avatar
Per Cederqvist committed
264
265
266

    {"Max penalty",
         assign_uint,    NULL,             0, 1, "100",
267
268
         &param.max_penalty,
         NULL},
Per Cederqvist's avatar
Per Cederqvist committed
269
270
271

    {"Low penalty",
         assign_uint,    NULL,             0, 1, "20",
272
273
         &param.low_penalty,
         NULL},
Per Cederqvist's avatar
Per Cederqvist committed
274

275
276
277
278

    /* More performance tuning. */

    {"Max client transmit queue",
279
280
	 assign_int,     NULL,             0, 1, "300", &param.maxqueuedsize,
         NULL},
281
    {"Max simultaneous client replies",
282
283
	 assign_int,     NULL,             0, 1, "10", &param.maxdequeuelen,
         NULL},
284
    {"Open files",
285
286
         assign_int,     NULL,             0, 1, "-1", &param.no_files,
         NULL},
287
    {"Use DNS",
288
289
         assign_bool,    NULL,             0, 1, "yes", &param.use_dns,
         NULL},
290
291
    {"DNS log threshold",
         assign_double,  NULL,             0, 1, "1.5",
292
293
         &param.dns_log_threshold,
         NULL},
294

295
    /* String limits */
296

297
    {"Max conference name length",
298
299
	 assign_int,     NULL,             0, 1, "60", &param.conf_name_len,
         NULL},
David Byers's avatar
David Byers committed
300
    {"Max client data length",
301
302
         assign_int,     NULL,             0, 1, "60", &param.client_data_len,
         NULL},
303
    {"Max password length",
304
305
	 assign_int,     NULL,             0, 1, "128", &param.pwd_len,
         NULL},
306
    {"Max what am I doing length",
307
308
	 assign_int,     NULL,             0, 1, "60", &param.what_do_len,
         NULL},
309
    {"Max username length",
310
311
	 assign_int,     NULL,             0, 1, "128", &param.username_len,
         NULL},
312
    {"Max text length",
313
314
	 assign_int,     NULL,             0, 1, "131072", &param.text_len,
         NULL},
315
    {"Max aux_item length",
316
317
	 assign_int,     NULL,             0, 1, "16384", &param.aux_len,
         NULL},
318
    {"Max broadcast length",
319
320
	 assign_int,     NULL,             0, 1, "1024", &param.broadcast_len,
         NULL},
321
    {"Max regexp length",
322
323
	 assign_int,     NULL,             0, 1, "1024", &param.regexp_len,
         NULL},
324

325
    /* Text_stat limits */
326

327
    {"Max marks per person",
328
329
330
	 assign_int,     NULL,             0, 1, "2048",
         &param.max_marks_person,
         NULL},
331
    {"Max marks per text",
332
333
	 assign_int,     NULL,             0, 1, "1024", &param.max_marks_text,
         NULL},
334
    {"Max recipients per text",
335
336
	 assign_int,     NULL,             0, 1, "512", &param.max_recipients,
         NULL},
337
    {"Max comments per text",
338
339
	 assign_int,     NULL,             0, 1, "128", &param.max_comm,
         NULL},
340
    {"Max footnotes per text",
341
342
	 assign_int,     NULL,             0, 1, "32", &param.max_foot,
         NULL},
343
    {"Max links per text",
344
345
	 assign_int,     NULL,             0, 1, "512", &param.max_crea_misc,
         NULL},
346

347
    /* Other client-visible configuration */
348

349
    {"Max mark_as_read chunks",
350
351
352
	 assign_int,     NULL,             0, 1, "128",
         &param.mark_as_read_chunk,
         NULL},
353
    {"Max accept_async len",
354
355
356
	 assign_int,     NULL,             0, 1, "128",
         &param.accept_async_len,
         NULL},
357
    {"Max aux_items added per call",
358
359
         assign_int,     NULL,             0, 1, "128", &param.max_add_aux,
         NULL},
360
    {"Max aux_items deleted per call",
361
362
         assign_int,     NULL,             0, 1, "128", &param.max_delete_aux,
         NULL},
363
    {"Max read_ranges per call",
364
365
         assign_int,     NULL,             0, 1, "512", &param.max_read_ranges,
         NULL},
366
    {"Max super_conf loop",
367
368
369
	 assign_int,     NULL,             0, 1, "17",
         &param.max_super_conf_loop,
         NULL},
370
    {"Default garb nice",
371
372
	 assign_int,     NULL,             0, 1, "77", &param.default_nice,
         NULL},
373
    {"Default keep commented nice",
374
375
376
	 assign_int,     NULL,             0, 1, "77",
         &param.default_keep_commented,
         NULL},
377

378
    /* Security options */
379

380
    {"Anyone can create new persons",
381
382
383
	 assign_bool,    NULL,             0, 1, "yes",
         &param.anyone_can_create_new_persons,
         NULL},
384
    {"Anyone can create new conferences",
385
386
387
	 assign_bool,    NULL,             0, 1, "yes",
         &param.anyone_can_create_new_confs,
         NULL},
388
    {"Allow creation of persons before login",
389
390
391
	 assign_bool,    NULL,             0, 1, "yes",
         &param.create_person_before_login,
         NULL},
392
    {"Default change name capability",
393
394
395
	 assign_bool,    NULL,             0, 1, "on",
         &param.default_change_name,
         NULL},
396
    {"Add members by invitation",
397
398
399
        assign_bool,     NULL,             0, 1, "on",
         &param.invite_by_default,
         NULL},
400
    {"Allow secret memberships",
401
402
403
        assign_bool,     NULL,             0, 1, "on",
         &param.secret_memberships,
         NULL},
404
    {"Allow reinvitations",
405
406
        assign_bool,     NULL,             0, 1, "off", &param.allow_reinvite,
         NULL},
407
    {"Log login",
408
409
	 assign_bool,    NULL,             0, 1, "off", &param.log_login,
         NULL},
410
    {"Ident-authentication",
411
412
413
	ident_param,     NULL,             0, 1, "try",
         &param.authentication_level,
         NULL},
414

415
    /* Cache configuration */
416

417
    {"Cache conference limit",
418
419
420
	 assign_int,     NULL,             0, 1, "20",
         &param.cache_conferences,
         NULL},
421
    {"Cache person limit",
422
423
	 assign_int,     NULL,             0, 1, "20", &param.cache_persons,
         NULL},
424
    {"Cache text_stat limit",
425
426
	 assign_int,     NULL,             0, 1, "20", &param.cache_text_stats,
         NULL},
427

428
    /* Echo the value to the log. */
429

430
    {"Echo",
431
432
	 log_param,      NULL,             0, -1, NULL, NULL,
         NULL},
433

434
    /* Register a forbidden text number. */
435

436
    {"Jubel",
437
438
         jubel,          NULL,             0, -1, NULL, NULL,
         NULL},
439

David Byers's avatar
David Byers committed
440
    {"Max conferences",
441
442
        assign_ulong,    NULL,             1, 1, "4765", &param.max_conf,
         NULL},
David Byers's avatar
David Byers committed
443
    {"Max texts",
444
445
        assign_ulong,    NULL,             1, 1, "2000000", &param.max_text,
         NULL},
446

447
448
449
    /* Configuration for support programs.  */

    {"Normal shutdown time",
450
451
452
	 assign_int,     NULL,             0, 1, "21",
         &param.normal_shutdown_time,
         NULL},
453
    {"Mail after downtime",
454
455
456
	 assign_int,     NULL,             0, 1, "60",
         &param.downtime_mail_start,
         NULL},
457
    {"Mail until downtime",
458
459
460
	 assign_int,     NULL,             0, 1, "120",
         &param.downtime_mail_end,
         NULL},
461
    {"lyskomd path",
462
463
464
	 assign_string,  unassign_string,  0, 1, "bin/lyskomd",
         &param.lyskomd_path,
         NULL},
465
    {"savecore path",
466
467
468
	 assign_string,  unassign_string,  0, 1, "bin/savecore",
         &param.savecore_path,
         NULL},
469
    
470
    /* end marker */
471

472
    {NULL, NULL, NULL, 0, 0, NULL, NULL, NULL}};
Per Cederqvist's avatar
Per Cederqvist committed
473

Per Cederqvist's avatar
Per Cederqvist committed
474
/* Where to save things. These are used by lyskomd and dbck. */
Per Cederqvist's avatar
Per Cederqvist committed
475

Per Cederqvist's avatar
Per Cederqvist committed
476
/*
Per Cederqvist's avatar
Per Cederqvist committed
477
 * DEFAULT_DBASE_DIR can be overriden in the config file.  The default 
478
479
 * config file is found in DEFAULT_DBASE_DIR/CONFIG_FILE (before
 * DEFAULT_DBASE_DIR is overriden, of course).
Per Cederqvist's avatar
Per Cederqvist committed
480
481
 */

482
const char * DEFAULT_DBASE_DIR = DEFAULT_PREFIX;
Per Cederqvist's avatar
Per Cederqvist committed
483
const char *CONFIG_FILE = "etc/config";
Per Cederqvist's avatar
Per Cederqvist committed
484

485
486
/* This file descriptor, and any above it, will not be used by lyskomd. */
int fd_ceiling = 0;	/* Initialized by main(). */
487

488
/* What is whitespace? */
489
const char *WHITESPACE = " \t\n\r";
490

491
static Success
492
log_param(const char *val, const struct parameter *UNUSED(par))
493
494
{
    if (val != NULL)
David Byers's avatar
David Byers committed
495
	kom_log ("config: %s\n", val);
496
497
    return OK;
}
Per Cederqvist's avatar
Per Cederqvist committed
498

499
500
501
502
503
static Success
jubel(const char *val, const struct parameter *par)
{
    long a, b, c;
    int res;
504
    Bool public = FALSE;
505
506
507
    
    if (val == NULL)
        return OK;
Per Cederqvist's avatar
Per Cederqvist committed
508

509
510
511
512
513
514
    if (!strncmp(val, "public ", 7))
    {
	public = TRUE;
	val += 7;
    }

515
516
517
518
    res = sscanf(val, "%ld %ld %ld", &a, &b, &c);
    switch (res)
    {
    case 3:
519
	register_jubel(a, b, c, public);
520
521
	break;
    case 2:
522
	register_jubel(a, 0, b, public);
523
524
	break;
    default:
525
	kom_log("%s expecting [public ] x y [z]\n", par->name);
526
527
528
529
	return  FAILURE;
    }
    return OK;
}
Per Cederqvist's avatar
Per Cederqvist committed
530

Per Cederqvist's avatar
Per Cederqvist committed
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
static Success
ident_param(const char *val, const struct parameter *par)
{
    if (val == NULL)
	restart_kom("ident_param(): val == NULL\n");
    if (!strcmp(val, "off")
	|| !strcmp(val, "never"))
    {
	*(int*)par->value = 0;
    }
    else if (!strcmp(val, "on")
	     || !strcmp(val, "try"))
    {
	*(int*)par->value = 1;
    }
    else if (!strcmp(val, "require")
	     || !strcmp(val, "required"))
    {
	*(int*)par->value = 2;
    }
    else
    {
David Byers's avatar
David Byers committed
553
	kom_log ("%s expects \"never\", \"try\" or \"required\" as argument\n",
Per Cederqvist's avatar
Per Cederqvist committed
554
555
556
557
558
559
	     par->name);
	return FAILURE;
    }
    return OK;
}

560
561
562
563
564
565
566
567
568
569
570
571
572
573
static void
add_prefix(char **name)
{
    char *s;

    if (**name == '/')
	return;			/* Don't alter full paths. */

    s = smalloc(2 + strlen(param.dbase_dir) + strlen(*name));
    sprintf(s, "%s/%s", param.dbase_dir, *name);
    sfree(*name);
    *name = s;
}

574
static const char *
575
576
577
578
579
580
581
582
583
param_name(void *value)
{
    int ix;

    for (ix = 0; parameters[ix].name != NULL; ix++)
	if (parameters[ix].value == value)
	    return parameters[ix].name;

    restart_kom("Internal error: non-existing config param in param_name.\n");
David Byers's avatar
David Byers committed
584
585
    /* notreached */
    return NULL;
586
587
588
589
590
591
592
593
}

static Bool
check_abs_path(char **path)
{
    if (**path == '/')
	return FALSE;
	
David Byers's avatar
David Byers committed
594
    kom_log("Parameter '%s' must be an absolute path when 'Prefix' is empty.\n",
595
596
597
598
	param_name(path));
    return TRUE;
}

599
600
601
void
read_configuration(const char *conf_file)
{
602
603
    Bool err = FALSE;

604
605
    read_config(conf_file, parameters);
    
606
607
608
    assert(param.dbase_dir != NULL);
    assert(param.datafile_name != NULL);
    assert(param.backupfile_name != NULL);
609
    assert(param.backupfile_name_2 != NULL);
610
    assert(param.lockfile_name != NULL);
611
    assert(param.textfile_name != NULL);
612
613
    assert(param.numberfile_name != NULL);
    assert(param.numberfile_tmp_name != NULL);
614
    assert(param.textbackupfile_name != NULL);
615
    assert(param.backup_dir != NULL);
616
617
618
619
    assert(param.statistic_name != NULL);
    assert(param.pid_name != NULL);
    assert(param.memuse_name != NULL);
    assert(param.logfile_name != NULL);
620
621
    assert(param.connection_status_file != NULL);
    assert(param.connection_status_file_tmp != NULL);
622
    assert(param.aux_def_file != NULL);
623
    assert(param.status_file != NULL);
624
    assert(param.core_dir != NULL);
625
    assert(param.lyskomd_path != NULL);
626
    assert(param.savecore_path != NULL);
627
628
629
630
631

    if (strlen(param.dbase_dir) > 0) 
    {
	if (param.dbase_dir[0] != '/')
	{
David Byers's avatar
David Byers committed
632
	    kom_log("The 'Prefix' parameter must be an absolute path.\n");
633
634
635
636
637
	    err = TRUE;
	}

	add_prefix(&param.datafile_name);
	add_prefix(&param.backupfile_name);
638
	add_prefix(&param.backupfile_name_2);
639
	add_prefix(&param.lockfile_name);
640
	add_prefix(&param.textfile_name);
641
642
	add_prefix(&param.numberfile_name);
	add_prefix(&param.numberfile_tmp_name);
643
	add_prefix(&param.textbackupfile_name);
644
	add_prefix(&param.backup_dir);
645
646
647
648
	add_prefix(&param.statistic_name);
	add_prefix(&param.pid_name);
	add_prefix(&param.memuse_name);
	add_prefix(&param.logfile_name);
649
650
	add_prefix(&param.connection_status_file);
	add_prefix(&param.connection_status_file_tmp);
651
	add_prefix(&param.aux_def_file);
652
	add_prefix(&param.status_file);
653
	add_prefix(&param.core_dir);
654
	add_prefix(&param.lyskomd_path);
655
	add_prefix(&param.savecore_path);
656
657
658
659
660
    }
    else
    {
	err |= check_abs_path(&param.datafile_name);
	err |= check_abs_path(&param.backupfile_name);
661
	err |= check_abs_path(&param.backupfile_name_2);
662
	err |= check_abs_path(&param.lockfile_name);
663
	err |= check_abs_path(&param.textfile_name);
664
665
	err |= check_abs_path(&param.numberfile_name);
	err |= check_abs_path(&param.numberfile_tmp_name);
666
	err |= check_abs_path(&param.textbackupfile_name);
667
	err |= check_abs_path(&param.backup_dir);
668
669
670
671
	err |= check_abs_path(&param.statistic_name);
	err |= check_abs_path(&param.pid_name);
	err |= check_abs_path(&param.memuse_name);
	err |= check_abs_path(&param.logfile_name);
672
673
	err |= check_abs_path(&param.connection_status_file);
	err |= check_abs_path(&param.connection_status_file_tmp);
674
	err |= check_abs_path(&param.aux_def_file);
675
	err |= check_abs_path(&param.status_file);
676
	err |= check_abs_path(&param.core_dir);
677
	err |= check_abs_path(&param.lyskomd_path);
678
	err |= check_abs_path(&param.savecore_path);
679
680
    }

681
682
683
684
685
686
687
    if (param.saved_items_per_call < 1)
    {
	err = TRUE;
	kom_log("Parameter '%s' must be at least 1.\n",
		param_name(&param.saved_items_per_call));
    }

688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
    /* We want max_texts and max_confs to hold the first forbidden
       number, but the documentation states that they hold the number
       of objects that are allowed to be created.  Adjust. */
    if (++param.max_text < 2)
    {
	err = TRUE;
	kom_log("Parameter '%s' must be at least 1.\n",
		param_name(&param.max_text));
    }
    if (++param.max_conf < 6)
    {
	err = TRUE;
	kom_log("Parameter '%s' must be at least 5.\n",
		param_name(&param.max_conf));
    }

704
705
706
707
708
709
    /* FIXME (bug 165): Check config parameters for sanity.
       One thing to check is:
          The following should always be true:
          0 <= SYNCTIMEOUT <= GARBTIMEOUT <= TIMEOUT
          Times in milliseconds.
       There are probably many more things to check. */
710
711
712

    if (err)
	restart_kom("Please fix the above configuration errors.\n");
713
}
Per Cederqvist's avatar
Per Cederqvist committed
714

David Byers's avatar
David Byers committed
715
716
717
718
719
720
721
722
723
724
725
726
727
728
void
free_configuration(void)
{
    int i = 0;

    while (parameters[i].name != NULL)
    {
        if (parameters[i].freer != NULL)
        {
            (*parameters[i].freer)(&parameters[i]);
        }
        i += 1;
    }
}