2012-10-12 14:26:12 +02:00
|
|
|
/*
|
|
|
|
* StdRegProv implementation
|
|
|
|
*
|
|
|
|
* Copyright 2012 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 to_bstr_array( BSTR *strings, DWORD count, VARIANT *var )
|
|
|
|
{
|
|
|
|
SAFEARRAY *sa;
|
|
|
|
HRESULT hr;
|
|
|
|
LONG i;
|
|
|
|
|
|
|
|
if (!(sa = SafeArrayCreateVector( VT_BSTR, 0, count ))) return E_OUTOFMEMORY;
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if ((hr = SafeArrayPutElement( sa, &i, strings[i] )) != S_OK)
|
|
|
|
{
|
|
|
|
SafeArrayDestroy( sa );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set_variant( VT_BSTR|VT_ARRAY, 0, sa, var );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-22 12:13:55 +02:00
|
|
|
static void free_bstr_array( BSTR *strings, DWORD count )
|
|
|
|
{
|
|
|
|
while (count--)
|
|
|
|
SysFreeString( *(strings++) );
|
|
|
|
}
|
|
|
|
|
2012-10-12 14:26:12 +02:00
|
|
|
static HRESULT to_i4_array( DWORD *values, DWORD count, VARIANT *var )
|
|
|
|
{
|
|
|
|
SAFEARRAY *sa;
|
|
|
|
HRESULT hr;
|
|
|
|
LONG i;
|
|
|
|
|
|
|
|
if (!(sa = SafeArrayCreateVector( VT_I4, 0, count ))) return E_OUTOFMEMORY;
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if ((hr = SafeArrayPutElement( sa, &i, &values[i] )) != S_OK)
|
|
|
|
{
|
|
|
|
SafeArrayDestroy( sa );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set_variant( VT_I4|VT_ARRAY, 0, sa, var );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2021-03-03 07:05:52 +01:00
|
|
|
static unsigned int reg_get_access_mask( IWbemContext *context )
|
|
|
|
{
|
|
|
|
VARIANT value;
|
|
|
|
|
|
|
|
if (!context) return 0;
|
|
|
|
|
|
|
|
V_VT( &value ) = VT_EMPTY;
|
|
|
|
if (FAILED(IWbemContext_GetValue( context, L"__ProviderArchitecture", 0, &value )))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (FAILED(VariantChangeType( &value, &value, 0, VT_I4 )))
|
|
|
|
{
|
|
|
|
VariantClear( &value );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (V_I4( &value ) == 32)
|
|
|
|
return KEY_WOW64_32KEY;
|
|
|
|
else if (V_I4( &value ) == 64)
|
|
|
|
return KEY_WOW64_64KEY;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-03 07:05:54 +01:00
|
|
|
static HRESULT create_key( HKEY root, const WCHAR *subkey, IWbemContext *context, VARIANT *retval )
|
2018-09-28 10:58:40 +02:00
|
|
|
{
|
|
|
|
LONG res;
|
|
|
|
HKEY hkey;
|
|
|
|
|
|
|
|
TRACE("%p, %s\n", root, debugstr_w(subkey));
|
|
|
|
|
2021-03-03 07:05:54 +01:00
|
|
|
res = RegCreateKeyExW( root, subkey, 0, NULL, 0, reg_get_access_mask( context ), NULL, &hkey, NULL );
|
2018-09-28 10:58:40 +02:00
|
|
|
set_variant( VT_UI4, res, NULL, retval );
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return HRESULT_FROM_WIN32( res );
|
|
|
|
}
|
|
|
|
|
2021-03-03 07:05:50 +01:00
|
|
|
HRESULT reg_create_key( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
|
2018-09-28 10:58:40 +02:00
|
|
|
{
|
|
|
|
VARIANT defkey, subkey, retval;
|
|
|
|
IWbemClassObject *sig, *out_params = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2021-03-05 11:22:58 +01:00
|
|
|
TRACE("%p, %p, %p, %p\n", obj, context, in, out);
|
2018-09-28 10:58:40 +02:00
|
|
|
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
|
2018-09-28 10:58:40 +02:00
|
|
|
if (hr != S_OK) return hr;
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
|
2018-09-28 10:58:40 +02:00
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
2021-09-13 16:13:27 +02:00
|
|
|
hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"CreateKey", PARAM_OUT, &sig );
|
2018-09-28 10:58:40 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &subkey );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
if (out)
|
|
|
|
{
|
|
|
|
hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &subkey );
|
|
|
|
IWbemClassObject_Release( sig );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
2021-03-03 07:05:54 +01:00
|
|
|
hr = create_key( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), context, &retval );
|
2018-09-28 10:58:40 +02:00
|
|
|
if (hr == S_OK && out_params)
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
|
2018-09-28 10:58:40 +02:00
|
|
|
|
|
|
|
VariantClear( &subkey );
|
|
|
|
IWbemClassObject_Release( sig );
|
|
|
|
if (hr == S_OK && out)
|
|
|
|
{
|
|
|
|
*out = out_params;
|
|
|
|
IWbemClassObject_AddRef( out_params );
|
|
|
|
}
|
|
|
|
if (out_params) IWbemClassObject_Release( out_params );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2021-03-03 07:05:55 +01:00
|
|
|
static HRESULT enum_key( HKEY root, const WCHAR *subkey, VARIANT *names, IWbemContext *context, VARIANT *retval )
|
2012-10-12 14:26:12 +02:00
|
|
|
{
|
|
|
|
HKEY hkey;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
WCHAR buf[256];
|
|
|
|
BSTR *strings, *tmp;
|
2018-09-11 22:08:07 +02:00
|
|
|
DWORD count = 2, len = ARRAY_SIZE( buf );
|
2012-10-12 14:26:12 +02:00
|
|
|
LONG res, i = 0;
|
|
|
|
|
|
|
|
TRACE("%p, %s\n", root, debugstr_w(subkey));
|
|
|
|
|
|
|
|
if (!(strings = heap_alloc( count * sizeof(BSTR) ))) return E_OUTOFMEMORY;
|
2021-03-03 07:05:55 +01:00
|
|
|
if ((res = RegOpenKeyExW( root, subkey, 0, KEY_ENUMERATE_SUB_KEYS | reg_get_access_mask( context ), &hkey )))
|
2012-10-12 14:26:12 +02:00
|
|
|
{
|
|
|
|
set_variant( VT_UI4, res, NULL, retval );
|
|
|
|
heap_free( strings );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (i >= count)
|
|
|
|
{
|
|
|
|
count *= 2;
|
|
|
|
if (!(tmp = heap_realloc( strings, count * sizeof(BSTR) )))
|
|
|
|
{
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
strings = tmp;
|
|
|
|
}
|
|
|
|
if ((res = RegEnumKeyW( hkey, i, buf, len )) == ERROR_NO_MORE_ITEMS)
|
|
|
|
{
|
|
|
|
if (i) res = ERROR_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (res) break;
|
|
|
|
if (!(strings[i] = SysAllocString( buf )))
|
|
|
|
{
|
|
|
|
for (i--; i >= 0; i--) SysFreeString( strings[i] );
|
2016-09-13 09:03:57 +02:00
|
|
|
hr = E_OUTOFMEMORY;
|
2012-10-12 14:26:12 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2015-04-22 12:13:55 +02:00
|
|
|
if (hr == S_OK && !res)
|
|
|
|
{
|
|
|
|
hr = to_bstr_array( strings, i, names );
|
|
|
|
free_bstr_array( strings, i );
|
|
|
|
}
|
2012-10-12 14:26:12 +02:00
|
|
|
set_variant( VT_UI4, res, NULL, retval );
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
heap_free( strings );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2021-03-03 07:05:50 +01:00
|
|
|
HRESULT reg_enum_key( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
|
2012-10-12 14:26:12 +02:00
|
|
|
{
|
|
|
|
VARIANT defkey, subkey, names, retval;
|
2014-05-19 12:30:46 +02:00
|
|
|
IWbemClassObject *sig, *out_params = NULL;
|
2012-10-12 14:26:12 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2021-03-05 11:22:58 +01:00
|
|
|
TRACE("%p, %p, %p, %p\n", obj, context, in, out);
|
2012-10-12 14:26:12 +02:00
|
|
|
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
|
2012-10-12 14:26:12 +02:00
|
|
|
if (hr != S_OK) return hr;
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
|
2012-10-12 14:26:12 +02:00
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
2021-09-13 16:13:27 +02:00
|
|
|
hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"EnumKey", PARAM_OUT, &sig );
|
2012-10-12 14:26:12 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &subkey );
|
|
|
|
return hr;
|
|
|
|
}
|
2014-05-19 12:30:46 +02:00
|
|
|
if (out)
|
2012-10-12 14:26:12 +02:00
|
|
|
{
|
2014-05-19 12:30:46 +02:00
|
|
|
hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &subkey );
|
|
|
|
IWbemClassObject_Release( sig );
|
|
|
|
return hr;
|
|
|
|
}
|
2012-10-12 14:26:12 +02:00
|
|
|
}
|
|
|
|
VariantInit( &names );
|
2021-03-03 07:05:55 +01:00
|
|
|
hr = enum_key( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), &names, context, &retval );
|
2012-10-12 14:26:12 +02:00
|
|
|
if (hr != S_OK) goto done;
|
2014-05-19 12:30:46 +02:00
|
|
|
if (out_params)
|
2012-10-12 14:26:12 +02: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"sNames", 0, &names, CIM_STRING|CIM_FLAG_ARRAY );
|
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 );
|
2012-10-12 14:26:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
VariantClear( &names );
|
|
|
|
VariantClear( &subkey );
|
|
|
|
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 );
|
2012-10-12 14:26:12 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2021-03-03 07:05:56 +01:00
|
|
|
static HRESULT enum_values( HKEY root, const WCHAR *subkey, VARIANT *names, VARIANT *types, IWbemContext *context,
|
|
|
|
VARIANT *retval )
|
2012-10-12 14:26:12 +02:00
|
|
|
{
|
|
|
|
HKEY hkey = NULL;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
BSTR *value_names = NULL;
|
|
|
|
DWORD count, buflen, len, *value_types = NULL;
|
|
|
|
LONG res, i = 0;
|
|
|
|
WCHAR *buf = NULL;
|
|
|
|
|
|
|
|
TRACE("%p, %s\n", root, debugstr_w(subkey));
|
|
|
|
|
2021-03-03 07:05:56 +01:00
|
|
|
if ((res = RegOpenKeyExW( root, subkey, 0, KEY_QUERY_VALUE | reg_get_access_mask( context ), &hkey ))) goto done;
|
2012-10-12 14:26:12 +02:00
|
|
|
if ((res = RegQueryInfoKeyW( hkey, NULL, NULL, NULL, NULL, NULL, NULL, &count, &buflen, NULL, NULL, NULL )))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
if (!(buf = heap_alloc( (buflen + 1) * sizeof(WCHAR) ))) goto done;
|
|
|
|
if (!(value_names = heap_alloc( count * sizeof(BSTR) ))) goto done;
|
|
|
|
if (!(value_types = heap_alloc( count * sizeof(DWORD) ))) goto done;
|
|
|
|
|
|
|
|
hr = S_OK;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
len = buflen + 1;
|
|
|
|
res = RegEnumValueW( hkey, i, buf, &len, NULL, &value_types[i], NULL, NULL );
|
|
|
|
if (res == ERROR_NO_MORE_ITEMS)
|
|
|
|
{
|
|
|
|
if (i) res = ERROR_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (res) break;
|
|
|
|
if (!(value_names[i] = SysAllocString( buf )))
|
|
|
|
{
|
|
|
|
for (i--; i >= 0; i--) SysFreeString( value_names[i] );
|
2016-09-13 09:03:57 +02:00
|
|
|
hr = E_OUTOFMEMORY;
|
2012-10-12 14:26:12 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (hr == S_OK && !res)
|
|
|
|
{
|
|
|
|
hr = to_bstr_array( value_names, i, names );
|
2015-04-22 12:13:55 +02:00
|
|
|
free_bstr_array( value_names, i );
|
2012-10-12 14:26:12 +02:00
|
|
|
if (hr == S_OK) hr = to_i4_array( value_types, i, types );
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
set_variant( VT_UI4, res, NULL, retval );
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
heap_free( value_names );
|
|
|
|
heap_free( value_types );
|
|
|
|
heap_free( buf );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2021-03-03 07:05:50 +01:00
|
|
|
HRESULT reg_enum_values( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
|
2012-10-12 14:26:12 +02:00
|
|
|
{
|
|
|
|
VARIANT defkey, subkey, names, types, retval;
|
2014-05-19 12:30:46 +02:00
|
|
|
IWbemClassObject *sig, *out_params = NULL;
|
2012-10-12 14:26:12 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2021-03-05 11:22:58 +01:00
|
|
|
TRACE("%p, %p, %p, %p\n", obj, context, in, out);
|
2012-10-12 14:26:12 +02:00
|
|
|
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
|
2012-10-12 14:26:12 +02:00
|
|
|
if (hr != S_OK) return hr;
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
|
2012-10-12 14:26:12 +02:00
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
2021-09-13 16:13:27 +02:00
|
|
|
hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"EnumValues", PARAM_OUT, &sig );
|
2012-10-12 14:26:12 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &subkey );
|
|
|
|
return hr;
|
|
|
|
}
|
2014-05-19 12:30:46 +02:00
|
|
|
if (out)
|
2012-10-12 14:26:12 +02:00
|
|
|
{
|
2014-05-19 12:30:46 +02:00
|
|
|
hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &subkey );
|
|
|
|
IWbemClassObject_Release( sig );
|
|
|
|
return hr;
|
|
|
|
}
|
2012-10-12 14:26:12 +02:00
|
|
|
}
|
|
|
|
VariantInit( &names );
|
|
|
|
VariantInit( &types );
|
2021-03-03 07:05:56 +01:00
|
|
|
hr = enum_values( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), &names, &types, context, &retval );
|
2012-10-12 14:26:12 +02:00
|
|
|
if (hr != S_OK) goto done;
|
2014-05-19 12:30:46 +02:00
|
|
|
if (out_params)
|
2012-10-12 14:26:12 +02: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"sNames", 0, &names, CIM_STRING|CIM_FLAG_ARRAY );
|
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"Types", 0, &types, CIM_SINT32|CIM_FLAG_ARRAY );
|
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 );
|
2012-10-12 14:26:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
VariantClear( &types );
|
|
|
|
VariantClear( &names );
|
|
|
|
VariantClear( &subkey );
|
|
|
|
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 );
|
2012-10-12 14:26:12 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2012-10-15 10:46:09 +02:00
|
|
|
|
2021-03-03 07:05:53 +01:00
|
|
|
static HRESULT get_stringvalue( HKEY root, const WCHAR *subkey, const WCHAR *name, VARIANT *value,
|
|
|
|
IWbemContext *context, VARIANT *retval )
|
2012-10-15 10:46:09 +02:00
|
|
|
{
|
2021-03-03 07:05:53 +01:00
|
|
|
DWORD size, mask, flags = RRF_RT_REG_SZ;
|
2012-10-15 10:46:09 +02:00
|
|
|
HRESULT hr = S_OK;
|
2013-05-02 12:03:02 +02:00
|
|
|
BSTR str = NULL;
|
2012-10-15 10:46:09 +02:00
|
|
|
LONG res;
|
|
|
|
|
|
|
|
TRACE("%p, %s, %s\n", root, debugstr_w(subkey), debugstr_w(name));
|
|
|
|
|
2021-03-03 07:05:53 +01:00
|
|
|
mask = reg_get_access_mask( context );
|
|
|
|
|
|
|
|
if (mask & KEY_WOW64_64KEY)
|
|
|
|
flags |= RRF_SUBKEY_WOW6464KEY;
|
|
|
|
else if (mask & KEY_WOW64_32KEY)
|
|
|
|
flags |= RRF_SUBKEY_WOW6432KEY;
|
|
|
|
|
|
|
|
if ((res = RegGetValueW( root, subkey, name, flags, NULL, NULL, &size ))) goto done;
|
2013-05-02 12:03:02 +02:00
|
|
|
if (!(str = SysAllocStringLen( NULL, size / sizeof(WCHAR) - 1 )))
|
2012-10-15 10:46:09 +02:00
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
2021-03-03 07:05:53 +01:00
|
|
|
if (!(res = RegGetValueW( root, subkey, name, flags, NULL, str, &size )))
|
2013-05-02 12:03:02 +02:00
|
|
|
set_variant( VT_BSTR, 0, str, value );
|
2012-10-15 10:46:09 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
set_variant( VT_UI4, res, NULL, retval );
|
2013-05-02 12:03:02 +02:00
|
|
|
if (res) SysFreeString( str );
|
2012-10-15 10:46:09 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2021-03-03 07:05:50 +01:00
|
|
|
HRESULT reg_get_stringvalue( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
|
2012-10-15 10:46:09 +02:00
|
|
|
{
|
|
|
|
VARIANT defkey, subkey, name, value, retval;
|
2014-05-19 12:30:46 +02:00
|
|
|
IWbemClassObject *sig, *out_params = NULL;
|
2012-10-15 10:46:09 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2021-03-05 11:22:58 +01:00
|
|
|
TRACE("%p, %p, %p, %p\n", obj, context, in, out);
|
2012-10-15 10:46:09 +02:00
|
|
|
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
|
2012-10-15 10:46:09 +02:00
|
|
|
if (hr != S_OK) return hr;
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
|
2012-10-15 10:46:09 +02:00
|
|
|
if (hr != S_OK) return hr;
|
2020-04-20 10:38:10 +02:00
|
|
|
hr = IWbemClassObject_Get( in, L"sValueName", 0, &name, NULL, NULL );
|
2021-03-05 11:22:57 +01:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &subkey );
|
|
|
|
return hr;
|
|
|
|
}
|
2012-10-15 10:46:09 +02:00
|
|
|
|
2021-09-13 16:13:27 +02:00
|
|
|
hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"GetStringValue", PARAM_OUT, &sig );
|
2012-10-15 10:46:09 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &name );
|
|
|
|
VariantClear( &subkey );
|
|
|
|
return hr;
|
|
|
|
}
|
2014-05-19 12:30:46 +02:00
|
|
|
if (out)
|
2012-10-15 10:46:09 +02:00
|
|
|
{
|
2014-05-19 12:30:46 +02:00
|
|
|
hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &name );
|
|
|
|
VariantClear( &subkey );
|
|
|
|
IWbemClassObject_Release( sig );
|
|
|
|
return hr;
|
|
|
|
}
|
2012-10-15 10:46:09 +02:00
|
|
|
}
|
|
|
|
VariantInit( &value );
|
2021-03-03 07:05:53 +01:00
|
|
|
hr = get_stringvalue( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), V_BSTR(&name), &value, context, &retval );
|
2012-10-15 10:46:09 +02:00
|
|
|
if (hr != S_OK) goto done;
|
2014-05-19 12:30:46 +02:00
|
|
|
if (out_params)
|
2012-10-15 10:46:09 +02: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"sValue", 0, &value, 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 );
|
2012-10-15 10:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
VariantClear( &name );
|
|
|
|
VariantClear( &subkey );
|
|
|
|
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 );
|
2012-10-15 10:46:09 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2021-03-01 08:14:44 +01:00
|
|
|
|
2021-03-03 07:05:57 +01:00
|
|
|
static void set_stringvalue( HKEY root, const WCHAR *subkey, const WCHAR *name, const WCHAR *value,
|
|
|
|
IWbemContext *context, VARIANT *retval )
|
2021-03-01 08:14:44 +01:00
|
|
|
{
|
2021-03-03 07:05:57 +01:00
|
|
|
HKEY hkey;
|
2021-03-01 08:14:44 +01:00
|
|
|
LONG res;
|
|
|
|
|
|
|
|
TRACE("%p, %s, %s, %s\n", root, debugstr_w(subkey), debugstr_w(name), debugstr_w(value));
|
|
|
|
|
2021-03-03 07:05:57 +01:00
|
|
|
if ((res = RegOpenKeyExW( root, subkey, 0, KEY_SET_VALUE | reg_get_access_mask( context ), &hkey )))
|
|
|
|
{
|
|
|
|
set_variant( VT_UI4, res, NULL, retval );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = RegSetKeyValueW( hkey, NULL, name, REG_SZ, value, (lstrlenW( value ) + 1) * sizeof(*value) );
|
2021-03-01 08:14:44 +01:00
|
|
|
set_variant( VT_UI4, res, NULL, retval );
|
2021-03-03 07:05:57 +01:00
|
|
|
RegCloseKey( hkey );
|
2021-03-01 08:14:44 +01:00
|
|
|
}
|
|
|
|
|
2021-03-03 07:05:50 +01:00
|
|
|
HRESULT reg_set_stringvalue( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
|
2021-03-01 08:14:44 +01:00
|
|
|
{
|
|
|
|
VARIANT defkey, subkey, name, value, retval;
|
|
|
|
IWbemClassObject *sig, *out_params = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2021-03-05 11:22:58 +01:00
|
|
|
TRACE("%p, %p, %p, %p\n", obj, context, in, out);
|
2021-03-01 08:14:44 +01:00
|
|
|
|
|
|
|
hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
hr = IWbemClassObject_Get( in, L"sValueName", 0, &name, NULL, NULL );
|
2021-03-05 11:22:57 +01:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &subkey );
|
|
|
|
return hr;
|
|
|
|
}
|
2021-03-01 08:14:44 +01:00
|
|
|
hr = IWbemClassObject_Get( in, L"sValue", 0, &value, NULL, NULL );
|
2021-03-05 11:22:57 +01:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &name );
|
|
|
|
VariantClear( &subkey );
|
|
|
|
return hr;
|
|
|
|
}
|
2021-03-01 08:14:44 +01:00
|
|
|
|
2021-09-13 16:13:27 +02:00
|
|
|
hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"SetStringValue", PARAM_OUT, &sig );
|
2021-03-01 08:14:44 +01:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &name );
|
|
|
|
VariantClear( &subkey );
|
|
|
|
VariantClear( &value );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
if (out)
|
|
|
|
{
|
|
|
|
hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &name );
|
|
|
|
VariantClear( &subkey );
|
|
|
|
VariantClear( &value );
|
|
|
|
IWbemClassObject_Release( sig );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-03 07:05:57 +01:00
|
|
|
set_stringvalue( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), V_BSTR(&name), V_BSTR(&value), context, &retval );
|
2021-03-01 08:14:44 +01:00
|
|
|
if (out_params)
|
|
|
|
hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
|
|
|
|
|
|
|
|
VariantClear( &name );
|
|
|
|
VariantClear( &subkey );
|
|
|
|
VariantClear( &value );
|
|
|
|
IWbemClassObject_Release( sig );
|
|
|
|
if (hr == S_OK && out)
|
|
|
|
{
|
|
|
|
*out = out_params;
|
|
|
|
IWbemClassObject_AddRef( out_params );
|
|
|
|
}
|
|
|
|
if (out_params) IWbemClassObject_Release( out_params );
|
|
|
|
return hr;
|
|
|
|
}
|
2021-03-01 08:14:45 +01:00
|
|
|
|
2021-03-03 07:05:58 +01:00
|
|
|
static void set_dwordvalue( HKEY root, const WCHAR *subkey, const WCHAR *name, DWORD value, IWbemContext *context,
|
|
|
|
VARIANT *retval )
|
2021-03-01 08:14:45 +01:00
|
|
|
{
|
2021-03-03 07:05:58 +01:00
|
|
|
HKEY hkey;
|
2021-03-01 08:14:45 +01:00
|
|
|
LONG res;
|
|
|
|
|
|
|
|
TRACE("%p, %s, %s, %#x\n", root, debugstr_w(subkey), debugstr_w(name), value);
|
|
|
|
|
2021-03-03 07:05:58 +01:00
|
|
|
if ((res = RegOpenKeyExW( root, subkey, 0, KEY_SET_VALUE | reg_get_access_mask( context ), &hkey )))
|
|
|
|
{
|
|
|
|
set_variant( VT_UI4, res, NULL, retval );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = RegSetKeyValueW( hkey, NULL, name, REG_DWORD, &value, sizeof(value) );
|
2021-03-01 08:14:45 +01:00
|
|
|
set_variant( VT_UI4, res, NULL, retval );
|
2021-03-03 07:05:58 +01:00
|
|
|
RegCloseKey( hkey );
|
2021-03-01 08:14:45 +01:00
|
|
|
}
|
|
|
|
|
2021-03-03 07:05:50 +01:00
|
|
|
HRESULT reg_set_dwordvalue( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
|
2021-03-01 08:14:45 +01:00
|
|
|
{
|
|
|
|
VARIANT defkey, subkey, name, value, retval;
|
|
|
|
IWbemClassObject *sig, *out_params = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2021-03-05 11:22:58 +01:00
|
|
|
TRACE("%p, %p, %p, %p\n", obj, context, in, out);
|
2021-03-01 08:14:45 +01:00
|
|
|
|
|
|
|
hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
hr = IWbemClassObject_Get( in, L"sValueName", 0, &name, NULL, NULL );
|
2021-03-05 11:22:57 +01:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &subkey );
|
|
|
|
return hr;
|
|
|
|
}
|
2021-03-01 08:14:45 +01:00
|
|
|
hr = IWbemClassObject_Get( in, L"uValue", 0, &value, NULL, NULL );
|
2021-03-05 11:22:57 +01:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &name );
|
|
|
|
VariantClear( &subkey );
|
|
|
|
return hr;
|
|
|
|
}
|
2021-03-01 08:14:45 +01:00
|
|
|
|
2021-09-13 16:13:27 +02:00
|
|
|
hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"SetDWORDValue", PARAM_OUT, &sig );
|
2021-03-01 08:14:45 +01:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &name );
|
|
|
|
VariantClear( &subkey );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
if (out)
|
|
|
|
{
|
|
|
|
hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &name );
|
|
|
|
VariantClear( &subkey );
|
|
|
|
IWbemClassObject_Release( sig );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
2021-03-03 07:05:58 +01:00
|
|
|
set_dwordvalue( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), V_BSTR(&name), V_UI4(&value), context, &retval );
|
2021-03-01 08:14:45 +01:00
|
|
|
if (out_params)
|
|
|
|
hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
|
|
|
|
|
|
|
|
VariantClear( &name );
|
|
|
|
VariantClear( &subkey );
|
|
|
|
IWbemClassObject_Release( sig );
|
|
|
|
if (hr == S_OK && out)
|
|
|
|
{
|
|
|
|
*out = out_params;
|
|
|
|
IWbemClassObject_AddRef( out_params );
|
|
|
|
}
|
|
|
|
if (out_params) IWbemClassObject_Release( out_params );
|
|
|
|
return hr;
|
|
|
|
}
|
2021-03-01 08:14:46 +01:00
|
|
|
|
2021-03-03 07:05:52 +01:00
|
|
|
static void delete_key( HKEY root, const WCHAR *subkey, IWbemContext *context, VARIANT *retval )
|
2021-03-01 08:14:46 +01:00
|
|
|
{
|
|
|
|
LONG res;
|
|
|
|
|
|
|
|
TRACE("%p, %s\n", root, debugstr_w(subkey));
|
|
|
|
|
2021-03-03 07:05:52 +01:00
|
|
|
res = RegDeleteKeyExW( root, subkey, reg_get_access_mask( context ), 0 );
|
2021-03-01 08:14:46 +01:00
|
|
|
set_variant( VT_UI4, res, NULL, retval );
|
|
|
|
}
|
|
|
|
|
2021-03-03 07:05:50 +01:00
|
|
|
HRESULT reg_delete_key( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
|
2021-03-01 08:14:46 +01:00
|
|
|
{
|
|
|
|
VARIANT defkey, subkey, retval;
|
|
|
|
IWbemClassObject *sig, *out_params = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2021-03-05 11:22:58 +01:00
|
|
|
TRACE("%p, %p, %p, %p\n", obj, context, in, out);
|
2021-03-01 08:14:46 +01:00
|
|
|
|
|
|
|
hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
2021-09-13 16:13:27 +02:00
|
|
|
hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"DeleteKey", PARAM_OUT, &sig );
|
2021-03-01 08:14:46 +01:00
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &subkey );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
if (out)
|
|
|
|
{
|
|
|
|
hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
VariantClear( &subkey );
|
|
|
|
IWbemClassObject_Release( sig );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
2021-03-03 07:05:52 +01:00
|
|
|
delete_key( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), context, &retval );
|
2021-03-01 08:14:46 +01:00
|
|
|
if (out_params)
|
|
|
|
hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
|
|
|
|
|
|
|
|
VariantClear( &subkey );
|
|
|
|
IWbemClassObject_Release( sig );
|
|
|
|
if (hr == S_OK && out)
|
|
|
|
{
|
|
|
|
*out = out_params;
|
|
|
|
IWbemClassObject_AddRef( out_params );
|
|
|
|
}
|
|
|
|
if (out_params) IWbemClassObject_Release( out_params );
|
|
|
|
return hr;
|
|
|
|
}
|