Blob Blame History Raw
diff -up firefox-78.0/extensions/pref/autoconfig/src/nsReadConfig.cpp.1170092 firefox-78.0/extensions/pref/autoconfig/src/nsReadConfig.cpp
--- firefox-78.0/extensions/pref/autoconfig/src/nsReadConfig.cpp.1170092	2020-06-17 04:18:58.000000000 +0200
+++ firefox-78.0/extensions/pref/autoconfig/src/nsReadConfig.cpp	2020-06-25 13:45:28.816999491 +0200
@@ -244,8 +244,20 @@ nsresult nsReadConfig::openAndEvaluateJS
     if (NS_FAILED(rv)) return rv;
 
     rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
-    if (NS_FAILED(rv)) return rv;
+    if (NS_FAILED(rv)) {
+      // Look for cfg file in /etc/<application>/pref
+      rv = NS_GetSpecialDirectory(NS_APP_PREFS_SYSTEM_CONFIG_DIR,
+                                  getter_AddRefs(jsFile));
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      rv = jsFile->AppendNative(NS_LITERAL_CSTRING("pref"));
+      NS_ENSURE_SUCCESS(rv, rv);
+      rv = jsFile->AppendNative(nsDependentCString(aFileName));
+      NS_ENSURE_SUCCESS(rv, rv);
 
+      rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
+      NS_ENSURE_SUCCESS(rv, rv);
+    }
   } else {
     nsAutoCString location("resource://gre/defaults/autoconfig/");
     location += aFileName;
diff -up firefox-78.0/modules/libpref/Preferences.cpp.1170092 firefox-78.0/modules/libpref/Preferences.cpp
--- firefox-78.0/modules/libpref/Preferences.cpp.1170092	2020-06-25 13:45:28.818999498 +0200
+++ firefox-78.0/modules/libpref/Preferences.cpp	2020-06-25 13:48:45.996708102 +0200
@@ -4499,6 +4499,8 @@ nsresult Preferences::InitInitialObjects
   //
   // Thus, in the omni.jar case, we always load app-specific default
   // preferences from omni.jar, whether or not `$app == $gre`.
+  // At very end load configuration from system config location:
+  // - /etc/firefox/pref/*.js
 
   nsresult rv = NS_ERROR_FAILURE;
   UniquePtr<nsZipFind> find;
diff -up firefox-78.0/toolkit/xre/nsXREDirProvider.cpp.1170092 firefox-78.0/toolkit/xre/nsXREDirProvider.cpp
--- firefox-78.0/toolkit/xre/nsXREDirProvider.cpp.1170092	2020-06-17 04:20:11.000000000 +0200
+++ firefox-78.0/toolkit/xre/nsXREDirProvider.cpp	2020-06-25 13:48:28.613645633 +0200
@@ -60,6 +60,7 @@
 #endif
 #ifdef XP_UNIX
 #  include <ctype.h>
+#  include "nsIXULAppInfo.h"
 #endif
 #ifdef XP_IOS
 #  include "UIKitDirProvider.h"
@@ -533,6 +534,21 @@ nsXREDirProvider::GetFile(const char* aP
       }
     }
   }
+
+#if defined(XP_UNIX)
+  if (!strcmp(aProperty, NS_APP_PREFS_SYSTEM_CONFIG_DIR)) {
+    nsCString sysConfigDir = NS_LITERAL_CSTRING("/etc/");
+    nsCOMPtr<nsIXULAppInfo> appInfo = do_GetService("@mozilla.org/xre/app-info;1");
+    if (!appInfo)
+      return NS_ERROR_NOT_AVAILABLE;
+    nsCString appName;
+    appInfo->GetName(appName);
+    ToLowerCase(appName);
+    sysConfigDir.Append(appName);
+    return NS_NewNativeLocalFile(sysConfigDir, false, aFile);
+  }
+#endif
+
   if (NS_FAILED(rv) || !file) return NS_ERROR_FAILURE;
 
   if (ensureFilePermissions) {
@@ -845,6 +861,17 @@ nsresult nsXREDirProvider::GetFilesInter
 
     LoadDirIntoArray(mXULAppDir, kAppendPrefDir, directories);
 
+    // Add /etc/<application>/pref/ directory if it exists
+    nsCOMPtr<nsIFile> systemPrefDir;
+    rv = NS_GetSpecialDirectory(NS_APP_PREFS_SYSTEM_CONFIG_DIR,
+                                getter_AddRefs(systemPrefDir));
+    if (NS_SUCCEEDED(rv)) {
+      rv = systemPrefDir->AppendNative(NS_LITERAL_CSTRING("pref"));
+      if (NS_SUCCEEDED(rv)) {
+        directories.AppendObject(systemPrefDir);
+    }
+    }
+
     rv = NS_NewArrayEnumerator(aResult, directories, NS_GET_IID(nsIFile));
   } else if (!strcmp(aProperty, NS_APP_CHROME_DIR_LIST)) {
     // NS_APP_CHROME_DIR_LIST is only used to get default (native) icons
diff -up firefox-78.0/xpcom/io/nsAppDirectoryServiceDefs.h.1170092 firefox-78.0/xpcom/io/nsAppDirectoryServiceDefs.h
--- firefox-78.0/xpcom/io/nsAppDirectoryServiceDefs.h.1170092	2020-06-17 04:20:17.000000000 +0200
+++ firefox-78.0/xpcom/io/nsAppDirectoryServiceDefs.h	2020-06-25 13:45:28.819999502 +0200
@@ -60,6 +60,7 @@
 #define NS_APP_PREFS_DEFAULTS_DIR_LIST "PrefDL"
 #define NS_APP_PREFS_OVERRIDE_DIR \
   "PrefDOverride"  // Directory for per-profile defaults
+#define NS_APP_PREFS_SYSTEM_CONFIG_DIR          "PrefSysConf"   // Directory with system-wide configuration
 
 #define NS_APP_USER_PROFILE_50_DIR "ProfD"
 #define NS_APP_USER_PROFILE_LOCAL_50_DIR "ProfLD"