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.

213 lines
5.7 KiB

  1. //*************************************************************
  2. //
  3. // Copyright (c) Microsoft Corporation 1998
  4. // All rights reserved
  5. //
  6. // filedb.hxx
  7. //
  8. //*************************************************************
  9. #ifndef _FILEDB_HXX_
  10. #define _FILEDB_HXX_
  11. #define GPT_SUBDIR L"\\Documents & Settings\\"
  12. #define INIFILE_NAME L"fdeploy.ini"
  13. //forward declaration
  14. class CCopyFailData;
  15. typedef struct _FOLDERINFO
  16. {
  17. int CSidl;
  18. DWORD FolderNameLength;
  19. WCHAR * FolderName;
  20. } FOLDERINFO;
  21. class CSavedSettings
  22. {
  23. friend class CRedirectInfo;
  24. public:
  25. CSavedSettings();
  26. ~CSavedSettings();
  27. BOOL NeedsProcessing (void);
  28. DWORD HandleUserNameChange (CFileDB * pFileDB,
  29. CRedirectInfo * pRedir);
  30. DWORD Load (CFileDB * pFileDB);
  31. static const DWORD MaxSidString = 256;
  32. DWORD Save (const WCHAR * pwszPath, DWORD dwFlags, PSID pSid, const WCHAR * pszGPOName);
  33. static void ResetStaticMembers (void);
  34. void ResetMembers (void);
  35. private: //data
  36. static int m_idConstructor;
  37. static CFileDB * m_pFileDB;
  38. static WCHAR * m_szSavedSettingsPath;
  39. //object specific data
  40. REDIRECTABLE m_rID; //the id of the folder that it represents
  41. WCHAR * m_szLastRedirectedPath;
  42. WCHAR * m_szCurrentPath;
  43. WCHAR * m_szLastUserName; //the name of the user at the last logon
  44. BOOL m_bUserNameChanged; //if the user's logon name was different at last logon.
  45. WCHAR * m_szLastHomedir; // The value of Homedir at last redirection.
  46. BOOL m_bIsHomedirRedir; // Indicates if this is a homedir redirection.
  47. BOOL m_bHomedirChanged; // Indicates if the homedir value has changed.
  48. PSID m_psid;
  49. DWORD m_dwFlags;
  50. BOOL m_bValidGPO;
  51. WCHAR m_szGPOName[50]; //unique GPO name (if any) that was used for redirection
  52. //50 characters are more than enough to store the GPO name.
  53. private: //helper functions
  54. DWORD LoadDefaultLocal (void);
  55. DWORD LoadFromIniFile (void);
  56. DWORD GetCurrentPath (void);
  57. DWORD ResetLastUserName (void);
  58. DWORD UpdateUserNameInCache (void);
  59. };
  60. class CFileDB : public CRedirectionLog
  61. {
  62. friend class CSavedSettings;
  63. friend class CRedirectInfo;
  64. friend class CRedirectionPolicy;
  65. public:
  66. CFileDB();
  67. ~CFileDB();
  68. DWORD
  69. Initialize (
  70. HANDLE hUserToken,
  71. HKEY hkRoot,
  72. CRsopContext* pRsopContext
  73. );
  74. DWORD
  75. Process(
  76. PGROUP_POLICY_OBJECT pGPO,
  77. BOOL bRemove
  78. );
  79. const WCHAR *
  80. GetLocalStoragePath ();
  81. PVOID
  82. GetEnvBlock (void);
  83. CRsopContext*
  84. GetRsopContext();
  85. private:
  86. DWORD
  87. ProcessRedirects();
  88. static const DWORD MaxIniSectionSize = 32 * (1024*1024); // limit this to 32 MB to avoid a huge section that eats all memory.
  89. BOOL
  90. ReadIniSection(
  91. WCHAR * pwszSectionName,
  92. WCHAR ** ppwszStrings,
  93. DWORD * pcchLen = NULL
  94. );
  95. DWORD
  96. GetLocalFilePath(
  97. WCHAR * pwszFolderPath,
  98. WCHAR wszFullPath[MAX_PATH]
  99. );
  100. DWORD
  101. GetPathFromFolderName(
  102. WCHAR * pwszFolderName,
  103. WCHAR wszFullPath[MAX_PATH]
  104. );
  105. const FOLDERINFO*
  106. FolderInfoFromFolderName(
  107. WCHAR * pwszFolderName
  108. );
  109. int
  110. RegValueCSIDLFromFolderName(
  111. WCHAR * pwszFolderName
  112. );
  113. DWORD
  114. CopyFileTree(
  115. WCHAR * pwszExistingPath,
  116. WCHAR * pwszNewPath,
  117. WCHAR * pwszIgnoredSubdir,
  118. SHARESTATUS StatusFrom,
  119. SHARESTATUS StatusTo,
  120. BOOL bAllowRdrTimeout,
  121. CCopyFailData * pCopyFailure
  122. );
  123. DWORD
  124. DeleteFileTree(
  125. WCHAR * pwszPath,
  126. WCHAR * pwszIgnoredSubdir
  127. );
  128. DWORD
  129. CreateRedirectedFolderPath(
  130. const WCHAR * pwszSource,
  131. const WCHAR * pwszDest,
  132. BOOL bSourceValid,
  133. BOOL bCheckOwner,
  134. BOOL bMoveContents
  135. );
  136. DWORD
  137. CreateFolderWithUserFileSecurity(
  138. WCHAR * pwszPath
  139. );
  140. DWORD
  141. SetUserAsOwner(
  142. WCHAR * pwszPath
  143. );
  144. DWORD IsUserOwner (const WCHAR * pwszPath);
  145. //data
  146. //same across all policies
  147. HANDLE _hUserToken;
  148. HKEY _hkRoot;
  149. PTOKEN_GROUPS _pGroups;
  150. WCHAR _pwszLocalPath[MAX_PATH]; //path to the Local Settings directory
  151. //created only if necessary but same across all policies
  152. PVOID _pEnvBlock;
  153. //varies with each policy
  154. BOOL _bRemove;
  155. WCHAR * _pwszGPTPath; // Path to Documents & Settings dir on GPT
  156. DWORD _GPTPathLen; //number of characters allocated to _pwszGPTPath
  157. WCHAR * _pwszIniFilePath; // Full path to file deployment ini file on the GPT
  158. DWORD _IniFileLen; //# of characters allocated to _pwszIniFilePath
  159. WCHAR * _pwszGPOName; // From GPO_INFO struct, not alloced
  160. WCHAR * _pwszGPOUniqueName; // From GPO_INFO struct, not alloced
  161. WCHAR * _pwszGPOSOMPath; // From GPO_INFO struct, not alloced
  162. WCHAR * _pwszGPODSPath; // From GPO_INFO struct, not alloced
  163. CRsopContext* _pRsopContext; // unowned reference to rsop info
  164. };
  165. inline void
  166. RemoveEndingSlash(
  167. WCHAR * pwszPath
  168. )
  169. {
  170. DWORD Length = wcslen( pwszPath );
  171. if ( pwszPath[Length-1] == L'\\' )
  172. pwszPath[Length-1] = 0;
  173. }
  174. #endif