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) {
67 control_fp = fopen("citadel.control", "rb+");
68 if (control_fp != NULL) {
69 fchown(fileno(control_fp), config.c_ctdluid, -1);
72 if (control_fp == NULL) {
73 control_fp = fopen("citadel.control", "wb+");
74 if (control_fp != NULL) {
75 fchown(fileno(control_fp), config.c_ctdluid, -1);
76 memset(&CitControl, 0, sizeof(struct CitControl));
77 fwrite(&CitControl, sizeof(struct CitControl),
82 if (control_fp == NULL) {
83 lprintf(CTDL_ALERT, "ERROR opening citadel.control: %s\n",
89 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
93 * put_control - write the control record to disk.
95 void put_control(void)
98 if (control_fp != NULL) {
100 fwrite(&CitControl, sizeof(struct CitControl), 1,
108 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
110 long get_new_message_number(void)
112 begin_critical_section(S_CONTROL);
114 ++CitControl.MMhighest;
116 end_critical_section(S_CONTROL);
117 return (CitControl.MMhighest);
122 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
124 long get_new_user_number(void)
126 begin_critical_section(S_CONTROL);
128 ++CitControl.MMnextuser;
130 end_critical_section(S_CONTROL);
131 return (CitControl.MMnextuser);
137 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
139 long get_new_room_number(void)
141 begin_critical_section(S_CONTROL);
143 ++CitControl.MMnextroom;
145 end_critical_section(S_CONTROL);
146 return (CitControl.MMnextroom);
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);
221 else if (!strcasecmp(cmd, "SET")) {
223 cprintf("%d Send configuration...\n", SEND_LISTING);
225 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
228 safestrncpy(config.c_nodename, buf,
229 sizeof config.c_nodename);
232 safestrncpy(config.c_fqdn, buf,
233 sizeof config.c_fqdn);
236 safestrncpy(config.c_humannode, buf,
237 sizeof config.c_humannode);
240 safestrncpy(config.c_phonenum, buf,
241 sizeof config.c_phonenum);
244 config.c_creataide = atoi(buf);
247 config.c_sleeping = atoi(buf);
250 config.c_initax = atoi(buf);
251 if (config.c_initax < 1)
253 if (config.c_initax > 6)
257 config.c_regiscall = atoi(buf);
258 if (config.c_regiscall != 0)
259 config.c_regiscall = 1;
262 config.c_twitdetect = atoi(buf);
263 if (config.c_twitdetect != 0)
264 config.c_twitdetect = 1;
267 safestrncpy(config.c_twitroom, buf,
268 sizeof config.c_twitroom);
271 safestrncpy(config.c_moreprompt, buf,
272 sizeof config.c_moreprompt);
275 config.c_restrict = atoi(buf);
276 if (config.c_restrict != 0)
277 config.c_restrict = 1;
280 safestrncpy(config.c_site_location, buf,
281 sizeof config.c_site_location);
284 safestrncpy(config.c_sysadm, buf,
285 sizeof config.c_sysadm);
288 config.c_maxsessions = atoi(buf);
289 if (config.c_maxsessions < 0)
290 config.c_maxsessions = 0;
293 /* placeholder -- field no longer in use */
296 config.c_userpurge = atoi(buf);
299 config.c_roompurge = atoi(buf);
302 safestrncpy(config.c_logpages, buf,
303 sizeof config.c_logpages);
306 config.c_createax = atoi(buf);
307 if (config.c_createax < 1)
308 config.c_createax = 1;
309 if (config.c_createax > 6)
310 config.c_createax = 6;
313 if (atoi(buf) >= 8192)
314 config.c_maxmsglen = atoi(buf);
318 config.c_min_workers = atoi(buf);
320 if (atoi(buf) >= config.c_min_workers)
321 config.c_max_workers = atoi(buf);
323 config.c_pop3_port = atoi(buf);
326 config.c_smtp_port = atoi(buf);
329 config.c_rfc822_strict_from = atoi(buf);
332 config.c_aide_zap = atoi(buf);
333 if (config.c_aide_zap != 0)
334 config.c_aide_zap = 1;
337 config.c_imap_port = atoi(buf);
340 config.c_net_freq = atol(buf);
343 config.c_disable_newu = atoi(buf);
344 if (config.c_disable_newu != 0)
345 config.c_disable_newu = 1;
351 if ((config.c_purge_hour >= 0)
352 && (config.c_purge_hour <= 23)) {
353 config.c_purge_hour = atoi(buf);
358 safestrncpy(config.c_ldap_host, buf,
359 sizeof config.c_ldap_host);
362 config.c_ldap_port = atoi(buf);
365 safestrncpy(config.c_ldap_base_dn, buf,
366 sizeof config.c_ldap_base_dn);
369 safestrncpy(config.c_ldap_bind_dn, buf,
370 sizeof config.c_ldap_bind_dn);
373 safestrncpy(config.c_ldap_bind_pw, buf,
374 sizeof config.c_ldap_bind_pw);
378 safestrncpy(config.c_ip_addr, buf,
379 sizeof config.c_ip_addr);
381 config.c_msa_port = atoi(buf);
384 config.c_imaps_port = atoi(buf);
387 config.c_pop3s_port = atoi(buf);
390 config.c_smtps_port = atoi(buf);
393 config.c_enable_fulltext = atoi(buf);
399 snprintf(buf, sizeof buf,
400 "Global system configuration edited by %s\n",
404 if (strlen(config.c_logpages) > 0)
405 create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
407 /* If full text indexing has been disabled, invalidate the
408 * index so it doesn't try to use it later.
410 if (!config.c_enable_fulltext == 0) {
411 CitControl.fulltext_wordbreaker = 0;
416 else if (!strcasecmp(cmd, "GETSYS")) {
417 extract_token(confname, argbuf, 1, '|', sizeof confname);
418 confptr = CtdlGetSysConfig(confname);
419 if (confptr != NULL) {
420 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
421 client_write(confptr, strlen(confptr));
422 if (confptr[strlen(confptr) - 1] != 10)
423 client_write("\n", 1);
427 cprintf("%d No such configuration.\n",
428 ERROR + ILLEGAL_VALUE);
432 else if (!strcasecmp(cmd, "PUTSYS")) {
433 extract_token(confname, argbuf, 1, '|', sizeof confname);
435 cprintf("%d %s\n", SEND_LISTING, confname);
436 confptr = CtdlReadMessageBody("000",
437 config.c_maxmsglen, NULL, 0);
438 CtdlPutSysConfig(confname, confptr);
443 cprintf("%d Illegal option(s) specified.\n",
444 ERROR + ILLEGAL_VALUE);