net-snmp 5.7
|
00001 #include <net-snmp/net-snmp-config.h> 00002 00003 #include <net-snmp/net-snmp-includes.h> 00004 #include <net-snmp/net-snmp-features.h> 00005 00006 #include <net-snmp/library/check_varbind.h> 00007 00008 netsnmp_feature_child_of(check_varbind_all, libnetsnmp) 00009 00010 netsnmp_feature_child_of(check_vb_range, check_varbind_all) 00011 netsnmp_feature_child_of(check_vb_size_range, check_varbind_all) 00012 netsnmp_feature_child_of(check_vb_uint, check_varbind_all) 00013 netsnmp_feature_child_of(check_vb_storagetype, check_varbind_all) 00014 netsnmp_feature_child_of(check_vb_oid, check_varbind_all) 00015 netsnmp_feature_child_of(check_vb_type_and_max_size, check_varbind_all) 00016 netsnmp_feature_child_of(check_vb_type_and_max_size, check_varbind_all) 00017 netsnmp_feature_child_of(check_vb_rowstatus_with_storagetype, check_varbind_all) 00018 netsnmp_feature_child_of(check_vb_truthvalue, check_varbind_all) 00019 00020 #ifdef NETSNMP_FEATURE_REQUIRE_CHECK_VB_ROWSTATUS_WITH_STORAGETYPE 00021 netsnmp_feature_require(check_rowstatus_with_storagetype_transition) 00022 #endif /* NETSNMP_FEATURE_REQUIRES_CHECK_VB_ROWSTATUS_WITH_STORAGETYPE */ 00023 00024 00025 NETSNMP_INLINE int 00026 netsnmp_check_vb_type(const netsnmp_variable_list *var, int type ) 00027 { 00028 register int rc = SNMP_ERR_NOERROR; 00029 00030 if (NULL == var) 00031 return SNMP_ERR_GENERR; 00032 00033 if (var->type != type) { 00034 rc = SNMP_ERR_WRONGTYPE; 00035 } 00036 00037 return rc; 00038 } 00039 00040 NETSNMP_INLINE int 00041 netsnmp_check_vb_size(const netsnmp_variable_list *var, size_t size ) 00042 { 00043 register int rc = SNMP_ERR_NOERROR; 00044 00045 if (NULL == var) 00046 return SNMP_ERR_GENERR; 00047 00048 else if (var->val_len != size) { 00049 rc = SNMP_ERR_WRONGLENGTH; 00050 } 00051 00052 return rc; 00053 } 00054 00055 NETSNMP_INLINE int 00056 netsnmp_check_vb_max_size(const netsnmp_variable_list *var, size_t size ) 00057 { 00058 register int rc = SNMP_ERR_NOERROR; 00059 00060 if (NULL == var) 00061 return SNMP_ERR_GENERR; 00062 00063 else if (var->val_len > size) { 00064 rc = SNMP_ERR_WRONGLENGTH; 00065 } 00066 00067 return rc; 00068 } 00069 00070 #ifndef NETSNMP_FEATURE_REMOVE_CHECK_VB_RANGE 00071 NETSNMP_INLINE int 00072 netsnmp_check_vb_range(const netsnmp_variable_list *var, 00073 size_t low, size_t high ) 00074 { 00075 register int rc = SNMP_ERR_NOERROR; 00076 00077 if (NULL == var) 00078 return SNMP_ERR_GENERR; 00079 00080 if (((size_t)*var->val.integer < low) || ((size_t)*var->val.integer > high)) { 00081 rc = SNMP_ERR_WRONGVALUE; 00082 } 00083 00084 return rc; 00085 } 00086 #endif /* NETSNMP_FEATURE_REMOVE_CHECK_VB_RANGE */ 00087 00088 #ifndef NETSNMP_FEATURE_REMOVE_CHECK_VB_SIZE_RANGE 00089 NETSNMP_INLINE int 00090 netsnmp_check_vb_size_range(const netsnmp_variable_list *var, 00091 size_t low, size_t high ) 00092 { 00093 register int rc = SNMP_ERR_NOERROR; 00094 00095 if (NULL == var) 00096 return SNMP_ERR_GENERR; 00097 00098 if ((var->val_len < low) || (var->val_len > high)) { 00099 rc = SNMP_ERR_WRONGLENGTH; 00100 } 00101 00102 return rc; 00103 } 00104 #endif /* NETSNMP_FEATURE_REMOVE_CHECK_VB_SIZE_RANGE */ 00105 00106 NETSNMP_INLINE int 00107 netsnmp_check_vb_type_and_size(const netsnmp_variable_list *var, 00108 int type, size_t size) 00109 { 00110 register int rc = SNMP_ERR_NOERROR; 00111 00112 if (NULL == var) 00113 return SNMP_ERR_GENERR; 00114 00115 if ((rc = netsnmp_check_vb_type(var,type))) 00116 ; 00117 else 00118 rc = netsnmp_check_vb_size(var, size); 00119 00120 return rc; 00121 } 00122 00123 #ifndef NETSNMP_FEATURE_REMOVE_CHECK_VB_TYPE_AND_MAX_SIZE 00124 NETSNMP_INLINE int 00125 netsnmp_check_vb_type_and_max_size(const netsnmp_variable_list *var, 00126 int type, size_t size) 00127 { 00128 register int rc = SNMP_ERR_NOERROR; 00129 00130 if (NULL == var) 00131 return SNMP_ERR_GENERR; 00132 00133 if ((rc = netsnmp_check_vb_type(var,type))) 00134 ; 00135 else 00136 rc = netsnmp_check_vb_max_size(var, size); 00137 00138 return rc; 00139 } 00140 #endif /* NETSNMP_FEATURE_REMOVE_CHECK_VB_TYPE_AND_MAX_SIZE */ 00141 00142 #ifndef NETSNMP_FEATURE_REMOVE_CHECK_VB_OID 00143 NETSNMP_INLINE int 00144 netsnmp_check_vb_oid(const netsnmp_variable_list *var) 00145 { 00146 register int rc = SNMP_ERR_NOERROR; 00147 00148 if (NULL == var) 00149 return SNMP_ERR_GENERR; 00150 00151 if ((rc = netsnmp_check_vb_type(var,ASN_OBJECT_ID))) 00152 ; 00153 else 00154 rc = netsnmp_check_vb_max_size(var, MAX_OID_LEN*sizeof(oid)); 00155 00156 return rc; 00157 } 00158 #endif /* NETSNMP_FEATURE_REMOVE_CHECK_VB_OID */ 00159 00160 NETSNMP_INLINE int 00161 netsnmp_check_vb_int(const netsnmp_variable_list *var) 00162 { 00163 if (NULL == var) 00164 return SNMP_ERR_GENERR; 00165 00166 return netsnmp_check_vb_type_and_size(var, ASN_INTEGER, sizeof(long)); 00167 } 00168 00169 #ifndef NETSNMP_FEATURE_REMOVE_CHECK_VB_UINT 00170 NETSNMP_INLINE int 00171 netsnmp_check_vb_uint(const netsnmp_variable_list *var) 00172 { 00173 if (NULL == var) 00174 return SNMP_ERR_GENERR; 00175 00176 return netsnmp_check_vb_type_and_size(var, ASN_UNSIGNED, sizeof(long)); 00177 } 00178 #endif /* NETSNMP_FEATURE_REMOVE_CHECK_VB_UINT */ 00179 00180 NETSNMP_INLINE int 00181 netsnmp_check_vb_int_range(const netsnmp_variable_list *var, int low, int high) 00182 { 00183 register int rc = SNMP_ERR_NOERROR; 00184 00185 if (NULL == var) 00186 return SNMP_ERR_GENERR; 00187 00188 if ((rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER, sizeof(long)))) 00189 return rc; 00190 00191 if ((*var->val.integer < low) || (*var->val.integer > high)) { 00192 rc = SNMP_ERR_WRONGVALUE; 00193 } 00194 00195 return rc; 00196 } 00197 00198 #ifndef NETSNMP_FEATURE_REMOVE_CHECK_VB_TRUTHVALUE 00199 int 00200 netsnmp_check_vb_truthvalue(const netsnmp_variable_list *var) 00201 { 00202 register int rc = SNMP_ERR_NOERROR; 00203 00204 if (NULL == var) 00205 return SNMP_ERR_GENERR; 00206 00207 if ((rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER, sizeof(long)))) 00208 return rc; 00209 00210 return netsnmp_check_vb_int_range(var, 1, 2); 00211 } 00212 #endif /* NETSNMP_FEATURE_REMOVE_CHECK_VB_TRUTHVALUE */ 00213 00214 NETSNMP_INLINE int 00215 netsnmp_check_vb_rowstatus_value(const netsnmp_variable_list *var) 00216 { 00217 register int rc = SNMP_ERR_NOERROR; 00218 00219 if (NULL == var) 00220 return SNMP_ERR_GENERR; 00221 00222 if ((rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER, sizeof(long)))) 00223 return rc; 00224 00225 if (*var->val.integer == RS_NOTREADY) 00226 return SNMP_ERR_WRONGVALUE; 00227 00228 return netsnmp_check_vb_int_range(var, SNMP_ROW_NONEXISTENT, 00229 SNMP_ROW_DESTROY); 00230 } 00231 00232 int 00233 netsnmp_check_vb_rowstatus(const netsnmp_variable_list *var, int old_value) 00234 { 00235 register int rc = SNMP_ERR_NOERROR; 00236 00237 if (NULL == var) 00238 return SNMP_ERR_GENERR; 00239 00240 if ((rc = netsnmp_check_vb_rowstatus_value(var))) 00241 return rc; 00242 00243 return check_rowstatus_transition(old_value, *var->val.integer); 00244 } 00245 00246 #ifndef NETSNMP_FEATURE_REMOVE_CHECK_VB_ROWSTATUS_WITH_STORAGETYPE 00247 int 00248 netsnmp_check_vb_rowstatus_with_storagetype(const netsnmp_variable_list *var, 00249 int old_value, int old_storage) 00250 { 00251 register int rc = SNMP_ERR_NOERROR; 00252 00253 if (NULL == var) 00254 return SNMP_ERR_GENERR; 00255 00256 if ((rc = netsnmp_check_vb_rowstatus_value(var))) 00257 return rc; 00258 00259 return check_rowstatus_with_storagetype_transition(old_value, 00260 *var->val.integer, 00261 old_storage); 00262 } 00263 #endif /* NETSNMP_FEATURE_REMOVE_CHECK_VB_ROWSTATUS_WITH_STORAGETYPE */ 00264 00265 #ifndef NETSNMP_FEATURE_REMOVE_CHECK_VB_STORAGETYPE 00266 int 00267 netsnmp_check_vb_storagetype(const netsnmp_variable_list *var, int old_value) 00268 { 00269 int rc = SNMP_ERR_NOERROR; 00270 00271 if (NULL == var) 00272 return SNMP_ERR_GENERR; 00273 00274 if ((rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER, sizeof(long)))) 00275 return rc; 00276 00277 if ((rc = netsnmp_check_vb_int_range(var, SNMP_STORAGE_NONE, 00278 SNMP_STORAGE_READONLY))) 00279 return rc; 00280 00281 return check_storage_transition(old_value, *var->val.integer); 00282 } 00283 #endif /* NETSNMP_FEATURE_REMOVE_CHECK_VB_STORAGETYPE */