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>
34 #include "serv_extensions.h"
35 #include "sysdep_decls.h"
39 #include "citserver.h"
47 struct CitControl CitControl;
48 extern struct config config;
49 FILE *control_fp = NULL;
52 * get_control - read the control record into memory.
54 void get_control(void)
57 /* Zero it out. If the control record on disk is missing or short,
58 * the system functions with all control record fields initialized
61 memset(&CitControl, 0, sizeof(struct CitControl));
62 if (control_fp == NULL) {
63 control_fp = fopen(file_citadel_control, "rb+");
64 if (control_fp != NULL) {
65 fchown(fileno(control_fp), config.c_ctdluid, -1);
68 if (control_fp == NULL) {
69 control_fp = fopen(file_citadel_control, "wb+");
70 if (control_fp != NULL) {
71 fchown(fileno(control_fp), config.c_ctdluid, -1);
72 memset(&CitControl, 0, sizeof(struct CitControl));
73 fwrite(&CitControl, sizeof(struct CitControl),
78 if (control_fp == NULL) {
79 lprintf(CTDL_ALERT, "ERROR opening %s: %s\n",
86 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
90 * put_control - write the control record to disk.
92 void put_control(void)
95 if (control_fp != NULL) {
97 fwrite(&CitControl, sizeof(struct CitControl), 1,
105 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
107 long get_new_message_number(void)
110 begin_critical_section(S_CONTROL);
112 retval = ++CitControl.MMhighest;
114 end_critical_section(S_CONTROL);
120 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
122 long get_new_user_number(void)
125 begin_critical_section(S_CONTROL);
127 retval = ++CitControl.MMnextuser;
129 end_critical_section(S_CONTROL);
136 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
138 long get_new_room_number(void)
141 begin_critical_section(S_CONTROL);
143 retval = ++CitControl.MMnextroom;
145 end_critical_section(S_CONTROL);
152 * Get or set global configuration options
154 void cmd_conf(char *argbuf)
162 if (CtdlAccessCheck(ac_aide)) return;
164 extract_token(cmd, argbuf, 0, '|', sizeof cmd);
165 if (!strcasecmp(cmd, "GET")) {
166 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
167 cprintf("%s\n", config.c_nodename);
168 cprintf("%s\n", config.c_fqdn);
169 cprintf("%s\n", config.c_humannode);
170 cprintf("%s\n", config.c_phonenum);
171 cprintf("%d\n", config.c_creataide);
172 cprintf("%d\n", config.c_sleeping);
173 cprintf("%d\n", config.c_initax);
174 cprintf("%d\n", config.c_regiscall);
175 cprintf("%d\n", config.c_twitdetect);
176 cprintf("%s\n", config.c_twitroom);
177 cprintf("%s\n", config.c_moreprompt);
178 cprintf("%d\n", config.c_restrict);
179 cprintf("%s\n", config.c_site_location);
180 cprintf("%s\n", config.c_sysadm);
181 cprintf("%d\n", config.c_maxsessions);
182 cprintf("xxx\n"); /* placeholder -- field no longer in use */
183 cprintf("%d\n", config.c_userpurge);
184 cprintf("%d\n", config.c_roompurge);
185 cprintf("%s\n", config.c_logpages);
186 cprintf("%d\n", config.c_createax);
187 cprintf("%ld\n", config.c_maxmsglen);
188 cprintf("%d\n", config.c_min_workers);
189 cprintf("%d\n", config.c_max_workers);
190 cprintf("%d\n", config.c_pop3_port);
191 cprintf("%d\n", config.c_smtp_port);
192 cprintf("%d\n", config.c_rfc822_strict_from);
193 cprintf("%d\n", config.c_aide_zap);
194 cprintf("%d\n", config.c_imap_port);
195 cprintf("%ld\n", config.c_net_freq);
196 cprintf("%d\n", config.c_disable_newu);
197 cprintf("1\n"); /* niu */
198 cprintf("%d\n", config.c_purge_hour);
200 cprintf("%s\n", config.c_ldap_host);
201 cprintf("%d\n", config.c_ldap_port);
202 cprintf("%s\n", config.c_ldap_base_dn);
203 cprintf("%s\n", config.c_ldap_bind_dn);
204 cprintf("%s\n", config.c_ldap_bind_pw);
212 cprintf("%s\n", config.c_ip_addr);
213 cprintf("%d\n", config.c_msa_port);
214 cprintf("%d\n", config.c_imaps_port);
215 cprintf("%d\n", config.c_pop3s_port);
216 cprintf("%d\n", config.c_smtps_port);
217 cprintf("%d\n", config.c_enable_fulltext);
218 cprintf("%d\n", config.c_auto_cull);
219 cprintf("%d\n", config.c_instant_expunge);
220 cprintf("%d\n", config.c_allow_spoofing);
221 cprintf("%d\n", config.c_journal_email);
222 cprintf("%d\n", config.c_journal_pubmsgs);
223 cprintf("%s\n", config.c_journal_dest);
224 cprintf("%s\n", config.c_default_cal_zone);
225 cprintf("%d\n", config.c_pftcpdict_port);
226 cprintf("%d\n", config.c_managesieve_port);
230 else if (!strcasecmp(cmd, "SET")) {
232 cprintf("%d Send configuration...\n", SEND_LISTING);
234 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
237 safestrncpy(config.c_nodename, buf,
238 sizeof config.c_nodename);
241 safestrncpy(config.c_fqdn, buf,
242 sizeof config.c_fqdn);
245 safestrncpy(config.c_humannode, buf,
246 sizeof config.c_humannode);
249 safestrncpy(config.c_phonenum, buf,
250 sizeof config.c_phonenum);
253 config.c_creataide = atoi(buf);
256 config.c_sleeping = atoi(buf);
259 config.c_initax = atoi(buf);
260 if (config.c_initax < 1)
262 if (config.c_initax > 6)
266 config.c_regiscall = atoi(buf);
267 if (config.c_regiscall != 0)
268 config.c_regiscall = 1;
271 config.c_twitdetect = atoi(buf);
272 if (config.c_twitdetect != 0)
273 config.c_twitdetect = 1;
276 safestrncpy(config.c_twitroom, buf,
277 sizeof config.c_twitroom);
280 safestrncpy(config.c_moreprompt, buf,
281 sizeof config.c_moreprompt);
284 config.c_restrict = atoi(buf);
285 if (config.c_restrict != 0)
286 config.c_restrict = 1;
289 safestrncpy(config.c_site_location, buf,
290 sizeof config.c_site_location);
293 safestrncpy(config.c_sysadm, buf,
294 sizeof config.c_sysadm);
297 config.c_maxsessions = atoi(buf);
298 if (config.c_maxsessions < 0)
299 config.c_maxsessions = 0;
302 /* placeholder -- field no longer in use */
305 config.c_userpurge = atoi(buf);
308 config.c_roompurge = atoi(buf);
311 safestrncpy(config.c_logpages, buf,
312 sizeof config.c_logpages);
315 config.c_createax = atoi(buf);
316 if (config.c_createax < 1)
317 config.c_createax = 1;
318 if (config.c_createax > 6)
319 config.c_createax = 6;
322 if (atoi(buf) >= 8192)
323 config.c_maxmsglen = atoi(buf);
327 config.c_min_workers = atoi(buf);
329 if (atoi(buf) >= config.c_min_workers)
330 config.c_max_workers = atoi(buf);
332 config.c_pop3_port = atoi(buf);
335 config.c_smtp_port = atoi(buf);
338 config.c_rfc822_strict_from = atoi(buf);
341 config.c_aide_zap = atoi(buf);
342 if (config.c_aide_zap != 0)
343 config.c_aide_zap = 1;
346 config.c_imap_port = atoi(buf);
349 config.c_net_freq = atol(buf);
352 config.c_disable_newu = atoi(buf);
353 if (config.c_disable_newu != 0)
354 config.c_disable_newu = 1;
360 if ((config.c_purge_hour >= 0)
361 && (config.c_purge_hour <= 23)) {
362 config.c_purge_hour = atoi(buf);
367 safestrncpy(config.c_ldap_host, buf,
368 sizeof config.c_ldap_host);
371 config.c_ldap_port = atoi(buf);
374 safestrncpy(config.c_ldap_base_dn, buf,
375 sizeof config.c_ldap_base_dn);
378 safestrncpy(config.c_ldap_bind_dn, buf,
379 sizeof config.c_ldap_bind_dn);
382 safestrncpy(config.c_ldap_bind_pw, buf,
383 sizeof config.c_ldap_bind_pw);
387 safestrncpy(config.c_ip_addr, buf,
388 sizeof config.c_ip_addr);
390 config.c_msa_port = atoi(buf);
393 config.c_imaps_port = atoi(buf);
396 config.c_pop3s_port = atoi(buf);
399 config.c_smtps_port = atoi(buf);
402 config.c_enable_fulltext = atoi(buf);
405 config.c_auto_cull = atoi(buf);
408 config.c_instant_expunge = atoi(buf);
411 config.c_allow_spoofing = atoi(buf);
414 config.c_journal_email = atoi(buf);
417 config.c_journal_pubmsgs = atoi(buf);
420 safestrncpy(config.c_journal_dest, buf,
421 sizeof config.c_journal_dest);
423 safestrncpy(config.c_default_cal_zone, buf,
424 sizeof config.c_default_cal_zone);
427 config.c_pftcpdict_port = atoi(buf);
430 config.c_managesieve_port = atoi(buf);
436 snprintf(buf, sizeof buf,
437 "The global system configuration has been edited by %s.\n",
441 if (strlen(config.c_logpages) > 0)
442 create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
444 /* If full text indexing has been disabled, invalidate the
445 * index so it doesn't try to use it later.
447 if (config.c_enable_fulltext == 0) {
448 CitControl.fulltext_wordbreaker = 0;
453 else if (!strcasecmp(cmd, "GETSYS")) {
454 extract_token(confname, argbuf, 1, '|', sizeof confname);
455 confptr = CtdlGetSysConfig(confname);
456 if (confptr != NULL) {
457 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
458 client_write(confptr, strlen(confptr));
459 if (confptr[strlen(confptr) - 1] != 10)
460 client_write("\n", 1);
464 cprintf("%d No such configuration.\n",
465 ERROR + ILLEGAL_VALUE);
469 else if (!strcasecmp(cmd, "PUTSYS")) {
470 extract_token(confname, argbuf, 1, '|', sizeof confname);
472 cprintf("%d %s\n", SEND_LISTING, confname);
473 confptr = CtdlReadMessageBody("000",
474 config.c_maxmsglen, NULL, 0);
475 CtdlPutSysConfig(confname, confptr);
480 cprintf("%d Illegal option(s) specified.\n",
481 ERROR + ILLEGAL_VALUE);