Changeset 49722 in vbox for trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.cpp
- Timestamp:
- Nov 29, 2013 11:23:41 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.cpp
r46385 r49722 124 124 * @param fCopy Whether to just assign or copy the actual buffer 125 125 * contents from source -> dest. 126 * @todo r=bird: It appears that fCopy == true is never used, which is127 * fortunate as it (a) doesn't check for there being room in the128 * buffer, (b) terminate the string (which is customary, even if not129 * strictly necessary), and (c) overwrites MaximumLength.130 126 */ 131 127 HRESULT … … 136 132 137 133 size_t cbLen = RTUtf16Len(pwszSource) * sizeof(RTUTF16); 138 AssertReturn(cbLen >= USHORT_MAX, E_INVALIDARG); 139 140 pUnicodeDest->Length = (USHORT)cbLen; 141 pUnicodeDest->MaximumLength = (USHORT)cbLen; 134 AssertReturn(cbLen <= USHORT_MAX, E_INVALIDARG); 135 136 HRESULT hr; 142 137 143 138 if (fCopy) 144 139 { 145 AssertFailed(/*see todo*/); 146 memcpy(pUnicodeDest->Buffer, pwszSource, cbLen); 140 if (cbLen <= pUnicodeDest->MaximumLength) 141 { 142 memcpy(pUnicodeDest->Buffer, pwszSource, cbLen); 143 pUnicodeDest->Length = (USHORT)cbLen; 144 hr = S_OK; 145 } 146 else 147 hr = E_INVALIDARG; 147 148 } 148 149 else /* Just assign the buffer. */ 149 pUnicodeDest->Buffer = pwszSource; 150 151 return S_OK; 150 { 151 pUnicodeDest->Buffer = pwszSource; 152 pUnicodeDest->Length = (USHORT)cbLen; 153 hr = S_OK; 154 } 155 156 return hr; 152 157 } 153 158 … … 893 898 } 894 899 900 /* Fill in the username and password. */ 895 901 if (SUCCEEDED(hr)) 896 902 { 897 /* Fill in the username and password. */ 903 hr = RTUTF16ToUnicode(&pKerberosLogon->UserName, 904 m_apwszCredentials[VBOXCREDPROV_FIELDID_USERNAME], 905 false /* Just assign, no copy */); 898 906 if (SUCCEEDED(hr)) 899 907 { 900 hr = RTUTF16ToUnicode(&pKerberosLogon-> UserName,901 m_apwszCredentials[VBOXCREDPROV_FIELDID_ USERNAME],908 hr = RTUTF16ToUnicode(&pKerberosLogon->Password, 909 m_apwszCredentials[VBOXCREDPROV_FIELDID_PASSWORD], 902 910 false /* Just assign, no copy */); 903 911 if (SUCCEEDED(hr)) 904 912 { 905 hr = RTUTF16ToUnicode(&pKerberosLogon->Password, 906 m_apwszCredentials[VBOXCREDPROV_FIELDID_PASSWORD], 907 false /* Just assign, no copy */); 913 /* Set credential type according to current usage scenario. */ 914 AssertPtr(pKerberosLogon); 915 switch (m_enmUsageScenario) 916 { 917 case CPUS_UNLOCK_WORKSTATION: 918 pKerberosLogon->MessageType = KerbWorkstationUnlockLogon; 919 break; 920 921 case CPUS_LOGON: 922 pKerberosLogon->MessageType = KerbInteractiveLogon; 923 break; 924 925 case CPUS_CREDUI: 926 pKerberosLogon->MessageType = (KERB_LOGON_SUBMIT_TYPE)0; /* No message type required here. */ 927 break; 928 929 default: 930 hr = E_FAIL; 931 break; 932 } 933 934 if (FAILED(hr)) 935 VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSerialization: Unknown usage scenario=%ld\n", m_enmUsageScenario); 936 937 if (SUCCEEDED(hr)) /* Build the logon package. */ 938 { 939 hr = AllocateLogonPackage(KerberosUnlockLogon, 940 &pcpCredentialSerialization->rgbSerialization, 941 &pcpCredentialSerialization->cbSerialization); 942 if (FAILED(hr)) 943 VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSerialization: Failed to allocate logon package, hr=0x%08x\n", hr); 944 } 945 908 946 if (SUCCEEDED(hr)) 909 947 { 910 /* Set credential type according to current usage scenario. */ 911 AssertPtr(pKerberosLogon); 912 switch (m_enmUsageScenario) 948 ULONG ulAuthPackage; 949 950 HANDLE hLsa; 951 NTSTATUS s = LsaConnectUntrusted(&hLsa); 952 if (SUCCEEDED(HRESULT_FROM_NT(s))) 913 953 { 914 case CPUS_UNLOCK_WORKSTATION: 915 pKerberosLogon->MessageType = KerbWorkstationUnlockLogon; 916 break; 917 918 case CPUS_LOGON: 919 pKerberosLogon->MessageType = KerbInteractiveLogon; 920 break; 921 922 case CPUS_CREDUI: 923 pKerberosLogon->MessageType = (KERB_LOGON_SUBMIT_TYPE)0; /* No message type required here. */ 924 break; 925 926 default: 927 hr = E_FAIL; 928 break; 954 LSA_STRING lsaszKerberosName; 955 size_t cchKerberosName; 956 hr = StringCchLengthA(NEGOSSP_NAME_A, USHORT_MAX, &cchKerberosName); 957 if (SUCCEEDED(hr)) 958 { 959 USHORT usLength; 960 hr = SizeTToUShort(cchKerberosName, &usLength); 961 if (SUCCEEDED(hr)) 962 { 963 lsaszKerberosName.Buffer = (PCHAR)NEGOSSP_NAME_A; 964 lsaszKerberosName.Length = usLength; 965 lsaszKerberosName.MaximumLength = lsaszKerberosName.Length + 1; 966 967 } 968 } 969 970 if (SUCCEEDED(hr)) 971 { 972 s = LsaLookupAuthenticationPackage(hLsa, &lsaszKerberosName, 973 &ulAuthPackage); 974 if (FAILED(HRESULT_FROM_NT(s))) 975 { 976 hr = HRESULT_FROM_NT(s); 977 VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSerialization: Failed looking up authentication package, hr=0x%08x\n", hr); 978 } 979 } 980 981 LsaDeregisterLogonProcess(hLsa); 929 982 } 930 931 if (SUCCEEDED(hr)) /* Build the logon package. */932 hr = AllocateLogonPackage(KerberosUnlockLogon,933 &pcpCredentialSerialization->rgbSerialization,934 &pcpCredentialSerialization->cbSerialization);935 983 936 984 if (SUCCEEDED(hr)) 937 985 { 938 ULONG ulAuthPackage; 939 940 HANDLE hLsa; 941 NTSTATUS s = LsaConnectUntrusted(&hLsa); 942 if (SUCCEEDED(HRESULT_FROM_NT(s))) 943 { 944 LSA_STRING lsaszKerberosName; 945 size_t cchKerberosName; 946 hr = StringCchLengthA(NEGOSSP_NAME_A, USHORT_MAX, &cchKerberosName); 947 if (SUCCEEDED(hr)) 948 { 949 USHORT usLength; 950 hr = SizeTToUShort(cchKerberosName, &usLength); 951 if (SUCCEEDED(hr)) 952 { 953 lsaszKerberosName.Buffer = (PCHAR)NEGOSSP_NAME_A; 954 lsaszKerberosName.Length = usLength; 955 lsaszKerberosName.MaximumLength = lsaszKerberosName.Length + 1; 956 957 } 958 } 959 960 if (SUCCEEDED(hr)) 961 { 962 s = LsaLookupAuthenticationPackage(hLsa, &lsaszKerberosName, 963 &ulAuthPackage); 964 if (FAILED(HRESULT_FROM_NT(s))) 965 hr = HRESULT_FROM_NT(s); 966 } 967 968 LsaDeregisterLogonProcess(hLsa); 969 } 970 971 if (SUCCEEDED(hr)) 972 { 973 pcpCredentialSerialization->ulAuthenticationPackage = ulAuthPackage; 974 pcpCredentialSerialization->clsidCredentialProvider = CLSID_VBoxCredProvider; 975 976 /* We're done -- let the logon UI know. */ 977 *pcpGetSerializationResponse = CPGSR_RETURN_CREDENTIAL_FINISHED; 978 } 986 pcpCredentialSerialization->ulAuthenticationPackage = ulAuthPackage; 987 pcpCredentialSerialization->clsidCredentialProvider = CLSID_VBoxCredProvider; 988 989 /* We're done -- let the logon UI know. */ 990 *pcpGetSerializationResponse = CPGSR_RETURN_CREDENTIAL_FINISHED; 979 991 } 980 992 } 981 993 } 982 } 994 else 995 VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSerialization: Error copying password, hr=0x%08x\n", hr); 996 } 997 else 998 VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetSerialization: Error copying user name, hr=0x%08x\n", hr); 983 999 } 984 1000
Note:
See TracChangeset
for help on using the changeset viewer.