Source code of Windows XP (NT5)
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.

1401 lines
42 KiB

  1. #include "brian.h"
  2. typedef struct _ASYNC_OPEN {
  3. ACCESS_MASK DesiredAccess;
  4. PLARGE_INTEGER AllocationSizePtr;
  5. LARGE_INTEGER AllocationSize;
  6. ULONG FileAttributes;
  7. ULONG ShareAccess;
  8. ULONG CreateDisposition;
  9. ULONG CreateOptions;
  10. PVOID EaBuffer;
  11. ULONG EaLength;
  12. STRING ObjectName;
  13. PUSHORT RootDirIndexPtr;
  14. USHORT RootDirIndex;
  15. ULONG Attributes;
  16. PSECURITY_DESCRIPTOR SecurityDescriptor;
  17. PSECURITY_QUALITY_OF_SERVICE SecurityQualityOfService;
  18. BOOLEAN DisplayParameters;
  19. BOOLEAN VerboseResults;
  20. BOOLEAN AnsiName;
  21. USHORT AsyncIndex;
  22. USHORT NameIndex;
  23. } ASYNC_OPEN, *PASYNC_OPEN;
  24. #define DESIRED_ACCESS_DEFAULT (SYNCHRONIZE | GENERIC_READ)
  25. #define ALLOCATION_SIZE_DEFAULT 0L
  26. #define FILE_ATTRIBUTES_DEFAULT FILE_ATTRIBUTE_NORMAL
  27. #define SHARE_ACCESS_DEFAULT FILE_SHARE_READ
  28. #define CREATE_DISP_DEFAULT FILE_OPEN
  29. #define CREATE_OPTIONS_DEFAULT FILE_SYNCHRONOUS_IO_ALERT
  30. #define EA_LENGTH_DEFAULT 0L
  31. #define ATTRIBUTES_DEFAULT OBJ_CASE_INSENSITIVE
  32. #define DISPLAY_PARMS_DEFAULT FALSE
  33. #define VERBOSE_RESULTS_DEFAULT TRUE
  34. #define ANSI_NAME_DEFAULT FALSE
  35. #define EXACT_NAME_DEFAULT FALSE
  36. VOID
  37. FullOpen (
  38. IN PASYNC_OPEN AsyncOpen
  39. );
  40. VOID
  41. InputOpenFile (
  42. IN PCHAR ParamBuffer
  43. )
  44. {
  45. ACCESS_MASK DesiredAccess;
  46. LARGE_INTEGER AllocationSize;
  47. PLARGE_INTEGER AllocationSizePtr;
  48. ULONG FileAttributes;
  49. ULONG ShareAccess;
  50. ULONG CreateDisposition;
  51. ULONG CreateOptions;
  52. PVOID EaBuffer;
  53. USHORT BufferIndex;
  54. ULONG EaLength;
  55. STRING ObjectName;
  56. USHORT NameIndex;
  57. PUSHORT RootDirIndexPtr;
  58. USHORT RootDirIndex;
  59. ULONG Attributes;
  60. PSECURITY_DESCRIPTOR SecurityDescriptor;
  61. PSECURITY_QUALITY_OF_SERVICE SecurityQualityOfService;
  62. BOOLEAN DisplayParameters;
  63. BOOLEAN VerboseResults;
  64. BOOLEAN AnsiName;
  65. BOOLEAN ExactName;
  66. BOOLEAN FileNameFound;
  67. BOOLEAN LastInput;
  68. BOOLEAN NameIndexAllocated;
  69. PUCHAR FileName;
  70. USHORT AsyncIndex;
  71. //
  72. // Set the defaults for the open and the return values.
  73. //
  74. DesiredAccess = DESIRED_ACCESS_DEFAULT;
  75. AllocationSize = RtlConvertUlongToLargeInteger( ALLOCATION_SIZE_DEFAULT );
  76. AllocationSizePtr = NULL;
  77. FileAttributes = FILE_ATTRIBUTES_DEFAULT;
  78. ShareAccess = SHARE_ACCESS_DEFAULT;
  79. CreateDisposition = CREATE_DISP_DEFAULT;
  80. CreateOptions = CREATE_OPTIONS_DEFAULT;
  81. EaBuffer = NULL;
  82. EaLength = EA_LENGTH_DEFAULT;
  83. ObjectName.MaximumLength = 256;
  84. ObjectName.Length = 256;
  85. RootDirIndexPtr = NULL;
  86. RootDirIndex = 0;
  87. Attributes = ATTRIBUTES_DEFAULT;
  88. SecurityDescriptor = NULL;
  89. SecurityQualityOfService = NULL;
  90. DisplayParameters = DISPLAY_PARMS_DEFAULT;
  91. VerboseResults = VERBOSE_RESULTS_DEFAULT;
  92. AnsiName = ANSI_NAME_DEFAULT;
  93. ExactName = EXACT_NAME_DEFAULT;
  94. NameIndexAllocated = FALSE;
  95. FileNameFound = FALSE;
  96. LastInput = TRUE;
  97. {
  98. NTSTATUS Status;
  99. SIZE_T RegionSize;
  100. ULONG TempIndex;
  101. RegionSize = 1024;
  102. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  103. if (!NT_SUCCESS( Status )) {
  104. printf("InputOpenFile: Can't allocate name index buffer\n" );
  105. return;
  106. }
  107. NameIndexAllocated = TRUE;
  108. NameIndex = (USHORT) TempIndex;
  109. ObjectName.Buffer = Buffers[NameIndex].Buffer;
  110. }
  111. //
  112. // While there is more input, analyze the parameter and update the
  113. // open flags.
  114. //
  115. while (TRUE) {
  116. ULONG DummyCount;
  117. //
  118. // Swallow leading white spaces.
  119. //
  120. ParamBuffer = SwallowWhite( ParamBuffer, &DummyCount );
  121. if (*ParamBuffer) {
  122. //
  123. // If the next parameter is legal then check the paramter value.
  124. // Update the parameter value.
  125. //
  126. if((*ParamBuffer == '-'
  127. || *ParamBuffer == '/')
  128. && (ParamBuffer++, *ParamBuffer != '\0')) {
  129. BOOLEAN SwitchBool;
  130. //
  131. // Switch on the next character.
  132. //
  133. switch (*ParamBuffer) {
  134. //
  135. // Update the file attributes.
  136. //
  137. case 'a' :
  138. case 'A' :
  139. //
  140. // Move to the next character, as long as there
  141. // are no white spaces continue analyzing letters.
  142. // On the first bad letter, skip to the next
  143. // parameter.
  144. //
  145. ParamBuffer++;
  146. SwitchBool = TRUE;
  147. while (*ParamBuffer
  148. && *ParamBuffer != ' '
  149. && *ParamBuffer != '\t') {
  150. //
  151. // Perform switch on character.
  152. //
  153. switch (*ParamBuffer) {
  154. case 'a' :
  155. case 'A' :
  156. FileAttributes |= FILE_ATTRIBUTE_READONLY;
  157. break;
  158. case 'b' :
  159. case 'B' :
  160. FileAttributes |= FILE_ATTRIBUTE_HIDDEN;
  161. break;
  162. case 'c' :
  163. case 'C' :
  164. FileAttributes |= FILE_ATTRIBUTE_SYSTEM;
  165. break;
  166. case 'e' :
  167. case 'E' :
  168. FileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
  169. break;
  170. case 'f' :
  171. case 'F' :
  172. FileAttributes |= FILE_ATTRIBUTE_ARCHIVE;
  173. break;
  174. case 'g' :
  175. case 'G' :
  176. FileAttributes |= FILE_ATTRIBUTE_ENCRYPTED;
  177. break;
  178. case 'h' :
  179. case 'H' :
  180. FileAttributes |= FILE_ATTRIBUTE_NORMAL;
  181. break;
  182. case 'i' :
  183. case 'I' :
  184. FileAttributes |= FILE_ATTRIBUTE_TEMPORARY;
  185. break;
  186. case 'j' :
  187. case 'J' :
  188. FileAttributes |= FILE_ATTRIBUTE_SPARSE_FILE;
  189. break;
  190. case 'k' :
  191. case 'K' :
  192. FileAttributes |= FILE_ATTRIBUTE_REPARSE_POINT;
  193. break;
  194. case 'l' :
  195. case 'L' :
  196. FileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
  197. break;
  198. case 'm' :
  199. case 'M' :
  200. FileAttributes |= FILE_ATTRIBUTE_OFFLINE;
  201. break;
  202. case 'n' :
  203. case 'N' :
  204. FileAttributes |= FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
  205. break;
  206. case 'z' :
  207. case 'Z' :
  208. FileAttributes = 0;
  209. break;
  210. default :
  211. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  212. SwitchBool = FALSE;
  213. }
  214. if (!SwitchBool) {
  215. break;
  216. }
  217. ParamBuffer++;
  218. }
  219. break;
  220. //
  221. // Update buffer to use.
  222. //
  223. case 'b' :
  224. case 'B' :
  225. //
  226. // Move to the next character, as long as there
  227. // are no white spaces continue analyzing letters.
  228. // On the first bad letter, skip to the next
  229. // parameter.
  230. //
  231. ParamBuffer++;
  232. BufferIndex = (USHORT) AsciiToInteger( ParamBuffer );
  233. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  234. if (BufferIndex <= MAX_BUFFERS) {
  235. EaBuffer = Buffers[BufferIndex].Buffer;
  236. EaLength = Buffers[BufferIndex].Length;
  237. }
  238. break;
  239. //
  240. // Update buffer length to pass.
  241. //
  242. case 'l' :
  243. case 'L' :
  244. //
  245. // Move to the next character, as long as there
  246. // are no white spaces continue analyzing letters.
  247. // On the first bad letter, skip to the next
  248. // parameter.
  249. //
  250. ParamBuffer++;
  251. EaLength = AsciiToInteger( ParamBuffer );
  252. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  253. break;
  254. //
  255. // Update the desired access.
  256. //
  257. case 'd' :
  258. case 'D' :
  259. //
  260. // Move to the next character, as long as there
  261. // are no white spaces continue analyzing letters.
  262. // On the first bad letter, skip to the next
  263. // parameter.
  264. //
  265. ParamBuffer++;
  266. SwitchBool = TRUE;
  267. while (*ParamBuffer
  268. && *ParamBuffer != ' '
  269. && *ParamBuffer != '\t') {
  270. //
  271. // Perform switch on character.
  272. //
  273. switch (*ParamBuffer) {
  274. case 'a' :
  275. case 'A' :
  276. DesiredAccess |= FILE_READ_DATA;
  277. break;
  278. case 'b' :
  279. case 'B' :
  280. DesiredAccess |= FILE_WRITE_DATA;
  281. break;
  282. case 'c' :
  283. case 'C' :
  284. DesiredAccess |= FILE_APPEND_DATA;
  285. break;
  286. case 'd' :
  287. case 'D' :
  288. DesiredAccess |= FILE_READ_EA;
  289. break;
  290. case 'e' :
  291. case 'E' :
  292. DesiredAccess |= FILE_WRITE_EA;
  293. break;
  294. case 'f' :
  295. case 'F' :
  296. DesiredAccess |= FILE_EXECUTE;
  297. break;
  298. case 'g' :
  299. case 'G' :
  300. DesiredAccess |= FILE_DELETE_CHILD;
  301. break;
  302. case 'h' :
  303. case 'H' :
  304. DesiredAccess |= FILE_READ_ATTRIBUTES;
  305. break;
  306. case 'i' :
  307. case 'I' :
  308. DesiredAccess |= FILE_WRITE_ATTRIBUTES;
  309. break;
  310. case 'j' :
  311. case 'J' :
  312. DesiredAccess |= FILE_ALL_ACCESS;
  313. break;
  314. case 'k' :
  315. case 'K' :
  316. DesiredAccess |= SYNCHRONIZE;
  317. break;
  318. case 'l' :
  319. case 'L' :
  320. DesiredAccess |= DELETE;
  321. break;
  322. case 'm' :
  323. case 'M' :
  324. DesiredAccess |= READ_CONTROL;
  325. break;
  326. case 'n' :
  327. case 'N' :
  328. DesiredAccess |= WRITE_DAC;
  329. break;
  330. case 'o' :
  331. case 'O' :
  332. DesiredAccess |= WRITE_OWNER;
  333. break;
  334. case 'p' :
  335. case 'P' :
  336. DesiredAccess |= GENERIC_READ;
  337. break;
  338. case 'q' :
  339. case 'Q' :
  340. DesiredAccess |= GENERIC_WRITE;
  341. break;
  342. case 'r' :
  343. case 'R' :
  344. DesiredAccess |= GENERIC_EXECUTE;
  345. break;
  346. case 's' :
  347. case 'S' :
  348. DesiredAccess |= GENERIC_ALL;
  349. break;
  350. case 't' :
  351. DesiredAccess |= MAXIMUM_ALLOWED;
  352. break;
  353. case 'z' :
  354. case 'Z' :
  355. DesiredAccess = 0;
  356. break;
  357. default :
  358. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  359. SwitchBool = FALSE;
  360. }
  361. if (!SwitchBool) {
  362. break;
  363. }
  364. ParamBuffer++;
  365. }
  366. break;
  367. //
  368. // Get the filename.
  369. //
  370. case 'f' :
  371. case 'F' :
  372. //
  373. // Remember the buffer offset and get the filename.
  374. //
  375. ParamBuffer++;
  376. FileName = ParamBuffer;
  377. DummyCount = 0;
  378. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  379. //
  380. // If the name length is 0, then ignore this entry.
  381. //
  382. if (DummyCount) {
  383. ULONG ObjectNameIncrement = 0;
  384. //
  385. // If the first character is a backslash then
  386. // we add the full 'dosdevices' prefix.
  387. //
  388. FileNameFound = TRUE;
  389. if (!ExactName) {
  390. if (*FileName == '\\') {
  391. ObjectNameIncrement = sizeof( "DosDevices" );
  392. RtlMoveMemory( ObjectName.Buffer,
  393. "\\DosDevices",
  394. sizeof( "\\DosDevices" ));
  395. }
  396. }
  397. ObjectName.Length = (SHORT) (DummyCount + ObjectNameIncrement);
  398. RtlMoveMemory( &ObjectName.Buffer[ObjectNameIncrement],
  399. FileName,
  400. DummyCount );
  401. } else {
  402. ULONG ObjectNameIncrement = 0;
  403. FileNameFound = TRUE;
  404. ObjectName.Length = (SHORT) (DummyCount + ObjectNameIncrement);
  405. }
  406. break;
  407. //
  408. // Update the file Id.
  409. //
  410. case 'i' :
  411. case 'I' :
  412. {
  413. PLARGE_INTEGER FileId;
  414. FileId = (PLARGE_INTEGER) ObjectName.Buffer;
  415. //
  416. // Move to the next character, as long as there
  417. // are no white spaces continue analyzing letters.
  418. // On the first bad letter, skip to the next
  419. // parameter.
  420. //
  421. ParamBuffer++;
  422. if (*ParamBuffer == '\0') {
  423. break;
  424. }
  425. switch (*ParamBuffer) {
  426. case 'l':
  427. case 'L':
  428. FileId->LowPart = AsciiToInteger( ++ParamBuffer );
  429. ObjectName.Length = sizeof( LARGE_INTEGER );
  430. break;
  431. case 'h':
  432. case 'H':
  433. FileId->HighPart = AsciiToInteger( ++ParamBuffer );
  434. ObjectName.Length = sizeof( LARGE_INTEGER );
  435. break;
  436. }
  437. FileNameFound = TRUE;
  438. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  439. break;
  440. }
  441. //
  442. // Update the share access field.
  443. //
  444. case 'h' :
  445. case 'H' :
  446. //
  447. // Move to the next character, as long as there
  448. // are no white spaces continue analyzing letters.
  449. // On the first bad letter, skip to the next
  450. // parameter.
  451. //
  452. ParamBuffer++;
  453. SwitchBool = TRUE;
  454. while (*ParamBuffer
  455. && *ParamBuffer != ' '
  456. && *ParamBuffer != '\t') {
  457. //
  458. // Perform switch on character.
  459. //
  460. switch (*ParamBuffer) {
  461. case 'a' :
  462. case 'A' :
  463. ShareAccess |= FILE_SHARE_READ;
  464. break;
  465. case 'b' :
  466. case 'B' :
  467. ShareAccess |= FILE_SHARE_WRITE;
  468. break;
  469. case 'c' :
  470. case 'C' :
  471. ShareAccess |= FILE_SHARE_DELETE;
  472. break;
  473. case 'z' :
  474. case 'Z' :
  475. ShareAccess = 0;
  476. break;
  477. default :
  478. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  479. SwitchBool = FALSE;
  480. }
  481. if (!SwitchBool) {
  482. break;
  483. }
  484. ParamBuffer++;
  485. }
  486. break;
  487. //
  488. // Update the create options.
  489. //
  490. case 'n' :
  491. case 'N' :
  492. //
  493. // Move to the next character, as long as there
  494. // are no white spaces continue analyzing letters.
  495. // On the first bad letter, skip to the next
  496. // parameter.
  497. //
  498. ParamBuffer++;
  499. SwitchBool = TRUE;
  500. while (*ParamBuffer
  501. && *ParamBuffer != ' '
  502. && *ParamBuffer != '\t') {
  503. //
  504. // Perform switch on character.
  505. //
  506. switch( *ParamBuffer ) {
  507. case 'a' :
  508. case 'A' :
  509. CreateOptions |= FILE_DIRECTORY_FILE;
  510. break;
  511. case 'b' :
  512. case 'B' :
  513. CreateOptions |= FILE_WRITE_THROUGH;
  514. break;
  515. case 'c' :
  516. case 'C' :
  517. CreateOptions |= FILE_SEQUENTIAL_ONLY;
  518. break;
  519. case 'd' :
  520. case 'D' :
  521. CreateOptions |= FILE_NO_INTERMEDIATE_BUFFERING;
  522. break;
  523. case 'e' :
  524. case 'E' :
  525. CreateOptions |= FILE_SYNCHRONOUS_IO_ALERT;
  526. break;
  527. case 'f' :
  528. case 'F' :
  529. CreateOptions |= FILE_SYNCHRONOUS_IO_NONALERT;
  530. break;
  531. case 'g' :
  532. case 'G' :
  533. CreateOptions |= FILE_NON_DIRECTORY_FILE;
  534. break;
  535. case 'h' :
  536. case 'H' :
  537. CreateOptions |= FILE_CREATE_TREE_CONNECTION;
  538. break;
  539. case 'i' :
  540. case 'I' :
  541. CreateOptions |= FILE_COMPLETE_IF_OPLOCKED;
  542. break;
  543. case 'j' :
  544. case 'J' :
  545. CreateOptions |= FILE_OPEN_BY_FILE_ID;
  546. break;
  547. case 'k' :
  548. case 'K' :
  549. CreateOptions |= FILE_NO_EA_KNOWLEDGE;
  550. break;
  551. case 'l' :
  552. case 'L' :
  553. CreateOptions |= FILE_DELETE_ON_CLOSE;
  554. break;
  555. case 'm' :
  556. case 'M' :
  557. CreateOptions |= FILE_RESERVE_OPFILTER;
  558. break;
  559. case 'n' :
  560. case 'N' :
  561. CreateOptions |= FILE_OPEN_REPARSE_POINT;
  562. break;
  563. case 'o' :
  564. case 'O' :
  565. CreateOptions |= FILE_NO_COMPRESSION;
  566. break;
  567. case 'p' :
  568. case 'P' :
  569. CreateOptions |= FILE_OPEN_FOR_BACKUP_INTENT;
  570. break;
  571. case 'z' :
  572. case 'Z' :
  573. CreateOptions = 0;
  574. break;
  575. default :
  576. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  577. SwitchBool = FALSE;
  578. }
  579. if (!SwitchBool) {
  580. break;
  581. }
  582. ParamBuffer++;
  583. }
  584. break;
  585. case 'o' :
  586. case 'O' :
  587. //
  588. // Move to the next character, as long as there
  589. // are no white spaces continue analyzing letters.
  590. // On the first bad letter, skip to the next
  591. // parameter.
  592. //
  593. ParamBuffer++;
  594. SwitchBool = TRUE;
  595. while (*ParamBuffer
  596. && *ParamBuffer != ' '
  597. && *ParamBuffer != '\t') {
  598. //
  599. // Perform switch on character.
  600. //
  601. switch (*ParamBuffer) {
  602. case 'a' :
  603. case 'A' :
  604. Attributes |= OBJ_INHERIT;
  605. break;
  606. case 'b' :
  607. case 'B' :
  608. Attributes |= OBJ_PERMANENT;
  609. break;
  610. case 'c' :
  611. case 'C' :
  612. Attributes |= OBJ_EXCLUSIVE;
  613. break;
  614. case 'd' :
  615. case 'D' :
  616. Attributes |= OBJ_CASE_INSENSITIVE;
  617. break;
  618. case 'e' :
  619. case 'E' :
  620. Attributes |= OBJ_OPENIF;
  621. break;
  622. case 'z' :
  623. case 'Z' :
  624. Attributes = 0;
  625. break;
  626. default :
  627. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  628. SwitchBool = FALSE;
  629. }
  630. if (!SwitchBool) {
  631. break;
  632. }
  633. ParamBuffer++;
  634. }
  635. break;
  636. //
  637. // Update the create disposition.
  638. //
  639. case 'p' :
  640. case 'P' :
  641. //
  642. // Move to the next character, as long as there
  643. // are no white spaces continue analyzing letters.
  644. // On the first bad letter, skip to the next
  645. // parameter.
  646. //
  647. ParamBuffer++;
  648. SwitchBool = TRUE;
  649. while (*ParamBuffer
  650. && *ParamBuffer != ' '
  651. && *ParamBuffer != '\t') {
  652. //
  653. // Perform switch on character.
  654. //
  655. switch (*ParamBuffer) {
  656. case 'a' :
  657. case 'A' :
  658. CreateDisposition |= FILE_SUPERSEDE;
  659. break;
  660. case 'b' :
  661. case 'B' :
  662. CreateDisposition |= FILE_OPEN;
  663. break;
  664. case 'c' :
  665. case 'C' :
  666. CreateDisposition |= FILE_CREATE;
  667. break;
  668. case 'd' :
  669. case 'D' :
  670. CreateDisposition |= FILE_OPEN_IF;
  671. break;
  672. case 'e' :
  673. case 'E' :
  674. CreateDisposition |= FILE_OVERWRITE;
  675. break;
  676. case 'f' :
  677. case 'F' :
  678. CreateDisposition |= FILE_OVERWRITE_IF;
  679. break;
  680. case 'z' :
  681. case 'Z' :
  682. CreateDisposition = 0;
  683. break;
  684. default :
  685. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  686. SwitchBool = FALSE;
  687. }
  688. if( !SwitchBool ) {
  689. break;
  690. }
  691. ParamBuffer++;
  692. }
  693. break;
  694. //
  695. // Get a root directory handle.
  696. //
  697. case 'r' :
  698. case 'R' :
  699. //
  700. // Move to the next character, as long as there
  701. // are no white spaces continue analyzing letters.
  702. // On the first bad letter, skip to the next
  703. // parameter.
  704. //
  705. ParamBuffer++;
  706. RootDirIndex = (USHORT) AsciiToInteger( ParamBuffer );
  707. if( RootDirIndex <= MAX_HANDLES ) {
  708. RootDirIndexPtr = &RootDirIndex;
  709. }
  710. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  711. break;
  712. //
  713. // Update the allocation size.
  714. //
  715. case 's' :
  716. case 'S' :
  717. //
  718. // Move to the next character, as long as there
  719. // are no white spaces continue analyzing letters.
  720. // On the first bad letter, skip to the next
  721. // parameter.
  722. //
  723. ParamBuffer++;
  724. AllocationSize.QuadPart = AsciiToLargeInteger( ParamBuffer );
  725. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  726. AllocationSizePtr = &AllocationSize;
  727. break;
  728. case 'v' :
  729. case 'V' :
  730. //
  731. // Legal values for params are T/t or F/f.
  732. //
  733. ParamBuffer++;
  734. if (*ParamBuffer == 'T'
  735. || *ParamBuffer == 't') {
  736. VerboseResults = TRUE;
  737. } else if (*ParamBuffer == 'F'
  738. || *ParamBuffer == 'f') {
  739. VerboseResults = FALSE;
  740. }
  741. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  742. break;
  743. //
  744. // Check for using name exactly as given.
  745. //
  746. case 'x' :
  747. case 'X' :
  748. //
  749. // Legal values for params are T/t or F/f.
  750. //
  751. ParamBuffer++;
  752. if (*ParamBuffer == 'T'
  753. || *ParamBuffer == 't') {
  754. ExactName = TRUE;
  755. } else if (*ParamBuffer == 'F'
  756. || *ParamBuffer == 'f') {
  757. ExactName = FALSE;
  758. }
  759. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  760. break;
  761. //
  762. // Check for unicode or ansi file names.
  763. //
  764. case 'u' :
  765. case 'U' :
  766. //
  767. // Legal values for params are T/t or F/f.
  768. //
  769. ParamBuffer++;
  770. if (*ParamBuffer == 'T'
  771. || *ParamBuffer == 't') {
  772. AnsiName = FALSE;
  773. } else if (*ParamBuffer == 'F'
  774. || *ParamBuffer == 'f') {
  775. AnsiName = TRUE;
  776. }
  777. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  778. break;
  779. case 'y' :
  780. case 'Y' :
  781. //
  782. // Set the display parms flag and jump over this
  783. // character.
  784. //
  785. DisplayParameters = TRUE;
  786. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  787. break;
  788. case 'z' :
  789. case 'Z' :
  790. //
  791. // Set flag for more input and jump over this char.
  792. //
  793. LastInput = FALSE;
  794. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  795. break;
  796. default :
  797. //
  798. // Swallow to the next white space and continue the
  799. // loop.
  800. //
  801. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  802. }
  803. }
  804. //
  805. // Else the text is invalid, skip the entire block.
  806. //
  807. //
  808. //
  809. // Else if there is no input then exit.
  810. //
  811. } else if( LastInput ) {
  812. break;
  813. //
  814. // Else try to read another line for open parameters.
  815. //
  816. } else {
  817. }
  818. }
  819. //
  820. // If the file name wasn't found, then display the syntax message
  821. // and set verbose to FALSE.
  822. //
  823. if( !FileNameFound ) {
  824. printf( "\n Usage: op [options]* -f<filename> | -i[l|h]<fileId> [options]*\n" );
  825. printf( " Options:\n" );
  826. printf( " -f<filename> Name of file to open\n" );
  827. printf( " -il<digits> Low 32 bits of file id\n" );
  828. printf( " -ih<digits> High 32 bits of file id\n" );
  829. printf( " -x[t|f] Use name exactly (don't add \\DosDevices)\n" );
  830. printf( " -u[t|f] Use unicode names \n" );
  831. printf( " -v[t|f] Print out results\n" );
  832. printf( " -z Get additional input\n" );
  833. printf( " -y Display create parameters\n" );
  834. printf( " -b<digits> Buffer index for Ea's\n" );
  835. printf( " -l<digits> Stated length of Ea buffer\n" );
  836. printf( " -d<chars> Modify Desired Access value\n" );
  837. printf( " -r<digits> Relative directory handle index\n" );
  838. printf( " -o<chars> Object Attributes\n" );
  839. printf( " -s<digits> Allocation size\n" );
  840. printf( " -a<chars> File Attribute values\n" );
  841. printf( " -h<chars> Share Access values\n" );
  842. printf( " -p<chars> Create Disposition values\n" );
  843. printf( " -n<chars> Create Options values\n" );
  844. printf( "\n\n" );
  845. DeallocateBuffer( NameIndex );
  846. //
  847. // Else return the status of opening the file.
  848. //
  849. } else {
  850. NTSTATUS Status;
  851. SIZE_T RegionSize;
  852. ULONG TempIndex;
  853. PASYNC_OPEN AsyncOpen;
  854. HANDLE ThreadHandle;
  855. ULONG ThreadId;
  856. RegionSize = sizeof( ASYNC_OPEN );
  857. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  858. AsyncIndex = (USHORT) TempIndex;
  859. if (!NT_SUCCESS( Status )) {
  860. printf("\tInputOpen: Unable to allocate async structure\n" );
  861. DeallocateBuffer( NameIndex );
  862. } else {
  863. AsyncOpen = (PASYNC_OPEN) Buffers[AsyncIndex].Buffer;
  864. AsyncOpen->DesiredAccess = DesiredAccess;
  865. AsyncOpen->AllocationSize = AllocationSize;
  866. AsyncOpen->AllocationSizePtr = AllocationSizePtr
  867. ? &AsyncOpen->AllocationSize
  868. : NULL;
  869. AsyncOpen->FileAttributes = FileAttributes;
  870. AsyncOpen->ShareAccess = ShareAccess;
  871. AsyncOpen->CreateDisposition = CreateDisposition;
  872. AsyncOpen->CreateOptions = CreateOptions;
  873. AsyncOpen->EaBuffer = EaBuffer;
  874. AsyncOpen->EaLength = EaLength;
  875. AsyncOpen->ObjectName = ObjectName;
  876. AsyncOpen->RootDirIndex = RootDirIndex;
  877. AsyncOpen->RootDirIndexPtr = RootDirIndexPtr
  878. ? &AsyncOpen->RootDirIndex
  879. : NULL;
  880. AsyncOpen->Attributes = Attributes;
  881. AsyncOpen->SecurityDescriptor = SecurityDescriptor;
  882. AsyncOpen->SecurityQualityOfService = SecurityQualityOfService;
  883. AsyncOpen->DisplayParameters = DisplayParameters;
  884. AsyncOpen->VerboseResults = VerboseResults;
  885. AsyncOpen->AnsiName = AnsiName;
  886. AsyncOpen->AsyncIndex = AsyncIndex;
  887. AsyncOpen->NameIndex = NameIndex;
  888. if (!SynchronousCmds) {
  889. ThreadHandle = CreateThread( NULL,
  890. 0,
  891. FullOpen,
  892. AsyncOpen,
  893. 0,
  894. &ThreadId );
  895. if (ThreadHandle == 0) {
  896. printf( "\nInputOpen: Spawning thread fails -> %d\n", GetLastError() );
  897. DeallocateBuffer( NameIndex );
  898. DeallocateBuffer( AsyncIndex );
  899. return;
  900. }
  901. } else {
  902. FullOpen( AsyncOpen );
  903. }
  904. }
  905. }
  906. return;
  907. }
  908. VOID
  909. FullOpen (
  910. IN PASYNC_OPEN AsyncOpen
  911. )
  912. {
  913. NTSTATUS Status;
  914. IO_STATUS_BLOCK Iosb;
  915. OBJECT_ATTRIBUTES ObjectAttributes;
  916. UNICODE_STRING UnicodeName;
  917. PUNICODE_STRING NameString;
  918. USHORT ThisIndex;
  919. Iosb.Status = STATUS_SUCCESS;
  920. Iosb.Information = 0;
  921. //
  922. // Check that the relative index is a valid value.
  923. //
  924. if (AsyncOpen->RootDirIndexPtr != NULL) {
  925. if (AsyncOpen->RootDirIndex >= MAX_HANDLES) {
  926. bprint "\n" );
  927. bprint "Relative index is invalid\n" );
  928. DeallocateBuffer( AsyncOpen->AsyncIndex );
  929. DeallocateBuffer( AsyncOpen->NameIndex );
  930. return;
  931. }
  932. ObjectAttributes.RootDirectory = Handles[AsyncOpen->RootDirIndex].Handle;
  933. } else {
  934. ObjectAttributes.RootDirectory = 0;
  935. }
  936. //
  937. // Find a free index.
  938. //
  939. if (ObtainIndex( &ThisIndex ) != STATUS_SUCCESS) {
  940. bprint "\n" );
  941. bprint "Unable to get a new handle index \n" );
  942. return;
  943. }
  944. if (AsyncOpen->AnsiName
  945. || FlagOn( AsyncOpen->CreateOptions, FILE_OPEN_BY_FILE_ID )) {
  946. NameString = (PUNICODE_STRING) &AsyncOpen->ObjectName;
  947. } else {
  948. RtlAnsiStringToUnicodeString( &UnicodeName,
  949. &AsyncOpen->ObjectName,
  950. TRUE );
  951. NameString = &UnicodeName;
  952. }
  953. ObjectAttributes.Length = sizeof( OBJECT_ATTRIBUTES );
  954. ObjectAttributes.ObjectName = NameString;
  955. ObjectAttributes.SecurityDescriptor = AsyncOpen->SecurityDescriptor;
  956. ObjectAttributes.SecurityQualityOfService = AsyncOpen->SecurityQualityOfService;
  957. ObjectAttributes.Attributes = AsyncOpen->Attributes;
  958. if (AsyncOpen->DisplayParameters) {
  959. bprint "\n" );
  960. bprint " CallOpenFile Parameters\n" );
  961. bprint "\n" );
  962. bprint " DesiredAccess -> %08lx\n", AsyncOpen->DesiredAccess );
  963. if (FlagOn( AsyncOpen->CreateOptions, FILE_OPEN_BY_FILE_ID )) {
  964. PLARGE_INTEGER FileId;
  965. FileId = (PLARGE_INTEGER) AsyncOpen->ObjectName.Buffer;
  966. bprint " FileId.LowPart -> %08lx\n", FileId->LowPart );
  967. bprint " FileId.HighPart -> %08lx\n", FileId->HighPart );
  968. } else {
  969. bprint " Filename -> %s\n", AsyncOpen->ObjectName.Buffer );
  970. bprint " FileNameLen -> %ld\n", AsyncOpen->ObjectName.Length );
  971. }
  972. bprint " RootDirectoryIndexPtr -> %ld\n", AsyncOpen->RootDirIndexPtr );
  973. if (AsyncOpen->RootDirIndexPtr != NULL) {
  974. bprint " RootDirectoryIndex -> %ld\n", AsyncOpen->RootDirIndex );
  975. }
  976. bprint " SecurityDescriptor -> %lx\n", AsyncOpen->SecurityDescriptor );
  977. bprint " SecurityQualityOfService -> %lx\n", AsyncOpen->SecurityQualityOfService );
  978. bprint " Attributes -> %08lx\n", AsyncOpen->Attributes );
  979. bprint " AllocationSizePtr -> %lx\n", AsyncOpen->AllocationSizePtr );
  980. if (AsyncOpen->AllocationSizePtr) {
  981. bprint " AllocationSize.LowPart -> %lx\n", AsyncOpen->AllocationSize.LowPart );
  982. bprint " AllocationSize.HighPart -> %lx\n", AsyncOpen->AllocationSize.HighPart );
  983. }
  984. bprint " FileAttributes -> %08lx\n", AsyncOpen->FileAttributes );
  985. bprint " ShareAccess -> %08lx\n", AsyncOpen->ShareAccess );
  986. bprint " CreateDisposition -> %08lx\n", AsyncOpen->CreateDisposition );
  987. bprint " CreateOptions -> %08lx\n", AsyncOpen->CreateOptions );
  988. bprint " EaBuffer -> %lx\n", AsyncOpen->EaBuffer );
  989. bprint " EaLength -> %ld\n", AsyncOpen->EaLength );
  990. bprint " AnsiName -> %04x\n", AsyncOpen->AnsiName );
  991. bprint "\n" );
  992. }
  993. Status = NtCreateFile( &Handles[ThisIndex].Handle,
  994. AsyncOpen->DesiredAccess,
  995. &ObjectAttributes,
  996. &Iosb,
  997. AsyncOpen->AllocationSizePtr,
  998. AsyncOpen->FileAttributes,
  999. AsyncOpen->ShareAccess,
  1000. AsyncOpen->CreateDisposition,
  1001. AsyncOpen->CreateOptions,
  1002. AsyncOpen->EaBuffer,
  1003. AsyncOpen->EaLength );
  1004. if (AsyncOpen->VerboseResults) {
  1005. bprint "\n" );
  1006. bprint " OpenFile: Status -> %08lx\n", Status );
  1007. bprint "\n" );
  1008. bprint " File Handle -> 0x%lx\n", Handles[ThisIndex].Handle );
  1009. bprint " File HandleIndex -> %ld\n", ThisIndex );
  1010. if (NT_SUCCESS( Status )) {
  1011. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1012. bprint " Io.Info -> %08lx\n", Iosb.Information );
  1013. }
  1014. bprint "\n" );
  1015. }
  1016. if (!NT_SUCCESS( Status )) {
  1017. FreeIndex( ThisIndex );
  1018. }
  1019. DeallocateBuffer( AsyncOpen->NameIndex );
  1020. if (!AsyncOpen->AnsiName) {
  1021. RtlFreeUnicodeString( &UnicodeName );
  1022. }
  1023. DeallocateBuffer( AsyncOpen->AsyncIndex );
  1024. NtTerminateThread( 0, STATUS_SUCCESS );
  1025. }