xref: /freebsd/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_begemot.c (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
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 
31 #include <stdlib.h>
32 
33 #include "hostres_snmp.h"
34 #include "hostres_oid.h"
35 #include "hostres_tree.h"
36 
37 int
38 op_begemot(struct snmp_context *ctx, struct snmp_value *value,
39     u_int sub, u_int iidx __unused, enum snmp_op op)
40 {
41 
42 	switch (op) {
43 
44 	  case SNMP_OP_GET:
45 		switch (value->var.subs[sub - 1]) {
46 
47 		  case LEAF_begemotHrStorageUpdate:
48 			value->v.uint32 = storage_tbl_refresh;
49 			return (SNMP_ERR_NOERROR);
50 
51 		  case LEAF_begemotHrFSUpdate:
52 			value->v.uint32 = fs_tbl_refresh;
53 			return (SNMP_ERR_NOERROR);
54 
55 		  case LEAF_begemotHrDiskStorageUpdate:
56 			value->v.uint32 = disk_storage_tbl_refresh;
57 			return (SNMP_ERR_NOERROR);
58 
59 		  case LEAF_begemotHrNetworkUpdate:
60 			value->v.uint32 = network_tbl_refresh;
61 			return (SNMP_ERR_NOERROR);
62 
63 		  case LEAF_begemotHrSWInstalledUpdate:
64 			value->v.uint32 = swins_tbl_refresh;
65 			return (SNMP_ERR_NOERROR);
66 
67 		  case LEAF_begemotHrSWRunUpdate:
68 			value->v.uint32 = swrun_tbl_refresh;
69 			return (SNMP_ERR_NOERROR);
70 
71 		  case LEAF_begemotHrPkgDir:
72 			return (string_get(value, pkg_dir, -1));
73 		}
74 		abort();
75 
76 	  case SNMP_OP_GETNEXT:
77 		abort();
78 
79 	  case SNMP_OP_SET:
80 		switch (value->var.subs[sub - 1]) {
81 
82 		  case LEAF_begemotHrStorageUpdate:
83 			ctx->scratch->int1 = storage_tbl_refresh;
84 			storage_tbl_refresh = value->v.uint32;
85 			return (SNMP_ERR_NOERROR);
86 
87 		  case LEAF_begemotHrFSUpdate:
88 			ctx->scratch->int1 = fs_tbl_refresh;
89 			fs_tbl_refresh = value->v.uint32;
90 			return (SNMP_ERR_NOERROR);
91 
92 		  case LEAF_begemotHrDiskStorageUpdate:
93 			ctx->scratch->int1 = disk_storage_tbl_refresh;
94 			disk_storage_tbl_refresh = value->v.uint32;
95 			return (SNMP_ERR_NOERROR);
96 
97 		  case LEAF_begemotHrNetworkUpdate:
98 			ctx->scratch->int1 = network_tbl_refresh;
99 			network_tbl_refresh = value->v.uint32;
100 			return (SNMP_ERR_NOERROR);
101 
102 		  case LEAF_begemotHrSWInstalledUpdate:
103 			ctx->scratch->int1 = swins_tbl_refresh;
104 			swins_tbl_refresh = value->v.uint32;
105 			return (SNMP_ERR_NOERROR);
106 
107 		  case LEAF_begemotHrSWRunUpdate:
108 			ctx->scratch->int1 = swrun_tbl_refresh;
109 			swrun_tbl_refresh = value->v.uint32;
110 			return (SNMP_ERR_NOERROR);
111 
112 		  case LEAF_begemotHrPkgDir:
113 			return (string_save(value, ctx, -1, &pkg_dir));
114 		}
115 		abort();
116 
117 	  case SNMP_OP_COMMIT:
118 		switch (value->var.subs[sub - 1]) {
119 
120 		  case LEAF_begemotHrStorageUpdate:
121 		  case LEAF_begemotHrFSUpdate:
122 		  case LEAF_begemotHrDiskStorageUpdate:
123 		  case LEAF_begemotHrNetworkUpdate:
124 		  case LEAF_begemotHrSWInstalledUpdate:
125 		  case LEAF_begemotHrSWRunUpdate:
126 			return (SNMP_ERR_NOERROR);
127 
128 		  case LEAF_begemotHrPkgDir:
129 			string_commit(ctx);
130 			return (SNMP_ERR_NOERROR);
131 		}
132 		abort();
133 
134 	  case SNMP_OP_ROLLBACK:
135 		switch (value->var.subs[sub - 1]) {
136 
137 		  case LEAF_begemotHrStorageUpdate:
138 			storage_tbl_refresh = ctx->scratch->int1;
139 			return (SNMP_ERR_NOERROR);
140 
141 		  case LEAF_begemotHrFSUpdate:
142 			fs_tbl_refresh = ctx->scratch->int1;
143 			return (SNMP_ERR_NOERROR);
144 
145 		  case LEAF_begemotHrDiskStorageUpdate:
146 			disk_storage_tbl_refresh = ctx->scratch->int1;
147 			return (SNMP_ERR_NOERROR);
148 
149 		  case LEAF_begemotHrNetworkUpdate:
150 			network_tbl_refresh = ctx->scratch->int1;
151 			return (SNMP_ERR_NOERROR);
152 
153 		  case LEAF_begemotHrSWInstalledUpdate:
154 			swins_tbl_refresh = ctx->scratch->int1;
155 			return (SNMP_ERR_NOERROR);
156 
157 		  case LEAF_begemotHrSWRunUpdate:
158 			swrun_tbl_refresh = ctx->scratch->int1;
159 			return (SNMP_ERR_NOERROR);
160 
161 		  case LEAF_begemotHrPkgDir:
162 			string_rollback(ctx, &pkg_dir);
163 			return (SNMP_ERR_NOERROR);
164 		}
165 		abort();
166 	}
167 
168 	abort();
169 }
170