4 * This module handles states which are global to the entire server.
15 #if TIME_WITH_SYS_TIME
16 # include <sys/time.h>
20 # include <sys/time.h>
30 #include <sys/types.h>
35 #include "serv_extensions.h"
36 #include "sysdep_decls.h"
40 #include "citserver.h"
48 struct CitControl CitControl;
49 extern struct config config;
50 FILE *control_fp = NULL;
55 * lock_control - acquire a lock on the control record file.
56 * This keeps multiple citservers from running concurrently.
58 void lock_control(void)
60 if (flock(fileno(control_fp), (LOCK_EX | LOCK_NB))) {
61 lprintf(CTDL_EMERG, "citserver: unable to lock %s.\n", file_citadel_control);
62 lprintf(CTDL_EMERG, "Is another citserver already running?\n");
63 exit(CTDLEXIT_CONTROL);
69 * get_control - read the control record into memory.
71 void get_control(void)
73 /* Zero it out. If the control record on disk is missing or short,
74 * the system functions with all control record fields initialized
77 memset(&CitControl, 0, sizeof(struct CitControl));
78 if (control_fp == NULL) {
79 control_fp = fopen(file_citadel_control, "rb+");
80 if (control_fp != NULL) {
82 fchown(fileno(control_fp), config.c_ctdluid, -1);
85 if (control_fp == NULL) {
86 control_fp = fopen(file_citadel_control, "wb+");
87 if (control_fp != NULL) {
89 fchown(fileno(control_fp), config.c_ctdluid, -1);
90 memset(&CitControl, 0, sizeof(struct CitControl));
91 fwrite(&CitControl, sizeof(struct CitControl),
96 if (control_fp == NULL) {
97 lprintf(CTDL_ALERT, "ERROR opening %s: %s\n",
104 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
108 * put_control - write the control record to disk.
110 void put_control(void)
113 if (control_fp != NULL) {
115 fwrite(&CitControl, sizeof(struct CitControl), 1,
123 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
125 long get_new_message_number(void)
128 begin_critical_section(S_CONTROL);
130 retval = ++CitControl.MMhighest;
132 end_critical_section(S_CONTROL);
138 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
140 long get_new_user_number(void)
143 begin_critical_section(S_CONTROL);
145 retval = ++CitControl.MMnextuser;
147 end_critical_section(S_CONTROL);
154 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
156 long get_new_room_number(void)
159 begin_critical_section(S_CONTROL);
161 retval = ++CitControl.MMnextroom;
163 end_critical_section(S_CONTROL);
170 * Get or set global configuration options
172 void cmd_conf(char *argbuf)
180 if (CtdlAccessCheck(ac_aide)) return;
182 extract_token(cmd, argbuf, 0, '|', sizeof cmd);
183 if (!strcasecmp(cmd, "GET")) {
184 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
185 cprintf("%s\n", config.c_nodename);
186 cprintf("%s\n", config.c_fqdn);
187 cprintf("%s\n", config.c_humannode);
188 cprintf("%s\n", config.c_phonenum);
189 cprintf("%d\n", config.c_creataide);
190 cprintf("%d\n", config.c_sleeping);
191 cprintf("%d\n", config.c_initax);
192 cprintf("%d\n", config.c_regiscall);
193 cprintf("%d\n", config.c_twitdetect);
194 cprintf("%s\n", config.c_twitroom);
195 cprintf("%s\n", config.c_moreprompt);
196 cprintf("%d\n", config.c_restrict);
197 cprintf("%s\n", config.c_site_location);
198 cprintf("%s\n", config.c_sysadm);
199 cprintf("%d\n", config.c_maxsessions);
200 cprintf("xxx\n"); /* placeholder -- field no longer in use */
201 cprintf("%d\n", config.c_userpurge);
202 cprintf("%d\n", config.c_roompurge);
203 cprintf("%s\n", config.c_logpages);
204 cprintf("%d\n", config.c_createax);
205 cprintf("%ld\n", config.c_maxmsglen);
206 cprintf("%d\n", config.c_min_workers);
207 cprintf("%d\n", config.c_max_workers);
208 cprintf("%d\n", config.c_pop3_port);
209 cprintf("%d\n", config.c_smtp_port);
210 cprintf("%d\n", config.c_rfc822_strict_from);
211 cprintf("%d\n", config.c_aide_zap);
212 cprintf("%d\n", config.c_imap_port);
213 cprintf("%ld\n", config.c_net_freq);
214 cprintf("%d\n", config.c_disable_newu);
215 cprintf("1\n"); /* niu */
216 cprintf("%d\n", config.c_purge_hour);
218 cprintf("%s\n", config.c_ldap_host);
219 cprintf("%d\n", config.c_ldap_port);
220 cprintf("%s\n", config.c_ldap_base_dn);
221 cprintf("%s\n", config.c_ldap_bind_dn);
222 cprintf("%s\n", config.c_ldap_bind_pw);
230 cprintf("%s\n", config.c_ip_addr);
231 cprintf("%d\n", config.c_msa_port);
232 cprintf("%d\n", config.c_imaps_port);
233 cprintf("%d\n", config.c_pop3s_port);
234 cprintf("%d\n", config.c_smtps_port);
235 cprintf("%d\n", config.c_enable_fulltext);
236 cprintf("%d\n", config.c_auto_cull);
237 cprintf("%d\n", config.c_instant_expunge);
238 cprintf("%d\n", config.c_allow_spoofing);
239 cprintf("%d\n", config.c_journal_email);
240 cprintf("%d\n", config.c_journal_pubmsgs);
241 cprintf("%s\n", config.c_journal_dest);
242 cprintf("%s\n", config.c_default_cal_zone);
243 cprintf("%d\n", config.c_pftcpdict_port);
244 cprintf("%d\n", config.c_managesieve_port);
248 else if (!strcasecmp(cmd, "SET")) {
250 cprintf("%d Send configuration...\n", SEND_LISTING);
252 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
255 safestrncpy(config.c_nodename, buf,
256 sizeof config.c_nodename);
259 safestrncpy(config.c_fqdn, buf,
260 sizeof config.c_fqdn);
263 safestrncpy(config.c_humannode, buf,
264 sizeof config.c_humannode);
267 safestrncpy(config.c_phonenum, buf,
268 sizeof config.c_phonenum);
271 config.c_creataide = atoi(buf);
274 config.c_sleeping = atoi(buf);
277 config.c_initax = atoi(buf);
278 if (config.c_initax < 1)
280 if (config.c_initax > 6)
284 config.c_regiscall = atoi(buf);
285 if (config.c_regiscall != 0)
286 config.c_regiscall = 1;
289 config.c_twitdetect = atoi(buf);
290 if (config.c_twitdetect != 0)
291 config.c_twitdetect = 1;
294 safestrncpy(config.c_twitroom, buf,
295 sizeof config.c_twitroom);
298 safestrncpy(config.c_moreprompt, buf,
299 sizeof config.c_moreprompt);
302 config.c_restrict = atoi(buf);
303 if (config.c_restrict != 0)
304 config.c_restrict = 1;
307 safestrncpy(config.c_site_location, buf,
308 sizeof config.c_site_location);
311 safestrncpy(config.c_sysadm, buf,
312 sizeof config.c_sysadm);
315 config.c_maxsessions = atoi(buf);
316 if (config.c_maxsessions < 0)
317 config.c_maxsessions = 0;
320 /* placeholder -- field no longer in use */
323 config.c_userpurge = atoi(buf);
326 config.c_roompurge = atoi(buf);
329 safestrncpy(config.c_logpages, buf,
330 sizeof config.c_logpages);
333 config.c_createax = atoi(buf);
334 if (config.c_createax < 1)
335 config.c_createax = 1;
336 if (config.c_createax > 6)
337 config.c_createax = 6;
340 if (atoi(buf) >= 8192)
341 config.c_maxmsglen = atoi(buf);
345 config.c_min_workers = atoi(buf);
347 if (atoi(buf) >= config.c_min_workers)
348 config.c_max_workers = atoi(buf);
350 config.c_pop3_port = atoi(buf);
353 config.c_smtp_port = atoi(buf);
356 config.c_rfc822_strict_from = atoi(buf);
359 config.c_aide_zap = atoi(buf);
360 if (config.c_aide_zap != 0)
361 config.c_aide_zap = 1;
364 config.c_imap_port = atoi(buf);
367 config.c_net_freq = atol(buf);
370 config.c_disable_newu = atoi(buf);
371 if (config.c_disable_newu != 0)
372 config.c_disable_newu = 1;
378 if ((config.c_purge_hour >= 0)
379 && (config.c_purge_hour <= 23)) {
380 config.c_purge_hour = atoi(buf);
385 safestrncpy(config.c_ldap_host, buf,
386 sizeof config.c_ldap_host);
389 config.c_ldap_port = atoi(buf);
392 safestrncpy(config.c_ldap_base_dn, buf,
393 sizeof config.c_ldap_base_dn);
396 safestrncpy(config.c_ldap_bind_dn, buf,
397 sizeof config.c_ldap_bind_dn);
400 safestrncpy(config.c_ldap_bind_pw, buf,
401 sizeof config.c_ldap_bind_pw);
405 safestrncpy(config.c_ip_addr, buf,
406 sizeof config.c_ip_addr);
408 config.c_msa_port = atoi(buf);
411 config.c_imaps_port = atoi(buf);
414 config.c_pop3s_port = atoi(buf);
417 config.c_smtps_port = atoi(buf);
420 config.c_enable_fulltext = atoi(buf);
423 config.c_auto_cull = atoi(buf);
426 config.c_instant_expunge = atoi(buf);
429 config.c_allow_spoofing = atoi(buf);
432 config.c_journal_email = atoi(buf);
435 config.c_journal_pubmsgs = atoi(buf);
438 safestrncpy(config.c_journal_dest, buf,
439 sizeof config.c_journal_dest);
441 safestrncpy(config.c_default_cal_zone, buf,
442 sizeof config.c_default_cal_zone);
445 config.c_pftcpdict_port = atoi(buf);
448 config.c_managesieve_port = atoi(buf);
454 snprintf(buf, sizeof buf,
455 "The global system configuration has been edited by %s.\n",
457 aide_message(buf,"Citadel Configuration Manager Message");
459 if (strlen(config.c_logpages) > 0)
460 create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
462 /* If full text indexing has been disabled, invalidate the
463 * index so it doesn't try to use it later.
465 if (config.c_enable_fulltext == 0) {
466 CitControl.fulltext_wordbreaker = 0;
471 else if (!strcasecmp(cmd, "GETSYS")) {
472 extract_token(confname, argbuf, 1, '|', sizeof confname);
473 confptr = CtdlGetSysConfig(confname);
474 if (confptr != NULL) {
475 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
476 client_write(confptr, strlen(confptr));
477 if (confptr[strlen(confptr) - 1] != 10)
478 client_write("\n", 1);
482 cprintf("%d No such configuration.\n",
483 ERROR + ILLEGAL_VALUE);
487 else if (!strcasecmp(cmd, "PUTSYS")) {
488 extract_token(confname, argbuf, 1, '|', sizeof confname);
490 cprintf("%d %s\n", SEND_LISTING, confname);
491 confptr = CtdlReadMessageBody("000",
492 config.c_maxmsglen, NULL, 0);
493 CtdlPutSysConfig(confname, confptr);
498 cprintf("%d Illegal option(s) specified.\n",
499 ERROR + ILLEGAL_VALUE);