b81526cf1dc855078349afb8ed70a4803bb0388d
[citadel.git] / citadel / control.c
1 /*
2  * This module handles states which are global to the entire server.
3  *
4  * Copyright (c) 1987-2012 by the citadel.org team
5  *
6  *  This program is open source software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License version 3.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  */
14
15 #include "sysdep.h"
16 #include <stdlib.h>
17 #include <unistd.h>
18 #include <stdio.h>
19 #include <fcntl.h>
20 #include <signal.h>
21
22 #if TIME_WITH_SYS_TIME
23 # include <sys/time.h>
24 # include <time.h>
25 #else
26 # if HAVE_SYS_TIME_H
27 #  include <sys/time.h>
28 # else
29 #  include <time.h>
30 # endif
31 #endif
32
33 #include <ctype.h>
34 #include <string.h>
35 #include <errno.h>
36 #include <limits.h>
37 #include <sys/types.h>
38 #include <sys/file.h>
39 #include <sys/stat.h>
40 #include <libcitadel.h>
41 #include "citadel.h"
42 #include "server.h"
43 #include "control.h"
44 #include "sysdep_decls.h"
45 #include "support.h"
46 #include "config.h"
47 #include "msgbase.h"
48 #include "citserver.h"
49 #include "room_ops.h"
50 #include "user_ops.h"
51 #include "database.h"
52 #include "threads.h"
53
54 #ifndef HAVE_SNPRINTF
55 #include "snprintf.h"
56 #endif
57
58 #include "ctdl_module.h"
59
60 struct CitControl CitControl;
61 extern struct config config;
62 FILE *control_fp = NULL;
63 long control_highest_user = 0;
64
65
66 /*
67  * lock_control  -  acquire a lock on the control record file.
68  *                  This keeps multiple citservers from running concurrently.
69  */
70 void lock_control(void)
71 {
72 #if defined(LOCK_EX) && defined(LOCK_NB)
73         if (flock(fileno(control_fp), (LOCK_EX | LOCK_NB))) {
74                 syslog(LOG_EMERG, "citserver: unable to lock %s.\n", file_citadel_control);
75                 syslog(LOG_EMERG, "Is another citserver already running?\n");
76                 exit(CTDLEXIT_CONTROL);
77         }
78 #endif
79 }
80
81 /*
82  * callback to get highest room number when rebuilding control file
83  */
84 void control_find_highest(struct ctdlroom *qrbuf, void *data)
85 {
86         struct ctdlroom room;
87         struct cdbdata *cdbfr;
88         long *msglist;
89         int num_msgs=0;
90         int c;
91         int room_fixed = 0;
92         int message_fixed = 0;
93         
94         if (qrbuf->QRnumber > CitControl.MMnextroom)
95         {
96                 CitControl.MMnextroom = qrbuf->QRnumber;
97                 room_fixed = 1;
98         }
99                 
100         CtdlGetRoom (&room, qrbuf->QRname);
101         
102         /* Load the message list */
103         cdbfr = cdb_fetch(CDB_MSGLISTS, &room.QRnumber, sizeof(long));
104         if (cdbfr != NULL) {
105                 msglist = (long *) cdbfr->ptr;
106                 num_msgs = cdbfr->len / sizeof(long);
107         } else {
108                 return; /* No messages at all?  No further action. */
109         }
110
111         if (num_msgs>0)
112         {
113                 for (c=0; c<num_msgs; c++)
114                 {
115                         if (msglist[c] > CitControl.MMhighest)
116                         {
117                                 CitControl.MMhighest = msglist[c];
118                                 message_fixed = 1;
119                         }
120                 }
121         }
122         cdb_free(cdbfr);
123         if (room_fixed)
124                 syslog(LOG_INFO, "Control record checking....Fixed room counter\n");
125         if (message_fixed)
126                 syslog(LOG_INFO, "Control record checking....Fixed message count\n");
127         return;
128 }
129
130
131 /*
132  * Callback to get highest user number.
133  */
134  
135 void control_find_user (struct ctdluser *EachUser, void *out_data)
136 {
137         int user_fixed = 0;
138         
139         if (EachUser->usernum > CitControl.MMnextuser)
140         {
141                 CitControl.MMnextuser = EachUser->usernum;
142                 user_fixed = 1;
143         }
144         if(user_fixed)
145                 syslog(LOG_INFO, "Control record checking....Fixed user count\n");
146 }
147
148
149 /*
150  * get_control  -  read the control record into memory.
151  */
152 void get_control(void)
153 {
154         static int already_have_control = 0;
155         int rv = 0;
156
157         /*
158          * If we already have the control record in memory, there's no point
159          * in reading it from disk again.
160          */
161         if (already_have_control) return;
162
163         /* Zero it out.  If the control record on disk is missing or short,
164          * the system functions with all control record fields initialized
165          * to zero.
166          */
167         memset(&CitControl, 0, sizeof(struct CitControl));
168         if (control_fp == NULL) {
169                 control_fp = fopen(file_citadel_control, "rb+");
170                 if (control_fp != NULL) {
171                         lock_control();
172                         rv = fchown(fileno(control_fp), config.c_ctdluid, -1);
173                         if (rv == -1)
174                                 syslog(LOG_EMERG, "Failed to adjust ownership of: %s [%s]\n", 
175                                        file_citadel_control, strerror(errno));
176                         rv = fchmod(fileno(control_fp), S_IRUSR|S_IWUSR);
177                         if (rv == -1)
178                                 syslog(LOG_EMERG, "Failed to adjust accessrights of: %s [%s]\n", 
179                                        file_citadel_control, strerror(errno));
180                 }
181         }
182         if (control_fp == NULL) {
183                 control_fp = fopen(file_citadel_control, "wb+");
184                 if (control_fp != NULL) {
185                         lock_control();
186                         memset(&CitControl, 0, sizeof(struct CitControl));
187
188                         rv = fchown(fileno(control_fp), config.c_ctdluid, -1);
189                         if (rv == -1)
190                                 syslog(LOG_EMERG, "Failed to adjust ownership of: %s [%s]\n", 
191                                        file_citadel_control, strerror(errno));
192
193                         rv = fchmod(fileno(control_fp), S_IRUSR|S_IWUSR);
194                         if (rv == -1)
195                                 syslog(LOG_EMERG, "Failed to adjust accessrights of: %s [%s]\n", 
196                                        file_citadel_control, strerror(errno));
197                         rv = fwrite(&CitControl, sizeof(struct CitControl), 1, control_fp);
198                         if (rv == -1)
199                                 syslog(LOG_EMERG, "Failed to write: %s [%s]\n", 
200                                        file_citadel_control, strerror(errno));
201                         rewind(control_fp);
202                 }
203         }
204         if (control_fp == NULL) {
205                 syslog(LOG_ALERT, "ERROR opening %s: %s\n", file_citadel_control, strerror(errno));
206                 return;
207         }
208
209         rewind(control_fp);
210         rv = fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
211         if (rv == -1)
212                 syslog(LOG_EMERG, "Failed to read Controlfile: %s [%s]\n", 
213                        file_citadel_control, strerror(errno));
214         already_have_control = 1;
215         rv = chown(file_citadel_control, config.c_ctdluid, (-1));
216         if (rv == -1)
217                 syslog(LOG_EMERG, "Failed to adjust ownership of: %s [%s]\n", 
218                        file_citadel_control, strerror(errno));  
219 }
220
221 /*
222  * put_control  -  write the control record to disk.
223  */
224 void put_control(void)
225 {
226         int rv = 0;
227
228         if (control_fp != NULL) {
229                 rewind(control_fp);
230                 rv = fwrite(&CitControl, sizeof(struct CitControl), 1, control_fp);
231                 if (rv == -1)
232                         syslog(LOG_EMERG, "Failed to write: %s [%s]\n", 
233                                file_citadel_control, strerror(errno));
234                 fflush(control_fp);
235         }
236 }
237
238
239 /*
240  * check_control   -  check the control record has sensible values for message, user and room numbers
241  */
242 void check_control(void)
243 {
244         syslog(LOG_INFO, "Checking/re-building control record\n");
245         get_control();
246         // Find highest room number and message number.
247         CtdlForEachRoom(control_find_highest, NULL);
248         ForEachUser(control_find_user, NULL);
249         put_control();
250 }
251
252
253 /*
254  * release_control - close our fd on exit
255  */
256 void release_control(void)
257 {
258         if (control_fp != NULL) {
259                 fclose(control_fp);
260         }
261         control_fp = NULL;
262 }
263
264 /*
265  * get_new_message_number()  -  Obtain a new, unique ID to be used for a message.
266  */
267 long get_new_message_number(void)
268 {
269         long retval = 0L;
270         begin_critical_section(S_CONTROL);
271         get_control();
272         retval = ++CitControl.MMhighest;
273         put_control();
274         end_critical_section(S_CONTROL);
275         return(retval);
276 }
277
278
279 /*
280  * CtdlGetCurrentMessageNumber()  -  Obtain the current highest message number in the system
281  * This provides a quick way to initialise a variable that might be used to indicate
282  * messages that should not be processed. EG. a new Sieve script will use this
283  * to record determine that messages older than this should not be processed.
284  */
285 long CtdlGetCurrentMessageNumber(void)
286 {
287         long retval = 0L;
288         begin_critical_section(S_CONTROL);
289         get_control();
290         retval = CitControl.MMhighest;
291         end_critical_section(S_CONTROL);
292         return(retval);
293 }
294
295
296 /*
297  * get_new_user_number()  -  Obtain a new, unique ID to be used for a user.
298  */
299 long get_new_user_number(void)
300 {
301         long retval = 0L;
302         begin_critical_section(S_CONTROL);
303         get_control();
304         retval = ++CitControl.MMnextuser;
305         put_control();
306         end_critical_section(S_CONTROL);
307         return(retval);
308 }
309
310
311
312 /*
313  * get_new_room_number()  -  Obtain a new, unique ID to be used for a room.
314  */
315 long get_new_room_number(void)
316 {
317         long retval = 0L;
318         begin_critical_section(S_CONTROL);
319         get_control();
320         retval = ++CitControl.MMnextroom;
321         put_control();
322         end_critical_section(S_CONTROL);
323         return(retval);
324 }
325
326
327
328 /* 
329  * Get or set global configuration options
330  *
331  * IF YOU ADD OR CHANGE FIELDS HERE, YOU *MUST* DOCUMENT YOUR CHANGES AT:
332  * http://www.citadel.org/doku.php?id=documentation:applicationprotocol
333  *
334  */
335 void cmd_conf(char *argbuf)
336 {
337         char cmd[16];
338         char buf[256];
339         int a;
340         char *confptr;
341         char confname[128];
342
343         if (CtdlAccessCheck(ac_aide)) return;
344
345         extract_token(cmd, argbuf, 0, '|', sizeof cmd);
346         if (!strcasecmp(cmd, "GET")) {
347                 cprintf("%d Configuration...\n", LISTING_FOLLOWS);
348                 cprintf("%s\n", config.c_nodename);
349                 cprintf("%s\n", config.c_fqdn);
350                 cprintf("%s\n", config.c_humannode);
351                 cprintf("%s\n", config.c_phonenum);
352                 cprintf("%d\n", config.c_creataide);
353                 cprintf("%d\n", config.c_sleeping);
354                 cprintf("%d\n", config.c_initax);
355                 cprintf("%d\n", config.c_regiscall);
356                 cprintf("%d\n", config.c_twitdetect);
357                 cprintf("%s\n", config.c_twitroom);
358                 cprintf("%s\n", config.c_moreprompt);
359                 cprintf("%d\n", config.c_restrict);
360                 cprintf("%s\n", config.c_site_location);
361                 cprintf("%s\n", config.c_sysadm);
362                 cprintf("%d\n", config.c_maxsessions);
363                 cprintf("xxx\n"); /* placeholder -- field no longer in use */
364                 cprintf("%d\n", config.c_userpurge);
365                 cprintf("%d\n", config.c_roompurge);
366                 cprintf("%s\n", config.c_logpages);
367                 cprintf("%d\n", config.c_createax);
368                 cprintf("%ld\n", config.c_maxmsglen);
369                 cprintf("%d\n", config.c_min_workers);
370                 cprintf("%d\n", config.c_max_workers);
371                 cprintf("%d\n", config.c_pop3_port);
372                 cprintf("%d\n", config.c_smtp_port);
373                 cprintf("%d\n", config.c_rfc822_strict_from);
374                 cprintf("%d\n", config.c_aide_zap);
375                 cprintf("%d\n", config.c_imap_port);
376                 cprintf("%ld\n", config.c_net_freq);
377                 cprintf("%d\n", config.c_disable_newu);
378                 cprintf("1\n"); /* niu */
379                 cprintf("%d\n", config.c_purge_hour);
380 #ifdef HAVE_LDAP
381                 cprintf("%s\n", config.c_ldap_host);
382                 cprintf("%d\n", config.c_ldap_port);
383                 cprintf("%s\n", config.c_ldap_base_dn);
384                 cprintf("%s\n", config.c_ldap_bind_dn);
385                 cprintf("%s\n", config.c_ldap_bind_pw);
386 #else
387                 cprintf("\n");
388                 cprintf("0\n");
389                 cprintf("\n");
390                 cprintf("\n");
391                 cprintf("\n");
392 #endif
393                 cprintf("%s\n", config.c_ip_addr);
394                 cprintf("%d\n", config.c_msa_port);
395                 cprintf("%d\n", config.c_imaps_port);
396                 cprintf("%d\n", config.c_pop3s_port);
397                 cprintf("%d\n", config.c_smtps_port);
398                 cprintf("%d\n", config.c_enable_fulltext);
399                 cprintf("%d\n", config.c_auto_cull);
400                 cprintf("%d\n", config.c_instant_expunge);
401                 cprintf("%d\n", config.c_allow_spoofing);
402                 cprintf("%d\n", config.c_journal_email);
403                 cprintf("%d\n", config.c_journal_pubmsgs);
404                 cprintf("%s\n", config.c_journal_dest);
405                 cprintf("%s\n", config.c_default_cal_zone);
406                 cprintf("%d\n", config.c_pftcpdict_port);
407                 cprintf("%d\n", config.c_managesieve_port);
408                 cprintf("%d\n", config.c_auth_mode);
409                 cprintf("%s\n", config.c_funambol_host);
410                 cprintf("%d\n", config.c_funambol_port);
411                 cprintf("%s\n", config.c_funambol_source);
412                 cprintf("%s\n", config.c_funambol_auth);
413                 cprintf("%d\n", config.c_rbl_at_greeting);
414                 cprintf("%s\n", config.c_master_user);
415                 cprintf("%s\n", config.c_master_pass);
416                 cprintf("%s\n", config.c_pager_program);
417                 cprintf("%d\n", config.c_imap_keep_from);
418                 cprintf("%d\n", config.c_xmpp_c2s_port);
419                 cprintf("%d\n", config.c_xmpp_s2s_port);
420                 cprintf("%ld\n", config.c_pop3_fetch);
421                 cprintf("%ld\n", config.c_pop3_fastest);
422                 cprintf("%d\n", config.c_spam_flag_only);
423                 cprintf("%d\n", config.c_guest_logins);
424                 cprintf("%d\n", config.c_port_number);
425                 cprintf("%d\n", config.c_ctdluid);
426                 cprintf("000\n");
427         }
428
429         else if (!strcasecmp(cmd, "SET")) {
430                 unbuffer_output();
431                 cprintf("%d Send configuration...\n", SEND_LISTING);
432                 a = 0;
433                 while (client_getln(buf, sizeof buf) >= 0 && strcmp(buf, "000")) {
434                         switch (a) {
435                         case 0:
436                                 safestrncpy(config.c_nodename, buf,
437                                             sizeof config.c_nodename);
438                                 break;
439                         case 1:
440                                 safestrncpy(config.c_fqdn, buf,
441                                             sizeof config.c_fqdn);
442                                 break;
443                         case 2:
444                                 safestrncpy(config.c_humannode, buf,
445                                             sizeof config.c_humannode);
446                                 break;
447                         case 3:
448                                 safestrncpy(config.c_phonenum, buf,
449                                             sizeof config.c_phonenum);
450                                 break;
451                         case 4:
452                                 config.c_creataide = atoi(buf);
453                                 break;
454                         case 5:
455                                 config.c_sleeping = atoi(buf);
456                                 break;
457                         case 6:
458                                 config.c_initax = atoi(buf);
459                                 if (config.c_initax < 1)
460                                         config.c_initax = 1;
461                                 if (config.c_initax > 6)
462                                         config.c_initax = 6;
463                                 break;
464                         case 7:
465                                 config.c_regiscall = atoi(buf);
466                                 if (config.c_regiscall != 0)
467                                         config.c_regiscall = 1;
468                                 break;
469                         case 8:
470                                 config.c_twitdetect = atoi(buf);
471                                 if (config.c_twitdetect != 0)
472                                         config.c_twitdetect = 1;
473                                 break;
474                         case 9:
475                                 safestrncpy(config.c_twitroom, buf,
476                                             sizeof config.c_twitroom);
477                                 break;
478                         case 10:
479                                 safestrncpy(config.c_moreprompt, buf,
480                                             sizeof config.c_moreprompt);
481                                 break;
482                         case 11:
483                                 config.c_restrict = atoi(buf);
484                                 if (config.c_restrict != 0)
485                                         config.c_restrict = 1;
486                                 break;
487                         case 12:
488                                 safestrncpy(config.c_site_location, buf,
489                                             sizeof config.c_site_location);
490                                 break;
491                         case 13:
492                                 safestrncpy(config.c_sysadm, buf,
493                                             sizeof config.c_sysadm);
494                                 break;
495                         case 14:
496                                 config.c_maxsessions = atoi(buf);
497                                 if (config.c_maxsessions < 0)
498                                         config.c_maxsessions = 0;
499                                 break;
500                         case 15:
501                                 /* placeholder -- field no longer in use */
502                                 break;
503                         case 16:
504                                 config.c_userpurge = atoi(buf);
505                                 break;
506                         case 17:
507                                 config.c_roompurge = atoi(buf);
508                                 break;
509                         case 18:
510                                 safestrncpy(config.c_logpages, buf,
511                                             sizeof config.c_logpages);
512                                 break;
513                         case 19:
514                                 config.c_createax = atoi(buf);
515                                 if (config.c_createax < 1)
516                                         config.c_createax = 1;
517                                 if (config.c_createax > 6)
518                                         config.c_createax = 6;
519                                 break;
520                         case 20:
521                                 if (atoi(buf) >= 8192)
522                                         config.c_maxmsglen = atoi(buf);
523                                 break;
524                         case 21:
525                                 if (atoi(buf) >= 2)
526                                         config.c_min_workers = atoi(buf);
527                         case 22:
528                                 if (atoi(buf) >= config.c_min_workers)
529                                         config.c_max_workers = atoi(buf);
530                         case 23:
531                                 config.c_pop3_port = atoi(buf);
532                                 break;
533                         case 24:
534                                 config.c_smtp_port = atoi(buf);
535                                 break;
536                         case 25:
537                                 config.c_rfc822_strict_from = atoi(buf);
538                                 break;
539                         case 26:
540                                 config.c_aide_zap = atoi(buf);
541                                 if (config.c_aide_zap != 0)
542                                         config.c_aide_zap = 1;
543                                 break;
544                         case 27:
545                                 config.c_imap_port = atoi(buf);
546                                 break;
547                         case 28:
548                                 config.c_net_freq = atol(buf);
549                                 break;
550                         case 29:
551                                 config.c_disable_newu = atoi(buf);
552                                 if (config.c_disable_newu != 0)
553                                         config.c_disable_newu = 1;
554                                 break;
555                         case 30:
556                                 /* niu */
557                                 break;
558                         case 31:
559                                 if ((config.c_purge_hour >= 0)
560                                    && (config.c_purge_hour <= 23)) {
561                                         config.c_purge_hour = atoi(buf);
562                                 }
563                                 break;
564 #ifdef HAVE_LDAP
565                         case 32:
566                                 safestrncpy(config.c_ldap_host, buf,
567                                             sizeof config.c_ldap_host);
568                                 break;
569                         case 33:
570                                 config.c_ldap_port = atoi(buf);
571                                 break;
572                         case 34:
573                                 safestrncpy(config.c_ldap_base_dn, buf,
574                                             sizeof config.c_ldap_base_dn);
575                                 break;
576                         case 35:
577                                 safestrncpy(config.c_ldap_bind_dn, buf,
578                                             sizeof config.c_ldap_bind_dn);
579                                 break;
580                         case 36:
581                                 safestrncpy(config.c_ldap_bind_pw, buf,
582                                             sizeof config.c_ldap_bind_pw);
583                                 break;
584 #endif
585                         case 37:
586                                 safestrncpy(config.c_ip_addr, buf,
587                                                 sizeof config.c_ip_addr);
588                         case 38:
589                                 config.c_msa_port = atoi(buf);
590                                 break;
591                         case 39:
592                                 config.c_imaps_port = atoi(buf);
593                                 break;
594                         case 40:
595                                 config.c_pop3s_port = atoi(buf);
596                                 break;
597                         case 41:
598                                 config.c_smtps_port = atoi(buf);
599                                 break;
600                         case 42:
601                                 config.c_enable_fulltext = atoi(buf);
602                                 break;
603                         case 43:
604                                 config.c_auto_cull = atoi(buf);
605                                 break;
606                         case 44:
607                                 config.c_instant_expunge = atoi(buf);
608                                 break;
609                         case 45:
610                                 config.c_allow_spoofing = atoi(buf);
611                                 break;
612                         case 46:
613                                 config.c_journal_email = atoi(buf);
614                                 break;
615                         case 47:
616                                 config.c_journal_pubmsgs = atoi(buf);
617                                 break;
618                         case 48:
619                                 safestrncpy(config.c_journal_dest, buf,
620                                                 sizeof config.c_journal_dest);
621                         case 49:
622                                 safestrncpy(config.c_default_cal_zone, buf,
623                                                 sizeof config.c_default_cal_zone);
624                                 break;
625                         case 50:
626                                 config.c_pftcpdict_port = atoi(buf);
627                                 break;
628                         case 51:
629                                 config.c_managesieve_port = atoi(buf);
630                                 break;
631                         case 52:
632                                 config.c_auth_mode = atoi(buf);
633                         case 53:
634                                 safestrncpy(config.c_funambol_host, buf,
635                                         sizeof config.c_funambol_host);
636                                 break;
637                         case 54:
638                                 config.c_funambol_port = atoi(buf);
639                                 break;
640                         case 55:
641                                 safestrncpy(config.c_funambol_source,
642                                         buf, 
643                                         sizeof config.c_funambol_source);
644                                 break;
645                         case 56:
646                                 safestrncpy(config.c_funambol_auth,
647                                         buf,
648                                         sizeof config.c_funambol_auth);
649                                 break;
650                         case 57:
651                                 config.c_rbl_at_greeting = atoi(buf);
652                                 break;
653                         case 58:
654                                 safestrncpy(config.c_master_user, buf, sizeof config.c_master_user);
655                                 break;
656                         case 59:
657                                 safestrncpy(config.c_master_pass, buf, sizeof config.c_master_pass);
658                                 break;
659                         case 60:
660                                 safestrncpy(config.c_pager_program,
661                                         buf,
662                                         sizeof config.c_pager_program);
663                                 break;
664                         case 61:
665                                 config.c_imap_keep_from = atoi(buf);
666                                 break;
667                         case 62:
668                                 config.c_xmpp_c2s_port = atoi(buf);
669                                 break;
670                         case 63:
671                                 config.c_xmpp_s2s_port = atoi(buf);
672                                 break;
673                         case 64:
674                                 config.c_pop3_fetch = atol(buf);
675                                 break;
676                         case 65:
677                                 config.c_pop3_fastest = atol(buf);
678                                 break;
679                         case 66:
680                                 config.c_spam_flag_only = atoi(buf);
681                                 break;
682                         case 67:
683                                 config.c_guest_logins = atoi(buf);
684                                 break;
685                         case 68:
686                                 config.c_port_number = atoi(buf);
687                                 break;
688                         case 69:
689                                 config.c_ctdluid = atoi(buf);
690                                 break;
691                         }
692                         ++a;
693                 }
694                 put_config();
695                 snprintf(buf, sizeof buf,
696                         "The global system configuration has been edited by %s.\n",
697                          (CC->logged_in ? CC->curr_user : "an administrator")
698                 );
699                 CtdlAideMessage(buf,"Citadel Configuration Manager Message");
700
701                 if (!IsEmptyStr(config.c_logpages))
702                         CtdlCreateRoom(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
703
704                 /* If full text indexing has been disabled, invalidate the
705                  * index so it doesn't try to use it later.
706                  */
707                 if (config.c_enable_fulltext == 0) {
708                         CitControl.fulltext_wordbreaker = 0;
709                         put_control();
710                 }
711         }
712
713         else if (!strcasecmp(cmd, "GETSYS")) {
714                 extract_token(confname, argbuf, 1, '|', sizeof confname);
715                 confptr = CtdlGetSysConfig(confname);
716                 if (confptr != NULL) {
717                         long len; 
718
719                         len = strlen(confptr);
720                         cprintf("%d %s\n", LISTING_FOLLOWS, confname);
721                         client_write(confptr, len);
722                         if ((len > 0) && (confptr[len - 1] != 10))
723                                 client_write("\n", 1);
724                         cprintf("000\n");
725                         free(confptr);
726                 } else {
727                         cprintf("%d No such configuration.\n",
728                                 ERROR + ILLEGAL_VALUE);
729                 }
730         }
731
732         else if (!strcasecmp(cmd, "PUTSYS")) {
733                 extract_token(confname, argbuf, 1, '|', sizeof confname);
734                 unbuffer_output();
735                 cprintf("%d %s\n", SEND_LISTING, confname);
736                 confptr = CtdlReadMessageBody(HKEY("000"), config.c_maxmsglen, NULL, 0, 0);
737                 CtdlPutSysConfig(confname, confptr);
738                 free(confptr);
739         }
740
741         else {
742                 cprintf("%d Illegal option(s) specified.\n",
743                         ERROR + ILLEGAL_VALUE);
744         }
745 }
746
747
748 /*****************************************************************************/
749 /*                      MODULE INITIALIZATION STUFF                          */
750 /*****************************************************************************/
751
752
753 CTDL_MODULE_INIT(control)
754 {
755         if (!threading) {
756                 CtdlRegisterProtoHook(cmd_conf, "CONF", "get/set system configuration");
757         }
758         /* return our id for the Log */
759         return "control";
760 }