4 * This module handles states which are global to the entire server.
15 #if TIME_WITH_SYS_TIME
16 # include <sys/time.h>
20 # include <sys/time.h>
30 #include <sys/types.h>
34 #include "serv_extensions.h"
35 #include "sysdep_decls.h"
39 #include "citserver.h"
47 struct CitControl CitControl;
48 extern struct config config;
49 FILE *control_fp = NULL;
52 * get_control - read the control record into memory.
54 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(file_citadel_control, "rb+");
64 if (control_fp != NULL) {
65 fchown(fileno(control_fp), config.c_ctdluid, -1);
68 if (control_fp == NULL) {
69 control_fp = fopen(file_citadel_control, "wb+");
70 if (control_fp != NULL) {
71 fchown(fileno(control_fp), config.c_ctdluid, -1);
72 memset(&CitControl, 0, sizeof(struct CitControl));
73 fwrite(&CitControl, sizeof(struct CitControl),
78 if (control_fp == NULL) {
79 lprintf(CTDL_ALERT, "ERROR opening %s: %s\n",
86 fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
90 * put_control - write the control record to disk.
92 void put_control(void)
95 if (control_fp != NULL) {
97 fwrite(&CitControl, sizeof(struct CitControl), 1,
105 * get_new_message_number() - Obtain a new, unique ID to be used for a message.
107 long get_new_message_number(void)
110 begin_critical_section(S_CONTROL);
112 retval = ++CitControl.MMhighest;
114 end_critical_section(S_CONTROL);
120 * get_new_user_number() - Obtain a new, unique ID to be used for a user.
122 long get_new_user_number(void)
125 begin_critical_section(S_CONTROL);
127 retval = ++CitControl.MMnextuser;
129 end_critical_section(S_CONTROL);
136 * get_new_room_number() - Obtain a new, unique ID to be used for a room.
138 long get_new_room_number(void)
141 begin_critical_section(S_CONTROL);
143 retval = ++CitControl.MMnextroom;
145 end_critical_section(S_CONTROL);
152 * Get or set global configuration options
154 void cmd_conf(char *argbuf)
162 if (CtdlAccessCheck(ac_aide)) return;
164 extract_token(cmd, argbuf, 0, '|', sizeof cmd);
165 if (!strcasecmp(cmd, "GET")) {
166 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
167 cprintf("%s\n", config.c_nodename);
168 cprintf("%s\n", config.c_fqdn);
169 cprintf("%s\n", config.c_humannode);
170 cprintf("%s\n", config.c_phonenum);
171 cprintf("%d\n", config.c_creataide);
172 cprintf("%d\n", config.c_sleeping);
173 cprintf("%d\n", config.c_initax);
174 cprintf("%d\n", config.c_regiscall);
175 cprintf("%d\n", config.c_twitdetect);
176 cprintf("%s\n", config.c_twitroom);
177 cprintf("%s\n", config.c_moreprompt);
178 cprintf("%d\n", config.c_restrict);
179 cprintf("%s\n", config.c_site_location);
180 cprintf("%s\n", config.c_sysadm);
181 cprintf("%d\n", config.c_maxsessions);
182 cprintf("xxx\n"); /* placeholder -- field no longer in use */
183 cprintf("%d\n", config.c_userpurge);
184 cprintf("%d\n", config.c_roompurge);
185 cprintf("%s\n", config.c_logpages);
186 cprintf("%d\n", config.c_createax);
187 cprintf("%ld\n", config.c_maxmsglen);
188 cprintf("%d\n", config.c_min_workers);
189 cprintf("%d\n", config.c_max_workers);
190 cprintf("%d\n", config.c_pop3_port);
191 cprintf("%d\n", config.c_smtp_port);
192 cprintf("%d\n", config.c_rfc822_strict_from);
193 cprintf("%d\n", config.c_aide_zap);
194 cprintf("%d\n", config.c_imap_port);
195 cprintf("%ld\n", config.c_net_freq);
196 cprintf("%d\n", config.c_disable_newu);
197 cprintf("1\n"); /* niu */
198 cprintf("%d\n", config.c_purge_hour);
200 cprintf("%s\n", config.c_ldap_host);
201 cprintf("%d\n", config.c_ldap_port);
202 cprintf("%s\n", config.c_ldap_base_dn);
203 cprintf("%s\n", config.c_ldap_bind_dn);
204 cprintf("%s\n", config.c_ldap_bind_pw);
212 cprintf("%s\n", config.c_ip_addr);
213 cprintf("%d\n", config.c_msa_port);
214 cprintf("%d\n", config.c_imaps_port);
215 cprintf("%d\n", config.c_pop3s_port);
216 cprintf("%d\n", config.c_smtps_port);
217 cprintf("%d\n", config.c_enable_fulltext);
218 cprintf("%d\n", config.c_auto_cull);
219 cprintf("%d\n", config.c_instant_expunge);
220 cprintf("%d\n", config.c_allow_spoofing);
221 cprintf("%d\n", config.c_journal_email);
222 cprintf("%d\n", config.c_journal_pubmsgs);
223 cprintf("%s\n", config.c_journal_dest);
224 cprintf("%s\n", config.c_default_cal_zone);
225 cprintf("%d\n", config.c_pftcpdict_port);
229 else if (!strcasecmp(cmd, "SET")) {
231 cprintf("%d Send configuration...\n", SEND_LISTING);
233 while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
236 safestrncpy(config.c_nodename, buf,
237 sizeof config.c_nodename);
240 safestrncpy(config.c_fqdn, buf,
241 sizeof config.c_fqdn);
244 safestrncpy(config.c_humannode, buf,
245 sizeof config.c_humannode);
248 safestrncpy(config.c_phonenum, buf,
249 sizeof config.c_phonenum);
252 config.c_creataide = atoi(buf);
255 config.c_sleeping = atoi(buf);
258 config.c_initax = atoi(buf);
259 if (config.c_initax < 1)
261 if (config.c_initax > 6)
265 config.c_regiscall = atoi(buf);
266 if (config.c_regiscall != 0)
267 config.c_regiscall = 1;
270 config.c_twitdetect = atoi(buf);
271 if (config.c_twitdetect != 0)
272 config.c_twitdetect = 1;
275 safestrncpy(config.c_twitroom, buf,
276 sizeof config.c_twitroom);
279 safestrncpy(config.c_moreprompt, buf,
280 sizeof config.c_moreprompt);
283 config.c_restrict = atoi(buf);
284 if (config.c_restrict != 0)
285 config.c_restrict = 1;
288 safestrncpy(config.c_site_location, buf,
289 sizeof config.c_site_location);
292 safestrncpy(config.c_sysadm, buf,
293 sizeof config.c_sysadm);
296 config.c_maxsessions = atoi(buf);
297 if (config.c_maxsessions < 0)
298 config.c_maxsessions = 0;
301 /* placeholder -- field no longer in use */
304 config.c_userpurge = atoi(buf);
307 config.c_roompurge = atoi(buf);
310 safestrncpy(config.c_logpages, buf,
311 sizeof config.c_logpages);
314 config.c_createax = atoi(buf);
315 if (config.c_createax < 1)
316 config.c_createax = 1;
317 if (config.c_createax > 6)
318 config.c_createax = 6;
321 if (atoi(buf) >= 8192)
322 config.c_maxmsglen = atoi(buf);
326 config.c_min_workers = atoi(buf);
328 if (atoi(buf) >= config.c_min_workers)
329 config.c_max_workers = atoi(buf);
331 config.c_pop3_port = atoi(buf);
334 config.c_smtp_port = atoi(buf);
337 config.c_rfc822_strict_from = atoi(buf);
340 config.c_aide_zap = atoi(buf);
341 if (config.c_aide_zap != 0)
342 config.c_aide_zap = 1;
345 config.c_imap_port = atoi(buf);
348 config.c_net_freq = atol(buf);
351 config.c_disable_newu = atoi(buf);
352 if (config.c_disable_newu != 0)
353 config.c_disable_newu = 1;
359 if ((config.c_purge_hour >= 0)
360 && (config.c_purge_hour <= 23)) {
361 config.c_purge_hour = atoi(buf);
366 safestrncpy(config.c_ldap_host, buf,
367 sizeof config.c_ldap_host);
370 config.c_ldap_port = atoi(buf);
373 safestrncpy(config.c_ldap_base_dn, buf,
374 sizeof config.c_ldap_base_dn);
377 safestrncpy(config.c_ldap_bind_dn, buf,
378 sizeof config.c_ldap_bind_dn);
381 safestrncpy(config.c_ldap_bind_pw, buf,
382 sizeof config.c_ldap_bind_pw);
386 safestrncpy(config.c_ip_addr, buf,
387 sizeof config.c_ip_addr);
389 config.c_msa_port = atoi(buf);
392 config.c_imaps_port = atoi(buf);
395 config.c_pop3s_port = atoi(buf);
398 config.c_smtps_port = atoi(buf);
401 config.c_enable_fulltext = atoi(buf);
404 config.c_auto_cull = atoi(buf);
407 config.c_instant_expunge = atoi(buf);
410 config.c_allow_spoofing = atoi(buf);
413 config.c_journal_email = atoi(buf);
416 config.c_journal_pubmsgs = atoi(buf);
419 safestrncpy(config.c_journal_dest, buf,
420 sizeof config.c_journal_dest);
422 safestrncpy(config.c_default_cal_zone, buf,
423 sizeof config.c_default_cal_zone);
426 config.c_pftcpdict_port = atoi(buf);
432 snprintf(buf, sizeof buf,
433 "The global system configuration has been edited by %s.\n",
437 if (strlen(config.c_logpages) > 0)
438 create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
440 /* If full text indexing has been disabled, invalidate the
441 * index so it doesn't try to use it later.
443 if (config.c_enable_fulltext == 0) {
444 CitControl.fulltext_wordbreaker = 0;
449 else if (!strcasecmp(cmd, "GETSYS")) {
450 extract_token(confname, argbuf, 1, '|', sizeof confname);
451 confptr = CtdlGetSysConfig(confname);
452 if (confptr != NULL) {
453 cprintf("%d %s\n", LISTING_FOLLOWS, confname);
454 client_write(confptr, strlen(confptr));
455 if (confptr[strlen(confptr) - 1] != 10)
456 client_write("\n", 1);
460 cprintf("%d No such configuration.\n",
461 ERROR + ILLEGAL_VALUE);
465 else if (!strcasecmp(cmd, "PUTSYS")) {
466 extract_token(confname, argbuf, 1, '|', sizeof confname);
468 cprintf("%d %s\n", SEND_LISTING, confname);
469 confptr = CtdlReadMessageBody("000",
470 config.c_maxmsglen, NULL, 0);
471 CtdlPutSysConfig(confname, confptr);
476 cprintf("%d Illegal option(s) specified.\n",
477 ERROR + ILLEGAL_VALUE);