2 * Copyright 2008 Juan Lang
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
26 static HMODULE inetmib1;
28 static void testInit(void)
30 BOOL (WINAPI *pInit)(DWORD, HANDLE *, AsnObjectIdentifier *);
33 AsnObjectIdentifier oid;
35 pInit = (void *)GetProcAddress(inetmib1, "SnmpExtensionInit");
38 skip("no SnmpExtensionInit\n");
42 ret = pInit(0, NULL, NULL);
43 ret = pInit(0, NULL, &oid);
44 ret = pInit(0, &event, NULL);
46 ret = pInit(0, &event, &oid);
47 ok(ret, "SnmpExtensionInit failed: %d\n", GetLastError());
48 ok(!strcmp("1.3.6.1.2.1.1", SnmpUtilOidToA(&oid)),
49 "Expected 1.3.6.1.2.1.1, got %s\n", SnmpUtilOidToA(&oid));
52 static void testQuery(void)
54 BOOL (WINAPI *pQuery)(BYTE, SnmpVarBindList *, AsnInteger32 *,
58 AsnInteger32 error, index;
59 UINT bogus[] = { 1,2,3,4 };
60 UINT mib2System[] = { 1,3,6,1,2,1,1 };
61 UINT mib2If[] = { 1,3,6,1,2,1,2 };
62 UINT mib2IfTable[] = { 1,3,6,1,2,1,2,2 };
63 UINT mib2IfDescr[] = { 1,3,6,1,2,1,2,2,1,2 };
64 UINT mib2IfAdminStatus[] = { 1,3,6,1,2,1,2,2,1,7 };
65 UINT mib2IfOperStatus[] = { 1,3,6,1,2,1,2,2,1,8 };
66 UINT mib2IpAddr[] = { 1,3,6,1,2,1,4,20,1,1 };
67 UINT mib2IpRouteTable[] = { 1,3,6,1,2,1,4,21,1,1 };
68 UINT mib2UdpTable[] = { 1,3,6,1,2,1,7,5,1,1 };
69 SnmpVarBind vars[3], vars2[3];
72 pQuery = (void *)GetProcAddress(inetmib1, "SnmpExtensionQuery");
75 skip("couldn't find SnmpExtensionQuery\n");
79 ret = pQuery(0, NULL, NULL, NULL);
80 ret = pQuery(0, NULL, &error, NULL);
81 ret = pQuery(0, NULL, NULL, &index);
82 ret = pQuery(0, &list, NULL, NULL);
83 ret = pQuery(0, &list, &error, NULL);
86 /* An empty list succeeds */
90 ret = pQuery(SNMP_PDU_GET, &list, &error, &index);
91 ok(ret, "SnmpExtensionQuery failed: %d\n", GetLastError());
92 ok(error == SNMP_ERRORSTATUS_NOERROR,
93 "expected SNMP_ERRORSTATUS_NOERROR, got %d\n", error);
94 ok(index == 0, "expected index 0, got %d\n", index);
96 /* Oddly enough, this "succeeds," even though the OID is clearly
99 vars[0].name.idLength = sizeof(bogus) / sizeof(bogus[0]);
100 vars[0].name.ids = bogus;
101 vars[0].value.asnType = 0;
104 SetLastError(0xdeadbeef);
107 ret = pQuery(SNMP_PDU_GET, &list, &error, &index);
108 ok(ret, "SnmpExtensionQuery failed: %d\n", GetLastError());
109 ok(error == SNMP_ERRORSTATUS_NOERROR,
110 "expected SNMP_ERRORSTATUS_NOERROR, got %d\n", error);
111 ok(index == 0, "expected index 0, got %d\n", index);
112 /* The OID isn't changed either: */
113 ok(!strcmp("1.2.3.4", SnmpUtilOidToA(&vars[0].name)),
114 "expected 1.2.3.4, got %s\n", SnmpUtilOidToA(&vars[0].name));
116 /* The table is not an accessible variable, so it fails */
117 vars[0].name.idLength = sizeof(mib2IfTable) / sizeof(mib2IfTable[0]);
118 vars[0].name.ids = mib2IfTable;
119 SetLastError(0xdeadbeef);
122 ret = pQuery(SNMP_PDU_GET, &list, &error, &index);
123 ok(ret, "SnmpExtensionQuery failed: %d\n", GetLastError());
124 ok(error == SNMP_ERRORSTATUS_NOSUCHNAME,
125 "expected SNMP_ERRORSTATUS_NOSUCHNAME, got %d\n", error);
126 /* The index is 1-based rather than 0-based */
127 ok(index == 1, "expected index 1, got %d\n", index);
129 /* A Get fails on something that specifies a table (but not a particular
132 vars[0].name.idLength = sizeof(mib2IfDescr) / sizeof(mib2IfDescr[0]);
133 vars[0].name.ids = mib2IfDescr;
134 vars[1].name.idLength =
135 sizeof(mib2IfAdminStatus) / sizeof(mib2IfAdminStatus[0]);
136 vars[1].name.ids = mib2IfAdminStatus;
137 vars[2].name.idLength =
138 sizeof(mib2IfOperStatus) / sizeof(mib2IfOperStatus[0]);
139 vars[2].name.ids = mib2IfOperStatus;
141 SetLastError(0xdeadbeef);
144 ret = pQuery(SNMP_PDU_GET, &list, &error, &index);
145 ok(ret, "SnmpExtensionQuery failed: %d\n", GetLastError());
146 ok(error == SNMP_ERRORSTATUS_NOSUCHNAME,
147 "expected SNMP_ERRORSTATUS_NOSUCHNAME, got %d\n", error);
148 ok(index == 1, "expected index 1, got %d\n", index);
149 /* but a GetNext succeeds with the same values, because GetNext gets the
150 * entry after the specified OID, not the entry specified by it. The
151 * successor to the table is the first entry in the table.
152 * The OIDs need to be allocated, because GetNext modifies them to indicate
155 SnmpUtilOidCpy(&vars2[0].name, &vars[0].name);
156 SnmpUtilOidCpy(&vars2[1].name, &vars[1].name);
157 SnmpUtilOidCpy(&vars2[2].name, &vars[2].name);
162 SetLastError(0xdeadbeef);
165 ret = pQuery(SNMP_PDU_GETNEXT, &list, &error, &index);
166 ok(ret, "SnmpExtensionQuery failed: %d\n", GetLastError());
167 ok(error == SNMP_ERRORSTATUS_NOERROR,
168 "expected SNMP_ERRORSTATUS_NOERROR, got %d\n", error);
169 ok(index == 0, "expected index 0, got %d\n", index);
174 else if (SnmpUtilOidNCmp(&vars2[0].name, &vars[0].name,
175 vars[0].name.idLength))
177 else if (SnmpUtilOidNCmp(&vars2[1].name, &vars[1].name,
178 vars[1].name.idLength))
180 else if (SnmpUtilOidNCmp(&vars2[2].name, &vars[2].name,
181 vars[2].name.idLength))
185 /* Check the OIDs. For these types of values (display strings and
186 * integers) they increase by 1 for each element of the table.
188 ok(vars2[0].name.idLength == vars[0].name.idLength + 1,
189 "expected length %d, got %d\n", vars[0].name.idLength + 1,
190 vars2[0].name.idLength);
191 ok(vars2[0].name.ids[vars2[0].name.idLength - 1] == entry,
192 "expected %d, got %d\n", entry,
193 vars2[0].name.ids[vars2[0].name.idLength - 1]);
194 ok(vars2[1].name.idLength == vars[1].name.idLength + 1,
195 "expected length %d, got %d\n", vars[1].name.idLength + 1,
196 vars2[1].name.idLength);
197 ok(vars2[1].name.ids[vars2[1].name.idLength - 1] == entry,
198 "expected %d, got %d\n", entry,
199 vars2[1].name.ids[vars2[1].name.idLength - 1]);
200 ok(vars2[2].name.idLength == vars[2].name.idLength + 1,
201 "expected length %d, got %d\n", vars[2].name.idLength + 1,
202 vars2[2].name.idLength);
203 ok(vars2[2].name.ids[vars2[2].name.idLength - 1] == entry,
204 "expected %d, got %d\n", entry,
205 vars2[2].name.ids[vars2[2].name.idLength - 1]);
207 /* Check the types while we're at it */
208 ok(vars2[0].value.asnType == ASN_OCTETSTRING,
209 "expected ASN_OCTETSTRING, got %02x\n", vars2[0].value.asnType);
210 ok(vars2[1].value.asnType == ASN_INTEGER,
211 "expected ASN_INTEGER, got %02x\n", vars2[1].value.asnType);
212 ok(vars2[2].value.asnType == ASN_INTEGER,
213 "expected ASN_INTEGER, got %02x\n", vars2[2].value.asnType);
214 /* Check that the operational status of an interface correctly
215 * follows the MIB2 definition of it, rather than the values
216 * defined for IPHlpApi's dwOperStatus field.
218 ok(vars2[2].value.asnValue.unsigned32 <= 2,
219 "expected a value of 0, 1, or 2, got %u\n",
220 vars2[2].value.asnValue.unsigned32);
223 SnmpUtilVarBindFree(&vars2[0]);
224 SnmpUtilVarBindFree(&vars2[1]);
225 SnmpUtilVarBindFree(&vars2[2]);
227 /* Even though SnmpExtensionInit says this DLL supports the MIB2 system
228 * variables, the first variable it returns a value for is the first
231 vars[0].name.idLength = sizeof(mib2System) / sizeof(mib2System[0]);
232 vars[0].name.ids = mib2System;
233 SnmpUtilOidCpy(&vars2[0].name, &vars[0].name);
234 vars2[0].value.asnType = 0;
238 ret = pQuery(SNMP_PDU_GETNEXT, &list, &error, &index);
239 ok(ret, "SnmpExtensionQuery failed: %d\n", GetLastError());
240 ok(error == SNMP_ERRORSTATUS_NOERROR,
241 "expected SNMP_ERRORSTATUS_NOERROR, got %d\n", error);
242 ok(index == 0, "expected index 0, got %d\n", index);
243 vars[0].name.idLength = sizeof(mib2If) / sizeof(mib2If[0]);
244 vars[0].name.ids = mib2If;
245 ok(!SnmpUtilOidNCmp(&vars2[0].name, &vars[0].name, vars[0].name.idLength),
246 "expected 1.3.6.1.2.1.2, got %s\n", SnmpUtilOidToA(&vars2[0].name));
247 SnmpUtilVarBindFree(&vars2[0]);
249 /* Check the type and OIDs of the IP address table */
250 vars[0].name.idLength = sizeof(mib2IpAddr) / sizeof(mib2IpAddr[0]);
251 vars[0].name.ids = mib2IpAddr;
252 SnmpUtilOidCpy(&vars2[0].name, &vars[0].name);
253 vars2[0].value.asnType = 0;
258 ret = pQuery(SNMP_PDU_GETNEXT, &list, &error, &index);
259 ok(ret, "SnmpExtensionQuery failed: %d\n", GetLastError());
260 ok(error == SNMP_ERRORSTATUS_NOERROR,
261 "expected SNMP_ERRORSTATUS_NOERROR, got %d\n", error);
262 ok(index == 0, "expected index 0, got %d\n", index);
267 else if (SnmpUtilOidNCmp(&vars2[0].name, &vars[0].name,
268 vars[0].name.idLength))
272 /* Make sure the size of the OID is right.
273 * FIXME: don't know if IPv6 addrs are shared with this table.
274 * Don't think so, but I'm not certain.
276 ok(vars2[0].name.idLength == vars[0].name.idLength + 4,
277 "expected length %d, got %d\n", vars[0].name.idLength + 4,
278 vars2[0].name.idLength);
279 /* Make sure the type is right */
280 ok(vars2[0].value.asnType == ASN_IPADDRESS,
281 "expected type ASN_IPADDRESS, got %02x\n",
282 vars2[0].value.asnType);
283 if (vars2[0].value.asnType == ASN_IPADDRESS)
287 /* This looks uglier than it is: the base OID for the IP
288 * address, 1.3.6.1.2.1.4.20.1.1, is appended with the IP
289 * address of the entry. So e.g. the loopback address is
290 * identified in MIB2 as 1.3.6.1.2.1.4.20.1.1.127.0.0.1
292 for (i = 0; i < vars2[0].value.asnValue.address.length; i++)
294 ok(vars2[0].value.asnValue.address.stream[i] ==
295 vars2[0].name.ids[vars2[0].name.idLength - 4 + i],
296 "expected ident byte %d to be %d, got %d\n", i,
297 vars2[0].value.asnValue.address.stream[i],
298 vars2[0].name.ids[vars2[0].name.idLength - 4 + i]);
303 SnmpUtilVarBindFree(&vars2[0]);
305 /* Check the type and OIDs of the IP route table */
306 vars[0].name.idLength = DEFINE_SIZEOF(mib2IpRouteTable);
307 vars[0].name.ids = mib2IpRouteTable;
308 SnmpUtilOidCpy(&vars2[0].name, &vars[0].name);
309 vars2[0].value.asnType = 0;
314 ret = pQuery(SNMP_PDU_GETNEXT, &list, &error, &index);
315 ok(ret, "SnmpExtensionQuery failed: %d\n", GetLastError());
316 ok(error == SNMP_ERRORSTATUS_NOERROR,
317 "expected SNMP_ERRORSTATUS_NOERROR, got %d\n", error);
318 ok(index == 0, "expected index 0, got %d\n", index);
323 else if (SnmpUtilOidNCmp(&vars2[0].name, &vars[0].name,
324 vars[0].name.idLength))
328 /* Make sure the size of the OID is right.
329 * FIXME: don't know if IPv6 addrs are shared with this table.
330 * Don't think so, but I'm not certain.
332 ok(vars2[0].name.idLength = vars[0].name.idLength + 4,
333 "expected length %d, got %d\n", vars[0].name.idLength + 4,
334 vars2[0].name.idLength);
335 /* Make sure the type is right */
336 ok(vars2[0].value.asnType == ASN_IPADDRESS,
337 "expected type ASN_IPADDRESS, got %02x\n",
338 vars2[0].value.asnType);
339 if (vars2[0].value.asnType == ASN_IPADDRESS)
343 /* The base OID for the route table, 1.3.6.1.2.1.4.21.1.1, is
344 * appended with the dest IP address of the entry. So e.g. a
345 * route entry for 224.0.0.0 is identified in MIB2 as
346 * 1.3.6.1.2.1.4.21.1.1.224.0.0.0
348 for (i = 0; i < vars2[0].value.asnValue.address.length; i++)
350 ok(vars2[0].value.asnValue.address.stream[i] ==
351 vars2[0].name.ids[vars2[0].name.idLength - 4 + i],
352 "expected ident byte %d to be %d, got %d\n", i,
353 vars2[0].value.asnValue.address.stream[i],
354 vars2[0].name.ids[vars2[0].name.idLength - 4 + i]);
359 SnmpUtilVarBindFree(&vars2[0]);
361 /* Check the type and OIDs of the UDP table */
362 vars[0].name.idLength = DEFINE_SIZEOF(mib2UdpTable);
363 vars[0].name.ids = mib2UdpTable;
364 SnmpUtilOidCpy(&vars2[0].name, &vars[0].name);
365 vars2[0].value.asnType = 0;
370 ret = pQuery(SNMP_PDU_GETNEXT, &list, &error, &index);
371 ok(ret, "SnmpExtensionQuery failed: %d\n", GetLastError());
372 /* FIXME: error and index aren't checked here because the UDP table is
373 * the last OID currently supported by Wine, so the last GetNext fails.
374 * todo_wine is also not effective because it will succeed for all but
375 * the last GetNext. Remove the if (0) if any later OID is supported
379 ok(error == SNMP_ERRORSTATUS_NOERROR,
380 "expected SNMP_ERRORSTATUS_NOERROR, got %d\n", error);
381 ok(index == 0, "expected index 0, got %d\n", index);
387 else if (SnmpUtilOidNCmp(&vars2[0].name, &vars[0].name,
388 vars[0].name.idLength))
392 /* Make sure the size of the OID is right. */
393 ok(vars2[0].name.idLength == vars[0].name.idLength + 5,
394 "expected length %d, got %d\n", vars[0].name.idLength + 5,
395 vars2[0].name.idLength);
396 /* Make sure the type is right */
397 ok(vars2[0].value.asnType == ASN_IPADDRESS,
398 "expected type ASN_IPADDRESS, got %02x\n",
399 vars2[0].value.asnType);
400 if (vars2[0].value.asnType == ASN_IPADDRESS)
404 /* Again with the ugly: the base OID for the UDP table,
405 * 1.3.6.1.2.1.7.5.1, is appended with the local IP address and
406 * port number of the entry. So e.g. an entry for
407 * 192.168.1.1:4000 is identified in MIB2 as
408 * 1.3.6.1.2.1.7.5.1.192.168.1.1.4000
410 for (i = 0; i < vars2[0].value.asnValue.address.length; i++)
412 ok(vars2[0].value.asnValue.address.stream[i] ==
413 vars2[0].name.ids[vars2[0].name.idLength - 5 + i],
414 "expected ident byte %d to be %d, got %d\n", i,
415 vars2[0].value.asnValue.address.stream[i],
416 vars2[0].name.ids[vars2[0].name.idLength - 5 + i]);
421 SnmpUtilVarBindFree(&vars2[0]);
426 inetmib1 = LoadLibraryA("inetmib1");