Release 20030408.
[wine/gsoc-2012-control.git] / dlls / shell32 / shpolicy.c
blobe9818faf51e59b789d14cfb87ede0cfcf4604801
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 <stdlib.h>
33 #include <string.h>
35 #include "windef.h"
36 #include "winerror.h"
37 #include "winreg.h"
39 #include "shell32_main.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(shell);
45 #define SHELL_NO_POLICY 0xffffffff
47 typedef struct tagPOLICYDAT
49 DWORD policy; /* policy value passed to SHRestricted */
50 LPCSTR appstr; /* application str such as "Explorer" */
51 LPCSTR keystr; /* name of the actual registry key / policy */
52 DWORD cache; /* cached value or 0xffffffff for invalid */
53 } POLICYDATA, *LPPOLICYDATA;
55 /* registry strings */
56 static const CHAR strRegistryPolicyA[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies";
57 static const WCHAR strRegistryPolicyW[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o',
58 's','o','f','t','\\','W','i','n','d','o','w','s','\\',
59 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',
60 '\\','P','o','l','i','c','i','e','s',0};
61 static const CHAR strPolicyA[] = "Policy";
62 static const WCHAR strPolicyW[] = {'P','o','l','i','c','y',0};
64 /* application strings */
66 static const char strExplorer[] = {"Explorer"};
67 static const char strActiveDesk[] = {"ActiveDesktop"};
68 static const char strWinOldApp[] = {"WinOldApp"};
69 static const char strAddRemoveProgs[] = {"AddRemoveProgs"};
71 /* key strings */
73 static const char strNoFileURL[] = {"NoFileUrl"};
74 static const char strNoFolderOptions[] = {"NoFolderOptions"};
75 static const char strNoChangeStartMenu[] = {"NoChangeStartMenu"};
76 static const char strNoWindowsUpdate[] = {"NoWindowsUpdate"};
77 static const char strNoSetActiveDesktop[] = {"NoSetActiveDesktop"};
78 static const char strNoForgetSoftwareUpdate[] = {"NoForgetSoftwareUpdate"};
79 static const char strNoMSAppLogo[] = {"NoMSAppLogo5ChannelNotify"};
80 static const char strForceCopyACLW[] = {"ForceCopyACLWithFile"};
81 static const char strNoResolveTrk[] = {"NoResolveTrack"};
82 static const char strNoResolveSearch[] = {"NoResolveSearch"};
83 static const char strNoEditComponent[] = {"NoEditingComponents"};
84 static const char strNoMovingBand[] = {"NoMovingBands"};
85 static const char strNoCloseDragDrop[] = {"NoCloseDragDropBands"};
86 static const char strNoCloseComponent[] = {"NoClosingComponents"};
87 static const char strNoDelComponent[] = {"NoDeletingComponents"};
88 static const char strNoAddComponent[] = {"NoAddingComponents"};
89 static const char strNoComponent[] = {"NoComponents"};
90 static const char strNoChangeWallpaper[] = {"NoChangingWallpaper"};
91 static const char strNoHTMLWallpaper[] = {"NoHTMLWallpaper"};
92 static const char strNoCustomWebView[] = {"NoCustomizeWebView"};
93 static const char strClassicShell[] = {"ClassicShell"};
94 static const char strClearRecentDocs[] = {"ClearRecentDocsOnExit"};
95 static const char strNoFavoritesMenu[] = {"NoFavoritesMenu"};
96 static const char strNoActiveDesktopChanges[] = {"NoActiveDesktopChanges"};
97 static const char strNoActiveDesktop[] = {"NoActiveDesktop"};
98 static const char strNoRecentDocMenu[] = {"NoRecentDocsMenu"};
99 static const char strNoRecentDocHistory[] = {"NoRecentDocsHistory"};
100 static const char strNoInetIcon[] = {"NoInternetIcon"};
101 static const char strNoStngsWizard[] = {"NoSettingsWizards"};
102 static const char strNoLogoff[] = {"NoLogoff"};
103 static const char strNoNetConDis[] = {"NoNetConnectDisconnect"};
104 static const char strNoContextMenu[] = {"NoViewContextMenu"};
105 static const char strNoTryContextMenu[] = {"NoTrayContextMenu"};
106 static const char strNoWebMenu[] = {"NoWebMenu"};
107 static const char strLnkResolveIgnoreLnkInfo[] = {"LinkResolveIgnoreLinkInfo"};
108 static const char strNoCommonGroups[] = {"NoCommonGroups"};
109 static const char strEnforceShlExtSecurity[] = {"EnforceShellExtensionSecurity"};
110 static const char strNoRealMode[] = {"NoRealMode"};
111 static const char strMyDocsOnNet[] = {"MyDocsOnNet"};
112 static const char strNoStartMenuSubfolder[] = {"NoStartMenuSubFolders"};
113 static const char strNoAddPrinters[] = {"NoAddPrinter"};
114 static const char strNoDeletePrinters[] = {"NoDeletePrinter"};
115 static const char strNoPrintTab[] = {"NoPrinterTabs"};
116 static const char strRestrictRun[] = {"RestrictRun"};
117 static const char strNoStartBanner[] = {"NoStartBanner"};
118 static const char strNoNetworkNeighborhood[] = {"NoNetHood"};
119 static const char strNoDriveTypeAtRun[] = {"NoDriveTypeAutoRun"};
120 static const char strNoDrivesAutoRun[] = {"NoDriveAutoRun"};
121 static const char strNoDrives[] = {"NoDrives"};
122 static const char strNoFind[] = {"NoFind"};
123 static const char strNoDesktop[] = {"NoDesktop"};
124 static const char strNoSetTaskBar[] = {"NoSetTaskbar"};
125 static const char strNoSetFld[] = {"NoSetFolders"};
126 static const char strNoFileMenu[] = {"NoFileMenu"};
127 static const char strNoSavSetng[] = {"NoSaveSettings"};
128 static const char strNoClose[] = {"NoClose"};
129 static const char strNoRun[] = {"NoRun"};
131 /* policy data array */
132 POLICYDATA sh32_policy_table[] =
135 0x1,
136 strExplorer,
137 strNoRun,
138 SHELL_NO_POLICY
141 0x2,
142 strExplorer,
143 strNoClose,
144 SHELL_NO_POLICY
147 0x4,
148 strExplorer,
149 strNoSavSetng,
150 SHELL_NO_POLICY
153 0x8,
154 strExplorer,
155 strNoFileMenu,
156 SHELL_NO_POLICY
159 0x10,
160 strExplorer,
161 strNoSetFld,
162 SHELL_NO_POLICY
165 0x20,
166 strExplorer,
167 strNoSetTaskBar,
168 SHELL_NO_POLICY
171 0x40,
172 strExplorer,
173 strNoDesktop,
174 SHELL_NO_POLICY
177 0x80,
178 strExplorer,
179 strNoFind,
180 SHELL_NO_POLICY
183 0x100,
184 strExplorer,
185 strNoDrives,
186 SHELL_NO_POLICY
189 0x200,
190 strExplorer,
191 strNoDrivesAutoRun,
192 SHELL_NO_POLICY
195 0x400,
196 strExplorer,
197 strNoDriveTypeAtRun,
198 SHELL_NO_POLICY
201 0x800,
202 strExplorer,
203 strNoNetworkNeighborhood,
204 SHELL_NO_POLICY
207 0x1000,
208 strExplorer,
209 strNoStartBanner,
210 SHELL_NO_POLICY
213 0x2000,
214 strExplorer,
215 strRestrictRun,
216 SHELL_NO_POLICY
219 0x4000,
220 strExplorer,
221 strNoPrintTab,
222 SHELL_NO_POLICY
225 0x8000,
226 strExplorer,
227 strNoDeletePrinters,
228 SHELL_NO_POLICY
231 0x10000,
232 strExplorer,
233 strNoAddPrinters,
234 SHELL_NO_POLICY
237 0x20000,
238 strExplorer,
239 strNoStartMenuSubfolder,
240 SHELL_NO_POLICY
243 0x40000,
244 strExplorer,
245 strMyDocsOnNet,
246 SHELL_NO_POLICY
249 0x80000,
250 strWinOldApp,
251 strNoRealMode,
252 SHELL_NO_POLICY
255 0x100000,
256 strExplorer,
257 strEnforceShlExtSecurity,
258 SHELL_NO_POLICY
261 0x200000,
262 strExplorer,
263 strLnkResolveIgnoreLnkInfo,
264 SHELL_NO_POLICY
267 0x400000,
268 strExplorer,
269 strNoCommonGroups,
270 SHELL_NO_POLICY
273 0x800000,
274 strExplorer,
275 "SeparateProcess",
276 SHELL_NO_POLICY
279 0x1000000,
280 strExplorer,
281 strNoWebMenu,
282 SHELL_NO_POLICY
285 0x2000000,
286 strExplorer,
287 strNoTryContextMenu,
288 SHELL_NO_POLICY
291 0x4000000,
292 strExplorer,
293 strNoContextMenu,
294 SHELL_NO_POLICY
297 0x8000000,
298 strExplorer,
299 strNoNetConDis,
300 SHELL_NO_POLICY
303 0x10000000,
304 strExplorer,
305 strNoLogoff,
306 SHELL_NO_POLICY
309 0x20000000,
310 strExplorer,
311 strNoStngsWizard,
312 SHELL_NO_POLICY
315 0x40000001,
316 strExplorer,
317 strNoInetIcon,
318 SHELL_NO_POLICY
321 0x40000002,
322 strExplorer,
323 strNoRecentDocHistory,
324 SHELL_NO_POLICY
327 0x40000003,
328 strExplorer,
329 strNoRecentDocMenu,
330 SHELL_NO_POLICY
333 0x40000004,
334 strExplorer,
335 strNoActiveDesktop,
336 SHELL_NO_POLICY
339 0x40000005,
340 strExplorer,
341 strNoActiveDesktopChanges,
342 SHELL_NO_POLICY
345 0x40000006,
346 strExplorer,
347 strNoFavoritesMenu,
348 SHELL_NO_POLICY
351 0x40000007,
352 strExplorer,
353 strClearRecentDocs,
354 SHELL_NO_POLICY
357 0x40000008,
358 strExplorer,
359 strClassicShell,
360 SHELL_NO_POLICY
363 0x40000009,
364 strExplorer,
365 strNoCustomWebView,
366 SHELL_NO_POLICY
369 0x40000010,
370 strActiveDesk,
371 strNoHTMLWallpaper,
372 SHELL_NO_POLICY
375 0x40000011,
376 strActiveDesk,
377 strNoChangeWallpaper,
378 SHELL_NO_POLICY
381 0x40000012,
382 strActiveDesk,
383 strNoComponent,
384 SHELL_NO_POLICY
387 0x40000013,
388 strActiveDesk,
389 strNoAddComponent,
390 SHELL_NO_POLICY
393 0x40000014,
394 strActiveDesk,
395 strNoDelComponent,
396 SHELL_NO_POLICY
399 0x40000015,
400 strActiveDesk,
401 strNoCloseComponent,
402 SHELL_NO_POLICY
405 0x40000016,
406 strActiveDesk,
407 strNoCloseDragDrop,
408 SHELL_NO_POLICY
411 0x40000017,
412 strActiveDesk,
413 strNoMovingBand,
414 SHELL_NO_POLICY
417 0x40000018,
418 strActiveDesk,
419 strNoEditComponent,
420 SHELL_NO_POLICY
423 0x40000019,
424 strExplorer,
425 strNoResolveSearch,
426 SHELL_NO_POLICY
429 0x4000001a,
430 strExplorer,
431 strNoResolveTrk,
432 SHELL_NO_POLICY
435 0x4000001b,
436 strExplorer,
437 strForceCopyACLW,
438 SHELL_NO_POLICY
441 0x4000001c,
442 strExplorer,
443 strNoMSAppLogo,
444 SHELL_NO_POLICY
447 0x4000001d,
448 strExplorer,
449 strNoForgetSoftwareUpdate,
450 SHELL_NO_POLICY
453 0x4000001e,
454 strExplorer,
455 strNoSetActiveDesktop,
456 SHELL_NO_POLICY
459 0x4000001f,
460 strExplorer,
461 strNoWindowsUpdate,
462 SHELL_NO_POLICY
465 0x40000020,
466 strExplorer,
467 strNoChangeStartMenu,
468 SHELL_NO_POLICY
471 0x40000021,
472 strExplorer,
473 strNoFolderOptions,
474 SHELL_NO_POLICY
477 0x50000024,
478 strExplorer,
479 strNoFileURL,
480 SHELL_NO_POLICY
483 0x40000022,
484 strExplorer,
485 "FindComputers",
486 SHELL_NO_POLICY
489 0x40000023,
490 strExplorer,
491 "IntelliMenus",
492 SHELL_NO_POLICY
495 0x40000024,
496 strExplorer,
497 "MemCheckBoxInRunDlg",
498 SHELL_NO_POLICY
501 0x40000025,
502 strAddRemoveProgs,
503 "ShowPostSetup",
504 SHELL_NO_POLICY
507 0x40000026,
508 strExplorer,
509 "NoSyncAll",
510 SHELL_NO_POLICY
513 0x40000027,
514 strExplorer,
515 "NoControlPanel",
516 SHELL_NO_POLICY
519 0x40000028,
520 strExplorer,
521 "EnumWorkgroup",
522 SHELL_NO_POLICY
525 0x40000029,
526 strAddRemoveProgs,
527 "NoAddRemovePrograms",
528 SHELL_NO_POLICY
531 0x4000002A,
532 strAddRemoveProgs,
533 "NoRemovePage",
534 SHELL_NO_POLICY
537 0x4000002B,
538 strAddRemoveProgs,
539 "NoAddPage",
540 SHELL_NO_POLICY
543 0x4000002C,
544 strAddRemoveProgs,
545 "NoWindowsSetupPage",
546 SHELL_NO_POLICY
549 0x4000002E,
550 strExplorer,
551 "NoChangeMappedDriveLabel",
552 SHELL_NO_POLICY
555 0x4000002F,
556 strExplorer,
557 "NoChangeMappedDriveComment",
558 SHELL_NO_POLICY
561 0x40000030,
562 strExplorer,
563 "MaxRecentDocs",
564 SHELL_NO_POLICY
567 0x40000031,
568 strExplorer,
569 "NoNetworkConnections",
570 SHELL_NO_POLICY
573 0x40000032,
574 strExplorer,
575 "ForceStartMenuLogoff",
576 SHELL_NO_POLICY
579 0x40000033,
580 strExplorer,
581 "NoWebView",
582 SHELL_NO_POLICY
585 0x40000034,
586 strExplorer,
587 "NoCustomizeThisFolder",
588 SHELL_NO_POLICY
591 0x40000035,
592 strExplorer,
593 "NoEncryption",
594 SHELL_NO_POLICY
597 0x40000036,
598 strExplorer,
599 "AllowFrenchEncryption",
600 SHELL_NO_POLICY
603 0x40000037,
604 strExplorer,
605 "DontShowSuperHidden",
606 SHELL_NO_POLICY
609 0x40000038,
610 strExplorer,
611 "NoShellSearchButton",
612 SHELL_NO_POLICY
615 0x40000039,
616 strExplorer,
617 "NoHardwareTab",
618 SHELL_NO_POLICY
621 0x4000003A,
622 strExplorer,
623 "NoRunasInstallPrompt",
624 SHELL_NO_POLICY
627 0x4000003B,
628 strExplorer,
629 "PromptRunasInstallNetPath",
630 SHELL_NO_POLICY
633 0x4000003C,
634 strExplorer,
635 "NoManageMyComputerVerb",
636 SHELL_NO_POLICY
639 0x4000003D,
640 strExplorer,
641 "NoRecentDocsNetHood",
642 SHELL_NO_POLICY
645 0x4000003E,
646 strExplorer,
647 "DisallowRun",
648 SHELL_NO_POLICY
651 0x4000003F,
652 strExplorer,
653 "NoWelcomeScreen",
654 SHELL_NO_POLICY
657 0x40000040,
658 strExplorer,
659 "RestrictCpl",
660 SHELL_NO_POLICY
663 0x40000041,
664 strExplorer,
665 "DisallowCpl",
666 SHELL_NO_POLICY
669 0x40000042,
670 strExplorer,
671 "NoSMBalloonTip",
672 SHELL_NO_POLICY
675 0x40000043,
676 strExplorer,
677 "NoSMHelp",
678 SHELL_NO_POLICY
681 0x40000044,
682 strExplorer,
683 "NoWinKeys",
684 SHELL_NO_POLICY
687 0x40000045,
688 strExplorer,
689 "NoEncryptOnMove",
690 SHELL_NO_POLICY
693 0x40000046,
694 strExplorer,
695 "DisableLocalMachineRun",
696 SHELL_NO_POLICY
699 0x40000047,
700 strExplorer,
701 "DisableCurrentUserRun",
702 SHELL_NO_POLICY
705 0x40000048,
706 strExplorer,
707 "DisableLocalMachineRunOnce",
708 SHELL_NO_POLICY
711 0x40000049,
712 strExplorer,
713 "DisableCurrentUserRunOnce",
714 SHELL_NO_POLICY
717 0x4000004A,
718 strExplorer,
719 "ForceActiveDesktopOn",
720 SHELL_NO_POLICY
723 0x4000004B,
724 strExplorer,
725 "NoComputersNearMe",
726 SHELL_NO_POLICY
729 0x4000004C,
730 strExplorer,
731 "NoViewOnDrive",
732 SHELL_NO_POLICY
735 0x4000004F,
736 strExplorer,
737 "NoSMMyDocs",
738 SHELL_NO_POLICY
741 0x40000061,
742 strExplorer,
743 "StartRunNoHOMEPATH",
744 SHELL_NO_POLICY
747 0x41000001,
748 strExplorer,
749 "NoDisconnect",
750 SHELL_NO_POLICY
753 0x41000002,
754 strExplorer,
755 "NoNTSecurity",
756 SHELL_NO_POLICY
759 0x41000003,
760 strExplorer,
761 "NoFileAssociate",
762 SHELL_NO_POLICY
768 SHELL_NO_POLICY
772 /*************************************************************************
773 * SHRestricted [SHELL32.100]
775 * Get the value associated with a policy Id.
777 * PARAMS
778 * pol [I] Policy Id
780 * RETURNS
781 * The queried value for the policy.
783 * NOTES
784 * Exported by ordinal.
785 * This function caches the retrieved values to prevent unnecessary registry access,
786 * if SHInitRestricted() was previously called.
788 * REFERENCES
789 * a: MS System Policy Editor.
790 * b: 98Lite 2.0 (which uses many of these policy keys) http://www.98lite.net/
791 * c: 'The Windows 95 Registry', by John Woram, 1996 MIS: Press
793 DWORD WINAPI SHRestricted (DWORD policy)
795 char regstr[256];
796 HKEY xhkey;
797 DWORD retval, datsize = 4;
798 LPPOLICYDATA p;
800 TRACE("(%08lx)\n", policy);
802 /* scan to see if we know this policy ID */
803 for (p = sh32_policy_table; p->policy; p++)
805 if (policy == p->policy)
807 break;
811 if (p->policy == 0)
813 /* we don't know this policy, return 0 */
814 TRACE("unknown policy: (%08lx)\n", policy);
815 return 0;
818 /* we have a known policy */
820 /* first check if this policy has been cached, return it if so */
821 if (p->cache != SHELL_NO_POLICY)
823 return p->cache;
826 lstrcpyA(regstr, strRegistryPolicyA);
827 lstrcatA(regstr, p->appstr);
829 /* return 0 and don't set the cache if any registry errors occur */
830 retval = 0;
831 if (RegOpenKeyA(HKEY_CURRENT_USER, regstr, &xhkey) == ERROR_SUCCESS)
833 if (RegQueryValueExA(xhkey, p->keystr, NULL, NULL, (LPBYTE)&retval, &datsize) == ERROR_SUCCESS)
835 p->cache = retval;
837 RegCloseKey(xhkey);
839 return retval;
842 /*************************************************************************
843 * SHInitRestricted [SHELL32.244]
845 * Initialise the policy cache to speed up calls to SHRestricted().
847 * PARAMS
848 * unused [I] Reserved.
849 * inpRegKey [I] Registry key to scan.
851 * RETURNS
852 * Success: -1. The policy cache is initialised.
853 * Failure: 0, if inpRegKey is any value other than NULL, "Policy", or
854 * "Software\Microsoft\Windows\CurrentVersion\Policies".
856 * NOTES
857 * Exported by ordinal. Introduced in Win98.
859 BOOL WINAPI SHInitRestricted(LPCVOID unused, LPCVOID inpRegKey)
861 LPPOLICYDATA p;
863 TRACE("(%p, %p)\n", unused, inpRegKey);
865 /* first check - if input is non-NULL and points to the secret
866 key string, then pass. Otherwise return 0.
868 if (inpRegKey != NULL)
870 if (SHELL_OsIsUnicode())
872 if (lstrcmpiW((LPWSTR)inpRegKey, strRegistryPolicyW) &&
873 lstrcmpiW((LPWSTR)inpRegKey, strPolicyW))
874 /* doesn't match, fail */
875 return 0;
877 else
879 if (lstrcmpiA((LPSTR)inpRegKey, strRegistryPolicyA) &&
880 lstrcmpiA((LPSTR)inpRegKey, strPolicyA))
881 /* doesn't match, fail */
882 return 0;
886 /* check passed, init all policy cache entries with SHELL_NO_POLICY */
887 for (p = sh32_policy_table; p->policy; p++)
889 p->cache = SHELL_NO_POLICY;
891 return SHELL_NO_POLICY;