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