WorkstationService.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* Copyright (C) 2014-2018 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. namespace SMBLibrary.Services
  11. {
  12. /// <summary>
  13. /// [MS-WKST]
  14. /// </summary>
  15. public class WorkstationService : RemoteService
  16. {
  17. public const string ServicePipeName = @"wkssvc";
  18. public static readonly Guid ServiceInterfaceGuid = new Guid("6BFFD098-A112-3610-9833-46C3F87E345A");
  19. public const int ServiceVersion = 1;
  20. private uint m_platformID;
  21. private string m_computerName;
  22. private string m_lanGroup;
  23. private uint m_verMajor;
  24. private uint m_verMinor;
  25. public WorkstationService(string computerName, string lanGroup)
  26. {
  27. m_platformID = (uint)PlatformName.NT;
  28. m_computerName = computerName;
  29. m_lanGroup = lanGroup;
  30. m_verMajor = 5;
  31. m_verMinor = 2;
  32. }
  33. public override byte[] GetResponseBytes(ushort opNum, byte[] requestBytes)
  34. {
  35. switch ((WorkstationServiceOpName)opNum)
  36. {
  37. case WorkstationServiceOpName.NetrWkstaGetInfo:
  38. NetrWkstaGetInfoRequest request = new NetrWkstaGetInfoRequest(requestBytes);
  39. NetrWkstaGetInfoResponse response = GetNetrWkstaGetInfoResponse(request);
  40. return response.GetBytes();
  41. default:
  42. throw new UnsupportedOpNumException();
  43. }
  44. }
  45. public NetrWkstaGetInfoResponse GetNetrWkstaGetInfoResponse(NetrWkstaGetInfoRequest request)
  46. {
  47. NetrWkstaGetInfoResponse response = new NetrWkstaGetInfoResponse();
  48. switch (request.Level)
  49. {
  50. case 100:
  51. {
  52. WorkstationInfo100 info = new WorkstationInfo100();
  53. info.PlatformID = m_platformID;
  54. info.ComputerName.Value = m_computerName;
  55. info.LanGroup.Value = m_lanGroup;
  56. info.VerMajor = m_verMajor;
  57. info.VerMinor = m_verMinor;
  58. response.WkstaInfo = new WorkstationInfo(info);
  59. response.Result = Win32Error.ERROR_SUCCESS;
  60. return response;
  61. }
  62. case 101:
  63. {
  64. WorkstationInfo101 info = new WorkstationInfo101();
  65. info.PlatformID = m_platformID;
  66. info.ComputerName.Value = m_computerName;
  67. info.LanGroup.Value = m_lanGroup;
  68. info.VerMajor = m_verMajor;
  69. info.VerMinor = m_verMinor;
  70. info.LanRoot.Value = m_lanGroup;
  71. response.WkstaInfo = new WorkstationInfo(info);
  72. response.Result = Win32Error.ERROR_SUCCESS;
  73. return response;
  74. }
  75. case 102:
  76. case 502:
  77. {
  78. response.WkstaInfo = new WorkstationInfo(request.Level);
  79. response.Result = Win32Error.ERROR_NOT_SUPPORTED;
  80. return response;
  81. }
  82. default:
  83. {
  84. response.WkstaInfo = new WorkstationInfo(request.Level);
  85. response.Result = Win32Error.ERROR_INVALID_LEVEL;
  86. return response;
  87. }
  88. }
  89. }
  90. public override Guid InterfaceGuid
  91. {
  92. get
  93. {
  94. return ServiceInterfaceGuid;
  95. }
  96. }
  97. public override string PipeName
  98. {
  99. get
  100. {
  101. return ServicePipeName;
  102. }
  103. }
  104. }
  105. }