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"
48 struct CitControl CitControl;
50 FILE *control_fp = NULL;
53 * get_control - read the control record into memory.
55 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) {
63 control_fp = fopen("citadel.control", "rb+");
64 if (control_fp != NULL) {
65 fchown(fileno(control_fp), config.c_bbsuid, -1);
68 if (control_fp == NULL) {
69 control_fp = fopen("citadel.control", "wb+");
70 if (control_fp != NULL) {
71 fchown(fileno(control_fp), config.c_bbsuid, -1);
72 memset(&CitControl, 0, sizeof(struct CitControl));
73 fwrite(&CitControl, sizeof(struct CitControl),
78 if (control_fp == NULL) {
79 lprintf(1, "ERROR opening citadel.control: %s\n",
85 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
89 * put_control - write the control record to disk.
91 void put_control(void) {
93 if (control_fp != NULL) {
95 fwrite(&CitControl, sizeof(struct CitControl), 1, control_fp);
102 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
104 long get_new_message_number(void) {
105 begin_critical_section(S_CONTROL);
107 ++CitControl.MMhighest;
109 end_critical_section(S_CONTROL);
110 return(CitControl.MMhighest);
115 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
117 long get_new_user_number(void) {
118 begin_critical_section(S_CONTROL);
120 ++CitControl.MMnextuser;
122 end_critical_section(S_CONTROL);
123 return(CitControl.MMnextuser);
129 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
131 long get_new_room_number(void) {
132 begin_critical_section(S_CONTROL);
134 ++CitControl.MMnextroom;
136 end_critical_section(S_CONTROL);
137 return(CitControl.MMnextroom);
143 * Get or set global configuration options
145 void cmd_conf(char *argbuf) {
152 if (CtdlAccessCheck(ac_aide)) return;
154 extract(cmd, argbuf, 0);
155 if (!strcasecmp(cmd, "GET")) {
156 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
157 cprintf("%s\n", config.c_nodename);
158 cprintf("%s\n", config.c_fqdn);
159 cprintf("%s\n", config.c_humannode);
160 cprintf("%s\n", config.c_phonenum);
161 cprintf("%d\n", config.c_creataide);
162 cprintf("%d\n", config.c_sleeping);
163 cprintf("%d\n", config.c_initax);
164 cprintf("%d\n", config.c_regiscall);
165 cprintf("%d\n", config.c_twitdetect);
166 cprintf("%s\n", config.c_twitroom);
167 cprintf("%s\n", config.c_moreprompt);
168 cprintf("%d\n", config.c_restrict);
169 cprintf("%s\n", config.c_bbs_city);
170 cprintf("%s\n", config.c_sysadm);
171 cprintf("%d\n", config.c_maxsessions);
172 cprintf("%s\n", config.c_net_password);
173 cprintf("%d\n", config.c_userpurge);
174 cprintf("%d\n", config.c_roompurge);
175 cprintf("%s\n", config.c_logpages);
176 cprintf("%d\n", config.c_createax);
177 cprintf("%d\n", config.c_maxmsglen);
178 cprintf("%d\n", config.c_min_workers);
179 cprintf("%d\n", config.c_max_workers);
180 cprintf("%d\n", config.c_pop3_port);
181 cprintf("%d\n", config.c_smtp_port);
182 cprintf("%d\n", config.c_default_filter);
183 cprintf("%d\n", config.c_aide_zap);
184 cprintf("%d\n", config.c_imap_port);
188 else if (!strcasecmp(cmd, "SET")) {
189 cprintf("%d Send configuration...\n", SEND_LISTING);
191 while (client_gets(buf), strcmp(buf, "000")) {
193 case 0: safestrncpy(config.c_nodename, buf,
194 sizeof config.c_nodename);
196 case 1: safestrncpy(config.c_fqdn, buf,
197 sizeof config.c_fqdn);
199 case 2: safestrncpy(config.c_humannode, buf,
200 sizeof config.c_humannode);
202 case 3: safestrncpy(config.c_phonenum, buf,
203 sizeof config.c_phonenum);
205 case 4: config.c_creataide = atoi(buf);
207 case 5: config.c_sleeping = atoi(buf);
209 case 6: config.c_initax = atoi(buf);
210 if (config.c_initax < 1) config.c_initax = 1;
211 if (config.c_initax > 6) config.c_initax = 6;
213 case 7: config.c_regiscall = atoi(buf);
214 if (config.c_regiscall != 0)
215 config.c_regiscall = 1;
217 case 8: config.c_twitdetect = atoi(buf);
218 if (config.c_twitdetect != 0)
219 config.c_twitdetect = 1;
221 case 9: safestrncpy(config.c_twitroom, buf,
222 sizeof config.c_twitroom);
224 case 10: safestrncpy(config.c_moreprompt, buf,
225 sizeof config.c_moreprompt);
227 case 11: config.c_restrict = atoi(buf);
228 if (config.c_restrict != 0)
229 config.c_restrict = 1;
231 case 12: safestrncpy(config.c_bbs_city, buf,
232 sizeof config.c_bbs_city);
234 case 13: safestrncpy(config.c_sysadm, buf,
235 sizeof config.c_sysadm);
237 case 14: config.c_maxsessions = atoi(buf);
238 if (config.c_maxsessions < 1)
239 config.c_maxsessions = 1;
241 case 15: safestrncpy(config.c_net_password, buf,
242 sizeof config.c_net_password);
244 case 16: config.c_userpurge = atoi(buf);
246 case 17: config.c_roompurge = atoi(buf);
248 case 18: safestrncpy(config.c_logpages, buf,
249 sizeof config.c_logpages);
251 case 19: config.c_createax = atoi(buf);
252 if (config.c_createax < 1)
253 config.c_createax = 1;
254 if (config.c_createax > 6)
255 config.c_createax = 6;
257 case 20: if (atoi(buf) >= 8192)
258 config.c_maxmsglen = atoi(buf);
260 case 21: if (atoi(buf) >= 2)
261 config.c_min_workers = atoi(buf);
262 case 22: if (atoi(buf) >= config.c_min_workers)
263 config.c_max_workers = atoi(buf);
264 case 23: config.c_pop3_port = atoi(buf);
266 case 24: config.c_smtp_port = atoi(buf);
268 case 25: config.c_default_filter = atoi(buf);
270 case 26: config.c_aide_zap = atoi(buf);
271 if (config.c_aide_zap != 0)
272 config.c_aide_zap = 1;
274 case 27: config.c_imap_port = atoi(buf);
280 snprintf(buf,sizeof buf,
281 "Global system configuration edited by %s\n",
285 if (strlen(config.c_logpages) > 0)
286 create_room(config.c_logpages, 3, "", 0, 1);
289 else if (!strcasecmp(cmd, "GETSYS")) {
290 extract(confname, argbuf, 1);
291 confptr = CtdlGetSysConfig(confname);
292 if (confptr != NULL) {
293 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
294 client_write(confptr, strlen(confptr));
295 if (confptr[strlen(confptr)-1] != 10)
296 client_write("\n", 1);
301 cprintf("%d No such configuration.\n",
302 ERROR+ILLEGAL_VALUE);
306 else if (!strcasecmp(cmd, "PUTSYS")) {
307 extract(confname, argbuf, 1);
308 cprintf("%d %s\n", SEND_LISTING, confname);
309 confptr = CtdlReadMessageBody("000", config.c_maxmsglen, NULL);
310 CtdlPutSysConfig(confname, confptr);
315 cprintf("%d Illegal option(s) specified.\n",
316 ERROR+ILLEGAL_VALUE);