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.

150 lines
3.3 KiB

  1. /******************************************************************************\
  2. * This is a part of the Microsoft Source Code Samples.
  3. * Copyright 1995 - 1997 Microsoft Corporation.
  4. * All rights reserved.
  5. * This source code is only intended as a supplement to
  6. * Microsoft Development Tools and/or WinHelp documentation.
  7. * See these sources for detailed information regarding the
  8. * Microsoft samples programs.
  9. \******************************************************************************/
  10. /*++
  11. Copyright (c) 1997 Microsoft Corporation
  12. Module Name:
  13. SrvCtoS.c
  14. Abstract:
  15. This file implements the client-to-server flow
  16. of data for remote server. The data is the keyboard
  17. or piped input that the client received and sent
  18. over the wire to us, bracketed by BEGINMARK and ENDMARK
  19. bytes so we can display nice attribution comments in
  20. brackets next to input lines.
  21. Author:
  22. Dave Hart 30 May 1997
  23. Environment:
  24. Console App. User mode.
  25. Revision History:
  26. --*/
  27. #include <precomp.h>
  28. #include "Remote.h"
  29. #include "Server.h"
  30. VOID
  31. FASTCALL
  32. StartReadClientInput(
  33. PREMOTE_CLIENT pClient
  34. )
  35. {
  36. //
  37. // Start read of data from this client's stdin.
  38. //
  39. if ( ! ReadFileEx(
  40. pClient->PipeReadH,
  41. pClient->ReadBuffer,
  42. BUFFSIZE - 1, // allow for null term
  43. &pClient->ReadOverlapped,
  44. ReadClientInputCompleted
  45. )) {
  46. CloseClient(pClient);
  47. }
  48. }
  49. VOID
  50. WINAPI
  51. ReadClientInputCompleted(
  52. DWORD dwError,
  53. DWORD cbRead,
  54. LPOVERLAPPED lpO
  55. )
  56. {
  57. PREMOTE_CLIENT pClient;
  58. pClient = CONTAINING_RECORD(lpO, REMOTE_CLIENT, ReadOverlapped);
  59. if (HandleSessionError(pClient, dwError) ||
  60. !cbRead) {
  61. return;
  62. }
  63. pClient->ReadBuffer[cbRead] = 0;
  64. if (FilterCommand(pClient, pClient->ReadBuffer, cbRead)) {
  65. //
  66. // Local command, don't pass it to child app, just
  67. // start another client read.
  68. //
  69. if ( ! ReadFileEx(
  70. pClient->PipeReadH,
  71. pClient->ReadBuffer,
  72. BUFFSIZE - 1, // allow for null term
  73. &pClient->ReadOverlapped,
  74. ReadClientInputCompleted
  75. )) {
  76. CloseClient(pClient);
  77. }
  78. } else {
  79. //
  80. // Write buffer to child stdin.
  81. //
  82. if ( ! WriteFileEx(
  83. hWriteChildStdIn,
  84. pClient->ReadBuffer,
  85. cbRead,
  86. &pClient->ReadOverlapped,
  87. WriteChildStdInCompleted
  88. )) {
  89. // Child is going away. Let this client's chain of IO stop.
  90. }
  91. }
  92. }
  93. VOID
  94. WINAPI
  95. WriteChildStdInCompleted(
  96. DWORD dwError,
  97. DWORD cbWritten,
  98. LPOVERLAPPED lpO
  99. )
  100. {
  101. PREMOTE_CLIENT pClient;
  102. pClient = CONTAINING_RECORD(lpO, REMOTE_CLIENT, ReadOverlapped);
  103. if (HandleSessionError(pClient, dwError)) {
  104. return;
  105. }
  106. //
  107. // Start another read against the client input.
  108. //
  109. StartReadClientInput(pClient);
  110. }