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