Avoid crashing when releasing an NdrCStdStubBuffer that had been
[wine/dcerpc.git] / dlls / shell32 / shpolicy.c
blobdc58d886921a88e776a9f96adb9d5c3df59155a8
1 /*
2 * shpolicy.c - Data for shell/system policies.
4 * Copyright 1999 Ian Schmidt <ischmidt@cfl.rr.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * NOTES:
22 * Some of these policies can be tweaked via the System Policy
23 * Editor which came with the Win95 Migration Guide, although
24 * there doesn't appear to be an updated Win98 version that
25 * would handle the many new policies introduced since then.
26 * You could easily write one with the information in
27 * this file...
29 * Up to date as of SHELL32 v4.72 (Win98, Win95 with MSIE 5)
32 #include <stdlib.h>
33 #include <string.h>
35 #include "windef.h"
36 #include "winerror.h"
37 #include "winreg.h"
39 #include "undocshell.h"
40 #include "wine/winuser16.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(shell);
46 #define SHELL_MAX_POLICIES 57
48 #define SHELL_NO_POLICY 0xffffffff
50 typedef struct tagPOLICYDAT
52 DWORD polflags; /* flags value passed to SHRestricted */
53 LPSTR appstr; /* application str such as "Explorer" */
54 LPSTR keystr; /* name of the actual registry key / policy */
55 DWORD cache; /* cached value or 0xffffffff for invalid */
56 } POLICYDATA, *LPPOLICYDATA;
58 #if 0
59 extern POLICYDATA sh32_policy_table[SHELL_MAX_POLICIES];
60 #endif
62 /* application strings */
64 static char strExplorer[] = {"Explorer"};
65 static char strActiveDesk[] = {"ActiveDesktop"};
66 static char strWinOldApp[] = {"WinOldApp"};
68 /* key strings */
70 static char strNoFileURL[] = {"NoFileUrl"};
71 static char strNoFolderOptions[] = {"NoFolderOptions"};
72 static char strNoChangeStartMenu[] = {"NoChangeStartMenu"};
73 static char strNoWindowsUpdate[] = {"NoWindowsUpdate"};
74 static char strNoSetActiveDesktop[] = {"NoSetActiveDesktop"};
75 static char strNoForgetSoftwareUpdate[] = {"NoForgetSoftwareUpdate"};
76 static char strNoMSAppLogo[] = {"NoMSAppLogo5ChannelNotify"};
77 static char strForceCopyACLW[] = {"ForceCopyACLWithFile"};
78 static char strNoResolveTrk[] = {"NoResolveTrack"};
79 static char strNoResolveSearch[] = {"NoResolveSearch"};
80 static char strNoEditComponent[] = {"NoEditingComponents"};
81 static char strNoMovingBand[] = {"NoMovingBands"};
82 static char strNoCloseDragDrop[] = {"NoCloseDragDropBands"};
83 static char strNoCloseComponent[] = {"NoClosingComponents"};
84 static char strNoDelComponent[] = {"NoDeletingComponents"};
85 static char strNoAddComponent[] = {"NoAddingComponents"};
86 static char strNoComponent[] = {"NoComponents"};
87 static char strNoChangeWallpaper[] = {"NoChangingWallpaper"};
88 static char strNoHTMLWallpaper[] = {"NoHTMLWallpaper"};
89 static char strNoCustomWebView[] = {"NoCustomizeWebView"};
90 static char strClassicShell[] = {"ClassicShell"};
91 static char strClearRecentDocs[] = {"ClearRecentDocsOnExit"};
92 static char strNoFavoritesMenu[] = {"NoFavoritesMenu"};
93 static char strNoActiveDesktopChanges[] = {"NoActiveDesktopChanges"};
94 static char strNoActiveDesktop[] = {"NoActiveDesktop"};
95 static char strNoRecentDocMenu[] = {"NoRecentDocsMenu"};
96 static char strNoRecentDocHistory[] = {"NoRecentDocsHistory"};
97 static char strNoInetIcon[] = {"NoInternetIcon"};
98 static char strNoStngsWizard[] = {"NoSettingsWizards"};
99 static char strNoLogoff[] = {"NoLogoff"};
100 static char strNoNetConDis[] = {"NoNetConnectDisconnect"};
101 static char strNoContextMenu[] = {"NoViewContextMenu"};
102 static char strNoTryContextMenu[] = {"NoTrayContextMenu"};
103 static char strNoWebMenu[] = {"NoWebMenu"};
104 static char strLnkResolveIgnoreLnkInfo[] = {"LinkResolveIgnoreLinkInfo"};
105 static char strNoCommonGroups[] = {"NoCommonGroups"};
106 static char strEnforceShlExtSecurity[] = {"EnforceShellExtensionSecurity"};
107 static char strNoRealMode[] = {"NoRealMode"};
108 static char strMyDocsOnNet[] = {"MyDocsOnNet"};
109 static char strNoStartMenuSubfolder[] = {"NoStartMenuSubFolders"};
110 static char strNoAddPrinters[] = {"NoAddPrinter"};
111 static char strNoDeletePrinters[] = {"NoDeletePrinter"};
112 static char strNoPrintTab[] = {"NoPrinterTabs"};
113 static char strRestrictRun[] = {"RestrictRun"};
114 static char strNoStartBanner[] = {"NoStartBanner"};
115 static char strNoNetworkNeighborhood[] = {"NoNetHood"};
116 static char strNoDriveTypeAtRun[] = {"NoDriveTypeAutoRun"};
117 static char strNoDrivesAutoRun[] = {"NoDriveAutoRun"};
118 static char strNoDrives[] = {"NoDrives"};
119 static char strNoFind[] = {"NoFind"};
120 static char strNoDesktop[] = {"NoDesktop"};
121 static char strNoSetTaskBar[] = {"NoSetTaskbar"};
122 static char strNoSetFld[] = {"NoSetFolders"};
123 static char strNoFileMenu[] = {"NoFileMenu"};
124 static char strNoSavSetng[] = {"NoSaveSettings"};
125 static char strNoClose[] = {"NoClose"};
126 static char strNoRun[] = {"NoRun"};
128 /* policy data array */
130 POLICYDATA sh32_policy_table[] =
133 0x1,
134 strExplorer,
135 strNoRun,
136 SHELL_NO_POLICY
139 0x2,
140 strExplorer,
141 strNoClose,
142 SHELL_NO_POLICY
145 0x4,
146 strExplorer,
147 strNoSavSetng,
148 SHELL_NO_POLICY
151 0x8,
152 strExplorer,
153 strNoFileMenu,
154 SHELL_NO_POLICY
157 0x10,
158 strExplorer,
159 strNoSetFld,
160 SHELL_NO_POLICY
163 0x20,
164 strExplorer,
165 strNoSetTaskBar,
166 SHELL_NO_POLICY
169 0x40,
170 strExplorer,
171 strNoDesktop,
172 SHELL_NO_POLICY
175 0x80,
176 strExplorer,
177 strNoFind,
178 SHELL_NO_POLICY
181 0x100,
182 strExplorer,
183 strNoDrives,
184 SHELL_NO_POLICY
187 0x200,
188 strExplorer,
189 strNoDrivesAutoRun,
190 SHELL_NO_POLICY
193 0x400,
194 strExplorer,
195 strNoDriveTypeAtRun,
196 SHELL_NO_POLICY
199 0x800,
200 strExplorer,
201 strNoNetworkNeighborhood,
202 SHELL_NO_POLICY
205 0x1000,
206 strExplorer,
207 strNoStartBanner,
208 SHELL_NO_POLICY
211 0x2000,
212 strExplorer,
213 strRestrictRun,
214 SHELL_NO_POLICY
217 0x4000,
218 strExplorer,
219 strNoPrintTab,
220 SHELL_NO_POLICY
223 0x8000,
224 strExplorer,
225 strNoDeletePrinters,
226 SHELL_NO_POLICY
229 0x10000,
230 strExplorer,
231 strNoAddPrinters,
232 SHELL_NO_POLICY
235 0x20000,
236 strExplorer,
237 strNoStartMenuSubfolder,
238 SHELL_NO_POLICY
241 0x40000,
242 strExplorer,
243 strMyDocsOnNet,
244 SHELL_NO_POLICY
247 0x80000,
248 strWinOldApp,
249 strNoRealMode,
250 SHELL_NO_POLICY
253 0x100000,
254 strExplorer,
255 strEnforceShlExtSecurity,
256 SHELL_NO_POLICY
259 0x200000,
260 strExplorer,
261 strLnkResolveIgnoreLnkInfo,
262 SHELL_NO_POLICY
265 0x400000,
266 strExplorer,
267 strNoCommonGroups,
268 SHELL_NO_POLICY
271 0x1000000,
272 strExplorer,
273 strNoWebMenu,
274 SHELL_NO_POLICY
277 0x2000000,
278 strExplorer,
279 strNoTryContextMenu,
280 SHELL_NO_POLICY
283 0x4000000,
284 strExplorer,
285 strNoContextMenu,
286 SHELL_NO_POLICY
289 0x8000000,
290 strExplorer,
291 strNoNetConDis,
292 SHELL_NO_POLICY
295 0x10000000,
296 strExplorer,
297 strNoLogoff,
298 SHELL_NO_POLICY
301 0x20000000,
302 strExplorer,
303 strNoStngsWizard,
304 SHELL_NO_POLICY
307 0x40000001,
308 strExplorer,
309 strNoInetIcon,
310 SHELL_NO_POLICY
313 0x40000002,
314 strExplorer,
315 strNoRecentDocHistory,
316 SHELL_NO_POLICY
319 0x40000003,
320 strExplorer,
321 strNoRecentDocMenu,
322 SHELL_NO_POLICY
325 0x40000004,
326 strExplorer,
327 strNoActiveDesktop,
328 SHELL_NO_POLICY
331 0x40000005,
332 strExplorer,
333 strNoActiveDesktopChanges,
334 SHELL_NO_POLICY
337 0x40000006,
338 strExplorer,
339 strNoFavoritesMenu,
340 SHELL_NO_POLICY
343 0x40000007,
344 strExplorer,
345 strClearRecentDocs,
346 SHELL_NO_POLICY
349 0x40000008,
350 strExplorer,
351 strClassicShell,
352 SHELL_NO_POLICY
355 0x40000009,
356 strExplorer,
357 strNoCustomWebView,
358 SHELL_NO_POLICY
361 0x40000010,
362 strActiveDesk,
363 strNoHTMLWallpaper,
364 SHELL_NO_POLICY
367 0x40000011,
368 strActiveDesk,
369 strNoChangeWallpaper,
370 SHELL_NO_POLICY
373 0x40000012,
374 strActiveDesk,
375 strNoComponent,
376 SHELL_NO_POLICY
379 0x40000013,
380 strActiveDesk,
381 strNoAddComponent,
382 SHELL_NO_POLICY
385 0x40000014,
386 strActiveDesk,
387 strNoDelComponent,
388 SHELL_NO_POLICY
391 0x40000015,
392 strActiveDesk,
393 strNoCloseComponent,
394 SHELL_NO_POLICY
397 0x40000016,
398 strActiveDesk,
399 strNoCloseDragDrop,
400 SHELL_NO_POLICY
403 0x40000017,
404 strActiveDesk,
405 strNoMovingBand,
406 SHELL_NO_POLICY
409 0x40000018,
410 strActiveDesk,
411 strNoEditComponent,
412 SHELL_NO_POLICY
415 0x40000019,
416 strExplorer,
417 strNoResolveSearch,
418 SHELL_NO_POLICY
421 0x4000001a,
422 strExplorer,
423 strNoResolveTrk,
424 SHELL_NO_POLICY
427 0x4000001b,
428 strExplorer,
429 strForceCopyACLW,
430 SHELL_NO_POLICY
433 0x4000001c,
434 strExplorer,
435 strNoMSAppLogo,
436 SHELL_NO_POLICY
439 0x4000001d,
440 strExplorer,
441 strNoForgetSoftwareUpdate,
442 SHELL_NO_POLICY
445 0x4000001e,
446 strExplorer,
447 strNoSetActiveDesktop,
448 SHELL_NO_POLICY
451 0x4000001f,
452 strExplorer,
453 strNoWindowsUpdate,
454 SHELL_NO_POLICY
457 0x40000020,
458 strExplorer,
459 strNoChangeStartMenu,
460 SHELL_NO_POLICY
463 0x40000021,
464 strExplorer,
465 strNoFolderOptions,
466 SHELL_NO_POLICY
469 0x50000024,
470 strExplorer,
471 strNoFileURL,
472 SHELL_NO_POLICY
476 /*************************************************************************
477 * SHRestricted [SHELL32.100]
479 * walks through policy table, queries <app> key, <type> value, returns
480 * queried (DWORD) value, and caches it between called to SHInitRestricted
481 * to prevent unnecessary registry access.
483 * NOTES
484 * exported by ordinal
486 * REFERENCES:
487 * MS System Policy Editor
488 * 98Lite 2.0 (which uses many of these policy keys) http://www.98lite.net/
489 * "The Windows 95 Registry", by John Woram, 1996 MIS: Press
491 DWORD WINAPI SHRestricted (DWORD pol) {
492 char regstr[256];
493 HKEY xhkey;
494 DWORD retval, polidx, i, datsize = 4;
496 TRACE("(%08lx)\n",pol);
498 polidx = -1;
500 /* scan to see if we know this policy ID */
501 for (i = 0; i < SHELL_MAX_POLICIES; i++)
503 if (pol == sh32_policy_table[i].polflags)
505 polidx = i;
506 break;
510 if (polidx == -1)
512 /* we don't know this policy, return 0 */
513 TRACE("unknown policy: (%08lx)\n", pol);
514 return 0;
517 /* we have a known policy */
518 strcpy(regstr, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\");
519 strcat(regstr, sh32_policy_table[polidx].appstr);
521 /* first check if this policy has been cached, return it if so */
522 if (sh32_policy_table[polidx].cache != SHELL_NO_POLICY)
524 return sh32_policy_table[polidx].cache;
527 /* return 0 and don't set the cache if any registry errors occur */
528 retval = 0;
529 if (RegOpenKeyA(HKEY_CURRENT_USER, regstr, &xhkey) == ERROR_SUCCESS)
531 if (RegQueryValueExA(xhkey, sh32_policy_table[polidx].keystr, NULL, NULL, (LPBYTE)&retval, &datsize) == ERROR_SUCCESS)
533 sh32_policy_table[polidx].cache = retval;
536 RegCloseKey(xhkey);
539 return retval;
542 /*************************************************************************
543 * SHInitRestricted [SHELL32.244]
545 * Win98+ by-ordinal only routine called by Explorer and MSIE 4 and 5.
546 * Inits the policy cache used by SHRestricted to avoid excess
547 * registry access.
549 * INPUTS
550 * Two inputs: one is a string or NULL. If non-NULL the pointer
551 * should point to a string containing the following exact text:
552 * "Software\Microsoft\Windows\CurrentVersion\Policies".
553 * The other input is unused.
555 * NOTES
556 * If the input is non-NULL and does not point to a string containing
557 * that exact text the routine will do nothing.
559 * If the text does match or the pointer is NULL, then the routine
560 * will init SHRestricted()'s policy cache to all 0xffffffff and
561 * returns 0xffffffff as well.
563 * I haven't yet run into anything calling this with inputs other than
564 * (NULL, NULL), so I may have the inputs reversed.
567 BOOL WINAPI SHInitRestricted(LPSTR inpRegKey, LPSTR parm2)
569 int i;
571 TRACE("(%p, %p)\n", inpRegKey, parm2);
573 /* first check - if input is non-NULL and points to the secret
574 key string, then pass. Otherwise return 0.
577 if (inpRegKey != (LPSTR)NULL)
579 if (lstrcmpiA(inpRegKey, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies"))
581 /* doesn't match, fail */
582 return 0;
586 /* check passed, init all policy cache entries with SHELL_NO_POLICY */
587 for (i = 0; i < SHELL_MAX_POLICIES; i++)
589 sh32_policy_table[i].cache = SHELL_NO_POLICY;
592 return SHELL_NO_POLICY;