The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=665877ced9ea53f838f80176739a8621a61d40c6
commit 665877ced9ea53f838f80176739a8621a61d40c6 Author: Gleb Smirnoff <gleb...@freebsd.org> AuthorDate: 2025-07-17 15:59:44 +0000 Commit: Gleb Smirnoff <gleb...@freebsd.org> CommitDate: 2025-07-17 15:59:44 +0000 libbsnmp: define SNMP_DEFAULT_LOCAL that matches default server config 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 --- contrib/bsnmp/lib/snmpclient.c | 10 ++-------- contrib/bsnmp/lib/snmpclient.h | 1 + contrib/bsnmp/lib/snmppriv.h | 1 - usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c | 9 --------- usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.h | 1 - 5 files changed, 3 insertions(+), 19 deletions(-) diff --git a/contrib/bsnmp/lib/snmpclient.c b/contrib/bsnmp/lib/snmpclient.c index a7556527ad51..d5d4af998a0c 100644 --- a/contrib/bsnmp/lib/snmpclient.c +++ b/contrib/bsnmp/lib/snmpclient.c @@ -981,14 +981,8 @@ open_client_local(const char *path) char *ptr; int stype; - if (snmp_client.chost == NULL) { - if ((snmp_client.chost = malloc(1 + sizeof(DEFAULT_LOCAL))) - == NULL) { - seterr(&snmp_client, "%s", strerror(errno)); - return (-1); - } - strcpy(snmp_client.chost, DEFAULT_LOCAL); - } + if (snmp_client.chost == NULL && path == NULL) + path = SNMP_DEFAULT_LOCAL; if (path != NULL) { if ((ptr = malloc(1 + strlen(path))) == NULL) { seterr(&snmp_client, "%s", strerror(errno)); diff --git a/contrib/bsnmp/lib/snmpclient.h b/contrib/bsnmp/lib/snmpclient.h index a19bdb2ea653..662dc7c4a204 100644 --- a/contrib/bsnmp/lib/snmpclient.h +++ b/contrib/bsnmp/lib/snmpclient.h @@ -40,6 +40,7 @@ #define SNMP_STRERROR_LEN 200 +#define SNMP_DEFAULT_LOCAL "/var/run/snmpd.sock" #define SNMP_LOCAL_PATH "/tmp/snmpXXXXXXXXXXXXXX" diff --git a/contrib/bsnmp/lib/snmppriv.h b/contrib/bsnmp/lib/snmppriv.h index 5b66992ca985..6ed51cf39369 100644 --- a/contrib/bsnmp/lib/snmppriv.h +++ b/contrib/bsnmp/lib/snmppriv.h @@ -44,4 +44,3 @@ enum snmp_code snmp_pdu_decrypt(const struct snmp_pdu *); #define DEFAULT_HOST "localhost" #define DEFAULT_PORT "snmp" -#define DEFAULT_LOCAL "/var/run/snmp.sock" diff --git a/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c b/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c index fb09e1ac785e..b4613763fff5 100644 --- a/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c +++ b/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c @@ -790,15 +790,6 @@ parse_server(char *opt_arg) if (snmp_parse_server(&snmp_client, opt_arg) < 0) return (-1); - if (snmp_client.trans > SNMP_TRANS_UDP && snmp_client.chost == NULL) { - if ((snmp_client.chost = malloc(strlen(SNMP_DEFAULT_LOCAL) + 1)) - == NULL) { - syslog(LOG_ERR, "malloc() failed: %s", strerror(errno)); - return (-1); - } - strcpy(snmp_client.chost, SNMP_DEFAULT_LOCAL); - } - return (2); } diff --git a/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.h b/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.h index 2874f311fbd0..54a087491a4f 100644 --- a/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.h +++ b/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.h @@ -43,7 +43,6 @@ #define MAX_BUFF_SIZE (ASN_MAXOCTETSTRING + 50) #define SNMP_DEFS_DIR "/usr/share/snmp/defs/" -#define SNMP_DEFAULT_LOCAL "/var/run/snmpd.sock" #define SNMP_MAX_REPETITIONS 10