4 * This module handles states which are global to the entire server.
25 #include "sysdep_decls.h"
32 struct CitControl CitControl;
34 FILE *control_fp = NULL;
37 * get_control - read the control record into memory.
39 void get_control(void) {
41 /* Zero it out. If the control record on disk is missing or short,
42 * the system functions with all control record fields initialized
45 memset(&CitControl, 0, sizeof(struct CitControl));
46 if (control_fp == NULL)
47 control_fp = fopen("citadel.control", "rb+");
48 if (control_fp == NULL) {
49 control_fp = fopen("citadel.control", "wb+");
50 if (control_fp != NULL) {
51 memset(&CitControl, 0, sizeof(struct CitControl));
52 fwrite(&CitControl, sizeof(struct CitControl),
57 if (control_fp == NULL) {
58 lprintf(1, "ERROR opening citadel.control: %s\n",
64 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
68 * put_control - write the control record to disk.
70 void put_control(void) {
72 if (control_fp != NULL) {
74 fwrite(&CitControl, sizeof(struct CitControl), 1, control_fp);
81 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
83 long get_new_message_number(void) {
84 begin_critical_section(S_CONTROL);
86 ++CitControl.MMhighest;
88 end_critical_section(S_CONTROL);
89 return(CitControl.MMhighest);
94 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
96 long get_new_user_number(void) {
97 begin_critical_section(S_CONTROL);
99 ++CitControl.MMnextuser;
101 end_critical_section(S_CONTROL);
102 return(CitControl.MMnextuser);
108 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
110 long get_new_room_number(void) {
111 begin_critical_section(S_CONTROL);
113 ++CitControl.MMnextroom;
115 end_critical_section(S_CONTROL);
116 return(CitControl.MMnextroom);
122 * Get or set global configuration options
124 void cmd_conf(char *argbuf) {
129 if (!(CC->logged_in)) {
130 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
134 if (CC->usersupp.axlevel < 6) {
135 cprintf("%d Higher access required.\n",
136 ERROR+HIGHER_ACCESS_REQUIRED);
140 extract(cmd, argbuf, 0);
141 if (!strcasecmp(cmd, "GET")) {
142 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
143 cprintf("%s\n", config.c_nodename);
144 cprintf("%s\n", config.c_fqdn);
145 cprintf("%s\n", config.c_humannode);
146 cprintf("%s\n", config.c_phonenum);
147 cprintf("%d\n", config.c_creataide);
148 cprintf("%d\n", config.c_sleeping);
149 cprintf("%d\n", config.c_initax);
150 cprintf("%d\n", config.c_regiscall);
151 cprintf("%d\n", config.c_twitdetect);
152 cprintf("%s\n", config.c_twitroom);
153 cprintf("%s\n", config.c_moreprompt);
154 cprintf("%d\n", config.c_restrict);
155 cprintf("%s\n", config.c_bbs_city);
156 cprintf("%s\n", config.c_sysadm);
157 cprintf("%d\n", config.c_maxsessions);
158 cprintf("%s\n", config.c_net_password);
159 cprintf("%d\n", config.c_userpurge);
160 cprintf("%d\n", config.c_roompurge);
161 cprintf("%s\n", config.c_logpages);
162 cprintf("%d\n", config.c_createax);
163 cprintf("%d\n", config.c_maxmsglen);
164 cprintf("%d\n", config.c_min_workers);
165 cprintf("%d\n", config.c_max_workers);
169 else if (!strcasecmp(cmd, "SET")) {
170 cprintf("%d Send configuration...\n", SEND_LISTING);
172 while (client_gets(buf), strcmp(buf, "000")) {
174 case 0: safestrncpy(config.c_nodename, buf,
175 sizeof config.c_nodename);
177 case 1: safestrncpy(config.c_fqdn, buf,
178 sizeof config.c_fqdn);
180 case 2: safestrncpy(config.c_humannode, buf,
181 sizeof config.c_humannode);
183 case 3: safestrncpy(config.c_phonenum, buf,
184 sizeof config.c_phonenum);
186 case 4: config.c_creataide = atoi(buf);
188 case 5: config.c_sleeping = atoi(buf);
190 case 6: config.c_initax = atoi(buf);
191 if (config.c_initax < 1) config.c_initax = 1;
192 if (config.c_initax > 6) config.c_initax = 6;
194 case 7: config.c_regiscall = atoi(buf);
195 if (config.c_regiscall != 0)
196 config.c_regiscall = 1;
198 case 8: config.c_twitdetect = atoi(buf);
199 if (config.c_twitdetect != 0)
200 config.c_twitdetect = 1;
202 case 9: safestrncpy(config.c_twitroom, buf,
203 sizeof config.c_twitroom);
205 case 10: safestrncpy(config.c_moreprompt, buf,
206 sizeof config.c_moreprompt);
208 case 11: config.c_restrict = atoi(buf);
209 if (config.c_restrict != 0)
210 config.c_restrict = 1;
212 case 12: safestrncpy(config.c_bbs_city, buf,
213 sizeof config.c_bbs_city);
215 case 13: safestrncpy(config.c_sysadm, buf,
216 sizeof config.c_sysadm);
218 case 14: config.c_maxsessions = atoi(buf);
219 if (config.c_maxsessions < 1)
220 config.c_maxsessions = 1;
222 case 15: safestrncpy(config.c_net_password, buf,
223 sizeof config.c_net_password);
225 case 16: config.c_userpurge = atoi(buf);
227 case 17: config.c_roompurge = atoi(buf);
229 case 18: safestrncpy(config.c_logpages, buf,
230 sizeof config.c_logpages);
232 case 19: config.c_createax = atoi(buf);
233 if (config.c_createax < 1)
234 config.c_createax = 1;
235 if (config.c_createax > 6)
236 config.c_createax = 6;
238 case 20: if (atoi(buf) >= 8192)
239 config.c_maxmsglen = atoi(buf);
241 case 21: if (atoi(buf) >= 2)
242 config.c_min_workers = atoi(buf);
243 case 22: if (atoi(buf) >= config.c_min_workers)
244 config.c_max_workers = atoi(buf);
249 snprintf(buf,sizeof buf,
250 "Global system configuration edited by %s\n",
254 if (strlen(config.c_logpages) > 0)
255 create_room(config.c_logpages, 4, "", 0);
259 cprintf("%d The only valid options are GET and SET.\n",
260 ERROR+ILLEGAL_VALUE);