server-config.c 24.3 KB
Newer Older
Linus Tolke's avatar
Linus Tolke committed
1
/*
2
 * $Id: server-config.c,v 0.101 2003/10/03 07:33:41 ceder Exp $
3
 * Copyright (C) 1991-1999, 2001-2003  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
 *
 * 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.
 *
Per Cederqvist's avatar
Per Cederqvist committed
23
 * Please report bugs at http://bugzilla.lysator.liu.se/. 
Linus Tolke's avatar
Linus Tolke committed
24
 */
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!)
Per Cederqvist's avatar
Per Cederqvist committed
30
31
 */

David Byers's avatar
David Byers committed
32
33
34
35
36

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

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

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

71
struct kom_par param;
72

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

77
static const struct datatype cf_log_param = {
78
    log_param, NULL, NULL,
79
80
81
};

static const struct datatype cf_jubel = {
82
    jubel, NULL, NULL,
83
84
85
};

static const struct datatype cf_ident_param = {
86
    ident_param, NULL, NULL,
87
88
89
90
91
92
93
};

    

/* Paths are a special kind of strings.  For now, just use this
   define to make it easier to spot paths in the table below. */
#define cf_path cf_string
94

95
96
97
/* 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. */
98
static const struct parameter parameters[] = {
99

100
    /* "Normal" configuration */
101

102
    {"Locale",
103
	 &cf_string, 	       0, 1, NULL, &param.use_locale,
104
         NULL},
105
    {"Force ISO 8859-1",
106
         &cf_bool, 	       0, 1, "no", &param.force_iso_8859_1,
107
         NULL},
108
    {"Prefix",
109
	 &cf_path, 	       0, 1, DEFAULT_PREFIX,
110
111
         &param.dbase_dir,
         NULL},
112
    {"Send async",
113
  	 &cf_bool, 	       0, 1, "1",
114
115
         &param.send_async_messages,
         NULL},
116
117
118
    {"Listen",
	 &cf_ipport_list,      0, -1, "4894", &param.listen,
         "4894"},
119
    {"Presentation of conferences",
120
	 &cf_conf_no, 	       0, 1, "1", &kom_info.conf_pres_conf,
121
         NULL},
122
    {"Presentation of persons",
123
	 &cf_conf_no, 	       0, 1, "2", &kom_info.pers_pres_conf,
124
         NULL},
125
    {"Motd-conference",
126
	 &cf_conf_no, 	       0, 1, "3", &kom_info.motd_conf,
127
         NULL},
128
    {"News-conference", 
129
	 &cf_conf_no, 	       0, 1, "4", &kom_info.kom_news_conf,
130
         NULL},
131
    {"Message of the day",
132
	 &cf_text_no, 	       0, 1, "0", &kom_info.motd_of_lyskom,
133
         NULL},
134
    {"Garb",
135
	 &cf_bool, 	       0, 1, "off", &param.garb_enable,
136
         NULL},
137
    {"Never save",
138
	 &cf_bool, 	       0, 1, "no", &param.never_save,
139
         NULL},
140
141
#ifdef LOGACCESSES
    {"Log accesses", 
142
	 &cf_path, 	       0, 1, NULL, &param.logaccess_file,
143
         NULL},
144
#endif
145

146
    /* The database files. */
147

148
    {"Data file",
149
	 &cf_path, 	       0, 1, DATA_FILE, &param.datafile_name,
150
         NULL},
151
    {"Backup file",
152
	 &cf_path, 	       0, 1, BACKUP_FILE, &param.backupfile_name,
153
         NULL},
154
    {"Backup file 2",
155
	 &cf_path, 	       0, 1, PREV_BACKUP_FILE,
156
157
         &param.backupfile_name_2,
         NULL},
158
    {"Lock file",
159
	 &cf_path, 	       0, 1, LOCK_FILE, &param.lockfile_name,
160
         NULL},
161
    {"Text file",
162
	 &cf_path, 	       0, 1, TEXT_FILE, &param.textfile_name,
163
         NULL},
164
    {"Number file",
165
	 &cf_path, 	       0, 1, NUMBER_FILE, &param.numberfile_name,
166
         NULL},
167
    {"Number temp file",
168
	 &cf_path, 	       0, 1, NUMBER_FILE_TMP,
169
170
         &param.numberfile_tmp_name,
         NULL},
171
    {"Text backup file",
172
	 &cf_path, 	       0, 1, TEXT_BACKUP_FILE,
173
174
         &param.textbackupfile_name,
         NULL},
175
    {"Backup export directory",
176
	 &cf_path, 	       0, 1, EXPORT_DIR, &param.backup_dir,
177
         NULL},
178

179
    /* Various log files */
180

181
    {"Log file",
182
	 &cf_path, 	       0, 1, LYSKOMD_LOG, &param.logfile_name,
183
         NULL},
184
    {"Log statistics",
185
	 &cf_path, 	       0, 1, LYSKOMD_STATS, &param.statistic_name,
186
         NULL},
187
    {"Pid file",
188
	 &cf_path, 	       0, 1, LYSKOMD_PID, &param.pid_name,
189
         NULL},
190
    {"Memory usage file",
191
	 &cf_path, 	       0, 1, MEMORY_USAGE, &param.memuse_name,
192
         NULL},
193

194
    /* Other files. */
195

196
    {"Aux-item definition file",
197
	 &cf_path, 	       0, 1, AUX_FILE, &param.aux_def_file,
198
         NULL},
199
    {"Status file",
200
         &cf_path, 	       0, 1, STATUS_FILE, &param.status_file,
201
         NULL},
202

203
    {"Connection status file",
204
         &cf_path, 	       0, 1, CONNECTIONS_FILE,
205
206
         &param.connection_status_file,
         NULL},
207
208

    {"Connection status temp file",
209
         &cf_path, 	       0, 1, CONNECTIONS_TMP,
210
211
         &param.connection_status_file_tmp,
         NULL},
212

213
    /* Where to dump core. */
214

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

222
    /* Performance tuning parameters (milliseconds) */
223

Per Cederqvist's avatar
Per Cederqvist committed
224
    {"Garb busy postponement",
225
226
227
	 &cf_timeval, 	       0, 1, "50",
         &param.garb_busy_postponement,
         "milliseconds"},
Per Cederqvist's avatar
Per Cederqvist committed
228

229
    {"Garb timeout",
230
	 &cf_timeval, 	       0, 1, "0", &param.garbtimeout,
231
         "milliseconds"},
232
    {"Sync timeout",
233
	 &cf_timeval, 	       0, 1, "0", &param.synctimeout,
234
         "milliseconds"},
235

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

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

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

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

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

    {"Max penalty",
265
         &cf_uint, 	       0, 1, "100", &param.max_penalty,
266
         NULL},
Per Cederqvist's avatar
Per Cederqvist committed
267
268

    {"Low penalty",
269
         &cf_uint, 	       0, 1, "20", &param.low_penalty,
270
         NULL},
Per Cederqvist's avatar
Per Cederqvist committed
271

272
    {"Default priority",
273
         &cf_uint, 	       0, 1, "0", &param.default_priority,
274
275
276
         NULL},

    {"Max priority",
277
         &cf_uint, 	       0, 1, "0", &param.max_priority,
278
279
280
         NULL},

    {"Default weight",
281
         &cf_uint, 	       0, 1, "20", &param.default_weight,
282
283
284
         NULL},

    {"Max weight",
285
         &cf_uint, 	       0, 1, "100", &param.max_weight,
286
287
         NULL},

288
    /* Client inactivity timeouts. */
289

290
    {"Connect timeout",
291
	 &cf_timeval, 	       0, 1, "30", &param.connect_timeout,
292
         "seconds"},
293
294

    {"Login timeout",
295
	 &cf_timeval, 	       0, 1, "30", &param.login_timeout,
296
297
298
         "minutes"},

    {"Active timeout",
299
	 &cf_timeval, 	       0, 1, "11.5", &param.active_timeout,
300
301
302
         "days"},

    
303
304
    /* More performance tuning. */

305
    {"Max client message size",
306
	 &cf_int, 	       0, 1, "8176", &param.maxmsgsize,
307
308
309
         NULL},

    {"Max client transmit queue messages",
310
	 &cf_int, 	       0, 1, "50", &param.maxqueuedsize,
311
312
313
         NULL},

    {"Max client transmit queue bytes",
314
	 &cf_int, 	       0, 1, "100000",
315
         &param.maxqueuedsize_bytes,
316
         NULL},
317
318

    {"Stale timeout",
319
	 &cf_timeval, 	       0, 1, "60", &param.stale_timeout,
320
321
         "minutes"},

322
    {"Max simultaneous client replies",
323
	 &cf_int, 	       0, 1, "10", &param.maxdequeuelen,
324
         NULL},
325
    {"Open files",
326
         &cf_int, 	       0, 1, "-1", &param.no_files,
327
         NULL},
328
    {"Use DNS",
329
         &cf_bool, 	       0, 1, "yes", &param.use_dns,
330
         NULL},
331
    {"DNS log threshold",
332
         &cf_double, 	       0, 1, "1.5", &param.dns_log_threshold,
333
         NULL},
334

335
    /* String limits */
336

337
    {"Max conference name length",
338
	 &cf_int, 	       0, 1, "60", &param.conf_name_len,
339
         NULL},
David Byers's avatar
David Byers committed
340
    {"Max client data length",
341
         &cf_int, 	       0, 1, "60", &param.client_data_len,
342
         NULL},
343
    {"Max password length",
344
	 &cf_int, 	       0, 1, "128", &param.pwd_len,
345
         NULL},
346
    {"Max what am I doing length",
347
	 &cf_int, 	       0, 1, "60", &param.what_do_len,
348
         NULL},
349
    {"Max username length",
350
	 &cf_int, 	       0, 1, "128", &param.username_len,
351
         NULL},
352
    {"Max text length",
353
	 &cf_int, 	       0, 1, "131072", &param.text_len,
354
         NULL},
355
    {"Max aux_item length",
356
	 &cf_int, 	       0, 1, "16384", &param.aux_len,
357
         NULL},
358
    {"Max broadcast length",
359
	 &cf_int, 	       0, 1, "1024", &param.broadcast_len,
360
         NULL},
361
    {"Max regexp length",
362
	 &cf_int, 	       0, 1, "1024", &param.regexp_len,
363
         NULL},
364
    {"Statistic name length",
365
	 &cf_int, 	       0, 1, "64", &param.stat_name_len,
366
         NULL},
367

368
    /* Text_stat limits */
369

370
    {"Max marks per person",
371
	 &cf_int, 	       0, 1, "2048", &param.max_marks_person,
372
         NULL},
373
    {"Max marks per text",
374
	 &cf_int, 	       0, 1, "1024", &param.max_marks_text,
375
         NULL},
376
    {"Max recipients per text",
377
	 &cf_int, 	       0, 1, "512", &param.max_recipients,
378
         NULL},
379
    {"Max comments per text",
380
	 &cf_int, 	       0, 1, "128", &param.max_comm,
381
         NULL},
382
    {"Max footnotes per text",
383
	 &cf_int, 	       0, 1, "32", &param.max_foot,
384
         NULL},
385
    {"Max links per text",
386
	 &cf_int, 	       0, 1, "512", &param.max_crea_misc,
387
         NULL},
388

389
    /* Other client-visible configuration */
390

391
    {"Max mark_as_read chunks",
392
	 &cf_int, 	       0, 1, "128",
393
394
         &param.mark_as_read_chunk,
         NULL},
395
    {"Max accept_async len",
396
	 &cf_int, 	       0, 1, "128",
397
398
         &param.accept_async_len,
         NULL},
399
    {"Max aux_items added per call",
400
         &cf_int, 	       0, 1, "128", &param.max_add_aux,
401
         NULL},
402
    {"Max aux_items deleted per call",
403
         &cf_int, 	       0, 1, "128", &param.max_delete_aux,
404
         NULL},
405
    {"Max read_ranges per call",
406
         &cf_int, 	       0, 1, "512", &param.max_read_ranges,
407
         NULL},
408
    {"Max super_conf loop",
409
	 &cf_int, 	       0, 1, "17", &param.max_super_conf_loop,
410
         NULL},
411
    {"Default garb nice",
412
	 &cf_int, 	       0, 1, "77", &param.default_nice,
413
         NULL},
414
    {"Default keep commented nice",
415
	 &cf_int, 	       0, 1, "77", &param.default_keep_commented,
416
         NULL},
417

418
    /* Security options */
419

420
    {"Anyone can create new persons",
421
	 &cf_bool, 	       0, 1, "yes",
422
423
         &param.anyone_can_create_new_persons,
         NULL},
424
    {"Anyone can create new conferences",
425
	 &cf_bool, 	       0, 1, "yes",
426
427
         &param.anyone_can_create_new_confs,
         NULL},
428
    {"Allow creation of persons before login",
429
	 &cf_bool, 	       0, 1, "yes",
430
431
         &param.create_person_before_login,
         NULL},
432
    {"Default change name capability",
433
	 &cf_bool, 	       0, 1, "on",
434
435
         &param.default_change_name,
         NULL},
436
    {"Add members by invitation",
437
         &cf_bool, 	       0, 1, "on",
438
439
         &param.invite_by_default,
         NULL},
440
    {"Allow secret memberships",
441
         &cf_bool, 	       0, 1, "on",
442
443
         &param.secret_memberships,
         NULL},
444
    {"Allow reinvitations",
445
         &cf_bool, 	       0, 1, "off", &param.allow_reinvite,
446
         NULL},
447
    {"Log login",
448
	 &cf_bool, 	       0, 1, "off", &param.log_login,
449
         NULL},
450
    {"Ident-authentication",
451
	 &cf_ident_param,      0, 1, "try",
452
453
         &param.authentication_level,
         NULL},
454

455
    /* Cache configuration */
456

457
    {"Cache conference limit",
458
	 &cf_int, 	       0, 1, "20", &param.cache_conferences,
459
         NULL},
460
    {"Cache person limit",
461
	 &cf_int, 	       0, 1, "20", &param.cache_persons,
462
         NULL},
463
    {"Cache text_stat limit",
464
	 &cf_int, 	       0, 1, "20", &param.cache_text_stats,
465
         NULL},
466

467
    /* Echo the value to the log. */
468

469
    {"Echo",
470
	 &cf_log_param,        0, -1, NULL, NULL,
471
         NULL},
472

473
    /* Register a forbidden text number. */
474

475
    {"Jubel",
476
         &cf_jubel, 	       0, -1, NULL, NULL,
477
         NULL},
478

David Byers's avatar
David Byers committed
479
    {"Max conferences",
480
         &cf_ulong, 	       1, 1, "4765", &param.max_conf,
481
         NULL},
David Byers's avatar
David Byers committed
482
    {"Max texts",
483
         &cf_ulong, 	       1, 1, "2000000", &param.max_text,
484
         NULL},
485

486
487
488
    /* Configuration for support programs.  */

    {"Normal shutdown time",
489
	 &cf_int, 	       0, 1, "21", &param.normal_shutdown_time,
490
         NULL},
491
    {"Mail after downtime",
492
	 &cf_int, 	       0, 1, "60", &param.downtime_mail_start,
493
         NULL},
494
    {"Mail until downtime",
495
	 &cf_int, 	       0, 1, "120", &param.downtime_mail_end,
496
         NULL},
497
    {"sendmail path",
498
         &cf_path, 	       0, 1, SENDMAIL_PATH, &param.sendmail_path,
499
         NULL},
500
    {"lyskomd path",
501
	 &cf_path, 	       0, 1, LYSKOMD_PATH, &param.lyskomd_path,
502
         NULL},
503
    {"savecore path",
504
	 &cf_path, 	       0, 1, SAVECORE_PATH, &param.savecore_path,
505
         NULL},
506
507
508
509

    /* checkspace configuration */

    {"Free space warning level",
510
         &cf_double, 	       0, 1, "10e6", &param.chkspc_warn_space_abs,
511
512
513
         NULL},
    
    {"Free space warning percent",
514
         &cf_double, 	       0, 1, "10", &param.chkspc_warn_space_percent,
515
516
517
         NULL},

    {"Free inodes warning level",
518
         &cf_double, 	       0, 1, "100", &param.chkspc_warn_inode_abs,
519
520
521
         NULL},

    {"Free inodes warning percent",
522
         &cf_double, 	       0, 1, "5", &param.chkspc_warn_inode_percent,
523
524
525
         NULL},

    {"Free space critical level",
526
         &cf_double, 	       0, 1, "1e6", &param.chkspc_crit_space_abs,
527
528
529
         NULL},

    {"Free space critical percent",
530
         &cf_double, 	       0, 1, "2", &param.chkspc_crit_space_percent,
531
532
533
         NULL},

    {"Free inodes critical level",
534
         &cf_double, 	       0, 1, "10", &param.chkspc_crit_inode_abs,
535
536
537
         NULL},

    {"Free inodes critical percent",
538
         &cf_double, 	       0, 1, "0", &param.chkspc_crit_inode_percent,
539
         NULL},
540
    
541
    /* end marker */
542

543
    {NULL, NULL, 0, 0, NULL, NULL, NULL}};
Per Cederqvist's avatar
Per Cederqvist committed
544

545
/* Where to save things. */
546

547
static const char compiled_config_file[] = CONFIG_FILE;
548
549
550
551
552
553
554
static const char *default_config = NULL;

const char *
get_default_config_file_name(void)
{
    if (default_config == NULL)
    {
555
556
	if (compiled_config_file[0] == '/')
	    default_config = compiled_config_file;
557
558
559
	else
	{
	    char *cfg = smalloc(strlen(DEFAULT_PREFIX)
560
561
				+ strlen(compiled_config_file) + 2);
	    sprintf(cfg, "%s/%s", DEFAULT_PREFIX, compiled_config_file);
562
563
564
565
566
567
568
569
570
571
	    default_config = cfg;
	}
    }
    return default_config;
}


void
free_default_config_file_name(void)
{
572
    if (default_config != NULL && default_config != compiled_config_file)
573
574
575
576
577
578
579
580
    {
	/* cast away const; this string was allocated by
	   get_default_config_file_name().  */

	sfree((char*)default_config);
    }
    default_config = NULL;
}
Per Cederqvist's avatar
Per Cederqvist committed
581

Per Cederqvist's avatar
Per Cederqvist committed
582

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

586
/* What is whitespace? */
587
const char *WHITESPACE = " \t\n\r";
588

589
static Success
590
log_param(const char *val, const struct parameter *UNUSED(par))
591
592
{
    if (val != NULL)
David Byers's avatar
David Byers committed
593
	kom_log ("config: %s\n", val);
594
595
    return OK;
}
Per Cederqvist's avatar
Per Cederqvist committed
596

597
598
599
600
601
static Success
jubel(const char *val, const struct parameter *par)
{
    long a, b, c;
    int res;
602
    Bool public = FALSE;
603
604
605
    
    if (val == NULL)
        return OK;
Per Cederqvist's avatar
Per Cederqvist committed
606

607
608
609
610
611
612
    if (!strncmp(val, "public ", 7))
    {
	public = TRUE;
	val += 7;
    }

613
614
615
616
    res = sscanf(val, "%ld %ld %ld", &a, &b, &c);
    switch (res)
    {
    case 3:
617
	register_jubel(a, b, c, public);
618
619
	break;
    case 2:
620
	register_jubel(a, 0, b, public);
621
622
	break;
    default:
623
	kom_log("%s expecting [public ] x y [z]\n", par->name);
624
625
626
627
	return  FAILURE;
    }
    return OK;
}
Per Cederqvist's avatar
Per Cederqvist committed
628

Per Cederqvist's avatar
Per Cederqvist committed
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
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
651
	kom_log ("%s expects \"never\", \"try\" or \"required\" as argument\n",
Per Cederqvist's avatar
Per Cederqvist committed
652
653
654
655
656
657
	     par->name);
	return FAILURE;
    }
    return OK;
}

658
659
660
661
662
663
664
665
666
667
668
669
670
671
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;
}

672
static const char *
673
674
675
676
677
678
679
680
681
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
682
683
    /* notreached */
    return NULL;
684
685
686
687
688
689
690
691
}

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

697
698
699
700
701
702
703
704
705
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));
}    

706
707
708
709
710
711
712
713
714
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));
}    

715
716
717
void
read_configuration(const char *conf_file)
{
718
719
    Bool err = FALSE;

720
721
    if (read_config(conf_file, parameters) != OK)
	err = TRUE;
722
    
723
724
725
    assert(param.dbase_dir != NULL);
    assert(param.datafile_name != NULL);
    assert(param.backupfile_name != NULL);
726
    assert(param.backupfile_name_2 != NULL);
727
    assert(param.lockfile_name != NULL);
728
    assert(param.textfile_name != NULL);
729
730
    assert(param.numberfile_name != NULL);
    assert(param.numberfile_tmp_name != NULL);
731
    assert(param.textbackupfile_name != NULL);
732
    assert(param.backup_dir != NULL);
733
734
735
736
    assert(param.statistic_name != NULL);
    assert(param.pid_name != NULL);
    assert(param.memuse_name != NULL);
    assert(param.logfile_name != NULL);
737
738
    assert(param.connection_status_file != NULL);
    assert(param.connection_status_file_tmp != NULL);
739
    assert(param.aux_def_file != NULL);
740
    assert(param.status_file != NULL);
Per Cederqvist's avatar