File: settings.c

package info (click to toggle)
dancer-services 1.8.0.6.3-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,600 kB
  • ctags: 1,623
  • sloc: ansic: 34,690; sh: 2,850; makefile: 269
file content (974 lines) | stat: -rw-r--r-- 26,671 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
/*
 * HybServ TS Services, Copyright (C) 1998-1999 Patrick Alken
 * This program comes with absolutely NO WARRANTY
 *
 * Should you choose to use and/or modify this source code, please
 * do so under the terms of the GNU General Public License under which
 * this program is distributed.
 *
 * $Id: settings.c,v 1.3 2001/11/12 09:50:55 asuffield Exp $
 */

#include "defs.h"

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

#include "alloc.h"
#include "config.h"
#include "hybdefs.h"
#include "log.h"
#include "match.h"
#include "misc.h"
#include "settings.h"
#include "timestr.h"
#include "sprintf_irc.h"

/*
 * These variables, or directives, are set by parsing
 * SETPATH (settings.conf)
 */

char      *HPath;
char      *ConfigFile;
char      *LogFile;
char      *PidFile;
char      *PipeFile;
char      *HelpPath;
char      *MotdFile;
char      *DccMotdFile;

char      *GlineFile;
char      *JupeFile;

char      *LogonNews;

char      *NickServDB;
char      *ChanServDB;
char      *MemoServDB;
char      *StatServDB;
char      *OperServDB;
char      *SeenServDB;

char      *n_OperServ;
char      *n_NickServ;
char      *n_ChanServ;
char      *n_MemoServ;
char      *n_StatServ;
char      *n_HelpServ;
char      *n_SeenServ;
char      *n_Global;
char      *id_OperServ;
char      *id_NickServ;
char      *id_ChanServ;
char      *id_MemoServ;
char      *id_StatServ;
char      *id_HelpServ;
char      *id_SeenServ;
char      *desc_SeenServ;
char      *id_Global;
char      *desc_OperServ;
char      *desc_NickServ;
char      *desc_ChanServ;
char      *desc_MemoServ;
char      *desc_StatServ;
char      *desc_HelpServ;
char      *desc_Global;
char      *ServiceUmodes;

int       RestrictedAccess;
int       AutoOpAdmins;
int       OpersHaveAccess;
int       SmartMasking;

long      NickNameExpire;
long      ChannelExpire;
long      MemoExpire;
long      StatExpire;
long      NSReleaseTimeout;

int       FloodProtection;
int       FloodCount;
long      FloodTime;
long      IgnoreTime;
int       IgnoreOffenses;

int       MaxClones;
char      *MaxClonesWarning;
int       AutoKillClones;

long      ConnectFrequency;
long      ConnectBurst;
long      AutoLinkFreq;
long      TelnetTimeout;
long      IdentTimeout;
long      BindAttemptFreq;
int       MaxBinds;
int       MaxConnections;
int       OpersOnlyDcc;
long      DatabaseSync;
long      BackupFreq;
int       ReloadDbsOnHup;
int       NonStarChars;
int       DefaultHubPort;
int       DefaultTcmPort;
int       LogLevel;
int       MaxLogs;
int       MaxModes;

int       MaxTrace;
int       MaxChannel;
int       MaxKill;
int       LimitTraceKills;
int       ServerNotices;
int       DoWallops;
int       BCFloodCount;
long      BCFloodTime;

int       NSSetKill;
int       NSSetAutoMask;
int       NSSetPrivate;
int       NSSetSecure;
int       NSSetUnSecure;
int       NSSetAllowMemos;
int       NSSetMemoSignon;
int       NSSetMemoNotify;
int       NSSetHide;
int       NSSetHideEmail;
int       NSSetHideUrl;
int       NSSetHideQuit;
int       LastSeenInfo;
int       NicknameWarn;
long      NickRegDelay;
int       MaxLinks;
int       AllowKillProtection;
int       AllowKillImmed;
int	      AllowGuardChannel;

int       MaxChansPerUser;
int       MaxAkicks;
long      InhabitTimeout;
int       AllowAccessIfSOp;
int       RestrictRegister;
int       GiveNotice;
long      MaxTSDelta;

int       MaxMemos;
long      MemoPurgeFreq;

int       LagDetect;
long      MaxPing;

int       GlobalNotices;
int       SeenMaxRecs;

int       UseMD5;

int       MaxServerCollides;
long      MinServerCollidesDelta;

static void ClearDirectives();
static int CheckDirectives();
static int dparse(char *, int, int);

struct Directive directives[] = {

  /* File Paths */
  { "HPath", D_NORUNTIME,           { { PARAM_STRING, &HPath } } },
  { "ConfigFile", D_NORUNTIME,      { { PARAM_STRING, &ConfigFile } } },
  { "LogFile", D_NORUNTIME,         { { PARAM_STRING, &LogFile } } },
  { "PidFile", D_NORUNTIME,         { { PARAM_STRING, &PidFile } } },
  { "PipeFile", D_NORUNTIME,         { { PARAM_STRING, &PipeFile } } },
  { "HelpPath", D_NORUNTIME,        { { PARAM_STRING, &HelpPath } } },
  { "MotdFile", D_NORUNTIME,        { { PARAM_STRING, &MotdFile } } },
  { "DccMotdFile", D_NORUNTIME,     { { PARAM_STRING, &DccMotdFile } } },

  { "GlineFile", D_OPTIONAL,       { { PARAM_STRING, &GlineFile } } },
  { "JupeFile", D_OPTIONAL,        { { PARAM_STRING, &JupeFile } } },

#ifdef GLOBALSERVICES

  { "LogonNews", D_OPTIONAL,       { { PARAM_STRING, &LogonNews } } },

#endif /* GLOBALSERVICES */

  /* Database Files */
  { "NickServDB", D_NORUNTIME,      { { PARAM_STRING, &NickServDB } } },
  { "ChanServDB", D_NORUNTIME,      { { PARAM_STRING, &ChanServDB } } },
  { "MemoServDB", D_NORUNTIME,      { { PARAM_STRING, &MemoServDB } } },
  { "StatServDB", D_NORUNTIME,      { { PARAM_STRING, &StatServDB } } },
  { "OperServDB", D_NORUNTIME,      { { PARAM_STRING, &OperServDB } } },
  { "SeenServDB", D_NORUNTIME,      { { PARAM_STRING, &SeenServDB } } },

  /* Pseudo-Client Nicknames/Idents/Descriptions and Options */
  { "OperServNick", D_NORUNTIME,    { { PARAM_STRING, &n_OperServ },
                                      { PARAM_STRING, &id_OperServ },
                                      { PARAM_STRING, &desc_OperServ } } },
  { "NickServNick", D_NORUNTIME,    { { PARAM_STRING, &n_NickServ },
                                      { PARAM_STRING, &id_NickServ },
                                      { PARAM_STRING, &desc_NickServ } } },
  { "ChanServNick", D_NORUNTIME,    { { PARAM_STRING, &n_ChanServ },
                                      { PARAM_STRING, &id_ChanServ },
                                      { PARAM_STRING, &desc_ChanServ } } },
  { "MemoServNick", D_NORUNTIME,    { { PARAM_STRING, &n_MemoServ },
                                      { PARAM_STRING, &id_MemoServ },
                                      { PARAM_STRING, &desc_MemoServ } } },
  { "StatServNick", D_NORUNTIME,    { { PARAM_STRING, &n_StatServ },
                                      { PARAM_STRING, &id_StatServ },
                                      { PARAM_STRING, &desc_StatServ } } },
  { "HelpServNick", D_NORUNTIME,    { { PARAM_STRING, &n_HelpServ },
                                      { PARAM_STRING, &id_HelpServ },
                                      { PARAM_STRING, &desc_HelpServ } } },
  { "GlobalNick", D_NORUNTIME,      { { PARAM_STRING, &n_Global },
                                      { PARAM_STRING, &id_Global },
                                      { PARAM_STRING, &desc_Global } } },
  { "SeenServNick", D_NORUNTIME,    { { PARAM_STRING, &n_SeenServ },
                                      { PARAM_STRING, &id_SeenServ },
                                      { PARAM_STRING, &desc_SeenServ } } },

  { "ServiceUmodes", D_NORUNTIME,   { { PARAM_STRING, &ServiceUmodes } } },

  /* Security Settings */
  { "RestrictedAccess", D_OPTIONAL, { { PARAM_SET, &RestrictedAccess } } },
  { "AutoOpAdmins", D_OPTIONAL,     { { PARAM_SET, &AutoOpAdmins } } },
  { "OpersHaveAccess", D_OPTIONAL,  { { PARAM_SET, &OpersHaveAccess } } },
  { "SmartMasking", D_OPTIONAL,     { { PARAM_SET, &SmartMasking } } },

  /* Expire Settings */
  { "NickNameExpire", D_OPTIONAL,   { { PARAM_TIME, &NickNameExpire } } },
  { "ChannelExpire", D_OPTIONAL,    { { PARAM_TIME, &ChannelExpire } } },
  { "MemoExpire", D_OPTIONAL,       { { PARAM_TIME, &MemoExpire } } },
  { "StatExpire", D_OPTIONAL,       { { PARAM_TIME, &StatExpire } } },
  { "NSReleaseTimeout", D_OPTIONAL, { { PARAM_TIME, &NSReleaseTimeout } } },

  /* Flood Protection */
  { "FloodProtection", D_OPTIONAL,  { { PARAM_SET, &FloodProtection } } },
  { "FloodCount", D_OPTIONAL,       { { PARAM_INT, &FloodCount } } },
  { "FloodTime", D_OPTIONAL,        { { PARAM_TIME, &FloodTime } } },
  { "IgnoreTime", D_OPTIONAL,       { { PARAM_TIME, &IgnoreTime } } },
  { "IgnoreOffenses", D_OPTIONAL,   { { PARAM_INT, &IgnoreOffenses } } },

  /* Clone Control */
  { "MaxClones", D_OPTIONAL,        { { PARAM_INT, &MaxClones } } },
  { "MaxClonesWarning", D_OPTIONAL, { { PARAM_STRING, &MaxClonesWarning } } },
  { "AutoKillClones", D_OPTIONAL,   { { PARAM_SET, &AutoKillClones } } },

  /* General Configuration */
  { "ConnectFrequency", D_REQUIRED, { { PARAM_TIME, &ConnectFrequency } } },
  { "ConnectBurst", D_REQUIRED,     { { PARAM_TIME, &ConnectBurst } } },
  { "AutoLinkFreq", D_REQUIRED,     { { PARAM_TIME, &AutoLinkFreq } } },
  { "TelnetTimeout", D_REQUIRED,    { { PARAM_TIME, &TelnetTimeout } } },
  { "IdentTimeout", D_REQUIRED,     { { PARAM_TIME, &IdentTimeout } } },
  { "BindAttemptFreq", D_OPTIONAL,  { { PARAM_TIME, &BindAttemptFreq } } },
  { "MaxBinds", D_OPTIONAL,         { { PARAM_INT, &MaxBinds } } },
  { "MaxConnections", D_OPTIONAL,   { { PARAM_INT, &MaxConnections } } },
  { "OpersOnlyDcc", D_OPTIONAL,     { { PARAM_SET, &OpersOnlyDcc } } },
  { "DatabaseSync", D_REQUIRED,     { { PARAM_TIME, &DatabaseSync } } },
  { "BackupFreq", D_OPTIONAL,       { { PARAM_TIME, &BackupFreq } } },
  { "ReloadDbsOnHup", D_OPTIONAL,   { { PARAM_SET, &ReloadDbsOnHup } } },
  { "NonStarChars", D_OPTIONAL,     { { PARAM_INT, &NonStarChars } } },
  { "DefaultHubPort", D_REQUIRED,   { { PARAM_PORT, &DefaultHubPort } } },
  { "DefaultTcmPort", D_REQUIRED,   { { PARAM_PORT, &DefaultTcmPort } } },
  { "LogLevel", D_REQUIRED,         { { PARAM_INT, &LogLevel } } },
  { "MaxLogs", D_OPTIONAL,          { { PARAM_INT, &MaxLogs } } },
  { "MaxModes", D_NORUNTIME,        { { PARAM_INT, &MaxModes } } },
  { "MaxTSDelta", D_OPTIONAL,       { { PARAM_TIME, &MaxTSDelta } } },

  /* SeenServ Configuration */
  { "SeenMaxRecs", D_REQUIRED,      { { PARAM_INT, &SeenMaxRecs } } },

  /* OperServ Configuration */
  { "MaxTrace", D_REQUIRED,         { { PARAM_INT, &MaxTrace } } },
  { "MaxChannel", D_REQUIRED,       { { PARAM_INT, &MaxChannel } } },
  { "MaxKill", D_REQUIRED,          { { PARAM_INT, &MaxKill } } },
  { "LimitTraceKills", D_OPTIONAL,  { { PARAM_SET, &LimitTraceKills } } },
  { "ServerNotices", D_OPTIONAL,    { { PARAM_SET, &ServerNotices } } },
  { "DoWallops", D_OPTIONAL,        { { PARAM_SET, &DoWallops } } },
  { "BCFloodCount", D_OPTIONAL,     { { PARAM_INT, &BCFloodCount } } },
  { "BCFloodTime", D_OPTIONAL,      { { PARAM_TIME, &BCFloodTime } } },

  /* NickServ Configuration */
  { "NSSetKill", D_OPTIONAL,        { { PARAM_SET, &NSSetKill } } },
  { "NSSetAutoMask", D_OPTIONAL,    { { PARAM_SET, &NSSetAutoMask } } },
  { "NSSetPrivate", D_OPTIONAL,     { { PARAM_SET, &NSSetPrivate } } },
  { "NSSetSecure", D_OPTIONAL,      { { PARAM_SET, &NSSetSecure } } },
  { "NSSetUnSecure", D_OPTIONAL,    { { PARAM_SET, &NSSetUnSecure } } },
  { "NSSetAllowMemos", D_OPTIONAL,  { { PARAM_SET, &NSSetAllowMemos } } },
  { "NSSetMemoSignon", D_OPTIONAL,  { { PARAM_SET, &NSSetMemoSignon } } },
  { "NSSetMemoNotify", D_OPTIONAL,  { { PARAM_SET, &NSSetMemoNotify } } },
  { "NSSetHide", D_OPTIONAL,        { { PARAM_SET, &NSSetHide } } },
  { "NSSetHideEmail", D_OPTIONAL,   { { PARAM_SET, &NSSetHideEmail } } },
  { "NSSetHideUrl", D_OPTIONAL,     { { PARAM_SET, &NSSetHideUrl } } },
  { "NSSetHideQuit", D_OPTIONAL,    { { PARAM_SET, &NSSetHideQuit } } },
  { "LastSeenInfo", D_OPTIONAL,     { { PARAM_SET, &LastSeenInfo } } },
  { "NicknameWarn", D_OPTIONAL,     { { PARAM_SET, &NicknameWarn } } },
  { "NickRegDelay", D_OPTIONAL,     { { PARAM_TIME, &NickRegDelay } } },
  { "MaxLinks", D_OPTIONAL,         { { PARAM_INT, &MaxLinks } } },
  { "AllowKillProtection", D_OPTIONAL, { { PARAM_SET, &AllowKillProtection } } },
  { "AllowKillImmed", D_OPTIONAL,   { { PARAM_SET, &AllowKillImmed } } },

  /* ChanServ Configuration */
  { "MaxChansPerUser", D_OPTIONAL,  { { PARAM_INT, &MaxChansPerUser } } },
  { "MaxAkicks", D_OPTIONAL,        { { PARAM_INT, &MaxAkicks } } },
  { "InhabitTimeout", D_OPTIONAL,   { { PARAM_TIME, &InhabitTimeout } } },
  { "AllowAccessIfSOp", D_OPTIONAL, { { PARAM_SET, &AllowAccessIfSOp } } },
  { "RestrictRegister", D_OPTIONAL, { { PARAM_SET, &RestrictRegister } } },
  { "GiveNotice", D_OPTIONAL,       { { PARAM_SET, &GiveNotice } } },
  { "AllowGuardChannel", D_OPTIONAL, { { PARAM_SET, &AllowGuardChannel } } },

  /* MemoServ Configuration */
  { "MaxMemos", D_OPTIONAL,         { { PARAM_INT, &MaxMemos } } },
  { "MemoPurgeFreq", D_OPTIONAL,    { { PARAM_TIME, &MemoPurgeFreq } } },

  /* StatServ Configuration */
  { "LagDetect", D_OPTIONAL,        { { PARAM_SET, &LagDetect } } },
  { "MaxPing", D_OPTIONAL,          { { PARAM_TIME, &MaxPing } } },

  /* Global Configuration */
  { "GlobalNotices", D_OPTIONAL,    { { PARAM_SET, &GlobalNotices } } },
  { "UseMD5", D_OPTIONAL,           { { PARAM_SET, &UseMD5 } } },
  { "MaxServerCollides", D_OPTIONAL,{ { PARAM_INT, &MaxServerCollides } } },
  { "MinServerCollidesDelta", D_OPTIONAL,{ { PARAM_TIME, &MinServerCollidesDelta } } },

  { 0, 0,                           { { 0, 0 } } }
};

/*
ClearDirectives()
 Zero all of the ptr fields of directives[]

If rehash is 1, zero all directives that are NOT required. If
we zero a required directive, and they commented it out, it would
never get reset, which could cause a seg fault down the line. This
way, if they comment out a required directive and rehash, we still
have the old copy to work from. If they change a required directive's
value and rehash, it will simply get set to the new value, so
everything is fine.
*/

static void
ClearDirectives(int rehash)

{
  struct Directive *tmp;
  int ii;

  for (tmp = directives; tmp->name; ++tmp)
  {
    if (rehash &&
        ((tmp->flag == D_NORUNTIME) || (tmp->flag == D_REQUIRED)))
      continue;

    for (ii = 0; ii < PARAM_MAX; ii++)
    {
      if (!tmp->param[ii].type)
        break;

      switch (tmp->param[ii].type)
      {
        case PARAM_STRING:
        {
          *(char **) tmp->param[ii].ptr = NULL;
          break;
        }

        case PARAM_TIME:
        {
          *(long **) tmp->param[ii].ptr = NULL;
          break;
        }

        case PARAM_INT:
        case PARAM_SET:
        case PARAM_PORT:
        {
          *(int *) tmp->param[ii].ptr = 0;
          break;
        }

        default: break;
      } /* switch (tmp->param[ii].type) */
    }
  }
} /* ClearDirectives() */

/*
CheckDirectives()
 Make sure all required directives were specified (by checking
if any of them have zero values)
Return 1 if they are all ok, 0 if not
*/

static int
CheckDirectives()

{
  struct Directive *tmp;
  int ii,
      ret,
      good;

  ret = 1;
  for (tmp = directives; tmp->name; tmp++)
  {
    if ((tmp->flag == D_REQUIRED) || (tmp->flag == D_NORUNTIME))
    {
      for (ii = 0; ii < PARAM_MAX; ii++)
      {
        if (!tmp->param[ii].type)
          break;

        good = 1;
        switch (tmp->param[ii].type)
        {
          case PARAM_STRING:
          {
            if (!(*(char **) tmp->param[ii].ptr))
              good = 0;

            break;
          }

          case PARAM_TIME:
          {
            if (!(*(long **) tmp->param[ii].ptr))
              good = 0;

            break;
          }

          case PARAM_INT:
          case PARAM_SET:
          case PARAM_PORT:
          {
            if (!(*(int *) tmp->param[ii].ptr))
              good = 0;

            break;
          }

          default:
          {
            /* shouldn't get here */
            good = 0;
            break;
          }
        }

        if (!good)
        {
          ret = 0;
          fatal(1, "%s: Missing required directive [%s]",
            SETPATH,
            tmp->name);
        }
      }
    }
  }

  /*
   * Some variable-specific checks
   */
  if (FloodProtection &&
      (!FloodCount || !FloodTime || !IgnoreTime || !IgnoreOffenses))
  {
    fatal(1,
      "%s: When FloodProtection is enabled, FloodCount, FloodTime, IgnoreTime, and IgnoreOffenses are required",
      SETPATH);
    ret = 0;
  }

  if (BindAttemptFreq && !MaxBinds)
  {
    fatal(1,
      "%s: When BindAttempFreq is enabled, MaxBinds is also required",
      SETPATH);
    ret = 0;
  }

  return (ret);
} /* CheckDirectives() */

/*
FindDirective()
 Return pointer to index of directives[] matching 'directive'
*/

struct Directive *
FindDirective(char *directive)

{
  struct Directive *tmp;

  if (!directive)
    return (NULL);

  for (tmp = directives; tmp->name; tmp++)
    if (!irccmp(directive, tmp->name))
      return (tmp);

  return (NULL);
} /* FindDirective() */

/*
dparse()
 Parse the given line from the settings file SETPATH
Return: 2 if the line is ok
        1 if the line contained warnings
        0 if the line contained errors
*/

static int
dparse(char *line, int linenum, int rehash)

{
  struct Directive *dptr;
  int larc; /* line arg count */
  char *larv[PARAM_MAX]; /* holds line arguements */
  char *lineptr,
       *tmp;
  int ret,
      ii,
      pcnt;

  ret = 2;

  /*
   * We can't use SplitBuf() to break up the line, since
   * it doesn't handle quotes etc. - do it manually
   */

  larc = 0;
  for (lineptr = line; *lineptr; lineptr++)
  {
    if (larc >= PARAM_MAX)
    {
      fatal(1, "%s:%d Too many parameters (max: %d)",
        SETPATH,
        linenum,
        PARAM_MAX);
      ret = 0;
      break;
    }

    if (!lineptr || !*lineptr)
      break;

    while (*lineptr && IsSpace(*lineptr))
      lineptr++;

    if (!*lineptr)
      break;

    tmp = lineptr;

    if (*lineptr == '"')
    {
      /* we encountered a quote */

      /* advance past quotation mark */
      tmp++;
      lineptr++;

      /*
       * Now advance lineptr until we hit another quotation mark,
       * or the end of the line
       */
      while (*lineptr && (*lineptr != '"'))
      {
        /*
         * If they want to include double quotes, they can
         * put a \" inside the quoted string, so advance
         * lineptr past it twice, once for the '\' and once
         * for the '"'.
         */
        if (*lineptr == '\\')
          lineptr++;

        lineptr++;
      }

      if (!*lineptr)
      {
        /* we hit EOL without reaching another quotation mark */
        fatal(1, "%s:%d Unterminated quote",
          SETPATH,
          linenum);
        ret = 0;
        break;
      }

      *lineptr = '\0';
    } /* if (*lineptr == '"') */
    else
    {
      /*
       * Advance lineptr until we hit a space
       */
      while (*lineptr && !IsSpace(*lineptr))
        lineptr++;

      if (*lineptr)
        *lineptr = '\0';
    }

    larv[larc++] = tmp;
  } /* for (lineptr = line; *lineptr; lineptr++) */

  if (!ret || !larc)
    return (ret);

  if (!(dptr = FindDirective(larv[0])))
  {
    fatal(1, "%s:%d Unknown directive [%s] (ignoring)",
      SETPATH,
      linenum,
      larv[0]);
    return (1);
  }

  if (rehash && (dptr->flag == D_NORUNTIME))
  {
    /*
     * SETPATH is being parsed during a rehash, and we
     * hit a non-run time configurable option, ignore it
     */
    return (2);
  }

  pcnt = 1;
  for (ii = 0; ii < PARAM_MAX; ii++, pcnt++)
  {
    if (!dptr->param[ii].type)
      break;

    /*
     * Now assign our variable (dptr->param[ii].ptr) to the
     * corresponding larv[] slot
     */
    if ((dptr->param[ii].type != PARAM_SET) && (pcnt >= larc))
    {
      fatal(1, "%s:%d Not enough arguements to [%s] directive",
        SETPATH, linenum, dptr->name);
      return (0);
    }

#if 0
    /*
     * There should be code which check for too many arguments for
     * PARAM_SET - because of bugs in previous HybServ1 code I am leaving
     * this code under undef, but it _should_ go into distribution once.
     * However, I don't wont to break old `save -conf' files. -kre
     */
     if ((dptr->param[ii].type == PARAM_SET) && (pcnt > 1))
     {
        fatal(1, "%s:%d Too many arguments for [%s] directive",
          SETPATH, linenum, dptr->name);
        return 0;
     }
#endif

    switch (dptr->param[ii].type)
    {
      case PARAM_STRING:
      {
        if ((*(char **) dptr->param[ii].ptr) != NULL)
        {
          /*
           * If this is a rehash, make sure we free the old
           * string before allocating a new one. If this
           * is NOT a rehash, we should never get here, because
           * ClearDirectives() would have already zeroed
           * all ptr fields of directives[]
           */
          MyFree(*(char **) dptr->param[ii].ptr);
        }

        *(char **) dptr->param[ii].ptr = MyStrdup(larv[pcnt]);
        break;
      }

      case PARAM_INT:
      {
        int value;

        value = IsNum(larv[pcnt]);
        if (!value)
        {
          fatal(1, "%s:%d Invalid integer",
            SETPATH,
            linenum);
          ret = 0;
          break;
        }

        /*
         * We have to call atoi() anyway since IsNum() would
         * have returned 1 if larv[pcnt] was "0", but IsNum()
         * is a good way of making sure we have a valid integer
         */
        *(int *) dptr->param[ii].ptr = atoi(larv[pcnt]);
        break;
      }

      case PARAM_TIME:
      {
        long value;

        value = timestr(larv[pcnt]);
	/* Now, let us consider this a bit. Function timestr() will try to
	 * extract as much data as it can. And sometimes we actually
	 * _want_ to put 0 in time field to turn off that feature. So we
	 * will have it turned off whether it has garbage there, or is 0.
	 * Sounds OK, does it? -kre */
	/*
        if (!value)
        {
          fatal(1, "%s:%d Invalid time format",
            SETPATH,
            linenum);
          ret = 0;
          break;
        }
	*/

        *(long *) dptr->param[ii].ptr = value;
        break;
      }

      case PARAM_SET:
      {
        *(int *) dptr->param[ii].ptr = 1;
        break;
      }

      case PARAM_PORT:
      {
        int value;

        value = IsNum(larv[pcnt]);
        if (!value)
        {
          fatal(1, "%s:%d Invalid port number (must be between 1 and 65535)",
            SETPATH,
            linenum);
          ret = 0;
          break;
        }

        value = atoi(larv[pcnt]);

        if ((value < 1) || (value > 65535))
        {
          fatal(1, "%s:%d Invalid port number (must be between 1 and 65535)",
            SETPATH,
            linenum);
          ret = 0;
          break;
        }

        *(int *) dptr->param[ii].ptr = value;

        break;
      }

      default:
      {
        /* we shouldn't get here */
        fatal(1, "%s:%d Unknown parameter type [%d] for directive [%s]",
          SETPATH,
          linenum,
          dptr->param[ii].type,
          dptr->name);
        ret = 0;
        break;
      }
    } /* switch (dptr->param[ii].type) */
  } /* for (ii = 0; ii < PARAM_MAX; ii++, pcnt++) */

  return (ret);
} /* dparse() */

/*
LoadSettings()
 Load directives in SETPATH, and make sure all required
directives are specified. Return 1 if successful, 0 if not
 If (rehash == 1), it indicates this function is being
called from a rehash, so don't call ClearDirectives() or
CheckDirectives()
*/

int
LoadSettings(int rehash)

{
  FILE *fp;
  char buffer[MAXLINE];
  int goodread;
  int cnt;

  if ((fp = fopen(SETPATH, "r")) == NULL)
  {
    fprintf(stderr, "Unable to open SETPATH (%s)\n",
      SETPATH);

    if (rehash)
      return (0);
    else
      exit(0);
  }

  /*
   * If rehash is 0, clear all directives, otherwise clear
   * only PARAM_SET directives in case they comment out a
   * SET directive, in which case we wouldn't be able to
   * detect it, unless it was already zero'd
   */
  ClearDirectives(rehash);

  cnt = 0;
  goodread = 1;

  while (fgets(buffer, sizeof(buffer), fp))
  {
    cnt++;
    if (buffer[0] != '#') /* comment line */
    {
      int tmp;

      tmp = dparse(buffer, cnt, rehash);

      if ((goodread > 0) && (tmp == 0))
        goodread = 0;
    }
  }

  fclose(fp);

  if (!rehash)
  {
    /*
     * Now check to make sure all required directives
     * were specified
     */
    if (CheckDirectives() == 0)
      goodread = 0;
  }

  return (goodread);
} /* LoadSettings() */

/*
SaveSettings()
 Save all current settings to SETPATH.
Return: 1 if successful
        0 if not
*/
int SaveSettings()
{
  FILE *fp;
  struct Directive *dptr;
  int ii;
  char buffer[MAXLINE],
       tmp[MAXLINE],
       tempname[MAXLINE];

  /* MMkay, this should write safe config files so that they won't get
   * b0rked if something happens when writing. -kre */
  ircsprintf(tempname, "%s.tmp", SETPATH);
  
  if (!(fp = fopen(tempname, "w")))
  {
    putlog(LOG1,
      "SaveSettings(): Unable to open %s: %s",
      SETPATH,
      strerror(errno));
    return 0;
  }

  for (dptr = directives; dptr->name; dptr++)
  {
    buffer[0] = 0;
    for (ii = 0; ii < PARAM_MAX; ii++)
    {
      if (!dptr->param[ii].type)
        break;

      switch (dptr->param[ii].type)
      {
        case PARAM_STRING:
        {
          /* Try to write out string only if non-null, ie is set -kre */
          if (*(char **)dptr->param[ii].ptr)
          {
            ircsprintf(tmp, "\"%s\" ",
              *(char **) dptr->param[ii].ptr);
            strcat(buffer, tmp);
          }

          break;
        } /* case PARAM_STRING */

        case PARAM_TIME:
        {
          ircsprintf(tmp, "%s ",
            timeago(*(long *) dptr->param[ii].ptr, 4));
          strcat(buffer, tmp);

          break;
        } /* case PARAM_TIME */

        case PARAM_INT:
        case PARAM_PORT:
        {
          ircsprintf(tmp, "%d ", *(int *) dptr->param[ii].ptr);
          strcat(buffer, tmp);

          break;
        }

        case PARAM_SET:
        {
          /*
           * Only write out SETs if they are non null
           *
           * IMHO if dptr->param[ii].type == PARAM_SET there is no reason
           * to write numeric value because it is ignored in the first
           * way.
           * -kre
           */
          if (*(int *) dptr->param[ii].ptr)
          {
#if 0
            ircsprintf(tmp, "%d ",
              *(int *) dptr->param[ii].ptr);
            strcat(buffer, tmp);
#endif
            /* Fill in buffer.. */
            strcat(buffer, " ");
            /* and then do continue -kre */
          }
          else
            /* Any of SETs in param[] was empty, so there is no need to
             * write directive -kre */
            buffer[0] = 0;

          break;
        } /* case PARAM_SET */
      } /* switch (dptr->param[ii].type) */
    }

    if (*buffer)
      fprintf(fp, "%-20s %s\n",
        dptr->name,
        buffer);
  }

  fclose(fp);

  rename(tempname, SETPATH);

  return 1;
} /* SaveSettings() */