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