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