[Midnightbsd-cvs] src [10990] trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.h: update
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Fri Jun 15 16:40:13 EDT 2018
Revision: 10990
http://svnweb.midnightbsd.org/src/?rev=10990
Author: laffer1
Date: 2018-06-15 16:40:12 -0400 (Fri, 15 Jun 2018)
Log Message:
-----------
update
Modified Paths:
--------------
trunk/usr.sbin/bsnmpd/tools/libbsnmptools/Makefile
trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c
trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c
trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c
trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.h
trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c
trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.h
Property Changed:
----------------
trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c
Modified: trunk/usr.sbin/bsnmpd/tools/libbsnmptools/Makefile
===================================================================
--- trunk/usr.sbin/bsnmpd/tools/libbsnmptools/Makefile 2018-06-15 20:38:07 UTC (rev 10989)
+++ trunk/usr.sbin/bsnmpd/tools/libbsnmptools/Makefile 2018-06-15 20:40:12 UTC (rev 10990)
@@ -1,6 +1,7 @@
-#
# $MidnightBSD$
#
+# $FreeBSD: stable/10/usr.sbin/bsnmpd/tools/libbsnmptools/Makefile 216377 2010-12-11 13:24:01Z syrinx $
+#
.PATH: ${.CURDIR}
Modified: trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c
===================================================================
--- trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c 2018-06-15 20:38:07 UTC (rev 10989)
+++ trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c 2018-06-15 20:40:12 UTC (rev 10990)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2006 The FreeBSD Project
* All rights reserved.
@@ -26,7 +27,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c 310903 2016-12-31 10:34:09Z ngie $
*/
/*
@@ -53,7 +54,7 @@
* subtype := STRING
*
* enum := ENUM '(' value ')'
- *
+ *
* bits := BITS '(' value ')'
*
* value := INT STRING | INT STRING value
@@ -140,9 +141,9 @@
LIST_ENTRY(input) link;
};
-LIST_HEAD(, input) inputs = LIST_HEAD_INITIALIZER(inputs);
-struct input *input = NULL;
-int32_t pbchar = -1;
+static LIST_HEAD(, input) inputs = LIST_HEAD_INITIALIZER(inputs);
+static struct input *input = NULL;
+static int32_t pbchar = -1;
#define MAX_PATHS 100
@@ -301,7 +302,7 @@
{ NULL, 0, 0 }
};
-struct {
+static struct {
/* Current OID type, regarding table membership. */
enum snmp_tbl_entry tbl_type;
/* A pointer to a structure in table list to add to its members. */
@@ -308,11 +309,11 @@
struct snmp_index_entry *table_idx;
} table_data;
-struct asn_oid current_oid;
-char nexttok[MAXSTR];
-u_long val; /* integer values */
-int32_t all_cond; /* all conditions are true */
-int32_t saved_token = -1;
+static struct asn_oid current_oid;
+static char nexttok[MAXSTR];
+static u_long val; /* integer values */
+static int32_t all_cond; /* all conditions are true */
+static int32_t saved_token = -1;
/* Prepare the global data before parsing a new file. */
static void
@@ -483,7 +484,7 @@
switch (te) {
case ENTRY_NONE:
if (table_data.tbl_type == ENTRY_NONE)
- return (NULL);
+ return (NULL);
if (table_data.tbl_type == ENTRY_INDEX)
table_data.table_idx = NULL;
table_data.tbl_type--;
@@ -513,7 +514,7 @@
}
static int32_t
-parse_enum(struct snmp_toolinfo *snmptoolctx, enum tok *tok,
+parse_enum(struct snmp_toolinfo *snmptoolctx, int32_t *tok,
struct enum_pairs *enums)
{
while ((*tok = gettoken(snmptoolctx)) == TOK_STR) {
@@ -532,7 +533,7 @@
}
static int32_t
-parse_subtype(struct snmp_toolinfo *snmptoolctx, enum tok *tok,
+parse_subtype(struct snmp_toolinfo *snmptoolctx, int32_t *tok,
enum snmp_tc *tc)
{
if ((*tok = gettoken(snmptoolctx)) != TOK_STR) {
@@ -539,7 +540,7 @@
warnx("subtype expected after '|'");
return (-1);
}
-
+
*tc = snmp_get_tc(nexttok);
*tok = gettoken(snmptoolctx);
@@ -547,7 +548,7 @@
}
static int32_t
-parse_type(struct snmp_toolinfo *snmptoolctx, enum tok *tok,
+parse_type(struct snmp_toolinfo *snmptoolctx, int32_t *tok,
enum snmp_tc *tc, struct enum_pairs **snmp_enum)
{
int32_t syntax, mem;
@@ -630,17 +631,15 @@
static int32_t
snmp_import_table(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *obj)
{
- int32_t i;
+ int32_t i, tok;
enum snmp_tc tc;
- enum tok tok;
struct snmp_index_entry *entry;
- if ((entry = malloc(sizeof(struct snmp_index_entry))) == NULL) {
+ if ((entry = calloc(1, sizeof(struct snmp_index_entry))) == NULL) {
syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
return (-1);
}
- memset(entry, 0, sizeof(struct snmp_index_entry));
STAILQ_INIT(&(entry->index_list));
for (i = 0, tok = gettoken(snmptoolctx); i < SNMP_INDEXES_MAX; i++) {
@@ -693,6 +692,7 @@
/* Same entry already present in lists. */
free(entry->string);
free(entry);
+ return (0);
}
(void) snmp_import_update_table(ENTRY_INDEX, entry);
@@ -704,7 +704,7 @@
* Read everything after the syntax type that is certainly a leaf OID info.
*/
static int32_t
-snmp_import_leaf(struct snmp_toolinfo *snmptoolctx, enum tok *tok,
+snmp_import_leaf(struct snmp_toolinfo *snmptoolctx, int32_t *tok,
struct snmp_oid2str *oid2str)
{
int32_t i, syntax;
@@ -757,25 +757,23 @@
{
char *string;
int i;
- enum tok tok;
+ int32_t tok;
struct snmp_oid2str *oid2str;
if (snmp_import_head(snmptoolctx) < 0)
return (-1);
- if ((oid2str = malloc(sizeof(struct snmp_oid2str))) == NULL) {
- syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
+ if ((oid2str = calloc(1, sizeof(struct snmp_oid2str))) == NULL) {
+ syslog(LOG_ERR, "calloc() failed: %s", strerror(errno));
return (-1);
}
- if ((string = malloc(strlen(nexttok) + 1)) == NULL) {
- syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
+ if ((string = strdup(nexttok)) == NULL) {
+ syslog(LOG_ERR, "strdup() failed: %s", strerror(errno));
free(oid2str);
return (-1);
}
- memset(oid2str, 0, sizeof(struct snmp_oid2str));
- strlcpy(string, nexttok, strlen(nexttok) + 1);
oid2str->string = string;
oid2str->strlen = strlen(nexttok);
@@ -809,7 +807,7 @@
if (snmp_suboid_append(¤t_oid, (asn_subid_t) val) < 0)
goto error;
- /*
+ /*
* Ignore the error for nodes since the .def files currently
* contain different strings for 1.3.6.1.2.1 - mibII. Only make
* sure the memory is freed and don't complain.
@@ -856,7 +854,7 @@
}
static int32_t
-snmp_import_tree(struct snmp_toolinfo *snmptoolctx, enum tok *tok)
+snmp_import_tree(struct snmp_toolinfo *snmptoolctx, int32_t *tok)
{
while (*tok != TOK_EOF) {
switch (*tok) {
@@ -882,7 +880,7 @@
}
static int32_t
-snmp_import_top(struct snmp_toolinfo *snmptoolctx, enum tok *tok)
+snmp_import_top(struct snmp_toolinfo *snmptoolctx, int32_t *tok)
{
enum snmp_tc tc;
struct enum_type *t;
@@ -939,7 +937,7 @@
snmp_import(struct snmp_toolinfo *snmptoolctx)
{
int i;
- enum tok tok;
+ int32_t tok;
tok = gettoken(snmptoolctx);
Modified: trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c
===================================================================
--- trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c 2018-06-15 20:38:07 UTC (rev 10989)
+++ trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c 2018-06-15 20:40:12 UTC (rev 10990)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2006 The FreeBSD Project
* All rights reserved.
@@ -26,10 +27,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c 310903 2016-12-31 10:34:09Z ngie $
*/
-#include <sys/param.h>
+#include <sys/param.h>
#include <sys/queue.h>
#include <sys/uio.h>
@@ -47,7 +48,6 @@
#include "bsnmptc.h"
#include "bsnmptools.h"
-extern int _bsnmptools_debug;
#define DEBUG if (_bsnmptools_debug) fprintf
/* Allocate memory and initialize list. */
@@ -56,12 +56,11 @@
{
struct snmp_mappings *m;
- if ((m = malloc(sizeof(struct snmp_mappings))) == NULL) {
+ if ((m = calloc(1, sizeof(struct snmp_mappings))) == NULL) {
syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
return (NULL);
}
- memset(m, 0, sizeof(struct snmp_mappings));
return (m);
}
@@ -269,21 +268,18 @@
{
struct enum_pair *e_new;
- if ((e_new = malloc(sizeof(struct enum_pair))) == NULL) {
- syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
+ if ((e_new = calloc(1, sizeof(struct enum_pair))) == NULL) {
+ syslog(LOG_ERR, "calloc() failed: %s", strerror(errno));
return (-1);
}
- memset(e_new, 0, sizeof(struct enum_pair));
-
- if ((e_new->enum_str = malloc(strlen(enum_str) + 1)) == NULL) {
- syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
+ if ((e_new->enum_str = strdup(enum_str)) == NULL) {
+ syslog(LOG_ERR, "strdup() failed: %s", strerror(errno));
free(e_new);
return (-1);
}
e_new->enum_val = enum_val;
- strlcpy(e_new->enum_str, enum_str, strlen(enum_str) + 1);
STAILQ_INSERT_TAIL(headp, e_new, link);
return (1);
@@ -482,13 +478,11 @@
{
struct index *idx;
- if ((idx = malloc(sizeof(struct index))) == NULL) {
+ if ((idx = calloc(1, sizeof(struct index))) == NULL) {
syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
return (-1);
}
- memset(idx, 0, sizeof(struct index));
-
if (snmp_index_insert(headp, idx) < 0) {
free(idx);
return (-1);
@@ -558,18 +552,16 @@
{
struct enum_type *enum_tc;
- if ((enum_tc = malloc(sizeof(struct enum_type))) == NULL) {
+ if ((enum_tc = calloc(1, sizeof(struct enum_type))) == NULL) {
syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
return (NULL);
}
- memset(enum_tc, 0, sizeof(struct enum_type));
- if ((enum_tc->name = malloc(strlen(name) + 1)) == NULL) {
+ if ((enum_tc->name = strdup(name)) == NULL) {
syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
free(enum_tc);
return (NULL);
}
- strlcpy(enum_tc->name, name, strlen(name) + 1);
return (enum_tc);
}
@@ -645,7 +637,7 @@
}
}
-void
+void
snmp_mapping_dump(struct snmp_toolinfo *snmptoolctx /* int bits */)
{
if (!_bsnmptools_debug)
Modified: trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c
===================================================================
--- trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c 2018-06-15 20:38:07 UTC (rev 10989)
+++ trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c 2018-06-15 20:40:12 UTC (rev 10990)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2006 The FreeBSD Project
* All rights reserved.
@@ -28,10 +29,10 @@
*
* Textual conventions for OctetStrings
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c 311595 2017-01-07 08:46:16Z ngie $
*/
-#include <sys/param.h>
+#include <sys/param.h>
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/uio.h>
@@ -93,7 +94,7 @@
static char *snmp_bits2oct(char *str, struct asn_oid *oid);
static int32_t parse_bits(struct snmp_value *value, char *string);
-struct snmp_text_conv {
+static struct snmp_text_conv {
enum snmp_tc tc;
const char *tc_str;
int32_t len;
@@ -158,7 +159,7 @@
uint32_t tc_len;
char * buf;
- if (tc < 0 || tc > SNMP_UNKNOWN)
+ if (tc > SNMP_UNKNOWN)
tc = SNMP_UNKNOWN;
if (text_convs[tc].len > 0)
@@ -183,7 +184,7 @@
char *
snmp_tc2oid(enum snmp_tc tc, char *str, struct asn_oid *oid)
{
- if (tc < 0 || tc > SNMP_UNKNOWN)
+ if (tc > SNMP_UNKNOWN)
tc = SNMP_UNKNOWN;
return (text_convs[tc].tc2oid(str, oid));
@@ -192,7 +193,7 @@
int32_t
snmp_tc2oct(enum snmp_tc tc, struct snmp_value *value, char *string)
{
- if (tc < 0 || tc > SNMP_UNKNOWN)
+ if (tc > SNMP_UNKNOWN)
tc = SNMP_UNKNOWN;
return (text_convs[tc].tc2oct(value, string));
@@ -266,13 +267,13 @@
return (-1);
}
- value->v.octetstring.len = len;
-
- if((value->v.octetstring.octets = malloc(len)) == NULL) {
- syslog(LOG_ERR,"malloc failed: %s", strerror(errno));
+ if ((value->v.octetstring.octets = malloc(len)) == NULL) {
+ value->v.octetstring.len = 0;
+ syslog(LOG_ERR, "malloc failed: %s", strerror(errno));
return (-1);
}
+ value->v.octetstring.len = len;
memcpy(value->v.octetstring.octets, val, len);
value->syntax = SNMP_SYNTAX_OCTETSTRING;
@@ -338,8 +339,9 @@
snmp_date2asn_oid(char *str, struct asn_oid *oid)
{
char *endptr, *ptr;
+ static const char UTC[3] = "UTC";
+ int32_t saved_errno;
uint32_t v;
- int32_t saved_errno;
if (snmp_suboid_append(oid, (asn_subid_t) SNMP_DATETIME_OCTETS) < 0)
return (NULL);
@@ -363,6 +365,7 @@
/* 'MM-' */
ptr = endptr + 1;
saved_errno = errno;
+ errno = 0;
v = strtoul(ptr, &endptr, 10);
if (errno != 0)
goto error;
@@ -376,6 +379,7 @@
/* 'DD,' */
ptr = endptr + 1;
saved_errno = errno;
+ errno = 0;
v = strtoul(ptr, &endptr, 10);
if (errno != 0)
goto error;
@@ -389,6 +393,7 @@
/* 'HH:' */
ptr = endptr + 1;
saved_errno = errno;
+ errno = 0;
v = strtoul(ptr, &endptr, 10);
if (errno != 0)
goto error;
@@ -402,6 +407,7 @@
/* 'MM:' */
ptr = endptr + 1;
saved_errno = errno;
+ errno = 0;
v = strtoul(ptr, &endptr, 10);
if (errno != 0)
goto error;
@@ -415,6 +421,7 @@
/* 'SS.' */
ptr = endptr + 1;
saved_errno = errno;
+ errno = 0;
v = strtoul(ptr, &endptr, 10);
if (errno != 0)
goto error;
@@ -428,6 +435,7 @@
/* 'M(mseconds),' */
ptr = endptr + 1;
saved_errno = errno;
+ errno = 0;
v = strtoul(ptr, &endptr, 10);
if (errno != 0)
goto error;
@@ -440,8 +448,8 @@
/* 'UTC' - optional */
ptr = endptr + 1;
- if (*ptr == 'U' && *(ptr + 1) == 'T' && *(ptr + 1) == 'C')
- ptr += 3;
+ if (strncmp(ptr, UTC, sizeof(UTC)) == 0)
+ ptr += sizeof(UTC);
/* '+/-' */
if (*ptr == '-' || *ptr == '+') {
@@ -453,6 +461,7 @@
/* 'HH:' */
ptr = endptr + 1;
saved_errno = errno;
+ errno = 0;
v = strtoul(ptr, &endptr, 10);
if (errno != 0)
goto error;
@@ -466,6 +475,7 @@
/* 'MM' - last one - ignore endptr here. */
ptr = endptr + 1;
saved_errno = errno;
+ errno = 0;
v = strtoul(ptr, &endptr, 10);
if (errno != 0)
goto error;
@@ -561,7 +571,7 @@
date[10] = v;
if ((sv->v.octetstring.octets = malloc(SNMP_DATETIME_OCTETS)) == NULL) {
- warnx("malloc() failed - %s", strerror(errno));
+ warn("malloc() failed");
return (-1);
}
@@ -617,7 +627,7 @@
return (NULL);
}
if (*endptr != ':') {
- warnx("Failed adding oid - %s",str);
+ warnx("Failed adding oid - %s", str);
return (NULL);
}
if (snmp_suboid_append(oid, (asn_subid_t) v) < 0)
@@ -670,7 +680,7 @@
phys_addr[5] = v;
if ((sv->v.octetstring.octets = malloc(SNMP_PHYSADDR_OCTETS)) == NULL) {
- syslog(LOG_ERR,"malloc failed: %s", strerror(errno));
+ syslog(LOG_ERR, "malloc failed: %s", strerror(errno));
return (-1);
}
@@ -724,6 +734,7 @@
ptr = str;
saved_errno = errno;
+ errno = 0;
v = strtoul(ptr, &endptr, 10);
if (errno != 0 || (v / 1000) > 9) {
warnx("Integer value %s not supported", str);
@@ -733,7 +744,7 @@
errno = saved_errno;
if (*endptr != '.') {
- warnx("Failed adding oid - %s",str);
+ warnx("Failed adding oid - %s", str);
return (NULL);
}
@@ -748,6 +759,7 @@
ptr = endptr + 1;
saved_errno = errno;
+ errno = 0;
v = strtoul(ptr, &endptr, 10);
if (errno != 0 || (v / 1000) > 9) {
warnx("Integer value %s not supported", str);
@@ -775,13 +787,14 @@
uint8_t ntp_ts[SNMP_NTP_TS_OCTETS];
saved_errno = errno;
+ errno = 0;
v = strtoul(val, &endptr, 10);
if (errno != 0 || (v / 1000) > 9) {
- saved_errno = errno;
+ errno = saved_errno;
warnx("Integer value %s not supported", val);
return (-1);
} else
- saved_errno = errno;
+ errno = saved_errno;
if (*endptr != '.') {
warnx("Failed reading octet - %s", val);
@@ -796,13 +809,14 @@
val = endptr + 1;
saved_errno = errno;
+ errno = 0;
v = strtoul(val, &endptr, 10);
if (errno != 0 || (v / 1000) > 9) {
- saved_errno = errno;
+ errno = saved_errno;
warnx("Integer value %s not supported", val);
return (-1);
} else
- saved_errno = errno;
+ errno = saved_errno;
for (i = 0, d = 1000; i < 4; i++) {
ntp_ts[i + 4] = v / d;
@@ -811,7 +825,7 @@
}
if ((sv->v.octetstring.octets = malloc(SNMP_NTP_TS_OCTETS)) == NULL) {
- syslog(LOG_ERR,"malloc failed: %s", strerror(errno));
+ syslog(LOG_ERR, "malloc failed: %s", strerror(errno));
return (-1);
}
@@ -878,8 +892,8 @@
ptr = str;
/* Read the priority. */
saved_errno = errno;
+ errno = 0;
v = strtoul(ptr, &endptr, 10);
- errno = 0;
if (v > SNMP_MAX_BRIDGE_PRIORITY || errno != 0 || *endptr != '.') {
errno = saved_errno;
@@ -896,6 +910,7 @@
ptr = endptr + 1;
for (i = 0; i < 5; i++) {
saved_errno = errno;
+ errno = 0;
v = strtoul(ptr, &endptr, 16);
errno = saved_errno;
if (v > 0xff) {
@@ -913,6 +928,7 @@
/* The last one - don't check the ending char here. */
saved_errno = errno;
+ errno = 0;
v = strtoul(ptr, &endptr, 16);
errno = saved_errno;
if (v > 0xff) {
@@ -928,17 +944,15 @@
static int32_t
parse_bridge_id(struct snmp_value *sv, char *string)
{
- char *ptr, *endptr;
+ char *endptr;
int32_t i, saved_errno;
uint32_t v;
uint8_t bridge_id[SNMP_BRIDGEID_OCTETS];
- ptr = string;
/* Read the priority. */
saved_errno = errno;
errno = 0;
v = strtoul(string, &endptr, 10);
- errno = saved_errno;
if (v > SNMP_MAX_BRIDGE_PRIORITY || errno != 0 || *endptr != '.') {
errno = saved_errno;
@@ -974,7 +988,7 @@
bridge_id[7] = v;
if ((sv->v.octetstring.octets = malloc(SNMP_BRIDGEID_OCTETS)) == NULL) {
- syslog(LOG_ERR,"malloc failed: %s", strerror(errno));
+ syslog(LOG_ERR, "malloc failed: %s", strerror(errno));
return (-1);
}
@@ -1026,8 +1040,8 @@
ptr = str;
/* Read the priority. */
saved_errno = errno;
+ errno = 0;
v = strtoul(ptr, &endptr, 10);
- errno = 0;
if (v > SNMP_MAX_BPORT_PRIORITY || errno != 0 || *endptr != '.') {
errno = saved_errno;
@@ -1039,6 +1053,7 @@
return (NULL);
saved_errno = errno;
+ errno = 0;
v = strtoul(ptr, &endptr, 16);
errno = saved_errno;
@@ -1056,17 +1071,15 @@
static int32_t
parse_bport_id(struct snmp_value *value, char *string)
{
- char *ptr, *endptr;
+ char *endptr;
int saved_errno;
uint32_t v;
uint8_t bport_id[SNMP_BPORT_OCTETS];
- ptr = string;
/* Read the priority. */
saved_errno = errno;
errno = 0;
v = strtoul(string, &endptr, 10);
- errno = saved_errno;
if (v > SNMP_MAX_BPORT_PRIORITY || errno != 0 || *endptr != '.') {
errno = saved_errno;
@@ -1086,7 +1099,7 @@
bport_id[1] = v;
if ((value->v.octetstring.octets = malloc(SNMP_BPORT_OCTETS)) == NULL) {
- syslog(LOG_ERR,"malloc failed: %s", strerror(errno));
+ syslog(LOG_ERR, "malloc failed: %s", strerror(errno));
return (-1);
}
@@ -1131,7 +1144,7 @@
**************************************************************
* TODO: FIXME!!! syrinx: Since we do not support checking the
* consistency of a varbinding based on the value of a previous
- * one, try to guess the type of address based on the
+ * one, try to guess the type of address based on the
* OctetString SIZE - 4 for IPv4, 16 for IPv6, others currently
* not supported.
*/
@@ -1166,7 +1179,7 @@
}
if (inet_ntop(af, ip, buf, SNMP_INADDRS_STRSZ) == NULL) {
- warnx("inet_ntop failed - %s", strerror(errno));
+ warn("inet_ntop failed");
return (NULL);
}
@@ -1174,13 +1187,13 @@
}
static char *
-snmp_inetaddr2oct(char *str, struct asn_oid *oid)
+snmp_inetaddr2oct(char *str __unused, struct asn_oid *oid __unused)
{
return (NULL);
}
static int32_t
-parse_inetaddr(struct snmp_value *value, char *string)
+parse_inetaddr(struct snmp_value *value __unused, char *string __unused)
{
return (-1);
}
@@ -1218,7 +1231,7 @@
v = strtoull(str, &endptr, 16);
if (errno != 0) {
- warnx("Bad BITS value %s - %s", str, strerror(errno));
+ warn("Bad BITS value %s", str);
errno = saved_errno;
return (NULL);
}
@@ -1258,7 +1271,7 @@
v = strtoull(string, &endptr, 16);
if (errno != 0) {
- warnx("Bad BITS value %s - %s", string, strerror(errno));
+ warn("Bad BITS value %s", string);
errno = saved_errno;
return (-1);
}
Modified: trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.h
===================================================================
--- trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.h 2018-06-15 20:38:07 UTC (rev 10989)
+++ trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.h 2018-06-15 20:40:12 UTC (rev 10990)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2006 The FreeBSD Project
* All rights reserved.
@@ -28,7 +29,7 @@
*
* Textual conventions for snmp
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.h 216295 2010-12-08 14:30:25Z syrinx $
*/
#ifndef _BSNMP_TEXT_CONV_H_
Modified: trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c
===================================================================
--- trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c 2018-06-15 20:38:07 UTC (rev 10989)
+++ trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c 2018-06-15 20:40:12 UTC (rev 10990)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2005-2006 The FreeBSD Project
* All rights reserved.
@@ -28,10 +29,10 @@
*
* Helper functions for snmp client tools
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c 311595 2017-01-07 08:46:16Z ngie $
*/
-#include <sys/param.h>
+#include <sys/param.h>
#include <sys/queue.h>
#include <sys/uio.h>
@@ -87,7 +88,7 @@
{ "General error", SNMP_ERR_GENERR },
{ "No access", SNMP_ERR_NO_ACCESS },
{ "Wrong type", SNMP_ERR_WRONG_TYPE },
- { "Wrong lenght", SNMP_ERR_WRONG_LENGTH },
+ { "Wrong length", SNMP_ERR_WRONG_LENGTH },
{ "Wrong encoding", SNMP_ERR_WRONG_ENCODING },
{ "Wrong value", SNMP_ERR_WRONG_VALUE },
{ "No creation", SNMP_ERR_NO_CREATION },
@@ -117,7 +118,7 @@
{ "Gauge", SNMP_SYNTAX_GAUGE },
{ "TimeTicks", SNMP_SYNTAX_TIMETICKS },
{ "Counter64", SNMP_SYNTAX_COUNTER64 },
- { "Unknown", SNMP_SYNTAX_UNKNOWN },
+ { "Unknown", SNMP_SYNTAX_UNKNOWN },
};
int
@@ -132,6 +133,7 @@
snmptoolctx->flags = SNMP_PDU_GET; /* XXX */
SLIST_INIT(&snmptoolctx->filelist);
snmp_client_init(&snmp_client);
+ SET_MAXREP(snmptoolctx, SNMP_MAX_REPETITIONS);
if (add_filename(snmptoolctx, bsnmpd_defs, &IsoOrgDod_OID, 0) < 0)
warnx("Error adding file %s to list", bsnmpd_defs);
@@ -176,7 +178,7 @@
if ((slen = strlen(str)) > MAXSTR)
slen = MAXSTR - 1;
if ((snmptoolctx->passwd = malloc(slen + 1)) == NULL) {
- warnx("malloc() failed - %s", strerror(errno));
+ warn("malloc() failed");
return (-1);
}
if (slen > 0)
@@ -188,7 +190,7 @@
#define OBJECT_IDX_LIST(o) o->info->table_idx->index_list
-/*
+/*
* Walk through the file list and import string<->oid mappings from each file.
*/
int32_t
@@ -227,12 +229,12 @@
}
/*
- * Add a filename to the file list - the initail idea of keeping a list with all
+ * Add a filename to the file list - the initial idea of keeping a list with all
* files to read OIDs from was that an application might want to have loaded in
* memory the OIDs from a single file only and when done with them read the OIDs
* from another file. This is not used yet but might be a good idea at some
* point. Size argument is number of bytes in string including trailing '\0',
- * not string lenght.
+ * not string length.
*/
int32_t
add_filename(struct snmp_toolinfo *snmptoolctx, const char *filename,
@@ -250,22 +252,19 @@
return (0);
}
- if ((fstring = malloc(strlen(filename) + 1)) == NULL) {
- warnx("malloc() failed - %s", strerror(errno));
+ if ((fstring = strdup(filename)) == NULL) {
+ warn("strdup() failed");
return (-1);
}
- if ((entry = malloc(sizeof(struct fname))) == NULL) {
- warnx("malloc() failed - %s", strerror(errno));
+ if ((entry = calloc(1, sizeof(struct fname))) == NULL) {
+ warn("calloc() failed");
free(fstring);
return (-1);
}
- memset(entry, 0, sizeof(struct fname));
-
if (cut != NULL)
asn_append_oid(&(entry->cut), cut);
- strlcpy(fstring, filename, strlen(filename) + 1);
entry->name = fstring;
entry->done = done;
SLIST_INSERT_HEAD(&snmptoolctx->filelist, entry, link);
@@ -289,7 +288,7 @@
}
}
-static char
+static char
isvalid_fchar(char c, int pos)
{
if (isalpha(c)|| c == '/'|| c == '_' || c == '.' || c == '~' ||
@@ -445,11 +444,12 @@
static int32_t
parse_ascii(char *ascii, uint8_t *binstr, size_t binlen)
{
- int32_t alen, count, saved_errno, i;
+ char dptr[3];
+ size_t count;
+ int32_t alen, i, saved_errno;
uint32_t val;
- char dptr[3];
- /* Filter 0x at the beggining */
+ /* Filter 0x at the beginning */
if ((alen = strlen(ascii)) > 2 && ascii[0] == '0' && ascii[1] == 'x')
i = 2;
else
@@ -468,7 +468,7 @@
}
binstr[count] = (uint8_t) val;
if (++count >= binlen) {
- warnx("Key %s too long - truncating to %zu octest",
+ warnx("Key %s too long - truncating to %zu octets",
ascii, binlen);
break;
}
@@ -482,7 +482,7 @@
* snmp_client structure.
*/
int32_t
-parse_authentication(struct snmp_toolinfo *snmptoolctx, char *opt_arg)
+parse_authentication(struct snmp_toolinfo *snmptoolctx __unused, char *opt_arg)
{
int32_t count, subopt;
char *val, *option;
@@ -537,7 +537,7 @@
}
int32_t
-parse_privacy(struct snmp_toolinfo *snmptoolctx, char *opt_arg)
+parse_privacy(struct snmp_toolinfo *snmptoolctx __unused, char *opt_arg)
{
int32_t count, subopt;
char *val, *option;
@@ -590,7 +590,7 @@
}
int32_t
-parse_context(struct snmp_toolinfo *snmptoolctx, char *opt_arg)
+parse_context(struct snmp_toolinfo *snmptoolctx __unused, char *opt_arg)
{
int32_t count, subopt;
char *val, *option;
@@ -616,8 +616,8 @@
warnx("Suboption 'context-engine' - no argument");
return (-1);
}
- if ((snmp_client.clen = parse_ascii(val,
- snmp_client.cengine, SNMP_ENGINE_ID_SIZ)) < 0) {
+ if ((int32_t)(snmp_client.clen = parse_ascii(val,
+ snmp_client.cengine, SNMP_ENGINE_ID_SIZ)) == -1) {
warnx("Bad EngineID - %s", val);
return (-1);
}
@@ -632,7 +632,7 @@
}
int32_t
-parse_user_security(struct snmp_toolinfo *snmptoolctx, char *opt_arg)
+parse_user_security(struct snmp_toolinfo *snmptoolctx __unused, char *opt_arg)
{
int32_t count, subopt, saved_errno;
char *val, *option;
@@ -653,9 +653,9 @@
warnx("Suboption 'engine' - no argument");
return (-1);
}
- snmp_client.engine.engine_len = parse_ascii(val,
+ snmp_client.engine.engine_len = parse_ascii(val,
snmp_client.engine.engine_id, SNMP_ENGINE_ID_SIZ);
- if (snmp_client.engine.engine_len < 0) {
+ if ((int32_t)snmp_client.engine.engine_len == -1) {
warnx("Bad EngineID - %s", val);
return (-1);
}
@@ -669,8 +669,7 @@
errno = 0;
snmp_client.engine.engine_boots = strtoul(val, NULL, 10);
if (errno != 0) {
- warnx("Bad 'engine-boots' value %s - %s", val,
- strerror(errno));
+ warn("Bad 'engine-boots' value %s", val);
errno = saved_errno;
return (-1);
}
@@ -685,8 +684,7 @@
errno = 0;
snmp_client.engine.engine_time = strtoul(val, NULL, 10);
if (errno != 0) {
- warnx("Bad 'engine-time' value %s - %s", val,
- strerror(errno));
+ warn("Bad 'engine-time' value %s", val);
errno = saved_errno;
return (-1);
}
@@ -797,7 +795,7 @@
return (-1);
if (snmp_client.trans > SNMP_TRANS_UDP && snmp_client.chost == NULL) {
- if ((snmp_client.chost = malloc(strlen(SNMP_DEFAULT_LOCAL + 1)))
+ if ((snmp_client.chost = malloc(strlen(SNMP_DEFAULT_LOCAL) + 1))
== NULL) {
syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
return (-1);
@@ -820,7 +818,7 @@
v = strtol(opt_arg, NULL, 10);
if (errno != 0) {
- warnx( "Error parsing timeout value - %s", strerror(errno));
+ warn("Error parsing timeout value");
errno = saved_errno;
return (-1);
}
@@ -843,7 +841,7 @@
v = strtoul(opt_arg, NULL, 10);
if (errno != 0) {
- warnx("Error parsing retries count - %s", strerror(errno));
+ warn("Error parsing retries count");
errno = saved_errno;
return (-1);
}
@@ -866,7 +864,7 @@
v = strtoul(opt_arg, NULL, 10);
if (errno != 0) {
- warnx("Error parsing version - %s", strerror(errno));
+ warn("Error parsing version");
errno = saved_errno;
return (-1);
}
@@ -918,7 +916,7 @@
size = strtoul(opt_arg, NULL, 10);
if (errno != 0) {
- warnx("Error parsing buffer size - %s", strerror(errno));
+ warn("Error parsing buffer size");
errno = saved_errno;
return (-1);
}
@@ -1041,8 +1039,7 @@
v = strtol(str, &endptr, 10);
if (errno != 0) {
- warnx("Integer value %s not supported - %s", str,
- strerror(errno));
+ warn("Integer value %s not supported", str);
errno = saved_errno;
return (NULL);
}
@@ -1060,7 +1057,7 @@
struct asn_oid *oid)
{
int32_t i;
- char string[MAXSTR], *endptr;
+ char string[MAXSTR + 1], *endptr;
struct snmp_object obj;
for (i = 0; i < MAXSTR; i++)
@@ -1076,12 +1073,10 @@
return (NULL);
} else {
strlcpy(string, str, i + 1);
- string[i] = '\0';
if (snmp_lookup_enumoid(snmptoolctx, &obj, string) < 0) {
- warnx("Unknown string - %s",string);
+ warnx("Unknown string - %s", string);
return (NULL);
}
- free(string);
}
asn_append_oid(oid, &(obj.val.var));
@@ -1096,6 +1091,7 @@
char *endptr, *ptr;
ptr = str;
+
for (i = 0; i < 4; i++) {
v = strtoul(ptr, &endptr, 10);
if (v > 0xff)
@@ -1123,8 +1119,7 @@
v = strtoul(str, &endptr, 10);
if (errno != 0) {
- warnx("Integer value %s not supported - %s\n", str,
- strerror(errno));
+ warn("Integer value %s not supported", str);
errno = saved_errno;
return (NULL);
}
@@ -1148,8 +1143,7 @@
v = strtoull(str, &endptr, 10);
if (errno != 0) {
- warnx("Integer value %s not supported - %s", str,
- strerror(errno));
+ warn("Integer value %s not supported", str);
errno = saved_errno;
return (NULL);
}
@@ -1366,12 +1360,11 @@
return (-1);
}
- if ((obj = malloc(sizeof(struct snmp_object))) == NULL) {
+ if ((obj = calloc(1, sizeof(struct snmp_object))) == NULL) {
syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
return (-1);
}
- memset(obj, 0, sizeof(struct snmp_object));
if (func(snmptoolctx, obj, string) < 0) {
warnx("Invalid OID - %s", string);
free(obj);
@@ -1474,7 +1467,7 @@
/* Return 0 in case of no more work todo. */
if (SLIST_EMPTY(&snmptoolctx->snmp_objectlist))
return (0);
-
+
if (maxcount < 0 || maxcount > SNMP_MAX_BINDINGS) {
warnx("maxcount out of range: <0 || >SNMP_MAX_BINDINGS");
return (-1);
@@ -1523,10 +1516,10 @@
}
/*
- * Check a PDU received in responce to a SNMP_PDU_GET/SNMP_PDU_GETBULK request
+ * Check a PDU received in response to a SNMP_PDU_GET/SNMP_PDU_GETBULK request
* but don't compare syntaxes - when sending a request PDU they must be null.
* This is a (almost) complete copy of snmp_pdu_check() - with matching syntaxes
- * checks and some other checks skiped.
+ * checks and some other checks skipped.
*/
int32_t
snmp_parse_get_resp(struct snmp_pdu *resp, struct snmp_pdu *req)
@@ -1605,7 +1598,7 @@
}
/*
- * Should be called to check a responce to get/getnext/getbulk.
+ * Should be called to check a response to get/getnext/getbulk.
*/
int32_t
snmp_parse_resp(struct snmp_pdu *resp, struct snmp_pdu *req)
@@ -1624,7 +1617,7 @@
}
if (resp->error_status != SNMP_ERR_NOERROR) {
- warnx("Error %d in responce", resp->error_status);
+ warnx("Error %d in response", resp->error_status);
return (-1);
}
@@ -2011,20 +2004,25 @@
void
snmp_output_err_resp(struct snmp_toolinfo *snmptoolctx, struct snmp_pdu *pdu)
{
+ struct snmp_object *object;
char buf[ASN_OIDSTRLEN];
- struct snmp_object object;
if (pdu == NULL || (pdu->error_index > (int32_t) pdu->nbindings)) {
- fprintf(stdout,"Invalid error index in PDU\n");
+ fprintf(stdout, "Invalid error index in PDU\n");
return;
}
+ if ((object = calloc(1, sizeof(struct snmp_object))) == NULL) {
+ fprintf(stdout, "calloc: %s", strerror(errno));
+ return;
+ }
+
fprintf(stdout, "Agent %s:%s returned error \n", snmp_client.chost,
snmp_client.cport);
- if (!ISSET_NUMERIC(snmptoolctx) && (snmp_fill_object(snmptoolctx, &object,
+ if (!ISSET_NUMERIC(snmptoolctx) && (snmp_fill_object(snmptoolctx, object,
&(pdu->bindings[pdu->error_index - 1])) > 0))
- snmp_output_object(snmptoolctx, &object);
+ snmp_output_object(snmptoolctx, object);
else {
asn_oid2str_r(&(pdu->bindings[pdu->error_index - 1].var), buf);
fprintf(stdout,"%s", buf);
@@ -2036,31 +2034,51 @@
fprintf(stdout, "%s\n", error_strings[pdu->error_status].str);
else
fprintf(stdout,"%s\n", error_strings[SNMP_ERR_UNKNOWN].str);
+
+ free(object);
+ object = NULL;
}
int32_t
-snmp_output_resp(struct snmp_toolinfo *snmptoolctx, struct snmp_pdu *pdu)
+snmp_output_resp(struct snmp_toolinfo *snmptoolctx, struct snmp_pdu *pdu,
+ struct asn_oid *root)
{
+ struct snmp_object *object;
+ char p[ASN_OIDSTRLEN];
int32_t error;
- char p[ASN_OIDSTRLEN];
uint32_t i;
- struct snmp_object object;
- for (i = 0, error = 0; i < pdu->nbindings; i++) {
+ if ((object = calloc(1, sizeof(struct snmp_object))) == NULL)
+ return (-1);
+
+ i = error = 0;
+ while (i < pdu->nbindings) {
+ if (root != NULL && !(asn_is_suboid(root,
+ &(pdu->bindings[i].var))))
+ break;
+
if (GET_OUTPUT(snmptoolctx) != OUTPUT_QUIET) {
if (!ISSET_NUMERIC(snmptoolctx) &&
- (snmp_fill_object(snmptoolctx, &object,
+ (snmp_fill_object(snmptoolctx, object,
&(pdu->bindings[i])) > 0))
- snmp_output_object(snmptoolctx, &object);
+ snmp_output_object(snmptoolctx, object);
else {
asn_oid2str_r(&(pdu->bindings[i].var), p);
fprintf(stdout, "%s", p);
}
}
- error |= snmp_output_numval(snmptoolctx, &(pdu->bindings[i]), object.info);
+ error |= snmp_output_numval(snmptoolctx, &(pdu->bindings[i]),
+ object->info);
+ i++;
}
- return (error);
+ free(object);
+ object = NULL;
+
+ if (error)
+ return (-1);
+
+ return (i);
}
void
Property changes on: trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Modified: trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.h
===================================================================
--- trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.h 2018-06-15 20:38:07 UTC (rev 10989)
+++ trunk/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.h 2018-06-15 20:40:12 UTC (rev 10990)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2005-2006 The FreeBSD Project
* All rights reserved.
@@ -28,7 +29,7 @@
*
* Helper functions common for all tools.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.h 301657 2016-06-08 17:34:37Z ngie $
*/
#ifndef _BSNMP_TOOLS_H_
@@ -47,6 +48,8 @@
#define SNMP_DEFS_DIR "/usr/share/snmp/defs/"
#define SNMP_DEFAULT_LOCAL "/var/run/snmpd.sock"
+#define SNMP_MAX_REPETITIONS 10
+
enum snmp_access {
SNMP_ACCESS_NONE = 0,
SNMP_ACCESS_GET,
@@ -185,14 +188,14 @@
/* Definitions for some flags' bits. */
#define OUTPUT_BITS 0x00000003 /* bits 0-1 for output type */
#define NUMERIC_BIT 0x00000004 /* bit 2 for numeric oids */
-#define RETRY_BIT 0x00000008 /* bit 3 for retry on error responce */
+#define RETRY_BIT 0x00000008 /* bit 3 for retry on error response */
#define ERRIGNORE_BIT 0x00000010 /* bit 4 for skip sanity checking */
#define ERRIGNORE_BIT 0x00000010 /* bit 4 for skip sanity checking */
#define EDISCOVER_BIT 0x00000020 /* bit 5 for SNMP Engine Discovery */
#define LOCALKEY_BIT 0x00000040 /* bit 6 for using localized key */
- /* 0x00000080 */ /* bit 7 reserverd */
+ /* 0x00000080 */ /* bit 7 reserved */
#define PDUTYPE_BITS 0x00000f00 /* bits 8-11 for pdu type */
- /* 0x0000f000 */ /* bit 12-15 reserverd */
+ /* 0x0000f000 */ /* bit 12-15 reserved */
#define MAXREP_BITS 0x00ff0000 /* bits 16-23 for max-repetit. value */
#define NONREP_BITS 0xff000000 /* bits 24-31 for non-repeaters value */
@@ -229,7 +232,7 @@
#define SET_NONREP(ctx, i) (((ctx)->flags |= (((i) & 0xff) << 24)))
#define GET_NONREP(ctx) (((ctx)->flags & NONREP_BITS) >> 24)
-
+extern int _bsnmptools_debug;
extern const struct asn_oid IsoOrgDod_OID;
int snmptool_init(struct snmp_toolinfo *);
@@ -323,7 +326,7 @@
int32_t snmp_output_numval(struct snmp_toolinfo *, struct snmp_value *,
struct snmp_oid2str *);
void snmp_output_val(struct snmp_value *);
-int32_t snmp_output_resp(struct snmp_toolinfo *, struct snmp_pdu *);
+int32_t snmp_output_resp(struct snmp_toolinfo *, struct snmp_pdu *, struct asn_oid *);
void snmp_output_err_resp(struct snmp_toolinfo *, struct snmp_pdu *);
void snmp_output_engine(void);
void snmp_output_keys(void);
More information about the Midnightbsd-cvs
mailing list