VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibCredentials.cpp@ 35263

Last change on this file since 35263 was 33540, checked in by vboxsync, 14 years ago

*: spelling fixes, thanks Timeless!

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/* $Id: VBoxGuestR3LibCredentials.cpp 33540 2010-10-28 09:27:05Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, user credentials.
4 */
5
6/*
7 * Copyright (C) 2009 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <iprt/asm.h>
32#include <iprt/mem.h>
33#include <iprt/rand.h>
34#include <iprt/string.h>
35#include <VBox/log.h>
36
37#include "VBGLR3Internal.h"
38
39
40/**
41 * Checks whether user credentials are available to the guest or not.
42 *
43 * @returns IPRT status value; VINF_SUCCESS if credentials are available,
44 * VERR_NOT_FOUND if not. Otherwise an error is occurred.
45 */
46VBGLR3DECL(int) VbglR3CredentialsQueryAvailability(void)
47{
48 VMMDevCredentials Req;
49 RT_ZERO(Req);
50 vmmdevInitRequest((VMMDevRequestHeader*)&Req, VMMDevReq_QueryCredentials);
51 Req.u32Flags |= VMMDEV_CREDENTIALS_QUERYPRESENCE;
52
53 int rc = vbglR3GRPerform(&Req.header);
54 if (RT_SUCCESS(rc))
55 {
56 if ((Req.u32Flags & VMMDEV_CREDENTIALS_PRESENT) == 0)
57 rc = VERR_NOT_FOUND;
58 }
59 return rc;
60}
61
62
63/**
64 * Retrieves and clears the user credentials for logging into the guest OS.
65 *
66 * @returns IPRT status value
67 * @param ppszUser Receives pointer of allocated user name string.
68 * The returned pointer must be freed using VbglR3CredentialsDestroy().
69 * @param ppszPassword Receives pointer of allocated user password string.
70 * The returned pointer must be freed using VbglR3CredentialsDestroy().
71 * @param ppszDomain Receives pointer of allocated domain name string.
72 * The returned pointer must be freed using VbglR3CredentialsDestroy().
73 */
74VBGLR3DECL(int) VbglR3CredentialsRetrieve(char **ppszUser, char **ppszPassword, char **ppszDomain)
75{
76 VMMDevCredentials Req;
77 RT_ZERO(Req);
78 vmmdevInitRequest((VMMDevRequestHeader*)&Req, VMMDevReq_QueryCredentials);
79 Req.u32Flags |= VMMDEV_CREDENTIALS_READ | VMMDEV_CREDENTIALS_CLEAR;
80
81 int rc = vbglR3GRPerform(&Req.header);
82 if (RT_SUCCESS(rc))
83 {
84 rc = RTStrDupEx(ppszUser, Req.szUserName);
85 if (RT_SUCCESS(rc))
86 {
87 rc = RTStrDupEx(ppszPassword, Req.szPassword);
88 if (RT_SUCCESS(rc))
89 {
90 rc = RTStrDupEx(ppszDomain, Req.szDomain);
91 if (RT_SUCCESS(rc))
92 return VINF_SUCCESS;
93
94 RTStrFree(*ppszPassword);
95 }
96 RTStrFree(*ppszUser);
97 }
98 }
99 return rc;
100}
101
102
103/**
104 * Clears and frees the three strings.
105 *
106 * @param pszUser Receives pointer of the user name string to destroy.
107 * Optional.
108 * @param pszPassword Receives pointer of the password string to destroy.
109 * Optional.
110 * @param pszDomain Receives pointer of allocated domain name string.
111 * Optional.
112 * @param cPasses Number of wipe passes. The more the better + slower.
113 */
114VBGLR3DECL(void) VbglR3CredentialsDestroy(char *pszUser, char *pszPassword, char *pszDomain, uint32_t cPasses)
115{
116 /* wipe first */
117 if (pszUser)
118 RTMemWipeThoroughly(pszUser, strlen(pszUser) + 1, cPasses);
119 if (pszPassword)
120 RTMemWipeThoroughly(pszPassword, strlen(pszPassword) + 1, cPasses);
121 if (pszDomain)
122 RTMemWipeThoroughly(pszDomain, strlen(pszDomain) + 1, cPasses);
123
124 /* then free. */
125 RTStrFree(pszUser);
126 RTStrFree(pszPassword);
127 RTStrFree(pszDomain);
128}
129
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use