create the struct oid and let parse.y supply the arguments.
OK tb@
-/* $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>
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;
;
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 {
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;
| 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;
-/* $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>
}
}
-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
-/* $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>
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 *);