ReactOS 0.4.16-dev-1151-g3842b59
shpolicy.c
Go to the documentation of this file.
1/*
2 * shpolicy.c - Data for shell/system policies.
3 *
4 * Copyright 1999 Ian Schmidt <ischmidt@cfl.rr.com>
5 * Copyright 2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 * NOTES:
22 *
23 * Some of these policies can be tweaked via the System Policy
24 * Editor which came with the Win95 Migration Guide, although
25 * there doesn't appear to be an updated Win98 version that
26 * would handle the many new policies introduced since then.
27 * You could easily write one with the information in
28 * this file...
29 */
30
31#include <stdarg.h>
32#include <stdlib.h>
33#include <string.h>
34
35#define WIN32_NO_STATUS
36#define _INC_WINDOWS
37
38#include <windef.h>
39#include <winbase.h>
40#include <shlobj.h>
41#include <initguid.h>
42#include <shlwapi_undoc.h>
43#include <shlwapi.h>
44#include <wine/debug.h>
45
46#include "shell32_main.h"
47
49
50DEFINE_GUID(GUID_Restrictions, 0xA48F1A32, 0xA340, 0x11D1, 0xBC, 0x6B, 0x00, 0xA0, 0xC9, 0x03, 0x12, 0xE1);
51
52#define DEFINE_POLICY(policy, appstr, keystr) \
53 { policy, L##appstr, L##keystr }
54
55static const POLICYDATA s_PolicyTable[] =
56{
57#include "PolicyData.h"
58 { 0, NULL, NULL }
59};
60
61#undef DEFINE_POLICY
62
63/*
64 * The restriction-related variables
65 */
69
70#ifdef __REACTOS__
71int WINAPI SHELL_StrCmpLogicalInit(PCWSTR s1, PCWSTR s2)
72{
74 return SHELL_StrCmpLogical(s1, s2);
75}
76
77int (WINAPI* SHELL_StrCmpLogical)(PCWSTR s1, PCWSTR s2) = SHELL_StrCmpLogicalInit;
78
79static void SH32_RestrictionsChanged()
80{
81 SHELL_StrCmpLogical = SHELL_StrCmpLogicalInit;
82}
83#endif
84
85/****************************************************************************
86 * SHELL_GetCachedGlobalCounter
87 *
88 * Retrieves the global counter using cache in a thread-safe manner.
89 * If a cache of global counter exists, the function returns it.
90 * If there is no cache, the function creates a global counter.
91 *
92 * @param[in,out] phGlobalCounter The pointer to the handle of global counter.
93 * @param[in] rguid The GUID of global counter.
94 * @return The handle of the global counter.
95 * @implemented
96 */
97#ifdef __REACTOS__
99#else
100static HANDLE
101#endif
103{
104 HANDLE hGlobalCounter;
105 if (*phGlobalCounter)
106 return *phGlobalCounter;
107 hGlobalCounter = SHGlobalCounterCreate(rguid);
108 if (InterlockedCompareExchangePointer(phGlobalCounter, hGlobalCounter, NULL))
109 CloseHandle(hGlobalCounter);
110 return *phGlobalCounter;
111}
112
113/****************************************************************************
114 * SHELL_GetRestrictionsCounter
115 *
116 * Retrieves the global counter for GUID_Restrictions using caching in a
117 * thread-safe manner. The variable g_hRestGlobalCounter is used for caching.
118 *
119 * @return The handle of the global counter.
120 * @see SHELL_GetCachedGlobalCounter
121 * @implemented
122 */
124{
125 return SHELL_GetCachedGlobalCounter(&g_hRestGlobalCounter, &GUID_Restrictions);
126}
127
128/****************************************************************************
129 * SHELL_QueryRestrictionsChanged
130 *
131 * @return The value of the global counter for GUID_Restrictions.
132 * @see SHELL_GetRestrictionsCounter
133 * @implemented
134 */
136{
139 return FALSE;
140
142 return TRUE;
143}
144
145/*************************************************************************
146 * SHRestricted [SHELL32.100]
147 *
148 * Get the value associated with a policy Id.
149 *
150 * PARAMS
151 * pol [I] Policy Id
152 *
153 * RETURNS
154 * The queried value for the policy.
155 *
156 * NOTES
157 * Exported by ordinal.
158 * This function caches the retrieved values to prevent unnecessary registry access,
159 * if SHSettingsChanged() was previously called.
160 *
161 * REFERENCES
162 * a: MS System Policy Editor.
163 * b: 98Lite 2.0 (which uses many of these policy keys) http://www.98lite.net/
164 * c: 'The Windows 95 Registry', by John Woram, 1996 MIS: Press
165 */
167{
168 TRACE("(0x%08lX)\n", rest);
169
170 /* If restrictions from registry have changed, reset all cached values to SHELL_NO_POLICY */
172 {
173 FillMemory(&g_RestValues, sizeof(g_RestValues), 0xFF);
174 SH32_RestrictionsChanged();
175 }
176
178}
179
180/*************************************************************************
181 * SHSettingsChanged [SHELL32.244]
182 *
183 * Initialise the policy cache to speed up calls to SHRestricted().
184 *
185 * PARAMS
186 * unused [I] Reserved.
187 * pszKey [I] Registry key to scan.
188 *
189 * RETURNS
190 * Success: -1. The policy cache is initialised.
191 * Failure: 0, if inpRegKey is any value other than NULL, "Policy", or
192 * "Software\Microsoft\Windows\CurrentVersion\Policies".
193 *
194 * NOTES
195 * Exported by ordinal. Introduced in Win98.
196 */
198{
199 TRACE("(%p, %s)\n", unused, debugstr_w(pszKey));
200
201 if (pszKey &&
202 lstrcmpiW(L"Policy", pszKey) != 0 &&
203 lstrcmpiW(L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies", pszKey) != 0)
204 {
205 return FALSE;
206 }
207
209}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
#define EXTERN_C
Definition: basetyps.h:12
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4262
DWORD WINAPI SHRestrictionLookup(DWORD policy, LPCWSTR initial, LPPOLICYDATA polTable, LPDWORD polArr)
Definition: ordinal.c:2811
INT WINAPI StrCmpLogicalW(LPCWSTR lpszStr, LPCWSTR lpszComp)
Definition: string.c:2310
int WINAPI StrCmpIW(LPCWSTR lpszStr, LPCWSTR lpszComp)
Definition: string.c:353
HANDLE WINAPI SHGlobalCounterCreate(REFGUID guid)
Definition: thread.c:551
LONG WINAPI SHGlobalCounterGetValue(HANDLE hSem)
Definition: thread.c:432
LONG WINAPI SHGlobalCounterIncrement(HANDLE hSem)
Definition: thread.c:453
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define FillMemory(BUF, SIZ, MASK)
Definition: strucsup.c:31
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
#define debugstr_w
Definition: kernel32.h:32
struct S1 s1
WORD unused[29]
Definition: crypt.c:1155
#define _Inout_
Definition: no_sal2.h:162
#define _In_
Definition: no_sal2.h:158
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
Definition: guiddef.h:68
PCWSTR s2
Definition: shell32_main.h:38
RESTRICTIONS
Definition: shlobj.h:1649
@ REST_NOSTRCMPLOGICAL
Definition: shlobj.h:1828
BOOL WINAPI SHSettingsChanged(LPCVOID unused, LPCWSTR pszKey)
Definition: shpolicy.c:197
static BOOL SHELL_QueryRestrictionsChanged(VOID)
Definition: shpolicy.c:135
static HANDLE SHELL_GetRestrictionsCounter(VOID)
Definition: shpolicy.c:123
DWORD g_RestValues[_countof(s_PolicyTable)]
Definition: shpolicy.c:68
static const POLICYDATA s_PolicyTable[]
Definition: shpolicy.c:55
HANDLE g_hRestGlobalCounter
Definition: shpolicy.c:66
LONG g_nRestCountValue
Definition: shpolicy.c:67
DWORD WINAPI SHRestricted(RESTRICTIONS rest)
Definition: shpolicy.c:166
static HANDLE SHELL_GetCachedGlobalCounter(_Inout_ HANDLE *phGlobalCounter, _In_ REFGUID rguid)
Definition: shpolicy.c:102
#define _countof(array)
Definition: sndvol32.h:70
#define TRACE(s)
Definition: solgame.cpp:4
Definition: scsiwmi.h:51
const uint16_t * PCWSTR
Definition: typedefs.h:57
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
CONST void * LPCVOID
Definition: windef.h:191
#define WINAPI
Definition: msvc.h:6
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185