2 * This function reads the citadel.config file. It should be called at
3 * the beginning of EVERY Citadel program.
20 char bbs_home_directory[PATH_MAX] = BBSDIR;
21 int home_specified = 0;
24 * get_config() is called during the initialization of any program which
25 * directly accesses Citadel data files. It verifies the system's integrity
26 * and reads citadel.config into memory.
28 void get_config(void) {
32 if (chdir(home_specified ? bbs_home_directory : BBSDIR) != 0) {
34 "This program could not be started.\n"
35 "Unable to change directory to %s\n"
37 (home_specified ? bbs_home_directory : BBSDIR),
41 cfp = fopen("citadel.config", "rb");
43 fprintf(stderr, "This program could not be started.\n"
44 "Unable to open %s/citadel.config\n"
46 (home_specified ? bbs_home_directory : BBSDIR),
50 fread((char *) &config, sizeof(struct config), 1, cfp);
51 if (fstat(fileno(cfp), &st)) {
52 perror("citadel.config");
55 if (st.st_uid != BBSUID || st.st_mode != (S_IFREG | S_IRUSR | S_IWUSR)) {
56 fprintf(stderr, "check the permissions on citadel.config\n");
61 if (config.c_setup_level != REV_LEVEL) {
62 fprintf(stderr, "config: Your data files are out of date. ");
63 fprintf(stderr, "Run setup to update them.\n");
65 " This program requires level %d.%02d\n",
66 (REV_LEVEL / 100), (REV_LEVEL % 100));
68 " Data files are currently at %d.%02d\n",
69 (config.c_setup_level / 100),
70 (config.c_setup_level % 100));
74 /* Default maximum message length is 'unlimited' (max int)
75 * and the minimum is 8192
77 if (config.c_maxmsglen <= 0)
78 config.c_maxmsglen = INT_MAX;
79 if (config.c_maxmsglen < 8192)
80 config.c_maxmsglen = 8192;
82 /* Default number of worker threads is 15 and the minimum is 5
84 /* Can't have fewer than two worker threads */
85 if (config.c_worker_threads == 0)
86 config.c_worker_threads = 15;
87 if (config.c_worker_threads < 5)
88 config.c_worker_threads = 5;
94 * Occasionally, we will need to write the config file, because some operations
95 * change site-wide parameters.
101 if ((cfp = fopen("citadel.config", "rb+")) == NULL)
102 perror("citadel.config");
104 fwrite((char *) &config, sizeof(struct config), 1, cfp);