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