Bug 1583466 - [Linux] Load policies per user from system, r=mkaply,mossop

Differential Revision: https://phabricator.services.mozilla.com/D46921

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Martin Stransky 2019-10-23 17:35:11 +00:00
Родитель bcccc1d738
Коммит 8197c0c37c
3 изменённых файлов: 26 добавлений и 2 удалений

Просмотреть файл

@ -23,6 +23,9 @@ XPCOMUtils.defineLazyModuleGetters(this, {
// ${InstallDir}/distribution folder.
const POLICIES_FILENAME = "policies.json";
// When true browser policy is loaded per-user from
// /run/user/$UID/appname
const PREF_PER_USER_DIR = "toolkit.policies.perUserDir";
// For easy testing, modify the helpers/sample.json file,
// and set PREF_ALTERNATE_PATH in firefox.js as:
// /your/repo/browser/components/enterprisepolicies/helpers/sample.json
@ -455,7 +458,12 @@ class JSONPoliciesProvider {
_getConfigurationFile() {
let configFile = null;
try {
configFile = Services.dirsvc.get("XREAppDist", Ci.nsIFile);
let perUserPath = Services.prefs.getBoolPref(PREF_PER_USER_DIR, false);
if (perUserPath) {
configFile = Services.dirsvc.get("XREUserRunTimeDir", Ci.nsIFile);
} else {
configFile = Services.dirsvc.get("XREAppDist", Ci.nsIFile);
}
configFile.append(POLICIES_FILENAME);
} catch (ex) {
// Getting the correct directory will fail in xpcshell tests. This should

Просмотреть файл

@ -45,6 +45,7 @@
#include "mozilla/Omnijar.h"
#include "mozilla/Preferences.h"
#include "mozilla/Telemetry.h"
#include "nsPrintfCString.h"
#include <stdlib.h>
@ -103,7 +104,7 @@ nsCOMPtr<nsIFile> gDataDirProfile = nullptr;
// These are required to allow nsXREDirProvider to be usable in xpcshell tests.
// where gAppData is null.
#if defined(XP_MACOSX) || defined(XP_WIN)
#if defined(XP_MACOSX) || defined(XP_WIN) || defined(XP_UNIX)
static const char* GetAppName() {
if (gAppData) {
return gAppData->name;
@ -461,6 +462,14 @@ nsXREDirProvider::GetFile(const char* aProperty, bool* aPersistent,
#endif
} else if (!strcmp(aProperty, XRE_USER_SYS_EXTENSION_DEV_DIR)) {
return GetSysUserExtensionsDevDirectory(aFile);
} else if (!strcmp(aProperty, XRE_USER_RUNTIME_DIR)) {
#ifdef MOZ_WIDGET_GTK
nsPrintfCString path("/run/user/%d/%s/", getuid(), GetAppName());
ToLowerCase(path);
return NS_NewNativeLocalFile(path, false, aFile);
#else
return NS_ERROR_FAILURE;
#endif
} else if (!strcmp(aProperty, XRE_APP_DISTRIBUTION_DIR)) {
bool persistent = false;
rv = GetFile(NS_GRE_DIR, &persistent, getter_AddRefs(file));

Просмотреть файл

@ -141,6 +141,13 @@
*/
#define XRE_ADDON_APP_DIR "XREAddonAppDir"
/**
* A directory service key which specifies the distribution specific files for
* the application unique for each user.
* It's located at /run/user/$UID/<product name>/
*/
#define XRE_USER_RUNTIME_DIR "XREUserRunTimeDir"
/**
* A directory service key which provides the update directory. Callers should
* fall back to appDir.