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");
57 if (config.c_setup_level != REV_LEVEL) {
58 fprintf(stderr, "config: Your data files are out of date. ");
59 fprintf(stderr, "Run setup to update them.\n");
61 " This program requires level %d.%02d\n",
62 (REV_LEVEL / 100), (REV_LEVEL % 100));
64 " Data files are currently at %d.%02d\n",
65 (config.c_setup_level / 100),
66 (config.c_setup_level % 100));
73 * Occasionally, we will need to write the config file, because some operations
74 * change site-wide parameters.
80 if ((cfp = fopen("citadel.config", "rb+")) == NULL)
81 perror("citadel.config");
83 fwrite((char *) &config, sizeof(struct config), 1, cfp);