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,
122 * release_control - close our fd on exit
124 void release_control(void)
126 if (control_fp != NULL)
132 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
134 long get_new_message_number(void)
137 begin_critical_section(S_CONTROL);
139 retval = ++CitControl.MMhighest;
141 end_critical_section(S_CONTROL);
147 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
149 long get_new_user_number(void)
152 begin_critical_section(S_CONTROL);
154 retval = ++CitControl.MMnextuser;
156 end_critical_section(S_CONTROL);
163 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
165 long get_new_room_number(void)
168 begin_critical_section(S_CONTROL);
170 retval = ++CitControl.MMnextroom;
172 end_critical_section(S_CONTROL);
179 * Get or set global configuration options
181 void cmd_conf(char *argbuf)
189 if (CtdlAccessCheck(ac_aide)) return;
191 extract_token(cmd, argbuf, 0, '|', sizeof cmd);
192 if (!strcasecmp(cmd, "GET")) {
193 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
194 cprintf("%s\n", config.c_nodename);
195 cprintf("%s\n", config.c_fqdn);
196 cprintf("%s\n", config.c_humannode);
197 cprintf("%s\n", config.c_phonenum);
198 cprintf("%d\n", config.c_creataide);
199 cprintf("%d\n", config.c_sleeping);
200 cprintf("%d\n", config.c_initax);
201 cprintf("%d\n", config.c_regiscall);
202 cprintf("%d\n", config.c_twitdetect);
203 cprintf("%s\n", config.c_twitroom);
204 cprintf("%s\n", config.c_moreprompt);
205 cprintf("%d\n", config.c_restrict);
206 cprintf("%s\n", config.c_site_location);
207 cprintf("%s\n", config.c_sysadm);
208 cprintf("%d\n", config.c_maxsessions);
209 cprintf("xxx\n"); /* placeholder -- field no longer in use */
210 cprintf("%d\n", config.c_userpurge);
211 cprintf("%d\n", config.c_roompurge);
212 cprintf("%s\n", config.c_logpages);
213 cprintf("%d\n", config.c_createax);
214 cprintf("%ld\n", config.c_maxmsglen);
215 cprintf("%d\n", config.c_min_workers);
216 cprintf("%d\n", config.c_max_workers);
217 cprintf("%d\n", config.c_pop3_port);
218 cprintf("%d\n", config.c_smtp_port);
219 cprintf("%d\n", config.c_rfc822_strict_from);
220 cprintf("%d\n", config.c_aide_zap);
221 cprintf("%d\n", config.c_imap_port);
222 cprintf("%ld\n", config.c_net_freq);
223 cprintf("%d\n", config.c_disable_newu);
224 cprintf("1\n"); /* niu */
225 cprintf("%d\n", config.c_purge_hour);
227 cprintf("%s\n", config.c_ldap_host);
228 cprintf("%d\n", config.c_ldap_port);
229 cprintf("%s\n", config.c_ldap_base_dn);
230 cprintf("%s\n", config.c_ldap_bind_dn);
231 cprintf("%s\n", config.c_ldap_bind_pw);
239 cprintf("%s\n", config.c_ip_addr);
240 cprintf("%d\n", config.c_msa_port);
241 cprintf("%d\n", config.c_imaps_port);
242 cprintf("%d\n", config.c_pop3s_port);
243 cprintf("%d\n", config.c_smtps_port);
244 cprintf("%d\n", config.c_enable_fulltext);
245 cprintf("%d\n", config.c_auto_cull);
246 cprintf("%d\n", config.c_instant_expunge);
247 cprintf("%d\n", config.c_allow_spoofing);
248 cprintf("%d\n", config.c_journal_email);
249 cprintf("%d\n", config.c_journal_pubmsgs);
250 cprintf("%s\n", config.c_journal_dest);
251 cprintf("%s\n", config.c_default_cal_zone);
252 cprintf("%d\n", config.c_pftcpdict_port);
253 cprintf("%d\n", config.c_managesieve_port);
254 cprintf("%d\n", config.c_auth_mode);
255 cprintf("%s\n", config.c_funambol_host);
256 cprintf("%d\n", config.c_funambol_port);
257 cprintf("%s\n", config.c_funambol_source);
258 cprintf("%s\n", config.c_funambol_auth);
259 cprintf("%d\n", config.c_rbl_at_greeting);
263 else if (!strcasecmp(cmd, "SET")) {
265 cprintf("%d Send configuration...\n", SEND_LISTING);
267 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
270 safestrncpy(config.c_nodename, buf,
271 sizeof config.c_nodename);
274 safestrncpy(config.c_fqdn, buf,
275 sizeof config.c_fqdn);
278 safestrncpy(config.c_humannode, buf,
279 sizeof config.c_humannode);
282 safestrncpy(config.c_phonenum, buf,
283 sizeof config.c_phonenum);
286 config.c_creataide = atoi(buf);
289 config.c_sleeping = atoi(buf);
292 config.c_initax = atoi(buf);
293 if (config.c_initax < 1)
295 if (config.c_initax > 6)
299 config.c_regiscall = atoi(buf);
300 if (config.c_regiscall != 0)
301 config.c_regiscall = 1;
304 config.c_twitdetect = atoi(buf);
305 if (config.c_twitdetect != 0)
306 config.c_twitdetect = 1;
309 safestrncpy(config.c_twitroom, buf,
310 sizeof config.c_twitroom);
313 safestrncpy(config.c_moreprompt, buf,
314 sizeof config.c_moreprompt);
317 config.c_restrict = atoi(buf);
318 if (config.c_restrict != 0)
319 config.c_restrict = 1;
322 safestrncpy(config.c_site_location, buf,
323 sizeof config.c_site_location);
326 safestrncpy(config.c_sysadm, buf,
327 sizeof config.c_sysadm);
330 config.c_maxsessions = atoi(buf);
331 if (config.c_maxsessions < 0)
332 config.c_maxsessions = 0;
335 /* placeholder -- field no longer in use */
338 config.c_userpurge = atoi(buf);
341 config.c_roompurge = atoi(buf);
344 safestrncpy(config.c_logpages, buf,
345 sizeof config.c_logpages);
348 config.c_createax = atoi(buf);
349 if (config.c_createax < 1)
350 config.c_createax = 1;
351 if (config.c_createax > 6)
352 config.c_createax = 6;
355 if (atoi(buf) >= 8192)
356 config.c_maxmsglen = atoi(buf);
360 config.c_min_workers = atoi(buf);
362 if (atoi(buf) >= config.c_min_workers)
363 config.c_max_workers = atoi(buf);
365 config.c_pop3_port = atoi(buf);
368 config.c_smtp_port = atoi(buf);
371 config.c_rfc822_strict_from = atoi(buf);
374 config.c_aide_zap = atoi(buf);
375 if (config.c_aide_zap != 0)
376 config.c_aide_zap = 1;
379 config.c_imap_port = atoi(buf);
382 config.c_net_freq = atol(buf);
385 config.c_disable_newu = atoi(buf);
386 if (config.c_disable_newu != 0)
387 config.c_disable_newu = 1;
393 if ((config.c_purge_hour >= 0)
394 && (config.c_purge_hour <= 23)) {
395 config.c_purge_hour = atoi(buf);
400 safestrncpy(config.c_ldap_host, buf,
401 sizeof config.c_ldap_host);
404 config.c_ldap_port = atoi(buf);
407 safestrncpy(config.c_ldap_base_dn, buf,
408 sizeof config.c_ldap_base_dn);
411 safestrncpy(config.c_ldap_bind_dn, buf,
412 sizeof config.c_ldap_bind_dn);
415 safestrncpy(config.c_ldap_bind_pw, buf,
416 sizeof config.c_ldap_bind_pw);
420 safestrncpy(config.c_ip_addr, buf,
421 sizeof config.c_ip_addr);
423 config.c_msa_port = atoi(buf);
426 config.c_imaps_port = atoi(buf);
429 config.c_pop3s_port = atoi(buf);
432 config.c_smtps_port = atoi(buf);
435 config.c_enable_fulltext = atoi(buf);
438 config.c_auto_cull = atoi(buf);
441 config.c_instant_expunge = atoi(buf);
444 config.c_allow_spoofing = atoi(buf);
447 config.c_journal_email = atoi(buf);
450 config.c_journal_pubmsgs = atoi(buf);
453 safestrncpy(config.c_journal_dest, buf,
454 sizeof config.c_journal_dest);
456 safestrncpy(config.c_default_cal_zone, buf,
457 sizeof config.c_default_cal_zone);
460 config.c_pftcpdict_port = atoi(buf);
463 config.c_managesieve_port = atoi(buf);
466 config.c_auth_mode = atoi(buf);
468 safestrncpy(config.c_funambol_host, buf,
469 sizeof config.c_funambol_host);
472 config.c_funambol_port = atoi(buf);
475 safestrncpy(config.c_funambol_source,
477 sizeof config.c_funambol_source);
480 safestrncpy(config.c_funambol_auth,
482 sizeof config.c_funambol_auth);
485 config.c_rbl_at_greeting = atoi(buf);
491 snprintf(buf, sizeof buf,
492 "The global system configuration has been edited by %s.\n",
494 aide_message(buf,"Citadel Configuration Manager Message");
496 if (strlen(config.c_logpages) > 0)
497 create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
499 /* If full text indexing has been disabled, invalidate the
500 * index so it doesn't try to use it later.
502 if (config.c_enable_fulltext == 0) {
503 CitControl.fulltext_wordbreaker = 0;
508 else if (!strcasecmp(cmd, "GETSYS")) {
509 extract_token(confname, argbuf, 1, '|', sizeof confname);
510 confptr = CtdlGetSysConfig(confname);
511 if (confptr != NULL) {
512 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
513 client_write(confptr, strlen(confptr));
514 if (confptr[strlen(confptr) - 1] != 10)
515 client_write("\n", 1);
519 cprintf("%d No such configuration.\n",
520 ERROR + ILLEGAL_VALUE);
524 else if (!strcasecmp(cmd, "PUTSYS")) {
525 extract_token(confname, argbuf, 1, '|', sizeof confname);
527 cprintf("%d %s\n", SEND_LISTING, confname);
528 confptr = CtdlReadMessageBody("000",
529 config.c_maxmsglen, NULL, 0);
530 CtdlPutSysConfig(confname, confptr);
535 cprintf("%d Illegal option(s) specified.\n",
536 ERROR + ILLEGAL_VALUE);