wbemprox_private.h 10.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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
 */

19
#include "wine/debug.h"
20
#include "wine/heap.h"
21 22
#include "wine/list.h"

23 24
IClientSecurity client_security DECLSPEC_HIDDEN;
struct list *table_list DECLSPEC_HIDDEN;
25

26 27 28 29 30 31 32
enum param_direction
{
    PARAM_OUT   = -1,
    PARAM_INOUT = 0,
    PARAM_IN    = 1
};

33 34
#define CIM_TYPE_MASK    0x00000fff

35 36
#define COL_TYPE_MASK    0x0000ffff
#define COL_FLAG_DYNAMIC 0x00010000
37
#define COL_FLAG_KEY     0x00020000
38 39
#define COL_FLAG_METHOD  0x00040000

40
typedef HRESULT (class_method)(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **);
41

42 43 44 45 46 47 48 49 50 51 52 53
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,
54 55
    OP_LIKE    = 11,
    OP_NOT     = 12
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
};

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;
};

88 89 90
struct column
{
    const WCHAR *name;
91
    UINT type;
92 93
};

94 95 96 97 98 99 100
enum fill_status
{
    FILL_STATUS_FAILED = -1,
    FILL_STATUS_UNFILTERED,
    FILL_STATUS_FILTERED
};

101 102
#define TABLE_FLAG_DYNAMIC 0x00000001

103 104 105 106 107 108
struct table
{
    const WCHAR *name;
    UINT num_cols;
    const struct column *columns;
    UINT num_rows;
109
    UINT num_rows_allocated;
110
    BYTE *data;
111
    enum fill_status (*fill)(struct table *, const struct expr *cond);
112 113
    UINT flags;
    struct list entry;
114
    LONG refs;
115 116
};

117 118 119 120 121 122 123
struct property
{
    const WCHAR *name;
    const WCHAR *class;
    const struct property *next;
};

124 125
struct array
{
126
    UINT elem_size;
127 128 129 130
    UINT count;
    void *ptr;
};

131 132 133 134 135 136 137
struct field
{
    UINT type;
    union
    {
        LONGLONG ival;
        WCHAR *sval;
138
        struct array *aval;
139 140 141 142 143 144 145
    } u;
};

struct record
{
    UINT count;
    struct field *fields;
146
    struct table *table;
147 148
};

149 150 151 152 153 154 155
struct keyword
{
    const WCHAR *name;
    const WCHAR *value;
    const struct keyword *next;
};

156 157 158 159 160 161
enum view_type
{
    VIEW_TYPE_SELECT,
    VIEW_TYPE_ASSOCIATORS,
};

162 163
struct view
{
164
    enum view_type type;
165 166
    const WCHAR *path;                      /* ASSOCIATORS OF query */
    const struct keyword *keywordlist;
167
    const struct property *proplist;        /* SELECT query */
168
    const struct expr *cond;
169 170 171
    UINT table_count;
    struct table **table;
    UINT result_count;
172
    UINT *result;
173 174 175 176
};

struct query
{
177
    LONG refs;
178 179 180 181
    struct view *view;
    struct list mem;
};

182 183 184 185 186 187 188 189 190 191 192 193
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;

194 195
struct query *create_query(void) DECLSPEC_HIDDEN;
void free_query( struct query * ) DECLSPEC_HIDDEN;
196
struct query *addref_query( struct query * ) DECLSPEC_HIDDEN;
197
void release_query( struct query *query ) DECLSPEC_HIDDEN;
198 199
HRESULT exec_query( const WCHAR *, IEnumWbemClassObject ** ) DECLSPEC_HIDDEN;
HRESULT parse_query( const WCHAR *, struct view **, struct list * ) DECLSPEC_HIDDEN;
200
HRESULT create_view( enum view_type, const WCHAR *, const struct keyword *, const WCHAR *, const struct property *,
201
                     const struct expr *, struct view ** ) DECLSPEC_HIDDEN;
202
void destroy_view( struct view * ) DECLSPEC_HIDDEN;
203
HRESULT execute_view( struct view * ) DECLSPEC_HIDDEN;
204
struct table *get_view_table( const struct view *, UINT ) DECLSPEC_HIDDEN;
205
void init_table_list( void ) DECLSPEC_HIDDEN;
206
struct table *grab_table( const WCHAR * ) DECLSPEC_HIDDEN;
207
struct table *addref_table( struct table * ) DECLSPEC_HIDDEN;
208
void release_table( struct table * ) DECLSPEC_HIDDEN;
209
struct table *create_table( const WCHAR *, UINT, const struct column *, UINT, UINT, BYTE *,
210
                            enum fill_status (*)(struct table *, const struct expr *) ) DECLSPEC_HIDDEN;
211 212
BOOL add_table( struct table * ) DECLSPEC_HIDDEN;
void free_columns( struct column *, UINT ) DECLSPEC_HIDDEN;
213
void free_row_values( const struct table *, UINT ) DECLSPEC_HIDDEN;
214
void clear_table( struct table * ) DECLSPEC_HIDDEN;
215
void free_table( struct table * ) DECLSPEC_HIDDEN;
216
UINT get_type_size( CIMTYPE ) DECLSPEC_HIDDEN;
217
HRESULT eval_cond( const struct table *, UINT, const struct expr *, LONGLONG *, UINT * ) DECLSPEC_HIDDEN;
218 219 220
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;
221
HRESULT set_value( const struct table *, UINT, UINT, LONGLONG, CIMTYPE ) DECLSPEC_HIDDEN;
222
BOOL is_method( const struct table *, UINT ) DECLSPEC_HIDDEN;
223
HRESULT get_method( const struct table *, const WCHAR *, class_method ** ) DECLSPEC_HIDDEN;
224
HRESULT get_propval( const struct view *, UINT, const WCHAR *, VARIANT *, CIMTYPE *, LONG * ) DECLSPEC_HIDDEN;
225
HRESULT put_propval( const struct view *, UINT, const WCHAR *, VARIANT *, CIMTYPE ) DECLSPEC_HIDDEN;
226 227
HRESULT to_longlong( VARIANT *, LONGLONG *, CIMTYPE * ) DECLSPEC_HIDDEN;
SAFEARRAY *to_safearray( const struct array *, CIMTYPE ) DECLSPEC_HIDDEN;
228
VARTYPE to_vartype( CIMTYPE ) DECLSPEC_HIDDEN;
229
void destroy_array( struct array *, CIMTYPE ) DECLSPEC_HIDDEN;
230 231
BOOL is_result_prop( const struct view *, const WCHAR * ) DECLSPEC_HIDDEN;
HRESULT get_properties( const struct view *, UINT, LONG, SAFEARRAY ** ) DECLSPEC_HIDDEN;
232
HRESULT get_object( const WCHAR *, IWbemClassObject ** ) DECLSPEC_HIDDEN;
233
BSTR get_method_name( const WCHAR *, UINT ) DECLSPEC_HIDDEN;
234 235 236
void set_variant( VARTYPE, LONGLONG, void *, VARIANT * ) DECLSPEC_HIDDEN;
HRESULT create_signature( const WCHAR *, const WCHAR *, enum param_direction,
                          IWbemClassObject ** ) DECLSPEC_HIDDEN;
237

238 239
HRESULT WbemLocator_create(LPVOID *) DECLSPEC_HIDDEN;
HRESULT WbemServices_create(const WCHAR *, LPVOID *) DECLSPEC_HIDDEN;
240
HRESULT create_class_object(const WCHAR *, IEnumWbemClassObject *, UINT,
241
                            struct record *, IWbemClassObject **) DECLSPEC_HIDDEN;
242 243
HRESULT EnumWbemClassObject_create(struct query *, LPVOID *) DECLSPEC_HIDDEN;
HRESULT WbemQualifierSet_create(const WCHAR *, const WCHAR *, LPVOID *) DECLSPEC_HIDDEN;
244

245
HRESULT process_get_owner(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
246
HRESULT reg_create_key(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
247 248 249
HRESULT reg_enum_key(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
HRESULT reg_enum_values(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
HRESULT reg_get_stringvalue(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
250
HRESULT service_pause_service(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
251
HRESULT service_resume_service(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
252
HRESULT service_start_service(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
253
HRESULT service_stop_service(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
254
HRESULT security_get_sd(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
255
HRESULT security_set_sd(IWbemClassObject *, IWbemClassObject *, IWbemClassObject **) DECLSPEC_HIDDEN;
256

257 258 259 260
static inline WCHAR *heap_strdupW( const WCHAR *src )
{
    WCHAR *dst;
    if (!src) return NULL;
261
    if ((dst = heap_alloc( (lstrlenW( src ) + 1) * sizeof(WCHAR) ))) lstrcpyW( dst, src );
262 263
    return dst;
}
264

265 266 267 268 269 270 271 272 273 274
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 );
    if ((dst = heap_alloc( len * sizeof(*dst) ))) MultiByteToWideChar( CP_ACP, 0, src, -1, dst, len );
    return dst;
}

275
static const WCHAR class_processW[] = {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
276
static const WCHAR class_serviceW[] = {'W','i','n','3','2','_','S','e','r','v','i','c','e',0};
277
static const WCHAR class_stdregprovW[] = {'S','t','d','R','e','g','P','r','o','v',0};
278
static const WCHAR class_systemsecurityW[] = {'_','_','S','y','s','t','e','m','S','e','c','u','r','i','t','y',0};
279

280 281
static const WCHAR prop_nameW[] = {'N','a','m','e',0};

282
static const WCHAR method_createkeyW[] = {'C','r','e','a','t','e','K','e','y',0};
283 284
static const WCHAR method_enumkeyW[] = {'E','n','u','m','K','e','y',0};
static const WCHAR method_enumvaluesW[] = {'E','n','u','m','V','a','l','u','e','s',0};
285
static const WCHAR method_getownerW[] = {'G','e','t','O','w','n','e','r',0};
286
static const WCHAR method_getsdW[] = {'G','e','t','S','D',0};
287
static const WCHAR method_getstringvalueW[] = {'G','e','t','S','t','r','i','n','g','V','a','l','u','e',0};
288
static const WCHAR method_pauseserviceW[] = {'P','a','u','s','e','S','e','r','v','i','c','e',0};
289
static const WCHAR method_resumeserviceW[] = {'R','e','s','u','m','e','S','e','r','v','i','c','e',0};
290
static const WCHAR method_setsdW[] = {'S','e','t','S','D',0};
291
static const WCHAR method_startserviceW[] = {'S','t','a','r','t','S','e','r','v','i','c','e',0};
292
static const WCHAR method_stopserviceW[] = {'S','t','o','p','S','e','r','v','i','c','e',0};
293 294

static const WCHAR param_defkeyW[] = {'h','D','e','f','K','e','y',0};
295
static const WCHAR param_domainW[] = {'D','o','m','a','i','n',0};
296 297
static const WCHAR param_namesW[] = {'s','N','a','m','e','s',0};
static const WCHAR param_returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
298
static const WCHAR param_sdW[] = {'S','D',0};
299 300
static const WCHAR param_subkeynameW[] = {'s','S','u','b','K','e','y','N','a','m','e',0};
static const WCHAR param_typesW[] = {'T','y','p','e','s',0};
301
static const WCHAR param_userW[] = {'U','s','e','r',0};
302 303
static const WCHAR param_valueW[] = {'s','V','a','l','u','e',0};
static const WCHAR param_valuenameW[] = {'s','V','a','l','u','e','N','a','m','e',0};