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.

451 lines
18 KiB

  1. #define MAX_SHADOW_DIR_NAME 16 // maximum string size of shadow directory
  2. // Stolen from IFSMgr code
  3. #define MAX_SERVER_SHARE (31+63+2)
  4. /********************** Type definitions for subclassed network objects ****/
  5. typedef struct tagRESOURCE *PRESOURCE;
  6. typedef struct tagFINDINFO *PFINDINFO;
  7. typedef struct tagFILEINFO *PFILEINFO;
  8. typedef struct tagFDB *PFDB, **PPFDB;
  9. typedef struct tagELEM *PELEM;
  10. typedef PELEM *PPELEM;
  11. typedef PRESOURCE *PPRESOURCE;
  12. typedef struct tagFINDSHADOW FINDSHADOW;
  13. typedef FINDSHADOW *LPFINDSHADOW;
  14. /******** Netowrk provider *********/
  15. typedef struct tagNETPRO
  16. {
  17. PRESOURCE pheadResource;
  18. pIFSFunc pOurConnectNet;
  19. pIFSFunc pConnectNet; // Providers connection function
  20. } NETPRO, DISKPRO, *PNETPRO, *PDISKPRO;
  21. /************ Resource AKA Volume AKA share *****/
  22. typedef struct tagRESOURCE
  23. {
  24. PRESOURCE pnextResource;
  25. PFILEINFO pheadFileInfo; // list of file I/O calls on this resource
  26. PFINDINFO pheadFindInfo; // list of finds on this resource
  27. PFDB pheadFdb; // List of files being shadowed
  28. HSHARE hShare; // Handle to the server shadow
  29. HSHADOW hRoot; // Handle to the root
  30. USHORT usFlags;
  31. USHORT usLocalFlags;
  32. PNETPRO pOurNetPro;
  33. rh_t rhPro; // Providers resource handle;
  34. fh_t fhSys; // System resource handle
  35. vfunc_t pVolTab; // Pointer to volume functions structure
  36. int cntLocks; // Count of locks on this resource
  37. ULONG uDriveMap; // Drive map for this resource
  38. PathElement pp_elements[1];
  39. } RESOURCE, *PRESOURCE;
  40. /********* per open file handle ****/
  41. typedef struct tagFILEINFO
  42. {
  43. PFILEINFO pnextFileInfo; // Next FileInfo
  44. PRESOURCE pResource; // Resource off which it is hanging
  45. CSCHFILE hfShadow; // Shadow file handle
  46. PFDB pFdb; // Info of Shadow File
  47. fh_t fhProFile; // providers file handle
  48. hndlfunc hfFileHandle; // providers file function table
  49. UCHAR uchAccess; // Acess-share flags for this open
  50. UCHAR uchDummy;
  51. USHORT usFlags;
  52. USHORT usLocalFlags;
  53. ULONG cbTotalRead;
  54. sfn_t sfnFile;
  55. pid_t pidFile;
  56. uid_t userFile;
  57. } FILEINFO, *PFILEINFO;
  58. /////////////////////////////////////////////////////////
  59. /**** FileDescriptionBlock. Common info for all open instances of a file**/
  60. typedef struct tagFDB
  61. {
  62. // I M P O R T A N T : the NT code for PFindFdbFromHshadow returns a PFDB
  63. // but this pointer must not be used to get/put any field except usFlags!
  64. PFDB pnextFdb; // Link to the next
  65. PRESOURCE pResource; // Back pointer to our resource
  66. USHORT usFlags; //
  67. USHORT usCount; // Open Count
  68. ULONG hShadow; // Shadow handle if any
  69. ULONG hDir;
  70. ULONG dwFileSize; // file size when first opened
  71. dos_time dosFileTime;
  72. ULONG dwAttr;
  73. USHORT cntLocks; // Total outstanding locks
  74. USHORT usLocalFlags;
  75. ULONG dwRemoteFileSize; // size of the file when first created, used in the heuristic
  76. ParsedPath sppathRemoteFile; // Parsed Path of the file
  77. } FDB, *PFDB;
  78. typedef struct tagOTHERINFO
  79. {
  80. ULONG ulRefPri;
  81. union
  82. {
  83. ULONG ulIHPri;
  84. ULONG ulRootStatus;
  85. };
  86. ULONG ulHintFlags;
  87. ULONG ulHintPri;
  88. HSHADOW hShadowOrg;
  89. FILETIME ftOrgTime;
  90. FILETIME ftLastRefreshTime;
  91. } OTHERINFO, *LPOTHERINFO;
  92. typedef int (PUBLIC *METAMATCHPROC)(LPFIND32, HSHADOW, HSHADOW, ULONG, LPOTHERINFO, LPVOID);
  93. #define MM_RET_FOUND_CONTINUE 2
  94. #define MM_RET_CONTINUE 1
  95. #define MM_RET_FOUND_BREAK 0
  96. #define MM_RET_BREAK -1
  97. typedef struct tagFINDSHADOW
  98. {
  99. LPFINDSHADOW lpFSHNext;
  100. ULONG ulFlags;
  101. HSHADOW hDir;
  102. ULONG ulCookie;
  103. ULONG uAttrib;
  104. ULONG uSrchFlags;
  105. USHORT *lpPattern;
  106. METAMATCHPROC lpfnMMProc;
  107. } FINDSHADOW, *LPFINDSHADOW;
  108. typedef struct tagSHADOWCHECK
  109. {
  110. USHORT uFlagsIn;
  111. USHORT uFlagsOut;
  112. ULONG ulCookie;
  113. USHORT *lpuName;
  114. USHORT *lpuType;
  115. HSHADOW hShadow;
  116. ULONG uStatus;
  117. ULONG ulHintFlags;
  118. ULONG ulHintPri;
  119. #ifdef MAYBE
  120. OTHERINFO sOI;
  121. #endif //MAYBE
  122. } SHADOWCHECK, *LPSHADOWCHECK;
  123. #define FLAG_OUT_SHADOWCHECK_FOUND 0x1
  124. #define FLAG_IN_SHADOWCHECK_EXCLUDE 0x0001
  125. #define FLAG_IN_SHADOWCHECK_NAME 0x0002
  126. #define FLAG_IN_SHADOWCHECK_SUBTREE 0x0004
  127. #define FLAG_IN_SHADOWCHECK_IGNOREHINTS 0x0008
  128. /*************** Our version of the find handle (VfnFindOpen)******/
  129. typedef struct tagFINDINFO
  130. {
  131. PFINDINFO pnextFindInfo; // Next FindInfo
  132. PRESOURCE pResource; // Resource off which it is hanging
  133. fh_t fhProFind; // providers find handle
  134. hndlfunc hfFindHandle; // providers find function table
  135. USHORT usFlags;
  136. USHORT usLocalFlags;
  137. HSHADOW hDir; // Directory in which the search is going on
  138. FINDSHADOW sFS;
  139. PathElement pe_pattern[1]; // Search pattern in case of wildcard search
  140. } FINDINFO, *PFINDINFO;
  141. /************ Generic linked list element ****************/
  142. typedef struct tagELEM
  143. {
  144. PELEM pnextElem;
  145. } ELEM;
  146. /********************* Flag definitions ************************************/
  147. /** Flags set in usLocalFlags field of FDB (FileDescriptionBlock) **/
  148. #define FLAG_FDB_SERIALIZE 0x0001
  149. #define FLAG_FDB_INUSE_BY_AGENT 0x0002
  150. #define FLAG_FDB_SHADOW_MODIFIED 0x0008
  151. #define FLAG_FDB_DONT_SHADOW 0x0010
  152. #define FLAG_FDB_FINAL_CLOSE_DONE 0x0020
  153. #define FLAG_FDB_DISABLE_AGENT 0x0040
  154. #define FLAG_FDB_ON_CACHEABLE_SHARE 0x0080
  155. #define FLAG_FDB_SHADOW_SNAPSHOTTED 0x0100
  156. #define FLAG_FDB_DELETE_ON_CLOSE 0x0200 // on NT we mark this file for delete after close
  157. /** Flags set in usLocalFlags field of FILEINFO **/
  158. #define FLAG_FILEINFO_INUSE_BY_AGENT 0x0002
  159. #define FLAG_FILEINFO_DUP_HANDLE 0x2000 // Duplicate handle
  160. #define FLAG_FILEINFO_INVALID_HANDLE 0x4000
  161. #define FLAG_FILEINFO_INTERNAL_HANDLE 0x8000 // Handle created for internal find
  162. /** Flags set in usLocalFlags field of FINDINFO **/
  163. #define FLAG_FINDINFO_SHADOWFIND 0x0001 // Shadow find is in progress
  164. #define FLAG_FINDINFO_INVALID_HANDLE 0x4000
  165. #define FLAG_FINDINFO_INTERNAL_HANDLE 0x8000 // Handle created for internal find
  166. /** Flags set on RESOURCE ***/
  167. #define FLAG_RESOURCE_DISCONNECTED SHARE_DISCONNECTED_OP //0x8000
  168. #define FLAG_RESOURCE_SHADOW_ERRORS SHARE_ERRORS // 0x4000
  169. #define FLAG_RESOURCE_SHADOW_CONNECT_PENDING 0x2000
  170. #define FLAG_RESOURCE_SHADOWNP SHARE_SHADOWNP // 0x1000
  171. #define FLAG_RESOURCE_SLOWLINK 0x0800
  172. #define FLAG_RESOURCE_OFFLINE_CONNECTION 0x0400
  173. #define FLAG_RESOURCE_CSC_MASK 0x00C0
  174. // the following defines deal with the CSC bits as obtained from the server and
  175. // as stored in the RESOURCE data structure
  176. #define ResourceCscBitsToSmbCscBits(uResBits) (((uResBits) & FLAG_RESOURCE_CSC_MASK) >> 4)
  177. #define SmbCscBitsToResourceCscBits(uResBits) (((uResBits) & SMB_NEW_CSC_MASK) << 4)
  178. #define ResourceCscBitsToShareCscBits(uResBits) ((uResBits) & FLAG_RESOURCE_CSC_MASK)
  179. #define FLAG_RESOURCE_CSC_MANUAL_REINT 0x0000 // No automatic file by file reint
  180. #define FLAG_RESOURCE_CSC_AUTO_REINT 0x0040 // File by file reint is OK
  181. #define FLAG_RESOURCE_CSC_VDO 0x0080 // no need to flow opens
  182. #define FLAG_RESOURCE_CSC_NO_CACHING 0x00C0 // client should not cache this share
  183. /** Find types *****/
  184. #define FLAG_FINDSHADOW_META 0x0001 // wild card matching
  185. #define FLAG_FINDSHADOW_NEWSTYLE 0x0002 // NT stle matching
  186. #define FLAG_FINDSHADOW_ALLOW_NORMAL 0x0004 // include non-sparse, undeleted shadows
  187. #define FLAG_FINDSHADOW_ALLOW_SPARSE 0x0008 // include sparse shadows
  188. #define FLAG_FINDSHADOW_ALLOW_DELETED 0x0010 // include shadows marked deleted
  189. #define FLAG_FINDSHADOW_DONT_ALLOW_INSYNC 0x0020 // ??
  190. #define FLAG_FINDSHADOW_ALL 0x8000
  191. /******* Findshadow flags ***********/
  192. #define FLAG_FINDSHADOW_INVALID_DIRECTORY 0x0001 //
  193. /************** Convenience macros ****************************/
  194. #define mShadowErrors(pRes) (((PRESOURCE)(pRes))->usLocalFlags & FLAG_RESOURCE_SHADOW_ERRORS)
  195. #define mShadowFindON(pFI) (((PFINDINFO)(pFI))->usLocalFlags & FLAG_FINDINFO_SHADOWFIND)
  196. #define mSetShadowFindON(pFI) (((PFINDINFO)(pFI))->usLocalFlags |= FLAG_FINDINFO_SHADOWFIND)
  197. #define mResetShadowFindON(pFI) (((PFINDINFO)(pFI))->usLocalFlags &= ~FLAG_FINDINFO_SHADOWFIND)
  198. #define mSerialize(pFdb) ((pFdb)->usLocalFlags & (FLAG_FDB_SERIALIZE))
  199. #define mSetSerialize(pFdb) ((pFdb)->usLocalFlags |= FLAG_FDB_SERIALIZE)
  200. #define mClearSerialize(pFdb) ((pFdb)->usLocalFlags &= ~FLAG_FDB_SERIALIZE)
  201. #define mInvalidFileHandle(pFileInfo) (((PFILEINFO)(pFileInfo))->usLocalFlags & FLAG_FILEINFO_INVALID_HANDLE)
  202. #define mInvalidFindHandle(pFileInfo) (((PFILEINFO)(pFileInfo))->usLocalFlags & FLAG_FINDINFO_INVALID_HANDLE)
  203. #define mIsDisconnected(pResource) (((PRESOURCE)(pResource))->usLocalFlags & FLAG_RESOURCE_DISCONNECTED)
  204. #define mMarkDisconnected(pResource) (((PRESOURCE)(pResource))->usLocalFlags |= FLAG_RESOURCE_DISCONNECTED)
  205. #define mClearDisconnected(pResource) (((PRESOURCE)(pResource))->usLocalFlags &= ~FLAG_RESOURCE_DISCONNECTED)
  206. #define mIsOfflineConnection(pResource) (((PRESOURCE)(pResource))->usLocalFlags & FLAG_RESOURCE_OFFLINE_CONNECTION)
  207. #define mShadowConnectPending(pResource) (((PRESOURCE)(pResource))->usLocalFlags & FLAG_RESOURCE_SHADOW_CONNECT_PENDING)
  208. #define mClearDriveUse(pResource, drvno) (((PRESOURCE)(pResource))->uDriveMap &= ~((1 << drvno)))
  209. #define mSetDriveUse(pResource, drvno) (((PRESOURCE)(pResource))->uDriveMap |= (1 << drvno))
  210. #define mGetDriveUse(pResource, drvno) (((PRESOURCE)(pResource))->uDriveMap & (1 << drvno))
  211. #define mGetCSCBits(pRes) (((PRESOURCE)(pRes))->usLocalFlags & FLAG_RESOURCE_CSC_MASK)
  212. #define mSetCSCBits(pRes, uBits) ((((PRESOURCE)(pRes))->usLocalFlags &= ~FLAG_RESOURCE_CSC_MASK), (((PRESOURCE)(pRes))->usLocalFlags |= ((uBits) & FLAG_RESOURCE_CSC_MASK)))
  213. #define mAutoReint(pRes) ((((PRESOURCE)(pRes))->usLocalFlags & FLAG_RESOURCE_CSC_MASK)==FLAG_RESOURCE_CSC_AUTO_REINT)
  214. #define mNotCacheable(pRes) ((((PRESOURCE)(pRes))->usLocalFlags & FLAG_RESOURCE_CSC_MASK)==FLAG_RESOURCE_CSC_NO_CACHING)
  215. #define ANY_RESOURCE (void *)(0xFFFFFFFF)
  216. #define ANY_FHID (void *)(0xFFFFFFFF)
  217. #define RH_DISCONNECTED (void *)0
  218. #define UseGlobalFind32() {AssertInShadowCrit();memset(&vsFind32, 0, sizeof(vsFind32));}
  219. #define EnterHookCrit() Wait_Semaphore(semHook, BLOCK_SVC_INTS)
  220. #define LeaveHookCrit() Signal_Semaphore(semHook)
  221. /*************************** Globals ************************************/
  222. /************************** Templates for exported functions ***************/
  223. int GetDriveIndex(LPSTR lpDrive);
  224. PFDB PFindFdbFromHShadow (HSHADOW hShadow);
  225. int CopyChunk (HSHADOW, HSHADOW, PFILEINFO, COPYCHUNKCONTEXT *);
  226. PRESOURCE PFindShadowResourceFromDriveMap(int indx);
  227. PRESOURCE PFindResource (LPPE lppeIn, rh_t rhPro, fh_t fhPro, ULONG uFlags, PNETPRO pNetPro);
  228. PRESOURCE PFindResourceFromHShare (HSHARE, USHORT, USHORT);
  229. PRESOURCE PFindResourceFromRoot (HSHADOW, USHORT, USHORT);
  230. void LinkResource (PRESOURCE pResource, PNETPRO pNetPro);
  231. PRESOURCE PUnlinkResource (PRESOURCE pResource, PNETPRO pNetPro);
  232. PRESOURCE PCreateResource (LPPE lppeIn);
  233. void DestroyResource (PRESOURCE pResource);
  234. int PUBLIC FindOpenHSHADOW(LPFINDSHADOW, LPHSHADOW, LPFIND32, ULONG far *, LPOTHERINFO);
  235. int PUBLIC FindNextHSHADOW(LPFINDSHADOW, LPHSHADOW, LPFIND32, ULONG far *, LPOTHERINFO);
  236. int PUBLIC FindCloseHSHADOW(LPFINDSHADOW);
  237. HSHARE
  238. HShareFromPath(
  239. PRESOURCE pResource,
  240. LPPE lppeShare,
  241. ULONG uFlags,
  242. LPFIND32 lpFind32,
  243. HSHADOW *lphRoot,
  244. ULONG *lpuShareStatus
  245. );
  246. PFILEINFO PFileInfoAgent(VOID);
  247. BOOL IsDupHandle(PFILEINFO pFileInfo);
  248. PFDB PFindFdbFromHShadow (HSHADOW);
  249. PFINDINFO PFindFindInfoFromHShadow(HSHADOW);
  250. int FsobjMMProc(LPFIND32, HSHADOW, HSHADOW, ULONG, LPOTHERINFO, LPFINDSHADOW);
  251. int GetShadowWithChecksProc (LPFIND32, HSHADOW, HSHADOW, ULONG, LPOTHERINFO, LPSHADOWCHECK);
  252. /* the fcb structures work very differently on NT/rdr2 from the shadow VxD.
  253. accordingly, we have to do things a bit differently. there are the following
  254. important considerations:
  255. 1. after you find a PFDBfromHShadow, it will continue to be valid until you
  256. leavveshadowcrit. what we'll do is to return a pointer to the status as
  257. part of the lookup routine and we'll use the pointer to fetch/update the status.
  258. IMPORTANT>>>> what i do is to actually return a pointer so that the status is
  259. act the correct offset from the pointer. the pointer must not be used for anything
  260. else.
  261. 2. i cannot continue to be in the shadow crit while looking up a netroot. accordingly,
  262. i'll have to drop the lock and reacquire it. so i get the status and the drive map at
  263. the same time and remember them for later.
  264. */
  265. #ifndef CSC_RECORDMANAGER_WINNT
  266. int ReportCreateDelete( HSHADOW hShadow, BOOL fCreate);
  267. #define SMB_NEW_CSC_MASK 0x000C // see below
  268. #define SMB_NEW_CSC_CACHE_MANUAL_REINT 0x0000 // No automatic file by file reint
  269. #define SMB_NEW_CSC_CACHE_AUTO_REINT 0x0004 // File by file reint is OK
  270. #define SMB_NEW_CSC_CACHE_VDO 0x0008 // no need to flow opens
  271. #define SMB_NEW_CSC_NO_CACHING 0x000C // client should not cache this share
  272. #define IFNOT_CSC_RECORDMANAGER_WINNT if(TRUE)
  273. #define MRxSmbCscGetSavedResourceStatus() (0)
  274. #define MRxSmbCscGetSavedResourceDriveMap() (0)
  275. #define DeclareFindFromShadowOnNtVars()
  276. #define PLocalFlagsFromPFdb(pFdb) (&((pFdb)->usLocalFlags))
  277. #else
  278. //BUGBUG
  279. //this comes from hook.c on win95
  280. #define ReportCreateDelete(a,b) {NOTHING;}
  281. #define IFNOT_CSC_RECORDMANAGER_WINNT if(FALSE)
  282. #define DeclareFindFromShadowOnNtVars() \
  283. ULONG mrxsmbShareStatus,mrxsmbDriveMap;
  284. #define PFindFindInfoFromHShadow(a) ((NULL))
  285. PFDB MRxSmbCscFindFdbFromHShadow (
  286. IN HSHADOW hShadow
  287. );
  288. #define PFindFdbFromHShadow(a) MRxSmbCscFindFdbFromHShadow(a)
  289. PRESOURCE MRxSmbCscFindResourceFromHandlesWithModify (
  290. IN HSHARE hShare,
  291. IN HSHADOW hRoot,
  292. IN USHORT usLocalFlagsIncl,
  293. IN USHORT usLocalFlagsExcl,
  294. OUT PULONG ShareStatus,
  295. OUT PULONG DriveMap,
  296. IN ULONG uStatus,
  297. IN ULONG uOp
  298. );
  299. USHORT *
  300. MRxSmbCscFindLocalFlagsFromFdb(
  301. PFDB pFdb
  302. );
  303. #define PFindResourceFromRoot(a,b,c) \
  304. MRxSmbCscFindResourceFromHandlesWithModify(0xffffffff,a,b,c,\
  305. &mrxsmbShareStatus, \
  306. &mrxsmbDriveMap,0,0xffffffff)
  307. #define MRxSmbCscGetSavedResourceStatus() (mrxsmbShareStatus)
  308. #define MRxSmbCscGetSavedResourceDriveMap() (mrxsmbDriveMap)
  309. #define PFindResourceFromHShare(a,b,c) \
  310. MRxSmbCscFindResourceFromHandlesWithModify(a,0xffffffff,b,c,\
  311. &mrxsmbShareStatus, \
  312. &mrxsmbDriveMap,0,0xffffffff)
  313. #define PSetResourceStatusFromHShare(a,b,c,d,e) \
  314. MRxSmbCscFindResourceFromHandlesWithModify(a,0xffffffff,b,c,\
  315. &mrxsmbShareStatus, \
  316. &mrxsmbDriveMap,d,e)
  317. #define ClearAllResourcesOfShadowingState() \
  318. MRxSmbCscFindResourceFromHandlesWithModify(0xffffffff,0xffffffff,0,0,\
  319. NULL, \
  320. NULL,0,SHADOW_FLAGS_AND)
  321. #define PLocalFlagsFromPFdb(a) MRxSmbCscFindLocalFlagsFromFdb(a)
  322. NTSTATUS
  323. MRxSmbCscCachingBitsFromCompleteUNCPath(
  324. PWSTR lpShareShare,
  325. ULONG *lpulBits
  326. );
  327. NTSTATUS
  328. MRxSmbCscServerStateFromCompleteUNCPath(
  329. PWSTR lpShareShare,
  330. BOOL *lpfOnline,
  331. BOOL *lpfPinnedOffline
  332. );
  333. NTSTATUS
  334. MRxSmbCscIsLoopbackServer(
  335. PWSTR lpServerShare,
  336. BOOL *lpfIsLoopBack);
  337. #define SIGNALAGENTFLAG_CONTINUE_FOR_NO_AGENT 0x00000001
  338. #define SIGNALAGENTFLAG_DONT_LEAVE_CRIT_SECT 0x00000002
  339. extern NTSTATUS
  340. MRxSmbCscSignalAgent (
  341. PRX_CONTEXT RxContext OPTIONAL,
  342. ULONG Controls
  343. );
  344. extern NTSTATUS
  345. MRxSmbCscSignalFillAgent (
  346. PRX_CONTEXT RxContext OPTIONAL,
  347. ULONG Controls
  348. );
  349. extern BOOL
  350. IsCSCBusy(
  351. VOID
  352. );
  353. VOID
  354. ClearCSCStateOnRedirStructures(
  355. VOID
  356. );
  357. #endif //ifndef CSC_RECORDMANAGER_WINNT