2 * Read and write the citadel.config file
4 * Copyright (c) 1987-2014 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
17 #include <sys/utsname.h>
18 #include <libcitadel.h>
20 #include "ctdl_module.h"
23 struct configlen configlen;
26 * Put some sane default values into our configuration. Some will be overridden when we run setup.
28 void brand_new_installation_set_defaults(void) {
31 struct utsname my_utsname;
34 /* Determine our host name, in case we need to use it as a default */
36 memset(&configlen, 0, sizeof(struct configlen));
37 /* set some sample/default values in place of blanks... */
38 configlen.c_nodename = extract_token(config.c_nodename, my_utsname.nodename, 0, '.', sizeof config.c_nodename);
39 if (IsEmptyStr(config.c_fqdn) ) {
40 if ((he = gethostbyname(my_utsname.nodename)) != NULL) {
41 configlen.c_fqdn = safestrncpy(config.c_fqdn, he->h_name, sizeof config.c_fqdn);
44 configlen.c_fqdn = safestrncpy(config.c_fqdn, my_utsname.nodename, sizeof config.c_fqdn);
48 configlen.c_humannode = safestrncpy(config.c_humannode, "Citadel Server", sizeof config.c_humannode);
49 configlen.c_phonenum = safestrncpy(config.c_phonenum, "US 800 555 1212", sizeof config.c_phonenum);
51 configlen.c_moreprompt = safestrncpy(config.c_moreprompt, "<more>", sizeof config.c_moreprompt);
52 configlen.c_twitroom = safestrncpy(config.c_twitroom, "Trashcan", sizeof config.c_twitroom);
53 configlen.c_baseroom = safestrncpy(config.c_baseroom, BASEROOM, sizeof config.c_baseroom);
54 configlen.c_aideroom = safestrncpy(config.c_aideroom, "Aide", sizeof config.c_aideroom);
55 config.c_port_number = 504;
56 config.c_sleeping = 900;
58 if (config.c_ctdluid == 0) {
59 pw = getpwnam("citadel");
61 config.c_ctdluid = pw->pw_uid;
64 if (config.c_ctdluid == 0) {
67 config.c_ctdluid = pw->pw_uid;
70 if (config.c_ctdluid == 0) {
71 pw = getpwnam("guest");
73 config.c_ctdluid = pw->pw_uid;
76 if (config.c_createax == 0) {
77 config.c_createax = 3;
81 * Default port numbers for various services
83 config.c_smtp_port = 25;
84 config.c_pop3_port = 110;
85 config.c_imap_port = 143;
86 config.c_msa_port = 587;
87 config.c_smtps_port = 465;
88 config.c_pop3s_port = 995;
89 config.c_imaps_port = 993;
90 config.c_pftcpdict_port = -1 ;
91 config.c_managesieve_port = 2020;
92 config.c_xmpp_c2s_port = 5222;
93 config.c_xmpp_s2s_port = 5269;
94 config.c_nntp_port = 119;
99 configlen.c_nodename = strlen(config.c_nodename);
100 configlen.c_fqdn = strlen(config.c_fqdn);
101 configlen.c_humannode = strlen(config.c_humannode);
102 configlen.c_phonenum = strlen(config.c_phonenum);
103 configlen.c_twitroom = strlen(config.c_twitroom);
104 configlen.c_moreprompt = strlen(config.c_moreprompt);
105 configlen.c_site_location = strlen(config.c_site_location);
106 configlen.c_sysadm = strlen(config.c_sysadm);
107 configlen.c_niu_2 = strlen(config.c_niu_2);
108 configlen.c_ip_addr = strlen(config.c_ip_addr);
109 configlen.c_logpages = strlen(config.c_logpages);
110 configlen.c_baseroom = strlen(config.c_baseroom);
111 configlen.c_aideroom = strlen(config.c_aideroom);
112 configlen.c_ldap_host = strlen(config.c_ldap_host);
113 configlen.c_ldap_base_dn = strlen(config.c_ldap_base_dn);
114 configlen.c_ldap_bind_dn = strlen(config.c_ldap_bind_dn);
115 configlen.c_ldap_bind_pw = strlen(config.c_ldap_bind_pw);
116 configlen.c_journal_dest = strlen(config.c_journal_dest);
117 configlen.c_default_cal_zone = strlen(config.c_default_cal_zone);
118 configlen.c_funambol_host = strlen(config.c_funambol_host);
119 configlen.c_funambol_source = strlen(config.c_funambol_source);
120 configlen.c_funambol_auth = strlen(config.c_funambol_auth);
121 configlen.c_master_user = strlen(config.c_master_user);
122 configlen.c_master_pass = strlen(config.c_master_pass);
123 configlen.c_pager_program = strlen(config.c_pager_program);
127 * get_config() is called during the initialization of Citadel server.
128 * It verifies the system's integrity and reads citadel.config into memory.
130 void get_config(void) {
134 if (chdir(ctdl_bbsbase_dir) != 0) {
136 "This program could not be started.\nUnable to change directory to %s\nError: %s\n",
143 memset(&config, 0, sizeof(struct config));
144 cfp = fopen(file_citadel_config, "rb");
146 rv = fread((char *) &config, sizeof(struct config), 1, cfp);
150 "Warning: The config file %s has unexpected size. \n",
158 brand_new_installation_set_defaults();
161 /* Ensure that we are linked to the correct version of libcitadel */
162 if (libcitadel_version_number() < LIBCITADEL_VERSION_NUMBER) {
163 fprintf(stderr, " You are running libcitadel version %d.%02d\n",
164 (libcitadel_version_number() / 100), (libcitadel_version_number() % 100));
165 fprintf(stderr, "citserver was compiled against version %d.%02d\n",
166 (LIBCITADEL_VERSION_NUMBER / 100), (LIBCITADEL_VERSION_NUMBER % 100));
167 exit(CTDLEXIT_LIBCITADEL);
170 /* Only allow LDAP auth mode if we actually have LDAP support */
172 if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
173 fprintf(stderr, "Your system is configured for LDAP authentication,\n"
174 "but you are running a server built without OpenLDAP support.\n");
175 exit(CTDL_EXIT_UNSUP_AUTH);
179 /* Default maximum message length is 10 megabytes. This is site
180 * configurable. Also check to make sure the limit has not been
181 * set below 8192 bytes.
183 if (config.c_maxmsglen <= 0)
184 config.c_maxmsglen = 10485760;
185 if (config.c_maxmsglen < 8192)
186 config.c_maxmsglen = 8192;
188 /* Default lower and upper limits on number of worker threads */
190 if (config.c_min_workers < 3) /* no less than 3 */
191 config.c_min_workers = 5;
193 if (config.c_max_workers == 0) /* default maximum */
194 config.c_max_workers = 256;
196 if (config.c_max_workers < config.c_min_workers) /* max >= min */
197 config.c_max_workers = config.c_min_workers;
199 /* Networking more than once every five minutes just isn't sane */
200 if (config.c_net_freq == 0L)
201 config.c_net_freq = 3600L; /* once per hour default */
202 if (config.c_net_freq < 300L)
203 config.c_net_freq = 300L;
205 /* Same goes for POP3 */
206 if (config.c_pop3_fetch == 0L)
207 config.c_pop3_fetch = 3600L; /* once per hour default */
208 if (config.c_pop3_fetch < 300L)
209 config.c_pop3_fetch = 300L;
210 if (config.c_pop3_fastest == 0L)
211 config.c_pop3_fastest = 3600L; /* once per hour default */
212 if (config.c_pop3_fastest < 300L)
213 config.c_pop3_fastest = 300L;
215 /* "create new user" only works with native authentication mode */
216 if (config.c_auth_mode != AUTHMODE_NATIVE) {
217 config.c_disable_newu = 1;
221 long config_msgnum = 0;
224 * Occasionally, we will need to write the config file, because some operations
225 * change site-wide parameters.
227 void put_config(void)
230 int blocks_written = 0;
232 cfp = fopen(file_citadel_config, "w");
234 blocks_written = fwrite((char *) &config, sizeof(struct config), 1, cfp);
235 if (blocks_written == 1) {
236 chown(file_citadel_config, CTDLUID, (-1));
237 chmod(file_citadel_config, 0600);
243 syslog(LOG_EMERG, "%s: %s", file_citadel_config, strerror(errno));
248 void CtdlGetSysConfigBackend(long msgnum, void *userdata) {
249 config_msgnum = msgnum;
253 char *CtdlGetSysConfig(char *sysconfname) {
254 char hold_rm[ROOMNAMELEN];
257 struct CtdlMessage *msg;
260 strcpy(hold_rm, CC->room.QRname);
261 if (CtdlGetRoom(&CC->room, SYSCONFIGROOM) != 0) {
262 CtdlGetRoom(&CC->room, hold_rm);
267 /* We want the last (and probably only) config in this room */
268 begin_critical_section(S_CONFIG);
269 config_msgnum = (-1L);
270 CtdlForEachMessage(MSGS_LAST, 1, NULL, sysconfname, NULL,
271 CtdlGetSysConfigBackend, NULL);
272 msgnum = config_msgnum;
273 end_critical_section(S_CONFIG);
279 msg = CtdlFetchMessage(msgnum, 1);
281 conf = strdup(msg->cm_fields[eMesageText]);
289 CtdlGetRoom(&CC->room, hold_rm);
291 if (conf != NULL) do {
292 extract_token(buf, conf, 0, '\n', sizeof buf);
293 strcpy(conf, &conf[strlen(buf)+1]);
294 } while ( (!IsEmptyStr(conf)) && (!IsEmptyStr(buf)) );
300 void CtdlPutSysConfig(char *sysconfname, char *sysconfdata) {
301 CtdlWriteObject(SYSCONFIGROOM, sysconfname, sysconfdata, (strlen(sysconfdata)+1), NULL, 0, 1, 0);