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