| 1 |
#include <net-snmp/net-snmp-config.h> |
| 2 |
#include <net-snmp/net-snmp-features.h> |
| 3 |
|
| 4 |
#include <sys/types.h> |
| 5 |
#ifdef TIME_WITH_SYS_TIME |
| 6 |
# include <sys/time.h> |
| 7 |
# include <time.h> |
| 8 |
#else |
| 9 |
# ifdef HAVE_SYS_TIME_H |
| 10 |
# include <sys/time.h> |
| 11 |
# else |
| 12 |
# include <time.h> |
| 13 |
# endif |
| 14 |
#endif |
| 15 |
#ifdef HAVE_NETINET_IN_H |
| 16 |
#include <netinet/in.h> |
| 17 |
#endif |
| 18 |
#ifdef HAVE_STRING_H |
| 19 |
#include <string.h> |
| 20 |
#endif |
| 21 |
|
| 22 |
#include <net-snmp/net-snmp-includes.h> |
| 23 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 24 |
|
| 25 |
#include "struct.h" |
| 26 |
#include "versioninfo.h" |
| 27 |
#include "util_funcs/header_generic.h" |
| 28 |
#include "util_funcs/restart.h" |
| 29 |
#include "util_funcs.h" /* clear_cache */ |
| 30 |
|
| 31 |
netsnmp_feature_require(clear_cache); |
| 32 |
|
| 33 |
|
| 34 |
void |
| 35 |
init_versioninfo(void) |
| 36 |
{ |
| 37 |
|
| 38 |
/* |
| 39 |
* define the structure we're going to ask the agent to register our |
| 40 |
* information at |
| 41 |
*/ |
| 42 |
struct variable2 extensible_version_variables[] = { |
| 43 |
{MIBINDEX, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, |
| 44 |
var_extensible_version, 1, {MIBINDEX}}, |
| 45 |
{VERTAG, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, |
| 46 |
var_extensible_version, 1, {VERTAG}}, |
| 47 |
{VERDATE, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, |
| 48 |
var_extensible_version, 1, {VERDATE}}, |
| 49 |
{VERCDATE, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, |
| 50 |
var_extensible_version, 1, {VERCDATE}}, |
| 51 |
{VERIDENT, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, |
| 52 |
var_extensible_version, 1, {VERIDENT}}, |
| 53 |
{VERCONFIG, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, |
| 54 |
var_extensible_version, 1, {VERCONFIG}}, |
| 55 |
{VERCLEARCACHE, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, |
| 56 |
var_extensible_version, 1, {VERCLEARCACHE}}, |
| 57 |
{VERUPDATECONFIG, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, |
| 58 |
var_extensible_version, 1, {VERUPDATECONFIG}}, |
| 59 |
{VERRESTARTAGENT, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, |
| 60 |
var_extensible_version, 1, {VERRESTARTAGENT}}, |
| 61 |
{VERSAVEPERSISTENT, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, |
| 62 |
var_extensible_version, 1, {VERSAVEPERSISTENT}}, |
| 63 |
{VERDEBUGGING, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, |
| 64 |
var_extensible_version, 1, {VERDEBUGGING}} |
| 65 |
}; |
| 66 |
|
| 67 |
/* |
| 68 |
* Define the OID pointer to the top of the mib tree that we're |
| 69 |
* registering underneath |
| 70 |
*/ |
| 71 |
oid version_variables_oid[] = |
| 72 |
{ NETSNMP_UCDAVIS_MIB, NETSNMP_VERSIONMIBNUM }; |
| 73 |
|
| 74 |
/* |
| 75 |
* register ourselves with the agent to handle our mib tree |
| 76 |
*/ |
| 77 |
REGISTER_MIB("ucd-snmp/versioninfo", extensible_version_variables, |
| 78 |
variable2, version_variables_oid); |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
u_char * |
| 84 |
var_extensible_version(struct variable *vp, |
| 85 |
oid * name, |
| 86 |
size_t * length, |
| 87 |
int exact, |
| 88 |
size_t * var_len, WriteMethod ** write_method) |
| 89 |
{ |
| 90 |
|
| 91 |
static long long_ret; |
| 92 |
static char errmsg[300]; |
| 93 |
char *cptr; |
| 94 |
time_t curtime; |
| 95 |
#ifdef NETSNMP_CONFIGURE_OPTIONS |
| 96 |
static char config_opts[] = NETSNMP_CONFIGURE_OPTIONS; |
| 97 |
#endif |
| 98 |
|
| 99 |
DEBUGMSGTL(("ucd-snmp/versioninfo", "var_extensible_version: ")); |
| 100 |
DEBUGMSGOID(("ucd-snmp/versioninfo", name, *length)); |
| 101 |
DEBUGMSG(("ucd-snmp/versioninfo", " %d\n", exact)); |
| 102 |
|
| 103 |
if (header_generic(vp, name, length, exact, var_len, write_method)) |
| 104 |
return (NULL); |
| 105 |
|
| 106 |
switch (vp->magic) { |
| 107 |
case MIBINDEX: |
| 108 |
long_ret = name[8]; |
| 109 |
return ((u_char *) (&long_ret)); |
| 110 |
case VERTAG: |
| 111 |
strlcpy(errmsg, netsnmp_get_version(), sizeof(errmsg)); |
| 112 |
*var_len = strlen(errmsg); |
| 113 |
return ((u_char *) errmsg); |
| 114 |
case VERDATE: |
| 115 |
strlcpy(errmsg, "$Date$", sizeof(errmsg)); |
| 116 |
*var_len = strlen(errmsg); |
| 117 |
return ((u_char *) errmsg); |
| 118 |
case VERCDATE: |
| 119 |
curtime = time(NULL); |
| 120 |
cptr = ctime(&curtime); |
| 121 |
strlcpy(errmsg, cptr, sizeof(errmsg)); |
| 122 |
*var_len = strlen(errmsg) - 1; /* - 1 to strip trailing newline */ |
| 123 |
return ((u_char *) errmsg); |
| 124 |
case VERIDENT: |
| 125 |
strlcpy(errmsg, "$Id$", sizeof(errmsg)); |
| 126 |
*var_len = strlen(errmsg); |
| 127 |
return ((u_char *) errmsg); |
| 128 |
case VERCONFIG: |
| 129 |
#ifdef NETSNMP_CONFIGURE_OPTIONS |
| 130 |
*var_len = strlen(config_opts); |
| 131 |
if (*var_len > 1024) |
| 132 |
*var_len = 1024; /* mib imposed restriction */ |
| 133 |
return (u_char *) config_opts; |
| 134 |
#else |
| 135 |
strlcpy(errmsg, "", sizeof(errmsg)); |
| 136 |
*var_len = strlen(errmsg); |
| 137 |
return ((u_char *) errmsg); |
| 138 |
#endif |
| 139 |
case VERCLEARCACHE: |
| 140 |
*write_method = clear_cache; |
| 141 |
long_ret = 0; |
| 142 |
return ((u_char *) & long_ret); |
| 143 |
case VERUPDATECONFIG: |
| 144 |
*write_method = update_hook; |
| 145 |
long_ret = 0; |
| 146 |
return ((u_char *) & long_ret); |
| 147 |
case VERRESTARTAGENT: |
| 148 |
*write_method = restart_hook; |
| 149 |
long_ret = 0; |
| 150 |
return ((u_char *) & long_ret); |
| 151 |
case VERSAVEPERSISTENT: |
| 152 |
*write_method = save_persistent; |
| 153 |
long_ret = 0; |
| 154 |
return ((u_char *) & long_ret); |
| 155 |
case VERDEBUGGING: |
| 156 |
*write_method = debugging_hook; |
| 157 |
long_ret = snmp_get_do_debugging(); |
| 158 |
return ((u_char *) & long_ret); |
| 159 |
} |
| 160 |
return NULL; |
| 161 |
} |
| 162 |
|
| 163 |
int |
| 164 |
update_hook(int action, |
| 165 |
u_char * var_val, |
| 166 |
u_char var_val_type, |
| 167 |
size_t var_val_len, |
| 168 |
u_char * statP, oid * name, size_t name_len) |
| 169 |
{ |
| 170 |
long tmp = 0; |
| 171 |
|
| 172 |
if (var_val_type != ASN_INTEGER) { |
| 173 |
snmp_log(LOG_ERR, "Wrong type != int\n"); |
| 174 |
return SNMP_ERR_WRONGTYPE; |
| 175 |
} |
| 176 |
tmp = *((long *) var_val); |
| 177 |
if (tmp == 1 && action == COMMIT) { |
| 178 |
update_config(); |
| 179 |
} |
| 180 |
return SNMP_ERR_NOERROR; |
| 181 |
} |
| 182 |
|
| 183 |
int |
| 184 |
debugging_hook(int action, |
| 185 |
u_char * var_val, |
| 186 |
u_char var_val_type, |
| 187 |
size_t var_val_len, |
| 188 |
u_char * statP, oid * name, size_t name_len) |
| 189 |
{ |
| 190 |
long tmp = 0; |
| 191 |
|
| 192 |
if (var_val_type != ASN_INTEGER) { |
| 193 |
DEBUGMSGTL(("versioninfo", "Wrong type != int\n")); |
| 194 |
return SNMP_ERR_WRONGTYPE; |
| 195 |
} |
| 196 |
tmp = *((long *) var_val); |
| 197 |
if (action == COMMIT) { |
| 198 |
snmp_set_do_debugging(tmp); |
| 199 |
} |
| 200 |
return SNMP_ERR_NOERROR; |
| 201 |
} |
| 202 |
|
| 203 |
int |
| 204 |
save_persistent(int action, |
| 205 |
u_char * var_val, |
| 206 |
u_char var_val_type, |
| 207 |
size_t var_val_len, |
| 208 |
u_char * statP, oid * name, size_t name_len) |
| 209 |
{ |
| 210 |
if (var_val_type != ASN_INTEGER) { |
| 211 |
DEBUGMSGTL(("versioninfo", "Wrong type != int\n")); |
| 212 |
return SNMP_ERR_WRONGTYPE; |
| 213 |
} |
| 214 |
if (action == COMMIT) { |
| 215 |
snmp_store(netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, |
| 216 |
NETSNMP_DS_LIB_APPTYPE)); |
| 217 |
} |
| 218 |
return SNMP_ERR_NOERROR; |
| 219 |
} |