RTProcessQueryUsernameA-generic.cpp revision c7814cf6e1240a519cbec0441e033d0e2470ed00
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/* $Id$ */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/** @file
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * IPRT - RTSystemQueryOSInfo, generic stub.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/*
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Copyright (C) 2008-2012 Oracle Corporation
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * available from http://www.virtualbox.org. This file is free software;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * you can redistribute it and/or modify it under the terms of the GNU
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * General Public License (GPL) as published by the Free Software
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * The contents of this file may alternatively be used under the terms
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * of the Common Development and Distribution License Version 1.0
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * VirtualBox OSE distribution, in which case the provisions of the
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * CDDL are applicable instead of those of the GPL.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * You may elect to license modified versions of this file under the
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * terms and conditions of either the GPL or the CDDL or both.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/*******************************************************************************
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync* Header Files *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync*******************************************************************************/
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#include <iprt/system.h>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#include "internal/iprt.h"
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#include <iprt/assert.h>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#include <iprt/string.h>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#include <iprt/process.h>
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncRTR3DECL(int) RTProcQueryUsernameA(RTPROCESS hProcess, char **ppszUser)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync{
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync /*
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Validation.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync AssertPtrReturn(ppszUser, VERR_INVALID_POINTER);
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync int rc = VINF_SUCCESS;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync size_t cbUser = 0;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync rc = RTProcQueryUsername(hProcess, NULL, cbUser, &cbUser);
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync if (rc == VERR_BUFFER_OVERFLOW)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync {
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync char *pszUser = (char *)RTStrAlloc(cbUser);
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync if (pszUser)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync {
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync rc = RTProcQueryUsername(hProcess, pszUser, cbUser, NULL);
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync Assert(rc != VERR_BUFFER_OVERFLOW);
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync if (RT_SUCCESS(rc))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *ppszUser = pszUser;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync else
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync RTStrFree(pszUser);
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync }
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync else
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync rc = VERR_NO_STR_MEMORY;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync }
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync return rc;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync}
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncRT_EXPORT_SYMBOL(RTProcQueryUsernameA);
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync