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.

235 lines
5.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: remote.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef __WSREMOTE_H__
  11. #define __WSREMOTE_H__
  12. #include <winsock2.h>
  13. #include <tchar.h>
  14. #define VERSION 7
  15. #define REMOTE_SERVER 1
  16. #define REMOTE_CLIENT 2
  17. #define SERVER_READ_PIPE TEXT("\\\\%s\\PIPE\\%sIN") //Client Writes and Server Reads
  18. #define SERVER_WRITE_PIPE TEXT("\\\\%s\\PIPE\\%sOUT") //Server Reads and Client Writes
  19. #define COMMANDCHAR '@' //Commands intended for remote begins with this
  20. #define CTRLC 3
  21. #define CLIENT_ATTR FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_RED|BACKGROUND_BLUE
  22. #define SERVER_ATTR FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE|BACKGROUND_RED
  23. //
  24. //Some General purpose Macros
  25. //
  26. #define MINIMUM(x,y) ((x)>(y)?(y):(x))
  27. #define MAXIMUM(x,y) ((x)>(y)?(x):(y))
  28. #define ERRORMSSG(str) _tprintf(TEXT("Error %d - %s [%s %d]\n"),GetLastError(),str,__FILE__,__LINE__)
  29. #define SAFECLOSEHANDLE(x) {if (x!=INVALID_HANDLE_VALUE) {CloseHandle(x);x=INVALID_HANDLE_VALUE;}}
  30. // All because printf does not work
  31. // with NT IO redirection
  32. //
  33. #define WRITEF(VArgs) { \
  34. HANDLE xh=GetStdHandle(STD_OUTPUT_HANDLE); \
  35. TCHAR VBuff[256]; \
  36. DWORD tmp; \
  37. _stprintf VArgs; \
  38. WriteFile(xh,VBuff,lstrlen(VBuff),&tmp,NULL); \
  39. } \
  40. #define HOSTNAMELEN 16
  41. #define CHARS_PER_LINE 45
  42. #define MAGICNUMBER 0x31109000
  43. #define BEGINMARK '\xfe'
  44. #define ENDMARK '\xff'
  45. #define LINESTOSEND 200
  46. #define MAX_SESSION 10
  47. typedef struct
  48. {
  49. DWORD Size;
  50. DWORD Version;
  51. TCHAR ClientName[15];
  52. DWORD LinesToSend;
  53. DWORD Flag;
  54. } SESSION_STARTUPINFO;
  55. typedef struct
  56. {
  57. DWORD MagicNumber; //New Remote
  58. DWORD Size; //Size of structure
  59. DWORD FileSize; //Num bytes sent
  60. } SESSION_STARTREPLY;
  61. typedef struct
  62. {
  63. TCHAR Name[HOSTNAMELEN]; //Name of client Machine;
  64. BOOL Active; //Client at the other end connected
  65. BOOL CommandRcvd; //True if a command recieved
  66. BOOL SendOutput; //True if Sendoutput output
  67. HANDLE PipeReadH; //Client sends its StdIn through this
  68. HANDLE PipeWriteH; //Client gets its StdOut through this
  69. HANDLE rSaveFile; //Sessions read handle to SaveFile
  70. HANDLE hThread; //Session Thread
  71. HANDLE MoreData; //Event handle set if data available to be read
  72. SOCKET Socket; //Socket for IP Session
  73. TCHAR szIP[16]; //IP Address of Client, if NOT IP then NULL
  74. } SESSION_TYPE;
  75. VOID
  76. Server(
  77. TCHAR* ChildCmd,
  78. TCHAR* PipeName
  79. );
  80. VOID
  81. Client(
  82. TCHAR* ServerName,
  83. TCHAR* PipeName
  84. );
  85. VOID
  86. SockClient(
  87. TCHAR* ServerName,
  88. TCHAR* PipeName
  89. );
  90. VOID
  91. ErrorExit(
  92. TCHAR* str
  93. );
  94. VOID
  95. DisplayClientHlp(
  96. );
  97. VOID
  98. DisplayServerHlp(
  99. );
  100. ULONG
  101. DbgPrint(
  102. PCH Format,
  103. ...
  104. );
  105. DWORD
  106. ReadFixBytes(
  107. HANDLE hRead,
  108. TCHAR *Buffer,
  109. DWORD ToRead,
  110. DWORD TimeOut //ignore for timebeing
  111. );
  112. DWORD
  113. SockReadFixBytes(
  114. SOCKET hSocket,
  115. TCHAR *Buffer,
  116. DWORD ToRead,
  117. DWORD TimeOut //ignore for timebeing
  118. );
  119. VOID
  120. Errormsg(
  121. TCHAR* str
  122. );
  123. BOOL ReadSocket(
  124. SOCKET s,
  125. TCHAR * buff,
  126. int len,
  127. DWORD* dread);
  128. BOOL WriteSocket(
  129. SOCKET s,
  130. TCHAR * buff,
  131. int len,
  132. DWORD* dsent);
  133. VOID
  134. Base64Encode(
  135. TCHAR * String,
  136. DWORD StringLength,
  137. TCHAR * EncodeBuffer);
  138. VOID
  139. Base64Decode(
  140. TCHAR * String,
  141. TCHAR * DecodeBuffer);
  142. int
  143. GetBase64Index(
  144. TCHAR A);
  145. VOID
  146. SplitUserName(
  147. TCHAR * FullName,
  148. TCHAR * Domain,
  149. TCHAR * UserName);
  150. #ifdef UNICODE
  151. BOOL WriteSocketA(
  152. SOCKET s,
  153. char * pszAnsiStr,
  154. int len,
  155. DWORD * dsent);
  156. // caller must free buffer
  157. WCHAR * inet_ntoaw(
  158. struct in_addr stInet );
  159. BOOL ReadFileW(
  160. HANDLE hFile, // handle of file to read
  161. WCHAR * pszBuffer, // pointer to buffer that receives data
  162. DWORD dwLength, // number of bytes to read
  163. LPDWORD pdwRead, // pointer to number of bytes read
  164. LPOVERLAPPED pData // pointer to structure for data
  165. );
  166. BOOL WriteFileW(
  167. HANDLE hFile, // handle to file to write to
  168. WCHAR * pszBuffer, // pointer to data to write to file
  169. DWORD dwWrite, // number of bytes to write
  170. LPDWORD pdwWritten, // pointer to number of bytes written
  171. LPOVERLAPPED pData // pointer to structure for overlapped I/O
  172. );
  173. BOOL GetAnsiStr(
  174. WCHAR * pszWideStr,
  175. char * pszAnsiStr,
  176. UINT uBufSize
  177. );
  178. #endif UNICODE
  179. extern TCHAR HostName[HOSTNAMELEN];
  180. extern TCHAR* ChildCmd;
  181. extern TCHAR* PipeName;
  182. extern TCHAR* ServerName;
  183. extern TCHAR* Username;
  184. extern TCHAR* Password;
  185. extern HANDLE MyOutHandle;
  186. extern DWORD LinesToSend;
  187. extern BOOL IsAdvertise;
  188. extern BOOL bIPLocked;
  189. extern DWORD ClientToServerFlag;
  190. #endif //__WSREMOTE_H__