4 * Read and write the citadel.config file
6 * Copyright (c) 1987-2009 by the citadel.org team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <libcitadel.h>
37 #include "ctdl_module.h"
43 * get_config() is called during the initialization of any program which
44 * directly accesses Citadel data files. It verifies the system's integrity
45 * and reads citadel.config into memory.
47 void get_config(void) {
52 if (chdir(ctdl_bbsbase_dir) != 0) {
54 "This program could not be started.\n"
55 "Unable to change directory to %s\n"
61 cfp = fopen(file_citadel_config, "rb");
63 fprintf(stderr, "This program could not be started.\n"
68 exit(CTDLEXIT_CONFIG);
70 memset(&config, 0, sizeof(struct config));
71 rv = fread((char *) &config, sizeof(struct config), 1, cfp);
72 if (rv != sizeof(struct config))
75 "Warning: The config file %s has unexpected size. \n",
78 if (fstat(fileno(cfp), &st)) {
79 perror(file_citadel_config);
80 exit(CTDLEXIT_CONFIG);
84 if (st.st_uid != CTDLUID) {
85 fprintf(stderr, "%s must be owned by uid="F_UID_T" but "F_UID_T" owns it!\n",
86 file_citadel_config, CTDLUID, st.st_uid);
87 exit(CTDLEXIT_CONFIG);
89 int desired_mode = (S_IFREG | S_IRUSR | S_IWUSR) ;
90 if (st.st_mode != desired_mode) {
91 fprintf(stderr, "%s must be set to permissions mode %03o but they are %03o\n",
92 file_citadel_config, (desired_mode & 0xFFF), (st.st_mode & 0xFFF));
93 exit(CTDLEXIT_CONFIG);
99 /* Ensure that we are linked to the correct version of libcitadel */
100 if (libcitadel_version_number() < LIBCITADEL_VERSION_NUMBER) {
101 fprintf(stderr, " You are running libcitadel version %d.%02d\n",
102 (libcitadel_version_number() / 100), (libcitadel_version_number() % 100));
103 fprintf(stderr, "citserver was compiled against version %d.%02d\n",
104 (LIBCITADEL_VERSION_NUMBER / 100), (LIBCITADEL_VERSION_NUMBER % 100));
105 exit(CTDLEXIT_LIBCITADEL);
108 /* Only allow LDAP auth mode if we actually have LDAP support */
110 if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
111 fprintf(stderr, "Your system is configured for LDAP authentication,\n"
112 "but you are running a server built without OpenLDAP support.\n");
113 exit(CTDL_EXIT_UNSUP_AUTH);
117 /* Check to see whether 'setup' must first be run to update data file formats */
118 if (config.c_setup_level < REV_MIN) {
119 fprintf(stderr, "Your data files are out of date. Run setup to update them.\n");
120 fprintf(stderr, " This program requires level %d.%02d\n",
121 (REV_LEVEL / 100), (REV_LEVEL % 100));
122 fprintf(stderr, " Data files are currently at %d.%02d\n",
123 (config.c_setup_level / 100),
124 (config.c_setup_level % 100));
128 /* Default maximum message length is 10 megabytes. This is site
129 * configurable. Also check to make sure the limit has not been
130 * set below 8192 bytes.
132 if (config.c_maxmsglen <= 0)
133 config.c_maxmsglen = 10485760;
134 if (config.c_maxmsglen < 8192)
135 config.c_maxmsglen = 8192;
137 /* Default lower and upper limits on number of worker threads */
139 if (config.c_min_workers < 3) /* no less than 3 */
140 config.c_min_workers = 5;
142 if (config.c_max_workers == 0) /* default maximum */
143 config.c_max_workers = 256;
145 if (config.c_max_workers < config.c_min_workers) /* max >= min */
146 config.c_max_workers = config.c_min_workers;
148 /* Networking more than once every five minutes just isn't sane */
149 if (config.c_net_freq == 0L)
150 config.c_net_freq = 3600L; /* once per hour default */
151 if (config.c_net_freq < 300L)
152 config.c_net_freq = 300L;
154 /* Same goes for POP3 */
155 if (config.c_pop3_fetch == 0L)
156 config.c_pop3_fetch = 3600L; /* once per hour default */
157 if (config.c_pop3_fetch < 300L)
158 config.c_pop3_fetch = 300L;
159 if (config.c_pop3_fastest == 0L)
160 config.c_pop3_fastest = 3600L; /* once per hour default */
161 if (config.c_pop3_fastest < 300L)
162 config.c_pop3_fastest = 300L;
164 /* "create new user" only works with native authentication mode */
165 if (config.c_auth_mode != AUTHMODE_NATIVE) {
166 config.c_disable_newu = 1;
172 * Occasionally, we will need to write the config file, because some operations
173 * change site-wide parameters.
175 void put_config(void)
180 if ((cfp = fopen(file_citadel_config, "rb+")) == NULL)
181 perror(file_citadel_config);
183 rv = fwrite((char *) &config, sizeof(struct config), 1, cfp);