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