Explicitly import kernel32 in tests that use it.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 "wine/debug.h"
31 #include "ole2.h"
32 #include "wine/unicode.h"
33 #include "urlmon.h"
34 #include "urlmon_main.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
37
38 /***********************************************************************
39  *           InternetSecurityManager implementation
40  *
41  */
42 typedef struct SecManagerImpl{
43
44     const IInternetSecurityManagerVtbl* lpvtbl1;  /* VTable relative to the IInternetSecurityManager interface.*/
45
46     LONG ref; /* reference counter for this object */
47
48 } SecManagerImpl;
49
50 static HRESULT WINAPI SecManagerImpl_QueryInterface(IInternetSecurityManager* iface,REFIID riid,void** ppvObject)
51 {
52     SecManagerImpl *This = (SecManagerImpl *)iface;
53
54     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
55
56     /* Perform a sanity check on the parameters.*/
57     if ( (This==0) || (ppvObject==0) )
58         return E_INVALIDARG;
59
60     /* Initialize the return parameter */
61     *ppvObject = 0;
62
63     /* Compare the riid with the interface IDs implemented by this object.*/
64     if (IsEqualIID(&IID_IUnknown, riid) ||
65         IsEqualIID(&IID_IInternetSecurityManager, riid))
66         *ppvObject = iface;
67
68     /* Check that we obtained an interface.*/
69     if ((*ppvObject)==0)
70         return E_NOINTERFACE;
71
72     /* Query Interface always increases the reference count by one when it is successful */
73     IInternetSecurityManager_AddRef(iface);
74
75     return S_OK;
76 }
77
78 static ULONG WINAPI SecManagerImpl_AddRef(IInternetSecurityManager* iface)
79 {
80     SecManagerImpl *This = (SecManagerImpl *)iface;
81     ULONG refCount = InterlockedIncrement(&This->ref);
82
83     TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1);
84
85     return refCount;
86 }
87
88 static ULONG WINAPI SecManagerImpl_Release(IInternetSecurityManager* iface)
89 {
90     SecManagerImpl *This = (SecManagerImpl *)iface;
91     ULONG refCount = InterlockedDecrement(&This->ref);
92
93     TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1);
94
95     /* destroy the object if there's no more reference on it */
96     if (!refCount){
97         HeapFree(GetProcessHeap(),0,This);
98         URLMON_UnlockModule();
99     }
100
101     return refCount;
102 }
103
104 static HRESULT WINAPI SecManagerImpl_SetSecuritySite(IInternetSecurityManager *iface,
105                                                      IInternetSecurityMgrSite *pSite)
106 {
107     FIXME("(%p)->(%p)\n", iface, pSite);
108     return E_NOTIMPL;
109 }
110
111 static HRESULT WINAPI SecManagerImpl_GetSecuritySite(IInternetSecurityManager *iface,
112                                                      IInternetSecurityMgrSite **ppSite)
113 {
114     FIXME("(%p)->( %p)\n", iface, ppSite);
115     return E_NOTIMPL;
116 }
117
118 static HRESULT WINAPI SecManagerImpl_MapUrlToZone(IInternetSecurityManager *iface,
119                                                   LPCWSTR pwszUrl, DWORD *pdwZone,
120                                                   DWORD dwFlags)
121 {
122     FIXME("(%p)->(%s %p %08lx)\n", iface, debugstr_w(pwszUrl), pdwZone, dwFlags);
123     return E_NOTIMPL;
124 }
125
126 static HRESULT WINAPI SecManagerImpl_GetSecurityId(IInternetSecurityManager *iface, 
127                                                    LPCWSTR pwszUrl,
128                                                    BYTE *pbSecurityId, DWORD *pcbSecurityId,
129                                                    DWORD dwReserved)
130 {
131     FIXME("(%p)->(%s %p %p %08lx)\n", iface, debugstr_w(pwszUrl), pbSecurityId, pcbSecurityId,
132           dwReserved);
133     return E_NOTIMPL;
134 }
135
136
137 static HRESULT WINAPI SecManagerImpl_ProcessUrlAction(IInternetSecurityManager *iface,
138                                                       LPCWSTR pwszUrl, DWORD dwAction,
139                                                       BYTE *pPolicy, DWORD cbPolicy,
140                                                       BYTE *pContext, DWORD cbContext,
141                                                       DWORD dwFlags, DWORD dwReserved)
142 {
143     FIXME("(%p)->(%s %08lx %p %08lx %p %08lx %08lx %08lx)\n", iface, debugstr_w(pwszUrl), dwAction,
144           pPolicy, cbPolicy, pContext, cbContext, dwFlags, dwReserved);
145     return E_NOTIMPL;
146 }
147                                                
148
149 static HRESULT WINAPI SecManagerImpl_QueryCustomPolicy(IInternetSecurityManager *iface,
150                                                        LPCWSTR pwszUrl, REFGUID guidKey,
151                                                        BYTE **ppPolicy, DWORD *pcbPolicy,
152                                                        BYTE *pContext, DWORD cbContext,
153                                                        DWORD dwReserved)
154 {
155     FIXME("(%p)->(%s %s %p %p %p %08lx %08lx )\n", iface, debugstr_w(pwszUrl), debugstr_guid(guidKey),
156           ppPolicy, pcbPolicy, pContext, cbContext, dwReserved);
157     return E_NOTIMPL;
158 }
159
160 static HRESULT WINAPI SecManagerImpl_SetZoneMapping(IInternetSecurityManager *iface,
161                                                     DWORD dwZone, LPCWSTR pwszPattern, DWORD dwFlags)
162 {
163     FIXME("(%p)->(%08lx %s %08lx)\n", iface, dwZone, debugstr_w(pwszPattern),dwFlags);
164     return E_NOTIMPL;
165 }
166
167 static HRESULT WINAPI SecManagerImpl_GetZoneMappings(IInternetSecurityManager *iface,
168                                                      DWORD dwZone, IEnumString **ppenumString, DWORD dwFlags)
169 {
170     FIXME("(%p)->(%08lx %p %08lx)\n", iface, dwZone, ppenumString,dwFlags);
171     return E_NOTIMPL;
172 }
173
174 static const IInternetSecurityManagerVtbl VT_SecManagerImpl =
175 {
176     SecManagerImpl_QueryInterface,
177     SecManagerImpl_AddRef,
178     SecManagerImpl_Release,
179     SecManagerImpl_SetSecuritySite,
180     SecManagerImpl_GetSecuritySite,
181     SecManagerImpl_MapUrlToZone,
182     SecManagerImpl_GetSecurityId,
183     SecManagerImpl_ProcessUrlAction,
184     SecManagerImpl_QueryCustomPolicy,
185     SecManagerImpl_SetZoneMapping,
186     SecManagerImpl_GetZoneMappings
187 };
188
189 HRESULT SecManagerImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
190 {
191     SecManagerImpl *This;
192
193     TRACE("(%p,%p)\n",pUnkOuter,ppobj);
194     This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
195
196     /* Initialize the virtual function table. */
197     This->lpvtbl1      = &VT_SecManagerImpl;
198     This->ref          = 1;
199
200     *ppobj = This;
201
202     URLMON_LockModule();
203
204     return S_OK;
205 }
206
207 /***********************************************************************
208  *           InternetZoneManager implementation
209  *
210  */
211 typedef struct {
212     const IInternetZoneManagerVtbl* lpVtbl;
213     LONG ref;
214 } ZoneMgrImpl;
215
216 /********************************************************************
217  *      IInternetZoneManager_QueryInterface
218  */
219 static HRESULT WINAPI ZoneMgrImpl_QueryInterface(IInternetZoneManager* iface, REFIID riid, void** ppvObject)
220 {
221     ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
222
223     TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
224
225     if(!This || !ppvObject)
226         return E_INVALIDARG;
227
228     if(!IsEqualIID(&IID_IUnknown, riid) && !IsEqualIID(&IID_IInternetZoneManager, riid)) {
229         FIXME("Unknown interface: %s\n", debugstr_guid(riid));
230         *ppvObject = NULL;
231         return E_NOINTERFACE;
232     }
233
234     *ppvObject = iface;
235     IInternetZoneManager_AddRef(iface);
236
237     return S_OK;
238 }
239
240 /********************************************************************
241  *      IInternetZoneManager_AddRef
242  */
243 static ULONG WINAPI ZoneMgrImpl_AddRef(IInternetZoneManager* iface)
244 {
245     ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
246     ULONG refCount = InterlockedIncrement(&This->ref);
247
248     TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1);
249
250     return refCount;
251 }
252
253 /********************************************************************
254  *      IInternetZoneManager_Release
255  */
256 static ULONG WINAPI ZoneMgrImpl_Release(IInternetZoneManager* iface)
257 {
258     ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
259     ULONG refCount = InterlockedDecrement(&This->ref);
260
261     TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1);
262
263     if(!refCount) {
264         HeapFree(GetProcessHeap(), 0, This);
265         URLMON_UnlockModule();
266     }
267     
268     return refCount;
269 }
270
271 /********************************************************************
272  *      IInternetZoneManager_GetZoneAttributes
273  */
274 static HRESULT WINAPI ZoneMgrImpl_GetZoneAttributes(IInternetZoneManager* iface,
275                                                     DWORD dwZone,
276                                                     ZONEATTRIBUTES* pZoneAttributes)
277 {
278     FIXME("(%p)->(%ld %p) stub\n", iface, dwZone, pZoneAttributes);
279     return E_NOTIMPL;
280 }
281
282 /********************************************************************
283  *      IInternetZoneManager_SetZoneAttributes
284  */
285 static HRESULT WINAPI ZoneMgrImpl_SetZoneAttributes(IInternetZoneManager* iface,
286                                                     DWORD dwZone,
287                                                     ZONEATTRIBUTES* pZoneAttributes)
288 {
289     FIXME("(%p)->(%08lx %p) stub\n", iface, dwZone, pZoneAttributes);
290     return E_NOTIMPL;
291 }
292
293 /********************************************************************
294  *      IInternetZoneManager_GetZoneCustomPolicy
295  */
296 static HRESULT WINAPI ZoneMgrImpl_GetZoneCustomPolicy(IInternetZoneManager* iface,
297                                                       DWORD dwZone,
298                                                       REFGUID guidKey,
299                                                       BYTE** ppPolicy,
300                                                       DWORD* pcbPolicy,
301                                                       URLZONEREG ulrZoneReg)
302 {
303     FIXME("(%p)->(%08lx %s %p %p %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
304                                                     ppPolicy, pcbPolicy, ulrZoneReg);
305     return E_NOTIMPL;
306 }
307
308 /********************************************************************
309  *      IInternetZoneManager_SetZoneCustomPolicy
310  */
311 static HRESULT WINAPI ZoneMgrImpl_SetZoneCustomPolicy(IInternetZoneManager* iface,
312                                                       DWORD dwZone,
313                                                       REFGUID guidKey,
314                                                       BYTE* ppPolicy,
315                                                       DWORD cbPolicy,
316                                                       URLZONEREG ulrZoneReg)
317 {
318     FIXME("(%p)->(%08lx %s %p %08lx %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
319                                                     ppPolicy, cbPolicy, ulrZoneReg);
320     return E_NOTIMPL;
321 }
322
323 /********************************************************************
324  *      IInternetZoneManager_GetZoneActionPolicy
325  */
326 static HRESULT WINAPI ZoneMgrImpl_GetZoneActionPolicy(IInternetZoneManager* iface,
327                                                       DWORD dwZone,
328                                                       DWORD dwAction,
329                                                       BYTE* pPolicy,
330                                                       DWORD cbPolicy,
331                                                       URLZONEREG urlZoneReg)
332 {
333     FIXME("(%p)->(%08lx %08lx %p %08lx %08x) stub\n", iface, dwZone, dwAction, pPolicy,
334                                                        cbPolicy, urlZoneReg);
335     return E_NOTIMPL;
336 }
337
338 /********************************************************************
339  *      IInternetZoneManager_SetZoneActionPolicy
340  */
341 static HRESULT WINAPI ZoneMgrImpl_SetZoneActionPolicy(IInternetZoneManager* iface,
342                                                       DWORD dwZone,
343                                                       DWORD dwAction,
344                                                       BYTE* pPolicy,
345                                                       DWORD cbPolicy,
346                                                       URLZONEREG urlZoneReg)
347 {
348     FIXME("(%p)->(%08lx %08lx %p %08lx %08x) stub\n", iface, dwZone, dwAction, pPolicy,
349                                                        cbPolicy, urlZoneReg);
350     return E_NOTIMPL;
351 }
352
353 /********************************************************************
354  *      IInternetZoneManager_PromptAction
355  */
356 static HRESULT WINAPI ZoneMgrImpl_PromptAction(IInternetZoneManager* iface,
357                                                DWORD dwAction,
358                                                HWND hwndParent,
359                                                LPCWSTR pwszUrl,
360                                                LPCWSTR pwszText,
361                                                DWORD dwPromptFlags)
362 {
363     FIXME("%p %08lx %p %s %s %08lx\n", iface, dwAction, hwndParent,
364           debugstr_w(pwszUrl), debugstr_w(pwszText), dwPromptFlags );
365     return E_NOTIMPL;
366 }
367
368 /********************************************************************
369  *      IInternetZoneManager_LogAction
370  */
371 static HRESULT WINAPI ZoneMgrImpl_LogAction(IInternetZoneManager* iface,
372                                             DWORD dwAction,
373                                             LPCWSTR pwszUrl,
374                                             LPCWSTR pwszText,
375                                             DWORD dwLogFlags)
376 {
377     FIXME("(%p)->(%08lx %s %s %08lx) stub\n", iface, dwAction, debugstr_w(pwszUrl),
378                                               debugstr_w(pwszText), dwLogFlags);
379     return E_NOTIMPL;
380 }
381
382 /********************************************************************
383  *      IInternetZoneManager_CreateZoneEnumerator
384  */
385 static HRESULT WINAPI ZoneMgrImpl_CreateZoneEnumerator(IInternetZoneManager* iface,
386                                                        DWORD* pdwEnum,
387                                                        DWORD* pdwCount,
388                                                        DWORD dwFlags)
389 {
390     FIXME("(%p)->(%p %p %08lx) stub\n", iface, pdwEnum, pdwCount, dwFlags);
391     return E_NOTIMPL;
392 }
393
394 /********************************************************************
395  *      IInternetZoneManager_GetZoneAt
396  */
397 static HRESULT WINAPI ZoneMgrImpl_GetZoneAt(IInternetZoneManager* iface,
398                                             DWORD dwEnum,
399                                             DWORD dwIndex,
400                                             DWORD* pdwZone)
401 {
402     FIXME("(%p)->(%08lx %08lx %p) stub\n", iface, dwEnum, dwIndex, pdwZone);
403     return E_NOTIMPL;
404 }
405
406 /********************************************************************
407  *      IInternetZoneManager_DestroyZoneEnumerator
408  */
409 static HRESULT WINAPI ZoneMgrImpl_DestroyZoneEnumerator(IInternetZoneManager* iface,
410                                                         DWORD dwEnum)
411 {
412     FIXME("(%p)->(%08lx) stub\n", iface, dwEnum);
413     return E_NOTIMPL;
414 }
415
416 /********************************************************************
417  *      IInternetZoneManager_CopyTemplatePoliciesToZone
418  */
419 static HRESULT WINAPI ZoneMgrImpl_CopyTemplatePoliciesToZone(IInternetZoneManager* iface,
420                                                              DWORD dwTemplate,
421                                                              DWORD dwZone,
422                                                              DWORD dwReserved)
423 {
424     FIXME("(%p)->(%08lx %08lx %08lx) stub\n", iface, dwTemplate, dwZone, dwReserved);
425     return E_NOTIMPL;
426 }
427
428 /********************************************************************
429  *      IInternetZoneManager_Construct
430  */
431 static const IInternetZoneManagerVtbl ZoneMgrImplVtbl = {
432     ZoneMgrImpl_QueryInterface,
433     ZoneMgrImpl_AddRef,
434     ZoneMgrImpl_Release,
435     ZoneMgrImpl_GetZoneAttributes,
436     ZoneMgrImpl_SetZoneAttributes,
437     ZoneMgrImpl_GetZoneCustomPolicy,
438     ZoneMgrImpl_SetZoneCustomPolicy,
439     ZoneMgrImpl_GetZoneActionPolicy,
440     ZoneMgrImpl_SetZoneActionPolicy,
441     ZoneMgrImpl_PromptAction,
442     ZoneMgrImpl_LogAction,
443     ZoneMgrImpl_CreateZoneEnumerator,
444     ZoneMgrImpl_GetZoneAt,
445     ZoneMgrImpl_DestroyZoneEnumerator,
446     ZoneMgrImpl_CopyTemplatePoliciesToZone,
447 };
448
449 HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
450 {
451     ZoneMgrImpl* ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ZoneMgrImpl));
452
453     TRACE("(%p %p)\n", pUnkOuter, ppobj);
454     ret->lpVtbl = &ZoneMgrImplVtbl;
455     ret->ref = 1;
456     *ppobj = (IInternetZoneManager*)ret;
457
458     URLMON_LockModule();
459
460     return S_OK;
461 }
462
463 /***********************************************************************
464  *           CoInternetCreateSecurityManager (URLMON.@)
465  *
466  */
467 HRESULT WINAPI CoInternetCreateSecurityManager( IServiceProvider *pSP,
468     IInternetSecurityManager **ppSM, DWORD dwReserved )
469 {
470     TRACE("%p %p %ld\n", pSP, ppSM, dwReserved );
471     return SecManagerImpl_Construct(NULL, (void**) ppSM);
472 }
473
474 /********************************************************************
475  *      CoInternetCreateZoneManager (URLMON.@)
476  */
477 HRESULT WINAPI CoInternetCreateZoneManager(IServiceProvider* pSP, IInternetZoneManager** ppZM, DWORD dwReserved)
478 {
479     TRACE("(%p %p %lx)\n", pSP, ppZM, dwReserved);
480     return ZoneMgrImpl_Construct(NULL, (void**)ppZM);
481 }