1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_PolicyChecks_h
8 #define mozilla_PolicyChecks_h
13 # include "mozilla/Maybe.h"
15 # define POLICY_REGKEY_NAME L"SOFTWARE\\Policies\\Mozilla\\" MOZ_APP_BASENAME
17 // NB: This code must be able to run apart from XPCOM
21 // Returns Some(true) if the registry value is 1
22 // Returns Some(false) if the registry value is not 1
23 // Returns Nothing() if the registry value is not present
24 inline Maybe
<bool> PolicyHasRegValueOfOne(HKEY aKey
, LPCWSTR aName
) {
26 DWORD len
= sizeof(DWORD
);
28 LONG ret
= ::RegGetValueW(aKey
, POLICY_REGKEY_NAME
, aName
, RRF_RT_DWORD
,
29 nullptr, &value
, &len
);
30 if (ret
== ERROR_SUCCESS
) {
31 return Some(value
== 1);
36 DWORD len
= sizeof(ULONGLONG
);
37 LONG ret
= ::RegGetValueW(aKey
, POLICY_REGKEY_NAME
, aName
, RRF_RT_QWORD
,
38 nullptr, &value
, &len
);
39 if (ret
== ERROR_SUCCESS
) {
40 return Some(value
== 1);
46 inline bool PolicyCheckBoolean(LPCWSTR aPolicyName
) {
47 Maybe
<bool> localMachineResult
=
48 PolicyHasRegValueOfOne(HKEY_LOCAL_MACHINE
, aPolicyName
);
49 if (localMachineResult
.isSome()) {
50 return localMachineResult
.value();
53 Maybe
<bool> currentUserResult
=
54 PolicyHasRegValueOfOne(HKEY_CURRENT_USER
, aPolicyName
);
55 if (currentUserResult
.isSome()) {
56 return currentUserResult
.value();
62 } // namespace mozilla
64 #endif // defined(XP_WIN)
66 #endif // mozilla_PolicyChecks_h