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.

313 lines
9.7 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. bitssrvcfg.h
  5. Abstract:
  6. Header to define server configuration information.
  7. --*/
  8. #pragma once
  9. #include <iads.h>
  10. #define BITS_COMMAND_VERBW L"BITS_POST"
  11. #define BITS_COMMAND_VERBA "BITS_POST"
  12. #define BITS_GROUP_IDW L"BITSEXTS"
  13. #define BITS_GROUP_IDA "BITSEXTS"
  14. const DWORD METABASE_OPEN_KEY_TIMEOUT = 10000; // 10 seconds
  15. const DWORD MD_BITS_UPLOAD_ENABLED = 0;
  16. const DWORD MD_BITS_CONNECTION_DIR = 1;
  17. const DWORD MD_BITS_MAX_FILESIZE = 2;
  18. const DWORD MD_BITS_NO_PROGRESS_TIMEOUT = 3;
  19. const DWORD MD_BITS_NOTIFICATION_URL_TYPE = 4;
  20. const DWORD MD_BITS_NOTIFICATION_URL = 5;
  21. const DWORD MD_BITS_CLEANUP_WORKITEM_KEY = 6;
  22. const DWORD MD_BITS_HOSTID = 7;
  23. const DWORD MD_BITS_HOSTID_FALLBACK_TIMEOUT = 8;
  24. const DWORD MD_BITS_UPLOAD_METADATA_VERSION = 9;
  25. #define ALLOW_OVERWRITES 1
  26. #if defined( ALLOW_OVERWRITES )
  27. const DWORD MD_BITS_ALLOW_OVERWRITES = 10;
  28. #endif
  29. enum BITS_SERVER_NOTIFICATION_TYPE
  30. {
  31. BITS_NOTIFICATION_TYPE_NONE = 0,
  32. BITS_NOTIFICATION_TYPE_POST_BYREF = 1,
  33. BITS_NOTIFICATION_TYPE_POST_BYVAL = 2,
  34. BITS_NOTIFICATION_TYPE_MAX = 2
  35. };
  36. const WCHAR * const MD_BITS_UNLIMITED_MAX_FILESIZE = L"18446744073709551615";
  37. const CHAR * const MD_BITS_UNLIMITED_MAX_FILESIZEA = "18446744073709551615";
  38. const UINT64 MD_BITS_UNLIMITED_MAX_FILESIZE_AS_INT64 = 18446744073709551615;
  39. const DWORD MD_BITS_NO_TIMEOUT = 0xFFFFFFFF;
  40. const WCHAR * const MD_DEFAULT_BITS_CONNECTION_DIR = L"BITS-Sessions";
  41. const CHAR * const MD_DEFAULT_BITS_CONNECTION_DIRA = "BITS-Sessions";
  42. const WCHAR * const MD_DEFAULT_BITS_MAX_FILESIZE = MD_BITS_UNLIMITED_MAX_FILESIZE;
  43. const CHAR * const MD_DEFAULT_BITS_MAX_FILESIZEA = MD_BITS_UNLIMITED_MAX_FILESIZEA;
  44. const UINT64 MD_DEFAULT_BITS_MAX_FILESIZE_AS_INT64 = MD_BITS_UNLIMITED_MAX_FILESIZE_AS_INT64;
  45. const DWORD MD_DEFAULT_NO_PROGESS_TIMEOUT = 60 /*seconds*/ * 60 /* minutes */ * 24 /* hours */ * 14 /* days */;
  46. const BITS_SERVER_NOTIFICATION_TYPE MD_DEFAULT_BITS_NOTIFICATION_URL_TYPE = BITS_NOTIFICATION_TYPE_NONE;
  47. const WCHAR * const MD_DEFAULT_BITS_NOTIFICATION_URL = L"";
  48. const CHAR * const MD_DEFAULT_BITS_NOTIFICATION_URLA = "";
  49. const WCHAR * const MD_DEFAULT_BITS_HOSTID = L"";
  50. const CHAR * const MD_DEFAULT_BITS_HOSTIDA = "";
  51. const DWORD MD_DEFAULT_HOSTID_FALLBACK_TIMEOUT = 60 /*seconds*/ * 60 /* minutes */ * 24 /* hours */; /* 1 day */
  52. const DWORD CURRENT_UPLOAD_METADATA_VERSION = 1;
  53. #if defined( ALLOW_OVERWRITES )
  54. const bool MD_DEFAULT_BITS_ALLOW_OVERWRITES = false;
  55. #endif
  56. const CHAR RESPONSE_FILE_NAME[] = "responsefile.bin";
  57. const CHAR REQUEST_FILE_NAME[] = "requestfile.bin";
  58. const CHAR REQUESTS_DIR_NAME[] = "Requests";
  59. const WCHAR REQUESTS_DIR_NAMEW[] = L"Requests";
  60. const CHAR REPLIES_DIR_NAME[] = "Replies";
  61. const WCHAR REPLIES_DIR_NAMEW[] = L"Replies";
  62. const CHAR CLEANUP_GUIDS_NAME[] = "CleanupGuids";
  63. const WCHAR STATE_FILE_NAMEW[] = L"statefile";
  64. const CHAR STATE_FILE_NAME[] = "statefile";
  65. const DWORD STATE_FILE_SIZE = 1024 * 4; // 4 KB
  66. const DWORD STATE_FILE_VERSION = 1;
  67. //
  68. // These ACLs are set by BITS at setup time.
  69. //
  70. // annah:
  71. // 0x6 is create files/data write + create folders/data append
  72. //
  73. // The inheritance of the ACL from the parent directory will occur if
  74. // the proper API is called. CreateBITSCacheDirectory was updated for that.
  75. //
  76. // Also not that the CO permissions is not as usefull as we would like. CO
  77. // rights are only effective during the object's creation period. (!!!)
  78. // Where needed, we will explicitly add the SID for the owner in the ACL.
  79. //
  80. const WCHAR BITS_SESSIONS_DIR_ACL[] = L"D:AI(A;;GA;;;CO)(A;OICI;GA;;;BA)(A;OICI;GA;;;SY)(A;OICIIO;0x6;;;WD)";
  81. const WCHAR BITS_CLEANUPGUIDS_DIR_ACL[] = L"D:AI(A;OICI;GA;;;BA)(A;OICI;GA;;;SY)";
  82. const WCHAR BITS_REQUESTS_DIR_ACL[] = L"D:AI(A;OICI;GA;;;BA)(A;OICI;GA;;;SY)(A;OICIIO;GA;;;CO)";
  83. const WCHAR BITS_REPLIES_DIR_ACL[] = L"D:AI(A;OICI;GA;;;BA)(A;OICI;GA;;;SY)(A;OICIIO;GA;;;CO)";
  84. const WCHAR BITS_EXPLICITOWNER_PARTIAL_ACL[] = L"(A;OICI;GA;;;";
  85. const WCHAR BITS_AGENT_NAMEW[] = L"BITSExts 1.5";
  86. const CHAR BITS_AGENT_NAMEA[] = "BITSExts 1.5";
  87. const DWORD BITS_MAX_HEADER_SIZE = 4096;
  88. struct PROPERTY_ITEM
  89. {
  90. WCHAR * PropertyName;
  91. WCHAR * ClassName;
  92. WCHAR * Syntax;
  93. DWORD UserType;
  94. DWORD PropertyNumber;
  95. };
  96. const PROPERTY_ITEM g_Properties[] =
  97. {
  98. {
  99. L"BITSUploadEnabled",
  100. L"IIsWebVirtualDir",
  101. L"Boolean",
  102. IIS_MD_UT_FILE,
  103. 0
  104. },
  105. {
  106. L"BITSSessionDirectory",
  107. L"IIsWebVirtualDir",
  108. L"String",
  109. IIS_MD_UT_FILE,
  110. 1
  111. },
  112. {
  113. L"BITSMaximumUploadSize",
  114. L"IIsWebVirtualDir",
  115. L"String",
  116. IIS_MD_UT_FILE,
  117. 2
  118. },
  119. {
  120. L"BITSSessionTimeout",
  121. L"IIsWebVirtualDir",
  122. L"Integer",
  123. IIS_MD_UT_FILE,
  124. 3
  125. },
  126. {
  127. L"BITSServerNotificationType",
  128. L"IIsWebVirtualDir",
  129. L"Integer",
  130. IIS_MD_UT_FILE,
  131. 4
  132. },
  133. {
  134. L"BITSServerNotificationURL",
  135. L"IIsWebVirtualDir",
  136. L"String",
  137. IIS_MD_UT_FILE,
  138. 5
  139. },
  140. {
  141. L"BITSCleanupWorkItemKey",
  142. L"IIsWebVirtualDir",
  143. L"String",
  144. IIS_MD_UT_FILE,
  145. 6
  146. },
  147. {
  148. L"BITSHostId",
  149. L"IIsWebVirtualDir",
  150. L"String",
  151. IIS_MD_UT_FILE,
  152. 7
  153. },
  154. {
  155. L"BITSHostIdFallbackTimeout",
  156. L"IIsWebVirtualDir",
  157. L"Integer",
  158. IIS_MD_UT_FILE,
  159. 8
  160. },
  161. {
  162. L"BITSUploadMetadataVersion",
  163. L"IIsWebVirtualDir",
  164. L"Integer",
  165. IIS_MD_UT_FILE,
  166. 9
  167. }
  168. #if defined( ALLOW_OVERWRITES )
  169. ,
  170. {
  171. L"BITSAllowOverwrites",
  172. L"IIsWebVirtualDir",
  173. L"Integer",
  174. IIS_MD_UT_FILE,
  175. 10
  176. }
  177. #endif
  178. };
  179. const SIZE_T g_NumberOfProperties = sizeof(g_Properties)/sizeof(*g_Properties);
  180. class PropertyIDManager
  181. {
  182. DWORD m_PropertyIDs[ g_NumberOfProperties ];
  183. DWORD m_PropertyUserTypes[ g_NumberOfProperties ];
  184. public:
  185. PropertyIDManager()
  186. {
  187. memset( &m_PropertyIDs, 0, sizeof( m_PropertyIDs ) );
  188. memset( &m_PropertyUserTypes, 0, sizeof( m_PropertyUserTypes ) );
  189. }
  190. HRESULT LoadPropertyInfo( const WCHAR *MachineName = L"LocalHost" );
  191. DWORD GetPropertyMetabaseID( DWORD PropID )
  192. {
  193. return m_PropertyIDs[PropID];
  194. }
  195. DWORD GetPropertyUserType( DWORD PropID )
  196. {
  197. return m_PropertyUserTypes[PropID];
  198. }
  199. };
  200. #include "smartptr.h"
  201. typedef SmartRefPointer<IMSAdminBase> SmartIMSAdminBasePointer;
  202. //
  203. // CSimplePropertyReader
  204. //
  205. // This class is just a 'container' for utility functions related with
  206. // Meta base access that are used both on mmcexts and isapi code.
  207. // These could appear in a library to be shared between both codes,
  208. // but to minimize code churn for a RC2 fix we are using an existing
  209. // .h file that is shared on both codes.
  210. //
  211. // This class will replace original mmcexts code that implemented
  212. // CleanupWorker::ConvertObjectPathToADSI and CleanupWorker::GetPropBSTR.
  213. // That's the reason this class has static methods: so we can use them
  214. // trully as auxiliary functions without requiring object instantiation.
  215. // Another way of doing this would be to create standalone functions,
  216. // But the class wrapping sort of give them a "namespace", which
  217. // is convenient when reading code.
  218. //
  219. class CSimplePropertyReader
  220. {
  221. public:
  222. static WCHAR *ConvertObjectPathToADSI(const WCHAR *ObjectPath);
  223. static BSTR GetADsStringProperty(IADs *MetaObj, BSTR bstrPropName);
  224. static LPWSTR GetAdmObjStringProperty(
  225. SmartIMSAdminBasePointer IISAdminBase,
  226. METADATA_HANDLE MdVDirKey,
  227. DWORD dwMDIdentifier
  228. );
  229. };
  230. //
  231. // CAccessRemoteVDir
  232. //
  233. // This class offers methods that implement getting IIS's credentials for
  234. // a virtual directory's UNC path.
  235. // Then, it is able to login and impersonate this user, such that we
  236. // can do filesystem operations in this remote path.
  237. //
  238. class CAccessRemoteVDir
  239. {
  240. IADs *m_MetaObj;
  241. BOOL m_fIsImpersonated;
  242. HANDLE m_hUserToken;
  243. LPWSTR m_szUNCPath;
  244. LPWSTR m_szUNCUsername;
  245. LPWSTR m_szUNCPassword;
  246. public:
  247. CAccessRemoteVDir();
  248. ~CAccessRemoteVDir();
  249. void LoginToUNC(SmartIMSAdminBasePointer IISAdminBase, METADATA_HANDLE MdVDirKey );
  250. void RevertFromUNCAccount();
  251. static BOOL IsUNCPath(LPCWSTR szPath);
  252. static void ImpersonateUNCUser(IN LPCWSTR szUNCPath, IN LPCWSTR szUNCUsername, IN LPCWSTR szUNCPassword, OUT HANDLE *hUserToken);
  253. };