VirtualBox

Changeset 24311 in vbox for trunk/src/VBox/Additions/common


Ignore:
Timestamp:
Nov 4, 2009 10:44:03 AM (15 years ago)
Author:
vboxsync
Message:

VBoxGuestR3LibCredentials.cpp: File header, use RT_ZERO(), deal with RTStrDupEx failures, corrected the *Retrieve docs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibCredentials.cpp

    r24270 r24311  
    1 /* $Id: */
     1/* $Id$ */
    22/** @file
    33 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, user credentials.
     
    3434 *
    3535 * @returns true if credentials are available, false if not (or error occured).
    36  *
    3736 */
    3837VBGLR3DECL(bool) VbglR3CredentialsAreAvailable(void)
    3938{
    40     int rc;
    41     VMMDevCredentials vmmreqCredentials;
     39    VMMDevCredentials Req;
     40    RT_ZERO(Req);
     41    vmmdevInitRequest((VMMDevRequestHeader*)&Req, VMMDevReq_QueryCredentials);
     42    Req.u32Flags |= VMMDEV_CREDENTIALS_QUERYPRESENCE;
    4243
    43     memset(&vmmreqCredentials, 0, sizeof(vmmreqCredentials));
    44 
    45     vmmdevInitRequest((VMMDevRequestHeader*)&vmmreqCredentials, VMMDevReq_QueryCredentials);
    46     vmmreqCredentials.u32Flags |= VMMDEV_CREDENTIALS_QUERYPRESENCE;
    47     rc = vbglR3GRPerform(&vmmreqCredentials.header);
    48 
    49     bool fAvailable = false;
    50     if (   RT_SUCCESS(rc)
    51         && ((vmmreqCredentials.u32Flags & VMMDEV_CREDENTIALS_PRESENT) != 0))
    52     {
    53         fAvailable = true;
    54     }
    55     return fAvailable;
     44    int rc = vbglR3GRPerform(&Req.header);
     45    return RT_SUCCESS(rc)
     46        && (Req.u32Flags & VMMDEV_CREDENTIALS_PRESENT) != 0;
    5647}
    5748
    5849
    5950/**
    60  * Retrieves user credentials to log into a guest OS.
     51 * Retrieves and clears the user credentials for logging into the guest OS.
    6152 *
    6253 * @returns IPRT status value
    63  * @param   ppszUser        Receives pointer of allocated user name string. NULL is accepted.
     54 * @param   ppszUser        Receives pointer of allocated user name string.
    6455 *                          The returned pointer must be freed using RTStrFree().
    65  * @param   ppszPassword    Receives pointer of allocated user password string. NULL is accepted.
     56 * @param   ppszPassword    Receives pointer of allocated user password string.
    6657 *                          The returned pointer must be freed using RTStrFree().
    67  * @param   ppszDomain      Receives pointer of allocated domain name string. NULL is accepted.
     58 * @param   ppszDomain      Receives pointer of allocated domain name string.
    6859 *                          The returned pointer must be freed using RTStrFree().
    6960 */
    7061VBGLR3DECL(int) VbglR3CredentialsRetrieve(char **ppszUser, char **ppszPassword, char **ppszDomain)
    7162{
    72     int rc;
    73     VMMDevCredentials vmmreqCredentials;
     63    VMMDevCredentials Req;
     64    RT_ZERO(Req);
     65    vmmdevInitRequest((VMMDevRequestHeader*)&Req, VMMDevReq_QueryCredentials);
     66    Req.u32Flags |= VMMDEV_CREDENTIALS_READ | VMMDEV_CREDENTIALS_CLEAR;
    7467
    75     memset(&vmmreqCredentials, 0, sizeof(vmmreqCredentials));
    76 
    77     vmmdevInitRequest((VMMDevRequestHeader*)&vmmreqCredentials, VMMDevReq_QueryCredentials);
    78     vmmreqCredentials.u32Flags |= VMMDEV_CREDENTIALS_READ;
    79     vmmreqCredentials.u32Flags |= VMMDEV_CREDENTIALS_CLEAR;
    80     rc = vbglR3GRPerform(&vmmreqCredentials.header);
    81 
     68    int rc = vbglR3GRPerform(&Req.header);
    8269    if (RT_SUCCESS(rc))
    8370    {
    84         /** @todo error checking */
    85         rc = RTStrDupEx(ppszUser, vmmreqCredentials.szUserName);
    86         rc = RTStrDupEx(ppszPassword, vmmreqCredentials.szPassword);
    87         rc = RTStrDupEx(ppszDomain, vmmreqCredentials.szDomain);
     71        rc = RTStrDupEx(ppszUser, Req.szUserName);
     72        if (RT_SUCCESS(rc))
     73        {
     74            rc = RTStrDupEx(ppszPassword, Req.szPassword);
     75            if (RT_SUCCESS(rc))
     76            {
     77                rc = RTStrDupEx(ppszDomain, Req.szDomain);
     78                if (RT_SUCCESS(rc))
     79                    return VINF_SUCCESS;
     80
     81                RTStrFree(*ppszPassword);
     82            }
     83            RTStrFree(*ppszUser);
     84        }
    8885    }
    8986    return rc;
Note: See TracChangeset for help on using the changeset viewer.

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