mshtml: Make IEventTarget_{add,remove}EventListener_hook() static.
[wine.git] / dlls / wbemprox / builtin.c
blob93bea5280cc26270c0d258dec2df37af3ff4d331
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
29 #ifdef HAVE_ARPA_INET_H
30 # include <arpa/inet.h>
31 #endif
33 #include "ntstatus.h"
34 #define WIN32_NO_STATUS
35 #include "windef.h"
36 #include "winbase.h"
37 #ifdef __MINGW32__
38 # include "winsock2.h"
39 # include "ws2tcpip.h"
40 # define WS_AF_UNSPEC AF_UNSPEC
41 # define WS_NI_MAXHOST NI_MAXHOST
42 # define WS_NI_NAMEREQD NI_NAMEREQD
43 #else
44 # define USE_WS_PREFIX
45 # include "winsock2.h"
46 # include "ws2tcpip.h"
47 #endif
48 #include "initguid.h"
49 #include "wbemcli.h"
50 #include "wbemprov.h"
51 #include "iphlpapi.h"
52 #include "tlhelp32.h"
53 #include "d3d10.h"
54 #include "winternl.h"
55 #include "winioctl.h"
56 #include "winsvc.h"
57 #include "winver.h"
58 #include "sddl.h"
59 #include "ntsecapi.h"
60 #include "winspool.h"
62 #include "wine/debug.h"
63 #include "wbemprox_private.h"
65 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
67 static const WCHAR class_baseboardW[] =
68 {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
69 static const WCHAR class_biosW[] =
70 {'W','i','n','3','2','_','B','I','O','S',0};
71 static const WCHAR class_cdromdriveW[] =
72 {'W','i','n','3','2','_','C','D','R','O','M','D','r','i','v','e',0};
73 static const WCHAR class_compsysW[] =
74 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
75 static const WCHAR class_compsysproductW[] =
76 {'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};
77 static const WCHAR class_datafileW[] =
78 {'C','I','M','_','D','a','t','a','F','i','l','e',0};
79 static const WCHAR class_desktopmonitorW[] =
80 {'W','i','n','3','2','_','D','e','s','k','t','o','p','M','o','n','i','t','o','r',0};
81 static const WCHAR class_directoryW[] =
82 {'W','i','n','3','2','_','D','i','r','e','c','t','o','r','y',0};
83 static const WCHAR class_diskdriveW[] =
84 {'W','i','n','3','2','_','D','i','s','k','D','r','i','v','e',0};
85 static const WCHAR class_diskpartitionW[] =
86 {'W','i','n','3','2','_','D','i','s','k','P','a','r','t','i','t','i','o','n',0};
87 static const WCHAR class_ip4routetableW[] =
88 {'W','i','n','3','2','_','I','P','4','R','o','u','t','e','T','a','b','l','e',0};
89 static const WCHAR class_logicaldiskW[] =
90 {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
91 static const WCHAR class_logicaldisk2W[] =
92 {'C','I','M','_','L','o','g','i','c','a','l','D','i','s','k',0};
93 static const WCHAR class_networkadapterW[] =
94 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
95 static const WCHAR class_networkadapterconfigW[] =
96 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',
97 'C','o','n','f','i','g','u','r','a','t','i','o','n',0};
98 static const WCHAR class_osW[] =
99 {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
100 static const WCHAR class_paramsW[] =
101 {'_','_','P','A','R','A','M','E','T','E','R','S',0};
102 static const WCHAR class_physicalmediaW[] =
103 {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','d','i','a',0};
104 static const WCHAR class_physicalmemoryW[] =
105 {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
106 static const WCHAR class_printerW[] =
107 {'W','i','n','3','2','_','P','r','i','n','t','e','r',0};
108 static const WCHAR class_process_getowner_outW[] =
109 {'_','_','W','I','N','3','2','_','P','R','O','C','E','S','S','_','G','E','T','O','W',
110 'N','E','R','_','O','U','T',0};
111 static const WCHAR class_processorW[] =
112 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
113 static const WCHAR class_processor2W[] =
114 {'C','I','M','_','P','r','o','c','e','s','s','o','r',0};
115 static const WCHAR class_qualifiersW[] =
116 {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
117 static const WCHAR class_sidW[] =
118 {'W','i','n','3','2','_','S','I','D',0};
119 static const WCHAR class_sounddeviceW[] =
120 {'W','i','n','3','2','_','S','o','u','n','d','D','e','v','i','c','e',0};
121 static const WCHAR class_systemenclosureW[] =
122 {'W','i','n','3','2','_','S','y','s','t','e','m','E','n','c','l','o','s','u','r','e',0};
123 static const WCHAR class_videocontrollerW[] =
124 {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
126 static const WCHAR prop_accountnameW[] =
127 {'A','c','c','o','u','n','t','N','a','m','e',0};
128 static const WCHAR prop_acceptpauseW[] =
129 {'A','c','c','e','p','t','P','a','u','s','e',0};
130 static const WCHAR prop_acceptstopW[] =
131 {'A','c','c','e','p','t','S','t','o','p',0};
132 static const WCHAR prop_accessmaskW[] =
133 {'A','c','c','e','s','s','M','a','s','k',0};
134 static const WCHAR prop_adapterdactypeW[] =
135 {'A','d','a','p','t','e','r','D','A','C','T','y','p','e',0};
136 static const WCHAR prop_adapterramW[] =
137 {'A','d','a','p','t','e','r','R','A','M',0};
138 static const WCHAR prop_adaptertypeW[] =
139 {'A','d','a','p','t','e','r','T','y','p','e',0};
140 static const WCHAR prop_addresswidthW[] =
141 {'A','d','d','r','e','s','s','W','i','d','t','h',0};
142 static const WCHAR prop_attributesW[] =
143 {'A','t','t','r','i','b','u','t','e','s',0};
144 static const WCHAR prop_availabilityW[] =
145 {'A','v','a','i','l','a','b','i','l','i','t','y',0};
146 static const WCHAR prop_binaryrepresentationW[] =
147 {'B','i','n','a','r','y','R','e','p','r','e','s','e','n','t','a','t','i','o','n',0};
148 static const WCHAR prop_bootableW[] =
149 {'B','o','o','t','a','b','l','e',0};
150 static const WCHAR prop_bootpartitionW[] =
151 {'B','o','o','t','P','a','r','t','i','t','i','o','n',0};
152 static const WCHAR prop_buildnumberW[] =
153 {'B','u','i','l','d','N','u','m','b','e','r',0};
154 static const WCHAR prop_capacityW[] =
155 {'C','a','p','a','c','i','t','y',0};
156 static const WCHAR prop_captionW[] =
157 {'C','a','p','t','i','o','n',0};
158 static const WCHAR prop_chassistypesW[] =
159 {'C','h','a','s','s','i','s','T','y','p','e','s',0};
160 static const WCHAR prop_classW[] =
161 {'C','l','a','s','s',0};
162 static const WCHAR prop_codesetW[] =
163 {'C','o','d','e','S','e','t',0};
164 static const WCHAR prop_commandlineW[] =
165 {'C','o','m','m','a','n','d','L','i','n','e',0};
166 static const WCHAR prop_countrycodeW[] =
167 {'C','o','u','n','t','r','y','C','o','d','e',0};
168 static const WCHAR prop_cpustatusW[] =
169 {'C','p','u','S','t','a','t','u','s',0};
170 static const WCHAR prop_csdversionW[] =
171 {'C','S','D','V','e','r','s','i','o','n',0};
172 static const WCHAR prop_currentbitsperpixelW[] =
173 {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
174 static const WCHAR prop_currentclockspeedW[] =
175 {'C','u','r','r','e','n','t','C','l','o','c','k','S','p','e','e','d',0};
176 static const WCHAR prop_currenthorizontalresW[] =
177 {'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};
178 static const WCHAR prop_currentrefreshrateW[] =
179 {'C','u','r','r','e','n','t','R','e','f','r','e','s','h','R','a','t','e',0};
180 static const WCHAR prop_currentscanmodeW[] =
181 {'C','u','r','r','e','n','t','S','c','a','n','M','o','d','e',0};
182 static const WCHAR prop_currentverticalresW[] =
183 {'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};
184 static const WCHAR prop_datawidthW[] =
185 {'D','a','t','a','W','i','d','t','h',0};
186 static const WCHAR prop_defaultipgatewayW[] =
187 {'D','e','f','a','u','l','t','I','P','G','a','t','e','w','a','y',0};
188 static const WCHAR prop_defaultvalueW[] =
189 {'D','e','f','a','u','l','t','V','a','l','u','e',0};
190 static const WCHAR prop_descriptionW[] =
191 {'D','e','s','c','r','i','p','t','i','o','n',0};
192 static const WCHAR prop_destinationW[] =
193 {'D','e','s','t','i','n','a','t','i','o','n',0};
194 static const WCHAR prop_deviceidW[] =
195 {'D','e','v','i','c','e','I','d',0};
196 static const WCHAR prop_dhcpenabledW[] =
197 {'D','H','C','P','E','n','a','b','l','e','d',0};
198 static const WCHAR prop_directionW[] =
199 {'D','i','r','e','c','t','i','o','n',0};
200 static const WCHAR prop_displaynameW[] =
201 {'D','i','s','p','l','a','y','N','a','m','e',0};
202 static const WCHAR prop_diskindexW[] =
203 {'D','i','s','k','I','n','d','e','x',0};
204 static const WCHAR prop_dnshostnameW[] =
205 {'D','N','S','H','o','s','t','N','a','m','e',0};
206 static const WCHAR prop_dnsserversearchorderW[] =
207 {'D','N','S','S','e','r','v','e','r','S','e','a','r','c','h','O','r','d','e','r',0};
208 static const WCHAR prop_domainW[] =
209 {'D','o','m','a','i','n',0};
210 static const WCHAR prop_domainroleW[] =
211 {'D','o','m','a','i','n','R','o','l','e',0};
212 static const WCHAR prop_driveW[] =
213 {'D','r','i','v','e',0};
214 static const WCHAR prop_drivernameW[] =
215 {'D','r','i','v','e','r','N','a','m','e',0};
216 static const WCHAR prop_driverversionW[] =
217 {'D','r','i','v','e','r','V','e','r','s','i','o','n',0};
218 static const WCHAR prop_drivetypeW[] =
219 {'D','r','i','v','e','T','y','p','e',0};
220 static const WCHAR prop_familyW[] =
221 {'F','a','m','i','l','y',0};
222 static const WCHAR prop_filesystemW[] =
223 {'F','i','l','e','S','y','s','t','e','m',0};
224 static const WCHAR prop_flavorW[] =
225 {'F','l','a','v','o','r',0};
226 static const WCHAR prop_freespaceW[] =
227 {'F','r','e','e','S','p','a','c','e',0};
228 static const WCHAR prop_handleW[] =
229 {'H','a','n','d','l','e',0};
230 static const WCHAR prop_horizontalresolutionW[] =
231 {'H','o','r','i','z','o','n','t','a','l','R','e','s','o','l','u','t','i','o','n',0};
232 static const WCHAR prop_idW[] =
233 {'I','D',0};
234 static const WCHAR prop_identificationcodeW[] =
235 {'I','d','e','n','t','i','f','i','c','a','t','i','o','n','C','o','d','e',0};
236 static const WCHAR prop_identifyingnumberW[] =
237 {'I','d','e','n','t','i','f','y','i','n','g','N','u','m','b','e','r',0};
238 static const WCHAR prop_indexW[] =
239 {'I','n','d','e','x',0};
240 static const WCHAR prop_installdateW[] =
241 {'I','n','s','t','a','l','l','D','a','t','e',0};
242 static const WCHAR prop_interfaceindexW[] =
243 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
244 static const WCHAR prop_interfacetypeW[] =
245 {'I','n','t','e','r','f','a','c','e','T','y','p','e',0};
246 static const WCHAR prop_intvalueW[] =
247 {'I','n','t','e','g','e','r','V','a','l','u','e',0};
248 static const WCHAR prop_ipconnectionmetricW[] =
249 {'I','P','C','o','n','n','e','c','t','i','o','n','M','e','t','r','i','c',0};
250 static const WCHAR prop_ipenabledW[] =
251 {'I','P','E','n','a','b','l','e','d',0};
252 static const WCHAR prop_lastbootuptimeW[] =
253 {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
254 static const WCHAR prop_localW[] =
255 {'L','o','c','a','l',0};
256 static const WCHAR prop_localdatetimeW[] =
257 {'L','o','c','a','l','D','a','t','e','T','i','m','e',0};
258 static const WCHAR prop_localeW[] =
259 {'L','o','c','a','l','e',0};
260 static const WCHAR prop_lockpresentW[] =
261 {'L','o','c','k','P','r','e','s','e','n','t',0};
262 static const WCHAR prop_macaddressW[] =
263 {'M','A','C','A','d','d','r','e','s','s',0};
264 static const WCHAR prop_manufacturerW[] =
265 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
266 static const WCHAR prop_maxclockspeedW[] =
267 {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
268 static const WCHAR prop_mediatypeW[] =
269 {'M','e','d','i','a','T','y','p','e',0};
270 static const WCHAR prop_memberW[] =
271 {'M','e','m','b','e','r',0};
272 static const WCHAR prop_memorytypeW[] =
273 {'M','e','m','o','r','y','T','y','p','e',0};
274 static const WCHAR prop_methodW[] =
275 {'M','e','t','h','o','d',0};
276 static const WCHAR prop_modelW[] =
277 {'M','o','d','e','l',0};
278 static const WCHAR prop_netconnectionstatusW[] =
279 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
280 static const WCHAR prop_networkW[] =
281 {'N','e','t','w','o','r','k',0};
282 static const WCHAR prop_nexthopW[] =
283 {'N','e','x','t','H','o','p',0};
284 static const WCHAR prop_numcoresW[] =
285 {'N','u','m','b','e','r','O','f','C','o','r','e','s',0};
286 static const WCHAR prop_numlogicalprocessorsW[] =
287 {'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};
288 static const WCHAR prop_numprocessorsW[] =
289 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
290 static const WCHAR prop_osarchitectureW[] =
291 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
292 static const WCHAR prop_oslanguageW[] =
293 {'O','S','L','a','n','g','u','a','g','e',0};
294 static const WCHAR prop_osproductsuiteW[] =
295 {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
296 static const WCHAR prop_ostypeW[] =
297 {'O','S','T','y','p','e',0};
298 static const WCHAR prop_parameterW[] =
299 {'P','a','r','a','m','e','t','e','r',0};
300 static const WCHAR prop_physicaladapterW[] =
301 {'P','h','y','s','i','c','a','l','A','d','a','p','t','e','r',0};
302 static const WCHAR prop_pixelsperxlogicalinchW[] =
303 {'P','i','x','e','l','s','P','e','r','X','L','o','g','i','c','a','l','I','n','c','h',0};
304 static const WCHAR prop_pnpdeviceidW[] =
305 {'P','N','P','D','e','v','i','c','e','I','D',0};
306 static const WCHAR prop_pprocessidW[] =
307 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
308 static const WCHAR prop_primaryW[] =
309 {'P','r','i','m','a','r','y',0};
310 static const WCHAR prop_processidW[] =
311 {'P','r','o','c','e','s','s','I','D',0};
312 static const WCHAR prop_processoridW[] =
313 {'P','r','o','c','e','s','s','o','r','I','d',0};
314 static const WCHAR prop_processortypeW[] =
315 {'P','r','o','c','e','s','s','o','r','T','y','p','e',0};
316 static const WCHAR prop_productW[] =
317 {'P','r','o','d','u','c','t',0};
318 static const WCHAR prop_productnameW[] =
319 {'P','r','o','d','u','c','t','N','a','m','e',0};
320 static const WCHAR prop_referenceddomainnameW[] =
321 {'R','e','f','e','r','e','n','c','e','d','D','o','m','a','i','n','N','a','m','e',0};
322 static const WCHAR prop_releasedateW[] =
323 {'R','e','l','e','a','s','e','D','a','t','e',0};
324 static const WCHAR prop_serialnumberW[] =
325 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
326 static const WCHAR prop_servicepackmajorW[] =
327 {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
328 static const WCHAR prop_servicepackminorW[] =
329 {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
330 static const WCHAR prop_servicetypeW[] =
331 {'S','e','r','v','i','c','e','T','y','p','e',0};
332 static const WCHAR prop_settingidW[] =
333 {'S','e','t','t','i','n','g','I','D',0};
334 static const WCHAR prop_smbiosbiosversionW[] =
335 {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
336 static const WCHAR prop_startmodeW[] =
337 {'S','t','a','r','t','M','o','d','e',0};
338 static const WCHAR prop_sidW[] =
339 {'S','I','D',0};
340 static const WCHAR prop_sidlengthW[] =
341 {'S','i','d','L','e','n','g','t','h',0};
342 static const WCHAR prop_sizeW[] =
343 {'S','i','z','e',0};
344 static const WCHAR prop_speedW[] =
345 {'S','p','e','e','d',0};
346 static const WCHAR prop_startingoffsetW[] =
347 {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0};
348 static const WCHAR prop_stateW[] =
349 {'S','t','a','t','e',0};
350 static const WCHAR prop_statusinfoW[] =
351 {'S','t','a','t','u','s','I','n','f','o',0};
352 static const WCHAR prop_strvalueW[] =
353 {'S','t','r','i','n','g','V','a','l','u','e',0};
354 static const WCHAR prop_suitemaskW[] =
355 {'S','u','i','t','e','M','a','s','k',0};
356 static const WCHAR prop_systemdirectoryW[] =
357 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
358 static const WCHAR prop_systemnameW[] =
359 {'S','y','s','t','e','m','N','a','m','e',0};
360 static const WCHAR prop_tagW[] =
361 {'T','a','g',0};
362 static const WCHAR prop_threadcountW[] =
363 {'T','h','r','e','a','d','C','o','u','n','t',0};
364 static const WCHAR prop_totalphysicalmemoryW[] =
365 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
366 static const WCHAR prop_totalvirtualmemorysizeW[] =
367 {'T','o','t','a','l','V','i','r','t','u','a','l','M','e','m','o','r','y','S','i','z','e',0};
368 static const WCHAR prop_totalvisiblememorysizeW[] =
369 {'T','o','t','a','l','V','i','s','i','b','l','e','M','e','m','o','r','y','S','i','z','e',0};
370 static const WCHAR prop_typeW[] =
371 {'T','y','p','e',0};
372 static const WCHAR prop_uniqueidW[] =
373 {'U','n','i','q','u','e','I','d',0};
374 static const WCHAR prop_usernameW[] =
375 {'U','s','e','r','N','a','m','e',0};
376 static const WCHAR prop_uuidW[] =
377 {'U','U','I','D',0};
378 static const WCHAR prop_varianttypeW[] =
379 {'V','a','r','i','a','n','t','T','y','p','e',0};
380 static const WCHAR prop_versionW[] =
381 {'V','e','r','s','i','o','n',0};
382 static const WCHAR prop_videoarchitectureW[] =
383 {'V','i','d','e','o','A','r','c','h','i','t','e','c','t','u','r','e',0};
384 static const WCHAR prop_videomemorytypeW[] =
385 {'V','i','d','e','o','M','e','m','o','r','y','T','y','p','e',0};
386 static const WCHAR prop_videomodedescriptionW[] =
387 {'V','i','d','e','o','M','o','d','e','D','e','s','c','r','i','p','t','i','o','n',0};
388 static const WCHAR prop_videoprocessorW[] =
389 {'V','i','d','e','o','P','r','o','c','e','s','s','o','r',0};
390 static const WCHAR prop_volumenameW[] =
391 {'V','o','l','u','m','e','N','a','m','e',0};
392 static const WCHAR prop_volumeserialnumberW[] =
393 {'V','o','l','u','m','e','S','e','r','i','a','l','N','u','m','b','e','r',0};
394 static const WCHAR prop_workingsetsizeW[] =
395 {'W','o','r','k','i','n','g','S','e','t','S','i','z','e',0};
397 /* column definitions must be kept in sync with record structures below */
398 static const struct column col_baseboard[] =
400 { prop_manufacturerW, CIM_STRING },
401 { prop_modelW, CIM_STRING },
402 { prop_nameW, CIM_STRING },
403 { prop_productW, CIM_STRING },
404 { prop_serialnumberW, CIM_STRING },
405 { prop_tagW, CIM_STRING|COL_FLAG_KEY },
406 { prop_versionW, CIM_STRING }
408 static const struct column col_bios[] =
410 { prop_descriptionW, CIM_STRING },
411 { prop_identificationcodeW, CIM_STRING },
412 { prop_manufacturerW, CIM_STRING },
413 { prop_nameW, CIM_STRING },
414 { prop_releasedateW, CIM_DATETIME },
415 { prop_serialnumberW, CIM_STRING },
416 { prop_smbiosbiosversionW, CIM_STRING },
417 { prop_versionW, CIM_STRING|COL_FLAG_KEY }
419 static const struct column col_cdromdrive[] =
421 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
422 { prop_driveW, CIM_STRING|COL_FLAG_DYNAMIC },
423 { prop_mediatypeW, CIM_STRING },
424 { prop_nameW, CIM_STRING },
425 { prop_pnpdeviceidW, CIM_STRING }
427 static const struct column col_compsys[] =
429 { prop_descriptionW, CIM_STRING },
430 { prop_domainW, CIM_STRING },
431 { prop_domainroleW, CIM_UINT16, VT_I4 },
432 { prop_manufacturerW, CIM_STRING },
433 { prop_modelW, CIM_STRING },
434 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
435 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
436 { prop_numprocessorsW, CIM_UINT32, VT_I4 },
437 { prop_totalphysicalmemoryW, CIM_UINT64 },
438 { prop_usernameW, CIM_STRING|COL_FLAG_DYNAMIC }
440 static const struct column col_compsysproduct[] =
442 { prop_identifyingnumberW, CIM_STRING|COL_FLAG_KEY },
443 { prop_uuidW, CIM_STRING|COL_FLAG_DYNAMIC }
445 static const struct column col_datafile[] =
447 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
448 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
450 static const struct column col_desktopmonitor[] =
452 { prop_pixelsperxlogicalinchW, CIM_UINT32 }
454 static const struct column col_directory[] =
456 { prop_accessmaskW, CIM_UINT32 },
457 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
459 static const struct column col_diskdrive[] =
461 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
462 { prop_indexW, CIM_UINT32, VT_I4 },
463 { prop_interfacetypeW, CIM_STRING },
464 { prop_manufacturerW, CIM_STRING },
465 { prop_mediatypeW, CIM_STRING },
466 { prop_modelW, CIM_STRING },
467 { prop_pnpdeviceidW, CIM_STRING },
468 { prop_serialnumberW, CIM_STRING },
469 { prop_sizeW, CIM_UINT64 }
471 static const struct column col_diskpartition[] =
473 { prop_bootableW, CIM_BOOLEAN },
474 { prop_bootpartitionW, CIM_BOOLEAN },
475 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
476 { prop_diskindexW, CIM_UINT32, VT_I4 },
477 { prop_indexW, CIM_UINT32, VT_I4 },
478 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
479 { prop_sizeW, CIM_UINT64 },
480 { prop_startingoffsetW, CIM_UINT64 },
481 { prop_typeW, CIM_STRING|COL_FLAG_DYNAMIC }
483 static const struct column col_ip4routetable[] =
485 { prop_destinationW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
486 { prop_interfaceindexW, CIM_SINT32|COL_FLAG_KEY },
487 { prop_nexthopW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
489 static const struct column col_logicaldisk[] =
491 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
492 { prop_drivetypeW, CIM_UINT32, VT_I4 },
493 { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
494 { prop_freespaceW, CIM_UINT64 },
495 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
496 { prop_sizeW, CIM_UINT64 },
497 { prop_volumenameW, CIM_STRING|COL_FLAG_DYNAMIC },
498 { prop_volumeserialnumberW, CIM_STRING|COL_FLAG_DYNAMIC }
500 static const struct column col_networkadapter[] =
502 { prop_adaptertypeW, CIM_STRING },
503 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
504 { prop_indexW, CIM_UINT32, VT_I4 },
505 { prop_interfaceindexW, CIM_UINT32, VT_I4 },
506 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
507 { prop_manufacturerW, CIM_STRING },
508 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
509 { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
510 { prop_physicaladapterW, CIM_BOOLEAN },
511 { prop_pnpdeviceidW, CIM_STRING },
512 { prop_speedW, CIM_UINT64 }
514 static const struct column col_networkadapterconfig[] =
516 { prop_defaultipgatewayW, CIM_STRING|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
517 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
518 { prop_dhcpenabledW, CIM_BOOLEAN },
519 { prop_dnshostnameW, CIM_STRING|COL_FLAG_DYNAMIC },
520 { prop_dnsserversearchorderW, CIM_STRING|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
521 { prop_indexW, CIM_UINT32|COL_FLAG_KEY, VT_I4 },
522 { prop_ipconnectionmetricW, CIM_UINT32, VT_I4 },
523 { prop_ipenabledW, CIM_BOOLEAN },
524 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
525 { prop_settingidW, CIM_STRING|COL_FLAG_DYNAMIC }
527 static const struct column col_os[] =
529 { prop_buildnumberW, CIM_STRING|COL_FLAG_DYNAMIC },
530 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
531 { prop_codesetW, CIM_STRING|COL_FLAG_DYNAMIC },
532 { prop_countrycodeW, CIM_STRING|COL_FLAG_DYNAMIC },
533 { prop_csdversionW, CIM_STRING|COL_FLAG_DYNAMIC },
534 { prop_installdateW, CIM_DATETIME },
535 { prop_lastbootuptimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
536 { prop_localdatetimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
537 { prop_localeW, CIM_STRING|COL_FLAG_DYNAMIC },
538 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
539 { prop_osarchitectureW, CIM_STRING },
540 { prop_oslanguageW, CIM_UINT32, VT_I4 },
541 { prop_osproductsuiteW, CIM_UINT32, VT_I4 },
542 { prop_ostypeW, CIM_UINT16, VT_I4 },
543 { prop_primaryW, CIM_BOOLEAN },
544 { prop_serialnumberW, CIM_STRING },
545 { prop_servicepackmajorW, CIM_UINT16, VT_I4 },
546 { prop_servicepackminorW, CIM_UINT16, VT_I4 },
547 { prop_suitemaskW, CIM_UINT32, VT_I4 },
548 { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC },
549 { prop_totalvirtualmemorysizeW, CIM_UINT64 },
550 { prop_totalvisiblememorysizeW, CIM_UINT64 },
551 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
553 static const struct column col_param[] =
555 { prop_classW, CIM_STRING },
556 { prop_methodW, CIM_STRING },
557 { prop_directionW, CIM_SINT32 },
558 { prop_parameterW, CIM_STRING },
559 { prop_typeW, CIM_UINT32 },
560 { prop_varianttypeW, CIM_UINT32 },
561 { prop_defaultvalueW, CIM_UINT32 }
563 static const struct column col_physicalmedia[] =
565 { prop_serialnumberW, CIM_STRING },
566 { prop_tagW, CIM_STRING }
568 static const struct column col_physicalmemory[] =
570 { prop_capacityW, CIM_UINT64 },
571 { prop_memorytypeW, CIM_UINT16, VT_I4 }
573 static const struct column col_printer[] =
575 { prop_attributesW, CIM_UINT32 },
576 { prop_drivernameW, CIM_STRING|COL_FLAG_DYNAMIC },
577 { prop_horizontalresolutionW, CIM_UINT32 },
578 { prop_localW, CIM_BOOLEAN },
579 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
580 { prop_networkW, CIM_BOOLEAN }
582 static const struct column col_process[] =
584 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
585 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
586 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
587 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
588 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
589 { prop_pprocessidW, CIM_UINT32, VT_I4 },
590 { prop_processidW, CIM_UINT32, VT_I4 },
591 { prop_threadcountW, CIM_UINT32, VT_I4 },
592 { prop_workingsetsizeW, CIM_UINT64 },
593 /* methods */
594 { method_getownerW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
596 static const struct column col_processor[] =
598 { prop_addresswidthW, CIM_UINT16, VT_I4 },
599 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
600 { prop_cpustatusW, CIM_UINT16 },
601 { prop_currentclockspeedW, CIM_UINT32, VT_I4 },
602 { prop_datawidthW, CIM_UINT16, VT_I4 },
603 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
604 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
605 { prop_familyW, CIM_UINT16, VT_I4 },
606 { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
607 { prop_maxclockspeedW, CIM_UINT32, VT_I4 },
608 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
609 { prop_numcoresW, CIM_UINT32, VT_I4 },
610 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
611 { prop_processoridW, CIM_STRING|COL_FLAG_DYNAMIC },
612 { prop_processortypeW, CIM_UINT16, VT_I4 },
613 { prop_uniqueidW, CIM_STRING },
614 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
616 static const struct column col_qualifier[] =
618 { prop_classW, CIM_STRING },
619 { prop_memberW, CIM_STRING },
620 { prop_typeW, CIM_UINT32 },
621 { prop_flavorW, CIM_SINT32 },
622 { prop_nameW, CIM_STRING },
623 { prop_intvalueW, CIM_SINT32 },
624 { prop_strvalueW, CIM_STRING }
626 static const struct column col_service[] =
628 { prop_acceptpauseW, CIM_BOOLEAN },
629 { prop_acceptstopW, CIM_BOOLEAN },
630 { prop_displaynameW, CIM_STRING|COL_FLAG_DYNAMIC },
631 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
632 { prop_processidW, CIM_UINT32 },
633 { prop_servicetypeW, CIM_STRING },
634 { prop_startmodeW, CIM_STRING },
635 { prop_stateW, CIM_STRING },
636 { prop_systemnameW, CIM_STRING|COL_FLAG_DYNAMIC },
637 /* methods */
638 { method_pauseserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
639 { method_resumeserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
640 { method_startserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
641 { method_stopserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
643 static const struct column col_sid[] =
645 { prop_accountnameW, CIM_STRING|COL_FLAG_DYNAMIC },
646 { prop_binaryrepresentationW, CIM_UINT8|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
647 { prop_referenceddomainnameW, CIM_STRING|COL_FLAG_DYNAMIC },
648 { prop_sidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
649 { prop_sidlengthW, CIM_UINT32 }
651 static const struct column col_sounddevice[] =
653 { prop_nameW, CIM_STRING },
654 { prop_productnameW, CIM_STRING },
655 { prop_statusinfoW, CIM_UINT16, VT_I4 }
657 static const struct column col_stdregprov[] =
659 { method_enumkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
660 { method_enumvaluesW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
661 { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
663 static const struct column col_systemenclosure[] =
665 { prop_captionW, CIM_STRING },
666 { prop_chassistypesW, CIM_UINT16|CIM_FLAG_ARRAY, VT_I4|VT_ARRAY },
667 { prop_descriptionW, CIM_STRING },
668 { prop_lockpresentW, CIM_BOOLEAN },
669 { prop_manufacturerW, CIM_STRING },
670 { prop_nameW, CIM_STRING },
671 { prop_tagW, CIM_STRING },
673 static const struct column col_systemsecurity[] =
675 { method_getsdW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
676 { method_setsdW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
678 static const struct column col_videocontroller[] =
680 { prop_adapterdactypeW, CIM_STRING },
681 { prop_adapterramW, CIM_UINT32, VT_I4 },
682 { prop_availabilityW, CIM_UINT16 },
683 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
684 { prop_currentbitsperpixelW, CIM_UINT32, VT_I4 },
685 { prop_currenthorizontalresW, CIM_UINT32, VT_I4 },
686 { prop_currentrefreshrateW, CIM_UINT32, VT_I4 },
687 { prop_currentscanmodeW, CIM_UINT16, VT_I4 },
688 { prop_currentverticalresW, CIM_UINT32, VT_I4 },
689 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
690 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
691 { prop_driverversionW, CIM_STRING },
692 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
693 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
694 { prop_videoarchitectureW, CIM_UINT16, VT_I4 },
695 { prop_videomemorytypeW, CIM_UINT16, VT_I4 },
696 { prop_videomodedescriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
697 { prop_videoprocessorW, CIM_STRING|COL_FLAG_DYNAMIC }
700 static const WCHAR baseboard_manufacturerW[] =
701 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
702 static const WCHAR baseboard_serialnumberW[] =
703 {'N','o','n','e',0};
704 static const WCHAR baseboard_tagW[] =
705 {'B','a','s','e',' ','B','o','a','r','d',0};
706 static const WCHAR baseboard_versionW[] =
707 {'1','.','0',0};
708 static const WCHAR bios_descriptionW[] =
709 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
710 static const WCHAR bios_manufacturerW[] =
711 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
712 static const WCHAR bios_nameW[] =
713 {'W','I','N','E',' ','B','I','O','S',0};
714 static const WCHAR bios_releasedateW[] =
715 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
716 static const WCHAR bios_serialnumberW[] =
717 {'0',0};
718 static const WCHAR bios_smbiosbiosversionW[] =
719 {'W','i','n','e',0};
720 static const WCHAR bios_versionW[] =
721 {'W','I','N','E',' ',' ',' ','-',' ','1',0};
722 static const WCHAR cdromdrive_mediatypeW[] =
723 {'C','D','-','R','O','M',0};
724 static const WCHAR cdromdrive_nameW[] =
725 {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
726 static const WCHAR cdromdrive_pnpdeviceidW[]=
727 {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
728 '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
729 '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
730 'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
731 static const WCHAR compsys_descriptionW[] =
732 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
733 static const WCHAR compsys_domainW[] =
734 {'W','O','R','K','G','R','O','U','P',0};
735 static const WCHAR compsys_manufacturerW[] =
736 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
737 static const WCHAR compsys_modelW[] =
738 {'W','i','n','e',0};
739 static const WCHAR compsysproduct_identifyingnumberW[] =
740 {'0',0};
741 static const WCHAR compsysproduct_uuidW[] =
742 {'d','e','a','d','d','e','a','d','-','d','e','a','d','-','d','e','a','d','-','d','e','a','d','-',
743 'd','e','a','d','d','e','a','d','d','e','a','d',0};
744 static const WCHAR diskdrive_interfacetypeW[] =
745 {'I','D','E',0};
746 static const WCHAR diskdrive_manufacturerW[] =
747 {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
748 static const WCHAR diskdrive_mediatype_fixedW[] =
749 {'F','i','x','e','d',' ','h','a','r','d',' ','d','i','s','k',0};
750 static const WCHAR diskdrive_mediatype_removableW[] =
751 {'R','e','m','o','v','a','b','l','e',' ','m','e','d','i','a',0};
752 static const WCHAR diskdrive_modelW[] =
753 {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
754 static const WCHAR diskdrive_pnpdeviceidW[] =
755 {'I','D','E','\\','D','i','s','k','\\','V','E','N','_','W','I','N','E',0};
756 static const WCHAR diskdrive_serialW[] =
757 {'W','I','N','E','H','D','I','S','K',0};
758 static const WCHAR networkadapter_pnpdeviceidW[]=
759 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
760 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
761 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
762 static const WCHAR os_32bitW[] =
763 {'3','2','-','b','i','t',0};
764 static const WCHAR os_64bitW[] =
765 {'6','4','-','b','i','t',0};
766 static const WCHAR os_installdateW[] =
767 {'2','0','1','4','0','1','0','1','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
768 static const WCHAR os_serialnumberW[] =
769 {'1','2','3','4','5','-','O','E','M','-','1','2','3','4','5','6','7','-','1','2','3','4','5',0};
770 static const WCHAR physicalmedia_tagW[] =
771 {'\\','\\','.','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
772 static const WCHAR sounddevice_productnameW[] =
773 {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
774 static const WCHAR systemenclosure_systemenclosureW[] =
775 {'S','y','s','t','e','m',' ','E','n','c','l','o','s','u','r','e',0};
776 static const WCHAR systemenclosure_tagW[] =
777 {'S','y','s','t','e','m',' ','E','n','c','l','o','s','u','r','e',' ','0',0};
778 static const WCHAR systemenclosure_manufacturerW[] =
779 {'W','i','n','e',0};
780 static const WCHAR videocontroller_dactypeW[] =
781 {'I','n','t','e','g','r','a','t','e','d',' ','R','A','M','D','A','C',0};
782 static const WCHAR videocontroller_deviceidW[] =
783 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
784 static const WCHAR videocontroller_driverversionW[] =
785 {'1','.','0',0};
787 #include "pshpack1.h"
788 struct record_baseboard
790 const WCHAR *manufacturer;
791 const WCHAR *model;
792 const WCHAR *name;
793 const WCHAR *product;
794 const WCHAR *serialnumber;
795 const WCHAR *tag;
796 const WCHAR *version;
798 struct record_bios
800 const WCHAR *description;
801 const WCHAR *identificationcode;
802 const WCHAR *manufacturer;
803 const WCHAR *name;
804 const WCHAR *releasedate;
805 const WCHAR *serialnumber;
806 const WCHAR *smbiosbiosversion;
807 const WCHAR *version;
809 struct record_cdromdrive
811 const WCHAR *device_id;
812 const WCHAR *drive;
813 const WCHAR *mediatype;
814 const WCHAR *name;
815 const WCHAR *pnpdevice_id;
817 struct record_computersystem
819 const WCHAR *description;
820 const WCHAR *domain;
821 UINT16 domainrole;
822 const WCHAR *manufacturer;
823 const WCHAR *model;
824 const WCHAR *name;
825 UINT32 num_logical_processors;
826 UINT32 num_processors;
827 UINT64 total_physical_memory;
828 const WCHAR *username;
830 struct record_computersystemproduct
832 const WCHAR *identifyingnumber;
833 const WCHAR *uuid;
835 struct record_datafile
837 const WCHAR *name;
838 const WCHAR *version;
840 struct record_desktopmonitor
842 UINT32 pixelsperxlogicalinch;
844 struct record_directory
846 UINT32 accessmask;
847 const WCHAR *name;
849 struct record_diskdrive
851 const WCHAR *device_id;
852 UINT32 index;
853 const WCHAR *interfacetype;
854 const WCHAR *manufacturer;
855 const WCHAR *mediatype;
856 const WCHAR *model;
857 const WCHAR *pnpdevice_id;
858 const WCHAR *serialnumber;
859 UINT64 size;
861 struct record_diskpartition
863 int bootable;
864 int bootpartition;
865 const WCHAR *device_id;
866 UINT32 diskindex;
867 UINT32 index;
868 const WCHAR *pnpdevice_id;
869 UINT64 size;
870 UINT64 startingoffset;
871 const WCHAR *type;
873 struct record_ip4routetable
875 const WCHAR *destination;
876 INT32 interfaceindex;
877 const WCHAR *nexthop;
879 struct record_logicaldisk
881 const WCHAR *device_id;
882 UINT32 drivetype;
883 const WCHAR *filesystem;
884 UINT64 freespace;
885 const WCHAR *name;
886 UINT64 size;
887 const WCHAR *volumename;
888 const WCHAR *volumeserialnumber;
890 struct record_networkadapter
892 const WCHAR *adaptertype;
893 const WCHAR *device_id;
894 UINT32 index;
895 UINT32 interface_index;
896 const WCHAR *mac_address;
897 const WCHAR *manufacturer;
898 const WCHAR *name;
899 UINT16 netconnection_status;
900 int physicaladapter;
901 const WCHAR *pnpdevice_id;
902 UINT64 speed;
904 struct record_networkadapterconfig
906 const struct array *defaultipgateway;
907 const WCHAR *description;
908 int dhcpenabled;
909 const WCHAR *dnshostname;
910 const struct array *dnsserversearchorder;
911 UINT32 index;
912 UINT32 ipconnectionmetric;
913 int ipenabled;
914 const WCHAR *mac_address;
915 const WCHAR *settingid;
917 struct record_operatingsystem
919 const WCHAR *buildnumber;
920 const WCHAR *caption;
921 const WCHAR *codeset;
922 const WCHAR *countrycode;
923 const WCHAR *csdversion;
924 const WCHAR *installdate;
925 const WCHAR *lastbootuptime;
926 const WCHAR *localdatetime;
927 const WCHAR *locale;
928 const WCHAR *name;
929 const WCHAR *osarchitecture;
930 UINT32 oslanguage;
931 UINT32 osproductsuite;
932 UINT16 ostype;
933 int primary;
934 const WCHAR *serialnumber;
935 UINT16 servicepackmajor;
936 UINT16 servicepackminor;
937 UINT32 suitemask;
938 const WCHAR *systemdirectory;
939 UINT64 totalvirtualmemorysize;
940 UINT64 totalvisiblememorysize;
941 const WCHAR *version;
943 struct record_param
945 const WCHAR *class;
946 const WCHAR *method;
947 INT32 direction;
948 const WCHAR *parameter;
949 UINT32 type;
950 UINT32 varianttype;
951 UINT32 defaultvalue;
953 struct record_physicalmedia
955 const WCHAR *serialnumber;
956 const WCHAR *tag;
958 struct record_physicalmemory
960 UINT64 capacity;
961 UINT16 memorytype;
963 struct record_printer
965 UINT32 attributes;
966 const WCHAR *drivername;
967 UINT32 horizontalresolution;
968 int local;
969 const WCHAR *name;
970 int network;
972 struct record_process
974 const WCHAR *caption;
975 const WCHAR *commandline;
976 const WCHAR *description;
977 const WCHAR *handle;
978 const WCHAR *name;
979 UINT32 pprocess_id;
980 UINT32 process_id;
981 UINT32 thread_count;
982 UINT64 workingsetsize;
983 /* methods */
984 class_method *get_owner;
986 struct record_processor
988 UINT16 addresswidth;
989 const WCHAR *caption;
990 UINT16 cpu_status;
991 UINT32 currentclockspeed;
992 UINT16 datawidth;
993 const WCHAR *description;
994 const WCHAR *device_id;
995 UINT16 family;
996 const WCHAR *manufacturer;
997 UINT32 maxclockspeed;
998 const WCHAR *name;
999 UINT32 num_cores;
1000 UINT32 num_logical_processors;
1001 const WCHAR *processor_id;
1002 UINT16 processortype;
1003 const WCHAR *unique_id;
1004 const WCHAR *version;
1006 struct record_qualifier
1008 const WCHAR *class;
1009 const WCHAR *member;
1010 UINT32 type;
1011 INT32 flavor;
1012 const WCHAR *name;
1013 INT32 intvalue;
1014 const WCHAR *strvalue;
1016 struct record_service
1018 int accept_pause;
1019 int accept_stop;
1020 const WCHAR *displayname;
1021 const WCHAR *name;
1022 UINT32 process_id;
1023 const WCHAR *servicetype;
1024 const WCHAR *startmode;
1025 const WCHAR *state;
1026 const WCHAR *systemname;
1027 /* methods */
1028 class_method *pause_service;
1029 class_method *resume_service;
1030 class_method *start_service;
1031 class_method *stop_service;
1033 struct record_sid
1035 const WCHAR *accountname;
1036 const struct array *binaryrepresentation;
1037 const WCHAR *referenceddomainname;
1038 const WCHAR *sid;
1039 UINT32 sidlength;
1041 struct record_sounddevice
1043 const WCHAR *name;
1044 const WCHAR *productname;
1045 UINT16 statusinfo;
1047 struct record_stdregprov
1049 class_method *enumkey;
1050 class_method *enumvalues;
1051 class_method *getstringvalue;
1053 struct record_systemsecurity
1055 class_method *getsd;
1056 class_method *setsd;
1058 struct record_systemenclosure
1060 const WCHAR *caption;
1061 const struct array *chassistypes;
1062 const WCHAR *description;
1063 int lockpresent;
1064 const WCHAR *manufacturer;
1065 const WCHAR *name;
1066 const WCHAR *tag;
1068 struct record_videocontroller
1070 const WCHAR *adapter_dactype;
1071 UINT32 adapter_ram;
1072 UINT16 availability;
1073 const WCHAR *caption;
1074 UINT32 current_bitsperpixel;
1075 UINT32 current_horizontalres;
1076 UINT32 current_refreshrate;
1077 UINT16 current_scanmode;
1078 UINT32 current_verticalres;
1079 const WCHAR *description;
1080 const WCHAR *device_id;
1081 const WCHAR *driverversion;
1082 const WCHAR *name;
1083 const WCHAR *pnpdevice_id;
1084 UINT16 videoarchitecture;
1085 UINT16 videomemorytype;
1086 const WCHAR *videomodedescription;
1087 const WCHAR *videoprocessor;
1089 #include "poppack.h"
1091 static const struct record_baseboard data_baseboard[] =
1093 { baseboard_manufacturerW, baseboard_tagW, baseboard_tagW, baseboard_tagW, baseboard_serialnumberW, baseboard_versionW }
1095 static const struct record_bios data_bios[] =
1097 { bios_descriptionW, NULL, bios_manufacturerW, bios_nameW, bios_releasedateW, bios_serialnumberW,
1098 bios_smbiosbiosversionW, bios_versionW }
1100 static const struct record_param data_param[] =
1102 { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1103 { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
1104 { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
1105 { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1106 { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1107 { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1108 { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1109 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
1110 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
1111 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1112 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
1113 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
1114 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
1115 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1116 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
1117 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
1118 { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
1119 { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
1120 { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
1121 { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1122 { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING },
1123 { class_systemsecurityW, method_getsdW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1124 { class_systemsecurityW, method_getsdW, -1, param_sdW, CIM_UINT8|CIM_FLAG_ARRAY },
1125 { class_systemsecurityW, method_setsdW, 1, param_sdW, CIM_UINT8|CIM_FLAG_ARRAY },
1126 { class_systemsecurityW, method_setsdW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1129 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
1130 WBEM_FLAVOR_ORIGIN_PROPAGATED)
1132 static const struct record_physicalmedia data_physicalmedia[] =
1134 { diskdrive_serialW, physicalmedia_tagW }
1136 static const struct record_qualifier data_qualifier[] =
1138 { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
1139 { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
1141 static const struct record_sounddevice data_sounddevice[] =
1143 { sounddevice_productnameW, sounddevice_productnameW, 3 /* enabled */ }
1145 static const struct record_stdregprov data_stdregprov[] =
1147 { reg_enum_key, reg_enum_values, reg_get_stringvalue }
1149 static UINT16 systemenclosure_chassistypes[] =
1153 static const struct array systemenclosure_chassistypes_array =
1155 SIZEOF(systemenclosure_chassistypes),
1156 &systemenclosure_chassistypes
1158 static const struct record_systemenclosure data_systemenclosure[] =
1161 systemenclosure_systemenclosureW,
1162 &systemenclosure_chassistypes_array,
1163 systemenclosure_systemenclosureW,
1164 FALSE,
1165 systemenclosure_manufacturerW,
1166 systemenclosure_systemenclosureW,
1167 systemenclosure_tagW,
1170 static const struct record_systemsecurity data_systemsecurity[] =
1172 { security_get_sd, security_set_sd }
1175 /* check if row matches condition and update status */
1176 static BOOL match_row( const struct table *table, UINT row, const struct expr *cond, enum fill_status *status )
1178 LONGLONG val;
1179 UINT type;
1181 if (!cond)
1183 *status = FILL_STATUS_UNFILTERED;
1184 return TRUE;
1186 if (eval_cond( table, row, cond, &val, &type ) != S_OK)
1188 *status = FILL_STATUS_FAILED;
1189 return FALSE;
1191 *status = FILL_STATUS_FILTERED;
1192 return val != 0;
1195 static BOOL resize_table( struct table *table, UINT row_count, UINT row_size )
1197 if (!table->num_rows_allocated)
1199 if (!(table->data = heap_alloc( row_count * row_size ))) return FALSE;
1200 table->num_rows_allocated = row_count;
1201 return TRUE;
1203 if (row_count > table->num_rows_allocated)
1205 BYTE *data;
1206 UINT count = max( row_count, table->num_rows_allocated * 2 );
1207 if (!(data = heap_realloc( table->data, count * row_size ))) return FALSE;
1208 table->data = data;
1209 table->num_rows_allocated = count;
1211 return TRUE;
1214 static enum fill_status fill_cdromdrive( struct table *table, const struct expr *cond )
1216 static const WCHAR fmtW[] = {'%','c',':',0};
1217 WCHAR drive[3], root[] = {'A',':','\\',0};
1218 struct record_cdromdrive *rec;
1219 UINT i, row = 0, offset = 0;
1220 DWORD drives = GetLogicalDrives();
1221 enum fill_status status = FILL_STATUS_UNFILTERED;
1223 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1225 for (i = 0; i < 26; i++)
1227 if (drives & (1 << i))
1229 root[0] = 'A' + i;
1230 if (GetDriveTypeW( root ) != DRIVE_CDROM)
1231 continue;
1233 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1235 rec = (struct record_cdromdrive *)(table->data + offset);
1236 rec->device_id = cdromdrive_pnpdeviceidW;
1237 sprintfW( drive, fmtW, 'A' + i );
1238 rec->drive = heap_strdupW( drive );
1239 rec->mediatype = cdromdrive_mediatypeW;
1240 rec->name = cdromdrive_nameW;
1241 rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
1242 if (!match_row( table, row, cond, &status ))
1244 free_row_values( table, row );
1245 continue;
1247 offset += sizeof(*rec);
1248 row++;
1251 TRACE("created %u rows\n", row);
1252 table->num_rows = row;
1253 return status;
1256 static UINT get_processor_count(void)
1258 SYSTEM_BASIC_INFORMATION info;
1260 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
1261 return info.NumberOfProcessors;
1264 static UINT get_logical_processor_count( UINT *num_cores )
1266 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
1267 UINT i, j, count = 0;
1268 NTSTATUS status;
1269 ULONG len;
1271 if (num_cores) *num_cores = get_processor_count();
1272 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
1273 if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
1275 if (!(info = heap_alloc( len ))) return get_processor_count();
1276 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
1277 if (status != STATUS_SUCCESS)
1279 heap_free( info );
1280 return get_processor_count();
1282 if (num_cores) *num_cores = 0;
1283 for (i = 0; i < len / sizeof(*info); i++)
1285 if (info[i].Relationship == RelationProcessorCore)
1287 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
1289 else if (info[i].Relationship == RelationProcessorPackage && num_cores)
1291 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) (*num_cores)++;
1294 heap_free( info );
1295 return count;
1298 static UINT64 get_total_physical_memory(void)
1300 MEMORYSTATUSEX status;
1302 status.dwLength = sizeof(status);
1303 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
1304 return status.ullTotalPhys;
1307 static WCHAR *get_computername(void)
1309 WCHAR *ret;
1310 DWORD size = MAX_COMPUTERNAME_LENGTH + 1;
1312 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
1313 GetComputerNameW( ret, &size );
1314 return ret;
1317 static WCHAR *get_username(void)
1319 WCHAR *ret;
1320 DWORD compsize, usersize;
1321 DWORD size;
1323 compsize = 0;
1324 GetComputerNameW( NULL, &compsize );
1325 usersize = 0;
1326 GetUserNameW( NULL, &usersize );
1327 size = compsize + usersize; /* two null terminators account for the \ */
1328 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
1329 GetComputerNameW( ret, &compsize );
1330 ret[compsize] = '\\';
1331 GetUserNameW( ret + compsize + 1, &usersize );
1332 return ret;
1335 static enum fill_status fill_compsys( struct table *table, const struct expr *cond )
1337 struct record_computersystem *rec;
1338 enum fill_status status = FILL_STATUS_UNFILTERED;
1339 UINT row = 0;
1341 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1343 rec = (struct record_computersystem *)table->data;
1344 rec->description = compsys_descriptionW;
1345 rec->domain = compsys_domainW;
1346 rec->domainrole = 0; /* standalone workstation */
1347 rec->manufacturer = compsys_manufacturerW;
1348 rec->model = compsys_modelW;
1349 rec->name = get_computername();
1350 rec->num_logical_processors = get_logical_processor_count( NULL );
1351 rec->num_processors = get_processor_count();
1352 rec->total_physical_memory = get_total_physical_memory();
1353 rec->username = get_username();
1354 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1355 else row++;
1357 TRACE("created %u rows\n", row);
1358 table->num_rows = row;
1359 return status;
1362 static WCHAR *get_compsysproduct_uuid(void)
1364 #ifdef __APPLE__
1365 unsigned char uuid[16];
1366 const struct timespec timeout = {1, 0};
1367 if (!gethostuuid( uuid, &timeout ))
1369 static const WCHAR fmtW[] =
1370 {'%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','-',
1371 '%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X',
1372 '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',0};
1373 WCHAR *ret = heap_alloc( 37 * sizeof(WCHAR) );
1374 if (!ret) return NULL;
1375 sprintfW( ret, fmtW, uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7],
1376 uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15] );
1377 return ret;
1379 #endif
1380 #ifdef __linux__
1381 int file;
1382 if ((file = open( "/var/lib/dbus/machine-id", O_RDONLY )) != -1)
1384 unsigned char buf[32];
1385 if (read( file, buf, sizeof(buf) ) == sizeof(buf))
1387 unsigned int i, j;
1388 WCHAR *ret, *p;
1390 close( file );
1391 if (!(p = ret = heap_alloc( 37 * sizeof(WCHAR) ))) return NULL;
1392 for (i = 0, j = 0; i < 8; i++) p[i] = toupperW( buf[j++] );
1393 p[8] = '-';
1394 for (i = 9; i < 13; i++) p[i] = toupperW( buf[j++] );
1395 p[13] = '-';
1396 for (i = 14; i < 18; i++) p[i] = toupperW( buf[j++] );
1397 p[18] = '-';
1398 for (i = 19; i < 23; i++) p[i] = toupperW( buf[j++] );
1399 p[23] = '-';
1400 for (i = 24; i < 36; i++) p[i] = toupperW( buf[j++] );
1401 ret[i] = 0;
1402 return ret;
1404 close( file );
1406 #endif
1407 return heap_strdupW( compsysproduct_uuidW );
1410 static enum fill_status fill_compsysproduct( struct table *table, const struct expr *cond )
1412 struct record_computersystemproduct *rec;
1413 enum fill_status status = FILL_STATUS_UNFILTERED;
1414 UINT row = 0;
1416 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1418 rec = (struct record_computersystemproduct *)table->data;
1419 rec->identifyingnumber = compsysproduct_identifyingnumberW;
1420 rec->uuid = get_compsysproduct_uuid();
1421 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1422 else row++;
1424 TRACE("created %u rows\n", row);
1425 table->num_rows = row;
1426 return status;
1429 struct dirstack
1431 WCHAR **dirs;
1432 UINT *len_dirs;
1433 UINT num_dirs;
1434 UINT num_allocated;
1437 static struct dirstack *alloc_dirstack( UINT size )
1439 struct dirstack *dirstack;
1441 if (!(dirstack = heap_alloc( sizeof(*dirstack) ))) return NULL;
1442 if (!(dirstack->dirs = heap_alloc( sizeof(WCHAR *) * size )))
1444 heap_free( dirstack );
1445 return NULL;
1447 if (!(dirstack->len_dirs = heap_alloc( sizeof(UINT) * size )))
1449 heap_free( dirstack->dirs );
1450 heap_free( dirstack );
1451 return NULL;
1453 dirstack->num_dirs = 0;
1454 dirstack->num_allocated = size;
1455 return dirstack;
1458 static void clear_dirstack( struct dirstack *dirstack )
1460 UINT i;
1461 for (i = 0; i < dirstack->num_dirs; i++) heap_free( dirstack->dirs[i] );
1462 dirstack->num_dirs = 0;
1465 static void free_dirstack( struct dirstack *dirstack )
1467 clear_dirstack( dirstack );
1468 heap_free( dirstack->dirs );
1469 heap_free( dirstack->len_dirs );
1470 heap_free( dirstack );
1473 static BOOL push_dir( struct dirstack *dirstack, WCHAR *dir, UINT len )
1475 UINT size, i = dirstack->num_dirs;
1477 if (!dir) return FALSE;
1479 if (i == dirstack->num_allocated)
1481 WCHAR **tmp;
1482 UINT *len_tmp;
1484 size = dirstack->num_allocated * 2;
1485 if (!(tmp = heap_realloc( dirstack->dirs, size * sizeof(WCHAR *) ))) return FALSE;
1486 dirstack->dirs = tmp;
1487 if (!(len_tmp = heap_realloc( dirstack->len_dirs, size * sizeof(UINT) ))) return FALSE;
1488 dirstack->len_dirs = len_tmp;
1489 dirstack->num_allocated = size;
1491 dirstack->dirs[i] = dir;
1492 dirstack->len_dirs[i] = len;
1493 dirstack->num_dirs++;
1494 return TRUE;
1497 static WCHAR *pop_dir( struct dirstack *dirstack, UINT *len )
1499 if (!dirstack->num_dirs)
1501 *len = 0;
1502 return NULL;
1504 dirstack->num_dirs--;
1505 *len = dirstack->len_dirs[dirstack->num_dirs];
1506 return dirstack->dirs[dirstack->num_dirs];
1509 static const WCHAR *peek_dir( struct dirstack *dirstack )
1511 if (!dirstack->num_dirs) return NULL;
1512 return dirstack->dirs[dirstack->num_dirs - 1];
1515 static WCHAR *build_glob( WCHAR drive, const WCHAR *path, UINT len )
1517 UINT i = 0;
1518 WCHAR *ret;
1520 if (!(ret = heap_alloc( (len + 6) * sizeof(WCHAR) ))) return NULL;
1521 ret[i++] = drive;
1522 ret[i++] = ':';
1523 ret[i++] = '\\';
1524 if (path && len)
1526 memcpy( ret + i, path, len * sizeof(WCHAR) );
1527 i += len;
1528 ret[i++] = '\\';
1530 ret[i++] = '*';
1531 ret[i] = 0;
1532 return ret;
1535 static WCHAR *build_name( WCHAR drive, const WCHAR *path )
1537 UINT i = 0, len = 0;
1538 const WCHAR *p;
1539 WCHAR *ret;
1541 for (p = path; *p; p++)
1543 if (*p == '\\') len += 2;
1544 else len++;
1546 if (!(ret = heap_alloc( (len + 5) * sizeof(WCHAR) ))) return NULL;
1547 ret[i++] = drive;
1548 ret[i++] = ':';
1549 ret[i++] = '\\';
1550 ret[i++] = '\\';
1551 for (p = path; *p; p++)
1553 if (*p != '\\') ret[i++] = *p;
1554 else
1556 ret[i++] = '\\';
1557 ret[i++] = '\\';
1560 ret[i] = 0;
1561 return ret;
1564 static WCHAR *build_dirname( const WCHAR *path, UINT *ret_len )
1566 const WCHAR *p = path, *start;
1567 UINT len, i;
1568 WCHAR *ret;
1570 if (!isalphaW( p[0] ) || p[1] != ':' || p[2] != '\\' || p[3] != '\\' || !p[4]) return NULL;
1571 start = path + 4;
1572 len = strlenW( start );
1573 p = start + len - 1;
1574 if (*p == '\\') return NULL;
1576 while (p >= start && *p != '\\') { len--; p--; };
1577 while (p >= start && *p == '\\') { len--; p--; };
1579 if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
1580 for (i = 0, p = start; p < start + len; p++)
1582 if (p[0] == '\\' && p[1] == '\\')
1584 ret[i++] = '\\';
1585 p++;
1587 else ret[i++] = *p;
1589 ret[i] = 0;
1590 *ret_len = i;
1591 return ret;
1594 static BOOL seen_dir( struct dirstack *dirstack, const WCHAR *path )
1596 UINT i;
1597 for (i = 0; i < dirstack->num_dirs; i++) if (!strcmpW( dirstack->dirs[i], path )) return TRUE;
1598 return FALSE;
1601 /* optimize queries of the form WHERE Name='...' [OR Name='...']* */
1602 static UINT seed_dirs( struct dirstack *dirstack, const struct expr *cond, WCHAR root, UINT *count )
1604 const struct expr *left, *right;
1606 if (!cond || cond->type != EXPR_COMPLEX) return *count = 0;
1608 left = cond->u.expr.left;
1609 right = cond->u.expr.right;
1610 if (cond->u.expr.op == OP_EQ)
1612 UINT len;
1613 WCHAR *path;
1614 const WCHAR *str = NULL;
1616 if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL &&
1617 !strcmpW( left->u.propval->name, prop_nameW ) &&
1618 toupperW( right->u.sval[0] ) == toupperW( root ))
1620 str = right->u.sval;
1622 else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL &&
1623 !strcmpW( right->u.propval->name, prop_nameW ) &&
1624 toupperW( left->u.sval[0] ) == toupperW( root ))
1626 str = left->u.sval;
1628 if (str && (path = build_dirname( str, &len )))
1630 if (seen_dir( dirstack, path ))
1632 heap_free( path );
1633 return ++*count;
1635 else if (push_dir( dirstack, path, len )) return ++*count;
1636 heap_free( path );
1637 return *count = 0;
1640 else if (cond->u.expr.op == OP_OR)
1642 UINT left_count = 0, right_count = 0;
1644 if (!(seed_dirs( dirstack, left, root, &left_count ))) return *count = 0;
1645 if (!(seed_dirs( dirstack, right, root, &right_count ))) return *count = 0;
1646 return *count += left_count + right_count;
1648 return *count = 0;
1651 static WCHAR *append_path( const WCHAR *path, const WCHAR *segment, UINT *len )
1653 UINT len_path = 0, len_segment = strlenW( segment );
1654 WCHAR *ret;
1656 *len = 0;
1657 if (path) len_path = strlenW( path );
1658 if (!(ret = heap_alloc( (len_path + len_segment + 2) * sizeof(WCHAR) ))) return NULL;
1659 if (path && len_path)
1661 memcpy( ret, path, len_path * sizeof(WCHAR) );
1662 ret[len_path] = '\\';
1663 *len += len_path + 1;
1665 memcpy( ret + *len, segment, len_segment * sizeof(WCHAR) );
1666 *len += len_segment;
1667 ret[*len] = 0;
1668 return ret;
1671 static WCHAR *get_file_version( const WCHAR *filename )
1673 static const WCHAR slashW[] = {'\\',0}, fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
1674 VS_FIXEDFILEINFO *info;
1675 DWORD size;
1676 void *block;
1677 WCHAR *ret;
1679 if (!(ret = heap_alloc( (4 * 5 + sizeof(fmtW) / sizeof(fmtW[0])) * sizeof(WCHAR) ))) return NULL;
1680 if (!(size = GetFileVersionInfoSizeW( filename, NULL )) || !(block = heap_alloc( size )))
1682 heap_free( ret );
1683 return NULL;
1685 if (!GetFileVersionInfoW( filename, 0, size, block ) ||
1686 !VerQueryValueW( block, slashW, (void **)&info, &size ))
1688 heap_free( block );
1689 heap_free( ret );
1690 return NULL;
1692 sprintfW( ret, fmtW, info->dwFileVersionMS >> 16, info->dwFileVersionMS & 0xffff,
1693 info->dwFileVersionLS >> 16, info->dwFileVersionLS & 0xffff );
1694 heap_free( block );
1695 return ret;
1698 static enum fill_status fill_datafile( struct table *table, const struct expr *cond )
1700 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1701 struct record_datafile *rec;
1702 UINT i, len, row = 0, offset = 0, num_expected_rows;
1703 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1704 DWORD drives = GetLogicalDrives();
1705 WIN32_FIND_DATAW data;
1706 HANDLE handle;
1707 struct dirstack *dirstack;
1708 enum fill_status status = FILL_STATUS_UNFILTERED;
1710 if (!resize_table( table, 8, sizeof(*rec) )) return FILL_STATUS_FAILED;
1712 dirstack = alloc_dirstack(2);
1714 for (i = 0; i < 26; i++)
1716 if (!(drives & (1 << i))) continue;
1718 root[0] = 'A' + i;
1719 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1721 num_expected_rows = 0;
1722 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1724 for (;;)
1726 heap_free( glob );
1727 heap_free( path );
1728 path = pop_dir( dirstack, &len );
1729 if (!(glob = build_glob( root[0], path, len )))
1731 status = FILL_STATUS_FAILED;
1732 goto done;
1734 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1738 if (!resize_table( table, row + 1, sizeof(*rec) ))
1740 status = FILL_STATUS_FAILED;
1741 FindClose( handle );
1742 goto done;
1744 if (!strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW )) continue;
1745 new_path = append_path( path, data.cFileName, &len );
1747 if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1749 if (push_dir( dirstack, new_path, len )) continue;
1750 heap_free( new_path );
1751 FindClose( handle );
1752 status = FILL_STATUS_FAILED;
1753 goto done;
1755 rec = (struct record_datafile *)(table->data + offset);
1756 rec->name = build_name( root[0], new_path );
1757 rec->version = get_file_version( rec->name );
1758 if (!match_row( table, row, cond, &status ))
1760 free_row_values( table, row );
1761 continue;
1763 else if (num_expected_rows && row == num_expected_rows - 1)
1765 row++;
1766 FindClose( handle );
1767 status = FILL_STATUS_FILTERED;
1768 goto done;
1770 offset += sizeof(*rec);
1771 row++;
1773 while (FindNextFileW( handle, &data ));
1774 FindClose( handle );
1776 if (!peek_dir( dirstack )) break;
1780 done:
1781 free_dirstack( dirstack );
1782 heap_free( glob );
1783 heap_free( path );
1785 TRACE("created %u rows\n", row);
1786 table->num_rows = row;
1787 return status;
1790 static UINT32 get_pixelsperxlogicalinch(void)
1792 HDC hdc = GetDC( NULL );
1793 UINT32 ret;
1795 if (!hdc) return 96;
1796 ret = GetDeviceCaps( hdc, LOGPIXELSX );
1797 ReleaseDC( NULL, hdc );
1798 return ret;
1801 static enum fill_status fill_desktopmonitor( struct table *table, const struct expr *cond )
1803 struct record_desktopmonitor *rec;
1804 enum fill_status status = FILL_STATUS_UNFILTERED;
1805 UINT row = 0;
1807 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1809 rec = (struct record_desktopmonitor *)table->data;
1810 rec->pixelsperxlogicalinch = get_pixelsperxlogicalinch();
1812 if (match_row( table, row, cond, &status )) row++;
1814 TRACE("created %u rows\n", row);
1815 table->num_rows = row;
1816 return status;
1819 static enum fill_status fill_directory( struct table *table, const struct expr *cond )
1821 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1822 struct record_directory *rec;
1823 UINT i, len, row = 0, offset = 0, num_expected_rows;
1824 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1825 DWORD drives = GetLogicalDrives();
1826 WIN32_FIND_DATAW data;
1827 HANDLE handle;
1828 struct dirstack *dirstack;
1829 enum fill_status status = FILL_STATUS_UNFILTERED;
1831 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1833 dirstack = alloc_dirstack(2);
1835 for (i = 0; i < 26; i++)
1837 if (!(drives & (1 << i))) continue;
1839 root[0] = 'A' + i;
1840 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1842 num_expected_rows = 0;
1843 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1845 for (;;)
1847 heap_free( glob );
1848 heap_free( path );
1849 path = pop_dir( dirstack, &len );
1850 if (!(glob = build_glob( root[0], path, len )))
1852 status = FILL_STATUS_FAILED;
1853 goto done;
1855 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1859 if (!resize_table( table, row + 1, sizeof(*rec) ))
1861 FindClose( handle );
1862 status = FILL_STATUS_FAILED;
1863 goto done;
1865 if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1866 !strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW ))
1867 continue;
1869 new_path = append_path( path, data.cFileName, &len );
1870 if (!(push_dir( dirstack, new_path, len )))
1872 heap_free( new_path );
1873 FindClose( handle );
1874 status = FILL_STATUS_FAILED;
1875 goto done;
1877 rec = (struct record_directory *)(table->data + offset);
1878 rec->accessmask = FILE_ALL_ACCESS;
1879 rec->name = build_name( root[0], new_path );
1880 if (!match_row( table, row, cond, &status ))
1882 free_row_values( table, row );
1883 continue;
1885 else if (num_expected_rows && row == num_expected_rows - 1)
1887 row++;
1888 FindClose( handle );
1889 status = FILL_STATUS_FILTERED;
1890 goto done;
1892 offset += sizeof(*rec);
1893 row++;
1895 while (FindNextFileW( handle, &data ));
1896 FindClose( handle );
1898 if (!peek_dir( dirstack )) break;
1902 done:
1903 free_dirstack( dirstack );
1904 heap_free( glob );
1905 heap_free( path );
1907 TRACE("created %u rows\n", row);
1908 table->num_rows = row;
1909 return status;
1912 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
1914 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
1915 ULARGE_INTEGER free;
1916 DISK_GEOMETRY_EX info;
1917 HANDLE handle;
1918 DWORD bytes_returned;
1920 free.QuadPart = 512 * 1024 * 1024;
1921 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
1923 root[4] = dir[0];
1924 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
1925 if (handle != INVALID_HANDLE_VALUE)
1927 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), &bytes_returned, NULL ))
1928 *disksize = info.DiskSize.QuadPart;
1929 CloseHandle( handle );
1931 return free.QuadPart;
1934 static enum fill_status fill_diskdrive( struct table *table, const struct expr *cond )
1936 static const WCHAR fmtW[] =
1937 {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','%','u',0};
1938 WCHAR device_id[sizeof(fmtW)/sizeof(fmtW[0]) + 10], root[] = {'A',':','\\',0};
1939 struct record_diskdrive *rec;
1940 UINT i, row = 0, offset = 0, index = 0, type;
1941 UINT64 size = 1024 * 1024 * 1024;
1942 DWORD drives = GetLogicalDrives();
1943 enum fill_status status = FILL_STATUS_UNFILTERED;
1945 if (!resize_table( table, 2, sizeof(*rec) )) return FILL_STATUS_FAILED;
1947 for (i = 0; i < 26; i++)
1949 if (drives & (1 << i))
1951 root[0] = 'A' + i;
1952 type = GetDriveTypeW( root );
1953 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1954 continue;
1956 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1958 rec = (struct record_diskdrive *)(table->data + offset);
1959 sprintfW( device_id, fmtW, index );
1960 rec->device_id = heap_strdupW( device_id );
1961 rec->index = index;
1962 rec->interfacetype = diskdrive_interfacetypeW;
1963 rec->manufacturer = diskdrive_manufacturerW;
1964 if (type == DRIVE_FIXED)
1965 rec->mediatype = diskdrive_mediatype_fixedW;
1966 else
1967 rec->mediatype = diskdrive_mediatype_removableW;
1968 rec->model = diskdrive_modelW;
1969 rec->pnpdevice_id = diskdrive_pnpdeviceidW;
1970 rec->serialnumber = diskdrive_serialW;
1971 get_freespace( root, &size );
1972 rec->size = size;
1973 if (!match_row( table, row, cond, &status ))
1975 free_row_values( table, row );
1976 continue;
1978 offset += sizeof(*rec);
1979 index++;
1980 row++;
1983 TRACE("created %u rows\n", row);
1984 table->num_rows = row;
1985 return status;
1988 static WCHAR *get_filesystem( const WCHAR *root )
1990 static const WCHAR ntfsW[] = {'N','T','F','S',0};
1991 WCHAR buffer[MAX_PATH + 1];
1993 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
1994 return heap_strdupW( buffer );
1995 return heap_strdupW( ntfsW );
1998 static enum fill_status fill_diskpartition( struct table *table, const struct expr *cond )
2000 static const WCHAR fmtW[] =
2001 {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
2002 WCHAR device_id[32], root[] = {'A',':','\\',0};
2003 struct record_diskpartition *rec;
2004 UINT i, row = 0, offset = 0, type, index = 0;
2005 UINT64 size = 1024 * 1024 * 1024;
2006 DWORD drives = GetLogicalDrives();
2007 enum fill_status status = FILL_STATUS_UNFILTERED;
2009 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
2011 for (i = 0; i < 26; i++)
2013 if (drives & (1 << i))
2015 root[0] = 'A' + i;
2016 type = GetDriveTypeW( root );
2017 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
2018 continue;
2020 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2022 rec = (struct record_diskpartition *)(table->data + offset);
2023 rec->bootable = (i == 2) ? -1 : 0;
2024 rec->bootpartition = (i == 2) ? -1 : 0;
2025 sprintfW( device_id, fmtW, index );
2026 rec->device_id = heap_strdupW( device_id );
2027 rec->diskindex = index;
2028 rec->index = 0;
2029 rec->pnpdevice_id = heap_strdupW( device_id );
2030 get_freespace( root, &size );
2031 rec->size = size;
2032 rec->startingoffset = 0;
2033 rec->type = get_filesystem( root );
2034 if (!match_row( table, row, cond, &status ))
2036 free_row_values( table, row );
2037 continue;
2039 offset += sizeof(*rec);
2040 row++;
2041 index++;
2044 TRACE("created %u rows\n", row);
2045 table->num_rows = row;
2046 return status;
2049 static WCHAR *get_ip4_string( DWORD addr )
2051 static const WCHAR fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
2052 WCHAR *ret;
2054 if (!(ret = heap_alloc( sizeof("ddd.ddd.ddd.ddd") * sizeof(WCHAR) ))) return NULL;
2055 sprintfW( ret, fmtW, (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff );
2056 return ret;
2059 static enum fill_status fill_ip4routetable( struct table *table, const struct expr *cond )
2061 struct record_ip4routetable *rec;
2062 UINT i, row = 0, offset = 0, size = 0;
2063 MIB_IPFORWARDTABLE *forwards;
2064 enum fill_status status = FILL_STATUS_UNFILTERED;
2066 if (GetIpForwardTable( NULL, &size, TRUE ) != ERROR_INSUFFICIENT_BUFFER) return FILL_STATUS_FAILED;
2067 if (!(forwards = heap_alloc( size ))) return FILL_STATUS_FAILED;
2068 if (GetIpForwardTable( forwards, &size, TRUE ))
2070 heap_free( forwards );
2071 return FILL_STATUS_FAILED;
2073 if (!resize_table( table, max(forwards->dwNumEntries, 1), sizeof(*rec) ))
2075 heap_free( forwards );
2076 return FILL_STATUS_FAILED;
2079 for (i = 0; i < forwards->dwNumEntries; i++)
2081 rec = (struct record_ip4routetable *)(table->data + offset);
2083 rec->destination = get_ip4_string( ntohl(forwards->table[i].dwForwardDest) );
2084 rec->interfaceindex = forwards->table[i].dwForwardIfIndex;
2085 rec->nexthop = get_ip4_string( ntohl(forwards->table[i].dwForwardNextHop) );
2087 if (!match_row( table, row, cond, &status ))
2089 free_row_values( table, row );
2090 continue;
2092 offset += sizeof(*rec);
2093 row++;
2095 TRACE("created %u rows\n", row);
2096 table->num_rows = row;
2098 heap_free( forwards );
2099 return status;
2102 static WCHAR *get_volumename( const WCHAR *root )
2104 WCHAR buf[MAX_PATH + 1] = {0};
2105 GetVolumeInformationW( root, buf, sizeof(buf)/sizeof(buf[0]), NULL, NULL, NULL, NULL, 0 );
2106 return heap_strdupW( buf );
2108 static WCHAR *get_volumeserialnumber( const WCHAR *root )
2110 static const WCHAR fmtW[] = {'%','0','8','X',0};
2111 DWORD serial = 0;
2112 WCHAR buffer[9];
2114 GetVolumeInformationW( root, NULL, 0, &serial, NULL, NULL, NULL, 0 );
2115 sprintfW( buffer, fmtW, serial );
2116 return heap_strdupW( buffer );
2119 static enum fill_status fill_logicaldisk( struct table *table, const struct expr *cond )
2121 static const WCHAR fmtW[] = {'%','c',':',0};
2122 WCHAR device_id[3], root[] = {'A',':','\\',0};
2123 struct record_logicaldisk *rec;
2124 UINT i, row = 0, offset = 0, type;
2125 UINT64 size = 1024 * 1024 * 1024;
2126 DWORD drives = GetLogicalDrives();
2127 enum fill_status status = FILL_STATUS_UNFILTERED;
2129 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
2131 for (i = 0; i < 26; i++)
2133 if (drives & (1 << i))
2135 root[0] = 'A' + i;
2136 type = GetDriveTypeW( root );
2137 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
2138 continue;
2140 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2142 rec = (struct record_logicaldisk *)(table->data + offset);
2143 sprintfW( device_id, fmtW, 'A' + i );
2144 rec->device_id = heap_strdupW( device_id );
2145 rec->drivetype = type;
2146 rec->filesystem = get_filesystem( root );
2147 rec->freespace = get_freespace( root, &size );
2148 rec->name = heap_strdupW( device_id );
2149 rec->size = size;
2150 rec->volumename = get_volumename( root );
2151 rec->volumeserialnumber = get_volumeserialnumber( root );
2152 if (!match_row( table, row, cond, &status ))
2154 free_row_values( table, row );
2155 continue;
2157 offset += sizeof(*rec);
2158 row++;
2161 TRACE("created %u rows\n", row);
2162 table->num_rows = row;
2163 return status;
2166 static UINT16 get_connection_status( IF_OPER_STATUS status )
2168 switch (status)
2170 case IfOperStatusDown:
2171 return 0; /* Disconnected */
2172 case IfOperStatusUp:
2173 return 2; /* Connected */
2174 default:
2175 ERR("unhandled status %u\n", status);
2176 break;
2178 return 0;
2180 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
2182 static const WCHAR fmtW[] =
2183 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
2184 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
2185 WCHAR *ret;
2187 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
2188 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
2189 return ret;
2191 static const WCHAR *get_adaptertype( DWORD type, int *physical )
2193 static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
2194 static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
2195 static const WCHAR firewireW[] = {'1','3','9','4',0};
2196 static const WCHAR tunnelW[] = {'T','u','n','n','e','l',0};
2198 switch (type)
2200 case IF_TYPE_ETHERNET_CSMACD: *physical = -1; return ethernetW;
2201 case IF_TYPE_IEEE80211: *physical = -1; return wirelessW;
2202 case IF_TYPE_IEEE1394: *physical = -1; return firewireW;
2203 case IF_TYPE_TUNNEL: *physical = 0; return tunnelW;
2204 default: *physical = 0; return NULL;
2208 static enum fill_status fill_networkadapter( struct table *table, const struct expr *cond )
2210 static const WCHAR fmtW[] = {'%','u',0};
2211 WCHAR device_id[11];
2212 struct record_networkadapter *rec;
2213 IP_ADAPTER_ADDRESSES *aa, *buffer;
2214 UINT row = 0, offset = 0, count = 0;
2215 DWORD size = 0, ret;
2216 int physical;
2217 enum fill_status status = FILL_STATUS_UNFILTERED;
2219 ret = GetAdaptersAddresses( WS_AF_UNSPEC, 0, NULL, NULL, &size );
2220 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
2222 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
2223 if (GetAdaptersAddresses( WS_AF_UNSPEC, 0, NULL, buffer, &size ))
2225 heap_free( buffer );
2226 return FILL_STATUS_FAILED;
2228 for (aa = buffer; aa; aa = aa->Next)
2230 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
2232 if (!resize_table( table, count, sizeof(*rec) ))
2234 heap_free( buffer );
2235 return FILL_STATUS_FAILED;
2237 for (aa = buffer; aa; aa = aa->Next)
2239 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
2241 rec = (struct record_networkadapter *)(table->data + offset);
2242 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
2243 rec->adaptertype = get_adaptertype( aa->IfType, &physical );
2244 rec->device_id = heap_strdupW( device_id );
2245 rec->index = aa->u.s.IfIndex;
2246 rec->interface_index = aa->u.s.IfIndex;
2247 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
2248 rec->manufacturer = compsys_manufacturerW;
2249 rec->name = heap_strdupW( aa->FriendlyName );
2250 rec->netconnection_status = get_connection_status( aa->OperStatus );
2251 rec->physicaladapter = physical;
2252 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
2253 rec->speed = 1000000;
2254 if (!match_row( table, row, cond, &status ))
2256 free_row_values( table, row );
2257 continue;
2259 offset += sizeof(*rec);
2260 row++;
2262 TRACE("created %u rows\n", row);
2263 table->num_rows = row;
2265 heap_free( buffer );
2266 return status;
2269 static WCHAR *get_dnshostname( IP_ADAPTER_UNICAST_ADDRESS *addr )
2271 const SOCKET_ADDRESS *sa = &addr->Address;
2272 WCHAR buf[WS_NI_MAXHOST];
2274 if (!addr) return NULL;
2275 if (GetNameInfoW( sa->lpSockaddr, sa->iSockaddrLength, buf, sizeof(buf)/sizeof(buf[0]), NULL,
2276 0, WS_NI_NAMEREQD )) return NULL;
2277 return heap_strdupW( buf );
2279 static struct array *get_defaultipgateway( IP_ADAPTER_GATEWAY_ADDRESS *list )
2281 IP_ADAPTER_GATEWAY_ADDRESS *gateway;
2282 struct array *ret;
2283 ULONG buflen, i = 0, count = 0;
2284 WCHAR **ptr, buf[54]; /* max IPv6 address length */
2286 if (!list) return NULL;
2287 for (gateway = list; gateway; gateway = gateway->Next) count++;
2289 if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
2290 if (!(ptr = heap_alloc( sizeof(*ptr) * count )))
2292 heap_free( ret );
2293 return NULL;
2295 for (gateway = list; gateway; gateway = gateway->Next)
2297 buflen = sizeof(buf)/sizeof(buf[0]);
2298 if (WSAAddressToStringW( gateway->Address.lpSockaddr, gateway->Address.iSockaddrLength,
2299 NULL, buf, &buflen) || !(ptr[i++] = heap_strdupW( buf )))
2301 for (; i > 0; i--) heap_free( ptr[i - 1] );
2302 heap_free( ptr );
2303 heap_free( ret );
2304 return NULL;
2307 ret->count = count;
2308 ret->ptr = ptr;
2309 return ret;
2311 static struct array *get_dnsserversearchorder( IP_ADAPTER_DNS_SERVER_ADDRESS *list )
2313 IP_ADAPTER_DNS_SERVER_ADDRESS *server;
2314 struct array *ret;
2315 ULONG buflen, i = 0, count = 0;
2316 WCHAR **ptr, *p, buf[54]; /* max IPv6 address length */
2318 if (!list) return NULL;
2319 for (server = list; server; server = server->Next) count++;
2321 if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
2322 if (!(ptr = heap_alloc( sizeof(*ptr) * count )))
2324 heap_free( ret );
2325 return NULL;
2327 for (server = list; server; server = server->Next)
2329 buflen = sizeof(buf)/sizeof(buf[0]);
2330 if (WSAAddressToStringW( server->Address.lpSockaddr, server->Address.iSockaddrLength,
2331 NULL, buf, &buflen) || !(ptr[i++] = heap_strdupW( buf )))
2333 for (; i > 0; i--) heap_free( ptr[i - 1] );
2334 heap_free( ptr );
2335 heap_free( ret );
2336 return NULL;
2338 if ((p = strrchrW( ptr[i - 1], ':' ))) *p = 0;
2340 ret->count = count;
2341 ret->ptr = ptr;
2342 return ret;
2344 static WCHAR *get_settingid( UINT32 index )
2346 GUID guid;
2347 WCHAR *ret, *str;
2348 memset( &guid, 0, sizeof(guid) );
2349 guid.Data1 = index;
2350 UuidToStringW( &guid, &str );
2351 ret = heap_strdupW( str );
2352 RpcStringFreeW( &str );
2353 return ret;
2356 static enum fill_status fill_networkadapterconfig( struct table *table, const struct expr *cond )
2358 struct record_networkadapterconfig *rec;
2359 IP_ADAPTER_ADDRESSES *aa, *buffer;
2360 UINT row = 0, offset = 0, count = 0;
2361 DWORD size = 0, ret;
2362 enum fill_status status = FILL_STATUS_UNFILTERED;
2364 ret = GetAdaptersAddresses( WS_AF_UNSPEC, GAA_FLAG_INCLUDE_ALL_GATEWAYS, NULL, NULL, &size );
2365 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
2367 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
2368 if (GetAdaptersAddresses( WS_AF_UNSPEC, GAA_FLAG_INCLUDE_ALL_GATEWAYS, NULL, buffer, &size ))
2370 heap_free( buffer );
2371 return FILL_STATUS_FAILED;
2373 for (aa = buffer; aa; aa = aa->Next)
2375 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
2377 if (!resize_table( table, count, sizeof(*rec) ))
2379 heap_free( buffer );
2380 return FILL_STATUS_FAILED;
2382 for (aa = buffer; aa; aa = aa->Next)
2384 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
2386 rec = (struct record_networkadapterconfig *)(table->data + offset);
2387 rec->defaultipgateway = get_defaultipgateway( aa->FirstGatewayAddress );
2388 rec->description = heap_strdupW( aa->Description );
2389 rec->dhcpenabled = -1;
2390 rec->dnshostname = get_dnshostname( aa->FirstUnicastAddress );
2391 rec->dnsserversearchorder = get_dnsserversearchorder( aa->FirstDnsServerAddress );
2392 rec->index = aa->u.s.IfIndex;
2393 rec->ipconnectionmetric = 20;
2394 rec->ipenabled = -1;
2395 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
2396 rec->settingid = get_settingid( rec->index );
2397 if (!match_row( table, row, cond, &status ))
2399 free_row_values( table, row );
2400 continue;
2402 offset += sizeof(*rec);
2403 row++;
2405 TRACE("created %u rows\n", row);
2406 table->num_rows = row;
2408 heap_free( buffer );
2409 return status;
2412 static enum fill_status fill_physicalmemory( struct table *table, const struct expr *cond )
2414 struct record_physicalmemory *rec;
2415 enum fill_status status = FILL_STATUS_UNFILTERED;
2416 UINT row = 0;
2418 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2420 rec = (struct record_physicalmemory *)table->data;
2421 rec->capacity = get_total_physical_memory();
2422 rec->memorytype = 9; /* RAM */
2423 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2424 else row++;
2426 TRACE("created %u rows\n", row);
2427 table->num_rows = row;
2428 return status;
2431 static enum fill_status fill_printer( struct table *table, const struct expr *cond )
2433 struct record_printer *rec;
2434 enum fill_status status = FILL_STATUS_UNFILTERED;
2435 PRINTER_INFO_2W *info;
2436 DWORD i, offset = 0, count = 0, size = 0, num_rows = 0;
2438 EnumPrintersW( PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &size, &count );
2439 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return FILL_STATUS_FAILED;
2441 if (!(info = heap_alloc( size ))) return FILL_STATUS_FAILED;
2442 if (!EnumPrintersW( PRINTER_ENUM_LOCAL, NULL, 2, (BYTE *)info, size, &size, &count ))
2444 heap_free( info );
2445 return FILL_STATUS_FAILED;
2447 if (!resize_table( table, count, sizeof(*rec) ))
2449 heap_free( info );
2450 return FILL_STATUS_FAILED;
2453 for (i = 0; i < count; i++)
2455 rec = (struct record_printer *)(table->data + offset);
2456 rec->attributes = info[i].Attributes;
2457 rec->drivername = heap_strdupW( info[i].pDriverName );
2458 rec->horizontalresolution = info[i].pDevMode->u1.s1.dmPrintQuality;
2459 rec->local = -1;
2460 rec->name = heap_strdupW( info[i].pPrinterName );
2461 rec->network = 0;
2462 if (!match_row( table, i, cond, &status ))
2464 free_row_values( table, i );
2465 continue;
2467 offset += sizeof(*rec);
2468 num_rows++;
2470 TRACE("created %u rows\n", num_rows);
2471 table->num_rows = num_rows;
2473 heap_free( info );
2474 return status;
2477 static WCHAR *get_cmdline( DWORD process_id )
2479 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
2480 return NULL; /* FIXME handle different process case */
2483 static enum fill_status fill_process( struct table *table, const struct expr *cond )
2485 static const WCHAR fmtW[] = {'%','u',0};
2486 WCHAR handle[11];
2487 struct record_process *rec;
2488 PROCESSENTRY32W entry;
2489 HANDLE snap;
2490 enum fill_status status = FILL_STATUS_FAILED;
2491 UINT row = 0, offset = 0;
2493 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
2494 if (snap == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED;
2496 entry.dwSize = sizeof(entry);
2497 if (!Process32FirstW( snap, &entry )) goto done;
2498 if (!resize_table( table, 8, sizeof(*rec) )) goto done;
2502 if (!resize_table( table, row + 1, sizeof(*rec) )) goto done;
2504 rec = (struct record_process *)(table->data + offset);
2505 rec->caption = heap_strdupW( entry.szExeFile );
2506 rec->commandline = get_cmdline( entry.th32ProcessID );
2507 rec->description = heap_strdupW( entry.szExeFile );
2508 sprintfW( handle, fmtW, entry.th32ProcessID );
2509 rec->handle = heap_strdupW( handle );
2510 rec->name = heap_strdupW( entry.szExeFile );
2511 rec->process_id = entry.th32ProcessID;
2512 rec->pprocess_id = entry.th32ParentProcessID;
2513 rec->thread_count = entry.cntThreads;
2514 rec->workingsetsize = 0;
2515 rec->get_owner = process_get_owner;
2516 if (!match_row( table, row, cond, &status ))
2518 free_row_values( table, row );
2519 continue;
2521 offset += sizeof(*rec);
2522 row++;
2523 } while (Process32NextW( snap, &entry ));
2525 TRACE("created %u rows\n", row);
2526 table->num_rows = row;
2527 status = FILL_STATUS_UNFILTERED;
2529 done:
2530 CloseHandle( snap );
2531 return status;
2534 static inline void do_cpuid( unsigned int ax, unsigned int *p )
2536 #ifdef __i386__
2537 #ifdef _MSC_VER
2538 __cpuid(p, ax);
2539 #else
2540 __asm__("pushl %%ebx\n\t"
2541 "cpuid\n\t"
2542 "movl %%ebx, %%esi\n\t"
2543 "popl %%ebx"
2544 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
2545 : "0" (ax));
2546 #endif
2547 #endif
2549 static const WCHAR *get_osarchitecture(void)
2551 SYSTEM_INFO info;
2552 GetNativeSystemInfo( &info );
2553 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
2554 return os_32bitW;
2556 static void get_processor_caption( WCHAR *caption )
2558 static const WCHAR fmtW[] =
2559 {'%','s',' ','F','a','m','i','l','y',' ','%','u',' ',
2560 'M','o','d','e','l',' ','%','u',' ','S','t','e','p','p','i','n','g',' ','%','u',0};
2561 static const WCHAR x86W[] = {'x','8','6',0};
2562 static const WCHAR intel64W[] = {'I','n','t','e','l','6','4',0};
2563 const WCHAR *arch = (get_osarchitecture() == os_32bitW) ? x86W : intel64W;
2564 unsigned int regs[4] = {0, 0, 0, 0};
2566 do_cpuid( 1, regs );
2567 sprintfW( caption, fmtW, arch, (regs[0] & (15 << 8)) >> 8, (regs[0] & (15 << 4)) >> 4, regs[0] & 15 );
2569 static void get_processor_version( WCHAR *version )
2571 static const WCHAR fmtW[] =
2572 {'M','o','d','e','l',' ','%','u',',',' ','S','t','e','p','p','i','n','g',' ','%','u',0};
2573 unsigned int regs[4] = {0, 0, 0, 0};
2575 do_cpuid( 1, regs );
2576 sprintfW( version, fmtW, (regs[0] & (15 << 4)) >> 4, regs[0] & 15 );
2578 static void get_processor_id( WCHAR *processor_id )
2580 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
2581 unsigned int regs[4] = {0, 0, 0, 0};
2583 do_cpuid( 1, regs );
2584 sprintfW( processor_id, fmtW, regs[3], regs[0] );
2586 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
2588 unsigned int i;
2589 unsigned char *p = (unsigned char *)regs;
2591 for (i = 0; i < len; i++) { buffer[i] = *p++; }
2592 buffer[i] = 0;
2594 static void get_processor_manufacturer( WCHAR *manufacturer )
2596 unsigned int tmp, regs[4] = {0, 0, 0, 0};
2598 do_cpuid( 0, regs );
2599 tmp = regs[2]; /* swap edx and ecx */
2600 regs[2] = regs[3];
2601 regs[3] = tmp;
2603 regs_to_str( regs + 1, 12, manufacturer );
2605 static void get_processor_name( WCHAR *name )
2607 unsigned int regs[4] = {0, 0, 0, 0};
2609 do_cpuid( 0x80000000, regs );
2610 if (regs[0] >= 0x80000004)
2612 do_cpuid( 0x80000002, regs );
2613 regs_to_str( regs, 16, name );
2614 do_cpuid( 0x80000003, regs );
2615 regs_to_str( regs, 16, name + 16 );
2616 do_cpuid( 0x80000004, regs );
2617 regs_to_str( regs, 16, name + 32 );
2620 static UINT get_processor_currentclockspeed( UINT index )
2622 PROCESSOR_POWER_INFORMATION *info;
2623 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
2624 NTSTATUS status;
2626 if ((info = heap_alloc( size )))
2628 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
2629 if (!status) ret = info[index].CurrentMhz;
2630 heap_free( info );
2632 return ret;
2634 static UINT get_processor_maxclockspeed( UINT index )
2636 PROCESSOR_POWER_INFORMATION *info;
2637 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
2638 NTSTATUS status;
2640 if ((info = heap_alloc( size )))
2642 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
2643 if (!status) ret = info[index].MaxMhz;
2644 heap_free( info );
2646 return ret;
2649 static enum fill_status fill_processor( struct table *table, const struct expr *cond )
2651 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
2652 WCHAR caption[100], device_id[14], processor_id[17], manufacturer[13], name[49] = {0}, version[50];
2653 struct record_processor *rec;
2654 UINT i, offset = 0, num_rows = 0, num_cores, num_logical_processors, count = get_processor_count();
2655 enum fill_status status = FILL_STATUS_UNFILTERED;
2657 if (!resize_table( table, count, sizeof(*rec) )) return FILL_STATUS_FAILED;
2659 get_processor_caption( caption );
2660 get_processor_id( processor_id );
2661 get_processor_manufacturer( manufacturer );
2662 get_processor_name( name );
2663 get_processor_version( version );
2665 num_logical_processors = get_logical_processor_count( &num_cores ) / count;
2666 num_cores /= count;
2668 for (i = 0; i < count; i++)
2670 rec = (struct record_processor *)(table->data + offset);
2671 rec->addresswidth = get_osarchitecture() == os_32bitW ? 32 : 64;
2672 rec->caption = heap_strdupW( caption );
2673 rec->cpu_status = 1; /* CPU Enabled */
2674 rec->currentclockspeed = get_processor_currentclockspeed( i );
2675 rec->datawidth = get_osarchitecture() == os_32bitW ? 32 : 64;
2676 rec->description = heap_strdupW( caption );
2677 sprintfW( device_id, fmtW, i );
2678 rec->device_id = heap_strdupW( device_id );
2679 rec->family = 2; /* Unknown */
2680 rec->manufacturer = heap_strdupW( manufacturer );
2681 rec->maxclockspeed = get_processor_maxclockspeed( i );
2682 rec->name = heap_strdupW( name );
2683 rec->num_cores = num_cores;
2684 rec->num_logical_processors = num_logical_processors;
2685 rec->processor_id = heap_strdupW( processor_id );
2686 rec->processortype = 3; /* central processor */
2687 rec->unique_id = NULL;
2688 rec->version = heap_strdupW( version );
2689 if (!match_row( table, i, cond, &status ))
2691 free_row_values( table, i );
2692 continue;
2694 offset += sizeof(*rec);
2695 num_rows++;
2698 TRACE("created %u rows\n", num_rows);
2699 table->num_rows = num_rows;
2700 return status;
2703 static WCHAR *get_lastbootuptime(void)
2705 static const WCHAR fmtW[] =
2706 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
2707 '.','%','0','6','u','+','0','0','0',0};
2708 SYSTEM_TIMEOFDAY_INFORMATION ti;
2709 TIME_FIELDS tf;
2710 WCHAR *ret;
2712 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2714 NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
2715 RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
2716 sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
2717 return ret;
2719 static WCHAR *get_localdatetime(void)
2721 static const WCHAR fmtW[] =
2722 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
2723 '.','%','0','6','u','%','+','0','3','d',0};
2724 TIME_ZONE_INFORMATION tzi;
2725 SYSTEMTIME st;
2726 WCHAR *ret;
2727 DWORD Status;
2728 LONG Bias;
2730 Status = GetTimeZoneInformation(&tzi);
2732 if(Status == TIME_ZONE_ID_INVALID) return NULL;
2733 Bias = tzi.Bias;
2734 if(Status == TIME_ZONE_ID_DAYLIGHT)
2735 Bias+= tzi.DaylightBias;
2736 else
2737 Bias+= tzi.StandardBias;
2738 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2740 GetLocalTime(&st);
2741 sprintfW( ret, fmtW, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds * 1000, -Bias);
2742 return ret;
2744 static WCHAR *get_systemdirectory(void)
2746 void *redir;
2747 WCHAR *ret;
2749 if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
2750 Wow64DisableWow64FsRedirection( &redir );
2751 GetSystemDirectoryW( ret, MAX_PATH );
2752 Wow64RevertWow64FsRedirection( redir );
2753 return ret;
2755 static WCHAR *get_codeset(void)
2757 static const WCHAR fmtW[] = {'%','u',0};
2758 WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
2759 if (ret) sprintfW( ret, fmtW, GetACP() );
2760 return ret;
2762 static WCHAR *get_countrycode(void)
2764 WCHAR *ret = heap_alloc( 6 * sizeof(WCHAR) );
2765 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY, ret, 6 );
2766 return ret;
2768 static WCHAR *get_locale(void)
2770 WCHAR *ret = heap_alloc( 5 * sizeof(WCHAR) );
2771 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, ret, 5 );
2772 return ret;
2774 static WCHAR *get_osbuildnumber( OSVERSIONINFOEXW *ver )
2776 static const WCHAR fmtW[] = {'%','u',0};
2777 WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
2778 if (ret) sprintfW( ret, fmtW, ver->dwBuildNumber );
2779 return ret;
2781 static WCHAR *get_oscaption( OSVERSIONINFOEXW *ver )
2783 static const WCHAR windowsW[] =
2784 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' '};
2785 static const WCHAR win2000W[] =
2786 {'2','0','0','0',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
2787 static const WCHAR win2003W[] =
2788 {'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};
2789 static const WCHAR winxpW[] =
2790 {'X','P',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
2791 static const WCHAR winxp64W[] =
2792 {'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};
2793 static const WCHAR vistaW[] =
2794 {'V','i','s','t','a',' ','U','l','t','i','m','a','t','e',0};
2795 static const WCHAR win2008W[] =
2796 {'S','e','r','v','e','r',' ','2','0','0','8',' ','S','t','a','n','d','a','r','d',0};
2797 static const WCHAR win7W[] =
2798 {'7',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
2799 static const WCHAR win2008r2W[] =
2800 {'S','e','r','v','e','r',' ','2','0','0','8',' ','R','2',' ','S','t','a','n','d','a','r','d',0};
2801 static const WCHAR win8W[] =
2802 {'8',' ','P','r','o',0};
2803 static const WCHAR win81W[] =
2804 {'8','.','1',' ','P','r','o',0};
2805 static const WCHAR win10W[] =
2806 {'1','0',' ','P','r','o',0};
2807 int len = sizeof(windowsW)/sizeof(windowsW[0]);
2808 WCHAR *ret;
2810 if (!(ret = heap_alloc( len * sizeof(WCHAR) + sizeof(win2003W) ))) return NULL;
2811 memcpy( ret, windowsW, sizeof(windowsW) );
2812 if (ver->dwMajorVersion == 10 && ver->dwMinorVersion == 0) memcpy( ret + len, win10W, sizeof(win10W) );
2813 else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 3) memcpy( ret + len, win8W, sizeof(win8W) );
2814 else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 2) memcpy( ret + len, win81W, sizeof(win81W) );
2815 else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 1)
2817 if (ver->wProductType == VER_NT_WORKSTATION) memcpy( ret + len, win7W, sizeof(win7W) );
2818 else memcpy( ret + len, win2008r2W, sizeof(win2008r2W) );
2820 else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 0)
2822 if (ver->wProductType == VER_NT_WORKSTATION) memcpy( ret + len, vistaW, sizeof(vistaW) );
2823 else memcpy( ret + len, win2008W, sizeof(win2008W) );
2825 else if (ver->dwMajorVersion == 5 && ver->dwMinorVersion == 2)
2827 if (ver->wProductType == VER_NT_WORKSTATION) memcpy( ret + len, winxp64W, sizeof(winxp64W) );
2828 else memcpy( ret + len, win2003W, sizeof(win2003W) );
2830 else if (ver->dwMajorVersion == 5 && ver->dwMinorVersion == 1) memcpy( ret + len, winxpW, sizeof(winxpW) );
2831 else memcpy( ret + len, win2000W, sizeof(win2000W) );
2832 return ret;
2834 static WCHAR *get_osname( const WCHAR *caption )
2836 static const WCHAR partitionW[] =
2837 {'|','C',':','\\','W','I','N','D','O','W','S','|','\\','D','e','v','i','c','e','\\',
2838 'H','a','r','d','d','i','s','k','0','\\','P','a','r','t','i','t','i','o','n','1',0};
2839 int len = strlenW( caption );
2840 WCHAR *ret;
2842 if (!(ret = heap_alloc( len * sizeof(WCHAR) + sizeof(partitionW) ))) return NULL;
2843 memcpy( ret, caption, len * sizeof(WCHAR) );
2844 memcpy( ret + len, partitionW, sizeof(partitionW) );
2845 return ret;
2847 static WCHAR *get_osversion( OSVERSIONINFOEXW *ver )
2849 static const WCHAR fmtW[] = {'%','u','.','%','u','.','%','u',0};
2850 WCHAR *ret = heap_alloc( 33 * sizeof(WCHAR) );
2851 if (ret) sprintfW( ret, fmtW, ver->dwMajorVersion, ver->dwMinorVersion, ver->dwBuildNumber );
2852 return ret;
2855 static enum fill_status fill_os( struct table *table, const struct expr *cond )
2857 struct record_operatingsystem *rec;
2858 enum fill_status status = FILL_STATUS_UNFILTERED;
2859 OSVERSIONINFOEXW ver;
2860 UINT row = 0;
2862 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2864 ver.dwOSVersionInfoSize = sizeof(ver);
2865 GetVersionExW( (OSVERSIONINFOW *)&ver );
2867 rec = (struct record_operatingsystem *)table->data;
2868 rec->buildnumber = get_osbuildnumber( &ver );
2869 rec->caption = get_oscaption( &ver );
2870 rec->codeset = get_codeset();
2871 rec->countrycode = get_countrycode();
2872 rec->csdversion = ver.szCSDVersion[0] ? heap_strdupW( ver.szCSDVersion ) : NULL;
2873 rec->installdate = os_installdateW;
2874 rec->lastbootuptime = get_lastbootuptime();
2875 rec->localdatetime = get_localdatetime();
2876 rec->locale = get_locale();
2877 rec->name = get_osname( rec->caption );
2878 rec->osarchitecture = get_osarchitecture();
2879 rec->oslanguage = GetSystemDefaultLangID();
2880 rec->osproductsuite = 2461140; /* Windows XP Professional */
2881 rec->ostype = 18; /* WINNT */
2882 rec->primary = -1;
2883 rec->serialnumber = os_serialnumberW;
2884 rec->servicepackmajor = ver.wServicePackMajor;
2885 rec->servicepackminor = ver.wServicePackMinor;
2886 rec->suitemask = 272; /* Single User + Terminal */
2887 rec->systemdirectory = get_systemdirectory();
2888 rec->totalvirtualmemorysize = get_total_physical_memory() / 1024;
2889 rec->totalvisiblememorysize = rec->totalvirtualmemorysize;
2890 rec->version = get_osversion( &ver );
2891 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2892 else row++;
2894 TRACE("created %u rows\n", row);
2895 table->num_rows = row;
2896 return status;
2899 static const WCHAR *get_service_type( DWORD type )
2901 static const WCHAR filesystem_driverW[] =
2902 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
2903 static const WCHAR kernel_driverW[] =
2904 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
2905 static const WCHAR own_processW[] =
2906 {'O','w','n',' ','P','r','o','c','e','s','s',0};
2907 static const WCHAR share_processW[] =
2908 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
2910 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
2911 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
2912 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
2913 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
2914 else ERR("unhandled type 0x%08x\n", type);
2915 return NULL;
2917 static const WCHAR *get_service_state( DWORD state )
2919 static const WCHAR runningW[] =
2920 {'R','u','n','n','i','n','g',0};
2921 static const WCHAR start_pendingW[] =
2922 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
2923 static const WCHAR stop_pendingW[] =
2924 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
2925 static const WCHAR stoppedW[] =
2926 {'S','t','o','p','p','e','d',0};
2927 static const WCHAR unknownW[] =
2928 {'U','n','k','n','o','w','n',0};
2930 switch (state)
2932 case SERVICE_STOPPED: return stoppedW;
2933 case SERVICE_START_PENDING: return start_pendingW;
2934 case SERVICE_STOP_PENDING: return stop_pendingW;
2935 case SERVICE_RUNNING: return runningW;
2936 default:
2937 ERR("unknown state %u\n", state);
2938 return unknownW;
2941 static const WCHAR *get_service_startmode( DWORD mode )
2943 static const WCHAR bootW[] = {'B','o','o','t',0};
2944 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
2945 static const WCHAR autoW[] = {'A','u','t','o',0};
2946 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
2947 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
2948 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
2950 switch (mode)
2952 case SERVICE_BOOT_START: return bootW;
2953 case SERVICE_SYSTEM_START: return systemW;
2954 case SERVICE_AUTO_START: return autoW;
2955 case SERVICE_DEMAND_START: return manualW;
2956 case SERVICE_DISABLED: return disabledW;
2957 default:
2958 ERR("unknown mode 0x%x\n", mode);
2959 return unknownW;
2962 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
2964 QUERY_SERVICE_CONFIGW *config = NULL;
2965 SC_HANDLE service;
2966 DWORD size;
2968 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
2969 QueryServiceConfigW( service, NULL, 0, &size );
2970 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
2971 if (!(config = heap_alloc( size ))) goto done;
2972 if (QueryServiceConfigW( service, config, size, &size )) goto done;
2973 heap_free( config );
2974 config = NULL;
2976 done:
2977 CloseServiceHandle( service );
2978 return config;
2981 static enum fill_status fill_service( struct table *table, const struct expr *cond )
2983 struct record_service *rec;
2984 SC_HANDLE manager;
2985 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
2986 SERVICE_STATUS_PROCESS *status;
2987 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
2988 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
2989 UINT i, row = 0, offset = 0, size = 256, needed, count;
2990 enum fill_status fill_status = FILL_STATUS_FAILED;
2991 BOOL ret;
2993 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return FILL_STATUS_FAILED;
2994 if (!(services = heap_alloc( size ))) goto done;
2996 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2997 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2998 &count, NULL, NULL );
2999 if (!ret)
3001 if (GetLastError() != ERROR_MORE_DATA) goto done;
3002 size = needed;
3003 if (!(tmp = heap_realloc( services, size ))) goto done;
3004 services = tmp;
3005 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
3006 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
3007 &count, NULL, NULL );
3008 if (!ret) goto done;
3010 if (!resize_table( table, count, sizeof(*rec) )) goto done;
3012 GetComputerNameW( sysnameW, &len );
3013 fill_status = FILL_STATUS_UNFILTERED;
3015 for (i = 0; i < count; i++)
3017 QUERY_SERVICE_CONFIGW *config;
3019 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
3021 status = &services[i].ServiceStatusProcess;
3022 rec = (struct record_service *)(table->data + offset);
3023 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
3024 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
3025 rec->displayname = heap_strdupW( services[i].lpDisplayName );
3026 rec->name = heap_strdupW( services[i].lpServiceName );
3027 rec->process_id = status->dwProcessId;
3028 rec->servicetype = get_service_type( status->dwServiceType );
3029 rec->startmode = get_service_startmode( config->dwStartType );
3030 rec->state = get_service_state( status->dwCurrentState );
3031 rec->systemname = heap_strdupW( sysnameW );
3032 rec->pause_service = service_pause_service;
3033 rec->resume_service = service_resume_service;
3034 rec->start_service = service_start_service;
3035 rec->stop_service = service_stop_service;
3036 heap_free( config );
3037 if (!match_row( table, row, cond, &fill_status ))
3039 free_row_values( table, row );
3040 continue;
3042 offset += sizeof(*rec);
3043 row++;
3046 TRACE("created %u rows\n", row);
3047 table->num_rows = row;
3049 done:
3050 CloseServiceHandle( manager );
3051 heap_free( services );
3052 return fill_status;
3055 static WCHAR *get_accountname( LSA_TRANSLATED_NAME *name )
3057 if (!name || !name->Name.Buffer) return NULL;
3058 return heap_strdupW( name->Name.Buffer );
3060 static struct array *get_binaryrepresentation( PSID sid, UINT len )
3062 struct array *array = heap_alloc( sizeof(struct array) );
3063 if (array)
3065 UINT8 *ret = heap_alloc( len );
3066 if (ret)
3068 memcpy( ret, sid, len );
3069 array->count = len;
3070 array->ptr = ret;
3071 return array;
3073 heap_free( array );
3075 return NULL;
3077 static WCHAR *get_referenceddomainname( LSA_REFERENCED_DOMAIN_LIST *domain )
3079 if (!domain || !domain->Domains || !domain->Domains->Name.Buffer) return NULL;
3080 return heap_strdupW( domain->Domains->Name.Buffer );
3082 static const WCHAR *find_sid_str( const struct expr *cond )
3084 const struct expr *left, *right;
3085 const WCHAR *ret = NULL;
3087 if (!cond || cond->type != EXPR_COMPLEX || cond->u.expr.op != OP_EQ) return NULL;
3089 left = cond->u.expr.left;
3090 right = cond->u.expr.right;
3091 if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL && !strcmpiW( left->u.propval->name, prop_sidW ))
3093 ret = right->u.sval;
3095 else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL && !strcmpiW( right->u.propval->name, prop_sidW ))
3097 ret = left->u.sval;
3099 return ret;
3102 static enum fill_status fill_sid( struct table *table, const struct expr *cond )
3104 PSID sid;
3105 LSA_REFERENCED_DOMAIN_LIST *domain;
3106 LSA_TRANSLATED_NAME *name;
3107 LSA_HANDLE handle;
3108 LSA_OBJECT_ATTRIBUTES attrs;
3109 const WCHAR *str;
3110 struct record_sid *rec;
3111 UINT len;
3113 if (!(str = find_sid_str( cond ))) return FILL_STATUS_FAILED;
3114 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
3116 if (!ConvertStringSidToSidW( str, &sid )) return FILL_STATUS_FAILED;
3117 len = GetLengthSid( sid );
3119 memset( &attrs, 0, sizeof(attrs) );
3120 attrs.Length = sizeof(attrs);
3121 if (LsaOpenPolicy( NULL, &attrs, POLICY_ALL_ACCESS, &handle ))
3123 LocalFree( sid );
3124 return FILL_STATUS_FAILED;
3126 if (LsaLookupSids( handle, 1, &sid, &domain, &name ))
3128 LocalFree( sid );
3129 LsaClose( handle );
3130 return FILL_STATUS_FAILED;
3133 rec = (struct record_sid *)table->data;
3134 rec->accountname = get_accountname( name );
3135 rec->binaryrepresentation = get_binaryrepresentation( sid, len );
3136 rec->referenceddomainname = get_referenceddomainname( domain );
3137 rec->sid = heap_strdupW( str );
3138 rec->sidlength = len;
3140 TRACE("created 1 row\n");
3141 table->num_rows = 1;
3143 LsaFreeMemory( domain );
3144 LsaFreeMemory( name );
3145 LocalFree( sid );
3146 LsaClose( handle );
3147 return FILL_STATUS_FILTERED;
3150 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
3152 HDC hdc = GetDC( NULL );
3153 UINT32 ret;
3155 if (!hdc) return 32;
3156 ret = GetDeviceCaps( hdc, BITSPIXEL );
3157 *hres = GetDeviceCaps( hdc, HORZRES );
3158 *vres = GetDeviceCaps( hdc, VERTRES );
3159 ReleaseDC( NULL, hdc );
3160 return ret;
3162 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
3164 static const WCHAR fmtW[] =
3165 {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
3166 '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
3167 '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
3168 WCHAR *ret;
3170 if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
3171 sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
3172 return ret;
3175 static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond )
3177 static const WCHAR fmtW[] = {'%','u',' ','x',' ','%','u',' ','x',' ','%','I','6','4','u',' ','c','o','l','o','r','s',0};
3178 struct record_videocontroller *rec;
3179 HRESULT hr;
3180 IDXGIFactory *factory = NULL;
3181 IDXGIAdapter *adapter = NULL;
3182 DXGI_ADAPTER_DESC desc;
3183 UINT row = 0, hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
3184 const WCHAR *name = videocontroller_deviceidW;
3185 enum fill_status status = FILL_STATUS_UNFILTERED;
3186 WCHAR mode[44];
3188 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
3190 memset (&desc, 0, sizeof(desc));
3191 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
3192 if (FAILED(hr)) goto done;
3194 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
3195 if (FAILED(hr)) goto done;
3197 hr = IDXGIAdapter_GetDesc( adapter, &desc );
3198 if (SUCCEEDED(hr))
3200 vidmem = desc.DedicatedVideoMemory;
3201 name = desc.Description;
3204 done:
3205 rec = (struct record_videocontroller *)table->data;
3206 rec->adapter_dactype = videocontroller_dactypeW;
3207 rec->adapter_ram = vidmem;
3208 rec->availability = 3; /* Running or Full Power */
3209 rec->caption = heap_strdupW( name );
3210 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
3211 rec->current_horizontalres = hres;
3212 rec->current_refreshrate = 0; /* default refresh rate */
3213 rec->current_scanmode = 2; /* Unknown */
3214 rec->current_verticalres = vres;
3215 rec->description = heap_strdupW( name );
3216 rec->device_id = videocontroller_deviceidW;
3217 rec->driverversion = videocontroller_driverversionW;
3218 rec->name = heap_strdupW( name );
3219 rec->pnpdevice_id = get_pnpdeviceid( &desc );
3220 rec->videoarchitecture = 2; /* Unknown */
3221 rec->videomemorytype = 2; /* Unknown */
3222 wsprintfW( mode, fmtW, hres, vres, (UINT64)1 << rec->current_bitsperpixel );
3223 rec->videomodedescription = heap_strdupW( mode );
3224 rec->videoprocessor = heap_strdupW( name );
3225 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
3226 else row++;
3228 TRACE("created %u rows\n", row);
3229 table->num_rows = row;
3231 if (adapter) IDXGIAdapter_Release( adapter );
3232 if (factory) IDXGIFactory_Release( factory );
3233 return status;
3236 static struct table builtin_classes[] =
3238 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), 0, (BYTE *)data_baseboard },
3239 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), 0, (BYTE *)data_bios },
3240 { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, 0, 0, NULL, fill_cdromdrive },
3241 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, 0, NULL, fill_compsys },
3242 { class_compsysproductW, SIZEOF(col_compsysproduct), col_compsysproduct, 0, 0, NULL, fill_compsysproduct },
3243 { class_datafileW, SIZEOF(col_datafile), col_datafile, 0, 0, NULL, fill_datafile },
3244 { class_desktopmonitorW, SIZEOF(col_desktopmonitor), col_desktopmonitor, 0, 0, NULL, fill_desktopmonitor },
3245 { class_directoryW, SIZEOF(col_directory), col_directory, 0, 0, NULL, fill_directory },
3246 { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, 0, 0, NULL, fill_diskdrive },
3247 { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, 0, NULL, fill_diskpartition },
3248 { class_ip4routetableW, SIZEOF(col_ip4routetable), col_ip4routetable, 0, 0, NULL, fill_ip4routetable },
3249 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
3250 { class_logicaldisk2W, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
3251 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, 0, NULL, fill_networkadapter },
3252 { class_networkadapterconfigW, SIZEOF(col_networkadapterconfig), col_networkadapterconfig, 0, 0, NULL, fill_networkadapterconfig },
3253 { class_osW, SIZEOF(col_os), col_os, 0, 0, NULL, fill_os },
3254 { class_paramsW, SIZEOF(col_param), col_param, SIZEOF(data_param), 0, (BYTE *)data_param },
3255 { class_physicalmediaW, SIZEOF(col_physicalmedia), col_physicalmedia, SIZEOF(data_physicalmedia), 0, (BYTE *)data_physicalmedia },
3256 { class_physicalmemoryW, SIZEOF(col_physicalmemory), col_physicalmemory, 0, 0, NULL, fill_physicalmemory },
3257 { class_printerW, SIZEOF(col_printer), col_printer, 0, 0, NULL, fill_printer },
3258 { class_processW, SIZEOF(col_process), col_process, 0, 0, NULL, fill_process },
3259 { class_processorW, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
3260 { class_processor2W, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
3261 { class_qualifiersW, SIZEOF(col_qualifier), col_qualifier, SIZEOF(data_qualifier), 0, (BYTE *)data_qualifier },
3262 { class_serviceW, SIZEOF(col_service), col_service, 0, 0, NULL, fill_service },
3263 { class_sidW, SIZEOF(col_sid), col_sid, 0, 0, NULL, fill_sid },
3264 { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), 0, (BYTE *)data_sounddevice },
3265 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), 0, (BYTE *)data_stdregprov },
3266 { class_systemsecurityW, SIZEOF(col_systemsecurity), col_systemsecurity, SIZEOF(data_systemsecurity), 0, (BYTE *)data_systemsecurity },
3267 { class_systemenclosureW, SIZEOF(col_systemenclosure), col_systemenclosure, SIZEOF(data_systemenclosure), 0, (BYTE *)data_systemenclosure },
3268 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, 0, NULL, fill_videocontroller }
3271 void init_table_list( void )
3273 static struct list tables = LIST_INIT( tables );
3274 UINT i;
3276 for (i = 0; i < SIZEOF(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
3277 table_list = &tables;