summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess2016-03-07 12:16:24 -0400
committerJoey Hess2016-03-07 12:16:24 -0400
commit91ce6e0f3898b08eec2ec7e6e8c3d31c12d941ab (patch)
tree1abe24ff22504f303201e3f7db1ed373c089e30b
parent48ca5d1e423b5a3ac78d25c2252f7a45bacc7474 (diff)
improve filtering of interface files
-rw-r--r--src/Propellor/Property/Network.hs16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/Propellor/Property/Network.hs b/src/Propellor/Property/Network.hs
index 0d079899..382f5d9d 100644
--- a/src/Propellor/Property/Network.hs
+++ b/src/Propellor/Property/Network.hs
@@ -3,6 +3,8 @@ module Propellor.Property.Network where
import Propellor.Base
import Propellor.Property.File
+import Data.Char
+
type Interface = String
ifUp :: Interface -> Property NoInfo
@@ -96,19 +98,13 @@ interfacesFile :: FilePath
interfacesFile = "/etc/network/interfaces"
-- | A file in the interfaces.d directory.
--- /etc/network/interfaces.d/ files have to match -- ^[a-zA-Z0-9_-]+$
--- see "man 5 interfaces"
interfaceDFile :: Interface -> FilePath
-interfaceDFile i = interfaceDFile' (escapeInterfaceDName i)
-
-interfaceDFile' :: Interface -> FilePath
-interfaceDFile' iface = "/etc/network/interfaces.d" </> iface
+interfaceDFile i = "/etc/network/interfaces.d" </> escapeInterfaceDName i
+-- | /etc/network/interfaces.d/ files have to match -- ^[a-zA-Z0-9_-]+$
+-- see "man 5 interfaces"
escapeInterfaceDName :: Interface -> FilePath
-escapeInterfaceDName "" = ""
-escapeInterfaceDName (':' : xs) = escapeInterfaceDName xs
-escapeInterfaceDName ('.' : xs) = escapeInterfaceDName xs
-escapeInterfaceDName (x : xs) = x : escapeInterfaceDName xs
+escapeInterfaceDName = filter (\c -> isAscii c && (isAlphaNum c || c `elem` "_-"))
-- | Ensures that files in the the interfaces.d directory are used.
interfacesDEnabled :: Property NoInfo