4 * This function reads the citadel.config file. It should be called at
5 * the beginning of EVERY Citadel program.
17 #include <libcitadel.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);
58 if (st.st_uid != CTDLUID) {
59 fprintf(stderr, "%s must be owned by uid="F_UID_T" but "F_UID_T" owns it!\n",
60 file_citadel_config, CTDLUID, st.st_uid);
61 exit(CTDLEXIT_CONFIG);
63 int desired_mode = (S_IFREG | S_IRUSR | S_IWUSR) ;
64 if (st.st_mode != desired_mode) {
65 fprintf(stderr, "%s must be set to permissions mode %03o but they are %03o\n",
66 file_citadel_config, (desired_mode & 0xFFF), (st.st_mode & 0xFFF));
67 exit(CTDLEXIT_CONFIG);
73 /* Ensure that we are linked to the correct version of libcitadel */
74 if (libcitadel_version_number() < LIBCITADEL_VERSION_NUMBER) {
75 fprintf(stderr, " You are running libcitadel version %d.%02d\n",
76 (libcitadel_version_number() / 100), (libcitadel_version_number() % 100));
77 fprintf(stderr, "citserver was compiled against version %d.%02d\n",
78 (LIBCITADEL_VERSION_NUMBER / 100), (LIBCITADEL_VERSION_NUMBER % 100));
79 exit(CTDLEXIT_LIBCITADEL);
82 /* Only allow LDAP auth mode if we actually have LDAP support */
84 if (config.c_auth_mode == AUTHMODE_LDAP) {
85 fprintf(stderr, "Your system is configured for LDAP authentication,\n"
86 "but you are running a server built without OpenLDAP support.\n");
87 exit(CTDL_EXIT_UNSUP_AUTH);
91 /* Check to see whether 'setup' must first be run to update data file formats */
92 if (config.c_setup_level < REV_MIN) {
93 fprintf(stderr, "Your data files are out of date. Run setup to update them.\n");
94 fprintf(stderr, " This program requires level %d.%02d\n",
95 (REV_LEVEL / 100), (REV_LEVEL % 100));
96 fprintf(stderr, " Data files are currently at %d.%02d\n",
97 (config.c_setup_level / 100),
98 (config.c_setup_level % 100));
102 /* Default maximum message length is 10 megabytes. This is site
103 * configurable. Also check to make sure the limit has not been
104 * set below 8192 bytes.
106 if (config.c_maxmsglen <= 0)
107 config.c_maxmsglen = 10485760;
108 if (config.c_maxmsglen < 8192)
109 config.c_maxmsglen = 8192;
111 /* Default lower and upper limits on number of worker threads */
113 if (config.c_min_workers < 3) /* no less than 3 */
114 config.c_min_workers = 5;
116 if (config.c_max_workers == 0) /* default maximum */
117 config.c_max_workers = 256;
119 if (config.c_max_workers < config.c_min_workers) /* max >= min */
120 config.c_max_workers = config.c_min_workers;
122 /* Networking more than once every five minutes just isn't sane */
123 if (config.c_net_freq == 0L)
124 config.c_net_freq = 3600L; /* once per hour default */
125 if (config.c_net_freq < 300L)
126 config.c_net_freq = 300L;
128 /* Same goes for POP3 */
129 if (config.c_pop3_fetch == 0L)
130 config.c_pop3_fetch = 3600L; /* once per hour default */
131 if (config.c_pop3_fetch < 300L)
132 config.c_pop3_fetch = 300L;
133 if (config.c_pop3_fastest == 0L)
134 config.c_pop3_fastest = 3600L; /* once per hour default */
135 if (config.c_pop3_fastest < 300L)
136 config.c_pop3_fastest = 300L;
138 /* "create new user" only works with native authentication mode */
139 if (config.c_auth_mode != AUTHMODE_NATIVE) {
140 config.c_disable_newu = 1;
146 * Occasionally, we will need to write the config file, because some operations
147 * change site-wide parameters.
149 void put_config(void)
153 if ((cfp = fopen(file_citadel_config, "rb+")) == NULL)
154 perror(file_citadel_config);
156 fwrite((char *) &config, sizeof(struct config), 1, cfp);