snmp_auth.c

Go to the documentation of this file.
00001 /*
00002  * Copyright 1998-2007 by egnite Software GmbH
00003  * Copyright 1988, 1989, 1991, 1992 by Carnegie Mellon University
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. Neither the name of the copyright holders nor the names of
00015  *    contributors may be used to endorse or promote products derived
00016  *    from this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00021  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00022  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00023  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00024  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00025  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00026  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00027  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00028  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00029  * SUCH DAMAGE.
00030  *
00031  * For additional information see http://www.ethernut.de/
00032  */
00033 
00034 #include <pro/snmp.h>
00035 #include <pro/snmp_agent.h>
00036 #include <pro/snmp_auth.h>
00037 
00049 CONST uint8_t *SnmpAuthParse(CONST uint8_t * data, size_t * length, uint8_t * sidp, size_t * slen, long *version)
00050 {
00051     uint8_t type = ASN_SEQUENCE | ASN_CONSTRUCTOR;
00052 
00053     /* Check header type. */
00054     if ((data = AsnSequenceParse(data, length, type)) == NULL) {
00055         return NULL;
00056     }
00057 
00058     /* Get SNMP version. */
00059     if ((data = AsnIntegerParse(data, length, &type, version)) == NULL) {
00060         return NULL;
00061     }
00062 
00063     /* Get SNMP community. */
00064     if ((data = AsnOctetStringParse(data, length, &type, sidp, slen)) == NULL) {
00065         return NULL;
00066     }
00067     if (*version == SNMP_VERSION_1) {
00068         sidp[*slen] = '\0';
00069     }
00070     return data;
00071 }
00072 
00076 uint8_t *SnmpAuthBuild(SNMP_SESSION * session, uint8_t * data, size_t * length, size_t messagelen)
00077 {
00078     data = AsnSequenceBuild(data, length, ASN_SEQUENCE | ASN_CONSTRUCTOR, messagelen + session->sess_id_len + 5);
00079     if (data == NULL) {
00080         return NULL;
00081     }
00082     data = AsnIntegerBuild(data, length, ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER, (long *) &session->sess_version);
00083     if (data == NULL) {
00084         return NULL;
00085     }
00086     data = AsnOctetStringBuild(data, length, ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OCTET_STR, session->sess_id, session->sess_id_len);
00087     if (data == NULL) {
00088         return NULL;
00089     }
00090     return data;
00091 }

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/