#!/usr/bin/perl
##############################################################################
# Copyright (C) 1999, 2000 Jay Beale
# Licensed under the GNU General Public License
#
# 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 the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#############################################################################

##############################################################################
# This is the Back End to Bastille Linux, a hardening program for Linux.     #
# Its counterpart is found in the InteractiveBastille or AutomatedBastille   #
# program, which writes the configuration file used for this.                #
#                                                                            #
# The Bastille Front End and Back End were written by and are currently      #
# maintained by Bastille Linux's Lead Developer, Jay Beale.                  #
#                                                                            #
# The original content for Bastille was assembled by Jay Beale using many    #
# documents, including SANS' Securing Linux Step by Step, Kurt Seifried's    #
# Linux Administrators Security Guide, and many other pieces, including the  #
# Security HOWTO, the Unix Security Handbook, the Solaris Security FAQ and   #
# various magazine articles in LinuxWorld and SunWorld.                      #
#                                                                            #
##############################################################################


## Our use of modules is somewhat strange for Perl: we have a main routine
## in each module which runs on the "use" command.

use lib "/usr/lib";
push (@INC,"/usr/lib/perl5/site_perl/");
push (@INC,"/usr/lib/Bastille");

use Getopt::Long;
require Bastille::API;
import Bastille::API;

if( ! Getopt::Long::GetOptions(
    "d"     => \$nodisclaim) ) {
    $error = 1; # parse error
} else {
    $error = 0; # no parse error
}

if (( @ARGV ) || ( $error)) { # GetOptions didn't parse all of the args
    &ErrorLog("Error encountered while parsing command line options.");
}

&PrepareToRun;
&showDisclaimer($nodisclaim);

#######################################################################
##     Network Interface Protection/IPCHAINS/Personal Firewalling    ##
#######################################################################
if(exists $GLOBAL_CONFIG{Firewall}){
    print "Executing Firewall Specific Configuration\n";
    require Bastille::Firewall;
    import Bastille::Firewall;
}

#######################################################################
##                      Port Scan Attack Detection                   ##
#######################################################################

if(exists $GLOBAL_CONFIG{PSAD}){
    print "Executing PSAD Specific Configuration\n";
    require Bastille::PSAD;
    import Bastille::PSAD;
}

#######################################################################
##                            File Permissions                       ##
#######################################################################
if(exists $GLOBAL_CONFIG{FilePermissions}){
    print "Executing File Permissions Specific Configuration\n";
    require Bastille::FilePermissions;
    import Bastille::FilePermissions;
}

#######################################################################
##                     Account Creation/Security                     ##
#######################################################################
if(exists $GLOBAL_CONFIG{AccountSecurity}){
    print "Executing Account Security Specific Configuration\n";
    require Bastille::AccountSecurity;
    import Bastille::AccountSecurity; 
}

#######################################################################
##                Protecting LILO and single user mode               ##
#######################################################################
if(exists $GLOBAL_CONFIG{BootSecurity}){
    print "Executing Boot Security Specific Configuration\n";
    require Bastille::BootSecurity;
    import Bastille::BootSecurity;
}

#######################################################################
##                    inetd / TCP Wrappers Configuration             ##
#######################################################################

if(exists $GLOBAL_CONFIG{SecureInetd}){
    print "Executing Inetd Specific Configuration\n";
    require  Bastille::SecureInetd; 
    import Bastille::SecureInetd;
}

#######################################################################
##                      Disabling of User Space Tools                ##
#######################################################################
if(exists $GLOBAL_CONFIG{DisableUserTools}){
    print "Executing User Tool Specific Configuration\n";
    require Bastille::DisableUserTools;   
    import Bastille::DisableUserTools;
}

#######################################################################
##    Misc. Pluggable Authentication Modules (PAM) Configuration     ##
#######################################################################

if(exists $GLOBAL_CONFIG{ConfigureMiscPAM}){
    print "Executing PAM Specific Configuration\n";
    require Bastille::ConfigureMiscPAM; 
    import Bastille::ConfigureMiscPAM;
}

#######################################################################
##                               Logging                             ##
#######################################################################
if(exists $GLOBAL_CONFIG{Logging}){
    print "Executing Logging Specific Configuration\n";
    require  Bastille::Logging; 
    import Bastille::Logging;
}

#######################################################################
#######################################################################
####                            System Daemons                     ####
#######################################################################
#######################################################################

#######################################################################
##                          Miscellaneous Daemons                    ##
#######################################################################
if(exists $GLOBAL_CONFIG{MiscellaneousDaemons}){
    print "Executing Daemon Specific Configuration\n";
    require  Bastille::MiscellaneousDaemons;  
    import Bastille::MiscellaneousDaemons;
}

#######################################################################
##                               Sendmail                            ##
#######################################################################
if(exists $GLOBAL_CONFIG{Sendmail}){
    print "Executing Sendmail Specific Configuration\n";
    require Bastille::Sendmail; 
    import Bastille::Sendmail;
}

#######################################################################
##                            Remote Access                          ##
#######################################################################

# version 1.2.0 -- removed this module temporarily from run -- let's
# 		   make this smarter
#
#use Bastille::RemoteAccess;

#######################################################################
##                             DNS/BIND/NAMED                        ##
#######################################################################
if(exists $GLOBAL_CONFIG{DNS}){
    print "Executing DNS Specific Configuration\n";
    require Bastille::DNS;  
    import Bastille::DNS;
}

#######################################################################
##                              HTTP/APACHE                          ##
#######################################################################
if(exists $GLOBAL_CONFIG{Apache}){
    print "Executing Apache Specific Configuration\n";
    require  Bastille::Apache; 
    import Bastille::Apache; 
}

#######################################################################
##                                lpr/lpd                            ##
#######################################################################
if(exists $GLOBAL_CONFIG{Printing}){
    print "Executing Printing Specific Configuration\n";
    require  Bastille::Printing;
    import Bastille::Printing;
}

#######################################################################
##                                  FTP                              ##
#######################################################################

if(exists $GLOBAL_CONFIG{FTP}){
    print "Executing FTP Specific Configuration\n";
    require Bastille::FTP;
    import Bastille::FTP; 
}

#######################################################################
##                                 TMPDIR			    ## 
#######################################################################
if(exists $GLOBAL_CONFIG{TMPDIR}){
    print "Executing Temporary Directory Specific Configuration\n";
    require Bastille::TMPDIR;
    import Bastille::TMPDIR; 
}

#######################################################################
##                            HP-UX OS Specific                      ##
#######################################################################
if(exists $GLOBAL_CONFIG{HP_UX}){
    print "Executing HP-UX Specific Configuration\n";
    require Bastille::HP_UX;
    import Bastille::HP_UX; 
}

#######################################################################
##            HP-UX Security Patch Check Configuration               ##
#######################################################################
if(exists $GLOBAL_CONFIG{Patches}){
    print "Executing HP-UX's Security Patch Check Configuration\n";
    require Bastille::Patches;
    import Bastille::Patches;
}

#######################################################################
##                            Patch Download                         ##
#######################################################################
# Note: currently comented since both RedHat and Debian implementations
# do not work ok.

#use Bastille::PatchDownload;



