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