Add SHDefExtractIcon{AW} function.
[wine] / dlls / shell32 / shpolicy.c
1 /*
2  * shpolicy.c - Data for shell/system policies.
3  *
4  * Copyright 1999 Ian Schmidt <ischmidt@cfl.rr.com>
5  *
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.
10  *
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.
15  *
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
19  *
20  * NOTES:
21  *
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...
28  *
29  * Up to date as of SHELL32 v4.72 (Win98, Win95 with MSIE 5)
30  */
31
32 #include <stdlib.h>
33 #include <string.h>
34
35 #include "windef.h"
36 #include "winerror.h"
37 #include "winreg.h"
38
39 #include "undocshell.h"
40 #include "wine/winuser16.h"
41
42 #include "wine/debug.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(shell);
45
46 #define SHELL_MAX_POLICIES 57
47
48 #define SHELL_NO_POLICY 0xffffffff
49
50 typedef struct tagPOLICYDAT
51 {
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;
57
58 #if 0
59 extern POLICYDATA sh32_policy_table[SHELL_MAX_POLICIES];
60 #endif
61
62 /* application strings */
63
64 static char strExplorer[] = {"Explorer"};
65 static char strActiveDesk[] = {"ActiveDesktop"};
66 static char strWinOldApp[] = {"WinOldApp"};
67
68 /* key strings */
69
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"};
127
128 /* policy data array */
129
130 POLICYDATA sh32_policy_table[] =
131 {
132   {
133     0x1,
134     strExplorer,
135     strNoRun,
136     SHELL_NO_POLICY
137   },
138   {
139     0x2,
140     strExplorer,
141     strNoClose,
142     SHELL_NO_POLICY
143   },
144   {
145     0x4,
146     strExplorer,
147     strNoSavSetng,
148     SHELL_NO_POLICY
149   },
150   {
151     0x8,
152     strExplorer,
153     strNoFileMenu,
154     SHELL_NO_POLICY
155   },
156   {
157     0x10,
158     strExplorer,
159     strNoSetFld,
160     SHELL_NO_POLICY
161   },
162   {
163     0x20,
164     strExplorer,
165     strNoSetTaskBar,
166     SHELL_NO_POLICY
167   },
168   {
169     0x40,
170     strExplorer,
171     strNoDesktop,
172     SHELL_NO_POLICY
173   },
174   {
175     0x80,
176     strExplorer,
177     strNoFind,
178     SHELL_NO_POLICY
179   },
180   {
181     0x100,
182     strExplorer,
183     strNoDrives,
184     SHELL_NO_POLICY
185   },
186   {
187     0x200,
188     strExplorer,
189     strNoDrivesAutoRun,
190     SHELL_NO_POLICY
191   },
192   {
193     0x400,
194     strExplorer,
195     strNoDriveTypeAtRun,
196     SHELL_NO_POLICY
197   },
198   {
199     0x800,
200     strExplorer,
201     strNoNetworkNeighborhood,
202     SHELL_NO_POLICY
203   },
204   {
205     0x1000,
206     strExplorer,
207     strNoStartBanner,
208     SHELL_NO_POLICY
209   },
210   {
211     0x2000,
212     strExplorer,
213     strRestrictRun,
214     SHELL_NO_POLICY
215   },
216   {
217     0x4000,
218     strExplorer,
219     strNoPrintTab,
220     SHELL_NO_POLICY
221   },
222   {
223     0x8000,
224     strExplorer,
225     strNoDeletePrinters,
226     SHELL_NO_POLICY
227   },
228   {
229     0x10000,
230     strExplorer,
231     strNoAddPrinters,
232     SHELL_NO_POLICY
233   },
234   {
235     0x20000,
236     strExplorer,
237     strNoStartMenuSubfolder,
238     SHELL_NO_POLICY
239   },
240   {
241     0x40000,
242     strExplorer,
243     strMyDocsOnNet,
244     SHELL_NO_POLICY
245   },
246   {
247     0x80000,
248     strWinOldApp,
249     strNoRealMode,
250     SHELL_NO_POLICY
251   },
252   {
253     0x100000,
254     strExplorer,
255     strEnforceShlExtSecurity,
256     SHELL_NO_POLICY
257   },
258   {
259     0x200000,
260     strExplorer,
261     strLnkResolveIgnoreLnkInfo,
262     SHELL_NO_POLICY
263   },
264   {
265     0x400000,
266     strExplorer,
267     strNoCommonGroups,
268     SHELL_NO_POLICY
269   },
270   {
271     0x1000000,
272     strExplorer,
273     strNoWebMenu,
274     SHELL_NO_POLICY
275   },
276   {
277     0x2000000,
278     strExplorer,
279     strNoTryContextMenu,
280     SHELL_NO_POLICY
281   },
282   {
283     0x4000000,
284     strExplorer,
285     strNoContextMenu,
286     SHELL_NO_POLICY
287   },
288   {
289     0x8000000,
290     strExplorer,
291     strNoNetConDis,
292     SHELL_NO_POLICY
293   },
294   {
295     0x10000000,
296     strExplorer,
297     strNoLogoff,
298     SHELL_NO_POLICY
299   },
300   {
301     0x20000000,
302     strExplorer,
303     strNoStngsWizard,
304     SHELL_NO_POLICY
305   },
306   {
307     0x40000001,
308     strExplorer,
309     strNoInetIcon,
310     SHELL_NO_POLICY
311   },
312   {
313     0x40000002,
314     strExplorer,
315     strNoRecentDocHistory,
316     SHELL_NO_POLICY
317   },
318   {
319     0x40000003,
320     strExplorer,
321     strNoRecentDocMenu,
322     SHELL_NO_POLICY
323   },
324   {
325     0x40000004,
326     strExplorer,
327     strNoActiveDesktop,
328     SHELL_NO_POLICY
329   },
330   {
331     0x40000005,
332     strExplorer,
333     strNoActiveDesktopChanges,
334     SHELL_NO_POLICY
335   },
336   {
337     0x40000006,
338     strExplorer,
339     strNoFavoritesMenu,
340     SHELL_NO_POLICY
341   },
342   {
343     0x40000007,
344     strExplorer,
345     strClearRecentDocs,
346     SHELL_NO_POLICY
347   },
348   {
349     0x40000008,
350     strExplorer,
351     strClassicShell,
352     SHELL_NO_POLICY
353   },
354   {
355     0x40000009,
356     strExplorer,
357     strNoCustomWebView,
358     SHELL_NO_POLICY
359   },
360   {
361     0x40000010,
362     strActiveDesk,
363     strNoHTMLWallpaper,
364     SHELL_NO_POLICY
365   },
366   {
367     0x40000011,
368     strActiveDesk,
369     strNoChangeWallpaper,
370     SHELL_NO_POLICY
371   },
372   {
373     0x40000012,
374     strActiveDesk,
375     strNoComponent,
376     SHELL_NO_POLICY
377   },
378   {
379     0x40000013,
380     strActiveDesk,
381     strNoAddComponent,
382     SHELL_NO_POLICY
383   },
384   {
385     0x40000014,
386     strActiveDesk,
387     strNoDelComponent,
388     SHELL_NO_POLICY
389   },
390   {
391     0x40000015,
392     strActiveDesk,
393     strNoCloseComponent,
394     SHELL_NO_POLICY
395   },
396   {
397     0x40000016,
398     strActiveDesk,
399     strNoCloseDragDrop,
400     SHELL_NO_POLICY
401   },
402   {
403     0x40000017,
404     strActiveDesk,
405     strNoMovingBand,
406     SHELL_NO_POLICY
407   },
408   {
409     0x40000018,
410     strActiveDesk,
411     strNoEditComponent,
412     SHELL_NO_POLICY
413   },
414   {
415     0x40000019,
416     strExplorer,
417     strNoResolveSearch,
418     SHELL_NO_POLICY
419   },
420   {
421     0x4000001a,
422     strExplorer,
423     strNoResolveTrk,
424     SHELL_NO_POLICY
425   },
426   {
427     0x4000001b,
428     strExplorer,
429     strForceCopyACLW,
430     SHELL_NO_POLICY
431   },
432   {
433     0x4000001c,
434     strExplorer,
435     strNoMSAppLogo,
436     SHELL_NO_POLICY
437   },
438   {
439     0x4000001d,
440     strExplorer,
441     strNoForgetSoftwareUpdate,
442     SHELL_NO_POLICY
443   },
444   {
445     0x4000001e,
446     strExplorer,
447     strNoSetActiveDesktop,
448     SHELL_NO_POLICY
449   },
450   {
451     0x4000001f,
452     strExplorer,
453     strNoWindowsUpdate,
454     SHELL_NO_POLICY
455   },
456   {
457     0x40000020,
458     strExplorer,
459     strNoChangeStartMenu,
460     SHELL_NO_POLICY
461   },
462   {
463     0x40000021,
464     strExplorer,
465     strNoFolderOptions,
466     SHELL_NO_POLICY
467   },
468   {
469     0x50000024,
470     strExplorer,
471     strNoFileURL,
472     SHELL_NO_POLICY
473   }
474 };
475
476 /*************************************************************************
477  * SHRestricted                         [SHELL32.100]
478  *
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.
482  *
483  * NOTES
484  *     exported by ordinal
485  *
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
490  */
491 DWORD WINAPI SHRestricted (DWORD pol) {
492         char regstr[256];
493         HKEY    xhkey;
494         DWORD   retval, polidx, i, datsize = 4;
495
496         TRACE("(%08lx)\n",pol);
497
498         polidx = -1;
499
500         /* scan to see if we know this policy ID */
501         for (i = 0; i < SHELL_MAX_POLICIES; i++)
502         {
503              if (pol == sh32_policy_table[i].polflags)
504              {
505                  polidx = i;
506                  break;
507              }
508         }
509
510         if (polidx == -1)
511         {
512             /* we don't know this policy, return 0 */
513             TRACE("unknown policy: (%08lx)\n", pol);
514                 return 0;
515         }
516
517         /* we have a known policy */
518         strcpy(regstr, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\");
519         strcat(regstr, sh32_policy_table[polidx].appstr);
520
521         /* first check if this policy has been cached, return it if so */
522         if (sh32_policy_table[polidx].cache != SHELL_NO_POLICY)
523         {
524             return sh32_policy_table[polidx].cache;
525         }
526
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)
530         {
531             if (RegQueryValueExA(xhkey, sh32_policy_table[polidx].keystr, NULL, NULL, (LPBYTE)&retval, &datsize) == ERROR_SUCCESS)
532             {
533                 sh32_policy_table[polidx].cache = retval;
534             }
535
536             RegCloseKey(xhkey);
537         }
538
539         return retval;
540 }
541
542 /*************************************************************************
543  *      SHInitRestricted                         [SHELL32.244]
544  *
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.
548  *
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.
554  *
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.
558  *
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.
562  *
563  * I haven't yet run into anything calling this with inputs other than
564  * (NULL, NULL), so I may have the inputs reversed.
565  */
566
567 BOOL WINAPI SHInitRestricted(LPSTR inpRegKey, LPSTR parm2)
568 {
569      int i;
570
571      TRACE("(%p, %p)\n", inpRegKey, parm2);
572
573      /* first check - if input is non-NULL and points to the secret
574         key string, then pass.  Otherwise return 0.
575      */
576
577      if (inpRegKey != (LPSTR)NULL)
578      {
579          if (lstrcmpiA(inpRegKey, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies"))
580          {
581              /* doesn't match, fail */
582              return 0;
583          }
584      }
585
586      /* check passed, init all policy cache entries with SHELL_NO_POLICY */
587      for (i = 0; i < SHELL_MAX_POLICIES; i++)
588      {
589           sh32_policy_table[i].cache = SHELL_NO_POLICY;
590      }
591
592      return SHELL_NO_POLICY;
593 }