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);
228 else if (!strcasecmp(cmd, "SET")) {
230 cprintf("%d Send configuration...\n", SEND_LISTING);
232 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
235 safestrncpy(config.c_nodename, buf,
236 sizeof config.c_nodename);
239 safestrncpy(config.c_fqdn, buf,
240 sizeof config.c_fqdn);
243 safestrncpy(config.c_humannode, buf,
244 sizeof config.c_humannode);
247 safestrncpy(config.c_phonenum, buf,
248 sizeof config.c_phonenum);
251 config.c_creataide = atoi(buf);
254 config.c_sleeping = atoi(buf);
257 config.c_initax = atoi(buf);
258 if (config.c_initax < 1)
260 if (config.c_initax > 6)
264 config.c_regiscall = atoi(buf);
265 if (config.c_regiscall != 0)
266 config.c_regiscall = 1;
269 config.c_twitdetect = atoi(buf);
270 if (config.c_twitdetect != 0)
271 config.c_twitdetect = 1;
274 safestrncpy(config.c_twitroom, buf,
275 sizeof config.c_twitroom);
278 safestrncpy(config.c_moreprompt, buf,
279 sizeof config.c_moreprompt);
282 config.c_restrict = atoi(buf);
283 if (config.c_restrict != 0)
284 config.c_restrict = 1;
287 safestrncpy(config.c_site_location, buf,
288 sizeof config.c_site_location);
291 safestrncpy(config.c_sysadm, buf,
292 sizeof config.c_sysadm);
295 config.c_maxsessions = atoi(buf);
296 if (config.c_maxsessions < 0)
297 config.c_maxsessions = 0;
300 /* placeholder -- field no longer in use */
303 config.c_userpurge = atoi(buf);
306 config.c_roompurge = atoi(buf);
309 safestrncpy(config.c_logpages, buf,
310 sizeof config.c_logpages);
313 config.c_createax = atoi(buf);
314 if (config.c_createax < 1)
315 config.c_createax = 1;
316 if (config.c_createax > 6)
317 config.c_createax = 6;
320 if (atoi(buf) >= 8192)
321 config.c_maxmsglen = atoi(buf);
325 config.c_min_workers = atoi(buf);
327 if (atoi(buf) >= config.c_min_workers)
328 config.c_max_workers = atoi(buf);
330 config.c_pop3_port = atoi(buf);
333 config.c_smtp_port = atoi(buf);
336 config.c_rfc822_strict_from = atoi(buf);
339 config.c_aide_zap = atoi(buf);
340 if (config.c_aide_zap != 0)
341 config.c_aide_zap = 1;
344 config.c_imap_port = atoi(buf);
347 config.c_net_freq = atol(buf);
350 config.c_disable_newu = atoi(buf);
351 if (config.c_disable_newu != 0)
352 config.c_disable_newu = 1;
358 if ((config.c_purge_hour >= 0)
359 && (config.c_purge_hour <= 23)) {
360 config.c_purge_hour = atoi(buf);
365 safestrncpy(config.c_ldap_host, buf,
366 sizeof config.c_ldap_host);
369 config.c_ldap_port = atoi(buf);
372 safestrncpy(config.c_ldap_base_dn, buf,
373 sizeof config.c_ldap_base_dn);
376 safestrncpy(config.c_ldap_bind_dn, buf,
377 sizeof config.c_ldap_bind_dn);
380 safestrncpy(config.c_ldap_bind_pw, buf,
381 sizeof config.c_ldap_bind_pw);
385 safestrncpy(config.c_ip_addr, buf,
386 sizeof config.c_ip_addr);
388 config.c_msa_port = atoi(buf);
391 config.c_imaps_port = atoi(buf);
394 config.c_pop3s_port = atoi(buf);
397 config.c_smtps_port = atoi(buf);
400 config.c_enable_fulltext = atoi(buf);
403 config.c_auto_cull = atoi(buf);
406 config.c_instant_expunge = atoi(buf);
409 config.c_allow_spoofing = atoi(buf);
412 config.c_journal_email = atoi(buf);
415 config.c_journal_pubmsgs = atoi(buf);
418 safestrncpy(config.c_journal_dest, buf,
419 sizeof config.c_journal_dest);
421 safestrncpy(config.c_default_cal_zone, buf,
422 sizeof config.c_default_cal_zone);
427 snprintf(buf, sizeof buf,
428 "The global system configuration has been edited by %s.\n",
432 if (strlen(config.c_logpages) > 0)
433 create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
435 /* If full text indexing has been disabled, invalidate the
436 * index so it doesn't try to use it later.
438 if (config.c_enable_fulltext == 0) {
439 CitControl.fulltext_wordbreaker = 0;
444 else if (!strcasecmp(cmd, "GETSYS")) {
445 extract_token(confname, argbuf, 1, '|', sizeof confname);
446 confptr = CtdlGetSysConfig(confname);
447 if (confptr != NULL) {
448 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
449 client_write(confptr, strlen(confptr));
450 if (confptr[strlen(confptr) - 1] != 10)
451 client_write("\n", 1);
455 cprintf("%d No such configuration.\n",
456 ERROR + ILLEGAL_VALUE);
460 else if (!strcasecmp(cmd, "PUTSYS")) {
461 extract_token(confname, argbuf, 1, '|', sizeof confname);
463 cprintf("%d %s\n", SEND_LISTING, confname);
464 confptr = CtdlReadMessageBody("000",
465 config.c_maxmsglen, NULL, 0);
466 CtdlPutSysConfig(confname, confptr);
471 cprintf("%d Illegal option(s) specified.\n",
472 ERROR + ILLEGAL_VALUE);