2013-01-11 17:22:14 +01:00
|
|
|
/*
|
|
|
|
* Win32_Process methods implementation
|
|
|
|
*
|
|
|
|
* Copyright 2013 Hans Leidekker for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wbemcli.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wbemprox_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
|
|
|
|
|
|
|
|
static HRESULT get_owner( VARIANT *user, VARIANT *domain, VARIANT *retval )
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
UINT error = 8;
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
GetUserNameW( NULL, &len );
|
|
|
|
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
|
2013-06-04 13:27:08 +02:00
|
|
|
if (!(V_BSTR( user ) = SysAllocStringLen( NULL, len - 1 ))) goto done;
|
2013-01-11 17:22:14 +01:00
|
|
|
if (!GetUserNameW( V_BSTR( user ), &len )) goto done;
|
|
|
|
V_VT( user ) = VT_BSTR;
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
GetComputerNameW( NULL, &len );
|
|
|
|
if (GetLastError() != ERROR_BUFFER_OVERFLOW) goto done;
|
2013-06-04 13:27:08 +02:00
|
|
|
if (!(V_BSTR( domain ) = SysAllocStringLen( NULL, len - 1 ))) goto done;
|
2013-01-11 17:22:14 +01:00
|
|
|
if (!GetComputerNameW( V_BSTR( domain ), &len )) goto done;
|
|
|
|
V_VT( domain ) = VT_BSTR;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
VariantClear( user );
|
|
|
|
VariantClear( domain );
|
|
|
|
}
|
|
|
|
set_variant( VT_UI4, error, NULL, retval );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2021-03-03 07:05:50 +01:00
|
|
|
HRESULT process_get_owner( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
|
2013-01-11 17:22:14 +01:00
|
|
|
{
|
|
|
|
VARIANT user, domain, retval;
|
2014-05-19 12:30:46 +02:00
|
|
|
IWbemClassObject *sig, *out_params = NULL;
|
2013-01-11 17:22:14 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2021-03-05 11:22:58 +01:00
|
|
|
TRACE("%p, %p, %p, %p\n", obj, context, in, out);
|
2013-01-11 17:22:14 +01:00
|
|
|
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = create_signature( L"Win32_Process", L"GetOwner", PARAM_OUT, &sig );
|
2013-01-11 17:22:14 +01:00
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
2014-05-19 12:30:46 +02:00
|
|
|
if (out)
|
2013-01-11 17:22:14 +01:00
|
|
|
{
|
2014-05-19 12:30:46 +02:00
|
|
|
hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
IWbemClassObject_Release( sig );
|
|
|
|
return hr;
|
|
|
|
}
|
2013-01-11 17:22:14 +01:00
|
|
|
}
|
|
|
|
VariantInit( &user );
|
|
|
|
VariantInit( &domain );
|
|
|
|
hr = get_owner( &user, &domain, &retval );
|
|
|
|
if (hr != S_OK) goto done;
|
2014-05-19 12:30:46 +02:00
|
|
|
if (out_params)
|
2013-01-11 17:22:14 +01:00
|
|
|
{
|
2014-05-19 12:30:46 +02:00
|
|
|
if (!V_UI4( &retval ))
|
|
|
|
{
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Put( out_params, L"User", 0, &user, CIM_STRING );
|
2014-05-19 12:30:46 +02:00
|
|
|
if (hr != S_OK) goto done;
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Put( out_params, L"Domain", 0, &domain, CIM_STRING );
|
2014-05-19 12:30:46 +02:00
|
|
|
if (hr != S_OK) goto done;
|
|
|
|
}
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
|
2013-01-11 17:22:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
VariantClear( &user );
|
|
|
|
VariantClear( &domain );
|
|
|
|
IWbemClassObject_Release( sig );
|
2014-05-19 12:30:46 +02:00
|
|
|
if (hr == S_OK && out)
|
|
|
|
{
|
|
|
|
*out = out_params;
|
|
|
|
IWbemClassObject_AddRef( out_params );
|
|
|
|
}
|
|
|
|
if (out_params) IWbemClassObject_Release( out_params );
|
2013-01-11 17:22:14 +01:00
|
|
|
return hr;
|
|
|
|
}
|