Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.6 KiB

  1. //***************************************************************************
  2. //
  3. // File:
  4. //
  5. // Module: MS SNMP Provider
  6. //
  7. // Purpose:
  8. //
  9. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. /*---------------------------------------------------------
  13. Filename: sec.cpp
  14. Written By: B.Rajeev
  15. ----------------------------------------------------------*/
  16. #include "precomp.h"
  17. #include "common.h"
  18. #include "encdec.h"
  19. #include "vblist.h"
  20. #include "sec.h"
  21. #include "pdu.h"
  22. #include "value.h"
  23. const char *SnmpCommunityBasedSecurity::GetCommunityName() const
  24. {
  25. return community_name;
  26. }
  27. void SnmpCommunityBasedSecurity::Initialize()
  28. {
  29. is_valid = TRUE;
  30. }
  31. SnmpCommunityBasedSecurity::SnmpCommunityBasedSecurity(IN const SnmpCommunityBasedSecurity &security) : community_name ( NULL )
  32. {
  33. const char *new_community_name = security.GetCommunityName();
  34. community_name = new char[strlen(new_community_name)+1];
  35. strcpy(community_name, new_community_name);
  36. Initialize();
  37. }
  38. SnmpCommunityBasedSecurity::SnmpCommunityBasedSecurity(IN const char *communityName) : community_name ( NULL)
  39. {
  40. community_name = new char[strlen(communityName)+1];
  41. strcpy(community_name, communityName);
  42. Initialize();
  43. }
  44. SnmpCommunityBasedSecurity::SnmpCommunityBasedSecurity(IN const SnmpOctetString &octetString) : community_name ( NULL )
  45. {
  46. int length = octetString.GetValueLength();
  47. community_name = new char[length+1];
  48. strncpy(community_name, (char *)octetString.GetValue(), length);
  49. community_name[length] = EOS;
  50. Initialize();
  51. }
  52. SnmpCommunityBasedSecurity::~SnmpCommunityBasedSecurity()
  53. {
  54. delete [] community_name;
  55. }
  56. SnmpErrorReport SnmpCommunityBasedSecurity::Secure (
  57. IN SnmpEncodeDecode &a_SnmpEncodeDecode,
  58. IN OUT SnmpPdu &snmpPdu
  59. )
  60. {
  61. SnmpCommunityBasedSecurity *t_Community = (SnmpCommunityBasedSecurity *)(this->Copy());
  62. if ( a_SnmpEncodeDecode.SetCommunityName (snmpPdu, *t_Community) == FALSE )
  63. return SnmpErrorReport(Snmp_Transport, Snmp_Local_Error);
  64. else
  65. return SnmpErrorReport(Snmp_Success, Snmp_No_Error);
  66. }
  67. SnmpSecurity *SnmpCommunityBasedSecurity::Copy() const
  68. {
  69. return new SnmpCommunityBasedSecurity(community_name);
  70. }
  71. void SnmpCommunityBasedSecurity::SetCommunityName ( IN const SnmpOctetString &a_OctetString )
  72. {
  73. delete [] community_name ;
  74. community_name = NULL;
  75. community_name = new char [ a_OctetString.GetValueLength () + 1 ] ;
  76. strncpy ( community_name , ( char * ) a_OctetString.GetValue () , a_OctetString.GetValueLength () ) ;
  77. community_name [ a_OctetString.GetValueLength () ] = 0 ;
  78. }
  79. void SnmpCommunityBasedSecurity:: SetCommunityName ( IN const char *a_CommunityName )
  80. {
  81. delete [] community_name ;
  82. community_name = NULL;
  83. community_name = new char [ strlen ( a_CommunityName ) + 1 ] ;
  84. strcpy ( community_name , a_CommunityName ) ;
  85. }
  86. void SnmpCommunityBasedSecurity:: GetCommunityName ( SnmpOctetString &a_SnmpOctetString ) const
  87. {
  88. a_SnmpOctetString.SetValue ( ( UCHAR * ) community_name , strlen ( community_name ) ) ;
  89. }
  90. SnmpCommunityBasedSecurity &SnmpCommunityBasedSecurity :: operator=(IN const SnmpCommunityBasedSecurity &to_copy)
  91. {
  92. delete [] community_name ;
  93. community_name = NULL;
  94. community_name = new char [ strlen ( to_copy.community_name ) + 1 ] ;
  95. strcpy ( community_name , to_copy.community_name ) ;
  96. return *this ;
  97. }