]>
git.ipfire.org Git - thirdparty/squid.git/blob - 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
36 #include <sys/types.h>
42 #include <gnumalloc.h>
59 #include <sys/socket.h>
62 #include <netinet/in.h>
65 #include <arpa/inet.h>
78 #include "snmp_vars.h"
79 #include "snmp_session.h"
80 #include "snmp_impl.h"
86 static struct snmp_mib_tree
*get_symbol(oid
*objid
, int objidlen
, struct snmp_mib_tree
*subtree
, char *buf
);
88 oid RFC1066_MIB
[] = {1, 3, 6, 1, 2, 1};
89 unsigned char RFC1066_MIB_text
[] = ".iso.org.dod.internet.mgmt.mib";
90 struct snmp_mib_tree
*Mib
;
103 static struct snmp_mib_tree
*
104 find_rfc1066_mib(struct snmp_mib_tree
*root
) {
105 oid
*op
= RFC1066_MIB
;
106 struct snmp_mib_tree
*tp
;
109 for (len
= sizeof(RFC1066_MIB
) / sizeof(oid
); len
; len
--, op
++) {
110 for (tp
= root
; tp
; tp
= tp
->next_peer
) {
111 if (tp
->subid
== *op
) {
112 root
= tp
->child_list
;
123 lc_cmp(const char *s1
, const char *s2
)
137 return ((c1
- c2
) > 0 ? 1 : -1);
150 parse_subtree(struct snmp_mib_tree
*subtree
, char *input
, oid
*output
, int *out_len
)
152 char buf
[128], *to
= buf
;
154 struct snmp_mib_tree
*tp
;
157 * No empty strings. Can happen if there is a trailing '.' or two '.'s
158 * in a row, i.e. "..".
160 if ((*input
== '\0') ||
164 if (xisdigit(*input
)) {
166 * Read the number, then try to find it in the subtree.
168 while (xisdigit(*input
)) {
170 subid
+= *input
++ - '0';
172 for (tp
= subtree
; tp
; tp
= tp
->next_peer
) {
173 if (tp
->subid
== subid
)
179 * Read the name into a buffer.
181 while ((*input
!= '\0') &&
188 * Find the name in the subtree;
190 for (tp
= subtree
; tp
; tp
= tp
->next_peer
) {
191 if (lc_cmp(tp
->label
, buf
) == 0) {
198 * If we didn't find the entry, punt...
201 snmplib_debug(0, "sub-identifier not found: %s\n", buf
);
207 if (subid
> (u_int
) MAX_SUBID
) {
208 snmplib_debug(0, "sub-identifier too large: %s\n", buf
);
211 if ((*out_len
)-- <= 0) {
212 snmplib_debug(0, "object identifier too long\n");
220 parse_subtree(tp
? tp
->child_list
: NULL
, ++input
, output
, out_len
)) == 0)
226 read_objid(input
, output
, out_len
)
229 int *out_len
; /* number of subid's in "output" */
231 struct snmp_mib_tree
*root
= Mib
;
238 root
= find_rfc1066_mib(root
);
239 for (i
= 0; i
< sizeof(RFC1066_MIB
) / sizeof(oid
); i
++) {
240 if ((*out_len
)-- > 0)
241 *output
++ = RFC1066_MIB
[i
];
243 snmplib_debug(0, "object identifier too long\n");
250 snmplib_debug(0, "Mib not initialized.\n");
253 if ((*out_len
= parse_subtree(root
, input
, output
, out_len
)) == 0)
255 *out_len
+= output
- op
;
261 print_objid(objid
, objidlen
)
263 int objidlen
; /* number of subidentifiers */
266 struct snmp_mib_tree
*subtree
= Mib
;
268 *buf
= '.'; /* this is a fully qualified name */
269 get_symbol(objid
, objidlen
, subtree
, buf
+ 1);
270 snmplib_debug(7, "%s\n", buf
);
275 sprint_objid(buf
, objid
, objidlen
)
278 int objidlen
; /* number of subidentifiers */
280 struct snmp_mib_tree
*subtree
= Mib
;
282 *buf
= '.'; /* this is a fully qualified name */
283 get_symbol(objid
, objidlen
, subtree
, buf
+ 1);
286 static struct snmp_mib_tree
*
287 get_symbol(objid
, objidlen
, subtree
, buf
)
290 struct snmp_mib_tree
*subtree
;
293 struct snmp_mib_tree
*return_tree
= NULL
;
295 for (; subtree
; subtree
= subtree
->next_peer
) {
296 if (*objid
== subtree
->subid
) {
297 strcpy(buf
, subtree
->label
);
302 /* subtree not found */
303 while (objidlen
--) { /* output rest of name, uninterpreted */
304 sprintf(buf
, "%u.", *objid
++);
308 *(buf
- 1) = '\0'; /* remove trailing dot */
317 return_tree
= get_symbol(objid
+ 1, objidlen
- 1, subtree
->child_list
, buf
);
319 if (return_tree
!= NULL
)
326 print_oid_nums(oid
* O
, int len
)
330 for (x
= 0; x
< len
; x
++)