From 91ce6e0f3898b08eec2ec7e6e8c3d31c12d941ab Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 7 Mar 2016 12:16:24 -0400 Subject: improve filtering of interface files --- src/Propellor/Property/Network.hs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/Propellor/Property') 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 -- cgit v1.2.3