VirtualBox

Changeset 30367 in vbox for trunk/src/VBox/Additions/WINNT


Ignore:
Timestamp:
Jun 22, 2010 12:19:33 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
62959
Message:

VBox Credential Provider: Added support for principal logon names (user@domain).

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

Legend:

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

    r30252 r30367  
    105105    PWSTR *ppwszStored;
    106106
     107    /*
     108     * Update domain name (can be NULL) and will
     109     * be later replaced by the local computer name in the
     110     * Kerberos authentication package or by the first part
     111     * of the principcal name.
     112     */
     113    if (pszDomain && strlen(pszDomain))
     114    {
     115        ppwszStored = &m_rgFieldStrings[SFI_DOMAINNAME];
     116        CoTaskMemFree(*ppwszStored);
     117        SHStrDupA(pszDomain, ppwszStored);
     118    }
     119
    107120    /* Update user name. */
    108121    if (pszUser && strlen(pszUser))
     
    123136            m_rgFieldStrings[SFI_USERNAME] = pwszAcount;
    124137        }
     138        else
     139        {
     140            /*
     141             * Oky, no display name, but mabye it's a
     142             * principal name from which we have to extract the
     143             * domain from? ([email protected] -> jdoe in
     144             * domain my-domain.sub.net.com.)
     145             */
     146            PWSTR pwszDomain;
     147            if (ExtractAccoutData(*ppwszStored, &pwszAcount, &pwszDomain))
     148            {
     149                /* Update user name. */
     150                CoTaskMemFree(*ppwszStored);
     151                m_rgFieldStrings[SFI_USERNAME] = pwszAcount;
     152
     153                /* Update domain. */
     154                ppwszStored = &m_rgFieldStrings[SFI_DOMAINNAME];
     155                CoTaskMemFree(*ppwszStored);
     156                m_rgFieldStrings[SFI_DOMAINNAME] = pwszDomain;
     157            }
     158        }
    125159    }
    126160
     
    131165        CoTaskMemFree(*ppwszStored);
    132166        SHStrDupA(pszPw, ppwszStored);
    133     }
    134 
    135     /*
    136      * Update domain name (can be NULL) and will
    137      * be later replaced by the local computer name in the
    138      * Kerberos authentication package.
    139      */
    140     if (pszDomain && strlen(pszDomain))
    141     {
    142         ppwszStored = &m_rgFieldStrings[SFI_DOMAINNAME];
    143         CoTaskMemFree(*ppwszStored);
    144         SHStrDupA(pszDomain, ppwszStored);
    145167    }
    146168
     
    361383                         * output buffer.
    362384                         */
    363                         LPWSTR ppwszTemp;
    364                         HRESULT hr = SHStrDupW(pCurBuf->usri2_name, &ppwszTemp);
     385                        LPWSTR pwszTemp;
     386                        HRESULT hr = SHStrDupW(pCurBuf->usri2_name, &pwszTemp);
    365387                        if (hr == S_OK)
    366388                        {
    367                             *ppwszAccoutName = ppwszTemp;
     389                            *ppwszAccoutName = pwszTemp;
    368390                            fFound = TRUE;
    369391                        }
    370392                        else
    371                             Log(("VBoxCredential::TranslateAccountName: Error copying data, hr=%08x", hr));
     393                            Log(("VBoxCredential::TranslateAccountName: Error copying data, hr=%08x\n", hr));
    372394                        break;
    373395                    }
     
    423445    }
    424446#endif
     447}
     448
     449
     450/*
     451 * Extracts the actual account name & domain from a (raw) account data string. This might
     452 * be a prncipal or FQDN string.
     453 */
     454BOOL VBoxCredential::ExtractAccoutData(PWSTR pwszAccountData, PWSTR *ppwszAccoutName, PWSTR *ppwszDomain)
     455{
     456    Log(("VBoxCredential::ExtractAccoutData\n"));
     457
     458    AssertPtr(pwszAccountData);
     459    Log(("VBoxCredential::ExtractAccoutData: Getting account name for '%ls' ...\n", pwszAccountData));
     460    HRESULT hr = E_FAIL;
     461
     462    /* Try to figure out whether this is a principal name (user@domain). */
     463    LPWSTR pPos = NULL;
     464    if (    (pPos                       = StrChrW(pwszAccountData, L'@')) != NULL
     465        &&   pPos                      != pwszAccountData)
     466    {
     467        DWORD cbSize = (pPos - pwszAccountData) * sizeof(WCHAR);
     468        LPWSTR pwszName = (LPWSTR)CoTaskMemAlloc(cbSize + sizeof(WCHAR)); /* Space for terminating zero. */
     469        LPWSTR pwszDomain = NULL;
     470        AssertPtr(pwszName);
     471        hr = StringCbCopyN(pwszName, cbSize + sizeof(WCHAR), pwszAccountData, cbSize);
     472        if (SUCCEEDED(hr))
     473        {
     474            *ppwszAccoutName = pwszName;
     475            *pPos++; /* Skip @, point to domain name (if any). */
     476            if (    pPos != NULL
     477                && *pPos != L'\0')
     478            {
     479                hr = SHStrDupW(pPos, &pwszDomain);
     480                if (SUCCEEDED(hr))
     481                {
     482                    *ppwszDomain = pwszDomain;
     483                }
     484                else
     485                    Log(("VBoxCredential::ExtractAccoutData/Principal: Error copying domain data, hr=%08x\n", hr));
     486            }
     487            else
     488            {
     489                hr = E_FAIL;
     490                Log(("VBoxCredential::ExtractAccoutData/Principal: No domain name found!\n"));
     491            }
     492        }
     493        else
     494            Log(("VBoxCredential::ExtractAccoutData/Principal: Error copying account data, hr=%08x\n", hr));
     495
     496        if (hr != S_OK)
     497        {
     498            CoTaskMemFree(pwszName);
     499            if (pwszDomain)
     500                CoTaskMemFree(pwszDomain);
     501        }
     502    }
     503    else
     504        Log(("VBoxCredential::ExtractAccoutData/Principal: No valid prinicipal account name found!\n"));
     505
     506    return (hr == S_OK);
    425507}
    426508
  • trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredential.h

    r30252 r30367  
    113113                   const char *pszDomain);
    114114        BOOL TranslateAccountName(PWSTR pwszDisplayName, PWSTR *ppwszAccoutName);
     115        BOOL ExtractAccoutData(PWSTR pwszAccountData, PWSTR *ppwszAccoutName, PWSTR *ppwszDomain);
    115116    private:
    116117
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