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