d2e479
diff -up firefox-87.0/extensions/pref/autoconfig/src/nsReadConfig.cpp.1170092 firefox-87.0/extensions/pref/autoconfig/src/nsReadConfig.cpp
d2e479
--- firefox-87.0/extensions/pref/autoconfig/src/nsReadConfig.cpp.1170092	2021-03-18 14:48:36.000000000 +0100
d2e479
+++ firefox-87.0/extensions/pref/autoconfig/src/nsReadConfig.cpp	2021-03-22 19:20:02.429310184 +0100
155c30
@@ -249,8 +249,20 @@ nsresult nsReadConfig::openAndEvaluateJS
155c30
     if (NS_FAILED(rv)) return rv;
155c30
 
155c30
     rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
155c30
-    if (NS_FAILED(rv)) return rv;
155c30
+    if (NS_FAILED(rv)) {
155c30
+      // Look for cfg file in /etc/<application>/pref
155c30
+      rv = NS_GetSpecialDirectory(NS_APP_PREFS_SYSTEM_CONFIG_DIR,
155c30
+                                  getter_AddRefs(jsFile));
155c30
+      NS_ENSURE_SUCCESS(rv, rv);
155c30
+
155c30
+      rv = jsFile->AppendNative(nsLiteralCString("pref"));
155c30
+      NS_ENSURE_SUCCESS(rv, rv);
155c30
+      rv = jsFile->AppendNative(nsDependentCString(aFileName));
155c30
+      NS_ENSURE_SUCCESS(rv, rv);
155c30
 
155c30
+      rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
155c30
+      NS_ENSURE_SUCCESS(rv, rv);
155c30
+    }
155c30
   } else {
155c30
     nsAutoCString location("resource://gre/defaults/autoconfig/");
155c30
     location += aFileName;
d2e479
diff -up firefox-87.0/modules/libpref/Preferences.cpp.1170092 firefox-87.0/modules/libpref/Preferences.cpp
d2e479
--- firefox-87.0/modules/libpref/Preferences.cpp.1170092	2021-03-18 14:48:54.000000000 +0100
d2e479
+++ firefox-87.0/modules/libpref/Preferences.cpp	2021-03-22 19:20:02.429310184 +0100
d2e479
@@ -4499,6 +4499,9 @@ nsresult Preferences::InitInitialObjects
155c30
   //
155c30
   // Thus, in the omni.jar case, we always load app-specific default
155c30
   // preferences from omni.jar, whether or not `$app == $gre`.
d2e479
+  //
155c30
+  // At very end load configuration from system config location:
155c30
+  // - /etc/firefox/pref/*.js
155c30
 
155c30
   nsresult rv = NS_ERROR_FAILURE;
155c30
   UniquePtr<nsZipFind> find;
d2e479
diff -up firefox-87.0/toolkit/xre/nsXREDirProvider.cpp.1170092 firefox-87.0/toolkit/xre/nsXREDirProvider.cpp
d2e479
--- firefox-87.0/toolkit/xre/nsXREDirProvider.cpp.1170092	2021-03-18 14:52:00.000000000 +0100
d2e479
+++ firefox-87.0/toolkit/xre/nsXREDirProvider.cpp	2021-03-22 19:37:56.574480347 +0100
d2e479
@@ -65,6 +65,7 @@
155c30
 #endif
155c30
 #ifdef XP_UNIX
155c30
 #  include <ctype.h>
155c30
+#  include "nsIXULAppInfo.h"
155c30
 #endif
155c30
 #ifdef XP_IOS
155c30
 #  include "UIKitDirProvider.h"
d2e479
@@ -552,6 +553,21 @@ nsXREDirProvider::GetFile(const char* aP
155c30
       }
155c30
     }
155c30
   }
155c30
+
155c30
+#if defined(XP_UNIX)
155c30
+  if (!strcmp(aProperty, NS_APP_PREFS_SYSTEM_CONFIG_DIR)) {
155c30
+    nsCString sysConfigDir = nsLiteralCString("/etc/");
155c30
+    nsCOMPtr<nsIXULAppInfo> appInfo = do_GetService("@mozilla.org/xre/app-info;1");
155c30
+    if (!appInfo)
155c30
+      return NS_ERROR_NOT_AVAILABLE;
155c30
+    nsCString appName;
155c30
+    appInfo->GetName(appName);
155c30
+    ToLowerCase(appName);
155c30
+    sysConfigDir.Append(appName);
155c30
+    return NS_NewNativeLocalFile(sysConfigDir, false, aFile);
155c30
+  }
155c30
+#endif
155c30
+
155c30
   if (NS_FAILED(rv) || !file) return NS_ERROR_FAILURE;
155c30
 
155c30
   if (ensureFilePermissions) {
d2e479
@@ -874,6 +890,16 @@ nsresult nsXREDirProvider::GetFilesInter
155c30
     }
155c30
 #endif
d2e479
 
155c30
+    // Add /etc/<application>/pref/ directory if it exists
155c30
+    nsCOMPtr<nsIFile> systemPrefDir;
155c30
+    rv = NS_GetSpecialDirectory(NS_APP_PREFS_SYSTEM_CONFIG_DIR,
155c30
+                                getter_AddRefs(systemPrefDir));
155c30
+    if (NS_SUCCEEDED(rv)) {
155c30
+      rv = systemPrefDir->AppendNative(nsLiteralCString("pref"));
d2e479
+      if (NS_SUCCEEDED(rv))
155c30
+        directories.AppendObject(systemPrefDir);
155c30
+      }
d2e479
+
155c30
     rv = NS_NewArrayEnumerator(aResult, directories, NS_GET_IID(nsIFile));
155c30
   } else if (!strcmp(aProperty, NS_APP_CHROME_DIR_LIST)) {
d2e479
     // NS_APP_CHROME_DIR_LIST is only used to get default (native) icons
d2e479
diff -up firefox-87.0/xpcom/io/nsAppDirectoryServiceDefs.h.1170092 firefox-87.0/xpcom/io/nsAppDirectoryServiceDefs.h
d2e479
--- firefox-87.0/xpcom/io/nsAppDirectoryServiceDefs.h.1170092	2021-03-18 14:51:58.000000000 +0100
d2e479
+++ firefox-87.0/xpcom/io/nsAppDirectoryServiceDefs.h	2021-03-22 19:20:02.430310213 +0100
155c30
@@ -59,6 +59,7 @@
155c30
 #define NS_APP_PREFS_DEFAULTS_DIR_LIST "PrefDL"
155c30
 #define NS_APP_PREFS_OVERRIDE_DIR \
155c30
   "PrefDOverride"  // Directory for per-profile defaults
155c30
+#define NS_APP_PREFS_SYSTEM_CONFIG_DIR          "PrefSysConf"   // Directory with system-wide configuration
155c30
 
155c30
 #define NS_APP_USER_PROFILE_50_DIR "ProfD"
155c30
 #define NS_APP_USER_PROFILE_LOCAL_50_DIR "ProfLD"