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