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)
62 * 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);
278 else if (!strcasecmp(cmd, "SET")) {
280 cprintf("%d Send configuration...\n", SEND_LISTING);
282 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
285 safestrncpy(config.c_nodename, buf,
286 sizeof config.c_nodename);
289 safestrncpy(config.c_fqdn, buf,
290 sizeof config.c_fqdn);
293 safestrncpy(config.c_humannode, buf,
294 sizeof config.c_humannode);
297 safestrncpy(config.c_phonenum, buf,
298 sizeof config.c_phonenum);
301 config.c_creataide = atoi(buf);
304 config.c_sleeping = atoi(buf);
307 config.c_initax = atoi(buf);
308 if (config.c_initax < 1)
310 if (config.c_initax > 6)
314 config.c_regiscall = atoi(buf);
315 if (config.c_regiscall != 0)
316 config.c_regiscall = 1;
319 config.c_twitdetect = atoi(buf);
320 if (config.c_twitdetect != 0)
321 config.c_twitdetect = 1;
324 safestrncpy(config.c_twitroom, buf,
325 sizeof config.c_twitroom);
328 safestrncpy(config.c_moreprompt, buf,
329 sizeof config.c_moreprompt);
332 config.c_restrict = atoi(buf);
333 if (config.c_restrict != 0)
334 config.c_restrict = 1;
337 safestrncpy(config.c_site_location, buf,
338 sizeof config.c_site_location);
341 safestrncpy(config.c_sysadm, buf,
342 sizeof config.c_sysadm);
345 config.c_maxsessions = atoi(buf);
346 if (config.c_maxsessions < 0)
347 config.c_maxsessions = 0;
350 /* placeholder -- field no longer in use */
353 config.c_userpurge = atoi(buf);
356 config.c_roompurge = atoi(buf);
359 safestrncpy(config.c_logpages, buf,
360 sizeof config.c_logpages);
363 config.c_createax = atoi(buf);
364 if (config.c_createax < 1)
365 config.c_createax = 1;
366 if (config.c_createax > 6)
367 config.c_createax = 6;
370 if (atoi(buf) >= 8192)
371 config.c_maxmsglen = atoi(buf);
375 config.c_min_workers = atoi(buf);
377 if (atoi(buf) >= config.c_min_workers)
378 config.c_max_workers = atoi(buf);
380 config.c_pop3_port = atoi(buf);
383 config.c_smtp_port = atoi(buf);
386 config.c_rfc822_strict_from = atoi(buf);
389 config.c_aide_zap = atoi(buf);
390 if (config.c_aide_zap != 0)
391 config.c_aide_zap = 1;
394 config.c_imap_port = atoi(buf);
397 config.c_net_freq = atol(buf);
400 config.c_disable_newu = atoi(buf);
401 if (config.c_disable_newu != 0)
402 config.c_disable_newu = 1;
408 if ((config.c_purge_hour >= 0)
409 && (config.c_purge_hour <= 23)) {
410 config.c_purge_hour = atoi(buf);
415 safestrncpy(config.c_ldap_host, buf,
416 sizeof config.c_ldap_host);
419 config.c_ldap_port = atoi(buf);
422 safestrncpy(config.c_ldap_base_dn, buf,
423 sizeof config.c_ldap_base_dn);
426 safestrncpy(config.c_ldap_bind_dn, buf,
427 sizeof config.c_ldap_bind_dn);
430 safestrncpy(config.c_ldap_bind_pw, buf,
431 sizeof config.c_ldap_bind_pw);
435 safestrncpy(config.c_ip_addr, buf,
436 sizeof config.c_ip_addr);
438 config.c_msa_port = atoi(buf);
441 config.c_imaps_port = atoi(buf);
444 config.c_pop3s_port = atoi(buf);
447 config.c_smtps_port = atoi(buf);
450 config.c_enable_fulltext = atoi(buf);
453 config.c_auto_cull = atoi(buf);
456 config.c_instant_expunge = atoi(buf);
459 config.c_allow_spoofing = atoi(buf);
462 config.c_journal_email = atoi(buf);
465 config.c_journal_pubmsgs = atoi(buf);
468 safestrncpy(config.c_journal_dest, buf,
469 sizeof config.c_journal_dest);
471 safestrncpy(config.c_default_cal_zone, buf,
472 sizeof config.c_default_cal_zone);
475 config.c_pftcpdict_port = atoi(buf);
478 config.c_managesieve_port = atoi(buf);
481 config.c_auth_mode = atoi(buf);
483 safestrncpy(config.c_funambol_host, buf,
484 sizeof config.c_funambol_host);
487 config.c_funambol_port = atoi(buf);
490 safestrncpy(config.c_funambol_source,
492 sizeof config.c_funambol_source);
495 safestrncpy(config.c_funambol_auth,
497 sizeof config.c_funambol_auth);
500 config.c_rbl_at_greeting = atoi(buf);
506 snprintf(buf, sizeof buf,
507 "The global system configuration has been edited by %s.\n",
509 aide_message(buf,"Citadel Configuration Manager Message");
511 if (strlen(config.c_logpages) > 0)
512 create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
514 /* If full text indexing has been disabled, invalidate the
515 * index so it doesn't try to use it later.
517 if (config.c_enable_fulltext == 0) {
518 CitControl.fulltext_wordbreaker = 0;
523 else if (!strcasecmp(cmd, "GETSYS")) {
524 extract_token(confname, argbuf, 1, '|', sizeof confname);
525 confptr = CtdlGetSysConfig(confname);
526 if (confptr != NULL) {
527 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
528 client_write(confptr, strlen(confptr));
529 if (confptr[strlen(confptr) - 1] != 10)
530 client_write("\n", 1);
534 cprintf("%d No such configuration.\n",
535 ERROR + ILLEGAL_VALUE);
539 else if (!strcasecmp(cmd, "PUTSYS")) {
540 extract_token(confname, argbuf, 1, '|', sizeof confname);
542 cprintf("%d %s\n", SEND_LISTING, confname);
543 confptr = CtdlReadMessageBody("000",
544 config.c_maxmsglen, NULL, 0);
545 CtdlPutSysConfig(confname, confptr);
550 cprintf("%d Illegal option(s) specified.\n",
551 ERROR + ILLEGAL_VALUE);