~ubuntu-branches/ubuntu/precise/wine1.3/precise

« back to all changes in this revision

Viewing changes to dlls/urlmon/sec_mgr.c

  • Committer: Package Import Robot
  • Author(s): Scott Ritchie
  • Date: 2012-01-17 09:00:34 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120117090034-eyhpp02jawlvrrkc
Tags: 1.3.37-0ubuntu1
* New upstream release
  - Many changes
* Convert to 3.0 source format
* debian/control:
  - Remove pre-multiarch amd64 build depends
  - Remove quilt build depends
  - Recommend proper gecko versions
* debian/rules:
  - Remove manual dh_quilt patch and unpatch
  - No need to uuencode/uudecode anymore with new source format

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
    return isalphaW(*path) && *(path+1) == ':';
63
63
}
64
64
 
 
65
/* List of schemes types Windows seems to expect to be hierarchical. */
 
66
static inline BOOL is_hierarchical_scheme(URL_SCHEME type) {
 
67
    return(type == URL_SCHEME_HTTP || type == URL_SCHEME_FTP ||
 
68
           type == URL_SCHEME_GOPHER || type == URL_SCHEME_NNTP ||
 
69
           type == URL_SCHEME_TELNET || type == URL_SCHEME_WAIS ||
 
70
           type == URL_SCHEME_FILE || type == URL_SCHEME_HTTPS ||
 
71
           type == URL_SCHEME_RES);
 
72
}
 
73
 
65
74
/********************************************************************
66
75
 * get_string_from_reg [internal]
67
76
 *
466
475
    if(FAILED(hres))
467
476
        return hres;
468
477
 
 
478
    /* Known hierarchical scheme types must have a host. If they don't Windows
 
479
     * assigns URLZONE_INVALID to the zone.
 
480
     */
 
481
    if((scheme_type != URL_SCHEME_UNKNOWN && scheme_type != URL_SCHEME_FILE)
 
482
        && is_hierarchical_scheme(scheme_type) && !*host) {
 
483
        *zone = URLZONE_INVALID;
 
484
 
 
485
        SysFreeString(host);
 
486
 
 
487
        /* The MapUrlToZone functions return S_OK when this condition occurs. */
 
488
        return S_OK;
 
489
    }
 
490
 
469
491
    hres = IUri_GetSchemeName(uri, &scheme);
470
492
    if(FAILED(hres)) {
471
493
        SysFreeString(host);
521
543
        else
522
544
            path_start = path;
523
545
 
524
 
        if(((ptr = strchrW(path_start, '\\')) || (ptr = strchrW(path_start, '/'))) && ptr-path_start < sizeof(root)/sizeof(WCHAR)) {
 
546
        if((ptr = strchrW(path_start, ':')) && ptr-path_start+1 < sizeof(root)/sizeof(WCHAR)) {
525
547
            UINT type;
526
548
 
527
 
            memcpy(root, path_start, (ptr-path_start)*sizeof(WCHAR));
528
 
            root[ptr-path_start] = 0;
 
549
            memcpy(root, path_start, (ptr-path_start+1)*sizeof(WCHAR));
 
550
            root[ptr-path_start+1] = 0;
529
551
 
530
552
            type = GetDriveTypeW(root);
531
553
 
597
619
    return hres;
598
620
}
599
621
 
600
 
static HRESULT map_uri_to_zone(IUri *uri, DWORD *zone)
 
622
static HRESULT map_uri_to_zone(IUri *uri, DWORD *zone, IUri **ret_uri)
601
623
{
602
624
    HRESULT hres;
603
625
    IUri *secur_uri;
607
629
        return hres;
608
630
 
609
631
    hres = map_security_uri_to_zone(secur_uri, zone);
610
 
    IUri_Release(secur_uri);
 
632
    if(FAILED(hres) || !ret_uri)
 
633
        IUri_Release(secur_uri);
 
634
    else
 
635
        *ret_uri = secur_uri;
611
636
 
612
637
    return hres;
613
638
}
686
711
    return hres;
687
712
}
688
713
 
689
 
static HRESULT get_security_id(LPCWSTR url, BYTE *secid, DWORD *secid_len)
690
 
{
691
 
    LPWSTR secur_url, ptr, ptr2;
692
 
    DWORD zone, len;
693
 
    HRESULT hres;
694
 
 
695
 
    static const WCHAR wszFile[] = {'f','i','l','e',':'};
 
714
static HRESULT generate_security_id(IUri *uri, BYTE *secid, DWORD *secid_len, DWORD zone)
 
715
{
 
716
    DWORD len;
 
717
    HRESULT hres;
 
718
    DWORD scheme_type;
 
719
 
 
720
    if(zone == URLZONE_INVALID)
 
721
        return E_INVALIDARG;
 
722
 
 
723
    hres = IUri_GetScheme(uri, &scheme_type);
 
724
    if(FAILED(hres))
 
725
        return hres;
 
726
 
 
727
    /* Windows handles opaque URLs differently then hierarchical ones. */
 
728
    if(!is_hierarchical_scheme(scheme_type) && scheme_type != URL_SCHEME_WILDCARD) {
 
729
        BSTR display_uri;
 
730
 
 
731
        hres = IUri_GetDisplayUri(uri, &display_uri);
 
732
        if(FAILED(hres))
 
733
            return hres;
 
734
 
 
735
        len = WideCharToMultiByte(CP_ACP, 0, display_uri, -1, NULL, 0, NULL, NULL)-1;
 
736
 
 
737
        if(len+sizeof(DWORD) > *secid_len) {
 
738
            SysFreeString(display_uri);
 
739
            return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
 
740
        }
 
741
 
 
742
        WideCharToMultiByte(CP_ACP, 0, display_uri, -1, (LPSTR)secid, len, NULL, NULL);
 
743
        SysFreeString(display_uri);
 
744
 
 
745
        *(DWORD*)(secid+len) = zone;
 
746
    } else {
 
747
        BSTR host, scheme;
 
748
        DWORD host_len, scheme_len;
 
749
        BYTE *ptr;
 
750
 
 
751
        hres = IUri_GetHost(uri, &host);
 
752
        if(FAILED(hres))
 
753
            return hres;
 
754
 
 
755
        /* The host can't be empty for Wildcard URIs. */
 
756
        if(scheme_type == URL_SCHEME_WILDCARD && !*host) {
 
757
            SysFreeString(host);
 
758
            return E_INVALIDARG;
 
759
        }
 
760
 
 
761
        hres = IUri_GetSchemeName(uri, &scheme);
 
762
        if(FAILED(hres)) {
 
763
            SysFreeString(host);
 
764
            return hres;
 
765
        }
 
766
 
 
767
        host_len = WideCharToMultiByte(CP_ACP, 0, host, -1, NULL, 0, NULL, NULL)-1;
 
768
        scheme_len = WideCharToMultiByte(CP_ACP, 0, scheme, -1, NULL, 0, NULL, NULL)-1;
 
769
 
 
770
        len = host_len+scheme_len+sizeof(BYTE);
 
771
 
 
772
        if(len+sizeof(DWORD) > *secid_len) {
 
773
            SysFreeString(host);
 
774
            SysFreeString(scheme);
 
775
            return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
 
776
        }
 
777
 
 
778
        WideCharToMultiByte(CP_ACP, 0, scheme, -1, (LPSTR)secid, len, NULL, NULL);
 
779
        SysFreeString(scheme);
 
780
 
 
781
        ptr = secid+scheme_len;
 
782
        *ptr++ = ':';
 
783
 
 
784
        WideCharToMultiByte(CP_ACP, 0, host, -1, (LPSTR)ptr, host_len, NULL, NULL);
 
785
        SysFreeString(host);
 
786
 
 
787
        ptr += host_len;
 
788
 
 
789
        *(DWORD*)ptr = zone;
 
790
    }
 
791
 
 
792
    *secid_len = len+sizeof(DWORD);
 
793
 
 
794
    return S_OK;
 
795
}
 
796
 
 
797
static HRESULT get_security_id_for_url(LPCWSTR url, BYTE *secid, DWORD *secid_len)
 
798
{
 
799
    HRESULT hres;
 
800
    DWORD zone = URLZONE_INVALID;
 
801
    LPWSTR secur_url = NULL;
 
802
    IUri *uri;
696
803
 
697
804
    hres = map_url_to_zone(url, &zone, &secur_url);
698
805
    if(FAILED(hres))
699
806
        return hres == 0x80041001 ? E_INVALIDARG : hres;
700
807
 
701
 
    /* file protocol is a special case */
702
 
    if(strlenW(secur_url) >= sizeof(wszFile)/sizeof(WCHAR)
703
 
            && !memcmp(secur_url, wszFile, sizeof(wszFile))) {
704
 
        WCHAR path[MAX_PATH];
705
 
        len = sizeof(path)/sizeof(WCHAR);
706
 
 
707
 
        hres = CoInternetParseUrl(secur_url, PARSE_PATH_FROM_URL, 0, path, len, &len, 0);
708
 
        if(hres == S_OK && !PathIsNetworkPathW(path)) {
709
 
            static const BYTE secidFile[] = {'f','i','l','e',':'};
710
 
 
711
 
            CoTaskMemFree(secur_url);
712
 
 
713
 
            if(*secid_len < sizeof(secidFile)+sizeof(zone))
714
 
                return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
715
 
 
716
 
            memcpy(secid, secidFile, sizeof(secidFile));
717
 
            *(DWORD*)(secid+sizeof(secidFile)) = zone;
718
 
 
719
 
            *secid_len = sizeof(secidFile)+sizeof(zone);
720
 
            return S_OK;
721
 
        }
722
 
    }
723
 
 
724
 
    ptr = strchrW(secur_url, ':');
725
 
    ptr2 = ++ptr;
726
 
    while(*ptr2 == '/')
727
 
        ptr2++;
728
 
    if(ptr2 != ptr)
729
 
        memmove(ptr, ptr2, (strlenW(ptr2)+1)*sizeof(WCHAR));
730
 
 
731
 
    ptr = strchrW(ptr, '/');
732
 
    if(ptr)
733
 
        *ptr = 0;
734
 
 
735
 
    len = WideCharToMultiByte(CP_ACP, 0, secur_url, -1, NULL, 0, NULL, NULL)-1;
736
 
 
737
 
    if(len+sizeof(DWORD) > *secid_len) {
738
 
        CoTaskMemFree(secur_url);
739
 
        return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
740
 
    }
741
 
 
742
 
    WideCharToMultiByte(CP_ACP, 0, secur_url, -1, (LPSTR)secid, len, NULL, NULL);
 
808
    hres = CreateUri(secur_url, 0, 0, &uri);
743
809
    CoTaskMemFree(secur_url);
744
 
 
745
 
    *(DWORD*)(secid+len) = zone;
746
 
 
747
 
    *secid_len = len+sizeof(DWORD);
748
 
 
749
 
    return S_OK;
 
810
    if(FAILED(hres))
 
811
        return hres;
 
812
 
 
813
    hres = generate_security_id(uri, secid, secid_len, zone);
 
814
    IUri_Release(uri);
 
815
 
 
816
    return hres;
 
817
}
 
818
 
 
819
static HRESULT get_security_id_for_uri(IUri *uri, BYTE *secid, DWORD *secid_len)
 
820
{
 
821
    HRESULT hres;
 
822
    IUri *secur_uri;
 
823
    DWORD zone = URLZONE_INVALID;
 
824
 
 
825
    hres = map_uri_to_zone(uri, &zone, &secur_uri);
 
826
    if(FAILED(hres))
 
827
        return hres;
 
828
 
 
829
    hres = generate_security_id(secur_uri, secid, secid_len, zone);
 
830
    IUri_Release(secur_uri);
 
831
 
 
832
    return hres;
750
833
}
751
834
 
752
835
/***********************************************************************
933
1016
    if(dwReserved)
934
1017
        FIXME("dwReserved is not supported\n");
935
1018
 
936
 
    return get_security_id(pwszUrl, pbSecurityId, pcbSecurityId);
 
1019
    return get_security_id_for_url(pwszUrl, pbSecurityId, pcbSecurityId);
937
1020
}
938
1021
 
939
1022
 
1070
1153
 
1071
1154
    TRACE("(%p)->(%p %p %08x %p %p)\n", This, pUri, pdwZone, dwFlags, ppwszMappedUrl, pdwOutFlags);
1072
1155
 
 
1156
    if(This->custom_manager) {
 
1157
        HRESULT hres;
 
1158
        IInternetSecurityManagerEx2 *sec_mgr2;
 
1159
 
 
1160
        hres = IInternetSecurityManager_QueryInterface(This->custom_manager, &IID_IInternetSecurityManagerEx2,
 
1161
                (void**)&sec_mgr2);
 
1162
        if(SUCCEEDED(hres)) {
 
1163
            hres = IInternetSecurityManagerEx2_MapUrlToZoneEx2(sec_mgr2, pUri, pdwZone, dwFlags, ppwszMappedUrl, pdwOutFlags);
 
1164
            IInternetSecurityManagerEx2_Release(sec_mgr2);
 
1165
        } else {
 
1166
            BSTR url;
 
1167
 
 
1168
            hres = IUri_GetDisplayUri(pUri, &url);
 
1169
            if(FAILED(hres))
 
1170
                return hres;
 
1171
 
 
1172
            hres = IInternetSecurityManager_MapUrlToZone(This->custom_manager, url, pdwZone, dwFlags);
 
1173
            SysFreeString(url);
 
1174
        }
 
1175
 
 
1176
        if(hres != INET_E_DEFAULT_ACTION)
 
1177
            return hres;
 
1178
    }
 
1179
 
1073
1180
    if(!pdwZone)
1074
1181
        return E_INVALIDARG;
1075
1182
 
1081
1188
    if(dwFlags)
1082
1189
        FIXME("Unsupported flags: %08x\n", dwFlags);
1083
1190
 
1084
 
    return map_uri_to_zone(pUri, pdwZone);
 
1191
    return map_uri_to_zone(pUri, pdwZone, NULL);
1085
1192
}
1086
1193
 
1087
1194
static HRESULT WINAPI SecManagerImpl_ProcessUrlActionEx2(IInternetSecurityManagerEx2 *iface,
1098
1205
        IUri *pUri, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
1099
1206
{
1100
1207
    SecManagerImpl *This = impl_from_IInternetSecurityManagerEx2(iface);
1101
 
    FIXME("(%p)->(%p %p %p %08x) stub\n", This, pUri, pbSecurityId, pcbSecurityId, (DWORD)dwReserved);
1102
 
    return E_NOTIMPL;
 
1208
    TRACE("(%p)->(%p %p %p %08x) stub\n", This, pUri, pbSecurityId, pcbSecurityId, (DWORD)dwReserved);
 
1209
 
 
1210
    if(dwReserved)
 
1211
        FIXME("dwReserved is not supported yet\n");
 
1212
 
 
1213
    if(!pUri || !pcbSecurityId || !pbSecurityId)
 
1214
        return E_INVALIDARG;
 
1215
 
 
1216
    return get_security_id_for_uri(pUri, pbSecurityId, pcbSecurityId);
1103
1217
}
1104
1218
 
1105
1219
static HRESULT WINAPI SecManagerImpl_QueryCustomPolicyEx2(IInternetSecurityManagerEx2 *iface,
1952
2066
    CoTaskMemFree(ret_url);
1953
2067
    return hres;
1954
2068
}
 
2069
 
 
2070
/********************************************************************
 
2071
 *      CompareSecurityIds (URLMON.@)
 
2072
 */
 
2073
HRESULT WINAPI CompareSecurityIds(BYTE *secid1, DWORD size1, BYTE *secid2, DWORD size2, DWORD reserved)
 
2074
{
 
2075
    FIXME("(%p %d %p %d %x)\n", secid1, size1, secid2, size2, reserved);
 
2076
    return E_NOTIMPL;
 
2077
}