From 48ca5d1e423b5a3ac78d25c2252f7a45bacc7474 Mon Sep 17 00:00:00 2001 From: FĂ©lix Sipma Date: Mon, 7 Mar 2016 15:01:45 +0100 Subject: Network: escape interfaceDFile names (cherry picked from commit 125135ea5d42d623346a385faf7ed404f8878891) --- src/Propellor/Property/Network.hs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/Propellor') diff --git a/src/Propellor/Property/Network.hs b/src/Propellor/Property/Network.hs index 1908bbb3..0d079899 100644 --- a/src/Propellor/Property/Network.hs +++ b/src/Propellor/Property/Network.hs @@ -45,7 +45,7 @@ dhcp iface = hasContent (interfaceDFile iface) -- -- If the interface file already exists, this property does nothing, -- no matter its content. --- +-- -- (ipv6 addresses are not included because it's assumed they come up -- automatically in most situations.) static :: Interface -> Property NoInfo @@ -96,8 +96,19 @@ 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 iface = "/etc/network/interfaces.d" iface +interfaceDFile i = interfaceDFile' (escapeInterfaceDName i) + +interfaceDFile' :: Interface -> FilePath +interfaceDFile' iface = "/etc/network/interfaces.d" iface + +escapeInterfaceDName :: Interface -> FilePath +escapeInterfaceDName "" = "" +escapeInterfaceDName (':' : xs) = escapeInterfaceDName xs +escapeInterfaceDName ('.' : xs) = escapeInterfaceDName xs +escapeInterfaceDName (x : xs) = x : escapeInterfaceDName xs -- | Ensures that files in the the interfaces.d directory are used. interfacesDEnabled :: Property NoInfo -- cgit v1.2.3