1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 1996 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26 #pragma ident "%Z%%M% %I% %E% SMI"
27
28 #include <sys/types.h>
29 #include <netinet/in.h>
30
31 #include "impl.h"
32 #include "asn1.h"
33 #include "error.h"
34 #include "snmp.h"
35 #include "trap.h"
36 #include "pdu.h"
37 #include "node.h"
38
39 #include "snmpdx_stub.h"
40
41
42
43 /***** regTreeEntry ********************************/
44
get_regTreeEntry(int search_type,RegTreeEntry_t ** regTreeEntry_data,IndexType * index)45 extern int get_regTreeEntry(int search_type, RegTreeEntry_t **regTreeEntry_data, IndexType *index)
46 {
47
48 int res;
49
50 *regTreeEntry_data = (RegTreeEntry_t*)calloc(1,sizeof(RegTreeEntry_t));
51 if(regTreeEntry_data == NULL) return SNMP_ERR_GENERR;
52
53 res = get_regTreeIndex(
54 search_type,
55 &((*regTreeEntry_data)->regTreeIndex),
56 index);
57 if(res != SNMP_ERR_NOERROR) return res;
58
59 res = get_regTreeAgentID(
60 search_type,
61 &((*regTreeEntry_data)->regTreeAgentID),
62 index);
63 if(res != SNMP_ERR_NOERROR) return res;
64
65 res = get_regTreeOID(
66 search_type,
67 &((*regTreeEntry_data)->regTreeOID),
68 index);
69 if(res != SNMP_ERR_NOERROR) return res;
70
71 res = get_regTreeStatus(
72 search_type,
73 &((*regTreeEntry_data)->regTreeStatus),
74 index);
75 if(res != SNMP_ERR_NOERROR) return res;
76
77 return res;
78 }
79
80
free_regTreeEntry(RegTreeEntry_t * regTreeEntry)81 void free_regTreeEntry(RegTreeEntry_t *regTreeEntry)
82 {
83 free_regTreeOID(&(regTreeEntry->regTreeOID));
84 }
85
get_regTreeIndex(int search_type,Integer * regTreeIndex,IndexType * index)86 int get_regTreeIndex(int search_type, Integer *regTreeIndex, IndexType *index)
87 {
88 /* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
89 /* this function should modify the index argument to the */
90 /* appropriate value */
91 switch(search_type)
92 {
93 case FIRST_ENTRY:
94 if(index->type == INTEGER){
95
96 /* assume 1 is the first index */
97
98 index->value[0] = 1;
99 index->len = 1;
100 }else{
101
102 /* index type will be array of integer */
103 /* assume that there are two index */
104
105 index->value[0] = 1;
106 index->value[1]= 1;
107 index->len = 2;
108 }
109 break;
110
111 case NEXT_ENTRY:
112 if(index->type == INTEGER){
113 index->value[0]++;
114 }else{
115
116 /* index type will be array of integer */
117 /* assume that there are two index */
118
119 index->value[index->len-1]++;
120 }
121 break;
122
123 case EXACT_ENTRY:
124 break;
125 }
126
127 /*assume that the mib variable has a value of 1 */
128
129 *regTreeIndex = 1;
130 return SNMP_ERR_NOERROR;
131 }
132
get_regTreeAgentID(int search_type,Integer * regTreeAgentID,IndexType * index)133 int get_regTreeAgentID(int search_type, Integer *regTreeAgentID, IndexType *index)
134 {
135 /* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
136 /* this function should modify the index argument to the */
137 /* appropriate value */
138 switch(search_type)
139 {
140 case FIRST_ENTRY:
141 if(index->type == INTEGER){
142
143 /* assume 1 is the first index */
144
145 index->value[0] = 1;
146 index->len = 1;
147 }else{
148
149 /* index type will be array of integer */
150 /* assume that there are two index */
151
152 index->value[0] = 1;
153 index->value[1]= 1;
154 index->len = 2;
155 }
156 break;
157
158 case NEXT_ENTRY:
159 if(index->type == INTEGER){
160 index->value[0]++;
161 }else{
162
163 /* index type will be array of integer */
164 /* assume that there are two index */
165
166 index->value[index->len-1]++;
167 }
168 break;
169
170 case EXACT_ENTRY:
171 break;
172 }
173
174 /*assume that the mib variable has a value of 1 */
175
176 *regTreeAgentID = 1;
177 return SNMP_ERR_NOERROR;
178 }
179
get_regTreeOID(int search_type,Oid * regTreeOID,IndexType * index)180 int get_regTreeOID(int search_type, Oid *regTreeOID, IndexType *index)
181 {
182 Subid *sub;
183 Subid fake_sub[] = {1,3,6,1,4,1,4,42};
184 int len;
185
186 /* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
187 /* this function should modify the index argument to the */
188 /* appropriate value */
189 switch(search_type)
190 {
191 case FIRST_ENTRY:
192 if(index->type == INTEGER){
193
194 /* assume 1 is the first index */
195
196 index->value[0] = 1;
197 index->len = 1;
198 }else{
199
200 /* index type will be array of integer */
201 /* assume that there are two index */
202
203 index->value[0] = 1;
204 index->value[1]= 1;
205 index->len = 2;
206 }
207 break;
208
209 case NEXT_ENTRY:
210 if(index->type == INTEGER){
211 index->value[0]++;
212 }else{
213
214 /* index type will be array of integer */
215 /* assume that there are two index */
216
217 index->value[index->len-1]++;
218 }
219 break;
220
221 case EXACT_ENTRY:
222 break;
223 }
224
225 /* It is required to allocate memory to the pointers */
226 /* inside the input argument */
227 /* Here, we assume that "1.3.6.1.4.1.42" is the value */
228 /* of the mib variable */
229 /* please change it to the real one */
230
231 /* 1.3.6.1.4.1.42 has 7 number separated by "." */
232
233 len =7 ;
234 sub = (Subid*)calloc(len,sizeof(Subid));
235 if(sub==NULL) return SNMP_ERR_GENERR;
236 memcpy(sub,fake_sub,len*sizeof(Subid));
237
238 /* fill in the contents of the argument */
239
240 regTreeOID->subids = sub;
241 regTreeOID->len = len;
242 return SNMP_ERR_NOERROR;
243 }
244
set_regTreeOID(int pass,IndexType index,Oid * regTreeOID)245 int set_regTreeOID(int pass, IndexType index, Oid *regTreeOID)
246 {
247 switch(pass)
248 {
249 case FIRST_PASS:
250
251 /* check the existence of the element which */
252 /* corresponding to the given index and */
253 /* check the validity fo the input value */
254 /* if not valid or not exist, */
255
256 return SNMP_ERR_GENERR;
257
258 case SECOND_PASS:
259
260 /* change the following coding, such that */
261 /* the input value will be stored in the */
262 /* corresponding mib variable of the given */
263 /* index */
264 printf("The new value is %s\n",SSAOidString(regTreeOID));
265 return SNMP_ERR_NOERROR;
266 }
267 }
268
269
free_regTreeOID(Oid * regTreeOID)270 void free_regTreeOID(Oid *regTreeOID)
271 {
272 if(regTreeOID->subids!=NULL && regTreeOID->len !=0)
273 {
274 free(regTreeOID->subids);
275 regTreeOID->len = 0;
276 }
277 }
278
get_regTreeStatus(int search_type,Integer * regTreeStatus,IndexType * index)279 int get_regTreeStatus(int search_type, Integer *regTreeStatus, IndexType *index)
280 {
281 /* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
282 /* this function should modify the index argument to the */
283 /* appropriate value */
284 switch(search_type)
285 {
286 case FIRST_ENTRY:
287 if(index->type == INTEGER){
288
289 /* assume 1 is the first index */
290
291 index->value[0] = 1;
292 index->len = 1;
293 }else{
294
295 /* index type will be array of integer */
296 /* assume that there are two index */
297
298 index->value[0] = 1;
299 index->value[1]= 1;
300 index->len = 2;
301 }
302 break;
303
304 case NEXT_ENTRY:
305 if(index->type == INTEGER){
306 index->value[0]++;
307 }else{
308
309 /* index type will be array of integer */
310 /* assume that there are two index */
311
312 index->value[index->len-1]++;
313 }
314 break;
315
316 case EXACT_ENTRY:
317 break;
318 }
319
320 /*assume that the mib variable has a value of 1 */
321
322 *regTreeStatus = 1;
323 return SNMP_ERR_NOERROR;
324 }
325
set_regTreeStatus(int pass,IndexType index,Integer * regTreeStatus)326 int set_regTreeStatus(int pass, IndexType index, Integer *regTreeStatus)
327 {
328 switch(pass)
329 {
330 case FIRST_PASS:
331
332 /* check the existence of the element which */
333 /* corresponding to the given index and */
334 /* check the validity fo the input value */
335 /* if not valid or not exist, */
336
337 return SNMP_ERR_GENERR;
338
339 case SECOND_PASS:
340
341 /* change the following coding, such that */
342 /* the input value will be stored in the */
343 /* corresponding mib variable of the given */
344 /* index */
345 printf("The new value is %d\n",regTreeStatus);
346 return SNMP_ERR_NOERROR;
347 }
348 }
349
350