a8a561
diff -up firefox-45.0.1/extensions/pref/autoconfig/src/nsReadConfig.cpp.1170092 firefox-45.0.1/extensions/pref/autoconfig/src/nsReadConfig.cpp
a8a561
--- firefox-45.0.1/extensions/pref/autoconfig/src/nsReadConfig.cpp.1170092	2016-03-15 23:37:54.000000000 +0100
a8a561
+++ firefox-45.0.1/extensions/pref/autoconfig/src/nsReadConfig.cpp	2016-03-21 16:10:42.540417899 +0100
a8a561
@@ -245,8 +245,20 @@ nsresult nsReadConfig::openAndEvaluateJS
a8a561
             return rv;
a8a561
 
a8a561
         rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
a8a561
-        if (NS_FAILED(rv)) 
a8a561
-            return rv;
a8a561
+        if (NS_FAILED(rv)) {
a8a561
+          // Look for cfg file in /etc/<application>/pref
a8a561
+          rv = NS_GetSpecialDirectory(NS_APP_PREFS_SYSTEM_CONFIG_DIR,
a8a561
+                                      getter_AddRefs(jsFile));
a8a561
+          NS_ENSURE_SUCCESS(rv, rv);
a8a561
+
a8a561
+          rv = jsFile->AppendNative(NS_LITERAL_CSTRING("pref"));
a8a561
+          NS_ENSURE_SUCCESS(rv, rv);
a8a561
+          rv = jsFile->AppendNative(nsDependentCString(aFileName));
a8a561
+          NS_ENSURE_SUCCESS(rv, rv);
a8a561
+
a8a561
+          rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
a8a561
+          NS_ENSURE_SUCCESS(rv, rv);
a8a561
+        }
a8a561
 
a8a561
     } else {
a8a561
         nsAutoCString location("resource://gre/defaults/autoconfig/");
a8a561
diff -up firefox-45.0.1/modules/libpref/Preferences.cpp.1170092 firefox-45.0.1/modules/libpref/Preferences.cpp
a8a561
--- firefox-45.0.1/modules/libpref/Preferences.cpp.1170092	2016-03-21 16:10:42.540417899 +0100
a8a561
+++ firefox-45.0.1/modules/libpref/Preferences.cpp	2016-03-21 16:13:29.145888710 +0100
a8a561
@@ -1214,6 +1214,8 @@ static nsresult pref_InitInitialObjects(
a8a561
   // - jar:$gre/omni.jar!/defaults/preferences/*.js
a8a561
   // Thus, in omni.jar case, we always load app-specific default preferences
a8a561
   // from omni.jar, whether or not $app == $gre.
a8a561
+  // At very end load configuration from system config location:
a8a561
+  // - /etc/firefox/pref/*.js
a8a561
 
a8a561
   nsZipFind *findPtr;
a8a561
   nsAutoPtr<nsZipFind> find;
a8a561
diff -up firefox-45.0.1/toolkit/xre/nsXREDirProvider.cpp.1170092 firefox-45.0.1/toolkit/xre/nsXREDirProvider.cpp
a8a561
--- firefox-45.0.1/toolkit/xre/nsXREDirProvider.cpp.1170092	2016-03-15 23:37:46.000000000 +0100
a8a561
+++ firefox-45.0.1/toolkit/xre/nsXREDirProvider.cpp	2016-03-21 16:12:06.498655156 +0100
a8a561
@@ -51,6 +51,7 @@
a8a561
 #endif
a8a561
 #ifdef XP_UNIX
a8a561
 #include <ctype.h>
a8a561
+#include "nsIXULAppInfo.h"
a8a561
 #endif
a8a561
 #ifdef XP_IOS
a8a561
 #include "UIKitDirProvider.h"
a8a561
@@ -457,6 +458,20 @@ nsXREDirProvider::GetFile(const char* aP
a8a561
       }
a8a561
     }
a8a561
   }
a8a561
+#if defined(XP_UNIX)
a8a561
+  if (!strcmp(aProperty, NS_APP_PREFS_SYSTEM_CONFIG_DIR)) {
a8a561
+    nsCString sysConfigDir = NS_LITERAL_CSTRING("/etc/");
a8a561
+    nsCOMPtr<nsIXULAppInfo> appInfo = do_GetService("@mozilla.org/xre/app-info;1");
a8a561
+    if (!appInfo)
a8a561
+      return NS_ERROR_NOT_AVAILABLE;
a8a561
+    nsCString appName;
a8a561
+    appInfo->GetName(appName);
a8a561
+    ToLowerCase(appName);
a8a561
+    sysConfigDir.Append(appName);
a8a561
+    return NS_NewNativeLocalFile(sysConfigDir, false, aFile);
a8a561
+  }
a8a561
+#endif
a8a561
+
a8a561
   if (NS_FAILED(rv) || !file)
a8a561
     return NS_ERROR_FAILURE;
a8a561
 
a8a561
@@ -753,6 +768,14 @@ nsXREDirProvider::GetFilesInternal(const
a8a561
     LoadDirIntoArray(mXULAppDir, kAppendPrefDir, directories);
a8a561
     LoadDirsIntoArray(mAppBundleDirectories,
a8a561
                       kAppendPrefDir, directories);
a8a561
+    // Add /etc/<application>/pref/ directory if it exists
a8a561
+    nsCOMPtr<nsIFile> systemPrefDir;
a8a561
+    rv = NS_GetSpecialDirectory(NS_APP_PREFS_SYSTEM_CONFIG_DIR, getter_AddRefs(systemPrefDir));
a8a561
+    if (NS_SUCCEEDED(rv)) {
a8a561
+      rv = systemPrefDir->AppendNative(NS_LITERAL_CSTRING("pref"));
a8a561
+      if (NS_SUCCEEDED(rv))
a8a561
+        directories.AppendObject(systemPrefDir);
a8a561
+    }
a8a561
 
a8a561
     rv = NS_NewArrayEnumerator(aResult, directories);
a8a561
   }
a8a561
diff -up firefox-45.0.1/xpcom/io/nsAppDirectoryServiceDefs.h.1170092 firefox-45.0.1/xpcom/io/nsAppDirectoryServiceDefs.h
a8a561
--- firefox-45.0.1/xpcom/io/nsAppDirectoryServiceDefs.h.1170092	2016-03-15 23:37:47.000000000 +0100
a8a561
+++ firefox-45.0.1/xpcom/io/nsAppDirectoryServiceDefs.h	2016-03-21 16:10:42.541417902 +0100
a8a561
@@ -67,6 +67,7 @@
a8a561
 #define NS_APP_PREFS_DEFAULTS_DIR_LIST          "PrefDL"
a8a561
 #define NS_EXT_PREFS_DEFAULTS_DIR_LIST          "ExtPrefDL"
a8a561
 #define NS_APP_PREFS_OVERRIDE_DIR               "PrefDOverride" // Directory for per-profile defaults
a8a561
+#define NS_APP_PREFS_SYSTEM_CONFIG_DIR          "PrefSysConf"   // Directory with system-wide configuration
a8a561
 
a8a561
 #define NS_APP_USER_PROFILE_50_DIR              "ProfD"
a8a561
 #define NS_APP_USER_PROFILE_LOCAL_50_DIR        "ProfLD"