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.

1411 lines
44 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 'q' :
  572. case 'Q' :
  573. CreateOptions |= FILE_OPEN_NO_RECALL;
  574. break;
  575. case 'z' :
  576. case 'Z' :
  577. CreateOptions = 0;
  578. break;
  579. default :
  580. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  581. SwitchBool = FALSE;
  582. }
  583. if (!SwitchBool) {
  584. break;
  585. }
  586. ParamBuffer++;
  587. }
  588. break;
  589. case 'o' :
  590. case 'O' :
  591. //
  592. // Move to the next character, as long as there
  593. // are no white spaces continue analyzing letters.
  594. // On the first bad letter, skip to the next
  595. // parameter.
  596. //
  597. ParamBuffer++;
  598. SwitchBool = TRUE;
  599. while (*ParamBuffer
  600. && *ParamBuffer != ' '
  601. && *ParamBuffer != '\t') {
  602. //
  603. // Perform switch on character.
  604. //
  605. switch (*ParamBuffer) {
  606. case 'a' :
  607. case 'A' :
  608. Attributes |= OBJ_INHERIT;
  609. break;
  610. case 'b' :
  611. case 'B' :
  612. Attributes |= OBJ_PERMANENT;
  613. break;
  614. case 'c' :
  615. case 'C' :
  616. Attributes |= OBJ_EXCLUSIVE;
  617. break;
  618. case 'd' :
  619. case 'D' :
  620. Attributes |= OBJ_CASE_INSENSITIVE;
  621. break;
  622. case 'e' :
  623. case 'E' :
  624. Attributes |= OBJ_OPENIF;
  625. break;
  626. case 'z' :
  627. case 'Z' :
  628. Attributes = 0;
  629. break;
  630. default :
  631. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  632. SwitchBool = FALSE;
  633. }
  634. if (!SwitchBool) {
  635. break;
  636. }
  637. ParamBuffer++;
  638. }
  639. break;
  640. //
  641. // Update the create disposition.
  642. //
  643. case 'p' :
  644. case 'P' :
  645. //
  646. // Move to the next character, as long as there
  647. // are no white spaces continue analyzing letters.
  648. // On the first bad letter, skip to the next
  649. // parameter.
  650. //
  651. ParamBuffer++;
  652. SwitchBool = TRUE;
  653. while (*ParamBuffer
  654. && *ParamBuffer != ' '
  655. && *ParamBuffer != '\t') {
  656. //
  657. // Perform switch on character.
  658. //
  659. switch (*ParamBuffer) {
  660. case 'a' :
  661. case 'A' :
  662. CreateDisposition |= FILE_SUPERSEDE;
  663. break;
  664. case 'b' :
  665. case 'B' :
  666. CreateDisposition |= FILE_OPEN;
  667. break;
  668. case 'c' :
  669. case 'C' :
  670. CreateDisposition |= FILE_CREATE;
  671. break;
  672. case 'd' :
  673. case 'D' :
  674. CreateDisposition |= FILE_OPEN_IF;
  675. break;
  676. case 'e' :
  677. case 'E' :
  678. CreateDisposition |= FILE_OVERWRITE;
  679. break;
  680. case 'f' :
  681. case 'F' :
  682. CreateDisposition |= FILE_OVERWRITE_IF;
  683. break;
  684. case 'z' :
  685. case 'Z' :
  686. CreateDisposition = 0;
  687. break;
  688. default :
  689. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  690. SwitchBool = FALSE;
  691. }
  692. if( !SwitchBool ) {
  693. break;
  694. }
  695. ParamBuffer++;
  696. }
  697. break;
  698. //
  699. // Get a root directory handle.
  700. //
  701. case 'r' :
  702. case 'R' :
  703. //
  704. // Move to the next character, as long as there
  705. // are no white spaces continue analyzing letters.
  706. // On the first bad letter, skip to the next
  707. // parameter.
  708. //
  709. ParamBuffer++;
  710. RootDirIndex = (USHORT) AsciiToInteger( ParamBuffer );
  711. if( RootDirIndex <= MAX_HANDLES ) {
  712. RootDirIndexPtr = &RootDirIndex;
  713. }
  714. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  715. break;
  716. //
  717. // Update the allocation size.
  718. //
  719. case 's' :
  720. case 'S' :
  721. //
  722. // Move to the next character, as long as there
  723. // are no white spaces continue analyzing letters.
  724. // On the first bad letter, skip to the next
  725. // parameter.
  726. //
  727. ParamBuffer++;
  728. AllocationSize.QuadPart = AsciiToLargeInteger( ParamBuffer );
  729. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  730. AllocationSizePtr = &AllocationSize;
  731. break;
  732. case 'v' :
  733. case 'V' :
  734. //
  735. // Legal values for params are T/t or F/f.
  736. //
  737. ParamBuffer++;
  738. if (*ParamBuffer == 'T'
  739. || *ParamBuffer == 't') {
  740. VerboseResults = TRUE;
  741. } else if (*ParamBuffer == 'F'
  742. || *ParamBuffer == 'f') {
  743. VerboseResults = FALSE;
  744. }
  745. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  746. break;
  747. //
  748. // Check for using name exactly as given.
  749. //
  750. case 'x' :
  751. case 'X' :
  752. //
  753. // Legal values for params are T/t or F/f.
  754. //
  755. ParamBuffer++;
  756. if (*ParamBuffer == 'T'
  757. || *ParamBuffer == 't') {
  758. ExactName = TRUE;
  759. } else if (*ParamBuffer == 'F'
  760. || *ParamBuffer == 'f') {
  761. ExactName = FALSE;
  762. }
  763. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  764. break;
  765. //
  766. // Check for unicode or ansi file names.
  767. //
  768. case 'u' :
  769. case 'U' :
  770. //
  771. // Legal values for params are T/t or F/f.
  772. //
  773. ParamBuffer++;
  774. if (*ParamBuffer == 'T'
  775. || *ParamBuffer == 't') {
  776. AnsiName = FALSE;
  777. } else if (*ParamBuffer == 'F'
  778. || *ParamBuffer == 'f') {
  779. AnsiName = TRUE;
  780. }
  781. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  782. break;
  783. case 'y' :
  784. case 'Y' :
  785. //
  786. // Set the display parms flag and jump over this
  787. // character.
  788. //
  789. DisplayParameters = TRUE;
  790. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  791. break;
  792. case 'z' :
  793. case 'Z' :
  794. //
  795. // Set flag for more input and jump over this char.
  796. //
  797. LastInput = FALSE;
  798. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  799. break;
  800. default :
  801. //
  802. // Swallow to the next white space and continue the
  803. // loop.
  804. //
  805. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  806. }
  807. }
  808. //
  809. // Else the text is invalid, skip the entire block.
  810. //
  811. //
  812. //
  813. // Else if there is no input then exit.
  814. //
  815. } else if( LastInput ) {
  816. break;
  817. //
  818. // Else try to read another line for open parameters.
  819. //
  820. } else {
  821. }
  822. }
  823. //
  824. // If the file name wasn't found, then display the syntax message
  825. // and set verbose to FALSE.
  826. //
  827. if( !FileNameFound ) {
  828. printf( "\n Usage: op [options]* -f<filename> | -i[l|h]<fileId> [options]*\n" );
  829. printf( " Options:\n" );
  830. printf( " -f<filename> Name of file to open\n" );
  831. printf( " -il<digits> Low 32 bits of file id\n" );
  832. printf( " -ih<digits> High 32 bits of file id\n" );
  833. printf( " -x[t|f] Use name exactly (don't add \\DosDevices)\n" );
  834. printf( " -u[t|f] Use unicode names \n" );
  835. printf( " -v[t|f] Print out results\n" );
  836. printf( " -z Get additional input\n" );
  837. printf( " -y Display create parameters\n" );
  838. printf( " -b<digits> Buffer index for Ea's\n" );
  839. printf( " -l<digits> Stated length of Ea buffer\n" );
  840. printf( " -d<chars> Modify Desired Access value\n" );
  841. printf( " -r<digits> Relative directory handle index\n" );
  842. printf( " -o<chars> Object Attributes\n" );
  843. printf( " -s<digits> Allocation size\n" );
  844. printf( " -a<chars> File Attribute values\n" );
  845. printf( " -h<chars> Share Access values\n" );
  846. printf( " -p<chars> Create Disposition values\n" );
  847. printf( " -n<chars> Create Options values\n" );
  848. printf( "\n\n" );
  849. DeallocateBuffer( NameIndex );
  850. //
  851. // Else return the status of opening the file.
  852. //
  853. } else {
  854. NTSTATUS Status;
  855. SIZE_T RegionSize;
  856. ULONG TempIndex;
  857. PASYNC_OPEN AsyncOpen;
  858. HANDLE ThreadHandle;
  859. ULONG ThreadId;
  860. RegionSize = sizeof( ASYNC_OPEN );
  861. Status = AllocateBuffer( 0, &RegionSize, &TempIndex );
  862. AsyncIndex = (USHORT) TempIndex;
  863. if (!NT_SUCCESS( Status )) {
  864. printf("\tInputOpen: Unable to allocate async structure\n" );
  865. DeallocateBuffer( NameIndex );
  866. } else {
  867. AsyncOpen = (PASYNC_OPEN) Buffers[AsyncIndex].Buffer;
  868. AsyncOpen->DesiredAccess = DesiredAccess;
  869. AsyncOpen->AllocationSize = AllocationSize;
  870. AsyncOpen->AllocationSizePtr = AllocationSizePtr
  871. ? &AsyncOpen->AllocationSize
  872. : NULL;
  873. AsyncOpen->FileAttributes = FileAttributes;
  874. AsyncOpen->ShareAccess = ShareAccess;
  875. AsyncOpen->CreateDisposition = CreateDisposition;
  876. AsyncOpen->CreateOptions = CreateOptions;
  877. AsyncOpen->EaBuffer = EaBuffer;
  878. AsyncOpen->EaLength = EaLength;
  879. AsyncOpen->ObjectName = ObjectName;
  880. AsyncOpen->RootDirIndex = RootDirIndex;
  881. AsyncOpen->RootDirIndexPtr = RootDirIndexPtr
  882. ? &AsyncOpen->RootDirIndex
  883. : NULL;
  884. AsyncOpen->Attributes = Attributes;
  885. AsyncOpen->SecurityDescriptor = SecurityDescriptor;
  886. AsyncOpen->SecurityQualityOfService = SecurityQualityOfService;
  887. AsyncOpen->DisplayParameters = DisplayParameters;
  888. AsyncOpen->VerboseResults = VerboseResults;
  889. AsyncOpen->AnsiName = AnsiName;
  890. AsyncOpen->AsyncIndex = AsyncIndex;
  891. AsyncOpen->NameIndex = NameIndex;
  892. if (!SynchronousCmds) {
  893. ThreadHandle = CreateThread( NULL,
  894. 0,
  895. FullOpen,
  896. AsyncOpen,
  897. 0,
  898. &ThreadId );
  899. if (ThreadHandle == 0) {
  900. printf( "\nInputOpen: Spawning thread fails -> %d\n", GetLastError() );
  901. DeallocateBuffer( NameIndex );
  902. DeallocateBuffer( AsyncIndex );
  903. return;
  904. }
  905. } else {
  906. FullOpen( AsyncOpen );
  907. }
  908. }
  909. }
  910. return;
  911. }
  912. VOID
  913. FullOpen (
  914. IN PASYNC_OPEN AsyncOpen
  915. )
  916. {
  917. NTSTATUS Status;
  918. IO_STATUS_BLOCK Iosb;
  919. OBJECT_ATTRIBUTES ObjectAttributes;
  920. UNICODE_STRING UnicodeName;
  921. PUNICODE_STRING NameString;
  922. USHORT ThisIndex;
  923. Iosb.Status = STATUS_SUCCESS;
  924. Iosb.Information = 0;
  925. //
  926. // Check that the relative index is a valid value.
  927. //
  928. if (AsyncOpen->RootDirIndexPtr != NULL) {
  929. if (AsyncOpen->RootDirIndex >= MAX_HANDLES) {
  930. bprint "\n" );
  931. bprint "Relative index is invalid\n" );
  932. DeallocateBuffer( AsyncOpen->AsyncIndex );
  933. DeallocateBuffer( AsyncOpen->NameIndex );
  934. return;
  935. }
  936. ObjectAttributes.RootDirectory = Handles[AsyncOpen->RootDirIndex].Handle;
  937. } else {
  938. ObjectAttributes.RootDirectory = 0;
  939. }
  940. //
  941. // Find a free index.
  942. //
  943. if (ObtainIndex( &ThisIndex ) != STATUS_SUCCESS) {
  944. bprint "\n" );
  945. bprint "Unable to get a new handle index \n" );
  946. return;
  947. }
  948. if (AsyncOpen->AnsiName
  949. || FlagOn( AsyncOpen->CreateOptions, FILE_OPEN_BY_FILE_ID )) {
  950. NameString = (PUNICODE_STRING) &AsyncOpen->ObjectName;
  951. } else {
  952. RtlAnsiStringToUnicodeString( &UnicodeName,
  953. &AsyncOpen->ObjectName,
  954. TRUE );
  955. NameString = &UnicodeName;
  956. }
  957. ObjectAttributes.Length = sizeof( OBJECT_ATTRIBUTES );
  958. ObjectAttributes.ObjectName = NameString;
  959. ObjectAttributes.SecurityDescriptor = AsyncOpen->SecurityDescriptor;
  960. ObjectAttributes.SecurityQualityOfService = AsyncOpen->SecurityQualityOfService;
  961. ObjectAttributes.Attributes = AsyncOpen->Attributes;
  962. if (AsyncOpen->DisplayParameters) {
  963. bprint "\n" );
  964. bprint " CallOpenFile Parameters\n" );
  965. bprint "\n" );
  966. bprint " DesiredAccess -> %08lx\n", AsyncOpen->DesiredAccess );
  967. if (FlagOn( AsyncOpen->CreateOptions, FILE_OPEN_BY_FILE_ID )) {
  968. PLARGE_INTEGER FileId;
  969. FileId = (PLARGE_INTEGER) AsyncOpen->ObjectName.Buffer;
  970. bprint " FileId.LowPart -> %08lx\n", FileId->LowPart );
  971. bprint " FileId.HighPart -> %08lx\n", FileId->HighPart );
  972. } else {
  973. bprint " Filename -> %s\n", AsyncOpen->ObjectName.Buffer );
  974. bprint " FileNameLen -> %ld\n", AsyncOpen->ObjectName.Length );
  975. }
  976. bprint " RootDirectoryIndexPtr -> %ld\n", AsyncOpen->RootDirIndexPtr );
  977. if (AsyncOpen->RootDirIndexPtr != NULL) {
  978. bprint " RootDirectoryIndex -> %ld\n", AsyncOpen->RootDirIndex );
  979. }
  980. bprint " SecurityDescriptor -> %lx\n", AsyncOpen->SecurityDescriptor );
  981. bprint " SecurityQualityOfService -> %lx\n", AsyncOpen->SecurityQualityOfService );
  982. bprint " Attributes -> %08lx\n", AsyncOpen->Attributes );
  983. bprint " AllocationSizePtr -> %lx\n", AsyncOpen->AllocationSizePtr );
  984. if (AsyncOpen->AllocationSizePtr) {
  985. bprint " AllocationSize.LowPart -> %lx\n", AsyncOpen->AllocationSize.LowPart );
  986. bprint " AllocationSize.HighPart -> %lx\n", AsyncOpen->AllocationSize.HighPart );
  987. }
  988. bprint " FileAttributes -> %08lx\n", AsyncOpen->FileAttributes );
  989. bprint " ShareAccess -> %08lx\n", AsyncOpen->ShareAccess );
  990. bprint " CreateDisposition -> %08lx\n", AsyncOpen->CreateDisposition );
  991. bprint " CreateOptions -> %08lx\n", AsyncOpen->CreateOptions );
  992. bprint " EaBuffer -> %lx\n", AsyncOpen->EaBuffer );
  993. bprint " EaLength -> %ld\n", AsyncOpen->EaLength );
  994. bprint " AnsiName -> %04x\n", AsyncOpen->AnsiName );
  995. bprint "\n" );
  996. }
  997. Status = NtCreateFile( &Handles[ThisIndex].Handle,
  998. AsyncOpen->DesiredAccess,
  999. &ObjectAttributes,
  1000. &Iosb,
  1001. AsyncOpen->AllocationSizePtr,
  1002. AsyncOpen->FileAttributes,
  1003. AsyncOpen->ShareAccess,
  1004. AsyncOpen->CreateDisposition,
  1005. AsyncOpen->CreateOptions,
  1006. AsyncOpen->EaBuffer,
  1007. AsyncOpen->EaLength );
  1008. if (AsyncOpen->VerboseResults) {
  1009. bprint "\n" );
  1010. bprint " OpenFile: Status -> %08lx\n", Status );
  1011. bprint "\n" );
  1012. bprint " File Handle -> 0x%lx\n", Handles[ThisIndex].Handle );
  1013. bprint " File HandleIndex -> %ld\n", ThisIndex );
  1014. if (NT_SUCCESS( Status )) {
  1015. bprint " Io.Status -> %08lx\n", Iosb.Status );
  1016. bprint " Io.Info -> %08lx\n", Iosb.Information );
  1017. }
  1018. bprint "\n" );
  1019. }
  1020. if (!NT_SUCCESS( Status )) {
  1021. FreeIndex( ThisIndex );
  1022. }
  1023. DeallocateBuffer( AsyncOpen->NameIndex );
  1024. if (!AsyncOpen->AnsiName) {
  1025. RtlFreeUnicodeString( &UnicodeName );
  1026. }
  1027. DeallocateBuffer( AsyncOpen->AsyncIndex );
  1028. if (!SynchronousCmds) {
  1029. NtTerminateThread( 0, STATUS_SUCCESS );
  1030. }
  1031. }