4 * This function reads the citadel.config file. It should be called at
5 * the beginning of EVERY Citadel program.
23 #include "serv_extensions.h"
27 char bbs_home_directory[PATH_MAX] = BBSDIR;
28 int home_specified = 0;
31 * get_config() is called during the initialization of any program which
32 * directly accesses Citadel data files. It verifies the system's integrity
33 * and reads citadel.config into memory.
35 void get_config(void) {
39 if (chdir(home_specified ? bbs_home_directory : BBSDIR) != 0) {
41 "This program could not be started.\n"
42 "Unable to change directory to %s\n"
44 (home_specified ? bbs_home_directory : BBSDIR),
48 cfp = fopen("citadel.config", "rb");
50 fprintf(stderr, "This program could not be started.\n"
51 "Unable to open %s/citadel.config\n"
53 (home_specified ? bbs_home_directory : BBSDIR),
57 fread((char *) &config, sizeof(struct config), 1, cfp);
58 if (fstat(fileno(cfp), &st)) {
59 perror("citadel.config");
63 if (st.st_uid != BBSUID || st.st_mode != (S_IFREG | S_IRUSR | S_IWUSR)) {
64 fprintf(stderr, "check the permissions on citadel.config\n");
70 if (config.c_setup_level < REV_MIN) {
71 fprintf(stderr, "config: Your data files are out of date. ");
72 fprintf(stderr, "Run setup to update them.\n");
74 " This program requires level %d.%02d\n",
75 (REV_LEVEL / 100), (REV_LEVEL % 100));
77 " Data files are currently at %d.%02d\n",
78 (config.c_setup_level / 100),
79 (config.c_setup_level % 100));
83 /* Default maximum message length is 10 megabytes. This is site
84 * configurable. Also check to make sure the limit has not been
85 * set below 8192 bytes.
87 if (config.c_maxmsglen <= 0)
88 config.c_maxmsglen = 10485760;
89 if (config.c_maxmsglen < 8192)
90 config.c_maxmsglen = 8192;
92 /* Default lower and upper limits on number of worker threads */
94 if (config.c_min_workers < 3) /* no less than 3 */
95 config.c_min_workers = 5;
97 if (config.c_max_workers == 0) /* default maximum */
98 config.c_max_workers = 256;
100 if (config.c_max_workers < config.c_min_workers) /* max >= min */
101 config.c_max_workers = config.c_min_workers;
103 /* Networking more than once every five minutes just isn't sane */
104 if (config.c_net_freq == 0L)
105 config.c_net_freq = 3600L; /* once per hour default */
106 if (config.c_net_freq < 300L)
107 config.c_net_freq = 300L;
112 * Occasionally, we will need to write the config file, because some operations
113 * change site-wide parameters.
115 void put_config(void)
119 if ((cfp = fopen("citadel.config", "rb+")) == NULL)
120 perror("citadel.config");
122 fwrite((char *) &config, sizeof(struct config), 1, cfp);