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 "sysdep_decls.h"
39 #include "citserver.h"
47 struct CitControl CitControl;
48 extern struct config config;
49 FILE *control_fp = NULL;
54 * lock_control - acquire a lock on the control record file.
55 * This keeps multiple citservers from running concurrently.
57 void lock_control(void)
61 * TODO: solaris manpages describe this function, but the headers
65 if (flock(fileno(control_fp), (LOCK_EX | LOCK_NB))) {
66 lprintf(CTDL_EMERG, "citserver: unable to lock %s.\n", file_citadel_control);
67 lprintf(CTDL_EMERG, "Is another citserver already running?\n");
68 exit(CTDLEXIT_CONTROL);
75 * get_control - read the control record into memory.
77 void get_control(void)
79 static int already_have_control = 0;
82 * If we already have the control record in memory, there's no point
83 * in reading it from disk again.
85 if (already_have_control) return;
87 /* Zero it out. If the control record on disk is missing or short,
88 * the system functions with all control record fields initialized
91 memset(&CitControl, 0, sizeof(struct CitControl));
92 if (control_fp == NULL) {
93 control_fp = fopen(file_citadel_control, "rb+");
94 if (control_fp != NULL) {
96 fchown(fileno(control_fp), config.c_ctdluid, -1);
99 if (control_fp == NULL) {
100 control_fp = fopen(file_citadel_control, "wb+");
101 if (control_fp != NULL) {
103 fchown(fileno(control_fp), config.c_ctdluid, -1);
104 memset(&CitControl, 0, sizeof(struct CitControl));
105 fwrite(&CitControl, sizeof(struct CitControl),
110 if (control_fp == NULL) {
111 lprintf(CTDL_ALERT, "ERROR opening %s: %s\n",
112 file_citadel_control,
118 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
119 already_have_control = 1;
123 * put_control - write the control record to disk.
125 void put_control(void)
128 if (control_fp != NULL) {
130 fwrite(&CitControl, sizeof(struct CitControl), 1,
137 * release_control - close our fd on exit
139 void release_control(void)
141 if (control_fp != NULL)
147 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
149 long get_new_message_number(void)
152 begin_critical_section(S_CONTROL);
154 retval = ++CitControl.MMhighest;
156 end_critical_section(S_CONTROL);
162 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
164 long get_new_user_number(void)
167 begin_critical_section(S_CONTROL);
169 retval = ++CitControl.MMnextuser;
171 end_critical_section(S_CONTROL);
178 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
180 long get_new_room_number(void)
183 begin_critical_section(S_CONTROL);
185 retval = ++CitControl.MMnextroom;
187 end_critical_section(S_CONTROL);
194 * Get or set global configuration options
196 void cmd_conf(char *argbuf)
204 if (CtdlAccessCheck(ac_aide)) return;
206 extract_token(cmd, argbuf, 0, '|', sizeof cmd);
207 if (!strcasecmp(cmd, "GET")) {
208 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
209 cprintf("%s\n", config.c_nodename);
210 cprintf("%s\n", config.c_fqdn);
211 cprintf("%s\n", config.c_humannode);
212 cprintf("%s\n", config.c_phonenum);
213 cprintf("%d\n", config.c_creataide);
214 cprintf("%d\n", config.c_sleeping);
215 cprintf("%d\n", config.c_initax);
216 cprintf("%d\n", config.c_regiscall);
217 cprintf("%d\n", config.c_twitdetect);
218 cprintf("%s\n", config.c_twitroom);
219 cprintf("%s\n", config.c_moreprompt);
220 cprintf("%d\n", config.c_restrict);
221 cprintf("%s\n", config.c_site_location);
222 cprintf("%s\n", config.c_sysadm);
223 cprintf("%d\n", config.c_maxsessions);
224 cprintf("xxx\n"); /* placeholder -- field no longer in use */
225 cprintf("%d\n", config.c_userpurge);
226 cprintf("%d\n", config.c_roompurge);
227 cprintf("%s\n", config.c_logpages);
228 cprintf("%d\n", config.c_createax);
229 cprintf("%ld\n", config.c_maxmsglen);
230 cprintf("%d\n", config.c_min_workers);
231 cprintf("%d\n", config.c_max_workers);
232 cprintf("%d\n", config.c_pop3_port);
233 cprintf("%d\n", config.c_smtp_port);
234 cprintf("%d\n", config.c_rfc822_strict_from);
235 cprintf("%d\n", config.c_aide_zap);
236 cprintf("%d\n", config.c_imap_port);
237 cprintf("%ld\n", config.c_net_freq);
238 cprintf("%d\n", config.c_disable_newu);
239 cprintf("1\n"); /* niu */
240 cprintf("%d\n", config.c_purge_hour);
242 cprintf("%s\n", config.c_ldap_host);
243 cprintf("%d\n", config.c_ldap_port);
244 cprintf("%s\n", config.c_ldap_base_dn);
245 cprintf("%s\n", config.c_ldap_bind_dn);
246 cprintf("%s\n", config.c_ldap_bind_pw);
254 cprintf("%s\n", config.c_ip_addr);
255 cprintf("%d\n", config.c_msa_port);
256 cprintf("%d\n", config.c_imaps_port);
257 cprintf("%d\n", config.c_pop3s_port);
258 cprintf("%d\n", config.c_smtps_port);
259 cprintf("%d\n", config.c_enable_fulltext);
260 cprintf("%d\n", config.c_auto_cull);
261 cprintf("%d\n", config.c_instant_expunge);
262 cprintf("%d\n", config.c_allow_spoofing);
263 cprintf("%d\n", config.c_journal_email);
264 cprintf("%d\n", config.c_journal_pubmsgs);
265 cprintf("%s\n", config.c_journal_dest);
266 cprintf("%s\n", config.c_default_cal_zone);
267 cprintf("%d\n", config.c_pftcpdict_port);
268 cprintf("%d\n", config.c_managesieve_port);
269 cprintf("%d\n", config.c_auth_mode);
270 cprintf("%s\n", config.c_funambol_host);
271 cprintf("%d\n", config.c_funambol_port);
272 cprintf("%s\n", config.c_funambol_source);
273 cprintf("%s\n", config.c_funambol_auth);
274 cprintf("%d\n", config.c_rbl_at_greeting);
275 cprintf("%s\n", config.c_master_user);
276 cprintf("%s\n", config.c_master_pass);
280 else if (!strcasecmp(cmd, "SET")) {
282 cprintf("%d Send configuration...\n", SEND_LISTING);
284 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
287 safestrncpy(config.c_nodename, buf,
288 sizeof config.c_nodename);
291 safestrncpy(config.c_fqdn, buf,
292 sizeof config.c_fqdn);
295 safestrncpy(config.c_humannode, buf,
296 sizeof config.c_humannode);
299 safestrncpy(config.c_phonenum, buf,
300 sizeof config.c_phonenum);
303 config.c_creataide = atoi(buf);
306 config.c_sleeping = atoi(buf);
309 config.c_initax = atoi(buf);
310 if (config.c_initax < 1)
312 if (config.c_initax > 6)
316 config.c_regiscall = atoi(buf);
317 if (config.c_regiscall != 0)
318 config.c_regiscall = 1;
321 config.c_twitdetect = atoi(buf);
322 if (config.c_twitdetect != 0)
323 config.c_twitdetect = 1;
326 safestrncpy(config.c_twitroom, buf,
327 sizeof config.c_twitroom);
330 safestrncpy(config.c_moreprompt, buf,
331 sizeof config.c_moreprompt);
334 config.c_restrict = atoi(buf);
335 if (config.c_restrict != 0)
336 config.c_restrict = 1;
339 safestrncpy(config.c_site_location, buf,
340 sizeof config.c_site_location);
343 safestrncpy(config.c_sysadm, buf,
344 sizeof config.c_sysadm);
347 config.c_maxsessions = atoi(buf);
348 if (config.c_maxsessions < 0)
349 config.c_maxsessions = 0;
352 /* placeholder -- field no longer in use */
355 config.c_userpurge = atoi(buf);
358 config.c_roompurge = atoi(buf);
361 safestrncpy(config.c_logpages, buf,
362 sizeof config.c_logpages);
365 config.c_createax = atoi(buf);
366 if (config.c_createax < 1)
367 config.c_createax = 1;
368 if (config.c_createax > 6)
369 config.c_createax = 6;
372 if (atoi(buf) >= 8192)
373 config.c_maxmsglen = atoi(buf);
377 config.c_min_workers = atoi(buf);
379 if (atoi(buf) >= config.c_min_workers)
380 config.c_max_workers = atoi(buf);
382 config.c_pop3_port = atoi(buf);
385 config.c_smtp_port = atoi(buf);
388 config.c_rfc822_strict_from = atoi(buf);
391 config.c_aide_zap = atoi(buf);
392 if (config.c_aide_zap != 0)
393 config.c_aide_zap = 1;
396 config.c_imap_port = atoi(buf);
399 config.c_net_freq = atol(buf);
402 config.c_disable_newu = atoi(buf);
403 if (config.c_disable_newu != 0)
404 config.c_disable_newu = 1;
410 if ((config.c_purge_hour >= 0)
411 && (config.c_purge_hour <= 23)) {
412 config.c_purge_hour = atoi(buf);
417 safestrncpy(config.c_ldap_host, buf,
418 sizeof config.c_ldap_host);
421 config.c_ldap_port = atoi(buf);
424 safestrncpy(config.c_ldap_base_dn, buf,
425 sizeof config.c_ldap_base_dn);
428 safestrncpy(config.c_ldap_bind_dn, buf,
429 sizeof config.c_ldap_bind_dn);
432 safestrncpy(config.c_ldap_bind_pw, buf,
433 sizeof config.c_ldap_bind_pw);
437 safestrncpy(config.c_ip_addr, buf,
438 sizeof config.c_ip_addr);
440 config.c_msa_port = atoi(buf);
443 config.c_imaps_port = atoi(buf);
446 config.c_pop3s_port = atoi(buf);
449 config.c_smtps_port = atoi(buf);
452 config.c_enable_fulltext = atoi(buf);
455 config.c_auto_cull = atoi(buf);
458 config.c_instant_expunge = atoi(buf);
461 config.c_allow_spoofing = atoi(buf);
464 config.c_journal_email = atoi(buf);
467 config.c_journal_pubmsgs = atoi(buf);
470 safestrncpy(config.c_journal_dest, buf,
471 sizeof config.c_journal_dest);
473 safestrncpy(config.c_default_cal_zone, buf,
474 sizeof config.c_default_cal_zone);
477 config.c_pftcpdict_port = atoi(buf);
480 config.c_managesieve_port = atoi(buf);
483 config.c_auth_mode = atoi(buf);
485 safestrncpy(config.c_funambol_host, buf,
486 sizeof config.c_funambol_host);
489 config.c_funambol_port = atoi(buf);
492 safestrncpy(config.c_funambol_source,
494 sizeof config.c_funambol_source);
497 safestrncpy(config.c_funambol_auth,
499 sizeof config.c_funambol_auth);
502 config.c_rbl_at_greeting = atoi(buf);
505 safestrncpy(config.c_master_user, buf, sizeof config.c_master_user);
508 safestrncpy(config.c_master_pass, buf, sizeof config.c_master_pass);
514 snprintf(buf, sizeof buf,
515 "The global system configuration has been edited by %s.\n",
517 aide_message(buf,"Citadel Configuration Manager Message");
519 if (!IsEmptyStr(config.c_logpages))
520 create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
522 /* If full text indexing has been disabled, invalidate the
523 * index so it doesn't try to use it later.
525 if (config.c_enable_fulltext == 0) {
526 CitControl.fulltext_wordbreaker = 0;
531 else if (!strcasecmp(cmd, "GETSYS")) {
532 extract_token(confname, argbuf, 1, '|', sizeof confname);
533 confptr = CtdlGetSysConfig(confname);
534 if (confptr != NULL) {
535 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
536 client_write(confptr, strlen(confptr));
537 if (confptr[strlen(confptr) - 1] != 10)
538 client_write("\n", 1);
542 cprintf("%d No such configuration.\n",
543 ERROR + ILLEGAL_VALUE);
547 else if (!strcasecmp(cmd, "PUTSYS")) {
548 extract_token(confname, argbuf, 1, '|', sizeof confname);
550 cprintf("%d %s\n", SEND_LISTING, confname);
551 confptr = CtdlReadMessageBody("000", config.c_maxmsglen, NULL, 0, 0);
552 CtdlPutSysConfig(confname, confptr);
557 cprintf("%d Illegal option(s) specified.\n",
558 ERROR + ILLEGAL_VALUE);