225ef2
diff -up firefox-91.0/extensions/pref/autoconfig/src/nsReadConfig.cpp.1170092 firefox-91.0/extensions/pref/autoconfig/src/nsReadConfig.cpp
225ef2
--- firefox-91.0/extensions/pref/autoconfig/src/nsReadConfig.cpp.1170092	2021-07-27 23:29:57.000000000 +0200
225ef2
+++ firefox-91.0/extensions/pref/autoconfig/src/nsReadConfig.cpp	2021-07-29 16:20:44.164513998 +0200
225ef2
@@ -249,8 +249,20 @@ nsresult nsReadConfig::openAndEvaluateJS
225ef2
     if (NS_FAILED(rv)) return rv;
225ef2
 
225ef2
     rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
225ef2
-    if (NS_FAILED(rv)) return rv;
225ef2
+    if (NS_FAILED(rv)) {
225ef2
+      // Look for cfg file in /etc/<application>/pref
225ef2
+      rv = NS_GetSpecialDirectory(NS_APP_PREFS_SYSTEM_CONFIG_DIR,
225ef2
+                                  getter_AddRefs(jsFile));
225ef2
+      NS_ENSURE_SUCCESS(rv, rv);
225ef2
+
225ef2
+      rv = jsFile->AppendNative(nsLiteralCString("pref"));
225ef2
+      NS_ENSURE_SUCCESS(rv, rv);
225ef2
+      rv = jsFile->AppendNative(nsDependentCString(aFileName));
225ef2
+      NS_ENSURE_SUCCESS(rv, rv);
225ef2
 
225ef2
+      rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
225ef2
+      NS_ENSURE_SUCCESS(rv, rv);
225ef2
+    }
225ef2
   } else {
225ef2
     nsAutoCString location("resource://gre/defaults/autoconfig/");
225ef2
     location += aFileName;
225ef2
diff -up firefox-91.0/modules/libpref/Preferences.cpp.1170092 firefox-91.0/modules/libpref/Preferences.cpp
225ef2
--- firefox-91.0/modules/libpref/Preferences.cpp.1170092	2021-07-27 23:30:34.000000000 +0200
225ef2
+++ firefox-91.0/modules/libpref/Preferences.cpp	2021-07-29 16:20:44.166514005 +0200
225ef2
@@ -4553,6 +4553,8 @@ nsresult Preferences::InitInitialObjects
225ef2
   //
225ef2
   // Thus, in the omni.jar case, we always load app-specific default
225ef2
   // preferences from omni.jar, whether or not `$app == $gre`.
225ef2
+  // At very end load configuration from system config location:
225ef2
+  // - /etc/firefox/pref/*.js
225ef2
 
225ef2
   nsresult rv = NS_ERROR_FAILURE;
225ef2
   UniquePtr<nsZipFind> find;
225ef2
diff -up firefox-91.0/toolkit/xre/nsXREDirProvider.cpp.1170092 firefox-91.0/toolkit/xre/nsXREDirProvider.cpp
225ef2
--- firefox-91.0/toolkit/xre/nsXREDirProvider.cpp.1170092	2021-07-27 23:30:56.000000000 +0200
225ef2
+++ firefox-91.0/toolkit/xre/nsXREDirProvider.cpp	2021-07-29 16:26:20.071628932 +0200
225ef2
@@ -71,6 +71,7 @@
225ef2
 #endif
225ef2
 #ifdef XP_UNIX
225ef2
 #  include <ctype.h>
225ef2
+#  include "nsIXULAppInfo.h"
225ef2
 #endif
225ef2
 #ifdef XP_IOS
225ef2
 #  include "UIKitDirProvider.h"
225ef2
@@ -550,6 +551,21 @@ nsXREDirProvider::GetFile(const char* aP
225ef2
       }
225ef2
     }
225ef2
   }
225ef2
+
225ef2
+#if defined(XP_UNIX)
225ef2
+  if (!strcmp(aProperty, NS_APP_PREFS_SYSTEM_CONFIG_DIR)) {
225ef2
+    nsCString sysConfigDir = nsLiteralCString("/etc/");
225ef2
+    nsCOMPtr<nsIXULAppInfo> appInfo = do_GetService("@mozilla.org/xre/app-info;1");
225ef2
+    if (!appInfo)
225ef2
+      return NS_ERROR_NOT_AVAILABLE;
225ef2
+    nsCString appName;
225ef2
+    appInfo->GetName(appName);
225ef2
+    ToLowerCase(appName);
225ef2
+    sysConfigDir.Append(appName);
225ef2
+    return NS_NewNativeLocalFile(sysConfigDir, false, aFile);
225ef2
+  }
225ef2
+#endif
225ef2
+
225ef2
   if (NS_FAILED(rv) || !file) return NS_ERROR_FAILURE;
225ef2
 
225ef2
   if (ensureFilePermissions) {
225ef2
@@ -827,6 +843,16 @@ nsresult nsXREDirProvider::GetFilesInter
225ef2
       LoadDirIntoArray(mXULAppDir, kAppendBackgroundTasksPrefDir, directories);
225ef2
     }
225ef2
 #endif
225ef2
+    // Add /etc/<application>/pref/ directory if it exists
225ef2
+    nsCOMPtr<nsIFile> systemPrefDir;
225ef2
+    rv = NS_GetSpecialDirectory(NS_APP_PREFS_SYSTEM_CONFIG_DIR,
225ef2
+                                getter_AddRefs(systemPrefDir));
225ef2
+    if (NS_SUCCEEDED(rv)) {
225ef2
+      rv = systemPrefDir->AppendNative(nsLiteralCString("pref"));
225ef2
+      if (NS_SUCCEEDED(rv)) {
225ef2
+        directories.AppendObject(systemPrefDir);
225ef2
+      }
225ef2
+    }
225ef2
 
225ef2
     rv = NS_NewArrayEnumerator(aResult, directories, NS_GET_IID(nsIFile));
225ef2
   } else if (!strcmp(aProperty, NS_APP_CHROME_DIR_LIST)) {
225ef2
diff -up firefox-91.0/xpcom/io/nsAppDirectoryServiceDefs.h.1170092 firefox-91.0/xpcom/io/nsAppDirectoryServiceDefs.h
225ef2
--- firefox-91.0/xpcom/io/nsAppDirectoryServiceDefs.h.1170092	2021-07-27 23:31:38.000000000 +0200
225ef2
+++ firefox-91.0/xpcom/io/nsAppDirectoryServiceDefs.h	2021-07-29 16:20:44.168514012 +0200
225ef2
@@ -59,6 +59,7 @@
225ef2
 #define NS_APP_PREFS_DEFAULTS_DIR_LIST "PrefDL"
225ef2
 #define NS_APP_PREFS_OVERRIDE_DIR \
225ef2
   "PrefDOverride"  // Directory for per-profile defaults
225ef2
+#define NS_APP_PREFS_SYSTEM_CONFIG_DIR          "PrefSysConf"   // Directory with system-wide configuration
225ef2
 
225ef2
 #define NS_APP_USER_PROFILE_50_DIR "ProfD"
225ef2
 #define NS_APP_USER_PROFILE_LOCAL_50_DIR "ProfLD"