Quote values in .ini file
[shpub.git] / src / shpub / Config.php
index 044b1504ab4ff87c7b21621d079e4187176bb155..d41e45dc2a3495179fb797eb185d471a0b8e015f 100644 (file)
@@ -15,6 +15,7 @@ class Config
     protected function getConfigFilePath()
     {
         if (!isset($_SERVER['HOME'])) {
+            Log::err('Cannot determine home directory');
             return false;
         }
 
@@ -64,13 +65,14 @@ class Config
                 if ($hostVal == '') {
                     continue;
                 }
-                $str .= $hostProp . '=' . $hostVal . "\n";
+                $str .= $hostProp
+                    . '=' . static::quoteIniValue($hostVal) . "\n";
             }
         }
         $cfgFilePath = $this->getConfigFilePath();
         $cfgDir = dirname($cfgFilePath);
         if (!is_dir($cfgDir)) {
-            mkdir($cfgDir);
+            mkdir($cfgDir, 0700);
         }
         file_put_contents($cfgFilePath, $str);
         //contains sensitive data; nobody else may read that
@@ -104,5 +106,13 @@ class Config
         }
         return null;
     }
+
+    public static function quoteIniValue($val)
+    {
+        if (strpos($val, '=') === false) {
+            return $val;
+        }
+        return '"' . $val . '"';
+    }
 }
 ?>