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.

255 lines
5.9 KiB

  1. #include <windows.h>
  2. #include "protocol.h"
  3. #include "tclient.h"
  4. #include "gdata.h"
  5. typedef PROTOCOLAPI LPCSTR (SMCAPI *PFNSCCHECK)(void *, LPCSTR, LPCWSTR);
  6. LPCSTR
  7. _SCConsConnect(
  8. LPCWSTR lpszServerName,
  9. LPCWSTR lpszUserName,
  10. LPCWSTR lpszPassword,
  11. LPCWSTR lpszDomain,
  12. IN const int xRes,
  13. IN const int yRes,
  14. PCONNECTINFO pCI
  15. )
  16. {
  17. LPCSTR rv = NULL;
  18. PFNSCCONNECT pfnConnect = NULL;
  19. pCI->hConsoleExtension = LoadLibraryA(g_strConsoleExtension);
  20. if ( NULL == pCI->hConsoleExtension )
  21. {
  22. TRACE((ERROR_MESSAGE, "Can't load library %s. GetLastError=%d\n",
  23. g_strConsoleExtension, GetLastError()));
  24. rv = ERR_CANTLOADLIB;
  25. goto exitpt;
  26. }
  27. pfnConnect = (PFNSCCONNECT)
  28. GetProcAddress( (HMODULE) pCI->hConsoleExtension, "SCConnect" );
  29. if ( NULL == pfnConnect )
  30. {
  31. TRACE((ERROR_MESSAGE, "Can't get SCConnect. GetLastError=%d\n",
  32. GetLastError()));
  33. rv = ERR_CANTGETPROCADDRESS;
  34. goto exitpt;
  35. }
  36. rv = pfnConnect(
  37. lpszServerName,
  38. lpszUserName,
  39. lpszPassword,
  40. lpszDomain,
  41. xRes, yRes,
  42. &(pCI->pCIConsole)
  43. );
  44. exitpt:
  45. return rv;
  46. }
  47. LPCSTR
  48. _SCConsDisconnect(
  49. PCONNECTINFO pCI
  50. )
  51. {
  52. LPCSTR rv = NULL;
  53. PFNSCDISCONNECT pfnDisconnect = NULL;
  54. if ( NULL == pCI->hConsoleExtension )
  55. {
  56. rv= ERR_CANTLOADLIB;
  57. goto exitpt;
  58. }
  59. pfnDisconnect = (PFNSCDISCONNECT)
  60. GetProcAddress( (HMODULE) pCI->hConsoleExtension, "SCDisconnect" );
  61. if ( NULL == pfnDisconnect )
  62. {
  63. TRACE((ERROR_MESSAGE, "Can't load SCDisconnect, GetLastError=%d\n",
  64. GetLastError()));
  65. rv = ERR_CANTGETPROCADDRESS;
  66. goto exitpt;
  67. }
  68. rv = pfnDisconnect( pCI->pCIConsole );
  69. //
  70. // the trick here is the console will be unloaded after
  71. // several clock ticks, so we need to replace the error with
  72. // generic one
  73. //
  74. if ( NULL != rv )
  75. {
  76. TRACE((ERROR_MESSAGE, "Error in console dll (replacing): %s\n", rv ));
  77. rv = ERR_CONSOLE_GENERIC;
  78. }
  79. exitpt:
  80. return rv;
  81. }
  82. LPCSTR
  83. _SCConsLogoff(
  84. PCONNECTINFO pCI
  85. )
  86. {
  87. LPCSTR rv = NULL;
  88. PFNSCLOGOFF pfnLogoff = NULL;
  89. if ( NULL == pCI->hConsoleExtension )
  90. {
  91. rv= ERR_CANTLOADLIB;
  92. goto exitpt;
  93. }
  94. pfnLogoff = (PFNSCLOGOFF)
  95. GetProcAddress( (HMODULE) pCI->hConsoleExtension, "SCLogoff" );
  96. if ( NULL == pfnLogoff )
  97. {
  98. TRACE((ERROR_MESSAGE, "Can't load SCLogoff, GetLastError=%d\n",
  99. GetLastError()));
  100. rv = ERR_CANTGETPROCADDRESS;
  101. goto exitpt;
  102. }
  103. rv = pfnLogoff( pCI->pCIConsole );
  104. //
  105. // the trick here is the console will be unloaded after
  106. // several clock ticks, so we need to replace the error with
  107. // generic one
  108. //
  109. if ( NULL != rv )
  110. {
  111. TRACE((ERROR_MESSAGE, "Error in console dll (replacing): %s\n", rv ));
  112. rv = ERR_CONSOLE_GENERIC;
  113. }
  114. exitpt:
  115. return rv;
  116. }
  117. LPCSTR
  118. _SCConsStart(
  119. PCONNECTINFO pCI,
  120. LPCWSTR lpszAppName
  121. )
  122. {
  123. LPCSTR rv = NULL;
  124. PFNSCSTART pfnStart = NULL;
  125. if ( NULL == pCI->hConsoleExtension )
  126. {
  127. rv= ERR_CANTLOADLIB;
  128. goto exitpt;
  129. }
  130. pfnStart = (PFNSCSTART)
  131. GetProcAddress( (HMODULE) pCI->hConsoleExtension, "SCStart" );
  132. if ( NULL == pfnStart )
  133. {
  134. TRACE((ERROR_MESSAGE, "Can't load SCStart, GetLastError=%d\n",
  135. GetLastError()));
  136. rv = ERR_CANTGETPROCADDRESS;
  137. goto exitpt;
  138. }
  139. rv = pfnStart( pCI->pCIConsole, lpszAppName );
  140. exitpt:
  141. return rv;
  142. }
  143. LPCSTR
  144. _SCConsClipboard(
  145. PCONNECTINFO pCI,
  146. const CLIPBOARDOPS eClipOp,
  147. LPCSTR lpszFileName
  148. )
  149. {
  150. LPCSTR rv = NULL;
  151. PFNSCCLIPBOARD pfnClipboard = NULL;
  152. if ( NULL == pCI->hConsoleExtension )
  153. {
  154. rv= ERR_CANTLOADLIB;
  155. goto exitpt;
  156. }
  157. pfnClipboard = (PFNSCCLIPBOARD)
  158. GetProcAddress( (HMODULE) pCI->hConsoleExtension, "SCClipboard" );
  159. if ( NULL == pfnClipboard )
  160. {
  161. TRACE((ERROR_MESSAGE, "Can't load SCClipboard, GetLastError=%d\n",
  162. GetLastError()));
  163. rv = ERR_CANTGETPROCADDRESS;
  164. goto exitpt;
  165. }
  166. rv = pfnClipboard( pCI->pCIConsole, eClipOp, lpszFileName );
  167. exitpt:
  168. return rv;
  169. }
  170. LPCSTR
  171. _SCConsSenddata(
  172. PCONNECTINFO pCI,
  173. const UINT uiMessage,
  174. const WPARAM wParam,
  175. const LPARAM lParam
  176. )
  177. {
  178. LPCSTR rv = NULL;
  179. PFNSCSENDDATA pfnSenddata = NULL;
  180. if ( NULL == pCI->hConsoleExtension )
  181. {
  182. rv= ERR_CANTLOADLIB;
  183. goto exitpt;
  184. }
  185. pfnSenddata = (PFNSCSENDDATA)
  186. GetProcAddress( (HMODULE) pCI->hConsoleExtension, "SCSenddata" );
  187. if ( NULL == pfnSenddata )
  188. {
  189. TRACE((ERROR_MESSAGE, "Can't load SCSenddata, GetLastError=%d\n",
  190. GetLastError()));
  191. rv = ERR_CANTGETPROCADDRESS;
  192. goto exitpt;
  193. }
  194. rv = pfnSenddata( pCI->pCIConsole, uiMessage, wParam, lParam );
  195. exitpt:
  196. return rv;
  197. }
  198. LPCSTR
  199. _SCConsCheck(
  200. PCONNECTINFO pCI,
  201. LPCSTR lpszCommand,
  202. LPCWSTR lpszParam
  203. )
  204. {
  205. LPCSTR rv = NULL;
  206. PFNSCCHECK pfnCheck = NULL;
  207. if ( NULL == pCI->hConsoleExtension )
  208. {
  209. rv= ERR_CANTLOADLIB;
  210. goto exitpt;
  211. }
  212. pfnCheck = (PFNSCCHECK)
  213. GetProcAddress( (HMODULE) pCI->hConsoleExtension, "SCCheck" );
  214. if ( NULL == pfnCheck )
  215. {
  216. TRACE((ERROR_MESSAGE, "Can't load SCCheck, GetLastError=%d\n",
  217. GetLastError()));
  218. rv = ERR_CANTGETPROCADDRESS;
  219. goto exitpt;
  220. }
  221. rv = pfnCheck( pCI->pCIConsole, lpszCommand, lpszParam );
  222. exitpt:
  223. return rv;
  224. }