6bc3f37529fb8cbe9958bf5ff8d20d86c9a6bc9e
[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 #define COBJMACROS
22
23 #include "config.h"
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wbemcli.h"
29
30 #include "wine/debug.h"
31 #include "wbemprox_private.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
34
35 static HRESULT get_owner( VARIANT *user, VARIANT *domain, VARIANT *retval )
36 {
37 DWORD len;
38 UINT error = 8;
39
40 len = 0;
41 GetUserNameW( NULL, &len );
42 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
43 if (!(V_BSTR( user ) = SysAllocStringLen( NULL, len - 1 ))) goto done;
44 if (!GetUserNameW( V_BSTR( user ), &len )) goto done;
45 V_VT( user ) = VT_BSTR;
46
47 len = 0;
48 GetComputerNameW( NULL, &len );
49 if (GetLastError() != ERROR_BUFFER_OVERFLOW) goto done;
50 if (!(V_BSTR( domain ) = SysAllocStringLen( NULL, len - 1 ))) goto done;
51 if (!GetComputerNameW( V_BSTR( domain ), &len )) goto done;
52 V_VT( domain ) = VT_BSTR;
53
54 error = 0;
55
56 done:
57 if (error)
58 {
59 VariantClear( user );
60 VariantClear( domain );
61 }
62 set_variant( VT_UI4, error, NULL, retval );
63 return S_OK;
64 }
65
66 HRESULT process_get_owner( IWbemClassObject *obj, IWbemClassObject *in, IWbemClassObject **out )
67 {
68 VARIANT user, domain, retval;
69 IWbemClassObject *sig, *out_params = NULL;
70 HRESULT hr;
71
72 TRACE("%p, %p, %p\n", obj, in, out);
73
74 hr = create_signature( class_processW, method_getownerW, PARAM_OUT, &sig );
75 if (hr != S_OK) return hr;
76
77 if (out)
78 {
79 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
80 if (hr != S_OK)
81 {
82 IWbemClassObject_Release( sig );
83 return hr;
84 }
85 }
86 VariantInit( &user );
87 VariantInit( &domain );
88 hr = get_owner( &user, &domain, &retval );
89 if (hr != S_OK) goto done;
90 if (out_params)
91 {
92 if (!V_UI4( &retval ))
93 {
94 hr = IWbemClassObject_Put( out_params, param_userW, 0, &user, CIM_STRING );
95 if (hr != S_OK) goto done;
96 hr = IWbemClassObject_Put( out_params, param_domainW, 0, &domain, CIM_STRING );
97 if (hr != S_OK) goto done;
98 }
99 hr = IWbemClassObject_Put( out_params, param_returnvalueW, 0, &retval, CIM_UINT32 );
100 }
101
102 done:
103 VariantClear( &user );
104 VariantClear( &domain );
105 IWbemClassObject_Release( sig );
106 if (hr == S_OK && out)
107 {
108 *out = out_params;
109 IWbemClassObject_AddRef( out_params );
110 }
111 if (out_params) IWbemClassObject_Release( out_params );
112 return hr;
113 }