4 * This function reads the citadel.config file. It should be called at
5 * the beginning of EVERY Citadel program.
19 #include "serv_extensions.h"
25 * get_config() is called during the initialization of any program which
26 * directly accesses Citadel data files. It verifies the system's integrity
27 * and reads citadel.config into memory.
29 void get_config(void) {
33 if (chdir(ctdl_bbsbase_dir) != 0) {
35 "This program could not be started.\n"
36 "Unable to change directory to %s\n"
42 cfp = fopen(file_citadel_config, "rb");
44 fprintf(stderr, "This program could not be started.\n"
49 exit(CTDLEXIT_CONFIG);
51 fread((char *) &config, sizeof(struct config), 1, cfp);
52 if (fstat(fileno(cfp), &st)) {
53 perror(file_citadel_config);
54 exit(CTDLEXIT_CONFIG);
57 if (st.st_uid != CTDLUID) {
58 fprintf(stderr, "%s must be owned by uid="F_UID_T" but "F_UID_T" owns it!\n",
59 file_citadel_config, CTDLUID, st.st_uid);
60 exit(CTDLEXIT_CONFIG);
62 int desired_mode = (S_IFREG | S_IRUSR | S_IWUSR) ;
63 if (st.st_mode != desired_mode) {
64 fprintf(stderr, "%s must be set to permissions mode %03o but they are %03o\n",
65 file_citadel_config, desired_mode, st.st_mode);
66 exit(CTDLEXIT_CONFIG);
71 if (config.c_setup_level < REV_MIN) {
72 fprintf(stderr, "config: Your data files are out of date. ");
73 fprintf(stderr, "Run setup to update them.\n");
75 " This program requires level %d.%02d\n",
76 (REV_LEVEL / 100), (REV_LEVEL % 100));
78 " Data files are currently at %d.%02d\n",
79 (config.c_setup_level / 100),
80 (config.c_setup_level % 100));
84 /* Default maximum message length is 10 megabytes. This is site
85 * configurable. Also check to make sure the limit has not been
86 * set below 8192 bytes.
88 if (config.c_maxmsglen <= 0)
89 config.c_maxmsglen = 10485760;
90 if (config.c_maxmsglen < 8192)
91 config.c_maxmsglen = 8192;
93 /* Default lower and upper limits on number of worker threads */
95 if (config.c_min_workers < 3) /* no less than 3 */
96 config.c_min_workers = 5;
98 if (config.c_max_workers == 0) /* default maximum */
99 config.c_max_workers = 256;
101 if (config.c_max_workers < config.c_min_workers) /* max >= min */
102 config.c_max_workers = config.c_min_workers;
104 /* Networking more than once every five minutes just isn't sane */
105 if (config.c_net_freq == 0L)
106 config.c_net_freq = 3600L; /* once per hour default */
107 if (config.c_net_freq < 300L)
108 config.c_net_freq = 300L;
113 * Occasionally, we will need to write the config file, because some operations
114 * change site-wide parameters.
116 void put_config(void)
120 if ((cfp = fopen(file_citadel_config, "rb+")) == NULL)
121 perror(file_citadel_config);
123 fwrite((char *) &config, sizeof(struct config), 1, cfp);