server-config.c 24.4 KB
Newer Older
Linus Tolke's avatar
Linus Tolke committed
1
/*
2
 * $Id: server-config.c,v 0.94 2003/08/14 23:01:13 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 "timewrap.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
#include "timeval-util.h"
68
69
70
#ifdef DEBUG_CALLS
#  include "services.h"
#endif
71

72
struct kom_par param;
73
char *read_config_file;
74

75
76
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
77
static Success ident_param(const char *val, const struct parameter *par);
78

79
80
81
/* 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. */
82
static const struct parameter parameters[] = {
83

84
    /* "Normal" configuration */
85

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

134
    /* The database files. */
135

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

173
    /* Various log files */
174

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

192
    /* Other files. */
193

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

203
204
    {"Connection status file",
         assign_string,  unassign_string,  0, 1, "etc/connections.txt",
205
206
         &param.connection_status_file,
         NULL},
207
208
209

    {"Connection status temp file",
         assign_string,  unassign_string,  0, 1, "etc/connections.tmp",
210
211
         &param.connection_status_file_tmp,
         NULL},
212

213
    /* Where to dump core. */
214

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

224
    /* Performance tuning parameters (milliseconds) */
225

Per Cederqvist's avatar
Per Cederqvist committed
226
    {"Garb busy postponement",
227
228
	 assign_timeval, NULL,             0, 1, "20",
         &param.garb_busy_postponement, "milliseconds"},
Per Cederqvist's avatar
Per Cederqvist committed
229

230
    {"Garb timeout",
231
232
	 assign_timeval, NULL,             0, 1, "100", &param.garbtimeout,
         "milliseconds"},
233
    {"Sync timeout",
234
235
	 assign_timeval, NULL,             0, 1, "0", &param.synctimeout,
         "milliseconds"},
236

237
    /* Performance tuning parameters (minutes) */
238

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

    {"Saved items per call",
         assign_int,     NULL,             0, 1, "5",
256
257
         &param.saved_items_per_call,
         NULL},
258

Per Cederqvist's avatar
Per Cederqvist committed
259
260
    {"Penalty per call",
         assign_uint,    NULL,             0, 1, "10",
261
262
         &param.penalty_per_call,
         NULL},
Per Cederqvist's avatar
Per Cederqvist committed
263
264
265

    {"Penalty per read",
         assign_uint,    NULL,             0, 1, "1",
266
267
         &param.penalty_per_read,
         NULL},
Per Cederqvist's avatar
Per Cederqvist committed
268
269
270

    {"Max penalty",
         assign_uint,    NULL,             0, 1, "100",
271
272
         &param.max_penalty,
         NULL},
Per Cederqvist's avatar
Per Cederqvist committed
273
274
275

    {"Low penalty",
         assign_uint,    NULL,             0, 1, "20",
276
277
         &param.low_penalty,
         NULL},
Per Cederqvist's avatar
Per Cederqvist committed
278

279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
    {"Default priority",
         assign_uint,    NULL,             0, 1, "0",
         &param.default_priority,
         NULL},

    {"Max priority",
         assign_uint,    NULL,             0, 1, "0",
         &param.max_priority,
         NULL},

    {"Default weight",
         assign_uint,    NULL,             0, 1, "20",
         &param.default_weight,
         NULL},

    {"Max weight",
         assign_uint,    NULL,             0, 1, "100",
         &param.max_weight,
         NULL},

299
    /* Client inactivity timeouts. */
300

301
    {"Connect timeout",
302
	 assign_timeval, NULL,             0, 1, "30",
303
         &param.connect_timeout,
304
         "seconds"},
305
306

    {"Login timeout",
307
	 assign_timeval, NULL,             0, 1, "30",
308
309
310
311
312
313
314
315
316
         &param.login_timeout,
         "minutes"},

    {"Active timeout",
	 assign_timeval, NULL,             0, 1, "11.5",
         &param.active_timeout,
         "days"},

    
317
318
    /* More performance tuning. */

319
320
321
322
323
324
325
326
327
328
329
    {"Max client message size",
	 assign_int,     NULL,             0, 1, "8176", &param.maxmsgsize,
         NULL},

    {"Max client transmit queue messages",
	 assign_int,     NULL,             0, 1, "50", &param.maxqueuedsize,
         NULL},

    {"Max client transmit queue bytes",
	 assign_int,     NULL,             0, 1, "100000",
         &param.maxqueuedsize_bytes,
330
         NULL},
331
332
333
334
335
336

    {"Stale timeout",
	 assign_timeval, NULL,             0, 1, "60",
         &param.stale_timeout,
         "minutes"},

337
    {"Max simultaneous client replies",
338
339
	 assign_int,     NULL,             0, 1, "10", &param.maxdequeuelen,
         NULL},
340
    {"Open files",
341
342
         assign_int,     NULL,             0, 1, "-1", &param.no_files,
         NULL},
343
    {"Use DNS",
344
345
         assign_bool,    NULL,             0, 1, "yes", &param.use_dns,
         NULL},
346
347
    {"DNS log threshold",
         assign_double,  NULL,             0, 1, "1.5",
348
349
         &param.dns_log_threshold,
         NULL},
350

351
    /* String limits */
352

353
    {"Max conference name length",
354
355
	 assign_int,     NULL,             0, 1, "60", &param.conf_name_len,
         NULL},
David Byers's avatar
David Byers committed
356
    {"Max client data length",
357
358
         assign_int,     NULL,             0, 1, "60", &param.client_data_len,
         NULL},
359
    {"Max password length",
360
361
	 assign_int,     NULL,             0, 1, "128", &param.pwd_len,
         NULL},
362
    {"Max what am I doing length",
363
364
	 assign_int,     NULL,             0, 1, "60", &param.what_do_len,
         NULL},
365
    {"Max username length",
366
367
	 assign_int,     NULL,             0, 1, "128", &param.username_len,
         NULL},
368
    {"Max text length",
369
370
	 assign_int,     NULL,             0, 1, "131072", &param.text_len,
         NULL},
371
    {"Max aux_item length",
372
373
	 assign_int,     NULL,             0, 1, "16384", &param.aux_len,
         NULL},
374
    {"Max broadcast length",
375
376
	 assign_int,     NULL,             0, 1, "1024", &param.broadcast_len,
         NULL},
377
    {"Max regexp length",
378
379
	 assign_int,     NULL,             0, 1, "1024", &param.regexp_len,
         NULL},
380
381
382
    {"Statistic name length",
	 assign_int,     NULL,             0, 1, "64", &param.stat_name_len,
         NULL},
383

384
    /* Text_stat limits */
385

386
    {"Max marks per person",
387
388
389
	 assign_int,     NULL,             0, 1, "2048",
         &param.max_marks_person,
         NULL},
390
    {"Max marks per text",
391
392
	 assign_int,     NULL,             0, 1, "1024", &param.max_marks_text,
         NULL},
393
    {"Max recipients per text",
394
395
	 assign_int,     NULL,             0, 1, "512", &param.max_recipients,
         NULL},
396
    {"Max comments per text",
397
398
	 assign_int,     NULL,             0, 1, "128", &param.max_comm,
         NULL},
399
    {"Max footnotes per text",
400
401
	 assign_int,     NULL,             0, 1, "32", &param.max_foot,
         NULL},
402
    {"Max links per text",
403
404
	 assign_int,     NULL,             0, 1, "512", &param.max_crea_misc,
         NULL},
405

406
    /* Other client-visible configuration */
407

408
    {"Max mark_as_read chunks",
409
410
411
	 assign_int,     NULL,             0, 1, "128",
         &param.mark_as_read_chunk,
         NULL},
412
    {"Max accept_async len",
413
414
415
	 assign_int,     NULL,             0, 1, "128",
         &param.accept_async_len,
         NULL},
416
    {"Max aux_items added per call",
417
418
         assign_int,     NULL,             0, 1, "128", &param.max_add_aux,
         NULL},
419
    {"Max aux_items deleted per call",
420
421
         assign_int,     NULL,             0, 1, "128", &param.max_delete_aux,
         NULL},
422
    {"Max read_ranges per call",
423
424
         assign_int,     NULL,             0, 1, "512", &param.max_read_ranges,
         NULL},
425
    {"Max super_conf loop",
426
427
428
	 assign_int,     NULL,             0, 1, "17",
         &param.max_super_conf_loop,
         NULL},
429
    {"Default garb nice",
430
431
	 assign_int,     NULL,             0, 1, "77", &param.default_nice,
         NULL},
432
    {"Default keep commented nice",
433
434
435
	 assign_int,     NULL,             0, 1, "77",
         &param.default_keep_commented,
         NULL},
436

437
    /* Security options */
438

439
    {"Anyone can create new persons",
440
441
442
	 assign_bool,    NULL,             0, 1, "yes",
         &param.anyone_can_create_new_persons,
         NULL},
443
    {"Anyone can create new conferences",
444
445
446
	 assign_bool,    NULL,             0, 1, "yes",
         &param.anyone_can_create_new_confs,
         NULL},
447
    {"Allow creation of persons before login",
448
449
450
	 assign_bool,    NULL,             0, 1, "yes",
         &param.create_person_before_login,
         NULL},
451
    {"Default change name capability",
452
453
454
	 assign_bool,    NULL,             0, 1, "on",
         &param.default_change_name,
         NULL},
455
    {"Add members by invitation",
456
457
458
        assign_bool,     NULL,             0, 1, "on",
         &param.invite_by_default,
         NULL},
459
    {"Allow secret memberships",
460
461
462
        assign_bool,     NULL,             0, 1, "on",
         &param.secret_memberships,
         NULL},
463
    {"Allow reinvitations",
464
465
        assign_bool,     NULL,             0, 1, "off", &param.allow_reinvite,
         NULL},
466
    {"Log login",
467
468
	 assign_bool,    NULL,             0, 1, "off", &param.log_login,
         NULL},
469
    {"Ident-authentication",
470
471
472
	ident_param,     NULL,             0, 1, "try",
         &param.authentication_level,
         NULL},
473

474
    /* Cache configuration */
475

476
    {"Cache conference limit",
477
478
479
	 assign_int,     NULL,             0, 1, "20",
         &param.cache_conferences,
         NULL},
480
    {"Cache person limit",
481
482
	 assign_int,     NULL,             0, 1, "20", &param.cache_persons,
         NULL},
483
    {"Cache text_stat limit",
484
485
	 assign_int,     NULL,             0, 1, "20", &param.cache_text_stats,
         NULL},
486

487
    /* Echo the value to the log. */
488

489
    {"Echo",
490
491
	 log_param,      NULL,             0, -1, NULL, NULL,
         NULL},
492

493
    /* Register a forbidden text number. */
494

495
    {"Jubel",
496
497
         jubel,          NULL,             0, -1, NULL, NULL,
         NULL},
498

David Byers's avatar
David Byers committed
499
    {"Max conferences",
500
501
        assign_ulong,    NULL,             1, 1, "4765", &param.max_conf,
         NULL},
David Byers's avatar
David Byers committed
502
    {"Max texts",
503
504
        assign_ulong,    NULL,             1, 1, "2000000", &param.max_text,
         NULL},
505

506
507
508
    /* Configuration for support programs.  */

    {"Normal shutdown time",
509
510
511
	 assign_int,     NULL,             0, 1, "21",
         &param.normal_shutdown_time,
         NULL},
512
    {"Mail after downtime",
513
514
515
	 assign_int,     NULL,             0, 1, "60",
         &param.downtime_mail_start,
         NULL},
516
    {"Mail until downtime",
517
518
519
	 assign_int,     NULL,             0, 1, "120",
         &param.downtime_mail_end,
         NULL},
520
    {"lyskomd path",
521
522
523
	 assign_string,  unassign_string,  0, 1, "bin/lyskomd",
         &param.lyskomd_path,
         NULL},
524
    {"savecore path",
525
526
527
	 assign_string,  unassign_string,  0, 1, "bin/savecore",
         &param.savecore_path,
         NULL},
528
    
529
    /* end marker */
530

531
    {NULL, NULL, NULL, 0, 0, NULL, NULL, NULL}};
Per Cederqvist's avatar
Per Cederqvist committed
532

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

Per Cederqvist's avatar
Per Cederqvist committed
535
/*
Per Cederqvist's avatar
Per Cederqvist committed
536
 * DEFAULT_DBASE_DIR can be overriden in the config file.  The default 
537
538
 * 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
539
540
 */

541
const char * DEFAULT_DBASE_DIR = DEFAULT_PREFIX;
Per Cederqvist's avatar
Per Cederqvist committed
542
const char *CONFIG_FILE = "etc/config";
Per Cederqvist's avatar
Per Cederqvist committed
543

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

547
/* What is whitespace? */
548
const char *WHITESPACE = " \t\n\r";
549

550
static Success
551
log_param(const char *val, const struct parameter *UNUSED(par))
552
553
{
    if (val != NULL)
David Byers's avatar
David Byers committed
554
	kom_log ("config: %s\n", val);
555
556
    return OK;
}
Per Cederqvist's avatar
Per Cederqvist committed
557

558
559
560
561
562
static Success
jubel(const char *val, const struct parameter *par)
{
    long a, b, c;
    int res;
563
    Bool public = FALSE;
564
565
566
    
    if (val == NULL)
        return OK;
Per Cederqvist's avatar
Per Cederqvist committed
567

568
569
570
571
572
573
    if (!strncmp(val, "public ", 7))
    {
	public = TRUE;
	val += 7;
    }

574
575
576
577
    res = sscanf(val, "%ld %ld %ld", &a, &b, &c);
    switch (res)
    {
    case 3:
578
	register_jubel(a, b, c, public);
579
580
	break;
    case 2:
581
	register_jubel(a, 0, b, public);
582
583
	break;
    default:
584
	kom_log("%s expecting [public ] x y [z]\n", par->name);
585
586
587
588
	return  FAILURE;
    }
    return OK;
}
Per Cederqvist's avatar
Per Cederqvist committed
589

Per Cederqvist's avatar
Per Cederqvist committed
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
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
612
	kom_log ("%s expects \"never\", \"try\" or \"required\" as argument\n",
Per Cederqvist's avatar
Per Cederqvist committed
613
614
615
616
617
618
	     par->name);
	return FAILURE;
    }
    return OK;
}

619
620
621
622
623
624
625
626
627
628
629
630
631
632
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;
}

633
static const char *
634
635
636
637
638
639
640
641
642
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
643
644
    /* notreached */
    return NULL;
645
646
647
648
649
650
651
652
}

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

658
659
660
661
662
663
664
665
666
static void
require_less(void *low,
	     void *high)
{
    kom_log("Parameter '%s' must be less than parameter '%s'.\n",
	    param_name(low),
	    param_name(high));
}    

667
668
669
670
671
672
673
674
675
static void
require_less_eq(void *low,
		void *high)
{
    kom_log("Parameter '%s' must be less than or equal to parameter '%s'.\n",
	    param_name(low),
	    param_name(high));
}    

676
677
678
void
read_configuration(const char *conf_file)
{
679
680
    Bool err = FALSE;

681
682
    read_config(conf_file, parameters);
    
683
684
685
    assert(param.dbase_dir != NULL);
    assert(param.datafile_name != NULL);
    assert(param.backupfile_name != NULL);
686
    assert(param.backupfile_name_2 != NULL);
687
    assert(param.lockfile_name != NULL);
688
    assert(param.textfile_name != NULL);
689
690
    assert(param.numberfile_name != NULL);
    assert(param.numberfile_tmp_name != NULL);
691
    assert(param.textbackupfile_name != NULL);
692
    assert(param.backup_dir != NULL);
693
694
695
696
    assert(param.statistic_name != NULL);
    assert(param.pid_name != NULL);
    assert(param.memuse_name != NULL);
    assert(param.logfile_name != NULL);
697
698
    assert(param.connection_status_file != NULL);
    assert(param.connection_status_file_tmp != NULL);
699
    assert(param.aux_def_file != NULL);
700
    assert(param.status_file != NULL);
701
    assert(param.core_dir != NULL);
702
    assert(param.lyskomd_path != NULL);
703
    assert(param.savecore_path != NULL);
704
705
706
707
708

    if (strlen(param.dbase_dir) > 0) 
    {
	if (param.dbase_dir[0] != '/')
	{
David Byers's avatar
David Byers committed
709
	    kom_log("The 'Prefix' parameter must be an absolute path.\n");
710
711
712
713
714
	    err = TRUE;
	}

	add_prefix(&param.datafile_name);
	add_prefix(&param.backupfile_name);
715
	add_prefix(&param.backupfile_name_2);
716
	add_prefix(&param.lockfile_name);
717
	add_prefix(&param.textfile_name);
718
719
	add_prefix(&param.numberfile_name);
	add_prefix(&param.numberfile_tmp_name);
720
	add_prefix(&param.textbackupfile_name);
721
	add_prefix(&param.backup_dir);
722
723
724
725
	add_prefix(&param.statistic_name);
	add_prefix(&param.pid_name);
	add_prefix(&param.memuse_name);
	add_prefix(&param.logfile_name);
726
727
	add_prefix(&param.connection_status_file);
	add_prefix(&param.connection_status_file_tmp);
728
	add_prefix(&param.aux_def_file);
729
	add_prefix(&param.status_file);
730
	add_prefix(&param.core_dir);
731
	add_prefix(&param.lyskomd_path);
732
	add_prefix(&param.savecore_path);
733
734
735
736
737
    }
    else
    {
	err |= check_abs_path(&param.datafile_name);
	err |= check_abs_path(&param.backupfile_name);
738
	err |= check_abs_path(&param.backupfile_name_2);
739
	err |= check_abs_path(&param.lockfile_name);
740
	err |= check_abs_path(&param.textfile_name);
741
742
	err |= check_abs_path(&param.numberfile_name);
	err |= check_abs_path(&param.numberfile_tmp_name);
743
	err |= check_abs_path(&param.textbackupfile_name);
744
	err |= check_abs_path(&param.backup_dir);
745
746
747
748
	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);
749
750
	err |= check_abs_path(&param.connection_status_file);
	err |= check_abs_path(&param.connection_status_file_tmp);
751
	err |= check_abs_path(&param.aux_def_file);
752
	err |= check_abs_path(&param.status_file);
753
	err |= check_abs_path(&param.core_dir);
754
	err |= check_abs_path(&param.lyskomd_path);
755
	err |= check_abs_path(&param.savecore_path);
756
757
    }

758
759
760
761
762
763
764
    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));
    }

765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
    /* 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));
    }

781
782
783
    if (param.low_penalty >= param.max_penalty)
    {
	err = TRUE;
784
785
786
	require_less(&param.low_penalty, &param.max_penalty);
    }

787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
    if (param.default_weight < 1)
    {
	err = TRUE;
	kom_log("Parameter '%s' must be at least 1.\n",
		param_name(&param.default_weight));
    }

    if (param.default_weight > param.max_weight)
    {
	err = TRUE;
	require_less_eq(&param.default_weight,
			&param.max_weight);
    }

    if (param.default_priority > param.max_priority)
    {
	err = TRUE;
	require_less_eq(&param.default_priority,
			&param.max_priority);
    }

    if (param.max_priority > 0)
    {
	err = TRUE;
	kom_log("Parameter '%s' must be at most 0.\n",
		param_name(&param.max_priority));
    }

    /* This limit stops a potential overflow in adjust_penalty(). */
    if (param.max_weight >= 0x10000)
    {
	err = TRUE;
	kom_log("Parameter '%s' must be at most %d.\n",
		param_name(&param.max_weight), 0x10000);
    }

    /* This limit stops a potential overflow in adjust_penalty(). */
    if (param.max_penalty >= 0x8000)
    {
	err = TRUE;
	kom_log("Parameter '%s' must be at most %d.\n",
		param_name(&param.max_weight), 0x8000);
    }

831
832
833
834
835
836
    /* 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. */
837
838
839

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

David Byers's avatar
David Byers committed
842
843
844
845
846
847
848
849
850
851
852
853
854
855
void
free_configuration(void)
{
    int i = 0;

    while (parameters[i].name != NULL)
    {
        if (parameters[i].freer != NULL)
        {
            (*parameters[i].freer)(&parameters[i]);
        }
        i += 1;
    }
}
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884

#ifdef DEBUG_CALLS

static void
dump_timeval(const struct parameter *par)
{
    struct timeval *tv = par->value;
    kom_log("Name: %s\n", par->name);
    kom_log("  Default suffix: %s\n", par->default_suffix);
    kom_log("  Seconds: %ld\n", tv->tv_sec);
    kom_log("  Microseconds: %ld\n", tv->tv_usec);
}


Success
dump_cfg_timevals(void)
{
    int ix;

    kom_log("Configuration timeval dump\n");
    for (ix = 0; parameters[ix].name != NULL; ix++)
	if (parameters[ix].assigner == assign_timeval)
	    dump_timeval(&parameters[ix]);
    kom_log("End of timeval dump\n");

    return OK;
}

#endif