Implement ResetDC and PHYSICALOFFSET[X|Y] devcaps.
[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 //extern POLICYDATA sh32_policy_table[SHELL_MAX_POLICIES];
59
60 /* application strings */
61
62 static char strExplorer[] = {"Explorer"};
63 static char strActiveDesk[] = {"ActiveDesktop"};
64 static char strWinOldApp[] = {"WinOldApp"};
65
66 /* key strings */
67
68 static char strNoFileURL[] = {"NoFileUrl"};
69 static char strNoFolderOptions[] = {"NoFolderOptions"};
70 static char strNoChangeStartMenu[] = {"NoChangeStartMenu"};
71 static char strNoWindowsUpdate[] = {"NoWindowsUpdate"};
72 static char strNoSetActiveDesktop[] = {"NoSetActiveDesktop"};
73 static char strNoForgetSoftwareUpdate[] = {"NoForgetSoftwareUpdate"};
74 static char strNoMSAppLogo[] = {"NoMSAppLogo5ChannelNotify"};
75 static char strForceCopyACLW[] = {"ForceCopyACLWithFile"};
76 static char strNoResolveTrk[] = {"NoResolveTrack"};
77 static char strNoResolveSearch[] = {"NoResolveSearch"};
78 static char strNoEditComponent[] = {"NoEditingComponents"};
79 static char strNoMovingBand[] = {"NoMovingBands"};
80 static char strNoCloseDragDrop[] = {"NoCloseDragDropBands"};
81 static char strNoCloseComponent[] = {"NoClosingComponents"};
82 static char strNoDelComponent[] = {"NoDeletingComponents"};
83 static char strNoAddComponent[] = {"NoAddingComponents"};
84 static char strNoComponent[] = {"NoComponents"};
85 static char strNoChangeWallpaper[] = {"NoChangingWallpaper"};
86 static char strNoHTMLWallpaper[] = {"NoHTMLWallpaper"};
87 static char strNoCustomWebView[] = {"NoCustomizeWebView"};
88 static char strClassicShell[] = {"ClassicShell"};
89 static char strClearRecentDocs[] = {"ClearRecentDocsOnExit"};
90 static char strNoFavoritesMenu[] = {"NoFavoritesMenu"};
91 static char strNoActiveDesktopChanges[] = {"NoActiveDesktopChanges"};
92 static char strNoActiveDesktop[] = {"NoActiveDesktop"};
93 static char strNoRecentDocMenu[] = {"NoRecentDocsMenu"};
94 static char strNoRecentDocHistory[] = {"NoRecentDocsHistory"};
95 static char strNoInetIcon[] = {"NoInternetIcon"};
96 static char strNoStngsWizard[] = {"NoSettingsWizards"};
97 static char strNoLogoff[] = {"NoLogoff"};
98 static char strNoNetConDis[] = {"NoNetConnectDisconnect"};
99 static char strNoContextMenu[] = {"NoViewContextMenu"};
100 static char strNoTryContextMenu[] = {"NoTrayContextMenu"};
101 static char strNoWebMenu[] = {"NoWebMenu"};
102 static char strLnkResolveIgnoreLnkInfo[] = {"LinkResolveIgnoreLinkInfo"};
103 static char strNoCommonGroups[] = {"NoCommonGroups"};
104 static char strEnforceShlExtSecurity[] = {"EnforceShellExtensionSecurity"};
105 static char strNoRealMode[] = {"NoRealMode"};
106 static char strMyDocsOnNet[] = {"MyDocsOnNet"};
107 static char strNoStartMenuSubfolder[] = {"NoStartMenuSubFolders"};
108 static char strNoAddPrinters[] = {"NoAddPrinter"};
109 static char strNoDeletePrinters[] = {"NoDeletePrinter"};
110 static char strNoPrintTab[] = {"NoPrinterTabs"};
111 static char strRestrictRun[] = {"RestrictRun"};
112 static char strNoStartBanner[] = {"NoStartBanner"};
113 static char strNoNetworkNeighborhood[] = {"NoNetHood"};
114 static char strNoDriveTypeAtRun[] = {"NoDriveTypeAutoRun"};
115 static char strNoDrivesAutoRun[] = {"NoDriveAutoRun"};
116 static char strNoDrives[] = {"NoDrives"};
117 static char strNoFind[] = {"NoFind"};
118 static char strNoDesktop[] = {"NoDesktop"};
119 static char strNoSetTaskBar[] = {"NoSetTaskbar"};
120 static char strNoSetFld[] = {"NoSetFolders"};
121 static char strNoFileMenu[] = {"NoFileMenu"};
122 static char strNoSavSetng[] = {"NoSaveSettings"};
123 static char strNoClose[] = {"NoClose"};
124 static char strNoRun[] = {"NoRun"};
125
126 /* policy data array */
127
128 POLICYDATA sh32_policy_table[] = 
129 {
130   {
131     0x1,
132     strExplorer,
133     strNoRun,
134     SHELL_NO_POLICY
135   },
136   {
137     0x2,
138     strExplorer,
139     strNoClose,
140     SHELL_NO_POLICY
141   },
142   {
143     0x4,
144     strExplorer,
145     strNoSavSetng,
146     SHELL_NO_POLICY
147   },
148   {
149     0x8,
150     strExplorer,
151     strNoFileMenu,
152     SHELL_NO_POLICY
153   },
154   {
155     0x10,
156     strExplorer,
157     strNoSetFld,
158     SHELL_NO_POLICY
159   },
160   {
161     0x20,
162     strExplorer,
163     strNoSetTaskBar,
164     SHELL_NO_POLICY
165   },
166   {
167     0x40,
168     strExplorer,
169     strNoDesktop,
170     SHELL_NO_POLICY
171   },
172   {
173     0x80,
174     strExplorer,
175     strNoFind,
176     SHELL_NO_POLICY
177   },
178   {
179     0x100,
180     strExplorer,
181     strNoDrives,
182     SHELL_NO_POLICY
183   },
184   {
185     0x200,
186     strExplorer,
187     strNoDrivesAutoRun,
188     SHELL_NO_POLICY
189   },
190   {
191     0x400,
192     strExplorer,
193     strNoDriveTypeAtRun,
194     SHELL_NO_POLICY
195   },
196   {
197     0x800,
198     strExplorer,
199     strNoNetworkNeighborhood,
200     SHELL_NO_POLICY
201   },
202   {
203     0x1000,
204     strExplorer,
205     strNoStartBanner,
206     SHELL_NO_POLICY
207   },
208   {
209     0x2000,
210     strExplorer,
211     strRestrictRun,
212     SHELL_NO_POLICY
213   },
214   {
215     0x4000,
216     strExplorer,
217     strNoPrintTab,
218     SHELL_NO_POLICY
219   },
220   {
221     0x8000,
222     strExplorer,
223     strNoDeletePrinters,
224     SHELL_NO_POLICY
225   },
226   {
227     0x10000,
228     strExplorer,
229     strNoAddPrinters,
230     SHELL_NO_POLICY
231   },
232   {
233     0x20000,
234     strExplorer,
235     strNoStartMenuSubfolder,
236     SHELL_NO_POLICY
237   },
238   {
239     0x40000,
240     strExplorer,
241     strMyDocsOnNet,
242     SHELL_NO_POLICY
243   },
244   {
245     0x80000,
246     strWinOldApp,
247     strNoRealMode,
248     SHELL_NO_POLICY
249   },
250   {
251     0x100000,
252     strExplorer,
253     strEnforceShlExtSecurity,
254     SHELL_NO_POLICY
255   },
256   {
257     0x200000,
258     strExplorer,
259     strLnkResolveIgnoreLnkInfo,
260     SHELL_NO_POLICY
261   },
262   {
263     0x400000,
264     strExplorer,
265     strNoCommonGroups,
266     SHELL_NO_POLICY
267   },
268   {
269     0x1000000,
270     strExplorer,
271     strNoWebMenu,
272     SHELL_NO_POLICY
273   },
274   {
275     0x2000000,
276     strExplorer,
277     strNoTryContextMenu,
278     SHELL_NO_POLICY
279   },
280   {
281     0x4000000,
282     strExplorer,
283     strNoContextMenu,
284     SHELL_NO_POLICY
285   },
286   {
287     0x8000000,
288     strExplorer,
289     strNoNetConDis,
290     SHELL_NO_POLICY
291   },
292   {
293     0x10000000,
294     strExplorer,
295     strNoLogoff,
296     SHELL_NO_POLICY
297   },
298   {
299     0x20000000,
300     strExplorer,
301     strNoStngsWizard,
302     SHELL_NO_POLICY
303   },
304   {
305     0x40000001,
306     strExplorer,
307     strNoInetIcon,
308     SHELL_NO_POLICY
309   },
310   {
311     0x40000002,
312     strExplorer,
313     strNoRecentDocHistory,
314     SHELL_NO_POLICY
315   },
316   {
317     0x40000003,
318     strExplorer,
319     strNoRecentDocMenu,
320     SHELL_NO_POLICY
321   },
322   {
323     0x40000004,
324     strExplorer,
325     strNoActiveDesktop,
326     SHELL_NO_POLICY
327   },
328   {
329     0x40000005,
330     strExplorer,
331     strNoActiveDesktopChanges,
332     SHELL_NO_POLICY
333   },
334   {
335     0x40000006,
336     strExplorer,
337     strNoFavoritesMenu,
338     SHELL_NO_POLICY
339   },
340   {
341     0x40000007,
342     strExplorer,
343     strClearRecentDocs,
344     SHELL_NO_POLICY
345   },
346   {
347     0x40000008,
348     strExplorer,
349     strClassicShell,
350     SHELL_NO_POLICY
351   },
352   {
353     0x40000009,
354     strExplorer,
355     strNoCustomWebView,
356     SHELL_NO_POLICY
357   },
358   {
359     0x40000010,
360     strActiveDesk,
361     strNoHTMLWallpaper,
362     SHELL_NO_POLICY
363   },
364   {
365     0x40000011,
366     strActiveDesk,
367     strNoChangeWallpaper,
368     SHELL_NO_POLICY
369   },
370   {
371     0x40000012,
372     strActiveDesk,
373     strNoComponent,
374     SHELL_NO_POLICY
375   },
376   {
377     0x40000013,
378     strActiveDesk,
379     strNoAddComponent,
380     SHELL_NO_POLICY
381   },
382   {
383     0x40000014,
384     strActiveDesk,
385     strNoDelComponent,
386     SHELL_NO_POLICY
387   },
388   {
389     0x40000015,
390     strActiveDesk,
391     strNoCloseComponent,
392     SHELL_NO_POLICY
393   },
394   {
395     0x40000016,
396     strActiveDesk,
397     strNoCloseDragDrop,
398     SHELL_NO_POLICY
399   },
400   {
401     0x40000017,
402     strActiveDesk,
403     strNoMovingBand,
404     SHELL_NO_POLICY
405   },
406   {
407     0x40000018,
408     strActiveDesk,
409     strNoEditComponent,
410     SHELL_NO_POLICY
411   },
412   {
413     0x40000019,
414     strExplorer,
415     strNoResolveSearch,
416     SHELL_NO_POLICY
417   },
418   {
419     0x4000001a,
420     strExplorer,
421     strNoResolveTrk,
422     SHELL_NO_POLICY
423   },
424   {
425     0x4000001b,
426     strExplorer,
427     strForceCopyACLW,
428     SHELL_NO_POLICY
429   },
430   {
431     0x4000001c,
432     strExplorer,
433     strNoMSAppLogo,
434     SHELL_NO_POLICY
435   },
436   {
437     0x4000001d,
438     strExplorer,
439     strNoForgetSoftwareUpdate,
440     SHELL_NO_POLICY
441   },
442   {
443     0x4000001e,
444     strExplorer,
445     strNoSetActiveDesktop,
446     SHELL_NO_POLICY
447   },
448   {
449     0x4000001f,
450     strExplorer,
451     strNoWindowsUpdate,
452     SHELL_NO_POLICY
453   },
454   {
455     0x40000020,
456     strExplorer,
457     strNoChangeStartMenu,
458     SHELL_NO_POLICY
459   },
460   {
461     0x40000021,
462     strExplorer,
463     strNoFolderOptions,
464     SHELL_NO_POLICY
465   },
466   {
467     0x50000024,
468     strExplorer,
469     strNoFileURL,
470     SHELL_NO_POLICY
471   }
472 };
473
474 /*************************************************************************
475  * SHRestricted                         [SHELL32.100]
476  *
477  * walks through policy table, queries <app> key, <type> value, returns 
478  * queried (DWORD) value, and caches it between called to SHInitRestricted
479  * to prevent unnecessary registry access.
480  *
481  * NOTES
482  *     exported by ordinal
483  *
484  * REFERENCES: 
485  *     MS System Policy Editor
486  *     98Lite 2.0 (which uses many of these policy keys) http://www.98lite.net/
487  *     "The Windows 95 Registry", by John Woram, 1996 MIS: Press
488  */
489 DWORD WINAPI SHRestricted (DWORD pol) {
490         char regstr[256];
491         HKEY    xhkey;
492         DWORD   retval, polidx, i, datsize = 4;
493
494         TRACE("(%08lx)\n",pol);
495
496         polidx = -1;
497
498         /* scan to see if we know this policy ID */
499         for (i = 0; i < SHELL_MAX_POLICIES; i++)
500         {
501              if (pol == sh32_policy_table[i].polflags)
502              {
503                  polidx = i;
504                  break;
505              }
506         }
507
508         if (polidx == -1)
509         {
510             /* we don't know this policy, return 0 */
511             TRACE("unknown policy: (%08lx)\n", pol);
512                 return 0;
513         }
514
515         /* we have a known policy */
516         strcpy(regstr, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\");
517         strcat(regstr, sh32_policy_table[polidx].appstr);
518
519         /* first check if this policy has been cached, return it if so */
520         if (sh32_policy_table[polidx].cache != SHELL_NO_POLICY)
521         {
522             return sh32_policy_table[polidx].cache;
523         }
524
525         /* return 0 and don't set the cache if any registry errors occur */
526         retval = 0;
527         if (RegOpenKeyA(HKEY_CURRENT_USER, regstr, &xhkey) == ERROR_SUCCESS)
528         {
529             if (RegQueryValueExA(xhkey, sh32_policy_table[polidx].keystr, NULL, NULL, (LPBYTE)&retval, &datsize) == ERROR_SUCCESS)
530             {
531                 sh32_policy_table[polidx].cache = retval;
532             }
533
534             RegCloseKey(xhkey);
535         }
536
537         return retval;
538 }
539
540 /*************************************************************************
541  *      SHInitRestricted                         [SHELL32.244]
542  *
543  * Win98+ by-ordinal only routine called by Explorer and MSIE 4 and 5.
544  * Inits the policy cache used by SHRestricted to avoid excess
545  * registry access.
546  *
547  * INPUTS
548  * Two inputs: one is a string or NULL.  If non-NULL the pointer
549  * should point to a string containing the following exact text:
550  * "Software\Microsoft\Windows\CurrentVersion\Policies".
551  * The other input is unused.
552  *
553  * NOTES
554  * If the input is non-NULL and does not point to a string containing
555  * that exact text the routine will do nothing.
556  *
557  * If the text does match or the pointer is NULL, then the routine
558  * will init SHRestricted()'s policy cache to all 0xffffffff and
559  * returns 0xffffffff as well.
560  *
561  * I haven't yet run into anything calling this with inputs other than
562  * (NULL, NULL), so I may have the inputs reversed.
563  */
564
565 BOOL WINAPI SHInitRestricted(LPSTR inpRegKey, LPSTR parm2)
566 {
567      int i;
568
569      TRACE("(%p, %p)\n", inpRegKey, parm2);
570
571      /* first check - if input is non-NULL and points to the secret
572         key string, then pass.  Otherwise return 0.
573      */
574
575      if (inpRegKey != (LPSTR)NULL)
576      {
577          if (lstrcmpiA(inpRegKey, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies"))
578          {
579              /* doesn't match, fail */
580              return 0;
581          }
582      }                               
583
584      /* check passed, init all policy cache entries with SHELL_NO_POLICY */
585      for (i = 0; i < SHELL_MAX_POLICIES; i++)
586      {
587           sh32_policy_table[i].cache = SHELL_NO_POLICY;
588      }
589
590      return SHELL_NO_POLICY;
591 }