WorkstationService.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright (C) 2014-2017 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 NotImplementedException();
  43. }
  44. }
  45. public NetrWkstaGetInfoResponse GetNetrWkstaGetInfoResponse(NetrWkstaGetInfoRequest request)
  46. {
  47. NetrWkstaGetInfoResponse response = new NetrWkstaGetInfoResponse();
  48. if (request.Level == 100)
  49. {
  50. WorkstationInfo100 info = new WorkstationInfo100();
  51. info.PlatformID = m_platformID;
  52. info.ComputerName.Value = m_computerName;
  53. info.LanGroup.Value = m_lanGroup;
  54. info.VerMajor = m_verMajor;
  55. info.VerMinor = m_verMinor;
  56. response.WkstaInfo = new WorkstationInfo(info);
  57. }
  58. else if (request.Level == 101)
  59. {
  60. WorkstationInfo101 info = new WorkstationInfo101();
  61. info.PlatformID = m_platformID;
  62. info.ComputerName.Value = m_computerName;
  63. info.LanGroup.Value = m_lanGroup;
  64. info.VerMajor = m_verMajor;
  65. info.VerMinor = m_verMinor;
  66. info.LanRoot.Value = m_lanGroup;
  67. response.WkstaInfo = new WorkstationInfo(info);
  68. }
  69. else
  70. {
  71. throw new NotImplementedException();
  72. }
  73. response.Result = Win32Error.ERROR_SUCCESS;
  74. return response;
  75. }
  76. public override Guid InterfaceGuid
  77. {
  78. get
  79. {
  80. return ServiceInterfaceGuid;
  81. }
  82. }
  83. public override string PipeName
  84. {
  85. get
  86. {
  87. return ServicePipeName;
  88. }
  89. }
  90. }
  91. }