[WBEMPROX]
[reactos.git] / reactos / dll / win32 / wbemprox / builtin.c
1 /*
2 * Copyright 2012 Hans Leidekker for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #include "wbemprox_private.h"
20
21 #include <wingdi.h>
22 #include <winsock2.h>
23 #include <iphlpapi.h>
24 #include <tlhelp32.h>
25 #include <winternl.h>
26 #include <winioctl.h>
27 #include <winver.h>
28
29 #include <initguid.h>
30 #include <d3d10.h>
31
32 static const WCHAR class_baseboardW[] =
33 {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
34 static const WCHAR class_biosW[] =
35 {'W','i','n','3','2','_','B','I','O','S',0};
36 static const WCHAR class_cdromdriveW[] =
37 {'W','i','n','3','2','_','C','D','R','O','M','D','r','i','v','e',0};
38 static const WCHAR class_compsysW[] =
39 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
40 static const WCHAR class_datafileW[] =
41 {'C','I','M','_','D','a','t','a','F','i','l','e',0};
42 static const WCHAR class_directoryW[] =
43 {'W','i','n','3','2','_','D','i','r','e','c','t','o','r','y',0};
44 static const WCHAR class_diskdriveW[] =
45 {'W','i','n','3','2','_','D','i','s','k','D','r','i','v','e',0};
46 static const WCHAR class_diskpartitionW[] =
47 {'W','i','n','3','2','_','D','i','s','k','P','a','r','t','i','t','i','o','n',0};
48 static const WCHAR class_logicaldiskW[] =
49 {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
50 static const WCHAR class_logicaldisk2W[] =
51 {'C','I','M','_','L','o','g','i','c','a','l','D','i','s','k',0};
52 static const WCHAR class_networkadapterW[] =
53 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
54 static const WCHAR class_networkadapterconfigW[] =
55 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',
56 'C','o','n','f','i','g','u','r','a','t','i','o','n',0};
57 static const WCHAR class_osW[] =
58 {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
59 static const WCHAR class_paramsW[] =
60 {'_','_','P','A','R','A','M','E','T','E','R','S',0};
61 static const WCHAR class_physicalmediaW[] =
62 {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','d','i','a',0};
63 static const WCHAR class_physicalmemoryW[] =
64 {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
65 static const WCHAR class_qualifiersW[] =
66 {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
67 static const WCHAR class_process_getowner_outW[] =
68 {'_','_','W','I','N','3','2','_','P','R','O','C','E','S','S','_','G','E','T','O','W',
69 'N','E','R','_','O','U','T',0};
70 static const WCHAR class_processorW[] =
71 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
72 static const WCHAR class_processor2W[] =
73 {'C','I','M','_','P','r','o','c','e','s','s','o','r',0};
74 static const WCHAR class_sounddeviceW[] =
75 {'W','i','n','3','2','_','S','o','u','n','d','D','e','v','i','c','e',0};
76 static const WCHAR class_videocontrollerW[] =
77 {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
78
79 static const WCHAR prop_acceptpauseW[] =
80 {'A','c','c','e','p','t','P','a','u','s','e',0};
81 static const WCHAR prop_acceptstopW[] =
82 {'A','c','c','e','p','t','S','t','o','p',0};
83 static const WCHAR prop_accessmaskW[] =
84 {'A','c','c','e','s','s','M','a','s','k',0};
85 static const WCHAR prop_adapterdactypeW[] =
86 {'A','d','a','p','t','e','r','D','A','C','T','y','p','e',0};
87 static const WCHAR prop_adapterramW[] =
88 {'A','d','a','p','t','e','r','R','A','M',0};
89 static const WCHAR prop_adaptertypeW[] =
90 {'A','d','a','p','t','e','r','T','y','p','e',0};
91 static const WCHAR prop_addresswidthW[] =
92 {'A','d','d','r','e','s','s','W','i','d','t','h',0};
93 static const WCHAR prop_availabilityW[] =
94 {'A','v','a','i','l','a','b','i','l','i','t','y',0};
95 static const WCHAR prop_bootableW[] =
96 {'B','o','o','t','a','b','l','e',0};
97 static const WCHAR prop_bootpartitionW[] =
98 {'B','o','o','t','P','a','r','t','i','t','i','o','n',0};
99 static const WCHAR prop_buildnumberW[] =
100 {'B','u','i','l','d','N','u','m','b','e','r',0};
101 static const WCHAR prop_capacityW[] =
102 {'C','a','p','a','c','i','t','y',0};
103 static const WCHAR prop_captionW[] =
104 {'C','a','p','t','i','o','n',0};
105 static const WCHAR prop_classW[] =
106 {'C','l','a','s','s',0};
107 static const WCHAR prop_codesetW[] =
108 {'C','o','d','e','S','e','t',0};
109 static const WCHAR prop_commandlineW[] =
110 {'C','o','m','m','a','n','d','L','i','n','e',0};
111 static const WCHAR prop_countrycodeW[] =
112 {'C','o','u','n','t','r','y','C','o','d','e',0};
113 static const WCHAR prop_cpustatusW[] =
114 {'C','p','u','S','t','a','t','u','s',0};
115 static const WCHAR prop_csdversionW[] =
116 {'C','S','D','V','e','r','s','i','o','n',0};
117 static const WCHAR prop_currentbitsperpixelW[] =
118 {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
119 static const WCHAR prop_currentclockspeedW[] =
120 {'C','u','r','r','e','n','t','C','l','o','c','k','S','p','e','e','d',0};
121 static const WCHAR prop_currenthorizontalresW[] =
122 {'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};
123 static const WCHAR prop_currentverticalresW[] =
124 {'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};
125 static const WCHAR prop_defaultvalueW[] =
126 {'D','e','f','a','u','l','t','V','a','l','u','e',0};
127 static const WCHAR prop_descriptionW[] =
128 {'D','e','s','c','r','i','p','t','i','o','n',0};
129 static const WCHAR prop_deviceidW[] =
130 {'D','e','v','i','c','e','I','d',0};
131 static const WCHAR prop_directionW[] =
132 {'D','i','r','e','c','t','i','o','n',0};
133 static const WCHAR prop_displaynameW[] =
134 {'D','i','s','p','l','a','y','N','a','m','e',0};
135 static const WCHAR prop_diskindexW[] =
136 {'D','i','s','k','I','n','d','e','x',0};
137 static const WCHAR prop_domainW[] =
138 {'D','o','m','a','i','n',0};
139 static const WCHAR prop_domainroleW[] =
140 {'D','o','m','a','i','n','R','o','l','e',0};
141 static const WCHAR prop_driveW[] =
142 {'D','r','i','v','e',0};
143 static const WCHAR prop_drivetypeW[] =
144 {'D','r','i','v','e','T','y','p','e',0};
145 static const WCHAR prop_familyW[] =
146 {'F','a','m','i','l','y',0};
147 static const WCHAR prop_filesystemW[] =
148 {'F','i','l','e','S','y','s','t','e','m',0};
149 static const WCHAR prop_flavorW[] =
150 {'F','l','a','v','o','r',0};
151 static const WCHAR prop_freespaceW[] =
152 {'F','r','e','e','S','p','a','c','e',0};
153 static const WCHAR prop_handleW[] =
154 {'H','a','n','d','l','e',0};
155 static const WCHAR prop_idW[] =
156 {'I','D',0};
157 static const WCHAR prop_identificationcodeW[] =
158 {'I','d','e','n','t','i','f','i','c','a','t','i','o','n','C','o','d','e',0};
159 static const WCHAR prop_indexW[] =
160 {'I','n','d','e','x',0};
161 static const WCHAR prop_installdateW[] =
162 {'I','n','s','t','a','l','l','D','a','t','e',0};
163 static const WCHAR prop_interfaceindexW[] =
164 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
165 static const WCHAR prop_interfacetypeW[] =
166 {'I','n','t','e','r','f','a','c','e','T','y','p','e',0};
167 static const WCHAR prop_intvalueW[] =
168 {'I','n','t','e','g','e','r','V','a','l','u','e',0};
169 static const WCHAR prop_ipconnectionmetricW[] =
170 {'I','P','C','o','n','n','e','c','t','i','o','n','M','e','t','r','i','c',0};
171 static const WCHAR prop_ipenabledW[] =
172 {'I','P','E','n','a','b','l','e','d',0};
173 static const WCHAR prop_lastbootuptimeW[] =
174 {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
175 static const WCHAR prop_localdatetimeW[] =
176 {'L','o','c','a','l','D','a','t','e','T','i','m','e',0};
177 static const WCHAR prop_localeW[] =
178 {'L','o','c','a','l','e',0};
179 static const WCHAR prop_macaddressW[] =
180 {'M','A','C','A','d','d','r','e','s','s',0};
181 static const WCHAR prop_manufacturerW[] =
182 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
183 static const WCHAR prop_maxclockspeedW[] =
184 {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
185 static const WCHAR prop_mediatypeW[] =
186 {'M','e','d','i','a','T','y','p','e',0};
187 static const WCHAR prop_memberW[] =
188 {'M','e','m','b','e','r',0};
189 static const WCHAR prop_methodW[] =
190 {'M','e','t','h','o','d',0};
191 static const WCHAR prop_modelW[] =
192 {'M','o','d','e','l',0};
193 static const WCHAR prop_netconnectionstatusW[] =
194 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
195 static const WCHAR prop_numcoresW[] =
196 {'N','u','m','b','e','r','O','f','C','o','r','e','s',0};
197 static const WCHAR prop_numlogicalprocessorsW[] =
198 {'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};
199 static const WCHAR prop_numprocessorsW[] =
200 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
201 static const WCHAR prop_osarchitectureW[] =
202 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
203 static const WCHAR prop_oslanguageW[] =
204 {'O','S','L','a','n','g','u','a','g','e',0};
205 static const WCHAR prop_osproductsuiteW[] =
206 {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
207 static const WCHAR prop_ostypeW[] =
208 {'O','S','T','y','p','e',0};
209 static const WCHAR prop_parameterW[] =
210 {'P','a','r','a','m','e','t','e','r',0};
211 static const WCHAR prop_physicaladapterW[] =
212 {'P','h','y','s','i','c','a','l','A','d','a','p','t','e','r',0};
213 static const WCHAR prop_pnpdeviceidW[] =
214 {'P','N','P','D','e','v','i','c','e','I','D',0};
215 static const WCHAR prop_pprocessidW[] =
216 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
217 static const WCHAR prop_processidW[] =
218 {'P','r','o','c','e','s','s','I','D',0};
219 static const WCHAR prop_processoridW[] =
220 {'P','r','o','c','e','s','s','o','r','I','d',0};
221 static const WCHAR prop_productnameW[] =
222 {'P','r','o','d','u','c','t','N','a','m','e',0};
223 static const WCHAR prop_releasedateW[] =
224 {'R','e','l','e','a','s','e','D','a','t','e',0};
225 static const WCHAR prop_serialnumberW[] =
226 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
227 static const WCHAR prop_servicepackmajorW[] =
228 {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
229 static const WCHAR prop_servicepackminorW[] =
230 {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
231 static const WCHAR prop_servicetypeW[] =
232 {'S','e','r','v','i','c','e','T','y','p','e',0};
233 static const WCHAR prop_smbiosbiosversionW[] =
234 {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
235 static const WCHAR prop_startmodeW[] =
236 {'S','t','a','r','t','M','o','d','e',0};
237 static const WCHAR prop_sizeW[] =
238 {'S','i','z','e',0};
239 static const WCHAR prop_speedW[] =
240 {'S','p','e','e','d',0};
241 static const WCHAR prop_startingoffsetW[] =
242 {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0};
243 static const WCHAR prop_stateW[] =
244 {'S','t','a','t','e',0};
245 static const WCHAR prop_strvalueW[] =
246 {'S','t','r','i','n','g','V','a','l','u','e',0};
247 static const WCHAR prop_suitemaskW[] =
248 {'S','u','i','t','e','M','a','s','k',0};
249 static const WCHAR prop_systemdirectoryW[] =
250 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
251 static const WCHAR prop_systemnameW[] =
252 {'S','y','s','t','e','m','N','a','m','e',0};
253 static const WCHAR prop_tagW[] =
254 {'T','a','g',0};
255 static const WCHAR prop_threadcountW[] =
256 {'T','h','r','e','a','d','C','o','u','n','t',0};
257 static const WCHAR prop_totalphysicalmemoryW[] =
258 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
259 static const WCHAR prop_typeW[] =
260 {'T','y','p','e',0};
261 static const WCHAR prop_uniqueidW[] =
262 {'U','n','i','q','u','e','I','d',0};
263 static const WCHAR prop_varianttypeW[] =
264 {'V','a','r','i','a','n','t','T','y','p','e',0};
265 static const WCHAR prop_versionW[] =
266 {'V','e','r','s','i','o','n',0};
267 static const WCHAR prop_volumeserialnumberW[] =
268 {'V','o','l','u','m','e','S','e','r','i','a','l','N','u','m','b','e','r',0};
269
270 /* column definitions must be kept in sync with record structures below */
271 static const struct column col_baseboard[] =
272 {
273 { prop_manufacturerW, CIM_STRING },
274 { prop_modelW, CIM_STRING },
275 { prop_nameW, CIM_STRING },
276 { prop_serialnumberW, CIM_STRING },
277 { prop_tagW, CIM_STRING|COL_FLAG_KEY }
278 };
279 static const struct column col_bios[] =
280 {
281 { prop_descriptionW, CIM_STRING },
282 { prop_identificationcodeW, CIM_STRING },
283 { prop_manufacturerW, CIM_STRING },
284 { prop_releasedateW, CIM_DATETIME },
285 { prop_serialnumberW, CIM_STRING },
286 { prop_smbiosbiosversionW, CIM_STRING },
287 { prop_versionW, CIM_STRING|COL_FLAG_KEY }
288 };
289 static const struct column col_cdromdrive[] =
290 {
291 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
292 { prop_driveW, CIM_STRING|COL_FLAG_DYNAMIC },
293 { prop_mediatypeW, CIM_STRING },
294 { prop_nameW, CIM_STRING },
295 { prop_pnpdeviceidW, CIM_STRING }
296 };
297 static const struct column col_compsys[] =
298 {
299 { prop_descriptionW, CIM_STRING },
300 { prop_domainW, CIM_STRING },
301 { prop_domainroleW, CIM_UINT16, VT_I4 },
302 { prop_manufacturerW, CIM_STRING },
303 { prop_modelW, CIM_STRING },
304 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
305 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
306 { prop_numprocessorsW, CIM_UINT32, VT_I4 },
307 { prop_totalphysicalmemoryW, CIM_UINT64 }
308 };
309 static const struct column col_datafile[] =
310 {
311 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
312 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
313 };
314 static const struct column col_directory[] =
315 {
316 { prop_accessmaskW, CIM_UINT32 },
317 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
318 };
319 static const struct column col_diskdrive[] =
320 {
321 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
322 { prop_indexW, CIM_UINT32, VT_I4 },
323 { prop_interfacetypeW, CIM_STRING },
324 { prop_manufacturerW, CIM_STRING },
325 { prop_mediatypeW, CIM_STRING },
326 { prop_modelW, CIM_STRING },
327 { prop_serialnumberW, CIM_STRING },
328 { prop_sizeW, CIM_UINT64 }
329 };
330 static const struct column col_diskpartition[] =
331 {
332 { prop_bootableW, CIM_BOOLEAN },
333 { prop_bootpartitionW, CIM_BOOLEAN },
334 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
335 { prop_diskindexW, CIM_UINT32, VT_I4 },
336 { prop_indexW, CIM_UINT32, VT_I4 },
337 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
338 { prop_sizeW, CIM_UINT64 },
339 { prop_startingoffsetW, CIM_UINT64 },
340 { prop_typeW, CIM_STRING|COL_FLAG_DYNAMIC }
341 };
342 static const struct column col_logicaldisk[] =
343 {
344 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
345 { prop_drivetypeW, CIM_UINT32, VT_I4 },
346 { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
347 { prop_freespaceW, CIM_UINT64 },
348 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
349 { prop_sizeW, CIM_UINT64 },
350 { prop_volumeserialnumberW, CIM_STRING|COL_FLAG_DYNAMIC }
351 };
352 static const struct column col_networkadapter[] =
353 {
354 { prop_adaptertypeW, CIM_STRING },
355 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
356 { prop_indexW, CIM_UINT32, VT_I4 },
357 { prop_interfaceindexW, CIM_UINT32, VT_I4 },
358 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
359 { prop_manufacturerW, CIM_STRING },
360 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
361 { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
362 { prop_physicaladapterW, CIM_BOOLEAN },
363 { prop_pnpdeviceidW, CIM_STRING },
364 { prop_speedW, CIM_UINT64 }
365 };
366 static const struct column col_networkadapterconfig[] =
367 {
368 { prop_indexW, CIM_UINT32|COL_FLAG_KEY, VT_I4 },
369 { prop_ipconnectionmetricW, CIM_UINT32, VT_I4 },
370 { prop_ipenabledW, CIM_BOOLEAN },
371 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC }
372 };
373 static const struct column col_os[] =
374 {
375 { prop_buildnumberW, CIM_STRING },
376 { prop_captionW, CIM_STRING },
377 { prop_codesetW, CIM_STRING|COL_FLAG_DYNAMIC },
378 { prop_countrycodeW, CIM_STRING|COL_FLAG_DYNAMIC },
379 { prop_csdversionW, CIM_STRING },
380 { prop_installdateW, CIM_DATETIME },
381 { prop_lastbootuptimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
382 { prop_localdatetimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
383 { prop_localeW, CIM_STRING|COL_FLAG_DYNAMIC },
384 { prop_nameW, CIM_STRING },
385 { prop_osarchitectureW, CIM_STRING },
386 { prop_oslanguageW, CIM_UINT32, VT_I4 },
387 { prop_osproductsuiteW, CIM_UINT32, VT_I4 },
388 { prop_ostypeW, CIM_UINT16, VT_I4 },
389 { prop_serialnumberW, CIM_STRING },
390 { prop_servicepackmajorW, CIM_UINT16, VT_I4 },
391 { prop_servicepackminorW, CIM_UINT16, VT_I4 },
392 { prop_suitemaskW, CIM_UINT32, VT_I4 },
393 { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC },
394 { prop_versionW, CIM_STRING }
395 };
396 static const struct column col_param[] =
397 {
398 { prop_classW, CIM_STRING },
399 { prop_methodW, CIM_STRING },
400 { prop_directionW, CIM_SINT32 },
401 { prop_parameterW, CIM_STRING },
402 { prop_typeW, CIM_UINT32 },
403 { prop_varianttypeW, CIM_UINT32 },
404 { prop_defaultvalueW, CIM_UINT32 }
405 };
406 static const struct column col_physicalmedia[] =
407 {
408 { prop_serialnumberW, CIM_STRING },
409 { prop_tagW, CIM_STRING }
410 };
411 static const struct column col_physicalmemory[] =
412 {
413 { prop_capacityW, CIM_UINT64 }
414 };
415 static const struct column col_process[] =
416 {
417 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
418 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
419 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
420 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
421 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
422 { prop_pprocessidW, CIM_UINT32, VT_I4 },
423 { prop_processidW, CIM_UINT32, VT_I4 },
424 { prop_threadcountW, CIM_UINT32, VT_I4 },
425 /* methods */
426 { method_getownerW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
427 };
428 static const struct column col_processor[] =
429 {
430 { prop_addresswidthW, CIM_UINT16, VT_I4 },
431 { prop_cpustatusW, CIM_UINT16 },
432 { prop_currentclockspeedW, CIM_UINT32, VT_I4 },
433 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
434 { prop_familyW, CIM_UINT16, VT_I4 },
435 { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
436 { prop_maxclockspeedW, CIM_UINT32, VT_I4 },
437 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
438 { prop_numcoresW, CIM_UINT32, VT_I4 },
439 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
440 { prop_processoridW, CIM_STRING|COL_FLAG_DYNAMIC },
441 { prop_uniqueidW, CIM_STRING }
442 };
443 static const struct column col_qualifier[] =
444 {
445 { prop_classW, CIM_STRING },
446 { prop_memberW, CIM_STRING },
447 { prop_typeW, CIM_UINT32 },
448 { prop_flavorW, CIM_SINT32 },
449 { prop_nameW, CIM_STRING },
450 { prop_intvalueW, CIM_SINT32 },
451 { prop_strvalueW, CIM_STRING }
452 };
453 static const struct column col_service[] =
454 {
455 { prop_acceptpauseW, CIM_BOOLEAN },
456 { prop_acceptstopW, CIM_BOOLEAN },
457 { prop_displaynameW, CIM_STRING|COL_FLAG_DYNAMIC },
458 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
459 { prop_processidW, CIM_UINT32 },
460 { prop_servicetypeW, CIM_STRING },
461 { prop_startmodeW, CIM_STRING },
462 { prop_stateW, CIM_STRING },
463 { prop_systemnameW, CIM_STRING|COL_FLAG_DYNAMIC },
464 /* methods */
465 { method_pauseserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
466 { method_resumeserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
467 { method_startserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
468 { method_stopserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
469 };
470 static const struct column col_sounddevice[] =
471 {
472 { prop_nameW, CIM_STRING },
473 { prop_productnameW, CIM_STRING }
474 };
475 static const struct column col_stdregprov[] =
476 {
477 { method_enumkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
478 { method_enumvaluesW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
479 { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
480 };
481 static const struct column col_systemsecurity[] =
482 {
483 { method_getsdW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
484 { method_setsdW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
485 };
486 static const struct column col_videocontroller[] =
487 {
488 { prop_adapterdactypeW, CIM_STRING },
489 { prop_adapterramW, CIM_UINT32, VT_I4 },
490 { prop_availabilityW, CIM_UINT16 },
491 { prop_currentbitsperpixelW, CIM_UINT32, VT_I4 },
492 { prop_currenthorizontalresW, CIM_UINT32, VT_I4 },
493 { prop_currentverticalresW, CIM_UINT32, VT_I4 },
494 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
495 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
496 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
497 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC }
498 };
499
500 static const WCHAR baseboard_manufacturerW[] =
501 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
502 static const WCHAR baseboard_serialnumberW[] =
503 {'N','o','n','e',0};
504 static const WCHAR baseboard_tagW[] =
505 {'B','a','s','e',' ','B','o','a','r','d',0};
506 static const WCHAR bios_descriptionW[] =
507 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
508 static const WCHAR bios_manufacturerW[] =
509 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
510 static const WCHAR bios_releasedateW[] =
511 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
512 static const WCHAR bios_serialnumberW[] =
513 {'0',0};
514 static const WCHAR bios_smbiosbiosversionW[] =
515 {'W','i','n','e',0};
516 static const WCHAR bios_versionW[] =
517 {'W','I','N','E',' ',' ',' ','-',' ','1',0};
518 static const WCHAR cdromdrive_mediatypeW[] =
519 {'C','D','-','R','O','M',0};
520 static const WCHAR cdromdrive_nameW[] =
521 {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
522 static const WCHAR cdromdrive_pnpdeviceidW[]=
523 {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
524 '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
525 '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
526 'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
527 static const WCHAR compsys_descriptionW[] =
528 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
529 static const WCHAR compsys_domainW[] =
530 {'W','O','R','K','G','R','O','U','P',0};
531 static const WCHAR compsys_manufacturerW[] =
532 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
533 static const WCHAR compsys_modelW[] =
534 {'W','i','n','e',0};
535 static const WCHAR diskdrive_interfacetypeW[] =
536 {'I','D','E',0};
537 static const WCHAR diskdrive_manufacturerW[] =
538 {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
539 static const WCHAR diskdrive_mediatype_fixedW[] =
540 {'F','i','x','e','d',' ','h','a','r','d',' ','d','i','s','k',0};
541 static const WCHAR diskdrive_mediatype_removableW[] =
542 {'R','e','m','o','v','a','b','l','e',' ','m','e','d','i','a',0};
543 static const WCHAR diskdrive_modelW[] =
544 {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
545 static const WCHAR diskdrive_serialW[] =
546 {'W','I','N','E','H','D','I','S','K',0};
547 static const WCHAR networkadapter_pnpdeviceidW[]=
548 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
549 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
550 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
551 static const WCHAR os_32bitW[] =
552 {'3','2','-','b','i','t',0};
553 static const WCHAR os_64bitW[] =
554 {'6','4','-','b','i','t',0};
555 static const WCHAR os_buildnumberW[] =
556 {'2','6','0','0',0};
557 static const WCHAR os_captionW[] =
558 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
559 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
560 static const WCHAR os_csdversionW[] =
561 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
562 static const WCHAR os_installdateW[] =
563 {'2','0','1','4','0','1','0','1','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
564 static const WCHAR os_nameW[] =
565 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
566 'P','r','o','f','e','s','s','i','o','n','a','l','|','C',':','\\','W','I','N','D','O','W','S',
567 '|','\\','D','e','v','i','c','e','\\','H','a','r','d','d','i','s','k','0',
568 '\\','P','a','r','t','i','t','i','o','n','1',0};
569 static const WCHAR os_serialnumberW[] =
570 {'1','2','3','4','5','-','O','E','M','-','1','2','3','4','5','6','7','-','1','2','3','4','5',0};
571 static const WCHAR os_versionW[] =
572 {'5','.','1','.','2','6','0','0',0};
573 static const WCHAR physicalmedia_tagW[] =
574 {'\\','\\','.','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
575 static const WCHAR sounddevice_productnameW[] =
576 {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
577 static const WCHAR videocontroller_dactypeW[] =
578 {'I','n','t','e','g','r','a','t','e','d',' ','R','A','M','D','A','C',0};
579 static const WCHAR videocontroller_deviceidW[] =
580 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
581
582 #include "pshpack1.h"
583 struct record_baseboard
584 {
585 const WCHAR *manufacturer;
586 const WCHAR *model;
587 const WCHAR *name;
588 const WCHAR *serialnumber;
589 const WCHAR *tag;
590 };
591 struct record_bios
592 {
593 const WCHAR *description;
594 const WCHAR *identificationcode;
595 const WCHAR *manufacturer;
596 const WCHAR *releasedate;
597 const WCHAR *serialnumber;
598 const WCHAR *smbiosbiosversion;
599 const WCHAR *version;
600 };
601 struct record_cdromdrive
602 {
603 const WCHAR *device_id;
604 const WCHAR *drive;
605 const WCHAR *mediatype;
606 const WCHAR *name;
607 const WCHAR *pnpdevice_id;
608 };
609 struct record_computersystem
610 {
611 const WCHAR *description;
612 const WCHAR *domain;
613 UINT16 domainrole;
614 const WCHAR *manufacturer;
615 const WCHAR *model;
616 const WCHAR *name;
617 UINT32 num_logical_processors;
618 UINT32 num_processors;
619 UINT64 total_physical_memory;
620 };
621 struct record_datafile
622 {
623 const WCHAR *name;
624 const WCHAR *version;
625 };
626 struct record_directory
627 {
628 UINT32 accessmask;
629 const WCHAR *name;
630 };
631 struct record_diskdrive
632 {
633 const WCHAR *device_id;
634 UINT32 index;
635 const WCHAR *interfacetype;
636 const WCHAR *manufacturer;
637 const WCHAR *mediatype;
638 const WCHAR *model;
639 const WCHAR *serialnumber;
640 UINT64 size;
641 };
642 struct record_diskpartition
643 {
644 int bootable;
645 int bootpartition;
646 const WCHAR *device_id;
647 UINT32 diskindex;
648 UINT32 index;
649 const WCHAR *pnpdevice_id;
650 UINT64 size;
651 UINT64 startingoffset;
652 const WCHAR *type;
653 };
654 struct record_logicaldisk
655 {
656 const WCHAR *device_id;
657 UINT32 drivetype;
658 const WCHAR *filesystem;
659 UINT64 freespace;
660 const WCHAR *name;
661 UINT64 size;
662 const WCHAR *volumeserialnumber;
663 };
664 struct record_networkadapter
665 {
666 const WCHAR *adaptertype;
667 const WCHAR *device_id;
668 UINT32 index;
669 UINT32 interface_index;
670 const WCHAR *mac_address;
671 const WCHAR *manufacturer;
672 const WCHAR *name;
673 UINT16 netconnection_status;
674 int physicaladapter;
675 const WCHAR *pnpdevice_id;
676 UINT64 speed;
677 };
678 struct record_networkadapterconfig
679 {
680 UINT32 index;
681 UINT32 ipconnectionmetric;
682 int ipenabled;
683 const WCHAR *mac_address;
684 };
685 struct record_operatingsystem
686 {
687 const WCHAR *buildnumber;
688 const WCHAR *caption;
689 const WCHAR *codeset;
690 const WCHAR *countrycode;
691 const WCHAR *csdversion;
692 const WCHAR *installdate;
693 const WCHAR *lastbootuptime;
694 const WCHAR *localdatetime;
695 const WCHAR *locale;
696 const WCHAR *name;
697 const WCHAR *osarchitecture;
698 UINT32 oslanguage;
699 UINT32 osproductsuite;
700 UINT16 ostype;
701 const WCHAR *serialnumber;
702 UINT16 servicepackmajor;
703 UINT16 servicepackminor;
704 UINT32 suitemask;
705 const WCHAR *systemdirectory;
706 const WCHAR *version;
707 };
708 struct record_param
709 {
710 const WCHAR *class;
711 const WCHAR *method;
712 INT32 direction;
713 const WCHAR *parameter;
714 UINT32 type;
715 UINT32 varianttype;
716 UINT32 defaultvalue;
717 };
718 struct record_physicalmedia
719 {
720 const WCHAR *serialnumber;
721 const WCHAR *tag;
722 };
723 struct record_physicalmemory
724 {
725 UINT64 capacity;
726 };
727 struct record_process
728 {
729 const WCHAR *caption;
730 const WCHAR *commandline;
731 const WCHAR *description;
732 const WCHAR *handle;
733 const WCHAR *name;
734 UINT32 pprocess_id;
735 UINT32 process_id;
736 UINT32 thread_count;
737 /* methods */
738 class_method *get_owner;
739 };
740 struct record_processor
741 {
742 UINT16 addresswidth;
743 UINT16 cpu_status;
744 UINT32 currentclockspeed;
745 const WCHAR *device_id;
746 UINT16 family;
747 const WCHAR *manufacturer;
748 UINT32 maxclockspeed;
749 const WCHAR *name;
750 UINT32 num_cores;
751 UINT32 num_logical_processors;
752 const WCHAR *processor_id;
753 const WCHAR *unique_id;
754 };
755 struct record_qualifier
756 {
757 const WCHAR *class;
758 const WCHAR *member;
759 UINT32 type;
760 INT32 flavor;
761 const WCHAR *name;
762 INT32 intvalue;
763 const WCHAR *strvalue;
764 };
765 struct record_service
766 {
767 int accept_pause;
768 int accept_stop;
769 const WCHAR *displayname;
770 const WCHAR *name;
771 UINT32 process_id;
772 const WCHAR *servicetype;
773 const WCHAR *startmode;
774 const WCHAR *state;
775 const WCHAR *systemname;
776 /* methods */
777 class_method *pause_service;
778 class_method *resume_service;
779 class_method *start_service;
780 class_method *stop_service;
781 };
782 struct record_sounddevice
783 {
784 const WCHAR *name;
785 const WCHAR *productname;
786 };
787 struct record_stdregprov
788 {
789 class_method *enumkey;
790 class_method *enumvalues;
791 class_method *getstringvalue;
792 };
793 struct record_systemsecurity
794 {
795 class_method *getsd;
796 class_method *setsd;
797 };
798 struct record_videocontroller
799 {
800 const WCHAR *adapter_dactype;
801 UINT32 adapter_ram;
802 UINT16 availability;
803 UINT32 current_bitsperpixel;
804 UINT32 current_horizontalres;
805 UINT32 current_verticalres;
806 const WCHAR *description;
807 const WCHAR *device_id;
808 const WCHAR *name;
809 const WCHAR *pnpdevice_id;
810 };
811 #include "poppack.h"
812
813 static const struct record_baseboard data_baseboard[] =
814 {
815 { baseboard_manufacturerW, baseboard_tagW, baseboard_tagW, baseboard_serialnumberW, baseboard_tagW }
816 };
817 static const struct record_bios data_bios[] =
818 {
819 { bios_descriptionW, bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW,
820 bios_smbiosbiosversionW, bios_versionW }
821 };
822 static const struct record_param data_param[] =
823 {
824 { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
825 { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
826 { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
827 { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
828 { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
829 { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
830 { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
831 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
832 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
833 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
834 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
835 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
836 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
837 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
838 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
839 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
840 { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
841 { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
842 { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
843 { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
844 { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING },
845 { class_systemsecurityW, method_getsdW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
846 { class_systemsecurityW, method_getsdW, -1, param_sdW, CIM_UINT8|CIM_FLAG_ARRAY },
847 { class_systemsecurityW, method_setsdW, 1, param_sdW, CIM_UINT8|CIM_FLAG_ARRAY },
848 { class_systemsecurityW, method_setsdW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
849 };
850
851 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
852 WBEM_FLAVOR_ORIGIN_PROPAGATED)
853
854 static const struct record_physicalmedia data_physicalmedia[] =
855 {
856 { diskdrive_serialW, physicalmedia_tagW }
857 };
858 static const struct record_qualifier data_qualifier[] =
859 {
860 { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
861 { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
862 };
863 static const struct record_sounddevice data_sounddevice[] =
864 {
865 { sounddevice_productnameW, sounddevice_productnameW }
866 };
867 static const struct record_stdregprov data_stdregprov[] =
868 {
869 { reg_enum_key, reg_enum_values, reg_get_stringvalue }
870 };
871 static const struct record_systemsecurity data_systemsecurity[] =
872 {
873 { security_get_sd, security_set_sd }
874 };
875
876 /* check if row matches condition and update status */
877 static BOOL match_row( const struct table *table, UINT row, const struct expr *cond, enum fill_status *status )
878 {
879 LONGLONG val;
880 UINT type;
881
882 if (!cond)
883 {
884 *status = FILL_STATUS_UNFILTERED;
885 return TRUE;
886 }
887 if (eval_cond( table, row, cond, &val, &type ) != S_OK)
888 {
889 *status = FILL_STATUS_FAILED;
890 return FALSE;
891 }
892 *status = FILL_STATUS_FILTERED;
893 return val != 0;
894 }
895
896 static BOOL resize_table( struct table *table, UINT row_count, UINT row_size )
897 {
898 if (!table->num_rows_allocated)
899 {
900 if (!(table->data = heap_alloc( row_count * row_size ))) return FALSE;
901 table->num_rows_allocated = row_count;
902 return TRUE;
903 }
904 if (row_count >= table->num_rows_allocated)
905 {
906 BYTE *data;
907 UINT count = table->num_rows_allocated * 2;
908 if (!(data = heap_realloc( table->data, count * row_size ))) return FALSE;
909 table->data = data;
910 table->num_rows_allocated = count;
911 }
912 return TRUE;
913 }
914
915 static enum fill_status fill_cdromdrive( struct table *table, const struct expr *cond )
916 {
917 static const WCHAR fmtW[] = {'%','c',':',0};
918 WCHAR drive[3], root[] = {'A',':','\\',0};
919 struct record_cdromdrive *rec;
920 UINT i, row = 0, offset = 0;
921 DWORD drives = GetLogicalDrives();
922 enum fill_status status = FILL_STATUS_UNFILTERED;
923
924 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
925
926 for (i = 0; i < sizeof(drives); i++)
927 {
928 if (drives & (1 << i))
929 {
930 root[0] = 'A' + i;
931 if (GetDriveTypeW( root ) != DRIVE_CDROM)
932 continue;
933
934 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
935
936 rec = (struct record_cdromdrive *)(table->data + offset);
937 rec->device_id = cdromdrive_pnpdeviceidW;
938 sprintfW( drive, fmtW, 'A' + i );
939 rec->drive = heap_strdupW( drive );
940 rec->mediatype = cdromdrive_mediatypeW;
941 rec->name = cdromdrive_nameW;
942 rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
943 if (!match_row( table, row, cond, &status ))
944 {
945 free_row_values( table, row );
946 continue;
947 }
948 offset += sizeof(*rec);
949 row++;
950 }
951 }
952 TRACE("created %u rows\n", row);
953 table->num_rows = row;
954 return status;
955 }
956
957 static UINT get_processor_count(void)
958 {
959 SYSTEM_BASIC_INFORMATION info;
960
961 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
962 return info.NumberOfProcessors;
963 }
964
965 static UINT get_logical_processor_count( UINT *num_cores )
966 {
967 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
968 UINT i, j, count = 0;
969 NTSTATUS status;
970 ULONG len;
971
972 if (num_cores) *num_cores = get_processor_count();
973 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
974 if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
975
976 if (!(info = heap_alloc( len ))) return get_processor_count();
977 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
978 if (status != STATUS_SUCCESS)
979 {
980 heap_free( info );
981 return get_processor_count();
982 }
983 if (num_cores) *num_cores = 0;
984 for (i = 0; i < len / sizeof(*info); i++)
985 {
986 if (info[i].Relationship == RelationProcessorCore)
987 {
988 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
989 }
990 else if (info[i].Relationship == RelationProcessorPackage && num_cores)
991 {
992 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) (*num_cores)++;
993 }
994 }
995 heap_free( info );
996 return count;
997 }
998
999 static UINT64 get_total_physical_memory(void)
1000 {
1001 MEMORYSTATUSEX status;
1002
1003 status.dwLength = sizeof(status);
1004 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
1005 return status.ullTotalPhys;
1006 }
1007
1008 static WCHAR *get_computername(void)
1009 {
1010 WCHAR *ret;
1011 DWORD size = MAX_COMPUTERNAME_LENGTH;
1012
1013 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
1014 GetComputerNameW( ret, &size );
1015 return ret;
1016 }
1017
1018 static enum fill_status fill_compsys( struct table *table, const struct expr *cond )
1019 {
1020 struct record_computersystem *rec;
1021 enum fill_status status = FILL_STATUS_UNFILTERED;
1022 UINT row = 0;
1023
1024 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1025
1026 rec = (struct record_computersystem *)table->data;
1027 rec->description = compsys_descriptionW;
1028 rec->domain = compsys_domainW;
1029 rec->domainrole = 0; /* standalone workstation */
1030 rec->manufacturer = compsys_manufacturerW;
1031 rec->model = compsys_modelW;
1032 rec->name = get_computername();
1033 rec->num_logical_processors = get_logical_processor_count( NULL );
1034 rec->num_processors = get_processor_count();
1035 rec->total_physical_memory = get_total_physical_memory();
1036 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1037 else row++;
1038
1039 TRACE("created %u rows\n", row);
1040 table->num_rows = row;
1041 return status;
1042 }
1043
1044 struct dirstack
1045 {
1046 WCHAR **dirs;
1047 UINT *len_dirs;
1048 UINT num_dirs;
1049 UINT num_allocated;
1050 };
1051
1052 static struct dirstack *alloc_dirstack( UINT size )
1053 {
1054 struct dirstack *dirstack;
1055
1056 if (!(dirstack = heap_alloc( sizeof(*dirstack) ))) return NULL;
1057 if (!(dirstack->dirs = heap_alloc( sizeof(WCHAR *) * size )))
1058 {
1059 heap_free( dirstack );
1060 return NULL;
1061 }
1062 if (!(dirstack->len_dirs = heap_alloc( sizeof(UINT) * size )))
1063 {
1064 heap_free( dirstack->dirs );
1065 heap_free( dirstack );
1066 return NULL;
1067 }
1068 dirstack->num_dirs = 0;
1069 dirstack->num_allocated = size;
1070 return dirstack;
1071 }
1072
1073 static void clear_dirstack( struct dirstack *dirstack )
1074 {
1075 UINT i;
1076 for (i = 0; i < dirstack->num_dirs; i++) heap_free( dirstack->dirs[i] );
1077 dirstack->num_dirs = 0;
1078 }
1079
1080 static void free_dirstack( struct dirstack *dirstack )
1081 {
1082 clear_dirstack( dirstack );
1083 heap_free( dirstack->dirs );
1084 heap_free( dirstack->len_dirs );
1085 heap_free( dirstack );
1086 }
1087
1088 static BOOL push_dir( struct dirstack *dirstack, WCHAR *dir, UINT len )
1089 {
1090 UINT size, i = dirstack->num_dirs;
1091
1092 if (!dir) return FALSE;
1093
1094 if (i == dirstack->num_allocated)
1095 {
1096 WCHAR **tmp;
1097 UINT *len_tmp;
1098
1099 size = dirstack->num_allocated * 2;
1100 if (!(tmp = heap_realloc( dirstack->dirs, size * sizeof(WCHAR *) ))) return FALSE;
1101 dirstack->dirs = tmp;
1102 if (!(len_tmp = heap_realloc( dirstack->len_dirs, size * sizeof(UINT) ))) return FALSE;
1103 dirstack->len_dirs = len_tmp;
1104 dirstack->num_allocated = size;
1105 }
1106 dirstack->dirs[i] = dir;
1107 dirstack->len_dirs[i] = len;
1108 dirstack->num_dirs++;
1109 return TRUE;
1110 }
1111
1112 static WCHAR *pop_dir( struct dirstack *dirstack, UINT *len )
1113 {
1114 if (!dirstack->num_dirs)
1115 {
1116 *len = 0;
1117 return NULL;
1118 }
1119 dirstack->num_dirs--;
1120 *len = dirstack->len_dirs[dirstack->num_dirs];
1121 return dirstack->dirs[dirstack->num_dirs];
1122 }
1123
1124 static const WCHAR *peek_dir( struct dirstack *dirstack )
1125 {
1126 if (!dirstack->num_dirs) return NULL;
1127 return dirstack->dirs[dirstack->num_dirs - 1];
1128 }
1129
1130 static WCHAR *build_glob( WCHAR drive, const WCHAR *path, UINT len )
1131 {
1132 UINT i = 0;
1133 WCHAR *ret;
1134
1135 if (!(ret = heap_alloc( (len + 6) * sizeof(WCHAR) ))) return NULL;
1136 ret[i++] = drive;
1137 ret[i++] = ':';
1138 ret[i++] = '\\';
1139 if (path && len)
1140 {
1141 memcpy( ret + i, path, len * sizeof(WCHAR) );
1142 i += len;
1143 ret[i++] = '\\';
1144 }
1145 ret[i++] = '*';
1146 ret[i] = 0;
1147 return ret;
1148 }
1149
1150 static WCHAR *build_name( WCHAR drive, const WCHAR *path )
1151 {
1152 UINT i = 0, len = 0;
1153 const WCHAR *p;
1154 WCHAR *ret;
1155
1156 for (p = path; *p; p++)
1157 {
1158 if (*p == '\\') len += 2;
1159 else len++;
1160 };
1161 if (!(ret = heap_alloc( (len + 5) * sizeof(WCHAR) ))) return NULL;
1162 ret[i++] = drive;
1163 ret[i++] = ':';
1164 ret[i++] = '\\';
1165 ret[i++] = '\\';
1166 for (p = path; *p; p++)
1167 {
1168 if (*p != '\\') ret[i++] = *p;
1169 else
1170 {
1171 ret[i++] = '\\';
1172 ret[i++] = '\\';
1173 }
1174 }
1175 ret[i] = 0;
1176 return ret;
1177 }
1178
1179 static WCHAR *build_dirname( const WCHAR *path, UINT *ret_len )
1180 {
1181 const WCHAR *p = path, *start;
1182 UINT len, i;
1183 WCHAR *ret;
1184
1185 if (!isalphaW( p[0] ) || p[1] != ':' || p[2] != '\\' || p[3] != '\\' || !p[4]) return NULL;
1186 start = path + 4;
1187 len = strlenW( start );
1188 p = start + len - 1;
1189 if (*p == '\\') return NULL;
1190
1191 while (p >= start && *p != '\\') { len--; p--; };
1192 while (p >= start && *p == '\\') { len--; p--; };
1193
1194 if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
1195 for (i = 0, p = start; p < start + len; p++)
1196 {
1197 if (p[0] == '\\' && p[1] == '\\')
1198 {
1199 ret[i++] = '\\';
1200 p++;
1201 }
1202 else ret[i++] = *p;
1203 }
1204 ret[i] = 0;
1205 *ret_len = i;
1206 return ret;
1207 }
1208
1209 static BOOL seen_dir( struct dirstack *dirstack, const WCHAR *path )
1210 {
1211 UINT i;
1212 for (i = 0; i < dirstack->num_dirs; i++) if (!strcmpW( dirstack->dirs[i], path )) return TRUE;
1213 return FALSE;
1214 }
1215
1216 /* optimize queries of the form WHERE Name='...' [OR Name='...']* */
1217 static UINT seed_dirs( struct dirstack *dirstack, const struct expr *cond, WCHAR root, UINT *count )
1218 {
1219 const struct expr *left, *right;
1220
1221 if (!cond || cond->type != EXPR_COMPLEX) return *count = 0;
1222
1223 left = cond->u.expr.left;
1224 right = cond->u.expr.right;
1225 if (cond->u.expr.op == OP_EQ)
1226 {
1227 UINT len;
1228 WCHAR *path;
1229 const WCHAR *str = NULL;
1230
1231 if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL &&
1232 !strcmpW( left->u.propval->name, prop_nameW ) &&
1233 toupperW( right->u.sval[0] ) == toupperW( root ))
1234 {
1235 str = right->u.sval;
1236 }
1237 else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL &&
1238 !strcmpW( right->u.propval->name, prop_nameW ) &&
1239 toupperW( left->u.sval[0] ) == toupperW( root ))
1240 {
1241 str = left->u.sval;
1242 }
1243 if (str && (path = build_dirname( str, &len )))
1244 {
1245 if (seen_dir( dirstack, path ))
1246 {
1247 heap_free( path );
1248 return ++*count;
1249 }
1250 else if (push_dir( dirstack, path, len )) return ++*count;
1251 heap_free( path );
1252 return *count = 0;
1253 }
1254 }
1255 else if (cond->u.expr.op == OP_OR)
1256 {
1257 UINT left_count = 0, right_count = 0;
1258
1259 if (!(seed_dirs( dirstack, left, root, &left_count ))) return *count = 0;
1260 if (!(seed_dirs( dirstack, right, root, &right_count ))) return *count = 0;
1261 return *count += left_count + right_count;
1262 }
1263 return *count = 0;
1264 }
1265
1266 static WCHAR *append_path( const WCHAR *path, const WCHAR *segment, UINT *len )
1267 {
1268 UINT len_path = 0, len_segment = strlenW( segment );
1269 WCHAR *ret;
1270
1271 *len = 0;
1272 if (path) len_path = strlenW( path );
1273 if (!(ret = heap_alloc( (len_path + len_segment + 2) * sizeof(WCHAR) ))) return NULL;
1274 if (path && len_path)
1275 {
1276 memcpy( ret, path, len_path * sizeof(WCHAR) );
1277 ret[len_path] = '\\';
1278 *len += len_path + 1;
1279 }
1280 memcpy( ret + *len, segment, len_segment * sizeof(WCHAR) );
1281 *len += len_segment;
1282 ret[*len] = 0;
1283 return ret;
1284 }
1285
1286 static WCHAR *get_file_version( const WCHAR *filename )
1287 {
1288 static const WCHAR slashW[] = {'\\',0}, fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
1289 VS_FIXEDFILEINFO *info;
1290 DWORD size;
1291 void *block;
1292 WCHAR *ret;
1293
1294 if (!(ret = heap_alloc( (4 * 5 + sizeof(fmtW) / sizeof(fmtW[0])) * sizeof(WCHAR) ))) return NULL;
1295 if (!(size = GetFileVersionInfoSizeW( filename, NULL )) || !(block = heap_alloc( size )))
1296 {
1297 heap_free( ret );
1298 return NULL;
1299 }
1300 if (!GetFileVersionInfoW( filename, 0, size, block ) ||
1301 !VerQueryValueW( block, slashW, (void **)&info, &size ))
1302 {
1303 heap_free( block );
1304 heap_free( ret );
1305 return NULL;
1306 }
1307 sprintfW( ret, fmtW, info->dwFileVersionMS >> 16, info->dwFileVersionMS & 0xffff,
1308 info->dwFileVersionLS >> 16, info->dwFileVersionLS & 0xffff );
1309 heap_free( block );
1310 return ret;
1311 }
1312
1313 static enum fill_status fill_datafile( struct table *table, const struct expr *cond )
1314 {
1315 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1316 struct record_datafile *rec;
1317 UINT i, len, row = 0, offset = 0, num_expected_rows;
1318 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1319 DWORD drives = GetLogicalDrives();
1320 WIN32_FIND_DATAW data;
1321 HANDLE handle;
1322 struct dirstack *dirstack;
1323 enum fill_status status = FILL_STATUS_UNFILTERED;
1324
1325 if (!resize_table( table, 8, sizeof(*rec) )) return FILL_STATUS_FAILED;
1326
1327 dirstack = alloc_dirstack(2);
1328
1329 for (i = 0; i < sizeof(drives); i++)
1330 {
1331 if (!(drives & (1 << i))) continue;
1332
1333 root[0] = 'A' + i;
1334 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1335
1336 num_expected_rows = 0;
1337 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1338
1339 for (;;)
1340 {
1341 path = pop_dir( dirstack, &len );
1342 if (!(glob = build_glob( root[0], path, len )))
1343 {
1344 status = FILL_STATUS_FAILED;
1345 goto done;
1346 }
1347 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1348 {
1349 do
1350 {
1351 if (!resize_table( table, row + 1, sizeof(*rec) ))
1352 {
1353 status = FILL_STATUS_FAILED;
1354 FindClose( handle );
1355 goto done;
1356 }
1357 if (!strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW )) continue;
1358 new_path = append_path( path, data.cFileName, &len );
1359
1360 if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1361 {
1362 if (push_dir( dirstack, new_path, len )) continue;
1363 heap_free( new_path );
1364 FindClose( handle );
1365 status = FILL_STATUS_FAILED;
1366 goto done;
1367 }
1368 rec = (struct record_datafile *)(table->data + offset);
1369 rec->name = build_name( root[0], new_path );
1370 rec->version = get_file_version( rec->name );
1371 if (!match_row( table, row, cond, &status ))
1372 {
1373 free_row_values( table, row );
1374 continue;
1375 }
1376 else if (num_expected_rows && row == num_expected_rows - 1)
1377 {
1378 row++;
1379 FindClose( handle );
1380 status = FILL_STATUS_FILTERED;
1381 goto done;
1382 }
1383 offset += sizeof(*rec);
1384 row++;
1385 }
1386 while (FindNextFileW( handle, &data ));
1387 FindClose( handle );
1388 }
1389 if (!peek_dir( dirstack )) break;
1390 heap_free( glob );
1391 heap_free( path );
1392 }
1393 }
1394
1395 done:
1396 free_dirstack( dirstack );
1397 heap_free( glob );
1398 heap_free( path );
1399
1400 TRACE("created %u rows\n", row);
1401 table->num_rows = row;
1402 return status;
1403 }
1404
1405 static enum fill_status fill_directory( struct table *table, const struct expr *cond )
1406 {
1407 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1408 struct record_directory *rec;
1409 UINT i, len, row = 0, offset = 0, num_expected_rows;
1410 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1411 DWORD drives = GetLogicalDrives();
1412 WIN32_FIND_DATAW data;
1413 HANDLE handle;
1414 struct dirstack *dirstack;
1415 enum fill_status status = FILL_STATUS_UNFILTERED;
1416
1417 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1418
1419 dirstack = alloc_dirstack(2);
1420
1421 for (i = 0; i < sizeof(drives); i++)
1422 {
1423 if (!(drives & (1 << i))) continue;
1424
1425 root[0] = 'A' + i;
1426 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1427
1428 num_expected_rows = 0;
1429 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1430
1431 for (;;)
1432 {
1433 path = pop_dir( dirstack, &len );
1434 if (!(glob = build_glob( root[0], path, len )))
1435 {
1436 status = FILL_STATUS_FAILED;
1437 goto done;
1438 }
1439 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1440 {
1441 do
1442 {
1443 if (!resize_table( table, row + 1, sizeof(*rec) ))
1444 {
1445 FindClose( handle );
1446 status = FILL_STATUS_FAILED;
1447 goto done;
1448 }
1449 if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1450 !strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW ))
1451 continue;
1452
1453 new_path = append_path( path, data.cFileName, &len );
1454 if (!(push_dir( dirstack, new_path, len )))
1455 {
1456 heap_free( new_path );
1457 FindClose( handle );
1458 status = FILL_STATUS_FAILED;
1459 goto done;
1460 }
1461 rec = (struct record_directory *)(table->data + offset);
1462 rec->accessmask = FILE_ALL_ACCESS;
1463 rec->name = build_name( root[0], new_path );
1464 if (!match_row( table, row, cond, &status ))
1465 {
1466 free_row_values( table, row );
1467 continue;
1468 }
1469 else if (num_expected_rows && row == num_expected_rows - 1)
1470 {
1471 row++;
1472 FindClose( handle );
1473 status = FILL_STATUS_FILTERED;
1474 goto done;
1475 }
1476 offset += sizeof(*rec);
1477 row++;
1478 }
1479 while (FindNextFileW( handle, &data ));
1480 FindClose( handle );
1481 }
1482 if (!peek_dir( dirstack )) break;
1483 heap_free( glob );
1484 heap_free( path );
1485 }
1486 }
1487
1488 done:
1489 free_dirstack( dirstack );
1490 heap_free( glob );
1491 heap_free( path );
1492
1493 TRACE("created %u rows\n", row);
1494 table->num_rows = row;
1495 return status;
1496 }
1497
1498 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
1499 {
1500 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
1501 ULARGE_INTEGER free;
1502 DISK_GEOMETRY_EX info;
1503 HANDLE handle;
1504 DWORD bytes_returned;
1505
1506 free.QuadPart = 512 * 1024 * 1024;
1507 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
1508
1509 root[4] = dir[0];
1510 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
1511 if (handle != INVALID_HANDLE_VALUE)
1512 {
1513 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), &bytes_returned, NULL ))
1514 *disksize = info.DiskSize.QuadPart;
1515 CloseHandle( handle );
1516 }
1517 return free.QuadPart;
1518 }
1519
1520 static enum fill_status fill_diskdrive( struct table *table, const struct expr *cond )
1521 {
1522 static const WCHAR fmtW[] =
1523 {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','%','u',0};
1524 WCHAR device_id[sizeof(fmtW)/sizeof(fmtW[0]) + 10], root[] = {'A',':','\\',0};
1525 struct record_diskdrive *rec;
1526 UINT i, row = 0, offset = 0, index = 0, type;
1527 UINT64 size = 1024 * 1024 * 1024;
1528 DWORD drives = GetLogicalDrives();
1529 enum fill_status status = FILL_STATUS_UNFILTERED;
1530
1531 if (!resize_table( table, 2, sizeof(*rec) )) return FILL_STATUS_FAILED;
1532
1533 for (i = 0; i < sizeof(drives); i++)
1534 {
1535 if (drives & (1 << i))
1536 {
1537 root[0] = 'A' + i;
1538 type = GetDriveTypeW( root );
1539 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1540 continue;
1541
1542 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1543
1544 rec = (struct record_diskdrive *)(table->data + offset);
1545 sprintfW( device_id, fmtW, index );
1546 rec->device_id = heap_strdupW( device_id );
1547 rec->index = index;
1548 rec->interfacetype = diskdrive_interfacetypeW;
1549 rec->manufacturer = diskdrive_manufacturerW;
1550 if (type == DRIVE_FIXED)
1551 rec->mediatype = diskdrive_mediatype_fixedW;
1552 else
1553 rec->mediatype = diskdrive_mediatype_removableW;
1554 rec->model = diskdrive_modelW;
1555 rec->serialnumber = diskdrive_serialW;
1556 get_freespace( root, &size );
1557 rec->size = size;
1558 if (!match_row( table, row, cond, &status ))
1559 {
1560 free_row_values( table, row );
1561 continue;
1562 }
1563 offset += sizeof(*rec);
1564 index++;
1565 row++;
1566 }
1567 }
1568 TRACE("created %u rows\n", row);
1569 table->num_rows = row;
1570 return status;
1571 }
1572
1573 static WCHAR *get_filesystem( const WCHAR *root )
1574 {
1575 static const WCHAR ntfsW[] = {'N','T','F','S',0};
1576 WCHAR buffer[MAX_PATH + 1];
1577
1578 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
1579 return heap_strdupW( buffer );
1580 return heap_strdupW( ntfsW );
1581 }
1582
1583 static enum fill_status fill_diskpartition( struct table *table, const struct expr *cond )
1584 {
1585 static const WCHAR fmtW[] =
1586 {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
1587 WCHAR device_id[32], root[] = {'A',':','\\',0};
1588 struct record_diskpartition *rec;
1589 UINT i, row = 0, offset = 0, type, index = 0;
1590 UINT64 size = 1024 * 1024 * 1024;
1591 DWORD drives = GetLogicalDrives();
1592 enum fill_status status = FILL_STATUS_UNFILTERED;
1593
1594 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1595
1596 for (i = 0; i < sizeof(drives); i++)
1597 {
1598 if (drives & (1 << i))
1599 {
1600 root[0] = 'A' + i;
1601 type = GetDriveTypeW( root );
1602 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1603 continue;
1604
1605 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1606
1607 rec = (struct record_diskpartition *)(table->data + offset);
1608 rec->bootable = (i == 2) ? -1 : 0;
1609 rec->bootpartition = (i == 2) ? -1 : 0;
1610 sprintfW( device_id, fmtW, index );
1611 rec->device_id = heap_strdupW( device_id );
1612 rec->diskindex = index;
1613 rec->index = 0;
1614 rec->pnpdevice_id = heap_strdupW( device_id );
1615 get_freespace( root, &size );
1616 rec->size = size;
1617 rec->startingoffset = 0;
1618 rec->type = get_filesystem( root );
1619 if (!match_row( table, row, cond, &status ))
1620 {
1621 free_row_values( table, row );
1622 continue;
1623 }
1624 offset += sizeof(*rec);
1625 row++;
1626 index++;
1627 }
1628 }
1629 TRACE("created %u rows\n", row);
1630 table->num_rows = row;
1631 return status;
1632 }
1633
1634 static WCHAR *get_volumeserialnumber( const WCHAR *root )
1635 {
1636 static const WCHAR fmtW[] = {'%','0','8','X',0};
1637 DWORD serial = 0;
1638 WCHAR buffer[9];
1639
1640 GetVolumeInformationW( root, NULL, 0, &serial, NULL, NULL, NULL, 0 );
1641 sprintfW( buffer, fmtW, serial );
1642 return heap_strdupW( buffer );
1643 }
1644
1645 static enum fill_status fill_logicaldisk( struct table *table, const struct expr *cond )
1646 {
1647 static const WCHAR fmtW[] = {'%','c',':',0};
1648 WCHAR device_id[3], root[] = {'A',':','\\',0};
1649 struct record_logicaldisk *rec;
1650 UINT i, row = 0, offset = 0, type;
1651 UINT64 size = 1024 * 1024 * 1024;
1652 DWORD drives = GetLogicalDrives();
1653 enum fill_status status = FILL_STATUS_UNFILTERED;
1654
1655 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1656
1657 for (i = 0; i < sizeof(drives); i++)
1658 {
1659 if (drives & (1 << i))
1660 {
1661 root[0] = 'A' + i;
1662 type = GetDriveTypeW( root );
1663 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
1664 continue;
1665
1666 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1667
1668 rec = (struct record_logicaldisk *)(table->data + offset);
1669 sprintfW( device_id, fmtW, 'A' + i );
1670 rec->device_id = heap_strdupW( device_id );
1671 rec->drivetype = type;
1672 rec->filesystem = get_filesystem( root );
1673 rec->freespace = get_freespace( root, &size );
1674 rec->name = heap_strdupW( device_id );
1675 rec->size = size;
1676 rec->volumeserialnumber = get_volumeserialnumber( root );
1677 if (!match_row( table, row, cond, &status ))
1678 {
1679 free_row_values( table, row );
1680 continue;
1681 }
1682 offset += sizeof(*rec);
1683 row++;
1684 }
1685 }
1686 TRACE("created %u rows\n", row);
1687 table->num_rows = row;
1688 return status;
1689 }
1690
1691 static UINT16 get_connection_status( IF_OPER_STATUS status )
1692 {
1693 switch (status)
1694 {
1695 case IfOperStatusDown:
1696 return 0; /* Disconnected */
1697 case IfOperStatusUp:
1698 return 2; /* Connected */
1699 default:
1700 ERR("unhandled status %u\n", status);
1701 break;
1702 }
1703 return 0;
1704 }
1705 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
1706 {
1707 static const WCHAR fmtW[] =
1708 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
1709 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
1710 WCHAR *ret;
1711
1712 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
1713 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
1714 return ret;
1715 }
1716 static const WCHAR *get_adaptertype( DWORD type, int *physical )
1717 {
1718 static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
1719 static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
1720 static const WCHAR firewireW[] = {'1','3','9','4',0};
1721 static const WCHAR tunnelW[] = {'T','u','n','n','e','l',0};
1722
1723 switch (type)
1724 {
1725 case IF_TYPE_ETHERNET_CSMACD: *physical = -1; return ethernetW;
1726 case IF_TYPE_IEEE80211: *physical = -1; return wirelessW;
1727 case IF_TYPE_IEEE1394: *physical = -1; return firewireW;
1728 case IF_TYPE_TUNNEL: *physical = 0; return tunnelW;
1729 default: *physical = 0; return NULL;
1730 }
1731 }
1732
1733 static enum fill_status fill_networkadapter( struct table *table, const struct expr *cond )
1734 {
1735 static const WCHAR fmtW[] = {'%','u',0};
1736 WCHAR device_id[11];
1737 struct record_networkadapter *rec;
1738 IP_ADAPTER_ADDRESSES *aa, *buffer;
1739 UINT row = 0, offset = 0, count = 0;
1740 DWORD size = 0, ret;
1741 int physical;
1742 enum fill_status status = FILL_STATUS_UNFILTERED;
1743
1744 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1745 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1746
1747 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1748 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1749 {
1750 heap_free( buffer );
1751 return FILL_STATUS_FAILED;
1752 }
1753 for (aa = buffer; aa; aa = aa->Next)
1754 {
1755 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
1756 }
1757 if (!resize_table( table, count, sizeof(*rec) ))
1758 {
1759 heap_free( buffer );
1760 return FILL_STATUS_FAILED;
1761 }
1762 for (aa = buffer; aa; aa = aa->Next)
1763 {
1764 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
1765
1766 rec = (struct record_networkadapter *)(table->data + offset);
1767 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
1768 rec->adaptertype = get_adaptertype( aa->IfType, &physical );
1769 rec->device_id = heap_strdupW( device_id );
1770 rec->index = aa->u.s.IfIndex;
1771 rec->interface_index = aa->u.s.IfIndex;
1772 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1773 rec->manufacturer = compsys_manufacturerW;
1774 rec->name = heap_strdupW( aa->FriendlyName );
1775 rec->netconnection_status = get_connection_status( aa->OperStatus );
1776 rec->physicaladapter = physical;
1777 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
1778 rec->speed = 1000000;
1779 if (!match_row( table, row, cond, &status ))
1780 {
1781 free_row_values( table, row );
1782 continue;
1783 }
1784 offset += sizeof(*rec);
1785 row++;
1786 }
1787 TRACE("created %u rows\n", row);
1788 table->num_rows = row;
1789
1790 heap_free( buffer );
1791 return status;
1792 }
1793
1794 static enum fill_status fill_networkadapterconfig( struct table *table, const struct expr *cond )
1795 {
1796 struct record_networkadapterconfig *rec;
1797 IP_ADAPTER_ADDRESSES *aa, *buffer;
1798 UINT row = 0, offset = 0, count = 0;
1799 DWORD size = 0, ret;
1800 enum fill_status status = FILL_STATUS_UNFILTERED;
1801
1802 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1803 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1804
1805 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1806 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1807 {
1808 heap_free( buffer );
1809 return FILL_STATUS_FAILED;
1810 }
1811 for (aa = buffer; aa; aa = aa->Next)
1812 {
1813 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
1814 }
1815 if (!resize_table( table, count, sizeof(*rec) ))
1816 {
1817 heap_free( buffer );
1818 return FILL_STATUS_FAILED;
1819 }
1820 for (aa = buffer; aa; aa = aa->Next)
1821 {
1822 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
1823
1824 rec = (struct record_networkadapterconfig *)(table->data + offset);
1825 rec->index = aa->u.s.IfIndex;
1826 rec->ipconnectionmetric = 20;
1827 rec->ipenabled = -1;
1828 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1829 if (!match_row( table, row, cond, &status ))
1830 {
1831 free_row_values( table, row );
1832 continue;
1833 }
1834 offset += sizeof(*rec);
1835 row++;
1836 }
1837 TRACE("created %u rows\n", row);
1838 table->num_rows = row;
1839
1840 heap_free( buffer );
1841 return status;
1842 }
1843
1844 static enum fill_status fill_physicalmemory( struct table *table, const struct expr *cond )
1845 {
1846 struct record_physicalmemory *rec;
1847 enum fill_status status = FILL_STATUS_UNFILTERED;
1848 UINT row = 0;
1849
1850 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1851
1852 rec = (struct record_physicalmemory *)table->data;
1853 rec->capacity = get_total_physical_memory();
1854 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1855 else row++;
1856
1857 TRACE("created %u rows\n", row);
1858 table->num_rows = row;
1859 return status;
1860 }
1861
1862 static WCHAR *get_cmdline( DWORD process_id )
1863 {
1864 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
1865 return NULL; /* FIXME handle different process case */
1866 }
1867
1868 static enum fill_status fill_process( struct table *table, const struct expr *cond )
1869 {
1870 static const WCHAR fmtW[] = {'%','u',0};
1871 WCHAR handle[11];
1872 struct record_process *rec;
1873 PROCESSENTRY32W entry;
1874 HANDLE snap;
1875 enum fill_status status = FILL_STATUS_FAILED;
1876 UINT row = 0, offset = 0;
1877
1878 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
1879 if (snap == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED;
1880
1881 entry.dwSize = sizeof(entry);
1882 if (!Process32FirstW( snap, &entry )) goto done;
1883 if (!resize_table( table, 8, sizeof(*rec) )) goto done;
1884
1885 do
1886 {
1887 if (!resize_table( table, row + 1, sizeof(*rec) )) goto done;
1888
1889 rec = (struct record_process *)(table->data + offset);
1890 rec->caption = heap_strdupW( entry.szExeFile );
1891 rec->commandline = get_cmdline( entry.th32ProcessID );
1892 rec->description = heap_strdupW( entry.szExeFile );
1893 sprintfW( handle, fmtW, entry.th32ProcessID );
1894 rec->handle = heap_strdupW( handle );
1895 rec->name = heap_strdupW( entry.szExeFile );
1896 rec->process_id = entry.th32ProcessID;
1897 rec->pprocess_id = entry.th32ParentProcessID;
1898 rec->thread_count = entry.cntThreads;
1899 rec->get_owner = process_get_owner;
1900 if (!match_row( table, row, cond, &status ))
1901 {
1902 free_row_values( table, row );
1903 continue;
1904 }
1905 offset += sizeof(*rec);
1906 row++;
1907 } while (Process32NextW( snap, &entry ));
1908
1909 TRACE("created %u rows\n", row);
1910 table->num_rows = row;
1911 status = FILL_STATUS_UNFILTERED;
1912
1913 done:
1914 CloseHandle( snap );
1915 return status;
1916 }
1917
1918 static inline void do_cpuid( unsigned int ax, unsigned int *p )
1919 {
1920 #ifdef __i386__
1921 #ifdef _MSC_VER
1922 __cpuid(p, ax);
1923 #else
1924 __asm__("pushl %%ebx\n\t"
1925 "cpuid\n\t"
1926 "movl %%ebx, %%esi\n\t"
1927 "popl %%ebx"
1928 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
1929 : "0" (ax));
1930 #endif
1931 #endif
1932 }
1933
1934 static void get_processor_id( WCHAR *processor_id )
1935 {
1936 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
1937 unsigned int regs[4] = {0, 0, 0, 0};
1938
1939 do_cpuid( 1, regs );
1940 sprintfW( processor_id, fmtW, regs[3], regs[0] );
1941 }
1942 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
1943 {
1944 unsigned int i;
1945 unsigned char *p = (unsigned char *)regs;
1946
1947 for (i = 0; i < len; i++) { buffer[i] = *p++; }
1948 buffer[i] = 0;
1949 }
1950 static void get_processor_manufacturer( WCHAR *manufacturer )
1951 {
1952 unsigned int tmp, regs[4] = {0, 0, 0, 0};
1953
1954 do_cpuid( 0, regs );
1955 tmp = regs[2]; /* swap edx and ecx */
1956 regs[2] = regs[3];
1957 regs[3] = tmp;
1958
1959 regs_to_str( regs + 1, 12, manufacturer );
1960 }
1961 static void get_processor_name( WCHAR *name )
1962 {
1963 unsigned int regs[4] = {0, 0, 0, 0};
1964
1965 do_cpuid( 0x80000000, regs );
1966 if (regs[0] >= 0x80000004)
1967 {
1968 do_cpuid( 0x80000002, regs );
1969 regs_to_str( regs, 16, name );
1970 do_cpuid( 0x80000003, regs );
1971 regs_to_str( regs, 16, name + 16 );
1972 do_cpuid( 0x80000004, regs );
1973 regs_to_str( regs, 16, name + 32 );
1974 }
1975 }
1976 static UINT get_processor_currentclockspeed( UINT index )
1977 {
1978 PROCESSOR_POWER_INFORMATION *info;
1979 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1980 NTSTATUS status;
1981
1982 if ((info = heap_alloc( size )))
1983 {
1984 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
1985 if (!status) ret = info[index].CurrentMhz;
1986 heap_free( info );
1987 }
1988 return ret;
1989 }
1990 static UINT get_processor_maxclockspeed( UINT index )
1991 {
1992 PROCESSOR_POWER_INFORMATION *info;
1993 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1994 NTSTATUS status;
1995
1996 if ((info = heap_alloc( size )))
1997 {
1998 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
1999 if (!status) ret = info[index].MaxMhz;
2000 heap_free( info );
2001 }
2002 return ret;
2003 }
2004 static const WCHAR *get_osarchitecture(void)
2005 {
2006 SYSTEM_INFO info;
2007 GetNativeSystemInfo( &info );
2008 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
2009 return os_32bitW;
2010 }
2011
2012 static enum fill_status fill_processor( struct table *table, const struct expr *cond )
2013 {
2014 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
2015 WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
2016 struct record_processor *rec;
2017 UINT i, offset = 0, num_cores, num_logical_processors, count = get_processor_count();
2018 enum fill_status status = FILL_STATUS_UNFILTERED;
2019
2020 if (!resize_table( table, count, sizeof(*rec) )) return FILL_STATUS_FAILED;
2021
2022 get_processor_id( processor_id );
2023 get_processor_manufacturer( manufacturer );
2024 get_processor_name( name );
2025
2026 num_logical_processors = get_logical_processor_count( &num_cores ) / count;
2027 num_cores /= count;
2028
2029 for (i = 0; i < count; i++)
2030 {
2031 rec = (struct record_processor *)(table->data + offset);
2032 rec->addresswidth = get_osarchitecture() == os_32bitW ? 32 : 64;
2033 rec->cpu_status = 1; /* CPU Enabled */
2034 rec->currentclockspeed = get_processor_currentclockspeed( i );
2035 sprintfW( device_id, fmtW, i );
2036 rec->device_id = heap_strdupW( device_id );
2037 rec->family = 2; /* Unknown */
2038 rec->manufacturer = heap_strdupW( manufacturer );
2039 rec->maxclockspeed = get_processor_maxclockspeed( i );
2040 rec->name = heap_strdupW( name );
2041 rec->num_cores = num_cores;
2042 rec->num_logical_processors = num_logical_processors;
2043 rec->processor_id = heap_strdupW( processor_id );
2044 rec->unique_id = NULL;
2045 if (!match_row( table, i, cond, &status ))
2046 {
2047 free_row_values( table, i );
2048 continue;
2049 }
2050 offset += sizeof(*rec);
2051 }
2052
2053 TRACE("created %u rows\n", count);
2054 table->num_rows = count;
2055 return status;
2056 }
2057
2058 static WCHAR *get_lastbootuptime(void)
2059 {
2060 static const WCHAR fmtW[] =
2061 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
2062 '.','%','0','6','u','+','0','0','0',0};
2063 SYSTEM_TIMEOFDAY_INFORMATION ti;
2064 TIME_FIELDS tf;
2065 WCHAR *ret;
2066
2067 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2068
2069 NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
2070 RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
2071 sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
2072 return ret;
2073 }
2074 static WCHAR *get_localdatetime(void)
2075 {
2076 static const WCHAR fmtW[] =
2077 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
2078 '.','%','0','6','u','%','+','0','3','d',0};
2079 TIME_ZONE_INFORMATION tzi;
2080 SYSTEMTIME st;
2081 WCHAR *ret;
2082 DWORD Status;
2083 LONG Bias;
2084
2085 Status = GetTimeZoneInformation(&tzi);
2086
2087 if(Status == TIME_ZONE_ID_INVALID) return NULL;
2088 Bias = tzi.Bias;
2089 if(Status == TIME_ZONE_ID_DAYLIGHT)
2090 Bias+= tzi.DaylightBias;
2091 else
2092 Bias+= tzi.StandardBias;
2093 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2094
2095 GetLocalTime(&st);
2096 sprintfW( ret, fmtW, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds * 1000, -Bias);
2097 return ret;
2098 }
2099 static WCHAR *get_systemdirectory(void)
2100 {
2101 void *redir;
2102 WCHAR *ret;
2103
2104 if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
2105 Wow64DisableWow64FsRedirection( &redir );
2106 GetSystemDirectoryW( ret, MAX_PATH );
2107 Wow64RevertWow64FsRedirection( redir );
2108 return ret;
2109 }
2110 static WCHAR *get_codeset(void)
2111 {
2112 static const WCHAR fmtW[] = {'%','u',0};
2113 WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
2114 if (ret) sprintfW( ret, fmtW, GetACP() );
2115 return ret;
2116 }
2117 static WCHAR *get_countrycode(void)
2118 {
2119 WCHAR *ret = heap_alloc( 6 * sizeof(WCHAR) );
2120 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY, ret, 6 );
2121 return ret;
2122 }
2123 static WCHAR *get_locale(void)
2124 {
2125 WCHAR *ret = heap_alloc( 5 * sizeof(WCHAR) );
2126 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, ret, 5 );
2127 return ret;
2128 }
2129
2130 static enum fill_status fill_os( struct table *table, const struct expr *cond )
2131 {
2132 struct record_operatingsystem *rec;
2133 enum fill_status status = FILL_STATUS_UNFILTERED;
2134 UINT row = 0;
2135
2136 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2137
2138 rec = (struct record_operatingsystem *)table->data;
2139 rec->buildnumber = os_buildnumberW;
2140 rec->caption = os_captionW;
2141 rec->codeset = get_codeset();
2142 rec->countrycode = get_countrycode();
2143 rec->csdversion = os_csdversionW;
2144 rec->installdate = os_installdateW;
2145 rec->lastbootuptime = get_lastbootuptime();
2146 rec->localdatetime = get_localdatetime();
2147 rec->locale = get_locale();
2148 rec->name = os_nameW;
2149 rec->osarchitecture = get_osarchitecture();
2150 rec->oslanguage = GetSystemDefaultLangID();
2151 rec->osproductsuite = 2461140; /* Windows XP Professional */
2152 rec->ostype = 18; /* WINNT */
2153 rec->serialnumber = os_serialnumberW;
2154 rec->servicepackmajor = 3;
2155 rec->servicepackminor = 0;
2156 rec->suitemask = 272; /* Single User + Terminal */
2157 rec->systemdirectory = get_systemdirectory();
2158 rec->version = os_versionW;
2159 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2160 else row++;
2161
2162 TRACE("created %u rows\n", row);
2163 table->num_rows = row;
2164 return status;
2165 }
2166
2167 static const WCHAR *get_service_type( DWORD type )
2168 {
2169 static const WCHAR filesystem_driverW[] =
2170 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
2171 static const WCHAR kernel_driverW[] =
2172 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
2173 static const WCHAR own_processW[] =
2174 {'O','w','n',' ','P','r','o','c','e','s','s',0};
2175 static const WCHAR share_processW[] =
2176 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
2177
2178 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
2179 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
2180 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
2181 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
2182 else ERR("unhandled type 0x%08x\n", type);
2183 return NULL;
2184 }
2185 static const WCHAR *get_service_state( DWORD state )
2186 {
2187 static const WCHAR runningW[] =
2188 {'R','u','n','n','i','n','g',0};
2189 static const WCHAR start_pendingW[] =
2190 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
2191 static const WCHAR stop_pendingW[] =
2192 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
2193 static const WCHAR stoppedW[] =
2194 {'S','t','o','p','p','e','d',0};
2195 static const WCHAR unknownW[] =
2196 {'U','n','k','n','o','w','n',0};
2197
2198 switch (state)
2199 {
2200 case SERVICE_STOPPED: return stoppedW;
2201 case SERVICE_START_PENDING: return start_pendingW;
2202 case SERVICE_STOP_PENDING: return stop_pendingW;
2203 case SERVICE_RUNNING: return runningW;
2204 default:
2205 ERR("unknown state %u\n", state);
2206 return unknownW;
2207 }
2208 }
2209 static const WCHAR *get_service_startmode( DWORD mode )
2210 {
2211 static const WCHAR bootW[] = {'B','o','o','t',0};
2212 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
2213 static const WCHAR autoW[] = {'A','u','t','o',0};
2214 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
2215 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
2216 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
2217
2218 switch (mode)
2219 {
2220 case SERVICE_BOOT_START: return bootW;
2221 case SERVICE_SYSTEM_START: return systemW;
2222 case SERVICE_AUTO_START: return autoW;
2223 case SERVICE_DEMAND_START: return manualW;
2224 case SERVICE_DISABLED: return disabledW;
2225 default:
2226 ERR("unknown mode 0x%x\n", mode);
2227 return unknownW;
2228 }
2229 }
2230 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
2231 {
2232 QUERY_SERVICE_CONFIGW *config = NULL;
2233 SC_HANDLE service;
2234 DWORD size;
2235
2236 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
2237 QueryServiceConfigW( service, NULL, 0, &size );
2238 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
2239 if (!(config = heap_alloc( size ))) goto done;
2240 if (QueryServiceConfigW( service, config, size, &size )) goto done;
2241 heap_free( config );
2242 config = NULL;
2243
2244 done:
2245 CloseServiceHandle( service );
2246 return config;
2247 }
2248
2249 static enum fill_status fill_service( struct table *table, const struct expr *cond )
2250 {
2251 struct record_service *rec;
2252 SC_HANDLE manager;
2253 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
2254 SERVICE_STATUS_PROCESS *status;
2255 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
2256 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
2257 UINT i, row = 0, offset = 0, size = 256, needed, count;
2258 enum fill_status fill_status = FILL_STATUS_FAILED;
2259 BOOL ret;
2260
2261 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return FILL_STATUS_FAILED;
2262 if (!(services = heap_alloc( size ))) goto done;
2263
2264 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2265 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2266 &count, NULL, NULL );
2267 if (!ret)
2268 {
2269 if (GetLastError() != ERROR_MORE_DATA) goto done;
2270 size = needed;
2271 if (!(tmp = heap_realloc( services, size ))) goto done;
2272 services = tmp;
2273 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2274 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2275 &count, NULL, NULL );
2276 if (!ret) goto done;
2277 }
2278 if (!resize_table( table, count, sizeof(*rec) )) goto done;
2279
2280 GetComputerNameW( sysnameW, &len );
2281 fill_status = FILL_STATUS_UNFILTERED;
2282
2283 for (i = 0; i < count; i++)
2284 {
2285 QUERY_SERVICE_CONFIGW *config;
2286
2287 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
2288
2289 status = &services[i].ServiceStatusProcess;
2290 rec = (struct record_service *)(table->data + offset);
2291 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
2292 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
2293 rec->displayname = heap_strdupW( services[i].lpDisplayName );
2294 rec->name = heap_strdupW( services[i].lpServiceName );
2295 rec->process_id = status->dwProcessId;
2296 rec->servicetype = get_service_type( status->dwServiceType );
2297 rec->startmode = get_service_startmode( config->dwStartType );
2298 rec->state = get_service_state( status->dwCurrentState );
2299 rec->systemname = heap_strdupW( sysnameW );
2300 rec->pause_service = service_pause_service;
2301 rec->resume_service = service_resume_service;
2302 rec->start_service = service_start_service;
2303 rec->stop_service = service_stop_service;
2304 heap_free( config );
2305 if (!match_row( table, row, cond, &fill_status ))
2306 {
2307 free_row_values( table, row );
2308 continue;
2309 }
2310 offset += sizeof(*rec);
2311 row++;
2312 }
2313
2314 TRACE("created %u rows\n", row);
2315 table->num_rows = row;
2316
2317 done:
2318 CloseServiceHandle( manager );
2319 heap_free( services );
2320 return fill_status;
2321 }
2322
2323 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
2324 {
2325 HDC hdc = GetDC( NULL );
2326 UINT32 ret;
2327
2328 if (!hdc) return 32;
2329 ret = GetDeviceCaps( hdc, BITSPIXEL );
2330 *hres = GetDeviceCaps( hdc, HORZRES );
2331 *vres = GetDeviceCaps( hdc, VERTRES );
2332 ReleaseDC( NULL, hdc );
2333 return ret;
2334 }
2335 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
2336 {
2337 static const WCHAR fmtW[] =
2338 {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
2339 '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
2340 '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
2341 WCHAR *ret;
2342
2343 if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
2344 sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
2345 return ret;
2346 }
2347
2348 static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond )
2349 {
2350
2351 struct record_videocontroller *rec;
2352 HRESULT hr;
2353 IDXGIFactory *factory = NULL;
2354 IDXGIAdapter *adapter = NULL;
2355 DXGI_ADAPTER_DESC desc;
2356 UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
2357 const WCHAR *name = videocontroller_deviceidW;
2358 enum fill_status status = FILL_STATUS_UNFILTERED;
2359 UINT row = 0;
2360
2361 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2362
2363 memset (&desc, 0, sizeof(desc));
2364 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
2365 if (FAILED(hr)) goto done;
2366
2367 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
2368 if (FAILED(hr)) goto done;
2369
2370 hr = IDXGIAdapter_GetDesc( adapter, &desc );
2371 if (SUCCEEDED(hr))
2372 {
2373 vidmem = desc.DedicatedVideoMemory;
2374 name = desc.Description;
2375 }
2376
2377 done:
2378 rec = (struct record_videocontroller *)table->data;
2379 rec->adapter_dactype = videocontroller_dactypeW;
2380 rec->adapter_ram = vidmem;
2381 rec->availability = 3; /* Running or Full Power */
2382 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
2383 rec->current_horizontalres = hres;
2384 rec->current_verticalres = vres;
2385 rec->description = heap_strdupW( name );
2386 rec->device_id = videocontroller_deviceidW;
2387 rec->name = heap_strdupW( name );
2388 rec->pnpdevice_id = get_pnpdeviceid( &desc );
2389 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2390 else row++;
2391
2392 TRACE("created %u rows\n", row);
2393 table->num_rows = row;
2394
2395 if (adapter) IDXGIAdapter_Release( adapter );
2396 if (factory) IDXGIFactory_Release( factory );
2397 return status;
2398 }
2399
2400 static struct table builtin_classes[] =
2401 {
2402 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), 0, (BYTE *)data_baseboard },
2403 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), 0, (BYTE *)data_bios },
2404 { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, 0, 0, NULL, fill_cdromdrive },
2405 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, 0, NULL, fill_compsys },
2406 { class_datafileW, SIZEOF(col_datafile), col_datafile, 0, 0, NULL, fill_datafile },
2407 { class_directoryW, SIZEOF(col_directory), col_directory, 0, 0, NULL, fill_directory },
2408 { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, 0, 0, NULL, fill_diskdrive },
2409 { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, 0, NULL, fill_diskpartition },
2410 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2411 { class_logicaldisk2W, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2412 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, 0, NULL, fill_networkadapter },
2413 { class_networkadapterconfigW, SIZEOF(col_networkadapterconfig), col_networkadapterconfig, 0, 0, NULL,
2414 fill_networkadapterconfig },
2415 { class_osW, SIZEOF(col_os), col_os, 0, 0, NULL, fill_os },
2416 { class_paramsW, SIZEOF(col_param), col_param, SIZEOF(data_param), 0, (BYTE *)data_param },
2417 { class_physicalmediaW, SIZEOF(col_physicalmedia), col_physicalmedia, SIZEOF(data_physicalmedia), 0, (BYTE *)data_physicalmedia },
2418 { class_physicalmemoryW, SIZEOF(col_physicalmemory), col_physicalmemory, 0, 0, NULL, fill_physicalmemory },
2419 { class_processW, SIZEOF(col_process), col_process, 0, 0, NULL, fill_process },
2420 { class_processorW, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
2421 { class_processor2W, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
2422 { class_qualifiersW, SIZEOF(col_qualifier), col_qualifier, SIZEOF(data_qualifier), 0, (BYTE *)data_qualifier },
2423 { class_serviceW, SIZEOF(col_service), col_service, 0, 0, NULL, fill_service },
2424 { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), 0, (BYTE *)data_sounddevice },
2425 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), 0, (BYTE *)data_stdregprov },
2426 { class_systemsecurityW, SIZEOF(col_systemsecurity), col_systemsecurity, SIZEOF(data_systemsecurity), 0, (BYTE *)data_systemsecurity },
2427 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, 0, NULL, fill_videocontroller }
2428 };
2429
2430 void init_table_list( void )
2431 {
2432 static struct list tables = LIST_INIT( tables );
2433 UINT i;
2434
2435 for (i = 0; i < SIZEOF(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
2436 table_list = &tables;
2437 }