Debian Codegraph @

agent/mibgroup/snmpv3/snmpEngine.c

raw
1 /*
2 * snmpEngine.c: implement's the SNMP-FRAMEWORK-MIB.
3 */
4
5 #include <net-snmp/net-snmp-config.h>
6 #include <net-snmp/net-snmp-features.h>
7 #include <net-snmp/net-snmp-includes.h>
8 #include <net-snmp/agent/net-snmp-agent-includes.h>
9 #include <net-snmp/agent/sysORTable.h>
10
11 #include "util_funcs/header_generic.h"
12 #include "snmpEngine.h"
13
14 netsnmp_feature_child_of(snmpengine_all, libnetsnmpmibs);
15
16 netsnmp_feature_child_of(register_snmpEngine_scalars_context, snmpengine_all);
17
18 struct variable2 snmpEngine_variables[] = {
19 {SNMPENGINEID, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
20 var_snmpEngine, 1, {1}},
21 #ifndef NETSNMP_NO_WRITE_SUPPORT
22 #ifdef NETSNMP_ENABLE_TESTING_CODE
23 {SNMPENGINEBOOTS, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE,
24 var_snmpEngine, 1, {2}},
25 {SNMPENGINETIME, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE,
26 var_snmpEngine, 1, {3}},
27 #else /* !NETSNMP_ENABLE_TESTING_CODE */
28 {SNMPENGINEBOOTS, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
29 var_snmpEngine, 1, {2}},
30 {SNMPENGINETIME, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
31 var_snmpEngine, 1, {3}},
32 #endif /* NETSNMP_ENABLE_TESTING_CODE */
33 #else /* !NETSNMP_NO_WRITE_SUPPORT */
34 {SNMPENGINEBOOTS, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
35 var_snmpEngine, 1, {2}},
36 {SNMPENGINETIME, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
37 var_snmpEngine, 1, {3}},
38 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
39 {SNMPENGINEMAXMESSAGESIZE, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
40 var_snmpEngine, 1, {4}},
41 };
42
43 /*
44 * now load this mib into the agents mib table
45 */
46 oid snmpEngine_variables_oid[] =
47 { 1, 3, 6, 1, 6, 3, 10, 2, 1 };
48
49 #if !defined(NETSNMP_NO_WRITE_SUPPORT) && defined(NETSNMP_ENABLE_TESTING_CODE)
50 int write_engineBoots(int action, u_char * var_val, u_char var_val_type,
51 size_t var_val_len, u_char * statP, oid * name,
52 size_t name_len);
53 int write_engineTime(int action, u_char * var_val, u_char var_val_type,
54 size_t var_val_len, u_char * statP, oid * name,
55 size_t name_len);
56 #endif
57
58 void
59 register_snmpEngine_scalars(void)
60 {
61 REGISTER_MIB("snmpv3/snmpEngine", snmpEngine_variables, variable2,
62 snmpEngine_variables_oid);
63 }
64
65 #ifndef NETSNMP_FEATURE_REMOVE_REGISTER_SNMPENGINE_SCALARS_CONTEXT
66 void
67 register_snmpEngine_scalars_context(const char *contextName)
68 {
69 register_mib_context("snmpv3/snmpEngine",
70 (struct variable *) snmpEngine_variables,
71 sizeof(struct variable2),
72 sizeof(snmpEngine_variables)/sizeof(struct variable2),
73 snmpEngine_variables_oid,
74 sizeof(snmpEngine_variables_oid)/sizeof(oid),
75 DEFAULT_MIB_PRIORITY, 0, 0, NULL,
76 contextName, -1, 0);
77 }
78 #endif /* NETSNMP_FEATURE_REMOVE_REGISTER_SNMPENGINE_SCALARS_CONTEXT */
79
80 void
81 init_snmpEngine(void)
82 {
83 oid reg[] = { 1, 3, 6, 1, 6, 3, 10, 3, 1, 1 };
84 REGISTER_SYSOR_ENTRY(reg, "The SNMP Management Architecture MIB.");
85 register_snmpEngine_scalars();
86 }
87
88 u_char *
89 var_snmpEngine(struct variable *vp,
90 oid * name,
91 size_t * length,
92 int exact, size_t * var_len, WriteMethod ** write_method)
93 {
94
95 /*
96 * variables we may use later
97 */
98 static long long_ret;
99 static unsigned char engineID[SNMP_MAXBUF];
100
101 *write_method = (WriteMethod*)0; /* assume it isnt writable for the time being */
102 *var_len = sizeof(long_ret); /* assume an integer and change later if not */
103
104 if (header_generic(vp, name, length, exact, var_len, write_method))
105 return NULL;
106
107 /*
108 * this is where we do the value assignments for the mib results.
109 */
110 switch (vp->magic) {
111
112 case SNMPENGINEID:
113 *var_len = snmpv3_get_engineID(engineID, SNMP_MAXBUF);
114 /*
115 * XXX Set ERROR_MSG() upon error?
116 */
117 return (unsigned char *) engineID;
118
119 case SNMPENGINEBOOTS:
120 #ifndef NETSNMP_NO_WRITE_SUPPORT
121 #ifdef NETSNMP_ENABLE_TESTING_CODE
122 *write_method = write_engineBoots;
123 #endif /* NETSNMP_ENABLE_TESTING_CODE */
124 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
125 long_ret = snmpv3_local_snmpEngineBoots();
126 return (unsigned char *) &long_ret;
127
128 case SNMPENGINETIME:
129 #ifndef NETSNMP_NO_WRITE_SUPPORT
130 #ifdef NETSNMP_ENABLE_TESTING_CODE
131 *write_method = write_engineTime;
132 #endif /* NETSNMP_ENABLE_TESTING_CODE */
133 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
134 long_ret = snmpv3_local_snmpEngineTime();
135 return (unsigned char *) &long_ret;
136
137 case SNMPENGINEMAXMESSAGESIZE:
138 long_ret = 1500;
139 return (unsigned char *) &long_ret;
140
141 default:
142 DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_snmpEngine\n",
143 vp->magic));
144 }
145 return NULL;
146 }
147
148
149 #if !defined(NETSNMP_NO_WRITE_SUPPORT) && defined(NETSNMP_ENABLE_TESTING_CODE)
150 /*
151 * write_engineBoots():
152 *
153 * This is technically not writable a writable mib object, but we
154 * allow it so we can run some time synchronization tests.
155 */
156 int
157 write_engineBoots(int action,
158 u_char * var_val,
159 u_char var_val_type,
160 size_t var_val_len,
161 u_char * statP, oid * name, size_t name_len)
162 {
163 /*
164 * variables we may use later
165 */
166 static long long_ret;
167 u_char engineIDBuf[SNMP_MAXBUF_MEDIUM];
168 int engineIDBufLen = 0;
169
170 if (var_val_type != ASN_INTEGER) {
171 DEBUGMSGTL(("snmpEngine",
172 "write to engineBoots not ASN_INTEGER\n"));
173 return SNMP_ERR_WRONGTYPE;
174 }
175 if (var_val_len > sizeof(long_ret)) {
176 DEBUGMSGTL(("snmpEngine", "write to engineBoots: bad length\n"));
177 return SNMP_ERR_WRONGLENGTH;
178 }
179 long_ret = *((long *) var_val);
180 if (action == COMMIT) {
181 engineIDBufLen =
182 snmpv3_get_engineID(engineIDBuf, SNMP_MAXBUF_MEDIUM);
183 /*
184 * set our local engineTime in the LCD timing cache
185 */
186 snmpv3_set_engineBootsAndTime(long_ret,
187 snmpv3_local_snmpEngineTime());
188 set_enginetime(engineIDBuf, engineIDBufLen,
189 snmpv3_local_snmpEngineBoots(),
190 snmpv3_local_snmpEngineTime(), TRUE);
191 }
192 return SNMP_ERR_NOERROR;
193 }
194
195 /*
196 * write_engineTime():
197 *
198 * This is technically not a writable mib object, but we
199 * allow it so we can run some time synchronization tests.
200 */
201 int
202 write_engineTime(int action,
203 u_char * var_val,
204 u_char var_val_type,
205 size_t var_val_len,
206 u_char * statP, oid * name, size_t name_len)
207 {
208 /*
209 * variables we may use later
210 */
211 static long long_ret;
212 u_char engineIDBuf[SNMP_MAXBUF_MEDIUM];
213 int engineIDBufLen = 0;
214
215 if (var_val_type != ASN_INTEGER) {
216 DEBUGMSGTL(("snmpEngine",
217 "write to engineTime not ASN_INTEGER\n"));
218 return SNMP_ERR_WRONGTYPE;
219 }
220 if (var_val_len > sizeof(long_ret)) {
221 DEBUGMSGTL(("snmpEngine", "write to engineTime: bad length\n"));
222 return SNMP_ERR_WRONGLENGTH;
223 }
224 long_ret = *((long *) var_val);
225 if (action == COMMIT) {
226 engineIDBufLen =
227 snmpv3_get_engineID(engineIDBuf, SNMP_MAXBUF_MEDIUM);
228 /*
229 * set our local engineTime in the LCD timing cache
230 */
231 snmpv3_set_engineBootsAndTime(snmpv3_local_snmpEngineBoots(),
232 long_ret);
233 set_enginetime(engineIDBuf, engineIDBufLen,
234 snmpv3_local_snmpEngineBoots(),
235 snmpv3_local_snmpEngineTime(), TRUE);
236 }
237 return SNMP_ERR_NOERROR;
238 }
239
240 #endif /* ! NETSNMP_NO_WRITE_SUPPORT && NETSNMP_ENABLE_TESTING_CODE */