Select Git revision
server-config.c
server-config.c 14.10 KiB
/*
* $Id: server-config.c,v 0.56 1999/04/18 13:10:20 ceder Exp $
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996 Lysator Academic Computer Association.
*
* 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.
*/
/*
* server-config.c
*
* This is in a .c file to make it possible to change a value without having
* to recompile the entire server (or, in fact, anything!)
*
* Compile with -DDEFAULT_PREFIX='"/usr/lyskom"' or something similar.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
static const char *
rcsid = "$Id: server-config.c,v 0.56 1999/04/18 13:10:20 ceder Exp $";
#include "rcs.h"
USE(rcsid);
#include <limits.h>
#include <stdio.h>
#include <sys/types.h>
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include <time.h>
#include <stdarg.h>
#include <assert.h>
#include "server/smalloc.h"
#include "kom-config.h"
#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"
#include "unused.h"
struct kom_par param;
static Success log_param(const char *val, const struct parameter *par);
static Success jubel(const char *val, const struct parameter *par);
static Success ident_param(const char *val, const struct parameter *par);
/* 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. */
static const struct parameter parameters[] = {
/* "Normal" configuration */
{"Locale",
assign_string, 0, 1, NULL, ¶m.use_locale},
{"Force ISO 8859-1",
assign_bool, 0, 1, "no", ¶m.force_iso_8859_1},
{"Prefix",
assign_string, 0, 1, DEFAULT_PREFIX, ¶m.dbase_dir},
{"Send async",
assign_bool, 0, 1, "1", ¶m.send_async_messages},
{"Client port",
assign_string, 1, 1, NULL, ¶m.ip_client_port},
{"Mux port",
assign_string, 1, 1, NULL, ¶m.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},
{"Garb",
assign_bool, 0, 1, "on", ¶m.garb_enable},
#ifndef NDEBUG
{"Never save",
assign_bool, 0, 1, "no", ¶m.never_save},
#endif
#ifdef LOGACCESSES
{"Log accesses",
assign_string, 0, 1, NULL, ¶m.logaccess_file},
#endif
/* The database files. */
{"Data file",
assign_string, 0, 1, "db/lyskomd-data", ¶m.datafile_name},
{"Backup file",
assign_string, 0, 1, "db/lyskomd-backup", ¶m.backupfile_name},
{"Backup file 2",
assign_string, 0, 1, "db/lyskomd-backup-prev",
¶m.backupfile_name_2},
{"Text file",
assign_string, 0, 1, "db/lyskomd-texts", ¶m.textfile_name},
{"Text backup file",
assign_string, 0, 1, "db/lyskomd-texts-backup",
¶m.textbackupfile_name},
/* Various log files */
{"Log file",
assign_string, 0, 1, "etc/server-log", ¶m.logfile_name},
{"Log statistics",
assign_string, 0, 1, "etc/lyskomd-log", ¶m.statistic_name},
{"Pid file",
assign_string, 0, 1, "etc/pid", ¶m.pid_name},
{"Memory usage file",
assign_string, 0, 1, "etc/memory-usage", ¶m.memuse_name},
/* Other files. */
{"Aux-item definition file",
assign_string, 0, 1, "etc/aux-items.conf", ¶m.aux_def_file},
{"Status file",
assign_string, 0, 1, "etc/status", ¶m.status_file},
/* Where to dump core. */
{"Core directory",
assign_string, 0, 1, "cores", ¶m.core_dir},
/* Performance tuning parameters (milliseconds) */
{"Idle timeout",
assign_int, 0, 1, "120000", ¶m.timeout},
{"Garb timeout",
assign_int, 0, 1, "100", ¶m.garbtimeout},
{"Sync timeout",
assign_int, 0, 1, "0", ¶m.synctimeout},
/* Performance tuning parameters (minutes) */
{"Garb interval",
assign_int, 0, 1, "1440", ¶m.garb_interval},
{"Permissive sync",
assign_bool, 0, 1, "off", ¶m.permissive_sync},
{"Sync interval",
assign_int, 0, 1, "5", ¶m.sync_interval},
{"Sync retry interval",
assign_int, 0, 1, "1", ¶m.sync_retry_interval},
/* More performance tuning. */
{"Max client transmit queue",
assign_int, 0, 1, "300", ¶m.maxqueuedsize},
{"Max simultaneous client replies",
assign_int, 0, 1, "10", ¶m.maxdequeuelen},
{"Open files",
assign_int, 0, 1, "-1", ¶m.no_files},
/* String limits */
{"Max conference name length",
assign_int, 0, 1, "60", ¶m.conf_name_len},
{"Max password length",
assign_int, 0, 1, "128", ¶m.pwd_len},
{"Max what am I doing length",
assign_int, 0, 1, "60", ¶m.what_do_len},
{"Max username length",
assign_int, 0, 1, "128", ¶m.username_len},
{"Max text length",
assign_int, 0, 1, "131072", ¶m.text_len},
{"Max broadcast length",
assign_int, 0, 1, "1024", ¶m.broadcast_len},
{"Max regexp length",
assign_int, 0, 1, "1024", ¶m.regexp_len},
/* Text_stat limits */
{"Max marks per person",
assign_int, 0, 1, "2048", ¶m.max_marks_person},
{"Max marks per text",
assign_int, 0, 1, "1024", ¶m.max_marks_text},
{"Max recipients per text",
assign_int, 0, 1, "512", ¶m.max_recipients},
{"Max comments per text",
assign_int, 0, 1, "128", ¶m.max_comm},
{"Max footnotes per text",
assign_int, 0, 1, "32", ¶m.max_foot},
{"Max links per text",
assign_int, 0, 1, "512", ¶m.max_crea_misc},
/* Other client-visible configuration */
{"Max mark_as_read chunks",
assign_int, 0, 1, "128", ¶m.mark_as_read_chunk},
{"Max accept_async len",
assign_int, 0, 1, "128", ¶m.accept_async_len},
{"Max aux_items added per call",
assign_int, 0, 1, "2048", ¶m.max_add_aux},
{"Max aux_items deleted per call",
assign_int, 0, 1, "128", ¶m.max_delete_aux},
{"Max super_conf loop",
assign_int, 0, 1, "17", ¶m.max_super_conf_loop},
{"Default garb nice",
assign_int, 0, 1, "77", ¶m.default_nice},
{"Default keep commented nice",
assign_int, 0, 1, "77", ¶m.default_keep_commented},
{"Regexps use collate table",
assign_bool, 0, 1, "on", ¶m.regex_use_collate_table},
/* Security options */
{"Anyone can create new persons",
assign_bool, 0, 1, "yes", ¶m.anyone_can_create_new_persons},
{"Anyone can create new conferences",
assign_bool, 0, 1, "yes", ¶m.anyone_can_create_new_confs},
{"Allow creation of persons before login",
assign_bool, 0, 1, "yes", ¶m.create_person_before_login},
{"Default change name capability",
assign_bool, 0, 1, "on", ¶m.default_change_name},
{"Add members by invitation",
assign_bool, 0, 1, "on", ¶m.invite_by_default},
{"Allow secret memberships",
assign_bool, 0, 1, "on", ¶m.secret_memberships},
{"Allow reinvitations",
assign_bool, 0, 1, "off", ¶m.allow_reinvite},
{"Log login",
assign_bool, 0, 1, "off", ¶m.log_login},
{"Ident-authentication",
ident_param, 0, 1, "try", ¶m.authentication_level},
/* Cache configuration */
{"Cache conference limit",
assign_int, 0, 1, "20", ¶m.cache_conferences},
{"Cache person limit",
assign_int, 0, 1, "20", ¶m.cache_persons},
{"Cache text_stat limit",
assign_int, 0, 1, "20", ¶m.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},
/* Configuration for support programs. */
{"Normal shutdown time",
assign_int, 0, 1, "21", ¶m.normal_shutdown_time},
{"Mail after downtime",
assign_int, 0, 1, "60", ¶m.downtime_mail_start},
{"Mail until downtime",
assign_int, 0, 1, "120", ¶m.downtime_mail_end},
{"lyskomd path",
assign_string, 0, 1, "bin/lyskomd", ¶m.lyskomd_path},
{"savecore path",
assign_string, 0, 1, "bin/savecore", ¶m.savecore_path},
/* end marker */
{NULL, NULL, 0, 0, NULL, NULL}};
/* Where to save things. These are used by lyskomd and dbck. */
/*
* DEFAULT_DBASE_DIR can be overriden in the config file. The default
* config file is found in DEFAULT_DBASE_DIR/CONFIG_FILE (before
* DEFAULT_DBASE_DIR is overriden, of course).
*/
const char * DEFAULT_DBASE_DIR = DEFAULT_PREFIX;
const char *CONFIG_FILE = "etc/config";
/*
* The following should always be true:
* 0 <= SYNCTIMEOUT <= GARBTIMEOUT <= TIMEOUT
* Times in milliseconds.
*/
/*
* MAX_NO_OF_CONNECTIONS must be small enough. See comment in kom-config.h.
*/
#if defined(HAVE_GETDTABLESIZE) || defined(HAVE_SYSCONF)
int MAX_NO_OF_CONNECTIONS = 0; /* Initialized by main(). */
#else
const int MAX_NO_OF_CONNECTIONS = (OPEN_MAX - PROTECTED_FDS);
#endif
/* What is whitespace? */
const unsigned char *WHITESPACE = (const unsigned char *)" \t\n\r";
static Success
log_param(const char *val, const struct parameter *UNUSED(par))
{
if (val != NULL)
log ("config: %s\n", val);
return OK;
}
static Success
jubel(const char *val, const struct parameter *par)
{
long a, b, c;
int res;
if (val == NULL)
return OK;
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;
}
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;
}
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;
}
static const char *
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");
}
static Bool
check_abs_path(char **path)
{
if (**path == '/')
return FALSE;
log("Parameter '%s' must be an absolute path when 'Prefix' is empty.\n",
param_name(path));
return TRUE;
}
void
read_configuration(const char *conf_file)
{
Bool err = FALSE;
read_config(conf_file, parameters);
assert(param.dbase_dir != NULL);
assert(param.datafile_name != NULL);
assert(param.backupfile_name != NULL);
assert(param.backupfile_name_2 != NULL);
assert(param.textfile_name != NULL);
assert(param.textbackupfile_name != NULL);
assert(param.statistic_name != NULL);
assert(param.pid_name != NULL);
assert(param.memuse_name != NULL);
assert(param.logfile_name != NULL);
assert(param.aux_def_file != NULL);
assert(param.status_file != NULL);
assert(param.core_dir != NULL);
assert(param.lyskomd_path != NULL);
assert(param.savecore_path != NULL);
if (strlen(param.dbase_dir) > 0)
{
if (param.dbase_dir[0] != '/')
{
log("The 'Prefix' parameter must be an absolute path.\n");
err = TRUE;
}
add_prefix(¶m.datafile_name);
add_prefix(¶m.backupfile_name);
add_prefix(¶m.backupfile_name_2);
add_prefix(¶m.textfile_name);
add_prefix(¶m.textbackupfile_name);
add_prefix(¶m.statistic_name);
add_prefix(¶m.pid_name);
add_prefix(¶m.memuse_name);
add_prefix(¶m.logfile_name);
add_prefix(¶m.aux_def_file);
add_prefix(¶m.status_file);
add_prefix(¶m.core_dir);
add_prefix(¶m.lyskomd_path);
add_prefix(¶m.savecore_path);
}
else
{
err |= check_abs_path(¶m.datafile_name);
err |= check_abs_path(¶m.backupfile_name);
err |= check_abs_path(¶m.backupfile_name_2);
err |= check_abs_path(¶m.textfile_name);
err |= check_abs_path(¶m.textbackupfile_name);
err |= check_abs_path(¶m.statistic_name);
err |= check_abs_path(¶m.pid_name);
err |= check_abs_path(¶m.memuse_name);
err |= check_abs_path(¶m.logfile_name);
err |= check_abs_path(¶m.aux_def_file);
err |= check_abs_path(¶m.status_file);
err |= check_abs_path(¶m.core_dir);
err |= check_abs_path(¶m.lyskomd_path);
err |= check_abs_path(¶m.savecore_path);
}
/* FIXME///+++ Check config parameters for sanity */
if (err)
restart_kom("Please fix the above configuration errors.\n");
}