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