4 * This module handles states which are global to the entire server.
20 #include <sys/types.h>
24 #include "sysdep_decls.h"
31 struct CitControl CitControl;
33 FILE *control_fp = NULL;
36 * get_control - read the control record into memory.
38 void get_control(void) {
40 /* Zero it out. If the control record on disk is missing or short,
41 * the system functions with all control record fields initialized
44 memset(&CitControl, 0, sizeof(struct CitControl));
45 if (control_fp == NULL) {
46 control_fp = fopen("citadel.control", "rb+");
47 if (control_fp != NULL) {
48 fchown(fileno(control_fp), config.c_bbsuid, -1);
51 if (control_fp == NULL) {
52 control_fp = fopen("citadel.control", "wb+");
53 if (control_fp != NULL) {
54 fchown(fileno(control_fp), config.c_bbsuid, -1);
55 memset(&CitControl, 0, sizeof(struct CitControl));
56 fwrite(&CitControl, sizeof(struct CitControl),
61 if (control_fp == NULL) {
62 lprintf(1, "ERROR opening citadel.control: %s\n",
68 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
72 * put_control - write the control record to disk.
74 void put_control(void) {
76 if (control_fp != NULL) {
78 fwrite(&CitControl, sizeof(struct CitControl), 1, control_fp);
85 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
87 long get_new_message_number(void) {
88 begin_critical_section(S_CONTROL);
90 ++CitControl.MMhighest;
92 end_critical_section(S_CONTROL);
93 return(CitControl.MMhighest);
98 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
100 long get_new_user_number(void) {
101 begin_critical_section(S_CONTROL);
103 ++CitControl.MMnextuser;
105 end_critical_section(S_CONTROL);
106 return(CitControl.MMnextuser);
112 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
114 long get_new_room_number(void) {
115 begin_critical_section(S_CONTROL);
117 ++CitControl.MMnextroom;
119 end_critical_section(S_CONTROL);
120 return(CitControl.MMnextroom);
126 * Get or set global configuration options
128 void cmd_conf(char *argbuf) {
135 if (!(CC->logged_in)) {
136 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
140 if (CC->usersupp.axlevel < 6) {
141 cprintf("%d Higher access required.\n",
142 ERROR+HIGHER_ACCESS_REQUIRED);
146 extract(cmd, argbuf, 0);
147 if (!strcasecmp(cmd, "GET")) {
148 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
149 cprintf("%s\n", config.c_nodename);
150 cprintf("%s\n", config.c_fqdn);
151 cprintf("%s\n", config.c_humannode);
152 cprintf("%s\n", config.c_phonenum);
153 cprintf("%d\n", config.c_creataide);
154 cprintf("%d\n", config.c_sleeping);
155 cprintf("%d\n", config.c_initax);
156 cprintf("%d\n", config.c_regiscall);
157 cprintf("%d\n", config.c_twitdetect);
158 cprintf("%s\n", config.c_twitroom);
159 cprintf("%s\n", config.c_moreprompt);
160 cprintf("%d\n", config.c_restrict);
161 cprintf("%s\n", config.c_bbs_city);
162 cprintf("%s\n", config.c_sysadm);
163 cprintf("%d\n", config.c_maxsessions);
164 cprintf("%s\n", config.c_net_password);
165 cprintf("%d\n", config.c_userpurge);
166 cprintf("%d\n", config.c_roompurge);
167 cprintf("%s\n", config.c_logpages);
168 cprintf("%d\n", config.c_createax);
169 cprintf("%d\n", config.c_maxmsglen);
170 cprintf("%d\n", config.c_min_workers);
171 cprintf("%d\n", config.c_max_workers);
172 cprintf("%d\n", config.c_pop3_port);
173 cprintf("%d\n", config.c_smtp_port);
174 cprintf("%d\n", config.c_default_filter);
175 cprintf("%d\n", config.c_aide_zap);
179 else if (!strcasecmp(cmd, "SET")) {
180 cprintf("%d Send configuration...\n", SEND_LISTING);
182 while (client_gets(buf), strcmp(buf, "000")) {
184 case 0: safestrncpy(config.c_nodename, buf,
185 sizeof config.c_nodename);
187 case 1: safestrncpy(config.c_fqdn, buf,
188 sizeof config.c_fqdn);
190 case 2: safestrncpy(config.c_humannode, buf,
191 sizeof config.c_humannode);
193 case 3: safestrncpy(config.c_phonenum, buf,
194 sizeof config.c_phonenum);
196 case 4: config.c_creataide = atoi(buf);
198 case 5: config.c_sleeping = atoi(buf);
200 case 6: config.c_initax = atoi(buf);
201 if (config.c_initax < 1) config.c_initax = 1;
202 if (config.c_initax > 6) config.c_initax = 6;
204 case 7: config.c_regiscall = atoi(buf);
205 if (config.c_regiscall != 0)
206 config.c_regiscall = 1;
208 case 8: config.c_twitdetect = atoi(buf);
209 if (config.c_twitdetect != 0)
210 config.c_twitdetect = 1;
212 case 9: safestrncpy(config.c_twitroom, buf,
213 sizeof config.c_twitroom);
215 case 10: safestrncpy(config.c_moreprompt, buf,
216 sizeof config.c_moreprompt);
218 case 11: config.c_restrict = atoi(buf);
219 if (config.c_restrict != 0)
220 config.c_restrict = 1;
222 case 12: safestrncpy(config.c_bbs_city, buf,
223 sizeof config.c_bbs_city);
225 case 13: safestrncpy(config.c_sysadm, buf,
226 sizeof config.c_sysadm);
228 case 14: config.c_maxsessions = atoi(buf);
229 if (config.c_maxsessions < 1)
230 config.c_maxsessions = 1;
232 case 15: safestrncpy(config.c_net_password, buf,
233 sizeof config.c_net_password);
235 case 16: config.c_userpurge = atoi(buf);
237 case 17: config.c_roompurge = atoi(buf);
239 case 18: safestrncpy(config.c_logpages, buf,
240 sizeof config.c_logpages);
242 case 19: config.c_createax = atoi(buf);
243 if (config.c_createax < 1)
244 config.c_createax = 1;
245 if (config.c_createax > 6)
246 config.c_createax = 6;
248 case 20: if (atoi(buf) >= 8192)
249 config.c_maxmsglen = atoi(buf);
251 case 21: if (atoi(buf) >= 2)
252 config.c_min_workers = atoi(buf);
253 case 22: if (atoi(buf) >= config.c_min_workers)
254 config.c_max_workers = atoi(buf);
255 case 23: config.c_pop3_port = atoi(buf);
257 case 24: config.c_smtp_port = atoi(buf);
259 case 25: config.c_default_filter = atoi(buf);
261 case 26: config.c_aide_zap = atoi(buf);
262 if (config.c_aide_zap != 0)
263 config.c_aide_zap = 1;
269 snprintf(buf,sizeof buf,
270 "Global system configuration edited by %s\n",
274 if (strlen(config.c_logpages) > 0)
275 create_room(config.c_logpages, 3, "", 0);
278 else if (!strcasecmp(cmd, "GETSYS")) {
279 extract(confname, argbuf, 1);
280 confptr = CtdlGetSysConfig(confname);
281 if (confptr != NULL) {
282 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
283 client_write(confptr, strlen(confptr));
284 if (confptr[strlen(confptr)-1] != 10)
285 client_write("\n", 1);
290 cprintf("%d No such configuration.\n",
291 ERROR+ILLEGAL_VALUE);
295 else if (!strcasecmp(cmd, "PUTSYS")) {
296 extract(confname, argbuf, 1);
297 cprintf("%d %s\n", SEND_LISTING, confname);
298 confptr = CtdlReadMessageBody("000", config.c_maxmsglen, NULL);
299 CtdlPutSysConfig(confname, confptr);
304 cprintf("%d Illegal option(s) specified.\n",
305 ERROR+ILLEGAL_VALUE);