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.

98 lines
2.1 KiB

  1. //=============================================================================
  2. //
  3. // MODULE: ASN1ABuffer.cxx
  4. //
  5. // Description:
  6. //
  7. // Implementation of ASN.1 address buffer parsing logic
  8. //
  9. // Modification History
  10. //
  11. // Mark Pustilnik Date: 06/08/02 - created
  12. //
  13. //=============================================================================
  14. #include "ASN1Parser.hxx"
  15. #include <stdio.h>
  16. DWORD
  17. ASN1ParserAddressBuffer::ParseBlob(
  18. IN OUT ASN1VALUE * Value
  19. )
  20. {
  21. DWORD dw = ERROR_SUCCESS;
  22. ASN1VALUE * Modifier = QueryModifier();
  23. if ( Modifier == NULL )
  24. {
  25. return ERROR_INTERNAL_ERROR;
  26. }
  27. if ( Modifier->ut != utInteger )
  28. {
  29. return ERROR_INTERNAL_ERROR;
  30. }
  31. switch ( Modifier->dw )
  32. {
  33. case KERB_ADDRTYPE_NETBIOS:
  34. //
  35. // Nothing special, just make it obvious this is not a binary blob
  36. // but a real string we're dealing with
  37. //
  38. Value->ut = utGeneralString;
  39. break;
  40. case KERB_ADDRTYPE_INET:
  41. {
  42. if ( Value->string.l >= 4 )
  43. {
  44. ULPBYTE IPv4 = new BYTE[sizeof("255.255.255.255")];
  45. if ( IPv4 == NULL )
  46. {
  47. dw = ERROR_NOT_ENOUGH_MEMORY;
  48. break;
  49. }
  50. _snprintf(
  51. (char *)IPv4,
  52. sizeof("255.255.255.255"),
  53. "%d.%d.%d.%d",
  54. (DWORD)Value->string.s[0],
  55. (DWORD)Value->string.s[1],
  56. (DWORD)Value->string.s[2],
  57. (DWORD)Value->string.s[3]
  58. );
  59. if ( Value->Allocated )
  60. {
  61. delete [] Value->string.s;
  62. }
  63. Value->ut = utGeneralString;
  64. Value->Allocated = TRUE;
  65. Value->string.s = IPv4;
  66. Value->string.l = strlen((const char *)IPv4);
  67. }
  68. break;
  69. }
  70. //
  71. // TODO: add parsers for more address types (x25, IPv6, etc.)
  72. //
  73. default:
  74. //
  75. // Leave as is
  76. //
  77. break;
  78. }
  79. return dw;
  80. }