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);
234 else if (!strcasecmp(cmd, "SET")) {
236 cprintf("%d Send configuration...\n", SEND_LISTING);
238 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
241 safestrncpy(config.c_nodename, buf,
242 sizeof config.c_nodename);
245 safestrncpy(config.c_fqdn, buf,
246 sizeof config.c_fqdn);
249 safestrncpy(config.c_humannode, buf,
250 sizeof config.c_humannode);
253 safestrncpy(config.c_phonenum, buf,
254 sizeof config.c_phonenum);
257 config.c_creataide = atoi(buf);
260 config.c_sleeping = atoi(buf);
263 config.c_initax = atoi(buf);
264 if (config.c_initax < 1)
266 if (config.c_initax > 6)
270 config.c_regiscall = atoi(buf);
271 if (config.c_regiscall != 0)
272 config.c_regiscall = 1;
275 config.c_twitdetect = atoi(buf);
276 if (config.c_twitdetect != 0)
277 config.c_twitdetect = 1;
280 safestrncpy(config.c_twitroom, buf,
281 sizeof config.c_twitroom);
284 safestrncpy(config.c_moreprompt, buf,
285 sizeof config.c_moreprompt);
288 config.c_restrict = atoi(buf);
289 if (config.c_restrict != 0)
290 config.c_restrict = 1;
293 safestrncpy(config.c_site_location, buf,
294 sizeof config.c_site_location);
297 safestrncpy(config.c_sysadm, buf,
298 sizeof config.c_sysadm);
301 config.c_maxsessions = atoi(buf);
302 if (config.c_maxsessions < 0)
303 config.c_maxsessions = 0;
306 /* placeholder -- field no longer in use */
309 config.c_userpurge = atoi(buf);
312 config.c_roompurge = atoi(buf);
315 safestrncpy(config.c_logpages, buf,
316 sizeof config.c_logpages);
319 config.c_createax = atoi(buf);
320 if (config.c_createax < 1)
321 config.c_createax = 1;
322 if (config.c_createax > 6)
323 config.c_createax = 6;
326 if (atoi(buf) >= 8192)
327 config.c_maxmsglen = atoi(buf);
331 config.c_min_workers = atoi(buf);
333 if (atoi(buf) >= config.c_min_workers)
334 config.c_max_workers = atoi(buf);
336 config.c_pop3_port = atoi(buf);
339 config.c_smtp_port = atoi(buf);
342 config.c_rfc822_strict_from = atoi(buf);
345 config.c_aide_zap = atoi(buf);
346 if (config.c_aide_zap != 0)
347 config.c_aide_zap = 1;
350 config.c_imap_port = atoi(buf);
353 config.c_net_freq = atol(buf);
356 config.c_disable_newu = atoi(buf);
357 if (config.c_disable_newu != 0)
358 config.c_disable_newu = 1;
364 if ((config.c_purge_hour >= 0)
365 && (config.c_purge_hour <= 23)) {
366 config.c_purge_hour = atoi(buf);
371 safestrncpy(config.c_ldap_host, buf,
372 sizeof config.c_ldap_host);
375 config.c_ldap_port = atoi(buf);
378 safestrncpy(config.c_ldap_base_dn, buf,
379 sizeof config.c_ldap_base_dn);
382 safestrncpy(config.c_ldap_bind_dn, buf,
383 sizeof config.c_ldap_bind_dn);
386 safestrncpy(config.c_ldap_bind_pw, buf,
387 sizeof config.c_ldap_bind_pw);
391 safestrncpy(config.c_ip_addr, buf,
392 sizeof config.c_ip_addr);
394 config.c_msa_port = atoi(buf);
397 config.c_imaps_port = atoi(buf);
400 config.c_pop3s_port = atoi(buf);
403 config.c_smtps_port = atoi(buf);
406 config.c_enable_fulltext = atoi(buf);
409 config.c_auto_cull = atoi(buf);
415 snprintf(buf, sizeof buf,
416 "Global system configuration edited by %s\n",
420 if (strlen(config.c_logpages) > 0)
421 create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
423 /* If full text indexing has been disabled, invalidate the
424 * index so it doesn't try to use it later.
426 if (!config.c_enable_fulltext == 0) {
427 CitControl.fulltext_wordbreaker = 0;
432 else if (!strcasecmp(cmd, "GETSYS")) {
433 extract_token(confname, argbuf, 1, '|', sizeof confname);
434 confptr = CtdlGetSysConfig(confname);
435 if (confptr != NULL) {
436 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
437 client_write(confptr, strlen(confptr));
438 if (confptr[strlen(confptr) - 1] != 10)
439 client_write("\n", 1);
443 cprintf("%d No such configuration.\n",
444 ERROR + ILLEGAL_VALUE);
448 else if (!strcasecmp(cmd, "PUTSYS")) {
449 extract_token(confname, argbuf, 1, '|', sizeof confname);
451 cprintf("%d %s\n", SEND_LISTING, confname);
452 confptr = CtdlReadMessageBody("000",
453 config.c_maxmsglen, NULL, 0);
454 CtdlPutSysConfig(confname, confptr);
459 cprintf("%d Illegal option(s) specified.\n",
460 ERROR + ILLEGAL_VALUE);