1 #include <net-snmp/net-snmp-config.h>
2
3 #include <net-snmp/net-snmp-includes.h>
4 #include <net-snmp/net-snmp-features.h>
5
6 #include <net-snmp/library/check_varbind.h>
7
8 netsnmp_feature_child_of(check_varbind_all, libnetsnmp);
9
10 netsnmp_feature_child_of(check_vb_range, check_varbind_all);
11 netsnmp_feature_child_of(check_vb_size_range, check_varbind_all);
12 netsnmp_feature_child_of(check_vb_uint, check_varbind_all);
13 netsnmp_feature_child_of(check_vb_storagetype, check_varbind_all);
14 netsnmp_feature_child_of(check_vb_oid, check_varbind_all);
15 netsnmp_feature_child_of(check_vb_type_and_max_size, check_varbind_all);
16 netsnmp_feature_child_of(check_vb_type_and_max_size, check_varbind_all);
17 netsnmp_feature_child_of(check_vb_rowstatus_with_storagetype, check_varbind_all);
18 netsnmp_feature_child_of(check_vb_truthvalue, check_varbind_all);
19
20 #ifdef NETSNMP_FEATURE_REQUIRE_CHECK_VB_ROWSTATUS_WITH_STORAGETYPE
21 netsnmp_feature_require(check_rowstatus_with_storagetype_transition);
22 #endif /* NETSNMP_FEATURE_REQUIRES_CHECK_VB_ROWSTATUS_WITH_STORAGETYPE */
23 #ifdef NETSNMP_FEATURE_REQUIRE_CHECK_VB_STORAGETYPE
24 netsnmp_feature_require(check_storage_transition);
25 #endif /* NETSNMP_FEATURE_REQUIRE_CHECK_VB_STORAGETYPE */
26
27
28 NETSNMP_INLINE int
netsnmp_check_vb_type(const netsnmp_variable_list * var,int type)29 netsnmp_check_vb_type(const netsnmp_variable_list *var, int type )
30 {
31 register int rc = SNMP_ERR_NOERROR;
32
33 if (NULL == var)
34 return SNMP_ERR_GENERR;
35
36 if (var->type != type) {
37 rc = SNMP_ERR_WRONGTYPE;
38 }
39
40 return rc;
41 }
42
43 NETSNMP_INLINE int
netsnmp_check_vb_size(const netsnmp_variable_list * var,size_t size)44 netsnmp_check_vb_size(const netsnmp_variable_list *var, size_t size )
45 {
46 register int rc = SNMP_ERR_NOERROR;
47
48 if (NULL == var)
49 return SNMP_ERR_GENERR;
50
51 else if (var->val_len != size) {
52 rc = SNMP_ERR_WRONGLENGTH;
53 }
54
55 return rc;
56 }
57
58 NETSNMP_INLINE int
netsnmp_check_vb_max_size(const netsnmp_variable_list * var,size_t size)59 netsnmp_check_vb_max_size(const netsnmp_variable_list *var, size_t size )
60 {
61 register int rc = SNMP_ERR_NOERROR;
62
63 if (NULL == var)
64 return SNMP_ERR_GENERR;
65
66 else if (var->val_len > size) {
67 rc = SNMP_ERR_WRONGLENGTH;
68 }
69
70 return rc;
71 }
72
73 #ifndef NETSNMP_FEATURE_REMOVE_CHECK_VB_RANGE
74 NETSNMP_INLINE int
netsnmp_check_vb_range(const netsnmp_variable_list * var,size_t low,size_t high)75 netsnmp_check_vb_range(const netsnmp_variable_list *var,
76 size_t low, size_t high )
77 {
78 register int rc = SNMP_ERR_NOERROR;
79
80 if (NULL == var)
81 return SNMP_ERR_GENERR;
82
83 if (((size_t)*var->val.integer < low) || ((size_t)*var->val.integer > high)) {
84 rc = SNMP_ERR_WRONGVALUE;
85 }
86
87 return rc;
88 }
89 #endif /* NETSNMP_FEATURE_REMOVE_CHECK_VB_RANGE */
90
91 #ifndef NETSNMP_FEATURE_REMOVE_CHECK_VB_SIZE_RANGE
92 NETSNMP_INLINE int
netsnmp_check_vb_size_range(const netsnmp_variable_list * var,size_t low,size_t high)93 netsnmp_check_vb_size_range(const netsnmp_variable_list *var,
94 size_t low, size_t high )
95 {
96 register int rc = SNMP_ERR_NOERROR;
97
98 if (NULL == var)
99 return SNMP_ERR_GENERR;
100
101 if ((var->val_len < low) || (var->val_len > high)) {
102 rc = SNMP_ERR_WRONGLENGTH;
103 }
104
105 return rc;
106 }
107 #endif /* NETSNMP_FEATURE_REMOVE_CHECK_VB_SIZE_RANGE */
108
109 NETSNMP_INLINE int
netsnmp_check_vb_type_and_size(const netsnmp_variable_list * var,int type,size_t size)110 netsnmp_check_vb_type_and_size(const netsnmp_variable_list *var,
111 int type, size_t size)
112 {
113 register int rc = SNMP_ERR_NOERROR;
114
115 if (NULL == var)
116 return SNMP_ERR_GENERR;
117
118 if ((rc = netsnmp_check_vb_type(var,type)))
119 ;
120 else
121 rc = netsnmp_check_vb_size(var, size);
122
123 return rc;
124 }
125
126 #ifndef NETSNMP_FEATURE_REMOVE_CHECK_VB_TYPE_AND_MAX_SIZE
127 NETSNMP_INLINE int
netsnmp_check_vb_type_and_max_size(const netsnmp_variable_list * var,int type,size_t size)128 netsnmp_check_vb_type_and_max_size(const netsnmp_variable_list *var,
129 int type, size_t size)
130 {
131 register int rc = SNMP_ERR_NOERROR;
132
133 if (NULL == var)
134 return SNMP_ERR_GENERR;
135
136 if ((rc = netsnmp_check_vb_type(var,type)))
137 ;
138 else
139 rc = netsnmp_check_vb_max_size(var, size);
140
141 return rc;
142 }
143 #endif /* NETSNMP_FEATURE_REMOVE_CHECK_VB_TYPE_AND_MAX_SIZE */
144
145 #ifndef NETSNMP_FEATURE_REMOVE_CHECK_VB_OID
146 NETSNMP_INLINE int
netsnmp_check_vb_oid(const netsnmp_variable_list * var)147 netsnmp_check_vb_oid(const netsnmp_variable_list *var)
148 {
149 register int rc = SNMP_ERR_NOERROR;
150
151 if (NULL == var)
152 return SNMP_ERR_GENERR;
153
154 if ((rc = netsnmp_check_vb_type(var,ASN_OBJECT_ID)))
155 ;
156 else
157 rc = netsnmp_check_vb_max_size(var, MAX_OID_LEN*sizeof(oid));
158
159 return rc;
160 }
161 #endif /* NETSNMP_FEATURE_REMOVE_CHECK_VB_OID */
162
163 NETSNMP_INLINE int
netsnmp_check_vb_int(const netsnmp_variable_list * var)164 netsnmp_check_vb_int(const netsnmp_variable_list *var)
165 {
166 if (NULL == var)
167 return SNMP_ERR_GENERR;
168
169 return netsnmp_check_vb_type_and_size(var, ASN_INTEGER, sizeof(long));
170 }
171
172 #ifndef NETSNMP_FEATURE_REMOVE_CHECK_VB_UINT
173 NETSNMP_INLINE int
netsnmp_check_vb_uint(const netsnmp_variable_list * var)174 netsnmp_check_vb_uint(const netsnmp_variable_list *var)
175 {
176 if (NULL == var)
177 return SNMP_ERR_GENERR;
178
179 return netsnmp_check_vb_type_and_size(var, ASN_UNSIGNED, sizeof(long));
180 }
181 #endif /* NETSNMP_FEATURE_REMOVE_CHECK_VB_UINT */
182
183 NETSNMP_INLINE int
netsnmp_check_vb_int_range(const netsnmp_variable_list * var,int low,int high)184 netsnmp_check_vb_int_range(const netsnmp_variable_list *var, int low, int high)
185 {
186 register int rc = SNMP_ERR_NOERROR;
187
188 if (NULL == var)
189 return SNMP_ERR_GENERR;
190
191 if ((rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER, sizeof(long))))
192 return rc;
193
194 if ((*var->val.integer < low) || (*var->val.integer > high)) {
195 rc = SNMP_ERR_WRONGVALUE;
196 }
197
198 return rc;
199 }
200
201 #ifndef NETSNMP_FEATURE_REMOVE_CHECK_VB_TRUTHVALUE
202 int
netsnmp_check_vb_truthvalue(const netsnmp_variable_list * var)203 netsnmp_check_vb_truthvalue(const netsnmp_variable_list *var)
204 {
205 register int rc = SNMP_ERR_NOERROR;
206
207 if (NULL == var)
208 return SNMP_ERR_GENERR;
209
210 if ((rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER, sizeof(long))))
211 return rc;
212
213 return netsnmp_check_vb_int_range(var, 1, 2);
214 }
215 #endif /* NETSNMP_FEATURE_REMOVE_CHECK_VB_TRUTHVALUE */
216
217 NETSNMP_INLINE int
netsnmp_check_vb_rowstatus_value(const netsnmp_variable_list * var)218 netsnmp_check_vb_rowstatus_value(const netsnmp_variable_list *var)
219 {
220 register int rc = SNMP_ERR_NOERROR;
221
222 if (NULL == var)
223 return SNMP_ERR_GENERR;
224
225 if ((rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER, sizeof(long))))
226 return rc;
227
228 if (*var->val.integer == RS_NOTREADY)
229 return SNMP_ERR_WRONGVALUE;
230
231 return netsnmp_check_vb_int_range(var, SNMP_ROW_NONEXISTENT,
232 SNMP_ROW_DESTROY);
233 }
234
235 int
netsnmp_check_vb_rowstatus(const netsnmp_variable_list * var,int old_value)236 netsnmp_check_vb_rowstatus(const netsnmp_variable_list *var, int old_value)
237 {
238 register int rc = SNMP_ERR_NOERROR;
239
240 if (NULL == var)
241 return SNMP_ERR_GENERR;
242
243 if ((rc = netsnmp_check_vb_rowstatus_value(var)))
244 return rc;
245
246 return check_rowstatus_transition(old_value, *var->val.integer);
247 }
248
249 #ifndef NETSNMP_FEATURE_REMOVE_CHECK_VB_ROWSTATUS_WITH_STORAGETYPE
250 int
netsnmp_check_vb_rowstatus_with_storagetype(const netsnmp_variable_list * var,int old_value,int old_storage)251 netsnmp_check_vb_rowstatus_with_storagetype(const netsnmp_variable_list *var,
252 int old_value, int old_storage)
253 {
254 register int rc = SNMP_ERR_NOERROR;
255
256 if (NULL == var)
257 return SNMP_ERR_GENERR;
258
259 if ((rc = netsnmp_check_vb_rowstatus_value(var)))
260 return rc;
261
262 return check_rowstatus_with_storagetype_transition(old_value,
263 *var->val.integer,
264 old_storage);
265 }
266 #endif /* NETSNMP_FEATURE_REMOVE_CHECK_VB_ROWSTATUS_WITH_STORAGETYPE */
267
268 #ifndef NETSNMP_FEATURE_REMOVE_CHECK_VB_STORAGETYPE
269 int
netsnmp_check_vb_storagetype(const netsnmp_variable_list * var,int old_value)270 netsnmp_check_vb_storagetype(const netsnmp_variable_list *var, int old_value)
271 {
272 int rc = SNMP_ERR_NOERROR;
273
274 if (NULL == var)
275 return SNMP_ERR_GENERR;
276
277 if ((rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER, sizeof(long))))
278 return rc;
279
280 if ((rc = netsnmp_check_vb_int_range(var, SNMP_STORAGE_NONE,
281 SNMP_STORAGE_READONLY)))
282 return rc;
283
284 return check_storage_transition(old_value, *var->val.integer);
285 }
286 #endif /* NETSNMP_FEATURE_REMOVE_CHECK_VB_STORAGETYPE */
287