summaryrefslogtreecommitdiff
path: root/usr.sbin/snmpd
diff options
context:
space:
mode:
authorMartijn van Duren <martijn@cvs.openbsd.org>2023-11-12 20:04:36 +0000
committerMartijn van Duren <martijn@cvs.openbsd.org>2023-11-12 20:04:36 +0000
commit5ef9dbe5e2db3e5e8da4a4f686118141de6d2627 (patch)
tree40aed2cc46f6cc7f4b3dbc0073f870fae3c43550 /usr.sbin/snmpd
parent0bfb9ed83666b6c62574f5c6be7ac1a0f447902f (diff)
Now that smi.c is basically an oid/name translator, let smi_insert()
create the struct oid and let parse.y supply the arguments. OK tb@
Diffstat (limited to 'usr.sbin/snmpd')
-rw-r--r--usr.sbin/snmpd/parse.y34
-rw-r--r--usr.sbin/snmpd/smi.c31
-rw-r--r--usr.sbin/snmpd/snmpd.h4
3 files changed, 34 insertions, 35 deletions
diff --git a/usr.sbin/snmpd/parse.y b/usr.sbin/snmpd/parse.y
index 7e1b8d889cb..da51d238bc4 100644
--- a/usr.sbin/snmpd/parse.y
+++ b/usr.sbin/snmpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.81 2023/11/12 16:03:41 martijn Exp $ */
+/* $OpenBSD: parse.y,v 1.82 2023/11/12 20:04:35 martijn Exp $ */
/*
* Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org>
@@ -99,7 +99,7 @@ char *symget(const char *);
struct snmpd *conf = NULL;
static int errors = 0;
static struct usmuser *user = NULL;
-static struct oid *smi_object;
+static struct ber_oid *smi_object;
static uint8_t engineid[SNMPD_MAXENGINEIDLEN];
static int32_t enginepen;
@@ -848,25 +848,19 @@ sysmib : CONTACT STRING {
;
object : OBJECTID oid NAME STRING optwrite {
- smi_object = calloc(1, sizeof(*smi_object));
- if (smi_object == NULL) {
- yyerror("calloc");
- free($2);
- free($4);
- YYERROR;
- }
-
- smi_object->o_id = *$2;
- smi_object->o_name = $4;
+ const char *error;
- if (smi_insert(smi_object) == -1) {
- yyerror("duplicate oid");
+ smi_object = $2;
+ error = smi_insert($2, $4);
+ free($4);
+ if (error != NULL) {
+ yyerror("%s", error);
free($2);
- free($4);
- free(smi_object);
YYERROR;
}
- } objectvalue
+ } objectvalue {
+ free(smi_object);
+ }
;
objectvalue : INTEGER NUMBER {
@@ -880,7 +874,7 @@ objectvalue : INTEGER NUMBER {
yyerror("number too large");
YYERROR;
}
- error = appl_internal_object_int(&smi_object->o_id, $2);
+ error = appl_internal_object_int(smi_object, $2);
if (error != NULL) {
yyerror("%s", error);
YYERROR;
@@ -889,8 +883,8 @@ objectvalue : INTEGER NUMBER {
| OCTETSTRING STRING {
const char *error;
- if ((error = appl_internal_object_string(
- &smi_object->o_id, $2)) != NULL) {
+ error = appl_internal_object_string(smi_object, $2);
+ if (error != NULL) {
yyerror("%s", error);
free($2);
YYERROR;
diff --git a/usr.sbin/snmpd/smi.c b/usr.sbin/snmpd/smi.c
index 5033b45cb9e..e10717ac807 100644
--- a/usr.sbin/snmpd/smi.c
+++ b/usr.sbin/snmpd/smi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smi.c,v 1.33 2023/11/04 09:38:47 martijn Exp $ */
+/* $OpenBSD: smi.c,v 1.34 2023/11/12 20:04:35 martijn Exp $ */
/*
* Copyright (c) 2007, 2008 Reyk Floeter <reyk@openbsd.org>
@@ -182,22 +182,27 @@ smi_delete(struct oid *oid)
}
}
-int
-smi_insert(struct oid *oid)
+const char *
+smi_insert(struct ber_oid *oid, const char *name)
{
- struct oid key, *value;
+ struct oid *object;
- if ((oid->o_flags & OID_TABLE) && oid->o_get == NULL)
- fatalx("smi_insert: invalid MIB table");
+ if ((object = calloc(1, sizeof(*object))) == NULL)
+ return strerror(errno);
- bzero(&key, sizeof(key));
- bcopy(&oid->o_id, &key.o_id, sizeof(struct ber_oid));
- value = RB_FIND(oidtree, &smi_oidtree, &key);
- if (value != NULL)
- return (-1);
+ object->o_id = *oid;
+ if ((object->o_name = strdup(name)) == NULL) {
+ free(object);
+ return strerror(errno);
+ }
- RB_INSERT(oidtree, &smi_oidtree, oid);
- return (0);
+ if (RB_INSERT(oidtree, &smi_oidtree, object) != NULL) {
+ free(object->o_name);
+ free(object);
+ return "duplicate oid";
+ }
+
+ return NULL;
}
void
diff --git a/usr.sbin/snmpd/snmpd.h b/usr.sbin/snmpd/snmpd.h
index 9d901cc1934..461ef2f20c7 100644
--- a/usr.sbin/snmpd/snmpd.h
+++ b/usr.sbin/snmpd/snmpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: snmpd.h,v 1.109 2023/11/12 16:07:34 martijn Exp $ */
+/* $OpenBSD: snmpd.h,v 1.110 2023/11/12 20:04:35 martijn Exp $ */
/*
* Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org>
@@ -515,7 +515,7 @@ void smi_oidlen(struct ber_oid *);
void smi_scalar_oidlen(struct ber_oid *);
int smi_string2oid(const char *, struct ber_oid *);
void smi_delete(struct oid *);
-int smi_insert(struct oid *);
+const char *smi_insert(struct ber_oid *, const char *);
int smi_oid_cmp(struct oid *, struct oid *);
int smi_key_cmp(struct oid *, struct oid *);
unsigned int smi_application(struct ber_element *);