d3d8: Cleanup the stateblock test callbacks a bit.
[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  * Copyright 2009 Detlef Riekenberg
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include <stdio.h>
24
25 #include "urlmon_main.h"
26 #include "winreg.h"
27 #include "wininet.h"
28
29 #include "wine/debug.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
32
33 static const WCHAR currentlevelW[] = {'C','u','r','r','e','n','t','L','e','v','e','l',0};
34 static const WCHAR descriptionW[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
35 static const WCHAR displaynameW[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
36 static const WCHAR fileW[] = {'f','i','l','e',0};
37 static const WCHAR flagsW[] = {'F','l','a','g','s',0};
38 static const WCHAR iconW[] = {'I','c','o','n',0};
39 static const WCHAR minlevelW[] = {'M','i','n','L','e','v','e','l',0};
40 static const WCHAR recommendedlevelW[] = {'R','e','c','o','m','m','e','n','d','e','d',
41                                           'L','e','v','e','l',0};
42 static const WCHAR wszZonesKey[] = {'S','o','f','t','w','a','r','e','\\',
43                                     'M','i','c','r','o','s','o','f','t','\\',
44                                     'W','i','n','d','o','w','s','\\',
45                                     'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
46                                     'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
47                                     'Z','o','n','e','s','\\',0};
48
49 /********************************************************************
50  * get_string_from_reg [internal]
51  *
52  * helper to get a string from the reg.
53  *
54  */
55 static void get_string_from_reg(HKEY hcu, HKEY hklm, LPCWSTR name, LPWSTR out, DWORD maxlen)
56 {
57     DWORD type = REG_SZ;
58     DWORD len = maxlen * sizeof(WCHAR);
59     DWORD res;
60
61     res = RegQueryValueExW(hcu, name, NULL, &type, (LPBYTE) out, &len);
62
63     if (res && hklm) {
64         len = maxlen * sizeof(WCHAR);
65         type = REG_SZ;
66         res = RegQueryValueExW(hklm, name, NULL, &type, (LPBYTE) out, &len);
67     }
68
69     if (res) {
70         TRACE("%s failed: %d\n", debugstr_w(name), res);
71         *out = '\0';
72     }
73 }
74
75 /********************************************************************
76  * get_dword_from_reg [internal]
77  *
78  * helper to get a dword from the reg.
79  *
80  */
81 static void get_dword_from_reg(HKEY hcu, HKEY hklm, LPCWSTR name, LPDWORD out)
82 {
83     DWORD type = REG_DWORD;
84     DWORD len = sizeof(DWORD);
85     DWORD res;
86
87     res = RegQueryValueExW(hcu, name, NULL, &type, (LPBYTE) out, &len);
88
89     if (res && hklm) {
90         len = sizeof(DWORD);
91         type = REG_DWORD;
92         res = RegQueryValueExW(hklm, name, NULL, &type, (LPBYTE) out, &len);
93     }
94
95     if (res) {
96         TRACE("%s failed: %d\n", debugstr_w(name), res);
97         *out = 0;
98     }
99 }
100
101 static HRESULT get_zone_from_reg(LPCWSTR schema, DWORD *zone)
102 {
103     DWORD res, size;
104     HKEY hkey;
105
106     static const WCHAR wszZoneMapProtocolKey[] =
107         {'S','o','f','t','w','a','r','e','\\',
108          'M','i','c','r','o','s','o','f','t','\\',
109          'W','i','n','d','o','w','s','\\',
110          'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
111          'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
112          'Z','o','n','e','M','a','p','\\',
113          'P','r','o','t','o','c','o','l','D','e','f','a','u','l','t','s',0};
114
115     res = RegOpenKeyW(HKEY_CURRENT_USER, wszZoneMapProtocolKey, &hkey);
116     if(res != ERROR_SUCCESS) {
117         ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey));
118         return E_UNEXPECTED;
119     }
120
121     size = sizeof(DWORD);
122     res = RegQueryValueExW(hkey, schema, NULL, NULL, (PBYTE)zone, &size);
123     RegCloseKey(hkey);
124     if(res == ERROR_SUCCESS)
125         return S_OK;
126
127     res = RegOpenKeyW(HKEY_LOCAL_MACHINE, wszZoneMapProtocolKey, &hkey);
128     if(res != ERROR_SUCCESS) {
129         ERR("Could not open key %s\n", debugstr_w(wszZoneMapProtocolKey));
130         return E_UNEXPECTED;
131     }
132
133     size = sizeof(DWORD);
134     res = RegQueryValueExW(hkey, schema, NULL, NULL, (PBYTE)zone, &size);
135     RegCloseKey(hkey);
136     if(res == ERROR_SUCCESS)
137         return S_OK;
138
139     *zone = 3;
140     return S_OK;
141 }
142
143 static HRESULT map_url_to_zone(LPCWSTR url, DWORD *zone, LPWSTR *ret_url)
144 {
145     LPWSTR secur_url;
146     WCHAR schema[64];
147     DWORD size=0;
148     HRESULT hres;
149
150     secur_url = heap_alloc(INTERNET_MAX_URL_LENGTH*sizeof(WCHAR));
151     *zone = -1;
152
153     hres = CoInternetParseUrl(url, PARSE_SECURITY_URL, 0, secur_url, INTERNET_MAX_URL_LENGTH, &size, 0);
154     if(hres != S_OK)
155         strcpyW(secur_url, url);
156
157     hres = CoInternetParseUrl(secur_url, PARSE_SCHEMA, 0, schema, sizeof(schema)/sizeof(WCHAR), &size, 0);
158     if(FAILED(hres) || !*schema) {
159         heap_free(secur_url);
160         return E_INVALIDARG;
161     }
162
163     /* file protocol is a special case */
164     if(!strcmpW(schema, fileW)) {
165         WCHAR path[MAX_PATH], root[20];
166         WCHAR *ptr;
167
168         hres = CoInternetParseUrl(secur_url, PARSE_PATH_FROM_URL, 0, path,
169                 sizeof(path)/sizeof(WCHAR), &size, 0);
170
171         if(SUCCEEDED(hres) && (ptr = strchrW(path, '\\')) && ptr-path < sizeof(root)/sizeof(WCHAR)) {
172             UINT type;
173
174             memcpy(root, path, (ptr-path)*sizeof(WCHAR));
175             root[ptr-path] = 0;
176
177             type = GetDriveTypeW(root);
178
179             switch(type) {
180             case DRIVE_UNKNOWN:
181             case DRIVE_NO_ROOT_DIR:
182                 break;
183             case DRIVE_REMOVABLE:
184             case DRIVE_FIXED:
185             case DRIVE_CDROM:
186             case DRIVE_RAMDISK:
187                 *zone = 0;
188                 hres = S_OK;
189                 break;
190             case DRIVE_REMOTE:
191                 *zone = 3;
192                 hres = S_OK;
193                 break;
194             default:
195                 FIXME("unsupported drive type %d\n", type);
196             }
197         }
198     }
199
200     if(*zone == -1) {
201         WARN("domains are not yet implemented\n");
202         hres = get_zone_from_reg(schema, zone);
203     }
204
205     if(FAILED(hres) || !ret_url)
206         heap_free(secur_url);
207     else
208         *ret_url = secur_url;
209
210     return hres;
211 }
212
213 static HRESULT open_zone_key(HKEY parent_key, DWORD zone, HKEY *hkey)
214 {
215     static const WCHAR wszFormat[] = {'%','s','%','l','d',0};
216
217     WCHAR key_name[sizeof(wszZonesKey)/sizeof(WCHAR)+8];
218     DWORD res;
219
220     wsprintfW(key_name, wszFormat, wszZonesKey, zone);
221
222     res = RegOpenKeyW(parent_key, key_name, hkey);
223
224     if(res != ERROR_SUCCESS) {
225         WARN("RegOpenKey failed\n");
226         return E_INVALIDARG;
227     }
228
229     return S_OK;
230 }
231
232 static HRESULT get_action_policy(DWORD zone, DWORD action, BYTE *policy, DWORD size, URLZONEREG zone_reg)
233 {
234     HKEY parent_key;
235     HKEY hkey;
236     LONG res;
237     HRESULT hres;
238
239     switch(action) {
240     case URLACTION_SCRIPT_OVERRIDE_SAFETY:
241     case URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY:
242         *(DWORD*)policy = URLPOLICY_DISALLOW;
243         return S_OK;
244     }
245
246     switch(zone_reg) {
247     case URLZONEREG_DEFAULT:
248     case URLZONEREG_HKCU:
249         parent_key = HKEY_CURRENT_USER;
250         break;
251     case URLZONEREG_HKLM:
252         parent_key = HKEY_LOCAL_MACHINE;
253         break;
254     default:
255         WARN("Unknown URLZONEREG: %d\n", zone_reg);
256         return E_FAIL;
257     };
258
259     hres = open_zone_key(parent_key, zone, &hkey);
260     if(SUCCEEDED(hres)) {
261         WCHAR action_str[16];
262         DWORD len = size;
263
264         static const WCHAR formatW[] = {'%','X',0};
265
266         wsprintfW(action_str, formatW, action);
267
268         res = RegQueryValueExW(hkey, action_str, NULL, NULL, policy, &len);
269         if(res == ERROR_MORE_DATA) {
270             hres = E_INVALIDARG;
271         }else if(res == ERROR_FILE_NOT_FOUND) {
272             hres = E_FAIL;
273         }else if(res != ERROR_SUCCESS) {
274             ERR("RegQueryValue failed: %d\n", res);
275             hres = E_UNEXPECTED;
276         }
277
278         RegCloseKey(hkey);
279     }
280
281     if(FAILED(hres) && zone_reg == URLZONEREG_DEFAULT)
282         return get_action_policy(zone, action, policy, size, URLZONEREG_HKLM);
283
284     return hres;
285 }
286
287 /***********************************************************************
288  *           InternetSecurityManager implementation
289  *
290  */
291 typedef struct {
292     const IInternetSecurityManagerVtbl* lpInternetSecurityManagerVtbl;
293
294     LONG ref;
295
296     IInternetSecurityMgrSite *mgrsite;
297     IInternetSecurityManager *custom_manager;
298 } SecManagerImpl;
299
300 #define SECMGR_THIS(iface) DEFINE_THIS(SecManagerImpl, InternetSecurityManager, iface)
301
302 static HRESULT WINAPI SecManagerImpl_QueryInterface(IInternetSecurityManager* iface,REFIID riid,void** ppvObject)
303 {
304     SecManagerImpl *This = SECMGR_THIS(iface);
305
306     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
307
308     /* Perform a sanity check on the parameters.*/
309     if ( (This==0) || (ppvObject==0) )
310         return E_INVALIDARG;
311
312     /* Initialize the return parameter */
313     *ppvObject = 0;
314
315     /* Compare the riid with the interface IDs implemented by this object.*/
316     if (IsEqualIID(&IID_IUnknown, riid) ||
317         IsEqualIID(&IID_IInternetSecurityManager, riid))
318         *ppvObject = iface;
319
320     /* Check that we obtained an interface.*/
321     if (!*ppvObject) {
322         WARN("not supported interface %s\n", debugstr_guid(riid));
323         return E_NOINTERFACE;
324     }
325
326     /* Query Interface always increases the reference count by one when it is successful */
327     IInternetSecurityManager_AddRef(iface);
328
329     return S_OK;
330 }
331
332 static ULONG WINAPI SecManagerImpl_AddRef(IInternetSecurityManager* iface)
333 {
334     SecManagerImpl *This = SECMGR_THIS(iface);
335     ULONG refCount = InterlockedIncrement(&This->ref);
336
337     TRACE("(%p) ref=%u\n", This, refCount);
338
339     return refCount;
340 }
341
342 static ULONG WINAPI SecManagerImpl_Release(IInternetSecurityManager* iface)
343 {
344     SecManagerImpl *This = SECMGR_THIS(iface);
345     ULONG refCount = InterlockedDecrement(&This->ref);
346
347     TRACE("(%p) ref=%u\n", This, refCount);
348
349     /* destroy the object if there's no more reference on it */
350     if (!refCount){
351         if(This->mgrsite)
352             IInternetSecurityMgrSite_Release(This->mgrsite);
353         if(This->custom_manager)
354             IInternetSecurityManager_Release(This->custom_manager);
355
356         heap_free(This);
357
358         URLMON_UnlockModule();
359     }
360
361     return refCount;
362 }
363
364 static HRESULT WINAPI SecManagerImpl_SetSecuritySite(IInternetSecurityManager *iface,
365                                                      IInternetSecurityMgrSite *pSite)
366 {
367     SecManagerImpl *This = SECMGR_THIS(iface);
368
369     TRACE("(%p)->(%p)\n", This, pSite);
370
371     if(This->mgrsite)
372         IInternetSecurityMgrSite_Release(This->mgrsite);
373
374     if(This->custom_manager) {
375         IInternetSecurityManager_Release(This->custom_manager);
376         This->custom_manager = NULL;
377     }
378
379     This->mgrsite = pSite;
380
381     if(pSite) {
382         IServiceProvider *servprov;
383         HRESULT hres;
384
385         IInternetSecurityMgrSite_AddRef(pSite);
386
387         hres = IInternetSecurityMgrSite_QueryInterface(pSite, &IID_IServiceProvider,
388                 (void**)&servprov);
389         if(SUCCEEDED(hres)) {
390             IServiceProvider_QueryService(servprov, &SID_SInternetSecurityManager,
391                     &IID_IInternetSecurityManager, (void**)&This->custom_manager);
392             IServiceProvider_Release(servprov);
393         }
394     }
395
396     return S_OK;
397 }
398
399 static HRESULT WINAPI SecManagerImpl_GetSecuritySite(IInternetSecurityManager *iface,
400                                                      IInternetSecurityMgrSite **ppSite)
401 {
402     SecManagerImpl *This = SECMGR_THIS(iface);
403
404     TRACE("(%p)->(%p)\n", This, ppSite);
405
406     if(!ppSite)
407         return E_INVALIDARG;
408
409     if(This->mgrsite)
410         IInternetSecurityMgrSite_AddRef(This->mgrsite);
411
412     *ppSite = This->mgrsite;
413     return S_OK;
414 }
415
416 static HRESULT WINAPI SecManagerImpl_MapUrlToZone(IInternetSecurityManager *iface,
417                                                   LPCWSTR pwszUrl, DWORD *pdwZone,
418                                                   DWORD dwFlags)
419 {
420     SecManagerImpl *This = SECMGR_THIS(iface);
421     HRESULT hres;
422
423     TRACE("(%p)->(%s %p %08x)\n", iface, debugstr_w(pwszUrl), pdwZone, dwFlags);
424
425     if(This->custom_manager) {
426         hres = IInternetSecurityManager_MapUrlToZone(This->custom_manager,
427                 pwszUrl, pdwZone, dwFlags);
428         if(hres != INET_E_DEFAULT_ACTION)
429             return hres;
430     }
431
432     if(!pwszUrl) {
433         *pdwZone = -1;
434         return E_INVALIDARG;
435     }
436
437     if(dwFlags)
438         FIXME("not supported flags: %08x\n", dwFlags);
439
440     return map_url_to_zone(pwszUrl, pdwZone, NULL);
441 }
442
443 static HRESULT WINAPI SecManagerImpl_GetSecurityId(IInternetSecurityManager *iface, 
444         LPCWSTR pwszUrl, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
445 {
446     SecManagerImpl *This = SECMGR_THIS(iface);
447     LPWSTR url, ptr, ptr2;
448     DWORD zone, len;
449     HRESULT hres;
450
451     static const WCHAR wszFile[] = {'f','i','l','e',':'};
452
453     TRACE("(%p)->(%s %p %p %08lx)\n", iface, debugstr_w(pwszUrl), pbSecurityId,
454           pcbSecurityId, dwReserved);
455
456     if(This->custom_manager) {
457         hres = IInternetSecurityManager_GetSecurityId(This->custom_manager,
458                 pwszUrl, pbSecurityId, pcbSecurityId, dwReserved);
459         if(hres != INET_E_DEFAULT_ACTION)
460             return hres;
461     }
462
463     if(!pwszUrl || !pbSecurityId || !pcbSecurityId)
464         return E_INVALIDARG;
465
466     if(dwReserved)
467         FIXME("dwReserved is not supported\n");
468
469     hres = map_url_to_zone(pwszUrl, &zone, &url);
470     if(FAILED(hres))
471         return hres == 0x80041001 ? E_INVALIDARG : hres;
472
473     /* file protocol is a special case */
474     if(strlenW(url) >= sizeof(wszFile)/sizeof(WCHAR)
475             && !memcmp(url, wszFile, sizeof(wszFile)) && strchrW(url, '\\')) {
476
477         static const BYTE secidFile[] = {'f','i','l','e',':'};
478
479         heap_free(url);
480
481         if(*pcbSecurityId < sizeof(secidFile)+sizeof(zone))
482             return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
483
484         memcpy(pbSecurityId, secidFile, sizeof(secidFile));
485         *(DWORD*)(pbSecurityId+sizeof(secidFile)) = zone;
486
487         *pcbSecurityId = sizeof(secidFile)+sizeof(zone);
488         return S_OK;
489     }
490
491     ptr = strchrW(url, ':');
492     ptr2 = ++ptr;
493     while(*ptr2 == '/')
494         ptr2++;
495     if(ptr2 != ptr)
496         memmove(ptr, ptr2, (strlenW(ptr2)+1)*sizeof(WCHAR));
497
498     ptr = strchrW(ptr, '/');
499     if(ptr)
500         *ptr = 0;
501
502     len = WideCharToMultiByte(CP_ACP, 0, url, -1, NULL, 0, NULL, NULL)-1;
503
504     if(len+sizeof(DWORD) > *pcbSecurityId) {
505         heap_free(url);
506         return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
507     }
508
509     WideCharToMultiByte(CP_ACP, 0, url, -1, (LPSTR)pbSecurityId, len, NULL, NULL);
510     heap_free(url);
511
512     *(DWORD*)(pbSecurityId+len) = zone;
513
514     *pcbSecurityId = len+sizeof(DWORD);
515
516     return S_OK;
517 }
518
519
520 static HRESULT WINAPI SecManagerImpl_ProcessUrlAction(IInternetSecurityManager *iface,
521                                                       LPCWSTR pwszUrl, DWORD dwAction,
522                                                       BYTE *pPolicy, DWORD cbPolicy,
523                                                       BYTE *pContext, DWORD cbContext,
524                                                       DWORD dwFlags, DWORD dwReserved)
525 {
526     SecManagerImpl *This = SECMGR_THIS(iface);
527     DWORD zone, policy;
528     HRESULT hres;
529
530     TRACE("(%p)->(%s %08x %p %08x %p %08x %08x %08x)\n", iface, debugstr_w(pwszUrl), dwAction,
531           pPolicy, cbPolicy, pContext, cbContext, dwFlags, dwReserved);
532
533     if(This->custom_manager) {
534         hres = IInternetSecurityManager_ProcessUrlAction(This->custom_manager, pwszUrl, dwAction,
535                 pPolicy, cbPolicy, pContext, cbContext, dwFlags, dwReserved);
536         if(hres != INET_E_DEFAULT_ACTION)
537             return hres;
538     }
539
540     if(dwFlags || dwReserved)
541         FIXME("Unsupported arguments\n");
542
543     if(!pwszUrl)
544         return E_INVALIDARG;
545
546     hres = map_url_to_zone(pwszUrl, &zone, NULL);
547     if(FAILED(hres))
548         return hres;
549
550     hres = get_action_policy(zone, dwAction, (BYTE*)&policy, sizeof(policy), URLZONEREG_DEFAULT);
551     if(FAILED(hres))
552         return hres;
553
554     TRACE("policy %x\n", policy);
555     if(cbPolicy >= sizeof(DWORD))
556         *(DWORD*)pPolicy = policy;
557
558     switch(GetUrlPolicyPermissions(policy)) {
559     case URLPOLICY_ALLOW:
560     case URLPOLICY_CHANNEL_SOFTDIST_PRECACHE:
561         return S_OK;
562     case URLPOLICY_DISALLOW:
563         return S_FALSE;
564     case URLPOLICY_QUERY:
565         FIXME("URLPOLICY_QUERY not implemented\n");
566         return E_FAIL;
567     default:
568         FIXME("Not implemented policy %x\n", policy);
569     }
570
571     return E_FAIL;
572 }
573                                                
574
575 static HRESULT WINAPI SecManagerImpl_QueryCustomPolicy(IInternetSecurityManager *iface,
576                                                        LPCWSTR pwszUrl, REFGUID guidKey,
577                                                        BYTE **ppPolicy, DWORD *pcbPolicy,
578                                                        BYTE *pContext, DWORD cbContext,
579                                                        DWORD dwReserved)
580 {
581     SecManagerImpl *This = SECMGR_THIS(iface);
582     HRESULT hres;
583
584     TRACE("(%p)->(%s %s %p %p %p %08x %08x )\n", iface, debugstr_w(pwszUrl), debugstr_guid(guidKey),
585           ppPolicy, pcbPolicy, pContext, cbContext, dwReserved);
586
587     if(This->custom_manager) {
588         hres = IInternetSecurityManager_QueryCustomPolicy(This->custom_manager, pwszUrl, guidKey,
589                 ppPolicy, pcbPolicy, pContext, cbContext, dwReserved);
590         if(hres != INET_E_DEFAULT_ACTION)
591             return hres;
592     }
593
594     WARN("Unknown guidKey %s\n", debugstr_guid(guidKey));
595     return HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
596 }
597
598 static HRESULT WINAPI SecManagerImpl_SetZoneMapping(IInternetSecurityManager *iface,
599                                                     DWORD dwZone, LPCWSTR pwszPattern, DWORD dwFlags)
600 {
601     SecManagerImpl *This = SECMGR_THIS(iface);
602     HRESULT hres;
603
604     TRACE("(%p)->(%08x %s %08x)\n", iface, dwZone, debugstr_w(pwszPattern),dwFlags);
605
606     if(This->custom_manager) {
607         hres = IInternetSecurityManager_SetZoneMapping(This->custom_manager, dwZone,
608                 pwszPattern, dwFlags);
609         if(hres != INET_E_DEFAULT_ACTION)
610             return hres;
611     }
612
613     FIXME("Default action is not implemented\n");
614     return E_NOTIMPL;
615 }
616
617 static HRESULT WINAPI SecManagerImpl_GetZoneMappings(IInternetSecurityManager *iface,
618         DWORD dwZone, IEnumString **ppenumString, DWORD dwFlags)
619 {
620     SecManagerImpl *This = SECMGR_THIS(iface);
621     HRESULT hres;
622
623     TRACE("(%p)->(%08x %p %08x)\n", iface, dwZone, ppenumString,dwFlags);
624
625     if(This->custom_manager) {
626         hres = IInternetSecurityManager_GetZoneMappings(This->custom_manager, dwZone,
627                 ppenumString, dwFlags);
628         if(hres != INET_E_DEFAULT_ACTION)
629             return hres;
630     }
631
632     FIXME("Default action is not implemented\n");
633     return E_NOTIMPL;
634 }
635
636 static const IInternetSecurityManagerVtbl VT_SecManagerImpl =
637 {
638     SecManagerImpl_QueryInterface,
639     SecManagerImpl_AddRef,
640     SecManagerImpl_Release,
641     SecManagerImpl_SetSecuritySite,
642     SecManagerImpl_GetSecuritySite,
643     SecManagerImpl_MapUrlToZone,
644     SecManagerImpl_GetSecurityId,
645     SecManagerImpl_ProcessUrlAction,
646     SecManagerImpl_QueryCustomPolicy,
647     SecManagerImpl_SetZoneMapping,
648     SecManagerImpl_GetZoneMappings
649 };
650
651 HRESULT SecManagerImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
652 {
653     SecManagerImpl *This;
654
655     TRACE("(%p,%p)\n",pUnkOuter,ppobj);
656     This = heap_alloc(sizeof(*This));
657
658     /* Initialize the virtual function table. */
659     This->lpInternetSecurityManagerVtbl = &VT_SecManagerImpl;
660
661     This->ref = 1;
662     This->mgrsite = NULL;
663     This->custom_manager = NULL;
664
665     *ppobj = This;
666
667     URLMON_LockModule();
668
669     return S_OK;
670 }
671
672 /***********************************************************************
673  *           InternetZoneManager implementation
674  *
675  */
676 typedef struct {
677     const IInternetZoneManagerEx2Vtbl* lpVtbl;
678     LONG ref;
679     LPDWORD *zonemaps;
680     DWORD zonemap_count;
681 } ZoneMgrImpl;
682
683
684 /***********************************************************************
685  * build_zonemap_from_reg [internal]
686  *
687  * Enumerate the Zones in the Registry and return the Zones in a DWORD-array
688  * The number of the Zones is returned in data[0]
689  */
690 static LPDWORD build_zonemap_from_reg(void)
691 {
692     WCHAR name[32];
693     HKEY hkey;
694     LPDWORD data = NULL;
695     DWORD allocated = 6; /* space for the zonecount and Zone "0" up to Zone "4" */
696     DWORD used = 0;
697     DWORD res;
698     DWORD len;
699
700
701     res = RegOpenKeyW(HKEY_CURRENT_USER, wszZonesKey, &hkey);
702     if (res)
703         return NULL;
704
705     data = heap_alloc(allocated * sizeof(DWORD));
706     if (!data)
707         goto cleanup;
708
709     while (!res) {
710         name[0] = '\0';
711         len = sizeof(name) / sizeof(name[0]);
712         res = RegEnumKeyExW(hkey, used, name, &len, NULL, NULL, NULL, NULL);
713
714         if (!res) {
715             used++;
716             if (used == allocated) {
717                 LPDWORD new_data;
718
719                 allocated *= 2;
720                 new_data = heap_realloc_zero(data, allocated * sizeof(DWORD));
721                 if (!new_data)
722                     goto cleanup;
723
724                 data = new_data;
725             }
726             data[used] = atoiW(name);
727         }
728     }
729     if (used) {
730         RegCloseKey(hkey);
731         data[0] = used;
732         return data;
733     }
734
735 cleanup:
736     /* something failed */
737     RegCloseKey(hkey);
738     heap_free(data);
739     return NULL;
740 }
741
742 /********************************************************************
743  *      IInternetZoneManager_QueryInterface
744  */
745 static HRESULT WINAPI ZoneMgrImpl_QueryInterface(IInternetZoneManagerEx2* iface, REFIID riid, void** ppvObject)
746 {
747     ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
748
749     TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
750
751     if(!This || !ppvObject)
752         return E_INVALIDARG;
753
754     if(IsEqualIID(&IID_IUnknown, riid)) {
755         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppvObject);
756     }else if(IsEqualIID(&IID_IInternetZoneManager, riid)) {
757         TRACE("(%p)->(IID_InternetZoneManager %p)\n", This, ppvObject);
758     }else if(IsEqualIID(&IID_IInternetZoneManagerEx, riid)) {
759         TRACE("(%p)->(IID_InternetZoneManagerEx %p)\n", This, ppvObject);
760     }else if(IsEqualIID(&IID_IInternetZoneManagerEx2, riid)) {
761         TRACE("(%p)->(IID_InternetZoneManagerEx2 %p)\n", This, ppvObject);
762     }
763     else
764     {
765         FIXME("Unknown interface: %s\n", debugstr_guid(riid));
766         *ppvObject = NULL;
767         return E_NOINTERFACE;
768     }
769
770     *ppvObject = iface;
771     IInternetZoneManager_AddRef(iface);
772     return S_OK;
773 }
774
775 /********************************************************************
776  *      IInternetZoneManager_AddRef
777  */
778 static ULONG WINAPI ZoneMgrImpl_AddRef(IInternetZoneManagerEx2* iface)
779 {
780     ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
781     ULONG refCount = InterlockedIncrement(&This->ref);
782
783     TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
784
785     return refCount;
786 }
787
788 /********************************************************************
789  *      IInternetZoneManager_Release
790  */
791 static ULONG WINAPI ZoneMgrImpl_Release(IInternetZoneManagerEx2* iface)
792 {
793     ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
794     ULONG refCount = InterlockedDecrement(&This->ref);
795
796     TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
797
798     if(!refCount) {
799         while (This->zonemap_count) heap_free(This->zonemaps[--This->zonemap_count]);
800         heap_free(This->zonemaps);
801         heap_free(This);
802         URLMON_UnlockModule();
803     }
804     
805     return refCount;
806 }
807
808 /********************************************************************
809  *      IInternetZoneManager_GetZoneAttributes
810  */
811 static HRESULT WINAPI ZoneMgrImpl_GetZoneAttributes(IInternetZoneManagerEx2* iface,
812                                                     DWORD dwZone,
813                                                     ZONEATTRIBUTES* pZoneAttributes)
814 {
815     ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
816     HRESULT hr;
817     HKEY hcu;
818     HKEY hklm = NULL;
819
820     TRACE("(%p)->(%d %p)\n", This, dwZone, pZoneAttributes);
821
822     if (!pZoneAttributes)
823         return E_INVALIDARG;
824
825     hr = open_zone_key(HKEY_CURRENT_USER, dwZone, &hcu);
826     if (FAILED(hr))
827         return S_OK;  /* IE6 and older returned E_FAIL here */
828
829     hr = open_zone_key(HKEY_LOCAL_MACHINE, dwZone, &hklm);
830     if (FAILED(hr))
831         TRACE("Zone %d not in HKLM\n", dwZone);
832
833     get_string_from_reg(hcu, hklm, displaynameW, pZoneAttributes->szDisplayName, MAX_ZONE_PATH);
834     get_string_from_reg(hcu, hklm, descriptionW, pZoneAttributes->szDescription, MAX_ZONE_DESCRIPTION);
835     get_string_from_reg(hcu, hklm, iconW, pZoneAttributes->szIconPath, MAX_ZONE_PATH);
836     get_dword_from_reg(hcu, hklm, minlevelW, &pZoneAttributes->dwTemplateMinLevel);
837     get_dword_from_reg(hcu, hklm, currentlevelW, &pZoneAttributes->dwTemplateCurrentLevel);
838     get_dword_from_reg(hcu, hklm, recommendedlevelW, &pZoneAttributes->dwTemplateRecommended);
839     get_dword_from_reg(hcu, hklm, flagsW, &pZoneAttributes->dwFlags);
840
841     RegCloseKey(hklm);
842     RegCloseKey(hcu);
843     return S_OK;
844 }
845
846 /********************************************************************
847  *      IInternetZoneManager_SetZoneAttributes
848  */
849 static HRESULT WINAPI ZoneMgrImpl_SetZoneAttributes(IInternetZoneManagerEx2* iface,
850                                                     DWORD dwZone,
851                                                     ZONEATTRIBUTES* pZoneAttributes)
852 {
853     FIXME("(%p)->(%08x %p) stub\n", iface, dwZone, pZoneAttributes);
854     return E_NOTIMPL;
855 }
856
857 /********************************************************************
858  *      IInternetZoneManager_GetZoneCustomPolicy
859  */
860 static HRESULT WINAPI ZoneMgrImpl_GetZoneCustomPolicy(IInternetZoneManagerEx2* iface,
861                                                       DWORD dwZone,
862                                                       REFGUID guidKey,
863                                                       BYTE** ppPolicy,
864                                                       DWORD* pcbPolicy,
865                                                       URLZONEREG ulrZoneReg)
866 {
867     FIXME("(%p)->(%08x %s %p %p %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
868                                                     ppPolicy, pcbPolicy, ulrZoneReg);
869     return E_NOTIMPL;
870 }
871
872 /********************************************************************
873  *      IInternetZoneManager_SetZoneCustomPolicy
874  */
875 static HRESULT WINAPI ZoneMgrImpl_SetZoneCustomPolicy(IInternetZoneManagerEx2* iface,
876                                                       DWORD dwZone,
877                                                       REFGUID guidKey,
878                                                       BYTE* ppPolicy,
879                                                       DWORD cbPolicy,
880                                                       URLZONEREG ulrZoneReg)
881 {
882     FIXME("(%p)->(%08x %s %p %08x %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
883                                                     ppPolicy, cbPolicy, ulrZoneReg);
884     return E_NOTIMPL;
885 }
886
887 /********************************************************************
888  *      IInternetZoneManager_GetZoneActionPolicy
889  */
890 static HRESULT WINAPI ZoneMgrImpl_GetZoneActionPolicy(IInternetZoneManagerEx2* iface,
891         DWORD dwZone, DWORD dwAction, BYTE* pPolicy, DWORD cbPolicy, URLZONEREG urlZoneReg)
892 {
893     TRACE("(%p)->(%d %08x %p %d %d)\n", iface, dwZone, dwAction, pPolicy,
894             cbPolicy, urlZoneReg);
895
896     if(!pPolicy)
897         return E_INVALIDARG;
898
899     return get_action_policy(dwZone, dwAction, pPolicy, cbPolicy, urlZoneReg);
900 }
901
902 /********************************************************************
903  *      IInternetZoneManager_SetZoneActionPolicy
904  */
905 static HRESULT WINAPI ZoneMgrImpl_SetZoneActionPolicy(IInternetZoneManagerEx2* iface,
906                                                       DWORD dwZone,
907                                                       DWORD dwAction,
908                                                       BYTE* pPolicy,
909                                                       DWORD cbPolicy,
910                                                       URLZONEREG urlZoneReg)
911 {
912     FIXME("(%p)->(%08x %08x %p %08x %08x) stub\n", iface, dwZone, dwAction, pPolicy,
913                                                        cbPolicy, urlZoneReg);
914     return E_NOTIMPL;
915 }
916
917 /********************************************************************
918  *      IInternetZoneManager_PromptAction
919  */
920 static HRESULT WINAPI ZoneMgrImpl_PromptAction(IInternetZoneManagerEx2* iface,
921                                                DWORD dwAction,
922                                                HWND hwndParent,
923                                                LPCWSTR pwszUrl,
924                                                LPCWSTR pwszText,
925                                                DWORD dwPromptFlags)
926 {
927     FIXME("%p %08x %p %s %s %08x\n", iface, dwAction, hwndParent,
928           debugstr_w(pwszUrl), debugstr_w(pwszText), dwPromptFlags );
929     return E_NOTIMPL;
930 }
931
932 /********************************************************************
933  *      IInternetZoneManager_LogAction
934  */
935 static HRESULT WINAPI ZoneMgrImpl_LogAction(IInternetZoneManagerEx2* iface,
936                                             DWORD dwAction,
937                                             LPCWSTR pwszUrl,
938                                             LPCWSTR pwszText,
939                                             DWORD dwLogFlags)
940 {
941     FIXME("(%p)->(%08x %s %s %08x) stub\n", iface, dwAction, debugstr_w(pwszUrl),
942                                               debugstr_w(pwszText), dwLogFlags);
943     return E_NOTIMPL;
944 }
945
946 /********************************************************************
947  *      IInternetZoneManager_CreateZoneEnumerator
948  */
949 static HRESULT WINAPI ZoneMgrImpl_CreateZoneEnumerator(IInternetZoneManagerEx2* iface,
950                                                        DWORD* pdwEnum,
951                                                        DWORD* pdwCount,
952                                                        DWORD dwFlags)
953 {
954     ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
955     LPDWORD * new_maps;
956     LPDWORD data;
957     DWORD i;
958
959     TRACE("(%p)->(%p, %p, 0x%08x)\n", This, pdwEnum, pdwCount, dwFlags);
960     if (!pdwEnum || !pdwCount || (dwFlags != 0))
961         return E_INVALIDARG;
962
963     data = build_zonemap_from_reg();
964     TRACE("found %d zones\n", data ? data[0] : -1);
965
966     if (!data)
967         return E_FAIL;
968
969     for (i = 0; i < This->zonemap_count; i++) {
970         if (This->zonemaps && !This->zonemaps[i]) {
971             This->zonemaps[i] = data;
972             *pdwEnum = i;
973             *pdwCount = data[0];
974             return S_OK;
975         }
976     }
977
978     if (This->zonemaps) {
979         /* try to double the nr. of pointers in the array */
980         new_maps = heap_realloc_zero(This->zonemaps, This->zonemap_count * 2 * sizeof(LPDWORD));
981         if (new_maps)
982             This->zonemap_count *= 2;
983     }
984     else
985     {
986         This->zonemap_count = 2;
987         new_maps = heap_alloc_zero(This->zonemap_count * sizeof(LPDWORD));
988     }
989
990     if (!new_maps) {
991         heap_free(data);
992         return E_FAIL;
993     }
994     This->zonemaps = new_maps;
995     This->zonemaps[i] = data;
996     *pdwEnum = i;
997     *pdwCount = data[0];
998     return S_OK;
999 }
1000
1001 /********************************************************************
1002  *      IInternetZoneManager_GetZoneAt
1003  */
1004 static HRESULT WINAPI ZoneMgrImpl_GetZoneAt(IInternetZoneManagerEx2* iface,
1005                                             DWORD dwEnum,
1006                                             DWORD dwIndex,
1007                                             DWORD* pdwZone)
1008 {
1009     ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
1010     LPDWORD data;
1011
1012     TRACE("(%p)->(0x%08x, %d, %p)\n", This, dwEnum, dwIndex, pdwZone);
1013
1014     /* make sure, that dwEnum and dwIndex are in the valid range */
1015     if (dwEnum < This->zonemap_count) {
1016         if ((data = This->zonemaps[dwEnum])) {
1017             if (dwIndex < data[0]) {
1018                 *pdwZone = data[dwIndex + 1];
1019                 return S_OK;
1020             }
1021         }
1022     }
1023     return E_INVALIDARG;
1024 }
1025
1026 /********************************************************************
1027  *      IInternetZoneManager_DestroyZoneEnumerator
1028  */
1029 static HRESULT WINAPI ZoneMgrImpl_DestroyZoneEnumerator(IInternetZoneManagerEx2* iface,
1030                                                         DWORD dwEnum)
1031 {
1032     ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
1033     LPDWORD data;
1034
1035     TRACE("(%p)->(0x%08x)\n", This, dwEnum);
1036     /* make sure, that dwEnum is valid */
1037     if (dwEnum < This->zonemap_count) {
1038         if ((data = This->zonemaps[dwEnum])) {
1039             This->zonemaps[dwEnum] = NULL;
1040             heap_free(data);
1041             return S_OK;
1042         }
1043     }
1044     return E_INVALIDARG;
1045 }
1046
1047 /********************************************************************
1048  *      IInternetZoneManager_CopyTemplatePoliciesToZone
1049  */
1050 static HRESULT WINAPI ZoneMgrImpl_CopyTemplatePoliciesToZone(IInternetZoneManagerEx2* iface,
1051                                                              DWORD dwTemplate,
1052                                                              DWORD dwZone,
1053                                                              DWORD dwReserved)
1054 {
1055     FIXME("(%p)->(%08x %08x %08x) stub\n", iface, dwTemplate, dwZone, dwReserved);
1056     return E_NOTIMPL;
1057 }
1058
1059 /********************************************************************
1060  *      IInternetZoneManagerEx_GetZoneActionPolicyEx
1061  */
1062 static HRESULT WINAPI ZoneMgrImpl_GetZoneActionPolicyEx(IInternetZoneManagerEx2* iface,
1063                                                         DWORD dwZone,
1064                                                         DWORD dwAction,
1065                                                         BYTE* pPolicy,
1066                                                         DWORD cbPolicy,
1067                                                         URLZONEREG urlZoneReg,
1068                                                         DWORD dwFlags)
1069 {
1070     TRACE("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x)\n", iface, dwZone,
1071             dwAction, pPolicy, cbPolicy, urlZoneReg, dwFlags);
1072
1073     if(!pPolicy)
1074         return E_INVALIDARG;
1075
1076     if (dwFlags)
1077         FIXME("dwFlags 0x%x ignored\n", dwFlags);
1078
1079     return get_action_policy(dwZone, dwAction, pPolicy, cbPolicy, urlZoneReg);
1080 }
1081
1082 /********************************************************************
1083  *      IInternetZoneManagerEx_SetZoneActionPolicyEx
1084  */
1085 static HRESULT WINAPI ZoneMgrImpl_SetZoneActionPolicyEx(IInternetZoneManagerEx2* iface,
1086                                                         DWORD dwZone,
1087                                                         DWORD dwAction,
1088                                                         BYTE* pPolicy,
1089                                                         DWORD cbPolicy,
1090                                                         URLZONEREG urlZoneReg,
1091                                                         DWORD dwFlags)
1092 {
1093     FIXME("(%p)->(%d, 0x%x, %p, %d, %d, 0x%x) stub\n", iface, dwZone, dwAction, pPolicy,
1094                                                        cbPolicy, urlZoneReg, dwFlags);
1095     return E_NOTIMPL;
1096 }
1097
1098 /********************************************************************
1099  *      IInternetZoneManagerEx2_GetZoneAttributesEx
1100  */
1101 static HRESULT WINAPI ZoneMgrImpl_GetZoneAttributesEx(IInternetZoneManagerEx2* iface,
1102                                                       DWORD dwZone,
1103                                                       ZONEATTRIBUTES* pZoneAttributes,
1104                                                       DWORD dwFlags)
1105 {
1106     TRACE("(%p)->(%d, %p, 0x%x)\n", iface, dwZone, pZoneAttributes, dwFlags);
1107
1108     if (dwFlags)
1109         FIXME("dwFlags 0x%x ignored\n", dwFlags);
1110
1111     return IInternetZoneManager_GetZoneAttributes(iface, dwZone, pZoneAttributes);
1112 }
1113
1114
1115 /********************************************************************
1116  *      IInternetZoneManagerEx2_GetZoneSecurityState
1117  */
1118 static HRESULT WINAPI ZoneMgrImpl_GetZoneSecurityState(IInternetZoneManagerEx2* iface,
1119                                                        DWORD dwZoneIndex,
1120                                                        BOOL fRespectPolicy,
1121                                                        LPDWORD pdwState,
1122                                                        BOOL *pfPolicyEncountered)
1123 {
1124     FIXME("(%p)->(%d, %d, %p, %p) stub\n", iface, dwZoneIndex, fRespectPolicy,
1125                                            pdwState, pfPolicyEncountered);
1126
1127     *pdwState = SECURITY_IE_STATE_GREEN;
1128
1129     if (pfPolicyEncountered)
1130         *pfPolicyEncountered = FALSE;
1131
1132     return S_OK;
1133 }
1134
1135 /********************************************************************
1136  *      IInternetZoneManagerEx2_GetIESecurityState
1137  */
1138 static HRESULT WINAPI ZoneMgrImpl_GetIESecurityState(IInternetZoneManagerEx2* iface,
1139                                                      BOOL fRespectPolicy,
1140                                                      LPDWORD pdwState,
1141                                                      BOOL *pfPolicyEncountered,
1142                                                      BOOL fNoCache)
1143 {
1144     FIXME("(%p)->(%d, %p, %p, %d) stub\n", iface, fRespectPolicy, pdwState,
1145                                            pfPolicyEncountered, fNoCache);
1146
1147     *pdwState = SECURITY_IE_STATE_GREEN;
1148
1149     if (pfPolicyEncountered)
1150         *pfPolicyEncountered = FALSE;
1151
1152     return S_OK;
1153 }
1154
1155 /********************************************************************
1156  *      IInternetZoneManagerEx2_FixInsecureSettings
1157  */
1158 static HRESULT WINAPI ZoneMgrImpl_FixInsecureSettings(IInternetZoneManagerEx2* iface)
1159 {
1160     FIXME("(%p) stub\n", iface);
1161     return S_OK;
1162 }
1163
1164 /********************************************************************
1165  *      IInternetZoneManager_Construct
1166  */
1167 static const IInternetZoneManagerEx2Vtbl ZoneMgrImplVtbl = {
1168     ZoneMgrImpl_QueryInterface,
1169     ZoneMgrImpl_AddRef,
1170     ZoneMgrImpl_Release,
1171     /* IInternetZoneManager */
1172     ZoneMgrImpl_GetZoneAttributes,
1173     ZoneMgrImpl_SetZoneAttributes,
1174     ZoneMgrImpl_GetZoneCustomPolicy,
1175     ZoneMgrImpl_SetZoneCustomPolicy,
1176     ZoneMgrImpl_GetZoneActionPolicy,
1177     ZoneMgrImpl_SetZoneActionPolicy,
1178     ZoneMgrImpl_PromptAction,
1179     ZoneMgrImpl_LogAction,
1180     ZoneMgrImpl_CreateZoneEnumerator,
1181     ZoneMgrImpl_GetZoneAt,
1182     ZoneMgrImpl_DestroyZoneEnumerator,
1183     ZoneMgrImpl_CopyTemplatePoliciesToZone,
1184     /* IInternetZoneManagerEx */
1185     ZoneMgrImpl_GetZoneActionPolicyEx,
1186     ZoneMgrImpl_SetZoneActionPolicyEx,
1187     /* IInternetZoneManagerEx2 */
1188     ZoneMgrImpl_GetZoneAttributesEx,
1189     ZoneMgrImpl_GetZoneSecurityState,
1190     ZoneMgrImpl_GetIESecurityState,
1191     ZoneMgrImpl_FixInsecureSettings,
1192 };
1193
1194 HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
1195 {
1196     ZoneMgrImpl* ret = heap_alloc_zero(sizeof(ZoneMgrImpl));
1197
1198     TRACE("(%p %p)\n", pUnkOuter, ppobj);
1199     ret->lpVtbl = &ZoneMgrImplVtbl;
1200     ret->ref = 1;
1201     *ppobj = (IInternetZoneManagerEx*)ret;
1202
1203     URLMON_LockModule();
1204
1205     return S_OK;
1206 }
1207
1208 /***********************************************************************
1209  *           CoInternetCreateSecurityManager (URLMON.@)
1210  *
1211  */
1212 HRESULT WINAPI CoInternetCreateSecurityManager( IServiceProvider *pSP,
1213     IInternetSecurityManager **ppSM, DWORD dwReserved )
1214 {
1215     TRACE("%p %p %d\n", pSP, ppSM, dwReserved );
1216
1217     if(pSP)
1218         FIXME("pSP not supported\n");
1219
1220     return SecManagerImpl_Construct(NULL, (void**) ppSM);
1221 }
1222
1223 /********************************************************************
1224  *      CoInternetCreateZoneManager (URLMON.@)
1225  */
1226 HRESULT WINAPI CoInternetCreateZoneManager(IServiceProvider* pSP, IInternetZoneManager** ppZM, DWORD dwReserved)
1227 {
1228     TRACE("(%p %p %x)\n", pSP, ppZM, dwReserved);
1229     return ZoneMgrImpl_Construct(NULL, (void**)ppZM);
1230 }