VirtualBox

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

Last change on this file since 28266 was 26425, checked in by vboxsync, 15 years ago

alternative license for VBoxGuestLib is CDDL

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: VBoxGuestR3LibCredentials.cpp 26425 2010-02-11 11:37:08Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, user credentials.
4 */
5
6/*
7 * Copyright (C) 2009 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include <iprt/asm.h>
36#include <iprt/string.h>
37#include <iprt/rand.h>
38#include <VBox/log.h>
39
40#include "VBGLR3Internal.h"
41
42
43/**
44 * Checks whether user credentials are available to the guest or not.
45 *
46 * @returns IPRT status value; VINF_SUCCESS if credentials are available,
47 * VERR_NOT_FOUND if not. Otherwise an error is occured.
48 */
49VBGLR3DECL(int) VbglR3CredentialsQueryAvailability(void)
50{
51 VMMDevCredentials Req;
52 RT_ZERO(Req);
53 vmmdevInitRequest((VMMDevRequestHeader*)&Req, VMMDevReq_QueryCredentials);
54 Req.u32Flags |= VMMDEV_CREDENTIALS_QUERYPRESENCE;
55
56 int rc = vbglR3GRPerform(&Req.header);
57 if (RT_SUCCESS(rc))
58 {
59 if ((Req.u32Flags & VMMDEV_CREDENTIALS_PRESENT) == 0)
60 rc = VERR_NOT_FOUND;
61 }
62 return rc;
63}
64
65
66/**
67 * Retrieves and clears the user credentials for logging into the guest OS.
68 *
69 * @returns IPRT status value
70 * @param ppszUser Receives pointer of allocated user name string.
71 * The returned pointer must be freed using VbglR3CredentialsDestroy().
72 * @param ppszPassword Receives pointer of allocated user password string.
73 * The returned pointer must be freed using VbglR3CredentialsDestroy().
74 * @param ppszDomain Receives pointer of allocated domain name string.
75 * The returned pointer must be freed using VbglR3CredentialsDestroy().
76 */
77VBGLR3DECL(int) VbglR3CredentialsRetrieve(char **ppszUser, char **ppszPassword, char **ppszDomain)
78{
79 VMMDevCredentials Req;
80 RT_ZERO(Req);
81 vmmdevInitRequest((VMMDevRequestHeader*)&Req, VMMDevReq_QueryCredentials);
82 Req.u32Flags |= VMMDEV_CREDENTIALS_READ | VMMDEV_CREDENTIALS_CLEAR;
83
84 int rc = vbglR3GRPerform(&Req.header);
85 if (RT_SUCCESS(rc))
86 {
87 rc = RTStrDupEx(ppszUser, Req.szUserName);
88 if (RT_SUCCESS(rc))
89 {
90 rc = RTStrDupEx(ppszPassword, Req.szPassword);
91 if (RT_SUCCESS(rc))
92 {
93 rc = RTStrDupEx(ppszDomain, Req.szDomain);
94 if (RT_SUCCESS(rc))
95 return VINF_SUCCESS;
96
97 RTStrFree(*ppszPassword);
98 }
99 RTStrFree(*ppszUser);
100 }
101 }
102 return rc;
103}
104
105
106/**
107 * Clears and frees the three strings.
108 *
109 * @param pszUser Receives pointer of the user name string to destroy.
110 * Optional.
111 * @param pszPassword Receives pointer of the password string to destroy.
112 * Optional.
113 * @param pszDomain Receives pointer of allocated domain name string.
114 * Optional.
115 * @param cPasses Number of wipe passes. The more the better + slower.
116 */
117VBGLR3DECL(void) VbglR3CredentialsDestroy(char *pszUser, char *pszPassword, char *pszDomain, uint32_t cPasses)
118{
119 size_t const cchUser = pszUser ? strlen(pszUser) : 0;
120 size_t const cchPassword = pszPassword ? strlen(pszPassword) : 0;
121 size_t const cchDomain = pszDomain ? strlen(pszDomain) : 0;
122
123 do
124 {
125 if (cchUser)
126 memset(pszUser, 0xff, cchUser);
127 if (cchPassword)
128 memset(pszPassword, 0xff, cchPassword);
129 if (cchDomain)
130 memset(pszDomain, 0xff, cchDomain);
131 ASMMemoryFence();
132
133 if (cchUser)
134 memset(pszUser, 0x00, cchUser);
135 if (cchPassword)
136 memset(pszPassword, 0x00, cchPassword);
137 if (cchDomain)
138 memset(pszDomain, 0x00, cchDomain);
139 ASMMemoryFence();
140
141 if (cchUser)
142 RTRandBytes(pszUser, cchUser);
143 if (cchPassword)
144 RTRandBytes(pszPassword, cchPassword);
145 if (cchDomain)
146 RTRandBytes(pszDomain, cchDomain);
147 ASMMemoryFence();
148
149 } while (cPasses-- > 0);
150
151 RTStrFree(pszUser);
152 RTStrFree(pszPassword);
153 RTStrFree(pszDomain);
154}
155
Note: See TracBrowser for help on using the repository browser.

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