aboutsummaryrefslogtreecommitdiff
path: root/contrib/bsnmp/lib
Commit message (Collapse)AuthorAgeFilesLines
* bsnmp: fix undefined behaviourLexi Winter2025-08-011-1/+3
| | | | | | | | Modifying and using a variable without an intervening sequence point is undefined behaviour, which causes an error in the GCC build. Reviewed by: harti, emaste Differential Revision: https://reviews.freebsd.org/D51576
* libbsnmp: make snmp_parse_server() more robust when lacking infoGleb Smirnoff2025-07-251-98/+85
| | | | | | | | | | | | | | | | | | | | | | Per documentation snmp_parse_server() has all 4 components optional. We want inputs like "udp::", "udp6::", "stream::" work with local default sockets and even degenerate case of "" shall end with defaults instead of a failure. While here make the parser more robust. Make all parser helpers to behave the same way: on successful return they are responsible to update both start & end of matched substring and return next characater to parse. This eliminates special handling of IPv6 and port parser that used to need to skip a character, and thus eliminates unchecked step forward in snmp_parse_server() itself. Additionally: - use strchr(3) instead of own cycle - INET_ADDRSTRLEN includes space for NUL character - INET6_ADDRSTRLEN includes both the scope and NUL character - prefer sizeof() comparison instead of preprocessor define repetitive use Reviewed by: harti Differential Revision: https://reviews.freebsd.org/D51072
* libbsnmp: make binding of client UNIX socket optional and configurableGleb Smirnoff2025-07-253-36/+62
| | | | | | | | | | | | | | | | | | | | | | | Before this change snmp_open(3) would always bind(2) client socket to a random "/tmp/snmpXXXXXXXXXXXXXX" name. However, this binding is not required for SOCK_STREAM transport. Also, any attempt to specify a different name would fail, as open_client_local() would blindly rewrite the name to the default. Make this binding optional. If application had initialized snmp_client.local_path, then try to bind to the specified pathname, otherwise perform the random name binding only if we are in the SOCK_DGRAM mode. While here change snmp_client.local_path size to SUNPATHLEN, so that any legitimate local socket name can be used. This requires library version bump. Note that this code has been broken by 81e0e7b9e36d for three years, thus it is known not to be widely used. Reviewed by: harti Differential Revision: https://reviews.freebsd.org/D51070
* libbsnmp: define SNMP_DEFAULT_LOCAL that matches default server configGleb Smirnoff2025-07-173-9/+3
| | | | | | | | | | | | | | | | | | | | | | The default /etc/snmpd.config we install for decades has: begemotSnmpdLocalPortStatus."/var/run/snmpd.sock" = 1 begemotSnmpdLocalPortType."/var/run/snmpd.sock" = 4 However, libbsnmp internally used DEFAULT_LOCAL set to "/var/run/snmp.sock" (note missing "d") to fill server pathname in case if API user didn't provide one. This results with default server config never working with an application that uses default initializer. The libbsnmptools has a workaround for that, it defines internally SNMP_DEFAULT_LOCAL that matches /etc/snmpd.config. Bring this all to an order: - Make a public define SNMP_DEFAULT_LOCAL in libbsnmp. - Point it to what /etc/snmpd.config has in. - Remove workaround from libbsnmptools. Reviewed by: harti Differential Revision: https://reviews.freebsd.org/D51071
* libbsnmp: fix local client socket creationGleb Smirnoff2025-07-171-1/+1
| | | | | | | | | | | | | Revert "bsnmp: Use mkstemp when creating clients local socket" The use of mktemp() was intentional here. We don't want a regular file to be created. If created, it guarantees that following bind(2) would always fail with EADDRINUSE and thus open_client_local() always fails. This reverts commit 81e0e7b9e36d6a25b3af6482811318e085537d2f. Reviewed by: rew, harti Differential Revision: https://reviews.freebsd.org/D51031
* libbsnmp: avoid division by zero with empty passwordGleb Smirnoff2025-01-111-1/+1
| | | | PR: 283909
* bsnmp: Remove "All Rights Reserved" from FreeBSD Foundation copyrightsEd Maste2023-03-032-2/+0
|
* bsnmp: Use mkstemp when creating clients local socketTom Jones2022-03-151-1/+1
| | | | | | | | Reviewed by: harti, rew Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. X-NetApp-PR: #72 Differential Revision: https://reviews.freebsd.org/D34550
* bsnmp: Fix two typos in error messagesGordon Bergling2022-01-261-2/+2
| | | | | | - s/responce/response/ MFC after: 1 week
* Revert "bsnmpclient(3): make it thread-safe"Edward Tomasz Napierala2020-12-293-4/+4
| | | | | | | | | | | | This reverts commit 89e3d5671ba13dceca272d5b159c9bd805f3f504. As pointed out, there are several problems with that commit: 1. The new semantics, while useful for clients where multiple threads use separate contexts, breaks clients which correctly share a single one 2. Change in semantics would require a library version bump 3. It doesn't build with GCC
* bsnmpclient(3): make it thread-safeEdward Tomasz Napierala2020-12-293-4/+4
| | | | | | | Reviewed By: harti Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D27336
* Merge release 1.14 of bsnmp.Hartmut Brandt2020-04-014-54/+130
|\ | | | | | | Notes: svn path=/head/; revision=359512
| * Flatten bsnmp vendor area.Hartmut Brandt2008-12-2016-7871/+0
| | | | | | | | Notes: svn path=/vendor/bsnmp/dist/; revision=186357
* | bsnmp: Fix operator precedence in error check in table_check_responseJustin Hibbits2019-11-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Summary: The ?: operator has a lower precedence than == and &&, so the result will always be recorded as true. Found by gcc8. Reviewed by: ngie, ae Differential Revision: https://reviews.freebsd.org/D22427 Notes: svn path=/head/; revision=354834
* | bsnmp: add asn1 message length validationEd Maste2019-08-061-0/+5
| | | | | | | | | | | | | | | | | | | | admbugs: 780 Submitted by: Guido Vranken, bz Reported by: Guido Vranken Security: CVE-2019-5610 Notes: svn path=/head/; revision=350635
* | Follow the declared behaviour that specifies server string format inAndrey V. Elsukov2019-04-031-63/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | bsnmpclient(3). snmp_parse_server() function accepts string where some fields can be omitted: [trans::][community@][server][:port] "trans" field can be "udp", "udp6", "dgram" and "stream". "community" can be empty string, if it is omitted, the default value will be used. For read_community it is "public", for write_comminity it is "private". "server" field can be hostname, IPv4 address or IPv6 address. IPv6 address should be specified in brackets "[]". If port is omitted, the default value "snmp" will be used for "udp" and "udp6" transports. So, now for bsnmpget(1) and bsnmwalk(1) it is not required to specify all fields in argument of '-s' option. E.g. # bsnmpget -s 127.1 sysName.0 # bsnmpget -s "udp::127.1" sysName.0 # bsnmpget -s "udp::public@127.1" sysName.0 # bsnmpget -s "udp::public@127.1:161" sysName.0 # bsnmpget -s "udp::[::1]" sysName.0 # bsnmpget -s "udp6::[::1]" sysName.0 # bsnmpget -s "[fe80::1%lo0]" sysName.0 PR: 236664 Reported by: olivier MFC after: 1 month Notes: svn path=/head/; revision=345843
* | Add IPv6 transport for bsnmp.Andrey V. Elsukov2019-04-023-74/+402
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds a new table begemotSnmpdTransInetTable that uses the InetAddressType textual convention and can be used to create listening ports for IPv4, IPv6, zoned IPv6 and based on DNS names. It also supports future extension beyond UDP by adding a protocol identifier to the table index. In order to support this gensnmptree had to be modified. Submitted by: harti MFC after: 1 month Relnotes: yes Differential Revision: https://reviews.freebsd.org/D16654 Notes: svn path=/head/; revision=345797
* | Make libbsnmp buildable.Jung-uk Kim2018-09-191-48/+81
| | | | | | | | Notes: svn path=/projects/openssl111/; revision=338769
* | Update bsnmp to version 1.13. This does not bring user-visible changes.Hartmut Brandt2018-07-032-0/+11
| | | | | | | | | | | | | | | | | | | | For developers gensnmptree can now generate functions for enums to convert between enums and strings and to check the validity of a value. The sources in FreeBSD are now in sync with the upstream which allows to bring in IPv6 modifications. Notes: svn path=/head/; revision=335885
* | bsnmp: explicitly test the return value for open_client_{local,udp} in ↵Enji Cooper2017-03-201-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | snmp_open(..) open_client_* returns -1 on failure; 0 on success. Ensure that the return value is 0 -- otherwise exit snmp_open(..). MFC after: 1 week Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=315642
* | bsnmp: don't leak snmp_client.fd in open_client_udp(..) on connect(2) failureEnji Cooper2017-03-201-0/+2
| | | | | | | | | | | | | | | | MFC after: 1 week Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=315641
* | snmp_table_fetch_async: don't leak `work` if snmp_pdu_send(..) failsEnji Cooper2017-01-051-1/+4
| | | | | | | | | | | | | | | | | | MFC after: 1 week Reported by: Coverity CID: 1017276 Notes: svn path=/head/; revision=311390
* | Use calloc instead of malloc with buffers in snmp_{recv,send}_packetEnji Cooper2017-01-041-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This doesn't fix the issue noted in the PR, but at the very least it cleans up the error so it looks a bit more sane, and in the event that bsnmp did wander off into the weeds, the likelihood of it crashing with more sensible output is greater, in my opinion MFC counter set high so I have enough time to resolve the real underlying bug in bsnmpwalk MFC after: 1 month PR: 215721 Notes: svn path=/head/; revision=311263
* | Fix spelling errors; bump .Dd for the changeEnji Cooper2017-01-011-3/+3
| | | | | | | | | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=311003
* | Bump .Dd for the spelling and .Nm updatesEnji Cooper2017-01-011-1/+1
| | | | | | | | | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=311001
* | Fix spelling errorsEnji Cooper2017-01-011-6/+6
| | | | | | | | | | | | | | | | MFC after: 3 days Reported by: igor Notes: svn path=/head/; revision=311000
* | bsnmpclient(3) also documents snmp_client_init, snmp_client_set_host,Enji Cooper2017-01-011-0/+3
| | | | | | | | | | | | | | | | | | and snmp_client_set_port. Add them to the NAME section MFC after: 3 days Notes: svn path=/head/; revision=310999
* | snmp_discover_engine: fix up req/resp (PDU object) handling a bitEnji Cooper2016-12-311-1/+6
| | | | | | | | | | | | | | | | | | | | | | - Call snmp_pdu_free on req and resp when done with the objects - Call snmp_pdu_free on req before calling snmp_pdu_create on it again MFC after: 1 week Notes: svn path=/head/; revision=310988
* | Unbreak the build by passing the string to strdup, not its lengthEnji Cooper2016-12-311-1/+1
| | | | | | | | | | | | | | | | | | MFC after: 1 week X-MFC with: r310931 Pointyhat to: ngie Notes: svn path=/head/; revision=310942
* | Use strdup in snmp_parse_server(..) when possible instead of malloc+strcpyEnji Cooper2016-12-311-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | This simplifies the code and mutes a Coverity warning about sc->cport being improperly allocated Reported by: Coverity CID: 1018247 MFC after: 1 week Notes: svn path=/head/; revision=310931
* | Prevent improper memory accesses after calling snmp_pdu_free and snmp_value_freeEnji Cooper2016-12-291-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | snmp_pdu_free: set pdu->nbindings to 0 to limit the damage that could happen if a pdu was reused after calling the function, and as both stack and heap allocation types are used in contrib/bsnmp and usr.sbin/bsnmpd. snmp_value_free: NULL out value->v.octetstring.octets after calling free on it to prevent a double-free from occurring. MFC after: 2 weeks Notes: svn path=/head/; revision=310729
* | style(9): snmp_send_packet(..): fix whitespaceEnji Cooper2016-12-281-3/+3
| | | | | | | | | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=310662
* | style(9): fix whitespace in pdu_encode_secparams(..)Enji Cooper2016-12-281-2/+2
| | | | | | | | | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=310660
* | style(9): clean up trailing whitespaceEnji Cooper2016-12-2716-47/+47
| | | | | | | | | | | | | | MFC after: 3 weeks Notes: svn path=/head/; revision=310648
* | Be more strict about IpAddress type in snmp_value_parse(..)Enji Cooper2016-12-241-18/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Use inet_pton with AF_INET instead of doing longhand with sscanf. - Use gethostbyname2 with AF_INET to ensure that the hostname isn't accidentally parsed with another address family, e.g. AF_INET6. NB: IpAddress per RFC-2578 is IPv4 only. Work is in progress to add the InetAddress type and friends documented in RFC-4001 and elsewhere (which supports IPv4, IPv6, and more). MFC after: 2 weeks Notes: svn path=/head/; revision=310501
* | Minor style(9) fixesEnji Cooper2016-12-241-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | - Trailing whitespace cleanup - Sort variables in snmp_dialog(..) by alignment No functional change MFC after: 1 week Notes: svn path=/head/; revision=310500
* | Sort #includesEnji Cooper2016-12-241-4/+4
| | | | | | | | | | | | | | | | | | No functional change MFC after: 3 days Notes: svn path=/head/; revision=310499
* | Clean up trailing and leading whitespaceEnji Cooper2016-12-181-25/+25
| | | | | | | | | | | | | | | | | | Fix variable type alignment in snmp_dialog(..) MFC after: 1 week Notes: svn path=/head/; revision=310202
* | Reply to a snmpEngineID discovery PDU with a Report PDU as per theShteryana Shopova2016-11-101-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | requirements of RFC 3414 section 4. PR: 174974 Submitted by: pguyot@kallisys.net Reported by: several people Reviewed by: bz@ Notes: svn path=/head/; revision=308490
* | Fix a regression introduced in SVN r256678 that breaks USM header parsingShteryana Shopova2016-10-241-1/+1
| | | | | | | | | | | | | | Reviewed by: bz@ Notes: svn path=/head/; revision=307882
* | Fix the function signatures when MK_CRYPT == no for snmp_get_local_keys andEnji Cooper2014-12-271-2/+2
| | | | | | | | | | | | | | | | | | | | snmp_passwd_to_keys MFC after: 1 week Reported by: Beeblebrox <zaphod@berentweb.com> Notes: svn path=/head/; revision=276319
* | Fix a problem with OBJECT IDENTIFIER encoding: need to check theHartmut Brandt2014-01-211-1/+1
| | | | | | | | | | | | | | | | second subid to be less than 40, not the first when the first subid is 0 or 1. Notes: svn path=/head/; revision=260986
* | Fix bsnmpd remote denial of service vulnerability.Xin LI2014-01-141-0/+5
| | | | | | | | | | | | | | | | | | | | Reported by: dinoex Submitted by: harti Security: FreeBSD-SA-14:01.bsnmpd Security: CVE-2014-1452 Notes: svn path=/head/; revision=260636
* | Fix the -Wconversion warnings produced when compiling the SNMP agent.Shteryana Shopova2013-10-171-3/+19
| | | | | | | | Notes: svn path=/head/; revision=256680
* | Fix SNMP Error response PDUs and properly encode them when using v3 ↵Shteryana Shopova2013-10-173-8/+49
| | | | | | | | | | | | | | | | | | auth/encryption. Reported by: harti@ Notes: svn path=/head/; revision=256678
* | Clean some 'svn:executable' properties in the tree.Pedro F. Giffuni2013-01-261-0/+0
| | | | | | | | | | | | | | | | Submitted by: Christoph Mallon MFC after: 3 days Notes: svn path=/head/; revision=245952
* | Remove end of line whitespace.Joel Dahl2012-06-171-2/+2
| | | | | | | | Notes: svn path=/head/; revision=237194
* | Minor mdoc fixes.Joel Dahl2012-06-172-4/+1
| | | | | | | | Notes: svn path=/head/; revision=237193
* | Bring in a SNMP module that allows configuration of SNMPv3 Notification targets.Shteryana Shopova2010-12-207-26/+98
| | | | | | | | | | | | | | | | | | Sponsored by: The FreeBSD Foundation Reviewed by: philip Approved by: philip Notes: svn path=/head/; revision=216594
* | Silence the compiler warnings in libbsnmp by removing several (now)Shteryana Shopova2010-12-163-21/+18
| | | | | | | | | | | | | | | | | | | | unsed parameters. Sponsored by: The FreeBSD Foundation Reviewed by: philip@ Notes: svn path=/head/; revision=216482