X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FMain.hs;h=5c6f401f7a5e839b6f5545bd4e4bba91cd6b3195;hb=4f6bb3da01e7136f1e17a7d2d28518eefe18fc36;hp=4da383352360ee4a37a552805a5da88897c27c4f;hpb=7d54d3e3e239342eae8b7fda5f5e4fb43adbbde8;p=haeredes.git diff --git a/src/Main.hs b/src/Main.hs index 4da3833..5c6f401 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -11,7 +11,6 @@ import qualified Data.ByteString.Char8 as BS ( words ) import Data.List ((\\)) import Data.String.Utils (join) - import Network.DNS ( Domain, FileOrNumericHost(RCHostName), @@ -19,13 +18,19 @@ import Network.DNS ( defaultResolvConf, makeResolvSeed, withResolver ) +import System.Exit (ExitCode(..), exitWith) +import System.IO (hPutStrLn, stderr) + import CommandLine (Args(..), get_args) import DNS ( LookupResult, lookupMX', lookupNS', - normalize ) + normalize, + normalize_case, + resolve_address ) +import ExitCodes (exit_bad_server) report :: (Domain, Maybe [Domain]) -> IO () report (d, Nothing) = @@ -59,19 +64,32 @@ main = do -- Convert these to ByteStrings. let raw_delegates = map BS.pack (delegates cfg) - -- Normalize the given names and delegates - let nrml_domains = map normalize raw_domains - let nrml_delegates = map normalize raw_delegates + let normalize_function = + if (no_append_root cfg) + then normalize_case + else normalize - let rc = case (server cfg) of - Nothing -> defaultResolvConf - Just s -> defaultResolvConf { resolvInfo = RCHostName s } + -- Normalize the given names and delegates + let nrml_domains = map normalize_function raw_domains + let nrml_delegates = map normalize_function raw_delegates + + rc <- case (server cfg) of + Nothing -> return defaultResolvConf + Just s -> do + s' <- resolve_address s + case s' of + Nothing -> do + hPutStrLn stderr ("Bad DNS server or lookup error: " ++ s) + exitWith (ExitFailure exit_bad_server) + Just s'' -> + return $ defaultResolvConf { resolvInfo = + RCHostName (show s'') } rs <- makeResolvSeed rc let lookup_function = case cfg of - (NS _ _) -> lookupNS' - (MX _ _) -> lookupMX' + (NS _ _ _) -> lookupNS' + (MX _ _ _) -> lookupMX' _ <- withResolver rs $ \resolver -> do -- Bad stuff happens if we try to run these lookups in parallel