server-config.c 9.34 KB
Newer Older
Linus Tolke's avatar
Linus Tolke committed
1
/*
2
 * $Id: server-config.c,v 0.33 1994/10/24 00:38:57 ceder Exp $
Per Cederqvist's avatar
Per Cederqvist committed
3
 * Copyright (C) 1991, 1992, 1993, 1994  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
 */

34
static char *rcsid = "$Id: server-config.c,v 0.33 1994/10/24 00:38:57 ceder Exp $";
35
36
#include "rcs.h"
USE(rcsid);
Per Cederqvist's avatar
Per Cederqvist committed
37

Per Cederqvist's avatar
Per Cederqvist committed
38
#include <limits.h>
39
40
41
42
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
#include <stdarg.h>
Per Cederqvist's avatar
Per Cederqvist committed
43

Per Cederqvist's avatar
Per Cederqvist committed
44
#include "config.h"
45
46
47
48
49
50
51
52
53
54
55
#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 "manipulate.h"
#include "lyskomd.h"

56

57
58
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
59
static Success ident_param(const char *val, const struct parameter *par);
60
61
62
63
64
65
66
67

/* See lyskomd.8 for more info about the parameters.
   Please remember to update lyskomd.8 if you add more parameters!
   Try to keep this list and the list in lyskomd.8 in the same order. */
static const struct parameter parameters[] = {
    /* "Normal" configuration */
    {"Locale",
	 assign_string,  0, 1, NULL, &param.use_locale},
68
69
    {"Force ISO 8859-1",
         assign_bool,    0, 1, "no", &param.force_iso_8859_1},
70
    {"Prefix",
71
	 assign_string,  0, 1, DEFAULT_PREFIX, &param.dbase_dir},
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
    {"Send async",
  	 assign_bool,    0, 1, "1",  &param.send_async_messages},
    {"Client port",
	 assign_string,  1, 1, NULL, &param.ip_client_port},
    {"Mux port",   
	 assign_string,  1, 1, NULL, &param.ip_mux_port},
    {"Presentation of conferences",
	 assign_conf_no, 0, 1, "1", &kom_info.conf_pres_conf},
    {"Presentation of persons",
	 assign_conf_no, 0, 1, "2", &kom_info.pers_pres_conf},
    {"Motd-conference",
	 assign_conf_no, 0, 1, "3", &kom_info.motd_conf},
    {"News-conference", 
	 assign_conf_no, 0, 1, "4", &kom_info.kom_news_conf},
    {"Message of the day",
	 assign_text_no, 0, 1, "0", &kom_info.motd_of_lyskom},
Per Cederqvist's avatar
Per Cederqvist committed
88
#ifndef NDEBUG
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
    {"Never save",
	 assign_bool,    0, 1, "no", &param.never_save},
#endif
#ifdef LOGACCESSES
    {"Log accesses", 
	 assign_string,  0, 1, NULL, &param.logaccess_file},
#endif
    /* The database files. */
    {"Data file",
	 assign_string,  0, 1, "db/lyskomd-data", &param.datafile_name},
    {"Backup file",
	 assign_string,  0, 1, "db/lyskomd-backup", &param.backupfile_name},
    {"Text file",
	 assign_string,  0, 1, "db/lyskomd-texts", &param.textfile_name},
    {"Text backup file",
104
105
	 assign_string,  0, 1, "db/lyskomd-texts-backup",
         &param.textbackupfile_name},
106
    /* Various log files */
107
108
    {"Log file",
	 assign_string, 0, 1, "etc/server-log", &param.logfile_name},
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
    {"Log statistics",
	 assign_string,  0, 1, "etc/lyskomd-log", &param.statistic_name},
    {"Pid file",
	 assign_string,  0, 1, "etc/pid", &param.pid_name},
    {"Memory usage file",
	 assign_string,  0, 1, "etc/memory-usage", &param.memuse_name},
    /* Performance tuning parameters (milliseconds) */
    {"Idle timeout",
	 assign_int,     0, 1, "120000", &param.timeout},
    {"Garb timeout",
	 assign_int,     0, 1, "100", &param.garbtimeout},
    {"Sync timeout",
	 assign_int,     0, 1, "0", &param.synctimeout},
    /* Performance tuning parameters (minutes) */
    {"Garb interval",
	 assign_int,     0, 1, "1440", &param.garb_interval},
    {"Sync interval",
	 assign_int,     0, 1, "5", &param.sync_interval},
    {"Sync retry interval",
	 assign_int,     0, 1, "1", &param.sync_retry_interval},
    /* String limits */
    {"Max conference name length",
	 assign_int,     0, 1, "60", &param.conf_name_len},
    {"Max password length",
	 assign_int,     0, 1, "128", &param.pwd_len},
    {"Max what am I doing length",
	 assign_int,     0, 1, "60", &param.what_do_len},
    {"Max username length",
	 assign_int,     0, 1, "128", &param.username_len},
    {"Max text length",
	 assign_int,     0, 1, "131072", &param.text_len},
    {"Max broadcaset length",
	 assign_int,     0, 1, "1024", &param.broadcast_len},
    {"Max regexp length",
	 assign_int,     0, 1, "1024", &param.regexp_len},
    /* Text_stat limits */
    {"Max marks per person",
	 assign_int,     0, 1, "2048", &param.max_marks_person},
    {"Max marks per text",
	 assign_int,     0, 1, "1024", &param.max_marks_text},
    {"Max recipients per text",
	 assign_int,     0, 1, "512", &param.max_recipients},
    {"Max comments per text",
	 assign_int,     0, 1, "128", &param.max_comm},
    {"Max footnotes per text",
	 assign_int,     0, 1, "32", &param.max_foot},
    {"Max links per text",
	 assign_int,     0, 1, "512", &param.max_crea_misc},
    /* Other client-visible configuration */
    {"Max mark_as_read chunks",
	 assign_int,     0, 1, "128", &param.mark_as_read_chunk},
    {"Max super_conf loop",
	 assign_int,     0, 1, "17", &param.max_super_conf_loop},
    {"Default garb nice",
	 assign_int,     0, 1, "77", &param.default_nice},
    {"Max client transmit queue",
	 assign_int,     0, 1, "300", &param.maxqueuedsize},
    {"Max simultaneous client replies",
	 assign_int,     0, 1, "10", &param.maxdequeuelen},
168
169
    {"Open files",
         assign_int,     0, 1, "-1", &param.no_files},
170
171
172
173
174
175
176
177
178
    /* Security options */
    {"Anyone can create new persons",
	 assign_bool,    0, 1, "yes", &param.anyone_can_create_new_persons},
    {"Anyone can create new conferences",
	 assign_bool,    0, 1, "yes", &param.anyone_can_create_new_confs},
    {"Allow creation of persons before login",
	 assign_bool,    0, 1, "yes", &param.create_person_before_login},
    {"Default change name capability",
	 assign_bool,    0, 1, "on", &param.default_change_name},
179
180
    {"Log login",
	 assign_bool,    0, 1, "off", &param.log_login},
181
182
183
184
185
186
187
188
189
190
191
192
193
    /* Cache configuration */
    {"Cache conference limit",
	 assign_int,     0, 1, "20", &param.cache_conferences},
    {"Cache person limit",
	 assign_int,     0, 1, "20", &param.cache_persons},
    {"Cache text_stat limit",
	 assign_int,     0, 1, "20", &param.cache_text_stats},
    /* Echo the value to the log. */
    {"Echo",
	 log_param,      0, -1, NULL, NULL},
    /* Register a forbidden text number. */
    {"Jubel",
         jubel,          0, -1, NULL, NULL},
Per Cederqvist's avatar
Per Cederqvist committed
194
195
    {"Ident-authentication",
	ident_param,     0, 1, "try", &param.authentication_level},
196
197
    /* end marker */
    {NULL, NULL, 0, 0, NULL, NULL}};
Per Cederqvist's avatar
Per Cederqvist committed
198

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

Per Cederqvist's avatar
Per Cederqvist committed
201
/*
Per Cederqvist's avatar
Per Cederqvist committed
202
 * DEFAULT_DBASE_DIR can be overriden in the config file.  The default 
203
204
 * 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
205
206
 */

207
const char * DEFAULT_DBASE_DIR = DEFAULT_PREFIX;
Per Cederqvist's avatar
Per Cederqvist committed
208
const char *CONFIG_FILE = "etc/config";
Per Cederqvist's avatar
Per Cederqvist committed
209
210
211
212
213
214

/*
 * The following should always be true:
 * 0 <= SYNCTIMEOUT <= GARBTIMEOUT <= TIMEOUT
 * Times in milliseconds.
 */
215

Per Cederqvist's avatar
Per Cederqvist committed
216
/*
217
 * MAX_NO_OF_CONNECTIONS must be small enough.  See comment in config.h.
218
 */
Per Cederqvist's avatar
Per Cederqvist committed
219

Per Cederqvist's avatar
Per Cederqvist committed
220
#if defined(HAVE_GETDTABLESIZE) || defined(HAVE_SYSCONF)
221
222
int MAX_NO_OF_CONNECTIONS = 0;	/* Initialized by main(). */
#else
Per Cederqvist's avatar
Per Cederqvist committed
223
const int MAX_NO_OF_CONNECTIONS = (OPEN_MAX - PROTECTED_FDS);
224
#endif
225

226
227
/* What is whitespace? */
const unsigned char *WHITESPACE = (const unsigned char *)" \t\f\n\r";
228

229
230
231
232
233
234
235
static Success
log_param(const char *val, const struct parameter *par)
{
    if (val != NULL)
	log ("config: %s\n", val);
    return OK;
}
Per Cederqvist's avatar
Per Cederqvist committed
236

237
238
239
240
241
242
243
244
static Success
jubel(const char *val, const struct parameter *par)
{
    long a, b, c;
    int res;
    
    if (val == NULL)
        return OK;
Per Cederqvist's avatar
Per Cederqvist committed
245

246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
    res = sscanf(val, "%ld %ld %ld", &a, &b, &c);
    switch (res)
    {
    case 3:
	register_jubel (a, b, c);
	break;
    case 2:
	register_jubel (a, 0, b);
	break;
    default:
	log ("%s expecting 2 or 3 integers as args\n", par->name);
	return  FAILURE;
    }
    return OK;
}
Per Cederqvist's avatar
Per Cederqvist committed
261

Per Cederqvist's avatar
Per Cederqvist committed
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
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
    {
	log ("%s expects \"never\", \"try\" or \"required\" as argument\n",
	     par->name);
	return FAILURE;
    }
    return OK;
}

291
292
293
294
295
296
297
void
read_configuration(const char *conf_file)
{
    read_config(conf_file, parameters);
    
    /* FIXME///+++ Check config parameters for sanity */
}
Per Cederqvist's avatar
Per Cederqvist committed
298