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);
227 else if (!strcasecmp(cmd, "SET")) {
229 cprintf("%d Send configuration...\n", SEND_LISTING);
231 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
234 safestrncpy(config.c_nodename, buf,
235 sizeof config.c_nodename);
238 safestrncpy(config.c_fqdn, buf,
239 sizeof config.c_fqdn);
242 safestrncpy(config.c_humannode, buf,
243 sizeof config.c_humannode);
246 safestrncpy(config.c_phonenum, buf,
247 sizeof config.c_phonenum);
250 config.c_creataide = atoi(buf);
253 config.c_sleeping = atoi(buf);
256 config.c_initax = atoi(buf);
257 if (config.c_initax < 1)
259 if (config.c_initax > 6)
263 config.c_regiscall = atoi(buf);
264 if (config.c_regiscall != 0)
265 config.c_regiscall = 1;
268 config.c_twitdetect = atoi(buf);
269 if (config.c_twitdetect != 0)
270 config.c_twitdetect = 1;
273 safestrncpy(config.c_twitroom, buf,
274 sizeof config.c_twitroom);
277 safestrncpy(config.c_moreprompt, buf,
278 sizeof config.c_moreprompt);
281 config.c_restrict = atoi(buf);
282 if (config.c_restrict != 0)
283 config.c_restrict = 1;
286 safestrncpy(config.c_site_location, buf,
287 sizeof config.c_site_location);
290 safestrncpy(config.c_sysadm, buf,
291 sizeof config.c_sysadm);
294 config.c_maxsessions = atoi(buf);
295 if (config.c_maxsessions < 0)
296 config.c_maxsessions = 0;
299 /* placeholder -- field no longer in use */
302 config.c_userpurge = atoi(buf);
305 config.c_roompurge = atoi(buf);
308 safestrncpy(config.c_logpages, buf,
309 sizeof config.c_logpages);
312 config.c_createax = atoi(buf);
313 if (config.c_createax < 1)
314 config.c_createax = 1;
315 if (config.c_createax > 6)
316 config.c_createax = 6;
319 if (atoi(buf) >= 8192)
320 config.c_maxmsglen = atoi(buf);
324 config.c_min_workers = atoi(buf);
326 if (atoi(buf) >= config.c_min_workers)
327 config.c_max_workers = atoi(buf);
329 config.c_pop3_port = atoi(buf);
332 config.c_smtp_port = atoi(buf);
335 config.c_rfc822_strict_from = atoi(buf);
338 config.c_aide_zap = atoi(buf);
339 if (config.c_aide_zap != 0)
340 config.c_aide_zap = 1;
343 config.c_imap_port = atoi(buf);
346 config.c_net_freq = atol(buf);
349 config.c_disable_newu = atoi(buf);
350 if (config.c_disable_newu != 0)
351 config.c_disable_newu = 1;
357 if ((config.c_purge_hour >= 0)
358 && (config.c_purge_hour <= 23)) {
359 config.c_purge_hour = atoi(buf);
364 safestrncpy(config.c_ldap_host, buf,
365 sizeof config.c_ldap_host);
368 config.c_ldap_port = atoi(buf);
371 safestrncpy(config.c_ldap_base_dn, buf,
372 sizeof config.c_ldap_base_dn);
375 safestrncpy(config.c_ldap_bind_dn, buf,
376 sizeof config.c_ldap_bind_dn);
379 safestrncpy(config.c_ldap_bind_pw, buf,
380 sizeof config.c_ldap_bind_pw);
384 safestrncpy(config.c_ip_addr, buf,
385 sizeof config.c_ip_addr);
387 config.c_msa_port = atoi(buf);
390 config.c_imaps_port = atoi(buf);
393 config.c_pop3s_port = atoi(buf);
396 config.c_smtps_port = atoi(buf);
399 config.c_enable_fulltext = atoi(buf);
402 config.c_auto_cull = atoi(buf);
405 config.c_instant_expunge = atoi(buf);
408 config.c_allow_spoofing = atoi(buf);
411 config.c_journal_email = atoi(buf);
414 config.c_journal_pubmsgs = atoi(buf);
417 safestrncpy(config.c_journal_dest, buf,
418 sizeof config.c_journal_dest);
423 snprintf(buf, sizeof buf,
424 "The global system configuration has been edited by %s.\n",
428 if (strlen(config.c_logpages) > 0)
429 create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
431 /* If full text indexing has been disabled, invalidate the
432 * index so it doesn't try to use it later.
434 if (config.c_enable_fulltext == 0) {
435 CitControl.fulltext_wordbreaker = 0;
440 else if (!strcasecmp(cmd, "GETSYS")) {
441 extract_token(confname, argbuf, 1, '|', sizeof confname);
442 confptr = CtdlGetSysConfig(confname);
443 if (confptr != NULL) {
444 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
445 client_write(confptr, strlen(confptr));
446 if (confptr[strlen(confptr) - 1] != 10)
447 client_write("\n", 1);
451 cprintf("%d No such configuration.\n",
452 ERROR + ILLEGAL_VALUE);
456 else if (!strcasecmp(cmd, "PUTSYS")) {
457 extract_token(confname, argbuf, 1, '|', sizeof confname);
459 cprintf("%d %s\n", SEND_LISTING, confname);
460 confptr = CtdlReadMessageBody("000",
461 config.c_maxmsglen, NULL, 0);
462 CtdlPutSysConfig(confname, confptr);
467 cprintf("%d Illegal option(s) specified.\n",
468 ERROR + ILLEGAL_VALUE);