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