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.

784 lines
17 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: DFSPROCS.H
  4. //
  5. // Contents:
  6. // This module defines all of the globally used procedures in the Dsfs
  7. // file system.
  8. //
  9. // Functions:
  10. //
  11. // History: 12 Nov 1991 AlanW Created from CDFS souce.
  12. // 8 May 1992 PeterCo Removed References to EPs
  13. // Added stuff to support PKT (M000)
  14. //-----------------------------------------------------------------------------
  15. #ifndef _DFSPROCS_
  16. #define _DFSPROCS_
  17. //
  18. // "System" include files
  19. //
  20. #if defined (MUPKD)
  21. #include <ntos.h>
  22. #include <string.h>
  23. #include <fsrtl.h>
  24. #else
  25. #include <ntifs.h>
  26. #include <ntddser.h>
  27. #endif
  28. #include <windef.h>
  29. #include <tdi.h>
  30. #include <wincred.h>
  31. #include <ntddnfs.h> // For communicating with
  32. // the SMB Rdr
  33. #include <ntddmup.h> // For UNC registration
  34. #include <winnetwk.h> // For NETRESOURCE def'n
  35. #include <dfsfsctl.h> // Dfs FsControl Codes.
  36. #include <lmdfs.h> // DFS_INFO_X
  37. #include "dfserr.h"
  38. #include "dfsstr.h"
  39. #include "nodetype.h"
  40. #include "dfsmrshl.h"
  41. #include "dfsrtl.h"
  42. #include "pkt.h"
  43. #include "dfsstruc.h"
  44. #include "dfsdata.h"
  45. #include "log.h"
  46. #ifndef i386
  47. #define DFS_UNALIGNED UNALIGNED
  48. #else
  49. #define DFS_UNALIGNED
  50. #endif // MIPS
  51. NTSYSAPI
  52. NTSTATUS
  53. NTAPI
  54. ZwQueryInformationProcess(
  55. IN HANDLE ProcessHandle,
  56. IN PROCESSINFOCLASS ProcessInformationClass,
  57. OUT PVOID ProcessInformation,
  58. IN ULONG ProcessInformationLength,
  59. OUT PULONG ReturnLength OPTIONAL
  60. );
  61. NTSYSAPI
  62. NTSTATUS
  63. NTAPI
  64. ZwCreateSymbolicLinkObject(
  65. OUT PHANDLE LinkHandle,
  66. IN ACCESS_MASK DesiredAccess,
  67. IN POBJECT_ATTRIBUTES ObjectAttributes,
  68. IN PUNICODE_STRING LinkTarget
  69. );
  70. //
  71. // The driver entry routine
  72. //
  73. NTSTATUS
  74. DfsDriverEntry(
  75. IN PDRIVER_OBJECT DriverObject,
  76. IN PUNICODE_STRING RegistryPath
  77. );
  78. VOID
  79. DfsUnload(
  80. IN PDRIVER_OBJECT DriverObject
  81. );
  82. //
  83. // The following routine is used to create and initialIze logical root
  84. // device objects, implemented in dsinit.c
  85. //
  86. #ifdef TERMSRV
  87. NTSTATUS
  88. DfsInitializeLogicalRoot (
  89. IN LPCWSTR Name,
  90. IN PUNICODE_STRING Prefix OPTIONAL,
  91. IN PDFS_CREDENTIALS Credentials OPTIONAL,
  92. IN USHORT VcbFlags OPTIONAL,
  93. IN ULONG SessionID,
  94. IN PLUID LogonID
  95. );
  96. NTSTATUS
  97. DfsDeleteLogicalRoot (
  98. IN PWSTR Name,
  99. IN BOOLEAN fForce,
  100. IN ULONG SessionID,
  101. IN PLUID LogonID
  102. );
  103. BOOLEAN
  104. DfsLogicalRootExists(
  105. IN PWSTR pwszName,
  106. IN ULONG SessionID,
  107. IN PLUID LogonID
  108. );
  109. NTSTATUS
  110. DfsInitializeDevlessRoot (
  111. IN PUNICODE_STRING NAME,
  112. IN PDFS_CREDENTIALS Credentials OPTIONAL,
  113. IN ULONG SessionID,
  114. IN PLUID LogonID
  115. );
  116. NTSTATUS
  117. DfsDeleteDevlessRoot (
  118. IN PUNICODE_STRING NAME,
  119. IN ULONG SessionID,
  120. IN PLUID LogonID
  121. );
  122. NTSTATUS
  123. DfsFindDevlessRoot(
  124. IN PUNICODE_STRING Name,
  125. IN ULONG SessionID,
  126. IN PLUID LogonID,
  127. OUT PDFS_DEVLESS_ROOT *Drt
  128. );
  129. #else // TERMSRV
  130. NTSTATUS
  131. DfsInitializeLogicalRoot (
  132. IN LPCWSTR Name,
  133. IN PUNICODE_STRING Prefix OPTIONAL,
  134. IN PDFS_CREDENTIALS Credentials OPTIONAL,
  135. IN USHORT VcbFlags OPTIONAL,
  136. IN PLUID LogonID
  137. );
  138. NTSTATUS
  139. DfsDeleteLogicalRoot (
  140. IN PWSTR Name,
  141. IN BOOLEAN fForce,
  142. IN PLUID LogonID
  143. );
  144. BOOLEAN
  145. DfsLogicalRootExists(
  146. PWSTR pwszName,
  147. IN PLUID LogonID
  148. );
  149. NTSTATUS
  150. DfsInitializeDevlessRoot (
  151. IN PUNICODE_STRING NAME,
  152. IN PDFS_CREDENTIALS Credentials OPTIONAL,
  153. IN PLUID LogonID
  154. );
  155. NTSTATUS
  156. DfsDeleteDevlessRoot (
  157. IN PUNICODE_STRING NAME,
  158. IN PLUID LogonID
  159. );
  160. NTSTATUS
  161. DfsFindDevlessRoot(
  162. IN PUNICODE_STRING Name,
  163. IN PLUID LogonID,
  164. OUT PDFS_DEVLESS_ROOT *Drt
  165. );
  166. #endif // TERMSRV
  167. NTSTATUS
  168. DfspLogRootNameToPath(
  169. LPCWSTR Name,
  170. PUNICODE_STRING RootName
  171. );
  172. NTSTATUS
  173. DfsGetResourceFromVcb(
  174. PIRP pIrp,
  175. PDFS_VCB Vcb,
  176. PUNICODE_STRING ProviderName,
  177. PUCHAR BufBegin,
  178. PUCHAR Buf,
  179. PULONG BufSize,
  180. PULONG pResourceSize
  181. );
  182. NTSTATUS
  183. DfsGetResourceFromDevlessRoot(
  184. PIRP pIrp,
  185. PDFS_DEVLESS_ROOT Drt,
  186. PUNICODE_STRING ProviderName,
  187. PUCHAR BufBegin,
  188. PUCHAR Buf,
  189. PULONG BufSize,
  190. PULONG pResourceSize
  191. );
  192. //
  193. // The following routines are used to manipulate the fcb associated with
  194. // each opened file object, implemented in FilObSup.c
  195. //
  196. typedef enum _TYPE_OF_OPEN {
  197. UnopenedFileObject = 1,
  198. FilesystemDeviceOpen,
  199. LogicalRootDeviceOpen,
  200. RedirectedFileOpen,
  201. UserVolumeOpen,
  202. UnknownOpen,
  203. } TYPE_OF_OPEN;
  204. VOID
  205. DfsSetFileObject (
  206. IN PFILE_OBJECT FileObject OPTIONAL,
  207. IN TYPE_OF_OPEN TypeOfOpen,
  208. IN PVOID VcbOrFcb
  209. );
  210. TYPE_OF_OPEN
  211. DfsDecodeFileObject (
  212. IN PFILE_OBJECT FileObject,
  213. OUT PDFS_VCB *Vcb,
  214. OUT PDFS_FCB *Fcb
  215. );
  216. //
  217. // In-memory structure support routines, implemented in StrucSup.c
  218. //
  219. PIRP_CONTEXT
  220. DfsCreateIrpContext (
  221. IN PIRP Irp,
  222. IN BOOLEAN Wait
  223. );
  224. VOID
  225. DfsDeleteIrpContext_Real (
  226. IN PIRP_CONTEXT IrpContext
  227. );
  228. #if DBG
  229. #define DfsDeleteIrpContext(IRPCONTEXT) { \
  230. DfsDeleteIrpContext_Real((IRPCONTEXT)); \
  231. (IRPCONTEXT) = NULL; \
  232. }
  233. #else
  234. #define DfsDeleteIrpContext(IRPCONTEXT) { \
  235. DfsDeleteIrpContext_Real((IRPCONTEXT)); \
  236. }
  237. #endif
  238. VOID
  239. DfsInitializeVcb (
  240. IN PIRP_CONTEXT IrpContext,
  241. IN OUT PDFS_VCB Vcb,
  242. IN PUNICODE_STRING LogRootPrefix,
  243. IN PDFS_CREDENTIALS Credentials OPTIONAL,
  244. IN PDEVICE_OBJECT TargetDeviceObject
  245. );
  246. VOID
  247. DfsInitializeDrt (
  248. IN OUT PDFS_DEVLESS_ROOT Drt,
  249. IN PUNICODE_STRING Name,
  250. IN PDFS_CREDENTIALS Credentials OPTIONAL
  251. );
  252. VOID
  253. DfsDeleteVcb_Real (
  254. IN PIRP_CONTEXT IrpContext,
  255. IN PDFS_VCB Vcb
  256. );
  257. #if DBG
  258. #define DfsDeleteVcb(IRPCONTEXT,VCB) { \
  259. DfsDeleteVcb_Real((IRPCONTEXT),(VCB)); \
  260. (VCB) = NULL; \
  261. }
  262. #else
  263. #define DfsDeleteVcb(IRPCONTEXT,VCB) { \
  264. DfsDeleteVcb_Real((IRPCONTEXT),(VCB)); \
  265. }
  266. #endif
  267. PDFS_FCB
  268. DfsCreateFcb (
  269. IN PIRP_CONTEXT IrpContext,
  270. IN PDFS_VCB Vcb,
  271. IN PUNICODE_STRING FullName OPTIONAL
  272. );
  273. VOID
  274. DfsDeleteFcb_Real (
  275. IN PIRP_CONTEXT IrpContext,
  276. IN PDFS_FCB Fcb
  277. );
  278. #if DBG
  279. #define DfsDeleteFcb(IRPCONTEXT,FCB) { \
  280. DfsDeleteFcb_Real((IRPCONTEXT),(FCB)); \
  281. (FCB) = NULL; \
  282. }
  283. #else
  284. #define DfsDeleteFcb(IRPCONTEXT,FCB) { \
  285. DfsDeleteFcb_Real((IRPCONTEXT),(FCB)); \
  286. }
  287. #endif
  288. //
  289. // Miscellaneous routines
  290. //
  291. VOID GuidToString(
  292. IN GUID *pGuid,
  293. OUT PWSTR pwszGuid);
  294. VOID StringToGuid(
  295. IN PWSTR pwszGuid,
  296. OUT GUID *pGuid);
  297. #ifdef TERMSRV
  298. NTSTATUS
  299. DfsFindLogicalRoot( // implemented in FsCtrl.c
  300. IN PUNICODE_STRING PrefixPath,
  301. IN ULONG SessionID,
  302. IN PLUID LogonID,
  303. OUT PDFS_VCB *Vcb,
  304. OUT PUNICODE_STRING RemainingPath
  305. );
  306. #else // TERMSRV
  307. NTSTATUS
  308. DfsFindLogicalRoot( // implemented in FsCtrl.c
  309. IN PUNICODE_STRING PrefixPath,
  310. IN PLUID LogonID,
  311. OUT PDFS_VCB *Vcb,
  312. OUT PUNICODE_STRING RemainingPath
  313. );
  314. #endif // TERMSRV
  315. NTSTATUS
  316. DfsInsertProvider( // implemented in FsCtrl.c
  317. IN PUNICODE_STRING pustrProviderName,
  318. IN ULONG fProvCapability,
  319. IN ULONG eProviderId);
  320. NTSTATUS // implemented in provider.c
  321. DfsGetProviderForDevice(
  322. IN PUNICODE_STRING DeviceName,
  323. PPROVIDER_DEF *Provider);
  324. VOID
  325. DfsAgePktEntries(
  326. IN PVOID DfsTimerContext
  327. );
  328. NTSTATUS
  329. DfsFsctrlIsThisADfsPath(
  330. IN PUNICODE_STRING filePath,
  331. IN BOOLEAN CSCAgentCreate,
  332. OUT PUNICODE_STRING pathName);
  333. NTSTATUS
  334. PktFsctrlFlushCache(
  335. IN PIRP_CONTEXT IrpContext,
  336. IN PIRP Irp,
  337. IN PVOID InputBuffer,
  338. IN ULONG InputBufferLength
  339. );
  340. NTSTATUS
  341. PktFsctrlFlushSpcCache(
  342. IN PIRP_CONTEXT IrpContext,
  343. IN PIRP Irp,
  344. IN PVOID InputBuffer,
  345. IN ULONG InputBufferLength
  346. );
  347. NTSTATUS
  348. DfsFsctrlSetDCName(
  349. IN PIRP_CONTEXT IrpContext,
  350. IN PIRP Irp,
  351. IN PVOID InputBuffer,
  352. IN ULONG InputBufferLength);
  353. NTSTATUS
  354. DfsFsctrlSetDomainNameFlat(
  355. IN PIRP_CONTEXT IrpContext,
  356. IN PIRP Irp,
  357. IN PVOID InputBuffer,
  358. IN ULONG InputBufferLength);
  359. NTSTATUS
  360. DfsFsctrlSetDomainNameDns(
  361. IN PIRP_CONTEXT IrpContext,
  362. IN PIRP Irp,
  363. IN PVOID InputBuffer,
  364. IN ULONG InputBufferLength);
  365. NTSTATUS
  366. PktpSetActiveSpcService(
  367. PUNICODE_STRING DomainName,
  368. PUNICODE_STRING DcName,
  369. BOOLEAN ResetTimeout);
  370. NTSTATUS
  371. PktpUpdateSpecialTable(
  372. PUNICODE_STRING DomainName,
  373. PUNICODE_STRING DCName);
  374. //
  375. // Pass-through functions
  376. //
  377. NTSTATUS
  378. DfsVolumePassThrough(
  379. IN PDEVICE_OBJECT DeviceObject,
  380. IN PIRP Irp
  381. );
  382. NTSTATUS
  383. DfsCompleteVolumePassThrough(
  384. IN PDEVICE_OBJECT pDevice,
  385. IN PIRP Irp,
  386. IN PVOID Context
  387. );
  388. NTSTATUS
  389. DfsFilePassThrough(
  390. IN PDFS_FCB pFcb,
  391. IN PIRP Irp
  392. );
  393. //
  394. // The FSD Level dispatch routines. These routines are called by the
  395. // I/O system via the dispatch table in the Driver Object.
  396. //
  397. // They each accept as input a pointer to a device object (actually most
  398. // expect a logical root device object; some will also work with a file
  399. // system device object), and a pointer to the IRP. They either perform
  400. // the function at the FSD level or post the request to the FSP work
  401. // queue for FSP level processing.
  402. //
  403. NTSTATUS
  404. DfsFsdCleanup ( // implemented in Close.c
  405. IN PDEVICE_OBJECT DeviceObject,
  406. IN PIRP Irp
  407. );
  408. NTSTATUS
  409. DfsFsdClose ( // implemented in Close.c
  410. IN PDEVICE_OBJECT DeviceObject,
  411. IN PIRP Irp
  412. );
  413. NTSTATUS
  414. DfsFsdCreate ( // implemented in Create.c
  415. IN PDEVICE_OBJECT DeviceObject,
  416. IN PIRP Irp
  417. );
  418. NTSTATUS
  419. DfsFsdDeviceIoControl ( // implemented in FsCtrl.c
  420. IN PDEVICE_OBJECT DeviceObject,
  421. IN PIRP Irp
  422. );
  423. NTSTATUS
  424. DfsFsdDirectoryControl ( // implemented in DirCtrl.c
  425. IN PDEVICE_OBJECT DeviceObject,
  426. IN PIRP Irp
  427. );
  428. NTSTATUS
  429. DfsFsdQueryInformation ( // implemented in FileInfo.c
  430. IN PDEVICE_OBJECT DeviceObject,
  431. IN PIRP Irp
  432. );
  433. NTSTATUS
  434. DfsFsdQueryInformation ( // implemented in FileInfo.c
  435. IN PDEVICE_OBJECT DeviceObject,
  436. IN PIRP Irp
  437. );
  438. NTSTATUS
  439. DfsFsdSetInformation ( // implemented in FileInfo.c
  440. IN PDEVICE_OBJECT DeviceObject,
  441. IN PIRP Irp
  442. );
  443. NTSTATUS
  444. DfsFsdFileSystemControl ( // implemented in FsCtrl.c
  445. IN PDEVICE_OBJECT DeviceObject,
  446. IN PIRP Irp
  447. );
  448. NTSTATUS
  449. DfsFsdQueryVolumeInformation ( // implemented in VolInfo.c
  450. IN PDEVICE_OBJECT DeviceObject,
  451. IN PIRP Irp
  452. );
  453. NTSTATUS
  454. DfsFsdSetVolumeInformation ( // implemented in VolInfo.c
  455. IN PDEVICE_OBJECT DeviceObject,
  456. IN PIRP Irp
  457. );
  458. //
  459. // The following macro is used to determine if an FSD thread can block
  460. // for I/O or wait for a resource. It returns TRUE if the thread can
  461. // block and FALSE otherwise. This attribute can then be used to call
  462. // the FSD & FSP common work routine with the proper wait value.
  463. //
  464. #define CanFsdWait(IRP) ((BOOLEAN)( \
  465. IoIsOperationSynchronous(IRP) || \
  466. DfsData.OurProcess == PsGetCurrentProcess()) \
  467. )
  468. //
  469. // Routine for posting an Irp to the FSP, implemented in fspdisp.c
  470. //
  471. NTSTATUS
  472. DfsFsdPostRequest(
  473. IN PIRP_CONTEXT IrpContext,
  474. IN PIRP Irp
  475. );
  476. //
  477. // The FSP level dispatch/main routine. This is the routine that takes
  478. // IRPs from the work queue and calls the appropriate FSP level work routine.
  479. //
  480. VOID
  481. DfsFspDispatch ( // implemented in FspDisp.c
  482. IN PVOID Context
  483. );
  484. //
  485. // The following routines are the FSP work routines that are called
  486. // by the preceding DfsFsdDispath routine. Each takes as input a pointer
  487. // to the IRP, performs the function, and returns.
  488. //
  489. // Each of the following routines is also responsible for completing the IRP.
  490. // We moved this responsibility from the main loop to the individual routines
  491. // to allow them the ability to complete the IRP and continue post processing
  492. // actions.
  493. //
  494. VOID
  495. DfsFspClose ( // implemented in Close.c
  496. IN PIRP_CONTEXT IrpContext,
  497. IN PIRP Irp
  498. );
  499. VOID
  500. DfsFspQueryInformation ( // implemented in FileInfo.c
  501. IN PIRP_CONTEXT IrpContext,
  502. IN PIRP Irp
  503. );
  504. VOID
  505. DfsFspSetInformation ( // implemented in FileInfo.c
  506. IN PIRP_CONTEXT IrpContext,
  507. IN PIRP Irp
  508. );
  509. VOID
  510. DfsFspFileSystemControl ( // implemented in FsCtrl.c
  511. IN PIRP_CONTEXT IrpContext,
  512. IN PIRP Irp
  513. );
  514. VOID
  515. DfsFspQueryVolumeInformation ( // implemented in VolInfo.c
  516. IN PIRP_CONTEXT IrpContext,
  517. IN PIRP Irp
  518. );
  519. VOID
  520. DfsFspSetVolumeInformation ( // implemented in VolInfo.c
  521. IN PIRP_CONTEXT IrpContext,
  522. IN PIRP Irp
  523. );
  524. //
  525. // The following macro is used by the FSP and FSD routines to complete
  526. // an IRP.
  527. //
  528. // Note that this macro allows either the Irp or the IrpContext to be
  529. // null, however the only legal order to do this in is:
  530. //
  531. // DfsCompleteRequest( NULL, Irp, Status ); // completes Irp & preserves context
  532. // ...
  533. // DfsCompleteRequest( IrpContext, NULL, DontCare ); // deallocates context
  534. //
  535. // This would typically be done in order to pass a "naked" IrpContext off to the
  536. // Fsp for post processing, such as read ahead.
  537. //
  538. VOID
  539. DfsCompleteRequest_Real (
  540. IN PIRP_CONTEXT IrpContext,
  541. IN PIRP Irp,
  542. IN NTSTATUS Status
  543. );
  544. #define DfsCompleteRequest(IRPCONTEXT,IRP,STATUS) { \
  545. DfsCompleteRequest_Real(IRPCONTEXT,IRP,STATUS); \
  546. }
  547. //
  548. // The following two macros are used by the Fsd/Fsp exception handlers to
  549. // process an exception. The first macro is the exception filter used in
  550. // the Fsd/Fsp to decide if an exception should be handled at this level.
  551. // The second macro decides if the exception is to be finished off by
  552. // completing the IRP, and cleaning up the Irp Context, or if we should
  553. // bugcheck. Exception values such as STATUS_FILE_INVALID (raised by
  554. // VerfySup.c) cause us to complete the Irp and cleanup, while exceptions
  555. // such as accvio cause us to bugcheck.
  556. //
  557. // The basic structure for fsd/fsp exception handling is as follows:
  558. //
  559. // DfsFsdXxx(...)
  560. // {
  561. // try {
  562. //
  563. // ...
  564. //
  565. // } except(DfsExceptionFilter("Xxx\n")) {
  566. //
  567. // DfsProcessException( IrpContext, Irp, &Status );
  568. // }
  569. //
  570. // Return Status;
  571. // }
  572. //
  573. // LONG
  574. // DfsExceptionFilter (
  575. // IN PSZ String
  576. // );
  577. //
  578. // VOID
  579. // DfsProcessException (
  580. // IN PIRP_CONTEXT IrpContext,
  581. // IN PIRP Irp,
  582. // IN PNTSTATUS ExceptionCode
  583. // );
  584. //
  585. LONG
  586. DfsExceptionFilter (
  587. IN PIRP_CONTEXT IrpContext,
  588. IN NTSTATUS ExceptionCode,
  589. IN PEXCEPTION_POINTERS ExceptionPointer
  590. );
  591. NTSTATUS
  592. DfsProcessException (
  593. IN PIRP_CONTEXT IrpContext,
  594. IN PIRP Irp,
  595. IN NTSTATUS ExceptionCode
  596. );
  597. NTSTATUS
  598. DfsGetLogonId (
  599. IN PLUID Id
  600. );
  601. //
  602. // VOID
  603. // DfsRaiseStatus (
  604. // IN PRIP_CONTEXT IrpContext,
  605. // IN NT_STATUS Status
  606. // );
  607. //
  608. //
  609. #define DfsRaiseStatus(IRPCONTEXT,STATUS) { \
  610. (IRPCONTEXT)->ExceptionStatus = (STATUS); \
  611. ExRaiseStatus( (STATUS) ); \
  612. BugCheck( "DfsRaiseStatus " #STATUS ); \
  613. }
  614. //
  615. // The following macros are used to establish the semantics needed
  616. // to do a return from within a try-finally clause. As a rule every
  617. // try clause must end with a label call try_exit. For example,
  618. //
  619. // try {
  620. // :
  621. // :
  622. //
  623. // try_exit: NOTHING;
  624. // } finally {
  625. //
  626. // :
  627. // :
  628. // }
  629. //
  630. // Every return statement executed inside of a try clause should use the
  631. // try_return macro. If the compiler fully supports the try-finally construct
  632. // then the macro should be
  633. //
  634. // #define try_return(S) { return(S); }
  635. //
  636. // If the compiler does not support the try-finally construct then the macro
  637. // should be
  638. //
  639. // #define try_return(S) { S; goto try_exit; }
  640. //
  641. #define try_return(S) { S; goto try_exit; }
  642. #ifdef TERMSRV
  643. NTSTATUS
  644. TSGetRequestorSessionId(
  645. IN PIRP pIrp,
  646. OUT PULONG pulSessionId
  647. );
  648. #endif // TERMSRV
  649. #endif // _DFSPROCS_