xref: /freebsd/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_begemot.c (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
1d76947f3SHartmut Brandt /*-
2d76947f3SHartmut Brandt  * Copyright (c) 2005-2006.
3d76947f3SHartmut Brandt  *	Hartmut Brandt.
4d76947f3SHartmut Brandt  *	All rights reserved.
5d76947f3SHartmut Brandt  *
6d76947f3SHartmut Brandt  * Author: Hartmut Brandt <harti@freebsd.org>
7d76947f3SHartmut Brandt  *
8d76947f3SHartmut Brandt  * Redistribution of this software and documentation and use in source and
9d76947f3SHartmut Brandt  * binary forms, with or without modification, are permitted provided that
10d76947f3SHartmut Brandt  * the following conditions are met:
11d76947f3SHartmut Brandt  *
12d76947f3SHartmut Brandt  * 1. Redistributions of source code or documentation must retain the above
13d76947f3SHartmut Brandt  *    copyright notice, this list of conditions and the following disclaimer.
14d76947f3SHartmut Brandt  * 2. Redistributions in binary form must reproduce the above copyright
15d76947f3SHartmut Brandt  *    notice, this list of conditions and the following disclaimer in the
16d76947f3SHartmut Brandt  *    documentation and/or other materials provided with the distribution.
17d76947f3SHartmut Brandt  *
18d76947f3SHartmut Brandt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19d76947f3SHartmut Brandt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20d76947f3SHartmut Brandt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21d76947f3SHartmut Brandt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22d76947f3SHartmut Brandt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23d76947f3SHartmut Brandt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24d76947f3SHartmut Brandt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25d76947f3SHartmut Brandt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26d76947f3SHartmut Brandt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27d76947f3SHartmut Brandt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28d76947f3SHartmut Brandt  * SUCH DAMAGE.
29d76947f3SHartmut Brandt  */
30d76947f3SHartmut Brandt 
31d76947f3SHartmut Brandt #include <stdlib.h>
32d76947f3SHartmut Brandt 
33d76947f3SHartmut Brandt #include "hostres_snmp.h"
34d76947f3SHartmut Brandt #include "hostres_oid.h"
35d76947f3SHartmut Brandt #include "hostres_tree.h"
36d76947f3SHartmut Brandt 
37d76947f3SHartmut Brandt int
op_begemot(struct snmp_context * ctx,struct snmp_value * value,u_int sub,u_int iidx __unused,enum snmp_op op)38d76947f3SHartmut Brandt op_begemot(struct snmp_context *ctx, struct snmp_value *value,
39d76947f3SHartmut Brandt     u_int sub, u_int iidx __unused, enum snmp_op op)
40d76947f3SHartmut Brandt {
41d76947f3SHartmut Brandt 
42d76947f3SHartmut Brandt 	switch (op) {
43d76947f3SHartmut Brandt 
44d76947f3SHartmut Brandt 	  case SNMP_OP_GET:
45d76947f3SHartmut Brandt 		switch (value->var.subs[sub - 1]) {
46d76947f3SHartmut Brandt 
47d76947f3SHartmut Brandt 		  case LEAF_begemotHrStorageUpdate:
48d76947f3SHartmut Brandt 			value->v.uint32 = storage_tbl_refresh;
49d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
50d76947f3SHartmut Brandt 
51d76947f3SHartmut Brandt 		  case LEAF_begemotHrFSUpdate:
52d76947f3SHartmut Brandt 			value->v.uint32 = fs_tbl_refresh;
53d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
54d76947f3SHartmut Brandt 
55d76947f3SHartmut Brandt 		  case LEAF_begemotHrDiskStorageUpdate:
56d76947f3SHartmut Brandt 			value->v.uint32 = disk_storage_tbl_refresh;
57d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
58d76947f3SHartmut Brandt 
59d76947f3SHartmut Brandt 		  case LEAF_begemotHrNetworkUpdate:
60d76947f3SHartmut Brandt 			value->v.uint32 = network_tbl_refresh;
61d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
62d76947f3SHartmut Brandt 
63d76947f3SHartmut Brandt 		  case LEAF_begemotHrSWInstalledUpdate:
64d76947f3SHartmut Brandt 			value->v.uint32 = swins_tbl_refresh;
65d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
66d76947f3SHartmut Brandt 
67d76947f3SHartmut Brandt 		  case LEAF_begemotHrSWRunUpdate:
68d76947f3SHartmut Brandt 			value->v.uint32 = swrun_tbl_refresh;
69d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
70d76947f3SHartmut Brandt 
71d76947f3SHartmut Brandt 		  case LEAF_begemotHrPkgDir:
72d76947f3SHartmut Brandt 			return (string_get(value, pkg_dir, -1));
73d76947f3SHartmut Brandt 		}
74d76947f3SHartmut Brandt 		abort();
75d76947f3SHartmut Brandt 
76d76947f3SHartmut Brandt 	  case SNMP_OP_GETNEXT:
77d76947f3SHartmut Brandt 		abort();
78d76947f3SHartmut Brandt 
79d76947f3SHartmut Brandt 	  case SNMP_OP_SET:
80d76947f3SHartmut Brandt 		switch (value->var.subs[sub - 1]) {
81d76947f3SHartmut Brandt 
82d76947f3SHartmut Brandt 		  case LEAF_begemotHrStorageUpdate:
83d76947f3SHartmut Brandt 			ctx->scratch->int1 = storage_tbl_refresh;
84d76947f3SHartmut Brandt 			storage_tbl_refresh = value->v.uint32;
85d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
86d76947f3SHartmut Brandt 
87d76947f3SHartmut Brandt 		  case LEAF_begemotHrFSUpdate:
88d76947f3SHartmut Brandt 			ctx->scratch->int1 = fs_tbl_refresh;
89d76947f3SHartmut Brandt 			fs_tbl_refresh = value->v.uint32;
90d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
91d76947f3SHartmut Brandt 
92d76947f3SHartmut Brandt 		  case LEAF_begemotHrDiskStorageUpdate:
93d76947f3SHartmut Brandt 			ctx->scratch->int1 = disk_storage_tbl_refresh;
94d76947f3SHartmut Brandt 			disk_storage_tbl_refresh = value->v.uint32;
95d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
96d76947f3SHartmut Brandt 
97d76947f3SHartmut Brandt 		  case LEAF_begemotHrNetworkUpdate:
98d76947f3SHartmut Brandt 			ctx->scratch->int1 = network_tbl_refresh;
99d76947f3SHartmut Brandt 			network_tbl_refresh = value->v.uint32;
100d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
101d76947f3SHartmut Brandt 
102d76947f3SHartmut Brandt 		  case LEAF_begemotHrSWInstalledUpdate:
103d76947f3SHartmut Brandt 			ctx->scratch->int1 = swins_tbl_refresh;
104d76947f3SHartmut Brandt 			swins_tbl_refresh = value->v.uint32;
105d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
106d76947f3SHartmut Brandt 
107d76947f3SHartmut Brandt 		  case LEAF_begemotHrSWRunUpdate:
108d76947f3SHartmut Brandt 			ctx->scratch->int1 = swrun_tbl_refresh;
109d76947f3SHartmut Brandt 			swrun_tbl_refresh = value->v.uint32;
110d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
111d76947f3SHartmut Brandt 
112d76947f3SHartmut Brandt 		  case LEAF_begemotHrPkgDir:
113d76947f3SHartmut Brandt 			return (string_save(value, ctx, -1, &pkg_dir));
114d76947f3SHartmut Brandt 		}
115d76947f3SHartmut Brandt 		abort();
116d76947f3SHartmut Brandt 
117d76947f3SHartmut Brandt 	  case SNMP_OP_COMMIT:
118d76947f3SHartmut Brandt 		switch (value->var.subs[sub - 1]) {
119d76947f3SHartmut Brandt 
120d76947f3SHartmut Brandt 		  case LEAF_begemotHrStorageUpdate:
121d76947f3SHartmut Brandt 		  case LEAF_begemotHrFSUpdate:
122d76947f3SHartmut Brandt 		  case LEAF_begemotHrDiskStorageUpdate:
123d76947f3SHartmut Brandt 		  case LEAF_begemotHrNetworkUpdate:
124d76947f3SHartmut Brandt 		  case LEAF_begemotHrSWInstalledUpdate:
125d76947f3SHartmut Brandt 		  case LEAF_begemotHrSWRunUpdate:
126d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
127d76947f3SHartmut Brandt 
128d76947f3SHartmut Brandt 		  case LEAF_begemotHrPkgDir:
129d76947f3SHartmut Brandt 			string_commit(ctx);
130d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
131d76947f3SHartmut Brandt 		}
132d76947f3SHartmut Brandt 		abort();
133d76947f3SHartmut Brandt 
134d76947f3SHartmut Brandt 	  case SNMP_OP_ROLLBACK:
135d76947f3SHartmut Brandt 		switch (value->var.subs[sub - 1]) {
136d76947f3SHartmut Brandt 
137d76947f3SHartmut Brandt 		  case LEAF_begemotHrStorageUpdate:
138d76947f3SHartmut Brandt 			storage_tbl_refresh = ctx->scratch->int1;
139d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
140d76947f3SHartmut Brandt 
141d76947f3SHartmut Brandt 		  case LEAF_begemotHrFSUpdate:
142d76947f3SHartmut Brandt 			fs_tbl_refresh = ctx->scratch->int1;
143d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
144d76947f3SHartmut Brandt 
145d76947f3SHartmut Brandt 		  case LEAF_begemotHrDiskStorageUpdate:
146d76947f3SHartmut Brandt 			disk_storage_tbl_refresh = ctx->scratch->int1;
147d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
148d76947f3SHartmut Brandt 
149d76947f3SHartmut Brandt 		  case LEAF_begemotHrNetworkUpdate:
150d76947f3SHartmut Brandt 			network_tbl_refresh = ctx->scratch->int1;
151d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
152d76947f3SHartmut Brandt 
153d76947f3SHartmut Brandt 		  case LEAF_begemotHrSWInstalledUpdate:
154d76947f3SHartmut Brandt 			swins_tbl_refresh = ctx->scratch->int1;
155d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
156d76947f3SHartmut Brandt 
157d76947f3SHartmut Brandt 		  case LEAF_begemotHrSWRunUpdate:
158d76947f3SHartmut Brandt 			swrun_tbl_refresh = ctx->scratch->int1;
159d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
160d76947f3SHartmut Brandt 
161d76947f3SHartmut Brandt 		  case LEAF_begemotHrPkgDir:
162d76947f3SHartmut Brandt 			string_rollback(ctx, &pkg_dir);
163d76947f3SHartmut Brandt 			return (SNMP_ERR_NOERROR);
164d76947f3SHartmut Brandt 		}
165d76947f3SHartmut Brandt 		abort();
166d76947f3SHartmut Brandt 	}
167d76947f3SHartmut Brandt 
168d76947f3SHartmut Brandt 	abort();
169d76947f3SHartmut Brandt }
170