]>
git.ipfire.org Git - thirdparty/squid.git/blob - lib/snmplib/mib.c
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /***********************************************************
10 Copyright 1988, 1989 by Carnegie Mellon University
14 Permission to use, copy, modify, and distribute this software and its
15 documentation for any purpose and without fee is hereby granted,
16 provided that the above copyright notice appear in all copies and that
17 both that copyright notice and this permission notice appear in
18 supporting documentation, and that the name of CMU not be
19 used in advertising or publicity pertaining to distribution of the
20 software without specific, written prior permission.
22 CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
23 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
24 CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
25 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
26 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
27 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
29 ******************************************************************/
40 #include <sys/types.h>
46 #include <gnumalloc.h>
63 #include <sys/socket.h>
66 #include <netinet/in.h>
69 #include <arpa/inet.h>
83 #include "snmp_impl.h"
85 #include "snmp_session.h"
86 #include "snmp_vars.h"
90 static struct snmp_mib_tree
*get_symbol(oid
*objid
, int objidlen
, struct snmp_mib_tree
*subtree
, char *buf
);
92 oid RFC1066_MIB
[] = {1, 3, 6, 1, 2, 1};
93 unsigned char RFC1066_MIB_text
[] = ".iso.org.dod.internet.mgmt.mib";
94 struct snmp_mib_tree
*Mib
;
103 Mib
= read_mib(file
);
106 static struct snmp_mib_tree
*
107 find_rfc1066_mib(struct snmp_mib_tree
*root
) {
108 oid
*op
= RFC1066_MIB
;
109 struct snmp_mib_tree
*tp
;
112 for (len
= sizeof(RFC1066_MIB
) / sizeof(oid
); len
; len
--, op
++) {
113 for (tp
= root
; tp
; tp
= tp
->next_peer
) {
114 if (tp
->subid
== *op
) {
115 root
= tp
->child_list
;
126 lc_cmp(const char *s1
, const char *s2
)
140 return ((c1
- c2
) > 0 ? 1 : -1);
153 parse_subtree(struct snmp_mib_tree
*subtree
, char *input
, oid
*output
, int *out_len
)
155 char buf
[128], *to
= buf
;
157 struct snmp_mib_tree
*tp
;
160 * No empty strings. Can happen if there is a trailing '.' or two '.'s
161 * in a row, i.e. "..".
163 if ((*input
== '\0') ||
167 if (xisdigit(*input
)) {
169 * Read the number, then try to find it in the subtree.
171 while (xisdigit(*input
)) {
173 subid
+= *input
++ - '0';
175 for (tp
= subtree
; tp
; tp
= tp
->next_peer
) {
176 if (tp
->subid
== subid
)
182 * Read the name into a buffer.
184 while ((*input
!= '\0') &&
191 * Find the name in the subtree;
193 for (tp
= subtree
; tp
; tp
= tp
->next_peer
) {
194 if (lc_cmp(tp
->label
, buf
) == 0) {
201 * If we didn't find the entry, punt...
204 snmplib_debug(0, "sub-identifier not found: %s\n", buf
);
210 if (subid
> (u_int
) MAX_SUBID
) {
211 snmplib_debug(0, "sub-identifier too large: %s\n", buf
);
214 if ((*out_len
)-- <= 0) {
215 snmplib_debug(0, "object identifier too long\n");
223 parse_subtree(tp
? tp
->child_list
: NULL
, ++input
, output
, out_len
)) == 0)
229 read_objid(input
, output
, out_len
)
232 int *out_len
; /* number of subid's in "output" */
234 struct snmp_mib_tree
*root
= Mib
;
241 root
= find_rfc1066_mib(root
);
242 for (i
= 0; i
< sizeof(RFC1066_MIB
) / sizeof(oid
); i
++) {
243 if ((*out_len
)-- > 0)
244 *output
++ = RFC1066_MIB
[i
];
246 snmplib_debug(0, "object identifier too long\n");
253 snmplib_debug(0, "Mib not initialized.\n");
256 if ((*out_len
= parse_subtree(root
, input
, output
, out_len
)) == 0)
258 *out_len
+= output
- op
;
264 print_objid(objid
, objidlen
)
266 int objidlen
; /* number of subidentifiers */
269 struct snmp_mib_tree
*subtree
= Mib
;
271 *buf
= '.'; /* this is a fully qualified name */
272 get_symbol(objid
, objidlen
, subtree
, buf
+ 1);
273 snmplib_debug(7, "%s\n", buf
);
278 sprint_objid(buf
, objid
, objidlen
)
281 int objidlen
; /* number of subidentifiers */
283 struct snmp_mib_tree
*subtree
= Mib
;
285 *buf
= '.'; /* this is a fully qualified name */
286 get_symbol(objid
, objidlen
, subtree
, buf
+ 1);
289 static struct snmp_mib_tree
*
290 get_symbol(objid
, objidlen
, subtree
, buf
)
293 struct snmp_mib_tree
*subtree
;
296 struct snmp_mib_tree
*return_tree
= NULL
;
298 for (; subtree
; subtree
= subtree
->next_peer
) {
299 if (*objid
== subtree
->subid
) {
300 strcpy(buf
, subtree
->label
);
305 /* subtree not found */
306 while (objidlen
--) { /* output rest of name, uninterpreted */
307 sprintf(buf
, "%u.", *objid
++);
311 *(buf
- 1) = '\0'; /* remove trailing dot */
320 return_tree
= get_symbol(objid
+ 1, objidlen
- 1, subtree
->child_list
, buf
);
322 if (return_tree
!= NULL
)
329 print_oid_nums(oid
* O
, int len
)
333 for (x
= 0; x
< len
; x
++)