2009-07-14 12:26:38 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2009 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
|
|
|
|
*/
|
|
|
|
|
2013-02-06 13:54:06 +01:00
|
|
|
#include "wine/debug.h"
|
2012-06-15 15:46:51 +02:00
|
|
|
#include "wine/list.h"
|
|
|
|
|
2021-09-13 16:13:27 +02:00
|
|
|
enum wbm_namespace
|
|
|
|
{
|
|
|
|
WBEMPROX_NAMESPACE_CIMV2,
|
2021-09-13 16:13:29 +02:00
|
|
|
WBEMPROX_NAMESPACE_MS_WINDOWS_STORAGE,
|
2021-10-16 10:01:25 +02:00
|
|
|
WBEMPROX_NAMESPACE_WMI,
|
2021-09-13 16:13:27 +02:00
|
|
|
WBEMPROX_NAMESPACE_LAST,
|
|
|
|
};
|
|
|
|
|
2020-01-24 00:05:27 +01:00
|
|
|
extern IClientSecurity client_security DECLSPEC_HIDDEN;
|
2021-09-13 16:13:27 +02:00
|
|
|
extern struct list *table_list[WBEMPROX_NAMESPACE_LAST] DECLSPEC_HIDDEN;
|
2012-06-28 09:24:42 +02:00
|
|
|
|
2012-07-25 13:13:17 +02:00
|
|
|
enum param_direction
|
|
|
|
{
|
|
|
|
PARAM_OUT = -1,
|
|
|
|
PARAM_INOUT = 0,
|
|
|
|
PARAM_IN = 1
|
|
|
|
};
|
|
|
|
|
2012-10-12 14:25:13 +02:00
|
|
|
#define CIM_TYPE_MASK 0x00000fff
|
|
|
|
|
2012-06-19 10:21:12 +02:00
|
|
|
#define COL_TYPE_MASK 0x0000ffff
|
|
|
|
#define COL_FLAG_DYNAMIC 0x00010000
|
2012-06-20 12:06:17 +02:00
|
|
|
#define COL_FLAG_KEY 0x00020000
|
2012-07-13 11:35:09 +02:00
|
|
|
#define COL_FLAG_METHOD 0x00040000
|
|
|
|
|
2021-03-03 07:05:50 +01:00
|
|
|
typedef HRESULT (class_method)(IWbemClassObject *object, IWbemContext *context, IWbemClassObject *in_params,
|
|
|
|
IWbemClassObject **out_params);
|
2012-06-19 10:21:12 +02:00
|
|
|
|
2013-05-22 10:09:26 +02:00
|
|
|
enum operator
|
|
|
|
{
|
|
|
|
OP_EQ = 1,
|
|
|
|
OP_AND = 2,
|
|
|
|
OP_OR = 3,
|
|
|
|
OP_GT = 4,
|
|
|
|
OP_LT = 5,
|
|
|
|
OP_LE = 6,
|
|
|
|
OP_GE = 7,
|
|
|
|
OP_NE = 8,
|
|
|
|
OP_ISNULL = 9,
|
|
|
|
OP_NOTNULL = 10,
|
2014-02-28 11:23:39 +01:00
|
|
|
OP_LIKE = 11,
|
|
|
|
OP_NOT = 12
|
2013-05-22 10:09:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct expr;
|
|
|
|
struct complex_expr
|
|
|
|
{
|
|
|
|
enum operator op;
|
|
|
|
struct expr *left;
|
|
|
|
struct expr *right;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum expr_type
|
|
|
|
{
|
|
|
|
EXPR_COMPLEX = 1,
|
|
|
|
EXPR_UNARY = 2,
|
|
|
|
EXPR_PROPVAL = 3,
|
|
|
|
EXPR_SVAL = 4,
|
|
|
|
EXPR_IVAL = 5,
|
|
|
|
EXPR_BVAL = 6
|
|
|
|
};
|
|
|
|
|
|
|
|
struct expr
|
|
|
|
{
|
|
|
|
enum expr_type type;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct complex_expr expr;
|
|
|
|
const struct property *propval;
|
|
|
|
const WCHAR *sval;
|
|
|
|
int ival;
|
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
2012-06-15 15:47:28 +02:00
|
|
|
struct column
|
|
|
|
{
|
|
|
|
const WCHAR *name;
|
2012-06-19 10:21:12 +02:00
|
|
|
UINT type;
|
2012-06-15 15:47:28 +02:00
|
|
|
};
|
|
|
|
|
2013-05-22 10:09:26 +02:00
|
|
|
enum fill_status
|
|
|
|
{
|
|
|
|
FILL_STATUS_FAILED = -1,
|
|
|
|
FILL_STATUS_UNFILTERED,
|
|
|
|
FILL_STATUS_FILTERED
|
|
|
|
};
|
|
|
|
|
2012-07-13 11:35:39 +02:00
|
|
|
#define TABLE_FLAG_DYNAMIC 0x00000001
|
|
|
|
|
2012-06-15 15:47:28 +02:00
|
|
|
struct table
|
|
|
|
{
|
|
|
|
const WCHAR *name;
|
|
|
|
UINT num_cols;
|
|
|
|
const struct column *columns;
|
|
|
|
UINT num_rows;
|
2013-06-04 13:28:21 +02:00
|
|
|
UINT num_rows_allocated;
|
2012-06-15 15:47:28 +02:00
|
|
|
BYTE *data;
|
2013-05-22 10:09:26 +02:00
|
|
|
enum fill_status (*fill)(struct table *, const struct expr *cond);
|
2012-07-13 11:35:39 +02:00
|
|
|
UINT flags;
|
|
|
|
struct list entry;
|
2012-10-10 12:01:44 +02:00
|
|
|
LONG refs;
|
2012-06-15 15:47:28 +02:00
|
|
|
};
|
|
|
|
|
2012-06-15 15:46:51 +02:00
|
|
|
struct property
|
|
|
|
{
|
|
|
|
const WCHAR *name;
|
|
|
|
const WCHAR *class;
|
|
|
|
const struct property *next;
|
|
|
|
};
|
|
|
|
|
2012-10-10 12:03:10 +02:00
|
|
|
struct array
|
|
|
|
{
|
2019-08-27 16:35:55 +02:00
|
|
|
UINT elem_size;
|
2012-10-10 12:03:10 +02:00
|
|
|
UINT count;
|
|
|
|
void *ptr;
|
|
|
|
};
|
|
|
|
|
2012-09-06 14:03:50 +02:00
|
|
|
struct field
|
|
|
|
{
|
|
|
|
UINT type;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
LONGLONG ival;
|
|
|
|
WCHAR *sval;
|
2012-10-10 12:03:10 +02:00
|
|
|
struct array *aval;
|
2012-09-06 14:03:50 +02:00
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct record
|
|
|
|
{
|
|
|
|
UINT count;
|
|
|
|
struct field *fields;
|
2012-10-17 11:06:41 +02:00
|
|
|
struct table *table;
|
2012-09-06 14:03:50 +02:00
|
|
|
};
|
|
|
|
|
2019-06-24 15:15:35 +02:00
|
|
|
struct keyword
|
|
|
|
{
|
|
|
|
const WCHAR *name;
|
|
|
|
const WCHAR *value;
|
|
|
|
const struct keyword *next;
|
|
|
|
};
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
enum view_type
|
|
|
|
{
|
|
|
|
VIEW_TYPE_SELECT,
|
|
|
|
VIEW_TYPE_ASSOCIATORS,
|
|
|
|
};
|
|
|
|
|
2012-06-15 15:46:51 +02:00
|
|
|
struct view
|
|
|
|
{
|
2021-09-13 16:13:27 +02:00
|
|
|
enum wbm_namespace ns;
|
2019-09-10 17:09:14 +02:00
|
|
|
enum view_type type;
|
2019-06-24 15:15:35 +02:00
|
|
|
const WCHAR *path; /* ASSOCIATORS OF query */
|
|
|
|
const struct keyword *keywordlist;
|
2019-09-10 17:09:14 +02:00
|
|
|
const struct property *proplist; /* SELECT query */
|
2012-06-15 15:46:51 +02:00
|
|
|
const struct expr *cond;
|
2019-09-10 17:09:14 +02:00
|
|
|
UINT table_count;
|
|
|
|
struct table **table;
|
|
|
|
UINT result_count;
|
2012-06-15 15:47:54 +02:00
|
|
|
UINT *result;
|
2012-06-15 15:46:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct query
|
|
|
|
{
|
2012-06-28 09:25:13 +02:00
|
|
|
LONG refs;
|
2021-09-13 16:13:27 +02:00
|
|
|
enum wbm_namespace ns;
|
2012-06-15 15:46:51 +02:00
|
|
|
struct view *view;
|
|
|
|
struct list mem;
|
|
|
|
};
|
|
|
|
|
2019-09-10 17:09:14 +02:00
|
|
|
struct path
|
|
|
|
{
|
|
|
|
WCHAR *class;
|
|
|
|
UINT class_len;
|
|
|
|
WCHAR *filter;
|
|
|
|
UINT filter_len;
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT parse_path( const WCHAR *, struct path ** ) DECLSPEC_HIDDEN;
|
|
|
|
void free_path( struct path * ) DECLSPEC_HIDDEN;
|
|
|
|
WCHAR *query_from_path( const struct path * ) DECLSPEC_HIDDEN;
|
|
|
|
|
2021-09-13 16:13:27 +02:00
|
|
|
struct query *create_query( enum wbm_namespace ) DECLSPEC_HIDDEN;
|
2013-06-04 13:27:48 +02:00
|
|
|
void free_query( struct query * ) DECLSPEC_HIDDEN;
|
2012-10-17 11:06:41 +02:00
|
|
|
struct query *addref_query( struct query * ) DECLSPEC_HIDDEN;
|
2012-06-28 09:25:13 +02:00
|
|
|
void release_query( struct query *query ) DECLSPEC_HIDDEN;
|
2021-09-13 16:13:27 +02:00
|
|
|
HRESULT exec_query( enum wbm_namespace, const WCHAR *, IEnumWbemClassObject ** ) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT parse_query( enum wbm_namespace, const WCHAR *, struct view **, struct list * ) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT create_view( enum view_type, enum wbm_namespace, const WCHAR *, const struct keyword *, const WCHAR *,
|
|
|
|
const struct property *, const struct expr *, struct view ** ) DECLSPEC_HIDDEN;
|
2012-06-15 15:46:51 +02:00
|
|
|
void destroy_view( struct view * ) DECLSPEC_HIDDEN;
|
2013-06-04 13:27:48 +02:00
|
|
|
HRESULT execute_view( struct view * ) DECLSPEC_HIDDEN;
|
2019-09-10 17:09:14 +02:00
|
|
|
struct table *get_view_table( const struct view *, UINT ) DECLSPEC_HIDDEN;
|
2012-07-13 11:35:39 +02:00
|
|
|
void init_table_list( void ) DECLSPEC_HIDDEN;
|
2021-09-13 16:13:27 +02:00
|
|
|
enum wbm_namespace get_namespace_from_string( const WCHAR *namespace ) DECLSPEC_HIDDEN;
|
|
|
|
struct table *grab_table( enum wbm_namespace, const WCHAR * ) DECLSPEC_HIDDEN;
|
2012-10-17 11:06:41 +02:00
|
|
|
struct table *addref_table( struct table * ) DECLSPEC_HIDDEN;
|
2012-10-10 12:01:44 +02:00
|
|
|
void release_table( struct table * ) DECLSPEC_HIDDEN;
|
2013-06-04 13:28:21 +02:00
|
|
|
struct table *create_table( const WCHAR *, UINT, const struct column *, UINT, UINT, BYTE *,
|
2013-05-22 10:09:26 +02:00
|
|
|
enum fill_status (*)(struct table *, const struct expr *) ) DECLSPEC_HIDDEN;
|
2021-09-13 16:13:27 +02:00
|
|
|
BOOL add_table( enum wbm_namespace, struct table * ) DECLSPEC_HIDDEN;
|
2012-07-13 11:35:39 +02:00
|
|
|
void free_columns( struct column *, UINT ) DECLSPEC_HIDDEN;
|
2013-05-22 10:10:16 +02:00
|
|
|
void free_row_values( const struct table *, UINT ) DECLSPEC_HIDDEN;
|
2013-05-22 10:08:17 +02:00
|
|
|
void clear_table( struct table * ) DECLSPEC_HIDDEN;
|
2012-07-13 11:35:39 +02:00
|
|
|
void free_table( struct table * ) DECLSPEC_HIDDEN;
|
2012-07-25 13:13:17 +02:00
|
|
|
UINT get_type_size( CIMTYPE ) DECLSPEC_HIDDEN;
|
2014-01-28 13:26:16 +01:00
|
|
|
HRESULT eval_cond( const struct table *, UINT, const struct expr *, LONGLONG *, UINT * ) DECLSPEC_HIDDEN;
|
2012-07-13 11:35:39 +02:00
|
|
|
HRESULT get_column_index( const struct table *, const WCHAR *, UINT * ) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT get_value( const struct table *, UINT, UINT, LONGLONG * ) DECLSPEC_HIDDEN;
|
|
|
|
BSTR get_value_bstr( const struct table *, UINT, UINT ) DECLSPEC_HIDDEN;
|
2012-07-25 13:12:10 +02:00
|
|
|
HRESULT set_value( const struct table *, UINT, UINT, LONGLONG, CIMTYPE ) DECLSPEC_HIDDEN;
|
2014-04-30 10:19:30 +02:00
|
|
|
BOOL is_method( const struct table *, UINT ) DECLSPEC_HIDDEN;
|
2012-09-28 13:37:21 +02:00
|
|
|
HRESULT get_method( const struct table *, const WCHAR *, class_method ** ) DECLSPEC_HIDDEN;
|
2019-09-10 17:09:14 +02:00
|
|
|
HRESULT get_propval( const struct view *, UINT, const WCHAR *, VARIANT *, CIMTYPE *, LONG * ) DECLSPEC_HIDDEN;
|
2012-07-25 13:12:10 +02:00
|
|
|
HRESULT put_propval( const struct view *, UINT, const WCHAR *, VARIANT *, CIMTYPE ) DECLSPEC_HIDDEN;
|
2012-10-10 12:03:10 +02:00
|
|
|
HRESULT to_longlong( VARIANT *, LONGLONG *, CIMTYPE * ) DECLSPEC_HIDDEN;
|
|
|
|
SAFEARRAY *to_safearray( const struct array *, CIMTYPE ) DECLSPEC_HIDDEN;
|
2012-10-12 14:25:39 +02:00
|
|
|
VARTYPE to_vartype( CIMTYPE ) DECLSPEC_HIDDEN;
|
2012-10-12 14:25:13 +02:00
|
|
|
void destroy_array( struct array *, CIMTYPE ) DECLSPEC_HIDDEN;
|
2019-09-10 17:09:14 +02:00
|
|
|
BOOL is_result_prop( const struct view *, const WCHAR * ) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT get_properties( const struct view *, UINT, LONG, SAFEARRAY ** ) DECLSPEC_HIDDEN;
|
2021-09-13 16:13:27 +02:00
|
|
|
HRESULT get_object( enum wbm_namespace ns, const WCHAR *, IWbemClassObject ** ) DECLSPEC_HIDDEN;
|
|
|
|
BSTR get_method_name( enum wbm_namespace ns, const WCHAR *, UINT ) DECLSPEC_HIDDEN;
|
2012-10-12 14:26:12 +02:00
|
|
|
void set_variant( VARTYPE, LONGLONG, void *, VARIANT * ) DECLSPEC_HIDDEN;
|
2021-09-13 16:13:27 +02:00
|
|
|
HRESULT create_signature( enum wbm_namespace ns, const WCHAR *, const WCHAR *, enum param_direction,
|
2012-10-12 14:26:12 +02:00
|
|
|
IWbemClassObject ** ) DECLSPEC_HIDDEN;
|
2012-06-15 15:46:51 +02:00
|
|
|
|
2013-12-30 10:21:36 +01:00
|
|
|
HRESULT WbemLocator_create(LPVOID *) DECLSPEC_HIDDEN;
|
2021-03-03 07:05:48 +01:00
|
|
|
HRESULT WbemServices_create(const WCHAR *, IWbemContext *, LPVOID *) DECLSPEC_HIDDEN;
|
2021-02-23 21:06:33 +01:00
|
|
|
HRESULT WbemContext_create(void **) DECLSPEC_HIDDEN;
|
2021-09-13 16:13:27 +02:00
|
|
|
HRESULT create_class_object(enum wbm_namespace ns, const WCHAR *, IEnumWbemClassObject *, UINT,
|
2012-09-06 14:03:50 +02:00
|
|
|
struct record *, IWbemClassObject **) DECLSPEC_HIDDEN;
|
2013-12-30 10:21:36 +01:00
|
|
|
HRESULT EnumWbemClassObject_create(struct query *, LPVOID *) DECLSPEC_HIDDEN;
|
2021-09-13 16:13:27 +02:00
|
|
|
HRESULT WbemQualifierSet_create(enum wbm_namespace, const WCHAR *, const WCHAR *, LPVOID *) DECLSPEC_HIDDEN;
|
2012-06-14 16:03:26 +02:00
|
|
|
|
2021-03-03 07:05:50 +01:00
|
|
|
HRESULT process_get_owner(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
2021-05-18 09:49:45 +02:00
|
|
|
HRESULT process_create(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
2021-03-03 07:05:50 +01:00
|
|
|
HRESULT reg_create_key(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT reg_enum_key(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT reg_enum_values(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT reg_get_stringvalue(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT reg_set_stringvalue(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT reg_set_dwordvalue(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT reg_delete_key(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT service_pause_service(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT service_resume_service(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT service_start_service(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT service_stop_service(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT security_get_sd(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT security_set_sd(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
2021-03-05 11:22:59 +01:00
|
|
|
HRESULT sysrestore_create(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT sysrestore_disable(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT sysrestore_enable(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT sysrestore_get_last_status(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT sysrestore_restore(IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out) DECLSPEC_HIDDEN;
|
2012-10-12 14:26:12 +02:00
|
|
|
|
2019-08-27 16:35:56 +02:00
|
|
|
static inline WCHAR *heap_strdupAW( const char *src )
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
WCHAR *dst;
|
|
|
|
if (!src) return NULL;
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, src, -1, NULL, 0 );
|
2022-01-31 14:49:43 +01:00
|
|
|
if ((dst = malloc( len * sizeof(*dst) ))) MultiByteToWideChar( CP_ACP, 0, src, -1, dst, len );
|
2019-08-27 16:35:56 +02:00
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2020-02-07 15:06:58 +01:00
|
|
|
static inline BOOL is_digit(WCHAR c)
|
|
|
|
{
|
|
|
|
return '0' <= c && c <= '9';
|
|
|
|
}
|