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,
123 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
125 long get_new_message_number(void)
128 begin_critical_section(S_CONTROL);
130 retval = ++CitControl.MMhighest;
132 end_critical_section(S_CONTROL);
138 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
140 long get_new_user_number(void)
143 begin_critical_section(S_CONTROL);
145 retval = ++CitControl.MMnextuser;
147 end_critical_section(S_CONTROL);
154 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
156 long get_new_room_number(void)
159 begin_critical_section(S_CONTROL);
161 retval = ++CitControl.MMnextroom;
163 end_critical_section(S_CONTROL);
170 * Get or set global configuration options
172 void cmd_conf(char *argbuf)
180 if (CtdlAccessCheck(ac_aide)) return;
182 extract_token(cmd, argbuf, 0, '|', sizeof cmd);
183 if (!strcasecmp(cmd, "GET")) {
184 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
185 cprintf("%s\n", config.c_nodename);
186 cprintf("%s\n", config.c_fqdn);
187 cprintf("%s\n", config.c_humannode);
188 cprintf("%s\n", config.c_phonenum);
189 cprintf("%d\n", config.c_creataide);
190 cprintf("%d\n", config.c_sleeping);
191 cprintf("%d\n", config.c_initax);
192 cprintf("%d\n", config.c_regiscall);
193 cprintf("%d\n", config.c_twitdetect);
194 cprintf("%s\n", config.c_twitroom);
195 cprintf("%s\n", config.c_moreprompt);
196 cprintf("%d\n", config.c_restrict);
197 cprintf("%s\n", config.c_site_location);
198 cprintf("%s\n", config.c_sysadm);
199 cprintf("%d\n", config.c_maxsessions);
200 cprintf("xxx\n"); /* placeholder -- field no longer in use */
201 cprintf("%d\n", config.c_userpurge);
202 cprintf("%d\n", config.c_roompurge);
203 cprintf("%s\n", config.c_logpages);
204 cprintf("%d\n", config.c_createax);
205 cprintf("%ld\n", config.c_maxmsglen);
206 cprintf("%d\n", config.c_min_workers);
207 cprintf("%d\n", config.c_max_workers);
208 cprintf("%d\n", config.c_pop3_port);
209 cprintf("%d\n", config.c_smtp_port);
210 cprintf("%d\n", config.c_rfc822_strict_from);
211 cprintf("%d\n", config.c_aide_zap);
212 cprintf("%d\n", config.c_imap_port);
213 cprintf("%ld\n", config.c_net_freq);
214 cprintf("%d\n", config.c_disable_newu);
215 cprintf("1\n"); /* niu */
216 cprintf("%d\n", config.c_purge_hour);
218 cprintf("%s\n", config.c_ldap_host);
219 cprintf("%d\n", config.c_ldap_port);
220 cprintf("%s\n", config.c_ldap_base_dn);
221 cprintf("%s\n", config.c_ldap_bind_dn);
222 cprintf("%s\n", config.c_ldap_bind_pw);
230 cprintf("%s\n", config.c_ip_addr);
231 cprintf("%d\n", config.c_msa_port);
232 cprintf("%d\n", config.c_imaps_port);
233 cprintf("%d\n", config.c_pop3s_port);
234 cprintf("%d\n", config.c_smtps_port);
235 cprintf("%d\n", config.c_enable_fulltext);
236 cprintf("%d\n", config.c_auto_cull);
237 cprintf("%d\n", config.c_instant_expunge);
238 cprintf("%d\n", config.c_allow_spoofing);
239 cprintf("%d\n", config.c_journal_email);
240 cprintf("%d\n", config.c_journal_pubmsgs);
241 cprintf("%s\n", config.c_journal_dest);
242 cprintf("%s\n", config.c_default_cal_zone);
243 cprintf("%d\n", config.c_pftcpdict_port);
244 cprintf("%d\n", config.c_managesieve_port);
245 cprintf("%d\n", config.c_auth_mode);
246 cprintf("%s\n", config.c_funambol_host);
247 cprintf("%d\n", config.c_funambol_port);
248 cprintf("%s\n", config.c_funambol_source);
249 cprintf("%s\n", config.c_funambol_auth);
253 else if (!strcasecmp(cmd, "SET")) {
255 cprintf("%d Send configuration...\n", SEND_LISTING);
257 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
260 safestrncpy(config.c_nodename, buf,
261 sizeof config.c_nodename);
264 safestrncpy(config.c_fqdn, buf,
265 sizeof config.c_fqdn);
268 safestrncpy(config.c_humannode, buf,
269 sizeof config.c_humannode);
272 safestrncpy(config.c_phonenum, buf,
273 sizeof config.c_phonenum);
276 config.c_creataide = atoi(buf);
279 config.c_sleeping = atoi(buf);
282 config.c_initax = atoi(buf);
283 if (config.c_initax < 1)
285 if (config.c_initax > 6)
289 config.c_regiscall = atoi(buf);
290 if (config.c_regiscall != 0)
291 config.c_regiscall = 1;
294 config.c_twitdetect = atoi(buf);
295 if (config.c_twitdetect != 0)
296 config.c_twitdetect = 1;
299 safestrncpy(config.c_twitroom, buf,
300 sizeof config.c_twitroom);
303 safestrncpy(config.c_moreprompt, buf,
304 sizeof config.c_moreprompt);
307 config.c_restrict = atoi(buf);
308 if (config.c_restrict != 0)
309 config.c_restrict = 1;
312 safestrncpy(config.c_site_location, buf,
313 sizeof config.c_site_location);
316 safestrncpy(config.c_sysadm, buf,
317 sizeof config.c_sysadm);
320 config.c_maxsessions = atoi(buf);
321 if (config.c_maxsessions < 0)
322 config.c_maxsessions = 0;
325 /* placeholder -- field no longer in use */
328 config.c_userpurge = atoi(buf);
331 config.c_roompurge = atoi(buf);
334 safestrncpy(config.c_logpages, buf,
335 sizeof config.c_logpages);
338 config.c_createax = atoi(buf);
339 if (config.c_createax < 1)
340 config.c_createax = 1;
341 if (config.c_createax > 6)
342 config.c_createax = 6;
345 if (atoi(buf) >= 8192)
346 config.c_maxmsglen = atoi(buf);
350 config.c_min_workers = atoi(buf);
352 if (atoi(buf) >= config.c_min_workers)
353 config.c_max_workers = atoi(buf);
355 config.c_pop3_port = atoi(buf);
358 config.c_smtp_port = atoi(buf);
361 config.c_rfc822_strict_from = atoi(buf);
364 config.c_aide_zap = atoi(buf);
365 if (config.c_aide_zap != 0)
366 config.c_aide_zap = 1;
369 config.c_imap_port = atoi(buf);
372 config.c_net_freq = atol(buf);
375 config.c_disable_newu = atoi(buf);
376 if (config.c_disable_newu != 0)
377 config.c_disable_newu = 1;
383 if ((config.c_purge_hour >= 0)
384 && (config.c_purge_hour <= 23)) {
385 config.c_purge_hour = atoi(buf);
390 safestrncpy(config.c_ldap_host, buf,
391 sizeof config.c_ldap_host);
394 config.c_ldap_port = atoi(buf);
397 safestrncpy(config.c_ldap_base_dn, buf,
398 sizeof config.c_ldap_base_dn);
401 safestrncpy(config.c_ldap_bind_dn, buf,
402 sizeof config.c_ldap_bind_dn);
405 safestrncpy(config.c_ldap_bind_pw, buf,
406 sizeof config.c_ldap_bind_pw);
410 safestrncpy(config.c_ip_addr, buf,
411 sizeof config.c_ip_addr);
413 config.c_msa_port = atoi(buf);
416 config.c_imaps_port = atoi(buf);
419 config.c_pop3s_port = atoi(buf);
422 config.c_smtps_port = atoi(buf);
425 config.c_enable_fulltext = atoi(buf);
428 config.c_auto_cull = atoi(buf);
431 config.c_instant_expunge = atoi(buf);
434 config.c_allow_spoofing = atoi(buf);
437 config.c_journal_email = atoi(buf);
440 config.c_journal_pubmsgs = atoi(buf);
443 safestrncpy(config.c_journal_dest, buf,
444 sizeof config.c_journal_dest);
446 safestrncpy(config.c_default_cal_zone, buf,
447 sizeof config.c_default_cal_zone);
450 config.c_pftcpdict_port = atoi(buf);
453 config.c_managesieve_port = atoi(buf);
456 config.c_auth_mode = atoi(buf);
458 safestrncpy(config.c_funambol_host, buf,
459 sizeof config.c_funambol_host);
462 config.c_funambol_port = atoi(buf);
465 safestrncpy(config.c_funambol_source,
467 sizeof config.c_funambol_source);
470 safestrncpy(config.c_funambol_auth,
472 sizeof config.c_funambol_auth);
478 snprintf(buf, sizeof buf,
479 "The global system configuration has been edited by %s.\n",
481 aide_message(buf,"Citadel Configuration Manager Message");
483 if (strlen(config.c_logpages) > 0)
484 create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
486 /* If full text indexing has been disabled, invalidate the
487 * index so it doesn't try to use it later.
489 if (config.c_enable_fulltext == 0) {
490 CitControl.fulltext_wordbreaker = 0;
495 else if (!strcasecmp(cmd, "GETSYS")) {
496 extract_token(confname, argbuf, 1, '|', sizeof confname);
497 confptr = CtdlGetSysConfig(confname);
498 if (confptr != NULL) {
499 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
500 client_write(confptr, strlen(confptr));
501 if (confptr[strlen(confptr) - 1] != 10)
502 client_write("\n", 1);
506 cprintf("%d No such configuration.\n",
507 ERROR + ILLEGAL_VALUE);
511 else if (!strcasecmp(cmd, "PUTSYS")) {
512 extract_token(confname, argbuf, 1, '|', sizeof confname);
514 cprintf("%d %s\n", SEND_LISTING, confname);
515 confptr = CtdlReadMessageBody("000",
516 config.c_maxmsglen, NULL, 0);
517 CtdlPutSysConfig(confname, confptr);
522 cprintf("%d Illegal option(s) specified.\n",
523 ERROR + ILLEGAL_VALUE);