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