builtin.c 119 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * 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
20 21
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
22 23 24

#include "config.h"
#include <stdarg.h>
25
#include <fcntl.h>
26 27 28
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
29 30 31
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
32

33 34
#include "ntstatus.h"
#define WIN32_NO_STATUS
35 36
#include "windef.h"
#include "winbase.h"
37 38 39 40 41 42 43 44 45 46 47
#ifdef __MINGW32__
# include "winsock2.h"
# include "ws2tcpip.h"
# define WS_AF_UNSPEC AF_UNSPEC
# define WS_NI_MAXHOST NI_MAXHOST
# define WS_NI_NAMEREQD NI_NAMEREQD
#else
# define USE_WS_PREFIX
# include "winsock2.h"
# include "ws2tcpip.h"
#endif
48
#include "initguid.h"
49
#include "wbemcli.h"
50
#include "wbemprov.h"
51
#include "iphlpapi.h"
52
#include "tlhelp32.h"
53
#include "d3d10.h"
54
#include "winternl.h"
55
#include "winioctl.h"
56
#include "winsvc.h"
57
#include "winver.h"
58 59
#include "sddl.h"
#include "ntsecapi.h"
60
#include "winspool.h"
61 62 63 64 65 66

#include "wine/debug.h"
#include "wbemprox_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);

67 68
static const WCHAR class_baseboardW[] =
    {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
69 70
static const WCHAR class_biosW[] =
    {'W','i','n','3','2','_','B','I','O','S',0};
71 72
static const WCHAR class_cdromdriveW[] =
    {'W','i','n','3','2','_','C','D','R','O','M','D','r','i','v','e',0};
73 74
static const WCHAR class_compsysW[] =
    {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
75 76
static const WCHAR class_compsysproductW[] =
    {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m','P','r','o','d','u','c','t',0};
77 78
static const WCHAR class_datafileW[] =
    {'C','I','M','_','D','a','t','a','F','i','l','e',0};
79 80
static const WCHAR class_desktopmonitorW[] =
    {'W','i','n','3','2','_','D','e','s','k','t','o','p','M','o','n','i','t','o','r',0};
81 82
static const WCHAR class_directoryW[] =
    {'W','i','n','3','2','_','D','i','r','e','c','t','o','r','y',0};
83 84
static const WCHAR class_diskdriveW[] =
    {'W','i','n','3','2','_','D','i','s','k','D','r','i','v','e',0};
85 86
static const WCHAR class_diskpartitionW[] =
    {'W','i','n','3','2','_','D','i','s','k','P','a','r','t','i','t','i','o','n',0};
87 88
static const WCHAR class_ip4routetableW[] =
    {'W','i','n','3','2','_','I','P','4','R','o','u','t','e','T','a','b','l','e',0};
89 90
static const WCHAR class_logicaldiskW[] =
    {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
91 92
static const WCHAR class_logicaldisk2W[] =
    {'C','I','M','_','L','o','g','i','c','a','l','D','i','s','k',0};
93 94
static const WCHAR class_networkadapterW[] =
    {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
95 96 97
static const WCHAR class_networkadapterconfigW[] =
    {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',
     'C','o','n','f','i','g','u','r','a','t','i','o','n',0};
98 99
static const WCHAR class_osW[] =
    {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
100 101
static const WCHAR class_paramsW[] =
    {'_','_','P','A','R','A','M','E','T','E','R','S',0};
102 103
static const WCHAR class_physicalmediaW[] =
    {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','d','i','a',0};
104 105
static const WCHAR class_physicalmemoryW[] =
    {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
106 107
static const WCHAR class_printerW[] =
    {'W','i','n','3','2','_','P','r','i','n','t','e','r',0};
108 109 110
static const WCHAR class_process_getowner_outW[] =
    {'_','_','W','I','N','3','2','_','P','R','O','C','E','S','S','_','G','E','T','O','W',
     'N','E','R','_','O','U','T',0};
111 112
static const WCHAR class_processorW[] =
    {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
113 114
static const WCHAR class_processor2W[] =
    {'C','I','M','_','P','r','o','c','e','s','s','o','r',0};
115 116
static const WCHAR class_qualifiersW[] =
    {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
117 118
static const WCHAR class_sidW[] =
    {'W','i','n','3','2','_','S','I','D',0};
119 120
static const WCHAR class_sounddeviceW[] =
    {'W','i','n','3','2','_','S','o','u','n','d','D','e','v','i','c','e',0};
121 122
static const WCHAR class_systemenclosureW[] =
    {'W','i','n','3','2','_','S','y','s','t','e','m','E','n','c','l','o','s','u','r','e',0};
123 124
static const WCHAR class_videocontrollerW[] =
    {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
125

126 127
static const WCHAR prop_accountnameW[] =
    {'A','c','c','o','u','n','t','N','a','m','e',0};
128 129 130 131
static const WCHAR prop_acceptpauseW[] =
    {'A','c','c','e','p','t','P','a','u','s','e',0};
static const WCHAR prop_acceptstopW[] =
    {'A','c','c','e','p','t','S','t','o','p',0};
132 133
static const WCHAR prop_accessmaskW[] =
    {'A','c','c','e','s','s','M','a','s','k',0};
134 135
static const WCHAR prop_adapterdactypeW[] =
    {'A','d','a','p','t','e','r','D','A','C','T','y','p','e',0};
136 137
static const WCHAR prop_adapterramW[] =
    {'A','d','a','p','t','e','r','R','A','M',0};
138 139
static const WCHAR prop_adaptertypeW[] =
    {'A','d','a','p','t','e','r','T','y','p','e',0};
140 141
static const WCHAR prop_addresswidthW[] =
    {'A','d','d','r','e','s','s','W','i','d','t','h',0};
142 143
static const WCHAR prop_attributesW[] =
    {'A','t','t','r','i','b','u','t','e','s',0};
144 145
static const WCHAR prop_availabilityW[] =
    {'A','v','a','i','l','a','b','i','l','i','t','y',0};
146 147
static const WCHAR prop_binaryrepresentationW[] =
    {'B','i','n','a','r','y','R','e','p','r','e','s','e','n','t','a','t','i','o','n',0};
148 149
static const WCHAR prop_bootableW[] =
    {'B','o','o','t','a','b','l','e',0};
150 151
static const WCHAR prop_bootpartitionW[] =
    {'B','o','o','t','P','a','r','t','i','t','i','o','n',0};
152 153
static const WCHAR prop_buildnumberW[] =
    {'B','u','i','l','d','N','u','m','b','e','r',0};
154 155
static const WCHAR prop_capacityW[] =
    {'C','a','p','a','c','i','t','y',0};
156 157
static const WCHAR prop_captionW[] =
    {'C','a','p','t','i','o','n',0};
158 159
static const WCHAR prop_chassistypesW[] =
    {'C','h','a','s','s','i','s','T','y','p','e','s',0};
160 161
static const WCHAR prop_classW[] =
    {'C','l','a','s','s',0};
162 163
static const WCHAR prop_codesetW[] =
    {'C','o','d','e','S','e','t',0};
164 165
static const WCHAR prop_commandlineW[] =
    {'C','o','m','m','a','n','d','L','i','n','e',0};
166 167
static const WCHAR prop_countrycodeW[] =
    {'C','o','u','n','t','r','y','C','o','d','e',0};
168 169
static const WCHAR prop_cpustatusW[] =
    {'C','p','u','S','t','a','t','u','s',0};
170 171
static const WCHAR prop_csdversionW[] =
    {'C','S','D','V','e','r','s','i','o','n',0};
172 173
static const WCHAR prop_currentbitsperpixelW[] =
    {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
174 175
static const WCHAR prop_currentclockspeedW[] =
    {'C','u','r','r','e','n','t','C','l','o','c','k','S','p','e','e','d',0};
176 177
static const WCHAR prop_currenthorizontalresW[] =
    {'C','u','r','r','e','n','t','H','o','r','i','z','o','n','t','a','l','R','e','s','o','l','u','t','i','o','n',0};
178 179 180 181
static const WCHAR prop_currentrefreshrateW[] =
    {'C','u','r','r','e','n','t','R','e','f','r','e','s','h','R','a','t','e',0};
static const WCHAR prop_currentscanmodeW[] =
    {'C','u','r','r','e','n','t','S','c','a','n','M','o','d','e',0};
182 183
static const WCHAR prop_currentverticalresW[] =
    {'C','u','r','r','e','n','t','V','e','r','t','i','c','a','l','R','e','s','o','l','u','t','i','o','n',0};
184 185
static const WCHAR prop_datawidthW[] =
    {'D','a','t','a','W','i','d','t','h',0};
186 187
static const WCHAR prop_defaultipgatewayW[] =
    {'D','e','f','a','u','l','t','I','P','G','a','t','e','w','a','y',0};
188 189
static const WCHAR prop_defaultvalueW[] =
    {'D','e','f','a','u','l','t','V','a','l','u','e',0};
190 191
static const WCHAR prop_descriptionW[] =
    {'D','e','s','c','r','i','p','t','i','o','n',0};
192 193
static const WCHAR prop_destinationW[] =
    {'D','e','s','t','i','n','a','t','i','o','n',0};
194 195
static const WCHAR prop_deviceidW[] =
    {'D','e','v','i','c','e','I','d',0};
196 197
static const WCHAR prop_dhcpenabledW[] =
    {'D','H','C','P','E','n','a','b','l','e','d',0};
198 199
static const WCHAR prop_directionW[] =
    {'D','i','r','e','c','t','i','o','n',0};
200 201
static const WCHAR prop_displaynameW[] =
    {'D','i','s','p','l','a','y','N','a','m','e',0};
202 203
static const WCHAR prop_diskindexW[] =
    {'D','i','s','k','I','n','d','e','x',0};
204 205
static const WCHAR prop_dnshostnameW[] =
    {'D','N','S','H','o','s','t','N','a','m','e',0};
206 207
static const WCHAR prop_dnsserversearchorderW[] =
    {'D','N','S','S','e','r','v','e','r','S','e','a','r','c','h','O','r','d','e','r',0};
208 209
static const WCHAR prop_domainW[] =
    {'D','o','m','a','i','n',0};
210 211
static const WCHAR prop_domainroleW[] =
    {'D','o','m','a','i','n','R','o','l','e',0};
212 213
static const WCHAR prop_driveW[] =
    {'D','r','i','v','e',0};
214 215
static const WCHAR prop_drivernameW[] =
    {'D','r','i','v','e','r','N','a','m','e',0};
216 217
static const WCHAR prop_driverversionW[] =
    {'D','r','i','v','e','r','V','e','r','s','i','o','n',0};
218 219
static const WCHAR prop_drivetypeW[] =
    {'D','r','i','v','e','T','y','p','e',0};
220 221
static const WCHAR prop_familyW[] =
    {'F','a','m','i','l','y',0};
222 223
static const WCHAR prop_filesystemW[] =
    {'F','i','l','e','S','y','s','t','e','m',0};
224 225
static const WCHAR prop_flavorW[] =
    {'F','l','a','v','o','r',0};
226 227
static const WCHAR prop_freespaceW[] =
    {'F','r','e','e','S','p','a','c','e',0};
228 229
static const WCHAR prop_handleW[] =
    {'H','a','n','d','l','e',0};
230 231
static const WCHAR prop_horizontalresolutionW[] =
    {'H','o','r','i','z','o','n','t','a','l','R','e','s','o','l','u','t','i','o','n',0};
232 233
static const WCHAR prop_idW[] =
    {'I','D',0};
234 235
static const WCHAR prop_identificationcodeW[] =
    {'I','d','e','n','t','i','f','i','c','a','t','i','o','n','C','o','d','e',0};
236 237
static const WCHAR prop_identifyingnumberW[] =
    {'I','d','e','n','t','i','f','y','i','n','g','N','u','m','b','e','r',0};
238 239
static const WCHAR prop_indexW[] =
    {'I','n','d','e','x',0};
240 241
static const WCHAR prop_installdateW[] =
    {'I','n','s','t','a','l','l','D','a','t','e',0};
242 243
static const WCHAR prop_interfaceindexW[] =
    {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
244 245
static const WCHAR prop_interfacetypeW[] =
    {'I','n','t','e','r','f','a','c','e','T','y','p','e',0};
246 247
static const WCHAR prop_intvalueW[] =
    {'I','n','t','e','g','e','r','V','a','l','u','e',0};
248 249
static const WCHAR prop_ipconnectionmetricW[] =
    {'I','P','C','o','n','n','e','c','t','i','o','n','M','e','t','r','i','c',0};
250 251
static const WCHAR prop_ipenabledW[] =
    {'I','P','E','n','a','b','l','e','d',0};
252 253
static const WCHAR prop_lastbootuptimeW[] =
    {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
254 255
static const WCHAR prop_localW[] =
    {'L','o','c','a','l',0};
256 257
static const WCHAR prop_localdatetimeW[] =
    {'L','o','c','a','l','D','a','t','e','T','i','m','e',0};
258 259
static const WCHAR prop_localeW[] =
    {'L','o','c','a','l','e',0};
260 261
static const WCHAR prop_lockpresentW[] =
    {'L','o','c','k','P','r','e','s','e','n','t',0};
262 263
static const WCHAR prop_macaddressW[] =
    {'M','A','C','A','d','d','r','e','s','s',0};
264 265
static const WCHAR prop_manufacturerW[] =
    {'M','a','n','u','f','a','c','t','u','r','e','r',0};
266 267
static const WCHAR prop_maxclockspeedW[] =
    {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
268 269
static const WCHAR prop_mediatypeW[] =
    {'M','e','d','i','a','T','y','p','e',0};
270 271
static const WCHAR prop_memberW[] =
    {'M','e','m','b','e','r',0};
272 273
static const WCHAR prop_memorytypeW[] =
    {'M','e','m','o','r','y','T','y','p','e',0};
274 275
static const WCHAR prop_methodW[] =
    {'M','e','t','h','o','d',0};
276 277
static const WCHAR prop_modelW[] =
    {'M','o','d','e','l',0};
278 279
static const WCHAR prop_netconnectionstatusW[] =
    {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
280 281
static const WCHAR prop_networkW[] =
    {'N','e','t','w','o','r','k',0};
282 283
static const WCHAR prop_nexthopW[] =
    {'N','e','x','t','H','o','p',0};
284 285
static const WCHAR prop_numcoresW[] =
    {'N','u','m','b','e','r','O','f','C','o','r','e','s',0};
286 287 288 289
static const WCHAR prop_numlogicalprocessorsW[] =
    {'N','u','m','b','e','r','O','f','L','o','g','i','c','a','l','P','r','o','c','e','s','s','o','r','s',0};
static const WCHAR prop_numprocessorsW[] =
    {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
290 291
static const WCHAR prop_osarchitectureW[] =
    {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
292 293
static const WCHAR prop_oslanguageW[] =
    {'O','S','L','a','n','g','u','a','g','e',0};
294 295 296 297
static const WCHAR prop_osproductsuiteW[] =
    {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
static const WCHAR prop_ostypeW[] =
    {'O','S','T','y','p','e',0};
298 299
static const WCHAR prop_parameterW[] =
    {'P','a','r','a','m','e','t','e','r',0};
300 301
static const WCHAR prop_physicaladapterW[] =
    {'P','h','y','s','i','c','a','l','A','d','a','p','t','e','r',0};
302 303
static const WCHAR prop_pixelsperxlogicalinchW[] =
    {'P','i','x','e','l','s','P','e','r','X','L','o','g','i','c','a','l','I','n','c','h',0};
304 305
static const WCHAR prop_pnpdeviceidW[] =
    {'P','N','P','D','e','v','i','c','e','I','D',0};
306 307
static const WCHAR prop_pprocessidW[] =
    {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
308 309
static const WCHAR prop_primaryW[] =
    {'P','r','i','m','a','r','y',0};
310 311
static const WCHAR prop_processidW[] =
    {'P','r','o','c','e','s','s','I','D',0};
312 313
static const WCHAR prop_processoridW[] =
    {'P','r','o','c','e','s','s','o','r','I','d',0};
314 315
static const WCHAR prop_processortypeW[] =
    {'P','r','o','c','e','s','s','o','r','T','y','p','e',0};
316 317
static const WCHAR prop_productW[] =
    {'P','r','o','d','u','c','t',0};
318 319
static const WCHAR prop_productnameW[] =
    {'P','r','o','d','u','c','t','N','a','m','e',0};
320 321
static const WCHAR prop_referenceddomainnameW[] =
    {'R','e','f','e','r','e','n','c','e','d','D','o','m','a','i','n','N','a','m','e',0};
322 323 324 325
static const WCHAR prop_releasedateW[] =
    {'R','e','l','e','a','s','e','D','a','t','e',0};
static const WCHAR prop_serialnumberW[] =
    {'S','e','r','i','a','l','N','u','m','b','e','r',0};
326 327
static const WCHAR prop_servicepackmajorW[] =
    {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
328 329
static const WCHAR prop_servicepackminorW[] =
    {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
330 331
static const WCHAR prop_servicetypeW[] =
    {'S','e','r','v','i','c','e','T','y','p','e',0};
332 333
static const WCHAR prop_settingidW[] =
    {'S','e','t','t','i','n','g','I','D',0};
334 335
static const WCHAR prop_smbiosbiosversionW[] =
    {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
336 337
static const WCHAR prop_startmodeW[] =
    {'S','t','a','r','t','M','o','d','e',0};
338 339 340 341
static const WCHAR prop_sidW[] =
    {'S','I','D',0};
static const WCHAR prop_sidlengthW[] =
    {'S','i','d','L','e','n','g','t','h',0};
342 343
static const WCHAR prop_sizeW[] =
    {'S','i','z','e',0};
344 345
static const WCHAR prop_speedW[] =
    {'S','p','e','e','d',0};
346 347
static const WCHAR prop_startingoffsetW[] =
    {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0};
348 349
static const WCHAR prop_stateW[] =
    {'S','t','a','t','e',0};
350 351
static const WCHAR prop_statusinfoW[] =
    {'S','t','a','t','u','s','I','n','f','o',0};
352 353
static const WCHAR prop_strvalueW[] =
    {'S','t','r','i','n','g','V','a','l','u','e',0};
354 355
static const WCHAR prop_suitemaskW[] =
    {'S','u','i','t','e','M','a','s','k',0};
356 357
static const WCHAR prop_systemdirectoryW[] =
    {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
358 359
static const WCHAR prop_systemnameW[] =
    {'S','y','s','t','e','m','N','a','m','e',0};
360 361
static const WCHAR prop_tagW[] =
    {'T','a','g',0};
362 363
static const WCHAR prop_threadcountW[] =
    {'T','h','r','e','a','d','C','o','u','n','t',0};
364 365
static const WCHAR prop_totalphysicalmemoryW[] =
    {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
366 367
static const WCHAR prop_totalvirtualmemorysizeW[] =
    {'T','o','t','a','l','V','i','r','t','u','a','l','M','e','m','o','r','y','S','i','z','e',0};
368 369
static const WCHAR prop_totalvisiblememorysizeW[] =
    {'T','o','t','a','l','V','i','s','i','b','l','e','M','e','m','o','r','y','S','i','z','e',0};
370 371
static const WCHAR prop_typeW[] =
    {'T','y','p','e',0};
372 373
static const WCHAR prop_uniqueidW[] =
    {'U','n','i','q','u','e','I','d',0};
374 375
static const WCHAR prop_usernameW[] =
    {'U','s','e','r','N','a','m','e',0};
376 377
static const WCHAR prop_uuidW[] =
    {'U','U','I','D',0};
378 379
static const WCHAR prop_varianttypeW[] =
    {'V','a','r','i','a','n','t','T','y','p','e',0};
380 381
static const WCHAR prop_versionW[] =
    {'V','e','r','s','i','o','n',0};
382 383 384 385
static const WCHAR prop_videoarchitectureW[] =
    {'V','i','d','e','o','A','r','c','h','i','t','e','c','t','u','r','e',0};
static const WCHAR prop_videomemorytypeW[] =
    {'V','i','d','e','o','M','e','m','o','r','y','T','y','p','e',0};
386 387
static const WCHAR prop_videomodedescriptionW[] =
    {'V','i','d','e','o','M','o','d','e','D','e','s','c','r','i','p','t','i','o','n',0};
388 389
static const WCHAR prop_videoprocessorW[] =
    {'V','i','d','e','o','P','r','o','c','e','s','s','o','r',0};
390 391
static const WCHAR prop_volumenameW[] =
    {'V','o','l','u','m','e','N','a','m','e',0};
392 393
static const WCHAR prop_volumeserialnumberW[] =
    {'V','o','l','u','m','e','S','e','r','i','a','l','N','u','m','b','e','r',0};
394 395
static const WCHAR prop_workingsetsizeW[] =
    {'W','o','r','k','i','n','g','S','e','t','S','i','z','e',0};
396

397
/* column definitions must be kept in sync with record structures below */
398 399 400
static const struct column col_baseboard[] =
{
    { prop_manufacturerW,  CIM_STRING },
401 402
    { prop_modelW,         CIM_STRING },
    { prop_nameW,          CIM_STRING },
403
    { prop_productW,       CIM_STRING },
404
    { prop_serialnumberW,  CIM_STRING },
405 406
    { prop_tagW,           CIM_STRING|COL_FLAG_KEY },
    { prop_versionW,       CIM_STRING }
407
};
408 409
static const struct column col_bios[] =
{
410 411 412
    { prop_descriptionW,        CIM_STRING },
    { prop_identificationcodeW, CIM_STRING },
    { prop_manufacturerW,       CIM_STRING },
413
    { prop_nameW,               CIM_STRING },
414 415 416 417
    { prop_releasedateW,        CIM_DATETIME },
    { prop_serialnumberW,       CIM_STRING },
    { prop_smbiosbiosversionW,  CIM_STRING },
    { prop_versionW,            CIM_STRING|COL_FLAG_KEY }
418
};
419 420
static const struct column col_cdromdrive[] =
{
421 422
    { prop_deviceidW,    CIM_STRING|COL_FLAG_KEY },
    { prop_driveW,       CIM_STRING|COL_FLAG_DYNAMIC },
423
    { prop_mediatypeW,   CIM_STRING },
424 425
    { prop_nameW,        CIM_STRING },
    { prop_pnpdeviceidW, CIM_STRING }
426
};
427 428
static const struct column col_compsys[] =
{
429
    { prop_descriptionW,          CIM_STRING },
430
    { prop_domainW,               CIM_STRING },
431
    { prop_domainroleW,           CIM_UINT16, VT_I4 },
432 433
    { prop_manufacturerW,         CIM_STRING },
    { prop_modelW,                CIM_STRING },
434
    { prop_nameW,                 CIM_STRING|COL_FLAG_DYNAMIC },
435 436
    { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
    { prop_numprocessorsW,        CIM_UINT32, VT_I4 },
437
    { prop_totalphysicalmemoryW,  CIM_UINT64 },
438
    { prop_usernameW,             CIM_STRING|COL_FLAG_DYNAMIC }
439
};
440 441
static const struct column col_compsysproduct[] =
{
442
    { prop_identifyingnumberW,  CIM_STRING|COL_FLAG_KEY },
443
    { prop_uuidW,               CIM_STRING|COL_FLAG_DYNAMIC }
444
};
445 446 447 448 449
static const struct column col_datafile[] =
{
    { prop_nameW,    CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
    { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
};
450 451 452 453
static const struct column col_desktopmonitor[] =
{
    { prop_pixelsperxlogicalinchW, CIM_UINT32 }
};
454 455 456
static const struct column col_directory[] =
{
    { prop_accessmaskW, CIM_UINT32 },
457
    { prop_nameW,       CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
458
};
459 460
static const struct column col_diskdrive[] =
{
461 462 463 464 465 466
    { prop_deviceidW,      CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
    { prop_indexW,         CIM_UINT32, VT_I4 },
    { prop_interfacetypeW, CIM_STRING },
    { prop_manufacturerW,  CIM_STRING },
    { prop_mediatypeW,     CIM_STRING },
    { prop_modelW,         CIM_STRING },
467
    { prop_pnpdeviceidW,   CIM_STRING },
468 469
    { prop_serialnumberW,  CIM_STRING },
    { prop_sizeW,          CIM_UINT64 }
470
};
471 472 473
static const struct column col_diskpartition[] =
{
    { prop_bootableW,       CIM_BOOLEAN },
474
    { prop_bootpartitionW,  CIM_BOOLEAN },
475 476 477 478 479 480 481 482
    { prop_deviceidW,       CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
    { prop_diskindexW,      CIM_UINT32, VT_I4 },
    { prop_indexW,          CIM_UINT32, VT_I4 },
    { prop_pnpdeviceidW,    CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_sizeW,           CIM_UINT64 },
    { prop_startingoffsetW, CIM_UINT64 },
    { prop_typeW,           CIM_STRING|COL_FLAG_DYNAMIC }
};
483 484 485 486 487 488
static const struct column col_ip4routetable[] =
{
    { prop_destinationW,    CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
    { prop_interfaceindexW, CIM_SINT32|COL_FLAG_KEY },
    { prop_nexthopW,        CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
};
489 490
static const struct column col_logicaldisk[] =
{
491 492 493 494 495 496
    { prop_deviceidW,           CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
    { prop_drivetypeW,          CIM_UINT32, VT_I4 },
    { prop_filesystemW,         CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_freespaceW,          CIM_UINT64 },
    { prop_nameW,               CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_sizeW,               CIM_UINT64 },
497
    { prop_volumenameW,         CIM_STRING|COL_FLAG_DYNAMIC },
498
    { prop_volumeserialnumberW, CIM_STRING|COL_FLAG_DYNAMIC }
499
};
500 501
static const struct column col_networkadapter[] =
{
502
    { prop_adaptertypeW,         CIM_STRING },
503
    { prop_deviceidW,            CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
504
    { prop_indexW,               CIM_UINT32, VT_I4 },
505
    { prop_interfaceindexW,      CIM_UINT32, VT_I4 },
506
    { prop_macaddressW,          CIM_STRING|COL_FLAG_DYNAMIC },
507
    { prop_manufacturerW,        CIM_STRING },
508
    { prop_nameW,                CIM_STRING|COL_FLAG_DYNAMIC },
509
    { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
510
    { prop_physicaladapterW,     CIM_BOOLEAN },
511
    { prop_pnpdeviceidW,         CIM_STRING },
512
    { prop_speedW,               CIM_UINT64 }
513
};
514 515
static const struct column col_networkadapterconfig[] =
{
516 517 518 519 520 521 522 523
    { prop_defaultipgatewayW,     CIM_STRING|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
    { prop_descriptionW,          CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_dhcpenabledW,          CIM_BOOLEAN },
    { prop_dnshostnameW,          CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_dnsserversearchorderW, CIM_STRING|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
    { prop_indexW,                CIM_UINT32|COL_FLAG_KEY, VT_I4 },
    { prop_ipconnectionmetricW,   CIM_UINT32, VT_I4 },
    { prop_ipenabledW,            CIM_BOOLEAN },
524 525
    { prop_macaddressW,           CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_settingidW,            CIM_STRING|COL_FLAG_DYNAMIC }
526
};
527 528
static const struct column col_os[] =
{
529 530
    { prop_buildnumberW,            CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_captionW,                CIM_STRING|COL_FLAG_DYNAMIC },
531 532
    { prop_codesetW,                CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_countrycodeW,            CIM_STRING|COL_FLAG_DYNAMIC },
533
    { prop_csdversionW,             CIM_STRING|COL_FLAG_DYNAMIC },
534 535 536 537
    { prop_installdateW,            CIM_DATETIME },
    { prop_lastbootuptimeW,         CIM_DATETIME|COL_FLAG_DYNAMIC },
    { prop_localdatetimeW,          CIM_DATETIME|COL_FLAG_DYNAMIC },
    { prop_localeW,                 CIM_STRING|COL_FLAG_DYNAMIC },
538
    { prop_nameW,                   CIM_STRING|COL_FLAG_DYNAMIC },
539 540 541 542
    { prop_osarchitectureW,         CIM_STRING },
    { prop_oslanguageW,             CIM_UINT32, VT_I4 },
    { prop_osproductsuiteW,         CIM_UINT32, VT_I4 },
    { prop_ostypeW,                 CIM_UINT16, VT_I4 },
543
    { prop_primaryW,                CIM_BOOLEAN },
544 545 546 547 548
    { prop_serialnumberW,           CIM_STRING },
    { prop_servicepackmajorW,       CIM_UINT16, VT_I4 },
    { prop_servicepackminorW,       CIM_UINT16, VT_I4 },
    { prop_suitemaskW,              CIM_UINT32, VT_I4 },
    { prop_systemdirectoryW,        CIM_STRING|COL_FLAG_DYNAMIC },
549
    { prop_totalvirtualmemorysizeW, CIM_UINT64 },
550
    { prop_totalvisiblememorysizeW, CIM_UINT64 },
551
    { prop_versionW,                CIM_STRING|COL_FLAG_DYNAMIC }
552
};
553
static const struct column col_param[] =
554 555 556 557 558 559
{
    { prop_classW,        CIM_STRING },
    { prop_methodW,       CIM_STRING },
    { prop_directionW,    CIM_SINT32 },
    { prop_parameterW,    CIM_STRING },
    { prop_typeW,         CIM_UINT32 },
560
    { prop_varianttypeW,  CIM_UINT32 },
561 562
    { prop_defaultvalueW, CIM_UINT32 }
};
563 564
static const struct column col_physicalmedia[] =
{
565 566
    { prop_serialnumberW,       CIM_STRING },
    { prop_tagW,                CIM_STRING }
567
};
568 569
static const struct column col_physicalmemory[] =
{
570 571
    { prop_capacityW,   CIM_UINT64 },
    { prop_memorytypeW, CIM_UINT16, VT_I4 }
572
};
573 574 575 576 577 578 579 580 581
static const struct column col_printer[] =
{
    { prop_attributesW,           CIM_UINT32 },
    { prop_drivernameW,           CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_horizontalresolutionW, CIM_UINT32 },
    { prop_localW,                CIM_BOOLEAN },
    { prop_nameW,                 CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_networkW,              CIM_BOOLEAN }
};
582 583
static const struct column col_process[] =
{
584 585 586 587 588 589 590 591 592
    { prop_captionW,        CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_commandlineW,    CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_descriptionW,    CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_handleW,         CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
    { prop_nameW,           CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_pprocessidW,     CIM_UINT32, VT_I4 },
    { prop_processidW,      CIM_UINT32, VT_I4 },
    { prop_threadcountW,    CIM_UINT32, VT_I4 },
    { prop_workingsetsizeW, CIM_UINT64 },
593
    /* methods */
594
    { method_getownerW,     CIM_FLAG_ARRAY|COL_FLAG_METHOD }
595
};
596 597
static const struct column col_processor[] =
{
598
    { prop_addresswidthW,         CIM_UINT16, VT_I4 },
599
    { prop_captionW,              CIM_STRING|COL_FLAG_DYNAMIC },
600
    { prop_cpustatusW,            CIM_UINT16 },
601
    { prop_currentclockspeedW,    CIM_UINT32, VT_I4 },
602 603
    { prop_datawidthW,            CIM_UINT16, VT_I4 },
    { prop_descriptionW,          CIM_STRING|COL_FLAG_DYNAMIC },
604
    { prop_deviceidW,             CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
605
    { prop_familyW,               CIM_UINT16, VT_I4 },
606
    { prop_manufacturerW,         CIM_STRING|COL_FLAG_DYNAMIC },
607
    { prop_maxclockspeedW,        CIM_UINT32, VT_I4 },
608
    { prop_nameW,                 CIM_STRING|COL_FLAG_DYNAMIC },
609
    { prop_numcoresW,             CIM_UINT32, VT_I4 },
610
    { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
611
    { prop_processoridW,          CIM_STRING|COL_FLAG_DYNAMIC },
612
    { prop_processortypeW,        CIM_UINT16, VT_I4 },
613 614
    { prop_uniqueidW,             CIM_STRING },
    { prop_versionW,              CIM_STRING|COL_FLAG_DYNAMIC }
615
};
616 617 618 619 620 621 622 623 624 625
static const struct column col_qualifier[] =
{
    { prop_classW,    CIM_STRING },
    { prop_memberW,   CIM_STRING },
    { prop_typeW,     CIM_UINT32 },
    { prop_flavorW,   CIM_SINT32 },
    { prop_nameW,     CIM_STRING },
    { prop_intvalueW, CIM_SINT32 },
    { prop_strvalueW, CIM_STRING }
};
626 627
static const struct column col_service[] =
{
628 629
    { prop_acceptpauseW,      CIM_BOOLEAN },
    { prop_acceptstopW,       CIM_BOOLEAN },
630 631 632 633
    { prop_displaynameW,      CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_nameW,             CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
    { prop_processidW,        CIM_UINT32 },
    { prop_servicetypeW,      CIM_STRING },
634
    { prop_startmodeW,        CIM_STRING },
635
    { prop_stateW,            CIM_STRING },
636 637
    { prop_systemnameW,       CIM_STRING|COL_FLAG_DYNAMIC },
    /* methods */
638
    { method_pauseserviceW,   CIM_FLAG_ARRAY|COL_FLAG_METHOD },
639
    { method_resumeserviceW,  CIM_FLAG_ARRAY|COL_FLAG_METHOD },
640 641
    { method_startserviceW,   CIM_FLAG_ARRAY|COL_FLAG_METHOD },
    { method_stopserviceW,    CIM_FLAG_ARRAY|COL_FLAG_METHOD }
642
};
643 644 645 646 647 648 649 650
static const struct column col_sid[] =
{
    { prop_accountnameW,            CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_binaryrepresentationW,   CIM_UINT8|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
    { prop_referenceddomainnameW,   CIM_STRING|COL_FLAG_DYNAMIC },
    { prop_sidW,                    CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
    { prop_sidlengthW,              CIM_UINT32 }
};
651 652
static const struct column col_sounddevice[] =
{
653
    { prop_nameW,        CIM_STRING },
654
    { prop_productnameW, CIM_STRING },
655
    { prop_statusinfoW,  CIM_UINT16, VT_I4 }
656
};
657 658
static const struct column col_stdregprov[] =
{
659 660 661
    { method_enumkeyW,        CIM_FLAG_ARRAY|COL_FLAG_METHOD },
    { method_enumvaluesW,     CIM_FLAG_ARRAY|COL_FLAG_METHOD },
    { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
662
};
663 664 665
static const struct column col_systemenclosure[] =
{
    { prop_captionW,      CIM_STRING },
666
    { prop_chassistypesW, CIM_UINT16|CIM_FLAG_ARRAY, VT_I4|VT_ARRAY },
667 668 669 670 671 672
    { prop_descriptionW,  CIM_STRING },
    { prop_lockpresentW,  CIM_BOOLEAN },
    { prop_manufacturerW, CIM_STRING },
    { prop_nameW,         CIM_STRING },
    { prop_tagW,          CIM_STRING },
};
673 674 675
static const struct column col_systemsecurity[] =
{
    { method_getsdW,                    CIM_FLAG_ARRAY|COL_FLAG_METHOD },
676
    { method_setsdW,                    CIM_FLAG_ARRAY|COL_FLAG_METHOD },
677
};
678 679
static const struct column col_videocontroller[] =
{
680
    { prop_adapterdactypeW,       CIM_STRING },
681
    { prop_adapterramW,           CIM_UINT32, VT_I4 },
682
    { prop_availabilityW,         CIM_UINT16 },
683
    { prop_captionW,              CIM_STRING|COL_FLAG_DYNAMIC },
684 685
    { prop_currentbitsperpixelW,  CIM_UINT32, VT_I4 },
    { prop_currenthorizontalresW, CIM_UINT32, VT_I4 },
686 687
    { prop_currentrefreshrateW,   CIM_UINT32, VT_I4 },
    { prop_currentscanmodeW,      CIM_UINT16, VT_I4 },
688
    { prop_currentverticalresW,   CIM_UINT32, VT_I4 },
689
    { prop_descriptionW,          CIM_STRING|COL_FLAG_DYNAMIC },
690
    { prop_deviceidW,             CIM_STRING|COL_FLAG_KEY },
691
    { prop_driverversionW,        CIM_STRING },
692
    { prop_nameW,                 CIM_STRING|COL_FLAG_DYNAMIC },
693
    { prop_pnpdeviceidW,          CIM_STRING|COL_FLAG_DYNAMIC },
694 695
    { prop_videoarchitectureW,    CIM_UINT16, VT_I4 },
    { prop_videomemorytypeW,      CIM_UINT16, VT_I4 },
696
    { prop_videomodedescriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
697
    { prop_videoprocessorW,       CIM_STRING|COL_FLAG_DYNAMIC }
698
};
699

700 701 702 703 704 705
static const WCHAR baseboard_manufacturerW[] =
    {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
static const WCHAR baseboard_serialnumberW[] =
    {'N','o','n','e',0};
static const WCHAR baseboard_tagW[] =
    {'B','a','s','e',' ','B','o','a','r','d',0};
706 707
static const WCHAR baseboard_versionW[] =
    {'1','.','0',0};
708 709 710 711
static const WCHAR bios_descriptionW[] =
    {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
static const WCHAR bios_manufacturerW[] =
    {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
712 713
static const WCHAR bios_nameW[] =
    {'W','I','N','E',' ','B','I','O','S',0};
714 715 716 717
static const WCHAR bios_releasedateW[] =
    {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
static const WCHAR bios_serialnumberW[] =
    {'0',0};
718 719
static const WCHAR bios_smbiosbiosversionW[] =
    {'W','i','n','e',0};
720 721
static const WCHAR bios_versionW[] =
    {'W','I','N','E',' ',' ',' ','-',' ','1',0};
722 723
static const WCHAR cdromdrive_mediatypeW[] =
    {'C','D','-','R','O','M',0};
724 725
static const WCHAR cdromdrive_nameW[] =
    {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
726 727 728 729 730
static const WCHAR cdromdrive_pnpdeviceidW[]=
    {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
     '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
     '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
     'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
731 732
static const WCHAR compsys_descriptionW[] =
    {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
733 734
static const WCHAR compsys_domainW[] =
    {'W','O','R','K','G','R','O','U','P',0};
735 736 737 738
static const WCHAR compsys_manufacturerW[] =
    {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
static const WCHAR compsys_modelW[] =
    {'W','i','n','e',0};
739 740
static const WCHAR compsysproduct_identifyingnumberW[] =
    {'0',0};
741
static const WCHAR compsysproduct_uuidW[] =
742 743
    {'d','e','a','d','d','e','a','d','-','d','e','a','d','-','d','e','a','d','-','d','e','a','d','-',
     'd','e','a','d','d','e','a','d','d','e','a','d',0};
744 745
static const WCHAR diskdrive_interfacetypeW[] =
    {'I','D','E',0};
746 747
static const WCHAR diskdrive_manufacturerW[] =
    {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
748
static const WCHAR diskdrive_mediatype_fixedW[] =
749
    {'F','i','x','e','d',' ','h','a','r','d',' ','d','i','s','k',0};
750 751
static const WCHAR diskdrive_mediatype_removableW[] =
    {'R','e','m','o','v','a','b','l','e',' ','m','e','d','i','a',0};
752 753
static const WCHAR diskdrive_modelW[] =
    {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
754 755
static const WCHAR diskdrive_pnpdeviceidW[] =
    {'I','D','E','\\','D','i','s','k','\\','V','E','N','_','W','I','N','E',0};
756 757
static const WCHAR diskdrive_serialW[] =
    {'W','I','N','E','H','D','I','S','K',0};
758 759 760 761
static const WCHAR networkadapter_pnpdeviceidW[]=
    {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
     'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
     '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
762 763 764 765 766 767 768 769
static const WCHAR os_32bitW[] =
    {'3','2','-','b','i','t',0};
static const WCHAR os_64bitW[] =
    {'6','4','-','b','i','t',0};
static const WCHAR os_installdateW[] =
    {'2','0','1','4','0','1','0','1','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
static const WCHAR os_serialnumberW[] =
    {'1','2','3','4','5','-','O','E','M','-','1','2','3','4','5','6','7','-','1','2','3','4','5',0};
770 771
static const WCHAR physicalmedia_tagW[] =
    {'\\','\\','.','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
772 773
static const WCHAR sounddevice_productnameW[] =
    {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
774 775 776 777 778 779
static const WCHAR systemenclosure_systemenclosureW[] =
    {'S','y','s','t','e','m',' ','E','n','c','l','o','s','u','r','e',0};
static const WCHAR systemenclosure_tagW[] =
    {'S','y','s','t','e','m',' ','E','n','c','l','o','s','u','r','e',' ','0',0};
static const WCHAR systemenclosure_manufacturerW[] =
    {'W','i','n','e',0};
780 781
static const WCHAR videocontroller_dactypeW[] =
    {'I','n','t','e','g','r','a','t','e','d',' ','R','A','M','D','A','C',0};
782 783
static const WCHAR videocontroller_deviceidW[] =
    {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
784 785
static const WCHAR videocontroller_driverversionW[] =
    {'1','.','0',0};
786 787

#include "pshpack1.h"
788 789 790
struct record_baseboard
{
    const WCHAR *manufacturer;
791 792
    const WCHAR *model;
    const WCHAR *name;
793
    const WCHAR *product;
794 795
    const WCHAR *serialnumber;
    const WCHAR *tag;
796
    const WCHAR *version;
797
};
798 799 800
struct record_bios
{
    const WCHAR *description;
801
    const WCHAR *identificationcode;
802
    const WCHAR *manufacturer;
803
    const WCHAR *name;
804 805
    const WCHAR *releasedate;
    const WCHAR *serialnumber;
806
    const WCHAR *smbiosbiosversion;
807
    const WCHAR *version;
808
};
809 810
struct record_cdromdrive
{
811 812
    const WCHAR *device_id;
    const WCHAR *drive;
813
    const WCHAR *mediatype;
814
    const WCHAR *name;
815
    const WCHAR *pnpdevice_id;
816
};
817 818 819
struct record_computersystem
{
    const WCHAR *description;
820
    const WCHAR *domain;
821
    UINT16       domainrole;
822 823
    const WCHAR *manufacturer;
    const WCHAR *model;
824
    const WCHAR *name;
825 826
    UINT32       num_logical_processors;
    UINT32       num_processors;
827
    UINT64       total_physical_memory;
828
    const WCHAR *username;
829
};
830 831
struct record_computersystemproduct
{
832
    const WCHAR *identifyingnumber;
833 834
    const WCHAR *uuid;
};
835 836 837 838 839
struct record_datafile
{
    const WCHAR *name;
    const WCHAR *version;
};
840 841 842 843
struct record_desktopmonitor
{
    UINT32       pixelsperxlogicalinch;
};
844 845 846 847 848
struct record_directory
{
    UINT32       accessmask;
    const WCHAR *name;
};
849 850
struct record_diskdrive
{
851
    const WCHAR *device_id;
852
    UINT32       index;
853
    const WCHAR *interfacetype;
854
    const WCHAR *manufacturer;
855
    const WCHAR *mediatype;
856
    const WCHAR *model;
857
    const WCHAR *pnpdevice_id;
858
    const WCHAR *serialnumber;
859
    UINT64       size;
860
};
861 862 863
struct record_diskpartition
{
    int          bootable;
864
    int          bootpartition;
865 866 867 868 869 870 871 872
    const WCHAR *device_id;
    UINT32       diskindex;
    UINT32       index;
    const WCHAR *pnpdevice_id;
    UINT64       size;
    UINT64       startingoffset;
    const WCHAR *type;
};
873 874 875 876 877 878
struct record_ip4routetable
{
    const WCHAR *destination;
    INT32        interfaceindex;
    const WCHAR *nexthop;
};
879 880 881 882 883 884
struct record_logicaldisk
{
    const WCHAR *device_id;
    UINT32       drivetype;
    const WCHAR *filesystem;
    UINT64       freespace;
885
    const WCHAR *name;
886
    UINT64       size;
887
    const WCHAR *volumename;
888
    const WCHAR *volumeserialnumber;
889
};
890 891
struct record_networkadapter
{
892
    const WCHAR *adaptertype;
893
    const WCHAR *device_id;
894 895
    UINT32       index;
    UINT32       interface_index;
896
    const WCHAR *mac_address;
897
    const WCHAR *manufacturer;
898
    const WCHAR *name;
899
    UINT16       netconnection_status;
900
    int          physicaladapter;
901
    const WCHAR *pnpdevice_id;
902
    UINT64       speed;
903
};
904 905
struct record_networkadapterconfig
{
906 907
    const struct array *defaultipgateway;
    const WCHAR        *description;
908
    int                 dhcpenabled;
909
    const WCHAR        *dnshostname;
910
    const struct array *dnsserversearchorder;
911 912 913 914
    UINT32              index;
    UINT32              ipconnectionmetric;
    int                 ipenabled;
    const WCHAR        *mac_address;
915
    const WCHAR        *settingid;
916
};
917 918
struct record_operatingsystem
{
919
    const WCHAR *buildnumber;
920
    const WCHAR *caption;
921
    const WCHAR *codeset;
922
    const WCHAR *countrycode;
923
    const WCHAR *csdversion;
924
    const WCHAR *installdate;
925
    const WCHAR *lastbootuptime;
926
    const WCHAR *localdatetime;
927
    const WCHAR *locale;
928
    const WCHAR *name;
929
    const WCHAR *osarchitecture;
930
    UINT32       oslanguage;
931 932
    UINT32       osproductsuite;
    UINT16       ostype;
933
    int          primary;
934
    const WCHAR *serialnumber;
935
    UINT16       servicepackmajor;
936
    UINT16       servicepackminor;
937
    UINT32       suitemask;
938
    const WCHAR *systemdirectory;
939
    UINT64       totalvirtualmemorysize;
940
    UINT64       totalvisiblememorysize;
941
    const WCHAR *version;
942
};
943
struct record_param
944 945 946 947 948 949
{
    const WCHAR *class;
    const WCHAR *method;
    INT32        direction;
    const WCHAR *parameter;
    UINT32       type;
950
    UINT32       varianttype;
951 952
    UINT32       defaultvalue;
};
953 954 955
struct record_physicalmedia
{
    const WCHAR *serialnumber;
956
    const WCHAR *tag;
957
};
958 959 960
struct record_physicalmemory
{
    UINT64 capacity;
961
    UINT16 memorytype;
962
};
963 964 965 966 967 968 969 970 971
struct record_printer
{
    UINT32       attributes;
    const WCHAR *drivername;
    UINT32       horizontalresolution;
    int          local;
    const WCHAR *name;
    int          network;
};
972 973 974
struct record_process
{
    const WCHAR *caption;
975
    const WCHAR *commandline;
976
    const WCHAR *description;
977
    const WCHAR *handle;
978
    const WCHAR *name;
979 980 981
    UINT32       pprocess_id;
    UINT32       process_id;
    UINT32       thread_count;
982
    UINT64       workingsetsize;
983 984
    /* methods */
    class_method *get_owner;
985
};
986 987
struct record_processor
{
988
    UINT16       addresswidth;
989
    const WCHAR *caption;
990
    UINT16       cpu_status;
991
    UINT32       currentclockspeed;
992 993
    UINT16       datawidth;
    const WCHAR *description;
994
    const WCHAR *device_id;
995
    UINT16       family;
996
    const WCHAR *manufacturer;
997
    UINT32       maxclockspeed;
998
    const WCHAR *name;
999
    UINT32       num_cores;
1000
    UINT32       num_logical_processors;
1001
    const WCHAR *processor_id;
1002
    UINT16       processortype;
1003
    const WCHAR *unique_id;
1004
    const WCHAR *version;
1005
};
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
struct record_qualifier
{
    const WCHAR *class;
    const WCHAR *member;
    UINT32       type;
    INT32        flavor;
    const WCHAR *name;
    INT32        intvalue;
    const WCHAR *strvalue;
};
1016 1017
struct record_service
{
1018 1019
    int          accept_pause;
    int          accept_stop;
1020 1021 1022 1023
    const WCHAR *displayname;
    const WCHAR *name;
    UINT32       process_id;
    const WCHAR *servicetype;
1024
    const WCHAR *startmode;
1025
    const WCHAR *state;
1026
    const WCHAR *systemname;
1027 1028
    /* methods */
    class_method *pause_service;
1029
    class_method *resume_service;
1030
    class_method *start_service;
1031
    class_method *stop_service;
1032
};
1033 1034 1035
struct record_sid
{
    const WCHAR *accountname;
1036
    const struct array *binaryrepresentation;
1037 1038 1039 1040
    const WCHAR *referenceddomainname;
    const WCHAR *sid;
    UINT32       sidlength;
};
1041 1042
struct record_sounddevice
{
1043
    const WCHAR *name;
1044
    const WCHAR *productname;
1045
    UINT16       statusinfo;
1046
};
1047 1048 1049 1050
struct record_stdregprov
{
    class_method *enumkey;
    class_method *enumvalues;
1051
    class_method *getstringvalue;
1052
};
1053 1054 1055
struct record_systemsecurity
{
    class_method *getsd;
1056
    class_method *setsd;
1057
};
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
struct record_systemenclosure
{
    const WCHAR *caption;
    const struct array *chassistypes;
    const WCHAR *description;
    int         lockpresent;
    const WCHAR *manufacturer;
    const WCHAR *name;
    const WCHAR *tag;
};
1068 1069
struct record_videocontroller
{
1070
    const WCHAR *adapter_dactype;
1071
    UINT32       adapter_ram;
1072
    UINT16       availability;
1073
    const WCHAR *caption;
1074 1075
    UINT32       current_bitsperpixel;
    UINT32       current_horizontalres;
1076 1077
    UINT32       current_refreshrate;
    UINT16       current_scanmode;
1078
    UINT32       current_verticalres;
1079
    const WCHAR *description;
1080
    const WCHAR *device_id;
1081
    const WCHAR *driverversion;
1082
    const WCHAR *name;
1083
    const WCHAR *pnpdevice_id;
1084 1085
    UINT16       videoarchitecture;
    UINT16       videomemorytype;
1086
    const WCHAR *videomodedescription;
1087
    const WCHAR *videoprocessor;
1088
};
1089 1090
#include "poppack.h"

1091 1092
static const struct record_baseboard data_baseboard[] =
{
1093
    { baseboard_manufacturerW, baseboard_tagW, baseboard_tagW, baseboard_tagW, baseboard_serialnumberW, baseboard_versionW }
1094
};
1095 1096
static const struct record_bios data_bios[] =
{
1097
    { bios_descriptionW, NULL, bios_manufacturerW, bios_nameW, bios_releasedateW, bios_serialnumberW,
1098
      bios_smbiosbiosversionW, bios_versionW }
1099
};
1100
static const struct record_param data_param[] =
1101
{
1102 1103 1104
    { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
    { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
    { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
1105
    { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1106
    { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1107
    { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1108
    { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1109
    { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
1110
    { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
1111
    { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1112
    { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
1113
    { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
1114
    { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
1115
    { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1116
    { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
1117 1118 1119 1120 1121
    { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
    { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
    { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
    { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
    { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1122 1123 1124
    { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING },
    { class_systemsecurityW, method_getsdW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
    { class_systemsecurityW, method_getsdW, -1, param_sdW, CIM_UINT8|CIM_FLAG_ARRAY },
1125 1126
    { class_systemsecurityW, method_setsdW, 1, param_sdW, CIM_UINT8|CIM_FLAG_ARRAY },
    { class_systemsecurityW, method_setsdW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1127
};
1128 1129 1130 1131

#define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
                   WBEM_FLAVOR_ORIGIN_PROPAGATED)

1132 1133
static const struct record_physicalmedia data_physicalmedia[] =
{
1134
    { diskdrive_serialW, physicalmedia_tagW }
1135
};
1136 1137 1138 1139 1140
static const struct record_qualifier data_qualifier[] =
{
    { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
    { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
};
1141 1142
static const struct record_sounddevice data_sounddevice[] =
{
1143
    { sounddevice_productnameW, sounddevice_productnameW, 3 /* enabled */ }
1144
};
1145 1146
static const struct record_stdregprov data_stdregprov[] =
{
1147
    { reg_enum_key, reg_enum_values, reg_get_stringvalue }
1148
};
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
static UINT16 systemenclosure_chassistypes[] =
{
    1,
};
static const struct array systemenclosure_chassistypes_array =
{
    SIZEOF(systemenclosure_chassistypes),
    &systemenclosure_chassistypes
};
static const struct record_systemenclosure data_systemenclosure[] =
{
    {
        systemenclosure_systemenclosureW,
        &systemenclosure_chassistypes_array,
        systemenclosure_systemenclosureW,
        FALSE,
        systemenclosure_manufacturerW,
        systemenclosure_systemenclosureW,
        systemenclosure_tagW,
    }
};
1170 1171
static const struct record_systemsecurity data_systemsecurity[] =
{
1172
    { security_get_sd, security_set_sd }
1173
};
1174

1175 1176 1177 1178
/* check if row matches condition and update status */
static BOOL match_row( const struct table *table, UINT row, const struct expr *cond, enum fill_status *status )
{
    LONGLONG val;
1179 1180
    UINT type;

1181 1182 1183 1184 1185
    if (!cond)
    {
        *status = FILL_STATUS_UNFILTERED;
        return TRUE;
    }
1186
    if (eval_cond( table, row, cond, &val, &type ) != S_OK)
1187 1188 1189 1190 1191 1192 1193 1194
    {
        *status = FILL_STATUS_FAILED;
        return FALSE;
    }
    *status = FILL_STATUS_FILTERED;
    return val != 0;
}

1195 1196 1197 1198 1199 1200 1201 1202
static BOOL resize_table( struct table *table, UINT row_count, UINT row_size )
{
    if (!table->num_rows_allocated)
    {
        if (!(table->data = heap_alloc( row_count * row_size ))) return FALSE;
        table->num_rows_allocated = row_count;
        return TRUE;
    }
1203
    if (row_count > table->num_rows_allocated)
1204 1205
    {
        BYTE *data;
1206
        UINT count = max( row_count, table->num_rows_allocated * 2 );
1207 1208 1209 1210 1211 1212 1213
        if (!(data = heap_realloc( table->data, count * row_size ))) return FALSE;
        table->data = data;
        table->num_rows_allocated = count;
    }
    return TRUE;
}

1214
static enum fill_status fill_cdromdrive( struct table *table, const struct expr *cond )
1215 1216 1217 1218
{
    static const WCHAR fmtW[] = {'%','c',':',0};
    WCHAR drive[3], root[] = {'A',':','\\',0};
    struct record_cdromdrive *rec;
1219
    UINT i, row = 0, offset = 0;
1220
    DWORD drives = GetLogicalDrives();
1221
    enum fill_status status = FILL_STATUS_UNFILTERED;
1222

1223
    if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1224

1225
    for (i = 0; i < 26; i++)
1226 1227 1228 1229 1230 1231 1232
    {
        if (drives & (1 << i))
        {
            root[0] = 'A' + i;
            if (GetDriveTypeW( root ) != DRIVE_CDROM)
                continue;

1233 1234
            if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;

1235 1236 1237 1238
            rec = (struct record_cdromdrive *)(table->data + offset);
            rec->device_id    = cdromdrive_pnpdeviceidW;
            sprintfW( drive, fmtW, 'A' + i );
            rec->drive        = heap_strdupW( drive );
1239
            rec->mediatype    = cdromdrive_mediatypeW;
1240 1241
            rec->name         = cdromdrive_nameW;
            rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
1242 1243 1244 1245 1246
            if (!match_row( table, row, cond, &status ))
            {
                free_row_values( table, row );
                continue;
            }
1247
            offset += sizeof(*rec);
1248
            row++;
1249 1250
        }
    }
1251 1252 1253
    TRACE("created %u rows\n", row);
    table->num_rows = row;
    return status;
1254 1255
}

1256 1257 1258 1259 1260 1261 1262 1263
static UINT get_processor_count(void)
{
    SYSTEM_BASIC_INFORMATION info;

    if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
    return info.NumberOfProcessors;
}

1264
static UINT get_logical_processor_count( UINT *num_cores )
1265 1266 1267 1268 1269 1270
{
    SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
    UINT i, j, count = 0;
    NTSTATUS status;
    ULONG len;

1271
    if (num_cores) *num_cores = get_processor_count();
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
    status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
    if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();

    if (!(info = heap_alloc( len ))) return get_processor_count();
    status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
    if (status != STATUS_SUCCESS)
    {
        heap_free( info );
        return get_processor_count();
    }
1282
    if (num_cores) *num_cores = 0;
1283 1284
    for (i = 0; i < len / sizeof(*info); i++)
    {
1285 1286 1287 1288 1289 1290 1291 1292
        if (info[i].Relationship == RelationProcessorCore)
        {
            for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
        }
        else if (info[i].Relationship == RelationProcessorPackage && num_cores)
        {
            for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) (*num_cores)++;
        }
1293 1294 1295 1296 1297
    }
    heap_free( info );
    return count;
}

1298 1299 1300 1301 1302 1303 1304 1305 1306
static UINT64 get_total_physical_memory(void)
{
    MEMORYSTATUSEX status;

    status.dwLength = sizeof(status);
    if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
    return status.ullTotalPhys;
}

1307 1308 1309
static WCHAR *get_computername(void)
{
    WCHAR *ret;
1310
    DWORD size = MAX_COMPUTERNAME_LENGTH + 1;
1311 1312 1313 1314 1315 1316

    if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
    GetComputerNameW( ret, &size );
    return ret;
}

1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334
static WCHAR *get_username(void)
{
    WCHAR *ret;
    DWORD compsize, usersize;
    DWORD size;

    compsize = 0;
    GetComputerNameW( NULL, &compsize );
    usersize = 0;
    GetUserNameW( NULL, &usersize );
    size = compsize + usersize; /* two null terminators account for the \ */
    if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
    GetComputerNameW( ret, &compsize );
    ret[compsize] = '\\';
    GetUserNameW( ret + compsize + 1, &usersize );
    return ret;
}

1335
static enum fill_status fill_compsys( struct table *table, const struct expr *cond )
1336 1337
{
    struct record_computersystem *rec;
1338 1339
    enum fill_status status = FILL_STATUS_UNFILTERED;
    UINT row = 0;
1340

1341
    if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1342 1343 1344

    rec = (struct record_computersystem *)table->data;
    rec->description            = compsys_descriptionW;
1345
    rec->domain                 = compsys_domainW;
1346
    rec->domainrole             = 0; /* standalone workstation */
1347 1348
    rec->manufacturer           = compsys_manufacturerW;
    rec->model                  = compsys_modelW;
1349
    rec->name                   = get_computername();
1350
    rec->num_logical_processors = get_logical_processor_count( NULL );
1351
    rec->num_processors         = get_processor_count();
1352
    rec->total_physical_memory  = get_total_physical_memory();
1353
    rec->username               = get_username();
1354 1355
    if (!match_row( table, row, cond, &status )) free_row_values( table, row );
    else row++;
1356

1357 1358 1359
    TRACE("created %u rows\n", row);
    table->num_rows = row;
    return status;
1360 1361
}

1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378
static WCHAR *get_compsysproduct_uuid(void)
{
#ifdef __APPLE__
    unsigned char uuid[16];
    const struct timespec timeout = {1, 0};
    if (!gethostuuid( uuid, &timeout ))
    {
        static const WCHAR fmtW[] =
            {'%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','-',
             '%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X',
             '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',0};
        WCHAR *ret = heap_alloc( 37 * sizeof(WCHAR) );
        if (!ret) return NULL;
        sprintfW( ret, fmtW, uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7],
                  uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15] );
        return ret;
    }
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405
#endif
#ifdef __linux__
    int file;
    if ((file = open( "/var/lib/dbus/machine-id", O_RDONLY )) != -1)
    {
        unsigned char buf[32];
        if (read( file, buf, sizeof(buf) ) == sizeof(buf))
        {
            unsigned int i, j;
            WCHAR *ret, *p;

            close( file );
            if (!(p = ret = heap_alloc( 37 * sizeof(WCHAR) ))) return NULL;
            for (i = 0, j = 0; i < 8; i++) p[i] = toupperW( buf[j++] );
            p[8] = '-';
            for (i = 9; i < 13; i++) p[i] = toupperW( buf[j++] );
            p[13] = '-';
            for (i = 14; i < 18; i++) p[i] = toupperW( buf[j++] );
            p[18] = '-';
            for (i = 19; i < 23; i++) p[i] = toupperW( buf[j++] );
            p[23] = '-';
            for (i = 24; i < 36; i++) p[i] = toupperW( buf[j++] );
            ret[i] = 0;
            return ret;
        }
        close( file );
    }
1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428
#endif
    return heap_strdupW( compsysproduct_uuidW );
}

static enum fill_status fill_compsysproduct( struct table *table, const struct expr *cond )
{
    struct record_computersystemproduct *rec;
    enum fill_status status = FILL_STATUS_UNFILTERED;
    UINT row = 0;

    if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;

    rec = (struct record_computersystemproduct *)table->data;
    rec->identifyingnumber = compsysproduct_identifyingnumberW;
    rec->uuid              = get_compsysproduct_uuid();
    if (!match_row( table, row, cond, &status )) free_row_values( table, row );
    else row++;

    TRACE("created %u rows\n", row);
    table->num_rows = row;
    return status;
}

1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457
struct dirstack
{
    WCHAR **dirs;
    UINT   *len_dirs;
    UINT    num_dirs;
    UINT    num_allocated;
};

static struct dirstack *alloc_dirstack( UINT size )
{
    struct dirstack *dirstack;

    if (!(dirstack = heap_alloc( sizeof(*dirstack) ))) return NULL;
    if (!(dirstack->dirs = heap_alloc( sizeof(WCHAR *) * size )))
    {
        heap_free( dirstack );
        return NULL;
    }
    if (!(dirstack->len_dirs = heap_alloc( sizeof(UINT) * size )))
    {
        heap_free( dirstack->dirs );
        heap_free( dirstack );
        return NULL;
    }
    dirstack->num_dirs = 0;
    dirstack->num_allocated = size;
    return dirstack;
}

1458
static void clear_dirstack( struct dirstack *dirstack )
1459 1460 1461
{
    UINT i;
    for (i = 0; i < dirstack->num_dirs; i++) heap_free( dirstack->dirs[i] );
1462 1463 1464 1465 1466 1467
    dirstack->num_dirs = 0;
}

static void free_dirstack( struct dirstack *dirstack )
{
    clear_dirstack( dirstack );
1468 1469 1470 1471 1472 1473 1474 1475 1476
    heap_free( dirstack->dirs );
    heap_free( dirstack->len_dirs );
    heap_free( dirstack );
}

static BOOL push_dir( struct dirstack *dirstack, WCHAR *dir, UINT len )
{
    UINT size, i = dirstack->num_dirs;

1477 1478
    if (!dir) return FALSE;

1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523
    if (i == dirstack->num_allocated)
    {
        WCHAR **tmp;
        UINT *len_tmp;

        size = dirstack->num_allocated * 2;
        if (!(tmp = heap_realloc( dirstack->dirs, size * sizeof(WCHAR *) ))) return FALSE;
        dirstack->dirs = tmp;
        if (!(len_tmp = heap_realloc( dirstack->len_dirs, size * sizeof(UINT) ))) return FALSE;
        dirstack->len_dirs = len_tmp;
        dirstack->num_allocated = size;
    }
    dirstack->dirs[i] = dir;
    dirstack->len_dirs[i] = len;
    dirstack->num_dirs++;
    return TRUE;
}

static WCHAR *pop_dir( struct dirstack *dirstack, UINT *len )
{
    if (!dirstack->num_dirs)
    {
        *len = 0;
        return NULL;
    }
    dirstack->num_dirs--;
    *len = dirstack->len_dirs[dirstack->num_dirs];
    return dirstack->dirs[dirstack->num_dirs];
}

static const WCHAR *peek_dir( struct dirstack *dirstack )
{
    if (!dirstack->num_dirs) return NULL;
    return dirstack->dirs[dirstack->num_dirs - 1];
}

static WCHAR *build_glob( WCHAR drive, const WCHAR *path, UINT len )
{
    UINT i = 0;
    WCHAR *ret;

    if (!(ret = heap_alloc( (len + 6) * sizeof(WCHAR) ))) return NULL;
    ret[i++] = drive;
    ret[i++] = ':';
    ret[i++] = '\\';
1524
    if (path && len)
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534
    {
        memcpy( ret + i, path, len * sizeof(WCHAR) );
        i += len;
        ret[i++] = '\\';
    }
    ret[i++] = '*';
    ret[i] = 0;
    return ret;
}

1535
static WCHAR *build_name( WCHAR drive, const WCHAR *path )
1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563
{
    UINT i = 0, len = 0;
    const WCHAR *p;
    WCHAR *ret;

    for (p = path; *p; p++)
    {
        if (*p == '\\') len += 2;
        else len++;
    };
    if (!(ret = heap_alloc( (len + 5) * sizeof(WCHAR) ))) return NULL;
    ret[i++] = drive;
    ret[i++] = ':';
    ret[i++] = '\\';
    ret[i++] = '\\';
    for (p = path; *p; p++)
    {
        if (*p != '\\') ret[i++] = *p;
        else
        {
            ret[i++] = '\\';
            ret[i++] = '\\';
        }
    }
    ret[i] = 0;
    return ret;
}

1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603
static WCHAR *build_dirname( const WCHAR *path, UINT *ret_len )
{
    const WCHAR *p = path, *start;
    UINT len, i;
    WCHAR *ret;

    if (!isalphaW( p[0] ) || p[1] != ':' || p[2] != '\\' || p[3] != '\\' || !p[4]) return NULL;
    start = path + 4;
    len = strlenW( start );
    p = start + len - 1;
    if (*p == '\\') return NULL;

    while (p >= start && *p != '\\') { len--; p--; };
    while (p >= start && *p == '\\') { len--; p--; };

    if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
    for (i = 0, p = start; p < start + len; p++)
    {
        if (p[0] == '\\' && p[1] == '\\')
        {
            ret[i++] = '\\';
            p++;
        }
        else ret[i++] = *p;
    }
    ret[i] = 0;
    *ret_len = i;
    return ret;
}

static BOOL seen_dir( struct dirstack *dirstack, const WCHAR *path )
{
    UINT i;
    for (i = 0; i < dirstack->num_dirs; i++) if (!strcmpW( dirstack->dirs[i], path )) return TRUE;
    return FALSE;
}

/* optimize queries of the form WHERE Name='...' [OR Name='...']* */
static UINT seed_dirs( struct dirstack *dirstack, const struct expr *cond, WCHAR root, UINT *count )
{
1604
    const struct expr *left, *right;
1605

1606 1607 1608 1609
    if (!cond || cond->type != EXPR_COMPLEX) return *count = 0;

    left = cond->u.expr.left;
    right = cond->u.expr.right;
1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650
    if (cond->u.expr.op == OP_EQ)
    {
        UINT len;
        WCHAR *path;
        const WCHAR *str = NULL;

        if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL &&
            !strcmpW( left->u.propval->name, prop_nameW ) &&
            toupperW( right->u.sval[0] ) == toupperW( root ))
        {
            str = right->u.sval;
        }
        else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL &&
                 !strcmpW( right->u.propval->name, prop_nameW ) &&
                 toupperW( left->u.sval[0] ) == toupperW( root ))
        {
            str = left->u.sval;
        }
        if (str && (path = build_dirname( str, &len )))
        {
            if (seen_dir( dirstack, path ))
            {
                heap_free( path );
                return ++*count;
            }
            else if (push_dir( dirstack, path, len )) return ++*count;
            heap_free( path );
            return *count = 0;
        }
    }
    else if (cond->u.expr.op == OP_OR)
    {
        UINT left_count = 0, right_count = 0;

        if (!(seed_dirs( dirstack, left, root, &left_count ))) return *count = 0;
        if (!(seed_dirs( dirstack, right, root, &right_count ))) return *count = 0;
        return *count += left_count + right_count;
    }
    return *count = 0;
}

1651 1652 1653 1654 1655 1656 1657 1658
static WCHAR *append_path( const WCHAR *path, const WCHAR *segment, UINT *len )
{
    UINT len_path = 0, len_segment = strlenW( segment );
    WCHAR *ret;

    *len = 0;
    if (path) len_path = strlenW( path );
    if (!(ret = heap_alloc( (len_path + len_segment + 2) * sizeof(WCHAR) ))) return NULL;
1659
    if (path && len_path)
1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670
    {
        memcpy( ret, path, len_path * sizeof(WCHAR) );
        ret[len_path] = '\\';
        *len += len_path + 1;
    }
    memcpy( ret + *len, segment, len_segment * sizeof(WCHAR) );
    *len += len_segment;
    ret[*len] = 0;
    return ret;
}

1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706
static WCHAR *get_file_version( const WCHAR *filename )
{
    static const WCHAR slashW[] = {'\\',0}, fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
    VS_FIXEDFILEINFO *info;
    DWORD size;
    void *block;
    WCHAR *ret;

    if (!(ret = heap_alloc( (4 * 5 + sizeof(fmtW) / sizeof(fmtW[0])) * sizeof(WCHAR) ))) return NULL;
    if (!(size = GetFileVersionInfoSizeW( filename, NULL )) || !(block = heap_alloc( size )))
    {
        heap_free( ret );
        return NULL;
    }
    if (!GetFileVersionInfoW( filename, 0, size, block ) ||
        !VerQueryValueW( block, slashW, (void **)&info, &size ))
    {
        heap_free( block );
        heap_free( ret );
        return NULL;
    }
    sprintfW( ret, fmtW, info->dwFileVersionMS >> 16, info->dwFileVersionMS & 0xffff,
                         info->dwFileVersionLS >> 16, info->dwFileVersionLS & 0xffff );
    heap_free( block );
    return ret;
}

static enum fill_status fill_datafile( struct table *table, const struct expr *cond )
{
    static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
    struct record_datafile *rec;
    UINT i, len, row = 0, offset = 0, num_expected_rows;
    WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
    DWORD drives = GetLogicalDrives();
    WIN32_FIND_DATAW data;
    HANDLE handle;
1707
    struct dirstack *dirstack;
1708 1709 1710 1711
    enum fill_status status = FILL_STATUS_UNFILTERED;

    if (!resize_table( table, 8, sizeof(*rec) )) return FILL_STATUS_FAILED;

1712 1713
    dirstack = alloc_dirstack(2);

1714
    for (i = 0; i < 26; i++)
1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725
    {
        if (!(drives & (1 << i))) continue;

        root[0] = 'A' + i;
        if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;

        num_expected_rows = 0;
        if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );

        for (;;)
        {
1726 1727
            heap_free( glob );
            heap_free( path );
1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740
            path = pop_dir( dirstack, &len );
            if (!(glob = build_glob( root[0], path, len )))
            {
                status = FILL_STATUS_FAILED;
                goto done;
            }
            if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
            {
                do
                {
                    if (!resize_table( table, row + 1, sizeof(*rec) ))
                    {
                        status = FILL_STATUS_FAILED;
1741
                        FindClose( handle );
1742 1743 1744 1745 1746 1747 1748 1749 1750
                        goto done;
                    }
                    if (!strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW )) continue;
                    new_path = append_path( path, data.cFileName, &len );

                    if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                    {
                        if (push_dir( dirstack, new_path, len )) continue;
                        heap_free( new_path );
1751
                        FindClose( handle );
1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789
                        status = FILL_STATUS_FAILED;
                        goto done;
                    }
                    rec = (struct record_datafile *)(table->data + offset);
                    rec->name    = build_name( root[0], new_path );
                    rec->version = get_file_version( rec->name );
                    if (!match_row( table, row, cond, &status ))
                    {
                        free_row_values( table, row );
                        continue;
                    }
                    else if (num_expected_rows && row == num_expected_rows - 1)
                    {
                        row++;
                        FindClose( handle );
                        status = FILL_STATUS_FILTERED;
                        goto done;
                    }
                    offset += sizeof(*rec);
                    row++;
                }
                while (FindNextFileW( handle, &data ));
                FindClose( handle );
            }
            if (!peek_dir( dirstack )) break;
        }
    }

done:
    free_dirstack( dirstack );
    heap_free( glob );
    heap_free( path );

    TRACE("created %u rows\n", row);
    table->num_rows = row;
    return status;
}

1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818
static UINT32 get_pixelsperxlogicalinch(void)
{
    HDC hdc = GetDC( NULL );
    UINT32 ret;

    if (!hdc) return 96;
    ret = GetDeviceCaps( hdc, LOGPIXELSX );
    ReleaseDC( NULL, hdc );
    return ret;
}

static enum fill_status fill_desktopmonitor( struct table *table, const struct expr *cond )
{
    struct record_desktopmonitor *rec;
    enum fill_status status = FILL_STATUS_UNFILTERED;
    UINT row = 0;

    if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;

    rec = (struct record_desktopmonitor *)table->data;
    rec->pixelsperxlogicalinch = get_pixelsperxlogicalinch();

    if (match_row( table, row, cond, &status )) row++;

    TRACE("created %u rows\n", row);
    table->num_rows = row;
    return status;
}

1819 1820 1821 1822
static enum fill_status fill_directory( struct table *table, const struct expr *cond )
{
    static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
    struct record_directory *rec;
1823
    UINT i, len, row = 0, offset = 0, num_expected_rows;
1824 1825 1826 1827
    WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
    DWORD drives = GetLogicalDrives();
    WIN32_FIND_DATAW data;
    HANDLE handle;
1828
    struct dirstack *dirstack;
1829 1830
    enum fill_status status = FILL_STATUS_UNFILTERED;

1831
    if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1832

1833 1834
    dirstack = alloc_dirstack(2);

1835
    for (i = 0; i < 26; i++)
1836 1837 1838 1839 1840 1841
    {
        if (!(drives & (1 << i))) continue;

        root[0] = 'A' + i;
        if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;

1842 1843 1844
        num_expected_rows = 0;
        if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );

1845 1846
        for (;;)
        {
1847 1848
            heap_free( glob );
            heap_free( path );
1849 1850 1851 1852 1853 1854 1855 1856 1857 1858
            path = pop_dir( dirstack, &len );
            if (!(glob = build_glob( root[0], path, len )))
            {
                status = FILL_STATUS_FAILED;
                goto done;
            }
            if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
            {
                do
                {
1859
                    if (!resize_table( table, row + 1, sizeof(*rec) ))
1860
                    {
1861
                        FindClose( handle );
1862 1863
                        status = FILL_STATUS_FAILED;
                        goto done;
1864 1865 1866 1867 1868 1869 1870 1871 1872
                    }
                    if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
                        !strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW ))
                        continue;

                    new_path = append_path( path, data.cFileName, &len );
                    if (!(push_dir( dirstack, new_path, len )))
                    {
                        heap_free( new_path );
1873
                        FindClose( handle );
1874 1875 1876 1877 1878
                        status = FILL_STATUS_FAILED;
                        goto done;
                    }
                    rec = (struct record_directory *)(table->data + offset);
                    rec->accessmask = FILE_ALL_ACCESS;
1879
                    rec->name       = build_name( root[0], new_path );
1880 1881 1882 1883 1884
                    if (!match_row( table, row, cond, &status ))
                    {
                        free_row_values( table, row );
                        continue;
                    }
1885 1886 1887 1888 1889 1890 1891
                    else if (num_expected_rows && row == num_expected_rows - 1)
                    {
                        row++;
                        FindClose( handle );
                        status = FILL_STATUS_FILTERED;
                        goto done;
                    }
1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911
                    offset += sizeof(*rec);
                    row++;
                }
                while (FindNextFileW( handle, &data ));
                FindClose( handle );
            }
            if (!peek_dir( dirstack )) break;
        }
    }

done:
    free_dirstack( dirstack );
    heap_free( glob );
    heap_free( path );

    TRACE("created %u rows\n", row);
    table->num_rows = row;
    return status;
}

1912 1913 1914 1915 1916 1917
static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
{
    WCHAR root[] = {'\\','\\','.','\\','A',':',0};
    ULARGE_INTEGER free;
    DISK_GEOMETRY_EX info;
    HANDLE handle;
1918
    DWORD bytes_returned;
1919 1920 1921 1922 1923 1924 1925 1926

    free.QuadPart = 512 * 1024 * 1024;
    GetDiskFreeSpaceExW( dir, NULL, NULL, &free );

    root[4] = dir[0];
    handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
    if (handle != INVALID_HANDLE_VALUE)
    {
1927
        if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), &bytes_returned, NULL ))
1928 1929 1930 1931 1932 1933
            *disksize = info.DiskSize.QuadPart;
        CloseHandle( handle );
    }
    return free.QuadPart;
}

1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946
static enum fill_status fill_diskdrive( struct table *table, const struct expr *cond )
{
    static const WCHAR fmtW[] =
        {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','%','u',0};
    WCHAR device_id[sizeof(fmtW)/sizeof(fmtW[0]) + 10], root[] = {'A',':','\\',0};
    struct record_diskdrive *rec;
    UINT i, row = 0, offset = 0, index = 0, type;
    UINT64 size = 1024 * 1024 * 1024;
    DWORD drives = GetLogicalDrives();
    enum fill_status status = FILL_STATUS_UNFILTERED;

    if (!resize_table( table, 2, sizeof(*rec) )) return FILL_STATUS_FAILED;

1947
    for (i = 0; i < 26; i++)
1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968
    {
        if (drives & (1 << i))
        {
            root[0] = 'A' + i;
            type = GetDriveTypeW( root );
            if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
                continue;

            if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;

            rec = (struct record_diskdrive *)(table->data + offset);
            sprintfW( device_id, fmtW, index );
            rec->device_id     = heap_strdupW( device_id );
            rec->index         = index;
            rec->interfacetype = diskdrive_interfacetypeW;
            rec->manufacturer  = diskdrive_manufacturerW;
            if (type == DRIVE_FIXED)
                rec->mediatype = diskdrive_mediatype_fixedW;
            else
                rec->mediatype = diskdrive_mediatype_removableW;
            rec->model         = diskdrive_modelW;
1969
            rec->pnpdevice_id  = diskdrive_pnpdeviceidW;
1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997
            rec->serialnumber  = diskdrive_serialW;
            get_freespace( root, &size );
            rec->size          = size;
            if (!match_row( table, row, cond, &status ))
            {
                free_row_values( table, row );
                continue;
            }
            offset += sizeof(*rec);
            index++;
            row++;
        }
    }
    TRACE("created %u rows\n", row);
    table->num_rows = row;
    return status;
}

static WCHAR *get_filesystem( const WCHAR *root )
{
    static const WCHAR ntfsW[] = {'N','T','F','S',0};
    WCHAR buffer[MAX_PATH + 1];

    if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
        return heap_strdupW( buffer );
    return heap_strdupW( ntfsW );
}

1998
static enum fill_status fill_diskpartition( struct table *table, const struct expr *cond )
1999 2000 2001 2002 2003
{
    static const WCHAR fmtW[] =
        {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
    WCHAR device_id[32], root[] = {'A',':','\\',0};
    struct record_diskpartition *rec;
2004
    UINT i, row = 0, offset = 0, type, index = 0;
2005 2006
    UINT64 size = 1024 * 1024 * 1024;
    DWORD drives = GetLogicalDrives();
2007
    enum fill_status status = FILL_STATUS_UNFILTERED;
2008

2009
    if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
2010

2011
    for (i = 0; i < 26; i++)
2012 2013 2014 2015 2016 2017 2018 2019
    {
        if (drives & (1 << i))
        {
            root[0] = 'A' + i;
            type = GetDriveTypeW( root );
            if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
                continue;

2020 2021
            if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;

2022 2023
            rec = (struct record_diskpartition *)(table->data + offset);
            rec->bootable       = (i == 2) ? -1 : 0;
2024
            rec->bootpartition  = (i == 2) ? -1 : 0;
2025 2026 2027 2028 2029 2030 2031 2032 2033
            sprintfW( device_id, fmtW, index );
            rec->device_id      = heap_strdupW( device_id );
            rec->diskindex      = index;
            rec->index          = 0;
            rec->pnpdevice_id   = heap_strdupW( device_id );
            get_freespace( root, &size );
            rec->size           = size;
            rec->startingoffset = 0;
            rec->type           = get_filesystem( root );
2034 2035 2036 2037 2038
            if (!match_row( table, row, cond, &status ))
            {
                free_row_values( table, row );
                continue;
            }
2039
            offset += sizeof(*rec);
2040
            row++;
2041 2042 2043
            index++;
        }
    }
2044 2045 2046
    TRACE("created %u rows\n", row);
    table->num_rows = row;
    return status;
2047 2048
}

2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101
static WCHAR *get_ip4_string( DWORD addr )
{
    static const WCHAR fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
    WCHAR *ret;

    if (!(ret = heap_alloc( sizeof("ddd.ddd.ddd.ddd") * sizeof(WCHAR) ))) return NULL;
    sprintfW( ret, fmtW, (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff );
    return ret;
}

static enum fill_status fill_ip4routetable( struct table *table, const struct expr *cond )
{
    struct record_ip4routetable *rec;
    UINT i, row = 0, offset = 0, size = 0;
    MIB_IPFORWARDTABLE *forwards;
    enum fill_status status = FILL_STATUS_UNFILTERED;

    if (GetIpForwardTable( NULL, &size, TRUE ) != ERROR_INSUFFICIENT_BUFFER) return FILL_STATUS_FAILED;
    if (!(forwards = heap_alloc( size ))) return FILL_STATUS_FAILED;
    if (GetIpForwardTable( forwards, &size, TRUE ))
    {
        heap_free( forwards );
        return FILL_STATUS_FAILED;
    }
    if (!resize_table( table, forwards->dwNumEntries, sizeof(*rec) ))
    {
        heap_free( forwards );
        return FILL_STATUS_FAILED;
    }

    for (i = 0; i < forwards->dwNumEntries; i++)
    {
        rec = (struct record_ip4routetable *)(table->data + offset);

        rec->destination    = get_ip4_string( ntohl(forwards->table[i].dwForwardDest) );
        rec->interfaceindex = forwards->table[i].dwForwardIfIndex;
        rec->nexthop        = get_ip4_string( ntohl(forwards->table[i].dwForwardNextHop) );

        if (!match_row( table, row, cond, &status ))
        {
            free_row_values( table, row );
            continue;
        }
        offset += sizeof(*rec);
        row++;
    }
    TRACE("created %u rows\n", row);
    table->num_rows = row;

    heap_free( forwards );
    return status;
}

2102 2103 2104 2105 2106 2107
static WCHAR *get_volumename( const WCHAR *root )
{
    WCHAR buf[MAX_PATH + 1] = {0};
    GetVolumeInformationW( root, buf, sizeof(buf)/sizeof(buf[0]), NULL, NULL, NULL, NULL, 0 );
    return heap_strdupW( buf );
}
2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118
static WCHAR *get_volumeserialnumber( const WCHAR *root )
{
    static const WCHAR fmtW[] = {'%','0','8','X',0};
    DWORD serial = 0;
    WCHAR buffer[9];

    GetVolumeInformationW( root, NULL, 0, &serial, NULL, NULL, NULL, 0 );
    sprintfW( buffer, fmtW, serial );
    return heap_strdupW( buffer );
}

2119
static enum fill_status fill_logicaldisk( struct table *table, const struct expr *cond )
2120 2121 2122 2123
{
    static const WCHAR fmtW[] = {'%','c',':',0};
    WCHAR device_id[3], root[] = {'A',':','\\',0};
    struct record_logicaldisk *rec;
2124
    UINT i, row = 0, offset = 0, type;
2125 2126
    UINT64 size = 1024 * 1024 * 1024;
    DWORD drives = GetLogicalDrives();
2127
    enum fill_status status = FILL_STATUS_UNFILTERED;
2128

2129
    if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
2130

2131
    for (i = 0; i < 26; i++)
2132 2133 2134 2135 2136 2137 2138 2139
    {
        if (drives & (1 << i))
        {
            root[0] = 'A' + i;
            type = GetDriveTypeW( root );
            if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
                continue;

2140 2141
            if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;

2142 2143
            rec = (struct record_logicaldisk *)(table->data + offset);
            sprintfW( device_id, fmtW, 'A' + i );
2144 2145 2146 2147 2148 2149
            rec->device_id          = heap_strdupW( device_id );
            rec->drivetype          = type;
            rec->filesystem         = get_filesystem( root );
            rec->freespace          = get_freespace( root, &size );
            rec->name               = heap_strdupW( device_id );
            rec->size               = size;
2150
            rec->volumename         = get_volumename( root );
2151
            rec->volumeserialnumber = get_volumeserialnumber( root );
2152 2153 2154 2155 2156
            if (!match_row( table, row, cond, &status ))
            {
                free_row_values( table, row );
                continue;
            }
2157
            offset += sizeof(*rec);
2158
            row++;
2159 2160
        }
    }
2161 2162 2163
    TRACE("created %u rows\n", row);
    table->num_rows = row;
    return status;
2164 2165
}

2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179
static UINT16 get_connection_status( IF_OPER_STATUS status )
{
    switch (status)
    {
    case IfOperStatusDown:
        return 0; /* Disconnected */
    case IfOperStatusUp:
        return 2; /* Connected */
    default:
        ERR("unhandled status %u\n", status);
        break;
    }
    return 0;
}
2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190
static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
{
    static const WCHAR fmtW[] =
        {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
         '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
    WCHAR *ret;

    if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
    sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
    return ret;
}
2191
static const WCHAR *get_adaptertype( DWORD type, int *physical )
2192 2193 2194 2195 2196 2197 2198 2199
{
    static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
    static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
    static const WCHAR firewireW[] = {'1','3','9','4',0};
    static const WCHAR tunnelW[]   = {'T','u','n','n','e','l',0};

    switch (type)
    {
2200 2201 2202 2203 2204
    case IF_TYPE_ETHERNET_CSMACD: *physical = -1; return ethernetW;
    case IF_TYPE_IEEE80211:       *physical = -1; return wirelessW;
    case IF_TYPE_IEEE1394:        *physical = -1; return firewireW;
    case IF_TYPE_TUNNEL:          *physical = 0; return tunnelW;
    default:                      *physical = 0; return NULL;
2205 2206
    }
}
2207

2208
static enum fill_status fill_networkadapter( struct table *table, const struct expr *cond )
2209 2210 2211 2212 2213
{
    static const WCHAR fmtW[] = {'%','u',0};
    WCHAR device_id[11];
    struct record_networkadapter *rec;
    IP_ADAPTER_ADDRESSES *aa, *buffer;
2214
    UINT row = 0, offset = 0, count = 0;
2215
    DWORD size = 0, ret;
2216
    int physical;
2217
    enum fill_status status = FILL_STATUS_UNFILTERED;
2218

2219
    ret = GetAdaptersAddresses( WS_AF_UNSPEC, 0, NULL, NULL, &size );
2220
    if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
2221

2222
    if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
2223
    if (GetAdaptersAddresses( WS_AF_UNSPEC, 0, NULL, buffer, &size ))
2224 2225
    {
        heap_free( buffer );
2226
        return FILL_STATUS_FAILED;
2227
    }
2228 2229 2230 2231
    for (aa = buffer; aa; aa = aa->Next)
    {
        if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
    }
2232
    if (!resize_table( table, count, sizeof(*rec) ))
2233 2234
    {
        heap_free( buffer );
2235
        return FILL_STATUS_FAILED;
2236 2237 2238
    }
    for (aa = buffer; aa; aa = aa->Next)
    {
2239 2240
        if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;

2241 2242
        rec = (struct record_networkadapter *)(table->data + offset);
        sprintfW( device_id, fmtW, aa->u.s.IfIndex );
2243
        rec->adaptertype          = get_adaptertype( aa->IfType, &physical );
2244
        rec->device_id            = heap_strdupW( device_id );
2245
        rec->index                = aa->u.s.IfIndex;
2246
        rec->interface_index      = aa->u.s.IfIndex;
2247
        rec->mac_address          = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
2248
        rec->manufacturer         = compsys_manufacturerW;
2249
        rec->name                 = heap_strdupW( aa->FriendlyName );
2250
        rec->netconnection_status = get_connection_status( aa->OperStatus );
2251
        rec->physicaladapter      = physical;
2252
        rec->pnpdevice_id         = networkadapter_pnpdeviceidW;
2253
        rec->speed                = 1000000;
2254 2255 2256 2257 2258
        if (!match_row( table, row, cond, &status ))
        {
            free_row_values( table, row );
            continue;
        }
2259
        offset += sizeof(*rec);
2260
        row++;
2261
    }
2262 2263
    TRACE("created %u rows\n", row);
    table->num_rows = row;
2264 2265

    heap_free( buffer );
2266
    return status;
2267 2268
}

2269 2270 2271
static WCHAR *get_dnshostname( IP_ADAPTER_UNICAST_ADDRESS *addr )
{
    const SOCKET_ADDRESS *sa = &addr->Address;
2272
    WCHAR buf[WS_NI_MAXHOST];
2273 2274 2275

    if (!addr) return NULL;
    if (GetNameInfoW( sa->lpSockaddr, sa->iSockaddrLength, buf, sizeof(buf)/sizeof(buf[0]), NULL,
2276
                      0, WS_NI_NAMEREQD )) return NULL;
2277 2278
    return heap_strdupW( buf );
}
2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310
static struct array *get_defaultipgateway( IP_ADAPTER_GATEWAY_ADDRESS *list )
{
    IP_ADAPTER_GATEWAY_ADDRESS *gateway;
    struct array *ret;
    ULONG buflen, i = 0, count = 0;
    WCHAR **ptr, buf[54]; /* max IPv6 address length */

    if (!list) return NULL;
    for (gateway = list; gateway; gateway = gateway->Next) count++;

    if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
    if (!(ptr = heap_alloc( sizeof(*ptr) * count )))
    {
        heap_free( ret );
        return NULL;
    }
    for (gateway = list; gateway; gateway = gateway->Next)
    {
        buflen = sizeof(buf)/sizeof(buf[0]);
        if (WSAAddressToStringW( gateway->Address.lpSockaddr, gateway->Address.iSockaddrLength,
                                 NULL, buf, &buflen) || !(ptr[i++] = heap_strdupW( buf )))
        {
            for (; i > 0; i--) heap_free( ptr[i - 1] );
            heap_free( ptr );
            heap_free( ret );
            return NULL;
        }
    }
    ret->count = count;
    ret->ptr   = ptr;
    return ret;
}
2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343
static struct array *get_dnsserversearchorder( IP_ADAPTER_DNS_SERVER_ADDRESS *list )
{
    IP_ADAPTER_DNS_SERVER_ADDRESS *server;
    struct array *ret;
    ULONG buflen, i = 0, count = 0;
    WCHAR **ptr, *p, buf[54]; /* max IPv6 address length */

    if (!list) return NULL;
    for (server = list; server; server = server->Next) count++;

    if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
    if (!(ptr = heap_alloc( sizeof(*ptr) * count )))
    {
        heap_free( ret );
        return NULL;
    }
    for (server = list; server; server = server->Next)
    {
        buflen = sizeof(buf)/sizeof(buf[0]);
        if (WSAAddressToStringW( server->Address.lpSockaddr, server->Address.iSockaddrLength,
                                 NULL, buf, &buflen) || !(ptr[i++] = heap_strdupW( buf )))
        {
            for (; i > 0; i--) heap_free( ptr[i - 1] );
            heap_free( ptr );
            heap_free( ret );
            return NULL;
        }
        if ((p = strrchrW( ptr[i - 1], ':' ))) *p = 0;
    }
    ret->count = count;
    ret->ptr   = ptr;
    return ret;
}
2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354
static WCHAR *get_settingid( UINT32 index )
{
    GUID guid;
    WCHAR *ret, *str;
    memset( &guid, 0, sizeof(guid) );
    guid.Data1 = index;
    UuidToStringW( &guid, &str );
    ret = heap_strdupW( str );
    RpcStringFreeW( &str );
    return ret;
}
2355

2356 2357 2358 2359 2360 2361 2362 2363
static enum fill_status fill_networkadapterconfig( struct table *table, const struct expr *cond )
{
    struct record_networkadapterconfig *rec;
    IP_ADAPTER_ADDRESSES *aa, *buffer;
    UINT row = 0, offset = 0, count = 0;
    DWORD size = 0, ret;
    enum fill_status status = FILL_STATUS_UNFILTERED;

2364
    ret = GetAdaptersAddresses( WS_AF_UNSPEC, GAA_FLAG_INCLUDE_ALL_GATEWAYS, NULL, NULL, &size );
2365 2366 2367
    if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;

    if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
2368
    if (GetAdaptersAddresses( WS_AF_UNSPEC, GAA_FLAG_INCLUDE_ALL_GATEWAYS, NULL, buffer, &size ))
2369 2370 2371 2372
    {
        heap_free( buffer );
        return FILL_STATUS_FAILED;
    }
2373 2374 2375 2376
    for (aa = buffer; aa; aa = aa->Next)
    {
        if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
    }
2377 2378 2379 2380 2381 2382 2383
    if (!resize_table( table, count, sizeof(*rec) ))
    {
        heap_free( buffer );
        return FILL_STATUS_FAILED;
    }
    for (aa = buffer; aa; aa = aa->Next)
    {
2384 2385
        if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;

2386
        rec = (struct record_networkadapterconfig *)(table->data + offset);
2387 2388 2389 2390 2391 2392 2393 2394 2395
        rec->defaultipgateway     = get_defaultipgateway( aa->FirstGatewayAddress );
        rec->description          = heap_strdupW( aa->Description );
        rec->dhcpenabled          = -1;
        rec->dnshostname          = get_dnshostname( aa->FirstUnicastAddress );
        rec->dnsserversearchorder = get_dnsserversearchorder( aa->FirstDnsServerAddress );
        rec->index                = aa->u.s.IfIndex;
        rec->ipconnectionmetric   = 20;
        rec->ipenabled            = -1;
        rec->mac_address          = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
2396
        rec->settingid            = get_settingid( rec->index );
2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411
        if (!match_row( table, row, cond, &status ))
        {
            free_row_values( table, row );
            continue;
        }
        offset += sizeof(*rec);
        row++;
    }
    TRACE("created %u rows\n", row);
    table->num_rows = row;

    heap_free( buffer );
    return status;
}

2412 2413 2414 2415 2416 2417 2418 2419 2420
static enum fill_status fill_physicalmemory( struct table *table, const struct expr *cond )
{
    struct record_physicalmemory *rec;
    enum fill_status status = FILL_STATUS_UNFILTERED;
    UINT row = 0;

    if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;

    rec = (struct record_physicalmemory *)table->data;
2421 2422
    rec->capacity   = get_total_physical_memory();
    rec->memorytype = 9; /* RAM */
2423 2424 2425 2426 2427 2428 2429 2430
    if (!match_row( table, row, cond, &status )) free_row_values( table, row );
    else row++;

    TRACE("created %u rows\n", row);
    table->num_rows = row;
    return status;
}

2431 2432 2433 2434 2435
static enum fill_status fill_printer( struct table *table, const struct expr *cond )
{
    struct record_printer *rec;
    enum fill_status status = FILL_STATUS_UNFILTERED;
    PRINTER_INFO_2W *info;
2436
    DWORD i, offset = 0, count = 0, size = 0, num_rows = 0;
2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467

    EnumPrintersW( PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &size, &count );
    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return FILL_STATUS_FAILED;

    if (!(info = heap_alloc( size ))) return FILL_STATUS_FAILED;
    if (!EnumPrintersW( PRINTER_ENUM_LOCAL, NULL, 2, (BYTE *)info, size, &size, &count ))
    {
        heap_free( info );
        return FILL_STATUS_FAILED;
    }
    if (!resize_table( table, count, sizeof(*rec) ))
    {
        heap_free( info );
        return FILL_STATUS_FAILED;
    }

    for (i = 0; i < count; i++)
    {
        rec = (struct record_printer *)(table->data + offset);
        rec->attributes           = info[i].Attributes;
        rec->drivername           = heap_strdupW( info[i].pDriverName );
        rec->horizontalresolution = info[i].pDevMode->u1.s1.dmPrintQuality;
        rec->local                = -1;
        rec->name                 = heap_strdupW( info[i].pPrinterName );
        rec->network              = 0;
        if (!match_row( table, i, cond, &status ))
        {
            free_row_values( table, i );
            continue;
        }
        offset += sizeof(*rec);
2468
        num_rows++;
2469
    }
2470 2471
    TRACE("created %u rows\n", num_rows);
    table->num_rows = num_rows;
2472 2473 2474 2475 2476

    heap_free( info );
    return status;
}

2477 2478 2479 2480 2481 2482
static WCHAR *get_cmdline( DWORD process_id )
{
    if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
    return NULL; /* FIXME handle different process case */
}

2483
static enum fill_status fill_process( struct table *table, const struct expr *cond )
2484
{
2485 2486
    static const WCHAR fmtW[] = {'%','u',0};
    WCHAR handle[11];
2487 2488 2489
    struct record_process *rec;
    PROCESSENTRY32W entry;
    HANDLE snap;
2490
    enum fill_status status = FILL_STATUS_FAILED;
2491
    UINT row = 0, offset = 0;
2492 2493

    snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
2494
    if (snap == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED;
2495 2496 2497

    entry.dwSize = sizeof(entry);
    if (!Process32FirstW( snap, &entry )) goto done;
2498
    if (!resize_table( table, 8, sizeof(*rec) )) goto done;
2499 2500 2501

    do
    {
2502 2503
        if (!resize_table( table, row + 1, sizeof(*rec) )) goto done;

2504
        rec = (struct record_process *)(table->data + offset);
2505 2506 2507
        rec->caption        = heap_strdupW( entry.szExeFile );
        rec->commandline    = get_cmdline( entry.th32ProcessID );
        rec->description    = heap_strdupW( entry.szExeFile );
2508
        sprintfW( handle, fmtW, entry.th32ProcessID );
2509 2510 2511 2512 2513 2514 2515
        rec->handle         = heap_strdupW( handle );
        rec->name           = heap_strdupW( entry.szExeFile );
        rec->process_id     = entry.th32ProcessID;
        rec->pprocess_id    = entry.th32ParentProcessID;
        rec->thread_count   = entry.cntThreads;
        rec->workingsetsize = 0;
        rec->get_owner      = process_get_owner;
2516 2517 2518 2519 2520
        if (!match_row( table, row, cond, &status ))
        {
            free_row_values( table, row );
            continue;
        }
2521
        offset += sizeof(*rec);
2522
        row++;
2523 2524
    } while (Process32NextW( snap, &entry ));

2525 2526
    TRACE("created %u rows\n", row);
    table->num_rows = row;
2527
    status = FILL_STATUS_UNFILTERED;
2528 2529 2530

done:
    CloseHandle( snap );
2531
    return status;
2532 2533
}

2534 2535 2536
static inline void do_cpuid( unsigned int ax, unsigned int *p )
{
#ifdef __i386__
2537 2538 2539
#ifdef _MSC_VER
    __cpuid(p, ax);
#else
2540 2541 2542 2543 2544 2545 2546
    __asm__("pushl %%ebx\n\t"
                "cpuid\n\t"
                "movl %%ebx, %%esi\n\t"
                "popl %%ebx"
                : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
                :  "0" (ax));
#endif
2547
#endif
2548
}
2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564
static const WCHAR *get_osarchitecture(void)
{
    SYSTEM_INFO info;
    GetNativeSystemInfo( &info );
    if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
    return os_32bitW;
}
static void get_processor_caption( WCHAR *caption )
{
    static const WCHAR fmtW[] =
        {'%','s',' ','F','a','m','i','l','y',' ','%','u',' ',
         'M','o','d','e','l',' ','%','u',' ','S','t','e','p','p','i','n','g',' ','%','u',0};
    static const WCHAR x86W[] = {'x','8','6',0};
    static const WCHAR intel64W[] = {'I','n','t','e','l','6','4',0};
    const WCHAR *arch = (get_osarchitecture() == os_32bitW) ? x86W : intel64W;
    unsigned int regs[4] = {0, 0, 0, 0};
2565

2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577
    do_cpuid( 1, regs );
    sprintfW( caption, fmtW, arch, (regs[0] & (15 << 8)) >> 8, (regs[0] & (15 << 4)) >> 4, regs[0] & 15 );
}
static void get_processor_version( WCHAR *version )
{
    static const WCHAR fmtW[] =
        {'M','o','d','e','l',' ','%','u',',',' ','S','t','e','p','p','i','n','g',' ','%','u',0};
    unsigned int regs[4] = {0, 0, 0, 0};

    do_cpuid( 1, regs );
    sprintfW( version, fmtW, (regs[0] & (15 << 4)) >> 4, regs[0] & 15 );
}
2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590
static void get_processor_id( WCHAR *processor_id )
{
    static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
    unsigned int regs[4] = {0, 0, 0, 0};

    do_cpuid( 1, regs );
    sprintfW( processor_id, fmtW, regs[3], regs[0] );
}
static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
{
    unsigned int i;
    unsigned char *p = (unsigned char *)regs;

2591
    for (i = 0; i < len; i++) { buffer[i] = *p++; }
2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619
    buffer[i] = 0;
}
static void get_processor_manufacturer( WCHAR *manufacturer )
{
    unsigned int tmp, regs[4] = {0, 0, 0, 0};

    do_cpuid( 0, regs );
    tmp = regs[2];      /* swap edx and ecx */
    regs[2] = regs[3];
    regs[3] = tmp;

    regs_to_str( regs + 1, 12, manufacturer );
}
static void get_processor_name( WCHAR *name )
{
    unsigned int regs[4] = {0, 0, 0, 0};

    do_cpuid( 0x80000000, regs );
    if (regs[0] >= 0x80000004)
    {
        do_cpuid( 0x80000002, regs );
        regs_to_str( regs, 16, name );
        do_cpuid( 0x80000003, regs );
        regs_to_str( regs, 16, name + 16 );
        do_cpuid( 0x80000004, regs );
        regs_to_str( regs, 16, name + 32 );
    }
}
2620
static UINT get_processor_currentclockspeed( UINT index )
2621
{
2622
    PROCESSOR_POWER_INFORMATION *info;
2623
    UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
2624 2625 2626 2627 2628
    NTSTATUS status;

    if ((info = heap_alloc( size )))
    {
        status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643
        if (!status) ret = info[index].CurrentMhz;
        heap_free( info );
    }
    return ret;
}
static UINT get_processor_maxclockspeed( UINT index )
{
    PROCESSOR_POWER_INFORMATION *info;
    UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
    NTSTATUS status;

    if ((info = heap_alloc( size )))
    {
        status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
        if (!status) ret = info[index].MaxMhz;
2644 2645 2646
        heap_free( info );
    }
    return ret;
2647
}
2648

2649
static enum fill_status fill_processor( struct table *table, const struct expr *cond )
2650 2651
{
    static const WCHAR fmtW[] = {'C','P','U','%','u',0};
2652
    WCHAR caption[100], device_id[14], processor_id[17], manufacturer[13], name[49] = {0}, version[50];
2653
    struct record_processor *rec;
2654
    UINT i, offset = 0, num_rows = 0, num_cores, num_logical_processors, count = get_processor_count();
2655
    enum fill_status status = FILL_STATUS_UNFILTERED;
2656

2657
    if (!resize_table( table, count, sizeof(*rec) )) return FILL_STATUS_FAILED;
2658

2659
    get_processor_caption( caption );
2660 2661 2662
    get_processor_id( processor_id );
    get_processor_manufacturer( manufacturer );
    get_processor_name( name );
2663
    get_processor_version( version );
2664

2665 2666
    num_logical_processors = get_logical_processor_count( &num_cores ) / count;
    num_cores /= count;
2667

2668 2669 2670
    for (i = 0; i < count; i++)
    {
        rec = (struct record_processor *)(table->data + offset);
2671
        rec->addresswidth           = get_osarchitecture() == os_32bitW ? 32 : 64;
2672
        rec->caption                = heap_strdupW( caption );
2673
        rec->cpu_status             = 1; /* CPU Enabled */
2674
        rec->currentclockspeed      = get_processor_currentclockspeed( i );
2675 2676
        rec->datawidth              = get_osarchitecture() == os_32bitW ? 32 : 64;
        rec->description            = heap_strdupW( caption );
2677
        sprintfW( device_id, fmtW, i );
2678
        rec->device_id              = heap_strdupW( device_id );
2679
        rec->family                 = 2; /* Unknown */
2680
        rec->manufacturer           = heap_strdupW( manufacturer );
2681
        rec->maxclockspeed          = get_processor_maxclockspeed( i );
2682
        rec->name                   = heap_strdupW( name );
2683
        rec->num_cores              = num_cores;
2684 2685
        rec->num_logical_processors = num_logical_processors;
        rec->processor_id           = heap_strdupW( processor_id );
2686
        rec->processortype          = 3; /* central processor */
2687
        rec->unique_id              = NULL;
2688
        rec->version                = heap_strdupW( version );
2689 2690 2691 2692 2693
        if (!match_row( table, i, cond, &status ))
        {
            free_row_values( table, i );
            continue;
        }
2694
        offset += sizeof(*rec);
2695
        num_rows++;
2696
    }
2697

2698 2699
    TRACE("created %u rows\n", num_rows);
    table->num_rows = num_rows;
2700
    return status;
2701 2702
}

2703 2704 2705 2706 2707
static WCHAR *get_lastbootuptime(void)
{
    static const WCHAR fmtW[] =
        {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
         '.','%','0','6','u','+','0','0','0',0};
2708 2709
    SYSTEM_TIMEOFDAY_INFORMATION ti;
    TIME_FIELDS tf;
2710 2711 2712
    WCHAR *ret;

    if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2713 2714 2715 2716

    NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
    RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
    sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
2717 2718
    return ret;
}
2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743
static WCHAR *get_localdatetime(void)
{
    static const WCHAR fmtW[] =
        {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
         '.','%','0','6','u','%','+','0','3','d',0};
    TIME_ZONE_INFORMATION tzi;
    SYSTEMTIME st;
    WCHAR *ret;
    DWORD Status;
    LONG Bias;

    Status = GetTimeZoneInformation(&tzi);

    if(Status == TIME_ZONE_ID_INVALID) return NULL;
    Bias = tzi.Bias;
    if(Status == TIME_ZONE_ID_DAYLIGHT)
        Bias+= tzi.DaylightBias;
    else
        Bias+= tzi.StandardBias;
    if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;

    GetLocalTime(&st);
    sprintfW( ret, fmtW, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds * 1000, -Bias);
    return ret;
}
2744 2745
static WCHAR *get_systemdirectory(void)
{
2746
    void *redir;
2747
    WCHAR *ret;
2748

2749 2750 2751 2752 2753 2754
    if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
    Wow64DisableWow64FsRedirection( &redir );
    GetSystemDirectoryW( ret, MAX_PATH );
    Wow64RevertWow64FsRedirection( redir );
    return ret;
}
2755 2756 2757 2758 2759 2760 2761
static WCHAR *get_codeset(void)
{
    static const WCHAR fmtW[] = {'%','u',0};
    WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
    if (ret) sprintfW( ret, fmtW, GetACP() );
    return ret;
}
2762 2763 2764 2765 2766 2767
static WCHAR *get_countrycode(void)
{
    WCHAR *ret = heap_alloc( 6 * sizeof(WCHAR) );
    if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY, ret, 6 );
    return ret;
}
2768 2769 2770 2771 2772 2773
static WCHAR *get_locale(void)
{
    WCHAR *ret = heap_alloc( 5 * sizeof(WCHAR) );
    if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, ret, 5 );
    return ret;
}
2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853
static WCHAR *get_osbuildnumber( OSVERSIONINFOEXW *ver )
{
    static const WCHAR fmtW[] = {'%','u',0};
    WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
    if (ret) sprintfW( ret, fmtW, ver->dwBuildNumber );
    return ret;
}
static WCHAR *get_oscaption( OSVERSIONINFOEXW *ver )
{
    static const WCHAR windowsW[] =
        {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' '};
    static const WCHAR win2000W[] =
        {'2','0','0','0',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
    static const WCHAR win2003W[] =
        {'S','e','r','v','e','r',' ','2','0','0','3',' ','S','t','a','n','d','a','r','d',' ','E','d','i','t','i','o','n',0};
    static const WCHAR winxpW[] =
        {'X','P',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
    static const WCHAR winxp64W[] =
        {'X','P',' ','P','r','o','f','e','s','s','i','o','n','a','l',' ','x','6','4',' ','E','d','i','t','i','o','n',0};
    static const WCHAR vistaW[] =
        {'V','i','s','t','a',' ','U','l','t','i','m','a','t','e',0};
    static const WCHAR win2008W[] =
        {'S','e','r','v','e','r',' ','2','0','0','8',' ','S','t','a','n','d','a','r','d',0};
    static const WCHAR win7W[] =
        {'7',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
    static const WCHAR win2008r2W[] =
        {'S','e','r','v','e','r',' ','2','0','0','8',' ','R','2',' ','S','t','a','n','d','a','r','d',0};
    static const WCHAR win8W[] =
        {'8',' ','P','r','o',0};
    static const WCHAR win81W[] =
        {'8','.','1',' ','P','r','o',0};
    static const WCHAR win10W[] =
        {'1','0',' ','P','r','o',0};
    int len = sizeof(windowsW)/sizeof(windowsW[0]);
    WCHAR *ret;

    if (!(ret = heap_alloc( len * sizeof(WCHAR) + sizeof(win2003W) ))) return NULL;
    memcpy( ret, windowsW, sizeof(windowsW) );
    if (ver->dwMajorVersion == 10 && ver->dwMinorVersion == 0) memcpy( ret + len, win10W, sizeof(win10W) );
    else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 3) memcpy( ret + len, win8W, sizeof(win8W) );
    else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 2) memcpy( ret + len, win81W, sizeof(win81W) );
    else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 1)
    {
        if (ver->wProductType == VER_NT_WORKSTATION) memcpy( ret + len, win7W, sizeof(win7W) );
        else memcpy( ret + len, win2008r2W, sizeof(win2008r2W) );
    }
    else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 0)
    {
        if (ver->wProductType == VER_NT_WORKSTATION) memcpy( ret + len, vistaW, sizeof(vistaW) );
        else memcpy( ret + len, win2008W, sizeof(win2008W) );
    }
    else if (ver->dwMajorVersion == 5 && ver->dwMinorVersion == 2)
    {
        if (ver->wProductType == VER_NT_WORKSTATION) memcpy( ret + len, winxp64W, sizeof(winxp64W) );
        else memcpy( ret + len, win2003W, sizeof(win2003W) );
    }
    else if (ver->dwMajorVersion == 5 && ver->dwMinorVersion == 1) memcpy( ret + len, winxpW, sizeof(winxpW) );
    else memcpy( ret + len, win2000W, sizeof(win2000W) );
    return ret;
}
static WCHAR *get_osname( const WCHAR *caption )
{
    static const WCHAR partitionW[] =
        {'|','C',':','\\','W','I','N','D','O','W','S','|','\\','D','e','v','i','c','e','\\',
         'H','a','r','d','d','i','s','k','0','\\','P','a','r','t','i','t','i','o','n','1',0};
    int len = strlenW( caption );
    WCHAR *ret;

    if (!(ret = heap_alloc( len * sizeof(WCHAR) + sizeof(partitionW) ))) return NULL;
    memcpy( ret, caption, len * sizeof(WCHAR) );
    memcpy( ret + len, partitionW, sizeof(partitionW) );
    return ret;
}
static WCHAR *get_osversion( OSVERSIONINFOEXW *ver )
{
    static const WCHAR fmtW[] = {'%','u','.','%','u','.','%','u',0};
    WCHAR *ret = heap_alloc( 33 * sizeof(WCHAR) );
    if (ret) sprintfW( ret, fmtW, ver->dwMajorVersion, ver->dwMinorVersion, ver->dwBuildNumber );
    return ret;
}
2854

2855
static enum fill_status fill_os( struct table *table, const struct expr *cond )
2856 2857
{
    struct record_operatingsystem *rec;
2858
    enum fill_status status = FILL_STATUS_UNFILTERED;
2859
    OSVERSIONINFOEXW ver;
2860
    UINT row = 0;
2861

2862
    if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2863

2864 2865 2866
    ver.dwOSVersionInfoSize = sizeof(ver);
    GetVersionExW( (OSVERSIONINFOW *)&ver );

2867
    rec = (struct record_operatingsystem *)table->data;
2868 2869
    rec->buildnumber            = get_osbuildnumber( &ver );
    rec->caption                = get_oscaption( &ver );
2870 2871
    rec->codeset                = get_codeset();
    rec->countrycode            = get_countrycode();
2872
    rec->csdversion             = ver.szCSDVersion[0] ? heap_strdupW( ver.szCSDVersion ) : NULL;
2873 2874 2875 2876
    rec->installdate            = os_installdateW;
    rec->lastbootuptime         = get_lastbootuptime();
    rec->localdatetime          = get_localdatetime();
    rec->locale                 = get_locale();
2877
    rec->name                   = get_osname( rec->caption );
2878 2879 2880 2881
    rec->osarchitecture         = get_osarchitecture();
    rec->oslanguage             = GetSystemDefaultLangID();
    rec->osproductsuite         = 2461140; /* Windows XP Professional  */
    rec->ostype                 = 18;      /* WINNT */
2882
    rec->primary                = -1;
2883
    rec->serialnumber           = os_serialnumberW;
2884 2885
    rec->servicepackmajor       = ver.wServicePackMajor;
    rec->servicepackminor       = ver.wServicePackMinor;
2886 2887
    rec->suitemask              = 272;     /* Single User + Terminal */
    rec->systemdirectory        = get_systemdirectory();
2888 2889
    rec->totalvirtualmemorysize = get_total_physical_memory() / 1024;
    rec->totalvisiblememorysize = rec->totalvirtualmemorysize;
2890
    rec->version                = get_osversion( &ver );
2891 2892
    if (!match_row( table, row, cond, &status )) free_row_values( table, row );
    else row++;
2893

2894 2895 2896
    TRACE("created %u rows\n", row);
    table->num_rows = row;
    return status;
2897 2898
}

2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940
static const WCHAR *get_service_type( DWORD type )
{
    static const WCHAR filesystem_driverW[] =
        {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
    static const WCHAR kernel_driverW[] =
        {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
    static const WCHAR own_processW[] =
        {'O','w','n',' ','P','r','o','c','e','s','s',0};
    static const WCHAR share_processW[] =
        {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};

    if (type & SERVICE_KERNEL_DRIVER)            return kernel_driverW;
    else if (type & SERVICE_FILE_SYSTEM_DRIVER)  return filesystem_driverW;
    else if (type & SERVICE_WIN32_OWN_PROCESS)   return own_processW;
    else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
    else ERR("unhandled type 0x%08x\n", type);
    return NULL;
}
static const WCHAR *get_service_state( DWORD state )
{
    static const WCHAR runningW[] =
        {'R','u','n','n','i','n','g',0};
    static const WCHAR start_pendingW[] =
        {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
    static const WCHAR stop_pendingW[] =
        {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
    static const WCHAR stoppedW[] =
        {'S','t','o','p','p','e','d',0};
    static const WCHAR unknownW[] =
        {'U','n','k','n','o','w','n',0};

    switch (state)
    {
    case SERVICE_STOPPED:       return stoppedW;
    case SERVICE_START_PENDING: return start_pendingW;
    case SERVICE_STOP_PENDING:  return stop_pendingW;
    case SERVICE_RUNNING:       return runningW;
    default:
        ERR("unknown state %u\n", state);
        return unknownW;
    }
}
2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961
static const WCHAR *get_service_startmode( DWORD mode )
{
    static const WCHAR bootW[] = {'B','o','o','t',0};
    static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
    static const WCHAR autoW[] = {'A','u','t','o',0};
    static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
    static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
    static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};

    switch (mode)
    {
    case SERVICE_BOOT_START:   return bootW;
    case SERVICE_SYSTEM_START: return systemW;
    case SERVICE_AUTO_START:   return autoW;
    case SERVICE_DEMAND_START: return manualW;
    case SERVICE_DISABLED:     return disabledW;
    default:
        ERR("unknown mode 0x%x\n", mode);
        return unknownW;
    }
}
2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980
static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
{
    QUERY_SERVICE_CONFIGW *config = NULL;
    SC_HANDLE service;
    DWORD size;

    if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
    QueryServiceConfigW( service, NULL, 0, &size );
    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
    if (!(config = heap_alloc( size ))) goto done;
    if (QueryServiceConfigW( service, config, size, &size )) goto done;
    heap_free( config );
    config = NULL;

done:
    CloseServiceHandle( service );
    return config;
}

2981
static enum fill_status fill_service( struct table *table, const struct expr *cond )
2982 2983 2984 2985 2986
{
    struct record_service *rec;
    SC_HANDLE manager;
    ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
    SERVICE_STATUS_PROCESS *status;
2987 2988
    WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
    DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
2989
    UINT i, row = 0, offset = 0, size = 256, needed, count;
2990
    enum fill_status fill_status = FILL_STATUS_FAILED;
2991 2992
    BOOL ret;

2993
    if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return FILL_STATUS_FAILED;
2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009
    if (!(services = heap_alloc( size ))) goto done;

    ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
                                 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
                                 &count, NULL, NULL );
    if (!ret)
    {
        if (GetLastError() != ERROR_MORE_DATA) goto done;
        size = needed;
        if (!(tmp = heap_realloc( services, size ))) goto done;
        services = tmp;
        ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
                                     SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
                                     &count, NULL, NULL );
        if (!ret) goto done;
    }
3010
    if (!resize_table( table, count, sizeof(*rec) )) goto done;
3011

3012
    GetComputerNameW( sysnameW, &len );
3013
    fill_status = FILL_STATUS_UNFILTERED;
3014

3015 3016
    for (i = 0; i < count; i++)
    {
3017
        QUERY_SERVICE_CONFIGW *config;
3018 3019

        if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
3020

3021 3022
        status = &services[i].ServiceStatusProcess;
        rec = (struct record_service *)(table->data + offset);
3023 3024 3025 3026 3027 3028 3029 3030 3031 3032
        rec->accept_pause   = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
        rec->accept_stop    = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
        rec->displayname    = heap_strdupW( services[i].lpDisplayName );
        rec->name           = heap_strdupW( services[i].lpServiceName );
        rec->process_id     = status->dwProcessId;
        rec->servicetype    = get_service_type( status->dwServiceType );
        rec->startmode      = get_service_startmode( config->dwStartType );
        rec->state          = get_service_state( status->dwCurrentState );
        rec->systemname     = heap_strdupW( sysnameW );
        rec->pause_service  = service_pause_service;
3033
        rec->resume_service = service_resume_service;
3034
        rec->start_service  = service_start_service;
3035
        rec->stop_service   = service_stop_service;
3036
        heap_free( config );
3037 3038 3039 3040 3041
        if (!match_row( table, row, cond, &fill_status ))
        {
            free_row_values( table, row );
            continue;
        }
3042
        offset += sizeof(*rec);
3043
        row++;
3044 3045
    }

3046 3047
    TRACE("created %u rows\n", row);
    table->num_rows = row;
3048 3049 3050 3051

done:
    CloseServiceHandle( manager );
    heap_free( services );
3052
    return fill_status;
3053 3054
}

3055 3056 3057 3058 3059
static WCHAR *get_accountname( LSA_TRANSLATED_NAME *name )
{
    if (!name || !name->Name.Buffer) return NULL;
    return heap_strdupW( name->Name.Buffer );
}
3060
static struct array *get_binaryrepresentation( PSID sid, UINT len )
3061
{
3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075
    struct array *array = heap_alloc( sizeof(struct array) );
    if (array)
    {
        UINT8 *ret = heap_alloc( len );
        if (ret)
        {
            memcpy( ret, sid, len );
            array->count = len;
            array->ptr = ret;
            return array;
        }
        heap_free( array );
    }
    return NULL;
3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149
}
static WCHAR *get_referenceddomainname( LSA_REFERENCED_DOMAIN_LIST *domain )
{
    if (!domain || !domain->Domains || !domain->Domains->Name.Buffer) return NULL;
    return heap_strdupW( domain->Domains->Name.Buffer );
}
static const WCHAR *find_sid_str( const struct expr *cond )
{
    const struct expr *left, *right;
    const WCHAR *ret = NULL;

    if (!cond || cond->type != EXPR_COMPLEX || cond->u.expr.op != OP_EQ) return NULL;

    left = cond->u.expr.left;
    right = cond->u.expr.right;
    if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL && !strcmpiW( left->u.propval->name, prop_sidW ))
    {
        ret = right->u.sval;
    }
    else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL && !strcmpiW( right->u.propval->name, prop_sidW ))
    {
        ret = left->u.sval;
    }
    return ret;
}

static enum fill_status fill_sid( struct table *table, const struct expr *cond )
{
    PSID sid;
    LSA_REFERENCED_DOMAIN_LIST *domain;
    LSA_TRANSLATED_NAME *name;
    LSA_HANDLE handle;
    LSA_OBJECT_ATTRIBUTES attrs;
    const WCHAR *str;
    struct record_sid *rec;
    UINT len;

    if (!(str = find_sid_str( cond ))) return FILL_STATUS_FAILED;
    if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;

    if (!ConvertStringSidToSidW( str, &sid )) return FILL_STATUS_FAILED;
    len = GetLengthSid( sid );

    memset( &attrs, 0, sizeof(attrs) );
    attrs.Length = sizeof(attrs);
    if (LsaOpenPolicy( NULL, &attrs, POLICY_ALL_ACCESS, &handle ))
    {
        LocalFree( sid );
        return FILL_STATUS_FAILED;
    }
    if (LsaLookupSids( handle, 1, &sid, &domain, &name ))
    {
        LocalFree( sid );
        LsaClose( handle );
        return FILL_STATUS_FAILED;
    }

    rec = (struct record_sid *)table->data;
    rec->accountname            = get_accountname( name );
    rec->binaryrepresentation   = get_binaryrepresentation( sid, len );
    rec->referenceddomainname   = get_referenceddomainname( domain );
    rec->sid                    = heap_strdupW( str );
    rec->sidlength              = len;

    TRACE("created 1 row\n");
    table->num_rows = 1;

    LsaFreeMemory( domain );
    LsaFreeMemory( name );
    LocalFree( sid );
    LsaClose( handle );
    return FILL_STATUS_FILTERED;
}

3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161
static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
{
    HDC hdc = GetDC( NULL );
    UINT32 ret;

    if (!hdc) return 32;
    ret = GetDeviceCaps( hdc, BITSPIXEL );
    *hres = GetDeviceCaps( hdc, HORZRES );
    *vres = GetDeviceCaps( hdc, VERTRES );
    ReleaseDC( NULL, hdc );
    return ret;
}
3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174
static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
{
    static const WCHAR fmtW[] =
        {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
         '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
         '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
    WCHAR *ret;

    if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
    sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
    return ret;
}

3175
static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond )
3176
{
3177
    static const WCHAR fmtW[] = {'%','u',' ','x',' ','%','u',' ','x',' ','%','I','6','4','u',' ','c','o','l','o','r','s',0};
3178 3179 3180 3181 3182
    struct record_videocontroller *rec;
    HRESULT hr;
    IDXGIFactory *factory = NULL;
    IDXGIAdapter *adapter = NULL;
    DXGI_ADAPTER_DESC desc;
3183
    UINT row = 0, hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
3184
    const WCHAR *name = videocontroller_deviceidW;
3185
    enum fill_status status = FILL_STATUS_UNFILTERED;
3186
    WCHAR mode[44];
3187

3188 3189
    if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;

3190
    memset (&desc, 0, sizeof(desc));
3191 3192 3193 3194 3195 3196 3197
    hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
    if (FAILED(hr)) goto done;

    hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
    if (FAILED(hr)) goto done;

    hr = IDXGIAdapter_GetDesc( adapter, &desc );
3198 3199 3200 3201 3202
    if (SUCCEEDED(hr))
    {
        vidmem = desc.DedicatedVideoMemory;
        name   = desc.Description;
    }
3203 3204 3205

done:
    rec = (struct record_videocontroller *)table->data;
3206
    rec->adapter_dactype       = videocontroller_dactypeW;
3207
    rec->adapter_ram           = vidmem;
3208
    rec->availability          = 3; /* Running or Full Power */
3209
    rec->caption               = heap_strdupW( name );
3210 3211
    rec->current_bitsperpixel  = get_bits_per_pixel( &hres, &vres );
    rec->current_horizontalres = hres;
3212 3213
    rec->current_refreshrate   = 0; /* default refresh rate */
    rec->current_scanmode      = 2; /* Unknown */
3214
    rec->current_verticalres   = vres;
3215
    rec->description           = heap_strdupW( name );
3216
    rec->device_id             = videocontroller_deviceidW;
3217
    rec->driverversion         = videocontroller_driverversionW;
3218
    rec->name                  = heap_strdupW( name );
3219
    rec->pnpdevice_id          = get_pnpdeviceid( &desc );
3220 3221
    rec->videoarchitecture     = 2; /* Unknown */
    rec->videomemorytype       = 2; /* Unknown */
3222 3223
    wsprintfW( mode, fmtW, hres, vres, (UINT64)1 << rec->current_bitsperpixel );
    rec->videomodedescription  = heap_strdupW( mode );
3224
    rec->videoprocessor        = heap_strdupW( name );
3225 3226
    if (!match_row( table, row, cond, &status )) free_row_values( table, row );
    else row++;
3227

3228 3229
    TRACE("created %u rows\n", row);
    table->num_rows = row;
3230 3231 3232

    if (adapter) IDXGIAdapter_Release( adapter );
    if (factory) IDXGIFactory_Release( factory );
3233
    return status;
3234 3235
}

3236
static struct table builtin_classes[] =
3237
{
3238 3239 3240 3241
    { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), 0, (BYTE *)data_baseboard },
    { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), 0, (BYTE *)data_bios },
    { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, 0, 0, NULL, fill_cdromdrive },
    { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, 0, NULL, fill_compsys },
3242
    { class_compsysproductW, SIZEOF(col_compsysproduct), col_compsysproduct, 0, 0, NULL, fill_compsysproduct },
3243
    { class_datafileW, SIZEOF(col_datafile), col_datafile, 0, 0, NULL, fill_datafile },
3244
    { class_desktopmonitorW, SIZEOF(col_desktopmonitor), col_desktopmonitor, 0, 0, NULL, fill_desktopmonitor },
3245
    { class_directoryW, SIZEOF(col_directory), col_directory, 0, 0, NULL, fill_directory },
3246
    { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, 0, 0, NULL, fill_diskdrive },
3247
    { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, 0, NULL, fill_diskpartition },
3248
    { class_ip4routetableW, SIZEOF(col_ip4routetable), col_ip4routetable, 0, 0, NULL, fill_ip4routetable },
3249 3250 3251
    { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
    { class_logicaldisk2W, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
    { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, 0, NULL, fill_networkadapter },
3252
    { class_networkadapterconfigW, SIZEOF(col_networkadapterconfig), col_networkadapterconfig, 0, 0, NULL, fill_networkadapterconfig },
3253 3254
    { class_osW, SIZEOF(col_os), col_os, 0, 0, NULL, fill_os },
    { class_paramsW, SIZEOF(col_param), col_param, SIZEOF(data_param), 0, (BYTE *)data_param },
3255
    { class_physicalmediaW, SIZEOF(col_physicalmedia), col_physicalmedia, SIZEOF(data_physicalmedia), 0, (BYTE *)data_physicalmedia },
3256
    { class_physicalmemoryW, SIZEOF(col_physicalmemory), col_physicalmemory, 0, 0, NULL, fill_physicalmemory },
3257
    { class_printerW, SIZEOF(col_printer), col_printer, 0, 0, NULL, fill_printer },
3258 3259
    { class_processW, SIZEOF(col_process), col_process, 0, 0, NULL, fill_process },
    { class_processorW, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
3260
    { class_processor2W, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
3261 3262
    { class_qualifiersW, SIZEOF(col_qualifier), col_qualifier, SIZEOF(data_qualifier), 0, (BYTE *)data_qualifier },
    { class_serviceW, SIZEOF(col_service), col_service, 0, 0, NULL, fill_service },
3263
    { class_sidW, SIZEOF(col_sid), col_sid, 0, 0, NULL, fill_sid },
3264 3265
    { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), 0, (BYTE *)data_sounddevice },
    { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), 0, (BYTE *)data_stdregprov },
3266
    { class_systemsecurityW, SIZEOF(col_systemsecurity), col_systemsecurity, SIZEOF(data_systemsecurity), 0, (BYTE *)data_systemsecurity },
3267
    { class_systemenclosureW, SIZEOF(col_systemenclosure), col_systemenclosure, SIZEOF(data_systemenclosure), 0, (BYTE *)data_systemenclosure },
3268
    { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, 0, NULL, fill_videocontroller }
3269 3270
};

3271
void init_table_list( void )
3272
{
3273
    static struct list tables = LIST_INIT( tables );
3274 3275
    UINT i;

3276
    for (i = 0; i < SIZEOF(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
3277
    table_list = &tables;
3278
}