summaryrefslogtreecommitdiffstats
path: root/contrib/bsnmp/lib
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2004-01-23 10:44:47 +0000
committerharti <harti@FreeBSD.org>2004-01-23 10:44:47 +0000
commit37f8604ae2d6123aca70878041cfad4e857aae0a (patch)
tree064e02524b69deb956e22716b5e049d1e4c9f066 /contrib/bsnmp/lib
parentca3ba04f7363860ece02c8042bffc3db8c209dfb (diff)
downloadFreeBSD-src-37f8604ae2d6123aca70878041cfad4e857aae0a.zip
FreeBSD-src-37f8604ae2d6123aca70878041cfad4e857aae0a.tar.gz
Virgin import of bsnmpd 1.5a
Diffstat (limited to 'contrib/bsnmp/lib')
-rw-r--r--contrib/bsnmp/lib/asn1.32
-rw-r--r--contrib/bsnmp/lib/asn1.c14
-rw-r--r--contrib/bsnmp/lib/asn1.h2
-rw-r--r--contrib/bsnmp/lib/bsnmpagent.32
-rw-r--r--contrib/bsnmp/lib/bsnmpclient.322
-rw-r--r--contrib/bsnmp/lib/bsnmplib.32
-rw-r--r--contrib/bsnmp/lib/snmp.c60
-rw-r--r--contrib/bsnmp/lib/snmp.h4
-rw-r--r--contrib/bsnmp/lib/snmpagent.c2
-rw-r--r--contrib/bsnmp/lib/snmpagent.h2
-rw-r--r--contrib/bsnmp/lib/snmpclient.c30
-rw-r--r--contrib/bsnmp/lib/snmpclient.h10
-rw-r--r--contrib/bsnmp/lib/snmppriv.h2
13 files changed, 126 insertions, 28 deletions
diff --git a/contrib/bsnmp/lib/asn1.3 b/contrib/bsnmp/lib/asn1.3
index 3751e50..ec01b9a 100644
--- a/contrib/bsnmp/lib/asn1.3
+++ b/contrib/bsnmp/lib/asn1.3
@@ -30,7 +30,7 @@
.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $Begemot: bsnmp/lib/asn1.3,v 1.2 2002/08/16 10:02:53 hbb Exp $
+.\" $Begemot: bsnmp/lib/asn1.3,v 1.3 2003/12/02 15:45:48 hbb Exp $
.\"
.Dd August 15, 2002
.Dt asn1 3
diff --git a/contrib/bsnmp/lib/asn1.c b/contrib/bsnmp/lib/asn1.c
index 533b9dd..75d5300 100644
--- a/contrib/bsnmp/lib/asn1.c
+++ b/contrib/bsnmp/lib/asn1.c
@@ -30,7 +30,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Begemot: bsnmp/lib/asn1.c,v 1.24 2003/01/28 13:44:34 hbb Exp $
+ * $Begemot: bsnmp/lib/asn1.c,v 1.27 2003/12/08 17:11:58 hbb Exp $
*
* ASN.1 for SNMP.
*/
@@ -244,6 +244,13 @@ asn_get_real_integer(struct asn_buf *b, asn_len_t len, int64_t *vp)
err = ASN_ERR_OK;
if (len > 8)
err = ASN_ERR_RANGE;
+ else if (len > 1 &&
+ ((*b->asn_cptr == 0x00 && (b->asn_cptr[1] & 0x80) == 0) ||
+ (*b->asn_cptr == 0xff && (b->asn_cptr[1] & 0x80) == 0x80))) {
+ asn_error(b, "non-minimal integer");
+ err = ASN_ERR_BADLEN;
+ }
+
if (*b->asn_cptr & 0x80)
neg = 1;
val = 0;
@@ -332,6 +339,10 @@ asn_get_real_unsigned(struct asn_buf *b, asn_len_t len, u_int64_t *vp)
/* negative integer or too larger */
*vp = 0xffffffffffffffffULL;
err = ASN_ERR_RANGE;
+ } else if (len > 1 &&
+ *b->asn_cptr == 0x00 && (b->asn_cptr[1] & 0x80) == 0) {
+ asn_error(b, "non-minimal unsigned");
+ err = ASN_ERR_BADLEN;
}
while (len--) {
@@ -718,7 +729,6 @@ asn_get_sequence(struct asn_buf *b, asn_len_t *len)
return (ASN_ERR_OK);
}
-
/*
* Application types
*
diff --git a/contrib/bsnmp/lib/asn1.h b/contrib/bsnmp/lib/asn1.h
index 83a31e5..0c21fe4 100644
--- a/contrib/bsnmp/lib/asn1.h
+++ b/contrib/bsnmp/lib/asn1.h
@@ -30,7 +30,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Begemot: bsnmp/lib/asn1.h,v 1.16 2002/02/11 10:19:57 hbb Exp $
+ * $Begemot: bsnmp/lib/asn1.h,v 1.17 2003/12/02 15:52:37 hbb Exp $
*
* ASN.1 for SNMP
*/
diff --git a/contrib/bsnmp/lib/bsnmpagent.3 b/contrib/bsnmp/lib/bsnmpagent.3
index a9a8104..ad2f628 100644
--- a/contrib/bsnmp/lib/bsnmpagent.3
+++ b/contrib/bsnmp/lib/bsnmpagent.3
@@ -30,7 +30,7 @@
.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $Begemot: bsnmp/lib/bsnmpagent.3,v 1.1 2002/08/16 12:22:58 hbb Exp $
+.\" $Begemot: bsnmp/lib/bsnmpagent.3,v 1.2 2003/12/02 16:13:45 hbb Exp $
.\"
.Dd August 16, 2002
.Dt bsnmpagent 3
diff --git a/contrib/bsnmp/lib/bsnmpclient.3 b/contrib/bsnmp/lib/bsnmpclient.3
index f4a7eac..a4996c4 100644
--- a/contrib/bsnmp/lib/bsnmpclient.3
+++ b/contrib/bsnmp/lib/bsnmpclient.3
@@ -30,7 +30,7 @@
.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $Begemot: bsnmp/lib/bsnmpclient.3,v 1.3 2002/12/11 15:54:07 hbb Exp $
+.\" $Begemot: bsnmp/lib/bsnmpclient.3,v 1.5 2003/12/08 17:11:58 hbb Exp $
.\"
.Dd August 15, 2002
.Dt bsnmpclient 3
@@ -107,7 +107,7 @@ that use SNMP versions 1 or 2. Most of the routines use a
.Bd -literal -offset indent
struct snmp_client {
enum snmp_version version;
- int local; /* use local socket */
+ int trans; /* transport type to use */
/* these two are read-only for the application */
char *cport; /* port number as string */
@@ -147,13 +147,19 @@ This is the version of SNMP to use. See
.Xr bsnmplib 3
for applicable values. The default version is
.Li SNMP_V2c .
-.It Va local
-If this is set to true, the library opens a
-.Ux
-domain socket rather than
-an UDP socket. It uses the
+.It Va trans
+If this is
+.Dv SNMP_TRANS_LOC_DGRAM
+a local datagram socket is used.
+If it is
+.Dv SNMP_TRANS_LOC_STREAM
+a local stream socket is used.
+For
+.Dv SNMP_TRANS_UDP
+a UDP socket is created.
+It uses the
.Va chost
-field as the path to the server's socket.
+field as the path to the server's socket for local sockets.
.It Va cport
The SNMP agent's UDP port number. This may be a symbolic port number (from
.Pa /etc/services
diff --git a/contrib/bsnmp/lib/bsnmplib.3 b/contrib/bsnmp/lib/bsnmplib.3
index 13f9651..8f7fcb4 100644
--- a/contrib/bsnmp/lib/bsnmplib.3
+++ b/contrib/bsnmp/lib/bsnmplib.3
@@ -30,7 +30,7 @@
.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $Begemot: bsnmp/lib/bsnmplib.3,v 1.2 2002/08/16 10:02:53 hbb Exp $
+.\" $Begemot: bsnmp/lib/bsnmplib.3,v 1.3 2003/12/02 16:14:28 hbb Exp $
.\"
.Dd August 15, 2002
.Dt bsnmplib 3
diff --git a/contrib/bsnmp/lib/snmp.c b/contrib/bsnmp/lib/snmp.c
index 786bf8c..3369dd3 100644
--- a/contrib/bsnmp/lib/snmp.c
+++ b/contrib/bsnmp/lib/snmp.c
@@ -30,7 +30,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Begemot: bsnmp/lib/snmp.c,v 1.34 2003/01/28 13:44:34 hbb Exp $
+ * $Begemot: bsnmp/lib/snmp.c,v 1.37 2003/12/08 17:11:58 hbb Exp $
*
* SNMP
*/
@@ -432,6 +432,64 @@ snmp_pdu_decode(struct asn_buf *b, struct snmp_pdu *pdu, int32_t *ip)
}
/*
+ * Check whether what we have is the complete PDU by snooping at the
+ * enclosing structure header. This returns:
+ * -1 if there are ASN.1 errors
+ * 0 if we need more data
+ * > 0 the length of this PDU
+ */
+int
+snmp_pdu_snoop(const struct asn_buf *b0)
+{
+ u_int length;
+ asn_len_t len;
+ struct asn_buf b = *b0;
+
+ /* <0x10|0x20> <len> <data...> */
+
+ if (b.asn_len == 0)
+ return (0);
+ if (b.asn_cptr[0] != (ASN_TYPE_SEQUENCE | ASN_TYPE_CONSTRUCTED)) {
+ asn_error(&b, "bad sequence type %u", b.asn_cptr[0]);
+ return (-1);
+ }
+ b.asn_len--;
+ b.asn_cptr++;
+
+ if (b.asn_len == 0)
+ return (0);
+
+ if (*b.asn_cptr & 0x80) {
+ /* long length */
+ length = *b.asn_cptr++ & 0x7f;
+ b.asn_len--;
+ if (length == 0) {
+ asn_error(&b, "indefinite length not supported");
+ return (-1);
+ }
+ if (length > ASN_MAXLENLEN) {
+ asn_error(&b, "long length too long (%u)", length);
+ return (-1);
+ }
+ if (length > b.asn_len)
+ return (0);
+ len = 0;
+ while (length--) {
+ len = (len << 8) | *b.asn_cptr++;
+ b.asn_len--;
+ }
+ } else {
+ len = *b.asn_cptr++;
+ b.asn_len--;
+ }
+
+ if (len > b.asn_len)
+ return (0);
+
+ return (len + b.asn_cptr - b0->asn_cptr);
+}
+
+/*
* Encode the SNMP PDU without the variable bindings field.
* We do this the rather uneffective way by
* moving things around and assuming that the length field will never
diff --git a/contrib/bsnmp/lib/snmp.h b/contrib/bsnmp/lib/snmp.h
index 30b1e2c..86a36e7 100644
--- a/contrib/bsnmp/lib/snmp.h
+++ b/contrib/bsnmp/lib/snmp.h
@@ -30,7 +30,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Begemot: bsnmp/lib/snmp.h,v 1.27 2002/03/08 14:24:58 hbb Exp $
+ * $Begemot: bsnmp/lib/snmp.h,v 1.29 2003/12/08 17:11:58 hbb Exp $
*
* Header file for SNMP functions.
*/
@@ -164,6 +164,8 @@ void snmp_pdu_free(struct snmp_pdu *);
enum snmp_code snmp_pdu_decode(struct asn_buf *b, struct snmp_pdu *pdu, int32_t *);
enum snmp_code snmp_pdu_encode(struct snmp_pdu *pdu, struct asn_buf *resp_b);
+int snmp_pdu_snoop(const struct asn_buf *);
+
void snmp_pdu_dump(const struct snmp_pdu *pdu);
extern void (*snmp_error)(const char *, ...);
diff --git a/contrib/bsnmp/lib/snmpagent.c b/contrib/bsnmp/lib/snmpagent.c
index 19ac661..c03b606 100644
--- a/contrib/bsnmp/lib/snmpagent.c
+++ b/contrib/bsnmp/lib/snmpagent.c
@@ -30,7 +30,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Begemot: bsnmp/lib/snmpagent.c,v 1.14 2003/01/30 11:23:00 hbb Exp $
+ * $Begemot: bsnmp/lib/snmpagent.c,v 1.16 2003/12/03 09:55:58 hbb Exp $
*
* SNMP Agent functions
*/
diff --git a/contrib/bsnmp/lib/snmpagent.h b/contrib/bsnmp/lib/snmpagent.h
index a854138..cd89456 100644
--- a/contrib/bsnmp/lib/snmpagent.h
+++ b/contrib/bsnmp/lib/snmpagent.h
@@ -30,7 +30,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Begemot: bsnmp/lib/snmpagent.h,v 1.9 2002/03/08 14:24:58 hbb Exp $
+ * $Begemot: bsnmp/lib/snmpagent.h,v 1.10 2003/12/03 09:55:58 hbb Exp $
*
* Header file for SNMP functions. This requires snmp.h to be included.
*/
diff --git a/contrib/bsnmp/lib/snmpclient.c b/contrib/bsnmp/lib/snmpclient.c
index e1206b0..ce3b2c0 100644
--- a/contrib/bsnmp/lib/snmpclient.c
+++ b/contrib/bsnmp/lib/snmpclient.c
@@ -31,7 +31,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Begemot: bsnmp/lib/snmpclient.c,v 1.24 2003/01/28 13:44:34 hbb Exp $
+ * $Begemot: bsnmp/lib/snmpclient.c,v 1.27 2003/12/08 17:11:58 hbb Exp $
*
* Support functions for SNMP clients.
*/
@@ -826,7 +826,7 @@ snmp_client_init(struct snmp_client *c)
memset(c, 0, sizeof(*c));
c->version = SNMP_V2c;
- c->local = 0;
+ c->trans = SNMP_TRANS_UDP;
c->chost = NULL;
c->cport = NULL;
@@ -941,6 +941,7 @@ open_client_local(const char *path)
{
struct sockaddr_un sa;
char *ptr;
+ int stype;
if (snmp_client.chost == NULL) {
if ((snmp_client.chost = malloc(1 + sizeof(DEFAULT_LOCAL)))
@@ -960,7 +961,12 @@ open_client_local(const char *path)
strcpy(snmp_client.chost, path);
}
- if ((snmp_client.fd = socket(PF_LOCAL, SOCK_DGRAM, 0)) == -1) {
+ if (snmp_client.trans == SNMP_TRANS_LOC_DGRAM)
+ stype = SOCK_DGRAM;
+ else
+ stype = SOCK_STREAM;
+
+ if ((snmp_client.fd = socket(PF_LOCAL, stype, 0)) == -1) {
seterr("%s", strerror(errno));
return (-1);
}
@@ -1028,12 +1034,22 @@ snmp_open(const char *host, const char *port, const char *readcomm,
strlcpy(snmp_client.write_community, writecomm,
sizeof(snmp_client.write_community));
- if (!snmp_client.local) {
+ switch (snmp_client.trans) {
+
+ case SNMP_TRANS_UDP:
if (open_client_udp(host, port))
return (-1);
- } else {
+ break;
+
+ case SNMP_TRANS_LOC_DGRAM:
+ case SNMP_TRANS_LOC_STREAM:
if (open_client_local(host))
return (-1);
+ break;
+
+ default:
+ seterr("bad transport mapping");
+ return (-1);
}
tout.tv_sec = 0;
tout.tv_usec = 0;
@@ -1042,7 +1058,7 @@ snmp_open(const char *host, const char *port, const char *readcomm,
seterr("%s", strerror(errno));
(void)close(snmp_client.fd);
snmp_client.fd = -1;
- if (snmp_client.local)
+ if (snmp_client.local_path[0] != '\0')
(void)remove(snmp_client.local_path);
return (-1);
}
@@ -1075,7 +1091,7 @@ snmp_close(void)
if (snmp_client.fd != -1) {
(void)close(snmp_client.fd);
snmp_client.fd = -1;
- if (snmp_client.local)
+ if (snmp_client.local_path[0] != '\0')
(void)remove(snmp_client.local_path);
}
while(!LIST_EMPTY(&sent_pdus)){
diff --git a/contrib/bsnmp/lib/snmpclient.h b/contrib/bsnmp/lib/snmpclient.h
index 700d020..80acb14 100644
--- a/contrib/bsnmp/lib/snmpclient.h
+++ b/contrib/bsnmp/lib/snmpclient.h
@@ -31,7 +31,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Begemot: bsnmp/lib/snmpclient.h,v 1.15 2002/12/11 15:54:07 hbb Exp $
+ * $Begemot: bsnmp/lib/snmpclient.h,v 1.17 2003/12/08 17:11:58 hbb Exp $
*/
#ifndef _BSNMP_SNMPCLIENT_H
#define _BSNMP_SNMPCLIENT_H
@@ -47,6 +47,12 @@
#define SNMP_LOCAL_PATH "/tmp/snmpXXXXXXXXXXXXXX"
+/*
+ * transport methods
+ */
+#define SNMP_TRANS_UDP 0
+#define SNMP_TRANS_LOC_DGRAM 1
+#define SNMP_TRANS_LOC_STREAM 2
/* type of callback function for responses
* this callback function is responsible for free() any memory associated with
@@ -68,7 +74,7 @@ typedef void (*snmp_timeout_stop_f)(void *timeout_id);
*/
struct snmp_client {
enum snmp_version version;
- int local; /* use local socket */
+ int trans; /* which transport to use */
/* these two are read-only for the application */
char *cport; /* port number as string */
diff --git a/contrib/bsnmp/lib/snmppriv.h b/contrib/bsnmp/lib/snmppriv.h
index 82189f0..9fb66aa 100644
--- a/contrib/bsnmp/lib/snmppriv.h
+++ b/contrib/bsnmp/lib/snmppriv.h
@@ -30,7 +30,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Begemot: bsnmp/lib/snmppriv.h,v 1.7 2002/12/11 15:54:07 hbb Exp $
+ * $Begemot: bsnmp/lib/snmppriv.h,v 1.8 2003/12/03 09:55:58 hbb Exp $
*
* Private functions.
*/
OpenPOWER on IntegriCloud