Alexandre Julliard <julliard@winehq.org>
[reactos.git] / reactos / lib / 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 IInternetSecurityManagerVtbl* lpvtbl1; /* VTable relative to the IInternetSecurityManager interface.*/
45
46 ULONG 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 URLMON_LockModule();
86
87 return refCount;
88 }
89
90 static ULONG WINAPI SecManagerImpl_Release(IInternetSecurityManager* iface)
91 {
92 SecManagerImpl *This = (SecManagerImpl *)iface;
93 ULONG refCount = InterlockedDecrement(&This->ref);
94
95 TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1);
96
97 /* destroy the object if there's no more reference on it */
98 if (!refCount){
99 HeapFree(GetProcessHeap(),0,This);
100 }
101
102 URLMON_UnlockModule();
103
104 return refCount;
105 }
106
107 static HRESULT WINAPI SecManagerImpl_SetSecuritySite(IInternetSecurityManager *iface,
108 IInternetSecurityMgrSite *pSite)
109 {
110 FIXME("(%p)->(%p)\n", iface, pSite);
111 return E_NOTIMPL;
112 }
113
114 static HRESULT WINAPI SecManagerImpl_GetSecuritySite(IInternetSecurityManager *iface,
115 IInternetSecurityMgrSite **ppSite)
116 {
117 FIXME("(%p)->( %p)\n", iface, ppSite);
118 return E_NOTIMPL;
119 }
120
121 static HRESULT WINAPI SecManagerImpl_MapUrlToZone(IInternetSecurityManager *iface,
122 LPCWSTR pwszUrl, DWORD *pdwZone,
123 DWORD dwFlags)
124 {
125 FIXME("(%p)->(%s %p %08lx)\n", iface, debugstr_w(pwszUrl), pdwZone, dwFlags);
126 return E_NOTIMPL;
127 }
128
129 static HRESULT WINAPI SecManagerImpl_GetSecurityId(IInternetSecurityManager *iface,
130 LPCWSTR pwszUrl,
131 BYTE *pbSecurityId, DWORD *pcbSecurityId,
132 DWORD dwReserved)
133 {
134 FIXME("(%p)->(%s %p %p %08lx)\n", iface, debugstr_w(pwszUrl), pbSecurityId, pcbSecurityId,
135 dwReserved);
136 return E_NOTIMPL;
137 }
138
139
140 static HRESULT WINAPI SecManagerImpl_ProcessUrlAction(IInternetSecurityManager *iface,
141 LPCWSTR pwszUrl, DWORD dwAction,
142 BYTE *pPolicy, DWORD cbPolicy,
143 BYTE *pContext, DWORD cbContext,
144 DWORD dwFlags, DWORD dwReserved)
145 {
146 FIXME("(%p)->(%s %08lx %p %08lx %p %08lx %08lx %08lx)\n", iface, debugstr_w(pwszUrl), dwAction,
147 pPolicy, cbPolicy, pContext, cbContext, dwFlags, dwReserved);
148 return E_NOTIMPL;
149 }
150
151
152 static HRESULT WINAPI SecManagerImpl_QueryCustomPolicy(IInternetSecurityManager *iface,
153 LPCWSTR pwszUrl, REFGUID guidKey,
154 BYTE **ppPolicy, DWORD *pcbPolicy,
155 BYTE *pContext, DWORD cbContext,
156 DWORD dwReserved)
157 {
158 FIXME("(%p)->(%s %s %p %p %p %08lx %08lx )\n", iface, debugstr_w(pwszUrl), debugstr_guid(guidKey),
159 ppPolicy, pcbPolicy, pContext, cbContext, dwReserved);
160 return E_NOTIMPL;
161 }
162
163 static HRESULT WINAPI SecManagerImpl_SetZoneMapping(IInternetSecurityManager *iface,
164 DWORD dwZone, LPCWSTR pwszPattern, DWORD dwFlags)
165 {
166 FIXME("(%p)->(%08lx %s %08lx)\n", iface, dwZone, debugstr_w(pwszPattern),dwFlags);
167 return E_NOTIMPL;
168 }
169
170 static HRESULT WINAPI SecManagerImpl_GetZoneMappings(IInternetSecurityManager *iface,
171 DWORD dwZone, IEnumString **ppenumString, DWORD dwFlags)
172 {
173 FIXME("(%p)->(%08lx %p %08lx)\n", iface, dwZone, ppenumString,dwFlags);
174 return E_NOTIMPL;
175 }
176
177 static IInternetSecurityManagerVtbl VT_SecManagerImpl =
178 {
179 SecManagerImpl_QueryInterface,
180 SecManagerImpl_AddRef,
181 SecManagerImpl_Release,
182 SecManagerImpl_SetSecuritySite,
183 SecManagerImpl_GetSecuritySite,
184 SecManagerImpl_MapUrlToZone,
185 SecManagerImpl_GetSecurityId,
186 SecManagerImpl_ProcessUrlAction,
187 SecManagerImpl_QueryCustomPolicy,
188 SecManagerImpl_SetZoneMapping,
189 SecManagerImpl_GetZoneMappings
190 };
191
192 HRESULT SecManagerImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
193 {
194 SecManagerImpl *This;
195
196 TRACE("(%p,%p)\n",pUnkOuter,ppobj);
197 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
198
199 /* Initialize the virtual function table. */
200 This->lpvtbl1 = &VT_SecManagerImpl;
201 This->ref = 1;
202
203 *ppobj = This;
204 return S_OK;
205 }
206
207 /***********************************************************************
208 * InternetZoneManager implementation
209 *
210 */
211 typedef struct {
212 IInternetZoneManagerVtbl* lpVtbl;
213 ULONG 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 URLMON_LockModule();
251
252 return refCount;
253 }
254
255 /********************************************************************
256 * IInternetZoneManager_Release
257 */
258 static ULONG WINAPI ZoneMgrImpl_Release(IInternetZoneManager* iface)
259 {
260 ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
261 ULONG refCount = InterlockedDecrement(&This->ref);
262
263 TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1);
264
265 if(!refCount)
266 HeapFree(GetProcessHeap(), 0, This);
267
268 URLMON_UnlockModule();
269
270 return refCount;
271 }
272
273 /********************************************************************
274 * IInternetZoneManager_GetZoneAttributes
275 */
276 static HRESULT WINAPI ZoneMgrImpl_GetZoneAttributes(IInternetZoneManager* iface,
277 DWORD dwZone,
278 ZONEATTRIBUTES* pZoneAttributes)
279 {
280 FIXME("(%p)->(%ld %p) stub\n", iface, dwZone, pZoneAttributes);
281 return E_NOTIMPL;
282 }
283
284 /********************************************************************
285 * IInternetZoneManager_SetZoneAttributes
286 */
287 static HRESULT WINAPI ZoneMgrImpl_SetZoneAttributes(IInternetZoneManager* iface,
288 DWORD dwZone,
289 ZONEATTRIBUTES* pZoneAttributes)
290 {
291 FIXME("(%p)->(%08lx %p) stub\n", iface, dwZone, pZoneAttributes);
292 return E_NOTIMPL;
293 }
294
295 /********************************************************************
296 * IInternetZoneManager_GetZoneCustomPolicy
297 */
298 static HRESULT WINAPI ZoneMgrImpl_GetZoneCustomPolicy(IInternetZoneManager* iface,
299 DWORD dwZone,
300 REFGUID guidKey,
301 BYTE** ppPolicy,
302 DWORD* pcbPolicy,
303 URLZONEREG ulrZoneReg)
304 {
305 FIXME("(%p)->(%08lx %s %p %p %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
306 ppPolicy, pcbPolicy, ulrZoneReg);
307 return E_NOTIMPL;
308 }
309
310 /********************************************************************
311 * IInternetZoneManager_SetZoneCustomPolicy
312 */
313 static HRESULT WINAPI ZoneMgrImpl_SetZoneCustomPolicy(IInternetZoneManager* iface,
314 DWORD dwZone,
315 REFGUID guidKey,
316 BYTE* ppPolicy,
317 DWORD cbPolicy,
318 URLZONEREG ulrZoneReg)
319 {
320 FIXME("(%p)->(%08lx %s %p %08lx %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
321 ppPolicy, cbPolicy, ulrZoneReg);
322 return E_NOTIMPL;
323 }
324
325 /********************************************************************
326 * IInternetZoneManager_GetZoneActionPolicy
327 */
328 static HRESULT WINAPI ZoneMgrImpl_GetZoneActionPolicy(IInternetZoneManager* iface,
329 DWORD dwZone,
330 DWORD dwAction,
331 BYTE* pPolicy,
332 DWORD cbPolicy,
333 URLZONEREG urlZoneReg)
334 {
335 FIXME("(%p)->(%08lx %08lx %p %08lx %08x) stub\n", iface, dwZone, dwAction, pPolicy,
336 cbPolicy, urlZoneReg);
337 return E_NOTIMPL;
338 }
339
340 /********************************************************************
341 * IInternetZoneManager_SetZoneActionPolicy
342 */
343 static HRESULT WINAPI ZoneMgrImpl_SetZoneActionPolicy(IInternetZoneManager* iface,
344 DWORD dwZone,
345 DWORD dwAction,
346 BYTE* pPolicy,
347 DWORD cbPolicy,
348 URLZONEREG urlZoneReg)
349 {
350 FIXME("(%p)->(%08lx %08lx %p %08lx %08x) stub\n", iface, dwZone, dwAction, pPolicy,
351 cbPolicy, urlZoneReg);
352 return E_NOTIMPL;
353 }
354
355 /********************************************************************
356 * IInternetZoneManager_PromptAction
357 */
358 static HRESULT WINAPI ZoneMgrImpl_PromptAction(IInternetZoneManager* iface,
359 DWORD dwAction,
360 HWND hwndParent,
361 LPCWSTR pwszUrl,
362 LPCWSTR pwszText,
363 DWORD dwPromptFlags)
364 {
365 FIXME("%p %08lx %p %s %s %08lx\n", iface, dwAction, hwndParent,
366 debugstr_w(pwszUrl), debugstr_w(pwszText), dwPromptFlags );
367 return E_NOTIMPL;
368 }
369
370 /********************************************************************
371 * IInternetZoneManager_LogAction
372 */
373 static HRESULT WINAPI ZoneMgrImpl_LogAction(IInternetZoneManager* iface,
374 DWORD dwAction,
375 LPCWSTR pwszUrl,
376 LPCWSTR pwszText,
377 DWORD dwLogFlags)
378 {
379 FIXME("(%p)->(%08lx %s %s %08lx) stub\n", iface, dwAction, debugstr_w(pwszUrl),
380 debugstr_w(pwszText), dwLogFlags);
381 return E_NOTIMPL;
382 }
383
384 /********************************************************************
385 * IInternetZoneManager_CreateZoneEnumerator
386 */
387 static HRESULT WINAPI ZoneMgrImpl_CreateZoneEnumerator(IInternetZoneManager* iface,
388 DWORD* pdwEnum,
389 DWORD* pdwCount,
390 DWORD dwFlags)
391 {
392 FIXME("(%p)->(%p %p %08lx) stub\n", iface, pdwEnum, pdwCount, dwFlags);
393 return E_NOTIMPL;
394 }
395
396 /********************************************************************
397 * IInternetZoneManager_GetZoneAt
398 */
399 static HRESULT WINAPI ZoneMgrImpl_GetZoneAt(IInternetZoneManager* iface,
400 DWORD dwEnum,
401 DWORD dwIndex,
402 DWORD* pdwZone)
403 {
404 FIXME("(%p)->(%08lx %08lx %p) stub\n", iface, dwEnum, dwIndex, pdwZone);
405 return E_NOTIMPL;
406 }
407
408 /********************************************************************
409 * IInternetZoneManager_DestroyZoneEnumerator
410 */
411 static HRESULT WINAPI ZoneMgrImpl_DestroyZoneEnumerator(IInternetZoneManager* iface,
412 DWORD dwEnum)
413 {
414 FIXME("(%p)->(%08lx) stub\n", iface, dwEnum);
415 return E_NOTIMPL;
416 }
417
418 /********************************************************************
419 * IInternetZoneManager_CopyTemplatePoliciesToZone
420 */
421 static HRESULT WINAPI ZoneMgrImpl_CopyTemplatePoliciesToZone(IInternetZoneManager* iface,
422 DWORD dwTemplate,
423 DWORD dwZone,
424 DWORD dwReserved)
425 {
426 FIXME("(%p)->(%08lx %08lx %08lx) stub\n", iface, dwTemplate, dwZone, dwReserved);
427 return E_NOTIMPL;
428 }
429
430 /********************************************************************
431 * IInternetZoneManager_Construct
432 */
433 static IInternetZoneManagerVtbl ZoneMgrImplVtbl = {
434 ZoneMgrImpl_QueryInterface,
435 ZoneMgrImpl_AddRef,
436 ZoneMgrImpl_Release,
437 ZoneMgrImpl_GetZoneAttributes,
438 ZoneMgrImpl_SetZoneAttributes,
439 ZoneMgrImpl_GetZoneCustomPolicy,
440 ZoneMgrImpl_SetZoneCustomPolicy,
441 ZoneMgrImpl_GetZoneActionPolicy,
442 ZoneMgrImpl_SetZoneActionPolicy,
443 ZoneMgrImpl_PromptAction,
444 ZoneMgrImpl_LogAction,
445 ZoneMgrImpl_CreateZoneEnumerator,
446 ZoneMgrImpl_GetZoneAt,
447 ZoneMgrImpl_DestroyZoneEnumerator,
448 ZoneMgrImpl_CopyTemplatePoliciesToZone,
449 };
450
451 HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
452 {
453 ZoneMgrImpl* ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ZoneMgrImpl));
454
455 TRACE("(%p %p)\n", pUnkOuter, ppobj);
456 ret->lpVtbl = &ZoneMgrImplVtbl;
457 ret->ref = 1;
458 *ppobj = (IInternetZoneManager*)ret;
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 }