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