libwine: Add a minor number to the library filename for future extensions.
[wine] / dlls / urlmon / sec_mgr.c
1 /*
2  * Internet Security and Zone Manager
3  *
4  * Copyright (c) 2004 Huw D M Davies
5  * Copyright 2004 Jacek Caban
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include <stdarg.h>
23 #include <stdio.h>
24
25 #define COBJMACROS
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winreg.h"
31 #include "wine/debug.h"
32 #include "ole2.h"
33 #include "wine/unicode.h"
34 #include "urlmon.h"
35 #include "urlmon_main.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
38
39 /***********************************************************************
40  *           InternetSecurityManager implementation
41  *
42  */
43 typedef struct {
44     const IInternetSecurityManagerVtbl* lpInternetSecurityManagerVtbl;
45
46     LONG ref;
47
48     IInternetSecurityMgrSite *mgrsite;
49     IInternetSecurityManager *custom_manager;
50 } SecManagerImpl;
51
52 #define SECMGR_THIS(iface) DEFINE_THIS(SecManagerImpl, InternetSecurityManager, iface)
53
54 static HRESULT map_url_to_zone(LPCWSTR url, DWORD *zone)
55 {
56     WCHAR schema[64];
57     DWORD res, size=0;
58     HKEY hkey;
59     HRESULT hres;
60
61     static const WCHAR wszZoneMapProtocolKey[] =
62         {'S','o','f','t','w','a','r','e','\\',
63                     'M','i','c','r','o','s','o','f','t','\\',
64                     'W','i','n','d','o','w','s','\\',
65                     'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
66                     'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
67                     'Z','o','n','e','M','a','p','\\',
68                     'P','r','o','t','o','c','o','l','D','e','f','a','u','l','t','s',0};
69     static const WCHAR wszFile[] = {'f','i','l','e',0};
70
71     hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, schema, sizeof(schema)/sizeof(WCHAR), &size, 0);
72     if(FAILED(hres))
73         return hres;
74     if(!*schema)
75         return 0x80041001;
76
77     /* file protocol is a special case */
78     if(!strcmpW(schema, wszFile)) {
79         WCHAR path[MAX_PATH];
80
81         hres = CoInternetParseUrl(url, PARSE_PATH_FROM_URL, 0, path,
82                 sizeof(path)/sizeof(WCHAR), &size, 0);
83
84         if(SUCCEEDED(hres) && strchrW(path, '\\')) {
85             *zone = 0;
86             return S_OK;
87         }
88     }
89
90     WARN("domains are not yet implemented\n");
91
92     res = RegOpenKeyW(HKEY_CURRENT_USER, wszZoneMapProtocolKey, &hkey);
93     if(res != ERROR_SUCCESS) {
94         ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey));
95         return E_UNEXPECTED;
96     }
97
98     size = sizeof(DWORD);
99     res = RegQueryValueExW(hkey, schema, NULL, NULL, (PBYTE)zone, &size);
100     RegCloseKey(hkey);
101     if(res == ERROR_SUCCESS)
102         return S_OK;
103
104     res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszZoneMapProtocolKey, &hkey);
105     if(res != ERROR_SUCCESS) {
106         ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey));
107         return E_UNEXPECTED;
108     }
109
110     size = sizeof(DWORD);
111     res = RegQueryValueExW(hkey, schema, NULL, NULL, (PBYTE)zone, &size);
112     RegCloseKey(hkey);
113     if(res == ERROR_SUCCESS)
114         return S_OK;
115
116     *zone = 3;
117     return S_OK;
118 }
119
120 static HRESULT WINAPI SecManagerImpl_QueryInterface(IInternetSecurityManager* iface,REFIID riid,void** ppvObject)
121 {
122     SecManagerImpl *This = SECMGR_THIS(iface);
123
124     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
125
126     /* Perform a sanity check on the parameters.*/
127     if ( (This==0) || (ppvObject==0) )
128         return E_INVALIDARG;
129
130     /* Initialize the return parameter */
131     *ppvObject = 0;
132
133     /* Compare the riid with the interface IDs implemented by this object.*/
134     if (IsEqualIID(&IID_IUnknown, riid) ||
135         IsEqualIID(&IID_IInternetSecurityManager, riid))
136         *ppvObject = iface;
137
138     /* Check that we obtained an interface.*/
139     if (!*ppvObject) {
140         WARN("not supported interface %s\n", debugstr_guid(riid));
141         return E_NOINTERFACE;
142     }
143
144     /* Query Interface always increases the reference count by one when it is successful */
145     IInternetSecurityManager_AddRef(iface);
146
147     return S_OK;
148 }
149
150 static ULONG WINAPI SecManagerImpl_AddRef(IInternetSecurityManager* iface)
151 {
152     SecManagerImpl *This = SECMGR_THIS(iface);
153     ULONG refCount = InterlockedIncrement(&This->ref);
154
155     TRACE("(%p) ref=%lu\n", This, refCount);
156
157     return refCount;
158 }
159
160 static ULONG WINAPI SecManagerImpl_Release(IInternetSecurityManager* iface)
161 {
162     SecManagerImpl *This = SECMGR_THIS(iface);
163     ULONG refCount = InterlockedDecrement(&This->ref);
164
165     TRACE("(%p) ref=%lu\n", This, refCount);
166
167     /* destroy the object if there's no more reference on it */
168     if (!refCount){
169         if(This->mgrsite)
170             IInternetSecurityMgrSite_Release(This->mgrsite);
171         if(This->custom_manager)
172             IInternetSecurityManager_Release(This->custom_manager);
173
174         HeapFree(GetProcessHeap(),0,This);
175
176         URLMON_UnlockModule();
177     }
178
179     return refCount;
180 }
181
182 static HRESULT WINAPI SecManagerImpl_SetSecuritySite(IInternetSecurityManager *iface,
183                                                      IInternetSecurityMgrSite *pSite)
184 {
185     SecManagerImpl *This = SECMGR_THIS(iface);
186
187     TRACE("(%p)->(%p)\n", This, pSite);
188
189     if(This->mgrsite)
190         IInternetSecurityMgrSite_Release(This->mgrsite);
191
192     if(This->custom_manager) {
193         IInternetSecurityManager_Release(This->custom_manager);
194         This->custom_manager = NULL;
195     }
196
197     This->mgrsite = pSite;
198
199     if(pSite) {
200         IServiceProvider *servprov;
201         HRESULT hres;
202
203         IInternetSecurityMgrSite_AddRef(pSite);
204
205         hres = IInternetSecurityMgrSite_QueryInterface(pSite, &IID_IServiceProvider,
206                 (void**)&servprov);
207         if(SUCCEEDED(hres)) {
208             IServiceProvider_QueryService(servprov, &SID_SInternetSecurityManager,
209                     &IID_IInternetSecurityManager, (void**)&This->custom_manager);
210             IServiceProvider_Release(servprov);
211         }
212     }
213
214     return S_OK;
215 }
216
217 static HRESULT WINAPI SecManagerImpl_GetSecuritySite(IInternetSecurityManager *iface,
218                                                      IInternetSecurityMgrSite **ppSite)
219 {
220     SecManagerImpl *This = SECMGR_THIS(iface);
221
222     TRACE("(%p)->(%p)\n", This, ppSite);
223
224     if(!ppSite)
225         return E_INVALIDARG;
226
227     if(This->mgrsite)
228         IInternetSecurityMgrSite_AddRef(This->mgrsite);
229
230     *ppSite = This->mgrsite;
231     return S_OK;
232 }
233
234 static HRESULT WINAPI SecManagerImpl_MapUrlToZone(IInternetSecurityManager *iface,
235                                                   LPCWSTR pwszUrl, DWORD *pdwZone,
236                                                   DWORD dwFlags)
237 {
238     SecManagerImpl *This = SECMGR_THIS(iface);
239     LPWSTR url;
240     DWORD size;
241     HRESULT hres;
242
243     TRACE("(%p)->(%s %p %08lx)\n", iface, debugstr_w(pwszUrl), pdwZone, dwFlags);
244
245     if(This->custom_manager) {
246         hres = IInternetSecurityManager_MapUrlToZone(This->custom_manager,
247                 pwszUrl, pdwZone, dwFlags);
248         if(hres != INET_E_DEFAULT_ACTION)
249             return hres;
250     }
251
252     if(!pwszUrl)
253         return E_INVALIDARG;
254
255     if(dwFlags)
256         FIXME("not supported flags: %08lx\n", dwFlags);
257
258     size = (strlenW(pwszUrl)+16) * sizeof(WCHAR);
259     url = HeapAlloc(GetProcessHeap(), 0, size);
260
261     hres = CoInternetParseUrl(pwszUrl, PARSE_SECURITY_URL, 0, url, size/sizeof(WCHAR), &size, 0);
262     if(FAILED(hres))
263         memcpy(url, pwszUrl, size);
264
265     hres = map_url_to_zone(url, pdwZone);
266
267     HeapFree(GetProcessHeap(), 0, url);
268
269     return hres;
270 }
271
272 static HRESULT WINAPI SecManagerImpl_GetSecurityId(IInternetSecurityManager *iface, 
273         LPCWSTR pwszUrl, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
274 {
275     SecManagerImpl *This = SECMGR_THIS(iface);
276     LPWSTR buf, ptr, ptr2;
277     DWORD size, zone, len;
278     HRESULT hres;
279
280     static const WCHAR wszFile[] = {'f','i','l','e',':'};
281
282     TRACE("(%p)->(%s %p %p %08lx)\n", iface, debugstr_w(pwszUrl), pbSecurityId,
283           pcbSecurityId, dwReserved);
284
285     if(This->custom_manager) {
286         hres = IInternetSecurityManager_GetSecurityId(This->custom_manager,
287                 pwszUrl, pbSecurityId, pcbSecurityId, dwReserved);
288         if(hres != INET_E_DEFAULT_ACTION)
289             return hres;
290     }
291
292     if(!pwszUrl || !pbSecurityId || !pcbSecurityId)
293         return E_INVALIDARG;
294
295     if(dwReserved)
296         FIXME("dwReserved is not supported\n");
297
298     len = strlenW(pwszUrl)+1;
299     buf = HeapAlloc(GetProcessHeap(), 0, (len+16)*sizeof(WCHAR));
300
301     hres = CoInternetParseUrl(pwszUrl, PARSE_SECURITY_URL, 0, buf, len, &size, 0);
302     if(FAILED(hres))
303         memcpy(buf, pwszUrl, len*sizeof(WCHAR));
304
305     hres = map_url_to_zone(buf, &zone);
306     if(FAILED(hres)) {
307         HeapFree(GetProcessHeap(), 0, buf);
308         return hres == 0x80041001 ? E_INVALIDARG : hres;
309     }
310
311     /* file protocol is a special case */
312     if(strlenW(pwszUrl) >= sizeof(wszFile)/sizeof(WCHAR)
313             && !memcmp(buf, wszFile, sizeof(wszFile))) {
314
315         static const BYTE secidFile[] = {'f','i','l','e',':'};
316
317         if(*pcbSecurityId < sizeof(secidFile)+sizeof(zone))
318             return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
319
320         memcpy(pbSecurityId, secidFile, sizeof(secidFile));
321         *(DWORD*)(pbSecurityId+sizeof(secidFile)) = zone;
322
323         *pcbSecurityId = sizeof(secidFile)+sizeof(zone);
324         return S_OK;
325     }
326
327     ptr = strchrW(buf, ':');
328     ptr2 = ++ptr;
329     while(*ptr2 == '/')
330         ptr2++;
331     if(ptr2 != ptr)
332         memmove(ptr, ptr2, (strlenW(ptr2)+1)*sizeof(WCHAR));
333
334     ptr = strchrW(ptr, '/');
335     if(ptr)
336         *ptr = 0;
337
338     len = WideCharToMultiByte(CP_ACP, 0, buf, -1, NULL, 0, NULL, NULL)-1;
339
340     if(len+sizeof(DWORD) > *pcbSecurityId)
341         return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
342
343     WideCharToMultiByte(CP_ACP, 0, buf, -1, (LPSTR)pbSecurityId, -1, NULL, NULL);
344     HeapFree(GetProcessHeap(), 0, buf);
345
346     *(DWORD*)(pbSecurityId+len) = zone;
347
348     *pcbSecurityId = len+sizeof(DWORD);
349
350     return S_OK;
351 }
352
353
354 static HRESULT WINAPI SecManagerImpl_ProcessUrlAction(IInternetSecurityManager *iface,
355                                                       LPCWSTR pwszUrl, DWORD dwAction,
356                                                       BYTE *pPolicy, DWORD cbPolicy,
357                                                       BYTE *pContext, DWORD cbContext,
358                                                       DWORD dwFlags, DWORD dwReserved)
359 {
360     SecManagerImpl *This = SECMGR_THIS(iface);
361     HRESULT hres;
362
363     TRACE("(%p)->(%s %08lx %p %08lx %p %08lx %08lx %08lx)\n", iface, debugstr_w(pwszUrl), dwAction,
364           pPolicy, cbPolicy, pContext, cbContext, dwFlags, dwReserved);
365
366     if(This->custom_manager) {
367         hres = IInternetSecurityManager_ProcessUrlAction(This->custom_manager, pwszUrl, dwAction,
368                 pPolicy, cbPolicy, pContext, cbContext, dwFlags, dwReserved);
369         if(hres != INET_E_DEFAULT_ACTION)
370             return hres;
371     }
372
373     FIXME("Default action is not implemented\n");
374     return E_NOTIMPL;
375 }
376                                                
377
378 static HRESULT WINAPI SecManagerImpl_QueryCustomPolicy(IInternetSecurityManager *iface,
379                                                        LPCWSTR pwszUrl, REFGUID guidKey,
380                                                        BYTE **ppPolicy, DWORD *pcbPolicy,
381                                                        BYTE *pContext, DWORD cbContext,
382                                                        DWORD dwReserved)
383 {
384     SecManagerImpl *This = SECMGR_THIS(iface);
385     HRESULT hres;
386
387     TRACE("(%p)->(%s %s %p %p %p %08lx %08lx )\n", iface, debugstr_w(pwszUrl), debugstr_guid(guidKey),
388           ppPolicy, pcbPolicy, pContext, cbContext, dwReserved);
389
390     if(This->custom_manager) {
391         hres = IInternetSecurityManager_QueryCustomPolicy(This->custom_manager, pwszUrl, guidKey,
392                 ppPolicy, pcbPolicy, pContext, cbContext, dwReserved);
393         if(hres != INET_E_DEFAULT_ACTION)
394             return hres;
395     }
396
397     FIXME("Default action is not implemented\n");
398     return E_NOTIMPL;
399 }
400
401 static HRESULT WINAPI SecManagerImpl_SetZoneMapping(IInternetSecurityManager *iface,
402                                                     DWORD dwZone, LPCWSTR pwszPattern, DWORD dwFlags)
403 {
404     SecManagerImpl *This = SECMGR_THIS(iface);
405     HRESULT hres;
406
407     TRACE("(%p)->(%08lx %s %08lx)\n", iface, dwZone, debugstr_w(pwszPattern),dwFlags);
408
409     if(This->custom_manager) {
410         hres = IInternetSecurityManager_SetZoneMapping(This->custom_manager, dwZone,
411                 pwszPattern, dwFlags);
412         if(hres != INET_E_DEFAULT_ACTION)
413             return hres;
414     }
415
416     FIXME("Default action is not implemented\n");
417     return E_NOTIMPL;
418 }
419
420 static HRESULT WINAPI SecManagerImpl_GetZoneMappings(IInternetSecurityManager *iface,
421         DWORD dwZone, IEnumString **ppenumString, DWORD dwFlags)
422 {
423     SecManagerImpl *This = SECMGR_THIS(iface);
424     HRESULT hres;
425
426     TRACE("(%p)->(%08lx %p %08lx)\n", iface, dwZone, ppenumString,dwFlags);
427
428     if(This->custom_manager) {
429         hres = IInternetSecurityManager_GetZoneMappings(This->custom_manager, dwZone,
430                 ppenumString, dwFlags);
431         if(hres != INET_E_DEFAULT_ACTION)
432             return hres;
433     }
434
435     FIXME("Default action is not implemented\n");
436     return E_NOTIMPL;
437 }
438
439 static const IInternetSecurityManagerVtbl VT_SecManagerImpl =
440 {
441     SecManagerImpl_QueryInterface,
442     SecManagerImpl_AddRef,
443     SecManagerImpl_Release,
444     SecManagerImpl_SetSecuritySite,
445     SecManagerImpl_GetSecuritySite,
446     SecManagerImpl_MapUrlToZone,
447     SecManagerImpl_GetSecurityId,
448     SecManagerImpl_ProcessUrlAction,
449     SecManagerImpl_QueryCustomPolicy,
450     SecManagerImpl_SetZoneMapping,
451     SecManagerImpl_GetZoneMappings
452 };
453
454 HRESULT SecManagerImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
455 {
456     SecManagerImpl *This;
457
458     TRACE("(%p,%p)\n",pUnkOuter,ppobj);
459     This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
460
461     /* Initialize the virtual function table. */
462     This->lpInternetSecurityManagerVtbl = &VT_SecManagerImpl;
463
464     This->ref = 1;
465     This->mgrsite = NULL;
466     This->custom_manager = NULL;
467
468     *ppobj = This;
469
470     URLMON_LockModule();
471
472     return S_OK;
473 }
474
475 /***********************************************************************
476  *           InternetZoneManager implementation
477  *
478  */
479 typedef struct {
480     const IInternetZoneManagerVtbl* lpVtbl;
481     LONG ref;
482 } ZoneMgrImpl;
483
484 static HRESULT open_zone_key(DWORD zone, HKEY *hkey, URLZONEREG zone_reg)
485 {
486     static const WCHAR wszZonesKey[] =
487         {'S','o','f','t','w','a','r','e','\\',
488             'M','i','c','r','o','s','o','f','t','\\',
489             'W','i','n','d','o','w','s','\\',
490             'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
491             'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
492             'Z','o','n','e','s','\\',0};
493     static const WCHAR wszFormat[] = {'%','s','%','l','d',0};
494
495     WCHAR key_name[sizeof(wszZonesKey)/sizeof(WCHAR)+8];
496     HKEY parent_key;
497     DWORD res;
498
499     switch(zone_reg) {
500     case URLZONEREG_DEFAULT: /* FIXME: TEST */
501     case URLZONEREG_HKCU:
502         parent_key = HKEY_CURRENT_USER;
503         break;
504     case URLZONEREG_HKLM:
505         parent_key = HKEY_LOCAL_MACHINE;
506         break;
507     default:
508         WARN("Unknown URLZONEREG: %d\n", zone_reg);
509         return E_FAIL;
510     };
511
512     wsprintfW(key_name, wszFormat, wszZonesKey, zone);
513
514     res = RegOpenKeyW(parent_key, key_name, hkey);
515
516     if(res != ERROR_SUCCESS) {
517         WARN("RegOpenKey failed\n");
518         return E_INVALIDARG;
519     }
520
521     return S_OK;
522 }
523
524 /********************************************************************
525  *      IInternetZoneManager_QueryInterface
526  */
527 static HRESULT WINAPI ZoneMgrImpl_QueryInterface(IInternetZoneManager* iface, REFIID riid, void** ppvObject)
528 {
529     ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
530
531     TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
532
533     if(!This || !ppvObject)
534         return E_INVALIDARG;
535
536     if(!IsEqualIID(&IID_IUnknown, riid) && !IsEqualIID(&IID_IInternetZoneManager, riid)) {
537         FIXME("Unknown interface: %s\n", debugstr_guid(riid));
538         *ppvObject = NULL;
539         return E_NOINTERFACE;
540     }
541
542     *ppvObject = iface;
543     IInternetZoneManager_AddRef(iface);
544
545     return S_OK;
546 }
547
548 /********************************************************************
549  *      IInternetZoneManager_AddRef
550  */
551 static ULONG WINAPI ZoneMgrImpl_AddRef(IInternetZoneManager* iface)
552 {
553     ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
554     ULONG refCount = InterlockedIncrement(&This->ref);
555
556     TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1);
557
558     return refCount;
559 }
560
561 /********************************************************************
562  *      IInternetZoneManager_Release
563  */
564 static ULONG WINAPI ZoneMgrImpl_Release(IInternetZoneManager* iface)
565 {
566     ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
567     ULONG refCount = InterlockedDecrement(&This->ref);
568
569     TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1);
570
571     if(!refCount) {
572         HeapFree(GetProcessHeap(), 0, This);
573         URLMON_UnlockModule();
574     }
575     
576     return refCount;
577 }
578
579 /********************************************************************
580  *      IInternetZoneManager_GetZoneAttributes
581  */
582 static HRESULT WINAPI ZoneMgrImpl_GetZoneAttributes(IInternetZoneManager* iface,
583                                                     DWORD dwZone,
584                                                     ZONEATTRIBUTES* pZoneAttributes)
585 {
586     FIXME("(%p)->(%ld %p) stub\n", iface, dwZone, pZoneAttributes);
587     return E_NOTIMPL;
588 }
589
590 /********************************************************************
591  *      IInternetZoneManager_SetZoneAttributes
592  */
593 static HRESULT WINAPI ZoneMgrImpl_SetZoneAttributes(IInternetZoneManager* iface,
594                                                     DWORD dwZone,
595                                                     ZONEATTRIBUTES* pZoneAttributes)
596 {
597     FIXME("(%p)->(%08lx %p) stub\n", iface, dwZone, pZoneAttributes);
598     return E_NOTIMPL;
599 }
600
601 /********************************************************************
602  *      IInternetZoneManager_GetZoneCustomPolicy
603  */
604 static HRESULT WINAPI ZoneMgrImpl_GetZoneCustomPolicy(IInternetZoneManager* iface,
605                                                       DWORD dwZone,
606                                                       REFGUID guidKey,
607                                                       BYTE** ppPolicy,
608                                                       DWORD* pcbPolicy,
609                                                       URLZONEREG ulrZoneReg)
610 {
611     FIXME("(%p)->(%08lx %s %p %p %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
612                                                     ppPolicy, pcbPolicy, ulrZoneReg);
613     return E_NOTIMPL;
614 }
615
616 /********************************************************************
617  *      IInternetZoneManager_SetZoneCustomPolicy
618  */
619 static HRESULT WINAPI ZoneMgrImpl_SetZoneCustomPolicy(IInternetZoneManager* iface,
620                                                       DWORD dwZone,
621                                                       REFGUID guidKey,
622                                                       BYTE* ppPolicy,
623                                                       DWORD cbPolicy,
624                                                       URLZONEREG ulrZoneReg)
625 {
626     FIXME("(%p)->(%08lx %s %p %08lx %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
627                                                     ppPolicy, cbPolicy, ulrZoneReg);
628     return E_NOTIMPL;
629 }
630
631 /********************************************************************
632  *      IInternetZoneManager_GetZoneActionPolicy
633  */
634 static HRESULT WINAPI ZoneMgrImpl_GetZoneActionPolicy(IInternetZoneManager* iface,
635         DWORD dwZone, DWORD dwAction, BYTE* pPolicy, DWORD cbPolicy, URLZONEREG urlZoneReg)
636 {
637     WCHAR action[16];
638     HKEY hkey;
639     LONG res;
640     DWORD size = cbPolicy;
641     HRESULT hres;
642
643     static const WCHAR wszFormat[] = {'%','l','X',0};
644
645     TRACE("(%p)->(%ld %08lx %p %ld %d)\n", iface, dwZone, dwAction, pPolicy,
646             cbPolicy, urlZoneReg);
647
648     if(!pPolicy)
649         return E_INVALIDARG;
650
651     hres = open_zone_key(dwZone, &hkey, urlZoneReg);
652     if(FAILED(hres))
653         return hres;
654
655     wsprintfW(action, wszFormat, dwAction);
656
657     res = RegQueryValueExW(hkey, action, NULL, NULL, pPolicy, &size);
658     if(res == ERROR_MORE_DATA) {
659         hres = E_INVALIDARG;
660     }else if(res == ERROR_FILE_NOT_FOUND) {
661         hres = E_FAIL;
662     }else if(res != ERROR_SUCCESS) {
663         ERR("RegQueryValue failed: %ld\n", res);
664         hres = E_UNEXPECTED;
665     }
666
667     RegCloseKey(hkey);
668
669     return hres;
670 }
671
672 /********************************************************************
673  *      IInternetZoneManager_SetZoneActionPolicy
674  */
675 static HRESULT WINAPI ZoneMgrImpl_SetZoneActionPolicy(IInternetZoneManager* iface,
676                                                       DWORD dwZone,
677                                                       DWORD dwAction,
678                                                       BYTE* pPolicy,
679                                                       DWORD cbPolicy,
680                                                       URLZONEREG urlZoneReg)
681 {
682     FIXME("(%p)->(%08lx %08lx %p %08lx %08x) stub\n", iface, dwZone, dwAction, pPolicy,
683                                                        cbPolicy, urlZoneReg);
684     return E_NOTIMPL;
685 }
686
687 /********************************************************************
688  *      IInternetZoneManager_PromptAction
689  */
690 static HRESULT WINAPI ZoneMgrImpl_PromptAction(IInternetZoneManager* iface,
691                                                DWORD dwAction,
692                                                HWND hwndParent,
693                                                LPCWSTR pwszUrl,
694                                                LPCWSTR pwszText,
695                                                DWORD dwPromptFlags)
696 {
697     FIXME("%p %08lx %p %s %s %08lx\n", iface, dwAction, hwndParent,
698           debugstr_w(pwszUrl), debugstr_w(pwszText), dwPromptFlags );
699     return E_NOTIMPL;
700 }
701
702 /********************************************************************
703  *      IInternetZoneManager_LogAction
704  */
705 static HRESULT WINAPI ZoneMgrImpl_LogAction(IInternetZoneManager* iface,
706                                             DWORD dwAction,
707                                             LPCWSTR pwszUrl,
708                                             LPCWSTR pwszText,
709                                             DWORD dwLogFlags)
710 {
711     FIXME("(%p)->(%08lx %s %s %08lx) stub\n", iface, dwAction, debugstr_w(pwszUrl),
712                                               debugstr_w(pwszText), dwLogFlags);
713     return E_NOTIMPL;
714 }
715
716 /********************************************************************
717  *      IInternetZoneManager_CreateZoneEnumerator
718  */
719 static HRESULT WINAPI ZoneMgrImpl_CreateZoneEnumerator(IInternetZoneManager* iface,
720                                                        DWORD* pdwEnum,
721                                                        DWORD* pdwCount,
722                                                        DWORD dwFlags)
723 {
724     FIXME("(%p)->(%p %p %08lx) stub\n", iface, pdwEnum, pdwCount, dwFlags);
725     return E_NOTIMPL;
726 }
727
728 /********************************************************************
729  *      IInternetZoneManager_GetZoneAt
730  */
731 static HRESULT WINAPI ZoneMgrImpl_GetZoneAt(IInternetZoneManager* iface,
732                                             DWORD dwEnum,
733                                             DWORD dwIndex,
734                                             DWORD* pdwZone)
735 {
736     FIXME("(%p)->(%08lx %08lx %p) stub\n", iface, dwEnum, dwIndex, pdwZone);
737     return E_NOTIMPL;
738 }
739
740 /********************************************************************
741  *      IInternetZoneManager_DestroyZoneEnumerator
742  */
743 static HRESULT WINAPI ZoneMgrImpl_DestroyZoneEnumerator(IInternetZoneManager* iface,
744                                                         DWORD dwEnum)
745 {
746     FIXME("(%p)->(%08lx) stub\n", iface, dwEnum);
747     return E_NOTIMPL;
748 }
749
750 /********************************************************************
751  *      IInternetZoneManager_CopyTemplatePoliciesToZone
752  */
753 static HRESULT WINAPI ZoneMgrImpl_CopyTemplatePoliciesToZone(IInternetZoneManager* iface,
754                                                              DWORD dwTemplate,
755                                                              DWORD dwZone,
756                                                              DWORD dwReserved)
757 {
758     FIXME("(%p)->(%08lx %08lx %08lx) stub\n", iface, dwTemplate, dwZone, dwReserved);
759     return E_NOTIMPL;
760 }
761
762 /********************************************************************
763  *      IInternetZoneManager_Construct
764  */
765 static const IInternetZoneManagerVtbl ZoneMgrImplVtbl = {
766     ZoneMgrImpl_QueryInterface,
767     ZoneMgrImpl_AddRef,
768     ZoneMgrImpl_Release,
769     ZoneMgrImpl_GetZoneAttributes,
770     ZoneMgrImpl_SetZoneAttributes,
771     ZoneMgrImpl_GetZoneCustomPolicy,
772     ZoneMgrImpl_SetZoneCustomPolicy,
773     ZoneMgrImpl_GetZoneActionPolicy,
774     ZoneMgrImpl_SetZoneActionPolicy,
775     ZoneMgrImpl_PromptAction,
776     ZoneMgrImpl_LogAction,
777     ZoneMgrImpl_CreateZoneEnumerator,
778     ZoneMgrImpl_GetZoneAt,
779     ZoneMgrImpl_DestroyZoneEnumerator,
780     ZoneMgrImpl_CopyTemplatePoliciesToZone,
781 };
782
783 HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
784 {
785     ZoneMgrImpl* ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ZoneMgrImpl));
786
787     TRACE("(%p %p)\n", pUnkOuter, ppobj);
788     ret->lpVtbl = &ZoneMgrImplVtbl;
789     ret->ref = 1;
790     *ppobj = (IInternetZoneManager*)ret;
791
792     URLMON_LockModule();
793
794     return S_OK;
795 }
796
797 /***********************************************************************
798  *           CoInternetCreateSecurityManager (URLMON.@)
799  *
800  */
801 HRESULT WINAPI CoInternetCreateSecurityManager( IServiceProvider *pSP,
802     IInternetSecurityManager **ppSM, DWORD dwReserved )
803 {
804     TRACE("%p %p %ld\n", pSP, ppSM, dwReserved );
805
806     if(pSP)
807         FIXME("pSP not supported\n");
808
809     return SecManagerImpl_Construct(NULL, (void**) ppSM);
810 }
811
812 /********************************************************************
813  *      CoInternetCreateZoneManager (URLMON.@)
814  */
815 HRESULT WINAPI CoInternetCreateZoneManager(IServiceProvider* pSP, IInternetZoneManager** ppZM, DWORD dwReserved)
816 {
817     TRACE("(%p %p %lx)\n", pSP, ppZM, dwReserved);
818     return ZoneMgrImpl_Construct(NULL, (void**)ppZM);
819 }