[RSHELL]
[reactos.git] / dll / win32 / wbemprox / process.c
1 /*
2 * Win32_Process methods implementation
3 *
4 * Copyright 2013 Hans Leidekker for CodeWeavers
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "wbemprox_private.h"
22
23 static HRESULT get_owner( VARIANT *user, VARIANT *domain, VARIANT *retval )
24 {
25 DWORD len;
26 UINT error = 8;
27
28 len = 0;
29 GetUserNameW( NULL, &len );
30 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
31 if (!(V_BSTR( user ) = SysAllocStringLen( NULL, len - 1 ))) goto done;
32 if (!GetUserNameW( V_BSTR( user ), &len )) goto done;
33 V_VT( user ) = VT_BSTR;
34
35 len = 0;
36 GetComputerNameW( NULL, &len );
37 if (GetLastError() != ERROR_BUFFER_OVERFLOW) goto done;
38 if (!(V_BSTR( domain ) = SysAllocStringLen( NULL, len - 1 ))) goto done;
39 if (!GetComputerNameW( V_BSTR( domain ), &len )) goto done;
40 V_VT( domain ) = VT_BSTR;
41
42 error = 0;
43
44 done:
45 if (error)
46 {
47 VariantClear( user );
48 VariantClear( domain );
49 }
50 set_variant( VT_UI4, error, NULL, retval );
51 return S_OK;
52 }
53
54 HRESULT process_get_owner( IWbemClassObject *obj, IWbemClassObject *in, IWbemClassObject **out )
55 {
56 VARIANT user, domain, retval;
57 IWbemClassObject *sig;
58 HRESULT hr;
59
60 TRACE("%p, %p, %p\n", obj, in, out);
61
62 hr = create_signature( class_processW, method_getownerW, PARAM_OUT, &sig );
63 if (hr != S_OK) return hr;
64
65 hr = IWbemClassObject_SpawnInstance( sig, 0, out );
66 if (hr != S_OK)
67 {
68 IWbemClassObject_Release( sig );
69 return hr;
70 }
71 VariantInit( &user );
72 VariantInit( &domain );
73 hr = get_owner( &user, &domain, &retval );
74 if (hr != S_OK) goto done;
75 if (!V_UI4( &retval ))
76 {
77 hr = IWbemClassObject_Put( *out, param_userW, 0, &user, CIM_STRING );
78 if (hr != S_OK) goto done;
79 hr = IWbemClassObject_Put( *out, param_domainW, 0, &domain, CIM_STRING );
80 if (hr != S_OK) goto done;
81 }
82 hr = IWbemClassObject_Put( *out, param_returnvalueW, 0, &retval, CIM_UINT32 );
83
84 done:
85 VariantClear( &user );
86 VariantClear( &domain );
87 IWbemClassObject_Release( sig );
88 if (hr != S_OK) IWbemClassObject_Release( *out );
89 return hr;
90 }