4 * This module handles states which are global to the entire server.
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
24 # include <sys/time.h>
34 #include <sys/types.h>
38 #include "serv_extensions.h"
39 #include "sysdep_decls.h"
43 #include "citserver.h"
51 struct CitControl CitControl;
52 extern struct config config;
53 FILE *control_fp = NULL;
56 * get_control - read the control record into memory.
58 void get_control(void)
61 /* Zero it out. If the control record on disk is missing or short,
62 * the system functions with all control record fields initialized
65 memset(&CitControl, 0, sizeof(struct CitControl));
66 if (control_fp == NULL) {
73 "/citadel.control", "rb+");
74 if (control_fp != NULL) {
75 fchown(fileno(control_fp), config.c_ctdluid, -1);
78 if (control_fp == NULL) {
85 "/citadel.control", "wb+");
86 if (control_fp != NULL) {
87 fchown(fileno(control_fp), config.c_ctdluid, -1);
88 memset(&CitControl, 0, sizeof(struct CitControl));
89 fwrite(&CitControl, sizeof(struct CitControl),
94 if (control_fp == NULL) {
95 lprintf(CTDL_ALERT, "ERROR opening citadel.control: %s\n",
101 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
105 * put_control - write the control record to disk.
107 void put_control(void)
110 if (control_fp != NULL) {
112 fwrite(&CitControl, sizeof(struct CitControl), 1,
120 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
122 long get_new_message_number(void)
124 begin_critical_section(S_CONTROL);
126 ++CitControl.MMhighest;
128 end_critical_section(S_CONTROL);
129 return (CitControl.MMhighest);
134 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
136 long get_new_user_number(void)
138 begin_critical_section(S_CONTROL);
140 ++CitControl.MMnextuser;
142 end_critical_section(S_CONTROL);
143 return (CitControl.MMnextuser);
149 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
151 long get_new_room_number(void)
153 begin_critical_section(S_CONTROL);
155 ++CitControl.MMnextroom;
157 end_critical_section(S_CONTROL);
158 return (CitControl.MMnextroom);
164 * Get or set global configuration options
166 void cmd_conf(char *argbuf)
174 if (CtdlAccessCheck(ac_aide)) return;
176 extract_token(cmd, argbuf, 0, '|', sizeof cmd);
177 if (!strcasecmp(cmd, "GET")) {
178 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
179 cprintf("%s\n", config.c_nodename);
180 cprintf("%s\n", config.c_fqdn);
181 cprintf("%s\n", config.c_humannode);
182 cprintf("%s\n", config.c_phonenum);
183 cprintf("%d\n", config.c_creataide);
184 cprintf("%d\n", config.c_sleeping);
185 cprintf("%d\n", config.c_initax);
186 cprintf("%d\n", config.c_regiscall);
187 cprintf("%d\n", config.c_twitdetect);
188 cprintf("%s\n", config.c_twitroom);
189 cprintf("%s\n", config.c_moreprompt);
190 cprintf("%d\n", config.c_restrict);
191 cprintf("%s\n", config.c_site_location);
192 cprintf("%s\n", config.c_sysadm);
193 cprintf("%d\n", config.c_maxsessions);
194 cprintf("xxx\n"); /* placeholder -- field no longer in use */
195 cprintf("%d\n", config.c_userpurge);
196 cprintf("%d\n", config.c_roompurge);
197 cprintf("%s\n", config.c_logpages);
198 cprintf("%d\n", config.c_createax);
199 cprintf("%ld\n", config.c_maxmsglen);
200 cprintf("%d\n", config.c_min_workers);
201 cprintf("%d\n", config.c_max_workers);
202 cprintf("%d\n", config.c_pop3_port);
203 cprintf("%d\n", config.c_smtp_port);
204 cprintf("%d\n", config.c_rfc822_strict_from);
205 cprintf("%d\n", config.c_aide_zap);
206 cprintf("%d\n", config.c_imap_port);
207 cprintf("%ld\n", config.c_net_freq);
208 cprintf("%d\n", config.c_disable_newu);
209 cprintf("1\n"); /* niu */
210 cprintf("%d\n", config.c_purge_hour);
212 cprintf("%s\n", config.c_ldap_host);
213 cprintf("%d\n", config.c_ldap_port);
214 cprintf("%s\n", config.c_ldap_base_dn);
215 cprintf("%s\n", config.c_ldap_bind_dn);
216 cprintf("%s\n", config.c_ldap_bind_pw);
224 cprintf("%s\n", config.c_ip_addr);
225 cprintf("%d\n", config.c_msa_port);
226 cprintf("%d\n", config.c_imaps_port);
227 cprintf("%d\n", config.c_pop3s_port);
228 cprintf("%d\n", config.c_smtps_port);
229 cprintf("%d\n", config.c_enable_fulltext);
230 cprintf("%d\n", config.c_auto_cull);
231 cprintf("%d\n", config.c_instant_expunge);
232 cprintf("%d\n", config.c_allow_spoofing);
236 else if (!strcasecmp(cmd, "SET")) {
238 cprintf("%d Send configuration...\n", SEND_LISTING);
240 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
243 safestrncpy(config.c_nodename, buf,
244 sizeof config.c_nodename);
247 safestrncpy(config.c_fqdn, buf,
248 sizeof config.c_fqdn);
251 safestrncpy(config.c_humannode, buf,
252 sizeof config.c_humannode);
255 safestrncpy(config.c_phonenum, buf,
256 sizeof config.c_phonenum);
259 config.c_creataide = atoi(buf);
262 config.c_sleeping = atoi(buf);
265 config.c_initax = atoi(buf);
266 if (config.c_initax < 1)
268 if (config.c_initax > 6)
272 config.c_regiscall = atoi(buf);
273 if (config.c_regiscall != 0)
274 config.c_regiscall = 1;
277 config.c_twitdetect = atoi(buf);
278 if (config.c_twitdetect != 0)
279 config.c_twitdetect = 1;
282 safestrncpy(config.c_twitroom, buf,
283 sizeof config.c_twitroom);
286 safestrncpy(config.c_moreprompt, buf,
287 sizeof config.c_moreprompt);
290 config.c_restrict = atoi(buf);
291 if (config.c_restrict != 0)
292 config.c_restrict = 1;
295 safestrncpy(config.c_site_location, buf,
296 sizeof config.c_site_location);
299 safestrncpy(config.c_sysadm, buf,
300 sizeof config.c_sysadm);
303 config.c_maxsessions = atoi(buf);
304 if (config.c_maxsessions < 0)
305 config.c_maxsessions = 0;
308 /* placeholder -- field no longer in use */
311 config.c_userpurge = atoi(buf);
314 config.c_roompurge = atoi(buf);
317 safestrncpy(config.c_logpages, buf,
318 sizeof config.c_logpages);
321 config.c_createax = atoi(buf);
322 if (config.c_createax < 1)
323 config.c_createax = 1;
324 if (config.c_createax > 6)
325 config.c_createax = 6;
328 if (atoi(buf) >= 8192)
329 config.c_maxmsglen = atoi(buf);
333 config.c_min_workers = atoi(buf);
335 if (atoi(buf) >= config.c_min_workers)
336 config.c_max_workers = atoi(buf);
338 config.c_pop3_port = atoi(buf);
341 config.c_smtp_port = atoi(buf);
344 config.c_rfc822_strict_from = atoi(buf);
347 config.c_aide_zap = atoi(buf);
348 if (config.c_aide_zap != 0)
349 config.c_aide_zap = 1;
352 config.c_imap_port = atoi(buf);
355 config.c_net_freq = atol(buf);
358 config.c_disable_newu = atoi(buf);
359 if (config.c_disable_newu != 0)
360 config.c_disable_newu = 1;
366 if ((config.c_purge_hour >= 0)
367 && (config.c_purge_hour <= 23)) {
368 config.c_purge_hour = atoi(buf);
373 safestrncpy(config.c_ldap_host, buf,
374 sizeof config.c_ldap_host);
377 config.c_ldap_port = atoi(buf);
380 safestrncpy(config.c_ldap_base_dn, buf,
381 sizeof config.c_ldap_base_dn);
384 safestrncpy(config.c_ldap_bind_dn, buf,
385 sizeof config.c_ldap_bind_dn);
388 safestrncpy(config.c_ldap_bind_pw, buf,
389 sizeof config.c_ldap_bind_pw);
393 safestrncpy(config.c_ip_addr, buf,
394 sizeof config.c_ip_addr);
396 config.c_msa_port = atoi(buf);
399 config.c_imaps_port = atoi(buf);
402 config.c_pop3s_port = atoi(buf);
405 config.c_smtps_port = atoi(buf);
408 config.c_enable_fulltext = atoi(buf);
411 config.c_auto_cull = atoi(buf);
414 config.c_instant_expunge = atoi(buf);
417 config.c_allow_spoofing = atoi(buf);
423 snprintf(buf, sizeof buf,
424 "Global system configuration 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);