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);
262 else if (!strcasecmp(cmd, "SET")) {
264 cprintf("%d Send configuration...\n", SEND_LISTING);
266 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
269 safestrncpy(config.c_nodename, buf,
270 sizeof config.c_nodename);
273 safestrncpy(config.c_fqdn, buf,
274 sizeof config.c_fqdn);
277 safestrncpy(config.c_humannode, buf,
278 sizeof config.c_humannode);
281 safestrncpy(config.c_phonenum, buf,
282 sizeof config.c_phonenum);
285 config.c_creataide = atoi(buf);
288 config.c_sleeping = atoi(buf);
291 config.c_initax = atoi(buf);
292 if (config.c_initax < 1)
294 if (config.c_initax > 6)
298 config.c_regiscall = atoi(buf);
299 if (config.c_regiscall != 0)
300 config.c_regiscall = 1;
303 config.c_twitdetect = atoi(buf);
304 if (config.c_twitdetect != 0)
305 config.c_twitdetect = 1;
308 safestrncpy(config.c_twitroom, buf,
309 sizeof config.c_twitroom);
312 safestrncpy(config.c_moreprompt, buf,
313 sizeof config.c_moreprompt);
316 config.c_restrict = atoi(buf);
317 if (config.c_restrict != 0)
318 config.c_restrict = 1;
321 safestrncpy(config.c_site_location, buf,
322 sizeof config.c_site_location);
325 safestrncpy(config.c_sysadm, buf,
326 sizeof config.c_sysadm);
329 config.c_maxsessions = atoi(buf);
330 if (config.c_maxsessions < 0)
331 config.c_maxsessions = 0;
334 /* placeholder -- field no longer in use */
337 config.c_userpurge = atoi(buf);
340 config.c_roompurge = atoi(buf);
343 safestrncpy(config.c_logpages, buf,
344 sizeof config.c_logpages);
347 config.c_createax = atoi(buf);
348 if (config.c_createax < 1)
349 config.c_createax = 1;
350 if (config.c_createax > 6)
351 config.c_createax = 6;
354 if (atoi(buf) >= 8192)
355 config.c_maxmsglen = atoi(buf);
359 config.c_min_workers = atoi(buf);
361 if (atoi(buf) >= config.c_min_workers)
362 config.c_max_workers = atoi(buf);
364 config.c_pop3_port = atoi(buf);
367 config.c_smtp_port = atoi(buf);
370 config.c_rfc822_strict_from = atoi(buf);
373 config.c_aide_zap = atoi(buf);
374 if (config.c_aide_zap != 0)
375 config.c_aide_zap = 1;
378 config.c_imap_port = atoi(buf);
381 config.c_net_freq = atol(buf);
384 config.c_disable_newu = atoi(buf);
385 if (config.c_disable_newu != 0)
386 config.c_disable_newu = 1;
392 if ((config.c_purge_hour >= 0)
393 && (config.c_purge_hour <= 23)) {
394 config.c_purge_hour = atoi(buf);
399 safestrncpy(config.c_ldap_host, buf,
400 sizeof config.c_ldap_host);
403 config.c_ldap_port = atoi(buf);
406 safestrncpy(config.c_ldap_base_dn, buf,
407 sizeof config.c_ldap_base_dn);
410 safestrncpy(config.c_ldap_bind_dn, buf,
411 sizeof config.c_ldap_bind_dn);
414 safestrncpy(config.c_ldap_bind_pw, buf,
415 sizeof config.c_ldap_bind_pw);
419 safestrncpy(config.c_ip_addr, buf,
420 sizeof config.c_ip_addr);
422 config.c_msa_port = atoi(buf);
425 config.c_imaps_port = atoi(buf);
428 config.c_pop3s_port = atoi(buf);
431 config.c_smtps_port = atoi(buf);
434 config.c_enable_fulltext = atoi(buf);
437 config.c_auto_cull = atoi(buf);
440 config.c_instant_expunge = atoi(buf);
443 config.c_allow_spoofing = atoi(buf);
446 config.c_journal_email = atoi(buf);
449 config.c_journal_pubmsgs = atoi(buf);
452 safestrncpy(config.c_journal_dest, buf,
453 sizeof config.c_journal_dest);
455 safestrncpy(config.c_default_cal_zone, buf,
456 sizeof config.c_default_cal_zone);
459 config.c_pftcpdict_port = atoi(buf);
462 config.c_managesieve_port = atoi(buf);
465 config.c_auth_mode = atoi(buf);
467 safestrncpy(config.c_funambol_host, buf,
468 sizeof config.c_funambol_host);
471 config.c_funambol_port = atoi(buf);
474 safestrncpy(config.c_funambol_source,
476 sizeof config.c_funambol_source);
479 safestrncpy(config.c_funambol_auth,
481 sizeof config.c_funambol_auth);
487 snprintf(buf, sizeof buf,
488 "The global system configuration has been edited by %s.\n",
490 aide_message(buf,"Citadel Configuration Manager Message");
492 if (strlen(config.c_logpages) > 0)
493 create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
495 /* If full text indexing has been disabled, invalidate the
496 * index so it doesn't try to use it later.
498 if (config.c_enable_fulltext == 0) {
499 CitControl.fulltext_wordbreaker = 0;
504 else if (!strcasecmp(cmd, "GETSYS")) {
505 extract_token(confname, argbuf, 1, '|', sizeof confname);
506 confptr = CtdlGetSysConfig(confname);
507 if (confptr != NULL) {
508 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
509 client_write(confptr, strlen(confptr));
510 if (confptr[strlen(confptr) - 1] != 10)
511 client_write("\n", 1);
515 cprintf("%d No such configuration.\n",
516 ERROR + ILLEGAL_VALUE);
520 else if (!strcasecmp(cmd, "PUTSYS")) {
521 extract_token(confname, argbuf, 1, '|', sizeof confname);
523 cprintf("%d %s\n", SEND_LISTING, confname);
524 confptr = CtdlReadMessageBody("000",
525 config.c_maxmsglen, NULL, 0);
526 CtdlPutSysConfig(confname, confptr);
531 cprintf("%d Illegal option(s) specified.\n",
532 ERROR + ILLEGAL_VALUE);