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