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 /***** regTblEntry          ********************************/
44 
get_regTblEntry(int search_type,RegTblEntry_t ** regTblEntry_data,IndexType * index)45 extern int get_regTblEntry(int search_type, RegTblEntry_t **regTblEntry_data, IndexType *index)
46 {
47 
48 	int res;
49 
50 	*regTblEntry_data = (RegTblEntry_t*)calloc(1,sizeof(RegTblEntry_t));
51 	if(regTblEntry_data == NULL) return SNMP_ERR_GENERR;
52 
53 	res = get_regTblIndex(
54 	        search_type,
55 	        &((*regTblEntry_data)->regTblIndex),
56 	        index);
57 	if(res != SNMP_ERR_NOERROR) return res;
58 
59 	res = get_regTblAgentID(
60 	        search_type,
61 	        &((*regTblEntry_data)->regTblAgentID),
62 	        index);
63 	if(res != SNMP_ERR_NOERROR) return res;
64 
65 	res = get_regTblOID(
66 	        search_type,
67 	        &((*regTblEntry_data)->regTblOID),
68 	        index);
69 	if(res != SNMP_ERR_NOERROR) return res;
70 
71 	res = get_regTblStartColumn(
72 	        search_type,
73 	        &((*regTblEntry_data)->regTblStartColumn),
74 	        index);
75 	if(res != SNMP_ERR_NOERROR) return res;
76 
77 	res = get_regTblEndColumn(
78 	        search_type,
79 	        &((*regTblEntry_data)->regTblEndColumn),
80 	        index);
81 	if(res != SNMP_ERR_NOERROR) return res;
82 
83 	res = get_regTblStartRow(
84 	        search_type,
85 	        &((*regTblEntry_data)->regTblStartRow),
86 	        index);
87 	if(res != SNMP_ERR_NOERROR) return res;
88 
89 	res = get_regTblEndRow(
90 	        search_type,
91 	        &((*regTblEntry_data)->regTblEndRow),
92 	        index);
93 	if(res != SNMP_ERR_NOERROR) return res;
94 
95 	res = get_regTblStatus(
96 	        search_type,
97 	        &((*regTblEntry_data)->regTblStatus),
98 	        index);
99 	if(res != SNMP_ERR_NOERROR) return res;
100 
101 	 return res;
102 }
103 
104 
free_regTblEntry(RegTblEntry_t * regTblEntry)105 void free_regTblEntry(RegTblEntry_t *regTblEntry)
106 {
107 	free_regTblOID(&(regTblEntry->regTblOID));
108 }
109 
get_regTblIndex(int search_type,Integer * regTblIndex,IndexType * index)110 int get_regTblIndex(int search_type, Integer *regTblIndex, IndexType *index)
111 {
112 	/* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
113 	/* this function should modify the index argument to the */
114 	/* appropriate value */
115 	switch(search_type)
116 	{
117 		case FIRST_ENTRY:
118 			if(index->type == INTEGER){
119 
120 				/* assume 1 is the first index */
121 
122 				index->value[0] = 1;
123 				index->len = 1;
124 			}else{
125 
126 				/* index type will be array of integer */
127 				/* assume that there are two index */
128 
129 				index->value[0] = 1;
130 				index->value[1]= 1;
131 				index->len = 2;
132 			}
133 			break;
134 
135 		case NEXT_ENTRY:
136 			if(index->type == INTEGER){
137 				index->value[0]++;
138 			}else{
139 
140 				/* index type will be array of integer */
141 				/* assume that there are two index */
142 
143 				index->value[index->len-1]++;
144 			}
145 			break;
146 
147 		case EXACT_ENTRY:
148 			break;
149 	}
150 
151 	/*assume that the mib variable has a value of 1 */
152 
153 	*regTblIndex = 1;
154 	return SNMP_ERR_NOERROR;
155 }
156 
get_regTblAgentID(int search_type,Integer * regTblAgentID,IndexType * index)157 int get_regTblAgentID(int search_type, Integer *regTblAgentID, IndexType *index)
158 {
159 	/* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
160 	/* this function should modify the index argument to the */
161 	/* appropriate value */
162 	switch(search_type)
163 	{
164 		case FIRST_ENTRY:
165 			if(index->type == INTEGER){
166 
167 				/* assume 1 is the first index */
168 
169 				index->value[0] = 1;
170 				index->len = 1;
171 			}else{
172 
173 				/* index type will be array of integer */
174 				/* assume that there are two index */
175 
176 				index->value[0] = 1;
177 				index->value[1]= 1;
178 				index->len = 2;
179 			}
180 			break;
181 
182 		case NEXT_ENTRY:
183 			if(index->type == INTEGER){
184 				index->value[0]++;
185 			}else{
186 
187 				/* index type will be array of integer */
188 				/* assume that there are two index */
189 
190 				index->value[index->len-1]++;
191 			}
192 			break;
193 
194 		case EXACT_ENTRY:
195 			break;
196 	}
197 
198 	/*assume that the mib variable has a value of 1 */
199 
200 	*regTblAgentID = 1;
201 	return SNMP_ERR_NOERROR;
202 }
203 
get_regTblOID(int search_type,Oid * regTblOID,IndexType * index)204 int get_regTblOID(int search_type, Oid *regTblOID, IndexType *index)
205 {
206 	Subid *sub;
207 	Subid fake_sub[] = {1,3,6,1,4,1,4,42};
208 	int len;
209 
210 	/* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
211 	/* this function should modify the index argument to the */
212 	/* appropriate value */
213 	switch(search_type)
214 	{
215 		case FIRST_ENTRY:
216 			if(index->type == INTEGER){
217 
218 				/* assume 1 is the first index */
219 
220 				index->value[0] = 1;
221 				index->len = 1;
222 			}else{
223 
224 				/* index type will be array of integer */
225 				/* assume that there are two index */
226 
227 				index->value[0] = 1;
228 				index->value[1]= 1;
229 				index->len = 2;
230 			}
231 			break;
232 
233 		case NEXT_ENTRY:
234 			if(index->type == INTEGER){
235 				index->value[0]++;
236 			}else{
237 
238 				/* index type will be array of integer */
239 				/* assume that there are two index */
240 
241 				index->value[index->len-1]++;
242 			}
243 			break;
244 
245 		case EXACT_ENTRY:
246 			break;
247 	}
248 
249 	/* It is required to allocate memory to the pointers */
250 	/* inside the input argument */
251 	/* Here, we assume that "1.3.6.1.4.1.42" is the value */
252 	/* of the mib variable */
253 	/* please change it to the real one */
254 
255 	/* 1.3.6.1.4.1.42 has 7 number separated by "." */
256 
257 	len =7 ;
258 	sub = (Subid*)calloc(len,sizeof(Subid));
259 	if(sub==NULL) return SNMP_ERR_GENERR;
260 	memcpy(sub,fake_sub,len*sizeof(Subid));
261 
262 	/* fill in the contents of the argument */
263 
264 	regTblOID->subids = sub;
265 	regTblOID->len = len;
266 	return SNMP_ERR_NOERROR;
267 }
268 
set_regTblOID(int pass,IndexType index,Oid * regTblOID)269 int set_regTblOID(int pass, IndexType index, Oid *regTblOID)
270 {
271 	switch(pass)
272 	{
273 		case FIRST_PASS:
274 
275 			/* check the existence of the element which */
276 			/* corresponding to the given index and */
277 			/* check the validity fo the input value */
278 			/* if not valid or not exist, */
279 
280 			return SNMP_ERR_GENERR;
281 
282 		case SECOND_PASS:
283 
284 			/* change the following coding, such that */
285 			/* the input value will be stored in the */
286 			/* corresponding mib variable of the given */
287 			/* index */
288 			printf("The new value is %s\n",SSAOidString(regTblOID));
289 			return SNMP_ERR_NOERROR;
290 	}
291 }
292 
293 
free_regTblOID(Oid * regTblOID)294 void free_regTblOID(Oid *regTblOID)
295 {
296 	 if(regTblOID->subids!=NULL && regTblOID->len !=0)
297 	{
298 		free(regTblOID->subids);
299 		regTblOID->len = 0;
300 	}
301 }
302 
get_regTblStartColumn(int search_type,Integer * regTblStartColumn,IndexType * index)303 int get_regTblStartColumn(int search_type, Integer *regTblStartColumn, IndexType *index)
304 {
305 	/* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
306 	/* this function should modify the index argument to the */
307 	/* appropriate value */
308 	switch(search_type)
309 	{
310 		case FIRST_ENTRY:
311 			if(index->type == INTEGER){
312 
313 				/* assume 1 is the first index */
314 
315 				index->value[0] = 1;
316 				index->len = 1;
317 			}else{
318 
319 				/* index type will be array of integer */
320 				/* assume that there are two index */
321 
322 				index->value[0] = 1;
323 				index->value[1]= 1;
324 				index->len = 2;
325 			}
326 			break;
327 
328 		case NEXT_ENTRY:
329 			if(index->type == INTEGER){
330 				index->value[0]++;
331 			}else{
332 
333 				/* index type will be array of integer */
334 				/* assume that there are two index */
335 
336 				index->value[index->len-1]++;
337 			}
338 			break;
339 
340 		case EXACT_ENTRY:
341 			break;
342 	}
343 
344 	/*assume that the mib variable has a value of 1 */
345 
346 	*regTblStartColumn = 1;
347 	return SNMP_ERR_NOERROR;
348 }
349 
set_regTblStartColumn(int pass,IndexType index,Integer * regTblStartColumn)350 int set_regTblStartColumn(int pass, IndexType index, Integer *regTblStartColumn)
351 {
352 	switch(pass)
353 	{
354 		case FIRST_PASS:
355 
356 			/* check the existence of the element which */
357 			/* corresponding to the given index and */
358 			/* check the validity fo the input value */
359 			/* if not valid or not exist, */
360 
361 			return SNMP_ERR_GENERR;
362 
363 		case SECOND_PASS:
364 
365 			/* change the following coding, such that */
366 			/* the input value will be stored in the */
367 			/* corresponding mib variable of the given */
368 			/* index */
369 			printf("The new value is %d\n",regTblStartColumn);
370 			return SNMP_ERR_NOERROR;
371 	}
372 }
373 
374 
get_regTblEndColumn(int search_type,Integer * regTblEndColumn,IndexType * index)375 int get_regTblEndColumn(int search_type, Integer *regTblEndColumn, IndexType *index)
376 {
377 	/* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
378 	/* this function should modify the index argument to the */
379 	/* appropriate value */
380 	switch(search_type)
381 	{
382 		case FIRST_ENTRY:
383 			if(index->type == INTEGER){
384 
385 				/* assume 1 is the first index */
386 
387 				index->value[0] = 1;
388 				index->len = 1;
389 			}else{
390 
391 				/* index type will be array of integer */
392 				/* assume that there are two index */
393 
394 				index->value[0] = 1;
395 				index->value[1]= 1;
396 				index->len = 2;
397 			}
398 			break;
399 
400 		case NEXT_ENTRY:
401 			if(index->type == INTEGER){
402 				index->value[0]++;
403 			}else{
404 
405 				/* index type will be array of integer */
406 				/* assume that there are two index */
407 
408 				index->value[index->len-1]++;
409 			}
410 			break;
411 
412 		case EXACT_ENTRY:
413 			break;
414 	}
415 
416 	/*assume that the mib variable has a value of 1 */
417 
418 	*regTblEndColumn = 1;
419 	return SNMP_ERR_NOERROR;
420 }
421 
set_regTblEndColumn(int pass,IndexType index,Integer * regTblEndColumn)422 int set_regTblEndColumn(int pass, IndexType index, Integer *regTblEndColumn)
423 {
424 	switch(pass)
425 	{
426 		case FIRST_PASS:
427 
428 			/* check the existence of the element which */
429 			/* corresponding to the given index and */
430 			/* check the validity fo the input value */
431 			/* if not valid or not exist, */
432 
433 			return SNMP_ERR_GENERR;
434 
435 		case SECOND_PASS:
436 
437 			/* change the following coding, such that */
438 			/* the input value will be stored in the */
439 			/* corresponding mib variable of the given */
440 			/* index */
441 			printf("The new value is %d\n",regTblEndColumn);
442 			return SNMP_ERR_NOERROR;
443 	}
444 }
445 
446 
get_regTblStartRow(int search_type,Integer * regTblStartRow,IndexType * index)447 int get_regTblStartRow(int search_type, Integer *regTblStartRow, IndexType *index)
448 {
449 	/* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
450 	/* this function should modify the index argument to the */
451 	/* appropriate value */
452 	switch(search_type)
453 	{
454 		case FIRST_ENTRY:
455 			if(index->type == INTEGER){
456 
457 				/* assume 1 is the first index */
458 
459 				index->value[0] = 1;
460 				index->len = 1;
461 			}else{
462 
463 				/* index type will be array of integer */
464 				/* assume that there are two index */
465 
466 				index->value[0] = 1;
467 				index->value[1]= 1;
468 				index->len = 2;
469 			}
470 			break;
471 
472 		case NEXT_ENTRY:
473 			if(index->type == INTEGER){
474 				index->value[0]++;
475 			}else{
476 
477 				/* index type will be array of integer */
478 				/* assume that there are two index */
479 
480 				index->value[index->len-1]++;
481 			}
482 			break;
483 
484 		case EXACT_ENTRY:
485 			break;
486 	}
487 
488 	/*assume that the mib variable has a value of 1 */
489 
490 	*regTblStartRow = 1;
491 	return SNMP_ERR_NOERROR;
492 }
493 
set_regTblStartRow(int pass,IndexType index,Integer * regTblStartRow)494 int set_regTblStartRow(int pass, IndexType index, Integer *regTblStartRow)
495 {
496 	switch(pass)
497 	{
498 		case FIRST_PASS:
499 
500 			/* check the existence of the element which */
501 			/* corresponding to the given index and */
502 			/* check the validity fo the input value */
503 			/* if not valid or not exist, */
504 
505 			return SNMP_ERR_GENERR;
506 
507 		case SECOND_PASS:
508 
509 			/* change the following coding, such that */
510 			/* the input value will be stored in the */
511 			/* corresponding mib variable of the given */
512 			/* index */
513 			printf("The new value is %d\n",regTblStartRow);
514 			return SNMP_ERR_NOERROR;
515 	}
516 }
517 
518 
get_regTblEndRow(int search_type,Integer * regTblEndRow,IndexType * index)519 int get_regTblEndRow(int search_type, Integer *regTblEndRow, IndexType *index)
520 {
521 	/* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
522 	/* this function should modify the index argument to the */
523 	/* appropriate value */
524 	switch(search_type)
525 	{
526 		case FIRST_ENTRY:
527 			if(index->type == INTEGER){
528 
529 				/* assume 1 is the first index */
530 
531 				index->value[0] = 1;
532 				index->len = 1;
533 			}else{
534 
535 				/* index type will be array of integer */
536 				/* assume that there are two index */
537 
538 				index->value[0] = 1;
539 				index->value[1]= 1;
540 				index->len = 2;
541 			}
542 			break;
543 
544 		case NEXT_ENTRY:
545 			if(index->type == INTEGER){
546 				index->value[0]++;
547 			}else{
548 
549 				/* index type will be array of integer */
550 				/* assume that there are two index */
551 
552 				index->value[index->len-1]++;
553 			}
554 			break;
555 
556 		case EXACT_ENTRY:
557 			break;
558 	}
559 
560 	/*assume that the mib variable has a value of 1 */
561 
562 	*regTblEndRow = 1;
563 	return SNMP_ERR_NOERROR;
564 }
565 
set_regTblEndRow(int pass,IndexType index,Integer * regTblEndRow)566 int set_regTblEndRow(int pass, IndexType index, Integer *regTblEndRow)
567 {
568 	switch(pass)
569 	{
570 		case FIRST_PASS:
571 
572 			/* check the existence of the element which */
573 			/* corresponding to the given index and */
574 			/* check the validity fo the input value */
575 			/* if not valid or not exist, */
576 
577 			return SNMP_ERR_GENERR;
578 
579 		case SECOND_PASS:
580 
581 			/* change the following coding, such that */
582 			/* the input value will be stored in the */
583 			/* corresponding mib variable of the given */
584 			/* index */
585 			printf("The new value is %d\n",regTblEndRow);
586 			return SNMP_ERR_NOERROR;
587 	}
588 }
589 
590 
get_regTblStatus(int search_type,Integer * regTblStatus,IndexType * index)591 int get_regTblStatus(int search_type, Integer *regTblStatus, IndexType *index)
592 {
593 	/* In the case, the search_type is FIRST_ENTRY or NEXT_ENTRY */
594 	/* this function should modify the index argument to the */
595 	/* appropriate value */
596 	switch(search_type)
597 	{
598 		case FIRST_ENTRY:
599 			if(index->type == INTEGER){
600 
601 				/* assume 1 is the first index */
602 
603 				index->value[0] = 1;
604 				index->len = 1;
605 			}else{
606 
607 				/* index type will be array of integer */
608 				/* assume that there are two index */
609 
610 				index->value[0] = 1;
611 				index->value[1]= 1;
612 				index->len = 2;
613 			}
614 			break;
615 
616 		case NEXT_ENTRY:
617 			if(index->type == INTEGER){
618 				index->value[0]++;
619 			}else{
620 
621 				/* index type will be array of integer */
622 				/* assume that there are two index */
623 
624 				index->value[index->len-1]++;
625 			}
626 			break;
627 
628 		case EXACT_ENTRY:
629 			break;
630 	}
631 
632 	/*assume that the mib variable has a value of 1 */
633 
634 	*regTblStatus = 1;
635 	return SNMP_ERR_NOERROR;
636 }
637 
set_regTblStatus(int pass,IndexType index,Integer * regTblStatus)638 int set_regTblStatus(int pass, IndexType index, Integer *regTblStatus)
639 {
640 	switch(pass)
641 	{
642 		case FIRST_PASS:
643 
644 			/* check the existence of the element which */
645 			/* corresponding to the given index and */
646 			/* check the validity fo the input value */
647 			/* if not valid or not exist, */
648 
649 			return SNMP_ERR_GENERR;
650 
651 		case SECOND_PASS:
652 
653 			/* change the following coding, such that */
654 			/* the input value will be stored in the */
655 			/* corresponding mib variable of the given */
656 			/* index */
657 			printf("The new value is %d\n",regTblStatus);
658 			return SNMP_ERR_NOERROR;
659 	}
660 }
661 
662