VirtualBox

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

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

VBoxCredProv: Update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1/* $Id: */
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#include <iprt/string.h>
27#include <VBox/log.h>
28
29#include "VBGLR3Internal.h"
30
31
32/**
33 * Checks whether user credentials are available to the guest or not.
34 *
35 * @returns true if credentials are available, false if not (or error occured).
36 *
37 */
38VBGLR3DECL(bool) VbglR3CredentialsAreAvailable(void)
39{
40 int rc;
41 VMMDevCredentials vmmreqCredentials;
42
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;
56}
57
58
59/**
60 * Retrieves user credentials to log into a guest OS.
61 *
62 * @returns IPRT status value
63 * @param ppszUser Receives pointer of allocated user name string. NULL is accepted.
64 * The returned pointer must be freed using RTStrFree().
65 * @param ppszPassword Receives pointer of allocated user password string. NULL is accepted.
66 * The returned pointer must be freed using RTStrFree().
67 * @param ppszDomain Receives pointer of allocated domain name string. NULL is accepted.
68 * The returned pointer must be freed using RTStrFree().
69 */
70VBGLR3DECL(int) VbglR3CredentialsRetrieve(char **ppszUser, char **ppszPassword, char **ppszDomain)
71{
72 int rc;
73 VMMDevCredentials vmmreqCredentials;
74
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
82 if (RT_SUCCESS(rc))
83 {
84 /** @todo error checking */
85 rc = RTStrDupEx(ppszUser, vmmreqCredentials.szUserName);
86 rc = RTStrDupEx(ppszPassword, vmmreqCredentials.szPassword);
87 rc = RTStrDupEx(ppszDomain, vmmreqCredentials.szDomain);
88 }
89 return rc;
90}
91
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