diff options
author | Martijn van Duren <martijn@cvs.openbsd.org> | 2023-11-12 16:07:35 +0000 |
---|---|---|
committer | Martijn van Duren <martijn@cvs.openbsd.org> | 2023-11-12 16:07:35 +0000 |
commit | da75bd6d2e3743f414a6e28b8f8bf0c8a70f6da4 (patch) | |
tree | 4080f736bd21f70e940b67efecd9edc0d11a0642 /usr.sbin/snmpd | |
parent | 4a4d57c394ba1dbd6f286f3053818b6602924c1c (diff) |
Now that the last consumer of mps.c is gone, remove it and its
application_legacy.c companion.
OK tb@
Diffstat (limited to 'usr.sbin/snmpd')
-rw-r--r-- | usr.sbin/snmpd/Makefile | 9 | ||||
-rw-r--r-- | usr.sbin/snmpd/application.c | 4 | ||||
-rw-r--r-- | usr.sbin/snmpd/application.h | 6 | ||||
-rw-r--r-- | usr.sbin/snmpd/application_legacy.c | 173 | ||||
-rw-r--r-- | usr.sbin/snmpd/mps.c | 327 | ||||
-rw-r--r-- | usr.sbin/snmpd/snmpd.h | 17 |
6 files changed, 7 insertions, 529 deletions
diff --git a/usr.sbin/snmpd/Makefile b/usr.sbin/snmpd/Makefile index 1bc8ed521b8..dfb72716902 100644 --- a/usr.sbin/snmpd/Makefile +++ b/usr.sbin/snmpd/Makefile @@ -1,11 +1,10 @@ -# $OpenBSD: Makefile,v 1.24 2023/11/04 09:38:47 martijn Exp $ +# $OpenBSD: Makefile,v 1.25 2023/11/12 16:07:34 martijn Exp $ PROG= snmpd MAN= snmpd.8 snmpd.conf.5 -SRCS= parse.y log.c snmpe.c application.c application_legacy.c \ - application_blocklist.c application_internal.c \ - application_agentx.c ax.c \ - mps.c trap.c smi.c snmpd.c \ +SRCS= parse.y log.c snmpe.c application.c application_blocklist.c \ + application_internal.c application_agentx.c ax.c \ + trap.c smi.c snmpd.c \ proc.c usm.c traphandler.c util.c LDADD= -levent -lutil -lcrypto diff --git a/usr.sbin/snmpd/application.c b/usr.sbin/snmpd/application.c index afc9f2e74cc..434146f6513 100644 --- a/usr.sbin/snmpd/application.c +++ b/usr.sbin/snmpd/application.c @@ -1,4 +1,4 @@ -/* $OpenBSD: application.c,v 1.35 2023/11/08 20:07:14 martijn Exp $ */ +/* $OpenBSD: application.c,v 1.36 2023/11/12 16:07:34 martijn Exp $ */ /* * Copyright (c) 2021 Martijn van Duren <martijn@openbsd.org> @@ -177,7 +177,6 @@ appl_init(void) { appl_blocklist_init(); appl_internal_init(); - appl_legacy_init(); appl_agentx_init(); } @@ -188,7 +187,6 @@ appl_shutdown(void) appl_blocklist_shutdown(); appl_internal_shutdown(); - appl_legacy_shutdown(); appl_agentx_shutdown(); TAILQ_FOREACH_SAFE(ctx, &contexts, ac_entries, tctx) { diff --git a/usr.sbin/snmpd/application.h b/usr.sbin/snmpd/application.h index d6129634670..5c35942137a 100644 --- a/usr.sbin/snmpd/application.h +++ b/usr.sbin/snmpd/application.h @@ -1,4 +1,4 @@ -/* $OpenBSD: application.h,v 1.12 2023/11/12 16:03:41 martijn Exp $ */ +/* $OpenBSD: application.h,v 1.13 2023/11/12 16:07:34 martijn Exp $ */ /* * Copyright (c) 2021 Martijn van Duren <martijn@openbsd.org> @@ -143,10 +143,6 @@ void appl_response(struct appl_backend *, int32_t, enum appl_error, int16_t, void appl_report(struct snmp_message *, int32_t, struct ber_oid *); struct ber_element *appl_exception(enum appl_exception); -/* application_legacy.c */ -void appl_legacy_init(void); -void appl_legacy_shutdown(void); - /* application_agentx.c */ void appl_agentx(void); void appl_agentx_init(void); diff --git a/usr.sbin/snmpd/application_legacy.c b/usr.sbin/snmpd/application_legacy.c deleted file mode 100644 index b916908fb7d..00000000000 --- a/usr.sbin/snmpd/application_legacy.c +++ /dev/null @@ -1,173 +0,0 @@ -/* $OpenBSD: application_legacy.c,v 1.1 2022/01/19 10:59:35 martijn Exp $ */ - -/* - * Copyright (c) 2021 Martijn van Duren <martijn@openbsd.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <event.h> -#include <stdlib.h> - -#include "application.h" - -#include "snmpd.h" - -struct appl_varbind *appl_legacy_response(size_t); -void appl_legacy_get(struct appl_backend *, int32_t, int32_t, const char *, - struct appl_varbind *); -void appl_legacy_getnext(struct appl_backend *, int32_t, int32_t, const char *, - struct appl_varbind *); - -struct appl_backend_functions appl_legacy_functions = { - .ab_get = appl_legacy_get, - .ab_getnext = appl_legacy_getnext, - .ab_getbulk = NULL, /* Legacy getbulk implementation is broken */ -}; - -struct appl_backend appl_legacy = { - .ab_name = "legacy backend", - .ab_cookie = NULL, - .ab_retries = 0, - .ab_fn = &appl_legacy_functions -}; - -static struct ber_element *root; -static struct appl_varbind *response = NULL; -static size_t responsesz = 0; - -void -appl_legacy_init(void) -{ - struct oid *object = NULL; - struct ber_oid oid; - - while ((object = smi_foreach(object, OID_RD)) != NULL) { - oid = object->o_id; - if (!(object->o_flags & OID_TABLE)) - oid.bo_id[oid.bo_n++] = 0; - appl_register(NULL, 150, 1, &oid, - !(object->o_flags & OID_TABLE), 1, 0, 0, &appl_legacy); - } - - if ((root = ober_add_sequence(NULL)) == NULL) - fatal("%s: Failed to init root", __func__); -} - -void -appl_legacy_shutdown(void) -{ - appl_close(&appl_legacy); - - ober_free_elements(root); - free(response); -} - -struct appl_varbind * -appl_legacy_response(size_t nvarbind) -{ - struct appl_varbind *tmp; - size_t i; - - if (responsesz < nvarbind) { - if ((tmp = recallocarray(response, responsesz, nvarbind, - sizeof(*response))) == NULL) { - log_warn(NULL); - return NULL; - } - responsesz = nvarbind; - response = tmp; - } - for (i = 0; i < nvarbind; i++) - response[i].av_next = i + 1 == nvarbind ? - NULL : &(response[i + 1]); - return response; -} - -void -appl_legacy_get(struct appl_backend *backend, __unused int32_t transactionid, - int32_t requestid, __unused const char *ctx, struct appl_varbind *vblist) -{ - size_t i; - struct ber_element *elm; - struct appl_varbind *vb, *rvb, *rvblist; - - for (i = 0, vb = vblist; vb != NULL; vb = vb->av_next) - i++; - if ((rvblist = appl_legacy_response(i)) == NULL) { - appl_response(backend, requestid, APPL_ERROR_GENERR, 1, vb); - return; - } - rvb = rvblist; - for (vb = vblist; vb != NULL; vb = vb->av_next, rvb = rvb->av_next) { - (void)mps_getreq(NULL, root, &(vb->av_oid), 1); - elm = ober_unlink_elements(root); - ober_get_oid(elm, &(rvb->av_oid)); - rvb->av_value = ober_unlink_elements(elm); - ober_free_elements(elm); - } - - appl_response(backend, requestid, APPL_ERROR_NOERROR, 0, rvblist); -} - -void -appl_legacy_getnext(struct appl_backend *backend, - __unused int32_t transactionid, int32_t requestid, __unused const char *ctx, - struct appl_varbind *vblist) -{ - size_t i; - struct ber_element *elm; - struct appl_varbind *vb, *rvb, *rvblist; - struct snmp_message msg; - int ret; - - for (i = 0, vb = vblist; vb != NULL; vb = vb->av_next) - i++; - if ((rvblist = appl_legacy_response(i)) == NULL) { - appl_response(backend, requestid, APPL_ERROR_GENERR, 1, vb); - return; - } - rvb = rvblist; - i = 1; - for (vb = vblist; vb != NULL; vb = vb->av_next, rvb = rvb->av_next) { - ret = -1; - if (vb->av_include) { - ret = mps_getreq(NULL, root, &(vb->av_oid), 0); - if (ret == -1) - ober_free_elements(ober_unlink_elements(root)); - } - rvb->av_oid = vb->av_oid; - if (ret == -1) { - msg.sm_version = 1; - (void)mps_getnextreq(&msg, root, &(rvb->av_oid)); - } - elm = ober_unlink_elements(root); - ober_get_oid(elm, &(rvb->av_oid)); - if (ober_oid_cmp(&(rvb->av_oid), &(vb->av_oid_end)) > 0) { - rvb->av_oid = vb->av_oid; - rvb->av_value = appl_exception(APPL_EXC_ENDOFMIBVIEW); - if (rvb->av_value == NULL) { - log_warn("Failed to create endOfMibView"); - rvb->av_next = NULL; - appl_response(backend, requestid, - APPL_ERROR_GENERR, i, rvblist); - return; - } - } else - rvb->av_value = ober_unlink_elements(elm); - ober_free_elements(elm); - i++; - } - - appl_response(backend, requestid, APPL_ERROR_NOERROR, 0, rvblist); -} diff --git a/usr.sbin/snmpd/mps.c b/usr.sbin/snmpd/mps.c deleted file mode 100644 index 8af55a71aef..00000000000 --- a/usr.sbin/snmpd/mps.c +++ /dev/null @@ -1,327 +0,0 @@ -/* $OpenBSD: mps.c,v 1.30 2022/10/06 14:41:08 martijn Exp $ */ - -/* - * Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <sys/queue.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/socket.h> -#include <sys/un.h> -#include <sys/tree.h> -#include <sys/sysctl.h> - -#include <net/if.h> -#include <net/if_dl.h> -#include <net/if_arp.h> -#include <net/if_media.h> -#include <net/route.h> -#include <netinet/in.h> -#include <netinet/if_ether.h> -#include <arpa/inet.h> - -#include <stdlib.h> -#include <stdio.h> -#include <errno.h> -#include <event.h> -#include <fcntl.h> -#include <string.h> -#include <unistd.h> -#include <pwd.h> - -#include "snmpd.h" -#include "mib.h" - -struct ber_oid * - mps_table(struct oid *, struct ber_oid *, struct ber_oid *); - -int -mps_getstr(struct oid *oid, struct ber_oid *o, struct ber_element **elm) -{ - char *s = oid->o_data; - - if (s == NULL) - return (-1); - *elm = ober_add_string(*elm, s); - return (0); -} - -int -mps_getint(struct oid *oid, struct ber_oid *o, struct ber_element **elm) -{ - *elm = ober_add_integer(*elm, oid->o_val); - return (0); -} - -int -mps_getts(struct oid *oid, struct ber_oid *o, struct ber_element **elm) -{ - *elm = ober_add_integer(*elm, oid->o_val); - ober_set_header(*elm, BER_CLASS_APPLICATION, SNMP_T_TIMETICKS); - return (0); -} - -int -mps_getreq(struct snmp_message *msg, struct ber_element *root, - struct ber_oid *o, u_int sm_version) -{ - struct ber_element *elm = root; - struct oid key, *value; - unsigned long error_type = 0; /* noSuchObject */ - - if (o->bo_n > BER_MAX_OID_LEN) - return (-1); - bzero(&key, sizeof(key)); - bcopy(o, &key.o_id, sizeof(struct ber_oid)); - smi_oidlen(&key.o_id); /* Strip off any trailing .0. */ - value = smi_find(&key); - if (value == NULL) - goto fail; - - if (OID_NOTSET(value)) - goto fail; - - if (value->o_get == NULL) - goto fail; - - if (value->o_oidlen == o->bo_n) { - /* No instance identifier specified. */ - error_type = 1; /* noSuchInstance */ - goto fail; - } - - if ((value->o_flags & OID_TABLE) == 0) - elm = ober_add_oid(elm, o); - if (value->o_get(value, o, &elm) != 0) - goto fail; - - return (0); - -fail: - if (sm_version == 0) - return (-1); - - /* Set SNMPv2 extended error response. */ - elm = ober_add_oid(elm, o); - elm = ober_add_null(elm); - ober_set_header(elm, BER_CLASS_CONTEXT, error_type); - return (0); -} - -int -mps_getnextreq(struct snmp_message *msg, struct ber_element *root, - struct ber_oid *o) -{ - struct oid *next = NULL; - struct ber_element *ber = root; - struct oid key, *value; - int ret; - struct ber_oid no; - unsigned long error_type = 0; /* noSuchObject */ - - if (o->bo_n > BER_MAX_OID_LEN) - return (-1); - bzero(&key, sizeof(key)); - bcopy(o, &key.o_id, sizeof(struct ber_oid)); - smi_oidlen(&key.o_id); /* Strip off any trailing .0. */ - value = smi_nfind(&key); - if (value == NULL) - goto fail; - - if (value->o_flags & OID_TABLE) { - /* Get the next table row for this column */ - if (mps_table(value, o, &no) != NULL) { - bcopy(&no, o, sizeof(*o)); - ret = value->o_get(value, o, &ber); - } else - ret = 1; - switch (ret) { - case 0: - return (0); - case -1: - goto fail; - case 1: /* end-of-rows */ - break; - } - } else if (o->bo_n == value->o_oidlen && value->o_get != NULL) { - next = value; - goto appendzero; - } - - getnext: - for (next = value; next != NULL;) { - next = smi_next(next); - if (next == NULL) - break; - if (!OID_NOTSET(next) && next->o_get != NULL) - break; - } - if (next == NULL || next->o_get == NULL) - goto fail; - - if (next->o_flags & OID_TABLE) { - /* Get the next table row for this column */ - if (mps_table(next, o, &no) == NULL) { - value = next; - goto getnext; - } - bcopy(&no, o, sizeof(*o)); - if ((ret = next->o_get(next, o, &ber)) != 0) { - if (ret == 1) { - value = next; - goto getnext; - } - goto fail; - } - } else { - bcopy(&next->o_id, o, sizeof(*o)); - appendzero: - /* No instance identifier specified. Append .0. */ - if (o->bo_n + 1 > BER_MAX_OID_LEN) - goto fail; - ber = ober_add_noid(ber, o, ++o->bo_n); - if ((ret = next->o_get(next, o, &ber)) != 0) - goto fail; - } - - return (0); - -fail: - if (msg->sm_version == 0) - return (-1); - - /* Set SNMPv2 extended error response. */ - ber = ober_add_oid(ber, o); - ber = ober_add_null(ber); - ober_set_header(ber, BER_CLASS_CONTEXT, error_type); - return (0); -} - -int -mps_getbulkreq(struct snmp_message *msg, struct ber_element **root, - struct ber_element **end, struct ber_oid *o, int max) -{ - struct ber_element *c, *d, *e; - size_t len; - int j, ret; - - j = max; - c = *root; - *end = NULL; - - for (d = NULL, len = 0; j > 0; j--) { - e = ober_add_sequence(NULL); - if (c == NULL) - c = e; - ret = mps_getnextreq(msg, e, o); - if (ret == 1) { - *root = c; - return (1); - } - if (ret == -1) { - ober_free_elements(e); - if (d == NULL) - return (-1); - break; - } - len += ober_calc_len(e); - if (len > SNMPD_MAXVARBINDLEN) { - ober_free_elements(e); - break; - } - if (d != NULL) - ober_link_elements(d, e); - d = e; - *end = d; - } - - *root = c; - return (0); -} - -int -mps_set(struct ber_oid *o, void *p, long long len) -{ - struct oid key, *value; - - smi_oidlen(o); - if (o->bo_n > BER_MAX_OID_LEN) - return (-1); - bzero(&key, sizeof(key)); - bcopy(o, &key.o_id, sizeof(struct ber_oid)); - value = smi_find(&key); - if (value == NULL) - return (-1); - free(value->o_data); - value->o_data = p; - value->o_val = len; - - return (0); -} - -struct ber_oid * -mps_table(struct oid *oid, struct ber_oid *o, struct ber_oid *no) -{ - u_int32_t col, idx = 1, id, subid; - struct oid a, b; - - /* - * This function is being used to iterate through elements - * in a SMI "table". It is called by the mps_getnext() handler. - * For example, if the input is sysORIndex, it will return - * sysORIndex.1. If the input is sysORIndex.2, it will return - * sysORIndex.3 etc.. The MIB code has to verify the index, - * see mib_sysor() as an example. - */ - - if (oid->o_table != NULL) - return (oid->o_table(oid, o, no)); - - bcopy(&oid->o_id, no, sizeof(*no)); - id = oid->o_oidlen - 1; - subid = oid->o_oidlen; - - if (o->bo_n >= oid->o_oidlen) { - /* - * Compare the requested and the matched OID to see - * if we have to iterate to the next element. - */ - bzero(&a, sizeof(a)); - bcopy(o, &a.o_id, sizeof(struct ber_oid)); - bzero(&b, sizeof(b)); - bcopy(&oid->o_id, &b.o_id, sizeof(struct ber_oid)); - b.o_oidlen--; - b.o_flags |= OID_TABLE; - if (smi_oid_cmp(&a, &b) == 0) { - col = oid->o_oid[id]; - if (col > o->bo_id[id]) - idx = 1; - else - idx = o->bo_id[subid] + 1; - o->bo_id[subid] = idx; - o->bo_id[id] = col; - bcopy(o, no, sizeof(*no)); - } - } - - /* The root element ends with a 0, iterate to the first element */ - if (!no->bo_id[subid]) - no->bo_id[subid]++; - - smi_oidlen(no); - - return (no); -} diff --git a/usr.sbin/snmpd/snmpd.h b/usr.sbin/snmpd/snmpd.h index b90e4cb17ee..9d901cc1934 100644 --- a/usr.sbin/snmpd/snmpd.h +++ b/usr.sbin/snmpd/snmpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: snmpd.h,v 1.108 2023/11/04 09:38:47 martijn Exp $ */ +/* $OpenBSD: snmpd.h,v 1.109 2023/11/12 16:07:34 martijn Exp $ */ /* * Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org> @@ -503,21 +503,6 @@ void trap_init(void); int trap_imsg(struct imsgev *, pid_t); int trap_send(struct ber_oid *, struct ber_element *); -/* mps.c */ -int mps_getreq(struct snmp_message *, struct ber_element *, - struct ber_oid *, u_int); -int mps_getnextreq(struct snmp_message *, struct ber_element *, - struct ber_oid *); -int mps_getbulkreq(struct snmp_message *, struct ber_element **, - struct ber_element **, struct ber_oid *, int); -int mps_set(struct ber_oid *, void *, long long); -int mps_getstr(struct oid *, struct ber_oid *, - struct ber_element **); -int mps_getint(struct oid *, struct ber_oid *, - struct ber_element **); -int mps_getts(struct oid *, struct ber_oid *, - struct ber_element **); - /* smi.c */ int smi_init(void); void smi_mibtree(struct oid *); |