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);
176 cprintf("%d\n", config.c_imap_port);
180 else if (!strcasecmp(cmd, "SET")) {
181 cprintf("%d Send configuration...\n", SEND_LISTING);
183 while (client_gets(buf), strcmp(buf, "000")) {
185 case 0: safestrncpy(config.c_nodename, buf,
186 sizeof config.c_nodename);
188 case 1: safestrncpy(config.c_fqdn, buf,
189 sizeof config.c_fqdn);
191 case 2: safestrncpy(config.c_humannode, buf,
192 sizeof config.c_humannode);
194 case 3: safestrncpy(config.c_phonenum, buf,
195 sizeof config.c_phonenum);
197 case 4: config.c_creataide = atoi(buf);
199 case 5: config.c_sleeping = atoi(buf);
201 case 6: config.c_initax = atoi(buf);
202 if (config.c_initax < 1) config.c_initax = 1;
203 if (config.c_initax > 6) config.c_initax = 6;
205 case 7: config.c_regiscall = atoi(buf);
206 if (config.c_regiscall != 0)
207 config.c_regiscall = 1;
209 case 8: config.c_twitdetect = atoi(buf);
210 if (config.c_twitdetect != 0)
211 config.c_twitdetect = 1;
213 case 9: safestrncpy(config.c_twitroom, buf,
214 sizeof config.c_twitroom);
216 case 10: safestrncpy(config.c_moreprompt, buf,
217 sizeof config.c_moreprompt);
219 case 11: config.c_restrict = atoi(buf);
220 if (config.c_restrict != 0)
221 config.c_restrict = 1;
223 case 12: safestrncpy(config.c_bbs_city, buf,
224 sizeof config.c_bbs_city);
226 case 13: safestrncpy(config.c_sysadm, buf,
227 sizeof config.c_sysadm);
229 case 14: config.c_maxsessions = atoi(buf);
230 if (config.c_maxsessions < 1)
231 config.c_maxsessions = 1;
233 case 15: safestrncpy(config.c_net_password, buf,
234 sizeof config.c_net_password);
236 case 16: config.c_userpurge = atoi(buf);
238 case 17: config.c_roompurge = atoi(buf);
240 case 18: safestrncpy(config.c_logpages, buf,
241 sizeof config.c_logpages);
243 case 19: config.c_createax = atoi(buf);
244 if (config.c_createax < 1)
245 config.c_createax = 1;
246 if (config.c_createax > 6)
247 config.c_createax = 6;
249 case 20: if (atoi(buf) >= 8192)
250 config.c_maxmsglen = atoi(buf);
252 case 21: if (atoi(buf) >= 2)
253 config.c_min_workers = atoi(buf);
254 case 22: if (atoi(buf) >= config.c_min_workers)
255 config.c_max_workers = atoi(buf);
256 case 23: config.c_pop3_port = atoi(buf);
258 case 24: config.c_smtp_port = atoi(buf);
260 case 25: config.c_default_filter = atoi(buf);
262 case 26: config.c_aide_zap = atoi(buf);
263 if (config.c_aide_zap != 0)
264 config.c_aide_zap = 1;
266 case 27: config.c_imap_port = atoi(buf);
272 snprintf(buf,sizeof buf,
273 "Global system configuration edited by %s\n",
277 if (strlen(config.c_logpages) > 0)
278 create_room(config.c_logpages, 3, "", 0);
281 else if (!strcasecmp(cmd, "GETSYS")) {
282 extract(confname, argbuf, 1);
283 confptr = CtdlGetSysConfig(confname);
284 if (confptr != NULL) {
285 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
286 client_write(confptr, strlen(confptr));
287 if (confptr[strlen(confptr)-1] != 10)
288 client_write("\n", 1);
293 cprintf("%d No such configuration.\n",
294 ERROR+ILLEGAL_VALUE);
298 else if (!strcasecmp(cmd, "PUTSYS")) {
299 extract(confname, argbuf, 1);
300 cprintf("%d %s\n", SEND_LISTING, confname);
301 confptr = CtdlReadMessageBody("000", config.c_maxmsglen, NULL);
302 CtdlPutSysConfig(confname, confptr);
307 cprintf("%d Illegal option(s) specified.\n",
308 ERROR+ILLEGAL_VALUE);