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