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