inetcomm: Added tests reading MHTML page as MIME message.
[wine.git] / dlls / wbemprox / builtin.c
blob14e819e5373c955272c61684b8abac2eab2b0c0e
1 /*
2 * Copyright 2012 Hans Leidekker for CodeWeavers
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.
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.
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
19 #define COBJMACROS
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
23 #include "config.h"
24 #include <stdarg.h>
25 #include <fcntl.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
30 #include "ntstatus.h"
31 #define WIN32_NO_STATUS
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winsock2.h"
35 #include "ws2tcpip.h"
36 #include "initguid.h"
37 #include "wbemcli.h"
38 #include "wbemprov.h"
39 #include "iphlpapi.h"
40 #include "tlhelp32.h"
41 #include "d3d10.h"
42 #include "winternl.h"
43 #include "winioctl.h"
44 #include "winsvc.h"
45 #include "winver.h"
46 #include "sddl.h"
47 #include "ntsecapi.h"
48 #include "winspool.h"
50 #include "wine/debug.h"
51 #include "wbemprox_private.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
55 static const WCHAR class_baseboardW[] =
56 {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
57 static const WCHAR class_biosW[] =
58 {'W','i','n','3','2','_','B','I','O','S',0};
59 static const WCHAR class_cdromdriveW[] =
60 {'W','i','n','3','2','_','C','D','R','O','M','D','r','i','v','e',0};
61 static const WCHAR class_compsysW[] =
62 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
63 static const WCHAR class_compsysproductW[] =
64 {'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};
65 static const WCHAR class_datafileW[] =
66 {'C','I','M','_','D','a','t','a','F','i','l','e',0};
67 static const WCHAR class_desktopmonitorW[] =
68 {'W','i','n','3','2','_','D','e','s','k','t','o','p','M','o','n','i','t','o','r',0};
69 static const WCHAR class_directoryW[] =
70 {'W','i','n','3','2','_','D','i','r','e','c','t','o','r','y',0};
71 static const WCHAR class_diskdriveW[] =
72 {'W','i','n','3','2','_','D','i','s','k','D','r','i','v','e',0};
73 static const WCHAR class_diskpartitionW[] =
74 {'W','i','n','3','2','_','D','i','s','k','P','a','r','t','i','t','i','o','n',0};
75 static const WCHAR class_logicaldiskW[] =
76 {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
77 static const WCHAR class_logicaldisk2W[] =
78 {'C','I','M','_','L','o','g','i','c','a','l','D','i','s','k',0};
79 static const WCHAR class_networkadapterW[] =
80 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
81 static const WCHAR class_networkadapterconfigW[] =
82 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',
83 'C','o','n','f','i','g','u','r','a','t','i','o','n',0};
84 static const WCHAR class_osW[] =
85 {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
86 static const WCHAR class_paramsW[] =
87 {'_','_','P','A','R','A','M','E','T','E','R','S',0};
88 static const WCHAR class_physicalmediaW[] =
89 {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','d','i','a',0};
90 static const WCHAR class_physicalmemoryW[] =
91 {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
92 static const WCHAR class_printerW[] =
93 {'W','i','n','3','2','_','P','r','i','n','t','e','r',0};
94 static const WCHAR class_process_getowner_outW[] =
95 {'_','_','W','I','N','3','2','_','P','R','O','C','E','S','S','_','G','E','T','O','W',
96 'N','E','R','_','O','U','T',0};
97 static const WCHAR class_processorW[] =
98 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
99 static const WCHAR class_processor2W[] =
100 {'C','I','M','_','P','r','o','c','e','s','s','o','r',0};
101 static const WCHAR class_qualifiersW[] =
102 {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
103 static const WCHAR class_sidW[] =
104 {'W','i','n','3','2','_','S','I','D',0};
105 static const WCHAR class_sounddeviceW[] =
106 {'W','i','n','3','2','_','S','o','u','n','d','D','e','v','i','c','e',0};
107 static const WCHAR class_systemenclosureW[] =
108 {'W','i','n','3','2','_','S','y','s','t','e','m','E','n','c','l','o','s','u','r','e',0};
109 static const WCHAR class_videocontrollerW[] =
110 {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
112 static const WCHAR prop_accountnameW[] =
113 {'A','c','c','o','u','n','t','N','a','m','e',0};
114 static const WCHAR prop_acceptpauseW[] =
115 {'A','c','c','e','p','t','P','a','u','s','e',0};
116 static const WCHAR prop_acceptstopW[] =
117 {'A','c','c','e','p','t','S','t','o','p',0};
118 static const WCHAR prop_accessmaskW[] =
119 {'A','c','c','e','s','s','M','a','s','k',0};
120 static const WCHAR prop_adapterdactypeW[] =
121 {'A','d','a','p','t','e','r','D','A','C','T','y','p','e',0};
122 static const WCHAR prop_adapterramW[] =
123 {'A','d','a','p','t','e','r','R','A','M',0};
124 static const WCHAR prop_adaptertypeW[] =
125 {'A','d','a','p','t','e','r','T','y','p','e',0};
126 static const WCHAR prop_addresswidthW[] =
127 {'A','d','d','r','e','s','s','W','i','d','t','h',0};
128 static const WCHAR prop_attributesW[] =
129 {'A','t','t','r','i','b','u','t','e','s',0};
130 static const WCHAR prop_availabilityW[] =
131 {'A','v','a','i','l','a','b','i','l','i','t','y',0};
132 static const WCHAR prop_binaryrepresentationW[] =
133 {'B','i','n','a','r','y','R','e','p','r','e','s','e','n','t','a','t','i','o','n',0};
134 static const WCHAR prop_bootableW[] =
135 {'B','o','o','t','a','b','l','e',0};
136 static const WCHAR prop_bootpartitionW[] =
137 {'B','o','o','t','P','a','r','t','i','t','i','o','n',0};
138 static const WCHAR prop_buildnumberW[] =
139 {'B','u','i','l','d','N','u','m','b','e','r',0};
140 static const WCHAR prop_capacityW[] =
141 {'C','a','p','a','c','i','t','y',0};
142 static const WCHAR prop_captionW[] =
143 {'C','a','p','t','i','o','n',0};
144 static const WCHAR prop_chassistypesW[] =
145 {'C','h','a','s','s','i','s','T','y','p','e','s',0};
146 static const WCHAR prop_classW[] =
147 {'C','l','a','s','s',0};
148 static const WCHAR prop_codesetW[] =
149 {'C','o','d','e','S','e','t',0};
150 static const WCHAR prop_commandlineW[] =
151 {'C','o','m','m','a','n','d','L','i','n','e',0};
152 static const WCHAR prop_countrycodeW[] =
153 {'C','o','u','n','t','r','y','C','o','d','e',0};
154 static const WCHAR prop_cpustatusW[] =
155 {'C','p','u','S','t','a','t','u','s',0};
156 static const WCHAR prop_csdversionW[] =
157 {'C','S','D','V','e','r','s','i','o','n',0};
158 static const WCHAR prop_currentbitsperpixelW[] =
159 {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
160 static const WCHAR prop_currentclockspeedW[] =
161 {'C','u','r','r','e','n','t','C','l','o','c','k','S','p','e','e','d',0};
162 static const WCHAR prop_currenthorizontalresW[] =
163 {'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};
164 static const WCHAR prop_currentrefreshrateW[] =
165 {'C','u','r','r','e','n','t','R','e','f','r','e','s','h','R','a','t','e',0};
166 static const WCHAR prop_currentscanmodeW[] =
167 {'C','u','r','r','e','n','t','S','c','a','n','M','o','d','e',0};
168 static const WCHAR prop_currentverticalresW[] =
169 {'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};
170 static const WCHAR prop_datawidthW[] =
171 {'D','a','t','a','W','i','d','t','h',0};
172 static const WCHAR prop_defaultipgatewayW[] =
173 {'D','e','f','a','u','l','t','I','P','G','a','t','e','w','a','y',0};
174 static const WCHAR prop_defaultvalueW[] =
175 {'D','e','f','a','u','l','t','V','a','l','u','e',0};
176 static const WCHAR prop_descriptionW[] =
177 {'D','e','s','c','r','i','p','t','i','o','n',0};
178 static const WCHAR prop_deviceidW[] =
179 {'D','e','v','i','c','e','I','d',0};
180 static const WCHAR prop_dhcpenabledW[] =
181 {'D','H','C','P','E','n','a','b','l','e','d',0};
182 static const WCHAR prop_directionW[] =
183 {'D','i','r','e','c','t','i','o','n',0};
184 static const WCHAR prop_displaynameW[] =
185 {'D','i','s','p','l','a','y','N','a','m','e',0};
186 static const WCHAR prop_diskindexW[] =
187 {'D','i','s','k','I','n','d','e','x',0};
188 static const WCHAR prop_dnshostnameW[] =
189 {'D','N','S','H','o','s','t','N','a','m','e',0};
190 static const WCHAR prop_dnsserversearchorderW[] =
191 {'D','N','S','S','e','r','v','e','r','S','e','a','r','c','h','O','r','d','e','r',0};
192 static const WCHAR prop_domainW[] =
193 {'D','o','m','a','i','n',0};
194 static const WCHAR prop_domainroleW[] =
195 {'D','o','m','a','i','n','R','o','l','e',0};
196 static const WCHAR prop_driveW[] =
197 {'D','r','i','v','e',0};
198 static const WCHAR prop_drivernameW[] =
199 {'D','r','i','v','e','r','N','a','m','e',0};
200 static const WCHAR prop_driverversionW[] =
201 {'D','r','i','v','e','r','V','e','r','s','i','o','n',0};
202 static const WCHAR prop_drivetypeW[] =
203 {'D','r','i','v','e','T','y','p','e',0};
204 static const WCHAR prop_familyW[] =
205 {'F','a','m','i','l','y',0};
206 static const WCHAR prop_filesystemW[] =
207 {'F','i','l','e','S','y','s','t','e','m',0};
208 static const WCHAR prop_flavorW[] =
209 {'F','l','a','v','o','r',0};
210 static const WCHAR prop_freespaceW[] =
211 {'F','r','e','e','S','p','a','c','e',0};
212 static const WCHAR prop_handleW[] =
213 {'H','a','n','d','l','e',0};
214 static const WCHAR prop_horizontalresolutionW[] =
215 {'H','o','r','i','z','o','n','t','a','l','R','e','s','o','l','u','t','i','o','n',0};
216 static const WCHAR prop_idW[] =
217 {'I','D',0};
218 static const WCHAR prop_identificationcodeW[] =
219 {'I','d','e','n','t','i','f','i','c','a','t','i','o','n','C','o','d','e',0};
220 static const WCHAR prop_identifyingnumberW[] =
221 {'I','d','e','n','t','i','f','y','i','n','g','N','u','m','b','e','r',0};
222 static const WCHAR prop_indexW[] =
223 {'I','n','d','e','x',0};
224 static const WCHAR prop_installdateW[] =
225 {'I','n','s','t','a','l','l','D','a','t','e',0};
226 static const WCHAR prop_interfaceindexW[] =
227 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
228 static const WCHAR prop_interfacetypeW[] =
229 {'I','n','t','e','r','f','a','c','e','T','y','p','e',0};
230 static const WCHAR prop_intvalueW[] =
231 {'I','n','t','e','g','e','r','V','a','l','u','e',0};
232 static const WCHAR prop_ipconnectionmetricW[] =
233 {'I','P','C','o','n','n','e','c','t','i','o','n','M','e','t','r','i','c',0};
234 static const WCHAR prop_ipenabledW[] =
235 {'I','P','E','n','a','b','l','e','d',0};
236 static const WCHAR prop_lastbootuptimeW[] =
237 {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
238 static const WCHAR prop_localW[] =
239 {'L','o','c','a','l',0};
240 static const WCHAR prop_localdatetimeW[] =
241 {'L','o','c','a','l','D','a','t','e','T','i','m','e',0};
242 static const WCHAR prop_localeW[] =
243 {'L','o','c','a','l','e',0};
244 static const WCHAR prop_lockpresentW[] =
245 {'L','o','c','k','P','r','e','s','e','n','t',0};
246 static const WCHAR prop_macaddressW[] =
247 {'M','A','C','A','d','d','r','e','s','s',0};
248 static const WCHAR prop_manufacturerW[] =
249 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
250 static const WCHAR prop_maxclockspeedW[] =
251 {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
252 static const WCHAR prop_mediatypeW[] =
253 {'M','e','d','i','a','T','y','p','e',0};
254 static const WCHAR prop_memberW[] =
255 {'M','e','m','b','e','r',0};
256 static const WCHAR prop_memorytypeW[] =
257 {'M','e','m','o','r','y','T','y','p','e',0};
258 static const WCHAR prop_methodW[] =
259 {'M','e','t','h','o','d',0};
260 static const WCHAR prop_modelW[] =
261 {'M','o','d','e','l',0};
262 static const WCHAR prop_netconnectionstatusW[] =
263 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
264 static const WCHAR prop_networkW[] =
265 {'N','e','t','w','o','r','k',0};
266 static const WCHAR prop_numcoresW[] =
267 {'N','u','m','b','e','r','O','f','C','o','r','e','s',0};
268 static const WCHAR prop_numlogicalprocessorsW[] =
269 {'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};
270 static const WCHAR prop_numprocessorsW[] =
271 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
272 static const WCHAR prop_osarchitectureW[] =
273 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
274 static const WCHAR prop_oslanguageW[] =
275 {'O','S','L','a','n','g','u','a','g','e',0};
276 static const WCHAR prop_osproductsuiteW[] =
277 {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
278 static const WCHAR prop_ostypeW[] =
279 {'O','S','T','y','p','e',0};
280 static const WCHAR prop_parameterW[] =
281 {'P','a','r','a','m','e','t','e','r',0};
282 static const WCHAR prop_physicaladapterW[] =
283 {'P','h','y','s','i','c','a','l','A','d','a','p','t','e','r',0};
284 static const WCHAR prop_pixelsperxlogicalinchW[] =
285 {'P','i','x','e','l','s','P','e','r','X','L','o','g','i','c','a','l','I','n','c','h',0};
286 static const WCHAR prop_pnpdeviceidW[] =
287 {'P','N','P','D','e','v','i','c','e','I','D',0};
288 static const WCHAR prop_pprocessidW[] =
289 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
290 static const WCHAR prop_primaryW[] =
291 {'P','r','i','m','a','r','y',0};
292 static const WCHAR prop_processidW[] =
293 {'P','r','o','c','e','s','s','I','D',0};
294 static const WCHAR prop_processoridW[] =
295 {'P','r','o','c','e','s','s','o','r','I','d',0};
296 static const WCHAR prop_processortypeW[] =
297 {'P','r','o','c','e','s','s','o','r','T','y','p','e',0};
298 static const WCHAR prop_productW[] =
299 {'P','r','o','d','u','c','t',0};
300 static const WCHAR prop_productnameW[] =
301 {'P','r','o','d','u','c','t','N','a','m','e',0};
302 static const WCHAR prop_referenceddomainnameW[] =
303 {'R','e','f','e','r','e','n','c','e','d','D','o','m','a','i','n','N','a','m','e',0};
304 static const WCHAR prop_releasedateW[] =
305 {'R','e','l','e','a','s','e','D','a','t','e',0};
306 static const WCHAR prop_serialnumberW[] =
307 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
308 static const WCHAR prop_servicepackmajorW[] =
309 {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
310 static const WCHAR prop_servicepackminorW[] =
311 {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
312 static const WCHAR prop_servicetypeW[] =
313 {'S','e','r','v','i','c','e','T','y','p','e',0};
314 static const WCHAR prop_settingidW[] =
315 {'S','e','t','t','i','n','g','I','D',0};
316 static const WCHAR prop_smbiosbiosversionW[] =
317 {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
318 static const WCHAR prop_startmodeW[] =
319 {'S','t','a','r','t','M','o','d','e',0};
320 static const WCHAR prop_sidW[] =
321 {'S','I','D',0};
322 static const WCHAR prop_sidlengthW[] =
323 {'S','i','d','L','e','n','g','t','h',0};
324 static const WCHAR prop_sizeW[] =
325 {'S','i','z','e',0};
326 static const WCHAR prop_speedW[] =
327 {'S','p','e','e','d',0};
328 static const WCHAR prop_startingoffsetW[] =
329 {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0};
330 static const WCHAR prop_stateW[] =
331 {'S','t','a','t','e',0};
332 static const WCHAR prop_statusinfoW[] =
333 {'S','t','a','t','u','s','I','n','f','o',0};
334 static const WCHAR prop_strvalueW[] =
335 {'S','t','r','i','n','g','V','a','l','u','e',0};
336 static const WCHAR prop_suitemaskW[] =
337 {'S','u','i','t','e','M','a','s','k',0};
338 static const WCHAR prop_systemdirectoryW[] =
339 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
340 static const WCHAR prop_systemnameW[] =
341 {'S','y','s','t','e','m','N','a','m','e',0};
342 static const WCHAR prop_tagW[] =
343 {'T','a','g',0};
344 static const WCHAR prop_threadcountW[] =
345 {'T','h','r','e','a','d','C','o','u','n','t',0};
346 static const WCHAR prop_totalphysicalmemoryW[] =
347 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
348 static const WCHAR prop_totalvirtualmemorysizeW[] =
349 {'T','o','t','a','l','V','i','r','t','u','a','l','M','e','m','o','r','y','S','i','z','e',0};
350 static const WCHAR prop_totalvisiblememorysizeW[] =
351 {'T','o','t','a','l','V','i','s','i','b','l','e','M','e','m','o','r','y','S','i','z','e',0};
352 static const WCHAR prop_typeW[] =
353 {'T','y','p','e',0};
354 static const WCHAR prop_uniqueidW[] =
355 {'U','n','i','q','u','e','I','d',0};
356 static const WCHAR prop_usernameW[] =
357 {'U','s','e','r','N','a','m','e',0};
358 static const WCHAR prop_uuidW[] =
359 {'U','U','I','D',0};
360 static const WCHAR prop_varianttypeW[] =
361 {'V','a','r','i','a','n','t','T','y','p','e',0};
362 static const WCHAR prop_versionW[] =
363 {'V','e','r','s','i','o','n',0};
364 static const WCHAR prop_videoarchitectureW[] =
365 {'V','i','d','e','o','A','r','c','h','i','t','e','c','t','u','r','e',0};
366 static const WCHAR prop_videomemorytypeW[] =
367 {'V','i','d','e','o','M','e','m','o','r','y','T','y','p','e',0};
368 static const WCHAR prop_videomodedescriptionW[] =
369 {'V','i','d','e','o','M','o','d','e','D','e','s','c','r','i','p','t','i','o','n',0};
370 static const WCHAR prop_videoprocessorW[] =
371 {'V','i','d','e','o','P','r','o','c','e','s','s','o','r',0};
372 static const WCHAR prop_volumenameW[] =
373 {'V','o','l','u','m','e','N','a','m','e',0};
374 static const WCHAR prop_volumeserialnumberW[] =
375 {'V','o','l','u','m','e','S','e','r','i','a','l','N','u','m','b','e','r',0};
376 static const WCHAR prop_workingsetsizeW[] =
377 {'W','o','r','k','i','n','g','S','e','t','S','i','z','e',0};
379 /* column definitions must be kept in sync with record structures below */
380 static const struct column col_baseboard[] =
382 { prop_manufacturerW, CIM_STRING },
383 { prop_modelW, CIM_STRING },
384 { prop_nameW, CIM_STRING },
385 { prop_productW, CIM_STRING },
386 { prop_serialnumberW, CIM_STRING },
387 { prop_tagW, CIM_STRING|COL_FLAG_KEY },
388 { prop_versionW, CIM_STRING }
390 static const struct column col_bios[] =
392 { prop_descriptionW, CIM_STRING },
393 { prop_identificationcodeW, CIM_STRING },
394 { prop_manufacturerW, CIM_STRING },
395 { prop_nameW, CIM_STRING },
396 { prop_releasedateW, CIM_DATETIME },
397 { prop_serialnumberW, CIM_STRING },
398 { prop_smbiosbiosversionW, CIM_STRING },
399 { prop_versionW, CIM_STRING|COL_FLAG_KEY }
401 static const struct column col_cdromdrive[] =
403 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
404 { prop_driveW, CIM_STRING|COL_FLAG_DYNAMIC },
405 { prop_mediatypeW, CIM_STRING },
406 { prop_nameW, CIM_STRING },
407 { prop_pnpdeviceidW, CIM_STRING }
409 static const struct column col_compsys[] =
411 { prop_descriptionW, CIM_STRING },
412 { prop_domainW, CIM_STRING },
413 { prop_domainroleW, CIM_UINT16, VT_I4 },
414 { prop_manufacturerW, CIM_STRING },
415 { prop_modelW, CIM_STRING },
416 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
417 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
418 { prop_numprocessorsW, CIM_UINT32, VT_I4 },
419 { prop_totalphysicalmemoryW, CIM_UINT64 },
420 { prop_usernameW, CIM_STRING|COL_FLAG_DYNAMIC }
422 static const struct column col_compsysproduct[] =
424 { prop_identifyingnumberW, CIM_STRING|COL_FLAG_KEY },
425 { prop_uuidW, CIM_STRING|COL_FLAG_DYNAMIC }
427 static const struct column col_datafile[] =
429 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
430 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
432 static const struct column col_desktopmonitor[] =
434 { prop_pixelsperxlogicalinchW, CIM_UINT32 }
436 static const struct column col_directory[] =
438 { prop_accessmaskW, CIM_UINT32 },
439 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
441 static const struct column col_diskdrive[] =
443 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
444 { prop_indexW, CIM_UINT32, VT_I4 },
445 { prop_interfacetypeW, CIM_STRING },
446 { prop_manufacturerW, CIM_STRING },
447 { prop_mediatypeW, CIM_STRING },
448 { prop_modelW, CIM_STRING },
449 { prop_pnpdeviceidW, CIM_STRING },
450 { prop_serialnumberW, CIM_STRING },
451 { prop_sizeW, CIM_UINT64 }
453 static const struct column col_diskpartition[] =
455 { prop_bootableW, CIM_BOOLEAN },
456 { prop_bootpartitionW, CIM_BOOLEAN },
457 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
458 { prop_diskindexW, CIM_UINT32, VT_I4 },
459 { prop_indexW, CIM_UINT32, VT_I4 },
460 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
461 { prop_sizeW, CIM_UINT64 },
462 { prop_startingoffsetW, CIM_UINT64 },
463 { prop_typeW, CIM_STRING|COL_FLAG_DYNAMIC }
465 static const struct column col_logicaldisk[] =
467 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
468 { prop_drivetypeW, CIM_UINT32, VT_I4 },
469 { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
470 { prop_freespaceW, CIM_UINT64 },
471 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
472 { prop_sizeW, CIM_UINT64 },
473 { prop_volumenameW, CIM_STRING|COL_FLAG_DYNAMIC },
474 { prop_volumeserialnumberW, CIM_STRING|COL_FLAG_DYNAMIC }
476 static const struct column col_networkadapter[] =
478 { prop_adaptertypeW, CIM_STRING },
479 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
480 { prop_indexW, CIM_UINT32, VT_I4 },
481 { prop_interfaceindexW, CIM_UINT32, VT_I4 },
482 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
483 { prop_manufacturerW, CIM_STRING },
484 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
485 { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
486 { prop_physicaladapterW, CIM_BOOLEAN },
487 { prop_pnpdeviceidW, CIM_STRING },
488 { prop_speedW, CIM_UINT64 }
490 static const struct column col_networkadapterconfig[] =
492 { prop_defaultipgatewayW, CIM_STRING|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
493 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
494 { prop_dhcpenabledW, CIM_BOOLEAN },
495 { prop_dnshostnameW, CIM_STRING|COL_FLAG_DYNAMIC },
496 { prop_dnsserversearchorderW, CIM_STRING|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
497 { prop_indexW, CIM_UINT32|COL_FLAG_KEY, VT_I4 },
498 { prop_ipconnectionmetricW, CIM_UINT32, VT_I4 },
499 { prop_ipenabledW, CIM_BOOLEAN },
500 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
501 { prop_settingidW, CIM_STRING|COL_FLAG_DYNAMIC }
503 static const struct column col_os[] =
505 { prop_buildnumberW, CIM_STRING|COL_FLAG_DYNAMIC },
506 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
507 { prop_codesetW, CIM_STRING|COL_FLAG_DYNAMIC },
508 { prop_countrycodeW, CIM_STRING|COL_FLAG_DYNAMIC },
509 { prop_csdversionW, CIM_STRING|COL_FLAG_DYNAMIC },
510 { prop_installdateW, CIM_DATETIME },
511 { prop_lastbootuptimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
512 { prop_localdatetimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
513 { prop_localeW, CIM_STRING|COL_FLAG_DYNAMIC },
514 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
515 { prop_osarchitectureW, CIM_STRING },
516 { prop_oslanguageW, CIM_UINT32, VT_I4 },
517 { prop_osproductsuiteW, CIM_UINT32, VT_I4 },
518 { prop_ostypeW, CIM_UINT16, VT_I4 },
519 { prop_primaryW, CIM_BOOLEAN },
520 { prop_serialnumberW, CIM_STRING },
521 { prop_servicepackmajorW, CIM_UINT16, VT_I4 },
522 { prop_servicepackminorW, CIM_UINT16, VT_I4 },
523 { prop_suitemaskW, CIM_UINT32, VT_I4 },
524 { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC },
525 { prop_totalvirtualmemorysizeW, CIM_UINT64 },
526 { prop_totalvisiblememorysizeW, CIM_UINT64 },
527 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
529 static const struct column col_param[] =
531 { prop_classW, CIM_STRING },
532 { prop_methodW, CIM_STRING },
533 { prop_directionW, CIM_SINT32 },
534 { prop_parameterW, CIM_STRING },
535 { prop_typeW, CIM_UINT32 },
536 { prop_varianttypeW, CIM_UINT32 },
537 { prop_defaultvalueW, CIM_UINT32 }
539 static const struct column col_physicalmedia[] =
541 { prop_serialnumberW, CIM_STRING },
542 { prop_tagW, CIM_STRING }
544 static const struct column col_physicalmemory[] =
546 { prop_capacityW, CIM_UINT64 },
547 { prop_memorytypeW, CIM_UINT16, VT_I4 }
549 static const struct column col_printer[] =
551 { prop_attributesW, CIM_UINT32 },
552 { prop_drivernameW, CIM_STRING|COL_FLAG_DYNAMIC },
553 { prop_horizontalresolutionW, CIM_UINT32 },
554 { prop_localW, CIM_BOOLEAN },
555 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
556 { prop_networkW, CIM_BOOLEAN }
558 static const struct column col_process[] =
560 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
561 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
562 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
563 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
564 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
565 { prop_pprocessidW, CIM_UINT32, VT_I4 },
566 { prop_processidW, CIM_UINT32, VT_I4 },
567 { prop_threadcountW, CIM_UINT32, VT_I4 },
568 { prop_workingsetsizeW, CIM_UINT64 },
569 /* methods */
570 { method_getownerW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
572 static const struct column col_processor[] =
574 { prop_addresswidthW, CIM_UINT16, VT_I4 },
575 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
576 { prop_cpustatusW, CIM_UINT16 },
577 { prop_currentclockspeedW, CIM_UINT32, VT_I4 },
578 { prop_datawidthW, CIM_UINT16, VT_I4 },
579 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
580 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
581 { prop_familyW, CIM_UINT16, VT_I4 },
582 { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
583 { prop_maxclockspeedW, CIM_UINT32, VT_I4 },
584 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
585 { prop_numcoresW, CIM_UINT32, VT_I4 },
586 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
587 { prop_processoridW, CIM_STRING|COL_FLAG_DYNAMIC },
588 { prop_processortypeW, CIM_UINT16, VT_I4 },
589 { prop_uniqueidW, CIM_STRING },
590 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
592 static const struct column col_qualifier[] =
594 { prop_classW, CIM_STRING },
595 { prop_memberW, CIM_STRING },
596 { prop_typeW, CIM_UINT32 },
597 { prop_flavorW, CIM_SINT32 },
598 { prop_nameW, CIM_STRING },
599 { prop_intvalueW, CIM_SINT32 },
600 { prop_strvalueW, CIM_STRING }
602 static const struct column col_service[] =
604 { prop_acceptpauseW, CIM_BOOLEAN },
605 { prop_acceptstopW, CIM_BOOLEAN },
606 { prop_displaynameW, CIM_STRING|COL_FLAG_DYNAMIC },
607 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
608 { prop_processidW, CIM_UINT32 },
609 { prop_servicetypeW, CIM_STRING },
610 { prop_startmodeW, CIM_STRING },
611 { prop_stateW, CIM_STRING },
612 { prop_systemnameW, CIM_STRING|COL_FLAG_DYNAMIC },
613 /* methods */
614 { method_pauseserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
615 { method_resumeserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
616 { method_startserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
617 { method_stopserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
619 static const struct column col_sid[] =
621 { prop_accountnameW, CIM_STRING|COL_FLAG_DYNAMIC },
622 { prop_binaryrepresentationW, CIM_UINT8|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
623 { prop_referenceddomainnameW, CIM_STRING|COL_FLAG_DYNAMIC },
624 { prop_sidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
625 { prop_sidlengthW, CIM_UINT32 }
627 static const struct column col_sounddevice[] =
629 { prop_nameW, CIM_STRING },
630 { prop_productnameW, CIM_STRING },
631 { prop_statusinfoW, CIM_UINT16, VT_I4 }
633 static const struct column col_stdregprov[] =
635 { method_enumkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
636 { method_enumvaluesW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
637 { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
639 static const struct column col_systemenclosure[] =
641 { prop_captionW, CIM_STRING },
642 { prop_chassistypesW, CIM_UINT16|CIM_FLAG_ARRAY, VT_I4|VT_ARRAY },
643 { prop_descriptionW, CIM_STRING },
644 { prop_lockpresentW, CIM_BOOLEAN },
645 { prop_manufacturerW, CIM_STRING },
646 { prop_nameW, CIM_STRING },
647 { prop_tagW, CIM_STRING },
649 static const struct column col_systemsecurity[] =
651 { method_getsdW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
652 { method_setsdW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
654 static const struct column col_videocontroller[] =
656 { prop_adapterdactypeW, CIM_STRING },
657 { prop_adapterramW, CIM_UINT32, VT_I4 },
658 { prop_availabilityW, CIM_UINT16 },
659 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
660 { prop_currentbitsperpixelW, CIM_UINT32, VT_I4 },
661 { prop_currenthorizontalresW, CIM_UINT32, VT_I4 },
662 { prop_currentrefreshrateW, CIM_UINT32, VT_I4 },
663 { prop_currentscanmodeW, CIM_UINT16, VT_I4 },
664 { prop_currentverticalresW, CIM_UINT32, VT_I4 },
665 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
666 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
667 { prop_driverversionW, CIM_STRING },
668 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
669 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
670 { prop_videoarchitectureW, CIM_UINT16, VT_I4 },
671 { prop_videomemorytypeW, CIM_UINT16, VT_I4 },
672 { prop_videomodedescriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
673 { prop_videoprocessorW, CIM_STRING|COL_FLAG_DYNAMIC }
676 static const WCHAR baseboard_manufacturerW[] =
677 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
678 static const WCHAR baseboard_serialnumberW[] =
679 {'N','o','n','e',0};
680 static const WCHAR baseboard_tagW[] =
681 {'B','a','s','e',' ','B','o','a','r','d',0};
682 static const WCHAR baseboard_versionW[] =
683 {'1','.','0',0};
684 static const WCHAR bios_descriptionW[] =
685 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
686 static const WCHAR bios_manufacturerW[] =
687 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
688 static const WCHAR bios_nameW[] =
689 {'W','I','N','E',' ','B','I','O','S',0};
690 static const WCHAR bios_releasedateW[] =
691 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
692 static const WCHAR bios_serialnumberW[] =
693 {'0',0};
694 static const WCHAR bios_smbiosbiosversionW[] =
695 {'W','i','n','e',0};
696 static const WCHAR bios_versionW[] =
697 {'W','I','N','E',' ',' ',' ','-',' ','1',0};
698 static const WCHAR cdromdrive_mediatypeW[] =
699 {'C','D','-','R','O','M',0};
700 static const WCHAR cdromdrive_nameW[] =
701 {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
702 static const WCHAR cdromdrive_pnpdeviceidW[]=
703 {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
704 '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
705 '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
706 'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
707 static const WCHAR compsys_descriptionW[] =
708 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
709 static const WCHAR compsys_domainW[] =
710 {'W','O','R','K','G','R','O','U','P',0};
711 static const WCHAR compsys_manufacturerW[] =
712 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
713 static const WCHAR compsys_modelW[] =
714 {'W','i','n','e',0};
715 static const WCHAR compsysproduct_identifyingnumberW[] =
716 {'0',0};
717 static const WCHAR compsysproduct_uuidW[] =
718 {'d','e','a','d','d','e','a','d','-','d','e','a','d','-','d','e','a','d','-','d','e','a','d','-',
719 'd','e','a','d','d','e','a','d','d','e','a','d',0};
720 static const WCHAR diskdrive_interfacetypeW[] =
721 {'I','D','E',0};
722 static const WCHAR diskdrive_manufacturerW[] =
723 {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
724 static const WCHAR diskdrive_mediatype_fixedW[] =
725 {'F','i','x','e','d',' ','h','a','r','d',' ','d','i','s','k',0};
726 static const WCHAR diskdrive_mediatype_removableW[] =
727 {'R','e','m','o','v','a','b','l','e',' ','m','e','d','i','a',0};
728 static const WCHAR diskdrive_modelW[] =
729 {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
730 static const WCHAR diskdrive_pnpdeviceidW[] =
731 {'I','D','E','\\','D','i','s','k','\\','V','E','N','_','W','I','N','E',0};
732 static const WCHAR diskdrive_serialW[] =
733 {'W','I','N','E','H','D','I','S','K',0};
734 static const WCHAR networkadapter_pnpdeviceidW[]=
735 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
736 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
737 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
738 static const WCHAR os_32bitW[] =
739 {'3','2','-','b','i','t',0};
740 static const WCHAR os_64bitW[] =
741 {'6','4','-','b','i','t',0};
742 static const WCHAR os_installdateW[] =
743 {'2','0','1','4','0','1','0','1','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
744 static const WCHAR os_serialnumberW[] =
745 {'1','2','3','4','5','-','O','E','M','-','1','2','3','4','5','6','7','-','1','2','3','4','5',0};
746 static const WCHAR physicalmedia_tagW[] =
747 {'\\','\\','.','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
748 static const WCHAR sounddevice_productnameW[] =
749 {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
750 static const WCHAR systemenclosure_systemenclosureW[] =
751 {'S','y','s','t','e','m',' ','E','n','c','l','o','s','u','r','e',0};
752 static const WCHAR systemenclosure_tagW[] =
753 {'S','y','s','t','e','m',' ','E','n','c','l','o','s','u','r','e',' ','0',0};
754 static const WCHAR systemenclosure_manufacturerW[] =
755 {'W','i','n','e',0};
756 static const WCHAR videocontroller_dactypeW[] =
757 {'I','n','t','e','g','r','a','t','e','d',' ','R','A','M','D','A','C',0};
758 static const WCHAR videocontroller_deviceidW[] =
759 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
760 static const WCHAR videocontroller_driverversionW[] =
761 {'1','.','0',0};
763 #include "pshpack1.h"
764 struct record_baseboard
766 const WCHAR *manufacturer;
767 const WCHAR *model;
768 const WCHAR *name;
769 const WCHAR *product;
770 const WCHAR *serialnumber;
771 const WCHAR *tag;
772 const WCHAR *version;
774 struct record_bios
776 const WCHAR *description;
777 const WCHAR *identificationcode;
778 const WCHAR *manufacturer;
779 const WCHAR *name;
780 const WCHAR *releasedate;
781 const WCHAR *serialnumber;
782 const WCHAR *smbiosbiosversion;
783 const WCHAR *version;
785 struct record_cdromdrive
787 const WCHAR *device_id;
788 const WCHAR *drive;
789 const WCHAR *mediatype;
790 const WCHAR *name;
791 const WCHAR *pnpdevice_id;
793 struct record_computersystem
795 const WCHAR *description;
796 const WCHAR *domain;
797 UINT16 domainrole;
798 const WCHAR *manufacturer;
799 const WCHAR *model;
800 const WCHAR *name;
801 UINT32 num_logical_processors;
802 UINT32 num_processors;
803 UINT64 total_physical_memory;
804 const WCHAR *username;
806 struct record_computersystemproduct
808 const WCHAR *identifyingnumber;
809 const WCHAR *uuid;
811 struct record_datafile
813 const WCHAR *name;
814 const WCHAR *version;
816 struct record_desktopmonitor
818 UINT32 pixelsperxlogicalinch;
820 struct record_directory
822 UINT32 accessmask;
823 const WCHAR *name;
825 struct record_diskdrive
827 const WCHAR *device_id;
828 UINT32 index;
829 const WCHAR *interfacetype;
830 const WCHAR *manufacturer;
831 const WCHAR *mediatype;
832 const WCHAR *model;
833 const WCHAR *pnpdevice_id;
834 const WCHAR *serialnumber;
835 UINT64 size;
837 struct record_diskpartition
839 int bootable;
840 int bootpartition;
841 const WCHAR *device_id;
842 UINT32 diskindex;
843 UINT32 index;
844 const WCHAR *pnpdevice_id;
845 UINT64 size;
846 UINT64 startingoffset;
847 const WCHAR *type;
849 struct record_logicaldisk
851 const WCHAR *device_id;
852 UINT32 drivetype;
853 const WCHAR *filesystem;
854 UINT64 freespace;
855 const WCHAR *name;
856 UINT64 size;
857 const WCHAR *volumename;
858 const WCHAR *volumeserialnumber;
860 struct record_networkadapter
862 const WCHAR *adaptertype;
863 const WCHAR *device_id;
864 UINT32 index;
865 UINT32 interface_index;
866 const WCHAR *mac_address;
867 const WCHAR *manufacturer;
868 const WCHAR *name;
869 UINT16 netconnection_status;
870 int physicaladapter;
871 const WCHAR *pnpdevice_id;
872 UINT64 speed;
874 struct record_networkadapterconfig
876 const struct array *defaultipgateway;
877 const WCHAR *description;
878 int dhcpenabled;
879 const WCHAR *dnshostname;
880 const struct array *dnsserversearchorder;
881 UINT32 index;
882 UINT32 ipconnectionmetric;
883 int ipenabled;
884 const WCHAR *mac_address;
885 const WCHAR *settingid;
887 struct record_operatingsystem
889 const WCHAR *buildnumber;
890 const WCHAR *caption;
891 const WCHAR *codeset;
892 const WCHAR *countrycode;
893 const WCHAR *csdversion;
894 const WCHAR *installdate;
895 const WCHAR *lastbootuptime;
896 const WCHAR *localdatetime;
897 const WCHAR *locale;
898 const WCHAR *name;
899 const WCHAR *osarchitecture;
900 UINT32 oslanguage;
901 UINT32 osproductsuite;
902 UINT16 ostype;
903 int primary;
904 const WCHAR *serialnumber;
905 UINT16 servicepackmajor;
906 UINT16 servicepackminor;
907 UINT32 suitemask;
908 const WCHAR *systemdirectory;
909 UINT64 totalvirtualmemorysize;
910 UINT64 totalvisiblememorysize;
911 const WCHAR *version;
913 struct record_param
915 const WCHAR *class;
916 const WCHAR *method;
917 INT32 direction;
918 const WCHAR *parameter;
919 UINT32 type;
920 UINT32 varianttype;
921 UINT32 defaultvalue;
923 struct record_physicalmedia
925 const WCHAR *serialnumber;
926 const WCHAR *tag;
928 struct record_physicalmemory
930 UINT64 capacity;
931 UINT16 memorytype;
933 struct record_printer
935 UINT32 attributes;
936 const WCHAR *drivername;
937 UINT32 horizontalresolution;
938 int local;
939 const WCHAR *name;
940 int network;
942 struct record_process
944 const WCHAR *caption;
945 const WCHAR *commandline;
946 const WCHAR *description;
947 const WCHAR *handle;
948 const WCHAR *name;
949 UINT32 pprocess_id;
950 UINT32 process_id;
951 UINT32 thread_count;
952 UINT64 workingsetsize;
953 /* methods */
954 class_method *get_owner;
956 struct record_processor
958 UINT16 addresswidth;
959 const WCHAR *caption;
960 UINT16 cpu_status;
961 UINT32 currentclockspeed;
962 UINT16 datawidth;
963 const WCHAR *description;
964 const WCHAR *device_id;
965 UINT16 family;
966 const WCHAR *manufacturer;
967 UINT32 maxclockspeed;
968 const WCHAR *name;
969 UINT32 num_cores;
970 UINT32 num_logical_processors;
971 const WCHAR *processor_id;
972 UINT16 processortype;
973 const WCHAR *unique_id;
974 const WCHAR *version;
976 struct record_qualifier
978 const WCHAR *class;
979 const WCHAR *member;
980 UINT32 type;
981 INT32 flavor;
982 const WCHAR *name;
983 INT32 intvalue;
984 const WCHAR *strvalue;
986 struct record_service
988 int accept_pause;
989 int accept_stop;
990 const WCHAR *displayname;
991 const WCHAR *name;
992 UINT32 process_id;
993 const WCHAR *servicetype;
994 const WCHAR *startmode;
995 const WCHAR *state;
996 const WCHAR *systemname;
997 /* methods */
998 class_method *pause_service;
999 class_method *resume_service;
1000 class_method *start_service;
1001 class_method *stop_service;
1003 struct record_sid
1005 const WCHAR *accountname;
1006 const struct array *binaryrepresentation;
1007 const WCHAR *referenceddomainname;
1008 const WCHAR *sid;
1009 UINT32 sidlength;
1011 struct record_sounddevice
1013 const WCHAR *name;
1014 const WCHAR *productname;
1015 UINT16 statusinfo;
1017 struct record_stdregprov
1019 class_method *enumkey;
1020 class_method *enumvalues;
1021 class_method *getstringvalue;
1023 struct record_systemsecurity
1025 class_method *getsd;
1026 class_method *setsd;
1028 struct record_systemenclosure
1030 const WCHAR *caption;
1031 const struct array *chassistypes;
1032 const WCHAR *description;
1033 int lockpresent;
1034 const WCHAR *manufacturer;
1035 const WCHAR *name;
1036 const WCHAR *tag;
1038 struct record_videocontroller
1040 const WCHAR *adapter_dactype;
1041 UINT32 adapter_ram;
1042 UINT16 availability;
1043 const WCHAR *caption;
1044 UINT32 current_bitsperpixel;
1045 UINT32 current_horizontalres;
1046 UINT32 current_refreshrate;
1047 UINT16 current_scanmode;
1048 UINT32 current_verticalres;
1049 const WCHAR *description;
1050 const WCHAR *device_id;
1051 const WCHAR *driverversion;
1052 const WCHAR *name;
1053 const WCHAR *pnpdevice_id;
1054 UINT16 videoarchitecture;
1055 UINT16 videomemorytype;
1056 const WCHAR *videomodedescription;
1057 const WCHAR *videoprocessor;
1059 #include "poppack.h"
1061 static const struct record_baseboard data_baseboard[] =
1063 { baseboard_manufacturerW, baseboard_tagW, baseboard_tagW, baseboard_tagW, baseboard_serialnumberW, baseboard_versionW }
1065 static const struct record_bios data_bios[] =
1067 { bios_descriptionW, NULL, bios_manufacturerW, bios_nameW, bios_releasedateW, bios_serialnumberW,
1068 bios_smbiosbiosversionW, bios_versionW }
1070 static const struct record_param data_param[] =
1072 { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1073 { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
1074 { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
1075 { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1076 { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1077 { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1078 { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1079 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
1080 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
1081 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1082 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
1083 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
1084 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
1085 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1086 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
1087 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
1088 { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
1089 { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
1090 { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
1091 { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1092 { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING },
1093 { class_systemsecurityW, method_getsdW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1094 { class_systemsecurityW, method_getsdW, -1, param_sdW, CIM_UINT8|CIM_FLAG_ARRAY },
1095 { class_systemsecurityW, method_setsdW, 1, param_sdW, CIM_UINT8|CIM_FLAG_ARRAY },
1096 { class_systemsecurityW, method_setsdW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1099 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
1100 WBEM_FLAVOR_ORIGIN_PROPAGATED)
1102 static const struct record_physicalmedia data_physicalmedia[] =
1104 { diskdrive_serialW, physicalmedia_tagW }
1106 static const struct record_qualifier data_qualifier[] =
1108 { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
1109 { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
1111 static const struct record_sounddevice data_sounddevice[] =
1113 { sounddevice_productnameW, sounddevice_productnameW, 3 /* enabled */ }
1115 static const struct record_stdregprov data_stdregprov[] =
1117 { reg_enum_key, reg_enum_values, reg_get_stringvalue }
1119 static UINT16 systemenclosure_chassistypes[] =
1123 static const struct array systemenclosure_chassistypes_array =
1125 SIZEOF(systemenclosure_chassistypes),
1126 &systemenclosure_chassistypes
1128 static const struct record_systemenclosure data_systemenclosure[] =
1131 systemenclosure_systemenclosureW,
1132 &systemenclosure_chassistypes_array,
1133 systemenclosure_systemenclosureW,
1134 FALSE,
1135 systemenclosure_manufacturerW,
1136 systemenclosure_systemenclosureW,
1137 systemenclosure_tagW,
1140 static const struct record_systemsecurity data_systemsecurity[] =
1142 { security_get_sd, security_set_sd }
1145 /* check if row matches condition and update status */
1146 static BOOL match_row( const struct table *table, UINT row, const struct expr *cond, enum fill_status *status )
1148 LONGLONG val;
1149 UINT type;
1151 if (!cond)
1153 *status = FILL_STATUS_UNFILTERED;
1154 return TRUE;
1156 if (eval_cond( table, row, cond, &val, &type ) != S_OK)
1158 *status = FILL_STATUS_FAILED;
1159 return FALSE;
1161 *status = FILL_STATUS_FILTERED;
1162 return val != 0;
1165 static BOOL resize_table( struct table *table, UINT row_count, UINT row_size )
1167 if (!table->num_rows_allocated)
1169 if (!(table->data = heap_alloc( row_count * row_size ))) return FALSE;
1170 table->num_rows_allocated = row_count;
1171 return TRUE;
1173 if (row_count > table->num_rows_allocated)
1175 BYTE *data;
1176 UINT count = max( row_count, table->num_rows_allocated * 2 );
1177 if (!(data = heap_realloc( table->data, count * row_size ))) return FALSE;
1178 table->data = data;
1179 table->num_rows_allocated = count;
1181 return TRUE;
1184 static enum fill_status fill_cdromdrive( struct table *table, const struct expr *cond )
1186 static const WCHAR fmtW[] = {'%','c',':',0};
1187 WCHAR drive[3], root[] = {'A',':','\\',0};
1188 struct record_cdromdrive *rec;
1189 UINT i, row = 0, offset = 0;
1190 DWORD drives = GetLogicalDrives();
1191 enum fill_status status = FILL_STATUS_UNFILTERED;
1193 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1195 for (i = 0; i < 26; i++)
1197 if (drives & (1 << i))
1199 root[0] = 'A' + i;
1200 if (GetDriveTypeW( root ) != DRIVE_CDROM)
1201 continue;
1203 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1205 rec = (struct record_cdromdrive *)(table->data + offset);
1206 rec->device_id = cdromdrive_pnpdeviceidW;
1207 sprintfW( drive, fmtW, 'A' + i );
1208 rec->drive = heap_strdupW( drive );
1209 rec->mediatype = cdromdrive_mediatypeW;
1210 rec->name = cdromdrive_nameW;
1211 rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
1212 if (!match_row( table, row, cond, &status ))
1214 free_row_values( table, row );
1215 continue;
1217 offset += sizeof(*rec);
1218 row++;
1221 TRACE("created %u rows\n", row);
1222 table->num_rows = row;
1223 return status;
1226 static UINT get_processor_count(void)
1228 SYSTEM_BASIC_INFORMATION info;
1230 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
1231 return info.NumberOfProcessors;
1234 static UINT get_logical_processor_count( UINT *num_cores )
1236 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
1237 UINT i, j, count = 0;
1238 NTSTATUS status;
1239 ULONG len;
1241 if (num_cores) *num_cores = get_processor_count();
1242 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
1243 if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
1245 if (!(info = heap_alloc( len ))) return get_processor_count();
1246 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
1247 if (status != STATUS_SUCCESS)
1249 heap_free( info );
1250 return get_processor_count();
1252 if (num_cores) *num_cores = 0;
1253 for (i = 0; i < len / sizeof(*info); i++)
1255 if (info[i].Relationship == RelationProcessorCore)
1257 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
1259 else if (info[i].Relationship == RelationProcessorPackage && num_cores)
1261 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) (*num_cores)++;
1264 heap_free( info );
1265 return count;
1268 static UINT64 get_total_physical_memory(void)
1270 MEMORYSTATUSEX status;
1272 status.dwLength = sizeof(status);
1273 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
1274 return status.ullTotalPhys;
1277 static WCHAR *get_computername(void)
1279 WCHAR *ret;
1280 DWORD size = MAX_COMPUTERNAME_LENGTH + 1;
1282 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
1283 GetComputerNameW( ret, &size );
1284 return ret;
1287 static WCHAR *get_username(void)
1289 WCHAR *ret;
1290 DWORD compsize, usersize;
1291 DWORD size;
1293 compsize = 0;
1294 GetComputerNameW( NULL, &compsize );
1295 usersize = 0;
1296 GetUserNameW( NULL, &usersize );
1297 size = compsize + usersize; /* two null terminators account for the \ */
1298 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
1299 GetComputerNameW( ret, &compsize );
1300 ret[compsize] = '\\';
1301 GetUserNameW( ret + compsize + 1, &usersize );
1302 return ret;
1305 static enum fill_status fill_compsys( struct table *table, const struct expr *cond )
1307 struct record_computersystem *rec;
1308 enum fill_status status = FILL_STATUS_UNFILTERED;
1309 UINT row = 0;
1311 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1313 rec = (struct record_computersystem *)table->data;
1314 rec->description = compsys_descriptionW;
1315 rec->domain = compsys_domainW;
1316 rec->domainrole = 0; /* standalone workstation */
1317 rec->manufacturer = compsys_manufacturerW;
1318 rec->model = compsys_modelW;
1319 rec->name = get_computername();
1320 rec->num_logical_processors = get_logical_processor_count( NULL );
1321 rec->num_processors = get_processor_count();
1322 rec->total_physical_memory = get_total_physical_memory();
1323 rec->username = get_username();
1324 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1325 else row++;
1327 TRACE("created %u rows\n", row);
1328 table->num_rows = row;
1329 return status;
1332 static WCHAR *get_compsysproduct_uuid(void)
1334 #ifdef __APPLE__
1335 unsigned char uuid[16];
1336 const struct timespec timeout = {1, 0};
1337 if (!gethostuuid( uuid, &timeout ))
1339 static const WCHAR fmtW[] =
1340 {'%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','-',
1341 '%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X',
1342 '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',0};
1343 WCHAR *ret = heap_alloc( 37 * sizeof(WCHAR) );
1344 if (!ret) return NULL;
1345 sprintfW( ret, fmtW, uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7],
1346 uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15] );
1347 return ret;
1349 #endif
1350 #ifdef __linux__
1351 int file;
1352 if ((file = open( "/var/lib/dbus/machine-id", O_RDONLY )) != -1)
1354 unsigned char buf[32];
1355 if (read( file, buf, sizeof(buf) ) == sizeof(buf))
1357 unsigned int i, j;
1358 WCHAR *ret, *p;
1360 close( file );
1361 if (!(p = ret = heap_alloc( 37 * sizeof(WCHAR) ))) return NULL;
1362 for (i = 0, j = 0; i < 8; i++) p[i] = toupperW( buf[j++] );
1363 p[8] = '-';
1364 for (i = 9; i < 13; i++) p[i] = toupperW( buf[j++] );
1365 p[13] = '-';
1366 for (i = 14; i < 18; i++) p[i] = toupperW( buf[j++] );
1367 p[18] = '-';
1368 for (i = 19; i < 23; i++) p[i] = toupperW( buf[j++] );
1369 p[23] = '-';
1370 for (i = 24; i < 36; i++) p[i] = toupperW( buf[j++] );
1371 ret[i] = 0;
1372 return ret;
1374 close( file );
1376 #endif
1377 return heap_strdupW( compsysproduct_uuidW );
1380 static enum fill_status fill_compsysproduct( struct table *table, const struct expr *cond )
1382 struct record_computersystemproduct *rec;
1383 enum fill_status status = FILL_STATUS_UNFILTERED;
1384 UINT row = 0;
1386 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1388 rec = (struct record_computersystemproduct *)table->data;
1389 rec->identifyingnumber = compsysproduct_identifyingnumberW;
1390 rec->uuid = get_compsysproduct_uuid();
1391 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1392 else row++;
1394 TRACE("created %u rows\n", row);
1395 table->num_rows = row;
1396 return status;
1399 struct dirstack
1401 WCHAR **dirs;
1402 UINT *len_dirs;
1403 UINT num_dirs;
1404 UINT num_allocated;
1407 static struct dirstack *alloc_dirstack( UINT size )
1409 struct dirstack *dirstack;
1411 if (!(dirstack = heap_alloc( sizeof(*dirstack) ))) return NULL;
1412 if (!(dirstack->dirs = heap_alloc( sizeof(WCHAR *) * size )))
1414 heap_free( dirstack );
1415 return NULL;
1417 if (!(dirstack->len_dirs = heap_alloc( sizeof(UINT) * size )))
1419 heap_free( dirstack->dirs );
1420 heap_free( dirstack );
1421 return NULL;
1423 dirstack->num_dirs = 0;
1424 dirstack->num_allocated = size;
1425 return dirstack;
1428 static void clear_dirstack( struct dirstack *dirstack )
1430 UINT i;
1431 for (i = 0; i < dirstack->num_dirs; i++) heap_free( dirstack->dirs[i] );
1432 dirstack->num_dirs = 0;
1435 static void free_dirstack( struct dirstack *dirstack )
1437 clear_dirstack( dirstack );
1438 heap_free( dirstack->dirs );
1439 heap_free( dirstack->len_dirs );
1440 heap_free( dirstack );
1443 static BOOL push_dir( struct dirstack *dirstack, WCHAR *dir, UINT len )
1445 UINT size, i = dirstack->num_dirs;
1447 if (!dir) return FALSE;
1449 if (i == dirstack->num_allocated)
1451 WCHAR **tmp;
1452 UINT *len_tmp;
1454 size = dirstack->num_allocated * 2;
1455 if (!(tmp = heap_realloc( dirstack->dirs, size * sizeof(WCHAR *) ))) return FALSE;
1456 dirstack->dirs = tmp;
1457 if (!(len_tmp = heap_realloc( dirstack->len_dirs, size * sizeof(UINT) ))) return FALSE;
1458 dirstack->len_dirs = len_tmp;
1459 dirstack->num_allocated = size;
1461 dirstack->dirs[i] = dir;
1462 dirstack->len_dirs[i] = len;
1463 dirstack->num_dirs++;
1464 return TRUE;
1467 static WCHAR *pop_dir( struct dirstack *dirstack, UINT *len )
1469 if (!dirstack->num_dirs)
1471 *len = 0;
1472 return NULL;
1474 dirstack->num_dirs--;
1475 *len = dirstack->len_dirs[dirstack->num_dirs];
1476 return dirstack->dirs[dirstack->num_dirs];
1479 static const WCHAR *peek_dir( struct dirstack *dirstack )
1481 if (!dirstack->num_dirs) return NULL;
1482 return dirstack->dirs[dirstack->num_dirs - 1];
1485 static WCHAR *build_glob( WCHAR drive, const WCHAR *path, UINT len )
1487 UINT i = 0;
1488 WCHAR *ret;
1490 if (!(ret = heap_alloc( (len + 6) * sizeof(WCHAR) ))) return NULL;
1491 ret[i++] = drive;
1492 ret[i++] = ':';
1493 ret[i++] = '\\';
1494 if (path && len)
1496 memcpy( ret + i, path, len * sizeof(WCHAR) );
1497 i += len;
1498 ret[i++] = '\\';
1500 ret[i++] = '*';
1501 ret[i] = 0;
1502 return ret;
1505 static WCHAR *build_name( WCHAR drive, const WCHAR *path )
1507 UINT i = 0, len = 0;
1508 const WCHAR *p;
1509 WCHAR *ret;
1511 for (p = path; *p; p++)
1513 if (*p == '\\') len += 2;
1514 else len++;
1516 if (!(ret = heap_alloc( (len + 5) * sizeof(WCHAR) ))) return NULL;
1517 ret[i++] = drive;
1518 ret[i++] = ':';
1519 ret[i++] = '\\';
1520 ret[i++] = '\\';
1521 for (p = path; *p; p++)
1523 if (*p != '\\') ret[i++] = *p;
1524 else
1526 ret[i++] = '\\';
1527 ret[i++] = '\\';
1530 ret[i] = 0;
1531 return ret;
1534 static WCHAR *build_dirname( const WCHAR *path, UINT *ret_len )
1536 const WCHAR *p = path, *start;
1537 UINT len, i;
1538 WCHAR *ret;
1540 if (!isalphaW( p[0] ) || p[1] != ':' || p[2] != '\\' || p[3] != '\\' || !p[4]) return NULL;
1541 start = path + 4;
1542 len = strlenW( start );
1543 p = start + len - 1;
1544 if (*p == '\\') return NULL;
1546 while (p >= start && *p != '\\') { len--; p--; };
1547 while (p >= start && *p == '\\') { len--; p--; };
1549 if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
1550 for (i = 0, p = start; p < start + len; p++)
1552 if (p[0] == '\\' && p[1] == '\\')
1554 ret[i++] = '\\';
1555 p++;
1557 else ret[i++] = *p;
1559 ret[i] = 0;
1560 *ret_len = i;
1561 return ret;
1564 static BOOL seen_dir( struct dirstack *dirstack, const WCHAR *path )
1566 UINT i;
1567 for (i = 0; i < dirstack->num_dirs; i++) if (!strcmpW( dirstack->dirs[i], path )) return TRUE;
1568 return FALSE;
1571 /* optimize queries of the form WHERE Name='...' [OR Name='...']* */
1572 static UINT seed_dirs( struct dirstack *dirstack, const struct expr *cond, WCHAR root, UINT *count )
1574 const struct expr *left, *right;
1576 if (!cond || cond->type != EXPR_COMPLEX) return *count = 0;
1578 left = cond->u.expr.left;
1579 right = cond->u.expr.right;
1580 if (cond->u.expr.op == OP_EQ)
1582 UINT len;
1583 WCHAR *path;
1584 const WCHAR *str = NULL;
1586 if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL &&
1587 !strcmpW( left->u.propval->name, prop_nameW ) &&
1588 toupperW( right->u.sval[0] ) == toupperW( root ))
1590 str = right->u.sval;
1592 else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL &&
1593 !strcmpW( right->u.propval->name, prop_nameW ) &&
1594 toupperW( left->u.sval[0] ) == toupperW( root ))
1596 str = left->u.sval;
1598 if (str && (path = build_dirname( str, &len )))
1600 if (seen_dir( dirstack, path ))
1602 heap_free( path );
1603 return ++*count;
1605 else if (push_dir( dirstack, path, len )) return ++*count;
1606 heap_free( path );
1607 return *count = 0;
1610 else if (cond->u.expr.op == OP_OR)
1612 UINT left_count = 0, right_count = 0;
1614 if (!(seed_dirs( dirstack, left, root, &left_count ))) return *count = 0;
1615 if (!(seed_dirs( dirstack, right, root, &right_count ))) return *count = 0;
1616 return *count += left_count + right_count;
1618 return *count = 0;
1621 static WCHAR *append_path( const WCHAR *path, const WCHAR *segment, UINT *len )
1623 UINT len_path = 0, len_segment = strlenW( segment );
1624 WCHAR *ret;
1626 *len = 0;
1627 if (path) len_path = strlenW( path );
1628 if (!(ret = heap_alloc( (len_path + len_segment + 2) * sizeof(WCHAR) ))) return NULL;
1629 if (path && len_path)
1631 memcpy( ret, path, len_path * sizeof(WCHAR) );
1632 ret[len_path] = '\\';
1633 *len += len_path + 1;
1635 memcpy( ret + *len, segment, len_segment * sizeof(WCHAR) );
1636 *len += len_segment;
1637 ret[*len] = 0;
1638 return ret;
1641 static WCHAR *get_file_version( const WCHAR *filename )
1643 static const WCHAR slashW[] = {'\\',0}, fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
1644 VS_FIXEDFILEINFO *info;
1645 DWORD size;
1646 void *block;
1647 WCHAR *ret;
1649 if (!(ret = heap_alloc( (4 * 5 + sizeof(fmtW) / sizeof(fmtW[0])) * sizeof(WCHAR) ))) return NULL;
1650 if (!(size = GetFileVersionInfoSizeW( filename, NULL )) || !(block = heap_alloc( size )))
1652 heap_free( ret );
1653 return NULL;
1655 if (!GetFileVersionInfoW( filename, 0, size, block ) ||
1656 !VerQueryValueW( block, slashW, (void **)&info, &size ))
1658 heap_free( block );
1659 heap_free( ret );
1660 return NULL;
1662 sprintfW( ret, fmtW, info->dwFileVersionMS >> 16, info->dwFileVersionMS & 0xffff,
1663 info->dwFileVersionLS >> 16, info->dwFileVersionLS & 0xffff );
1664 heap_free( block );
1665 return ret;
1668 static enum fill_status fill_datafile( struct table *table, const struct expr *cond )
1670 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1671 struct record_datafile *rec;
1672 UINT i, len, row = 0, offset = 0, num_expected_rows;
1673 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1674 DWORD drives = GetLogicalDrives();
1675 WIN32_FIND_DATAW data;
1676 HANDLE handle;
1677 struct dirstack *dirstack;
1678 enum fill_status status = FILL_STATUS_UNFILTERED;
1680 if (!resize_table( table, 8, sizeof(*rec) )) return FILL_STATUS_FAILED;
1682 dirstack = alloc_dirstack(2);
1684 for (i = 0; i < 26; i++)
1686 if (!(drives & (1 << i))) continue;
1688 root[0] = 'A' + i;
1689 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1691 num_expected_rows = 0;
1692 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1694 for (;;)
1696 heap_free( glob );
1697 heap_free( path );
1698 path = pop_dir( dirstack, &len );
1699 if (!(glob = build_glob( root[0], path, len )))
1701 status = FILL_STATUS_FAILED;
1702 goto done;
1704 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1708 if (!resize_table( table, row + 1, sizeof(*rec) ))
1710 status = FILL_STATUS_FAILED;
1711 FindClose( handle );
1712 goto done;
1714 if (!strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW )) continue;
1715 new_path = append_path( path, data.cFileName, &len );
1717 if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1719 if (push_dir( dirstack, new_path, len )) continue;
1720 heap_free( new_path );
1721 FindClose( handle );
1722 status = FILL_STATUS_FAILED;
1723 goto done;
1725 rec = (struct record_datafile *)(table->data + offset);
1726 rec->name = build_name( root[0], new_path );
1727 rec->version = get_file_version( rec->name );
1728 if (!match_row( table, row, cond, &status ))
1730 free_row_values( table, row );
1731 continue;
1733 else if (num_expected_rows && row == num_expected_rows - 1)
1735 row++;
1736 FindClose( handle );
1737 status = FILL_STATUS_FILTERED;
1738 goto done;
1740 offset += sizeof(*rec);
1741 row++;
1743 while (FindNextFileW( handle, &data ));
1744 FindClose( handle );
1746 if (!peek_dir( dirstack )) break;
1750 done:
1751 free_dirstack( dirstack );
1752 heap_free( glob );
1753 heap_free( path );
1755 TRACE("created %u rows\n", row);
1756 table->num_rows = row;
1757 return status;
1760 static UINT32 get_pixelsperxlogicalinch(void)
1762 HDC hdc = GetDC( NULL );
1763 UINT32 ret;
1765 if (!hdc) return 96;
1766 ret = GetDeviceCaps( hdc, LOGPIXELSX );
1767 ReleaseDC( NULL, hdc );
1768 return ret;
1771 static enum fill_status fill_desktopmonitor( struct table *table, const struct expr *cond )
1773 struct record_desktopmonitor *rec;
1774 enum fill_status status = FILL_STATUS_UNFILTERED;
1775 UINT row = 0;
1777 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1779 rec = (struct record_desktopmonitor *)table->data;
1780 rec->pixelsperxlogicalinch = get_pixelsperxlogicalinch();
1782 if (match_row( table, row, cond, &status )) row++;
1784 TRACE("created %u rows\n", row);
1785 table->num_rows = row;
1786 return status;
1789 static enum fill_status fill_directory( struct table *table, const struct expr *cond )
1791 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1792 struct record_directory *rec;
1793 UINT i, len, row = 0, offset = 0, num_expected_rows;
1794 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1795 DWORD drives = GetLogicalDrives();
1796 WIN32_FIND_DATAW data;
1797 HANDLE handle;
1798 struct dirstack *dirstack;
1799 enum fill_status status = FILL_STATUS_UNFILTERED;
1801 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1803 dirstack = alloc_dirstack(2);
1805 for (i = 0; i < 26; i++)
1807 if (!(drives & (1 << i))) continue;
1809 root[0] = 'A' + i;
1810 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1812 num_expected_rows = 0;
1813 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1815 for (;;)
1817 heap_free( glob );
1818 heap_free( path );
1819 path = pop_dir( dirstack, &len );
1820 if (!(glob = build_glob( root[0], path, len )))
1822 status = FILL_STATUS_FAILED;
1823 goto done;
1825 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1829 if (!resize_table( table, row + 1, sizeof(*rec) ))
1831 FindClose( handle );
1832 status = FILL_STATUS_FAILED;
1833 goto done;
1835 if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1836 !strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW ))
1837 continue;
1839 new_path = append_path( path, data.cFileName, &len );
1840 if (!(push_dir( dirstack, new_path, len )))
1842 heap_free( new_path );
1843 FindClose( handle );
1844 status = FILL_STATUS_FAILED;
1845 goto done;
1847 rec = (struct record_directory *)(table->data + offset);
1848 rec->accessmask = FILE_ALL_ACCESS;
1849 rec->name = build_name( root[0], new_path );
1850 if (!match_row( table, row, cond, &status ))
1852 free_row_values( table, row );
1853 continue;
1855 else if (num_expected_rows && row == num_expected_rows - 1)
1857 row++;
1858 FindClose( handle );
1859 status = FILL_STATUS_FILTERED;
1860 goto done;
1862 offset += sizeof(*rec);
1863 row++;
1865 while (FindNextFileW( handle, &data ));
1866 FindClose( handle );
1868 if (!peek_dir( dirstack )) break;
1872 done:
1873 free_dirstack( dirstack );
1874 heap_free( glob );
1875 heap_free( path );
1877 TRACE("created %u rows\n", row);
1878 table->num_rows = row;
1879 return status;
1882 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
1884 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
1885 ULARGE_INTEGER free;
1886 DISK_GEOMETRY_EX info;
1887 HANDLE handle;
1888 DWORD bytes_returned;
1890 free.QuadPart = 512 * 1024 * 1024;
1891 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
1893 root[4] = dir[0];
1894 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
1895 if (handle != INVALID_HANDLE_VALUE)
1897 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), &bytes_returned, NULL ))
1898 *disksize = info.DiskSize.QuadPart;
1899 CloseHandle( handle );
1901 return free.QuadPart;
1904 static enum fill_status fill_diskdrive( struct table *table, const struct expr *cond )
1906 static const WCHAR fmtW[] =
1907 {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','%','u',0};
1908 WCHAR device_id[sizeof(fmtW)/sizeof(fmtW[0]) + 10], root[] = {'A',':','\\',0};
1909 struct record_diskdrive *rec;
1910 UINT i, row = 0, offset = 0, index = 0, type;
1911 UINT64 size = 1024 * 1024 * 1024;
1912 DWORD drives = GetLogicalDrives();
1913 enum fill_status status = FILL_STATUS_UNFILTERED;
1915 if (!resize_table( table, 2, sizeof(*rec) )) return FILL_STATUS_FAILED;
1917 for (i = 0; i < 26; i++)
1919 if (drives & (1 << i))
1921 root[0] = 'A' + i;
1922 type = GetDriveTypeW( root );
1923 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1924 continue;
1926 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1928 rec = (struct record_diskdrive *)(table->data + offset);
1929 sprintfW( device_id, fmtW, index );
1930 rec->device_id = heap_strdupW( device_id );
1931 rec->index = index;
1932 rec->interfacetype = diskdrive_interfacetypeW;
1933 rec->manufacturer = diskdrive_manufacturerW;
1934 if (type == DRIVE_FIXED)
1935 rec->mediatype = diskdrive_mediatype_fixedW;
1936 else
1937 rec->mediatype = diskdrive_mediatype_removableW;
1938 rec->model = diskdrive_modelW;
1939 rec->pnpdevice_id = diskdrive_pnpdeviceidW;
1940 rec->serialnumber = diskdrive_serialW;
1941 get_freespace( root, &size );
1942 rec->size = size;
1943 if (!match_row( table, row, cond, &status ))
1945 free_row_values( table, row );
1946 continue;
1948 offset += sizeof(*rec);
1949 index++;
1950 row++;
1953 TRACE("created %u rows\n", row);
1954 table->num_rows = row;
1955 return status;
1958 static WCHAR *get_filesystem( const WCHAR *root )
1960 static const WCHAR ntfsW[] = {'N','T','F','S',0};
1961 WCHAR buffer[MAX_PATH + 1];
1963 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
1964 return heap_strdupW( buffer );
1965 return heap_strdupW( ntfsW );
1968 static enum fill_status fill_diskpartition( struct table *table, const struct expr *cond )
1970 static const WCHAR fmtW[] =
1971 {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
1972 WCHAR device_id[32], root[] = {'A',':','\\',0};
1973 struct record_diskpartition *rec;
1974 UINT i, row = 0, offset = 0, type, index = 0;
1975 UINT64 size = 1024 * 1024 * 1024;
1976 DWORD drives = GetLogicalDrives();
1977 enum fill_status status = FILL_STATUS_UNFILTERED;
1979 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1981 for (i = 0; i < 26; i++)
1983 if (drives & (1 << i))
1985 root[0] = 'A' + i;
1986 type = GetDriveTypeW( root );
1987 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1988 continue;
1990 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1992 rec = (struct record_diskpartition *)(table->data + offset);
1993 rec->bootable = (i == 2) ? -1 : 0;
1994 rec->bootpartition = (i == 2) ? -1 : 0;
1995 sprintfW( device_id, fmtW, index );
1996 rec->device_id = heap_strdupW( device_id );
1997 rec->diskindex = index;
1998 rec->index = 0;
1999 rec->pnpdevice_id = heap_strdupW( device_id );
2000 get_freespace( root, &size );
2001 rec->size = size;
2002 rec->startingoffset = 0;
2003 rec->type = get_filesystem( root );
2004 if (!match_row( table, row, cond, &status ))
2006 free_row_values( table, row );
2007 continue;
2009 offset += sizeof(*rec);
2010 row++;
2011 index++;
2014 TRACE("created %u rows\n", row);
2015 table->num_rows = row;
2016 return status;
2019 static WCHAR *get_volumename( const WCHAR *root )
2021 WCHAR buf[MAX_PATH + 1] = {0};
2022 GetVolumeInformationW( root, buf, sizeof(buf)/sizeof(buf[0]), NULL, NULL, NULL, NULL, 0 );
2023 return heap_strdupW( buf );
2025 static WCHAR *get_volumeserialnumber( const WCHAR *root )
2027 static const WCHAR fmtW[] = {'%','0','8','X',0};
2028 DWORD serial = 0;
2029 WCHAR buffer[9];
2031 GetVolumeInformationW( root, NULL, 0, &serial, NULL, NULL, NULL, 0 );
2032 sprintfW( buffer, fmtW, serial );
2033 return heap_strdupW( buffer );
2036 static enum fill_status fill_logicaldisk( struct table *table, const struct expr *cond )
2038 static const WCHAR fmtW[] = {'%','c',':',0};
2039 WCHAR device_id[3], root[] = {'A',':','\\',0};
2040 struct record_logicaldisk *rec;
2041 UINT i, row = 0, offset = 0, type;
2042 UINT64 size = 1024 * 1024 * 1024;
2043 DWORD drives = GetLogicalDrives();
2044 enum fill_status status = FILL_STATUS_UNFILTERED;
2046 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
2048 for (i = 0; i < 26; i++)
2050 if (drives & (1 << i))
2052 root[0] = 'A' + i;
2053 type = GetDriveTypeW( root );
2054 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
2055 continue;
2057 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2059 rec = (struct record_logicaldisk *)(table->data + offset);
2060 sprintfW( device_id, fmtW, 'A' + i );
2061 rec->device_id = heap_strdupW( device_id );
2062 rec->drivetype = type;
2063 rec->filesystem = get_filesystem( root );
2064 rec->freespace = get_freespace( root, &size );
2065 rec->name = heap_strdupW( device_id );
2066 rec->size = size;
2067 rec->volumename = get_volumename( root );
2068 rec->volumeserialnumber = get_volumeserialnumber( root );
2069 if (!match_row( table, row, cond, &status ))
2071 free_row_values( table, row );
2072 continue;
2074 offset += sizeof(*rec);
2075 row++;
2078 TRACE("created %u rows\n", row);
2079 table->num_rows = row;
2080 return status;
2083 static UINT16 get_connection_status( IF_OPER_STATUS status )
2085 switch (status)
2087 case IfOperStatusDown:
2088 return 0; /* Disconnected */
2089 case IfOperStatusUp:
2090 return 2; /* Connected */
2091 default:
2092 ERR("unhandled status %u\n", status);
2093 break;
2095 return 0;
2097 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
2099 static const WCHAR fmtW[] =
2100 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
2101 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
2102 WCHAR *ret;
2104 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
2105 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
2106 return ret;
2108 static const WCHAR *get_adaptertype( DWORD type, int *physical )
2110 static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
2111 static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
2112 static const WCHAR firewireW[] = {'1','3','9','4',0};
2113 static const WCHAR tunnelW[] = {'T','u','n','n','e','l',0};
2115 switch (type)
2117 case IF_TYPE_ETHERNET_CSMACD: *physical = -1; return ethernetW;
2118 case IF_TYPE_IEEE80211: *physical = -1; return wirelessW;
2119 case IF_TYPE_IEEE1394: *physical = -1; return firewireW;
2120 case IF_TYPE_TUNNEL: *physical = 0; return tunnelW;
2121 default: *physical = 0; return NULL;
2125 static enum fill_status fill_networkadapter( struct table *table, const struct expr *cond )
2127 static const WCHAR fmtW[] = {'%','u',0};
2128 WCHAR device_id[11];
2129 struct record_networkadapter *rec;
2130 IP_ADAPTER_ADDRESSES *aa, *buffer;
2131 UINT row = 0, offset = 0, count = 0;
2132 DWORD size = 0, ret;
2133 int physical;
2134 enum fill_status status = FILL_STATUS_UNFILTERED;
2136 ret = GetAdaptersAddresses( WS_AF_UNSPEC, 0, NULL, NULL, &size );
2137 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
2139 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
2140 if (GetAdaptersAddresses( WS_AF_UNSPEC, 0, NULL, buffer, &size ))
2142 heap_free( buffer );
2143 return FILL_STATUS_FAILED;
2145 for (aa = buffer; aa; aa = aa->Next)
2147 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
2149 if (!resize_table( table, count, sizeof(*rec) ))
2151 heap_free( buffer );
2152 return FILL_STATUS_FAILED;
2154 for (aa = buffer; aa; aa = aa->Next)
2156 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
2158 rec = (struct record_networkadapter *)(table->data + offset);
2159 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
2160 rec->adaptertype = get_adaptertype( aa->IfType, &physical );
2161 rec->device_id = heap_strdupW( device_id );
2162 rec->index = aa->u.s.IfIndex;
2163 rec->interface_index = aa->u.s.IfIndex;
2164 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
2165 rec->manufacturer = compsys_manufacturerW;
2166 rec->name = heap_strdupW( aa->FriendlyName );
2167 rec->netconnection_status = get_connection_status( aa->OperStatus );
2168 rec->physicaladapter = physical;
2169 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
2170 rec->speed = 1000000;
2171 if (!match_row( table, row, cond, &status ))
2173 free_row_values( table, row );
2174 continue;
2176 offset += sizeof(*rec);
2177 row++;
2179 TRACE("created %u rows\n", row);
2180 table->num_rows = row;
2182 heap_free( buffer );
2183 return status;
2186 static WCHAR *get_dnshostname( IP_ADAPTER_UNICAST_ADDRESS *addr )
2188 const SOCKET_ADDRESS *sa = &addr->Address;
2189 WCHAR buf[WS_NI_MAXHOST];
2191 if (!addr) return NULL;
2192 if (GetNameInfoW( sa->lpSockaddr, sa->iSockaddrLength, buf, sizeof(buf)/sizeof(buf[0]), NULL,
2193 0, WS_NI_NAMEREQD )) return NULL;
2194 return heap_strdupW( buf );
2196 static struct array *get_defaultipgateway( IP_ADAPTER_GATEWAY_ADDRESS *list )
2198 IP_ADAPTER_GATEWAY_ADDRESS *gateway;
2199 struct array *ret;
2200 ULONG buflen, i = 0, count = 0;
2201 WCHAR **ptr, buf[54]; /* max IPv6 address length */
2203 if (!list) return NULL;
2204 for (gateway = list; gateway; gateway = gateway->Next) count++;
2206 if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
2207 if (!(ptr = heap_alloc( sizeof(*ptr) * count )))
2209 heap_free( ret );
2210 return NULL;
2212 for (gateway = list; gateway; gateway = gateway->Next)
2214 buflen = sizeof(buf)/sizeof(buf[0]);
2215 if (WSAAddressToStringW( gateway->Address.lpSockaddr, gateway->Address.iSockaddrLength,
2216 NULL, buf, &buflen) || !(ptr[i++] = heap_strdupW( buf )))
2218 for (; i > 0; i--) heap_free( ptr[i - 1] );
2219 heap_free( ptr );
2220 heap_free( ret );
2221 return NULL;
2224 ret->count = count;
2225 ret->ptr = ptr;
2226 return ret;
2228 static struct array *get_dnsserversearchorder( IP_ADAPTER_DNS_SERVER_ADDRESS *list )
2230 IP_ADAPTER_DNS_SERVER_ADDRESS *server;
2231 struct array *ret;
2232 ULONG buflen, i = 0, count = 0;
2233 WCHAR **ptr, *p, buf[54]; /* max IPv6 address length */
2235 if (!list) return NULL;
2236 for (server = list; server; server = server->Next) count++;
2238 if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
2239 if (!(ptr = heap_alloc( sizeof(*ptr) * count )))
2241 heap_free( ret );
2242 return NULL;
2244 for (server = list; server; server = server->Next)
2246 buflen = sizeof(buf)/sizeof(buf[0]);
2247 if (WSAAddressToStringW( server->Address.lpSockaddr, server->Address.iSockaddrLength,
2248 NULL, buf, &buflen) || !(ptr[i++] = heap_strdupW( buf )))
2250 for (; i > 0; i--) heap_free( ptr[i - 1] );
2251 heap_free( ptr );
2252 heap_free( ret );
2253 return NULL;
2255 if ((p = strrchrW( ptr[i - 1], ':' ))) *p = 0;
2257 ret->count = count;
2258 ret->ptr = ptr;
2259 return ret;
2261 static WCHAR *get_settingid( UINT32 index )
2263 GUID guid;
2264 WCHAR *ret, *str;
2265 memset( &guid, 0, sizeof(guid) );
2266 guid.Data1 = index;
2267 UuidToStringW( &guid, &str );
2268 ret = heap_strdupW( str );
2269 RpcStringFreeW( &str );
2270 return ret;
2273 static enum fill_status fill_networkadapterconfig( struct table *table, const struct expr *cond )
2275 struct record_networkadapterconfig *rec;
2276 IP_ADAPTER_ADDRESSES *aa, *buffer;
2277 UINT row = 0, offset = 0, count = 0;
2278 DWORD size = 0, ret;
2279 enum fill_status status = FILL_STATUS_UNFILTERED;
2281 ret = GetAdaptersAddresses( WS_AF_UNSPEC, GAA_FLAG_INCLUDE_ALL_GATEWAYS, NULL, NULL, &size );
2282 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
2284 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
2285 if (GetAdaptersAddresses( WS_AF_UNSPEC, GAA_FLAG_INCLUDE_ALL_GATEWAYS, NULL, buffer, &size ))
2287 heap_free( buffer );
2288 return FILL_STATUS_FAILED;
2290 for (aa = buffer; aa; aa = aa->Next)
2292 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
2294 if (!resize_table( table, count, sizeof(*rec) ))
2296 heap_free( buffer );
2297 return FILL_STATUS_FAILED;
2299 for (aa = buffer; aa; aa = aa->Next)
2301 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
2303 rec = (struct record_networkadapterconfig *)(table->data + offset);
2304 rec->defaultipgateway = get_defaultipgateway( aa->FirstGatewayAddress );
2305 rec->description = heap_strdupW( aa->Description );
2306 rec->dhcpenabled = -1;
2307 rec->dnshostname = get_dnshostname( aa->FirstUnicastAddress );
2308 rec->dnsserversearchorder = get_dnsserversearchorder( aa->FirstDnsServerAddress );
2309 rec->index = aa->u.s.IfIndex;
2310 rec->ipconnectionmetric = 20;
2311 rec->ipenabled = -1;
2312 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
2313 rec->settingid = get_settingid( rec->index );
2314 if (!match_row( table, row, cond, &status ))
2316 free_row_values( table, row );
2317 continue;
2319 offset += sizeof(*rec);
2320 row++;
2322 TRACE("created %u rows\n", row);
2323 table->num_rows = row;
2325 heap_free( buffer );
2326 return status;
2329 static enum fill_status fill_physicalmemory( struct table *table, const struct expr *cond )
2331 struct record_physicalmemory *rec;
2332 enum fill_status status = FILL_STATUS_UNFILTERED;
2333 UINT row = 0;
2335 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2337 rec = (struct record_physicalmemory *)table->data;
2338 rec->capacity = get_total_physical_memory();
2339 rec->memorytype = 9; /* RAM */
2340 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2341 else row++;
2343 TRACE("created %u rows\n", row);
2344 table->num_rows = row;
2345 return status;
2348 static enum fill_status fill_printer( struct table *table, const struct expr *cond )
2350 struct record_printer *rec;
2351 enum fill_status status = FILL_STATUS_UNFILTERED;
2352 PRINTER_INFO_2W *info;
2353 DWORD i, offset = 0, count = 0, size = 0, num_rows = 0;
2355 EnumPrintersW( PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &size, &count );
2356 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return FILL_STATUS_FAILED;
2358 if (!(info = heap_alloc( size ))) return FILL_STATUS_FAILED;
2359 if (!EnumPrintersW( PRINTER_ENUM_LOCAL, NULL, 2, (BYTE *)info, size, &size, &count ))
2361 heap_free( info );
2362 return FILL_STATUS_FAILED;
2364 if (!resize_table( table, count, sizeof(*rec) ))
2366 heap_free( info );
2367 return FILL_STATUS_FAILED;
2370 for (i = 0; i < count; i++)
2372 rec = (struct record_printer *)(table->data + offset);
2373 rec->attributes = info[i].Attributes;
2374 rec->drivername = heap_strdupW( info[i].pDriverName );
2375 rec->horizontalresolution = info[i].pDevMode->u1.s1.dmPrintQuality;
2376 rec->local = -1;
2377 rec->name = heap_strdupW( info[i].pPrinterName );
2378 rec->network = 0;
2379 if (!match_row( table, i, cond, &status ))
2381 free_row_values( table, i );
2382 continue;
2384 offset += sizeof(*rec);
2385 num_rows++;
2387 TRACE("created %u rows\n", num_rows);
2388 table->num_rows = num_rows;
2390 heap_free( info );
2391 return status;
2394 static WCHAR *get_cmdline( DWORD process_id )
2396 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
2397 return NULL; /* FIXME handle different process case */
2400 static enum fill_status fill_process( struct table *table, const struct expr *cond )
2402 static const WCHAR fmtW[] = {'%','u',0};
2403 WCHAR handle[11];
2404 struct record_process *rec;
2405 PROCESSENTRY32W entry;
2406 HANDLE snap;
2407 enum fill_status status = FILL_STATUS_FAILED;
2408 UINT row = 0, offset = 0;
2410 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
2411 if (snap == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED;
2413 entry.dwSize = sizeof(entry);
2414 if (!Process32FirstW( snap, &entry )) goto done;
2415 if (!resize_table( table, 8, sizeof(*rec) )) goto done;
2419 if (!resize_table( table, row + 1, sizeof(*rec) )) goto done;
2421 rec = (struct record_process *)(table->data + offset);
2422 rec->caption = heap_strdupW( entry.szExeFile );
2423 rec->commandline = get_cmdline( entry.th32ProcessID );
2424 rec->description = heap_strdupW( entry.szExeFile );
2425 sprintfW( handle, fmtW, entry.th32ProcessID );
2426 rec->handle = heap_strdupW( handle );
2427 rec->name = heap_strdupW( entry.szExeFile );
2428 rec->process_id = entry.th32ProcessID;
2429 rec->pprocess_id = entry.th32ParentProcessID;
2430 rec->thread_count = entry.cntThreads;
2431 rec->workingsetsize = 0;
2432 rec->get_owner = process_get_owner;
2433 if (!match_row( table, row, cond, &status ))
2435 free_row_values( table, row );
2436 continue;
2438 offset += sizeof(*rec);
2439 row++;
2440 } while (Process32NextW( snap, &entry ));
2442 TRACE("created %u rows\n", row);
2443 table->num_rows = row;
2444 status = FILL_STATUS_UNFILTERED;
2446 done:
2447 CloseHandle( snap );
2448 return status;
2451 static inline void do_cpuid( unsigned int ax, unsigned int *p )
2453 #ifdef __i386__
2454 #ifdef _MSC_VER
2455 __cpuid(p, ax);
2456 #else
2457 __asm__("pushl %%ebx\n\t"
2458 "cpuid\n\t"
2459 "movl %%ebx, %%esi\n\t"
2460 "popl %%ebx"
2461 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
2462 : "0" (ax));
2463 #endif
2464 #endif
2466 static const WCHAR *get_osarchitecture(void)
2468 SYSTEM_INFO info;
2469 GetNativeSystemInfo( &info );
2470 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
2471 return os_32bitW;
2473 static void get_processor_caption( WCHAR *caption )
2475 static const WCHAR fmtW[] =
2476 {'%','s',' ','F','a','m','i','l','y',' ','%','u',' ',
2477 'M','o','d','e','l',' ','%','u',' ','S','t','e','p','p','i','n','g',' ','%','u',0};
2478 static const WCHAR x86W[] = {'x','8','6',0};
2479 static const WCHAR intel64W[] = {'I','n','t','e','l','6','4',0};
2480 const WCHAR *arch = (get_osarchitecture() == os_32bitW) ? x86W : intel64W;
2481 unsigned int regs[4] = {0, 0, 0, 0};
2483 do_cpuid( 1, regs );
2484 sprintfW( caption, fmtW, arch, (regs[0] & (15 << 8)) >> 8, (regs[0] & (15 << 4)) >> 4, regs[0] & 15 );
2486 static void get_processor_version( WCHAR *version )
2488 static const WCHAR fmtW[] =
2489 {'M','o','d','e','l',' ','%','u',',',' ','S','t','e','p','p','i','n','g',' ','%','u',0};
2490 unsigned int regs[4] = {0, 0, 0, 0};
2492 do_cpuid( 1, regs );
2493 sprintfW( version, fmtW, (regs[0] & (15 << 4)) >> 4, regs[0] & 15 );
2495 static void get_processor_id( WCHAR *processor_id )
2497 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
2498 unsigned int regs[4] = {0, 0, 0, 0};
2500 do_cpuid( 1, regs );
2501 sprintfW( processor_id, fmtW, regs[3], regs[0] );
2503 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
2505 unsigned int i;
2506 unsigned char *p = (unsigned char *)regs;
2508 for (i = 0; i < len; i++) { buffer[i] = *p++; }
2509 buffer[i] = 0;
2511 static void get_processor_manufacturer( WCHAR *manufacturer )
2513 unsigned int tmp, regs[4] = {0, 0, 0, 0};
2515 do_cpuid( 0, regs );
2516 tmp = regs[2]; /* swap edx and ecx */
2517 regs[2] = regs[3];
2518 regs[3] = tmp;
2520 regs_to_str( regs + 1, 12, manufacturer );
2522 static void get_processor_name( WCHAR *name )
2524 unsigned int regs[4] = {0, 0, 0, 0};
2526 do_cpuid( 0x80000000, regs );
2527 if (regs[0] >= 0x80000004)
2529 do_cpuid( 0x80000002, regs );
2530 regs_to_str( regs, 16, name );
2531 do_cpuid( 0x80000003, regs );
2532 regs_to_str( regs, 16, name + 16 );
2533 do_cpuid( 0x80000004, regs );
2534 regs_to_str( regs, 16, name + 32 );
2537 static UINT get_processor_currentclockspeed( UINT index )
2539 PROCESSOR_POWER_INFORMATION *info;
2540 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
2541 NTSTATUS status;
2543 if ((info = heap_alloc( size )))
2545 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
2546 if (!status) ret = info[index].CurrentMhz;
2547 heap_free( info );
2549 return ret;
2551 static UINT get_processor_maxclockspeed( UINT index )
2553 PROCESSOR_POWER_INFORMATION *info;
2554 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
2555 NTSTATUS status;
2557 if ((info = heap_alloc( size )))
2559 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
2560 if (!status) ret = info[index].MaxMhz;
2561 heap_free( info );
2563 return ret;
2566 static enum fill_status fill_processor( struct table *table, const struct expr *cond )
2568 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
2569 WCHAR caption[100], device_id[14], processor_id[17], manufacturer[13], name[49] = {0}, version[50];
2570 struct record_processor *rec;
2571 UINT i, offset = 0, num_rows = 0, num_cores, num_logical_processors, count = get_processor_count();
2572 enum fill_status status = FILL_STATUS_UNFILTERED;
2574 if (!resize_table( table, count, sizeof(*rec) )) return FILL_STATUS_FAILED;
2576 get_processor_caption( caption );
2577 get_processor_id( processor_id );
2578 get_processor_manufacturer( manufacturer );
2579 get_processor_name( name );
2580 get_processor_version( version );
2582 num_logical_processors = get_logical_processor_count( &num_cores ) / count;
2583 num_cores /= count;
2585 for (i = 0; i < count; i++)
2587 rec = (struct record_processor *)(table->data + offset);
2588 rec->addresswidth = get_osarchitecture() == os_32bitW ? 32 : 64;
2589 rec->caption = heap_strdupW( caption );
2590 rec->cpu_status = 1; /* CPU Enabled */
2591 rec->currentclockspeed = get_processor_currentclockspeed( i );
2592 rec->datawidth = get_osarchitecture() == os_32bitW ? 32 : 64;
2593 rec->description = heap_strdupW( caption );
2594 sprintfW( device_id, fmtW, i );
2595 rec->device_id = heap_strdupW( device_id );
2596 rec->family = 2; /* Unknown */
2597 rec->manufacturer = heap_strdupW( manufacturer );
2598 rec->maxclockspeed = get_processor_maxclockspeed( i );
2599 rec->name = heap_strdupW( name );
2600 rec->num_cores = num_cores;
2601 rec->num_logical_processors = num_logical_processors;
2602 rec->processor_id = heap_strdupW( processor_id );
2603 rec->processortype = 3; /* central processor */
2604 rec->unique_id = NULL;
2605 rec->version = heap_strdupW( version );
2606 if (!match_row( table, i, cond, &status ))
2608 free_row_values( table, i );
2609 continue;
2611 offset += sizeof(*rec);
2612 num_rows++;
2615 TRACE("created %u rows\n", num_rows);
2616 table->num_rows = num_rows;
2617 return status;
2620 static WCHAR *get_lastbootuptime(void)
2622 static const WCHAR fmtW[] =
2623 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
2624 '.','%','0','6','u','+','0','0','0',0};
2625 SYSTEM_TIMEOFDAY_INFORMATION ti;
2626 TIME_FIELDS tf;
2627 WCHAR *ret;
2629 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2631 NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
2632 RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
2633 sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
2634 return ret;
2636 static WCHAR *get_localdatetime(void)
2638 static const WCHAR fmtW[] =
2639 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
2640 '.','%','0','6','u','%','+','0','3','d',0};
2641 TIME_ZONE_INFORMATION tzi;
2642 SYSTEMTIME st;
2643 WCHAR *ret;
2644 DWORD Status;
2645 LONG Bias;
2647 Status = GetTimeZoneInformation(&tzi);
2649 if(Status == TIME_ZONE_ID_INVALID) return NULL;
2650 Bias = tzi.Bias;
2651 if(Status == TIME_ZONE_ID_DAYLIGHT)
2652 Bias+= tzi.DaylightBias;
2653 else
2654 Bias+= tzi.StandardBias;
2655 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2657 GetLocalTime(&st);
2658 sprintfW( ret, fmtW, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds * 1000, -Bias);
2659 return ret;
2661 static WCHAR *get_systemdirectory(void)
2663 void *redir;
2664 WCHAR *ret;
2666 if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
2667 Wow64DisableWow64FsRedirection( &redir );
2668 GetSystemDirectoryW( ret, MAX_PATH );
2669 Wow64RevertWow64FsRedirection( redir );
2670 return ret;
2672 static WCHAR *get_codeset(void)
2674 static const WCHAR fmtW[] = {'%','u',0};
2675 WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
2676 if (ret) sprintfW( ret, fmtW, GetACP() );
2677 return ret;
2679 static WCHAR *get_countrycode(void)
2681 WCHAR *ret = heap_alloc( 6 * sizeof(WCHAR) );
2682 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY, ret, 6 );
2683 return ret;
2685 static WCHAR *get_locale(void)
2687 WCHAR *ret = heap_alloc( 5 * sizeof(WCHAR) );
2688 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, ret, 5 );
2689 return ret;
2691 static WCHAR *get_osbuildnumber( OSVERSIONINFOEXW *ver )
2693 static const WCHAR fmtW[] = {'%','u',0};
2694 WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
2695 if (ret) sprintfW( ret, fmtW, ver->dwBuildNumber );
2696 return ret;
2698 static WCHAR *get_oscaption( OSVERSIONINFOEXW *ver )
2700 static const WCHAR windowsW[] =
2701 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' '};
2702 static const WCHAR win2000W[] =
2703 {'2','0','0','0',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
2704 static const WCHAR win2003W[] =
2705 {'S','e','r','v','e','r',' ','2','0','0','3',' ','S','t','a','n','d','a','r','d',' ','E','d','i','t','i','o','n',0};
2706 static const WCHAR winxpW[] =
2707 {'X','P',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
2708 static const WCHAR winxp64W[] =
2709 {'X','P',' ','P','r','o','f','e','s','s','i','o','n','a','l',' ','x','6','4',' ','E','d','i','t','i','o','n',0};
2710 static const WCHAR vistaW[] =
2711 {'V','i','s','t','a',' ','U','l','t','i','m','a','t','e',0};
2712 static const WCHAR win2008W[] =
2713 {'S','e','r','v','e','r',' ','2','0','0','8',' ','S','t','a','n','d','a','r','d',0};
2714 static const WCHAR win7W[] =
2715 {'7',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
2716 static const WCHAR win2008r2W[] =
2717 {'S','e','r','v','e','r',' ','2','0','0','8',' ','R','2',' ','S','t','a','n','d','a','r','d',0};
2718 static const WCHAR win8W[] =
2719 {'8',' ','P','r','o',0};
2720 static const WCHAR win81W[] =
2721 {'8','.','1',' ','P','r','o',0};
2722 static const WCHAR win10W[] =
2723 {'1','0',' ','P','r','o',0};
2724 int len = sizeof(windowsW)/sizeof(windowsW[0]);
2725 WCHAR *ret;
2727 if (!(ret = heap_alloc( len * sizeof(WCHAR) + sizeof(win2003W) ))) return NULL;
2728 memcpy( ret, windowsW, sizeof(windowsW) );
2729 if (ver->dwMajorVersion == 10 && ver->dwMinorVersion == 0) memcpy( ret + len, win10W, sizeof(win10W) );
2730 else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 3) memcpy( ret + len, win8W, sizeof(win8W) );
2731 else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 2) memcpy( ret + len, win81W, sizeof(win81W) );
2732 else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 1)
2734 if (ver->wProductType == VER_NT_WORKSTATION) memcpy( ret + len, win7W, sizeof(win7W) );
2735 else memcpy( ret + len, win2008r2W, sizeof(win2008r2W) );
2737 else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 0)
2739 if (ver->wProductType == VER_NT_WORKSTATION) memcpy( ret + len, vistaW, sizeof(vistaW) );
2740 else memcpy( ret + len, win2008W, sizeof(win2008W) );
2742 else if (ver->dwMajorVersion == 5 && ver->dwMinorVersion == 2)
2744 if (ver->wProductType == VER_NT_WORKSTATION) memcpy( ret + len, winxp64W, sizeof(winxp64W) );
2745 else memcpy( ret + len, win2003W, sizeof(win2003W) );
2747 else if (ver->dwMajorVersion == 5 && ver->dwMinorVersion == 1) memcpy( ret + len, winxpW, sizeof(winxpW) );
2748 else memcpy( ret + len, win2000W, sizeof(win2000W) );
2749 return ret;
2751 static WCHAR *get_osname( const WCHAR *caption )
2753 static const WCHAR partitionW[] =
2754 {'|','C',':','\\','W','I','N','D','O','W','S','|','\\','D','e','v','i','c','e','\\',
2755 'H','a','r','d','d','i','s','k','0','\\','P','a','r','t','i','t','i','o','n','1',0};
2756 int len = strlenW( caption );
2757 WCHAR *ret;
2759 if (!(ret = heap_alloc( len * sizeof(WCHAR) + sizeof(partitionW) ))) return NULL;
2760 memcpy( ret, caption, len * sizeof(WCHAR) );
2761 memcpy( ret + len, partitionW, sizeof(partitionW) );
2762 return ret;
2764 static WCHAR *get_osversion( OSVERSIONINFOEXW *ver )
2766 static const WCHAR fmtW[] = {'%','u','.','%','u','.','%','u',0};
2767 WCHAR *ret = heap_alloc( 33 * sizeof(WCHAR) );
2768 if (ret) sprintfW( ret, fmtW, ver->dwMajorVersion, ver->dwMinorVersion, ver->dwBuildNumber );
2769 return ret;
2772 static enum fill_status fill_os( struct table *table, const struct expr *cond )
2774 struct record_operatingsystem *rec;
2775 enum fill_status status = FILL_STATUS_UNFILTERED;
2776 OSVERSIONINFOEXW ver;
2777 UINT row = 0;
2779 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2781 ver.dwOSVersionInfoSize = sizeof(ver);
2782 GetVersionExW( (OSVERSIONINFOW *)&ver );
2784 rec = (struct record_operatingsystem *)table->data;
2785 rec->buildnumber = get_osbuildnumber( &ver );
2786 rec->caption = get_oscaption( &ver );
2787 rec->codeset = get_codeset();
2788 rec->countrycode = get_countrycode();
2789 rec->csdversion = ver.szCSDVersion[0] ? heap_strdupW( ver.szCSDVersion ) : NULL;
2790 rec->installdate = os_installdateW;
2791 rec->lastbootuptime = get_lastbootuptime();
2792 rec->localdatetime = get_localdatetime();
2793 rec->locale = get_locale();
2794 rec->name = get_osname( rec->caption );
2795 rec->osarchitecture = get_osarchitecture();
2796 rec->oslanguage = GetSystemDefaultLangID();
2797 rec->osproductsuite = 2461140; /* Windows XP Professional */
2798 rec->ostype = 18; /* WINNT */
2799 rec->primary = -1;
2800 rec->serialnumber = os_serialnumberW;
2801 rec->servicepackmajor = ver.wServicePackMajor;
2802 rec->servicepackminor = ver.wServicePackMinor;
2803 rec->suitemask = 272; /* Single User + Terminal */
2804 rec->systemdirectory = get_systemdirectory();
2805 rec->totalvirtualmemorysize = get_total_physical_memory() / 1024;
2806 rec->totalvisiblememorysize = rec->totalvirtualmemorysize;
2807 rec->version = get_osversion( &ver );
2808 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2809 else row++;
2811 TRACE("created %u rows\n", row);
2812 table->num_rows = row;
2813 return status;
2816 static const WCHAR *get_service_type( DWORD type )
2818 static const WCHAR filesystem_driverW[] =
2819 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
2820 static const WCHAR kernel_driverW[] =
2821 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
2822 static const WCHAR own_processW[] =
2823 {'O','w','n',' ','P','r','o','c','e','s','s',0};
2824 static const WCHAR share_processW[] =
2825 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
2827 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
2828 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
2829 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
2830 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
2831 else ERR("unhandled type 0x%08x\n", type);
2832 return NULL;
2834 static const WCHAR *get_service_state( DWORD state )
2836 static const WCHAR runningW[] =
2837 {'R','u','n','n','i','n','g',0};
2838 static const WCHAR start_pendingW[] =
2839 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
2840 static const WCHAR stop_pendingW[] =
2841 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
2842 static const WCHAR stoppedW[] =
2843 {'S','t','o','p','p','e','d',0};
2844 static const WCHAR unknownW[] =
2845 {'U','n','k','n','o','w','n',0};
2847 switch (state)
2849 case SERVICE_STOPPED: return stoppedW;
2850 case SERVICE_START_PENDING: return start_pendingW;
2851 case SERVICE_STOP_PENDING: return stop_pendingW;
2852 case SERVICE_RUNNING: return runningW;
2853 default:
2854 ERR("unknown state %u\n", state);
2855 return unknownW;
2858 static const WCHAR *get_service_startmode( DWORD mode )
2860 static const WCHAR bootW[] = {'B','o','o','t',0};
2861 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
2862 static const WCHAR autoW[] = {'A','u','t','o',0};
2863 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
2864 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
2865 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
2867 switch (mode)
2869 case SERVICE_BOOT_START: return bootW;
2870 case SERVICE_SYSTEM_START: return systemW;
2871 case SERVICE_AUTO_START: return autoW;
2872 case SERVICE_DEMAND_START: return manualW;
2873 case SERVICE_DISABLED: return disabledW;
2874 default:
2875 ERR("unknown mode 0x%x\n", mode);
2876 return unknownW;
2879 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
2881 QUERY_SERVICE_CONFIGW *config = NULL;
2882 SC_HANDLE service;
2883 DWORD size;
2885 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
2886 QueryServiceConfigW( service, NULL, 0, &size );
2887 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
2888 if (!(config = heap_alloc( size ))) goto done;
2889 if (QueryServiceConfigW( service, config, size, &size )) goto done;
2890 heap_free( config );
2891 config = NULL;
2893 done:
2894 CloseServiceHandle( service );
2895 return config;
2898 static enum fill_status fill_service( struct table *table, const struct expr *cond )
2900 struct record_service *rec;
2901 SC_HANDLE manager;
2902 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
2903 SERVICE_STATUS_PROCESS *status;
2904 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
2905 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
2906 UINT i, row = 0, offset = 0, size = 256, needed, count;
2907 enum fill_status fill_status = FILL_STATUS_FAILED;
2908 BOOL ret;
2910 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return FILL_STATUS_FAILED;
2911 if (!(services = heap_alloc( size ))) goto done;
2913 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2914 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2915 &count, NULL, NULL );
2916 if (!ret)
2918 if (GetLastError() != ERROR_MORE_DATA) goto done;
2919 size = needed;
2920 if (!(tmp = heap_realloc( services, size ))) goto done;
2921 services = tmp;
2922 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2923 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2924 &count, NULL, NULL );
2925 if (!ret) goto done;
2927 if (!resize_table( table, count, sizeof(*rec) )) goto done;
2929 GetComputerNameW( sysnameW, &len );
2930 fill_status = FILL_STATUS_UNFILTERED;
2932 for (i = 0; i < count; i++)
2934 QUERY_SERVICE_CONFIGW *config;
2936 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
2938 status = &services[i].ServiceStatusProcess;
2939 rec = (struct record_service *)(table->data + offset);
2940 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
2941 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
2942 rec->displayname = heap_strdupW( services[i].lpDisplayName );
2943 rec->name = heap_strdupW( services[i].lpServiceName );
2944 rec->process_id = status->dwProcessId;
2945 rec->servicetype = get_service_type( status->dwServiceType );
2946 rec->startmode = get_service_startmode( config->dwStartType );
2947 rec->state = get_service_state( status->dwCurrentState );
2948 rec->systemname = heap_strdupW( sysnameW );
2949 rec->pause_service = service_pause_service;
2950 rec->resume_service = service_resume_service;
2951 rec->start_service = service_start_service;
2952 rec->stop_service = service_stop_service;
2953 heap_free( config );
2954 if (!match_row( table, row, cond, &fill_status ))
2956 free_row_values( table, row );
2957 continue;
2959 offset += sizeof(*rec);
2960 row++;
2963 TRACE("created %u rows\n", row);
2964 table->num_rows = row;
2966 done:
2967 CloseServiceHandle( manager );
2968 heap_free( services );
2969 return fill_status;
2972 static WCHAR *get_accountname( LSA_TRANSLATED_NAME *name )
2974 if (!name || !name->Name.Buffer) return NULL;
2975 return heap_strdupW( name->Name.Buffer );
2977 static struct array *get_binaryrepresentation( PSID sid, UINT len )
2979 struct array *array = heap_alloc( sizeof(struct array) );
2980 if (array)
2982 UINT8 *ret = heap_alloc( len );
2983 if (ret)
2985 memcpy( ret, sid, len );
2986 array->count = len;
2987 array->ptr = ret;
2988 return array;
2990 heap_free( array );
2992 return NULL;
2994 static WCHAR *get_referenceddomainname( LSA_REFERENCED_DOMAIN_LIST *domain )
2996 if (!domain || !domain->Domains || !domain->Domains->Name.Buffer) return NULL;
2997 return heap_strdupW( domain->Domains->Name.Buffer );
2999 static const WCHAR *find_sid_str( const struct expr *cond )
3001 const struct expr *left, *right;
3002 const WCHAR *ret = NULL;
3004 if (!cond || cond->type != EXPR_COMPLEX || cond->u.expr.op != OP_EQ) return NULL;
3006 left = cond->u.expr.left;
3007 right = cond->u.expr.right;
3008 if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL && !strcmpiW( left->u.propval->name, prop_sidW ))
3010 ret = right->u.sval;
3012 else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL && !strcmpiW( right->u.propval->name, prop_sidW ))
3014 ret = left->u.sval;
3016 return ret;
3019 static enum fill_status fill_sid( struct table *table, const struct expr *cond )
3021 PSID sid;
3022 LSA_REFERENCED_DOMAIN_LIST *domain;
3023 LSA_TRANSLATED_NAME *name;
3024 LSA_HANDLE handle;
3025 LSA_OBJECT_ATTRIBUTES attrs;
3026 const WCHAR *str;
3027 struct record_sid *rec;
3028 UINT len;
3030 if (!(str = find_sid_str( cond ))) return FILL_STATUS_FAILED;
3031 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
3033 if (!ConvertStringSidToSidW( str, &sid )) return FILL_STATUS_FAILED;
3034 len = GetLengthSid( sid );
3036 memset( &attrs, 0, sizeof(attrs) );
3037 attrs.Length = sizeof(attrs);
3038 if (LsaOpenPolicy( NULL, &attrs, POLICY_ALL_ACCESS, &handle ))
3040 LocalFree( sid );
3041 return FILL_STATUS_FAILED;
3043 if (LsaLookupSids( handle, 1, &sid, &domain, &name ))
3045 LocalFree( sid );
3046 LsaClose( handle );
3047 return FILL_STATUS_FAILED;
3050 rec = (struct record_sid *)table->data;
3051 rec->accountname = get_accountname( name );
3052 rec->binaryrepresentation = get_binaryrepresentation( sid, len );
3053 rec->referenceddomainname = get_referenceddomainname( domain );
3054 rec->sid = heap_strdupW( str );
3055 rec->sidlength = len;
3057 TRACE("created 1 row\n");
3058 table->num_rows = 1;
3060 LsaFreeMemory( domain );
3061 LsaFreeMemory( name );
3062 LocalFree( sid );
3063 LsaClose( handle );
3064 return FILL_STATUS_FILTERED;
3067 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
3069 HDC hdc = GetDC( NULL );
3070 UINT32 ret;
3072 if (!hdc) return 32;
3073 ret = GetDeviceCaps( hdc, BITSPIXEL );
3074 *hres = GetDeviceCaps( hdc, HORZRES );
3075 *vres = GetDeviceCaps( hdc, VERTRES );
3076 ReleaseDC( NULL, hdc );
3077 return ret;
3079 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
3081 static const WCHAR fmtW[] =
3082 {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
3083 '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
3084 '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
3085 WCHAR *ret;
3087 if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
3088 sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
3089 return ret;
3092 static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond )
3094 static const WCHAR fmtW[] = {'%','u',' ','x',' ','%','u',' ','x',' ','%','I','6','4','u',' ','c','o','l','o','r','s',0};
3095 struct record_videocontroller *rec;
3096 HRESULT hr;
3097 IDXGIFactory *factory = NULL;
3098 IDXGIAdapter *adapter = NULL;
3099 DXGI_ADAPTER_DESC desc;
3100 UINT row = 0, hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
3101 const WCHAR *name = videocontroller_deviceidW;
3102 enum fill_status status = FILL_STATUS_UNFILTERED;
3103 WCHAR mode[44];
3105 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
3107 memset (&desc, 0, sizeof(desc));
3108 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
3109 if (FAILED(hr)) goto done;
3111 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
3112 if (FAILED(hr)) goto done;
3114 hr = IDXGIAdapter_GetDesc( adapter, &desc );
3115 if (SUCCEEDED(hr))
3117 vidmem = desc.DedicatedVideoMemory;
3118 name = desc.Description;
3121 done:
3122 rec = (struct record_videocontroller *)table->data;
3123 rec->adapter_dactype = videocontroller_dactypeW;
3124 rec->adapter_ram = vidmem;
3125 rec->availability = 3; /* Running or Full Power */
3126 rec->caption = heap_strdupW( name );
3127 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
3128 rec->current_horizontalres = hres;
3129 rec->current_refreshrate = 0; /* default refresh rate */
3130 rec->current_scanmode = 2; /* Unknown */
3131 rec->current_verticalres = vres;
3132 rec->description = heap_strdupW( name );
3133 rec->device_id = videocontroller_deviceidW;
3134 rec->driverversion = videocontroller_driverversionW;
3135 rec->name = heap_strdupW( name );
3136 rec->pnpdevice_id = get_pnpdeviceid( &desc );
3137 rec->videoarchitecture = 2; /* Unknown */
3138 rec->videomemorytype = 2; /* Unknown */
3139 wsprintfW( mode, fmtW, hres, vres, (UINT64)1 << rec->current_bitsperpixel );
3140 rec->videomodedescription = heap_strdupW( mode );
3141 rec->videoprocessor = heap_strdupW( name );
3142 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
3143 else row++;
3145 TRACE("created %u rows\n", row);
3146 table->num_rows = row;
3148 if (adapter) IDXGIAdapter_Release( adapter );
3149 if (factory) IDXGIFactory_Release( factory );
3150 return status;
3153 static struct table builtin_classes[] =
3155 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), 0, (BYTE *)data_baseboard },
3156 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), 0, (BYTE *)data_bios },
3157 { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, 0, 0, NULL, fill_cdromdrive },
3158 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, 0, NULL, fill_compsys },
3159 { class_compsysproductW, SIZEOF(col_compsysproduct), col_compsysproduct, 0, 0, NULL, fill_compsysproduct },
3160 { class_datafileW, SIZEOF(col_datafile), col_datafile, 0, 0, NULL, fill_datafile },
3161 { class_desktopmonitorW, SIZEOF(col_desktopmonitor), col_desktopmonitor, 0, 0, NULL, fill_desktopmonitor },
3162 { class_directoryW, SIZEOF(col_directory), col_directory, 0, 0, NULL, fill_directory },
3163 { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, 0, 0, NULL, fill_diskdrive },
3164 { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, 0, NULL, fill_diskpartition },
3165 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
3166 { class_logicaldisk2W, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
3167 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, 0, NULL, fill_networkadapter },
3168 { class_networkadapterconfigW, SIZEOF(col_networkadapterconfig), col_networkadapterconfig, 0, 0, NULL, fill_networkadapterconfig },
3169 { class_osW, SIZEOF(col_os), col_os, 0, 0, NULL, fill_os },
3170 { class_paramsW, SIZEOF(col_param), col_param, SIZEOF(data_param), 0, (BYTE *)data_param },
3171 { class_physicalmediaW, SIZEOF(col_physicalmedia), col_physicalmedia, SIZEOF(data_physicalmedia), 0, (BYTE *)data_physicalmedia },
3172 { class_physicalmemoryW, SIZEOF(col_physicalmemory), col_physicalmemory, 0, 0, NULL, fill_physicalmemory },
3173 { class_printerW, SIZEOF(col_printer), col_printer, 0, 0, NULL, fill_printer },
3174 { class_processW, SIZEOF(col_process), col_process, 0, 0, NULL, fill_process },
3175 { class_processorW, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
3176 { class_processor2W, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
3177 { class_qualifiersW, SIZEOF(col_qualifier), col_qualifier, SIZEOF(data_qualifier), 0, (BYTE *)data_qualifier },
3178 { class_serviceW, SIZEOF(col_service), col_service, 0, 0, NULL, fill_service },
3179 { class_sidW, SIZEOF(col_sid), col_sid, 0, 0, NULL, fill_sid },
3180 { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), 0, (BYTE *)data_sounddevice },
3181 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), 0, (BYTE *)data_stdregprov },
3182 { class_systemsecurityW, SIZEOF(col_systemsecurity), col_systemsecurity, SIZEOF(data_systemsecurity), 0, (BYTE *)data_systemsecurity },
3183 { class_systemenclosureW, SIZEOF(col_systemenclosure), col_systemenclosure, SIZEOF(data_systemenclosure), 0, (BYTE *)data_systemenclosure },
3184 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, 0, NULL, fill_videocontroller }
3187 void init_table_list( void )
3189 static struct list tables = LIST_INIT( tables );
3190 UINT i;
3192 for (i = 0; i < SIZEOF(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
3193 table_list = &tables;