e2c46b
diff -up firefox-58.0/extensions/pref/autoconfig/src/nsReadConfig.cpp.1170092 firefox-58.0/extensions/pref/autoconfig/src/nsReadConfig.cpp
e2c46b
--- firefox-58.0/extensions/pref/autoconfig/src/nsReadConfig.cpp.1170092	2018-01-11 21:17:03.000000000 +0100
e2c46b
+++ firefox-58.0/extensions/pref/autoconfig/src/nsReadConfig.cpp	2018-01-23 13:59:45.446495820 +0100
e2c46b
@@ -239,9 +239,20 @@ nsresult nsReadConfig::openAndEvaluateJS
7b08d5
             return rv;
7b08d5
 
7b08d5
         rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
e2c46b
-        if (NS_FAILED(rv))
7b08d5
-            return rv;
7b08d5
+        if (NS_FAILED(rv)) {
7b08d5
+          // Look for cfg file in /etc/<application>/pref
7b08d5
+          rv = NS_GetSpecialDirectory(NS_APP_PREFS_SYSTEM_CONFIG_DIR,
7b08d5
+                                      getter_AddRefs(jsFile));
7b08d5
+          NS_ENSURE_SUCCESS(rv, rv);
7b08d5
+
7b08d5
+          rv = jsFile->AppendNative(NS_LITERAL_CSTRING("pref"));
7b08d5
+          NS_ENSURE_SUCCESS(rv, rv);
7b08d5
+          rv = jsFile->AppendNative(nsDependentCString(aFileName));
7b08d5
+          NS_ENSURE_SUCCESS(rv, rv);
e2c46b
 
7b08d5
+          rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
7b08d5
+          NS_ENSURE_SUCCESS(rv, rv);
7b08d5
+        }
7b08d5
     } else {
7b08d5
         nsAutoCString location("resource://gre/defaults/autoconfig/");
e2c46b
         location += aFileName;
e2c46b
diff -up firefox-58.0/modules/libpref/Preferences.cpp.1170092 firefox-58.0/modules/libpref/Preferences.cpp
e2c46b
--- firefox-58.0/modules/libpref/Preferences.cpp.1170092	2018-01-23 13:59:45.447495817 +0100
e2c46b
+++ firefox-58.0/modules/libpref/Preferences.cpp	2018-01-23 14:02:51.456987774 +0100
e2c46b
@@ -4402,6 +4402,8 @@ pref_InitInitialObjects()
e2c46b
   //
e2c46b
   // Thus, in the omni.jar case, we always load app-specific default
e2c46b
   // preferences from omni.jar, whether or not `$app == $gre`.
7b08d5
+  // At very end load configuration from system config location:
7b08d5
+  // - /etc/firefox/pref/*.js
7b08d5
 
e2c46b
   nsresult rv;
e2c46b
   nsZipFind* findPtr;
e2c46b
diff -up firefox-58.0/toolkit/xre/nsXREDirProvider.cpp.1170092 firefox-58.0/toolkit/xre/nsXREDirProvider.cpp
e2c46b
--- firefox-58.0/toolkit/xre/nsXREDirProvider.cpp.1170092	2018-01-11 21:17:06.000000000 +0100
e2c46b
+++ firefox-58.0/toolkit/xre/nsXREDirProvider.cpp	2018-01-23 13:59:45.447495817 +0100
e2c46b
@@ -59,6 +59,7 @@
7b08d5
 #endif
7b08d5
 #ifdef XP_UNIX
7b08d5
 #include <ctype.h>
7b08d5
+#include "nsIXULAppInfo.h"
7b08d5
 #endif
7b08d5
 #ifdef XP_IOS
7b08d5
 #include "UIKitDirProvider.h"
e2c46b
@@ -554,6 +555,20 @@ nsXREDirProvider::GetFile(const char* aP
7b08d5
       }
7b08d5
     }
7b08d5
   }
7b08d5
+#if defined(XP_UNIX)
7b08d5
+  if (!strcmp(aProperty, NS_APP_PREFS_SYSTEM_CONFIG_DIR)) {
7b08d5
+    nsCString sysConfigDir = NS_LITERAL_CSTRING("/etc/");
7b08d5
+    nsCOMPtr<nsIXULAppInfo> appInfo = do_GetService("@mozilla.org/xre/app-info;1");
7b08d5
+    if (!appInfo)
7b08d5
+      return NS_ERROR_NOT_AVAILABLE;
7b08d5
+    nsCString appName;
7b08d5
+    appInfo->GetName(appName);
7b08d5
+    ToLowerCase(appName);
7b08d5
+    sysConfigDir.Append(appName);
7b08d5
+    return NS_NewNativeLocalFile(sysConfigDir, false, aFile);
7b08d5
+  }
7b08d5
+#endif
7b08d5
+
7b08d5
   if (NS_FAILED(rv) || !file)
7b08d5
     return NS_ERROR_FAILURE;
7b08d5
 
e2c46b
@@ -887,6 +902,14 @@ nsXREDirProvider::GetFilesInternal(const
7b08d5
     LoadDirIntoArray(mXULAppDir, kAppendPrefDir, directories);
7b08d5
     LoadDirsIntoArray(mAppBundleDirectories,
7b08d5
                       kAppendPrefDir, directories);
7b08d5
+    // Add /etc/<application>/pref/ directory if it exists
7b08d5
+    nsCOMPtr<nsIFile> systemPrefDir;
7b08d5
+    rv = NS_GetSpecialDirectory(NS_APP_PREFS_SYSTEM_CONFIG_DIR, getter_AddRefs(systemPrefDir));
7b08d5
+    if (NS_SUCCEEDED(rv)) {
7b08d5
+      rv = systemPrefDir->AppendNative(NS_LITERAL_CSTRING("pref"));
7b08d5
+      if (NS_SUCCEEDED(rv))
7b08d5
+        directories.AppendObject(systemPrefDir);
7b08d5
+    }
7b08d5
 
7b08d5
     rv = NS_NewArrayEnumerator(aResult, directories);
7b08d5
   }
e2c46b
diff -up firefox-58.0/xpcom/io/nsAppDirectoryServiceDefs.h.1170092 firefox-58.0/xpcom/io/nsAppDirectoryServiceDefs.h
e2c46b
--- firefox-58.0/xpcom/io/nsAppDirectoryServiceDefs.h.1170092	2018-01-23 13:59:45.447495817 +0100
e2c46b
+++ firefox-58.0/xpcom/io/nsAppDirectoryServiceDefs.h	2018-01-23 14:02:02.871120476 +0100
e2c46b
@@ -59,6 +59,7 @@
e2c46b
 #define NS_APP_PREFS_50_FILE                    "PrefF"
7b08d5
 #define NS_APP_PREFS_DEFAULTS_DIR_LIST          "PrefDL"
7b08d5
 #define NS_APP_PREFS_OVERRIDE_DIR               "PrefDOverride" // Directory for per-profile defaults
7b08d5
+#define NS_APP_PREFS_SYSTEM_CONFIG_DIR          "PrefSysConf"   // Directory with system-wide configuration
7b08d5
 
7b08d5
 #define NS_APP_USER_PROFILE_50_DIR              "ProfD"
7b08d5
 #define NS_APP_USER_PROFILE_LOCAL_50_DIR        "ProfLD"