File: fcheck

package info (click to toggle)
fcheck 2.7.59-22
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 608 kB
  • sloc: perl: 5,384; sh: 45; makefile: 41
file content (1700 lines) | stat: -rwxr-xr-x 72,500 bytes parent folder | download | duplicates (3)
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
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
#!/usr/bin/perl
#############################################################################
#                                                                           #
# Copyright (C) 1996 Michael A. Gumienny                                    #
#                                                                           #
# This program is free software; you can redistribute it and/or modify it   #
# under the terms of the GNU General Public License as published by the     #
# Free Software Foundation; either version 2 of the License, or (at your    #
# option) any later version.                                                #
#                                                                           #
# This program is distributed in the hope that it will be useful, but       #
# WITHOUT ANY WARRANTY; without even the implied warranty of                #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General #
# Public License for more details.                                          #
#                                                                           #
# You should have received a copy of the GNU General Public License along   #
# with this program; if not, write to:                                      #
#                                                                           #
#      Free Software Foundation, Inc.                                       #
#      59 Temple Place - Suite 330                                          #
#      Boston, MA 02111-1307, USA.                                          #
#                                                                           #
# Or you can find the full GNU GPL online at: http://www.gnu.org            #
#                                                                           #
# Please send your comments, updates, improvements, wishes and bug reports  #
# for fcheck to:                                                            #
#                                                                           #
#      Michael A. Gumienny           gumienny@hotmail.com                   #
#                                                                           #
#############################################################################

#############################################################################
#                                                                           #
# File:  fcheck                                                             #
#                                                                           #
# Usage: fcheck [-acdfihlrsvx] [configuration file] [directory]             #
#                                                                           #
# $Id: fcheck,v 2.7.59 2001/03/03 02:38:26 root Exp root $                  #
#                                                                           #
# Description:                                                              #
#        Used to validate creation dates of critical system files, and as   #
#        a baseline system verification script.                             #
#                                                                           #
# Options:                                                                  #
#        -a    Automatic mode, do all directories in configuration file.    #
#        -c    Create a new base line database for the given directory.     #
#        -d    Directory names are to be monitored for changes also.        #
#        -f    Use alternate 'filename' as the configuration file.          #
#        -i    Ignore creation times, check permissions, adds, deletes.     #
#        -h    Append the $HOSTNAME to the configuration filename.          #
#        -l    Log information to logger rather than stdout messages.       #
#        -r    Report mode - so you can save to a file and get a positive   #
#              record of what you have checked, even if errors go to logger #
#        -s    Sign each file with a CRC/hash signature.                    #
#        -v    Verbose mode, not used for report generation.                #
#        -x    eXtended Unix checks - Nlinks, UID, GID, Major/Minor numers  #
#                                                                           #
# Author: Michael A. Gumienny                                               #
#                                                                           #
# Written: 1996                                                             #
#                                                                           #
#############################################################################

#############################################################################
# $Log: fcheck,v $
# Revision 2.7.59  2001/03/03 02:38:26  root
# Beta testers gave final thumbs up, final checkin w/ approval.
#
#
# Revision 2.7.58  2001/03/01 11:24:29  root
# This version needed some repairs to the output. CRC differences were not being
# displayed to the screen, only to logger. No impact from this bug, FCheck still
# flagged CRC changes, but did not display them as CRC diffs, only that a change
# had been detected when ran in interactive mode.
#
#
# Revision 2.7.57  2001/02/21 01:18:09  root
# GNU version of MD5 sends its output backwards than high end Unix systems.
# Added a new routines to autodetect this based on filename, md5 or md5sum.
#
#
# Revision 2.7.56  2001/01/13 17:26:19  root
# Checked in with minor cosmetic improvements.
#
#
# Revision 2.7.55  2000/12/05 01:18:09  root
# Put back exclusion routine that was in version 2.7.51. New routine did not
# accurately exlude files/directories except for exact matches only.
#
#
# Revision 2.7.54  2000/11/07 12:33:32  root
# Added "FindDiff" routine to report the detail of what has been changed,
# taking all guess work out of the reported lines.
#
# FCheck WARNING lines now report like the following:
#    fcheck: "WARNING: [host] /bin/cron [CRCs: 3932278317 - 2003041699]"
#          which tells you immediately that there is a variation in the CRCs.
#
#
# Revision 2.7.52Beta  2000/10/15 16:50
#  Added more features, merged in several suggestions from jim moore.
#   (Sorry for the delay in getting this out with them.)
#
#  The ability to include chunks of configuration files through the CFINCLUDE
#  directive (suggestion by John Vogtle)
#
#  Added the "FILE" type for checking individual files.
#
#  Made the database into a single file
#
#  Fixed bug in MD5 handling (so that it can use standard source of MD5
#  available)
#
#  Added report mode, so that the report is sufficient for documentation
#
#  Added modes to check uid, gid, and major and minor numbers on Unix special
#  files
#
#  Added ReadDB and WriteDB configuration primatives, so that the same config
#  file could be used to generate a database that would be moved to read-only
#  a location
#
#  Added check for users passing a (-s) flag to HASHFunc (otherwise the open
#  tries to execute the file and collect its output)
#
#
# Revision 2.7.51  2000/04/02 18:45:32  root
# Final checkin for revision control of tested script
#
#
# Revision 2.7.50  2000/03/11 16:10:39  root
# Modified parsing of "logger" variable to allow user defined option flags
#
# Finally got around to fixing the trailing space bug in the configuration
# file. Now the parser is less strict of the varying editors being used to
# create configuration files.
#
# Todo: request have been made to register a permission problem when ran
#       as other than root user, and can't recurse directory trees rather
#       than terminate with an error as fcheck does now.
#
#
# Revision 2.7.49  2000/03/11 15:08:04  root
# Fixed option when told to ignore creation dates to also check file size.
#
# Fixed option when told to ignore diretory names (-d), when you are not
# checking recursively and don't want to see directory Inode changes.
#
#
# Revision 2.7.47  2000/02/21 02:05:18  root
# Removed the pre-defined "-t" (tag) option used by logger to allow for user
# defined output devices: scritps, programs, or device files.
#
# Typo found under permission calculations:
#       local ($ftype) = $ftype[($mode & 0170000)>>12];
#
# A reported glitch with European and some US spellings for filenames that
# contain a single quote (D'Abo) was fixed.
#
#
# Revision 2.7.46  2000/01/10 23:06:22  root
# Minor improvements and documentation efforts made.
# Replaced uneccesary date coding to compensate epoch of January 1, 1970 GMT
#                $year += ($year < 70) ? 2000 : 1900;
# with a simpler
#                $year += 1900;
#
# Revision 2.7.45  1999/10/19 17:40:22  root
# Added optional file hash/CRC signature abilities.
#
# Added support for multiple configuration files by passing optional name.
#
# Updated documentation.
#
# Todo: Minor issue. Need to check string parsing from configuration file.
#       Spaces on end of string confuse current parser logic.
#
#
# Revision 2.7.43  1999/10/08 20:57:34  root
# Added optional CRC/hash signature ability
#
#
# Revision 2.7.42  1999/09/21 00:55:14  root
# Experimental stages, checked in.
#
#
# Revision 2.7.40  1999/09/14 02:18:01  root
# Added suggestion by Ian Thurlbeck <ian@stams.strath.ac.uk> to replace the
# lookup intensive arrays with associative arrays to speed things along.
#
# Removed a few un-needed lines and routines left in from previos edits.
#
# Updated documentation.
#
#
# Revision 2.7.38  1999/08/16 22:16:37  root
# Enclosed logger string in quotes. RedHat Linux logger choked without them.
# Fixed spelling errors, etc in documentation.
#
#
# Revision 2.7.37  1999/08/04 22:51:00  root
# Minor changes to permissions routines.
#
#
# Revision 2.7.34  1999/07/29 01:11:13  root
# Now Works under windows, added internal ls type function.
#
#
# Revision 2.6.27  1999/07/24 14:49:04  root
# Initial checkin for migration to DOS PERL
#

#############################################################################
#                                                                           #
#                 User modifiable variable definitions:                     #
#                                                                           #
#############################################################################
# This should be passed through the command line, but hard coding still works
$config="/etc/fcheck/fcheck.cfg";
#$config="C:/Work/fcheck/fcheck.cfg";

#############################################################################
#                                                                           #
#      Non-User modifiable variable definitions: (DO NOT MODIFY THESE!)     #
#                                                                           #
#############################################################################
undef($Auto);
undef($Verbose);
undef($BaseLine);
undef($CreateDate);
undef($DirCheck);
undef($Logging);
undef($DOS);
undef($Hash);
undef($XTended);
undef($Reporting);
undef($ReportFail);
undef($ALogger);
undef($ReadDB);
undef($WriteDB);
undef($GnuHASHOut);
$XTended=0;
$Reporting=0;
$ReportFail=0;
($Me)=split("/", reverse($0));
($Me)=split(" ", reverse($Me));
$rcfflag=1;

#############################################################################
# &Help;                                                                    #
# This routine explains brief usage syntax to STDOUT. The program is then   #
#  terminated.                                                              #
#############################################################################
sub Help
    {
    open(ME, "<$0");
    for ($i=0; $i<38; $i++) { $_=<ME>; }
    close(ME);

    $_ = substr($_, 15, 18);

    printf("Usage:\t%s [-acdfhilrsvx] [config filename] [directory]\n", $Me);
    printf("\tUsed to validate creation dates of critical system files.\n\n");
    printf("\tVersion: %s\n\n", $_);
    printf("\tOptions:\n");
    printf("\t-a\tAutomatic mode, do all directories in configuration file.\n");
    printf("\t-c\tCreate base-line database.\n");
    printf("\t-d\tDirectory names are to be monitored for changes also.\n");
    printf("\t-f\tUse alternate 'config filename' to initiate from.\n");
    printf("\t-h\tAppend the \$HOSTNAME to the configuration filename.\n");
    printf("\t-i\tIgnore create dates, check permissions, additions, deletions.\n");
    printf("\t-l\tLog information to logger rather than stdout messages.\n");
    printf("\t-r\tReporter mode that lists individual files too.\n");
    printf("\t-s\tSign each file with a CRC/hash signature.\n");
    printf("\t-v\tVerbose mode.\n");
    printf("\t-x\teXtended Unix checks - Nlinks, UID, GID, Major/Minor numbers.\n\n");
    exit(0);
    }



#############################################################################
# &DoConfig($config_file,$recurse,$RecurseDepth);                           #
#############################################################################
sub DoConfig
    {
    local($CFFile,$godeep,$CLevel)=@_;
    local($KeyWord, $Variable);
    local(*CONFIG);
    if($Verbose)
        { printf("debug: (DoConfig) Drawing Config from %s\n", $CFFile); }
    open(CONFIG, "<$CFFile") || &Error("Can't find configuration file $CFFile");
    $CLevel++;
    $CTemp="\t" x $CLevel ;
    $CString="$CTemp"."$CFFile";
    push(@ConfigTree,$CString);
    while(<CONFIG>)
        {
        next if /^#/ || /^\n/;
        chop;
        ($KeyWord, $Variable)=m/(\w+)\s*=\s*(.*)/;
        # Fast hack to remove trailing spaces...
        $Variable =~ s/\s*$//;
        $KeyWord = &toupper($KeyWord);
        if ( $Verbose)
            {printf("debug: Key:\"%s\"\tValue:\"%s\"\n", $KeyWord, $Variable);}
        # Allow config files to be modular, included from one another
        # This means that the last definition wins
        if ( $KeyWord eq "CFINCLUDE")
            {
            if (!(-r  $Variable && -s $Variable)) { &Error("CFINCLUDE $Variable in config file NOT readable or zero length"); }
            if (-f "$Variable" && ($godeep)) { &DoConfig("$Variable", $godeep,$CLevel); }
            }
        if ( $KeyWord eq "DIRECTORY") { push(@CheckDir, $Variable); }
        if ( $KeyWord eq "FILE") { push(@CheckFile, $Variable); }
        if ( $KeyWord eq "EXCLUSION")
            {
            if($DOS) { $Variable = &toupper($Variable); }
            $TVariable="$Variable";
            push(@ExcludeMatrix, $TVariable);
            }
        if ( $KeyWord eq "LOGGER")
            {
            ($Logger, $LoggerFlags) = $Variable =~ m/(\S+)\s* s*(.*)\s*/;
            (@LogFlags)=split(' ',$LoggerFlags);
            if ( $Verbose)
                { printf("debug: Corrected LOGGER value:\"%s\"\ndebug: Corrected LOGGER FLAGs:\"%s\"\n", $Logger, $LoggerFlags); }
            }
        if ( $KeyWord eq "AUTHLOGGER")
            {
            ($ALogger, $ALoggerFlags) = $Variable =~ m/(\S+)\s* s*(.*)\s*/;
            (@ALogFlags)=split(' ',$ALoggerFlags);
            if ( $Verbose)
                 { printf("debug: Corrected AUTHLOGGER value:\"%s\"\ndebug: Corrected AUTHLOGGER FLAGs:\"%s\"\n", $ALogger, $ALoggerFlags); }
            }
        if ( $KeyWord eq "FILETYPER") { $Filefunc = $Variable; }
        if ( $KeyWord eq "DATABASE")  { $DBFile = $Variable; }
        if ( $KeyWord eq "READDB")  { $ReadDB = $Variable; }
        if ( $KeyWord eq "WRITEDB")  { $WriteDB = $Variable; }
        if ( $KeyWord eq "HOSTNAME")  { $ThisHost = $Variable; }
        if (($KeyWord eq "SYSTEM") && (&toupper($Variable) eq "DOS"))
            { $ENV{'CMDLINE'}="null"; }
        if (($KeyWord eq "SYSTEM") && (&toupper($Variable) eq "UNIX"))
            {
            $ENV{'CMDLINE'}="";
            $ThisOS=`uname -s -r`;
            chop($ThisOS);
            $Uname=`uname -a`;
            chop($Uname);
            }
        if ( $KeyWord eq "TIMEZONE")  { $ENV{'TZ'}=&toupper($Variable); }
        if ( $KeyWord eq "SIGNATURE") { $HASHFunc = $Variable; }
        # if ( $KeyWord eq "GNUMD5")    { $GnuHASHOut = &toupper($Variable); }
        }
    # if ($GnuHASHOut == "False") { undef($GnuHASHOut); }
    }



#############################################################################
# &Configure;                                                               #
# This routine reads in the configuration file, and initializes user        #
# definable variables.                                                      #
#############################################################################
sub Configure
    {
    if ($Verbose) { printf("debug: Attempting to determine OS and hostname.\n"); }
    # Try to determine the OS that we're running on based on environment
    # variables that do not normally exist on Unix platforms but do in DOS.
    # This can be set in the config file to by pass this routine.
    #
    if ($ENV{'COMSPEC'} && $ENV{'CMDLINE'})
        {
        # I think this system is DOS
        ++$DOS;
        # hostname not included with win3.x, win95/98, but is for NT, so...
        $ThisHost = $ENV{'HOSTNAME'} unless $ThisHost;
        }
    else
        {
        # I think this system is Unix based
        if(!$ThisHost)
            {
            $ThisHost = `uname -n`;
            chop($ThisHost);
            $ThisOS=`uname -s -r`;
            chop($ThisOS);
            $Uname=`uname -a`;
            chop($Uname);
            }
        }
    # If no hostname given, default to "localhost" as our name
    $ThisHost = "localhost" unless $ThisHost;
    if ($Verbose)              { printf("debug: Set hostname to: $ThisHost.\n"); }
    if (($Verbose) && ($DOS))  { printf("debug: OS is DOS based.\n"); }
    if (($Verbose) && (!$DOS)) { printf("debug: OS is Unix based.\n"); }
    if ($Verbose) { printf("debug: (Configure) Reading configuration file.\n"); }
    # Allow for a config definition involving the $HOSTNAME
    if($UseHostName)
        { $CFInput=sprintf("%s.%s", $config, $ThisHost); }
    else
        { $CFInput=$config; }
    if($Verbose)
        { printf("debug: (Configure) Configuration file set to: %s\n", $CFInput); }

    $ConfigLevel = -1;
    # Make an attempt to find the configuration file at least one deep
    &DoConfig($CFInput,$rcfflag,$ConfigLevel);
    if (!$ENV{'TZ'}) { printf("Error: Need TZ environment configured or environment set!\n\n"); &Help; }
    }



#############################################################################
# &Exclude($filename);                                                      #
#############################################################################
sub Exclude
    {
    local($EFile)=@_;
    if($Verbose) { printf("debug: (Exclude) checking on %s\n", $EFile); }
    foreach $Line (@ExcludeMatrix)
        {
        if($DOS) { $EFile = &toupper($EFile); }
        if($Verbose) { printf("debug: (Exclude) against %s\n", $Line); }
            if ($Line =~ /\/$/)
                { # Sub-directory matches
                if ($EFile =~ /^$Line/) { if($Verbose) { printf("debug: (Exclude) directory match found, ignoring below here...\n"); } return(1); }
                }
            else
                { # A file matches
                if ($EFile eq $Line) { if($Verbose) { printf("debug: (Exclude) file match found, ignoring...\n"); } return(1); } }
                }
            return(0);
        }



#############################################################################
# &BuildFileSeg();                                                          #
#############################################################################
sub BuildFileSeg
    {
    if ($Verbose) { printf("debug: (BuildFileSeg) building baseline %s\n", $DBfile); }
    printf(DB "# - - - - -> BEGIN FILES <- - - - -\n");
    foreach $Line (@LiveData) { printf(DB "%s\n", $Line); }
    printf(DB "# - - - - -> END FILES <- - - - -\n");
    return 0;
    }



#############################################################################
# &BuildDirSeg($DirName,$recurse);                                          #
#############################################################################
sub BuildDirSeg
    {
    local($DirName,$recurse)=@_;
    if ($Verbose) { printf("debug: (BuildDirSeg) building baseline %s\n", $DBfile); }
    if ( $recurse == 1 )
        { printf(DB "# - - - - -> BEGIN Directory Recursion  %s <- - - - -\n", $DirName); }
    else
        { printf(DB "# - - - - -> BEGIN Directory %s <- - - - -\n", $DirName); }
    foreach $Line (@LiveData) { printf(DB "%s\n", $Line); }
    return 0;
    }



#############################################################################
# &GetFilesDB($dir);                                                        #
# This routine builds the array @BaseLineData from the database segment     #
#############################################################################
sub GetFilesDB
    {
    local($index,$BI,$BP,$BL,$BU,$BG,$BS,$BT,$BN,$CRC,$pdir);
    if($DOS) { $Dirname =~ s/:/.drive/; } # Handle drive delimiters, C:, D:, E:, etc.
    %BaseLineData = ();
    if (($FilesBegin != -1) && ($FilesEnd != -1) && ($FilesEnd <= $FilesEnd))
        {
        for ($index=$FilesBegin; $index<$FilesEnd + 1; $index++)
            {
            $_="$Database[$index]";
            chop;
            if($Verbose) { printf("debug: (GetFilesDB) reading [%s]\n", $_); }
            # BI - Baseline Inode, BP - Baseline Permissions, BS - Size
            # BT - Time, BN - Name (all generated by the "stat" call of perl
            # B_CRC - the Checksum/Signature
            # eXtended format has $BL - Link Count, $BU - Uid, $BG - Gid
            if ($XTended)
                { ($BI, $BP, $BL, $BU, $BG, $BS, $BT, $BN, $CRC) = split("!", $_); }
            else
                { ($BI, $BP, $BS, $BT, $BN, $CRC) = split("!", $_); }
            if(((($BP & 0170000)>>12)==4) ) { next; }
            $BaseLineData{$BN} = $_;
            }
        }
    else
        { if($Verbose) { printf("debug: (GetFilesDB) No files to retrieve from DB"); } }
    return(@BaseLineData);
    }



#############################################################################
# &GetLiveFiles();                                                          #
# This routine builds the array @LiveData based on the live data.           #
#############################################################################
sub GetLiveFiles
    {
    local($filename);
    if ($Verbose) { printf("debug: (GetLiveFiles) reading %s files\n",$#CheckFile ); }
    if ( $#CheckFile != -1 )
        {
        for ($index=0; $index < $#CheckFile + 1; $index++)
            {
            if ($Verbose) { printf("debug: (GetLiveFiles) reading %s \n",$CheckFile[$index]); }
            # Report configuration problems - non-existant files - when Baselining
            if (!-e "$CheckFile[$index]" && $BaseLine)
                {
                if ($Logging)
                    {
                    if(!$DOS)
                        {
                        $cmd=sprintf("\"CONFIG: File %s on %s contains reference to non-existant file %s\"\n", $config,$ThisHost,$CheckFile[$index]);
                        system($Logger, @LogFlags, $cmd);
                        }
                    }
                if ((!$Logging) || (($Logging) && ($Reporting)))
                    { printf("\nCONFIG: File %s on %s contains reference to non-existant file %s\n",$config,$ThisHost,$CheckFile[$index]); }
                }
            # Root generally can not read a file if it is a link and the link points to
            # a non-existant file. Basically the stat will fail
            next if (!-r "$CheckFile[$index]" );
            if (-d "$CheckFile[$index]" )
                {
                push(@CheckDir, "$CheckFile[$index]" );
                if ($Logging)
                    {
                    $cmd=sprintf("\"CONFIG: Configuration file on %s labels %s as a file when it is a directory\"\n",$ThisHost,$CheckFile[$index]);
                    system($Logger, @LogFlags, $cmd);
                    }
                next;
                }
            elsif (-f "$CheckFile[$index]" )
                { &GetFileInfo("$CheckFile[$index]"); }
            elsif (!$DOS)
                {
                # give the Unix folks a bit more info
                if (-p "$CheckFile[$index]" || -S "$CheckFile[$index]" || -b "$CheckFile[$index]" || -c "$CheckFile[$index]")
                    { &GetFileInfo("$CheckFile[$index]"); }
                }
            else
                {
                if ($Logging)
                    {
                    $cmd=sprintf("\"CONFIG: Configuration file on %s labels %s as a file when it is not a file or a directory\"\n",$ThisHost,$CheckFile[$index]);
                    system($Logger, @LogFlags, $cmd);
                    }
                next;
                }
            }
        }
    else
        { if ($Verbose) { printf("debug: (GetLiveFiles) No individual files to read\n"); } }
    }



#############################################################################
# &GetDirDB($dir);                                                          #
# This routine builds the array @BaseLineData from the database segment     #
#############################################################################
sub GetDirDB
    {
    local($Dirname)=@_;
    local($index,$BI,$BP,$BL,$BU,$BG,$BS,$BT,$BN,$CRC);
    if($DOS) { $Dirname =~ s/:/.drive/; } # Handle drive delimiters, C:, D:, E:, etc.
    $Dirname =~ s/\//_/g;
    if ($Verbose) { printf("debug: (GetDirDB) reading \n", $Dirname); }
    %BaseLineData = ();
    if ((defined($begin{"$Dirname"})) && (defined($end{"$Dirname"})) && ($begin{"$Dirname"} <= $end{"$Dirname"} + 1))
        {
        for ($index=$begin{"$Dirname"}; $index<$end{"$Dirname"} + 1; $index++)
            {
            $_="$Database[$index]";
            chop;
            if($Verbose) { printf("debug: (GetDirDB) reading [%s]\n", $_); }
            # BI - Baseline Inode, BP - Baseline Permissions, BS - Size
            # BT - Time, BN - Name (all generated by the "stat" call of perl
            # B_CRC - the Checksum/Signature
            if ($XTended)
                { ($BI, $BP, $BL, $BU, $BG, $BS, $BT, $BN, $CRC) = split("!", $_); }
            else
                { ($BI, $BP, $BS, $BT, $BN, $CRC) = split("!", $_); }
            if(!$DirCheck) { next if ( $BP =~ /^d/); }
            if( (!$DirCheck) && (!$DOS) && ((($BP & 0170000)>>12)==4) ) { next; }
            $BaseLineData{$BN} = $_;
            }
        }
    else
        {
        if (($Logging) && ($BaseLine))
            {
            if(!$DOS)
                {
                $cmd=sprintf("\"CONFIG: %s database %s does NOT match config file %s on %s for %s\"\n", $Me,$DBFile,$config,$ThisHost,$Dirname);
                system($Logger, @LogFlags, $cmd);
                }
            }
        &Error("Error: Baseline does not match configuration file on $Dirname");
        }
    return(@BaseLineData);
    }



#############################################################################
# &GetLiveDir($dir);                                                        #
# This routine builds the array @LiveData based on the live data.           #
#############################################################################
sub GetLiveDir
    {
    local($Dir)=@_;
    local($filename);
    if ($Verbose) { printf("debug: (GetLiveDir) reading %s\n", $Dir); }
    if (! -d $Dir )
        {
        if ($Logging)
            {
            if(!$DOS)
                {
                $cmd=sprintf("\"CONFIG: Configuration file %s on %s declares %s a Directory when it is not\"\n", $config,$ThisHost,$Dir);
                system($Logger, @LogFlags, $cmd);
                }
            }
        else
            { printf("\nCONFIG: Configuration file %s on %s labels %s as a directory when it is NOT \n",$config,$ThisHost,$Dir); }
        return;
        }
    else
        {
        # It's a directory
        if ($Dir =~ /:\/$/) { &GetDir($Dir, 0); }
        elsif (($Dir =~ /\/$/) && ($Dir ne "/")) { $Dir =~ s/\/$//; &GetDir($Dir, 1); }
        else { &GetDir($Dir, 0); }
        }
    }



###############################################################################
# $x=&Scan_Build(type);                                                       #
# This is the heart of the script. Scan_Build will either scan and/or build a #
# grouping of files based on the files or directories given it in the config  #
# file works on a directory by directory basis or a list of individual files  #
###############################################################################
sub Scan_Build
    {
    local($type)=@_;
    local($Hacks);

    # Check the type and log what we are doing verbose / debugging
    if (("$type" eq "Files") && ($Verbose)) { printf("debug: (Scan_Build) reading Files \n"); }
    elsif (("$type" eq "Directory") && ($Verbose))
        { printf("debug: (Scan_Build) reading directory %s\n", $Dir); }
    elsif (("$type" ne "Files") && ("$type" ne "Directory"))
        { &Error("Error: Scan_Build received an invalid type $type -- Must be Files or Directory"); }

    # Hacks is where plusses, minuses, and changes get incremented
    $Hacks=0;

    # If we are not building, then we are scanning
    if (!$BaseLine)
        {
        if (("$type" eq "Files"))
            {
            # Scan the individual files
            # Load the segment of an existing database into an associative array BaseLineData
            &GetFilesDB();
            # Build a similar array from the directory as it exists now
            &GetLiveFiles();
            }
        else
            {
            # Scan directory
            # Load the segment of an existing database into an associative array BaseLineData
            &GetDirDB($Dir);
            # Build a similar array from the directory as it exists now
            &GetLiveDir($Dir);
            }

        # Loop over the live data to detect differences
        for ($ldd=0; $ldd < $#LiveData + 1; $ldd++)
            {
            if ($XTended)
                { ($L_Inode, $L_Perms, $L_Links, $L_Uid, $L_Gid, $L_Size, $L_Time, $L_Name, $L_CRC) = split("!", $LiveData[$ldd]); }
            else
                { ($L_Inode, $L_Perms, $L_Size, $L_Time, $L_Name, $L_CRC) = split("!", $LiveData[$ldd]); }
            # Ignore any not in BaseLineData
            next unless defined($BaseLineData{$L_Name});

            if ($XTended)
                { ($B_Inode, $B_Perms, $B_Links, $B_Uid, $B_Gid, $B_Size, $B_Time, $B_Name, $B_CRC) = split("!", $BaseLineData{$L_Name}); }
            else
                { ($B_Inode, $B_Perms, $B_Size, $B_Time, $B_Name, $B_CRC) = split("!", $BaseLineData{$L_Name}); }
            # In the next version the checks, and the logging will be built through a mask
            if ($CreateDate)
                {
                # Ignore creation dates
                # Check to see if there is a mismatch in either the permissions or inode number
                if ((!$Hash) && (($L_Perms ne $B_Perms) || ($L_Inode ne $B_Inode) || ($L_Size ne $B_Size)))
                    {
                    # Are we logging (Unix style logger command)
                    if($Logging)
                        {
                        # Form the command in the $cmd variable
                        $cmd = sprintf("\"WARNING: [%s] %s [%s]\"\n", $ThisHost, $L_Name,
                            &FindDiff($B_Inode, &ShowPerms($B_Perms), $B_Size, &ctime($B_Time), "UID", "GID", "LINKS", "CRC",
                            $B_Name, $L_Inode, &ShowPerms($L_Perms),$L_Size, &ctime($L_Time), "UID", "GID", "LINKS", "CRC"), $L_Name);
                        system($Logger, @LogFlags, $cmd);
                        }
                    if ((!$Logging) || (($Logging) && ($Reporting)))
                        {
                        # Logger not available - print to screen
                        printf("\n\tWARNING: [%s] %s\n\t[%s]\n", $ThisHost, $L_Name,
                            &FindDiff($B_Inode, &ShowPerms($B_Perms), $B_Size, &ctime($B_Time), "UID", "GID", "LINKS", "CRC",
                            $B_Name, $L_Inode, &ShowPerms($L_Perms),$L_Size, &ctime($L_Time), "UID", "GID", "LINKS", "CRC"), $L_Name);
                        }
                    # Increment the number of "Hacks" for mismatched permissions or inode numbers
                    ++$Hacks;
                    }

                # Additionally check for Hash (e.g. MD5) mismatches
                # Do we care
                elsif ( ($Hash) && (($L_CRC ne $B_CRC) || ($L_Perms ne $B_Perms) || ($L_Inode ne $B_Inode) || ($L_Size ne $B_Size)))
                    {
                    if($Logging)
                        {
                        # Show the change to CRC/Signature
                        $cmd = sprintf("\"WARNING: [%s] %s [%s]\"\n", $ThisHost, $L_Name,
                            &FindDiff($B_Inode, &ShowPerms($B_Perms),$B_Size, &ctime($B_Time), "UID", "GID", "LINKS", $B_CRC,
                            $B_Name, $L_Inode, &ShowPerms($L_Perms),$L_Size, &ctime($L_Time), "UID", "GID", "LINKS", $L_CRC), $L_Name);
                        system($Logger, @LogFlags, $cmd);
                        }
                    if ((!$Logging) || (($Logging) && ($Reporting)))
                        {
                        printf("\n\tWARNING: [%s] %s\n\t[%s]\n", $ThisHost, $L_Name,
                            &FindDiff($B_Inode, &ShowPerms($B_Perms),$B_Size, &ctime($B_Time), "UID", "GID", "LINKS", $B_CRC,
                            $B_Name, $L_Inode, &ShowPerms($L_Perms),$L_Size, &ctime($L_Time), "UID", "GID", "LINKS", $L_CRC), $L_Name);
                        }
                    # Increment the number of "Hacks" for mismatched hashes
                    ++$Hacks;
                    }
                elsif ($Reporting)
                    {
                    if ( ("$type" eq "Files") || (-d $L_Name))
                        { printf("No changes on %s to: %s \n", $ThisHost, $L_Name); }
                     }

                 }
             elsif ($XTended)
                 {
                 # Creation time mode - Check times & permissions & inodes
                 if ((!$Hash) && (($L_Time ne $B_Time) || ($L_Size ne $B_Size) ||
                    ($L_Perms ne $B_Perms) || ($L_Inode ne $B_Inode) ||
                    ($L_Links ne $B_Links) || ($L_Uid ne $B_Uid) || ($L_Gid ne $B_Gid) ))
                     {
                     # Log differences
                     if($Logging)
                         {
                         $cmd = sprintf("\"WARNING: [%s] %s [%s]\"\n", $ThisHost, $L_Name,
                                &FindDiff($B_Inode, &ShowPerms($B_Perms),$B_Size, &ctime($B_Time), $B_Uid, $B_Gid, $B_Links, $B_CRC,
                                $B_Name, $L_Inode, &ShowPerms($L_Perms),$L_Size, &ctime($L_Time), $L_Uid, $L_Gid, $L_Links, $L_CRC), $L_Name);
                         system($Logger, @LogFlags, $cmd);
                         }
                     if ((!$Logging) || (($Logging) && ($Reporting)))
                         {
                         printf("\n\tWARNING: [%s] %s\n\t[%s]\n", $ThisHost, $L_Name,
                                &FindDiff($B_Inode, &ShowPerms($B_Perms),$B_Size, &ctime($B_Time), $B_Uid, $B_Gid, $B_Links, $B_CRC,
                                $B_Name, $L_Inode, &ShowPerms($L_Perms),$L_Size, &ctime($L_Time), $L_Uid, $L_Gid, $L_Links, $L_CRC), $L_Name);
                         }
                     # Increment # of changes
                     ++$Hacks;
                     }
                 # Check hashes in addition to times & permissions & inodes
                 elsif (($Hash) && (($L_Time ne $B_Time) || ($L_Size ne $B_Size) ||
                       ($L_Perms ne $B_Perms) || ($L_Inode ne $B_Inode) ||
                       ($L_Links ne $B_Links) || ($L_Uid ne $B_Uid) || ($L_Gid ne $B_Gid) ||
                       ($L_CRC ne $B_CRC)))
                     {
                     if($Logging)
                         {
                         # Show the change to CRC/Signature
                         $cmd = sprintf("\"WARNING: [%s] %s [%s]\"\n", $ThisHost, $L_Name,
                                &FindDiff($B_Inode, &ShowPerms($B_Perms),$B_Size, &ctime($B_Time), $B_Uid, $B_Gid, "LINKS", $B_CRC,
                                $B_Name, $L_Inode, &ShowPerms($L_Perms),$L_Size, &ctime($L_Time), $L_Uid, $L_Gid, "LINKS", $L_CRC), $L_Name);
                         system($Logger, @LogFlags, $cmd);
                         }
                     if ((!$Logging) || (($Logging) && ($Reporting)))
                         {
                         printf("\n\tWARNING: [%s] %s\n\t[%s]\n", $ThisHost, $L_Name,
                                &FindDiff($B_Inode, &ShowPerms($B_Perms),$B_Size, &ctime($B_Time), $B_Uid, $B_Gid, "LINKS", $B_CRC,
                                $B_Name, $L_Inode, &ShowPerms($L_Perms),$L_Size, &ctime($L_Time), $L_Uid, $L_Gid, "LINKS", $L_CRC), $L_Name);
                         }
                     # End Logging
                     # Increment # of changes
                ++$Hacks;
                }
            # End Hash check
            elsif ($Reporting)
                {
                if ( ("$type" eq "Files") || (-d $L_Name))
                    { printf("No changes on %s to: %s \n", $ThisHost, $L_Name); }
                }
            }
        else
            {
            # Creation time mode - Check times & permissions & inodes
            if ((!$Hash) && (($L_Time ne $B_Time) || ($L_Size ne $B_Size) ||
               ($L_Perms ne $B_Perms) || ($L_Inode ne $B_Inode) ))
                {
                # Log differences
                if($Logging)
                    {
                    $cmd = sprintf("\"WARNING: [%s] %s [%s]\"\n", $ThisHost, $L_Name,
                        &FindDiff($B_Inode, &ShowPerms($B_Perms),$B_Size, &ctime($B_Time), "UID", "GID", "LINKS", "CRC",
                        $B_Name, $L_Inode, &ShowPerms($L_Perms),$L_Size, &ctime($L_Time), "UID", "GID", "LINKS", "CRC"), $L_Name);
                    system($Logger, @LogFlags, $cmd);
                    }
                if ((!$Logging) || (($Logging) && ($Reporting)))
                    {
                    printf("\n\tWARNING: [%s] %s\n\t[%s]\n", $ThisHost, $L_Name,
                        &FindDiff($B_Inode, &ShowPerms($B_Perms),$B_Size, &ctime($B_Time), "UID", "GID", "LINKS", "CRC",
                        $B_Name, $L_Inode, &ShowPerms($L_Perms),$L_Size, &ctime($L_Time), "UID", "GID", "LINKS", "CRC"), $L_Name);
                    }
                # Increment # of changes
                ++$Hacks;
                }
            # Check hashes in addition to times & permissions & inodes
            elsif (($Hash) && (($L_Time ne $B_Time) || ($L_Size ne $B_Size) ||
                  ($L_Perms ne $B_Perms) || ($L_Inode ne $B_Inode) || ($L_CRC ne $B_CRC)))
                {
                if($Logging)
                    {
                    # Change to CRC/Signature
                    $cmd = sprintf("\"WARNING: [%s] %s [%s]\"\n", $ThisHost, $L_Name,
                        &FindDiff($B_Inode, &ShowPerms($B_Perms),$B_Size, &ctime($B_Time), "UID", "GID", "LINKS", $B_CRC,
                        $B_Name, $L_Inode, &ShowPerms($L_Perms),$L_Size, &ctime($L_Time), "UID", "GID", "LINKS", $L_CRC), $L_Name);
                    system($Logger, @LogFlags, $cmd);
                    }
                if ((!$Logging) || (($Logging) && ($Reporting)))
                    {
                    printf("\n\tWARNING: [%s] %s\n\t[%s]\n", $ThisHost, $L_Name,
                        &FindDiff($B_Inode, &ShowPerms($B_Perms),$B_Size, &ctime($B_Time), "UID", "GID", "LINKS", $B_CRC,
                        $B_Name, $L_Inode, &ShowPerms($L_Perms),$L_Size, &ctime($L_Time), "UID", "GID", "LINKS", $L_CRC), $L_Name);
                    }
                # Increment # of changes
                ++$Hacks;
            }
        elsif ($Reporting)
            {
            if (("$type" eq "Files") || (-d $L_Name))
                { printf("No changes on %s to: %s \n", $ThisHost, $L_Name); }
            }
        }
        # Delete matches in BaseLineData and LiveData so that the values
        #  that remain are added or deleted files
        $BaseLineData{$L_Name} = "";
        $LiveData[$ldd] = "";
    }

    # loop over remaining LiveData elements (ones matching entries in
    # BaseLineData set to empty string)

    # Check for files that have been added
    foreach $Live (@LiveData)
        {
        next if ($Live eq "");
        if ($XTended)
            { ($Inode, $Perms, $NLinks, $Uid, $Gid, $Size, $Time, $Name, $CRC) = split("!", $Live);}
        else
            { ($Inode, $Perms, $Size, $Time, $Name, $CRC) = split("!", $Live); }
    if($Logging)
        {
        if ($XTended)
            {
            $cmd=sprintf("\"ADDITION: [%s] %s  [%s  %s  %s  %s  %s  %s %s  %s]\"\n",
            $ThisHost, $Name, $Inode, &ShowPerms($Perms), $NLinks, $Uid, $Gid, $Size, &ctime($Time));
            }
        else
            {
            $cmd=sprintf("\"ADDITION: [%s] %s  [%s  %s  %s  %s]\"\n",
            $ThisHost, $Name, $Inode, &ShowPerms($Perms), $Size, &ctime($Time));
            }
        system($Logger, @LogFlags, $cmd);
        }
      if ((!$Logging) || (($Logging) && ($Reporting)))
          {
          if ($XTended)
              {
              printf("\n\tADDITION: [%s] %s\n", $ThisHost, $Name);
              printf("\tInode\tPermissons\tNLink\tUid\tGid\tSize\tCreated On\n");
              printf("\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
              $Inode, &ShowPerms($Perms), $NLinks, $Uid, $Gid, $Size, &ctime($Time));
              }
          else
              {
              printf("\n\tADDITION: [%s] %s\n", $ThisHost, $Name);
              printf("\tInode\tPermissons\tSize\tCreated On\n");
              printf("\t%s\t%s\t%s\t%s\n",
              $Inode, &ShowPerms($Perms), $Size, &ctime($Time));
              }
          }
      ++$Hacks;
      }

      # Check for files that have been deleted
      foreach $Base (sort values %BaseLineData)
          {
          next if ($Base eq "");
          if ($XTended)
              { ($Inode, $Perms, $NLinks, $Uid, $Gid, $Size, $Time, $Name, $CRC) = split("!", $Base); }
          else
              { ($Inode, $Perms, $Size, $Time, $Name, $CRC) = split("!", $Base); }
          if($Logging)
              {
              if ($XTended)
                  {
                  $cmd=sprintf("\"DELETION: [%s] %s  [%s  %s  %s  %s  %s  %s %s]\"\n",
                  $ThisHost, $Name, $Inode, &ShowPerms($Perms), $NLinks, $Uid, $Gid, $Size, &ctime($Time));
                  }
              else
                  {
                  $cmd=sprintf("\"DELETION: [%s] %s  [%s  %s  %s  %s]\"\n",
                  $ThisHost, $Name, $Inode, &ShowPerms($Perms), $Size, &ctime($Time));
                  }
              system($Logger, @LogFlags, $cmd);
              }
          if ((!$Logging) || (($Logging) && ($Reporting)))
              {
              if ($XTended)
                  {
                  printf("\n\tDELETION: [%s] %s\n", $ThisHost, $Name);
                  printf("\tInode\tPermissons\tNLink\tUid\tGid\tSize\tCreated On\n");
                  printf("\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", $Inode, &ShowPerms($Perms), $NLinks, $Uid, $Gid, $Size, &ctime($Time));
                  }
              else
                  {
                  printf("\n\tDELETION: [%s] %s\n", $ThisHost, $Name);
                  printf("\tInode\tPermissons\tSize\tCreated On\n");
                  printf("\t%s\t%s\t%s\t%s\n", $Inode, &ShowPerms($Perms), $Size, &ctime($Time));
                  }
              }
            ++$Hacks;
            }
        # Tally failures, compare against 0 to set the return
        $ReportFail += $Hacks;
        }
    else #Build baseline database
        {
        if (("$type" eq "Files"))
            {
            # Build a similar array from the directory as it exists now
            &GetLiveFiles();
            &BuildFileSeg();
            }
        else
            {
            # Build a similar array from the directory as it exists now
            &GetLiveDir($Dir);
            &BuildDirSeg($Dir);
            }
        undef(@BaseLineData);
        undef(@LiveData);
        return(1);
        }
    return($Hacks);
    }



###############################################################################
# &SpecialFileProps($FileName);                                               #
# This routine will get the properties of *nix special files, beginning with  #
# block and character special files                                           #
###############################################################################
sub SpecialFileProps
    {
    local ($filename,$Rdev)=@_;
    local ($properties,$sfptmp,$majmin,$ai,@scratchpad);
    if ((-b "$filename" ) || (-c "$filename" ))
        {
        $majmin=$Rdev;
        if (defined($Filefunc))
            {
            $sfptmp = &ExecHash($Filefunc, $filename);
            (@scratchpad) = split(' ',$sfptmp);
            # it is the one after special, sans the parens
            SCRATCH: for ($ai=0; $ai < $#scratchpad + 1; $ai++)
                {
                if ( $scratchpad[$ai] =~ m/special/i )
                    {
                    $majmin = $scratchpad[$ai + 1];
                    $majmin = substr($majmin,1,length($majmin) -2);
                    last SCRATCH;
                    }
                }
            }

        # If Filefunc not defined, just return rdev
        $properties = $majmin;
        }

    # Return properties
    $properties;
    }



###############################################################################
# &GetFileInfo($FileName);                                                    #
# This routine will build the @LiveData array from the information            #
# it is the guts of the old GetDir, so that individual files can be checked   #
###############################################################################
sub GetFileInfo
    {
    local($filename,@junk)=@_;

    local($Dev,$Inode,$Perms,$NLink,$Uid,$Gid,$Rdev,$Size,$ATime,$MTime,$CTime,$BlkSize,$Blocks);
    local($majmin);
    if ($Verbose)
        { printf("debug: (GetFileInfo) processing %s \n",$filename); }
    # DOS chokes when the root directory gets a double slash prepended
    $filename =~ s/\/\//\//;
    #       0  dev      device number of filesystem
    #       1  ino      inode number
    #       2  mode     file mode  (type and permissions)
    #       3  nlink    number of (hard) links to the file
    #       4  uid      numeric user ID of file's owner
    #       5  gid      numeric group ID of file's owner
    #       6  rdev     the device identifier (special files only)
    #       7  size     total size of file, in bytes
    #       8  atime    last access time since the epoch
    #       9  mtime    last modify time since the epoch
    #      10 ctime    inode change time (NOT creation time!) since the epoch
    #      11 blksize  preferred block size for file system I/O
    #      12 blocks   actual number of blocks allocated
    #      (The epoch was at 00:00 January 1, 1970 GMT.)  Fixed Y2K glitch under DOS
    next if (&Exclude($filename));

    ($Dev,$Inode,$Perms,$NLink,$Uid,$Gid,$Rdev,$Size,$ATime,$MTime,$CTime,$BlkSize,$Blocks) = stat("$filename");

    # Handle links and special files a little bit differently
    if($DOS)
        {
        if($Hash && !-d "$filename" && !-l "$filename")
            {
            $filesig = &ExecHash($HASHFunc, $filename);
            if ($HASHFunc =~ m/md5sum/)
                # Format of md5sum is
                # filesig filename
                { ($filesig) = split(" ", $filesig); }
            elsif ($HASHFunc =~ m/md5/)
                # Format of MD5 is
                # MD5 (filename) = filesig
                { ($md5label,$md5filename,$md5equals,$filesig) = split(" ", $filesig); }
            else
                # Format of most others is
                # filesig filename
                { ($filesig) = split(" ", $filesig); }
#            close(IN);
            }
        else
            { $filesig = "NOCRC"; }
        # Do not check Directories unless "-d" was specified
        #
        if (((($Perms & 0170000) >> 12) != 4) || $DirCheck)
            {
            # DOS names are really all uppercase, so...
            if($DOS)
                { push(@LiveData, join("!", " ", "          ", $Size, $CTime, &toupper($filename), $filesig )); }
            else
                 { push(@LiveData, join("!", $Inode, $Perms, $Size, $CTime, $filename, $filesig)); }

            if (($Verbose) && (!$DOS))
                {
                printf("debug: (GetFileInfo) %s %s %s %s %s %s %s\n",
                $Inode, $Perms, $Month, $Day, $Time, $filename, $filesig);
                }
            if (($Verbose) && ($DOS))
                {
                printf("debug: (GetFileInfo) %s %s %s %s\n",
                $Size, $Time, $filename, $filesig);
                }
            }
        }
    else
        {
        if($Hash)
            {
            # Eliminate things that we don't want to "open" for reading
            if (-p "$filename" ) { $filesig = "FIFO"; }
            elsif (-S "$filename" ) { $filesig = "SOCKET"; }
            elsif (-b "$filename" )
                {
                $majmin = &SpecialFileProps($filename,$Rdev);
                $filesig = "BlockSpecial".':'.$majmin ;
                }
            elsif (-c "$filename" )
                {
                $majmin = &SpecialFileProps($filename,$Rdev);
                $filesig = "CharSpecial".':'.$majmin;
                }
            elsif (-d "$filename" ) { $filesig = "Dir"; }
            elsif (-f "$filename" && !-s "$filename" ) { $filesig = "ZeroLength"; }
            elsif (!-e "$filename" ) { $filesig = "NoSuchFile"; }

            # OK now start looking at signatures
            elsif (-l "$filename" && -s "$filename")
                {
                $filesig = &ExecHash($HASHFunc, $filename);
                $fullsigmsg="$filesig";
                # Check for can't be opened message
                if ( $fullsigmsg !~ m/can.t be opened/)
                    {
                    if ($HASHFunc =~ m/md5sum/)
                        # Format of md5sum is
                        # filesig filename
                        { ($filesig) = split(" ", $filesig); }
                    elsif ($HASHFunc =~ m/md5/)
                        # Format of MD5 is
                        # MD5 (filename) = filesig
                        { ($md5label,$md5filename,$md5equals,$filesig) = split(" ", $filesig); }
                    else
                        # Format of most others is
                        # filesig filename
                        { ($filesig) = split(" ", $filesig); }
                    }
                else
                    { $filesig="CanNotOpen"; }
                $filesig="SYMLINK:"."$filesig";
            }
            elsif (-f "$filename" && -s "$filename")
                {
                $filesig = &ExecHash($HASHFunc, $filename);
                $fullsigmsg="$filesig";
                # Check for can't be opened message
                if ( $fullsigmsg !~ m/can.t be opened/)
                    {
                    if ($HASHFunc =~ m/md5sum/)
                        # Format of md5sum is
                        # filesig filename
                        { ($filesig) = split(" ", $filesig); }
                    elsif ($HASHFunc =~ m/md5/)
                        # Format of MD5 is
                        # MD5 (filename) = filesig
                        { ($md5label,$md5filename,$md5equals,$filesig) = split(" ", $filesig); }
                    else
                        # Format of most others is
                        # filesig filename
                        { ($filesig) = split(" ", $filesig); }
                    }
                else
                    { $filesig="CanNotOpen"; }
                }
            else
                { $filesig = "NOCRC"; }
            }
        else
            { $filesig = "NOCRC"; }
        # DOS names are really all uppercase, so...
        if($DOS)
            { push(@LiveData, join("!", " ", "          ", $Size, $CTime, &toupper($filename), $filesig )); }
        else
            {
            # Match ls -li format
            if($XTended)
                { push(@LiveData, join("!", $Inode, $Perms, $NLink, $Uid, $Gid, $Size, $CTime, $filename, $filesig)); }
            else
                { push(@LiveData, join("!", $Inode, $Perms, $Size, $CTime, $filename, $filesig)); }
            }

        if (($Verbose) && (!$DOS))
            {
            if($XTended)
                {
                printf("debug: (GetFileInfo) %s %s %s %s %s %s %s %s\n",
                $Inode, $Perms, $NLink, $Uid, $Gid, $CTime, $filename, $filesig);
                }
            else
                {
                printf("debug: (GetFileInfo) %s %s %s %s %s\n",
                $Inode, $Perms, $CTime, $filename, $filesig);
                }
            }
            if (($Verbose) && ($DOS))
                {
                printf("debug: (GetFileInfo) %s %s %s %s\n",
                $Size, $CTime, $filename, $filesig);
                }
            }

        }



###############################################################################
# &GetDir($dir, $recurse);                                                    #
# This routine will build the @LiveData array from the information in $dir,   #
# optionally this routine will recurse down that directory tree.              #
###############################################################################
sub GetDir
    {
    local($rootdir, $r)=@_;
    local($filename);
    # Is it a directory?
    if (-d "$rootdir")
        {
        opendir(DIR, $rootdir) || die "debug: (GetDir) No can do ($rootdir)...\n";
            foreach (sort readdir(DIR))
                {
                next if (/^\.\.?$/);
                $filename = $_;
                $filename = "$rootdir/$filename";
                # Root generally can not read a file if it is a link and the link points to
                # a non-existant file. Basically the stat will fail
                next if (!-r "$filename" );

                # DOS chokes when the root directory gets a double slash prepended
                if (!-d "$filename" || (-d "$filename" && $DirCheck )) {&GetFileInfo("$filename");}
                if ((-d "$filename" && !-l "$filename") && ($r)) { &GetDir("$filename", 1); }
                }
            close(DIR);
            }
        else
            { &GetFileInfo("$rootdir"); }
    }



###############################################################################
# $success=&BuildDBIndex();                                                   #
# This small support routine will return the $string in uppercase format.     #
###############################################################################
sub BuildDBIndex
{
    # Data format so that it is both human readible and is all in one file
    # and accomodates individual file
    #  Format
    #  First Line: # - Host *hostname*
    #  Second Line:  # - OS *OS*
    #  Third Line:  # - Database Creation  *date*
    #  Fourth Line is for *IX and is the results of "uname -a"
    #  Fourth Line:  # - Uname *uname*
    #  Fifth Line: # - FCheck vx.x.x by Michael A. Gumienny
    #
    #  Individual files are at the Beginning with the following delimiters
    #  - - - - -> BEGIN FILES < - - - - -
    #  - - - - -> END FILES < - - - - -
    #
    #  Directories boundaries are delimited by
    #  - - - - -> BEGIN Directory *directory_name* < - - - - -
    #                     or
    #  - - - - -> BEGIN Directory Recursion *directory_name* < - - - - -
    #
    # Recursion is only documented, so that the if the config file changes
    #
    # The last line in the file should be
    # - - - - -> END Directories < - - - - -
    #
    local($index);
    if ($Verbose) { printf("debug: (BuildDBIndex) processing %s \n",$filename); }
    $DirFromDB = "initial";
    $FoundEndDir = 2 ;
    $FoundEndFile = 2 ;
    $FilesBegin = -1;
    $FilesEnd = -1;
    for ($index=0; ($Done == 0) && ($index<$#Database + 1); $index++)
        {
        # Skip header info
        next if ($Database[$index] =~ m/^#(-|\s|>)*Database\s*Creation\s*/) ;
        next if ($Database[$index] =~ m/^#(-|\s|>)*Host\s*/) ;
        next if ($Database[$index] =~ m/^#(-|\s|>)*OS\s*/) ;
        next if ($Database[$index] =~ m/^#(-|\s|>)*Uname\s*/) ;
        next if ($Database[$index] =~ m/^#(-|\s|>)*FCheck\s*/) ;
        if ($Database[$index] =~ m/^#(-|\s|>)*BEGIN\s*FILES\s*/)
            {
            $FoundEndFile = 0 ;
            if ($Verbose) { printf("debug: (BuildDBIndex) Individual Files declaration at line %s\n",$index); }
            # Define the elements into the "files" array
            $FilesBegin = $index + 1;
            }
        elsif ($Database[$index] =~ m/^#(-|\s|>)*END\s*FILES\s*/)
            {
            $FilesEnd = $index - 1 ;
            $FoundEndFile = 1 ;
            # Begin processing directories or files
            }
        elsif ($Database[$index] =~ m/^#(-|\s|>)*BEGIN\s*Directory\s*/)
            {
            # Detect delimiter problems
            if ($FoundEndFile == 0) { &Error("Malformed database no ending delimiter line for FILES" ); }
            # Store last line of previous directory
            if ($DirFromDB ne "initial") { $end{"$DirFromDB"} = $index - 1 };
            $FoundEndDir = 0 ;
            $tmp = "$Database[$index]";
            chop($tmp);
            # Chop up the line
            $tmp =~ s/^#(-|\s|>)*BEGIN\s*Directory\s*// ;
            if ($tmp =~ m/^\s*Recursion\s*/)
                {
                $tmp2 = "$tmp";
                $tmp2 =~ s/^\s*Recursion\s*//;
                $tmp2 =~ s/(-|\s|>|<)*$//;
                # From original fcheck - DOS may have heartburn
                $tmp2 =~ s/\//_/g;
                $DirFromDB = "$tmp2";
                $recurse["$DirFromDB"] = 1;
                if ($Verbose) { printf("debug: (BuildDBIndex) Recursive Directory declaration for %s at line %s \n",$DirFromDB,$index); }
                }
            else
                {
                $tmp =~ s/(-|\s|>|<)*$//;
                # From original fcheck - DOS may have heartburn
                $tmp =~ s/\//_/g;
                $DirFromDB = "$tmp";
                if ($Verbose) { printf("debug: (BuildDBIndex) Directory declaration for  %s at line %s \n",$DirFromDB,$index); }
                }
            $begin{"$DirFromDB"} = $index + 1;
            }
        elsif ($Database[$index] =~ m/^#(-|\s|>)*END\s*Directories\s*/)
            {
            if ($DirFromDB ne "initial") { $end{"$DirFromDB"} = $index - 1 };
            $FoundEndDir = 1 ;
            }
        }
    # Detect delimiter problems
    if ($FoundEndDir == 0)
        { &Error("Malformed database no ending delimiter line for Directories" ); }
    }



###############################################################################
# $x=&toupper($string);                                                       #
# This small support routine will return the $string in uppercase format.     #
###############################################################################
sub toupper
    {
    local($x) = @_;
    $x =~ tr/a-z/A-Z/;
    return $x;
    }



###############################################################################
# $x=&ctime($y);                                                              #
# This support routine will return the converted time to human readable format#
# Basically, I'm trying to get away from any functions that may not be in any #
# very minimal PERL distribution.                                             #
###############################################################################
sub ctime
    {
    local($time) = @_;
    local($sec, $min, $hour, $mday, $mon, $year, $wday);

    @WeekDay = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
    @Month   = ('Jan','Feb','Mar','Apr','May','Jun',
                'Jul','Aug','Sep','Oct','Nov','Dec');

    ($sec, $min, $hour, $mday, $mon, $year, $wday) = ($TZ) ? gmtime($time) : localtime($time);
    if ($DOS)
        {
        # Present the times in the traditional DOS way...
        sprintf("%02d-%02d-%02d %02d:%02d%s", $mon, $mday, $year, $hour, $min, ($hour >=12) ? "p" : "a");
        }
    else
        {
        # Present the times in the traditional Unix way...
        # Will anybody still be using this after 2036?
        #$year += ($year < 70) ? 2000 : 1900;
        $year += 1900;
        sprintf("%s %02d %02d:%02d %4d", $Month[$mon], $mday, $hour, $min, $year);
        }
    }



###############################################################################
# $x=&ShowPerms($y);                                                          #
# This routine is a fairly simplistic approach (Hey, it works!) to converting #
# the returned "stat" call values to the more readable "rwx" format of Unix.  #
###############################################################################
sub ShowPerms
    {
    local($mode) = @_;
    if($DOS) { return("\t"); }
    local(@perms) = ("---", "--x",  "-w-",  "-wx",  "r--",  "r-x",  "rw-",  "rwx");
    local(@ftype) = ("?", "p", "c", "?", "d", "?", "b", "?", "-", "?", "l", "?", "s", "?", "?", "?");
    local ($setids) = ($mode & 07000)>>9;
    local (@permstrs) = @perms[($mode & 0700) >> 6, ($mode & 0070) >> 3, ($mode & 0007) >> 0];
    local ($ftype) = $ftype[($mode & 0170000)>>12];
    if ($setids)
        {
        # Sticky Bit?
        if ($setids & 01) { $permstrs[2] =~ s/([-x])$/$1 eq 'x' ? 't' : 'T'/e; }
        # Setuid Bit?
        if ($setids & 04) { $permstrs[0] =~ s/([-x])$/$1 eq 'x' ? 's' : 'S'/e; }
        # Setgid Bit?
        if ($setids & 02) { $permstrs[1] =~ s/([-x])$/$1 eq 'x' ? 's' : 'S'/e; }
        }
    return (join('', $ftype, @permstrs));
    }



###############################################################################
# &Error("string");                                                           #
# This routine prints out critical errors and terminates execution.           #
###############################################################################
sub Error
    {
    printf("%s: %s\nterminating...\n\n", $Me, @_);
    exit(2);
    }



###############################################################################
# $x=&FindDiff($LInode, $LPerms, $LSize, $LTime, $Luid, $Lgid, $LLinks, $LCRC,#
#           $CInode, $CPerms, $CSize, $CTime, $Cuid, $Cgid], $CLinks, $CCRC); #
# This routine will determine the differences between the baseline database   #
# and the current run, and return only thoses differences.                    #
###############################################################################
sub FindDiff
    {
    local($C);
    local($LI, $LP, $LS, $LT, $LU, $LG, $LL, $LC, $CN, $CI, $CP, $CS, $CT, $CU, $CG, $CL, $CC)=@_;

    if ($LI ne $CI) { $C = sprintf("Inodes: %s - %s, ", $LI, $CI); }
    if ($LP ne $CP) { $C = sprintf("%sPermissions: %s - %s, ", $C, $LP, $CP); }
    if ($LS ne $CS) { $C = sprintf("%sSizes: %s - %s, ", $C, $LS, $CS); }
    if ($LT ne $CT) { $C = sprintf("%sTimes: %s - %s, ", $C, $LT, $CT); }
    if ($LU ne $CU) { $C = sprintf("%sUIDs: %s - %s, ", $C, $LU, $CU); }
    if ($LG ne $CG) { $C = sprintf("%sGIDs: %s - %s, ", $C, $LG, $CG); }
    if ($LL ne $CL) { $C = sprintf("%sLinks: %s - %s, ", $C, $LL, $CL); }
    if ($LC ne $CC) { $C = sprintf("%sCRCs: %s - %s, ", $C, $LC, $CC); }

    #printf("WARNING: %s\n", $C);
    # $cmd = sprintf("\"WARNING: [%s] %s [%s]\"\n", $ThisHost, $L_Name,
    #        &FindDiff($B_Inode, &ShowPerms($B_Perms),$B_Size, &ctime($B_Time),
    #        $B_Name, $L_Inode, &ShowPerms($L_Perms),$L_Size, &ctime($L_Time), $L_Name));
    # system($Logger, @LogFlags, $cmd);
    # Quick hack to get this released on time.
    chop($C); chop($C);
    return($C);
    }



###############################################################################
# $Hash=&ExecHash($HASHFunc, $filename);                                      #
# This routine allows us to do a safer hash spawn without generating a shell. #
# This routine is also used by the special properties routine for major/minor #
# number determinations.                                                      #
#                                                                             #
# This also provides a springboard for future expansion of a possible internal#
# MD5 routine, etc...                                                         #
###############################################################################
sub ExecHash
    {
    local($HASHFunc, $filename) = @_;
    local $filesig;

    unless ( defined $HASHFunc )
        { &Error("invalid command $HASHFunc given"); }
    if (open (HASHIN, "-|") )
        {
        $filesig = <HASHIN>;
        close HASHIN;
        }
    else
        { exec ($HASHFunc, $filename); }

    unless ( $filesig )
        { &Error("$HASHFunc was unable to read $filename, or was unable to execute\n"); }
    # Chop the <CR> off the end, do I trust the chpo function?
    # depends on the OS...
    $filesig =~ s/\n$//;
    return $filesig;
    }



###############################################################################
# Main routine starts here.                                                   #
###############################################################################
# Parse the command line for arguments and flags
if($#ARGV==-1){&Help;} # help the user, they forgot the syntax, otherwise...

if(($#ARGV==0) && (@ARGV[0] !~ /^-/))
    { $Dir  = shift(@ARGV); }
else
    {
    foreach $arg (@ARGV)
        {
        if ($Verbose)
            { printf("debug: processing command line - arg %s \t ARGV[0] %s\n",$arg,$ARGV[0]); }
        if ($arg =~ /^-/)
            {
            if ($arg =~ /a/)  { $Auto=1; }
            if ($arg =~ /c/)  { $BaseLine=1; }
            if ($arg =~ /d/)  { $DirCheck=1; }
            if ($arg =~ /f/)  { $Config=1; }
            if ($arg =~ /g/)  { $GnuHASHOut=1; }
            if ($arg =~ /i/)  { $CreateDate=1; }
            if ($arg =~ /h/)  { $UseHostName=1; }
            if ($arg =~ /l/)  { $Logging=1; }
            if ($arg =~ /r/)  { $Reporting=1; }
            if ($arg =~ /s/)  { $Hash=1; }
            if ($arg =~ /v/)  { $Verbose=1; }
            if ($arg =~ /x/)  { $XTended=1; }
            }
        }
    shift(@ARGV);
    if ($Config) { $config = shift(@ARGV); }
    $Dir  = shift(@ARGV);
    }

# Give user syntax help
if (($Dir eq "") && (!$Auto)) { &Help; }

$Dir =~ s/\\/\//g;

if ($BaseLine) { $DirCheck=1; } &Configure;

# Make sure that you have a HASHFunc if you request the hash, otherwise the
# open will try to execute the filename
if($Hash)
{
    if (!(-s  $HASHFunc && -x $HASHFunc))
        { &Error("Signaturing requested with -s switch, but no SIGNATURE program specified in config file"); }
}

# Allow for a higher security mode, where databases are written to one place
# and read from another, with the same config file
# Sanity check is if both are defined
if (defined($ReadDB) && defined($WriteDB)){
        #Only work with the automatic modes
        if (($BaseLine) && ($Auto)) { $DBFile = "$WriteDB"; }
        elsif ((!$BaseLine) && ($Auto)) { $DBFile = "$ReadDB"; }
}

#If a separate Authorization logger is not defined, try to approximate one
if (($Logging) && (!$DOS) && (!defined($ALogger)))
        {
        #Push towards the auth log if this hasn't been defined
        #If you don't like it use the keyword and define it yourself
        $ALogger="${Logger}";
        $ALoggerFlags="${LoggerFlags}";
        foreach $atom (@LogFlags)
            {
            if ($atom =~ m/-p auth/) { $atom =~ s/[a-z0-7]*/auth/; }
            push(@ALogFlags,$atom);
            }
        }
 elsif (($Logging) && (!defined($ALogger)))
        {
        #Mimic normal logger
        $ALogger="${Logger}";
        $ALoggerFlags="${LoggerFlags}";
        (@ALogFlags)=split(' ',$ALoggerFlags);
        }
if ($Verbose) { printf("debug: Processing host [%s]\n", $ThisHost); }

# Handling only one database file now
if ($BaseLine)
  {
     # Open for write
     open (DB, ">$DBFile") || &Error("could not open fcheck database for writing! [$DBFile]: $!");
     printf(DB "# - Host  %s\n",$ThisHost);
     printf(DB "# - OS  %s\n",$ThisOS);
     $#junk = -1;
     (@junk) = stat("$DBFile");
     $DBCTime = $junk[10];
     $#junk = -1;
     printf(DB "# - Database Creation  %s\n",&ctime($DBCTime));
     if (!$DOS) { printf(DB "# - Uname  %s\n",$Uname); }
     printf(DB "# - FCheck by Michael A. Gumienny\n");
  }
else
  {
    #Open for read
    open (DB, "<$DBFile") || &Error("no fcheck database exists! [$DBFile]");
    #Suck the database into an array
    @Database=<DB>;
    close(DB);
    &BuildDBIndex
  }


# Building a baseline is a significant event - syslog it if you can
if (($Logging) && ($BaseLine))
{
  if(!$DOS)
  {
      # All rebuilds are significant
      $cmd=sprintf("\"INFO: Rebuild of the %s database %s begun for %s using config file %s\"\n",$Me,$DBFile,$ThisHost,$config);
      system($ALogger, @ALogFlags, $cmd);
  }
}
$Processing="";
if ($Auto)
  {
  if ($Reporting)
    {
      printf("Configuration: Configuration on %s begins with %s \n", $ThisHost,$config);
      for ($cti=0; $cti < $#ConfigTree + 1; $cti++)
        {
          printf("%s\n", $ConfigTree[$cti]);
        }
        printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
    }
  # Processing files and Directories except files are treated like one directory
  # Make sure we have files to process
  if ($#CheckFile != -1 )
    {
    $Processing="Files";
    if (!$BaseLine)
      {
        if (!$Logging) { printf("\nPROGRESS: validating integrity of Files\nSTATUS: "); }
      }
    if($Verbose) { printf("\nbuilding baseline for Files\n"); }
    if ((!&Scan_Build($Processing)) && (!$Logging)) { printf("passed...\n\n"); }
    undef(@BaseLineData);
    undef(@LiveData);
    }
  else #No FILE directives in config file
    {
    if ((!$BaseLine) && (!$Logging)) { printf("\nPROGRESS: No individual files to validating \n"); }
    if($Verbose) { printf("\nNo Files specified for baseline, check for directories\n"); }
    }
  # Make sure we have directories to process
  if ($#CheckDir != -1 )
    {
    $Processing="Directory";
    foreach $Dir (@CheckDir)
      {
      if (!$BaseLine)
        { if (!$Logging) { printf("\nPROGRESS: validating integrity of %s\nSTATUS:", $Dir); } }
      if($Verbose) { printf("\nbuilding baseline for %s\n", $Dir); }
      if ((!&Scan_Build($Processing)) && (!$Logging)) { printf("passed...\n\n"); }
      undef(@BaseLineData);
      undef(@LiveData);
      }
      printf(DB "# - - - - -> END Directories <- - - - -\n");
     }
   else
     {
     # No DIRECTORY directives in config file
       if ((!$BaseLine) && (!$Logging)) { printf("\nPROGRESS: No directories specified in config file validation \n"); }

        if($Verbose) { printf("\nNo Directories specified for baseline\n"); }
      }
  if ($ReportFail != 0 )
    {
        #Return 1 for not all passes
        exit(1);
    }
  }
else   #Not automatic mode
  {
     if (!$BaseLine)
       {
         if (!$Logging) { printf("\nPROGRESS: validating integrity of %s\nSTATUS: ", $Dir); }
        }
     else #Not automatic, but baselining (included from original fcheck)
       {
         if($Verbose) { printf("\nbuilding baseline for %s\n", $Dir); }
         if (-d $Dir )
           {
             $Processing="Directory";
             &Scan_Build($Processing);
           }
         elsif (-f $Dir )
           {
             $Processing="Files";
             &Scan_Build($Processing);
           }
         else
           {
             if (!$Logging) { printf("\nError: Command line argument: $Dir not a file or directory \n"); }
             &Help;
           }
         }
  }
close(DB);
if (!$DOS) { chmod 0600,$DBFile ; }