Rewrote getenv and _wgetenv to avoid returning a pointer to a freed
[wine/testsucceed.git] / dlls / shell32 / shpolicy.c
blob6e36fa1481227047fbebf8e5d267414592b3a57f
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 v5.00 (W2K)
32 #include <stdarg.h>
33 #include <stdlib.h>
34 #include <string.h>
36 #include "windef.h"
37 #include "winbase.h"
38 #include "winerror.h"
39 #include "winreg.h"
41 #include "shell32_main.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(shell);
47 #define SHELL_NO_POLICY 0xffffffff
49 typedef struct tagPOLICYDAT
51 DWORD policy; /* policy value passed to SHRestricted */
52 LPCSTR appstr; /* application str such as "Explorer" */
53 LPCSTR keystr; /* name of the actual registry key / policy */
54 DWORD cache; /* cached value or 0xffffffff for invalid */
55 } POLICYDATA, *LPPOLICYDATA;
57 /* registry strings */
58 static const CHAR strRegistryPolicyA[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies";
59 static const WCHAR strRegistryPolicyW[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o',
60 's','o','f','t','\\','W','i','n','d','o','w','s','\\',
61 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',
62 '\\','P','o','l','i','c','i','e','s',0};
63 static const CHAR strPolicyA[] = "Policy";
64 static const WCHAR strPolicyW[] = {'P','o','l','i','c','y',0};
66 /* application strings */
68 static const char strExplorer[] = {"Explorer"};
69 static const char strActiveDesk[] = {"ActiveDesktop"};
70 static const char strWinOldApp[] = {"WinOldApp"};
71 static const char strAddRemoveProgs[] = {"AddRemoveProgs"};
73 /* key strings */
75 static const char strNoFileURL[] = {"NoFileUrl"};
76 static const char strNoFolderOptions[] = {"NoFolderOptions"};
77 static const char strNoChangeStartMenu[] = {"NoChangeStartMenu"};
78 static const char strNoWindowsUpdate[] = {"NoWindowsUpdate"};
79 static const char strNoSetActiveDesktop[] = {"NoSetActiveDesktop"};
80 static const char strNoForgetSoftwareUpdate[] = {"NoForgetSoftwareUpdate"};
81 static const char strNoMSAppLogo[] = {"NoMSAppLogo5ChannelNotify"};
82 static const char strForceCopyACLW[] = {"ForceCopyACLWithFile"};
83 static const char strNoResolveTrk[] = {"NoResolveTrack"};
84 static const char strNoResolveSearch[] = {"NoResolveSearch"};
85 static const char strNoEditComponent[] = {"NoEditingComponents"};
86 static const char strNoMovingBand[] = {"NoMovingBands"};
87 static const char strNoCloseDragDrop[] = {"NoCloseDragDropBands"};
88 static const char strNoCloseComponent[] = {"NoClosingComponents"};
89 static const char strNoDelComponent[] = {"NoDeletingComponents"};
90 static const char strNoAddComponent[] = {"NoAddingComponents"};
91 static const char strNoComponent[] = {"NoComponents"};
92 static const char strNoChangeWallpaper[] = {"NoChangingWallpaper"};
93 static const char strNoHTMLWallpaper[] = {"NoHTMLWallpaper"};
94 static const char strNoCustomWebView[] = {"NoCustomizeWebView"};
95 static const char strClassicShell[] = {"ClassicShell"};
96 static const char strClearRecentDocs[] = {"ClearRecentDocsOnExit"};
97 static const char strNoFavoritesMenu[] = {"NoFavoritesMenu"};
98 static const char strNoActiveDesktopChanges[] = {"NoActiveDesktopChanges"};
99 static const char strNoActiveDesktop[] = {"NoActiveDesktop"};
100 static const char strNoRecentDocMenu[] = {"NoRecentDocsMenu"};
101 static const char strNoRecentDocHistory[] = {"NoRecentDocsHistory"};
102 static const char strNoInetIcon[] = {"NoInternetIcon"};
103 static const char strNoStngsWizard[] = {"NoSettingsWizards"};
104 static const char strNoLogoff[] = {"NoLogoff"};
105 static const char strNoNetConDis[] = {"NoNetConnectDisconnect"};
106 static const char strNoContextMenu[] = {"NoViewContextMenu"};
107 static const char strNoTryContextMenu[] = {"NoTrayContextMenu"};
108 static const char strNoWebMenu[] = {"NoWebMenu"};
109 static const char strLnkResolveIgnoreLnkInfo[] = {"LinkResolveIgnoreLinkInfo"};
110 static const char strNoCommonGroups[] = {"NoCommonGroups"};
111 static const char strEnforceShlExtSecurity[] = {"EnforceShellExtensionSecurity"};
112 static const char strNoRealMode[] = {"NoRealMode"};
113 static const char strMyDocsOnNet[] = {"MyDocsOnNet"};
114 static const char strNoStartMenuSubfolder[] = {"NoStartMenuSubFolders"};
115 static const char strNoAddPrinters[] = {"NoAddPrinter"};
116 static const char strNoDeletePrinters[] = {"NoDeletePrinter"};
117 static const char strNoPrintTab[] = {"NoPrinterTabs"};
118 static const char strRestrictRun[] = {"RestrictRun"};
119 static const char strNoStartBanner[] = {"NoStartBanner"};
120 static const char strNoNetworkNeighborhood[] = {"NoNetHood"};
121 static const char strNoDriveTypeAtRun[] = {"NoDriveTypeAutoRun"};
122 static const char strNoDrivesAutoRun[] = {"NoDriveAutoRun"};
123 static const char strNoDrives[] = {"NoDrives"};
124 static const char strNoFind[] = {"NoFind"};
125 static const char strNoDesktop[] = {"NoDesktop"};
126 static const char strNoSetTaskBar[] = {"NoSetTaskbar"};
127 static const char strNoSetFld[] = {"NoSetFolders"};
128 static const char strNoFileMenu[] = {"NoFileMenu"};
129 static const char strNoSavSetng[] = {"NoSaveSettings"};
130 static const char strNoClose[] = {"NoClose"};
131 static const char strNoRun[] = {"NoRun"};
133 /* policy data array */
134 POLICYDATA sh32_policy_table[] =
137 0x1,
138 strExplorer,
139 strNoRun,
140 SHELL_NO_POLICY
143 0x2,
144 strExplorer,
145 strNoClose,
146 SHELL_NO_POLICY
149 0x4,
150 strExplorer,
151 strNoSavSetng,
152 SHELL_NO_POLICY
155 0x8,
156 strExplorer,
157 strNoFileMenu,
158 SHELL_NO_POLICY
161 0x10,
162 strExplorer,
163 strNoSetFld,
164 SHELL_NO_POLICY
167 0x20,
168 strExplorer,
169 strNoSetTaskBar,
170 SHELL_NO_POLICY
173 0x40,
174 strExplorer,
175 strNoDesktop,
176 SHELL_NO_POLICY
179 0x80,
180 strExplorer,
181 strNoFind,
182 SHELL_NO_POLICY
185 0x100,
186 strExplorer,
187 strNoDrives,
188 SHELL_NO_POLICY
191 0x200,
192 strExplorer,
193 strNoDrivesAutoRun,
194 SHELL_NO_POLICY
197 0x400,
198 strExplorer,
199 strNoDriveTypeAtRun,
200 SHELL_NO_POLICY
203 0x800,
204 strExplorer,
205 strNoNetworkNeighborhood,
206 SHELL_NO_POLICY
209 0x1000,
210 strExplorer,
211 strNoStartBanner,
212 SHELL_NO_POLICY
215 0x2000,
216 strExplorer,
217 strRestrictRun,
218 SHELL_NO_POLICY
221 0x4000,
222 strExplorer,
223 strNoPrintTab,
224 SHELL_NO_POLICY
227 0x8000,
228 strExplorer,
229 strNoDeletePrinters,
230 SHELL_NO_POLICY
233 0x10000,
234 strExplorer,
235 strNoAddPrinters,
236 SHELL_NO_POLICY
239 0x20000,
240 strExplorer,
241 strNoStartMenuSubfolder,
242 SHELL_NO_POLICY
245 0x40000,
246 strExplorer,
247 strMyDocsOnNet,
248 SHELL_NO_POLICY
251 0x80000,
252 strWinOldApp,
253 strNoRealMode,
254 SHELL_NO_POLICY
257 0x100000,
258 strExplorer,
259 strEnforceShlExtSecurity,
260 SHELL_NO_POLICY
263 0x200000,
264 strExplorer,
265 strLnkResolveIgnoreLnkInfo,
266 SHELL_NO_POLICY
269 0x400000,
270 strExplorer,
271 strNoCommonGroups,
272 SHELL_NO_POLICY
275 0x800000,
276 strExplorer,
277 "SeparateProcess",
278 SHELL_NO_POLICY
281 0x1000000,
282 strExplorer,
283 strNoWebMenu,
284 SHELL_NO_POLICY
287 0x2000000,
288 strExplorer,
289 strNoTryContextMenu,
290 SHELL_NO_POLICY
293 0x4000000,
294 strExplorer,
295 strNoContextMenu,
296 SHELL_NO_POLICY
299 0x8000000,
300 strExplorer,
301 strNoNetConDis,
302 SHELL_NO_POLICY
305 0x10000000,
306 strExplorer,
307 strNoLogoff,
308 SHELL_NO_POLICY
311 0x20000000,
312 strExplorer,
313 strNoStngsWizard,
314 SHELL_NO_POLICY
317 0x40000001,
318 strExplorer,
319 strNoInetIcon,
320 SHELL_NO_POLICY
323 0x40000002,
324 strExplorer,
325 strNoRecentDocHistory,
326 SHELL_NO_POLICY
329 0x40000003,
330 strExplorer,
331 strNoRecentDocMenu,
332 SHELL_NO_POLICY
335 0x40000004,
336 strExplorer,
337 strNoActiveDesktop,
338 SHELL_NO_POLICY
341 0x40000005,
342 strExplorer,
343 strNoActiveDesktopChanges,
344 SHELL_NO_POLICY
347 0x40000006,
348 strExplorer,
349 strNoFavoritesMenu,
350 SHELL_NO_POLICY
353 0x40000007,
354 strExplorer,
355 strClearRecentDocs,
356 SHELL_NO_POLICY
359 0x40000008,
360 strExplorer,
361 strClassicShell,
362 SHELL_NO_POLICY
365 0x40000009,
366 strExplorer,
367 strNoCustomWebView,
368 SHELL_NO_POLICY
371 0x40000010,
372 strActiveDesk,
373 strNoHTMLWallpaper,
374 SHELL_NO_POLICY
377 0x40000011,
378 strActiveDesk,
379 strNoChangeWallpaper,
380 SHELL_NO_POLICY
383 0x40000012,
384 strActiveDesk,
385 strNoComponent,
386 SHELL_NO_POLICY
389 0x40000013,
390 strActiveDesk,
391 strNoAddComponent,
392 SHELL_NO_POLICY
395 0x40000014,
396 strActiveDesk,
397 strNoDelComponent,
398 SHELL_NO_POLICY
401 0x40000015,
402 strActiveDesk,
403 strNoCloseComponent,
404 SHELL_NO_POLICY
407 0x40000016,
408 strActiveDesk,
409 strNoCloseDragDrop,
410 SHELL_NO_POLICY
413 0x40000017,
414 strActiveDesk,
415 strNoMovingBand,
416 SHELL_NO_POLICY
419 0x40000018,
420 strActiveDesk,
421 strNoEditComponent,
422 SHELL_NO_POLICY
425 0x40000019,
426 strExplorer,
427 strNoResolveSearch,
428 SHELL_NO_POLICY
431 0x4000001a,
432 strExplorer,
433 strNoResolveTrk,
434 SHELL_NO_POLICY
437 0x4000001b,
438 strExplorer,
439 strForceCopyACLW,
440 SHELL_NO_POLICY
443 0x4000001c,
444 strExplorer,
445 strNoMSAppLogo,
446 SHELL_NO_POLICY
449 0x4000001d,
450 strExplorer,
451 strNoForgetSoftwareUpdate,
452 SHELL_NO_POLICY
455 0x4000001e,
456 strExplorer,
457 strNoSetActiveDesktop,
458 SHELL_NO_POLICY
461 0x4000001f,
462 strExplorer,
463 strNoWindowsUpdate,
464 SHELL_NO_POLICY
467 0x40000020,
468 strExplorer,
469 strNoChangeStartMenu,
470 SHELL_NO_POLICY
473 0x40000021,
474 strExplorer,
475 strNoFolderOptions,
476 SHELL_NO_POLICY
479 0x50000024,
480 strExplorer,
481 strNoFileURL,
482 SHELL_NO_POLICY
485 0x40000022,
486 strExplorer,
487 "FindComputers",
488 SHELL_NO_POLICY
491 0x40000023,
492 strExplorer,
493 "IntelliMenus",
494 SHELL_NO_POLICY
497 0x40000024,
498 strExplorer,
499 "MemCheckBoxInRunDlg",
500 SHELL_NO_POLICY
503 0x40000025,
504 strAddRemoveProgs,
505 "ShowPostSetup",
506 SHELL_NO_POLICY
509 0x40000026,
510 strExplorer,
511 "NoSyncAll",
512 SHELL_NO_POLICY
515 0x40000027,
516 strExplorer,
517 "NoControlPanel",
518 SHELL_NO_POLICY
521 0x40000028,
522 strExplorer,
523 "EnumWorkgroup",
524 SHELL_NO_POLICY
527 0x40000029,
528 strAddRemoveProgs,
529 "NoAddRemovePrograms",
530 SHELL_NO_POLICY
533 0x4000002A,
534 strAddRemoveProgs,
535 "NoRemovePage",
536 SHELL_NO_POLICY
539 0x4000002B,
540 strAddRemoveProgs,
541 "NoAddPage",
542 SHELL_NO_POLICY
545 0x4000002C,
546 strAddRemoveProgs,
547 "NoWindowsSetupPage",
548 SHELL_NO_POLICY
551 0x4000002E,
552 strExplorer,
553 "NoChangeMappedDriveLabel",
554 SHELL_NO_POLICY
557 0x4000002F,
558 strExplorer,
559 "NoChangeMappedDriveComment",
560 SHELL_NO_POLICY
563 0x40000030,
564 strExplorer,
565 "MaxRecentDocs",
566 SHELL_NO_POLICY
569 0x40000031,
570 strExplorer,
571 "NoNetworkConnections",
572 SHELL_NO_POLICY
575 0x40000032,
576 strExplorer,
577 "ForceStartMenuLogoff",
578 SHELL_NO_POLICY
581 0x40000033,
582 strExplorer,
583 "NoWebView",
584 SHELL_NO_POLICY
587 0x40000034,
588 strExplorer,
589 "NoCustomizeThisFolder",
590 SHELL_NO_POLICY
593 0x40000035,
594 strExplorer,
595 "NoEncryption",
596 SHELL_NO_POLICY
599 0x40000036,
600 strExplorer,
601 "AllowFrenchEncryption",
602 SHELL_NO_POLICY
605 0x40000037,
606 strExplorer,
607 "DontShowSuperHidden",
608 SHELL_NO_POLICY
611 0x40000038,
612 strExplorer,
613 "NoShellSearchButton",
614 SHELL_NO_POLICY
617 0x40000039,
618 strExplorer,
619 "NoHardwareTab",
620 SHELL_NO_POLICY
623 0x4000003A,
624 strExplorer,
625 "NoRunasInstallPrompt",
626 SHELL_NO_POLICY
629 0x4000003B,
630 strExplorer,
631 "PromptRunasInstallNetPath",
632 SHELL_NO_POLICY
635 0x4000003C,
636 strExplorer,
637 "NoManageMyComputerVerb",
638 SHELL_NO_POLICY
641 0x4000003D,
642 strExplorer,
643 "NoRecentDocsNetHood",
644 SHELL_NO_POLICY
647 0x4000003E,
648 strExplorer,
649 "DisallowRun",
650 SHELL_NO_POLICY
653 0x4000003F,
654 strExplorer,
655 "NoWelcomeScreen",
656 SHELL_NO_POLICY
659 0x40000040,
660 strExplorer,
661 "RestrictCpl",
662 SHELL_NO_POLICY
665 0x40000041,
666 strExplorer,
667 "DisallowCpl",
668 SHELL_NO_POLICY
671 0x40000042,
672 strExplorer,
673 "NoSMBalloonTip",
674 SHELL_NO_POLICY
677 0x40000043,
678 strExplorer,
679 "NoSMHelp",
680 SHELL_NO_POLICY
683 0x40000044,
684 strExplorer,
685 "NoWinKeys",
686 SHELL_NO_POLICY
689 0x40000045,
690 strExplorer,
691 "NoEncryptOnMove",
692 SHELL_NO_POLICY
695 0x40000046,
696 strExplorer,
697 "DisableLocalMachineRun",
698 SHELL_NO_POLICY
701 0x40000047,
702 strExplorer,
703 "DisableCurrentUserRun",
704 SHELL_NO_POLICY
707 0x40000048,
708 strExplorer,
709 "DisableLocalMachineRunOnce",
710 SHELL_NO_POLICY
713 0x40000049,
714 strExplorer,
715 "DisableCurrentUserRunOnce",
716 SHELL_NO_POLICY
719 0x4000004A,
720 strExplorer,
721 "ForceActiveDesktopOn",
722 SHELL_NO_POLICY
725 0x4000004B,
726 strExplorer,
727 "NoComputersNearMe",
728 SHELL_NO_POLICY
731 0x4000004C,
732 strExplorer,
733 "NoViewOnDrive",
734 SHELL_NO_POLICY
737 0x4000004F,
738 strExplorer,
739 "NoSMMyDocs",
740 SHELL_NO_POLICY
743 0x40000061,
744 strExplorer,
745 "StartRunNoHOMEPATH",
746 SHELL_NO_POLICY
749 0x41000001,
750 strExplorer,
751 "NoDisconnect",
752 SHELL_NO_POLICY
755 0x41000002,
756 strExplorer,
757 "NoNTSecurity",
758 SHELL_NO_POLICY
761 0x41000003,
762 strExplorer,
763 "NoFileAssociate",
764 SHELL_NO_POLICY
770 SHELL_NO_POLICY
774 /*************************************************************************
775 * SHRestricted [SHELL32.100]
777 * Get the value associated with a policy Id.
779 * PARAMS
780 * pol [I] Policy Id
782 * RETURNS
783 * The queried value for the policy.
785 * NOTES
786 * Exported by ordinal.
787 * This function caches the retrieved values to prevent unnecessary registry access,
788 * if SHInitRestricted() was previously called.
790 * REFERENCES
791 * a: MS System Policy Editor.
792 * b: 98Lite 2.0 (which uses many of these policy keys) http://www.98lite.net/
793 * c: 'The Windows 95 Registry', by John Woram, 1996 MIS: Press
795 DWORD WINAPI SHRestricted (DWORD policy)
797 char regstr[256];
798 HKEY xhkey;
799 DWORD retval, datsize = 4;
800 LPPOLICYDATA p;
802 TRACE("(%08lx)\n", policy);
804 /* scan to see if we know this policy ID */
805 for (p = sh32_policy_table; p->policy; p++)
807 if (policy == p->policy)
809 break;
813 if (p->policy == 0)
815 /* we don't know this policy, return 0 */
816 TRACE("unknown policy: (%08lx)\n", policy);
817 return 0;
820 /* we have a known policy */
822 /* first check if this policy has been cached, return it if so */
823 if (p->cache != SHELL_NO_POLICY)
825 return p->cache;
828 lstrcpyA(regstr, strRegistryPolicyA);
829 lstrcatA(regstr, p->appstr);
831 /* return 0 and don't set the cache if any registry errors occur */
832 retval = 0;
833 if (RegOpenKeyA(HKEY_CURRENT_USER, regstr, &xhkey) == ERROR_SUCCESS)
835 if (RegQueryValueExA(xhkey, p->keystr, NULL, NULL, (LPBYTE)&retval, &datsize) == ERROR_SUCCESS)
837 p->cache = retval;
839 RegCloseKey(xhkey);
841 return retval;
844 /*************************************************************************
845 * SHInitRestricted [SHELL32.244]
847 * Initialise the policy cache to speed up calls to SHRestricted().
849 * PARAMS
850 * unused [I] Reserved.
851 * inpRegKey [I] Registry key to scan.
853 * RETURNS
854 * Success: -1. The policy cache is initialised.
855 * Failure: 0, if inpRegKey is any value other than NULL, "Policy", or
856 * "Software\Microsoft\Windows\CurrentVersion\Policies".
858 * NOTES
859 * Exported by ordinal. Introduced in Win98.
861 BOOL WINAPI SHInitRestricted(LPCVOID unused, LPCVOID inpRegKey)
863 LPPOLICYDATA p;
865 TRACE("(%p, %p)\n", unused, inpRegKey);
867 /* first check - if input is non-NULL and points to the secret
868 key string, then pass. Otherwise return 0.
870 if (inpRegKey != NULL)
872 if (SHELL_OsIsUnicode())
874 if (lstrcmpiW((LPWSTR)inpRegKey, strRegistryPolicyW) &&
875 lstrcmpiW((LPWSTR)inpRegKey, strPolicyW))
876 /* doesn't match, fail */
877 return 0;
879 else
881 if (lstrcmpiA((LPSTR)inpRegKey, strRegistryPolicyA) &&
882 lstrcmpiA((LPSTR)inpRegKey, strPolicyA))
883 /* doesn't match, fail */
884 return 0;
888 /* check passed, init all policy cache entries with SHELL_NO_POLICY */
889 for (p = sh32_policy_table; p->policy; p++)
891 p->cache = SHELL_NO_POLICY;
893 return SHELL_NO_POLICY;