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>
35 #include <sys/types.h>
39 #include "dynloader.h"
40 #include "sysdep_decls.h"
44 #include "citserver.h"
52 struct CitControl CitControl;
54 FILE *control_fp = NULL;
57 * get_control - read the control record into memory.
59 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_bbsuid, -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_bbsuid, -1);
76 memset(&CitControl, 0, sizeof(struct CitControl));
77 fwrite(&CitControl, sizeof(struct CitControl),
82 if (control_fp == NULL) {
83 lprintf(1, "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) {
97 if (control_fp != NULL) {
99 fwrite(&CitControl, sizeof(struct CitControl), 1, control_fp);
106 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
108 long get_new_message_number(void) {
109 begin_critical_section(S_CONTROL);
111 ++CitControl.MMhighest;
113 end_critical_section(S_CONTROL);
114 return(CitControl.MMhighest);
119 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
121 long get_new_user_number(void) {
122 begin_critical_section(S_CONTROL);
124 ++CitControl.MMnextuser;
126 end_critical_section(S_CONTROL);
127 return(CitControl.MMnextuser);
133 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
135 long get_new_room_number(void) {
136 begin_critical_section(S_CONTROL);
138 ++CitControl.MMnextroom;
140 end_critical_section(S_CONTROL);
141 return(CitControl.MMnextroom);
147 * Get or set global configuration options
149 void cmd_conf(char *argbuf) {
156 if (CtdlAccessCheck(ac_aide)) return;
158 extract(cmd, argbuf, 0);
159 if (!strcasecmp(cmd, "GET")) {
160 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
161 cprintf("%s\n", config.c_nodename);
162 cprintf("%s\n", config.c_fqdn);
163 cprintf("%s\n", config.c_humannode);
164 cprintf("%s\n", config.c_phonenum);
165 cprintf("%d\n", config.c_creataide);
166 cprintf("%d\n", config.c_sleeping);
167 cprintf("%d\n", config.c_initax);
168 cprintf("%d\n", config.c_regiscall);
169 cprintf("%d\n", config.c_twitdetect);
170 cprintf("%s\n", config.c_twitroom);
171 cprintf("%s\n", config.c_moreprompt);
172 cprintf("%d\n", config.c_restrict);
173 cprintf("%s\n", config.c_bbs_city);
174 cprintf("%s\n", config.c_sysadm);
175 cprintf("%d\n", config.c_maxsessions);
176 cprintf("%s\n", config.c_net_password);
177 cprintf("%d\n", config.c_userpurge);
178 cprintf("%d\n", config.c_roompurge);
179 cprintf("%s\n", config.c_logpages);
180 cprintf("%d\n", config.c_createax);
181 cprintf("%ld\n", config.c_maxmsglen);
182 cprintf("%d\n", config.c_min_workers);
183 cprintf("%d\n", config.c_max_workers);
184 cprintf("%d\n", config.c_pop3_port);
185 cprintf("%d\n", config.c_smtp_port);
186 cprintf("%d\n", config.c_default_filter);
187 cprintf("%d\n", config.c_aide_zap);
188 cprintf("%d\n", config.c_imap_port);
189 cprintf("%ld\n", config.c_net_freq);
190 cprintf("%d\n", config.c_disable_newu);
194 else if (!strcasecmp(cmd, "SET")) {
195 cprintf("%d Send configuration...\n", SEND_LISTING);
197 while (client_gets(buf), strcmp(buf, "000")) {
199 case 0: safestrncpy(config.c_nodename, buf,
200 sizeof config.c_nodename);
202 case 1: safestrncpy(config.c_fqdn, buf,
203 sizeof config.c_fqdn);
205 case 2: safestrncpy(config.c_humannode, buf,
206 sizeof config.c_humannode);
208 case 3: safestrncpy(config.c_phonenum, buf,
209 sizeof config.c_phonenum);
211 case 4: config.c_creataide = atoi(buf);
213 case 5: config.c_sleeping = atoi(buf);
215 case 6: config.c_initax = atoi(buf);
216 if (config.c_initax < 1) config.c_initax = 1;
217 if (config.c_initax > 6) config.c_initax = 6;
219 case 7: config.c_regiscall = atoi(buf);
220 if (config.c_regiscall != 0)
221 config.c_regiscall = 1;
223 case 8: config.c_twitdetect = atoi(buf);
224 if (config.c_twitdetect != 0)
225 config.c_twitdetect = 1;
227 case 9: safestrncpy(config.c_twitroom, buf,
228 sizeof config.c_twitroom);
230 case 10: safestrncpy(config.c_moreprompt, buf,
231 sizeof config.c_moreprompt);
233 case 11: config.c_restrict = atoi(buf);
234 if (config.c_restrict != 0)
235 config.c_restrict = 1;
237 case 12: safestrncpy(config.c_bbs_city, buf,
238 sizeof config.c_bbs_city);
240 case 13: safestrncpy(config.c_sysadm, buf,
241 sizeof config.c_sysadm);
243 case 14: config.c_maxsessions = atoi(buf);
244 if (config.c_maxsessions < 1)
245 config.c_maxsessions = 1;
247 case 15: safestrncpy(config.c_net_password, buf,
248 sizeof config.c_net_password);
250 case 16: config.c_userpurge = atoi(buf);
252 case 17: config.c_roompurge = atoi(buf);
254 case 18: safestrncpy(config.c_logpages, buf,
255 sizeof config.c_logpages);
257 case 19: config.c_createax = atoi(buf);
258 if (config.c_createax < 1)
259 config.c_createax = 1;
260 if (config.c_createax > 6)
261 config.c_createax = 6;
263 case 20: if (atoi(buf) >= 8192)
264 config.c_maxmsglen = atoi(buf);
266 case 21: if (atoi(buf) >= 2)
267 config.c_min_workers = atoi(buf);
268 case 22: if (atoi(buf) >= config.c_min_workers)
269 config.c_max_workers = atoi(buf);
270 case 23: config.c_pop3_port = atoi(buf);
272 case 24: config.c_smtp_port = atoi(buf);
274 case 25: config.c_default_filter = atoi(buf);
276 case 26: config.c_aide_zap = atoi(buf);
277 if (config.c_aide_zap != 0)
278 config.c_aide_zap = 1;
280 case 27: config.c_imap_port = atoi(buf);
282 case 28: config.c_net_freq = atol(buf);
284 case 29: config.c_disable_newu = atoi(buf);
285 if (config.c_disable_newu != 0)
286 config.c_disable_newu = 1;
292 snprintf(buf,sizeof buf,
293 "Global system configuration edited by %s\n",
297 if (strlen(config.c_logpages) > 0)
298 create_room(config.c_logpages, 3, "", 0, 1);
301 else if (!strcasecmp(cmd, "GETSYS")) {
302 extract(confname, argbuf, 1);
303 confptr = CtdlGetSysConfig(confname);
304 if (confptr != NULL) {
305 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
306 client_write(confptr, strlen(confptr));
307 if (confptr[strlen(confptr)-1] != 10)
308 client_write("\n", 1);
313 cprintf("%d No such configuration.\n",
314 ERROR+ILLEGAL_VALUE);
318 else if (!strcasecmp(cmd, "PUTSYS")) {
319 extract(confname, argbuf, 1);
320 cprintf("%d %s\n", SEND_LISTING, confname);
321 confptr = CtdlReadMessageBody("000", config.c_maxmsglen, NULL);
322 CtdlPutSysConfig(confname, confptr);
327 cprintf("%d Illegal option(s) specified.\n",
328 ERROR+ILLEGAL_VALUE);