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
64 if (flock(fileno(control_fp), (LOCK_EX | LOCK_NB))) {
65 lprintf(CTDL_EMERG, "citserver: unable to lock %s.\n", file_citadel_control);
66 lprintf(CTDL_EMERG, "Is another citserver already running?\n");
67 exit(CTDLEXIT_CONTROL);
74 * get_control - read the control record into memory.
76 void get_control(void)
78 static int already_have_control = 0;
81 * If we already have the control record in memory, there's no point
82 * in reading it from disk again.
84 if (already_have_control) return;
86 /* Zero it out. If the control record on disk is missing or short,
87 * the system functions with all control record fields initialized
90 memset(&CitControl, 0, sizeof(struct CitControl));
91 if (control_fp == NULL) {
92 control_fp = fopen(file_citadel_control, "rb+");
93 if (control_fp != NULL) {
95 fchown(fileno(control_fp), config.c_ctdluid, -1);
98 if (control_fp == NULL) {
99 control_fp = fopen(file_citadel_control, "wb+");
100 if (control_fp != NULL) {
102 fchown(fileno(control_fp), config.c_ctdluid, -1);
103 memset(&CitControl, 0, sizeof(struct CitControl));
104 fwrite(&CitControl, sizeof(struct CitControl),
109 if (control_fp == NULL) {
110 lprintf(CTDL_ALERT, "ERROR opening %s: %s\n",
111 file_citadel_control,
117 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
118 already_have_control = 1;
122 * put_control - write the control record to disk.
124 void put_control(void)
127 if (control_fp != NULL) {
129 fwrite(&CitControl, sizeof(struct CitControl), 1,
136 * release_control - close our fd on exit
138 void release_control(void)
140 if (control_fp != NULL)
146 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
148 long get_new_message_number(void)
151 begin_critical_section(S_CONTROL);
153 retval = ++CitControl.MMhighest;
155 end_critical_section(S_CONTROL);
161 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
163 long get_new_user_number(void)
166 begin_critical_section(S_CONTROL);
168 retval = ++CitControl.MMnextuser;
170 end_critical_section(S_CONTROL);
177 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
179 long get_new_room_number(void)
182 begin_critical_section(S_CONTROL);
184 retval = ++CitControl.MMnextroom;
186 end_critical_section(S_CONTROL);
193 * Get or set global configuration options
195 void cmd_conf(char *argbuf)
203 if (CtdlAccessCheck(ac_aide)) return;
205 extract_token(cmd, argbuf, 0, '|', sizeof cmd);
206 if (!strcasecmp(cmd, "GET")) {
207 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
208 cprintf("%s\n", config.c_nodename);
209 cprintf("%s\n", config.c_fqdn);
210 cprintf("%s\n", config.c_humannode);
211 cprintf("%s\n", config.c_phonenum);
212 cprintf("%d\n", config.c_creataide);
213 cprintf("%d\n", config.c_sleeping);
214 cprintf("%d\n", config.c_initax);
215 cprintf("%d\n", config.c_regiscall);
216 cprintf("%d\n", config.c_twitdetect);
217 cprintf("%s\n", config.c_twitroom);
218 cprintf("%s\n", config.c_moreprompt);
219 cprintf("%d\n", config.c_restrict);
220 cprintf("%s\n", config.c_site_location);
221 cprintf("%s\n", config.c_sysadm);
222 cprintf("%d\n", config.c_maxsessions);
223 cprintf("xxx\n"); /* placeholder -- field no longer in use */
224 cprintf("%d\n", config.c_userpurge);
225 cprintf("%d\n", config.c_roompurge);
226 cprintf("%s\n", config.c_logpages);
227 cprintf("%d\n", config.c_createax);
228 cprintf("%ld\n", config.c_maxmsglen);
229 cprintf("%d\n", config.c_min_workers);
230 cprintf("%d\n", config.c_max_workers);
231 cprintf("%d\n", config.c_pop3_port);
232 cprintf("%d\n", config.c_smtp_port);
233 cprintf("%d\n", config.c_rfc822_strict_from);
234 cprintf("%d\n", config.c_aide_zap);
235 cprintf("%d\n", config.c_imap_port);
236 cprintf("%ld\n", config.c_net_freq);
237 cprintf("%d\n", config.c_disable_newu);
238 cprintf("1\n"); /* niu */
239 cprintf("%d\n", config.c_purge_hour);
241 cprintf("%s\n", config.c_ldap_host);
242 cprintf("%d\n", config.c_ldap_port);
243 cprintf("%s\n", config.c_ldap_base_dn);
244 cprintf("%s\n", config.c_ldap_bind_dn);
245 cprintf("%s\n", config.c_ldap_bind_pw);
253 cprintf("%s\n", config.c_ip_addr);
254 cprintf("%d\n", config.c_msa_port);
255 cprintf("%d\n", config.c_imaps_port);
256 cprintf("%d\n", config.c_pop3s_port);
257 cprintf("%d\n", config.c_smtps_port);
258 cprintf("%d\n", config.c_enable_fulltext);
259 cprintf("%d\n", config.c_auto_cull);
260 cprintf("%d\n", config.c_instant_expunge);
261 cprintf("%d\n", config.c_allow_spoofing);
262 cprintf("%d\n", config.c_journal_email);
263 cprintf("%d\n", config.c_journal_pubmsgs);
264 cprintf("%s\n", config.c_journal_dest);
265 cprintf("%s\n", config.c_default_cal_zone);
266 cprintf("%d\n", config.c_pftcpdict_port);
267 cprintf("%d\n", config.c_managesieve_port);
268 cprintf("%d\n", config.c_auth_mode);
269 cprintf("%s\n", config.c_funambol_host);
270 cprintf("%d\n", config.c_funambol_port);
271 cprintf("%s\n", config.c_funambol_source);
272 cprintf("%s\n", config.c_funambol_auth);
273 cprintf("%d\n", config.c_rbl_at_greeting);
277 else if (!strcasecmp(cmd, "SET")) {
279 cprintf("%d Send configuration...\n", SEND_LISTING);
281 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
284 safestrncpy(config.c_nodename, buf,
285 sizeof config.c_nodename);
288 safestrncpy(config.c_fqdn, buf,
289 sizeof config.c_fqdn);
292 safestrncpy(config.c_humannode, buf,
293 sizeof config.c_humannode);
296 safestrncpy(config.c_phonenum, buf,
297 sizeof config.c_phonenum);
300 config.c_creataide = atoi(buf);
303 config.c_sleeping = atoi(buf);
306 config.c_initax = atoi(buf);
307 if (config.c_initax < 1)
309 if (config.c_initax > 6)
313 config.c_regiscall = atoi(buf);
314 if (config.c_regiscall != 0)
315 config.c_regiscall = 1;
318 config.c_twitdetect = atoi(buf);
319 if (config.c_twitdetect != 0)
320 config.c_twitdetect = 1;
323 safestrncpy(config.c_twitroom, buf,
324 sizeof config.c_twitroom);
327 safestrncpy(config.c_moreprompt, buf,
328 sizeof config.c_moreprompt);
331 config.c_restrict = atoi(buf);
332 if (config.c_restrict != 0)
333 config.c_restrict = 1;
336 safestrncpy(config.c_site_location, buf,
337 sizeof config.c_site_location);
340 safestrncpy(config.c_sysadm, buf,
341 sizeof config.c_sysadm);
344 config.c_maxsessions = atoi(buf);
345 if (config.c_maxsessions < 0)
346 config.c_maxsessions = 0;
349 /* placeholder -- field no longer in use */
352 config.c_userpurge = atoi(buf);
355 config.c_roompurge = atoi(buf);
358 safestrncpy(config.c_logpages, buf,
359 sizeof config.c_logpages);
362 config.c_createax = atoi(buf);
363 if (config.c_createax < 1)
364 config.c_createax = 1;
365 if (config.c_createax > 6)
366 config.c_createax = 6;
369 if (atoi(buf) >= 8192)
370 config.c_maxmsglen = atoi(buf);
374 config.c_min_workers = atoi(buf);
376 if (atoi(buf) >= config.c_min_workers)
377 config.c_max_workers = atoi(buf);
379 config.c_pop3_port = atoi(buf);
382 config.c_smtp_port = atoi(buf);
385 config.c_rfc822_strict_from = atoi(buf);
388 config.c_aide_zap = atoi(buf);
389 if (config.c_aide_zap != 0)
390 config.c_aide_zap = 1;
393 config.c_imap_port = atoi(buf);
396 config.c_net_freq = atol(buf);
399 config.c_disable_newu = atoi(buf);
400 if (config.c_disable_newu != 0)
401 config.c_disable_newu = 1;
407 if ((config.c_purge_hour >= 0)
408 && (config.c_purge_hour <= 23)) {
409 config.c_purge_hour = atoi(buf);
414 safestrncpy(config.c_ldap_host, buf,
415 sizeof config.c_ldap_host);
418 config.c_ldap_port = atoi(buf);
421 safestrncpy(config.c_ldap_base_dn, buf,
422 sizeof config.c_ldap_base_dn);
425 safestrncpy(config.c_ldap_bind_dn, buf,
426 sizeof config.c_ldap_bind_dn);
429 safestrncpy(config.c_ldap_bind_pw, buf,
430 sizeof config.c_ldap_bind_pw);
434 safestrncpy(config.c_ip_addr, buf,
435 sizeof config.c_ip_addr);
437 config.c_msa_port = atoi(buf);
440 config.c_imaps_port = atoi(buf);
443 config.c_pop3s_port = atoi(buf);
446 config.c_smtps_port = atoi(buf);
449 config.c_enable_fulltext = atoi(buf);
452 config.c_auto_cull = atoi(buf);
455 config.c_instant_expunge = atoi(buf);
458 config.c_allow_spoofing = atoi(buf);
461 config.c_journal_email = atoi(buf);
464 config.c_journal_pubmsgs = atoi(buf);
467 safestrncpy(config.c_journal_dest, buf,
468 sizeof config.c_journal_dest);
470 safestrncpy(config.c_default_cal_zone, buf,
471 sizeof config.c_default_cal_zone);
474 config.c_pftcpdict_port = atoi(buf);
477 config.c_managesieve_port = atoi(buf);
480 config.c_auth_mode = atoi(buf);
482 safestrncpy(config.c_funambol_host, buf,
483 sizeof config.c_funambol_host);
486 config.c_funambol_port = atoi(buf);
489 safestrncpy(config.c_funambol_source,
491 sizeof config.c_funambol_source);
494 safestrncpy(config.c_funambol_auth,
496 sizeof config.c_funambol_auth);
499 config.c_rbl_at_greeting = atoi(buf);
505 snprintf(buf, sizeof buf,
506 "The global system configuration has been edited by %s.\n",
508 aide_message(buf,"Citadel Configuration Manager Message");
510 if (!IsEmptyStr(config.c_logpages))
511 create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
513 /* If full text indexing has been disabled, invalidate the
514 * index so it doesn't try to use it later.
516 if (config.c_enable_fulltext == 0) {
517 CitControl.fulltext_wordbreaker = 0;
522 else if (!strcasecmp(cmd, "GETSYS")) {
523 extract_token(confname, argbuf, 1, '|', sizeof confname);
524 confptr = CtdlGetSysConfig(confname);
525 if (confptr != NULL) {
526 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
527 client_write(confptr, strlen(confptr));
528 if (confptr[strlen(confptr) - 1] != 10)
529 client_write("\n", 1);
533 cprintf("%d No such configuration.\n",
534 ERROR + ILLEGAL_VALUE);
538 else if (!strcasecmp(cmd, "PUTSYS")) {
539 extract_token(confname, argbuf, 1, '|', sizeof confname);
541 cprintf("%d %s\n", SEND_LISTING, confname);
542 confptr = CtdlReadMessageBody("000",
543 config.c_maxmsglen, NULL, 0);
544 CtdlPutSysConfig(confname, confptr);
549 cprintf("%d Illegal option(s) specified.\n",
550 ERROR + ILLEGAL_VALUE);