VirtualBox

Changeset 95890 in vbox


Ignore:
Timestamp:
Jul 28, 2022 1:49:20 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
152621
Message:

Add/Nt/VBoxCredProv: Make it compile in VBOX_WITH_NOCRT_STATIC mode. bugref:10261

Location:
trunk/src/VBox/Additions/WINNT/VBoxCredProv
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.cpp

    r93115 r95890  
    547547             */
    548548            PWSTR pwszExtractedDomain = NULL;
    549             if (ExtractAccoutData(pwszUser, &pwszExtractedName, &pwszExtractedDomain))
     549            if (ExtractAccountData(pwszUser, &pwszExtractedName, &pwszExtractedDomain))
    550550            {
    551551                /* Update user name. */
     
    842842 * This might be a principal or FQDN string.
    843843 *
    844  * @return  TRUE if extraction of the account name was successful, FALSE if not.
    845  * @param   pwszAccountData         (Raw) account data string to extract data from.
    846  * @param   ppwszAccoutName         Where to store the extracted account name on success.
    847  *                                  Needs to be free'd with CoTaskMemFree().
    848  * @param   ppwszDomain             Where to store the extracted domain name on success.
    849  *                                  Needs to be free'd with CoTaskMemFree().
    850  */
    851 BOOL VBoxCredProvCredential::ExtractAccoutData(PWSTR pwszAccountData, PWSTR *ppwszAccoutName, PWSTR *ppwszDomain)
     844 * @return  success indicator. Will fail if input not in a user@domain format.
     845 * @param   pwszAccountData     Raw account data string to extract data from.
     846 * @param   ppwszAccountName    Where to store the extracted account name on
     847 *                              success. Needs to be freed with CoTaskMemFree().
     848 * @param   ppwszDomain         Where to store the extracted domain name on
     849 *                              success. Needs to be freed with CoTaskMemFree().
     850 */
     851/*static*/ bool VBoxCredProvCredential::ExtractAccountData(PWSTR pwszAccountData, PWSTR *ppwszAccountName, PWSTR *ppwszDomain)
    852852{
    853853    AssertPtrReturn(pwszAccountData, FALSE);
    854854    VBoxCredProvVerbose(0, "VBoxCredProvCredential::ExtractAccoutData: Getting account name for \"%ls\" ...\n",
    855855                        pwszAccountData);
    856     HRESULT hr = E_FAIL;
     856
     857/** @todo  r=bird: The original code seemed a little confused about whether
     858 *         the domain stuff was optional or not, as it declared pwszDomain
     859 *         very early and freed it in the error path.  Not entirely sure what
     860 *         to make of that... */
    857861
    858862    /* Try to figure out whether this is a principal name (user@domain). */
    859     LPWSTR pPos = NULL;
    860     if (   (pPos  = StrChrW(pwszAccountData, L'@')) != NULL
    861         &&  pPos != pwszAccountData)
    862     {
    863         size_t cbSize = (pPos - pwszAccountData) * sizeof(WCHAR);
    864         LPWSTR pwszName = (LPWSTR)CoTaskMemAlloc(cbSize + sizeof(WCHAR)); /* Space for terminating zero. */
    865         LPWSTR pwszDomain = NULL;
    866         AssertPtr(pwszName);
    867         hr = StringCbCopyN(pwszName, cbSize + sizeof(WCHAR), pwszAccountData, cbSize);
    868         if (SUCCEEDED(hr))
    869         {
    870             *ppwszAccoutName = pwszName;
    871             pPos++; /* Skip @, point to domain name (if any). */
    872             if (    pPos != NULL
    873                 && *pPos != L'\0')
     863    LPWSTR const pwszAt = StrChrW(pwszAccountData, L'@');
     864    if (pwszAt && pwszAt != pwszAccountData)
     865    {
     866        if (pwszAt[1])
     867        {
     868            size_t cwcUser  = (size_t)(pwszAt - pwszAccountData) + 1;
     869            LPWSTR pwszName = (LPWSTR)CoTaskMemAlloc(cwcUser * sizeof(WCHAR));
     870            if (pwszName)
    874871            {
    875                 hr = SHStrDupW(pPos, &pwszDomain);
    876                 if (SUCCEEDED(hr))
     872                int rc = RTUtf16CopyEx(pwszName, cwcUser, pwszAccountData, cwcUser - 1);
     873                if (RT_SUCCESS(rc))
    877874                {
    878                     *ppwszDomain = pwszDomain;
     875                    LPWSTR pwszDomain = NULL;
     876                    HRESULT hr = SHStrDupW(&pwszAt[1], &pwszDomain);
     877                    if (SUCCEEDED(hr))
     878                    {
     879                        *ppwszAccountName = pwszName;
     880                        *ppwszDomain      = pwszDomain;
     881                        return true;
     882                    }
     883
     884                    VBoxCredProvVerbose(0, "VBoxCredProvCredential::ExtractAccountData: Error copying domain data, hr=%08x\n", hr);
    879885                }
    880886                else
    881                     VBoxCredProvVerbose(0, "VBoxCredProvCredential::ExtractAccoutData: Error copying domain data, hr=%08x\n", hr);
     887                    VBoxCredProvVerbose(0, "VBoxCredProvCredential::ExtractAccountData: Error copying account data, rc=%Rrc\n", rc);
     888                CoTaskMemFree(pwszName);
    882889            }
    883890            else
    884             {
    885                 hr = E_FAIL;
    886                 VBoxCredProvVerbose(0, "VBoxCredProvCredential::ExtractAccoutData: No domain name found!\n");
    887             }
     891                VBoxCredProvVerbose(0, "VBoxCredProvCredential::ExtractAccountData: allocation failure.\n");
    888892        }
    889893        else
    890             VBoxCredProvVerbose(0, "VBoxCredProvCredential::ExtractAccoutData: Error copying account data, hr=%08x\n", hr);
    891 
    892         if (hr != S_OK)
    893         {
    894             CoTaskMemFree(pwszName);
    895             if (pwszDomain)
    896                 CoTaskMemFree(pwszDomain);
    897         }
     894            VBoxCredProvVerbose(0, "VBoxCredProvCredential::ExtractAccountData: No domain name found!\n");
    898895    }
    899896    else
    900         VBoxCredProvVerbose(0, "VBoxCredProvCredential::ExtractAccoutData: No valid principal account name found!\n");
    901 
    902     return (hr == S_OK);
     897        VBoxCredProvVerbose(0, "VBoxCredProvCredential::ExtractAccountData: No valid principal account name found!\n");
     898
     899    return false;
    903900}
    904901
     
    931928            {
    932929                if (   m_apwszFields[dwFieldID]
    933                     && RTUtf16Len(m_apwszFields[dwFieldID]))
    934                 {
     930                    && m_apwszFields[dwFieldID][0])
    935931                    hr = SHStrDupW(m_apwszFields[dwFieldID], &pwszString);
    936                 }
    937932                else /* Fill in an empty value. */
    938933                    hr = SHStrDupW(L"", &pwszString);
     
    955950
    956951    if (ppwszString)
    957     {
    958952        *ppwszString = pwszString;
    959     }
    960953    else if (pwszString)
    961954        CoTaskMemFree(pwszString);
     
    11331126            if (SUCCEEDED(hr))
    11341127            {
    1135                 LSA_STRING lsaszKerberosName;
     1128#if 0 /* eeek. leaving this as an example of how not to handle a string constant. */
    11361129                size_t cchKerberosName;
    11371130                hr = StringCchLengthA(NEGOSSP_NAME_A, USHORT_MAX, &cchKerberosName);
     
    11411134                    hr = SizeTToUShort(cchKerberosName, &usLength);
    11421135                    if (SUCCEEDED(hr))
     1136#endif
    11431137                    {
     1138                        LSA_STRING lsaszKerberosName;
    11441139                        lsaszKerberosName.Buffer        = (PCHAR)NEGOSSP_NAME_A;
    1145                         lsaszKerberosName.Length        = usLength;
    1146                         lsaszKerberosName.MaximumLength = lsaszKerberosName.Length + 1;
     1140                        lsaszKerberosName.Length        = sizeof(NEGOSSP_NAME_A) - 1;
     1141                        lsaszKerberosName.MaximumLength = sizeof(NEGOSSP_NAME_A);
    11471142
    11481143                        ULONG ulAuthPackage = 0;
     
    11661161                            VBoxCredProvVerbose(1, "VBoxCredProvCredential::GetSerialization: LsaLookupAuthenticationPackage failed with ntStatus=%ld\n", s);
    11671162                    }
     1163#if 0
    11681164                }
    1169 
     1165#endif
    11701166                LsaDeregisterLogonProcess(hLSA);
    11711167            }
  • trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvCredential.h

    r93115 r95890  
    2323
    2424
    25 /*******************************************************************************
    26 *   Header Files                                                               *
    27 *******************************************************************************/
    2825#include <iprt/win/windows.h>
    2926#include <NTSecAPI.h>
     
    3128#include <Security.h>
    3229#include <ShlGuid.h>
    33 #include <strsafe.h>
    3430
    3531#include <iprt/win/shlwapi.h>
     
    9692    int RetrieveCredentials(void);
    9793    BOOL TranslateAccountName(PWSTR pwszDisplayName, PWSTR *ppwszAccoutName);
    98     BOOL ExtractAccoutData(PWSTR pwszAccountData, PWSTR *ppwszAccoutName, PWSTR *ppwszDomain);
     94    static bool ExtractAccountData(PWSTR pwszAccountData, PWSTR *ppwszAccountName, PWSTR *ppwszDomain);
    9995
    10096protected:
  • trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvProvider.cpp

    r93115 r95890  
    213213{
    214214    HRESULT hr = S_OK;
    215     DWORD dwErr;
    216215
    217216    VBoxCredProvVerbose(0, "VBoxCredProv::SetUsageScenario: enmUsageScenario=%d, dwFlags=%ld\n",
     
    227226            VBoxCredProvReportStatus(VBoxGuestFacilityStatus_Active);
    228227
    229             dwErr = LoadConfiguration();
     228            DWORD dwErr = LoadConfiguration();
    230229            if (dwErr != ERROR_SUCCESS)
    231230                VBoxCredProvVerbose(0, "VBoxCredProv: Error while loading configuration, error=%ld\n", dwErr);
     
    239238                break;
    240239
     240            hr = S_OK;
    241241            if (!m_pPoller)
    242242            {
    243                 try
     243#ifdef RT_EXCEPTIONS_ENABLED
     244                try { m_pPoller = new VBoxCredProvPoller(); }
     245                catch (std::bad_alloc &) { hr = E_OUTOFMEMORY; }
     246#else
     247                m_pPoller = new VBoxCredProvPoller();
     248                AssertStmt(m_pPoller, hr = E_OUTOFMEMORY);
     249#endif
     250                if (SUCCEEDED(hr))
    244251                {
    245                     m_pPoller = new VBoxCredProvPoller();
    246                     AssertPtr(m_pPoller);
    247252                    int rc = m_pPoller->Initialize(this);
    248253                    if (RT_FAILURE(rc))
    249254                        VBoxCredProvVerbose(0, "VBoxCredProv::SetUsageScenario: Error initializing poller thread, rc=%Rrc\n", rc);
    250                 }
    251                 catch (std::bad_alloc &ex)
    252                 {
    253                     NOREF(ex);
    254                     hr = E_OUTOFMEMORY;
     255/** @todo r=bird: Why is the initialize failure ignored here? */
    255256                }
    256257            }
     
    259260                && !m_pCred)
    260261            {
    261                 try
    262                 {
    263                     m_pCred = new VBoxCredProvCredential();
    264                     AssertPtr(m_pPoller);
     262#ifdef RT_EXCEPTIONS_ENABLED
     263                try { m_pCred = new VBoxCredProvCredential(); }
     264                catch (std::bad_alloc &) { hr = E_OUTOFMEMORY; }
     265#else
     266                m_pCred = new VBoxCredProvCredential();
     267                AssertStmt(m_pCred, hr = E_OUTOFMEMORY);
     268#endif
     269                if (SUCCEEDED(hr))
    265270                    hr = m_pCred->Initialize(m_enmUsageScenario);
    266                 }
    267                 catch (std::bad_alloc &ex)
    268                 {
    269                     NOREF(ex);
    270                     hr = E_OUTOFMEMORY;
    271                 }
    272271            }
    273272            else
     
    277276
    278277            /* If we failed, do some cleanup. */
     278/** @todo r=bird: Why aren't we cleaning up m_pPoller too? Very confusing given
     279 * that m_pCred wasn't necessarily even created above.  Always explain the WHY
     280 * when doing something that isn't logical like here! */
    279281            if (FAILED(hr))
    280282            {
     
    291293        case CPUS_CREDUI:          /* Displays an own UI. We don't need that. */
    292294        case CPUS_PLAP:            /* See Pre-Logon-Access Provider. Not needed (yet). */
    293 
    294295            hr = E_NOTIMPL;
    295296            break;
     
    571572VBoxCredProvProviderCreate(REFIID interfaceID, void **ppvInterface)
    572573{
    573     HRESULT hr;
    574 
    575     try
    576     {
    577         VBoxCredProvProvider *pProvider = new VBoxCredProvProvider();
    578         AssertPtr(pProvider);
    579         hr = pProvider->QueryInterface(interfaceID, ppvInterface);
    580         pProvider->Release();
    581     }
    582     catch (std::bad_alloc &ex)
    583     {
    584         NOREF(ex);
    585         hr = E_OUTOFMEMORY;
    586     }
     574    VBoxCredProvProvider *pProvider;
     575#ifdef RT_EXCEPTIONS_ENABLED
     576    try { pProvider = new VBoxCredProvProvider(); }
     577    catch (std::bad_alloc &) { AssertFailedReturn(E_OUTOFMEMORY); }
     578#else
     579    pProvider = new VBoxCredProvProvider();
     580    AssertReturn(pProvider, E_OUTOFMEMORY);
     581#endif
     582
     583    HRESULT hr = pProvider->QueryInterface(interfaceID, ppvInterface);
     584    pProvider->Release();
    587585
    588586    return hr;
  • trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvProvider.h

    r93115 r95890  
    2424#include <iprt/win/credentialprovider.h>
    2525#include <iprt/win/windows.h>
    26 #include <strsafe.h>
    2726
    2827#include <VBox/VBoxGuestLib.h>
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette