#!/usr/bin/perl ##=====================================================================## ## Copyright (C) 2001-2002 Stephen Zarkos. All rights reserved. ## Obsid@Sentry.net ## ## Please see file: COPYRIGHT for further copyright information and ## disclaimer. Or online at http://www.SentryFirewall.com/files/COPYRIGHT ##=====================================================================## ## File: get_config.pl sub get_config { my($config) = "$_[0]"; my($status) = "0"; my($dev) = ''; ## Attempt to mount /dev/fd0 $m_point = '/floppy'; $device = '/dev/fd0'; ## Test to see if there is a floppy in the drive. ## Thanks to Stefan Andersson for this. if (system("/bin/dd if=$device of=/dev/null bs=1 count=1 1>/dev/null 2>/dev/null") == "0") { ## Disk present, attempt to mount $device on $m_point $status = &mount('/sbin/mount',"$device","$m_point",'1'); if (($status eq "0") || ($status eq "2")) { ## Attempt to mount again $status = &mount('/sbin/mount',"$device","$m_point",'2'); } } else { ## Disk not present $status = "0"; } ## If unable to mount floppy, try mounting /dev/hda1 if ($status ne '1') { $m_point = '/mnt'; $device = '/dev/hda1'; if (system("/bin/dd if=$device of=/dev/null bs=1 count=1 1>/dev/null 2>/dev/null") == "0") { ## Disk present, attempt to mount $device on $m_point $status = &mount('/sbin/mount',"$device","$m_point",'1'); } else { ## Disk not present $status = "0"; } } ## Check $status now. If it's not 1, then we've failed ## to mount anything. if ($status ne '1') { $device = ''; return 0; } ## I guess mount succeeded. &do_log("Mounted ${device} on ${m_point}."); open(CONF,"<$m_point/$config") or return 0; @conf = ; close(CONF); return 1; } ## End sub get_config sub mount { $SIG{ALRM} = sub { die "TIMEOUT" }; my $command = "$_[0]"; my $dev = "$_[1]"; my $m_point = "$_[2]"; my $num = "$_[3]"; print "Attempting to mount $dev, attempt $num..."; eval { alarm(10); ## Set timeout to 10 seconds. system("$command -r -n $dev $m_point 1>/dev/null 2>/dev/null"); alarm(0); }; if ($@) { if ($@ =~ /TIMEOUT/) { ## Command timed out print " Timed Out\n"; return 2; ## Timed Out } else { alarm(0); print " Unknown Exception: $@\n"; return 0; ## Return Error } } if (($?) && ($? gt "0")) { ## Something went wrong ## Do something productive print " Error: $?\n"; return 0; ## Return Error } else { sleep(1); print " Done.\n"; return 1; Return Success } } ## End sub mount return 1; ## _EOF_ ##