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.

1356 lines
34 KiB

  1. /* file.c
  2. * OemUnicode win32 thunks
  3. * - file and debug apis
  4. *
  5. * 14-Jan-1993 Jonle
  6. */
  7. #include <nt.h>
  8. #include <ntrtl.h>
  9. #include <nturtl.h>
  10. #include <windows.h>
  11. #include <oemuni.h>
  12. #include "oem.h"
  13. #include "dpmtbls.h"
  14. BOOL
  15. CheckForSameCurdir(
  16. PUNICODE_STRING PathName
  17. )
  18. {
  19. PCURDIR CurDir;
  20. UNICODE_STRING CurrentDir;
  21. BOOL rv;
  22. if(!PathName) {
  23. return FALSE;
  24. }
  25. CurDir = &(NtCurrentPeb()->ProcessParameters->CurrentDirectory);
  26. if (CurDir->DosPath.Length > 6 ) {
  27. if ( (CurDir->DosPath.Length-2) != PathName->Length ) {
  28. return FALSE;
  29. }
  30. }
  31. else {
  32. if ( CurDir->DosPath.Length != PathName->Length ) {
  33. return FALSE;
  34. }
  35. }
  36. RtlAcquirePebLock();
  37. CurrentDir = CurDir->DosPath;
  38. if ( CurrentDir.Length > 6 ) {
  39. CurrentDir.Length -= 2;
  40. }
  41. rv = FALSE;
  42. if ( RtlEqualUnicodeString(&CurrentDir,PathName,TRUE) ) {
  43. rv = TRUE;
  44. }
  45. RtlReleasePebLock();
  46. return rv;
  47. }
  48. HANDLE
  49. WINAPI
  50. CreateFileOem(
  51. LPCSTR lpFileName,
  52. DWORD dwDesiredAccess,
  53. DWORD dwShareMode,
  54. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  55. DWORD dwCreationDisposition,
  56. DWORD dwFlagsAndAttributes,
  57. HANDLE hTemplateFile
  58. )
  59. /*++
  60. Routine Description:
  61. OEM thunk to CreateFileW
  62. --*/
  63. {
  64. PUNICODE_STRING Unicode;
  65. OEM_STRING OemString;
  66. NTSTATUS Status;
  67. HANDLE hFile;
  68. DWORD dw;
  69. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  70. InitOemString(&OemString,lpFileName);
  71. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  72. if ( !NT_SUCCESS(Status) ) {
  73. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  74. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  75. }
  76. else {
  77. BaseSetLastNTError(Status);
  78. }
  79. return INVALID_HANDLE_VALUE;
  80. }
  81. /*
  82. * Dos allows change of attributes (time\date etc)
  83. * on files opend for generic read, so we add
  84. * FILE_WRITE_ATTRIBUTES to the Desired access.
  85. */
  86. if(NtCurrentTeb()->Vdm) {
  87. hFile = DPM_CreateFileW( Unicode->Buffer,
  88. dwDesiredAccess == GENERIC_READ
  89. ? dwDesiredAccess | FILE_WRITE_ATTRIBUTES
  90. : dwDesiredAccess,
  91. dwShareMode,
  92. lpSecurityAttributes,
  93. dwCreationDisposition,
  94. dwFlagsAndAttributes,
  95. hTemplateFile
  96. );
  97. } else {
  98. hFile = CreateFileW( Unicode->Buffer,
  99. dwDesiredAccess == GENERIC_READ
  100. ? dwDesiredAccess | FILE_WRITE_ATTRIBUTES
  101. : dwDesiredAccess,
  102. dwShareMode,
  103. lpSecurityAttributes,
  104. dwCreationDisposition,
  105. dwFlagsAndAttributes,
  106. hTemplateFile
  107. );
  108. }
  109. /*
  110. * However, NT may fail the request because of the
  111. * extra FILE_WRITE_ATTRIBUTES. Common example
  112. * is a generic read open on a read only net share.
  113. * Retry the Createfile without FILE_WRTIE_ATTRIBUTES
  114. */
  115. if (hFile == INVALID_HANDLE_VALUE && dwDesiredAccess == GENERIC_READ)
  116. {
  117. if(NtCurrentTeb()->Vdm) {
  118. hFile = DPM_CreateFileW( Unicode->Buffer,
  119. dwDesiredAccess,
  120. dwShareMode,
  121. lpSecurityAttributes,
  122. dwCreationDisposition,
  123. dwFlagsAndAttributes,
  124. hTemplateFile
  125. );
  126. } else {
  127. hFile = CreateFileW( Unicode->Buffer,
  128. dwDesiredAccess,
  129. dwShareMode,
  130. lpSecurityAttributes,
  131. dwCreationDisposition,
  132. dwFlagsAndAttributes,
  133. hTemplateFile
  134. );
  135. }
  136. }
  137. return hFile;
  138. }
  139. BOOL
  140. APIENTRY
  141. SetVolumeLabelOem(
  142. LPSTR pszRootPath,
  143. LPSTR pszVolumeName
  144. )
  145. /*++
  146. Routine Description:
  147. Oem thunk to SetVolumeLabelW
  148. --*/
  149. {
  150. UNICODE_STRING UnicodeRootPath;
  151. PUNICODE_STRING UnicodeVolumeName;
  152. OEM_STRING OemString;
  153. BOOL bRet = FALSE;
  154. NTSTATUS Status;
  155. UnicodeVolumeName = &NtCurrentTeb()->StaticUnicodeString;
  156. InitOemString(&OemString, pszVolumeName);
  157. Status = RtlOemStringToUnicodeString(UnicodeVolumeName,&OemString,FALSE);
  158. if ( !NT_SUCCESS(Status) ) {
  159. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  160. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  161. }
  162. else {
  163. BaseSetLastNTError(Status);
  164. }
  165. return(FALSE);
  166. }
  167. InitOemString(&OemString, pszRootPath);
  168. Status = RtlOemStringToUnicodeString(&UnicodeRootPath, &OemString, TRUE);
  169. if ( !NT_SUCCESS(Status) ) {
  170. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  171. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  172. }
  173. else {
  174. BaseSetLastNTError(Status);
  175. }
  176. return(FALSE);
  177. }
  178. bRet = DPM_SetVolumeLabelW(UnicodeRootPath.Buffer,
  179. UnicodeVolumeName->Buffer
  180. );
  181. RtlFreeUnicodeString(&UnicodeRootPath);
  182. return(bRet);
  183. }
  184. BOOL
  185. APIENTRY
  186. SetFileAttributesOemSys(
  187. LPSTR lpFileName,
  188. DWORD dwFileAttributes,
  189. BOOL fSysCall
  190. )
  191. /*++
  192. Routine Description:
  193. Oem thunk to SetFileAttributesW
  194. fSysCall: TRUE if call is made on behalf of the system.
  195. FALSE if this is exposed as (part of) an API thunk.
  196. --*/
  197. {
  198. PUNICODE_STRING Unicode;
  199. OEM_STRING OemString;
  200. NTSTATUS Status;
  201. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  202. InitOemString(&OemString,lpFileName);
  203. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  204. if ( !NT_SUCCESS(Status) ) {
  205. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  206. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  207. }
  208. else {
  209. BaseSetLastNTError(Status);
  210. }
  211. return FALSE;
  212. }
  213. if(!NtCurrentTeb()->Vdm) {
  214. fSysCall = TRUE;
  215. }
  216. if(fSysCall) {
  217. return ( SetFileAttributesW(
  218. Unicode->Buffer,
  219. dwFileAttributes
  220. )
  221. );
  222. }
  223. else {
  224. return ( DPM_SetFileAttributesW(
  225. Unicode->Buffer,
  226. dwFileAttributes
  227. )
  228. );
  229. }
  230. }
  231. DWORD
  232. APIENTRY
  233. GetFileAttributesOemSys(
  234. LPSTR lpFileName,
  235. BOOL fSysCall
  236. )
  237. /*++
  238. Routine Description:
  239. OEM thunk to GetFileAttributesW
  240. fSysCall: TRUE if call is made on behalf of the system.
  241. FALSE if this is exposed as (part of) an API thunk.
  242. --*/
  243. {
  244. PUNICODE_STRING Unicode;
  245. OEM_STRING OemString;
  246. NTSTATUS Status;
  247. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  248. RtlInitAnsiString(&OemString,lpFileName);
  249. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  250. if ( !NT_SUCCESS(Status) ) {
  251. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  252. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  253. }
  254. else {
  255. BaseSetLastNTError(Status);
  256. }
  257. return 0xFFFFFFFF;
  258. }
  259. if(!NtCurrentTeb()->Vdm) {
  260. fSysCall = TRUE;
  261. }
  262. if(fSysCall) {
  263. return ( GetFileAttributesW(Unicode->Buffer) );
  264. }
  265. else {
  266. return ( DPM_GetFileAttributesW(Unicode->Buffer) );
  267. }
  268. }
  269. BOOL
  270. APIENTRY
  271. DeleteFileOem(
  272. LPSTR lpFileName
  273. )
  274. /*++
  275. Routine Description:
  276. Oem thunk to DeleteFileW
  277. --*/
  278. {
  279. PUNICODE_STRING Unicode;
  280. OEM_STRING OemString;
  281. NTSTATUS Status;
  282. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  283. InitOemString(&OemString,lpFileName);
  284. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  285. if ( !NT_SUCCESS(Status) ) {
  286. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  287. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  288. }
  289. else {
  290. BaseSetLastNTError(Status);
  291. }
  292. return FALSE;
  293. }
  294. if(NtCurrentTeb()->Vdm) {
  295. return(DPM_DeleteFileW(Unicode->Buffer));
  296. } else {
  297. return(DeleteFileW(Unicode->Buffer));
  298. }
  299. }
  300. BOOL
  301. APIENTRY
  302. MoveFileOem(
  303. LPSTR lpExistingFileName,
  304. LPSTR lpNewFileName
  305. )
  306. /*++
  307. Routine Description:
  308. OEM thunk to MoveFileW
  309. --*/
  310. {
  311. PUNICODE_STRING Unicode;
  312. UNICODE_STRING UnicodeNewFileName;
  313. OEM_STRING OemString;
  314. NTSTATUS Status;
  315. BOOL ReturnValue;
  316. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  317. InitOemString(&OemString,lpExistingFileName);
  318. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  319. if ( !NT_SUCCESS(Status) ) {
  320. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  321. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  322. }
  323. else {
  324. BaseSetLastNTError(Status);
  325. }
  326. return FALSE;
  327. }
  328. if (ARGUMENT_PRESENT( lpNewFileName )) {
  329. InitOemString(&OemString,lpNewFileName);
  330. Status = RtlOemStringToUnicodeString(&UnicodeNewFileName,&OemString,TRUE);
  331. if ( !NT_SUCCESS(Status) ) {
  332. BaseSetLastNTError(Status);
  333. return FALSE;
  334. }
  335. }
  336. else {
  337. UnicodeNewFileName.Buffer = NULL;
  338. }
  339. if(NtCurrentTeb()->Vdm) {
  340. ReturnValue = DPM_MoveFileExW(Unicode->Buffer,
  341. UnicodeNewFileName.Buffer,
  342. MOVEFILE_COPY_ALLOWED);
  343. } else {
  344. ReturnValue = MoveFileExW(Unicode->Buffer,
  345. UnicodeNewFileName.Buffer,
  346. MOVEFILE_COPY_ALLOWED);
  347. }
  348. if (UnicodeNewFileName.Buffer != NULL) {
  349. RtlFreeUnicodeString(&UnicodeNewFileName);
  350. }
  351. return ReturnValue;
  352. }
  353. BOOL
  354. APIENTRY
  355. MoveFileExOem(
  356. LPSTR lpExistingFileName,
  357. LPSTR lpNewFileName,
  358. DWORD fdwFlags
  359. )
  360. /*++
  361. Routine Description:
  362. OEM thunk to MoveFileExW
  363. --*/
  364. {
  365. PUNICODE_STRING Unicode;
  366. UNICODE_STRING UnicodeNewFileName;
  367. OEM_STRING OemString;
  368. NTSTATUS Status;
  369. BOOL ReturnValue;
  370. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  371. InitOemString(&OemString,lpExistingFileName);
  372. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  373. if ( !NT_SUCCESS(Status) ) {
  374. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  375. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  376. }
  377. else {
  378. BaseSetLastNTError(Status);
  379. }
  380. return FALSE;
  381. }
  382. if (ARGUMENT_PRESENT( lpNewFileName )) {
  383. InitOemString(&OemString,lpNewFileName);
  384. Status = RtlOemStringToUnicodeString(&UnicodeNewFileName,&OemString,TRUE);
  385. if ( !NT_SUCCESS(Status) ) {
  386. BaseSetLastNTError(Status);
  387. return FALSE;
  388. }
  389. }
  390. else {
  391. UnicodeNewFileName.Buffer = NULL;
  392. }
  393. if(NtCurrentTeb()->Vdm) {
  394. ReturnValue = DPM_MoveFileExW(Unicode->Buffer,
  395. UnicodeNewFileName.Buffer,
  396. fdwFlags);
  397. } else {
  398. ReturnValue = MoveFileExW(Unicode->Buffer,
  399. UnicodeNewFileName.Buffer,
  400. fdwFlags);
  401. }
  402. if (UnicodeNewFileName.Buffer != NULL) {
  403. RtlFreeUnicodeString(&UnicodeNewFileName);
  404. }
  405. return ReturnValue;
  406. }
  407. HANDLE
  408. APIENTRY
  409. FindFirstFileOem(
  410. LPSTR lpFileName,
  411. LPWIN32_FIND_DATAA lpFindFileData
  412. )
  413. /*++
  414. Routine Description:
  415. OEM thunk to FindFirstFileW
  416. --*/
  417. {
  418. HANDLE ReturnValue;
  419. PUNICODE_STRING Unicode;
  420. OEM_STRING OemString;
  421. NTSTATUS Status;
  422. UNICODE_STRING UnicodeString;
  423. WIN32_FIND_DATAW FindFileData;
  424. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  425. InitOemString(&OemString,lpFileName);
  426. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  427. if ( !NT_SUCCESS(Status) ) {
  428. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  429. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  430. }
  431. else {
  432. BaseSetLastNTError(Status);
  433. }
  434. return INVALID_HANDLE_VALUE;
  435. }
  436. if(NtCurrentTeb()->Vdm) {
  437. ReturnValue = DPM_FindFirstFileW(Unicode->Buffer,&FindFileData);
  438. } else {
  439. ReturnValue = FindFirstFileW(Unicode->Buffer,&FindFileData);
  440. }
  441. if ( ReturnValue == INVALID_HANDLE_VALUE ) {
  442. return ReturnValue;
  443. }
  444. RtlMoveMemory(
  445. lpFindFileData,
  446. &FindFileData,
  447. (ULONG)((ULONG)&FindFileData.cFileName[0] - (ULONG)&FindFileData)
  448. );
  449. RtlInitUnicodeString(&UnicodeString,(PWSTR)FindFileData.cFileName);
  450. OemString.Buffer = lpFindFileData->cFileName;
  451. OemString.MaximumLength = MAX_PATH;
  452. Status = RtlUnicodeStringToOemString(&OemString,&UnicodeString,FALSE);
  453. if (NT_SUCCESS(Status)) {
  454. RtlInitUnicodeString(&UnicodeString,(PWSTR)FindFileData.cAlternateFileName);
  455. OemString.Buffer = lpFindFileData->cAlternateFileName;
  456. OemString.MaximumLength = 14;
  457. Status = RtlUnicodeStringToOemString(&OemString,&UnicodeString,FALSE);
  458. }
  459. if ( !NT_SUCCESS(Status) ) {
  460. if(NtCurrentTeb()->Vdm) {
  461. DPM_FindClose(ReturnValue);
  462. } else {
  463. FindClose(ReturnValue);
  464. }
  465. BaseSetLastNTError(Status);
  466. return INVALID_HANDLE_VALUE;
  467. }
  468. return ReturnValue;
  469. }
  470. BOOL
  471. APIENTRY
  472. FindNextFileOem(
  473. HANDLE hFindFile,
  474. LPWIN32_FIND_DATAA lpFindFileData
  475. )
  476. /*++
  477. Routine Description:
  478. Oem thunk to FindFileDataW
  479. --*/
  480. {
  481. BOOL ReturnValue;
  482. OEM_STRING OemString;
  483. NTSTATUS Status;
  484. UNICODE_STRING UnicodeString;
  485. WIN32_FIND_DATAW FindFileData;
  486. if(NtCurrentTeb()->Vdm) {
  487. ReturnValue = DPM_FindNextFileW(hFindFile,&FindFileData);
  488. } else {
  489. ReturnValue = FindNextFileW(hFindFile,&FindFileData);
  490. }
  491. if ( !ReturnValue ) {
  492. return ReturnValue;
  493. }
  494. RtlMoveMemory(
  495. lpFindFileData,
  496. &FindFileData,
  497. (ULONG)((ULONG)&FindFileData.cFileName[0] - (ULONG)&FindFileData)
  498. );
  499. RtlInitUnicodeString(&UnicodeString,(PWSTR)FindFileData.cFileName);
  500. OemString.Buffer = lpFindFileData->cFileName;
  501. OemString.MaximumLength = MAX_PATH;
  502. Status = RtlUnicodeStringToOemString(&OemString,&UnicodeString,FALSE);
  503. if (NT_SUCCESS(Status)) {
  504. RtlInitUnicodeString(&UnicodeString,(PWSTR)FindFileData.cAlternateFileName);
  505. OemString.Buffer = lpFindFileData->cAlternateFileName;
  506. OemString.MaximumLength = 14;
  507. Status = RtlUnicodeStringToOemString(&OemString,&UnicodeString,FALSE);
  508. }
  509. if ( !NT_SUCCESS(Status) ) {
  510. BaseSetLastNTError(Status);
  511. return FALSE;
  512. }
  513. return ReturnValue;
  514. }
  515. DWORD
  516. APIENTRY
  517. GetFullPathNameOemSys(
  518. LPCSTR lpFileName,
  519. DWORD nBufferLength,
  520. LPSTR lpBuffer,
  521. LPSTR *lpFilePart,
  522. BOOL fSysCall
  523. )
  524. /*++
  525. Routine Description:
  526. Oem thunk to GetFullPathNameW
  527. fSysCall: TRUE if call is made on behalf of the system.
  528. FALSE if this is exposed as (part of) an API thunk.
  529. --*/
  530. {
  531. NTSTATUS Status;
  532. ULONG UnicodeLength;
  533. #ifdef FE_SB
  534. ULONG FilePartLength;
  535. UNICODE_STRING UnicodeFilePart;
  536. #endif
  537. UNICODE_STRING UnicodeString;
  538. UNICODE_STRING UnicodeResult;
  539. OEM_STRING OemString;
  540. OEM_STRING OemResult;
  541. PWSTR Ubuff;
  542. PWSTR FilePart;
  543. PWSTR *FilePartPtr;
  544. if ( ARGUMENT_PRESENT(lpFilePart) ) {
  545. FilePartPtr = &FilePart;
  546. }
  547. else {
  548. FilePartPtr = NULL;
  549. }
  550. RtlInitString(&OemString,lpFileName);
  551. Status = RtlOemStringToUnicodeString(&UnicodeString,&OemString,TRUE);
  552. if ( !NT_SUCCESS(Status) ){
  553. RtlFreeUnicodeString(&UnicodeString);
  554. BaseSetLastNTError(Status);
  555. return 0;
  556. }
  557. Ubuff = RtlAllocateHeap(RtlProcessHeap(), 0,(MAX_PATH<<1) + sizeof(UNICODE_NULL));
  558. if ( !Ubuff ) {
  559. RtlFreeUnicodeString(&UnicodeString);
  560. BaseSetLastNTError(STATUS_NO_MEMORY);
  561. return 0;
  562. }
  563. if(!NtCurrentTeb()->Vdm) {
  564. fSysCall = TRUE;
  565. }
  566. if(fSysCall) {
  567. UnicodeLength = RtlGetFullPathName_U(
  568. UnicodeString.Buffer,
  569. (MAX_PATH<<1),
  570. Ubuff,
  571. FilePartPtr
  572. );
  573. }
  574. else {
  575. UnicodeLength = DPM_RtlGetFullPathName_U(
  576. UnicodeString.Buffer,
  577. (MAX_PATH<<1),
  578. Ubuff,
  579. FilePartPtr
  580. );
  581. }
  582. #ifdef FE_SB
  583. // BugFix: can't listed with file open dialog of MS's app 1995.3.7 V-HIDEKK
  584. RtlInitUnicodeString( &UnicodeFilePart, Ubuff );
  585. UnicodeLength = RtlUnicodeStringToOemSize( &UnicodeFilePart );
  586. #else
  587. UnicodeLength >>= 1;
  588. #endif
  589. if ( UnicodeLength && UnicodeLength < nBufferLength ) {
  590. RtlInitUnicodeString(&UnicodeResult,Ubuff);
  591. Status = RtlUnicodeStringToOemString(&OemResult,&UnicodeResult,TRUE);
  592. if ( NT_SUCCESS(Status) ) {
  593. #ifdef FE_SB
  594. RtlMoveMemory(lpBuffer,OemResult.Buffer,UnicodeLength);
  595. #else
  596. RtlMoveMemory(lpBuffer,OemResult.Buffer,UnicodeLength+1);
  597. #endif
  598. RtlFreeOemString(&OemResult);
  599. if ( ARGUMENT_PRESENT(lpFilePart) ) {
  600. if ( FilePart == NULL ) {
  601. *lpFilePart = NULL;
  602. }
  603. else {
  604. #ifdef FE_SB
  605. RtlInitUnicodeString(&UnicodeFilePart,FilePart);
  606. FilePartLength = RtlUnicodeStringToOemSize( &UnicodeFilePart );
  607. *lpFilePart = (PSZ)(UnicodeLength - FilePartLength);
  608. #else
  609. *lpFilePart = (PSZ)(FilePart - Ubuff);
  610. #endif
  611. *lpFilePart = *lpFilePart + (ULONG)lpBuffer;
  612. }
  613. }
  614. }
  615. else {
  616. BaseSetLastNTError(Status);
  617. UnicodeLength = 0;
  618. }
  619. }
  620. else {
  621. if ( UnicodeLength ) {
  622. UnicodeLength++;
  623. }
  624. }
  625. RtlFreeUnicodeString(&UnicodeString);
  626. RtlFreeHeap(RtlProcessHeap(), 0,Ubuff);
  627. return (DWORD)UnicodeLength;
  628. }
  629. DWORD
  630. APIENTRY
  631. GetCurrentDirectoryOem(
  632. DWORD nBufferLength,
  633. LPSTR lpBuffer
  634. )
  635. /*++
  636. Routine Description:
  637. Oem thunk to GetCurrentDirectoryW
  638. --*/
  639. {
  640. PUNICODE_STRING Unicode;
  641. OEM_STRING OemString;
  642. NTSTATUS Status;
  643. DWORD ReturnValue;
  644. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  645. if(NtCurrentTeb()->Vdm) {
  646. Unicode->Length = (USHORT)DPM_RtlGetCurrentDirectory_U(
  647. Unicode->MaximumLength,
  648. Unicode->Buffer
  649. );
  650. } else {
  651. Unicode->Length = (USHORT)RtlGetCurrentDirectory_U(
  652. Unicode->MaximumLength,
  653. Unicode->Buffer
  654. );
  655. }
  656. #ifdef FE_SB
  657. ReturnValue = RtlUnicodeStringToOemSize( Unicode );
  658. if ( nBufferLength > ReturnValue-1 ) {
  659. #else
  660. if ( nBufferLength > (DWORD)(Unicode->Length>>1) ) {
  661. #endif
  662. OemString.Buffer = lpBuffer;
  663. OemString.MaximumLength = (USHORT)(nBufferLength+1);
  664. Status = RtlUnicodeStringToOemString(&OemString,Unicode,FALSE);
  665. if ( !NT_SUCCESS(Status) ) {
  666. BaseSetLastNTError(Status);
  667. ReturnValue = 0;
  668. }
  669. else {
  670. ReturnValue = OemString.Length;
  671. }
  672. }
  673. #ifndef FE_SB
  674. else {
  675. ReturnValue = ((Unicode->Length)>>1)+1;
  676. }
  677. #endif
  678. return ReturnValue;
  679. }
  680. BOOL
  681. APIENTRY
  682. SetCurrentDirectoryOem(
  683. LPSTR lpPathName
  684. )
  685. /*++
  686. Routine Description:
  687. Oem thunk to SetCurrentDirectoryW
  688. --*/
  689. {
  690. PUNICODE_STRING Unicode;
  691. OEM_STRING OemString;
  692. NTSTATUS Status;
  693. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  694. InitOemString(&OemString,lpPathName);
  695. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  696. if ( !NT_SUCCESS(Status) ) {
  697. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  698. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  699. }
  700. else {
  701. BaseSetLastNTError(Status);
  702. }
  703. return FALSE;
  704. }
  705. if (!CheckForSameCurdir(Unicode)) {
  706. if(NtCurrentTeb()->Vdm) {
  707. Status = DPM_RtlSetCurrentDirectory_U(Unicode);
  708. } else {
  709. Status = RtlSetCurrentDirectory_U(Unicode);
  710. }
  711. if ( !NT_SUCCESS(Status) ) {
  712. BaseSetLastNTError(Status);
  713. return FALSE;
  714. }
  715. }
  716. return TRUE;
  717. }
  718. BOOL
  719. APIENTRY
  720. CreateDirectoryOem(
  721. LPSTR lpPathName,
  722. LPSECURITY_ATTRIBUTES lpSecurityAttributes
  723. )
  724. /*++
  725. Routine Description:
  726. Oem thunk to CreateDirectoryW
  727. --*/
  728. {
  729. PUNICODE_STRING Unicode;
  730. OEM_STRING OemString;
  731. NTSTATUS Status;
  732. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  733. InitOemString(&OemString,lpPathName);
  734. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  735. if ( !NT_SUCCESS(Status) ) {
  736. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  737. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  738. }
  739. else {
  740. BaseSetLastNTError(Status);
  741. }
  742. return FALSE;
  743. }
  744. if(NtCurrentTeb()->Vdm) {
  745. return ( DPM_CreateDirectoryW(Unicode->Buffer,lpSecurityAttributes) );
  746. } else {
  747. return ( CreateDirectoryW(Unicode->Buffer,lpSecurityAttributes) );
  748. }
  749. }
  750. BOOL
  751. APIENTRY
  752. RemoveDirectoryOem(
  753. LPSTR lpPathName
  754. )
  755. /*++
  756. Routine Description:
  757. Oem thunk to RemoveDirectoryW
  758. --*/
  759. {
  760. PUNICODE_STRING Unicode;
  761. OEM_STRING OemString;
  762. NTSTATUS Status;
  763. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  764. InitOemString(&OemString,lpPathName);
  765. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  766. if ( !NT_SUCCESS(Status) ) {
  767. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  768. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  769. }
  770. else {
  771. BaseSetLastNTError(Status);
  772. }
  773. return FALSE;
  774. }
  775. if(NtCurrentTeb()->Vdm) {
  776. return ( DPM_RemoveDirectoryW(Unicode->Buffer) );
  777. } else {
  778. return ( RemoveDirectoryW(Unicode->Buffer) );
  779. }
  780. }
  781. UINT
  782. APIENTRY
  783. GetDriveTypeOem(
  784. LPSTR lpRootPathName
  785. )
  786. /*++
  787. Routine Description:
  788. OEM thunk to GetDriveTypeW
  789. --*/
  790. {
  791. PUNICODE_STRING Unicode;
  792. OEM_STRING OemString;
  793. NTSTATUS Status;
  794. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  795. InitOemString(
  796. &OemString,
  797. ARGUMENT_PRESENT(lpRootPathName) ? lpRootPathName : "\\"
  798. );
  799. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  800. if ( !NT_SUCCESS(Status) ) {
  801. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  802. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  803. }
  804. else {
  805. BaseSetLastNTError(Status);
  806. }
  807. return 1;
  808. }
  809. if(NtCurrentTeb()->Vdm) {
  810. return (DPM_GetDriveTypeW(Unicode->Buffer));
  811. } else {
  812. return (GetDriveTypeW(Unicode->Buffer));
  813. }
  814. }
  815. BOOL
  816. APIENTRY
  817. GetDiskFreeSpaceOem(
  818. LPSTR lpRootPathName,
  819. LPDWORD lpSectorsPerCluster,
  820. LPDWORD lpBytesPerSector,
  821. LPDWORD lpNumberOfFreeClusters,
  822. LPDWORD lpTotalNumberOfClusters
  823. )
  824. /*++
  825. Routine Description:
  826. Oem thunk to GetDiskFreeSpaceW
  827. --*/
  828. {
  829. PUNICODE_STRING Unicode;
  830. OEM_STRING OemString;
  831. NTSTATUS Status;
  832. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  833. InitOemString(
  834. &OemString,
  835. ARGUMENT_PRESENT(lpRootPathName) ? lpRootPathName : "\\"
  836. );
  837. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  838. if ( !NT_SUCCESS(Status) ) {
  839. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  840. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  841. }
  842. else {
  843. BaseSetLastNTError(Status);
  844. }
  845. return FALSE;
  846. }
  847. if(NtCurrentTeb()->Vdm) {
  848. return ( DPM_GetDiskFreeSpaceW(
  849. Unicode->Buffer,
  850. lpSectorsPerCluster,
  851. lpBytesPerSector,
  852. lpNumberOfFreeClusters,
  853. lpTotalNumberOfClusters
  854. )
  855. );
  856. } else {
  857. return ( GetDiskFreeSpaceW(
  858. Unicode->Buffer,
  859. lpSectorsPerCluster,
  860. lpBytesPerSector,
  861. lpNumberOfFreeClusters,
  862. lpTotalNumberOfClusters
  863. )
  864. );
  865. }
  866. }
  867. BOOL
  868. APIENTRY
  869. GetVolumeInformationOem(
  870. LPSTR lpRootPathName,
  871. LPSTR lpVolumeNameBuffer,
  872. DWORD nVolumeNameSize,
  873. LPDWORD lpVolumeSerialNumber,
  874. LPDWORD lpMaximumComponentLength,
  875. LPDWORD lpFileSystemFlags,
  876. LPSTR lpFileSystemNameBuffer,
  877. DWORD nFileSystemNameSize
  878. )
  879. /*++
  880. Routine Description:
  881. Oem thunk to GetVolumeInformationW
  882. --*/
  883. {
  884. PUNICODE_STRING Unicode;
  885. OEM_STRING OemString;
  886. NTSTATUS Status;
  887. UNICODE_STRING UnicodeVolumeName;
  888. UNICODE_STRING UnicodeFileSystemName;
  889. OEM_STRING OemVolumeName;
  890. OEM_STRING OemFileSystemName;
  891. BOOL ReturnValue;
  892. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  893. InitOemString(
  894. &OemString,
  895. ARGUMENT_PRESENT(lpRootPathName) ? lpRootPathName : "\\"
  896. );
  897. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  898. if ( !NT_SUCCESS(Status) ) {
  899. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  900. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  901. }
  902. else {
  903. BaseSetLastNTError(Status);
  904. }
  905. return FALSE;
  906. }
  907. UnicodeVolumeName.Buffer = NULL;
  908. UnicodeFileSystemName.Buffer = NULL;
  909. UnicodeVolumeName.MaximumLength = 0;
  910. UnicodeFileSystemName.MaximumLength = 0;
  911. OemVolumeName.Buffer = lpVolumeNameBuffer;
  912. OemVolumeName.MaximumLength = (USHORT)(nVolumeNameSize+1);
  913. OemFileSystemName.Buffer = lpFileSystemNameBuffer;
  914. OemFileSystemName.MaximumLength = (USHORT)(nFileSystemNameSize+1);
  915. try {
  916. if ( ARGUMENT_PRESENT(lpVolumeNameBuffer) ) {
  917. UnicodeVolumeName.MaximumLength = OemVolumeName.MaximumLength << 1;
  918. UnicodeVolumeName.Buffer = RtlAllocateHeap(
  919. RtlProcessHeap(), 0,
  920. UnicodeVolumeName.MaximumLength
  921. );
  922. if ( !UnicodeVolumeName.Buffer ) {
  923. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  924. return FALSE;
  925. }
  926. }
  927. if ( ARGUMENT_PRESENT(lpFileSystemNameBuffer) ) {
  928. UnicodeFileSystemName.MaximumLength = OemFileSystemName.MaximumLength << 1;
  929. UnicodeFileSystemName.Buffer = RtlAllocateHeap(
  930. RtlProcessHeap(), 0,
  931. UnicodeFileSystemName.MaximumLength
  932. );
  933. if ( !UnicodeFileSystemName.Buffer ) {
  934. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  935. return FALSE;
  936. }
  937. }
  938. ReturnValue = GetVolumeInformationW(
  939. Unicode->Buffer,
  940. UnicodeVolumeName.Buffer,
  941. nVolumeNameSize,
  942. lpVolumeSerialNumber,
  943. lpMaximumComponentLength,
  944. lpFileSystemFlags,
  945. UnicodeFileSystemName.Buffer,
  946. nFileSystemNameSize
  947. );
  948. if ( ReturnValue ) {
  949. if ( ARGUMENT_PRESENT(lpVolumeNameBuffer) ) {
  950. RtlInitUnicodeString(
  951. &UnicodeVolumeName,
  952. UnicodeVolumeName.Buffer
  953. );
  954. Status = RtlUnicodeStringToOemString(
  955. &OemVolumeName,
  956. &UnicodeVolumeName,
  957. FALSE
  958. );
  959. if ( !NT_SUCCESS(Status) ) {
  960. BaseSetLastNTError(Status);
  961. return FALSE;
  962. }
  963. }
  964. if ( ARGUMENT_PRESENT(lpFileSystemNameBuffer) ) {
  965. RtlInitUnicodeString(
  966. &UnicodeFileSystemName,
  967. UnicodeFileSystemName.Buffer
  968. );
  969. Status = RtlUnicodeStringToOemString(
  970. &OemFileSystemName,
  971. &UnicodeFileSystemName,
  972. FALSE
  973. );
  974. if ( !NT_SUCCESS(Status) ) {
  975. BaseSetLastNTError(Status);
  976. return FALSE;
  977. }
  978. }
  979. }
  980. }
  981. finally {
  982. if ( UnicodeVolumeName.Buffer ) {
  983. RtlFreeHeap(RtlProcessHeap(), 0,UnicodeVolumeName.Buffer);
  984. }
  985. if ( UnicodeFileSystemName.Buffer ) {
  986. RtlFreeHeap(RtlProcessHeap(), 0,UnicodeFileSystemName.Buffer);
  987. }
  988. }
  989. return ReturnValue;
  990. }
  991. VOID
  992. APIENTRY
  993. OutputDebugStringOem(
  994. LPCSTR lpOutputString
  995. )
  996. /*++
  997. Routine Description:
  998. OEM thunk to OutputDebugStringA
  999. --*/
  1000. {
  1001. UNICODE_STRING Unicode;
  1002. OEM_STRING OemString;
  1003. ANSI_STRING AnsiString;
  1004. NTSTATUS Status;
  1005. Unicode.Buffer = NULL;
  1006. AnsiString.Buffer = NULL;
  1007. try {
  1008. InitOemString(&OemString, lpOutputString);
  1009. Status = RtlOemStringToUnicodeString(&Unicode, &OemString, TRUE);
  1010. if ( !NT_SUCCESS(Status) ) {
  1011. goto try_exit;
  1012. }
  1013. Status = RtlUnicodeStringToAnsiString(&AnsiString,&Unicode,TRUE);
  1014. if ( !NT_SUCCESS(Status) ) {
  1015. goto try_exit;
  1016. }
  1017. OutputDebugStringA(AnsiString.Buffer);
  1018. try_exit:;
  1019. }
  1020. finally {
  1021. if (Unicode.Buffer != NULL) {
  1022. RtlFreeUnicodeString( &Unicode );
  1023. }
  1024. if (AnsiString.Buffer != NULL) {
  1025. RtlFreeAnsiString( &AnsiString);
  1026. }
  1027. }
  1028. }
  1029. BOOL
  1030. APIENTRY
  1031. GetComputerNameOem(
  1032. LPSTR lpBuffer,
  1033. LPDWORD nSize
  1034. )
  1035. /*++
  1036. Routine Description:
  1037. Oem thunk to GetComputerNameW
  1038. --*/
  1039. {
  1040. UNICODE_STRING UnicodeString;
  1041. OEM_STRING OemString;
  1042. LPWSTR UnicodeBuffer;
  1043. //
  1044. // Work buffer needs to be twice the size of the user's buffer
  1045. //
  1046. UnicodeBuffer = RtlAllocateHeap(RtlProcessHeap(), 0, *nSize * sizeof(WCHAR));
  1047. if (!UnicodeBuffer) {
  1048. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1049. return(FALSE);
  1050. }
  1051. //
  1052. // Set up an ANSI_STRING that points to the user's buffer
  1053. //
  1054. OemString.MaximumLength = (USHORT) *nSize;
  1055. OemString.Length = 0;
  1056. OemString.Buffer = lpBuffer;
  1057. //
  1058. // Call the UNICODE version to do the work
  1059. //
  1060. if (!GetComputerNameW(UnicodeBuffer, nSize)) {
  1061. RtlFreeHeap(RtlProcessHeap(), 0, UnicodeBuffer);
  1062. return(FALSE);
  1063. }
  1064. //
  1065. // Now convert back to Oem for the caller
  1066. //
  1067. RtlInitUnicodeString(&UnicodeString, UnicodeBuffer);
  1068. RtlUnicodeStringToOemString(&OemString, &UnicodeString, FALSE);
  1069. *nSize = OemString.Length;
  1070. RtlFreeHeap(RtlProcessHeap(), 0, UnicodeBuffer);
  1071. return(TRUE);
  1072. }
  1073. BOOL
  1074. WINAPI
  1075. RemoveFontResourceOem(
  1076. LPSTR lpFileName
  1077. )
  1078. /*++
  1079. Routine Description:
  1080. Oem thunk to RemoveFontResourceW
  1081. --*/
  1082. {
  1083. PUNICODE_STRING Unicode;
  1084. OEM_STRING OemString;
  1085. NTSTATUS Status;
  1086. Unicode = &NtCurrentTeb()->StaticUnicodeString;
  1087. InitOemString(&OemString,lpFileName);
  1088. Status = RtlOemStringToUnicodeString(Unicode,&OemString,FALSE);
  1089. if ( !NT_SUCCESS(Status) ) {
  1090. if ( Status == STATUS_BUFFER_OVERFLOW ) {
  1091. SetLastError(ERROR_FILENAME_EXCED_RANGE);
  1092. }
  1093. else {
  1094. BaseSetLastNTError(Status);
  1095. }
  1096. return FALSE;
  1097. }
  1098. return ( RemoveFontResourceW(Unicode->Buffer) );
  1099. }