Nut/OS  4.10.3
API Reference
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 
00042 
00054 CONST uint8_t *SnmpAuthParse(CONST uint8_t * data, size_t * length, uint8_t * sidp, size_t * slen, long *version)
00055 {
00056     uint8_t type = ASN_SEQUENCE | ASN_CONSTRUCTOR;
00057 
00058     /* Check header type. */
00059     if ((data = AsnSequenceParse(data, length, type)) == NULL) {
00060         return NULL;
00061     }
00062 
00063     /* Get SNMP version. */
00064     if ((data = AsnIntegerParse(data, length, &type, version)) == NULL) {
00065         return NULL;
00066     }
00067 
00068     /* Get SNMP community. */
00069     if ((data = AsnOctetStringParse(data, length, &type, sidp, slen)) == NULL) {
00070         return NULL;
00071     }
00072     if (*version == SNMP_VERSION_1) {
00073         sidp[*slen] = '\0';
00074     }
00075     return data;
00076 }
00077 
00081 uint8_t *SnmpAuthBuild(SNMP_SESSION * session, uint8_t * data, size_t * length, size_t messagelen)
00082 {
00083     data = AsnSequenceBuild(data, length, ASN_SEQUENCE | ASN_CONSTRUCTOR, messagelen + session->sess_id_len + 5);
00084     if (data == NULL) {
00085         return NULL;
00086     }
00087     data = AsnIntegerBuild(data, length, ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER, (long *) &session->sess_version);
00088     if (data == NULL) {
00089         return NULL;
00090     }
00091     data = AsnOctetStringBuild(data, length, ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OCTET_STR, session->sess_id, session->sess_id_len);
00092     if (data == NULL) {
00093         return NULL;
00094     }
00095     return data;
00096 }
00097