Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

winExtDLL not loading #383

Closed
janclod opened this issue Nov 25, 2021 · 3 comments
Closed

winExtDLL not loading #383

janclod opened this issue Nov 25, 2021 · 3 comments

Comments

@janclod
Copy link

janclod commented Nov 25, 2021

Last time writing down my problem lead me to a solution, so I will describe my new problem here and hope it will also get me closer to a solution :)

Goal: run NetSNMP agent v3 on Win10

Requirement 1: v3 with both authentication and encryption (e.g., SHA/AES)

Requirement 2: need to load extension of Windows agent written years ago by someone else

V5-9-patches scenario
I am able to fulfil requirements 1 by running my own build of the V5-9-patches branch. Using the V5-9-patches build I am not able to load the winExtDLL, this is the debug information:

registered debug token winExtDLL, 1
init_winExtDLL started.
winExtDLL: read_extension_dlls_from_registry called
init_winExtDLL: found 0 extension DLLs in the registry.
init_winExtDLL: registered 0 OID ranges.
init_winExtDLL finished.

Build information
Architecture: x86
OpenSSL: v3 32bit

v5.5.0 binary scenario
I am able to fulfil requirement 2 by running the binaries downloadable from sourceforge (v5.5.0 64-bit), but not requirements 1. As far as I understand it is not possible to install NetSNMP with encryption support from binary, please correct if I am wrong. So the first scenario is where I am looking for a solution.

Bug trace

init_winExtDLL started.
winExtDLL: read_extension_dlls_from_registry called
registry key SOFTWARE\mysoftware\CurrentVersion: DLL C:\Windows\System32\mysnmp.dll.
registry key Software\mysoftware\CurrentVersion: DLL C:\Windows\System32\mysnmp.dll.
init_winExtDLL: found 2 extension DLLs in the registry.
loading DLL C:\Windows\System32\mysnmp.dll.
loading DLL C:\Windows\System32\mysnmp.dll.
registering handler for DLL C:\Windows\System32\mysnmp.dll and OID prefix .1.3.6.1.4.1.XXXXX
registering handler for DLL C:\Windows\System32\mysnmp.dll and OID prefix .1.3.6.1.4.1.XXXXX
registering handler for DLL C:\Windows\System32\mysnmp.dll and OID prefix .1.3.6.1.4.1.XXXXXX
OID range .1.3.6.1.4.1.96788: replacing handler C:\Windows\System32\mysnmp.dll by C:\Windows\System32\mysnmp.dll.
init_winExtDLL: registered 4 OID ranges.
init_winExtDLL finished.

This is how my registry looks like:

Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ExtensionAgents
Default REG_SZ                (value not set)
0           REG_SZ                Software\mysoftware\CurrentVersion
1           REG_SZ                SOFTWARE\mysoftware\CurrentVersion

Can you provide some guidance for scenario V5-9-patches? Should I try building from a different branch? Is this a bug (unlikely)?

@bvanassche
Copy link
Contributor

winExtDLL can only load Windows SNMP DLLs after these have been installed. Is SNMP still supported by Windows 10? The following appears if I try to install SNMP in a Windows 10 VM:

$ Enable-WindowsOptionalFeature -online -FeatureName SNMP
Enable-WindowsOptionalFeature : Feature name SNMP is unknown.
At line:1 char:1
+ Enable-WindowsOptionalFeature -online -FeatureName SNMP
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Enable-WindowsOptionalFeature], COMException
    + FullyQualifiedErrorId : Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand

@janclod
Copy link
Author

janclod commented Nov 29, 2021

Thank you Bart for your contribution :)

Windows 10 still offers the SNMP service, it is simply extra hidden. I did install the SNMP Win service following this strategy and the customized winExtDLL is registered.

I also dare to claim that the winExtDLL SNMP works based:

  • on the output posted above, see v5.5.0 binary scenario
  • on the fact that I am able to query the custom SNMP loaded from winExtDLLs

Based on some extra debugging, I found out that NetSNMP fails to open the Win registry (where the winExtDLL path is stored): SOFTWARE\mysoftware\CurrentVersion

EDIT: I made some progress, it seems that software (e.g., NetSNMP) is built using x86 environment. As far as I can understand x86 software can not access registry written by x64 software (e.g., my own software, SNMP Win service). I am now busy building the NetSNMP using x64 env and see if the issue is solved.

@janclod
Copy link
Author

janclod commented Nov 30, 2021

In my specific case, the mysnmp.dll was a 64-bit version. In the V5-9-patches scenario I was trying to load the 64-bit library (DLL) into a 32-bit process. This is not allowed.
https://docs.microsoft.com/en-us/windows/win32/winprog64/process-interoperability

SOLUTION: build NetSNMP agent using x64 environment

Specifications
NetSNMP: branch V5-9-patches
OpenSSL: Win64OpenSSL-3_0_0.exe
Build env: x64
winExtDLL: mysnmp.dll (64-bit version)

@janclod janclod closed this as completed Nov 30, 2021
bvanassche added a commit that referenced this issue Dec 11, 2021
Commit 59b4d40 ("CHANGES: Windows: Make winExtDLL work on 64-bit
Windows systems") caused snmpd to skip MIB-II on 64-bit systems. Revert
that change such that the Windows MIB-II implementation can be used on
Windows 10. See also:
* #383
* #388

With this patch applied, I see the following output in a Windows VM:
$ /c/usr/bin/snmpwalk -v2c -cpublic localhost .1.3.6.1.2.1.2
IF-MIB::ifNumber.0 = INTEGER: 9
IF-MIB::ifIndex.1 = INTEGER: 1
IF-MIB::ifIndex.2 = INTEGER: 2
IF-MIB::ifIndex.3 = INTEGER: 3
IF-MIB::ifIndex.4 = INTEGER: 4
IF-MIB::ifIndex.5 = INTEGER: 5
IF-MIB::ifIndex.6 = INTEGER: 6
IF-MIB::ifIndex.7 = INTEGER: 7
IF-MIB::ifIndex.8 = INTEGER: 8
IF-MIB::ifIndex.9 = INTEGER: 9
IF-MIB::ifDescr.1 = STRING: Software Loopback Interface 1
IF-MIB::ifDescr.2 = STRING: Microsoft 6to4 Adapter
IF-MIB::ifDescr.3 = STRING: Microsoft Kernel Debug Network Adapter
IF-MIB::ifDescr.4 = STRING: Microsoft IP-HTTPS Platform Adapter
IF-MIB::ifDescr.5 = STRING: Intel(R) 82574L Gigabit Network Connection
IF-MIB::ifDescr.6 = STRING: Microsoft Teredo Tunneling Adapter
IF-MIB::ifDescr.7 = STRING: Intel(R) 82574L Gigabit Network Connection-WFP Native MAC Layer LightWeight Filter-0000
IF-MIB::ifDescr.8 = STRING: Intel(R) 82574L Gigabit Network Connection-QoS Packet Scheduler-0000
IF-MIB::ifDescr.9 = STRING: Intel(R) 82574L Gigabit Network Connection-WFP 802.3 MAC Layer LightWeight Filter-0000
IF-MIB::ifType.1 = INTEGER: softwareLoopback(24)
IF-MIB::ifType.2 = INTEGER: tunnel(131)
IF-MIB::ifType.3 = INTEGER: ethernetCsmacd(6)
IF-MIB::ifType.4 = INTEGER: tunnel(131)
IF-MIB::ifType.5 = INTEGER: ethernetCsmacd(6)
IF-MIB::ifType.6 = INTEGER: tunnel(131)
IF-MIB::ifType.7 = INTEGER: ethernetCsmacd(6)
IF-MIB::ifType.8 = INTEGER: ethernetCsmacd(6)
IF-MIB::ifType.9 = INTEGER: ethernetCsmacd(6)
IF-MIB::ifMtu.1 = INTEGER: 1500
IF-MIB::ifMtu.2 = INTEGER: 0
IF-MIB::ifMtu.3 = INTEGER: 0
IF-MIB::ifMtu.4 = INTEGER: 0
IF-MIB::ifMtu.5 = INTEGER: 1500
IF-MIB::ifMtu.6 = INTEGER: 0
IF-MIB::ifMtu.7 = INTEGER: 1500
IF-MIB::ifMtu.8 = INTEGER: 1500
IF-MIB::ifMtu.9 = INTEGER: 1500
IF-MIB::ifSpeed.1 = Gauge32: 1073741824
IF-MIB::ifSpeed.2 = Gauge32: 0
IF-MIB::ifSpeed.3 = Gauge32: 0
IF-MIB::ifSpeed.4 = Gauge32: 0
IF-MIB::ifSpeed.5 = Gauge32: 1000000000
IF-MIB::ifSpeed.6 = Gauge32: 0
IF-MIB::ifSpeed.7 = Gauge32: 1000000000
IF-MIB::ifSpeed.8 = Gauge32: 1000000000
IF-MIB::ifSpeed.9 = Gauge32: 1000000000
IF-MIB::ifPhysAddress.1 = STRING:
IF-MIB::ifPhysAddress.2 = STRING:
IF-MIB::ifPhysAddress.3 = STRING:
IF-MIB::ifPhysAddress.4 = STRING:
IF-MIB::ifPhysAddress.5 = STRING: 52:54:0:bb:6f:2f
IF-MIB::ifPhysAddress.6 = STRING:
IF-MIB::ifPhysAddress.7 = STRING: 52:54:0:bb:6f:2f
IF-MIB::ifPhysAddress.8 = STRING: 52:54:0:bb:6f:2f
IF-MIB::ifPhysAddress.9 = STRING: 52:54:0:bb:6f:2f
IF-MIB::ifAdminStatus.1 = INTEGER: up(1)
IF-MIB::ifAdminStatus.2 = INTEGER: down(2)
IF-MIB::ifAdminStatus.3 = INTEGER: down(2)
IF-MIB::ifAdminStatus.4 = INTEGER: down(2)
IF-MIB::ifAdminStatus.5 = INTEGER: up(1)
IF-MIB::ifAdminStatus.6 = INTEGER: down(2)
IF-MIB::ifAdminStatus.7 = INTEGER: up(1)
IF-MIB::ifAdminStatus.8 = INTEGER: up(1)
IF-MIB::ifAdminStatus.9 = INTEGER: up(1)
IF-MIB::ifOperStatus.1 = INTEGER: up(1)
IF-MIB::ifOperStatus.2 = INTEGER: down(2)
IF-MIB::ifOperStatus.3 = INTEGER: down(2)
IF-MIB::ifOperStatus.4 = INTEGER: down(2)
IF-MIB::ifOperStatus.5 = INTEGER: up(1)
IF-MIB::ifOperStatus.6 = INTEGER: down(2)
IF-MIB::ifOperStatus.7 = INTEGER: up(1)
IF-MIB::ifOperStatus.8 = INTEGER: up(1)
IF-MIB::ifOperStatus.9 = INTEGER: up(1)
IF-MIB::ifLastChange.1 = Timeticks: (0) 0:00:00.00
IF-MIB::ifLastChange.2 = Timeticks: (0) 0:00:00.00
IF-MIB::ifLastChange.3 = Timeticks: (0) 0:00:00.00
IF-MIB::ifLastChange.4 = Timeticks: (0) 0:00:00.00
IF-MIB::ifLastChange.5 = Timeticks: (0) 0:00:00.00
IF-MIB::ifLastChange.6 = Timeticks: (0) 0:00:00.00
IF-MIB::ifLastChange.7 = Timeticks: (0) 0:00:00.00
IF-MIB::ifLastChange.8 = Timeticks: (0) 0:00:00.00
IF-MIB::ifLastChange.9 = Timeticks: (0) 0:00:00.00
IF-MIB::ifInOctets.1 = Counter32: 0
IF-MIB::ifInOctets.2 = Counter32: 0
IF-MIB::ifInOctets.3 = Counter32: 0
IF-MIB::ifInOctets.4 = Counter32: 0
IF-MIB::ifInOctets.5 = Counter32: 3902284436
IF-MIB::ifInOctets.6 = Counter32: 0
IF-MIB::ifInOctets.7 = Counter32: 3902284436
IF-MIB::ifInOctets.8 = Counter32: 3902284436
IF-MIB::ifInOctets.9 = Counter32: 3902284436
IF-MIB::ifInUcastPkts.1 = Counter32: 0
IF-MIB::ifInUcastPkts.2 = Counter32: 0
IF-MIB::ifInUcastPkts.3 = Counter32: 0
IF-MIB::ifInUcastPkts.4 = Counter32: 0
IF-MIB::ifInUcastPkts.5 = Counter32: 265150678
IF-MIB::ifInUcastPkts.6 = Counter32: 0
IF-MIB::ifInUcastPkts.7 = Counter32: 265150678
IF-MIB::ifInUcastPkts.8 = Counter32: 265150678
IF-MIB::ifInUcastPkts.9 = Counter32: 265150678
IF-MIB::ifInNUcastPkts.1 = Counter32: 0
IF-MIB::ifInNUcastPkts.2 = Counter32: 0
IF-MIB::ifInNUcastPkts.3 = Counter32: 0
IF-MIB::ifInNUcastPkts.4 = Counter32: 0
IF-MIB::ifInNUcastPkts.5 = Counter32: 28
IF-MIB::ifInNUcastPkts.6 = Counter32: 0
IF-MIB::ifInNUcastPkts.7 = Counter32: 28
IF-MIB::ifInNUcastPkts.8 = Counter32: 28
IF-MIB::ifInNUcastPkts.9 = Counter32: 28
IF-MIB::ifInDiscards.1 = Counter32: 0
IF-MIB::ifInDiscards.2 = Counter32: 0
IF-MIB::ifInDiscards.3 = Counter32: 0
IF-MIB::ifInDiscards.4 = Counter32: 0
IF-MIB::ifInDiscards.5 = Counter32: 0
IF-MIB::ifInDiscards.6 = Counter32: 0
IF-MIB::ifInDiscards.7 = Counter32: 0
IF-MIB::ifInDiscards.8 = Counter32: 0
IF-MIB::ifInDiscards.9 = Counter32: 0
IF-MIB::ifInErrors.1 = Counter32: 0
IF-MIB::ifInErrors.2 = Counter32: 0
IF-MIB::ifInErrors.3 = Counter32: 0
IF-MIB::ifInErrors.4 = Counter32: 0
IF-MIB::ifInErrors.5 = Counter32: 0
IF-MIB::ifInErrors.6 = Counter32: 0
IF-MIB::ifInErrors.7 = Counter32: 0
IF-MIB::ifInErrors.8 = Counter32: 0
IF-MIB::ifInErrors.9 = Counter32: 0
IF-MIB::ifInUnknownProtos.1 = Counter32: 0
IF-MIB::ifInUnknownProtos.2 = Counter32: 0
IF-MIB::ifInUnknownProtos.3 = Counter32: 0
IF-MIB::ifInUnknownProtos.4 = Counter32: 0
IF-MIB::ifInUnknownProtos.5 = Counter32: 0
IF-MIB::ifInUnknownProtos.6 = Counter32: 0
IF-MIB::ifInUnknownProtos.7 = Counter32: 0
IF-MIB::ifInUnknownProtos.8 = Counter32: 0
IF-MIB::ifInUnknownProtos.9 = Counter32: 0
IF-MIB::ifOutOctets.1 = Counter32: 0
IF-MIB::ifOutOctets.2 = Counter32: 0
IF-MIB::ifOutOctets.3 = Counter32: 0
IF-MIB::ifOutOctets.4 = Counter32: 0
IF-MIB::ifOutOctets.5 = Counter32: 1952733666
IF-MIB::ifOutOctets.6 = Counter32: 0
IF-MIB::ifOutOctets.7 = Counter32: 1952733666
IF-MIB::ifOutOctets.8 = Counter32: 1952733666
IF-MIB::ifOutOctets.9 = Counter32: 1952733666
IF-MIB::ifOutUcastPkts.1 = Counter32: 0
IF-MIB::ifOutUcastPkts.2 = Counter32: 0
IF-MIB::ifOutUcastPkts.3 = Counter32: 0
IF-MIB::ifOutUcastPkts.4 = Counter32: 0
IF-MIB::ifOutUcastPkts.5 = Counter32: 137686780
IF-MIB::ifOutUcastPkts.6 = Counter32: 0
IF-MIB::ifOutUcastPkts.7 = Counter32: 137686780
IF-MIB::ifOutUcastPkts.8 = Counter32: 137686780
IF-MIB::ifOutUcastPkts.9 = Counter32: 137686780
IF-MIB::ifOutNUcastPkts.1 = Counter32: 0
IF-MIB::ifOutNUcastPkts.2 = Counter32: 0
IF-MIB::ifOutNUcastPkts.3 = Counter32: 0
IF-MIB::ifOutNUcastPkts.4 = Counter32: 0
IF-MIB::ifOutNUcastPkts.5 = Counter32: 115
IF-MIB::ifOutNUcastPkts.6 = Counter32: 0
IF-MIB::ifOutNUcastPkts.7 = Counter32: 115
IF-MIB::ifOutNUcastPkts.8 = Counter32: 115
IF-MIB::ifOutNUcastPkts.9 = Counter32: 115
IF-MIB::ifOutDiscards.1 = Counter32: 0
IF-MIB::ifOutDiscards.2 = Counter32: 0
IF-MIB::ifOutDiscards.3 = Counter32: 0
IF-MIB::ifOutDiscards.4 = Counter32: 0
IF-MIB::ifOutDiscards.5 = Counter32: 0
IF-MIB::ifOutDiscards.6 = Counter32: 0
IF-MIB::ifOutDiscards.7 = Counter32: 0
IF-MIB::ifOutDiscards.8 = Counter32: 0
IF-MIB::ifOutDiscards.9 = Counter32: 0
IF-MIB::ifOutErrors.1 = Counter32: 0
IF-MIB::ifOutErrors.2 = Counter32: 0
IF-MIB::ifOutErrors.3 = Counter32: 0
IF-MIB::ifOutErrors.4 = Counter32: 0
IF-MIB::ifOutErrors.5 = Counter32: 0
IF-MIB::ifOutErrors.6 = Counter32: 0
IF-MIB::ifOutErrors.7 = Counter32: 0
IF-MIB::ifOutErrors.8 = Counter32: 0
IF-MIB::ifOutErrors.9 = Counter32: 0
IF-MIB::ifOutQLen.1 = Gauge32: 0
IF-MIB::ifOutQLen.2 = Gauge32: 0
IF-MIB::ifOutQLen.3 = Gauge32: 0
IF-MIB::ifOutQLen.4 = Gauge32: 0
IF-MIB::ifOutQLen.5 = Gauge32: 0
IF-MIB::ifOutQLen.6 = Gauge32: 0
IF-MIB::ifOutQLen.7 = Gauge32: 0
IF-MIB::ifOutQLen.8 = Gauge32: 0
IF-MIB::ifOutQLen.9 = Gauge32: 0
IF-MIB::ifSpecific.1 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.2 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.3 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.4 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.5 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.6 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.7 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.8 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.9 = OID: SNMPv2-SMI::zeroDotZero
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants