X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/c0781576e11dc6df0813823c1fc109f81a39a088..f72fe0d0de6eb91663b005b7d061ecebb555d667:/print-snmp.c diff --git a/print-snmp.c b/print-snmp.c index 8f8b856d..a82cbf92 100644 --- a/print-snmp.c +++ b/print-snmp.c @@ -1,16 +1,29 @@ /* * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997 - * The Regents of the University of California. All rights reserved. + * John Robert LoVerso. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by John Robert LoVerso. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * This implementation has been influenced by the CMU SNMP release, * by Steve Waldbusser. However, this shares no code with that system. @@ -45,7 +58,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.46 2001-03-17 04:41:50 itojun Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.52 2002-05-07 18:27:40 fenner Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -428,16 +441,11 @@ asn1_parse(register const u_char *p, u_int len, struct be *elem) elem->form = form; elem->class = class; elem->id = id; - if (vflag > 1) - printf("|%.2x", *p); p++; len--; hdr = 1; /* extended tag field */ if (id == ASN_ID_EXT) { - for (id = 0; *p & ASN_BIT8 && len > 0; len--, hdr++, p++) { - if (vflag > 1) - printf("|%.2x", *p); + for (id = 0; *p & ASN_BIT8 && len > 0; len--, hdr++, p++) id = (id << 7) | (*p & ~ASN_BIT8); - } if (len == 0 && *p & ASN_BIT8) { ifNotTruncated fputs("[Xtagfield?]", stdout); return -1; @@ -452,8 +460,6 @@ asn1_parse(register const u_char *p, u_int len, struct be *elem) return -1; } elem->asnlen = *p; - if (vflag > 1) - printf("|%.2x", *p); p++; len--; hdr++; if (elem->asnlen & ASN_BIT8) { int noct = elem->asnlen % ASN_BIT8; @@ -462,11 +468,8 @@ asn1_parse(register const u_char *p, u_int len, struct be *elem) ifNotTruncated printf("[asnlen? %d<%d]", len, noct); return -1; } - for (; noct-- > 0; len--, hdr++) { - if (vflag > 1) - printf("|%.2x", *p); + for (; noct-- > 0; len--, hdr++) elem->asnlen = (elem->asnlen << ASN_SHIFT8) | *p++; - } } if (len < elem->asnlen) { if (!truncated) { @@ -685,13 +688,17 @@ asn1_print(struct be *elem) /* * first subitem encodes two items with 1st*OIDMUX+2nd + * (see X.690:1997 clause 8.19 for the details) */ if (first < 0) { + int s; if (!nflag) objp = mibroot; first = 0; - OBJ_PRINT(o/OIDMUX, first); - o %= OIDMUX; + s = o / OIDMUX; + if (s > 2) s = 2; + OBJ_PRINT(s, first); + o -= s * OIDMUX; } OBJ_PRINT(o, first); if (--first < 0) @@ -859,7 +866,7 @@ static struct smi2be smi2betab[] = { }; static void smi_decode_oid(struct be *elem, unsigned int *oid, - unsigned int *oidlen) + unsigned int oidsize, unsigned int *oidlen) { u_char *p = (u_char *)elem->data.raw; u_int32_t asnlen = elem->asnlen; @@ -872,13 +879,20 @@ static void smi_decode_oid(struct be *elem, unsigned int *oid, /* * first subitem encodes two items with 1st*OIDMUX+2nd + * (see X.690:1997 clause 8.19 for the details) */ if (first < 0) { first = 0; - oid[(*oidlen)++] = o/OIDMUX; - o %= OIDMUX; + if (*oidlen < oidsize) { + oid[*oidlen] = o / OIDMUX; + if (oid[*oidlen] > 2) oid[*oidlen] = 2; + } + o -= oid[*oidlen] * OIDMUX; + if (*oidlen < oidsize) (*oidlen)++; + } + if (*oidlen < oidsize) { + oid[(*oidlen)++] = o; } - oid[(*oidlen)++] = o; o = 0; } } @@ -975,7 +989,7 @@ static SmiNode *smi_print_variable(struct be *elem) SmiNode *smiNode = NULL; int i; - smi_decode_oid(elem, oid, &oidlen); + smi_decode_oid(elem, oid, sizeof(oid)/sizeof(unsigned int), &oidlen); smiNode = smiGetNodeByOID(oidlen, oid); if (! smiNode) { asn1_print(elem); @@ -1042,7 +1056,7 @@ static void smi_print_value(SmiNode *smiNode, u_char pduid, struct be *elem) } if (! smi_check_range(smiType, elem)) { - fputs("[wrongLength]", stdout); + fputs("[outOfRange]", stdout); } /* resolve bits to named bits */ @@ -1058,7 +1072,9 @@ static void smi_print_value(SmiNode *smiNode, u_char pduid, struct be *elem) if (smiType->basetype == SMI_BASETYPE_BITS) { /* print bit labels */ } else { - smi_decode_oid(elem, oid, &oidlen); + smi_decode_oid(elem, oid, + sizeof(oid)/sizeof(unsigned int), + &oidlen); smiNode = smiGetNodeByOID(oidlen, oid); if (smiNode) { if (vflag) { @@ -1446,7 +1462,7 @@ pdu_print(const u_char *np, u_int length, int version) } if (vflag) { - fputs("} ", stdout); + fputs(" } ", stdout); } }