home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / manage / snmp / cmu-snmp1.0 / snmplib / snmp_auth.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-19  |  3.0 KB  |  110 lines

  1. /*
  2.  * snmp_auth.c -
  3.  *   Authentication for SNMP (RFC 1067).  This implements a null
  4.  * authentication layer.
  5.  *
  6.  *
  7.  */
  8. /***********************************************************
  9.     Copyright 1988, 1989 by Carnegie Mellon University
  10.  
  11.                       All Rights Reserved
  12.  
  13. Permission to use, copy, modify, and distribute this software and its 
  14. documentation for any purpose and without fee is hereby granted, 
  15. provided that the above copyright notice appear in all copies and that
  16. both that copyright notice and this permission notice appear in 
  17. supporting documentation, and that the name of CMU not be
  18. used in advertising or publicity pertaining to distribution of the
  19. software without specific, written prior permission.  
  20.  
  21. CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  22. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  23. CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  24. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  25. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  26. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  27. SOFTWARE.
  28. ******************************************************************/
  29.  
  30. #ifdef KINETICS
  31. #include "gw.h"
  32. #include "fp4/cmdmacro.h"
  33. #endif
  34.  
  35. #if (defined(unix) && !defined(KINETICS))
  36. #include <sys/types.h>
  37. #include <netinet/in.h>
  38. #ifndef NULL
  39. #define NULL 0
  40. #endif
  41. #endif
  42.  
  43. #include "asn1.h"
  44. #include "snmp.h"
  45. #include "snmp_impl.h"
  46.  
  47. u_char *
  48. snmp_auth_parse(data, length, sid, slen, version)
  49.     u_char        *data;
  50.     int            *length;
  51.     u_char        *sid;
  52.     int            *slen;
  53.     long        *version;
  54. {
  55.     u_char    type;
  56.  
  57.     data = asn_parse_header(data, length, &type);
  58.     if (data == NULL){
  59.     ERROR("bad header");
  60.     return NULL;
  61.     }
  62.     if (type != (ASN_SEQUENCE | ASN_CONSTRUCTOR)){
  63.     ERROR("wrong auth header type");
  64.     return NULL;
  65.     }
  66.     data = asn_parse_int(data, length, &type, version, sizeof(*version));
  67.     if (data == NULL){
  68.     ERROR("bad parse of version");
  69.     return NULL;
  70.     }
  71.     data = asn_parse_string(data, length, &type, sid, slen);
  72.     if (data == NULL){
  73.     ERROR("bad parse of community");
  74.     return NULL;
  75.     }
  76.     sid[*slen] = '\0';
  77.     return (u_char *)data;
  78. }
  79.  
  80. u_char *
  81. snmp_auth_build(data, length, sid, slen, version, messagelen)
  82.     u_char        *data;
  83.     int            *length;
  84.     u_char        *sid;
  85.     int            *slen;
  86.     long        *version;
  87.     int            messagelen;
  88. {
  89.     data = asn_build_header(data, length, (u_char)(ASN_SEQUENCE | ASN_CONSTRUCTOR), messagelen + *slen + 5);
  90.     if (data == NULL){
  91.     ERROR("buildheader");
  92.     return NULL;
  93.     }
  94.     data = asn_build_int(data, length,
  95.         (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
  96.         (long *)version, sizeof(*version));
  97.     if (data == NULL){
  98.     ERROR("buildint");
  99.     return NULL;
  100.     }
  101.     data = asn_build_string(data, length,
  102.         (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OCTET_STR), 
  103.         sid, *slen);
  104.     if (data == NULL){
  105.     ERROR("buildstring");
  106.     return NULL;
  107.     }
  108.     return (u_char *)data;
  109. }
  110.