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