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.

459 lines
10 KiB

  1. /*++
  2. Copyright (c) 1990-2003 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. xcv.c
  6. Abstract:
  7. Implements xcv functions.
  8. // @@BEGIN_DDKSPLIT
  9. Author:
  10. Environment:
  11. User Mode -Win32
  12. Revision History:
  13. // @@END_DDKSPLIT
  14. --*/
  15. #include "precomp.h"
  16. #pragma hdrstop
  17. //
  18. // The ddk montior samples will be build with the name ddklocalmon and ddklocalui
  19. // so they can be installed without clashing with existing files
  20. //
  21. // @@BEGIN_DDKSPLIT
  22. #if 0
  23. // @@END_DDKSPLIT
  24. //
  25. // change this to the name of the dll that provides the ui for the monitor
  26. //
  27. #define SZLOCALUI L"DDKLocalUI.dll"
  28. // @@BEGIN_DDKSPLIT
  29. #endif
  30. #define SZLOCALUI L"LocalUI.dll"
  31. // @@END_DDKSPLIT
  32. DWORD
  33. GetMonitorUI(
  34. PBYTE pInputData,
  35. DWORD cbInputData,
  36. PBYTE pOutputData,
  37. DWORD cbOutputData,
  38. PDWORD pcbOutputNeeded,
  39. PINIXCVPORT pIniXcv
  40. );
  41. DWORD
  42. DoPortExists(
  43. PBYTE pInputData,
  44. DWORD cbInputData,
  45. PBYTE pOutputData,
  46. DWORD cbOutputData,
  47. PDWORD pcbOutputNeeded,
  48. PINIXCVPORT pIniXcv
  49. );
  50. DWORD
  51. DoPortIsValid(
  52. PBYTE pInputData,
  53. DWORD cbInputData,
  54. PBYTE pOutputData,
  55. DWORD cbOutputData,
  56. PDWORD pcbOutputNeeded,
  57. PINIXCVPORT pIniXcv
  58. );
  59. DWORD
  60. DoDeletePort(
  61. PBYTE pInputData,
  62. DWORD cbInputData,
  63. PBYTE pOutputData,
  64. DWORD cbOutputData,
  65. PDWORD pcbOutputNeeded,
  66. PINIXCVPORT pIniXcv
  67. );
  68. DWORD
  69. DoAddPort(
  70. PBYTE pInputData,
  71. DWORD cbInputData,
  72. PBYTE pOutputData,
  73. DWORD cbOutputData,
  74. PDWORD pcbOutputNeeded,
  75. PINIXCVPORT pIniXcv
  76. );
  77. DWORD
  78. DoSetDefaultCommConfig(
  79. PBYTE pInputData,
  80. DWORD cbInputData,
  81. PBYTE pOutputData,
  82. DWORD cbOutputData,
  83. PDWORD pcbOutputNeeded,
  84. PINIXCVPORT pIniXcv
  85. );
  86. DWORD
  87. DoGetDefaultCommConfig(
  88. PBYTE pInputData,
  89. DWORD cbInputData,
  90. PBYTE pOutputData,
  91. DWORD cbOutputData,
  92. PDWORD pcbOutputNeeded,
  93. PINIXCVPORT pIniXcv
  94. );
  95. DWORD
  96. GetTransmissionRetryTimeout(
  97. PBYTE pInputData,
  98. DWORD cbInputData,
  99. PBYTE pOutputData,
  100. DWORD cbOutputData,
  101. PDWORD pcbOutputNeeded,
  102. PINIXCVPORT pIniXcv
  103. );
  104. typedef struct {
  105. PWSTR pszMethod;
  106. DWORD (*pfn)( PBYTE pInputData,
  107. DWORD cbInputData,
  108. PBYTE pOutputData,
  109. DWORD cbOutputData,
  110. PDWORD pcbOutputNeeded,
  111. PINIXCVPORT pIniXcv
  112. );
  113. } XCV_METHOD, *PXCV_METHOD;
  114. XCV_METHOD gpLcmXcvMethod[] = {
  115. {L"MonitorUI", GetMonitorUI},
  116. {L"ConfigureLPTPortCommandOK", ConfigureLPTPortCommandOK},
  117. {L"AddPort", DoAddPort},
  118. {L"DeletePort", DoDeletePort},
  119. {L"PortExists", DoPortExists},
  120. {L"PortIsValid", DoPortIsValid},
  121. {L"GetTransmissionRetryTimeout", GetTransmissionRetryTimeout},
  122. {L"SetDefaultCommConfig", DoSetDefaultCommConfig},
  123. {L"GetDefaultCommConfig", DoGetDefaultCommConfig},
  124. {NULL, NULL}
  125. };
  126. DWORD
  127. LcmXcvDataPort(
  128. HANDLE hXcv,
  129. LPCWSTR pszDataName,
  130. PBYTE pInputData,
  131. DWORD cbInputData,
  132. PBYTE pOutputData,
  133. DWORD cbOutputData,
  134. PDWORD pcbOutputNeeded
  135. )
  136. {
  137. DWORD dwRet;
  138. DWORD i;
  139. for(i = 0 ; gpLcmXcvMethod[i].pszMethod &&
  140. wcscmp(gpLcmXcvMethod[i].pszMethod, pszDataName) ; ++i)
  141. ;
  142. if (gpLcmXcvMethod[i].pszMethod) {
  143. dwRet = (*gpLcmXcvMethod[i].pfn)( pInputData,
  144. cbInputData,
  145. pOutputData,
  146. cbOutputData,
  147. pcbOutputNeeded,
  148. (PINIXCVPORT) hXcv);
  149. } else {
  150. dwRet = ERROR_INVALID_PARAMETER;
  151. }
  152. return dwRet;
  153. }
  154. BOOL
  155. LcmXcvOpenPort(
  156. HANDLE hMonitor,
  157. LPCWSTR pszObject,
  158. ACCESS_MASK GrantedAccess,
  159. PHANDLE phXcv
  160. )
  161. {
  162. PINILOCALMON pIniLocalMon = (PINILOCALMON)hMonitor;
  163. *phXcv = CreateXcvPortEntry(pIniLocalMon, pszObject, GrantedAccess);
  164. return !!*phXcv;
  165. }
  166. BOOL
  167. LcmXcvClosePort(
  168. HANDLE hXcv
  169. )
  170. {
  171. LcmEnterSplSem();
  172. DeleteXcvPortEntry((PINIXCVPORT) hXcv);
  173. LcmLeaveSplSem();
  174. return TRUE;
  175. }
  176. DWORD
  177. DoDeletePort(
  178. PBYTE pInputData,
  179. DWORD cbInputData,
  180. PBYTE pOutputData,
  181. DWORD cbOutputData,
  182. PDWORD pcbOutputNeeded,
  183. PINIXCVPORT pIniXcv
  184. )
  185. {
  186. DWORD dwRet = ERROR_SUCCESS;
  187. if (!(pIniXcv->GrantedAccess & SERVER_ACCESS_ADMINISTER))
  188. return ERROR_ACCESS_DENIED;
  189. LcmEnterSplSem();
  190. if (LcmDeletePortEntry( pIniXcv->pIniLocalMon, (PWSTR)pInputData))
  191. WriteProfileString(szPorts, (PWSTR) pInputData, NULL);
  192. else
  193. dwRet = ERROR_FILE_NOT_FOUND;
  194. LcmLeaveSplSem();
  195. return dwRet;
  196. }
  197. DWORD
  198. DoPortExists(
  199. PBYTE pInputData,
  200. DWORD cbInputData,
  201. PBYTE pOutputData,
  202. DWORD cbOutputData,
  203. PDWORD pcbOutputNeeded,
  204. PINIXCVPORT pIniXcv
  205. )
  206. {
  207. DWORD dwRet;
  208. BOOL bPortExists;
  209. *pcbOutputNeeded = sizeof(DWORD);
  210. if (cbOutputData < sizeof(DWORD)) {
  211. return ERROR_INSUFFICIENT_BUFFER;
  212. }
  213. bPortExists = PortExists(NULL, (PWSTR) pInputData, &dwRet);
  214. if (dwRet == ERROR_SUCCESS)
  215. *(DWORD *) pOutputData = bPortExists;
  216. return dwRet;
  217. }
  218. DWORD
  219. DoPortIsValid(
  220. PBYTE pInputData,
  221. DWORD cbInputData,
  222. PBYTE pOutputData,
  223. DWORD cbOutputData,
  224. PDWORD pcbOutputNeeded,
  225. PINIXCVPORT pIniXcv
  226. )
  227. {
  228. BOOL bRet;
  229. bRet = PortIsValid((PWSTR) pInputData);
  230. return bRet ? ERROR_SUCCESS : GetLastError();
  231. }
  232. DWORD
  233. DoAddPort(
  234. PBYTE pInputData,
  235. DWORD cbInputData,
  236. PBYTE pOutputData,
  237. DWORD cbOutputData,
  238. PDWORD pcbOutputNeeded,
  239. PINIXCVPORT pIniXcv
  240. )
  241. {
  242. DWORD dwRet, bPortExists;
  243. PINIPORT pIniPort = NULL;
  244. if (!(pIniXcv->GrantedAccess & SERVER_ACCESS_ADMINISTER))
  245. return ERROR_ACCESS_DENIED;
  246. if ( cbInputData == 0 ||
  247. pInputData == NULL ||
  248. ( wcslen((LPWSTR)pInputData) + 1 ) * sizeof(WCHAR) != cbInputData )
  249. return ERROR_INVALID_PARAMETER;
  250. bPortExists = PortExists(NULL, (PWSTR) pInputData, &dwRet);
  251. if (dwRet == ERROR_SUCCESS) {
  252. if (bPortExists) {
  253. SetLastError(ERROR_ALREADY_EXISTS);
  254. } else {
  255. pIniPort = LcmCreatePortEntry( pIniXcv->pIniLocalMon, (PWSTR)pInputData );
  256. if (pIniPort) {
  257. if (!WriteProfileString(szPorts, (PWSTR) pInputData, L""))
  258. {
  259. LcmDeletePortEntry(pIniXcv->pIniLocalMon, (PWSTR) pInputData);
  260. pIniPort = NULL;
  261. }
  262. }
  263. }
  264. }
  265. return pIniPort ? ERROR_SUCCESS : GetLastError();
  266. }
  267. DWORD
  268. DoSetDefaultCommConfig(
  269. PBYTE pInputData,
  270. DWORD cbInputData,
  271. PBYTE pOutputData,
  272. DWORD cbOutputData,
  273. PDWORD pcbOutputNeeded,
  274. PINIXCVPORT pIniXcv
  275. )
  276. {
  277. BOOL bRet = FALSE;
  278. DWORD dwLength;
  279. PWSTR pszPortName = NULL;
  280. COMMCONFIG *pCommConfig = (COMMCONFIG *) pInputData;
  281. if (!(pIniXcv->GrantedAccess & SERVER_ACCESS_ADMINISTER))
  282. return ERROR_ACCESS_DENIED;
  283. dwLength = wcslen(pIniXcv->pszName);
  284. if (pIniXcv->pszName[dwLength - 1] == L':') {
  285. if (!(pszPortName = AllocSplStr(pIniXcv->pszName)))
  286. goto Done;
  287. pszPortName[dwLength - 1] = L'\0';
  288. }
  289. bRet = SetDefaultCommConfig(pszPortName,
  290. pCommConfig,
  291. pCommConfig->dwSize);
  292. Done:
  293. FreeSplStr(pszPortName);
  294. return bRet ? ERROR_SUCCESS : GetLastError();
  295. }
  296. DWORD
  297. DoGetDefaultCommConfig(
  298. PBYTE pInputData,
  299. DWORD cbInputData,
  300. PBYTE pOutputData,
  301. DWORD cbOutputData,
  302. PDWORD pcbOutputNeeded,
  303. PINIXCVPORT pIniXcv
  304. )
  305. {
  306. PWSTR pszPortName = (PWSTR) pInputData;
  307. COMMCONFIG *pCommConfig = (COMMCONFIG *) pOutputData;
  308. BOOL bRet;
  309. if (cbOutputData < sizeof(COMMCONFIG))
  310. return ERROR_INSUFFICIENT_BUFFER;
  311. pCommConfig->dwProviderSubType = PST_RS232;
  312. *pcbOutputNeeded = cbOutputData;
  313. bRet = GetDefaultCommConfig(pszPortName, pCommConfig, pcbOutputNeeded);
  314. return bRet ? ERROR_SUCCESS : GetLastError();
  315. }
  316. DWORD
  317. GetTransmissionRetryTimeout(
  318. PBYTE pInputData,
  319. DWORD cbInputData,
  320. PBYTE pOutputData,
  321. DWORD cbOutputData,
  322. PDWORD pcbOutputNeeded,
  323. PINIXCVPORT pIniXcv
  324. )
  325. {
  326. *pcbOutputNeeded = sizeof(DWORD);
  327. if (cbOutputData < sizeof(DWORD))
  328. return ERROR_INSUFFICIENT_BUFFER;
  329. *(PDWORD) pOutputData = GetProfileInt(szWindows,
  330. szINIKey_TransmissionRetryTimeout,
  331. 45 );
  332. return ERROR_SUCCESS;
  333. }
  334. DWORD
  335. GetMonitorUI(
  336. PBYTE pInputData,
  337. DWORD cbInputData,
  338. PBYTE pOutputData,
  339. DWORD cbOutputData,
  340. PDWORD pcbOutputNeeded,
  341. PINIXCVPORT pIniXcv
  342. )
  343. {
  344. DWORD dwRet;
  345. *pcbOutputNeeded = sizeof( SZLOCALUI );
  346. if (cbOutputData < *pcbOutputNeeded) {
  347. dwRet = ERROR_INSUFFICIENT_BUFFER;
  348. } else {
  349. dwRet = HRESULT_CODE (StringCbCopy ((PWSTR) pOutputData, cbOutputData, SZLOCALUI));
  350. }
  351. return dwRet;
  352. }
  353. DWORD
  354. ConfigureLPTPortCommandOK(
  355. PBYTE pInputData,
  356. DWORD cbInputData,
  357. PBYTE pOutputData,
  358. DWORD cbOutputData,
  359. PDWORD pcbOutputNeeded,
  360. PINIXCVPORT pIniXcv
  361. )
  362. {
  363. if (!(pIniXcv->GrantedAccess & SERVER_ACCESS_ADMINISTER))
  364. return ERROR_ACCESS_DENIED;
  365. if (!WriteProfileString( szWindows, szINIKey_TransmissionRetryTimeout, (PWSTR) pInputData ))
  366. return GetLastError();
  367. return ERROR_SUCCESS;
  368. }