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