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 "Cannot start.\nThere is no Citadel installation in %s\n%s\n",
35 (home_specified ? bbs_home_directory : BBSDIR),
39 cfp = fopen("citadel.config", "rb");
41 fprintf(stderr, "Cannot start.\n");
42 fprintf(stderr, "There is no citadel.config in %s\n%s\n",
43 (home_specified ? bbs_home_directory : BBSDIR),
47 fread((char *) &config, sizeof(struct config), 1, cfp);
48 if (fstat(fileno(cfp), &st)) {
49 perror("citadel.config");
52 if (st.st_uid != BBSUID || st.st_mode != (S_IFREG | S_IRUSR | S_IWUSR)) {
53 fprintf(stderr, "check the permissions on citadel.config\n");
58 if (config.c_setup_level != REV_LEVEL) {
59 fprintf(stderr, "config: Your data files are out of date. ");
60 fprintf(stderr, "Run setup to update them.\n");
62 " This program requires level %d.%02d\n",
63 (REV_LEVEL / 100), (REV_LEVEL % 100));
65 " Data files are currently at %d.%02d\n",
66 (config.c_setup_level / 100),
67 (config.c_setup_level % 100));
71 /* Default maximum message length is 'unlimited' (max int)
72 * and the minimum is 8192
74 if (config.c_maxmsglen <= 0)
75 config.c_maxmsglen = INT_MAX;
76 if (config.c_maxmsglen < 8192)
77 config.c_maxmsglen = 8192;
83 * Occasionally, we will need to write the config file, because some operations
84 * change site-wide parameters.
90 if ((cfp = fopen("citadel.config", "rb+")) == NULL)
91 perror("citadel.config");
93 fwrite((char *) &config, sizeof(struct config), 1, cfp);