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) {
69 "/citadel.control", "rb+");
70 if (control_fp != NULL) {
71 fchown(fileno(control_fp), config.c_ctdluid, -1);
74 if (control_fp == NULL) {
81 "/citadel.control", "wb+");
82 if (control_fp != NULL) {
83 fchown(fileno(control_fp), config.c_ctdluid, -1);
84 memset(&CitControl, 0, sizeof(struct CitControl));
85 fwrite(&CitControl, sizeof(struct CitControl),
90 if (control_fp == NULL) {
91 lprintf(CTDL_ALERT, "ERROR opening citadel.control: %s\n",
97 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
101 * put_control - write the control record to disk.
103 void put_control(void)
106 if (control_fp != NULL) {
108 fwrite(&CitControl, sizeof(struct CitControl), 1,
116 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
118 long get_new_message_number(void)
121 begin_critical_section(S_CONTROL);
123 retval = ++CitControl.MMhighest;
125 end_critical_section(S_CONTROL);
131 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
133 long get_new_user_number(void)
136 begin_critical_section(S_CONTROL);
138 retval = ++CitControl.MMnextuser;
140 end_critical_section(S_CONTROL);
147 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
149 long get_new_room_number(void)
152 begin_critical_section(S_CONTROL);
154 retval = ++CitControl.MMnextroom;
156 end_critical_section(S_CONTROL);
163 * Get or set global configuration options
165 void cmd_conf(char *argbuf)
173 if (CtdlAccessCheck(ac_aide)) return;
175 extract_token(cmd, argbuf, 0, '|', sizeof cmd);
176 if (!strcasecmp(cmd, "GET")) {
177 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
178 cprintf("%s\n", config.c_nodename);
179 cprintf("%s\n", config.c_fqdn);
180 cprintf("%s\n", config.c_humannode);
181 cprintf("%s\n", config.c_phonenum);
182 cprintf("%d\n", config.c_creataide);
183 cprintf("%d\n", config.c_sleeping);
184 cprintf("%d\n", config.c_initax);
185 cprintf("%d\n", config.c_regiscall);
186 cprintf("%d\n", config.c_twitdetect);
187 cprintf("%s\n", config.c_twitroom);
188 cprintf("%s\n", config.c_moreprompt);
189 cprintf("%d\n", config.c_restrict);
190 cprintf("%s\n", config.c_site_location);
191 cprintf("%s\n", config.c_sysadm);
192 cprintf("%d\n", config.c_maxsessions);
193 cprintf("xxx\n"); /* placeholder -- field no longer in use */
194 cprintf("%d\n", config.c_userpurge);
195 cprintf("%d\n", config.c_roompurge);
196 cprintf("%s\n", config.c_logpages);
197 cprintf("%d\n", config.c_createax);
198 cprintf("%ld\n", config.c_maxmsglen);
199 cprintf("%d\n", config.c_min_workers);
200 cprintf("%d\n", config.c_max_workers);
201 cprintf("%d\n", config.c_pop3_port);
202 cprintf("%d\n", config.c_smtp_port);
203 cprintf("%d\n", config.c_rfc822_strict_from);
204 cprintf("%d\n", config.c_aide_zap);
205 cprintf("%d\n", config.c_imap_port);
206 cprintf("%ld\n", config.c_net_freq);
207 cprintf("%d\n", config.c_disable_newu);
208 cprintf("1\n"); /* niu */
209 cprintf("%d\n", config.c_purge_hour);
211 cprintf("%s\n", config.c_ldap_host);
212 cprintf("%d\n", config.c_ldap_port);
213 cprintf("%s\n", config.c_ldap_base_dn);
214 cprintf("%s\n", config.c_ldap_bind_dn);
215 cprintf("%s\n", config.c_ldap_bind_pw);
223 cprintf("%s\n", config.c_ip_addr);
224 cprintf("%d\n", config.c_msa_port);
225 cprintf("%d\n", config.c_imaps_port);
226 cprintf("%d\n", config.c_pop3s_port);
227 cprintf("%d\n", config.c_smtps_port);
228 cprintf("%d\n", config.c_enable_fulltext);
229 cprintf("%d\n", config.c_auto_cull);
230 cprintf("%d\n", config.c_instant_expunge);
231 cprintf("%d\n", config.c_allow_spoofing);
232 cprintf("%d\n", config.c_journal_email);
233 cprintf("%d\n", config.c_journal_pubmsgs);
234 cprintf("%s\n", config.c_journal_dest);
238 else if (!strcasecmp(cmd, "SET")) {
240 cprintf("%d Send configuration...\n", SEND_LISTING);
242 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
245 safestrncpy(config.c_nodename, buf,
246 sizeof config.c_nodename);
249 safestrncpy(config.c_fqdn, buf,
250 sizeof config.c_fqdn);
253 safestrncpy(config.c_humannode, buf,
254 sizeof config.c_humannode);
257 safestrncpy(config.c_phonenum, buf,
258 sizeof config.c_phonenum);
261 config.c_creataide = atoi(buf);
264 config.c_sleeping = atoi(buf);
267 config.c_initax = atoi(buf);
268 if (config.c_initax < 1)
270 if (config.c_initax > 6)
274 config.c_regiscall = atoi(buf);
275 if (config.c_regiscall != 0)
276 config.c_regiscall = 1;
279 config.c_twitdetect = atoi(buf);
280 if (config.c_twitdetect != 0)
281 config.c_twitdetect = 1;
284 safestrncpy(config.c_twitroom, buf,
285 sizeof config.c_twitroom);
288 safestrncpy(config.c_moreprompt, buf,
289 sizeof config.c_moreprompt);
292 config.c_restrict = atoi(buf);
293 if (config.c_restrict != 0)
294 config.c_restrict = 1;
297 safestrncpy(config.c_site_location, buf,
298 sizeof config.c_site_location);
301 safestrncpy(config.c_sysadm, buf,
302 sizeof config.c_sysadm);
305 config.c_maxsessions = atoi(buf);
306 if (config.c_maxsessions < 0)
307 config.c_maxsessions = 0;
310 /* placeholder -- field no longer in use */
313 config.c_userpurge = atoi(buf);
316 config.c_roompurge = atoi(buf);
319 safestrncpy(config.c_logpages, buf,
320 sizeof config.c_logpages);
323 config.c_createax = atoi(buf);
324 if (config.c_createax < 1)
325 config.c_createax = 1;
326 if (config.c_createax > 6)
327 config.c_createax = 6;
330 if (atoi(buf) >= 8192)
331 config.c_maxmsglen = atoi(buf);
335 config.c_min_workers = atoi(buf);
337 if (atoi(buf) >= config.c_min_workers)
338 config.c_max_workers = atoi(buf);
340 config.c_pop3_port = atoi(buf);
343 config.c_smtp_port = atoi(buf);
346 config.c_rfc822_strict_from = atoi(buf);
349 config.c_aide_zap = atoi(buf);
350 if (config.c_aide_zap != 0)
351 config.c_aide_zap = 1;
354 config.c_imap_port = atoi(buf);
357 config.c_net_freq = atol(buf);
360 config.c_disable_newu = atoi(buf);
361 if (config.c_disable_newu != 0)
362 config.c_disable_newu = 1;
368 if ((config.c_purge_hour >= 0)
369 && (config.c_purge_hour <= 23)) {
370 config.c_purge_hour = atoi(buf);
375 safestrncpy(config.c_ldap_host, buf,
376 sizeof config.c_ldap_host);
379 config.c_ldap_port = atoi(buf);
382 safestrncpy(config.c_ldap_base_dn, buf,
383 sizeof config.c_ldap_base_dn);
386 safestrncpy(config.c_ldap_bind_dn, buf,
387 sizeof config.c_ldap_bind_dn);
390 safestrncpy(config.c_ldap_bind_pw, buf,
391 sizeof config.c_ldap_bind_pw);
395 safestrncpy(config.c_ip_addr, buf,
396 sizeof config.c_ip_addr);
398 config.c_msa_port = atoi(buf);
401 config.c_imaps_port = atoi(buf);
404 config.c_pop3s_port = atoi(buf);
407 config.c_smtps_port = atoi(buf);
410 config.c_enable_fulltext = atoi(buf);
413 config.c_auto_cull = atoi(buf);
416 config.c_instant_expunge = atoi(buf);
419 config.c_allow_spoofing = atoi(buf);
422 config.c_journal_email = atoi(buf);
425 config.c_journal_pubmsgs = atoi(buf);
428 safestrncpy(config.c_journal_dest, buf,
429 sizeof config.c_journal_dest);
434 snprintf(buf, sizeof buf,
435 "The global system configuration has been edited by %s.\n",
439 if (strlen(config.c_logpages) > 0)
440 create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
442 /* If full text indexing has been disabled, invalidate the
443 * index so it doesn't try to use it later.
445 if (!config.c_enable_fulltext == 0) {
446 CitControl.fulltext_wordbreaker = 0;
451 else if (!strcasecmp(cmd, "GETSYS")) {
452 extract_token(confname, argbuf, 1, '|', sizeof confname);
453 confptr = CtdlGetSysConfig(confname);
454 if (confptr != NULL) {
455 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
456 client_write(confptr, strlen(confptr));
457 if (confptr[strlen(confptr) - 1] != 10)
458 client_write("\n", 1);
462 cprintf("%d No such configuration.\n",
463 ERROR + ILLEGAL_VALUE);
467 else if (!strcasecmp(cmd, "PUTSYS")) {
468 extract_token(confname, argbuf, 1, '|', sizeof confname);
470 cprintf("%d %s\n", SEND_LISTING, confname);
471 confptr = CtdlReadMessageBody("000",
472 config.c_maxmsglen, NULL, 0);
473 CtdlPutSysConfig(confname, confptr);
478 cprintf("%d Illegal option(s) specified.\n",
479 ERROR + ILLEGAL_VALUE);