module DNS (
+ LookupResult,
+ lookupMX',
+ lookupNS',
normalize
)
where
map,
pack )
import Data.Char (toLower)
-import Network.DNS.Types (Domain)
+import Network.DNS (
+ Domain,
+ Resolver,
+ lookupMX,
+ lookupNS )
+
+type LookupResult = (Domain, Maybe [Domain])
+
+lookupMX' :: Resolver -> Domain -> IO LookupResult
+lookupMX' resolver domain =
+ lookupMX resolver domain >>= return . pair_em . drop_priority
+ where
+ drop_priority :: Maybe [(Domain, Int)] -> Maybe [Domain]
+ drop_priority = fmap (map fst)
+
+ pair_em :: a -> (Domain, a)
+ pair_em = (,) domain
+
+-- This function keeps the domain matches with its NS records.
+lookupNS' :: Resolver -> Domain -> IO LookupResult
+lookupNS' resolver domain =
+ lookupNS resolver domain >>= return . pair_em
+ where
+ pair_em :: a -> (Domain, a)
+ pair_em = (,) domain
-- | Normalize the given name by lowercasing and appending a trailing
-- dot (the root) if necessary.
FileOrNumericHost(RCHostName),
ResolvConf(resolvInfo),
defaultResolvConf,
- lookupNS,
makeResolvSeed,
withResolver )
import CommandLine (Args(..), get_args)
-import DNS (normalize)
+import DNS (
+ LookupResult,
+ lookupMX',
+ lookupNS',
+ normalize )
report :: (Domain, Maybe [Domain]) -> IO ()
report (d, Nothing) =
(join " " (map show leftovers))
clean :: [Domain] -- ^ List of delegates, @ds@
- -> (Domain, Maybe [Domain]) -- ^ Pairs of (domain name, lookup result)
- -> (Domain, Maybe [Domain])
+ -> LookupResult
+ -> LookupResult
clean _ p@(_, Nothing) = p
-clean ds (d, Just targets) =
- (d, Just $ targets \\ ds)
+clean delgts (d, Just targets) =
+ (d, Just $ targets \\ delgts)
+
main :: IO ()
Just s -> defaultResolvConf { resolvInfo = RCHostName s }
rs <- makeResolvSeed rc
- withResolver rs $ \resolver -> do
- -- This function keeps the domain matches with its NS records.
- let lookupNS' = \d -> (lookupNS resolver d) >>= (return . ((,) d))
-
- -- Bad stuff happens if we try to run these lookups in parallel
- -- instead of the reports.
- domains_ns <- mapM lookupNS' nrml_domains
- let cdns = map (clean nrml_delegates) domains_ns
-
- _ <- case cfg of
- (NS _ _) ->
- -- We're only checking NS records, so report what we found.
- parallel (map report cdns)
- (MX _ _) ->
- return [()]
-
- stopGlobalPool
+
+ let lookup_function = case cfg of
+ (NS _ _) -> lookupNS'
+ (MX _ _) -> lookupMX'
+
+ _ <- withResolver rs $ \resolver -> do
+ -- Bad stuff happens if we try to run these lookups in parallel
+ -- instead of the reports.
+ records <- mapM (lookup_function resolver) nrml_domains
+ let cleaned_records = map (clean nrml_delegates) records
+ parallel (map report cleaned_records)
+
+ stopGlobalPool