4 * Read and write the citadel.config file
16 #include <libcitadel.h>
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(ctdl_bbsbase_dir) != 0) {
34 "This program could not be started.\n"
35 "Unable to change directory to %s\n"
41 cfp = fopen(file_citadel_config, "rb");
43 fprintf(stderr, "This program could not be started.\n"
48 exit(CTDLEXIT_CONFIG);
50 fread((char *) &config, sizeof(struct config), 1, cfp);
51 if (fstat(fileno(cfp), &st)) {
52 perror(file_citadel_config);
53 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 & 0xFFF), (st.st_mode & 0xFFF));
66 exit(CTDLEXIT_CONFIG);
72 /* Ensure that we are linked to the correct version of libcitadel */
73 if (libcitadel_version_number() < LIBCITADEL_VERSION_NUMBER) {
74 fprintf(stderr, " You are running libcitadel version %d.%02d\n",
75 (libcitadel_version_number() / 100), (libcitadel_version_number() % 100));
76 fprintf(stderr, "citserver was compiled against version %d.%02d\n",
77 (LIBCITADEL_VERSION_NUMBER / 100), (LIBCITADEL_VERSION_NUMBER % 100));
78 exit(CTDLEXIT_LIBCITADEL);
81 /* Only allow LDAP auth mode if we actually have LDAP support */
83 if (config.c_auth_mode == AUTHMODE_LDAP) {
84 fprintf(stderr, "Your system is configured for LDAP authentication,\n"
85 "but you are running a server built without OpenLDAP support.\n");
86 exit(CTDL_EXIT_UNSUP_AUTH);
90 /* Check to see whether 'setup' must first be run to update data file formats */
91 if (config.c_setup_level < REV_MIN) {
92 fprintf(stderr, "Your data files are out of date. Run setup to update them.\n");
93 fprintf(stderr, " This program requires level %d.%02d\n",
94 (REV_LEVEL / 100), (REV_LEVEL % 100));
95 fprintf(stderr, " Data files are currently at %d.%02d\n",
96 (config.c_setup_level / 100),
97 (config.c_setup_level % 100));
101 /* Default maximum message length is 10 megabytes. This is site
102 * configurable. Also check to make sure the limit has not been
103 * set below 8192 bytes.
105 if (config.c_maxmsglen <= 0)
106 config.c_maxmsglen = 10485760;
107 if (config.c_maxmsglen < 8192)
108 config.c_maxmsglen = 8192;
110 /* Default lower and upper limits on number of worker threads */
112 if (config.c_min_workers < 3) /* no less than 3 */
113 config.c_min_workers = 5;
115 if (config.c_max_workers == 0) /* default maximum */
116 config.c_max_workers = 256;
118 if (config.c_max_workers < config.c_min_workers) /* max >= min */
119 config.c_max_workers = config.c_min_workers;
121 /* Networking more than once every five minutes just isn't sane */
122 if (config.c_net_freq == 0L)
123 config.c_net_freq = 3600L; /* once per hour default */
124 if (config.c_net_freq < 300L)
125 config.c_net_freq = 300L;
127 /* Same goes for POP3 */
128 if (config.c_pop3_fetch == 0L)
129 config.c_pop3_fetch = 3600L; /* once per hour default */
130 if (config.c_pop3_fetch < 300L)
131 config.c_pop3_fetch = 300L;
132 if (config.c_pop3_fastest == 0L)
133 config.c_pop3_fastest = 3600L; /* once per hour default */
134 if (config.c_pop3_fastest < 300L)
135 config.c_pop3_fastest = 300L;
137 /* "create new user" only works with native authentication mode */
138 if (config.c_auth_mode != AUTHMODE_NATIVE) {
139 config.c_disable_newu = 1;
145 * Occasionally, we will need to write the config file, because some operations
146 * change site-wide parameters.
148 void put_config(void)
152 if ((cfp = fopen(file_citadel_config, "rb+")) == NULL)
153 perror(file_citadel_config);
155 fwrite((char *) &config, sizeof(struct config), 1, cfp);