812674
diff -up firefox-115.0.2/extensions/pref/autoconfig/src/nsReadConfig.cpp.1170092 firefox-115.0.2/extensions/pref/autoconfig/src/nsReadConfig.cpp
812674
--- firefox-115.0.2/extensions/pref/autoconfig/src/nsReadConfig.cpp.1170092	2023-07-10 21:08:53.000000000 +0200
812674
+++ firefox-115.0.2/extensions/pref/autoconfig/src/nsReadConfig.cpp	2023-07-17 10:33:23.443355156 +0200
812674
@@ -263,8 +263,20 @@ nsresult nsReadConfig::openAndEvaluateJS
7468b5
     if (NS_FAILED(rv)) return rv;
4cf60e
 
7468b5
     rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
7468b5
-    if (NS_FAILED(rv)) return rv;
7468b5
+    if (NS_FAILED(rv)) {
7468b5
+      // Look for cfg file in /etc/<application>/pref
7468b5
+      rv = NS_GetSpecialDirectory(NS_APP_PREFS_SYSTEM_CONFIG_DIR,
7468b5
+                                  getter_AddRefs(jsFile));
7468b5
+      NS_ENSURE_SUCCESS(rv, rv);
4cf60e
+
488d12
+      rv = jsFile->AppendNative(nsLiteralCString("pref"));
7468b5
+      NS_ENSURE_SUCCESS(rv, rv);
7468b5
+      rv = jsFile->AppendNative(nsDependentCString(aFileName));
7468b5
+      NS_ENSURE_SUCCESS(rv, rv);
d417c4
 
7468b5
+      rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
7468b5
+      NS_ENSURE_SUCCESS(rv, rv);
7468b5
+    }
7468b5
   } else {
7468b5
     nsAutoCString location("resource://gre/defaults/autoconfig/");
7468b5
     location += aFileName;
812674
diff -up firefox-115.0.2/modules/libpref/Preferences.cpp.1170092 firefox-115.0.2/modules/libpref/Preferences.cpp
812674
--- firefox-115.0.2/modules/libpref/Preferences.cpp.1170092	2023-07-10 21:09:00.000000000 +0200
812674
+++ firefox-115.0.2/modules/libpref/Preferences.cpp	2023-07-17 10:33:23.444355156 +0200
812674
@@ -4825,6 +4825,9 @@ nsresult Preferences::InitInitialObjects
d417c4
   //
d417c4
   // Thus, in the omni.jar case, we always load app-specific default
d417c4
   // preferences from omni.jar, whether or not `$app == $gre`.
481763
+  //
4cf60e
+  // At very end load configuration from system config location:
4cf60e
+  // - /etc/firefox/pref/*.js
4cf60e
 
727eab
   nsresult rv = NS_ERROR_FAILURE;
e98f2c
   UniquePtr<nsZipFind> find;
812674
diff -up firefox-115.0.2/toolkit/xre/nsXREDirProvider.cpp.1170092 firefox-115.0.2/toolkit/xre/nsXREDirProvider.cpp
812674
--- firefox-115.0.2/toolkit/xre/nsXREDirProvider.cpp.1170092	2023-07-10 22:57:20.000000000 +0200
812674
+++ firefox-115.0.2/toolkit/xre/nsXREDirProvider.cpp	2023-07-17 10:56:25.309692121 +0200
812674
@@ -72,6 +72,7 @@
4cf60e
 #endif
4cf60e
 #ifdef XP_UNIX
727eab
 #  include <ctype.h>
727eab
+#  include "nsIXULAppInfo.h"
4cf60e
 #endif
4cf60e
 #ifdef XP_IOS
727eab
 #  include "UIKitDirProvider.h"
812674
@@ -478,6 +479,17 @@ nsXREDirProvider::GetFile(const char* aP
812674
     rv = file->AppendNative(nsLiteralCString(PREF_OVERRIDE_DIRNAME));
812674
     NS_ENSURE_SUCCESS(rv, rv);
812674
     rv = EnsureDirectoryExists(file);
812674
+  } else if (!strcmp(aProperty, NS_APP_PREFS_SYSTEM_CONFIG_DIR)) {
488d12
+    nsCString sysConfigDir = nsLiteralCString("/etc/");
4cf60e
+    nsCOMPtr<nsIXULAppInfo> appInfo = do_GetService("@mozilla.org/xre/app-info;1");
4cf60e
+    if (!appInfo)
4cf60e
+      return NS_ERROR_NOT_AVAILABLE;
4cf60e
+    nsCString appName;
4cf60e
+    appInfo->GetName(appName);
4cf60e
+    ToLowerCase(appName);
4cf60e
+    sysConfigDir.Append(appName);
812674
+    NS_NewNativeLocalFile(sysConfigDir, false, getter_AddRefs(file));
812674
+    rv = EnsureDirectoryExists(file);
812674
   } else {
812674
     // We don't know anything about this property. Fail without warning, because
812674
     // otherwise we'll get too much warning spam due to
812674
@@ -694,6 +706,16 @@ nsXREDirProvider::GetFiles(const char* a
488d12
     }
488d12
 #endif
481763
 
4cf60e
+    // Add /etc/<application>/pref/ directory if it exists
4cf60e
+    nsCOMPtr<nsIFile> systemPrefDir;
7468b5
+    rv = NS_GetSpecialDirectory(NS_APP_PREFS_SYSTEM_CONFIG_DIR,
7468b5
+                                getter_AddRefs(systemPrefDir));
4cf60e
+    if (NS_SUCCEEDED(rv)) {
488d12
+      rv = systemPrefDir->AppendNative(nsLiteralCString("pref"));
481763
+      if (NS_SUCCEEDED(rv))
4cf60e
+        directories.AppendObject(systemPrefDir);
727eab
+      }
481763
+
727eab
     rv = NS_NewArrayEnumerator(aResult, directories, NS_GET_IID(nsIFile));
7468b5
   } else if (!strcmp(aProperty, NS_APP_CHROME_DIR_LIST)) {
481763
     // NS_APP_CHROME_DIR_LIST is only used to get default (native) icons
812674
diff -up firefox-115.0.2/xpcom/io/nsAppDirectoryServiceDefs.h.1170092 firefox-115.0.2/xpcom/io/nsAppDirectoryServiceDefs.h
812674
--- firefox-115.0.2/xpcom/io/nsAppDirectoryServiceDefs.h.1170092	2023-07-10 21:09:13.000000000 +0200
812674
+++ firefox-115.0.2/xpcom/io/nsAppDirectoryServiceDefs.h	2023-07-17 10:33:23.444355156 +0200
812674
@@ -58,6 +58,7 @@
7468b5
 #define NS_APP_PREFS_DEFAULTS_DIR_LIST "PrefDL"
7468b5
 #define NS_APP_PREFS_OVERRIDE_DIR \
7468b5
   "PrefDOverride"  // Directory for per-profile defaults
4cf60e
+#define NS_APP_PREFS_SYSTEM_CONFIG_DIR          "PrefSysConf"   // Directory with system-wide configuration
4cf60e
 
7468b5
 #define NS_APP_USER_PROFILE_50_DIR "ProfD"
7468b5
 #define NS_APP_USER_PROFILE_LOCAL_50_DIR "ProfLD"