summaryrefslogtreecommitdiff
path: root/src/Propellor/CmdLine.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Propellor/CmdLine.hs')
-rw-r--r--src/Propellor/CmdLine.hs21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/Propellor/CmdLine.hs b/src/Propellor/CmdLine.hs
index 1298daf2..95a633ec 100644
--- a/src/Propellor/CmdLine.hs
+++ b/src/Propellor/CmdLine.hs
@@ -7,7 +7,7 @@ import System.Environment (getArgs)
import Data.List
import System.Exit
import System.PosixCompat
-import qualified Network.BSD
+import Network.Socket
import Propellor
import Propellor.Gpg
@@ -18,7 +18,6 @@ import Propellor.Types.CmdLine
import qualified Propellor.Property.Docker as Docker
import qualified Propellor.Property.Chroot as Chroot
import qualified Propellor.Shim as Shim
-import Utility.SafeCommand
usage :: Handle -> IO ()
usage h = hPutStrLn h $ unlines
@@ -52,6 +51,7 @@ processCmdLine = go =<< getArgs
_ -> Spin <$> mapM hostname ps <*> pure Nothing
go ("--add-key":k:[]) = return $ AddKey k
go ("--set":f:c:[]) = withprivfield f c Set
+ go ("--unset":f:c:[]) = withprivfield f c Unset
go ("--dump":f:c:[]) = withprivfield f c Dump
go ("--edit":f:c:[]) = withprivfield f c Edit
go ("--list-fields":[]) = return ListFields
@@ -95,6 +95,7 @@ defaultMain hostlist = do
go _ (Continue cmdline) = go False cmdline
go _ Check = return ()
go _ (Set field context) = setPrivData field context
+ go _ (Unset field context) = unsetPrivData field context
go _ (Dump field context) = dumpPrivData field context
go _ (Edit field context) = editPrivData field context
go _ ListFields = listPrivDataFields hostlist
@@ -166,9 +167,15 @@ updateFirst' cmdline next = ifM fetchOrigin
, next
)
+-- Gets the fully qualified domain name, given a string that might be
+-- a short name to look up in the DNS.
hostname :: String -> IO HostName
-hostname s
- | "." `isInfixOf` s = pure s
- | otherwise = do
- h <- Network.BSD.getHostByName s
- return (Network.BSD.hostName h)
+hostname s = go =<< catchDefaultIO [] dnslookup
+ where
+ dnslookup = getAddrInfo (Just canonname) (Just s) Nothing
+ canonname = defaultHints { addrFlags = [AI_CANONNAME] }
+ go (AddrInfo { addrCanonName = Just v } : _) = pure v
+ go _
+ | "." `isInfixOf` s = pure s -- assume it's a fqdn
+ | otherwise =
+ error $ "cannot find host " ++ s ++ " in the DNS"