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)
120 begin_critical_section(S_CONTROL);
122 ++CitControl.MMhighest;
124 end_critical_section(S_CONTROL);
125 return (CitControl.MMhighest);
130 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
132 long get_new_user_number(void)
134 begin_critical_section(S_CONTROL);
136 ++CitControl.MMnextuser;
138 end_critical_section(S_CONTROL);
139 return (CitControl.MMnextuser);
145 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
147 long get_new_room_number(void)
149 begin_critical_section(S_CONTROL);
151 ++CitControl.MMnextroom;
153 end_critical_section(S_CONTROL);
154 return (CitControl.MMnextroom);
160 * Get or set global configuration options
162 void cmd_conf(char *argbuf)
170 if (CtdlAccessCheck(ac_aide)) return;
172 extract_token(cmd, argbuf, 0, '|', sizeof cmd);
173 if (!strcasecmp(cmd, "GET")) {
174 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
175 cprintf("%s\n", config.c_nodename);
176 cprintf("%s\n", config.c_fqdn);
177 cprintf("%s\n", config.c_humannode);
178 cprintf("%s\n", config.c_phonenum);
179 cprintf("%d\n", config.c_creataide);
180 cprintf("%d\n", config.c_sleeping);
181 cprintf("%d\n", config.c_initax);
182 cprintf("%d\n", config.c_regiscall);
183 cprintf("%d\n", config.c_twitdetect);
184 cprintf("%s\n", config.c_twitroom);
185 cprintf("%s\n", config.c_moreprompt);
186 cprintf("%d\n", config.c_restrict);
187 cprintf("%s\n", config.c_site_location);
188 cprintf("%s\n", config.c_sysadm);
189 cprintf("%d\n", config.c_maxsessions);
190 cprintf("xxx\n"); /* placeholder -- field no longer in use */
191 cprintf("%d\n", config.c_userpurge);
192 cprintf("%d\n", config.c_roompurge);
193 cprintf("%s\n", config.c_logpages);
194 cprintf("%d\n", config.c_createax);
195 cprintf("%ld\n", config.c_maxmsglen);
196 cprintf("%d\n", config.c_min_workers);
197 cprintf("%d\n", config.c_max_workers);
198 cprintf("%d\n", config.c_pop3_port);
199 cprintf("%d\n", config.c_smtp_port);
200 cprintf("%d\n", config.c_rfc822_strict_from);
201 cprintf("%d\n", config.c_aide_zap);
202 cprintf("%d\n", config.c_imap_port);
203 cprintf("%ld\n", config.c_net_freq);
204 cprintf("%d\n", config.c_disable_newu);
205 cprintf("1\n"); /* niu */
206 cprintf("%d\n", config.c_purge_hour);
208 cprintf("%s\n", config.c_ldap_host);
209 cprintf("%d\n", config.c_ldap_port);
210 cprintf("%s\n", config.c_ldap_base_dn);
211 cprintf("%s\n", config.c_ldap_bind_dn);
212 cprintf("%s\n", config.c_ldap_bind_pw);
220 cprintf("%s\n", config.c_ip_addr);
221 cprintf("%d\n", config.c_msa_port);
222 cprintf("%d\n", config.c_imaps_port);
223 cprintf("%d\n", config.c_pop3s_port);
224 cprintf("%d\n", config.c_smtps_port);
225 cprintf("%d\n", config.c_enable_fulltext);
226 cprintf("%d\n", config.c_auto_cull);
227 cprintf("%d\n", config.c_instant_expunge);
228 cprintf("%d\n", config.c_allow_spoofing);
232 else if (!strcasecmp(cmd, "SET")) {
234 cprintf("%d Send configuration...\n", SEND_LISTING);
236 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
239 safestrncpy(config.c_nodename, buf,
240 sizeof config.c_nodename);
243 safestrncpy(config.c_fqdn, buf,
244 sizeof config.c_fqdn);
247 safestrncpy(config.c_humannode, buf,
248 sizeof config.c_humannode);
251 safestrncpy(config.c_phonenum, buf,
252 sizeof config.c_phonenum);
255 config.c_creataide = atoi(buf);
258 config.c_sleeping = atoi(buf);
261 config.c_initax = atoi(buf);
262 if (config.c_initax < 1)
264 if (config.c_initax > 6)
268 config.c_regiscall = atoi(buf);
269 if (config.c_regiscall != 0)
270 config.c_regiscall = 1;
273 config.c_twitdetect = atoi(buf);
274 if (config.c_twitdetect != 0)
275 config.c_twitdetect = 1;
278 safestrncpy(config.c_twitroom, buf,
279 sizeof config.c_twitroom);
282 safestrncpy(config.c_moreprompt, buf,
283 sizeof config.c_moreprompt);
286 config.c_restrict = atoi(buf);
287 if (config.c_restrict != 0)
288 config.c_restrict = 1;
291 safestrncpy(config.c_site_location, buf,
292 sizeof config.c_site_location);
295 safestrncpy(config.c_sysadm, buf,
296 sizeof config.c_sysadm);
299 config.c_maxsessions = atoi(buf);
300 if (config.c_maxsessions < 0)
301 config.c_maxsessions = 0;
304 /* placeholder -- field no longer in use */
307 config.c_userpurge = atoi(buf);
310 config.c_roompurge = atoi(buf);
313 safestrncpy(config.c_logpages, buf,
314 sizeof config.c_logpages);
317 config.c_createax = atoi(buf);
318 if (config.c_createax < 1)
319 config.c_createax = 1;
320 if (config.c_createax > 6)
321 config.c_createax = 6;
324 if (atoi(buf) >= 8192)
325 config.c_maxmsglen = atoi(buf);
329 config.c_min_workers = atoi(buf);
331 if (atoi(buf) >= config.c_min_workers)
332 config.c_max_workers = atoi(buf);
334 config.c_pop3_port = atoi(buf);
337 config.c_smtp_port = atoi(buf);
340 config.c_rfc822_strict_from = atoi(buf);
343 config.c_aide_zap = atoi(buf);
344 if (config.c_aide_zap != 0)
345 config.c_aide_zap = 1;
348 config.c_imap_port = atoi(buf);
351 config.c_net_freq = atol(buf);
354 config.c_disable_newu = atoi(buf);
355 if (config.c_disable_newu != 0)
356 config.c_disable_newu = 1;
362 if ((config.c_purge_hour >= 0)
363 && (config.c_purge_hour <= 23)) {
364 config.c_purge_hour = atoi(buf);
369 safestrncpy(config.c_ldap_host, buf,
370 sizeof config.c_ldap_host);
373 config.c_ldap_port = atoi(buf);
376 safestrncpy(config.c_ldap_base_dn, buf,
377 sizeof config.c_ldap_base_dn);
380 safestrncpy(config.c_ldap_bind_dn, buf,
381 sizeof config.c_ldap_bind_dn);
384 safestrncpy(config.c_ldap_bind_pw, buf,
385 sizeof config.c_ldap_bind_pw);
389 safestrncpy(config.c_ip_addr, buf,
390 sizeof config.c_ip_addr);
392 config.c_msa_port = atoi(buf);
395 config.c_imaps_port = atoi(buf);
398 config.c_pop3s_port = atoi(buf);
401 config.c_smtps_port = atoi(buf);
404 config.c_enable_fulltext = atoi(buf);
407 config.c_auto_cull = atoi(buf);
410 config.c_instant_expunge = atoi(buf);
413 config.c_allow_spoofing = atoi(buf);
419 snprintf(buf, sizeof buf,
420 "The global system configuration has been edited by %s.\n",
424 if (strlen(config.c_logpages) > 0)
425 create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
427 /* If full text indexing has been disabled, invalidate the
428 * index so it doesn't try to use it later.
430 if (!config.c_enable_fulltext == 0) {
431 CitControl.fulltext_wordbreaker = 0;
436 else if (!strcasecmp(cmd, "GETSYS")) {
437 extract_token(confname, argbuf, 1, '|', sizeof confname);
438 confptr = CtdlGetSysConfig(confname);
439 if (confptr != NULL) {
440 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
441 client_write(confptr, strlen(confptr));
442 if (confptr[strlen(confptr) - 1] != 10)
443 client_write("\n", 1);
447 cprintf("%d No such configuration.\n",
448 ERROR + ILLEGAL_VALUE);
452 else if (!strcasecmp(cmd, "PUTSYS")) {
453 extract_token(confname, argbuf, 1, '|', sizeof confname);
455 cprintf("%d %s\n", SEND_LISTING, confname);
456 confptr = CtdlReadMessageBody("000",
457 config.c_maxmsglen, NULL, 0);
458 CtdlPutSysConfig(confname, confptr);
463 cprintf("%d Illegal option(s) specified.\n",
464 ERROR + ILLEGAL_VALUE);