Source code of Windows XP (NT5)
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.

234 lines
4.5 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved
  3. Module Name:
  4. clientob.cpp
  5. Abstract:
  6. This component is the client object the recall filter system contacts
  7. to notify when a recall starts.
  8. Author:
  9. Rohde Wakefield [rohde] 27-May-1997
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #include "fsantfy.h"
  14. static BOOL VerifyPipeName(IN OLECHAR * szPipeName);
  15. HRESULT
  16. CNotifyClient::IdentifyWithServer(
  17. IN OLECHAR * szPipeName
  18. )
  19. /*++
  20. Implements:
  21. IFsaRecallNotifyClient::IdentifyWithServer
  22. --*/
  23. {
  24. TRACEFNHR( "IdentifyWithServer" );
  25. AFX_MANAGE_STATE( AfxGetStaticModuleState( ) );
  26. try {
  27. HANDLE handle = INVALID_HANDLE_VALUE;
  28. //
  29. // Parse the object and verify it looks like an HSM server named pipe
  30. // Note that we cannot assume anything on the string besides it being null-terminated
  31. //
  32. if (! VerifyPipeName(szPipeName)) {
  33. // Wrong name - possible attack - abort
  34. RecThrow(E_INVALIDARG);
  35. }
  36. //
  37. // Open the pipe and send a response
  38. //
  39. handle = CreateFileW( szPipeName, // Pipe name.
  40. GENERIC_WRITE, // Generic access, read/write.
  41. FILE_SHARE_WRITE,
  42. NULL, // No security.
  43. OPEN_EXISTING, // Fail if not existing.
  44. SECURITY_SQOS_PRESENT |
  45. SECURITY_IDENTIFICATION, // No overlap, No pipe impersonation
  46. NULL ); // No template.
  47. RecAffirmHandle( handle );
  48. //
  49. // Verify that what we just opened is a pipe
  50. //
  51. DWORD dwType = GetFileType(handle);
  52. if (dwType != FILE_TYPE_PIPE) {
  53. // Object is not a pipe - close and abort
  54. CloseHandle(handle);
  55. handle = INVALID_HANDLE_VALUE;
  56. RecThrow(E_INVALIDARG);
  57. }
  58. WSB_PIPE_MSG pmsg;
  59. DWORD len, bytesWritten;
  60. pmsg.msgType = WSB_PMSG_IDENTIFY;
  61. len = MAX_COMPUTERNAME_LENGTH + 1;
  62. GetComputerNameW( pmsg.msg.idrp.clientName, &len );
  63. BOOL code = WriteFile( handle, &pmsg, sizeof(WSB_PIPE_MSG),
  64. &bytesWritten, 0 );
  65. CloseHandle(handle);
  66. } RecCatch( hrRet );
  67. return(hrRet);
  68. }
  69. HRESULT
  70. CNotifyClient::OnRecallStarted(
  71. IN IFsaRecallNotifyServer * pRecall
  72. )
  73. /*++
  74. Implements:
  75. IFsaRecallNotifyClient::OnRecallStarted
  76. --*/
  77. {
  78. TRACEFNHR( "OnRecallStarted" );
  79. AFX_MANAGE_STATE( AfxGetStaticModuleState( ) );
  80. hrRet = RecApp->AddRecall( pRecall );
  81. return( hrRet );
  82. }
  83. HRESULT
  84. CNotifyClient::OnRecallFinished(
  85. IN IFsaRecallNotifyServer * pRecall,
  86. IN HRESULT hrError
  87. )
  88. /*++
  89. Implements:
  90. IFsaRecallNotifyClient::OnRecallFinished
  91. --*/
  92. {
  93. TRACEFNHR( "CNotifyClient::OnRecallFinished" );
  94. AFX_MANAGE_STATE( AfxGetStaticModuleState( ) );
  95. hrRet = RecApp->RemoveRecall( pRecall );
  96. return( hrRet );
  97. }
  98. HRESULT
  99. CNotifyClient::FinalConstruct(
  100. void
  101. )
  102. /*++
  103. Implements:
  104. CComObjectRoot::FinalConstruct
  105. --*/
  106. {
  107. TRACEFNHR( "CNotifyClient::FinalConstruct" );
  108. AFX_MANAGE_STATE( AfxGetStaticModuleState( ) );
  109. try {
  110. RecAffirmHr( CComObjectRoot::FinalConstruct( ) );
  111. } RecCatch( hrRet );
  112. return( hrRet );
  113. }
  114. void
  115. CNotifyClient::FinalRelease(
  116. void
  117. )
  118. /*++
  119. Implements:
  120. CComObjectRoot::FinalConstruct
  121. --*/
  122. {
  123. TRACEFN( "CNotifyClient::FinalRelease" );
  124. AFX_MANAGE_STATE( AfxGetStaticModuleState( ) );
  125. CComObjectRoot::FinalRelease( );
  126. }
  127. //
  128. // Verifies that pipe name matches the expected RSS named pipe
  129. // \\<machine-name>\pipe\HSM_PIPE
  130. //
  131. // Returns TRUE for a valid pipe name and FALSE otherwise
  132. //
  133. static BOOL VerifyPipeName(IN OLECHAR * szPipeName)
  134. {
  135. if (wcslen(szPipeName) < 3)
  136. return FALSE;
  137. if ((szPipeName[0] != L'\\') || (szPipeName[1] != L'\\'))
  138. return FALSE;
  139. OLECHAR *pTemp1 = NULL;
  140. OLECHAR *pTemp2 = NULL;
  141. pTemp1 = wcschr(&(szPipeName[2]), L'/');
  142. if (pTemp1 != NULL)
  143. return FALSE;
  144. pTemp1 = wcschr(&(szPipeName[2]), L'\\');
  145. if (pTemp1 == NULL)
  146. return FALSE;
  147. pTemp1++;
  148. pTemp2 = wcschr(pTemp1, L'\\');
  149. if (pTemp2 == NULL)
  150. return FALSE;
  151. *pTemp2 = L'\0';
  152. if (0 != _wcsicmp(pTemp1, L"pipe")) {
  153. *pTemp2 = L'\\';
  154. return FALSE;
  155. }
  156. *pTemp2 = L'\\';
  157. pTemp2++;
  158. if (0 != _wcsicmp(pTemp2, WSB_PIPE_NAME))
  159. return FALSE;
  160. return TRUE;
  161. }