VBoxGuestR3LibCredentials.cpp revision f5663ddc90362ab5cfe32e277fa34f2b057e8cfd
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/* $Id$ */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/** @file
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, user credentials.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/*
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Copyright (C) 2009 Sun Microsystems, Inc.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * available from http://www.virtualbox.org. This file is free software;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * you can redistribute it and/or modify it under the terms of the GNU
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * General Public License (GPL) as published by the Free Software
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * additional information or have any questions.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/*******************************************************************************
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync* Header Files *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync*******************************************************************************/
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#include <iprt/string.h>
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#include <VBox/log.h>
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#include "VBGLR3Internal.h"
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/**
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Checks whether user credentials are available to the guest or not.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @returns true if credentials are available, false if not (or error occured).
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncVBGLR3DECL(bool) VbglR3CredentialsAreAvailable(void)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync{
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync VMMDevCredentials Req;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync RT_ZERO(Req);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync vmmdevInitRequest((VMMDevRequestHeader*)&Req, VMMDevReq_QueryCredentials);
881b5ff6bc55e1fb0f4ef42f9782ccec79c0a138vboxsync Req.u32Flags |= VMMDEV_CREDENTIALS_QUERYPRESENCE;
881b5ff6bc55e1fb0f4ef42f9782ccec79c0a138vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync int rc = vbglR3GRPerform(&Req.header);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync return RT_SUCCESS(rc)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync && (Req.u32Flags & VMMDEV_CREDENTIALS_PRESENT) != 0;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync}
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/**
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Retrieves and clears the user credentials for logging into the guest OS.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @returns IPRT status value
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param ppszUser Receives pointer of allocated user name string.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * The returned pointer must be freed using RTStrFree().
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param ppszPassword Receives pointer of allocated user password string.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * The returned pointer must be freed using RTStrFree().
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param ppszDomain Receives pointer of allocated domain name string.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * The returned pointer must be freed using RTStrFree().
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncVBGLR3DECL(int) VbglR3CredentialsRetrieve(char **ppszUser, char **ppszPassword, char **ppszDomain)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync{
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync VMMDevCredentials Req;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync RT_ZERO(Req);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync vmmdevInitRequest((VMMDevRequestHeader*)&Req, VMMDevReq_QueryCredentials);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync Req.u32Flags |= VMMDEV_CREDENTIALS_READ | VMMDEV_CREDENTIALS_CLEAR;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync int rc = vbglR3GRPerform(&Req.header);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (RT_SUCCESS(rc))
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync rc = RTStrDupEx(ppszUser, Req.szUserName);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (RT_SUCCESS(rc))
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync rc = RTStrDupEx(ppszPassword, Req.szPassword);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (RT_SUCCESS(rc))
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync rc = RTStrDupEx(ppszDomain, Req.szDomain);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (RT_SUCCESS(rc))
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync return VINF_SUCCESS;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync RTStrFree(*ppszPassword);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync }
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync RTStrFree(*ppszUser);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync }
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync }
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync return rc;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync}
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync