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 static int already_have_control = 0;
76 * If we already have the control record in memory, there's no point
77 * in reading it from disk again.
79 if (already_have_control) return;
81 /* Zero it out. If the control record on disk is missing or short,
82 * the system functions with all control record fields initialized
85 memset(&CitControl, 0, sizeof(struct CitControl));
86 if (control_fp == NULL) {
87 control_fp = fopen(file_citadel_control, "rb+");
88 if (control_fp != NULL) {
90 fchown(fileno(control_fp), config.c_ctdluid, -1);
93 if (control_fp == NULL) {
94 control_fp = fopen(file_citadel_control, "wb+");
95 if (control_fp != NULL) {
97 fchown(fileno(control_fp), config.c_ctdluid, -1);
98 memset(&CitControl, 0, sizeof(struct CitControl));
99 fwrite(&CitControl, sizeof(struct CitControl),
104 if (control_fp == NULL) {
105 lprintf(CTDL_ALERT, "ERROR opening %s: %s\n",
106 file_citadel_control,
112 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
113 already_have_control = 1;
117 * put_control - write the control record to disk.
119 void put_control(void)
122 if (control_fp != NULL) {
124 fwrite(&CitControl, sizeof(struct CitControl), 1,
131 * release_control - close our fd on exit
133 void release_control(void)
135 if (control_fp != NULL)
141 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
143 long get_new_message_number(void)
146 begin_critical_section(S_CONTROL);
148 retval = ++CitControl.MMhighest;
150 end_critical_section(S_CONTROL);
156 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
158 long get_new_user_number(void)
161 begin_critical_section(S_CONTROL);
163 retval = ++CitControl.MMnextuser;
165 end_critical_section(S_CONTROL);
172 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
174 long get_new_room_number(void)
177 begin_critical_section(S_CONTROL);
179 retval = ++CitControl.MMnextroom;
181 end_critical_section(S_CONTROL);
188 * Get or set global configuration options
190 void cmd_conf(char *argbuf)
198 if (CtdlAccessCheck(ac_aide)) return;
200 extract_token(cmd, argbuf, 0, '|', sizeof cmd);
201 if (!strcasecmp(cmd, "GET")) {
202 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
203 cprintf("%s\n", config.c_nodename);
204 cprintf("%s\n", config.c_fqdn);
205 cprintf("%s\n", config.c_humannode);
206 cprintf("%s\n", config.c_phonenum);
207 cprintf("%d\n", config.c_creataide);
208 cprintf("%d\n", config.c_sleeping);
209 cprintf("%d\n", config.c_initax);
210 cprintf("%d\n", config.c_regiscall);
211 cprintf("%d\n", config.c_twitdetect);
212 cprintf("%s\n", config.c_twitroom);
213 cprintf("%s\n", config.c_moreprompt);
214 cprintf("%d\n", config.c_restrict);
215 cprintf("%s\n", config.c_site_location);
216 cprintf("%s\n", config.c_sysadm);
217 cprintf("%d\n", config.c_maxsessions);
218 cprintf("xxx\n"); /* placeholder -- field no longer in use */
219 cprintf("%d\n", config.c_userpurge);
220 cprintf("%d\n", config.c_roompurge);
221 cprintf("%s\n", config.c_logpages);
222 cprintf("%d\n", config.c_createax);
223 cprintf("%ld\n", config.c_maxmsglen);
224 cprintf("%d\n", config.c_min_workers);
225 cprintf("%d\n", config.c_max_workers);
226 cprintf("%d\n", config.c_pop3_port);
227 cprintf("%d\n", config.c_smtp_port);
228 cprintf("%d\n", config.c_rfc822_strict_from);
229 cprintf("%d\n", config.c_aide_zap);
230 cprintf("%d\n", config.c_imap_port);
231 cprintf("%ld\n", config.c_net_freq);
232 cprintf("%d\n", config.c_disable_newu);
233 cprintf("1\n"); /* niu */
234 cprintf("%d\n", config.c_purge_hour);
236 cprintf("%s\n", config.c_ldap_host);
237 cprintf("%d\n", config.c_ldap_port);
238 cprintf("%s\n", config.c_ldap_base_dn);
239 cprintf("%s\n", config.c_ldap_bind_dn);
240 cprintf("%s\n", config.c_ldap_bind_pw);
248 cprintf("%s\n", config.c_ip_addr);
249 cprintf("%d\n", config.c_msa_port);
250 cprintf("%d\n", config.c_imaps_port);
251 cprintf("%d\n", config.c_pop3s_port);
252 cprintf("%d\n", config.c_smtps_port);
253 cprintf("%d\n", config.c_enable_fulltext);
254 cprintf("%d\n", config.c_auto_cull);
255 cprintf("%d\n", config.c_instant_expunge);
256 cprintf("%d\n", config.c_allow_spoofing);
257 cprintf("%d\n", config.c_journal_email);
258 cprintf("%d\n", config.c_journal_pubmsgs);
259 cprintf("%s\n", config.c_journal_dest);
260 cprintf("%s\n", config.c_default_cal_zone);
261 cprintf("%d\n", config.c_pftcpdict_port);
262 cprintf("%d\n", config.c_managesieve_port);
263 cprintf("%d\n", config.c_auth_mode);
264 cprintf("%s\n", config.c_funambol_host);
265 cprintf("%d\n", config.c_funambol_port);
266 cprintf("%s\n", config.c_funambol_source);
267 cprintf("%s\n", config.c_funambol_auth);
268 cprintf("%d\n", config.c_rbl_at_greeting);
272 else if (!strcasecmp(cmd, "SET")) {
274 cprintf("%d Send configuration...\n", SEND_LISTING);
276 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
279 safestrncpy(config.c_nodename, buf,
280 sizeof config.c_nodename);
283 safestrncpy(config.c_fqdn, buf,
284 sizeof config.c_fqdn);
287 safestrncpy(config.c_humannode, buf,
288 sizeof config.c_humannode);
291 safestrncpy(config.c_phonenum, buf,
292 sizeof config.c_phonenum);
295 config.c_creataide = atoi(buf);
298 config.c_sleeping = atoi(buf);
301 config.c_initax = atoi(buf);
302 if (config.c_initax < 1)
304 if (config.c_initax > 6)
308 config.c_regiscall = atoi(buf);
309 if (config.c_regiscall != 0)
310 config.c_regiscall = 1;
313 config.c_twitdetect = atoi(buf);
314 if (config.c_twitdetect != 0)
315 config.c_twitdetect = 1;
318 safestrncpy(config.c_twitroom, buf,
319 sizeof config.c_twitroom);
322 safestrncpy(config.c_moreprompt, buf,
323 sizeof config.c_moreprompt);
326 config.c_restrict = atoi(buf);
327 if (config.c_restrict != 0)
328 config.c_restrict = 1;
331 safestrncpy(config.c_site_location, buf,
332 sizeof config.c_site_location);
335 safestrncpy(config.c_sysadm, buf,
336 sizeof config.c_sysadm);
339 config.c_maxsessions = atoi(buf);
340 if (config.c_maxsessions < 0)
341 config.c_maxsessions = 0;
344 /* placeholder -- field no longer in use */
347 config.c_userpurge = atoi(buf);
350 config.c_roompurge = atoi(buf);
353 safestrncpy(config.c_logpages, buf,
354 sizeof config.c_logpages);
357 config.c_createax = atoi(buf);
358 if (config.c_createax < 1)
359 config.c_createax = 1;
360 if (config.c_createax > 6)
361 config.c_createax = 6;
364 if (atoi(buf) >= 8192)
365 config.c_maxmsglen = atoi(buf);
369 config.c_min_workers = atoi(buf);
371 if (atoi(buf) >= config.c_min_workers)
372 config.c_max_workers = atoi(buf);
374 config.c_pop3_port = atoi(buf);
377 config.c_smtp_port = atoi(buf);
380 config.c_rfc822_strict_from = atoi(buf);
383 config.c_aide_zap = atoi(buf);
384 if (config.c_aide_zap != 0)
385 config.c_aide_zap = 1;
388 config.c_imap_port = atoi(buf);
391 config.c_net_freq = atol(buf);
394 config.c_disable_newu = atoi(buf);
395 if (config.c_disable_newu != 0)
396 config.c_disable_newu = 1;
402 if ((config.c_purge_hour >= 0)
403 && (config.c_purge_hour <= 23)) {
404 config.c_purge_hour = atoi(buf);
409 safestrncpy(config.c_ldap_host, buf,
410 sizeof config.c_ldap_host);
413 config.c_ldap_port = atoi(buf);
416 safestrncpy(config.c_ldap_base_dn, buf,
417 sizeof config.c_ldap_base_dn);
420 safestrncpy(config.c_ldap_bind_dn, buf,
421 sizeof config.c_ldap_bind_dn);
424 safestrncpy(config.c_ldap_bind_pw, buf,
425 sizeof config.c_ldap_bind_pw);
429 safestrncpy(config.c_ip_addr, buf,
430 sizeof config.c_ip_addr);
432 config.c_msa_port = atoi(buf);
435 config.c_imaps_port = atoi(buf);
438 config.c_pop3s_port = atoi(buf);
441 config.c_smtps_port = atoi(buf);
444 config.c_enable_fulltext = atoi(buf);
447 config.c_auto_cull = atoi(buf);
450 config.c_instant_expunge = atoi(buf);
453 config.c_allow_spoofing = atoi(buf);
456 config.c_journal_email = atoi(buf);
459 config.c_journal_pubmsgs = atoi(buf);
462 safestrncpy(config.c_journal_dest, buf,
463 sizeof config.c_journal_dest);
465 safestrncpy(config.c_default_cal_zone, buf,
466 sizeof config.c_default_cal_zone);
469 config.c_pftcpdict_port = atoi(buf);
472 config.c_managesieve_port = atoi(buf);
475 config.c_auth_mode = atoi(buf);
477 safestrncpy(config.c_funambol_host, buf,
478 sizeof config.c_funambol_host);
481 config.c_funambol_port = atoi(buf);
484 safestrncpy(config.c_funambol_source,
486 sizeof config.c_funambol_source);
489 safestrncpy(config.c_funambol_auth,
491 sizeof config.c_funambol_auth);
494 config.c_rbl_at_greeting = atoi(buf);
500 snprintf(buf, sizeof buf,
501 "The global system configuration has been edited by %s.\n",
503 aide_message(buf,"Citadel Configuration Manager Message");
505 if (strlen(config.c_logpages) > 0)
506 create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
508 /* If full text indexing has been disabled, invalidate the
509 * index so it doesn't try to use it later.
511 if (config.c_enable_fulltext == 0) {
512 CitControl.fulltext_wordbreaker = 0;
517 else if (!strcasecmp(cmd, "GETSYS")) {
518 extract_token(confname, argbuf, 1, '|', sizeof confname);
519 confptr = CtdlGetSysConfig(confname);
520 if (confptr != NULL) {
521 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
522 client_write(confptr, strlen(confptr));
523 if (confptr[strlen(confptr) - 1] != 10)
524 client_write("\n", 1);
528 cprintf("%d No such configuration.\n",
529 ERROR + ILLEGAL_VALUE);
533 else if (!strcasecmp(cmd, "PUTSYS")) {
534 extract_token(confname, argbuf, 1, '|', sizeof confname);
536 cprintf("%d %s\n", SEND_LISTING, confname);
537 confptr = CtdlReadMessageBody("000",
538 config.c_maxmsglen, NULL, 0);
539 CtdlPutSysConfig(confname, confptr);
544 cprintf("%d Illegal option(s) specified.\n",
545 ERROR + ILLEGAL_VALUE);