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.

319 lines
7.1 KiB

  1. /************************************************************************
  2. Copyright (c) 2000 - 2000 Microsoft Corporation
  3. Module Name :
  4. cjob.h
  5. Abstract :
  6. Main header file for files.
  7. Author :
  8. Revision History :
  9. ***********************************************************************/
  10. class CFile;
  11. class CJob;
  12. class CFileExternal;
  13. class CJobExternal;
  14. class CFileExternal : public IBackgroundCopyFile
  15. {
  16. public:
  17. friend CFile;
  18. // IUnknown Methods
  19. STDMETHOD(QueryInterface)(REFIID riid, void **ppvObject);
  20. ULONG _stdcall AddRef(void);
  21. ULONG _stdcall Release(void);
  22. // IBackgroundCopyFile methods
  23. HRESULT STDMETHODCALLTYPE GetRemoteNameInternal(
  24. /* [out] */ LPWSTR *pVal);
  25. HRESULT STDMETHODCALLTYPE GetRemoteName(
  26. /* [out] */ LPWSTR *pVal)
  27. {
  28. EXTERNAL_FUNC_WRAP( GetRemoteNameInternal( pVal ) )
  29. }
  30. HRESULT STDMETHODCALLTYPE GetLocalNameInternal(
  31. /* [out] */ LPWSTR *pVal);
  32. HRESULT STDMETHODCALLTYPE GetLocalName(
  33. /* [out] */ LPWSTR *pVal)
  34. {
  35. EXTERNAL_FUNC_WRAP( GetLocalNameInternal( pVal ) )
  36. }
  37. HRESULT STDMETHODCALLTYPE GetProgressInternal(
  38. /* [out] */ BG_FILE_PROGRESS *pVal);
  39. HRESULT STDMETHODCALLTYPE GetProgress(
  40. /* [out] */ BG_FILE_PROGRESS *pVal)
  41. {
  42. EXTERNAL_FUNC_WRAP( GetProgressInternal( pVal ) )
  43. }
  44. // other methods
  45. CFileExternal(
  46. CFile * file,
  47. CJobExternal * JobExternal
  48. );
  49. ~CFileExternal();
  50. private:
  51. long m_refs;
  52. long m_ServiceInstance;
  53. CFile * m_file;
  54. CJobExternal * m_JobExternal;
  55. };
  56. class CFile : public ITransferCallback
  57. {
  58. public:
  59. friend CFileExternal;
  60. // ITransferCallback methods
  61. virtual bool
  62. DownloaderProgress(
  63. UINT64 BytesTransferred,
  64. UINT64 BytesTotal
  65. );
  66. virtual bool PollAbort();
  67. virtual bool
  68. UploaderProgress(
  69. UINT64 BytesTransferred
  70. );
  71. // other methods
  72. CFile(
  73. CJob* Job,
  74. BG_JOB_TYPE FileType,
  75. StringHandle RemoteName,
  76. StringHandle LocalName
  77. );
  78. virtual ~CFile();
  79. bool Transfer( HANDLE hToken,
  80. BG_JOB_PRIORITY priority,
  81. const PROXY_SETTINGS & ProxySettings,
  82. const CCredentialsContainer *Credentials,
  83. QMErrInfo & ErrInfo
  84. );
  85. void
  86. DiscoverBytesTotal(
  87. HANDLE Token,
  88. const PROXY_SETTINGS & ProxySettings,
  89. const CCredentialsContainer * Credentials,
  90. QMErrInfo & ErrorInfo
  91. );
  92. HRESULT GetRemoteName( LPWSTR *pVal ) const;
  93. HRESULT GetLocalName( LPWSTR *pVal ) const;
  94. const StringHandle & GetRemoteName() const
  95. {
  96. return m_RemoteName;
  97. }
  98. const StringHandle & GetLocalName() const
  99. {
  100. return m_LocalName;
  101. }
  102. const StringHandle & GetTemporaryName() const
  103. {
  104. return m_TemporaryName;
  105. }
  106. void GetProgress( BG_FILE_PROGRESS *pVal ) const;
  107. HRESULT Serialize( HANDLE hFile );
  108. static CFile * Unserialize( HANDLE hFile, CJob* Job );
  109. UINT64 _GetBytesTransferred() const
  110. {
  111. return m_BytesTransferred;
  112. }
  113. UINT64 _GetBytesTotal() const
  114. {
  115. return m_BytesTotal;
  116. }
  117. void SetBytesTotal( UINT64 BytesTotal )
  118. {
  119. m_BytesTotal = BytesTotal;
  120. }
  121. void SetBytesTransferred( UINT64 BytesTransferred )
  122. {
  123. m_BytesTransferred = BytesTransferred;
  124. }
  125. bool IsCompleted()
  126. {
  127. return m_Completed;
  128. }
  129. bool ReceivedAllData()
  130. {
  131. return (m_BytesTotal == m_BytesTransferred);
  132. }
  133. CFileExternal * CreateExternalInterface();
  134. CJob* GetJob() const
  135. {
  136. return m_Job;
  137. }
  138. HRESULT CheckClientAccess(
  139. IN DWORD RequestedAccess
  140. ) const;
  141. HRESULT MoveTempFile();
  142. HRESULT DeleteTempFile();
  143. HRESULT VerifyLocalName( LPCWSTR name, BG_JOB_TYPE JobType );
  144. BOOL VerifyRemoteName( LPCWSTR name );
  145. static HRESULT VerifyLocalFileName( LPCWSTR name, BG_JOB_TYPE JobType );
  146. bool IsCanonicalVolume( const WCHAR *CanonicalVolume )
  147. {
  148. return ( _wcsicmp( m_CanonicalVolumePath, CanonicalVolume ) == 0 );
  149. }
  150. HRESULT ValidateAccessForUser( SidHandle sid, bool fWrite );
  151. bool ValidateDriveInfo( HANDLE hToken, QMErrInfo & ErrInfo );
  152. bool OnDiskChange( const WCHAR *CanonicalVolume, DWORD VolumeSerialNumber );
  153. bool OnDismount( const WCHAR *CanonicalVolume );
  154. void ChangedOnServer();
  155. static bool IsDriveTypeRemote( UINT DriveType )
  156. {
  157. return
  158. ( DriveType == DRIVE_UNKNOWN ) ||
  159. ( DriveType == DRIVE_NO_ROOT_DIR ) ||
  160. ( DriveType == DRIVE_REMOTE );
  161. }
  162. static bool IsAbsolutePath( const WCHAR * Path )
  163. {
  164. bool ret;
  165. if ( (Path [0] == L'\\' && Path[1] == L'\\') ||
  166. (iswalpha ( Path [0] ) && Path [1] == L':' && Path[ 2 ] == L'\\') ) {
  167. ret = true;
  168. } else {
  169. ret = false;
  170. }
  171. return ret;
  172. }
  173. static bool IsUncPath( LPCWSTR Path )
  174. {
  175. if (Path [0] == L'\\' && Path[1] == L'\\')
  176. {
  177. return true;
  178. }
  179. return false;
  180. }
  181. DWORD GetSizeEstimate()
  182. {
  183. //
  184. // Serialize() will store five file paths and five constants
  185. //
  186. return (5 * MAX_PATH * sizeof(WCHAR)) + 5 * sizeof( UINT64 );
  187. }
  188. HANDLE OpenLocalFileForUpload() throw( ComError );
  189. HRESULT SetLocalFileTime( FILETIME Time );
  190. private:
  191. CFile(
  192. CJob* Job
  193. );
  194. StringHandle m_RemoteName;
  195. StringHandle m_LocalName;
  196. StringHandle m_TemporaryName;
  197. FILETIME m_LocalFileTime;
  198. UINT64 m_BytesTotal;
  199. UINT64 m_BytesTransferred;
  200. bool m_Completed;
  201. CJob * m_Job;
  202. // Drive information
  203. StringHandle m_VolumePath;
  204. StringHandle m_CanonicalVolumePath;
  205. UINT m_DriveType;
  206. DWORD m_VolumeSerialNumber;
  207. };
  208. /**
  209. * When deleting a file, some errors are OK to ignore because they imply that
  210. * the file has already been deleted by an external agent. This fn filters
  211. * out those errors.
  212. *
  213. * @param Hr HRESULT form of the error from deletion
  214. * @param Path the file being deleted
  215. *
  216. * @return true if the error should be reported,
  217. * false if the error should be ignored
  218. */
  219. inline bool
  220. IsReportableFileDeletionError(
  221. HRESULT Hr,
  222. LPCWSTR Path
  223. )
  224. {
  225. if (Hr == HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ))
  226. {
  227. return false;
  228. }
  229. //
  230. // ERROR_PATH_NOT_FOUND is returned when we try to delete a UNC path while
  231. // the Workstation service is halted. Tn this case, report the error.
  232. //
  233. if (Hr == HRESULT_FROM_WIN32( ERROR_PATH_NOT_FOUND ) &&
  234. false == CFile::IsUncPath(Path))
  235. {
  236. return false;
  237. }
  238. return true;
  239. }