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