/*
* Read and write the citadel.config file
*
- * Copyright (c) 1987-2012 by the citadel.org team
+ * Copyright (c) 1987-2014 by the citadel.org team
*
* This program is open source software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3.
struct config config;
struct configlen configlen;
+#define STR_NOT_EMPTY(CFG_FIELDNAME) if (IsEmptyStr(config.CFG_FIELDNAME)) \
+ syslog(LOG_EMERG, "configuration setting "#CFG_FIELDNAME" is empty, but must not - check your config!");
+
+#define TEST_PORT(CFG_PORT, DEFAULTPORT) \
+ if ((config.CFG_PORT < -1) || \
+ (config.CFG_PORT == 0) || \
+ (config.CFG_PORT > UINT16_MAX)) \
+ syslog(LOG_EMERG, "configuration setting "#CFG_PORT" is not -1 (disabled) or a valid TCP-Port - check your config! Default setting is: "#DEFAULTPORT);
+
+
+void validate_config(void) {
+/* these shouldn't be empty: */
+ STR_NOT_EMPTY(c_fqdn);
+
+ STR_NOT_EMPTY(c_baseroom);
+ STR_NOT_EMPTY(c_aideroom);
+ STR_NOT_EMPTY(c_twitroom);
+ STR_NOT_EMPTY(c_nodename);
+ STR_NOT_EMPTY(c_default_cal_zone);
+
+/* we bind a lot of ports: */
+ TEST_PORT(c_smtp_port, 25);
+ TEST_PORT(c_pop3_port, 110);
+ TEST_PORT(c_imap_port, 143);
+ TEST_PORT(c_msa_port, 587);
+ TEST_PORT(c_port_number, 504);
+ TEST_PORT(c_smtps_port, 465);
+ TEST_PORT(c_pop3s_port, 995);
+ TEST_PORT(c_imaps_port, 993);
+ TEST_PORT(c_pftcpdict_port, -1);
+ TEST_PORT(c_managesieve_port, 2020);
+ TEST_PORT(c_xmpp_c2s_port, 5222);
+ TEST_PORT(c_xmpp_s2s_port, 5269);
+ TEST_PORT(c_nntp_port, 119);
+ TEST_PORT(c_nntps_port, 563);
+
+ if (config.c_ctdluid == 0)
+ syslog(LOG_EMERG, "citadel should not be configured to run as root! Check the value of c_ctdluid");
+ else if (getpwuid(CTDLUID) == NULL)
+ syslog(LOG_EMERG, "The UID (%d) citadel is configured to use is not defined in your system (/etc/passwd?)! Check the value of c_ctdluid", CTDLUID);
+
+}
+
/*
* Put some sane default values into our configuration. Some will be overridden when we run setup.
*/
config.c_managesieve_port = 2020;
config.c_xmpp_c2s_port = 5222;
config.c_xmpp_s2s_port = 5269;
+ config.c_nntp_port = 119;
+ config.c_nntps_port = 563;
}
void setcfglen(void)
FILE *cfp;
int blocks_written = 0;
- if ((cfp = fopen(file_citadel_config, "w")) != NULL) {
+ cfp = fopen(file_citadel_config, "w");
+ if (cfp != NULL) {
blocks_written = fwrite((char *) &config, sizeof(struct config), 1, cfp);
if (blocks_written == 1) {
- fclose(cfp);
chown(file_citadel_config, CTDLUID, (-1));
chmod(file_citadel_config, 0600);
+ fclose(cfp);
return;
}
+ fclose(cfp);
}
syslog(LOG_EMERG, "%s: %s", file_citadel_config, strerror(errno));
}