Path: blob/main/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_begemot.c
107769 views
/*-1* Copyright (c) 2005-2006.2* Hartmut Brandt.3* All rights reserved.4*5* Author: Hartmut Brandt <[email protected]>6*7* Redistribution of this software and documentation and use in source and8* binary forms, with or without modification, are permitted provided that9* the following conditions are met:10*11* 1. Redistributions of source code or documentation must retain the above12* copyright notice, this list of conditions and the following disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in the15* documentation and/or other materials provided with the distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND18* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE20* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE21* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT25* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY26* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF27* SUCH DAMAGE.28*/2930#include <stdlib.h>3132#include "hostres_snmp.h"33#include "hostres_oid.h"34#include "hostres_tree.h"3536int37op_begemot(struct snmp_context *ctx, struct snmp_value *value,38u_int sub, u_int iidx __unused, enum snmp_op op)39{4041switch (op) {4243case SNMP_OP_GET:44switch (value->var.subs[sub - 1]) {4546case LEAF_begemotHrStorageUpdate:47value->v.uint32 = storage_tbl_refresh;48return (SNMP_ERR_NOERROR);4950case LEAF_begemotHrFSUpdate:51value->v.uint32 = fs_tbl_refresh;52return (SNMP_ERR_NOERROR);5354case LEAF_begemotHrDiskStorageUpdate:55value->v.uint32 = disk_storage_tbl_refresh;56return (SNMP_ERR_NOERROR);5758case LEAF_begemotHrNetworkUpdate:59value->v.uint32 = network_tbl_refresh;60return (SNMP_ERR_NOERROR);6162case LEAF_begemotHrSWInstalledUpdate:63value->v.uint32 = swins_tbl_refresh;64return (SNMP_ERR_NOERROR);6566case LEAF_begemotHrSWRunUpdate:67value->v.uint32 = swrun_tbl_refresh;68return (SNMP_ERR_NOERROR);6970case LEAF_begemotHrPkgDir:71return (string_get(value, pkg_dir, -1));72}73abort();7475case SNMP_OP_GETNEXT:76abort();7778case SNMP_OP_SET:79switch (value->var.subs[sub - 1]) {8081case LEAF_begemotHrStorageUpdate:82ctx->scratch->int1 = storage_tbl_refresh;83storage_tbl_refresh = value->v.uint32;84return (SNMP_ERR_NOERROR);8586case LEAF_begemotHrFSUpdate:87ctx->scratch->int1 = fs_tbl_refresh;88fs_tbl_refresh = value->v.uint32;89return (SNMP_ERR_NOERROR);9091case LEAF_begemotHrDiskStorageUpdate:92ctx->scratch->int1 = disk_storage_tbl_refresh;93disk_storage_tbl_refresh = value->v.uint32;94return (SNMP_ERR_NOERROR);9596case LEAF_begemotHrNetworkUpdate:97ctx->scratch->int1 = network_tbl_refresh;98network_tbl_refresh = value->v.uint32;99return (SNMP_ERR_NOERROR);100101case LEAF_begemotHrSWInstalledUpdate:102ctx->scratch->int1 = swins_tbl_refresh;103swins_tbl_refresh = value->v.uint32;104return (SNMP_ERR_NOERROR);105106case LEAF_begemotHrSWRunUpdate:107ctx->scratch->int1 = swrun_tbl_refresh;108swrun_tbl_refresh = value->v.uint32;109return (SNMP_ERR_NOERROR);110111case LEAF_begemotHrPkgDir:112return (string_save(value, ctx, -1, &pkg_dir));113}114abort();115116case SNMP_OP_COMMIT:117switch (value->var.subs[sub - 1]) {118119case LEAF_begemotHrStorageUpdate:120case LEAF_begemotHrFSUpdate:121case LEAF_begemotHrDiskStorageUpdate:122case LEAF_begemotHrNetworkUpdate:123case LEAF_begemotHrSWInstalledUpdate:124case LEAF_begemotHrSWRunUpdate:125return (SNMP_ERR_NOERROR);126127case LEAF_begemotHrPkgDir:128string_commit(ctx);129return (SNMP_ERR_NOERROR);130}131abort();132133case SNMP_OP_ROLLBACK:134switch (value->var.subs[sub - 1]) {135136case LEAF_begemotHrStorageUpdate:137storage_tbl_refresh = ctx->scratch->int1;138return (SNMP_ERR_NOERROR);139140case LEAF_begemotHrFSUpdate:141fs_tbl_refresh = ctx->scratch->int1;142return (SNMP_ERR_NOERROR);143144case LEAF_begemotHrDiskStorageUpdate:145disk_storage_tbl_refresh = ctx->scratch->int1;146return (SNMP_ERR_NOERROR);147148case LEAF_begemotHrNetworkUpdate:149network_tbl_refresh = ctx->scratch->int1;150return (SNMP_ERR_NOERROR);151152case LEAF_begemotHrSWInstalledUpdate:153swins_tbl_refresh = ctx->scratch->int1;154return (SNMP_ERR_NOERROR);155156case LEAF_begemotHrSWRunUpdate:157swrun_tbl_refresh = ctx->scratch->int1;158return (SNMP_ERR_NOERROR);159160case LEAF_begemotHrPkgDir:161string_rollback(ctx, &pkg_dir);162return (SNMP_ERR_NOERROR);163}164abort();165}166167abort();168}169170171