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.

846 lines
23 KiB

  1. /*++
  2. Copyright (c) 1985 - 1999, Microsoft Corporation
  3. Module Name:
  4. stream.c
  5. Abstract:
  6. This module contains the stubs for the console stream API.
  7. Author:
  8. Therese Stowell (thereses) 3-Dec-1990
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #if !defined(BUILD_WOW64)
  14. HANDLE InputWaitHandle = INVALID_HANDLE_VALUE;
  15. HANDLE
  16. APIENTRY
  17. GetConsoleInputWaitHandle( VOID )
  18. {
  19. return InputWaitHandle;
  20. }
  21. #endif //!defined(BUILD_WOW64)
  22. #if !defined(BUILD_WOW6432)
  23. HANDLE
  24. APIENTRY
  25. OpenConsoleWInternal(
  26. IN ULONG HandleType,
  27. IN ULONG DesiredAccess,
  28. IN BOOL InheritHandle,
  29. IN ULONG ShareMode
  30. )
  31. /*++
  32. Routine Description:
  33. Marshals parameters for the ConsolepOpenConsole command.
  34. Arguments:
  35. See the CONSOLE_OPENCONSOLE_MSG structure and OpenConsoleW.
  36. Return Value:
  37. INVALID_HANDLE_VALUE - An error occured.
  38. --*/
  39. {
  40. CONSOLE_API_MSG m;
  41. PCONSOLE_OPENCONSOLE_MSG a = &m.u.OpenConsole;
  42. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  43. a->HandleType = HandleType;
  44. a->DesiredAccess = DesiredAccess;
  45. a->InheritHandle = InheritHandle;
  46. a->ShareMode= ShareMode;
  47. CsrClientCallServer( (PCSR_API_MSG)&m,
  48. NULL,
  49. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  50. ConsolepOpenConsole
  51. ),
  52. sizeof( *a )
  53. );
  54. if (!NT_SUCCESS( m.ReturnValue)) {
  55. SET_LAST_NT_ERROR(m.ReturnValue);
  56. return INVALID_HANDLE_VALUE;
  57. }
  58. else {
  59. return a->Handle;
  60. }
  61. }
  62. #endif // !defined(BUILD_WOW6432)
  63. #if !defined(BUILD_WOW64)
  64. HANDLE
  65. APIENTRY
  66. OpenConsoleW(
  67. IN LPWSTR lpConsoleDevice,
  68. IN DWORD dwDesiredAccess,
  69. IN BOOL bInheritHandle,
  70. IN DWORD dwShareMode
  71. )
  72. /*++
  73. Parameters:
  74. lpConsoleDevice - Supplies the console device name to open. "CONIN$"
  75. indicates console input. "CONOUT$" indicates console output. The
  76. caller must have appropriate access to the console for this call to
  77. succeed.
  78. dwDesiredAccess - Supplies the caller's desired access to the console
  79. device.
  80. DesiredAccess Flags:
  81. GENERIC_READ - Read access to the console device is requested. This
  82. allows data to be read from the console device.
  83. GENERIC_WRITE - Write access to the console device is requested. This
  84. allows data to be written to the console device.
  85. bInheritHandle - Supplies a flag that indicates whether or not the
  86. returned handle is to be inherited by a new process
  87. during a CreateProcess. A value of TRUE indicates that the
  88. new process will inherit the handle.
  89. dwShareMode - Supplies a set of flags that indicates how this console
  90. device is to be shared with other openers of the console device. A
  91. value of zero for this parameter indicates no sharing of the console,
  92. or exclusive access to the console is to occur.
  93. ShareMode Flags:
  94. FILE_SHARE_READ - Other open operations may be performed on the
  95. console device for read access.
  96. FILE_SHARE_WRITE - Other open operations may be performed on the
  97. console device for write access.
  98. Return Value:
  99. Not -1 - Returns an open handle to the specified console device.
  100. Subsequent access to the file is controlled by the DesiredAccess
  101. parameter.
  102. 0xffffffff - The operation failed. Extended error status is available
  103. using GetLastError.
  104. --*/
  105. {
  106. ULONG HandleType;
  107. try {
  108. if (CompareStringW(LOCALE_INVARIANT,
  109. NORM_IGNORECASE,
  110. lpConsoleDevice,
  111. -1,
  112. CONSOLE_INPUT_STRING,
  113. -1) == CSTR_EQUAL) {
  114. HandleType = CONSOLE_INPUT_HANDLE;
  115. }
  116. else if (CompareStringW(LOCALE_INVARIANT,
  117. NORM_IGNORECASE,
  118. lpConsoleDevice,
  119. -1,
  120. CONSOLE_OUTPUT_STRING,
  121. -1) == CSTR_EQUAL) {
  122. HandleType = CONSOLE_OUTPUT_HANDLE;
  123. }
  124. else {
  125. SET_LAST_ERROR(ERROR_INVALID_PARAMETER);
  126. return INVALID_HANDLE_VALUE;
  127. }
  128. } except( EXCEPTION_EXECUTE_HANDLER ) {
  129. SET_LAST_ERROR(ERROR_INVALID_ACCESS);
  130. return INVALID_HANDLE_VALUE;
  131. }
  132. if (dwDesiredAccess & ~VALID_ACCESSES ||
  133. dwShareMode & ~VALID_SHARE_ACCESSES) {
  134. SET_LAST_ERROR(ERROR_INVALID_PARAMETER);
  135. return INVALID_HANDLE_VALUE;
  136. }
  137. return OpenConsoleWInternal(HandleType,
  138. dwDesiredAccess,
  139. bInheritHandle,
  140. dwShareMode
  141. );
  142. }
  143. #endif // !defined(BUILD_WOW64)
  144. #if !defined(BUILD_WOW6432)
  145. BOOL
  146. APIENTRY
  147. ReadConsoleInternal(
  148. IN HANDLE hConsoleInput,
  149. OUT LPVOID lpBuffer,
  150. IN DWORD nNumberOfCharsToRead,
  151. OUT LPDWORD lpNumberOfCharsRead,
  152. IN OUT LPVOID lpReserved,
  153. IN BOOLEAN Unicode,
  154. IN USHORT ExeNameLength,
  155. IN LPWSTR ExeName
  156. )
  157. /*++
  158. Parameters:
  159. hConsoleInput - Supplies an open handle to "CONIN$" open for GENERIC_READ
  160. or the StdIn handle.
  161. lpBuffer - Supplies the address of a buffer to receive the data read
  162. from the console input.
  163. nNumberOfBytesToRead - Supplies the number of bytes to read from the
  164. input buffer.
  165. lpReserved - Ignore unless 4.0 application, in which case it points
  166. to a CONSOLE_READCONSOLE_CONTROL data structure. UNICODE only.
  167. If !Unicode, then call fails if this parameter is non-NULL
  168. Unicode - TRUE if call from ReadConsoleW, FALSE if ReadConsoleA
  169. Return Value:
  170. NON-NULL - Returns the number of bytes actually read from the input buffer.
  171. FALSE/NULL - The operation failed.
  172. Extended error status is available using GetLastError.
  173. --*/
  174. {
  175. PCSR_CAPTURE_HEADER CaptureBuffer;
  176. CONSOLE_API_MSG m;
  177. PCONSOLE_READCONSOLE_MSG a = &m.u.ReadConsole;
  178. BOOLEAN Dummy;
  179. PCONSOLE_READCONSOLE_CONTROL pInputControl;
  180. NTSTATUS Status;
  181. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  182. a->InputHandle = hConsoleInput;
  183. a->ExeNameLength = ExeNameLength;
  184. RtlCopyMemory(a->Buffer, ExeName, ExeNameLength);
  185. a->Unicode = Unicode;
  186. //
  187. // if ansi, make capture buffer large enough to hold translated
  188. // string. this will make server side code much simpler.
  189. //
  190. a->CaptureBufferSize = a->NumBytes = nNumberOfCharsToRead * sizeof(WCHAR);
  191. if (a->CaptureBufferSize > BUFFER_SIZE) {
  192. CaptureBuffer = CsrAllocateCaptureBuffer( 1,
  193. a->CaptureBufferSize
  194. );
  195. if (CaptureBuffer == NULL) {
  196. SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
  197. return FALSE;
  198. }
  199. CsrCaptureMessageBuffer( CaptureBuffer,
  200. NULL,
  201. a->CaptureBufferSize,
  202. (PVOID *) &a->BufPtr
  203. );
  204. }
  205. else {
  206. a->BufPtr = a->Buffer;
  207. CaptureBuffer = NULL;
  208. }
  209. pInputControl = (PCONSOLE_READCONSOLE_CONTROL)lpReserved;
  210. a->InitialNumBytes = 0;
  211. a->CtrlWakeupMask = 0;
  212. a->ControlKeyState = 0;
  213. Status = STATUS_SUCCESS;
  214. try {
  215. if (Unicode &&
  216. ARGUMENT_PRESENT(lpReserved) &&
  217. NtCurrentPeb()->ImageSubsystemMajorVersion >= 4 &&
  218. pInputControl->nLength == sizeof(*pInputControl)
  219. ) {
  220. if ((pInputControl->nInitialChars > nNumberOfCharsToRead)) {
  221. Status = STATUS_INVALID_PARAMETER;
  222. } else {
  223. a->InitialNumBytes = pInputControl->nInitialChars * sizeof(WCHAR);
  224. if (pInputControl->nInitialChars != 0) {
  225. RtlCopyMemory( a->BufPtr, lpBuffer, a->InitialNumBytes );
  226. }
  227. a->CtrlWakeupMask = pInputControl->dwCtrlWakeupMask;
  228. }
  229. } else {
  230. pInputControl = NULL;
  231. }
  232. } except( EXCEPTION_EXECUTE_HANDLER ) {
  233. Status = GetExceptionCode();
  234. }
  235. if (!NT_SUCCESS(Status) && pInputControl != NULL) {
  236. if (CaptureBuffer != NULL) {
  237. CsrFreeCaptureBuffer( CaptureBuffer );
  238. }
  239. SET_LAST_NT_ERROR(Status);
  240. return FALSE;
  241. }
  242. CsrClientCallServer( (PCSR_API_MSG)&m,
  243. CaptureBuffer,
  244. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  245. ConsolepReadConsole
  246. ),
  247. sizeof( *a )
  248. );
  249. if (NT_SUCCESS( m.ReturnValue )) {
  250. try {
  251. *lpNumberOfCharsRead = a->NumBytes;
  252. if (Unicode) {
  253. *lpNumberOfCharsRead /= sizeof(WCHAR);
  254. if (pInputControl != NULL) {
  255. pInputControl->dwControlKeyState = a->ControlKeyState;
  256. }
  257. }
  258. RtlCopyMemory( lpBuffer, a->BufPtr, a->NumBytes );
  259. } except( EXCEPTION_EXECUTE_HANDLER ) {
  260. if (CaptureBuffer != NULL) {
  261. CsrFreeCaptureBuffer( CaptureBuffer );
  262. }
  263. SET_LAST_ERROR(ERROR_INVALID_ACCESS);
  264. return FALSE;
  265. }
  266. }
  267. if (CaptureBuffer != NULL) {
  268. CsrFreeCaptureBuffer( CaptureBuffer );
  269. }
  270. if (!NT_SUCCESS( m.ReturnValue )) {
  271. SET_LAST_NT_ERROR(m.ReturnValue);
  272. return FALSE;
  273. } else if (m.ReturnValue == STATUS_ALERTED) {
  274. // ctrl-c or ctrl-break
  275. NtYieldExecution();
  276. SET_LAST_ERROR(ERROR_OPERATION_ABORTED);
  277. }
  278. return TRUE;
  279. }
  280. #endif //!defined(BUILD_WOW6432)
  281. #if !defined(BUILD_WOW64)
  282. BOOL
  283. APIENTRY
  284. ReadConsoleA(
  285. IN HANDLE hConsoleInput,
  286. OUT LPVOID lpBuffer,
  287. IN DWORD nNumberOfCharsToRead,
  288. OUT LPDWORD lpNumberOfCharsRead,
  289. IN OUT LPVOID lpReserved
  290. )
  291. {
  292. WCHAR ExeName[BUFFER_SIZE/2];
  293. USHORT ExeNameLength;
  294. ExeNameLength = GetCurrentExeName(ExeName, sizeof(ExeName));
  295. return ReadConsoleInternal(hConsoleInput,
  296. lpBuffer,
  297. nNumberOfCharsToRead,
  298. lpNumberOfCharsRead,
  299. NULL,
  300. FALSE,
  301. ExeNameLength,
  302. ExeName
  303. );
  304. UNREFERENCED_PARAMETER(lpReserved);
  305. }
  306. BOOL
  307. APIENTRY
  308. ReadConsoleW(
  309. IN HANDLE hConsoleInput,
  310. OUT LPVOID lpBuffer,
  311. IN DWORD nNumberOfCharsToRead,
  312. OUT LPDWORD lpNumberOfCharsRead,
  313. IN OUT LPVOID lpReserved
  314. )
  315. {
  316. WCHAR ExeName[BUFFER_SIZE/2];
  317. USHORT ExeNameLength;
  318. ExeNameLength = GetCurrentExeName(ExeName, sizeof(ExeName));
  319. return ReadConsoleInternal(hConsoleInput,
  320. lpBuffer,
  321. nNumberOfCharsToRead,
  322. lpNumberOfCharsRead,
  323. lpReserved,
  324. TRUE,
  325. ExeNameLength,
  326. ExeName
  327. );
  328. UNREFERENCED_PARAMETER(lpReserved);
  329. }
  330. #endif //!defined(BUILD_WOW64)
  331. #if !defined(BUILD_WOW6432)
  332. BOOL
  333. APIENTRY
  334. WriteConsoleInternal(
  335. IN HANDLE hConsoleOutput,
  336. IN CONST VOID *lpBuffer,
  337. IN DWORD nNumberOfCharsToWrite,
  338. OUT LPDWORD lpNumberOfCharsWritten,
  339. IN BOOLEAN Unicode
  340. )
  341. /*++
  342. Parameters:
  343. hFile - Supplies an open handle to to "CONOUT$" open for GENERIC_WRITE
  344. or the StdOut or StdErr handle.
  345. lpBuffer - Supplies the address of the data that is to be written to
  346. the console output.
  347. nNumberOfBytesToWrite - Supplies the number of bytes to write to the
  348. console output.
  349. Return Value:
  350. NON-NULL - Returns the number of bytes actually written to the device.
  351. FALSE/NULL - The operation failed.
  352. Extended error status is available using GetLastError.
  353. --*/
  354. {
  355. PCSR_CAPTURE_HEADER CaptureBuffer;
  356. CONSOLE_API_MSG m;
  357. PCONSOLE_WRITECONSOLE_MSG a = &m.u.WriteConsole;
  358. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  359. a->OutputHandle = hConsoleOutput;
  360. if (Unicode) {
  361. a->NumBytes = nNumberOfCharsToWrite * sizeof(WCHAR);
  362. } else {
  363. a->NumBytes = nNumberOfCharsToWrite;
  364. }
  365. a->Unicode = Unicode;
  366. if (a->NumBytes > BUFFER_SIZE) {
  367. CaptureBuffer = CsrAllocateCaptureBuffer( 1,
  368. a->NumBytes
  369. );
  370. if (CaptureBuffer == NULL) {
  371. SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
  372. return FALSE;
  373. }
  374. CsrCaptureMessageBuffer( CaptureBuffer,
  375. (PCHAR) lpBuffer,
  376. a->NumBytes,
  377. (PVOID *) &a->BufPtr
  378. );
  379. a->BufferInMessage = FALSE;
  380. }
  381. else {
  382. a->BufPtr = a->Buffer;
  383. try {
  384. RtlCopyMemory( a->BufPtr, lpBuffer, a->NumBytes);
  385. } except( EXCEPTION_EXECUTE_HANDLER ) {
  386. SET_LAST_ERROR(ERROR_INVALID_ACCESS);
  387. return FALSE;
  388. }
  389. CaptureBuffer = NULL;
  390. a->BufferInMessage = TRUE;
  391. }
  392. CsrClientCallServer( (PCSR_API_MSG)&m,
  393. CaptureBuffer,
  394. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  395. ConsolepWriteConsole
  396. ),
  397. sizeof( *a )
  398. );
  399. if (CaptureBuffer != NULL) {
  400. CsrFreeCaptureBuffer( CaptureBuffer );
  401. }
  402. if (!NT_SUCCESS( m.ReturnValue )) {
  403. SET_LAST_NT_ERROR(m.ReturnValue);
  404. return FALSE;
  405. }
  406. try {
  407. *lpNumberOfCharsWritten = a->NumBytes;
  408. if (Unicode) {
  409. *lpNumberOfCharsWritten /= sizeof(WCHAR);
  410. }
  411. } except( EXCEPTION_EXECUTE_HANDLER ) {
  412. SET_LAST_ERROR(ERROR_INVALID_ACCESS);
  413. return FALSE;
  414. }
  415. return TRUE;
  416. }
  417. #endif //!defined(BUILD_WOW6432)
  418. #if !defined(BUILD_WOW64)
  419. BOOL
  420. APIENTRY
  421. WriteConsoleA(
  422. IN HANDLE hConsoleOutput,
  423. IN CONST VOID *lpBuffer,
  424. IN DWORD nNumberOfCharsToWrite,
  425. OUT LPDWORD lpNumberOfCharsWritten,
  426. IN OUT LPVOID lpReserved
  427. )
  428. {
  429. return WriteConsoleInternal(hConsoleOutput,
  430. lpBuffer,
  431. nNumberOfCharsToWrite,
  432. lpNumberOfCharsWritten,
  433. FALSE
  434. );
  435. UNREFERENCED_PARAMETER(lpReserved);
  436. }
  437. BOOL
  438. APIENTRY
  439. WriteConsoleW(
  440. IN HANDLE hConsoleOutput,
  441. IN CONST VOID *lpBuffer,
  442. IN DWORD nNumberOfCharsToWrite,
  443. OUT LPDWORD lpNumberOfCharsWritten,
  444. IN OUT LPVOID lpReserved
  445. )
  446. {
  447. return WriteConsoleInternal(hConsoleOutput,
  448. lpBuffer,
  449. nNumberOfCharsToWrite,
  450. lpNumberOfCharsWritten,
  451. TRUE
  452. );
  453. UNREFERENCED_PARAMETER(lpReserved);
  454. }
  455. #endif //!defined(BUILD_WOW64)
  456. #if !defined(BUILD_WOW6432)
  457. BOOL
  458. APIENTRY
  459. CloseConsoleHandle(
  460. IN HANDLE hConsole
  461. )
  462. /*++
  463. Parameters:
  464. hConsole - An open handle to console input or output.
  465. Return Value:
  466. TRUE - The operation was successful.
  467. FALSE/NULL - The operation failed. Extended error status is available
  468. using GetLastError.
  469. --*/
  470. {
  471. CONSOLE_API_MSG m;
  472. PCONSOLE_CLOSEHANDLE_MSG a = &m.u.CloseHandle;
  473. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  474. a->Handle = hConsole;
  475. CsrClientCallServer( (PCSR_API_MSG)&m,
  476. NULL,
  477. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  478. ConsolepCloseHandle
  479. ),
  480. sizeof( *a )
  481. );
  482. if (NT_SUCCESS( m.ReturnValue )) {
  483. return TRUE;
  484. } else {
  485. SET_LAST_NT_ERROR (m.ReturnValue);
  486. return FALSE;
  487. }
  488. }
  489. HANDLE
  490. APIENTRY
  491. DuplicateConsoleHandle(
  492. IN HANDLE hSourceHandle,
  493. IN DWORD dwDesiredAccess,
  494. IN BOOL bInheritHandle,
  495. IN DWORD dwOptions
  496. )
  497. /*++
  498. Parameters:
  499. hSourceHandle - An open handle to the console device.
  500. dwDesiredAccess - The access requested to for the new handle. This
  501. access must be equal to or a proper subset of the granted access
  502. associated with the SourceHandle. This parameter is ignored if
  503. the DUPLICATE_SAME_ACCESS option is specified.
  504. bInheritHandle - Supplies a flag that if TRUE, marks the target
  505. handle as inheritable. If this is the case, then the target
  506. handle will be inherited to new processes each time the target
  507. process creates a new process using CreateProcess.
  508. dwOptions - Specifies optional behaviors for the caller.
  509. Options Flags:
  510. DUPLICATE_CLOSE_SOURCE - The SourceHandle will be closed by
  511. this service prior to returning to the caller. This occurs
  512. regardless of any error status returned.
  513. DUPLICATE_SAME_ACCESS - The DesiredAccess parameter is ignored
  514. and instead the GrantedAccess associated with SourceHandle
  515. is used as the DesiredAccess when creating the TargetHandle.
  516. Return Value:
  517. Not -1 - Returns an open handle to the specified console device.
  518. Subsequent access to the file is controlled by the DesiredAccess
  519. parameter.
  520. 0xffffffff - The operation failed. Extended error status is available
  521. using GetLastError.
  522. --*/
  523. {
  524. CONSOLE_API_MSG m;
  525. PCONSOLE_DUPHANDLE_MSG a = &m.u.DuplicateHandle;
  526. if (dwOptions & ~VALID_DUP_OPTIONS) {
  527. SET_LAST_ERROR(ERROR_INVALID_PARAMETER);
  528. return INVALID_HANDLE_VALUE;
  529. }
  530. if (((dwOptions & DUPLICATE_SAME_ACCESS) == 0) &&
  531. (dwDesiredAccess & ~VALID_ACCESSES)) {
  532. SET_LAST_ERROR(ERROR_INVALID_PARAMETER);
  533. return INVALID_HANDLE_VALUE;
  534. }
  535. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  536. a->SourceHandle = hSourceHandle;
  537. a->DesiredAccess = dwDesiredAccess;
  538. a->InheritHandle = (BOOLEAN) bInheritHandle;
  539. a->Options = dwOptions;
  540. CsrClientCallServer( (PCSR_API_MSG)&m,
  541. NULL,
  542. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  543. ConsolepDupHandle
  544. ),
  545. sizeof( *a )
  546. );
  547. if (NT_SUCCESS( m.ReturnValue )) {
  548. return a->TargetHandle;
  549. } else {
  550. SET_LAST_NT_ERROR (m.ReturnValue);
  551. return INVALID_HANDLE_VALUE;
  552. }
  553. }
  554. BOOL
  555. APIENTRY
  556. GetConsoleHandleInformation(
  557. IN HANDLE hObject,
  558. OUT LPDWORD lpdwFlags
  559. )
  560. /*++
  561. Parameters:
  562. hObject - An open handle to console input or output.
  563. lpdwFlags - Receives flags for console object.
  564. Return Value:
  565. TRUE - The operation was successful.
  566. FALSE/NULL - The operation failed. Extended error status is available
  567. using GetLastError.
  568. --*/
  569. {
  570. CONSOLE_API_MSG m;
  571. PCONSOLE_GETHANDLEINFORMATION_MSG a = &m.u.GetHandleInformation;
  572. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  573. a->Handle = hObject;
  574. CsrClientCallServer( (PCSR_API_MSG)&m,
  575. NULL,
  576. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  577. ConsolepGetHandleInformation
  578. ),
  579. sizeof( *a )
  580. );
  581. if (NT_SUCCESS( m.ReturnValue )) {
  582. try {
  583. *lpdwFlags = a->Flags;
  584. } except( EXCEPTION_EXECUTE_HANDLER ) {
  585. SET_LAST_ERROR(ERROR_INVALID_ACCESS);
  586. return FALSE;
  587. }
  588. return TRUE;
  589. } else {
  590. SET_LAST_NT_ERROR (m.ReturnValue);
  591. return FALSE;
  592. }
  593. }
  594. BOOL
  595. APIENTRY
  596. SetConsoleHandleInformation(
  597. IN HANDLE hObject,
  598. IN DWORD dwMask,
  599. IN DWORD dwFlags
  600. )
  601. /*++
  602. Parameters:
  603. hObject - An open handle to console input or output.
  604. dwMask - Flags to change.
  605. dwFlags - New values for flags.
  606. Return Value:
  607. TRUE - The operation was successful.
  608. FALSE/NULL - The operation failed. Extended error status is available
  609. using GetLastError.
  610. --*/
  611. {
  612. CONSOLE_API_MSG m;
  613. PCONSOLE_SETHANDLEINFORMATION_MSG a = &m.u.SetHandleInformation;
  614. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  615. a->Handle = hObject;
  616. a->Mask = dwMask;
  617. a->Flags = dwFlags;
  618. CsrClientCallServer( (PCSR_API_MSG)&m,
  619. NULL,
  620. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  621. ConsolepSetHandleInformation
  622. ),
  623. sizeof( *a )
  624. );
  625. if (NT_SUCCESS( m.ReturnValue )) {
  626. return TRUE;
  627. } else {
  628. SET_LAST_NT_ERROR (m.ReturnValue);
  629. return FALSE;
  630. }
  631. }
  632. BOOL
  633. APIENTRY
  634. VerifyConsoleIoHandle(
  635. IN HANDLE hIoHandle
  636. )
  637. /*++
  638. Parameters:
  639. hIoHandle - Handle to verify
  640. Return Value:
  641. TRUE - handle is a valid console handle.
  642. FALSE - handle is not a valid console handle.
  643. --*/
  644. {
  645. CONSOLE_API_MSG m;
  646. PCONSOLE_VERIFYIOHANDLE_MSG a = &m.u.VerifyConsoleIoHandle;
  647. a->ConsoleHandle = GET_CONSOLE_HANDLE;
  648. a->Handle = hIoHandle;
  649. //
  650. // If this process doesn't have a console handle, bail immediately.
  651. //
  652. if (a->ConsoleHandle == NULL) {
  653. return FALSE;
  654. }
  655. CsrClientCallServer( (PCSR_API_MSG)&m,
  656. NULL,
  657. CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
  658. ConsolepVerifyIoHandle
  659. ),
  660. sizeof( *a )
  661. );
  662. if (NT_SUCCESS( m.ReturnValue )) {
  663. return a->Valid;
  664. } else {
  665. SET_LAST_NT_ERROR (m.ReturnValue);
  666. return FALSE;
  667. }
  668. }
  669. #endif //!defined(BUILD_WOW6432)