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