]>
git.ipfire.org Git - thirdparty/squid.git/blob - lib/snmplib/mib.c
2 /***********************************************************
3 Copyright 1988, 1989 by Carnegie Mellon University
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the name of CMU not be
12 used in advertising or publicity pertaining to distribution of the
13 software without specific, written prior permission.
15 CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
16 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
17 CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
18 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
20 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
22 ******************************************************************/
24 #define SQUID_NO_STRING_BUFFER_PROTECT 1
34 #include <sys/types.h>
40 #include <gnumalloc.h>
57 #include <sys/socket.h>
60 #include <netinet/in.h>
63 #include <arpa/inet.h>
77 #include "snmp_impl.h"
79 #include "snmp_session.h"
80 #include "snmp_vars.h"
84 static struct snmp_mib_tree
*get_symbol(oid
*objid
, int objidlen
, struct snmp_mib_tree
*subtree
, char *buf
);
86 oid RFC1066_MIB
[] = {1, 3, 6, 1, 2, 1};
87 unsigned char RFC1066_MIB_text
[] = ".iso.org.dod.internet.mgmt.mib";
88 struct snmp_mib_tree
*Mib
;
100 static struct snmp_mib_tree
*
101 find_rfc1066_mib(struct snmp_mib_tree
*root
) {
102 oid
*op
= RFC1066_MIB
;
103 struct snmp_mib_tree
*tp
;
106 for (len
= sizeof(RFC1066_MIB
) / sizeof(oid
); len
; len
--, op
++) {
107 for (tp
= root
; tp
; tp
= tp
->next_peer
) {
108 if (tp
->subid
== *op
) {
109 root
= tp
->child_list
;
120 lc_cmp(const char *s1
, const char *s2
)
134 return ((c1
- c2
) > 0 ? 1 : -1);
147 parse_subtree(struct snmp_mib_tree
*subtree
, char *input
, oid
*output
, int *out_len
)
149 char buf
[128], *to
= buf
;
151 struct snmp_mib_tree
*tp
;
154 * No empty strings. Can happen if there is a trailing '.' or two '.'s
155 * in a row, i.e. "..".
157 if ((*input
== '\0') ||
161 if (xisdigit(*input
)) {
163 * Read the number, then try to find it in the subtree.
165 while (xisdigit(*input
)) {
167 subid
+= *input
++ - '0';
169 for (tp
= subtree
; tp
; tp
= tp
->next_peer
) {
170 if (tp
->subid
== subid
)
176 * Read the name into a buffer.
178 while ((*input
!= '\0') &&
185 * Find the name in the subtree;
187 for (tp
= subtree
; tp
; tp
= tp
->next_peer
) {
188 if (lc_cmp(tp
->label
, buf
) == 0) {
195 * If we didn't find the entry, punt...
198 snmplib_debug(0, "sub-identifier not found: %s\n", buf
);
204 if (subid
> (u_int
) MAX_SUBID
) {
205 snmplib_debug(0, "sub-identifier too large: %s\n", buf
);
208 if ((*out_len
)-- <= 0) {
209 snmplib_debug(0, "object identifier too long\n");
217 parse_subtree(tp
? tp
->child_list
: NULL
, ++input
, output
, out_len
)) == 0)
223 read_objid(input
, output
, out_len
)
226 int *out_len
; /* number of subid's in "output" */
228 struct snmp_mib_tree
*root
= Mib
;
235 root
= find_rfc1066_mib(root
);
236 for (i
= 0; i
< sizeof(RFC1066_MIB
) / sizeof(oid
); i
++) {
237 if ((*out_len
)-- > 0)
238 *output
++ = RFC1066_MIB
[i
];
240 snmplib_debug(0, "object identifier too long\n");
247 snmplib_debug(0, "Mib not initialized.\n");
250 if ((*out_len
= parse_subtree(root
, input
, output
, out_len
)) == 0)
252 *out_len
+= output
- op
;
258 print_objid(objid
, objidlen
)
260 int objidlen
; /* number of subidentifiers */
263 struct snmp_mib_tree
*subtree
= Mib
;
265 *buf
= '.'; /* this is a fully qualified name */
266 get_symbol(objid
, objidlen
, subtree
, buf
+ 1);
267 snmplib_debug(7, "%s\n", buf
);
272 sprint_objid(buf
, objid
, objidlen
)
275 int objidlen
; /* number of subidentifiers */
277 struct snmp_mib_tree
*subtree
= Mib
;
279 *buf
= '.'; /* this is a fully qualified name */
280 get_symbol(objid
, objidlen
, subtree
, buf
+ 1);
283 static struct snmp_mib_tree
*
284 get_symbol(objid
, objidlen
, subtree
, buf
)
287 struct snmp_mib_tree
*subtree
;
290 struct snmp_mib_tree
*return_tree
= NULL
;
292 for (; subtree
; subtree
= subtree
->next_peer
) {
293 if (*objid
== subtree
->subid
) {
294 strcpy(buf
, subtree
->label
);
299 /* subtree not found */
300 while (objidlen
--) { /* output rest of name, uninterpreted */
301 sprintf(buf
, "%u.", *objid
++);
305 *(buf
- 1) = '\0'; /* remove trailing dot */
314 return_tree
= get_symbol(objid
+ 1, objidlen
- 1, subtree
->child_list
, buf
);
316 if (return_tree
!= NULL
)
323 print_oid_nums(oid
* O
, int len
)
327 for (x
= 0; x
< len
; x
++)